Module: kamailio
Branch: master
Commit: b26951c06483a0e9720b65689179541b29c938c5
URL:
https://github.com/kamailio/kamailio/commit/b26951c06483a0e9720b65689179541…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: GitHub <noreply(a)github.com>
Date: 2020-05-19T12:56:58+02:00
Merge pull request #2326 from NGSegovia/keepalive/first_check_on_start
keepalive: early start of OPTIONS checking
---
Modified: src/modules/keepalive/keepalive.h
Modified: src/modules/keepalive/keepalive_api.c
Modified: src/modules/keepalive/keepalive_core.c
---
Diff:
https://github.com/kamailio/kamailio/commit/b26951c06483a0e9720b65689179541…
Patch:
https://github.com/kamailio/kamailio/commit/b26951c06483a0e9720b65689179541…
---
diff --git a/src/modules/keepalive/keepalive.h b/src/modules/keepalive/keepalive.h
index a8da607db8..41e8eab00a 100644
--- a/src/modules/keepalive/keepalive.h
+++ b/src/modules/keepalive/keepalive.h
@@ -48,6 +48,8 @@ extern int ka_ping_interval;
#define KA_PROBE_INACTIVE 2
#define KA_PROBE_ONLYFLAGGED 3
+#define KA_FIRST_TRY_DELAY 500 /* First OPTIONS send is done 500 millis after adding the
destination */
+
typedef void (*ka_statechanged_f)(str *uri, int state, void *user_attr);
typedef void (*ka_response_f)(
str *uri, struct tmcb_params *ps, void *user_attr);
@@ -62,6 +64,7 @@ typedef struct _ka_dest
int state;
time_t last_checked, last_up, last_down;
int counter; // counts unreachable attemps
+ ticks_t ping_interval; /*!< Actual interval between OPTIONS */
void *user_attr;
ka_statechanged_f statechanged_clb;
@@ -70,7 +73,7 @@ typedef struct _ka_dest
struct ip_addr ip_address; /*!< IP-Address of the entry */
unsigned short int port; /*!< Port of the URI */
unsigned short int proto; /*!< Protocol of the URI */
- struct timer_ln *timer;
+ struct timer_ln *timer; /*!< Timer firing the OPTIONS test */
struct _ka_dest *next;
} ka_dest_t;
diff --git a/src/modules/keepalive/keepalive_api.c
b/src/modules/keepalive/keepalive_api.c
index 18336084af..19339c4ba6 100644
--- a/src/modules/keepalive/keepalive_api.c
+++ b/src/modules/keepalive/keepalive_api.c
@@ -107,6 +107,7 @@ int ka_add_dest(str *uri, str *owner, int flags, int ping_interval,
dest->statechanged_clb = statechanged_clb;
dest->response_clb = response_clb;
dest->user_attr = user_attr;
+ dest->ping_interval = MS_TO_TICKS((ping_interval == 0 ? ka_ping_interval :
ping_interval) * 1000) ;
dest->timer = timer_alloc();
if (dest->timer == NULL) {
@@ -116,8 +117,7 @@ int ka_add_dest(str *uri, str *owner, int flags, int ping_interval,
timer_init(dest->timer, ka_check_timer, dest, 0);
- int actual_ping_interval = ping_interval == 0 ? ka_ping_interval : ping_interval;
- if(timer_add(dest->timer, MS_TO_TICKS(actual_ping_interval * 1000)) < 0){
+ if(timer_add(dest->timer, MS_TO_TICKS(KA_FIRST_TRY_DELAY)) < 0){
LM_ERR("failed to start timer\n");
goto err;
}
diff --git a/src/modules/keepalive/keepalive_core.c
b/src/modules/keepalive/keepalive_core.c
index 04b520a62b..4daa57908d 100644
--- a/src/modules/keepalive/keepalive_core.c
+++ b/src/modules/keepalive/keepalive_core.c
@@ -82,7 +82,7 @@ ticks_t ka_check_timer(ticks_t ticks, struct timer_ln* tl, void* param)
ka_dest->last_checked = time(NULL);
- return (ticks_t)(-1); /* periodical */
+ return ka_dest->ping_interval; /* periodical, but based on dest->ping_interval,
not on initial_timeout */
}
/*! \brief