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.
106 lines
3.0 KiB
106 lines
3.0 KiB
11 years ago
|
#ifndef TRANSIT_TUNNEL_H__
|
||
|
#define TRANSIT_TUNNEL_H__
|
||
|
|
||
|
#include <inttypes.h>
|
||
10 years ago
|
#include <vector>
|
||
11 years ago
|
#include <mutex>
|
||
10 years ago
|
#include <memory>
|
||
9 years ago
|
#include "Crypto.h"
|
||
11 years ago
|
#include "I2NPProtocol.h"
|
||
|
#include "TunnelEndpoint.h"
|
||
|
#include "TunnelGateway.h"
|
||
11 years ago
|
#include "TunnelBase.h"
|
||
11 years ago
|
|
||
|
namespace i2p
|
||
|
{
|
||
|
namespace tunnel
|
||
|
{
|
||
10 years ago
|
class TransitTunnel: public TunnelBase
|
||
11 years ago
|
{
|
||
|
public:
|
||
|
|
||
|
TransitTunnel (uint32_t receiveTunnelID,
|
||
|
const uint8_t * nextIdent, uint32_t nextTunnelID,
|
||
11 years ago
|
const uint8_t * layerKey,const uint8_t * ivKey);
|
||
11 years ago
|
|
||
10 years ago
|
virtual size_t GetNumTransmittedBytes () const { return 0; };
|
||
11 years ago
|
|
||
11 years ago
|
// implements TunnelBase
|
||
10 years ago
|
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg);
|
||
10 years ago
|
void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg);
|
||
9 years ago
|
void EncryptTunnelMsg (std::shared_ptr<const I2NPMessage> in, std::shared_ptr<I2NPMessage> out);
|
||
11 years ago
|
private:
|
||
|
|
||
11 years ago
|
i2p::crypto::TunnelEncryption m_Encryption;
|
||
11 years ago
|
};
|
||
11 years ago
|
|
||
10 years ago
|
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; };
|
||
10 years ago
|
void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg);
|
||
10 years ago
|
void FlushTunnelDataMsgs ();
|
||
|
|
||
|
private:
|
||
|
|
||
|
size_t m_NumTransmittedBytes;
|
||
10 years ago
|
std::vector<std::shared_ptr<i2p::I2NPMessage> > m_TunnelDataMsgs;
|
||
10 years ago
|
};
|
||
|
|
||
11 years ago
|
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) {};
|
||
|
|
||
10 years ago
|
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg);
|
||
10 years ago
|
void FlushTunnelDataMsgs ();
|
||
11 years ago
|
size_t GetNumTransmittedBytes () const { return m_Gateway.GetNumSentBytes (); };
|
||
11 years ago
|
|
||
|
private:
|
||
|
|
||
11 years ago
|
std::mutex m_SendMutex;
|
||
11 years ago
|
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):
|
||
11 years ago
|
TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID, layerKey, ivKey),
|
||
|
m_Endpoint (false) {}; // transit endpoint is always outbound
|
||
11 years ago
|
|
||
8 years ago
|
void Cleanup () { m_Endpoint.Cleanup (); }
|
||
|
|
||
10 years ago
|
void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg);
|
||
11 years ago
|
size_t GetNumTransmittedBytes () const { return m_Endpoint.GetNumReceivedBytes (); }
|
||
11 years ago
|
|
||
|
private:
|
||
|
|
||
|
TunnelEndpoint m_Endpoint;
|
||
|
};
|
||
|
|
||
9 years ago
|
std::shared_ptr<TransitTunnel> CreateTransitTunnel (uint32_t receiveTunnelID,
|
||
11 years ago
|
const uint8_t * nextIdent, uint32_t nextTunnelID,
|
||
|
const uint8_t * layerKey,const uint8_t * ivKey,
|
||
|
bool isGateway, bool isEndpoint);
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|