mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-11 21:47:52 +00:00
inbound tunnels
This commit is contained in:
parent
1c0c530769
commit
0214ad69a6
36
BOB.cpp
36
BOB.cpp
@ -122,7 +122,7 @@ namespace client
|
|||||||
|
|
||||||
BOBCommandSession::BOBCommandSession (BOBCommandChannel& owner):
|
BOBCommandSession::BOBCommandSession (BOBCommandChannel& owner):
|
||||||
m_Owner (owner), m_Socket (m_Owner.GetService ()), m_ReceiveBufferOffset (0),
|
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)
|
void BOBCommandSession::StartCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "BOB: start ", m_Nickname);
|
LogPrint (eLogDebug, "BOB: start ", m_Nickname);
|
||||||
if (m_IsOutgoing)
|
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)
|
||||||
{
|
{
|
||||||
auto dest = context.CreateNewLocalDestination (m_Keys, true);
|
|
||||||
auto tunnel = new I2PServerTunnel (m_Owner.GetService (), m_Address, m_Port, dest);
|
|
||||||
m_Owner.AddTunnel (m_Nickname, tunnel);
|
m_Owner.AddTunnel (m_Nickname, tunnel);
|
||||||
tunnel->Start ();
|
tunnel->Start ();
|
||||||
SendReplyOK ("tunnel starting");
|
SendReplyOK ("tunnel starting");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
SendReplyError ("not implemented");
|
SendReplyError ("failed to create tunnel");
|
||||||
}
|
}
|
||||||
|
|
||||||
void BOBCommandSession::SetNickCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::SetNickCommandHandler (const char * operand, size_t len)
|
||||||
@ -281,7 +285,7 @@ namespace client
|
|||||||
void BOBCommandSession::OuthostCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::OuthostCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "BOB: outhost");
|
LogPrint (eLogDebug, "BOB: outhost");
|
||||||
m_IsOutgoing = true;
|
m_IsOutbound = true;
|
||||||
m_Address = operand;
|
m_Address = operand;
|
||||||
SendReplyOK ("outhost set");
|
SendReplyOK ("outhost set");
|
||||||
}
|
}
|
||||||
@ -289,11 +293,27 @@ namespace client
|
|||||||
void BOBCommandSession::OutportCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::OutportCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "BOB: outport");
|
LogPrint (eLogDebug, "BOB: outport");
|
||||||
m_IsOutgoing = true;
|
m_IsOutbound = true;
|
||||||
m_Port = boost::lexical_cast<int>(operand);
|
m_Port = boost::lexical_cast<int>(operand);
|
||||||
SendReplyOK ("outbound port set");
|
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<int>(operand);
|
||||||
|
SendReplyOK ("inbound port set");
|
||||||
|
}
|
||||||
|
|
||||||
BOBCommandChannel::BOBCommandChannel (int port):
|
BOBCommandChannel::BOBCommandChannel (int port):
|
||||||
m_IsRunning (false), m_Thread (nullptr),
|
m_IsRunning (false), m_Thread (nullptr),
|
||||||
m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port))
|
m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port))
|
||||||
@ -306,6 +326,8 @@ namespace client
|
|||||||
m_CommandHandlers[BOB_COMMAND_NEWKEYS] = &BOBCommandSession::NewkeysCommandHandler;
|
m_CommandHandlers[BOB_COMMAND_NEWKEYS] = &BOBCommandSession::NewkeysCommandHandler;
|
||||||
m_CommandHandlers[BOB_COMMAND_OUTHOST] = &BOBCommandSession::OuthostCommandHandler;
|
m_CommandHandlers[BOB_COMMAND_OUTHOST] = &BOBCommandSession::OuthostCommandHandler;
|
||||||
m_CommandHandlers[BOB_COMMAND_OUTPORT] = &BOBCommandSession::OutportCommandHandler;
|
m_CommandHandlers[BOB_COMMAND_OUTPORT] = &BOBCommandSession::OutportCommandHandler;
|
||||||
|
m_CommandHandlers[BOB_COMMAND_INHOST] = &BOBCommandSession::InhostCommandHandler;
|
||||||
|
m_CommandHandlers[BOB_COMMAND_INPORT] = &BOBCommandSession::InportCommandHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOBCommandChannel::~BOBCommandChannel ()
|
BOBCommandChannel::~BOBCommandChannel ()
|
||||||
|
6
BOB.h
6
BOB.h
@ -23,6 +23,8 @@ namespace client
|
|||||||
const char BOB_COMMAND_NEWKEYS[] = "newkeys";
|
const char BOB_COMMAND_NEWKEYS[] = "newkeys";
|
||||||
const char BOB_COMMAND_OUTHOST[] = "outhost";
|
const char BOB_COMMAND_OUTHOST[] = "outhost";
|
||||||
const char BOB_COMMAND_OUTPORT[] = "outport";
|
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_OK[] = "OK %s\n";
|
||||||
const char BOB_REPLY_ERROR[] = "ERROR %s\n";
|
const char BOB_REPLY_ERROR[] = "ERROR %s\n";
|
||||||
@ -77,6 +79,8 @@ namespace client
|
|||||||
void NewkeysCommandHandler (const char * operand, size_t len);
|
void NewkeysCommandHandler (const char * operand, size_t len);
|
||||||
void OuthostCommandHandler (const char * operand, size_t len);
|
void OuthostCommandHandler (const char * operand, size_t len);
|
||||||
void OutportCommandHandler (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:
|
private:
|
||||||
|
|
||||||
@ -93,7 +97,7 @@ namespace client
|
|||||||
boost::asio::ip::tcp::socket m_Socket;
|
boost::asio::ip::tcp::socket m_Socket;
|
||||||
char m_ReceiveBuffer[BOB_COMMAND_BUFFER_SIZE + 1], m_SendBuffer[BOB_COMMAND_BUFFER_SIZE + 1];
|
char m_ReceiveBuffer[BOB_COMMAND_BUFFER_SIZE + 1], m_SendBuffer[BOB_COMMAND_BUFFER_SIZE + 1];
|
||||||
size_t m_ReceiveBufferOffset;
|
size_t m_ReceiveBufferOffset;
|
||||||
bool m_IsOpen, m_IsOutgoing;
|
bool m_IsOpen, m_IsOutbound;
|
||||||
std::string m_Nickname, m_Address;
|
std::string m_Nickname, m_Address;
|
||||||
int m_Port;
|
int m_Port;
|
||||||
i2p::data::PrivateKeys m_Keys;
|
i2p::data::PrivateKeys m_Keys;
|
||||||
|
@ -61,6 +61,9 @@ namespace client
|
|||||||
m_Service (service), m_LocalDestination (localDestination) {};
|
m_Service (service), m_LocalDestination (localDestination) {};
|
||||||
virtual ~I2PTunnel () { ClearConnections (); };
|
virtual ~I2PTunnel () { ClearConnections (); };
|
||||||
|
|
||||||
|
virtual void Start () {};
|
||||||
|
virtual void Stop () {};
|
||||||
|
|
||||||
void AddConnection (std::shared_ptr<I2PTunnelConnection> conn);
|
void AddConnection (std::shared_ptr<I2PTunnelConnection> conn);
|
||||||
void RemoveConnection (std::shared_ptr<I2PTunnelConnection> conn);
|
void RemoveConnection (std::shared_ptr<I2PTunnelConnection> conn);
|
||||||
void ClearConnections ();
|
void ClearConnections ();
|
||||||
|
Loading…
Reference in New Issue
Block a user