Browse Source

update remote endpoint and send path challenge

pull/1791/head
orignal 2 years ago
parent
commit
3bdef5f58d
  1. 4
      libi2pd/SSU2.cpp
  2. 22
      libi2pd/SSU2Session.cpp
  3. 3
      libi2pd/SSU2Session.h

4
libi2pd/SSU2.cpp

@ -410,7 +410,7 @@ namespace transport
{ {
case eSSU2SessionStateEstablished: case eSSU2SessionStateEstablished:
case eSSU2SessionStateSessionConfirmedSent: case eSSU2SessionStateSessionConfirmedSent:
m_LastSession->ProcessData (buf, len); m_LastSession->ProcessData (buf, len, senderEndpoint);
break; break;
case eSSU2SessionStateSessionCreatedSent: case eSSU2SessionStateSessionCreatedSent:
if (!m_LastSession->ProcessSessionConfirmed (buf, len)) if (!m_LastSession->ProcessSessionConfirmed (buf, len))
@ -437,7 +437,7 @@ namespace transport
m_LastSession->ProcessPeerTest (buf, len); m_LastSession->ProcessPeerTest (buf, len);
break; break;
case eSSU2SessionStateClosing: case eSSU2SessionStateClosing:
m_LastSession->ProcessData (buf, len); // we might receive termintaion block m_LastSession->ProcessData (buf, len, senderEndpoint); // we might receive termintaion block
if (m_LastSession && m_LastSession->GetState () != eSSU2SessionStateTerminated) if (m_LastSession && m_LastSession->GetState () != eSSU2SessionStateTerminated)
m_LastSession->RequestTermination (eSSU2TerminationReasonIdleTimeout); // send termination again m_LastSession->RequestTermination (eSSU2TerminationReasonIdleTimeout); // send termination again
break; break;

22
libi2pd/SSU2Session.cpp

@ -1301,7 +1301,7 @@ namespace transport
return m_SendPacketNum - 1; return m_SendPacketNum - 1;
} }
void SSU2Session::ProcessData (uint8_t * buf, size_t len) void SSU2Session::ProcessData (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& from)
{ {
Header header; Header header;
header.ll[0] = m_SourceConnID; header.ll[0] = m_SourceConnID;
@ -1316,6 +1316,12 @@ namespace transport
ResendHandshakePacket (); // assume we receive ResendHandshakePacket (); // assume we receive
return; return;
} }
if (from != m_RemoteEndpoint)
{
LogPrint (eLogInfo, "SSU2: Remote endpoint update ", m_RemoteEndpoint, "->", from);
m_RemoteEndpoint = from;
SendPathChallenge ();
}
uint8_t payload[SSU2_MAX_PACKET_SIZE]; uint8_t payload[SSU2_MAX_PACKET_SIZE];
size_t payloadSize = len - 32; size_t payloadSize = len - 32;
uint32_t packetNum = be32toh (header.h.packetNum); uint32_t packetNum = be32toh (header.h.packetNum);
@ -2625,6 +2631,20 @@ namespace transport
memcpy (payload + 3, data, len); memcpy (payload + 3, data, len);
SendData (payload, len + 3); SendData (payload, len + 3);
} }
void SSU2Session::SendPathChallenge ()
{
uint8_t payload[SSU2_MAX_PACKET_SIZE];
payload[0] = eSSU2BlkPathChallenge;
size_t len = rand () % (m_MaxPayloadSize - 3);
htobe16buf (payload + 1, len);
if (len > 0)
RAND_bytes (payload + 3, len);
len += 3;
if (len < m_MaxPayloadSize)
len += CreatePaddingBlock (payload + len, m_MaxPayloadSize - len);
SendData (payload, len);
}
void SSU2Session::CleanUp (uint64_t ts) void SSU2Session::CleanUp (uint64_t ts)
{ {

3
libi2pd/SSU2Session.h

@ -255,7 +255,7 @@ namespace transport
bool ProcessRetry (uint8_t * buf, size_t len); bool ProcessRetry (uint8_t * buf, size_t len);
bool ProcessHolePunch (uint8_t * buf, size_t len); bool ProcessHolePunch (uint8_t * buf, size_t len);
bool ProcessPeerTest (uint8_t * buf, size_t len); bool ProcessPeerTest (uint8_t * buf, size_t len);
void ProcessData (uint8_t * buf, size_t len); void ProcessData (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& from);
private: private:
@ -284,6 +284,7 @@ namespace transport
void SendHolePunch (uint32_t nonce, const boost::asio::ip::udp::endpoint& ep, const uint8_t * introKey, uint64_t token); 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 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 SendPathResponse (const uint8_t * data, size_t len);
void SendPathChallenge ();
void HandlePayload (const uint8_t * buf, size_t len); void HandlePayload (const uint8_t * buf, size_t len);
void HandleDateTime (const uint8_t * buf, size_t len); void HandleDateTime (const uint8_t * buf, size_t len);

Loading…
Cancel
Save