2020-05-22 15:18:41 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2020, The PurpleI2P Project
|
|
|
|
*
|
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3
|
|
|
|
*
|
|
|
|
* See full license text in LICENSE file at top of project tree
|
|
|
|
*/
|
|
|
|
|
2013-11-11 00:19:49 +01:00
|
|
|
#ifndef TUNNEL_BASE_H__
|
|
|
|
#define TUNNEL_BASE_H__
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
2015-01-27 20:55:46 +01:00
|
|
|
#include <memory>
|
2014-01-04 04:56:28 +01:00
|
|
|
#include "Timestamp.h"
|
2013-11-13 13:56:16 +01:00
|
|
|
#include "I2NPProtocol.h"
|
2014-01-21 00:37:51 +01:00
|
|
|
#include "Identity.h"
|
2013-11-11 00:19:49 +01:00
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace tunnel
|
|
|
|
{
|
2013-11-23 02:41:28 +01:00
|
|
|
const size_t TUNNEL_DATA_MSG_SIZE = 1028;
|
2013-12-10 14:10:49 +01:00
|
|
|
const size_t TUNNEL_DATA_ENCRYPTED_SIZE = 1008;
|
2013-11-23 02:41:28 +01:00
|
|
|
const size_t TUNNEL_DATA_MAX_PAYLOAD_SIZE = 1003;
|
2018-01-06 04:48:51 +01:00
|
|
|
|
|
|
|
enum TunnelDeliveryType
|
|
|
|
{
|
|
|
|
eDeliveryTypeLocal = 0,
|
2013-11-11 00:19:49 +01:00
|
|
|
eDeliveryTypeTunnel = 1,
|
|
|
|
eDeliveryTypeRouter = 2
|
2018-01-06 04:48:51 +01:00
|
|
|
};
|
2013-11-11 00:19:49 +01:00
|
|
|
struct TunnelMessageBlock
|
|
|
|
{
|
|
|
|
TunnelDeliveryType deliveryType;
|
2018-01-06 04:48:51 +01:00
|
|
|
i2p::data::IdentHash hash;
|
2014-01-21 01:12:59 +01:00
|
|
|
uint32_t tunnelID;
|
2015-06-19 20:38:31 +02:00
|
|
|
std::shared_ptr<I2NPMessage> data;
|
2013-11-11 00:19:49 +01:00
|
|
|
};
|
2013-11-13 13:56:16 +01:00
|
|
|
|
|
|
|
class TunnelBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2018-01-06 04:48:51 +01:00
|
|
|
TunnelBase (uint32_t tunnelID, uint32_t nextTunnelID, i2p::data::IdentHash nextIdent):
|
2015-11-03 15:15:49 +01:00
|
|
|
m_TunnelID (tunnelID), m_NextTunnelID (nextTunnelID), m_NextIdent (nextIdent),
|
|
|
|
m_CreationTime (i2p::util::GetSecondsSinceEpoch ()) {};
|
2013-12-10 14:10:49 +01:00
|
|
|
virtual ~TunnelBase () {};
|
2016-11-09 20:51:55 +01:00
|
|
|
virtual void Cleanup () {};
|
2018-01-06 04:48:51 +01:00
|
|
|
|
2015-06-26 03:49:16 +02:00
|
|
|
virtual void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg) = 0;
|
2015-06-19 20:38:31 +02:00
|
|
|
virtual void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg) = 0;
|
2015-01-22 03:50:46 +01:00
|
|
|
virtual void FlushTunnelDataMsgs () {};
|
2015-06-25 04:19:56 +02:00
|
|
|
virtual void EncryptTunnelMsg (std::shared_ptr<const I2NPMessage> in, std::shared_ptr<I2NPMessage> out) = 0;
|
2015-11-03 15:15:49 +01: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 04:56:28 +01:00
|
|
|
|
|
|
|
uint32_t GetCreationTime () const { return m_CreationTime; };
|
|
|
|
void SetCreationTime (uint32_t t) { m_CreationTime = t; };
|
2018-01-06 04:48:51 +01:00
|
|
|
|
2014-01-04 04:56:28 +01:00
|
|
|
private:
|
2015-11-03 15:15:49 +01:00
|
|
|
|
|
|
|
uint32_t m_TunnelID, m_NextTunnelID;
|
|
|
|
i2p::data::IdentHash m_NextIdent;
|
2014-01-04 04:56:28 +01:00
|
|
|
uint32_t m_CreationTime; // seconds since epoch
|
2018-01-06 04:48:51 +01:00
|
|
|
};
|
2014-03-14 20:13:34 +01:00
|
|
|
|
|
|
|
struct TunnelCreationTimeCmp
|
|
|
|
{
|
2018-02-05 03:07:26 +01:00
|
|
|
template<typename T>
|
|
|
|
bool operator() (const std::shared_ptr<T> & t1, const std::shared_ptr<T> & t2) const
|
2018-01-06 05:01:44 +01:00
|
|
|
{
|
2014-03-14 20:13:34 +01:00
|
|
|
if (t1->GetCreationTime () != t2->GetCreationTime ())
|
2018-01-06 04:48:51 +01:00
|
|
|
return t1->GetCreationTime () > t2->GetCreationTime ();
|
2014-03-14 20:13:34 +01:00
|
|
|
else
|
|
|
|
return t1 < t2;
|
2018-02-05 17:13:25 +01:00
|
|
|
}
|
2018-01-06 04:48:51 +01:00
|
|
|
};
|
2013-11-11 00:19:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|