mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-10-17 09:10:21 +01:00
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
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:
parent
dc9cdf941d
commit
cd841f7219
4 changed files with 35 additions and 9 deletions
|
@ -56,7 +56,8 @@ namespace datagram
|
||||||
return ObtainSession(ident);
|
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)
|
if (session)
|
||||||
{
|
{
|
||||||
|
@ -65,9 +66,18 @@ namespace datagram
|
||||||
{
|
{
|
||||||
case eDatagramV3:
|
case eDatagramV3:
|
||||||
{
|
{
|
||||||
constexpr uint8_t flags[] = { 0x00, 0x03 }; // datagram3, no options
|
uint8_t flags[] = { 0x00, 0x03 }; // datagram3, no options
|
||||||
msg = CreateDataMessage ({{m_Owner->GetIdentity ()->GetIdentHash (), 32},
|
if (options)
|
||||||
{flags, 2}, {payload, len}}, fromPort, toPort, i2p::client::PROTOCOL_TYPE_DATAGRAM3, false); // datagram3
|
{
|
||||||
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case eDatagramV1:
|
case eDatagramV1:
|
||||||
|
|
|
@ -134,12 +134,13 @@ namespace datagram
|
||||||
DatagramDestination (std::shared_ptr<i2p::client::ClientDestination> owner, bool gzip, DatagramVersion version);
|
DatagramDestination (std::shared_ptr<i2p::client::ClientDestination> owner, bool gzip, DatagramVersion version);
|
||||||
~DatagramDestination ();
|
~DatagramDestination ();
|
||||||
|
|
||||||
void SendDatagramTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash & ident, uint16_t fromPort = 0, uint16_t toPort = 0);
|
void SendDatagramTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint16_t fromPort = 0, uint16_t toPort = 0);
|
||||||
void SendRawDatagramTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash & ident, uint16_t fromPort = 0, uint16_t toPort = 0);
|
void SendRawDatagramTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint16_t fromPort = 0, uint16_t toPort = 0);
|
||||||
// TODO: implement calls from other thread from SAM
|
// TODO: implement calls from other thread from SAM
|
||||||
|
|
||||||
std::shared_ptr<DatagramSession> GetSession(const i2p::data::IdentHash & ident);
|
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 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);
|
void FlushSendQueue (std::shared_ptr<DatagramSession> session);
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,7 @@ namespace util
|
||||||
return { (const char *)(buf + 1), l };
|
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;
|
size_t offset = 2;
|
||||||
for (auto it: m_Options)
|
for (auto it: m_Options)
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <charconv>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
|
@ -234,7 +235,7 @@ namespace util
|
||||||
Mapping () = default;
|
Mapping () = default;
|
||||||
size_t FromBuffer (const uint8_t * buf, size_t len);
|
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 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;
|
std::string_view operator[](std::string_view param) const;
|
||||||
bool Insert (std::string_view param, std::string_view value);
|
bool Insert (std::string_view param, std::string_view value);
|
||||||
|
@ -244,6 +245,20 @@ namespace util
|
||||||
static std::string_view ExtractString (const uint8_t * buf, size_t len);
|
static std::string_view ExtractString (const uint8_t * buf, size_t len);
|
||||||
static size_t WriteString (std::string_view str, uint8_t * buf, size_t len);
|
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);
|
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:
|
private:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue