mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 16:39:29 -05:00
moved TR filtering to beginning of TR handlign function. Makes it more consistent w.t.r. the displayed turtle statistics
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4223 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
f3ca5b9941
commit
7edcf59116
@ -1543,6 +1543,45 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
||||
if(TS_request_bounces.find(item->request_id) != TS_request_bounces.end())
|
||||
TS_request_bounces[item->request_id].push_back(time(NULL)) ;
|
||||
#endif
|
||||
// TR forwarding. We must pay attention not to flood the network. The policy is to force a statistical behavior
|
||||
// according to the followin grules:
|
||||
// - below a number of tunnel request forwards per second MAX_TR_FORWARD_PER_SEC, we keep the traffic
|
||||
// - if we get close to that limit, we drop long tunnels first with a probability that is larger for long tunnels
|
||||
//
|
||||
// Variables involved:
|
||||
// distance_to_maximum : in [0,inf] is the proportion of the current up TR speed with respect to the maximum allowed speed. This is estimated
|
||||
// as an average between the average number of TR over the 60 last seconds and the current TR up speed.
|
||||
// corrected_distance : in [0,inf] is a squeezed version of distance: small values become very small and large values become very large.
|
||||
// depth_peer_probability : basic probability of forwarding when the speed limit is reached.
|
||||
// forward_probability : final probability of forwarding the packet, per peer.
|
||||
//
|
||||
// When the number of peers increases, the speed limit is reached faster, but the behavior per peer is the same.
|
||||
//
|
||||
static const float depth_peer_probability[7] = { 1.0f,0.99f,0.9f,0.7f,0.4f,0.15f,0.1f } ;
|
||||
static const int TUNNEL_REQUEST_PACKET_SIZE = 50 ;
|
||||
static const int MAX_TR_FORWARD_PER_SEC = 20 ;
|
||||
static const int DISTANCE_SQUEEZING_POWER = 8 ;
|
||||
|
||||
float forward_probability ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||
_traffic_info_buffer.tr_dn_Bps += static_cast<RsTurtleItem*>(item)->serial_size() ;
|
||||
|
||||
float distance_to_maximum = std::min(100.0f,_traffic_info.tr_up_Bps/(float)(TUNNEL_REQUEST_PACKET_SIZE*MAX_TR_FORWARD_PER_SEC)) ;
|
||||
float corrected_distance = pow(distance_to_maximum,DISTANCE_SQUEEZING_POWER) ;
|
||||
forward_probability = pow(depth_peer_probability[std::min((uint16_t)6,item->depth)],corrected_distance) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "Forwarding probability: depth=" << item->depth << ", distance to max speed=" << distance_to_maximum << ", corrected=" << corrected_distance << ", prob.=" << forward_probability << std::endl;
|
||||
#endif
|
||||
if(forward_probability < 0.1)
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "Dropped packet!" << std::endl;
|
||||
#endif
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
// If the item contains an already handled tunnel request, give up. This
|
||||
// happens when the same tunnel request gets relayed by different peers. We
|
||||
@ -1552,8 +1591,6 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
||||
{
|
||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
_traffic_info_buffer.tr_dn_Bps += static_cast<RsTurtleItem*>(item)->serial_size() ;
|
||||
|
||||
std::map<TurtleTunnelRequestId,TurtleRequestInfo>::iterator it = _tunnel_requests_origins.find(item->request_id) ;
|
||||
|
||||
if(it != _tunnel_requests_origins.end())
|
||||
@ -1678,32 +1715,6 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
||||
std::cerr << " Forwarding tunnel request: Looking for online peers" << std::endl ;
|
||||
#endif
|
||||
|
||||
// TR forwarding. We must pay attention not to flood the network. The policy is to force a statistical behavior
|
||||
// according to the followin grules:
|
||||
// - below a number of tunnel request forwards per second MAX_TR_FORWARD_PER_SEC, we keep the traffic
|
||||
// - if we get close to that limit, we drop long tunnels first with a probability that is larger for long tunnels
|
||||
//
|
||||
// Variables involved:
|
||||
// distance_to_maximum : in [0,inf] is the proportion of the current up TR speed with respect to the maximum allowed speed. This is estimated
|
||||
// as an average between the average number of TR over the 60 last seconds and the current TR up speed.
|
||||
// corrected_distance : in [0,inf] is a squeezed version of distance: small values become very small and large values become very large.
|
||||
// depth_peer_probability : basic probability of forwarding when the speed limit is reached.
|
||||
// forward_probability : final probability of forwarding the packet, per peer.
|
||||
//
|
||||
// When the number of peers increases, the speed limit is reached faster, but the behavior per peer is the same.
|
||||
//
|
||||
static const float depth_peer_probability[7] = { 1.0f,0.99f,0.9f,0.7f,0.4f,0.15f,0.1f } ;
|
||||
static const int TUNNEL_REQUEST_PACKET_SIZE = 50 ;
|
||||
static const int MAX_TR_FORWARD_PER_SEC = 40 ;
|
||||
static const int DISTANCE_SQUEEZING_POWER = 8 ;
|
||||
|
||||
float distance_to_maximum = std::min(100.0f,_traffic_info.tr_up_Bps/(float)(TUNNEL_REQUEST_PACKET_SIZE*MAX_TR_FORWARD_PER_SEC)) ;
|
||||
float corrected_distance = pow(distance_to_maximum,DISTANCE_SQUEEZING_POWER) ;
|
||||
float forward_probability = pow(depth_peer_probability[std::min((uint16_t)6,item->depth)],corrected_distance) ;
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "Forwarding probability: depth=" << item->depth << ", distance to max speed=" << distance_to_maximum << ", corrected=" << corrected_distance << ", prob.=" << forward_probability << std::endl;
|
||||
#endif
|
||||
|
||||
for(std::list<std::string>::const_iterator it(onlineIds.begin());it!=onlineIds.end();++it)
|
||||
if(*it != item->PeerId() && RSRandom::random_f32() <= forward_probability)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user