From bbe403fb408f3e23cd703ef79204dd1676c59b48 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 25 Dec 2014 21:13:51 -0500 Subject: [PATCH] main netdb can request router info only --- Destination.cpp | 2 +- NetDb.cpp | 89 ++++++++++++++----------------------------------- NetDb.h | 14 ++++---- SAM.cpp | 2 +- SOCKS.cpp | 2 +- api.cpp | 2 +- 6 files changed, 35 insertions(+), 76 deletions(-) diff --git a/Destination.cpp b/Destination.cpp index 7fa9e9f4..85f7b426 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -124,7 +124,7 @@ namespace client else { LogPrint ("All leases of remote LeaseSet expired. Request it"); - i2p::data::netdb.RequestDestination (ident, true, m_Pool); + RequestDestination (ident); } } else diff --git a/NetDb.cpp b/NetDb.cpp index 8848f692..0fa7e072 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -26,14 +26,7 @@ namespace data { I2NPMessage * msg = i2p::CreateDatabaseLookupMsg (m_Destination, replyTunnel->GetNextIdentHash (), replyTunnel->GetNextTunnelID (), m_IsExploratory, - &m_ExcludedPeers, m_IsLeaseSet, m_Pool); - if (m_IsLeaseSet) // wrap lookup message into garlic - { - if (m_Pool && m_Pool->GetLocalDestination ()) - msg = m_Pool->GetLocalDestination ()->WrapMessage (*router, msg); - else - LogPrint ("Can't create garlic message without destination"); - } + &m_ExcludedPeers, false, m_Pool); m_ExcludedPeers.insert (router->GetIdentHash ()); m_LastRouter = router; m_CreationTime = i2p::util::GetSecondsSinceEpoch (); @@ -62,7 +55,7 @@ namespace data #endif NetDb netdb; - NetDb::NetDb (): m_IsRunning (false), m_Thread (0) + NetDb::NetDb (): m_IsRunning (false), m_Thread (nullptr) { } @@ -413,46 +406,17 @@ namespace data } } - void NetDb::RequestDestination (const IdentHash& destination, bool isLeaseSet, i2p::tunnel::TunnelPool * pool) + void NetDb::RequestDestination (const IdentHash& destination, i2p::tunnel::TunnelPool * pool) { - if (isLeaseSet) // we request LeaseSet through tunnels - { - i2p::tunnel::OutboundTunnel * outbound = pool ? pool->GetNextOutboundTunnel () : i2p::tunnel::tunnels.GetNextOutboundTunnel (); - if (outbound) - { - i2p::tunnel::InboundTunnel * inbound = pool ? pool->GetNextInboundTunnel () :i2p::tunnel::tunnels.GetNextInboundTunnel (); - if (inbound) - { - RequestedDestination * dest = CreateRequestedDestination (destination, true, false, pool); - auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ()); - if (floodfill) - { - // DatabaseLookup message - outbound->SendTunnelDataMsg ( - { - i2p::tunnel::TunnelMessageBlock - { - i2p::tunnel::eDeliveryTypeRouter, - floodfill->GetIdentHash (), 0, - dest->CreateRequestMessage (floodfill, inbound) - } - }); - } - else - LogPrint ("No more floodfills found"); - } - else - LogPrint ("No inbound tunnels found"); - } - else - LogPrint ("No outbound tunnels found"); - } - else // RouterInfo is requested directly + // request RouterInfo directly + RequestedDestination * dest = CreateRequestedDestination (destination, false, pool); + auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ()); + if (floodfill) + transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ())); + else { - RequestedDestination * dest = CreateRequestedDestination (destination, false, false, pool); - auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ()); - if (floodfill) - transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ())); + LogPrint (eLogError, "No floodfills found"); + DeleteRequestedDestination (dest); } } @@ -519,17 +483,14 @@ namespace data { auto nextFloodfill = GetClosestFloodfill (dest->GetDestination (), dest->GetExcludedPeers ()); if (nextFloodfill) - { - if (!dest->IsLeaseSet ()) - { - // tell floodfill about us - msgs.push_back (i2p::tunnel::TunnelMessageBlock - { - i2p::tunnel::eDeliveryTypeRouter, - nextFloodfill->GetIdentHash (), 0, - CreateDatabaseStoreMsg () - }); - } + { + // tell floodfill about us + msgs.push_back (i2p::tunnel::TunnelMessageBlock + { + i2p::tunnel::eDeliveryTypeRouter, + nextFloodfill->GetIdentHash (), 0, + CreateDatabaseStoreMsg () + }); // request destination LogPrint ("Try ", key, " at ", count, " floodfill ", nextFloodfill->GetIdentHash ().ToBase64 ()); @@ -564,7 +525,7 @@ namespace data LogPrint ("Found new/outdated router. Requesting RouterInfo ..."); if (outbound && inbound && dest->GetLastRouter ()) { - RequestedDestination * d1 = CreateRequestedDestination (router, false, false, pool); + RequestedDestination * d1 = CreateRequestedDestination (router, false, pool); auto msg = d1->CreateRequestMessage (dest->GetLastRouter (), inbound); msgs.push_back (i2p::tunnel::TunnelMessageBlock { @@ -573,7 +534,7 @@ namespace data }); } else - RequestDestination (router, false, pool); + RequestDestination (router, pool); } else LogPrint ("Bayan"); @@ -586,7 +547,7 @@ namespace data { // request router LogPrint ("Found new floodfill. Request it"); - RequestDestination (router, false, pool); + RequestDestination (router, pool); } } } @@ -728,7 +689,7 @@ namespace data for (int i = 0; i < numDestinations; i++) { rnd.GenerateBlock (randomHash, 32); - RequestedDestination * dest = CreateRequestedDestination (IdentHash (randomHash), false, true, exploratoryPool); + RequestedDestination * dest = CreateRequestedDestination (IdentHash (randomHash), true, exploratoryPool); auto floodfill = GetClosestFloodfill (randomHash, dest->GetExcludedPeers ()); if (floodfill && !floodfills.count (floodfill.get ())) // request floodfill only once { @@ -774,13 +735,13 @@ namespace data } RequestedDestination * NetDb::CreateRequestedDestination (const IdentHash& dest, - bool isLeaseSet, bool isExploratory, i2p::tunnel::TunnelPool * pool) + bool isExploratory, i2p::tunnel::TunnelPool * pool) { std::unique_lock l(m_RequestedDestinationsMutex); auto it = m_RequestedDestinations.find (dest); if (it == m_RequestedDestinations.end ()) // not exist yet { - RequestedDestination * d = new RequestedDestination (dest, isLeaseSet, isExploratory, pool); + RequestedDestination * d = new RequestedDestination (dest, isExploratory, pool); m_RequestedDestinations[dest] = d; return d; } diff --git a/NetDb.h b/NetDb.h index ae21e6ce..095f14b3 100644 --- a/NetDb.h +++ b/NetDb.h @@ -24,9 +24,9 @@ namespace data { public: - RequestedDestination (const IdentHash& destination, bool isLeaseSet, - bool isExploratory = false, i2p::tunnel::TunnelPool * pool = nullptr): - m_Destination (destination), m_IsLeaseSet (isLeaseSet), m_IsExploratory (isExploratory), + RequestedDestination (const IdentHash& destination, bool isExploratory = false, + i2p::tunnel::TunnelPool * pool = nullptr): + m_Destination (destination), m_IsExploratory (isExploratory), m_Pool (pool), m_CreationTime (0) {}; const IdentHash& GetDestination () const { return m_Destination; }; @@ -36,7 +36,6 @@ namespace data std::shared_ptr GetLastRouter () const { return m_LastRouter; }; i2p::tunnel::TunnelPool * GetTunnelPool () { return m_Pool; }; bool IsExploratory () const { return m_IsExploratory; }; - bool IsLeaseSet () const { return m_IsLeaseSet; }; bool IsExcluded (const IdentHash& ident) const { return m_ExcludedPeers.count (ident); }; uint64_t GetCreationTime () const { return m_CreationTime; }; I2NPMessage * CreateRequestMessage (std::shared_ptr, const i2p::tunnel::InboundTunnel * replyTunnel); @@ -45,7 +44,7 @@ namespace data private: IdentHash m_Destination; - bool m_IsLeaseSet, m_IsExploratory; + bool m_IsExploratory; i2p::tunnel::TunnelPool * m_Pool; std::set m_ExcludedPeers; std::shared_ptr m_LastRouter; @@ -68,8 +67,7 @@ namespace data std::shared_ptr FindRouter (const IdentHash& ident) const; LeaseSet * FindLeaseSet (const IdentHash& destination) const; - void RequestDestination (const IdentHash& destination, bool isLeaseSet = false, - i2p::tunnel::TunnelPool * pool = nullptr); + void RequestDestination (const IdentHash& destination, i2p::tunnel::TunnelPool * pool = nullptr); void HandleDatabaseStoreMsg (I2NPMessage * msg); void HandleDatabaseSearchReplyMsg (I2NPMessage * msg); @@ -100,7 +98,7 @@ namespace data void ManageRequests (); RequestedDestination * CreateRequestedDestination (const IdentHash& dest, - bool isLeaseSet, bool isExploratory = false, i2p::tunnel::TunnelPool * pool = nullptr); + bool isExploratory = false, i2p::tunnel::TunnelPool * pool = nullptr); bool DeleteRequestedDestination (const IdentHash& dest); // returns true if found void DeleteRequestedDestination (RequestedDestination * dest); diff --git a/SAM.cpp b/SAM.cpp index 7cc71f20..102c0454 100644 --- a/SAM.cpp +++ b/SAM.cpp @@ -325,7 +325,7 @@ namespace client Connect (*leaseSet); else { - i2p::data::netdb.RequestDestination (dest.GetIdentHash (), true, m_Session->localDestination->GetTunnelPool ()); + m_Session->localDestination->RequestDestination (dest.GetIdentHash ()); m_Timer.expires_from_now (boost::posix_time::seconds(SAM_CONNECT_TIMEOUT)); m_Timer.async_wait (std::bind (&SAMSocket::HandleStreamDestinationRequestTimer, shared_from_this (), std::placeholders::_1, dest.GetIdentHash ())); diff --git a/SOCKS.cpp b/SOCKS.cpp index 11c124e4..d4c755ac 100644 --- a/SOCKS.cpp +++ b/SOCKS.cpp @@ -159,7 +159,7 @@ namespace proxy LogPrint("--- sock4a find lease set"); m_ls = i2p::data::netdb.FindLeaseSet(m_dest); if (!m_ls || m_ls->HasNonExpiredLeases()) { - i2p::data::netdb.RequestDestination (m_dest, true, i2p::client::context.GetSharedLocalDestination ()->GetTunnelPool ()); + i2p::client::context.GetSharedLocalDestination ()->RequestDestination (m_dest); m_ls_timer.expires_from_now(boost::posix_time::seconds(socks_leaseset_timeout)); m_ls_timer.async_wait(boost::bind(&SOCKS4AHandler::LeaseSetTimeout, this, boost::asio::placeholders::error)); } else { diff --git a/api.cpp b/api.cpp index 439e3ed6..3cddf4f5 100644 --- a/api.cpp +++ b/api.cpp @@ -76,7 +76,7 @@ namespace api void RequestLeaseSet (i2p::client::ClientDestination * dest, const i2p::data::IdentHash& remote) { if (dest) - i2p::data::netdb.RequestDestination (remote, true, dest->GetTunnelPool ()); + dest->RequestDestination (remote); } std::shared_ptr CreateStream (i2p::client::ClientDestination * dest, const i2p::data::IdentHash& remote)