Don't wake up without paths

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2019-03-09 14:37:32 +00:00
parent eab4cdb1ad
commit f67a5b4fed
2 changed files with 12 additions and 6 deletions

16
mud.c
View File

@@ -1467,7 +1467,7 @@ mud_update(struct mud *mud, uint64_t now)
mud->mtu = mtu ?: MUD_MTU_MIN; mud->mtu = mtu ?: MUD_MTU_MIN;
} }
unsigned long long
mud_send_wait(struct mud *mud) mud_send_wait(struct mud *mud)
{ {
const uint64_t now = mud_now(); const uint64_t now = mud_now();
@@ -1477,12 +1477,18 @@ mud_send_wait(struct mud *mud)
if (mud->window) if (mud->window)
return 0; return 0;
unsigned long dt = MUD_ONE_SEC - 1; long dt = MUD_ONE_SEC - 1;
unsigned not_down = 0;
for (unsigned i = 0; i < mud->count; i++) { for (unsigned i = 0; i < mud->count; i++) {
struct mud_path *path = &mud->paths[i]; struct mud_path *path = &mud->paths[i];
if (path->state <= MUD_DOWN || !path->ok) if (path->state <= MUD_DOWN)
continue;
not_down++;
if (!path->ok)
continue; continue;
uint64_t elapsed = MUD_TIME_MASK(now - path->window_time); uint64_t elapsed = MUD_TIME_MASK(now - path->window_time);
@@ -1493,10 +1499,10 @@ mud_send_wait(struct mud *mud)
uint64_t new_dt = MUD_WINDOW_TIMEOUT - elapsed; uint64_t new_dt = MUD_WINDOW_TIMEOUT - elapsed;
if ((uint64_t)dt > new_dt) if ((uint64_t)dt > new_dt)
dt = (unsigned long)new_dt; dt = (long)new_dt;
} }
return dt; return not_down ? dt : -1;
} }
unsigned long unsigned long

2
mud.h
View File

@@ -63,7 +63,7 @@ int mud_get_key (struct mud *, unsigned char *, size_t *);
void mud_set_mtu (struct mud *, size_t); void mud_set_mtu (struct mud *, size_t);
size_t mud_get_mtu (struct mud *); size_t mud_get_mtu (struct mud *);
unsigned long mud_send_wait (struct mud *); long mud_send_wait (struct mud *);
unsigned long mud_sync (struct mud *); unsigned long mud_sync (struct mud *);
int mud_set_time_tolerance (struct mud *, unsigned long); int mud_set_time_tolerance (struct mud *, unsigned long);