X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fmeshlink%2B%2B.h;h=48eabf3fbf5fdf80cfb3586c6a5001e808a7e208;hb=2fd608c4111ef4d48a649401d918f5981856cc44;hp=37ca7e8b4d799281bcf0c86eeb0da1b60a3507af;hpb=ec02aca3d7888f072c5c0d52ba6b5c37ed42b69e;p=meshlink diff --git a/src/meshlink++.h b/src/meshlink++.h index 37ca7e8b..48eabf3f 100644 --- a/src/meshlink++.h +++ b/src/meshlink++.h @@ -43,6 +43,13 @@ typedef meshlink_errno_t errno_t; */ typedef void (*receive_cb_t)(mesh *mesh, node *source, const void *data, size_t len); +/// A callback reporting the meta-connection attempt made by the host node to an another node. +/** @param mesh A handle which represents an instance of MeshLink. + * @param node A pointer to a meshlink_node_t describing the node to whom meta-connection is being tried. + * This pointer is valid until meshlink_close() is called. + */ +typedef void (*connection_try_cb_t)(mesh *mesh, node *node); + /// A callback reporting node status changes. /** @param mesh A handle which represents an instance of MeshLink. * @param node A pointer to a meshlink::node describing the node whose status changed. @@ -213,6 +220,12 @@ public: (void)message; } + /// 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 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 @@ -287,6 +300,7 @@ public: meshlink_set_node_duplicate_cb(handle, &node_duplicate_trampoline); meshlink_set_log_cb(handle, MESHLINK_DEBUG, &log_trampoline); meshlink_set_channel_accept_cb(handle, &channel_accept_trampoline); + meshlink_set_connection_try_cb(handle, &connection_try_trampoline); return meshlink_start(handle); } @@ -327,6 +341,18 @@ public: return (node *)meshlink_get_node(handle, name); } + /// Get a handle for a specific submesh. + /** This function returns a handle for the submesh with the given name. + * + * @param name The name of the submesh for which a handle is requested. + * + * @return A pointer to a meshlink::submesh which represents the requested submesh, + * or NULL if the requested submesh does not exist. + */ + submesh *get_submesh(const char *name) { + return (submesh *)meshlink_get_submesh(handle, name); + } + /// Get a handle for our own node. /** This function returns a handle for the local node. * @@ -691,6 +717,30 @@ public: return meshlink_channel_send(handle, channel, data, len); } + /// Get the amount of bytes in the send buffer. + /** This returns the amount of bytes in the send buffer. + * These bytes have not been received by the peer yet. + * + * @param channel A handle for the channel. + * + * @return The amount of un-ACKed bytes in the send buffer. + */ + size_t channel_get_sendq(channel *channel) { + return meshlink_channel_get_sendq(handle, channel); + } + + /// Get the amount of bytes in the receive buffer. + /** This returns the amount of bytes in the receive buffer. + * These bytes have not been processed by the application yet. + * + * @param channel A handle for the channel. + * + * @return The amount of bytes in the receive buffer. + */ + size_t channel_get_recvq(channel *channel) { + return meshlink_channel_get_recvq(handle, channel); + } + /// Enable or disable zeroconf discovery of local peers /** This controls whether zeroconf discovery using the Catta library will be * enabled to search for peers on the local network. By default, it is enabled. @@ -743,6 +793,15 @@ private: that->log(level, message); } + static void connection_try_trampoline(meshlink_handle_t *handle, meshlink_node_t *peer) { + if(!(handle->priv)) { + return; + } + + meshlink::mesh *that = static_cast(handle->priv); + that->connection_try(static_cast(peer)); + } + 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;