Skip to content

Commit

Permalink
Add session settings "multiscrape-maximum" and "concurrent-announces-…
Browse files Browse the repository at this point in the history
…maximum" to settings.json.

Fixes https://trac.transmissionbt.com/ticket/6126 (reduce TR_MULTISCRAPE_MAX)
and   https://trac.transmissionbt.com/ticket/6127 (announcer slots are not properly accounted for)
  • Loading branch information
cfpp2p committed May 23, 2016
1 parent a059515 commit 83bca0a
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 26 deletions.
24 changes: 6 additions & 18 deletions libtransmission/announcer.c
Expand Up @@ -132,23 +132,8 @@ compareStops( const void * va, const void * vb )
****
***/

/**
* "global" (per-tr_session) fields
*/
typedef struct tr_announcer
{
tr_ptrArray stops; /* tr_announce_request */

tr_session * session;
struct event * upkeepTimer;
int slotsAvailable;
int key;
time_t tauUpkeepAt;
}
tr_announcer;

bool
tr_announcerHasBacklog( const struct tr_announcer * announcer )
tr_announcerHasBacklog( const tr_announcer * announcer )
{
return announcer->slotsAvailable < 1;
}
Expand Down Expand Up @@ -1531,7 +1516,7 @@ multiscrape( tr_announcer * announcer, tr_ptrArray * tiers )
{
tr_scrape_request * req = &requests[j];

if( req->info_hash_count >= TR_MULTISCRAPE_MAX )
if( req->info_hash_count >= announcer->session->maxMultiscrape )
continue;
if( tr_strcmp0( req->url, url ) )
continue;
Expand All @@ -1556,8 +1541,11 @@ multiscrape( tr_announcer * announcer, tr_ptrArray * tiers )
}

/* send the requests we just built */
for( i=0; i<request_count; ++i )
for( i=0; i<request_count; ++i ) {
if( announcer->session->maxConcurrentAnnounces >= 0 )
--announcer->slotsAvailable;
scrape_request_delegate( announcer, &requests[i], on_scrape_done, announcer->session );
}

/* cleanup */
tr_free( requests );
Expand Down
25 changes: 21 additions & 4 deletions libtransmission/announcer.h
Expand Up @@ -17,9 +17,26 @@
#ifndef _TR_ANNOUNCER_H_
#define _TR_ANNOUNCER_H_

#include <event2/event.h> /* evtimer */

#include "transmission.h"
#include "ptrarray.h"

/**
* "global" (per-tr_session) fields
*/
typedef struct tr_announcer
{
tr_ptrArray stops; /* tr_announce_request */

tr_session * session;
struct event * upkeepTimer;
int slotsAvailable;
int key;
time_t tauUpkeepAt;
}
tr_announcer;

struct tr_announcer;
struct tr_torrent_tiers;

/**
Expand Down Expand Up @@ -76,11 +93,11 @@ struct tr_torrent_tiers * tr_announcerAddTorrent( tr_torrent * torrent,
tr_tracker_callback * cb,
void * cbdata );

bool tr_announcerHasBacklog( const struct tr_announcer * );
bool tr_announcerHasBacklog( const tr_announcer * );

void tr_announcerResetTorrent( struct tr_announcer*, tr_torrent* );
void tr_announcerResetTorrent( tr_announcer*, tr_torrent* );

void tr_announcerRemoveTorrent( struct tr_announcer * ,
void tr_announcerRemoveTorrent( tr_announcer * ,
tr_torrent * );

void tr_announcerChangeMyPort( tr_torrent * );
Expand Down
6 changes: 6 additions & 0 deletions libtransmission/rpcimpl.c
Expand Up @@ -1787,6 +1787,10 @@ sessionSet( tr_session * session,
tr_sessionSetMaxMagnetBadPiece( session, i );
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_REDIRECT_MAXIMUM, &i ) )
tr_sessionSetMaxRedirect( session, i );
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_MULTISCRAPE_MAXIMUM, &i ) )
tr_sessionSetMaxMultiscrape( session, i );
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_CONCURRENT_ANNOUNCE_MAXIMUM, &i ) )
tr_sessionSetMaxConcurrentAnnounces( session, i );

notify( session, TR_RPC_SESSION_CHANGED, NULL );

Expand Down Expand Up @@ -1928,6 +1932,8 @@ sessionGet( tr_session * s,
tr_bencDictAddStr ( d, TR_PREFS_KEY_USER_AGENT, tr_sessionGetUserAgent( s ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_MAGNET_BAD_PIECE_MAX, tr_sessionGetMaxMagnetBadPiece( s ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_REDIRECT_MAXIMUM, tr_sessionGetMaxRedirect( s ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_MULTISCRAPE_MAXIMUM, tr_sessionGetMaxMultiscrape( s ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_CONCURRENT_ANNOUNCE_MAXIMUM, tr_sessionGetMaxConcurrentAnnounces( s ) );

return NULL;
}
Expand Down
49 changes: 47 additions & 2 deletions libtransmission/session.c
Expand Up @@ -367,7 +367,7 @@ tr_sessionGetDefaultSettings( tr_benc * d )

assert( tr_bencIsDict( d ) );

tr_bencDictReserve( d, 88);
tr_bencDictReserve( d, 90);
tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, false );
tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_WEBSEEDS, false );
tr_bencDictAddBool( d, TR_PREFS_KEY_IPV6_ENABLED, false );
Expand Down Expand Up @@ -452,6 +452,8 @@ tr_sessionGetDefaultSettings( tr_benc * d )
tr_bencDictAddStr ( d, TR_PREFS_KEY_USER_AGENT, "" );
tr_bencDictAddInt ( d, TR_PREFS_KEY_MAGNET_BAD_PIECE_MAX, 25 );
tr_bencDictAddInt ( d, TR_PREFS_KEY_REDIRECT_MAXIMUM, 16 );
tr_bencDictAddInt ( d, TR_PREFS_KEY_MULTISCRAPE_MAXIMUM, 64 );
tr_bencDictAddInt ( d, TR_PREFS_KEY_CONCURRENT_ANNOUNCE_MAXIMUM, 48 );

tr_bencDictAddStr (d, TR_PREFS_KEY_DOWNLOAD_GROUP_DEFAULT, tr_getDefaultDownloadGroupDefault ());
knownGroups = tr_getDefaultDownloadGroups ();
Expand All @@ -467,7 +469,7 @@ tr_sessionGetSettings( tr_session * s, struct tr_benc * d )

assert( tr_bencIsDict( d ) );

tr_bencDictReserve( d, 87 );
tr_bencDictReserve( d, 89 );
tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, tr_blocklistIsEnabled( s ) );
tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_WEBSEEDS, s->blockListWebseeds );
tr_bencDictAddBool( d, TR_PREFS_KEY_IPV6_ENABLED, s->ipv6Enabled );
Expand Down Expand Up @@ -551,6 +553,8 @@ tr_sessionGetSettings( tr_session * s, struct tr_benc * d )
tr_bencDictAddStr ( d, TR_PREFS_KEY_USER_AGENT, tr_sessionGetUserAgent( s ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_MAGNET_BAD_PIECE_MAX, s->maxMagnetBadPiece );
tr_bencDictAddInt ( d, TR_PREFS_KEY_REDIRECT_MAXIMUM, s->maxRedirect );
tr_bencDictAddInt ( d, TR_PREFS_KEY_MULTISCRAPE_MAXIMUM, s->maxMultiscrape );
tr_bencDictAddInt ( d, TR_PREFS_KEY_CONCURRENT_ANNOUNCE_MAXIMUM, s->maxConcurrentAnnounces );

tr_bencDictAddStr (d, TR_PREFS_KEY_DOWNLOAD_GROUP_DEFAULT, tr_sessionGetDownloadGroupDefault (s));
knownGroups = tr_sessionGetDownloadGroups (s);
Expand Down Expand Up @@ -849,6 +853,9 @@ tr_sessionInitImpl( void * vdata )
if( session->isLPDEnabled )
tr_lpdInit( session, &session->public_ipv4->addr );

if( session->maxConcurrentAnnounces >= 0 )
session->announcer->slotsAvailable = session->maxConcurrentAnnounces;

/* cleanup */
tr_bencFree( &settings );
data->done = true;
Expand Down Expand Up @@ -945,6 +952,10 @@ sessionSetImpl( void * vdata )
tr_sessionSetUserAgent( session, str );
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_REDIRECT_MAXIMUM, &i ) )
session->maxRedirect = ( i >= 0 ) ? i : -1 ;
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_MULTISCRAPE_MAXIMUM, &i ) )
session->maxMultiscrape = ( ( i >= 0 ) && ( i < 65 ) ) ? i : 64 ;
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_CONCURRENT_ANNOUNCE_MAXIMUM, &i ) )
session->maxConcurrentAnnounces = ( i >= 0 ) ? i : -1 ;

if (tr_bencDictFindList (settings, TR_PREFS_KEY_DOWNLOAD_GROUPS, &groups))
{
Expand Down Expand Up @@ -3185,6 +3196,40 @@ tr_sessionGetMaxRedirect( const tr_session * session )
return session->maxRedirect;
}

void
tr_sessionSetMaxMultiscrape( tr_session * session, int maxMultiscrape )
{
assert( tr_isSession( session ) );
if( ( maxMultiscrape >= 0 ) && ( maxMultiscrape < 65 ) )
session->maxMultiscrape = maxMultiscrape;

}

int
tr_sessionGetMaxMultiscrape( const tr_session * session )
{
assert( tr_isSession( session ) );

return session->maxMultiscrape;
}

void
tr_sessionSetMaxConcurrentAnnounces( tr_session * session, int maxConcurrentAnnounces )
{
assert( tr_isSession( session ) );
if( maxConcurrentAnnounces >= -1 )
session->maxConcurrentAnnounces = maxConcurrentAnnounces;

}

int
tr_sessionGetMaxConcurrentAnnounces( const tr_session * session )
{
assert( tr_isSession( session ) );

return session->maxConcurrentAnnounces;
}

/****
*****
****/
Expand Down
4 changes: 3 additions & 1 deletion libtransmission/session.h
Expand Up @@ -27,6 +27,7 @@
#endif
#endif

#include "announcer.h"
#include "bandwidth.h"
#include "bencode.h"
#include "bitfield.h"
Expand All @@ -53,7 +54,6 @@ struct event_base;
struct evdns_base;

struct tr_address;
struct tr_announcer;
struct tr_announcer_udp;
struct tr_bindsockets;
struct tr_cache;
Expand Down Expand Up @@ -136,6 +136,8 @@ struct tr_session
int webseedTimeout;

int maxRedirect;
int maxMultiscrape;
int maxConcurrentAnnounces;

tr_benc removedTorrents;

Expand Down
10 changes: 9 additions & 1 deletion libtransmission/transmission.h
@@ -1,5 +1,5 @@
/******************************************************************************
* $Id: transmission.h 14485 2015-05-01 14:29:33Z livings124 $
* $Id: transmission.h 14734 2016-05-22 14:05:11Z livings124 $
*
* Copyright (c) Transmission authors and contributors
*
Expand Down Expand Up @@ -252,6 +252,8 @@ const char* tr_getDefaultDownloadGroupDefault (void);
#define TR_PREFS_KEY_WEBSEED_TIMEOUT_VALUE "webseed-timeout-seconds"
#define TR_PREFS_KEY_MAGNET_BAD_PIECE_MAX "magnet-bad-piece-max"
#define TR_PREFS_KEY_REDIRECT_MAXIMUM "redirect-maximum"
#define TR_PREFS_KEY_MULTISCRAPE_MAXIMUM "multiscrape-maximum"
#define TR_PREFS_KEY_CONCURRENT_ANNOUNCE_MAXIMUM "concurrent-announces-maximum"


/**
Expand Down Expand Up @@ -982,6 +984,12 @@ void tr_sessionSetUserAgent( tr_session *, const char * userAgent );
void tr_sessionSetMaxRedirect( tr_session *, int maxRedirect );
int tr_sessionGetMaxRedirect( const tr_session * );

void tr_sessionSetMaxMultiscrape( tr_session *, int maxMultiscrape );
int tr_sessionGetMaxMultiscrape( const tr_session * );

void tr_sessionSetMaxConcurrentAnnounces( tr_session *, int maxConcurrentAnnounces );
int tr_sessionGetMaxConcurrentAnnounces( const tr_session * );

/**
***
**/
Expand Down

0 comments on commit 83bca0a

Please sign in to comment.