From 40983ee4f1eb7976340df133cb5c0e586b9a5c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Fri, 15 Feb 2019 09:35:24 +0000 Subject: [PATCH] Compute path->ok both sides MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- mud.c | 40 +++++++++++++++++++--------------------- mud.h | 2 +- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/mud.c b/mud.c index 8029e56..6141ccf 100644 --- a/mud.c +++ b/mud.c @@ -115,7 +115,7 @@ struct mud_addr { struct mud_msg { unsigned char sent[MUD_U48_SIZE]; - unsigned char state, ok; + unsigned char state; struct mud_addr addr; unsigned char pub[MUD_PUB_SIZE]; unsigned char aes; @@ -1114,7 +1114,6 @@ mud_send_msg(struct mud *mud, struct mud_path *path, uint64_t now, } msg->state = (unsigned char)path->state; - msg->ok = path->ok; memcpy(msg->pub, mud->crypto.pub.local, @@ -1129,24 +1128,30 @@ mud_send_msg(struct mud *mud, struct mud_path *path, uint64_t now, if (mud->peer.set) { if (sent) { - dt = MUD_TIME_MASK(now - path->recv.stat_time); + dt = MUD_TIME_MASK(now - path->recv.msg_time); path->recv.bytes = 0; - path->recv.stat_time = now; + path->recv.msg_time = now; } else { - dt = MUD_TIME_MASK(now - path->send.stat_time); + dt = MUD_TIME_MASK(now - path->send.msg_time); path->send.bytes = 0; - path->send.stat_time = now; + path->send.msg_time = now; + + if (path->msg_sent < MUD_MSG_SENT_MAX) + path->msg_sent++; } } else { - dt = MUD_TIME_MASK(now - path->recv.stat_time); + dt = MUD_TIME_MASK(now - path->recv.msg_time); path->send.bytes = 0; - path->send.stat_time = now; + path->send.msg_time = now; path->recv.bytes = 0; - path->recv.stat_time = now; + path->recv.msg_time = now; + + if (path->msg_sent < MUD_MSG_SENT_MAX) + path->msg_sent++; } mud_write48(msg->dt, dt); @@ -1154,9 +1159,6 @@ mud_send_msg(struct mud *mud, struct mud_path *path, uint64_t now, mud_write48(msg->fwd_send, fwd_send); mud_write48(msg->rate, path->rate_rx); - if (path->msg_sent < MUD_MSG_SENT_MAX) - path->msg_sent++; - const struct mud_crypto_opt opt = { .dst = dst, .src = src, @@ -1248,16 +1250,19 @@ mud_recv_msg(struct mud *mud, struct mud_path *path, path->mtu.min = size + 1; path->mtu.count = 0; } + mud_update_stat(&path->rtt, MUD_TIME_MASK(now - peer_sent)); mud_update_window(mud, path, now, sent, mud_read48(msg->fwd_dt), mud_read48(msg->fwd_send), mud_read48(msg->dt), mud_read48(msg->recv)); + + path->msg_sent = 0; + path->ok = 1; } else { mud_keyx_init(mud, now); path->state = (enum mud_state)msg->state; - path->ok = msg->ok; mud_update_rate(mud, path, mud_read48(msg->rate)); } @@ -1369,13 +1374,9 @@ mud_recv(struct mud *mud, void *data, size_t size) if (path->state <= MUD_DOWN) return 0; - path->ok = 1; - if (MUD_MSG(send_time)) mud_recv_msg(mud, path, now, send_time, data, packet_size); - path->msg_sent = 0; - path->recv.total++; path->recv.time = now; path->recv.bytes += packet_size; @@ -1454,11 +1455,8 @@ mud_update(struct mud *mud, uint64_t now) } if (mud->peer.set) { - if (mud_timeout(now, path->send.stat_time, MUD_SEND_TIMEOUT)) + if (mud_timeout(now, path->send.msg_time, MUD_SEND_TIMEOUT)) mud_send_msg(mud, path, now, 0, 0, 0, 0); - } else { - if (mud_timeout(now, path->recv.time, MUD_MSG_SENT_MAX * MUD_SEND_TIMEOUT)) - mud_reset_path(mud, path); // XXX } window += path->window; diff --git a/mud.h b/mud.h index 6f33b5b..a45ba61 100644 --- a/mud.h +++ b/mud.h @@ -45,8 +45,8 @@ struct mud_path { struct { uint64_t total; uint64_t bytes; - uint64_t stat_time; uint64_t time; + uint64_t msg_time; } send, recv; struct mud_public pub; unsigned char ok;