2013-11-11 03:19:49 +04:00
|
|
|
#ifndef TUNNEL_BASE_H__
|
|
|
|
#define TUNNEL_BASE_H__
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
2015-01-27 22:55:46 +03:00
|
|
|
#include <memory>
|
2014-01-04 07:56:28 +04:00
|
|
|
#include "Timestamp.h"
|
2013-11-13 16:56:16 +04:00
|
|
|
#include "I2NPProtocol.h"
|
2014-01-21 03:37:51 +04:00
|
|
|
#include "Identity.h"
|
2013-11-11 03:19:49 +04:00
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace tunnel
|
|
|
|
{
|
2013-11-23 05:41:28 +04:00
|
|
|
const size_t TUNNEL_DATA_MSG_SIZE = 1028;
|
2013-12-10 17:10:49 +04:00
|
|
|
const size_t TUNNEL_DATA_ENCRYPTED_SIZE = 1008;
|
2013-11-23 05:41:28 +04:00
|
|
|
const size_t TUNNEL_DATA_MAX_PAYLOAD_SIZE = 1003;
|
|
|
|
|
2013-11-11 03:19:49 +04:00
|
|
|
enum TunnelDeliveryType
|
|
|
|
{
|
|
|
|
eDeliveryTypeLocal = 0,
|
|
|
|
eDeliveryTypeTunnel = 1,
|
|
|
|
eDeliveryTypeRouter = 2
|
|
|
|
};
|
|
|
|
struct TunnelMessageBlock
|
|
|
|
{
|
|
|
|
TunnelDeliveryType deliveryType;
|
2014-01-21 03:37:51 +04:00
|
|
|
i2p::data::IdentHash hash;
|
2014-01-21 04:12:59 +04:00
|
|
|
uint32_t tunnelID;
|
2013-11-11 03:19:49 +04:00
|
|
|
I2NPMessage * data;
|
|
|
|
};
|
2013-11-13 16:56:16 +04:00
|
|
|
|
|
|
|
class TunnelBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-01-20 17:27:46 +04:00
|
|
|
//WARNING!!! GetSecondsSinceEpoch() return uint64_t
|
2014-01-04 07:56:28 +04:00
|
|
|
TunnelBase (): m_CreationTime (i2p::util::GetSecondsSinceEpoch ()) {};
|
2013-12-10 17:10:49 +04:00
|
|
|
virtual ~TunnelBase () {};
|
|
|
|
|
2015-01-21 22:40:48 +03:00
|
|
|
virtual void HandleTunnelDataMsg (i2p::I2NPMessage * tunnelMsg) = 0;
|
2015-01-24 00:26:39 +03:00
|
|
|
virtual void SendTunnelDataMsg (i2p::I2NPMessage * msg) = 0;
|
2015-01-22 05:50:46 +03:00
|
|
|
virtual void FlushTunnelDataMsgs () {};
|
2013-11-13 16:56:16 +04:00
|
|
|
virtual void EncryptTunnelMsg (I2NPMessage * tunnelMsg) = 0;
|
|
|
|
virtual uint32_t GetNextTunnelID () const = 0;
|
2013-12-10 17:10:49 +04:00
|
|
|
virtual const i2p::data::IdentHash& GetNextIdentHash () const = 0;
|
2014-01-04 07:56:28 +04:00
|
|
|
virtual uint32_t GetTunnelID () const = 0; // as known at our side
|
|
|
|
|
|
|
|
uint32_t GetCreationTime () const { return m_CreationTime; };
|
|
|
|
void SetCreationTime (uint32_t t) { m_CreationTime = t; };
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
uint32_t m_CreationTime; // seconds since epoch
|
2013-11-13 16:56:16 +04:00
|
|
|
};
|
2014-03-14 23:13:34 +04:00
|
|
|
|
|
|
|
struct TunnelCreationTimeCmp
|
|
|
|
{
|
2015-01-27 22:55:46 +03:00
|
|
|
bool operator() (std::shared_ptr<const TunnelBase> t1, std::shared_ptr<const TunnelBase> t2) const
|
2014-03-14 23:13:34 +04:00
|
|
|
{
|
|
|
|
if (t1->GetCreationTime () != t2->GetCreationTime ())
|
|
|
|
return t1->GetCreationTime () > t2->GetCreationTime ();
|
|
|
|
else
|
|
|
|
return t1 < t2;
|
|
|
|
};
|
|
|
|
};
|
2013-11-11 03:19:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|