always pass RouterInfo param values as string_view
Some checks are pending
Build Debian packages / bookworm (push) Waiting to run
Build Debian packages / bullseye (push) Waiting to run
Build Debian packages / buster (push) Waiting to run
Build on FreeBSD / with UPnP (push) Waiting to run
Build on OSX / With USE_UPNP=no (push) Waiting to run
Build on OSX / With USE_UPNP=yes (push) Waiting to run
Build on Windows / x86_64 (push) Waiting to run
Build on Windows / clang-x86_64 (push) Waiting to run
Build on Windows / i686 (push) Waiting to run
Build on Windows / ucrt-x86_64 (push) Waiting to run
Build on Windows / CMake clang-x86_64 (push) Waiting to run
Build on Windows / CMake i686 (push) Waiting to run
Build on Windows / CMake ucrt-x86_64 (push) Waiting to run
Build on Windows / CMake x86_64 (push) Waiting to run
Build on Windows / XP (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=no (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=yes (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Waiting to run
Build containers / Building container for linux/arm64 (push) Waiting to run
Build containers / Building container for linux/arm/v7 (push) Waiting to run
Build containers / Building container for linux/386 (push) Waiting to run
Build containers / Pushing merged manifest (push) Blocked by required conditions
Build containers / Building container for linux/amd64 (push) Waiting to run

This commit is contained in:
orignal 2025-02-19 11:08:47 -05:00
parent 70f99ccc21
commit d09367d686
4 changed files with 21 additions and 33 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2024, The PurpleI2P Project
* Copyright (c) 2013-2025, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
@ -90,10 +90,10 @@ namespace data
}
bool Families::VerifyFamily (const std::string& family, const IdentHash& ident,
const char * signature, const char * key) const
std::string_view signature, const char * key) const
{
uint8_t buf[100], signatureBuf[64];
size_t len = family.length (), signatureLen = strlen (signature);
size_t len = family.length ();
if (len + 32 > 100)
{
LogPrint (eLogError, "Family: ", family, " is too long");
@ -105,7 +105,7 @@ namespace data
memcpy (buf, family.c_str (), len);
memcpy (buf + len, (const uint8_t *)ident, 32);
len += 32;
auto signatureBufLen = Base64ToByteStream (signature, signatureLen, signatureBuf, 64);
auto signatureBufLen = Base64ToByteStream (signature.data (), signature.length (), signatureBuf, 64);
if (signatureBufLen)
{
EVP_MD_CTX * ctx = EVP_MD_CTX_create ();

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2024, The PurpleI2P Project
* Copyright (c) 2013-2025, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
@ -11,6 +11,7 @@
#include <map>
#include <string>
#include <string_view>
#include <memory>
#include <openssl/evp.h>
#include "Identity.h"
@ -28,7 +29,7 @@ namespace data
~Families ();
void LoadCertificates ();
bool VerifyFamily (const std::string& family, const IdentHash& ident,
const char * signature, const char * key = nullptr) const;
std::string_view signature, const char * key = nullptr) const;
FamilyID GetFamilyID (const std::string& family) const;
private:

View file

@ -213,6 +213,7 @@ namespace data
uint8_t numAddresses = buf[offset]; offset++;
for (int i = 0; i < numAddresses; i++)
{
if (offset + 9 > len) return false; // 1 byte cost + 8 bytes date
uint8_t supportedTransports = 0;
auto address = NewAddress ();
offset++; // cost, ignore
@ -231,6 +232,7 @@ namespace data
address->transportStyle = eTransportUnknown;
address->caps = 0;
address->port = 0;
if (offset + 2 > len) return false;
uint16_t size = bufbe16toh (buf + offset); offset += 2; // size
if (offset + size >= len) return false;
if (address->transportStyle == eTransportUnknown)
@ -434,10 +436,11 @@ namespace data
boost::atomic_store (&m_Addresses, addresses);
#endif
// read peers
if (offset + 1 > len) return false;
uint8_t numPeers = buf[offset]; offset++; // num peers
offset += numPeers*32; // TODO: read peers
if (offset >= len) return false;
// read properties
if (offset + 2 > len) return false;
m_Version = 0;
bool isNetId = false;
std::string family;
@ -499,7 +502,7 @@ namespace data
}
else if (key == ROUTER_INFO_PROPERTY_FAMILY_SIG)
{
if (netdb.GetFamilies ().VerifyFamily (family, GetIdentHash (), std::string(value).c_str ())) // TODO
if (netdb.GetFamilies ().VerifyFamily (family, GetIdentHash (), value)) // TODO
m_FamilyID = netdb.GetFamilies ().GetFamilyID (family);
else
{
@ -520,12 +523,11 @@ namespace data
return m_FamilyID == famid;
}
void RouterInfo::ExtractCaps (const char * value)
void RouterInfo::ExtractCaps (std::string_view value)
{
const char * cap = value;
while (*cap)
for (auto cap: value)
{
switch (*cap)
switch (cap)
{
case CAPS_FLAG_FLOODFILL:
m_Caps |= Caps::eFloodfill;
@ -534,16 +536,16 @@ namespace data
case CAPS_FLAG_LOW_BANDWIDTH2:
case CAPS_FLAG_LOW_BANDWIDTH3:
case CAPS_FLAG_LOW_BANDWIDTH4:
m_BandwidthCap = *cap;
m_BandwidthCap = cap;
break;
case CAPS_FLAG_HIGH_BANDWIDTH:
m_Caps |= Caps::eHighBandwidth;
m_BandwidthCap = *cap;
m_BandwidthCap = cap;
break;
case CAPS_FLAG_EXTRA_BANDWIDTH1:
case CAPS_FLAG_EXTRA_BANDWIDTH2:
m_Caps |= Caps::eExtraBandwidth | Caps::eHighBandwidth;
m_BandwidthCap = *cap;
m_BandwidthCap = cap;
break;
case CAPS_FLAG_HIDDEN:
m_Caps |= Caps::eHidden;
@ -565,22 +567,15 @@ namespace data
break;
default: ;
}
cap++;
}
}
void RouterInfo::ExtractCaps (std::string_view value)
{
ExtractCaps (std::string (value).c_str ()); // TODO
}
uint8_t RouterInfo::ExtractAddressCaps (const char * value) const
uint8_t RouterInfo::ExtractAddressCaps (std::string_view value) const
{
uint8_t caps = 0;
const char * cap = value;
while (*cap)
for (auto cap: value)
{
switch (*cap)
switch (cap)
{
case CAPS_FLAG_V4:
caps |= AddressCaps::eV4;
@ -596,16 +591,10 @@ namespace data
break;
default: ;
}
cap++;
}
return caps;
}
uint8_t RouterInfo::ExtractAddressCaps (std::string_view value) const
{
return ExtractAddressCaps (std::string (value).c_str ()); // TODO:
}
void RouterInfo::UpdateIntroducers (std::shared_ptr<Address> address, uint64_t ts)
{
if (!address || !address->ssu) return;

View file

@ -339,9 +339,7 @@ namespace data
void ReadFromBuffer (bool verifySignature);
std::string_view ExtractString (const uint8_t * buf, size_t len) const;
std::tuple<std::string_view, std::string_view, size_t> ExtractParam (const uint8_t * buf, size_t len) const;
void ExtractCaps (const char * value);
void ExtractCaps (std::string_view value);
uint8_t ExtractAddressCaps (const char * value) const;
uint8_t ExtractAddressCaps (std::string_view value) const;
void UpdateIntroducers (std::shared_ptr<Address> address, uint64_t ts);
template<typename Filter>