Changeset 5613
- Timestamp:
- Apr 14, 2008, 2:39:13 PM (14 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/metainfo.c
r5611 r5613 158 158 159 159 void 160 tr_metainfoMigrate( consttr_handle * handle,161 consttr_info * inf )160 tr_metainfoMigrate( tr_handle * handle, 161 tr_info * inf ) 162 162 { 163 163 struct stat new_sb; … … 177 177 FILE * out = fopen( new_name, "wb+" ); 178 178 if( fwrite( content, sizeof( uint8_t ), contentLen, out ) == contentLen ) 179 { 180 tr_free( inf->torrent ); 181 inf->torrent = tr_strdup( new_name ); 182 tr_sessionSetTorrentFile( handle, inf->hashString, new_name ); 179 183 unlink( old_name ); 184 } 180 185 fclose( out ); 181 186 } … … 315 320 tr_free( inf->torrent ); 316 321 inf->torrent = tr_strdup( buf ); 317 fprintf( stderr, "inf->torrent is [%s]\n", inf->torrent );318 322 319 323 return TR_OK; -
trunk/libtransmission/metainfo.h
r5611 r5613 39 39 const tr_info * info ); 40 40 41 void tr_metainfoMigrate( consttr_handle * handle,42 consttr_info * inf );41 void tr_metainfoMigrate( tr_handle * handle, 42 tr_info * inf ); 43 43 44 44 #endif -
trunk/libtransmission/resume.c
r5611 r5613 41 41 #define KEY_SPEEDLIMIT_UP_MODE "up-mode" 42 42 43 #define KEY_PROGRESS_MTIMES "mtimes"43 #define KEY_PROGRESS_MTIMES "mtimes" 44 44 #define KEY_PROGRESS_BITFIELD "bitfield" 45 45 … … 62 62 savePeers( tr_benc * dict, const tr_torrent * tor ) 63 63 { 64 tr_pex * pex ;64 tr_pex * pex = NULL; 65 65 const int count = tr_peerMgrGetPeers( tor->handle->peerMgr, 66 66 tor->info.hash, &pex ); 67 if( count > 0 ) { 68 tr_benc * child = tr_bencDictAdd( dict, KEY_PEERS ); 69 tr_bencInitStrDupLen( child, (const char*)pex, sizeof(tr_pex)*count ); 70 tr_free( pex ); 71 } 67 if( count > 0 ) 68 tr_bencInitStrDupLen( tr_bencDictAdd( dict, KEY_PEERS ), 69 (const char*)pex, sizeof(tr_pex)*count ); 70 tr_free( pex ); 72 71 } 73 72 … … 181 180 ***/ 182 181 182 static const time_t verifyNeeded = ~(time_t)0; 183 183 184 static void 184 185 saveProgress( tr_benc * dict, const tr_torrent * tor ) … … 198 199 mtimes = tr_torrentGetMTimes( tor, &n ); 199 200 m = tr_bencDictAddList( p, KEY_PROGRESS_MTIMES, n ); 200 for( i=0; i<n; ++i ) { 201 if( !tr_torrentIsFileChecked( tor, i ) ) 202 mtimes[i] = ~(time_t)0; /* force a recheck next time */ 203 tr_bencListAddInt( m, mtimes[i] ); 204 } 201 for( i=0; i<n; ++i ) 202 tr_bencListAddInt( m, tr_torrentIsFileChecked( tor, i ) 203 ? mtimes[i] : verifyNeeded ); 205 204 206 205 /* add the bitfield */ … … 231 230 { 232 231 int i; 233 const time_t recheck = ~(time_t)0;234 232 for( i=0; i<m->val.l.count; ++i ) 235 233 { 236 234 int64_t x; 237 time_t t = tr_bencGetInt( &m->val.l.vals[i], &x ) ? x : recheck; 238 if( ( t != recheck ) && ( curMTimes[i] == t ) ) 235 const time_t t = tr_bencGetInt( &m->val.l.vals[i], &x ) 236 ? x : verifyNeeded; 237 if( ( t != verifyNeeded ) && ( t == curMTimes[i] ) ) 239 238 tr_torrentSetFileChecked( tor, i, TRUE ); 240 239 else { … … 283 282 char filename[MAX_PATH_LENGTH]; 284 283 285 /* populate the bencoded data */286 284 tr_bencInitDict( &top, 10 ); 287 tr_bencDictAddInt( &top, KEY_CORRUPT, tor->corruptPrev + tor->corruptCur ); 288 tr_bencDictAddStr( &top, KEY_DESTINATION, tor->destination ); 285 tr_bencDictAddInt( &top, KEY_CORRUPT, 286 tor->corruptPrev + tor->corruptCur ); 287 tr_bencDictAddStr( &top, KEY_DESTINATION, 288 tor->destination ); 289 289 tr_bencDictAddInt( &top, KEY_DOWNLOADED, 290 tor->downloadedPrev + tor->downloadedCur );290 tor->downloadedPrev + tor->downloadedCur ); 291 291 tr_bencDictAddInt( &top, KEY_UPLOADED, 292 292 tor->uploadedPrev + tor->uploadedCur ); 293 tr_bencDictAddInt( &top, KEY_MAX_PEERS, tor->maxConnectedPeers ); 294 tr_bencDictAddInt( &top, KEY_PAUSED, tor->isRunning?0:1 ); 293 tr_bencDictAddInt( &top, KEY_MAX_PEERS, 294 tor->maxConnectedPeers ); 295 tr_bencDictAddInt( &top, KEY_PAUSED, 296 tor->isRunning ? 0 : 1 ); 295 297 savePeers( &top, tor ); 296 298 savePriorities( &top, tor ); -
trunk/libtransmission/session.c
r5588 r5613 37 37 #include "fdlimit.h" 38 38 #include "list.h" 39 #include "metainfo.h" /* tr_metainfoFree */ 39 40 #include "net.h" 40 41 #include "peer-mgr.h" … … 113 114 **** 114 115 ***/ 116 117 static void metainfoLookupRescan( tr_handle * h ); 115 118 116 119 tr_handle * … … 195 198 tr_statsInit( h ); 196 199 200 metainfoLookupRescan( h ); 201 197 202 return h; 198 203 } … … 464 469 tr_ctorSetMetainfoFromFile( ctor, filename ); 465 470 tor = tr_torrentNew( h, ctor, NULL ); 466 if( tor != NULL) {471 if( tor ) { 467 472 tr_list_append( &list, tor ); 468 473 n++; … … 542 547 return _tr_blocklistHasAddress( handle->blocklist, addr ); 543 548 } 549 550 /*** 551 **** 552 ***/ 553 554 static int 555 compareLookupEntries( const void * va, const void * vb ) 556 { 557 const struct tr_metainfo_lookup * a = va; 558 const struct tr_metainfo_lookup * b = vb; 559 return strcmp( a->hashString, b->hashString ); 560 } 561 562 static void 563 metainfoLookupResort( tr_handle * h ) 564 { 565 qsort( h->metainfoLookup, 566 h->metainfoLookupCount, 567 sizeof( struct tr_metainfo_lookup ), 568 compareLookupEntries ); 569 } 570 571 static int 572 compareHashStringToLookupEntry( const void * va, const void * vb ) 573 { 574 const char * a = va; 575 const struct tr_metainfo_lookup * b = vb; 576 return strcmp( a, b->hashString ); 577 } 578 579 const char* 580 tr_sessionFindTorrentFile( const tr_handle * h, 581 const char * hashStr ) 582 { 583 struct tr_metainfo_lookup * l = bsearch( hashStr, 584 h->metainfoLookup, 585 h->metainfoLookupCount, 586 sizeof( struct tr_metainfo_lookup ), 587 compareHashStringToLookupEntry ); 588 return l ? l->filename : NULL; 589 } 590 591 static void 592 metainfoLookupRescan( tr_handle * h ) 593 { 594 int i; 595 int n; 596 struct stat sb; 597 const char * dirname = tr_getTorrentDir( h ); 598 DIR * odir = NULL; 599 tr_ctor * ctor = NULL; 600 tr_list * list = NULL; 601 602 /* walk through the directory and find the mappings */ 603 ctor = tr_ctorNew( h ); 604 tr_ctorSetSave( ctor, FALSE ); /* since we already have them */ 605 if( !stat( dirname, &sb ) && S_ISDIR( sb.st_mode ) && (( odir = opendir( dirname )))) 606 { 607 struct dirent *d; 608 for (d = readdir( odir ); d!=NULL; d=readdir( odir ) ) 609 { 610 if( d->d_name && d->d_name[0]!='.' ) /* skip dotfiles, ., and .. */ 611 { 612 tr_info inf; 613 char filename[MAX_PATH_LENGTH]; 614 tr_buildPath( filename, sizeof(filename), dirname, d->d_name, NULL ); 615 tr_ctorSetMetainfoFromFile( ctor, filename ); 616 if( !tr_torrentParse( h, ctor, &inf ) ) 617 { 618 tr_list_append( &list, tr_strdup( inf.hashString ) ); 619 tr_list_append( &list, tr_strdup( filename ) ); 620 tr_metainfoFree( &inf ); 621 } 622 } 623 } 624 closedir( odir ); 625 } 626 tr_ctorFree( ctor ); 627 628 n = tr_list_size( list ) / 2; 629 h->metainfoLookup = tr_new0( struct tr_metainfo_lookup, n ); 630 h->metainfoLookupCount = n; 631 for( i=0; i<n; ++i ) 632 { 633 char * hashString = tr_list_pop_front( &list ); 634 char * filename = tr_list_pop_front( &list ); 635 636 memcpy( h->metainfoLookup[i].hashString, hashString, 2*SHA_DIGEST_LENGTH+1 ); 637 tr_free( hashString ); 638 h->metainfoLookup[i].filename = filename; 639 } 640 641 metainfoLookupResort( h ); 642 tr_dbg( "Found %d torrents in \"%s\"", n, dirname ); 643 } 644 645 void 646 tr_sessionSetTorrentFile( tr_handle * h, 647 const char * hashString, 648 const char * filename ) 649 { 650 struct tr_metainfo_lookup * l = bsearch( hashString, 651 h->metainfoLookup, 652 h->metainfoLookupCount, 653 sizeof( struct tr_metainfo_lookup ), 654 compareHashStringToLookupEntry ); 655 if( l != NULL ) 656 { 657 if( l->filename != filename ) 658 { 659 tr_free( l->filename ); 660 l->filename = tr_strdup( filename ); 661 } 662 } 663 else 664 { 665 const int n = h->metainfoLookupCount++; 666 struct tr_metainfo_lookup * node; 667 h->metainfoLookup = tr_renew( struct tr_metainfo_lookup, 668 h->metainfoLookup, 669 h->metainfoLookupCount ); 670 node = h->metainfoLookup + n; 671 memcpy( node->hashString, hashString, 2*SHA_DIGEST_LENGTH+1 ); 672 node->filename = tr_strdup( filename ); 673 metainfoLookupResort( h ); 674 } 675 } -
trunk/libtransmission/session.h
r5588 r5613 54 54 const uint8_t* tr_getPeerId( void ); 55 55 56 struct tr_metainfo_lookup 57 { 58 char hashString[2*SHA_DIGEST_LENGTH+1]; 59 char * filename; 60 }; 61 62 const char * tr_sessionFindTorrentFile( const tr_handle * h, 63 const char * hashString ); 64 65 void tr_sessionSetTorrentFile( tr_handle * h, 66 const char * hashString, 67 const char * filename ); 68 56 69 struct tr_handle 57 70 { 58 unsigned int isPortSet : 1;59 unsigned int isPexEnabled : 1;60 unsigned int isClosed : 1;61 unsigned int useUploadLimit : 1;62 unsigned int useDownloadLimit : 1;71 unsigned int isPortSet : 1; 72 unsigned int isPexEnabled : 1; 73 unsigned int isClosed : 1; 74 unsigned int useUploadLimit : 1; 75 unsigned int useDownloadLimit : 1; 63 76 64 tr_encryption_mode encryptionMode;77 tr_encryption_mode encryptionMode; 65 78 66 struct tr_event_handle * events;79 struct tr_event_handle * events; 67 80 68 int peerSocketTOS;81 int peerSocketTOS; 69 82 70 int torrentCount;71 tr_torrent * torrentList;83 int torrentCount; 84 tr_torrent * torrentList; 72 85 73 char * tag;86 char * tag; 74 87 75 char * configDir;76 char * torrentDir;77 char * resumeDir;88 char * configDir; 89 char * torrentDir; 90 char * resumeDir; 78 91 79 struct tr_ratecontrol * upload;80 struct tr_ratecontrol * download;92 struct tr_ratecontrol * upload; 93 struct tr_ratecontrol * download; 81 94 82 struct tr_blocklist * blocklist;83 struct tr_peerMgr * peerMgr;84 struct tr_shared * shared;95 struct tr_blocklist * blocklist; 96 struct tr_peerMgr * peerMgr; 97 struct tr_shared * shared; 85 98 86 struct tr_lock * lock;99 struct tr_lock * lock; 87 100 88 tr_handle_status stats[2];89 int statCur;101 tr_handle_status stats[2]; 102 int statCur; 90 103 91 struct tr_stats_handle * sessionStats; 92 struct tr_tracker_handle * tracker; 104 struct tr_stats_handle * sessionStats; 105 struct tr_tracker_handle * tracker; 106 107 struct tr_metainfo_lookup * metainfoLookup; 108 int metainfoLookupCount; 93 109 }; 94 110 -
trunk/libtransmission/torrent-ctor.c
r5517 r5613 15 15 #include "bencode.h" 16 16 #include "platform.h" 17 #include "session.h" /* tr_sessionFindTorrentFile */ 17 18 #include "trcompat.h" /* strlcpy */ 18 19 #include "utils.h" … … 126 127 const char * hashString ) 127 128 { 128 int err = -1; 129 char basename[2048]; 130 char filename[MAX_PATH_LENGTH]; 131 132 if( err && ( ctor->handle->tag != NULL ) ) { 133 snprintf( basename, sizeof(basename), "%s-%s", hashString, ctor->handle->tag ); 134 tr_buildPath( filename, sizeof(filename), tr_getTorrentDir( ctor->handle ), basename, NULL ); 135 err = tr_ctorSetMetainfoFromFile( ctor, filename ); 136 } 137 138 if( err ) { 139 tr_buildPath( filename, sizeof(filename), tr_getTorrentDir( ctor->handle ), hashString, NULL ); 140 err = tr_ctorSetMetainfoFromFile( ctor, filename ); 141 } 129 int err; 130 const char * filename; 131 132 if(( filename = tr_sessionFindTorrentFile( ctor->handle, hashString ))) 133 err = tr_ctorSetMetainfoFromFile( ctor, filename ); 134 else 135 err = TR_ERROR; 142 136 143 137 return err; -
trunk/libtransmission/torrent.c
r5611 r5613 388 388 const char * filename = tor->info.torrent; 389 389 tr_bencSaveFile( filename, val ); 390 tr_sessionSetTorrentFile( tor->handle, tor->info.hashString, filename ); 390 391 } 391 392 }
Note: See TracChangeset
for help on using the changeset viewer.