dht timeout tweak

This commit is contained in:
Jeff Becker 2020-01-10 10:45:25 -05:00
parent ac46d99107
commit 8bb492da6e
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
2 changed files with 20 additions and 27 deletions

View File

@ -13,8 +13,7 @@ namespace llarp
{ {
namespace dht namespace dht
{ {
template < typename K, typename V, typename K_Hash, template < typename K, typename V, typename K_Hash >
llarp_time_t requestTimeoutMS = 30000UL >
struct TXHolder struct TXHolder
{ {
using TXPtr = std::unique_ptr< TX< K, V > >; using TXPtr = std::unique_ptr< TX< K, V > >;
@ -72,7 +71,7 @@ namespace llarp
void void
NewTX(const TXOwner& askpeer, const TXOwner& whoasked, const K& k, NewTX(const TXOwner& askpeer, const TXOwner& whoasked, const K& k,
TX< K, V >* t); TX< K, V >* t, llarp_time_t requestTimeoutMS = 15000);
/// mark tx as not fond /// mark tx as not fond
void void
@ -93,11 +92,9 @@ namespace llarp
Expire(llarp_time_t now); Expire(llarp_time_t now);
}; };
template < typename K, typename V, typename K_Hash, template < typename K, typename V, typename K_Hash >
llarp_time_t requestTimeoutMS >
const TX< K, V >* const TX< K, V >*
TXHolder< K, V, K_Hash, requestTimeoutMS >::GetPendingLookupFrom( TXHolder< K, V, K_Hash >::GetPendingLookupFrom(const TXOwner& owner) const
const TXOwner& owner) const
{ {
auto itr = tx.find(owner); auto itr = tx.find(owner);
if(itr == tx.end()) if(itr == tx.end())
@ -108,12 +105,12 @@ namespace llarp
return itr->second.get(); return itr->second.get();
} }
template < typename K, typename V, typename K_Hash, template < typename K, typename V, typename K_Hash >
llarp_time_t requestTimeoutMS >
void void
TXHolder< K, V, K_Hash, requestTimeoutMS >::NewTX(const TXOwner& askpeer, TXHolder< K, V, K_Hash >::NewTX(const TXOwner& askpeer,
const TXOwner& whoasked, const TXOwner& whoasked, const K& k,
const K& k, TX< K, V >* t) TX< K, V >* t,
llarp_time_t requestTimeoutMS)
{ {
(void)whoasked; (void)whoasked;
tx.emplace(askpeer, std::unique_ptr< TX< K, V > >(t)); tx.emplace(askpeer, std::unique_ptr< TX< K, V > >(t));
@ -131,11 +128,10 @@ namespace llarp
} }
} }
template < typename K, typename V, typename K_Hash, template < typename K, typename V, typename K_Hash >
llarp_time_t requestTimeoutMS >
void void
TXHolder< K, V, K_Hash, requestTimeoutMS >::NotFound( TXHolder< K, V, K_Hash >::NotFound(const TXOwner& from,
const TXOwner& from, const std::unique_ptr< Key_t >& next) const std::unique_ptr< Key_t >& next)
{ {
auto txitr = tx.find(from); auto txitr = tx.find(from);
if(txitr == tx.end()) if(txitr == tx.end())
@ -148,12 +144,10 @@ namespace llarp
Inform(from, txitr->second->target, {}, true, true); Inform(from, txitr->second->target, {}, true, true);
} }
template < typename K, typename V, typename K_Hash, template < typename K, typename V, typename K_Hash >
llarp_time_t requestTimeoutMS >
void void
TXHolder< K, V, K_Hash, requestTimeoutMS >::Inform(TXOwner from, K key, TXHolder< K, V, K_Hash >::Inform(TXOwner from, K key,
std::vector< V > values, std::vector< V > values, bool sendreply,
bool sendreply,
bool removeTimeouts) bool removeTimeouts)
{ {
auto range = waiting.equal_range(key); auto range = waiting.equal_range(key);
@ -187,15 +181,14 @@ namespace llarp
} }
} }
template < typename K, typename V, typename K_Hash, template < typename K, typename V, typename K_Hash >
llarp_time_t requestTimeoutMS >
void void
TXHolder< K, V, K_Hash, requestTimeoutMS >::Expire(llarp_time_t now) TXHolder< K, V, K_Hash >::Expire(llarp_time_t now)
{ {
auto itr = timeouts.begin(); auto itr = timeouts.begin();
while(itr != timeouts.end()) while(itr != timeouts.end())
{ {
if(now > itr->second && now - itr->second >= requestTimeoutMS) if(now >= itr->second)
{ {
Inform(TXOwner{}, itr->first, {}, true, false); Inform(TXOwner{}, itr->first, {}, true, false);
itr = timeouts.erase(itr); itr = timeouts.erase(itr);

View File

@ -36,7 +36,7 @@ namespace llarp
/// determine if this request has timed out /// determine if this request has timed out
bool bool
IsTimedOut(llarp_time_t now, llarp_time_t timeout = 60000) const IsTimedOut(llarp_time_t now, llarp_time_t timeout = 20000) const
{ {
if(now <= m_created) if(now <= m_created)
return false; return false;