Changeset 8204


Ignore:
Timestamp:
Apr 10, 2009, 5:34:25 PM (13 years ago)
Author:
charles
Message:

(1.5x libT) various backports for 1.52:
(1) recognize Aria2 as a client
(2) remove jhujhiti's tr_suspectAddress(), since he removed it from trunka
(3) on Mac, better detection of where the Web UI files are located
(4) reintroduce the web task queue
(5) various minor formatting changes to reduce the diffs between 1.52 and trunk

Location:
branches/1.5x/libtransmission
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • branches/1.5x/libtransmission/bandwidth.h

    r7664 r8204  
    168168 */
    169169static TR_INLINE void tr_bandwidthSetLimited( tr_bandwidth        * bandwidth,
    170                                            tr_direction          dir,
    171                                            tr_bool               isLimited )
     170                                              tr_direction          dir,
     171                                              tr_bool               isLimited )
    172172{
    173173    bandwidth->band[dir].isLimited = isLimited;
     
    178178 */
    179179static TR_INLINE tr_bool tr_bandwidthIsLimited( const tr_bandwidth  * bandwidth,
    180                                              tr_direction          dir )
     180                                                tr_direction          dir )
    181181{
    182182    return bandwidth->band[dir].isLimited;
     
    234234 */
    235235static TR_INLINE void tr_bandwidthHonorParentLimits ( tr_bandwidth        * bandwidth,
    236                                                    tr_direction          direction,
    237                                                    tr_bool               isEnabled )
     236                                                      tr_direction          direction,
     237                                                      tr_bool               isEnabled )
    238238{
    239239    assert( tr_isBandwidth( bandwidth ) );
  • branches/1.5x/libtransmission/clients.c

    r7664 r8204  
    325325    else if( !memcmp( id, "346-", 4 ) )      no_version( buf, buflen, "TorrentTopia" );
    326326    else if( !memcmp( id, "eX", 2 ) )        no_version( buf, buflen, "eXeem" );
     327    else if( !memcmp( id, "-aria2-", 7 ) )   no_version( buf, buflen, "aria2" );
    327328    else if( !memcmp( id, "-FG", 3 ) )       two_major_two_minor( buf, buflen, "FlashGet", id+3 );
    328329   
  • branches/1.5x/libtransmission/json.h

    r7664 r8204  
    1313#ifndef TR_JSON_H
    1414
     15#ifdef __cplusplus
     16extern "C" {
     17#endif
     18
    1519int tr_jsonParse( const void *     vbuf,
    1620                  size_t           len,
     
    1822                  const uint8_t ** setme_end );
    1923
     24#ifdef __cplusplus
     25}
    2026#endif
     27
     28#endif
  • branches/1.5x/libtransmission/makemeta.h

    r7664 r8204  
    1313#ifndef TR_MAKEMETA_H
    1414#define TR_MAKEMETA_H 1
     15
     16#ifdef __cplusplus
     17extern "C" {
     18#endif
    1519
    1620typedef struct tr_metainfo_builder_file
     
    118122
    119123
     124#ifdef __cplusplus
     125}
    120126#endif
     127
     128#endif
  • branches/1.5x/libtransmission/net.c

    r7852 r8204  
    128128}
    129129
    130 void
    131 tr_suspectAddress( const tr_address * a UNUSED, const char * source UNUSED )
    132 {
    133 /* this is overkill for a production environment,
    134  * but useful in the nightly builds, so only compile it into the nightlies */
    135 #ifdef TR_UNSTABLE
    136     /* be really aggressive in what we report */
    137     if( a->type == TR_AF_INET && !( ntohl( a->addr.addr4.s_addr ) & 0xff000000 ) )
    138         tr_err(  "Funny looking address %s from %s", tr_ntop_non_ts( a ), source );
    139     /* /16s taken from ipv6 rib on 21 dec, 2008 */
    140     /* this is really, really ugly. expedience over quality */
    141     if( a->type == TR_AF_INET6 )
    142     {
    143         uint16_t slash16;
    144         uint16_t valid[] = { 0x339, 0x2002, 0x2003, 0x2400, 0x2401, 0x2402,
    145             0x2403, 0x2404, 0x2405, 0x2406, 0x2407, 0x2600, 0x2607, 0x2610,
    146             0x2620, 0x2800, 0x2801, 0x2a00, 0x2a01, 0x0a02, 0x2001, 0x0000 };
    147         uint16_t *p;
    148         tr_bool good = FALSE;
    149         p = valid;
    150         memcpy( &slash16, &a->addr, 2 );
    151         slash16 = ntohs( slash16 );
    152         while( *p )
    153         {
    154             if( slash16 == *p )
    155                 good = TRUE;
    156             p++;
    157         }
    158         if( !good && !IN6_IS_ADDR_V4MAPPED( &a->addr.addr6 ) )
    159             tr_err(  "Funny looking address %s from %s", tr_ntop_non_ts( a ), source );
    160     }
    161 #endif
    162 }
    163 
    164130const char *
    165131tr_ntop( const tr_address * src, char * dst, int size )
     
    205171}
    206172
    207 void
    208 tr_normalizeV4Mapped( tr_address * const addr )
    209 {
    210     assert( tr_isAddress( addr ) );
    211 
    212     if( addr->type == TR_AF_INET6 && IN6_IS_ADDR_V4MAPPED( &addr->addr.addr6 ) )
    213     {
    214         addr->type = TR_AF_INET;
    215         memcpy( &addr->addr.addr4.s_addr, addr->addr.addr6.s6_addr + 12, 4 );
    216     }
    217 }
    218 
    219173/*
    220174 * Compare two tr_address structures.
     
    464418
    465419static TR_INLINE tr_bool
     420isIPv4MappedOrCompatAddress( const tr_address * addr )
     421{
     422    if( addr->type == TR_AF_INET6 )
     423    {
     424        if( IN6_IS_ADDR_V4MAPPED( &addr->addr.addr6 ) ||
     425            IN6_IS_ADDR_V4COMPAT( &addr->addr.addr6 ) )
     426            return TRUE;
     427    }
     428    return FALSE;
     429}
     430
     431static TR_INLINE tr_bool
    466432isIPv6LinkLocalAddress( const tr_address * addr )
    467433{
    468434    if( addr->type == TR_AF_INET6 &&
    469             IN6_IS_ADDR_LINKLOCAL( &addr->addr.addr6 ))
     435        IN6_IS_ADDR_LINKLOCAL( &addr->addr.addr6 ) )
    470436        return TRUE;
    471437    return FALSE;
     
    475441tr_isValidPeerAddress( const tr_address * addr, tr_port port )
    476442{
    477     if( isMulticastAddress( addr ) || isIPv6LinkLocalAddress( addr ) )
     443    if( isMulticastAddress( addr ) || isIPv6LinkLocalAddress( addr ) ||
     444        isIPv4MappedOrCompatAddress( addr ) )
    478445        return FALSE;
    479446
     
    496463    assert( tr_isAddress( addr ) );
    497464
    498     if( isMulticastAddress( addr ) || isIPv6LinkLocalAddress( addr ))
     465    if( isMulticastAddress( addr ) || isIPv6LinkLocalAddress( addr ) )
    499466        return -EINVAL;
    500467
  • branches/1.5x/libtransmission/net.h

    r7847 r8204  
    8787int tr_compareAddresses( const tr_address * a,
    8888                         const tr_address * b);
    89 void tr_normalizeV4Mapped( tr_address * const addr );
    9089
    9190tr_bool tr_isValidPeerAddress( const tr_address * addr, tr_port port );
    92 
    93 void tr_suspectAddress( const tr_address * a, const char * source );
    9491
    9592static TR_INLINE tr_bool tr_isAddress( const tr_address * a ) { return ( a != NULL ) && ( a->type==TR_AF_INET || a->type==TR_AF_INET6 ); }
  • branches/1.5x/libtransmission/peer-mgr.c

    r7949 r8204  
    14561456    for( i = 0 ; i < n ; i++ ) {
    14571457        memcpy( &pex[i].addr, walk, sizeof( tr_address ) );
    1458         tr_suspectAddress( &pex[i].addr, "tracker"  );
    14591458        memcpy( &pex[i].port, walk + sizeof( tr_address ), 2 );
    14601459        pex[i].flags = 0x00;
     
    18301829        const struct peer_atom * atom = getExistingAtom( t, &peer->addr );
    18311830        tr_peer_stat *           stat = ret + i;
    1832         tr_address               norm_addr;
    1833 
    1834         norm_addr = peer->addr;
    1835         tr_normalizeV4Mapped( &norm_addr );
    1836         tr_ntop( &norm_addr, stat->addr, sizeof( stat->addr ) );
     1831
     1832        tr_ntop( &peer->addr, stat->addr, sizeof( stat->addr ) );
    18371833        tr_strlcpy( stat->client, ( peer->client ? peer->client : "" ),
    18381834                   sizeof( stat->client ) );
  • branches/1.5x/libtransmission/peer-msgs.c

    r7771 r8204  
    588588**/
    589589
    590 static int
     590static tr_bool
    591591isPieceInteresting( const tr_peermsgs * msgs,
    592592                    tr_piece_index_t    piece )
     
    600600
    601601/* "interested" means we'll ask for piece data if they unchoke us */
    602 static int
     602static tr_bool
    603603isPeerInteresting( const tr_peermsgs * msgs )
    604604{
     
    658658}
    659659
    660 static int
     660static tr_bool
    661661popNextRequest( tr_peermsgs *         msgs,
    662662                struct peer_request * setme )
     
    719719**/
    720720
    721 static int
     721static tr_bool
    722722reqIsValid( const tr_peermsgs * peer,
    723723            uint32_t            index,
     
    728728}
    729729
    730 static int
     730static tr_bool
    731731requestIsValid( const tr_peermsgs * msgs, const struct peer_request * req )
    732732{
     
    825825}
    826826
    827 static TR_INLINE int
     827static TR_INLINE tr_bool
    828828requestQueueIsFull( const tr_peermsgs * msgs )
    829829{
     
    842842    assert( msgs );
    843843    assert( msgs->torrent );
    844     assert( reqIsValid( msgs, index, offset, length ) );
    845844
    846845    /**
     
    854853    }
    855854
    856     /* peer doesn't have this piece */
    857     if( !tr_bitfieldHas( msgs->peer->have, index ) )
    858         return TR_ADDREQ_MISSING;
    859 
    860855    /* peer's queue is full */
    861856    if( requestQueueIsFull( msgs ) ) {
     
    863858        return TR_ADDREQ_FULL;
    864859    }
     860
     861    /* peer doesn't have this piece */
     862    if( !tr_bitfieldHas( msgs->peer->have, index ) )
     863        return TR_ADDREQ_MISSING;
    865864
    866865    /* have we already asked for this piece? */
     
    12241223}
    12251224
    1226 static int
     1225static tr_bool
    12271226messageLengthIsCorrect( const tr_peermsgs * msg, uint8_t id, uint32_t len )
    12281227{
     
    15971596    tr_peermsgs * msgs = vmsgs;
    15981597    firePeerGotData( msgs, bytesWritten, wasPieceData );
    1599     peerPulse( msgs );
     1598
     1599    if ( tr_isPeerIo( io ) && io->userData )
     1600        peerPulse( msgs );
    16001601}
    16011602
     
    19871988            for( i = 0; i < diffs.addedCount; ++i )
    19881989            {
    1989                 tr_suspectAddress( &diffs.added[i].addr, "pex" );
    19901990                memcpy( walk, &diffs.added[i].addr.addr, 4 ); walk += 4;
    19911991                memcpy( walk, &diffs.added[i].port, 2 ); walk += 2;
     
    20182018            for( i = 0; i < diffs6.addedCount; ++i )
    20192019            {
    2020                 tr_suspectAddress( &diffs6.added[i].addr, "pex6" );
    20212020                memcpy( walk, &diffs6.added[i].addr.addr.addr6.s6_addr, 16 );
    20222021                walk += 16;
  • branches/1.5x/libtransmission/platform.c

    r8162 r8204  
    530530        {
    531531
    532 #ifdef SYS_DARWIN
     532#ifdef SYS_DARWIN /* on Mac, look in the app package first, then the Application Support folder (for daemon, etc) */
    533533
    534534            CFURLRef appURL = CFBundleCopyBundleURL( CFBundleGetMainBundle( ) );
     
    541541
    542542            s = tr_buildPath( appString, "Contents", "Resources", "web", NULL );
     543           
     544            if( !isClutchDir( s ) ) {
     545                tr_free( s );
     546               
     547                /* Fallback to the Application Support folder */
     548                s = tr_buildPath( tr_sessionGetConfigDir( session ), "web", NULL );
     549                if( !isClutchDir( s ) ) {
     550                    tr_free( s );
     551                    s = NULL;
     552                }
     553            }
    543554
    544555#elif defined( WIN32 )
  • branches/1.5x/libtransmission/rpc-server.c

    r8200 r8204  
    314314        if( errno )
    315315        {
    316             send_simple_response( req, HTTP_NOTFOUND, NULL );
     316            send_simple_response( req, HTTP_NOTFOUND, filename );
    317317        }
    318318        else
     
    516516        else
    517517        {
    518             send_simple_response( req, HTTP_NOTFOUND, NULL );
     518            send_simple_response( req, HTTP_NOTFOUND, req->uri );
    519519        }
    520520
  • branches/1.5x/libtransmission/rpcimpl.h

    r7767 r8204  
    1313#ifndef TR_RPC_H
    1414#define TR_RPC_H
     15
     16#ifdef __cplusplus
     17extern "C" {
     18#endif
    1519
    1620/***
     
    4246                            int              list_str_len );
    4347
     48#ifdef __cplusplus
     49}
     50#endif
    4451
    45 #endif
     52#endif /* TR_RPC_H */
  • branches/1.5x/libtransmission/torrent.c

    r7855 r8204  
    5959    tr_torrent * tor = NULL;
    6060
    61     while( ( tor = tr_torrentNext( session, tor ) ) )
     61    while(( tor = tr_torrentNext( session, tor )))
    6262        if( tor->uniqueId == id )
    6363            return tor;
     
    7171    tr_torrent * tor = NULL;
    7272
    73     while( ( tor = tr_torrentNext( session, tor ) ) )
    74         if( !strcmp( str, tor->info.hashString ) )
     73    while(( tor = tr_torrentNext( session, tor )))
     74        if( !strcmp( str, tor->info.hashString ))
    7575            return tor;
    7676
     
    8383    tr_torrent * tor = NULL;
    8484
    85     while( ( tor = tr_torrentNext( session, tor ) ) )
     85    while(( tor = tr_torrentNext( session, tor )))
    8686        if( *tor->info.hash == *torrentHash )
    8787            if( !memcmp( tor->info.hash, torrentHash, SHA_DIGEST_LENGTH ) )
     
    9797    tr_torrent * tor = NULL;
    9898
    99     while( ( tor = tr_torrentNext( session, tor ) ) )
     99    while(( tor = tr_torrentNext( session, tor )))
    100100        if( !memcmp( tor->obfuscatedHash, obfuscatedTorrentHash,
    101101                     SHA_DIGEST_LENGTH ) )
     
    114114                        tr_speedlimit mode )
    115115{
    116     assert( tor != NULL );
     116    assert( tr_isTorrent( tor ) );
    117117    assert( tr_isDirection( dir ) );
    118118    assert( mode==TR_SPEEDLIMIT_GLOBAL || mode==TR_SPEEDLIMIT_SINGLE || mode==TR_SPEEDLIMIT_UNLIMITED  );
     
    128128                        tr_direction       dir )
    129129{
    130     assert( tor != NULL );
     130    assert( tr_isTorrent( tor ) );
    131131    assert( tr_isDirection( dir ) );
    132132
     
    10711071    tr_globalLock( tor->session );
    10721072
    1073     tor->isRunning = 1;
     1073    tor->isRunning = TRUE;
    10741074    *tor->errorString = '\0';
    10751075    tr_torrentResetTransferStats( tor );
     
    14401440
    14411441static void
    1442 setFileDND( tr_torrent *    tor,
    1443             tr_file_index_t fileIndex,
    1444             int             doDownload )
     1442setFileDND( tr_torrent * tor, tr_file_index_t fileIndex, int doDownload )
    14451443{
    14461444    tr_file *        file;
     
    14971495
    14981496void
    1499 tr_torrentInitFileDLs( tr_torrent *      tor,
     1497tr_torrentInitFileDLs( tr_torrent      * tor,
    15001498                       tr_file_index_t * files,
    15011499                       tr_file_index_t   fileCount,
     
    15081506    tr_torrentLock( tor );
    15091507
    1510     for( i = 0; i < fileCount; ++i )
     1508    for( i=0; i<fileCount; ++i )
    15111509        setFileDND( tor, files[i], doDownload );
    15121510    tr_cpInvalidateDND ( &tor->completion );
     
    16441642
    16451643    if( isChecked )
    1646         tr_bitfieldAddRange ( &tor->checkedPieces, begin, end );
     1644        tr_bitfieldAddRange( &tor->checkedPieces, begin, end );
    16471645    else
    1648         tr_bitfieldRemRange ( &tor->checkedPieces, begin, end );
     1646        tr_bitfieldRemRange( &tor->checkedPieces, begin, end );
    16491647}
    16501648
     
    17771775**/
    17781776
    1779 /** @deprecated this method will be removed in 1.40 */
    17801777void
    17811778tr_torrentSetAddedDate( tr_torrent * tor,
     
    17871784}
    17881785
    1789 /** @deprecated this method will be removed in 1.40 */
    17901786void
    17911787tr_torrentSetActivityDate( tr_torrent * tor,
     
    17971793}
    17981794
    1799 /** @deprecated this method will be removed in 1.40 */
    18001795void
    18011796tr_torrentSetDoneDate( tr_torrent * tor,
  • branches/1.5x/libtransmission/tr-getopt.c

    r7813 r8204  
    217217    return o->val;
    218218}
    219 
  • branches/1.5x/libtransmission/tr-getopt.h

    r7813 r8204  
    2626#define TR_GETOPT_H
    2727
     28#ifdef __cplusplus
     29extern "C" {
     30#endif
     31
    2832extern int tr_optind;
    2933
    3034typedef struct tr_option
    3135{
    32     int     val;          /* the value to return from tr_getopt() */
     36    int           val;          /* the value to return from tr_getopt() */
    3337    const char *  longName;     /* --long-form */
    3438    const char *  description;  /* option's description for tr_getopt_usage() */
    3539    const char *  shortName;    /* short form */
    36     int     has_arg;      /* 0 for no argument, 1 for argument */
     40    int           has_arg;      /* 0 for no argument, 1 for argument */
    3741    const char *  argName;      /* argument's description for tr_getopt_usage() */
    3842}
     
    6670                      const tr_option * opts );
    6771
     72#ifdef __cplusplus
     73} /* extern "C" */
     74#endif
     75
    6876#endif /* TR_GETOPT_H */
  • branches/1.5x/libtransmission/tracker.c

    r7897 r8204  
    260260        memcpy( &addr.addr.addr4, compactWalk, 4 );
    261261        memcpy( &port, compactWalk + 4, 2 );
    262         tr_suspectAddress( &addr, "compact" );
    263262       
    264263        memcpy( walk, &addr, sizeof( addr ) );
     
    293292        memcpy( &port, compactWalk + 16, 2 );
    294293        compactWalk += 18;
    295         tr_suspectAddress( &addr, "compact6" );
    296294       
    297295        memcpy( walk, &addr, sizeof( addr ) );
     
    347345    const int peerCount = bePeers->val.l.count;
    348346
    349     assert( bePeers->type == TYPE_LIST );
     347    assert( tr_bencIsList( bePeers ) );
    350348
    351349    array = tr_new( uint8_t, peerCount * ( sizeof( tr_address ) + 2 ) );
     
    369367
    370368        memcpy( walk, &addr, sizeof( tr_address ) );
    371         tr_suspectAddress( &addr, "old tracker" );
    372369        port = htons( itmp );
    373370        memcpy( walk + sizeof( tr_address ), &port, 2 );
     
    485482                const int allAreSeeds = incomplete == 0;
    486483
    487                 if( tmp->type == TYPE_STR ) /* "compact" extension */
     484                if( tr_bencIsString( tmp ) ) /* "compact" extension */
    488485                {
    489486                    publishNewPeersCompact( t, allAreSeeds, tmp->val.s.s,
    490487                                            tmp->val.s.i );
    491488                }
    492                 else if( tmp->type == TYPE_LIST ) /* original protocol */
     489                else if( tr_bencIsList( tmp ) ) /* original protocol */
    493490                {
    494491                    size_t    byteCount = 0;
     
    503500                const int allAreSeeds = incomplete == 0;
    504501               
    505                 if( tmp->type == TYPE_STR ) /* "compact" extension */
     502                if( tr_bencIsString( tmp ) ) /* "compact" extension */
    506503                {
    507504                    publishNewPeersCompact6( t, allAreSeeds, tmp->val.s.s,
  • branches/1.5x/libtransmission/web.c

    r7906 r8204  
    7373    tr_session * session;
    7474    struct event timer_event;
     75    tr_list * easy_queue;
    7576    tr_list * fds;
    7677};
     
    215216            curl_easy_setopt( easy, CURLOPT_ENCODING, "" );
    216217
    217         {
     218        if( web->still_running >= MAX_CONCURRENT_TASKS ) {
     219            tr_list_append( &web->easy_queue, easy );
     220            dbgmsg( ">> enqueueing a task... size is now %d", tr_list_size( web->easy_queue ) );
     221        } else {
    218222            const CURLMcode mcode = curl_multi_add_handle( web->multi, easy );
    219223            tr_assert( mcode == CURLM_OK, "curl_multi_add_handle() failed: %d (%s)", mcode, curl_multi_strerror( mcode ) );
     
    323327    tr_timevalMsec( g->timer_ms, &interval );
    324328    evtimer_add( &g->timer_event, &interval );
     329}
     330
     331static void
     332add_tasks_from_queue( tr_web * g )
     333{
     334    while( ( g->still_running < MAX_CONCURRENT_TASKS )
     335        && ( tr_list_size( g->easy_queue ) > 0 ) )
     336    {
     337        CURL * easy = tr_list_pop_front( &g->easy_queue );
     338        if( easy )
     339        {
     340            const CURLMcode rc = curl_multi_add_handle( g->multi, easy );
     341            if( rc != CURLM_OK )
     342                tr_err( "%s", curl_multi_strerror( rc ) );
     343            else {
     344                dbgmsg( "pumped the task queue, %d remain",
     345                        tr_list_size( g->easy_queue ) );
     346                ++g->still_running;
     347            }
     348        }
     349    }
    325350}
    326351
     
    372397
    373398    remove_finished_tasks( g );
     399
     400    add_tasks_from_queue( g );
    374401
    375402    if( !g->still_running ) {
Note: See TracChangeset for help on using the changeset viewer.