2013-11-11 03:19:49 +04:00
|
|
|
#ifndef TRANSIT_TUNNEL_H__
|
|
|
|
#define TRANSIT_TUNNEL_H__
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
2015-01-22 05:50:46 +03:00
|
|
|
#include <vector>
|
2014-06-26 23:41:12 +04:00
|
|
|
#include <mutex>
|
2015-06-17 19:31:28 +03:00
|
|
|
#include <memory>
|
2014-05-09 15:59:40 +04:00
|
|
|
#include "aes.h"
|
2013-11-11 03:19:49 +04:00
|
|
|
#include "I2NPProtocol.h"
|
|
|
|
#include "TunnelEndpoint.h"
|
|
|
|
#include "TunnelGateway.h"
|
2013-11-29 16:52:09 +04:00
|
|
|
#include "TunnelBase.h"
|
2013-11-11 03:19:49 +04:00
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace tunnel
|
|
|
|
{
|
2015-01-22 05:50:46 +03:00
|
|
|
class TransitTunnel: public TunnelBase
|
2013-11-11 03:19:49 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
TransitTunnel (uint32_t receiveTunnelID,
|
|
|
|
const uint8_t * nextIdent, uint32_t nextTunnelID,
|
2013-11-29 16:52:09 +04:00
|
|
|
const uint8_t * layerKey,const uint8_t * ivKey);
|
2013-11-11 03:19:49 +04:00
|
|
|
|
2015-01-22 05:50:46 +03:00
|
|
|
virtual size_t GetNumTransmittedBytes () const { return 0; };
|
2013-11-11 03:19:49 +04:00
|
|
|
|
|
|
|
uint32_t GetTunnelID () const { return m_TunnelID; };
|
|
|
|
|
2013-11-29 16:52:09 +04:00
|
|
|
// implements TunnelBase
|
2015-06-19 21:38:31 +03:00
|
|
|
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg);
|
2015-06-26 04:49:16 +03:00
|
|
|
void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg);
|
2015-06-25 05:19:56 +03:00
|
|
|
void EncryptTunnelMsg (std::shared_ptr<const I2NPMessage> in, std::shared_ptr<I2NPMessage> out);
|
2013-11-29 16:52:09 +04:00
|
|
|
uint32_t GetNextTunnelID () const { return m_NextTunnelID; };
|
|
|
|
const i2p::data::IdentHash& GetNextIdentHash () const { return m_NextIdent; };
|
2013-11-11 03:19:49 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
uint32_t m_TunnelID, m_NextTunnelID;
|
2013-11-29 16:52:09 +04:00
|
|
|
i2p::data::IdentHash m_NextIdent;
|
2013-11-11 03:19:49 +04:00
|
|
|
|
2014-05-16 01:55:09 +04:00
|
|
|
i2p::crypto::TunnelEncryption m_Encryption;
|
2013-11-11 03:19:49 +04:00
|
|
|
};
|
2013-11-29 16:52:09 +04:00
|
|
|
|
2015-01-22 05:50:46 +03:00
|
|
|
class TransitTunnelParticipant: public TransitTunnel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
TransitTunnelParticipant (uint32_t receiveTunnelID,
|
|
|
|
const uint8_t * nextIdent, uint32_t nextTunnelID,
|
|
|
|
const uint8_t * layerKey,const uint8_t * ivKey):
|
|
|
|
TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID,
|
|
|
|
layerKey, ivKey), m_NumTransmittedBytes (0) {};
|
|
|
|
~TransitTunnelParticipant ();
|
|
|
|
|
|
|
|
size_t GetNumTransmittedBytes () const { return m_NumTransmittedBytes; };
|
2015-06-26 04:49:16 +03:00
|
|
|
void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg);
|
2015-01-22 05:50:46 +03:00
|
|
|
void FlushTunnelDataMsgs ();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
size_t m_NumTransmittedBytes;
|
2015-06-17 19:31:28 +03:00
|
|
|
std::vector<std::shared_ptr<i2p::I2NPMessage> > m_TunnelDataMsgs;
|
2015-01-22 05:50:46 +03:00
|
|
|
};
|
|
|
|
|
2013-11-29 16:52:09 +04:00
|
|
|
class TransitTunnelGateway: public TransitTunnel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
TransitTunnelGateway (uint32_t receiveTunnelID,
|
|
|
|
const uint8_t * nextIdent, uint32_t nextTunnelID,
|
|
|
|
const uint8_t * layerKey,const uint8_t * ivKey):
|
|
|
|
TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID,
|
|
|
|
layerKey, ivKey), m_Gateway(this) {};
|
|
|
|
|
2015-06-19 21:38:31 +03:00
|
|
|
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg);
|
2015-01-24 06:05:33 +03:00
|
|
|
void FlushTunnelDataMsgs ();
|
2014-01-06 07:52:17 +04:00
|
|
|
size_t GetNumTransmittedBytes () const { return m_Gateway.GetNumSentBytes (); };
|
2013-11-29 16:52:09 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2014-06-26 23:41:12 +04:00
|
|
|
std::mutex m_SendMutex;
|
2013-11-29 16:52:09 +04:00
|
|
|
TunnelGateway m_Gateway;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TransitTunnelEndpoint: public TransitTunnel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
TransitTunnelEndpoint (uint32_t receiveTunnelID,
|
|
|
|
const uint8_t * nextIdent, uint32_t nextTunnelID,
|
|
|
|
const uint8_t * layerKey,const uint8_t * ivKey):
|
2014-07-10 20:44:49 +04:00
|
|
|
TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID, layerKey, ivKey),
|
|
|
|
m_Endpoint (false) {}; // transit endpoint is always outbound
|
2013-11-29 16:52:09 +04:00
|
|
|
|
2015-06-26 04:49:16 +03:00
|
|
|
void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg);
|
2014-01-06 07:52:17 +04:00
|
|
|
size_t GetNumTransmittedBytes () const { return m_Endpoint.GetNumReceivedBytes (); }
|
2013-11-29 16:52:09 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
TunnelEndpoint m_Endpoint;
|
|
|
|
};
|
|
|
|
|
|
|
|
TransitTunnel * CreateTransitTunnel (uint32_t receiveTunnelID,
|
|
|
|
const uint8_t * nextIdent, uint32_t nextTunnelID,
|
|
|
|
const uint8_t * layerKey,const uint8_t * ivKey,
|
|
|
|
bool isGateway, bool isEndpoint);
|
2013-11-11 03:19:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|