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

Method Save

libi2pd_client/AddressBook.cpp:232–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

230 }
231
232 int AddressBookFilesystemStorage::Save (const Addresses& addresses)
233 {
234 if (addresses.empty())
235 {
236 LogPrint(eLogWarning, "Addressbook: Not saving empty addressbook");
237 return 0;
238 }
239
240 int num = 0;
241 {
242 // save index file
243 std::ofstream f (indexPath, std::ofstream::out); // in text mode
244 if (f.is_open ())
245 {
246 for (const auto& it: addresses)
247 {
248 if (it.second->IsValid ())
249 {
250 f << it.first << ",";
251 if (it.second->IsIdentHash ())
252 f << it.second->identHash.ToBase32 ();
253 else
254 f << it.second->blindedPublicKey->ToB33 ();
255 f << std::endl;
256 num++;
257 }
258 else
259 LogPrint (eLogWarning, "Addressbook: Invalid address ", it.first);
260 }
261 LogPrint (eLogInfo, "Addressbook: ", num, " addresses saved");
262 }
263 else
264 LogPrint (eLogWarning, "Addressbook: Can't open ", indexPath);
265 }
266 if (!m_HostsFile.empty ())
267 {
268 // dump full hosts.txt
269 std::ofstream f (m_HostsFile, std::ofstream::out); // in text mode
270 if (f.is_open ())
271 {
272 for (const auto& it: addresses)
273 {
274 std::shared_ptr<const i2p::data::IdentityEx> addr;
275 if (it.second->IsIdentHash ())
276 {
277 addr = GetAddress (it.second->identHash);
278 if (addr)
279 f << it.first << "=" << addr->ToBase64 () << std::endl;
280 }
281 }
282 }
283 else
284 LogPrint (eLogWarning, "Addressbook: Can't open ", m_HostsFile);
285 }
286
287 return num;
288 }
289

Callers 2

StopMethod · 0.45
AddressBook.cppFile · 0.45

Calls 5

LogPrintFunction · 0.85
IsIdentHashMethod · 0.80
ToB33Method · 0.80
ToBase64Method · 0.80
IsValidMethod · 0.45

Tested by

no test coverage detected