2014-10-22 19:30:25 +00:00
|
|
|
#ifndef DATAGRAM_H__
|
|
|
|
#define DATAGRAM_H__
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
2015-01-29 02:37:08 +00:00
|
|
|
#include <memory>
|
2014-10-31 20:44:44 +00:00
|
|
|
#include <functional>
|
2015-04-04 00:34:37 +00:00
|
|
|
#include <map>
|
2014-10-31 20:44:44 +00:00
|
|
|
#include "Identity.h"
|
2014-10-23 20:56:50 +00:00
|
|
|
#include "LeaseSet.h"
|
|
|
|
#include "I2NPProtocol.h"
|
2014-10-22 19:30:25 +00:00
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace client
|
|
|
|
{
|
2015-07-16 21:29:52 +00:00
|
|
|
class ClientDestination;
|
2014-10-22 19:30:25 +00:00
|
|
|
}
|
|
|
|
namespace datagram
|
|
|
|
{
|
2015-07-16 21:29:52 +00:00
|
|
|
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;
|
2014-10-31 20:44:44 +00:00
|
|
|
|
2015-07-16 21:29:52 +00:00
|
|
|
public:
|
2014-10-22 19:30:25 +00:00
|
|
|
|
2015-07-16 21:29:52 +00:00
|
|
|
DatagramDestination (i2p::client::ClientDestination& owner);
|
|
|
|
~DatagramDestination () {};
|
2014-10-22 19:30:25 +00:00
|
|
|
|
2015-07-16 21:29:52 +00:00
|
|
|
void SendDatagramTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint16_t fromPort = 0, uint16_t toPort = 0);
|
|
|
|
void HandleDataMessagePayload (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len);
|
2014-10-22 19:30:25 +00:00
|
|
|
|
2015-07-16 21:29:52 +00:00
|
|
|
void SetReceiver (const Receiver& receiver) { m_Receiver = receiver; };
|
|
|
|
void ResetReceiver () { m_Receiver = nullptr; };
|
2014-10-31 20:44:44 +00:00
|
|
|
|
2015-07-16 21:29:52 +00:00
|
|
|
void SetReceiver (const Receiver& receiver, uint16_t port) { m_ReceiversByPorts[port] = receiver; };
|
|
|
|
void ResetReceiver (uint16_t port) { m_ReceiversByPorts.erase (port); };
|
2015-04-04 00:34:37 +00:00
|
|
|
|
2015-07-16 21:29:52 +00:00
|
|
|
private:
|
2014-10-23 20:56:50 +00:00
|
|
|
|
2015-07-16 21:29:52 +00:00
|
|
|
void HandleLeaseSetRequestComplete (std::shared_ptr<i2p::data::LeaseSet> leaseSet, I2NPMessage * msg);
|
|
|
|
|
|
|
|
I2NPMessage * CreateDataMessage (const uint8_t * payload, size_t len, uint16_t fromPort, uint16_t toPort);
|
|
|
|
void SendMsg (I2NPMessage * msg, std::shared_ptr<const i2p::data::LeaseSet> remote);
|
|
|
|
void HandleDatagram (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len);
|
2014-10-23 20:56:50 +00:00
|
|
|
|
2015-07-16 21:29:52 +00:00
|
|
|
private:
|
2014-10-22 19:30:25 +00:00
|
|
|
|
2015-07-16 21:29:52 +00:00
|
|
|
i2p::client::ClientDestination& m_Owner;
|
|
|
|
Receiver m_Receiver; // default
|
|
|
|
std::map<uint16_t, Receiver> m_ReceiversByPorts;
|
|
|
|
};
|
2014-10-22 19:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|