1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-08-26 12:51:54 +00:00

read bool param

This commit is contained in:
orignal 2025-08-04 18:25:07 -04:00
parent 28996583e4
commit f0c4203f5a
2 changed files with 22 additions and 12 deletions

View File

@ -11,6 +11,7 @@
#include <string> #include <string>
#include <set> #include <set>
#include <vector> #include <vector>
#include <charconv>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include "Crypto.h" #include "Crypto.h"
#include "ECIESX25519AEADRatchetSession.h" #include "ECIESX25519AEADRatchetSession.h"
@ -93,10 +94,8 @@ namespace client
} }
it = params->find (I2CP_PARAM_DONT_PUBLISH_LEASESET); it = params->find (I2CP_PARAM_DONT_PUBLISH_LEASESET);
if (it != params->end ()) if (it != params->end ())
{
// override isPublic // override isPublic
m_IsPublic = (it->second != "true"); m_IsPublic = GetBoolParamValue (it->second);
}
it = params->find (I2CP_PARAM_LEASESET_TYPE); it = params->find (I2CP_PARAM_LEASESET_TYPE);
if (it != params->end ()) if (it != params->end ())
m_LeaseSetType = std::stoi(it->second); m_LeaseSetType = std::stoi(it->second);
@ -188,6 +187,24 @@ namespace client
CleanUp (); // GarlicDestination 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<std::string, std::string> params) bool LeaseSetDestination::Reconfigure(std::map<std::string, std::string> params)
{ {
auto itr = params.find("i2cp.dontPublishLeaseSet"); auto itr = params.find("i2cp.dontPublishLeaseSet");
@ -1096,15 +1113,7 @@ namespace client
} }
it = params->find (I2CP_PARAM_STREAMING_ANSWER_PINGS); it = params->find (I2CP_PARAM_STREAMING_ANSWER_PINGS);
if (it != params->end ()) if (it != params->end ())
{ m_IsStreamingAnswerPings = GetBoolParamValue (it->second);
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
}
if (GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_ENCRYPTED_LEASESET2) if (GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_ENCRYPTED_LEASESET2)
{ {

View File

@ -174,6 +174,7 @@ namespace client
int GetLeaseSetType () const { return m_LeaseSetType; }; int GetLeaseSetType () const { return m_LeaseSetType; };
void SetLeaseSetType (int leaseSetType) { m_LeaseSetType = leaseSetType; }; void SetLeaseSetType (int leaseSetType) { m_LeaseSetType = leaseSetType; };
int GetAuthType () const { return m_AuthType; }; int GetAuthType () const { return m_AuthType; };
static bool GetBoolParamValue (std::string_view value);
virtual void CleanupDestination () {}; // additional clean up in derived classes virtual void CleanupDestination () {}; // additional clean up in derived classes
virtual i2p::data::CryptoKeyType GetPreferredCryptoType () const = 0; virtual i2p::data::CryptoKeyType GetPreferredCryptoType () const = 0;
// I2CP // I2CP