send options in Datagram3
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-09-30 19:01:12 -04:00
parent dc9cdf941d
commit cd841f7219
4 changed files with 35 additions and 9 deletions

View file

@ -56,7 +56,8 @@ namespace datagram
return ObtainSession(ident);
}
void DatagramDestination::SendDatagram (std::shared_ptr<DatagramSession> session, const uint8_t * payload, size_t len, uint16_t fromPort, uint16_t toPort)
void DatagramDestination::SendDatagram (std::shared_ptr<DatagramSession> session, const uint8_t * payload, size_t len,
uint16_t fromPort, uint16_t toPort, const i2p::util::Mapping * options)
{
if (session)
{
@ -65,7 +66,16 @@ namespace datagram
{
case eDatagramV3:
{
constexpr uint8_t flags[] = { 0x00, 0x03 }; // datagram3, no options
uint8_t flags[] = { 0x00, 0x03 }; // datagram3, no options
if (options)
{
uint8_t optionsBuf[256]; // TODO: evaluate actual size
size_t optionsLen = options->ToBuffer (optionsBuf, 256);
if (optionsLen) flags[1] |= DATAGRAM3_FLAG_OPTIONS;
msg = CreateDataMessage ({{m_Owner->GetIdentity ()->GetIdentHash (), 32}, {flags, 2},
{optionsBuf, optionsLen}, {payload, len}}, fromPort, toPort, i2p::client::PROTOCOL_TYPE_DATAGRAM3, false); // datagram3
}
else
msg = CreateDataMessage ({{m_Owner->GetIdentity ()->GetIdentHash (), 32},
{flags, 2}, {payload, len}}, fromPort, toPort, i2p::client::PROTOCOL_TYPE_DATAGRAM3, false); // datagram3
break;

View file

@ -139,7 +139,8 @@ namespace datagram
// TODO: implement calls from other thread from SAM
std::shared_ptr<DatagramSession> GetSession(const i2p::data::IdentHash & ident);
void SendDatagram (std::shared_ptr<DatagramSession> session, const uint8_t * payload, size_t len, uint16_t fromPort, uint16_t toPort);
void SendDatagram (std::shared_ptr<DatagramSession> session, const uint8_t * payload, size_t len,
uint16_t fromPort, uint16_t toPort, const i2p::util::Mapping * options = nullptr);
void SendRawDatagram (std::shared_ptr<DatagramSession> session, const uint8_t * payload, size_t len, uint16_t fromPort, uint16_t toPort);
void FlushSendQueue (std::shared_ptr<DatagramSession> session);

View file

@ -266,7 +266,7 @@ namespace util
return { (const char *)(buf + 1), l };
}
size_t Mapping::ToBuffer (uint8_t * buf, size_t len)
size_t Mapping::ToBuffer (uint8_t * buf, size_t len) const
{
size_t offset = 2;
for (auto it: m_Options)

View file

@ -17,6 +17,7 @@
#include <mutex>
#include <thread>
#include <utility>
#include <charconv>
#include <boost/asio.hpp>
#ifdef ANDROID
@ -234,7 +235,7 @@ namespace util
Mapping () = default;
size_t FromBuffer (const uint8_t * buf, size_t len);
size_t FromBuffer (size_t size, const uint8_t * buf, size_t len); //without 2 bytes size
size_t ToBuffer (uint8_t * buf, size_t len);
size_t ToBuffer (uint8_t * buf, size_t len) const;
std::string_view operator[](std::string_view param) const;
bool Insert (std::string_view param, std::string_view value);
@ -245,6 +246,20 @@ namespace util
static size_t WriteString (std::string_view str, uint8_t * buf, size_t len);
static size_t WriteOption (std::string_view param, std::string_view value, uint8_t * buf, size_t len);
template<typename T>
bool Get(std::string_view param, T& value)
{
auto s = (*this)[param];
if (s.empty ()) return false;
auto res = std::from_chars(s.data(), s.data() + s.size(), value);
return res.ec != std::errc();
}
template<typename T>
bool Put (std::string_view param, T value)
{
return Insert (param, std::to_string (value));
}
private:
std::map<std::string, std::string, std::less<> > m_Options;