i2pd/libi2pd/TunnelBase.h

74 lines
2.0 KiB
C
Raw Normal View History

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