From 0214ad69a6b8729bf55aeff9c1448740199342a1 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 3 Dec 2014 15:02:19 -0500 Subject: [PATCH] inbound tunnels --- BOB.cpp | 40 +++++++++++++++++++++++++++++++--------- BOB.h | 8 ++++++-- I2PTunnel.h | 3 +++ 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/BOB.cpp b/BOB.cpp index 1c62141b..c08ddbfb 100644 --- a/BOB.cpp +++ b/BOB.cpp @@ -122,7 +122,7 @@ namespace client BOBCommandSession::BOBCommandSession (BOBCommandChannel& owner): m_Owner (owner), m_Socket (m_Owner.GetService ()), m_ReceiveBufferOffset (0), - m_IsOpen (true), m_IsOutgoing (false), m_Port (0) + m_IsOpen (true), m_IsOutbound (false), m_Port (0) { } @@ -250,16 +250,20 @@ namespace client void BOBCommandSession::StartCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: start ", m_Nickname); - if (m_IsOutgoing) - { - auto dest = context.CreateNewLocalDestination (m_Keys, true); - auto tunnel = new I2PServerTunnel (m_Owner.GetService (), m_Address, m_Port, dest); + auto dest = context.CreateNewLocalDestination (m_Keys, true); + I2PTunnel * tunnel = nullptr; + if (m_IsOutbound) + tunnel = new I2PServerTunnel (m_Owner.GetService (), m_Address, m_Port, dest); + else + tunnel = new BOBI2PInboundTunnel (m_Owner.GetService (), m_Port, dest); + if (tunnel) + { m_Owner.AddTunnel (m_Nickname, tunnel); - tunnel->Start (); + tunnel->Start (); SendReplyOK ("tunnel starting"); } else - SendReplyError ("not implemented"); + SendReplyError ("failed to create tunnel"); } void BOBCommandSession::SetNickCommandHandler (const char * operand, size_t len) @@ -281,7 +285,7 @@ namespace client void BOBCommandSession::OuthostCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: outhost"); - m_IsOutgoing = true; + m_IsOutbound = true; m_Address = operand; SendReplyOK ("outhost set"); } @@ -289,10 +293,26 @@ namespace client void BOBCommandSession::OutportCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: outport"); - m_IsOutgoing = true; + m_IsOutbound = true; m_Port = boost::lexical_cast(operand); SendReplyOK ("outbound port set"); } + + void BOBCommandSession::InhostCommandHandler (const char * operand, size_t len) + { + LogPrint (eLogDebug, "BOB: inhost"); + m_IsOutbound = false; + m_Address = operand; + SendReplyOK ("inhost set"); + } + + void BOBCommandSession::InportCommandHandler (const char * operand, size_t len) + { + LogPrint (eLogDebug, "BOB: inport"); + m_IsOutbound = false; + m_Port = boost::lexical_cast(operand); + SendReplyOK ("inbound port set"); + } BOBCommandChannel::BOBCommandChannel (int port): m_IsRunning (false), m_Thread (nullptr), @@ -306,6 +326,8 @@ namespace client m_CommandHandlers[BOB_COMMAND_NEWKEYS] = &BOBCommandSession::NewkeysCommandHandler; m_CommandHandlers[BOB_COMMAND_OUTHOST] = &BOBCommandSession::OuthostCommandHandler; m_CommandHandlers[BOB_COMMAND_OUTPORT] = &BOBCommandSession::OutportCommandHandler; + m_CommandHandlers[BOB_COMMAND_INHOST] = &BOBCommandSession::InhostCommandHandler; + m_CommandHandlers[BOB_COMMAND_INPORT] = &BOBCommandSession::InportCommandHandler; } BOBCommandChannel::~BOBCommandChannel () diff --git a/BOB.h b/BOB.h index 58b75104..7951cfb8 100644 --- a/BOB.h +++ b/BOB.h @@ -23,6 +23,8 @@ namespace client const char BOB_COMMAND_NEWKEYS[] = "newkeys"; const char BOB_COMMAND_OUTHOST[] = "outhost"; const char BOB_COMMAND_OUTPORT[] = "outport"; + const char BOB_COMMAND_INHOST[] = "inhost"; + const char BOB_COMMAND_INPORT[] = "inport"; const char BOB_REPLY_OK[] = "OK %s\n"; const char BOB_REPLY_ERROR[] = "ERROR %s\n"; @@ -77,7 +79,9 @@ namespace client void NewkeysCommandHandler (const char * operand, size_t len); void OuthostCommandHandler (const char * operand, size_t len); void OutportCommandHandler (const char * operand, size_t len); - + void InhostCommandHandler (const char * operand, size_t len); + void InportCommandHandler (const char * operand, size_t len); + private: void HandleReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred); @@ -93,7 +97,7 @@ namespace client boost::asio::ip::tcp::socket m_Socket; char m_ReceiveBuffer[BOB_COMMAND_BUFFER_SIZE + 1], m_SendBuffer[BOB_COMMAND_BUFFER_SIZE + 1]; size_t m_ReceiveBufferOffset; - bool m_IsOpen, m_IsOutgoing; + bool m_IsOpen, m_IsOutbound; std::string m_Nickname, m_Address; int m_Port; i2p::data::PrivateKeys m_Keys; diff --git a/I2PTunnel.h b/I2PTunnel.h index 6d906c1e..86eab4a2 100644 --- a/I2PTunnel.h +++ b/I2PTunnel.h @@ -61,6 +61,9 @@ namespace client m_Service (service), m_LocalDestination (localDestination) {}; virtual ~I2PTunnel () { ClearConnections (); }; + virtual void Start () {}; + virtual void Stop () {}; + void AddConnection (std::shared_ptr conn); void RemoveConnection (std::shared_ptr conn); void ClearConnections ();