]> git.meshlink.io Git - meshlink/blob - src/meshlink.h
Provide a way to open MeshLink in its own network namespace.
[meshlink] / src / meshlink.h
1 #ifndef MESHLINK_H
2 #define MESHLINK_H
3
4 /*
5     meshlink.h -- MeshLink API
6     Copyright (C) 2014-2018 Guus Sliepen <guus@meshlink.io>
7
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17
18     You should have received a copy of the GNU General Public License along
19     with this program; if not, write to the Free Software Foundation, Inc.,
20     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 #include <stdint.h>
24 #include <stdbool.h>
25 #include <stddef.h>
26 #include <unistd.h>
27
28 #if defined(_WIN32)
29 #include <winsock2.h>
30 #else
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #endif
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 /// The length in bytes of a signature made with meshlink_sign()
40 #define MESHLINK_SIGLEN (64ul)
41
42 // The maximum length of fingerprints
43 #define MESHLINK_FINGERPRINTLEN (64ul)
44
45 /// A handle for an instance of MeshLink.
46 typedef struct meshlink_handle meshlink_handle_t;
47
48 /// A handle for a MeshLink node.
49 typedef struct meshlink_node meshlink_node_t;
50
51 /// A handle for a MeshLink channel.
52 typedef struct meshlink_channel meshlink_channel_t;
53
54 /// A struct containing all parameters used for opening a mesh.
55 typedef struct meshlink_open_params meshlink_open_params_t;
56
57 /// Code of most recent error encountered.
58 typedef enum {
59         MESHLINK_OK,        ///< Everything is fine
60         MESHLINK_EINVAL,    ///< Invalid parameter(s) to function call
61         MESHLINK_ENOMEM,    ///< Out of memory
62         MESHLINK_ENOENT,    ///< Node is not known
63         MESHLINK_EEXIST,    ///< Node already exists
64         MESHLINK_EINTERNAL, ///< MeshLink internal error
65         MESHLINK_ERESOLV,   ///< MeshLink could not resolve a hostname
66         MESHLINK_ESTORAGE,  ///< MeshLink coud not load or write data from/to disk
67         MESHLINK_ENETWORK,  ///< MeshLink encountered a network error
68         MESHLINK_EPEER,     ///< A peer caused an error
69         MESHLINK_ENOTSUP,   ///< The operation is not supported in the current configuration of MeshLink
70         MESHLINK_EBUSY,     ///< The MeshLink instance is already in use by another process
71 } meshlink_errno_t;
72
73 /// Device class
74 typedef enum {
75         DEV_CLASS_BACKBONE = 0,
76         DEV_CLASS_STATIONARY = 1,
77         DEV_CLASS_PORTABLE = 2,
78         DEV_CLASS_UNKNOWN = 3,
79         _DEV_CLASS_MAX = 3
80 } dev_class_t;
81
82 /// Invitation flags
83 static const uint32_t MESHLINK_INVITE_LOCAL = 1;    // Only use local addresses in the URL
84 static const uint32_t MESHLINK_INVITE_PUBLIC = 2;   // Only use public or canonical addresses in the URL
85 static const uint32_t MESHLINK_INVITE_IPV4 = 4;     // Only use IPv4 addresses in the URL
86 static const uint32_t MESHLINK_INVITE_IPV6 = 8;     // Only use IPv6 addresses in the URL
87 static const uint32_t MESHLINK_INVITE_NUMERIC = 16; // Don't look up hostnames
88
89 /// Channel flags
90 static const uint32_t MESHLINK_CHANNEL_RELIABLE = 1;   // Data is retransmitted when packets are lost.
91 static const uint32_t MESHLINK_CHANNEL_ORDERED = 2;    // Data is delivered in-order to the application.
92 static const uint32_t MESHLINK_CHANNEL_FRAMED = 4;     // Data is delivered in chunks of the same length as data was originally sent.
93 static const uint32_t MESHLINK_CHANNEL_DROP_LATE = 8;  // When packets are reordered, late packets are ignored.
94 static const uint32_t MESHLINK_CHANNEL_TCP = 3;        // Select TCP semantics.
95 static const uint32_t MESHLINK_CHANNEL_UDP = 0;        // Select UDP semantics.
96
97 /// A variable holding the last encountered error from MeshLink.
98 /** This is a thread local variable that contains the error code of the most recent error
99  *  encountered by a MeshLink API function called in the current thread.
100  *  The variable is only updated when an error is encountered, and is not reset to MESHLINK_OK
101  *  if a function returned succesfully.
102  */
103 extern __thread meshlink_errno_t meshlink_errno;
104
105 #ifndef MESHLINK_INTERNAL_H
106
107 struct meshlink_handle {
108         const char *const name; ///< Textual name of ourself. It is stored in a nul-terminated C string, which is allocated by MeshLink.
109         void *priv;             ///< Private pointer which may be set freely by the application, and is never used or modified by MeshLink.
110 };
111
112 struct meshlink_node {
113         const char *const name; ///< Textual name of this node. It is stored in a nul-terminated C string, which is allocated by MeshLink.
114         void *priv;             ///< Private pointer which may be set freely by the application, and is never used or modified by MeshLink.
115 };
116
117 struct meshlink_channel {
118         struct meshlink_node *const node; ///< Pointer to the peer of this channel.
119         void *priv;                       ///< Private pointer which may be set freely by the application, and is never used or modified by MeshLink.
120 };
121
122 struct meshlink_open_params {
123         /* This is an opaque struct, all parameters must be set using the corresponding meshlink_open_params_*() functions. */
124 };
125
126 #endif // MESHLINK_INTERNAL_H
127
128 /// Get the text for the given MeshLink error code.
129 /** This function returns a pointer to the string containing the description of the given error code.
130  *
131  *  @param err      An error code returned by MeshLink.
132  *
133  *  @return         A pointer to a string containing the description of the error code.
134  *                  The pointer is to static storage that is valid for the lifetime of the application.
135  *                  This function will always return a valid pointer, even if an invalid error code has been passed.
136  */
137 extern const char *meshlink_strerror(meshlink_errno_t err);
138
139 /// Create a new meshlink_open_params_t struct.
140 /** This function allocates and initializes a new meshlink_open_params_t struct that can be passed to meshlink_open_ex().
141  *  The resulting struct may be reused for multiple calls to meshlink_open_ex().
142  *  After the last use, the application must free this struct using meshlink_open_params_free().
143  *
144  *  @param confbase The directory in which MeshLink will store its configuration files.
145  *                  After the function returns, the application is free to overwrite or free @a confbase @a.
146  *  @param name     The name which this instance of the application will use in the mesh.
147  *                  After the function returns, the application is free to overwrite or free @a name @a.
148  *  @param appname  The application name which will be used in the mesh.
149  *                  After the function returns, the application is free to overwrite or free @a name @a.
150  *  @param devclass The device class which will be used in the mesh.
151  *
152  *  @return         A pointer to a meshlink_open_params_t which can be passed to meshlink_open_ex(), or NULL in case of an error.
153  *                  The pointer is valid until meshlink_open_params_free() is called.
154  */
155 extern meshlink_open_params_t *meshlink_open_params_init(const char *confbase, const char *name, const char *appname, dev_class_t devclass);
156
157 /// Free a meshlink_open_params_t struct.
158 /** This function frees a meshlink_open_params_t struct and all resources associated with it.
159  *
160  *  @param params   A pointer to a meshlink_open_params_t which must have been created earlier with meshlink_open_params_init().
161  */
162 extern void meshlink_open_params_free(meshlink_open_params_t *params);
163
164 /// Open or create a MeshLink instance.
165 /** This function opens or creates a MeshLink instance.
166  *  All parameters needed by MeshLink are passed via a meshlink_open_params_t struct,
167  *  which must have been initialized earlier by the application.
168  *
169  *  This function returns a pointer to a struct meshlink_handle that will be allocated by MeshLink.
170  *  When the application does no longer need to use this handle, it must call meshlink_close() to
171  *  free its resources.
172  *
173  *  This function does not start any network I/O yet. The application should
174  *  first set callbacks, and then call meshlink_start().
175  *
176  *  @param params   A pointer to a meshlink_open_params_t which must be filled in by the application.
177  *                  After the function returns, the application is free to reuse or free @a params @a.
178  *
179  *  @return         A pointer to a meshlink_handle_t which represents this instance of MeshLink, or NULL in case of an error.
180  *                  The pointer is valid until meshlink_close() is called.
181  */
182 extern meshlink_handle_t *meshlink_open_ex(const meshlink_open_params_t *params);
183
184 /// Open or create a MeshLink instance.
185 /** This function opens or creates a MeshLink instance.
186  *  The state is stored in the configuration directory passed in the variable @a confbase @a.
187  *  If the configuration directory does not exist yet, for example when it is the first time
188  *  this instance is opened, the configuration directory will be automatically created and initialized.
189  *  However, the parent directory should already exist, otherwise an error will be returned.
190  *
191  *  The name given should be a unique identifier for this instance.
192  *
193  *  This function returns a pointer to a struct meshlink_handle that will be allocated by MeshLink.
194  *  When the application does no longer need to use this handle, it must call meshlink_close() to
195  *  free its resources.
196  *
197  *  This function does not start any network I/O yet. The application should
198  *  first set callbacks, and then call meshlink_start().
199  *
200  *  @param confbase The directory in which MeshLink will store its configuration files.
201  *                  After the function returns, the application is free to overwrite or free @a confbase @a.
202  *  @param name     The name which this instance of the application will use in the mesh.
203  *                  After the function returns, the application is free to overwrite or free @a name @a.
204  *  @param appname  The application name which will be used in the mesh.
205  *                  After the function returns, the application is free to overwrite or free @a name @a.
206  *  @param devclass The device class which will be used in the mesh.
207  *
208  *  @return         A pointer to a meshlink_handle_t which represents this instance of MeshLink, or NULL in case of an error.
209  *                  The pointer is valid until meshlink_close() is called.
210  */
211 extern meshlink_handle_t *meshlink_open(const char *confbase, const char *name, const char *appname, dev_class_t devclass);
212
213 /// Start MeshLink.
214 /** This function causes MeshLink to open network sockets, make outgoing connections, and
215  *  create a new thread, which will handle all network I/O.
216  *
217  *  It is allowed to call this function even if MeshLink is already started, in which case it will return true.
218  *
219  *  @param mesh     A handle which represents an instance of MeshLink.
220  *
221  *  @return         This function will return true if MeshLink has succesfully started, false otherwise.
222  */
223 extern bool meshlink_start(meshlink_handle_t *mesh);
224
225 /// Stop MeshLink.
226 /** This function causes MeshLink to disconnect from all other nodes,
227  *  close all sockets, and shut down its own thread.
228  *
229  *  This function always succeeds. It is allowed to call meshlink_stop() even if MeshLink is already stopped or has never been started.
230  *  Channels that are still open will remain valid, but any communication via channels will stop as well.
231  *
232  *  @param mesh     A handle which represents an instance of MeshLink.
233  */
234 extern void meshlink_stop(meshlink_handle_t *mesh);
235
236 /// Close the MeshLink handle.
237 /** This function calls meshlink_stop() if necessary,
238  *  and frees the struct meshlink_handle and all associacted memory allocated by MeshLink, including all channels.
239  *  Afterwards, the handle and any pointers to a struct meshlink_node or struct meshlink_channel are invalid.
240  *
241  *  It is allowed to call this function at any time on a valid handle, except inside callback functions.
242  *  If called at a proper time with a valid handle, this function always succeeds.
243  *  If called within a callback or with an invalid handle, the result is undefined.
244  *
245  *  @param mesh     A handle which represents an instance of MeshLink.
246  */
247 extern void meshlink_close(meshlink_handle_t *mesh);
248
249 /// Destroy a MeshLink instance.
250 /** This function remove all configuration files of a MeshLink instance. It should only be called when the application
251  *  does not have an open handle to this instance. Afterwards, a call to meshlink_open() will create a completely
252  *  new instance.
253  *
254  *  @param confbase The directory in which MeshLink stores its configuration files.
255  *                  After the function returns, the application is free to overwrite or free @a confbase @a.
256  *
257  *  @return         This function will return true if the MeshLink instance was succesfully destroyed, false otherwise.
258  */
259 extern bool meshlink_destroy(const char *confbase);
260
261 /// A callback for receiving data from the mesh.
262 /** @param mesh      A handle which represents an instance of MeshLink.
263  *  @param source    A pointer to a meshlink_node_t describing the source of the data.
264  *  @param data      A pointer to a buffer containing the data sent by the source, or NULL in case there is no data (an empty packet was received).
265  *                   The pointer is only valid during the lifetime of the callback.
266  *                   The callback should mempcy() the data if it needs to be available outside the callback.
267  *  @param len       The length of the received data, or 0 in case there is no data.
268  */
269 typedef void (*meshlink_receive_cb_t)(meshlink_handle_t *mesh, meshlink_node_t *source, const void *data, size_t len);
270
271 /// Set the receive callback.
272 /** This functions sets the callback that is called whenever another node sends data to the local node.
273  *  The callback is run in MeshLink's own thread.
274  *  It is therefore important that the callback uses apprioriate methods (queues, pipes, locking, etc.)
275  *  to hand the data over to the application's thread.
276  *  The callback should also not block itself and return as quickly as possible.
277  *
278  *  @param mesh      A handle which represents an instance of MeshLink.
279  *  @param cb        A pointer to the function which will be called when another node sends data to the local node.
280  *                   If a NULL pointer is given, the callback will be disabled.
281  */
282 extern void meshlink_set_receive_cb(meshlink_handle_t *mesh, meshlink_receive_cb_t cb);
283
284 /// A callback reporting node status changes.
285 /** @param mesh       A handle which represents an instance of MeshLink.
286  *  @param node       A pointer to a meshlink_node_t describing the node whose status changed.
287  *                    This pointer is valid until meshlink_close() is called.
288  *  @param reachable  True if the node is reachable, false otherwise.
289  */
290 typedef void (*meshlink_node_status_cb_t)(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable);
291
292 /// Set the node status callback.
293 /** This functions sets the callback that is called whenever another node's status changed.
294  *  The callback is run in MeshLink's own thread.
295  *  It is therefore important that the callback uses apprioriate methods (queues, pipes, locking, etc.)
296  *  to hand the data over to the application's thread.
297  *  The callback should also not block itself and return as quickly as possible.
298  *
299  *  @param mesh      A handle which represents an instance of MeshLink.
300  *  @param cb        A pointer to the function which will be called when another node's status changes.
301  *                   If a NULL pointer is given, the callback will be disabled.
302  */
303 extern void meshlink_set_node_status_cb(meshlink_handle_t *mesh, meshlink_node_status_cb_t cb);
304
305 /// A callback reporting duplicate node detection.
306 /** @param mesh       A handle which represents an instance of MeshLink.
307  *  @param node       A pointer to a meshlink_node_t describing the node which is duplicate.
308  *                    This pointer is valid until meshlink_close() is called.
309  */
310 typedef void (*meshlink_node_duplicate_cb_t)(meshlink_handle_t *mesh, meshlink_node_t *node);
311
312 /// Set the node duplicate callback.
313 /** This functions sets the callback that is called whenever a duplicate node is detected.
314  *  The callback is run in MeshLink's own thread.
315  *  It is therefore important that the callback uses apprioriate methods (queues, pipes, locking, etc.)
316  *  to hand the data over to the application's thread.
317  *  The callback should also not block itself and return as quickly as possible.
318  *
319  *  @param mesh      A handle which represents an instance of MeshLink.
320  *  @param cb        A pointer to the function which will be called when a duplicate node is detected.
321  *                   If a NULL pointer is given, the callback will be disabled.
322  */
323 extern void meshlink_set_node_duplicate_cb(meshlink_handle_t *mesh, meshlink_node_duplicate_cb_t cb);
324
325 /// Severity of log messages generated by MeshLink.
326 typedef enum {
327         MESHLINK_DEBUG,    ///< Internal debugging messages. Only useful during application development.
328         MESHLINK_INFO,     ///< Informational messages.
329         MESHLINK_WARNING,  ///< Warnings which might indicate problems, but which are not real errors.
330         MESHLINK_ERROR,    ///< Errors which hamper correct functioning of MeshLink, without causing it to fail completely.
331         MESHLINK_CRITICAL, ///< Critical errors which cause MeshLink to fail completely.
332 } meshlink_log_level_t;
333
334 /// A callback for receiving log messages generated by MeshLink.
335 /** @param mesh      A handle which represents an instance of MeshLink, or NULL.
336  *  @param level     An enum describing the severity level of the message.
337  *  @param text      A pointer to a nul-terminated C string containing the textual log message.
338  *                   This pointer is only valid for the duration of the callback.
339  *                   The application must not free() this pointer.
340  *                   The application should strdup() the text if it has to be available outside the callback.
341  */
342 typedef void (*meshlink_log_cb_t)(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text);
343
344 /// Set the log callback.
345 /** This functions sets the callback that is called whenever MeshLink has some information to log.
346  *
347  *  The @a mesh @a parameter can either be a valid MeshLink handle, or NULL.
348  *  In case it is NULL, the callback will be called for errors that happen outside the context of a valid mesh instance.
349  *  Otherwise, it will be called for errors that happen in the context of the given mesh instance.
350  *
351  *  If @a mesh @a is not NULL, then the callback is run in MeshLink's own thread.
352  *  It is important that the callback uses apprioriate methods (queues, pipes, locking, etc.)
353  *  to hand the data over to the application's thread.
354  *  The callback should also not block itself and return as quickly as possible.
355  *
356  *  The @a mesh @a parameter can either be a valid MeshLink handle, or NULL.
357  *  In case it is NULL, the callback will be called for errors that happen outside the context of a valid mesh instance.
358  *  Otherwise, it will be called for errors that happen in the context of the given mesh instance.
359  *
360  *  @param mesh      A handle which represents an instance of MeshLink, or NULL.
361  *  @param level     An enum describing the minimum severity level. Debugging information with a lower level will not trigger the callback.
362  *  @param cb        A pointer to the function which will be called when another node sends data to the local node.
363  *                   If a NULL pointer is given, the callback will be disabled.
364  */
365 extern void meshlink_set_log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, meshlink_log_cb_t cb);
366
367 /// Send data to another node.
368 /** This functions sends one packet of data to another node in the mesh.
369  *  The packet is sent using UDP semantics, which means that
370  *  the packet is sent as one unit and is received as one unit,
371  *  and that there is no guarantee that the packet will arrive at the destination.
372  *  Packets that are too big to be sent over the network as one unit might be dropped, and this function may return an error if this situation can be detected beforehand.
373  *  The application should not send packets that are larger than the path MTU, which can be queried with meshlink_get_pmtu().
374  *  The application should take care of getting an acknowledgement and retransmission if necessary.
375  *
376  *  @param mesh         A handle which represents an instance of MeshLink.
377  *  @param destination  A pointer to a meshlink_node_t describing the destination for the data.
378  *  @param data         A pointer to a buffer containing the data to be sent to the source.
379  *                      After meshlink_send() returns, the application is free to overwrite or free this buffer.
380  *                      It is valid to specify a NULL pointer, but only if @a len @a is also 0.
381  *  @param len          The length of the data.
382  *  @return             This function will return true if MeshLink has queued the message for transmission, and false otherwise.
383  *                      A return value of true does not guarantee that the message will actually arrive at the destination.
384  */
385 extern bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const void *data, size_t len);
386
387 /// Query the maximum packet size that can be sent to a node.
388 /** This functions returns the maximum size of packets (path MTU) that can be sent to a specific node with meshlink_send().
389  *  The path MTU is a property of the path packets will take to the destination node over the Internet.
390  *  It can be different for different destination nodes.
391  *  and the path MTU can change at any point in time due to changes in the Internet.
392  *  Therefore, although this should only occur rarely, it can still happen that packets that do not exceed this size get dropped.
393  *
394  *  @param mesh         A handle which represents an instance of MeshLink.
395  *  @param destination  A pointer to a meshlink_node_t describing the destination for the data.
396  *
397  *  @return             The recommended maximum size of packets that are to be sent to the destination node, 0 if the node is unreachable,
398  *                      or a negative value in case of an error.
399  */
400 extern ssize_t meshlink_get_pmtu(meshlink_handle_t *mesh, meshlink_node_t *destination);
401
402 /// Get a handle for our own node.
403 /** This function returns a handle for the local node.
404  *
405  *  @param mesh         A handle which represents an instance of MeshLink.
406  *
407  *  @return             A pointer to a meshlink_node_t which represents the local node.
408  *                      The pointer is guaranteed to be valid until meshlink_close() is called.
409  */
410 extern meshlink_node_t *meshlink_get_self(meshlink_handle_t *mesh);
411
412 /// Get a handle for a specific node.
413 /** This function returns a handle for the node with the given name.
414  *
415  *  @param mesh         A handle which represents an instance of MeshLink.
416  *  @param name         The name of the node for which a handle is requested.
417  *                      After this function returns, the application is free to overwrite or free @a name @a.
418  *
419  *  @return             A pointer to a meshlink_node_t which represents the requested node,
420  *                      or NULL if the requested node does not exist.
421  *                      The pointer is guaranteed to be valid until meshlink_close() is called.
422  */
423 extern meshlink_node_t *meshlink_get_node(meshlink_handle_t *mesh, const char *name);
424
425 /// Get the fingerprint of a node's public key.
426 /** This function returns a fingerprint of the node's public key.
427  *  It should be treated as an opaque blob.
428  *
429  *  @param mesh         A handle which represents an instance of MeshLink.
430  *  @param node         A pointer to a meshlink_node_t describing the node.
431  *
432  *  @return             A nul-terminated C string containing the fingerprint of the node's public key in a printable ASCII format.
433  *                      The application should call free() after it is done using this string.
434  */
435 extern char *meshlink_get_fingerprint(meshlink_handle_t *mesh, meshlink_node_t *node);
436
437 /// Get a list of all nodes.
438 /** This function returns a list with handles for all known nodes.
439  *
440  *  @param mesh         A handle which represents an instance of MeshLink.
441  *  @param nodes        A pointer to a previously allocated array of pointers to meshlink_node_t, or NULL in which case MeshLink will allocate a new array.
442  *                      The application can supply an array it allocated itself with malloc, or the return value from the previous call to this function (which is the preferred way).
443  *                      The application is allowed to call free() on the array whenever it wishes.
444  *                      The pointers in the array are valid until meshlink_close() is called.
445  *  @param nmemb        A pointer to a variable holding the number of nodes that are stored in the array.
446  *                      In case the @a nodes @a argument is not NULL, MeshLink might call realloc() on the array to change its size.
447  *                      The contents of this variable will be changed to reflect the new size of the array.
448  *
449  *  @return             A pointer to an array containing pointers to all known nodes, or NULL in case of an error.
450  *                      If the @a nodes @a argument was not NULL, then the return value can either be the same value or a different value.
451  *                      If it is a new value, the old value of @a nodes @a should not be used anymore.
452  *                      If the new value is NULL, then the old array will have been freed by MeshLink.
453  */
454 extern meshlink_node_t **meshlink_get_all_nodes(meshlink_handle_t *mesh, meshlink_node_t **nodes, size_t *nmemb);
455
456 /// Sign data using the local node's MeshLink key.
457 /** This function signs data using the local node's MeshLink key.
458  *  The generated signature can be securely verified by other nodes.
459  *
460  *  @param mesh         A handle which represents an instance of MeshLink.
461  *  @param data         A pointer to a buffer containing the data to be signed.
462  *  @param len          The length of the data to be signed.
463  *  @param signature    A pointer to a buffer where the signature will be stored.
464  *                      The buffer must be allocated by the application, and should be at least MESHLINK_SIGLEN bytes big.
465  *                      The signature is a binary blob, and is not nul-terminated.
466  *  @param siglen       The size of the signature buffer. Will be changed after the call to match the size of the signature itself.
467  *
468  *  @return             This function returns true if the signature was correctly generated, false otherwise.
469  */
470 extern bool meshlink_sign(meshlink_handle_t *mesh, const void *data, size_t len, void *signature, size_t *siglen);
471
472 /// Verify the signature generated by another node of a piece of data.
473 /** This function verifies the signature that another node generated for a piece of data.
474  *
475  *  @param mesh         A handle which represents an instance of MeshLink.
476  *  @param source       A pointer to a meshlink_node_t describing the source of the signature.
477  *  @param data         A pointer to a buffer containing the data to be verified.
478  *  @param len          The length of the data to be verified.
479  *  @param signature    A pointer to a buffer where the signature is stored.
480  *  @param siglen       A pointer to a variable holding the size of the signature buffer.
481  *                      The contents of the variable will be changed by meshlink_sign() to reflect the actual size of the signature.
482  *
483  *  @return             This function returns true if the signature is valid, false otherwise.
484  */
485 extern bool meshlink_verify(meshlink_handle_t *mesh, meshlink_node_t *source, const void *data, size_t len, const void *signature, size_t siglen);
486
487 /// Set the canonical Address for a node.
488 /** This function sets the canonical Address for a node.
489  *  This address is stored permanently until it is changed by another call to this function,
490  *  unlike other addresses associated with a node,
491  *  such as those added with meshlink_hint_address() or addresses discovered at runtime.
492  *
493  *  If a canonical Address is set for the local node,
494  *  it will be used for the hostname part of generated invitation URLs.
495  *
496  *  @param mesh         A handle which represents an instance of MeshLink.
497  *  @param node         A pointer to a meshlink_node_t describing the node.
498  *  @param address      A nul-terminated C string containing the address, which can be either in numeric format or a hostname.
499  *  @param port         A nul-terminated C string containing the port, which can be either in numeric or symbolic format.
500  *                      If it is NULL, the listening port's number will be used.
501  *
502  *  @return             This function returns true if the address was added, false otherwise.
503  */
504 extern bool meshlink_set_canonical_address(meshlink_handle_t *mesh, meshlink_node_t *node, const char *address, const char *port);
505
506 /// Add an Address for the local node.
507 /** This function adds an Address for the local node, which will be used for invitation URLs.
508  *
509  *  @param mesh         A handle which represents an instance of MeshLink.
510  *  @param address      A nul-terminated C string containing the address, which can be either in numeric format or a hostname.
511  *
512  *  @return             This function returns true if the address was added, false otherwise.
513  */
514 extern bool meshlink_add_address(meshlink_handle_t *mesh, const char *address);
515
516 /// Try to discover the external address for the local node.
517 /** This function performs tries to discover the local node's external address
518  *  by contacting the meshlink.io server. If a reverse lookup of the address works,
519  *  the FQDN associated with the address will be returned.
520  *
521  *  Please note that this is function only returns a single address,
522  *  even if the local node might have more than one external address.
523  *  In that case, there is no control over which address will be selected.
524  *  Also note that if you have a dynamic IP address, or are behind carrier-grade NAT,
525  *  there is no guarantee that the external address will be valid for an extended period of time.
526  *
527  *  This function is blocking. It can take several seconds before it returns.
528  *  There is no guarantee it will be able to resolve the external address.
529  *  Failures might be because by temporary network outages.
530  *
531  *  @param mesh         A handle which represents an instance of MeshLink.
532  *
533  *  @return             This function returns a pointer to a C string containing the discovered external address,
534  *                      or NULL if there was an error looking up the address.
535  *                      After meshlink_get_external_address() returns, the application is free to overwrite or free this string.
536  */
537 extern char *meshlink_get_external_address(meshlink_handle_t *mesh);
538
539 /// Try to discover the external address for the local node.
540 /** This function performs tries to discover the local node's external address
541  *  by contacting the meshlink.io server. If a reverse lookup of the address works,
542  *  the FQDN associated with the address will be returned.
543  *
544  *  Please note that this is function only returns a single address,
545  *  even if the local node might have more than one external address.
546  *  In that case, there is no control over which address will be selected.
547  *  Also note that if you have a dynamic IP address, or are behind carrier-grade NAT,
548  *  there is no guarantee that the external address will be valid for an extended period of time.
549  *
550  *  This function is blocking. It can take several seconds before it returns.
551  *  There is no guarantee it will be able to resolve the external address.
552  *  Failures might be because by temporary network outages.
553  *
554  *  @param mesh         A handle which represents an instance of MeshLink.
555  *  @param family       The address family to check, for example AF_INET or AF_INET6. If AF_UNSPEC is given,
556  *                      this might return the external address for any working address family.
557  *
558  *  @return             This function returns a pointer to a C string containing the discovered external address,
559  *                      or NULL if there was an error looking up the address.
560  *                      After meshlink_get_external_address_for_family() returns, the application is free to overwrite or free this string.
561  */
562 extern char *meshlink_get_external_address_for_family(meshlink_handle_t *mesh, int address_family);
563
564 /// Try to discover the local address for the local node.
565 /** This function performs tries to discover the address of the local interface used for outgoing connection.
566  *
567  *  Please note that this is function only returns a single address,
568  *  even if the interface might have more than one address.
569  *  In that case, there is no control over which address will be selected.
570  *  Also note that if you have a dynamic IP address,
571  *  there is no guarantee that the local address will be valid for an extended period of time.
572  *
573  *  This function will fail if it couldn't find a local address for the given address family.
574  *  If hostname resolving is requested, this function may block for a few seconds.
575  *
576  *  @param mesh         A handle which represents an instance of MeshLink.
577  *  @param family       The address family to check, for example AF_INET or AF_INET6. If AF_UNSPEC is given,
578  *                      this might return the local address for any working address family.
579  *
580  *  @return             This function returns a pointer to a C string containing the discovered local address,
581  *                      or NULL if there was an error looking up the address.
582  *                      After meshlink_get_local_address_for_family() returns, the application is free to overwrite or free this string.
583  */
584 extern char *meshlink_get_local_address_for_family(meshlink_handle_t *mesh, int address_family);
585
586 /// Try to discover the external address for the local node, and add it to its list of addresses.
587 /** This function is equivalent to:
588  *
589  *    meshlink_add_address(mesh, meshlink_get_external_address(mesh));
590  *
591  *  Read the description of meshlink_get_external_address() for the limitations of this function.
592  *
593  *  @param mesh         A handle which represents an instance of MeshLink.
594  *
595  *  @return             This function returns true if the address was added, false otherwise.
596  */
597 extern bool meshlink_add_external_address(meshlink_handle_t *mesh);
598
599 /// Get the network port used by the local node.
600 /** This function returns the network port that the local node is listening on.
601  *
602  *  @param mesh          A handle which represents an instance of MeshLink.
603  *
604  *  @return              This function returns the port number, or -1 in case of an error.
605  */
606 extern int meshlink_get_port(meshlink_handle_t *mesh);
607
608 /// Set the network port used by the local node.
609 /** This function sets the network port that the local node is listening on.
610  *  It may only be called when the mesh is not running.
611  *  If unsure, call meshlink_stop() before calling this function.
612  *  Also note that if your node is already part of a mesh with other nodes,
613  *  that the other nodes may no longer be able to initiate connections to the local node,
614  *  since they will try to connect to the previously configured port.
615  *
616  *  @param mesh          A handle which represents an instance of MeshLink.
617  *  @param port          The port number to listen on. This must be between 0 and 65535.
618  *                       If the port is set to 0, then MeshLink will listen on a port
619  *                       that is randomly assigned by the operating system every time meshlink_open() is called.
620  *
621  *  @return              This function returns true if the port was succesfully changed, false otherwise.
622  */
623
624 extern bool meshlink_set_port(meshlink_handle_t *mesh, int port);
625
626 /// Set the timeout for invitations.
627 /** This function sets the timeout for invitations.
628  *  Note that timeouts are only checked at the time a node tries to join using an invitation.
629  *  The default timeout for invitations is 1 week.
630  *
631  *  @param mesh         A handle which represents an instance of MeshLink.
632  *  @param timeout      The timeout for invitations in seconds.
633  */
634 extern void meshlink_set_invitation_timeout(meshlink_handle_t *mesh, int timeout);
635
636 /// Invite another node into the mesh.
637 /** This function generates an invitation that can be used by another node to join the same mesh as the local node.
638  *  The generated invitation is a string containing a URL.
639  *  This URL should be passed by the application to the invitee in a way that no eavesdroppers can see the URL.
640  *  The URL can only be used once, after the user has joined the mesh the URL is no longer valid.
641  *
642  *  @param mesh         A handle which represents an instance of MeshLink.
643  *  @param name         A nul-terminated C string containing the name that the invitee will be allowed to use in the mesh.
644  *                      After this function returns, the application is free to overwrite or free @a name @a.
645  *  @param flags        A bitwise-or'd combination of flags that controls how the URL is generated.
646  *
647  *  @return             This function returns a nul-terminated C string that contains the invitation URL, or NULL in case of an error.
648  *                      The application should call free() after it has finished using the URL.
649  */
650 extern char *meshlink_invite_ex(meshlink_handle_t *mesh, const char *name, uint32_t flags);
651
652 /// Invite another node into the mesh.
653 /** This function generates an invitation that can be used by another node to join the same mesh as the local node.
654  *  The generated invitation is a string containing a URL.
655  *  This URL should be passed by the application to the invitee in a way that no eavesdroppers can see the URL.
656  *  The URL can only be used once, after the user has joined the mesh the URL is no longer valid.
657  *
658  *  Calling this function is equal to callen meshlink_invite_ex() with flags set to 0.
659  *
660  *  @param mesh         A handle which represents an instance of MeshLink.
661  *  @param name         A nul-terminated C string containing the name that the invitee will be allowed to use in the mesh.
662  *                      After this function returns, the application is free to overwrite or free @a name @a.
663  *
664  *  @return             This function returns a nul-terminated C string that contains the invitation URL, or NULL in case of an error.
665  *                      The application should call free() after it has finished using the URL.
666  */
667 extern char *meshlink_invite(meshlink_handle_t *mesh, const char *name);
668
669 /// Use an invitation to join a mesh.
670 /** This function allows the local node to join an existing mesh using an invitation URL generated by another node.
671  *  An invitation can only be used if the local node has never connected to other nodes before.
672  *  After a succesfully accepted invitation, the name of the local node may have changed.
673  *
674  *  This function may only be called on a mesh that has not been started yet and which is not already part of an existing mesh.
675  *
676  *  This function is blocking. It can take several seconds before it returns.
677  *  There is no guarantee it will perform a successful join.
678  *  Failures might be caused by temporary network outages, or by the invitation having expired.
679  *
680  *  @param mesh         A handle which represents an instance of MeshLink.
681  *  @param invitation   A nul-terminated C string containing the invitation URL.
682  *                      After this function returns, the application is free to overwrite or free @a invitation @a.
683  *
684  *  @return             This function returns true if the local node joined the mesh it was invited to, false otherwise.
685  */
686 extern bool meshlink_join(meshlink_handle_t *mesh, const char *invitation);
687
688 /// Export the local node's key and addresses.
689 /** This function generates a string that contains the local node's public key and one or more IP addresses.
690  *  The application can pass it in some way to another node, which can then import it,
691  *  granting the local node access to the other node's mesh.
692  *  The exported data does not contain any secret keys, it is therefore safe to transmit this data unencrypted over public networks.
693  *
694  *  Note that to create a working connection between two nodes, both must call meshink_export() and both must meshlink_import() each other's data.
695  *
696  *  @param mesh         A handle which represents an instance of MeshLink.
697  *
698  *  @return             This function returns a nul-terminated C string that contains the exported key and addresses, or NULL in case of an error.
699  *                      The application should call free() after it has finished using this string.
700  */
701 extern char *meshlink_export(meshlink_handle_t *mesh);
702
703 /// Import another node's key and addresses.
704 /** This function accepts a string containing the exported public key and addresses of another node.
705  *  By importing this data, the local node grants the other node access to its mesh.
706  *  The application should make sure that the data it imports is really coming from the node it wants to import,
707  *
708  *  Note that to create a working connection between two nodes, both must call meshink_export() and both must meshlink_import() each other's data.
709  *
710  *  @param mesh         A handle which represents an instance of MeshLink.
711  *  @param data         A nul-terminated C string containing the other node's exported key and addresses.
712  *                      After this function returns, the application is free to overwrite or free @a data @a.
713  *
714  *  @return             This function returns true if the data was valid and the other node has been granted access to the mesh, false otherwise.
715  */
716 extern bool meshlink_import(meshlink_handle_t *mesh, const char *data);
717
718 /// Blacklist a node from the mesh.
719 /** This function causes the local node to blacklist another node.
720  *  The local node will drop any existing connections to that node,
721  *  and will not send data to it nor accept any data received from it any more.
722  *
723  *  @param mesh         A handle which represents an instance of MeshLink.
724  *  @param node         A pointer to a meshlink_node_t describing the node to be blacklisted.
725  */
726 extern void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node);
727
728 /// Whitelist a node on the mesh.
729 /** This function causes the local node to whitelist a previously blacklisted node.
730  *  The local node will allow connections to and from that node,
731  *  and will send data to it and accept any data received from it.
732  *
733  *  @param mesh         A handle which represents an instance of MeshLink.
734  *  @param node         A pointer to a meshlink_node_t describing the node to be whitelisted.
735  */
736 extern void meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node);
737
738 /// Set whether new nodes are blacklisted by default.
739 /** This function sets the blacklist behaviour for newly discovered nodes.
740  *  If set to true, new nodes will be automatically blacklisted.
741  *  If set to false, which is the default, new nodes are automatically whitelisted.
742  *  The whitelist/blacklist status of a node may be changed afterwards with the
743  *  meshlink_whitelist() and meshlink_blacklist() functions.
744  *
745  *  @param mesh         A handle which represents an instance of MeshLink.
746  *  @param blacklist    True if new nodes are to be blacklisted, false if whitelisted.
747  */
748 extern void meshlink_set_default_blacklist(meshlink_handle_t *mesh, bool blacklist);
749
750 /// A callback for accepting incoming channels.
751 /** This function is called whenever a remote node wants to open a channel to the local node.
752  *  The application then has to decide whether to accept or reject this channel.
753  *
754  *  The callback is run in MeshLink's own thread.
755  *  It is therefore important that the callback return quickly and uses apprioriate methods (queues, pipes, locking, etc.)
756  *  to hand any data over to the application's thread.
757  *
758  *  @param mesh         A handle which represents an instance of MeshLink.
759  *  @param channel      A handle for the incoming channel.
760  *                      If the application accepts the incoming channel by returning true,
761  *                      then this handle is valid until meshlink_channel_close() is called on it.
762  *                      If the application rejects the incoming channel by returning false,
763  *                      then this handle is invalid after the callback returns
764  *                      (the callback does not need to call meshlink_channel_close() itself in this case).
765  *  @param port         The port number the peer wishes to connect to.
766  *  @param data         A pointer to a buffer containing data already received, or NULL in case no data has been received yet. (Not yet used.)
767  *                      The pointer is only valid during the lifetime of the callback.
768  *                      The callback should mempcy() the data if it needs to be available outside the callback.
769  *  @param len          The length of the data, or 0 in case no data has been received yet. (Not yet used.)
770  *
771  *  @return             This function should return true if the application accepts the incoming channel, false otherwise.
772  *                      If returning false, the channel is invalid and may not be used anymore.
773  */
774 typedef bool (*meshlink_channel_accept_cb_t)(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len);
775
776 /// A callback for receiving data from a channel.
777 /** This function is called whenever data is received from a remote node on a channel.
778  *
779  *  This function is also called in case the channel has been closed by the remote node, or when the channel is terminated abnormally.
780  *  In both cases, @a data @a will be NULL and @a len @a will be 0, and meshlink_errno will be set.
781  *  In any case, the @a channel @a handle will still be valid until the application calls meshlink_close().
782  *
783  *  @param mesh         A handle which represents an instance of MeshLink.
784  *  @param channel      A handle for the channel.
785  *  @param data         A pointer to a buffer containing data sent by the source, or NULL in case of an error.
786  *                      The pointer is only valid during the lifetime of the callback.
787  *                      The callback should mempcy() the data if it needs to be available outside the callback.
788  *  @param len          The length of the data, or 0 in case of an error.
789  */
790 typedef void (*meshlink_channel_receive_cb_t)(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len);
791
792 /// A callback informing the application when data can be sent on a channel.
793 /** This function is called whenever there is enough free buffer space so a call to meshlink_channel_send() will succeed.
794  *
795  *  @param mesh         A handle which represents an instance of MeshLink.
796  *  @param channel      A handle for the channel.
797  *  @param len          The maximum amount of data that is guaranteed to be accepted by meshlink_channel_send(),
798  *                      or 0 in case of an error.
799  */
800 typedef void (*meshlink_channel_poll_cb_t)(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len);
801
802 /// Set the accept callback.
803 /** This functions sets the callback that is called whenever another node sends data to the local node.
804  *  The callback is run in MeshLink's own thread.
805  *  It is therefore important that the callback uses apprioriate methods (queues, pipes, locking, etc.)
806  *  to hand the data over to the application's thread.
807  *  The callback should also not block itself and return as quickly as possible.
808  *
809  *  If no accept callback is set, incoming channels are rejected.
810  *
811  *  @param mesh      A handle which represents an instance of MeshLink.
812  *  @param cb        A pointer to the function which will be called when another node sends data to the local node.
813  *                   If a NULL pointer is given, the callback will be disabled.
814  */
815 extern void meshlink_set_channel_accept_cb(meshlink_handle_t *mesh, meshlink_channel_accept_cb_t cb);
816
817 /// Set the receive callback.
818 /** This functions sets the callback that is called whenever another node sends data to the local node.
819  *  The callback is run in MeshLink's own thread.
820  *  It is therefore important that the callback uses apprioriate methods (queues, pipes, locking, etc.)
821  *  to hand the data over to the application's thread.
822  *  The callback should also not block itself and return as quickly as possible.
823  *
824  *  @param mesh      A handle which represents an instance of MeshLink.
825  *  @param channel   A handle for the channel.
826  *  @param cb        A pointer to the function which will be called when another node sends data to the local node.
827  *                   If a NULL pointer is given, the callback will be disabled and incoming data is ignored.
828  */
829 extern void meshlink_set_channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, meshlink_channel_receive_cb_t cb);
830
831 /// Set the poll callback.
832 /** This functions sets the callback that is called whenever data can be sent to another node.
833  *  The callback is run in MeshLink's own thread.
834  *  It is therefore important that the callback uses apprioriate methods (queues, pipes, locking, etc.)
835  *  to pass data to or from the application's thread.
836  *  The callback should also not block itself and return as quickly as possible.
837  *
838  *  @param mesh      A handle which represents an instance of MeshLink.
839  *  @param channel   A handle for the channel.
840  *  @param cb        A pointer to the function which will be called when data can be sent to another node.
841  *                   If a NULL pointer is given, the callback will be disabled.
842  */
843 extern void meshlink_set_channel_poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, meshlink_channel_poll_cb_t cb);
844
845 /// Open a reliable stream channel to another node.
846 /** This function is called whenever a remote node wants to open a channel to the local node.
847  *  The application then has to decide whether to accept or reject this channel.
848  *
849  *  This function returns a pointer to a struct meshlink_channel that will be allocated by MeshLink.
850  *  When the application does no longer need to use this channel, it must call meshlink_close()
851  *  to free its resources.
852  *
853  *  @param mesh         A handle which represents an instance of MeshLink.
854  *  @param node         The node to which this channel is being initiated.
855  *  @param port         The port number the peer wishes to connect to.
856  *  @param cb           A pointer to the function which will be called when the remote node sends data to the local node.
857  *                      The pointer may be NULL, in which case incoming data is ignored.
858  *  @param data         A pointer to a buffer containing data to already queue for sending, or NULL if there is no data to send.
859  *                      After meshlink_send() returns, the application is free to overwrite or free this buffer.
860  *  @param len          The length of the data, or 0 if there is no data to send.
861  *  @param flags        A bitwise-or'd combination of flags that set the semantics for this channel.
862  *
863  *  @return             A handle for the channel, or NULL in case of an error.
864  *                      The handle is valid until meshlink_channel_close() is called.
865  */
866 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);
867
868 /// Open a reliable stream channel to another node.
869 /** This function is called whenever a remote node wants to open a channel to the local node.
870  *  The application then has to decide whether to accept or reject this channel.
871  *
872  *  This function returns a pointer to a struct meshlink_channel that will be allocated by MeshLink.
873  *  When the application does no longer need to use this channel, it must call meshlink_close()
874  *  to free its resources.
875  *
876  *  Calling this function is equivalent to calling meshlink_channel_open_ex()
877  *  with the flags set to MESHLINK_CHANNEL_TCP.
878  *
879  *  @param mesh         A handle which represents an instance of MeshLink.
880  *  @param node         The node to which this channel is being initiated.
881  *  @param port         The port number the peer wishes to connect to.
882  *  @param cb           A pointer to the function which will be called when the remote node sends data to the local node.
883  *                      The pointer may be NULL, in which case incoming data is ignored.
884  *  @param data         A pointer to a buffer containing data to already queue for sending, or NULL if there is no data to send.
885  *                      After meshlink_send() returns, the application is free to overwrite or free this buffer.
886  *  @param len          The length of the data, or 0 if there is no data to send.
887  *
888  *  @return             A handle for the channel, or NULL in case of an error.
889  *                      The handle is valid until meshlink_channel_close() is called.
890  */
891 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);
892
893 /// Partially close a reliable stream channel.
894 /** This shuts down the read or write side of a channel, or both, without closing the handle.
895  *  It can be used to inform the remote node that the local node has finished sending all data on the channel,
896  *  but still allows waiting for incoming data from the remote node.
897  *
898  *  Shutting down the receive direction is also possible, and is equivalent to setting the receive callback to NULL.
899  *
900  *  @param mesh         A handle which represents an instance of MeshLink.
901  *  @param channel      A handle for the channel.
902  *  @param direction    Must be one of SHUT_RD, SHUT_WR or SHUT_RDWR, otherwise this call will not have any affect.
903  */
904 extern void meshlink_channel_shutdown(meshlink_handle_t *mesh, meshlink_channel_t *channel, int direction);
905
906 /// Close a reliable stream channel.
907 /** This informs the remote node that the local node has finished sending all data on the channel.
908  *  It also causes the local node to stop accepting incoming data from the remote node.
909  *  It will free the struct meshlink_channel and all associated resources.
910  *  Afterwards, the channel handle is invalid and must not be used any more.
911  *
912  *  It is allowed to call this function at any time on a valid handle, even inside callback functions.
913  *  If called with a valid handle, this function always succeeds, otherwise the result is undefined.
914  *
915  *  @param mesh         A handle which represents an instance of MeshLink.
916  *  @param channel      A handle for the channel.
917  */
918 extern void meshlink_channel_close(meshlink_handle_t *mesh, meshlink_channel_t *channel);
919
920 /// Transmit data on a channel
921 /** This queues data to send to the remote node.
922  *
923  *  @param mesh         A handle which represents an instance of MeshLink.
924  *  @param channel      A handle for the channel.
925  *  @param data         A pointer to a buffer containing data sent by the source, or NULL if there is no data to send.
926  *                      After meshlink_send() returns, the application is free to overwrite or free this buffer.
927  *  @param len          The length of the data, or 0 if there is no data to send.
928  *
929  *  @return             The amount of data that was queued, which can be less than len, or a negative value in case of an error.
930  */
931 extern ssize_t meshlink_channel_send(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len);
932
933 /// Get channel flags.
934 /** This returns the flags used when opening this channel.
935  *
936  *  @param mesh         A handle which represents an instance of MeshLink.
937  *  @param channel      A handle for the channel.
938  *
939  *  @return             The flags set for this channel.
940  */
941 extern uint32_t meshlink_channel_get_flags(meshlink_handle_t *mesh, meshlink_channel_t *channel);
942
943 /// Hint that a hostname may be found at an address
944 /** This function indicates to meshlink that the given hostname is likely found
945  *  at the given IP address and port.
946  *
947  *  @param mesh     A handle which represents an instance of MeshLink.
948  *  @param hostname The hostname which can be found at the given address.
949  *                  The caller is free to overwrite or free this string
950  *                  once meshlink returns.
951  *  @param addr     The IP address and port which should be tried for the
952  *                  given hostname. The caller is free to overwrite or free
953  *                  this memory once meshlink returns.
954  */
955 extern void meshlink_hint_address(meshlink_handle_t *mesh, meshlink_node_t *node, const struct sockaddr *addr);
956
957 /// Enable or disable zeroconf discovery of local peers
958
959 /** This controls whether zeroconf discovery using the Catta library will be
960  *  enabled to search for peers on the local network. By default, it is enabled.
961  *
962  *  @param mesh    A handle which represents an instance of MeshLink.
963  *  @param enable  Set to true to enable discovery, false to disable.
964  */
965 extern void meshlink_enable_discovery(meshlink_handle_t *mesh, bool enable);
966
967 #ifdef __cplusplus
968 }
969 #endif
970
971 #endif