From: Ralph Ronnquist Date: Sat, 25 Mar 2023 23:43:43 +0000 (+1100) Subject: added heartbeat rate configuration X-Git-Tag: 1.6.2~4 X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=ae7fa03b5414c82c50e311232aac7dfe7bba1332;p=rrq%2Frrqnet.git added heartbeat rate configuration --- diff --git a/debian/changelog b/debian/changelog index 3e588f3..d988a1c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +rrqnet (1.6.2) unstable; urgency=medium + + * add configuration of "heartbeat" messaging rate. + + -- Ralph Ronnquist Sun, 26 Mar 2023 10:42:42 +1100 + rrqnet (1.6.1) unstable; urgency=medium * limiting dest IP capture to downlinks diff --git a/rrqnet.8.adoc b/rrqnet.8.adoc index ccc35c1..e6ed668 100644 --- a/rrqnet.8.adoc +++ b/rrqnet.8.adoc @@ -25,7 +25,7 @@ OPTIONS Note that any options must be given or omitted in the fixed order: - [-v] [-tpg] [-4] [-B n] [-T n] [-m mcast] [-t tap] [-S source] + [-v] [-tpg] [-4] [-B n] [-T n] [-H r] [-m mcast] [-t tap] [-S source] *-v*:: @@ -60,6 +60,13 @@ where it immediately puts received packets into the buffer queue which is serviced by the dispatch threads for optional decryption, dispatch decision, optional encryption and delivery. +*-H* _r_:: + +This sets the number of seconds *rrqnet* should wait between "heart +beat" messages to uplinks. The default is 30. This is used to hold the +uplink open for return traffic through NAT routers. Set to 0 to +disable the heartbeat messages. + *-m* _mcast_:: This tells *rrqnet* to open an ipv4 UDP multicast channel as an diff --git a/rrqnet.c b/rrqnet.c index 193e673..b06c3ab 100644 --- a/rrqnet.c +++ b/rrqnet.c @@ -99,8 +99,7 @@ typedef struct _ReaderData { } ReaderData; // heartbeat interval, in seconds -#define HEARTBEAT 30 -#define HEARTBEAT_MICROS ( HEARTBEAT * 1000000 ) +#define HEARTBEAT_MICROS ( heart_rate * 1000000 ) // Macros for timing, for struct timeval variables #define TIME_MICROS(TM) (((int64_t) (TM)->tv_sec * 1000000) + (TM)->tv_usec ) @@ -184,6 +183,7 @@ static int udp_fd; static int udp_port; static int threads_count = 0; static int buffers_count = 0; +static int heart_rate = 30; // Setup for multicast channel static struct { @@ -691,6 +691,14 @@ static int parse_threads_count(char *arg) { return 0; } +static int parse_heartbeat_rate(char *arg) { + if ( ( sscanf( arg, "%u", &heart_rate ) != 1 ) || heart_rate < 0 ) { + return 1; + } + VERBOSEOUT( "** Heartbeat rate = %d\n", heart_rate ); + return 0; +} + static int parse_buffers_count(char *arg) { if ( ( sscanf( arg, "%u", &buffers_count ) != 1 ) || buffers_count < 1 ) { return 1; @@ -1461,7 +1469,7 @@ static void heartbeat(int fd) { r = (struct Remote *) tmp; VERBOSE3OUT( "heartbeat check %s\n", inet_stoa( &r->uaddr ) ); if ( r->spec && is_uplink( r->spec ) ) { - if ( DIFF_MICROS( &now, &r->rec_when ) > HEARTBEAT_MICROS ) { + if ( DIFF_MICROS( &now, &r->rec_when ) >= HEARTBEAT_MICROS ) { VERBOSE3OUT( "heartbeat %s\n", inet_stoa( &r->uaddr ) ); write_remote( data, 0, r ); } @@ -1626,6 +1634,15 @@ int main(int argc, char *argv[]) { i += 2; ENSUREARGS( 1 ); } + // then: optional -H seconds + if ( strncmp( "-H", argv[i], 2 ) == 0 ) { + ENSUREARGS( 2 ); + if ( parse_heartbeat_rate( argv[i+1] ) ) { + usage(); + } + i += 2; + ENSUREARGS( 1 ); + } // then: optional -m mcast if ( strncmp( "-m", argv[i], 2 ) == 0 ) { ENSUREARGS( 2 ); @@ -1789,10 +1806,12 @@ int main(int argc, char *argv[]) { pthread_create( &thread, 0, doreadTap, &tap_reader ); } - // Start heartbeating to uplinks - for ( ;; ) { - sleep( HEARTBEAT ); - heartbeat( udp_fd ); + if ( heart_rate == 0 ) { + // Start heartbeating to uplinks + for ( ;; ) { + sleep( heart_rate ); + heartbeat( udp_fd ); + } } return 0; }