TESTS = \
- basic.test
+ basic.test \
+ import-export.test \
+ invite-join.test
dist_check_SCRIPTS = $(TESTS)
AM_CPPFLAGS = -I../src
-check_PROGRAMS = basic
+check_PROGRAMS = basic import-export invite-join
basic_SOURCES = basic.c
basic_LDADD = ../src/libmeshlink.la
+
+import_export_SOURCES = import-export.c
+import_export_LDADD = ../src/libmeshlink.la
+
+invite_join_SOURCES = invite-join.c
+invite_join_LDADD = ../src/libmeshlink.la
--- /dev/null
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "meshlink.h"
+
+volatile bool bar_reachable = false;
+
+void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
+ if(!strcmp(node->name, "bar"))
+ bar_reachable = 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)
+ return 1;
+
+ meshlink_handle_t *mesh2 = meshlink_open("import_export_conf.2", "bar");
+ if(!mesh2)
+ return 1;
+
+ // Import and export both side's data
+
+ meshlink_add_address(mesh1, "localhost");
+ meshlink_add_address(mesh2, "localhost");
+
+ char *data = meshlink_export(mesh1);
+
+ if(!meshlink_import(mesh2, data))
+ return 1;
+
+ free(data);
+
+ data = meshlink_export(mesh2);
+
+ if(!meshlink_import(mesh1, data))
+ return 1;
+
+ free(data);
+
+ // Start both instances
+
+ meshlink_set_node_status_cb(mesh1, status_cb);
+
+ if(!meshlink_start(mesh1))
+ return 1;
+
+ if(!meshlink_start(mesh2))
+ return 1;
+
+ // Wait for the two to connect.
+
+ for(int i = 0; i < 20; i++) {
+ sleep(1);
+ if(bar_reachable)
+ break;
+ }
+
+ if(!bar_reachable)
+ return 1;
+
+ // Clean up.
+
+ meshlink_stop(mesh2);
+ meshlink_stop(mesh1);
+ meshlink_close(mesh2);
+ meshlink_close(mesh1);
+
+ return 0;
+}
--- /dev/null
+#!/bin/sh
+
+rm -Rf import_export_conf*
+./import-export
--- /dev/null
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "meshlink.h"
+
+volatile bool baz_reachable = false;
+
+void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
+ if(!strcmp(node->name, "baz"))
+ baz_reachable = reachable;
+}
+
+int main(int argc, char *argv[]) {
+ // Open two new meshlink instance.
+
+ meshlink_handle_t *mesh1 = meshlink_open("invite_join_conf.1", "foo");
+ if(!mesh1)
+ return 1;
+
+ meshlink_handle_t *mesh2 = meshlink_open("invite_join_conf.2", "bar");
+ if(!mesh2)
+ return 1;
+
+ // Start the first instance and have it generate an invitation.
+
+ meshlink_set_node_status_cb(mesh1, status_cb);
+
+ if(!meshlink_start(mesh1))
+ return 1;
+
+ meshlink_add_address(mesh1, "localhost");
+ char *url = meshlink_invite(mesh1, "baz");
+ if(!url)
+ return 1;
+
+ // Have the second instance join the first.
+
+ if(!meshlink_join(mesh2, url))
+ return 1;
+
+ free(url);
+
+ if(!meshlink_start(mesh2))
+ return 1;
+
+ // Wait for the two to connect.
+
+ for(int i = 0; i < 20; i++) {
+ sleep(1);
+ if(baz_reachable)
+ break;
+ }
+
+ if(!baz_reachable)
+ return 1;
+
+ // Clean up.
+
+ meshlink_stop(mesh2);
+ meshlink_stop(mesh1);
+ meshlink_close(mesh2);
+ meshlink_close(mesh1);
+
+ return 0;
+}
--- /dev/null
+#!/bin/sh
+
+rm -Rf invite_join_conf*
+./invite-join