diff --git a/SSU.cpp b/SSU.cpp index 7d21c8ca..f00cf622 100644 --- a/SSU.cpp +++ b/SSU.cpp @@ -115,7 +115,7 @@ namespace ssu } case PAYLOAD_TYPE_RELAY_INTRO: LogPrint ("SSU relay intro received"); - // TODO: + ProcessRelayIntro (buf + sizeof (SSUHeader), len - sizeof (SSUHeader)); break; default: LogPrint ("Unexpected SSU payload type ", (int)header->GetPayloadType ()); @@ -430,6 +430,22 @@ namespace ssu } } + void SSUSession::ProcessRelayIntro (uint8_t * buf, size_t len) + { + uint8_t size = *buf; + if (size == 4) + { + buf++; // size + boost::asio::ip::address_v4 address (be32toh (*(uint32_t* )buf)); + buf += 4; // address + uint16_t port = be16toh (*(uint16_t *)buf); + // send hole punch of 1 byte + m_Server.Send (buf, 1, boost::asio::ip::udp::endpoint (address, port)); + } + else + LogPrint ("Address size ", size, " is not supported"); + } + void SSUSession::FillHeaderAndEncrypt (uint8_t payloadType, uint8_t * buf, size_t len, const uint8_t * aesKey, const uint8_t * iv, const uint8_t * macKey) { diff --git a/SSU.h b/SSU.h index e680c7f1..6294f10e 100644 --- a/SSU.h +++ b/SSU.h @@ -100,6 +100,7 @@ namespace ssu void ProcessSessionConfirmed (uint8_t * buf, size_t len); void SendSessionConfirmed (const uint8_t * y, const uint8_t * ourAddress, uint32_t relayTag); void ProcessRelayResponse (uint8_t * buf, size_t len); + void ProcessRelayIntro (uint8_t * buf, size_t len); void Established (); void Failed (); void HandleConnectTimer (const boost::system::error_code& ecode);