From 8d4b96efb7955eaa96174af4804597f92e124041 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Wed, 13 May 2020 22:48:02 +0200 Subject: [PATCH] Fix more compiler warnings. This enables much more compiler warnings by default, and fixes all the warnings we get from GCC 10 and Clang 10 in the library. The blackbox test cases still produce a lot of warnings that have not been fixed yet. --- configure.ac | 1 + examples/groupchat.c | 93 ++++++++++---------- examples/manynodes.c | 67 +++++++------- examples/meshlinkapp.c | 9 +- src/adns.c | 2 +- src/adns.h | 8 +- src/buffer.h | 12 +-- src/conf.h | 56 ++++++------ src/connection.h | 12 +-- src/crypto.h | 8 +- src/devtools.h | 18 ++-- src/discovery.h | 4 +- src/dropin.h | 4 +- src/ecdh.h | 6 +- src/ecdsa.h | 26 +++--- src/ecdsagen.h | 6 +- src/edge.h | 18 ++-- src/event.c | 13 +-- src/event.h | 40 ++++----- src/graph.c | 4 +- src/graph.h | 2 +- src/hash.h | 14 +-- src/list.h | 28 +++--- src/logger.h | 2 +- src/meshlink.c | 50 +++++------ src/meshlink.h | 168 ++++++++++++++++++------------------ src/meshlink_internal.h | 12 +-- src/meta.c | 2 +- src/meta.h | 12 +-- src/net.h | 62 ++++++------- src/net_packet.c | 15 ++-- src/net_setup.c | 2 +- src/netutl.h | 26 +++--- src/node.h | 20 ++--- src/prf.c | 2 +- src/prf.h | 2 +- src/protocol.c | 8 +- src/protocol.h | 54 ++++++------ src/protocol_auth.c | 2 +- src/protocol_edge.c | 4 +- src/protocol_key.c | 10 +-- src/route.h | 2 +- src/splay_tree.h | 45 +++++----- src/sptps.h | 16 ++-- src/submesh.h | 12 +-- src/utcp-test.c | 4 +- src/utcp.c | 4 +- src/utcp.h | 80 ++++++++--------- src/utils.h | 14 +-- src/xoshiro.h | 2 +- test/basic.c | 2 +- test/blacklist.c | 2 +- test/channels-cornercases.c | 2 +- test/channels-failure.c | 2 +- test/channels-fork.c | 2 +- test/channels-udp.c | 2 +- test/channels.c | 2 +- test/duplicate.c | 4 +- test/echo-fork.c | 2 +- test/encrypted.c | 2 +- test/ephemeral.c | 2 +- test/get-all-nodes.c | 6 +- test/import-export.c | 6 +- test/invite-join.c | 2 +- test/sign-verify.c | 2 +- test/trio.c | 2 +- test/trio2.c | 2 +- 67 files changed, 566 insertions(+), 561 deletions(-) diff --git a/configure.ac b/configure.ac index 37e7b82f..c5e629d6 100644 --- a/configure.ac +++ b/configure.ac @@ -75,6 +75,7 @@ AS_IF([test "x$enable_hardening" != "xno"], 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"]) ] ); diff --git a/examples/groupchat.c b/examples/groupchat.c index 75e259db..18e6f619 100644 --- a/examples/groupchat.c +++ b/examples/groupchat.c @@ -80,16 +80,9 @@ static void node_status(meshlink_handle_t *mesh, meshlink_node_t *node, bool rea } } -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; @@ -103,38 +96,38 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { } 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)); @@ -191,7 +184,9 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { 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); @@ -256,25 +251,29 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { 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); @@ -296,45 +295,47 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { 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); diff --git a/examples/manynodes.c b/examples/manynodes.c index d9fb0a41..923b5542 100644 --- a/examples/manynodes.c +++ b/examples/manynodes.c @@ -23,8 +23,8 @@ #include 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; @@ -42,11 +42,10 @@ static void log_message(meshlink_handle_t *mesh, meshlink_log_level_t level, con } //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)); @@ -55,7 +54,7 @@ static void testmesh() { 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)); } } @@ -65,15 +64,15 @@ static void testmesh() { } } // 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); @@ -106,7 +105,7 @@ static bool exportmeshgraph(const char *path) { 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; @@ -117,7 +116,7 @@ static bool exportmeshgraph(const char *path) { } -void exportmeshgraph_timer(int signum) { +static void exportmeshgraph_timer(int signum) { (void)signum; struct timeval ts; @@ -211,7 +210,7 @@ static void parse_command(char *buf) { 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)); @@ -226,15 +225,15 @@ static void parse_command(char *buf) { 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); } @@ -244,14 +243,14 @@ static void parse_command(char *buf) { 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; } @@ -263,14 +262,14 @@ static void parse_command(char *buf) { 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; } @@ -278,7 +277,7 @@ static void parse_command(char *buf) { 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)); @@ -292,12 +291,12 @@ static void parse_command(char *buf) { 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")) { @@ -319,7 +318,7 @@ static void parse_command(char *buf) { 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); @@ -389,7 +388,7 @@ static void parse_input(char *buf) { msg++; } - destination = meshlink_get_node(mesh[nodeindex], buf); + destination = meshlink_get_node(meshes[nodeindex], buf); if(!destination) { fprintf(stderr, "Unknown node '%s'\n", buf); @@ -402,7 +401,7 @@ static void parse_input(char *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; } @@ -436,7 +435,7 @@ int main(int argc, char *argv[]) { graphexporttimeout = argv[4]; } - mesh = calloc(n, sizeof(*mesh)); + meshes = calloc(n, sizeof(*meshes)); meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_message); #ifndef _WIN32 @@ -453,14 +452,14 @@ int main(int argc, char *argv[]) { 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; @@ -470,7 +469,7 @@ int main(int argc, char *argv[]) { 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++; @@ -498,7 +497,7 @@ int main(int argc, char *argv[]) { printf("Nodes stopping.\n"); for(int i = 0; i < n; i++) { - meshlink_close(mesh[i]); + meshlink_close(meshes[i]); } return 0; diff --git a/examples/meshlinkapp.c b/examples/meshlinkapp.c index 54e82a39..67f996a4 100644 --- a/examples/meshlinkapp.c +++ b/examples/meshlinkapp.c @@ -2,17 +2,16 @@ #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; diff --git a/src/adns.c b/src/adns.c index 8181140d..a0431014 100644 --- a/src/adns.c +++ b/src/adns.c @@ -141,7 +141,7 @@ struct adns_blocking_info { 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); diff --git a/src/adns.h b/src/adns.h index 8dc89fe1..7f9aa908 100644 --- a/src/adns.h +++ b/src/adns.h @@ -24,9 +24,9 @@ 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 diff --git a/src/buffer.h b/src/buffer.h index ba6647ed..26c0dc9e 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -27,11 +27,11 @@ typedef struct buffer_t { 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 diff --git a/src/conf.h b/src/conf.h index 2f79834a..32492ace 100644 --- a/src/conf.h +++ b/src/conf.h @@ -29,33 +29,33 @@ typedef struct config_t { 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 diff --git a/src/connection.h b/src/connection.h index 5160422b..b5ccaed9 100644 --- a/src/connection.h +++ b/src/connection.h @@ -80,11 +80,11 @@ typedef struct connection_t { 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 diff --git a/src/crypto.h b/src/crypto.h index 779f4522..9e8a19bc 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -3,7 +3,7 @@ /* crypto.h -- header for crypto.c - Copyright (C) 2014, 2017 Guus Sliepen + Copyright (C) 2014-2020 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,8 +20,8 @@ 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 diff --git a/src/devtools.h b/src/devtools.h index 2981d6d3..44965c37 100644 --- a/src/devtools.h +++ b/src/devtools.h @@ -71,7 +71,7 @@ struct devtool_edge { * 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. @@ -79,7 +79,7 @@ extern devtool_edge_t *devtool_get_all_edges(meshlink_handle_t *mesh, devtool_ed * * @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; @@ -116,7 +116,7 @@ struct devtool_node_status { * 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. @@ -130,7 +130,7 @@ extern void devtool_get_node_status(meshlink_handle_t *mesh, meshlink_node_t *no * 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. @@ -147,7 +147,7 @@ extern meshlink_submesh_t **devtool_get_all_submeshes(meshlink_handle_t *mesh, m * @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 @@ -177,6 +177,14 @@ extern void (*devtool_adns_resolve_probe)(void); */ 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 diff --git a/src/discovery.h b/src/discovery.h index bd034a80..48571695 100644 --- a/src/discovery.h +++ b/src/discovery.h @@ -22,7 +22,7 @@ #include -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 diff --git a/src/dropin.h b/src/dropin.h index f7a42975..603a28d9 100644 --- a/src/dropin.h +++ b/src/dropin.h @@ -21,8 +21,8 @@ */ #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 diff --git a/src/ecdh.h b/src/ecdh.h index eb66ec0d..ea4a841a 100644 --- a/src/ecdh.h +++ b/src/ecdh.h @@ -27,8 +27,8 @@ 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 diff --git a/src/ecdsa.h b/src/ecdsa.h index 6da3d2f4..64b329fe 100644 --- a/src/ecdsa.h +++ b/src/ecdsa.h @@ -24,18 +24,18 @@ 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 diff --git a/src/ecdsagen.h b/src/ecdsagen.h index 812a98b4..26390677 100644 --- a/src/ecdsagen.h +++ b/src/ecdsagen.h @@ -22,8 +22,8 @@ #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 diff --git a/src/edge.h b/src/edge.h index 3805e557..d5ec117d 100644 --- a/src/edge.h +++ b/src/edge.h @@ -37,14 +37,14 @@ typedef struct edge_t { 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 diff --git a/src/event.c b/src/event.c index 40dbd18e..39a7d18f 100644 --- a/src/event.c +++ b/src/event.c @@ -364,13 +364,6 @@ bool event_loop_run(event_loop_t *loop, pthread_mutex_t *mutex) { 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; } @@ -394,14 +387,14 @@ void event_loop_exit(event_loop_t *loop) { 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); } } diff --git a/src/event.h b/src/event.h index 31c326be..a87685da 100644 --- a/src/event.h +++ b/src/event.h @@ -78,25 +78,25 @@ struct event_loop_t { 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 diff --git a/src/graph.c b/src/graph.c index c6e413d4..754626ed 100644 --- a/src/graph.c +++ b/src/graph.c @@ -126,8 +126,8 @@ static void sssp_bfs(meshlink_handle_t *mesh) { 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); diff --git a/src/graph.h b/src/graph.h index 2375cc6c..17757327 100644 --- a/src/graph.h +++ b/src/graph.h @@ -20,6 +20,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -extern void graph(struct meshlink_handle *mesh); +void graph(struct meshlink_handle *mesh); #endif diff --git a/src/hash.h b/src/hash.h index de96f888..b28dc977 100644 --- a/src/hash.h +++ b/src/hash.h @@ -27,15 +27,15 @@ typedef struct hash_t { 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 diff --git a/src/list.h b/src/list.h index 60f9a437..bdce1567 100644 --- a/src/list.h +++ b/src/list.h @@ -44,35 +44,35 @@ typedef struct list_t { /* (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 diff --git a/src/logger.h b/src/logger.h index d6a28c59..b9269f04 100644 --- a/src/logger.h +++ b/src/logger.h @@ -22,6 +22,6 @@ #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 diff --git a/src/meshlink.c b/src/meshlink.c index 7c5bbd22..55b1e04f 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -167,7 +167,7 @@ static int socket_in_netns(int domain, int type, int protocol, int netns) { // 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, @@ -204,7 +204,7 @@ static bool getlocaladdr(char *destaddr, sockaddr_t *sa, socklen_t *salen, int n 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); @@ -386,7 +386,7 @@ char *meshlink_get_local_address_for_family(meshlink_handle_t *mesh, int family) 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; @@ -710,39 +710,39 @@ static bool finalize_join(join_state_t *state, const void *buf, uint16_t len) { // 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); @@ -888,7 +888,7 @@ static bool recvline(join_state_t *state) { 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; @@ -3136,14 +3136,14 @@ bool meshlink_import(meshlink_handle_t *mesh, const char *data) { 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); @@ -3169,7 +3169,7 @@ bool meshlink_import(meshlink_handle_t *mesh, const char *data) { 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); @@ -3406,7 +3406,7 @@ bool meshlink_forget_node(meshlink_handle_t *mesh, meshlink_node_t *node) { 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); } } } @@ -4281,7 +4281,7 @@ void handle_network_change(meshlink_handle_t *mesh, bool online) { 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; @@ -4292,7 +4292,7 @@ void call_error_cb(meshlink_handle_t *mesh, meshlink_errno_t meshlink_errno) { } if(mesh->thread == pthread_self()) { - mesh->error_cb(mesh, meshlink_errno); + mesh->error_cb(mesh, cb_errno); } } diff --git a/src/meshlink.h b/src/meshlink.h index 2763ad8d..f5044975 100644 --- a/src/meshlink.h +++ b/src/meshlink.h @@ -140,7 +140,7 @@ struct meshlink_channel { * 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(). @@ -159,14 +159,14 @@ extern const char *meshlink_strerror(meshlink_errno_t err) __attribute__((__warn * @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. @@ -176,7 +176,7 @@ extern void meshlink_open_params_free(meshlink_open_params_t *params); * * @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. @@ -187,7 +187,7 @@ extern bool meshlink_open_params_set_netns(meshlink_open_params_t *params, int n * * @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. @@ -207,7 +207,7 @@ extern bool meshlink_open_params_set_storage_key(meshlink_open_params_t *params, * @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. @@ -237,7 +237,7 @@ extern struct meshlink_handle *meshlink_open_ex(const meshlink_open_params_t *pa * @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. @@ -269,7 +269,7 @@ extern struct meshlink_handle *meshlink_open(const char *confbase, const char *n * @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. @@ -293,7 +293,7 @@ extern struct meshlink_handle *meshlink_open_encrypted(const char *confbase, con * @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 @@ -322,7 +322,7 @@ struct meshlink_submesh *meshlink_submesh_open(struct meshlink_handle *mesh, con * * @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, @@ -334,7 +334,7 @@ extern bool meshlink_start(struct meshlink_handle *mesh) __attribute__((__warn_u * \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, @@ -348,7 +348,7 @@ extern void meshlink_stop(struct meshlink_handle *mesh); * \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 @@ -360,7 +360,7 @@ extern void meshlink_close(struct meshlink_handle *mesh); * * @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. @@ -384,7 +384,7 @@ typedef void (*meshlink_receive_cb_t)(struct meshlink_handle *mesh, struct meshl * @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. @@ -405,7 +405,7 @@ typedef void (*meshlink_connection_try_cb_t)(struct meshlink_handle *mesh, struc * @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. @@ -427,7 +427,7 @@ typedef void (*meshlink_node_status_cb_t)(struct meshlink_handle *mesh, struct m * @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. @@ -449,7 +449,7 @@ typedef void (*meshlink_node_pmtu_cb_t)(struct meshlink_handle *mesh, struct mes * @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. @@ -470,7 +470,7 @@ typedef void (*meshlink_node_duplicate_cb_t)(struct meshlink_handle *mesh, struc * @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 { @@ -513,7 +513,7 @@ typedef void (*meshlink_log_cb_t)(struct meshlink_handle *mesh, meshlink_log_lev * @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. @@ -545,7 +545,7 @@ typedef void (*meshlink_error_cb_t)(struct meshlink_handle *mesh, meshlink_errno * @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. @@ -566,7 +566,7 @@ extern void meshlink_set_error_cb(struct meshlink_handle *mesh, meshlink_error_c * @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(). @@ -582,7 +582,7 @@ extern bool meshlink_send(struct meshlink_handle *mesh, struct meshlink_node *de * @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. @@ -593,7 +593,7 @@ extern ssize_t meshlink_get_pmtu(struct meshlink_handle *mesh, struct meshlink_n * @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. @@ -607,7 +607,7 @@ extern struct meshlink_node *meshlink_get_self(struct meshlink_handle *mesh) __a * 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. @@ -621,7 +621,7 @@ extern struct meshlink_node *meshlink_get_node(struct meshlink_handle *mesh, con * 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. @@ -634,7 +634,7 @@ extern struct meshlink_submesh *meshlink_get_submesh(struct meshlink_handle *mes * @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. @@ -654,7 +654,7 @@ extern char *meshlink_get_fingerprint(struct meshlink_handle *mesh, struct meshl * 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. @@ -671,7 +671,7 @@ extern struct meshlink_node **meshlink_get_all_nodes(struct meshlink_handle *mes * * @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. @@ -692,7 +692,7 @@ extern bool meshlink_sign(struct meshlink_handle *mesh, const void *data, size_t * 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. @@ -713,7 +713,7 @@ extern struct meshlink_node **meshlink_get_all_nodes_by_dev_class(struct meshlin * 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. @@ -737,7 +737,7 @@ extern struct meshlink_node **meshlink_get_all_nodes_by_submesh(struct meshlink_ * 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. @@ -748,7 +748,7 @@ extern struct meshlink_node **meshlink_get_all_nodes_by_last_reachable(struct me * * @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. @@ -759,7 +759,7 @@ extern dev_class_t meshlink_get_node_dev_class(struct meshlink_handle *mesh, str * * @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. @@ -775,7 +775,7 @@ extern struct meshlink_submesh *meshlink_get_node_submesh(struct meshlink_handle * * @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. @@ -791,7 +791,7 @@ extern bool meshlink_get_node_reachability(struct meshlink_handle *mesh, struct * * @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. @@ -811,7 +811,7 @@ extern bool meshlink_verify(struct meshlink_handle *mesh, struct meshlink_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. @@ -826,7 +826,7 @@ extern bool meshlink_set_canonical_address(struct meshlink_handle *mesh, struct * * @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(). @@ -834,7 +834,7 @@ extern bool meshlink_add_invitation_address(struct meshlink_handle *mesh, const * \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. @@ -846,7 +846,7 @@ extern void meshlink_clear_invitation_addresses(struct meshlink_handle *mesh); * * @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 @@ -870,7 +870,7 @@ extern bool meshlink_add_address(struct meshlink_handle *mesh, const char *addre * 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 @@ -896,7 +896,7 @@ extern char *meshlink_get_external_address(struct meshlink_handle *mesh) __attri * 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. @@ -919,7 +919,7 @@ extern char *meshlink_get_external_address_for_family(struct meshlink_handle *me * 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: @@ -933,7 +933,7 @@ extern char *meshlink_get_local_address_for_family(struct meshlink_handle *mesh, * * @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. @@ -943,7 +943,7 @@ extern bool meshlink_add_external_address(struct meshlink_handle *mesh) __attrib * * @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. @@ -964,7 +964,7 @@ extern int meshlink_get_port(struct meshlink_handle *mesh) __attribute__((__warn * 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. @@ -975,7 +975,7 @@ extern bool meshlink_set_port(struct meshlink_handle *mesh, int port) __attribut * @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. @@ -993,7 +993,7 @@ extern void meshlink_set_invitation_timeout(struct meshlink_handle *mesh, int ti * @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. @@ -1012,7 +1012,7 @@ extern char *meshlink_invite_ex(struct meshlink_handle *mesh, struct meshlink_su * @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. @@ -1032,7 +1032,7 @@ extern char *meshlink_invite(struct meshlink_handle *mesh, struct meshlink_subme * * @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. @@ -1048,7 +1048,7 @@ extern bool meshlink_join(struct meshlink_handle *mesh, const char *invitation) * @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. @@ -1064,7 +1064,7 @@ extern char *meshlink_export(struct meshlink_handle *mesh) __attribute__((__warn * * @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, @@ -1086,7 +1086,7 @@ extern bool meshlink_import(struct meshlink_handle *mesh, const char *data) __at * * @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. @@ -1099,7 +1099,7 @@ extern bool meshlink_forget_node(struct meshlink_handle *mesh, struct meshlink_n * * @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. @@ -1114,7 +1114,7 @@ extern bool meshlink_blacklist(struct meshlink_handle *mesh, struct meshlink_nod * * @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. @@ -1127,7 +1127,7 @@ extern bool meshlink_blacklist_by_name(struct meshlink_handle *mesh, const char * * @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. @@ -1143,7 +1143,7 @@ extern bool meshlink_whitelist(struct meshlink_handle *mesh, struct meshlink_nod * * @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. @@ -1156,7 +1156,7 @@ extern bool meshlink_whitelist_by_name(struct meshlink_handle *mesh, const char * @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. @@ -1224,7 +1224,7 @@ typedef void (*meshlink_channel_poll_cb_t)(struct meshlink_handle *mesh, struct * @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. @@ -1239,7 +1239,7 @@ extern void meshlink_set_channel_accept_cb(struct meshlink_handle *mesh, meshlin * @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. @@ -1254,7 +1254,7 @@ extern void meshlink_set_channel_receive_cb(struct meshlink_handle *mesh, struct * @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. @@ -1266,7 +1266,7 @@ extern void meshlink_set_channel_poll_cb(struct meshlink_handle *mesh, struct me * @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. @@ -1278,7 +1278,7 @@ extern void meshlink_set_channel_sndbuf(struct meshlink_handle *mesh, struct mes * @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. @@ -1303,7 +1303,7 @@ extern void meshlink_set_channel_rcvbuf(struct meshlink_handle *mesh, struct mes * @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. @@ -1330,7 +1330,7 @@ extern struct meshlink_channel *meshlink_channel_open_ex(struct meshlink_handle * @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. @@ -1344,7 +1344,7 @@ extern struct meshlink_channel *meshlink_channel_open(struct meshlink_handle *me * @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. @@ -1359,7 +1359,7 @@ extern void meshlink_channel_shutdown(struct meshlink_handle *mesh, struct meshl * @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. @@ -1375,7 +1375,7 @@ extern void meshlink_channel_close(struct meshlink_handle *mesh, struct meshlink * 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. @@ -1417,7 +1417,7 @@ typedef void (*meshlink_aio_fd_cb_t)(struct meshlink_handle *mesh, struct meshli * * @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. @@ -1434,7 +1434,7 @@ extern bool meshlink_channel_aio_send(struct meshlink_handle *mesh, struct meshl * * @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. @@ -1453,7 +1453,7 @@ extern bool meshlink_channel_aio_fd_send(struct meshlink_handle *mesh, struct me * * @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. @@ -1470,7 +1470,7 @@ extern bool meshlink_channel_aio_receive(struct meshlink_handle *mesh, struct me * * @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. @@ -1481,7 +1481,7 @@ extern bool meshlink_channel_aio_fd_receive(struct meshlink_handle *mesh, struct * * @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. @@ -1493,7 +1493,7 @@ extern uint32_t meshlink_channel_get_flags(struct meshlink_handle *mesh, struct * * @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. @@ -1505,7 +1505,7 @@ extern size_t meshlink_channel_get_sendq(struct meshlink_handle *mesh, struct me * * @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. @@ -1516,7 +1516,7 @@ extern size_t meshlink_channel_get_recvq(struct meshlink_handle *mesh, struct me * * @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. @@ -1528,7 +1528,7 @@ extern size_t meshlink_channel_get_mss(struct meshlink_handle *mesh, struct mesh * @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 @@ -1541,7 +1541,7 @@ extern void meshlink_set_node_channel_timeout(struct meshlink_handle *mesh, stru * 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 @@ -1551,7 +1551,7 @@ extern void meshlink_hint_address(struct meshlink_handle *mesh, struct meshlink_ * @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 @@ -1564,7 +1564,7 @@ extern void meshlink_enable_discovery(struct meshlink_handle *mesh, bool enable) * * @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. @@ -1576,7 +1576,7 @@ extern bool meshlink_encrypted_key_rotate(struct meshlink_handle *mesh, const vo * @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. @@ -1587,7 +1587,7 @@ extern void meshlink_set_dev_class_timeouts(struct meshlink_handle *mesh, dev_cl * @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. @@ -1598,7 +1598,7 @@ extern void meshlink_set_dev_class_fast_retry_period(struct meshlink_handle *mes * @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. @@ -1609,7 +1609,7 @@ extern void meshlink_set_inviter_commits_first(struct meshlink_handle *mesh, boo * @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. @@ -1621,7 +1621,7 @@ extern void meshlink_set_external_address_discovery_url(struct meshlink_handle * * @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 } diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index f9225ee5..d6dc87d0 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -238,14 +238,14 @@ typedef struct meshlink_packethdr { 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) { diff --git a/src/meta.c b/src/meta.c index f3ab47f1..fa880d2a 100644 --- a/src/meta.c +++ b/src/meta.c @@ -70,7 +70,7 @@ void broadcast_meta(meshlink_handle_t *mesh, connection_t *from, const char *buf } } -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); diff --git a/src/meta.h b/src/meta.h index 768c7acf..039fa348 100644 --- a/src/meta.h +++ b/src/meta.h @@ -22,12 +22,12 @@ #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 diff --git a/src/net.h b/src/net.h index 5ea2ae3e..a139c432 100644 --- a/src/net.h +++ b/src/net.h @@ -80,37 +80,37 @@ typedef struct outgoing_t { #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) diff --git a/src/net_packet.c b/src/net_packet.c index 56012e0e..3ee0eaec 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -317,14 +317,17 @@ static void choose_udp_address(meshlink_handle_t *mesh, const node_t *n, const 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; + } } } diff --git a/src/net_setup.c b/src/net_setup.c index ceaeb0c5..af49ea09 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -521,7 +521,7 @@ static bool add_listen_sockets(meshlink_handle_t *mesh) { /* 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; diff --git a/src/netutl.h b/src/netutl.h index 6c777bde..bce0aaee 100644 --- a/src/netutl.h +++ b/src/netutl.h @@ -23,18 +23,18 @@ #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 diff --git a/src/node.h b/src/node.h index 4c3f2afe..63f3c2c8 100644 --- a/src/node.h +++ b/src/node.h @@ -99,15 +99,15 @@ typedef struct node_t { 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 diff --git a/src/prf.c b/src/prf.c index 3e1b0b54..e6fdcb60 100644 --- a/src/prf.c +++ b/src/prf.c @@ -85,7 +85,7 @@ static bool hmac_sha512(const char *key, size_t keylen, const char *msg, size_t 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); diff --git a/src/prf.h b/src/prf.h index 1fc0ee19..1494eca8 100644 --- a/src/prf.h +++ b/src/prf.h @@ -20,6 +20,6 @@ 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 diff --git a/src/protocol.c b/src/protocol.c index c8c75cfc..e2842abe 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -42,7 +42,7 @@ static bool (*request_handlers[])(meshlink_handle_t *, connection_t *, const cha /* Request names */ -static char (*request_name[]) = { +static const char *request_name[] = { "ID", "METAKEY", "CHALLENGE", "CHAL_REPLY", "ACK", "STATUS", "ERROR", "TERMREQ", "PING", "PONG", @@ -66,7 +66,7 @@ bool check_id(const char *id) { /* Generic request routines - takes care of logging and error detection as well */ -bool send_request(meshlink_handle_t *mesh, connection_t *c, 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); @@ -106,7 +106,7 @@ bool send_request(meshlink_handle_t *mesh, connection_t *c, submesh_t *s, const } } -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); @@ -180,7 +180,7 @@ static void age_past_requests(event_loop_t *loop, void *data) { 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++; } diff --git a/src/protocol.h b/src/protocol.h index f97682a1..794b0515 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -70,39 +70,39 @@ typedef struct past_request_t { /* 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 diff --git a/src/protocol_auth.c b/src/protocol_auth.c index c17d9e82..201cac9f 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -298,7 +298,7 @@ static void send_everything(meshlink_handle_t *mesh, connection_t *c) { /* 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); } } diff --git a/src/protocol_edge.c b/src/protocol_edge.c index c42a10d2..38dd56f8 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -37,8 +37,8 @@ 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)) { diff --git a/src/protocol_key.c b/src/protocol_key.c index b614494b..2c741be5 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -334,12 +334,12 @@ bool ans_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { /* 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; } diff --git a/src/route.h b/src/route.h index 284fc69a..92e9fe03 100644 --- a/src/route.h +++ b/src/route.h @@ -23,6 +23,6 @@ #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 diff --git a/src/splay_tree.h b/src/splay_tree.h index ca53dc37..de19ab7d 100644 --- a/src/splay_tree.h +++ b/src/splay_tree.h @@ -63,40 +63,41 @@ typedef struct splay_tree_t { /* (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 diff --git a/src/sptps.h b/src/sptps.h index c91d3882..ba6bcd57 100644 --- a/src/sptps.h +++ b/src/sptps.h @@ -87,14 +87,14 @@ typedef struct sptps { } 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 diff --git a/src/submesh.h b/src/submesh.h index 15720aab..9366b057 100644 --- a/src/submesh.h +++ b/src/submesh.h @@ -31,11 +31,11 @@ typedef struct submesh_t { 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 diff --git a/src/utcp-test.c b/src/utcp-test.c index 2a273de7..992e6f0f 100644 --- a/src/utcp-test.c +++ b/src/utcp-test.c @@ -58,8 +58,8 @@ static void debug(const char *format, ...) { #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) { diff --git a/src/utcp.c b/src/utcp.c index 47acf221..5ba5553b 100644 --- a/src/utcp.c +++ b/src/utcp.c @@ -2455,8 +2455,8 @@ void utcp_offline(struct utcp *utcp, bool offline) { } } -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) { diff --git a/src/utcp.h b/src/utcp.h index ff509ac9..c051ff1f 100644 --- a/src/utcp.h +++ b/src/utcp.h @@ -63,63 +63,63 @@ typedef ssize_t (*utcp_recv_t)(struct utcp_connection *connection, const void *d 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 diff --git a/src/utils.h b/src/utils.h index 6c01e6ae..dfbb2055 100644 --- a/src/utils.h +++ b/src/utils.h @@ -20,15 +20,15 @@ 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) @@ -45,6 +45,6 @@ extern const char *winerror(int); #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 diff --git a/src/xoshiro.h b/src/xoshiro.h index 03d5620a..c771c7b9 100644 --- a/src/xoshiro.h +++ b/src/xoshiro.h @@ -1,6 +1,6 @@ #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 diff --git a/test/basic.c b/test/basic.c index bc93de09..004e7186 100644 --- a/test/basic.c +++ b/test/basic.c @@ -13,7 +13,7 @@ #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 diff --git a/test/blacklist.c b/test/blacklist.c index 11a330eb..8b081963 100644 --- a/test/blacklist.c +++ b/test/blacklist.c @@ -44,7 +44,7 @@ static void baz_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool r } } -int main() { +int main(void) { meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); // Create three instances. diff --git a/test/channels-cornercases.c b/test/channels-cornercases.c index d4644a42..3b605bb5 100644 --- a/test/channels-cornercases.c +++ b/test/channels-cornercases.c @@ -79,7 +79,7 @@ static void poll_cb2(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_ 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; diff --git a/test/channels-failure.c b/test/channels-failure.c index 8e17341d..e9b4c7ba 100644 --- a/test/channels-failure.c +++ b/test/channels-failure.c @@ -43,7 +43,7 @@ static void receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, con set_sync_flag(&receive_flag, true); } -int main() { +int main(void) { meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); // Open two meshlink instances. diff --git a/test/channels-fork.c b/test/channels-fork.c index f331d0d2..30f7cf8e 100644 --- a/test/channels-fork.c +++ b/test/channels-fork.c @@ -186,7 +186,7 @@ static void alarm_handler(int sig) { assert(0); } -int main() { +int main(void) { int fda[2], fdb[2]; assert(pipe2(fda, 0) != -1); diff --git a/test/channels-udp.c b/test/channels-udp.c index 8071d467..4e628c01 100644 --- a/test/channels-udp.c +++ b/test/channels-udp.c @@ -100,7 +100,7 @@ static bool accept_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint 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. diff --git a/test/channels.c b/test/channels.c index 5424ae66..3dbbaa7b 100644 --- a/test/channels.c +++ b/test/channels.c @@ -75,7 +75,7 @@ static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t 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. diff --git a/test/duplicate.c b/test/duplicate.c index db2ce72a..ed3e7568 100644 --- a/test/duplicate.c +++ b/test/duplicate.c @@ -18,7 +18,7 @@ static void handle_duplicate(meshlink_handle_t *mesh, meshlink_node_t *node) { assert(meshlink_blacklist(mesh, node)); } -int main() { +int main(void) { meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); // Open meshlink instances @@ -34,7 +34,7 @@ int main() { 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); diff --git a/test/echo-fork.c b/test/echo-fork.c index 94000c68..0096c9e0 100644 --- a/test/echo-fork.c +++ b/test/echo-fork.c @@ -174,7 +174,7 @@ static int main2(void) { } -int main() { +int main(void) { meshlink_set_log_cb(NULL, MESHLINK_WARNING, log_cb); // Initialize and exchange configuration. diff --git a/test/encrypted.c b/test/encrypted.c index c7d5bc4b..ac0dfa92 100644 --- a/test/encrypted.c +++ b/test/encrypted.c @@ -13,7 +13,7 @@ #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. diff --git a/test/ephemeral.c b/test/ephemeral.c index 07bb745a..07db7ebd 100644 --- a/test/ephemeral.c +++ b/test/ephemeral.c @@ -10,7 +10,7 @@ #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. diff --git a/test/get-all-nodes.c b/test/get-all-nodes.c index 65a0a8a4..3340982b 100644 --- a/test/get-all-nodes.c +++ b/test/get-all-nodes.c @@ -13,9 +13,9 @@ #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")) { @@ -23,7 +23,7 @@ void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { } } -int main() { +int main(void) { struct meshlink_node **nodes = NULL; size_t nnodes = 0; diff --git a/test/import-export.c b/test/import-export.c index 5d37146f..599e4c14 100644 --- a/test/import-export.c +++ b/test/import-export.c @@ -12,9 +12,9 @@ #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")) { @@ -22,7 +22,7 @@ void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { } } -int main() { +int main(void) { meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); // Open two new meshlink instance. diff --git a/test/invite-join.c b/test/invite-join.c index 21041d8b..85fb4931 100644 --- a/test/invite-join.c +++ b/test/invite-join.c @@ -22,7 +22,7 @@ static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reach } } -int main() { +int main(void) { meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); assert(meshlink_destroy("invite_join_conf.1")); diff --git a/test/sign-verify.c b/test/sign-verify.c index 66f4ecc3..a9ac1157 100644 --- a/test/sign-verify.c +++ b/test/sign-verify.c @@ -11,7 +11,7 @@ #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. diff --git a/test/trio.c b/test/trio.c index 4362f6da..478dd28e 100644 --- a/test/trio.c +++ b/test/trio.c @@ -47,7 +47,7 @@ static void baz_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool r } } -int main() { +int main(void) { meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); // Create three instances. diff --git a/test/trio2.c b/test/trio2.c index d57af960..328c6a95 100644 --- a/test/trio2.c +++ b/test/trio2.c @@ -47,7 +47,7 @@ static void baz_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool r } } -int main() { +int main(void) { meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); // Create three instances. -- 2.39.5