mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
check if peer is connected before trying to connect
This commit is contained in:
parent
39e378a03d
commit
1e5604ed43
@ -458,7 +458,7 @@ namespace transport
|
||||
}
|
||||
if (!connected) return;
|
||||
}
|
||||
if (!it->second.sessions.empty ())
|
||||
if (it->second.IsConnected ())
|
||||
it->second.sessions.front ()->SendI2NPMessages (msgs);
|
||||
else
|
||||
{
|
||||
@ -616,7 +616,8 @@ namespace transport
|
||||
{
|
||||
LogPrint (eLogDebug, "Transports: RouterInfo for ", ident.ToBase64 (), " found, trying to connect");
|
||||
it->second.SetRouter (r);
|
||||
ConnectToPeer (ident, it->second);
|
||||
if (!it->second.IsConnected ())
|
||||
ConnectToPeer (ident, it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -810,13 +811,13 @@ namespace transport
|
||||
auto it = m_Peers.find (ident);
|
||||
if (it != m_Peers.end ())
|
||||
{
|
||||
auto before = it->second.sessions.size ();
|
||||
bool wasConnected = it->second.IsConnected ();
|
||||
it->second.sessions.remove (session);
|
||||
if (it->second.sessions.empty ())
|
||||
if (!it->second.IsConnected ())
|
||||
{
|
||||
if (it->second.delayedMessages.size () > 0)
|
||||
{
|
||||
if (before > 0) // we had an active session before
|
||||
if (wasConnected) // we had an active session before
|
||||
it->second.numAttempts = 0; // start over
|
||||
ConnectToPeer (ident, it->second);
|
||||
}
|
||||
@ -849,7 +850,7 @@ namespace transport
|
||||
{
|
||||
return !session || !session->IsEstablished ();
|
||||
});
|
||||
if (it->second.sessions.empty () && ts > it->second.creationTime + SESSION_CREATION_TIMEOUT)
|
||||
if (!it->second.IsConnected () && ts > it->second.creationTime + SESSION_CREATION_TIMEOUT)
|
||||
{
|
||||
LogPrint (eLogWarning, "Transports: Session to peer ", it->first.ToBase64 (), " has not been created in ", SESSION_CREATION_TIMEOUT, " seconds");
|
||||
/* if (!it->second.router)
|
||||
@ -991,7 +992,7 @@ namespace transport
|
||||
[isHighBandwidth](const Peer& peer)->bool
|
||||
{
|
||||
// connected, not overloaded and not slow
|
||||
return !peer.router && !peer.sessions.empty () && peer.isReachable &&
|
||||
return !peer.router && peer.IsConnected () && peer.isReachable &&
|
||||
peer.sessions.front ()->GetSendQueueSize () <= PEER_ROUTER_INFO_OVERLOAD_QUEUE_SIZE &&
|
||||
!peer.sessions.front ()->IsSlow () && !peer.sessions.front ()->IsBandwidthExceeded (peer.isHighBandwidth) &&
|
||||
(!isHighBandwidth || peer.isHighBandwidth);
|
||||
|
@ -101,6 +101,8 @@ namespace transport
|
||||
isReachable = (bool)router->GetCompatibleTransports (true);
|
||||
}
|
||||
}
|
||||
|
||||
bool IsConnected () const { return !sessions.empty (); }
|
||||
};
|
||||
|
||||
const uint64_t SESSION_CREATION_TIMEOUT = 15; // in seconds
|
||||
|
Loading…
Reference in New Issue
Block a user