#ifndef TUNNEL_H__ #define TUNNEL_H__ #include #include #include #include #include #include #include #include #include "Queue.h" #include "TunnelConfig.h" #include "TunnelPool.h" #include "TransitTunnel.h" #include "TunnelEndpoint.h" #include "TunnelGateway.h" #include "TunnelBase.h" #include "I2NPProtocol.h" namespace i2p { namespace tunnel { const int TUNNEL_EXPIRATION_TIMEOUT = 660; // 11 minutes class OutboundTunnel; class InboundTunnel; class Tunnel: public TunnelBase { public: Tunnel (TunnelConfig * config); ~Tunnel (); void Build (uint32_t replyMsgID, OutboundTunnel * outboundTunnel = 0); TunnelConfig * GetTunnelConfig () const { return m_Config; } bool IsEstablished () const { return m_IsEstablished; }; bool IsFailed () const { return m_IsFailed; }; void SetFailed (bool failed) { m_IsFailed = failed; } TunnelPool * GetTunnelPool () const { return m_Pool; }; void SetTunnelPool (TunnelPool * pool) { m_Pool = pool; }; bool HandleTunnelBuildResponse (uint8_t * msg, size_t len); // implements TunnelBase void EncryptTunnelMsg (I2NPMessage * tunnelMsg); uint32_t GetNextTunnelID () const { return m_Config->GetFirstHop ()->tunnelID; }; const i2p::data::IdentHash& GetNextIdentHash () const { return m_Config->GetFirstHop ()->router->GetIdentHash (); }; private: void LayerDecrypt (const uint8_t * in, size_t len, const uint8_t * layerKey, const uint8_t * iv, uint8_t * out); void IVDecrypt (const uint8_t * in, const uint8_t * ivKey, uint8_t * out); private: TunnelConfig * m_Config; TunnelPool * m_Pool; // pool, tunnel belongs to, or null bool m_IsEstablished, m_IsFailed; CryptoPP::ECB_Mode::Decryption m_ECBDecryption; CryptoPP::CBC_Mode::Decryption m_CBCDecryption; }; class OutboundTunnel: public Tunnel { public: OutboundTunnel (TunnelConfig * config): Tunnel (config), m_Gateway (this) {}; void SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg); void SendTunnelDataMsg (std::vector msgs); // multiple messages const i2p::data::RouterInfo * GetEndpointRouter () const { return GetTunnelConfig ()->GetLastHop ()->router; }; size_t GetNumSentBytes () const { return m_Gateway.GetNumSentBytes (); }; // implements TunnelBase uint32_t GetTunnelID () const { return GetNextTunnelID (); }; private: TunnelGateway m_Gateway; }; class InboundTunnel: public Tunnel { public: InboundTunnel (TunnelConfig * config): Tunnel (config) {}; void HandleTunnelDataMsg (I2NPMessage * msg); size_t GetNumReceivedBytes () const { return m_Endpoint.GetNumReceivedBytes (); }; // implements TunnelBase uint32_t GetTunnelID () const { return GetTunnelConfig ()->GetLastHop ()->nextTunnelID; }; private: TunnelEndpoint m_Endpoint; }; class Tunnels { public: Tunnels (); ~Tunnels (); void Start (); void Stop (); InboundTunnel * GetInboundTunnel (uint32_t tunnelID); Tunnel * GetPendingTunnel (uint32_t replyMsgID); InboundTunnel * GetNextInboundTunnel (); OutboundTunnel * GetNextOutboundTunnel (); TransitTunnel * GetTransitTunnel (uint32_t tunnelID); void AddTransitTunnel (TransitTunnHTTP/1.1 200 OK X-Frame-Options: SAMEORIGIN Cache-Control: public, max-age=21600, no-transform Content-Disposition: inline; filename="Tunnel.h"; filename*=UTF-8''Tunnel.h Content-Length: 4896 Last-Modified: Tue, 01 Apr 2014 16:50:29 GMT Access-Control-Expose-Headers: Content-Disposition Content-Type: text/plain; charset=utf-8 Etag: "b964c55e620758984b445533115f443bb9524f4e" X-Content-Type-Options: nosniff Date: Wed, 23 Jul 2025 10:50:14 GMT Connection: close Set-Cookie: i_like_gitea=07aba14f7c4989ed; Path=/; HttpOnly; Secure; SameSite=Lax Set-Cookie: _csrf=e94vfwa9FONMzn8gMS8w3jh1gvY6MTc1MzI2NzgxNDM4NzU0NzE3Mw; Path=/; Max-Age=86400; HttpOnly; Secure; SameSite=Lax X-Cache-Status: HIT X-Cache-Age: 0 #ifndef TUNNEL_H__ #define TUNNEL_H__ #include #include #include #include #include #include #include #include #include "Queue.h" #include "TunnelConfig.h" #include "TunnelPool.h" #include "TransitTunnel.h" #include "TunnelEndpoint.h" #include "TunnelGateway.h" #include "TunnelBase.h" #include "I2NPProtocol.h" namespace i2p { namespace tunnel { const int TUNNEL_EXPIRATION_TIMEOUT = 660; // 11 minutes class OutboundTunnel; class InboundTunnel; class Tunnel: public TunnelBase { public: Tunnel (TunnelConfig * config); ~Tunnel (); void Build (uint32_t replyMsgID, OutboundTunnel * outboundTunnel = 0); TunnelConfig * GetTunnelConfig () const