|
|
@ -896,48 +896,62 @@ namespace transport |
|
|
|
LogPrint (eLogWarning, "Address of ", size, " bytes not supported"); |
|
|
|
LogPrint (eLogWarning, "Address of ", size, " bytes not supported"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (m_PeerTestNonces.count (nonce) > 0) |
|
|
|
switch (m_Server.GetPeerTestParticipant (nonce)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// existing test
|
|
|
|
// existing test
|
|
|
|
if (m_PeerTest) // Alice
|
|
|
|
case ePeerTestParticipantAlice1: |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_State == eSessionStateEstablished) |
|
|
|
if (m_State == eSessionStateEstablished) |
|
|
|
LogPrint (eLogDebug, "SSU peer test from Bob. We are Alice"); |
|
|
|
LogPrint (eLogDebug, "SSU peer test from Bob. We are Alice"); |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogDebug, "SSU first peer test from Charlie. We are Alice"); |
|
|
|
LogPrint (eLogDebug, "SSU first peer test from Charlie. We are Alice"); |
|
|
|
m_PeerTest = false; |
|
|
|
m_Server.UpdatePeerTest (nonce, ePeerTestParticipantAlice2); |
|
|
|
m_PeerTestNonces.erase (nonce); |
|
|
|
|
|
|
|
m_Server.PeerTestComplete (nonce); |
|
|
|
|
|
|
|
SendPeerTest (nonce, senderEndpoint.address ().to_v4 ().to_ulong (), |
|
|
|
SendPeerTest (nonce, senderEndpoint.address ().to_v4 ().to_ulong (), |
|
|
|
senderEndpoint.port (), introKey, true, false); // to Charlie
|
|
|
|
senderEndpoint.port (), introKey, true, false); // to Charlie
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case ePeerTestParticipantAlice2: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (m_State == eSessionStateEstablished) |
|
|
|
|
|
|
|
LogPrint (eLogDebug, "SSU peer test from Bob. We are Alice"); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// peer test successive
|
|
|
|
|
|
|
|
LogPrint (eLogDebug, "SSU second peer test from Charlie. We are Alice"); |
|
|
|
|
|
|
|
m_Server.RemovePeerTest (nonce); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (port) // Bob
|
|
|
|
case ePeerTestParticipantBob: |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogDebug, "SSU peer test from Charlie. We are Bob"); |
|
|
|
LogPrint (eLogDebug, "SSU peer test from Charlie. We are Bob"); |
|
|
|
m_PeerTestNonces.erase (nonce); // nonce has been used
|
|
|
|
m_Server.RemovePeerTest (nonce); // nonce has been used
|
|
|
|
boost::asio::ip::udp::endpoint ep (boost::asio::ip::address_v4 (be32toh (address)), be16toh (port)); // Alice's address/port
|
|
|
|
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
|
|
|
|
auto session = m_Server.FindSession (ep); // find session with Alice
|
|
|
|
if (session) |
|
|
|
if (session) |
|
|
|
session->Send (PAYLOAD_TYPE_PEER_TEST, buf1, len); // back to Alice
|
|
|
|
session->Send (PAYLOAD_TYPE_PEER_TEST, buf1, len); // back to Alice
|
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
else // Charlie
|
|
|
|
case ePeerTestParticipantCharlie: |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogDebug, "SSU peer test from Alice. We are Charlie"); |
|
|
|
LogPrint (eLogDebug, "SSU peer test from Alice. We are Charlie"); |
|
|
|
|
|
|
|
m_Server.RemovePeerTest (nonce); // nonce has been used
|
|
|
|
SendPeerTest (nonce, senderEndpoint.address ().to_v4 ().to_ulong (), |
|
|
|
SendPeerTest (nonce, senderEndpoint.address ().to_v4 ().to_ulong (), |
|
|
|
senderEndpoint.port (), introKey); // to Alice with her actual address
|
|
|
|
senderEndpoint.port (), introKey); // to Alice with her actual address
|
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// test not found
|
|
|
|
else |
|
|
|
case ePeerTestParticipantUnknown: |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_State == eSessionStateEstablished) |
|
|
|
if (m_State == eSessionStateEstablished) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// new test
|
|
|
|
// new test
|
|
|
|
m_PeerTestNonces.insert (nonce); |
|
|
|
|
|
|
|
if (port) |
|
|
|
if (port) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogDebug, "SSU peer test from Bob. We are Charlie"); |
|
|
|
LogPrint (eLogDebug, "SSU peer test from Bob. We are Charlie"); |
|
|
|
|
|
|
|
m_Server.NewPeerTest (nonce, ePeerTestParticipantCharlie); |
|
|
|
Send (PAYLOAD_TYPE_PEER_TEST, buf1, len); // back to Bob
|
|
|
|
Send (PAYLOAD_TYPE_PEER_TEST, buf1, len); // back to Bob
|
|
|
|
SendPeerTest (nonce, be32toh (address), be16toh (port), introKey); // to Alice with her address received from Bob
|
|
|
|
SendPeerTest (nonce, be32toh (address), be16toh (port), introKey); // to Alice with her address received from Bob
|
|
|
|
} |
|
|
|
} |
|
|
@ -946,12 +960,16 @@ namespace transport |
|
|
|
LogPrint (eLogDebug, "SSU peer test from Alice. We are Bob"); |
|
|
|
LogPrint (eLogDebug, "SSU peer test from Alice. We are Bob"); |
|
|
|
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); |
|
|
|
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
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
LogPrint (eLogDebug, "SSU second peer test from Charlie. We are Alice"); |
|
|
|
LogPrint (eLogError, "SSU unexpected peer test"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1023,8 +1041,8 @@ namespace transport |
|
|
|
} |
|
|
|
} |
|
|
|
uint32_t nonce = i2p::context.GetRandomNumberGenerator ().GenerateWord32 (); |
|
|
|
uint32_t nonce = i2p::context.GetRandomNumberGenerator ().GenerateWord32 (); |
|
|
|
if (!nonce) nonce = 1; |
|
|
|
if (!nonce) nonce = 1; |
|
|
|
m_PeerTestNonces.insert (nonce); |
|
|
|
m_PeerTest = false; |
|
|
|
m_Server.NewPeerTest (nonce); |
|
|
|
m_Server.NewPeerTest (nonce, ePeerTestParticipantAlice1); |
|
|
|
SendPeerTest (nonce, 0, 0, address->key, false, false); // address and port always zero for Alice
|
|
|
|
SendPeerTest (nonce, 0, 0, address->key, false, false); // address and port always zero for Alice
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|