Browse Source

send updated local RouterInfo for long sessions

pull/1769/head
orignal 3 years ago
parent
commit
c348736058
  1. 19
      libi2pd/Transports.cpp
  2. 6
      libi2pd/Transports.h

19
libi2pd/Transports.cpp

@ -415,9 +415,10 @@ namespace transport @@ -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<std::mutex> l(m_PeersMutex);
it = m_Peers.insert (std::pair<i2p::data::IdentHash, Peer>(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 @@ -753,8 +754,10 @@ namespace transport
return;
}
session->SendI2NPMessages ({ CreateDatabaseStoreMsg () }); // send DatabaseStore
std::unique_lock<std::mutex> 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<std::mutex> 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 @@ -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;

6
libi2pd/Transports.h

@ -62,12 +62,14 @@ namespace transport @@ -62,12 +62,14 @@ namespace transport
};
typedef EphemeralKeysSupplier<i2p::crypto::X25519Keys> 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<const i2p::data::RouterInfo> router;
std::list<std::shared_ptr<TransportSession> > sessions;
uint64_t creationTime;
uint64_t creationTime, nextRouterInfoUpdateTime;
std::vector<std::shared_ptr<i2p::I2NPMessage> > delayedMessages;
void Done ()
@ -77,7 +79,7 @@ namespace transport @@ -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

Loading…
Cancel
Save