summaryrefslogtreecommitdiff
path: root/ecp
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2024-05-09 22:41:52 +0200
committerUros Majstorovic <majstor@majstor.org>2024-05-09 22:41:52 +0200
commit9089e3b41cefeb20cf504fec51bbb5177aa00304 (patch)
tree18db631d18e796beeb52de908a20c624b4e7276c /ecp
parentbc3f5dc45e19e88a984e215ec5393e86cea84e1c (diff)
added SIGUSR2 signal handler - expires garbage collected connections
Diffstat (limited to 'ecp')
-rw-r--r--ecp/server/Makefile2
-rw-r--r--ecp/server/dir.c4
-rw-r--r--ecp/server/dir.h2
-rw-r--r--ecp/server/ht.c1
-rw-r--r--ecp/server/server.c3
-rw-r--r--ecp/server/sig.c23
-rw-r--r--ecp/server/sig.h2
-rw-r--r--ecp/server/timer.c1
-rw-r--r--ecp/server/vlink.c5
9 files changed, 28 insertions, 15 deletions
diff --git a/ecp/server/Makefile b/ecp/server/Makefile
index 977e891..1ac945d 100644
--- a/ecp/server/Makefile
+++ b/ecp/server/Makefile
@@ -3,7 +3,7 @@ include $(src_dir)/ecp/common.mk
CFLAGS += -I../util -Wno-int-to-void-pointer-cast
LDFLAGS += -lrt
-obj = server.o dir.o vlink.o ht.o acl.o sig.o timer.o
+obj = server.o dir.o vlink.o ht.o acl.o sig.o # timer.o
dep = ../build-posix/*.a ../util/libecputil.a
%.o: %.c
diff --git a/ecp/server/dir.c b/ecp/server/dir.c
index 7244fd9..1dca021 100644
--- a/ecp/server/dir.c
+++ b/ecp/server/dir.c
@@ -7,6 +7,7 @@
#include <ecp/cr.h>
#include <ecp/ht.h>
#include <ecp/tm.h>
+#include <ecp/dir/dir.h>
#include "dir.h"
#include "vlink.h"
@@ -53,8 +54,6 @@ ssize_t dir_send_online(ECPConnection *conn, uint8_t region) {
pthread_rwlock_rdlock(&dir_online_rwlock);
list = &dir_online->list[region];
- if (list->msg_count == 0) goto send_online_fin;
-
for (i=0; i<list->msg_count; i++) {
ssize_t rv_snd;
@@ -84,7 +83,6 @@ ssize_t dir_send_online(ECPConnection *conn, uint8_t region) {
rv += rv_snd;
}
-send_online_fin:
pthread_rwlock_unlock(&dir_online_rwlock);
return rv;
}
diff --git a/ecp/server/dir.h b/ecp/server/dir.h
index 24af3bc..f82454b 100644
--- a/ecp/server/dir.h
+++ b/ecp/server/dir.h
@@ -1,5 +1,3 @@
-#include <ecp/dir/dir.h>
-
#define MAX_DIR_ITEM_IN_MSG ((ECP_MAX_PLD - (4 + sizeof(uint16_t))) / ECP_SIZE_DIR_ITEM)
#define MAX_DIR_MSG 10
diff --git a/ecp/server/ht.c b/ecp/server/ht.c
index dc67d30..964c6d6 100644
--- a/ecp/server/ht.c
+++ b/ecp/server/ht.c
@@ -1,5 +1,6 @@
#include <ecp/core.h>
#include <ecp/ht.h>
+#include <ecp/dir/dir.h>
#include "dir.h"
#include "ht.h"
diff --git a/ecp/server/server.c b/ecp/server/server.c
index a4bd8f6..eeb5f2d 100644
--- a/ecp/server/server.c
+++ b/ecp/server/server.c
@@ -9,6 +9,7 @@
#include <ecp/core.h>
#include <ecp/vconn/vconn.h>
+#include <ecp/dir/dir.h>
#include <util.h>
@@ -234,7 +235,7 @@ int main(int argc, char *argv[]) {
rv = ecp_start_receiver(&sock);
if (rv) fail("ecp_start_receiver err:%d\n", rv);
- rv = sig_start_handler();
+ rv = sig_start_handler(&sock);
if (rv) fail("sig_start_handler err:%d\n", rv);
if (argc == _argc + 2) {
diff --git a/ecp/server/sig.c b/ecp/server/sig.c
index 09593d3..3b83ade 100644
--- a/ecp/server/sig.c
+++ b/ecp/server/sig.c
@@ -6,20 +6,26 @@
#include <ecp/dir/dir.h>
#include "server.h"
+#include "dir.h"
#include "acl.h"
+
#include "sig.h"
static pthread_t sig_handler_thd;
static sigset_t sig_set;
+static int conn_expired(ECPConnection *conn, ecp_sts_t now) {
+ return _ecp_conn_is_zombie(conn, now, CONN_EXPIRE_TO);
+}
+
static void * _sig_handler(void *arg) {
- sigset_t *set = arg;
+ ECPSocket *sock = arg;
int rv, sig;
while (1) {
- rv = sigwait(set, &sig);
+ rv = sigwait(&sig_set, &sig);
if (rv) {
- LOG(LOG_ERR, "sig_handler: sigwait err:%d\n", rv);
+ LOG(LOG_ERR, "sig_handler: sigwait error\n");
continue;
}
switch (sig) {
@@ -32,16 +38,22 @@ static void * _sig_handler(void *arg) {
LOG(LOG_DEBUG, "sig_handler: acl reloaded\n");
break;
}
+
+ case SIGUSR2: {
+ ecp_sock_expire(sock, conn_expired);
+ LOG(LOG_DEBUG, "sig_handler: gc done - inbound connection count:%u\n", ecp_sock_gct_count(sock));
+ break;
+ }
}
}
return NULL;
}
-int sig_start_handler(void) {
+int sig_start_handler(ECPSocket *sock) {
int rv;
- rv = pthread_create(&sig_handler_thd, NULL, &_sig_handler, (void *)&sig_set);
+ rv = pthread_create(&sig_handler_thd, NULL, &_sig_handler, sock);
if (rv) return ECP_ERR;
return ECP_OK;
@@ -52,6 +64,7 @@ int sig_init(void) {
sigemptyset(&sig_set);
sigaddset(&sig_set, SIGUSR1);
+ sigaddset(&sig_set, SIGUSR2);
rv = pthread_sigmask(SIG_BLOCK, &sig_set, NULL);
if (rv) return ECP_ERR;
diff --git a/ecp/server/sig.h b/ecp/server/sig.h
index be4d647..52b5bd8 100644
--- a/ecp/server/sig.h
+++ b/ecp/server/sig.h
@@ -1,2 +1,2 @@
-int sig_start_handler(void);
+int sig_start_handler(ECPSocket *sock);
int sig_init(void);
diff --git a/ecp/server/timer.c b/ecp/server/timer.c
index ab30633..7a477ab 100644
--- a/ecp/server/timer.c
+++ b/ecp/server/timer.c
@@ -3,6 +3,7 @@
#include <time.h>
#include <ecp/core.h>
+#include <ecp/dir/dir.h>
#include "dir.h"
diff --git a/ecp/server/vlink.c b/ecp/server/vlink.c
index 6efb654..e18ec9f 100644
--- a/ecp/server/vlink.c
+++ b/ecp/server/vlink.c
@@ -3,9 +3,10 @@
#include <string.h>
#include <ecp/core.h>
-#include <ecp/vconn/vconn.h>
#include <ecp/ht.h>
#include <ecp/tm.h>
+#include <ecp/vconn/vconn.h>
+#include <ecp/dir/dir.h>
#include "dir.h"
#include "vlink.h"
@@ -149,7 +150,7 @@ void vlink_keyx(ECPSocket *sock, int keyx_period) {
LOG(LOG_DEBUG, "vlink_keyx: disconnect\n");
/* close all inbound connections */
- while ((_conn = ecp_sock_search_gc(conn->sock, &conn->remote.key_perma.public))) {
+ while ((_conn = ecp_sock_gct_search(conn->sock, &conn->remote.key_perma.public))) {
ecp_conn_close(_conn);
ecp_conn_refcount_dec(_conn);
}