diff --git a/SSU.cpp b/SSU.cpp index 198fed4b..7950dc45 100644 --- a/SSU.cpp +++ b/SSU.cpp @@ -159,6 +159,11 @@ namespace transport m_Relays[tag] = relay; } + void SSUServer::RemoveRelay (uint32_t tag) + { + m_Relays.erase (tag); + } + std::shared_ptr SSUServer::FindRelaySession (uint32_t tag) { auto it = m_Relays.find (tag); diff --git a/SSU.h b/SSU.h index 9d8e2878..8753ff77 100644 --- a/SSU.h +++ b/SSU.h @@ -58,6 +58,7 @@ namespace transport const boost::asio::ip::udp::endpoint& GetEndpoint () const { return m_Endpoint; }; void Send (const uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& to); void AddRelay (uint32_t tag, const boost::asio::ip::udp::endpoint& relay); + void RemoveRelay (uint32_t tag); std::shared_ptr FindRelaySession (uint32_t tag); void NewPeerTest (uint32_t nonce, PeerTestParticipant role, std::shared_ptr session = nullptr); diff --git a/SSUSession.cpp b/SSUSession.cpp index 0e277432..e67ff1de 100644 --- a/SSUSession.cpp +++ b/SSUSession.cpp @@ -16,7 +16,7 @@ namespace transport TransportSession (router, SSU_TERMINATION_TIMEOUT), m_Server (server), m_RemoteEndpoint (remoteEndpoint), m_ConnectTimer (GetService ()), m_IsPeerTest (peerTest),m_State (eSessionStateUnknown), m_IsSessionKey (false), - m_RelayTag (0),m_Data (*this), m_IsDataReceived (false) + m_RelayTag (0), m_SentRelayTag (0), m_Data (*this), m_IsDataReceived (false) { if (router) { @@ -458,14 +458,13 @@ namespace transport else s.Insert (address->host.to_v6 ().to_bytes ().data (), 16); // our IP V6 s.Insert (htobe16 (address->port)); // our port - uint32_t relayTag = 0; if (sendRelayTag && i2p::context.GetRouterInfo ().IsIntroducer () && !IsV6 ()) { - RAND_bytes((uint8_t *)&relayTag, 4); - if (!relayTag) relayTag = 1; - m_Server.AddRelay (relayTag, m_RemoteEndpoint); + RAND_bytes((uint8_t *)&m_SentRelayTag, 4); + if (!m_SentRelayTag) m_SentRelayTag = 1; + m_Server.AddRelay (m_SentRelayTag, m_RemoteEndpoint); } - htobe32buf (payload, relayTag); + htobe32buf (payload, m_SentRelayTag); payload += 4; // relay tag htobe32buf (payload, i2p::util::GetSecondsSinceEpoch ()); // signed on time payload += 4; @@ -870,6 +869,8 @@ namespace transport transports.PeerDisconnected (shared_from_this ()); m_Data.Stop (); m_ConnectTimer.cancel (); + if (m_SentRelayTag) + m_Server.RemoveRelay (m_SentRelayTag); // relay tag is not valid anymore } void SSUSession::Done () diff --git a/SSUSession.h b/SSUSession.h index 4838be2a..b25beeae 100644 --- a/SSUSession.h +++ b/SSUSession.h @@ -141,7 +141,8 @@ namespace transport bool m_IsPeerTest; SessionState m_State; bool m_IsSessionKey; - uint32_t m_RelayTag; + uint32_t m_RelayTag; // received from peer + uint32_t m_SentRelayTag; // sent by us i2p::crypto::CBCEncryption m_SessionKeyEncryption; i2p::crypto::CBCDecryption m_SessionKeyDecryption; i2p::crypto::AESKey m_SessionKey;