Changeset 8433


Ignore:
Timestamp:
May 19, 2009, 6:38:26 PM (12 years ago)
Author:
charles
Message:

(trunk) #7: DHT support. This is a work in progress... no gui/rpc support yet

Location:
trunk
Files:
11 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/AUTHORS

    r8270 r8433  
    88Project Contributors
    99  Tomas Carnecky  (Profiling, patches, and detection of sneaky bugs)
     10  Juliusz Chroboczek  (DHT)
    1011  John Clay  (Website maintenance and troubleshooting)
    1112  Rashid Eissing  (Mac OS X Transfers preferences icon)
  • trunk/cli/Makefile.am

    r8152 r8433  
    2121    $(top_builddir)/third-party/libnatpmp/libnatpmp.a \
    2222    $(top_builddir)/third-party/miniupnp/libminiupnp.a \
     23    $(top_builddir)/third-party/dht/libdht.a \
    2324    $(INTLLIBS) \
    2425    $(LIBCURL_LIBS) \
  • trunk/configure.ac

    r8429 r8433  
    264264if test "x$enable_nls" = "xyes" ; then
    265265    use_nls=yes
    266     IT_PROG_INTLTOOL([0.40.0],[no-xml])
     266    IT_PROG_INTLTOOL([0.35],[no-xml])
    267267    AC_CHECK_HEADERS([libintl.h])
    268268    GETTEXT_PACKAGE=transmission
     
    356356                 third-party/miniupnp/Makefile
    357357                 third-party/libnatpmp/Makefile
     358                 third-party/dht/Makefile
    358359                 macosx/Makefile
    359360                 gtk/Makefile
  • trunk/daemon/Makefile.am

    r8152 r8433  
    2323    $(top_builddir)/third-party/libnatpmp/libnatpmp.a \
    2424    $(top_builddir)/third-party/libevent/libevent.la \
     25    $(top_builddir)/third-party/dht/libdht.a \
    2526    $(INTLLIBS) \
    2627    $(LIBCURL_LIBS) \
  • trunk/gtk/Makefile.am

    r8389 r8433  
    104104    $(top_builddir)/third-party/miniupnp/libminiupnp.a \
    105105    $(top_builddir)/third-party/libnatpmp/libnatpmp.a \
     106    $(top_builddir)/third-party/dht/libdht.a \
    106107    $(GTK_LIBS) \
    107108    $(GIO_LIBS) \
  • trunk/gtk/details.c

    r8432 r8433  
    942942            str = mixed;
    943943        else if( baseline )
    944             str = _( "Private to this tracker -- PEX disabled" );
     944            str = _( "Private to this tracker -- DHT and PEX disabled" );
    945945        else
    946946            str = _( "Public torrent" );
     
    15041504                case 'E': s = _( "Encrypted connection" ); break;
    15051505                case 'X': s = _( "Peer was discovered through Peer Exchange (PEX)" ); break;
     1506                case 'H': s = _( "Peer was discovered through DHT" ); break;
    15061507                case 'I': s = _( "Peer is an incoming connection" ); break;
    15071508            }
  • trunk/libtransmission/Makefile.am

    r8152 r8433  
    5050    tr-getopt.c \
    5151    tracker.c \
     52    tr-dht.c \
    5253    trevent.c \
    5354    upnp.c \
     
    9798    tr-getopt.h \
    9899    transmission.h \
     100    tr-dht.h \
    99101    trevent.h \
    100102    upnp.h \
     
    125127    $(top_builddir)/third-party/libnatpmp/libnatpmp.a \
    126128    $(top_builddir)/third-party/libevent/libevent.la \
     129    $(top_builddir)/third-party/dht/libdht.a \
    127130    $(INTLLIBS) \
    128131    $(LIBCURL_LIBS) \
  • trunk/libtransmission/handshake.c

    r7883 r8433  
    2929#include "peer-mgr.h"
    3030#include "torrent.h"
     31#include "tr-dht.h"
    3132#include "trevent.h"
    3233#include "utils.h"
     
    3637/* fast extensions */
    3738#define ENABLE_FAST * /
     39/* DHT */
     40#define ENABLE_DHT * /
    3841
    3942/***
     
    8184 #define HANDSHAKE_HAS_FASTEXT( bits ) ( 0 )
    8285 #define HANDSHAKE_SET_FASTEXT( bits ) ( (void)0 )
     86#endif
     87
     88#ifdef ENABLE_DHT
     89 #define HANDSHAKE_HAS_DHT( bits ) ( ( ( bits )[7] & 0x01 ) ? 1 : 0 )
     90 #define HANDSHAKE_SET_DHT( bits ) ( ( bits )[7] |= 0x01 )
     91#else
     92 #define HANDSHAKE_HAS_DHT( bits ) ( 0 )
     93 #define HANDSHAKE_SET_DHT( bits ) ( (void)0 )
    8394#endif
    8495
     
    220231    HANDSHAKE_SET_FASTEXT( walk );
    221232
     233    /* Note that this doesn't depend on whether the torrent is private.  We
     234       don't accept DHT peers for a private torrent, but we participate in
     235       the DHT regardless. */
     236    if(tr_dhtEnabled(handshake->session))
     237        HANDSHAKE_SET_DHT( walk );
     238
    222239    walk += HANDSHAKE_FLAGS_LEN;
    223240    memcpy( walk, torrentHash, SHA_DIGEST_LENGTH );
     
    303320
    304321    tr_peerIoEnableFEXT( handshake->io, HANDSHAKE_HAS_FASTEXT( reserved ) );
     322
     323    /* This doesn't depend on whether the torrent is private. */
     324    if( tor->session->isDHTEnabled )
     325        tr_peerIoEnableDHT( handshake->io, HANDSHAKE_HAS_DHT( reserved ) );
    305326
    306327    return HANDSHAKE_OK;
  • trunk/libtransmission/peer-io.c

    r8265 r8433  
    618618}
    619619
     620void
     621tr_peerIoEnableDHT( tr_peerIo * io, tr_bool flag )
     622{
     623    assert( tr_isPeerIo( io ) );
     624    assert( tr_isBool( flag ) );
     625
     626    dbgmsg( io, "setting DHT support flag to %d", (flag!=0) );
     627    io->dhtSupported = flag;
     628}
     629
    620630/**
    621631***
  • trunk/libtransmission/peer-io.h

    r8265 r8433  
    6464    tr_bool               extendedProtocolSupported;
    6565    tr_bool               fastExtensionSupported;
     66    tr_bool               dhtSupported;
    6667
    6768    /* we create the socket in a nonblocking way, so this flag is initially
     
    158159
    159160    return io->fastExtensionSupported;
     161}
     162
     163void        tr_peerIoEnableDHT( tr_peerIo * io, tr_bool flag );
     164
     165static TR_INLINE tr_bool tr_peerIoSupportsDHT( const tr_peerIo * io )
     166{
     167    assert( tr_isPeerIo( io ) );
     168
     169    return io->dhtSupported;
    160170}
    161171
  • trunk/libtransmission/peer-mgr.c

    r8406 r8433  
    18741874        if( !stat->peerIsChoked && !stat->peerIsInterested ) *pch++ = '?';
    18751875        if( stat->isEncrypted ) *pch++ = 'E';
     1876        if( stat->from == TR_PEER_FROM_DHT ) *pch++ = 'H';
    18761877        if( stat->from == TR_PEER_FROM_PEX ) *pch++ = 'X';
    18771878        if( stat->isIncoming ) *pch++ = 'I';
     
    21642165        return a->time < b->time ? -1 : 1;
    21652166
    2166     /* all other things being equal, prefer peers whose
    2167      * information comes from a more reliable source */
     2167    /* In order to avoid fragmenting the swarm, peers from trackers and
     2168     * from the DHT should be preferred to peers from PEX. */
    21682169    if( a->from != b->from )
    21692170        return a->from < b->from ? -1 : 1;
  • trunk/libtransmission/peer-msgs.c

    r8415 r8433  
    3737#include "stats.h"
    3838#include "torrent.h"
     39#include "tr-dht.h"
    3940#include "trevent.h"
    4041#include "utils.h"
     
    305306    dbgOutMessageLen( msgs );
    306307    pokeBatchPeriod( msgs, IMMEDIATE_PRIORITY_INTERVAL_SECS );
     308}
     309
     310static void
     311protocolSendPort(tr_peermsgs *msgs, uint16_t port)
     312{
     313    tr_peerIo       * io  = msgs->peer->io;
     314    struct evbuffer * out = msgs->outMessages;
     315
     316    dbgmsg( msgs, "sending Port %u", port);
     317    tr_peerIoWriteUint32( io, out, 3 );
     318    tr_peerIoWriteUint8 ( io, out, BT_PORT );
     319    tr_peerIoWriteUint16( io, out, port);
    307320}
    308321
     
    21242137        sendLtepHandshake( m );
    21252138
     2139    if(tr_peerIoSupportsDHT(peer->io))
     2140        protocolSendPort(m, tr_dhtPort(torrent->session));
     2141
    21262142    tellPeerWhatWeHave( m );
    21272143
  • trunk/libtransmission/session.c

    r8398 r8433  
    4646#include "verify.h"
    4747#include "web.h"
     48#include "tr-dht.h"
    4849
    4950#define dbgmsg( ... ) \
     
    622623    assert( found );
    623624    session->isPexEnabled = boolVal;
     625    /* This really ought to be a separate preference. */
     626    session->isDHTEnabled = boolVal;
    624627
    625628    found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ENCRYPTION, &i );
     
    831834    session->isWaiting = FALSE;
    832835    dbgmsg( "returning session %p; session->tracker is %p", session, session->tracker );
     836
     837    if( session->isDHTEnabled )
     838        tr_dhtInit(session);
    833839}
    834840
     
    13931399
    13941400static void
    1395 tr_closeAllConnections( void * vsession )
     1401sessionCloseImpl( void * vsession )
    13961402{
    13971403    tr_session *  session = vsession;
     
    14031409
    14041410    free_incoming_peer_port( session );
     1411
     1412    if( session->isDHTEnabled )
     1413        tr_dhtUninit( session );
    14051414
    14061415    evtimer_del( session->altTimer );
     
    14561465
    14571466    /* close the session */
    1458     tr_runInEventThread( session, tr_closeAllConnections, session );
     1467    tr_runInEventThread( session, sessionCloseImpl, session );
    14591468    while( !session->isClosed && !deadlineReached( deadline ) )
    14601469    {
     
    15781587
    15791588    return session->isPexEnabled;
     1589}
     1590
     1591tr_bool
     1592tr_sessionIsDHTEnabled( const tr_session * session )
     1593{
     1594    assert( tr_isSession( session ) );
     1595
     1596    return session->isDHTEnabled;
    15801597}
    15811598
  • trunk/libtransmission/session.h

    r8398 r8433  
    6262    tr_bool                      isPortRandom;
    6363    tr_bool                      isPexEnabled;
     64    tr_bool                      isDHTEnabled;
    6465    tr_bool                      isBlocklistEnabled;
    6566    tr_bool                      isProxyEnabled;
  • trunk/libtransmission/torrent.c

    r8414 r8433  
    12721272checkAndStartImpl( void * vtor )
    12731273{
     1274    time_t now;
    12741275    tr_torrent * tor = vtor;
    12751276
     
    12781279    tr_globalLock( tor->session );
    12791280
     1281    now = time( NULL );
    12801282    tor->isRunning = TRUE;
    12811283    tor->needsSeedRatioCheck = TRUE;
     
    12841286    tor->completeness = tr_cpGetStatus( &tor->completion );
    12851287    tr_torrentSaveResume( tor );
    1286     tor->startDate = tor->anyDate = time( NULL );
     1288    tor->startDate = tor->anyDate = now;
    12871289    tr_trackerStart( tor->tracker );
     1290    tor->dhtAnnounceAt = now + tr_cryptoWeakRandInt( 20 );
    12881291    tr_peerMgrStartTorrent( tor );
    12891292
  • trunk/libtransmission/torrent.h

    r8389 r8433  
    176176    struct tr_publisher_tag *  trackerSubscription;
    177177
     178    time_t                     dhtAnnounceAt;
     179    tr_bool                    dhtAnnounceInProgress;
     180
    178181    uint64_t                   downloadedCur;
    179182    uint64_t                   downloadedPrev;
     
    289292}
    290293
     294static TR_INLINE tr_bool tr_torrentAllowsDHT( const tr_torrent * tor )
     295{
     296    return ( tor != NULL  ) && tor->session->isDHTEnabled && !tr_torrentIsPrivate( tor );
     297}
     298
    291299static TR_INLINE tr_bool tr_torrentIsPieceChecked( const tr_torrent  * tor, tr_piece_index_t i )
    292300{
  • trunk/libtransmission/tracker.c

    r8394 r8433  
    2727#include "torrent.h"
    2828#include "tracker.h"
     29#include "tr-dht.h"
    2930#include "trevent.h"
    3031#include "utils.h"
     
    978979            enqueueRequest( session, t, TR_REQ_REANNOUNCE );
    979980        }
     981
     982        if( tor->dhtAnnounceAt <= now ) {
     983            int rc = 1;
     984            if( tr_torrentAllowsDHT(tor) )
     985                rc = tr_dhtAnnounce(tor, 1);
     986            if(rc == 0)
     987                /* The DHT is not ready yet.  Try again soon. */
     988                tor->dhtAnnounceAt = now + 5 + tr_cryptoWeakRandInt( 5 );
     989            else
     990                /* We should announce at least once every 30 minutes. */
     991                tor->dhtAnnounceAt = now + 25 * 60 + tr_cryptoWeakRandInt( 3 * 60 );
     992        }
    980993    }
    981994
  • trunk/libtransmission/transmission.h

    r8389 r8433  
    531531tr_bool            tr_sessionIsPexEnabled( const tr_session * session );
    532532
     533tr_bool            tr_sessionIsDHTEnabled( const tr_session * session );
     534
    533535void               tr_sessionSetLazyBitfieldEnabled( tr_session * session,
    534536                                                     tr_bool       enabled );
     
    13441346    TR_PEER_FROM_INCOMING  = 0,  /* connections made to the listening port */
    13451347    TR_PEER_FROM_TRACKER   = 1,  /* peers received from a tracker */
    1346     TR_PEER_FROM_CACHE     = 2,  /* peers read from the peer cache */
    1347     TR_PEER_FROM_PEX       = 3,  /* peers discovered via PEX */
     1348    TR_PEER_FROM_DHT       = 2,  /* peers learnt from the DHT */
     1349    TR_PEER_FROM_CACHE     = 3,  /* peers read from the peer cache */
     1350    TR_PEER_FROM_PEX       = 4,  /* peers discovered via PEX */
    13481351    TR_PEER_FROM__MAX
    13491352};
  • trunk/third-party/Makefile.am

    r7974 r8433  
    22    libevent \
    33    libnatpmp \
    4     miniupnp
     4    miniupnp \
     5    dht
    56
    67EXTRA_DIST = \
Note: See TracChangeset for help on using the changeset viewer.