@@ -279,6 +279,16 @@ network_pex_host_request_update(struct network *net, struct network_pex_host *ho
279
279
network_pex_host_send_endpoint_notify (net , host );
280
280
}
281
281
282
+ static void
283
+ network_pex_free_host (struct network * net , struct network_pex_host * host )
284
+ {
285
+ struct network_pex * pex = & net -> pex ;
286
+
287
+ pex -> num_hosts -- ;
288
+ list_del (& host -> list );
289
+ free (host );
290
+ }
291
+
282
292
static void
283
293
network_pex_request_update_cb (struct uloop_timeout * t )
284
294
{
@@ -294,8 +304,7 @@ network_pex_request_update_cb(struct uloop_timeout *t)
294
304
295
305
list_for_each_entry_safe (host , tmp , & pex -> hosts , list ) {
296
306
if (host -> timeout && host -> timeout < now ) {
297
- list_del (& host -> list );
298
- free (host );
307
+ network_pex_free_host (net , host );
299
308
continue ;
300
309
}
301
310
@@ -725,6 +734,7 @@ void network_pex_create_host(struct network *net, union network_endpoint *ep,
725
734
new_host = true;
726
735
memcpy (& host -> endpoint , ep , sizeof (host -> endpoint ));
727
736
list_add_tail (& host -> list , & pex -> hosts );
737
+ pex -> num_hosts ++ ;
728
738
729
739
out :
730
740
if (timeout && (new_host || host -> timeout ))
@@ -837,8 +847,7 @@ void network_pex_close(struct network *net)
837
847
if (host -> last_active + UNETD_PEX_HOST_ACITVE_TIMEOUT >= now )
838
848
continue ;
839
849
840
- list_del (& host -> list );
841
- free (host );
850
+ network_pex_free_host (net , host );
842
851
}
843
852
844
853
if (pex -> fd .fd < 0 )
@@ -854,10 +863,8 @@ void network_pex_free(struct network *net)
854
863
struct network_pex * pex = & net -> pex ;
855
864
struct network_pex_host * host , * tmp ;
856
865
857
- list_for_each_entry_safe (host , tmp , & pex -> hosts , list ) {
858
- list_del (& host -> list );
859
- free (host );
860
- }
866
+ list_for_each_entry_safe (host , tmp , & pex -> hosts , list )
867
+ network_pex_free_host (net , host );
861
868
}
862
869
863
870
static struct network *
@@ -954,8 +961,13 @@ global_pex_recv(void *msg, size_t msg_len, struct sockaddr_in6 *addr)
954
961
memcpy (& peer -> state .next_endpoint , addr , sizeof (* addr ));
955
962
if (hdr -> opcode == PEX_MSG_ENDPOINT_PORT_NOTIFY ) {
956
963
struct pex_endpoint_port_notify * port = data ;
964
+ union network_endpoint host_ep = {
965
+ .in6 = * addr
966
+ };
957
967
958
968
peer -> state .next_endpoint .in .sin_port = port -> port ;
969
+ if (net -> pex .num_hosts < NETWORK_PEX_HOSTS_LIMIT )
970
+ network_pex_create_host (net , & host_ep , 120 );
959
971
}
960
972
break ;
961
973
}
0 commit comments