Browse Source

Respond to path challenge. Correct termination reason for duplicated session

pull/1786/head
orignal 2 years ago
parent
commit
98d2ce5845
  1. 2
      libi2pd/SSU2.cpp
  2. 16
      libi2pd/SSU2Session.cpp
  3. 4
      libi2pd/SSU2Session.h

2
libi2pd/SSU2.cpp

@ -292,7 +292,7 @@ namespace transport @@ -292,7 +292,7 @@ namespace transport
// session already exists
LogPrint (eLogWarning, "SSU2: Session to ", ident->GetIdentHash ().ToBase64 (), " already exists");
// terminate existing
GetService ().post (std::bind (&SSU2Session::RequestTermination, ret.first->second, eSSU2TerminationReasonTerminationReceived));
GetService ().post (std::bind (&SSU2Session::RequestTermination, ret.first->second, eSSU2TerminationReasonReplacedByNewSession));
// update session
ret.first->second = session;
}

16
libi2pd/SSU2Session.cpp

@ -1403,8 +1403,11 @@ namespace transport @@ -1403,8 +1403,11 @@ namespace transport
break;
}
case eSSU2BlkPathChallenge:
LogPrint (eLogDebug, "SSU2: Path challenge");
SendPathResponse (buf + offset, size);
break;
case eSSU2BlkPathResponse:
LogPrint (eLogDebug, "SSU2: Path response");
break;
case eSSU2BlkFirstPacketNumber:
break;
@ -2441,6 +2444,19 @@ namespace transport @@ -2441,6 +2444,19 @@ namespace transport
SendData (payload, payloadSize);
}
void SSU2Session::SendPathResponse (const uint8_t * data, size_t len)
{
if (len < 8 || len > m_MaxPayloadSize - 3)
{
LogPrint (eLogWarning, "SSU2: Incorrect data size for path response ", len);
return;
}
uint8_t payload[SSU2_MAX_PACKET_SIZE];
payload[0] = eSSU2BlkPathResponse;
htobe16buf (payload + 1, len);
SendData (payload, len + 3);
}
void SSU2Session::CleanUp (uint64_t ts)
{
for (auto it = m_IncompleteMessages.begin (); it != m_IncompleteMessages.end ();)

4
libi2pd/SSU2Session.h

@ -150,7 +150,8 @@ namespace transport @@ -150,7 +150,8 @@ namespace transport
eSSU2TerminationReasonBadToken = 18,
eSSU2TerminationReasonConnectionLimits = 19,
eSSU2TerminationReasonIncompatibleVersion = 20,
eSSU2TerminationReasonWrongNetID = 21
eSSU2TerminationReasonWrongNetID = 21,
eSSU2TerminationReasonReplacedByNewSession = 22
};
struct SSU2IncompleteMessage
@ -272,6 +273,7 @@ namespace transport @@ -272,6 +273,7 @@ namespace transport
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 HandlePayload (const uint8_t * buf, size_t len);
void HandleAck (const uint8_t * buf, size_t len);

Loading…
Cancel
Save