Add mud_set_keyx_timeout()

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2018-03-14 06:54:38 +00:00
parent 467310bb4f
commit ef319d2153
2 changed files with 24 additions and 1 deletions

24
mud.c
View File

@@ -144,6 +144,7 @@ struct mud {
int fd; int fd;
uint64_t send_timeout; uint64_t send_timeout;
uint64_t time_tolerance; uint64_t time_tolerance;
uint64_t keyx_timeout;
struct mud_path *paths; struct mud_path *paths;
unsigned count; unsigned count;
struct { struct {
@@ -622,6 +623,26 @@ mud_set_time_tolerance(struct mud *mud, unsigned long msec)
return 0; return 0;
} }
int
mud_set_keyx_timeout(struct mud *mud, unsigned long msec)
{
if (!msec) {
errno = EINVAL;
return -1;
}
const uint64_t x = msec * MUD_ONE_MSEC;
if ((uint64_t)msec != x / MUD_ONE_MSEC) {
errno = ERANGE;
return -1;
}
mud->keyx_timeout = x;
return 0;
}
int int
mud_set_state(struct mud *mud, struct sockaddr *peer, enum mud_state state) mud_set_state(struct mud *mud, struct sockaddr *peer, enum mud_state state)
{ {
@@ -830,6 +851,7 @@ mud_create(struct sockaddr *addr)
mud->send_timeout = MUD_SEND_TIMEOUT; mud->send_timeout = MUD_SEND_TIMEOUT;
mud->time_tolerance = MUD_TIME_TOLERANCE; mud->time_tolerance = MUD_TIME_TOLERANCE;
mud->keyx_timeout = MUD_KEYX_TIMEOUT;
mud->tc = MUD_PACKET_TC; mud->tc = MUD_PACKET_TC;
mud->mtu = sizeof(struct mud_packet); mud->mtu = sizeof(struct mud_packet);
@@ -1259,7 +1281,7 @@ mud_update(struct mud *mud, uint64_t now)
int update_keyx = 0; int update_keyx = 0;
if (mud_timeout(now, mud->crypto.time, MUD_KEYX_TIMEOUT)) { if (mud_timeout(now, mud->crypto.time, mud->keyx_timeout)) {
mud_keyx_init(mud); mud_keyx_init(mud);
update_keyx = 1; update_keyx = 1;
mud->crypto.time = now; mud->crypto.time = now;

1
mud.h
View File

@@ -55,6 +55,7 @@ size_t mud_get_mtu (struct mud *);
int mud_set_send_timeout (struct mud *, unsigned long); int mud_set_send_timeout (struct mud *, unsigned long);
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_tc (struct mud *, int); int mud_set_tc (struct mud *, int);
int mud_set_aes (struct mud *); int mud_set_aes (struct mud *);