X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Fimport-export.c;h=de2231e9298d2b673c4b808765e034c91b82a086;hb=dc0e52cb3e42620c3139e713b373d130aa30b698;hp=17beaaf0ea8e6a665088cb4de36baf8956d22ecd;hpb=9f9925cb0726874c5d1f4fc266df54c0437a4660;p=meshlink diff --git a/test/import-export.c b/test/import-export.c index 17beaaf0..de2231e9 100644 --- a/test/import-export.c +++ b/test/import-export.c @@ -8,31 +8,42 @@ volatile bool bar_reachable = false; void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { - if(!strcmp(node->name, "bar")) + (void)mesh; + + if(!strcmp(node->name, "bar")) { bar_reachable = reachable; + } } -int main(int argc, char *argv[]) { +int main() { // Open two new meshlink instance. - meshlink_handle_t *mesh1 = meshlink_open("import_export_conf.1", "foo"); + meshlink_handle_t *mesh1 = meshlink_open("import_export_conf.1", "foo", "import-export", DEV_CLASS_BACKBONE); + if(!mesh1) { fprintf(stderr, "Could not initialize configuration for foo\n"); return 1; } - meshlink_handle_t *mesh2 = meshlink_open("import_export_conf.2", "bar"); + meshlink_handle_t *mesh2 = meshlink_open("import_export_conf.2", "bar", "import-export", DEV_CLASS_BACKBONE); + if(!mesh2) { fprintf(stderr, "Could not initialize configuration for bar\n"); return 1; } + // Disable local discovery + + meshlink_enable_discovery(mesh1, false); + meshlink_enable_discovery(mesh2, false); + // Import and export both side's data meshlink_add_address(mesh1, "localhost"); meshlink_add_address(mesh2, "localhost"); char *data = meshlink_export(mesh1); + if(!data) { fprintf(stderr, "Foo could not export its configuration\n"); return 1; @@ -46,6 +57,7 @@ int main(int argc, char *argv[]) { free(data); data = meshlink_export(mesh2); + if(!data) { fprintf(stderr, "Bar could not export its configuration\n"); return 1; @@ -62,7 +74,7 @@ int main(int argc, char *argv[]) { // Start both instances meshlink_set_node_status_cb(mesh1, status_cb); - + if(!meshlink_start(mesh1)) { fprintf(stderr, "Foo could not start\n"); return 1; @@ -77,8 +89,10 @@ int main(int argc, char *argv[]) { for(int i = 0; i < 20; i++) { sleep(1); - if(bar_reachable) + + if(bar_reachable) { break; + } } if(!bar_reachable) { @@ -86,6 +100,18 @@ int main(int argc, char *argv[]) { return 1; } + int pmtu = meshlink_get_pmtu(mesh2, meshlink_get_node(mesh2, "bar")); + + for(int i = 0; i < 10 && !pmtu; i++) { + sleep(1); + pmtu = meshlink_get_pmtu(mesh2, meshlink_get_node(mesh2, "bar")); + } + + if(!pmtu) { + fprintf(stderr, "UDP communication with bar not possible after 10 seconds\n"); + return 1; + } + // Clean up. meshlink_stop(mesh2);