Browse Source

handle stop command

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

41
BOB.cpp

@ -266,6 +266,18 @@ namespace client @@ -266,6 +266,18 @@ namespace client
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)
{
LogPrint (eLogDebug, "BOB: setnick");
@ -275,6 +287,20 @@ namespace client @@ -275,6 +287,20 @@ namespace client
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)
{
LogPrint (eLogDebug, "BOB: newkeys");
@ -322,7 +348,9 @@ namespace client @@ -322,7 +348,9 @@ namespace client
m_CommandHandlers[BOB_COMMAND_ZAP] = &BOBCommandSession::ZapCommandHandler;
m_CommandHandlers[BOB_COMMAND_QUIT] = &BOBCommandSession::QuitCommandHandler;
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_GETNICK] = &BOBCommandSession::GetNickCommandHandler;
m_CommandHandlers[BOB_COMMAND_NEWKEYS] = &BOBCommandSession::NewkeysCommandHandler;
m_CommandHandlers[BOB_COMMAND_OUTHOST] = &BOBCommandSession::OuthostCommandHandler;
m_CommandHandlers[BOB_COMMAND_OUTPORT] = &BOBCommandSession::OutportCommandHandler;
@ -333,6 +361,8 @@ namespace client @@ -333,6 +361,8 @@ namespace client
BOBCommandChannel::~BOBCommandChannel ()
{
Stop ();
for (auto it: m_Tunnels)
delete it.second;
}
void BOBCommandChannel::Start ()
@ -345,8 +375,7 @@ namespace client @@ -345,8 +375,7 @@ namespace client
void BOBCommandChannel::Stop ()
{
for (auto it: m_Tunnels)
delete it.second;
m_Tunnels.clear ();
it.second->Stop ();
m_IsRunning = false;
m_Service.stop ();
if (m_Thread)
@ -377,6 +406,14 @@ namespace client @@ -377,6 +406,14 @@ namespace client
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 ()
{
auto newSession = std::make_shared<BOBCommandSession> (*this);

5
BOB.h

@ -19,7 +19,9 @@ namespace client @@ -19,7 +19,9 @@ namespace client
const char BOB_COMMAND_ZAP[] = "zap";
const char BOB_COMMAND_QUIT[] = "quit";
const char BOB_COMMAND_START[] = "start";
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_OUTHOST[] = "outhost";
const char BOB_COMMAND_OUTPORT[] = "outport";
@ -75,7 +77,9 @@ namespace client @@ -75,7 +77,9 @@ namespace client
void ZapCommandHandler (const char * operand, size_t len);
void QuitCommandHandler (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 GetNickCommandHandler (const char * operand, size_t len);
void NewkeysCommandHandler (const char * operand, size_t len);
void OuthostCommandHandler (const char * operand, size_t len);
void OutportCommandHandler (const char * operand, size_t len);
@ -117,6 +121,7 @@ namespace client @@ -117,6 +121,7 @@ namespace client
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);
private:

Loading…
Cancel
Save