Changeset 8370


Ignore:
Timestamp:
May 9, 2009, 6:08:21 AM (12 years ago)
Author:
charles
Message:

(trunk) improvements to peer-mgr.c. also, new temporary assert()s to help test them.

Location:
trunk/libtransmission
Files:
2 edited

Legend:

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

    r8358 r8370  
    361361
    362362static void
    363 removePeer( Torrent * t,
    364             tr_peer * peer )
    365 {
    366     tr_peer *          removed;
    367     struct peer_atom * atom;
     363removePeer( Torrent * t, tr_peer * peer )
     364{
     365    tr_peer * removed;
     366    struct peer_atom * atom = peer->atom;
     367assert( atom == getExistingAtom( t, &peer->addr ) );
    368368
    369369    assert( torrentIsLocked( t ) );
    370 
    371     atom = getExistingAtom( t, &peer->addr );
    372370    assert( atom );
     371
    373372    atom->time = time( NULL );
    374373
     
    912911
    913912static void
    914 addStrike( Torrent * t,
    915            tr_peer * peer )
     913addStrike( Torrent * t, tr_peer * peer )
    916914{
    917915    tordbg( t, "increasing peer %s strike count to %d",
     
    921919    if( ++peer->strikes >= MAX_BAD_PIECES_PER_PEER )
    922920    {
    923         struct peer_atom * atom = getExistingAtom( t, &peer->addr );
     921        struct peer_atom * atom = peer->atom;
     922assert( atom == getExistingAtom( t, &peer->addr ) );
    924923        atom->myflags |= MYFLAG_BANNED;
    925924        peer->doPurge = 1;
     
    10101009            /* update our atom */
    10111010            if( peer ) {
    1012                 struct peer_atom * a = getExistingAtom( t, &peer->addr );
    1013                 a->uploadOnly = e->uploadOnly ? UPLOAD_ONLY_YES : UPLOAD_ONLY_NO;
     1011assert( peer->atom == getExistingAtom( t, &peer->addr ) );
     1012                peer->atom->uploadOnly = e->uploadOnly ? UPLOAD_ONLY_YES : UPLOAD_ONLY_NO;
    10141013            }
    10151014            break;
     
    10381037
    10391038            /* update our atom */
    1040             if( peer ) {
    1041                 struct peer_atom * a = getExistingAtom( t, &peer->addr );
    1042                 if( e->wasPieceData )
    1043                     a->piece_data_time = now;
     1039            if( peer && e->wasPieceData ) {
     1040assert( peer->atom == getExistingAtom( t, &peer->addr ) );
     1041                peer->atom->piece_data_time = now;
    10441042            }
    10451043
     
    10801078
    10811079            /* update our atom */
    1082             if( peer ) {
    1083                 struct peer_atom * a = getExistingAtom( t, &peer->addr );
    1084                 if( e->wasPieceData )
    1085                     a->piece_data_time = now;
     1080            if( peer && e->wasPieceData ) {
     1081assert( peer->atom == getExistingAtom( t, &peer->addr ) );
     1082                peer->atom->piece_data_time = now;
    10861083            }
    10871084
     
    10931090            if( peer )
    10941091            {
    1095                 struct peer_atom * atom = getExistingAtom( t, &peer->addr );
     1092                struct peer_atom * atom = peer->atom;
    10961093                const int peerIsSeed = e->progress >= 1.0;
     1094assert( peer->atom == getExistingAtom( t, &peer->addr ) );
    10971095                if( peerIsSeed ) {
    10981096                    tordbg( t, "marking peer %s as a seed", tr_peerIoAddrStr( &atom->addr, atom->port ) );
     
    13181316
    13191317                peer->port = port;
     1318                peer->atom = atom;
    13201319                peer->io = tr_handshakeStealIO( handshake ); /* this steals its refcount too, which is
    13211320                                                                balanced by our unref in peerDestructor()  */
     
    15551554            if( peer->addr.type == af )
    15561555            {
    1557                 const struct peer_atom * atom = getExistingAtom( t, &peer->addr );
     1556                const struct peer_atom * atom = peer->atom;
     1557assert( atom == getExistingAtom( t, &peer->addr ) );
    15581558
    15591559                assert( tr_isAddress( &peer->addr ) );
     
    17461746    {
    17471747        const tr_peer * peer = peers[i];
    1748         const struct peer_atom * atom = getExistingAtom( t, &peer->addr );
     1748        const struct peer_atom * atom = peer->atom;
     1749assert( atom == getExistingAtom( t, &peer->addr ) );
    17491750
    17501751        if( peer->io == NULL ) /* not connected */
     
    18261827    now = tr_date( );
    18271828
    1828     for( i = 0; i < size; ++i )
     1829    for( i=0; i<size; ++i )
    18291830    {
    18301831        char *                   pch;
    18311832        const tr_peer *          peer = peers[i];
    1832         const struct peer_atom * atom = getExistingAtom( t, &peer->addr );
     1833        const struct peer_atom * atom = peer->atom;
    18331834        tr_peer_stat *           stat = ret + i;
     1835assert( atom == getExistingAtom( t, &peer->addr ) );
    18341836
    18351837        tr_ntop( &peer->addr, stat->addr, sizeof( stat->addr ) );
     
    19331935    {
    19341936        tr_peer * peer = peers[i];
    1935         struct peer_atom * atom = getExistingAtom( t, &peer->addr );
     1937        struct peer_atom * atom = peer->atom;
     1938assert( atom == getExistingAtom( t, &peer->addr ) );
    19361939
    19371940        if( peer->progress >= 1.0 ) /* choke all seeds */
     
    20522055    const tr_torrent *       tor = t->tor;
    20532056    const time_t             now = time( NULL );
    2054     const struct peer_atom * atom = getExistingAtom( t, &peer->addr );
     2057    const struct peer_atom * atom = peer->atom;
     2058assert( atom == getExistingAtom( t, &peer->addr ) );
    20552059
    20562060    /* if it's marked for purging, close it */
     
    22562260    assert( peer != NULL );
    22572261
     2262    atom = peer->atom;
     2263assert( atom == getExistingAtom( t, &peer->addr ) );
     2264
    22582265    /* if we transferred piece data, then they might be good peers,
    22592266       so reset their `numFails' weight to zero.  otherwise we connected
    22602267       to them fruitlessly, so mark it as another fail */
    2261     atom = getExistingAtom( t, &peer->addr );
    22622268    if( atom->piece_data_time )
    22632269        atom->numFails = 0;
  • trunk/libtransmission/peer-mgr.h

    r7712 r8370  
    6161};
    6262
     63/* opaque forward declaration */
     64struct peer_atom;
     65
    6366/**
    6467 * State information about a connected peer.
     
    8285    tr_address               addr;
    8386    struct tr_peerIo       * io;
     87    struct peer_atom       * atom;
    8488
    8589    struct tr_bitfield     * blame;
Note: See TracChangeset for help on using the changeset viewer.