mirror of https://github.com/PurpleI2P/i2pd.git
I2P: End-to-End encrypted and anonymous Internet
https://i2pd.website/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.0 KiB
74 lines
2.0 KiB
11 years ago
|
#ifndef TUNNEL_BASE_H__
|
||
|
#define TUNNEL_BASE_H__
|
||
|
|
||
|
#include <inttypes.h>
|
||
10 years ago
|
#include <memory>
|
||
11 years ago
|
#include "Timestamp.h"
|
||
11 years ago
|
#include "I2NPProtocol.h"
|
||
11 years ago
|
#include "Identity.h"
|
||
11 years ago
|
|
||
|
namespace i2p
|
||
|
{
|
||
|
namespace tunnel
|
||
|
{
|
||
11 years ago
|
const size_t TUNNEL_DATA_MSG_SIZE = 1028;
|
||
11 years ago
|
const size_t TUNNEL_DATA_ENCRYPTED_SIZE = 1008;
|
||
11 years ago
|
const size_t TUNNEL_DATA_MAX_PAYLOAD_SIZE = 1003;
|
||
|
|
||
11 years ago
|
enum TunnelDeliveryType
|
||
|
{
|
||
|
eDeliveryTypeLocal = 0,
|
||
|
eDeliveryTypeTunnel = 1,
|
||
|
eDeliveryTypeRouter = 2
|
||
|
};
|
||
|
struct TunnelMessageBlock
|
||
|
{
|
||
|
TunnelDeliveryType deliveryType;
|
||
11 years ago
|
i2p::data::IdentHash hash;
|
||
11 years ago
|
uint32_t tunnelID;
|
||
10 years ago
|
std::shared_ptr<I2NPMessage> data;
|
||
11 years ago
|
};
|
||
11 years ago
|
|
||
|
class TunnelBase
|
||
|
{
|
||
|
public:
|
||
|
|
||
9 years ago
|
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 ()) {};
|
||
11 years ago
|
virtual ~TunnelBase () {};
|
||
8 years ago
|
virtual void Cleanup () {};
|
||
11 years ago
|
|
||
10 years ago
|
virtual void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg) = 0;
|
||
10 years ago
|
virtual void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg) = 0;
|
||
10 years ago
|
virtual void FlushTunnelDataMsgs () {};
|
||
10 years ago
|
virtual void EncryptTunnelMsg (std::shared_ptr<const I2NPMessage> in, std::shared_ptr<I2NPMessage> out) = 0;
|
||
9 years ago
|
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
|
||
11 years ago
|
|
||
|
uint32_t GetCreationTime () const { return m_CreationTime; };
|
||
|
void SetCreationTime (uint32_t t) { m_CreationTime = t; };
|
||
8 years ago
|
|
||
11 years ago
|
private:
|
||
9 years ago
|
|
||
|
uint32_t m_TunnelID, m_NextTunnelID;
|
||
|
i2p::data::IdentHash m_NextIdent;
|
||
11 years ago
|
uint32_t m_CreationTime; // seconds since epoch
|
||
11 years ago
|
};
|
||
11 years ago
|
|
||
|
struct TunnelCreationTimeCmp
|
||
|
{
|
||
10 years ago
|
bool operator() (std::shared_ptr<const TunnelBase> t1, std::shared_ptr<const TunnelBase> t2) const
|
||
11 years ago
|
{
|
||
|
if (t1->GetCreationTime () != t2->GetCreationTime ())
|
||
|
return t1->GetCreationTime () > t2->GetCreationTime ();
|
||
|
else
|
||
|
return t1 < t2;
|
||
|
};
|
||
|
};
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|