Changeset 162 for trunk/libtransmission


Ignore:
Timestamp:
Mar 23, 2006, 12:39:39 PM (16 years ago)
Author:
titer
Message:

Merge from branches/new_api:r161

Location:
trunk/libtransmission
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/choking.c

    r109 r162  
    139139void tr_chokingPulse( tr_choking_t * c )
    140140{
    141     int i, peersTotalCount, unchoked, mustOptimistic = 1;
     141    int peersTotalCount, unchoked, mustOptimistic = 1;
    142142    tr_peer_t ** canChoke, ** canUnchoke;
    143143    tr_peer_t ** canChokeZero, ** canUnchokeZero;
     
    153153    /* Lock all torrents and get the total number of peers */
    154154    peersTotalCount = 0;
    155     for( i = 0; i < c->h->torrentCount; i++ )
    156     {
    157         tor = c->h->torrents[i];
     155    for( tor = c->h->torrentList; tor; tor = tor->next )
     156    {
    158157        tr_lockLock( &tor->lock );
    159158        peersTotalCount += tor->peerCount;
     
    166165    unchoked        = 0;
    167166
    168     for( i = 0; i < c->h->torrentCount; i++ )
     167    for( tor = c->h->torrentList; tor; tor = tor->next )
    169168    {
    170169        tr_peer_t * peer;
    171         int j;
    172 
    173         tor = c->h->torrents[i];
    174         for( j = 0; j < tor->peerCount; j++ )
     170        int i;
     171
     172        for( i = 0; i < tor->peerCount; i++ )
    175173        {
    176             peer = tor->peers[j];
     174            peer = tor->peers[i];
    177175
    178176            if( !tr_peerIsConnected( peer ) )
     
    321319
    322320    /* Unlock all torrents */
    323     for( i = 0; i < c->h->torrentCount; i++ )
    324     {
    325         tr_lockUnlock( &c->h->torrents[i]->lock );
     321    for( tor = c->h->torrentList; tor; tor = tor->next )
     322    {
     323        tr_lockUnlock( &tor->lock );
    326324    }
    327325
  • trunk/libtransmission/internal.h

    r65 r162  
    11/******************************************************************************
    2  * Copyright (c) 2005 Eric Petit
     2 * Copyright (c) 2005-2006 Transmission authors and contributors
    33 *
    44 * Permission is hereby granted, free of charge, to any person obtaining a
     
    8383#define TR_MAX_PEER_COUNT 60
    8484
    85 typedef struct tr_torrent_s tr_torrent_t;
    8685typedef struct tr_completion_s tr_completion_t;
    8786
     
    109108
    110109    int               status;
    111         int                               finished;
    112     char              error[128];
     110    int               error;
     111    char              trackerError[128];
     112    int               finished;
    113113
    114114    char            * id;
    115115    char            * key;
     116    int             * bindPort;
    116117
    117118    /* An escaped string used to include the hash in HTTP queries */
     
    127128    int               blockCount;
    128129   
    129 #if 0
    130     /* Status for each block
    131        -1 = we have it
    132         n = we are downloading it from n peers */
    133     char            * blockHave;
    134     int               blockHaveCount;
    135     uint8_t         * bitfield;
    136 #endif
    137130    tr_completion_t * completion;
    138131
     
    151144    uint64_t          downloaded;
    152145    uint64_t          uploaded;
     146
     147    tr_stat_t         stats[2];
     148    int               statCur;
     149
     150    tr_torrent_t    * prev;
     151    tr_torrent_t    * next;
    153152};
    154153
     
    159158{
    160159    int            torrentCount;
    161     tr_torrent_t * torrents[TR_MAX_TORRENT_COUNT];
     160    tr_torrent_t * torrentList;
    162161
    163162    tr_ratecontrol_t * upload;
  • trunk/libtransmission/tracker.c

    r61 r162  
    5858static void recvAnswer ( tr_tracker_t * tc );
    5959
    60 tr_tracker_t * tr_trackerInit( tr_handle_t * h, tr_torrent_t * tor )
     60tr_tracker_t * tr_trackerInit( tr_torrent_t * tor )
    6161{
    6262    tr_tracker_t * tc;
     
    6464    tc           = calloc( 1, sizeof( tr_tracker_t ) );
    6565    tc->tor      = tor;
    66     tc->id       = h->id;
     66    tc->id       = tor->id;
    6767
    6868    tc->started  = 1;
     
    7575    tc->buf      = malloc( tc->size );
    7676
    77     tc->bindPort = h->bindPort;
     77    tc->bindPort = *(tor->bindPort);
    7878    tc->newPort  = -1;
    7979
     
    375375    {
    376376        tr_err( "Tracker: %s", bePeers->val.s.s );
    377         tor->status |= TR_TRACKER_ERROR;
    378         snprintf( tor->error, sizeof( tor->error ),
     377        tor->error |= TR_ETRACKER;
     378        snprintf( tor->trackerError, sizeof( tor->trackerError ),
    379379                  "%s", bePeers->val.s.s );
    380380        goto cleanup;
    381381    }
    382 
    383     tor->status &= ~TR_TRACKER_ERROR;
     382    tor->error &= ~TR_ETRACKER;
    384383
    385384    if( !tc->interval )
  • trunk/libtransmission/tracker.h

    r26 r162  
    2626typedef struct tr_tracker_s tr_tracker_t;
    2727
    28 tr_tracker_t * tr_trackerInit      ( tr_handle_t *, tr_torrent_t * );
     28tr_tracker_t * tr_trackerInit      ( tr_torrent_t * );
    2929void           tr_trackerChangePort( tr_tracker_t *, int );
    3030int            tr_trackerPulse     ( tr_tracker_t * );
  • trunk/libtransmission/transmission.c

    r133 r162  
    11/******************************************************************************
    2  * Copyright (c) 2005 Eric Petit
     2 * Copyright (c) 2005-2006 Transmission authors and contributors
    33 *
    44 * Permission is hereby granted, free of charge, to any person obtaining a
     
    2626 * Local prototypes
    2727 **********************************************************************/
    28 static void torrentReallyStop( tr_handle_t * h, int t );
     28static void torrentReallyStop( tr_torrent_t * );
    2929static void  downloadLoop( void * );
    3030static void  acceptLoop( void * );
     
    8686void tr_setBindPort( tr_handle_t * h, int port )
    8787{
    88     int ii, sock;
     88    int sock;
     89    tr_torrent_t * tor;
    8990
    9091    if( h->bindPort == port )
     
    107108    h->bindPort = port;
    108109
    109     for( ii = 0; ii < h->torrentCount; ii++ )
    110     {
    111         tr_lockLock( &h->torrents[ii]->lock );
    112         if( NULL != h->torrents[ii]->tracker )
    113         {
    114             tr_trackerChangePort( h->torrents[ii]->tracker, port );
    115         }
    116         tr_lockUnlock( &h->torrents[ii]->lock );
     110    for( tor = h->torrentList; tor; tor = tor->next )
     111    {
     112        tr_lockLock( &tor->lock );
     113        if( NULL != tor->tracker )
     114        {
     115            tr_trackerChangePort( tor->tracker, port );
     116        }
     117        tr_lockUnlock( &tor->lock );
    117118    }
    118119
     
    147148{
    148149    tr_torrent_t * tor;
    149     int i;
    150150
    151151    *dl = 0.0;
    152152    *ul = 0.0;
    153     for( i = 0; i < h->torrentCount; i++ )
    154     {
    155         tor = h->torrents[i];
     153    for( tor = h->torrentList; tor; tor = tor->next )
     154    {
    156155        tr_lockLock( &tor->lock );
    157156        if( tor->status & TR_STATUS_DOWNLOAD )
     
    168167 * to fill it.
    169168 **********************************************************************/
    170 int tr_torrentInit( tr_handle_t * h, const char * path )
    171 {
    172     tr_torrent_t  * tor;
     169tr_torrent_t * tr_torrentInit( tr_handle_t * h, const char * path,
     170                               int * error )
     171{
     172    tr_torrent_t  * tor, * tor_tmp;
    173173    tr_info_t     * inf;
    174174    int             i;
    175175    char          * s1, * s2;
    176176
    177     if( h->torrentCount >= TR_MAX_TORRENT_COUNT )
    178     {
    179         tr_err( "Maximum number of torrents reached" );
    180         return 1;
    181     }
    182 
    183177    tor = calloc( sizeof( tr_torrent_t ), 1 );
    184178    inf = &tor->info;
     
    187181    if( tr_metainfoParse( inf, path ) )
    188182    {
     183        *error = TR_EINVALID;
    189184        free( tor );
    190         return 1;
     185        return NULL;
    191186    }
    192187
    193188    /* Make sure this torrent is not already open */
    194     for( i = 0; i < h->torrentCount; i++ )
    195     {
    196         if( !memcmp( tor->info.hash, h->torrents[i]->info.hash,
     189    for( tor_tmp = h->torrentList; tor_tmp; tor_tmp = tor_tmp->next )
     190    {
     191        if( !memcmp( tor->info.hash, tor_tmp->info.hash,
    197192                     SHA_DIGEST_LENGTH ) )
    198193        {
    199             tr_err( "Torrent already open" );
     194            *error = TR_EDUPLICATE;
    200195            free( tor );
    201             return 1;
     196            return NULL;
    202197        }
    203198    }
     
    206201    tor->id     = h->id;
    207202    tor->key    = h->key;
     203    tor->bindPort = &h->bindPort;
    208204        tor->finished = 0;
    209205
     
    247243    /* We have a new torrent */
    248244    tr_lockLock( &h->acceptLock );
    249     h->torrents[h->torrentCount] = tor;
     245    tor->prev = NULL;
     246    tor->next = h->torrentList;
     247    if( tor->next )
     248    {
     249        tor->next->prev = tor;
     250    }
     251    h->torrentList = tor;
    250252    (h->torrentCount)++;
    251253    tr_lockUnlock( &h->acceptLock );
    252254
    253     return 0;
     255    return tor;
     256}
     257
     258tr_info_t * tr_torrentInfo( tr_torrent_t * tor )
     259{
     260    return &tor->info;
    254261}
    255262
    256263/***********************************************************************
    257264 * tr_torrentScrape
    258  ***********************************************************************
    259  * Allocates a tr_torrent_t structure, then relies on tr_metainfoParse
    260  * to fill it.
    261  **********************************************************************/
    262 int tr_torrentScrape( tr_handle_t * h, int t, int * s, int * l )
    263 {
    264     return tr_trackerScrape( h->torrents[t], s, l );
    265 }
    266 
    267 void tr_torrentSetFolder( tr_handle_t * h, int t, const char * path )
    268 {
    269     tr_torrent_t * tor = h->torrents[t];
    270 
     265 **********************************************************************/
     266int tr_torrentScrape( tr_torrent_t * tor, int * s, int * l )
     267{
     268    return tr_trackerScrape( tor, s, l );
     269}
     270
     271void tr_torrentSetFolder( tr_torrent_t * tor, const char * path )
     272{
    271273    tor->destination = strdup( path );
    272274}
    273275
    274 char * tr_torrentGetFolder( tr_handle_t * h, int t )
    275 {
    276     tr_torrent_t * tor = h->torrents[t];
    277 
     276char * tr_torrentGetFolder( tr_torrent_t * tor )
     277{
    278278    return tor->destination;
    279279}
    280280
    281 void tr_torrentStart( tr_handle_t * h, int t )
    282 {
    283     tr_torrent_t * tor = h->torrents[t];
    284 
     281void tr_torrentStart( tr_torrent_t * tor )
     282{
    285283    if( tor->status & ( TR_STATUS_STOPPING | TR_STATUS_STOPPED ) )
    286284    {
    287285        /* Join the thread first */
    288         torrentReallyStop( h, t );
    289     }
    290 
    291     tor->status   = TR_STATUS_CHECK;
    292     tor->tracker  = tr_trackerInit( h, tor );
    293 
    294     if( 0 > h->bindPort )
    295     {
    296         tr_setBindPort( h, TR_DEFAULT_PORT );
    297     }
     286        torrentReallyStop( tor );
     287    }
     288
     289    tor->status  = TR_STATUS_CHECK;
     290    tor->tracker = tr_trackerInit( tor );
    298291
    299292    tor->date = tr_date();
     
    302295}
    303296
    304 void tr_torrentStop( tr_handle_t * h, int t )
    305 {
    306     tr_torrent_t * tor = h->torrents[t];
    307 
     297void tr_torrentStop( tr_torrent_t * tor )
     298{
    308299    tr_lockLock( &tor->lock );
    309300    tr_trackerStopped( tor->tracker );
     
    320311 * Joins the download thread and frees/closes everything related to it.
    321312 **********************************************************************/
    322 static void torrentReallyStop( tr_handle_t * h, int t )
    323 {
    324     tr_torrent_t * tor = h->torrents[t];
    325 
     313static void torrentReallyStop( tr_torrent_t * tor )
     314{
    326315    tor->die = 1;
    327316    tr_threadJoin( &tor->thread );
     
    346335}
    347336
    348 int tr_getFinished( tr_handle_t * h, int i)
    349 {
    350         return h->torrents[i]->finished;
    351 }
    352 void tr_setFinished( tr_handle_t * h, int i, int val)
    353 {
    354         h->torrents[i]->finished = val;
    355 }
    356 
    357 int tr_torrentStat( tr_handle_t * h, tr_stat_t ** stat )
     337void tr_torrentIterate( tr_handle_t * h, tr_callback_t func, void * d )
     338{
     339    tr_torrent_t * tor;
     340
     341    for( tor = h->torrentList; tor; tor = tor->next )
     342    {
     343        func( tor, d );
     344    }
     345}
     346
     347int tr_getFinished( tr_torrent_t * tor )
     348{
     349    if( tor->finished )
     350    {
     351        tor->finished = 0;
     352        return 1;
     353    }
     354    return 0;
     355}
     356
     357tr_stat_t * tr_torrentStat( tr_torrent_t * tor )
    358358{
    359359    tr_stat_t * s;
    360     tr_torrent_t * tor;
    361     tr_info_t * inf;
    362     int i, j, k, piece;
    363 
    364     if( h->torrentCount < 1 )
    365     {
    366         *stat = NULL;
    367         return 0;
    368     }
    369 
    370     s = malloc( h->torrentCount * sizeof( tr_stat_t ) );
    371 
    372     for( i = 0; i < h->torrentCount; i++ )
    373     {
    374         tor = h->torrents[i];
    375         inf = &tor->info;
    376 
    377         if( ( tor->status & TR_STATUS_STOPPED ) ||
    378             ( ( tor->status & TR_STATUS_STOPPING ) &&
    379               tr_date() > tor->stopDate + 60000 ) )
    380         {
    381             torrentReallyStop( h, i );
    382             tor->status = TR_STATUS_PAUSE;
    383         }
    384 
    385         tr_lockLock( &tor->lock );
    386 
    387         memcpy( &s[i].info, &tor->info, sizeof( tr_info_t ) );
    388         s[i].status = tor->status;
    389         memcpy( s[i].error, tor->error, sizeof( s[i].error ) );
    390 
    391         s[i].peersTotal       = 0;
    392         s[i].peersUploading   = 0;
    393         s[i].peersDownloading = 0;
    394 
     360    tr_info_t * inf = &tor->info;
     361    int i;
     362
     363    tor->statCur = ( tor->statCur + 1 ) % 2;
     364    s = &tor->stats[tor->statCur];
     365
     366    if( ( tor->status & TR_STATUS_STOPPED ) ||
     367        ( ( tor->status & TR_STATUS_STOPPING ) &&
     368          tr_date() > tor->stopDate + 60000 ) )
     369    {
     370        torrentReallyStop( tor );
     371        tor->status = TR_STATUS_PAUSE;
     372    }
     373
     374    tr_lockLock( &tor->lock );
     375
     376    s->status = tor->status;
     377    memcpy( s->trackerError, tor->trackerError,
     378            sizeof( s->trackerError ) );
     379
     380    s->peersTotal       = 0;
     381    s->peersUploading   = 0;
     382    s->peersDownloading = 0;
     383
     384    for( i = 0; i < tor->peerCount; i++ )
     385    {
     386        if( tr_peerIsConnected( tor->peers[i] ) )
     387        {
     388            (s->peersTotal)++;
     389            if( tr_peerIsUploading( tor->peers[i] ) )
     390            {
     391                (s->peersUploading)++;
     392            }
     393            if( tr_peerIsDownloading( tor->peers[i] ) )
     394            {
     395                (s->peersDownloading)++;
     396            }
     397        }
     398    }
     399
     400    s->progress = tr_cpCompletionAsFloat( tor->completion );
     401    if( tor->status & TR_STATUS_DOWNLOAD )
     402        s->rateDownload = tr_rcRate( tor->download );
     403    else
     404        /* tr_rcRate() doesn't make the difference between 'piece'
     405           messages and other messages, which causes a non-zero
     406           download rate even tough we are not downloading. So we
     407           force it to zero not to confuse the user. */
     408        s->rateDownload = 0.0;
     409    s->rateUpload = tr_rcRate( tor->upload );
     410   
     411    s->seeders    = tr_trackerSeeders(tor);
     412        s->leechers       = tr_trackerLeechers(tor);
     413
     414    if( s->rateDownload < 0.1 )
     415    {
     416        s->eta = -1;
     417    }
     418    else
     419    {
     420        s->eta = (float) ( 1.0 - s->progress ) *
     421            (float) inf->totalSize / s->rateDownload / 1024.0;
     422        if( s->eta > 99 * 3600 + 59 * 60 + 59 )
     423        {
     424            s->eta = -1;
     425        }
     426    }
     427
     428    s->downloaded = tor->downloaded;
     429    s->uploaded   = tor->uploaded;
     430
     431    tr_lockUnlock( &tor->lock );
     432
     433    return s;
     434}
     435
     436void tr_torrentAvailability( tr_torrent_t * tor, int8_t * tab, int size )
     437{
     438    int i, j, piece;
     439
     440    tr_lockLock( &tor->lock );
     441    for( i = 0; i < size; i++ )
     442    {
     443        piece = i * tor->info.pieceCount / size;
     444
     445        if( tr_cpPieceIsComplete( tor->completion, piece ) )
     446        {
     447            tab[i] = -1;
     448            continue;
     449        }
     450
     451        tab[i] = 0;
    395452        for( j = 0; j < tor->peerCount; j++ )
    396453        {
    397             if( tr_peerIsConnected( tor->peers[j] ) )
     454            if( tr_peerBitfield( tor->peers[j] ) &&
     455                tr_bitfieldHas( tr_peerBitfield( tor->peers[j] ), piece ) )
    398456            {
    399                 (s[i].peersTotal)++;
    400                 if( tr_peerIsUploading( tor->peers[j] ) )
    401                 {
    402                     (s[i].peersUploading)++;
    403                 }
    404                 if( tr_peerIsDownloading( tor->peers[j] ) )
    405                 {
    406                     (s[i].peersDownloading)++;
    407                 }
     457                (tab[i])++;
    408458            }
    409459        }
    410 
    411         s[i].progress     = tr_cpCompletionAsFloat( tor->completion );
    412         if( tor->status & TR_STATUS_DOWNLOAD )
    413             s[i].rateDownload = tr_rcRate( tor->download );
    414         else
    415             /* tr_rcRate() doesn't make the difference between 'piece'
    416                messages and other messages, which causes a non-zero
    417                download rate even tough we are not downloading. So we
    418                force it to zero not to confuse the user. */
    419             s[i].rateDownload = 0.0;
    420         s[i].rateUpload = tr_rcRate( tor->upload );
    421        
    422         s[i].seeders      = tr_trackerSeeders(tor);
    423                 s[i].leechers     = tr_trackerLeechers(tor);
    424 
    425         if( s[i].rateDownload < 0.1 )
    426         {
    427             s[i].eta = -1;
    428         }
    429         else
    430         {
    431             s[i].eta = (float) ( 1.0 - s[i].progress ) *
    432                 (float) inf->totalSize / s[i].rateDownload / 1024.0;
    433             if( s[i].eta > 99 * 3600 + 59 * 60 + 59 )
    434             {
    435                 s[i].eta = -1;
    436             }
    437         }
    438 
    439         for( j = 0; j < 120; j++ )
    440         {
    441             piece = j * inf->pieceCount / 120;
    442 
    443             if( tr_cpPieceIsComplete( tor->completion, piece ) )
    444             {
    445                 s[i].pieces[j] = -1;
    446                 continue;
    447             }
    448 
    449             s[i].pieces[j] = 0;
    450            
    451             for( k = 0; k < tor->peerCount; k++ )
    452             {
    453                 if( tr_peerBitfield( tor->peers[k] ) &&
    454                     tr_bitfieldHas( tr_peerBitfield( tor->peers[k] ), piece ) )
    455                 {
    456                     (s[i].pieces[j])++;
    457                 }
    458             }
    459         }
    460 
    461         s[i].downloaded = tor->downloaded;
    462         s[i].uploaded   = tor->uploaded;
    463 
    464         s[i].folder = tor->destination;
    465 
    466         tr_lockUnlock( &tor->lock );
    467     }
    468 
    469     *stat = s;
    470     return h->torrentCount;
     460    }
     461    tr_lockUnlock( &tor->lock );
    471462}
    472463
     
    476467 * Frees memory allocated by tr_torrentInit.
    477468 **********************************************************************/
    478 void tr_torrentClose( tr_handle_t * h, int t )
    479 {
    480     tr_torrent_t * tor = h->torrents[t];
    481     tr_info_t    * inf = &tor->info;
     469void tr_torrentClose( tr_handle_t * h, tr_torrent_t * tor )
     470{
     471    tr_info_t * inf = &tor->info;
    482472
    483473    if( tor->status & ( TR_STATUS_STOPPING | TR_STATUS_STOPPED ) )
    484474    {
    485475        /* Join the thread first */
    486         torrentReallyStop( h, t );
     476        torrentReallyStop( tor );
    487477    }
    488478
     
    503493    free( inf->pieces );
    504494    free( inf->files );
     495
     496    if( tor->prev )
     497    {
     498        tor->prev->next = tor->next;
     499    }
     500    else
     501    {
     502        h->torrentList = tor->next;
     503    }
     504    if( tor->next )
     505    {
     506        tor->next->prev = tor->prev;
     507    }
    505508    free( tor );
    506 
    507     memmove( &h->torrents[t], &h->torrents[t+1],
    508              ( h->torrentCount - t ) * sizeof( void * ) );
    509509
    510510    tr_lockUnlock( &h->acceptLock );
     
    596596    tr_handle_t * h = _h;
    597597    uint64_t      date1, date2, lastchoke = 0;
    598     int           ii, jj;
     598    int           ii;
    599599    uint8_t     * hash;
     600    tr_torrent_t * tor;
    600601
    601602    tr_dbg( "Accept thread started" );
     
    641642            if( NULL != ( hash = tr_peerHash( h->acceptPeers[ii] ) ) )
    642643            {
    643                 for( jj = 0; jj < h->torrentCount; jj++ )
     644                for( tor = h->torrentList; tor; tor = tor->next )
    644645                {
    645                     tr_lockLock( &h->torrents[jj]->lock );
    646                     if( 0 == memcmp( h->torrents[jj]->info.hash, hash,
     646                    tr_lockLock( &tor->lock );
     647                    if( 0 == memcmp( tor->info.hash, hash,
    647648                                     SHA_DIGEST_LENGTH ) )
    648649                    {
    649                       tr_peerAttach( h->torrents[jj], h->acceptPeers[ii] );
    650                       tr_lockUnlock( &h->torrents[jj]->lock );
     650                      tr_peerAttach( tor, h->acceptPeers[ii] );
     651                      tr_lockUnlock( &tor->lock );
    651652                      goto removePeer;
    652653                    }
    653                     tr_lockUnlock( &h->torrents[jj]->lock );
     654                    tr_lockUnlock( &tor->lock );
    654655                }
    655656                tr_peerDestroy( h->fdlimit, h->acceptPeers[ii] );
  • trunk/libtransmission/transmission.h

    r20 r162  
    11/******************************************************************************
    2  * Copyright (c) 2005 Eric Petit
     2 * Copyright (c) 2005-2006 Transmission authors and contributors
    33 *
    44 * Permission is hereby granted, free of charge, to any person obtaining a
     
    3030#include <inttypes.h>
    3131
    32 #define SHA_DIGEST_LENGTH    20
     32#define SHA_DIGEST_LENGTH 20
    3333#ifdef __BEOS__
    3434# include <StorageDefs.h>
    35 # define MAX_PATH_LENGTH B_FILE_NAME_LENGTH
     35# define MAX_PATH_LENGTH  B_FILE_NAME_LENGTH
    3636#else
    37 # define MAX_PATH_LENGTH      1024
    38 #endif
    39 #define TR_MAX_TORRENT_COUNT 50
    40 
    41 #define TR_DEFAULT_PORT      9090
     37# define MAX_PATH_LENGTH  1024
     38#endif
     39
     40#define TR_DEFAULT_PORT   9090
     41#define TR_NOERROR        0
    4242
    4343/***********************************************************************
     
    4848 **********************************************************************/
    4949typedef struct tr_handle_s tr_handle_t;
    50 
    5150tr_handle_t * tr_init();
    5251
     
    7675
    7776/***********************************************************************
     77 * tr_torrentCount
     78 ***********************************************************************
     79 * Returns the count of open torrents
     80 **********************************************************************/
     81int tr_torrentCount( tr_handle_t * h );
     82
     83/***********************************************************************
     84 * tr_torrentIterate
     85 ***********************************************************************
     86 * Iterates on open torrents
     87 **********************************************************************/
     88typedef struct tr_torrent_s tr_torrent_t;
     89typedef void (*tr_callback_t) ( tr_torrent_t *, void * );
     90void tr_torrentIterate( tr_handle_t *, tr_callback_t, void * );
     91
     92/***********************************************************************
    7893 * tr_torrentRates
    7994 ***********************************************************************
     
    8398
    8499/***********************************************************************
    85  * tr_getFinished
    86  ***********************************************************************
    87  * Tests to see if torrent is finished
    88  **********************************************************************/
    89 int tr_getFinished( tr_handle_t *, int );
    90 
    91 /***********************************************************************
    92  * tr_setFinished
    93  ***********************************************************************
    94  * Sets the boolean value finished in the torrent back to false
    95  **********************************************************************/
    96 void tr_setFinished( tr_handle_t *, int, int );
     100 * tr_close
     101 ***********************************************************************
     102 * Frees memory allocated by tr_init.
     103 **********************************************************************/
     104void tr_close( tr_handle_t * );
    97105
    98106/***********************************************************************
     
    100108 ***********************************************************************
    101109 * Opens and parses torrent file at 'path'. If the file exists and is a
    102  * valid torrent file, returns 0 and adds it to the list of torrents
    103  * (but doesn't start it). Returns a non-zero value otherwise.
    104  **********************************************************************/
    105 int tr_torrentInit( tr_handle_t *, const char * path );
     110 * valid torrent file, returns an handle and adds it to the list of
     111 * torrents (but doesn't start it). Returns NULL and sets *error
     112 * otherwise.
     113 **********************************************************************/
     114#define TR_EINVALID     1
     115#define TR_EUNSUPPORTED 2
     116#define TR_EDUPLICATE   3
     117#define TR_EOTHER       666
     118tr_torrent_t * tr_torrentInit( tr_handle_t *, const char * path,
     119                               int * error );
     120
     121typedef struct tr_info_s tr_info_t;
     122tr_info_t * tr_torrentInfo( tr_torrent_t * );
    106123
    107124/***********************************************************************
     
    114131 * before returning.
    115132 **********************************************************************/
    116 int tr_torrentScrape( tr_handle_t *, int, int * s, int * l );
     133int tr_torrentScrape( tr_torrent_t *, int * s, int * l );
    117134
    118135/***********************************************************************
     
    122139 * therefore tr_torrentStart returns immediately.
    123140 **********************************************************************/
    124 void   tr_torrentSetFolder( tr_handle_t *, int, const char * );
    125 char * tr_torrentGetFolder( tr_handle_t *, int );
    126 void   tr_torrentStart( tr_handle_t *, int );
     141void   tr_torrentSetFolder( tr_torrent_t *, const char * );
     142char * tr_torrentGetFolder( tr_torrent_t * );
     143void   tr_torrentStart( tr_torrent_t * );
    127144
    128145/***********************************************************************
     
    137154 *   waiting any further.
    138155 **********************************************************************/
    139 void tr_torrentStop( tr_handle_t *, int );
     156void tr_torrentStop( tr_torrent_t * );
     157
     158/***********************************************************************
     159 * tr_getFinished
     160 ***********************************************************************
     161 * The first call after a torrent is completed returns 1. Returns 0
     162 * in other cases.
     163 **********************************************************************/
     164int tr_getFinished( tr_torrent_t * );
    140165
    141166/***********************************************************************
    142167 * tr_torrentStat
    143168 ***********************************************************************
    144  * Allocates an array of tr_stat_t structures, containing information
    145  * about the current status of all open torrents (see the contents
    146  * of tr_stat_s below). Returns the count of open torrents and sets
    147  * (*s) to the address of the array, or NULL if no torrent is open.
    148  * In the former case, the array belongs to the caller who is
    149  * responsible of freeing it.
    150  * The interface should call this function every 0.5 second or so in
    151  * order to update itself.
     169 * Returns a pointer to an tr_stat_t structure with updated information
     170 * on the torrent. The structure belongs to libtransmission (do not
     171 * free it) and is guaranteed to be unchanged until the next call to
     172 * tr_torrentStat.
     173 * The interface should call this function every second or so in order
     174 * to update itself.
    152175 **********************************************************************/
    153176typedef struct tr_stat_s tr_stat_t;
    154 
    155 int tr_torrentCount( tr_handle_t * h );
    156 int tr_torrentStat( tr_handle_t *, tr_stat_t ** s );
     177tr_stat_t * tr_torrentStat( tr_torrent_t * );
     178
     179/***********************************************************************
     180 * tr_torrentAvailability
     181 ***********************************************************************
     182 * Use this to draw an advanced progress bar which is 'size' pixels
     183 * wide. Fills 'tab' which you must have allocated: each byte is set
     184 * to either -1 if we have the piece, otherwise it is set to the number
     185 * of connected peers who have the piece.
     186 **********************************************************************/
     187void tr_torrentAvailability( tr_torrent_t *, int8_t * tab, int size );
    157188
    158189/***********************************************************************
     
    162193 * you must call tr_torrentStop() before closing it.
    163194 **********************************************************************/
    164 void tr_torrentClose( tr_handle_t *, int );
    165 
    166 /***********************************************************************
    167  * tr_close
    168  ***********************************************************************
    169  * Frees memory allocated by tr_init.
    170  **********************************************************************/
    171 void tr_close( tr_handle_t * );
    172 
    173 
    174 /***********************************************************************
    175  * tr_stat_s
     195void tr_torrentClose( tr_handle_t *, tr_torrent_t * );
     196
     197
     198/***********************************************************************
     199 * tr_info_s
    176200 **********************************************************************/
    177201typedef struct tr_file_s
     
    181205}
    182206tr_file_t;
    183 
    184 typedef struct tr_info_s
     207struct tr_info_s
    185208{
    186209    /* Path to torrent */
     
    205228    int         fileCount;
    206229    tr_file_t * files;
    207 }
    208 tr_info_t;
    209 
     230};
     231
     232/***********************************************************************
     233 * tr_stat_s
     234 **********************************************************************/
    210235struct tr_stat_s
    211236{
    212     tr_info_t   info;
    213 
    214237#define TR_STATUS_CHECK    0x001 /* Checking files */
    215238#define TR_STATUS_DOWNLOAD 0x002 /* Downloading */
     
    219242                                    running (for internal use only) */
    220243#define TR_STATUS_PAUSE    0x020 /* Paused */
    221 #define TR_TRACKER_ERROR   0x100
     244
     245#define TR_STATUS_ACTIVE   (TR_STATUS_CHECK|TR_STATUS_DOWNLOAD|TR_STATUS_SEED)
     246#define TR_STATUS_INACTIVE (TR_STATUS_STOPPING|TR_STATUS_STOPPED|TR_STATUS_PAUSE)
    222247    int         status;
    223     char        error[128];
     248
     249#define TR_ETRACKER 1
     250#define TR_EINOUT   2
     251    int         error;
     252    char        trackerError[128];
    224253
    225254    float       progress;
     
    230259    int         peersUploading;
    231260    int         peersDownloading;
    232     char        pieces[120];
    233261    int         seeders;
    234262    int         leechers;
     
    236264    uint64_t    downloaded;
    237265    uint64_t    uploaded;
    238 
    239     char      * folder;
    240266};
    241267
Note: See TracChangeset for help on using the changeset viewer.