From 6281fa625abc8812a98d65b1cc641d3c1f89fbd7 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 24 Oct 2014 15:50:48 -0400 Subject: [PATCH] moved remote RI and identity to TransportSession --- NTCPSession.cpp | 6 ++---- NTCPSession.h | 7 +------ SSU.cpp | 10 ++++------ SSU.h | 3 --- TransportSession.h | 15 ++++++++++++++- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/NTCPSession.cpp b/NTCPSession.cpp index a1950200..8f6faa4b 100644 --- a/NTCPSession.cpp +++ b/NTCPSession.cpp @@ -20,12 +20,10 @@ namespace i2p namespace transport { NTCPSession::NTCPSession (boost::asio::io_service& service, const i2p::data::RouterInfo * in_RemoteRouter): - m_Socket (service), m_TerminationTimer (service), m_IsEstablished (false), - m_RemoteRouter (in_RemoteRouter), m_ReceiveBufferOffset (0), + TransportSession (in_RemoteRouter), m_Socket (service), + m_TerminationTimer (service), m_IsEstablished (false), m_ReceiveBufferOffset (0), m_NextMessage (nullptr), m_NumSentBytes (0), m_NumReceivedBytes (0) { - if (m_RemoteRouter) - m_RemoteIdentity = m_RemoteRouter->GetRouterIdentity (); m_DHKeysPair = transports.GetNextDHKeysPair (); m_Establisher = new Establisher; } diff --git a/NTCPSession.h b/NTCPSession.h index 8d8b1d67..61113772 100644 --- a/NTCPSession.h +++ b/NTCPSession.h @@ -72,12 +72,10 @@ namespace transport public: NTCPSession (boost::asio::io_service& service, const i2p::data::RouterInfo * in_RemoteRouter = nullptr); - virtual ~NTCPSession (); + ~NTCPSession (); boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; }; bool IsEstablished () const { return m_IsEstablished; }; - const i2p::data::RouterInfo * GetRemoteRouter () { return m_RemoteRouter; }; - const i2p::data::IdentityEx& GetRemoteIdentity () { return m_RemoteIdentity; }; void ClientLogin (); void ServerLogin (); @@ -134,9 +132,6 @@ namespace transport i2p::crypto::CBCDecryption m_Decryption; i2p::crypto::CBCEncryption m_Encryption; CryptoPP::Adler32 m_Adler; - - const i2p::data::RouterInfo * m_RemoteRouter; - i2p::data::IdentityEx m_RemoteIdentity; struct Establisher { diff --git a/SSU.cpp b/SSU.cpp index a316bddd..96c1e7ae 100644 --- a/SSU.cpp +++ b/SSU.cpp @@ -16,8 +16,8 @@ namespace transport { SSUSession::SSUSession (SSUServer& server, boost::asio::ip::udp::endpoint& remoteEndpoint, - const i2p::data::RouterInfo * router, bool peerTest ): - m_Server (server), m_RemoteEndpoint (remoteEndpoint), m_RemoteRouter (router), + const i2p::data::RouterInfo * router, bool peerTest ): TransportSession (router), + m_Server (server), m_RemoteEndpoint (remoteEndpoint), m_Timer (m_Server.GetService ()), m_PeerTest (peerTest), m_State (eSessionStateUnknown), m_IsSessionKey (false), m_RelayTag (0), m_Data (*this), m_NumSentBytes (0), m_NumReceivedBytes (0) @@ -232,10 +232,8 @@ namespace transport payload += 2; // size of identity fragment if (identitySize == i2p::data::DEFAULT_IDENTITY_SIZE) { - i2p::data::Identity ident; - ident.FromBuffer (payload, identitySize); - m_RemoteIdent = ident.Hash (); - m_Data.UpdatePacketSize (m_RemoteIdent); + m_RemoteIdentity.FromBuffer (payload, identitySize); + m_Data.UpdatePacketSize (m_RemoteIdentity.GetIdentHash ()); } else LogPrint ("SSU unexpected identity size ", identitySize); diff --git a/SSU.h b/SSU.h index 7f1d2563..b9fb781e 100644 --- a/SSU.h +++ b/SSU.h @@ -72,7 +72,6 @@ namespace transport void WaitForIntroduction (); void Close (); boost::asio::ip::udp::endpoint& GetRemoteEndpoint () { return m_RemoteEndpoint; }; - const i2p::data::RouterInfo * GetRemoteRouter () const { return m_RemoteRouter; }; void SendI2NPMessage (I2NPMessage * msg); void SendPeerTest (); // Alice @@ -129,8 +128,6 @@ namespace transport friend class SSUData; // TODO: change in later SSUServer& m_Server; boost::asio::ip::udp::endpoint m_RemoteEndpoint; - const i2p::data::RouterInfo * m_RemoteRouter; - i2p::data::IdentHash m_RemoteIdent; // if m_RemoteRouter is null boost::asio::deadline_timer m_Timer; bool m_PeerTest; SessionState m_State; diff --git a/TransportSession.h b/TransportSession.h index 37b58fe8..0e993508 100644 --- a/TransportSession.h +++ b/TransportSession.h @@ -2,6 +2,8 @@ #define TRANSPORT_SESSION_H__ #include +#include "Identity.h" +#include "RouterInfo.h" namespace i2p { @@ -17,11 +19,22 @@ namespace transport { public: - TransportSession (): m_DHKeysPair (nullptr) {}; + TransportSession (const i2p::data::RouterInfo * in_RemoteRouter): + m_RemoteRouter (in_RemoteRouter), m_DHKeysPair (nullptr) + { + if (m_RemoteRouter) + m_RemoteIdentity = m_RemoteRouter->GetRouterIdentity (); + } + virtual ~TransportSession () { delete m_DHKeysPair; }; + const i2p::data::RouterInfo * GetRemoteRouter () { return m_RemoteRouter; }; + const i2p::data::IdentityEx& GetRemoteIdentity () { return m_RemoteIdentity; }; + protected: + const i2p::data::RouterInfo * m_RemoteRouter; + i2p::data::IdentityEx m_RemoteIdentity; DHKeysPair * m_DHKeysPair; // X - for client and Y - for server }; }