MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / AdjustTimeOffset

Method AdjustTimeOffset

libi2pd/SSU2.cpp:247–281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245 }
246
247 void SSU2Server::AdjustTimeOffset (int64_t offset, std::shared_ptr<const i2p::data::IdentityEx> from)
248 {
249 if (offset)
250 {
251 if (m_PendingTimeOffset) // one more
252 {
253 if (m_PendingTimeOffsetFrom && from &&
254 m_PendingTimeOffsetFrom->GetIdentHash ().GetLL()[0] != from->GetIdentHash ().GetLL()[0]) // from different routers
255 {
256 if (std::abs (m_PendingTimeOffset - offset) < SSU2_CLOCK_SKEW)
257 {
258 offset = (m_PendingTimeOffset + offset)/2; // average
259 LogPrint (eLogWarning, "SSU2: Clock adjusted by ", offset, " seconds");
260 i2p::util::AdjustTimeOffset (offset);
261 }
262 else
263 LogPrint (eLogWarning, "SSU2: Time offsets are too different. Clock not adjusted");
264 m_PendingTimeOffset = 0;
265 m_PendingTimeOffsetFrom = nullptr;
266 }
267 else
268 LogPrint (eLogWarning, "SSU2: Time offsets from same router. Clock not adjusted");
269 }
270 else
271 {
272 m_PendingTimeOffset = offset; // first
273 m_PendingTimeOffsetFrom = from;
274 }
275 }
276 else
277 {
278 m_PendingTimeOffset = 0; // reset
279 m_PendingTimeOffsetFrom = nullptr;
280 }
281 }
282
283 boost::asio::ip::udp::socket& SSU2Server::OpenSocket (const boost::asio::ip::udp::endpoint& localEndpoint)
284 {

Callers 2

HandleDateTimeMethod · 0.80
SetTestingStateMethod · 0.80

Calls 2

LogPrintFunction · 0.85
AdjustTimeOffsetFunction · 0.85

Tested by

no test coverage detected