Changeset 6565


Ignore:
Timestamp:
Aug 17, 2008, 5:18:34 PM (13 years ago)
Author:
charles
Message:

(1.3x libT) backport the r6548 outMessages fix
(1.3x libT) backport the r6549/r6550/r6552 connection management tweaks

Location:
branches/1.3x/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/1.3x/libtransmission/net.c

    r6396 r6565  
    124124
    125125    if( fd >= 0 ) {
    126         const int buffsize = 1500*2; /* 2x MTU for most ethernet/wireless */
     126        const int buffsize = 1500*3; /* 3x MTU for most ethernet/wireless */
    127127        setsockopt( fd, SOL_SOCKET, SO_SNDBUF, &buffsize, sizeof( buffsize ) );
    128128    }
  • branches/1.3x/libtransmission/peer-mgr.c

    r6469 r6565  
    5757
    5858    /* max # of peers to ask fer per torrent per reconnect pulse */
    59     MAX_RECONNECTIONS_PER_PULSE = 4,
     59    MAX_RECONNECTIONS_PER_PULSE = 2,
    6060
    6161    /* max number of peers to ask for per second overall.
    6262     * this throttle is to avoid overloading the router */
    63     MAX_CONNECTIONS_PER_SECOND = 8,
     63    MAX_CONNECTIONS_PER_SECOND = 4,
    6464
    6565    /* number of unchoked peers per torrent.
     
    17561756}
    17571757
     1758static int
     1759getReconnectIntervalSecs( const struct peer_atom * atom )
     1760{
     1761    int sec;
     1762
     1763    switch( atom->numFails )
     1764    {
     1765        case 0: sec = 0; break;
     1766        case 1: sec = 5; break;
     1767        case 2: sec = 2*60; break;
     1768        case 3: sec = 15*60; break;
     1769        case 4: sec = 30*60; break;
     1770        case 5: sec = 60*60; break;
     1771        default: sec = 120*60; break;
     1772    }
     1773
     1774    return sec;
     1775}
     1776
    17581777static struct peer_atom **
    17591778getPeerCandidates( Torrent * t, int * setmeSize )
     
    17921811            continue;
    17931812
    1794         /* we're wasting our time trying to connect to this bozo. */
    1795         if( atom->numFails > 3 )
    1796             continue;
    1797 
    17981813        /* If we were connected to this peer recently and transferring
    17991814         * piece data, try to reconnect -- network troubles may have
    18001815         * disconnected us.  but if we weren't sharing piece data,
    18011816         * hold off on this peer to give another one a try instead */
    1802         if( ( now - atom->piece_data_time ) > 30 )
     1817        if( ( now - atom->piece_data_time ) > 10 )
    18031818        {
    1804             int minWait = (60 * 5); /* five minutes */
    1805             int maxWait = minWait * 3;
    1806             int wait = atom->numFails * minWait;
    1807             if( wait < minWait ) wait = minWait;
    1808             if( wait > maxWait ) wait = maxWait;
     1819            const int wait = getReconnectIntervalSecs( atom );
    18091820            if( ( now - atom->time ) < wait ) {
    18101821                tordbg( t, "RECONNECT peer %d (%s) is in its grace period of %d seconds..",
     
    18611872
    18621873        /* disconnect some peers.
    1863            if we got transferred piece data, then they might be good peers,
     1874           if we transferred piece data, then they might be good peers,
    18641875           so reset their `numFails' weight to zero.  otherwise we connected
    18651876           to them fruitlessly, so mark it as another fail */
  • branches/1.3x/libtransmission/peer-msgs.c

    r6489 r6565  
    389389    tr_peerIoWriteUint32( io, out, req->length );
    390390    pokeBatchPeriod( msgs, HIGH_PRIORITY_INTERVAL_SECS );
     391    dbgmsg( msgs, "outMessage size is now %d", (int)EVBUFFER_LENGTH(out) );
    391392}
    392393
     
    404405    tr_peerIoWriteUint32( io, out, req->length );
    405406    pokeBatchPeriod( msgs, IMMEDIATE_PRIORITY_INTERVAL_SECS );
     407    dbgmsg( msgs, "outMessage size is now %d", (int)EVBUFFER_LENGTH(out) );
    406408}
    407409
     
    417419    tr_peerIoWriteUint32( io, out, index );
    418420    pokeBatchPeriod( msgs, LOW_PRIORITY_INTERVAL_SECS );
     421    dbgmsg( msgs, "outMessage size is now %d", (int)EVBUFFER_LENGTH(out) );
    419422}
    420423
     
    429432    tr_peerIoWriteUint8 ( io, out, choke ? BT_CHOKE : BT_UNCHOKE );
    430433    pokeBatchPeriod( msgs, IMMEDIATE_PRIORITY_INTERVAL_SECS );
     434    dbgmsg( msgs, "outMessage size is now %d", (int)EVBUFFER_LENGTH(out) );
    431435}
    432436
     
    552556sendInterest( tr_peermsgs * msgs, int weAreInterested )
    553557{
     558    struct evbuffer * out = msgs->outMessages;
     559
    554560    assert( msgs );
    555561    assert( weAreInterested==0 || weAreInterested==1 );
    556562
    557563    msgs->info->clientIsInterested = weAreInterested;
    558     dbgmsg( msgs, "Sending %s",
    559             weAreInterested ? "Interested" : "Not Interested");
    560 
    561     tr_peerIoWriteUint32( msgs->io, msgs->outMessages, sizeof(uint8_t) );
    562     tr_peerIoWriteUint8 ( msgs->io, msgs->outMessages,
    563                    weAreInterested ? BT_INTERESTED : BT_NOT_INTERESTED );
     564    dbgmsg( msgs, "Sending %s", weAreInterested ? "Interested" : "Not Interested");
     565    tr_peerIoWriteUint32( msgs->io, out, sizeof(uint8_t) );
     566    tr_peerIoWriteUint8 ( msgs->io, out, weAreInterested ? BT_INTERESTED : BT_NOT_INTERESTED );
    564567    pokeBatchPeriod( msgs, HIGH_PRIORITY_INTERVAL_SECS );
     568    dbgmsg( msgs, "outMessage size is now %d", (int)EVBUFFER_LENGTH(out) );
    565569}
    566570
     
    656660    if( tr_peerIoSupportsFEXT( msgs->io ) )
    657661    {
     662        struct evbuffer * out = msgs->outMessages;
    658663        const uint32_t len = sizeof(uint8_t) + 3 * sizeof(uint32_t);
    659         tr_peerIoWriteUint32( msgs->io, msgs->outMessages, len );
    660         tr_peerIoWriteUint8( msgs->io, msgs->outMessages, BT_REJECT );
    661         tr_peerIoWriteUint32( msgs->io, msgs->outMessages, pieceIndex );
    662         tr_peerIoWriteUint32( msgs->io, msgs->outMessages, offset );
    663         tr_peerIoWriteUint32( msgs->io, msgs->outMessages, length );
     664        dbgmsg( msgs, "sending fast reject %u:%u->%u", pieceIndex, offset, length );
     665        tr_peerIoWriteUint32( msgs->io, out, len );
     666        tr_peerIoWriteUint8( msgs->io, out, BT_REJECT );
     667        tr_peerIoWriteUint32( msgs->io, out, pieceIndex );
     668        tr_peerIoWriteUint32( msgs->io, out, offset );
     669        tr_peerIoWriteUint32( msgs->io, out, length );
    664670        pokeBatchPeriod( msgs, LOW_PRIORITY_INTERVAL_SECS );
     671        dbgmsg( msgs, "outMessage size is now %d", (int)EVBUFFER_LENGTH(out) );
    665672    }
    666673}
     
    689696    if( tr_peerIoSupportsFEXT( msgs->io ) )
    690697    {
    691         tr_peerIoWriteUint32( msgs->io, msgs->outMessages, sizeof(uint8_t) + sizeof(uint32_t) );
    692         tr_peerIoWriteUint8( msgs->io, msgs->outMessages, BT_ALLOWED_FAST );
    693         tr_peerIoWriteUint32( msgs->io, msgs->outMessages, pieceIndex );
     698        struct evbuffer * out = msgs->outMessages;
     699        dbgmsg( msgs, "sending fast allowed" );
     700        tr_peerIoWriteUint32( msgs->io, out,  sizeof(uint8_t) + sizeof(uint32_t) );
     701        tr_peerIoWriteUint8( msgs->io, out, BT_ALLOWED_FAST );
     702        tr_peerIoWriteUint32( msgs->io, out, pieceIndex );
    694703        pokeBatchPeriod( msgs, LOW_PRIORITY_INTERVAL_SECS );
     704        dbgmsg( msgs, "outMessage size is now %d", (int)EVBUFFER_LENGTH(out) );
    695705    }
    696706}
     
    925935    int len;
    926936    int pex;
    927     struct evbuffer * outbuf;
     937    struct evbuffer * out = msgs->outMessages;
    928938
    929939    if( msgs->clientSentLtepHandshake )
    930940        return;
    931941
    932     outbuf = evbuffer_new( );
    933942    dbgmsg( msgs, "sending an ltep handshake" );
    934943    msgs->clientSentLtepHandshake = 1;
     
    951960    buf = tr_bencSave( &val, &len );
    952961
    953     tr_peerIoWriteUint32( msgs->io, outbuf, 2*sizeof(uint8_t) + len );
    954     tr_peerIoWriteUint8 ( msgs->io, outbuf, BT_LTEP );
    955     tr_peerIoWriteUint8 ( msgs->io, outbuf, LTEP_HANDSHAKE );
    956     tr_peerIoWriteBytes ( msgs->io, outbuf, buf, len );
    957 
    958     tr_peerIoWriteBuf( msgs->io, outbuf );
    959 
    960     dbgmsg( msgs, "here is the ltep handshake we sent [%*.*s]", len, len, buf );
     962    tr_peerIoWriteUint32( msgs->io, out, 2*sizeof(uint8_t) + len );
     963    tr_peerIoWriteUint8 ( msgs->io, out, BT_LTEP );
     964    tr_peerIoWriteUint8 ( msgs->io, out, LTEP_HANDSHAKE );
     965    tr_peerIoWriteBytes ( msgs->io, out, buf, len );
     966    pokeBatchPeriod( msgs, IMMEDIATE_PRIORITY_INTERVAL_SECS );
     967    dbgmsg( msgs, "outMessage size is now %d", (int)EVBUFFER_LENGTH(out) );
    961968
    962969    /* cleanup */
    963970    tr_bencFree( &val );
    964971    tr_free( buf );
    965     evbuffer_free( outbuf );
    966972}
    967973
     
    18201826        char * benc;
    18211827        int bencLen;
     1828        struct evbuffer * out = msgs->outMessages;
    18221829
    18231830        /* build the diffs */
     
    18721879        /* write the pex message */
    18731880        benc = tr_bencSave( &val, &bencLen );
    1874         tr_peerIoWriteUint32( msgs->io, msgs->outMessages, 2*sizeof(uint8_t) + bencLen );
    1875         tr_peerIoWriteUint8 ( msgs->io, msgs->outMessages, BT_LTEP );
    1876         tr_peerIoWriteUint8 ( msgs->io, msgs->outMessages, msgs->ut_pex_id );
    1877         tr_peerIoWriteBytes ( msgs->io, msgs->outMessages, benc, bencLen );
     1881        tr_peerIoWriteUint32( msgs->io, out, 2*sizeof(uint8_t) + bencLen );
     1882        tr_peerIoWriteUint8 ( msgs->io, out, BT_LTEP );
     1883        tr_peerIoWriteUint8 ( msgs->io, out, msgs->ut_pex_id );
     1884        tr_peerIoWriteBytes ( msgs->io, out, benc, bencLen );
    18781885        pokeBatchPeriod( msgs, IMMEDIATE_PRIORITY_INTERVAL_SECS );
     1886        dbgmsg( msgs, "outMessage size is now %d", (int)EVBUFFER_LENGTH(out) );
    18791887
    18801888        /* cleanup */
Note: See TracChangeset for help on using the changeset viewer.