Browse Source

store session with Alice with PeerTest

pull/168/head
orignal 10 years ago
parent
commit
d226a4a0b7
  1. 14
      SSU.cpp
  2. 4
      SSU.h
  3. 7
      SSUSession.cpp

14
SSU.cpp

@ -256,7 +256,6 @@ namespace transport @@ -256,7 +256,6 @@ namespace transport
std::shared_ptr<SSUSession> SSUServer::FindSession (const boost::asio::ip::udp::endpoint& e) const
{
std::unique_lock<std::mutex> l(m_SessionsMutex);
auto it = m_Sessions.find (e);
if (it != m_Sessions.end ())
return it->second;
@ -473,9 +472,9 @@ namespace transport @@ -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<SSUSession> 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 @@ -487,6 +486,15 @@ namespace transport
return ePeerTestParticipantUnknown;
}
std::shared_ptr<SSUSession> 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);

4
SSU.h

@ -54,8 +54,9 @@ namespace transport @@ -54,8 +54,9 @@ namespace transport
void AddRelay (uint32_t tag, const boost::asio::ip::udp::endpoint& relay);
std::shared_ptr<SSUSession> FindRelaySession (uint32_t tag);
void NewPeerTest (uint32_t nonce, PeerTestParticipant role);
void NewPeerTest (uint32_t nonce, PeerTestParticipant role, std::shared_ptr<SSUSession> session = nullptr);
PeerTestParticipant GetPeerTestParticipant (uint32_t nonce);
std::shared_ptr<SSUSession> GetPeerTestSession (uint32_t nonce);
void UpdatePeerTest (uint32_t nonce, PeerTestParticipant role);
void RemovePeerTest (uint32_t nonce);
@ -86,6 +87,7 @@ namespace transport @@ -86,6 +87,7 @@ namespace transport
{
uint64_t creationTime;
PeerTestParticipant role;
std::shared_ptr<SSUSession> session; // for Bob to Alice
};
bool m_IsRunning;

7
SSUSession.cpp

@ -929,9 +929,8 @@ namespace transport @@ -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 @@ -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
}

Loading…
Cancel
Save