mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-23 05:06:31 +00:00
store shared pointer to RI in tunnel config
This commit is contained in:
parent
5187701af1
commit
8a357ac46c
@ -787,22 +787,22 @@ namespace data
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<const RouterInfo> NetDb::GetRandomRouter (const RouterInfo * compatibleWith) const
|
std::shared_ptr<const RouterInfo> NetDb::GetRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const
|
||||||
{
|
{
|
||||||
return GetRandomRouter (
|
return GetRandomRouter (
|
||||||
[compatibleWith](std::shared_ptr<const RouterInfo> router)->bool
|
[compatibleWith](std::shared_ptr<const RouterInfo> router)->bool
|
||||||
{
|
{
|
||||||
return !router->IsHidden () && router.get () != compatibleWith &&
|
return !router->IsHidden () && router != compatibleWith &&
|
||||||
router->IsCompatible (*compatibleWith);
|
router->IsCompatible (*compatibleWith);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<const RouterInfo> NetDb::GetHighBandwidthRandomRouter (const RouterInfo * compatibleWith) const
|
std::shared_ptr<const RouterInfo> NetDb::GetHighBandwidthRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const
|
||||||
{
|
{
|
||||||
return GetRandomRouter (
|
return GetRandomRouter (
|
||||||
[compatibleWith](std::shared_ptr<const RouterInfo> router)->bool
|
[compatibleWith](std::shared_ptr<const RouterInfo> router)->bool
|
||||||
{
|
{
|
||||||
return !router->IsHidden () && router.get () != compatibleWith &&
|
return !router->IsHidden () && router != compatibleWith &&
|
||||||
router->IsCompatible (*compatibleWith) && (router->GetCaps () & RouterInfo::eHighBandwidth);
|
router->IsCompatible (*compatibleWith) && (router->GetCaps () & RouterInfo::eHighBandwidth);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
4
NetDb.h
4
NetDb.h
@ -76,8 +76,8 @@ namespace data
|
|||||||
void HandleDatabaseLookupMsg (I2NPMessage * msg);
|
void HandleDatabaseLookupMsg (I2NPMessage * msg);
|
||||||
|
|
||||||
std::shared_ptr<const RouterInfo> GetRandomRouter () const;
|
std::shared_ptr<const RouterInfo> GetRandomRouter () const;
|
||||||
std::shared_ptr<const RouterInfo> GetRandomRouter (const RouterInfo * compatibleWith) const;
|
std::shared_ptr<const RouterInfo> GetRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const;
|
||||||
std::shared_ptr<const RouterInfo> GetHighBandwidthRandomRouter (const RouterInfo * compatibleWith) const;
|
std::shared_ptr<const RouterInfo> GetHighBandwidthRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const;
|
||||||
void SetUnreachable (const IdentHash& ident, bool unreachable);
|
void SetUnreachable (const IdentHash& ident, bool unreachable);
|
||||||
|
|
||||||
void PostI2NPMsg (I2NPMessage * msg);
|
void PostI2NPMsg (I2NPMessage * msg);
|
||||||
|
12
Tunnel.cpp
12
Tunnel.cpp
@ -466,9 +466,9 @@ namespace tunnel
|
|||||||
if (!inboundTunnel) return;
|
if (!inboundTunnel) return;
|
||||||
LogPrint ("Creating one hop outbound tunnel...");
|
LogPrint ("Creating one hop outbound tunnel...");
|
||||||
CreateTunnel<OutboundTunnel> (
|
CreateTunnel<OutboundTunnel> (
|
||||||
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
new TunnelConfig (std::vector<std::shared_ptr<const i2p::data::RouterInfo> >
|
||||||
{
|
{
|
||||||
i2p::data::netdb.GetRandomRouter ().get ()
|
i2p::data::netdb.GetRandomRouter ()
|
||||||
},
|
},
|
||||||
inboundTunnel->GetTunnelConfig ()));
|
inboundTunnel->GetTunnelConfig ()));
|
||||||
}
|
}
|
||||||
@ -519,9 +519,9 @@ namespace tunnel
|
|||||||
// trying to create one more inbound tunnel
|
// trying to create one more inbound tunnel
|
||||||
LogPrint ("Creating one hop inbound tunnel...");
|
LogPrint ("Creating one hop inbound tunnel...");
|
||||||
CreateTunnel<InboundTunnel> (
|
CreateTunnel<InboundTunnel> (
|
||||||
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
new TunnelConfig (std::vector<std::shared_ptr<const i2p::data::RouterInfo> >
|
||||||
{
|
{
|
||||||
i2p::data::netdb.GetRandomRouter ().get ()
|
i2p::data::netdb.GetRandomRouter ()
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -609,9 +609,9 @@ namespace tunnel
|
|||||||
void Tunnels::CreateZeroHopsInboundTunnel ()
|
void Tunnels::CreateZeroHopsInboundTunnel ()
|
||||||
{
|
{
|
||||||
CreateTunnel<InboundTunnel> (
|
CreateTunnel<InboundTunnel> (
|
||||||
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
new TunnelConfig (std::vector<std::shared_ptr<const i2p::data::RouterInfo> >
|
||||||
{
|
{
|
||||||
&i2p::context.GetRouterInfo ()
|
i2p::context.GetSharedRouterInfo ()
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
Tunnel.h
2
Tunnel.h
@ -79,7 +79,7 @@ namespace tunnel
|
|||||||
|
|
||||||
void SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg);
|
void SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg);
|
||||||
void SendTunnelDataMsg (const std::vector<TunnelMessageBlock>& msgs); // multiple messages
|
void SendTunnelDataMsg (const std::vector<TunnelMessageBlock>& msgs); // multiple messages
|
||||||
const i2p::data::RouterInfo * GetEndpointRouter () const
|
std::shared_ptr<const i2p::data::RouterInfo> GetEndpointRouter () const
|
||||||
{ return GetTunnelConfig ()->GetLastHop ()->router; };
|
{ return GetTunnelConfig ()->GetLastHop ()->router; };
|
||||||
size_t GetNumSentBytes () const { return m_Gateway.GetNumSentBytes (); };
|
size_t GetNumSentBytes () const { return m_Gateway.GetNumSentBytes (); };
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
#include "aes.h"
|
#include "aes.h"
|
||||||
#include "RouterInfo.h"
|
#include "RouterInfo.h"
|
||||||
#include "RouterContext.h"
|
#include "RouterContext.h"
|
||||||
@ -14,7 +15,7 @@ namespace tunnel
|
|||||||
{
|
{
|
||||||
struct TunnelHopConfig
|
struct TunnelHopConfig
|
||||||
{
|
{
|
||||||
const i2p::data::RouterInfo * router, * nextRouter;
|
std::shared_ptr<const i2p::data::RouterInfo> router, nextRouter;
|
||||||
uint32_t tunnelID, nextTunnelID;
|
uint32_t tunnelID, nextTunnelID;
|
||||||
uint8_t layerKey[32];
|
uint8_t layerKey[32];
|
||||||
uint8_t ivKey[32];
|
uint8_t ivKey[32];
|
||||||
@ -26,7 +27,7 @@ namespace tunnel
|
|||||||
i2p::crypto::TunnelDecryption decryption;
|
i2p::crypto::TunnelDecryption decryption;
|
||||||
int recordIndex; // record # in tunnel build message
|
int recordIndex; // record # in tunnel build message
|
||||||
|
|
||||||
TunnelHopConfig (const i2p::data::RouterInfo * r)
|
TunnelHopConfig (std::shared_ptr<const i2p::data::RouterInfo> r)
|
||||||
{
|
{
|
||||||
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
|
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
|
||||||
rnd.GenerateBlock (layerKey, 32);
|
rnd.GenerateBlock (layerKey, 32);
|
||||||
@ -36,14 +37,14 @@ namespace tunnel
|
|||||||
isGateway = true;
|
isGateway = true;
|
||||||
isEndpoint = true;
|
isEndpoint = true;
|
||||||
router = r;
|
router = r;
|
||||||
nextRouter = 0;
|
//nextRouter = nullptr;
|
||||||
nextTunnelID = 0;
|
nextTunnelID = 0;
|
||||||
|
|
||||||
next = 0;
|
next = nullptr;
|
||||||
prev = 0;
|
prev = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetNextRouter (const i2p::data::RouterInfo * r)
|
void SetNextRouter (std::shared_ptr<const i2p::data::RouterInfo> r)
|
||||||
{
|
{
|
||||||
nextRouter = r;
|
nextRouter = r;
|
||||||
isEndpoint = false;
|
isEndpoint = false;
|
||||||
@ -88,7 +89,7 @@ namespace tunnel
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
TunnelConfig (std::vector<const i2p::data::RouterInfo *> peers,
|
TunnelConfig (std::vector<std::shared_ptr<const i2p::data::RouterInfo> > peers,
|
||||||
const TunnelConfig * replyTunnelConfig = nullptr) // replyTunnelConfig=nullptr means inbound
|
const TunnelConfig * replyTunnelConfig = nullptr) // replyTunnelConfig=nullptr means inbound
|
||||||
{
|
{
|
||||||
TunnelHopConfig * prev = nullptr;
|
TunnelHopConfig * prev = nullptr;
|
||||||
@ -109,7 +110,7 @@ namespace tunnel
|
|||||||
m_LastHop->SetReplyHop (replyTunnelConfig->GetFirstHop ());
|
m_LastHop->SetReplyHop (replyTunnelConfig->GetFirstHop ());
|
||||||
}
|
}
|
||||||
else // inbound
|
else // inbound
|
||||||
m_LastHop->SetNextRouter (&i2p::context.GetRouterInfo ());
|
m_LastHop->SetNextRouter (i2p::context.GetSharedRouterInfo ());
|
||||||
}
|
}
|
||||||
|
|
||||||
~TunnelConfig ()
|
~TunnelConfig ()
|
||||||
@ -184,7 +185,7 @@ namespace tunnel
|
|||||||
if (hop->isGateway) // inbound tunnel
|
if (hop->isGateway) // inbound tunnel
|
||||||
newHop->SetReplyHop (m_FirstHop); // use it as reply tunnel
|
newHop->SetReplyHop (m_FirstHop); // use it as reply tunnel
|
||||||
else
|
else
|
||||||
newHop->SetNextRouter (&i2p::context.GetRouterInfo ());
|
newHop->SetNextRouter (i2p::context.GetSharedRouterInfo ());
|
||||||
}
|
}
|
||||||
if (!hop->next) newConfig->m_FirstHop = newHop; // last hop
|
if (!hop->next) newConfig->m_FirstHop = newHop; // last hop
|
||||||
|
|
||||||
@ -195,7 +196,7 @@ namespace tunnel
|
|||||||
|
|
||||||
TunnelConfig * Clone (const TunnelConfig * replyTunnelConfig = nullptr) const
|
TunnelConfig * Clone (const TunnelConfig * replyTunnelConfig = nullptr) const
|
||||||
{
|
{
|
||||||
std::vector<const i2p::data::RouterInfo *> peers;
|
std::vector<std::shared_ptr<const i2p::data::RouterInfo> > peers;
|
||||||
TunnelHopConfig * hop = m_FirstHop;
|
TunnelHopConfig * hop = m_FirstHop;
|
||||||
while (hop)
|
while (hop)
|
||||||
{
|
{
|
||||||
|
@ -235,12 +235,12 @@ namespace tunnel
|
|||||||
m_LocalDestination.ProcessDeliveryStatusMessage (msg);
|
m_LocalDestination.ProcessDeliveryStatusMessage (msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
const i2p::data::RouterInfo * TunnelPool::SelectNextHop (const i2p::data::RouterInfo * prevHop) const
|
std::shared_ptr<const i2p::data::RouterInfo> TunnelPool::SelectNextHop (std::shared_ptr<const i2p::data::RouterInfo> prevHop) const
|
||||||
{
|
{
|
||||||
auto hop = m_NumHops >= 3 ? i2p::data::netdb.GetHighBandwidthRandomRouter (prevHop).get () :
|
auto hop = m_NumHops >= 3 ? i2p::data::netdb.GetHighBandwidthRandomRouter (prevHop) :
|
||||||
i2p::data::netdb.GetRandomRouter (prevHop).get ();
|
i2p::data::netdb.GetRandomRouter (prevHop);
|
||||||
if (!hop)
|
if (!hop)
|
||||||
hop = i2p::data::netdb.GetRandomRouter ().get ();
|
hop = i2p::data::netdb.GetRandomRouter ();
|
||||||
return hop;
|
return hop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,8 +250,8 @@ namespace tunnel
|
|||||||
if (!outboundTunnel)
|
if (!outboundTunnel)
|
||||||
outboundTunnel = tunnels.GetNextOutboundTunnel ();
|
outboundTunnel = tunnels.GetNextOutboundTunnel ();
|
||||||
LogPrint ("Creating destination inbound tunnel...");
|
LogPrint ("Creating destination inbound tunnel...");
|
||||||
const i2p::data::RouterInfo * prevHop = &i2p::context.GetRouterInfo ();
|
auto prevHop = i2p::context.GetSharedRouterInfo ();
|
||||||
std::vector<const i2p::data::RouterInfo *> hops;
|
std::vector<std::shared_ptr<const i2p::data::RouterInfo> > hops;
|
||||||
int numHops = m_NumHops;
|
int numHops = m_NumHops;
|
||||||
if (outboundTunnel)
|
if (outboundTunnel)
|
||||||
{
|
{
|
||||||
@ -294,8 +294,8 @@ namespace tunnel
|
|||||||
{
|
{
|
||||||
LogPrint ("Creating destination outbound tunnel...");
|
LogPrint ("Creating destination outbound tunnel...");
|
||||||
|
|
||||||
const i2p::data::RouterInfo * prevHop = &i2p::context.GetRouterInfo ();
|
auto prevHop = i2p::context.GetSharedRouterInfo ();
|
||||||
std::vector<const i2p::data::RouterInfo *> hops;
|
std::vector<std::shared_ptr<const i2p::data::RouterInfo> > hops;
|
||||||
for (int i = 0; i < m_NumHops; i++)
|
for (int i = 0; i < m_NumHops; i++)
|
||||||
{
|
{
|
||||||
auto hop = SelectNextHop (prevHop);
|
auto hop = SelectNextHop (prevHop);
|
||||||
|
@ -61,7 +61,7 @@ namespace tunnel
|
|||||||
template<class TTunnels>
|
template<class TTunnels>
|
||||||
typename TTunnels::value_type GetNextTunnel (TTunnels& tunnels,
|
typename TTunnels::value_type GetNextTunnel (TTunnels& tunnels,
|
||||||
typename TTunnels::value_type suggested = nullptr) const;
|
typename TTunnels::value_type suggested = nullptr) const;
|
||||||
const i2p::data::RouterInfo * SelectNextHop (const i2p::data::RouterInfo * prevHop) const;
|
std::shared_ptr<const i2p::data::RouterInfo> SelectNextHop (std::shared_ptr<const i2p::data::RouterInfo> prevHop) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user