From 39330501e426a340ef2c3a6dc77ee0f89fbb280c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 21 Jun 2009 08:57:26 +0000 Subject: [PATCH] (trunk) #2222: Make DHT support a compile-time option, enabled by default --- configure.ac | 17 +++++++++++++++-- gtk/tr-prefs.c | 2 ++ libtransmission/handshake.c | 2 +- libtransmission/session.c | 18 +++++++++++++++++- libtransmission/session.h | 2 ++ libtransmission/torrent.h | 11 ++++++++--- libtransmission/tr-dht.c | 21 +++++++++++++++++++++ third-party/Makefile.am | 7 ++++++- 8 files changed, 72 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index d10cff859..de029ef78 100644 --- a/configure.ac +++ b/configure.ac @@ -195,8 +195,20 @@ dnl ---------------------------------------------------------------------------- dnl dnl dht -DHT_CFLAGS="-I\$(top_srcdir)/third-party/dht" -DHT_LIBS="\$(top_builddir)/third-party/dht/libdht.a" + +AC_ARG_ENABLE([dht], + AS_HELP_STRING([--disable-dht],[omit DHT support]), + [enable_dht=${enableval}], + [enable_dht=yes]) +if test "x$enable_dht" = "xno" ; then + AC_DEFINE([WITHOUT_DHT], 1) + DHT_CFLAGS="" + DHT_LIBS="" +else + DHT_CFLAGS="-I\$(top_srcdir)/third-party/dht" + DHT_LIBS="\$(top_builddir)/third-party/dht/libdht.a" +fi +AM_CONDITIONAL(DHT, test "x$enable_dht" = "xyes") AC_SUBST(DHT_CFLAGS) AC_SUBST(DHT_LIBS) @@ -397,6 +409,7 @@ Configuration: Source code location: ${srcdir} Compiler: ${CXX} System or bundled libevent: ${libevent_source} + DHT support: ${enable_dht} Build OS X client: ${build_mac} Build GTK+ client: ${build_gtk} diff --git a/gtk/tr-prefs.c b/gtk/tr-prefs.c index b56ffe54e..bd9428aaa 100644 --- a/gtk/tr-prefs.c +++ b/gtk/tr-prefs.c @@ -544,11 +544,13 @@ peerPage( GObject * core ) gtr_widget_set_tooltip_text( w, s ); hig_workarea_add_wide_control( t, &row, w ); +#ifndef WITHOUT_DHT s = _( "Use _DHT to find more peers" ); w = new_check_button( s, TR_PREFS_KEY_DHT_ENABLED, core ); s = _( "DHT is a tool for finding peers without a tracker." ); gtr_widget_set_tooltip_text( w, s ); hig_workarea_add_wide_control( t, &row, w ); +#endif hig_workarea_finish( t, &row ); g_object_weak_ref( G_OBJECT( t ), peerPageDestroyed, data ); diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index baeb145d8..ca261374d 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -313,7 +313,7 @@ parseHandshake( tr_handshake * handshake, tr_peerIoEnableFEXT( handshake->io, HANDSHAKE_HAS_FASTEXT( reserved ) ); /* This doesn't depend on whether the torrent is private. */ - if( tor && tor->session->isDHTEnabled ) + if( tor && tr_sessionAllowsDHT( tor->session ) ) tr_peerIoEnableDHT( handshake->io, HANDSHAKE_HAS_DHT( reserved ) ); return HANDSHAKE_OK; diff --git a/libtransmission/session.c b/libtransmission/session.c index e7f9fca7d..9e9d7e9e1 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -837,7 +837,13 @@ tr_sessionInitImpl( void * vdata ) dbgmsg( "returning session %p; session->tracker is %p", session, session->tracker ); if( session->isDHTEnabled ) - tr_dhtInit(session); + { +#ifdef WITHOUT_DHT + tr_inf( "DHT disabled by packager." ); +#else + tr_dhtInit( session ); +#endif + } } /*** @@ -1587,6 +1593,16 @@ tr_sessionIsPexEnabled( const tr_session * session ) return session->isPexEnabled; } +tr_bool +tr_sessionAllowsDHT( const tr_session * session UNUSED ) +{ +#ifdef WITHOUT_DHT + return 0; +#else + return tr_sessionIsDHTEnabled( session ); +#endif +} + tr_bool tr_sessionIsDHTEnabled( const tr_session * session ) { diff --git a/libtransmission/session.h b/libtransmission/session.h index 0837e648e..16cb46a41 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -138,6 +138,8 @@ struct tr_session struct tr_bindinfo * public_ipv6; }; +tr_bool tr_sessionAllowsDHT( const tr_session * session ); + tr_bool tr_sessionGetActiveSpeedLimit( const tr_session * session, tr_direction dir, int * setme ); diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index 3c32caad3..d290f9f79 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -288,15 +288,20 @@ static TR_INLINE tr_bool tr_torrentIsPrivate( const tr_torrent * tor ) static TR_INLINE tr_bool tr_torrentAllowsPex( const tr_torrent * tor ) { - return ( tor != NULL ) && tor->session->isPexEnabled && !tr_torrentIsPrivate( tor ); + return ( tor != NULL ) + && ( tor->session->isPexEnabled ) + && ( !tr_torrentIsPrivate( tor ) ); } static TR_INLINE tr_bool tr_torrentAllowsDHT( const tr_torrent * tor ) { - return ( tor != NULL ) && tor->session->isDHTEnabled && !tr_torrentIsPrivate( tor ); + return ( tor != NULL ) + && ( tr_sessionAllowsDHT( tor->session ) ) + && ( !tr_torrentIsPrivate( tor ) ); } -static TR_INLINE tr_bool tr_torrentIsPieceChecked( const tr_torrent * tor, tr_piece_index_t i ) +static TR_INLINE tr_bool tr_torrentIsPieceChecked( const tr_torrent * tor, + tr_piece_index_t i ) { return tr_bitfieldHasFast( &tor->checkedPieces, i ); } diff --git a/libtransmission/tr-dht.c b/libtransmission/tr-dht.c index be87c19e2..3df38f7eb 100644 --- a/libtransmission/tr-dht.c +++ b/libtransmission/tr-dht.c @@ -50,6 +50,25 @@ THE SOFTWARE. #include "utils.h" #include "version.h" +#ifdef WITHOUT_DHT + + /* These are the stubs for when we're building without DHT support */ + int tr_dhtInit( tr_session * session UNUSED ) { return TR_DHT_STOPPED; } + void tr_dhtUninit( tr_session * session UNUSED ) { } + tr_bool tr_dhtEnabled( const tr_session * session UNUSED ) { return FALSE; } + tr_port tr_dhtPort ( const tr_session * sesssion UNUSED ) { return 0; } + int tr_dhtStatus( tr_session * session UNUSED, + int * setmeCount UNUSED ) { return TR_DHT_STOPPED; } + int tr_dhtAddNode( tr_session * session UNUSED, + tr_address * addr UNUSED, + tr_port port UNUSED, + tr_bool bootstrap UNUSED ) { return 0; } + int tr_dhtAnnounce( tr_torrent * session UNUSED, + tr_bool announce UNUSED ) { return -1; } + + +#else + static int dht_socket; static struct event dht_event; static tr_port dht_port; @@ -392,3 +411,5 @@ dht_random_bytes( void * buf, size_t size ) tr_cryptoRandBuf( buf, size ); return size; } + +#endif diff --git a/third-party/Makefile.am b/third-party/Makefile.am index 241a1fa25..92958e97a 100644 --- a/third-party/Makefile.am +++ b/third-party/Makefile.am @@ -1,5 +1,10 @@ +if DHT + DHT_DIR = dht +else + DHT_DIR = +endif -SUBDIRS = libnatpmp miniupnp dht libevent +SUBDIRS = libnatpmp miniupnp libevent $(DHT_DIR) EXTRA_DIST = macosx-libevent-config.h -- 2.40.0