Return MTU probing status in mud_update()

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2020-01-03 20:49:04 +00:00
parent 2a812f332f
commit e3689d29b7
3 changed files with 14 additions and 9 deletions

16
mud.c
View File

@@ -1415,10 +1415,11 @@ mud_cleanup_path(struct mud *mud, uint64_t now, struct mud_path *path)
return path->state <= MUD_DOWN; return path->state <= MUD_DOWN;
} }
static int int
mud_update(struct mud *mud) mud_update(struct mud *mud)
{ {
int count = 0; int count = 0;
int mtu_probe = 0;
uint64_t rate = 0; uint64_t rate = 0;
size_t mtu = 0; size_t mtu = 0;
@@ -1436,6 +1437,9 @@ mud_update(struct mud *mud)
path->ok = 0; path->ok = 0;
count++; count++;
if (path->mtu.probe)
mtu_probe = 1;
if (!mud->backup && path->state == MUD_BACKUP) if (!mud->backup && path->state == MUD_BACKUP)
continue; continue;
@@ -1482,7 +1486,10 @@ mud_update(struct mud *mud)
mud->rate = rate; mud->rate = rate;
mud->mtu = mtu; mud->mtu = mtu;
return count; if (!count)
return -1;
return (mtu_probe << 1) | (mud->window < 1500);
} }
int int
@@ -1526,12 +1533,9 @@ mud_set_state(struct mud *mud, struct sockaddr *addr,
return 0; return 0;
} }
long int
mud_send_wait(struct mud *mud) mud_send_wait(struct mud *mud)
{ {
if (!mud_update(mud))
return -1;
return mud->window < 1500; return mud->window < 1500;
} }

5
mud.h
View File

@@ -70,6 +70,9 @@ struct mud_bad {
struct mud *mud_create (struct sockaddr *); struct mud *mud_create (struct sockaddr *);
void mud_delete (struct mud *); void mud_delete (struct mud *);
int mud_update (struct mud *);
int mud_send_wait (struct mud *);
int mud_get_fd (struct mud *); int mud_get_fd (struct mud *);
size_t mud_get_mtu (struct mud *); size_t mud_get_mtu (struct mud *);
int mud_get_bad (struct mud *, struct mud_bad *); int mud_get_bad (struct mud *, struct mud_bad *);
@@ -77,8 +80,6 @@ int mud_get_bad (struct mud *, struct mud_bad *);
int mud_set_key (struct mud *, unsigned char *, size_t); int mud_set_key (struct mud *, unsigned char *, size_t);
int mud_get_key (struct mud *, unsigned char *, size_t *); int mud_get_key (struct mud *, unsigned char *, size_t *);
long mud_send_wait (struct mud *);
int mud_set_time_tolerance (struct mud *, unsigned long); int mud_set_time_tolerance (struct mud *, unsigned long);
int mud_set_keyx_timeout (struct mud *, unsigned long); int mud_set_keyx_timeout (struct mud *, unsigned long);
int mud_set_loss_limit (struct mud *, unsigned); int mud_set_loss_limit (struct mud *, unsigned);

2
test.c
View File

@@ -62,7 +62,7 @@ main(int argc, char **argv)
for (;;) { for (;;) {
// mandatory, mud have lot of work to do. // mandatory, mud have lot of work to do.
if (mud_send_wait(mud)) if (mud_update(mud))
usleep(100000); // don't use all the cpu usleep(100000); // don't use all the cpu
if (client) { if (client) {