Changeset 7385 for trunk/libtransmission/torrent.c
- Timestamp:
- Dec 14, 2008, 11:21:11 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/torrent.c
r7368 r7385 61 61 62 62 tr_torrent* 63 tr_torrentFindFromId( tr_handle * handle, 64 int id ) 63 tr_torrentFindFromId( tr_session * session, int id ) 65 64 { 66 65 tr_torrent * tor = NULL; 67 66 68 while( ( tor = tr_torrentNext( handle, tor ) ) )67 while( ( tor = tr_torrentNext( session, tor ) ) ) 69 68 if( tor->uniqueId == id ) 70 69 return tor; … … 74 73 75 74 tr_torrent* 76 tr_torrentFindFromHashString( tr_handle * handle, 77 const char * str ) 75 tr_torrentFindFromHashString( tr_session * session, const char * str ) 78 76 { 79 77 tr_torrent * tor = NULL; 80 78 81 while( ( tor = tr_torrentNext( handle, tor ) ) )79 while( ( tor = tr_torrentNext( session, tor ) ) ) 82 80 if( !strcmp( str, tor->info.hashString ) ) 83 81 return tor; … … 87 85 88 86 tr_bool 89 tr_torrentExists( const tr_handle * handle, 90 const uint8_t * torrentHash ) 91 { 92 return tr_torrentFindFromHash( (tr_handle*)handle, 93 torrentHash ) != NULL; 87 tr_torrentExists( const tr_session * session, const uint8_t * torrentHash ) 88 { 89 return tr_torrentFindFromHash( (tr_session*)session, torrentHash ) != NULL; 94 90 } 95 91 96 92 tr_torrent* 97 tr_torrentFindFromHash( tr_handle * handle, 98 const uint8_t * torrentHash ) 93 tr_torrentFindFromHash( tr_session * session, const uint8_t * torrentHash ) 99 94 { 100 95 tr_torrent * tor = NULL; 101 96 102 while( ( tor = tr_torrentNext( handle, tor ) ) )97 while( ( tor = tr_torrentNext( session, tor ) ) ) 103 98 if( *tor->info.hash == *torrentHash ) 104 99 if( !memcmp( tor->info.hash, torrentHash, SHA_DIGEST_LENGTH ) ) … … 109 104 110 105 tr_torrent* 111 tr_torrentFindFromObfuscatedHash( tr_ handle * handle,106 tr_torrentFindFromObfuscatedHash( tr_session * session, 112 107 const uint8_t * obfuscatedTorrentHash ) 113 108 { 114 109 tr_torrent * tor = NULL; 115 110 116 while( ( tor = tr_torrentNext( handle, tor ) ) )111 while( ( tor = tr_torrentNext( session, tor ) ) ) 117 112 if( !memcmp( tor->obfuscatedHash, obfuscatedTorrentHash, 118 113 SHA_DIGEST_LENGTH ) ) … … 467 462 468 463 static void 469 torrentRealInit( tr_ handle * h,470 tr_torrent *tor,471 const tr_ctor * ctor )464 torrentRealInit( tr_session * session, 465 tr_torrent * tor, 466 const tr_ctor * ctor ) 472 467 { 473 468 int doStart; … … 477 472 static int nextUniqueId = 1; 478 473 479 tr_globalLock( h);480 481 tor->session = h;474 tr_globalLock( session ); 475 476 tor->session = session; 482 477 tor->uniqueId = nextUniqueId++; 483 478 484 479 randomizeTiers( info ); 485 480 486 tor->bandwidth = tr_bandwidthNew( h, h->bandwidth );481 tor->bandwidth = tr_bandwidthNew( session, session->bandwidth ); 487 482 488 483 tor->blockSize = getBlockSize( info->pieceSize ); … … 532 527 NULL ); 533 528 534 tr_peerMgrAddTorrent( h->peerMgr, tor ); 535 536 assert( h->isPortSet ); 537 529 tr_peerMgrAddTorrent( session->peerMgr, tor ); 530 531 assert( session->isPortSet ); 538 532 assert( !tor->downloadedCur ); 539 533 assert( !tor->uploadedCur ); … … 570 564 tr_torrent * it = NULL; 571 565 tr_torrent * last = NULL; 572 while( ( it = tr_torrentNext( h, it ) ) )566 while( ( it = tr_torrentNext( session, it ) ) ) 573 567 last = it; 574 568 575 569 if( !last ) 576 h->torrentList = tor;570 session->torrentList = tor; 577 571 else 578 572 last->next = tor; 579 ++ h->torrentCount;580 } 581 582 tr_globalUnlock( h);573 ++session->torrentCount; 574 } 575 576 tr_globalUnlock( session ); 583 577 584 578 /* maybe save our own copy of the metainfo */ … … 595 589 } 596 590 597 tr_metainfoMigrate( h, &tor->info );591 tr_metainfoMigrate( session, &tor->info ); 598 592 599 593 if( doStart ) … … 602 596 603 597 int 604 tr_torrentParse( const tr_ handle * handle,605 const tr_ctor *ctor,606 tr_info *setmeInfo )598 tr_torrentParse( const tr_session * session, 599 const tr_ctor * ctor, 600 tr_info * setmeInfo ) 607 601 { 608 602 int err = 0; … … 618 612 return TR_EINVALID; 619 613 620 err = tr_metainfoParse( handle, setmeInfo, metainfo );614 err = tr_metainfoParse( session, setmeInfo, metainfo ); 621 615 doFree = !err && ( setmeInfo == &tmp ); 622 616 … … 624 618 err = TR_EINVALID; 625 619 626 if( !err && tr_torrentExists( handle, setmeInfo->hash ) )620 if( !err && tr_torrentExists( session, setmeInfo->hash ) ) 627 621 err = TR_EDUPLICATE; 628 622 … … 634 628 635 629 tr_torrent * 636 tr_torrentNew( tr_ handle * handle,637 const tr_ctor * ctor,638 int *setmeError )630 tr_torrentNew( tr_session * session, 631 const tr_ctor * ctor, 632 int * setmeError ) 639 633 { 640 634 int err; … … 642 636 tr_torrent * tor = NULL; 643 637 644 err = tr_torrentParse( handle, ctor, &tmpInfo );638 err = tr_torrentParse( session, ctor, &tmpInfo ); 645 639 if( !err ) 646 640 { 647 641 tor = tr_new0( tr_torrent, 1 ); 648 642 tor->info = tmpInfo; 649 torrentRealInit( handle, tor, ctor );643 torrentRealInit( session, tor, ctor ); 650 644 } 651 645 else if( setmeError ) … … 1049 1043 { 1050 1044 tr_torrent * t; 1051 tr_ handle * h= tor->session;1045 tr_session * session = tor->session; 1052 1046 tr_info * inf = &tor->info; 1053 1047 … … 1055 1049 assert( !tor->isRunning ); 1056 1050 1057 tr_globalLock( h);1058 1059 tr_peerMgrRemoveTorrent( h->peerMgr, tor->info.hash );1051 tr_globalLock( session ); 1052 1053 tr_peerMgrRemoveTorrent( session->peerMgr, tor->info.hash ); 1060 1054 1061 1055 tr_cpClose( tor->completion ); … … 1072 1066 tr_free( tor->peer_id ); 1073 1067 1074 if( tor == h->torrentList ) 1075 h->torrentList = tor->next; 1076 else for( t = h->torrentList; t != NULL; t = t->next ) 1077 { 1078 if( t->next == tor ) 1079 { 1080 t->next = tor->next; 1081 break; 1082 } 1068 if( tor == session->torrentList ) 1069 session->torrentList = tor->next; 1070 else for( t = session->torrentList; t != NULL; t = t->next ) { 1071 if( t->next == tor ) { 1072 t->next = tor->next; 1073 break; 1083 1074 } 1084 1085 assert( h->torrentCount >= 1 ); 1086 h->torrentCount--; 1075 } 1076 1077 assert( session->torrentCount >= 1 ); 1078 session->torrentCount--; 1087 1079 1088 1080 tr_bandwidthFree( tor->bandwidth ); … … 1091 1083 tr_free( tor ); 1092 1084 1093 tr_globalUnlock( h);1085 tr_globalUnlock( session ); 1094 1086 } 1095 1087 … … 1249 1241 if( tor ) 1250 1242 { 1251 tr_ handle * handle= tor->session;1252 tr_globalLock( handle);1243 tr_session * session = tor->session; 1244 tr_globalLock( session ); 1253 1245 1254 1246 tr_torrentClearCompletenessCallback( tor ); 1255 tr_runInEventThread( handle, closeTorrent, tor );1256 1257 tr_globalUnlock( handle);1247 tr_runInEventThread( session, closeTorrent, tor ); 1248 1249 tr_globalUnlock( session ); 1258 1250 } 1259 1251 }
Note: See TracChangeset
for help on using the changeset viewer.