mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
enable zero-hops inbound tunnel
This commit is contained in:
parent
ecfdc377ec
commit
d541572882
36
Tunnel.cpp
36
Tunnel.cpp
|
@ -200,18 +200,28 @@ namespace tunnel
|
|||
m_Endpoint.HandleDecryptedTunnelDataMsg (newMsg);
|
||||
}
|
||||
|
||||
void InboundTunnel::SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg)
|
||||
{
|
||||
// assume zero-hops tunnel
|
||||
m_Endpoint.HandleDecryptedTunnelDataMsg (msg);
|
||||
}
|
||||
|
||||
void InboundTunnel::Print (std::stringstream& s) const
|
||||
{
|
||||
PrintHops (s);
|
||||
s << " ⇒ " << GetTunnelID () << ":me";
|
||||
}
|
||||
|
||||
ZeroHopsInboundTunnel::ZeroHopsInboundTunnel ():
|
||||
InboundTunnel (std::make_shared<ZeroHopsTunnelConfig> ())
|
||||
{
|
||||
}
|
||||
|
||||
void ZeroHopsInboundTunnel::SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg)
|
||||
{
|
||||
msg->from = shared_from_this ();
|
||||
m_Endpoint.HandleDecryptedTunnelDataMsg (msg);
|
||||
}
|
||||
|
||||
void ZeroHopsInboundTunnel::Print (std::stringstream& s) const
|
||||
{
|
||||
s << " ⇒ " << GetTunnelID () << ":me";
|
||||
}
|
||||
|
||||
void OutboundTunnel::SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, std::shared_ptr<i2p::I2NPMessage> msg)
|
||||
{
|
||||
TunnelMessageBlock block;
|
||||
|
@ -771,11 +781,21 @@ namespace tunnel
|
|||
|
||||
void Tunnels::CreateZeroHopsInboundTunnel ()
|
||||
{
|
||||
CreateTunnel<InboundTunnel> (
|
||||
/*CreateTunnel<InboundTunnel> (
|
||||
std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> >
|
||||
{
|
||||
i2p::context.GetIdentity ()
|
||||
}));
|
||||
}));*/
|
||||
auto inboundTunnel = std::make_shared<ZeroHopsInboundTunnel> ();
|
||||
m_InboundTunnels.push_back (inboundTunnel);
|
||||
m_Tunnels[inboundTunnel->GetTunnelID ()] = inboundTunnel;
|
||||
|
||||
// create paired outbound tunnel, TODO: move to separate function
|
||||
CreateTunnel<OutboundTunnel> (
|
||||
std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> >
|
||||
{
|
||||
i2p::context.GetIdentity ()
|
||||
}, inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash ()));
|
||||
}
|
||||
|
||||
int Tunnels::GetTransitTunnelsExpirationTimeout ()
|
||||
|
|
13
Tunnel.h
13
Tunnel.h
|
@ -73,6 +73,8 @@ namespace tunnel
|
|||
|
||||
bool HandleTunnelBuildResponse (uint8_t * msg, size_t len);
|
||||
|
||||
virtual void Print (std::stringstream& s) const {};
|
||||
|
||||
// implements TunnelBase
|
||||
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg);
|
||||
void EncryptTunnelMsg (std::shared_ptr<const I2NPMessage> in, std::shared_ptr<I2NPMessage> out);
|
||||
|
@ -119,15 +121,22 @@ namespace tunnel
|
|||
|
||||
InboundTunnel (std::shared_ptr<const TunnelConfig> config): Tunnel (config), m_Endpoint (true) {};
|
||||
void HandleTunnelDataMsg (std::shared_ptr<const I2NPMessage> msg);
|
||||
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg); // for zero-hops only
|
||||
size_t GetNumReceivedBytes () const { return m_Endpoint.GetNumReceivedBytes (); };
|
||||
void Print (std::stringstream& s) const;
|
||||
|
||||
private:
|
||||
protected:
|
||||
|
||||
TunnelEndpoint m_Endpoint;
|
||||
};
|
||||
|
||||
class ZeroHopsInboundTunnel: public InboundTunnel
|
||||
{
|
||||
public:
|
||||
|
||||
ZeroHopsInboundTunnel ();
|
||||
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg);
|
||||
void Print (std::stringstream& s) const;
|
||||
};
|
||||
|
||||
class Tunnels
|
||||
{
|
||||
|
|
|
@ -226,14 +226,13 @@ namespace tunnel
|
|||
TunnelHopConfig * m_FirstHop, * m_LastHop;
|
||||
};
|
||||
|
||||
class ZeroHopTunnelConfig: public TunnelConfig
|
||||
class ZeroHopsTunnelConfig: public TunnelConfig
|
||||
{
|
||||
public:
|
||||
|
||||
ZeroHopTunnelConfig (uint32_t tunnelID = 0): // 0 means outbound
|
||||
m_TunnelID (tunnelID) {};
|
||||
ZeroHopsTunnelConfig () { RAND_bytes ((uint8_t *)&m_TunnelID, 4);};
|
||||
|
||||
bool IsInbound () const { return m_TunnelID; };
|
||||
bool IsInbound () const { return true; }; // TODO:
|
||||
uint32_t GetTunnelID () const { return m_TunnelID; };
|
||||
uint32_t GetNextTunnelID () const { return m_TunnelID; };
|
||||
const i2p::data::IdentHash& GetNextIdentHash () const { return i2p::context.GetIdentHash (); };
|
||||
|
|
Loading…
Reference in a new issue