diff options
Diffstat (limited to 'src/topology/test_gnunet_daemon_topology.c')
-rw-r--r-- | src/topology/test_gnunet_daemon_topology.c | 224 |
1 files changed, 113 insertions, 111 deletions
diff --git a/src/topology/test_gnunet_daemon_topology.c b/src/topology/test_gnunet_daemon_topology.c index 6b2c58208..9e2db4f66 100644 --- a/src/topology/test_gnunet_daemon_topology.c +++ b/src/topology/test_gnunet_daemon_topology.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file topology/test_gnunet_daemon_topology.c | 21 | * @file topology/test_gnunet_daemon_topology.c |
22 | * @brief testcase for topology maintenance code | 22 | * @brief testcase for topology maintenance code |
@@ -36,12 +36,12 @@ | |||
36 | * too high can cause bandwidth problems for the testing peers. | 36 | * too high can cause bandwidth problems for the testing peers. |
37 | * Normal should be 5KB/s per peer. See gnunet-config -s ats. | 37 | * Normal should be 5KB/s per peer. See gnunet-config -s ats. |
38 | */ | 38 | */ |
39 | #define THRESHOLD NUM_PEERS/2 | 39 | #define THRESHOLD NUM_PEERS / 2 |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * How long until we give up on connecting the peers? | 42 | * How long until we give up on connecting the peers? |
43 | */ | 43 | */ |
44 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 44 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) |
45 | 45 | ||
46 | /* | 46 | /* |
47 | * Store manual connections. | 47 | * Store manual connections. |
@@ -71,8 +71,7 @@ static struct GNUNET_SCHEDULER_Task *timeout_tid; | |||
71 | /* | 71 | /* |
72 | * Peer context for every testbed peer. | 72 | * Peer context for every testbed peer. |
73 | */ | 73 | */ |
74 | struct peerctx | 74 | struct peerctx { |
75 | { | ||
76 | int index; | 75 | int index; |
77 | struct GNUNET_STATISTICS_Handle *statistics; | 76 | struct GNUNET_STATISTICS_Handle *statistics; |
78 | int connections; | 77 | int connections; |
@@ -81,28 +80,29 @@ struct peerctx | |||
81 | 80 | ||
82 | 81 | ||
83 | static void | 82 | static void |
84 | shutdown_task (void *cls) | 83 | shutdown_task(void *cls) |
85 | { | 84 | { |
86 | unsigned int i; | 85 | unsigned int i; |
87 | 86 | ||
88 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 87 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
89 | "Shutting down testcase\n"); | 88 | "Shutting down testcase\n"); |
90 | 89 | ||
91 | for (i=0;i<NUM_PEERS;i++) { | 90 | for (i = 0; i < NUM_PEERS; i++) |
92 | if (NULL != op[i]) | 91 | { |
93 | GNUNET_TESTBED_operation_done (op[i]); | 92 | if (NULL != op[i]) |
94 | } | 93 | GNUNET_TESTBED_operation_done(op[i]); |
94 | } | ||
95 | 95 | ||
96 | if (NULL != timeout_tid) | 96 | if (NULL != timeout_tid) |
97 | GNUNET_SCHEDULER_cancel (timeout_tid); | 97 | GNUNET_SCHEDULER_cancel(timeout_tid); |
98 | } | 98 | } |
99 | 99 | ||
100 | static void | 100 | static void |
101 | timeout_task (void *cls) | 101 | timeout_task(void *cls) |
102 | { | 102 | { |
103 | timeout_tid = NULL; | 103 | timeout_tid = NULL; |
104 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 104 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
105 | "Testcase timeout\n"); | 105 | "Testcase timeout\n"); |
106 | 106 | ||
107 | result = GNUNET_SYSERR; | 107 | result = GNUNET_SYSERR; |
108 | GNUNET_SCHEDULER_shutdown(); | 108 | GNUNET_SCHEDULER_shutdown(); |
@@ -113,172 +113,174 @@ timeout_task (void *cls) | |||
113 | * peers to a peer changes. | 113 | * peers to a peer changes. |
114 | */ | 114 | */ |
115 | int | 115 | int |
116 | statistics_iterator (void *cls, | 116 | statistics_iterator(void *cls, |
117 | const char *subsystem, | 117 | const char *subsystem, |
118 | const char *name, | 118 | const char *name, |
119 | uint64_t value, | 119 | uint64_t value, |
120 | int is_persistent) | 120 | int is_persistent) |
121 | { | 121 | { |
122 | struct peerctx *p_ctx = (struct peerctx*) cls; | 122 | struct peerctx *p_ctx = (struct peerctx*)cls; |
123 | 123 | ||
124 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 124 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
125 | "Peer %d: %s = %llu\n", | 125 | "Peer %d: %s = %llu\n", |
126 | p_ctx->index, | 126 | p_ctx->index, |
127 | name, | 127 | name, |
128 | (unsigned long long) value); | 128 | (unsigned long long)value); |
129 | 129 | ||
130 | if (p_ctx->connections < value) | 130 | if (p_ctx->connections < value) |
131 | p_ctx->connections = value; | 131 | p_ctx->connections = value; |
132 | 132 | ||
133 | if (THRESHOLD <= value && GNUNET_NO == p_ctx->reported) { | 133 | if (THRESHOLD <= value && GNUNET_NO == p_ctx->reported) |
134 | p_ctx->reported = GNUNET_YES; | 134 | { |
135 | checked_peers++; | 135 | p_ctx->reported = GNUNET_YES; |
136 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 136 | checked_peers++; |
137 | "Peer %d successfully connected to at least %d peers once.\n", | ||
138 | p_ctx->index, | ||
139 | THRESHOLD); | ||
140 | |||
141 | if (checked_peers == NUM_PEERS) { | ||
142 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 137 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
143 | "Test OK: All peers have connected to %d peers once.\n", | 138 | "Peer %d successfully connected to at least %d peers once.\n", |
144 | THRESHOLD); | 139 | p_ctx->index, |
145 | result = GNUNET_YES; | 140 | THRESHOLD); |
146 | GNUNET_SCHEDULER_shutdown(); | 141 | |
142 | if (checked_peers == NUM_PEERS) | ||
143 | { | ||
144 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
145 | "Test OK: All peers have connected to %d peers once.\n", | ||
146 | THRESHOLD); | ||
147 | result = GNUNET_YES; | ||
148 | GNUNET_SCHEDULER_shutdown(); | ||
149 | } | ||
147 | } | 150 | } |
148 | } | ||
149 | 151 | ||
150 | return GNUNET_YES; | 152 | return GNUNET_YES; |
151 | } | 153 | } |
152 | 154 | ||
153 | static void * | 155 | static void * |
154 | ca_statistics (void *cls, | 156 | ca_statistics(void *cls, |
155 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 157 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
156 | { | 158 | { |
157 | return GNUNET_STATISTICS_create ("topology", cfg); | 159 | return GNUNET_STATISTICS_create("topology", cfg); |
158 | } | 160 | } |
159 | 161 | ||
160 | 162 | ||
161 | void | 163 | void |
162 | da_statistics (void *cls, | 164 | da_statistics(void *cls, |
163 | void *op_result) | 165 | void *op_result) |
164 | { | 166 | { |
165 | struct peerctx *p_ctx = (struct peerctx *) cls; | 167 | struct peerctx *p_ctx = (struct peerctx *)cls; |
166 | 168 | ||
167 | GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel | 169 | GNUNET_break(GNUNET_OK == GNUNET_STATISTICS_watch_cancel |
168 | (p_ctx->statistics, "topology", "# peers connected", | 170 | (p_ctx->statistics, "topology", "# peers connected", |
169 | statistics_iterator, p_ctx)); | 171 | statistics_iterator, p_ctx)); |
170 | 172 | ||
171 | GNUNET_STATISTICS_destroy (p_ctx->statistics, GNUNET_NO); | 173 | GNUNET_STATISTICS_destroy(p_ctx->statistics, GNUNET_NO); |
172 | p_ctx->statistics = NULL; | 174 | p_ctx->statistics = NULL; |
173 | 175 | ||
174 | GNUNET_free (p_ctx); | 176 | GNUNET_free(p_ctx); |
175 | } | 177 | } |
176 | 178 | ||
177 | 179 | ||
178 | static void | 180 | static void |
179 | service_connect_complete (void *cls, | 181 | service_connect_complete(void *cls, |
180 | struct GNUNET_TESTBED_Operation *op, | 182 | struct GNUNET_TESTBED_Operation *op, |
181 | void *ca_result, | 183 | void *ca_result, |
182 | const char *emsg) | 184 | const char *emsg) |
183 | { | 185 | { |
184 | int ret; | 186 | int ret; |
185 | struct peerctx *p_ctx = (struct peerctx*) cls; | 187 | struct peerctx *p_ctx = (struct peerctx*)cls; |
186 | 188 | ||
187 | if (NULL == ca_result) | 189 | if (NULL == ca_result) |
188 | GNUNET_SCHEDULER_shutdown(); | 190 | GNUNET_SCHEDULER_shutdown(); |
189 | 191 | ||
190 | p_ctx->statistics = ca_result; | 192 | p_ctx->statistics = ca_result; |
191 | 193 | ||
192 | ret = GNUNET_STATISTICS_watch (ca_result, | 194 | ret = GNUNET_STATISTICS_watch(ca_result, |
193 | "topology", | 195 | "topology", |
194 | "# peers connected", | 196 | "# peers connected", |
195 | statistics_iterator, | 197 | statistics_iterator, |
196 | p_ctx); | 198 | p_ctx); |
197 | 199 | ||
198 | if (GNUNET_NO == ret) | 200 | if (GNUNET_NO == ret) |
199 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 201 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
200 | "call to GNUNET_STATISTICS_watch() failed\n"); | 202 | "call to GNUNET_STATISTICS_watch() failed\n"); |
201 | } | 203 | } |
202 | 204 | ||
203 | static void | 205 | static void |
204 | notify_connect_complete (void *cls, | 206 | notify_connect_complete(void *cls, |
205 | struct GNUNET_TESTBED_Operation *op, | 207 | struct GNUNET_TESTBED_Operation *op, |
206 | const char *emsg) | 208 | const char *emsg) |
207 | { | 209 | { |
208 | GNUNET_TESTBED_operation_done (op); | 210 | GNUNET_TESTBED_operation_done(op); |
209 | if (NULL != emsg) | 211 | if (NULL != emsg) |
210 | { | 212 | { |
211 | fprintf (stderr, "Failed to connect two peers: %s\n", emsg); | 213 | fprintf(stderr, "Failed to connect two peers: %s\n", emsg); |
212 | result = GNUNET_SYSERR; | 214 | result = GNUNET_SYSERR; |
213 | GNUNET_SCHEDULER_shutdown (); | 215 | GNUNET_SCHEDULER_shutdown(); |
214 | return; | 216 | return; |
215 | } | 217 | } |
216 | connect_left--; | 218 | connect_left--; |
217 | } | 219 | } |
218 | 220 | ||
219 | static void | 221 | static void |
220 | do_connect (void *cls, | 222 | do_connect(void *cls, |
221 | struct GNUNET_TESTBED_RunHandle *h, | 223 | struct GNUNET_TESTBED_RunHandle *h, |
222 | unsigned int num_peers, | 224 | unsigned int num_peers, |
223 | struct GNUNET_TESTBED_Peer **peers, | 225 | struct GNUNET_TESTBED_Peer **peers, |
224 | unsigned int links_succeeded, | 226 | unsigned int links_succeeded, |
225 | unsigned int links_failed) | 227 | unsigned int links_failed) |
226 | { | 228 | { |
227 | unsigned int i; | 229 | unsigned int i; |
228 | struct peerctx *p_ctx; | 230 | struct peerctx *p_ctx; |
229 | 231 | ||
230 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 232 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
231 | "Threshold is set to %d.\n", | 233 | "Threshold is set to %d.\n", |
232 | THRESHOLD); | 234 | THRESHOLD); |
233 | 235 | ||
234 | GNUNET_assert (NUM_PEERS == num_peers); | 236 | GNUNET_assert(NUM_PEERS == num_peers); |
235 | 237 | ||
236 | for (i=0;i<NUM_PEERS;i++) | 238 | for (i = 0; i < NUM_PEERS; i++) |
237 | { | 239 | { |
238 | p_ctx = GNUNET_new (struct peerctx); | 240 | p_ctx = GNUNET_new(struct peerctx); |
239 | p_ctx->index = i; | 241 | p_ctx->index = i; |
240 | p_ctx->connections = 0; | 242 | p_ctx->connections = 0; |
241 | p_ctx->reported = GNUNET_NO; | 243 | p_ctx->reported = GNUNET_NO; |
242 | 244 | ||
243 | if (i<NUM_PEERS-1) { | 245 | if (i < NUM_PEERS - 1) |
244 | connect_left++; | 246 | { |
245 | GNUNET_TESTBED_overlay_connect (NULL, | 247 | connect_left++; |
246 | ¬ify_connect_complete, NULL, | 248 | GNUNET_TESTBED_overlay_connect(NULL, |
247 | peers[i], peers[i+1]); | 249 | ¬ify_connect_complete, NULL, |
248 | } | 250 | peers[i], peers[i + 1]); |
251 | } | ||
249 | 252 | ||
250 | op[i] = | 253 | op[i] = |
251 | GNUNET_TESTBED_service_connect (cls, | 254 | GNUNET_TESTBED_service_connect(cls, |
252 | peers[i], | 255 | peers[i], |
253 | "statistics", | 256 | "statistics", |
254 | service_connect_complete, | 257 | service_connect_complete, |
255 | p_ctx, /* cls of completion cb */ | 258 | p_ctx, /* cls of completion cb */ |
256 | ca_statistics, /* connect adapter */ | 259 | ca_statistics, /* connect adapter */ |
257 | da_statistics, /* disconnect adapter */ | 260 | da_statistics, /* disconnect adapter */ |
258 | p_ctx); | 261 | p_ctx); |
259 | |||
260 | } | 262 | } |
261 | 263 | ||
262 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 264 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
263 | timeout_tid = | 265 | timeout_tid = |
264 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 266 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, |
265 | &timeout_task, | 267 | &timeout_task, |
266 | NULL); | 268 | NULL); |
267 | } | 269 | } |
268 | 270 | ||
269 | 271 | ||
270 | int | 272 | int |
271 | main (int argc, char *argv[]) | 273 | main(int argc, char *argv[]) |
272 | { | 274 | { |
273 | result = GNUNET_SYSERR; | 275 | result = GNUNET_SYSERR; |
274 | checked_peers = 0; | 276 | checked_peers = 0; |
275 | 277 | ||
276 | (void) GNUNET_TESTBED_test_run ("test-gnunet-daemon-topology", | 278 | (void)GNUNET_TESTBED_test_run("test-gnunet-daemon-topology", |
277 | "test_gnunet_daemon_topology_data.conf", | 279 | "test_gnunet_daemon_topology_data.conf", |
278 | NUM_PEERS, | 280 | NUM_PEERS, |
279 | 0, NULL, NULL, | 281 | 0, NULL, NULL, |
280 | &do_connect, NULL); | 282 | &do_connect, NULL); |
281 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-topology"); | 283 | GNUNET_DISK_directory_remove("/tmp/test-gnunet-topology"); |
282 | 284 | ||
283 | return (GNUNET_OK != result) ? 1 : 0; | 285 | return (GNUNET_OK != result) ? 1 : 0; |
284 | } | 286 | } |