]> git.meshlink.io Git - meshlink/blobdiff - test/import-export.c
Add utility functions to create paired MeshLink instances.
[meshlink] / test / import-export.c
index 17beaaf0ea8e6a665088cb4de36baf8956d22ecd..411a7a21ce0e3b4575dc5521fc8108158a8796d4 100644 (file)
@@ -15,18 +15,23 @@ 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");
+       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");
@@ -62,7 +67,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;
@@ -86,6 +91,17 @@ 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);