Browse Source

connected recently mutex

pull/2117/head
orignal 1 month ago
parent
commit
ddf30784ec
  1. 2
      libi2pd/SSU2.cpp
  2. 1
      libi2pd/SSU2.h

2
libi2pd/SSU2.cpp

@ -219,6 +219,7 @@ namespace transport
bool SSU2Server::IsConnectedRecently (const boost::asio::ip::udp::endpoint& ep) bool SSU2Server::IsConnectedRecently (const boost::asio::ip::udp::endpoint& ep)
{ {
if (!ep.port () || ep.address ().is_unspecified ()) return false; if (!ep.port () || ep.address ().is_unspecified ()) return false;
std::lock_guard<std::mutex> l(m_ConnectedRecentlyMutex);
auto it = m_ConnectedRecently.find (ep); auto it = m_ConnectedRecently.find (ep);
if (it != m_ConnectedRecently.end ()) if (it != m_ConnectedRecently.end ())
{ {
@ -234,6 +235,7 @@ namespace transport
{ {
if (!ep.port () || ep.address ().is_unspecified () || if (!ep.port () || ep.address ().is_unspecified () ||
i2p::util::GetSecondsSinceEpoch () > ts + SSU2_HOLE_PUNCH_EXPIRATION) return; i2p::util::GetSecondsSinceEpoch () > ts + SSU2_HOLE_PUNCH_EXPIRATION) return;
std::lock_guard<std::mutex> l(m_ConnectedRecentlyMutex);
auto [it, added] = m_ConnectedRecently.try_emplace (ep, ts); auto [it, added] = m_ConnectedRecently.try_emplace (ep, ts);
if (!added && ts > it->second) if (!added && ts > it->second)
it->second = ts; // renew timestamp of existing endpoint it->second = ts; // renew timestamp of existing endpoint

1
libi2pd/SSU2.h

@ -194,6 +194,7 @@ namespace transport
std::shared_ptr<const i2p::data::IdentityEx> m_PendingTimeOffsetFrom; std::shared_ptr<const i2p::data::IdentityEx> m_PendingTimeOffsetFrom;
std::mt19937 m_Rng; std::mt19937 m_Rng;
std::map<boost::asio::ip::udp::endpoint, uint64_t> m_ConnectedRecently; // endpoint -> last activity time in seconds std::map<boost::asio::ip::udp::endpoint, uint64_t> m_ConnectedRecently; // endpoint -> last activity time in seconds
mutable std::mutex m_ConnectedRecentlyMutex;
std::unordered_map<uint32_t, std::pair <std::weak_ptr<SSU2PeerTestSession>, uint64_t > > m_RequestedPeerTests; // nonce->(Alice, timestamp) std::unordered_map<uint32_t, std::pair <std::weak_ptr<SSU2PeerTestSession>, uint64_t > > m_RequestedPeerTests; // nonce->(Alice, timestamp)
std::list<Packet *> m_ReceivedPacketsQueue; std::list<Packet *> m_ReceivedPacketsQueue;
mutable std::mutex m_ReceivedPacketsQueueMutex; mutable std::mutex m_ReceivedPacketsQueueMutex;

Loading…
Cancel
Save