mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-13 19:37:51 +00:00
set datagram receiver per port
This commit is contained in:
parent
321dd252ea
commit
89ed8c2173
@ -16,7 +16,7 @@ namespace datagram
|
|||||||
m_Owner (owner), m_Receiver (nullptr)
|
m_Owner (owner), m_Receiver (nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatagramDestination::SendDatagramTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint16_t fromPort, uint16_t toPort)
|
void DatagramDestination::SendDatagramTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint16_t fromPort, uint16_t toPort)
|
||||||
{
|
{
|
||||||
uint8_t buf[MAX_DATAGRAM_SIZE];
|
uint8_t buf[MAX_DATAGRAM_SIZE];
|
||||||
@ -105,7 +105,10 @@ namespace datagram
|
|||||||
|
|
||||||
if (verified)
|
if (verified)
|
||||||
{
|
{
|
||||||
if (m_Receiver != nullptr)
|
auto it = m_ReceiversByPorts.find (toPort);
|
||||||
|
if (it != m_ReceiversByPorts.end ())
|
||||||
|
it->second (identity, fromPort, toPort, buf + headerLen, len -headerLen);
|
||||||
|
else if (m_Receiver != nullptr)
|
||||||
m_Receiver (identity, fromPort, toPort, buf + headerLen, len -headerLen);
|
m_Receiver (identity, fromPort, toPort, buf + headerLen, len -headerLen);
|
||||||
else
|
else
|
||||||
LogPrint (eLogWarning, "Receiver for datagram is not set");
|
LogPrint (eLogWarning, "Receiver for datagram is not set");
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
#include "LeaseSet.h"
|
#include "LeaseSet.h"
|
||||||
#include "I2NPProtocol.h"
|
#include "I2NPProtocol.h"
|
||||||
@ -32,6 +33,9 @@ namespace datagram
|
|||||||
void SetReceiver (const Receiver& receiver) { m_Receiver = receiver; };
|
void SetReceiver (const Receiver& receiver) { m_Receiver = receiver; };
|
||||||
void ResetReceiver () { m_Receiver = nullptr; };
|
void ResetReceiver () { m_Receiver = nullptr; };
|
||||||
|
|
||||||
|
void SetReceiver (const Receiver& receiver, uint16_t port) { m_ReceiversByPorts[port] = receiver; };
|
||||||
|
void ResetReceiver (uint16_t port) { m_ReceiversByPorts.erase (port); };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void HandleLeaseSetRequestComplete (bool success, I2NPMessage * msg, i2p::data::IdentHash ident);
|
void HandleLeaseSetRequestComplete (bool success, I2NPMessage * msg, i2p::data::IdentHash ident);
|
||||||
@ -43,7 +47,8 @@ namespace datagram
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
i2p::client::ClientDestination& m_Owner;
|
i2p::client::ClientDestination& m_Owner;
|
||||||
Receiver m_Receiver;
|
Receiver m_Receiver; // default
|
||||||
|
std::map<uint16_t, Receiver> m_ReceiversByPorts;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user