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

Method Start

libi2pd/NetDb.cpp:53–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51 }
52
53 void NetDb::Start ()
54 {
55 m_Storage.SetPlace(i2p::fs::GetDataDir());
56 m_Storage.Init(i2p::data::GetBase64SubstitutionTable(), 64);
57 InitProfilesStorage ();
58 m_Families.LoadCertificates ();
59 Load ();
60
61 if (!m_Requests)
62 {
63 m_Requests = std::make_shared<NetDbRequests>();
64 m_Requests->Start ();
65 }
66
67 uint16_t threshold; i2p::config::GetOption("reseed.threshold", threshold);
68 if (m_RouterInfos.size () < threshold || m_Floodfills.GetSize () < NETDB_MIN_FLOODFILLS) // reseed if # of router less than threshold or too few floodfiils
69 {
70 Reseed ();
71 }
72 else if (!GetRandomRouter (i2p::context.GetSharedRouterInfo (), false, false, false))
73 Reseed (); // we don't have a router we can connect to. Trying to reseed
74
75 auto it = m_RouterInfos.find (i2p::context.GetIdentHash ());
76 if (it != m_RouterInfos.end ())
77 {
78 // remove own router
79 m_Floodfills.Remove (it->second->GetIdentHash ());
80 m_RouterInfos.erase (it);
81 }
82 // insert own router
83 m_RouterInfos.emplace (i2p::context.GetIdentHash (), i2p::context.GetSharedRouterInfo ());
84 if (i2p::context.IsFloodfill ())
85 m_Floodfills.Insert (i2p::context.GetSharedRouterInfo ());
86
87 i2p::config::GetOption("persist.profiles", m_PersistProfiles);
88
89 int persistInterval = 0;
90 i2p::config::GetOption("persist.netdbinterval", persistInterval);
91 if (persistInterval < NETDB_MIN_PERSIST_INTERVAL) persistInterval = NETDB_MIN_PERSIST_INTERVAL;
92 if (persistInterval > NETDB_MAX_PERSIST_INTERVAL) persistInterval = NETDB_MAX_PERSIST_INTERVAL;
93 m_NetDbPersistInterval = persistInterval*1000LL;
94
95 m_IsRunning = true;
96 m_Thread = new std::thread (std::bind (&NetDb::Run, this));
97 }
98
99 void NetDb::Stop ()
100 {

Callers

nothing calls this directly

Calls 11

InitProfilesStorageFunction · 0.85
GetOptionFunction · 0.85
SetPlaceMethod · 0.80
GetSharedRouterInfoMethod · 0.80
InitMethod · 0.45
LoadCertificatesMethod · 0.45
GetSizeMethod · 0.45
RemoveMethod · 0.45
IsFloodfillMethod · 0.45
InsertMethod · 0.45

Tested by

no test coverage detected