Changeset 3089


Ignore:
Timestamp:
Sep 16, 2007, 11:39:11 PM (15 years ago)
Author:
charles
Message:
  • peer manager: use a lot less memory.
  • make peer code aware of libevent's buffered I/O, which was skewing our ul/dl speed measurements
  • only refill our peers' request lists when we need to, rather than periodically.
  • fix simple cut-and-paste ratecontrol bug
Location:
branches/encryption/libtransmission
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • branches/encryption/libtransmission/inout.c

    r3065 r3089  
    5454                   size_t                buflen )
    5555{
    56     const tr_info_t * info = &tor->info;
     56    const tr_info * info = &tor->info;
    5757    const tr_file_t * file = &info->files[fileIndex];
    5858    typedef size_t (* iofunc) ( int, void *, size_t );
     
    9595                   uint64_t           * fileOffset )
    9696{
    97     const tr_info_t * info = &tor->info;
     97    const tr_info * info = &tor->info;
    9898
    9999    int i;
     
    157157    int fileIndex;
    158158    uint64_t fileOffset;
    159     const tr_info_t * info = &tor->info;
     159    const tr_info * info = &tor->info;
    160160
    161161    assert( 0<=pieceIndex && pieceIndex<tor->info.pieceCount );
     
    208208    int ret;
    209209    uint8_t * buf;
    210     const tr_info_t * info;
     210    const tr_info * info;
    211211
    212212    assert( tor != NULL );
     
    245245{
    246246    int i;
    247     const tr_info_t * info = &tor->info;
     247    const tr_info * info = &tor->info;
    248248
    249249    for( i=0; i<info->fileCount; ++i )
  • branches/encryption/libtransmission/internal.h

    r3076 r3089  
    102102struct tr_torrent
    103103{
    104     tr_handle_t               * handle;
    105     tr_info_t                   info;
     104    tr_handle                 * handle;
     105    tr_info                     info;
    106106
    107107    tr_speedlimit_t             uploadLimitMode;
  • branches/encryption/libtransmission/ipcparse.c

    r2391 r3089  
    586586
    587587int
    588 ipc_addinfo( benc_val_t * list, int tor, const tr_info_t * inf, int types )
     588ipc_addinfo( benc_val_t * list, int tor, const tr_info * inf, int types )
    589589{
    590590    benc_val_t * dict, * item, * file, * tier;
  • branches/encryption/libtransmission/ipcparse.h

    r2342 r3089  
    2828#include <inttypes.h>
    2929
    30 /* yay for typedefs, we can't forward declare benc_val_t or tr_info_t
     30/* yay for typedefs, we can't forward declare benc_val_t or tr_info
    3131   like with structs */
    3232#include "bencode.h"
     
    160160uint8_t *    ipc_mkgetinfo( struct ipc_info *, size_t *, enum ipc_msg, int64_t,
    161161                            int, const int * );
    162 int          ipc_addinfo  ( benc_val_t *, int, const tr_info_t *, int );
     162int          ipc_addinfo  ( benc_val_t *, int, const tr_info *, int );
    163163int          ipc_addstat  ( benc_val_t *, int, const tr_stat_t *, int );
    164164
  • branches/encryption/libtransmission/metainfo.c

    r2938 r3089  
    4545 * Local prototypes
    4646 **********************************************************************/
    47 static int realparse( tr_info_t * inf, const uint8_t * buf, size_t len );
     47static int realparse( tr_info * inf, const uint8_t * buf, size_t len );
    4848static void savedname( char * name, size_t len, const char * hash,
    4949                       const char * tag );
     
    5353static int getfile( char * buf, int size,
    5454                    const char * prefix, benc_val_t * name );
    55 static int getannounce( tr_info_t * inf, benc_val_t * meta );
     55static int getannounce( tr_info * inf, benc_val_t * meta );
    5656static char * announceToScrape( const char * announce );
    57 static int parseFiles( tr_info_t * inf, benc_val_t * name,
     57static int parseFiles( tr_info * inf, benc_val_t * name,
    5858                       benc_val_t * files, benc_val_t * length );
    5959
     
    6464 **********************************************************************/
    6565int
    66 tr_metainfoParseFile( tr_info_t * inf, const char * tag,
     66tr_metainfoParseFile( tr_info * inf, const char * tag,
    6767                      const char * path, int save )
    6868{
     
    103103
    104104int
    105 tr_metainfoParseData( tr_info_t * inf, const char * tag,
     105tr_metainfoParseData( tr_info * inf, const char * tag,
    106106                      const uint8_t * data, size_t size, int save )
    107107{
     
    124124
    125125int
    126 tr_metainfoParseHash( tr_info_t * inf, const char * tag, const char * hash )
     126tr_metainfoParseHash( tr_info * inf, const char * tag, const char * hash )
    127127{
    128128    struct stat sb;
     
    173173
    174174static int
    175 realparse( tr_info_t * inf, const uint8_t * buf, size_t size )
     175realparse( tr_info * inf, const uint8_t * buf, size_t size )
    176176{
    177177    benc_val_t   meta, * beInfo, * val, * val2;
     
    309309}
    310310
    311 void tr_metainfoFree( tr_info_t * inf )
     311void tr_metainfoFree( tr_info * inf )
    312312{
    313313    int i, j;
     
    324324    tr_free( inf->trackerList );
    325325
    326     memset( inf, '\0', sizeof(tr_info_t) );
     326    memset( inf, '\0', sizeof(tr_info) );
    327327}
    328328
     
    383383}
    384384
    385 static int getannounce( tr_info_t * inf, benc_val_t * meta )
     385static int getannounce( tr_info * inf, benc_val_t * meta )
    386386{
    387387    benc_val_t        * val, * subval, * urlval;
     
    692692
    693693static int
    694 parseFiles( tr_info_t * inf, benc_val_t * name,
     694parseFiles( tr_info * inf, benc_val_t * name,
    695695            benc_val_t * files, benc_val_t * length )
    696696{
  • branches/encryption/libtransmission/metainfo.h

    r2207 r3089  
    2828#include "transmission.h"
    2929
    30 int tr_metainfoParseFile( tr_info_t *, const char * tag,
     30int tr_metainfoParseFile( tr_info *, const char * tag,
    3131                          const char * path, int save );
    32 int tr_metainfoParseData( tr_info_t *, const char * tag,
     32int tr_metainfoParseData( tr_info *, const char * tag,
    3333                          const uint8_t * data, size_t size, int save );
    34 int tr_metainfoParseHash( tr_info_t *, const char * tag, const char * hash );
    35 void tr_metainfoFree( tr_info_t * inf );
     34int tr_metainfoParseHash( tr_info *, const char * tag, const char * hash );
     35void tr_metainfoFree( tr_info * inf );
    3636void tr_metainfoRemoveSaved( const char * hashString, const char * tag );
    3737
  • branches/encryption/libtransmission/peer-io.c

    r3070 r3089  
    338338***
    339339**/
     340
     341size_t
     342tr_peerIoWriteBytesWaiting( const tr_peerIo * io )
     343{
     344    return EVBUFFER_LENGTH( EVBUFFER_OUTPUT( io->bufev ) );
     345}
    340346 
    341347void
  • branches/encryption/libtransmission/peer-io.h

    r3070 r3089  
    109109                           short         disable_mode );
    110110
     111size_t tr_peerIoWriteBytesWaiting( const tr_peerIo * io );
     112
    111113void tr_peerIoWrite( tr_peerIo   * io,
    112114                     const void  * writeme,
  • branches/encryption/libtransmission/peer-mgr.c

    r3078 r3089  
    4343**/
    4444
    45 struct tr_block
    46 {
    47     unsigned int have          : 1;
    48     unsigned int dnd           : 1;
    49     unsigned int low_priority  : 1;
    50     unsigned int high_priority : 1;
    51     uint8_t requestCount;
    52     uint8_t scarcity;
    53     uint32_t block;
    54 };
    55 
    56 #define MAX_SCARCITY UINT8_MAX
    57 #define MAX_REQ_COUNT UINT8_MAX
    58 
    59 static void
    60 incrementReqCount( struct tr_block * block )
    61 {
    62     assert( block != NULL );
    63 
    64     if( block->requestCount < MAX_REQ_COUNT )
    65         block->requestCount++;
    66 }
    67 
    68 static void
    69 incrementScarcity( struct tr_block * block )
    70 {
    71     assert( block != NULL );
    72 
    73     if( block->scarcity < MAX_SCARCITY )
    74         block->scarcity++;
    75 }
    76 
    77 static int
    78 compareBlockByIndex( const void * va, const void * vb )
    79 {
    80     const struct tr_block * a = (const struct tr_block *) va;
    81     const struct tr_block * b = (const struct tr_block *) vb;
    82     return tr_compareUint32( a->block, b->block );
    83 }
    84 
    85 static int
    86 compareBlockByInterest( const void * va, const void * vb )
    87 {
    88     const struct tr_block * a = (const struct tr_block *) va;
    89     const struct tr_block * b = (const struct tr_block *) vb;
    90     int i;
    91 
    92     if( a->dnd != b->dnd )
    93         return a->dnd ? 1 : -1;
    94 
    95     if( a->have != b->have )
    96         return a->have ? 1 : -1;
    97 
    98     if(( i = tr_compareUint8( a->requestCount, b->requestCount )))
    99         return i;
    100 
    101     if( a->high_priority != b->high_priority )
    102         return a->high_priority ? -1 : 1;
    103 
    104     if( a->low_priority != b->low_priority )
    105         return a->low_priority ? 1 : -1;
    106 
    107     if(( i = tr_compareUint16( a->scarcity, b->scarcity )))
    108         return i;
    109 
    110     if(( i = tr_compareUint32( a->block, b->block )))
    111         return i;
    112 
    113     return 0;
    114 }
    115 
    116 /**
    117 ***
    118 **/
    119 
    12045typedef struct
    12146{
     
    12550    tr_timer * refillTimer;
    12651    tr_torrent * tor;
    127 
    128     struct tr_block * blocks;
    129     uint32_t blockCount;
     52    tr_bitfield * requested;
    13053
    13154    unsigned int isRunning : 1;
     
    273196        freePeer( peers[i] );
    274197
     198    tr_bitfieldFree( t->requested );
    275199    tr_ptrArrayFree( t->peers );
    276200    tr_ptrArrayRemoveSorted( manager->torrents, t, torrentCompare );
    277     tr_free( t->blocks );
    278201    tr_free( t );
    279202
     
    312235}
    313236
    314 /**
    315 ***
    316 **/
    317 
    318237static tr_peer**
    319238getConnectedPeers( Torrent * t, int * setmeCount )
     
    331250}
    332251
    333 static void
    334 populateBlockArray( Torrent * t )
     252/***
     253****  Refill
     254***/
     255
     256struct tr_refill_piece
     257{
     258    tr_priority_t priority;
     259    uint32_t piece;
     260    uint32_t peerCount;
     261};
     262
     263static int
     264compareRefillPiece (const void * aIn, const void * bIn)
     265{
     266    const struct tr_refill_piece * a = aIn;
     267    const struct tr_refill_piece * b = bIn;
     268
     269    /* if one piece has a higher priority, it goes first */
     270    if (a->priority != b->priority)
     271        return a->priority > b->priority ? -1 : 1;
     272
     273    /* otherwise if one has fewer peers, it goes first */
     274    if (a->peerCount != b->peerCount)
     275        return a->peerCount < b->peerCount ? -1 : 1;
     276
     277    /* otherwise go with the earlier piece */
     278    return a->piece - b->piece;
     279}
     280
     281static int
     282isPieceInteresting( const tr_torrent  * tor,
     283                    int                 piece )
     284{
     285    if( tor->info.pieces[piece].dnd ) /* we don't want it */
     286        return 0;
     287
     288    if( tr_cpPieceIsComplete( tor->completion, piece ) ) /* we already have it */
     289        return 0;
     290
     291    return 1;
     292}
     293
     294static uint32_t*
     295getPreferredPieces( Torrent     * t,
     296                    uint32_t    * pieceCount )
     297{
     298    const tr_torrent * tor = t->tor;
     299    const tr_info * inf = &tor->info;
     300
     301    int i;
     302    uint32_t poolSize = 0;
     303    uint32_t * pool = tr_new( uint32_t, inf->pieceCount );
     304
     305    int peerCount;
     306    tr_peer** peers = getConnectedPeers( t, &peerCount );
     307
     308    for( i=0; i<inf->pieceCount; ++i )
     309        if( isPieceInteresting( tor, i ) )
     310            pool[poolSize++] = i;
     311
     312    /* sort the pool from most interesting to least... */
     313    if( poolSize > 1 )
     314    {
     315        uint32_t j;
     316        struct tr_refill_piece * p = tr_new( struct tr_refill_piece, poolSize );
     317
     318        for( j=0; j<poolSize; ++j )
     319        {
     320            int k;
     321            const int piece = pool[j];
     322            struct tr_refill_piece * setme = p + j;
     323
     324            setme->piece = piece;
     325            setme->priority = inf->pieces[piece].priority;
     326            setme->peerCount = 0;
     327
     328            for( k=0; k<peerCount; ++k ) {
     329                const tr_peer * peer = peers[k];
     330                if( peer->peerIsInterested && !peer->clientIsChoked && tr_bitfieldHas( peer->have, piece ) )
     331                    ++setme->peerCount;
     332            }
     333        }
     334
     335        qsort (p, poolSize, sizeof(struct tr_refill_piece), compareRefillPiece);
     336
     337        for( j=0; j<poolSize; ++j )
     338            pool[j] = p[j].piece;
     339
     340        tr_free( p );
     341    }
     342
     343#if 0
     344fprintf (stderr, "new pool: ");
     345for (i=0; i<15 && i<poolSize; ++i ) fprintf (stderr, "%d, ", pool[i] );
     346fprintf (stderr, "\n");
     347#endif
     348    tr_free( peers );
     349
     350    *pieceCount = poolSize;
     351    return pool;
     352}
     353
     354static uint64_t*
     355getPreferredBlocks( Torrent * t, uint64_t * setmeCount )
    335356{
    336357    uint32_t i;
    337     struct tr_block * b;
     358    uint32_t pieceCount;
     359    uint32_t * pieces;
     360    uint64_t *req, *unreq, *ret;
     361    int reqCount, unreqCount;
    338362    const tr_torrent * tor = t->tor;
    339363
    340     t->blockCount = tor->blockCount;
    341     t->blocks = b = tr_new( struct tr_block, t->blockCount );
    342 
    343     for( i=0; i<t->blockCount; ++i, ++b )
    344     {
    345         const int index = tr_torBlockPiece( tor, i );
    346         b->have = tr_cpBlockIsComplete( tor->completion, i ) ? 1 : 0;
    347         b->dnd = tor->info.pieces[index].dnd ? 1 : 0;
    348         b->low_priority = tor->info.pieces[index].priority == TR_PRI_LOW;
    349         b->high_priority = tor->info.pieces[index].priority == TR_PRI_HIGH;
    350         b->requestCount = 0;
    351         b->scarcity = 0;
    352         b->block = i;
    353     }
     364    pieces = getPreferredPieces( t, &pieceCount );
     365fprintf( stderr, "REFILL refillPulse for {%s} got %d of %d pieces\n", tor->info.name, (int)pieceCount, t->tor->info.pieceCount );
     366
     367    req = tr_new( uint64_t, pieceCount *  tor->blockCountInPiece );
     368    reqCount = 0;
     369    unreq = tr_new( uint64_t, pieceCount *  tor->blockCountInPiece );
     370    unreqCount = 0;
     371
     372    for( i=0; i<pieceCount; ++i ) {
     373        const uint32_t index = pieces[i];
     374        const int begin = tr_torPieceFirstBlock( tor, index );
     375        const int end = begin + tr_torPieceCountBlocks( tor, (int)index );
     376        int block;
     377        for( block=begin; block<end; ++block )
     378            if( tr_cpBlockIsComplete( tor->completion, block ) )
     379                continue;
     380            else if( tr_bitfieldHas( t->requested, block ) )
     381                req[reqCount++] = block;
     382            else
     383                unreq[unreqCount++] = block;
     384    }
     385
     386fprintf( stderr, "REFILL refillPulse for {%s} reqCount is %d\n", tor->info.name, (int)reqCount );
     387fprintf( stderr, "REFILL refillPulse for {%s} unreqCount is %d\n", tor->info.name, (int)unreqCount );
     388    ret = tr_new( uint64_t, unreqCount + reqCount );
     389    memcpy( ret, unreq, sizeof(uint64_t) * unreqCount );
     390    memcpy( ret, req, sizeof(uint64_t) * reqCount );
     391    *setmeCount = unreqCount + reqCount;
     392
     393    tr_free( req );
     394    tr_free( unreq );
     395
     396    return ret;
    354397}
    355398
     
    357400refillPulse( void * vtorrent )
    358401{
     402    Torrent * t = vtorrent;
     403    tr_torrent * tor = t->tor;
    359404    uint32_t i;
    360     int size;
    361     Torrent * t = (Torrent *) vtorrent;
     405    int peerCount;
    362406    tr_peer ** peers;
    363     const int isSeeding = tr_cpGetStatus( t->tor->completion ) != TR_CP_INCOMPLETE;
    364     const int wantToRefill = t->isRunning && !isSeeding;
    365 
    366     if( !wantToRefill && t->blocks!=NULL ) /* torrent has stopped or switched to seeding */
    367     {
    368         tr_free( t->blocks );
    369         t->blocks = NULL;
    370         t->blockCount = 0;
    371     }
    372     else if( wantToRefill && t->blocks==NULL ) /* torrent has started or switched to leeching */
    373     {
    374         populateBlockArray( t );
    375     }
    376 
    377     peers = getConnectedPeers( t, &size );
    378     if( wantToRefill && size>0 )
    379     {
    380         /* sort the blocks by interest */
    381         fprintf( stderr, "sorting [%s] blocks by interest...", t->tor->info.name );
    382         qsort( t->blocks, t->blockCount, sizeof(struct tr_block), compareBlockByInterest );
    383         fprintf( stderr, "done\n" );
    384 
    385         /* walk through all the most interesting blocks */
    386         for( i=0; i<t->blockCount; ++i )
     407    uint64_t blockCount;
     408    uint64_t * blocks;
     409
     410    if( !t->isRunning )
     411        return TRUE;
     412    if( tr_cpGetStatus( t->tor->completion ) != TR_CP_INCOMPLETE )
     413        return TRUE;
     414
     415    blocks = getPreferredBlocks( t, &blockCount );
     416    peers = getConnectedPeers( t, &peerCount );
     417
     418fprintf( stderr, "REFILL refillPulse for {%s} got %d blocks\n", tor->info.name, (int)blockCount );
     419
     420    for( i=0; peerCount && i<blockCount; ++i )
     421    {
     422        const int block = blocks[i];
     423        const uint32_t index = tr_torBlockPiece( tor, block );
     424        const uint32_t begin = tor->blockSize * (block - tr_torPieceFirstBlock(tor,index));
     425        const uint32_t length = tr_torBlockCountBytes( tor, block );
     426        int j;
     427
     428        /* find a peer who can ask for this block */
     429        for( j=0; j<peerCount; )
    387430        {
    388             const uint32_t b = t->blocks[i].block;
    389             const uint32_t index = tr_torBlockPiece( t->tor, b );
    390             const uint32_t begin = ( b * t->tor->blockSize )-( index * t->tor->info.pieceSize );
    391             const uint32_t length = tr_torBlockCountBytes( t->tor, (int)b );
    392             int j;
    393 
    394             if( t->blocks[i].have || t->blocks[i].dnd )
    395                 continue;
    396 
    397             if( !size ) /* all peers full */
    398                 break;
    399 
    400             /* find a peer who can ask for this block */
    401             for( j=0; j<size; )
     431            const int val = tr_peerMsgsAddRequest( peers[j]->msgs, index, begin, length );
     432            switch( val )
    402433            {
    403                 const int val = tr_peerMsgsAddRequest( peers[j]->msgs, index, begin, length );
    404                 switch( val )
    405                 {
    406                     case TR_ADDREQ_FULL:
    407                     case TR_ADDREQ_CLIENT_CHOKED:
    408                         peers[j] = peers[--size];
    409                         break;
    410 
    411                     case TR_ADDREQ_MISSING:
    412                         ++j;
    413                         break;
    414 
    415                     case TR_ADDREQ_OK:
    416                         fprintf( stderr, "peer %p took the request for block %d\n", peers[j]->msgs, b );
    417                         incrementReqCount( &t->blocks[i] );
    418                         j = size;
    419                         break;
    420                 }
     434                case TR_ADDREQ_FULL:
     435                case TR_ADDREQ_CLIENT_CHOKED:
     436                    peers[j] = peers[--peerCount];
     437                    break;
     438
     439                case TR_ADDREQ_MISSING:
     440                    ++j;
     441                    break;
     442
     443                case TR_ADDREQ_OK:
     444                    fprintf( stderr, "REFILL peer %p took the request for block %d\n", peers[j]->msgs, block );
     445                    tr_bitfieldAdd( t->requested, block );
     446                    j = peerCount;
     447                    break;
    421448            }
    422449        }
    423 
    424         /* put the blocks back the way we found them */
    425         qsort( t->blocks, t->blockCount, sizeof(struct tr_block), compareBlockByIndex );
    426450    }
    427451
    428452    /* cleanup */
    429453    tr_free( peers );
    430 
    431     return TRUE;
     454    tr_free( blocks );
     455
     456    t->refillTimer = NULL;
     457    return FALSE;
    432458}
    433459
     
    460486    switch( e->eventType )
    461487    {
    462         case TR_PEERMSG_PEER_BITFIELD: {
    463             if( t->blocks!=NULL ) {
    464                 int i;
    465                 for( i=0; i<t->tor->info.pieceCount; ++i ) {
    466                     const uint32_t begin = tr_torPieceFirstBlock( t->tor, i );
    467                     const uint32_t end = begin + tr_torPieceCountBlocks( t->tor, i );
    468                     uint32_t j;
    469                     for( j=begin; t->blocks!=NULL && j<end; ++j ) {
    470                         assert( t->blocks[j].block == j );
    471                         incrementScarcity( &t->blocks[j] );
    472                     }
    473                 }
    474             }
     488        case TR_PEERMSG_NEED_REQ:
     489            if( t->refillTimer == NULL )
     490                t->refillTimer = tr_timerNew( t->manager->handle, refillPulse, t, REFILL_PERIOD_MSEC );
    475491            break;
    476         }
    477492
    478493        case TR_PEERMSG_CLIENT_HAVE:
     
    480495            break;
    481496
    482         case TR_PEERMSG_PEER_HAVE: {
    483             if( t->blocks != NULL ) {
    484                 uint32_t i;
    485                 const uint32_t begin = tr_torPieceFirstBlock( t->tor, e->pieceIndex );
    486                 const uint32_t end = begin + tr_torPieceCountBlocks( t->tor, (int)e->pieceIndex );
    487                 for( i=begin; i<end; ++i ) {
    488                     assert( t->blocks[i].block == i );
    489                     incrementScarcity( &t->blocks[i] );
    490                 }
    491             }
    492             break;
    493         }
    494 
    495         case TR_PEERMSG_CLIENT_BLOCK: {
    496             if( t->blocks != NULL ) {
    497                 const uint32_t i = _tr_block( t->tor, e->pieceIndex, e->offset );
    498                 assert( t->blocks[i].block == i );
    499                 t->blocks[i].have = 1;
    500             }
     497        case TR_PEERMSG_CLIENT_BLOCK:
    501498            broadcastGotBlock( t, e->pieceIndex, e->offset, e->length );
    502499            break;
    503         }
    504500
    505501        case TR_PEERMSG_GOT_PEX:
     
    774770
    775771void
    776 tr_peerMgrUpdateCompletion( tr_peerMgr     * manager,
    777                             const uint8_t  * torrentHash )
    778 {
    779     uint32_t i;
    780     Torrent * t = getExistingTorrent( manager, torrentHash );
    781 
    782     for( i=0; t->blocks!=NULL && i<t->blockCount; ++i ) {
    783         assert( t->blocks[i].block == i );
    784         t->blocks[i].have = tr_cpBlockIsComplete( t->tor->completion, i ) ? 1 : 0;
    785     }
    786 }
    787 
    788 void
    789772tr_peerMgrAddTorrent( tr_peerMgr * manager,
    790773                      tr_torrent * tor )
     
    799782    t->tor = tor;
    800783    t->peers = tr_ptrArrayNew( );
     784    t->requested = tr_bitfieldNew( tor->blockCount );
    801785    t->chokeTimer = tr_timerNew( manager->handle, chokePulse, t, RECHOKE_PERIOD_SECONDS );
    802     t->refillTimer = tr_timerNew( t->manager->handle, refillPulse, t, REFILL_PERIOD_MSEC );
    803786
    804787    memcpy( t->hash, tor->info.hash, SHA_DIGEST_LENGTH );
  • branches/encryption/libtransmission/peer-mgr.h

    r3076 r3089  
    7373                           struct tr_torrent  * tor );
    7474
    75 void tr_peerMgrUpdateCompletion( tr_peerMgr     * manager,
    76                                  const uint8_t  * torrentHash );
    77 
    78 
    7975void tr_peerMgrRemoveTorrent( tr_peerMgr     * manager,
    8076                               const uint8_t  * torrentHash );
  • branches/encryption/libtransmission/peer-msgs.c

    r3076 r3089  
    129129**/
    130130
    131 static const tr_peermsgs_event blankEvent = { 0, 0, 0, 0, NULL };
     131static const tr_peermsgs_event blankEvent = { 0, 0, 0, 0 };
    132132
    133133static void
     
    146146
    147147static void
    148 fireGotBitfield( tr_peermsgs * peer, const tr_bitfield * bitfield )
     148fireNeedReq( tr_peermsgs * msgs )
    149149{
    150150    tr_peermsgs_event e = blankEvent;
    151     e.eventType = TR_PEERMSG_PEER_BITFIELD;
    152     e.bitfield = bitfield;
    153     tr_publisherPublish( peer->publisher, peer, &e );
    154 }
    155 
    156 static void
    157 fireHave( tr_peermsgs * msgs, int isClient, uint32_t pieceIndex )
     151    e.eventType = TR_PEERMSG_NEED_REQ;
     152    tr_publisherPublish( msgs->publisher, msgs, &e );
     153}
     154
     155static void
     156fireClientHave( tr_peermsgs * msgs, uint32_t pieceIndex )
    158157{
    159158    tr_peermsgs_event e = blankEvent;
    160     e.eventType = isClient ? TR_PEERMSG_CLIENT_HAVE : TR_PEERMSG_PEER_HAVE;
     159    e.eventType = TR_PEERMSG_CLIENT_HAVE;
    161160    e.pieceIndex = pieceIndex;
    162161    tr_publisherPublish( msgs->publisher, msgs, &e );
    163 }
    164 
    165 static void
    166 fireClientHave( tr_peermsgs * msgs, uint32_t pieceIndex )
    167 {
    168     fireHave( msgs, TRUE, pieceIndex );
    169 }
    170 
    171 static void
    172 firePeerHave( tr_peermsgs * msgs, uint32_t pieceIndex )
    173 {
    174     fireHave( msgs, FALSE, pieceIndex );
    175162}
    176163
     
    261248    if( i != msgs->info->clientIsInterested )
    262249        sendInterest( msgs, i );
     250    if( i )
     251        fireNeedReq( msgs );
    263252}
    264253
     
    549538            tr_list_foreach( msgs->peerAskedFor, tr_free );
    550539            tr_list_free( &msgs->peerAskedFor );
    551             /* FIXME: maybe choke them */
    552540            /* FIXME: unmark anything we'd requested from them... */
    553541            break;
     
    557545            fprintf( stderr, "peer-msgs %p sent us a BT_UNCHOKE\n", msgs );
    558546            msgs->info->clientIsChoked = 0;
    559             /* FIXME: maybe unchoke them */
    560             /* FIXME: maybe send them requests */
     547            fireNeedReq( msgs );
    561548            break;
    562549
     
    565552            fprintf( stderr, "peer-msgs %p sent us a BT_INTERESTED\n", msgs );
    566553            msgs->info->peerIsInterested = 1;
    567             /* FIXME: maybe unchoke them */
    568554            break;
    569555
     
    572558            fprintf( stderr, "peer-msgs %p sent us a BT_NOT_INTERESTED\n", msgs );
    573559            msgs->info->peerIsInterested = 0;
    574             /* FIXME: maybe choke them */
    575560            break;
    576561
     
    583568            fprintf( stderr, "after the HAVE message, peer progress is %f\n", msgs->info->progress );
    584569            updateInterest( msgs );
    585             firePeerHave( msgs, ui32 );
    586570            break;
    587571
     
    592576            msgs->info->progress = tr_bitfieldCountTrueBits( msgs->info->have ) / (float)msgs->torrent->info.pieceCount;
    593577            fprintf( stderr, "after the BITFIELD peer progress is %f\n", msgs->info->progress );
    594             fireGotBitfield( msgs, msgs->info->have );
    595578            updateInterest( msgs );
    596579            /* FIXME: maybe unchoke */
     
    678661    tor->uploadedCur += byteCount;
    679662    tr_rcTransferred( tor->upload, byteCount );
    680     tr_rcTransferred( tor->upload, byteCount );
     663    tr_rcTransferred( tor->handle->upload, byteCount );
    681664}
    682665
     
    797780
    798781    fireGotBlock( msgs, index, offset, length );
     782    fireNeedReq( msgs );
    799783
    800784    /**
     
    876860
    877861static int
    878 canUpload( const tr_peermsgs * peer )
    879 {
    880     const tr_torrent * tor = peer->torrent;
     862canUpload( const tr_peermsgs * msgs )
     863{
     864    const tr_torrent * tor = msgs->torrent;
     865
     866    /* don't let our outbuffer get too large */
     867    if( tr_peerIoWriteBytesWaiting( msgs->io ) > 1024 )
     868        return FALSE;
    881869
    882870    if( tor->uploadLimitMode == TR_SPEEDLIMIT_GLOBAL )
     
    11461134
    11471135    sendBitfield( peer );
     1136    fireNeedReq( peer );
    11481137
    11491138    return peer;
  • branches/encryption/libtransmission/peer-msgs.h

    r3070 r3089  
    5757typedef enum
    5858{
    59     TR_PEERMSG_PEER_BITFIELD,
    60     TR_PEERMSG_PEER_HAVE,
    6159    TR_PEERMSG_CLIENT_HAVE,
    6260    TR_PEERMSG_CLIENT_BLOCK,
    6361    TR_PEERMSG_GOT_PEX,
    64     TR_PEERMSG_GOT_ERROR
     62    TR_PEERMSG_GOT_ERROR,
     63    TR_PEERMSG_NEED_REQ
    6564}
    6665PeerMsgsEventType;
     
    7271    uint32_t offset;     /* for TR_PEERMSG_GOT_BLOCK */
    7372    uint32_t length;     /* for TR_PEERMSG_GOT_BLOCK */
    74     const struct tr_bitfield * bitfield; /* for TR_PEERMSG_GOT_BITFIELD */
    7573}
    7674tr_peermsgs_event;
  • branches/encryption/libtransmission/peer.c

    r2956 r3089  
    575575    {
    576576        uint8_t buf[HANDSHAKE_SIZE];
    577         const tr_info_t * inf;
     577        const tr_info * inf;
    578578
    579579        inf = tr_torrentInfo( tor );
  • branches/encryption/libtransmission/peeraz.h

    r2941 r3089  
    495495parseAZPex( tr_torrent * tor, tr_peer_t * peer, uint8_t * buf, int len )
    496496{
    497     tr_info_t * info = &tor->info;
     497    tr_info * info = &tor->info;
    498498    benc_val_t  val, * list, * pair;
    499499    int         ii, used;
  • branches/encryption/libtransmission/peermessages.h

    r2949 r3089  
    295295static void sendRequest( tr_torrent * tor, tr_peer_t * peer, int block )
    296296{
    297     tr_info_t * inf = &tor->info;
     297    tr_info * inf = &tor->info;
    298298    tr_request_t * r;
    299299    uint8_t * p;
  • branches/encryption/libtransmission/peerparse.h

    r2949 r3089  
    105105                      uint8_t * p, int len )
    106106{
    107     tr_info_t * inf = &tor->info;
     107    tr_info * inf = &tor->info;
    108108    uint32_t piece;
    109109
     
    143143                          uint8_t * p, int len )
    144144{
    145     tr_info_t * inf = &tor->info;
     145    tr_info * inf = &tor->info;
    146146    int bitfieldSize;
    147147    int i;
     
    198198                         uint8_t * p, int len )
    199199{
    200     tr_info_t * inf = &tor->info;
     200    tr_info * inf = &tor->info;
    201201    int index, begin, length;
    202202    tr_request_t * r;
     
    285285                       uint8_t * p, int len )
    286286{
    287     tr_info_t * inf = &tor->info;
     287    tr_info * inf = &tor->info;
    288288    int index, begin, block, i, ret;
    289289
     
    383383                        uint8_t * p, int len )
    384384{
    385     tr_info_t * inf = &tor->info;
     385    tr_info * inf = &tor->info;
    386386    int index, begin, length;
    387387    tr_request_t req;
     
    600600static int parseHandshake( tr_torrent * tor, tr_peer_t * peer )
    601601{
    602     tr_info_t * inf = &tor->info;
     602    tr_info * inf = &tor->info;
    603603    int         ii, extmsgs, azproto;
    604604    char      * dbgsup, * dbgwant;
  • branches/encryption/libtransmission/peerutils.h

    r2941 r3089  
    229229                                int               * isEndgame )
    230230{
    231     const tr_info_t * inf = &tor->info;
     231    const tr_info * inf = &tor->info;
    232232
    233233    int i;
  • branches/encryption/libtransmission/ratecontrol.c

    r3061 r3089  
    5656{
    5757    uint64_t bytes = 0;
    58     const uint64_t now = tr_date ();
     58    const uint64_t cutoff = tr_date () - interval_msec;
    5959    int i = r->newest;
    6060    for( ;; )
    6161    {
    62         if( r->transfers[i].date + interval_msec < now )
     62        if( r->transfers[i].date < cutoff )
    6363            break;
    6464
  • branches/encryption/libtransmission/ratecontrol.h

    r3061 r3089  
    3232int              tr_rcGetLimit( const tr_ratecontrol * );
    3333int              tr_rcCanTransfer( const tr_ratecontrol * );
    34 void             tr_rcTransferred( tr_ratecontrol *, size_t );
     34void             tr_rcTransferred( tr_ratecontrol *, size_t byteCount );
    3535float            tr_rcRate( const tr_ratecontrol * );
    3636void             tr_rcReset( tr_ratecontrol * );
  • branches/encryption/libtransmission/torrent.c

    r3076 r3089  
    180180
    181181static int
    182 getBytePiece( const tr_info_t * info, uint64_t byteOffset )
     182getBytePiece( const tr_info * info, uint64_t byteOffset )
    183183{
    184184    assert( info != NULL );
     
    189189
    190190static void
    191 initFilePieces ( tr_info_t * info, int fileIndex )
     191initFilePieces ( tr_info * info, int fileIndex )
    192192{
    193193    tr_file_t * file = &info->files[fileIndex];
     
    267267recheckDoneCB( tr_torrent * tor )
    268268{
    269     tr_peerMgrUpdateCompletion( tor->handle->peerMgr,
    270                                 tor->info.hash );
    271 
    272269    recheckCpState( tor );
    273270
     
    285282    uint64_t t;
    286283    tr_bitfield * uncheckedPieces;
    287     tr_info_t * info = &tor->info;
     284    tr_info * info = &tor->info;
    288285   
    289286    tor->info.flags |= flags;
     
    442439infoCanAdd( const tr_handle_t   * h,
    443440            const char          * destination,
    444             const tr_info_t     * info )
     441            const tr_info     * info )
    445442{
    446443    if( hashExists( h, info->hash ) )
     
    457454                 const char         * path,
    458455                 const char         * destination,
    459                  tr_info_t          * setme_info )
     456                 tr_info          * setme_info )
    460457{
    461458    int ret, doFree;
    462     tr_info_t tmp;
     459    tr_info tmp;
    463460
    464461    if( setme_info == NULL )
    465462        setme_info = &tmp;
    466463
    467     memset( setme_info, 0, sizeof( tr_info_t ) );
     464    memset( setme_info, 0, sizeof( tr_info ) );
    468465    ret = tr_metainfoParseFile( setme_info, h->tag, path, FALSE );
    469466    doFree = !ret && (setme_info == &tmp);
     
    508505                     const char         * hashStr,
    509506                     const char         * destination,
    510                      tr_info_t          * setme_info )
     507                     tr_info          * setme_info )
    511508{
    512509    int ret, doFree;
    513     tr_info_t tmp;
     510    tr_info tmp;
    514511
    515512    if( setme_info == NULL )
    516513        setme_info = &tmp;
    517514
    518     memset( setme_info, 0, sizeof( tr_info_t ) );
     515    memset( setme_info, 0, sizeof( tr_info ) );
    519516    ret = tr_metainfoParseHash( setme_info, h->tag, hashStr );
    520517    doFree = !ret && (setme_info == &tmp);
     
    560557                     size_t               size,
    561558                     const char         * destination,
    562                      tr_info_t          * setme_info )
     559                     tr_info          * setme_info )
    563560{
    564561    int ret, doFree;
    565     tr_info_t tmp;
     562    tr_info tmp;
    566563
    567564    if( setme_info == NULL )
    568565        setme_info = &tmp;
    569566
    570     memset( setme_info, 0, sizeof( tr_info_t ) );
     567    memset( setme_info, 0, sizeof( tr_info ) );
    571568    ret = tr_metainfoParseData( setme_info, h->tag, data, size, FALSE );
    572569    doFree = !ret && (setme_info == &tmp);
     
    608605}
    609606
    610 const tr_info_t *
     607const tr_info *
    611608tr_torrentInfo( const tr_torrent * tor )
    612609{
     
    1001998    tr_torrent * t;
    1002999    tr_handle_t * h = tor->handle;
    1003     tr_info_t * inf = &tor->info;
     1000    tr_info * inf = &tor->info;
    10041001fprintf( stderr, "closing torrent %s\n", tor->info.name );
    10051002
     
    12851282int _tr_block( const tr_torrent * tor, int index, int begin )
    12861283{
    1287     const tr_info_t * inf = &tor->info;
     1284    const tr_info * inf = &tor->info;
    12881285    return index * ( inf->pieceSize / tor->blockSize ) +
    12891286        begin / tor->blockSize;
  • branches/encryption/libtransmission/tracker.c

    r3049 r3089  
    272272tr_trackerGet( const tr_torrent * tor )
    273273{
    274     const tr_info_t * info = &tor->info;
     274    const tr_info * info = &tor->info;
    275275    tr_ptrArray * trackers = getTrackerLookupTable( );
    276276    Tracker *t, tmp;
  • branches/encryption/libtransmission/transmission.h

    r2995 r3089  
    342342 */
    343343int tr_torrentParse( const tr_handle  * handle,
    344                      const char         * metainfo_filename,
    345                      const char         * destination,
    346                      tr_info_t          * setme_info );
     344                     const char       * metainfo_filename,
     345                     const char       * destination,
     346                     tr_info          * setme_info );
    347347
    348348/**
     
    352352int
    353353tr_torrentParseHash( const tr_handle  * h,
    354                      const char         * hashStr,
    355                      const char         * destination,
    356                      tr_info_t          * setme_info );
     354                     const char       * hashStr,
     355                     const char       * destination,
     356                     tr_info          * setme_info );
    357357
    358358
     
    389389void tr_torrentDisablePex( tr_torrent *, int disable );
    390390
    391 const tr_info_t * tr_torrentInfo( const tr_torrent * );
     391const tr_info * tr_torrentInfo( const tr_torrent * );
    392392
    393393#if 0
Note: See TracChangeset for help on using the changeset viewer.