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);
18 assert(meshlink_blacklist(mesh, node));
22 init_sync_flag(&duplicate_detected);
24 meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
26 // Open meshlink instances
28 static const char *name[4] = {"foo", "bar", "baz", "foo"};
29 meshlink_handle_t *mesh[4];
31 for(int i = 0; i < 4; i++) {
33 snprintf(dirname, sizeof dirname, "duplicate_conf.%d", i);
35 assert(meshlink_destroy(dirname));
36 mesh[i] = meshlink_open(dirname, name[i], "duplicate", DEV_CLASS_BACKBONE);
39 assert(meshlink_set_canonical_address(mesh[i], meshlink_get_self(mesh[i]), "localhost", NULL));
40 meshlink_enable_discovery(mesh[i], false);
42 meshlink_set_node_duplicate_cb(mesh[i], handle_duplicate);
45 // Link them in a chain
49 for(int i = 0; i < 4; i++) {
50 data[i] = meshlink_export(mesh[i]);
54 for(int i = 0; i < 3; i++) {
55 assert(meshlink_import(mesh[i], data[i + 1]));
56 assert(meshlink_import(mesh[i + 1], data[i]));
59 for(int i = 0; i < 4; i++) {
65 for(int i = 0; i < 4; i++) {
66 assert(meshlink_start(mesh[i]));
69 // Wait for the duplicate node to be detected
71 assert(wait_sync_flag(&duplicate_detected, 20));
75 for(int i = 0; i < 4; i++) {
76 meshlink_close(mesh[i]);