Module: kamailio
Branch: master
Commit: f6b5f782e0ebc8570d640415c61b9bf654336154
URL: 
https://github.com/kamailio/kamailio/commit/f6b5f782e0ebc8570d640415c61b9bf654336154

Author: Nacho Garcia Segovia <nacho...@zaleos.net>
Committer: Nacho Garcia Segovia <nacho...@zaleos.net>
Date: 2020-05-15T08:21:15+02:00

keepalive: early start of OPTIONS checking

- Current code takes some time to start checking (ping_interval). So, if 
someone sets a really high ping_interval it takes a while to get destination 
status. This change fires the first OPTIONS check just 3 seconds (fixed) after 
the destination is added. The checks would be done with the pace defined in 
ping_interval.

---

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/f6b5f782e0ebc8570d640415c61b9bf654336154.diff
Patch: 
https://github.com/kamailio/kamailio/commit/f6b5f782e0ebc8570d640415c61b9bf654336154.patch

---

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


_______________________________________________
Kamailio (SER) - Development Mailing List
sr-dev@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to