Browse code

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.

Nacho Garcia Segovia authored on 15/05/2020 06:21:15
Showing 3 changed files
... ...
@@ -48,6 +48,8 @@ extern int ka_ping_interval;
48 48
 #define KA_PROBE_INACTIVE 2
49 49
 #define KA_PROBE_ONLYFLAGGED 3
50 50
 
51
+#define KA_FIRST_TRY_DELAY 500 /* First OPTIONS send is done 500 millis after adding the destination */
52
+
51 53
 typedef void (*ka_statechanged_f)(str *uri, int state, void *user_attr);
52 54
 typedef void (*ka_response_f)(
53 55
 		str *uri, struct tmcb_params *ps, void *user_attr);
... ...
@@ -62,6 +64,7 @@ typedef struct _ka_dest
62 64
 	int state;
63 65
 	time_t last_checked, last_up, last_down;
64 66
 	int counter;	// counts unreachable attemps
67
+	ticks_t ping_interval;  /*!< Actual interval between OPTIONS  */
65 68
 
66 69
 	void *user_attr;
67 70
 	ka_statechanged_f statechanged_clb;
... ...
@@ -70,7 +73,7 @@ typedef struct _ka_dest
70 73
 	struct ip_addr ip_address; /*!< IP-Address of the entry */
71 74
 	unsigned short int port;   /*!< Port of the URI */
72 75
 	unsigned short int proto;  /*!< Protocol of the URI */
73
-	struct timer_ln *timer;
76
+	struct timer_ln *timer;    /*!< Timer firing the OPTIONS test */
74 77
 	struct _ka_dest *next;
75 78
 } ka_dest_t;
76 79
 
... ...
@@ -107,6 +107,7 @@ int ka_add_dest(str *uri, str *owner, int flags, int ping_interval,
107 107
 	dest->statechanged_clb = statechanged_clb;
108 108
 	dest->response_clb = response_clb;
109 109
 	dest->user_attr = user_attr;
110
+	dest->ping_interval = MS_TO_TICKS((ping_interval == 0 ? ka_ping_interval : ping_interval) * 1000) ;
110 111
 
111 112
     dest->timer = timer_alloc();
112 113
 	if (dest->timer == NULL) {
... ...
@@ -116,8 +117,7 @@ int ka_add_dest(str *uri, str *owner, int flags, int ping_interval,
116 117
 
117 118
 	timer_init(dest->timer, ka_check_timer, dest, 0);
118 119
 
119
-    int actual_ping_interval =  ping_interval == 0 ? ka_ping_interval : ping_interval;
120
-	if(timer_add(dest->timer, MS_TO_TICKS(actual_ping_interval * 1000)) < 0){
120
+	if(timer_add(dest->timer, MS_TO_TICKS(KA_FIRST_TRY_DELAY)) < 0){
121 121
 		LM_ERR("failed to start timer\n");
122 122
 		goto err;
123 123
 	}
... ...
@@ -82,7 +82,7 @@ ticks_t ka_check_timer(ticks_t ticks, struct timer_ln* tl, void* param)
82 82
 
83 83
     ka_dest->last_checked = time(NULL);
84 84
 
85
-	return (ticks_t)(-1); /* periodical */
85
+	return ka_dest->ping_interval; /* periodical, but based on dest->ping_interval, not on initial_timeout */
86 86
 }
87 87
 
88 88
 /*! \brief