From 717940d969191a2a666cced8400d6e19ac4c9995 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 10 Jan 2015 09:07:07 -0500 Subject: [PATCH] some cleanup --- NetDb.cpp | 79 +++++++++++++++---------------------------------------- NetDb.h | 2 -- 2 files changed, 21 insertions(+), 60 deletions(-) diff --git a/NetDb.cpp b/NetDb.cpp index 612cdfb2..088cb495 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -29,7 +29,6 @@ namespace data replyTunnel->GetNextIdentHash (), replyTunnel->GetNextTunnelID (), m_IsExploratory, &m_ExcludedPeers); m_ExcludedPeers.insert (router->GetIdentHash ()); - m_LastRouter = router; m_CreationTime = i2p::util::GetSecondsSinceEpoch (); return msg; } @@ -39,7 +38,6 @@ namespace data I2NPMessage * msg = i2p::CreateRouterInfoDatabaseLookupMsg (m_Destination, i2p::context.GetRouterInfo ().GetIdentHash () , 0, false, &m_ExcludedPeers); m_ExcludedPeers.insert (floodfill); - m_LastRouter = nullptr; m_CreationTime = i2p::util::GetSecondsSinceEpoch (); return msg; } @@ -508,51 +506,7 @@ namespace data LogPrint (key, " was not found on 7 floodfills"); } } - - for (int i = 0; i < num; i++) - { - uint8_t * router = buf + 33 + i*32; - char peerHash[48]; - int l1 = i2p::data::ByteStreamToBase64 (router, 32, peerHash, 48); - peerHash[l1] = 0; - LogPrint (i,": ", peerHash); - if (dest->IsExploratory ()) - { - auto r = FindRouter (router); - if (!r || i2p::util::GetMillisecondsSinceEpoch () > r->GetTimestamp () + 3600*1000LL) - { - // router with ident not found or too old (1 hour) - LogPrint ("Found new/outdated router. Requesting RouterInfo ..."); - if (outbound && inbound && dest->GetLastRouter ()) - { - RequestedDestination * d1 = CreateRequestedDestination (router, false); - auto msg = d1->CreateRequestMessage (dest->GetLastRouter (), inbound); - msgs.push_back (i2p::tunnel::TunnelMessageBlock - { - i2p::tunnel::eDeliveryTypeRouter, - dest->GetLastRouter ()->GetIdentHash (), 0, msg - }); - } - else - RequestDestination (router); - } - else - LogPrint ("Bayan"); - } - else - { - auto r = FindRouter (router); - // do we have that floodfill router in our database? - if (!r) - { - // request router - LogPrint ("Found new floodfill. Request it"); - RequestDestination (router); - } - } - } - if (outbound && msgs.size () > 0) outbound->SendTunnelDataMsg (msgs); if (deleteDest) @@ -569,20 +523,29 @@ namespace data m_RequestedDestinations.erase (it); } } - else - { + else LogPrint ("Requested destination for ", key, " not found"); - // it might contain new routers - for (int i = 0; i < num; i++) - { - IdentHash router (buf + 33 + i*32); - if (!FindRouter (router)) - { - LogPrint ("New router ", router.ToBase64 (), " found. Request it"); - RequestDestination (router); - } - } + + // try responses + for (int i = 0; i < num; i++) + { + uint8_t * router = buf + 33 + i*32; + char peerHash[48]; + int l1 = i2p::data::ByteStreamToBase64 (router, 32, peerHash, 48); + peerHash[l1] = 0; + LogPrint (i,": ", peerHash); + + auto r = FindRouter (router); + if (!r || i2p::util::GetMillisecondsSinceEpoch () > r->GetTimestamp () + 3600*1000LL) + { + // router with ident not found or too old (1 hour) + LogPrint ("Found new/outdated router. Requesting RouterInfo ..."); + RequestDestination (router); + } + else + LogPrint ("Bayan"); } + i2p::DeleteI2NPMessage (msg); } diff --git a/NetDb.h b/NetDb.h index 5aa6acec..24d0a499 100644 --- a/NetDb.h +++ b/NetDb.h @@ -31,7 +31,6 @@ namespace data int GetNumExcludedPeers () const { return m_ExcludedPeers.size (); }; const std::set& GetExcludedPeers () { return m_ExcludedPeers; }; void ClearExcludedPeers (); - std::shared_ptr GetLastRouter () const { return m_LastRouter; }; bool IsExploratory () const { return m_IsExploratory; }; bool IsExcluded (const IdentHash& ident) const { return m_ExcludedPeers.count (ident); }; uint64_t GetCreationTime () const { return m_CreationTime; }; @@ -43,7 +42,6 @@ namespace data IdentHash m_Destination; bool m_IsExploratory; std::set m_ExcludedPeers; - std::shared_ptr m_LastRouter; uint64_t m_CreationTime; };