Add mud_del_path()

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2018-01-29 15:47:39 +00:00
parent 61e7a23a11
commit d4546ccae0
2 changed files with 33 additions and 0 deletions

32
mud.c
View File

@@ -77,6 +77,7 @@
struct mud_path {
struct {
unsigned skip : 1;
unsigned backup : 1;
} state;
struct sockaddr_storage local_addr, addr;
@@ -522,6 +523,31 @@ mud_peer(struct mud *mud, const char *host, int port)
return 0;
}
int
mud_del_path(struct mud *mud, const char *name)
{
if (!name) {
errno = EINVAL;
return -1;
}
struct sockaddr_storage addr;
if (mud_addrinfo(&addr, name, 0))
return -1;
struct mud_path *path;
for (path = mud->path; path; path = path->next) {
if (mud_cmp_addr(&addr, mud->peer.set ? &path->local_addr : &path->addr))
continue;
path->state.skip = 1;
}
return 0;
}
int
mud_add_path(struct mud *mud, const char *name)
{
@@ -1197,6 +1223,9 @@ mud_update(struct mud *mud)
struct mud_path *path = mud->path;
for (; path; path = path->next) {
if (path->state.skip)
continue;
if (update_keyx || mud_timeout(now, path->recv_time, mud->send_timeout + MUD_ONE_SEC))
path->conf.remote = 0;
@@ -1238,6 +1267,9 @@ mud_send(struct mud *mud, const void *data, size_t size, int tc)
int64_t limit_min = INT64_MAX;
for (path = mud->path; path; path = path->next) {
if (path->state.skip)
continue;
if (path->state.backup) {
path_backup = path;
continue;

1
mud.h
View File

@@ -24,6 +24,7 @@ int mud_set_aes (struct mud *);
int mud_peer (struct mud *, const char *, int);
int mud_add_path (struct mud *, const char *);
int mud_del_path (struct mud *, const char *);
int mud_recv (struct mud *, void *, size_t);
int mud_send (struct mud *, const void *, size_t, int);