10 #include "meshlink-tiny.h"
14 meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
16 meshlink_handle_t *mesh1;
17 meshlink_handle_t *mesh2;
21 assert(meshlink_destroy("storage-policy_conf.1"));
22 assert(meshlink_destroy("storage-policy_conf.2"));
24 mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE);
25 mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE);
28 meshlink_enable_discovery(mesh1, false);
29 meshlink_enable_discovery(mesh2, false);
30 meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_DISABLED);
31 meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_DISABLED);
35 char *export1 = meshlink_export(mesh1);
36 char *export2 = meshlink_export(mesh2);
41 assert(meshlink_import(mesh1, export2));
42 assert(meshlink_import(mesh2, export1));
44 // Check that they know each other
46 assert(meshlink_get_node(mesh1, "bar"));
47 assert(meshlink_get_node(mesh2, "foo"));
49 start_meshlink_pair(mesh1, mesh2);
51 // Close the instances and reopen them.
53 close_meshlink_pair(mesh1, mesh2);
55 mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE);
56 mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE);
59 meshlink_enable_discovery(mesh1, false);
60 meshlink_enable_discovery(mesh2, false);
61 meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY);
62 meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_KEYS_ONLY);
64 // Check that the nodes no longer know each other
66 assert(!meshlink_get_node(mesh1, "bar"));
67 assert(!meshlink_get_node(mesh2, "foo"));
69 // Exchange data again
71 assert(meshlink_import(mesh1, export2));
72 assert(meshlink_import(mesh2, export1));
77 // Close the instances and reopen them.
79 close_meshlink_pair(mesh1, mesh2);
81 mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE);
82 mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE);
85 meshlink_enable_discovery(mesh1, false);
86 meshlink_enable_discovery(mesh2, false);
87 meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY);
88 meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_KEYS_ONLY);
90 // Check that the nodes know each other
92 assert(meshlink_get_node(mesh1, "bar"));
93 assert(meshlink_get_node(mesh2, "foo"));
95 // Check that we update reachability
97 time_t last_reachable;
98 time_t last_unreachable;
99 assert(!meshlink_get_node_reachability(mesh1, meshlink_get_node(mesh1, "bar"), &last_reachable, &last_unreachable));
100 assert(!last_reachable);
101 assert(!last_unreachable);
103 start_meshlink_pair(mesh1, mesh2);
104 stop_meshlink_pair(mesh1, mesh2);
106 assert(!meshlink_get_node_reachability(mesh1, meshlink_get_node(mesh1, "bar"), &last_reachable, &last_unreachable));
107 assert(last_reachable);
108 assert(last_unreachable);
110 // But have not stored it
112 close_meshlink_pair(mesh1, mesh2);
114 mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE);
115 mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE);
118 meshlink_enable_discovery(mesh1, false);
119 meshlink_enable_discovery(mesh2, false);
120 meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY);
121 meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_KEYS_ONLY);
123 assert(meshlink_get_node(mesh1, "bar"));
124 assert(meshlink_get_node(mesh2, "foo"));
126 assert(!meshlink_get_node_reachability(mesh1, meshlink_get_node(mesh1, "bar"), &last_reachable, &last_unreachable));
127 assert(!last_reachable);
128 assert(!last_unreachable);
130 // Check that if we change back to STORAGE_ENABLED right before closing, pending changes are still saved
132 start_meshlink_pair(mesh1, mesh2);
133 stop_meshlink_pair(mesh1, mesh2);
135 meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_ENABLED);
136 meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_ENABLED);
138 close_meshlink_pair(mesh1, mesh2);
140 mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE);
141 mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE);
144 meshlink_enable_discovery(mesh1, false);
145 meshlink_enable_discovery(mesh2, false);
147 assert(!meshlink_get_node_reachability(mesh1, meshlink_get_node(mesh1, "bar"), &last_reachable, &last_unreachable));
148 assert(last_reachable);
149 assert(last_unreachable);
151 // Close the instances and reopen them.
153 close_meshlink_pair(mesh1, mesh2);
155 mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE);
156 mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE);
159 meshlink_enable_discovery(mesh1, false);
160 meshlink_enable_discovery(mesh2, false);
161 meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY);
162 meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_KEYS_ONLY);
164 // Check that the nodes know each other
166 assert(meshlink_get_node(mesh1, "bar"));
167 assert(meshlink_get_node(mesh2, "foo"));
171 close_meshlink_pair(mesh1, mesh2);