Browse Source

handle stop command

pull/113/head
orignal 10 years ago
parent
commit
b2a6b6657f
  1. 43
      BOB.cpp
  2. 7
      BOB.h

43
BOB.cpp

@ -265,7 +265,19 @@ namespace client
else else
SendReplyError ("failed to create tunnel"); SendReplyError ("failed to create tunnel");
} }
void BOBCommandSession::StopCommandHandler (const char * operand, size_t len)
{
auto tunnel = m_Owner.FindTunnel (m_Nickname);
if (tunnel)
{
tunnel->Stop ();
SendReplyOK ("tunnel stopping");
}
else
SendReplyError ("tunnel not found");
}
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");
@ -275,6 +287,20 @@ namespace client
SendReplyOK (msg.c_str ()); SendReplyOK (msg.c_str ());
} }
void BOBCommandSession::GetNickCommandHandler (const char * operand, size_t len)
{
LogPrint (eLogDebug, "BOB: getnick");
if (m_Owner.FindTunnel (operand))
{
m_Nickname = operand;
std::string msg ("Nickname set to");
msg += operand;
SendReplyOK (msg.c_str ());
}
else
SendReplyError ("tunnel not found");
}
void BOBCommandSession::NewkeysCommandHandler (const char * operand, size_t len) void BOBCommandSession::NewkeysCommandHandler (const char * operand, size_t len)
{ {
LogPrint (eLogDebug, "BOB: newkeys"); LogPrint (eLogDebug, "BOB: newkeys");
@ -322,7 +348,9 @@ namespace client
m_CommandHandlers[BOB_COMMAND_ZAP] = &BOBCommandSession::ZapCommandHandler; m_CommandHandlers[BOB_COMMAND_ZAP] = &BOBCommandSession::ZapCommandHandler;
m_CommandHandlers[BOB_COMMAND_QUIT] = &BOBCommandSession::QuitCommandHandler; m_CommandHandlers[BOB_COMMAND_QUIT] = &BOBCommandSession::QuitCommandHandler;
m_CommandHandlers[BOB_COMMAND_START] = &BOBCommandSession::StartCommandHandler; m_CommandHandlers[BOB_COMMAND_START] = &BOBCommandSession::StartCommandHandler;
m_CommandHandlers[BOB_COMMAND_STOP] = &BOBCommandSession::StopCommandHandler;
m_CommandHandlers[BOB_COMMAND_SETNICK] = &BOBCommandSession::SetNickCommandHandler; m_CommandHandlers[BOB_COMMAND_SETNICK] = &BOBCommandSession::SetNickCommandHandler;
m_CommandHandlers[BOB_COMMAND_GETNICK] = &BOBCommandSession::GetNickCommandHandler;
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;
@ -333,6 +361,8 @@ namespace client
BOBCommandChannel::~BOBCommandChannel () BOBCommandChannel::~BOBCommandChannel ()
{ {
Stop (); Stop ();
for (auto it: m_Tunnels)
delete it.second;
} }
void BOBCommandChannel::Start () void BOBCommandChannel::Start ()
@ -345,8 +375,7 @@ namespace client
void BOBCommandChannel::Stop () void BOBCommandChannel::Stop ()
{ {
for (auto it: m_Tunnels) for (auto it: m_Tunnels)
delete it.second; it.second->Stop ();
m_Tunnels.clear ();
m_IsRunning = false; m_IsRunning = false;
m_Service.stop (); m_Service.stop ();
if (m_Thread) if (m_Thread)
@ -376,6 +405,14 @@ namespace client
{ {
m_Tunnels[name] = tunnel; m_Tunnels[name] = tunnel;
} }
I2PTunnel * BOBCommandChannel::FindTunnel (const std::string& name)
{
auto it = m_Tunnels.find (name);
if (it != m_Tunnels.end ())
return it->second;
return nullptr;
}
void BOBCommandChannel::Accept () void BOBCommandChannel::Accept ()
{ {

7
BOB.h

@ -19,7 +19,9 @@ namespace client
const char BOB_COMMAND_ZAP[] = "zap"; const char BOB_COMMAND_ZAP[] = "zap";
const char BOB_COMMAND_QUIT[] = "quit"; const char BOB_COMMAND_QUIT[] = "quit";
const char BOB_COMMAND_START[] = "start"; const char BOB_COMMAND_START[] = "start";
const char BOB_COMMAND_SETNICK[] = "setnick"; const char BOB_COMMAND_STOP[] = "stop";
const char BOB_COMMAND_SETNICK[] = "setnick";
const char BOB_COMMAND_GETNICK[] = "getnick";
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";
@ -75,7 +77,9 @@ namespace client
void ZapCommandHandler (const char * operand, size_t len); void ZapCommandHandler (const char * operand, size_t len);
void QuitCommandHandler (const char * operand, size_t len); void QuitCommandHandler (const char * operand, size_t len);
void StartCommandHandler (const char * operand, size_t len); void StartCommandHandler (const char * operand, size_t len);
void StopCommandHandler (const char * operand, size_t len);
void SetNickCommandHandler (const char * operand, size_t len); void SetNickCommandHandler (const char * operand, size_t len);
void GetNickCommandHandler (const char * operand, size_t len);
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);
@ -117,6 +121,7 @@ namespace client
boost::asio::io_service& GetService () { return m_Service; }; boost::asio::io_service& GetService () { return m_Service; };
std::map<std::string, BOBCommandHandler>& GetCommandHandlers () { return m_CommandHandlers; }; std::map<std::string, BOBCommandHandler>& GetCommandHandlers () { return m_CommandHandlers; };
void AddTunnel (const std::string& name, I2PTunnel * tunnel); void AddTunnel (const std::string& name, I2PTunnel * tunnel);
I2PTunnel * FindTunnel (const std::string& name);
private: private:

Loading…
Cancel
Save