From fe5563f92021618b4a8b41e412c73d8364fcaf6e Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 9 Nov 2019 17:57:55 +0100 Subject: [PATCH] Fix __warn_unused_result__, add more of it and fix the resulting warnings. Due to a bug in the autoconf test for function attributes, we were always disabling __warn_unused_result__. Fix this, and add this function attribute to a lot more functions whose results are definitely important. This change makes it clear where we ignore the results of a function that might fail. The proper fix in most cases is to propagate the result to the caller. For meshlink_blacklist() and meshlink_whitelist(), we were not return an error condition, even if we might fail to commit the blacklist operation to permanent storage. So we now make these functions return a bool. --- examples/channels.c | 10 +- examples/chat.c | 10 +- examples/groupchat.c | 10 +- examples/manynodes.c | 17 ++- examples/meshlinkapp.c | 15 ++- m4/attribute.m4 | 4 +- src/conf.c | 5 +- src/conf.h | 36 +++--- src/edge.h | 2 +- src/event.h | 2 +- src/fake-getaddrinfo.h | 4 +- src/fake-getnameinfo.h | 2 +- src/meshlink++.h | 17 ++- src/meshlink.c | 69 ++++++++---- src/meshlink.h | 104 +++++++++--------- src/meshlink_queue.h | 4 +- src/meta.h | 2 +- src/net.c | 16 +-- src/net.h | 26 ++--- src/net_packet.c | 4 +- src/net_setup.c | 6 +- src/net_socket.c | 6 +- src/netutl.h | 6 +- src/node.h | 4 +- src/packmsg.h | 4 +- src/protocol.h | 1 - src/protocol_auth.c | 4 +- src/protocol_key.c | 30 ++--- src/sptps.h | 8 +- src/submesh.h | 8 +- src/utils.h | 2 +- src/xoshiro.h | 2 +- .../run_blackbox_tests/test_cases_add_addr.c | 8 +- .../test_cases_add_ex_addr.c | 4 +- .../test_cases_autoconnect.c | 10 +- .../run_blackbox_tests/test_cases_blacklist.c | 22 ++-- .../test_cases_channel_blacklist.c | 12 +- .../test_cases_channel_close.c | 12 +- .../test_cases_channel_ex.c | 12 +- .../test_cases_channel_get_flags.c | 6 +- .../test_cases_channel_open.c | 24 ++-- .../test_cases_channel_send.c | 20 ++-- .../test_cases_channel_set_accept_cb.c | 8 +- .../test_cases_channel_set_poll_cb.c | 12 +- .../test_cases_channel_set_receive_cb.c | 12 +- .../test_cases_channel_shutdown.c | 16 +-- .../test_cases_default_blacklist.c | 12 +- .../run_blackbox_tests/test_cases_export.c | 4 +- .../test_cases_get_all_nodes.c | 10 +- .../test_cases_get_all_nodes_by_dev_class.c | 22 ++-- .../test_cases_get_ex_addr.c | 4 +- .../test_cases_get_fingerprint.c | 6 +- .../run_blackbox_tests/test_cases_get_node.c | 12 +- .../run_blackbox_tests/test_cases_get_port.c | 2 +- .../run_blackbox_tests/test_cases_get_self.c | 2 +- .../test_cases_hint_address.c | 8 +- .../run_blackbox_tests/test_cases_import.c | 40 +++---- .../run_blackbox_tests/test_cases_invite.c | 16 +-- .../run_blackbox_tests/test_cases_join.c | 18 +-- .../test_cases_key_rotation.c | 32 +++--- .../run_blackbox_tests/test_cases_open.c | 8 +- .../run_blackbox_tests/test_cases_pmtu.c | 6 +- .../test_cases_random_port_bindings01.c | 12 +- .../test_cases_random_port_bindings02.c | 26 ++--- .../run_blackbox_tests/test_cases_rec_cb.c | 4 +- .../run_blackbox_tests/test_cases_send.c | 6 +- .../test_cases_set_connection_try_cb.c | 12 +- .../test_cases_set_log_cb.c | 4 +- .../run_blackbox_tests/test_cases_set_port.c | 4 +- .../run_blackbox_tests/test_cases_sign.c | 12 +- .../run_blackbox_tests/test_cases_start.c | 6 +- .../run_blackbox_tests/test_cases_status_cb.c | 16 +-- .../run_blackbox_tests/test_cases_verify.c | 20 ++-- .../run_blackbox_tests/test_cases_whitelist.c | 30 ++--- .../run_blackbox_tests/test_optimal_pmtu.c | 12 +- .../node_sim_nut_01.c | 4 +- .../node_sim_relay_01.c | 2 +- .../test_case_channel_conn_04/node_sim_nut.c | 2 +- .../node_sim_relay.c | 2 +- .../node_sim_relay.c | 2 +- .../node_sim_relay.c | 2 +- .../test_case_channel_conn_08/node_sim_nut.c | 2 +- .../node_sim_relay.c | 2 +- .../test_case_meta_conn_01/node_sim_nut.c | 2 +- .../test_case_meta_conn_01/node_sim_peer.c | 2 +- .../test_case_meta_conn_01/node_sim_relay.c | 2 +- .../test_case_meta_conn_02/node_sim_nut.c | 2 +- .../test_case_meta_conn_02/node_sim_peer.c | 2 +- .../test_case_meta_conn_02/node_sim_relay.c | 2 +- .../test_case_meta_conn_03/node_sim_nut.c | 2 +- .../test_case_meta_conn_03/node_sim_peer.c | 2 +- .../test_case_meta_conn_03/node_sim_relay.c | 2 +- .../test_case_meta_conn_04/node_sim_nut.c | 2 +- .../test_case_meta_conn_04/node_sim_peer.c | 2 +- .../test_case_meta_conn_04/node_sim_relay.c | 2 +- .../test_case_meta_conn_05/node_sim_nut.c | 2 +- .../test_case_meta_conn_05/node_sim_peer.c | 2 +- .../test_case_meta_conn_05/node_sim_relay.c | 2 +- .../test_case_optimal_pmtu_01/node_sim_nut.c | 2 +- .../node_sim_relay.c | 2 +- .../test_cases_submesh04/node_sim_app1node2.c | 8 +- test/channels-cornercases.c | 5 +- test/channels-fork.c | 6 +- test/channels-no-partial.c | 2 +- test/channels.c | 2 +- test/duplicate.c | 4 +- test/import-export.c | 4 +- test/invite-join.c | 2 +- test/trio.c | 2 +- test/trio2.c | 2 +- test/utils.c | 4 +- 111 files changed, 577 insertions(+), 500 deletions(-) diff --git a/examples/channels.c b/examples/channels.c index 70c27004..0f23de89 100644 --- a/examples/channels.c +++ b/examples/channels.c @@ -136,7 +136,10 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { return; } - meshlink_blacklist(mesh, node); + if(!meshlink_blacklist(mesh, node)) { + fprintf(stderr, "Error blacklising '%s': %s", arg, meshlink_strerror(meshlink_errno)); + return; + } printf("Node '%s' blacklisted.\n", arg); } else if(!strcasecmp(buf, "whitelist")) { @@ -152,7 +155,10 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { return; } - meshlink_whitelist(mesh, node); + if(!meshlink_whitelist(mesh, node)) { + fprintf(stderr, "Error whitelising '%s': %s", arg, meshlink_strerror(meshlink_errno)); + return; + } printf("Node '%s' whitelisted.\n", arg); } else if(!strcasecmp(buf, "who")) { diff --git a/examples/chat.c b/examples/chat.c index 77ba59e6..88fe127a 100644 --- a/examples/chat.c +++ b/examples/chat.c @@ -99,7 +99,10 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { return; } - meshlink_blacklist(mesh, node); + if(!meshlink_blacklist(mesh, node)) { + fprintf(stderr, "Error blacklising '%s': %s", arg, meshlink_strerror(meshlink_errno)); + return; + } printf("Node '%s' blacklisted.\n", arg); } else if(!strcasecmp(buf, "whitelist")) { @@ -115,7 +118,10 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { return; } - meshlink_whitelist(mesh, node); + if(!meshlink_whitelist(mesh, node)) { + fprintf(stderr, "Error whitelising '%s': %s", arg, meshlink_strerror(meshlink_errno)); + return; + } printf("Node '%s' whitelisted.\n", arg); } else if(!strcasecmp(buf, "who")) { diff --git a/examples/groupchat.c b/examples/groupchat.c index 7a5a300f..c049dd8a 100644 --- a/examples/groupchat.c +++ b/examples/groupchat.c @@ -227,7 +227,10 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { return; } - meshlink_blacklist(mesh, node); + if(!meshlink_blacklist(mesh, node)) { + fprintf(stderr, "Error blacklising '%s': %s", arg, meshlink_strerror(meshlink_errno)); + return; + } fprintf(stderr, "Node '%s' blacklisted.\n", arg); } else if(!strcasecmp(buf, "whitelist")) { @@ -243,7 +246,10 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { return; } - meshlink_whitelist(mesh, node); + if(!meshlink_whitelist(mesh, node)) { + fprintf(stderr, "Error whitelising '%s': %s", arg, meshlink_strerror(meshlink_errno)); + return; + } fprintf(stderr, "Node '%s' whitelisted.\n", arg); } else if(!strcasecmp(buf, "who")) { diff --git a/examples/manynodes.c b/examples/manynodes.c index fbfd215f..d9fb0a41 100644 --- a/examples/manynodes.c +++ b/examples/manynodes.c @@ -71,8 +71,11 @@ static void linkmesh() { for(int j = i + 1; j < n; j++) { char *dataj = meshlink_export(mesh[j]); - meshlink_import(mesh[i], dataj); - meshlink_import(mesh[j], datai); + + 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)); + } + free(dataj); } @@ -248,7 +251,10 @@ static void parse_command(char *buf) { return; } - meshlink_blacklist(mesh[nodeindex], node); + if(!meshlink_blacklist(mesh[nodeindex], node)) { + fprintf(stderr, "Error blacklising '%s': %s", arg, meshlink_strerror(meshlink_errno)); + return; + } printf("Node '%s' blacklisted.\n", arg); } else if(!strcasecmp(buf, "whitelist")) { @@ -264,7 +270,10 @@ static void parse_command(char *buf) { return; } - meshlink_whitelist(mesh[nodeindex], node); + if(!meshlink_whitelist(mesh[nodeindex], node)) { + fprintf(stderr, "Error whitelising '%s': %s", arg, meshlink_strerror(meshlink_errno)); + return; + } printf("Node '%s' whitelisted.\n", arg); } else if(!strcasecmp(buf, "who")) { diff --git a/examples/meshlinkapp.c b/examples/meshlinkapp.c index 2c12ea11..54e82a39 100644 --- a/examples/meshlinkapp.c +++ b/examples/meshlinkapp.c @@ -18,10 +18,18 @@ int main(int argc, char **argv) { myhandle = meshlink_open(confbase, name, "meshlinkapp", DEV_CLASS_STATIONARY); + if(!myhandle) { + fprintf(stderr, "Could not open MeshLink: %s", meshlink_strerror(meshlink_errno)); + return 1; + } + //Register callback function for incoming data meshlink_set_receive_cb(myhandle, (meshlink_receive_cb_t)handle_recv_data); - meshlink_start(myhandle); + if(!meshlink_start(myhandle)) { + fprintf(stderr, "Could not start MeshLink: %s", meshlink_strerror(meshlink_errno)); + return 1; + } while(1) { sleep(10); @@ -39,7 +47,10 @@ int main(int argc, char **argv) { strcpy(mydata, "Hello World!"); //send out data - meshlink_send(myhandle, remotenode, mydata, sizeof(mydata)); + if(!meshlink_send(myhandle, remotenode, mydata, sizeof(mydata))) { + fprintf(stderr, "Error sending data: %s", meshlink_strerror(meshlink_errno)); + return 1; + } } meshlink_stop(myhandle); diff --git a/m4/attribute.m4 b/m4/attribute.m4 index 11142d8e..06784859 100644 --- a/m4/attribute.m4 +++ b/m4/attribute.m4 @@ -9,8 +9,8 @@ AC_DEFUN([MeshLink_ATTRIBUTE], CFLAGS="$CFLAGS -Wall -Werror" AC_COMPILE_IFELSE( [AC_LANG_SOURCE( - [void test(void) __attribute__ (($1)); - void test(void) { return; } + [void *test(void *arg) __attribute__ (($1)); + void *test(void *arg) { return arg; } ], )], [MeshLink_cv_attribute_$1=yes], diff --git a/src/conf.c b/src/conf.c index 7f92048c..9a138712 100644 --- a/src/conf.c +++ b/src/conf.c @@ -444,8 +444,9 @@ bool meshlink_confbase_exists(meshlink_handle_t *mesh) { // Cleanup if current is existing with old and new if(confbase_exists && confbase_decryptable) { - config_destroy(mesh->confbase, "old"); - config_destroy(mesh->confbase, "new"); + if(!config_destroy(mesh->confbase, "old") || !config_destroy(mesh->confbase, "new")) { + return false; + } } return confbase_exists; diff --git a/src/conf.h b/src/conf.h index 49598ee5..f3d1e358 100644 --- a/src/conf.h +++ b/src/conf.h @@ -29,32 +29,32 @@ 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); -extern bool config_write_file(struct meshlink_handle *mesh, FILE *f, const struct config_t *, const void *key); +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); +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); -extern bool config_destroy(const char *confbase, const char *conf_subdir); -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); -extern bool config_rename(struct meshlink_handle *mesh, const char *old_conf_subdir, const char *new_conf_subdir); -extern bool config_sync(struct meshlink_handle *mesh, const char *conf_subdir); +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); -extern bool main_config_lock(struct meshlink_handle *mesh); +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); -extern bool main_config_write(struct meshlink_handle *mesh, const char *conf_subdir, const struct config_t *, void *key); +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); -extern bool config_read(struct meshlink_handle *mesh, const char *conf_subdir, const char *name, struct config_t *, void *key); -extern bool config_write(struct meshlink_handle *mesh, const char *conf_subdir, const char *name, const struct config_t *, void *key); -extern bool config_scan_all(struct meshlink_handle *mesh, const char *conf_subdir, const char *conf_type, config_scan_action_t action, void *arg); +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_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); -extern bool invitation_write(struct meshlink_handle *mesh, const char *conf_subdir, const char *name, const struct config_t *, void *key); +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); #endif diff --git a/src/edge.h b/src/edge.h index ba18e875..3805e557 100644 --- a/src/edge.h +++ b/src/edge.h @@ -45,6 +45,6 @@ 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 *); +extern edge_t *lookup_edge(struct node_t *, struct node_t *) __attribute__((__warn_unused_result__)); #endif diff --git a/src/event.h b/src/event.h index 245656a3..8a61e81b 100644 --- a/src/event.h +++ b/src/event.h @@ -93,7 +93,7 @@ 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); +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); diff --git a/src/fake-getaddrinfo.h b/src/fake-getaddrinfo.h index db3621b4..7fbd91b5 100644 --- a/src/fake-getaddrinfo.h +++ b/src/fake-getaddrinfo.h @@ -32,11 +32,11 @@ struct addrinfo { #endif /* !HAVE_STRUCT_ADDRINFO */ #if !HAVE_DECL_GETADDRINFO -int getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res); +int getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res) __attribute__((__warn_unused_result__)); #endif /* !HAVE_GETADDRINFO */ #if !HAVE_DECL_GAI_STRERROR -char *gai_strerror(int ecode); +char *gai_strerror(int ecode) __attribute__((__warn_unused_result__)); #endif /* !HAVE_GAI_STRERROR */ #if !HAVE_DECL_FREEADDRINFO diff --git a/src/fake-getnameinfo.h b/src/fake-getnameinfo.h index e6951642..fc1f1d40 100644 --- a/src/fake-getnameinfo.h +++ b/src/fake-getnameinfo.h @@ -2,7 +2,7 @@ #define MESHLINK_FAKE_GETNAMEINFO_H #if !HAVE_DECL_GETNAMEINFO -int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags); +int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) __attribute__((__warn_unused_result__)); #endif /* !HAVE_GETNAMEINFO */ #ifndef NI_MAXSERV diff --git a/src/meshlink++.h b/src/meshlink++.h index 64673f58..980e5b12 100644 --- a/src/meshlink++.h +++ b/src/meshlink++.h @@ -664,11 +664,26 @@ public: * and will not send data to it nor accept any data received from it any more. * * @param node A pointer to a meshlink::node describing the node to be blacklisted. + * + * @return This function returns true if the node has been whitelisted, false otherwise. */ - void blacklist(node *node) { + bool blacklist(node *node) { return meshlink_blacklist(handle, node); } + /// Whitelist a node on the mesh. + /** This function causes the local node to whitelist another node. + * The local node will allow connections to and from that node, + * and will send data to it and accept any data received from it. + * + * @param node A pointer to a meshlink::node describing the node to be whitelisted. + * + * @return This function returns true if the node has been whitelisted, false otherwise. + */ + bool whitelist(node *node) { + return meshlink_whitelist(handle, node); + } + /// Set the poll callback. /** This functions sets the callback that is called whenever data can be sent to another node. * The callback is run in MeshLink's own thread. diff --git a/src/meshlink.c b/src/meshlink.c index e6aea4dd..75458fe6 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1361,7 +1361,11 @@ meshlink_handle_t *meshlink_open_ex(const meshlink_open_params_t *params) { } add_local_addresses(mesh); - node_write_config(mesh, mesh->self); + + if(!node_write_config(mesh, mesh->self)) { + logger(NULL, MESHLINK_ERROR, "Cannot update configuration\n"); + return NULL; + } idle_set(&mesh->loop, idle, mesh); @@ -1550,12 +1554,11 @@ void meshlink_stop(meshlink_handle_t *mesh) { exit_outgoings(mesh); - // Write out any changed node config files + // Try to write out any changed node config files, ignore errors at this point. if(mesh->nodes) { for splay_each(node_t, n, mesh->nodes) { if(n->status.dirty) { - node_write_config(mesh, n); - n->status.dirty = false; + n->status.dirty = !node_write_config(mesh, n); } } } @@ -2169,11 +2172,15 @@ bool meshlink_set_canonical_address(meshlink_handle_t *mesh, meshlink_node_t *no node_t *n = (node_t *)node; free(n->canonical_address); n->canonical_address = canonical_address; - node_write_config(mesh, n); + + if(!node_write_config(mesh, n)) { + pthread_mutex_unlock(&mesh->mutex); + return false; + } pthread_mutex_unlock(&mesh->mutex); - return true; + return config_sync(mesh, "current"); } bool meshlink_add_address(meshlink_handle_t *mesh, const char *address) { @@ -2805,7 +2812,11 @@ bool meshlink_import(meshlink_handle_t *mesh, const char *data) { break; } - config_write(mesh, "current", n->name, &config, mesh->config_key); + if(!config_write(mesh, "current", n->name, &config, mesh->config_key)) { + free_node(n); + return false; + } + node_add(mesh, n); } @@ -2826,10 +2837,10 @@ bool meshlink_import(meshlink_handle_t *mesh, const char *data) { return true; } -void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) { +bool meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) { if(!mesh || !node) { meshlink_errno = MESHLINK_EINVAL; - return; + return false; } pthread_mutex_lock(&mesh->mutex); @@ -2841,20 +2852,16 @@ void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) { logger(mesh, MESHLINK_ERROR, "%s blacklisting itself?\n", node->name); meshlink_errno = MESHLINK_EINVAL; pthread_mutex_unlock(&mesh->mutex); - return; + return false; } if(n->status.blacklisted) { logger(mesh, MESHLINK_DEBUG, "Node %s already blacklisted\n", node->name); pthread_mutex_unlock(&mesh->mutex); - return; + return true; } n->status.blacklisted = true; - node_write_config(mesh, n); - config_sync(mesh, "current"); - - logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n", node->name); /* Immediately shut down any connections we have with the blacklisted node. * We can't call terminate_connection(), because we might be called from a callback function. @@ -2873,13 +2880,22 @@ void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) { n->mtuprobes = 0; n->status.udp_confirmed = false; + if(!node_write_config(mesh, n)) { + pthread_mutex_unlock(&mesh->mutex); + return false; + } + + logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n", node->name); + pthread_mutex_unlock(&mesh->mutex); + + return config_sync(mesh, "current"); } -void meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node) { +bool meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node) { if(!mesh || !node) { meshlink_errno = MESHLINK_EINVAL; - return; + return false; } pthread_mutex_lock(&mesh->mutex); @@ -2890,27 +2906,31 @@ void meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node) { logger(mesh, MESHLINK_ERROR, "%s whitelisting itself?\n", node->name); meshlink_errno = MESHLINK_EINVAL; pthread_mutex_unlock(&mesh->mutex); - return; + return false; } if(!n->status.blacklisted) { logger(mesh, MESHLINK_DEBUG, "Node %s was already whitelisted\n", node->name); pthread_mutex_unlock(&mesh->mutex); - return; + return true; } n->status.blacklisted = false; - node_write_config(mesh, n); - config_sync(mesh, "current"); if(n->status.reachable) { update_node_status(mesh, n); } + if(!node_write_config(mesh, n)) { + pthread_mutex_unlock(&mesh->mutex); + return false; + } + logger(mesh, MESHLINK_DEBUG, "Whitelisted %s.\n", node->name); pthread_mutex_unlock(&mesh->mutex); - return; + + return config_sync(mesh, "current"); } void meshlink_set_default_blacklist(meshlink_handle_t *mesh, bool blacklist) { @@ -2931,7 +2951,10 @@ void meshlink_hint_address(meshlink_handle_t *mesh, meshlink_node_t *node, const node_t *n = (node_t *)node; memmove(n->recent + 1, n->recent, 4 * sizeof(*n->recent)); memcpy(n->recent, addr, SALEN(*addr)); - node_write_config(mesh, n); + + if(!node_write_config(mesh, n)) { + logger(mesh, MESHLINK_DEBUG, "Could not update %s\n", n->name); + } pthread_mutex_unlock(&mesh->mutex); // @TODO do we want to fire off a connection attempt right away? diff --git a/src/meshlink.h b/src/meshlink.h index 3d12af6b..dd08436d 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); +extern 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(). @@ -158,7 +158,7 @@ extern const char *meshlink_strerror(meshlink_errno_t err); * @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); +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__)); /// Free a meshlink_open_params_t struct. /** This function frees a meshlink_open_params_t struct and all resources associated with it. @@ -175,7 +175,7 @@ extern void meshlink_open_params_free(meshlink_open_params_t *params); * * @return This function will return true if the open parameters have been succesfully updated, false otherwise. */ -extern bool meshlink_open_params_set_netns(meshlink_open_params_t *params, int netns); +extern 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. @@ -186,7 +186,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 succesfully updated, false otherwise. */ -extern bool meshlink_open_params_set_storage_key(meshlink_open_params_t *params, const void *key, size_t keylen); +extern 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. @@ -206,7 +206,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); +extern 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. @@ -235,7 +235,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); +extern 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. @@ -266,7 +266,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); +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__)); /// Create an ephemeral MeshLink instance that does not store any state. /** This function creates a MeshLink instance. @@ -290,7 +290,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); +extern 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 @@ -306,7 +306,7 @@ extern struct meshlink_handle *meshlink_open_ephemeral(const char *name, const c * @return A pointer to a struct meshlink_submesh which represents this instance of SubMesh, or NULL in case of an error. * The pointer is valid until meshlink_close() is called. */ -struct meshlink_submesh *meshlink_submesh_open(struct meshlink_handle *mesh, const char *submesh); +struct meshlink_submesh *meshlink_submesh_open(struct meshlink_handle *mesh, const char *submesh) __attribute__((__warn_unused_result__)); /// Start MeshLink. /** This function causes MeshLink to open network sockets, make outgoing connections, and @@ -319,7 +319,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); +extern bool meshlink_start(struct meshlink_handle *mesh) __attribute__((__warn_unused_result__)); /// Stop MeshLink. /** This function causes MeshLink to disconnect from all other nodes, @@ -357,7 +357,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); +extern 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. @@ -563,7 +563,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); +extern 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(). @@ -579,7 +579,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); +extern 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. @@ -590,7 +590,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); +extern 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. @@ -604,7 +604,7 @@ extern struct meshlink_node *meshlink_get_self(struct meshlink_handle *mesh); * 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); +extern 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. @@ -618,7 +618,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); +extern 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. @@ -631,7 +631,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); +extern 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. @@ -651,7 +651,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); +extern 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. @@ -668,7 +668,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); +extern 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. @@ -689,7 +689,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); +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__)); /// 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. @@ -710,7 +710,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); +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__)); /// Get the node's device class. /** This function returns the device class of the given node. @@ -721,7 +721,7 @@ extern struct meshlink_node **meshlink_get_all_nodes_by_submesh(struct meshlink_ * * @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); +extern 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. @@ -732,7 +732,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); +extern struct meshlink_submesh *meshlink_get_node_submesh(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); /// 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. @@ -748,7 +748,7 @@ extern struct meshlink_submesh *meshlink_get_node_submesh(struct meshlink_handle * * @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); +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__)); /// Set the canonical Address for a node. /** This function sets the canonical Address for a node. @@ -768,7 +768,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); +extern 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 Address for the local node. /** This function adds an Address for the local node, which will be used for invitation URLs. @@ -779,7 +779,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_address(struct meshlink_handle *mesh, const char *address); +extern bool meshlink_add_address(struct meshlink_handle *mesh, const char *address) __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 @@ -803,7 +803,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); +extern 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 @@ -829,7 +829,7 @@ extern char *meshlink_get_external_address(struct meshlink_handle *mesh); * 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); +extern 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. @@ -852,7 +852,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); +extern 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: @@ -866,7 +866,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); +extern 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. @@ -876,7 +876,7 @@ extern bool meshlink_add_external_address(struct meshlink_handle *mesh); * * @return This function returns the port number, or -1 in case of an error. */ -extern int meshlink_get_port(struct meshlink_handle *mesh); +extern 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. @@ -897,7 +897,7 @@ extern int meshlink_get_port(struct meshlink_handle *mesh); * is no guarantee that MeshLink is listening on the old port. */ -extern bool meshlink_set_port(struct meshlink_handle *mesh, int port); +extern 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. @@ -926,7 +926,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); +extern 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. @@ -945,7 +945,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); +extern 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. @@ -965,7 +965,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); +extern 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. @@ -981,7 +981,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); +extern 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. @@ -997,7 +997,7 @@ extern char *meshlink_export(struct meshlink_handle *mesh); * * @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); +extern bool meshlink_import(struct meshlink_handle *mesh, const char *data) __attribute__((__warn_unused_result__)); /// Blacklist a node from the mesh. /** This function causes the local node to blacklist another node. @@ -1007,8 +1007,10 @@ extern bool meshlink_import(struct meshlink_handle *mesh, const char *data); * \memberof meshlink_node * @param mesh A handle which represents an instance of MeshLink. * @param node A pointer to a struct meshlink_node describing the node to be blacklisted. + * + * @return This function returns true if the node has been blacklisted, false otherwise. */ -extern void meshlink_blacklist(struct meshlink_handle *mesh, struct meshlink_node *node); +extern bool meshlink_blacklist(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); /// Whitelist a node on the mesh. /** This function causes the local node to whitelist a previously blacklisted node. @@ -1018,8 +1020,10 @@ extern void meshlink_blacklist(struct meshlink_handle *mesh, struct meshlink_nod * \memberof meshlink_node * @param mesh A handle which represents an instance of MeshLink. * @param node A pointer to a struct meshlink_node describing the node to be whitelisted. + * + * @return This function returns true if the node has been whitelisted, false otherwise. */ -extern void meshlink_whitelist(struct meshlink_handle *mesh, struct meshlink_node *node); +extern bool meshlink_whitelist(struct meshlink_handle *mesh, struct meshlink_node *node) __attribute__((__warn_unused_result__)); /// Set whether new nodes are blacklisted by default. /** This function sets the blacklist behaviour for newly discovered nodes. @@ -1179,7 +1183,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); +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__)); /// 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. @@ -1206,7 +1210,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); +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__)); /// Partially close a reliable stream channel. /** This shuts down the read or write side of a channel, or both, without closing the handle. @@ -1251,7 +1255,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); +extern 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. @@ -1293,7 +1297,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); +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__)); /// 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. @@ -1310,7 +1314,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); +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__)); /// Receive data on a channel asynchronously /** This registers a buffer that will be filled with incoming channel data. @@ -1329,7 +1333,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); +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__)); /// 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. @@ -1346,7 +1350,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); +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__)); /// Get channel flags. /** This returns the flags used when opening this channel. @@ -1357,7 +1361,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); +extern 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. @@ -1369,7 +1373,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); +extern 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. @@ -1381,7 +1385,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); +extern size_t meshlink_channel_get_recvq(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. @@ -1429,7 +1433,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); +extern 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. diff --git a/src/meshlink_queue.h b/src/meshlink_queue.h index 764f4162..d075f1c8 100644 --- a/src/meshlink_queue.h +++ b/src/meshlink_queue.h @@ -49,7 +49,7 @@ static inline void meshlink_queue_exit(meshlink_queue_t *queue) { pthread_mutex_destroy(&queue->mutex); } -static inline bool meshlink_queue_push(meshlink_queue_t *queue, void *data) { +static inline __attribute__((__warn_unused_result__)) bool meshlink_queue_push(meshlink_queue_t *queue, void *data) { meshlink_queue_item_t *item = malloc(sizeof(*item)); if(!item) { @@ -70,7 +70,7 @@ static inline bool meshlink_queue_push(meshlink_queue_t *queue, void *data) { return true; } -static inline void *meshlink_queue_pop(meshlink_queue_t *queue) { +static inline __attribute__((__warn_unused_result__)) void *meshlink_queue_pop(meshlink_queue_t *queue) { meshlink_queue_item_t *item; void *data; pthread_mutex_lock(&queue->mutex); diff --git a/src/meta.h b/src/meta.h index 88e601a3..768c7acf 100644 --- a/src/meta.h +++ b/src/meta.h @@ -28,6 +28,6 @@ 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, const char *buffer, int length); -extern bool receive_meta(struct meshlink_handle *mesh, struct connection_t *); +extern bool receive_meta(struct meshlink_handle *mesh, struct connection_t *) __attribute__((__warn_unused_result__)); #endif diff --git a/src/net.c b/src/net.c index 80490efa..b9f441a0 100644 --- a/src/net.c +++ b/src/net.c @@ -604,7 +604,10 @@ static void periodic_handler(event_loop_t *loop, void *data) { for splay_each(node_t, n, mesh->nodes) { if(n->status.dirty) { - node_write_config(mesh, n); + if(node_write_config(mesh, n)) { + logger(mesh, MESHLINK_DEBUG, "Could not update %s", n->name); + } + n->status.dirty = false; } } @@ -696,7 +699,7 @@ void retry(meshlink_handle_t *mesh) { /* this is where it all happens... */ -int main_loop(meshlink_handle_t *mesh) { +void main_loop(meshlink_handle_t *mesh) { timeout_add(&mesh->loop, &mesh->pingtimer, timeout_handler, &mesh->pingtimer, &(struct timeval) { default_timeout, prng(mesh, TIMER_FUDGE) }); @@ -710,17 +713,10 @@ int main_loop(meshlink_handle_t *mesh) { if(!event_loop_run(&mesh->loop, &mesh->mutex)) { logger(mesh, MESHLINK_ERROR, "Error while waiting for input: %s", strerror(errno)); - abort(); - signal_del(&mesh->loop, &mesh->datafromapp); - timeout_del(&mesh->loop, &mesh->periodictimer); - timeout_del(&mesh->loop, &mesh->pingtimer); - - return 1; + call_error_cb(mesh, MESHLINK_ENETWORK); } signal_del(&mesh->loop, &mesh->datafromapp); timeout_del(&mesh->loop, &mesh->periodictimer); timeout_del(&mesh->loop, &mesh->pingtimer); - - return 0; } diff --git a/src/net.h b/src/net.h index 4da61bd4..262696d8 100644 --- a/src/net.h +++ b/src/net.h @@ -82,26 +82,26 @@ 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 bool do_outgoing_connection(struct meshlink_handle *mesh, struct outgoing_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_listen_socket(const sockaddr_t *); -extern int setup_vpn_in_socket(struct meshlink_handle *mesh, const sockaddr_t *); +extern int setup_listen_socket(const sockaddr_t *) __attribute__((__warn_unused_result__)); +extern int setup_vpn_in_socket(struct meshlink_handle *mesh, const sockaddr_t *) __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); +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); +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); -extern bool setup_network(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 setup_outgoing_connection(struct meshlink_handle *mesh, struct outgoing_t *); extern void close_network_connections(struct meshlink_handle *mesh); -extern int main_loop(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 *); -extern bool node_read_from_config(struct meshlink_handle *mesh, struct node_t *, const config_t *config); -extern bool read_ecdsa_public_key(struct meshlink_handle *mesh, struct connection_t *); -extern bool read_ecdsa_private_key(struct meshlink_handle *mesh); -extern bool node_write_config(struct meshlink_handle *mesh, struct node_t *); +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); diff --git a/src/net_packet.c b/src/net_packet.c index a2709553..953887a5 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -256,7 +256,9 @@ static void receive_udppacket(meshlink_handle_t *mesh, node_t *n, vpn_packet_t * return; } - sptps_receive_data(&n->sptps, inpkt->data, inpkt->len); + if(!sptps_receive_data(&n->sptps, inpkt->data, inpkt->len)) { + logger(mesh, MESHLINK_ERROR, "Could not process SPTPS data from %s: %s", n->name, strerror(errno)); + } } static void send_sptps_packet(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *origpkt) { diff --git a/src/net_setup.c b/src/net_setup.c index aeceb1f8..559f0496 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -116,7 +116,6 @@ bool node_read_public_key(meshlink_handle_t *mesh, node_t *n) { n->recent[i + known_count] = packmsg_get_sockaddr(&in); } - config_free(&config); return true; } @@ -233,6 +232,7 @@ bool node_write_config(meshlink_handle_t *mesh, node_t *n) { } if(!packmsg_output_ok(&out)) { + meshlink_errno = MESHLINK_EINTERNAL; return false; } @@ -402,7 +402,9 @@ bool setup_myself(meshlink_handle_t *mesh) { graph(mesh); - config_scan_all(mesh, "current", "hosts", load_node, NULL); + if(!config_scan_all(mesh, "current", "hosts", load_node, NULL)) { + logger(mesh, MESHLINK_WARNING, "Could not scan all host config files"); + } /* Open sockets */ diff --git a/src/net_socket.c b/src/net_socket.c index 51e0cacc..31bc608f 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -493,7 +493,7 @@ static bool get_next_outgoing_address(meshlink_handle_t *mesh, outgoing_t *outgo return false; } -bool do_outgoing_connection(meshlink_handle_t *mesh, outgoing_t *outgoing) { +void do_outgoing_connection(meshlink_handle_t *mesh, outgoing_t *outgoing) { struct addrinfo *proxyai = NULL; int result; @@ -507,7 +507,7 @@ begin: retry_outgoing(mesh, outgoing); } - return false; + return; } connection_t *c = new_connection(); @@ -586,8 +586,6 @@ begin: connection_add(mesh, c); io_add(&mesh->loop, &c->io, handle_meta_io, c, c->socket, IO_READ | IO_WRITE); - - return true; } void setup_outgoing_connection(meshlink_handle_t *mesh, outgoing_t *outgoing) { diff --git a/src/netutl.h b/src/netutl.h index ebba1ac3..6c777bde 100644 --- a/src/netutl.h +++ b/src/netutl.h @@ -27,14 +27,14 @@ extern struct addrinfo *str2addrinfo(const char *, const char *, int) __attribut 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 *); -extern int sockaddrcmp_noport(const sockaddr_t *, const sockaddr_t *); +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); +extern 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 28464520..d307e5f2 100644 --- a/src/node.h +++ b/src/node.h @@ -100,8 +100,8 @@ 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); -extern node_t *lookup_node_udp(struct meshlink_handle *mesh, const sockaddr_t *sa); +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); #endif diff --git a/src/packmsg.h b/src/packmsg.h index 7adf2f91..a145722d 100644 --- a/src/packmsg.h +++ b/src/packmsg.h @@ -173,7 +173,7 @@ static inline size_t packmsg_output_size(const packmsg_output_t *buf, const uint * \return True if all read operations performed on the input buffer so far have completed successfully, * false if any error has occurred. */ -static inline bool packmsg_input_ok(const packmsg_input_t *buf) { +static inline __attribute__((__warn_unused_result__)) bool packmsg_input_ok(const packmsg_input_t *buf) { assert(buf); return packmsg_likely(buf->len >= 0); @@ -192,7 +192,7 @@ static inline bool packmsg_input_ok(const packmsg_input_t *buf) { * false if there is still data remaining in the input buffer, * or if any error has occurred. */ -static inline bool packmsg_done(const packmsg_input_t *buf) { +static inline __attribute__((__warn_unused_result__)) bool packmsg_done(const packmsg_input_t *buf) { assert(buf); return buf->len == 0; diff --git a/src/protocol.h b/src/protocol.h index 47aacd99..f97682a1 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -87,7 +87,6 @@ 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 void send_key_changed(struct meshlink_handle *mesh); extern bool send_req_key(struct meshlink_handle *mesh, struct node_t *); /* Request handlers */ diff --git a/src/protocol_auth.c b/src/protocol_auth.c index beeef54e..e80af7d9 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -343,9 +343,7 @@ bool id_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { return false; } - node_read_public_key(mesh, n); - - if(!ecdsa_active(n->ecdsa)) { + if(!node_read_public_key(mesh, n)) { logger(mesh, MESHLINK_ERROR, "No key known for peer %s", c->name); if(n->status.reachable && !n->status.waitingforkey) { diff --git a/src/protocol_key.c b/src/protocol_key.c index 641e2b96..8a1d6000 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -33,17 +33,6 @@ static const int req_key_timeout = 2; -void send_key_changed(meshlink_handle_t *mesh) { - send_request(mesh, mesh->everyone, NULL, "%d %x %s", KEY_CHANGED, prng(mesh, UINT_MAX), mesh->self->name); - - /* Force key exchange for connections using SPTPS */ - - for splay_each(node_t, n, mesh->nodes) - if(n->status.reachable && n->status.validkey) { - sptps_force_kex(&n->sptps); - } -} - bool key_changed_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { assert(request); assert(*request); @@ -188,8 +177,17 @@ static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char * from->status.validkey = false; from->status.waitingforkey = true; from->last_req_key = mesh->loop.now.tv_sec; - sptps_start(&from->sptps, from, false, true, mesh->private_key, from->ecdsa, label, sizeof(label) - 1, send_sptps_data, receive_sptps_record); - sptps_receive_data(&from->sptps, buf, len); + + if(!sptps_start(&from->sptps, from, false, true, mesh->private_key, from->ecdsa, label, sizeof(label) - 1, send_sptps_data, receive_sptps_record)) { + logger(mesh, MESHLINK_ERROR, "Could not start SPTPS session with %s: %s", from->name, strerror(errno)); + return true; + } + + if(!sptps_receive_data(&from->sptps, buf, len)) { + logger(mesh, MESHLINK_ERROR, "Could not process SPTPS data from %s: %s", from->name, strerror(errno)); + return true; + } + return true; } @@ -207,7 +205,11 @@ static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char * return true; } - sptps_receive_data(&from->sptps, buf, len); + if(!sptps_receive_data(&from->sptps, buf, len)) { + logger(mesh, MESHLINK_ERROR, "Could not process SPTPS data from %s: %s", from->name, strerror(errno)); + return true; + } + return true; } diff --git a/src/sptps.h b/src/sptps.h index 66ac564a..c91d3882 100644 --- a/src/sptps.h +++ b/src/sptps.h @@ -90,11 +90,11 @@ typedef struct sptps { 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); 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); +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); -extern bool sptps_force_kex(sptps_t *s); -extern bool sptps_verify_datagram(sptps_t *s, const void *data, size_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__)); #endif diff --git a/src/submesh.h b/src/submesh.h index d6122d8f..15720aab 100644 --- a/src/submesh.h +++ b/src/submesh.h @@ -33,9 +33,9 @@ typedef struct 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 *); -extern submesh_t *lookup_submesh(struct meshlink_handle *mesh, const char *); -extern submesh_t *lookup_or_create_submesh(struct meshlink_handle *mesh, const char *); -extern bool submesh_allows_node(const submesh_t *submesh, const struct node_t *node); +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__)); #endif diff --git a/src/utils.h b/src/utils.h index 371a327d..6c01e6ae 100644 --- a/src/utils.h +++ b/src/utils.h @@ -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); +extern 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 fcd5192c..03d5620a 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]); +extern uint64_t xoshiro(uint64_t s[4]) __attribute__((__warn_unused_result__)); #endif diff --git a/test/blackbox/run_blackbox_tests/test_cases_add_addr.c b/test/blackbox/run_blackbox_tests/test_cases_add_addr.c index 4d13928a..02453efd 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_add_addr.c +++ b/test/blackbox/run_blackbox_tests/test_cases_add_addr.c @@ -72,7 +72,7 @@ static void test_case_mesh_add_address_01(void **state) { */ static bool test_steps_mesh_add_address_01(void) { char *node = "foo"; - meshlink_destroy("add_conf.1"); + assert(meshlink_destroy("add_conf.1")); // Create node instance meshlink_handle_t *mesh = meshlink_open("add_conf.1", node, "chat", DEV_CLASS_STATIONARY); @@ -100,7 +100,7 @@ static bool test_steps_mesh_add_address_01(void) { // Clean up meshlink_close(mesh); - meshlink_destroy("add_conf.1"); + assert(meshlink_destroy("add_conf.1")); return true; } @@ -141,7 +141,7 @@ static void test_case_mesh_add_address_03(void **state) { meshlink_add_address API returns false by reporting error successfully. */ static bool test_steps_mesh_add_address_03(void) { - meshlink_destroy("add_conf.3"); + assert(meshlink_destroy("add_conf.3")); // Create node instance meshlink_handle_t *mesh = meshlink_open("add_conf.3", "foo", "chat", DEV_CLASS_STATIONARY); @@ -151,7 +151,7 @@ static bool test_steps_mesh_add_address_03(void) { assert_int_equal(result, false); meshlink_close(mesh); - meshlink_destroy("add_conf.3"); + assert(meshlink_destroy("add_conf.3")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_add_ex_addr.c b/test/blackbox/run_blackbox_tests/test_cases_add_ex_addr.c index c7869095..894d3d3f 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_add_ex_addr.c +++ b/test/blackbox/run_blackbox_tests/test_cases_add_ex_addr.c @@ -65,7 +65,7 @@ void test_case_mesh_add_ex_address_01(void **state) { meshlink_add_external_address API adds the new address given to it's confbase */ bool test_steps_mesh_add_ex_address_01(void) { - meshlink_destroy("addex_conf.1"); + assert(meshlink_destroy("addex_conf.1")); // Create node instance meshlink_handle_t *mesh = meshlink_open("addex_conf.1", "foo", "test", DEV_CLASS_STATIONARY); @@ -94,7 +94,7 @@ bool test_steps_mesh_add_ex_address_01(void) { assert_int_equal(found, true); meshlink_close(mesh); - meshlink_destroy("addex_conf.1"); + assert(meshlink_destroy("addex_conf.1")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_autoconnect.c b/test/blackbox/run_blackbox_tests/test_cases_autoconnect.c index d8b7e490..f9c27717 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_autoconnect.c +++ b/test/blackbox/run_blackbox_tests/test_cases_autoconnect.c @@ -101,8 +101,8 @@ bool test_steps_mesh_autoconnect(void) { char *invite = NULL; meshlink_node_t *node = NULL; - meshlink_destroy("m1n1"); - meshlink_destroy("m1n2"); + assert(meshlink_destroy("m1n1")); + assert(meshlink_destroy("m1n2")); // Open two new meshlink instance. mesh1 = meshlink_open("m1n1", "m1n1", "autoconnect", DEV_CLASS_BACKBONE); @@ -129,7 +129,7 @@ bool test_steps_mesh_autoconnect(void) { assert(wait_sync_flag(&test_autoconnect_m1n1_reachable, 30)); node = meshlink_get_node(mesh2, "m1n1"); - meshlink_blacklist(mesh2, node); + assert(meshlink_blacklist(mesh2, node)); set_sync_flag(&test_autoconnect_blacklisted, true); assert(wait_sync_flag(&test_autoconnect_successful, 60)); @@ -140,8 +140,8 @@ bool test_steps_mesh_autoconnect(void) { meshlink_close(mesh2); fprintf(stderr, "Meshlink node2 closed\n"); - meshlink_destroy("m1n1"); - meshlink_destroy("m1n2"); + assert(meshlink_destroy("m1n1")); + assert(meshlink_destroy("m1n2")); fprintf(stderr, "Meshlink nodes destroyed\n"); return true; diff --git a/test/blackbox/run_blackbox_tests/test_cases_blacklist.c b/test/blackbox/run_blackbox_tests/test_cases_blacklist.c index 19908930..8f9a118c 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_blacklist.c +++ b/test/blackbox/run_blackbox_tests/test_cases_blacklist.c @@ -99,8 +99,8 @@ static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reach but when enabled foo node should not receive data */ bool test_steps_mesh_blacklist_01(void) { - meshlink_destroy("blacklist_conf.1"); - meshlink_destroy("blacklist_conf.2"); + assert(meshlink_destroy("blacklist_conf.1")); + assert(meshlink_destroy("blacklist_conf.2")); // Open two new meshlink instance. meshlink_handle_t *mesh1 = meshlink_open("blacklist_conf.1", "foo", "blacklist", DEV_CLASS_BACKBONE); @@ -136,7 +136,7 @@ bool test_steps_mesh_blacklist_01(void) { sleep(1); assert(received); - meshlink_blacklist(mesh1, bar); + assert(meshlink_blacklist(mesh1, bar)); received = false; assert(meshlink_send(mesh2, foo, "test", 5)); @@ -146,8 +146,8 @@ bool test_steps_mesh_blacklist_01(void) { // Clean up. meshlink_close(mesh2); meshlink_close(mesh1); - meshlink_destroy("blacklist_conf.1"); - meshlink_destroy("blacklist_conf.2"); + assert(meshlink_destroy("blacklist_conf.1")); + assert(meshlink_destroy("blacklist_conf.2")); return true; } @@ -166,7 +166,7 @@ void test_case_mesh_blacklist_02(void **state) { meshlink_blacklist API handles the invalid parameter when called by giving proper error number. */ bool test_steps_mesh_blacklist_02(void) { - meshlink_destroy("blacklist_conf.3"); + assert(meshlink_destroy("blacklist_conf.3")); // Open two new meshlink instance. meshlink_handle_t *mesh = meshlink_open("blacklist_conf.3", "foo", "blacklist", DEV_CLASS_BACKBONE); @@ -176,12 +176,12 @@ bool test_steps_mesh_blacklist_02(void) { assert(node); // Passing NULL as mesh handle and node handle being some valid node handle - meshlink_blacklist(NULL, node); + assert(!meshlink_blacklist(NULL, node)); assert_int_equal(meshlink_errno, MESHLINK_EINVAL); // Clean up. meshlink_close(mesh); - meshlink_destroy("blacklist_conf.3"); + assert(meshlink_destroy("blacklist_conf.3")); return true; } @@ -200,19 +200,19 @@ void test_case_mesh_blacklist_03(void **state) { meshlink_blacklist API handles the invalid parameter when called by giving proper error number. */ bool test_steps_mesh_blacklist_03(void) { - meshlink_destroy("blacklist_conf.4"); + assert(meshlink_destroy("blacklist_conf.4")); // Open two new meshlink instance. meshlink_handle_t *mesh = meshlink_open("blacklist_conf.4", "foo", "blacklist", DEV_CLASS_BACKBONE); assert(mesh != NULL); // Passing NULL as node handle and mesh handle being some valid mesh handle value - meshlink_blacklist(mesh, NULL); + assert(!meshlink_blacklist(mesh, NULL)); assert_int_equal(meshlink_errno, MESHLINK_EINVAL); // Clean up. meshlink_close(mesh); - meshlink_destroy("blacklist_conf.4"); + assert(meshlink_destroy("blacklist_conf.4")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_blacklist.c b/test/blackbox/run_blackbox_tests/test_cases_channel_blacklist.c index 333f3a99..568a475b 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_blacklist.c +++ b/test/blackbox/run_blackbox_tests/test_cases_channel_blacklist.c @@ -66,9 +66,9 @@ static int setup_test(void **state) { netns_create_topology(test_channel_disconnection_state); fprintf(stderr, "\nCreated topology\n"); - meshlink_destroy("nut"); - meshlink_destroy("peer"); - meshlink_destroy("relay"); + assert(meshlink_destroy("nut")); + assert(meshlink_destroy("peer")); + assert(meshlink_destroy("relay")); channel_discon_case_ping = false; channel_discon_network_failure_01 = false; channel_discon_network_failure_02 = false; @@ -81,9 +81,9 @@ static int setup_test(void **state) { static int teardown_test(void **state) { (void)state; - meshlink_destroy("nut"); - meshlink_destroy("peer"); - meshlink_destroy("relay"); + assert(meshlink_destroy("nut")); + assert(meshlink_destroy("peer")); + assert(meshlink_destroy("relay")); netns_destroy_topology(test_channel_disconnection_state); return EXIT_SUCCESS; diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_close.c b/test/blackbox/run_blackbox_tests/test_cases_channel_close.c index 1f6e3a02..9f2c9c93 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_close.c +++ b/test/blackbox/run_blackbox_tests/test_cases_channel_close.c @@ -56,8 +56,8 @@ static void test_case_mesh_channel_close_01(void **state) { /* Test Steps for meshlink_channel_close Test Case # 1*/ static bool test_steps_mesh_channel_close_01(void) { - meshlink_destroy("chan_close_conf.3"); - meshlink_destroy("chan_close_conf.4"); + assert(meshlink_destroy("chan_close_conf.3")); + assert(meshlink_destroy("chan_close_conf.4")); // Open two new meshlink instance. meshlink_handle_t *mesh1 = meshlink_open("chan_close_conf.3", "foo", "channels", DEV_CLASS_BACKBONE); @@ -100,8 +100,8 @@ static bool test_steps_mesh_channel_close_01(void) { meshlink_close(mesh2); meshlink_close(mesh1); - meshlink_destroy("chan_close_conf.3"); - meshlink_destroy("chan_close_conf.4"); + assert(meshlink_destroy("chan_close_conf.3")); + assert(meshlink_destroy("chan_close_conf.4")); return true; } @@ -113,7 +113,7 @@ static void test_case_mesh_channel_close_02(void **state) { /* Test Steps for meshlink_channel_close Test Case # 2*/ static bool test_steps_mesh_channel_close_02(void) { - meshlink_destroy("chan_close_conf.5"); + assert(meshlink_destroy("chan_close_conf.5")); // Open two new meshlink instance. meshlink_handle_t *mesh = meshlink_open("chan_close_conf.5", "foo", "channels", DEV_CLASS_BACKBONE); @@ -129,7 +129,7 @@ static bool test_steps_mesh_channel_close_02(void) { // Clean up. meshlink_close(mesh); - meshlink_destroy("chan_close_conf.5"); + assert(meshlink_destroy("chan_close_conf.5")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_ex.c b/test/blackbox/run_blackbox_tests/test_cases_channel_ex.c index 9f539cff..74c3a3e6 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_ex.c +++ b/test/blackbox/run_blackbox_tests/test_cases_channel_ex.c @@ -164,7 +164,7 @@ static bool test_steps_channel_ex_01(void) { assert_int_equal(ret, true); meshlink_close(mesh_handle); - meshlink_destroy("channelexconf"); + assert(meshlink_destroy("channelexconf")); return true; } @@ -217,7 +217,7 @@ static bool test_steps_channel_ex_02(void) { assert_int_equal(ret, true); meshlink_close(mesh_handle); - meshlink_destroy("channelexconf"); + assert(meshlink_destroy("channelexconf")); return true; } @@ -269,7 +269,7 @@ static bool test_steps_channel_ex_03(void) { assert_int_equal(ret, true); meshlink_close(mesh_handle); - meshlink_destroy("channelexconf"); + assert(meshlink_destroy("channelexconf")); return true; } @@ -321,7 +321,7 @@ static bool test_steps_channel_ex_04(void) { assert_int_equal(ret, true); meshlink_close(mesh_handle); - meshlink_destroy("channelexconf"); + assert(meshlink_destroy("channelexconf")); return true; } @@ -361,7 +361,7 @@ static bool test_steps_channel_ex_05(void) { assert(channel == NULL); meshlink_close(mesh_handle); - meshlink_destroy("channelexconf"); + assert(meshlink_destroy("channelexconf")); return true; } @@ -399,7 +399,7 @@ static bool test_steps_channel_ex_06(void) { assert_int_equal(channel, NULL); meshlink_close(mesh_handle); - meshlink_destroy("channelexconf"); + assert(meshlink_destroy("channelexconf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_get_flags.c b/test/blackbox/run_blackbox_tests/test_cases_channel_get_flags.c index 9ae6dfdf..5bb26839 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_get_flags.c +++ b/test/blackbox/run_blackbox_tests/test_cases_channel_get_flags.c @@ -96,7 +96,7 @@ static bool test_steps_channel_get_flags_01(void) { assert_int_equal(flags, MESHLINK_CHANNEL_TCP); meshlink_close(mesh_handle); - meshlink_destroy("getflagsconf"); + assert(meshlink_destroy("getflagsconf")); return true; } @@ -145,7 +145,7 @@ static bool test_steps_channel_get_flags_02(void) { assert_int_equal(meshlink_errno, MESHLINK_EINVAL); meshlink_close(mesh_handle); - meshlink_destroy("getflagsconf"); + assert(meshlink_destroy("getflagsconf")); return true; } @@ -181,7 +181,7 @@ static bool test_steps_channel_get_flags_03(void) { assert_int_equal(meshlink_errno, MESHLINK_EINVAL); meshlink_close(mesh_handle); - meshlink_destroy("getflagsconf"); + assert(meshlink_destroy("getflagsconf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_open.c b/test/blackbox/run_blackbox_tests/test_cases_channel_open.c index 89c69ba9..9792aec5 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_open.c +++ b/test/blackbox/run_blackbox_tests/test_cases_channel_open.c @@ -78,8 +78,8 @@ static void test_case_mesh_channel_open_01(void **state) { meshlink_channel_open should open a channel by returning a channel handler */ static bool test_steps_mesh_channel_open_01(void) { - meshlink_destroy("channels_conf.1"); - meshlink_destroy("channels_conf.2"); + assert(meshlink_destroy("channels_conf.1")); + assert(meshlink_destroy("channels_conf.2")); // Open two new meshlink instance. meshlink_handle_t *mesh1 = meshlink_open("channels_conf.1", "foo", "channels", DEV_CLASS_BACKBONE); @@ -111,8 +111,8 @@ static bool test_steps_mesh_channel_open_01(void) { // Clean up. meshlink_close(mesh2); meshlink_close(mesh1); - meshlink_destroy("channels_conf.1"); - meshlink_destroy("channels_conf.2"); + assert(meshlink_destroy("channels_conf.1")); + assert(meshlink_destroy("channels_conf.2")); return true; } @@ -132,8 +132,8 @@ static void test_case_mesh_channel_open_02(void **state) { /* Test Steps for meshlink_channel_open Test Case # 2*/ static bool test_steps_mesh_channel_open_02(void) { - meshlink_destroy("channels_conf.3"); - meshlink_destroy("channels_conf.4"); + assert(meshlink_destroy("channels_conf.3")); + assert(meshlink_destroy("channels_conf.4")); // Open two new meshlink instance. meshlink_handle_t *mesh1 = meshlink_open("channels_conf.3", "foo", "channels", DEV_CLASS_BACKBONE); @@ -166,8 +166,8 @@ static bool test_steps_mesh_channel_open_02(void) { // Clean up. meshlink_close(mesh2); meshlink_close(mesh1); - meshlink_destroy("channels_conf.3"); - meshlink_destroy("channels_conf.4"); + assert(meshlink_destroy("channels_conf.3")); + assert(meshlink_destroy("channels_conf.4")); return true; } @@ -188,7 +188,7 @@ static void test_case_mesh_channel_open_03(void **state) { when called by giving proper error number. */ static bool test_steps_mesh_channel_open_03(void) { - meshlink_destroy("channels_conf.5"); + assert(meshlink_destroy("channels_conf.5")); // Open two new meshlink instance. meshlink_handle_t *mesh = meshlink_open("channels_conf.5", "foo", "channels", DEV_CLASS_BACKBONE); @@ -202,7 +202,7 @@ static bool test_steps_mesh_channel_open_03(void) { // Clean up. meshlink_close(mesh); - meshlink_destroy("channels_conf.5"); + assert(meshlink_destroy("channels_conf.5")); return true; } @@ -223,7 +223,7 @@ static void test_case_mesh_channel_open_04(void **state) { when called by giving proper error number. */ static bool test_steps_mesh_channel_open_04(void) { - meshlink_destroy("channels_conf.7"); + assert(meshlink_destroy("channels_conf.7")); // Open two new meshlink instance. meshlink_handle_t *mesh = meshlink_open("channels_conf.7", "foo", "channels", DEV_CLASS_BACKBONE); @@ -237,7 +237,7 @@ static bool test_steps_mesh_channel_open_04(void) { // Clean up. meshlink_close(mesh); - meshlink_destroy("channels_conf.7"); + assert(meshlink_destroy("channels_conf.7")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_send.c b/test/blackbox/run_blackbox_tests/test_cases_channel_send.c index f302e2b5..d818a0c7 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_send.c +++ b/test/blackbox/run_blackbox_tests/test_cases_channel_send.c @@ -142,8 +142,8 @@ static void poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t /* Test Steps for meshlink_channel_send Test Case # 1*/ static bool test_steps_mesh_channel_send_01(void) { struct timespec timeout = {0}; - meshlink_destroy("chan_send_conf.1"); - meshlink_destroy("chan_send_conf.2"); + assert(meshlink_destroy("chan_send_conf.1")); + assert(meshlink_destroy("chan_send_conf.2")); // Open two new meshlink instance. meshlink_handle_t *mesh1 = meshlink_open("chan_send_conf.1", "foo", "channels", DEV_CLASS_BACKBONE); @@ -216,8 +216,8 @@ static bool test_steps_mesh_channel_send_01(void) { meshlink_close(mesh2); meshlink_close(mesh1); - meshlink_destroy("chan_send_conf.1"); - meshlink_destroy("chan_send_conf.2"); + assert(meshlink_destroy("chan_send_conf.1")); + assert(meshlink_destroy("chan_send_conf.2")); return true; } @@ -230,7 +230,7 @@ static void test_case_mesh_channel_send_02(void **state) { /* Test Steps for meshlink_channel_send Test Case # 2*/ static bool test_steps_mesh_channel_send_02(void) { struct timespec timeout = {0}; - meshlink_destroy("chan_send_conf.5"); + assert(meshlink_destroy("chan_send_conf.5")); // Open new meshlink instance. @@ -265,7 +265,7 @@ static bool test_steps_mesh_channel_send_02(void) { // Clean up. meshlink_close(mesh1); - meshlink_destroy("chan_send_conf.5"); + assert(meshlink_destroy("chan_send_conf.5")); return true; } @@ -277,7 +277,7 @@ static void test_case_mesh_channel_send_03(void **state) { /* Test Steps for meshlink_channel_send Test Case # 3*/ static bool test_steps_mesh_channel_send_03(void) { - meshlink_destroy("chan_send_conf.7"); + assert(meshlink_destroy("chan_send_conf.7")); // Open new meshlink instance. meshlink_handle_t *mesh1 = meshlink_open("chan_send_conf.7", "foo", "channels", DEV_CLASS_BACKBONE); @@ -295,7 +295,7 @@ static bool test_steps_mesh_channel_send_03(void) { // Clean up. meshlink_close(mesh1); - meshlink_destroy("chan_send_conf.7"); + assert(meshlink_destroy("chan_send_conf.7")); return true; } @@ -308,7 +308,7 @@ static void test_case_mesh_channel_send_04(void **state) { /* Test Steps for meshlink_channel_send Test Case # 4*/ static bool test_steps_mesh_channel_send_04(void) { struct timespec timeout = {0}; - meshlink_destroy("chan_send_conf.9"); + assert(meshlink_destroy("chan_send_conf.9")); // Open two new meshlink instance. meshlink_handle_t *mesh1 = meshlink_open("chan_send_conf.9", "foo", "channels", DEV_CLASS_BACKBONE); @@ -342,7 +342,7 @@ static bool test_steps_mesh_channel_send_04(void) { // Clean up. meshlink_close(mesh1); - meshlink_destroy("chan_send_conf.9"); + assert(meshlink_destroy("chan_send_conf.9")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_set_accept_cb.c b/test/blackbox/run_blackbox_tests/test_cases_channel_set_accept_cb.c index 9972b63a..fa345b31 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_set_accept_cb.c +++ b/test/blackbox/run_blackbox_tests/test_cases_channel_set_accept_cb.c @@ -138,8 +138,8 @@ static void test_case_set_channel_accept_cb_01(void **state) { static bool test_steps_set_channel_accept_cb_01(void) { /* deleting the confbase if already exists */ struct timespec timeout = {0}; - meshlink_destroy("acceptconf1"); - meshlink_destroy("acceptconf2"); + assert(meshlink_destroy("acceptconf1")); + assert(meshlink_destroy("acceptconf2")); meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); /* Create meshlink instances */ @@ -225,8 +225,8 @@ static bool test_steps_set_channel_accept_cb_01(void) { /* closing channel, meshes and destroying confbase */ meshlink_close(mesh1); meshlink_close(mesh2); - meshlink_destroy("acceptconf1"); - meshlink_destroy("acceptconf2"); + assert(meshlink_destroy("acceptconf1")); + assert(meshlink_destroy("acceptconf2")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_set_poll_cb.c b/test/blackbox/run_blackbox_tests/test_cases_channel_set_poll_cb.c index 39579e85..5ad8f03d 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_set_poll_cb.c +++ b/test/blackbox/run_blackbox_tests/test_cases_channel_set_poll_cb.c @@ -114,8 +114,8 @@ static void test_case_channel_set_poll_cb_01(void **state) { static bool test_steps_channel_set_poll_cb_01(void) { /* deleting the confbase if already exists */ struct timespec timeout = {0}; - meshlink_destroy("pollconf1"); - meshlink_destroy("pollconf2"); + assert(meshlink_destroy("pollconf1")); + assert(meshlink_destroy("pollconf2")); meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); /* Create meshlink instances */ @@ -170,8 +170,8 @@ static bool test_steps_channel_set_poll_cb_01(void) { /* closing channel, meshes and destroying confbase */ meshlink_close(mesh1); meshlink_close(mesh2); - meshlink_destroy("pollconf1"); - meshlink_destroy("pollconf2"); + assert(meshlink_destroy("pollconf1")); + assert(meshlink_destroy("pollconf2")); return true; } @@ -212,7 +212,7 @@ static bool test_steps_channel_set_poll_cb_02(void) { assert_int_not_equal(meshlink_errno, 0); meshlink_close(mesh_handle); - meshlink_destroy("channelpollconf3"); + assert(meshlink_destroy("channelpollconf3")); return true; } @@ -245,7 +245,7 @@ static bool test_steps_channel_set_poll_cb_03(void) { assert_int_equal(meshlink_errno, MESHLINK_EINVAL); meshlink_close(mesh_handle); - meshlink_destroy("channelpollconf4"); + assert(meshlink_destroy("channelpollconf4")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_set_receive_cb.c b/test/blackbox/run_blackbox_tests/test_cases_channel_set_receive_cb.c index 1f904cec..697812e5 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_set_receive_cb.c +++ b/test/blackbox/run_blackbox_tests/test_cases_channel_set_receive_cb.c @@ -122,7 +122,7 @@ static void test_case_set_channel_receive_cb_01(void **state) { */ static bool test_steps_set_channel_receive_cb_01(void) { struct timespec timeout = {0}; - meshlink_destroy("channelreceiveconf"); + assert(meshlink_destroy("channelreceiveconf")); meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); /* Create meshlink instance */ @@ -160,7 +160,7 @@ static bool test_steps_set_channel_receive_cb_01(void) { pthread_mutex_unlock(& lock_receive); meshlink_close(mesh_handle); - meshlink_destroy("channelreceiveconf"); + assert(meshlink_destroy("channelreceiveconf")); return true; } @@ -179,7 +179,7 @@ static void test_case_set_channel_receive_cb_02(void **state) { meshlink_channel_set_receive_cb returning proper meshlink_errno. */ static bool test_steps_set_channel_receive_cb_02(void) { - meshlink_destroy("channelreceiveconf"); + assert(meshlink_destroy("channelreceiveconf")); meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); /* Create meshlink instance */ @@ -202,7 +202,7 @@ static bool test_steps_set_channel_receive_cb_02(void) { assert_int_equal(meshlink_errno, MESHLINK_EINVAL); meshlink_close(mesh_handle); - meshlink_destroy("channelreceiveconf"); + assert(meshlink_destroy("channelreceiveconf")); return true; } @@ -221,7 +221,7 @@ static void test_case_set_channel_receive_cb_03(void **state) { meshlink_channel_set_receive_cb returning proper meshlink_errno. */ static bool test_steps_set_channel_receive_cb_03(void) { - meshlink_destroy("channelreceiveconf"); + assert(meshlink_destroy("channelreceiveconf")); meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); /* Create meshlink instance */ @@ -239,7 +239,7 @@ static bool test_steps_set_channel_receive_cb_03(void) { assert_int_equal(meshlink_errno, MESHLINK_EINVAL); meshlink_close(mesh_handle); - meshlink_destroy("channelreceiveconf"); + assert(meshlink_destroy("channelreceiveconf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_channel_shutdown.c b/test/blackbox/run_blackbox_tests/test_cases_channel_shutdown.c index 434afc91..c8f6ef43 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_channel_shutdown.c +++ b/test/blackbox/run_blackbox_tests/test_cases_channel_shutdown.c @@ -146,8 +146,8 @@ static void test_case_mesh_channel_shutdown_01(void **state) { */ static bool test_steps_mesh_channel_shutdown_01(void) { struct timespec timeout = {0}; - meshlink_destroy("chan_shutdown_conf.1"); - meshlink_destroy("chan_shutdown_conf.2"); + assert(meshlink_destroy("chan_shutdown_conf.1")); + assert(meshlink_destroy("chan_shutdown_conf.2")); // Open two new meshlink instance. meshlink_handle_t *mesh1 = meshlink_open("chan_shutdown_conf.1", "foo", "channels", DEV_CLASS_BACKBONE); @@ -245,8 +245,8 @@ static bool test_steps_mesh_channel_shutdown_01(void) { meshlink_close(mesh2); meshlink_close(mesh1); - meshlink_destroy("chan_shutdown_conf.1"); - meshlink_destroy("chan_shutdown_conf.2"); + assert(meshlink_destroy("chan_shutdown_conf.1")); + assert(meshlink_destroy("chan_shutdown_conf.2")); return true; } @@ -266,7 +266,7 @@ static void test_case_mesh_channel_shutdown_02(void **state) { meshlink_channel_shutdown API should report proper error handling */ static bool test_steps_mesh_channel_shutdown_02(void) { - meshlink_destroy("channelshutdownconf.3"); + assert(meshlink_destroy("channelshutdownconf.3")); meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); /* Create meshlink instance */ @@ -290,7 +290,7 @@ static bool test_steps_mesh_channel_shutdown_02(void) { assert_int_equal(meshlink_errno, MESHLINK_EINVAL); meshlink_close(mesh_handle); - meshlink_destroy("channelshutdownconf.3"); + assert(meshlink_destroy("channelshutdownconf.3")); return true; } @@ -310,7 +310,7 @@ static void test_case_mesh_channel_shutdown_03(void **state) { meshlink_channel_shutdown API should report proper error handling */ static bool test_steps_mesh_channel_shutdown_03(void) { - meshlink_destroy("channelshutdownconf.4"); + assert(meshlink_destroy("channelshutdownconf.4")); meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); /* Create meshlink instance */ @@ -327,7 +327,7 @@ static bool test_steps_mesh_channel_shutdown_03(void) { assert_int_equal(meshlink_errno, MESHLINK_EINVAL); meshlink_close(mesh_handle); - meshlink_destroy("channelshutdownconf.4"); + assert(meshlink_destroy("channelshutdownconf.4")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_default_blacklist.c b/test/blackbox/run_blackbox_tests/test_cases_default_blacklist.c index 37ddd020..508e784b 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_default_blacklist.c +++ b/test/blackbox/run_blackbox_tests/test_cases_default_blacklist.c @@ -97,9 +97,9 @@ void status_cb1(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) but when enabled foo node should not receive data from foz */ static bool test_steps_mesh_default_blacklist_01(void) { - meshlink_destroy("def_blacklist_conf.1"); - meshlink_destroy("def_blacklist_conf.2"); - meshlink_destroy("def_blacklist_conf.3"); + assert(meshlink_destroy("def_blacklist_conf.1")); + assert(meshlink_destroy("def_blacklist_conf.2")); + assert(meshlink_destroy("def_blacklist_conf.3")); // Open two new meshlink instance. meshlink_handle_t *mesh1 = meshlink_open("def_blacklist_conf.1", "foo", "blacklist", DEV_CLASS_BACKBONE); @@ -165,9 +165,9 @@ static bool test_steps_mesh_default_blacklist_01(void) { meshlink_close(mesh1); meshlink_close(mesh2); meshlink_close(mesh3); - meshlink_destroy("def_blacklist_conf.1"); - meshlink_destroy("def_blacklist_conf.2"); - meshlink_destroy("def_blacklist_conf.3"); + assert(meshlink_destroy("def_blacklist_conf.1")); + assert(meshlink_destroy("def_blacklist_conf.2")); + assert(meshlink_destroy("def_blacklist_conf.3")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_export.c b/test/blackbox/run_blackbox_tests/test_cases_export.c index db94a002..0281f0b5 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_export.c +++ b/test/blackbox/run_blackbox_tests/test_cases_export.c @@ -65,7 +65,7 @@ static void test_case_export_01(void **state) { API returns a NULL terminated string containing meta data of NUT. */ static bool test_export_01(void) { - meshlink_destroy("exportconf"); + assert(meshlink_destroy("exportconf")); meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); /* Create meshlink instance */ @@ -77,7 +77,7 @@ static bool test_export_01(void) { assert_int_not_equal(expo, NULL); meshlink_close(mesh_handle); - meshlink_destroy("exportconf"); + assert(meshlink_destroy("exportconf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes.c b/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes.c index 9f298a2c..6fd409bb 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes.c +++ b/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes.c @@ -75,8 +75,8 @@ static void test_case_get_all_nodes_01(void **state) { Obtaining list of nodes in the mesh at the given instance */ static bool test_get_all_nodes_01(void) { - meshlink_destroy("getnodeconf1"); - meshlink_destroy("getnodeconf2"); + assert(meshlink_destroy("getnodeconf1")); + assert(meshlink_destroy("getnodeconf2")); meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); /* Create meshlink instance for NUT */ @@ -108,8 +108,8 @@ static bool test_get_all_nodes_01(void) { meshlink_close(mesh1); meshlink_close(mesh2); - meshlink_destroy("getnodeconf1"); - meshlink_destroy("getnodeconf2"); + assert(meshlink_destroy("getnodeconf1")); + assert(meshlink_destroy("getnodeconf2")); return true; } @@ -162,7 +162,7 @@ static bool test_get_all_nodes_03(void) { assert_int_equal(nodes, NULL); meshlink_close(mesh_handle); - meshlink_destroy("getallnodesconf"); + assert(meshlink_destroy("getallnodesconf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes_by_dev_class.c b/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes_by_dev_class.c index 3c1498eb..f3c73a92 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes_by_dev_class.c +++ b/test/blackbox/run_blackbox_tests/test_cases_get_all_nodes_by_dev_class.c @@ -213,7 +213,7 @@ static bool test_steps_mesh_get_node_by_dev_class_02(void) { meshlink_node_t **nodes; size_t nnodes = 0; - meshlink_destroy("getnodeconf.1"); + assert(meshlink_destroy("getnodeconf.1")); /* Create meshlink instance for NUT */ meshlink_handle_t *mesh_nut = meshlink_open("getnodeconf.1", "nut", "node_sim", DEV_CLASS_STATIONARY); @@ -233,7 +233,7 @@ static bool test_steps_mesh_get_node_by_dev_class_02(void) { assert_int_not_equal(meshlink_errno, 0); meshlink_close(mesh_nut); - meshlink_destroy("getnodeconf.1"); + assert(meshlink_destroy("getnodeconf.1")); return true; } @@ -252,7 +252,7 @@ static void test_case_mesh_get_node_dev_class_01(void **state) { meshlink_get_node_dev_class API should return DEV_CLASS_STATIONARY device class */ static bool test_steps_mesh_get_node_dev_class_01(void) { - meshlink_destroy("getnodeconf.1"); + assert(meshlink_destroy("getnodeconf.1")); /* Create meshlink instance for NUT */ meshlink_handle_t *mesh_nut = meshlink_open("getnodeconf.1", "nut", "node_sim", DEV_CLASS_STATIONARY); @@ -267,7 +267,7 @@ static bool test_steps_mesh_get_node_dev_class_01(void) { assert_int_equal(dev_class, DEV_CLASS_STATIONARY); meshlink_close(mesh_nut); - meshlink_destroy("getnodeconf.1"); + assert(meshlink_destroy("getnodeconf.1")); return true; } @@ -287,7 +287,7 @@ static void test_case_mesh_get_node_dev_class_02(void **state) { meshlink_errno. */ static bool test_steps_mesh_get_node_dev_class_02(void) { - meshlink_destroy("getnodeconf.1"); + assert(meshlink_destroy("getnodeconf.1")); /* Create meshlink instance for NUT */ meshlink_handle_t *mesh_nut = meshlink_open("getnodeconf.1", "nut", "node_sim", DEV_CLASS_STATIONARY); @@ -307,7 +307,7 @@ static bool test_steps_mesh_get_node_dev_class_02(void) { assert_int_not_equal(meshlink_errno, 0); meshlink_close(mesh_nut); - meshlink_destroy("getnodeconf.1"); + assert(meshlink_destroy("getnodeconf.1")); return true; } @@ -315,11 +315,11 @@ static int black_box_setup_test_case(void **state) { (void)state; fprintf(stderr, "Destroying confbases\n"); - meshlink_destroy("getnodeconf.1"); - meshlink_destroy("getnodeconf.2"); - meshlink_destroy("getnodeconf.3"); - meshlink_destroy("getnodeconf.4"); - meshlink_destroy("getnodeconf.5"); + assert(meshlink_destroy("getnodeconf.1")); + assert(meshlink_destroy("getnodeconf.2")); + assert(meshlink_destroy("getnodeconf.3")); + assert(meshlink_destroy("getnodeconf.4")); + assert(meshlink_destroy("getnodeconf.5")); meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); meshlink_errno = MESHLINK_OK; diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_ex_addr.c b/test/blackbox/run_blackbox_tests/test_cases_get_ex_addr.c index 2c5cea46..02cb4d6f 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_get_ex_addr.c +++ b/test/blackbox/run_blackbox_tests/test_cases_get_ex_addr.c @@ -79,7 +79,7 @@ static bool test_steps_mesh_get_address_01(void) { free(addr); meshlink_close(mesh); - meshlink_destroy("getex_conf"); + assert(meshlink_destroy("getex_conf")); return true; } @@ -128,7 +128,7 @@ static bool test_steps_mesh_get_address_03(void) { free(addr); meshlink_close(mesh); - meshlink_destroy("getex_conf"); + assert(meshlink_destroy("getex_conf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_fingerprint.c b/test/blackbox/run_blackbox_tests/test_cases_get_fingerprint.c index 59321f0d..3435f6ee 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_get_fingerprint.c +++ b/test/blackbox/run_blackbox_tests/test_cases_get_fingerprint.c @@ -85,7 +85,7 @@ static bool test_get_fingerprint_cb_01(void) { assert_int_not_equal(fp, NULL); meshlink_close(mesh_handle); - meshlink_destroy("getfingerprintconf"); + assert(meshlink_destroy("getfingerprintconf")); return true; } @@ -126,7 +126,7 @@ static bool test_get_fingerprint_cb_02(void) { assert_int_equal(fp, NULL); meshlink_close(mesh_handle); - meshlink_destroy("getfingerprintconf"); + assert(meshlink_destroy("getfingerprintconf")); return true; } @@ -158,7 +158,7 @@ static bool test_get_fingerprint_cb_03(void) { assert_int_equal(fp, NULL); meshlink_close(mesh_handle); - meshlink_destroy("getfingerprintconf"); + assert(meshlink_destroy("getfingerprintconf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_node.c b/test/blackbox/run_blackbox_tests/test_cases_get_node.c index c46caa5c..a13b4756 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_get_node.c +++ b/test/blackbox/run_blackbox_tests/test_cases_get_node.c @@ -81,8 +81,8 @@ static void test_case_mesh_get_node_01(void **state) { */ static bool test_steps_mesh_get_node_01(void) { meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_destroy("getnode1"); - meshlink_destroy("getnode2"); + assert(meshlink_destroy("getnode1")); + assert(meshlink_destroy("getnode2")); // Opening NUT and bar nodes meshlink_handle_t *mesh1 = meshlink_open("getnode1", "nut", "test", DEV_CLASS_STATIONARY); @@ -111,8 +111,8 @@ static bool test_steps_mesh_get_node_01(void) { // Cleanup meshlink_close(mesh1); meshlink_close(mesh2); - meshlink_destroy("getnode1"); - meshlink_destroy("getnode2"); + assert(meshlink_destroy("getnode1")); + assert(meshlink_destroy("getnode2")); return true; } @@ -158,7 +158,7 @@ static bool test_steps_mesh_get_node_03(void) { assert_int_equal(get_node, NULL); meshlink_close(mesh); - meshlink_destroy("node_conf.3"); + assert(meshlink_destroy("node_conf.3")); return true; } @@ -187,7 +187,7 @@ static bool test_steps_mesh_get_node_04(void) { assert_int_equal(get_node, NULL); meshlink_close(mesh); - meshlink_destroy("node_conf"); + assert(meshlink_destroy("node_conf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_port.c b/test/blackbox/run_blackbox_tests/test_cases_get_port.c index 9b559844..71f7cb44 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_get_port.c +++ b/test/blackbox/run_blackbox_tests/test_cases_get_port.c @@ -72,7 +72,7 @@ static bool test_steps_mesh_get_port_01(void) { assert_int_not_equal(port, -1); meshlink_close(mesh); - meshlink_destroy("port_conf"); + assert(meshlink_destroy("port_conf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_get_self.c b/test/blackbox/run_blackbox_tests/test_cases_get_self.c index 52f909e7..3368a42f 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_get_self.c +++ b/test/blackbox/run_blackbox_tests/test_cases_get_self.c @@ -75,7 +75,7 @@ static bool test_steps_mesh_get_self_01(void) { } meshlink_close(mesh); - meshlink_destroy("self_conf"); + assert(meshlink_destroy("self_conf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_hint_address.c b/test/blackbox/run_blackbox_tests/test_cases_hint_address.c index d79c4889..61be4518 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_hint_address.c +++ b/test/blackbox/run_blackbox_tests/test_cases_hint_address.c @@ -65,8 +65,8 @@ void test_case_hint_address_01(void **state) { } /* Test Steps for meshlink_hint_address Test Case # 1 - Valid case */ bool test_steps_hint_address_01(void) { - meshlink_destroy("hintconf1"); - meshlink_destroy("hintconf2"); + assert(meshlink_destroy("hintconf1")); + assert(meshlink_destroy("hintconf2")); meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); // Create meshlink instance for the nodes @@ -123,8 +123,8 @@ bool test_steps_hint_address_01(void) { free(buff); meshlink_close(mesh1); meshlink_close(mesh2); - meshlink_destroy("hintconf1"); - meshlink_destroy("hintconf2"); + assert(meshlink_destroy("hintconf1")); + assert(meshlink_destroy("hintconf2")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_import.c b/test/blackbox/run_blackbox_tests/test_cases_import.c index 53107a28..fb1b559a 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_import.c +++ b/test/blackbox/run_blackbox_tests/test_cases_import.c @@ -87,8 +87,8 @@ static void test_case_import_01(void **state) { */ static bool test_import_01(void) { meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_destroy("importconf1"); - meshlink_destroy("importconf2"); + assert(meshlink_destroy("importconf1")); + assert(meshlink_destroy("importconf2")); // Opening NUT and bar nodes meshlink_handle_t *mesh1 = meshlink_open("importconf1", "nut", "test", DEV_CLASS_STATIONARY); @@ -110,8 +110,8 @@ static bool test_import_01(void) { meshlink_close(mesh1); meshlink_close(mesh2); - meshlink_destroy("importconf1"); - meshlink_destroy("importconf2"); + assert(meshlink_destroy("importconf1")); + assert(meshlink_destroy("importconf2")); return imp1 && imp2; } @@ -130,8 +130,8 @@ static void test_case_import_02(void **state) { */ static bool test_import_02(void) { meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_destroy("importconf1"); - meshlink_destroy("importconf2"); + assert(meshlink_destroy("importconf1")); + assert(meshlink_destroy("importconf2")); // Opening NUT and bar nodes meshlink_handle_t *mesh1 = meshlink_open("importconf1", "nut", "test", DEV_CLASS_STATIONARY); @@ -153,8 +153,8 @@ static bool test_import_02(void) { meshlink_close(mesh1); meshlink_close(mesh2); - meshlink_destroy("importconf1"); - meshlink_destroy("importconf2"); + assert(meshlink_destroy("importconf1")); + assert(meshlink_destroy("importconf2")); return true; } @@ -175,8 +175,8 @@ static void test_case_import_03(void **state) { static bool test_import_03(void) { meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_destroy("importconf1"); - meshlink_destroy("importconf2"); + assert(meshlink_destroy("importconf1")); + assert(meshlink_destroy("importconf2")); /* Opening NUT and bar nodes */ meshlink_handle_t *mesh1 = meshlink_open("importconf1", "nut", "chat", DEV_CLASS_STATIONARY); @@ -199,8 +199,8 @@ static bool test_import_03(void) { meshlink_close(mesh1); meshlink_close(mesh2); - meshlink_destroy("importconf1"); - meshlink_destroy("importconf2"); + assert(meshlink_destroy("importconf1")); + assert(meshlink_destroy("importconf2")); return true; } @@ -220,8 +220,8 @@ static void test_case_import_04(void **state) { */ static bool test_import_04(void) { meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_destroy("importconf1"); - meshlink_destroy("importconf2"); + assert(meshlink_destroy("importconf1")); + assert(meshlink_destroy("importconf2")); // Opening NUT and bar nodes meshlink_handle_t *mesh1 = meshlink_open("importconf1", "nut", "chat", DEV_CLASS_STATIONARY); @@ -244,8 +244,8 @@ static bool test_import_04(void) { meshlink_close(mesh1); meshlink_close(mesh2); - meshlink_destroy("importconf1"); - meshlink_destroy("importconf2"); + assert(meshlink_destroy("importconf1")); + assert(meshlink_destroy("importconf2")); return true; } @@ -265,8 +265,8 @@ static void test_case_import_05(void **state) { */ static bool test_import_05(void) { meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); - meshlink_destroy("importconf1"); - meshlink_destroy("importconf2"); + assert(meshlink_destroy("importconf1")); + assert(meshlink_destroy("importconf2")); /* Opening NUT and bar nodes */ meshlink_handle_t *mesh1 = meshlink_open("importconf1", "nut", "chat", DEV_CLASS_STATIONARY); @@ -293,8 +293,8 @@ static bool test_import_05(void) { meshlink_close(mesh1); meshlink_close(mesh2); - meshlink_destroy("importconf1"); - meshlink_destroy("importconf2"); + assert(meshlink_destroy("importconf1")); + assert(meshlink_destroy("importconf2")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_invite.c b/test/blackbox/run_blackbox_tests/test_cases_invite.c index e95f278b..929b002a 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_invite.c +++ b/test/blackbox/run_blackbox_tests/test_cases_invite.c @@ -78,7 +78,7 @@ static void test_case_invite_01(void **state) { Generates an invitation */ static bool test_invite_01(void) { - meshlink_destroy("inviteconf"); + assert(meshlink_destroy("inviteconf")); meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); // Create meshlink instance @@ -91,7 +91,7 @@ static bool test_invite_01(void) { free(invitation); meshlink_close(mesh_handle); - meshlink_destroy("inviteconf"); + assert(meshlink_destroy("inviteconf")); return true; } @@ -127,7 +127,7 @@ static void test_case_invite_03(void **state) { Reports appropriate error by returning NULL */ static bool test_invite_03(void) { - meshlink_destroy("inviteconf"); + assert(meshlink_destroy("inviteconf")); meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); // Create meshlink instance @@ -140,7 +140,7 @@ static bool test_invite_03(void) { assert_int_equal(invitation, NULL); meshlink_close(mesh_handle); - meshlink_destroy("inviteconf"); + assert(meshlink_destroy("inviteconf")); return true; } @@ -159,7 +159,7 @@ static void test_case_invite_04(void **state) { Newly added address should be there in the invitation. */ static bool test_invite_04(void) { - meshlink_destroy("inviteconf"); + assert(meshlink_destroy("inviteconf")); meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); // Create meshlink instance @@ -168,12 +168,12 @@ static bool test_invite_04(void) { meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); char *hostname1 = "127.1.1.1"; - meshlink_add_address(mesh_handle, hostname1); + assert(meshlink_add_address(mesh_handle, hostname1)); char *invitation = meshlink_invite(mesh_handle, NULL, "foo"); assert_int_not_equal(strstr(invitation, hostname1), NULL); char *hostname2 = "127.1.2.3"; - meshlink_add_address(mesh_handle, hostname2); + assert(meshlink_add_address(mesh_handle, hostname2)); invitation = meshlink_invite(mesh_handle, NULL, "bar"); // Verify we have both the added addresses @@ -181,7 +181,7 @@ static bool test_invite_04(void) { assert_int_not_equal(strstr(invitation, hostname2), NULL); meshlink_close(mesh_handle); - meshlink_destroy("inviteconf"); + assert(meshlink_destroy("inviteconf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_join.c b/test/blackbox/run_blackbox_tests/test_cases_join.c index 56866fe5..86552857 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_join.c +++ b/test/blackbox/run_blackbox_tests/test_cases_join.c @@ -86,8 +86,8 @@ static void test_case_meshlink_join_01(void **state) { NUT joins relay using the invitation generated. */ static bool test_meshlink_join_01(void) { - meshlink_destroy("join_conf.1"); - meshlink_destroy("join_conf.2"); + assert(meshlink_destroy("join_conf.1")); + assert(meshlink_destroy("join_conf.2")); // Create node instances meshlink_handle_t *mesh1 = meshlink_open("join_conf.1", "nut", "test", DEV_CLASS_STATIONARY); @@ -101,7 +101,7 @@ static bool test_meshlink_join_01(void) { meshlink_set_node_status_cb(mesh1, status_callback); // Inviting nut - meshlink_start(mesh2); + assert(meshlink_start(mesh2)); char *invitation = meshlink_invite(mesh2, NULL, "nut"); assert(invitation); @@ -116,8 +116,8 @@ static bool test_meshlink_join_01(void) { free(invitation); meshlink_close(mesh1); meshlink_close(mesh2); - meshlink_destroy("join_conf.1"); - meshlink_destroy("join_conf.2"); + assert(meshlink_destroy("join_conf.1")); + assert(meshlink_destroy("join_conf.2")); return true; } @@ -136,7 +136,7 @@ static void test_case_meshlink_join_02(void **state) { report error accordingly when NULL is passed as mesh handle argument */ static bool test_meshlink_join_02(void) { - meshlink_destroy("join_conf.3"); + assert(meshlink_destroy("join_conf.3")); // Create node instances meshlink_handle_t *mesh1 = meshlink_open("join_conf.3", "nut", "test", DEV_CLASS_STATIONARY); @@ -151,7 +151,7 @@ static bool test_meshlink_join_02(void) { free(invitation); meshlink_close(mesh1); - meshlink_destroy("join_conf.3"); + assert(meshlink_destroy("join_conf.3")); return true; } @@ -171,7 +171,7 @@ static void test_case_meshlink_join_03(void **state) { Report error accordingly when NULL is passed as invite argument */ static bool test_meshlink_join_03(void) { - meshlink_destroy("joinconf.4"); + assert(meshlink_destroy("joinconf.4")); meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); /* Create meshlink instance */ @@ -184,7 +184,7 @@ static bool test_meshlink_join_03(void) { assert_int_equal(ret, false); meshlink_close(mesh_handle); - meshlink_destroy("joinconf.4"); + assert(meshlink_destroy("joinconf.4")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_key_rotation.c b/test/blackbox/run_blackbox_tests/test_cases_key_rotation.c index 695d5e69..8987d7c5 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_key_rotation.c +++ b/test/blackbox/run_blackbox_tests/test_cases_key_rotation.c @@ -70,7 +70,7 @@ static void test_case_key_rotation_01(void **state) { */ static bool test_key_rotation_01(void) { meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); // Open a new meshlink instance. @@ -91,7 +91,7 @@ static bool test_key_rotation_01(void) { // Cleanup meshlink_close(mesh); - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); return true; } @@ -113,7 +113,7 @@ static void test_case_key_rotation_02(void **state) { */ static bool test_key_rotation_02(void) { meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); // Open a new meshlink instance. @@ -145,7 +145,7 @@ static bool test_key_rotation_02(void) { // Cleanup meshlink_close(mesh); - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); return true; } @@ -166,7 +166,7 @@ static void test_case_key_rotation_03(void **state) { been changed to new by key rotate API. */ static bool test_key_rotation_03(void) { - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); // Open a new meshlink instance. @@ -188,7 +188,7 @@ static bool test_key_rotation_03(void) { // Cleanup - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); return true; } @@ -224,7 +224,7 @@ static bool test_key_rotation_04(void) { bool join_status; char *invitations_directory_path = "encrypted_conf/current/invitations/"; - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); // Open a new meshlink instance. @@ -310,9 +310,9 @@ static bool test_key_rotation_04(void) { meshlink_close(mesh); meshlink_close(mesh1); meshlink_close(mesh2); - meshlink_destroy("encrypted_conf"); - meshlink_destroy("encrypted_conf.1"); - meshlink_destroy("encrypted_conf.2"); + assert(meshlink_destroy("encrypted_conf")); + assert(meshlink_destroy("encrypted_conf.1")); + assert(meshlink_destroy("encrypted_conf.2")); return true; } @@ -360,7 +360,7 @@ static bool test_key_rotation_05(void) { pid_t pid; int status; meshlink_handle_t *mesh; - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); assert(signal(SIGINT, SIG_DFL) != SIG_ERR); @@ -376,7 +376,7 @@ static bool test_key_rotation_05(void) { for(break_stage = 1; break_stage <= 3; break_stage += 1) { fprintf(stderr, "Debugging stage %d\n", break_stage); - meshlink_destroy("encrypted_conf"); + assert(meshlink_destroy("encrypted_conf")); assert(pipe(pipefd) != -1); @@ -397,7 +397,7 @@ static bool test_key_rotation_05(void) { assert(write(pipefd[1], invitation, strlen(invitation) + 1) != -1); - meshlink_encrypted_key_rotate(mesh, "newkey", 6); + assert(meshlink_encrypted_key_rotate(mesh, "newkey", 6)); raise(SIGABRT); } @@ -441,7 +441,7 @@ static bool test_key_rotation_05(void) { assert(meshlink_start(mesh)); - meshlink_destroy("encrypted_conf.1"); + assert(meshlink_destroy("encrypted_conf.1")); meshlink_handle_t *mesh2 = meshlink_open("encrypted_conf.1", "bar", "bar", DEV_CLASS_BACKBONE); assert(mesh2); @@ -461,8 +461,8 @@ static bool test_key_rotation_05(void) { // Cleanup - meshlink_destroy("encrypted_conf"); - meshlink_destroy("encrypted_conf.1"); + assert(meshlink_destroy("encrypted_conf")); + assert(meshlink_destroy("encrypted_conf.1")); devtool_keyrotate_probe = nop_stage; return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_open.c b/test/blackbox/run_blackbox_tests/test_cases_open.c index cdfba7b0..40bd26c7 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_open.c +++ b/test/blackbox/run_blackbox_tests/test_cases_open.c @@ -91,7 +91,7 @@ static bool test_steps_mesh_open_01(void) { assert_int_not_equal(mesh, NULL); meshlink_close(mesh); - meshlink_destroy("open_conf"); + assert(meshlink_destroy("open_conf")); return true; } @@ -134,7 +134,7 @@ static bool test_steps_mesh_open_03(void) { meshlink_handle_t *mesh = meshlink_open("openconf", NULL, "test", DEV_CLASS_STATIONARY); assert_int_equal(mesh, NULL); - meshlink_destroy("open_conf"); + assert(meshlink_destroy("open_conf")); return true; } @@ -156,7 +156,7 @@ static bool test_steps_mesh_open_04(void) { meshlink_handle_t *mesh = meshlink_open("openconf", "foo", NULL, DEV_CLASS_STATIONARY); assert_int_equal(mesh, NULL); - meshlink_destroy("open_conf"); + assert(meshlink_destroy("open_conf")); return true; } @@ -178,7 +178,7 @@ static bool test_steps_mesh_open_05(void) { meshlink_handle_t *mesh = meshlink_open("openconf", "foo", "test", -1); assert_int_equal(mesh, NULL); - meshlink_destroy("open_conf"); + assert(meshlink_destroy("open_conf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_pmtu.c b/test/blackbox/run_blackbox_tests/test_cases_pmtu.c index 204132d7..58675964 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_pmtu.c +++ b/test/blackbox/run_blackbox_tests/test_cases_pmtu.c @@ -81,7 +81,7 @@ static bool test_steps_mesh_pmtu_01(void) { assert_int_not_equal(pmtu, -1); meshlink_close(mesh); - meshlink_destroy("pmtu_conf"); + assert(meshlink_destroy("pmtu_conf")); return true; } @@ -111,7 +111,7 @@ static bool test_steps_mesh_pmtu_02(void) { assert_int_equal(pmtu, -1); meshlink_close(mesh); - meshlink_destroy("pmtu_conf"); + assert(meshlink_destroy("pmtu_conf")); return true; } @@ -139,7 +139,7 @@ static bool test_steps_mesh_pmtu_03(void) { assert_int_equal(pmtu, -1); meshlink_close(mesh); - meshlink_destroy("pmtu_conf"); + assert(meshlink_destroy("pmtu_conf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings01.c b/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings01.c index 45d86ed2..5cce98c0 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings01.c +++ b/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings01.c @@ -143,7 +143,7 @@ void test_case_mesh_random_port_bindings_01(void **state) { */ bool test_steps_mesh_random_port_bindings_01(void) { meshlink_handle_t *relay = NULL; - meshlink_destroy("relay_conf"); + assert(meshlink_destroy("relay_conf")); meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_message); @@ -171,7 +171,7 @@ bool test_steps_mesh_random_port_bindings_01(void) { ipv6_fd = -1; meshlink_close(relay); - meshlink_destroy("relay_conf"); + assert(meshlink_destroy("relay_conf")); return true; } @@ -193,7 +193,7 @@ void test_case_mesh_random_port_bindings_02(void **state) { */ bool test_steps_mesh_random_port_bindings_02(void) { meshlink_handle_t *relay = NULL; - meshlink_destroy("relay_conf"); + assert(meshlink_destroy("relay_conf")); meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_message); @@ -220,7 +220,7 @@ bool test_steps_mesh_random_port_bindings_02(void) { ipv6_fd = -1; meshlink_close(relay); - meshlink_destroy("relay_conf"); + assert(meshlink_destroy("relay_conf")); return true; } @@ -244,7 +244,7 @@ void test_case_mesh_random_port_bindings_03(void **state) { bool test_steps_mesh_random_port_bindings_03(void) { int port, new_port; meshlink_handle_t *relay = NULL; - meshlink_destroy("relay_conf"); + assert(meshlink_destroy("relay_conf")); meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_message); @@ -282,7 +282,7 @@ bool test_steps_mesh_random_port_bindings_03(void) { ipv6_fd = -1; meshlink_close(relay); - meshlink_destroy("relay_conf"); + assert(meshlink_destroy("relay_conf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings02.c b/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings02.c index 3fa76069..168915ad 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings02.c +++ b/test/blackbox/run_blackbox_tests/test_cases_random_port_bindings02.c @@ -69,9 +69,9 @@ static int setup_test(void **state) { set_sync_flag(&test_random_port_binding_peer_closed, false); set_sync_flag(&test_random_port_binding_nut_closed, false); - meshlink_destroy("nut"); - meshlink_destroy("peer"); - meshlink_destroy("relay"); + assert(meshlink_destroy("nut")); + assert(meshlink_destroy("peer")); + assert(meshlink_destroy("relay")); return EXIT_SUCCESS; } @@ -79,9 +79,9 @@ static int setup_test(void **state) { static int teardown_test(void **state) { (void)state; - meshlink_destroy("nut"); - meshlink_destroy("peer"); - meshlink_destroy("relay"); + assert(meshlink_destroy("nut")); + assert(meshlink_destroy("peer")); + assert(meshlink_destroy("relay")); netns_destroy_topology(test_random_port_bindings_state); return EXIT_SUCCESS; @@ -138,7 +138,7 @@ static void *relay_node(void *arg) { //system("ifconfig"); - meshlink_destroy("relay"); + assert(meshlink_destroy("relay")); relay = meshlink_open(mesh_arg->node_name, mesh_arg->confbase, mesh_arg->app_name, mesh_arg->dev_class); assert(relay); @@ -156,7 +156,7 @@ static void *relay_node(void *arg) { if(localnode == true) { assert(wait_sync_flag(&test_random_port_binding_make_switch, 300)); meshlink_close(relay); - meshlink_destroy("relay"); + assert(meshlink_destroy("relay")); set_sync_flag(&test_random_port_binding_relay_closed, true); @@ -167,7 +167,7 @@ static void *relay_node(void *arg) { assert(wait_sync_flag(&test_random_port_binding_node_connected, 300)); meshlink_close(relay); - meshlink_destroy("relay"); + assert(meshlink_destroy("relay")); set_sync_flag(&test_random_port_binding_relay_closed, true); @@ -180,7 +180,7 @@ static void *peer_node(void *arg) { fprintf(stderr, "\n\x1b[32mPeer Thread Started\x1b[0m\n"); - meshlink_destroy("peer"); + assert(meshlink_destroy("peer")); peer = meshlink_open(mesh_arg->node_name, mesh_arg->confbase, mesh_arg->app_name, mesh_arg->dev_class); assert(peer); @@ -209,7 +209,7 @@ static void *peer_node(void *arg) { assert(wait_sync_flag(&test_random_port_binding_node_connected, 300)); meshlink_close(peer); - meshlink_destroy("peer"); + assert(meshlink_destroy("peer")); set_sync_flag(&test_random_port_binding_peer_closed, true); @@ -221,7 +221,7 @@ static void *nut_node(void *arg) { fprintf(stderr, "\n\x1b[32mNut Thread Started\x1b[0m\n"); - meshlink_destroy("nut"); + assert(meshlink_destroy("nut")); nut_instance = meshlink_open(mesh_arg->node_name, mesh_arg->confbase, mesh_arg->app_name, mesh_arg->dev_class); assert(nut_instance); @@ -254,7 +254,7 @@ static void *nut_node(void *arg) { assert(wait_sync_flag(&test_random_port_binding_node_connected, 300)); meshlink_close(nut_instance); - meshlink_destroy("nut"); + assert(meshlink_destroy("nut")); set_sync_flag(&test_random_port_binding_nut_closed, true); diff --git a/test/blackbox/run_blackbox_tests/test_cases_rec_cb.c b/test/blackbox/run_blackbox_tests/test_cases_rec_cb.c index e94f9bfa..044234b3 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_rec_cb.c +++ b/test/blackbox/run_blackbox_tests/test_cases_rec_cb.c @@ -121,7 +121,7 @@ static bool test_set_rec_cb_01(void) { pthread_mutex_unlock(&lock); meshlink_close(mesh_handle); - meshlink_destroy("set_receive_cb_conf"); + assert(meshlink_destroy("set_receive_cb_conf")); return true; } @@ -189,7 +189,7 @@ static bool test_set_rec_cb_03(void) { pthread_mutex_unlock(&lock); meshlink_close(mesh_handle); - meshlink_destroy("set_receive_cb_conf"); + assert(meshlink_destroy("set_receive_cb_conf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_send.c b/test/blackbox/run_blackbox_tests/test_cases_send.c index 743636af..1cf47fce 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_send.c +++ b/test/blackbox/run_blackbox_tests/test_cases_send.c @@ -99,7 +99,7 @@ static bool test_steps_mesh_send_01(void) { assert_int_equal(receive_data, true); meshlink_close(mesh); - meshlink_destroy("send_conf"); + assert(meshlink_destroy("send_conf")); return result; } @@ -130,7 +130,7 @@ static bool test_steps_mesh_send_02(void) { assert_int_equal(ret, false); meshlink_close(mesh); - meshlink_destroy("send_conf"); + assert(meshlink_destroy("send_conf")); return true; } @@ -159,7 +159,7 @@ static bool test_steps_mesh_send_03(void) { assert_int_equal(ret, false); meshlink_close(mesh); - meshlink_destroy("send_conf"); + assert(meshlink_destroy("send_conf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_set_connection_try_cb.c b/test/blackbox/run_blackbox_tests/test_cases_set_connection_try_cb.c index 45e75542..6eac8577 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_set_connection_try_cb.c +++ b/test/blackbox/run_blackbox_tests/test_cases_set_connection_try_cb.c @@ -75,8 +75,8 @@ static void test_case_set_connection_try_cb_01(void **state) { After closing bar node it should invoke 3 connection try callbacks in span of about 30 seconds. */ static bool test_set_connection_try_cb_01(void) { - meshlink_destroy("meshlink_conf.1"); - meshlink_destroy("meshlink_conf.2"); + assert(meshlink_destroy("meshlink_conf.1")); + assert(meshlink_destroy("meshlink_conf.2")); // Opening foo and bar nodes meshlink_handle_t *mesh1 = meshlink_open("meshlink_conf.1", "foo", "test", DEV_CLASS_STATIONARY); @@ -95,8 +95,8 @@ static bool test_set_connection_try_cb_01(void) { assert(exp1 != NULL); char *exp2 = meshlink_export(mesh2); assert(exp2 != NULL); - meshlink_import(mesh1, exp2); - meshlink_import(mesh2, exp1); + assert(meshlink_import(mesh1, exp2)); + assert(meshlink_import(mesh2, exp1)); free(exp1); free(exp2); @@ -129,8 +129,8 @@ static bool test_set_connection_try_cb_01(void) { assert_in_range(attempt_time_stop - attempt_time_start, 25, 45); // Cleanup - meshlink_destroy("meshlink_conf.1"); - meshlink_destroy("meshlink_conf.2"); + assert(meshlink_destroy("meshlink_conf.1")); + assert(meshlink_destroy("meshlink_conf.2")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_set_log_cb.c b/test/blackbox/run_blackbox_tests/test_cases_set_log_cb.c index 9a287023..da495584 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_set_log_cb.c +++ b/test/blackbox/run_blackbox_tests/test_cases_set_log_cb.c @@ -80,7 +80,7 @@ static void test_case_set_log_cb_01(void **state) { log callback should be invoked when NUT joins with relay. */ static bool test_set_log_cb_01(void) { - meshlink_destroy("logconf"); + assert(meshlink_destroy("logconf")); // Create meshlink instance for NUT @@ -104,7 +104,7 @@ static bool test_set_log_cb_01(void) { // closing meshes and destroying confbase meshlink_close(mesh); - meshlink_destroy("logconf"); + assert(meshlink_destroy("logconf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_set_port.c b/test/blackbox/run_blackbox_tests/test_cases_set_port.c index ca3a2f38..e514e57f 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_set_port.c +++ b/test/blackbox/run_blackbox_tests/test_cases_set_port.c @@ -95,7 +95,7 @@ static bool test_set_port_01(void) { // Clean up meshlink_close(mesh_handle); - meshlink_destroy("setportconf"); + assert(meshlink_destroy("setportconf")); return true; } @@ -153,7 +153,7 @@ static bool test_set_port_03(void) { // Clean up meshlink_close(mesh_handle); - meshlink_destroy("getportconf"); + assert(meshlink_destroy("getportconf")); return false; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_sign.c b/test/blackbox/run_blackbox_tests/test_cases_sign.c index 75880714..68ae3521 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_sign.c +++ b/test/blackbox/run_blackbox_tests/test_cases_sign.c @@ -119,7 +119,7 @@ static bool test_sign_01(void) { // Clean up meshlink_close(mesh_handle); - meshlink_destroy("signconf"); + assert(meshlink_destroy("signconf")); return ret; } @@ -188,7 +188,7 @@ static bool test_sign_03(void) { // Clean up meshlink_close(mesh_handle); - meshlink_destroy("signconf"); + assert(meshlink_destroy("signconf")); if(!ret) { PRINT_TEST_CASE_MSG("meshlink_sign Successfully reported error on passing NULL as data arg\n"); @@ -234,7 +234,7 @@ static bool test_sign_04(void) { // Clean up meshlink_close(mesh_handle); - meshlink_destroy("signconf"); + assert(meshlink_destroy("signconf")); if(!ret) { PRINT_TEST_CASE_MSG("meshlink_sign Successfully reported error on passing 0 as size of data arg\n"); @@ -279,7 +279,7 @@ static bool test_sign_05(void) { // Clean up meshlink_close(mesh_handle); - meshlink_destroy("signconf"); + assert(meshlink_destroy("signconf")); if(!ret) { PRINT_TEST_CASE_MSG("meshlink_sign Successfully reported error on passing NULL as sign arg\n"); @@ -323,7 +323,7 @@ static bool test_sign_06(void) { // Clean up meshlink_close(mesh_handle); - meshlink_destroy("signconf"); + assert(meshlink_destroy("signconf")); if(!ret) { PRINT_TEST_CASE_MSG("meshlink_sign Successfully reported error on passing NULL as signsize arg\n"); @@ -369,7 +369,7 @@ static bool test_sign_07(void) { meshlink_stop(mesh_handle); meshlink_close(mesh_handle); - meshlink_destroy("signconf"); + assert(meshlink_destroy("signconf")); if(!ret) { PRINT_TEST_CASE_MSG("meshlink_sign Successfully reported error on passing signsize < MESHLINK_SIGLEN arg\n"); diff --git a/test/blackbox/run_blackbox_tests/test_cases_start.c b/test/blackbox/run_blackbox_tests/test_cases_start.c index 7e6a8e8c..be29b330 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_start.c +++ b/test/blackbox/run_blackbox_tests/test_cases_start.c @@ -75,7 +75,7 @@ static bool test_steps_mesh_start_01(void) { // Clean up meshlink_close(mesh); - meshlink_destroy("start_conf"); + assert(meshlink_destroy("start_conf")); if(!result) { fprintf(stderr, "meshlink_start status1: %s\n", meshlink_strerror(meshlink_errno)); @@ -100,7 +100,7 @@ static void test_case_mesh_start_02(void **state) { */ static bool test_steps_mesh_start_02(void) { bool result = false; - meshlink_destroy("start_conf"); + assert(meshlink_destroy("start_conf")); meshlink_handle_t *mesh = meshlink_open("start_conf", "foo", "test", DEV_CLASS_STATIONARY); assert(mesh); @@ -112,7 +112,7 @@ static bool test_steps_mesh_start_02(void) { // Clean up meshlink_close(mesh); - meshlink_destroy("start_conf"); + assert(meshlink_destroy("start_conf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_status_cb.c b/test/blackbox/run_blackbox_tests/test_cases_status_cb.c index f60542b5..fedf3e61 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_status_cb.c +++ b/test/blackbox/run_blackbox_tests/test_cases_status_cb.c @@ -85,8 +85,8 @@ static void test_case_set_status_cb_01(void **state) { status callback should be invoked when NUT connects/disconnects with 'relay' node. */ static bool test_set_status_cb_01(void) { - meshlink_destroy("set_status_cb_conf.1"); - meshlink_destroy("set_status_cb_conf.2"); + assert(meshlink_destroy("set_status_cb_conf.1")); + assert(meshlink_destroy("set_status_cb_conf.2")); // Opening NUT and bar nodes meshlink_handle_t *mesh1 = meshlink_open("set_status_cb_conf.1", "nut", "test", DEV_CLASS_STATIONARY); @@ -104,8 +104,8 @@ static bool test_set_status_cb_01(void) { assert(exp1 != NULL); char *exp2 = meshlink_export(mesh2); assert(exp2 != NULL); - meshlink_import(mesh1, exp2); - meshlink_import(mesh2, exp1); + assert(meshlink_import(mesh1, exp2)); + assert(meshlink_import(mesh2, exp1)); assert(meshlink_start(mesh1)); assert(meshlink_start(mesh2)); @@ -123,8 +123,8 @@ static bool test_set_status_cb_01(void) { free(exp1); free(exp2); meshlink_close(mesh1); - meshlink_destroy("set_status_cb_conf.1"); - meshlink_destroy("set_status_cb_conf.2"); + assert(meshlink_destroy("set_status_cb_conf.1")); + assert(meshlink_destroy("set_status_cb_conf.2")); return true; } @@ -146,7 +146,7 @@ static bool test_set_status_cb_02(void) { // Create meshlink instance - meshlink_destroy("set_status_cb_conf.3"); + assert(meshlink_destroy("set_status_cb_conf.3")); meshlink_handle_t *mesh_handle = meshlink_open("set_status_cb_conf.3", "nut", "node_sim", 1); assert(mesh_handle); @@ -159,7 +159,7 @@ static bool test_set_status_cb_02(void) { // Clean up meshlink_close(mesh_handle); - meshlink_destroy("set_status_cb_conf.3"); + assert(meshlink_destroy("set_status_cb_conf.3")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_cases_verify.c b/test/blackbox/run_blackbox_tests/test_cases_verify.c index 96a27059..f811e169 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_verify.c +++ b/test/blackbox/run_blackbox_tests/test_cases_verify.c @@ -113,7 +113,7 @@ bool test_verify_01(void) { assert(source); ret = meshlink_verify(mesh_handle, source, data, strlen(data) + 1, sig, ssize); meshlink_close(mesh_handle); - meshlink_destroy("verifyconf"); + assert(meshlink_destroy("verifyconf")); if(!ret) { PRINT_TEST_CASE_MSG("meshlink_verify FAILED to verify data\n"); @@ -158,7 +158,7 @@ bool test_verify_02(void) { assert(source != NULL); bool ret = meshlink_verify(NULL, source, data, strlen(data) + 1, sig, ssize); meshlink_close(mesh_handle); - meshlink_destroy("verifyconf"); + assert(meshlink_destroy("verifyconf")); if(!ret) { PRINT_TEST_CASE_MSG("meshlink_sign Successfully reported error on passing NULL as mesh_handle arg\n"); @@ -200,7 +200,7 @@ bool test_verify_03(void) { assert(ret); ret = meshlink_verify(mesh_handle, NULL, data, strlen(data) + 1, sig, ssize); meshlink_close(mesh_handle); - meshlink_destroy("verifyconf"); + assert(meshlink_destroy("verifyconf")); if(!ret) { PRINT_TEST_CASE_MSG("meshlink_verify successfully reported NULL as node_handle arg\n"); @@ -228,7 +228,7 @@ void test_case_verify_04(void **state) { Reports error accordingly by returning false */ bool test_verify_04(void) { - meshlink_destroy("verifyconf"); + assert(meshlink_destroy("verifyconf")); meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); meshlink_handle_t *mesh_handle = meshlink_open("verifyconf", "nut", "node_sim", DEV_CLASS_BACKBONE); assert(mesh_handle); @@ -245,7 +245,7 @@ bool test_verify_04(void) { ret = meshlink_verify(mesh_handle, source, NULL, strlen(data) + 1, sig, ssize); meshlink_stop(mesh_handle); meshlink_close(mesh_handle); - meshlink_destroy("verifyconf"); + assert(meshlink_destroy("verifyconf")); if(!ret) { PRINT_TEST_CASE_MSG("meshlink_verify successfully reported NULL as data arg\n"); @@ -291,7 +291,7 @@ bool test_verify_05(void) { ret = meshlink_verify(mesh_handle, source, data, strlen(data) + 1, NULL, ssize); meshlink_stop(mesh_handle); meshlink_close(mesh_handle); - meshlink_destroy("verifyconf"); + assert(meshlink_destroy("verifyconf")); if(!ret) { PRINT_TEST_CASE_MSG("meshlink_verify successfully NULL as sign arg\n"); @@ -321,8 +321,8 @@ void test_case_verify_06(void **state) { */ bool test_verify_06(void) { /* deleting the confbase if already exists */ - meshlink_destroy("verifyconf1"); - meshlink_destroy("verifyconf2"); + assert(meshlink_destroy("verifyconf1")); + assert(meshlink_destroy("verifyconf2")); /* Set up logging for Meshlink */ meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger); meshlink_handle_t *mesh1 = meshlink_open("verifyconf1", "nut", "chat", DEV_CLASS_STATIONARY); @@ -349,8 +349,8 @@ bool test_verify_06(void) { ret = meshlink_verify(mesh_handle, source_nut, data, strlen(data) + 1, sig, ssize); meshlink_close(mesh1); meshlink_close(mesh2); - meshlink_destroy("verifyconf1"); - meshlink_destroy("verifyconf2"); + assert(meshlink_destroy("verifyconf1")); + assert(meshlink_destroy("verifyconf2")); if(!ret) { PRINT_TEST_CASE_MSG("meshlink_verify successfully returned 'false' when a wrong source node used to verify the data\n"); diff --git a/test/blackbox/run_blackbox_tests/test_cases_whitelist.c b/test/blackbox/run_blackbox_tests/test_cases_whitelist.c index 0a9dd318..68283a96 100644 --- a/test/blackbox/run_blackbox_tests/test_cases_whitelist.c +++ b/test/blackbox/run_blackbox_tests/test_cases_whitelist.c @@ -113,8 +113,8 @@ static bool test_steps_mesh_whitelist_01(void) { // Open two new meshlink instance. - meshlink_destroy("whitelist_conf.1"); - meshlink_destroy("whitelist_conf.2"); + assert(meshlink_destroy("whitelist_conf.1")); + assert(meshlink_destroy("whitelist_conf.2")); meshlink_handle_t *mesh1 = meshlink_open("whitelist_conf.1", "foo", "test", DEV_CLASS_BACKBONE); assert(mesh1); meshlink_set_log_cb(mesh1, MESHLINK_DEBUG, meshlink_callback_logger); @@ -170,7 +170,7 @@ static bool test_steps_mesh_whitelist_01(void) { pthread_mutex_unlock(& lock_receive); - meshlink_blacklist(mesh1, foo); + assert(meshlink_blacklist(mesh1, foo)); rec_stat = false; assert(meshlink_send(mesh1, bar, "test", 5)); @@ -183,7 +183,7 @@ static bool test_steps_mesh_whitelist_01(void) { } pthread_mutex_unlock(& lock_receive); - meshlink_whitelist(mesh1, foo); + assert(meshlink_whitelist(mesh1, foo)); rec_stat = false; bool result = meshlink_send(mesh2, foo, "test", 5); @@ -200,8 +200,8 @@ static bool test_steps_mesh_whitelist_01(void) { meshlink_close(mesh2); meshlink_close(mesh1); - meshlink_destroy("whitelist_conf.1"); - meshlink_destroy("whitelist_conf.2"); + assert(meshlink_destroy("whitelist_conf.1")); + assert(meshlink_destroy("whitelist_conf.2")); return result; } @@ -224,8 +224,8 @@ static bool test_steps_mesh_whitelist_02(void) { // Open two new meshlink instance. - meshlink_destroy("whitelist_conf.3"); - meshlink_destroy("whitelist_conf.4"); + assert(meshlink_destroy("whitelist_conf.3")); + assert(meshlink_destroy("whitelist_conf.4")); meshlink_handle_t *mesh1 = meshlink_open("whitelist_conf.3", "foo", "test", DEV_CLASS_BACKBONE); assert(mesh1); meshlink_handle_t *mesh2 = meshlink_open("whitelist_conf.4", "bar", "test", DEV_CLASS_BACKBONE); @@ -266,19 +266,19 @@ static bool test_steps_mesh_whitelist_02(void) { assert(meshlink_send(mesh1, bar, "test", 5)); - meshlink_blacklist(mesh1, foo); + assert(meshlink_blacklist(mesh1, foo)); // Passing NULL as mesh handle but with valid node handle 'foo' - meshlink_whitelist(NULL, foo); + assert(!meshlink_whitelist(NULL, foo)); assert_int_equal(meshlink_errno, MESHLINK_EINVAL); // Clean up. meshlink_close(mesh2); meshlink_close(mesh1); - meshlink_destroy("whitelist_conf.3"); - meshlink_destroy("whitelist_conf.4"); + assert(meshlink_destroy("whitelist_conf.3")); + assert(meshlink_destroy("whitelist_conf.4")); return true; } @@ -299,20 +299,20 @@ static void test_case_mesh_whitelist_03(void **state) { static bool test_steps_mesh_whitelist_03(void) { // Open meshlink instance. - meshlink_destroy("whitelist_conf"); + assert(meshlink_destroy("whitelist_conf")); meshlink_handle_t *mesh = meshlink_open("whitelist_conf", "foo", "test", DEV_CLASS_BACKBONE); assert(mesh); // Start instance assert(meshlink_start(mesh)); - meshlink_whitelist(mesh, NULL); + assert(!meshlink_whitelist(mesh, NULL)); assert_int_equal(meshlink_errno, MESHLINK_EINVAL); // Clean up. meshlink_close(mesh); - meshlink_destroy("whitelist_conf"); + assert(meshlink_destroy("whitelist_conf")); return true; } diff --git a/test/blackbox/run_blackbox_tests/test_optimal_pmtu.c b/test/blackbox/run_blackbox_tests/test_optimal_pmtu.c index d7463e76..1d740895 100644 --- a/test/blackbox/run_blackbox_tests/test_optimal_pmtu.c +++ b/test/blackbox/run_blackbox_tests/test_optimal_pmtu.c @@ -77,9 +77,9 @@ static int setup_test(void **state) { ping_channel_enable_07 = false; memset(node_pmtu, 0, sizeof(node_pmtu)); set_sync_flag(&test_pmtu_nut_closed, false); - meshlink_destroy("nut"); - meshlink_destroy("peer"); - meshlink_destroy("relay"); + assert(meshlink_destroy("nut")); + assert(meshlink_destroy("peer")); + assert(meshlink_destroy("relay")); return EXIT_SUCCESS; } @@ -87,9 +87,9 @@ static int setup_test(void **state) { static int teardown_test(void **state) { (void)state; - meshlink_destroy("nut"); - meshlink_destroy("peer"); - meshlink_destroy("relay"); + assert(meshlink_destroy("nut")); + assert(meshlink_destroy("peer")); + assert(meshlink_destroy("relay")); netns_destroy_topology(test_pmtu_state); return EXIT_SUCCESS; diff --git a/test/blackbox/test_case_channel_blacklist_01/node_sim_nut_01.c b/test/blackbox/test_case_channel_blacklist_01/node_sim_nut_01.c index 7c173405..9e04a8bb 100644 --- a/test/blackbox/test_case_channel_blacklist_01/node_sim_nut_01.c +++ b/test/blackbox/test_case_channel_blacklist_01/node_sim_nut_01.c @@ -179,7 +179,7 @@ void *test_channel_blacklist_disonnection_nut_01(void *arg) { fprintf(stderr, "Node blacklisted\n"); set_sync_flag(&channels_closed, false); - meshlink_blacklist(mesh, peer_node); + assert(meshlink_blacklist(mesh, peer_node)); sleep(10); @@ -209,7 +209,7 @@ void *test_channel_blacklist_disonnection_nut_01(void *arg) { set_sync_flag(&peer_reachable, false); - meshlink_whitelist(mesh, peer_node); + assert(meshlink_whitelist(mesh, peer_node)); fprintf(stderr, "Node whitelisted\n"); wait_sync_flag(&peer_reachable, 70); diff --git a/test/blackbox/test_case_channel_blacklist_01/node_sim_relay_01.c b/test/blackbox/test_case_channel_blacklist_01/node_sim_relay_01.c index 43e2a7f5..a6c293ad 100644 --- a/test/blackbox/test_case_channel_blacklist_01/node_sim_relay_01.c +++ b/test/blackbox/test_case_channel_blacklist_01/node_sim_relay_01.c @@ -36,7 +36,7 @@ void *test_channel_blacklist_disonnection_relay_01(void *arg) { mesh = meshlink_open(mesh_arg->node_name, mesh_arg->confbase, mesh_arg->app_name, mesh_arg->dev_class); assert(mesh); - meshlink_start(mesh); + assert(meshlink_start(mesh)); /* All test steps executed - wait for signals to stop/start or close the mesh */ while(test_channel_blacklist_disonnection_relay_01_running) { diff --git a/test/blackbox/test_case_channel_conn_04/node_sim_nut.c b/test/blackbox/test_case_channel_conn_04/node_sim_nut.c index 52646399..9579f012 100644 --- a/test/blackbox/test_case_channel_conn_04/node_sim_nut.c +++ b/test/blackbox/test_case_channel_conn_04/node_sim_nut.c @@ -152,7 +152,7 @@ int main(int argc, char *argv[]) { // Restarting the node instance meshlink_stop(mesh); - meshlink_start(mesh); + assert(meshlink_start(mesh)); assert(wait_sync_flag(&peer_reachable, 60)); send_event(NODE_RESTARTED); diff --git a/test/blackbox/test_case_channel_conn_05/node_sim_relay.c b/test/blackbox/test_case_channel_conn_05/node_sim_relay.c index c4fd1e4c..8e5e66ec 100644 --- a/test/blackbox/test_case_channel_conn_05/node_sim_relay.c +++ b/test/blackbox/test_case_channel_conn_05/node_sim_relay.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) { assert(mesh); meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_start(mesh); + assert(meshlink_start(mesh)); /* All test steps executed - wait for signals to stop/start or close the mesh */ while(test_running) { diff --git a/test/blackbox/test_case_channel_conn_06/node_sim_relay.c b/test/blackbox/test_case_channel_conn_06/node_sim_relay.c index c4fd1e4c..8e5e66ec 100644 --- a/test/blackbox/test_case_channel_conn_06/node_sim_relay.c +++ b/test/blackbox/test_case_channel_conn_06/node_sim_relay.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) { assert(mesh); meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_start(mesh); + assert(meshlink_start(mesh)); /* All test steps executed - wait for signals to stop/start or close the mesh */ while(test_running) { diff --git a/test/blackbox/test_case_channel_conn_07/node_sim_relay.c b/test/blackbox/test_case_channel_conn_07/node_sim_relay.c index c4fd1e4c..8e5e66ec 100644 --- a/test/blackbox/test_case_channel_conn_07/node_sim_relay.c +++ b/test/blackbox/test_case_channel_conn_07/node_sim_relay.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) { assert(mesh); meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_start(mesh); + assert(meshlink_start(mesh)); /* All test steps executed - wait for signals to stop/start or close the mesh */ while(test_running) { diff --git a/test/blackbox/test_case_channel_conn_08/node_sim_nut.c b/test/blackbox/test_case_channel_conn_08/node_sim_nut.c index 52646399..9579f012 100644 --- a/test/blackbox/test_case_channel_conn_08/node_sim_nut.c +++ b/test/blackbox/test_case_channel_conn_08/node_sim_nut.c @@ -152,7 +152,7 @@ int main(int argc, char *argv[]) { // Restarting the node instance meshlink_stop(mesh); - meshlink_start(mesh); + assert(meshlink_start(mesh)); assert(wait_sync_flag(&peer_reachable, 60)); send_event(NODE_RESTARTED); diff --git a/test/blackbox/test_case_channel_conn_08/node_sim_relay.c b/test/blackbox/test_case_channel_conn_08/node_sim_relay.c index c4fd1e4c..8e5e66ec 100644 --- a/test/blackbox/test_case_channel_conn_08/node_sim_relay.c +++ b/test/blackbox/test_case_channel_conn_08/node_sim_relay.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) { assert(mesh); meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); - meshlink_start(mesh); + assert(meshlink_start(mesh)); /* All test steps executed - wait for signals to stop/start or close the mesh */ while(test_running) { diff --git a/test/blackbox/test_case_meta_conn_01/node_sim_nut.c b/test/blackbox/test_case_meta_conn_01/node_sim_nut.c index 77ff2b80..5cf624f2 100644 --- a/test/blackbox/test_case_meta_conn_01/node_sim_nut.c +++ b/test/blackbox/test_case_meta_conn_01/node_sim_nut.c @@ -128,6 +128,6 @@ int main(int argc, char *argv[]) { assert(mesh_event_sock_send(client_id, META_RECONN_SUCCESSFUL, NULL, 0)); execute_close(); - meshlink_destroy(argv[1]); + assert(meshlink_destroy(argv[1])); return 0; } diff --git a/test/blackbox/test_case_meta_conn_01/node_sim_peer.c b/test/blackbox/test_case_meta_conn_01/node_sim_peer.c index 8b242038..5dd8807e 100644 --- a/test/blackbox/test_case_meta_conn_01/node_sim_peer.c +++ b/test/blackbox/test_case_meta_conn_01/node_sim_peer.c @@ -60,5 +60,5 @@ int main(int argc, char *argv[]) { } execute_close(); - meshlink_destroy(argv[1]); + assert(meshlink_destroy(argv[1])); } diff --git a/test/blackbox/test_case_meta_conn_01/node_sim_relay.c b/test/blackbox/test_case_meta_conn_01/node_sim_relay.c index 3c6c548c..cde644c8 100644 --- a/test/blackbox/test_case_meta_conn_01/node_sim_relay.c +++ b/test/blackbox/test_case_meta_conn_01/node_sim_relay.c @@ -56,5 +56,5 @@ int main(int argc, char *argv[]) { } execute_close(); - meshlink_destroy(argv[1]); + assert(meshlink_destroy(argv[1])); } diff --git a/test/blackbox/test_case_meta_conn_02/node_sim_nut.c b/test/blackbox/test_case_meta_conn_02/node_sim_nut.c index d56124dd..c197c58c 100644 --- a/test/blackbox/test_case_meta_conn_02/node_sim_nut.c +++ b/test/blackbox/test_case_meta_conn_02/node_sim_nut.c @@ -112,7 +112,7 @@ int main(int argc, char *argv[]) { assert(mesh_event_sock_send(client_id, META_CONN_SUCCESSFUL, NULL, 0)); execute_close(); - meshlink_destroy(argv[1]); + assert(meshlink_destroy(argv[1])); return 0; } diff --git a/test/blackbox/test_case_meta_conn_02/node_sim_peer.c b/test/blackbox/test_case_meta_conn_02/node_sim_peer.c index 429ca333..91ac601e 100644 --- a/test/blackbox/test_case_meta_conn_02/node_sim_peer.c +++ b/test/blackbox/test_case_meta_conn_02/node_sim_peer.c @@ -66,5 +66,5 @@ int main(int argc, char *argv[]) { } execute_close(); - meshlink_destroy(argv[1]); + assert(meshlink_destroy(argv[1])); } diff --git a/test/blackbox/test_case_meta_conn_02/node_sim_relay.c b/test/blackbox/test_case_meta_conn_02/node_sim_relay.c index 20fd8373..57ea254d 100644 --- a/test/blackbox/test_case_meta_conn_02/node_sim_relay.c +++ b/test/blackbox/test_case_meta_conn_02/node_sim_relay.c @@ -62,5 +62,5 @@ int main(int argc, char *argv[]) { } execute_close(); - meshlink_destroy(argv[1]); + assert(meshlink_destroy(argv[1])); } diff --git a/test/blackbox/test_case_meta_conn_03/node_sim_nut.c b/test/blackbox/test_case_meta_conn_03/node_sim_nut.c index cdffb6ea..4038d246 100644 --- a/test/blackbox/test_case_meta_conn_03/node_sim_nut.c +++ b/test/blackbox/test_case_meta_conn_03/node_sim_nut.c @@ -125,7 +125,7 @@ int main(int argc, char *argv[]) { } execute_close(); - meshlink_destroy(argv[1]); + assert(meshlink_destroy(argv[1])); return 0; } diff --git a/test/blackbox/test_case_meta_conn_03/node_sim_peer.c b/test/blackbox/test_case_meta_conn_03/node_sim_peer.c index 429ca333..91ac601e 100644 --- a/test/blackbox/test_case_meta_conn_03/node_sim_peer.c +++ b/test/blackbox/test_case_meta_conn_03/node_sim_peer.c @@ -66,5 +66,5 @@ int main(int argc, char *argv[]) { } execute_close(); - meshlink_destroy(argv[1]); + assert(meshlink_destroy(argv[1])); } diff --git a/test/blackbox/test_case_meta_conn_03/node_sim_relay.c b/test/blackbox/test_case_meta_conn_03/node_sim_relay.c index f24037d9..a6f91772 100644 --- a/test/blackbox/test_case_meta_conn_03/node_sim_relay.c +++ b/test/blackbox/test_case_meta_conn_03/node_sim_relay.c @@ -62,5 +62,5 @@ int main(int argc, char *argv[]) { } execute_close(); - meshlink_destroy(argv[1]); + assert(meshlink_destroy(argv[1])); } diff --git a/test/blackbox/test_case_meta_conn_04/node_sim_nut.c b/test/blackbox/test_case_meta_conn_04/node_sim_nut.c index e16dee39..e2085720 100644 --- a/test/blackbox/test_case_meta_conn_04/node_sim_nut.c +++ b/test/blackbox/test_case_meta_conn_04/node_sim_nut.c @@ -126,5 +126,5 @@ int main(int argc, char *argv[]) { } execute_close(); - meshlink_destroy(argv[1]); + assert(meshlink_destroy(argv[1])); } diff --git a/test/blackbox/test_case_meta_conn_04/node_sim_peer.c b/test/blackbox/test_case_meta_conn_04/node_sim_peer.c index ef0cfcbb..b003e061 100644 --- a/test/blackbox/test_case_meta_conn_04/node_sim_peer.c +++ b/test/blackbox/test_case_meta_conn_04/node_sim_peer.c @@ -66,5 +66,5 @@ int main(int argc, char *argv[]) { } execute_close(); - meshlink_destroy(argv[1]); + assert(meshlink_destroy(argv[1])); } diff --git a/test/blackbox/test_case_meta_conn_04/node_sim_relay.c b/test/blackbox/test_case_meta_conn_04/node_sim_relay.c index 3e4299dc..37bb11d6 100644 --- a/test/blackbox/test_case_meta_conn_04/node_sim_relay.c +++ b/test/blackbox/test_case_meta_conn_04/node_sim_relay.c @@ -59,5 +59,5 @@ int main(int argc, char *argv[]) { } execute_close(); - meshlink_destroy(argv[1]); + assert(meshlink_destroy(argv[1])); } diff --git a/test/blackbox/test_case_meta_conn_05/node_sim_nut.c b/test/blackbox/test_case_meta_conn_05/node_sim_nut.c index b6d90c93..1581cebb 100644 --- a/test/blackbox/test_case_meta_conn_05/node_sim_nut.c +++ b/test/blackbox/test_case_meta_conn_05/node_sim_nut.c @@ -143,5 +143,5 @@ int main(int argc, char *argv[]) { } execute_close(); - meshlink_destroy(argv[1]); + assert(meshlink_destroy(argv[1])); } diff --git a/test/blackbox/test_case_meta_conn_05/node_sim_peer.c b/test/blackbox/test_case_meta_conn_05/node_sim_peer.c index 429ca333..91ac601e 100644 --- a/test/blackbox/test_case_meta_conn_05/node_sim_peer.c +++ b/test/blackbox/test_case_meta_conn_05/node_sim_peer.c @@ -66,5 +66,5 @@ int main(int argc, char *argv[]) { } execute_close(); - meshlink_destroy(argv[1]); + assert(meshlink_destroy(argv[1])); } diff --git a/test/blackbox/test_case_meta_conn_05/node_sim_relay.c b/test/blackbox/test_case_meta_conn_05/node_sim_relay.c index 3e4299dc..37bb11d6 100644 --- a/test/blackbox/test_case_meta_conn_05/node_sim_relay.c +++ b/test/blackbox/test_case_meta_conn_05/node_sim_relay.c @@ -59,5 +59,5 @@ int main(int argc, char *argv[]) { } execute_close(); - meshlink_destroy(argv[1]); + assert(meshlink_destroy(argv[1])); } diff --git a/test/blackbox/test_case_optimal_pmtu_01/node_sim_nut.c b/test/blackbox/test_case_optimal_pmtu_01/node_sim_nut.c index 936720b2..6e745b75 100644 --- a/test/blackbox/test_case_optimal_pmtu_01/node_sim_nut.c +++ b/test/blackbox/test_case_optimal_pmtu_01/node_sim_nut.c @@ -286,7 +286,7 @@ void *node_sim_pmtu_nut_01(void *arg) { if(time_stamp >= send_time) { send_time = time_stamp + 10; - meshlink_channel_send(mesh, channel, "ping", 5); + assert(meshlink_channel_send(mesh, channel, "ping", 5) == 5); } } } diff --git a/test/blackbox/test_case_optimal_pmtu_01/node_sim_relay.c b/test/blackbox/test_case_optimal_pmtu_01/node_sim_relay.c index 0eff6da6..7823f4b9 100644 --- a/test/blackbox/test_case_optimal_pmtu_01/node_sim_relay.c +++ b/test/blackbox/test_case_optimal_pmtu_01/node_sim_relay.c @@ -50,7 +50,7 @@ void *node_sim_pmtu_relay_01(void *arg) { //meshlink_set_log_cb(mesh, MESHLINK_DEBUG, meshlink_callback_logger); meshlink_enable_discovery(mesh, false); - meshlink_start(mesh); + assert(meshlink_start(mesh)); //send_event(NODE_STARTED); /* All test steps executed - wait for signals to stop/start or close the mesh */ diff --git a/test/blackbox/test_cases_submesh04/node_sim_app1node2.c b/test/blackbox/test_cases_submesh04/node_sim_app1node2.c index 0b30963d..8e47d7e3 100644 --- a/test/blackbox/test_cases_submesh04/node_sim_app1node2.c +++ b/test/blackbox/test_cases_submesh04/node_sim_app1node2.c @@ -263,11 +263,11 @@ int main(int argc, char *argv[]) { } channel_data_recieved.flag = false; - meshlink_blacklist(mesh, app1_node1); + assert(meshlink_blacklist(mesh, app1_node1)); sleep(2); - meshlink_channel_send(mesh, ch_app1node1, "test", 5); + assert(meshlink_channel_send(mesh, ch_app1node1, "test", 5) == 5); wait_sync_flag(&channel_data_recieved, 30); @@ -277,11 +277,11 @@ int main(int argc, char *argv[]) { } channel_data_recieved.flag = false; - meshlink_whitelist(mesh, app1_node1); + assert(meshlink_whitelist(mesh, app1_node1)); sleep(2); - meshlink_channel_send(mesh, ch_app1node1, "Channel Message", strlen("Channel Message")); + assert(meshlink_channel_send(mesh, ch_app1node1, "Channel Message", strlen("Channel Message")) == strlen("Channel Message")); assert(wait_sync_flag(&channel_data_recieved, 60)); diff --git a/test/channels-cornercases.c b/test/channels-cornercases.c index 369ac4ee..d4644a42 100644 --- a/test/channels-cornercases.c +++ b/test/channels-cornercases.c @@ -34,7 +34,7 @@ static void a_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, c static void b_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) { // Send one message back, then close the channel. if(len) { - meshlink_channel_send(mesh, channel, data, len); + assert(meshlink_channel_send(mesh, channel, data, len) == (ssize_t)len); } meshlink_channel_close(mesh, channel); @@ -138,8 +138,7 @@ int main() { struct sync_flag channel_closed = {.flag = false}; channel->priv = &channel_closed; - meshlink_channel_send(a, channel, "Hello", 5); - + assert(meshlink_channel_send(a, channel, "Hello", 5) == 5); assert(wait_sync_flag(&channel_closed, 20)); assert(b_responded); assert(b_closed); diff --git a/test/channels-fork.c b/test/channels-fork.c index 8a2ddd80..9168168c 100644 --- a/test/channels-fork.c +++ b/test/channels-fork.c @@ -45,7 +45,7 @@ static void bar_status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool r static void bar_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) { // Echo the data back. if(len) { - meshlink_channel_send(mesh, channel, data, len); + assert(meshlink_channel_send(mesh, channel, data, len) == (ssize_t)len); } else { meshlink_channel_close(mesh, channel); } @@ -96,7 +96,7 @@ static int main1(int rfd, int wfd) { meshlink_enable_discovery(mesh, false); - meshlink_add_address(mesh, "localhost"); + assert(meshlink_add_address(mesh, "localhost")); char *data = meshlink_export(mesh); assert(data); @@ -152,7 +152,7 @@ static int main2(int rfd, int wfd) { meshlink_enable_discovery(mesh, false); - meshlink_add_address(mesh, "localhost"); + assert(meshlink_add_address(mesh, "localhost")); char *data = meshlink_export(mesh); assert(data); diff --git a/test/channels-no-partial.c b/test/channels-no-partial.c index bcf8cec1..c765456a 100644 --- a/test/channels-no-partial.c +++ b/test/channels-no-partial.c @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) { // Restart a to ensure it gets to flush the channel send queue. - meshlink_start(mesh_a); + assert(meshlink_start(mesh_a)); assert_after(!meshlink_channel_get_sendq(mesh_a, channel), 30); assert(meshlink_channel_send(mesh_a, channel, buf, 512) == 512); diff --git a/test/channels.c b/test/channels.c index 5dd4f428..5424ae66 100644 --- a/test/channels.c +++ b/test/channels.c @@ -32,7 +32,7 @@ static void b_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, c fwrite(data, 1, len, stdout); printf("\n"); // Echo the data back. - meshlink_channel_send(mesh, channel, data, len); + assert(meshlink_channel_send(mesh, channel, data, len) == (ssize_t)len); } static bool reject_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) { diff --git a/test/duplicate.c b/test/duplicate.c index 28155711..db2ce72a 100644 --- a/test/duplicate.c +++ b/test/duplicate.c @@ -15,7 +15,7 @@ static struct sync_flag duplicate_detected; static void handle_duplicate(meshlink_handle_t *mesh, meshlink_node_t *node) { set_sync_flag(&duplicate_detected, true); - meshlink_blacklist(mesh, node); + assert(meshlink_blacklist(mesh, node)); } int main() { @@ -34,7 +34,7 @@ int main() { mesh[i] = meshlink_open(dirname, name[i], "duplicate", DEV_CLASS_BACKBONE); assert(mesh[i]); - meshlink_add_address(mesh[i], "localhost"); + assert(meshlink_add_address(mesh[i], "localhost")); meshlink_enable_discovery(mesh[i], false); meshlink_set_node_duplicate_cb(mesh[i], handle_duplicate); diff --git a/test/import-export.c b/test/import-export.c index 133cbcbe..8bc41c1b 100644 --- a/test/import-export.c +++ b/test/import-export.c @@ -43,8 +43,8 @@ int main() { // Import and export both side's data - meshlink_add_address(mesh1, "localhost"); - meshlink_add_address(mesh2, "localhost"); + assert(meshlink_add_address(mesh1, "localhost")); + assert(meshlink_add_address(mesh2, "localhost")); char *data = meshlink_export(mesh1); assert(data); diff --git a/test/invite-join.c b/test/invite-join.c index 49b5981b..1dd6c26d 100644 --- a/test/invite-join.c +++ b/test/invite-join.c @@ -50,7 +50,7 @@ int main() { meshlink_set_node_status_cb(mesh1, status_cb); - meshlink_add_address(mesh1, "localhost"); + assert(meshlink_add_address(mesh1, "localhost")); char *baz_url = meshlink_invite(mesh1, NULL, "baz"); assert(baz_url); diff --git a/test/trio.c b/test/trio.c index 9fa7de33..a183b3da 100644 --- a/test/trio.c +++ b/test/trio.c @@ -65,7 +65,7 @@ int main() { assert(mesh[i]); free(path); - meshlink_add_address(mesh[i], "localhost"); + assert(meshlink_add_address(mesh[i], "localhost")); data[i] = meshlink_export(mesh[i]); assert(data[i]); diff --git a/test/trio2.c b/test/trio2.c index 283b280a..57312988 100644 --- a/test/trio2.c +++ b/test/trio2.c @@ -65,7 +65,7 @@ int main() { assert(mesh[i]); free(path); - meshlink_add_address(mesh[i], "localhost"); + assert(meshlink_add_address(mesh[i], "localhost")); data[i] = meshlink_export(mesh[i]); assert(data[i]); diff --git a/test/utils.c b/test/utils.c index c11894b7..28e3d62f 100644 --- a/test/utils.c +++ b/test/utils.c @@ -49,8 +49,8 @@ bool wait_sync_flag(struct sync_flag *s, int seconds) { void link_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b) { // Import and export both side's data - meshlink_add_address(a, "localhost"); - meshlink_add_address(b, "localhost"); + assert(meshlink_add_address(a, "localhost")); + assert(meshlink_add_address(b, "localhost")); char *data = meshlink_export(a); assert(data); -- 2.39.5