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")) {
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")) {
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")) {
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")) {
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")) {
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")) {
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);
}
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")) {
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")) {
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);
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);
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],
// 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;
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
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
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);
#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
#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
* 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.
}
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);
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);
}
}
}
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) {
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);
}
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);
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.
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);
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) {
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?
* 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().
* @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.
*
* @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.
*
* @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.
* @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.
* @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.
* @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.
* @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
* @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
*
* @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,
*
* @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.
* @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().
* @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.
* @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.
* 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.
* 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.
* @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.
* 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.
*
* @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.
* 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.
* 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.
*
* @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.
*
* @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.
*
* @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.
*
* @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.
*
* @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
* 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
* 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.
* 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:
*
* @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.
*
* @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.
* 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.
* @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.
* @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.
*
* @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.
* @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.
*
* @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.
* \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.
* \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.
* @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.
* @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.
* 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.
*
* @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.
*
* @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.
*
* @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.
*
* @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.
*
* @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.
*
* @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.
*
* @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.
*
* @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.
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) {
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);
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
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;
}
}
/*
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)
});
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;
}
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);
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) {
n->recent[i + known_count] = packmsg_get_sockaddr(&in);
}
-
config_free(&config);
return true;
}
}
if(!packmsg_output_ok(&out)) {
+ meshlink_errno = MESHLINK_EINTERNAL;
return false;
}
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 */
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;
retry_outgoing(mesh, outgoing);
}
- return false;
+ return;
}
connection_t *c = new_connection();
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) {
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
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
* \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);
* 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;
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 */
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) {
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);
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;
}
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;
}
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
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
#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
#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
*/
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);
// Clean up
meshlink_close(mesh);
- meshlink_destroy("add_conf.1");
+ assert(meshlink_destroy("add_conf.1"));
return true;
}
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);
assert_int_equal(result, false);
meshlink_close(mesh);
- meshlink_destroy("add_conf.3");
+ assert(meshlink_destroy("add_conf.3"));
return true;
}
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);
assert_int_equal(found, true);
meshlink_close(mesh);
- meshlink_destroy("addex_conf.1");
+ assert(meshlink_destroy("addex_conf.1"));
return true;
}
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);
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));
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;
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);
sleep(1);
assert(received);
- meshlink_blacklist(mesh1, bar);
+ assert(meshlink_blacklist(mesh1, bar));
received = false;
assert(meshlink_send(mesh2, foo, "test", 5));
// 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;
}
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);
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;
}
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;
}
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;
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;
/* 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);
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;
}
/* 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);
// Clean up.
meshlink_close(mesh);
- meshlink_destroy("chan_close_conf.5");
+ assert(meshlink_destroy("chan_close_conf.5"));
return true;
}
assert_int_equal(ret, true);
meshlink_close(mesh_handle);
- meshlink_destroy("channelexconf");
+ assert(meshlink_destroy("channelexconf"));
return true;
}
assert_int_equal(ret, true);
meshlink_close(mesh_handle);
- meshlink_destroy("channelexconf");
+ assert(meshlink_destroy("channelexconf"));
return true;
}
assert_int_equal(ret, true);
meshlink_close(mesh_handle);
- meshlink_destroy("channelexconf");
+ assert(meshlink_destroy("channelexconf"));
return true;
}
assert_int_equal(ret, true);
meshlink_close(mesh_handle);
- meshlink_destroy("channelexconf");
+ assert(meshlink_destroy("channelexconf"));
return true;
}
assert(channel == NULL);
meshlink_close(mesh_handle);
- meshlink_destroy("channelexconf");
+ assert(meshlink_destroy("channelexconf"));
return true;
}
assert_int_equal(channel, NULL);
meshlink_close(mesh_handle);
- meshlink_destroy("channelexconf");
+ assert(meshlink_destroy("channelexconf"));
return true;
}
assert_int_equal(flags, MESHLINK_CHANNEL_TCP);
meshlink_close(mesh_handle);
- meshlink_destroy("getflagsconf");
+ assert(meshlink_destroy("getflagsconf"));
return true;
}
assert_int_equal(meshlink_errno, MESHLINK_EINVAL);
meshlink_close(mesh_handle);
- meshlink_destroy("getflagsconf");
+ assert(meshlink_destroy("getflagsconf"));
return true;
}
assert_int_equal(meshlink_errno, MESHLINK_EINVAL);
meshlink_close(mesh_handle);
- meshlink_destroy("getflagsconf");
+ assert(meshlink_destroy("getflagsconf"));
return true;
}
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);
// 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;
}
/* 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);
// 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;
}
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);
// Clean up.
meshlink_close(mesh);
- meshlink_destroy("channels_conf.5");
+ assert(meshlink_destroy("channels_conf.5"));
return true;
}
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);
// Clean up.
meshlink_close(mesh);
- meshlink_destroy("channels_conf.7");
+ assert(meshlink_destroy("channels_conf.7"));
return true;
}
/* 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);
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;
}
/* 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.
// Clean up.
meshlink_close(mesh1);
- meshlink_destroy("chan_send_conf.5");
+ assert(meshlink_destroy("chan_send_conf.5"));
return true;
}
/* 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);
// Clean up.
meshlink_close(mesh1);
- meshlink_destroy("chan_send_conf.7");
+ assert(meshlink_destroy("chan_send_conf.7"));
return true;
}
/* 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);
// Clean up.
meshlink_close(mesh1);
- meshlink_destroy("chan_send_conf.9");
+ assert(meshlink_destroy("chan_send_conf.9"));
return true;
}
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 */
/* 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;
}
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 */
/* 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;
}
assert_int_not_equal(meshlink_errno, 0);
meshlink_close(mesh_handle);
- meshlink_destroy("channelpollconf3");
+ assert(meshlink_destroy("channelpollconf3"));
return true;
}
assert_int_equal(meshlink_errno, MESHLINK_EINVAL);
meshlink_close(mesh_handle);
- meshlink_destroy("channelpollconf4");
+ assert(meshlink_destroy("channelpollconf4"));
return true;
}
*/
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 */
pthread_mutex_unlock(& lock_receive);
meshlink_close(mesh_handle);
- meshlink_destroy("channelreceiveconf");
+ assert(meshlink_destroy("channelreceiveconf"));
return true;
}
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 */
assert_int_equal(meshlink_errno, MESHLINK_EINVAL);
meshlink_close(mesh_handle);
- meshlink_destroy("channelreceiveconf");
+ assert(meshlink_destroy("channelreceiveconf"));
return true;
}
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 */
assert_int_equal(meshlink_errno, MESHLINK_EINVAL);
meshlink_close(mesh_handle);
- meshlink_destroy("channelreceiveconf");
+ assert(meshlink_destroy("channelreceiveconf"));
return true;
}
*/
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);
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;
}
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 */
assert_int_equal(meshlink_errno, MESHLINK_EINVAL);
meshlink_close(mesh_handle);
- meshlink_destroy("channelshutdownconf.3");
+ assert(meshlink_destroy("channelshutdownconf.3"));
return true;
}
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 */
assert_int_equal(meshlink_errno, MESHLINK_EINVAL);
meshlink_close(mesh_handle);
- meshlink_destroy("channelshutdownconf.4");
+ assert(meshlink_destroy("channelshutdownconf.4"));
return true;
}
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);
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;
}
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 */
assert_int_not_equal(expo, NULL);
meshlink_close(mesh_handle);
- meshlink_destroy("exportconf");
+ assert(meshlink_destroy("exportconf"));
return true;
}
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 */
meshlink_close(mesh1);
meshlink_close(mesh2);
- meshlink_destroy("getnodeconf1");
- meshlink_destroy("getnodeconf2");
+ assert(meshlink_destroy("getnodeconf1"));
+ assert(meshlink_destroy("getnodeconf2"));
return true;
}
assert_int_equal(nodes, NULL);
meshlink_close(mesh_handle);
- meshlink_destroy("getallnodesconf");
+ assert(meshlink_destroy("getallnodesconf"));
return true;
}
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);
assert_int_not_equal(meshlink_errno, 0);
meshlink_close(mesh_nut);
- meshlink_destroy("getnodeconf.1");
+ assert(meshlink_destroy("getnodeconf.1"));
return true;
}
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);
assert_int_equal(dev_class, DEV_CLASS_STATIONARY);
meshlink_close(mesh_nut);
- meshlink_destroy("getnodeconf.1");
+ assert(meshlink_destroy("getnodeconf.1"));
return true;
}
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);
assert_int_not_equal(meshlink_errno, 0);
meshlink_close(mesh_nut);
- meshlink_destroy("getnodeconf.1");
+ assert(meshlink_destroy("getnodeconf.1"));
return true;
}
(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;
free(addr);
meshlink_close(mesh);
- meshlink_destroy("getex_conf");
+ assert(meshlink_destroy("getex_conf"));
return true;
}
free(addr);
meshlink_close(mesh);
- meshlink_destroy("getex_conf");
+ assert(meshlink_destroy("getex_conf"));
return true;
}
assert_int_not_equal(fp, NULL);
meshlink_close(mesh_handle);
- meshlink_destroy("getfingerprintconf");
+ assert(meshlink_destroy("getfingerprintconf"));
return true;
}
assert_int_equal(fp, NULL);
meshlink_close(mesh_handle);
- meshlink_destroy("getfingerprintconf");
+ assert(meshlink_destroy("getfingerprintconf"));
return true;
}
assert_int_equal(fp, NULL);
meshlink_close(mesh_handle);
- meshlink_destroy("getfingerprintconf");
+ assert(meshlink_destroy("getfingerprintconf"));
return true;
}
*/
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);
// Cleanup
meshlink_close(mesh1);
meshlink_close(mesh2);
- meshlink_destroy("getnode1");
- meshlink_destroy("getnode2");
+ assert(meshlink_destroy("getnode1"));
+ assert(meshlink_destroy("getnode2"));
return true;
}
assert_int_equal(get_node, NULL);
meshlink_close(mesh);
- meshlink_destroy("node_conf.3");
+ assert(meshlink_destroy("node_conf.3"));
return true;
}
assert_int_equal(get_node, NULL);
meshlink_close(mesh);
- meshlink_destroy("node_conf");
+ assert(meshlink_destroy("node_conf"));
return true;
}
assert_int_not_equal(port, -1);
meshlink_close(mesh);
- meshlink_destroy("port_conf");
+ assert(meshlink_destroy("port_conf"));
return true;
}
}
meshlink_close(mesh);
- meshlink_destroy("self_conf");
+ assert(meshlink_destroy("self_conf"));
return true;
}
}
/* 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
free(buff);
meshlink_close(mesh1);
meshlink_close(mesh2);
- meshlink_destroy("hintconf1");
- meshlink_destroy("hintconf2");
+ assert(meshlink_destroy("hintconf1"));
+ assert(meshlink_destroy("hintconf2"));
return true;
}
*/
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);
meshlink_close(mesh1);
meshlink_close(mesh2);
- meshlink_destroy("importconf1");
- meshlink_destroy("importconf2");
+ assert(meshlink_destroy("importconf1"));
+ assert(meshlink_destroy("importconf2"));
return imp1 && imp2;
}
*/
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);
meshlink_close(mesh1);
meshlink_close(mesh2);
- meshlink_destroy("importconf1");
- meshlink_destroy("importconf2");
+ assert(meshlink_destroy("importconf1"));
+ assert(meshlink_destroy("importconf2"));
return true;
}
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);
meshlink_close(mesh1);
meshlink_close(mesh2);
- meshlink_destroy("importconf1");
- meshlink_destroy("importconf2");
+ assert(meshlink_destroy("importconf1"));
+ assert(meshlink_destroy("importconf2"));
return true;
}
*/
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);
meshlink_close(mesh1);
meshlink_close(mesh2);
- meshlink_destroy("importconf1");
- meshlink_destroy("importconf2");
+ assert(meshlink_destroy("importconf1"));
+ assert(meshlink_destroy("importconf2"));
return true;
}
*/
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);
meshlink_close(mesh1);
meshlink_close(mesh2);
- meshlink_destroy("importconf1");
- meshlink_destroy("importconf2");
+ assert(meshlink_destroy("importconf1"));
+ assert(meshlink_destroy("importconf2"));
return true;
}
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
free(invitation);
meshlink_close(mesh_handle);
- meshlink_destroy("inviteconf");
+ assert(meshlink_destroy("inviteconf"));
return true;
}
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
assert_int_equal(invitation, NULL);
meshlink_close(mesh_handle);
- meshlink_destroy("inviteconf");
+ assert(meshlink_destroy("inviteconf"));
return true;
}
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
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
assert_int_not_equal(strstr(invitation, hostname2), NULL);
meshlink_close(mesh_handle);
- meshlink_destroy("inviteconf");
+ assert(meshlink_destroy("inviteconf"));
return true;
}
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);
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);
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;
}
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);
free(invitation);
meshlink_close(mesh1);
- meshlink_destroy("join_conf.3");
+ assert(meshlink_destroy("join_conf.3"));
return true;
}
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 */
assert_int_equal(ret, false);
meshlink_close(mesh_handle);
- meshlink_destroy("joinconf.4");
+ assert(meshlink_destroy("joinconf.4"));
return true;
}
*/
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.
// Cleanup
meshlink_close(mesh);
- meshlink_destroy("encrypted_conf");
+ assert(meshlink_destroy("encrypted_conf"));
return true;
}
*/
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.
// Cleanup
meshlink_close(mesh);
- meshlink_destroy("encrypted_conf");
+ assert(meshlink_destroy("encrypted_conf"));
return true;
}
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.
// Cleanup
- meshlink_destroy("encrypted_conf");
+ assert(meshlink_destroy("encrypted_conf"));
return true;
}
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.
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;
}
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);
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);
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);
}
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);
// 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;
}
assert_int_not_equal(mesh, NULL);
meshlink_close(mesh);
- meshlink_destroy("open_conf");
+ assert(meshlink_destroy("open_conf"));
return true;
}
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;
}
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;
}
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;
}
assert_int_not_equal(pmtu, -1);
meshlink_close(mesh);
- meshlink_destroy("pmtu_conf");
+ assert(meshlink_destroy("pmtu_conf"));
return true;
}
assert_int_equal(pmtu, -1);
meshlink_close(mesh);
- meshlink_destroy("pmtu_conf");
+ assert(meshlink_destroy("pmtu_conf"));
return true;
}
assert_int_equal(pmtu, -1);
meshlink_close(mesh);
- meshlink_destroy("pmtu_conf");
+ assert(meshlink_destroy("pmtu_conf"));
return true;
}
*/
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);
ipv6_fd = -1;
meshlink_close(relay);
- meshlink_destroy("relay_conf");
+ assert(meshlink_destroy("relay_conf"));
return true;
}
*/
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);
ipv6_fd = -1;
meshlink_close(relay);
- meshlink_destroy("relay_conf");
+ assert(meshlink_destroy("relay_conf"));
return true;
}
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);
ipv6_fd = -1;
meshlink_close(relay);
- meshlink_destroy("relay_conf");
+ assert(meshlink_destroy("relay_conf"));
return true;
}
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;
}
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;
//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);
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);
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);
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);
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);
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);
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);
pthread_mutex_unlock(&lock);
meshlink_close(mesh_handle);
- meshlink_destroy("set_receive_cb_conf");
+ assert(meshlink_destroy("set_receive_cb_conf"));
return true;
}
pthread_mutex_unlock(&lock);
meshlink_close(mesh_handle);
- meshlink_destroy("set_receive_cb_conf");
+ assert(meshlink_destroy("set_receive_cb_conf"));
return true;
}
assert_int_equal(receive_data, true);
meshlink_close(mesh);
- meshlink_destroy("send_conf");
+ assert(meshlink_destroy("send_conf"));
return result;
}
assert_int_equal(ret, false);
meshlink_close(mesh);
- meshlink_destroy("send_conf");
+ assert(meshlink_destroy("send_conf"));
return true;
}
assert_int_equal(ret, false);
meshlink_close(mesh);
- meshlink_destroy("send_conf");
+ assert(meshlink_destroy("send_conf"));
return true;
}
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);
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);
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;
}
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
// closing meshes and destroying confbase
meshlink_close(mesh);
- meshlink_destroy("logconf");
+ assert(meshlink_destroy("logconf"));
return true;
}
// Clean up
meshlink_close(mesh_handle);
- meshlink_destroy("setportconf");
+ assert(meshlink_destroy("setportconf"));
return true;
}
// Clean up
meshlink_close(mesh_handle);
- meshlink_destroy("getportconf");
+ assert(meshlink_destroy("getportconf"));
return false;
}
// Clean up
meshlink_close(mesh_handle);
- meshlink_destroy("signconf");
+ assert(meshlink_destroy("signconf"));
return ret;
}
// 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");
// 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");
// 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");
// 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");
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");
// 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));
*/
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);
// Clean up
meshlink_close(mesh);
- meshlink_destroy("start_conf");
+ assert(meshlink_destroy("start_conf"));
return true;
}
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);
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));
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;
}
// 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);
// Clean up
meshlink_close(mesh_handle);
- meshlink_destroy("set_status_cb_conf.3");
+ assert(meshlink_destroy("set_status_cb_conf.3"));
return true;
}
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");
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");
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");
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);
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");
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");
*/
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);
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");
// 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);
pthread_mutex_unlock(& lock_receive);
- meshlink_blacklist(mesh1, foo);
+ assert(meshlink_blacklist(mesh1, foo));
rec_stat = false;
assert(meshlink_send(mesh1, bar, "test", 5));
}
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);
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;
}
// 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);
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;
}
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;
}
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;
}
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;
fprintf(stderr, "Node blacklisted\n");
set_sync_flag(&channels_closed, false);
- meshlink_blacklist(mesh, peer_node);
+ assert(meshlink_blacklist(mesh, peer_node));
sleep(10);
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);
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) {
// 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);
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) {
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) {
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) {
// 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);
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) {
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;
}
}
execute_close();
- meshlink_destroy(argv[1]);
+ assert(meshlink_destroy(argv[1]));
}
}
execute_close();
- meshlink_destroy(argv[1]);
+ assert(meshlink_destroy(argv[1]));
}
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;
}
}
execute_close();
- meshlink_destroy(argv[1]);
+ assert(meshlink_destroy(argv[1]));
}
}
execute_close();
- meshlink_destroy(argv[1]);
+ assert(meshlink_destroy(argv[1]));
}
}
execute_close();
- meshlink_destroy(argv[1]);
+ assert(meshlink_destroy(argv[1]));
return 0;
}
}
execute_close();
- meshlink_destroy(argv[1]);
+ assert(meshlink_destroy(argv[1]));
}
}
execute_close();
- meshlink_destroy(argv[1]);
+ assert(meshlink_destroy(argv[1]));
}
}
execute_close();
- meshlink_destroy(argv[1]);
+ assert(meshlink_destroy(argv[1]));
}
}
execute_close();
- meshlink_destroy(argv[1]);
+ assert(meshlink_destroy(argv[1]));
}
}
execute_close();
- meshlink_destroy(argv[1]);
+ assert(meshlink_destroy(argv[1]));
}
}
execute_close();
- meshlink_destroy(argv[1]);
+ assert(meshlink_destroy(argv[1]));
}
}
execute_close();
- meshlink_destroy(argv[1]);
+ assert(meshlink_destroy(argv[1]));
}
}
execute_close();
- meshlink_destroy(argv[1]);
+ assert(meshlink_destroy(argv[1]));
}
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);
}
}
}
//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 */
}
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);
}
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));
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);
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);
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);
}
meshlink_enable_discovery(mesh, false);
- meshlink_add_address(mesh, "localhost");
+ assert(meshlink_add_address(mesh, "localhost"));
char *data = meshlink_export(mesh);
assert(data);
meshlink_enable_discovery(mesh, false);
- meshlink_add_address(mesh, "localhost");
+ assert(meshlink_add_address(mesh, "localhost"));
char *data = meshlink_export(mesh);
assert(data);
// 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);
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) {
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() {
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);
// 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);
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);
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]);
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]);
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);