Changeset 10606


Ignore:
Timestamp:
May 1, 2010, 4:04:00 PM (8 years ago)
Author:
charles
Message:

(trunk) #3060 -- Local Peer Discovery patch from Eszet

Location:
trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/daemon.c

    r10542 r10606  
    8686    { 'o', "dht", "Enable distributed hash tables (DHT)", "o", 0, NULL },
    8787    { 'O', "no-dht", "Disable distributed hash tables (DHT)", "O", 0, NULL },
     88    { 'z', "lds", "Enable local peer discovery (LDS)", "z", 0, NULL },
     89    { 'Z', "no-lds", "Disable local peer discovery (LDS)", "Z", 0, NULL },
    8890    { 'P', "peerport", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "P", 1, "<port>" },
    8991    { 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", 0, NULL },
     
    407409                      tr_bencDictAddBool( &settings, TR_PREFS_KEY_RATIO_ENABLED, FALSE );
    408410                      break;
     411            case 'z': tr_bencDictAddBool( &settings, TR_PREFS_KEY_LDS_ENABLED, TRUE );
     412                      break;
     413            case 'Z': tr_bencDictAddBool( &settings, TR_PREFS_KEY_LDS_ENABLED, FALSE );
     414                      break;
    409415            default:  showUsage( );
    410416                      break;
  • trunk/libtransmission/Makefile.am

    r10332 r10606  
    5656    torrent-magnet.c \
    5757    tr-dht.c \
     58    tr-lds.c \
    5859    tr-getopt.c \
    5960    trevent.c \
     
    108109    transmission.h \
    109110    tr-dht.h \
     111    tr-lds.h \
    110112    trevent.h \
    111113    upnp.h \
  • trunk/libtransmission/announcer.c

    r10500 r10606  
    2525#include "session.h"
    2626#include "tr-dht.h"
     27#include "tr-lds.h"
    2728#include "torrent.h"
    2829#include "utils.h"
     
    6667    SLOW_HOST_PENALTY_SECS = ( 60 * 10 ),
    6768
    68     UPKEEP_INTERVAL_SECS = 1
     69    UPKEEP_INTERVAL_SECS = 1,
     70
     71    /* this is an upper limit for the frequency of LDS announces */
     72    LDS_HOUSEKEEPING_INTERVAL_SECS = 30
    6973
    7074};
     
    203207    struct event * upkeepTimer;
    204208    int slotsAvailable;
     209    time_t ldsHouseKeepingAt;
    205210}
    206211tr_announcer;
     
    232237onUpkeepTimer( int foo UNUSED, short bar UNUSED, void * vannouncer );
    233238
     239static inline time_t
     240calcRescheduleWithJitter( const int minPeriod )
     241{
     242    const double jitterFac = 0.1;
     243
     244    assert( minPeriod > 0 );
     245
     246    return tr_time()
     247        + minPeriod
     248        + tr_cryptoWeakRandInt( (int) ( minPeriod * jitterFac ) + 1 );
     249}
     250
    234251void
    235252tr_announcerInit( tr_session * session )
    236253{
    237254    tr_announcer * a;
     255
     256    const time_t relaxUntil =
     257        calcRescheduleWithJitter( LDS_HOUSEKEEPING_INTERVAL_SECS / 3 );
    238258
    239259    assert( tr_isSession( session ) );
     
    244264    a->session = session;
    245265    a->slotsAvailable = MAX_CONCURRENT_TASKS;
     266    a->ldsHouseKeepingAt = relaxUntil;
    246267    a->upkeepTimer = tr_new0( struct event, 1 );
    247268    evtimer_set( a->upkeepTimer, onUpkeepTimer, a );
     
    18851906        }
    18861907    }
     1908
     1909    /* Local Peer Discovery */
     1910    if( announcer->ldsHouseKeepingAt <= now )
     1911    {
     1912        tr_ldsAnnounceMore( now, LDS_HOUSEKEEPING_INTERVAL_SECS );
     1913
     1914        /* reschedule more LDS announces for ( the future + jitter ) */
     1915        announcer->ldsHouseKeepingAt =
     1916            calcRescheduleWithJitter( LDS_HOUSEKEEPING_INTERVAL_SECS );
     1917    }
    18871918}
    18881919
  • trunk/libtransmission/peer-mgr.c

    r10544 r10606  
    15091509        case TR_PEER_FROM_PEX      : return 60 * 60 * 2;
    15101510        case TR_PEER_FROM_RESUME   : return 60 * 60;
     1511        case TR_PEER_FROM_LDS      : return 10 * 60;
    15111512        default                    : return 60 * 60;
    15121513    }
  • trunk/libtransmission/rpcimpl.c

    r10550 r10606  
    12151215    if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_DHT_ENABLED, &boolVal ) )
    12161216        tr_sessionSetDHTEnabled( session, boolVal );
     1217    if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_LDS_ENABLED, &boolVal ) )
     1218        tr_sessionSetLDSEnabled( session, boolVal );
    12171219    if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, &boolVal ) )
    12181220        tr_sessionSetPeerPortRandomOnStart( session, boolVal );
     
    13271329    tr_bencDictAddBool( d, TR_PREFS_KEY_PEX_ENABLED, tr_sessionIsPexEnabled( s ) );
    13281330    tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED, tr_sessionIsDHTEnabled( s ) );
     1331    tr_bencDictAddBool( d, TR_PREFS_KEY_LDS_ENABLED, tr_sessionIsLDSEnabled( s ) );
    13291332    tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT, tr_sessionGetPeerPort( s ) );
    13301333    tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, tr_sessionGetPeerPortRandomOnStart( s ) );
  • trunk/libtransmission/session.c

    r10554 r10606  
    4343#include "torrent.h"
    4444#include "tr-dht.h"
     45#include "tr-lds.h"
    4546#include "trevent.h"
    4647#include "utils.h"
     
    245246    tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED,        FALSE );
    246247    tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED,              TRUE );
     248    tr_bencDictAddBool( d, TR_PREFS_KEY_LDS_ENABLED,              FALSE );
    247249    tr_bencDictAddStr ( d, TR_PREFS_KEY_DOWNLOAD_DIR,             tr_getDefaultDownloadDir( ) );
    248250    tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED,                   100 );
     
    307309    tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED,        tr_blocklistIsEnabled( s ) );
    308310    tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED,              s->isDHTEnabled );
     311    tr_bencDictAddBool( d, TR_PREFS_KEY_LDS_ENABLED,              s->isLDSEnabled );
    309312    tr_bencDictAddStr ( d, TR_PREFS_KEY_DOWNLOAD_DIR,             s->downloadDir );
    310313    tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED,                   tr_sessionGetSpeedLimit( s, TR_DOWN ) );
     
    626629    }
    627630
     631    if( session->isLDSEnabled )
     632    {
     633        if( tr_ldsInit( session, &session->public_ipv4->addr ) )
     634            tr_ninf( "LDS", "Local Peer Discovery active" );
     635    }
     636    else
     637        tr_ndbg( "LDS", "Local Peer Discovery disabled" );
     638
    628639    /* cleanup */
    629640    tr_bencFree( &settings );
     
    668679    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_DHT_ENABLED, &boolVal ) )
    669680        tr_sessionSetDHTEnabled( session, boolVal );
     681    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_LDS_ENABLED, &boolVal ) )
     682        tr_sessionSetLDSEnabled( session, boolVal );
    670683    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ENCRYPTION, &i ) )
    671684        tr_sessionSetEncryption( session, i );
     
    15511564
    15521565    free_incoming_peer_port( session );
     1566
     1567    if( session->isLDSEnabled )
     1568        tr_ldsUninit( session );
    15531569
    15541570    if( session->isDHTEnabled )
     
    17841800    if( ( enabled != 0 ) != ( session->isDHTEnabled != 0 ) )
    17851801        tr_runInEventThread( session, toggleDHTImpl, session );
     1802}
     1803
     1804void
     1805tr_sessionSetLDSEnabled( tr_session * session,
     1806                         tr_bool      enabled )
     1807{
     1808    assert( tr_isSession( session ) );
     1809
     1810    session->isLDSEnabled = ( enabled != 0 );
     1811}
     1812
     1813tr_bool
     1814tr_sessionIsLDSEnabled( const tr_session * session )
     1815{
     1816    assert( tr_isSession( session ) );
     1817
     1818    return session->isLDSEnabled;
     1819}
     1820
     1821tr_bool
     1822tr_sessionAllowsLDS( const tr_session * session )
     1823{
     1824    return tr_sessionIsLDSEnabled( session );
    17861825}
    17871826
  • trunk/libtransmission/session.h

    r10550 r10606  
    8585    tr_bool                      isPexEnabled;
    8686    tr_bool                      isDHTEnabled;
     87    tr_bool                      isLDSEnabled;
    8788    tr_bool                      isBlocklistEnabled;
    8889    tr_bool                      isProxyEnabled;
     
    180181tr_bool      tr_sessionAllowsDHT( const tr_session * session );
    181182
     183tr_bool      tr_sessionAllowsLDS( const tr_session * session );
     184
    182185const char * tr_sessionFindTorrentFile( const tr_session * session,
    183186                                        const char *       hashString );
  • trunk/libtransmission/torrent.c

    r10551 r10606  
    941941}
    942942
    943 static tr_torrent_activity
     943tr_torrent_activity
    944944tr_torrentGetActivity( tr_torrent * tor )
    945945{
     
    14011401        tor->dhtAnnounceAt = now + tr_cryptoWeakRandInt( 20 );
    14021402        tor->dhtAnnounce6At = now + tr_cryptoWeakRandInt( 20 );
     1403        tor->ldsAnnounceAt = now;
    14031404        tr_peerMgrStartTorrent( tor );
    14041405    }
  • trunk/libtransmission/torrent.h

    r10550 r10606  
    131131                                           tr_verify_state   state );
    132132
     133tr_torrent_activity tr_torrentGetActivity( tr_torrent * tor );
     134
    133135struct tr_incomplete_metadata;
    134136
     
    198200    tr_bool                    dhtAnnounceInProgress;
    199201    tr_bool                    dhtAnnounce6InProgress;
     202   
     203    time_t                     ldsAnnounceAt;
    200204
    201205    uint64_t                   downloadedCur;
     
    328332    return ( tor != NULL )
    329333        && ( tr_sessionAllowsDHT( tor->session ) )
     334        && ( !tr_torrentIsPrivate( tor ) );
     335}
     336
     337static inline tr_bool tr_torrentAllowsLDS( const tr_torrent * tor )
     338{
     339    return ( tor != NULL )
     340        && ( tr_sessionAllowsLDS( tor->session ) )
    330341        && ( !tr_torrentIsPrivate( tor ) );
    331342}
  • trunk/libtransmission/transmission.h

    r10550 r10606  
    165165#define TR_PREFS_KEY_BLOCKLIST_ENABLED          "blocklist-enabled"
    166166#define TR_PREFS_KEY_DHT_ENABLED                "dht-enabled"
     167#define TR_PREFS_KEY_LDS_ENABLED                "lds-enabled"
    167168#define TR_PREFS_KEY_DOWNLOAD_DIR               "download-dir"
    168169#define TR_PREFS_KEY_ENCRYPTION                 "encryption"
     
    592593void               tr_sessionSetDHTEnabled( tr_session * session, tr_bool );
    593594
     595tr_bool            tr_sessionIsLDSEnabled( const tr_session * session );
     596
     597void               tr_sessionSetLDSEnabled( tr_session * session, tr_bool enabled );
     598
    594599void               tr_sessionSetLazyBitfieldEnabled( tr_session * session,
    595600                                                     tr_bool       enabled );
     
    16501655    TR_PEER_FROM_INCOMING  = 0,  /* connections made to the listening port */
    16511656    TR_PEER_FROM_TRACKER   = 1,  /* peers received from a tracker */
    1652     TR_PEER_FROM_DHT       = 2,  /* peers learnt from the DHT */
    1653     TR_PEER_FROM_RESUME    = 3,  /* peers read from the .resume file */
    1654     TR_PEER_FROM_PEX       = 4,  /* peers discovered via PEX */
    1655     TR_PEER_FROM_LTEP      = 5,  /* peer address provided in an LTEP handshake */
     1657    TR_PEER_FROM_LDS       = 2,  /* peers discovered by local announcements */
     1658    TR_PEER_FROM_DHT       = 3,  /* peers learnt from the DHT */
     1659    TR_PEER_FROM_RESUME    = 4,  /* peers read from the .resume file */
     1660    TR_PEER_FROM_PEX       = 5,  /* peers discovered via PEX */
     1661    TR_PEER_FROM_LTEP      = 6,  /* peer address provided in an LTEP handshake */
    16561662    TR_PEER_FROM__MAX
    16571663};
Note: See TracChangeset for help on using the changeset viewer.