Changeset 3416


Ignore:
Timestamp:
Oct 15, 2007, 4:01:42 PM (14 years ago)
Author:
charles
Message:

fix choke fibrillation bug in new connections

Location:
trunk/libtransmission
Files:
3 edited

Legend:

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

    r3411 r3416  
    140140        struct evbuffer * buf = evbuffer_new( );
    141141        char timestr[64];
    142         evbuffer_add_printf( buf, "[%s] %s: ",
    143                              tr_getLogTimeStr( timestr, sizeof(timestr) ),
    144                             t->tor->info.name );
     142        evbuffer_add_printf( buf, "[%s] ", tr_getLogTimeStr( timestr, sizeof(timestr) ) );
     143        if( t != NULL )
     144            evbuffer_add_printf( buf, "%s ", t->tor->info.name );
    145145        va_start( args, fmt );
    146146        evbuffer_add_vprintf( buf, fmt, args );
     
    956956    if( getExistingHandshake( manager->incomingHandshakes, addr ) == NULL )
    957957    {
    958         tr_peerIo * io = tr_peerIoNewIncoming( manager->handle, addr, port, socket );
    959 
    960         tr_handshake * handshake = tr_handshakeNew( io,
    961                                                     manager->handle->encryptionMode,
    962                                                     myHandshakeDoneCB,
    963                                                     manager );
     958        tr_peerIo * io;
     959        tr_handshake * handshake;
     960
     961        tordbg( NULL, "Got an INCOMING connection with %s", tr_peerIoAddrStr( addr, port ) );
     962
     963        io = tr_peerIoNewIncoming( manager->handle, addr, port, socket );
     964
     965        handshake = tr_handshakeNew( io,
     966                                     manager->handle->encryptionMode,
     967                                     myHandshakeDoneCB,
     968                                     manager );
    964969
    965970        tr_ptrArrayInsertSorted( manager->incomingHandshakes, handshake, handshakeCompare );
     
    14301435{
    14311436    int i, peerCount, size=0, unchoked=0;
    1432     const time_t ignorePeersNewerThan = time(NULL) - MIN_CHOKE_PERIOD_SEC;
     1437    const time_t fibrillationTime = time(NULL) - MIN_CHOKE_PERIOD_SEC;
    14331438    tr_peer ** peers = getConnectedPeers( t, &peerCount );
    14341439    struct ChokeData * choke = tr_new0( struct ChokeData, peerCount );
     
    14411446        tr_peer * peer = peers[i];
    14421447        struct ChokeData * node;
    1443         if( peer->chokeChangedAt > ignorePeersNewerThan )
     1448        if( peer->chokeChangedAt > fibrillationTime )
    14441449            continue;
    14451450
     
    15661571getPeerCandidates( Torrent * t, int * setmeSize )
    15671572{
    1568     int i, insize, outsize;
     1573    int i, atomCount, retCount;
    15691574    struct peer_atom ** atoms;
    15701575    struct peer_atom ** ret;
     
    15741579    assert( torrentIsLocked( t ) );
    15751580
    1576     atoms = (struct peer_atom**) tr_ptrArrayPeek( t->pool, &insize );
    1577     ret = tr_new( struct peer_atom*, insize );
    1578     for( i=outsize=0; i<insize; ++i )
     1581    atoms = (struct peer_atom**) tr_ptrArrayPeek( t->pool, &atomCount );
     1582    ret = tr_new( struct peer_atom*, atomCount );
     1583    for( i=retCount=0; i<atomCount; ++i )
    15791584    {
    15801585        struct peer_atom * atom = atoms[i];
     
    16091614        }
    16101615
    1611         ret[outsize++] = atom;
    1612     }
    1613 
    1614     qsort( ret, outsize, sizeof(struct peer_atom*), compareAtomByTime );
    1615     *setmeSize = outsize;
     1616        ret[retCount++] = atom;
     1617    }
     1618
     1619    qsort( ret, retCount, sizeof(struct peer_atom*), compareAtomByTime );
     1620    *setmeSize = retCount;
    16161621    return ret;
    16171622}
     
    16541659            struct peer_atom * atom = candidates[i];
    16551660
    1656             tr_peerIo * io = tr_peerIoNewOutgoing( mgr->handle, &atom->addr, atom->port, t->hash );
     1661            tr_peerIo * io;
     1662
     1663            tordbg( t, "Starting an OUTGOING connection with %s",
     1664                       tr_peerIoAddrStr( &atom->addr, atom->port ) );
     1665
     1666            io = tr_peerIoNewOutgoing( mgr->handle, &atom->addr, atom->port, t->hash );
    16571667
    16581668            tr_handshake * handshake = tr_handshakeNew( io,
  • trunk/libtransmission/peer-msgs.c

    r3411 r3416  
    389389}
    390390
    391 void
     391#define MIN_CHOKE_PERIOD_SEC 10
     392
     393int
    392394tr_peerMsgsSetChoke( tr_peermsgs * msgs, int choke )
    393395{
     396    int ret;
     397    const time_t fibrillationTime = time(NULL) - MIN_CHOKE_PERIOD_SEC;
     398
    394399    assert( msgs != NULL );
    395400    assert( msgs->info != NULL );
    396401    assert( choke==0 || choke==1 );
    397402
    398     if( msgs->info->peerIsChoked != choke )
     403    if( msgs->info->chokeChangedAt > fibrillationTime )
     404    {
     405        dbgmsg( msgs, "Not changing choke to %d to avoid fibrillation", choke );
     406        ret = FALSE;
     407    }
     408    else if( msgs->info->peerIsChoked != choke )
    399409    {
    400410        msgs->info->peerIsChoked = choke;
    401         tr_list * walk;
    402411       
    403412        if( choke )
     413        {
     414            tr_list * walk;
    404415            for( walk = msgs->peerAskedFor; walk != NULL; )
    405416            {
     
    414425                walk = next;
    415426            }
     427        }
    416428
    417429        protocolSendChoke( msgs, choke );
    418430        msgs->info->chokeChangedAt = time( NULL );
    419     }
     431        ret = TRUE;
     432    }
     433
     434    return ret;
    420435}
    421436
     
    941956        case BT_BITFIELD: {
    942957            const int clientIsSeed = tr_cpGetStatus( msgs->torrent->completion ) != TR_CP_INCOMPLETE;
     958            dbgmsg( msgs, "got a bitfield" );
    943959            assert( msglen == msgs->info->have->len );
    944960            tr_peerIoReadBytes( msgs->io, inbuf, msgs->info->have->bits, msglen );
  • trunk/libtransmission/peer-msgs.h

    r3349 r3416  
    3030
    3131
    32 void         tr_peerMsgsSetChoke( tr_peermsgs *, int doChoke );
     32int          tr_peerMsgsSetChoke( tr_peermsgs *, int doChoke );
    3333
    3434void         tr_peerMsgsHave( tr_peermsgs * msgs,
Note: See TracChangeset for help on using the changeset viewer.