cleanup RelayRequests

pull/1696/head
orignal 3 years ago
parent 8debdc264c
commit 18b6ba80f2

@ -930,7 +930,8 @@ namespace transport
void SSUServer::ScheduleTermination ()
{
m_TerminationTimer.expires_from_now (boost::posix_time::seconds(SSU_TERMINATION_CHECK_TIMEOUT));
uint64_t timeout = SSU_TERMINATION_CHECK_TIMEOUT + (rand () % SSU_TERMINATION_CHECK_TIMEOUT)/5;
m_TerminationTimer.expires_from_now (boost::posix_time::seconds(timeout));
m_TerminationTimer.async_wait (std::bind (&SSUServer::HandleTerminationTimer,
this, std::placeholders::_1));
}
@ -953,14 +954,15 @@ namespace transport
});
}
else
it.second->CleanUp ();
it.second->CleanUp (ts);
ScheduleTermination ();
}
}
void SSUServer::ScheduleTerminationV6 ()
{
m_TerminationTimerV6.expires_from_now (boost::posix_time::seconds(SSU_TERMINATION_CHECK_TIMEOUT));
uint64_t timeout = SSU_TERMINATION_CHECK_TIMEOUT + (rand () % SSU_TERMINATION_CHECK_TIMEOUT)/5;
m_TerminationTimerV6.expires_from_now (boost::posix_time::seconds(timeout));
m_TerminationTimerV6.async_wait (std::bind (&SSUServer::HandleTerminationTimerV6,
this, std::placeholders::_1));
}
@ -983,7 +985,7 @@ namespace transport
});
}
else
it.second->CleanUp ();
it.second->CleanUp (ts);
ScheduleTerminationV6 ();
}
}

@ -484,9 +484,8 @@ namespace transport
}
}
void SSUData::CleanUp ()
void SSUData::CleanUp (uint64_t ts)
{
uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
for (auto it = m_IncompleteMessages.begin (); it != m_IncompleteMessages.end ();)
{
if (ts > it->second->lastFragmentInsertTime + INCOMPLETE_MESSAGES_CLEANUP_TIMEOUT)

@ -100,7 +100,7 @@ namespace transport
void Start ();
void Stop ();
void CleanUp ();
void CleanUp (uint64_t ts);
void ProcessMessage (uint8_t * buf, size_t len);
void FlushReceivedMessage ();

@ -730,7 +730,7 @@ namespace transport
(remoteIP.is_v6 () && i2p::context.GetStatusV6 () == eRouterStatusFirewalled))
m_Server.Send (buf, 0, remoteEndpoint); // send HolePunch
// we assume that HolePunch has been sent by this time and our SessionRequest will go through
m_Server.CreateDirectSession (it->second, remoteEndpoint, false);
m_Server.CreateDirectSession (it->second.first, remoteEndpoint, false);
}
// delete request
m_RelayRequests.erase (it);
@ -905,7 +905,8 @@ namespace transport
}
uint32_t nonce;
RAND_bytes ((uint8_t *)&nonce, 4);
m_RelayRequests[nonce] = to;
auto ts = i2p::util::GetSecondsSinceEpoch ();
m_RelayRequests.emplace (nonce, std::make_pair (to, ts));
SendRelayRequest (introducer, nonce);
}
@ -1004,10 +1005,16 @@ namespace transport
}
}
void SSUSession::CleanUp ()
void SSUSession::CleanUp (uint64_t ts)
{
m_Data.CleanUp ();
// TODO: clean up m_RelayRequests
m_Data.CleanUp (ts);
for (auto it = m_RelayRequests.begin (); it != m_RelayRequests.end ();)
{
if (ts > it->second.second + SSU_CONNECT_TIMEOUT)
it = m_RelayRequests.erase (it);
else
++it;
}
}
void SSUSession::ProcessPeerTest (const uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint)

@ -106,7 +106,7 @@ namespace transport
void SetCreationTime (uint32_t ts) { m_CreationTime = ts; }; // for introducers
void FlushData ();
void CleanUp ();
void CleanUp (uint64_t ts);
private:
@ -170,7 +170,7 @@ namespace transport
SSUData m_Data;
bool m_IsDataReceived;
std::unique_ptr<SignedData> m_SignedData; // we need it for SessionConfirmed only
std::map<uint32_t, std::shared_ptr<const i2p::data::RouterInfo> > m_RelayRequests; // nonce->Charlie
std::unordered_map<uint32_t, std::pair <std::shared_ptr<const i2p::data::RouterInfo>, uint64_t > > m_RelayRequests; // nonce->(Charlie, timestamp)
std::shared_ptr<i2p::crypto::DHKeys> m_DHKeysPair; // X - for client and Y - for server
};
}

Loading…
Cancel
Save