12 #include "meshlink-tiny.h"
15 static struct sync_flag bar_reachable;
17 static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
20 if(reachable && !strcmp(node->name, "bar")) {
21 set_sync_flag(&bar_reachable, true);
26 init_sync_flag(&bar_reachable);
28 meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
30 // Open two new meshlink instance.
32 assert(meshlink_destroy("import_export_conf.1"));
33 assert(meshlink_destroy("import_export_conf.2"));
35 meshlink_handle_t *mesh1 = meshlink_open("import_export_conf.1", "foo", "import-export", DEV_CLASS_BACKBONE);
38 meshlink_handle_t *mesh2 = meshlink_open("import_export_conf.2", "bar", "import-export", DEV_CLASS_BACKBONE);
41 // Import and export both side's data
43 assert(meshlink_set_canonical_address(mesh1, meshlink_get_self(mesh1), "localhost", NULL));
44 assert(meshlink_set_canonical_address(mesh2, meshlink_get_self(mesh2), "localhost", NULL));
46 char *data = meshlink_export(mesh1);
49 assert(meshlink_import(mesh2, data));
52 data = meshlink_export(mesh2);
55 assert(meshlink_import(mesh1, data));
57 // Check that importing twice is fine
58 assert(meshlink_import(mesh1, data));
61 // Check that importing garbage is not fine
62 assert(!meshlink_import(mesh1, "Garbage\n"));
64 // Check that foo knows bar, but that it is not reachable.
66 meshlink_node_t *bar = meshlink_get_node(mesh1, "bar");
71 meshlink_close(mesh2);
72 meshlink_close(mesh1);