"start-added-torrents" | boolean | true means added torrents will be started right away
"trash-original-torrent-files" | boolean | true means the .torrent file of added torrents will be deleted
"units" | object | see below
+ "utp-enabled" | boolean | true means allow utp
"version" | string | long version string "$version ($revision)"
---------------------------------+------------+-----------------------------+
units | object containing: |
tr_sessionSetPexEnabled( session, boolVal );
if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_DHT_ENABLED, &boolVal ) )
tr_sessionSetDHTEnabled( session, boolVal );
+ if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_UTP_ENABLED, &boolVal ) )
+ tr_sessionSetUTPEnabled( session, boolVal );
if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_LPD_ENABLED, &boolVal ) )
tr_sessionSetLPDEnabled( session, boolVal );
if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, &boolVal ) )
tr_bencDictAddStr ( d, TR_PREFS_KEY_INCOMPLETE_DIR, tr_sessionGetIncompleteDir( s ) );
tr_bencDictAddBool( d, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, tr_sessionIsIncompleteDirEnabled( s ) );
tr_bencDictAddBool( d, TR_PREFS_KEY_PEX_ENABLED, tr_sessionIsPexEnabled( s ) );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_UTP_ENABLED, tr_sessionIsUTPEnabled( s ) );
tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED, tr_sessionIsDHTEnabled( s ) );
tr_bencDictAddBool( d, TR_PREFS_KEY_LPD_ENABLED, tr_sessionIsLPDEnabled( s ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT, tr_sessionGetPeerPort( s ) );
#include "stats.h"
#include "torrent.h"
#include "tr-udp.h"
+#include "tr-utp.h"
#include "tr-lpd.h"
#include "trevent.h"
#include "utils.h"
tr_bencDictAddStr ( d, TR_PREFS_KEY_BLOCKLIST_URL, "http://www.example.com/blocklist" );
tr_bencDictAddInt ( d, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, DEFAULT_CACHE_SIZE_MB );
tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED, TRUE );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_UTP_ENABLED, FALSE );
tr_bencDictAddBool( d, TR_PREFS_KEY_LPD_ENABLED, FALSE );
tr_bencDictAddStr ( d, TR_PREFS_KEY_DOWNLOAD_DIR, tr_getDefaultDownloadDir( ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_KBps, 100 );
tr_bencDictAddStr ( d, TR_PREFS_KEY_BLOCKLIST_URL, tr_blocklistGetURL( s ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, tr_sessionGetCacheLimit_MB( s ) );
tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED, s->isDHTEnabled );
+ tr_bencDictAddBool( d, TR_PREFS_KEY_UTP_ENABLED, s->isUTPEnabled );
tr_bencDictAddBool( d, TR_PREFS_KEY_LPD_ENABLED, s->isLPDEnabled );
tr_bencDictAddStr ( d, TR_PREFS_KEY_DOWNLOAD_DIR, s->downloadDir );
tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_KBps, tr_sessionGetSpeedLimit_KBps( s, TR_DOWN ) );
tr_sessionSetPexEnabled( session, boolVal );
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_DHT_ENABLED, &boolVal ) )
tr_sessionSetDHTEnabled( session, boolVal );
+ if( tr_bencDictFindBool( settings, TR_PREFS_KEY_UTP_ENABLED, &boolVal ) )
+ tr_sessionSetUTPEnabled( session, boolVal );
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_LPD_ENABLED, &boolVal ) )
tr_sessionSetLPDEnabled( session, boolVal );
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ENCRYPTION, &i ) )
if( session->isLPDEnabled )
tr_lpdUninit( session );
+ tr_utpClose( session );
tr_udpUninit( session );
event_free( session->saveTimer );
tr_runInEventThread( session, toggleDHTImpl, session );
}
+/***
+****
+***/
+
+tr_bool
+tr_sessionIsUTPEnabled( const tr_session * session )
+{
+ assert( tr_isSession( session ) );
+
+ return session->isUTPEnabled;
+}
+
+static void
+toggle_utp( void * data )
+{
+ tr_session * session = data;
+ assert( tr_isSession( session ) );
+
+ session->isUTPEnabled = !session->isUTPEnabled;
+
+ if( !session->isUTPEnabled )
+ tr_utpClose( session );
+}
+
+void
+tr_sessionSetUTPEnabled( tr_session * session, tr_bool enabled )
+{
+ assert( tr_isSession( session ) );
+ assert( tr_isBool( enabled ) );
+
+ if( ( enabled != 0 ) != ( session->isUTPEnabled != 0 ) )
+ tr_runInEventThread( session, toggle_utp, session );
+}
+
+/***
+****
+***/
+
static void
toggleLPDImpl( void * data )
{
tr_bool isPortRandom;
tr_bool isPexEnabled;
tr_bool isDHTEnabled;
+ tr_bool isUTPEnabled;
tr_bool isLPDEnabled;
tr_bool isBlocklistEnabled;
tr_bool isPrefetchEnabled;
if(rc <= 0)
return;
- if(buf[0] == 'd') {
+ if((buf[0] == 'd') && tr_sessionIsDHTEnabled(ss)) {
/* DHT packet. */
buf[rc] = '\0';
tr_dhtCallback(buf, rc, (struct sockaddr*)&from, fromlen, sv);
- } else {
+ } else if(tr_sessionIsDHTEnabled(ss)){
rc = tr_utpPacket(buf, rc, (struct sockaddr*)&from, fromlen, ss);
if(!rc)
tr_ndbg("UDP", "Unexpected UDP packet");
sendto(ss->udp6_socket, buf, buflen, 0, to, tolen);
}
+static void
+reset_timer( void )
+{
+ int sec = 0;
+ int usec = UTP_INTERVAL_US / 2 + tr_cryptoWeakRandInt(UTP_INTERVAL_US);
+ tr_timerAdd( utp_timer, sec, usec );
+}
+
static void
timer_callback(int s UNUSED, short type UNUSED, void *closure UNUSED)
{
UTP_CheckTimeouts();
- tr_timerAdd(utp_timer, 0,
- UTP_INTERVAL_US / 2 + tr_cryptoWeakRandInt(UTP_INTERVAL_US));
+ reset_timer();
}
int
const struct sockaddr *from, socklen_t fromlen,
tr_session *ss)
{
- if(utp_timer == NULL) {
- utp_timer = evtimer_new( ss->event_base, timer_callback, NULL);
+ if(utp_timer == NULL)
+ {
+ utp_timer = evtimer_new( ss->event_base, timer_callback, NULL );
if(utp_timer == NULL)
return -1;
- tr_timerAdd(utp_timer, 0,
- UTP_INTERVAL_US / 2 +
- tr_cryptoWeakRandInt(UTP_INTERVAL_US));
+ reset_timer();
}
return UTP_IsIncomingUTP(incoming, send_to, ss,
buf, buflen, from, fromlen);
}
-
+void
+tr_utpClose( tr_session * session )
+{
+ if( utp_timer )
+ {
+ evtimer_del( utp_timer );
+ utp_timer = NULL;
+ }
+}
int tr_utpPacket(const unsigned char *buf, size_t buflen,
const struct sockaddr *from, socklen_t fromlen,
tr_session *ss);
+
+void tr_utpClose( tr_session * );
#define TR_PREFS_KEY_BLOCKLIST_URL "blocklist-url"
#define TR_PREFS_KEY_MAX_CACHE_SIZE_MB "cache-size-mb"
#define TR_PREFS_KEY_DHT_ENABLED "dht-enabled"
+#define TR_PREFS_KEY_UTP_ENABLED "utp-enabled"
#define TR_PREFS_KEY_LPD_ENABLED "lpd-enabled"
#define TR_PREFS_KEY_PREFETCH_ENABLED "prefetch-enabled"
#define TR_PREFS_KEY_DOWNLOAD_DIR "download-dir"
tr_bool tr_sessionIsDHTEnabled( const tr_session * session );
void tr_sessionSetDHTEnabled( tr_session * session, tr_bool );
+tr_bool tr_sessionIsUTPEnabled( const tr_session * session );
+void tr_sessionSetUTPEnabled( tr_session * session, tr_bool );
+
tr_bool tr_sessionIsLPDEnabled( const tr_session * session );
void tr_sessionSetLPDEnabled( tr_session * session, tr_bool enabled );