Browse Source

more BOB error messages

pull/581/head
orignal 8 years ago
parent
commit
abcf030181
  1. 60
      BOB.cpp
  2. 2
      BOB.h

60
BOB.cpp

@ -203,7 +203,7 @@ namespace client
BOBCommandSession::BOBCommandSession (BOBCommandChannel& owner): BOBCommandSession::BOBCommandSession (BOBCommandChannel& owner):
m_Owner (owner), m_Socket (m_Owner.GetService ()), m_Owner (owner), m_Socket (m_Owner.GetService ()),
m_ReceiveBufferOffset (0), m_IsOpen (true), m_IsQuiet (false), m_ReceiveBufferOffset (0), m_IsOpen (true), m_IsQuiet (false), m_IsActive (false),
m_InPort (0), m_OutPort (0), m_CurrentDestination (nullptr) m_InPort (0), m_OutPort (0), m_CurrentDestination (nullptr)
{ {
} }
@ -354,6 +354,11 @@ namespace client
void BOBCommandSession::StartCommandHandler (const char * operand, size_t len) void BOBCommandSession::StartCommandHandler (const char * operand, size_t len)
{ {
LogPrint (eLogDebug, "BOB: start ", m_Nickname); LogPrint (eLogDebug, "BOB: start ", m_Nickname);
if (m_IsActive)
{
SendReplyError ("tunnel is active");
return;
}
if (!m_CurrentDestination) if (!m_CurrentDestination)
{ {
m_CurrentDestination = new BOBDestination (i2p::client::context.CreateNewLocalDestination (m_Keys, true, &m_Options)); m_CurrentDestination = new BOBDestination (i2p::client::context.CreateNewLocalDestination (m_Keys, true, &m_Options));
@ -364,19 +369,27 @@ namespace client
if (m_OutPort && !m_Address.empty ()) if (m_OutPort && !m_Address.empty ())
m_CurrentDestination->CreateOutboundTunnel (m_Address, m_OutPort, m_IsQuiet); m_CurrentDestination->CreateOutboundTunnel (m_Address, m_OutPort, m_IsQuiet);
m_CurrentDestination->Start (); m_CurrentDestination->Start ();
SendReplyOK ("tunnel starting"); SendReplyOK ("Tunnel starting");
m_IsActive = true;
} }
void BOBCommandSession::StopCommandHandler (const char * operand, size_t len) void BOBCommandSession::StopCommandHandler (const char * operand, size_t len)
{ {
LogPrint (eLogDebug, "BOB: stop ", m_Nickname);
if (!m_IsActive)
{
SendReplyError ("tunnel is inactive");
return;
}
auto dest = m_Owner.FindDestination (m_Nickname); auto dest = m_Owner.FindDestination (m_Nickname);
if (dest) if (dest)
{ {
dest->StopTunnels (); dest->StopTunnels ();
SendReplyOK ("tunnel stopping"); SendReplyOK ("Tunnel stopping");
} }
else else
SendReplyError ("tunnel not found"); SendReplyError ("tunnel not found");
m_IsActive = false;
} }
void BOBCommandSession::SetNickCommandHandler (const char * operand, size_t len) void BOBCommandSession::SetNickCommandHandler (const char * operand, size_t len)
@ -384,7 +397,7 @@ namespace client
LogPrint (eLogDebug, "BOB: setnick ", operand); LogPrint (eLogDebug, "BOB: setnick ", operand);
m_Nickname = operand; m_Nickname = operand;
std::string msg ("Nickname set to "); std::string msg ("Nickname set to ");
msg += operand; msg += m_Nickname;
SendReplyOK (msg.c_str ()); SendReplyOK (msg.c_str ());
} }
@ -397,11 +410,11 @@ namespace client
m_Keys = m_CurrentDestination->GetKeys (); m_Keys = m_CurrentDestination->GetKeys ();
m_Nickname = operand; m_Nickname = operand;
std::string msg ("Nickname set to "); std::string msg ("Nickname set to ");
msg += operand; msg += m_Nickname;
SendReplyOK (msg.c_str ()); SendReplyOK (msg.c_str ());
} }
else else
SendReplyError ("tunnel not found"); SendReplyError ("no nickname has been set");
} }
void BOBCommandSession::NewkeysCommandHandler (const char * operand, size_t len) void BOBCommandSession::NewkeysCommandHandler (const char * operand, size_t len)
@ -441,7 +454,10 @@ namespace client
{ {
LogPrint (eLogDebug, "BOB: outport ", operand); LogPrint (eLogDebug, "BOB: outport ", operand);
m_OutPort = boost::lexical_cast<int>(operand); m_OutPort = boost::lexical_cast<int>(operand);
SendReplyOK ("outbound port set"); if (m_OutPort >= 0)
SendReplyOK ("outbound port set");
else
SendReplyError ("port out of range");
} }
void BOBCommandSession::InhostCommandHandler (const char * operand, size_t len) void BOBCommandSession::InhostCommandHandler (const char * operand, size_t len)
@ -455,14 +471,27 @@ namespace client
{ {
LogPrint (eLogDebug, "BOB: inport ", operand); LogPrint (eLogDebug, "BOB: inport ", operand);
m_InPort = boost::lexical_cast<int>(operand); m_InPort = boost::lexical_cast<int>(operand);
SendReplyOK ("inbound port set"); if (m_InPort >= 0)
SendReplyOK ("inbound port set");
else
SendReplyError ("port out of range");
} }
void BOBCommandSession::QuietCommandHandler (const char * operand, size_t len) void BOBCommandSession::QuietCommandHandler (const char * operand, size_t len)
{ {
LogPrint (eLogDebug, "BOB: quiet"); LogPrint (eLogDebug, "BOB: quiet");
m_IsQuiet = true; if (m_Nickname.length () > 0)
SendReplyOK ("quiet"); {
if (!m_IsActive)
{
m_IsQuiet = true;
SendReplyOK ("Quiet set");
}
else
SendReplyError ("tunnel is active");
}
else
SendReplyError ("no nickname has been set");
} }
void BOBCommandSession::LookupCommandHandler (const char * operand, size_t len) void BOBCommandSession::LookupCommandHandler (const char * operand, size_t len)
@ -497,6 +526,7 @@ namespace client
{ {
LogPrint (eLogDebug, "BOB: clear"); LogPrint (eLogDebug, "BOB: clear");
m_Owner.DeleteDestination (m_Nickname); m_Owner.DeleteDestination (m_Nickname);
m_Nickname = "";
SendReplyOK ("cleared"); SendReplyOK ("cleared");
} }
@ -515,10 +545,14 @@ namespace client
const char * value = strchr (operand, '='); const char * value = strchr (operand, '=');
if (value) if (value)
{ {
std::string msg ("option ");
*(const_cast<char *>(value)) = 0; *(const_cast<char *>(value)) = 0;
m_Options[operand] = value + 1; m_Options[operand] = value + 1;
msg += operand;
*(const_cast<char *>(value)) = '='; *(const_cast<char *>(value)) = '=';
SendReplyOK ("option"); msg += " set to ";
msg += value;
SendReplyOK (msg.c_str ());
} }
else else
SendReplyError ("malformed"); SendReplyError ("malformed");
@ -527,10 +561,10 @@ namespace client
void BOBCommandSession::StatusCommandHandler (const char * operand, size_t len) void BOBCommandSession::StatusCommandHandler (const char * operand, size_t len)
{ {
LogPrint (eLogDebug, "BOB: status ", operand); LogPrint (eLogDebug, "BOB: status ", operand);
if (operand == m_Nickname) if (m_Nickname == operand)
{ {
std::stringstream s; std::stringstream s;
s << "DATA"; s << " NICKNAME:"; s << operand; s << "DATA"; s << " NICKNAME:"; s << m_Nickname;
if (m_CurrentDestination->GetLocalDestination ()->IsReady ()) if (m_CurrentDestination->GetLocalDestination ()->IsReady ())
s << " STARTING:false RUNNING:true STOPPING:false"; s << " STARTING:false RUNNING:true STOPPING:false";
else else

2
BOB.h

@ -188,7 +188,7 @@ namespace client
boost::asio::ip::tcp::socket m_Socket; boost::asio::ip::tcp::socket m_Socket;
char m_ReceiveBuffer[BOB_COMMAND_BUFFER_SIZE + 1], m_SendBuffer[BOB_COMMAND_BUFFER_SIZE + 1]; char m_ReceiveBuffer[BOB_COMMAND_BUFFER_SIZE + 1], m_SendBuffer[BOB_COMMAND_BUFFER_SIZE + 1];
size_t m_ReceiveBufferOffset; size_t m_ReceiveBufferOffset;
bool m_IsOpen, m_IsQuiet; bool m_IsOpen, m_IsQuiet, m_IsActive;
std::string m_Nickname, m_Address; std::string m_Nickname, m_Address;
int m_InPort, m_OutPort; int m_InPort, m_OutPort;
i2p::data::PrivateKeys m_Keys; i2p::data::PrivateKeys m_Keys;

Loading…
Cancel
Save