]> git.meshlink.io Git - meshlink-tiny/commitdiff
Remove support for submeshes.
authorGuus Sliepen <guus@meshlink.io>
Sat, 19 Jun 2021 16:13:25 +0000 (18:13 +0200)
committerGuus Sliepen <guus@meshlink.io>
Sat, 19 Jun 2021 16:13:25 +0000 (18:13 +0200)
22 files changed:
src/Makefile.am
src/connection.h
src/devtools.c
src/devtools.h
src/meshlink-tiny++.h
src/meshlink-tiny.h
src/meshlink.c
src/meshlink.sym
src/meshlink_internal.h
src/meta.c
src/meta.h
src/net_packet.c
src/net_setup.c
src/node.h
src/protocol.c
src/protocol.h
src/protocol_auth.c
src/protocol_edge.c
src/protocol_key.c
src/protocol_misc.c
src/submesh.c [deleted file]
src/submesh.h [deleted file]

index d6ebe5e4109cdfa231a7e0ac9da9f664c7ef176e..af1d51c407efc14e26bec14aa414b7a9ed1371d2 100644 (file)
@@ -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 \
index 248f80674e5af5f2413412f2cdef947f0233c1c1..0bdea9efd49db9e54400ce6969f6f83638525386 100644 (file)
@@ -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 */
index 820b9620c6da221bbc4ce56f151820c584f55db3..54fe84a8630aa991f30e9c8c529a148ee2efd4f6 100644 (file)
@@ -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);
index fc09d823f28062e102511b720af4f78bef7c67c3..60b51d13be43c56e019fdba1a66d377905cb9b83 100644 (file)
@@ -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.
  *
index eba23aa3776a687d520ec0d94209b4254d569d58..b7893955d82723a5c39f06c6818a1afd7caab31d 100644 (file)
@@ -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.
         *
index 131dc8e49d8cb2f708f2c982d848a597cc1926d7..a0ca5fe2b07bf80e95a0789b3362b5418123fc13 100644 (file)
@@ -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.
index 59776da25a36382b481995a68a2b9c9aa4c40adf..8b3b841f5862b8cfe73313362d28081421cf1fa8 100644 (file)
@@ -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;
index 01149d60cdbb4d63cb5a35dfcd5f9e599ca0760f..3df9d7bf0a07f6e47239511253b230aaa55d79af 100644 (file)
@@ -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
index 68d061b680a5177c84a306f27fe8d4ccd08f383c..b1caa0a34ef3a5b5b46a5131704a0d755575a34e 100644 (file)
@@ -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;
index 94aab98136261d46bde95755fe385c0be8fe6b2d..d79dc6edbec77482c4a1e6ec5fc152f175b8bbad 100644 (file)
@@ -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);
index 039fa34840746ca92d79c92eb0391be215f6677e..6fd05e23074ab1e6d3de4df7a3ee63fb169a5800 100644 (file)
@@ -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
index b6478e44a7c47f438c7bbfd4f1a419c1ba599ff0..d4eb0c4f7d7eddd141e05518ea0ce877c2268de6 100644 (file)
@@ -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);
        }
 }
 
index b1bfc227174f611a1900b8b733f375e419f605af..4369692fde5004c151a47dd6ee363591ace61014 100644 (file)
@@ -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);
index 26d868dd185f3c635677f9dd22b70dfe424f68a2..dd19884537334dac78f910ff55e274b6811e759f 100644 (file)
 */
 
 #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;
 
index 9d1dff971e2b800a803584027aeb914866032be8..d95edceda62b99f506ddfe714241d7e63b222adf 100644 (file)
@@ -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) {
index 5882513d4947be821741ac3f55b6de36b1d011cf..080eab623c39be2a0d991cbd1ae2b65ee965fc9d 100644 (file)
@@ -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 *);
 
index e292d58c61b44c74cf985ac2eaa2eadb831d7efe..f46a4f473c6d5059b5ba449b8cf9fe8852c4a764 100644 (file)
@@ -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) {
index 16ebfd5fb425fd6c94fab8e7139052ac2b363cb6..28e2e7b44ffb44b98c01ce79d83bc50cf3c9e625 100644 (file)
@@ -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) {
index bd27b01b6aacc6a5efa3f9db3630f63bdb766c93..de6b1e5ea34ff3c67ac68c1e58ada692253022f4 100644 (file)
@@ -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? */
index 0fbb52069e30a1970c81461d21e54334ee121580..145dde7721cc3b374c43c462a058be88ba1b28eb 100644 (file)
@@ -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 (file)
index 4af2be0..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
-    submesh.c -- submesh management
-    Copyright (C) 2019 Guus Sliepen <guus@meshlink.io>,
-
-    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 (file)
index 9366b05..0000000
+++ /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 <guus@meshlink.io>
-
-    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