update session's remote enpoint after receiving path response
Some checks are pending
Build Debian packages / bookworm (push) Waiting to run
Build Debian packages / bullseye (push) Waiting to run
Build Debian packages / buster (push) Waiting to run
Build on FreeBSD / with UPnP (push) Waiting to run
Build on OSX / With USE_UPNP=no (push) Waiting to run
Build on OSX / With USE_UPNP=yes (push) Waiting to run
Build on Windows / i686 (push) Waiting to run
Build on Windows / clang-x86_64 (push) Waiting to run
Build on Windows / ucrt-x86_64 (push) Waiting to run
Build on Windows / x86_64 (push) Waiting to run
Build on Windows / CMake clang-x86_64 (push) Waiting to run
Build on Windows / CMake i686 (push) Waiting to run
Build on Windows / CMake ucrt-x86_64 (push) Waiting to run
Build on Windows / CMake x86_64 (push) Waiting to run
Build on Windows / XP (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=no (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=yes (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Waiting to run
Build containers / Building container for linux/amd64 (push) Waiting to run
Build containers / Building container for linux/arm64 (push) Waiting to run
Build containers / Building container for linux/arm/v7 (push) Waiting to run
Build containers / Building container for linux/386 (push) Waiting to run
Build containers / Pushing merged manifest (push) Blocked by required conditions

This commit is contained in:
orignal 2025-03-28 19:34:36 -04:00
parent 871fc14ba6
commit 7404ce7fd2
2 changed files with 17 additions and 11 deletions

View file

@ -1498,11 +1498,11 @@ namespace transport
ResendHandshakePacket (); // assume we receive ResendHandshakePacket (); // assume we receive
return; return;
} }
if (from != m_RemoteEndpoint && !i2p::transport::transports.IsInReservedRange (from.address ())) if (from != m_RemoteEndpoint && !i2p::transport::transports.IsInReservedRange (from.address ()) &&
(!m_PathChallenge || from != m_PathChallenge->second)) // path challenge was not sent to this endpoint yet
{ {
LogPrint (eLogInfo, "SSU2: Remote endpoint update ", m_RemoteEndpoint, "->", from); LogPrint (eLogInfo, "SSU2: Remote endpoint update ", m_RemoteEndpoint, "->", from);
m_RemoteEndpoint = from; SendPathChallenge (from);
SendPathChallenge ();
} }
if (len < 32) if (len < 32)
{ {
@ -1660,10 +1660,13 @@ namespace transport
LogPrint (eLogDebug, "SSU2: Path response"); LogPrint (eLogDebug, "SSU2: Path response");
if (m_PathChallenge) if (m_PathChallenge)
{ {
i2p::data::IdentHash hash; i2p::data::Tag<32> hash;
SHA256 (buf + offset, size, hash); SHA256 (buf + offset, size, hash);
if (hash == *m_PathChallenge) if (hash == m_PathChallenge->first)
{
m_RemoteEndpoint = m_PathChallenge->second;
m_PathChallenge.reset (nullptr); m_PathChallenge.reset (nullptr);
}
} }
break; break;
} }
@ -3070,7 +3073,7 @@ namespace transport
SendData (payload, payloadSize); SendData (payload, payloadSize);
} }
void SSU2Session::SendPathChallenge () void SSU2Session::SendPathChallenge (const boost::asio::ip::udp::endpoint& to)
{ {
uint8_t payload[SSU2_MAX_PACKET_SIZE]; uint8_t payload[SSU2_MAX_PACKET_SIZE];
payload[0] = eSSU2BlkPathChallenge; payload[0] = eSSU2BlkPathChallenge;
@ -3078,15 +3081,18 @@ namespace transport
htobe16buf (payload + 1, len); htobe16buf (payload + 1, len);
if (len > 0) if (len > 0)
{ {
m_PathChallenge = std::make_unique<std::pair<i2p::data::Tag<32>, boost::asio::ip::udp::endpoint> >();
RAND_bytes (payload + 3, len); RAND_bytes (payload + 3, len);
i2p::data::IdentHash * hash = new i2p::data::IdentHash (); SHA256 (payload + 3, len, m_PathChallenge->first);
SHA256 (payload + 3, len, *hash); m_PathChallenge->second = to;
m_PathChallenge.reset (hash);
} }
len += 3; len += 3;
if (len < m_MaxPayloadSize) if (len < m_MaxPayloadSize)
len += CreatePaddingBlock (payload + len, m_MaxPayloadSize - len, len < 8 ? 8 : 0); len += CreatePaddingBlock (payload + len, m_MaxPayloadSize - len, len < 8 ? 8 : 0);
auto existing = m_RemoteEndpoint;
m_RemoteEndpoint = to; // send path challenge to new endpoint
SendData (payload, len); SendData (payload, len);
m_RemoteEndpoint = existing; // restore endpoint back until path response received
} }
void SSU2Session::CleanUp (uint64_t ts) void SSU2Session::CleanUp (uint64_t ts)

View file

@ -327,7 +327,7 @@ namespace transport
void SendQuickAck (); void SendQuickAck ();
void SendTermination (); void SendTermination ();
void SendPathResponse (const uint8_t * data, size_t len); void SendPathResponse (const uint8_t * data, size_t len);
void SendPathChallenge (); void SendPathChallenge (const boost::asio::ip::udp::endpoint& to);
void HandleDateTime (const uint8_t * buf, size_t len); void HandleDateTime (const uint8_t * buf, size_t len);
void HandleRouterInfo (const uint8_t * buf, size_t len); void HandleRouterInfo (const uint8_t * buf, size_t len);
@ -394,7 +394,7 @@ namespace transport
boost::asio::deadline_timer m_ConnectTimer; boost::asio::deadline_timer m_ConnectTimer;
SSU2TerminationReason m_TerminationReason; SSU2TerminationReason m_TerminationReason;
size_t m_MaxPayloadSize; size_t m_MaxPayloadSize;
std::unique_ptr<i2p::data::IdentHash> m_PathChallenge; std::unique_ptr<std::pair<i2p::data::Tag<32>, boost::asio::ip::udp::endpoint> > m_PathChallenge;
std::unordered_map<uint32_t, uint32_t> m_ReceivedI2NPMsgIDs; // msgID -> timestamp in seconds std::unordered_map<uint32_t, uint32_t> m_ReceivedI2NPMsgIDs; // msgID -> timestamp in seconds
uint64_t m_LastResendTime, m_LastResendAttemptTime; // in milliseconds uint64_t m_LastResendTime, m_LastResendAttemptTime; // in milliseconds
int m_NumRanges; int m_NumRanges;