Browse Source

removed bootstrap from floodfill. Removed requested destinations mutex

pull/2072/head
orignal 6 months ago
parent
commit
4100249313
  1. 2
      libi2pd/Config.cpp
  2. 36
      libi2pd/NetDb.cpp
  3. 4
      libi2pd/NetDb.hpp
  4. 45
      libi2pd/NetDbRequests.cpp
  5. 5
      libi2pd/NetDbRequests.h

2
libi2pd/Config.cpp

@ -205,7 +205,7 @@ namespace config {
reseed.add_options() reseed.add_options()
("reseed.verify", value<bool>()->default_value(false), "Verify .su3 signature") ("reseed.verify", value<bool>()->default_value(false), "Verify .su3 signature")
("reseed.threshold", value<uint16_t>()->default_value(25), "Minimum number of known routers before requesting reseed") ("reseed.threshold", value<uint16_t>()->default_value(25), "Minimum number of known routers before requesting reseed")
("reseed.floodfill", value<std::string>()->default_value(""), "Path to router info of floodfill to reseed from") ("reseed.floodfill", value<std::string>()->default_value(""), "Ignored. Always empty")
("reseed.file", value<std::string>()->default_value(""), "Path to local .su3 file or HTTPS URL to reseed from") ("reseed.file", value<std::string>()->default_value(""), "Path to local .su3 file or HTTPS URL to reseed from")
("reseed.zipfile", value<std::string>()->default_value(""), "Path to local .zip file to reseed from") ("reseed.zipfile", value<std::string>()->default_value(""), "Path to local .zip file to reseed from")
("reseed.proxy", value<std::string>()->default_value(""), "url for reseed proxy, supports http/socks") ("reseed.proxy", value<std::string>()->default_value(""), "url for reseed proxy, supports http/socks")

36
libi2pd/NetDb.cpp

@ -478,28 +478,6 @@ namespace data
m_Reseeder->LoadCertificates (); // we need certificates for SU3 verification m_Reseeder->LoadCertificates (); // we need certificates for SU3 verification
} }
// try reseeding from floodfill first if specified
std::string riPath; i2p::config::GetOption("reseed.floodfill", riPath);
if (!riPath.empty())
{
auto ri = std::make_shared<RouterInfo>(riPath);
if (ri->IsFloodfill())
{
const uint8_t * riData = ri->GetBuffer();
int riLen = ri->GetBufferLen();
if (!i2p::data::netdb.AddRouterInfo(riData, riLen))
{
// bad router info
LogPrint(eLogError, "NetDb: Bad router info");
return;
}
m_FloodfillBootstrap = ri;
//ReseedFromFloodfill(*ri);
// don't try reseed servers if trying to bootstrap from floodfill
return;
}
}
m_Reseeder->Bootstrap (); m_Reseeder->Bootstrap ();
} }
@ -792,20 +770,6 @@ namespace data
LogPrint (eLogError, "NetDb: Requests is null"); LogPrint (eLogError, "NetDb: Requests is null");
} }
void NetDb::RequestDestinationFrom (const IdentHash& destination, const IdentHash & from, bool exploratory, RequestedDestination::RequestComplete requestComplete)
{
auto dest = m_Requests->CreateRequest (destination, exploratory, true, requestComplete); // non-exploratory
if (!dest)
{
LogPrint (eLogWarning, "NetDb: Destination ", destination.ToBase64(), " is requested already");
return;
}
if (CheckLogLevel (eLogDebug))
LogPrint(eLogDebug, "NetDb: Destination ", destination.ToBase64(), " being requested directly from ", from.ToBase64());
// direct
transports.SendMessage (from, dest->CreateRequestMessage (nullptr, nullptr));
}
void NetDb::HandleNTCP2RouterInfoMsg (std::shared_ptr<const I2NPMessage> m) void NetDb::HandleNTCP2RouterInfoMsg (std::shared_ptr<const I2NPMessage> m)
{ {
uint8_t flood = m->GetPayload ()[0] & NTCP2_ROUTER_INFO_FLAG_REQUEST_FLOOD; uint8_t flood = m->GetPayload ()[0] & NTCP2_ROUTER_INFO_FLAG_REQUEST_FLOOD;

4
libi2pd/NetDb.hpp

@ -83,7 +83,6 @@ namespace data
std::shared_ptr<RouterProfile> FindRouterProfile (const IdentHash& ident) const; std::shared_ptr<RouterProfile> FindRouterProfile (const IdentHash& ident) const;
void RequestDestination (const IdentHash& destination, RequestedDestination::RequestComplete requestComplete = nullptr, bool direct = true); void RequestDestination (const IdentHash& destination, RequestedDestination::RequestComplete requestComplete = nullptr, bool direct = true);
void RequestDestinationFrom (const IdentHash& destination, const IdentHash & from, bool exploritory, RequestedDestination::RequestComplete requestComplete = nullptr);
std::shared_ptr<const RouterInfo> GetRandomRouter () const; std::shared_ptr<const RouterInfo> GetRandomRouter () const;
std::shared_ptr<const RouterInfo> GetRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith, bool reverse, bool endpoint) const; std::shared_ptr<const RouterInfo> GetRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith, bool reverse, bool endpoint) const;
@ -185,9 +184,6 @@ namespace data
bool m_PersistProfiles; bool m_PersistProfiles;
std::future<void> m_SavingProfiles, m_DeletingProfiles, m_PersistingRouters; std::future<void> m_SavingProfiles, m_DeletingProfiles, m_PersistingRouters;
/** router info we are bootstrapping from or nullptr if we are not currently doing that*/
std::shared_ptr<RouterInfo> m_FloodfillBootstrap;
std::vector<std::shared_ptr<const RouterInfo> > m_ExploratorySelection; std::vector<std::shared_ptr<const RouterInfo> > m_ExploratorySelection;
uint64_t m_LastExploratorySelectionUpdateTime; // in monotonic seconds uint64_t m_LastExploratorySelectionUpdateTime; // in monotonic seconds

45
libi2pd/NetDbRequests.cpp

@ -157,22 +157,20 @@ namespace data
auto dest = m_RequestedDestinationsPool.AcquireSharedMt (destination, isExploratory, direct); auto dest = m_RequestedDestinationsPool.AcquireSharedMt (destination, isExploratory, direct);
if (requestComplete) if (requestComplete)
dest->AddRequestComplete (requestComplete); dest->AddRequestComplete (requestComplete);
auto ret = m_RequestedDestinations.emplace (destination, dest);
if (!ret.second) // not inserted
{ {
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex); dest->ResetRequestComplete (); // don't call requestComplete in destructor
auto ret = m_RequestedDestinations.emplace (destination, dest); dest = ret.first->second; // existing one
if (!ret.second) // not inserted if (requestComplete)
{ {
dest->ResetRequestComplete (); // don't call requestComplete in destructor if (dest->IsActive ())
dest = ret.first->second; // existing one dest->AddRequestComplete (requestComplete);
if (requestComplete) else
{ requestComplete (nullptr);
if (dest->IsActive ())
dest->AddRequestComplete (requestComplete);
else
requestComplete (nullptr);
}
return nullptr;
} }
return nullptr;
} }
return dest; return dest;
} }
@ -182,16 +180,13 @@ namespace data
GetIOService ().post ([this, ident, r]() GetIOService ().post ([this, ident, r]()
{ {
std::shared_ptr<RequestedDestination> request; std::shared_ptr<RequestedDestination> request;
auto it = m_RequestedDestinations.find (ident);
if (it != m_RequestedDestinations.end ())
{ {
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex); request = it->second;
auto it = m_RequestedDestinations.find (ident); if (request->IsExploratory ())
if (it != m_RequestedDestinations.end ()) m_RequestedDestinations.erase (it);
{ // otherwise cache for a while
request = it->second;
if (request->IsExploratory ())
m_RequestedDestinations.erase (it);
// otherwise cache for a while
}
} }
if (request) if (request)
{ {
@ -205,7 +200,6 @@ namespace data
std::shared_ptr<RequestedDestination> NetDbRequests::FindRequest (const IdentHash& ident) const std::shared_ptr<RequestedDestination> NetDbRequests::FindRequest (const IdentHash& ident) const
{ {
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
auto it = m_RequestedDestinations.find (ident); auto it = m_RequestedDestinations.find (ident);
if (it != m_RequestedDestinations.end ()) if (it != m_RequestedDestinations.end ())
return it->second; return it->second;
@ -215,7 +209,6 @@ namespace data
void NetDbRequests::ManageRequests () void NetDbRequests::ManageRequests ()
{ {
uint64_t ts = i2p::util::GetSecondsSinceEpoch (); uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
for (auto it = m_RequestedDestinations.begin (); it != m_RequestedDestinations.end ();) for (auto it = m_RequestedDestinations.begin (); it != m_RequestedDestinations.end ();)
{ {
auto& dest = it->second; auto& dest = it->second;
@ -424,9 +417,7 @@ namespace data
{ {
// router with ident not found or too old (1 hour) // router with ident not found or too old (1 hour)
LogPrint (eLogDebug, "NetDbReq: Found new/outdated router. Requesting RouterInfo..."); LogPrint (eLogDebug, "NetDbReq: Found new/outdated router. Requesting RouterInfo...");
/* if(m_FloodfillBootstrap) if (!IsRouterBanned (router))
RequestDestinationFrom(router, m_FloodfillBootstrap->GetIdentHash(), true);
else */if (!IsRouterBanned (router))
RequestDestination (router, nullptr, true); RequestDestination (router, nullptr, true);
else else
LogPrint (eLogDebug, "NetDbReq: Router ", router.ToBase64 (), " is banned. Skipped"); LogPrint (eLogDebug, "NetDbReq: Router ", router.ToBase64 (), " is banned. Skipped");

5
libi2pd/NetDbRequests.h

@ -86,14 +86,14 @@ namespace data
void Start (); void Start ();
void Stop (); void Stop ();
std::shared_ptr<RequestedDestination> CreateRequest (const IdentHash& destination, bool isExploratory,
bool direct = false, RequestedDestination::RequestComplete requestComplete = nullptr);
void RequestComplete (const IdentHash& ident, std::shared_ptr<RouterInfo> r); void RequestComplete (const IdentHash& ident, std::shared_ptr<RouterInfo> r);
void PostDatabaseSearchReplyMsg (std::shared_ptr<const I2NPMessage> msg); void PostDatabaseSearchReplyMsg (std::shared_ptr<const I2NPMessage> msg);
void PostRequestDestination (const IdentHash& destination, const RequestedDestination::RequestComplete& requestComplete, bool direct); void PostRequestDestination (const IdentHash& destination, const RequestedDestination::RequestComplete& requestComplete, bool direct);
private: private:
std::shared_ptr<RequestedDestination> CreateRequest (const IdentHash& destination, bool isExploratory,
bool direct = false, RequestedDestination::RequestComplete requestComplete = nullptr);
std::shared_ptr<RequestedDestination> FindRequest (const IdentHash& ident) const; std::shared_ptr<RequestedDestination> FindRequest (const IdentHash& ident) const;
bool SendNextRequest (std::shared_ptr<RequestedDestination> dest); bool SendNextRequest (std::shared_ptr<RequestedDestination> dest);
@ -114,7 +114,6 @@ namespace data
private: private:
mutable std::mutex m_RequestedDestinationsMutex;
std::unordered_map<IdentHash, std::shared_ptr<RequestedDestination> > m_RequestedDestinations; std::unordered_map<IdentHash, std::shared_ptr<RequestedDestination> > m_RequestedDestinations;
std::list<IdentHash> m_DiscoveredRouterHashes; std::list<IdentHash> m_DiscoveredRouterHashes;
i2p::util::MemoryPoolMt<RequestedDestination> m_RequestedDestinationsPool; i2p::util::MemoryPoolMt<RequestedDestination> m_RequestedDestinationsPool;

Loading…
Cancel
Save