Browse Source

* check router info addresses for nullptr

* Request LS before expiration for smoother handover
pull/628/head
Jeff Becker 8 years ago
parent
commit
eaac21cda1
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
  1. 23
      Destination.cpp
  2. 1
      Destination.h
  3. 7
      LeaseSet.cpp
  4. 1
      LeaseSet.h
  5. 1
      NTCPSession.cpp
  6. 1
      Transports.cpp

23
Destination.cpp

@ -171,11 +171,29 @@ namespace client
std::shared_ptr<const i2p::data::LeaseSet> LeaseSetDestination::FindLeaseSet (const i2p::data::IdentHash& ident) std::shared_ptr<const i2p::data::LeaseSet> LeaseSetDestination::FindLeaseSet (const i2p::data::IdentHash& ident)
{ {
std::lock_guard<std::mutex> lock(m_RemoteLeaseSetsMutex);
auto it = m_RemoteLeaseSets.find (ident); auto it = m_RemoteLeaseSets.find (ident);
if (it != m_RemoteLeaseSets.end ()) if (it != m_RemoteLeaseSets.end ())
{ {
if (!it->second->IsExpired ()) if (!it->second->IsExpired ())
{
if (it->second->ExpiresSoon())
{
LogPrint(eLogDebug, "Destination: Lease Set expires soon, updating before expire");
// update now before expiration for smooth handover
RequestDestination(ident, [this, ident] (std::shared_ptr<i2p::data::LeaseSet> ls) {
if(ls && !ls->IsExpired())
{
ls->PopulateLeases();
{
std::lock_guard<std::mutex> _lock(m_RemoteLeaseSetsMutex);
m_RemoteLeaseSets[ident] = ls;
}
}
});
}
return it->second; return it->second;
}
else else
LogPrint (eLogWarning, "Destination: remote LeaseSet expired"); LogPrint (eLogWarning, "Destination: remote LeaseSet expired");
} }
@ -185,7 +203,10 @@ namespace client
if (ls && !ls->IsExpired ()) if (ls && !ls->IsExpired ())
{ {
ls->PopulateLeases (); // since we don't store them in netdb ls->PopulateLeases (); // since we don't store them in netdb
{
std::lock_guard<std::mutex> lock(m_RemoteLeaseSetsMutex);
m_RemoteLeaseSets[ident] = ls; m_RemoteLeaseSets[ident] = ls;
}
return ls; return ls;
} }
} }
@ -279,6 +300,7 @@ namespace client
if (buf[DATABASE_STORE_TYPE_OFFSET] == 1) // LeaseSet if (buf[DATABASE_STORE_TYPE_OFFSET] == 1) // LeaseSet
{ {
LogPrint (eLogDebug, "Remote LeaseSet"); LogPrint (eLogDebug, "Remote LeaseSet");
std::lock_guard<std::mutex> lock(m_RemoteLeaseSetsMutex);
auto it = m_RemoteLeaseSets.find (buf + DATABASE_STORE_KEY_OFFSET); auto it = m_RemoteLeaseSets.find (buf + DATABASE_STORE_KEY_OFFSET);
if (it != m_RemoteLeaseSets.end ()) if (it != m_RemoteLeaseSets.end ())
{ {
@ -627,6 +649,7 @@ namespace client
void LeaseSetDestination::CleanupRemoteLeaseSets () void LeaseSetDestination::CleanupRemoteLeaseSets ()
{ {
auto ts = i2p::util::GetMillisecondsSinceEpoch (); auto ts = i2p::util::GetMillisecondsSinceEpoch ();
std::lock_guard<std::mutex> lock(m_RemoteLeaseSetsMutex);
for (auto it = m_RemoteLeaseSets.begin (); it != m_RemoteLeaseSets.end ();) for (auto it = m_RemoteLeaseSets.begin (); it != m_RemoteLeaseSets.end ();)
{ {
if (it->second->IsEmpty () || ts > it->second->GetExpirationTime ()) // leaseset expired if (it->second->IsEmpty () || ts > it->second->GetExpirationTime ()) // leaseset expired

1
Destination.h

@ -122,6 +122,7 @@ namespace client
std::thread * m_Thread; std::thread * m_Thread;
boost::asio::io_service m_Service; boost::asio::io_service m_Service;
boost::asio::io_service::work m_Work; boost::asio::io_service::work m_Work;
mutable std::mutex m_RemoteLeaseSetsMutex;
std::map<i2p::data::IdentHash, std::shared_ptr<i2p::data::LeaseSet> > m_RemoteLeaseSets; std::map<i2p::data::IdentHash, std::shared_ptr<i2p::data::LeaseSet> > m_RemoteLeaseSets;
std::map<i2p::data::IdentHash, std::shared_ptr<LeaseSetRequest> > m_LeaseSetRequests; std::map<i2p::data::IdentHash, std::shared_ptr<LeaseSetRequest> > m_LeaseSetRequests;

7
LeaseSet.cpp

@ -163,6 +163,13 @@ namespace data
return ExtractTimestamp (buf, len) > ExtractTimestamp (m_Buffer, m_BufferLen); return ExtractTimestamp (buf, len) > ExtractTimestamp (m_Buffer, m_BufferLen);
} }
bool LeaseSet::ExpiresSoon(const uint64_t dlt) const
{
auto now = i2p::util::GetMillisecondsSinceEpoch ();
if (now >= m_ExpirationTime) return true;
return m_ExpirationTime - now <= dlt;
}
const std::vector<std::shared_ptr<const Lease> > LeaseSet::GetNonExpiredLeases (bool withThreshold) const const std::vector<std::shared_ptr<const Lease> > LeaseSet::GetNonExpiredLeases (bool withThreshold) const
{ {
auto ts = i2p::util::GetMillisecondsSinceEpoch (); auto ts = i2p::util::GetMillisecondsSinceEpoch ();

1
LeaseSet.h

@ -60,6 +60,7 @@ namespace data
bool IsExpired () const; bool IsExpired () const;
bool IsEmpty () const { return m_Leases.empty (); }; bool IsEmpty () const { return m_Leases.empty (); };
uint64_t GetExpirationTime () const { return m_ExpirationTime; }; uint64_t GetExpirationTime () const { return m_ExpirationTime; };
bool ExpiresSoon(const uint64_t dlt=1000 * 5) const ;
bool operator== (const LeaseSet& other) const bool operator== (const LeaseSet& other) const
{ return m_BufferLen == other.m_BufferLen && !memcmp (m_Buffer, other.m_Buffer, m_BufferLen); }; { return m_BufferLen == other.m_BufferLen && !memcmp (m_Buffer, other.m_Buffer, m_BufferLen); };

1
NTCPSession.cpp

@ -768,6 +768,7 @@ namespace transport
auto& addresses = context.GetRouterInfo ().GetAddresses (); auto& addresses = context.GetRouterInfo ().GetAddresses ();
for (auto address: addresses) for (auto address: addresses)
{ {
if (!address) continue;
if (address->transportStyle == i2p::data::RouterInfo::eTransportNTCP) if (address->transportStyle == i2p::data::RouterInfo::eTransportNTCP)
{ {
if (address->host.is_v4()) if (address->host.is_v4())

1
Transports.cpp

@ -114,6 +114,7 @@ namespace transport
auto& addresses = context.GetRouterInfo ().GetAddresses (); auto& addresses = context.GetRouterInfo ().GetAddresses ();
for (auto address : addresses) for (auto address : addresses)
{ {
if (!address) continue;
if (m_NTCPServer == nullptr && enableNTCP) if (m_NTCPServer == nullptr && enableNTCP)
{ {
m_NTCPServer = new NTCPServer (); m_NTCPServer = new NTCPServer ();

Loading…
Cancel
Save