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