mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-11 13:27:52 +00:00
add hooks for visiting netdb
This commit is contained in:
parent
28fdd992c9
commit
fec49e5609
9
FS.cpp
9
FS.cpp
@ -158,6 +158,13 @@ namespace fs {
|
||||
}
|
||||
|
||||
void HashedStorage::Traverse(std::vector<std::string> & files) {
|
||||
Iterate([&files] (const std::string & fname) {
|
||||
files.push_back(fname);
|
||||
});
|
||||
}
|
||||
|
||||
void HashedStorage::Iterate(FilenameVisitor v)
|
||||
{
|
||||
boost::filesystem::path p(root);
|
||||
boost::filesystem::recursive_directory_iterator it(p);
|
||||
boost::filesystem::recursive_directory_iterator end;
|
||||
@ -166,7 +173,7 @@ namespace fs {
|
||||
if (!boost::filesystem::is_regular_file( it->status() ))
|
||||
continue;
|
||||
const std::string & t = it->path().string();
|
||||
files.push_back(t);
|
||||
v(t);
|
||||
}
|
||||
}
|
||||
} // fs
|
||||
|
4
FS.h
4
FS.h
@ -13,6 +13,7 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <functional>
|
||||
|
||||
namespace i2p {
|
||||
namespace fs {
|
||||
@ -43,6 +44,7 @@ namespace fs {
|
||||
std::string suffix; /**< suffix of file in storage (extension) */
|
||||
|
||||
public:
|
||||
typedef std::function<void(const std::string &)> FilenameVisitor;
|
||||
HashedStorage(const char *n, const char *p1, const char *p2, const char *s):
|
||||
name(n), prefix1(p1), prefix2(p2), suffix(s) {};
|
||||
|
||||
@ -58,6 +60,8 @@ namespace fs {
|
||||
void Remove(const std::string & ident);
|
||||
/** find all files in storage and store list in provided vector */
|
||||
void Traverse(std::vector<std::string> & files);
|
||||
/** visit every file in this storage with a visitor */
|
||||
void Iterate(FilenameVisitor v);
|
||||
};
|
||||
|
||||
/** @brief Returns current application name, default 'i2pd' */
|
||||
|
15
NetDb.cpp
15
NetDb.cpp
@ -329,6 +329,21 @@ namespace data
|
||||
for ( auto & entry : m_LeaseSets)
|
||||
v(entry.first, entry.second);
|
||||
}
|
||||
|
||||
void NetDb::VisitStoredRouterInfos(RouterInfoVisitor v)
|
||||
{
|
||||
m_Storage.Iterate([v] (const std::string & filename) {
|
||||
const i2p::data::RouterInfo ri(filename);
|
||||
v(ri);
|
||||
});
|
||||
}
|
||||
|
||||
void NetDb::VisitRouterInfos(RouterInfoVisitor v)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_RouterInfosMutex);
|
||||
for ( const auto & item : m_RouterInfos )
|
||||
v(*item.second);
|
||||
}
|
||||
|
||||
void NetDb::Load ()
|
||||
{
|
||||
|
10
NetDb.h
10
NetDb.h
@ -35,7 +35,10 @@ namespace data
|
||||
|
||||
/** function for visiting a leaseset stored in a floodfill */
|
||||
typedef std::function<void(const IdentHash, std::shared_ptr<LeaseSet>)> LeaseSetVisitor;
|
||||
|
||||
|
||||
/** function for visiting a router info we have locally */
|
||||
typedef std::function<void(const i2p::data::RouterInfo &)> RouterInfoVisitor;
|
||||
|
||||
class NetDb
|
||||
{
|
||||
public:
|
||||
@ -86,7 +89,10 @@ namespace data
|
||||
|
||||
/** visit all lease sets we currently store */
|
||||
void VisitLeaseSets(LeaseSetVisitor v);
|
||||
|
||||
/** visit all router infos we have currently on disk, usually insanely expensive, does not access in memory RI */
|
||||
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);
|
||||
private:
|
||||
|
||||
void Load ();
|
||||
|
Loading…
Reference in New Issue
Block a user