(trunk libT) as a followup to r12182, move LPD's periodic upkeep timer into the tr-lpd.c module where it can be started & stopped with the pre-existing tr_lpdInit() and tr_lpdUninit() functions.

This commit is contained in:
Jordan Lee 2011-03-17 13:16:23 +00:00
parent 501f2e106f
commit 78a4865aa1
4 changed files with 27 additions and 12 deletions

View File

@ -622,13 +622,6 @@ onNowTimer( int foo UNUSED, short bar UNUSED, void * vsession )
tr_dhtUpkeep( session );
/* lpd upkeep */
if( session->lpdUpkeepAt <= now ) {
const int LPD_UPKEEP_INTERVAL_SECS = 5;
session->lpdUpkeepAt = now + LPD_UPKEEP_INTERVAL_SECS;
tr_lpdAnnounceMore( now, LPD_UPKEEP_INTERVAL_SECS );
}
if( session->turtle.isClockEnabled )
turtleCheckClock( session, &session->turtle );

View File

@ -142,8 +142,6 @@ struct tr_session
struct event *udp_event;
struct event *udp6_event;
time_t lpdUpkeepAt;
/* The open port on the local machine for incoming peer requests */
tr_port private_peer_port;

View File

@ -69,6 +69,11 @@ THE SOFTWARE.
static void event_callback( int, short, void* );
enum {
UPKEEP_INTERVAL_SECS = 5
};
static struct event * upkeep_timer = NULL;
static int lpd_socket; /**<separate multicast receive socket */
static int lpd_socket2; /**<and multicast send socket */
static struct event * lpd_event = NULL;
@ -250,6 +255,8 @@ static int lpd_extractParam( const char* const str, const char* const name, int
/**
* @} */
static void on_upkeep_timer( int, short, void * );
/**
* @brief Initializes Local Peer Discovery for this node
*
@ -342,6 +349,9 @@ int tr_lpdInit( tr_session* ss, tr_address* tr_addr UNUSED )
lpd_event = event_new( ss->event_base, lpd_socket, EV_READ | EV_PERSIST, event_callback, NULL );
event_add( lpd_event, NULL );
upkeep_timer = evtimer_new( ss->event_base, on_upkeep_timer, ss );
tr_timerAdd( upkeep_timer, UPKEEP_INTERVAL_SECS, 0 );
tr_ndbg( "LPD", "Local Peer Discovery initialised" );
return 1;
@ -371,6 +381,9 @@ void tr_lpdUninit( tr_session* ss )
event_free( lpd_event );
lpd_event = NULL;
evtimer_del( upkeep_timer );
upkeep_timer = NULL;
/* just shut down, we won't remember any former nodes */
evutil_closesocket( lpd_socket );
evutil_closesocket( lpd_socket2 );
@ -539,8 +552,13 @@ static int tr_lpdConsiderAnnounce( tr_pex* peer, const char* const msg )
* the function needs to be informed of the externally employed housekeeping interval.
* Further, by setting interval to zero (or negative) the caller may actually disable LPD
* announces on a per-interval basis.
*
* FIXME: since this function's been made private and is called by a periodic timer,
* most of the previous paragraph isn't true anymore... we weren't using that functionality
* before. are there cases where we should? if not, should we remove the bells & whistles?
*/
int tr_lpdAnnounceMore( const time_t now, const int interval )
static int
tr_lpdAnnounceMore( const time_t now, const int interval )
{
tr_torrent* tor = NULL;
int announcesSent = 0;
@ -598,6 +616,14 @@ int tr_lpdAnnounceMore( const time_t now, const int interval )
return announcesSent;
}
static void
on_upkeep_timer( int foo UNUSED, short bar UNUSED, void * vsession UNUSED )
{
const time_t now = tr_time( );
tr_lpdAnnounceMore( now, UPKEEP_INTERVAL_SECS );
tr_timerAdd( upkeep_timer, UPKEEP_INTERVAL_SECS, 0 );
}
/**
* @brief Processing of timeout notifications and incoming data on the socket
* @note maximum rate of read events is limited according to @a lpd_maxAnnounceCap

View File

@ -36,8 +36,6 @@ tr_bool tr_lpdEnabled( const tr_session* );
tr_bool tr_lpdSendAnnounce( const tr_torrent* );
int tr_lpdAnnounceMore( const time_t, const int );
/**
* @defgroup Preproc Helper macros
* @{