Changeset 7456


Ignore:
Timestamp:
Dec 22, 2008, 12:52:44 AM (12 years ago)
Author:
charles
Message:

(trunk libT) minor cleanups found while diffing for backport to 1.4x in r7455

Location:
trunk/libtransmission
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/handshake.h

    r7441 r7456  
    1919
    2020#include "transmission.h"
     21#include "net.h"
    2122
    22 struct tr_address;
    2323struct tr_peerIo;
    2424typedef struct tr_handshake tr_handshake;
     
    3636                                        void *             doneUserData );
    3737
    38 const struct tr_address *
    39                       tr_handshakeGetAddr( const struct tr_handshake  * handshake,
     38const tr_address *     tr_handshakeGetAddr( const struct tr_handshake  * handshake,
    4039                                            tr_port                    * port );
    4140
  • trunk/libtransmission/peer-common.h

    r7404 r7456  
    6161    float            progress;     /* for PEER_PROGRESS */
    6262    int              err;          /* errno for GOT_ERROR */
    63     int              wasPieceData; /* for GOT_DATA */
     63    tr_bool          wasPieceData; /* for GOT_DATA */
    6464    tr_bool          uploadOnly;   /* for UPLOAD_ONLY */
    6565}
  • trunk/libtransmission/peer-io.c

    r7446 r7456  
    466466
    467467const char*
    468 tr_peerIoAddrStr( const tr_address * addr,
    469                   tr_port            port )
     468tr_peerIoAddrStr( const tr_address * addr, tr_port port )
    470469{
    471470    static char buf[512];
  • trunk/libtransmission/peer-mgr.c

    r7448 r7456  
    199199
    200200static int
    201 handshakeCompareToAddr( const void * va,
    202                         const void * vb )
     201handshakeCompareToAddr( const void * va, const void * vb )
    203202{
    204203    const tr_handshake * a = va;
     
    208207
    209208static int
    210 handshakeCompare( const void * a,
    211                   const void * b )
     209handshakeCompare( const void * a, const void * b )
    212210{
    213211    return handshakeCompareToAddr( a, tr_handshakeGetAddr( b, NULL ) );
     
    535533
    536534tr_bool
    537 tr_peerMgrPeerIsSeed( const tr_peerMgr   * mgr,
    538                       const uint8_t      * torrentHash,
    539                       const tr_address   * addr )
     535tr_peerMgrPeerIsSeed( const tr_peerMgr  * mgr,
     536                      const uint8_t     * torrentHash,
     537                      const tr_address  * addr )
    540538{
    541539    tr_bool isSeed = FALSE;
     
    633631
    634632static tr_piece_index_t *
    635 getPreferredPieces( Torrent * t, tr_piece_index_t  * pieceCount )
     633getPreferredPieces( Torrent * t, tr_piece_index_t * pieceCount )
    636634{
    637635    const tr_torrent  * tor = t->tor;
     
    831829        for( j=0; !handled && j<peerCount; )
    832830        {
    833             const tr_addreq_t val = tr_peerMsgsAddRequest( peers[j]->msgs, index, offset, length, FALSE );
     831            const tr_addreq_t val = tr_peerMsgsAddRequest( peers[j]->msgs, index, offset, length );
    834832            switch( val )
    835833            {
     
    858856        for( j=0; !handled && j<webseedCount; )
    859857        {
    860             const tr_addreq_t val = tr_webseedAddRequest( webseeds[j],
    861                                                           index, offset, length );
     858            const tr_addreq_t val = tr_webseedAddRequest( webseeds[j], index, offset, length );
    862859            switch( val )
    863860            {
     
    942939
    943940static void
    944 peerSuggestedPiece( Torrent            * t,
    945                     tr_peer            * peer,
    946                     tr_piece_index_t     pieceIndex,
    947                     int                  isFastAllowed )
    948 {
     941peerSuggestedPiece( Torrent            * t UNUSED,
     942                    tr_peer            * peer UNUSED,
     943                    tr_piece_index_t     pieceIndex UNUSED,
     944                    int                  isFastAllowed UNUSED )
     945{
     946#if 0
    949947    assert( t );
    950948    assert( peer );
     
    980978                const uint32_t offset = getBlockOffsetInPiece( tor, block );
    981979                const uint32_t length = tr_torBlockCountBytes( tor, block );
    982                 tr_peerMsgsAddRequest( peer->msgs, pieceIndex, offset, length, TRUE );
     980                tr_peerMsgsAddRequest( peer->msgs, pieceIndex, offset, length );
    983981                incrementPieceRequests( t, pieceIndex );
    984982            }
    985983        }
    986984    }
     985#endif
    987986}
    988987
    989988static void
    990 peerCallbackFunc( void * vpeer,
    991                   void * vevent,
    992                   void * vt )
    993 {
    994     tr_peer             * peer = vpeer; /* may be NULL if peer is a webseed */
    995     Torrent             * t = vt;
     989peerCallbackFunc( void * vpeer, void * vevent, void * vt )
     990{
     991    tr_peer * peer = vpeer; /* may be NULL if peer is a webseed */
     992    Torrent * t = vt;
    996993    const tr_peer_event * e = vevent;
    997994
     
    12041201/* FIXME: this is kind of a mess. */
    12051202static tr_bool
    1206 myHandshakeDoneCB( tr_handshake  *  handshake,
     1203myHandshakeDoneCB( tr_handshake  * handshake,
    12071204                   tr_peerIo     * io,
    12081205                   int             isConnected,
     
    13441341}
    13451342
    1346 static int
     1343static tr_bool
    13471344tr_isPex( const tr_pex * pex )
    13481345{
     
    13611358        managerLock( manager );
    13621359
    1363 
    13641360        t = getExistingTorrent( manager, torrentHash );
    13651361        if( !tr_sessionIsAddressBlocked( t->manager->session, &pex->addr ) )
    13661362            ensureAtomExists( t, &pex->addr, pex->port, pex->flags, from );
    1367    
     1363
    13681364        managerUnlock( manager );
    13691365    }
     
    15391535            {
    15401536                const struct peer_atom * atom = getExistingAtom( t, &peer->addr );
     1537
    15411538                assert( tr_isAddress( &peer->addr ) );
    15421539                walk->addr = peer->addr;
     
    15451542                if( peerPrefersCrypto( peer ) )
    15461543                    walk->flags |= ADDED_F_ENCRYPTION_FLAG;
    1547                 if( ( atom->uploadOnly == UPLOAD_ONLY_YES ) ||
    1548                     ( peer->progress >= 1.0 ) )
     1544                if( ( atom->uploadOnly == UPLOAD_ONLY_YES ) || ( peer->progress >= 1.0 ) )
    15491545                    walk->flags |= ADDED_F_SEED_FLAG;
    15501546                ++peersReturning;
     
    15551551        assert( ( walk - pex ) == peersReturning );
    15561552        qsort( pex, peersReturning, sizeof( tr_pex ), tr_pexCompare );
    1557 
    15581553        *setme_pex = pex;
    15591554    }
     
    16781673    const tr_torrent * tor;
    16791674    float              interval;
    1680     int                isSeed;
     1675    tr_bool            isSeed;
    16811676    int                peerCount;
    16821677    const tr_peer **   peers;
     
    16981693        if( isSeed || tr_cpPieceIsComplete( tor->completion, piece ) )
    16991694            tab[i] = -1;
    1700         else if( peerCount )
    1701         {
     1695        else if( peerCount ) {
    17021696            int j;
    17031697            for( j = 0; j < peerCount; ++j )
     
    18021796    webseeds = (const tr_webseed **) tr_ptrArrayPeek( t->webseeds, &size );
    18031797    for( i=0; i<size; ++i )
    1804     {
    18051798        if( tr_webseedIsActive( webseeds[i] ) )
    18061799            ++*setmeWebseedsSendingToUs;
    1807     }
    18081800
    18091801    managerUnlock( manager );
     
    18721864        tr_address               norm_addr;
    18731865
    1874         memcpy( &norm_addr, &peer->addr, sizeof( tr_address ) );
     1866        norm_addr = peer->addr;
    18751867        tr_normalizeV4Mapped( &norm_addr );
    18761868        tr_ntop( &norm_addr, stat->addr, sizeof( stat->addr ) );
     
    20482040    }
    20492041
    2050     for( i = 0; i < size; ++i )
     2042    for( i=0; i<size; ++i )
    20512043        tr_peerMsgsSetChoke( choke[i].peer->msgs, !choke[i].doUnchoke );
    20522044
     
    21052097            tr_bitfieldFree( tmp );
    21062098        }
    2107         if( peerHasEverything && ( !tr_torrentAllowsPex(tor) || (now-atom->time>=30 ))) {
     2099
     2100        if( peerHasEverything && ( !tr_torrentAllowsPex(tor) || (now-atom->time>=30 )))
     2101        {
    21082102            tordbg( t, "purging peer %s because we're both seeds",
    2109                    tr_peerIoAddrStr( &atom->addr, atom->port ) );
     2103                    tr_peerIoAddrStr( &atom->addr, atom->port ) );
    21102104            return TRUE;
    21112105        }
     
    23032297        if( nBad || nCandidates )
    23042298            tordbg( t, "reconnect pulse for [%s]: %d bad connections, "
    2305                    "%d connection candidates, %d atoms, max per pulse is %d",
    2306                    t->tor->info.name, nBad, nCandidates,
    2307                    tr_ptrArraySize( t->pool ),
    2308                    (int)MAX_RECONNECTIONS_PER_PULSE );
     2299                    "%d connection candidates, %d atoms, max per pulse is %d",
     2300                    t->tor->info.name, nBad, nCandidates,
     2301                    tr_ptrArraySize( t->pool ),
     2302                    (int)MAX_RECONNECTIONS_PER_PULSE );
    23092303
    23102304        /* disconnect some peers.
     
    23192313            else
    23202314                ++atom->numFails;
    2321              
    23222315            tordbg( t, "removing bad peer %s", tr_peerIoGetAddrStr( peer->io ) );
    23232316            removePeer( t, peer );
  • trunk/libtransmission/peer-msgs.c

    r7448 r7456  
    402402
    403403static void
    404 protocolSendRequest( tr_peermsgs *              msgs,
     404protocolSendRequest( tr_peermsgs               * msgs,
    405405                     const struct peer_request * req )
    406406{
     
    420420
    421421static void
    422 protocolSendCancel( tr_peermsgs *              msgs,
     422protocolSendCancel( tr_peermsgs               * msgs,
    423423                    const struct peer_request * req )
    424424{
     
    448448    tr_peerIoWriteUint32( io, out, index );
    449449
    450     dbgmsg( msgs, "sending Have %u...", index );
     450    dbgmsg( msgs, "sending Have %u", index );
    451451    dbgOutMessageLen( msgs );
    452452    pokeBatchPeriod( msgs, LOW_PRIORITY_INTERVAL_SECS );
     
    773773    tr_peerIoWriteUint32( msgs->peer->io, out, sizeof( uint8_t ) );
    774774    tr_peerIoWriteUint8 ( msgs->peer->io, out, weAreInterested ? BT_INTERESTED : BT_NOT_INTERESTED );
     775
    775776    pokeBatchPeriod( msgs, HIGH_PRIORITY_INTERVAL_SECS );
    776777    dbgOutMessageLen( msgs );
     
    876877    oldestAllowed = now - QUEUED_REQUEST_TTL_SECS;
    877878    reqListCopy( &tmp, &msgs->clientWillAskFor );
    878     for( i = 0; i < tmp.count; ++i ) {
     879    for( i=0; i<tmp.count; ++i ) {
    879880        const struct peer_request * req = &tmp.requests[i];
    880881        if( req->time_requested < oldestAllowed )
     
    934935    if( sent )
    935936        dbgmsg( msgs, "pump sent %d requests, now have %d active and %d queued",
    936                 sent,
    937                 msgs->clientAskedFor.count,
    938                 msgs->clientWillAskFor.count );
     937                sent, msgs->clientAskedFor.count, msgs->clientWillAskFor.count );
    939938
    940939    if( count < max )
     
    953952                       uint32_t         index,
    954953                       uint32_t         offset,
    955                        uint32_t         length,
    956                        int              doForce )
     954                       uint32_t         length )
    957955{
    958956    struct peer_request req;
     
    967965
    968966    /* don't send requests to choked clients */
    969     if( !doForce && msgs->peer->clientIsChoked ) {
     967    if( msgs->peer->clientIsChoked ) {
    970968        dbgmsg( msgs, "declining request because they're choking us" );
    971969        return TR_ADDREQ_CLIENT_CHOKED;
     
    973971
    974972    /* peer doesn't have this piece */
    975     if( !doForce && !tr_bitfieldHas( msgs->peer->have, index ) )
     973    if( !tr_bitfieldHas( msgs->peer->have, index ) )
    976974        return TR_ADDREQ_MISSING;
    977975
    978976    /* peer's queue is full */
    979     if( !doForce && requestQueueIsFull( msgs ) ) {
     977    if( requestQueueIsFull( msgs ) ) {
    980978        dbgmsg( msgs, "declining request because we're full" );
    981979        return TR_ADDREQ_FULL;
     
    986984    req.offset = offset;
    987985    req.length = length;
    988     if( !doForce ) {
    989         if( reqListFind( &msgs->clientAskedFor, &req ) != -1 ) {
    990             dbgmsg( msgs, "declining because it's a duplicate" );
    991             return TR_ADDREQ_DUPLICATE;
    992         }
    993         if( reqListFind( &msgs->clientWillAskFor, &req ) != -1 ) {
    994             dbgmsg( msgs, "declining because it's a duplicate" );
    995             return TR_ADDREQ_DUPLICATE;
    996         }
     986    if( reqListFind( &msgs->clientAskedFor, &req ) != -1 ) {
     987        dbgmsg( msgs, "declining because it's a duplicate" );
     988        return TR_ADDREQ_DUPLICATE;
     989    }
     990    if( reqListFind( &msgs->clientWillAskFor, &req ) != -1 ) {
     991        dbgmsg( msgs, "declining because it's a duplicate" );
     992        return TR_ADDREQ_DUPLICATE;
    997993    }
    998994
     
    15821578            break;
    15831579
    1584 
    15851580        case BT_FEXT_HAVE_NONE:
    15861581            dbgmsg( msgs, "Got a BT_FEXT_HAVE_NONE" );
     
    17811776    size_t bytesWritten = 0;
    17821777    struct peer_request req;
    1783     const int haveMessages = EVBUFFER_LENGTH( msgs->outMessages ) != 0;
     1778    const tr_bool haveMessages = EVBUFFER_LENGTH( msgs->outMessages ) != 0;
    17841779    const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io );
    17851780
     
    18811876tr_peerMsgsPulse( tr_peermsgs * msgs )
    18821877{
    1883     if( msgs )
     1878    if( msgs != NULL )
    18841879        peerPulse( msgs );
    18851880}
     
    22032198tr_peermsgs*
    22042199tr_peerMsgsNew( struct tr_torrent * torrent,
    2205                 struct tr_peer *    peer,
     2200                struct tr_peer    * peer,
    22062201                tr_delivery_func    func,
    2207                 void *              userData,
    2208                 tr_publisher_tag * setme )
     2202                void              * userData,
     2203                tr_publisher_tag  * setme )
    22092204{
    22102205    tr_peermsgs * m;
  • trunk/libtransmission/peer-msgs.h

    r7404 r7456  
    5454                                    uint32_t      pieceIndex,
    5555                                    uint32_t      offset,
    56                                     uint32_t      length,
    57                                     int           doForce );
     56                                    uint32_t      length );
    5857
    5958void         tr_peerMsgsUnsubscribe( tr_peermsgs      * peer,
  • trunk/libtransmission/transmission.h

    r7446 r7456  
    14091409tr_bool tr_isDirection( tr_direction );
    14101410
    1411 
    14121411/** @} */
    14131412
Note: See TracChangeset for help on using the changeset viewer.