(trunk libT) remove the unused tr_ratecontrol code. switch webseed over to using tr_bandwidth.
This commit is contained in:
parent
6d94a33f2d
commit
0c36e0c9de
|
@ -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 \
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#ifndef TR_BANDWIDTH_H
|
||||
#define TR_BANDWIDTH_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "transmission.h"
|
||||
#include "ptrarray.h"
|
||||
#include "utils.h" /* tr_new(), tr_free() */
|
||||
|
|
|
@ -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<n; ++i )
|
||||
if( tr_webseedGetSpeed_Bps( webseeds[i], now, &tmp ) )
|
||||
ret += tmp;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
double*
|
||||
tr_peerMgrWebSpeeds_KBps( const tr_torrent * tor )
|
||||
{
|
||||
|
|
|
@ -68,7 +68,6 @@ typedef struct tr_pex
|
|||
tr_pex;
|
||||
|
||||
|
||||
struct tr_bandwidth;
|
||||
struct tr_peerIo;
|
||||
struct tr_peermsgs;
|
||||
|
||||
|
@ -132,6 +131,11 @@ typedef struct tr_peer
|
|||
}
|
||||
tr_peer;
|
||||
|
||||
void tr_peerConstruct( struct tr_peer * peer );
|
||||
|
||||
void tr_peerDestruct( tr_torrent * tor, struct tr_peer * peer );
|
||||
|
||||
|
||||
static inline tr_bool
|
||||
tr_isPex( const tr_pex * pex )
|
||||
{
|
||||
|
@ -247,8 +251,6 @@ void tr_peerMgrTorrentStats( tr_torrent * tor,
|
|||
struct tr_peer_stat* tr_peerMgrPeerStats( const tr_torrent * tor,
|
||||
int * setmeCount );
|
||||
|
||||
int tr_peerMgrGetWebseedSpeed_Bps( const tr_torrent * tor, uint64_t now );
|
||||
|
||||
double* tr_peerMgrWebSpeeds_KBps( const tr_torrent * tor );
|
||||
|
||||
|
||||
|
|
|
@ -1,88 +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.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <string.h> /* 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;
|
||||
}
|
||||
}
|
|
@ -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 <string.h> /* 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
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
#include <event2/event.h>
|
||||
|
||||
#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;
|
||||
|
|
Loading…
Reference in New Issue