From b1ef118e3fc4a7c203c339998953983bf0acfda1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 2 Oct 2008 15:53:33 +0000 Subject: [PATCH] (libT) housekeeping: tr_torrent.handle --> tr_torrent.session --- libtransmission/fastresume.c | 14 ++++---- libtransmission/inout.c | 2 +- libtransmission/peer-mgr.c | 6 ++-- libtransmission/peer-msgs.c | 2 +- libtransmission/resume.c | 6 ++-- libtransmission/torrent.c | 62 ++++++++++++++++++------------------ libtransmission/torrent.h | 33 +++++++++---------- libtransmission/tracker.c | 4 +-- libtransmission/webseed.c | 2 +- 9 files changed, 64 insertions(+), 67 deletions(-) diff --git a/libtransmission/fastresume.c b/libtransmission/fastresume.c index 0bb298830..b70c6c9b1 100644 --- a/libtransmission/fastresume.c +++ b/libtransmission/fastresume.c @@ -615,7 +615,7 @@ parsePeers( tr_torrent * tor, { tr_pex pex; readBytes( &pex, &buf, sizeof( tr_pex ) ); - tr_peerMgrAddPex( tor->handle->peerMgr, tor->info.hash, + tr_peerMgrAddPex( tor->session->peerMgr, tor->info.hash, TR_PEER_FROM_CACHE, &pex ); } @@ -713,13 +713,13 @@ loadResumeFile( const tr_torrent * tor, { uint8_t * ret = NULL; char path[MAX_PATH_LENGTH]; - const char * cacheDir = tr_getResumeDir( tor->handle ); + const char * cacheDir = tr_getResumeDir( tor->session ); const char * hash = tor->info.hashString; - if( !ret && tor->handle->tag ) + if( !ret && tor->session->tag ) { char base[1024]; - tr_snprintf( base, sizeof( base ), "%s-%s", hash, tor->handle->tag ); + tr_snprintf( base, sizeof( base ), "%s-%s", hash, tor->session->tag ); tr_buildPath( path, sizeof( path ), cacheDir, base, NULL ); ret = tr_loadFile( path, len ); } @@ -776,13 +776,13 @@ void tr_fastResumeRemove( const tr_torrent * tor ) { char path[MAX_PATH_LENGTH]; - const char * cacheDir = tr_getResumeDir( tor->handle ); + const char * cacheDir = tr_getResumeDir( tor->session ); const char * hash = tor->info.hashString; - if( tor->handle->tag ) + if( tor->session->tag ) { char base[1024]; - tr_snprintf( base, sizeof( base ), "%s-%s", hash, tor->handle->tag ); + tr_snprintf( base, sizeof( base ), "%s-%s", hash, tor->session->tag ); tr_buildPath( path, sizeof( path ), cacheDir, base, NULL ); unlink( path ); } diff --git a/libtransmission/inout.c b/libtransmission/inout.c index 065f2895f..3cd670c41 100644 --- a/libtransmission/inout.c +++ b/libtransmission/inout.c @@ -84,7 +84,7 @@ readOrWriteBytes( const tr_torrent * tor, err = TR_OK; if( ( err == TR_OK ) && ( !fileExists ) && ( ioMode == TR_IO_WRITE ) ) - tr_statsFileCreated( tor->handle ); + tr_statsFileCreated( tor->session ); if( fd >= 0 ) tr_fdFileReturn( fd ); diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 70ef80675..995078072 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -889,7 +889,7 @@ peerCallbackFunc( void * vpeer, tr_torrent * tor = t->tor; tor->activityDate = now; tor->uploadedCur += e->length; - tr_statsAddUploaded( tor->handle, e->length ); + tr_statsAddUploaded( tor->session, e->length ); if( peer ) { struct peer_atom * atom = getExistingAtom( t, @@ -912,7 +912,7 @@ peerCallbackFunc( void * vpeer, * into the jurisdiction of the tracker." */ if( peer ) tor->downloadedCur += e->length; - tr_statsAddDownloaded( tor->handle, e->length ); + tr_statsAddDownloaded( tor->session, e->length ); if( peer ) { struct peer_atom * atom = getExistingAtom( t, @@ -971,7 +971,7 @@ peerCallbackFunc( void * vpeer, tr_torrentSetHasPiece( tor, p, !err ); tr_torrentSetPieceChecked( tor, p, TRUE ); - tr_peerMgrSetBlame( tor->handle->peerMgr, tor->info.hash, p, + tr_peerMgrSetBlame( tor->session->peerMgr, tor->info.hash, p, !err ); if( err ) diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index de15b71c3..f930d4f09 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -2092,7 +2092,7 @@ tr_peerMsgsNew( struct tr_torrent * torrent, m = tr_new0( tr_peermsgs, 1 ); m->publisher = tr_publisherNew( ); m->info = info; - m->session = torrent->handle; + m->session = torrent->session; m->torrent = torrent; m->io = info->io; m->info->clientIsChoked = 1; diff --git a/libtransmission/resume.c b/libtransmission/resume.c index 7717fdf02..119a61546 100644 --- a/libtransmission/resume.c +++ b/libtransmission/resume.c @@ -51,7 +51,7 @@ static char* getResumeFilename( const tr_torrent * tor ) { return tr_strdup_printf( "%s%c%s.%16.16s.resume", - tr_getResumeDir( tor->handle ), + tr_getResumeDir( tor->session ), TR_PATH_DELIMITER, tor->info.name, tor->info.hashString ); @@ -66,7 +66,7 @@ savePeers( tr_benc * dict, const tr_torrent * tor ) { tr_pex * pex = NULL; - const int count = tr_peerMgrGetPeers( tor->handle->peerMgr, + const int count = tr_peerMgrGetPeers( tor->session->peerMgr, tor->info.hash, &pex ); if( count > 0 ) @@ -90,7 +90,7 @@ loadPeers( tr_benc * dict, { tr_pex pex; memcpy( &pex, str + ( i * sizeof( tr_pex ) ), sizeof( tr_pex ) ); - tr_peerMgrAddPex( tor->handle->peerMgr, + tr_peerMgrAddPex( tor->session->peerMgr, tor->info.hash, TR_PEER_FROM_CACHE, &pex ); } tr_tordbg( tor, "Loaded %d peers from resume file", count ); diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index a238c1003..0513d6d5b 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -126,13 +126,13 @@ tr_torrentFindFromObfuscatedHash( tr_handle * handle, void tr_torrentLock( const tr_torrent * tor ) { - tr_globalLock( tor->handle ); + tr_globalLock( tor->session ); } void tr_torrentUnlock( const tr_torrent * tor ) { - tr_globalUnlock( tor->handle ); + tr_globalUnlock( tor->session ); } /*** @@ -222,7 +222,7 @@ onTrackerResponse( void * tracker UNUSED, { if( event->allAreSeeds ) pex[i].flags |= ADDED_F_SEED_FLAG; - tr_peerMgrAddPex( tor->handle->peerMgr, tor->info.hash, + tr_peerMgrAddPex( tor->session->peerMgr, tor->info.hash, TR_PEER_FROM_TRACKER, pex + i ); } @@ -461,7 +461,7 @@ torrentRealInit( tr_handle * h, tr_globalLock( h ); - tor->handle = h; + tor->session = h; tor->uniqueId = nextUniqueId++; randomizeTiers( info ); @@ -537,9 +537,9 @@ torrentRealInit( tr_handle * h, if( !( loaded & TR_FR_SPEEDLIMIT ) ) { tr_torrentSetSpeedLimit( tor, TR_UP, - tr_sessionGetSpeedLimit( tor->handle, TR_UP ) ); + tr_sessionGetSpeedLimit( tor->session, TR_UP ) ); tr_torrentSetSpeedLimit( tor, TR_DOWN, - tr_sessionGetSpeedLimit( tor->handle, + tr_sessionGetSpeedLimit( tor->session, TR_DOWN ) ); } @@ -573,7 +573,7 @@ torrentRealInit( tr_handle * h, { const char * filename = tor->info.torrent; tr_bencSaveFile( filename, val ); - tr_sessionSetTorrentFile( tor->handle, tor->info.hashString, + tr_sessionSetTorrentFile( tor->session, tor->info.hashString, filename ); } } @@ -680,7 +680,7 @@ int tr_torrentAllowsPex( const tr_torrent * tor ) { return tor - && tor->handle->isPexEnabled + && tor->session->isPexEnabled && !tr_torrentIsPrivate( tor ); } @@ -696,7 +696,7 @@ tr_torrentManualUpdateImpl( void * vtor ) void tr_torrentManualUpdate( tr_torrent * tor ) { - tr_runInEventThread( tor->handle, tr_torrentManualUpdateImpl, tor ); + tr_runInEventThread( tor->session, tr_torrentManualUpdateImpl, tor ); } int @@ -769,7 +769,7 @@ tr_torrentStat( tr_torrent * tor ) tr_trackerGetCounts( tc, &s->timesCompleted, &s->leechers, &s->seeders ); - tr_peerMgrTorrentStats( tor->handle->peerMgr, + tr_peerMgrTorrentStats( tor->session->peerMgr, tor->info.hash, &s->peersKnown, &s->peersConnected, @@ -821,7 +821,7 @@ tr_torrentStat( tr_torrent * tor ) { tr_piece_index_t i; tr_bitfield * peerPieces = tr_peerMgrGetAvailable( - tor->handle->peerMgr, + tor->session->peerMgr, tor->info. hash ); s->desiredAvailable = 0; @@ -941,7 +941,7 @@ tr_torrentFilesFree( tr_file_stat * files, float* tr_torrentWebSpeeds( const tr_torrent * tor ) { - return tor ? tr_peerMgrWebSpeeds( tor->handle->peerMgr, tor->info.hash ) + return tor ? tr_peerMgrWebSpeeds( tor->session->peerMgr, tor->info.hash ) : NULL; } @@ -952,7 +952,7 @@ tr_torrentPeers( const tr_torrent * tor, tr_peer_stat * ret = NULL; if( tor ) - ret = tr_peerMgrPeerStats( tor->handle->peerMgr, + ret = tr_peerMgrPeerStats( tor->session->peerMgr, tor->info.hash, peerCount ); return ret; @@ -970,7 +970,7 @@ tr_torrentAvailability( const tr_torrent * tor, int8_t * tab, int size ) { - tr_peerMgrTorrentAvailability( tor->handle->peerMgr, + tr_peerMgrTorrentAvailability( tor->session->peerMgr, tor->info.hash, tab, size ); } @@ -1026,7 +1026,7 @@ static void freeTorrent( tr_torrent * tor ) { tr_torrent * t; - tr_handle * h = tor->handle; + tr_handle * h = tor->session; tr_info * inf = &tor->info; assert( tor ); @@ -1077,7 +1077,7 @@ checkAndStartImpl( void * vtor ) { tr_torrent * tor = vtor; - tr_globalLock( tor->handle ); + tr_globalLock( tor->session ); tor->isRunning = 1; *tor->errorString = '\0'; @@ -1086,22 +1086,22 @@ checkAndStartImpl( void * vtor ) tr_torrentSaveResume( tor ); tor->startDate = time( NULL ); tr_trackerStart( tor->tracker ); - tr_peerMgrStartTorrent( tor->handle->peerMgr, tor->info.hash ); + tr_peerMgrStartTorrent( tor->session->peerMgr, tor->info.hash ); - tr_globalUnlock( tor->handle ); + tr_globalUnlock( tor->session ); } static void checkAndStartCB( tr_torrent * tor ) { - tr_runInEventThread( tor->handle, checkAndStartImpl, tor ); + tr_runInEventThread( tor->session, checkAndStartImpl, tor ); } static void torrentStart( tr_torrent * tor, int reloadProgress ) { - tr_globalLock( tor->handle ); + tr_globalLock( tor->session ); if( !tor->isRunning ) { @@ -1111,7 +1111,7 @@ torrentStart( tr_torrent * tor, tr_verifyAdd( tor, checkAndStartCB ); } - tr_globalUnlock( tor->handle ); + tr_globalUnlock( tor->session ); } void @@ -1130,7 +1130,7 @@ torrentRecheckDoneImpl( void * vtor ) static void torrentRecheckDoneCB( tr_torrent * tor ) { - tr_runInEventThread( tor->handle, torrentRecheckDoneImpl, tor ); + tr_runInEventThread( tor->session, torrentRecheckDoneImpl, tor ); } void @@ -1138,12 +1138,12 @@ tr_torrentVerify( tr_torrent * tor ) { tr_verifyRemove( tor ); - tr_globalLock( tor->handle ); + tr_globalLock( tor->session ); tr_torrentUncheck( tor ); tr_verifyAdd( tor, torrentRecheckDoneCB ); - tr_globalUnlock( tor->handle ); + tr_globalUnlock( tor->session ); } static void @@ -1154,7 +1154,7 @@ stopTorrent( void * vtor ) tr_torrent * tor = vtor; tr_verifyRemove( tor ); - tr_peerMgrStopTorrent( tor->handle->peerMgr, tor->info.hash ); + tr_peerMgrStopTorrent( tor->session->peerMgr, tor->info.hash ); tr_trackerStop( tor->tracker ); for( i = 0; i < tor->info.fileCount; ++i ) @@ -1172,14 +1172,14 @@ tr_torrentStop( tr_torrent * tor ) { if( tor ) { - tr_globalLock( tor->handle ); + tr_globalLock( tor->session ); tor->isRunning = 0; if( !tor->isDeleting ) tr_torrentSaveResume( tor ); - tr_runInEventThread( tor->handle, stopTorrent, tor ); + tr_runInEventThread( tor->session, stopTorrent, tor ); - tr_globalUnlock( tor->handle ); + tr_globalUnlock( tor->session ); } } @@ -1193,7 +1193,7 @@ closeTorrent( void * vtor ) stopTorrent( tor ); if( tor->isDeleting ) { - tr_metainfoRemoveSaved( tor->handle, &tor->info ); + tr_metainfoRemoveSaved( tor->session, &tor->info ); tr_torrentRemoveResume( tor ); } freeTorrent( tor ); @@ -1204,7 +1204,7 @@ tr_torrentFree( tr_torrent * tor ) { if( tor ) { - tr_handle * handle = tor->handle; + tr_handle * handle = tor->session; tr_globalLock( handle ); tr_torrentClearStatusCallback( tor ); @@ -1702,7 +1702,7 @@ tr_torrentSetAnnounceList( tr_torrent * tor, /* try to parse it back again, to make sure it's good */ memset( &tmpInfo, 0, sizeof( tr_info ) ); - if( !tr_metainfoParse( tor->handle, &tmpInfo, &metainfo ) ) + if( !tr_metainfoParse( tor->session, &tmpInfo, &metainfo ) ) { /* if it's good, save it and use it */ tr_metainfoFree( &tor->info ); diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index bb72f4864..e7a4e1111 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -41,31 +41,28 @@ void tr_torrentSetHasPiece( tr_torrent * tor, tr_piece_index_t pieceIndex, int has ); -void tr_torrentLock( const tr_torrent * ); +void tr_torrentLock( const tr_torrent * session ); -void tr_torrentUnlock( const tr_torrent * ); +void tr_torrentUnlock( const tr_torrent * session ); -int tr_torrentIsSeed( const tr_torrent * ); +int tr_torrentIsSeed( const tr_torrent * session ); -void tr_torrentChangeMyPort( tr_torrent * ); +void tr_torrentChangeMyPort( tr_torrent * session ); -int tr_torrentExists( const tr_handle *, - const uint8_t * ); +int tr_torrentExists( const tr_session * session, + const uint8_t * hash ); -tr_torrent* tr_torrentFindFromId( tr_handle *, - int id ); +tr_torrent* tr_torrentFindFromId( tr_session * session, + int id ); -tr_torrent* tr_torrentFindFromHash( tr_handle *, - const uint8_t * ); +tr_torrent* tr_torrentFindFromHash( tr_session * session, + const uint8_t * hash ); -tr_torrent* tr_torrentFindFromHashString( - tr_handle *, - const char * ); +tr_torrent* tr_torrentFindFromHashString( tr_session * session, + const char * hashString ); -tr_torrent* tr_torrentFindFromObfuscatedHash( - tr_handle *, - const - uint8_t* ); +tr_torrent* tr_torrentFindFromObfuscatedHash( tr_session * session, + const uint8_t * hash ); int tr_torrentAllowsPex( const tr_torrent * ); @@ -153,7 +150,7 @@ tr_verify_state; struct tr_torrent { - tr_handle * handle; + tr_session * session; tr_info info; int uploadLimit; diff --git a/libtransmission/tracker.c b/libtransmission/tracker.c index 77b97a9f7..52af47b5b 100644 --- a/libtransmission/tracker.c +++ b/libtransmission/tracker.c @@ -913,11 +913,11 @@ tr_trackerNew( const tr_torrent * torrent ) const tr_info * info = &torrent->info; tr_tracker * t; - ensureGlobalsExist( torrent->handle ); + ensureGlobalsExist( torrent->session ); t = tr_new0( tr_tracker, 1 ); t->publisher = tr_publisherNew( ); - t->session = torrent->handle; + t->session = torrent->session; t->scrapeIntervalSec = DEFAULT_SCRAPE_INTERVAL_SEC; t->retryScrapeIntervalSec = FIRST_SCRAPE_RETRY_INTERVAL_SEC; t->retryAnnounceIntervalSec = FIRST_ANNOUNCE_RETRY_INTERVAL_SEC; diff --git a/libtransmission/webseed.c b/libtransmission/webseed.c index 19e67accb..51e010937 100644 --- a/libtransmission/webseed.c +++ b/libtransmission/webseed.c @@ -300,7 +300,7 @@ requestNextChunk( tr_webseed * w ) left, and we're asking for %lu this time\n", range, (unsigned long)tr_torPieceCountBytes(w->torrent,piece), (unsigned long)have, (unsigned long)left, (unsigned long)thisPass );*/ - tr_webRun( w->torrent->handle, url, range, webResponseFunc, w ); + tr_webRun( w->torrent->session, url, range, webResponseFunc, w ); tr_free( range ); tr_free( url ); }