mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
short build message for re-created tunnels and far end transports
This commit is contained in:
parent
af133f4968
commit
e6bcd04a36
|
@ -67,6 +67,7 @@ namespace data
|
||||||
eSSUV6 = 0x08,
|
eSSUV6 = 0x08,
|
||||||
eNTCP2V6Mesh = 0x10
|
eNTCP2V6Mesh = 0x10
|
||||||
};
|
};
|
||||||
|
typedef uint8_t CompatibleTransports;
|
||||||
|
|
||||||
enum Caps
|
enum Caps
|
||||||
{
|
{
|
||||||
|
@ -207,7 +208,8 @@ namespace data
|
||||||
void DisableMesh ();
|
void DisableMesh ();
|
||||||
bool IsCompatible (const RouterInfo& other) const { return m_SupportedTransports & other.m_SupportedTransports; };
|
bool IsCompatible (const RouterInfo& other) const { return m_SupportedTransports & other.m_SupportedTransports; };
|
||||||
bool IsReachableFrom (const RouterInfo& other) const { return m_ReachableTransports & other.m_SupportedTransports; };
|
bool IsReachableFrom (const RouterInfo& other) const { return m_ReachableTransports & other.m_SupportedTransports; };
|
||||||
bool IsReachableBy (uint8_t transports) const { return m_ReachableTransports & transports; };
|
bool IsReachableBy (CompatibleTransports transports) const { return m_ReachableTransports & transports; };
|
||||||
|
CompatibleTransports GetCompatibleTransports (bool incoming) const { return incoming ? m_ReachableTransports : m_SupportedTransports; };
|
||||||
bool HasValidAddresses () const { return m_SupportedTransports; };
|
bool HasValidAddresses () const { return m_SupportedTransports; };
|
||||||
bool IsHidden () const { return m_Caps & eHidden; };
|
bool IsHidden () const { return m_Caps & eHidden; };
|
||||||
bool IsHighBandwidth () const { return m_Caps & RouterInfo::eHighBandwidth; };
|
bool IsHighBandwidth () const { return m_Caps & RouterInfo::eHighBandwidth; };
|
||||||
|
@ -273,7 +275,8 @@ namespace data
|
||||||
boost::shared_ptr<Addresses> m_Addresses; // TODO: use std::shared_ptr and std::atomic_store for gcc >= 4.9
|
boost::shared_ptr<Addresses> m_Addresses; // TODO: use std::shared_ptr and std::atomic_store for gcc >= 4.9
|
||||||
std::map<std::string, std::string> m_Properties;
|
std::map<std::string, std::string> m_Properties;
|
||||||
bool m_IsUpdated, m_IsUnreachable;
|
bool m_IsUpdated, m_IsUnreachable;
|
||||||
uint8_t m_SupportedTransports, m_ReachableTransports, m_Caps;
|
CompatibleTransports m_SupportedTransports, m_ReachableTransports;
|
||||||
|
uint8_t m_Caps;
|
||||||
int m_Version;
|
int m_Version;
|
||||||
mutable std::shared_ptr<RouterProfile> m_Profile;
|
mutable std::shared_ptr<RouterProfile> m_Profile;
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,8 +31,9 @@ namespace tunnel
|
||||||
{
|
{
|
||||||
Tunnel::Tunnel (std::shared_ptr<const TunnelConfig> config):
|
Tunnel::Tunnel (std::shared_ptr<const TunnelConfig> config):
|
||||||
TunnelBase (config->GetTunnelID (), config->GetNextTunnelID (), config->GetNextIdentHash ()),
|
TunnelBase (config->GetTunnelID (), config->GetNextTunnelID (), config->GetNextIdentHash ()),
|
||||||
m_Config (config), m_Pool (nullptr), m_State (eTunnelStatePending), m_IsRecreated (false),
|
m_Config (config), m_IsShortBuildMessage (false), m_Pool (nullptr),
|
||||||
m_Latency (0)
|
m_State (eTunnelStatePending), m_FarEndTransports (0),
|
||||||
|
m_IsRecreated (false), m_Latency (0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,6 +181,8 @@ namespace tunnel
|
||||||
m_Hops.push_back (std::unique_ptr<TunnelHop>(tunnelHop));
|
m_Hops.push_back (std::unique_ptr<TunnelHop>(tunnelHop));
|
||||||
hop = hop->prev;
|
hop = hop->prev;
|
||||||
}
|
}
|
||||||
|
m_IsShortBuildMessage = m_Config->IsShort ();
|
||||||
|
m_FarEndTransports = m_Config->GetFarEndTransports ();
|
||||||
m_Config = nullptr;
|
m_Config = nullptr;
|
||||||
}
|
}
|
||||||
if (established) m_State = eTunnelStateEstablished;
|
if (established) m_State = eTunnelStateEstablished;
|
||||||
|
@ -715,7 +718,7 @@ namespace tunnel
|
||||||
LogPrint (eLogDebug, "Tunnel: creating one hop outbound tunnel");
|
LogPrint (eLogDebug, "Tunnel: creating one hop outbound tunnel");
|
||||||
CreateTunnel<OutboundTunnel> (
|
CreateTunnel<OutboundTunnel> (
|
||||||
std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> > { router->GetRouterIdentity () },
|
std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> > { router->GetRouterIdentity () },
|
||||||
inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash ()), nullptr
|
inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash (), false), nullptr
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -791,7 +794,7 @@ namespace tunnel
|
||||||
}
|
}
|
||||||
LogPrint (eLogDebug, "Tunnel: creating one hop inbound tunnel");
|
LogPrint (eLogDebug, "Tunnel: creating one hop inbound tunnel");
|
||||||
CreateTunnel<InboundTunnel> (
|
CreateTunnel<InboundTunnel> (
|
||||||
std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> > { router->GetRouterIdentity () }), nullptr
|
std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> > { router->GetRouterIdentity () }, false), nullptr
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -897,7 +900,7 @@ namespace tunnel
|
||||||
{
|
{
|
||||||
// build symmetric outbound tunnel
|
// build symmetric outbound tunnel
|
||||||
CreateTunnel<OutboundTunnel> (std::make_shared<TunnelConfig>(newTunnel->GetInvertedPeers (),
|
CreateTunnel<OutboundTunnel> (std::make_shared<TunnelConfig>(newTunnel->GetInvertedPeers (),
|
||||||
newTunnel->GetNextTunnelID (), newTunnel->GetNextIdentHash ()), nullptr,
|
newTunnel->GetNextTunnelID (), newTunnel->GetNextIdentHash (), false), nullptr,
|
||||||
GetNextOutboundTunnel ());
|
GetNextOutboundTunnel ());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -71,6 +71,7 @@ namespace tunnel
|
||||||
std::shared_ptr<const TunnelConfig> GetTunnelConfig () const { return m_Config; }
|
std::shared_ptr<const TunnelConfig> GetTunnelConfig () const { return m_Config; }
|
||||||
std::vector<std::shared_ptr<const i2p::data::IdentityEx> > GetPeers () const;
|
std::vector<std::shared_ptr<const i2p::data::IdentityEx> > GetPeers () const;
|
||||||
std::vector<std::shared_ptr<const i2p::data::IdentityEx> > GetInvertedPeers () const;
|
std::vector<std::shared_ptr<const i2p::data::IdentityEx> > GetInvertedPeers () const;
|
||||||
|
bool IsShortBuildMessage () const { return m_IsShortBuildMessage; };
|
||||||
TunnelState GetState () const { return m_State; };
|
TunnelState GetState () const { return m_State; };
|
||||||
void SetState (TunnelState state);
|
void SetState (TunnelState state);
|
||||||
bool IsEstablished () const { return m_State == eTunnelStateEstablished; };
|
bool IsEstablished () const { return m_State == eTunnelStateEstablished; };
|
||||||
|
@ -109,8 +110,10 @@ namespace tunnel
|
||||||
|
|
||||||
std::shared_ptr<const TunnelConfig> m_Config;
|
std::shared_ptr<const TunnelConfig> m_Config;
|
||||||
std::vector<std::unique_ptr<TunnelHop> > m_Hops;
|
std::vector<std::unique_ptr<TunnelHop> > m_Hops;
|
||||||
|
bool m_IsShortBuildMessage;
|
||||||
std::shared_ptr<TunnelPool> m_Pool; // pool, tunnel belongs to, or null
|
std::shared_ptr<TunnelPool> m_Pool; // pool, tunnel belongs to, or null
|
||||||
TunnelState m_State;
|
TunnelState m_State;
|
||||||
|
i2p::data::RouterInfo::CompatibleTransports m_FarEndTransports;
|
||||||
bool m_IsRecreated; // if tunnel is replaced by new, or new tunnel requested to replace
|
bool m_IsRecreated; // if tunnel is replaced by new, or new tunnel requested to replace
|
||||||
uint64_t m_Latency; // in milliseconds
|
uint64_t m_Latency; // in milliseconds
|
||||||
};
|
};
|
||||||
|
|
|
@ -82,16 +82,17 @@ namespace tunnel
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TunnelConfig (const std::vector<std::shared_ptr<const i2p::data::IdentityEx> >& peers,
|
TunnelConfig (const std::vector<std::shared_ptr<const i2p::data::IdentityEx> >& peers,
|
||||||
bool isShort = false): // inbound
|
bool isShort, i2p::data::RouterInfo::CompatibleTransports farEndTransports = 0): // inbound
|
||||||
m_IsShort (isShort)
|
m_IsShort (isShort), m_FarEndTransports (farEndTransports)
|
||||||
{
|
{
|
||||||
CreatePeers (peers);
|
CreatePeers (peers);
|
||||||
m_LastHop->SetNextIdent (i2p::context.GetIdentHash ());
|
m_LastHop->SetNextIdent (i2p::context.GetIdentHash ());
|
||||||
}
|
}
|
||||||
|
|
||||||
TunnelConfig (const std::vector<std::shared_ptr<const i2p::data::IdentityEx> >& peers,
|
TunnelConfig (const std::vector<std::shared_ptr<const i2p::data::IdentityEx> >& peers,
|
||||||
uint32_t replyTunnelID, const i2p::data::IdentHash& replyIdent, bool isShort = false): // outbound
|
uint32_t replyTunnelID, const i2p::data::IdentHash& replyIdent, bool isShort,
|
||||||
m_IsShort (isShort)
|
i2p::data::RouterInfo::CompatibleTransports farEndTransports = 0): // outbound
|
||||||
|
m_IsShort (isShort), m_FarEndTransports (farEndTransports)
|
||||||
{
|
{
|
||||||
CreatePeers (peers);
|
CreatePeers (peers);
|
||||||
m_FirstHop->isGateway = false;
|
m_FirstHop->isGateway = false;
|
||||||
|
@ -112,6 +113,11 @@ namespace tunnel
|
||||||
|
|
||||||
bool IsShort () const { return m_IsShort; }
|
bool IsShort () const { return m_IsShort; }
|
||||||
|
|
||||||
|
i2p::data::RouterInfo::CompatibleTransports GetFarEndTransports () const
|
||||||
|
{
|
||||||
|
return m_FarEndTransports;
|
||||||
|
}
|
||||||
|
|
||||||
TunnelHopConfig * GetFirstHop () const
|
TunnelHopConfig * GetFirstHop () const
|
||||||
{
|
{
|
||||||
return m_FirstHop;
|
return m_FirstHop;
|
||||||
|
@ -178,7 +184,8 @@ namespace tunnel
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// this constructor can't be called from outside
|
// this constructor can't be called from outside
|
||||||
TunnelConfig (): m_FirstHop (nullptr), m_LastHop (nullptr), m_IsShort (false)
|
TunnelConfig (): m_FirstHop (nullptr), m_LastHop (nullptr), m_IsShort (false),
|
||||||
|
m_FarEndTransports (0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,6 +197,7 @@ namespace tunnel
|
||||||
|
|
||||||
TunnelHopConfig * m_FirstHop, * m_LastHop;
|
TunnelHopConfig * m_FirstHop, * m_LastHop;
|
||||||
bool m_IsShort;
|
bool m_IsShort;
|
||||||
|
i2p::data::RouterInfo::CompatibleTransports m_FarEndTransports;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ZeroHopsTunnelConfig: public TunnelConfig
|
class ZeroHopsTunnelConfig: public TunnelConfig
|
||||||
|
|
|
@ -495,6 +495,8 @@ namespace tunnel
|
||||||
}
|
}
|
||||||
prevHop = hop;
|
prevHop = hop;
|
||||||
path.Add (hop);
|
path.Add (hop);
|
||||||
|
if (i == numHops - 1)
|
||||||
|
path.farEndTransports = hop->GetCompatibleTransports (inbound);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -527,7 +529,11 @@ namespace tunnel
|
||||||
if (r)
|
if (r)
|
||||||
{
|
{
|
||||||
if (r->IsECIES ())
|
if (r->IsECIES ())
|
||||||
|
{
|
||||||
path.Add (r);
|
path.Add (r);
|
||||||
|
if (i == numHops - 1)
|
||||||
|
path.farEndTransports = r->GetCompatibleTransports (isInbound);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogPrint (eLogError, "Tunnels: ElGamal router ", ident.ToBase64 (), " is not supported");
|
LogPrint (eLogError, "Tunnels: ElGamal router ", ident.ToBase64 (), " is not supported");
|
||||||
|
@ -557,7 +563,7 @@ namespace tunnel
|
||||||
if (m_NumInboundHops > 0)
|
if (m_NumInboundHops > 0)
|
||||||
{
|
{
|
||||||
path.Reverse ();
|
path.Reverse ();
|
||||||
config = std::make_shared<TunnelConfig> (path.peers, path.isShort);
|
config = std::make_shared<TunnelConfig> (path.peers, path.isShort, path.farEndTransports);
|
||||||
}
|
}
|
||||||
auto tunnel = tunnels.CreateInboundTunnel (config, shared_from_this (), outboundTunnel);
|
auto tunnel = tunnels.CreateInboundTunnel (config, shared_from_this (), outboundTunnel);
|
||||||
if (tunnel->IsEstablished ()) // zero hops
|
if (tunnel->IsEstablished ()) // zero hops
|
||||||
|
@ -581,7 +587,7 @@ namespace tunnel
|
||||||
std::shared_ptr<TunnelConfig> config;
|
std::shared_ptr<TunnelConfig> config;
|
||||||
if (m_NumInboundHops > 0 && tunnel->GetPeers().size())
|
if (m_NumInboundHops > 0 && tunnel->GetPeers().size())
|
||||||
{
|
{
|
||||||
config = std::make_shared<TunnelConfig>(tunnel->GetPeers ());
|
config = std::make_shared<TunnelConfig>(tunnel->GetPeers (), tunnel->IsShortBuildMessage ());
|
||||||
}
|
}
|
||||||
if (!m_NumInboundHops || config)
|
if (!m_NumInboundHops || config)
|
||||||
{
|
{
|
||||||
|
@ -606,7 +612,8 @@ namespace tunnel
|
||||||
{
|
{
|
||||||
std::shared_ptr<TunnelConfig> config;
|
std::shared_ptr<TunnelConfig> config;
|
||||||
if (m_NumOutboundHops > 0)
|
if (m_NumOutboundHops > 0)
|
||||||
config = std::make_shared<TunnelConfig>(path.peers, inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash (), path.isShort);
|
config = std::make_shared<TunnelConfig>(path.peers, inboundTunnel->GetNextTunnelID (),
|
||||||
|
inboundTunnel->GetNextIdentHash (), path.isShort, path.farEndTransports);
|
||||||
|
|
||||||
std::shared_ptr<OutboundTunnel> tunnel;
|
std::shared_ptr<OutboundTunnel> tunnel;
|
||||||
if (path.isShort)
|
if (path.isShort)
|
||||||
|
@ -643,7 +650,8 @@ namespace tunnel
|
||||||
std::shared_ptr<TunnelConfig> config;
|
std::shared_ptr<TunnelConfig> config;
|
||||||
if (m_NumOutboundHops > 0 && tunnel->GetPeers().size())
|
if (m_NumOutboundHops > 0 && tunnel->GetPeers().size())
|
||||||
{
|
{
|
||||||
config = std::make_shared<TunnelConfig>(tunnel->GetPeers (), inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash ());
|
config = std::make_shared<TunnelConfig>(tunnel->GetPeers (), inboundTunnel->GetNextTunnelID (),
|
||||||
|
inboundTunnel->GetNextIdentHash (), inboundTunnel->IsShortBuildMessage ());
|
||||||
}
|
}
|
||||||
if (!m_NumOutboundHops || config)
|
if (!m_NumOutboundHops || config)
|
||||||
{
|
{
|
||||||
|
@ -660,7 +668,8 @@ namespace tunnel
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "Tunnels: Creating paired inbound tunnel...");
|
LogPrint (eLogDebug, "Tunnels: Creating paired inbound tunnel...");
|
||||||
auto tunnel = tunnels.CreateInboundTunnel (
|
auto tunnel = tunnels.CreateInboundTunnel (
|
||||||
m_NumOutboundHops > 0 ? std::make_shared<TunnelConfig>(outboundTunnel->GetInvertedPeers ()) : nullptr,
|
m_NumOutboundHops > 0 ? std::make_shared<TunnelConfig>(outboundTunnel->GetInvertedPeers (),
|
||||||
|
outboundTunnel->IsShortBuildMessage ()) : nullptr,
|
||||||
shared_from_this (), outboundTunnel);
|
shared_from_this (), outboundTunnel);
|
||||||
if (tunnel->IsEstablished ()) // zero hops
|
if (tunnel->IsEstablished ()) // zero hops
|
||||||
TunnelCreated (tunnel);
|
TunnelCreated (tunnel);
|
||||||
|
|
|
@ -40,6 +40,7 @@ namespace tunnel
|
||||||
{
|
{
|
||||||
std::vector<Peer> peers;
|
std::vector<Peer> peers;
|
||||||
bool isShort = true;
|
bool isShort = true;
|
||||||
|
i2p::data::RouterInfo::CompatibleTransports farEndTransports = 0;
|
||||||
|
|
||||||
void Add (std::shared_ptr<const i2p::data::RouterInfo> r);
|
void Add (std::shared_ptr<const i2p::data::RouterInfo> r);
|
||||||
void Reverse ();
|
void Reverse ();
|
||||||
|
|
Loading…
Reference in a new issue