use Mapping for I2CP options
Some checks failed
Build Debian packages / bookworm (push) Has been cancelled
Build Debian packages / bullseye (push) Has been cancelled
Build Debian packages / trixie (push) Has been cancelled
Build on FreeBSD / with UPnP (push) Has been cancelled
Build on OSX / With USE_UPNP=no (push) Has been cancelled
Build on OSX / With USE_UPNP=yes (push) Has been cancelled
Build on Windows / clang-x86_64 (push) Has been cancelled
Build on Windows / i686 (push) Has been cancelled
Build on Windows / ucrt-x86_64 (push) Has been cancelled
Build on Windows / x86_64 (push) Has been cancelled
Build on Windows / CMake clang-x86_64 (push) Has been cancelled
Build on Windows / CMake i686 (push) Has been cancelled
Build on Windows / CMake ucrt-x86_64 (push) Has been cancelled
Build on Windows / CMake x86_64 (push) Has been cancelled
Build on Windows / XP (push) Has been cancelled
Build on Ubuntu / Make with USE_UPNP=no (push) Has been cancelled
Build on Ubuntu / Make with USE_UPNP=yes (push) Has been cancelled
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Has been cancelled
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Has been cancelled
Build containers / Building container for linux/amd64 (push) Has been cancelled
Build containers / Building container for linux/arm64 (push) Has been cancelled
Build containers / Building container for linux/arm/v7 (push) Has been cancelled
Build containers / Building container for linux/386 (push) Has been cancelled
Build containers / Pushing merged manifest (push) Has been cancelled

This commit is contained in:
orignal 2025-10-13 18:28:51 -04:00
parent 07263e77df
commit 675b82dfdd
2 changed files with 4 additions and 51 deletions

View file

@ -620,50 +620,6 @@ namespace client
m_IsSending = false; m_IsSending = false;
} }
std::string_view I2CPSession::ExtractString (const uint8_t * buf, size_t len) const
{
uint8_t l = buf[0];
if (l > len) l = len;
return { (const char *)(buf + 1), l };
}
size_t I2CPSession::PutString (uint8_t * buf, size_t len, std::string_view str)
{
auto l = str.length ();
if (l + 1 >= len) l = len - 1;
if (l > 255) l = 255; // 1 byte max
buf[0] = l;
memcpy (buf + 1, str.data (), l);
return l + 1;
}
void I2CPSession::ExtractMapping (const uint8_t * buf, size_t len, i2p::util::Mapping& mapping) const
// TODO: call FromBuffer
{
size_t offset = 0;
while (offset < len)
{
auto param = ExtractString (buf + offset, len - offset);
offset += param.length () + 1;
if (buf[offset] != '=')
{
LogPrint (eLogWarning, "I2CP: Unexpected character ", buf[offset], " instead '=' after ", param);
break;
}
offset++;
auto value = ExtractString (buf + offset, len - offset);
offset += value.length () + 1;
if (buf[offset] != ';')
{
LogPrint (eLogWarning, "I2CP: Unexpected character ", buf[offset], " instead ';' after ", value);
break;
}
offset++;
mapping.Insert (param, value);
}
}
void I2CPSession::GetDateMessageHandler (const uint8_t * buf, size_t len) void I2CPSession::GetDateMessageHandler (const uint8_t * buf, size_t len)
{ {
constexpr std::string_view version(I2P_VERSION); constexpr std::string_view version(I2P_VERSION);
@ -672,7 +628,7 @@ namespace client
auto ts = i2p::util::GetMillisecondsSinceEpoch (); auto ts = i2p::util::GetMillisecondsSinceEpoch ();
htobe64buf (payload.data(), ts); htobe64buf (payload.data(), ts);
// send our version back // send our version back
PutString (payload.data() + 8, payload.size() - 8, version); i2p::util::Mapping::WriteString (version, payload.data() + 8, payload.size() - 8);
SendI2CPMessage (I2CP_SET_DATE_MESSAGE, payload.data(), payload.size()); SendI2CPMessage (I2CP_SET_DATE_MESSAGE, payload.data(), payload.size());
} }
@ -702,7 +658,7 @@ namespace client
return; return;
} }
i2p::util::Mapping params; i2p::util::Mapping params;
ExtractMapping (buf + offset, optionsSize, params); params.FromBuffer (optionsSize, buf + offset, len - offset);
offset += optionsSize; // options offset += optionsSize; // options
if (params[I2CP_PARAM_MESSAGE_RELIABILITY] == "none") m_IsSendAccepted = false; if (params[I2CP_PARAM_MESSAGE_RELIABILITY] == "none") m_IsSendAccepted = false;
@ -768,7 +724,7 @@ namespace client
{ {
buf += sizeof(uint16_t); buf += sizeof(uint16_t);
i2p::util::Mapping opts; i2p::util::Mapping opts;
ExtractMapping(buf, optssize, opts); opts.FromBuffer (optssize, buf, optssize);
buf += optssize; buf += optssize;
//uint64_t date = bufbe64toh(buf); //uint64_t date = bufbe64toh(buf);
buf += sizeof(uint64_t); buf += sizeof(uint64_t);
@ -980,7 +936,7 @@ namespace client
break; break;
case 1: // address case 1: // address
{ {
auto name = ExtractString (buf + 11, len - 11); auto name = i2p::util::Mapping::ExtractString (buf + 11, len - 11);
auto addr = i2p::client::context.GetAddressBook ().GetAddress (name); auto addr = i2p::client::context.GetAddressBook ().GetAddress (name);
if (!addr || !addr->IsIdentHash ()) if (!addr || !addr->IsIdentHash ())
{ {

View file

@ -195,9 +195,6 @@ namespace client
void HandleI2CPMessageSent (const boost::system::error_code& ecode, std::size_t bytes_transferred); void HandleI2CPMessageSent (const boost::system::error_code& ecode, std::size_t bytes_transferred);
std::string_view ExtractString (const uint8_t * buf, size_t len) const;
size_t PutString (uint8_t * buf, size_t len, std::string_view str);
void ExtractMapping (const uint8_t * buf, size_t len, i2p::util::Mapping& mapping) const;
void SendSessionStatusMessage (I2CPSessionStatus status); void SendSessionStatusMessage (I2CPSessionStatus status);
void SendHostReplyMessage (uint32_t requestID, std::shared_ptr<const i2p::data::IdentityEx> identity); void SendHostReplyMessage (uint32_t requestID, std::shared_ptr<const i2p::data::IdentityEx> identity);