Skip to content

Commit aeead5c

Browse files
committed
HevConf: Add support for custom cycle of UDP STUN check.
1 parent 66f26ba commit aeead5c

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Options:
5151
-d run as daemon
5252
-i <interface> network interface or IP address
5353
-k <interval> seconds between each keep-alive
54+
-c <count> UDP STUN check cycle (every <count> intervals)
5455
-s <addr>[:port] domain name or address of STUN server
5556
-h <addr>[:port] domain name or address of HTTP server
5657
-e <path> script path for notify mapped address

src/hev-conf.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
static int mode = SOCK_STREAM;
2222
static int type = AF_INET;
2323
static int keep;
24+
static unsigned int ucount;
2425
static int dmon;
2526
static int tmsec;
2627
static int bport[3];
@@ -52,6 +53,7 @@ hev_conf_help (void)
5253
" -d run as daemon\n"
5354
" -i <interface> network interface or IP address\n"
5455
" -k <interval> seconds between each keep-alive\n"
56+
" -c <count> UDP STUN check cycle (every <count> intervals)\n"
5557
" -s <addr>[:port] domain name or address of STUN server\n"
5658
" -h <addr>[:port] domain name or address of HTTP server\n"
5759
" -e <path> script path for notify mapped address\n"
@@ -94,6 +96,9 @@ hev_conf_init (int argc, char *argv[])
9496
case 'k':
9597
keep = strtoul (optarg, NULL, 10) * 1000;
9698
break;
99+
case 'c':
100+
ucount = strtoul (optarg, NULL, 10);
101+
break;
97102
case 's':
98103
sscanf (optarg, "%255[^:]:%5[0123456789]", stun, sport);
99104
break;
@@ -143,6 +148,10 @@ hev_conf_init (int argc, char *argv[])
143148
keep *= 1000;
144149
}
145150

151+
if (ucount <= 0) {
152+
ucount = 10;
153+
}
154+
146155
if (!bport[0]) {
147156
bport[0] = 0;
148157
}
@@ -183,6 +192,12 @@ hev_conf_keep (void)
183192
return keep;
184193
}
185194

195+
unsigned int
196+
hev_conf_ucount (void)
197+
{
198+
return ucount;
199+
}
200+
186201
const char *
187202
hev_conf_stun (void)
188203
{

src/hev-conf.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ int hev_conf_type (void);
5757
*/
5858
int hev_conf_keep (void);
5959

60+
/**
61+
* hev_conf_ucount:
62+
*
63+
* Get the UDP STUN check cycle value.
64+
*
65+
* Returns: returns integer number.
66+
*/
67+
unsigned int hev_conf_ucount (void);
68+
6069
/**
6170
* hev_conf_stun:
6271
*

src/hev-unsk.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static struct sockaddr_storage saddr;
2828
static struct sockaddr_storage daddr;
2929
static HevTask *task;
3030
static int timeout;
31+
static unsigned int cycle;
3132

3233
static void
3334
stun_handler (void)
@@ -54,7 +55,7 @@ unsk_keep_alive (void)
5455
}
5556

5657
fd = hev_ufwd_fd ();
57-
if ((fd < 0) || (++n >= 10)) {
58+
if ((fd < 0) || (++n >= cycle)) {
5859
hev_stun_run ((struct sockaddr *)&saddr, stun_handler);
5960
n = 0;
6061
continue;
@@ -100,6 +101,7 @@ unsk_run (void)
100101
iface = hev_conf_iface ();
101102
mark = hev_conf_mark ();
102103
timeout = hev_conf_keep ();
104+
cycle = hev_conf_ucount ();
103105

104106
fd = hev_sock_client_base (type, SOCK_DGRAM, addr, port, stun, sport, iface,
105107
mark, &saddr, &daddr);

0 commit comments

Comments
 (0)