From cb8373e48710f922aaf764daab23e16e1e83c3eb Mon Sep 17 00:00:00 2001 From: rszibele Date: Tue, 25 Jun 2019 17:59:44 +0200 Subject: [PATCH 1/3] BOB: status response now correctly starts with "OK DATA". --- libi2pd_client/BOB.cpp | 11 ++++++----- libi2pd_client/BOB.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libi2pd_client/BOB.cpp b/libi2pd_client/BOB.cpp index c329d86b..828b8e8a 100644 --- a/libi2pd_client/BOB.cpp +++ b/libi2pd_client/BOB.cpp @@ -341,10 +341,10 @@ namespace client SendReplyOK(); } - void BOBCommandSession::SendData (const char * data) + void BOBCommandSession::SendRaw (const char * data) { std::ostream os(&m_SendBuffer); - os << "DATA " << data << std::endl; + os << data << std::endl; } void BOBCommandSession::BuildStatusLine(bool currentTunnel, BOBDestination *dest, std::string &out) @@ -370,7 +370,8 @@ namespace client // build line std::stringstream ss; - ss << "NICKNAME: " << nickname << " " << "STARTING: " << bool_str(starting) << " " + ss << "DATA " + << "NICKNAME: " << nickname << " " << "STARTING: " << bool_str(starting) << " " << "RUNNING: " << bool_str(running) << " " << "STOPPING: " << bool_str(stopping) << " " << "KEYS: " << bool_str(keys) << " " << "QUIET: " << bool_str(quiet) << " " << "INPORT: " << inport << " " << "INHOST: " << inhost << " " @@ -654,7 +655,7 @@ namespace client for (const auto& it: destinations) { BuildStatusLine(false, it.second, statusLine); - SendData (statusLine.c_str()); + SendRaw(statusLine.c_str()); if(m_Nickname.compare(it.second->GetNickname()) == 0) sentCurrent = true; } @@ -663,7 +664,7 @@ namespace client // add the current tunnel to the list BuildStatusLine(true, m_CurrentDestination, statusLine); LogPrint(eLogError, statusLine); - SendData(statusLine.c_str()); + SendRaw(statusLine.c_str()); } SendReplyOK ("Listing done"); } diff --git a/libi2pd_client/BOB.h b/libi2pd_client/BOB.h index d531a13d..8f1af185 100644 --- a/libi2pd_client/BOB.h +++ b/libi2pd_client/BOB.h @@ -213,7 +213,7 @@ namespace client void HandleSent (const boost::system::error_code& ecode, std::size_t bytes_transferred); void SendReplyOK (const char * msg = nullptr); void SendReplyError (const char * msg); - void SendData (const char * data); + void SendRaw (const char * data); void BuildStatusLine(bool currentTunnel, BOBDestination *destination, std::string &out); From a23e845c03275a77f57e81b5af989806dcd5ebf8 Mon Sep 17 00:00:00 2001 From: rszibele Date: Tue, 25 Jun 2019 19:04:27 +0200 Subject: [PATCH 2/3] BOB: improve comment and remove error log in list command --- libi2pd_client/BOB.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libi2pd_client/BOB.cpp b/libi2pd_client/BOB.cpp index 828b8e8a..b88eea81 100644 --- a/libi2pd_client/BOB.cpp +++ b/libi2pd_client/BOB.cpp @@ -661,9 +661,9 @@ namespace client } if(!sentCurrent && !m_Nickname.empty()) { - // add the current tunnel to the list + // add the current tunnel to the list. + // this is for the incomplete tunnel which has not been started yet. BuildStatusLine(true, m_CurrentDestination, statusLine); - LogPrint(eLogError, statusLine); SendRaw(statusLine.c_str()); } SendReplyOK ("Listing done"); From b75929497551b9186f207f90913612c19f4ee909 Mon Sep 17 00:00:00 2001 From: rszibele Date: Tue, 25 Jun 2019 19:18:40 +0200 Subject: [PATCH 3/3] BOB: fix status command. --- libi2pd_client/BOB.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/libi2pd_client/BOB.cpp b/libi2pd_client/BOB.cpp index b88eea81..aba090dc 100644 --- a/libi2pd_client/BOB.cpp +++ b/libi2pd_client/BOB.cpp @@ -691,21 +691,23 @@ namespace client void BOBCommandSession::StatusCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: status ", operand); + const std::string name = operand; std::string statusLine; - if (m_Nickname == operand) + + // always prefer destination + auto ptr = m_Owner.FindDestination(name); + if(ptr != nullptr) { - // check current tunnel - BuildStatusLine(true, nullptr, statusLine); + // tunnel destination exists + BuildStatusLine(false, ptr, statusLine); SendReplyOK(statusLine.c_str()); } else { - // check other - std::string name = operand; - auto ptr = m_Owner.FindDestination(name); - if(ptr != nullptr) + if(m_Nickname == name && !name.empty()) { - BuildStatusLine(false, ptr, statusLine); + // tunnel is incomplete / has not been started yet + BuildStatusLine(true, nullptr, statusLine); SendReplyOK(statusLine.c_str()); } else