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 @@ -410,7 +410,7 @@ namespace transport
{
case eSSU2SessionStateEstablished:
case eSSU2SessionStateSessionConfirmedSent:
m_LastSession->ProcessData (buf, len);
m_LastSession->ProcessData (buf, len, senderEndpoint);
break;
case eSSU2SessionStateSessionCreatedSent:
if (!m_LastSession->ProcessSessionConfirmed (buf, len))
@ -437,7 +437,7 @@ namespace transport @@ -437,7 +437,7 @@ namespace transport
m_LastSession->ProcessPeerTest (buf, len);
break;
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)
m_LastSession->RequestTermination (eSSU2TerminationReasonIdleTimeout); // send termination again
break;

22
libi2pd/SSU2Session.cpp

@ -1301,7 +1301,7 @@ namespace transport @@ -1301,7 +1301,7 @@ namespace transport
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.ll[0] = m_SourceConnID;
@ -1316,6 +1316,12 @@ namespace transport @@ -1316,6 +1316,12 @@ namespace transport
ResendHandshakePacket (); // assume we receive
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];
size_t payloadSize = len - 32;
uint32_t packetNum = be32toh (header.h.packetNum);
@ -2626,6 +2632,20 @@ namespace transport @@ -2626,6 +2632,20 @@ namespace transport
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)
{
for (auto it = m_IncompleteMessages.begin (); it != m_IncompleteMessages.end ();)

3
libi2pd/SSU2Session.h

@ -255,7 +255,7 @@ namespace transport @@ -255,7 +255,7 @@ namespace transport
bool ProcessRetry (uint8_t * buf, size_t len);
bool ProcessHolePunch (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:
@ -284,6 +284,7 @@ namespace transport @@ -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 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 ();
void HandlePayload (const uint8_t * buf, size_t len);
void HandleDateTime (const uint8_t * buf, size_t len);

Loading…
Cancel
Save