8 volatile bool baz_reachable = false;
10 void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
13 if(!strcmp(node->name, "baz")) {
14 baz_reachable = reachable;
19 // Open two new meshlink instance.
21 meshlink_handle_t *mesh1 = meshlink_open("invite_join_conf.1", "foo", "invite-join", DEV_CLASS_BACKBONE);
24 fprintf(stderr, "Could not initialize configuration for foo\n");
28 meshlink_handle_t *mesh2 = meshlink_open("invite_join_conf.2", "bar", "invite-join", DEV_CLASS_BACKBONE);
31 fprintf(stderr, "Could not initialize configuration for bar\n");
35 meshlink_handle_t *mesh3 = meshlink_open("invite_join_conf.3", "quux", "invite-join", DEV_CLASS_BACKBONE);
38 fprintf(stderr, "Could not initialize configuration for quux\n");
42 // Disable local discovery.
44 meshlink_enable_discovery(mesh1, false);
45 meshlink_enable_discovery(mesh2, false);
46 meshlink_enable_discovery(mesh3, false);
48 // Start the first instance and have it generate invitations.
50 meshlink_set_node_status_cb(mesh1, status_cb);
52 if(!meshlink_start(mesh1)) {
53 fprintf(stderr, "Foo could not start\n");
57 meshlink_add_address(mesh1, "localhost");
58 char *baz_url = meshlink_invite(mesh1, NULL, "baz");
61 fprintf(stderr, "Foo could not generate an invitation for baz\n");
65 char *quux_url = meshlink_invite(mesh1, NULL, "quux");
68 fprintf(stderr, "Foo could not generate an invitation for quux\n");
72 // Have the second instance join the first.
74 if(!meshlink_join(mesh2, baz_url)) {
75 fprintf(stderr, "Baz could not join foo's mesh\n");
81 if(!meshlink_start(mesh2)) {
82 fprintf(stderr, "Baz could not start\n");
86 // Wait for the two to connect.
88 for(int i = 0; i < 60; i++) {
97 fprintf(stderr, "Baz not reachable for foo after 20 seconds\n");
101 int pmtu = meshlink_get_pmtu(mesh1, meshlink_get_node(mesh1, "baz"));
103 for(int i = 0; i < 10 && !pmtu; i++) {
105 pmtu = meshlink_get_pmtu(mesh1, meshlink_get_node(mesh1, "baz"));
109 fprintf(stderr, "UDP communication with baz not possible after 10 seconds\n");
113 // Check that nodes cannot join with expired invitations
115 meshlink_set_invitation_timeout(mesh1, 0);
117 if(meshlink_join(mesh3, quux_url)) {
118 fprintf(stderr, "Quux could join foo's mesh using an outdated invitation\n");
126 meshlink_stop(mesh2);
127 meshlink_stop(mesh1);
128 meshlink_close(mesh2);
129 meshlink_close(mesh1);