Browse Source

BOB lookup command

pull/113/head
orignal 10 years ago
parent
commit
9a9d6e8e00
  1. 23
      BOB.cpp
  2. 9
      BOB.h

23
BOB.cpp

@ -281,6 +281,13 @@ namespace client
Send (len); Send (len);
} }
void BOBCommandSession::SendVersion ()
{
size_t len = strlen (BOB_VERSION);
memcpy (m_SendBuffer, BOB_VERSION, len);
Send (len);
}
void BOBCommandSession::ZapCommandHandler (const char * operand, size_t len) void BOBCommandSession::ZapCommandHandler (const char * operand, size_t len)
{ {
LogPrint (eLogDebug, "BOB: zap"); LogPrint (eLogDebug, "BOB: zap");
@ -416,6 +423,19 @@ namespace client
SendReplyOK ("quiet"); SendReplyOK ("quiet");
} }
void BOBCommandSession::LookupCommandHandler (const char * operand, size_t len)
{
LogPrint (eLogDebug, "BOB: lookup");
i2p::data::IdentityEx addr;
if (!context.GetAddressBook ().GetAddress (operand, addr))
{
SendReplyError ("Address Not found");
return;
}
SendReplyOK (addr.ToBase64 ().c_str ());
}
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))
@ -436,6 +456,7 @@ namespace client
m_CommandHandlers[BOB_COMMAND_INHOST] = &BOBCommandSession::InhostCommandHandler; m_CommandHandlers[BOB_COMMAND_INHOST] = &BOBCommandSession::InhostCommandHandler;
m_CommandHandlers[BOB_COMMAND_INPORT] = &BOBCommandSession::InportCommandHandler; m_CommandHandlers[BOB_COMMAND_INPORT] = &BOBCommandSession::InportCommandHandler;
m_CommandHandlers[BOB_COMMAND_QUIET] = &BOBCommandSession::QuietCommandHandler; m_CommandHandlers[BOB_COMMAND_QUIET] = &BOBCommandSession::QuietCommandHandler;
m_CommandHandlers[BOB_COMMAND_LOOKUP] = &BOBCommandSession::LookupCommandHandler;
} }
BOBCommandChannel::~BOBCommandChannel () BOBCommandChannel::~BOBCommandChannel ()
@ -509,7 +530,7 @@ namespace client
if (!ecode) if (!ecode)
{ {
LogPrint (eLogInfo, "New BOB command connection from ", session->GetSocket ().remote_endpoint ()); LogPrint (eLogInfo, "New BOB command connection from ", session->GetSocket ().remote_endpoint ());
session->Receive (); session->SendVersion ();
} }
else else
LogPrint (eLogError, "BOB accept error: ", ecode.message ()); LogPrint (eLogError, "BOB accept error: ", ecode.message ());

9
BOB.h

@ -30,8 +30,10 @@ namespace client
const char BOB_COMMAND_OUTPORT[] = "outport"; const char BOB_COMMAND_OUTPORT[] = "outport";
const char BOB_COMMAND_INHOST[] = "inhost"; const char BOB_COMMAND_INHOST[] = "inhost";
const char BOB_COMMAND_INPORT[] = "inport"; const char BOB_COMMAND_INPORT[] = "inport";
const char BOB_COMMAND_QUIET[] = "quiet"; const char BOB_COMMAND_QUIET[] = "quiet";
const char BOB_COMMAND_LOOKUP[] = "lookup";
const char BOB_VERSION[] = "BOB 00.00.10\nOK\n";
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";
@ -100,7 +102,7 @@ namespace client
void Terminate (); void Terminate ();
boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; }; boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; };
void Receive (); void SendVersion ();
// command handlers // command handlers
void ZapCommandHandler (const char * operand, size_t len); void ZapCommandHandler (const char * operand, size_t len);
@ -118,9 +120,11 @@ namespace client
void InhostCommandHandler (const char * operand, size_t len); void InhostCommandHandler (const char * operand, size_t len);
void InportCommandHandler (const char * operand, size_t len); void InportCommandHandler (const char * operand, size_t len);
void QuietCommandHandler (const char * operand, size_t len); void QuietCommandHandler (const char * operand, size_t len);
void LookupCommandHandler (const char * operand, size_t len);
private: private:
void Receive ();
void HandleReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred); void HandleReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred);
void Send (size_t len); void Send (size_t len);
@ -128,6 +132,7 @@ namespace client
void SendReplyOK (const char * msg); void SendReplyOK (const char * msg);
void SendReplyError (const char * msg); void SendReplyError (const char * msg);
private: private:
BOBCommandChannel& m_Owner; BOBCommandChannel& m_Owner;

Loading…
Cancel
Save