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_set_storage_policy(mesh1, MESHLINK_STORAGE_DISABLED);
29 meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_DISABLED);
33 char *export1 = meshlink_export(mesh1);
34 char *export2 = meshlink_export(mesh2);
39 assert(meshlink_import(mesh1, export2));
40 assert(meshlink_import(mesh2, export1));
42 // Check that they know each other
44 assert(meshlink_get_node(mesh1, "bar"));
45 assert(meshlink_get_node(mesh2, "foo"));
47 start_meshlink_pair(mesh1, mesh2);
49 // Close the instances and reopen them.
51 close_meshlink_pair(mesh1, mesh2);
53 mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE);
54 mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE);
57 meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY);
58 meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_KEYS_ONLY);
60 // Check that the nodes no longer know each other
62 assert(!meshlink_get_node(mesh1, "bar"));
63 assert(!meshlink_get_node(mesh2, "foo"));
65 // Exchange data again
67 assert(meshlink_import(mesh1, export2));
68 assert(meshlink_import(mesh2, export1));
73 // Close the instances and reopen them.
75 close_meshlink_pair(mesh1, mesh2);
77 mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE);
78 mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE);
81 meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY);
82 meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_KEYS_ONLY);
84 // Check that the nodes know each other
86 assert(meshlink_get_node(mesh1, "bar"));
87 assert(meshlink_get_node(mesh2, "foo"));
89 // Check that we update reachability
91 time_t last_reachable;
92 time_t last_unreachable;
93 assert(!meshlink_get_node_reachability(mesh1, meshlink_get_node(mesh1, "bar"), &last_reachable, &last_unreachable));
94 assert(!last_reachable);
95 assert(!last_unreachable);
97 start_meshlink_pair(mesh1, mesh2);
98 stop_meshlink_pair(mesh1, mesh2);
100 assert(!meshlink_get_node_reachability(mesh1, meshlink_get_node(mesh1, "bar"), &last_reachable, &last_unreachable));
101 assert(last_reachable);
102 assert(last_unreachable);
104 // But have not stored it
106 close_meshlink_pair(mesh1, mesh2);
108 mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE);
109 mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE);
112 meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY);
113 meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_KEYS_ONLY);
115 assert(meshlink_get_node(mesh1, "bar"));
116 assert(meshlink_get_node(mesh2, "foo"));
118 assert(!meshlink_get_node_reachability(mesh1, meshlink_get_node(mesh1, "bar"), &last_reachable, &last_unreachable));
119 assert(!last_reachable);
120 assert(!last_unreachable);
122 // Check that if we change back to STORAGE_ENABLED right before closing, pending changes are still saved
124 start_meshlink_pair(mesh1, mesh2);
125 stop_meshlink_pair(mesh1, mesh2);
127 meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_ENABLED);
128 meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_ENABLED);
130 close_meshlink_pair(mesh1, mesh2);
132 mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE);
133 mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE);
137 assert(!meshlink_get_node_reachability(mesh1, meshlink_get_node(mesh1, "bar"), &last_reachable, &last_unreachable));
138 assert(last_reachable);
139 assert(last_unreachable);
141 // Close the instances and reopen them.
143 close_meshlink_pair(mesh1, mesh2);
145 mesh1 = meshlink_open("storage-policy_conf.1", "foo", "storage-policy", DEV_CLASS_BACKBONE);
146 mesh2 = meshlink_open("storage-policy_conf.2", "bar", "storage-policy", DEV_CLASS_BACKBONE);
149 meshlink_set_storage_policy(mesh1, MESHLINK_STORAGE_KEYS_ONLY);
150 meshlink_set_storage_policy(mesh2, MESHLINK_STORAGE_KEYS_ONLY);
152 // Check that the nodes know each other
154 assert(meshlink_get_node(mesh1, "bar"));
155 assert(meshlink_get_node(mesh2, "foo"));
159 close_meshlink_pair(mesh1, mesh2);