MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / AddressBookFilesystemStorage

Class AddressBookFilesystemStorage

libi2pd_client/AddressBook.cpp:43–79  ·  view source on GitHub ↗

TODO: this is actually proxy class

Source from the content-addressed store, hash-verified

41{
42 // TODO: this is actually proxy class
43 class AddressBookFilesystemStorage: public AddressBookStorage
44 {
45 public:
46
47 AddressBookFilesystemStorage (): storage("addressbook", "b", "", "b32")
48 {
49 i2p::config::GetOption("persist.addressbook", m_IsPersist);
50 if (m_IsPersist)
51 i2p::config::GetOption("addressbook.hostsfile", m_HostsFile);
52 }
53 std::shared_ptr<const i2p::data::IdentityEx> GetAddress (const i2p::data::IdentHash& ident) override;
54 void AddAddress (std::shared_ptr<const i2p::data::IdentityEx> address) override;
55 void RemoveAddress (const i2p::data::IdentHash& ident) override;
56 void CleanUpCache () override;
57
58 bool Init () override;
59 int Load (Addresses& addresses) override;
60 int LoadLocal (Addresses& addresses) override;
61 int Save (const Addresses& addresses) override;
62
63 void SaveEtag (const i2p::data::IdentHash& subscription, const std::string& etag, const std::string& lastModified) override;
64 bool GetEtag (const i2p::data::IdentHash& subscription, std::string& etag, std::string& lastModified) override;
65 void ResetEtags () override;
66
67 private:
68
69 int LoadFromFile (const std::string& filename, Addresses& addresses); // returns -1 if can't open file, otherwise number of records
70
71 private:
72
73 i2p::fs::HashedStorage storage;
74 std::string etagsPath, indexPath, localPath;
75 bool m_IsPersist;
76 std::string m_HostsFile; // file to dump hosts.txt, empty if not used
77 std::unordered_map<i2p::data::IdentHash, std::pair<std::vector<uint8_t>, uint64_t> > m_FullAddressCache; // ident hash -> (full ident buffer, last access timestamp)
78 std::mutex m_FullAddressCacheMutex;
79 };
80
81 bool AddressBookFilesystemStorage::Init()
82 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected