*/
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.
(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
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_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);
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 mesh A handle which represents an instance of MeshLink.
+ * @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.
meshlink_set_dev_class_fast_retry_period(handle, devclass, fast_retry_period);
}
+ /// Set device class maximum timeout
+ /** This sets the maximum timeout for outgoing connection retries for a given device class.
+ *
+ * @param devclass The device class to update
+ * @param maxtimeout The maximum timeout between reconnection attempts, in seconds. The default is 900.
+ */
+ void set_dev_class_maxtimeout(dev_class_t devclass, int maxtimeout) {
+ meshlink_set_dev_class_maxtimeout(handle, devclass, maxtimeout);
+ }
+
/// Set which order invitations are committed
/** This determines in which order configuration files are written to disk during an invitation.
* By default, the invitee saves the configuration to disk first, then the inviter.
that->connection_try(static_cast<node *>(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<mesh *>(handle->priv);
+ return that->channel_listen(static_cast<meshlink::node *>(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;