Browse Source

BOB 'list' command

pull/113/head
orignal 10 years ago
parent
commit
9164ac8a3e
  1. 41
      BOB.cpp
  2. 38
      BOB.h
  3. 3
      I2PTunnel.h

41
BOB.cpp

@ -10,7 +10,7 @@ namespace i2p @@ -10,7 +10,7 @@ namespace i2p
namespace client
{
BOBI2PInboundTunnel::BOBI2PInboundTunnel (boost::asio::io_service& service, int port, ClientDestination * localDestination):
I2PTunnel (service, localDestination),
BOBI2PTunnel (service, localDestination),
m_Acceptor (service, boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)),
m_Timer (service), m_ReceivedData (nullptr), m_ReceivedDataLen (0)
{
@ -96,7 +96,7 @@ namespace client @@ -96,7 +96,7 @@ namespace client
}
else
{
LogPrint ("BOB missing inbound address ", ecode.message ());
LogPrint ("BOB missing inbound address ", bytes_transferred);
delete socket;
}
}
@ -127,7 +127,7 @@ namespace client @@ -127,7 +127,7 @@ namespace client
}
BOBI2POutboundTunnel::BOBI2POutboundTunnel (boost::asio::io_service& service, const std::string& address, int port,
ClientDestination * localDestination, bool quiet): I2PTunnel (service, localDestination),
ClientDestination * localDestination, bool quiet): BOBI2PTunnel (service, localDestination),
m_Endpoint (boost::asio::ip::address::from_string (address), port), m_IsQuiet (quiet)
{
}
@ -280,7 +280,7 @@ namespace client @@ -280,7 +280,7 @@ namespace client
#endif
Send (len);
}
void BOBCommandSession::SendVersion ()
{
size_t len = strlen (BOB_VERSION);
@ -288,6 +288,16 @@ namespace client @@ -288,6 +288,16 @@ namespace client
Send (len);
}
void BOBCommandSession::SendData (const char * nickname)
{
#ifdef _MSC_VER
size_t len = sprintf_s (m_SendBuffer, BOB_COMMAND_BUFFER_SIZE, BOB_DATA, nickname);
#else
size_t len = snprintf (m_SendBuffer, BOB_COMMAND_BUFFER_SIZE, BOB_DATA, nickname);
#endif
Send (len);
}
void BOBCommandSession::ZapCommandHandler (const char * operand, size_t len)
{
LogPrint (eLogDebug, "BOB: zap");
@ -305,7 +315,7 @@ namespace client @@ -305,7 +315,7 @@ namespace client
{
LogPrint (eLogDebug, "BOB: start ", m_Nickname);
auto dest = context.CreateNewLocalDestination (m_Keys, true);
I2PTunnel * tunnel = nullptr;
BOBI2PTunnel * tunnel = nullptr;
if (m_IsOutbound)
tunnel = new BOBI2POutboundTunnel (m_Owner.GetService (), m_Address, m_Port, dest, m_IsQuiet);
else
@ -442,6 +452,21 @@ namespace client @@ -442,6 +452,21 @@ namespace client
SendReplyOK ("cleared");
}
void BOBCommandSession::ListCommandHandler (const char * operand, size_t len)
{
LogPrint (eLogDebug, "BOB: list");
auto& tunnels = m_Owner.GetTunnels ();
for (auto it: tunnels)
SendData (it.first.c_str ());
SendReplyOK ("Listing done");
}
void BOBCommandSession::OptionCommandHandler (const char * operand, size_t len)
{
LogPrint (eLogDebug, "BOB: option ", operand);
SendReplyOK ("option");
}
BOBCommandChannel::BOBCommandChannel (int port):
m_IsRunning (false), m_Thread (nullptr),
m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port))
@ -464,6 +489,8 @@ namespace client @@ -464,6 +489,8 @@ namespace client
m_CommandHandlers[BOB_COMMAND_QUIET] = &BOBCommandSession::QuietCommandHandler;
m_CommandHandlers[BOB_COMMAND_LOOKUP] = &BOBCommandSession::LookupCommandHandler;
m_CommandHandlers[BOB_COMMAND_CLEAR] = &BOBCommandSession::ClearCommandHandler;
m_CommandHandlers[BOB_COMMAND_LIST] = &BOBCommandSession::ListCommandHandler;
m_CommandHandlers[BOB_COMMAND_OPTION] = &BOBCommandSession::OptionCommandHandler;
}
BOBCommandChannel::~BOBCommandChannel ()
@ -509,12 +536,12 @@ namespace client @@ -509,12 +536,12 @@ namespace client
}
}
void BOBCommandChannel::AddTunnel (const std::string& name, I2PTunnel * tunnel)
void BOBCommandChannel::AddTunnel (const std::string& name, BOBI2PTunnel * tunnel)
{
m_Tunnels[name] = tunnel;
}
I2PTunnel * BOBCommandChannel::FindTunnel (const std::string& name)
BOBI2PTunnel * BOBCommandChannel::FindTunnel (const std::string& name)
{
auto it = m_Tunnels.find (name);
if (it != m_Tunnels.end ())

38
BOB.h

@ -32,13 +32,27 @@ namespace client @@ -32,13 +32,27 @@ namespace client
const char BOB_COMMAND_INPORT[] = "inport";
const char BOB_COMMAND_QUIET[] = "quiet";
const char BOB_COMMAND_LOOKUP[] = "lookup";
const char BOB_COMMAND_CLEAR[] = "clear";
const char BOB_COMMAND_CLEAR[] = "clear";
const char BOB_COMMAND_LIST[] = "list";
const char BOB_COMMAND_OPTION[] = "option";
const char BOB_VERSION[] = "BOB 00.00.10\nOK\n";
const char BOB_REPLY_OK[] = "OK %s\n";
const char BOB_REPLY_ERROR[] = "ERROR %s\n";
const char BOB_DATA[] = "NICKNAME %s\n";
class BOBI2PTunnel: public I2PTunnel
{
public:
BOBI2PTunnel (boost::asio::io_service& service, ClientDestination * localDestination):
I2PTunnel (service, localDestination) {};
class BOBI2PInboundTunnel: public I2PTunnel
virtual void Start () {};
virtual void Stop () {};
};
class BOBI2PInboundTunnel: public BOBI2PTunnel
{
public:
@ -70,7 +84,7 @@ namespace client @@ -70,7 +84,7 @@ namespace client
size_t m_ReceivedDataLen;
};
class BOBI2POutboundTunnel: public I2PTunnel
class BOBI2POutboundTunnel: public BOBI2PTunnel
{
public:
@ -123,6 +137,8 @@ namespace client @@ -123,6 +137,8 @@ namespace client
void QuietCommandHandler (const char * operand, size_t len);
void LookupCommandHandler (const char * operand, size_t len);
void ClearCommandHandler (const char * operand, size_t len);
void ListCommandHandler (const char * operand, size_t len);
void OptionCommandHandler (const char * operand, size_t len);
private:
@ -133,7 +149,7 @@ namespace client @@ -133,7 +149,7 @@ namespace client
void HandleSent (const boost::system::error_code& ecode, std::size_t bytes_transferred);
void SendReplyOK (const char * msg);
void SendReplyError (const char * msg);
void SendData (const char * nickname);
private:
@ -159,9 +175,8 @@ namespace client @@ -159,9 +175,8 @@ namespace client
void Stop ();
boost::asio::io_service& GetService () { return m_Service; };
std::map<std::string, BOBCommandHandler>& GetCommandHandlers () { return m_CommandHandlers; };
void AddTunnel (const std::string& name, I2PTunnel * tunnel);
I2PTunnel * FindTunnel (const std::string& name);
void AddTunnel (const std::string& name, BOBI2PTunnel * tunnel);
BOBI2PTunnel * FindTunnel (const std::string& name);
private:
@ -175,8 +190,13 @@ namespace client @@ -175,8 +190,13 @@ namespace client
std::thread * m_Thread;
boost::asio::io_service m_Service;
boost::asio::ip::tcp::acceptor m_Acceptor;
std::map<std::string, I2PTunnel *> m_Tunnels;
std::map<std::string, BOBI2PTunnel *> m_Tunnels;
std::map<std::string, BOBCommandHandler> m_CommandHandlers;
public:
const decltype(m_CommandHandlers)& GetCommandHandlers () const { return m_CommandHandlers; };
const decltype(m_Tunnels)& GetTunnels () const { return m_Tunnels; };
};
}
}

3
I2PTunnel.h

@ -62,9 +62,6 @@ namespace client @@ -62,9 +62,6 @@ namespace client
m_Service (service), m_LocalDestination (localDestination) {};
virtual ~I2PTunnel () { ClearConnections (); };
virtual void Start () {};
virtual void Stop () {};
void AddConnection (std::shared_ptr<I2PTunnelConnection> conn);
void RemoveConnection (std::shared_ptr<I2PTunnelConnection> conn);
void ClearConnections ();

Loading…
Cancel
Save