final fixes to global routing algorithm. Ensured messages are kept long enough and re-tried less and less wth time. Corrected 2 routing bugs.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7278 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-04-15 22:10:53 +00:00
parent 06ef59856f
commit a929f80596
3 changed files with 26 additions and 10 deletions

View File

@ -48,7 +48,7 @@ static const time_t RS_GROUTER_MEAN_EXPECTED_RTT = 30 ; // refer
static const uint32_t GROUTER_ITEM_DISTANCE_UNIT = 256 ; // One unit of distance between two peers
static const uint32_t GROUTER_ITEM_MAX_TRAVEL_DISTANCE = 6*256 ; // 6 distance units. That is a lot.
static const uint32_t GROUTER_ITEM_MAX_CACHE_KEEP_TIME = 1200 ; // should be probably extended. Items older than that should always be removed.
static const uint32_t GROUTER_ITEM_MAX_CACHE_KEEP_TIME = 30*86400 ; // Items are kept in cache for 1 month, to allow sending to peers while not online.
static const uint32_t RS_GROUTER_ROUTING_STATE_UNKN = 0x0000 ; // unknown. Unused.
static const uint32_t RS_GROUTER_ROUTING_STATE_PEND = 0x0001 ; // item is pending. Should be sent asap.

View File

@ -269,6 +269,19 @@ int p3GRouter::tick()
return 0 ;
}
time_t p3GRouter::computeNextTimeDelay(time_t stored_time)
{
// Computes the time to wait before re-sending the object, based on how long it has been stored already.
if(stored_time < 2*60 ) return 10 ; // re-schedule every 10 secs for items not older than 2 mins. This ensures a rapid spread when peers are online.
if(stored_time < 40*60 ) return 10 * 60 ; // then, try every 10 mins for 40 mins
if(stored_time < 4*3600) return 3600 ; // then, try every hour for 4 hours
if(stored_time < 10*24*3600) return 12*3600 ; // then, try every 12 hours for 10 days
if(stored_time < 6*30*24*3600) return 5*86400 ; // then, try every 5 days for 6 months
return 6*30*86400 ; // default: try every 5 months
}
RsSerialiser *p3GRouter::setupSerialiser()
{
RsSerialiser *rss = new RsSerialiser ;
@ -303,7 +316,7 @@ void p3GRouter::autoWash()
_pending_messages.erase(it) ;
it = tmp ;
}
else if(it->second.data_item != NULL && it->second.status_flags == RS_GROUTER_ROUTING_STATE_SENT && it->second.last_sent+RS_GROUTER_ROUTING_WAITING_TIME < now)
else if(it->second.data_item != NULL && it->second.status_flags == RS_GROUTER_ROUTING_STATE_SENT && computeNextTimeDelay(it->second.last_sent - it->second.received_time) + it->second.last_sent < now)
{
it->second.status_flags = RS_GROUTER_ROUTING_STATE_PEND ;
#ifdef GROUTER_DEBUG
@ -768,7 +781,7 @@ void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
#ifdef GROUTER_DEBUG
grouter_debug() << " No tries left. Removing item from pending list." << std::endl;
#endif
if(it->second.status_flags != RS_GROUTER_ROUTING_STATE_ARVD)
if(it->second.status_flags != RS_GROUTER_ROUTING_STATE_ARVD && next_state != RS_GROUTER_ROUTING_STATE_ARVD)
{
next_state = RS_GROUTER_ROUTING_STATE_DEAD ;
forward_state = RS_GROUTER_ACK_STATE_GVNP ;
@ -853,6 +866,9 @@ void p3GRouter::handleRecvDataItem(RsGRouterGenericDataItem *item)
grouter_debug() << " Item is already there. Nothing to do. Should we update the cache?" << std::endl;
#endif
item_copy = itr->second.data_item ;
if(itr->second.status_flags == RS_GROUTER_ROUTING_STATE_ARVD)
returned_ack = RS_GROUTER_ACK_STATE_IRCV ;
}
else // item is not known. Store it into pending msgs. We make a copy, since the item will be deleted otherwise.
{
@ -973,7 +989,7 @@ void p3GRouter::sendACK(const RsPeerId& peer, GRouterMsgPropagationId mid, uint3
item->state = ack_flags ;
item->mid = mid ;
item->PeerId(peer) ;
item->PeerId(peer) ;
sendItem(item) ;
}
@ -1135,14 +1151,13 @@ void p3GRouter::debugDump()
for(std::map<GRouterMsgPropagationId, GRouterRoutingInfo>::iterator it(_pending_messages.begin());it!=_pending_messages.end();++it)
{
grouter_debug() << " Msg id: " << std::hex << it->first << std::dec << " Local Origin: " << it->second.origin.toStdString() ;
grouter_debug() << " Destination: " << it->second.destination_key ;
grouter_debug() << " Time : " << now - it->second.last_sent << " secs ago.";
grouter_debug() << " Status: " << statusString[it->second.status_flags] << std::endl;
grouter_debug() << " Destination: " << it->second.destination_key ;
grouter_debug() << " Received : " << now - it->second.received_time << " secs ago.";
grouter_debug() << " Last sent : " << now - it->second.last_sent << " secs ago.";
grouter_debug() << " Status: " << statusString[it->second.status_flags] << std::endl;
grouter_debug() << " Interval: " << computeNextTimeDelay(it->second.last_sent - it->second.received_time) << std::endl;
}
// << " Last : " << it->second.tried_friends.front().friend_id.toStdString() << std::endl;
// << " Probabilities: " << std::endl;
grouter_debug() << " Routing matrix: " << std::endl;
_routing_matrix.debugDump() ;

View File

@ -168,6 +168,7 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
static uint32_t computeBranchingFactor(const std::vector<RsPeerId>& friends,uint32_t dist) ;
std::set<uint32_t> computeRoutingFriends(const std::vector<RsPeerId>& friends,const std::vector<float>& probas,uint32_t N) ;
static float computeMatrixContribution(float base,uint32_t time_shift,float probability) ;
static time_t computeNextTimeDelay(time_t duration) ;
uint32_t computeRandomDistanceIncrement(const RsPeerId& pid,const GRouterKeyId& destination_id) ;