From c348736058a94ad2dc19792fac24b9d6a376ed6c Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 19 Jun 2022 14:21:35 -0400 Subject: [PATCH] send updated local RouterInfo for long sessions --- libi2pd/Transports.cpp | 19 ++++++++++++++++--- libi2pd/Transports.h | 6 ++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/libi2pd/Transports.cpp b/libi2pd/Transports.cpp index 32651904..31abad6e 100644 --- a/libi2pd/Transports.cpp +++ b/libi2pd/Transports.cpp @@ -415,9 +415,10 @@ namespace transport auto r = netdb.FindRouter (ident); if (r && (r->IsUnreachable () || !r->IsReachableFrom (i2p::context.GetRouterInfo ()))) return; // router found but non-reachable { + auto ts = i2p::util::GetSecondsSinceEpoch (); std::unique_lock l(m_PeersMutex); it = m_Peers.insert (std::pair(ident, { 0, r, {}, - i2p::util::GetSecondsSinceEpoch (), {} })).first; + ts, ts + PEER_ROUTER_INFO_UPDATE_INTERVAL, {} })).first; } connected = ConnectToPeer (ident, it->second); } @@ -753,8 +754,10 @@ namespace transport return; } session->SendI2NPMessages ({ CreateDatabaseStoreMsg () }); // send DatabaseStore - std::unique_lock l(m_PeersMutex); - m_Peers.insert (std::make_pair (ident, Peer{ 0, nullptr, { session }, i2p::util::GetSecondsSinceEpoch (), {} })); + auto ts = i2p::util::GetSecondsSinceEpoch (); + std::unique_lock l(m_PeersMutex); + m_Peers.insert (std::make_pair (ident, Peer{ 0, nullptr, { session }, + ts, ts + PEER_ROUTER_INFO_UPDATE_INTERVAL, {} })); } }); } @@ -815,7 +818,17 @@ namespace transport it = m_Peers.erase (it); } else + { + if (ts > it->second.nextRouterInfoUpdateTime) + { + auto session = it->second.sessions.front (); + if (session) + session->SendLocalRouterInfo (true); + it->second.nextRouterInfoUpdateTime = ts + PEER_ROUTER_INFO_UPDATE_INTERVAL + + rand () % PEER_ROUTER_INFO_UPDATE_INTERVAL_VARIANCE; + } ++it; + } } UpdateBandwidth (); // TODO: use separate timer(s) for it bool ipv4Testing = i2p::context.GetStatus () == eRouterStatusTesting; diff --git a/libi2pd/Transports.h b/libi2pd/Transports.h index 80d1855e..8fdf6055 100644 --- a/libi2pd/Transports.h +++ b/libi2pd/Transports.h @@ -62,12 +62,14 @@ namespace transport }; typedef EphemeralKeysSupplier X25519KeysPairSupplier; + const int PEER_ROUTER_INFO_UPDATE_INTERVAL = 31*60; // in seconds + const int PEER_ROUTER_INFO_UPDATE_INTERVAL_VARIANCE = 7*60; // in seconds struct Peer { int numAttempts; std::shared_ptr router; std::list > sessions; - uint64_t creationTime; + uint64_t creationTime, nextRouterInfoUpdateTime; std::vector > delayedMessages; void Done () @@ -77,7 +79,7 @@ namespace transport } }; - const size_t SESSION_CREATION_TIMEOUT = 15; // in seconds + const uint64_t SESSION_CREATION_TIMEOUT = 15; // in seconds const int PEER_TEST_INTERVAL = 71; // in minutes const int MAX_NUM_DELAYED_MESSAGES = 150; class Transports