net_socket.c \
netutl.c netutl.h \
node.c node.h \
+ submesh.c submesh.h \
prf.c prf.h \
protocol.c protocol.h \
protocol_auth.c \
class mesh;
class node;
class channel;
+class submesh;
/// Severity of log messages generated by MeshLink.
typedef meshlink_log_level_t log_level_t;
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:
#include "meshlink_internal.h"
#include "netutl.h"
#include "node.h"
+#include "submesh.h"
#include "protocol.h"
#include "route.h"
#include "sockaddr.h"
return mesh;
}
+meshlink_submesh_t *meshlink_submesh_open(meshlink_handle_t *mesh, const char *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;
+ }
+
+ s = (meshlink_submesh_t *)lookup_submesh(mesh, submesh);
+
+ if (s) {
+ logger(NULL, MESHLINK_ERROR, "SubMesh Already exists!\n");
+ meshlink_errno = MESHLINK_EEXIST;
+ return NULL;
+ }
+
+ s = (meshlink_submesh_t *)new_submesh();
+ s->name = xstrdup(submesh);
+
+ submesh_add(mesh, (submesh_t *)s);
+
+ meshlink_errno = MESHLINK_OK;
+ return s;
+}
+
static void *meshlink_main_loop(void *arg) {
meshlink_handle_t *mesh = arg;
/// 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
MESHLINK_ENETWORK, ///< MeshLink encountered a network error
MESHLINK_EPEER, ///< A peer caused an error
MESHLINK_ENOTSUP, ///< The operation is not supported in the current configuration of MeshLink
- MESHLINK_EBUSY, ///< The MeshLink instance is already in use by another process
+ MESHLINK_EBUSY ///< The MeshLink instance is already in use by another process
} meshlink_errno_t;
/// Device class
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.
*/
extern meshlink_handle_t *meshlink_open(const char *confbase, const char *name, const char *appname, dev_class_t devclass);
+/// 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.
+ *
+ * @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 meshlink_submesh_t which represents this instance of SubMesh, or NULL in case of an error.
+ * The pointer is valid until meshlink_close() is called.
+ */
+meshlink_submesh_t *meshlink_submesh_open(meshlink_handle_t *mesh, const char *submesh);
+
/// 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.
MESHLINK_INFO, ///< Informational messages.
MESHLINK_WARNING, ///< Warnings which might indicate problems, but which are not real errors.
MESHLINK_ERROR, ///< Errors which hamper correct functioning of MeshLink, without causing it to fail completely.
- MESHLINK_CRITICAL, ///< Critical errors which cause MeshLink to fail completely.
+ MESHLINK_CRITICAL ///< Critical errors which cause MeshLink to fail completely.
} meshlink_log_level_t;
/// A callback for receiving log messages generated by MeshLink.
struct list_t *connections;
struct list_t *outgoings;
+ struct list_t *submeshes;
meshlink_queue_t outpacketqueue;
void *priv;
};
+/// A handle for a node Sub-Mesh.
+struct meshlink_submesh {
+ const char *name;
+ void *priv;
+};
+
/// A channel.
struct meshlink_channel {
struct node_t *node;
#include "sockaddr.h"
#include "sptps.h"
#include "utcp/utcp.h"
+#include "submesh.h"
typedef struct node_status_t {
unsigned int unused_active: 1; /* 1 if active (not used for nodes) */
dev_class_t devclass;
struct meshlink_handle *mesh; /* The mesh this node belongs to */
+ struct submesh_t *submesh; /* Nodes Sub-Mesh Handle*/
int sock; /* Socket to use for outgoing UDP packets */
sockaddr_t address; /* his real (internet) ip to send UDP packets to */
--- /dev/null
+/*
+ node.c -- node tree management
+ Copyright (C) 2014 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"
+
+void init_submeshes(meshlink_handle_t *mesh) {
+ mesh->submeshes = list_alloc((list_action_t)free_submesh);
+}
+
+void exit_submeshes(meshlink_handle_t *mesh) {
+ list_delete_list(mesh->submeshes);
+ mesh->submeshes = NULL;
+}
+
+submesh_t *new_submesh(void) {
+ submesh_t *s = xzalloc(sizeof(*s));
+
+ s->name = NULL;
+ s->priv = NULL;
+
+ return s;
+}
+
+void free_submesh(submesh_t *s) {
+ if(s->name) {
+ free(s->name);
+ }
+
+ free(s);
+}
+
+void submesh_add(meshlink_handle_t *mesh, submesh_t *s) {
+ s->mesh = mesh;
+ list_insert_tail(mesh->submeshes, (void *)s);
+}
+
+void submesh_del(meshlink_handle_t *mesh, submesh_t *s) {
+ list_delete(mesh->submeshes, (void *)s);
+}
+
+submesh_t *lookup_submesh(struct meshlink_handle *mesh, const char *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;
+}
\ No newline at end of file
--- /dev/null
+#ifndef MESHLINK_SUBMESH_H
+#define MESHLINK_SUBMESH_H
+
+/*
+ submesh.h -- header for node.c
+ Copyright (C) 2014, 2017 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"
+
+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;
+
+extern void init_submeshes(struct meshlink_handle *mesh);
+extern void exit_submeshes(struct meshlink_handle *mesh);
+extern submesh_t *new_submesh(void) __attribute__((__malloc__));
+extern void free_submesh(submesh_t *);
+extern void submesh_add(struct meshlink_handle *mesh, submesh_t *);
+extern void submesh_del(struct meshlink_handle *mesh, submesh_t *);
+extern submesh_t *lookup_submesh(struct meshlink_handle *mesh, const char *);
+
+#endif