diff --git a/NetDb.cpp b/NetDb.cpp index c411096d..758ffb28 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -787,22 +787,22 @@ namespace data }); } - std::shared_ptr NetDb::GetRandomRouter (const RouterInfo * compatibleWith) const + std::shared_ptr NetDb::GetRandomRouter (std::shared_ptr compatibleWith) const { return GetRandomRouter ( [compatibleWith](std::shared_ptr router)->bool { - return !router->IsHidden () && router.get () != compatibleWith && + return !router->IsHidden () && router != compatibleWith && router->IsCompatible (*compatibleWith); }); } - std::shared_ptr NetDb::GetHighBandwidthRandomRouter (const RouterInfo * compatibleWith) const + std::shared_ptr NetDb::GetHighBandwidthRandomRouter (std::shared_ptr compatibleWith) const { return GetRandomRouter ( [compatibleWith](std::shared_ptr router)->bool { - return !router->IsHidden () && router.get () != compatibleWith && + return !router->IsHidden () && router != compatibleWith && router->IsCompatible (*compatibleWith) && (router->GetCaps () & RouterInfo::eHighBandwidth); }); } diff --git a/NetDb.h b/NetDb.h index a5bd2f04..a96c1806 100644 --- a/NetDb.h +++ b/NetDb.h @@ -76,8 +76,8 @@ namespace data void HandleDatabaseLookupMsg (I2NPMessage * msg); std::shared_ptr GetRandomRouter () const; - std::shared_ptr GetRandomRouter (const RouterInfo * compatibleWith) const; - std::shared_ptr GetHighBandwidthRandomRouter (const RouterInfo * compatibleWith) const; + std::shared_ptr GetRandomRouter (std::shared_ptr compatibleWith) const; + std::shared_ptr GetHighBandwidthRandomRouter (std::shared_ptr compatibleWith) const; void SetUnreachable (const IdentHash& ident, bool unreachable); void PostI2NPMsg (I2NPMessage * msg); diff --git a/Tunnel.cpp b/Tunnel.cpp index af26ab7f..e4270335 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -466,9 +466,9 @@ namespace tunnel if (!inboundTunnel) return; LogPrint ("Creating one hop outbound tunnel..."); CreateTunnel ( - new TunnelConfig (std::vector + new TunnelConfig (std::vector > { - i2p::data::netdb.GetRandomRouter ().get () + i2p::data::netdb.GetRandomRouter () }, inboundTunnel->GetTunnelConfig ())); } @@ -519,9 +519,9 @@ namespace tunnel // trying to create one more inbound tunnel LogPrint ("Creating one hop inbound tunnel..."); CreateTunnel ( - new TunnelConfig (std::vector + new TunnelConfig (std::vector > { - i2p::data::netdb.GetRandomRouter ().get () + i2p::data::netdb.GetRandomRouter () })); } } @@ -609,9 +609,9 @@ namespace tunnel void Tunnels::CreateZeroHopsInboundTunnel () { CreateTunnel ( - new TunnelConfig (std::vector + new TunnelConfig (std::vector > { - &i2p::context.GetRouterInfo () + i2p::context.GetSharedRouterInfo () })); } } diff --git a/Tunnel.h b/Tunnel.h index 919be76e..cf78e9c7 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -79,7 +79,7 @@ namespace tunnel void SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg); void SendTunnelDataMsg (const std::vector& msgs); // multiple messages - const i2p::data::RouterInfo * GetEndpointRouter () const + std::shared_ptr GetEndpointRouter () const { return GetTunnelConfig ()->GetLastHop ()->router; }; size_t GetNumSentBytes () const { return m_Gateway.GetNumSentBytes (); }; diff --git a/TunnelConfig.h b/TunnelConfig.h index 6d1732d5..e7910ce1 100644 --- a/TunnelConfig.h +++ b/TunnelConfig.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "aes.h" #include "RouterInfo.h" #include "RouterContext.h" @@ -14,7 +15,7 @@ namespace tunnel { struct TunnelHopConfig { - const i2p::data::RouterInfo * router, * nextRouter; + std::shared_ptr router, nextRouter; uint32_t tunnelID, nextTunnelID; uint8_t layerKey[32]; uint8_t ivKey[32]; @@ -26,7 +27,7 @@ namespace tunnel i2p::crypto::TunnelDecryption decryption; int recordIndex; // record # in tunnel build message - TunnelHopConfig (const i2p::data::RouterInfo * r) + TunnelHopConfig (std::shared_ptr r) { CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); rnd.GenerateBlock (layerKey, 32); @@ -36,14 +37,14 @@ namespace tunnel isGateway = true; isEndpoint = true; router = r; - nextRouter = 0; + //nextRouter = nullptr; nextTunnelID = 0; - next = 0; - prev = 0; + next = nullptr; + prev = nullptr; } - void SetNextRouter (const i2p::data::RouterInfo * r) + void SetNextRouter (std::shared_ptr r) { nextRouter = r; isEndpoint = false; @@ -88,7 +89,7 @@ namespace tunnel public: - TunnelConfig (std::vector peers, + TunnelConfig (std::vector > peers, const TunnelConfig * replyTunnelConfig = nullptr) // replyTunnelConfig=nullptr means inbound { TunnelHopConfig * prev = nullptr; @@ -109,7 +110,7 @@ namespace tunnel m_LastHop->SetReplyHop (replyTunnelConfig->GetFirstHop ()); } else // inbound - m_LastHop->SetNextRouter (&i2p::context.GetRouterInfo ()); + m_LastHop->SetNextRouter (i2p::context.GetSharedRouterInfo ()); } ~TunnelConfig () @@ -184,7 +185,7 @@ namespace tunnel if (hop->isGateway) // inbound tunnel newHop->SetReplyHop (m_FirstHop); // use it as reply tunnel else - newHop->SetNextRouter (&i2p::context.GetRouterInfo ()); + newHop->SetNextRouter (i2p::context.GetSharedRouterInfo ()); } if (!hop->next) newConfig->m_FirstHop = newHop; // last hop @@ -195,7 +196,7 @@ namespace tunnel TunnelConfig * Clone (const TunnelConfig * replyTunnelConfig = nullptr) const { - std::vector peers; + std::vector > peers; TunnelHopConfig * hop = m_FirstHop; while (hop) { diff --git a/TunnelPool.cpp b/TunnelPool.cpp index f2b741d0..338eac28 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -235,12 +235,12 @@ namespace tunnel m_LocalDestination.ProcessDeliveryStatusMessage (msg); } - const i2p::data::RouterInfo * TunnelPool::SelectNextHop (const i2p::data::RouterInfo * prevHop) const + std::shared_ptr TunnelPool::SelectNextHop (std::shared_ptr prevHop) const { - auto hop = m_NumHops >= 3 ? i2p::data::netdb.GetHighBandwidthRandomRouter (prevHop).get () : - i2p::data::netdb.GetRandomRouter (prevHop).get (); + auto hop = m_NumHops >= 3 ? i2p::data::netdb.GetHighBandwidthRandomRouter (prevHop) : + i2p::data::netdb.GetRandomRouter (prevHop); if (!hop) - hop = i2p::data::netdb.GetRandomRouter ().get (); + hop = i2p::data::netdb.GetRandomRouter (); return hop; } @@ -250,8 +250,8 @@ namespace tunnel if (!outboundTunnel) outboundTunnel = tunnels.GetNextOutboundTunnel (); LogPrint ("Creating destination inbound tunnel..."); - const i2p::data::RouterInfo * prevHop = &i2p::context.GetRouterInfo (); - std::vector hops; + auto prevHop = i2p::context.GetSharedRouterInfo (); + std::vector > hops; int numHops = m_NumHops; if (outboundTunnel) { @@ -294,8 +294,8 @@ namespace tunnel { LogPrint ("Creating destination outbound tunnel..."); - const i2p::data::RouterInfo * prevHop = &i2p::context.GetRouterInfo (); - std::vector hops; + auto prevHop = i2p::context.GetSharedRouterInfo (); + std::vector > hops; for (int i = 0; i < m_NumHops; i++) { auto hop = SelectNextHop (prevHop); diff --git a/TunnelPool.h b/TunnelPool.h index 76ba45d8..2423e3af 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -61,7 +61,7 @@ namespace tunnel template typename TTunnels::value_type GetNextTunnel (TTunnels& tunnels, typename TTunnels::value_type suggested = nullptr) const; - const i2p::data::RouterInfo * SelectNextHop (const i2p::data::RouterInfo * prevHop) const; + std::shared_ptr SelectNextHop (std::shared_ptr prevHop) const; private: