Add NetDb::VisitRandomRouterInfos

This commit is contained in:
Jeff Becker 2016-08-30 15:54:53 -04:00
parent fa8548fe34
commit 970557660e
No known key found for this signature in database
GPG key ID: AB950234D6EA286B
2 changed files with 49 additions and 13 deletions

View file

@ -39,6 +39,9 @@ namespace data
/** function for visiting a router info we have locally */
typedef std::function<void(const i2p::data::RouterInfo &)> RouterInfoVisitor;
/** function for visiting a router info and determining if we want to use it */
typedef std::function<bool(const i2p::data::RouterInfo &)> RouterInfoFilter;
class NetDb
{
@ -49,8 +52,6 @@ namespace data
void Start ();
void Stop ();
/** block until netdb is ready, call only once*/
void WaitForReady();
bool AddRouterInfo (const uint8_t * buf, int len);
bool AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len);
@ -96,6 +97,8 @@ namespace data
void VisitStoredRouterInfos(RouterInfoVisitor v);
/** visit all router infos we have loaded in memory, cheaper than VisitLocalRouterInfos but locks access while visiting */
void VisitRouterInfos(RouterInfoVisitor v);
/** visit N random router that match using filter, then visit them with a visitor, return number of RouterInfos that were visited */
size_t VisitRandomRouterInfos(RouterInfoFilter f, RouterInfoVisitor v, size_t n);
private:
void Load ();
@ -112,7 +115,6 @@ namespace data
std::shared_ptr<const RouterInfo> GetRandomRouter (Filter filter) const;
private:
std::promise<void> m_Ready;
mutable std::mutex m_LeaseSetsMutex;
std::map<IdentHash, std::shared_ptr<LeaseSet> > m_LeaseSets;