Instead of rotating and picking one every 5 seconds, pick one from the list
every 500ms, but enforce a minimum interval of 10 seconds per host between
pings
Signed-off-by: Felix Fietkau <nbd@nbd.name>
char addrstr[INET6_ADDRSTRLEN];
uint64_t version = 0;
char addrstr[INET6_ADDRSTRLEN];
uint64_t version = 0;
+ host->last_ping = unet_gettime();
+
if (net->net_data_len)
version = net->net_data_version;
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 *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);
if (list_empty(&pex->hosts))
return;
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)
}
void network_pex_init(struct network *net)
{
struct network_pex *pex = &net->pex;
struct network_pex_host *host;
{
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;
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);
+ }
out:
if (timeout && (new_host || host->timeout))
host->timeout = timeout + unet_gettime();
out:
if (timeout && (new_host || host->timeout))
host->timeout = timeout + unet_gettime();
- network_pex_host_request_update(net, host);
struct list_head list;
uint64_t timeout;
uint64_t last_active;
struct list_head list;
uint64_t timeout;
uint64_t last_active;
union network_endpoint endpoint;
};
union network_endpoint endpoint;
};