]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink.h
Add meshlink_get_self().
[meshlink] / src / meshlink.h
index 75c4932715b6e23eaed4f373cc0b6e0c6c8dfb86..651f05c8bd355f54002c90881322f029d303337d 100644 (file)
@@ -26,7 +26,7 @@
 #include <unistd.h>
 
 #if defined(_WIN32)
-#include <Winsock2.h>
+#include <winsock2.h>
 #else
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -107,15 +107,15 @@ struct meshlink_channel {
 /// 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.
 };
@@ -160,9 +160,6 @@ extern const char *meshlink_strerror(meshlink_errno_t err);
  */
 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.
@@ -199,6 +196,18 @@ extern void meshlink_stop(meshlink_handle_t *mesh);
  */
 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.
@@ -320,6 +329,16 @@ extern bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination,
  */
 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.
  *
@@ -340,7 +359,7 @@ extern meshlink_node_t *meshlink_get_node(meshlink_handle_t *mesh, const char *n
  *  @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);
@@ -655,13 +674,13 @@ extern ssize_t meshlink_channel_send(meshlink_handle_t *mesh, meshlink_channel_t
 /** 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);