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

Method PostCreateNewLeaseSet

libi2pd_client/I2CP.cpp:177–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175 }
176
177 void I2CPDestination::PostCreateNewLeaseSet (std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels)
178 {
179 if (m_IsCreatingLeaseSet)
180 {
181 LogPrint (eLogInfo, "I2CP: LeaseSet is being created");
182 return;
183 }
184 m_ReadinessCheckTimer.cancel ();
185 auto pool = GetTunnelPool ();
186 if (!pool || pool->GetOutboundTunnels ().empty ())
187 {
188 // try again later
189 m_ReadinessCheckTimer.expires_after (std::chrono::seconds(I2CP_DESTINATION_READINESS_CHECK_INTERVAL));
190 m_ReadinessCheckTimer.async_wait(
191 [s=GetSharedFromThis (), tunnels=std::move(tunnels)](const boost::system::error_code& ecode)
192 {
193 if (ecode != boost::asio::error::operation_aborted)
194 s->PostCreateNewLeaseSet (tunnels);
195 });
196 return;
197 }
198 uint8_t priv[256] = {0};
199 i2p::data::LocalLeaseSet ls (m_Identity, priv, tunnels); // we don't care about encryption key, we need leases only
200 m_LeaseSetExpirationTime = ls.GetExpirationTime ();
201 uint8_t * leases = ls.GetLeases ();
202 int numLeases = leases[-1];
203 if (m_Owner && numLeases)
204 {
205 uint16_t sessionID = m_Owner->GetSessionID ();
206 if (sessionID != 0xFFFF)
207 {
208 m_IsCreatingLeaseSet = true;
209 htobe16buf (leases - 3, sessionID);
210 size_t l = 2/*sessionID*/ + 1/*num leases*/ + i2p::data::LEASE_SIZE*numLeases;
211 m_Owner->SendI2CPMessage (I2CP_REQUEST_VARIABLE_LEASESET_MESSAGE, leases - 3, l);
212 m_LeaseSetCreationTimer.expires_after (std::chrono::seconds (I2CP_LEASESET_CREATION_TIMEOUT));
213 auto s = GetSharedFromThis ();
214 m_LeaseSetCreationTimer.async_wait ([s](const boost::system::error_code& ecode)
215 {
216 if (ecode != boost::asio::error::operation_aborted)
217 {
218 LogPrint (eLogInfo, "I2CP: LeaseSet creation timeout expired. Terminate");
219 if (s->m_Owner) s->m_Owner->Stop ();
220 }
221 });
222 }
223 }
224 else
225 LogPrint (eLogError, "I2CP: Can't request LeaseSet");
226 }
227
228 void I2CPDestination::LeaseSetCreated (const uint8_t * buf, size_t len)
229 {

Callers

nothing calls this directly

Calls 7

LogPrintFunction · 0.85
htobe16bufFunction · 0.85
GetLeasesMethod · 0.80
GetSessionIDMethod · 0.80
SendI2CPMessageMethod · 0.80
GetExpirationTimeMethod · 0.45
StopMethod · 0.45

Tested by

no test coverage detected