mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01: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) {
|
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::path p(root);
|
||||||
boost::filesystem::recursive_directory_iterator it(p);
|
boost::filesystem::recursive_directory_iterator it(p);
|
||||||
boost::filesystem::recursive_directory_iterator end;
|
boost::filesystem::recursive_directory_iterator end;
|
||||||
|
@ -166,7 +173,7 @@ namespace fs {
|
||||||
if (!boost::filesystem::is_regular_file( it->status() ))
|
if (!boost::filesystem::is_regular_file( it->status() ))
|
||||||
continue;
|
continue;
|
||||||
const std::string & t = it->path().string();
|
const std::string & t = it->path().string();
|
||||||
files.push_back(t);
|
v(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // fs
|
} // fs
|
||||||
|
|
4
FS.h
4
FS.h
|
@ -13,6 +13,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace i2p {
|
namespace i2p {
|
||||||
namespace fs {
|
namespace fs {
|
||||||
|
@ -43,6 +44,7 @@ namespace fs {
|
||||||
std::string suffix; /**< suffix of file in storage (extension) */
|
std::string suffix; /**< suffix of file in storage (extension) */
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
typedef std::function<void(const std::string &)> FilenameVisitor;
|
||||||
HashedStorage(const char *n, const char *p1, const char *p2, const char *s):
|
HashedStorage(const char *n, const char *p1, const char *p2, const char *s):
|
||||||
name(n), prefix1(p1), prefix2(p2), suffix(s) {};
|
name(n), prefix1(p1), prefix2(p2), suffix(s) {};
|
||||||
|
|
||||||
|
@ -58,6 +60,8 @@ namespace fs {
|
||||||
void Remove(const std::string & ident);
|
void Remove(const std::string & ident);
|
||||||
/** find all files in storage and store list in provided vector */
|
/** find all files in storage and store list in provided vector */
|
||||||
void Traverse(std::vector<std::string> & files);
|
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' */
|
/** @brief Returns current application name, default 'i2pd' */
|
||||||
|
|
15
NetDb.cpp
15
NetDb.cpp
|
@ -330,6 +330,21 @@ namespace data
|
||||||
v(entry.first, entry.second);
|
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 ()
|
void NetDb::Load ()
|
||||||
{
|
{
|
||||||
// make sure we cleanup netDb from previous attempts
|
// make sure we cleanup netDb from previous attempts
|
||||||
|
|
8
NetDb.h
8
NetDb.h
|
@ -36,6 +36,9 @@ namespace data
|
||||||
/** function for visiting a leaseset stored in a floodfill */
|
/** function for visiting a leaseset stored in a floodfill */
|
||||||
typedef std::function<void(const IdentHash, std::shared_ptr<LeaseSet>)> LeaseSetVisitor;
|
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
|
class NetDb
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -86,7 +89,10 @@ namespace data
|
||||||
|
|
||||||
/** visit all lease sets we currently store */
|
/** visit all lease sets we currently store */
|
||||||
void VisitLeaseSets(LeaseSetVisitor v);
|
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:
|
private:
|
||||||
|
|
||||||
void Load ();
|
void Load ();
|
||||||
|
|
Loading…
Reference in a new issue