MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / HandlePeerCleanupTimer

Method HandlePeerCleanupTimer

libi2pd/Transports.cpp:1066–1115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1064 }
1065
1066 void Transports::HandlePeerCleanupTimer (const boost::system::error_code& ecode)
1067 {
1068 if (ecode != boost::asio::error::operation_aborted)
1069 {
1070 auto ts = i2p::util::GetSecondsSinceEpoch ();
1071 for (auto it = m_Peers.begin (); it != m_Peers.end (); )
1072 {
1073 it->second->sessions.remove_if (
1074 [](std::shared_ptr<TransportSession> session)->bool
1075 {
1076 return !session || !session->IsEstablished ();
1077 });
1078 if (!it->second->IsConnected () && ts > it->second->creationTime + SESSION_CREATION_TIMEOUT)
1079 {
1080 LogPrint (eLogWarning, "Transports: Session to peer ", it->first.ToBase64 (), " has not been created in ", SESSION_CREATION_TIMEOUT, " seconds");
1081 /* if (!it->second.router)
1082 {
1083 // if router for ident not found mark it unreachable
1084 auto profile = i2p::data::GetRouterProfile (it->first);
1085 if (profile) profile->Unreachable ();
1086 } */
1087 std::lock_guard<std::mutex> l(m_PeersMutex);
1088 it = m_Peers.erase (it);
1089 }
1090 else
1091 {
1092 if (ts > it->second->nextRouterInfoUpdateTime)
1093 {
1094 auto session = it->second->sessions.front ();
1095 if (session)
1096 session->SendLocalRouterInfo (true);
1097 it->second->nextRouterInfoUpdateTime = ts + PEER_ROUTER_INFO_UPDATE_INTERVAL +
1098 m_Rng() % PEER_ROUTER_INFO_UPDATE_INTERVAL_VARIANCE;
1099 }
1100 ++it;
1101 }
1102 }
1103 bool ipv4Testing = i2p::context.GetTesting ();
1104 if (!ipv4Testing)
1105 ipv4Testing = i2p::context.GetRouterInfo ().IsSSU2V4 () && (i2p::context.GetStatus() == eRouterStatusUnknown);
1106 bool ipv6Testing = i2p::context.GetTestingV6 ();
1107 if (!ipv6Testing)
1108 ipv6Testing = i2p::context.GetRouterInfo ().IsSSU2V6 () && (i2p::context.GetStatusV6() == eRouterStatusUnknown);
1109 // if still testing or unknown, repeat peer test
1110 if (ipv4Testing || ipv6Testing)
1111 PeerTest (ipv4Testing, ipv6Testing);
1112 m_PeerCleanupTimer->expires_after (std::chrono::seconds(2 * SESSION_CREATION_TIMEOUT + m_Rng() % SESSION_CREATION_TIMEOUT));
1113 m_PeerCleanupTimer->async_wait (std::bind (&Transports::HandlePeerCleanupTimer, this, std::placeholders::_1));
1114 }
1115 }
1116
1117 void Transports::HandlePeerTestTimer (const boost::system::error_code& ecode)
1118 {

Callers

nothing calls this directly

Calls 12

GetSecondsSinceEpochFunction · 0.85
LogPrintFunction · 0.85
ToBase64Method · 0.80
GetTestingMethod · 0.80
IsSSU2V4Method · 0.80
GetTestingV6Method · 0.80
IsSSU2V6Method · 0.80
GetStatusV6Method · 0.80
IsEstablishedMethod · 0.45
IsConnectedMethod · 0.45
SendLocalRouterInfoMethod · 0.45
GetStatusMethod · 0.45

Tested by

no test coverage detected