|
|
@ -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,26 +481,43 @@ 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); |
|
|
|
m_Nickname = operand; |
|
|
|
if(*operand) |
|
|
|
std::string msg ("Nickname set to "); |
|
|
|
{ |
|
|
|
msg += m_Nickname; |
|
|
|
auto dest = m_Owner.FindDestination (operand); |
|
|
|
SendReplyOK (msg.c_str ()); |
|
|
|
if (!dest) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_Nickname = operand; |
|
|
|
|
|
|
|
std::string msg ("Nickname set to "); |
|
|
|
|
|
|
|
msg += m_Nickname; |
|
|
|
|
|
|
|
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); |
|
|
|
m_CurrentDestination = m_Owner.FindDestination (operand); |
|
|
|
if(*operand) |
|
|
|
if (m_CurrentDestination) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_Keys = m_CurrentDestination->GetKeys (); |
|
|
|
|
|
|
|
m_Nickname = operand; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (m_Nickname == operand) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
std::string msg ("Nickname set to "); |
|
|
|
m_CurrentDestination = m_Owner.FindDestination (operand); |
|
|
|
msg += m_Nickname; |
|
|
|
if (m_CurrentDestination) |
|
|
|
SendReplyOK (msg.c_str ()); |
|
|
|
{ |
|
|
|
|
|
|
|
m_Keys = m_CurrentDestination->GetKeys (); |
|
|
|
|
|
|
|
m_IsActive = m_CurrentDestination->IsRunning (); |
|
|
|
|
|
|
|
m_Nickname = operand; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (m_Nickname == operand) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::string msg ("Nickname set to "); |
|
|
|
|
|
|
|
msg += m_Nickname; |
|
|
|
|
|
|
|
SendReplyOK (msg.c_str ()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
SendReplyError ("no nickname has been set"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
SendReplyError ("no nickname has been set"); |
|
|
|
SendReplyError ("no nickname has been set"); |
|
|
@ -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,35 +581,55 @@ 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); |
|
|
|
m_OutHost = operand; |
|
|
|
if (*operand) |
|
|
|
SendReplyOK ("outhost set"); |
|
|
|
{ |
|
|
|
|
|
|
|
m_OutHost = operand; |
|
|
|
|
|
|
|
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); |
|
|
|
m_OutPort = std::stoi(operand); |
|
|
|
if (*operand) |
|
|
|
if (m_OutPort >= 0) |
|
|
|
{ |
|
|
|
SendReplyOK ("outbound port set"); |
|
|
|
m_OutPort = std::stoi(operand); |
|
|
|
|
|
|
|
if (m_OutPort >= 0) |
|
|
|
|
|
|
|
SendReplyOK ("outbound port set"); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
SendReplyError ("port out of range"); |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
SendReplyError ("port out of range"); |
|
|
|
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); |
|
|
|
m_InHost = operand; |
|
|
|
if (*operand) |
|
|
|
SendReplyOK ("inhost set"); |
|
|
|
{ |
|
|
|
|
|
|
|
m_InHost = operand; |
|
|
|
|
|
|
|
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); |
|
|
|
m_InPort = std::stoi(operand); |
|
|
|
if (*operand) |
|
|
|
if (m_InPort >= 0) |
|
|
|
{ |
|
|
|
SendReplyOK ("inbound port set"); |
|
|
|
m_InPort = std::stoi(operand); |
|
|
|
|
|
|
|
if (m_InPort >= 0) |
|
|
|
|
|
|
|
SendReplyOK ("inbound port set"); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
SendReplyError ("port out of range"); |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
SendReplyError ("port out of range"); |
|
|
|
SendReplyError ("empty inport"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void BOBCommandSession::QuietCommandHandler (const char * operand, size_t len) |
|
|
|
void BOBCommandSession::QuietCommandHandler (const char * operand, size_t len) |
|
|
@ -613,52 +652,62 @@ 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); |
|
|
|
auto addr = context.GetAddressBook ().GetAddress (operand); |
|
|
|
if (*operand) |
|
|
|
if (!addr) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
SendReplyError ("Address Not found"); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
auto localDestination = m_CurrentDestination ? m_CurrentDestination->GetLocalDestination () : i2p::client::context.GetSharedLocalDestination (); |
|
|
|
|
|
|
|
if (addr->IsIdentHash ()) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// we might have leaseset already
|
|
|
|
auto addr = context.GetAddressBook ().GetAddress (operand); |
|
|
|
auto leaseSet = localDestination->FindLeaseSet (addr->identHash); |
|
|
|
if (!addr) |
|
|
|
if (leaseSet) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
SendReplyOK (leaseSet->GetIdentity ()->ToBase64 ().c_str ()); |
|
|
|
SendReplyError ("Address Not found"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
auto localDestination = m_CurrentDestination ? m_CurrentDestination->GetLocalDestination () : i2p::client::context.GetSharedLocalDestination (); |
|
|
|
// trying to request
|
|
|
|
if (addr->IsIdentHash ()) |
|
|
|
auto s = shared_from_this (); |
|
|
|
|
|
|
|
auto requstCallback = [s](std::shared_ptr<i2p::data::LeaseSet> ls) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (ls) |
|
|
|
// we might have leaseset already
|
|
|
|
s->SendReplyOK (ls->GetIdentity ()->ToBase64 ().c_str ()); |
|
|
|
auto leaseSet = localDestination->FindLeaseSet (addr->identHash); |
|
|
|
else |
|
|
|
if (leaseSet) |
|
|
|
s->SendReplyError ("LeaseSet Not found"); |
|
|
|
{ |
|
|
|
}; |
|
|
|
SendReplyOK (leaseSet->GetIdentity ()->ToBase64 ().c_str ()); |
|
|
|
if (addr->IsIdentHash ()) |
|
|
|
return; |
|
|
|
localDestination->RequestDestination (addr->identHash, requstCallback); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// trying to request
|
|
|
|
|
|
|
|
auto s = shared_from_this (); |
|
|
|
|
|
|
|
auto requstCallback = [s](std::shared_ptr<i2p::data::LeaseSet> ls) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (ls) |
|
|
|
|
|
|
|
s->SendReplyOK (ls->GetIdentity ()->ToBase64 ().c_str ()); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
s->SendReplyError ("LeaseSet Not found"); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
if (addr->IsIdentHash ()) |
|
|
|
|
|
|
|
localDestination->RequestDestination (addr->identHash, requstCallback); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
localDestination->RequestDestinationWithEncryptedLeaseSet (addr->blindedPublicKey, requstCallback); |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
localDestination->RequestDestinationWithEncryptedLeaseSet (addr->blindedPublicKey, requstCallback); |
|
|
|
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); |
|
|
|
auto addr = context.GetAddressBook ().GetAddress (operand); |
|
|
|
if (*operand) |
|
|
|
if (!addr) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
SendReplyError ("Address Not found"); |
|
|
|
auto addr = context.GetAddressBook ().GetAddress (operand); |
|
|
|
return; |
|
|
|
if (!addr) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
SendReplyError ("Address Not found"); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
auto ls = i2p::data::netdb.FindLeaseSet (addr->identHash); |
|
|
|
|
|
|
|
if (ls) |
|
|
|
|
|
|
|
SendReplyOK (ls->GetIdentity ()->ToBase64 ().c_str ()); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
SendReplyError ("Local LeaseSet Not found"); |
|
|
|
} |
|
|
|
} |
|
|
|
auto ls = i2p::data::netdb.FindLeaseSet (addr->identHash); |
|
|
|
|
|
|
|
if (ls) |
|
|
|
|
|
|
|
SendReplyOK (ls->GetIdentity ()->ToBase64 ().c_str ()); |
|
|
|
|
|
|
|
else |
|
|
|
else |
|
|
|
SendReplyError ("Local LeaseSet Not found"); |
|
|
|
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:"; |
|
|
|