|
|
@ -168,10 +168,44 @@ namespace client |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BOBDestination::BOBDestination (boost::asio::io_service& service, ClientDestination& localDestination): |
|
|
|
|
|
|
|
m_Service (service), m_LocalDestination (localDestination), |
|
|
|
|
|
|
|
m_OutboundTunnel (nullptr), m_InboundTunnel (nullptr) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BOBDestination::~BOBDestination () |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
delete m_OutboundTunnel; |
|
|
|
|
|
|
|
delete m_InboundTunnel; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BOBDestination::Start () |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (m_OutboundTunnel) m_OutboundTunnel->Start (); |
|
|
|
|
|
|
|
if (m_InboundTunnel) m_InboundTunnel->Start (); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BOBDestination::Stop () |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (m_OutboundTunnel) m_OutboundTunnel->Stop (); |
|
|
|
|
|
|
|
if (m_InboundTunnel) m_InboundTunnel->Stop (); |
|
|
|
|
|
|
|
m_LocalDestination.Stop (); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BOBDestination::CreateInboundTunnel (int port) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_InboundTunnel = new BOBI2PInboundTunnel (m_Service, port, &m_LocalDestination); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BOBDestination::CreateOutboundTunnel (const std::string& address, int port, bool quiet) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_OutboundTunnel = new BOBI2POutboundTunnel (m_Service, address, port, &m_LocalDestination, quiet); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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_IsOutbound (false), m_IsQuiet (false), m_Port (0) |
|
|
|
m_IsOpen (true), m_IsQuiet (false), m_InPort (0), m_OutPort (0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -192,7 +226,6 @@ namespace client |
|
|
|
std::placeholders::_1, std::placeholders::_2)); |
|
|
|
std::placeholders::_1, std::placeholders::_2)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BOBCommandSession::HandleReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred) |
|
|
|
void BOBCommandSession::HandleReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (ecode) |
|
|
|
if (ecode) |
|
|
@ -322,29 +355,23 @@ 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); |
|
|
|
auto dest = context.CreateNewLocalDestination (m_Keys, true, &m_Options); |
|
|
|
BOBDestination * dest = new BOBDestination (m_Owner.GetService (), |
|
|
|
BOBI2PTunnel * tunnel = nullptr; |
|
|
|
*context.CreateNewLocalDestination (m_Keys, true, &m_Options)); |
|
|
|
if (m_IsOutbound) |
|
|
|
if (m_InPort) |
|
|
|
tunnel = new BOBI2POutboundTunnel (m_Owner.GetService (), m_Address, m_Port, dest, m_IsQuiet); |
|
|
|
dest->CreateInboundTunnel (m_InPort); |
|
|
|
else |
|
|
|
if (m_OutPort && !m_Address.empty ()) |
|
|
|
tunnel = new BOBI2PInboundTunnel (m_Owner.GetService (), m_Port, dest); |
|
|
|
dest->CreateOutboundTunnel (m_Address, m_OutPort, m_IsQuiet); |
|
|
|
if (tunnel) |
|
|
|
m_Owner.AddDestination (m_Nickname, dest); |
|
|
|
{ |
|
|
|
dest->Start (); |
|
|
|
m_Owner.AddTunnel (m_Nickname, tunnel); |
|
|
|
SendReplyOK ("tunnel starting"); |
|
|
|
tunnel->Start (); |
|
|
|
|
|
|
|
SendReplyOK ("tunnel starting"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
SendReplyError ("failed to create tunnel"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void BOBCommandSession::StopCommandHandler (const char * operand, size_t len) |
|
|
|
void BOBCommandSession::StopCommandHandler (const char * operand, size_t len) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto tunnel = m_Owner.FindTunnel (m_Nickname); |
|
|
|
auto dest = m_Owner.FindDestination (m_Nickname); |
|
|
|
if (tunnel) |
|
|
|
if (dest) |
|
|
|
{ |
|
|
|
{ |
|
|
|
tunnel->Stop (); |
|
|
|
dest->Stop (); |
|
|
|
tunnel->GetLocalDestination ()->Stop (); |
|
|
|
|
|
|
|
SendReplyOK ("tunnel stopping"); |
|
|
|
SendReplyOK ("tunnel stopping"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
@ -353,7 +380,7 @@ namespace client |
|
|
|
|
|
|
|
|
|
|
|
void BOBCommandSession::SetNickCommandHandler (const char * operand, size_t len) |
|
|
|
void BOBCommandSession::SetNickCommandHandler (const char * operand, size_t len) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogDebug, "BOB: setnick"); |
|
|
|
LogPrint (eLogDebug, "BOB: setnick ", operand); |
|
|
|
m_Nickname = operand; |
|
|
|
m_Nickname = operand; |
|
|
|
std::string msg ("Nickname set to "); |
|
|
|
std::string msg ("Nickname set to "); |
|
|
|
msg += operand; |
|
|
|
msg += operand; |
|
|
@ -362,11 +389,11 @@ namespace client |
|
|
|
|
|
|
|
|
|
|
|
void BOBCommandSession::GetNickCommandHandler (const char * operand, size_t len) |
|
|
|
void BOBCommandSession::GetNickCommandHandler (const char * operand, size_t len) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogDebug, "BOB: getnick"); |
|
|
|
LogPrint (eLogDebug, "BOB: getnick ", operand); |
|
|
|
auto tunnel = m_Owner.FindTunnel (operand); |
|
|
|
auto dest = m_Owner.FindDestination (operand); |
|
|
|
if (tunnel) |
|
|
|
if (dest) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_Keys = tunnel->GetLocalDestination ()->GetPrivateKeys (); |
|
|
|
m_Keys = dest->GetKeys (); |
|
|
|
m_Nickname = operand; |
|
|
|
m_Nickname = operand; |
|
|
|
std::string msg ("Nickname set to "); |
|
|
|
std::string msg ("Nickname set to "); |
|
|
|
msg += operand; |
|
|
|
msg += operand; |
|
|
@ -385,7 +412,7 @@ namespace client |
|
|
|
|
|
|
|
|
|
|
|
void BOBCommandSession::SetkeysCommandHandler (const char * operand, size_t len) |
|
|
|
void BOBCommandSession::SetkeysCommandHandler (const char * operand, size_t len) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogDebug, "BOB: setkeys"); |
|
|
|
LogPrint (eLogDebug, "BOB: setkeys ", operand); |
|
|
|
m_Keys.FromBase64 (operand); |
|
|
|
m_Keys.FromBase64 (operand); |
|
|
|
SendReplyOK ("keys set"); |
|
|
|
SendReplyOK ("keys set"); |
|
|
|
} |
|
|
|
} |
|
|
@ -404,33 +431,29 @@ 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 ", operand); |
|
|
|
m_IsOutbound = true; |
|
|
|
|
|
|
|
m_Address = operand; |
|
|
|
m_Address = operand; |
|
|
|
SendReplyOK ("outhost set"); |
|
|
|
SendReplyOK ("outhost set"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 ", operand); |
|
|
|
m_IsOutbound = true; |
|
|
|
m_OutPort = 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) |
|
|
|
void BOBCommandSession::InhostCommandHandler (const char * operand, size_t len) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogDebug, "BOB: inhost"); |
|
|
|
LogPrint (eLogDebug, "BOB: inhost ", operand); |
|
|
|
m_IsOutbound = false; |
|
|
|
|
|
|
|
m_Address = operand; |
|
|
|
m_Address = operand; |
|
|
|
SendReplyOK ("inhost set"); |
|
|
|
SendReplyOK ("inhost set"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void BOBCommandSession::InportCommandHandler (const char * operand, size_t len) |
|
|
|
void BOBCommandSession::InportCommandHandler (const char * operand, size_t len) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogDebug, "BOB: inport"); |
|
|
|
LogPrint (eLogDebug, "BOB: inport ", operand); |
|
|
|
m_IsOutbound = false; |
|
|
|
m_InPort = boost::lexical_cast<int>(operand); |
|
|
|
m_Port = boost::lexical_cast<int>(operand); |
|
|
|
|
|
|
|
SendReplyOK ("inbound port set"); |
|
|
|
SendReplyOK ("inbound port set"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -443,7 +466,7 @@ namespace client |
|
|
|
|
|
|
|
|
|
|
|
void BOBCommandSession::LookupCommandHandler (const char * operand, size_t len) |
|
|
|
void BOBCommandSession::LookupCommandHandler (const char * operand, size_t len) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogDebug, "BOB: lookup"); |
|
|
|
LogPrint (eLogDebug, "BOB: lookup ", operand); |
|
|
|
i2p::data::IdentityEx addr; |
|
|
|
i2p::data::IdentityEx addr; |
|
|
|
if (!context.GetAddressBook ().GetAddress (operand, addr)) |
|
|
|
if (!context.GetAddressBook ().GetAddress (operand, addr)) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -463,8 +486,8 @@ namespace client |
|
|
|
void BOBCommandSession::ListCommandHandler (const char * operand, size_t len) |
|
|
|
void BOBCommandSession::ListCommandHandler (const char * operand, size_t len) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogDebug, "BOB: list"); |
|
|
|
LogPrint (eLogDebug, "BOB: list"); |
|
|
|
auto& tunnels = m_Owner.GetTunnels (); |
|
|
|
auto& destinations = m_Owner.GetDestinations (); |
|
|
|
for (auto it: tunnels) |
|
|
|
for (auto it: destinations) |
|
|
|
SendData (it.first.c_str ()); |
|
|
|
SendData (it.first.c_str ()); |
|
|
|
SendReplyOK ("Listing done"); |
|
|
|
SendReplyOK ("Listing done"); |
|
|
|
} |
|
|
|
} |
|
|
@ -513,7 +536,7 @@ namespace client |
|
|
|
BOBCommandChannel::~BOBCommandChannel () |
|
|
|
BOBCommandChannel::~BOBCommandChannel () |
|
|
|
{ |
|
|
|
{ |
|
|
|
Stop (); |
|
|
|
Stop (); |
|
|
|
for (auto it: m_Tunnels) |
|
|
|
for (auto it: m_Destinations) |
|
|
|
delete it.second; |
|
|
|
delete it.second; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -526,7 +549,7 @@ namespace client |
|
|
|
|
|
|
|
|
|
|
|
void BOBCommandChannel::Stop () |
|
|
|
void BOBCommandChannel::Stop () |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (auto it: m_Tunnels) |
|
|
|
for (auto it: m_Destinations) |
|
|
|
it.second->Stop (); |
|
|
|
it.second->Stop (); |
|
|
|
m_IsRunning = false; |
|
|
|
m_IsRunning = false; |
|
|
|
m_Service.stop (); |
|
|
|
m_Service.stop (); |
|
|
@ -553,15 +576,15 @@ namespace client |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void BOBCommandChannel::AddTunnel (const std::string& name, BOBI2PTunnel * tunnel) |
|
|
|
void BOBCommandChannel::AddDestination (const std::string& name, BOBDestination * dest) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_Tunnels[name] = tunnel; |
|
|
|
m_Destinations[name] = dest; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BOBI2PTunnel * BOBCommandChannel::FindTunnel (const std::string& name) |
|
|
|
BOBDestination * BOBCommandChannel::FindDestination (const std::string& name) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto it = m_Tunnels.find (name); |
|
|
|
auto it = m_Destinations.find (name); |
|
|
|
if (it != m_Tunnels.end ()) |
|
|
|
if (it != m_Destinations.end ()) |
|
|
|
return it->second; |
|
|
|
return it->second; |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|