8 volatile bool baz_reachable = false;
10 void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
11 if(!strcmp(node->name, "baz"))
12 baz_reachable = reachable;
15 int main(int argc, char *argv[]) {
16 // Open two new meshlink instance.
18 meshlink_handle_t *mesh1 = meshlink_open("invite_join_conf.1", "foo", "invite-join");
20 fprintf(stderr, "Could not initialize configuration for foo\n");
24 meshlink_handle_t *mesh2 = meshlink_open("invite_join_conf.2", "bar", "invite-join");
26 fprintf(stderr, "Could not initialize configuration for bar\n");
30 // Start the first instance and have it generate an invitation.
32 meshlink_set_node_status_cb(mesh1, status_cb);
34 if(!meshlink_start(mesh1)) {
35 fprintf(stderr, "Foo could not start\n");
39 meshlink_add_address(mesh1, "localhost");
40 char *url = meshlink_invite(mesh1, "baz");
42 fprintf(stderr, "Foo could not generate an invitation for baz\n");
46 // Have the second instance join the first.
48 if(!meshlink_join(mesh2, url)) {
49 fprintf(stderr, "Baz could not join foo's mesh\n");
55 if(!meshlink_start(mesh2)) {
56 fprintf(stderr, "Baz could not start\n");
60 // Wait for the two to connect.
62 for(int i = 0; i < 60; i++) {
69 fprintf(stderr, "Baz not reachable for foo after 20 seconds\n");
73 int pmtu = meshlink_get_pmtu(mesh1, meshlink_get_node(mesh1, "baz"));
74 for(int i = 0; i < 10 && !pmtu; i++) {
76 pmtu = meshlink_get_pmtu(mesh1, meshlink_get_node(mesh1, "baz"));
80 fprintf(stderr, "UDP communication with baz not possible after 10 seconds\n");
88 meshlink_close(mesh2);
89 meshlink_close(mesh1);