Changeset 6073


Ignore:
Timestamp:
Jun 7, 2008, 9:26:41 PM (13 years ago)
Author:
charles
Message:

#800 initial support for GetRight?-style fetching of data through http and ftp servers specified in the .torrent's "url-list" tag

Location:
trunk
Files:
3 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/tr-prefs.c

    r6068 r6073  
    263263        char url[256];
    264264        snprintf( url, sizeof(url), "http://portcheck.transmissionbt.com/%d", port );
    265         tr_webRun( handle, url, testing_port_done, data );
     265        tr_webRun( handle, url, NULL, testing_port_done, data );
    266266    }
    267267    return FALSE;
     
    493493    gtk_widget_show( d );
    494494
    495     tr_webRun( handle, url, got_blocklist, data );
     495    tr_webRun( handle, url, NULL, got_blocklist, data );
    496496}
    497497
  • trunk/libtransmission/Makefile.am

    r6031 r6073  
    4343    utils.c \
    4444    verify.c \
    45     web.c
     45    web.c \
     46    webseed.c
    4647
    4748noinst_HEADERS = \
     
    6465    natpmp.h \
    6566    net.h \
     67    peer-common.h \
    6668    peer-io.h \
    6769    peer-mgr.h \
     
    8587    utils.h \
    8688    verify.h \
    87     web.h
     89    web.h \
     90    webseed.h
    8891
    8992TESTS = \
  • trunk/libtransmission/bencode.c

    r5988 r6073  
    497497    tr_bencInit( val, TYPE_STR );
    498498    val->val.s.i = byteCount;
    499     val->val.s.s = tr_new( char, byteCount );
     499    val->val.s.s = tr_memdup( src, byteCount );
    500500    val->val.s.nofree = 0;
    501     memcpy( val->val.s.s, src, byteCount );
    502501}
    503502
  • trunk/libtransmission/inout.c

    r5843 r6073  
    100100}
    101101
    102 static void
    103 findFileLocation( const tr_torrent * tor,
    104                   tr_piece_index_t   pieceIndex,
    105                   uint32_t           pieceOffset,
    106                   tr_file_index_t  * fileIndex,
    107                   uint64_t         * fileOffset )
     102void
     103tr_ioFindFileLocation( const tr_torrent * tor,
     104                       tr_piece_index_t   pieceIndex,
     105                       uint32_t           pieceOffset,
     106                       tr_file_index_t  * fileIndex,
     107                       uint64_t         * fileOffset )
    108108{
    109109    const uint64_t offset = tr_pieceOffset( tor, pieceIndex, pieceOffset, 0 );
     
    173173        return TR_ERROR_ASSERT;
    174174
    175     findFileLocation ( tor, pieceIndex, pieceOffset,
    176                             &fileIndex, &fileOffset );
     175    tr_ioFindFileLocation( tor, pieceIndex, pieceOffset,
     176                           &fileIndex, &fileOffset );
    177177
    178178    while( buflen && !err )
  • trunk/libtransmission/inout.h

    r5645 r6073  
    5858
    5959
     60/**
     61 * Converts a piece index + offset into a file index + offset.
     62 */
     63void tr_ioFindFileLocation( const tr_torrent * tor,
     64                            tr_piece_index_t   pieceIndex,
     65                            uint32_t           pieceOffset,
     66                            tr_file_index_t  * fileIndex,
     67                            uint64_t         * fileOffset );
     68
     69
     70
    6071#endif
  • trunk/libtransmission/metainfo.c

    r5963 r6073  
    222222
    223223    return scrape;
     224}
     225
     226static void
     227geturllist( tr_info * inf, tr_benc * meta )
     228{
     229    benc_val_t * urls;
     230
     231    if( tr_bencDictFindList( meta, "url-list", &urls ) )
     232    {
     233        int i;
     234        const char * url;
     235        const int n = tr_bencListSize( urls );
     236
     237        inf->webseedCount = 0;
     238        inf->webseeds = tr_new0( char*, n );
     239
     240        for( i=0; i<n; ++i )
     241            if( tr_bencGetStr( tr_bencListChild( urls, i ), &url ) )
     242                inf->webseeds[inf->webseedCount++] = tr_strdup( url );
     243    }
    224244}
    225245
     
    412432        goto fail;
    413433
     434    /* get the url-list */
     435    geturllist( inf, meta );
     436
    414437    /* filename of Transmission's copy */
    415438    getTorrentFilename( handle, inf, buf, sizeof( buf ) );
     
    429452    int i;
    430453
     454    for( i=0; i<inf->webseedCount; ++i )
     455        tr_free( inf->webseeds[i] );
     456
    431457    for( ff=0; ff<inf->fileCount; ++ff )
    432458        tr_free( inf->files[ff].name );
    433459
     460    tr_free( inf->webseeds );
    434461    tr_free( inf->pieces );
    435462    tr_free( inf->files );
  • trunk/libtransmission/peer-mgr.c

    r6071 r6073  
    2525#include "crypto.h"
    2626#include "handshake.h"
     27#include "inout.h" /* tr_ioTestPiece */
    2728#include "net.h"
    2829#include "peer-io.h"
     
    3233#include "ptrarray.h"
    3334#include "ratecontrol.h"
     35#include "stats.h" /* tr_statsAddDownloaded */
    3436#include "torrent.h"
    3537#include "trevent.h"
    3638#include "utils.h"
     39#include "webseed.h"
    3740
    3841enum
     
    104107    tr_ptrArray * pool; /* struct peer_atom */
    105108    tr_ptrArray * peers; /* tr_peer */
     109    tr_ptrArray * webseeds; /* tr_webseed */
    106110    tr_timer * reconnectTimer;
    107111    tr_timer * rechokeTimer;
     
    333337    atom->time = time( NULL );
    334338
    335     removed = tr_ptrArrayRemoveSorted  ( t->peers, peer, peerCompare );
     339    removed = tr_ptrArrayRemoveSorted( t->peers, peer, peerCompare );
    336340    assert( removed == peer );
    337341    peerDestructor( removed );
     
    364368
    365369    tr_bitfieldFree( t->requested );
     370    tr_ptrArrayFree( t->webseeds, (PtrArrayForeachFunc)tr_webseedFree );
    366371    tr_ptrArrayFree( t->pool, (PtrArrayForeachFunc)tr_free );
    367372    tr_ptrArrayFree( t->outgoingHandshakes, NULL );
     
    371376}
    372377
     378static void peerCallbackFunc( void * vpeer, void * vevent, void * vt );
     379
    373380static Torrent*
    374381torrentConstructor( tr_peerMgr * manager, tr_torrent * tor )
    375382{
     383    int i;
    376384    Torrent * t;
    377385
     
    381389    t->pool = tr_ptrArrayNew( );
    382390    t->peers = tr_ptrArrayNew( );
     391    t->webseeds = tr_ptrArrayNew( );
    383392    t->outgoingHandshakes = tr_ptrArrayNew( );
    384393    t->requested = tr_bitfieldNew( tor->blockCount );
    385394    memcpy( t->hash, tor->info.hash, SHA_DIGEST_LENGTH );
     395
     396    for( i=0; i<tor->info.webseedCount; ++i ) {
     397        tr_webseed * w = tr_webseedNew( tor, tor->info.webseeds[i], peerCallbackFunc, t );
     398        tr_ptrArrayAppend( t->webseeds, w );
     399    }
    386400
    387401    return t;
     
    537551    if( a->priority != b->priority )
    538552        return a->priority > b->priority ? -1 : 1;
    539     
     553   
    540554    /* otherwise if one has fewer peers, it goes first */
    541555    if (a->peerCount != b->peerCount)
    542556        return a->peerCount < b->peerCount ? -1 : 1;
    543557
     558#if 0
     559    /* otherwise download them in order */
     560    return tr_compareUint16( a->piece, b->piece );
     561#else
    544562    /* otherwise go with our random seed */
    545563    return tr_compareUint16( a->random, b->random );
     564#endif
    546565}
    547566
     
    742761    tr_block_index_t i;
    743762    int peerCount;
     763    int webseedCount;
    744764    tr_peer ** peers;
     765    tr_webseed ** webseeds;
    745766    tr_block_index_t blockCount;
    746767    uint64_t * blocks;
     
    756777    blocks = getPreferredBlocks( t, &blockCount );
    757778    peers = getPeersUploadingToClient( t, &peerCount );
    758 
    759     for( i=0; peerCount && i<blockCount; ++i )
     779    webseedCount = tr_ptrArraySize( t->webseeds );
     780    webseeds = tr_memdup( tr_ptrArrayBase(t->webseeds), webseedCount*sizeof(tr_webseed*) );
     781
     782
     783#warning do not check in this line
     784peerCount = 0;
     785
     786    for( i=0; (webseedCount || peerCount) && i<blockCount; ++i )
    760787    {
    761788        int j;
     789        int handled = FALSE;
    762790
    763791        const tr_block_index_t block = blocks[i];
     
    765793        const uint32_t begin = (block * tor->blockSize) - (index * tor->info.pieceSize);
    766794        const uint32_t length = tr_torBlockCountBytes( tor, block );
     795fprintf( stderr, "next block in the refill pulse is %d\n", (int)block );
    767796
    768797        assert( tr_torrentReqIsValid( tor, index, begin, length ) );
     
    772801
    773802        /* find a peer who can ask for this block */
    774         for( j=0; j<peerCount; )
     803        for( j=0; !handled && j<peerCount; )
    775804        {
    776805            const int val = tr_peerMsgsAddRequest( peers[j]->msgs, index, begin, length );
     
    781810                    memmove( peers+j, peers+j+1, sizeof(tr_peer*)*(--peerCount-j) );
    782811                    break;
    783 
    784812                case TR_ADDREQ_MISSING:
    785813                case TR_ADDREQ_DUPLICATE:
    786814                    ++j;
    787815                    break;
    788 
    789816                case TR_ADDREQ_OK:
    790817                    tr_bitfieldAdd( t->requested, block );
    791                     j = peerCount;
     818                    handled = TRUE;
    792819                    break;
    793 
    794820                default:
    795821                    assert( 0 && "unhandled value" );
     
    797823            }
    798824        }
     825
     826        /* maybe one of the webseeds can do it */
     827        for( j=0; !handled && j<webseedCount; )
     828        {
     829            const int val = tr_webseedAddRequest( webseeds[j], index, begin, length );
     830            switch( val )
     831            {
     832                case TR_ADDREQ_FULL:
     833                    memmove( webseeds+j, webseeds+j+1, sizeof(tr_webseed*)*(--webseedCount-j) );
     834                    break;
     835                case TR_ADDREQ_OK:
     836                    tr_bitfieldAdd( t->requested, block );
     837                    handled = TRUE;
     838                    break;
     839                default:
     840                    assert( 0 && "unhandled value" );
     841                    break;
     842            }
     843        }
    799844    }
    800845
    801846    /* cleanup */
     847    tr_free( webseeds );
    802848    tr_free( peers );
    803849    tr_free( blocks );
     
    806852    torrentUnlock( t );
    807853    return FALSE;
    808 }
    809 
    810 static void
    811 broadcastClientHave( Torrent * t, uint32_t index )
    812 {
    813     int i, size;
    814     tr_peer ** peers;
    815 
    816     assert( torrentIsLocked( t ) );
    817 
    818     peers = getConnectedPeers( t, &size );
    819     for( i=0; i<size; ++i )
    820         tr_peerMsgsHave( peers[i]->msgs, index );
    821     tr_free( peers );
    822854}
    823855
     
    851883
    852884static void
    853 msgsCallbackFunc( void * vpeer, void * vevent, void * vt )
    854 {
    855     tr_peer * peer = vpeer;
     885gotBadPiece( Torrent * t, tr_piece_index_t pieceIndex )
     886{
     887    tr_torrent * tor = t->tor;
     888    const uint32_t byteCount = tr_torPieceCountBytes( tor, pieceIndex );
     889    tor->corruptCur += byteCount;
     890    tor->downloadedCur -= MIN( tor->downloadedCur, byteCount );
     891}
     892
     893static void
     894peerCallbackFunc( void * vpeer, void * vevent, void * vt )
     895{
     896    tr_peer * peer = vpeer; /* may be NULL if peer is a webseed */
    856897    Torrent * t = (Torrent *) vt;
    857     const tr_peermsgs_event * e = (const tr_peermsgs_event *) vevent;
     898    const tr_peer_event * e = vevent;
    858899
    859900    torrentLock( t );
     
    861902    switch( e->eventType )
    862903    {
    863         case TR_PEERMSG_NEED_REQ:
     904        case TR_PEER_NEED_REQ:
    864905            if( t->refillTimer == NULL )
    865906                t->refillTimer = tr_timerNew( t->manager->handle,
     
    868909            break;
    869910
    870         case TR_PEERMSG_CANCEL:
     911        case TR_PEER_CANCEL:
    871912            tr_bitfieldRem( t->requested, _tr_block( t->tor, e->pieceIndex, e->offset ) );
    872913            break;
    873914
    874         case TR_PEERMSG_PIECE_DATA: {
    875             struct peer_atom * atom = getExistingAtom( t, &peer->in_addr );
    876             atom->piece_data_time = time( NULL );
     915        case TR_PEER_PEER_GOT_DATA: {
     916            const time_t now = time( NULL );
     917            tr_torrent * tor = t->tor;
     918            tor->activityDate = now;
     919            tor->uploadedCur += e->length;
     920            tr_rcTransferred( tor->upload, e->length );
     921            tr_rcTransferred( tor->handle->upload, e->length );
     922            tr_statsAddUploaded( tor->handle, e->length );
     923            if( peer ) {
     924                struct peer_atom * atom = getExistingAtom( t, &peer->in_addr );
     925                atom->piece_data_time = time( NULL );
     926            }
    877927            break;
    878928        }
    879929
    880         case TR_PEERMSG_CLIENT_HAVE:
    881             broadcastClientHave( t, e->pieceIndex );
    882             tr_torrentRecheckCompleteness( t->tor );
     930        case TR_PEER_CLIENT_GOT_DATA: {
     931            const time_t now = time( NULL );
     932            tr_torrent * tor = t->tor;
     933            tor->activityDate = now;
     934            tor->downloadedCur += e->length;
     935            tr_rcTransferred( tor->download, e->length );
     936            tr_rcTransferred( tor->handle->download, e->length );
     937            tr_statsAddDownloaded( tor->handle, e->length );
     938            if( peer ) {
     939                struct peer_atom * atom = getExistingAtom( t, &peer->in_addr );
     940                atom->piece_data_time = time( NULL );
     941            }
    883942            break;
    884 
    885         case TR_PEERMSG_PEER_PROGRESS: {
    886             struct peer_atom * atom = getExistingAtom( t, &peer->in_addr );
    887             const int peerIsSeed = e->progress >= 1.0;
    888             if( peerIsSeed ) {
    889                 tordbg( t, "marking peer %s as a seed", tr_peerIoAddrStr(&atom->addr,atom->port) );
    890                 atom->flags |= ADDED_F_SEED_FLAG;
    891             } else {
    892                 tordbg( t, "marking peer %s as a non-seed", tr_peerIoAddrStr(&atom->addr,atom->port) );
    893                 atom->flags &= ~ADDED_F_SEED_FLAG;
    894             } break;
    895         }
    896 
    897         case TR_PEERMSG_CLIENT_BLOCK:
     943        }
     944
     945        case TR_PEER_PEER_PROGRESS: {
     946            if( peer ) {
     947                struct peer_atom * atom = getExistingAtom( t, &peer->in_addr );
     948                const int peerIsSeed = e->progress >= 1.0;
     949                if( peerIsSeed ) {
     950                    tordbg( t, "marking peer %s as a seed", tr_peerIoAddrStr(&atom->addr,atom->port) );
     951                    atom->flags |= ADDED_F_SEED_FLAG;
     952                } else {
     953                    tordbg( t, "marking peer %s as a non-seed", tr_peerIoAddrStr(&atom->addr,atom->port) );
     954                    atom->flags &= ~ADDED_F_SEED_FLAG;
     955                }
     956            }
     957            break;
     958        }
     959
     960        case TR_PEER_CLIENT_GOT_BLOCK:
     961        {
     962            tr_torrent * tor = t->tor;
     963
     964            tr_block_index_t block = _tr_block( tor, e->pieceIndex, e->offset );
     965
     966            tr_cpBlockAdd( tor->completion, block );
     967
    898968            broadcastGotBlock( t, e->pieceIndex, e->offset, e->length );
     969
     970            if( tr_cpPieceIsComplete( tor->completion, e->pieceIndex ) )
     971            {
     972                const tr_piece_index_t p = e->pieceIndex;
     973                const tr_errno err = tr_ioTestPiece( tor, p );
     974
     975                if( err ) {
     976                    tr_torerr( tor, _( "Piece %lu, which was just downloaded, failed its checksum test: %s" ),
     977                               (unsigned long)p, tr_errorString( err ) );
     978                }
     979
     980                tr_torrentSetHasPiece( tor, p, !err );
     981                tr_torrentSetPieceChecked( tor, p, TRUE );
     982                tr_peerMgrSetBlame( tor->handle->peerMgr, tor->info.hash, p, !err );
     983
     984                if( err )
     985                    gotBadPiece( t, p );
     986
     987                tr_torrentRecheckCompleteness( tor );
     988            }
    899989            break;
    900 
    901         case TR_PEERMSG_ERROR:
     990        }
     991
     992        case TR_PEER_ERROR:
    902993            if( TR_ERROR_IS_IO( e->err ) ) {
    903994                t->tor->error = e->err;
     
    10251116                peer->port = port;
    10261117                peer->io = io;
    1027                 peer->msgs = tr_peerMsgsNew( t->tor, peer, msgsCallbackFunc, t, &peer->msgsTag );
     1118                peer->msgs = tr_peerMsgsNew( t->tor, peer, peerCallbackFunc, t, &peer->msgsTag );
    10281119                atom->time = time( NULL );
    10291120            }
  • trunk/libtransmission/peer-msgs.c

    r6071 r6073  
    156156reqListCopy( struct request_list * dest, const struct request_list * src )
    157157{
    158     dest->count = src->count;
    159     dest->max = src->max;
    160     dest->requests = tr_new( struct peer_request, dest->max );
    161     memcpy( dest->requests, src->requests, sizeof( struct peer_request ) * dest->count );
     158    dest->count = dest->max = src->count;
     159    dest->requests = tr_memdup( src->requests, dest->count * sizeof( struct peer_request ) );
    162160}
    163161
     
    397395**/
    398396
    399 static const tr_peermsgs_event blankEvent = { 0, 0, 0, 0, 0.0f, 0 };
    400 
    401 static void
    402 publish( tr_peermsgs * msgs, tr_peermsgs_event * e )
     397static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0.0f, 0 };
     398
     399static void
     400publish( tr_peermsgs * msgs, tr_peer_event * e )
    403401{
    404402    tr_publisherPublish( msgs->publisher, msgs->info, e );
     
    408406fireError( tr_peermsgs * msgs, tr_errno err )
    409407{
    410     tr_peermsgs_event e = blankEvent;
    411     e.eventType = TR_PEERMSG_ERROR;
     408    tr_peer_event e = blankEvent;
     409    e.eventType = TR_PEER_ERROR;
    412410    e.err = err;
    413411    publish( msgs, &e );
     
    417415fireNeedReq( tr_peermsgs * msgs )
    418416{
    419     tr_peermsgs_event e = blankEvent;
    420     e.eventType = TR_PEERMSG_NEED_REQ;
     417    tr_peer_event e = blankEvent;
     418    e.eventType = TR_PEER_NEED_REQ;
    421419    publish( msgs, &e );
    422420}
     
    425423firePeerProgress( tr_peermsgs * msgs )
    426424{
    427     tr_peermsgs_event e = blankEvent;
    428     e.eventType = TR_PEERMSG_PEER_PROGRESS;
     425    tr_peer_event e = blankEvent;
     426    e.eventType = TR_PEER_PEER_PROGRESS;
    429427    e.progress = msgs->info->progress;
    430428    publish( msgs, &e );
     
    432430
    433431static void
    434 fireClientHave( tr_peermsgs * msgs, uint32_t pieceIndex )
    435 {
    436     tr_peermsgs_event e = blankEvent;
    437     e.eventType = TR_PEERMSG_CLIENT_HAVE;
    438     e.pieceIndex = pieceIndex;
    439     publish( msgs, &e );
    440 }
    441 
    442 static void
    443432fireGotBlock( tr_peermsgs * msgs, const struct peer_request * req )
    444433{
    445     tr_peermsgs_event e = blankEvent;
    446     e.eventType = TR_PEERMSG_CLIENT_BLOCK;
     434    tr_peer_event e = blankEvent;
     435    e.eventType = TR_PEER_CLIENT_GOT_BLOCK;
    447436    e.pieceIndex = req->index;
    448437    e.offset = req->offset;
     
    452441
    453442static void
    454 firePieceData( tr_peermsgs * msgs )
    455 {
    456     tr_peermsgs_event e = blankEvent;
    457     e.eventType = TR_PEERMSG_PIECE_DATA;
     443fireClientGotData( tr_peermsgs * msgs, uint32_t length )
     444{
     445    tr_peer_event e = blankEvent;
     446    e.length = length;
     447    e.eventType = TR_PEER_CLIENT_GOT_DATA;
    458448    publish( msgs, &e );
    459449}
    460450
    461451static void
     452firePeerGotData( tr_peermsgs * msgs, uint32_t length )
     453{
     454    tr_peer_event e = blankEvent;
     455    e.length = length;
     456    e.eventType = TR_PEER_PEER_GOT_DATA;
     457    publish( msgs, &e );
     458}
     459
     460static void
    462461fireCancelledReq( tr_peermsgs * msgs, const struct peer_request * req )
    463462{
    464     tr_peermsgs_event e = blankEvent;
    465     e.eventType = TR_PEERMSG_CANCEL;
     463    tr_peer_event e = blankEvent;
     464    e.eventType = TR_PEER_CANCEL;
    466465    e.pieceIndex = req->index;
    467466    e.offset = req->offset;
     
    11871186clientGotBytes( tr_peermsgs * msgs, uint32_t byteCount )
    11881187{
    1189     const time_t now = time( NULL );
    1190     tr_torrent * tor = msgs->torrent;
    1191     tor->activityDate = now;
    1192     tor->downloadedCur += byteCount;
    1193     msgs->info->pieceDataActivityDate = now;
     1188    msgs->info->pieceDataActivityDate = time( NULL );
    11941189    tr_rcTransferred( msgs->info->rcToClient, byteCount );
    1195     tr_rcTransferred( tor->download, byteCount );
    1196     tr_rcTransferred( tor->handle->download, byteCount );
    1197     tr_statsAddDownloaded( msgs->handle, byteCount );
    1198     firePieceData( msgs );
     1190    fireClientGotData( msgs, byteCount );
    11991191}
    12001192
     
    14091401peerGotBytes( tr_peermsgs * msgs, uint32_t byteCount )
    14101402{
    1411     const time_t now = time( NULL );
    1412     tr_torrent * tor = msgs->torrent;
    1413     tor->activityDate = now;
    1414     tor->uploadedCur += byteCount;
    1415     msgs->info->pieceDataActivityDate = now;
     1403    msgs->info->pieceDataActivityDate = time( NULL );
    14161404    tr_rcTransferred( msgs->info->rcToPeer, byteCount );
    1417     tr_rcTransferred( tor->upload, byteCount );
    1418     tr_rcTransferred( tor->handle->upload, byteCount );
    1419     tr_statsAddUploaded( msgs->handle, byteCount );
    1420     firePieceData( msgs );
     1405    firePeerGotData( msgs, byteCount );
    14211406}
    14221407
     
    14421427    tr_torrent * tor = msgs->torrent;
    14431428    tor->downloadedCur -= MIN( tor->downloadedCur, byteCount );
    1444 }
    1445 
    1446 static void
    1447 reassignBytesToCorrupt( tr_peermsgs * msgs, uint32_t byteCount )
    1448 {
    1449     tr_torrent * tor = msgs->torrent;
    1450 
    1451     tor->corruptCur += byteCount;
    1452 
    1453     decrementDownloadedCount( msgs, byteCount );
    1454 }
    1455 
    1456 static void
    1457 gotBadPiece( tr_peermsgs * msgs, tr_piece_index_t pieceIndex )
    1458 {
    1459     const uint32_t byteCount =
    1460         tr_torPieceCountBytes( msgs->torrent, pieceIndex );
    1461     reassignBytesToCorrupt( msgs, byteCount );
    14621429}
    14631430
     
    15301497        return err;
    15311498
    1532     tr_cpBlockAdd( tor->completion, block );
    1533 
    15341499    addPeerToBlamefield( msgs, req->index );
    1535 
    15361500    fireGotBlock( msgs, req );
    1537 
    1538     /**
    1539     ***  Handle if this was the last block in the piece
    1540     **/
    1541 
    1542     if( tr_cpPieceIsComplete( tor->completion, req->index ) )
    1543     {
    1544         const tr_errno err = tr_ioTestPiece( tor, req->index );
    1545 
    1546         if( err )
    1547             tr_torerr( tor, _( "Piece %lu, which was just downloaded, failed its checksum test: %s" ),
    1548                        (unsigned long)req->index,
    1549                        tr_errorString( err ) );
    1550 
    1551         tr_torrentSetHasPiece( tor, req->index, !err );
    1552         tr_torrentSetPieceChecked( tor, req->index, TRUE );
    1553         tr_peerMgrSetBlame( tor->handle->peerMgr, tor->info.hash, req->index, !err );
    1554 
    1555         if( !err )
    1556             fireClientHave( msgs, req->index );
    1557         else
    1558             gotBadPiece( msgs, req->index );
    1559     }
    1560 
    15611501    return 0;
    15621502}
  • trunk/libtransmission/peer-msgs.h

    r5199 r6073  
    1515
    1616#include <inttypes.h>
     17#include "peer-common.h"
    1718#include "publish.h"
    1819
     
    4344
    4445
     46#if 0
    4547enum {
    4648    TR_ADDREQ_OK=0,
     
    5052    TR_ADDREQ_CLIENT_CHOKED
    5153};
     54#endif
    5255
    5356int          tr_peerMsgsAddRequest( tr_peermsgs * peer,
     
    6063**/
    6164
     65#if 0
    6266typedef enum
    6367{
     
    8286}
    8387tr_peermsgs_event;
     88#endif
    8489
    85 tr_publisher_tag  tr_peerMsgsSubscribe   ( tr_peermsgs       * peer,
    86                                            tr_delivery_func    func,
    87                                            void              * user );
    88 
    89 void              tr_peerMsgsUnsubscribe ( tr_peermsgs       * peer,
    90                                            tr_publisher_tag    tag );
     90void  tr_peerMsgsUnsubscribe ( tr_peermsgs       * peer,
     91                               tr_publisher_tag    tag );
    9192
    9293#endif
  • trunk/libtransmission/ptrarray.c

    r5389 r6073  
    5858
    5959    out = tr_new( tr_ptrArray, 1 );
    60     out->n_items = in->n_items;
    61     out->n_alloc = in->n_items;
    62     out->items = tr_new( void*, out->n_alloc );
    63     memcpy( out->items, in->items, out->n_items * sizeof(void*) );
     60    out->n_items = out->n_alloc = in->n_items;
     61    out->items = tr_memdup( in->items, out->n_items * sizeof(void*) );
    6462
    6563    return out;
     
    9694{
    9795    *size = t->n_items;
     96    return t->items;
     97}
     98
     99void**
     100tr_ptrArrayBase( tr_ptrArray * t )
     101{
    98102    return t->items;
    99103}
  • trunk/libtransmission/tracker.c

    r6049 r6073  
    697697{
    698698    struct tr_tracker_request * req = vreq;
    699     uint8_t * hash;
    700699    tr_tracker * t = findTracker( req->session, req->torrent_hash );
    701700
     
    721720    ++req->session->tracker->runningCount;
    722721
    723     hash = tr_new0( uint8_t, SHA_DIGEST_LENGTH );
    724     memcpy( hash, req->torrent_hash, SHA_DIGEST_LENGTH );
    725     tr_webRun( req->session, req->url, req->done_func, hash );
     722    tr_webRun( req->session, req->url, NULL, req->done_func,
     723               tr_memdup( req->torrent_hash, SHA_DIGEST_LENGTH ) );
    726724
    727725    freeRequest( req );
  • trunk/libtransmission/transmission.h

    r6049 r6073  
    10371037    int                  trackerCount;
    10381038
     1039    char              ** webseeds;
     1040    int                  webseedCount;
     1041
    10391042    /* Torrent info */
    10401043    char               * comment;
  • trunk/libtransmission/utils.c

    r6072 r6073  
    239239                newmsg->level = level;
    240240                newmsg->when = time( NULL );
    241                 newmsg->message = tr_strdup( (char*)EVBUFFER_DATA( buf ) );
     241                newmsg->message = tr_strdup( EVBUFFER_DATA( buf ) );
    242242                newmsg->file = file;
    243243                newmsg->line = line;
     
    598598   
    599599char*
    600 tr_strdup( const char * in )
    601 {
    602     return tr_strndup( in, in ? strlen(in) : 0 );
     600tr_strdup( const void * in )
     601{
     602    return tr_strndup( in, in ? strlen((const char*)in) : 0 );
    603603}
    604604
    605605char*
    606 tr_strndup( const char * in, int len )
     606tr_strndup( const void * in, int len )
    607607{
    608608    char * out = NULL;
  • trunk/libtransmission/utils.h

    r6072 r6073  
    189189void  tr_free    ( void* );
    190190
    191 char* tr_strdup( const char * str ) TR_GNUC_MALLOC;
    192 char* tr_strndup( const char * str, int len ) TR_GNUC_MALLOC;
     191char* tr_strdup( const void * str ) TR_GNUC_MALLOC;
     192char* tr_strndup( const void * str, int len ) TR_GNUC_MALLOC;
    193193void* tr_memdup( const void * src, int byteCount ) TR_GNUC_MALLOC;
    194194char* tr_strdup_printf( const char * fmt, ... )  TR_GNUC_PRINTF( 1, 2 ) TR_GNUC_MALLOC;
  • trunk/libtransmission/web.c

    r6052 r6073  
    4747    struct evbuffer * response;
    4848    char * url;
     49    char * range;
    4950    tr_session * session;
    5051    tr_web_done_func * done_func;
     
    8788            curl_easy_cleanup( easy );
    8889            evbuffer_free( task->response );
     90            tr_free( task->range );
    8991            tr_free( task->url );
    9092            tr_free( task );
     
    155157        curl_easy_setopt( ch, CURLOPT_MAXREDIRS, 5 );
    156158        curl_easy_setopt( ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
    157         curl_easy_setopt( ch, CURLOPT_ENCODING, "" );
     159        if( task->range )
     160            curl_easy_setopt( ch, CURLOPT_RANGE, task->range );
     161        else /* don't set encoding if range is sent; it messes up binary data */
     162            curl_easy_setopt( ch, CURLOPT_ENCODING, "" );
    158163        curl_multi_add_handle( web->cm, ch );
    159164    }
     
    163168tr_webRun( tr_session         * session,
    164169           const char         * url,
     170           const char         * range,
    165171           tr_web_done_func   * done_func,
    166172           void               * done_func_user_data )
     
    174180        task->session = session;
    175181        task->url = tr_strdup( url );
     182        task->range = tr_strdup( range );
    176183        task->done_func = done_func;
    177184        task->done_func_user_data = done_func_user_data;
  • trunk/libtransmission/web.h

    r5714 r6073  
    1717typedef struct tr_web tr_web;
    1818
    19 tr_web* tr_webInit( tr_handle * session );
     19tr_web* tr_webInit( struct tr_handle * session );
    2020
    2121void tr_webClose( tr_web ** );
    2222
    23 typedef void (tr_web_done_func)( tr_handle    * session,
    24                                   long          response_code,
    25                                   const void  * response,
    26                                   size_t        response_byte_count,
    27                                   void        * user_data );
     23typedef void (tr_web_done_func)( struct tr_handle    * session,
     24                                 long                  response_code,
     25                                 const void          * response,
     26                                 size_t                response_byte_count,
     27                                 void                * user_data );
    2828
    2929const char * tr_webGetResponseStr( long response_code );
    3030                               
    31 void tr_webRun( tr_handle          * session,
     31void tr_webRun( struct tr_handle   * session,
    3232                const char         * url,
     33                const char         * range,
    3334                tr_web_done_func     done_func,
    3435                void               * done_func_user_data );
Note: See TracChangeset for help on using the changeset viewer.