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 // Start again from scratch, now use invite/join instead of import/export
153 close_meshlink_pair(mesh1, mesh2);
155 assert(meshlink_destroy("storage-policy_conf.1"));
156 assert(meshlink_destroy("storage-policy_conf.2"));
158 mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE);
159 mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE);
162 meshlink_enable_discovery(mesh1, false);
163 meshlink_enable_discovery(mesh2, false);
164 meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_DISABLED);
165 meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_DISABLED);
167 // Check that joining is not possible with storage disabled
169 assert(meshlink_set_canonical_address(mesh1, meshlink_get_self(mesh1), "localhost", NULL));
170 char *invitation = meshlink_invite(mesh1, NULL, "bar");
172 assert(meshlink_start(mesh1));
173 assert(!meshlink_join(mesh2, invitation));
174 assert(meshlink_errno == MESHLINK_EINVAL);
175 meshlink_stop(mesh1);
177 // Try again with KEYS_ONLY
179 meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY);
180 meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_KEYS_ONLY);
182 assert(meshlink_start(mesh1));
183 assert(meshlink_join(mesh2, invitation));
184 assert(meshlink_errno == MESHLINK_EINVAL);
185 meshlink_stop(mesh1);
187 start_meshlink_pair(mesh1, mesh2);
189 // Close the instances and reopen them.
191 close_meshlink_pair(mesh1, mesh2);
193 mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE);
194 mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE);
197 meshlink_enable_discovery(mesh1, false);
198 meshlink_enable_discovery(mesh2, false);
199 meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY);
200 meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_KEYS_ONLY);
202 // Check that the nodes know each other
204 assert(meshlink_get_node(mesh1, "bar"));
205 assert(meshlink_get_node(mesh2, "foo"));
209 close_meshlink_pair(mesh1, mesh2);