From d4546ccae0d4960641b261efe1d0e7a8b2b8a1fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Mon, 29 Jan 2018 15:47:39 +0000 Subject: [PATCH] Add mud_del_path() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- mud.c | 32 ++++++++++++++++++++++++++++++++ mud.h | 1 + 2 files changed, 33 insertions(+) diff --git a/mud.c b/mud.c index e306ec4..cf6ec1b 100644 --- a/mud.c +++ b/mud.c @@ -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; diff --git a/mud.h b/mud.h index d4e3333..1e8caae 100644 --- a/mud.h +++ b/mud.h @@ -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);