Code cleanup

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2019-12-17 16:12:16 +00:00
parent 7179de77da
commit 6b58ebb993
2 changed files with 20 additions and 17 deletions

30
mud.c
View File

@@ -132,7 +132,7 @@ struct mud_msg {
unsigned char rx_bytes[MUD_U48_SIZE]; unsigned char rx_bytes[MUD_U48_SIZE];
unsigned char rx_total[MUD_U48_SIZE]; unsigned char rx_total[MUD_U48_SIZE];
// unsigned char delay[MUD_U48_SIZE]; // unsigned char delay[MUD_U48_SIZE];
unsigned char rate_max[MUD_U48_SIZE]; unsigned char tx_max_rate[MUD_U48_SIZE];
unsigned char loss; unsigned char loss;
}; };
@@ -646,7 +646,7 @@ mud_get_path(struct mud *mud, struct sockaddr_storage *local_addr,
path->mtu.max = MUD_MTU_MAX; path->mtu.max = MUD_MTU_MAX;
path->mtu.probe = MUD_MTU_MAX; path->mtu.probe = MUD_MTU_MAX;
path->msg.timeout = MUD_MSG_TIMEOUT; path->conf.msg_timeout = MUD_MSG_TIMEOUT;
return path; return path;
} }
@@ -1149,7 +1149,7 @@ mud_send_msg(struct mud *mud, struct mud_path *path, uint64_t now,
mud_write48(msg->rx_total, path->rx.total); mud_write48(msg->rx_total, path->rx.total);
mud_write48(msg->fwd_bytes, fwd_bytes); mud_write48(msg->fwd_bytes, fwd_bytes);
mud_write48(msg->fwd_total, fwd_total); mud_write48(msg->fwd_total, fwd_total);
mud_write48(msg->rate_max, path->rx.rate_max); mud_write48(msg->tx_max_rate, path->conf.tx_max_rate);
msg->loss = (unsigned char)path->tx.loss; msg->loss = (unsigned char)path->tx.loss;
@@ -1340,11 +1340,11 @@ mud_recv_msg(struct mud *mud, struct mud_path *path,
mud_keyx_init(mud, now); mud_keyx_init(mud, now);
path->state = (enum mud_state)msg->state; path->state = (enum mud_state)msg->state;
const uint64_t rate_max = mud_read48(msg->rate_max); const uint64_t tx_max_rate = mud_read48(msg->tx_max_rate);
if (path->tx.rate_max != rate_max) { if (path->conf.tx_max_rate != tx_max_rate) {
path->tx.rate_max = rate_max; path->conf.tx_max_rate = tx_max_rate;
path->tx.rate = rate_max; path->tx.rate = tx_max_rate;
} }
} }
@@ -1501,7 +1501,7 @@ mud_update(struct mud *mud)
} }
if (mud->peer.set) { if (mud->peer.set) {
if (mud_timeout(now, path->msg.time, path->msg.timeout)) { if (mud_timeout(now, path->msg.time, path->conf.msg_timeout)) {
mud_send_msg(mud, path, now, 0, 0, 0, path->mtu.probe); mud_send_msg(mud, path, now, 0, 0, 0, path->mtu.probe);
path->msg.time = now; path->msg.time = now;
} }
@@ -1522,8 +1522,8 @@ mud_update(struct mud *mud)
int int
mud_set_state(struct mud *mud, struct sockaddr *addr, mud_set_state(struct mud *mud, struct sockaddr *addr,
enum mud_state state, enum mud_state state,
unsigned long rate_tx, unsigned long tx_max_rate,
unsigned long rate_rx, unsigned long rx_max_rate,
unsigned long msg_timeout) unsigned long msg_timeout)
{ {
if (!mud->peer.set || state > MUD_UP) { if (!mud->peer.set || state > MUD_UP) {
@@ -1542,14 +1542,14 @@ mud_set_state(struct mud *mud, struct sockaddr *addr,
if (!path) if (!path)
return -1; return -1;
if (rate_tx) if (tx_max_rate)
path->tx.rate_max = path->tx.rate = rate_tx; path->conf.tx_max_rate = path->tx.rate = tx_max_rate;
if (rate_rx) if (rx_max_rate)
path->rx.rate_max = path->rx.rate = rate_rx; path->conf.rx_max_rate = path->rx.rate = rx_max_rate;
if (msg_timeout) if (msg_timeout)
path->msg.timeout = msg_timeout; path->conf.msg_timeout = msg_timeout;
if (state && path->state != state) { if (state && path->state != state) {
path->state = state; path->state = state;

7
mud.h
View File

@@ -36,7 +36,6 @@ struct mud_path {
uint64_t bytes; uint64_t bytes;
uint64_t time; uint64_t time;
uint64_t rate; uint64_t rate;
uint64_t rate_max;
uint64_t loss; uint64_t loss;
} tx, rx; } tx, rx;
struct { struct {
@@ -48,7 +47,6 @@ struct mud_path {
uint64_t acc_time; uint64_t acc_time;
} tx, rx; } tx, rx;
uint64_t time; uint64_t time;
uint64_t timeout;
uint64_t sent; uint64_t sent;
uint64_t set; uint64_t set;
} msg; } msg;
@@ -58,6 +56,11 @@ struct mud_path {
size_t probe; size_t probe;
size_t ok; size_t ok;
} mtu; } mtu;
struct {
uint64_t tx_max_rate;
uint64_t rx_max_rate;
uint64_t msg_timeout;
} conf;
uint64_t window; uint64_t window;
uint64_t window_time; uint64_t window_time;
struct mud_pubkey pk; struct mud_pubkey pk;