Changeset 3780


Ignore:
Timestamp:
Nov 10, 2007, 2:59:14 PM (14 years ago)
Author:
charles
Message:

backport a handful of bugfixes to the 0.9x branch for a possible 0.93.

Location:
branches/0.9x
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/0.9x/README

    r3531 r3780  
    1919Building a Transmission release from the command line:
    2020
    21     $ tar xvfz transmission-0.90.tar.gz
    22     $ cd transmission-0.90
     21    $ tar xvfj transmission-0.93.tar.bz2
     22    $ cd transmission-0.92
    2323    $ ./configure -q && make -s
    2424    $ su (if necessary for the next line)
  • branches/0.9x/libtransmission/inout.c

    r3673 r3780  
    202202
    203203int
    204 tr_ioWrite( tr_torrent  * tor,
    205             int           pieceIndex,
    206             int           begin,
    207             int           len,
    208             uint8_t     * buf )
    209 {
    210     return readOrWritePiece( tor, TR_IO_WRITE, pieceIndex, begin, buf, len );
     204tr_ioWrite( tr_torrent     * tor,
     205            int              pieceIndex,
     206            int              begin,
     207            int              len,
     208            const uint8_t  * buf )
     209{
     210    return readOrWritePiece( tor, TR_IO_WRITE, pieceIndex, begin, (void*)buf, len );
    211211}
    212212
  • branches/0.9x/libtransmission/inout.h

    r3649 r3780  
    3939 **********************************************************************/
    4040int tr_ioRead  ( struct tr_torrent*, int index, int begin, int len, uint8_t * );
    41 int tr_ioWrite ( struct tr_torrent *, int index, int begin, int len, uint8_t * );
     41int tr_ioWrite ( struct tr_torrent *, int index, int begin, int len, const uint8_t * );
    4242
    4343/* hashes the specified piece and updates the completion accordingly. */
  • branches/0.9x/libtransmission/peer-mgr.c

    r3662 r3780  
    7373    /* set this too high and there will be a lot of churn.
    7474     * set it too low and you'll get peers too slowly */
    75     MAX_RECONNECTIONS_PER_PULSE = 10,
     75    MAX_RECONNECTIONS_PER_PULSE = 5,
    7676
    7777    /* corresponds to ut_pex's added.f flags */
     
    937937                tr_peerIoFree( io );
    938938            }
     939            else if( tr_ptrArraySize( t->peers ) >= MAX_CONNECTED_PEERS_PER_TORRENT )
     940            {
     941                tr_peerIoFree( io );
     942            }
    939943            else
    940944            {
     
    16951699
    16961700        /* add some new ones */
    1697         nAdd = MAX_CONNECTED_PEERS_PER_TORRENT - peerCount;
     1701        nAdd = !peerCount ? MAX_CONNECTED_PEERS_PER_TORRENT
     1702                          : MAX_RECONNECTIONS_PER_PULSE;
    16981703        for( i=0; i<nAdd && i<nCandidates && i<MAX_RECONNECTIONS_PER_PULSE; ++i )
    16991704        {
  • branches/0.9x/libtransmission/peer-msgs.c

    r3705 r3780  
    2121#include <netinet/in.h> /* struct in_addr */
    2222
    23 #include <sys/types.h> /* event.h needs this */
    2423#include <event.h>
    2524
     
    4039***
    4140**/
    42 
    43 #define MAX_ALLOWED_SET_COUNT   10 /* number of pieces generated for allow-fast,
    44                                       threshold for fast-allowing others */
    4541
    4642enum
     
    6965    MAX_REQUEST_BYTE_COUNT  = (16 * 1024), /* drop requests who want too much */
    7066
    71     KEEPALIVE_INTERVAL_SECS = 90,          /* idle seconds before we send a keepalive */
     67    /* idle seconds before we send a keepalive */
     68    KEEPALIVE_INTERVAL_SECS = 90,
     69
    7270    PEX_INTERVAL            = (60 * 1000), /* msec between calls to sendPex() */
    7371    PEER_PULSE_INTERVAL     = (100),       /* msec between calls to pulse() */
    7472    RATE_PULSE_INTERVAL     = (333),       /* msec between calls to ratePulse() */
     73
     74    /* number of pieces generated for allow-fast,
     75      threshold for fast-allowing others */
     76    MAX_ALLOWED_SET_COUNT   = 10
    7577};
    7678
     
    7880{
    7981    AWAITING_BT_LENGTH,
    80     AWAITING_BT_MESSAGE,
    81     READING_BT_PIECE
     82    AWAITING_BT_MESSAGE
    8283};
    8384
     
    9394compareRequest( const void * va, const void * vb )
    9495{
    95     struct peer_request * a = (struct peer_request*) va;
    96     struct peer_request * b = (struct peer_request*) vb;
    97     if( a->index != b->index ) return a->index - b->index;
    98     if( a->offset != b->offset ) return a->offset - b->offset;
    99     if( a->length != b->length ) return a->length - b->length;
     96    int i;
     97    const struct peer_request * a = va;
     98    const struct peer_request * b = vb;
     99    if(( i = tr_compareUint32( a->index, b->index ))) return i;
     100    if(( i = tr_compareUint32( a->offset, b->offset ))) return i;
     101    if(( i = tr_compareUint32( a->length, b->length ))) return i;
    100102    return 0;
    101103}
     
    113115    struct evbuffer * outBlock;    /* buffer of all the current piece message */
    114116    struct evbuffer * outMessages; /* buffer of all the non-piece messages */
    115     struct evbuffer * inBlock;     /* the block we're currently receiving */
    116117    tr_list * peerAskedFor;
    117118    tr_list * peerAskedForFast;
     
    122123    tr_timer * pulseTimer;
    123124    tr_timer * pexTimer;
    124 
    125     struct peer_request blockToUs; /* the block currntly being sent to us */
    126125
    127126    time_t lastReqAddedAt;
     
    284283
    285284static void
    286 fireGotBlock( tr_peermsgs * msgs, uint32_t pieceIndex, uint32_t offset, uint32_t length )
     285fireGotBlock( tr_peermsgs * msgs, const struct peer_request * req )
    287286{
    288287    tr_peermsgs_event e = blankEvent;
    289288    e.eventType = TR_PEERMSG_CLIENT_BLOCK;
    290     e.pieceIndex = pieceIndex;
    291     e.offset = offset;
    292     e.length = length;
     289    e.pieceIndex = req->index;
     290    e.offset = req->offset;
     291    e.length = req->length;
    293292    publish( msgs, &e );
    294293}
     
    434433#endif
    435434static void
    436 sendFastHave( tr_peermsgs * msgs,
    437               int           all)
    438 {
    439     dbgmsg( msgs, "w00t telling them we %s pieces", (all ? "HAVE_ALL" : "HAVE_NONE" ) );
     435sendFastHave( tr_peermsgs * msgs, int all )
     436{
     437    dbgmsg( msgs, "w00t telling them we have %s pieces", (all ? "ALL" : "NONE" ) );
    440438    tr_peerIoWriteUint32( msgs->io, msgs->outMessages, sizeof(uint8_t) );
    441     tr_peerIoWriteUint8( msgs->io, msgs->outMessages, ( all ? BT_HAVE_ALL : BT_HAVE_NONE ) );
    442    
     439    tr_peerIoWriteUint8( msgs->io, msgs->outMessages, ( all ? BT_HAVE_ALL
     440                                                            : BT_HAVE_NONE ) );
    443441    updateInterest( msgs );
    444442}
     
    493491
    494492static int
    495 reqIsValid( const tr_peermsgs * msgs, uint32_t index, uint32_t offset, uint32_t length )
     493reqIsValid( const tr_peermsgs   * msgs,
     494            uint32_t              index,
     495            uint32_t              offset,
     496            uint32_t              length )
    496497{
    497498    const tr_torrent * tor = msgs->torrent;
     
    530531    while( ( count < max ) && ( msgs->clientWillAskFor != NULL ) )
    531532    {
    532         struct peer_request * req = tr_list_pop_front( &msgs->clientWillAskFor );
    533         protocolSendRequest( msgs, req );
    534         req->time_requested = msgs->lastReqAddedAt = time( NULL );
    535         tr_list_append( &msgs->clientAskedFor, req );
     533        struct peer_request * r = tr_list_pop_front( &msgs->clientWillAskFor );
     534        protocolSendRequest( msgs, r );
     535        r->time_requested = msgs->lastReqAddedAt = time( NULL );
     536        tr_list_append( &msgs->clientAskedFor, r );
    536537        ++count;
    537538        ++sent;
     
    698699        tr_bencInitInt( tr_bencDictAdd( &val, "p" ), port );
    699700    tr_bencInitStr( tr_bencDictAdd( &val, "v" ), v, 0, 1 );
    700     buf = tr_bencSaveMalloc( &val,  &len );
     701    buf = tr_bencSaveMalloc( &val, &len );
    701702
    702703    tr_peerIoWriteUint32( msgs->io, outbuf, 2*sizeof(uint8_t) + len );
     
    891892        sendFastReject( msgs, req->index, req->offset, req->length );
    892893    }
    893     else if( peerIsChoked && !peerIsFast ) /* maybe he doesn't know he's choked? */
     894    else if( peerIsChoked && !peerIsFast ) /* doesn't he know he's choked? */
    894895    {
    895896        tr_peerMsgsSetChoke( msgs, 1 );
     
    951952}
    952953
     954static void
     955clientGotBlock( tr_peermsgs * msgs, const uint8_t * block, const struct peer_request * req );
    953956
    954957static int
     
    958961    uint32_t ui32;
    959962    uint32_t msglen = msgs->incomingMessageLength;
     963    const size_t startBufLen = EVBUFFER_LENGTH( inbuf );
    960964
    961965    if( EVBUFFER_LENGTH(inbuf) < msglen )
     
    963967
    964968    tr_peerIoReadUint8( msgs->io, inbuf, &id );
    965     dbgmsg( msgs, "got BT id %d, len %d", (int)id, (int)msglen );
     969    dbgmsg( msgs, "got BT id %d, len %d, buffer size is %d", (int)id, (int)msglen, (int)EVBUFFER_LENGTH(inbuf) );
    966970
    967971    if( !messageLengthIsCorrect( msgs, id, msglen ) )
    968972    {
     973        dbgmsg( msgs, "bad packet - BT message #%d with a length of %d", (int)id, (int)msglen );
    969974        fireGotError( msgs );
    970975        return READ_DONE;
     
    975980    switch( id )
    976981    {
    977         case BT_CHOKE:
    978             dbgmsg( msgs, "got Choke" );
    979             msgs->info->clientIsChoked = 1;
    980             cancelAllRequestsToPeer( msgs );
    981             cancelAllRequestsToClientExceptFast( msgs );
    982             break;
    983 
    984         case BT_UNCHOKE:
    985             dbgmsg( msgs, "got Unchoke" );
    986             msgs->info->clientIsChoked = 0;
    987             fireNeedReq( msgs );
    988             break;
    989 
    990         case BT_INTERESTED:
    991             dbgmsg( msgs, "got Interested" );
    992             msgs->info->peerIsInterested = 1;
    993             tr_peerMsgsSetChoke( msgs, 0 );
    994             break;
    995 
    996         case BT_NOT_INTERESTED:
    997             dbgmsg( msgs, "got Not Interested" );
    998             msgs->info->peerIsInterested = 0;
    999             break;
    1000 
    1001         case BT_HAVE:
    1002             tr_peerIoReadUint32( msgs->io, inbuf, &ui32 );
    1003             dbgmsg( msgs, "got Have: %u", ui32 );
    1004             tr_bitfieldAdd( msgs->info->have, ui32 );
    1005             updatePeerProgress( msgs );
    1006             tr_rcTransferred( msgs->torrent->swarmspeed, msgs->torrent->info.pieceSize );
    1007             break;
    1008 
    1009         case BT_BITFIELD: {
    1010             const int clientIsSeed = tr_torrentIsSeed( msgs->torrent );
    1011             dbgmsg( msgs, "got a bitfield" );
    1012             tr_peerIoReadBytes( msgs->io, inbuf, msgs->info->have->bits, msglen );
    1013             updatePeerProgress( msgs );
    1014             tr_peerMsgsSetChoke( msgs, !clientIsSeed || (msgs->info->progress<1.0) );
    1015             fireNeedReq( msgs );
    1016             break;
    1017         }
    1018 
    1019         case BT_REQUEST: {
    1020             struct peer_request req;
    1021             tr_peerIoReadUint32( msgs->io, inbuf, &req.index );
    1022             tr_peerIoReadUint32( msgs->io, inbuf, &req.offset );
    1023             tr_peerIoReadUint32( msgs->io, inbuf, &req.length );
    1024             dbgmsg( msgs, "got Request: %u:%u->%u", req.index, req.offset, req.length );
    1025             peerMadeRequest( msgs, &req );
    1026             break;
    1027         }
    1028 
    1029         case BT_CANCEL: {
    1030             struct peer_request req;
    1031             tr_peerIoReadUint32( msgs->io, inbuf, &req.index );
    1032             tr_peerIoReadUint32( msgs->io, inbuf, &req.offset );
    1033             tr_peerIoReadUint32( msgs->io, inbuf, &req.length );
    1034             dbgmsg( msgs, "got a Cancel %u:%u->%u", req.index, req.offset, req.length );
    1035             tr_free( tr_list_remove( &msgs->peerAskedForFast, &req, compareRequest ) );
    1036             tr_free( tr_list_remove( &msgs->peerAskedFor, &req, compareRequest ) );
    1037             break;
    1038         }
    1039 
    1040         case BT_PIECE: {
    1041             dbgmsg( msgs, "got a Piece!" );
    1042             assert( msgs->blockToUs.length == 0 );
    1043             tr_peerIoReadUint32( msgs->io, inbuf, &msgs->blockToUs.index );
    1044             tr_peerIoReadUint32( msgs->io, inbuf, &msgs->blockToUs.offset );
    1045             msgs->blockToUs.length = msglen - 8;
    1046             assert( EVBUFFER_LENGTH(msgs->inBlock) == 0 );
    1047             msgs->state = msgs->blockToUs.length ? READING_BT_PIECE : AWAITING_BT_LENGTH;
    1048             return READ_AGAIN;
    1049             break;
    1050         }
    1051 
    1052         case BT_PORT: {
    1053             dbgmsg( msgs, "Got a BT_PORT" );
    1054             tr_peerIoReadUint16( msgs->io, inbuf, &msgs->info->port );
    1055             break;
    1056         }
    1057    
    1058         case BT_SUGGEST: {
    1059             /* FIXME(tiennou) */
    1060             uint32_t index;
    1061             tr_peerIoReadUint32( msgs->io, inbuf, &index );
    1062             break;
    1063         }
    1064        
    1065         case BT_HAVE_ALL:
    1066             dbgmsg( msgs, "Got a BT_HAVE_ALL" );
     982        case BT_CHOKE:
     983            dbgmsg( msgs, "got Choke" );
     984            msgs->info->clientIsChoked = 1;
     985            cancelAllRequestsToPeer( msgs );
     986            cancelAllRequestsToClientExceptFast( msgs );
     987            break;
     988
     989        case BT_UNCHOKE:
     990            dbgmsg( msgs, "got Unchoke" );
     991            msgs->info->clientIsChoked = 0;
     992            fireNeedReq( msgs );
     993            break;
     994
     995        case BT_INTERESTED:
     996            dbgmsg( msgs, "got Interested" );
     997            msgs->info->peerIsInterested = 1;
     998            tr_peerMsgsSetChoke( msgs, 0 );
     999            break;
     1000
     1001        case BT_NOT_INTERESTED:
     1002            dbgmsg( msgs, "got Not Interested" );
     1003            msgs->info->peerIsInterested = 0;
     1004            break;
     1005
     1006        case BT_HAVE:
     1007            tr_peerIoReadUint32( msgs->io, inbuf, &ui32 );
     1008            dbgmsg( msgs, "got Have: %u", ui32 );
     1009            tr_bitfieldAdd( msgs->info->have, ui32 );
     1010            updatePeerProgress( msgs );
     1011            tr_rcTransferred( msgs->torrent->swarmspeed, msgs->torrent->info.pieceSize );
     1012            break;
     1013
     1014        case BT_BITFIELD: {
     1015            const int clientIsSeed = tr_torrentIsSeed( msgs->torrent );
     1016            dbgmsg( msgs, "got a bitfield" );
     1017            tr_peerIoReadBytes( msgs->io, inbuf, msgs->info->have->bits, msglen );
     1018            updatePeerProgress( msgs );
     1019            tr_peerMsgsSetChoke( msgs, !clientIsSeed || (msgs->info->progress<1.0) );
     1020            fireNeedReq( msgs );
     1021            break;
     1022        }
     1023
     1024        case BT_REQUEST: {
     1025            struct peer_request req;
     1026            tr_peerIoReadUint32( msgs->io, inbuf, &req.index );
     1027            tr_peerIoReadUint32( msgs->io, inbuf, &req.offset );
     1028            tr_peerIoReadUint32( msgs->io, inbuf, &req.length );
     1029            dbgmsg( msgs, "got Request: %u:%u->%u", req.index, req.offset, req.length );
     1030            peerMadeRequest( msgs, &req );
     1031            break;
     1032        }
     1033
     1034        case BT_CANCEL: {
     1035            struct peer_request req;
     1036            tr_peerIoReadUint32( msgs->io, inbuf, &req.index );
     1037            tr_peerIoReadUint32( msgs->io, inbuf, &req.offset );
     1038            tr_peerIoReadUint32( msgs->io, inbuf, &req.length );
     1039            dbgmsg( msgs, "got a Cancel %u:%u->%u", req.index, req.offset, req.length );
     1040            tr_free( tr_list_remove( &msgs->peerAskedForFast, &req, compareRequest ) );
     1041            tr_free( tr_list_remove( &msgs->peerAskedFor, &req, compareRequest ) );
     1042            break;
     1043        }
     1044
     1045        case BT_PIECE: {
     1046            uint8_t * block;
     1047            struct peer_request req;
     1048            tr_peerIoReadUint32( msgs->io, inbuf, &req.index );
     1049            tr_peerIoReadUint32( msgs->io, inbuf, &req.offset );
     1050            req.length = msglen - 8;
     1051            block = tr_new( uint8_t, req.length );
     1052            tr_peerIoReadBytes( msgs->io, inbuf, block, req.length );
     1053            dbgmsg( msgs, "got a Block %u:%u->%u", req.index, req.offset, req.length );
     1054            clientGotBlock( msgs, block, &req );
     1055            tr_free( block );
     1056            break;
     1057        }
     1058
     1059        case BT_PORT:
     1060            dbgmsg( msgs, "Got a BT_PORT" );
     1061            tr_peerIoReadUint16( msgs->io, inbuf, &msgs->info->port );
     1062            break;
     1063
     1064#if 0
     1065        case BT_SUGGEST: {
     1066            /* FIXME(tiennou) */
     1067            uint32_t index;
     1068            tr_peerIoReadUint32( msgs->io, inbuf, &index );
     1069            break;
     1070        }
     1071
     1072        case BT_HAVE_ALL:
     1073            dbgmsg( msgs, "Got a BT_HAVE_ALL" );
    10671074            tr_bitfieldAddRange( msgs->info->have, 0, msgs->torrent->info.pieceCount );
    1068             updatePeerProgress( msgs );
    1069             break;
    1070        
    1071         case BT_HAVE_NONE:
    1072             dbgmsg( msgs, "Got a BT_HAVE_NONE" );
    1073             tr_bitfieldClear( msgs->info->have );
    1074             updatePeerProgress( msgs );
    1075             break;
    1076        
    1077         case BT_REJECT: {
    1078             struct peer_request req;
    1079             dbgmsg( msgs, "Got a BT_REJECT" );
    1080             tr_peerIoReadUint32( msgs->io, inbuf, &req.index );
    1081             tr_peerIoReadUint32( msgs->io, inbuf, &req.offset );
    1082             tr_peerIoReadUint32( msgs->io, inbuf, &req.length );
    1083             tr_free( tr_list_remove( &msgs->clientAskedFor, &req, compareRequest ) );
    1084             break;
    1085         }
    1086        
    1087         case BT_ALLOWED_FAST: {
    1088             dbgmsg( msgs, "Got a BT_ALLOWED_FAST" );
    1089             tr_peerIoReadUint32( msgs->io, inbuf, &ui32 );
    1090             tr_bitfieldAdd( msgs->clientAllowedPieces, ui32 );
    1091             break;
    1092         }
    1093        
    1094         case BT_LTEP:
    1095             dbgmsg( msgs, "Got a BT_LTEP" );
    1096             parseLtep( msgs, msglen, inbuf );
    1097             break;
    1098 
    1099         default:
    1100             dbgmsg( msgs, "peer sent us an UNKNOWN: %d", (int)id );
    1101             tr_peerIoDrain( msgs->io, inbuf, msglen );
    1102             break;
    1103     }
     1075            updatePeerProgress( msgs );
     1076            break;
     1077
     1078        case BT_HAVE_NONE:
     1079            dbgmsg( msgs, "Got a BT_HAVE_NONE" );
     1080            tr_bitfieldClear( msgs->info->have );
     1081            updatePeerProgress( msgs );
     1082            break;
     1083
     1084        case BT_REJECT: {
     1085            struct peer_request req;
     1086            dbgmsg( msgs, "Got a BT_REJECT" );
     1087            tr_peerIoReadUint32( msgs->io, inbuf, &req.index );
     1088            tr_peerIoReadUint32( msgs->io, inbuf, &req.offset );
     1089            tr_peerIoReadUint32( msgs->io, inbuf, &req.length );
     1090            tr_free( tr_list_remove( &msgs->clientAskedFor, &req, compareRequest ) );
     1091            break;
     1092        }
     1093
     1094        case BT_ALLOWED_FAST: {
     1095            dbgmsg( msgs, "Got a BT_ALLOWED_FAST" );
     1096            tr_peerIoReadUint32( msgs->io, inbuf, &ui32 );
     1097            tr_bitfieldAdd( msgs->clientAllowedPieces, ui32 );
     1098            break;
     1099        }
     1100#endif
     1101
     1102        case BT_LTEP:
     1103            dbgmsg( msgs, "Got a BT_LTEP" );
     1104            parseLtep( msgs, msglen, inbuf );
     1105            break;
     1106
     1107        default:
     1108            dbgmsg( msgs, "peer sent us an UNKNOWN: %d", (int)id );
     1109            tr_peerIoDrain( msgs->io, inbuf, msglen );
     1110            break;
     1111    }
     1112
     1113
     1114dbgmsg( msgs, "startBufLen was %d, msglen was %d, current inbuf len is %d", (int)startBufLen, (int)(msglen+1), (int)EVBUFFER_LENGTH(inbuf) );
    11041115
    11051116    msgs->incomingMessageLength = -1;
     
    11701181
    11711182static void
    1172 gotUnwantedBlock( tr_peermsgs * msgs,
    1173                   uint32_t      index UNUSED,
    1174                   uint32_t      offset UNUSED,
    1175                   uint32_t      length )
    1176 {
    1177     reassignBytesToCorrupt( msgs, length );
    1178 }
    1179 
    1180 static void
    1181 addUsToBlamefield( tr_peermsgs * msgs, uint32_t index )
     1183clientGotUnwantedBlock( tr_peermsgs * msgs, const struct peer_request * req )
     1184{
     1185    reassignBytesToCorrupt( msgs, req->length );
     1186}
     1187
     1188static void
     1189addPeerToBlamefield( tr_peermsgs * msgs, uint32_t index )
    11821190{
    11831191    if( !msgs->info->blame )
     
    11871195
    11881196static void
    1189 gotBlock( tr_peermsgs      * msgs,
    1190           struct evbuffer  * inbuf,
    1191           uint32_t           index,
    1192           uint32_t           offset,
    1193           uint32_t           length )
    1194 {
     1197clientGotBlock( tr_peermsgs * msgs, const uint8_t * data, const struct peer_request * req )
     1198{
     1199    int i;
    11951200    tr_torrent * tor = msgs->torrent;
    1196     const int block = _tr_block( tor, index, offset );
    1197     struct peer_request key, *req;
     1201    const int block = _tr_block( tor, req->index, req->offset );
     1202    struct peer_request *myreq;
     1203
     1204    assert( msgs != NULL );
     1205    assert( req != NULL );
     1206    assert( req->length > 0 );
     1207    assert( req->length == (uint32_t)tr_torBlockCountBytes( msgs->torrent, block ) );
     1208
     1209    /* save the block */
     1210    dbgmsg( msgs, "got block %u:%u->%u", req->index, req->offset, req->length );
    11981211
    11991212    /**
     
    12011214    **/
    12021215
    1203     key.index = index;
    1204     key.offset = offset;
    1205     key.length = length;
    1206     req = (struct peer_request*) tr_list_remove( &msgs->clientAskedFor, &key,
    1207                                                  compareRequest );
    1208     if( req == NULL ) {
    1209         gotUnwantedBlock( msgs, index, offset, length );
     1216    myreq = tr_list_remove( &msgs->clientAskedFor, req, compareRequest );
     1217    if( myreq == NULL ) {
     1218        clientGotUnwantedBlock( msgs, req );
    12101219        dbgmsg( msgs, "we didn't ask for this message..." );
    12111220        return;
    12121221    }
     1222
    12131223    dbgmsg( msgs, "got block %u:%u->%u (turnaround time %d secs)",
    1214                      req->index, req->offset, req->length,
    1215                      (int)(time(NULL) - req->time_requested) );
    1216     tr_free( req );
     1224                  myreq->index, myreq->offset, myreq->length,
     1225                  (int)(time(NULL) - myreq->time_requested) );
    12171226    dbgmsg( msgs, "peer has %d more blocks we've asked for",
    12181227                  tr_list_size(msgs->clientAskedFor));
     
    12231232
    12241233    if( tr_cpBlockIsComplete( tor->completion, block ) ) {
    1225         dbgmsg( msgs, "have this block already..." );
    1226         tr_dbg( "have this block already..." );
    1227         gotUnwantedBlock( msgs, index, offset, length );
     1234        dbgmsg( msgs, "we have this block already..." );
     1235        clientGotUnwantedBlock( msgs, req );
    12281236        return;
    12291237    }
    12301238
    1231     if( (int)length != tr_torBlockCountBytes( tor, block ) ) {
    1232         dbgmsg( msgs, "block is the wrong length..." );
    1233         tr_dbg( "block is the wrong length..." );
    1234         gotUnwantedBlock( msgs, index, offset, length );
     1239    /**
     1240    ***  Save the block
     1241    **/
     1242
     1243    msgs->info->peerSentPieceDataAt = time( NULL );
     1244    clientGotBytes( msgs, req->length );
     1245    i = tr_ioWrite( tor, req->index, req->offset, req->length, data );
     1246    if( i )
    12351247        return;
    1236     }
    1237 
    1238     /**
    1239     ***  Write the block
    1240     **/
    1241 
    1242     if( tr_ioWrite( tor, index, offset, length, EVBUFFER_DATA( inbuf )))
    1243         return;
    1244 
    1245 #warning this sanity check is here to help track down the excess corrupt data bug, but is expensive and should be removed before the next release
    1246 {
    1247     uint8_t * tmp = tr_new( uint8_t, length );
    1248     const int val = tr_ioRead( tor, index, offset, length, tmp );
    1249     assert( !val );
    1250     assert( !memcmp( tmp, EVBUFFER_DATA(inbuf), length ) );
    1251     tr_free( tmp );
    1252 }
    12531248
    12541249    tr_cpBlockAdd( tor->completion, block );
    12551250
    1256     addUsToBlamefield( msgs, index );
    1257 
    1258     fireGotBlock( msgs, index, offset, length );
     1251    addPeerToBlamefield( msgs, req->index );
     1252
     1253    fireGotBlock( msgs, req );
    12591254
    12601255    /**
     
    12621257    **/
    12631258
    1264     if( tr_cpPieceIsComplete( tor->completion, index ) )
    1265     {
    1266         if( tr_ioHash( tor, index ) )
     1259    if( tr_cpPieceIsComplete( tor->completion, req->index ) )
     1260    {
     1261        if( tr_ioHash( tor, req->index ) )
    12671262        {
    1268             gotBadPiece( msgs, index );
     1263            gotBadPiece( msgs, req->index );
    12691264            return;
    12701265        }
    12711266
    1272         fireClientHave( msgs, index );
    1273     }
    1274 }
    1275 
    1276 
    1277 static ReadState
    1278 readBtPiece( tr_peermsgs * msgs, struct evbuffer * inbuf )
    1279 {
    1280     uint32_t inlen;
    1281     uint8_t * tmp;
    1282 
    1283     assert( msgs != NULL );
    1284     assert( msgs->blockToUs.length > 0 );
    1285     assert( inbuf != NULL );
    1286     assert( EVBUFFER_LENGTH( inbuf ) > 0 );
    1287 
    1288     /* read from the inbuf into our block buffer */
    1289     inlen = MIN( EVBUFFER_LENGTH(inbuf), msgs->blockToUs.length );
    1290     tmp = tr_new( uint8_t, inlen );
    1291     tr_peerIoReadBytes( msgs->io, inbuf, tmp, inlen );
    1292     evbuffer_add( msgs->inBlock, tmp, inlen );
    1293 
    1294     /* update our tables accordingly */
    1295     assert( inlen >= msgs->blockToUs.length );
    1296     msgs->blockToUs.length -= inlen;
    1297     msgs->info->peerSentPieceDataAt = time( NULL );
    1298     clientGotBytes( msgs, inlen );
    1299 
    1300     /* if this was the entire block, save it */
    1301     if( !msgs->blockToUs.length )
    1302     {
    1303         dbgmsg( msgs, "got block %u:%u", msgs->blockToUs.index, msgs->blockToUs.offset );
    1304         assert( (int)EVBUFFER_LENGTH( msgs->inBlock ) == tr_torBlockCountBytes( msgs->torrent, _tr_block(msgs->torrent,msgs->blockToUs.index, msgs->blockToUs.offset) ) );
    1305         gotBlock( msgs, msgs->inBlock,
    1306                         msgs->blockToUs.index,
    1307                         msgs->blockToUs.offset,
    1308                         EVBUFFER_LENGTH( msgs->inBlock ) );
    1309         evbuffer_drain( msgs->inBlock, ~0 );
    1310         msgs->state = AWAITING_BT_LENGTH;
    1311     }
    1312 
    1313     /* cleanup */
    1314     tr_free( tmp );
    1315     return READ_AGAIN;
     1267        fireClientHave( msgs, req->index );
     1268    }
    13161269}
    13171270
     
    13331286        case AWAITING_BT_LENGTH:  ret = readBtLength  ( msgs, inbuf ); break;
    13341287        case AWAITING_BT_MESSAGE: ret = readBtMessage ( msgs, inbuf ); break;
    1335         case READING_BT_PIECE:    ret = readBtPiece   ( msgs, inbuf ); break;
    13361288        default: assert( 0 );
    13371289    }
     
    13711323
    13721324    if( tor->uploadLimitMode == TR_SPEEDLIMIT_GLOBAL )
    1373         return tor->handle->useUploadLimit ? tr_rcBytesLeft( tor->handle->upload ) : maxval;
     1325        return tor->handle->useUploadLimit
     1326            ? tr_rcBytesLeft( tor->handle->upload ) : maxval;
    13741327
    13751328    if( tor->uploadLimitMode == TR_SPEEDLIMIT_SINGLE )
     
    13851338    msgs->info->rateToClient = tr_rcRate( msgs->info->rcToClient );
    13861339    msgs->info->rateToPeer = tr_rcRate( msgs->info->rcToPeer );
    1387     msgs->maxActiveRequests = MIN( 8 + (int)(msgs->info->rateToClient/10), 100 );
    1388     msgs->minActiveRequests = msgs->maxActiveRequests / 2;
     1340    msgs->maxActiveRequests = MIN( 8 + (int)(msgs->info->rateToClient/5), 100 );
     1341    msgs->minActiveRequests = msgs->maxActiveRequests / 3;
    13891342    return TRUE;
    13901343}
     
    16771630    m->outMessages = evbuffer_new( );
    16781631    m->outBlock = evbuffer_new( );
    1679     m->inBlock = evbuffer_new( );
    16801632    m->peerAllowedPieces = NULL;
    16811633    m->clientAllowedPieces = NULL;
     
    16971649    }
    16981650   
    1699     tr_peerIoSetTimeoutSecs( m->io, 150 ); /* error if we don't read or write for 2.5 minutes */
     1651    tr_peerIoSetTimeoutSecs( m->io, 150 ); /* timeout after N seconds of inactivity */
    17001652    tr_peerIoSetIOFuncs( m->io, canRead, didWrite, gotError, m );
    17011653    tr_peerIoSetIOMode( m->io, EV_READ|EV_WRITE, 0 );
     
    17421694        evbuffer_free( msgs->outMessages );
    17431695        evbuffer_free( msgs->outBlock );
    1744         evbuffer_free( msgs->inBlock );
    17451696        tr_free( msgs->pex );
    17461697        msgs->pexCount = 0;
  • branches/0.9x/libtransmission/trevent.c

    r3457 r3780  
    229229    eh->lock = tr_lockNew( );
    230230    eh->h = handle;
    231     eh->pulseInterval = timevalMsec( 50 );
     231    eh->pulseInterval = timevalMsec( 25 );
    232232    eh->thread = tr_threadNew( libeventThreadFunc, eh, "libeventThreadFunc" );
    233233}
Note: See TracChangeset for help on using the changeset viewer.