Browse Source

try next floodfill for router request on demand

pull/2010/head
orignal 11 months ago
parent
commit
49f4dc53ad
  1. 21
      libi2pd/NetDbRequests.cpp
  2. 8
      libi2pd/NetDbRequests.h

21
libi2pd/NetDbRequests.cpp

@ -17,6 +17,17 @@ namespace i2p
{ {
namespace data namespace data
{ {
RequestedDestination::RequestedDestination (const IdentHash& destination, bool isExploratory, bool direct):
m_Destination (destination), m_IsExploratory (isExploratory), m_IsDirect (direct),
m_CreationTime (i2p::util::GetSecondsSinceEpoch ()), m_LastRequestTime (0)
{
}
RequestedDestination::~RequestedDestination ()
{
if (m_RequestComplete) m_RequestComplete (nullptr);
}
std::shared_ptr<I2NPMessage> RequestedDestination::CreateRequestMessage (std::shared_ptr<const RouterInfo> router, std::shared_ptr<I2NPMessage> RequestedDestination::CreateRequestMessage (std::shared_ptr<const RouterInfo> router,
std::shared_ptr<const i2p::tunnel::InboundTunnel> replyTunnel) std::shared_ptr<const i2p::tunnel::InboundTunnel> replyTunnel)
{ {
@ -29,7 +40,7 @@ namespace data
msg = i2p::CreateRouterInfoDatabaseLookupMsg(m_Destination, i2p::context.GetIdentHash(), 0, m_IsExploratory, &m_ExcludedPeers); msg = i2p::CreateRouterInfoDatabaseLookupMsg(m_Destination, i2p::context.GetIdentHash(), 0, m_IsExploratory, &m_ExcludedPeers);
if(router) if(router)
m_ExcludedPeers.insert (router->GetIdentHash ()); m_ExcludedPeers.insert (router->GetIdentHash ());
m_CreationTime = i2p::util::GetSecondsSinceEpoch (); m_LastRequestTime = i2p::util::GetSecondsSinceEpoch ();
return msg; return msg;
} }
@ -38,7 +49,7 @@ namespace data
auto msg = i2p::CreateRouterInfoDatabaseLookupMsg (m_Destination, auto msg = i2p::CreateRouterInfoDatabaseLookupMsg (m_Destination,
i2p::context.GetRouterInfo ().GetIdentHash () , 0, false, &m_ExcludedPeers); i2p::context.GetRouterInfo ().GetIdentHash () , 0, false, &m_ExcludedPeers);
m_ExcludedPeers.insert (floodfill); m_ExcludedPeers.insert (floodfill);
m_CreationTime = i2p::util::GetSecondsSinceEpoch (); m_LastRequestTime = i2p::util::GetSecondsSinceEpoch ();
return msg; return msg;
} }
@ -100,7 +111,9 @@ namespace data
else else
ret.first->second->SetRequestComplete (requestComplete); ret.first->second->SetRequestComplete (requestComplete);
} }
if (i2p::util::GetSecondsSinceEpoch () > ret.first->second->GetLastRequestTime () + MIN_REQUEST_TIME)
if (!SendNextRequest (ret.first->second)) // try next floodfill
m_RequestedDestinations.erase (ret.first); // delete request if failed
return nullptr; return nullptr;
} }
} }
@ -147,7 +160,7 @@ namespace data
bool done = false; bool done = false;
if (ts < dest->GetCreationTime () + MAX_REQUEST_TIME) // request becomes worthless if (ts < dest->GetCreationTime () + MAX_REQUEST_TIME) // request becomes worthless
{ {
if (ts > dest->GetCreationTime () + MIN_REQUEST_TIME) // retry in no response after min interval if (ts > dest->GetLastRequestTime () + MIN_REQUEST_TIME) // try next floodfill if no response after min interval
done = !SendNextRequest (dest); done = !SendNextRequest (dest);
} }
else // delete obsolete request else // delete obsolete request

8
libi2pd/NetDbRequests.h

@ -30,9 +30,8 @@ namespace data
typedef std::function<void (std::shared_ptr<RouterInfo>)> RequestComplete; typedef std::function<void (std::shared_ptr<RouterInfo>)> RequestComplete;
RequestedDestination (const IdentHash& destination, bool isExploratory = false, bool direct = true): RequestedDestination (const IdentHash& destination, bool isExploratory = false, bool direct = true);
m_Destination (destination), m_IsExploratory (isExploratory), m_IsDirect (direct), m_CreationTime (0) {}; ~RequestedDestination ();
~RequestedDestination () { if (m_RequestComplete) m_RequestComplete (nullptr); };
const IdentHash& GetDestination () const { return m_Destination; }; const IdentHash& GetDestination () const { return m_Destination; };
int GetNumExcludedPeers () const { return m_ExcludedPeers.size (); }; int GetNumExcludedPeers () const { return m_ExcludedPeers.size (); };
@ -42,6 +41,7 @@ namespace data
bool IsDirect () const { return m_IsDirect; }; bool IsDirect () const { return m_IsDirect; };
bool IsExcluded (const IdentHash& ident) const { return m_ExcludedPeers.count (ident); }; bool IsExcluded (const IdentHash& ident) const { return m_ExcludedPeers.count (ident); };
uint64_t GetCreationTime () const { return m_CreationTime; }; uint64_t GetCreationTime () const { return m_CreationTime; };
uint64_t GetLastRequestTime () const { return m_LastRequestTime; };
std::shared_ptr<I2NPMessage> CreateRequestMessage (std::shared_ptr<const RouterInfo>, std::shared_ptr<const i2p::tunnel::InboundTunnel> replyTunnel); std::shared_ptr<I2NPMessage> CreateRequestMessage (std::shared_ptr<const RouterInfo>, std::shared_ptr<const i2p::tunnel::InboundTunnel> replyTunnel);
std::shared_ptr<I2NPMessage> CreateRequestMessage (const IdentHash& floodfill); std::shared_ptr<I2NPMessage> CreateRequestMessage (const IdentHash& floodfill);
@ -56,7 +56,7 @@ namespace data
IdentHash m_Destination; IdentHash m_Destination;
bool m_IsExploratory, m_IsDirect; bool m_IsExploratory, m_IsDirect;
std::set<IdentHash> m_ExcludedPeers; std::set<IdentHash> m_ExcludedPeers;
uint64_t m_CreationTime; uint64_t m_CreationTime, m_LastRequestTime; // in seconds
RequestComplete m_RequestComplete; RequestComplete m_RequestComplete;
}; };

Loading…
Cancel
Save