Changeset 10606
- Timestamp:
- May 1, 2010, 4:04:00 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/daemon/daemon.c
r10542 r10606 86 86 { 'o', "dht", "Enable distributed hash tables (DHT)", "o", 0, NULL }, 87 87 { '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 }, 88 90 { 'P', "peerport", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "P", 1, "<port>" }, 89 91 { 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", 0, NULL }, … … 407 409 tr_bencDictAddBool( &settings, TR_PREFS_KEY_RATIO_ENABLED, FALSE ); 408 410 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; 409 415 default: showUsage( ); 410 416 break; -
trunk/libtransmission/Makefile.am
r10332 r10606 56 56 torrent-magnet.c \ 57 57 tr-dht.c \ 58 tr-lds.c \ 58 59 tr-getopt.c \ 59 60 trevent.c \ … … 108 109 transmission.h \ 109 110 tr-dht.h \ 111 tr-lds.h \ 110 112 trevent.h \ 111 113 upnp.h \ -
trunk/libtransmission/announcer.c
r10500 r10606 25 25 #include "session.h" 26 26 #include "tr-dht.h" 27 #include "tr-lds.h" 27 28 #include "torrent.h" 28 29 #include "utils.h" … … 66 67 SLOW_HOST_PENALTY_SECS = ( 60 * 10 ), 67 68 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 69 73 70 74 }; … … 203 207 struct event * upkeepTimer; 204 208 int slotsAvailable; 209 time_t ldsHouseKeepingAt; 205 210 } 206 211 tr_announcer; … … 232 237 onUpkeepTimer( int foo UNUSED, short bar UNUSED, void * vannouncer ); 233 238 239 static inline time_t 240 calcRescheduleWithJitter( 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 234 251 void 235 252 tr_announcerInit( tr_session * session ) 236 253 { 237 254 tr_announcer * a; 255 256 const time_t relaxUntil = 257 calcRescheduleWithJitter( LDS_HOUSEKEEPING_INTERVAL_SECS / 3 ); 238 258 239 259 assert( tr_isSession( session ) ); … … 244 264 a->session = session; 245 265 a->slotsAvailable = MAX_CONCURRENT_TASKS; 266 a->ldsHouseKeepingAt = relaxUntil; 246 267 a->upkeepTimer = tr_new0( struct event, 1 ); 247 268 evtimer_set( a->upkeepTimer, onUpkeepTimer, a ); … … 1885 1906 } 1886 1907 } 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 } 1887 1918 } 1888 1919 -
trunk/libtransmission/peer-mgr.c
r10544 r10606 1509 1509 case TR_PEER_FROM_PEX : return 60 * 60 * 2; 1510 1510 case TR_PEER_FROM_RESUME : return 60 * 60; 1511 case TR_PEER_FROM_LDS : return 10 * 60; 1511 1512 default : return 60 * 60; 1512 1513 } -
trunk/libtransmission/rpcimpl.c
r10550 r10606 1215 1215 if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_DHT_ENABLED, &boolVal ) ) 1216 1216 tr_sessionSetDHTEnabled( session, boolVal ); 1217 if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_LDS_ENABLED, &boolVal ) ) 1218 tr_sessionSetLDSEnabled( session, boolVal ); 1217 1219 if( tr_bencDictFindBool( args_in, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, &boolVal ) ) 1218 1220 tr_sessionSetPeerPortRandomOnStart( session, boolVal ); … … 1327 1329 tr_bencDictAddBool( d, TR_PREFS_KEY_PEX_ENABLED, tr_sessionIsPexEnabled( s ) ); 1328 1330 tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED, tr_sessionIsDHTEnabled( s ) ); 1331 tr_bencDictAddBool( d, TR_PREFS_KEY_LDS_ENABLED, tr_sessionIsLDSEnabled( s ) ); 1329 1332 tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT, tr_sessionGetPeerPort( s ) ); 1330 1333 tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, tr_sessionGetPeerPortRandomOnStart( s ) ); -
trunk/libtransmission/session.c
r10554 r10606 43 43 #include "torrent.h" 44 44 #include "tr-dht.h" 45 #include "tr-lds.h" 45 46 #include "trevent.h" 46 47 #include "utils.h" … … 245 246 tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, FALSE ); 246 247 tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED, TRUE ); 248 tr_bencDictAddBool( d, TR_PREFS_KEY_LDS_ENABLED, FALSE ); 247 249 tr_bencDictAddStr ( d, TR_PREFS_KEY_DOWNLOAD_DIR, tr_getDefaultDownloadDir( ) ); 248 250 tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED, 100 ); … … 307 309 tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, tr_blocklistIsEnabled( s ) ); 308 310 tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED, s->isDHTEnabled ); 311 tr_bencDictAddBool( d, TR_PREFS_KEY_LDS_ENABLED, s->isLDSEnabled ); 309 312 tr_bencDictAddStr ( d, TR_PREFS_KEY_DOWNLOAD_DIR, s->downloadDir ); 310 313 tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED, tr_sessionGetSpeedLimit( s, TR_DOWN ) ); … … 626 629 } 627 630 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 628 639 /* cleanup */ 629 640 tr_bencFree( &settings ); … … 668 679 if( tr_bencDictFindBool( settings, TR_PREFS_KEY_DHT_ENABLED, &boolVal ) ) 669 680 tr_sessionSetDHTEnabled( session, boolVal ); 681 if( tr_bencDictFindBool( settings, TR_PREFS_KEY_LDS_ENABLED, &boolVal ) ) 682 tr_sessionSetLDSEnabled( session, boolVal ); 670 683 if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ENCRYPTION, &i ) ) 671 684 tr_sessionSetEncryption( session, i ); … … 1551 1564 1552 1565 free_incoming_peer_port( session ); 1566 1567 if( session->isLDSEnabled ) 1568 tr_ldsUninit( session ); 1553 1569 1554 1570 if( session->isDHTEnabled ) … … 1784 1800 if( ( enabled != 0 ) != ( session->isDHTEnabled != 0 ) ) 1785 1801 tr_runInEventThread( session, toggleDHTImpl, session ); 1802 } 1803 1804 void 1805 tr_sessionSetLDSEnabled( tr_session * session, 1806 tr_bool enabled ) 1807 { 1808 assert( tr_isSession( session ) ); 1809 1810 session->isLDSEnabled = ( enabled != 0 ); 1811 } 1812 1813 tr_bool 1814 tr_sessionIsLDSEnabled( const tr_session * session ) 1815 { 1816 assert( tr_isSession( session ) ); 1817 1818 return session->isLDSEnabled; 1819 } 1820 1821 tr_bool 1822 tr_sessionAllowsLDS( const tr_session * session ) 1823 { 1824 return tr_sessionIsLDSEnabled( session ); 1786 1825 } 1787 1826 -
trunk/libtransmission/session.h
r10550 r10606 85 85 tr_bool isPexEnabled; 86 86 tr_bool isDHTEnabled; 87 tr_bool isLDSEnabled; 87 88 tr_bool isBlocklistEnabled; 88 89 tr_bool isProxyEnabled; … … 180 181 tr_bool tr_sessionAllowsDHT( const tr_session * session ); 181 182 183 tr_bool tr_sessionAllowsLDS( const tr_session * session ); 184 182 185 const char * tr_sessionFindTorrentFile( const tr_session * session, 183 186 const char * hashString ); -
trunk/libtransmission/torrent.c
r10551 r10606 941 941 } 942 942 943 statictr_torrent_activity943 tr_torrent_activity 944 944 tr_torrentGetActivity( tr_torrent * tor ) 945 945 { … … 1401 1401 tor->dhtAnnounceAt = now + tr_cryptoWeakRandInt( 20 ); 1402 1402 tor->dhtAnnounce6At = now + tr_cryptoWeakRandInt( 20 ); 1403 tor->ldsAnnounceAt = now; 1403 1404 tr_peerMgrStartTorrent( tor ); 1404 1405 } -
trunk/libtransmission/torrent.h
r10550 r10606 131 131 tr_verify_state state ); 132 132 133 tr_torrent_activity tr_torrentGetActivity( tr_torrent * tor ); 134 133 135 struct tr_incomplete_metadata; 134 136 … … 198 200 tr_bool dhtAnnounceInProgress; 199 201 tr_bool dhtAnnounce6InProgress; 202 203 time_t ldsAnnounceAt; 200 204 201 205 uint64_t downloadedCur; … … 328 332 return ( tor != NULL ) 329 333 && ( tr_sessionAllowsDHT( tor->session ) ) 334 && ( !tr_torrentIsPrivate( tor ) ); 335 } 336 337 static inline tr_bool tr_torrentAllowsLDS( const tr_torrent * tor ) 338 { 339 return ( tor != NULL ) 340 && ( tr_sessionAllowsLDS( tor->session ) ) 330 341 && ( !tr_torrentIsPrivate( tor ) ); 331 342 } -
trunk/libtransmission/transmission.h
r10550 r10606 165 165 #define TR_PREFS_KEY_BLOCKLIST_ENABLED "blocklist-enabled" 166 166 #define TR_PREFS_KEY_DHT_ENABLED "dht-enabled" 167 #define TR_PREFS_KEY_LDS_ENABLED "lds-enabled" 167 168 #define TR_PREFS_KEY_DOWNLOAD_DIR "download-dir" 168 169 #define TR_PREFS_KEY_ENCRYPTION "encryption" … … 592 593 void tr_sessionSetDHTEnabled( tr_session * session, tr_bool ); 593 594 595 tr_bool tr_sessionIsLDSEnabled( const tr_session * session ); 596 597 void tr_sessionSetLDSEnabled( tr_session * session, tr_bool enabled ); 598 594 599 void tr_sessionSetLazyBitfieldEnabled( tr_session * session, 595 600 tr_bool enabled ); … … 1650 1655 TR_PEER_FROM_INCOMING = 0, /* connections made to the listening port */ 1651 1656 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 */ 1656 1662 TR_PEER_FROM__MAX 1657 1663 };
Note: See TracChangeset
for help on using the changeset viewer.