#include <unistd.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/time.h>
#include "meshlink.h"
volatile bool baz_reachable = false;
+void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) {
+ static struct timeval tv0;
+ struct timeval tv;
+
+ if(tv0.tv_sec == 0) {
+ gettimeofday(&tv0, NULL);
+ }
+
+ gettimeofday(&tv, NULL);
+ fprintf(stderr, "%u.%.03u ", (unsigned int)(tv.tv_sec - tv0.tv_sec), (unsigned int)tv.tv_usec / 1000);
+
+ if(mesh) {
+ fprintf(stderr, "(%s) ", mesh->name);
+ }
+
+ fprintf(stderr, "[%d] %s\n", level, text);
+}
+
void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
(void)mesh;
}
int main() {
- // Open two new meshlink instance.
+ meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
+
+ // Open thee new meshlink instance.
meshlink_handle_t *mesh1 = meshlink_open("invite_join_conf.1", "foo", "invite-join", DEV_CLASS_BACKBONE);
return 1;
}
+ meshlink_set_log_cb(mesh1, MESHLINK_DEBUG, log_cb);
+
meshlink_handle_t *mesh2 = meshlink_open("invite_join_conf.2", "bar", "invite-join", DEV_CLASS_BACKBONE);
if(!mesh2) {
return 1;
}
+ meshlink_set_log_cb(mesh2, MESHLINK_DEBUG, log_cb);
+
meshlink_handle_t *mesh3 = meshlink_open("invite_join_conf.3", "quux", "invite-join", DEV_CLASS_BACKBONE);
if(!mesh3) {
return 1;
}
+ meshlink_set_log_cb(mesh3, MESHLINK_DEBUG, log_cb);
+
// Disable local discovery.
meshlink_enable_discovery(mesh1, false);
return 1;
}
+ fprintf(stderr, "Invitation URL for baz: %s\n", baz_url);
+ fprintf(stderr, "Invitation URL for quux: %s\n", quux_url);
+
// Have the second instance join the first.
if(!meshlink_join(mesh2, baz_url)) {
// Clean up.
- meshlink_stop(mesh2);
- meshlink_stop(mesh1);
+ meshlink_close(mesh3);
meshlink_close(mesh2);
meshlink_close(mesh1);