esac
AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="$LDFLAGS -Wl,-z,relro"])
AX_CHECK_LINK_FLAG([-Wl,-z,now], [LDFLAGS="$LDFLAGS -Wl,-z,now"])
+ AX_CHECK_COMPILE_FLAG([-Wextra -pedantic -Wreturn-type -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wshadow -Wbad-function-cast -Wwrite-strings -fdiagnostics-show-option -fstrict-aliasing -Wmissing-noreturn], [CPPFLAGS="$CPPFLAGS -Wextra -pedantic -Wreturn-type -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wshadow -Wbad-function-cast -Wwrite-strings -fdiagnostics-show-option -fno-strict-aliasing -Wmissing-noreturn"])
]
);
}
}
-static meshlink_node_t **nodes;
-static size_t nnodes;
-
static void parse_command(meshlink_handle_t *mesh, char *buf) {
char *arg = strchr(buf, ' ');
char *arg1 = NULL;
- meshlink_submesh_t *s = NULL;
- static meshlink_submesh_t **submesh = NULL;
- static size_t nmemb = 0;
- size_t i;
if(arg) {
*arg++ = 0;
}
if(!strcasecmp(buf, "invite")) {
- char *invitation;
-
if(!arg) {
fprintf(stderr, "/invite requires an argument!\n");
return;
}
- if(arg1) {
+ meshlink_submesh_t *s = NULL;
- submesh = devtool_get_all_submeshes(mesh, submesh, &nmemb);
+ if(arg1) {
+ size_t nmemb;
+ meshlink_submesh_t **submeshes = devtool_get_all_submeshes(mesh, NULL, &nmemb);
- if(!submesh || !nmemb) {
+ if(!submeshes || !nmemb) {
fprintf(stderr, "Group does not exist!\n");
return;
}
- for(i = 0; i < nmemb; i++) {
- if(!strcmp(arg1, submesh[i]->name)) {
- s = submesh[i];
+ for(size_t i = 0; i < nmemb; i++) {
+ if(!strcmp(arg1, submeshes[i]->name)) {
+ s = submeshes[i];
break;
- } else {
- s = NULL;
}
}
+ free(submeshes);
+
if(!s) {
fprintf(stderr, "Group is not yet created!\n");
return;
}
}
- invitation = meshlink_invite(mesh, s, arg);
+ char *invitation = meshlink_invite(mesh, s, arg);
if(!invitation) {
fprintf(stderr, "Could not invite '%s': %s\n", arg, meshlink_strerror(meshlink_errno));
return;
}
- if(!(s = meshlink_submesh_open(mesh, arg))) {
+ meshlink_submesh_t *s = meshlink_submesh_open(mesh, arg);
+
+ if(!s) {
fprintf(stderr, "Could not create group: %s\n", meshlink_strerror(meshlink_errno));
} else {
fprintf(stderr, "Group '%s' created!\n", s->name);
meshlink_submesh_t *node_group = NULL;
if(!arg) {
- nodes = meshlink_get_all_nodes(mesh, nodes, &nnodes);
+ size_t nnodes;
+ meshlink_node_t **nodes = meshlink_get_all_nodes(mesh, NULL, &nnodes);
if(!nnodes) {
fprintf(stderr, "Could not get list of nodes: %s\n", meshlink_strerror(meshlink_errno));
- } else {
- fprintf(stderr, "%lu known nodes:\n", (unsigned long)nnodes);
+ return;
+ }
- for(size_t i = 0; i < nnodes; i++) {
- fprintf(stderr, " %lu. %s", (unsigned long)i, nodes[i]->name);
+ fprintf(stderr, "%lu known nodes:\n", (unsigned long)nnodes);
- if((node_group = meshlink_get_node_submesh(mesh, nodes[i]))) {
- fprintf(stderr, "\t%s", node_group->name);
- }
+ for(size_t i = 0; i < nnodes; i++) {
+ fprintf(stderr, " %lu. %s", (unsigned long)i, nodes[i]->name);
- fprintf(stderr, "\n");
+ if((node_group = meshlink_get_node_submesh(mesh, nodes[i]))) {
+ fprintf(stderr, "\t%s", node_group->name);
}
fprintf(stderr, "\n");
}
+
+ fprintf(stderr, "\n");
+
+ free(nodes);
} else {
meshlink_node_t *node = meshlink_get_node(mesh, arg);
return;
}
- submesh = devtool_get_all_submeshes(mesh, submesh, &nmemb);
+ size_t nmemb;
+ meshlink_submesh_t **submeshes = devtool_get_all_submeshes(mesh, NULL, &nmemb);
- if(!submesh || !nmemb) {
+ if(!submeshes || !nmemb) {
fprintf(stderr, "Group does not exist!\n");
return;
}
- for(i = 0; i < nmemb; i++) {
- if(!strcmp(arg, submesh[i]->name)) {
- s = submesh[i];
+ meshlink_submesh_t *s = NULL;
+
+ for(size_t i = 0; i < nmemb; i++) {
+ if(!strcmp(arg, submeshes[i]->name)) {
+ s = submeshes[i];
break;
- } else {
- s = NULL;
}
}
+ free(submeshes);
+
if(!s) {
fprintf(stderr, "Group %s does not exist!\n", arg);
return;
}
- nodes = meshlink_get_all_nodes_by_submesh(mesh, s, nodes, &nnodes);
+ size_t nnodes;
+ meshlink_node_t **nodes = meshlink_get_all_nodes_by_submesh(mesh, s, NULL, &nnodes);
- if(!nodes) {
+ if(!nodes || !nnodes) {
fprintf(stderr, "Group %s does not contain any nodes!\n", arg);
return;
}
- if(nnodes <= 0) {
- fprintf(stderr, "Could not get list of nodes for group %s: %s\n", arg, meshlink_strerror(meshlink_errno));
- } else {
- fprintf(stderr, "%zu known nodes in group %s:", nnodes, arg);
-
- for(size_t i = 0; i < nnodes; i++) {
- fprintf(stderr, " %s", nodes[i]->name);
- }
+ fprintf(stderr, "%zu known nodes in group %s:", nnodes, arg);
- fprintf(stderr, "\n");
+ for(size_t i = 0; i < nnodes; i++) {
+ fprintf(stderr, " %s", nodes[i]->name);
}
+
+ fprintf(stderr, "\n");
+
+ free(nodes);
} else if(!strcasecmp(buf, "quit")) {
fprintf(stderr, "Bye!\n");
fclose(stdin);
#include <assert.h>
static int n = 10;
-static meshlink_handle_t **mesh;
-static char *namesprefix = "machine1";
+static meshlink_handle_t **meshes;
+static const char *namesprefix = "machine1";
static int nodeindex = 0;
static meshlink_node_t **nodes;
}
//Test mesh sending data
-static void testmesh() {
-
+static void testmesh(void) {
for(int nindex = 0; nindex < n; nindex++) {
- nodes = meshlink_get_all_nodes(mesh[nindex], nodes, &nnodes);
+ nodes = meshlink_get_all_nodes(meshes[nindex], nodes, &nnodes);
if(!nodes) {
fprintf(stderr, "Could not get list of nodes: %s\n", meshlink_strerror(meshlink_errno));
for(size_t i = 0; i < nnodes; i++) {
//printf(" %s\n", nodes[i]->name);
- if(!meshlink_send(mesh[nindex], nodes[i], "magic", strlen("magic") + 1)) {
+ if(!meshlink_send(meshes[nindex], nodes[i], "magic", strlen("magic") + 1)) {
fprintf(stderr, "Could not send message to '%s': %s\n", nodes[i]->name, meshlink_strerror(meshlink_errno));
}
}
}
}
// Make all nodes know about each other by importing each others public keys and addresses.
-static void linkmesh() {
+static void linkmesh(void) {
for(int i = 0; i < n; i++) {
- char *datai = meshlink_export(mesh[i]);
+ char *datai = meshlink_export(meshes[i]);
for(int j = i + 1; j < n; j++) {
- char *dataj = meshlink_export(mesh[j]);
+ char *dataj = meshlink_export(meshes[j]);
- if(!meshlink_import(mesh[i], dataj) || !meshlink_import(mesh[j], datai)) {
- fprintf(stderr, "Could not exchange keys between %s and %s: %s\n", mesh[i]->name, mesh[j]->name, meshlink_strerror(meshlink_errno));
+ if(!meshlink_import(meshes[i], dataj) || !meshlink_import(meshes[j], datai)) {
+ fprintf(stderr, "Could not exchange keys between %s and %s: %s\n", meshes[i]->name, meshes[j]->name, meshlink_strerror(meshlink_errno));
}
free(dataj);
return false;
}
- if(!devtool_export_json_all_edges_state(mesh[0], stream)) {
+ if(!devtool_export_json_all_edges_state(meshes[0], stream)) {
fclose(stream);
fprintf(stderr, "could not export graph\n");
return false;
}
-void exportmeshgraph_timer(int signum) {
+static void exportmeshgraph_timer(int signum) {
(void)signum;
struct timeval ts;
return;
}
- invitation = meshlink_invite(mesh[nodeindex], NULL, arg);
+ invitation = meshlink_invite(meshes[nodeindex], NULL, arg);
if(!invitation) {
fprintf(stderr, "Could not invite '%s': %s\n", arg, meshlink_strerror(meshlink_errno));
return;
}
- meshlink_stop(mesh[nodeindex]);
+ meshlink_stop(meshes[nodeindex]);
- if(!meshlink_join(mesh[nodeindex], arg)) {
+ if(!meshlink_join(meshes[nodeindex], arg)) {
fprintf(stderr, "Could not join using invitation: %s\n", meshlink_strerror(meshlink_errno));
} else {
fprintf(stderr, "Invitation accepted!\n");
}
- if(!meshlink_start(mesh[nodeindex])) {
+ if(!meshlink_start(meshes[nodeindex])) {
fprintf(stderr, "Could not restart MeshLink: %s\n", meshlink_strerror(meshlink_errno));
exit(1);
}
return;
}
- meshlink_node_t *node = meshlink_get_node(mesh[nodeindex], arg);
+ meshlink_node_t *node = meshlink_get_node(meshes[nodeindex], arg);
if(!node) {
fprintf(stderr, "Unknown node '%s'\n", arg);
return;
}
- if(!meshlink_blacklist(mesh[nodeindex], node)) {
+ if(!meshlink_blacklist(meshes[nodeindex], node)) {
fprintf(stderr, "Error blacklising '%s': %s", arg, meshlink_strerror(meshlink_errno));
return;
}
return;
}
- meshlink_node_t *node = meshlink_get_node(mesh[nodeindex], arg);
+ meshlink_node_t *node = meshlink_get_node(meshes[nodeindex], arg);
if(!node) {
fprintf(stderr, "Error looking up '%s': %s\n", arg, meshlink_strerror(meshlink_errno));
return;
}
- if(!meshlink_whitelist(mesh[nodeindex], node)) {
+ if(!meshlink_whitelist(meshes[nodeindex], node)) {
fprintf(stderr, "Error whitelising '%s': %s", arg, meshlink_strerror(meshlink_errno));
return;
}
printf("Node '%s' whitelisted.\n", arg);
} else if(!strcasecmp(buf, "who")) {
if(!arg) {
- nodes = meshlink_get_all_nodes(mesh[nodeindex], nodes, &nnodes);
+ nodes = meshlink_get_all_nodes(meshes[nodeindex], nodes, &nnodes);
if(!nodes) {
fprintf(stderr, "Could not get list of nodes: %s\n", meshlink_strerror(meshlink_errno));
printf("\n");
}
} else {
- meshlink_node_t *node = meshlink_get_node(mesh[nodeindex], arg);
+ meshlink_node_t *node = meshlink_get_node(meshes[nodeindex], arg);
if(!node) {
fprintf(stderr, "Unknown node '%s'\n", arg);
} else {
- printf("Node %s found, pmtu %ld\n", arg, (long int)meshlink_get_pmtu(mesh[nodeindex], node));
+ printf("Node %s found, pmtu %ld\n", arg, (long int)meshlink_get_pmtu(meshes[nodeindex], node));
}
}
} else if(!strcasecmp(buf, "link")) {
nodeindex = atoi(arg);
printf("Index is now %d\n", nodeindex);
} else if(!strcasecmp(buf, "stop")) {
- meshlink_stop(mesh[nodeindex]);
+ meshlink_stop(meshes[nodeindex]);
} else if(!strcasecmp(buf, "quit")) {
printf("Bye!\n");
fclose(stdin);
msg++;
}
- destination = meshlink_get_node(mesh[nodeindex], buf);
+ destination = meshlink_get_node(meshes[nodeindex], buf);
if(!destination) {
fprintf(stderr, "Unknown node '%s'\n", buf);
return;
}
- if(!meshlink_send(mesh[nodeindex], destination, msg, strlen(msg) + 1)) {
+ if(!meshlink_send(meshes[nodeindex], destination, msg, strlen(msg) + 1)) {
fprintf(stderr, "Could not send message to '%s': %s\n", destination->name, meshlink_strerror(meshlink_errno));
return;
}
graphexporttimeout = argv[4];
}
- mesh = calloc(n, sizeof(*mesh));
+ meshes = calloc(n, sizeof(*meshes));
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_message);
#ifndef _WIN32
snprintf(filename, sizeof(filename), "%s/%s", basebase, nodename);
if(n / (i + 1) > n / 4) {
- mesh[i] = meshlink_open(filename, nodename, "manynodes", DEV_CLASS_BACKBONE);
+ meshes[i] = meshlink_open(filename, nodename, "manynodes", DEV_CLASS_BACKBONE);
} else {
- mesh[i] = meshlink_open(filename, nodename, "manynodes", DEV_CLASS_PORTABLE);
+ meshes[i] = meshlink_open(filename, nodename, "manynodes", DEV_CLASS_PORTABLE);
}
- meshlink_set_log_cb(mesh[i], MESHLINK_DEBUG, log_message);
+ meshlink_set_log_cb(meshes[i], MESHLINK_DEBUG, log_message);
- if(!mesh[i]) {
+ if(!meshes[i]) {
fprintf(stderr, "errno is: %d\n", meshlink_errno);
fprintf(stderr, "Could not open %s: %s\n", filename, meshlink_strerror(meshlink_errno));
return 1;
int started = 0;
for(int i = 0; i < n; i++) {
- if(!meshlink_start(mesh[i])) {
+ if(!meshlink_start(meshes[i])) {
fprintf(stderr, "Could not start node %d: %s\n", i, meshlink_strerror(meshlink_errno));
} else {
started++;
printf("Nodes stopping.\n");
for(int i = 0; i < n; i++) {
- meshlink_close(mesh[i]);
+ meshlink_close(meshes[i]);
}
return 0;
#include "../src/system.h"
#include "../src/meshlink.h"
-void handle_recv_data(meshlink_handle_t *mesh, meshlink_node_t *source, void *data, size_t len) {
+static void handle_recv_data(meshlink_handle_t *mesh, meshlink_node_t *source, void *data, size_t len) {
(void)mesh;
printf("Received %zu bytes from %s: %s\n", len, source->name, (char *)data);
}
int main(int argc, char **argv) {
- char *confbase = argc > 1 ? argv[1] : "/tmp/meshlink/";
- char *name = argc > 2 ? argv[2] : "foo";
-
- char *remotename = argc > 3 ? argv[3] : "bar";
+ const char *confbase = argc > 1 ? argv[1] : "/tmp/meshlink/";
+ const char *name = argc > 2 ? argv[2] : "foo";
+ const char *remotename = argc > 3 ? argv[3] : "bar";
meshlink_handle_t *myhandle;
bool done;
};
-void *adns_blocking_handler(void *data) {
+static void *adns_blocking_handler(void *data) {
struct adns_blocking_info *info = data;
logger(info->mesh, MESHLINK_DEBUG, "Resolving %s port %s", info->host, info->serv);
typedef void (*adns_cb_t)(meshlink_handle_t *mesh, char *host, char *serv, void *data, struct addrinfo *ai, int err);
-extern void init_adns(meshlink_handle_t *mesh);
-extern void exit_adns(meshlink_handle_t *mesh);
-extern void adns_queue(meshlink_handle_t *mesh, char *host, char *serv, adns_cb_t cb, void *data, int timeout);
-extern struct addrinfo *adns_blocking_request(meshlink_handle_t *mesh, char *host, char *serv, int timeout);
+void init_adns(meshlink_handle_t *mesh);
+void exit_adns(meshlink_handle_t *mesh);
+void adns_queue(meshlink_handle_t *mesh, char *host, char *serv, adns_cb_t cb, void *data, int timeout);
+struct addrinfo *adns_blocking_request(meshlink_handle_t *mesh, char *host, char *serv, int timeout);
#endif
size_t offset;
} buffer_t;
-extern void buffer_compact(buffer_t *buffer, size_t maxsize);
-extern char *buffer_prepare(buffer_t *buffer, size_t size);
-extern void buffer_add(buffer_t *buffer, const char *data, size_t size);
-extern char *buffer_readline(buffer_t *buffer);
-extern char *buffer_read(buffer_t *buffer, size_t size);
-extern void buffer_clear(buffer_t *buffer);
+void buffer_compact(buffer_t *buffer, size_t maxsize);
+char *buffer_prepare(buffer_t *buffer, size_t size);
+void buffer_add(buffer_t *buffer, const char *data, size_t size);
+char *buffer_readline(buffer_t *buffer);
+char *buffer_read(buffer_t *buffer, size_t size);
+void buffer_clear(buffer_t *buffer);
#endif
typedef bool (*config_scan_action_t)(struct meshlink_handle *mesh, const char *name, void *arg);
-extern bool config_read_file(struct meshlink_handle *mesh, FILE *f, struct config_t *, const void *key) __attribute__((__warn_unused_result__));
-extern bool config_write_file(struct meshlink_handle *mesh, FILE *f, const struct config_t *, const void *key) __attribute__((__warn_unused_result__));
-extern void config_free(struct config_t *config);
-
-extern bool meshlink_confbase_exists(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
-
-extern bool config_init(struct meshlink_handle *mesh, const char *conf_subdir) __attribute__((__warn_unused_result__));
-extern bool config_destroy(const char *confbase, const char *conf_subdir) __attribute__((__warn_unused_result__));
-extern bool config_copy(struct meshlink_handle *mesh, const char *src_dir_name, const void *src_key, const char *dst_dir_name, const void *dst_key) __attribute__((__warn_unused_result__));
-extern bool config_rename(struct meshlink_handle *mesh, const char *old_conf_subdir, const char *new_conf_subdir) __attribute__((__warn_unused_result__));
-extern bool config_sync(struct meshlink_handle *mesh, const char *conf_subdir) __attribute__((__warn_unused_result__));
-extern bool sync_path(const char *path) __attribute__((__warn_unused_result__));
-
-extern bool main_config_exists(struct meshlink_handle *mesh, const char *conf_subdir) __attribute__((__warn_unused_result__));
-extern bool main_config_lock(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
-extern void main_config_unlock(struct meshlink_handle *mesh);
-extern bool main_config_read(struct meshlink_handle *mesh, const char *conf_subdir, struct config_t *, void *key) __attribute__((__warn_unused_result__));
-extern bool main_config_write(struct meshlink_handle *mesh, const char *conf_subdir, const struct config_t *, void *key) __attribute__((__warn_unused_result__));
-
-extern bool config_exists(struct meshlink_handle *mesh, const char *conf_subdir, const char *name) __attribute__((__warn_unused_result__));
-extern bool config_read(struct meshlink_handle *mesh, const char *conf_subdir, const char *name, struct config_t *, void *key) __attribute__((__warn_unused_result__));
-extern bool config_write(struct meshlink_handle *mesh, const char *conf_subdir, const char *name, const struct config_t *, void *key) __attribute__((__warn_unused_result__));
-extern bool config_delete(struct meshlink_handle *mesh, const char *conf_subdir, const char *name) __attribute__((__warn_unused_result__));
-extern bool config_scan_all(struct meshlink_handle *mesh, const char *conf_subdir, const char *conf_type, config_scan_action_t action, void *arg) __attribute__((__warn_unused_result__));
-
-extern bool invitation_read(struct meshlink_handle *mesh, const char *conf_subdir, const char *name, struct config_t *, void *key) __attribute__((__warn_unused_result__));
-extern bool invitation_write(struct meshlink_handle *mesh, const char *conf_subdir, const char *name, const struct config_t *, void *key) __attribute__((__warn_unused_result__));
-extern size_t invitation_purge_old(struct meshlink_handle *mesh, time_t deadline);
+bool config_read_file(struct meshlink_handle *mesh, FILE *f, struct config_t *, const void *key) __attribute__((__warn_unused_result__));
+bool config_write_file(struct meshlink_handle *mesh, FILE *f, const struct config_t *, const void *key) __attribute__((__warn_unused_result__));
+void config_free(struct config_t *config);
+
+bool meshlink_confbase_exists(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
+
+bool config_init(struct meshlink_handle *mesh, const char *conf_subdir) __attribute__((__warn_unused_result__));
+bool config_destroy(const char *confbase, const char *conf_subdir) __attribute__((__warn_unused_result__));
+bool config_copy(struct meshlink_handle *mesh, const char *src_dir_name, const void *src_key, const char *dst_dir_name, const void *dst_key) __attribute__((__warn_unused_result__));
+bool config_rename(struct meshlink_handle *mesh, const char *old_conf_subdir, const char *new_conf_subdir) __attribute__((__warn_unused_result__));
+bool config_sync(struct meshlink_handle *mesh, const char *conf_subdir) __attribute__((__warn_unused_result__));
+bool sync_path(const char *path) __attribute__((__warn_unused_result__));
+
+bool main_config_exists(struct meshlink_handle *mesh, const char *conf_subdir) __attribute__((__warn_unused_result__));
+bool main_config_lock(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
+void main_config_unlock(struct meshlink_handle *mesh);
+bool main_config_read(struct meshlink_handle *mesh, const char *conf_subdir, struct config_t *, void *key) __attribute__((__warn_unused_result__));
+bool main_config_write(struct meshlink_handle *mesh, const char *conf_subdir, const struct config_t *, void *key) __attribute__((__warn_unused_result__));
+
+bool config_exists(struct meshlink_handle *mesh, const char *conf_subdir, const char *name) __attribute__((__warn_unused_result__));
+bool config_read(struct meshlink_handle *mesh, const char *conf_subdir, const char *name, struct config_t *, void *key) __attribute__((__warn_unused_result__));
+bool config_write(struct meshlink_handle *mesh, const char *conf_subdir, const char *name, const struct config_t *, void *key) __attribute__((__warn_unused_result__));
+bool config_delete(struct meshlink_handle *mesh, const char *conf_subdir, const char *name) __attribute__((__warn_unused_result__));
+bool config_scan_all(struct meshlink_handle *mesh, const char *conf_subdir, const char *conf_type, config_scan_action_t action, void *arg) __attribute__((__warn_unused_result__));
+
+bool invitation_read(struct meshlink_handle *mesh, const char *conf_subdir, const char *name, struct config_t *, void *key) __attribute__((__warn_unused_result__));
+bool invitation_write(struct meshlink_handle *mesh, const char *conf_subdir, const char *name, const struct config_t *, void *key) __attribute__((__warn_unused_result__));
+size_t invitation_purge_old(struct meshlink_handle *mesh, time_t deadline);
#endif
int protocol_minor; /* used protocol */
} connection_t;
-extern void init_connections(struct meshlink_handle *mesh);
-extern void exit_connections(struct meshlink_handle *mesh);
-extern connection_t *new_connection(void) __attribute__((__malloc__));
-extern void free_connection(connection_t *);
-extern void connection_add(struct meshlink_handle *mesh, connection_t *);
-extern void connection_del(struct meshlink_handle *mesh, connection_t *);
+void init_connections(struct meshlink_handle *mesh);
+void exit_connections(struct meshlink_handle *mesh);
+connection_t *new_connection(void) __attribute__((__malloc__));
+void free_connection(connection_t *);
+void connection_add(struct meshlink_handle *mesh, connection_t *);
+void connection_del(struct meshlink_handle *mesh, connection_t *);
#endif
/*
crypto.h -- header for crypto.c
- Copyright (C) 2014, 2017 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2020 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
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-extern void crypto_init();
-extern void crypto_exit();
-extern void randomize(void *, size_t);
+void crypto_init(void);
+void crypto_exit(void);
+void randomize(void *buf, size_t len);
#endif
* value. If the new values is NULL, then the old array
* will have been freed by Meshlink.
*/
-extern devtool_edge_t *devtool_get_all_edges(meshlink_handle_t *mesh, devtool_edge_t *edges, size_t *nmemb);
+devtool_edge_t *devtool_get_all_edges(meshlink_handle_t *mesh, devtool_edge_t *edges, size_t *nmemb);
/// Export a list of edges to a file in JSON format.
/* @param mesh A handle which represents an instance of MeshLink.
*
* @return True in case of success, false otherwise.
*/
-extern bool devtool_export_json_all_edges_state(meshlink_handle_t *mesh, FILE *stream);
+bool devtool_export_json_all_edges_state(meshlink_handle_t *mesh, FILE *stream);
/// The status of a node.
typedef struct devtool_node_status devtool_node_status_t;
* The contents of this variable will be changed to reflect
* the current status of the node.
*/
-extern void devtool_get_node_status(meshlink_handle_t *mesh, meshlink_node_t *node, devtool_node_status_t *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.
* The contents of this variable will be changed to indicate
* the number if array elements.
*/
-extern meshlink_submesh_t **devtool_get_all_submeshes(meshlink_handle_t *mesh, meshlink_submesh_t **submeshes, size_t *nmemb);
+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.
* @return A pointer to a meshlink_handle_t which represents this instance of MeshLink, or NULL in case of an error.
* The pointer is valid until meshlink_close() is called.
*/
-extern meshlink_handle_t *devtool_open_in_netns(const char *confbase, const char *name, const char *appname, dev_class_t devclass, int netns);
+meshlink_handle_t *devtool_open_in_netns(const char *confbase, const char *name, const char *appname, dev_class_t devclass, int netns);
/// Debug function pointer variable for set port API
/** This function pointer variable is a userspace tracepoint or debugger callback for
*/
extern void (*devtool_sptps_renewal_probe)(meshlink_node_t *node);
+/// Force renewal of SPTPS sessions with the given node.
+/** This causes the SPTPS sessions for both the UDP and TCP connections to renew their keys.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param node The node whose SPTPS key(s) should be renewed
+ */
+void devtool_force_sptps_renewal(meshlink_handle_t *mesh, meshlink_node_t *node);
+
/// Debug function pointer variable for asserting inviter/invitee committing sequence
/** This function pointer variable is a userspace tracepoint or debugger callback which
* invokes either after inviter writing invitees host file into the disk
#include <stdbool.h>
-extern bool discovery_start(meshlink_handle_t *mesh);
-extern void discovery_stop(meshlink_handle_t *mesh);
+bool discovery_start(meshlink_handle_t *mesh);
+void discovery_stop(meshlink_handle_t *mesh);
#endif
*/
#ifndef HAVE_ASPRINTF
-extern int asprintf(char **, const char *, ...);
-extern int vasprintf(char **, const char *, va_list ap);
+int asprintf(char **, const char *, ...);
+int vasprintf(char **, const char *, va_list ap);
#endif
#ifdef HAVE_MINGW
typedef struct ecdh ecdh_t;
#endif
-extern ecdh_t *ecdh_generate_public(void *pubkey) __attribute__((__malloc__));
-extern bool ecdh_compute_shared(ecdh_t *ecdh, const void *pubkey, void *shared) __attribute__((__warn_unused_result__));
-extern void ecdh_free(ecdh_t *ecdh);
+ecdh_t *ecdh_generate_public(void *pubkey) __attribute__((__malloc__));
+bool ecdh_compute_shared(ecdh_t *ecdh, const void *pubkey, void *shared) __attribute__((__warn_unused_result__));
+void ecdh_free(ecdh_t *ecdh);
#endif
typedef struct ecdsa ecdsa_t;
#endif
-extern ecdsa_t *ecdsa_set_private_key(const void *p) __attribute__((__malloc__));
-extern ecdsa_t *ecdsa_set_base64_public_key(const char *p) __attribute__((__malloc__));
-extern ecdsa_t *ecdsa_set_public_key(const void *p) __attribute__((__malloc__));
-extern char *ecdsa_get_base64_public_key(ecdsa_t *ecdsa);
-extern const void *ecdsa_get_public_key(ecdsa_t *ecdsa) __attribute__((__malloc__));
-extern const void *ecdsa_get_private_key(ecdsa_t *ecdsa) __attribute__((__malloc__));
-extern ecdsa_t *ecdsa_read_pem_public_key(FILE *fp) __attribute__((__malloc__));
-extern ecdsa_t *ecdsa_read_pem_private_key(FILE *fp) __attribute__((__malloc__));
-extern size_t ecdsa_size(ecdsa_t *ecdsa);
-extern bool ecdsa_sign(ecdsa_t *ecdsa, const void *in, size_t inlen, void *out) __attribute__((__warn_unused_result__));
-extern bool ecdsa_verify(ecdsa_t *ecdsa, const void *in, size_t inlen, const void *out) __attribute__((__warn_unused_result__));
-extern bool ecdsa_active(ecdsa_t *ecdsa);
-extern void ecdsa_free(ecdsa_t *ecdsa);
+ecdsa_t *ecdsa_set_private_key(const void *p) __attribute__((__malloc__));
+ecdsa_t *ecdsa_set_base64_public_key(const char *p) __attribute__((__malloc__));
+ecdsa_t *ecdsa_set_public_key(const void *p) __attribute__((__malloc__));
+char *ecdsa_get_base64_public_key(ecdsa_t *ecdsa);
+const void *ecdsa_get_public_key(ecdsa_t *ecdsa) __attribute__((__malloc__));
+const void *ecdsa_get_private_key(ecdsa_t *ecdsa) __attribute__((__malloc__));
+ecdsa_t *ecdsa_read_pem_public_key(FILE *fp) __attribute__((__malloc__));
+ecdsa_t *ecdsa_read_pem_private_key(FILE *fp) __attribute__((__malloc__));
+size_t ecdsa_size(ecdsa_t *ecdsa);
+bool ecdsa_sign(ecdsa_t *ecdsa, const void *in, size_t inlen, void *out) __attribute__((__warn_unused_result__));
+bool ecdsa_verify(ecdsa_t *ecdsa, const void *in, size_t inlen, const void *out) __attribute__((__warn_unused_result__));
+bool ecdsa_active(ecdsa_t *ecdsa);
+void ecdsa_free(ecdsa_t *ecdsa);
#endif
#include "ecdsa.h"
-extern ecdsa_t *ecdsa_generate(void) __attribute__((__malloc__));
-extern bool ecdsa_write_pem_public_key(ecdsa_t *ecdsa, FILE *fp) __attribute__((__warn_unused_result__));
-extern bool ecdsa_write_pem_private_key(ecdsa_t *ecdsa, FILE *fp) __attribute__((__warn_unused_result__));
+ecdsa_t *ecdsa_generate(void) __attribute__((__malloc__));
+bool ecdsa_write_pem_public_key(ecdsa_t *ecdsa, FILE *fp) __attribute__((__warn_unused_result__));
+bool ecdsa_write_pem_private_key(ecdsa_t *ecdsa, FILE *fp) __attribute__((__warn_unused_result__));
#endif
uint32_t session_id; /* the session_id of the from node */
} edge_t;
-extern void init_edges(struct meshlink_handle *mesh);
-extern void exit_edges(struct meshlink_handle *mesh);
-extern edge_t *new_edge(void) __attribute__((__malloc__));
-extern void free_edge(edge_t *);
-extern struct splay_tree_t *new_edge_tree(void) __attribute__((__malloc__));
-extern void free_edge_tree(struct splay_tree_t *);
-extern void edge_add(struct meshlink_handle *mesh, edge_t *);
-extern void edge_del(struct meshlink_handle *mesh, edge_t *);
-extern edge_t *lookup_edge(struct node_t *, struct node_t *) __attribute__((__warn_unused_result__));
+void init_edges(struct meshlink_handle *mesh);
+void exit_edges(struct meshlink_handle *mesh);
+edge_t *new_edge(void) __attribute__((__malloc__));
+void free_edge(edge_t *);
+struct splay_tree_t *new_edge_tree(void) __attribute__((__malloc__));
+void free_edge_tree(struct splay_tree_t *);
+void edge_add(struct meshlink_handle *mesh, edge_t *);
+void edge_del(struct meshlink_handle *mesh, edge_t *);
+edge_t *lookup_edge(struct node_t *, struct node_t *) __attribute__((__warn_unused_result__));
#endif
return true;
}
-void event_flush_output(event_loop_t *loop) {
- for splay_each(io_t, io, &loop->ios)
- if(FD_ISSET(io->fd, &loop->writefds)) {
- io->cb(loop, io->data, IO_WRITE);
- }
-}
-
void event_loop_start(event_loop_t *loop) {
loop->running = true;
}
assert(!loop->signals.count);
for splay_each(io_t, io, &loop->ios) {
- splay_unlink_node(&loop->ios, node);
+ splay_unlink_node(&loop->ios, splay_node);
}
for splay_each(timeout_t, timeout, &loop->timeouts) {
- splay_unlink_node(&loop->timeouts, node);
+ splay_unlink_node(&loop->timeouts, splay_node);
}
for splay_each(signal_t, signal, &loop->signals) {
- splay_unlink_node(&loop->signals, node);
+ splay_unlink_node(&loop->signals, splay_node);
}
}
int pipefd[2];
};
-extern void io_add(event_loop_t *loop, io_t *io, io_cb_t cb, void *data, int fd, int flags);
-extern void io_del(event_loop_t *loop, io_t *io);
-extern void io_set(event_loop_t *loop, io_t *io, int flags);
-
-extern void timeout_add(event_loop_t *loop, timeout_t *timeout, timeout_cb_t cb, void *data, struct timespec *tv);
-extern void timeout_del(event_loop_t *loop, timeout_t *timeout);
-extern void timeout_set(event_loop_t *loop, timeout_t *timeout, struct timespec *tv);
-
-extern void signal_add(event_loop_t *loop, signal_t *sig, signal_cb_t cb, void *data, uint8_t signum);
-extern void signal_trigger(event_loop_t *loop, signal_t *sig);
-extern void signal_del(event_loop_t *loop, signal_t *sig);
-
-extern void idle_set(event_loop_t *loop, idle_cb_t cb, void *data);
-
-extern void event_loop_init(event_loop_t *loop);
-extern void event_loop_exit(event_loop_t *loop);
-extern bool event_loop_run(event_loop_t *loop, pthread_mutex_t *mutex) __attribute__((__warn_unused_result__));
-extern void event_loop_flush_output(event_loop_t *loop);
-extern void event_loop_start(event_loop_t *loop);
-extern void event_loop_stop(event_loop_t *loop);
+void io_add(event_loop_t *loop, io_t *io, io_cb_t cb, void *data, int fd, int flags);
+void io_del(event_loop_t *loop, io_t *io);
+void io_set(event_loop_t *loop, io_t *io, int flags);
+
+void timeout_add(event_loop_t *loop, timeout_t *timeout, timeout_cb_t cb, void *data, struct timespec *tv);
+void timeout_del(event_loop_t *loop, timeout_t *timeout);
+void timeout_set(event_loop_t *loop, timeout_t *timeout, struct timespec *tv);
+
+void signal_add(event_loop_t *loop, signal_t *sig, signal_cb_t cb, void *data, uint8_t signum);
+void signal_trigger(event_loop_t *loop, signal_t *sig);
+void signal_del(event_loop_t *loop, signal_t *sig);
+
+void idle_set(event_loop_t *loop, idle_cb_t cb, void *data);
+
+void event_loop_init(event_loop_t *loop);
+void event_loop_exit(event_loop_t *loop);
+bool event_loop_run(event_loop_t *loop, pthread_mutex_t *mutex) __attribute__((__warn_unused_result__));
+void event_loop_flush_output(event_loop_t *loop);
+void event_loop_start(event_loop_t *loop);
+void event_loop_stop(event_loop_t *loop);
#endif
list_insert_tail(todo_list, e->to);
}
- next = node->next; /* Because the list_insert_tail() above could have added something extra for us! */
- list_delete_node(todo_list, node);
+ list_next = list_node->next; /* Because the list_insert_tail() above could have added something extra for us! */
+ list_delete_node(todo_list, list_node);
}
list_free(todo_list);
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-extern void graph(struct meshlink_handle *mesh);
+void graph(struct meshlink_handle *mesh);
#endif
const void **values;
} hash_t;
-extern hash_t *hash_alloc(size_t n, size_t size) __attribute__((__malloc__));
-extern void hash_free(hash_t *);
+hash_t *hash_alloc(size_t n, size_t size) __attribute__((__malloc__));
+void hash_free(hash_t *);
-extern void hash_insert(hash_t *, const void *key, const void *value);
+void hash_insert(hash_t *, const void *key, const void *value);
-extern void *hash_search(const hash_t *, const void *key);
-extern void *hash_search_or_insert(hash_t *, const void *key, const void *value);
+void *hash_search(const hash_t *, const void *key);
+void *hash_search_or_insert(hash_t *, const void *key, const void *value);
-extern void hash_clear(hash_t *);
-extern void hash_resize(hash_t *, size_t n);
+void hash_clear(hash_t *);
+void hash_resize(hash_t *, size_t n);
#endif
/* (De)constructors */
-extern list_t *list_alloc(list_action_t) __attribute__((__malloc__));
-extern void list_free(list_t *);
+list_t *list_alloc(list_action_t) __attribute__((__malloc__));
+void list_free(list_t *);
/* Insertion and deletion */
-extern list_node_t *list_insert_head(list_t *, void *);
-extern list_node_t *list_insert_tail(list_t *, void *);
+list_node_t *list_insert_head(list_t *, void *);
+list_node_t *list_insert_tail(list_t *, void *);
-extern void list_delete(list_t *, const void *);
+void list_delete(list_t *, const void *);
-extern void list_delete_node(list_t *, list_node_t *);
+void list_delete_node(list_t *, list_node_t *);
-extern void list_delete_head(list_t *);
-extern void list_delete_tail(list_t *);
+void list_delete_head(list_t *);
+void list_delete_tail(list_t *);
/* Head/tail lookup */
-extern void *list_get_head(list_t *);
-extern void *list_get_tail(list_t *);
+void *list_get_head(list_t *);
+void *list_get_tail(list_t *);
/* Fast list deletion */
-extern void list_delete_list(list_t *);
+void list_delete_list(list_t *);
/* Traversing */
-extern void list_foreach(list_t *, list_action_t);
-extern void list_foreach_node(list_t *, list_action_node_t);
+void list_foreach(list_t *, list_action_t);
+void list_foreach_node(list_t *, list_action_node_t);
-#define list_each(type, item, list) (type *item = (type *)1; item; item = NULL) for(list_node_t *node = (list)->head, *next; item = node ? node->data : NULL, next = node ? node->next : NULL, node; node = next)
+#define list_each(type, item, list) (type *item = (type *)1; item; item = NULL) for(list_node_t *list_node = (list)->head, *list_next; item = list_node ? list_node->data : NULL, list_next = list_node ? list_node->next : NULL, list_node; list_node = list_next)
#endif
#include "meshlink_internal.h"
-extern void logger(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *format, ...) __attribute__((__format__(printf, 3, 4)));
+void logger(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *format, ...) __attribute__((__format__(printf, 3, 4)));
#endif
// Find out what local address a socket would use if we connect to the given address.
// We do this using connect() on a UDP socket, so the kernel has to resolve the address
// of both endpoints, but this will actually not send any UDP packet.
-static bool getlocaladdr(char *destaddr, sockaddr_t *sa, socklen_t *salen, int netns) {
+static bool getlocaladdr(const char *destaddr, sockaddr_t *sa, socklen_t *salen, int netns) {
struct addrinfo *rai = NULL;
const struct addrinfo hint = {
.ai_family = AF_UNSPEC,
return true;
}
-static bool getlocaladdrname(char *destaddr, char *host, socklen_t hostlen, int netns) {
+static bool getlocaladdrname(const char *destaddr, char *host, socklen_t hostlen, int netns) {
sockaddr_t sa;
socklen_t salen = sizeof(sa);
return xstrdup(localaddr);
}
-void remove_duplicate_hostnames(char *host[], char *port[], int n) {
+static void remove_duplicate_hostnames(char *host[], char *port[], int n) {
for(int i = 0; i < n; i++) {
if(!host[i]) {
continue;
// Write host config files
for(uint32_t i = 0; i < count; i++) {
const void *data;
- uint32_t len = packmsg_get_bin_raw(&in, &data);
+ uint32_t data_len = packmsg_get_bin_raw(&in, &data);
- if(!len) {
+ if(!data_len) {
logger(mesh, MESHLINK_ERROR, "Incomplete invitation file!\n");
return false;
}
- packmsg_input_t in2 = {data, len};
- uint32_t version = packmsg_get_uint32(&in2);
- char *name = packmsg_get_str_dup(&in2);
+ packmsg_input_t in2 = {data, data_len};
+ uint32_t version2 = packmsg_get_uint32(&in2);
+ char *name2 = packmsg_get_str_dup(&in2);
- if(!packmsg_input_ok(&in2) || version != MESHLINK_CONFIG_VERSION || !check_id(name)) {
- free(name);
+ if(!packmsg_input_ok(&in2) || version2 != MESHLINK_CONFIG_VERSION || !check_id(name2)) {
+ free(name2);
packmsg_input_invalidate(&in);
break;
}
- if(!check_id(name)) {
- free(name);
+ if(!check_id(name2)) {
+ free(name2);
break;
}
- if(!strcmp(name, mesh->name)) {
+ if(!strcmp(name2, mesh->name)) {
logger(mesh, MESHLINK_DEBUG, "Secondary chunk would overwrite our own host config file.\n");
- free(name);
+ free(name2);
meshlink_errno = MESHLINK_EPEER;
return false;
}
node_t *n = new_node();
- n->name = name;
+ n->name = name2;
- config_t config = {data, len};
+ config_t config = {data, data_len};
if(!node_read_from_config(mesh, n, &config)) {
free_node(n);
return true;
}
-static bool sendline(int fd, char *format, ...) {
+static bool sendline(int fd, const char *format, ...) {
char buffer[4096];
char *p = buffer;
int blen = 0;
pthread_mutex_lock(&mesh->mutex);
while(count--) {
- const void *data;
- uint32_t len = packmsg_get_bin_raw(&in, &data);
+ const void *data2;
+ uint32_t len2 = packmsg_get_bin_raw(&in, &data2);
- if(!len) {
+ if(!len2) {
break;
}
- packmsg_input_t in2 = {data, len};
+ packmsg_input_t in2 = {data2, len2};
uint32_t version = packmsg_get_uint32(&in2);
char *name = packmsg_get_str_dup(&in2);
n = new_node();
n->name = name;
- config_t config = {data, len};
+ config_t config = {data2, len2};
if(!node_read_from_config(mesh, n, &config)) {
free_node(n);
if(mesh->outgoings) {
for list_each(outgoing_t, outgoing, mesh->outgoings) {
if(outgoing->node == n) {
- list_delete_node(mesh->outgoings, node);
+ list_delete_node(mesh->outgoings, list_node);
}
}
}
retry(mesh);
}
-void call_error_cb(meshlink_handle_t *mesh, meshlink_errno_t meshlink_errno) {
+void call_error_cb(meshlink_handle_t *mesh, meshlink_errno_t cb_errno) {
// We should only call the callback function if we are in the background thread.
if(!mesh->error_cb) {
return;
}
if(mesh->thread == pthread_self()) {
- mesh->error_cb(mesh, meshlink_errno);
+ mesh->error_cb(mesh, cb_errno);
}
}
* The pointer is to static storage that is valid for the lifetime of the application.
* This function will always return a valid pointer, even if an invalid error code has been passed.
*/
-extern const char *meshlink_strerror(meshlink_errno_t err) __attribute__((__warn_unused_result__));
+const char *meshlink_strerror(meshlink_errno_t err) __attribute__((__warn_unused_result__));
/// Create a new meshlink_open_params_t struct.
/** This function allocates and initializes a new meshlink_open_params_t struct that can be passed to meshlink_open_ex().
* @return A pointer to a meshlink_open_params_t which can be passed to meshlink_open_ex(), or NULL in case of an error.
* The pointer is valid until meshlink_open_params_free() is called.
*/
-extern meshlink_open_params_t *meshlink_open_params_init(const char *confbase, const char *name, const char *appname, dev_class_t devclass) __attribute__((__warn_unused_result__));
+meshlink_open_params_t *meshlink_open_params_init(const char *confbase, const char *name, const char *appname, dev_class_t devclass) __attribute__((__warn_unused_result__));
/// Free a meshlink_open_params_t struct.
/** This function frees a meshlink_open_params_t struct and all resources associated with it.
*
* @param params A pointer to a meshlink_open_params_t which must have been created earlier with meshlink_open_params_init().
*/
-extern void meshlink_open_params_free(meshlink_open_params_t *params);
+void meshlink_open_params_free(meshlink_open_params_t *params);
/// Set the network namespace MeshLink should use.
/** This function changes the open parameters to use the given netns filedescriptor.
*
* @return This function will return true if the open parameters have been successfully updated, false otherwise.
*/
-extern bool meshlink_open_params_set_netns(meshlink_open_params_t *params, int netns) __attribute__((__warn_unused_result__));
+bool meshlink_open_params_set_netns(meshlink_open_params_t *params, int netns) __attribute__((__warn_unused_result__));
/// Set the encryption key MeshLink should use for local storage.
/** This function changes the open parameters to use the given key for encrypting MeshLink's own configuration files.
*
* @return This function will return true if the open parameters have been successfully updated, false otherwise.
*/
-extern bool meshlink_open_params_set_storage_key(meshlink_open_params_t *params, const void *key, size_t keylen) __attribute__((__warn_unused_result__));
+bool meshlink_open_params_set_storage_key(meshlink_open_params_t *params, const void *key, size_t keylen) __attribute__((__warn_unused_result__));
/// Open or create a MeshLink instance.
/** This function opens or creates a MeshLink instance.
* @return A pointer to a struct meshlink_handle which represents this instance of MeshLink, or NULL in case of an error.
* The pointer is valid until meshlink_close() is called.
*/
-extern struct meshlink_handle *meshlink_open_ex(const meshlink_open_params_t *params) __attribute__((__warn_unused_result__));
+struct meshlink_handle *meshlink_open_ex(const meshlink_open_params_t *params) __attribute__((__warn_unused_result__));
/// Open or create a MeshLink instance.
/** This function opens or creates a MeshLink instance.
* @return A pointer to a struct meshlink_handle which represents this instance of MeshLink, or NULL in case of an error.
* The pointer is valid until meshlink_close() is called.
*/
-extern struct meshlink_handle *meshlink_open(const char *confbase, const char *name, const char *appname, dev_class_t devclass) __attribute__((__warn_unused_result__));
+struct meshlink_handle *meshlink_open(const char *confbase, const char *name, const char *appname, dev_class_t devclass) __attribute__((__warn_unused_result__));
/// Open or create a MeshLink instance that uses encrypted storage.
/** This function opens or creates a MeshLink instance.
* @return A pointer to a struct meshlink_handle which represents this instance of MeshLink, or NULL in case of an error.
* The pointer is valid until meshlink_close() is called.
*/
-extern struct meshlink_handle *meshlink_open_encrypted(const char *confbase, const char *name, const char *appname, dev_class_t devclass, const void *key, size_t keylen) __attribute__((__warn_unused_result__));
+struct meshlink_handle *meshlink_open_encrypted(const char *confbase, const char *name, const char *appname, dev_class_t devclass, const void *key, size_t keylen) __attribute__((__warn_unused_result__));
/// Create an ephemeral MeshLink instance that does not store any state.
/** This function creates a MeshLink instance.
* @return A pointer to a struct meshlink_handle which represents this instance of MeshLink, or NULL in case of an error.
* The pointer is valid until meshlink_close() is called.
*/
-extern struct meshlink_handle *meshlink_open_ephemeral(const char *name, const char *appname, dev_class_t devclass) __attribute__((__warn_unused_result__));
+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
*
* @return This function will return true if MeshLink has successfully started, false otherwise.
*/
-extern bool meshlink_start(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
+bool meshlink_start(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
/// Stop MeshLink.
/** This function causes MeshLink to disconnect from all other nodes,
* \memberof meshlink_handle
* @param mesh A handle which represents an instance of MeshLink.
*/
-extern void meshlink_stop(struct meshlink_handle *mesh);
+void meshlink_stop(struct meshlink_handle *mesh);
/// Close the MeshLink handle.
/** This function calls meshlink_stop() if necessary,
* \memberof meshlink_handle
* @param mesh A handle which represents an instance of MeshLink.
*/
-extern void meshlink_close(struct meshlink_handle *mesh);
+void meshlink_close(struct meshlink_handle *mesh);
/// Destroy a MeshLink instance.
/** This function remove all configuration files of a MeshLink instance. It should only be called when the application
*
* @return This function will return true if the MeshLink instance was successfully destroyed, false otherwise.
*/
-extern bool meshlink_destroy(const char *confbase) __attribute__((__warn_unused_result__));
+bool meshlink_destroy(const char *confbase) __attribute__((__warn_unused_result__));
/// A callback for receiving data from the mesh.
/** @param mesh A handle which represents an instance of MeshLink.
* @param cb A pointer to the function which will be called when another node sends data to the local node.
* If a NULL pointer is given, the callback will be disabled.
*/
-extern void meshlink_set_receive_cb(struct meshlink_handle *mesh, meshlink_receive_cb_t cb);
+void meshlink_set_receive_cb(struct meshlink_handle *mesh, meshlink_receive_cb_t cb);
/// A callback reporting the meta-connection attempt made by the host node to an another node.
/** @param mesh A handle which represents an instance of MeshLink.
* @param cb A pointer to the function which will be called when host node attempts to make
* the connection to another node. If a NULL pointer is given, the callback will be disabled.
*/
-extern void meshlink_set_connection_try_cb(struct meshlink_handle *mesh, meshlink_connection_try_cb_t cb);
+void meshlink_set_connection_try_cb(struct meshlink_handle *mesh, meshlink_connection_try_cb_t cb);
/// A callback reporting node status changes.
/** @param mesh A handle which represents an instance of MeshLink.
* @param cb A pointer to the function which will be called when another node's status changes.
* If a NULL pointer is given, the callback will be disabled.
*/
-extern void meshlink_set_node_status_cb(struct meshlink_handle *mesh, meshlink_node_status_cb_t cb);
+void meshlink_set_node_status_cb(struct meshlink_handle *mesh, meshlink_node_status_cb_t cb);
/// A callback reporting node path MTU changes.
/** @param mesh A handle which represents an instance of MeshLink.
* @param cb A pointer to the function which will be called when another node's extended status changes.
* If a NULL pointer is given, the callback will be disabled.
*/
-extern void meshlink_set_node_pmtu_cb(struct meshlink_handle *mesh, meshlink_node_pmtu_cb_t cb);
+void meshlink_set_node_pmtu_cb(struct meshlink_handle *mesh, meshlink_node_pmtu_cb_t cb);
/// A callback reporting duplicate node detection.
/** @param mesh A handle which represents an instance of MeshLink.
* @param cb A pointer to the function which will be called when a duplicate node is detected.
* If a NULL pointer is given, the callback will be disabled.
*/
-extern void meshlink_set_node_duplicate_cb(struct meshlink_handle *mesh, meshlink_node_duplicate_cb_t cb);
+void meshlink_set_node_duplicate_cb(struct meshlink_handle *mesh, meshlink_node_duplicate_cb_t cb);
/// Severity of log messages generated by MeshLink.
typedef enum {
* @param cb A pointer to the function which will be called when another node sends data to the local node.
* If a NULL pointer is given, the callback will be disabled.
*/
-extern void meshlink_set_log_cb(struct meshlink_handle *mesh, meshlink_log_level_t level, meshlink_log_cb_t cb);
+void meshlink_set_log_cb(struct meshlink_handle *mesh, meshlink_log_level_t level, meshlink_log_cb_t cb);
/// A callback for receiving error conditions encountered by the MeshLink thread.
/** @param mesh A handle which represents an instance of MeshLink, or NULL.
* @param cb A pointer to the function which will be called when a serious error is encountered.
* If a NULL pointer is given, the callback will be disabled.
*/
-extern void meshlink_set_error_cb(struct meshlink_handle *mesh, meshlink_error_cb_t cb);
+void meshlink_set_error_cb(struct meshlink_handle *mesh, meshlink_error_cb_t cb);
/// Send data to another node.
/** This functions sends one packet of data to another node in the mesh.
* @return This function will return true if MeshLink has queued the message for transmission, and false otherwise.
* A return value of true does not guarantee that the message will actually arrive at the destination.
*/
-extern bool meshlink_send(struct meshlink_handle *mesh, struct meshlink_node *destination, const void *data, size_t len) __attribute__((__warn_unused_result__));
+bool meshlink_send(struct meshlink_handle *mesh, struct meshlink_node *destination, const void *data, size_t len) __attribute__((__warn_unused_result__));
/// Query the maximum packet size that can be sent to a node.
/** This functions returns the maximum size of packets (path MTU) that can be sent to a specific node with meshlink_send().
* @return The recommended maximum size of packets that are to be sent to the destination node, 0 if the node is unreachable,
* or a negative value in case of an error.
*/
-extern ssize_t meshlink_get_pmtu(struct meshlink_handle *mesh, struct meshlink_node *destination) __attribute__((__warn_unused_result__));
+ssize_t meshlink_get_pmtu(struct meshlink_handle *mesh, struct meshlink_node *destination) __attribute__((__warn_unused_result__));
/// Get a handle for our own node.
/** This function returns a handle for the local node.
* @return A pointer to a struct meshlink_node which represents the local node.
* The pointer is guaranteed to be valid until meshlink_close() is called.
*/
-extern struct meshlink_node *meshlink_get_self(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
+struct meshlink_node *meshlink_get_self(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
/// Get a handle for a specific node.
/** This function returns a handle for the node with the given name.
* or NULL if the requested node does not exist.
* The pointer is guaranteed to be valid until meshlink_close() is called.
*/
-extern struct meshlink_node *meshlink_get_node(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__));
+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.
* or NULL if the requested submesh does not exist.
* The pointer is guaranteed to be valid until meshlink_close() is called.
*/
-extern struct meshlink_submesh *meshlink_get_submesh(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__));
+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.
* @return A nul-terminated C string containing the fingerprint of the node's public key in a printable ASCII format.
* The application should call free() after it is done using this string.
*/
-extern char *meshlink_get_fingerprint(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__));
+char *meshlink_get_fingerprint(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__));
/// Get a list of all nodes.
/** This function returns a list with handles for all known nodes.
* 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.
*/
-extern struct meshlink_node **meshlink_get_all_nodes(struct meshlink_handle *mesh, struct meshlink_node **nodes, size_t *nmemb) __attribute__((__warn_unused_result__));
+struct meshlink_node **meshlink_get_all_nodes(struct meshlink_handle *mesh, struct meshlink_node **nodes, size_t *nmemb) __attribute__((__warn_unused_result__));
/// Sign data using the local node's MeshLink key.
/** This function signs data using the local node's MeshLink key.
*
* @return This function returns true if the signature was correctly generated, false otherwise.
*/
-extern bool meshlink_sign(struct meshlink_handle *mesh, const void *data, size_t len, void *signature, size_t *siglen) __attribute__((__warn_unused_result__));
+bool meshlink_sign(struct meshlink_handle *mesh, const void *data, size_t len, void *signature, size_t *siglen) __attribute__((__warn_unused_result__));
/// Get the list of all nodes by device class.
/** This function returns a list with handles for all the nodes that matches with the given @a devclass.
* 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.
*/
-extern 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__));
+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.
* 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.
*/
-extern 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__));
+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 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.
*/
-extern struct meshlink_node **meshlink_get_all_nodes_by_last_reachable(struct meshlink_handle *mesh, time_t start, time_t end, struct meshlink_node **nodes, size_t *nmemb) __attribute__((__warn_unused_result__));
+struct meshlink_node **meshlink_get_all_nodes_by_last_reachable(struct meshlink_handle *mesh, time_t start, time_t end, struct meshlink_node **nodes, size_t *nmemb) __attribute__((__warn_unused_result__));
/// Get the node's device class.
/** This function returns the device class of the given node.
*
* @return This function returns the device class of the @a node, or -1 in case of an error.
*/
-extern dev_class_t meshlink_get_node_dev_class(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__));
+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.
*
* @return This function returns the submesh handle of the @a node, or NULL in case of an error.
*/
-extern struct meshlink_submesh *meshlink_get_node_submesh(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__));
+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.
*
* @return This function returns true if the node is currently reachable, false otherwise.
*/
-extern bool meshlink_get_node_reachability(struct meshlink_handle *mesh, struct meshlink_node *node, time_t *last_reachable, time_t *last_unreachable);
+bool meshlink_get_node_reachability(struct meshlink_handle *mesh, struct meshlink_node *node, time_t *last_reachable, time_t *last_unreachable);
/// Verify the signature generated by another node of a piece of data.
/** This function verifies the signature that another node generated for a piece of data.
*
* @return This function returns true if the signature is valid, false otherwise.
*/
-extern bool meshlink_verify(struct meshlink_handle *mesh, struct meshlink_node *source, const void *data, size_t len, const void *signature, size_t siglen) __attribute__((__warn_unused_result__));
+bool meshlink_verify(struct meshlink_handle *mesh, struct meshlink_node *source, const void *data, size_t len, const void *signature, size_t siglen) __attribute__((__warn_unused_result__));
/// Set the canonical Address for a node.
/** This function sets the canonical Address for a node.
*
* @return This function returns true if the address was added, false otherwise.
*/
-extern bool meshlink_set_canonical_address(struct meshlink_handle *mesh, struct meshlink_node *node, const char *address, const char *port) __attribute__((__warn_unused_result__));
+bool meshlink_set_canonical_address(struct meshlink_handle *mesh, struct meshlink_node *node, const char *address, const char *port) __attribute__((__warn_unused_result__));
/// Add an invitation address for the local node.
/** This function adds an address for the local node, which will be used only for invitation URLs.
*
* @return This function returns true if the address was added, false otherwise.
*/
-extern bool meshlink_add_invitation_address(struct meshlink_handle *mesh, const char *address, const char *port) __attribute__((__warn_unused_result__));
+bool meshlink_add_invitation_address(struct meshlink_handle *mesh, const char *address, const char *port) __attribute__((__warn_unused_result__));
/// Clears all invitation address for the local node.
/** This function removes all addresses added with meshlink_add_invitation_address().
* \memberof meshlink_handle
* @param mesh A handle which represents an instance of MeshLink.
*/
-extern void meshlink_clear_invitation_addresses(struct meshlink_handle *mesh);
+void meshlink_clear_invitation_addresses(struct meshlink_handle *mesh);
/// Add an Address for the local node.
/** This function adds an Address for the local node, which will be used for invitation URLs.
*
* @return This function returns true if the address was added, false otherwise.
*/
-extern bool meshlink_add_address(struct meshlink_handle *mesh, const char *address) __attribute__((__warn_unused_result__, __deprecated__("use meshlink_set_canonical_address() and/or meshlink_add_invitation_address() instead")));
+bool meshlink_add_address(struct meshlink_handle *mesh, const char *address) __attribute__((__warn_unused_result__, __deprecated__("use meshlink_set_canonical_address() and/or meshlink_add_invitation_address() instead")));
/// Try to discover the external address for the local node.
/** This function performs tries to discover the local node's external address
* or NULL if there was an error looking up the address.
* After meshlink_get_external_address() returns, the application is free to overwrite or free this string.
*/
-extern char *meshlink_get_external_address(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
+char *meshlink_get_external_address(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
/// Try to discover the external address for the local node.
/** This function performs tries to discover the local node's external address
* or NULL if there was an error looking up the address.
* After meshlink_get_external_address_for_family() returns, the application is free to overwrite or free this string.
*/
-extern char *meshlink_get_external_address_for_family(struct meshlink_handle *mesh, int address_family) __attribute__((__warn_unused_result__));
+char *meshlink_get_external_address_for_family(struct meshlink_handle *mesh, int address_family) __attribute__((__warn_unused_result__));
/// Try to discover the local address for the local node.
/** This function performs tries to discover the address of the local interface used for outgoing connection.
* or NULL if there was an error looking up the address.
* After meshlink_get_local_address_for_family() returns, the application is free to overwrite or free this string.
*/
-extern char *meshlink_get_local_address_for_family(struct meshlink_handle *mesh, int address_family) __attribute__((__warn_unused_result__));
+char *meshlink_get_local_address_for_family(struct meshlink_handle *mesh, int address_family) __attribute__((__warn_unused_result__));
/// Try to discover the external address for the local node, and add it to its list of addresses.
/** This function is equivalent to:
*
* @return This function returns true if the address was added, false otherwise.
*/
-extern bool meshlink_add_external_address(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
+bool meshlink_add_external_address(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
/// Get the network port used by the local node.
/** This function returns the network port that the local node is listening on.
*
* @return This function returns the port number, or -1 in case of an error.
*/
-extern int meshlink_get_port(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
+int meshlink_get_port(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
/// Set the network port used by the local node.
/** This function sets the network port that the local node is listening on.
* is no guarantee that MeshLink is listening on the old port.
*/
-extern bool meshlink_set_port(struct meshlink_handle *mesh, int port) __attribute__((__warn_unused_result__));
+bool meshlink_set_port(struct meshlink_handle *mesh, int port) __attribute__((__warn_unused_result__));
/// Set the timeout for invitations.
/** This function sets the timeout for invitations.
* @param mesh A handle which represents an instance of MeshLink.
* @param timeout The timeout for invitations in seconds.
*/
-extern void meshlink_set_invitation_timeout(struct meshlink_handle *mesh, int timeout);
+void meshlink_set_invitation_timeout(struct meshlink_handle *mesh, int timeout);
/// Invite another node into the mesh.
/** This function generates an invitation that can be used by another node to join the same mesh as the local node.
* @return This function returns a nul-terminated C string that contains the invitation URL, or NULL in case of an error.
* The application should call free() after it has finished using the URL.
*/
-extern char *meshlink_invite_ex(struct meshlink_handle *mesh, struct meshlink_submesh *submesh, const char *name, uint32_t flags) __attribute__((__warn_unused_result__));
+char *meshlink_invite_ex(struct meshlink_handle *mesh, struct meshlink_submesh *submesh, const char *name, uint32_t flags) __attribute__((__warn_unused_result__));
/// Invite another node into the mesh.
/** This function generates an invitation that can be used by another node to join the same mesh as the local node.
* @return This function returns a nul-terminated C string that contains the invitation URL, or NULL in case of an error.
* The application should call free() after it has finished using the URL.
*/
-extern char *meshlink_invite(struct meshlink_handle *mesh, struct meshlink_submesh *submesh, const char *name) __attribute__((__warn_unused_result__));
+char *meshlink_invite(struct meshlink_handle *mesh, struct meshlink_submesh *submesh, const char *name) __attribute__((__warn_unused_result__));
/// Use an invitation to join a mesh.
/** This function allows the local node to join an existing mesh using an invitation URL generated by another node.
*
* @return This function returns true if the local node joined the mesh it was invited to, false otherwise.
*/
-extern bool meshlink_join(struct meshlink_handle *mesh, const char *invitation) __attribute__((__warn_unused_result__));
+bool meshlink_join(struct meshlink_handle *mesh, const char *invitation) __attribute__((__warn_unused_result__));
/// Export the local node's key and addresses.
/** This function generates a string that contains the local node's public key and one or more IP addresses.
* @return This function returns a nul-terminated C string that contains the exported key and addresses, or NULL in case of an error.
* The application should call free() after it has finished using this string.
*/
-extern char *meshlink_export(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
+char *meshlink_export(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
/// Import another node's key and addresses.
/** This function accepts a string containing the exported public key and addresses of another node.
*
* @return This function returns true if the data was valid and the other node has been granted access to the mesh, false otherwise.
*/
-extern bool meshlink_import(struct meshlink_handle *mesh, const char *data) __attribute__((__warn_unused_result__));
+bool meshlink_import(struct meshlink_handle *mesh, const char *data) __attribute__((__warn_unused_result__));
/// Forget any information about a node.
/** This function allows the local node to forget any information it has about a node,
*
* @return This function returns true if all currently known data about the node has been forgotten, false otherwise.
*/
-extern bool meshlink_forget_node(struct meshlink_handle *mesh, struct meshlink_node *node);
+bool meshlink_forget_node(struct meshlink_handle *mesh, struct meshlink_node *node);
/// Blacklist a node from the mesh.
/** This function causes the local node to blacklist another node.
*
* @return This function returns true if the node has been blacklisted, false otherwise.
*/
-extern bool meshlink_blacklist(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__));
+bool meshlink_blacklist(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__));
/// Blacklist a node from the mesh by name.
/** This function causes the local node to blacklist another node by name.
*
* @return This function returns true if the node has been blacklisted, false otherwise.
*/
-extern bool meshlink_blacklist_by_name(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__));
+bool meshlink_blacklist_by_name(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__));
/// Whitelist a node on the mesh.
/** This function causes the local node to whitelist a previously blacklisted node.
*
* @return This function returns true if the node has been whitelisted, false otherwise.
*/
-extern bool meshlink_whitelist(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__));
+bool meshlink_whitelist(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__));
/// Whitelist a node on the mesh by name.
/** This function causes the local node to whitelist a node by name.
*
* @return This function returns true if the node has been whitelisted, false otherwise.
*/
-extern bool meshlink_whitelist_by_name(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__));
+bool meshlink_whitelist_by_name(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__));
/// Set whether new nodes are blacklisted by default.
/** This function sets the blacklist behaviour for newly discovered nodes.
* @param mesh A handle which represents an instance of MeshLink.
* @param blacklist True if new nodes are to be blacklisted, false if whitelisted.
*/
-extern void meshlink_set_default_blacklist(struct meshlink_handle *mesh, bool blacklist);
+void meshlink_set_default_blacklist(struct meshlink_handle *mesh, bool blacklist);
/// A callback for accepting incoming channels.
/** This function is called whenever a remote node wants to open a channel to the local node.
* @param cb A pointer to the function which will be called when another node sends data to the local node.
* If a NULL pointer is given, the callback will be disabled.
*/
-extern void meshlink_set_channel_accept_cb(struct meshlink_handle *mesh, meshlink_channel_accept_cb_t cb);
+void meshlink_set_channel_accept_cb(struct meshlink_handle *mesh, meshlink_channel_accept_cb_t cb);
/// Set the receive callback.
/** This functions sets the callback that is called whenever another node sends data to the local node.
* @param cb A pointer to the function which will be called when another node sends data to the local node.
* If a NULL pointer is given, the callback will be disabled and incoming data is ignored.
*/
-extern void meshlink_set_channel_receive_cb(struct meshlink_handle *mesh, struct meshlink_channel *channel, meshlink_channel_receive_cb_t cb);
+void meshlink_set_channel_receive_cb(struct meshlink_handle *mesh, struct meshlink_channel *channel, meshlink_channel_receive_cb_t cb);
/// Set the poll callback.
/** This functions sets the callback that is called whenever data can be sent to another node.
* @param cb A pointer to the function which will be called when data can be sent to another node.
* If a NULL pointer is given, the callback will be disabled.
*/
-extern void meshlink_set_channel_poll_cb(struct meshlink_handle *mesh, struct meshlink_channel *channel, meshlink_channel_poll_cb_t cb);
+void meshlink_set_channel_poll_cb(struct meshlink_handle *mesh, struct meshlink_channel *channel, meshlink_channel_poll_cb_t cb);
/// Set the send buffer size of a channel.
/** This function sets the desired size of the send buffer.
* @param size The desired size for the send buffer.
* If a NULL pointer is given, the callback will be disabled.
*/
-extern void meshlink_set_channel_sndbuf(struct meshlink_handle *mesh, struct meshlink_channel *channel, size_t size);
+void meshlink_set_channel_sndbuf(struct meshlink_handle *mesh, struct meshlink_channel *channel, size_t size);
/// Set the receive buffer size of a channel.
/** This function sets the desired size of the receive buffer.
* @param size The desired size for the send buffer.
* If a NULL pointer is given, the callback will be disabled.
*/
-extern void meshlink_set_channel_rcvbuf(struct meshlink_handle *mesh, struct meshlink_channel *channel, size_t size);
+void meshlink_set_channel_rcvbuf(struct meshlink_handle *mesh, struct meshlink_channel *channel, size_t size);
/// Open a reliable stream channel to another node.
/** This function is called whenever a remote node wants to open a channel to the local node.
* @return A handle for the channel, or NULL in case of an error.
* The handle is valid until meshlink_channel_close() is called.
*/
-extern struct meshlink_channel *meshlink_channel_open_ex(struct meshlink_handle *mesh, struct meshlink_node *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len, uint32_t flags) __attribute__((__warn_unused_result__));
+struct meshlink_channel *meshlink_channel_open_ex(struct meshlink_handle *mesh, struct meshlink_node *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len, uint32_t flags) __attribute__((__warn_unused_result__));
/// Open a reliable stream channel to another node.
/** This function is called whenever a remote node wants to open a channel to the local node.
* @return A handle for the channel, or NULL in case of an error.
* The handle is valid until meshlink_channel_close() is called.
*/
-extern struct meshlink_channel *meshlink_channel_open(struct meshlink_handle *mesh, struct meshlink_node *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len) __attribute__((__warn_unused_result__));
+struct meshlink_channel *meshlink_channel_open(struct meshlink_handle *mesh, struct meshlink_node *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len) __attribute__((__warn_unused_result__));
/// Partially close a reliable stream channel.
/** This shuts down the read or write side of a channel, or both, without closing the handle.
* @param channel A handle for the channel.
* @param direction Must be one of SHUT_RD, SHUT_WR or SHUT_RDWR, otherwise this call will not have any affect.
*/
-extern void meshlink_channel_shutdown(struct meshlink_handle *mesh, struct meshlink_channel *channel, int direction);
+void meshlink_channel_shutdown(struct meshlink_handle *mesh, struct meshlink_channel *channel, int direction);
/// Close a reliable stream channel.
/** This informs the remote node that the local node has finished sending all data on the channel.
* @param mesh A handle which represents an instance of MeshLink.
* @param channel A handle for the channel.
*/
-extern void meshlink_channel_close(struct meshlink_handle *mesh, struct meshlink_channel *channel);
+void meshlink_channel_close(struct meshlink_handle *mesh, struct meshlink_channel *channel);
/// Transmit data on a channel
/** This queues data to send to the remote node.
* If MESHLINK_CHANNEL_NO_PARTIAL is set, then the result will either be len,
* 0 if the buffer is currently too full, or -1 if len is too big even for an empty buffer.
*/
-extern ssize_t meshlink_channel_send(struct meshlink_handle *mesh, struct meshlink_channel *channel, const void *data, size_t len) __attribute__((__warn_unused_result__));
+ssize_t meshlink_channel_send(struct meshlink_handle *mesh, struct meshlink_channel *channel, const void *data, size_t len) __attribute__((__warn_unused_result__));
/// A callback for cleaning up buffers submitted for asynchronous I/O.
/** This callbacks signals that MeshLink has finished using this buffer.
*
* @return True if the buffer was enqueued, false otherwise.
*/
-extern bool meshlink_channel_aio_send(struct meshlink_handle *mesh, struct meshlink_channel *channel, const void *data, size_t len, meshlink_aio_cb_t cb, void *priv) __attribute__((__warn_unused_result__));
+bool meshlink_channel_aio_send(struct meshlink_handle *mesh, struct meshlink_channel *channel, const void *data, size_t len, meshlink_aio_cb_t cb, void *priv) __attribute__((__warn_unused_result__));
/// Transmit data on a channel asynchronously from a filedescriptor
/** This will read up to the specified length number of bytes from the given filedescriptor, and send it over the channel.
*
* @return True if the buffer was enqueued, false otherwise.
*/
-extern bool meshlink_channel_aio_fd_send(struct meshlink_handle *mesh, struct meshlink_channel *channel, int fd, size_t len, meshlink_aio_fd_cb_t cb, void *priv) __attribute__((__warn_unused_result__));
+bool meshlink_channel_aio_fd_send(struct meshlink_handle *mesh, struct meshlink_channel *channel, int fd, size_t len, meshlink_aio_fd_cb_t cb, void *priv) __attribute__((__warn_unused_result__));
/// Receive data on a channel asynchronously
/** This registers a buffer that will be filled with incoming channel data.
*
* @return True if the buffer was enqueued, false otherwise.
*/
-extern bool meshlink_channel_aio_receive(struct meshlink_handle *mesh, struct meshlink_channel *channel, const void *data, size_t len, meshlink_aio_cb_t cb, void *priv) __attribute__((__warn_unused_result__));
+bool meshlink_channel_aio_receive(struct meshlink_handle *mesh, struct meshlink_channel *channel, const void *data, size_t len, meshlink_aio_cb_t cb, void *priv) __attribute__((__warn_unused_result__));
/// Receive data on a channel asynchronously and send it to a filedescriptor
/** This will read up to the specified length number of bytes from the channel, and send it to the filedescriptor.
*
* @return True if the buffer was enqueued, false otherwise.
*/
-extern bool meshlink_channel_aio_fd_receive(struct meshlink_handle *mesh, struct meshlink_channel *channel, int fd, size_t len, meshlink_aio_fd_cb_t cb, void *priv) __attribute__((__warn_unused_result__));
+bool meshlink_channel_aio_fd_receive(struct meshlink_handle *mesh, struct meshlink_channel *channel, int fd, size_t len, meshlink_aio_fd_cb_t cb, void *priv) __attribute__((__warn_unused_result__));
/// Get channel flags.
/** This returns the flags used when opening this channel.
*
* @return The flags set for this channel.
*/
-extern uint32_t meshlink_channel_get_flags(struct meshlink_handle *mesh, struct meshlink_channel *channel) __attribute__((__warn_unused_result__));
+uint32_t meshlink_channel_get_flags(struct meshlink_handle *mesh, struct meshlink_channel *channel) __attribute__((__warn_unused_result__));
/// Get the amount of bytes in the send buffer.
/** This returns the amount of bytes in the send buffer.
*
* @return The amount of un-ACKed bytes in the send buffer.
*/
-extern size_t meshlink_channel_get_sendq(struct meshlink_handle *mesh, struct meshlink_channel *channel) __attribute__((__warn_unused_result__));
+size_t meshlink_channel_get_sendq(struct meshlink_handle *mesh, struct meshlink_channel *channel) __attribute__((__warn_unused_result__));
/// Get the amount of bytes in the receive buffer.
/** This returns the amount of bytes in the receive buffer.
*
* @return The amount of bytes in the receive buffer.
*/
-extern size_t meshlink_channel_get_recvq(struct meshlink_handle *mesh, struct meshlink_channel *channel) __attribute__((__warn_unused_result__));
+size_t meshlink_channel_get_recvq(struct meshlink_handle *mesh, struct meshlink_channel *channel) __attribute__((__warn_unused_result__));
/// Get the maximum segment size of a channel.
/** This returns the amount of bytes that can be sent at once for channels with UDP semantics.
*
* @return The amount of bytes in the receive buffer.
*/
-extern size_t meshlink_channel_get_mss(struct meshlink_handle *mesh, struct meshlink_channel *channel) __attribute__((__warn_unused_result__));
+size_t meshlink_channel_get_mss(struct meshlink_handle *mesh, struct meshlink_channel *channel) __attribute__((__warn_unused_result__));
/// Set the connection timeout used for channels to the given node.
/** This sets the timeout after which unresponsive channels will be reported as closed.
* @param timeout The timeout in seconds after which unresponsive channels will be reported as closed.
* The default is 60 seconds.
*/
-extern void meshlink_set_node_channel_timeout(struct meshlink_handle *mesh, struct meshlink_node *node, int timeout);
+void meshlink_set_node_channel_timeout(struct meshlink_handle *mesh, struct meshlink_node *node, int timeout);
/// Hint that a hostname may be found at an address
/** This function indicates to meshlink that the given hostname is likely found
* given hostname. The caller is free to overwrite or free
* this memory once meshlink returns.
*/
-extern void meshlink_hint_address(struct meshlink_handle *mesh, struct meshlink_node *node, const struct sockaddr *addr);
+void meshlink_hint_address(struct meshlink_handle *mesh, struct meshlink_node *node, const struct sockaddr *addr);
/// Enable or disable zeroconf discovery of local peers
/** This controls whether zeroconf discovery using the Catta library will be
* @param mesh A handle which represents an instance of MeshLink.
* @param enable Set to true to enable discovery, false to disable.
*/
-extern void meshlink_enable_discovery(struct meshlink_handle *mesh, bool enable);
+void meshlink_enable_discovery(struct meshlink_handle *mesh, bool enable);
/// Performs key rotation for an encrypted storage
/** This rotates the (master) key for an encrypted storage and discards the old key
*
* @return This function returns true if the key rotation for the encrypted storage succeeds, false otherwise.
*/
-extern bool meshlink_encrypted_key_rotate(struct meshlink_handle *mesh, const void *key, size_t keylen) __attribute__((__warn_unused_result__));
+bool meshlink_encrypted_key_rotate(struct meshlink_handle *mesh, const void *key, size_t keylen) __attribute__((__warn_unused_result__));
/// Set device class timeouts
/** This sets the ping interval and timeout for a given device class.
* @param pingtimeout The required time within which a peer should respond, in seconds. The default is 5.
* The timeout must be smaller than the interval.
*/
-extern void meshlink_set_dev_class_timeouts(struct meshlink_handle *mesh, dev_class_t devclass, int pinginterval, int pingtimeout);
+void meshlink_set_dev_class_timeouts(struct meshlink_handle *mesh, dev_class_t devclass, int pinginterval, int pingtimeout);
/// Set device class fast retry period
/** This sets the fast retry period for a given device class.
* @param devclass The device class to update
* @param fast_retry_period The period during which fast connection retries are done. The default is 0.
*/
-extern void meshlink_set_dev_class_fast_retry_period(struct meshlink_handle *mesh, dev_class_t devclass, int fast_retry_period);
+void meshlink_set_dev_class_fast_retry_period(struct meshlink_handle *mesh, dev_class_t devclass, int fast_retry_period);
/// Set which order invitations are committed
/** This determines in which order configuration files are written to disk during an invitation.
* @param mesh A handle which represents an instance of MeshLink.
* @param inviter_commits_first If true, then the node that invited a peer will commit data to disk first.
*/
-extern void meshlink_set_inviter_commits_first(struct meshlink_handle *mesh, bool inviter_commits_first);
+void meshlink_set_inviter_commits_first(struct meshlink_handle *mesh, bool inviter_commits_first);
/// Set the URL used to discover the host's external address
/** For generating invitation URLs, MeshLink can look up the externally visible address of the local node.
* @param mesh A handle which represents an instance of MeshLink.
* @param url The URL to use for external address queries, or NULL to revert back to the default URL.
*/
-extern void meshlink_set_external_address_discovery_url(struct meshlink_handle *mesh, const char *url);
+void meshlink_set_external_address_discovery_url(struct meshlink_handle *mesh, const char *url);
/// Set the scheduling granularity of the application
/** This should be set to the effective scheduling granularity for the application.
* @param mesh A handle which represents an instance of MeshLink.
* @param granularity The scheduling granularity of the application in microseconds.
*/
-extern void meshlink_set_scheduling_granularity(struct meshlink_handle *mesh, long granularity);
+void meshlink_set_scheduling_granularity(struct meshlink_handle *mesh, long granularity);
#ifdef __cplusplus
}
uint8_t source[16];
} __attribute__((__packed__)) meshlink_packethdr_t;
-extern void meshlink_send_from_queue(event_loop_t *loop, void *mesh);
-extern void update_node_status(meshlink_handle_t *mesh, struct node_t *n);
-extern void update_node_pmtu(meshlink_handle_t *mesh, struct node_t *n);
+void meshlink_send_from_queue(event_loop_t *loop, void *mesh);
+void update_node_status(meshlink_handle_t *mesh, struct node_t *n);
+void update_node_pmtu(meshlink_handle_t *mesh, struct node_t *n);
extern meshlink_log_level_t global_log_level;
extern meshlink_log_cb_t global_log_cb;
-extern void handle_duplicate_node(meshlink_handle_t *mesh, struct node_t *n);
-extern void handle_network_change(meshlink_handle_t *mesh, bool online);
-extern void call_error_cb(meshlink_handle_t *mesh, meshlink_errno_t meshlink_errno);
+void handle_duplicate_node(meshlink_handle_t *mesh, struct node_t *n);
+void handle_network_change(meshlink_handle_t *mesh, bool online);
+void call_error_cb(meshlink_handle_t *mesh, meshlink_errno_t meshlink_errno);
/// Per-instance PRNG
static inline int prng(meshlink_handle_t *mesh, uint64_t max) {
}
}
-void broadcast_submesh_meta(meshlink_handle_t *mesh, connection_t *from, submesh_t *s, const char *buffer, int length) {
+void broadcast_submesh_meta(meshlink_handle_t *mesh, connection_t *from, const submesh_t *s, const char *buffer, int length) {
assert(buffer);
assert(length);
#include "connection.h"
-extern bool send_meta(struct meshlink_handle *mesh, struct connection_t *, const char *, int);
-extern bool send_meta_sptps(void *, uint8_t, const void *, size_t);
-extern bool receive_meta_sptps(void *, uint8_t, const void *, uint16_t);
-extern 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, submesh_t *s,
+bool send_meta(struct meshlink_handle *mesh, struct connection_t *, const char *, int);
+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);
-extern bool receive_meta(struct meshlink_handle *mesh, struct connection_t *) __attribute__((__warn_unused_result__));
+bool receive_meta(struct meshlink_handle *mesh, struct connection_t *) __attribute__((__warn_unused_result__));
#endif
#include "connection.h"
#include "node.h"
-extern void init_outgoings(struct meshlink_handle *mesh);
-extern void exit_outgoings(struct meshlink_handle *mesh);
-
-extern void retry_outgoing(struct meshlink_handle *mesh, outgoing_t *);
-extern void handle_incoming_vpn_data(struct event_loop_t *loop, void *, int);
-extern void finish_connecting(struct meshlink_handle *mesh, struct connection_t *);
-extern void do_outgoing_connection(struct meshlink_handle *mesh, struct outgoing_t *);
-extern void handle_new_meta_connection(struct event_loop_t *loop, void *, int);
-extern int setup_tcp_listen_socket(struct meshlink_handle *mesh, const struct addrinfo *aip) __attribute__((__warn_unused_result__));
-extern int setup_udp_listen_socket(struct meshlink_handle *mesh, const struct addrinfo *aip) __attribute__((__warn_unused_result__));
-extern bool send_sptps_data(void *handle, uint8_t type, const void *data, size_t len);
-extern bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t len) __attribute__((__warn_unused_result__));
-extern void send_packet(struct meshlink_handle *mesh, struct node_t *, struct vpn_packet_t *);
-extern char *get_name(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
-extern void load_all_nodes(struct meshlink_handle *mesh);
-extern bool setup_myself_reloadable(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
-extern bool setup_network(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
-extern void reset_outgoing(struct outgoing_t *);
-extern void setup_outgoing_connection(struct meshlink_handle *mesh, struct outgoing_t *);
-extern void close_network_connections(struct meshlink_handle *mesh);
-extern void main_loop(struct meshlink_handle *mesh);
-extern void terminate_connection(struct meshlink_handle *mesh, struct connection_t *, bool);
-extern bool node_read_public_key(struct meshlink_handle *mesh, struct node_t *) __attribute__((__warn_unused_result__));
-extern bool node_read_from_config(struct meshlink_handle *mesh, struct node_t *, const config_t *config) __attribute__((__warn_unused_result__));
-extern bool read_ecdsa_public_key(struct meshlink_handle *mesh, struct connection_t *) __attribute__((__warn_unused_result__));
-extern bool read_ecdsa_private_key(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
-extern bool node_write_config(struct meshlink_handle *mesh, struct node_t *) __attribute__((__warn_unused_result__));
-extern void send_mtu_probe(struct meshlink_handle *mesh, struct node_t *);
-extern void handle_meta_connection_data(struct meshlink_handle *mesh, struct connection_t *);
-extern void retry(struct meshlink_handle *mesh);
-extern int check_port(struct meshlink_handle *mesh);
+void init_outgoings(struct meshlink_handle *mesh);
+void exit_outgoings(struct meshlink_handle *mesh);
+
+void retry_outgoing(struct meshlink_handle *mesh, outgoing_t *);
+void handle_incoming_vpn_data(struct event_loop_t *loop, void *, int);
+void finish_connecting(struct meshlink_handle *mesh, struct connection_t *);
+void do_outgoing_connection(struct meshlink_handle *mesh, struct outgoing_t *);
+void handle_new_meta_connection(struct event_loop_t *loop, void *, int);
+int setup_tcp_listen_socket(struct meshlink_handle *mesh, const struct addrinfo *aip) __attribute__((__warn_unused_result__));
+int setup_udp_listen_socket(struct meshlink_handle *mesh, const struct addrinfo *aip) __attribute__((__warn_unused_result__));
+bool send_sptps_data(void *handle, uint8_t type, const void *data, size_t len);
+bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t len) __attribute__((__warn_unused_result__));
+void send_packet(struct meshlink_handle *mesh, struct node_t *, struct vpn_packet_t *);
+char *get_name(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
+void load_all_nodes(struct meshlink_handle *mesh);
+bool setup_myself_reloadable(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
+bool setup_network(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
+void reset_outgoing(struct outgoing_t *);
+void setup_outgoing_connection(struct meshlink_handle *mesh, struct outgoing_t *);
+void close_network_connections(struct meshlink_handle *mesh);
+void main_loop(struct meshlink_handle *mesh);
+void terminate_connection(struct meshlink_handle *mesh, struct connection_t *, bool);
+bool node_read_public_key(struct meshlink_handle *mesh, struct node_t *) __attribute__((__warn_unused_result__));
+bool node_read_from_config(struct meshlink_handle *mesh, struct node_t *, const config_t *config) __attribute__((__warn_unused_result__));
+bool read_ecdsa_public_key(struct meshlink_handle *mesh, struct connection_t *) __attribute__((__warn_unused_result__));
+bool read_ecdsa_private_key(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
+bool node_write_config(struct meshlink_handle *mesh, struct node_t *) __attribute__((__warn_unused_result__));
+void send_mtu_probe(struct meshlink_handle *mesh, struct node_t *);
+void handle_meta_connection_data(struct meshlink_handle *mesh, struct connection_t *);
+void retry(struct meshlink_handle *mesh);
+int check_port(struct meshlink_handle *mesh);
#ifndef HAVE_MINGW
#define closesocket(s) close(s)
/* Otherwise, address are found in edges to this node.
So we pick a random edge and a random socket. */
- int i = 0;
- int j = prng(mesh, n->edge_tree->count);
edge_t *candidate = NULL;
- for splay_each(edge_t, e, n->edge_tree) {
- if(i++ == j) {
- candidate = e->reverse;
- break;
+ {
+ int i = 0;
+ int j = prng(mesh, n->edge_tree->count);
+
+ for splay_each(edge_t, e, n->edge_tree) {
+ if(i++ == j) {
+ candidate = e->reverse;
+ break;
+ }
}
}
/*
Configure node_t mesh->self and set up the local sockets (listen only)
*/
-bool setup_myself(meshlink_handle_t *mesh) {
+static bool setup_myself(meshlink_handle_t *mesh) {
/* Set some defaults */
mesh->maxtimeout = 900;
#include "net.h"
#include "packmsg.h"
-extern struct addrinfo *str2addrinfo(const char *, const char *, int) __attribute__((__malloc__));
-extern sockaddr_t str2sockaddr(const char *, const char *);
-extern void sockaddr2str(const sockaddr_t *, char **, char **);
-extern char *sockaddr2hostname(const sockaddr_t *) __attribute__((__malloc__));
-extern int sockaddrcmp(const sockaddr_t *, const sockaddr_t *) __attribute__((__warn_unused_result__));
-extern int sockaddrcmp_noport(const sockaddr_t *, const sockaddr_t *) __attribute__((__warn_unused_result__));
-extern void sockaddrunmap(sockaddr_t *);
-extern void sockaddrfree(sockaddr_t *);
-extern void sockaddrcpy(sockaddr_t *, const sockaddr_t *);
-extern void sockaddrcpy_setport(sockaddr_t *, const sockaddr_t *, uint16_t port);
-
-extern void packmsg_add_sockaddr(struct packmsg_output *out, const sockaddr_t *);
-extern sockaddr_t packmsg_get_sockaddr(struct packmsg_input *in) __attribute__((__warn_unused_result__));
+struct addrinfo *str2addrinfo(const char *, const char *, int) __attribute__((__malloc__));
+sockaddr_t str2sockaddr(const char *, const char *);
+void sockaddr2str(const sockaddr_t *, char **, char **);
+char *sockaddr2hostname(const sockaddr_t *) __attribute__((__malloc__));
+int sockaddrcmp(const sockaddr_t *, const sockaddr_t *) __attribute__((__warn_unused_result__));
+int sockaddrcmp_noport(const sockaddr_t *, const sockaddr_t *) __attribute__((__warn_unused_result__));
+void sockaddrunmap(sockaddr_t *);
+void sockaddrfree(sockaddr_t *);
+void sockaddrcpy(sockaddr_t *, const sockaddr_t *);
+void sockaddrcpy_setport(sockaddr_t *, const sockaddr_t *, uint16_t port);
+
+void packmsg_add_sockaddr(struct packmsg_output *out, const sockaddr_t *);
+sockaddr_t packmsg_get_sockaddr(struct packmsg_input *in) __attribute__((__warn_unused_result__));
#endif
struct splay_tree_t *edge_tree; /* Edges with this node as one of the endpoints */
} node_t;
-extern void init_nodes(struct meshlink_handle *mesh);
-extern void exit_nodes(struct meshlink_handle *mesh);
-extern node_t *new_node(void) __attribute__((__malloc__));
-extern void free_node(node_t *n);
-extern void node_add(struct meshlink_handle *mesh, node_t *n);
-extern void node_del(struct meshlink_handle *mesh, node_t *n);
-extern node_t *lookup_node(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__));
-extern node_t *lookup_node_udp(struct meshlink_handle *mesh, const sockaddr_t *sa) __attribute__((__warn_unused_result__));
-extern void update_node_udp(struct meshlink_handle *mesh, node_t *n, const sockaddr_t *sa);
-extern bool node_add_recent_address(struct meshlink_handle *mesh, node_t *n, const sockaddr_t *addr);
+void init_nodes(struct meshlink_handle *mesh);
+void exit_nodes(struct meshlink_handle *mesh);
+node_t *new_node(void) __attribute__((__malloc__));
+void free_node(node_t *n);
+void node_add(struct meshlink_handle *mesh, node_t *n);
+void node_del(struct meshlink_handle *mesh, node_t *n);
+node_t *lookup_node(struct meshlink_handle *mesh, const char *name) __attribute__((__warn_unused_result__));
+node_t *lookup_node_udp(struct meshlink_handle *mesh, const sockaddr_t *sa) __attribute__((__warn_unused_result__));
+void update_node_udp(struct meshlink_handle *mesh, node_t *n, const sockaddr_t *sa);
+bool node_add_recent_address(struct meshlink_handle *mesh, node_t *n, const sockaddr_t *addr);
#endif
We use SHA512 instead of MD5 and SHA1.
*/
-bool prf(const char *secret, size_t secretlen, char *seed, size_t seedlen, char *out, size_t outlen) {
+bool prf(const char *secret, size_t secretlen, const char *seed, size_t seedlen, char *out, size_t outlen) {
assert(secret);
assert(secretlen);
assert(seed);
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-extern bool prf(const char *secret, size_t secretlen, char *seed, size_t seedlen, char *out, size_t outlen) __attribute__((__warn_unused_result__));
+bool prf(const char *secret, size_t secretlen, const char *seed, size_t seedlen, char *out, size_t outlen) __attribute__((__warn_unused_result__));
#endif
/* Request names */
-static char (*request_name[]) = {
+static const char *request_name[] = {
"ID", "METAKEY", "CHALLENGE", "CHAL_REPLY", "ACK",
"STATUS", "ERROR", "TERMREQ",
"PING", "PONG",
/* Generic request routines - takes care of logging and error
detection as well */
-bool send_request(meshlink_handle_t *mesh, connection_t *c, submesh_t *s, const char *format, ...) {
+bool send_request(meshlink_handle_t *mesh, connection_t *c, const submesh_t *s, const char *format, ...) {
assert(c);
assert(format);
assert(*format);
}
}
-void forward_request(meshlink_handle_t *mesh, connection_t *from, submesh_t *s, const char *request) {
+void forward_request(meshlink_handle_t *mesh, connection_t *from, const submesh_t *s, const char *request) {
assert(from);
assert(request);
assert(*request);
for splay_each(past_request_t, p, mesh->past_request_tree) {
if(p->firstseen + request_timeout <= mesh->loop.now.tv_sec) {
- splay_delete_node(mesh->past_request_tree, node), deleted++;
+ splay_delete_node(mesh->past_request_tree, splay_node), deleted++;
} else {
left++;
}
/* Basic functions */
-extern bool send_request(struct meshlink_handle *mesh, struct connection_t *, struct submesh_t *s, const char *, ...) __attribute__((__format__(printf, 4, 5)));
-extern void forward_request(struct meshlink_handle *mesh, struct connection_t *, struct submesh_t *, const char *);
-extern bool receive_request(struct meshlink_handle *mesh, struct connection_t *, const char *);
-extern bool check_id(const char *);
+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 receive_request(struct meshlink_handle *mesh, struct connection_t *, const char *);
+bool check_id(const char *);
-extern void init_requests(struct meshlink_handle *mesh);
-extern void exit_requests(struct meshlink_handle *mesh);
-extern bool seen_request(struct meshlink_handle *mesh, const char *);
+void init_requests(struct meshlink_handle *mesh);
+void exit_requests(struct meshlink_handle *mesh);
+bool seen_request(struct meshlink_handle *mesh, const char *);
/* Requests */
-extern bool send_id(struct meshlink_handle *mesh, struct connection_t *);
-extern bool send_ack(struct meshlink_handle *mesh, struct connection_t *);
-extern bool send_ping(struct meshlink_handle *mesh, struct connection_t *);
-extern bool send_pong(struct meshlink_handle *mesh, struct connection_t *);
-extern bool send_add_edge(struct meshlink_handle *mesh, struct connection_t *, const struct edge_t *, int contradictions);
-extern bool send_del_edge(struct meshlink_handle *mesh, struct connection_t *, const struct edge_t *, int contradictions);
-extern bool send_req_key(struct meshlink_handle *mesh, struct node_t *);
+bool send_id(struct meshlink_handle *mesh, struct connection_t *);
+bool send_ack(struct meshlink_handle *mesh, struct connection_t *);
+bool send_ping(struct meshlink_handle *mesh, struct connection_t *);
+bool send_pong(struct meshlink_handle *mesh, struct connection_t *);
+bool send_add_edge(struct meshlink_handle *mesh, struct connection_t *, const struct edge_t *, int contradictions);
+bool send_del_edge(struct meshlink_handle *mesh, struct connection_t *, const struct edge_t *, int contradictions);
+bool send_req_key(struct meshlink_handle *mesh, struct node_t *);
/* Request handlers */
-extern bool id_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
-extern bool ack_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
-extern bool status_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
-extern bool error_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
-extern bool termreq_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
-extern bool ping_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
-extern bool pong_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
-extern bool add_edge_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
-extern bool del_edge_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
-extern bool key_changed_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
-extern bool req_key_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
-extern bool ans_key_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
-extern bool tcppacket_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
+bool id_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
+bool ack_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
+bool status_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
+bool error_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
+bool termreq_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
+bool ping_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
+bool pong_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
+bool add_edge_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
+bool del_edge_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
+bool key_changed_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
+bool req_key_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
+bool ans_key_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
+bool tcppacket_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
#endif
/* Send all known subnets and edges */
for splay_each(node_t, n, mesh->nodes) {
- for splay_each(edge_t, e, n->edge_tree) {
+ for inner_splay_each(edge_t, e, n->edge_tree) {
send_add_edge(mesh, c, e, 0);
}
}
bool send_add_edge(meshlink_handle_t *mesh, connection_t *c, const edge_t *e, int contradictions) {
bool x;
char *address, *port;
- char *from_submesh, *to_submesh;
- submesh_t *s = NULL;
+ const char *from_submesh, *to_submesh;
+ const submesh_t *s = NULL;
if(c->node && c->node->submesh) {
if(!submesh_allows_node(e->from->submesh, c->node)) {
/* Append the known UDP address of the from node, if we have a confirmed one */
if(!*address && from->status.udp_confirmed && from->address.sa.sa_family != AF_UNSPEC) {
- char *address, *port;
+ char *reflexive_address, *reflexive_port;
logger(mesh, MESHLINK_DEBUG, "Appending reflexive UDP address to ANS_KEY from %s to %s", from->name, to->name);
- sockaddr2str(&from->address, &address, &port);
- send_request(mesh, to->nexthop->connection, NULL, "%s %s %s", request, address, port);
- free(address);
- free(port);
+ sockaddr2str(&from->address, &reflexive_address, &reflexive_port);
+ send_request(mesh, to->nexthop->connection, NULL, "%s %s %s", request, reflexive_address, reflexive_port);
+ free(reflexive_address);
+ free(reflexive_port);
return true;
}
#include "net.h"
#include "node.h"
-extern void route(struct meshlink_handle *mesh, struct node_t *, struct vpn_packet_t *);
+void route(struct meshlink_handle *mesh, struct node_t *, struct vpn_packet_t *);
#endif
/* (De)constructors */
-extern splay_tree_t *splay_alloc_tree(splay_compare_t, splay_action_t) __attribute__((__malloc__));
-extern void splay_delete_tree(splay_tree_t *);
+splay_tree_t *splay_alloc_tree(splay_compare_t, splay_action_t) __attribute__((__malloc__));
+void splay_delete_tree(splay_tree_t *);
-extern splay_node_t *splay_alloc_node(void) __attribute__((__malloc__));
-extern void splay_free_node(splay_tree_t *tree, splay_node_t *);
+splay_node_t *splay_alloc_node(void) __attribute__((__malloc__));
+void splay_free_node(splay_tree_t *tree, splay_node_t *);
/* Insertion and deletion */
-extern splay_node_t *splay_insert(splay_tree_t *, void *);
-extern splay_node_t *splay_insert_node(splay_tree_t *, splay_node_t *);
+splay_node_t *splay_insert(splay_tree_t *, void *);
+splay_node_t *splay_insert_node(splay_tree_t *, splay_node_t *);
-extern splay_node_t *splay_unlink(splay_tree_t *, void *);
-extern void splay_unlink_node(splay_tree_t *tree, splay_node_t *);
-extern void splay_delete(splay_tree_t *, void *);
-extern void splay_delete_node(splay_tree_t *, splay_node_t *);
+splay_node_t *splay_unlink(splay_tree_t *, void *);
+void splay_unlink_node(splay_tree_t *tree, splay_node_t *);
+void splay_delete(splay_tree_t *, void *);
+void splay_delete_node(splay_tree_t *, splay_node_t *);
/* Searching */
-extern void *splay_search(splay_tree_t *, const void *);
-extern void *splay_search_closest(splay_tree_t *, const void *, int *);
-extern void *splay_search_closest_smaller(splay_tree_t *, const void *);
-extern void *splay_search_closest_greater(splay_tree_t *, const void *);
+void *splay_search(splay_tree_t *, const void *);
+void *splay_search_closest(splay_tree_t *, const void *, int *);
+void *splay_search_closest_smaller(splay_tree_t *, const void *);
+void *splay_search_closest_greater(splay_tree_t *, const void *);
-extern splay_node_t *splay_search_node(splay_tree_t *, const void *);
-extern splay_node_t *splay_search_closest_node(splay_tree_t *, const void *, int *);
-extern splay_node_t *splay_search_closest_node_nosplay(const splay_tree_t *, const void *, int *);
-extern splay_node_t *splay_search_closest_smaller_node(splay_tree_t *, const void *);
-extern splay_node_t *splay_search_closest_greater_node(splay_tree_t *, const void *);
+splay_node_t *splay_search_node(splay_tree_t *, const void *);
+splay_node_t *splay_search_closest_node(splay_tree_t *, const void *, int *);
+splay_node_t *splay_search_closest_node_nosplay(const splay_tree_t *, const void *, int *);
+splay_node_t *splay_search_closest_smaller_node(splay_tree_t *, const void *);
+splay_node_t *splay_search_closest_greater_node(splay_tree_t *, const void *);
/* Tree walking */
-extern void splay_foreach(const splay_tree_t *, splay_action_t);
-extern void splay_foreach_node(const splay_tree_t *, splay_action_t);
+void splay_foreach(const splay_tree_t *, splay_action_t);
+void splay_foreach_node(const splay_tree_t *, splay_action_t);
-#define splay_each(type, item, tree) (type *item = (type *)1; item; item = NULL) for(splay_node_t *node = (tree)->head, *next; item = node ? node->data : NULL, next = node ? node->next : NULL, node; node = next)
+#define splay_each(type, item, tree) (type *item = (type *)1; item; item = NULL) for(splay_node_t *splay_node = (tree)->head, *splay_next; item = splay_node ? splay_node->data : NULL, splay_next = splay_node ? splay_node->next : NULL, splay_node; splay_node = splay_next)
+#define inner_splay_each(type, item, tree) (type *item = (type *)1; item; item = NULL) for(splay_node_t *inner_splay_node = (tree)->head, *inner_splay_next; item = inner_splay_node ? inner_splay_node->data : NULL, inner_splay_next = inner_splay_node ? inner_splay_node->next : NULL, inner_splay_node; inner_splay_node = inner_splay_next)
#endif
} sptps_t;
-extern void sptps_log_quiet(sptps_t *s, int s_errno, const char *format, va_list ap);
-extern void sptps_log_stderr(sptps_t *s, int s_errno, const char *format, va_list ap);
+void sptps_log_quiet(sptps_t *s, int s_errno, const char *format, va_list ap);
+void sptps_log_stderr(sptps_t *s, int s_errno, const char *format, va_list ap);
extern void (*sptps_log)(sptps_t *s, int s_errno, const char *format, va_list ap);
-extern bool sptps_start(sptps_t *s, void *handle, bool initiator, bool datagram, ecdsa_t *mykey, ecdsa_t *hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record) __attribute__((__warn_unused_result__));
-extern bool sptps_stop(sptps_t *s);
-extern bool sptps_send_record(sptps_t *s, uint8_t type, const void *data, uint16_t len);
-extern bool sptps_receive_data(sptps_t *s, const void *data, size_t len) __attribute__((__warn_unused_result__));
-extern bool sptps_force_kex(sptps_t *s) __attribute__((__warn_unused_result__));
-extern bool sptps_verify_datagram(sptps_t *s, const void *data, size_t len) __attribute__((__warn_unused_result__));
+bool sptps_start(sptps_t *s, void *handle, bool initiator, bool datagram, ecdsa_t *mykey, ecdsa_t *hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record) __attribute__((__warn_unused_result__));
+bool sptps_stop(sptps_t *s);
+bool sptps_send_record(sptps_t *s, uint8_t type, const void *data, uint16_t len);
+bool sptps_receive_data(sptps_t *s, const void *data, size_t len) __attribute__((__warn_unused_result__));
+bool sptps_force_kex(sptps_t *s) __attribute__((__warn_unused_result__));
+bool sptps_verify_datagram(sptps_t *s, const void *data, size_t len) __attribute__((__warn_unused_result__));
#endif
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 *create_submesh(struct meshlink_handle *mesh, const char *) __attribute__((__warn_unused_result__));
-extern submesh_t *lookup_submesh(struct meshlink_handle *mesh, const char *) __attribute__((__warn_unused_result__));
-extern submesh_t *lookup_or_create_submesh(struct meshlink_handle *mesh, const char *) __attribute__((__warn_unused_result__));
-extern bool submesh_allows_node(const submesh_t *submesh, const struct node_t *node) __attribute__((__warn_unused_result__));
+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
#define debug(...) do {} while(0)
#endif
-static ssize_t do_recv(struct utcp_connection *c, const void *data, size_t len) {
- (void)c;
+static ssize_t do_recv(struct utcp_connection *rc, const void *data, size_t len) {
+ (void)rc;
if(!data || !len) {
if(errno) {
}
}
-void utcp_set_retransmit_cb(struct utcp *utcp, utcp_retransmit_t retransmit) {
- utcp->retransmit = retransmit;
+void utcp_set_retransmit_cb(struct utcp *utcp, utcp_retransmit_t cb) {
+ utcp->retransmit = cb;
}
void utcp_set_clock_granularity(long granularity) {
typedef void (*utcp_poll_t)(struct utcp_connection *connection, size_t len);
-extern struct utcp *utcp_init(utcp_accept_t accept, utcp_pre_accept_t pre_accept, utcp_send_t send, void *priv);
-extern void utcp_exit(struct utcp *utcp);
-
-extern struct utcp_connection *utcp_connect_ex(struct utcp *utcp, uint16_t port, utcp_recv_t recv, void *priv, uint32_t flags);
-extern struct utcp_connection *utcp_connect(struct utcp *utcp, uint16_t port, utcp_recv_t recv, void *priv);
-extern void utcp_accept(struct utcp_connection *utcp, utcp_recv_t recv, void *priv);
-extern ssize_t utcp_send(struct utcp_connection *connection, const void *data, size_t len);
-extern ssize_t utcp_recv(struct utcp *utcp, const void *data, size_t len);
-extern int utcp_close(struct utcp_connection *connection);
-extern int utcp_abort(struct utcp_connection *connection);
-extern int utcp_shutdown(struct utcp_connection *connection, int how);
-extern struct timespec utcp_timeout(struct utcp *utcp);
-extern void utcp_set_recv_cb(struct utcp_connection *connection, utcp_recv_t recv);
-extern void utcp_set_poll_cb(struct utcp_connection *connection, utcp_poll_t poll);
-extern void utcp_set_accept_cb(struct utcp *utcp, utcp_accept_t accept, utcp_pre_accept_t pre_accept);
-extern bool utcp_is_active(struct utcp *utcp);
-extern void utcp_abort_all_connections(struct utcp *utcp);
+struct utcp *utcp_init(utcp_accept_t accept, utcp_pre_accept_t pre_accept, utcp_send_t send, void *priv);
+void utcp_exit(struct utcp *utcp);
+
+struct utcp_connection *utcp_connect_ex(struct utcp *utcp, uint16_t port, utcp_recv_t recv, void *priv, uint32_t flags);
+struct utcp_connection *utcp_connect(struct utcp *utcp, uint16_t port, utcp_recv_t recv, void *priv);
+void utcp_accept(struct utcp_connection *utcp, utcp_recv_t recv, void *priv);
+ssize_t utcp_send(struct utcp_connection *connection, const void *data, size_t len);
+ssize_t utcp_recv(struct utcp *utcp, const void *data, size_t len);
+int utcp_close(struct utcp_connection *connection);
+int utcp_abort(struct utcp_connection *connection);
+int utcp_shutdown(struct utcp_connection *connection, int how);
+struct timespec utcp_timeout(struct utcp *utcp);
+void utcp_set_recv_cb(struct utcp_connection *connection, utcp_recv_t recv);
+void utcp_set_poll_cb(struct utcp_connection *connection, utcp_poll_t poll);
+void utcp_set_accept_cb(struct utcp *utcp, utcp_accept_t accept, utcp_pre_accept_t pre_accept);
+bool utcp_is_active(struct utcp *utcp);
+void utcp_abort_all_connections(struct utcp *utcp);
// Global socket options
-extern int utcp_get_user_timeout(struct utcp *utcp);
-extern void utcp_set_user_timeout(struct utcp *utcp, int seconds);
+int utcp_get_user_timeout(struct utcp *utcp);
+void utcp_set_user_timeout(struct utcp *utcp, int seconds);
-extern uint16_t utcp_get_mtu(struct utcp *utcp);
-extern uint16_t utcp_get_mss(struct utcp *utcp);
-extern void utcp_set_mtu(struct utcp *utcp, uint16_t mtu);
+uint16_t utcp_get_mtu(struct utcp *utcp);
+uint16_t utcp_get_mss(struct utcp *utcp);
+void utcp_set_mtu(struct utcp *utcp, uint16_t mtu);
-extern void utcp_reset_timers(struct utcp *utcp);
+void utcp_reset_timers(struct utcp *utcp);
-extern void utcp_offline(struct utcp *utcp, bool offline);
-extern void utcp_set_retransmit_cb(struct utcp *utcp, utcp_retransmit_t retransmit);
+void utcp_offline(struct utcp *utcp, bool offline);
+void utcp_set_retransmit_cb(struct utcp *utcp, utcp_retransmit_t retransmit);
// Per-socket options
-extern size_t utcp_get_sndbuf(struct utcp_connection *connection);
-extern void utcp_set_sndbuf(struct utcp_connection *connection, size_t size);
-extern size_t utcp_get_sndbuf_free(struct utcp_connection *connection);
+size_t utcp_get_sndbuf(struct utcp_connection *connection);
+void utcp_set_sndbuf(struct utcp_connection *connection, size_t size);
+size_t utcp_get_sndbuf_free(struct utcp_connection *connection);
-extern size_t utcp_get_rcvbuf(struct utcp_connection *connection);
-extern void utcp_set_rcvbuf(struct utcp_connection *connection, size_t size);
-extern size_t utcp_get_rcvbuf_free(struct utcp_connection *connection);
+size_t utcp_get_rcvbuf(struct utcp_connection *connection);
+void utcp_set_rcvbuf(struct utcp_connection *connection, size_t size);
+size_t utcp_get_rcvbuf_free(struct utcp_connection *connection);
-extern size_t utcp_get_sendq(struct utcp_connection *connection);
-extern size_t utcp_get_recvq(struct utcp_connection *connection);
+size_t utcp_get_sendq(struct utcp_connection *connection);
+size_t utcp_get_recvq(struct utcp_connection *connection);
-extern bool utcp_get_nodelay(struct utcp_connection *connection);
-extern void utcp_set_nodelay(struct utcp_connection *connection, bool nodelay);
+bool utcp_get_nodelay(struct utcp_connection *connection);
+void utcp_set_nodelay(struct utcp_connection *connection, bool nodelay);
-extern bool utcp_get_keepalive(struct utcp_connection *connection);
-extern void utcp_set_keepalive(struct utcp_connection *connection, bool keepalive);
+bool utcp_get_keepalive(struct utcp_connection *connection);
+void utcp_set_keepalive(struct utcp_connection *connection, bool keepalive);
-extern size_t utcp_get_outq(struct utcp_connection *connection);
+size_t utcp_get_outq(struct utcp_connection *connection);
-extern void utcp_expect_data(struct utcp_connection *connection, bool expect);
+void utcp_expect_data(struct utcp_connection *connection, bool expect);
// Completely global options
-extern void utcp_set_clock_granularity(long granularity);
+void utcp_set_clock_granularity(long granularity);
#endif
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-extern int hex2bin(const char *src, void *dst, int length);
-extern int bin2hex(const void *src, char *dst, int length);
+int hex2bin(const char *src, void *dst, int length);
+int bin2hex(const void *src, char *dst, int length);
-extern int b64encode(const void *src, char *dst, int length);
-extern int b64encode_urlsafe(const void *src, char *dst, int length);
-extern int b64decode(const char *src, void *dst, int length);
+int b64encode(const void *src, char *dst, int length);
+int b64encode_urlsafe(const void *src, char *dst, int length);
+int b64decode(const char *src, void *dst, int length);
#ifdef HAVE_MINGW
-extern const char *winerror(int);
+const char *winerror(int);
#define strerror(x) ((x)>0?strerror(x):winerror(GetLastError()))
#define sockerrno WSAGetLastError()
#define sockstrerror(x) winerror(x)
#define sockinuse(x) ((x) == EADDRINUSE)
#endif
-extern unsigned int bitfield_to_int(const void *bitfield, size_t size) __attribute__((__warn_unused_result__));
+unsigned int bitfield_to_int(const void *bitfield, size_t size) __attribute__((__warn_unused_result__));
#endif
#ifndef MESHLINK_XOSHIRO_H
#define MESHLINK_XOSHIRO_H
-extern uint64_t xoshiro(uint64_t s[4]) __attribute__((__warn_unused_result__));
+uint64_t xoshiro(uint64_t s[4]) __attribute__((__warn_unused_result__));
#endif
#include "meshlink.h"
#include "utils.h"
-int main() {
+int main(void) {
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Check that the first time we need to supply a name
}
}
-int main() {
+int main(void) {
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Create three instances.
set_sync_flag(channel->priv, true);
}
-int main() {
+int main(void) {
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
meshlink_handle_t *a, *b;
set_sync_flag(&receive_flag, true);
}
-int main() {
+int main(void) {
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Open two meshlink instances.
assert(0);
}
-int main() {
+int main(void) {
int fda[2], fdb[2];
assert(pipe2(fda, 0) != -1);
return false;
}
-int main() {
+int main(void) {
meshlink_set_log_cb(NULL, MESHLINK_WARNING, log_cb);
// Open four new meshlink instance, the server and three peers.
assert(meshlink_channel_send(mesh, channel, "Hello", 5) == 5);
}
-int main() {
+int main(void) {
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Open two new meshlink instance.
assert(meshlink_blacklist(mesh, node));
}
-int main() {
+int main(void) {
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Open meshlink instances
mesh[i] = meshlink_open(dirname, name[i], "duplicate", DEV_CLASS_BACKBONE);
assert(mesh[i]);
- assert(meshlink_add_address(mesh[i], "localhost"));
+ assert(meshlink_set_canonical_address(mesh[i], meshlink_get_self(mesh[i]), "localhost", NULL));
meshlink_enable_discovery(mesh[i], false);
meshlink_set_node_duplicate_cb(mesh[i], handle_duplicate);
}
-int main() {
+int main(void) {
meshlink_set_log_cb(NULL, MESHLINK_WARNING, log_cb);
// Initialize and exchange configuration.
#include "meshlink.h"
#include "utils.h"
-int main() {
+int main(void) {
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Open a new meshlink instance.
#include "meshlink.h"
#include "utils.h"
-int main() {
+int main(void) {
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Open two ephemeral meshlink instance.
#include "meshlink.h"
#include "utils.h"
-struct sync_flag bar_reachable;
+static struct sync_flag bar_reachable;
-void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
+static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
(void)mesh;
if(reachable && !strcmp(node->name, "bar")) {
}
}
-int main() {
+int main(void) {
struct meshlink_node **nodes = NULL;
size_t nnodes = 0;
#include "meshlink.h"
#include "utils.h"
-struct sync_flag bar_reachable;
+static struct sync_flag bar_reachable;
-void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
+static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
(void)mesh;
if(reachable && !strcmp(node->name, "bar")) {
}
}
-int main() {
+int main(void) {
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Open two new meshlink instance.
}
}
-int main() {
+int main(void) {
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
assert(meshlink_destroy("invite_join_conf.1"));
#include "meshlink.h"
#include "utils.h"
-int main() {
+int main(void) {
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Open two new meshlink instance.
}
}
-int main() {
+int main(void) {
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Create three instances.
}
}
-int main() {
+int main(void) {
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Create three instances.