X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Fimport-export.c;h=f2229589ab5da907870561820df3fc5e8bff3814;hb=011dd48c00fd637c8089fa1a6bb79c63472a626b;hp=f7ecf52162dd48d913cf78dd88b987b27b228267;hpb=c2b5ef48a8433db03569f621a431857d06fe1d85;p=meshlink diff --git a/test/import-export.c b/test/import-export.c index f7ecf521..f2229589 100644 --- a/test/import-export.c +++ b/test/import-export.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -14,13 +15,17 @@ void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { int main(int argc, char *argv[]) { // Open two new meshlink instance. - meshlink_handle_t *mesh1 = meshlink_open("import_export_conf.1", "foo"); - if(!mesh1) + meshlink_handle_t *mesh1 = meshlink_open("import_export_conf.1", "foo", "import-export"); + if(!mesh1) { + fprintf(stderr, "Could not initialize configuration for foo\n"); return 1; + } - meshlink_handle_t *mesh2 = meshlink_open("import_export_conf.2", "bar"); - if(!mesh2) + meshlink_handle_t *mesh2 = meshlink_open("import_export_conf.2", "bar", "import-export"); + if(!mesh2) { + fprintf(stderr, "Could not initialize configuration for bar\n"); return 1; + } // Import and export both side's data @@ -28,16 +33,29 @@ int main(int argc, char *argv[]) { meshlink_add_address(mesh2, "localhost"); char *data = meshlink_export(mesh1); + if(!data) { + fprintf(stderr, "Foo could not export its configuration\n"); + return 1; + } - if(!meshlink_import(mesh2, data)) + if(!meshlink_import(mesh2, data)) { + fprintf(stderr, "Bar could not import foo's configuration\n"); return 1; + } free(data); data = meshlink_export(mesh2); + if(!data) { + fprintf(stderr, "Bar could not export its configuration\n"); + return 1; + } - if(!meshlink_import(mesh1, data)) + + if(!meshlink_import(mesh1, data)) { + fprintf(stderr, "Foo could not import bar's configuration\n"); return 1; + } free(data); @@ -45,11 +63,15 @@ int main(int argc, char *argv[]) { meshlink_set_node_status_cb(mesh1, status_cb); - if(!meshlink_start(mesh1)) + if(!meshlink_start(mesh1)) { + fprintf(stderr, "Foo could not start\n"); return 1; + } - if(!meshlink_start(mesh2)) + if(!meshlink_start(mesh2)) { + fprintf(stderr, "Bar could not start\n"); return 1; + } // Wait for the two to connect. @@ -59,8 +81,21 @@ int main(int argc, char *argv[]) { break; } - if(!bar_reachable) + if(!bar_reachable) { + fprintf(stderr, "Bar not reachable for foo after 20 seconds\n"); 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.