Compute path->ok both sides

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2019-02-15 09:35:24 +00:00
parent 9eac498d81
commit 40983ee4f1
2 changed files with 20 additions and 22 deletions

40
mud.c
View File

@@ -115,7 +115,7 @@ struct mud_addr {
struct mud_msg { struct mud_msg {
unsigned char sent[MUD_U48_SIZE]; unsigned char sent[MUD_U48_SIZE];
unsigned char state, ok; unsigned char state;
struct mud_addr addr; struct mud_addr addr;
unsigned char pub[MUD_PUB_SIZE]; unsigned char pub[MUD_PUB_SIZE];
unsigned char aes; 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->state = (unsigned char)path->state;
msg->ok = path->ok;
memcpy(msg->pub, memcpy(msg->pub,
mud->crypto.pub.local, 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 (mud->peer.set) {
if (sent) { 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.bytes = 0;
path->recv.stat_time = now; path->recv.msg_time = now;
} else { } 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.bytes = 0;
path->send.stat_time = now; path->send.msg_time = now;
if (path->msg_sent < MUD_MSG_SENT_MAX)
path->msg_sent++;
} }
} else { } 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.bytes = 0;
path->send.stat_time = now; path->send.msg_time = now;
path->recv.bytes = 0; 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); 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->fwd_send, fwd_send);
mud_write48(msg->rate, path->rate_rx); mud_write48(msg->rate, path->rate_rx);
if (path->msg_sent < MUD_MSG_SENT_MAX)
path->msg_sent++;
const struct mud_crypto_opt opt = { const struct mud_crypto_opt opt = {
.dst = dst, .dst = dst,
.src = src, .src = src,
@@ -1248,16 +1250,19 @@ mud_recv_msg(struct mud *mud, struct mud_path *path,
path->mtu.min = size + 1; path->mtu.min = size + 1;
path->mtu.count = 0; path->mtu.count = 0;
} }
mud_update_stat(&path->rtt, MUD_TIME_MASK(now - peer_sent)); mud_update_stat(&path->rtt, MUD_TIME_MASK(now - peer_sent));
mud_update_window(mud, path, now, sent, mud_update_window(mud, path, now, sent,
mud_read48(msg->fwd_dt), mud_read48(msg->fwd_dt),
mud_read48(msg->fwd_send), mud_read48(msg->fwd_send),
mud_read48(msg->dt), mud_read48(msg->dt),
mud_read48(msg->recv)); mud_read48(msg->recv));
path->msg_sent = 0;
path->ok = 1;
} else { } else {
mud_keyx_init(mud, now); mud_keyx_init(mud, now);
path->state = (enum mud_state)msg->state; path->state = (enum mud_state)msg->state;
path->ok = msg->ok;
mud_update_rate(mud, path, mud_read48(msg->rate)); 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) if (path->state <= MUD_DOWN)
return 0; return 0;
path->ok = 1;
if (MUD_MSG(send_time)) if (MUD_MSG(send_time))
mud_recv_msg(mud, path, now, send_time, data, packet_size); mud_recv_msg(mud, path, now, send_time, data, packet_size);
path->msg_sent = 0;
path->recv.total++; path->recv.total++;
path->recv.time = now; path->recv.time = now;
path->recv.bytes += packet_size; path->recv.bytes += packet_size;
@@ -1454,11 +1455,8 @@ mud_update(struct mud *mud, uint64_t now)
} }
if (mud->peer.set) { 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); 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; window += path->window;

2
mud.h
View File

@@ -45,8 +45,8 @@ struct mud_path {
struct { struct {
uint64_t total; uint64_t total;
uint64_t bytes; uint64_t bytes;
uint64_t stat_time;
uint64_t time; uint64_t time;
uint64_t msg_time;
} send, recv; } send, recv;
struct mud_public pub; struct mud_public pub;
unsigned char ok; unsigned char ok;