Browse Source

BOB 'clear' command

pull/115/head
orignal 10 years ago
parent
commit
8f12881162
  1. 66
      BOB.cpp
  2. 3
      BOB.h

66
BOB.cpp

@ -198,24 +198,42 @@ namespace client @@ -198,24 +198,42 @@ namespace client
void BOBDestination::Stop ()
{
if (m_OutboundTunnel) m_OutboundTunnel->Stop ();
if (m_InboundTunnel) m_InboundTunnel->Stop ();
StopTunnels ();
m_LocalDestination.Stop ();
}
void BOBDestination::StopTunnels ()
{
if (m_OutboundTunnel)
{
m_OutboundTunnel->Stop ();
delete m_OutboundTunnel;
m_OutboundTunnel = nullptr;
}
if (m_InboundTunnel)
{
m_InboundTunnel->Stop ();
delete m_InboundTunnel;
m_InboundTunnel = nullptr;
}
}
void BOBDestination::CreateInboundTunnel (int port)
{
m_InboundTunnel = new BOBI2PInboundTunnel (m_Service, port, &m_LocalDestination);
if (!m_InboundTunnel)
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);
if (!m_OutboundTunnel)
m_OutboundTunnel = new BOBI2POutboundTunnel (m_Service, address, port, &m_LocalDestination, quiet);
}
BOBCommandSession::BOBCommandSession (BOBCommandChannel& owner):
m_Owner (owner), m_Socket (m_Owner.GetService ()), m_ReceiveBufferOffset (0),
m_IsOpen (true), m_IsQuiet (false), m_InPort (0), m_OutPort (0)
m_IsOpen (true), m_IsQuiet (false), m_InPort (0), m_OutPort (0),
m_CurrentDestination (nullptr)
{
}
@ -365,14 +383,17 @@ namespace client @@ -365,14 +383,17 @@ namespace client
void BOBCommandSession::StartCommandHandler (const char * operand, size_t len)
{
LogPrint (eLogDebug, "BOB: start ", m_Nickname);
BOBDestination * dest = new BOBDestination (m_Owner.GetService (),
*context.CreateNewLocalDestination (m_Keys, true, &m_Options));
if (!m_CurrentDestination)
{
m_CurrentDestination = new BOBDestination (m_Owner.GetService (),
*context.CreateNewLocalDestination (m_Keys, true, &m_Options));
m_Owner.AddDestination (m_Nickname, m_CurrentDestination);
}
if (m_InPort)
dest->CreateInboundTunnel (m_InPort);
m_CurrentDestination->CreateInboundTunnel (m_InPort);
if (m_OutPort && !m_Address.empty ())
dest->CreateOutboundTunnel (m_Address, m_OutPort, m_IsQuiet);
m_Owner.AddDestination (m_Nickname, dest);
dest->Start ();
m_CurrentDestination->CreateOutboundTunnel (m_Address, m_OutPort, m_IsQuiet);
m_CurrentDestination->Start ();
SendReplyOK ("tunnel starting");
}
@ -381,7 +402,7 @@ namespace client @@ -381,7 +402,7 @@ namespace client
auto dest = m_Owner.FindDestination (m_Nickname);
if (dest)
{
dest->Stop ();
dest->StopTunnels ();
SendReplyOK ("tunnel stopping");
}
else
@ -400,10 +421,10 @@ namespace client @@ -400,10 +421,10 @@ namespace client
void BOBCommandSession::GetNickCommandHandler (const char * operand, size_t len)
{
LogPrint (eLogDebug, "BOB: getnick ", operand);
auto dest = m_Owner.FindDestination (operand);
if (dest)
m_CurrentDestination = m_Owner.FindDestination (operand);
if (m_CurrentDestination)
{
m_Keys = dest->GetKeys ();
m_Keys = m_CurrentDestination->GetKeys ();
m_Nickname = operand;
std::string msg ("Nickname set to ");
msg += operand;
@ -489,7 +510,7 @@ namespace client @@ -489,7 +510,7 @@ namespace client
void BOBCommandSession::ClearCommandHandler (const char * operand, size_t len)
{
LogPrint (eLogDebug, "BOB: clear");
// TODO
m_Owner.DeleteDestination (m_Nickname);
SendReplyOK ("cleared");
}
@ -570,7 +591,7 @@ namespace client @@ -570,7 +591,7 @@ namespace client
m_Thread = nullptr;
}
}
void BOBCommandChannel::Run ()
{
while (m_IsRunning)
@ -591,6 +612,17 @@ namespace client @@ -591,6 +612,17 @@ namespace client
m_Destinations[name] = dest;
}
void BOBCommandChannel::DeleteDestination (const std::string& name)
{
auto it = m_Destinations.find (name);
if (it != m_Destinations.end ())
{
it->second->Stop ();
delete it->second;
m_Destinations.erase (it);
}
}
BOBDestination * BOBCommandChannel::FindDestination (const std::string& name)
{
auto it = m_Destinations.find (name);

3
BOB.h

@ -124,6 +124,7 @@ namespace client @@ -124,6 +124,7 @@ namespace client
void Start ();
void Stop ();
void StopTunnels ();
void CreateInboundTunnel (int port);
void CreateOutboundTunnel (const std::string& address, int port, bool quiet);
const i2p::data::PrivateKeys& GetKeys () const { return m_LocalDestination.GetPrivateKeys (); };
@ -191,6 +192,7 @@ namespace client @@ -191,6 +192,7 @@ namespace client
int m_InPort, m_OutPort;
i2p::data::PrivateKeys m_Keys;
std::map<std::string, std::string> m_Options;
BOBDestination * m_CurrentDestination;
};
typedef void (BOBCommandSession::*BOBCommandHandler)(const char * operand, size_t len);
@ -206,6 +208,7 @@ namespace client @@ -206,6 +208,7 @@ namespace client
boost::asio::io_service& GetService () { return m_Service; };
void AddDestination (const std::string& name, BOBDestination * dest);
void DeleteDestination (const std::string& name);
BOBDestination * FindDestination (const std::string& name);
private:

Loading…
Cancel
Save