i2pd/Datagram.h

53 lines
1.4 KiB
C
Raw Normal View History

2014-10-22 23:30:25 +04:00
#ifndef DATAGRAM_H__
#define DATAGRAM_H__
#include <inttypes.h>
2015-01-29 05:37:08 +03:00
#include <memory>
2014-10-31 23:44:44 +03:00
#include <functional>
#include "Identity.h"
2014-10-24 00:56:50 +04:00
#include "LeaseSet.h"
#include "I2NPProtocol.h"
2014-10-22 23:30:25 +04:00
namespace i2p
{
namespace client
{
class ClientDestination;
}
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;
2014-10-31 23:44:44 +03:00
2014-10-22 23:30:25 +04:00
public:
2014-10-24 00:56:50 +04:00
DatagramDestination (i2p::client::ClientDestination& owner);
2014-10-22 23:30:25 +04:00
~DatagramDestination () {};
2015-03-27 18:29:40 +03: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 05:08:34 +03:00
void HandleDataMessagePayload (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len);
2014-10-22 23:30:25 +04:00
2014-10-31 23:44:44 +03:00
void SetReceiver (const Receiver& receiver) { m_Receiver = receiver; };
void ResetReceiver () { m_Receiver = nullptr; };
2014-10-24 00:56:50 +04:00
private:
2015-03-27 04:23:59 +03:00
void HandleLeaseSetRequestComplete (bool success, I2NPMessage * msg, i2p::data::IdentHash ident);
2015-03-27 18:29:40 +03:00
I2NPMessage * CreateDataMessage (const uint8_t * payload, size_t len, uint16_t fromPort, uint16_t toPort);
2015-01-29 05:37:08 +03:00
void SendMsg (I2NPMessage * msg, std::shared_ptr<const i2p::data::LeaseSet> remote);
2015-03-02 05:08:34 +03:00
void HandleDatagram (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len);
2014-10-24 00:56:50 +04:00
2014-10-22 23:30:25 +04:00
private:
i2p::client::ClientDestination& m_Owner;
2014-10-31 23:44:44 +03:00
Receiver m_Receiver;
2014-10-22 23:30:25 +04:00
};
}
}
#endif