From 5a7d9644e4712bde19bc9b01f8ae198c0d9b0fe9 Mon Sep 17 00:00:00 2001 From: tiptorrent development team Date: Mon, 13 Sep 2021 16:40:46 +0200 Subject: allow to reuse redirections A redirection can be reused up to max_clients times. --- src/core.c | 12 +++++++++--- src/core.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core.c b/src/core.c index 952e1b0..f46df39 100644 --- a/src/core.c +++ b/src/core.c @@ -246,6 +246,7 @@ static int tip_client_redirect_create(const struct tip_client *cli) redir->addr = cli->addr; redir->addr.sin_port = htons(9999); redir->uri = strdup(cli->uri); + redir->users = max_clients; list_add_tail(&redir->list, &client_redirect_list); ev_timer_init(&redir->timer, tip_client_redirect_timer_cb, 60, 0.); @@ -386,10 +387,15 @@ bool tip_client_redirect(struct tip_client *cli) inet_ntoa(redir->addr.sin_addr), htons(redir->addr.sin_port), cli->uri); - free((void *)redir->uri); - ev_timer_stop(tip_main_loop, &redir->timer); list_del(&redir->list); - free(redir); + if (--redir->users == 0) { + free((void *)redir->uri); + ev_timer_stop(tip_main_loop, &redir->timer); + free(redir); + } else { + /* reinsert at the end to round-robin redirections. */ + list_add_tail(&redir->list, &client_redirect_list); + } return true; } diff --git a/src/core.h b/src/core.h index 88a07a9..7d6d403 100644 --- a/src/core.h +++ b/src/core.h @@ -84,6 +84,7 @@ struct tip_client_redirect { struct sockaddr_in addr; const char *uri; struct ev_timer timer; + uint32_t users; }; #endif -- cgit v1.2.3-18-g5258