From 8eb1e508a3fd32a93f1dabab098b3293f527ac2b Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 19 Jun 2021 18:13:25 +0200 Subject: [PATCH] Remove support for submeshes. --- src/Makefile.am | 1 - src/connection.h | 3 - src/devtools.c | 34 ---------- src/devtools.h | 14 ---- src/meshlink-tiny++.h | 17 ----- src/meshlink-tiny.h | 70 -------------------- src/meshlink.c | 97 +--------------------------- src/meshlink.sym | 5 -- src/meshlink_internal.h | 9 +-- src/meta.c | 12 ---- src/meta.h | 2 - src/net_packet.c | 4 +- src/net_setup.c | 21 ++---- src/node.h | 3 +- src/protocol.c | 19 ++---- src/protocol.h | 4 +- src/protocol_auth.c | 4 +- src/protocol_edge.c | 1 - src/protocol_key.c | 16 ++--- src/protocol_misc.c | 6 +- src/submesh.c | 138 ---------------------------------------- src/submesh.h | 41 ------------ 22 files changed, 29 insertions(+), 492 deletions(-) delete mode 100644 src/submesh.c delete mode 100644 src/submesh.h diff --git a/src/Makefile.am b/src/Makefile.am index d6ebe5e..af1d51c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -60,7 +60,6 @@ libmeshlink_tiny_la_SOURCES = \ net_socket.c \ netutl.c netutl.h \ node.c node.h \ - submesh.c submesh.h \ packmsg.h \ prf.c prf.h \ protocol.c protocol.h \ diff --git a/src/connection.h b/src/connection.h index 248f806..0bdea9e 100644 --- a/src/connection.h +++ b/src/connection.h @@ -46,7 +46,6 @@ typedef struct connection_status_t { #include "ecdsa.h" #include "net.h" #include "node.h" -#include "submesh.h" typedef struct connection_t { char *name; /* name he claims to have */ @@ -70,8 +69,6 @@ typedef struct connection_t { struct outgoing_t *outgoing; /* used to keep track of outgoing connections */ - struct submesh_t *submesh; /* his submesh handle if available in invitation file */ - // Only used during authentication ecdsa_t *ecdsa; /* his public ECDSA key */ int protocol_major; /* used protocol */ diff --git a/src/devtools.c b/src/devtools.c index 820b962..54fe84a 100644 --- a/src/devtools.c +++ b/src/devtools.c @@ -23,7 +23,6 @@ #include "logger.h" #include "meshlink_internal.h" #include "node.h" -#include "submesh.h" #include "splay_tree.h" #include "netutl.h" #include "xalloc.h" @@ -97,39 +96,6 @@ void devtool_get_node_status(meshlink_handle_t *mesh, meshlink_node_t *node, dev pthread_mutex_unlock(&mesh->mutex); } -meshlink_submesh_t **devtool_get_all_submeshes(meshlink_handle_t *mesh, meshlink_submesh_t **submeshes, size_t *nmemb) { - if(!mesh || !nmemb || (*nmemb && !submeshes)) { - meshlink_errno = MESHLINK_EINVAL; - return NULL; - } - - meshlink_submesh_t **result; - - //lock mesh->nodes - if(pthread_mutex_lock(&mesh->mutex) != 0) { - abort(); - } - - *nmemb = mesh->submeshes->count; - result = realloc(submeshes, *nmemb * sizeof(*submeshes)); - - if(result) { - meshlink_submesh_t **p = result; - - for list_each(submesh_t, s, mesh->submeshes) { - *p++ = (meshlink_submesh_t *)s; - } - } else { - *nmemb = 0; - free(submeshes); - meshlink_errno = MESHLINK_ENOMEM; - } - - pthread_mutex_unlock(&mesh->mutex); - - return result; -} - meshlink_handle_t *devtool_open_in_netns(const char *confbase, const char *name, const char *appname, dev_class_t devclass, int netns) { meshlink_open_params_t *params = meshlink_open_params_init(confbase, name, appname, devclass); params->netns = dup(netns); diff --git a/src/devtools.h b/src/devtools.h index fc09d82..60b51d1 100644 --- a/src/devtools.h +++ b/src/devtools.h @@ -63,20 +63,6 @@ struct devtool_node_status { */ void devtool_get_node_status(meshlink_handle_t *mesh, meshlink_node_t *node, devtool_node_status_t *status); -/// Get the list of all submeshes of a meshlink instance. -/** This function returns an array of submesh handles. - * These pointers are the same pointers that are present in the submeshes list - * in mesh handle. - * - * @param mesh A handle which represents an instance of MeshLink. - * @param submeshes A pointer to an array of submesh handles if any allocated previously. - * @param nmemb A pointer to a size_t variable that has - * to be provided by the caller. - * The contents of this variable will be changed to indicate - * the number if array elements. - */ -meshlink_submesh_t **devtool_get_all_submeshes(meshlink_handle_t *mesh, meshlink_submesh_t **submeshes, size_t *nmemb); - /// Open a MeshLink instance in a given network namespace. /** This function opens MeshLink in the given network namespace. * diff --git a/src/meshlink-tiny++.h b/src/meshlink-tiny++.h index eba23aa..b789395 100644 --- a/src/meshlink-tiny++.h +++ b/src/meshlink-tiny++.h @@ -27,7 +27,6 @@ namespace meshlink { class mesh; class node; class channel; -class submesh; /// Severity of log messages generated by MeshLink. typedef meshlink_log_level_t log_level_t; @@ -142,10 +141,6 @@ typedef void (*aio_fd_cb_t)(mesh *mesh, channel *channel, int fd, size_t len, vo class node: public meshlink_node_t { }; -/// A class describing a MeshLink Sub-Mesh. -class submesh: public meshlink_submesh_t { -}; - /// A class describing a MeshLink channel. class channel: public meshlink_channel_t { public: @@ -431,18 +426,6 @@ public: return meshlink_get_node_reachability(handle, node, last_reachable, last_unreachable); } - /// Get a handle for a specific submesh. - /** This function returns a handle for the submesh with the given name. - * - * @param name The name of the submesh for which a handle is requested. - * - * @return A pointer to a meshlink::submesh which represents the requested submesh, - * or NULL if the requested submesh does not exist. - */ - submesh *get_submesh(const char *name) { - return (submesh *)meshlink_get_submesh(handle, name); - } - /// Get a handle for our own node. /** This function returns a handle for the local node. * diff --git a/src/meshlink-tiny.h b/src/meshlink-tiny.h index 131dc8e..a0ca5fe 100644 --- a/src/meshlink-tiny.h +++ b/src/meshlink-tiny.h @@ -54,9 +54,6 @@ typedef struct meshlink_channel meshlink_channel_t; /// A struct containing all parameters used for opening a mesh. typedef struct meshlink_open_params meshlink_open_params_t; -/// A handle for a MeshLink sub-mesh. -typedef struct meshlink_submesh meshlink_submesh_t; - /// Code of most recent error encountered. typedef enum { MESHLINK_OK, ///< Everything is fine @@ -126,11 +123,6 @@ struct meshlink_node { void *priv; ///< Private pointer which may be set freely by the application, and is never used or modified by MeshLink. }; -struct meshlink_submesh { - const char *const name; ///< Textual name of this Sub-Mesh. It is stored in a nul-terminated C string, which is allocated by MeshLink. - void *priv; ///< Private pointer which may be set freely by the application, and is never used or modified by MeshLink. -}; - struct meshlink_channel { struct meshlink_node *const node; ///< Pointer to the peer of this channel. void *priv; ///< Private pointer which may be set freely by the application, and is never used or modified by MeshLink. @@ -323,22 +315,6 @@ struct meshlink_handle *meshlink_open_encrypted(const char *confbase, const char */ struct meshlink_handle *meshlink_open_ephemeral(const char *name, const char *appname, dev_class_t devclass) __attribute__((__warn_unused_result__)); -/// Create Sub-Mesh. -/** This function causes MeshLink to open a new Sub-Mesh network - * create a new thread, which will handle all network I/O. - * - * It is allowed to call this function even if MeshLink is already started, in which case it will return true. - * - * \memberof meshlink_handle - * @param mesh A handle which represents an instance of MeshLink. - * - * @param submesh Name of the new Sub-Mesh to create. - * - * @return A pointer to a struct meshlink_submesh which represents this instance of SubMesh, or NULL in case of an error. - * The pointer is valid until meshlink_close() is called. - */ -struct meshlink_submesh *meshlink_submesh_open(struct meshlink_handle *mesh, const char *submesh) __attribute__((__warn_unused_result__)); - /// Start MeshLink. /** This function causes MeshLink to open network sockets, make outgoing connections, and * create a new thread, which will handle all network I/O. @@ -652,20 +628,6 @@ struct meshlink_node *meshlink_get_self(struct meshlink_handle *mesh) __attribut */ struct meshlink_node *meshlink_get_node(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__)); -/// Get a handle for a specific submesh. -/** This function returns a handle for the submesh with the given name. - * - * \memberof meshlink_handle - * @param mesh A handle which represents an instance of MeshLink. - * @param name The name of the submesh for which a handle is requested. - * After this function returns, the application is free to overwrite or free @a name. - * - * @return A pointer to a struct meshlink_submesh which represents the requested submesh, - * or NULL if the requested submesh does not exist. - * The pointer is guaranteed to be valid until meshlink_close() is called. - */ -struct meshlink_submesh *meshlink_get_submesh(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__)); - /// Get the fingerprint of a node's public key. /** This function returns a fingerprint of the node's public key. * It should be treated as an opaque blob. @@ -737,27 +699,6 @@ bool meshlink_sign(struct meshlink_handle *mesh, const void *data, size_t len, v */ struct meshlink_node **meshlink_get_all_nodes_by_dev_class(struct meshlink_handle *mesh, dev_class_t devclass, struct meshlink_node **nodes, size_t *nmemb) __attribute__((__warn_unused_result__)); -/// Get the list of all nodes by Submesh. -/** This function returns a list with handles for all the nodes that matches with the given @a Submesh. - * - * \memberof meshlink_submesh - * @param mesh A handle which represents an instance of MeshLink. - * @param submesh Submesh handle of the nodes for which the list has to be obtained. - * @param nodes A pointer to a previously allocated array of pointers to struct meshlink_node, or NULL in which case MeshLink will allocate a new array. - * The application can supply an array it allocated itself with malloc, or the return value from the previous call to this function (which is the preferred way). - * The application is allowed to call free() on the array whenever it wishes. - * The pointers in the array are valid until meshlink_close() is called. - * @param nmemb A pointer to a variable holding the number of nodes with the same @a device class that are stored in the array. - * In case the @a nodes argument is not NULL, MeshLink might call realloc() on the array to change its size. - * The contents of this variable will be changed to reflect the new size of the array. - * - * @return A pointer to an array containing pointers to all known nodes of the given Submesh, or NULL in case of an error. - * If the @a nodes argument was not NULL, then the return value can either be the same value or a different value. - * If it is a new value, the old value of @a nodes should not be used anymore. - * If the new value is NULL, then the old array will have been freed by MeshLink. - */ -struct meshlink_node **meshlink_get_all_nodes_by_submesh(struct meshlink_handle *mesh, struct meshlink_submesh *submesh, struct meshlink_node **nodes, size_t *nmemb) __attribute__((__warn_unused_result__)); - /// Get the list of all nodes by time they were last reachable. /** This function returns a list with handles for all the nodes whose last known reachability time overlaps with the given time range. * If the range includes 0, it will count nodes that were never online. @@ -793,17 +734,6 @@ struct meshlink_node **meshlink_get_all_nodes_by_last_reachable(struct meshlink_ */ dev_class_t meshlink_get_node_dev_class(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); -/// Get the node's submesh handle. -/** This function returns the submesh handle of the given node. - * - * \memberof meshlink_node - * @param mesh A handle which represents an instance of MeshLink. - * @param node A pointer to a struct meshlink_node describing the node. - * - * @return This function returns the submesh handle of the @a node, or NULL in case of an error. - */ -struct meshlink_submesh *meshlink_get_node_submesh(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); - /// Get a node's reachability status. /** This function returns the current reachability of a given node, and the times of the last state changes. * If a given state change never happened, the time returned will be 0. diff --git a/src/meshlink.c b/src/meshlink.c index 59776da..8b3b841 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -27,7 +27,6 @@ #include "net.h" #include "netutl.h" #include "node.h" -#include "submesh.h" #include "packmsg.h" #include "prf.h" #include "protocol.h" @@ -208,28 +207,19 @@ static bool finalize_join(join_state_t *state, const void *buf, uint16_t len) { } char *name = packmsg_get_str_dup(&in); - char *submesh_name = packmsg_get_str_dup(&in); + packmsg_skip_element(&in); // submesh_name dev_class_t devclass = packmsg_get_int32(&in); uint32_t count = packmsg_get_array(&in); if(!name || !check_id(name)) { logger(mesh, MESHLINK_DEBUG, "No valid Name found in invitation!\n"); free(name); - free(submesh_name); - return false; - } - - if(!submesh_name || (strcmp(submesh_name, CORE_MESH) && !check_id(submesh_name))) { - logger(mesh, MESHLINK_DEBUG, "No valid Submesh found in invitation!\n"); - free(name); - free(submesh_name); return false; } if(!count) { logger(mesh, MESHLINK_ERROR, "Incomplete invitation file!\n"); free(name); - free(submesh_name); return false; } @@ -237,8 +227,6 @@ static bool finalize_join(join_state_t *state, const void *buf, uint16_t len) { free(mesh->self->name); mesh->name = name; mesh->self->name = xstrdup(name); - mesh->self->submesh = strcmp(submesh_name, CORE_MESH) ? lookup_or_create_submesh(mesh, submesh_name) : NULL; - free(submesh_name); mesh->self->devclass = devclass == DEV_CLASS_UNKNOWN ? mesh->devclass : devclass; // Initialize configuration directory @@ -990,7 +978,6 @@ meshlink_handle_t *meshlink_open_ex(const meshlink_open_params_t *params) { mesh->appname = xstrdup(params->appname); mesh->devclass = params->devclass; mesh->netns = params->netns; - mesh->submeshes = NULL; mesh->log_cb = global_log_cb; mesh->log_level = global_log_level; mesh->packet = xmalloc(sizeof(vpn_packet_t)); @@ -1114,35 +1101,6 @@ meshlink_handle_t *meshlink_open_ex(const meshlink_open_params_t *params) { return mesh; } -meshlink_submesh_t *meshlink_submesh_open(meshlink_handle_t *mesh, const char *submesh) { - logger(NULL, MESHLINK_DEBUG, "meshlink_submesh_open(%s)", submesh); - - meshlink_submesh_t *s = NULL; - - if(!mesh) { - logger(NULL, MESHLINK_ERROR, "No mesh handle given!\n"); - meshlink_errno = MESHLINK_EINVAL; - return NULL; - } - - if(!submesh || !*submesh) { - logger(NULL, MESHLINK_ERROR, "No submesh name given!\n"); - meshlink_errno = MESHLINK_EINVAL; - return NULL; - } - - //lock mesh->nodes - if(pthread_mutex_lock(&mesh->mutex) != 0) { - abort(); - } - - s = (meshlink_submesh_t *)create_submesh(mesh, submesh); - - pthread_mutex_unlock(&mesh->mutex); - - return s; -} - static void *meshlink_main_loop(void *arg) { meshlink_handle_t *mesh = arg; @@ -1745,28 +1703,6 @@ meshlink_node_t *meshlink_get_node(meshlink_handle_t *mesh, const char *name) { return (meshlink_node_t *)n; } -meshlink_submesh_t *meshlink_get_submesh(meshlink_handle_t *mesh, const char *name) { - if(!mesh || !name) { - meshlink_errno = MESHLINK_EINVAL; - return NULL; - } - - meshlink_submesh_t *submesh = NULL; - - if(pthread_mutex_lock(&mesh->mutex) != 0) { - abort(); - } - - submesh = (meshlink_submesh_t *)lookup_submesh(mesh, name); - pthread_mutex_unlock(&mesh->mutex); - - if(!submesh) { - meshlink_errno = MESHLINK_ENOENT; - } - - return submesh; -} - meshlink_node_t **meshlink_get_all_nodes(meshlink_handle_t *mesh, meshlink_node_t **nodes, size_t *nmemb) { if(!mesh || !nmemb || (*nmemb && !nodes)) { meshlink_errno = MESHLINK_EINVAL; @@ -1852,13 +1788,6 @@ static bool search_node_by_dev_class(const node_t *node, const void *condition) return false; } -static bool search_node_by_submesh(const node_t *node, const void *condition) { - if(condition == node->submesh) { - return true; - } - - return false; -} struct time_range { time_t start; @@ -1874,15 +1803,6 @@ meshlink_node_t **meshlink_get_all_nodes_by_dev_class(meshlink_handle_t *mesh, d return meshlink_get_all_nodes_by_condition(mesh, &devclass, nodes, nmemb, search_node_by_dev_class); } -meshlink_node_t **meshlink_get_all_nodes_by_submesh(meshlink_handle_t *mesh, meshlink_submesh_t *submesh, meshlink_node_t **nodes, size_t *nmemb) { - if(!mesh || !submesh || !nmemb) { - meshlink_errno = MESHLINK_EINVAL; - return NULL; - } - - return meshlink_get_all_nodes_by_condition(mesh, submesh, nodes, nmemb, search_node_by_submesh); -} - dev_class_t meshlink_get_node_dev_class(meshlink_handle_t *mesh, meshlink_node_t *node) { if(!mesh || !node) { meshlink_errno = MESHLINK_EINVAL; @@ -1902,21 +1822,6 @@ dev_class_t meshlink_get_node_dev_class(meshlink_handle_t *mesh, meshlink_node_t return devclass; } -meshlink_submesh_t *meshlink_get_node_submesh(meshlink_handle_t *mesh, meshlink_node_t *node) { - if(!mesh || !node) { - meshlink_errno = MESHLINK_EINVAL; - return NULL; - } - - node_t *n = (node_t *)node; - - meshlink_submesh_t *s; - - s = (meshlink_submesh_t *)n->submesh; - - return s; -} - bool meshlink_get_node_reachability(struct meshlink_handle *mesh, struct meshlink_node *node, time_t *last_reachable, time_t *last_unreachable) { if(!mesh || !node) { meshlink_errno = MESHLINK_EINVAL; diff --git a/src/meshlink.sym b/src/meshlink.sym index 01149d6..3df9d7b 100644 --- a/src/meshlink.sym +++ b/src/meshlink.sym @@ -1,5 +1,4 @@ __emutls_v.meshlink_errno -devtool_get_all_submeshes devtool_get_node_status devtool_keyrotate_probe devtool_open_in_netns @@ -31,15 +30,12 @@ meshlink_forget_node meshlink_get_all_nodes meshlink_get_all_nodes_by_dev_class meshlink_get_all_nodes_by_last_reachable -meshlink_get_all_nodes_by_submesh meshlink_get_fingerprint meshlink_get_node meshlink_get_node_dev_class meshlink_get_node_reachability -meshlink_get_node_submesh meshlink_get_pmtu meshlink_get_self -meshlink_get_submesh meshlink_hint_address meshlink_hint_network_change meshlink_import @@ -85,5 +81,4 @@ meshlink_start meshlink_stop meshlink_set_storage_policy meshlink_strerror -meshlink_submesh_open meshlink_verify diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index 68d061b..b1caa0a 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -45,6 +45,8 @@ static const char meshlink_udp_label[] = "MeshLink UDP"; #define MESHLINK_CONFIG_VERSION 2 #define MESHLINK_INVITATION_VERSION 2 +#define CORE_MESH "." + struct meshlink_open_params { char *confbase; char *lock_filename; @@ -95,7 +97,6 @@ struct meshlink_handle { struct list_t *connections; struct list_t *outgoings; - struct list_t *submeshes; // Meta-connection-related members struct splay_tree_t *past_request_tree; @@ -161,12 +162,6 @@ struct meshlink_node { void *priv; }; -/// A handle for a node Sub-Mesh. -struct meshlink_submesh { - const char *name; - void *priv; -}; - /// An AIO buffer. typedef struct meshlink_aio_buffer { const void *data; diff --git a/src/meta.c b/src/meta.c index 94aab98..d79dc6e 100644 --- a/src/meta.c +++ b/src/meta.c @@ -70,18 +70,6 @@ void broadcast_meta(meshlink_handle_t *mesh, connection_t *from, const char *buf } } -void broadcast_submesh_meta(meshlink_handle_t *mesh, connection_t *from, const submesh_t *s, const char *buffer, int length) { - assert(buffer); - assert(length); - - for list_each(connection_t, c, mesh->connections) - if(c != from && c->status.active) { - if(c->node && submesh_allows_node(s, c->node)) { - send_meta(mesh, c, buffer, length); - } - } -} - bool receive_meta_sptps(void *handle, uint8_t type, const void *data, uint16_t length) { assert(handle); assert(!length || data); diff --git a/src/meta.h b/src/meta.h index 039fa34..6fd05e2 100644 --- a/src/meta.h +++ b/src/meta.h @@ -26,8 +26,6 @@ bool send_meta(struct meshlink_handle *mesh, struct connection_t *, const char * bool send_meta_sptps(void *, uint8_t, const void *, size_t); bool receive_meta_sptps(void *, uint8_t, const void *, uint16_t); void broadcast_meta(struct meshlink_handle *mesh, struct connection_t *, const char *, int); -extern void broadcast_submesh_meta(struct meshlink_handle *mesh, connection_t *from, const submesh_t *s, - const char *buffer, int length); bool receive_meta(struct meshlink_handle *mesh, struct connection_t *) __attribute__((__warn_unused_result__)); #endif diff --git a/src/net_packet.c b/src/net_packet.c index b6478e4..d4eb0c4 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -113,9 +113,9 @@ bool send_sptps_data(void *handle, uint8_t type, const void *data, size_t len) { /* If no valid key is known yet, send the packets using ANS_KEY requests, to ensure we get to learn the reflexive UDP address. */ if(!to->status.validkey) { - return send_request(mesh, to->nexthop->connection, NULL, "%d %s %s %s -1 -1 -1 %d", ANS_KEY, mesh->self->name, to->name, buf, 0); + return send_request(mesh, to->nexthop->connection, "%d %s %s %s -1 -1 -1 %d", ANS_KEY, mesh->self->name, to->name, buf, 0); } else { - return send_request(mesh, to->nexthop->connection, NULL, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_SPTPS, buf); + return send_request(mesh, to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_SPTPS, buf); } } diff --git a/src/net_setup.c b/src/net_setup.c index b1bfc22..4369692 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -31,7 +31,6 @@ #include "route.h" #include "utils.h" #include "xalloc.h" -#include "submesh.h" /// Helper function to start parsing a host config file static bool node_get_config(meshlink_handle_t *mesh, node_t *n, config_t *config, packmsg_input_t *in) { @@ -129,6 +128,8 @@ bool node_read_public_key(meshlink_handle_t *mesh, node_t *n) { /// Fill in node details from a config blob. bool node_read_from_config(meshlink_handle_t *mesh, node_t *n, const config_t *config) { + (void)mesh; + if(n->canonical_address) { return true; } @@ -157,19 +158,7 @@ bool node_read_from_config(meshlink_handle_t *mesh, node_t *n, const config_t *c n->name = name; } - char *submesh_name = packmsg_get_str_dup(&in); - - if(!strcmp(submesh_name, CORE_MESH)) { - free(submesh_name); - n->submesh = NULL; - } else { - n->submesh = lookup_or_create_submesh(mesh, submesh_name); - free(submesh_name); - - if(!n->submesh) { - return false; - } - } + packmsg_skip_element(&in); // submesh_name n->devclass = packmsg_get_int32(&in); n->status.blacklisted = packmsg_get_bool(&in); @@ -234,7 +223,7 @@ bool node_write_config(meshlink_handle_t *mesh, node_t *n, bool new_key) { packmsg_add_uint32(&out, MESHLINK_CONFIG_VERSION); packmsg_add_str(&out, n->name); - packmsg_add_str(&out, n->submesh ? n->submesh->name : CORE_MESH); + packmsg_add_str(&out, CORE_MESH); packmsg_add_int32(&out, n->devclass); packmsg_add_bool(&out, n->status.blacklisted); @@ -352,7 +341,6 @@ static bool setup_myself(meshlink_handle_t *mesh) { */ bool setup_network(meshlink_handle_t *mesh) { init_connections(mesh); - init_submeshes(mesh); init_nodes(mesh); init_requests(mesh); @@ -378,7 +366,6 @@ void close_network_connections(meshlink_handle_t *mesh) { exit_requests(mesh); exit_nodes(mesh); - exit_submeshes(mesh); exit_connections(mesh); free(mesh->myport); diff --git a/src/node.h b/src/node.h index 26d868d..dd19884 100644 --- a/src/node.h +++ b/src/node.h @@ -21,10 +21,10 @@ */ #include "event.h" +#include "meshlink_internal.h" #include "sockaddr.h" #include "sptps.h" #include "utcp.h" -#include "submesh.h" typedef struct node_status_t { uint16_t validkey: 1; /* 1 if we currently have a valid key for him */ @@ -74,7 +74,6 @@ typedef struct node_t { // Used for meta-connection I/O, timeouts struct meshlink_handle *mesh; /* The mesh this node belongs to */ - struct submesh_t *submesh; /* Nodes Sub-Mesh Handle*/ time_t last_req_key; diff --git a/src/protocol.c b/src/protocol.c index 9d1dff9..d95edce 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -27,7 +27,6 @@ #include "protocol.h" #include "utils.h" #include "xalloc.h" -#include "submesh.h" /* Jumptable for the request handlers */ @@ -79,7 +78,7 @@ bool check_id(const char *id) { /* Generic request routines - takes care of logging and error detection as well */ -bool send_request(meshlink_handle_t *mesh, connection_t *c, const submesh_t *s, const char *format, ...) { +bool send_request(meshlink_handle_t *mesh, connection_t *c, const char *format, ...) { assert(format); assert(*format); @@ -110,20 +109,14 @@ bool send_request(meshlink_handle_t *mesh, connection_t *c, const submesh_t *s, request[len++] = '\n'; if(c == mesh->everyone) { - - if(s) { - broadcast_submesh_meta(mesh, NULL, s, request, len); - } else { - broadcast_meta(mesh, NULL, request, len); - } - + broadcast_meta(mesh, NULL, request, len); return true; } else { return send_meta(mesh, c, request, len); } } -void forward_request(meshlink_handle_t *mesh, connection_t *from, const submesh_t *s, const char *request) { +void forward_request(meshlink_handle_t *mesh, connection_t *from, const char *request) { assert(from); assert(request); assert(*request); @@ -137,11 +130,7 @@ void forward_request(meshlink_handle_t *mesh, connection_t *from, const submesh_ memcpy(tmp, request, len); tmp[len] = '\n'; - if(s) { - broadcast_submesh_meta(mesh, from, s, tmp, sizeof(tmp)); - } else { - broadcast_meta(mesh, from, tmp, sizeof(tmp)); - } + broadcast_meta(mesh, from, tmp, sizeof(tmp)); } bool receive_request(meshlink_handle_t *mesh, connection_t *c, const char *request) { diff --git a/src/protocol.h b/src/protocol.h index 5882513..080eab6 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -75,8 +75,8 @@ typedef struct past_request_t { /* Basic functions */ -bool send_request(struct meshlink_handle *mesh, struct connection_t *, const struct submesh_t *s, const char *, ...) __attribute__((__format__(printf, 4, 5))); -void forward_request(struct meshlink_handle *mesh, struct connection_t *, const struct submesh_t *, const char *); +bool send_request(struct meshlink_handle *mesh, struct connection_t *, const char *, ...) __attribute__((__format__(printf, 3, 4))); +void forward_request(struct meshlink_handle *mesh, struct connection_t *, const char *); bool receive_request(struct meshlink_handle *mesh, struct connection_t *, const char *); bool check_id(const char *); diff --git a/src/protocol_auth.c b/src/protocol_auth.c index e292d58..f46a4f4 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -42,7 +42,7 @@ extern bool node_write_devclass(meshlink_handle_t *mesh, node_t *n); bool send_id(meshlink_handle_t *mesh, connection_t *c) { - return send_request(mesh, c, NULL, "%d %s %d.%d %s", ID, mesh->self->name, PROT_MAJOR, PROT_MINOR, mesh->appname); + return send_request(mesh, c, "%d %s %d.%d %s", ID, mesh->self->name, PROT_MAJOR, PROT_MINOR, mesh->appname); } bool id_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { @@ -143,7 +143,7 @@ bool send_ack(meshlink_handle_t *mesh, connection_t *c) { } c->last_ping_time = mesh->loop.now.tv_sec; - return send_request(mesh, c, NULL, "%d %s %d %x", ACK, mesh->myport, mesh->devclass, OPTION_PMTU_DISCOVERY | (PROT_MINOR << 24)); + return send_request(mesh, c, "%d %s %d %x", ACK, mesh->myport, mesh->devclass, OPTION_PMTU_DISCOVERY | (PROT_MINOR << 24)); } bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { diff --git a/src/protocol_edge.c b/src/protocol_edge.c index 16ebfd5..28e2e7b 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -30,7 +30,6 @@ #include "protocol.h" #include "utils.h" #include "xalloc.h" -#include "submesh.h" #if 0 bool send_add_edge(meshlink_handle_t *mesh, connection_t *c, const edge_t *e, int contradictions) { diff --git a/src/protocol_key.c b/src/protocol_key.c index bd27b01..de6b1e5 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -58,7 +58,7 @@ bool key_changed_h(meshlink_handle_t *mesh, connection_t *c, const char *request /* Tell the others */ - forward_request(mesh, c, NULL, request); + forward_request(mesh, c, request); return true; } @@ -80,7 +80,7 @@ static bool send_initial_sptps_data(void *handle, uint8_t type, const void *data to->sptps.send_data = send_sptps_data; char buf[len * 4 / 3 + 5]; b64encode(data, buf, len); - return send_request(mesh, to->nexthop->connection, NULL, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_KEY, buf); + return send_request(mesh, to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_KEY, buf); } bool send_canonical_address(meshlink_handle_t *mesh, node_t *to) { @@ -88,7 +88,7 @@ bool send_canonical_address(meshlink_handle_t *mesh, node_t *to) { return true; } - return send_request(mesh, to->nexthop->connection, NULL, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_CANONICAL, mesh->self->canonical_address); + return send_request(mesh, to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_CANONICAL, mesh->self->canonical_address); } bool send_req_key(meshlink_handle_t *mesh, node_t *to) { @@ -101,7 +101,7 @@ bool send_req_key(meshlink_handle_t *mesh, node_t *to) { } char *pubkey = ecdsa_get_base64_public_key(mesh->private_key); - send_request(mesh, to->nexthop->connection, NULL, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_PUBKEY, pubkey); + send_request(mesh, to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_PUBKEY, pubkey); free(pubkey); return true; } @@ -156,7 +156,7 @@ static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char * } } - send_request(mesh, from->nexthop->connection, NULL, "%d %s %s %d %s", REQ_KEY, mesh->self->name, from->name, ANS_PUBKEY, pubkey); + send_request(mesh, from->nexthop->connection, "%d %s %s %d %s", REQ_KEY, mesh->self->name, from->name, ANS_PUBKEY, pubkey); free(pubkey); return true; } @@ -200,7 +200,7 @@ static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char * case REQ_KEY: { if(!node_read_public_key(mesh, from)) { logger(mesh, MESHLINK_DEBUG, "No ECDSA key known for %s", from->name); - send_request(mesh, from->nexthop->connection, NULL, "%d %s %s %d", REQ_KEY, mesh->self->name, from->name, REQ_PUBKEY); + send_request(mesh, from->nexthop->connection, "%d %s %s %d", REQ_KEY, mesh->self->name, from->name, REQ_PUBKEY); return true; } @@ -345,7 +345,7 @@ bool req_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { return true; } - send_request(mesh, to->nexthop->connection, NULL, "%s", request); + send_request(mesh, to->nexthop->connection, "%s", request); } return true; @@ -411,7 +411,7 @@ bool ans_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { return false; } - return send_request(mesh, to->nexthop->connection, NULL, "%s", request); + return send_request(mesh, to->nexthop->connection, "%s", request); } /* Is this an ANS_KEY informing us of our own reflexive UDP address? */ diff --git a/src/protocol_misc.c b/src/protocol_misc.c index 0fbb520..145dde7 100644 --- a/src/protocol_misc.c +++ b/src/protocol_misc.c @@ -51,7 +51,7 @@ bool status_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { } bool send_error(meshlink_handle_t *mesh, connection_t *c, request_error_t err, const char *message) { - send_request(mesh, c, NULL, "%d %d %s", ERROR, err, message); + send_request(mesh, c, "%d %d %s", ERROR, err, message); flush_meta(mesh, c); return false; } @@ -88,7 +88,7 @@ bool send_ping(meshlink_handle_t *mesh, connection_t *c) { c->status.pinged = true; c->last_ping_time = mesh->loop.now.tv_sec; - return send_request(mesh, c, NULL, "%d", PING); + return send_request(mesh, c, "%d", PING); } bool ping_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { @@ -101,7 +101,7 @@ bool ping_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { } bool send_pong(meshlink_handle_t *mesh, connection_t *c) { - return send_request(mesh, c, NULL, "%d", PONG); + return send_request(mesh, c, "%d", PONG); } bool pong_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { diff --git a/src/submesh.c b/src/submesh.c deleted file mode 100644 index 4af2be0..0000000 --- a/src/submesh.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - submesh.c -- submesh management - Copyright (C) 2019 Guus Sliepen , - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include "system.h" - -#include "hash.h" -#include "logger.h" -#include "meshlink_internal.h" -#include "net.h" -#include "netutl.h" -#include "submesh.h" -#include "splay_tree.h" -#include "utils.h" -#include "xalloc.h" -#include "protocol.h" - -static submesh_t *new_submesh(void) { - return xzalloc(sizeof(submesh_t)); -} - -static void free_submesh(submesh_t *s) { - free(s->name); - free(s); -} - -void init_submeshes(meshlink_handle_t *mesh) { - assert(!mesh->submeshes); - mesh->submeshes = list_alloc((list_action_t)free_submesh); -} - -void exit_submeshes(meshlink_handle_t *mesh) { - if(mesh->submeshes) { - list_delete_list(mesh->submeshes); - } - - mesh->submeshes = NULL; -} - -static submesh_t *submesh_add(meshlink_handle_t *mesh, const char *submesh) { - assert(submesh); - - submesh_t *s = new_submesh(); - s->name = xstrdup(submesh); - list_insert_tail(mesh->submeshes, (void *)s); - return s; -} - -submesh_t *create_submesh(meshlink_handle_t *mesh, const char *submesh) { - assert(submesh); - - if(0 == strcmp(submesh, CORE_MESH)) { - logger(NULL, MESHLINK_ERROR, "Cannot create submesh handle for core mesh!\n"); - meshlink_errno = MESHLINK_EINVAL; - return NULL; - } - - if(!check_id(submesh)) { - logger(NULL, MESHLINK_ERROR, "Invalid SubMesh Id!\n"); - meshlink_errno = MESHLINK_EINVAL; - return NULL; - } - - if(lookup_submesh(mesh, submesh)) { - logger(NULL, MESHLINK_ERROR, "SubMesh Already exists!\n"); - meshlink_errno = MESHLINK_EEXIST; - return NULL; - } - - return submesh_add(mesh, submesh); -} - -submesh_t *lookup_or_create_submesh(meshlink_handle_t *mesh, const char *submesh) { - assert(submesh); - - if(0 == strcmp(submesh, CORE_MESH)) { - logger(NULL, MESHLINK_ERROR, "Cannot create submesh handle for core mesh!\n"); - meshlink_errno = MESHLINK_EINVAL; - return NULL; - } - - if(!check_id(submesh)) { - logger(NULL, MESHLINK_ERROR, "Invalid SubMesh Id!\n"); - meshlink_errno = MESHLINK_EINVAL; - return NULL; - } - - submesh_t *s = lookup_submesh(mesh, submesh); - - if(s) { - meshlink_errno = MESHLINK_OK; - return s; - } - - return submesh_add(mesh, submesh); -} - -submesh_t *lookup_submesh(struct meshlink_handle *mesh, const char *submesh_name) { - assert(submesh_name); - - submesh_t *submesh = NULL; - - if(!mesh->submeshes) { - return NULL; - } - - for list_each(submesh_t, s, mesh->submeshes) { - if(!strcmp(submesh_name, s->name)) { - submesh = s; - break; - } - } - - return submesh; -} - -bool submesh_allows_node(const submesh_t *submesh, const node_t *node) { - if(!node->submesh || !submesh || submesh == node->submesh) { - return true; - } else { - return false; - } -} diff --git a/src/submesh.h b/src/submesh.h deleted file mode 100644 index 9366b05..0000000 --- a/src/submesh.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef MESHLINK_SUBMESH_H -#define MESHLINK_SUBMESH_H - -/* - submesh.h -- header for submesh.c - Copyright (C) 2019 Guus Sliepen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include "meshlink_internal.h" - -#define CORE_MESH "." - -typedef struct submesh_t { - char *name; /* name of this Sub-Mesh */ - void *priv; - - struct meshlink_handle *mesh; /* the mesh this submesh belongs to */ -} submesh_t; - -void init_submeshes(struct meshlink_handle *mesh); -void exit_submeshes(struct meshlink_handle *mesh); -submesh_t *create_submesh(struct meshlink_handle *mesh, const char *) __attribute__((__warn_unused_result__)); -submesh_t *lookup_submesh(struct meshlink_handle *mesh, const char *) __attribute__((__warn_unused_result__)); -submesh_t *lookup_or_create_submesh(struct meshlink_handle *mesh, const char *) __attribute__((__warn_unused_result__)); -bool submesh_allows_node(const submesh_t *submesh, const struct node_t *node) __attribute__((__warn_unused_result__)); - -#endif -- 2.39.5