char addrstr[INET6_ADDRSTRLEN];
uint64_t version = 0;
+ host->last_ping = unet_gettime();
+
if (net->net_data_len)
version = net->net_data_version;
{
struct network *net = container_of(t, struct network, pex.request_update_timer);
struct network_pex *pex = &net->pex;
- struct network_pex_host *host;
+ struct network_pex_host *host, *tmp;
+ uint64_t now = unet_gettime();
- uloop_timeout_set(t, 5000);
+ uloop_timeout_set(t, 500);
-retry:
if (list_empty(&pex->hosts))
return;
- host = list_first_entry(&pex->hosts, struct network_pex_host, list);
- if (host->timeout && host->timeout < unet_gettime()) {
- list_del(&host->list);
- free(host);
- goto retry;
- }
+ list_for_each_entry_safe(host, tmp, &pex->hosts, list) {
+ if (host->timeout && host->timeout < now) {
+ list_del(&host->list);
+ free(host);
+ continue;
+ }
+
+ if (host->last_ping + 10 >= now)
+ continue;
- list_move_tail(&host->list, &pex->hosts);
- network_pex_host_request_update(net, host);
+ list_move_tail(&host->list, &pex->hosts);
+ network_pex_host_request_update(net, host);
+ }
}
void network_pex_init(struct network *net)
{
struct network_pex *pex = &net->pex;
struct network_pex_host *host;
+ uint64_t now = unet_gettime();
bool new_host = false;
list_for_each_entry(host, &pex->hosts, list) {
if (memcmp(&host->endpoint, ep, sizeof(host->endpoint)) != 0)
continue;
- list_move_tail(&host->list, &pex->hosts);
+ if (host->last_ping + 10 < now) {
+ list_move_tail(&host->list, &pex->hosts);
+ network_pex_host_request_update(net, host);
+ }
goto out;
}
out:
if (timeout && (new_host || host->timeout))
host->timeout = timeout + unet_gettime();
- network_pex_host_request_update(net, host);
}
static void