+/// Whitelist a node on the mesh.
+/** This function causes the local node to whitelist a previously blacklisted 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 mesh A handle which represents an instance of MeshLink.
+ * @param node A pointer to a meshlink_node_t describing the node to be whitelisted.
+ */
+extern void meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node);
+
+/// Set whether new nodes are blacklisted by default.
+/** This function sets the blacklist behaviour for newly discovered nodes.
+ * If set to true, new nodes will be automatically blacklisted.
+ * If set to false, which is the default, new nodes are automatically whitelisted.
+ * The whitelist/blacklist status of a node may be changed afterwards with the
+ * meshlink_whitelist() and meshlink_blacklist() functions.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param blacklist True if new nodes are to be blacklisted, false if whitelisted.
+ */
+extern void meshlink_set_default_blacklist(meshlink_handle_t *mesh, bool blacklist);
+
+/// A callback for accepting incoming channels.
+/** This function is called whenever a remote node wants to open a channel to the local node.
+ * The application then has to decide whether to accept or reject this channel.
+ *
+ * The callback is run in MeshLink's own thread.
+ * It is therefore important that the callback return quickly and uses apprioriate methods (queues, pipes, locking, etc.)
+ * to hand any data over to the application's thread.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the incoming channel.
+ * If the application accepts the incoming channel by returning true,
+ * then this handle is valid until meshlink_channel_close() is called on it.
+ * If the application rejects the incoming channel by returning false,
+ * then this handle is invalid after the callback returns
+ * (the callback does not need to call meshlink_channel_close() itself in this case).
+ * @param port The port number the peer wishes to connect to.
+ * @param data A pointer to a buffer containing data already received, or NULL in case no data has been received yet. (Not yet used.)
+ * The pointer is only valid during the lifetime of the callback.
+ * The callback should mempcy() the data if it needs to be available outside the callback.
+ * @param len The length of the data, or 0 in case no data has been received yet. (Not yet used.)
+ *
+ * @return This function should return true if the application accepts the incoming channel, false otherwise.
+ * If returning false, the channel is invalid and may not be used anymore.
+ */
+typedef bool (*meshlink_channel_accept_cb_t)(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len);
+
+/// A callback for receiving data from a channel.
+/** This function is called whenever data is received from a remote node on a channel.
+ *
+ * This function is also called in case the channel has been closed by the remote node, or when the channel is terminated abnormally.
+ * In both cases, @a data will be NULL and @a len will be 0, and meshlink_errno will be set.
+ * In any case, the @a channel handle will still be valid until the application calls meshlink_close().
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ * @param data A pointer to a buffer containing data sent by the source, or NULL in case of an error.
+ * The pointer is only valid during the lifetime of the callback.
+ * The callback should mempcy() the data if it needs to be available outside the callback.
+ * @param len The length of the data, or 0 in case of an error.
+ */
+typedef void (*meshlink_channel_receive_cb_t)(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len);
+
+/// A callback informing the application when data can be sent on a channel.
+/** This function is called whenever there is enough free buffer space so a call to meshlink_channel_send() will succeed.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ * @param len The maximum amount of data that is guaranteed to be accepted by meshlink_channel_send(),
+ * or 0 in case of an error.
+ */
+typedef void (*meshlink_channel_poll_cb_t)(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len);
+
+/// Set the accept callback.
+/** This functions sets the callback that is called whenever another node sends data to the local node.
+ * The callback is run in MeshLink's own thread.
+ * It is therefore important that the callback uses apprioriate methods (queues, pipes, locking, etc.)
+ * to hand the data over to the application's thread.
+ * The callback should also not block itself and return as quickly as possible.
+ *
+ * If no accept callback is set, incoming channels are rejected.
+ *
+ * @param mesh 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.
+ * If a NULL pointer is given, the callback will be disabled.
+ */
+extern void meshlink_set_channel_accept_cb(meshlink_handle_t *mesh, meshlink_channel_accept_cb_t cb);
+
+/// Set the receive callback.
+/** This functions sets the callback that is called whenever another node sends data to the local node.
+ * The callback is run in MeshLink's own thread.
+ * It is therefore important that the callback uses apprioriate methods (queues, pipes, locking, etc.)
+ * to hand the data over to the application's thread.
+ * The callback should also not block itself and return as quickly as possible.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ * @param cb A pointer to the function which will be called when another node sends data to the local node.
+ * If a NULL pointer is given, the callback will be disabled and incoming data is ignored.
+ */
+extern void meshlink_set_channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, meshlink_channel_receive_cb_t cb);
+
+/// 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.
+ * 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 mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ * @param cb A pointer to the function which will be called when data can be sent to another node.
+ * If a NULL pointer is given, the callback will be disabled.
+ */
+extern void meshlink_set_channel_poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, meshlink_channel_poll_cb_t cb);
+
+/// Set the send buffer size of a channel.
+/** This function sets the desired size of the send buffer.
+ * The default size is 128 kB.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ * @param size The desired size for the send buffer.
+ * If a NULL pointer is given, the callback will be disabled.
+ */
+extern void meshlink_set_channel_sndbuf(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t size);
+
+/// Set the receive buffer size of a channel.
+/** This function sets the desired size of the receive buffer.
+ * The default size is 128 kB.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ * @param size The desired size for the send buffer.
+ * If a NULL pointer is given, the callback will be disabled.
+ */
+extern void meshlink_set_channel_rcvbuf(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t size);
+
+/// 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.
+ * The application then has to decide whether to accept or reject this channel.
+ *
+ * This function returns a pointer to a struct meshlink_channel that will be allocated by MeshLink.
+ * When the application does no longer need to use this channel, it must call meshlink_close()
+ * to free its resources.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param node The node to which this channel is being initiated.
+ * @param port The port number the peer wishes to connect to.
+ * @param cb A pointer to the function which will be called when the remote node sends data to the local node.
+ * The pointer may be NULL, in which case incoming data is ignored.
+ * @param data A pointer to a buffer containing data to already queue for sending, or NULL if there is no data to send.
+ * After meshlink_send() returns, the application is free to overwrite or free this buffer.
+ * @param len The length of the data, or 0 if there is no data to send.
+ * @param flags A bitwise-or'd combination of flags that set the semantics for this channel.
+ *
+ * @return A handle for the channel, or NULL in case of an error.
+ * The handle is valid until meshlink_channel_close() is called.
+ */
+extern meshlink_channel_t *meshlink_channel_open_ex(meshlink_handle_t *mesh, meshlink_node_t *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len, uint32_t flags);
+
+/// 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.
+ * The application then has to decide whether to accept or reject this channel.
+ *
+ * This function returns a pointer to a struct meshlink_channel that will be allocated by MeshLink.
+ * When the application does no longer need to use this channel, it must call meshlink_close()
+ * to free its resources.
+ *
+ * Calling this function is equivalent to calling meshlink_channel_open_ex()
+ * with the flags set to MESHLINK_CHANNEL_TCP.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param node The node to which this channel is being initiated.
+ * @param port The port number the peer wishes to connect to.
+ * @param cb A pointer to the function which will be called when the remote node sends data to the local node.
+ * The pointer may be NULL, in which case incoming data is ignored.
+ * @param data A pointer to a buffer containing data to already queue for sending, or NULL if there is no data to send.
+ * After meshlink_send() returns, the application is free to overwrite or free this buffer.
+ * @param len The length of the data, or 0 if there is no data to send.
+ *
+ * @return A handle for the channel, or NULL in case of an error.
+ * The handle is valid until meshlink_channel_close() is called.
+ */
+extern meshlink_channel_t *meshlink_channel_open(meshlink_handle_t *mesh, meshlink_node_t *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len);
+
+/// Partially close a reliable stream channel.
+/** This shuts down the read or write side of a channel, or both, without closing the handle.
+ * It can be used to inform the remote node that the local node has finished sending all data on the channel,
+ * but still allows waiting for incoming data from the remote node.
+ *
+ * Shutting down the receive direction is also possible, and is equivalent to setting the receive callback to NULL.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ * @param direction Must be one of SHUT_RD, SHUT_WR or SHUT_RDWR, otherwise this call will not have any affect.
+ */
+extern void meshlink_channel_shutdown(meshlink_handle_t *mesh, meshlink_channel_t *channel, int direction);
+
+/// Close a reliable stream channel.
+/** This informs the remote node that the local node has finished sending all data on the channel.
+ * It also causes the local node to stop accepting incoming data from the remote node.
+ * It will free the struct meshlink_channel and all associated resources.
+ * Afterwards, the channel handle is invalid and must not be used any more.
+ *
+ * It is allowed to call this function at any time on a valid handle, even inside callback functions.
+ * If called with a valid handle, this function always succeeds, otherwise the result is undefined.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ */
+extern void meshlink_channel_close(meshlink_handle_t *mesh, meshlink_channel_t *channel);
+
+/// Transmit data on a channel
+/** This queues data to send to the remote node.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ * @param data A pointer to a buffer containing data sent by the source, or NULL if there is no data to send.
+ * After meshlink_send() returns, the application is free to overwrite or free this buffer.
+ * @param len The length of the data, or 0 if there is no data to send.
+ *
+ * @return The amount of data that was queued, which can be less than len, or a negative value in case of an error.
+ * 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(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len);
+
+/// A callback for cleaning up buffers submitted for asynchronous I/O.
+/** This callbacks signals that MeshLink has finished using this buffer.
+ * The ownership of the buffer is now back into the application's hands.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel which used this buffer.
+ * @param data A pointer to a buffer containing the enqueued data.
+ * @param len The length of the buffer.
+ * @param priv A private pointer which was set by the application when submitting the buffer.
+ */
+typedef void (*meshlink_aio_cb_t)(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len, void *priv);
+
+/// A callback for asynchronous I/O to and from filedescriptors.
+/** This callbacks signals that MeshLink has finished using this filedescriptor.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel which used this filedescriptor.
+ * @param fd The filedescriptor that was used.
+ * @param len The length of the data that was successfully sent or received.
+ * @param priv A private pointer which was set by the application when submitting the buffer.
+ */
+typedef void (*meshlink_aio_fd_cb_t)(meshlink_handle_t *mesh, meshlink_channel_t *channel, int fd, size_t len, void *priv);
+
+/// Transmit data on a channel asynchronously
+/** This registers a buffer that will be used to send data to the remote node.
+ * Multiple buffers can be registered, in which case data will be sent in the order the buffers were registered.
+ * While there are still buffers with unsent data, the poll callback will not be called.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ * @param data A pointer to a buffer containing data sent by the source, or NULL if there is no data to send.
+ * After meshlink_channel_aio_send() returns, the buffer may not be modified or freed by the application
+ * until the callback routine is called.
+ * @param len The length of the data, or 0 if there is no data to send.
+ * @param cb A pointer to the function which will be called when MeshLink has finished using the buffer.
+ *
+ * @return True if the buffer was enqueued, false otherwise.
+ */
+extern bool meshlink_channel_aio_send(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len, meshlink_aio_cb_t cb, void *priv);
+
+/// 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.
+ * The callback may be returned early if there is an error reading from the filedescriptor.
+ * While there is still with unsent data, the poll callback will not be called.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ * @param fd A file descriptor from which data will be read.
+ * @param len The length of the data, or 0 if there is no data to send.
+ * @param cb A pointer to the function which will be called when MeshLink has finished using the filedescriptor.
+ *
+ * @return True if the buffer was enqueued, false otherwise.
+ */
+extern bool meshlink_channel_aio_fd_send(meshlink_handle_t *mesh, meshlink_channel_t *channel, int fd, size_t len, meshlink_aio_fd_cb_t cb, void *priv);
+
+/// Receive data on a channel asynchronously
+/** This registers a buffer that will be filled with incoming channel data.
+ * Multiple buffers can be registered, in which case data will be received in the order the buffers were registered.
+ * While there are still buffers that have not been filled, the receive callback will not be called.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ * @param data A pointer to a buffer that will be filled with incoming data.
+ * After meshlink_channel_aio_receive() returns, the buffer may not be modified or freed by the application
+ * until the callback routine is called.
+ * @param len The length of the data.
+ * @param cb A pointer to the function which will be called when MeshLink has finished using the buffer.
+ *
+ * @return True if the buffer was enqueued, false otherwise.
+ */
+extern bool meshlink_channel_aio_receive(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len, meshlink_aio_cb_t cb, void *priv);
+
+/// 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.
+ * The callback may be returned early if there is an error writing to the filedescriptor.
+ * While there is still unread data, the receive callback will not be called.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ * @param fd A file descriptor to which data will be written.
+ * @param len The length of the data.
+ * @param cb A pointer to the function which will be called when MeshLink has finished using the filedescriptor.
+ *
+ * @return True if the buffer was enqueued, false otherwise.
+ */
+extern bool meshlink_channel_aio_fd_receive(meshlink_handle_t *mesh, meshlink_channel_t *channel, int fd, size_t len, meshlink_aio_fd_cb_t cb, void *priv);
+
+/// Get channel flags.
+/** This returns the flags used when opening this channel.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ *
+ * @return The flags set for this channel.
+ */
+extern uint32_t meshlink_channel_get_flags(meshlink_handle_t *mesh, meshlink_channel_t *channel);
+
+/// 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 mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ *
+ * @return The amount of un-ACKed bytes in the send buffer.
+ */
+extern size_t meshlink_channel_get_sendq(meshlink_handle_t *mesh, meshlink_channel_t *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 mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ *
+ * @return The amount of bytes in the receive buffer.
+ */
+extern size_t meshlink_channel_get_recvq(meshlink_handle_t *mesh, meshlink_channel_t *channel);
+
+/// Hint that a hostname may be found at an address
+/** This function indicates to meshlink that the given hostname is likely found
+ * at the given IP address and port.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param node A pointer to a meshlink_node_t describing the node to add the address hint for.
+ * @param addr The IP address and port which should be tried for the
+ * given hostname. The caller is free to overwrite or free
+ * this memory once meshlink returns.
+ */
+extern void meshlink_hint_address(meshlink_handle_t *mesh, meshlink_node_t *node, const struct sockaddr *addr);
+
+/// 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.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param enable Set to true to enable discovery, false to disable.
+ */
+extern void meshlink_enable_discovery(meshlink_handle_t *mesh, bool enable);
+
+/// Performs key rotation for an encrypted storage
+/** This rotates the (master) key for an encrypted storage and discards the old key
+ * if the call succeeded. This is an atomic call.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param key A pointer to the new key used to encrypt storage.
+ * @param keylen The length of the new key in bytes.
+ *
+ * @return This function returns true if the key rotation for the encrypted storage succeeds, false otherwise.
+ */
+extern bool meshlink_encrypted_key_rotate(meshlink_handle_t *mesh, const void *new_key, size_t new_keylen);
+
+/// Set device class timeouts
+/** This sets the ping interval and timeout for a given device class.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param devclass The device class to update
+ * @param pinginterval The interval between keepalive packets, in seconds. The default is 60.
+ * @param pingtimeout The required time within which a peer should respond, in seconds. The default is 5.
+ * The timeout must be smaller than the interval.
+ */
+extern void meshlink_set_dev_class_timeouts(meshlink_handle_t *mesh, dev_class_t devclass, int pinginterval, int pingtimeout);
+