From f0c4203f5a9ef0d55c497bddded409c060314799 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 4 Aug 2025 18:25:07 -0400 Subject: [PATCH] read bool param --- libi2pd/Destination.cpp | 33 +++++++++++++++++++++------------ libi2pd/Destination.h | 1 + 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/libi2pd/Destination.cpp b/libi2pd/Destination.cpp index 1493df6b..0be5890a 100644 --- a/libi2pd/Destination.cpp +++ b/libi2pd/Destination.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "Crypto.h" #include "ECIESX25519AEADRatchetSession.h" @@ -93,10 +94,8 @@ namespace client } it = params->find (I2CP_PARAM_DONT_PUBLISH_LEASESET); if (it != params->end ()) - { // override isPublic - m_IsPublic = (it->second != "true"); - } + m_IsPublic = GetBoolParamValue (it->second); it = params->find (I2CP_PARAM_LEASESET_TYPE); if (it != params->end ()) m_LeaseSetType = std::stoi(it->second); @@ -188,6 +187,24 @@ namespace client CleanUp (); // GarlicDestination } + bool LeaseSetDestination::GetBoolParamValue (std::string_view value) + { + bool ret = false; + if (value == "true") + ret = true; + else if (value == "false") + ret = false; + else + { + int v = 0; + auto res = std::from_chars(value.data(), value.data() + value.size(), v); + if (res.ec != std::errc()) + LogPrint (eLogError, "Destination: Unable to parse bool param value ", value, ": ", std::make_error_code (res.ec).message ()); + ret = v; + } + return ret; + } + bool LeaseSetDestination::Reconfigure(std::map params) { auto itr = params.find("i2cp.dontPublishLeaseSet"); @@ -1096,15 +1113,7 @@ namespace client } it = params->find (I2CP_PARAM_STREAMING_ANSWER_PINGS); if (it != params->end ()) - { - LogPrint (eLogDebug, "Destination: Reading parameter ", I2CP_PARAM_STREAMING_ANSWER_PINGS, " value ", it->second); - if (it->second == "true") - m_IsStreamingAnswerPings = true; - else if (it->second == "false") - m_IsStreamingAnswerPings = false; - else - m_IsStreamingAnswerPings = std::stoi (it->second); // 1 for true - } + m_IsStreamingAnswerPings = GetBoolParamValue (it->second); if (GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_ENCRYPTED_LEASESET2) { diff --git a/libi2pd/Destination.h b/libi2pd/Destination.h index 87859657..d387a900 100644 --- a/libi2pd/Destination.h +++ b/libi2pd/Destination.h @@ -174,6 +174,7 @@ namespace client int GetLeaseSetType () const { return m_LeaseSetType; }; void SetLeaseSetType (int leaseSetType) { m_LeaseSetType = leaseSetType; }; int GetAuthType () const { return m_AuthType; }; + static bool GetBoolParamValue (std::string_view value); virtual void CleanupDestination () {}; // additional clean up in derived classes virtual i2p::data::CryptoKeyType GetPreferredCryptoType () const = 0; // I2CP