From: Guus Sliepen Date: Mon, 21 Apr 2014 17:27:55 +0000 (+0200) Subject: Rename variable handle to mesh. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=ae098a93ff90b51b591cd371bef2a5813d8d41f0;p=meshlink Rename variable handle to mesh. --- diff --git a/src/meshlink.c b/src/meshlink.c index 86340f0e..aaf6657b 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -35,61 +35,65 @@ meshlink_handle_t *meshlink_open(const char *confbase, const char *name) { return NULL; } -bool meshlink_start(meshlink_handle_t *handle) { +bool meshlink_start(meshlink_handle_t *mesh) { return false; } -void meshlink_stop(meshlink_handle_t *handle) { +void meshlink_stop(meshlink_handle_t *mesh) { } -void meshlink_close(meshlink_handle_t *handle) { +void meshlink_close(meshlink_handle_t *mesh) { } -void meshlink_set_receive_cb(meshlink_handle_t *handle, meshlink_receive_cb_t cb) { +void meshlink_set_receive_cb(meshlink_handle_t *mesh, meshlink_receive_cb_t cb) { + mesh->receive_cb = cb; } -void meshlink_set_node_status_cb(meshlink_handle_t *handle, meshlink_node_status_cb_t cb) { +void meshlink_set_node_status_cb(meshlink_handle_t *mesh, meshlink_node_status_cb_t cb) { + mesh->node_status_cb = cb; } -void meshlink_set_log_cb(meshlink_handle_t *handle, meshlink_log_level_t level, meshlink_log_cb_t cb) { +void meshlink_set_log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, meshlink_log_cb_t cb) { + mesh->log_cb = cb; + mesh->log_level = level; } -bool meshlink_send(meshlink_handle_t *handle, meshlink_node_t *destination, const void *data, unsigned int len) { +bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const void *data, unsigned int len) { return false; } -meshlink_node_t *meshlink_get_node(meshlink_handle_t *handle, const char *name) { +meshlink_node_t *meshlink_get_node(meshlink_handle_t *mesh, const char *name) { return NULL; } -size_t meshlink_get_all_nodes(meshlink_handle_t *handle, meshlink_node_t **nodes, size_t nmemb) { +size_t meshlink_get_all_nodes(meshlink_handle_t *mesh, meshlink_node_t **nodes, size_t nmemb) { return 0; } -char *meshlink_sign(meshlink_handle_t *handle, const char *data, size_t len) { +char *meshlink_sign(meshlink_handle_t *mesh, const char *data, size_t len) { return NULL; } -bool meshlink_verify(meshlink_handle_t *handle, meshlink_node_t *source, const char *data, size_t len, const char *signature) { +bool meshlink_verify(meshlink_handle_t *mesh, meshlink_node_t *source, const char *data, size_t len, const char *signature) { return false; } -char *meshlink_invite(meshlink_handle_t *handle, const char *name) { +char *meshlink_invite(meshlink_handle_t *mesh, const char *name) { return NULL; } -bool meshlink_join(meshlink_handle_t *handle, const char *invitation) { +bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) { return false; } -char *meshlink_export(meshlink_handle_t *handle) { +char *meshlink_export(meshlink_handle_t *mesh) { return NULL; } -bool meshlink_import(meshlink_handle_t *handle, const char *data) { +bool meshlink_import(meshlink_handle_t *mesh, const char *data) { return false; } -void meshlink_blacklist(meshlink_handle_t *handle, meshlink_node_t *node) { +void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) { } diff --git a/src/meshlink.h b/src/meshlink.h index 178e92aa..ffd05af2 100644 --- a/src/meshlink.h +++ b/src/meshlink.h @@ -81,7 +81,7 @@ extern meshlink_handle_t *meshlink_open(const char *confbase, const char *name); * * @return This function will return true if MeshLink has succesfully started its thread, false otherwise. */ -extern bool meshlink_start(meshlink_handle_t *handle); +extern bool meshlink_start(meshlink_handle_t *mesh); /// Stop MeshLink. /** This function causes MeshLink to disconnect from all other nodes, @@ -89,7 +89,7 @@ extern bool meshlink_start(meshlink_handle_t *handle); * * @param handle A handle which represents an instance of MeshLink. */ -extern void meshlink_stop(meshlink_handle_t *handle); +extern void meshlink_stop(meshlink_handle_t *mesh); /// Close the MeshLink handle. /** This function calls meshlink_stop() if necessary, @@ -98,7 +98,7 @@ extern void meshlink_stop(meshlink_handle_t *handle); * * @param handle A handle which represents an instance of MeshLink. */ -extern void meshlink_close(meshlink_handle_t *handle); +extern void meshlink_close(meshlink_handle_t *mesh); /// A callback for receiving data from the mesh. /** @param handle A handle which represents an instance of MeshLink. @@ -106,7 +106,7 @@ extern void meshlink_close(meshlink_handle_t *handle); * @param data A pointer to a buffer containing the data sent by the source. * @param len The length of the received data. */ -typedef void (*meshlink_receive_cb_t)(meshlink_handle_t *handle, meshlink_node_t *source, const void *data, size_t len); +typedef void (*meshlink_receive_cb_t)(meshlink_handle_t *mesh, meshlink_node_t *source, const void *data, size_t len); /// Set the receive callback. /** This functions sets the callback that is called whenever another node sends data to the local node. @@ -118,14 +118,14 @@ typedef void (*meshlink_receive_cb_t)(meshlink_handle_t *handle, meshlink_node_t * @param handle A handle which represents an instance of MeshLink. * @param cb A pointer to the function which will be called when another node sends data to the local node. */ -extern void meshlink_set_receive_cb(meshlink_handle_t *handle, meshlink_receive_cb_t cb); +extern void meshlink_set_receive_cb(meshlink_handle_t *mesh, meshlink_receive_cb_t cb); /// A callback reporting node status changes. /** @param handle A handle which represents an instance of MeshLink. * @param node A pointer to a meshlink_node_t describing the node whose status changed. * @param reachable True if the node is reachable, false otherwise. */ -typedef void (*meshlink_node_status_cb_t)(meshlink_handle_t *handle, meshlink_node_t *node, bool reachable); +typedef void (*meshlink_node_status_cb_t)(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable); /// Set the node status callback. /** This functions sets the callback that is called whenever another node's status changed. @@ -137,7 +137,7 @@ typedef void (*meshlink_node_status_cb_t)(meshlink_handle_t *handle, meshlink_no * @param handle A handle which represents an instance of MeshLink. * @param cb A pointer to the function which will be called when another node's status changes. */ -extern void meshlink_set_node_status_cb(meshlink_handle_t *handle, meshlink_node_status_cb_t cb); +extern void meshlink_set_node_status_cb(meshlink_handle_t *mesh, meshlink_node_status_cb_t cb); /// Severity of log messages generated by MeshLink. typedef enum { @@ -153,7 +153,7 @@ typedef enum { * @param level An enum describing the severity level of the message. * @param text A pointer to a string containing the textual log message. */ -typedef void (*meshlink_log_cb_t)(meshlink_handle_t *handle, meshlink_log_level_t level, const char *text); +typedef void (*meshlink_log_cb_t)(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text); /// Set the log callback. /** This functions sets the callback that is called whenever MeshLink has some information to log. @@ -166,7 +166,7 @@ typedef void (*meshlink_log_cb_t)(meshlink_handle_t *handle, meshlink_log_level_ * @param level An enum describing the minimum severity level. Debugging information with a lower level will not trigger the callback. * @param cb A pointer to the function which will be called when another node sends data to the local node. */ -extern void meshlink_set_log_cb(meshlink_handle_t *handle, meshlink_log_level_t level, meshlink_log_cb_t cb); +extern void meshlink_set_log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, meshlink_log_cb_t cb); /// Send data to another node. /** This functions sends one packet of data to another node in the mesh. @@ -182,7 +182,7 @@ extern void meshlink_set_log_cb(meshlink_handle_t *handle, meshlink_log_level_t * @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(meshlink_handle_t *handle, meshlink_node_t *destination, const void *data, unsigned int len); +extern bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const void *data, unsigned int len); /// Get a handle for a specific node. /** This function returns a handle for the node with the given name. @@ -193,7 +193,7 @@ extern bool meshlink_send(meshlink_handle_t *handle, meshlink_node_t *destinatio * @return A pointer to a meshlink_node_t which represents the requested node, * or NULL if the requested node does not exist. */ -extern meshlink_node_t *meshlink_get_node(meshlink_handle_t *handle, const char *name); +extern meshlink_node_t *meshlink_get_node(meshlink_handle_t *mesh, const char *name); /// Get a list of all nodes. /** This function returns a list with handles for all known nodes. @@ -204,7 +204,7 @@ extern meshlink_node_t *meshlink_get_node(meshlink_handle_t *handle, const char * * @param return The number of known nodes. This can be larger than nmemb, in which case not all nodes were stored in the nodes array. */ -extern size_t meshlink_get_all_nodes(meshlink_handle_t *handle, meshlink_node_t **nodes, size_t nmemb); +extern size_t meshlink_get_all_nodes(meshlink_handle_t *mesh, meshlink_node_t **nodes, size_t nmemb); /// Sign data using the local node's MeshLink key. /** This function signs data using the local node's MeshLink key. @@ -217,7 +217,7 @@ extern size_t meshlink_get_all_nodes(meshlink_handle_t *handle, meshlink_node_t * @return This function returns a pointer to a string containing the signature, or NULL in case of an error. * The application should call free() after it has finished using the signature. */ -extern char *meshlink_sign(meshlink_handle_t *handle, const char *data, size_t len); +extern char *meshlink_sign(meshlink_handle_t *mesh, const char *data, size_t len); /// 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. @@ -230,7 +230,7 @@ extern char *meshlink_sign(meshlink_handle_t *handle, const char *data, size_t l * * @return This function returns true if the signature is valid, false otherwise. */ -extern bool meshlink_verify(meshlink_handle_t *handle, meshlink_node_t *source, const char *data, size_t len, const char *signature); +extern bool meshlink_verify(meshlink_handle_t *mesh, meshlink_node_t *source, const char *data, size_t len, const char *signature); /// 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. @@ -244,7 +244,7 @@ extern bool meshlink_verify(meshlink_handle_t *handle, meshlink_node_t *source, * @return This function returns a string that contains the invitation URL. * The application should call free() after it has finished using the URL. */ -extern char *meshlink_invite(meshlink_handle_t *handle, const char *name); +extern char *meshlink_invite(meshlink_handle_t *mesh, const char *name); /// 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. @@ -256,7 +256,7 @@ extern char *meshlink_invite(meshlink_handle_t *handle, const char *name); * * @return This function returns true if the local node joined the mesh it was invited to, false otherwise. */ -extern bool meshlink_join(meshlink_handle_t *handle, const char *invitation); +extern bool meshlink_join(meshlink_handle_t *mesh, const char *invitation); /// 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. @@ -268,7 +268,7 @@ extern bool meshlink_join(meshlink_handle_t *handle, const char *invitation); * @return This function returns a string that contains the exported key and addresses. * The application should call free() after it has finished using this string. */ -extern char *meshlink_export(meshlink_handle_t *handle); +extern char *meshlink_export(meshlink_handle_t *mesh); /// Import another node's key and addresses. /** This function accepts a string containing the exported public key and addresses of another node. @@ -279,7 +279,7 @@ extern char *meshlink_export(meshlink_handle_t *handle); * * @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(meshlink_handle_t *handle, const char *data); +extern bool meshlink_import(meshlink_handle_t *mesh, const char *data); /// Blacklist a node from the mesh. /** This function causes the local node to blacklist another node. @@ -289,6 +289,6 @@ extern bool meshlink_import(meshlink_handle_t *handle, const char *data); * @param handle A handle which represents an instance of MeshLink. * @param node A pointer to a meshlink_node_t describing the node to be blacklisted. */ -extern void meshlink_blacklist(meshlink_handle_t *handle, meshlink_node_t *node); +extern void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node); #endif // MESHLINK_H diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index 6e59db0e..fcef8e84 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -22,8 +22,8 @@ #include "system.h" -#include "node.h" #include "meshlink.h" +#include "list.h" #include "splay_tree.h" #define MAXSOCKETS 16 @@ -39,7 +39,7 @@ struct meshlink_handle { meshlink_log_level_t log_level; pthread_t thread; - listen_socket_t listen_socket[MAXSOCKETS]; + struct list_t *sockets; struct node_t *myself;