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

Method UpdateCurrentRemoteLease

libi2pd/Streaming.cpp:1884–1993  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1882 }
1883
1884 void Stream::UpdateCurrentRemoteLease (bool expired)
1885 {
1886 bool isLeaseChanged = true;
1887 if (!m_RemoteLeaseSet || m_RemoteLeaseSet->IsExpired ())
1888 {
1889 auto remoteLeaseSet = m_LocalDestination.GetOwner ()->FindLeaseSet (m_RemoteIdentity->GetIdentHash ());
1890 if (!remoteLeaseSet)
1891 {
1892 LogPrint (eLogWarning, "Streaming: LeaseSet ", m_RemoteIdentity->GetIdentHash ().ToBase32 (), m_RemoteLeaseSet ? " expired" : " not found");
1893 if (!m_IsIncoming) // outgoing
1894 {
1895 auto requestCallback = [s = shared_from_this ()](std::shared_ptr<i2p::data::LeaseSet> ls)
1896 {
1897 if (!ls && s->m_Status == eStreamStatusOpen) // LeaseSet not found
1898 {
1899 // close the socket without sending FIN or RST
1900 s->m_Status = eStreamStatusClosed;
1901 s->AsyncClose ();
1902 }
1903 };
1904
1905 if (m_RemoteLeaseSet && m_RemoteLeaseSet->IsPublishedEncrypted ())
1906 {
1907 m_LocalDestination.GetOwner ()->RequestDestinationWithEncryptedLeaseSet (
1908 std::make_shared<i2p::data::BlindedPublicKey>(m_RemoteIdentity), requestCallback);
1909 return; // we keep m_RemoteLeaseSet for possible next request
1910 }
1911 else
1912 {
1913 m_RemoteLeaseSet = nullptr;
1914 m_LocalDestination.GetOwner ()->RequestDestination (m_RemoteIdentity->GetIdentHash (), requestCallback); // try to request for a next attempt
1915 }
1916 }
1917 else // incoming
1918 {
1919 // just close the socket without sending FIN or RST
1920 m_Status = eStreamStatusClosed;
1921 AsyncClose ();
1922 }
1923 }
1924 else
1925 {
1926 // LeaseSet updated
1927 m_RemoteLeaseSet = remoteLeaseSet;
1928 m_RemoteIdentity = m_RemoteLeaseSet->GetIdentity ();
1929 m_TransientVerifier = m_RemoteLeaseSet->GetTransientVerifier ();
1930 }
1931 }
1932 if (m_RemoteLeaseSet)
1933 {
1934 if (!m_RoutingSession)
1935 m_RoutingSession = m_LocalDestination.GetOwner ()->GetRoutingSession (m_RemoteLeaseSet, true);
1936 auto leases = m_RemoteLeaseSet->GetNonExpiredLeases (false); // try without threshold first
1937 if (leases.empty ())
1938 {
1939 expired = false;
1940 // time to request
1941 if (m_RemoteLeaseSet->IsPublishedEncrypted ())

Callers

nothing calls this directly

Calls 13

LogPrintFunction · 0.85
AsyncCloseMethod · 0.80
GetRoutingSessionMethod · 0.80
GetNonExpiredLeasesMethod · 0.80
GetRandomMethod · 0.80
IsExpiredMethod · 0.45
FindLeaseSetMethod · 0.45
GetOwnerMethod · 0.45
IsPublishedEncryptedMethod · 0.45
RequestDestinationMethod · 0.45
GetIdentityMethod · 0.45

Tested by

no test coverage detected