11 struct sync_flag bar_reachable;
13 void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
16 if(reachable && !strcmp(node->name, "bar")) {
17 set_sync_flag(&bar_reachable, true);
22 meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
24 // Open two new meshlink instance.
26 assert(meshlink_destroy("import_export_conf.1"));
27 assert(meshlink_destroy("import_export_conf.2"));
29 meshlink_handle_t *mesh1 = meshlink_open("import_export_conf.1", "foo", "import-export", DEV_CLASS_BACKBONE);
32 meshlink_handle_t *mesh2 = meshlink_open("import_export_conf.2", "bar", "import-export", DEV_CLASS_BACKBONE);
35 // Disable local discovery
37 meshlink_enable_discovery(mesh1, false);
38 meshlink_enable_discovery(mesh2, false);
40 // Import and export both side's data
42 meshlink_add_address(mesh1, "localhost");
43 meshlink_add_address(mesh2, "localhost");
45 char *data = meshlink_export(mesh1);
48 assert(meshlink_import(mesh2, data));
51 data = meshlink_export(mesh2);
54 assert(meshlink_import(mesh1, data));
57 // Start both instances
59 meshlink_set_node_status_cb(mesh1, status_cb);
61 assert(meshlink_start(mesh1));
62 assert(meshlink_start(mesh2));
64 // Wait for the two to connect.
66 assert(wait_sync_flag(&bar_reachable, 20));
68 // Wait for UDP communication to become possible.
70 int pmtu = meshlink_get_pmtu(mesh2, meshlink_get_node(mesh2, "bar"));
72 for(int i = 0; i < 10 && !pmtu; i++) {
74 pmtu = meshlink_get_pmtu(mesh2, meshlink_get_node(mesh2, "bar"));
81 meshlink_close(mesh2);
82 meshlink_close(mesh1);