From: Jordan Lee Date: Thu, 3 Mar 2011 18:33:24 +0000 (+0000) Subject: (trunk libT) remove the unused tr_ratecontrol code. switch webseed over to using... X-Git-Tag: 2.30b1~207 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0c36e0c9de8c0074c2639e9d179c4d3d4bc7a348;p=transmission (trunk libT) remove the unused tr_ratecontrol code. switch webseed over to using tr_bandwidth. --- diff --git a/libtransmission/Makefile.am b/libtransmission/Makefile.am index a02666036..6eacbbbb6 100644 --- a/libtransmission/Makefile.am +++ b/libtransmission/Makefile.am @@ -46,7 +46,6 @@ libtransmission_a_SOURCES = \ platform.c \ port-forwarding.c \ ptrarray.c \ - ratecontrol.c \ resume.c \ rpcimpl.c \ rpc-server.c \ @@ -99,7 +98,6 @@ noinst_HEADERS = \ platform.h \ port-forwarding.h \ ptrarray.h \ - ratecontrol.h \ resume.h \ rpcimpl.h \ rpc-server.h \ diff --git a/libtransmission/bandwidth.h b/libtransmission/bandwidth.h index e82b17c30..151f0d8e7 100644 --- a/libtransmission/bandwidth.h +++ b/libtransmission/bandwidth.h @@ -17,6 +17,8 @@ #ifndef TR_BANDWIDTH_H #define TR_BANDWIDTH_H +#include + #include "transmission.h" #include "ptrarray.h" #include "utils.h" /* tr_new(), tr_free() */ diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index e8bff23c1..b7bd7d5bc 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -378,20 +378,27 @@ peerIsInUse( const Torrent * ct, const struct peer_atom * atom ) || getExistingHandshake( &t->manager->incomingHandshakes, &atom->addr ); } -static tr_peer* -peerNew( struct peer_atom * atom ) +void +tr_peerConstruct( tr_peer * peer ) { - tr_peer * peer = tr_new0( tr_peer, 1 ); + memset( peer, 0, sizeof( tr_peer ) ); peer->have = TR_BITSET_INIT; - peer->atom = atom; - atom->peer = peer; - tr_historyConstruct( &peer->blocksSentToClient, CANCEL_HISTORY_SEC, ( RECHOKE_PERIOD_MSEC / 1000 ) ); tr_historyConstruct( &peer->blocksSentToPeer, CANCEL_HISTORY_SEC, ( RECHOKE_PERIOD_MSEC / 1000 ) ); tr_historyConstruct( &peer->cancelsSentToClient, CANCEL_HISTORY_SEC, ( RECHOKE_PERIOD_MSEC / 1000 ) ); tr_historyConstruct( &peer->cancelsSentToPeer, CANCEL_HISTORY_SEC, ( REFILL_UPKEEP_PERIOD_MSEC / 1000 ) ); +} + +static tr_peer* +peerNew( struct peer_atom * atom ) +{ + tr_peer * peer = tr_new( tr_peer, 1 ); + tr_peerConstruct( peer ); + + peer->atom = atom; + atom->peer = peer; return peer; } @@ -416,18 +423,20 @@ getPeer( Torrent * torrent, struct peer_atom * atom ) static void peerDeclinedAllRequests( Torrent *, const tr_peer * ); -static void -peerDelete( Torrent * t, tr_peer * peer ) +void +tr_peerDestruct( tr_torrent * tor, tr_peer * peer ) { assert( peer != NULL ); - peerDeclinedAllRequests( t, peer ); + peerDeclinedAllRequests( tor->torrentPeers, peer ); if( peer->msgs != NULL ) tr_peerMsgsFree( peer->msgs ); - tr_peerIoClear( peer->io ); - tr_peerIoUnref( peer->io ); /* balanced by the ref in handshakeDoneCB() */ + if( peer->io ) { + tr_peerIoClear( peer->io ); + tr_peerIoUnref( peer->io ); /* balanced by the ref in handshakeDoneCB() */ + } tr_historyDestruct( &peer->blocksSentToClient ); tr_historyDestruct( &peer->blocksSentToPeer ); @@ -438,7 +447,12 @@ peerDelete( Torrent * t, tr_peer * peer ) tr_bitfieldFree( peer->blame ); tr_free( peer->client ); peer->atom->peer = NULL; +} +static void +peerDelete( Torrent * t, tr_peer * peer ) +{ + tr_peerDestruct( t->tor, peer ); tr_free( peer ); } @@ -2457,7 +2471,7 @@ tr_peerUpdateProgress( tr_torrent * tor, tr_peer * peer ) peer->progress = trueCount / ( have->bitfield.bitCount + 1 ); } - if( peer->progress >= 1.0 ) + if( peer->atom && ( peer->progress >= 1.0 ) ) atomSetSeed( tor->torrentPeers, peer->atom ); } @@ -2580,25 +2594,6 @@ tr_peerMgrTorrentStats( tr_torrent * tor, *setmeWebseedsSendingToUs = countActiveWebseeds( t ); } -int -tr_peerMgrGetWebseedSpeed_Bps( const tr_torrent * tor, uint64_t now ) -{ - int i; - int tmp; - int ret = 0; - - const Torrent * t = tor->torrentPeers; - const int n = tr_ptrArraySize( &t->webseeds ); - const tr_webseed ** webseeds = (const tr_webseed**) tr_ptrArrayBase( &t->webseeds ); - - for( i=0; i /* memset */ - -#include "transmission.h" -#include "platform.h" -#include "ratecontrol.h" -#include "utils.h" - -/* return the xfer rate over the last `interval' seconds in KiB/sec */ -static int -rateForInterval( const tr_ratecontrol * r, - int interval_msec, - uint64_t now ) -{ - uint64_t bytes = 0; - const uint64_t cutoff = (now?now:tr_time_msec()) - interval_msec; - int i = r->newest; - - for( ; ; ) - { - if( r->transfers[i].date <= cutoff ) - break; - - bytes += r->transfers[i].size; - - if( --i == -1 ) i = TR_RC_HISTORY_SIZE - 1; /* circular history */ - if( i == r->newest ) break; /* we've come all the way around */ - } - - return bytes * ( 1000.0 / interval_msec ); -} - -/*** -**** -***/ - -int -tr_rcRate_Bps( const tr_ratecontrol * r, uint64_t now ) -{ - int ret = 0; - - if( r ) - ret = rateForInterval( r, TR_RC_HISTORY_MSEC, now ); - - return ret; -} - -/*** -**** -***/ - -void -tr_rcTransferred( tr_ratecontrol * r, size_t size ) -{ - const uint64_t now = tr_time_msec ( ); - - if( r->transfers[r->newest].date + TR_RC_GRANULARITY_MSEC >= now ) - r->transfers[r->newest].size += size; - else - { - if( ++r->newest == TR_RC_HISTORY_SIZE ) r->newest = 0; - r->transfers[r->newest].date = now; - r->transfers[r->newest].size = size; - } -} diff --git a/libtransmission/ratecontrol.h b/libtransmission/ratecontrol.h deleted file mode 100644 index d34b40c71..000000000 --- a/libtransmission/ratecontrol.h +++ /dev/null @@ -1,77 +0,0 @@ -/****************************************************************************** - * $Id$ - * - * Copyright (c) Transmission authors and contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - *****************************************************************************/ - -#ifndef __TRANSMISSION__ -#error only libtransmission should #include this header. -#endif - -#ifndef _TR_RATECONTROL_H_ -#define _TR_RATECONTROL_H_ - -#include /* memset() */ - -#include "transmission.h" - -/* these are PRIVATE IMPLEMENTATION details that should not be touched. - * it's included in the header for inlining and composition. */ -enum -{ - TR_RC_HISTORY_MSEC = 2000, - TR_RC_GRANULARITY_MSEC = 250, - TR_RC_HISTORY_SIZE = ( TR_RC_HISTORY_MSEC / TR_RC_GRANULARITY_MSEC ) -}; - -/* these are PRIVATE IMPLEMENTATION details that should not be touched. - * it's included in the header for inlining and composition. */ -struct tr_transfer -{ - uint64_t date; - uint64_t size; -}; - -/* these are PRIVATE IMPLEMENTATION details that should not be touched. - * it's included in the header for inlining and composition. */ -typedef struct tr_ratecontrol -{ - int newest; - struct tr_transfer transfers[TR_RC_HISTORY_SIZE]; -} -tr_ratecontrol; - -/*** -**** -***/ - -static inline void tr_rcConstruct ( tr_ratecontrol * rc ) { memset( rc, 0, sizeof( tr_ratecontrol ) ); } - -static inline void tr_rcDestruct ( tr_ratecontrol * rc ) { memset( rc, 0xDEAD, sizeof( tr_ratecontrol ) ); } - -void tr_rcTransferred ( tr_ratecontrol * ratecontrol, - size_t byteCount ); - -int tr_rcRate_Bps ( const tr_ratecontrol * ratecontrol, - uint64_t now ); - - -#endif diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index d88f4b710..42b603be0 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -1138,7 +1138,6 @@ tr_torrentStat( tr_torrent * tor ) tr_stat * s; int usableSeeds; uint64_t now; - double d; uint64_t seedRatioBytesLeft; uint64_t seedRatioBytesGoal; tr_bool seedRatioApplies; @@ -1170,11 +1169,10 @@ tr_torrentStat( tr_torrent * tor ) s->peersFrom ); now = tr_time_msec( ); - d = tr_peerMgrGetWebseedSpeed_Bps( tor, now ); s->rawUploadSpeed_KBps = toSpeedKBps( tr_bandwidthGetRawSpeed_Bps ( tor->bandwidth, now, TR_UP ) ); s->pieceUploadSpeed_KBps = toSpeedKBps( tr_bandwidthGetPieceSpeed_Bps( tor->bandwidth, now, TR_UP ) ); - s->rawDownloadSpeed_KBps = toSpeedKBps( d + tr_bandwidthGetRawSpeed_Bps ( tor->bandwidth, now, TR_DOWN ) ); - s->pieceDownloadSpeed_KBps = toSpeedKBps( d + tr_bandwidthGetPieceSpeed_Bps( tor->bandwidth, now, TR_DOWN ) ); + s->rawDownloadSpeed_KBps = toSpeedKBps( tr_bandwidthGetRawSpeed_Bps ( tor->bandwidth, now, TR_DOWN ) ); + s->pieceDownloadSpeed_KBps = toSpeedKBps( tr_bandwidthGetPieceSpeed_Bps( tor->bandwidth, now, TR_DOWN ) ); usableSeeds += tor->info.webseedCount; diff --git a/libtransmission/webseed.c b/libtransmission/webseed.c index 45e296040..d73397d80 100644 --- a/libtransmission/webseed.c +++ b/libtransmission/webseed.c @@ -16,10 +16,10 @@ #include #include "transmission.h" +#include "bandwidth.h" #include "cache.h" #include "inout.h" /* tr_ioFindFileLocation() */ #include "list.h" -#include "ratecontrol.h" #include "peer-mgr.h" #include "torrent.h" #include "utils.h" @@ -41,7 +41,7 @@ struct tr_webseed_task struct tr_webseed { tr_peer parent; - tr_ratecontrol download_rate; + tr_bandwidth bandwidth; tr_session * session; tr_peer_callback * callback; void * callback_data; @@ -64,12 +64,16 @@ enum static void webseed_free( struct tr_webseed * w ) { - tr_bitsetDestruct( &w->parent.have ); - tr_free( w->parent.client ); + tr_torrent * tor = tr_torrentFindFromId( w->session, w->torrent_id ); + /* webseed destruct */ event_free( w->timer ); - tr_rcDestruct( &w->download_rate ); + tr_bandwidthDestruct( &w->bandwidth ); tr_free( w->base_url ); + + /* parent class destruct */ + tr_peerDestruct( tor, &w->parent ); + tr_free( w ); } @@ -125,7 +129,7 @@ on_content_changed( struct evbuffer * buf UNUSED, if( ( info->n_added > 0 ) && !w->is_stopping ) { - tr_rcTransferred( &w->download_rate, info->n_added ); + tr_bandwidthUsed( &w->bandwidth, TR_DOWN, info->n_added, TRUE, tr_time_msec( ) ); fire_client_got_data( w, info->n_added ); } } @@ -296,7 +300,7 @@ tr_bool tr_webseedGetSpeed_Bps( const tr_webseed * w, uint64_t now, int * setme_Bps ) { const tr_bool is_active = webseed_has_tasks( w ); - *setme_Bps = is_active ? tr_rcRate_Bps( &w->download_rate, now ) : 0; + *setme_Bps = is_active ? tr_bandwidthGetPieceSpeed_Bps( &w->bandwidth, now, TR_DOWN ) : 0; return is_active; } @@ -320,29 +324,30 @@ webseed_timer_func( evutil_socket_t foo UNUSED, short bar UNUSED, void * vw ) } tr_webseed* -tr_webseedNew( struct tr_torrent * tor, - const char * url, - tr_peer_callback * callback, - void * callback_data ) +tr_webseedNew( struct tr_torrent * tor, + const char * url, + tr_peer_callback * callback, + void * callback_data ) { tr_webseed * w = tr_new0( tr_webseed, 1 ); tr_peer * peer = &w->parent; + /* construct parent class */ + tr_peerConstruct( peer ); peer->peerIsChoked = TRUE; peer->clientIsInterested = !tr_torrentIsSeed( tor ); - peer->progress = 1.0; peer->client = tr_strdup( "webseed" ); - peer->have = TR_BITSET_INIT; tr_bitsetSetHaveAll( &peer->have ); + tr_peerUpdateProgress( tor, peer ); w->torrent_id = tr_torrentId( tor ); w->session = tor->session; - w->base_url_len = strlen( url ); w->base_url = tr_strndup( url, w->base_url_len ); w->callback = callback; w->callback_data = callback_data; - tr_rcConstruct( &w->download_rate ); + //tr_rcConstruct( &w->download_rate ); + tr_bandwidthConstruct( &w->bandwidth, tor->session, tor->bandwidth ); w->timer = evtimer_new( w->session->event_base, webseed_timer_func, w ); tr_timerAddMsec( w->timer, TR_IDLE_TIMER_MSEC ); return w;