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 meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
24 // Open meshlink instances
26 static const char *name[4] = {"foo", "bar", "baz", "foo"};
27 meshlink_handle_t *mesh[4];
29 for(int i = 0; i < 4; i++) {
31 snprintf(dirname, sizeof dirname, "duplicate_conf.%d", i);
33 assert(meshlink_destroy(dirname));
34 mesh[i] = meshlink_open(dirname, name[i], "duplicate", DEV_CLASS_BACKBONE);
37 assert(meshlink_add_address(mesh[i], "localhost"));
38 meshlink_enable_discovery(mesh[i], false);
40 meshlink_set_node_duplicate_cb(mesh[i], handle_duplicate);
43 // Link them in a chain
47 for(int i = 0; i < 4; i++) {
48 data[i] = meshlink_export(mesh[i]);
52 for(int i = 0; i < 3; i++) {
53 assert(meshlink_import(mesh[i], data[i + 1]));
54 assert(meshlink_import(mesh[i + 1], data[i]));
57 for(int i = 0; i < 4; i++) {
63 for(int i = 0; i < 4; i++) {
64 assert(meshlink_start(mesh[i]));
67 // Wait for the duplicate node to be detected
69 assert(wait_sync_flag(&duplicate_detected, 20));
73 for(int i = 0; i < 4; i++) {
74 meshlink_close(mesh[i]);