14 static struct sync_flag duplicate_detected;
16 static void handle_duplicate(meshlink_handle_t *mesh, meshlink_node_t *node) {
17 set_sync_flag(&duplicate_detected, true);
21 init_sync_flag(&duplicate_detected);
23 meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
25 // Open meshlink instances
27 static const char *name[4] = {"foo", "bar", "baz", "foo"};
28 meshlink_handle_t *mesh[4];
30 for(int i = 0; i < 4; i++) {
32 snprintf(dirname, sizeof dirname, "duplicate_conf.%d", i);
34 assert(meshlink_destroy(dirname));
35 mesh[i] = meshlink_open(dirname, name[i], "duplicate", DEV_CLASS_BACKBONE);
38 assert(meshlink_set_canonical_address(mesh[i], meshlink_get_self(mesh[i]), "localhost", NULL));
39 meshlink_enable_discovery(mesh[i], false);
41 meshlink_set_node_duplicate_cb(mesh[i], handle_duplicate);
44 // Link them in a chain
48 for(int i = 0; i < 4; i++) {
49 data[i] = meshlink_export(mesh[i]);
53 for(int i = 0; i < 3; i++) {
54 assert(meshlink_import(mesh[i], data[i + 1]));
55 assert(meshlink_import(mesh[i + 1], data[i]));
58 for(int i = 0; i < 4; i++) {
64 for(int i = 0; i < 4; i++) {
65 assert(meshlink_start(mesh[i]));
68 // Wait for the duplicate node to be detected
70 assert(wait_sync_flag(&duplicate_detected, 20));
74 for(int i = 0; i < 4; i++) {
75 meshlink_close(mesh[i]);