mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 13:27:17 +01:00
moved peer test 5-7 to SSU2PeerTestSession
This commit is contained in:
parent
11bca5c3cd
commit
2c594dc67a
|
@ -2165,6 +2165,7 @@ namespace transport
|
|||
|
||||
void SSU2Session::HandlePeerTest (const uint8_t * buf, size_t len)
|
||||
{
|
||||
// msgs 1-4
|
||||
if (len < 3) return;
|
||||
uint8_t msg = buf[0];
|
||||
size_t offset = 3; // points to signed data
|
||||
|
@ -2400,35 +2401,6 @@ namespace transport
|
|||
LogPrint (eLogWarning, "SSU2: Unknown peer test 4 nonce ", nonce);
|
||||
break;
|
||||
}
|
||||
case 5: // Alice from Charlie 1
|
||||
if (htobe64 (((uint64_t)nonce << 32) | nonce) == m_SourceConnID)
|
||||
{
|
||||
bool isConnectedRecently = m_Server.IsConnectedRecently (m_RemoteEndpoint);
|
||||
if (m_Address)
|
||||
{
|
||||
if (!isConnectedRecently)
|
||||
SetRouterStatus (eRouterStatusOK);
|
||||
SendPeerTest (6, buf + offset, len - offset, m_Address->i);
|
||||
}
|
||||
else
|
||||
// we received msg 5 before msg 4
|
||||
m_State = isConnectedRecently ? eSSU2SessionStateVoidPeerTestReceived : eSSU2SessionStatePeerTestReceived;
|
||||
}
|
||||
else
|
||||
LogPrint (eLogWarning, "SSU2: Peer test 5 nonce mismatch ", nonce, " connID=", m_SourceConnID);
|
||||
break;
|
||||
case 6: // Charlie from Alice
|
||||
if (m_Address)
|
||||
SendPeerTest (7, buf + offset, len - offset, m_Address->i);
|
||||
else
|
||||
LogPrint (eLogWarning, "SSU2: Unknown address for peer test 6");
|
||||
m_Server.RemoveSession (~htobe64 (((uint64_t)nonce << 32) | nonce));
|
||||
break;
|
||||
case 7: // Alice from Charlie 2
|
||||
if (m_Address->IsV6 ())
|
||||
i2p::context.SetStatusV6 (eRouterStatusOK); // set status OK for ipv6 even if from SSU2
|
||||
m_Server.RemoveSession (htobe64 (((uint64_t)nonce << 32) | nonce));
|
||||
break;
|
||||
default:
|
||||
LogPrint (eLogWarning, "SSU2: PeerTest unexpected msg num ", buf[0]);
|
||||
}
|
||||
|
@ -3165,5 +3137,57 @@ namespace transport
|
|||
HandlePayload (payload, len - 48);
|
||||
return true;
|
||||
}
|
||||
|
||||
void SSU2PeerTestSession::HandlePeerTest (const uint8_t * buf, size_t len)
|
||||
{
|
||||
// msgs 5-7
|
||||
if (len < 8) return;
|
||||
uint8_t msg = buf[0];
|
||||
size_t offset = 3; // points to signed data after msg + code + flag
|
||||
uint32_t nonce = bufbe32toh (buf + offset + 1); // 1 - ver
|
||||
switch (msg) // msg
|
||||
{
|
||||
case 5: // Alice from Charlie 1
|
||||
{
|
||||
if (htobe64 (((uint64_t)nonce << 32) | nonce) == GetSourceConnID ())
|
||||
{
|
||||
bool isConnectedRecently = GetServer ().IsConnectedRecently (GetRemoteEndpoint ());
|
||||
auto addr = GetAddress ();
|
||||
if (addr)
|
||||
{
|
||||
if (!isConnectedRecently)
|
||||
SetRouterStatus (eRouterStatusOK);
|
||||
SendPeerTest (6, buf + offset, len - offset, addr->i);
|
||||
}
|
||||
else
|
||||
// we received msg 5 before msg 4
|
||||
SetState (isConnectedRecently ? eSSU2SessionStateVoidPeerTestReceived : eSSU2SessionStatePeerTestReceived);
|
||||
}
|
||||
else
|
||||
LogPrint (eLogWarning, "SSU2: Peer test 5 nonce mismatch ", nonce, " connID=", GetSourceConnID ());
|
||||
break;
|
||||
}
|
||||
case 6: // Charlie from Alice
|
||||
{
|
||||
auto addr = GetAddress ();
|
||||
if (addr)
|
||||
SendPeerTest (7, buf + offset, len - offset, addr->i);
|
||||
else
|
||||
LogPrint (eLogWarning, "SSU2: Unknown address for peer test 6");
|
||||
GetServer ().RemoveSession (~htobe64 (((uint64_t)nonce << 32) | nonce));
|
||||
break;
|
||||
}
|
||||
case 7: // Alice from Charlie 2
|
||||
{
|
||||
auto addr = GetAddress ();
|
||||
if (addr && addr->IsV6 ())
|
||||
i2p::context.SetStatusV6 (eRouterStatusOK); // set status OK for ipv6 even if from SSU2
|
||||
GetServer ().RemoveSession (htobe64 (((uint64_t)nonce << 32) | nonce));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LogPrint (eLogWarning, "SSU2: PeerTest unexpected msg num ", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -280,10 +280,17 @@ namespace transport
|
|||
|
||||
protected:
|
||||
|
||||
SSU2Server& GetServer () { return m_Server; }
|
||||
RouterStatus GetRouterStatus () const;
|
||||
void SetRouterStatus (RouterStatus status) const;
|
||||
|
||||
uint64_t GetSourceConnID () const { return m_SourceConnID; }
|
||||
void SetSourceConnID (uint64_t sourceConnID) { m_SourceConnID = sourceConnID; }
|
||||
uint64_t GetDestConnID () const { return m_DestConnID; }
|
||||
void SetDestConnID (uint64_t destConnID) { m_DestConnID = destConnID; }
|
||||
|
||||
void HandlePayload (const uint8_t * buf, size_t len);
|
||||
void SendPeerTest (uint8_t msg, const uint8_t * signedData, size_t signedDataLen, const uint8_t * introKey); // PeerTest message
|
||||
|
||||
private:
|
||||
|
||||
|
@ -310,7 +317,6 @@ namespace transport
|
|||
void SendQuickAck ();
|
||||
void SendTermination ();
|
||||
void SendHolePunch (uint32_t nonce, const boost::asio::ip::udp::endpoint& ep, const uint8_t * introKey, uint64_t token);
|
||||
void SendPeerTest (uint8_t msg, const uint8_t * signedData, size_t signedDataLen, const uint8_t * introKey); // PeerTest message
|
||||
void SendPathResponse (const uint8_t * data, size_t len);
|
||||
void SendPathChallenge ();
|
||||
|
||||
|
@ -323,8 +329,6 @@ namespace transport
|
|||
size_t CreateEndpoint (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& ep);
|
||||
std::shared_ptr<const i2p::data::RouterInfo::Address> FindLocalAddress () const;
|
||||
void AdjustMaxPayloadSize ();
|
||||
RouterStatus GetRouterStatus () const;
|
||||
void SetRouterStatus (RouterStatus status) const;
|
||||
bool GetTestingState () const;
|
||||
void SetTestingState(bool testing) const;
|
||||
std::shared_ptr<const i2p::data::RouterInfo> ExtractRouterInfo (const uint8_t * buf, size_t size);
|
||||
|
@ -334,7 +338,7 @@ namespace transport
|
|||
void HandleRelayRequest (const uint8_t * buf, size_t len);
|
||||
void HandleRelayIntro (const uint8_t * buf, size_t len, int attempts = 0);
|
||||
void HandleRelayResponse (const uint8_t * buf, size_t len);
|
||||
void HandlePeerTest (const uint8_t * buf, size_t len);
|
||||
virtual void HandlePeerTest (const uint8_t * buf, size_t len);
|
||||
void HandleI2NPMsg (std::shared_ptr<I2NPMessage>&& msg);
|
||||
|
||||
size_t CreateAddressBlock (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& ep);
|
||||
|
@ -396,6 +400,10 @@ namespace transport
|
|||
|
||||
bool ProcessPeerTest (uint8_t * buf, size_t len) override;
|
||||
|
||||
private:
|
||||
|
||||
void HandlePeerTest (const uint8_t * buf, size_t len) override;
|
||||
|
||||
private:
|
||||
|
||||
std::weak_ptr<SSU2Session> m_MainSession;
|
||||
|
|
Loading…
Reference in a new issue