Browse Source

eliminated NTCPServerConnection

pull/113/head
orignal 10 years ago
parent
commit
6c13ad78a5
  1. 16
      NTCPSession.cpp
  2. 14
      NTCPSession.h
  3. 12
      Transports.cpp
  4. 4
      Transports.h

16
NTCPSession.cpp

@ -98,7 +98,6 @@ namespace transport
void NTCPSession::Connected () void NTCPSession::Connected ()
{ {
LogPrint ("NTCP session connected");
m_IsEstablished = true; m_IsEstablished = true;
delete m_Establisher; delete m_Establisher;
@ -357,8 +356,8 @@ namespace transport
boost::bind(&NTCPSession::HandlePhase3ExtraReceived, this, boost::bind(&NTCPSession::HandlePhase3ExtraReceived, this,
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, tsB, paddingLen)); boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, tsB, paddingLen));
} }
else
HandlePhase3 (tsB, paddingLen); HandlePhase3 (tsB, paddingLen);
} }
} }
@ -431,6 +430,9 @@ namespace transport
else else
{ {
LogPrint (eLogDebug, "Phase 4 sent: ", bytes_transferred); LogPrint (eLogDebug, "Phase 4 sent: ", bytes_transferred);
LogPrint ("NTCP server session connected");
transports.AddNTCPSession (this);
Connected (); Connected ();
m_ReceiveBufferOffset = 0; m_ReceiveBufferOffset = 0;
m_NextMessage = nullptr; m_NextMessage = nullptr;
@ -469,6 +471,7 @@ namespace transport
Terminate (); Terminate ();
return; return;
} }
LogPrint ("NTCP session connected");
Connected (); Connected ();
m_ReceiveBufferOffset = 0; m_ReceiveBufferOffset = 0;
@ -690,12 +693,5 @@ namespace transport
ClientLogin (); ClientLogin ();
} }
} }
void NTCPServerConnection::Connected ()
{
LogPrint ("NTCP server session connected");
transports.AddNTCPSession (this);
NTCPSession::Connected ();
}
} }
} }

14
NTCPSession.h

@ -41,7 +41,7 @@ namespace transport
const size_t NTCP_MAX_MESSAGE_SIZE = 16384; const size_t NTCP_MAX_MESSAGE_SIZE = 16384;
const size_t NTCP_BUFFER_SIZE = 1040; // fits one tunnel message (1028) const size_t NTCP_BUFFER_SIZE = 1040; // fits one tunnel message (1028)
const int NTCP_TERMINATION_TIMEOUT = 120; // 2 minutes const int NTCP_TERMINATION_TIMEOUT = 120; // 2 minutes
const size_t NTCP_DEFAULT_PHASE3_SIZE = 2/*size*/ + i2p::data::DEFAULT_IDENTITY_SIZE/*387*/ + 4/*ts*/ + 15/*padding*/ + 40/*signature*/; // 428 const size_t NTCP_DEFAULT_PHASE3_SIZE = 2/*size*/ + i2p::data::DEFAULT_IDENTITY_SIZE/*387*/ + 4/*ts*/ + 15/*padding*/ + 40/*signature*/; // 448
class NTCPSession: public TransportSession class NTCPSession: public TransportSession
{ {
@ -143,18 +143,6 @@ namespace transport
boost::asio::ip::tcp::endpoint m_Endpoint; boost::asio::ip::tcp::endpoint m_Endpoint;
}; };
class NTCPServerConnection: public NTCPSession
{
public:
NTCPServerConnection (boost::asio::io_service& service):
NTCPSession (service) {};
protected:
virtual void Connected ();
};
} }
} }

12
Transports.cpp

@ -121,7 +121,7 @@ namespace transport
boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), address.port)); boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), address.port));
LogPrint ("Start listening TCP port ", address.port); LogPrint ("Start listening TCP port ", address.port);
auto conn = new NTCPServerConnection (m_Service); auto conn = new NTCPSession (m_Service);
m_NTCPAcceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAccept, this, m_NTCPAcceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAccept, this,
conn, boost::asio::placeholders::error)); conn, boost::asio::placeholders::error));
@ -134,7 +134,7 @@ namespace transport
m_NTCPV6Acceptor->listen (); m_NTCPV6Acceptor->listen ();
LogPrint ("Start listening V6 TCP port ", address.port); LogPrint ("Start listening V6 TCP port ", address.port);
auto conn = new NTCPServerConnection (m_Service); auto conn = new NTCPSession (m_Service);
m_NTCPV6Acceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAcceptV6, m_NTCPV6Acceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAcceptV6,
this, conn, boost::asio::placeholders::error)); this, conn, boost::asio::placeholders::error));
} }
@ -209,7 +209,7 @@ namespace transport
m_NTCPSessions.erase (session->GetRemoteIdentity ().GetIdentHash ()); m_NTCPSessions.erase (session->GetRemoteIdentity ().GetIdentHash ());
} }
void Transports::HandleAccept (NTCPServerConnection * conn, const boost::system::error_code& error) void Transports::HandleAccept (NTCPSession * conn, const boost::system::error_code& error)
{ {
if (!error) if (!error)
{ {
@ -221,13 +221,13 @@ namespace transport
if (error != boost::asio::error::operation_aborted) if (error != boost::asio::error::operation_aborted)
{ {
conn = new NTCPServerConnection (m_Service); conn = new NTCPSession (m_Service);
m_NTCPAcceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAccept, this, m_NTCPAcceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAccept, this,
conn, boost::asio::placeholders::error)); conn, boost::asio::placeholders::error));
} }
} }
void Transports::HandleAcceptV6 (NTCPServerConnection * conn, const boost::system::error_code& error) void Transports::HandleAcceptV6 (NTCPSession * conn, const boost::system::error_code& error)
{ {
if (!error) if (!error)
{ {
@ -239,7 +239,7 @@ namespace transport
if (error != boost::asio::error::operation_aborted) if (error != boost::asio::error::operation_aborted)
{ {
conn = new NTCPServerConnection (m_Service); conn = new NTCPSession (m_Service);
m_NTCPV6Acceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAcceptV6, this, m_NTCPV6Acceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAcceptV6, this,
conn, boost::asio::placeholders::error)); conn, boost::asio::placeholders::error));
} }

4
Transports.h

@ -75,8 +75,8 @@ namespace transport
private: private:
void Run (); void Run ();
void HandleAccept (NTCPServerConnection * conn, const boost::system::error_code& error); void HandleAccept (NTCPSession * conn, const boost::system::error_code& error);
void HandleAcceptV6 (NTCPServerConnection * conn, const boost::system::error_code& error); void HandleAcceptV6 (NTCPSession * conn, const boost::system::error_code& error);
void HandleResendTimer (const boost::system::error_code& ecode, boost::asio::deadline_timer * timer, void HandleResendTimer (const boost::system::error_code& ecode, boost::asio::deadline_timer * timer,
const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg); const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);
void PostMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg); void PostMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);

Loading…
Cancel
Save