X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fmeshlink%2B%2B.h;h=551913d4ba2a94ceb4df51852dd8595ce563a28d;hb=a23ddd4f4e273b2ed68fe173b4faa69aadc98756;hp=eeb1cd02ac1793921139e0e8285d7d2cd1fa593f;hpb=da55b444c063c510f37e4f8527982eb86f01c7b3;p=meshlink diff --git a/src/meshlink++.h b/src/meshlink++.h index eeb1cd02..551913d4 100644 --- a/src/meshlink++.h +++ b/src/meshlink++.h @@ -79,6 +79,15 @@ typedef void (*duplicate_cb_t)(mesh *mesh, node *node); */ typedef void (*log_cb_t)(mesh *mesh, log_level_t level, const char *text); +/// A callback for listening for incoming channels. +/** @param mesh A handle which represents an instance of MeshLink. + * @param node A handle for the node that wants to open a channel. + * @param port The port number the peer wishes to connect to. + * + * @return This function should return true if the application listens for the incoming channel, false otherwise. + */ +typedef bool (*meshlink_channel_listen_cb_t)(struct meshlink_handle *mesh, struct meshlink_node *node, uint16_t port); + /// A callback for accepting incoming channels. /** @param mesh A handle which represents an instance of MeshLink. * @param channel A handle for the incoming channel. @@ -265,12 +274,37 @@ public: (void)meshlink_errno; } + /// This functions is called whenever MeshLink is blacklisted by another node. + virtual void blacklisted(node *peer) { + /* do nothing */ + (void)peer; + } + /// This functions is called whenever MeshLink a meta-connection attempt is made. virtual void connection_try(node *peer) { /* do nothing */ (void)peer; } + /// This functions is called to determine if we are listening for incoming channels. + /** + * The function is run in MeshLink's own thread. + * It is therefore important that the callback uses apprioriate methods (queues, pipes, locking, etc.) + * to pass data to or from the application's thread. + * The callback should also not block itself and return as quickly as possible. + * + * @param node A handle for the node that wants to open a channel. + * @param port The port number the peer wishes to connect to. + * + * @return This function should return true if the application accepts the incoming channel, false otherwise. + */ + virtual bool channel_listen(node *node, uint16_t port) { + /* by default accept all channels */ + (void)node; + (void)port; + return true; + } + /// This functions is called whenever another node attempts to open a channel to the local node. /** * If the channel is accepted, the poll_callback will be set to channel_poll and can be @@ -346,6 +380,8 @@ public: meshlink_set_node_duplicate_cb(handle, &node_duplicate_trampoline); meshlink_set_log_cb(handle, MESHLINK_DEBUG, &log_trampoline); meshlink_set_error_cb(handle, &error_trampoline); + meshlink_set_blacklisted_cb(handle, &blacklisted_trampoline); + meshlink_set_channel_listen_cb(handle, &channel_listen_trampoline); meshlink_set_channel_accept_cb(handle, &channel_accept_trampoline); meshlink_set_connection_try_cb(handle, &connection_try_trampoline); return meshlink_start(handle); @@ -402,6 +438,17 @@ public: return meshlink_get_node_reachability(handle, node, last_reachable, last_unreachable); } + /// Get a node's blacklist status. + /** This function returns the current blacklist status of a given node. + * + * @param node A pointer to a meshlink::node describing the node. + * + * @return This function returns true if the node is currently blacklisted, false otherwise. + */ + bool get_node_blacklisted(node *node) { + return meshlink_get_node_blacklisted(handle, node); + } + /// Get a handle for a specific submesh. /** This function returns a handle for the submesh with the given name. * @@ -436,6 +483,22 @@ public: return (node **)meshlink_get_all_nodes(handle, (meshlink_node_t **)nodes, nmemb); } + /// Get a list of all nodes by blacklist status. + /** This function returns a list with handles for all the nodes who were either blacklisted or whitelisted. + * + * @param blacklisted If true, a list of blacklisted nodes will be returned, otherwise whitelisted nodes. + * @param nodes A pointer to an array of pointers to meshlink::node, which should be allocated by the application. + * @param nmemb The maximum number of pointers that can be stored in the nodes array. + * + * @return A pointer to an array containing pointers to all known nodes with the given blacklist status. + * If the @a nodes argument was not NULL, then the return value can either be the same value or a different value. + * 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. + */ + node **get_all_nodes_by_blacklisted(bool blacklisted, node **nodes, size_t *nmemb) { + return (node **)meshlink_get_all_nodes_by_blacklisted(handle, blacklisted, (meshlink_node_t **)nodes, nmemb); + } + /// Sign data using the local node's MeshLink key. /** This function signs data using the local node's MeshLink key. * The generated signature can be securely verified by other nodes. @@ -486,6 +549,17 @@ public: return meshlink_set_canonical_address(handle, node, address, port); } + /// Clear the canonical Address for a node. + /** This function clears the canonical Address for a node. + * + * @param node A pointer to a struct meshlink_node describing the node. + * + * @return This function returns true if the address was removed, false otherwise. + */ + bool clear_canonical_address(node *node) { + return meshlink_clear_canonical_address(handle, node); + } + /// Add an invitation address for the local node. /** This function adds an address for the local node, which will be used only for invitation URLs. * This address is not stored permanently. @@ -1141,6 +1215,15 @@ private: that->error(meshlink_errno); } + static void blacklisted_trampoline(meshlink_handle_t *handle, meshlink_node_t *peer) { + if(!(handle->priv)) { + return; + } + + meshlink::mesh *that = static_cast(handle->priv); + that->blacklisted(static_cast(peer)); + } + static void connection_try_trampoline(meshlink_handle_t *handle, meshlink_node_t *peer) { if(!(handle->priv)) { return; @@ -1150,6 +1233,15 @@ private: that->connection_try(static_cast(peer)); } + static bool channel_listen_trampoline(meshlink_handle_t *handle, meshlink_node_t *node, uint16_t port) { + if(!(handle->priv)) { + return false; + } + + meshlink::mesh *that = static_cast(handle->priv); + return that->channel_listen(static_cast(node), port); + } + static bool channel_accept_trampoline(meshlink_handle_t *handle, meshlink_channel *channel, uint16_t port, const void *data, size_t len) { if(!(handle->priv)) { return false;