Ignore:
Timestamp:
Dec 20, 2008, 10:19:34 PM (12 years ago)
Author:
charles
Message:

try to rework the bandwidth code yet again s.t. it satisfies all three: (1) fairly distributes bandwidth across all peers, (2) scales well in high-bandwidth situations, (3) is good at hitting and staying at bandwidth limits/goals

File:
1 edited

Legend:

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

    r7434 r7441  
    5858   
    5959    /* how frequently to reallocate bandwidth */
    60     BANDWIDTH_PERIOD_MSEC = 100,
     60    BANDWIDTH_PERIOD_MSEC = 500,
    6161
    6262    /* max # of peers to ask fer per torrent per reconnect pulse */
     
    144144    tr_ptrArray     * torrents; /* Torrent */
    145145    tr_ptrArray     * incomingHandshakes; /* tr_handshake */
     146    tr_ptrArray     * finishedHandshakes; /* tr_handshake */
    146147    tr_timer        * bandwidthTimer;
    147148};
     
    464465    m->torrents = tr_ptrArrayNew( );
    465466    m->incomingHandshakes = tr_ptrArrayNew( );
     467    m->finishedHandshakes = tr_ptrArrayNew( );
    466468    m->bandwidthTimer = tr_timerNew( session, bandwidthPulse, m, BANDWIDTH_PERIOD_MSEC );
    467469    return m;
     
    471473tr_peerMgrFree( tr_peerMgr * manager )
    472474{
     475    tr_handshake * handshake;
     476
    473477    managerLock( manager );
    474478
     
    481485
    482486    tr_ptrArrayFree( manager->incomingHandshakes, NULL );
     487
     488    while(( handshake = tr_ptrArrayPop( manager->finishedHandshakes )))
     489        tr_handshakeFree( handshake );
     490
     491    tr_ptrArrayFree( manager->finishedHandshakes, NULL );
    483492
    484493    /* free the torrents. */
     
    11951204/* FIXME: this is kind of a mess. */
    11961205static tr_bool
    1197 myHandshakeDoneCB( tr_handshake *  handshake,
    1198                    tr_peerIo *    io,
     1206myHandshakeDoneCB( tr_handshake  *  handshake,
     1207                   tr_peerIo     * io,
    11991208                   int             isConnected,
    12001209                   const uint8_t * peer_id,
    1201                    void *          vmanager )
     1210                   void          * vmanager )
    12021211{
    12031212    tr_bool            ok = isConnected;
     
    12411250                ++atom->numFails;
    12421251        }
    1243 
    1244         tr_peerIoFree( io );
    12451252    }
    12461253    else /* looking good */
     
    12561263            tordbg( t, "banned peer %s tried to reconnect",
    12571264                    tr_peerIoAddrStr( &atom->addr, atom->port ) );
    1258             tr_peerIoFree( io );
    12591265        }
    12601266        else if( tr_peerIoIsIncoming( io )
     
    12621268
    12631269        {
    1264             tr_peerIoFree( io );
    12651270        }
    12661271        else
     
    12701275            if( peer ) /* we already have this peer */
    12711276            {
    1272                 tr_peerIoFree( io );
    12731277            }
    12741278            else
     
    12861290
    12871291                peer->port = port;
    1288                 peer->io = io;
     1292                peer->io = tr_handshakeStealIO( handshake );
    12891293                tr_peerMsgsNew( t->tor, peer, peerCallbackFunc, t, &peer->msgsTag );
    12901294                tr_peerIoSetBandwidth( io, peer->bandwidth );
     
    12941298        }
    12951299    }
     1300
     1301    if( !success )
     1302        tr_ptrArrayAppend( manager->finishedHandshakes, handshake );
    12961303
    12971304    if( t )
     
    15451552        }
    15461553
    1547 #warning this for loop can be removed when we are sure the bug is fixed
    1548         for( i=0; i<peersReturning; ++i )
    1549             assert( tr_isAddress( &pex[i].addr ) );
    1550 
    15511554        assert( ( walk - pex ) == peersReturning );
    15521555        qsort( pex, peersReturning, sizeof( tr_pex ), tr_pexCompare );
    1553 
    1554 #warning this for loop can be removed when we are sure the bug is fixed
    1555         for( i=0; i<peersReturning; ++i )
    1556             assert( tr_isAddress( &pex[i].addr ) );
    15571556
    15581557        *setme_pex = pex;
     
    23952394bandwidthPulse( void * vmgr )
    23962395{
     2396    tr_handshake * handshake;
    23972397    tr_peerMgr * mgr = vmgr;
    23982398    managerLock( mgr );
    23992399
     2400    /* FIXME: this next line probably isn't necessary... */
    24002401    pumpAllPeers( mgr );
     2402
     2403    /* allocate bandwidth to the peers */
    24012404    tr_bandwidthAllocate( mgr->session->bandwidth, TR_UP, BANDWIDTH_PERIOD_MSEC );
    24022405    tr_bandwidthAllocate( mgr->session->bandwidth, TR_DOWN, BANDWIDTH_PERIOD_MSEC );
    2403     pumpAllPeers( mgr );
     2406
     2407    /* free all the finished handshakes */
     2408    while(( handshake = tr_ptrArrayPop( mgr->finishedHandshakes )))
     2409        tr_handshakeFree( handshake );
    24042410
    24052411    managerUnlock( mgr );
Note: See TracChangeset for help on using the changeset viewer.