10 static struct sync_flag duplicate_detected;
12 static void handle_duplicate(meshlink_handle_t *mesh, meshlink_node_t *node) {
13 set_sync_flag(&duplicate_detected, true);
14 meshlink_blacklist(mesh, node);
18 meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
20 // Open meshlink instances
22 static const char *name[4] = {"foo", "bar", "baz", "foo"};
23 meshlink_handle_t *mesh[4];
25 for(int i = 0; i < 4; i++) {
27 snprintf(dirname, sizeof dirname, "duplicate_conf.%d", i);
29 assert(meshlink_destroy(dirname));
30 mesh[i] = meshlink_open(dirname, name[i], "duplicate", DEV_CLASS_BACKBONE);
33 meshlink_add_address(mesh[i], "localhost");
34 meshlink_enable_discovery(mesh[i], false);
36 meshlink_set_node_duplicate_cb(mesh[i], handle_duplicate);
39 // Link them in a chain
43 for(int i = 0; i < 4; i++) {
44 data[i] = meshlink_export(mesh[i]);
48 for(int i = 0; i < 3; i++) {
49 assert(meshlink_import(mesh[i], data[i + 1]));
50 assert(meshlink_import(mesh[i + 1], data[i]));
53 for(int i = 0; i < 4; i++) {
59 for(int i = 0; i < 4; i++) {
60 assert(meshlink_start(mesh[i]));
63 // Wait for the duplicate node to be detected
65 assert(wait_sync_flag(&duplicate_detected, 20));
69 for(int i = 0; i < 4; i++) {
70 meshlink_close(mesh[i]);