Changeset 13801


Ignore:
Timestamp:
Jan 17, 2013, 8:08:21 PM (8 years ago)
Author:
jordan
Message:

in getReconnectIntervalSecs(), raise the interval between reconnection attempts if the peer was previously unreachable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr.c

    r13798 r13801  
    9494
    9595    /** how long we'll let requests we've made linger before we cancel them */
    96     REQUEST_TTL_SECS = 120,
     96    REQUEST_TTL_SECS = 90,
    9797
    9898    NO_BLOCKS_CANCEL_HISTORY = 120,
     
    32943294getReconnectIntervalSecs (const struct peer_atom * atom, const time_t now)
    32953295{
    3296     int sec;
    3297 
    3298     /* if we were recently connected to this peer and transferring piece
    3299      * data, try to reconnect to them sooner rather that later -- we don't
    3300      * want network troubles to get in the way of a good peer. */
    3301     if ((now - atom->piece_data_time) <= (MINIMUM_RECONNECT_INTERVAL_SECS * 2))
    3302         sec = MINIMUM_RECONNECT_INTERVAL_SECS;
    3303 
    3304     /* don't allow reconnects more often than our minimum */
    3305     else if ((now - atom->time) < MINIMUM_RECONNECT_INTERVAL_SECS)
    3306         sec = MINIMUM_RECONNECT_INTERVAL_SECS;
    3307 
    3308     /* otherwise, the interval depends on how many times we've tried
    3309      * and failed to connect to the peer */
    3310     else switch (atom->numFails) {
    3311         case 0: sec = 0; break;
    3312         case 1: sec = 5; break;
    3313         case 2: sec = 2 * 60; break;
    3314         case 3: sec = 15 * 60; break;
    3315         case 4: sec = 30 * 60; break;
    3316         case 5: sec = 60 * 60; break;
    3317         default: sec = 120 * 60; break;
    3318     }
    3319 
    3320     /* penalize peers that were unreachable the last time we tried */
    3321     if (atom->flags2 & MYFLAG_UNREACHABLE)
    3322         sec += sec;
    3323 
    3324     dbgmsg ("reconnect interval for %s is %d seconds", tr_atomAddrStr (atom), sec);
    3325     return sec;
     3296  int sec;
     3297  const bool unreachable = (atom->flags2 & MYFLAG_UNREACHABLE) != 0;
     3298
     3299  /* if we were recently connected to this peer and transferring piece
     3300   * data, try to reconnect to them sooner rather that later -- we don't
     3301   * want network troubles to get in the way of a good peer. */
     3302  if (!unreachable && ((now - atom->piece_data_time) <= (MINIMUM_RECONNECT_INTERVAL_SECS * 2)))
     3303    sec = MINIMUM_RECONNECT_INTERVAL_SECS;
     3304
     3305  /* otherwise, the interval depends on how many times we've tried
     3306   * and failed to connect to the peer */
     3307  else
     3308    {
     3309      int step = atom->numFails;
     3310
     3311      /* penalize peers that were unreachable the last time we tried */
     3312      if (unreachable)
     3313        step += 2;
     3314 
     3315      switch (step)
     3316        {
     3317          case 0: sec = 0; break;
     3318          case 1: sec = 10; break;
     3319          case 2: sec = 60 * 2; break;
     3320          case 3: sec = 60 * 15; break;
     3321          case 4: sec = 60 * 30; break;
     3322          case 5: sec = 60 * 60; break;
     3323          default: sec = 60 * 120; break;
     3324        }
     3325    }
     3326
     3327  dbgmsg ("reconnect interval for %s is %d seconds", tr_atomAddrStr (atom), sec);
     3328  return sec;
    33263329}
    33273330
Note: See TracChangeset for help on using the changeset viewer.