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 \
#include "ecdsa.h"
#include "net.h"
#include "node.h"
-#include "submesh.h"
typedef struct connection_t {
char *name; /* name he claims to have */
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 */
#include "logger.h"
#include "meshlink_internal.h"
#include "node.h"
-#include "submesh.h"
#include "splay_tree.h"
#include "netutl.h"
#include "xalloc.h"
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);
*/
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.
*
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:
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.
*
/// 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
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.
*/
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.
*/
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.
*/
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.
*/
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.
#include "net.h"
#include "netutl.h"
#include "node.h"
-#include "submesh.h"
#include "packmsg.h"
#include "prf.h"
#include "protocol.h"
}
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;
}
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
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));
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;
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;
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;
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;
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;
__emutls_v.meshlink_errno
-devtool_get_all_submeshes
devtool_get_node_status
devtool_keyrotate_probe
devtool_open_in_netns
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
meshlink_stop
meshlink_set_storage_policy
meshlink_strerror
-meshlink_submesh_open
meshlink_verify
#define MESHLINK_CONFIG_VERSION 2
#define MESHLINK_INVITATION_VERSION 2
+#define CORE_MESH "."
+
struct meshlink_open_params {
char *confbase;
char *lock_filename;
struct list_t *connections;
struct list_t *outgoings;
- struct list_t *submeshes;
// Meta-connection-related members
struct splay_tree_t *past_request_tree;
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;
}
}
-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);
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
/* 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);
}
}
#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) {
/// 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;
}
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);
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);
*/
bool setup_network(meshlink_handle_t *mesh) {
init_connections(mesh);
- init_submeshes(mesh);
init_nodes(mesh);
init_requests(mesh);
exit_requests(mesh);
exit_nodes(mesh);
- exit_submeshes(mesh);
exit_connections(mesh);
free(mesh->myport);
*/
#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 */
// 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;
#include "protocol.h"
#include "utils.h"
#include "xalloc.h"
-#include "submesh.h"
/* Jumptable for the request handlers */
/* 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);
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);
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) {
/* 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 *);
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) {
}
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) {
#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) {
/* Tell the others */
- forward_request(mesh, c, NULL, request);
+ forward_request(mesh, c, request);
return true;
}
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) {
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) {
}
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;
}
}
}
- 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;
}
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;
}
return true;
}
- send_request(mesh, to->nexthop->connection, NULL, "%s", request);
+ send_request(mesh, to->nexthop->connection, "%s", request);
}
return true;
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? */
}
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;
}
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) {
}
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) {
+++ /dev/null
-/*
- 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;
- }
-}
+++ /dev/null
-#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