(trunk) #2222: Make DHT support a compile-time option, enabled by default

This commit is contained in:
Charles Kerr 2009-06-21 08:57:26 +00:00
parent 587ddb48f0
commit 39330501e4
8 changed files with 72 additions and 8 deletions

View File

@ -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}

View File

@ -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 );

View File

@ -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;

View File

@ -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 )
{

View File

@ -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 );

View File

@ -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 );
}

View File

@ -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

View File

@ -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