Changeset 4285


Ignore:
Timestamp:
Dec 22, 2007, 5:30:31 PM (14 years ago)
Author:
charles
Message:

(1) fix peer limits in fastresume (2) possible fastresume corruption (3) add `save' field to torrent ctor

Location:
trunk/libtransmission
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fastresume.c

    r4283 r4285  
    5858#include "completion.h"
    5959#include "fastresume.h"
     60#include "internal.h" /* tr_torrentInitFileDLs */
    6061#include "peer-mgr.h"
    6162#include "platform.h"
     
    351352    switch( id )
    352353    {
    353         case FR_ID_DOWNLOADED:     ret = TR_FR_DOWNLOADED;  break;
    354         case FR_ID_UPLOADED:       ret = TR_FR_UPLOADED;    break;
    355         case FR_ID_PROGRESS:       ret = TR_FR_PROGRESS;    break;
    356         case FR_ID_PRIORITY:       ret = TR_FR_PRIORITY;    break;
    357         case FR_ID_SPEED:          ret = TR_FR_SPEEDLIMIT;  break;
    358         case FR_ID_RUN:            ret = TR_FR_RUN;         break;
    359         case FR_ID_CORRUPT:        ret = TR_FR_CORRUPT;     break;
    360         case FR_ID_PEERS:          ret = TR_FR_PEERS;       break;
    361         case FR_ID_DESTINATION:    ret = TR_FR_DESTINATION; break;
    362         case FR_ID_PEX:            ret = TR_FR_PEX;         break;
     354        case FR_ID_DOWNLOADED:     ret = TR_FR_DOWNLOADED;    break;
     355        case FR_ID_UPLOADED:       ret = TR_FR_UPLOADED;      break;
     356        case FR_ID_PROGRESS:       ret = TR_FR_PROGRESS;      break;
     357        case FR_ID_PRIORITY:       ret = TR_FR_PRIORITY;      break;
     358        case FR_ID_SPEED:          ret = TR_FR_SPEEDLIMIT;    break;
     359        case FR_ID_RUN:            ret = TR_FR_RUN;           break;
     360        case FR_ID_CORRUPT:        ret = TR_FR_CORRUPT;       break;
     361        case FR_ID_PEERS:          ret = TR_FR_PEERS;         break;
     362        case FR_ID_DESTINATION:    ret = TR_FR_DESTINATION;   break;
     363        case FR_ID_PEX:            ret = TR_FR_PEX;           break;
     364        case FR_ID_MAX_PEERS:      ret = TR_FR_MAX_PEERS;     break;
     365        case FR_ID_MAX_UNCHOKED:   ret = TR_FR_MAX_UNCHOKED;  break;
    363366    }
    364367
     
    502505
    503506        if( dndCount )
    504             tr_torrentSetFileDLs ( tor, dnd, dndCount, FALSE );
     507            tr_torrentInitFileDLs ( tor, dnd, dndCount, FALSE );
    505508        if( dlCount )
    506             tr_torrentSetFileDLs ( tor, dl, dlCount, TRUE );
     509            tr_torrentInitFileDLs ( tor, dl, dlCount, TRUE );
    507510
    508511        tr_free( dnd );
     
    617620            case FR_ID_MAX_PEERS:    ret |= parseConnections( tor, buf, len ); break;
    618621            case FR_ID_MAX_UNCHOKED: ret |= parseUnchoked( tor, buf, len ); break;
    619             case FR_ID_PEX:         ret |= parsePex( tor, buf, len ); break;
    620             case FR_ID_DESTINATION: ret |= parseDestination( tor, buf, len ); break;
    621             default:                tr_dbg( "Skipping unknown resume code %d", (int)id ); break;
     622            case FR_ID_PEX:          ret |= parsePex( tor, buf, len ); break;
     623            case FR_ID_DESTINATION:  ret |= parseDestination( tor, buf, len ); break;
     624            default:                 tr_dbg( "Skipping unknown resume code %d", (int)id ); break;
    622625        }
    623626
  • trunk/libtransmission/internal.h

    r4267 r4285  
    4444#endif
    4545
     46/* just like tr_torrentSetFileDLs but doesn't trigger a fastresume save */
     47void tr_torrentInitFileDLs( tr_torrent   * tor,
     48                            int          * files,
     49                            int            fileCount,
     50                            int            do_download );
     51
    4652int tr_torrentIsPrivate( const tr_torrent * );
    4753
  • trunk/libtransmission/torrent-ctor.c

    r4269 r4285  
    3636{
    3737    const tr_handle * handle;
     38    unsigned int saveInOurTorrentsDir : 1;
    3839
    3940    unsigned int isSet_metainfo : 1;
     
    117118
    118119void
     120tr_ctorSetSave( tr_ctor  * ctor,
     121                int        saveInOurTorrentsDir )
     122{
     123    ctor->saveInOurTorrentsDir = saveInOurTorrentsDir ? 1 : 0;
     124}
     125
     126int
     127tr_ctorGetSave( const tr_ctor * ctor )
     128{
     129    return ctor && ctor->saveInOurTorrentsDir;
     130}
     131
     132void
    119133tr_ctorSetPaused( tr_ctor        * ctor,
    120134                  tr_ctorMode      mode,
     
    246260    tr_ctorSetMaxUnchokedPeers( ctor, TR_FALLBACK, DEFAULT_MAX_UNCHOKED_PEERS );
    247261    tr_ctorSetPaused( ctor, TR_FALLBACK, FALSE );
     262    tr_ctorSetSave( ctor, TRUE );
    248263    return ctor;
    249264}
  • trunk/libtransmission/torrent.c

    r4279 r4285  
    397397    tr_info tmp;
    398398    const benc_val_t * metainfo;
     399    const int doSave = tr_ctorGetSave( ctor );
    399400
    400401    if( setmeInfo == NULL )
     
    405406        return TR_EINVALID;
    406407
    407     err = tr_metainfoParseBenc( setmeInfo, handle->tag, metainfo, FALSE );
     408    err = tr_metainfoParseBenc( setmeInfo, handle->tag, metainfo, doSave );
    408409    doFree = !err && ( setmeInfo == &tmp );
    409410
     
    11861187
    11871188void
     1189tr_torrentInitFileDLs ( tr_torrent   * tor,
     1190                        int          * files,
     1191                        int            fileCount,
     1192                        int            doDownload )
     1193{
     1194    int i;
     1195    tr_torrentLock( tor );
     1196
     1197    for( i=0; i<fileCount; ++i )
     1198        setFileDND( tor, files[i], doDownload );
     1199    tr_cpInvalidateDND ( tor->completion );
     1200
     1201    tr_torrentUnlock( tor );
     1202}
     1203
     1204void
    11881205tr_torrentSetFileDLs ( tr_torrent  * tor,
    11891206                       int         * files,
     
    11911208                       int           doDownload )
    11921209{
    1193     int i;
    11941210    tr_torrentLock( tor );
    1195 
    1196     for( i=0; i<fileCount; ++i )
    1197         setFileDND( tor, files[i], doDownload );
    1198     tr_cpInvalidateDND ( tor->completion );
     1211    tr_torrentInitFileDLs( tor, files, fileCount, doDownload );
    11991212    saveFastResumeNow( tor );
    1200 
    12011213    tr_torrentUnlock( tor );
    12021214}
  • trunk/libtransmission/transmission.c

    r4267 r4285  
    394394    tr_list *l=NULL, *list=NULL;
    395395
     396    tr_ctorSetSave( ctor, FALSE ); /* since we already have them */
     397
    396398    if( !stat( dirname, &sb )
    397399        && S_ISDIR( sb.st_mode )
  • trunk/libtransmission/transmission.h

    r4279 r4285  
    388388void     tr_ctorFree                   ( tr_ctor        * ctor );
    389389
     390void     tr_ctorSetSave                ( tr_ctor        * ctor,
     391                                         int              saveMetadataInOurTorrentsDir );
     392
    390393int      tr_ctorSetMetainfo            ( tr_ctor        * ctor,
    391394                                         const uint8_t  * metainfo,
     
    432435int      tr_ctorGetMetainfo            ( const tr_ctor  * ctor,
    433436                                         const struct benc_val_s ** setme );
     437
     438int      tr_ctorGetSave                ( const tr_ctor  * ctor );
    434439
    435440typedef struct tr_info tr_info;
Note: See TracChangeset for help on using the changeset viewer.