MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / BuildStatusLine

Method BuildStatusLine

libi2pd_client/BOB.cpp:387–431  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

385 }
386
387 void BOBCommandSession::BuildStatusLine(bool currentTunnel, std::shared_ptr<BOBDestination> dest, std::string &out)
388 {
389 // helper lambdas
390 const auto issetStr = [](const std::string &str) { return str.empty() ? "not_set" : str; }; // for inhost, outhost
391 const auto issetNum = [&issetStr](const int p) { return issetStr(p == 0 ? "" : std::to_string(p)); }; // for inport, outport
392 const auto destExists = [](const BOBDestination * const dest) { return dest != nullptr; };
393 const auto destReady = [](const BOBDestination * const dest) { return dest && dest->IsRunning(); };
394 const auto bool_str = [](const bool v) { return v ? "true" : "false"; }; // bool -> str
395 const auto getProxyType = [](const i2p::client::I2PService* proxy) -> std::string {
396 if (!proxy) return "NONE";
397 if (dynamic_cast<const i2p::proxy::SOCKSProxy*>(proxy)) return "SOCKS";
398 if (dynamic_cast<const i2p::proxy::HTTPProxy*>(proxy)) return "HTTPPROXY";
399 return "UNKNOWN";
400 };
401 const auto isProxyRunning = [](const i2p::client::I2PService* proxy) -> bool {
402 return proxy != nullptr;
403 };
404
405 // tunnel info
406 const std::string nickname = currentTunnel ? m_Nickname : dest->GetNickname();
407 const bool quiet = currentTunnel ? m_IsQuiet : dest->GetQuiet();
408 const std::string inhost = issetStr(currentTunnel ? m_InHost : dest->GetInHost());
409 const std::string outhost = issetStr(currentTunnel ? m_OutHost : dest->GetOutHost());
410 const std::string inport = issetNum(currentTunnel ? m_InPort : dest->GetInPort());
411 const std::string outport = issetNum(currentTunnel ? m_OutPort : dest->GetOutPort());
412 const bool keys = destExists(dest.get ()); // key must exist when destination is created
413 const bool starting = destExists(dest.get ()) && !destReady(dest.get ());
414 const bool running = destExists(dest.get ()) && destReady(dest.get ());
415 const bool stopping = false;
416
417 const i2p::client::I2PService* proxy = m_Owner.GetProxy(nickname);
418 const std::string proxyType = getProxyType(proxy);
419 const bool proxyStatus = isProxyRunning(proxy);
420
421 // build line
422 std::stringstream ss;
423 ss << "DATA "
424 << "NICKNAME: " << nickname << " " << "STARTING: " << bool_str(starting) << " "
425 << "RUNNING: " << bool_str(running) << " " << "STOPPING: " << bool_str(stopping) << " "
426 << "KEYS: " << bool_str(keys) << " " << "QUIET: " << bool_str(quiet) << " "
427 << "INPORT: " << inport << " " << "INHOST: " << inhost << " "
428 << "OUTPORT: " << outport << " " << "OUTHOST: " << outhost << " "
429 << "PROXYTYPE: "<< proxyType << " " << "PROXYSTART: " << bool_str(proxyStatus);
430 out = ss.str();
431 }
432
433 void BOBCommandSession::ZapCommandHandler (const char * operand, size_t len)
434 {

Callers

nothing calls this directly

Calls 6

to_stringFunction · 0.85
GetQuietMethod · 0.80
GetInPortMethod · 0.80
GetOutPortMethod · 0.80
GetProxyMethod · 0.80
IsRunningMethod · 0.45

Tested by

no test coverage detected