(trunk libT) #2922 "announce's 'download' field should follow the de facto standard" -- added to trunk for 1.91

This commit is contained in:
Charles Kerr 2010-02-20 15:36:25 +00:00
parent c4dbf9f8be
commit a973e38bb5
3 changed files with 45 additions and 54 deletions

View File

@ -1034,25 +1034,6 @@ tr_announcerAddBytes( tr_torrent * tor, int type, uint32_t byteCount )
}
}
void
tr_announcerSubtractBytes( tr_torrent * tor, int type, uint32_t byteCount )
{
int i, n;
tr_torrent_tiers * tiers;
assert( tr_isTorrent( tor ) );
assert( type==TR_ANN_UP || type==TR_ANN_DOWN || type==TR_ANN_CORRUPT );
tiers = tor->tiers;
n = tr_ptrArraySize( &tiers->tiers );
for( i=0; i<n; ++i )
{
tr_tier * tier = tr_ptrArrayNth( &tiers->tiers, i );
uint64_t * setme = &tier->byteCounts[type];
*setme -= MIN( *setme, byteCount );
}
}
/***
****
***/
@ -1514,22 +1495,42 @@ getNextAnnounceEvent( tr_tier * tier )
assert( tier != NULL );
assert( tr_isTorrent( tier->tor ) );
/* rule #1: if "stopped" is in the queue, ignore everything before it */
/* special case #1: if "stopped" is in the queue, ignore everything before it */
events = (char**) tr_ptrArrayPeek( &tier->announceEvents, &n );
for( i=0; pos<0 && i<n; ++i )
if( !strcmp( events[i], "stopped" ) )
if( pos == -1 ) {
for( i=0; i<n; ++i )
if( !strcmp( events[i], "stopped" ) )
break;
if( i < n )
pos = i;
}
/* rule #2: if the next two events are the same, ignore the first one */
for( i=0; pos<0 && i<=n-2; ++i )
if( strcmp( events[i], events[i+1] ) )
/* special case #2: don't use empty strings if something follows them */
if( pos == -1 ) {
for( i = 0; i < n; ++i )
if( *events[i] )
break;
if( i < n )
pos = i;
}
/* otherwise use the next announce event in line */
if( ( pos < 0 ) && ( n > 0 ) )
/* default: use the next in the queue */
if( ( pos == -1 ) && ( n > 0 ) )
pos = 0;
/* rule #3: BEP 21: "In order to tell the tracker that a peer is a
/* special case #3: if there are duplicate requests in a row, skip to the last one */
if( pos >= 0 ) {
for( i=pos+1; i<n; ++i )
if( events[pos] != events[i] )
break;
pos = i - 1;
}
for( i=0; i<n; ++i ) fprintf( stderr, "(%d)\"%s\" ", i, events[i] );
fprintf( stderr, "\n" );
fprintf( stderr, "using (%d)\"%s\"\n", pos, events[pos] );
/* special case #4: BEP 21: "In order to tell the tracker that a peer is a
* partial seed, it MUST send an event=paused parameter in every
* announce while it is a partial seed." */
str = pos>=0 ? events[pos] : NULL;

View File

@ -93,7 +93,6 @@ void tr_announcerTorrentCompleted( tr_torrent * );
enum { TR_ANN_UP, TR_ANN_DOWN, TR_ANN_CORRUPT };
void tr_announcerAddBytes( tr_torrent *, int up_down_or_corrupt, uint32_t byteCount );
void tr_announcerSubtractBytes( tr_torrent *, int up_down_or_corrupt, uint32_t byteCount );
time_t tr_announcerNextManualAnnounce( const tr_torrent * );

View File

@ -1186,7 +1186,6 @@ gotBadPiece( Torrent * t, tr_piece_index_t pieceIndex )
tor->downloadedCur -= MIN( tor->downloadedCur, byteCount );
tr_announcerAddBytes( tor, TR_ANN_CORRUPT, byteCount );
tr_announcerSubtractBytes( tor, TR_ANN_DOWN, byteCount );
}
static void
@ -1237,19 +1236,6 @@ peerSuggestedPiece( Torrent * t UNUSED,
#endif
}
static void
decrementDownloadedCount( tr_torrent * tor, uint32_t byteCount )
{
tor->downloadedCur -= MIN( tor->downloadedCur, byteCount );
tr_announcerSubtractBytes( tor, TR_ANN_DOWN, byteCount );
}
static void
clientGotUnwantedBlock( tr_torrent * tor, tr_block_index_t block )
{
decrementDownloadedCount( tor, tr_torBlockCountBytes( tor, block ) );
}
static void
removeRequestFromTables( Torrent * t, tr_block_index_t block, const tr_peer * peer )
{
@ -1355,15 +1341,8 @@ peerCallbackFunc( void * vpeer, void * vevent, void * vt )
tr_torrentSetActivityDate( tor, now );
/* only add this to downloadedCur if we got it from a peer --
* webseeds shouldn't count against our ratio. As one tracker
* admin put it, "Those pieces are downloaded directly from the
* content distributor, not the peers, it is the tracker's job
* to manage the swarms, not the web server and does not fit
* into the jurisdiction of the tracker." */
if( peer && e->wasPieceData ) {
if( e->wasPieceData ) {
tor->downloadedCur += e->length;
tr_announcerAddBytes( tor, TR_ANN_DOWN, e->length );
tr_torrentSetDirty( tor );
}
@ -1398,17 +1377,18 @@ peerCallbackFunc( void * vpeer, void * vevent, void * vt )
tr_block_index_t block = _tr_block( tor, e->pieceIndex, e->offset );
requestListRemove( t, block, peer );
pieceListRemoveRequest( t, block );
if( tr_cpBlockIsComplete( &tor->completion, block ) )
{
/* we already have this block... */
const uint32_t n = tr_torBlockCountBytes( tor, block );
tor->downloadedCur -= MIN( tor->downloadedCur, n );
tordbg( t, "we have this block already..." );
clientGotUnwantedBlock( tor, block );
pieceListRemoveRequest( t, block );
}
else
{
tr_cpBlockAdd( &tor->completion, block );
pieceListRemoveRequest( t, block );
tr_torrentSetDirty( tor );
if( tr_cpPieceIsComplete( &tor->completion, e->pieceIndex ) )
@ -1437,6 +1417,17 @@ peerCallbackFunc( void * vpeer, void * vevent, void * vt )
tr_peer ** peers;
tr_file_index_t fileIndex;
/* only add this to downloadedCur if we got it from a peer --
* webseeds shouldn't count against our ratio. As one tracker
* admin put it, "Those pieces are downloaded directly from the
* content distributor, not the peers, it is the tracker's job
* to manage the swarms, not the web server and does not fit
* into the jurisdiction of the tracker." */
if( peer != NULL ) {
const uint32_t n = tr_torPieceCountBytes( tor, p );
tr_announcerAddBytes( tor, TR_ANN_DOWN, n );
}
peerCount = tr_ptrArraySize( &t->peers );
peers = (tr_peer**) tr_ptrArrayBase( &t->peers );
for( i=0; i<peerCount; ++i )