#include <unistd.h>
#if defined(_WIN32)
-#include <Winsock2.h>
+#include <winsock2.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
/// An edge in the meshlink network.
struct meshlink_edge {
struct meshlink_node *from; ///< Pointer to a node. Node memory is
- // owned by meshlink and should not be
- // deallocated. Node contents may be
- // changed by meshlink.
+ // owned by meshlink and should not be
+ // deallocated. Node contents may be
+ // changed by meshlink.
struct meshlink_node *to; ///< Pointer to a node. Node memory is
- // owned by meshlink and should not be
- // deallocated. Node contents may be
- // changed by meshlink.
+ // owned by meshlink and should not be
+ // deallocated. Node contents may be
+ // changed by meshlink.
struct sockaddr_storage address;///< The address information associated
- // with this edge.
+ // with this edge.
uint32_t options; ///< Edge options. @TODO what are edge options?
int weight; ///< Weight assigned to this edge.
};
*/
extern meshlink_handle_t *meshlink_open(const char *confbase, const char *name, const char* appname, dev_class_t devclass);
-/// is used by the C++ wrapper to allocate more memory behind the handle
-extern meshlink_handle_t *meshlink_open_with_size(const char *confbase, const char *name, const char* appname, dev_class_t devclass, size_t size);
-
/// Start MeshLink.
/** This function causes MeshLink to open network sockets, make outgoing connections, and
* create a new thread, which will handle all network I/O.
*/
extern void meshlink_close(meshlink_handle_t *mesh);
+/// Destroy a MeshLink instance.
+/** This function remove all configuration files of a MeshLink instance. It should only be called when the application
+ * does not have an open handle to this instance. Afterwards, a call to meshlink_open() will create a completely
+ * new instance.
+ *
+ * @param confbase The directory in which MeshLink stores its configuration files.
+ * After the function returns, the application is free to overwrite or free @a confbase @a.
+ *
+ * @return This function will return true if the MeshLink instance was succesfully destroyed, false otherwise.
+ */
+extern bool meshlink_destroy(const char *confbase);
+
/// A callback for receiving data from the mesh.
/** @param mesh A handle which represents an instance of MeshLink.
* @param source A pointer to a meshlink_node_t describing the source of the data.
*/
extern ssize_t meshlink_get_pmtu(meshlink_handle_t *mesh, meshlink_node_t *destination);
+/// Get a handle for our own node.
+/** This function returns a handle for the local node.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ *
+ * @return A pointer to a meshlink_node_t which represents the local node.
+ * The pointer is guaranteed to be valid until meshlink_close() is called.
+ */
+extern meshlink_node_t *meshlink_get_self(meshlink_handle_t *mesh);
+
/// Get a handle for a specific node.
/** This function returns a handle for the node with the given name.
*
* @param mesh A handle which represents an instance of MeshLink.
* @param node A pointer to a meshlink_node_t describing the node.
*
- * @return A nul-terminated C string containing the fingerprint of the node's public key in a printable ASCII format.
+ * @return A nul-terminated C string containing the fingerprint of the node's public key in a printable ASCII format.
* The application should call free() after it is done using this string.
*/
extern char *meshlink_get_fingerprint(meshlink_handle_t *mesh, meshlink_node_t *node);
/** 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 hostname The hostname which can be found at the given address.
- * The caller is free to overwrite or free this string
- * once meshlink returns.
- * @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.
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param hostname The hostname which can be found at the given address.
+ * The caller is free to overwrite or free this string
+ * once meshlink returns.
+ * @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);