#ifndef SSU_SESSION_H__ #define SSU_SESSION_H__ #include #include #include #include #include "aes.h" #include "hmac.h" #include "I2NPProtocol.h" #include "TransportSession.h" #include "SSUData.h" namespace i2p { namespace transport { #pragma pack(1) struct SSUHeader { uint8_t mac[16]; uint8_t iv[16]; uint8_t flag; uint32_t time; uint8_t GetPayloadType () const { return flag >> 4; }; }; #pragma pack() const int SSU_CONNECT_TIMEOUT = 5; // 5 seconds const int SSU_TERMINATION_TIMEOUT = 330; // 5.5 minutes // payload types (4 bits) const uint8_t PAYLOAD_TYPE_SESSION_REQUEST = 0; const uint8_t PAYLOAD_TYPE_SESSION_CREATED = 1; const uint8_t PAYLOAD_TYPE_SESSION_CONFIRMED = 2; const uint8_t PAYLOAD_TYPE_RELAY_REQUEST = 3; const uint8_t PAYLOAD_TYPE_RELAY_RESPONSE = 4; const uint8_t PAYLOAD_TYPE_RELAY_INTRO = 5; const uint8_t PAYLOAD_TYPE_DATA = 6; const uint8_t PAYLOAD_TYPE_PEER_TEST = 7; const uint8_t PAYLOAD_TYPE_SESSION_DESTROYED = 8; enum SessionState { eSessionStateUnknown, eSessionStateIntroduced, eSessionStateEstablished, eSessionStateFailed }; class SSUServer; class SSUSession: public TransportSession { public: SSUSession (SSUServer& server, boost::asio::ip::udp::endpoint& remoteEndpoint, const i2p::data::RouterInfo * router = nullptr, bool peerTest = false); void ProcessNextMessage (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint); ~SSUSession (); void Connect (); void Introduce (uint32_t iTag, const uint8_t * iKey); void WaitForIntroduction (); void Close (); boost::asio::ip::udp::endpoint& GetRemoteEndpoint () { return m_RemoteEndpoint; }; bool IsV6 () const { return m_RemoteEndpoint.address ().is_v6 (); }; void SendI2NPMessage (I2NPMessage * msg); void SendPeerTest (); // Alice SessionState GetState () const { return m_State; }; size_t GetNumSentBytes () const { return m_NumSentBytes; }; size_t GetNumReceivedBytes () const { return m_NumReceivedBytes; }; void SendKeepAlive (); uint32_t GetRelayTag () const { return m_RelayTag; }; uint32_t GetCreationTime () const { return m_CreationTime; }; private: void CreateAESandMacKey (const uint8_t * pubKey); void PostI2NPMessage (I2NPMessage * msg); void ProcessMessage (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint); // call for established session void ProcessSessionRequest (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint); void SendSessionRequest (); void SendRelayRequest (uint32_t iTag, const uint8_t * iKey); void ProcessSessionCreated (uint8_t * buf, size_t len); void SendSessionCreated (const uint8_t * x); void ProcessSessionConfirmed (uint8_t * buf, size_t len); void SendSessionConfirmed (const uint8_t * y, const uint8_t * ourAddress, size_t ourAddressLen); void ProcessRelayRequest (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& from); void SendRelayResponse (uint32_t nonce, const boost::asio::ip::udp::endpoint& from, const uint8_t * introKey, const boost::asio::ip::udp::endpoint& to); void SendRelayIntro (SSUSession * session, const boost::asio::ip::udp::endpoint& from); void ProcessRelayResponse (uint8_t * buf, size_t len); void ProcessRelayIntro (uintHTTP/1.1 200 OK Content-Length: 5291 X-Frame-Options: SAMEORIGIN Connection: close Cache-Control: public, max-age=21600, no-transform Set-Cookie: i_like_gitea=2173efc3040216e7; Path=/; HttpOnly; Secure; SameSite=Lax Set-Cookie: _csrf=d9TnhdbExqwKCaPWWVDd-LVzjZw6MTc1MzI2NzkzOTU4OTEzMzY3NA; Path=/; Max-Age=86400; HttpOnly; Secure; SameSite=Lax Access-Control-Expose-Headers: Content-Disposition Etag: "fc1600d80a7063736afeb455910dd4c2a7d5ca09" Last-Modified: Sat, 01 Nov 2014 18:56:13 GMT X-Content-Type-Options: nosniff Content-Type: text/plain; charset=utf-8 Date: Wed, 23 Jul 2025 10:52:19 GMT Content-Disposition: inline; filename="SSUSession.h"; filename*=UTF-8''SSUSession.h X-Cache-Status: HIT X-Cache-Age: 0 #ifndef SSU_SESSION_H__ #define SSU_SESSION_H__ #include #include #include #include #include "aes.h" #include "hmac.h" #include "I2NPProtocol.h" #include "TransportSession.h" #include "SSUData.h" namespace i2p { namespace transport { #pragma pack(1) struct SSUHeader { uint8_t mac[16]; uint8_t iv[16]; uint8_t flag; uint32_t time; uint8_t GetPayloadType () const { return flag >> 4; }; }; #pragma pack() const int SSU_CONNECT_TIMEOUT = 5; // 5 seconds const int SSU_TERMINATION_TIMEOUT = 330; // 5.5 minutes // payload types (4 bits) const uint8_t PAYLOAD_TYPE_SESSION_REQUEST = 0; const uint8_t PAYLOAD_TYPE_SESSION_CREATED = 1; const uint8_t PAYLOAD_TYPE_SESSION_CONFIRMED = 2; const uint8_t PAYLOAD_TYPE_RELAY_REQUEST = 3; const uint8_t PAYLOAD_TYPE_RELAY_RESPONSE = 4; const uint8_t PAYLOAD_TYPE_RELAY_INTRO = 5; const uint8_t PAYLOAD_TYPE_DATA = 6; const uint8_t PAYLOAD_TYPE_PEER_TEST = 7; const uint8_t PAYLOAD_TYPE_SESSION_DESTROYED = 8; enum SessionState { eSessionStateUnknown, eSessionStateIntroduced, eSessionStateEstablished, eSessionStateFailed }; class