mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
don't adjust clock if offsets came from same router
This commit is contained in:
parent
c5a1806528
commit
70639f1139
|
@ -210,27 +210,40 @@ namespace transport
|
||||||
return ep.port ();
|
return ep.port ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSU2Server::AdjustTimeOffset (int64_t offset)
|
void SSU2Server::AdjustTimeOffset (int64_t offset, std::shared_ptr<const i2p::data::IdentityEx> from)
|
||||||
{
|
{
|
||||||
if (offset)
|
if (offset)
|
||||||
{
|
{
|
||||||
if (m_PendingTimeOffset) // one more
|
if (m_PendingTimeOffset) // one more
|
||||||
{
|
{
|
||||||
if (std::abs (m_PendingTimeOffset - offset) < SSU2_CLOCK_SKEW)
|
if (m_PendingTimeOffsetFrom && from &&
|
||||||
|
m_PendingTimeOffsetFrom->GetIdentHash ().GetLL()[0] != from->GetIdentHash ().GetLL()[0]) // from different routers
|
||||||
{
|
{
|
||||||
offset = (m_PendingTimeOffset + offset)/2; // average
|
if (std::abs (m_PendingTimeOffset - offset) < SSU2_CLOCK_SKEW)
|
||||||
LogPrint (eLogWarning, "SSU2: Clock adjusted by ", offset, " seconds");
|
{
|
||||||
i2p::util::AdjustTimeOffset (offset);
|
offset = (m_PendingTimeOffset + offset)/2; // average
|
||||||
|
LogPrint (eLogWarning, "SSU2: Clock adjusted by ", offset, " seconds");
|
||||||
|
i2p::util::AdjustTimeOffset (offset);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint (eLogWarning, "SSU2: Time offsets are too different. Clock not adjusted");
|
||||||
|
m_PendingTimeOffset = 0;
|
||||||
|
m_PendingTimeOffsetFrom = nullptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LogPrint (eLogWarning, "SSU2: Time offsets are too different. Clock not adjusted");
|
LogPrint (eLogWarning, "SSU2: Time offsets from same router. Clock not adjusted");
|
||||||
m_PendingTimeOffset = 0;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
m_PendingTimeOffset = offset; // first
|
m_PendingTimeOffset = offset; // first
|
||||||
|
m_PendingTimeOffsetFrom = from;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
m_PendingTimeOffset = 0; // reset
|
m_PendingTimeOffset = 0; // reset
|
||||||
|
m_PendingTimeOffsetFrom = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::asio::ip::udp::socket& SSU2Server::OpenSocket (const boost::asio::ip::udp::endpoint& localEndpoint)
|
boost::asio::ip::udp::socket& SSU2Server::OpenSocket (const boost::asio::ip::udp::endpoint& localEndpoint)
|
||||||
|
|
|
@ -67,7 +67,7 @@ namespace transport
|
||||||
bool IsSupported (const boost::asio::ip::address& addr) const;
|
bool IsSupported (const boost::asio::ip::address& addr) const;
|
||||||
uint16_t GetPort (bool v4) const;
|
uint16_t GetPort (bool v4) const;
|
||||||
bool IsSyncClockFromPeers () const { return m_IsSyncClockFromPeers; };
|
bool IsSyncClockFromPeers () const { return m_IsSyncClockFromPeers; };
|
||||||
void AdjustTimeOffset (int64_t offset);
|
void AdjustTimeOffset (int64_t offset, std::shared_ptr<const i2p::data::IdentityEx> from);
|
||||||
|
|
||||||
void AddSession (std::shared_ptr<SSU2Session> session);
|
void AddSession (std::shared_ptr<SSU2Session> session);
|
||||||
void RemoveSession (uint64_t connID);
|
void RemoveSession (uint64_t connID);
|
||||||
|
@ -164,6 +164,7 @@ namespace transport
|
||||||
bool m_IsPublished; // if we maintain introducers
|
bool m_IsPublished; // if we maintain introducers
|
||||||
bool m_IsSyncClockFromPeers;
|
bool m_IsSyncClockFromPeers;
|
||||||
int64_t m_PendingTimeOffset; // during peer test
|
int64_t m_PendingTimeOffset; // during peer test
|
||||||
|
std::shared_ptr<const i2p::data::IdentityEx> m_PendingTimeOffsetFrom;
|
||||||
|
|
||||||
// proxy
|
// proxy
|
||||||
bool m_IsThroughProxy;
|
bool m_IsThroughProxy;
|
||||||
|
|
|
@ -1671,10 +1671,10 @@ namespace transport
|
||||||
if (std::abs (offset) > SSU2_CLOCK_THRESHOLD)
|
if (std::abs (offset) > SSU2_CLOCK_THRESHOLD)
|
||||||
{
|
{
|
||||||
LogPrint (eLogWarning, "SSU2: Time offset ", offset, " from ", m_RemoteEndpoint);
|
LogPrint (eLogWarning, "SSU2: Time offset ", offset, " from ", m_RemoteEndpoint);
|
||||||
m_Server.AdjustTimeOffset (-offset);
|
m_Server.AdjustTimeOffset (-offset, GetRemoteIdentity ());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_Server.AdjustTimeOffset (0);
|
m_Server.AdjustTimeOffset (0, nullptr);
|
||||||
}
|
}
|
||||||
else if (std::abs (offset) > SSU2_CLOCK_SKEW)
|
else if (std::abs (offset) > SSU2_CLOCK_SKEW)
|
||||||
{
|
{
|
||||||
|
@ -2485,7 +2485,7 @@ namespace transport
|
||||||
i2p::context.SetTestingV6 (testing);
|
i2p::context.SetTestingV6 (testing);
|
||||||
}
|
}
|
||||||
if (!testing)
|
if (!testing)
|
||||||
m_Server.AdjustTimeOffset (0); // reset time offset when testing is over
|
m_Server.AdjustTimeOffset (0, nullptr); // reset time offset when testing is over
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t SSU2Session::CreateAddressBlock (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& ep)
|
size_t SSU2Session::CreateAddressBlock (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& ep)
|
||||||
|
|
Loading…
Reference in a new issue