Browse Source

cleanup RelayRequests

pull/1696/head
orignal 3 years ago
parent
commit
18b6ba80f2
  1. 10
      libi2pd/SSU.cpp
  2. 3
      libi2pd/SSUData.cpp
  3. 2
      libi2pd/SSUData.h
  4. 17
      libi2pd/SSUSession.cpp
  5. 4
      libi2pd/SSUSession.h

10
libi2pd/SSU.cpp

@ -930,7 +930,8 @@ namespace transport
void SSUServer::ScheduleTermination () 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, m_TerminationTimer.async_wait (std::bind (&SSUServer::HandleTerminationTimer,
this, std::placeholders::_1)); this, std::placeholders::_1));
} }
@ -953,14 +954,15 @@ namespace transport
}); });
} }
else else
it.second->CleanUp (); it.second->CleanUp (ts);
ScheduleTermination (); ScheduleTermination ();
} }
} }
void SSUServer::ScheduleTerminationV6 () 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, m_TerminationTimerV6.async_wait (std::bind (&SSUServer::HandleTerminationTimerV6,
this, std::placeholders::_1)); this, std::placeholders::_1));
} }
@ -983,7 +985,7 @@ namespace transport
}); });
} }
else else
it.second->CleanUp (); it.second->CleanUp (ts);
ScheduleTerminationV6 (); ScheduleTerminationV6 ();
} }
} }

3
libi2pd/SSUData.cpp

@ -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 ();) for (auto it = m_IncompleteMessages.begin (); it != m_IncompleteMessages.end ();)
{ {
if (ts > it->second->lastFragmentInsertTime + INCOMPLETE_MESSAGES_CLEANUP_TIMEOUT) if (ts > it->second->lastFragmentInsertTime + INCOMPLETE_MESSAGES_CLEANUP_TIMEOUT)

2
libi2pd/SSUData.h

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

17
libi2pd/SSUSession.cpp

@ -730,7 +730,7 @@ namespace transport
(remoteIP.is_v6 () && i2p::context.GetStatusV6 () == eRouterStatusFirewalled)) (remoteIP.is_v6 () && i2p::context.GetStatusV6 () == eRouterStatusFirewalled))
m_Server.Send (buf, 0, remoteEndpoint); // send HolePunch m_Server.Send (buf, 0, remoteEndpoint); // send HolePunch
// we assume that HolePunch has been sent by this time and our SessionRequest will go through // 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 // delete request
m_RelayRequests.erase (it); m_RelayRequests.erase (it);
@ -905,7 +905,8 @@ namespace transport
} }
uint32_t nonce; uint32_t nonce;
RAND_bytes ((uint8_t *)&nonce, 4); 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); SendRelayRequest (introducer, nonce);
} }
@ -1004,10 +1005,16 @@ namespace transport
} }
} }
void SSUSession::CleanUp () void SSUSession::CleanUp (uint64_t ts)
{ {
m_Data.CleanUp (); m_Data.CleanUp (ts);
// TODO: clean up m_RelayRequests 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) void SSUSession::ProcessPeerTest (const uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint)

4
libi2pd/SSUSession.h

@ -106,7 +106,7 @@ namespace transport
void SetCreationTime (uint32_t ts) { m_CreationTime = ts; }; // for introducers void SetCreationTime (uint32_t ts) { m_CreationTime = ts; }; // for introducers
void FlushData (); void FlushData ();
void CleanUp (); void CleanUp (uint64_t ts);
private: private:
@ -170,7 +170,7 @@ namespace transport
SSUData m_Data; SSUData m_Data;
bool m_IsDataReceived; bool m_IsDataReceived;
std::unique_ptr<SignedData> m_SignedData; // we need it for SessionConfirmed only 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 std::shared_ptr<i2p::crypto::DHKeys> m_DHKeysPair; // X - for client and Y - for server
}; };
} }

Loading…
Cancel
Save