8 volatile bool bar_reachable = false;
10 void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
13 if(!strcmp(node->name, "bar")) {
14 bar_reachable = reachable;
19 // Open two new meshlink instance.
21 meshlink_handle_t *mesh1 = meshlink_open("import_export_conf.1", "foo", "import-export", DEV_CLASS_BACKBONE);
24 fprintf(stderr, "Could not initialize configuration for foo\n");
28 meshlink_handle_t *mesh2 = meshlink_open("import_export_conf.2", "bar", "import-export", DEV_CLASS_BACKBONE);
31 fprintf(stderr, "Could not initialize configuration for bar\n");
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 fprintf(stderr, "Foo could not export its configuration\n");
52 if(!meshlink_import(mesh2, data)) {
53 fprintf(stderr, "Bar could not import foo's configuration\n");
59 data = meshlink_export(mesh2);
62 fprintf(stderr, "Bar could not export its configuration\n");
67 if(!meshlink_import(mesh1, data)) {
68 fprintf(stderr, "Foo could not import bar's configuration\n");
74 // Start both instances
76 meshlink_set_node_status_cb(mesh1, status_cb);
78 if(!meshlink_start(mesh1)) {
79 fprintf(stderr, "Foo could not start\n");
83 if(!meshlink_start(mesh2)) {
84 fprintf(stderr, "Bar could not start\n");
88 // Wait for the two to connect.
90 for(int i = 0; i < 20; i++) {
99 fprintf(stderr, "Bar not reachable for foo after 20 seconds\n");
103 int pmtu = meshlink_get_pmtu(mesh2, meshlink_get_node(mesh2, "bar"));
105 for(int i = 0; i < 10 && !pmtu; i++) {
107 pmtu = meshlink_get_pmtu(mesh2, meshlink_get_node(mesh2, "bar"));
111 fprintf(stderr, "UDP communication with bar not possible after 10 seconds\n");
117 meshlink_stop(mesh2);
118 meshlink_stop(mesh1);
119 meshlink_close(mesh2);
120 meshlink_close(mesh1);