7 void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) {
8 static struct timeval tv0;
12 gettimeofday(&tv0, NULL);
15 gettimeofday(&tv, NULL);
16 fprintf(stderr, "%u.%.03u ", (unsigned int)(tv.tv_sec - tv0.tv_sec), (unsigned int)tv.tv_usec / 1000);
19 fprintf(stderr, "(%s) ", mesh->name);
22 fprintf(stderr, "[%d] %s\n", level, text);
26 meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
28 // Open two ephemeral meshlink instance.
30 meshlink_handle_t *mesh1 = meshlink_open_ephemeral("foo", "ephemeral", DEV_CLASS_BACKBONE);
31 meshlink_handle_t *mesh2 = meshlink_open_ephemeral("bar", "ephemeral", DEV_CLASS_BACKBONE);
36 meshlink_set_log_cb(mesh1, MESHLINK_DEBUG, log_cb);
37 meshlink_set_log_cb(mesh2, MESHLINK_DEBUG, log_cb);
41 assert(meshlink_import(mesh1, meshlink_export(mesh2)));
42 assert(meshlink_import(mesh2, meshlink_export(mesh1)));
44 // Check that they know each other
46 assert(meshlink_get_node(mesh1, "bar"));
47 assert(meshlink_get_node(mesh2, "foo"));
49 // Close the ephemeral instances and reopen them.
51 meshlink_close(mesh1);
52 meshlink_close(mesh2);
54 mesh1 = meshlink_open_ephemeral("foo", "ephemeral", DEV_CLASS_BACKBONE);
55 mesh2 = meshlink_open_ephemeral("bar", "ephemeral", DEV_CLASS_BACKBONE);
60 meshlink_set_log_cb(mesh1, MESHLINK_DEBUG, log_cb);
61 meshlink_set_log_cb(mesh2, MESHLINK_DEBUG, log_cb);
63 // Check that the nodes no longer know each other
65 assert(!meshlink_get_node(mesh1, "bar"));
66 assert(!meshlink_get_node(mesh2, "foo"));
70 meshlink_close(mesh1);
71 meshlink_close(mesh2);