mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-05 01:34:13 +00:00
store session with Alice with PeerTest
This commit is contained in:
parent
c62659cdbc
commit
d226a4a0b7
14
SSU.cpp
14
SSU.cpp
@ -256,7 +256,6 @@ namespace transport
|
|||||||
|
|
||||||
std::shared_ptr<SSUSession> SSUServer::FindSession (const boost::asio::ip::udp::endpoint& e) const
|
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);
|
auto it = m_Sessions.find (e);
|
||||||
if (it != m_Sessions.end ())
|
if (it != m_Sessions.end ())
|
||||||
return it->second;
|
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<SSUSession> session)
|
||||||
{
|
{
|
||||||
m_PeerTests[nonce] = { i2p::util::GetMillisecondsSinceEpoch (), role };
|
m_PeerTests[nonce] = { i2p::util::GetMillisecondsSinceEpoch (), role, session };
|
||||||
}
|
}
|
||||||
|
|
||||||
PeerTestParticipant SSUServer::GetPeerTestParticipant (uint32_t nonce)
|
PeerTestParticipant SSUServer::GetPeerTestParticipant (uint32_t nonce)
|
||||||
@ -487,6 +486,15 @@ namespace transport
|
|||||||
return ePeerTestParticipantUnknown;
|
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)
|
void SSUServer::UpdatePeerTest (uint32_t nonce, PeerTestParticipant role)
|
||||||
{
|
{
|
||||||
auto it = m_PeerTests.find (nonce);
|
auto it = m_PeerTests.find (nonce);
|
||||||
|
4
SSU.h
4
SSU.h
@ -54,8 +54,9 @@ namespace transport
|
|||||||
void AddRelay (uint32_t tag, const boost::asio::ip::udp::endpoint& relay);
|
void AddRelay (uint32_t tag, const boost::asio::ip::udp::endpoint& relay);
|
||||||
std::shared_ptr<SSUSession> FindRelaySession (uint32_t tag);
|
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);
|
PeerTestParticipant GetPeerTestParticipant (uint32_t nonce);
|
||||||
|
std::shared_ptr<SSUSession> GetPeerTestSession (uint32_t nonce);
|
||||||
void UpdatePeerTest (uint32_t nonce, PeerTestParticipant role);
|
void UpdatePeerTest (uint32_t nonce, PeerTestParticipant role);
|
||||||
void RemovePeerTest (uint32_t nonce);
|
void RemovePeerTest (uint32_t nonce);
|
||||||
|
|
||||||
@ -86,6 +87,7 @@ namespace transport
|
|||||||
{
|
{
|
||||||
uint64_t creationTime;
|
uint64_t creationTime;
|
||||||
PeerTestParticipant role;
|
PeerTestParticipant role;
|
||||||
|
std::shared_ptr<SSUSession> session; // for Bob to Alice
|
||||||
};
|
};
|
||||||
|
|
||||||
bool m_IsRunning;
|
bool m_IsRunning;
|
||||||
|
@ -929,9 +929,8 @@ namespace transport
|
|||||||
case ePeerTestParticipantBob:
|
case ePeerTestParticipantBob:
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "SSU peer test from Charlie. We are Bob");
|
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.GetPeerTestSession (nonce); // session with Alice from PeerTest
|
||||||
auto session = m_Server.FindSession (ep); // find session with Alice
|
if (session && session->m_State == eSessionStateEstablished)
|
||||||
if (session)
|
|
||||||
session->Send (PAYLOAD_TYPE_PEER_TEST, buf, len); // back to Alice
|
session->Send (PAYLOAD_TYPE_PEER_TEST, buf, len); // back to Alice
|
||||||
m_Server.RemovePeerTest (nonce); // nonce has been used
|
m_Server.RemovePeerTest (nonce); // nonce has been used
|
||||||
break;
|
break;
|
||||||
@ -963,7 +962,7 @@ namespace transport
|
|||||||
auto session = m_Server.GetRandomEstablishedSession (shared_from_this ()); // Charlie
|
auto session = m_Server.GetRandomEstablishedSession (shared_from_this ()); // Charlie
|
||||||
if (session)
|
if (session)
|
||||||
{
|
{
|
||||||
m_Server.NewPeerTest (nonce, ePeerTestParticipantBob);
|
m_Server.NewPeerTest (nonce, ePeerTestParticipantBob, shared_from_this ());
|
||||||
session->SendPeerTest (nonce, senderEndpoint.address ().to_v4 ().to_ulong (),
|
session->SendPeerTest (nonce, senderEndpoint.address ().to_v4 ().to_ulong (),
|
||||||
senderEndpoint.port (), introKey, false); // to Charlie with Alice's actual address
|
senderEndpoint.port (), introKey, false); // to Charlie with Alice's actual address
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user