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

Method FindLeaseSet

libi2pd/Destination.cpp:194–235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192 }
193
194 std::shared_ptr<i2p::data::LeaseSet> LeaseSetDestination::FindLeaseSet (const i2p::data::IdentHash& ident)
195 {
196 std::shared_ptr<i2p::data::LeaseSet> remoteLS;
197 {
198 std::lock_guard<std::mutex> lock(m_RemoteLeaseSetsMutex);
199 auto it = m_RemoteLeaseSets.find (ident);
200 if (it != m_RemoteLeaseSets.end ())
201 remoteLS = it->second;
202 }
203
204 if (remoteLS)
205 {
206 if (!remoteLS->IsExpired ())
207 {
208 if (remoteLS->ExpiresSoon())
209 {
210 LogPrint(eLogDebug, "Destination: Lease Set expires soon, updating before expire");
211 // update now before expiration for smooth handover
212 auto s = shared_from_this ();
213 RequestDestination(ident, [s, ident] (std::shared_ptr<i2p::data::LeaseSet> ls) {
214 if(ls && !ls->IsExpired())
215 {
216 ls->PopulateLeases();
217 {
218 std::lock_guard<std::mutex> _lock(s->m_RemoteLeaseSetsMutex);
219 s->m_RemoteLeaseSets[ident] = ls;
220 }
221 }
222 });
223 }
224 return remoteLS;
225 }
226 else
227 {
228 LogPrint (eLogWarning, "Destination: Remote LeaseSet expired");
229 std::lock_guard<std::mutex> lock(m_RemoteLeaseSetsMutex);
230 m_RemoteLeaseSets.erase (ident);
231 return nullptr;
232 }
233 }
234 return nullptr;
235 }
236
237 std::shared_ptr<const i2p::data::LocalLeaseSet> LeaseSetDestination::GetLeaseSet ()
238 {

Callers

nothing calls this directly

Calls 4

LogPrintFunction · 0.85
ExpiresSoonMethod · 0.80
PopulateLeasesMethod · 0.80
IsExpiredMethod · 0.45

Tested by

no test coverage detected