From fb3ae8985db2f41c498b4fdaf2ca1566dbc84954 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 16 Dec 2014 14:51:36 +0100 Subject: [PATCH] Add a function to set the default white/blacklisting behaviour. This function should be called right after meshlink_open(), and will apply the default white/blacklist setting to newly learned nodes. The status can later be changed using the meshlink_whitelist() and meshlink_blacklist() functions. --- src/meshlink.c | 4 ++++ src/meshlink.h | 16 ++++++++++++++-- src/meshlink_internal.h | 2 ++ src/protocol_edge.c | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/meshlink.c b/src/meshlink.c index df257bf6..6ebbdcb0 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1825,6 +1825,10 @@ void meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node) { return; } +void meshlink_set_default_blacklist(meshlink_handle_t *mesh, bool blacklist) { + mesh->default_blacklist = blacklist; +} + /* Hint that a hostname may be found at an address * See header file for detailed comment. */ diff --git a/src/meshlink.h b/src/meshlink.h index 5777301a..75c49327 100644 --- a/src/meshlink.h +++ b/src/meshlink.h @@ -479,9 +479,21 @@ extern void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node); * and will send data to it and accept any data received from it. * * @param mesh A handle which represents an instance of MeshLink. - * @param node A pointer to a meshlink_node_t describing the node to be blacklisted. + * @param node A pointer to a meshlink_node_t describing the node to be whitelisted. */ -extern void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node); +extern void meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node); + +/// Set whether new nodes are blacklisted by default. +/** This function sets the blacklist behaviour for newly discovered nodes. + * If set to true, new nodes will be automatically blacklisted. + * If set to false, which is the default, new nodes are automatically whitelisted. + * The whitelist/blacklist status of a node may be changed afterwards with the + * meshlink_whitelist() and meshlink_blacklist() functions. + * + * @param mesh A handle which represents an instance of MeshLink. + * @param blacklist True if new nodes are to be blacklisted, false if whitelisted. + */ +extern void meshlink_set_default_blacklist(meshlink_handle_t *mesh, bool blacklist); /// A callback for accepting incoming channels. /** This function is called whenever a remote node wants to open a channel to the local node. diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index e36fd95f..b3ac72c4 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -112,6 +112,8 @@ struct meshlink_handle { bool localdiscovery; sockaddr_t localdiscovery_address; + bool default_blacklist; + hash_t *node_udp_cache; struct connection_t *everyone; struct ecdsa *invitation_key; diff --git a/src/protocol_edge.c b/src/protocol_edge.c index 89ed901d..783da775 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -102,6 +102,7 @@ bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { if(!from) { from = new_node(); + from->status.blacklisted = mesh->default_blacklist; from->name = xstrdup(from_name); node_add(mesh, from); } @@ -111,6 +112,7 @@ bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { if(!to) { to = new_node(); + to->status.blacklisted = mesh->default_blacklist; to->name = xstrdup(to_name); node_add(mesh, to); } -- 2.39.2