Browse Source

adjust time offset after second time discrepancy

pull/2003/head
orignal 12 months ago
parent
commit
d4c47d90cb
  1. 21
      libi2pd/SSU2.cpp
  2. 2
      libi2pd/SSU2.h
  3. 7
      libi2pd/SSU2Session.cpp

21
libi2pd/SSU2.cpp

@ -24,7 +24,8 @@ namespace transport @@ -24,7 +24,8 @@ namespace transport
m_AddressV4 (boost::asio::ip::address_v4()), m_AddressV6 (boost::asio::ip::address_v6()),
m_TerminationTimer (GetService ()), m_CleanupTimer (GetService ()), m_ResendTimer (GetService ()),
m_IntroducersUpdateTimer (GetService ()), m_IntroducersUpdateTimerV6 (GetService ()),
m_IsPublished (true), m_IsSyncClockFromPeers (true), m_IsThroughProxy (false)
m_IsPublished (true), m_IsSyncClockFromPeers (true), m_PendingTimeOffset (0),
m_IsThroughProxy (false)
{
}
@ -209,6 +210,24 @@ namespace transport @@ -209,6 +210,24 @@ namespace transport
return ep.port ();
}
void SSU2Server::AdjustTimeOffset (int64_t offset)
{
if (offset)
{
if (m_PendingTimeOffset) // one more
{
offset = (m_PendingTimeOffset + offset)/2; // average
LogPrint (eLogWarning, "SSU2: Clock adjusted by ", -offset, " seconds");
i2p::util::AdjustTimeOffset (-offset);
m_PendingTimeOffset = 0;
}
else
m_PendingTimeOffset = offset; // first
}
else
m_PendingTimeOffset = 0; // reset
}
boost::asio::ip::udp::socket& SSU2Server::OpenSocket (const boost::asio::ip::udp::endpoint& localEndpoint)
{
boost::asio::ip::udp::socket& socket = localEndpoint.address ().is_v6 () ? m_SocketV6 : m_SocketV4;

2
libi2pd/SSU2.h

@ -66,6 +66,7 @@ namespace transport @@ -66,6 +66,7 @@ namespace transport
bool IsSupported (const boost::asio::ip::address& addr) const;
uint16_t GetPort (bool v4) const;
bool IsSyncClockFromPeers () const { return m_IsSyncClockFromPeers; };
void AdjustTimeOffset (int64_t offset);
void AddSession (std::shared_ptr<SSU2Session> session);
void RemoveSession (uint64_t connID);
@ -161,6 +162,7 @@ namespace transport @@ -161,6 +162,7 @@ namespace transport
std::shared_ptr<SSU2Session> m_LastSession;
bool m_IsPublished; // if we maintain introducers
bool m_IsSyncClockFromPeers;
int64_t m_PendingTimeOffset; // during peer test
// proxy
bool m_IsThroughProxy;

7
libi2pd/SSU2Session.cpp

@ -1668,10 +1668,7 @@ namespace transport @@ -1668,10 +1668,7 @@ namespace transport
if (m_Server.IsSyncClockFromPeers ())
{
if (std::abs (offset) > SSU2_CLOCK_THRESHOLD)
{
LogPrint (eLogWarning, "SSU2: Clock adjusted by ", -offset, " seconds");
i2p::util::AdjustTimeOffset (-offset);
}
m_Server.AdjustTimeOffset (-offset);
}
else if (std::abs (offset) > SSU2_CLOCK_SKEW)
{
@ -2481,6 +2478,8 @@ namespace transport @@ -2481,6 +2478,8 @@ namespace transport
else if (m_Address->IsV6 ())
i2p::context.SetTestingV6 (testing);
}
if (!testing)
m_Server.AdjustTimeOffset (0); // reset time offset when testing is over
}
size_t SSU2Session::CreateAddressBlock (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& ep)

Loading…
Cancel
Save