]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink.h
object-oriented interface 1st durchstich, incl. chat program adopted. :-)
[meshlink] / src / meshlink.h
index b938ca38ce72e78328de8846d6004e3023e4ac24..603dbbd2e42a6004dbdb958b930ba812bfd9f11d 100644 (file)
@@ -44,8 +44,15 @@ typedef struct meshlink_channel meshlink_channel_t;
 /// Code of most recent error encountered.
 typedef enum {
        MESHLINK_OK,     ///< Everything is fine
+       MESHLINK_EINVAL, ///< Invalid parameter(s) to function call
        MESHLINK_ENOMEM, ///< Out of memory
        MESHLINK_ENOENT, ///< Node is not known
+       MESHLINK_EEXIST, ///< Node already exists
+       MESHLINK_EINTERNAL, ///< MeshLink internal error
+       MESHLINK_ERESOLV, ///< MeshLink could not resolve a hostname
+       MESHLINK_ESTORAGE, ///< MeshLink coud not load or write data from/to disk
+       MESHLINK_ENETWORK, ///< MeshLink encountered a network error
+       MESHLINK_EPEER, ///< A peer caused an error
 } meshlink_errno_t;
 
 /// A variable holding the last encountered error from MeshLink.
@@ -59,6 +66,8 @@ extern __thread meshlink_errno_t meshlink_errno;
 #ifndef MESHLINK_INTERNAL_H
 
 struct meshlink_handle {
+       const char *name;
+       void *priv;
 };
 
 struct meshlink_node {
@@ -108,6 +117,9 @@ extern const char *meshlink_strerror(meshlink_errno_t err);
  */
 extern meshlink_handle_t *meshlink_open(const char *confbase, const char *name);
 
+/// 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, 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.
@@ -240,6 +252,20 @@ extern void meshlink_set_log_cb(meshlink_handle_t *mesh, meshlink_log_level_t le
  */
 extern bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const void *data, size_t len);
 
+/// Query the maximum packet size that can be sent to a node.
+/** This functions returns the maximum size of packets (path MTU) that can be sent to a specific node with meshlink_send().
+ *  The path MTU is a property of the path packets will take to the destination node over the Internet.
+ *  It can be different for different destination nodes.
+ *  and the path MTU can change at any point in time due to changes in the Internet.
+ *  Therefore, although this should only occur rarely, it can still happen that packets that do not exceed this size get dropped.
+ *
+ *  @param mesh         A handle which represents an instance of MeshLink.
+ *  @param destination  A pointer to a meshlink_node_t describing the destination for the data.
+ *
+ *  @return             The recommended maximum size of packets that are to be sent to the destination node, 0 if the node is unreachable,
+ *                      or a negative value in case of an error.
+ */
+extern ssize_t meshlink_get_pmtu(meshlink_handle_t *mesh, meshlink_node_t *destination);
 
 /// Get a handle for a specific node.
 /** This function returns a handle for the node with the given name.
@@ -254,6 +280,18 @@ extern bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination,
  */
 extern meshlink_node_t *meshlink_get_node(meshlink_handle_t *mesh, const char *name);
 
+/// Get the fingerprint of a node's public key.
+/** This function returns a fingerprint of the node's public key.
+ *  It should be treated as an opaque blob.
+ *
+ *  @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.
+ *                      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);
+
 /// Get a list of all nodes.
 /** This function returns a list with handles for all known nodes.
  *