Changeset 3428


Ignore:
Timestamp:
Oct 16, 2007, 12:55:17 AM (15 years ago)
Author:
charles
Message:

when deciding which peers to try to connect to, add some weights to punish peers that don't transfer piece data with us. We'll still give them another, but at longer intervals than better peers get.

Location:
trunk/libtransmission
Files:
2 edited

Legend:

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

    r3416 r3428  
    9898    uint8_t myflags; /* flags that aren't defined in added_f */
    9999    uint16_t port;
    100     struct in_addr addr;
     100    uint16_t numFails;
     101    struct in_addr addr;
    101102    time_t time;
    102103};
     
    289290    assert( torrentIsLocked( t ) );
    290291    return tr_ptrArrayFindSorted( t->pool, addr, comparePeerAtomToAddress );
    291 }
    292 
    293 static int
    294 peerIsKnown( const Torrent * t, const struct in_addr * addr )
    295 {
    296     return getExistingAtom( t, addr ) != NULL;
    297292}
    298293
     
    853848ensureAtomExists( Torrent * t, const struct in_addr * addr, uint16_t port, uint8_t flags, uint8_t from )
    854849{
    855     if( !peerIsKnown( t, addr ) )
     850    struct peer_atom * a = getExistingAtom( t, addr );
     851
     852    if( a != NULL )
    856853    {
    857854        struct peer_atom * a = tr_new0( struct peer_atom, 1 );
     
    859856        a->port = port;
    860857        a->flags = flags;
    861         a->from = from;
    862858        tordbg( t, "got a new atom: %s", tr_peerIoAddrStr(&a->addr,a->port) );
    863859        tr_ptrArrayInsertSorted( t->pool, a, comparePeerAtoms );
    864860    }
     861
     862    a->from = from;
    865863}
    866864
     
    907905    {
    908906        tr_peerIoFree( io );
     907
     908        if( t )
     909            ++getExistingAtom( t, in_addr )->numFails;
    909910    }
    910911    else /* looking good */
     
    977978tr_peerMgrAddPex( tr_peerMgr     * manager,
    978979                  const uint8_t  * torrentHash,
    979                   int              from,
     980                  uint8_t          from,
    980981                  const tr_pex   * pex,
    981982                  int              pexCount )
     
    996997tr_peerMgrAddPeers( tr_peerMgr    * manager,
    997998                    const uint8_t * torrentHash,
    998                     int             from,
     999                    uint8_t         from,
    9991000                    const uint8_t * peerCompact,
    10001001                    int             peerCount )
     
    15831584    for( i=retCount=0; i<atomCount; ++i )
    15841585    {
     1586        int wait, minWait, maxWait;
    15851587        struct peer_atom * atom = atoms[i];
    15861588
     
    16081610
    16091611        /* if we used this peer recently, give someone else a turn */
    1610         if( ( now - atom->time ) < 180 ) {
    1611             tordbg( t, "RECONNECT peer %d (%s) is in its grace period..",
    1612                     i, tr_peerIoAddrStr(&atom->addr,atom->port) );
     1612        minWait = 60;
     1613        maxWait = minWait * 5;
     1614        wait = atom->numFails * 10;
     1615        if( wait < minWait ) wait = minWait;
     1616        if( wait > maxWait ) wait = maxWait;
     1617        if( ( now - atom->time ) < wait ) {
     1618            tordbg( t, "RECONNECT peer %d (%s) is in its grace period of %d seconds..",
     1619                    i, tr_peerIoAddrStr(&atom->addr,atom->port), wait );
    16131620            continue;
    16141621        }
     
    16471654                       (int)MAX_RECONNECTIONS_PER_PULSE );
    16481655
    1649         /* disconnect some peers */
    1650         for( i=0; i<nBad; ++i )
    1651             removePeer( t, connections[i] );
     1656        /* disconnect some peers.
     1657           if we got transferred piece data, then they might be good peers,
     1658           so reset their `numFails' weight to zero.  otherwise we connected
     1659           to them fruitlessly, so mark it as another fail */
     1660        for( i=0; i<nBad; ++i ) {
     1661            tr_peer * peer = connections[i];
     1662            struct peer_atom * atom = getExistingAtom( t, &peer->in_addr );
     1663            if( peer->pieceDataActivityDate )
     1664                atom->numFails = 0;
     1665            else
     1666                ++atom->numFails;
     1667            removePeer( t, peer );
     1668        }
    16521669
    16531670        /* add some new ones */
  • trunk/libtransmission/peer-mgr.h

    r3265 r3428  
    4444void tr_peerMgrAddPeers( tr_peerMgr     * manager,
    4545                         const uint8_t  * torrentHash,
    46                          int              from,
     46                         uint8_t          from,
    4747                         const uint8_t  * peerCompact,
    4848                         int              peerCount );
     
    5050void tr_peerMgrAddPex( tr_peerMgr     * manager,
    5151                       const uint8_t  * torrentHash,
    52                        int              from,
     52                       uint8_t          from,
    5353                       const tr_pex   * pex,
    5454                       int              pexCount );
Note: See TracChangeset for help on using the changeset viewer.