Browse code

usrloc: do keepalive-based contact expire on internal callback

- the one used by nathelper is not triggered automatically

Daniel-Constantin Mierla authored on 23/09/2020 15:00:29
Showing 1 changed files
... ...
@@ -40,6 +40,8 @@
40 40
 
41 41
 #include "ul_keepalive.h"
42 42
 
43
+extern int ul_keepalive_timeout;
44
+
43 45
 static int ul_ka_send(str *kamsg, dest_info_t *kadst);
44 46
 
45 47
 /**
... ...
@@ -102,11 +104,13 @@ int ul_ka_urecord(urecord_t *ur)
102 104
 	int aortype = 0;
103 105
 	int i;
104 106
 	struct timeval tv;
107
+	time_t tnow = 0;
105 108
 
106 109
 	if (ul_ka_mode == ULKA_NONE) {
107 110
 		return 0;
108 111
 	}
109 112
 	LM_DBG("keepalive for aor: %.*s\n", ur->aor.len, ur->aor.s);
113
+	tnow = time(NULL);
110 114
 
111 115
 	for(i=0; i<ur->aor.len; i++) {
112 116
 		if(ur->aor.s[i] == '@') {
... ...
@@ -122,6 +126,18 @@ int ul_ka_urecord(urecord_t *ur)
122 126
 		if((ul_ka_filter&GAU_OPT_SERVER_ID) && (uc->server_id != server_id)) {
123 127
 			continue;
124 128
 		}
129
+		if(ul_keepalive_timeout>0 && uc->last_keepalive>0) {
130
+			if(uc->last_keepalive+ul_keepalive_timeout < tnow) {
131
+				/* set contact as expired in 10s */
132
+				LM_DBG("set expired contact on keepalive - aor: %.*s c: %.*s\n",
133
+						ur->aor.len, ur->aor.s, uc->c.len, uc->c.s);
134
+				if(uc->expires > tnow + 10) {
135
+					uc->expires = tnow + 10;
136
+					continue;
137
+				}
138
+			}
139
+		}
140
+
125 141
 		if(ul_ka_mode & ULKA_NAT) {
126 142
 			/* keepalive for natted contacts only */
127 143
 			if (ul_nat_bflag == 0) {