1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-14 21:09:57 +00:00
i2pd/TransitTunnel.h

89 lines
2.5 KiB
C
Raw Normal View History

2013-11-10 18:19:49 -05:00
#ifndef TRANSIT_TUNNEL_H__
#define TRANSIT_TUNNEL_H__
#include <inttypes.h>
2014-06-26 15:41:12 -04:00
#include <mutex>
#include "aes.h"
2013-11-10 18:19:49 -05:00
#include "I2NPProtocol.h"
#include "TunnelEndpoint.h"
#include "TunnelGateway.h"
2013-11-29 07:52:09 -05:00
#include "TunnelBase.h"
2013-11-10 18:19:49 -05:00
namespace i2p
{
namespace tunnel
{
2013-11-29 07:52:09 -05:00
class TransitTunnel: public TunnelBase // tunnel patricipant
2013-11-10 18:19:49 -05:00
{
public:
TransitTunnel (uint32_t receiveTunnelID,
const uint8_t * nextIdent, uint32_t nextTunnelID,
2013-11-29 07:52:09 -05:00
const uint8_t * layerKey,const uint8_t * ivKey);
2013-11-10 18:19:49 -05:00
2013-11-29 07:52:09 -05:00
virtual void HandleTunnelDataMsg (i2p::I2NPMessage * tunnelMsg);
virtual void SendTunnelDataMsg (i2p::I2NPMessage * msg);
2014-01-05 22:52:17 -05:00
virtual size_t GetNumTransmittedBytes () const { return m_NumTransmittedBytes; };
2013-11-10 18:19:49 -05:00
uint32_t GetTunnelID () const { return m_TunnelID; };
2013-11-29 07:52:09 -05:00
// implements TunnelBase
void EncryptTunnelMsg (I2NPMessage * tunnelMsg);
uint32_t GetNextTunnelID () const { return m_NextTunnelID; };
const i2p::data::IdentHash& GetNextIdentHash () const { return m_NextIdent; };
2013-11-10 18:19:49 -05:00
private:
uint32_t m_TunnelID, m_NextTunnelID;
2013-11-29 07:52:09 -05:00
i2p::data::IdentHash m_NextIdent;
2014-01-05 22:52:17 -05:00
size_t m_NumTransmittedBytes;
2013-11-10 18:19:49 -05:00
2014-05-15 17:55:09 -04:00
i2p::crypto::TunnelEncryption m_Encryption;
2013-11-10 18:19:49 -05:00
};
2013-11-29 07:52:09 -05: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) {};
void SendTunnelDataMsg (i2p::I2NPMessage * msg);
2014-01-05 22:52:17 -05:00
size_t GetNumTransmittedBytes () const { return m_Gateway.GetNumSentBytes (); };
2013-11-29 07:52:09 -05:00
private:
2014-06-26 15:41:12 -04:00
std::mutex m_SendMutex;
2013-11-29 07:52:09 -05: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):
TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID, layerKey, ivKey),
m_Endpoint (false) {}; // transit endpoint is always outbound
2013-11-29 07:52:09 -05:00
void HandleTunnelDataMsg (i2p::I2NPMessage * tunnelMsg);
2014-01-05 22:52:17 -05:00
size_t GetNumTransmittedBytes () const { return m_Endpoint.GetNumReceivedBytes (); }
2013-11-29 07:52:09 -05: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-10 18:19:49 -05:00
}
}
#endif