Skip to content

Commit be17576

Browse files
committed
pex: keep active pex hosts after the specified timeout
Keep them as long as they have sent us a valid message in the last minute Signed-off-by: Felix Fietkau <[email protected]>
1 parent e58a566 commit be17576

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

pex.c

+20
Original file line numberDiff line numberDiff line change
@@ -795,12 +795,16 @@ void network_pex_close(struct network *net)
795795
{
796796
struct network_pex *pex = &net->pex;
797797
struct network_pex_host *host, *tmp;
798+
uint64_t now = unet_gettime();
798799

799800
uloop_timeout_cancel(&pex->request_update_timer);
800801
list_for_each_entry_safe(host, tmp, &pex->hosts, list) {
801802
if (host->timeout)
802803
continue;
803804

805+
if (host->last_active + UNETD_PEX_HOST_ACITVE_TIMEOUT >= now)
806+
continue;
807+
804808
list_del(&host->list);
805809
free(host);
806810
}
@@ -837,6 +841,20 @@ global_pex_find_network(const uint8_t *id)
837841
return NULL;
838842
}
839843

844+
static void
845+
global_pex_set_active(struct network *net, struct sockaddr_in6 *addr)
846+
{
847+
struct network_pex *pex = &net->pex;
848+
struct network_pex_host *host;
849+
850+
list_for_each_entry(host, &pex->hosts, list) {
851+
if (memcmp(&host->endpoint.in6, addr, sizeof(*addr)) != 0)
852+
continue;
853+
854+
host->last_active = unet_gettime();
855+
}
856+
}
857+
840858
static void
841859
global_pex_recv(struct pex_hdr *hdr, struct sockaddr_in6 *addr)
842860
{
@@ -856,6 +874,8 @@ global_pex_recv(struct pex_hdr *hdr, struct sockaddr_in6 *addr)
856874

857875
*(uint64_t *)hdr->id ^= pex_network_hash(net->config.auth_key, ehdr->nonce);
858876

877+
global_pex_set_active(net, addr);
878+
859879
D("PEX global rx op=%d", hdr->opcode);
860880
switch (hdr->opcode) {
861881
case PEX_MSG_HELLO:

pex.h

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct network;
1212
struct network_pex_host {
1313
struct list_head list;
1414
uint64_t timeout;
15+
uint64_t last_active;
1516
union network_endpoint endpoint;
1617
};
1718

unetd.h

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ extern int global_pex_port;
4545

4646
#define UNETD_DATA_UPDATE_DELAY (10 * 1000)
4747

48+
#define UNETD_PEX_HOST_ACITVE_TIMEOUT 60
49+
4850
void unetd_write_hosts(void);
4951
int unetd_attach_mssfix(int ifindex, int mtu);
5052

0 commit comments

Comments
 (0)