Browse Source

check if peer is connected before trying to connect

pull/2010/head
orignal 11 months ago
parent
commit
1e5604ed43
  1. 13
      libi2pd/Transports.cpp
  2. 2
      libi2pd/Transports.h

13
libi2pd/Transports.cpp

@ -458,7 +458,7 @@ namespace transport @@ -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,6 +616,7 @@ namespace transport @@ -616,6 +616,7 @@ namespace transport
{
LogPrint (eLogDebug, "Transports: RouterInfo for ", ident.ToBase64 (), " found, trying to connect");
it->second.SetRouter (r);
if (!it->second.IsConnected ())
ConnectToPeer (ident, it->second);
}
else
@ -810,13 +811,13 @@ namespace transport @@ -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 @@ -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 @@ -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);

2
libi2pd/Transports.h

@ -101,6 +101,8 @@ namespace transport @@ -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…
Cancel
Save