Allow a different loss_limit per path
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
24
mud.c
24
mud.c
@@ -125,6 +125,7 @@ struct mud_msg {
|
|||||||
unsigned char mtu[2];
|
unsigned char mtu[2];
|
||||||
unsigned char loss;
|
unsigned char loss;
|
||||||
unsigned char fixed_rate;
|
unsigned char fixed_rate;
|
||||||
|
unsigned char loss_limit;
|
||||||
struct mud_addr addr;
|
struct mud_addr addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -144,7 +145,6 @@ struct mud {
|
|||||||
int backup;
|
int backup;
|
||||||
uint64_t keepalive;
|
uint64_t keepalive;
|
||||||
uint64_t time_tolerance;
|
uint64_t time_tolerance;
|
||||||
uint64_t loss_limit;
|
|
||||||
struct sockaddr_storage addr;
|
struct sockaddr_storage addr;
|
||||||
struct mud_path *paths;
|
struct mud_path *paths;
|
||||||
unsigned count;
|
unsigned count;
|
||||||
@@ -644,6 +644,7 @@ mud_get_path(struct mud *mud, struct sockaddr_storage *local_addr,
|
|||||||
path->state = MUD_UP;
|
path->state = MUD_UP;
|
||||||
path->conf.beat = 100 * MUD_ONE_MSEC;
|
path->conf.beat = 100 * MUD_ONE_MSEC;
|
||||||
path->conf.fixed_rate = 1;
|
path->conf.fixed_rate = 1;
|
||||||
|
path->conf.loss_limit = 255;
|
||||||
path->idle = mud_now(mud);
|
path->idle = mud_now(mud);
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
@@ -763,7 +764,6 @@ mud_set_conf(struct mud *mud, struct mud_conf *conf)
|
|||||||
uint64_t keepalive = mud->keepalive;
|
uint64_t keepalive = mud->keepalive;
|
||||||
uint64_t timetolerance = mud->time_tolerance;
|
uint64_t timetolerance = mud->time_tolerance;
|
||||||
uint64_t kxtimeout = mud->keyx.timeout;
|
uint64_t kxtimeout = mud->keyx.timeout;
|
||||||
uint64_t losslimit = mud->loss_limit;
|
|
||||||
int tc = mud->tc;
|
int tc = mud->tc;
|
||||||
|
|
||||||
if (mud_set_msec(&keepalive, conf->keepalive))
|
if (mud_set_msec(&keepalive, conf->keepalive))
|
||||||
@@ -775,14 +775,6 @@ mud_set_conf(struct mud *mud, struct mud_conf *conf)
|
|||||||
if (mud_set_msec(&kxtimeout, conf->kxtimeout))
|
if (mud_set_msec(&kxtimeout, conf->kxtimeout))
|
||||||
return -3;
|
return -3;
|
||||||
|
|
||||||
if (conf->losslimit) {
|
|
||||||
if (conf->losslimit > 100) {
|
|
||||||
errno = ERANGE;
|
|
||||||
return -4;
|
|
||||||
}
|
|
||||||
losslimit = conf->losslimit * 255U / 100U;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (conf->tc & 1) {
|
if (conf->tc & 1) {
|
||||||
tc = conf->tc >> 1;
|
tc = conf->tc >> 1;
|
||||||
if (tc < 0 || tc > 255) {
|
if (tc < 0 || tc > 255) {
|
||||||
@@ -797,7 +789,6 @@ mud_set_conf(struct mud *mud, struct mud_conf *conf)
|
|||||||
mud->keepalive = keepalive;
|
mud->keepalive = keepalive;
|
||||||
mud->time_tolerance = timetolerance;
|
mud->time_tolerance = timetolerance;
|
||||||
mud->keyx.timeout = kxtimeout;
|
mud->keyx.timeout = kxtimeout;
|
||||||
mud->loss_limit = losslimit;
|
|
||||||
mud->tc = tc;
|
mud->tc = tc;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -952,7 +943,6 @@ mud_create(struct sockaddr *addr)
|
|||||||
mud->time_tolerance = 10 * MUD_ONE_MIN;
|
mud->time_tolerance = 10 * MUD_ONE_MIN;
|
||||||
mud->keyx.timeout = 60 * MUD_ONE_MIN;
|
mud->keyx.timeout = 60 * MUD_ONE_MIN;
|
||||||
mud->tc = 192; // CS6
|
mud->tc = 192; // CS6
|
||||||
mud->loss_limit = 25;
|
|
||||||
|
|
||||||
memcpy(&mud->addr, addr, addrlen);
|
memcpy(&mud->addr, addr, addrlen);
|
||||||
|
|
||||||
@@ -1135,6 +1125,7 @@ mud_send_msg(struct mud *mud, struct mud_path *path, uint64_t now,
|
|||||||
|
|
||||||
msg->loss = (unsigned char)path->tx.loss;
|
msg->loss = (unsigned char)path->tx.loss;
|
||||||
msg->fixed_rate = path->conf.fixed_rate;
|
msg->fixed_rate = path->conf.fixed_rate;
|
||||||
|
msg->loss_limit = path->conf.loss_limit;
|
||||||
|
|
||||||
const struct mud_crypto_opt opt = {
|
const struct mud_crypto_opt opt = {
|
||||||
.dst = dst,
|
.dst = dst,
|
||||||
@@ -1322,6 +1313,7 @@ mud_recv_msg(struct mud *mud, struct mud_path *path,
|
|||||||
|
|
||||||
path->conf.tx_max_rate = max_rate;
|
path->conf.tx_max_rate = max_rate;
|
||||||
path->conf.fixed_rate = msg->fixed_rate;
|
path->conf.fixed_rate = msg->fixed_rate;
|
||||||
|
path->conf.loss_limit = msg->loss_limit;
|
||||||
|
|
||||||
path->msg.sent++;
|
path->msg.sent++;
|
||||||
path->msg.time = now;
|
path->msg.time = now;
|
||||||
@@ -1446,7 +1438,7 @@ mud_path_is_ok(struct mud *mud, struct mud_path *path)
|
|||||||
if (!path->mtu.ok)
|
if (!path->mtu.ok)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (path->tx.loss > mud->loss_limit)
|
if (path->tx.loss > path->conf.loss_limit)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (mud->peer.set)
|
if (mud->peer.set)
|
||||||
@@ -1546,7 +1538,8 @@ mud_set_state(struct mud *mud, struct sockaddr *addr,
|
|||||||
unsigned long tx_max_rate,
|
unsigned long tx_max_rate,
|
||||||
unsigned long rx_max_rate,
|
unsigned long rx_max_rate,
|
||||||
unsigned long beat,
|
unsigned long beat,
|
||||||
unsigned char fixed_rate)
|
unsigned char fixed_rate,
|
||||||
|
unsigned char loss_limit)
|
||||||
{
|
{
|
||||||
if (!mud->peer.set || state > MUD_UP) {
|
if (!mud->peer.set || state > MUD_UP) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
@@ -1576,6 +1569,9 @@ mud_set_state(struct mud *mud, struct sockaddr *addr,
|
|||||||
if (fixed_rate)
|
if (fixed_rate)
|
||||||
path->conf.fixed_rate = fixed_rate >> 1;
|
path->conf.fixed_rate = fixed_rate >> 1;
|
||||||
|
|
||||||
|
if (loss_limit)
|
||||||
|
path->conf.loss_limit = loss_limit;
|
||||||
|
|
||||||
if (state && path->state != state) {
|
if (state && path->state != state) {
|
||||||
path->state = state;
|
path->state = state;
|
||||||
mud_reset_path(path);
|
mud_reset_path(path);
|
||||||
|
|||||||
5
mud.h
5
mud.h
@@ -26,7 +26,6 @@ struct mud_conf {
|
|||||||
unsigned long keepalive;
|
unsigned long keepalive;
|
||||||
unsigned long timetolerance;
|
unsigned long timetolerance;
|
||||||
unsigned long kxtimeout;
|
unsigned long kxtimeout;
|
||||||
unsigned losslimit;
|
|
||||||
int tc;
|
int tc;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,6 +64,7 @@ struct mud_path {
|
|||||||
uint64_t rx_max_rate;
|
uint64_t rx_max_rate;
|
||||||
uint64_t beat;
|
uint64_t beat;
|
||||||
unsigned char fixed_rate;
|
unsigned char fixed_rate;
|
||||||
|
unsigned char loss_limit;
|
||||||
} conf;
|
} conf;
|
||||||
uint64_t idle;
|
uint64_t idle;
|
||||||
unsigned char ok;
|
unsigned char ok;
|
||||||
@@ -95,7 +95,8 @@ int mud_set_aes (struct mud *);
|
|||||||
int mud_set_conf (struct mud *, struct mud_conf *);
|
int mud_set_conf (struct mud *, struct mud_conf *);
|
||||||
|
|
||||||
int mud_set_state (struct mud *, struct sockaddr *, enum mud_state,
|
int mud_set_state (struct mud *, struct sockaddr *, enum mud_state,
|
||||||
unsigned long, unsigned long, unsigned long, unsigned char);
|
unsigned long, unsigned long, unsigned long,
|
||||||
|
unsigned char, unsigned char);
|
||||||
|
|
||||||
int mud_peer (struct mud *, struct sockaddr *);
|
int mud_peer (struct mud *, struct sockaddr *);
|
||||||
|
|
||||||
|
|||||||
2
test.c
2
test.c
@@ -52,7 +52,7 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
// ...from loopback at 1MBps (not 1Mbps)
|
// ...from loopback at 1MBps (not 1Mbps)
|
||||||
if (mud_set_state(mud, (struct sockaddr *)&local,
|
if (mud_set_state(mud, (struct sockaddr *)&local,
|
||||||
MUD_UP, 1000 * 1000, 1000 * 1000, 0, 0)) {
|
MUD_UP, 1000 * 1000, 1000 * 1000, 0, 0, 0)) {
|
||||||
perror("mud_set_state");
|
perror("mud_set_state");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user