mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-10 11:28:27 +01:00
[BOB] require commands options, fix usage of existent nick and status
Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
parent
17892238a9
commit
605ccf3e02
2 changed files with 116 additions and 65 deletions
|
@ -168,7 +168,7 @@ namespace client
|
||||||
m_LocalDestination (localDestination),
|
m_LocalDestination (localDestination),
|
||||||
m_OutboundTunnel (nullptr), m_InboundTunnel (nullptr),
|
m_OutboundTunnel (nullptr), m_InboundTunnel (nullptr),
|
||||||
m_Nickname(nickname), m_InHost(inhost), m_OutHost(outhost),
|
m_Nickname(nickname), m_InHost(inhost), m_OutHost(outhost),
|
||||||
m_InPort(inport), m_OutPort(outport), m_Quiet(quiet)
|
m_InPort(inport), m_OutPort(outport), m_Quiet(quiet), m_IsRunning(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,6 +183,7 @@ namespace client
|
||||||
{
|
{
|
||||||
if (m_OutboundTunnel) m_OutboundTunnel->Start ();
|
if (m_OutboundTunnel) m_OutboundTunnel->Start ();
|
||||||
if (m_InboundTunnel) m_InboundTunnel->Start ();
|
if (m_InboundTunnel) m_InboundTunnel->Start ();
|
||||||
|
m_IsRunning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BOBDestination::Stop ()
|
void BOBDestination::Stop ()
|
||||||
|
@ -193,6 +194,7 @@ namespace client
|
||||||
|
|
||||||
void BOBDestination::StopTunnels ()
|
void BOBDestination::StopTunnels ()
|
||||||
{
|
{
|
||||||
|
m_IsRunning = false;
|
||||||
if (m_OutboundTunnel)
|
if (m_OutboundTunnel)
|
||||||
{
|
{
|
||||||
m_OutboundTunnel->Stop ();
|
m_OutboundTunnel->Stop ();
|
||||||
|
@ -361,7 +363,7 @@ namespace client
|
||||||
const auto issetStr = [](const std::string &str) { return str.empty() ? "not_set" : str; }; // for inhost, outhost
|
const auto issetStr = [](const std::string &str) { return str.empty() ? "not_set" : str; }; // for inhost, outhost
|
||||||
const auto issetNum = [&issetStr](const int p) { return issetStr(p == 0 ? "" : std::to_string(p)); }; // for inport, outport
|
const auto issetNum = [&issetStr](const int p) { return issetStr(p == 0 ? "" : std::to_string(p)); }; // for inport, outport
|
||||||
const auto destExists = [](const BOBDestination * const dest) { return dest != nullptr; };
|
const auto destExists = [](const BOBDestination * const dest) { return dest != nullptr; };
|
||||||
const auto destReady = [](const BOBDestination * const dest) { return dest->GetLocalDestination()->IsReady(); };
|
const auto destReady = [](const BOBDestination * const dest) { return dest->IsRunning(); };
|
||||||
const auto bool_str = [](const bool v) { return v ? "true" : "false"; }; // bool -> str
|
const auto bool_str = [](const bool v) { return v ? "true" : "false"; }; // bool -> str
|
||||||
|
|
||||||
// tunnel info
|
// tunnel info
|
||||||
|
@ -479,19 +481,33 @@ namespace client
|
||||||
void BOBCommandSession::SetNickCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::SetNickCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "BOB: setnick ", operand);
|
LogPrint (eLogDebug, "BOB: setnick ", operand);
|
||||||
|
if(*operand)
|
||||||
|
{
|
||||||
|
auto dest = m_Owner.FindDestination (operand);
|
||||||
|
if (!dest)
|
||||||
|
{
|
||||||
m_Nickname = operand;
|
m_Nickname = operand;
|
||||||
std::string msg ("Nickname set to ");
|
std::string msg ("Nickname set to ");
|
||||||
msg += m_Nickname;
|
msg += m_Nickname;
|
||||||
SendReplyOK (msg.c_str ());
|
SendReplyOK (msg.c_str ());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
SendReplyError ("tunnel is active");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SendReplyError ("no nickname has been set");
|
||||||
|
}
|
||||||
|
|
||||||
void BOBCommandSession::GetNickCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::GetNickCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "BOB: getnick ", operand);
|
LogPrint (eLogDebug, "BOB: getnick ", operand);
|
||||||
|
if(*operand)
|
||||||
|
{
|
||||||
m_CurrentDestination = m_Owner.FindDestination (operand);
|
m_CurrentDestination = m_Owner.FindDestination (operand);
|
||||||
if (m_CurrentDestination)
|
if (m_CurrentDestination)
|
||||||
{
|
{
|
||||||
m_Keys = m_CurrentDestination->GetKeys ();
|
m_Keys = m_CurrentDestination->GetKeys ();
|
||||||
|
m_IsActive = m_CurrentDestination->IsRunning ();
|
||||||
m_Nickname = operand;
|
m_Nickname = operand;
|
||||||
}
|
}
|
||||||
if (m_Nickname == operand)
|
if (m_Nickname == operand)
|
||||||
|
@ -503,6 +519,9 @@ namespace client
|
||||||
else
|
else
|
||||||
SendReplyError ("no nickname has been set");
|
SendReplyError ("no nickname has been set");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
SendReplyError ("no nickname has been set");
|
||||||
|
}
|
||||||
|
|
||||||
void BOBCommandSession::NewkeysCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::NewkeysCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
|
@ -535,7 +554,7 @@ namespace client
|
||||||
void BOBCommandSession::SetkeysCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::SetkeysCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "BOB: setkeys ", operand);
|
LogPrint (eLogDebug, "BOB: setkeys ", operand);
|
||||||
if (m_Keys.FromBase64 (operand))
|
if (*operand && m_Keys.FromBase64 (operand))
|
||||||
SendReplyOK (m_Keys.GetPublic ()->ToBase64 ().c_str ());
|
SendReplyOK (m_Keys.GetPublic ()->ToBase64 ().c_str ());
|
||||||
else
|
else
|
||||||
SendReplyError ("invalid keys");
|
SendReplyError ("invalid keys");
|
||||||
|
@ -562,36 +581,56 @@ namespace client
|
||||||
void BOBCommandSession::OuthostCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::OuthostCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "BOB: outhost ", operand);
|
LogPrint (eLogDebug, "BOB: outhost ", operand);
|
||||||
|
if (*operand)
|
||||||
|
{
|
||||||
m_OutHost = operand;
|
m_OutHost = operand;
|
||||||
SendReplyOK ("outhost set");
|
SendReplyOK ("outhost set");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
SendReplyError ("empty outhost");
|
||||||
|
}
|
||||||
|
|
||||||
void BOBCommandSession::OutportCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::OutportCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "BOB: outport ", operand);
|
LogPrint (eLogDebug, "BOB: outport ", operand);
|
||||||
|
if (*operand)
|
||||||
|
{
|
||||||
m_OutPort = std::stoi(operand);
|
m_OutPort = std::stoi(operand);
|
||||||
if (m_OutPort >= 0)
|
if (m_OutPort >= 0)
|
||||||
SendReplyOK ("outbound port set");
|
SendReplyOK ("outbound port set");
|
||||||
else
|
else
|
||||||
SendReplyError ("port out of range");
|
SendReplyError ("port out of range");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
SendReplyError ("empty outport");
|
||||||
|
}
|
||||||
|
|
||||||
void BOBCommandSession::InhostCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::InhostCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "BOB: inhost ", operand);
|
LogPrint (eLogDebug, "BOB: inhost ", operand);
|
||||||
|
if (*operand)
|
||||||
|
{
|
||||||
m_InHost = operand;
|
m_InHost = operand;
|
||||||
SendReplyOK ("inhost set");
|
SendReplyOK ("inhost set");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
SendReplyError ("empty inhost");
|
||||||
|
}
|
||||||
|
|
||||||
void BOBCommandSession::InportCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::InportCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "BOB: inport ", operand);
|
LogPrint (eLogDebug, "BOB: inport ", operand);
|
||||||
|
if (*operand)
|
||||||
|
{
|
||||||
m_InPort = std::stoi(operand);
|
m_InPort = std::stoi(operand);
|
||||||
if (m_InPort >= 0)
|
if (m_InPort >= 0)
|
||||||
SendReplyOK ("inbound port set");
|
SendReplyOK ("inbound port set");
|
||||||
else
|
else
|
||||||
SendReplyError ("port out of range");
|
SendReplyError ("port out of range");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
SendReplyError ("empty inport");
|
||||||
|
}
|
||||||
|
|
||||||
void BOBCommandSession::QuietCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::QuietCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
|
@ -613,6 +652,8 @@ namespace client
|
||||||
void BOBCommandSession::LookupCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::LookupCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "BOB: lookup ", operand);
|
LogPrint (eLogDebug, "BOB: lookup ", operand);
|
||||||
|
if (*operand)
|
||||||
|
{
|
||||||
auto addr = context.GetAddressBook ().GetAddress (operand);
|
auto addr = context.GetAddressBook ().GetAddress (operand);
|
||||||
if (!addr)
|
if (!addr)
|
||||||
{
|
{
|
||||||
|
@ -644,10 +685,15 @@ namespace client
|
||||||
else
|
else
|
||||||
localDestination->RequestDestinationWithEncryptedLeaseSet (addr->blindedPublicKey, requstCallback);
|
localDestination->RequestDestinationWithEncryptedLeaseSet (addr->blindedPublicKey, requstCallback);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
SendReplyError ("empty lookup address");
|
||||||
|
}
|
||||||
|
|
||||||
void BOBCommandSession::LookupLocalCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::LookupLocalCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "BOB: lookup local ", operand);
|
LogPrint (eLogDebug, "BOB: lookup local ", operand);
|
||||||
|
if (*operand)
|
||||||
|
{
|
||||||
auto addr = context.GetAddressBook ().GetAddress (operand);
|
auto addr = context.GetAddressBook ().GetAddress (operand);
|
||||||
if (!addr)
|
if (!addr)
|
||||||
{
|
{
|
||||||
|
@ -660,6 +706,9 @@ namespace client
|
||||||
else
|
else
|
||||||
SendReplyError ("Local LeaseSet Not found");
|
SendReplyError ("Local LeaseSet Not found");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
SendReplyError ("empty lookup address");
|
||||||
|
}
|
||||||
|
|
||||||
void BOBCommandSession::ClearCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::ClearCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
|
@ -718,11 +767,11 @@ namespace client
|
||||||
std::string statusLine;
|
std::string statusLine;
|
||||||
|
|
||||||
// always prefer destination
|
// always prefer destination
|
||||||
auto ptr = m_Owner.FindDestination(name);
|
auto dest = m_Owner.FindDestination(name);
|
||||||
if(ptr != nullptr)
|
if(dest)
|
||||||
{
|
{
|
||||||
// tunnel destination exists
|
// tunnel destination exists
|
||||||
BuildStatusLine(false, ptr, statusLine);
|
BuildStatusLine(false, dest, statusLine);
|
||||||
SendReplyOK(statusLine.c_str());
|
SendReplyOK(statusLine.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -742,7 +791,7 @@ namespace client
|
||||||
void BOBCommandSession::HelpCommandHandler (const char * operand, size_t len)
|
void BOBCommandSession::HelpCommandHandler (const char * operand, size_t len)
|
||||||
{
|
{
|
||||||
auto helpStrings = m_Owner.GetHelpStrings();
|
auto helpStrings = m_Owner.GetHelpStrings();
|
||||||
if(len == 0)
|
if(!*operand)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "COMMANDS:";
|
ss << "COMMANDS:";
|
||||||
|
|
|
@ -163,6 +163,7 @@ namespace client
|
||||||
int GetInPort() const { return m_InPort; }
|
int GetInPort() const { return m_InPort; }
|
||||||
int GetOutPort() const { return m_OutPort; }
|
int GetOutPort() const { return m_OutPort; }
|
||||||
bool GetQuiet() const { return m_Quiet; }
|
bool GetQuiet() const { return m_Quiet; }
|
||||||
|
bool IsRunning() const { return m_IsRunning; }
|
||||||
const i2p::data::PrivateKeys& GetKeys () const { return m_LocalDestination->GetPrivateKeys (); };
|
const i2p::data::PrivateKeys& GetKeys () const { return m_LocalDestination->GetPrivateKeys (); };
|
||||||
std::shared_ptr<ClientDestination> GetLocalDestination () const { return m_LocalDestination; };
|
std::shared_ptr<ClientDestination> GetLocalDestination () const { return m_LocalDestination; };
|
||||||
|
|
||||||
|
@ -176,6 +177,7 @@ namespace client
|
||||||
std::string m_InHost, m_OutHost;
|
std::string m_InHost, m_OutHost;
|
||||||
int m_InPort, m_OutPort;
|
int m_InPort, m_OutPort;
|
||||||
bool m_Quiet;
|
bool m_Quiet;
|
||||||
|
bool m_IsRunning;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BOBCommandChannel;
|
class BOBCommandChannel;
|
||||||
|
|
Loading…
Add table
Reference in a new issue