mirror of
https://github.com/transmission/transmission
synced 2025-01-31 03:12:44 +00:00
(trunk libT) move tr_dhtUpkeep() out of the announcer module
During shutdown, we can stop DHT almost immediately, but need to leave the announcer running for the DHT tracker event=stopped messages. So it doesn't make sense to keep them on the same periodic timer.
This commit is contained in:
parent
686103ae49
commit
6835374661
4 changed files with 36 additions and 41 deletions
|
@ -28,7 +28,6 @@
|
|||
#include "peer-mgr.h" /* tr_peerMgrCompactToPex() */
|
||||
#include "ptrarray.h"
|
||||
#include "session.h"
|
||||
#include "tr-dht.h"
|
||||
#include "tr-lpd.h"
|
||||
#include "torrent.h"
|
||||
#include "utils.h"
|
||||
|
@ -1493,42 +1492,6 @@ announceMore( tr_announcer * announcer )
|
|||
tr_ptrArrayDestruct( &announceMe, NULL );
|
||||
}
|
||||
|
||||
static void
|
||||
dht_upkeep( tr_session * session )
|
||||
{
|
||||
tr_torrent * tor = NULL;
|
||||
const time_t now = tr_time( );
|
||||
|
||||
while(( tor = tr_torrentNext( session, tor )))
|
||||
{
|
||||
if( tor->dhtAnnounceAt <= now )
|
||||
{
|
||||
if( tor->isRunning && tr_torrentAllowsDHT(tor) ) {
|
||||
const int rc = tr_dhtAnnounce(tor, AF_INET, 1);
|
||||
if(rc == 0)
|
||||
/* The DHT is not ready yet. Try again soon. */
|
||||
tor->dhtAnnounceAt = now + 5 + tr_cryptoWeakRandInt( 5 );
|
||||
else
|
||||
/* We should announce at least once every 30 minutes. */
|
||||
tor->dhtAnnounceAt =
|
||||
now + 25 * 60 + tr_cryptoWeakRandInt( 3 * 60 );
|
||||
}
|
||||
}
|
||||
|
||||
if( tor->dhtAnnounce6At <= now )
|
||||
{
|
||||
if( tor->isRunning && tr_torrentAllowsDHT(tor) ) {
|
||||
const int rc = tr_dhtAnnounce(tor, AF_INET6, 1);
|
||||
if(rc == 0)
|
||||
tor->dhtAnnounce6At = now + 5 + tr_cryptoWeakRandInt( 5 );
|
||||
else
|
||||
tor->dhtAnnounce6At =
|
||||
now + 25 * 60 + tr_cryptoWeakRandInt( 3 * 60 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
onUpkeepTimer( int foo UNUSED, short bar UNUSED, void * vannouncer )
|
||||
{
|
||||
|
@ -1542,8 +1505,6 @@ onUpkeepTimer( int foo UNUSED, short bar UNUSED, void * vannouncer )
|
|||
/* maybe send out some announcements to trackers */
|
||||
announceMore( announcer );
|
||||
|
||||
dht_upkeep( announcer->session );
|
||||
|
||||
/* LPD upkeep */
|
||||
if( announcer->lpdUpkeepAt <= now ) {
|
||||
const int seconds = LPD_HOUSEKEEPING_INTERVAL_SECS;
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "session.h"
|
||||
#include "stats.h"
|
||||
#include "torrent.h"
|
||||
#include "tr-dht.h" /* tr_dhtUpkeep() */
|
||||
#include "tr-udp.h"
|
||||
#include "tr-utp.h"
|
||||
#include "tr-lpd.h"
|
||||
|
@ -618,6 +619,8 @@ onNowTimer( int foo UNUSED, short bar UNUSED, void * vsession )
|
|||
|
||||
tr_timeUpdate( time( NULL ) );
|
||||
|
||||
tr_dhtUpkeep( session );
|
||||
|
||||
if( session->turtle.isClockEnabled )
|
||||
turtleCheckClock( session, &session->turtle );
|
||||
|
||||
|
|
|
@ -546,7 +546,7 @@ callback( void *ignore UNUSED, int event,
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
tr_dhtAnnounce(tr_torrent *tor, int af, tr_bool announce)
|
||||
{
|
||||
int rc, status, numnodes, ret = 0;
|
||||
|
@ -589,6 +589,37 @@ tr_dhtAnnounce(tr_torrent *tor, int af, tr_bool announce)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
tr_dhtUpkeep( tr_session * session )
|
||||
{
|
||||
tr_torrent * tor = NULL;
|
||||
const time_t now = tr_time( );
|
||||
|
||||
while(( tor = tr_torrentNext( session, tor )))
|
||||
{
|
||||
if( !tor->isRunning || !tr_torrentAllowsDHT( tor ) )
|
||||
continue;
|
||||
|
||||
if( tor->dhtAnnounceAt <= now )
|
||||
{
|
||||
const int rc = tr_dhtAnnounce(tor, AF_INET, 1);
|
||||
|
||||
tor->dhtAnnounceAt = now + (rc == 0)
|
||||
? 5 + tr_cryptoWeakRandInt( 5 )
|
||||
: 25 * 60 + tr_cryptoWeakRandInt( 3*60 );
|
||||
}
|
||||
|
||||
if( tor->dhtAnnounce6At <= now )
|
||||
{
|
||||
const int rc = tr_dhtAnnounce(tor, AF_INET6, 1);
|
||||
|
||||
tor->dhtAnnounce6At = now + (rc == 0)
|
||||
? 5 + tr_cryptoWeakRandInt( 5 )
|
||||
: 25 * 60 + tr_cryptoWeakRandInt( 3*60 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tr_dhtCallback(unsigned char *buf, int buflen,
|
||||
struct sockaddr *from, socklen_t fromlen,
|
||||
|
|
|
@ -43,7 +43,7 @@ tr_port tr_dhtPort ( tr_session * );
|
|||
int tr_dhtStatus( tr_session *, int af, int * setme_nodeCount );
|
||||
const char *tr_dhtPrintableStatus(int status);
|
||||
int tr_dhtAddNode( tr_session *, const tr_address *, tr_port, tr_bool bootstrap );
|
||||
int tr_dhtAnnounce( tr_torrent *, int af, tr_bool announce );
|
||||
void tr_dhtUpkeep( tr_session * );
|
||||
void tr_dhtCallback(unsigned char *buf, int buflen,
|
||||
struct sockaddr *from, socklen_t fromlen,
|
||||
void *sv);
|
||||
|
|
Loading…
Reference in a new issue