mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
send updated local RouterInfo for long sessions
This commit is contained in:
parent
5bb20cb039
commit
c348736058
|
@ -415,9 +415,10 @@ namespace transport
|
||||||
auto r = netdb.FindRouter (ident);
|
auto r = netdb.FindRouter (ident);
|
||||||
if (r && (r->IsUnreachable () || !r->IsReachableFrom (i2p::context.GetRouterInfo ()))) return; // router found but non-reachable
|
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);
|
std::unique_lock<std::mutex> l(m_PeersMutex);
|
||||||
it = m_Peers.insert (std::pair<i2p::data::IdentHash, Peer>(ident, { 0, r, {},
|
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);
|
connected = ConnectToPeer (ident, it->second);
|
||||||
}
|
}
|
||||||
|
@ -753,8 +754,10 @@ namespace transport
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
session->SendI2NPMessages ({ CreateDatabaseStoreMsg () }); // send DatabaseStore
|
session->SendI2NPMessages ({ CreateDatabaseStoreMsg () }); // send DatabaseStore
|
||||||
std::unique_lock<std::mutex> l(m_PeersMutex);
|
auto ts = i2p::util::GetSecondsSinceEpoch ();
|
||||||
m_Peers.insert (std::make_pair (ident, Peer{ 0, nullptr, { session }, 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
|
||||||
it = m_Peers.erase (it);
|
it = m_Peers.erase (it);
|
||||||
}
|
}
|
||||||
else
|
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;
|
++it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
UpdateBandwidth (); // TODO: use separate timer(s) for it
|
UpdateBandwidth (); // TODO: use separate timer(s) for it
|
||||||
bool ipv4Testing = i2p::context.GetStatus () == eRouterStatusTesting;
|
bool ipv4Testing = i2p::context.GetStatus () == eRouterStatusTesting;
|
||||||
|
|
|
@ -62,12 +62,14 @@ namespace transport
|
||||||
};
|
};
|
||||||
typedef EphemeralKeysSupplier<i2p::crypto::X25519Keys> X25519KeysPairSupplier;
|
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
|
struct Peer
|
||||||
{
|
{
|
||||||
int numAttempts;
|
int numAttempts;
|
||||||
std::shared_ptr<const i2p::data::RouterInfo> router;
|
std::shared_ptr<const i2p::data::RouterInfo> router;
|
||||||
std::list<std::shared_ptr<TransportSession> > sessions;
|
std::list<std::shared_ptr<TransportSession> > sessions;
|
||||||
uint64_t creationTime;
|
uint64_t creationTime, nextRouterInfoUpdateTime;
|
||||||
std::vector<std::shared_ptr<i2p::I2NPMessage> > delayedMessages;
|
std::vector<std::shared_ptr<i2p::I2NPMessage> > delayedMessages;
|
||||||
|
|
||||||
void Done ()
|
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 PEER_TEST_INTERVAL = 71; // in minutes
|
||||||
const int MAX_NUM_DELAYED_MESSAGES = 150;
|
const int MAX_NUM_DELAYED_MESSAGES = 150;
|
||||||
class Transports
|
class Transports
|
||||||
|
|
Loading…
Reference in a new issue