mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-10-20 10:40:19 +01:00
pass options from Datagram2 and Datagram3 to handlers
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
acb09c3119
commit
dc9cdf941d
8 changed files with 53 additions and 16 deletions
|
@ -165,7 +165,7 @@ namespace datagram
|
|||
session->Ack();
|
||||
auto r = FindReceiver(toPort);
|
||||
if(r)
|
||||
r(identity, fromPort, toPort, buf + headerLen, len -headerLen);
|
||||
r(identity, fromPort, toPort, buf + headerLen, len - headerLen, nullptr);
|
||||
else
|
||||
LogPrint (eLogWarning, "DatagramDestination: no receiver for port ", toPort);
|
||||
}
|
||||
|
@ -218,8 +218,20 @@ namespace datagram
|
|||
}
|
||||
uint16_t flags = bufbe16toh (buf + identityLen);
|
||||
size_t offset = identityLen + 2;
|
||||
bool isOptions = false;
|
||||
if (flags & DATAGRAM2_FLAG_OPTIONS)
|
||||
offset += bufbe16toh (buf + offset) + 2;
|
||||
{
|
||||
isOptions = true;
|
||||
m_Options.CleanUp ();
|
||||
auto optionsLen = m_Options.FromBuffer (buf + offset, len - offset);
|
||||
if (optionsLen)
|
||||
offset += optionsLen;
|
||||
else
|
||||
{
|
||||
LogPrint (eLogWarning, "Datagram: datagram2 can't read options");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (offset > len)
|
||||
{
|
||||
LogPrint (eLogWarning, "Datagram: datagram2 is too short ", len, " expected ", offset);
|
||||
|
@ -256,7 +268,7 @@ namespace datagram
|
|||
session->Ack();
|
||||
auto r = FindReceiver(toPort);
|
||||
if(r)
|
||||
r(identity, fromPort, toPort, buf + offset, len - offset - signatureLen);
|
||||
r(identity, fromPort, toPort, buf + offset, len - offset - signatureLen, isOptions ? &m_Options : nullptr);
|
||||
else
|
||||
LogPrint (eLogWarning, "DatagramDestination: no receiver for port ", toPort);
|
||||
}
|
||||
|
@ -288,14 +300,26 @@ namespace datagram
|
|||
{
|
||||
uint16_t flags = bufbe16toh (buf + 32);
|
||||
size_t offset = 34;
|
||||
bool isOptions = false;
|
||||
if (flags & DATAGRAM3_FLAG_OPTIONS)
|
||||
offset += bufbe16toh (buf + offset) + 2;
|
||||
{
|
||||
isOptions = true;
|
||||
m_Options.CleanUp ();
|
||||
auto optionsLen = m_Options.FromBuffer (buf + offset, len - offset);
|
||||
if (optionsLen)
|
||||
offset += optionsLen;
|
||||
else
|
||||
{
|
||||
LogPrint (eLogWarning, "Datagram: datagram3 can't read options");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (offset > len)
|
||||
{
|
||||
LogPrint (eLogWarning, "Datagram: datagram3 is too short ", len, " expected ", offset);
|
||||
return;
|
||||
}
|
||||
r(*ls->GetIdentity (), fromPort, toPort, buf + offset, len - offset);
|
||||
r(*ls->GetIdentity (), fromPort, toPort, buf + offset, len - offset, isOptions ? &m_Options : nullptr);
|
||||
}
|
||||
else
|
||||
LogPrint (eLogWarning, "Datagram: no receiver for port ", toPort);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "LeaseSet.h"
|
||||
#include "I2NPProtocol.h"
|
||||
#include "Garlic.h"
|
||||
#include "util.h"
|
||||
#include "ECIESX25519AEADRatchetSession.h"
|
||||
|
||||
namespace i2p
|
||||
|
@ -124,7 +125,8 @@ namespace datagram
|
|||
const size_t MAX_DATAGRAM_SIZE = 32768;
|
||||
class DatagramDestination
|
||||
{
|
||||
typedef std::function<void (const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len)> Receiver;
|
||||
typedef std::function<void (const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort,
|
||||
const uint8_t * buf, size_t len, const i2p::util::Mapping * options)> Receiver;
|
||||
typedef std::function<void (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len)> RawReceiver;
|
||||
|
||||
public:
|
||||
|
@ -193,6 +195,7 @@ namespace datagram
|
|||
DatagramVersion m_Version; // default for destination
|
||||
i2p::data::GzipInflator m_Inflator;
|
||||
std::unique_ptr<i2p::data::GzipDeflator> m_Deflator;
|
||||
i2p::util::Mapping m_Options;
|
||||
std::vector<uint8_t> m_From, m_Signature;
|
||||
i2p::util::MemoryPool<I2NPMessageBuffer<I2NP_MAX_MESSAGE_SIZE> > m_I2NPMsgsPool;
|
||||
};
|
||||
|
|
|
@ -223,7 +223,7 @@ namespace util
|
|||
|
||||
size_t Mapping::FromBuffer (size_t size, const uint8_t * buf, size_t len)
|
||||
{
|
||||
if (len < size) return 0;
|
||||
if (!size || len < size) return 0;
|
||||
size_t offset = 0;
|
||||
while (offset < size)
|
||||
{
|
||||
|
|
|
@ -239,6 +239,7 @@ namespace util
|
|||
std::string_view operator[](std::string_view param) const;
|
||||
bool Insert (std::string_view param, std::string_view value);
|
||||
void CleanUp ();
|
||||
bool IsEmpty () const { return m_Options.empty (); }
|
||||
|
||||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue