diff --git a/SSU.cpp b/SSU.cpp index 8c7948ee..457c1213 100644 --- a/SSU.cpp +++ b/SSU.cpp @@ -256,7 +256,6 @@ namespace transport std::shared_ptr SSUServer::FindSession (const boost::asio::ip::udp::endpoint& e) const { - std::unique_lock l(m_SessionsMutex); auto it = m_Sessions.find (e); if (it != m_Sessions.end ()) return it->second; @@ -473,9 +472,9 @@ namespace transport } } - void SSUServer::NewPeerTest (uint32_t nonce, PeerTestParticipant role) + void SSUServer::NewPeerTest (uint32_t nonce, PeerTestParticipant role, std::shared_ptr session) { - m_PeerTests[nonce] = { i2p::util::GetMillisecondsSinceEpoch (), role }; + m_PeerTests[nonce] = { i2p::util::GetMillisecondsSinceEpoch (), role, session }; } PeerTestParticipant SSUServer::GetPeerTestParticipant (uint32_t nonce) @@ -487,6 +486,15 @@ namespace transport return ePeerTestParticipantUnknown; } + std::shared_ptr SSUServer::GetPeerTestSession (uint32_t nonce) + { + auto it = m_PeerTests.find (nonce); + if (it != m_PeerTests.end ()) + return it->second.session; + else + return nullptr; + } + void SSUServer::UpdatePeerTest (uint32_t nonce, PeerTestParticipant role) { auto it = m_PeerTests.find (nonce); diff --git a/SSU.h b/SSU.h index 1b954b21..1033a2bf 100644 --- a/SSU.h +++ b/SSU.h @@ -54,8 +54,9 @@ namespace transport void AddRelay (uint32_t tag, const boost::asio::ip::udp::endpoint& relay); std::shared_ptr FindRelaySession (uint32_t tag); - void NewPeerTest (uint32_t nonce, PeerTestParticipant role); + void NewPeerTest (uint32_t nonce, PeerTestParticipant role, std::shared_ptr session = nullptr); PeerTestParticipant GetPeerTestParticipant (uint32_t nonce); + std::shared_ptr GetPeerTestSession (uint32_t nonce); void UpdatePeerTest (uint32_t nonce, PeerTestParticipant role); void RemovePeerTest (uint32_t nonce); @@ -86,6 +87,7 @@ namespace transport { uint64_t creationTime; PeerTestParticipant role; + std::shared_ptr session; // for Bob to Alice }; bool m_IsRunning; diff --git a/SSUSession.cpp b/SSUSession.cpp index ed4362ea..edc5cb9f 100644 --- a/SSUSession.cpp +++ b/SSUSession.cpp @@ -929,9 +929,8 @@ namespace transport case ePeerTestParticipantBob: { LogPrint (eLogDebug, "SSU peer test from Charlie. We are Bob"); - boost::asio::ip::udp::endpoint ep (boost::asio::ip::address_v4 (be32toh (address)), be16toh (port)); // Alice's address/port - auto session = m_Server.FindSession (ep); // find session with Alice - if (session) + auto session = m_Server.GetPeerTestSession (nonce); // session with Alice from PeerTest + if (session && session->m_State == eSessionStateEstablished) session->Send (PAYLOAD_TYPE_PEER_TEST, buf, len); // back to Alice m_Server.RemovePeerTest (nonce); // nonce has been used break; @@ -963,7 +962,7 @@ namespace transport auto session = m_Server.GetRandomEstablishedSession (shared_from_this ()); // Charlie if (session) { - m_Server.NewPeerTest (nonce, ePeerTestParticipantBob); + m_Server.NewPeerTest (nonce, ePeerTestParticipantBob, shared_from_this ()); session->SendPeerTest (nonce, senderEndpoint.address ().to_v4 ().to_ulong (), senderEndpoint.port (), introKey, false); // to Charlie with Alice's actual address }