From 9b2e275c45d2330b255201d447178a198c9c4c69 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 14 Oct 2014 20:52:40 -0400 Subject: [PATCH] try closest floodfills sequentially --- HTTPServer.cpp | 6 +-- I2PTunnel.cpp | 2 +- Identity.cpp | 5 +- NetDb.cpp | 130 +++++++++++++++++++++---------------------------- 4 files changed, 61 insertions(+), 82 deletions(-) diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 2e7d867d..38759c3e 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -520,7 +520,7 @@ namespace util m_Stream = nullptr; } m_Socket->close (); - delete this; + //delete this; } void HTTPConnection::Receive () @@ -544,8 +544,8 @@ namespace util m_Stream->Send ((uint8_t *)m_Buffer, bytes_transferred); Receive (); } - /*else if (ecode != boost::asio::error::operation_aborted) - Terminate ();*/ + else if (ecode != boost::asio::error::operation_aborted) + Terminate (); } void HTTPConnection::RunRequest () diff --git a/I2PTunnel.cpp b/I2PTunnel.cpp index 3a5bc033..765bc997 100644 --- a/I2PTunnel.cpp +++ b/I2PTunnel.cpp @@ -44,7 +44,7 @@ namespace stream m_Socket->close (); if (m_Owner) m_Owner->RemoveConnection (this); - delete this; + //delete this; } void I2PTunnelConnection::Receive () diff --git a/Identity.cpp b/Identity.cpp index 2a48cfd5..a13906da 100644 --- a/Identity.cpp +++ b/Identity.cpp @@ -307,13 +307,12 @@ namespace data memcpy (buf, (const uint8_t *)ident, 32); time_t t = time (nullptr); struct tm tm; - // WARNING!!! check if it is correct #ifdef _WIN32 gmtime_s(&tm, &t); - sprintf_s((char *)(buf + 32), 9, "%4i%2i%2i", tm.tm_year, tm.tm_mon, tm.tm_mday); + sprintf_s((char *)(buf + 32), 9, "%4i%2i%2i", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); #else gmtime_r(&t, &tm); - sprintf((char *)(buf + 32), "%4i%2i%2i", tm.tm_year, tm.tm_mon, tm.tm_mday); + sprintf((char *)(buf + 32), "%4i%2i%2i", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); #endif IdentHash key; CryptoPP::SHA256().CalculateDigest((uint8_t *)key, buf, 40); diff --git a/NetDb.cpp b/NetDb.cpp index aa97871c..ce544b55 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -376,26 +376,19 @@ namespace data if (inbound) { RequestedDestination * dest = CreateRequestedDestination (destination, true, false, pool); - std::vector msgs; - // request 3 closests floodfills - for (int i = 0; i < 3; i++) - { - auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ()); - if (floodfill) - { - // DatabaseLookup message - msgs.push_back (i2p::tunnel::TunnelMessageBlock + 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) - }); - } - } - if (msgs.size () > 0) - { - dest->ClearExcludedPeers (); - outbound->SendTunnelDataMsg (msgs); + } + }); } else LogPrint ("No more floodfills found"); @@ -468,6 +461,43 @@ namespace data auto outbound = pool ? pool->GetNextOutboundTunnel () : i2p::tunnel::tunnels.GetNextOutboundTunnel (); auto inbound = pool ? pool->GetNextInboundTunnel () : i2p::tunnel::tunnels.GetNextInboundTunnel (); std::vector msgs; + if (!dest->IsExploratory ()) + { + // reply to our destination. Try other floodfills + if (outbound && inbound ) + { + auto count = dest->GetExcludedPeers ().size (); + if (count < 7) + { + 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 () + }); + } + + // request destination + LogPrint ("Try ", key, " at ", count, " floodfill ", nextFloodfill->GetIdentHash ().ToBase64 ()); + auto msg = dest->CreateRequestMessage (nextFloodfill, inbound); + msgs.push_back (i2p::tunnel::TunnelMessageBlock + { + i2p::tunnel::eDeliveryTypeRouter, + nextFloodfill->GetIdentHash (), 0, msg + }); + deleteDest = false; + } + } + else + LogPrint (key, " was not found on 7 floodfills"); + } + } for (int i = 0; i < num; i++) { @@ -501,64 +531,14 @@ namespace data LogPrint ("Bayan"); } else - { - // reply to our destination. Try other floodfills - if (outbound && inbound && dest->GetLastRouter ()) - { - auto r = FindRouter (router); - // do we have that floodfill router in our database? - if (r) - { - // we do - if (!dest->IsExcluded (r->GetIdentHash ()) && dest->GetNumExcludedPeers () < 30) // TODO: fix TunnelGateway first - { - LogPrint ("Try ", key, " at floodfill ", peerHash); - if (!dest->IsLeaseSet ()) - { - // tell floodfill about us - msgs.push_back (i2p::tunnel::TunnelMessageBlock - { - i2p::tunnel::eDeliveryTypeRouter, - r->GetIdentHash (), 0, - CreateDatabaseStoreMsg () - }); - } - // request destination - auto msg = dest->CreateRequestMessage (r, inbound); - msgs.push_back (i2p::tunnel::TunnelMessageBlock - { - i2p::tunnel::eDeliveryTypeRouter, - r->GetIdentHash (), 0, msg - }); - deleteDest = false; - } - } - else - { - // request router - LogPrint ("Found new floodfill. Request it"); - RequestedDestination * d2 = CreateRequestedDestination (router, false, false, pool); - I2NPMessage * msg = d2->CreateRequestMessage (dest->GetLastRouter (), inbound); - msgs.push_back (i2p::tunnel::TunnelMessageBlock - { - i2p::tunnel::eDeliveryTypeRouter, - dest->GetLastRouter ()->GetIdentHash (), 0, msg - }); - } - } - else // we should send directly - { - if (!dest->IsLeaseSet ()) // if not LeaseSet - { - if (!dest->IsExcluded (router) && dest->GetNumExcludedPeers () < 30) - { - LogPrint ("Try ", key, " at floodfill ", peerHash, " directly"); - i2p::transports.SendMessage (router, dest->CreateRequestMessage (router)); - deleteDest = false; - } - } - else - LogPrint ("Can't request LeaseSet"); + { + 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, false, pool); } } } @@ -567,7 +547,7 @@ namespace data outbound->SendTunnelDataMsg (msgs); if (deleteDest) { - // no more requests for tha destinationation. delete it + // no more requests for the destinationation. delete it delete it->second; m_RequestedDestinations.erase (it); }