mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2026-05-04 03:06:00 +00:00
send options in Datagram3
This commit is contained in:
+14
-4
@@ -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,9 +66,18 @@ namespace datagram
|
||||
{
|
||||
case eDatagramV3:
|
||||
{
|
||||
constexpr uint8_t flags[] = { 0x00, 0x03 }; // datagram3, no options
|
||||
msg = CreateDataMessage ({{m_Owner->GetIdentity ()->GetIdentHash (), 32},
|
||||
{flags, 2}, {payload, len}}, fromPort, toPort, i2p::client::PROTOCOL_TYPE_DATAGRAM3, false); // datagram3
|
||||
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;
|
||||
}
|
||||
case eDatagramV1:
|
||||
|
||||
+4
-3
@@ -134,12 +134,13 @@ namespace datagram
|
||||
DatagramDestination (std::shared_ptr<i2p::client::ClientDestination> owner, bool gzip, DatagramVersion version);
|
||||
~DatagramDestination ();
|
||||
|
||||
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 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);
|
||||
// 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);
|
||||
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
+16
-1
@@ -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);
|
||||
@@ -244,6 +245,20 @@ namespace util
|
||||
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 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:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user