8 volatile bool bar_reachable = false;
10 void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
11 if(!strcmp(node->name, "bar")) {
12 bar_reachable = reachable;
16 int main(int argc, char *argv[]) {
17 // Open two new meshlink instance.
19 meshlink_handle_t *mesh1 = meshlink_open("import_export_conf.1", "foo", "import-export", DEV_CLASS_BACKBONE);
22 fprintf(stderr, "Could not initialize configuration for foo\n");
26 meshlink_handle_t *mesh2 = meshlink_open("import_export_conf.2", "bar", "import-export", DEV_CLASS_BACKBONE);
29 fprintf(stderr, "Could not initialize configuration for bar\n");
33 // Disable local discovery
35 meshlink_enable_discovery(mesh1, false);
36 meshlink_enable_discovery(mesh2, false);
38 // Import and export both side's data
40 meshlink_add_address(mesh1, "localhost");
41 meshlink_add_address(mesh2, "localhost");
43 char *data = meshlink_export(mesh1);
46 fprintf(stderr, "Foo could not export its configuration\n");
50 if(!meshlink_import(mesh2, data)) {
51 fprintf(stderr, "Bar could not import foo's configuration\n");
57 data = meshlink_export(mesh2);
60 fprintf(stderr, "Bar could not export its configuration\n");
65 if(!meshlink_import(mesh1, data)) {
66 fprintf(stderr, "Foo could not import bar's configuration\n");
72 // Start both instances
74 meshlink_set_node_status_cb(mesh1, status_cb);
76 if(!meshlink_start(mesh1)) {
77 fprintf(stderr, "Foo could not start\n");
81 if(!meshlink_start(mesh2)) {
82 fprintf(stderr, "Bar could not start\n");
86 // Wait for the two to connect.
88 for(int i = 0; i < 20; i++) {
97 fprintf(stderr, "Bar not reachable for foo after 20 seconds\n");
101 int pmtu = meshlink_get_pmtu(mesh2, meshlink_get_node(mesh2, "bar"));
103 for(int i = 0; i < 10 && !pmtu; i++) {
105 pmtu = meshlink_get_pmtu(mesh2, meshlink_get_node(mesh2, "bar"));
109 fprintf(stderr, "UDP communication with bar not possible after 10 seconds\n");
115 meshlink_stop(mesh2);
116 meshlink_stop(mesh1);
117 meshlink_close(mesh2);
118 meshlink_close(mesh1);