diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/testbed | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/testbed')
61 files changed, 11741 insertions, 11699 deletions
diff --git a/src/testbed/generate-underlay-topology.c b/src/testbed/generate-underlay-topology.c index 7857652e0..a463d384a 100644 --- a/src/testbed/generate-underlay-topology.c +++ b/src/testbed/generate-underlay-topology.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/generate-underlay-topology.c | 22 | * @file testbed/generate-underlay-topology.c |
@@ -30,10 +30,10 @@ | |||
30 | #include "testbed_api_topology.h" | 30 | #include "testbed_api_topology.h" |
31 | #include "sqlite3.h" | 31 | #include "sqlite3.h" |
32 | 32 | ||
33 | #define LOG(type, ...) GNUNET_log (type, __VA_ARGS__) | 33 | #define LOG(type, ...) GNUNET_log(type, __VA_ARGS__) |
34 | 34 | ||
35 | 35 | ||
36 | #define LOG_ERROR(...) LOG (GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__) | 36 | #define LOG_ERROR(...) LOG(GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__) |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Log an error message at log-level 'level' that indicates | 39 | * Log an error message at log-level 'level' that indicates |
@@ -42,22 +42,22 @@ | |||
42 | */ | 42 | */ |
43 | #define LOG_SQLITE(db, msg, level, cmd) \ | 43 | #define LOG_SQLITE(db, msg, level, cmd) \ |
44 | do \ | 44 | do \ |
45 | { \ | 45 | { \ |
46 | GNUNET_log_from (level, \ | 46 | GNUNET_log_from(level, \ |
47 | "sqlite", \ | 47 | "sqlite", \ |
48 | _ ("`%s' failed at %s:%d with error: %s\n"), \ | 48 | _("`%s' failed at %s:%d with error: %s\n"), \ |
49 | cmd, \ | 49 | cmd, \ |
50 | __FILE__, \ | 50 | __FILE__, \ |
51 | __LINE__, \ | 51 | __LINE__, \ |
52 | sqlite3_errmsg (db)); \ | 52 | sqlite3_errmsg(db)); \ |
53 | if (msg != NULL) \ | 53 | if (msg != NULL) \ |
54 | GNUNET_asprintf (msg, \ | 54 | GNUNET_asprintf (msg, \ |
55 | _ ("`%s' failed at %s:%u with error: %s"), \ | 55 | _("`%s' failed at %s:%u with error: %s"), \ |
56 | cmd, \ | 56 | cmd, \ |
57 | __FILE__, \ | 57 | __FILE__, \ |
58 | __LINE__, \ | 58 | __LINE__, \ |
59 | sqlite3_errmsg (db)); \ | 59 | sqlite3_errmsg(db)); \ |
60 | } while (0) | 60 | } while (0) |
61 | 61 | ||
62 | 62 | ||
63 | /** | 63 | /** |
@@ -98,43 +98,43 @@ static int exit_result; | |||
98 | * @return GNUNET_OK to continue processing; GNUNET_SYSERR to abort | 98 | * @return GNUNET_OK to continue processing; GNUNET_SYSERR to abort |
99 | */ | 99 | */ |
100 | static int | 100 | static int |
101 | link_processor (void *cls, | 101 | link_processor(void *cls, |
102 | unsigned int A, | 102 | unsigned int A, |
103 | unsigned int B, | 103 | unsigned int B, |
104 | unsigned int bandwidth, | 104 | unsigned int bandwidth, |
105 | unsigned int latency, | 105 | unsigned int latency, |
106 | unsigned int loss) | 106 | unsigned int loss) |
107 | { | 107 | { |
108 | if ((SQLITE_OK != sqlite3_bind_int (stmt_insert, 1, A)) || | 108 | if ((SQLITE_OK != sqlite3_bind_int(stmt_insert, 1, A)) || |
109 | (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, B)) || | 109 | (SQLITE_OK != sqlite3_bind_int(stmt_insert, 2, B)) || |
110 | (SQLITE_OK != sqlite3_bind_int (stmt_insert, 3, bandwidth)) || | 110 | (SQLITE_OK != sqlite3_bind_int(stmt_insert, 3, bandwidth)) || |
111 | (SQLITE_OK != sqlite3_bind_int (stmt_insert, 4, latency)) || | 111 | (SQLITE_OK != sqlite3_bind_int(stmt_insert, 4, latency)) || |
112 | (SQLITE_OK != sqlite3_bind_int (stmt_insert, 5, loss))) | 112 | (SQLITE_OK != sqlite3_bind_int(stmt_insert, 5, loss))) |
113 | { | 113 | { |
114 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int"); | 114 | LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int"); |
115 | return GNUNET_SYSERR; | 115 | return GNUNET_SYSERR; |
116 | } | 116 | } |
117 | if (SQLITE_DONE != sqlite3_step (stmt_insert)) | 117 | if (SQLITE_DONE != sqlite3_step(stmt_insert)) |
118 | { | 118 | { |
119 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step"); | 119 | LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step"); |
120 | return GNUNET_SYSERR; | 120 | return GNUNET_SYSERR; |
121 | } | 121 | } |
122 | fprintf (stdout, "%u -> %u\n", A, B); | 122 | fprintf(stdout, "%u -> %u\n", A, B); |
123 | GNUNET_break (SQLITE_OK == sqlite3_reset (stmt_insert)); | 123 | GNUNET_break(SQLITE_OK == sqlite3_reset(stmt_insert)); |
124 | //GNUNET_break (SQLITE_OK == sqlite3_clear_bindings (stmt_insert)); | 124 | //GNUNET_break (SQLITE_OK == sqlite3_clear_bindings (stmt_insert)); |
125 | if ((SQLITE_OK != sqlite3_bind_int (stmt_insert, 1, B)) || | 125 | if ((SQLITE_OK != sqlite3_bind_int(stmt_insert, 1, B)) || |
126 | (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, A))) | 126 | (SQLITE_OK != sqlite3_bind_int(stmt_insert, 2, A))) |
127 | { | 127 | { |
128 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int"); | 128 | LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int"); |
129 | return GNUNET_SYSERR; | 129 | return GNUNET_SYSERR; |
130 | } | 130 | } |
131 | if (SQLITE_DONE != sqlite3_step (stmt_insert)) | 131 | if (SQLITE_DONE != sqlite3_step(stmt_insert)) |
132 | { | 132 | { |
133 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step"); | 133 | LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step"); |
134 | return GNUNET_SYSERR; | 134 | return GNUNET_SYSERR; |
135 | } | 135 | } |
136 | fprintf (stdout, "%u -> %u\n", B, A); | 136 | fprintf(stdout, "%u -> %u\n", B, A); |
137 | GNUNET_break (SQLITE_OK == sqlite3_reset (stmt_insert)); | 137 | GNUNET_break(SQLITE_OK == sqlite3_reset(stmt_insert)); |
138 | return GNUNET_OK; | 138 | return GNUNET_OK; |
139 | } | 139 | } |
140 | 140 | ||
@@ -148,7 +148,7 @@ link_processor (void *cls, | |||
148 | * to be printed) | 148 | * to be printed) |
149 | */ | 149 | */ |
150 | static int | 150 | static int |
151 | setup_db (const char *dbfile) | 151 | setup_db(const char *dbfile) |
152 | { | 152 | { |
153 | const char *query_create = "CREATE TABLE whitelist (" | 153 | const char *query_create = "CREATE TABLE whitelist (" |
154 | "id INTEGER," | 154 | "id INTEGER," |
@@ -176,28 +176,28 @@ setup_db (const char *dbfile) | |||
176 | int ret; | 176 | int ret; |
177 | 177 | ||
178 | ret = GNUNET_SYSERR; | 178 | ret = GNUNET_SYSERR; |
179 | if (SQLITE_OK != sqlite3_open (dbfile, &db)) | 179 | if (SQLITE_OK != sqlite3_open(dbfile, &db)) |
180 | { | 180 | { |
181 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_open"); | 181 | LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_open"); |
182 | goto err_ret; | 182 | goto err_ret; |
183 | } | 183 | } |
184 | if (0 != sqlite3_exec (db, query_create, NULL, NULL, NULL)) | 184 | if (0 != sqlite3_exec(db, query_create, NULL, NULL, NULL)) |
185 | { | 185 | { |
186 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); | 186 | LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); |
187 | fprintf (stderr, | 187 | fprintf(stderr, |
188 | "Error: %d. Perhaps the database `%s' already exits.\n", | 188 | "Error: %d. Perhaps the database `%s' already exits.\n", |
189 | sqlite3_errcode (db), | 189 | sqlite3_errcode(db), |
190 | dbfile); | 190 | dbfile); |
191 | goto err_ret; | 191 | goto err_ret; |
192 | } | 192 | } |
193 | GNUNET_break (0 == | 193 | GNUNET_break(0 == |
194 | sqlite3_exec (db, "PRAGMA synchronous = 0;", NULL, NULL, NULL)); | 194 | sqlite3_exec(db, "PRAGMA synchronous = 0;", NULL, NULL, NULL)); |
195 | if (SQLITE_OK != | 195 | if (SQLITE_OK != |
196 | sqlite3_prepare_v2 (db, query_insert, -1, &stmt_insert, NULL)) | 196 | sqlite3_prepare_v2(db, query_insert, -1, &stmt_insert, NULL)) |
197 | { | 197 | { |
198 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2"); | 198 | LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2"); |
199 | goto err_ret; | 199 | goto err_ret; |
200 | } | 200 | } |
201 | ret = GNUNET_OK; | 201 | ret = GNUNET_OK; |
202 | 202 | ||
203 | err_ret: | 203 | err_ret: |
@@ -214,10 +214,10 @@ err_ret: | |||
214 | * @param cfg the configuration file handle | 214 | * @param cfg the configuration file handle |
215 | */ | 215 | */ |
216 | static void | 216 | static void |
217 | run (void *cls, | 217 | run(void *cls, |
218 | char *const *args, | 218 | char *const *args, |
219 | const char *cfgfile, | 219 | const char *cfgfile, |
220 | const struct GNUNET_CONFIGURATION_Handle *config) | 220 | const struct GNUNET_CONFIGURATION_Handle *config) |
221 | { | 221 | { |
222 | const char *dbfile; | 222 | const char *dbfile; |
223 | const char *topology_string; | 223 | const char *topology_string; |
@@ -231,118 +231,125 @@ run (void *cls, | |||
231 | arg_uint1 = 0; /* make compilers happy */ | 231 | arg_uint1 = 0; /* make compilers happy */ |
232 | arg_uint2 = 0; /* make compilers happy */ | 232 | arg_uint2 = 0; /* make compilers happy */ |
233 | if (NULL == args) | 233 | if (NULL == args) |
234 | { | 234 | { |
235 | LOG_ERROR (_ ("Need at least 2 arguments\n")); | 235 | LOG_ERROR(_("Need at least 2 arguments\n")); |
236 | return; | 236 | return; |
237 | } | 237 | } |
238 | if (NULL == (dbfile = args[argc++])) | 238 | if (NULL == (dbfile = args[argc++])) |
239 | { | ||
240 | LOG_ERROR (_ ("Database filename missing\n")); | ||
241 | return; | ||
242 | } | ||
243 | if (GNUNET_OK != setup_db (dbfile)) | ||
244 | return; | ||
245 | if (NULL == (topology_string = args[argc++])) | ||
246 | { | ||
247 | LOG_ERROR (_ ("Topology string missing\n")); | ||
248 | return; | ||
249 | } | ||
250 | if (GNUNET_YES != GNUNET_TESTBED_topology_get_ (&topology, topology_string)) | ||
251 | { | ||
252 | LOG_ERROR (_ ("Invalid topology: %s\n"), topology_string); | ||
253 | return; | ||
254 | } | ||
255 | arg_str1 = NULL; | ||
256 | /* parse for first TOPOOPT. This can either be arg_uint1 or arg_str1 */ | ||
257 | switch (topology) | ||
258 | { | ||
259 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: | ||
260 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: | ||
261 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: | ||
262 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: | ||
263 | if (NULL == (value = args[argc++])) | ||
264 | { | 239 | { |
265 | LOG_ERROR (_ ("An argument is missing for given topology `%s'\n"), | 240 | LOG_ERROR(_("Database filename missing\n")); |
266 | topology_string); | ||
267 | return; | 241 | return; |
268 | } | 242 | } |
269 | if (-1 == sscanf (value, "%u", &arg_uint1)) | 243 | if (GNUNET_OK != setup_db(dbfile)) |
244 | return; | ||
245 | if (NULL == (topology_string = args[argc++])) | ||
270 | { | 246 | { |
271 | LOG_ERROR (_ ("Invalid argument `%s' given as topology argument\n"), | 247 | LOG_ERROR(_("Topology string missing\n")); |
272 | value); | ||
273 | return; | 248 | return; |
274 | } | 249 | } |
275 | break; | 250 | if (GNUNET_YES != GNUNET_TESTBED_topology_get_(&topology, topology_string)) |
276 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: | ||
277 | if (NULL == (arg_str1 = args[argc++])) | ||
278 | { | 251 | { |
279 | LOG_ERROR (_ ("Filename argument missing for topology `%s'\n"), | 252 | LOG_ERROR(_("Invalid topology: %s\n"), topology_string); |
280 | topology_string); | ||
281 | return; | 253 | return; |
282 | } | 254 | } |
283 | break; | 255 | arg_str1 = NULL; |
284 | default: | 256 | /* parse for first TOPOOPT. This can either be arg_uint1 or arg_str1 */ |
285 | break; | ||
286 | } | ||
287 | /* parse for second TOPOOPT. Only required for SCALE_FREE topology */ | ||
288 | switch (topology) | 257 | switch (topology) |
289 | { | ||
290 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: | ||
291 | if (NULL == (value = args[argc++])) | ||
292 | { | 258 | { |
293 | LOG_ERROR (_ ("Second argument for topology `%s' is missing\n"), | 259 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: |
294 | topology_string); | 260 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: |
295 | return; | 261 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: |
262 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: | ||
263 | if (NULL == (value = args[argc++])) | ||
264 | { | ||
265 | LOG_ERROR(_("An argument is missing for given topology `%s'\n"), | ||
266 | topology_string); | ||
267 | return; | ||
268 | } | ||
269 | if (-1 == sscanf(value, "%u", &arg_uint1)) | ||
270 | { | ||
271 | LOG_ERROR(_("Invalid argument `%s' given as topology argument\n"), | ||
272 | value); | ||
273 | return; | ||
274 | } | ||
275 | break; | ||
276 | |||
277 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: | ||
278 | if (NULL == (arg_str1 = args[argc++])) | ||
279 | { | ||
280 | LOG_ERROR(_("Filename argument missing for topology `%s'\n"), | ||
281 | topology_string); | ||
282 | return; | ||
283 | } | ||
284 | break; | ||
285 | |||
286 | default: | ||
287 | break; | ||
296 | } | 288 | } |
297 | if (-1 == sscanf (value, "%u", &arg_uint2)) | 289 | /* parse for second TOPOOPT. Only required for SCALE_FREE topology */ |
290 | switch (topology) | ||
298 | { | 291 | { |
299 | LOG_ERROR (_ ("Invalid argument `%s'; expecting unsigned int\n"), value); | 292 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: |
300 | return; | 293 | if (NULL == (value = args[argc++])) |
294 | { | ||
295 | LOG_ERROR(_("Second argument for topology `%s' is missing\n"), | ||
296 | topology_string); | ||
297 | return; | ||
298 | } | ||
299 | if (-1 == sscanf(value, "%u", &arg_uint2)) | ||
300 | { | ||
301 | LOG_ERROR(_("Invalid argument `%s'; expecting unsigned int\n"), value); | ||
302 | return; | ||
303 | } | ||
304 | break; | ||
305 | |||
306 | default: | ||
307 | break; | ||
301 | } | 308 | } |
302 | break; | ||
303 | default: | ||
304 | break; | ||
305 | } | ||
306 | /* contruct topologies */ | 309 | /* contruct topologies */ |
307 | switch (topology) | 310 | switch (topology) |
308 | { | 311 | { |
309 | case GNUNET_TESTBED_TOPOLOGY_LINE: | 312 | case GNUNET_TESTBED_TOPOLOGY_LINE: |
310 | case GNUNET_TESTBED_TOPOLOGY_RING: | 313 | case GNUNET_TESTBED_TOPOLOGY_RING: |
311 | case GNUNET_TESTBED_TOPOLOGY_STAR: | 314 | case GNUNET_TESTBED_TOPOLOGY_STAR: |
312 | case GNUNET_TESTBED_TOPOLOGY_CLIQUE: | 315 | case GNUNET_TESTBED_TOPOLOGY_CLIQUE: |
313 | case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: | 316 | case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: |
314 | GNUNET_TESTBED_underlay_construct_ (num_peers, | 317 | GNUNET_TESTBED_underlay_construct_(num_peers, |
315 | link_processor, | 318 | link_processor, |
316 | NULL, | 319 | NULL, |
317 | topology); | 320 | topology); |
318 | break; | 321 | break; |
319 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: | 322 | |
320 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: | 323 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: |
321 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: | 324 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: |
322 | GNUNET_TESTBED_underlay_construct_ (num_peers, | 325 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: |
323 | link_processor, | 326 | GNUNET_TESTBED_underlay_construct_(num_peers, |
324 | NULL, | 327 | link_processor, |
325 | topology, | 328 | NULL, |
326 | arg_uint1); | 329 | topology, |
327 | break; | 330 | arg_uint1); |
328 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: | 331 | break; |
329 | GNUNET_TESTBED_underlay_construct_ (num_peers, | 332 | |
330 | link_processor, | 333 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: |
331 | NULL, | 334 | GNUNET_TESTBED_underlay_construct_(num_peers, |
332 | topology, | 335 | link_processor, |
333 | arg_str1); | 336 | NULL, |
334 | break; | 337 | topology, |
335 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: | 338 | arg_str1); |
336 | GNUNET_TESTBED_underlay_construct_ (num_peers, | 339 | break; |
337 | link_processor, | 340 | |
338 | NULL, | 341 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: |
339 | topology, | 342 | GNUNET_TESTBED_underlay_construct_(num_peers, |
340 | arg_uint1, | 343 | link_processor, |
341 | arg_uint2); | 344 | NULL, |
342 | break; | 345 | topology, |
343 | default: | 346 | arg_uint1, |
344 | GNUNET_assert (0); | 347 | arg_uint2); |
345 | } | 348 | break; |
349 | |||
350 | default: | ||
351 | GNUNET_assert(0); | ||
352 | } | ||
346 | } | 353 | } |
347 | 354 | ||
348 | 355 | ||
@@ -350,25 +357,25 @@ run (void *cls, | |||
350 | * Main | 357 | * Main |
351 | */ | 358 | */ |
352 | int | 359 | int |
353 | main (int argc, char *const argv[]) | 360 | main(int argc, char *const argv[]) |
354 | { | 361 | { |
355 | struct GNUNET_GETOPT_CommandLineOption option[] = { | 362 | struct GNUNET_GETOPT_CommandLineOption option[] = { |
356 | 363 | GNUNET_GETOPT_option_uint('p', | |
357 | GNUNET_GETOPT_option_uint ('p', | 364 | "num-peers", |
358 | "num-peers", | 365 | "COUNT", |
359 | "COUNT", | 366 | gettext_noop("create COUNT number of peers"), |
360 | gettext_noop ("create COUNT number of peers"), | 367 | &num_peers), |
361 | &num_peers), | 368 | GNUNET_GETOPT_OPTION_END |
362 | GNUNET_GETOPT_OPTION_END}; | 369 | }; |
363 | 370 | ||
364 | int ret; | 371 | int ret; |
365 | 372 | ||
366 | exit_result = GNUNET_SYSERR; | 373 | exit_result = GNUNET_SYSERR; |
367 | ret = GNUNET_PROGRAM_run ( | 374 | ret = GNUNET_PROGRAM_run( |
368 | argc, | 375 | argc, |
369 | argv, | 376 | argv, |
370 | "gnunet-underlay-topology", | 377 | "gnunet-underlay-topology", |
371 | _ ( | 378 | _( |
372 | "Generates SQLite3 database representing a given underlay topology.\n" | 379 | "Generates SQLite3 database representing a given underlay topology.\n" |
373 | "Usage: gnunet-underlay-topology [OPTIONS] db-filename TOPO [TOPOOPTS]\n" | 380 | "Usage: gnunet-underlay-topology [OPTIONS] db-filename TOPO [TOPOOPTS]\n" |
374 | "The following options are available for TOPO followed by TOPOOPTS if applicable:\n" | 381 | "The following options are available for TOPO followed by TOPOOPTS if applicable:\n" |
@@ -391,9 +398,9 @@ main (int argc, char *const argv[]) | |||
391 | &run, | 398 | &run, |
392 | NULL); | 399 | NULL); |
393 | if (NULL != stmt_insert) | 400 | if (NULL != stmt_insert) |
394 | sqlite3_finalize (stmt_insert); | 401 | sqlite3_finalize(stmt_insert); |
395 | if (NULL != db) | 402 | if (NULL != db) |
396 | GNUNET_break (SQLITE_OK == sqlite3_close (db)); | 403 | GNUNET_break(SQLITE_OK == sqlite3_close(db)); |
397 | if ((GNUNET_OK != ret) || (GNUNET_OK != exit_result)) | 404 | if ((GNUNET_OK != ret) || (GNUNET_OK != exit_result)) |
398 | return 1; | 405 | return 1; |
399 | return 0; | 406 | return 0; |
diff --git a/src/testbed/gnunet-daemon-latency-logger.c b/src/testbed/gnunet-daemon-latency-logger.c index a1685d849..5e0fffe2b 100644 --- a/src/testbed/gnunet-daemon-latency-logger.c +++ b/src/testbed/gnunet-daemon-latency-logger.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/gnunet-daemon-latency-logger.c | 22 | * @file testbed/gnunet-daemon-latency-logger.c |
@@ -33,14 +33,14 @@ | |||
33 | /** | 33 | /** |
34 | * Logging shorthand | 34 | * Logging shorthand |
35 | */ | 35 | */ |
36 | #define LOG(type,...) \ | 36 | #define LOG(type, ...) \ |
37 | GNUNET_log (type, __VA_ARGS__) | 37 | GNUNET_log(type, __VA_ARGS__) |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * Debug logging shorthand | 40 | * Debug logging shorthand |
41 | */ | 41 | */ |
42 | #define DEBUG(...) \ | 42 | #define DEBUG(...) \ |
43 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 43 | LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Log an error message at log-level 'level' that indicates | 46 | * Log an error message at log-level 'level' that indicates |
@@ -49,19 +49,18 @@ | |||
49 | */ | 49 | */ |
50 | #define LOG_SQLITE(db, msg, level, cmd) \ | 50 | #define LOG_SQLITE(db, msg, level, cmd) \ |
51 | do { \ | 51 | do { \ |
52 | GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), \ | 52 | GNUNET_log_from(level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), \ |
53 | cmd, __FILE__,__LINE__, sqlite3_errmsg(db)); \ | 53 | cmd, __FILE__, __LINE__, sqlite3_errmsg(db)); \ |
54 | if (msg != NULL) \ | 54 | if (msg != NULL) \ |
55 | GNUNET_asprintf(msg, _("`%s' failed at %s:%u with error: %s"), cmd, \ | 55 | GNUNET_asprintf (msg, _("`%s' failed at %s:%u with error: %s"), cmd, \ |
56 | __FILE__, __LINE__, sqlite3_errmsg(db)); \ | 56 | __FILE__, __LINE__, sqlite3_errmsg(db)); \ |
57 | } while(0) | 57 | } while (0) |
58 | 58 | ||
59 | 59 | ||
60 | /** | 60 | /** |
61 | * Entry type to be used in the map to store old latency values | 61 | * Entry type to be used in the map to store old latency values |
62 | */ | 62 | */ |
63 | struct Entry | 63 | struct Entry { |
64 | { | ||
65 | /** | 64 | /** |
66 | * The peer's identity | 65 | * The peer's identity |
67 | */ | 66 | */ |
@@ -72,7 +71,6 @@ struct Entry | |||
72 | * FIXME: type! | 71 | * FIXME: type! |
73 | */ | 72 | */ |
74 | unsigned int latency; | 73 | unsigned int latency; |
75 | |||
76 | }; | 74 | }; |
77 | 75 | ||
78 | 76 | ||
@@ -109,15 +107,15 @@ static struct sqlite3_stmt *stmt_insert; | |||
109 | * #GNUNET_NO if not. | 107 | * #GNUNET_NO if not. |
110 | */ | 108 | */ |
111 | static int | 109 | static int |
112 | free_iterator (void *cls, | 110 | free_iterator(void *cls, |
113 | const struct GNUNET_PeerIdentity *key, | 111 | const struct GNUNET_PeerIdentity *key, |
114 | void *value) | 112 | void *value) |
115 | { | 113 | { |
116 | struct Entry *e = cls; | 114 | struct Entry *e = cls; |
117 | 115 | ||
118 | GNUNET_assert (GNUNET_YES == | 116 | GNUNET_assert(GNUNET_YES == |
119 | GNUNET_CONTAINER_multipeermap_remove (map, key, e)); | 117 | GNUNET_CONTAINER_multipeermap_remove(map, key, e)); |
120 | GNUNET_free (e); | 118 | GNUNET_free(e); |
121 | return GNUNET_YES; | 119 | return GNUNET_YES; |
122 | } | 120 | } |
123 | 121 | ||
@@ -129,24 +127,24 @@ free_iterator (void *cls, | |||
129 | * @return | 127 | * @return |
130 | */ | 128 | */ |
131 | static void | 129 | static void |
132 | do_shutdown (void *cls) | 130 | do_shutdown(void *cls) |
133 | { | 131 | { |
134 | GNUNET_ATS_performance_done (ats); | 132 | GNUNET_ATS_performance_done(ats); |
135 | ats = NULL; | 133 | ats = NULL; |
136 | if (NULL != stmt_insert) | 134 | if (NULL != stmt_insert) |
137 | { | 135 | { |
138 | sqlite3_finalize (stmt_insert); | 136 | sqlite3_finalize(stmt_insert); |
139 | stmt_insert = NULL; | 137 | stmt_insert = NULL; |
140 | } | 138 | } |
141 | GNUNET_break (SQLITE_OK == sqlite3_close (db)); | 139 | GNUNET_break(SQLITE_OK == sqlite3_close(db)); |
142 | db = NULL; | 140 | db = NULL; |
143 | if (NULL != map) | 141 | if (NULL != map) |
144 | { | 142 | { |
145 | GNUNET_assert (GNUNET_SYSERR != | 143 | GNUNET_assert(GNUNET_SYSERR != |
146 | GNUNET_CONTAINER_multipeermap_iterate (map, free_iterator, NULL)); | 144 | GNUNET_CONTAINER_multipeermap_iterate(map, free_iterator, NULL)); |
147 | GNUNET_CONTAINER_multipeermap_destroy (map); | 145 | GNUNET_CONTAINER_multipeermap_destroy(map); |
148 | map = NULL; | 146 | map = NULL; |
149 | } | 147 | } |
150 | } | 148 | } |
151 | 149 | ||
152 | /** | 150 | /** |
@@ -163,85 +161,85 @@ do_shutdown (void *cls) | |||
163 | * @param prop performance data for the address (as far as known) | 161 | * @param prop performance data for the address (as far as known) |
164 | */ | 162 | */ |
165 | static void | 163 | static void |
166 | addr_info_cb (void *cls, | 164 | addr_info_cb(void *cls, |
167 | const struct GNUNET_HELLO_Address *address, | 165 | const struct GNUNET_HELLO_Address *address, |
168 | int address_active, | 166 | int address_active, |
169 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 167 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
170 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 168 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
171 | const struct GNUNET_ATS_Properties *prop) | 169 | const struct GNUNET_ATS_Properties *prop) |
172 | { | 170 | { |
173 | static const char *query_insert = | 171 | static const char *query_insert = |
174 | "INSERT INTO ats_info(" | 172 | "INSERT INTO ats_info(" |
175 | " id," | 173 | " id," |
176 | " val," | 174 | " val," |
177 | " timestamp" | 175 | " timestamp" |
178 | ") VALUES (" | 176 | ") VALUES (" |
179 | " ?1," | 177 | " ?1," |
180 | " ?2," | 178 | " ?2," |
181 | " datetime('now')" | 179 | " datetime('now')" |
182 | ");"; | 180 | ");"; |
183 | struct Entry *entry; | 181 | struct Entry *entry; |
184 | int latency; /* FIXME: type!? */ | 182 | int latency; /* FIXME: type!? */ |
185 | 183 | ||
186 | if (NULL == address) | 184 | if (NULL == address) |
187 | { | 185 | { |
188 | /* ATS service temporarily disconnected */ | 186 | /* ATS service temporarily disconnected */ |
189 | return; | 187 | return; |
190 | } | 188 | } |
191 | 189 | ||
192 | GNUNET_assert (NULL != db); | 190 | GNUNET_assert(NULL != db); |
193 | if (GNUNET_YES != address_active) | 191 | if (GNUNET_YES != address_active) |
194 | return; | 192 | return; |
195 | latency = (int) prop->delay.rel_value_us; | 193 | latency = (int)prop->delay.rel_value_us; |
196 | entry = NULL; | 194 | entry = NULL; |
197 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (map, | 195 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(map, |
198 | &address->peer)) | 196 | &address->peer)) |
199 | { | 197 | { |
200 | entry = GNUNET_CONTAINER_multipeermap_get (map, &address->peer); | 198 | entry = GNUNET_CONTAINER_multipeermap_get(map, &address->peer); |
201 | GNUNET_assert (NULL != entry); | 199 | GNUNET_assert(NULL != entry); |
202 | if (latency == entry->latency) | 200 | if (latency == entry->latency) |
203 | return; | 201 | return; |
204 | } | 202 | } |
205 | if (NULL == stmt_insert) | 203 | if (NULL == stmt_insert) |
206 | { | ||
207 | if (SQLITE_OK != sqlite3_prepare_v2 (db, query_insert, -1, &stmt_insert, | ||
208 | NULL)) | ||
209 | { | 204 | { |
210 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2"); | 205 | if (SQLITE_OK != sqlite3_prepare_v2(db, query_insert, -1, &stmt_insert, |
206 | NULL)) | ||
207 | { | ||
208 | LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2"); | ||
209 | goto err_shutdown; | ||
210 | } | ||
211 | } | ||
212 | if ((SQLITE_OK != sqlite3_bind_text(stmt_insert, 1, | ||
213 | GNUNET_i2s(&address->peer), -1, | ||
214 | SQLITE_STATIC)) || | ||
215 | (SQLITE_OK != sqlite3_bind_int(stmt_insert, 2, latency))) | ||
216 | { | ||
217 | LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_text"); | ||
218 | goto err_shutdown; | ||
219 | } | ||
220 | if (SQLITE_DONE != sqlite3_step(stmt_insert)) | ||
221 | { | ||
222 | LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step"); | ||
223 | goto err_shutdown; | ||
224 | } | ||
225 | if (SQLITE_OK != sqlite3_reset(stmt_insert)) | ||
226 | { | ||
227 | LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_insert"); | ||
211 | goto err_shutdown; | 228 | goto err_shutdown; |
212 | } | 229 | } |
213 | } | ||
214 | if ( (SQLITE_OK != sqlite3_bind_text (stmt_insert, 1, | ||
215 | GNUNET_i2s (&address->peer), -1, | ||
216 | SQLITE_STATIC)) || | ||
217 | (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, latency)) ) | ||
218 | { | ||
219 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_text"); | ||
220 | goto err_shutdown; | ||
221 | } | ||
222 | if (SQLITE_DONE != sqlite3_step (stmt_insert)) | ||
223 | { | ||
224 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step"); | ||
225 | goto err_shutdown; | ||
226 | } | ||
227 | if (SQLITE_OK != sqlite3_reset (stmt_insert)) | ||
228 | { | ||
229 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_insert"); | ||
230 | goto err_shutdown; | ||
231 | } | ||
232 | if (NULL == entry) | 230 | if (NULL == entry) |
233 | { | 231 | { |
234 | entry = GNUNET_new (struct Entry); | 232 | entry = GNUNET_new(struct Entry); |
235 | entry->id = address->peer; | 233 | entry->id = address->peer; |
236 | GNUNET_CONTAINER_multipeermap_put (map, | 234 | GNUNET_CONTAINER_multipeermap_put(map, |
237 | &entry->id, entry, | 235 | &entry->id, entry, |
238 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 236 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
239 | } | 237 | } |
240 | entry->latency = latency; | 238 | entry->latency = latency; |
241 | return; | 239 | return; |
242 | 240 | ||
243 | err_shutdown: | 241 | err_shutdown: |
244 | GNUNET_SCHEDULER_shutdown (); | 242 | GNUNET_SCHEDULER_shutdown(); |
245 | } | 243 | } |
246 | 244 | ||
247 | 245 | ||
@@ -254,45 +252,45 @@ addr_info_cb (void *cls, | |||
254 | * @param c configuration | 252 | * @param c configuration |
255 | */ | 253 | */ |
256 | static void | 254 | static void |
257 | run (void *cls, char *const *args, const char *cfgfile, | 255 | run(void *cls, char *const *args, const char *cfgfile, |
258 | const struct GNUNET_CONFIGURATION_Handle *c) | 256 | const struct GNUNET_CONFIGURATION_Handle *c) |
259 | { | 257 | { |
260 | const char *query_create = | 258 | const char *query_create = |
261 | "CREATE TABLE ats_info (" | 259 | "CREATE TABLE ats_info (" |
262 | "id TEXT," | 260 | "id TEXT," |
263 | "val INTEGER," | 261 | "val INTEGER," |
264 | "timestamp NUMERIC" | 262 | "timestamp NUMERIC" |
265 | ");"; | 263 | ");"; |
266 | char *dbfile; | 264 | char *dbfile; |
267 | 265 | ||
268 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "LATENCY-LOGGER", | 266 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(c, "LATENCY-LOGGER", |
269 | "DBFILE", | 267 | "DBFILE", |
270 | &dbfile)) | 268 | &dbfile)) |
271 | { | ||
272 | GNUNET_break (0); | ||
273 | return; | ||
274 | } | ||
275 | if (SQLITE_OK != sqlite3_open (dbfile, &db)) | ||
276 | { | ||
277 | if (NULL != db) | ||
278 | { | 269 | { |
279 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_open_v2"); | 270 | GNUNET_break(0); |
280 | GNUNET_break (SQLITE_OK == sqlite3_close (db)); | 271 | return; |
281 | } | 272 | } |
282 | else | 273 | if (SQLITE_OK != sqlite3_open(dbfile, &db)) |
283 | LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot open sqlite file %s\n", dbfile); | 274 | { |
284 | GNUNET_free (dbfile); | 275 | if (NULL != db) |
285 | return; | 276 | { |
286 | } | 277 | LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_open_v2"); |
287 | if (0 != sqlite3_exec (db, query_create, NULL, NULL, NULL)) | 278 | GNUNET_break(SQLITE_OK == sqlite3_close(db)); |
288 | DEBUG ("SQLite Error: %d. Perhaps the database `%s' already exits.\n", | 279 | } |
289 | sqlite3_errcode (db), dbfile); | 280 | else |
290 | DEBUG ("Opened database %s\n", dbfile); | 281 | LOG(GNUNET_ERROR_TYPE_ERROR, "Cannot open sqlite file %s\n", dbfile); |
291 | GNUNET_free (dbfile); | 282 | GNUNET_free(dbfile); |
283 | return; | ||
284 | } | ||
285 | if (0 != sqlite3_exec(db, query_create, NULL, NULL, NULL)) | ||
286 | DEBUG("SQLite Error: %d. Perhaps the database `%s' already exits.\n", | ||
287 | sqlite3_errcode(db), dbfile); | ||
288 | DEBUG("Opened database %s\n", dbfile); | ||
289 | GNUNET_free(dbfile); | ||
292 | dbfile = NULL; | 290 | dbfile = NULL; |
293 | ats = GNUNET_ATS_performance_init (c, &addr_info_cb, NULL); | 291 | ats = GNUNET_ATS_performance_init(c, &addr_info_cb, NULL); |
294 | map = GNUNET_CONTAINER_multipeermap_create (30, GNUNET_YES); | 292 | map = GNUNET_CONTAINER_multipeermap_create(30, GNUNET_YES); |
295 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 293 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
296 | } | 294 | } |
297 | 295 | ||
298 | 296 | ||
@@ -300,20 +298,20 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
300 | * Execution entry point | 298 | * Execution entry point |
301 | */ | 299 | */ |
302 | int | 300 | int |
303 | main (int argc, char * const *argv) | 301 | main(int argc, char * const *argv) |
304 | { | 302 | { |
305 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 303 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
306 | GNUNET_GETOPT_OPTION_END | 304 | GNUNET_GETOPT_OPTION_END |
307 | }; | 305 | }; |
308 | int ret; | 306 | int ret; |
309 | 307 | ||
310 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 308 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
311 | return 2; | 309 | return 2; |
312 | ret = | 310 | ret = |
313 | (GNUNET_OK == | 311 | (GNUNET_OK == |
314 | GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-latency-logger", | 312 | GNUNET_PROGRAM_run(argc, argv, "gnunet-daemon-latency-logger", |
315 | _("Daemon to log latency values of connections to neighbours"), | 313 | _("Daemon to log latency values of connections to neighbours"), |
316 | options, &run, NULL)) ? 0 : 1; | 314 | options, &run, NULL)) ? 0 : 1; |
317 | GNUNET_free ((void*) argv); | 315 | GNUNET_free((void*)argv); |
318 | return ret; | 316 | return ret; |
319 | } | 317 | } |
diff --git a/src/testbed/gnunet-daemon-testbed-blacklist.c b/src/testbed/gnunet-daemon-testbed-blacklist.c index a91c6a161..e894fb79d 100644 --- a/src/testbed/gnunet-daemon-testbed-blacklist.c +++ b/src/testbed/gnunet-daemon-testbed-blacklist.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | 21 | ||
22 | /** | 22 | /** |
@@ -34,14 +34,14 @@ | |||
34 | /** | 34 | /** |
35 | * Logging shorthand | 35 | * Logging shorthand |
36 | */ | 36 | */ |
37 | #define LOG(type,...) \ | 37 | #define LOG(type, ...) \ |
38 | GNUNET_log (type, __VA_ARGS__) | 38 | GNUNET_log(type, __VA_ARGS__) |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Debug logging shorthand | 41 | * Debug logging shorthand |
42 | */ | 42 | */ |
43 | #define DEBUG(...) \ | 43 | #define DEBUG(...) \ |
44 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 44 | LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * Allow access from the peers read from the whitelist | 47 | * Allow access from the peers read from the whitelist |
@@ -79,13 +79,13 @@ static int mode; | |||
79 | * Cleaup and destroy the map | 79 | * Cleaup and destroy the map |
80 | */ | 80 | */ |
81 | static void | 81 | static void |
82 | cleanup_map () | 82 | cleanup_map() |
83 | { | 83 | { |
84 | if (NULL != map) | 84 | if (NULL != map) |
85 | { | 85 | { |
86 | GNUNET_CONTAINER_multipeermap_destroy (map); | 86 | GNUNET_CONTAINER_multipeermap_destroy(map); |
87 | map = NULL; | 87 | map = NULL; |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | 91 | ||
@@ -95,11 +95,11 @@ cleanup_map () | |||
95 | * @param cls NULL | 95 | * @param cls NULL |
96 | */ | 96 | */ |
97 | static void | 97 | static void |
98 | do_shutdown (void *cls) | 98 | do_shutdown(void *cls) |
99 | { | 99 | { |
100 | cleanup_map (); | 100 | cleanup_map(); |
101 | if (NULL != bh) | 101 | if (NULL != bh) |
102 | GNUNET_TRANSPORT_blacklist_cancel (bh); | 102 | GNUNET_TRANSPORT_blacklist_cancel(bh); |
103 | } | 103 | } |
104 | 104 | ||
105 | 105 | ||
@@ -111,12 +111,12 @@ do_shutdown (void *cls) | |||
111 | * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not | 111 | * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not |
112 | */ | 112 | */ |
113 | static int | 113 | static int |
114 | check_access (void *cls, const struct GNUNET_PeerIdentity * pid) | 114 | check_access(void *cls, const struct GNUNET_PeerIdentity * pid) |
115 | { | 115 | { |
116 | int contains; | 116 | int contains; |
117 | 117 | ||
118 | if (NULL != map) | 118 | if (NULL != map) |
119 | contains = GNUNET_CONTAINER_multipeermap_contains (map, pid); | 119 | contains = GNUNET_CONTAINER_multipeermap_contains(map, pid); |
120 | else | 120 | else |
121 | contains = GNUNET_NO; | 121 | contains = GNUNET_NO; |
122 | if (ACCESS_DENY == mode) | 122 | if (ACCESS_DENY == mode) |
@@ -133,42 +133,42 @@ check_access (void *cls, const struct GNUNET_PeerIdentity * pid) | |||
133 | * @param cfg the configuration for connecting to the peer's transport service | 133 | * @param cfg the configuration for connecting to the peer's transport service |
134 | */ | 134 | */ |
135 | static void | 135 | static void |
136 | setup_ac (const char *fname, | 136 | setup_ac(const char *fname, |
137 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 137 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
138 | { | 138 | { |
139 | uint64_t fsize; | 139 | uint64_t fsize; |
140 | unsigned int npeers; | 140 | unsigned int npeers; |
141 | unsigned int cnt; | 141 | unsigned int cnt; |
142 | 142 | ||
143 | GNUNET_assert (GNUNET_OK != | 143 | GNUNET_assert(GNUNET_OK != |
144 | GNUNET_DISK_file_size (fname, &fsize, GNUNET_NO, | 144 | GNUNET_DISK_file_size(fname, &fsize, GNUNET_NO, |
145 | GNUNET_YES)); | 145 | GNUNET_YES)); |
146 | if (0 != (fsize % sizeof (struct GNUNET_PeerIdentity))) | 146 | if (0 != (fsize % sizeof(struct GNUNET_PeerIdentity))) |
147 | { | 147 | { |
148 | GNUNET_break (0); | 148 | GNUNET_break(0); |
149 | return; | 149 | return; |
150 | } | 150 | } |
151 | npeers = fsize / sizeof (struct GNUNET_PeerIdentity); | 151 | npeers = fsize / sizeof(struct GNUNET_PeerIdentity); |
152 | if (0 != npeers) | 152 | if (0 != npeers) |
153 | { | 153 | { |
154 | map = GNUNET_CONTAINER_multipeermap_create (npeers, GNUNET_YES); | 154 | map = GNUNET_CONTAINER_multipeermap_create(npeers, GNUNET_YES); |
155 | ilist = GNUNET_malloc_large (fsize); | 155 | ilist = GNUNET_malloc_large(fsize); |
156 | GNUNET_assert (fsize == GNUNET_DISK_fn_read (fname, ilist, fsize)); | 156 | GNUNET_assert(fsize == GNUNET_DISK_fn_read(fname, ilist, fsize)); |
157 | } | 157 | } |
158 | for (cnt = 0; cnt < npeers; cnt++) | 158 | for (cnt = 0; cnt < npeers; cnt++) |
159 | { | ||
160 | if (GNUNET_SYSERR == | ||
161 | GNUNET_CONTAINER_multipeermap_put (map, &ilist[cnt], | ||
162 | &ilist[cnt], | ||
163 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
164 | { | 159 | { |
165 | cleanup_map (); | 160 | if (GNUNET_SYSERR == |
166 | GNUNET_free (ilist); | 161 | GNUNET_CONTAINER_multipeermap_put(map, &ilist[cnt], |
167 | return; | 162 | &ilist[cnt], |
163 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
164 | { | ||
165 | cleanup_map(); | ||
166 | GNUNET_free(ilist); | ||
167 | return; | ||
168 | } | ||
168 | } | 169 | } |
169 | } | 170 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
170 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 171 | bh = GNUNET_TRANSPORT_blacklist(cfg, &check_access, NULL); |
171 | bh = GNUNET_TRANSPORT_blacklist (cfg, &check_access, NULL); | ||
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
@@ -181,45 +181,45 @@ setup_ac (const char *fname, | |||
181 | * @param c configuration | 181 | * @param c configuration |
182 | */ | 182 | */ |
183 | static void | 183 | static void |
184 | run (void *cls, | 184 | run(void *cls, |
185 | char *const *args, | 185 | char *const *args, |
186 | const char *cfgfile, | 186 | const char *cfgfile, |
187 | const struct GNUNET_CONFIGURATION_Handle *c) | 187 | const struct GNUNET_CONFIGURATION_Handle *c) |
188 | { | 188 | { |
189 | char *shome; | 189 | char *shome; |
190 | char *fname; | 190 | char *fname; |
191 | 191 | ||
192 | if (GNUNET_OK != | 192 | if (GNUNET_OK != |
193 | GNUNET_CONFIGURATION_get_value_filename (c, | 193 | GNUNET_CONFIGURATION_get_value_filename(c, |
194 | "PATHS", | 194 | "PATHS", |
195 | "GNUNET_HOME", | 195 | "GNUNET_HOME", |
196 | &shome)) | 196 | &shome)) |
197 | { | 197 | { |
198 | GNUNET_break (0); | 198 | GNUNET_break(0); |
199 | return; | 199 | return; |
200 | } | 200 | } |
201 | GNUNET_asprintf (&fname, | 201 | GNUNET_asprintf(&fname, |
202 | "%s/whitelist", | 202 | "%s/whitelist", |
203 | shome); | 203 | shome); |
204 | if (GNUNET_YES == GNUNET_DISK_file_test (fname)) | 204 | if (GNUNET_YES == GNUNET_DISK_file_test(fname)) |
205 | { | 205 | { |
206 | mode = ACCESS_ALLOW; | 206 | mode = ACCESS_ALLOW; |
207 | setup_ac (fname, c); | 207 | setup_ac(fname, c); |
208 | GNUNET_free (shome); | 208 | GNUNET_free(shome); |
209 | GNUNET_free (fname); | 209 | GNUNET_free(fname); |
210 | return; | 210 | return; |
211 | } | 211 | } |
212 | GNUNET_free (fname); | 212 | GNUNET_free(fname); |
213 | GNUNET_asprintf (&fname, | 213 | GNUNET_asprintf(&fname, |
214 | "%s/blacklist", | 214 | "%s/blacklist", |
215 | shome); | 215 | shome); |
216 | if (GNUNET_YES == GNUNET_DISK_file_test (fname)) | 216 | if (GNUNET_YES == GNUNET_DISK_file_test(fname)) |
217 | { | 217 | { |
218 | mode = ACCESS_DENY; | 218 | mode = ACCESS_DENY; |
219 | setup_ac (shome, c); | 219 | setup_ac(shome, c); |
220 | } | 220 | } |
221 | GNUNET_free (shome); | 221 | GNUNET_free(shome); |
222 | GNUNET_free (fname); | 222 | GNUNET_free(fname); |
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
@@ -231,7 +231,7 @@ run (void *cls, | |||
231 | * @return 0 ok, 1 on error | 231 | * @return 0 ok, 1 on error |
232 | */ | 232 | */ |
233 | int | 233 | int |
234 | main (int argc, char *const *argv) | 234 | main(int argc, char *const *argv) |
235 | { | 235 | { |
236 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 236 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
237 | GNUNET_GETOPT_OPTION_END | 237 | GNUNET_GETOPT_OPTION_END |
@@ -239,15 +239,15 @@ main (int argc, char *const *argv) | |||
239 | int ret; | 239 | int ret; |
240 | 240 | ||
241 | if (GNUNET_OK != | 241 | if (GNUNET_OK != |
242 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 242 | GNUNET_STRINGS_get_utf8_args(argc, argv, |
243 | &argc, &argv)) | 243 | &argc, &argv)) |
244 | return 2; | 244 | return 2; |
245 | ret = | 245 | ret = |
246 | (GNUNET_OK == | 246 | (GNUNET_OK == |
247 | GNUNET_PROGRAM_run (argc, argv, | 247 | GNUNET_PROGRAM_run(argc, argv, |
248 | "gnunet-daemon-testbed-blacklist", | 248 | "gnunet-daemon-testbed-blacklist", |
249 | _("Daemon to restrict incoming transport layer connections during testbed deployments"), | 249 | _("Daemon to restrict incoming transport layer connections during testbed deployments"), |
250 | options, &run, NULL)) ? 0 : 1; | 250 | options, &run, NULL)) ? 0 : 1; |
251 | GNUNET_free ((void*) argv); | 251 | GNUNET_free((void*)argv); |
252 | return ret; | 252 | return ret; |
253 | } | 253 | } |
diff --git a/src/testbed/gnunet-daemon-testbed-underlay.c b/src/testbed/gnunet-daemon-testbed-underlay.c index f5f6899e9..0c6a3c3df 100644 --- a/src/testbed/gnunet-daemon-testbed-underlay.c +++ b/src/testbed/gnunet-daemon-testbed-underlay.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | 21 | ||
22 | /** | 22 | /** |
@@ -37,14 +37,14 @@ | |||
37 | /** | 37 | /** |
38 | * Logging shorthand | 38 | * Logging shorthand |
39 | */ | 39 | */ |
40 | #define LOG(type,...) \ | 40 | #define LOG(type, ...) \ |
41 | GNUNET_log (type, __VA_ARGS__) | 41 | GNUNET_log(type, __VA_ARGS__) |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Debug logging shorthand | 44 | * Debug logging shorthand |
45 | */ | 45 | */ |
46 | #define DEBUG(...) \ | 46 | #define DEBUG(...) \ |
47 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 47 | LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
48 | 48 | ||
49 | /** | 49 | /** |
50 | * Log an error message at log-level 'level' that indicates | 50 | * Log an error message at log-level 'level' that indicates |
@@ -53,12 +53,12 @@ | |||
53 | */ | 53 | */ |
54 | #define LOG_SQLITE(db, msg, level, cmd) \ | 54 | #define LOG_SQLITE(db, msg, level, cmd) \ |
55 | do { \ | 55 | do { \ |
56 | GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), \ | 56 | GNUNET_log_from(level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), \ |
57 | cmd, __FILE__,__LINE__, sqlite3_errmsg(db)); \ | 57 | cmd, __FILE__, __LINE__, sqlite3_errmsg(db)); \ |
58 | if (msg != NULL) \ | 58 | if (msg != NULL) \ |
59 | GNUNET_asprintf(msg, _("`%s' failed at %s:%u with error: %s"), cmd, \ | 59 | GNUNET_asprintf (msg, _("`%s' failed at %s:%u with error: %s"), cmd, \ |
60 | __FILE__, __LINE__, sqlite3_errmsg(db)); \ | 60 | __FILE__, __LINE__, sqlite3_errmsg(db)); \ |
61 | } while(0) | 61 | } while (0) |
62 | 62 | ||
63 | 63 | ||
64 | /** | 64 | /** |
@@ -115,10 +115,10 @@ static unsigned int num_hostkeys; | |||
115 | * #GNUNET_NO if not. | 115 | * #GNUNET_NO if not. |
116 | */ | 116 | */ |
117 | static int | 117 | static int |
118 | iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | 118 | iterator(void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
119 | { | 119 | { |
120 | GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (map, key, | 120 | GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove(map, key, |
121 | value)); | 121 | value)); |
122 | return GNUNET_YES; | 122 | return GNUNET_YES; |
123 | } | 123 | } |
124 | 124 | ||
@@ -127,16 +127,16 @@ iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | |||
127 | * Cleaup and destroy the map | 127 | * Cleaup and destroy the map |
128 | */ | 128 | */ |
129 | static void | 129 | static void |
130 | cleanup_map () | 130 | cleanup_map() |
131 | { | 131 | { |
132 | if (NULL != map) | 132 | if (NULL != map) |
133 | { | 133 | { |
134 | GNUNET_assert (GNUNET_SYSERR != GNUNET_CONTAINER_multipeermap_iterate (map, | 134 | GNUNET_assert(GNUNET_SYSERR != GNUNET_CONTAINER_multipeermap_iterate(map, |
135 | &iterator, | 135 | &iterator, |
136 | NULL)); | 136 | NULL)); |
137 | GNUNET_CONTAINER_multipeermap_destroy (map); | 137 | GNUNET_CONTAINER_multipeermap_destroy(map); |
138 | map = NULL; | 138 | map = NULL; |
139 | } | 139 | } |
140 | } | 140 | } |
141 | 141 | ||
142 | 142 | ||
@@ -148,35 +148,35 @@ cleanup_map () | |||
148 | * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not | 148 | * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not |
149 | */ | 149 | */ |
150 | static int | 150 | static int |
151 | check_access (void *cls, const struct GNUNET_PeerIdentity * pid) | 151 | check_access(void *cls, const struct GNUNET_PeerIdentity * pid) |
152 | { | 152 | { |
153 | int contains; | 153 | int contains; |
154 | 154 | ||
155 | GNUNET_assert (NULL != map); | 155 | GNUNET_assert(NULL != map); |
156 | contains = GNUNET_CONTAINER_multipeermap_contains (map, pid); | 156 | contains = GNUNET_CONTAINER_multipeermap_contains(map, pid); |
157 | if (GNUNET_YES == contains) | 157 | if (GNUNET_YES == contains) |
158 | { | 158 | { |
159 | DEBUG ("Permitting `%s'\n", GNUNET_i2s (pid)); | 159 | DEBUG("Permitting `%s'\n", GNUNET_i2s(pid)); |
160 | return GNUNET_OK; | 160 | return GNUNET_OK; |
161 | } | 161 | } |
162 | DEBUG ("Not permitting `%s'\n", GNUNET_i2s (pid)); | 162 | DEBUG("Not permitting `%s'\n", GNUNET_i2s(pid)); |
163 | return GNUNET_SYSERR; | 163 | return GNUNET_SYSERR; |
164 | } | 164 | } |
165 | 165 | ||
166 | 166 | ||
167 | static int | 167 | static int |
168 | get_identity (unsigned int offset, | 168 | get_identity(unsigned int offset, |
169 | struct GNUNET_PeerIdentity *id) | 169 | struct GNUNET_PeerIdentity *id) |
170 | { | 170 | { |
171 | struct GNUNET_CRYPTO_EddsaPrivateKey private_key; | 171 | struct GNUNET_CRYPTO_EddsaPrivateKey private_key; |
172 | 172 | ||
173 | if (offset >= num_hostkeys) | 173 | if (offset >= num_hostkeys) |
174 | return GNUNET_SYSERR; | 174 | return GNUNET_SYSERR; |
175 | GNUNET_memcpy (&private_key, | 175 | GNUNET_memcpy(&private_key, |
176 | hostkeys_data + (offset * GNUNET_TESTING_HOSTKEYFILESIZE), | 176 | hostkeys_data + (offset * GNUNET_TESTING_HOSTKEYFILESIZE), |
177 | GNUNET_TESTING_HOSTKEYFILESIZE); | 177 | GNUNET_TESTING_HOSTKEYFILESIZE); |
178 | GNUNET_CRYPTO_eddsa_key_get_public (&private_key, | 178 | GNUNET_CRYPTO_eddsa_key_get_public(&private_key, |
179 | &id->public_key); | 179 | &id->public_key); |
180 | return GNUNET_OK; | 180 | return GNUNET_OK; |
181 | } | 181 | } |
182 | 182 | ||
@@ -184,8 +184,7 @@ get_identity (unsigned int offset, | |||
184 | /** | 184 | /** |
185 | * Whilelist entry | 185 | * Whilelist entry |
186 | */ | 186 | */ |
187 | struct WhiteListRow | 187 | struct WhiteListRow { |
188 | { | ||
189 | /** | 188 | /** |
190 | * Next ptr | 189 | * Next ptr |
191 | */ | 190 | */ |
@@ -200,7 +199,6 @@ struct WhiteListRow | |||
200 | * Latency to be assigned to the link | 199 | * Latency to be assigned to the link |
201 | */ | 200 | */ |
202 | int latency; | 201 | int latency; |
203 | |||
204 | }; | 202 | }; |
205 | 203 | ||
206 | 204 | ||
@@ -208,7 +206,7 @@ struct WhiteListRow | |||
208 | * Function to load keys | 206 | * Function to load keys |
209 | */ | 207 | */ |
210 | static int | 208 | static int |
211 | load_keys (const struct GNUNET_CONFIGURATION_Handle *c) | 209 | load_keys(const struct GNUNET_CONFIGURATION_Handle *c) |
212 | { | 210 | { |
213 | char *data_dir; | 211 | char *data_dir; |
214 | char *idfile; | 212 | char *idfile; |
@@ -217,43 +215,42 @@ load_keys (const struct GNUNET_CONFIGURATION_Handle *c) | |||
217 | data_dir = NULL; | 215 | data_dir = NULL; |
218 | idfile = NULL; | 216 | idfile = NULL; |
219 | fsize = 0; | 217 | fsize = 0; |
220 | data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); | 218 | data_dir = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_DATADIR); |
221 | GNUNET_asprintf (&idfile, "%s/testing_hostkeys.ecc", data_dir); | 219 | GNUNET_asprintf(&idfile, "%s/testing_hostkeys.ecc", data_dir); |
222 | GNUNET_free (data_dir); | 220 | GNUNET_free(data_dir); |
223 | data_dir = NULL; | 221 | data_dir = NULL; |
224 | if (GNUNET_OK != | 222 | if (GNUNET_OK != |
225 | GNUNET_DISK_file_size (idfile, &fsize, GNUNET_YES, GNUNET_YES)) | 223 | GNUNET_DISK_file_size(idfile, &fsize, GNUNET_YES, GNUNET_YES)) |
226 | { | 224 | { |
227 | GNUNET_free (idfile); | 225 | GNUNET_free(idfile); |
228 | return GNUNET_SYSERR; | 226 | return GNUNET_SYSERR; |
229 | } | 227 | } |
230 | if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE)) | 228 | if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE)) |
231 | { | 229 | { |
232 | LOG (GNUNET_ERROR_TYPE_ERROR, | 230 | LOG(GNUNET_ERROR_TYPE_ERROR, |
233 | _("Incorrect hostkey file format: %s\n"), idfile); | 231 | _("Incorrect hostkey file format: %s\n"), idfile); |
234 | GNUNET_free (idfile); | 232 | GNUNET_free(idfile); |
235 | return GNUNET_SYSERR; | 233 | return GNUNET_SYSERR; |
236 | } | 234 | } |
237 | hostkeys_fd = GNUNET_DISK_file_open (idfile, GNUNET_DISK_OPEN_READ, | 235 | hostkeys_fd = GNUNET_DISK_file_open(idfile, GNUNET_DISK_OPEN_READ, |
238 | GNUNET_DISK_PERM_NONE); | 236 | GNUNET_DISK_PERM_NONE); |
239 | if (NULL == hostkeys_fd) | 237 | if (NULL == hostkeys_fd) |
240 | { | 238 | { |
241 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", idfile); | 239 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", idfile); |
242 | GNUNET_free (idfile); | 240 | GNUNET_free(idfile); |
243 | return GNUNET_SYSERR; | 241 | return GNUNET_SYSERR; |
244 | } | 242 | } |
245 | GNUNET_free (idfile); | 243 | GNUNET_free(idfile); |
246 | idfile = NULL; | 244 | idfile = NULL; |
247 | hostkeys_data = GNUNET_DISK_file_map (hostkeys_fd, | 245 | hostkeys_data = GNUNET_DISK_file_map(hostkeys_fd, |
248 | &hostkeys_map, | 246 | &hostkeys_map, |
249 | GNUNET_DISK_MAP_TYPE_READ, | 247 | GNUNET_DISK_MAP_TYPE_READ, |
250 | fsize); | 248 | fsize); |
251 | if (NULL == hostkeys_data) | 249 | if (NULL == hostkeys_data) |
252 | { | 250 | { |
253 | 251 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "mmap"); | |
254 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "mmap"); | 252 | return GNUNET_SYSERR; |
255 | return GNUNET_SYSERR; | 253 | } |
256 | } | ||
257 | num_hostkeys = fsize / GNUNET_TESTING_HOSTKEYFILESIZE; | 254 | num_hostkeys = fsize / GNUNET_TESTING_HOSTKEYFILESIZE; |
258 | return GNUNET_OK; | 255 | return GNUNET_OK; |
259 | } | 256 | } |
@@ -263,20 +260,20 @@ load_keys (const struct GNUNET_CONFIGURATION_Handle *c) | |||
263 | * Function to unload keys | 260 | * Function to unload keys |
264 | */ | 261 | */ |
265 | static void | 262 | static void |
266 | unload_keys () | 263 | unload_keys() |
267 | { | 264 | { |
268 | if (NULL != hostkeys_map) | 265 | if (NULL != hostkeys_map) |
269 | { | 266 | { |
270 | GNUNET_assert (NULL != hostkeys_data); | 267 | GNUNET_assert(NULL != hostkeys_data); |
271 | GNUNET_DISK_file_unmap (hostkeys_map); | 268 | GNUNET_DISK_file_unmap(hostkeys_map); |
272 | hostkeys_map = NULL; | 269 | hostkeys_map = NULL; |
273 | hostkeys_data = NULL; | 270 | hostkeys_data = NULL; |
274 | } | 271 | } |
275 | if (NULL != hostkeys_fd) | 272 | if (NULL != hostkeys_fd) |
276 | { | 273 | { |
277 | GNUNET_DISK_file_close (hostkeys_fd); | 274 | GNUNET_DISK_file_close(hostkeys_fd); |
278 | hostkeys_fd = NULL; | 275 | hostkeys_fd = NULL; |
279 | } | 276 | } |
280 | } | 277 | } |
281 | 278 | ||
282 | 279 | ||
@@ -286,17 +283,17 @@ unload_keys () | |||
286 | * @param cls NULL | 283 | * @param cls NULL |
287 | */ | 284 | */ |
288 | static void | 285 | static void |
289 | do_shutdown (void *cls) | 286 | do_shutdown(void *cls) |
290 | { | 287 | { |
291 | if (NULL != transport) | 288 | if (NULL != transport) |
292 | { | 289 | { |
293 | GNUNET_TRANSPORT_manipulation_disconnect (transport); | 290 | GNUNET_TRANSPORT_manipulation_disconnect(transport); |
294 | transport = NULL; | 291 | transport = NULL; |
295 | } | 292 | } |
296 | cleanup_map (); | 293 | cleanup_map(); |
297 | unload_keys (); | 294 | unload_keys(); |
298 | if (NULL != bh) | 295 | if (NULL != bh) |
299 | GNUNET_TRANSPORT_blacklist_cancel (bh); | 296 | GNUNET_TRANSPORT_blacklist_cancel(bh); |
300 | } | 297 | } |
301 | 298 | ||
302 | 299 | ||
@@ -309,7 +306,7 @@ do_shutdown (void *cls) | |||
309 | * @return GNUNET_SYSERR upon error OR the number of rows retrieved | 306 | * @return GNUNET_SYSERR upon error OR the number of rows retrieved |
310 | */ | 307 | */ |
311 | static int | 308 | static int |
312 | db_read_whitelist (struct sqlite3 *db, int pid, struct WhiteListRow **wl_rows) | 309 | db_read_whitelist(struct sqlite3 *db, int pid, struct WhiteListRow **wl_rows) |
313 | { | 310 | { |
314 | static const char *query_wl = "SELECT oid, latency FROM whitelist WHERE (id == ?);"; | 311 | static const char *query_wl = "SELECT oid, latency FROM whitelist WHERE (id == ?);"; |
315 | struct sqlite3_stmt *stmt_wl; | 312 | struct sqlite3_stmt *stmt_wl; |
@@ -317,31 +314,32 @@ db_read_whitelist (struct sqlite3 *db, int pid, struct WhiteListRow **wl_rows) | |||
317 | int nrows; | 314 | int nrows; |
318 | int ret; | 315 | int ret; |
319 | 316 | ||
320 | if (SQLITE_OK != (ret = sqlite3_prepare_v2 (db, query_wl, -1, &stmt_wl, NULL))) | 317 | if (SQLITE_OK != (ret = sqlite3_prepare_v2(db, query_wl, -1, &stmt_wl, NULL))) |
321 | { | 318 | { |
322 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2"); | 319 | LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2"); |
323 | return GNUNET_SYSERR; | 320 | return GNUNET_SYSERR; |
324 | } | 321 | } |
325 | if (SQLITE_OK != (ret = sqlite3_bind_int (stmt_wl, 1, pid))) | 322 | if (SQLITE_OK != (ret = sqlite3_bind_int(stmt_wl, 1, pid))) |
326 | { | 323 | { |
327 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int"); | 324 | LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int"); |
328 | sqlite3_finalize (stmt_wl); | 325 | sqlite3_finalize(stmt_wl); |
329 | return GNUNET_SYSERR; | 326 | return GNUNET_SYSERR; |
330 | } | 327 | } |
331 | nrows = 0; | 328 | nrows = 0; |
332 | do | 329 | do |
333 | { | 330 | { |
334 | ret = sqlite3_step (stmt_wl); | 331 | ret = sqlite3_step(stmt_wl); |
335 | if (SQLITE_ROW != ret) | 332 | if (SQLITE_ROW != ret) |
336 | break; | 333 | break; |
337 | nrows++; | 334 | nrows++; |
338 | lr = GNUNET_new (struct WhiteListRow); | 335 | lr = GNUNET_new(struct WhiteListRow); |
339 | lr->id = sqlite3_column_int (stmt_wl, 0); | 336 | lr->id = sqlite3_column_int(stmt_wl, 0); |
340 | lr->latency = sqlite3_column_int (stmt_wl, 1); | 337 | lr->latency = sqlite3_column_int(stmt_wl, 1); |
341 | lr->next = *wl_rows; | 338 | lr->next = *wl_rows; |
342 | *wl_rows = lr; | 339 | *wl_rows = lr; |
343 | } while (1); | 340 | } |
344 | sqlite3_finalize (stmt_wl); | 341 | while (1); |
342 | sqlite3_finalize(stmt_wl); | ||
345 | return nrows; | 343 | return nrows; |
346 | } | 344 | } |
347 | 345 | ||
@@ -355,8 +353,8 @@ db_read_whitelist (struct sqlite3 *db, int pid, struct WhiteListRow **wl_rows) | |||
355 | * @param c configuration | 353 | * @param c configuration |
356 | */ | 354 | */ |
357 | static void | 355 | static void |
358 | run (void *cls, char *const *args, const char *cfgfile, | 356 | run(void *cls, char *const *args, const char *cfgfile, |
359 | const struct GNUNET_CONFIGURATION_Handle *c) | 357 | const struct GNUNET_CONFIGURATION_Handle *c) |
360 | { | 358 | { |
361 | char *dbfile; | 359 | char *dbfile; |
362 | struct WhiteListRow *wl_head; | 360 | struct WhiteListRow *wl_head; |
@@ -369,78 +367,78 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
369 | int ret; | 367 | int ret; |
370 | 368 | ||
371 | if (GNUNET_OK != | 369 | if (GNUNET_OK != |
372 | GNUNET_CONFIGURATION_get_value_number (c, "TESTBED", | 370 | GNUNET_CONFIGURATION_get_value_number(c, "TESTBED", |
373 | "PEERID", &pid)) | 371 | "PEERID", &pid)) |
374 | { | ||
375 | GNUNET_break (0); | ||
376 | return; | ||
377 | } | ||
378 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "TESTBED-UNDERLAY", | ||
379 | "DBFILE", | ||
380 | &dbfile)) | ||
381 | { | ||
382 | GNUNET_break (0); | ||
383 | return; | ||
384 | } | ||
385 | if (SQLITE_OK != (ret = sqlite3_open_v2 (dbfile, &db, SQLITE_OPEN_READONLY, NULL))) | ||
386 | { | ||
387 | if (NULL != db) | ||
388 | { | 372 | { |
389 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_open_v2"); | 373 | GNUNET_break(0); |
390 | GNUNET_break (SQLITE_OK == sqlite3_close (db)); | 374 | return; |
391 | } | 375 | } |
392 | else | 376 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(c, "TESTBED-UNDERLAY", |
393 | LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot open sqlite file %s\n", dbfile); | 377 | "DBFILE", |
394 | GNUNET_free (dbfile); | 378 | &dbfile)) |
395 | return; | 379 | { |
396 | } | 380 | GNUNET_break(0); |
397 | DEBUG ("Opened database %s\n", dbfile); | 381 | return; |
398 | GNUNET_free (dbfile); | 382 | } |
383 | if (SQLITE_OK != (ret = sqlite3_open_v2(dbfile, &db, SQLITE_OPEN_READONLY, NULL))) | ||
384 | { | ||
385 | if (NULL != db) | ||
386 | { | ||
387 | LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_open_v2"); | ||
388 | GNUNET_break(SQLITE_OK == sqlite3_close(db)); | ||
389 | } | ||
390 | else | ||
391 | LOG(GNUNET_ERROR_TYPE_ERROR, "Cannot open sqlite file %s\n", dbfile); | ||
392 | GNUNET_free(dbfile); | ||
393 | return; | ||
394 | } | ||
395 | DEBUG("Opened database %s\n", dbfile); | ||
396 | GNUNET_free(dbfile); | ||
399 | dbfile = NULL; | 397 | dbfile = NULL; |
400 | wl_head = NULL; | 398 | wl_head = NULL; |
401 | if (GNUNET_OK != load_keys (c)) | 399 | if (GNUNET_OK != load_keys(c)) |
402 | goto close_db; | 400 | goto close_db; |
403 | 401 | ||
404 | transport = GNUNET_TRANSPORT_manipulation_connect (c); | 402 | transport = GNUNET_TRANSPORT_manipulation_connect(c); |
405 | if (NULL == transport) | 403 | if (NULL == transport) |
406 | { | 404 | { |
407 | GNUNET_break (0); | 405 | GNUNET_break(0); |
408 | return; | 406 | return; |
409 | } | 407 | } |
410 | /* read and process whitelist */ | 408 | /* read and process whitelist */ |
411 | nrows = 0; | 409 | nrows = 0; |
412 | wl_head = NULL; | 410 | wl_head = NULL; |
413 | nrows = db_read_whitelist (db, pid, &wl_head); | 411 | nrows = db_read_whitelist(db, pid, &wl_head); |
414 | if ((GNUNET_SYSERR == nrows) || (0 == nrows)) | 412 | if ((GNUNET_SYSERR == nrows) || (0 == nrows)) |
415 | { | 413 | { |
416 | GNUNET_TRANSPORT_manipulation_disconnect (transport); | 414 | GNUNET_TRANSPORT_manipulation_disconnect(transport); |
417 | goto close_db; | 415 | goto close_db; |
418 | } | 416 | } |
419 | map = GNUNET_CONTAINER_multipeermap_create (nrows, GNUNET_NO); | 417 | map = GNUNET_CONTAINER_multipeermap_create(nrows, GNUNET_NO); |
420 | while (NULL != (wl_entry = wl_head)) | 418 | while (NULL != (wl_entry = wl_head)) |
421 | { | 419 | { |
422 | wl_head = wl_entry->next; | 420 | wl_head = wl_entry->next; |
423 | delay.rel_value_us = wl_entry->latency; | 421 | delay.rel_value_us = wl_entry->latency; |
424 | memset (&prop, 0, sizeof (prop)); | 422 | memset(&prop, 0, sizeof(prop)); |
425 | GNUNET_assert (GNUNET_OK == get_identity (wl_entry->id, &identity)); | 423 | GNUNET_assert(GNUNET_OK == get_identity(wl_entry->id, &identity)); |
426 | GNUNET_break (GNUNET_OK == | 424 | GNUNET_break(GNUNET_OK == |
427 | GNUNET_CONTAINER_multipeermap_put (map, &identity, &identity, | 425 | GNUNET_CONTAINER_multipeermap_put(map, &identity, &identity, |
428 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 426 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
429 | DEBUG ("Setting %u ms latency to peer `%s'\n", | 427 | DEBUG("Setting %u ms latency to peer `%s'\n", |
430 | wl_entry->latency, | 428 | wl_entry->latency, |
431 | GNUNET_i2s (&identity)); | 429 | GNUNET_i2s(&identity)); |
432 | GNUNET_TRANSPORT_manipulation_set (transport, | 430 | GNUNET_TRANSPORT_manipulation_set(transport, |
433 | &identity, | 431 | &identity, |
434 | &prop, | 432 | &prop, |
435 | delay, | 433 | delay, |
436 | delay); | 434 | delay); |
437 | GNUNET_free (wl_entry); | 435 | GNUNET_free(wl_entry); |
438 | } | 436 | } |
439 | bh = GNUNET_TRANSPORT_blacklist (c, &check_access, NULL); | 437 | bh = GNUNET_TRANSPORT_blacklist(c, &check_access, NULL); |
440 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 438 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
441 | 439 | ||
442 | close_db: | 440 | close_db: |
443 | GNUNET_break (SQLITE_OK == sqlite3_close (db)); | 441 | GNUNET_break(SQLITE_OK == sqlite3_close(db)); |
444 | } | 442 | } |
445 | 443 | ||
446 | 444 | ||
@@ -452,24 +450,24 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
452 | * @return 0 ok, 1 on error | 450 | * @return 0 ok, 1 on error |
453 | */ | 451 | */ |
454 | int | 452 | int |
455 | main (int argc, char *const *argv) | 453 | main(int argc, char *const *argv) |
456 | { | 454 | { |
457 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 455 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
458 | GNUNET_GETOPT_OPTION_END | 456 | GNUNET_GETOPT_OPTION_END |
459 | }; | 457 | }; |
460 | int ret; | 458 | int ret; |
461 | 459 | ||
462 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 460 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
463 | return 2; | 461 | return 2; |
464 | #ifdef SQLITE_CONFIG_MMAP_SIZE | 462 | #ifdef SQLITE_CONFIG_MMAP_SIZE |
465 | (void) sqlite3_config (SQLITE_CONFIG_MMAP_SIZE, 512000, 256000000); | 463 | (void)sqlite3_config(SQLITE_CONFIG_MMAP_SIZE, 512000, 256000000); |
466 | #endif | 464 | #endif |
467 | ret = | 465 | ret = |
468 | (GNUNET_OK == | 466 | (GNUNET_OK == |
469 | GNUNET_PROGRAM_run (argc, argv, "testbed-underlay", | 467 | GNUNET_PROGRAM_run(argc, argv, "testbed-underlay", |
470 | _ | 468 | _ |
471 | ("Daemon to restrict underlay network in testbed deployments"), | 469 | ("Daemon to restrict underlay network in testbed deployments"), |
472 | options, &run, NULL)) ? 0 : 1; | 470 | options, &run, NULL)) ? 0 : 1; |
473 | GNUNET_free ((void*) argv); | 471 | GNUNET_free((void*)argv); |
474 | return ret; | 472 | return ret; |
475 | } | 473 | } |
diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c index a45f8de03..979d6c38f 100644 --- a/src/testbed/gnunet-helper-testbed.c +++ b/src/testbed/gnunet-helper-testbed.c | |||
@@ -49,12 +49,12 @@ | |||
49 | /** | 49 | /** |
50 | * Generic logging shortcut | 50 | * Generic logging shortcut |
51 | */ | 51 | */ |
52 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | 52 | #define LOG(kind, ...) GNUNET_log(kind, __VA_ARGS__) |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Debug logging shorthand | 55 | * Debug logging shorthand |
56 | */ | 56 | */ |
57 | #define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 57 | #define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
58 | 58 | ||
59 | 59 | ||
60 | /** | 60 | /** |
@@ -70,8 +70,7 @@ | |||
70 | /** | 70 | /** |
71 | * Context for a single write on a chunk of memory | 71 | * Context for a single write on a chunk of memory |
72 | */ | 72 | */ |
73 | struct WriteContext | 73 | struct WriteContext { |
74 | { | ||
75 | /** | 74 | /** |
76 | * The data to write | 75 | * The data to write |
77 | */ | 76 | */ |
@@ -151,50 +150,50 @@ static int status; | |||
151 | * @param cls NULL | 150 | * @param cls NULL |
152 | */ | 151 | */ |
153 | static void | 152 | static void |
154 | shutdown_task (void *cls) | 153 | shutdown_task(void *cls) |
155 | { | 154 | { |
156 | LOG_DEBUG ("Shutting down\n"); | 155 | LOG_DEBUG("Shutting down\n"); |
157 | if (NULL != testbed) | 156 | if (NULL != testbed) |
158 | { | 157 | { |
159 | LOG_DEBUG ("Killing testbed\n"); | 158 | LOG_DEBUG("Killing testbed\n"); |
160 | GNUNET_break (0 == GNUNET_OS_process_kill (testbed, GNUNET_TERM_SIG)); | 159 | GNUNET_break(0 == GNUNET_OS_process_kill(testbed, GNUNET_TERM_SIG)); |
161 | } | 160 | } |
162 | if (NULL != read_task_id) | 161 | if (NULL != read_task_id) |
163 | { | 162 | { |
164 | GNUNET_SCHEDULER_cancel (read_task_id); | 163 | GNUNET_SCHEDULER_cancel(read_task_id); |
165 | read_task_id = NULL; | 164 | read_task_id = NULL; |
166 | } | 165 | } |
167 | if (NULL != write_task_id) | 166 | if (NULL != write_task_id) |
168 | { | 167 | { |
169 | struct WriteContext *wc; | 168 | struct WriteContext *wc; |
170 | 169 | ||
171 | wc = GNUNET_SCHEDULER_cancel (write_task_id); | 170 | wc = GNUNET_SCHEDULER_cancel(write_task_id); |
172 | write_task_id = NULL; | 171 | write_task_id = NULL; |
173 | GNUNET_free (wc->data); | 172 | GNUNET_free(wc->data); |
174 | GNUNET_free (wc); | 173 | GNUNET_free(wc); |
175 | } | 174 | } |
176 | if (NULL != child_death_task_id) | 175 | if (NULL != child_death_task_id) |
177 | { | 176 | { |
178 | GNUNET_SCHEDULER_cancel (child_death_task_id); | 177 | GNUNET_SCHEDULER_cancel(child_death_task_id); |
179 | child_death_task_id = NULL; | 178 | child_death_task_id = NULL; |
180 | } | 179 | } |
181 | if (NULL != stdin_fd) | 180 | if (NULL != stdin_fd) |
182 | (void) GNUNET_DISK_file_close (stdin_fd); | 181 | (void)GNUNET_DISK_file_close(stdin_fd); |
183 | if (NULL != stdout_fd) | 182 | if (NULL != stdout_fd) |
184 | (void) GNUNET_DISK_file_close (stdout_fd); | 183 | (void)GNUNET_DISK_file_close(stdout_fd); |
185 | GNUNET_MST_destroy (tokenizer); | 184 | GNUNET_MST_destroy(tokenizer); |
186 | tokenizer = NULL; | 185 | tokenizer = NULL; |
187 | if (NULL != testbed) | 186 | if (NULL != testbed) |
188 | { | 187 | { |
189 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (testbed)); | 188 | GNUNET_break(GNUNET_OK == GNUNET_OS_process_wait(testbed)); |
190 | GNUNET_OS_process_destroy (testbed); | 189 | GNUNET_OS_process_destroy(testbed); |
191 | testbed = NULL; | 190 | testbed = NULL; |
192 | } | 191 | } |
193 | if (NULL != test_system) | 192 | if (NULL != test_system) |
194 | { | 193 | { |
195 | GNUNET_TESTING_system_destroy (test_system, GNUNET_YES); | 194 | GNUNET_TESTING_system_destroy(test_system, GNUNET_YES); |
196 | test_system = NULL; | 195 | test_system = NULL; |
197 | } | 196 | } |
198 | } | 197 | } |
199 | 198 | ||
200 | 199 | ||
@@ -204,34 +203,34 @@ shutdown_task (void *cls) | |||
204 | * @param cls the WriteContext | 203 | * @param cls the WriteContext |
205 | */ | 204 | */ |
206 | static void | 205 | static void |
207 | write_task (void *cls) | 206 | write_task(void *cls) |
208 | { | 207 | { |
209 | struct WriteContext *wc = cls; | 208 | struct WriteContext *wc = cls; |
210 | ssize_t bytes_wrote; | 209 | ssize_t bytes_wrote; |
211 | 210 | ||
212 | GNUNET_assert (NULL != wc); | 211 | GNUNET_assert(NULL != wc); |
213 | write_task_id = NULL; | 212 | write_task_id = NULL; |
214 | bytes_wrote = GNUNET_DISK_file_write (stdout_fd, | 213 | bytes_wrote = GNUNET_DISK_file_write(stdout_fd, |
215 | wc->data + wc->pos, | 214 | wc->data + wc->pos, |
216 | wc->length - wc->pos); | 215 | wc->length - wc->pos); |
217 | if (GNUNET_SYSERR == bytes_wrote) | 216 | if (GNUNET_SYSERR == bytes_wrote) |
218 | { | 217 | { |
219 | LOG (GNUNET_ERROR_TYPE_WARNING, "Cannot reply back configuration\n"); | 218 | LOG(GNUNET_ERROR_TYPE_WARNING, "Cannot reply back configuration\n"); |
220 | GNUNET_free (wc->data); | 219 | GNUNET_free(wc->data); |
221 | GNUNET_free (wc); | 220 | GNUNET_free(wc); |
222 | return; | 221 | return; |
223 | } | 222 | } |
224 | wc->pos += bytes_wrote; | 223 | wc->pos += bytes_wrote; |
225 | if (wc->pos == wc->length) | 224 | if (wc->pos == wc->length) |
226 | { | 225 | { |
227 | GNUNET_free (wc->data); | 226 | GNUNET_free(wc->data); |
228 | GNUNET_free (wc); | 227 | GNUNET_free(wc); |
229 | return; | 228 | return; |
230 | } | 229 | } |
231 | write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, | 230 | write_task_id = GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL, |
232 | stdout_fd, | 231 | stdout_fd, |
233 | &write_task, | 232 | &write_task, |
234 | wc); | 233 | wc); |
235 | } | 234 | } |
236 | 235 | ||
237 | 236 | ||
@@ -242,7 +241,7 @@ write_task (void *cls) | |||
242 | * @param cls closure, NULL if we need to self-restart | 241 | * @param cls closure, NULL if we need to self-restart |
243 | */ | 242 | */ |
244 | static void | 243 | static void |
245 | child_death_task (void *cls) | 244 | child_death_task(void *cls) |
246 | { | 245 | { |
247 | const struct GNUNET_DISK_FileHandle *pr; | 246 | const struct GNUNET_DISK_FileHandle *pr; |
248 | char c[16]; | 247 | char c[16]; |
@@ -250,36 +249,36 @@ child_death_task (void *cls) | |||
250 | unsigned long code; | 249 | unsigned long code; |
251 | int ret; | 250 | int ret; |
252 | 251 | ||
253 | pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); | 252 | pr = GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ); |
254 | child_death_task_id = NULL; | 253 | child_death_task_id = NULL; |
255 | /* consume the signal */ | 254 | /* consume the signal */ |
256 | GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c))); | 255 | GNUNET_break(0 < GNUNET_DISK_file_read(pr, &c, sizeof(c))); |
257 | LOG_DEBUG ("Got SIGCHLD\n"); | 256 | LOG_DEBUG("Got SIGCHLD\n"); |
258 | if (NULL == testbed) | 257 | if (NULL == testbed) |
259 | { | 258 | { |
260 | GNUNET_break (0); | 259 | GNUNET_break(0); |
261 | return; | 260 | return; |
262 | } | 261 | } |
263 | GNUNET_break (GNUNET_SYSERR != | 262 | GNUNET_break(GNUNET_SYSERR != |
264 | (ret = GNUNET_OS_process_status (testbed, &type, &code))); | 263 | (ret = GNUNET_OS_process_status(testbed, &type, &code))); |
265 | if (GNUNET_NO != ret) | 264 | if (GNUNET_NO != ret) |
266 | { | ||
267 | GNUNET_OS_process_destroy (testbed); | ||
268 | testbed = NULL; | ||
269 | /* Send SIGTERM to our process group */ | ||
270 | if (0 != kill (0, GNUNET_TERM_SIG)) | ||
271 | { | 265 | { |
272 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "signal"); | 266 | GNUNET_OS_process_destroy(testbed); |
273 | GNUNET_SCHEDULER_shutdown (); /* Couldn't send the signal, we shutdown frowning */ | 267 | testbed = NULL; |
268 | /* Send SIGTERM to our process group */ | ||
269 | if (0 != kill(0, GNUNET_TERM_SIG)) | ||
270 | { | ||
271 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "signal"); | ||
272 | GNUNET_SCHEDULER_shutdown(); /* Couldn't send the signal, we shutdown frowning */ | ||
273 | } | ||
274 | return; | ||
274 | } | 275 | } |
275 | return; | 276 | LOG_DEBUG("Child hasn't died. Resuming to monitor its status\n"); |
276 | } | ||
277 | LOG_DEBUG ("Child hasn't died. Resuming to monitor its status\n"); | ||
278 | child_death_task_id = | 277 | child_death_task_id = |
279 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 278 | GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, |
280 | pr, | 279 | pr, |
281 | &child_death_task, | 280 | &child_death_task, |
282 | NULL); | 281 | NULL); |
283 | } | 282 | } |
284 | 283 | ||
285 | 284 | ||
@@ -296,7 +295,7 @@ child_death_task (void *cls) | |||
296 | * #GNUNET_SYSERR to stop further processing with error | 295 | * #GNUNET_SYSERR to stop further processing with error |
297 | */ | 296 | */ |
298 | static int | 297 | static int |
299 | tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) | 298 | tokenizer_cb(void *cls, const struct GNUNET_MessageHeader *message) |
300 | { | 299 | { |
301 | const struct GNUNET_TESTBED_HelperInit *msg; | 300 | const struct GNUNET_TESTBED_HelperInit *msg; |
302 | struct GNUNET_TESTBED_HelperReply *reply; | 301 | struct GNUNET_TESTBED_HelperReply *reply; |
@@ -316,182 +315,185 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) | |||
316 | uint16_t hostname_size; | 315 | uint16_t hostname_size; |
317 | uint16_t msize; | 316 | uint16_t msize; |
318 | 317 | ||
319 | msize = ntohs (message->size); | 318 | msize = ntohs(message->size); |
320 | if ((sizeof (struct GNUNET_TESTBED_HelperInit) >= msize) || | 319 | if ((sizeof(struct GNUNET_TESTBED_HelperInit) >= msize) || |
321 | (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT != ntohs (message->type))) | 320 | (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT != ntohs(message->type))) |
322 | { | 321 | { |
323 | LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); | 322 | LOG(GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); |
324 | goto error; | 323 | goto error; |
325 | } | 324 | } |
326 | msg = (const struct GNUNET_TESTBED_HelperInit *) message; | 325 | msg = (const struct GNUNET_TESTBED_HelperInit *)message; |
327 | trusted_ip_size = ntohs (msg->trusted_ip_size); | 326 | trusted_ip_size = ntohs(msg->trusted_ip_size); |
328 | trusted_ip = (char *) &msg[1]; | 327 | trusted_ip = (char *)&msg[1]; |
329 | if ('\0' != trusted_ip[trusted_ip_size]) | 328 | if ('\0' != trusted_ip[trusted_ip_size]) |
330 | { | 329 | { |
331 | LOG (GNUNET_ERROR_TYPE_WARNING, "Trusted IP cannot be empty -- exiting\n"); | 330 | LOG(GNUNET_ERROR_TYPE_WARNING, "Trusted IP cannot be empty -- exiting\n"); |
332 | goto error; | 331 | goto error; |
333 | } | 332 | } |
334 | hostname_size = ntohs (msg->hostname_size); | 333 | hostname_size = ntohs(msg->hostname_size); |
335 | if ((sizeof (struct GNUNET_TESTBED_HelperInit) + trusted_ip_size + 1 + | 334 | if ((sizeof(struct GNUNET_TESTBED_HelperInit) + trusted_ip_size + 1 + |
336 | hostname_size) >= msize) | 335 | hostname_size) >= msize) |
337 | { | 336 | { |
338 | GNUNET_break (0); | 337 | GNUNET_break(0); |
339 | LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); | 338 | LOG(GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); |
340 | goto error; | 339 | goto error; |
341 | } | 340 | } |
342 | ul_config_size = (uLongf) ntohs (msg->config_size); | 341 | ul_config_size = (uLongf)ntohs(msg->config_size); |
343 | config = GNUNET_malloc (ul_config_size); | 342 | config = GNUNET_malloc(ul_config_size); |
344 | xconfig_size = msize - (trusted_ip_size + 1 + hostname_size + | 343 | xconfig_size = msize - (trusted_ip_size + 1 + hostname_size + |
345 | sizeof (struct GNUNET_TESTBED_HelperInit)); | 344 | sizeof(struct GNUNET_TESTBED_HelperInit)); |
346 | int ret = uncompress ((Bytef *) config, | 345 | int ret = uncompress((Bytef *)config, |
347 | &ul_config_size, | 346 | &ul_config_size, |
348 | (const Bytef *) (trusted_ip + trusted_ip_size + 1 + | 347 | (const Bytef *)(trusted_ip + trusted_ip_size + 1 + |
349 | hostname_size), | 348 | hostname_size), |
350 | (uLongf) xconfig_size); | 349 | (uLongf)xconfig_size); |
351 | if (Z_OK != ret) | 350 | if (Z_OK != ret) |
352 | { | ||
353 | switch (ret) | ||
354 | { | 351 | { |
355 | case Z_MEM_ERROR: | 352 | switch (ret) |
356 | LOG (GNUNET_ERROR_TYPE_ERROR, "Not enough memory for decompression\n"); | 353 | { |
357 | break; | 354 | case Z_MEM_ERROR: |
358 | case Z_BUF_ERROR: | 355 | LOG(GNUNET_ERROR_TYPE_ERROR, "Not enough memory for decompression\n"); |
359 | LOG (GNUNET_ERROR_TYPE_ERROR, "Output buffer too small\n"); | 356 | break; |
360 | break; | 357 | |
361 | case Z_DATA_ERROR: | 358 | case Z_BUF_ERROR: |
362 | LOG (GNUNET_ERROR_TYPE_ERROR, "Data corrupted/incomplete\n"); | 359 | LOG(GNUNET_ERROR_TYPE_ERROR, "Output buffer too small\n"); |
363 | break; | 360 | break; |
364 | default: | 361 | |
365 | GNUNET_break (0); | 362 | case Z_DATA_ERROR: |
363 | LOG(GNUNET_ERROR_TYPE_ERROR, "Data corrupted/incomplete\n"); | ||
364 | break; | ||
365 | |||
366 | default: | ||
367 | GNUNET_break(0); | ||
368 | } | ||
369 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
370 | "Error while uncompressing config -- exiting\n"); | ||
371 | GNUNET_free(config); | ||
372 | goto error; | ||
366 | } | 373 | } |
367 | LOG (GNUNET_ERROR_TYPE_ERROR, | 374 | cfg = GNUNET_CONFIGURATION_create(); |
368 | "Error while uncompressing config -- exiting\n"); | ||
369 | GNUNET_free (config); | ||
370 | goto error; | ||
371 | } | ||
372 | cfg = GNUNET_CONFIGURATION_create (); | ||
373 | if (GNUNET_OK != | 375 | if (GNUNET_OK != |
374 | GNUNET_CONFIGURATION_deserialize (cfg, config, ul_config_size, NULL)) | 376 | GNUNET_CONFIGURATION_deserialize(cfg, config, ul_config_size, NULL)) |
375 | { | 377 | { |
376 | LOG (GNUNET_ERROR_TYPE_ERROR, "Unable to deserialize config -- exiting\n"); | 378 | LOG(GNUNET_ERROR_TYPE_ERROR, "Unable to deserialize config -- exiting\n"); |
377 | GNUNET_free (config); | 379 | GNUNET_free(config); |
378 | goto error; | 380 | goto error; |
379 | } | 381 | } |
380 | GNUNET_free (config); | 382 | GNUNET_free(config); |
381 | hostname = NULL; | 383 | hostname = NULL; |
382 | if (0 != hostname_size) | 384 | if (0 != hostname_size) |
383 | { | 385 | { |
384 | hostname = GNUNET_malloc (hostname_size + 1); | 386 | hostname = GNUNET_malloc(hostname_size + 1); |
385 | GNUNET_strlcpy (hostname, | 387 | GNUNET_strlcpy(hostname, |
386 | ((char *) &msg[1]) + trusted_ip_size + 1, | 388 | ((char *)&msg[1]) + trusted_ip_size + 1, |
387 | hostname_size + 1); | 389 | hostname_size + 1); |
388 | } | 390 | } |
389 | /* unset GNUNET_TESTING_PREFIX if present as it is more relevant for testbed */ | 391 | /* unset GNUNET_TESTING_PREFIX if present as it is more relevant for testbed */ |
390 | evstr = getenv (GNUNET_TESTING_PREFIX); | 392 | evstr = getenv(GNUNET_TESTING_PREFIX); |
391 | if (NULL != evstr) | 393 | if (NULL != evstr) |
392 | { | 394 | { |
393 | /* unsetting the variable will invalidate the pointer! */ | 395 | /* unsetting the variable will invalidate the pointer! */ |
394 | evstr = GNUNET_strdup (evstr); | 396 | evstr = GNUNET_strdup(evstr); |
395 | #ifdef WINDOWS | 397 | #ifdef WINDOWS |
396 | GNUNET_break (0 != SetEnvironmentVariable (GNUNET_TESTING_PREFIX, NULL)); | 398 | GNUNET_break(0 != SetEnvironmentVariable(GNUNET_TESTING_PREFIX, NULL)); |
397 | #else | 399 | #else |
398 | GNUNET_break (0 == unsetenv (GNUNET_TESTING_PREFIX)); | 400 | GNUNET_break(0 == unsetenv(GNUNET_TESTING_PREFIX)); |
399 | #endif | 401 | #endif |
400 | } | 402 | } |
401 | test_system = | 403 | test_system = |
402 | GNUNET_TESTING_system_create ("testbed-helper", trusted_ip, hostname, NULL); | 404 | GNUNET_TESTING_system_create("testbed-helper", trusted_ip, hostname, NULL); |
403 | if (NULL != evstr) | 405 | if (NULL != evstr) |
404 | { | 406 | { |
405 | #ifdef WINDOWS | 407 | #ifdef WINDOWS |
406 | GNUNET_assert (0 != SetEnvironmentVariable (GNUNET_TESTING_PREFIX, evstr)); | 408 | GNUNET_assert(0 != SetEnvironmentVariable(GNUNET_TESTING_PREFIX, evstr)); |
407 | #else | 409 | #else |
408 | char *evar; | 410 | char *evar; |
409 | 411 | ||
410 | GNUNET_asprintf (&evar, GNUNET_TESTING_PREFIX "=%s", evstr); | 412 | GNUNET_asprintf(&evar, GNUNET_TESTING_PREFIX "=%s", evstr); |
411 | GNUNET_assert (0 == putenv (evar)); /* consumes 'evar', | 413 | GNUNET_assert(0 == putenv(evar)); /* consumes 'evar', |
412 | see putenv(): becomes part of envrionment! */ | 414 | see putenv(): becomes part of envrionment! */ |
413 | #endif | 415 | #endif |
414 | GNUNET_free (evstr); | 416 | GNUNET_free(evstr); |
415 | evstr = NULL; | 417 | evstr = NULL; |
416 | } | 418 | } |
417 | GNUNET_free_non_null (hostname); | 419 | GNUNET_free_non_null(hostname); |
418 | hostname = NULL; | 420 | hostname = NULL; |
419 | GNUNET_assert (NULL != test_system); | 421 | GNUNET_assert(NULL != test_system); |
420 | GNUNET_assert (GNUNET_OK == | 422 | GNUNET_assert(GNUNET_OK == |
421 | GNUNET_TESTING_configuration_create (test_system, cfg)); | 423 | GNUNET_TESTING_configuration_create(test_system, cfg)); |
422 | GNUNET_assert (GNUNET_OK == | 424 | GNUNET_assert(GNUNET_OK == |
423 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 425 | GNUNET_CONFIGURATION_get_value_filename(cfg, |
424 | "PATHS", | 426 | "PATHS", |
425 | "DEFAULTCONFIG", | 427 | "DEFAULTCONFIG", |
426 | &config)); | 428 | &config)); |
427 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config)) | 429 | if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg, config)) |
428 | { | 430 | { |
429 | LOG (GNUNET_ERROR_TYPE_WARNING, | 431 | LOG(GNUNET_ERROR_TYPE_WARNING, |
430 | "Unable to write config file: %s -- exiting\n", | 432 | "Unable to write config file: %s -- exiting\n", |
431 | config); | 433 | config); |
432 | GNUNET_CONFIGURATION_destroy (cfg); | 434 | GNUNET_CONFIGURATION_destroy(cfg); |
433 | GNUNET_free (config); | 435 | GNUNET_free(config); |
434 | goto error; | 436 | goto error; |
435 | } | 437 | } |
436 | LOG_DEBUG ("Staring testbed with config: %s\n", config); | 438 | LOG_DEBUG("Staring testbed with config: %s\n", config); |
437 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-testbed"); | 439 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-testbed"); |
438 | { | 440 | { |
439 | char *evar; | 441 | char *evar; |
440 | 442 | ||
441 | /* expose testbed configuration through env variable */ | 443 | /* expose testbed configuration through env variable */ |
442 | GNUNET_asprintf (&evar, "%s=%s", ENV_TESTBED_CONFIG, config); | 444 | GNUNET_asprintf(&evar, "%s=%s", ENV_TESTBED_CONFIG, config); |
443 | GNUNET_assert (0 == putenv (evar)); /* consumes 'evar', | 445 | GNUNET_assert(0 == putenv(evar)); /* consumes 'evar', |
444 | see putenv(): becomes part of envrionment! */ | 446 | see putenv(): becomes part of envrionment! */ |
445 | evstr = NULL; | 447 | evstr = NULL; |
446 | } | 448 | } |
447 | testbed = GNUNET_OS_start_process (PIPE_CONTROL, | 449 | testbed = GNUNET_OS_start_process(PIPE_CONTROL, |
448 | GNUNET_OS_INHERIT_STD_ERR /*verbose? */, | 450 | GNUNET_OS_INHERIT_STD_ERR /*verbose? */, |
449 | NULL, | 451 | NULL, |
450 | NULL, | 452 | NULL, |
451 | NULL, | 453 | NULL, |
452 | binary, | 454 | binary, |
453 | "gnunet-service-testbed", | 455 | "gnunet-service-testbed", |
454 | "-c", | 456 | "-c", |
455 | config, | 457 | config, |
456 | NULL); | 458 | NULL); |
457 | GNUNET_free (binary); | 459 | GNUNET_free(binary); |
458 | GNUNET_free (config); | 460 | GNUNET_free(config); |
459 | if (NULL == testbed) | 461 | if (NULL == testbed) |
460 | { | 462 | { |
461 | LOG (GNUNET_ERROR_TYPE_WARNING, | 463 | LOG(GNUNET_ERROR_TYPE_WARNING, |
462 | "Error starting gnunet-service-testbed -- exiting\n"); | 464 | "Error starting gnunet-service-testbed -- exiting\n"); |
463 | GNUNET_CONFIGURATION_destroy (cfg); | 465 | GNUNET_CONFIGURATION_destroy(cfg); |
464 | goto error; | 466 | goto error; |
465 | } | 467 | } |
466 | done_reading = GNUNET_YES; | 468 | done_reading = GNUNET_YES; |
467 | config = GNUNET_CONFIGURATION_serialize (cfg, &config_size); | 469 | config = GNUNET_CONFIGURATION_serialize(cfg, &config_size); |
468 | GNUNET_CONFIGURATION_destroy (cfg); | 470 | GNUNET_CONFIGURATION_destroy(cfg); |
469 | cfg = NULL; | 471 | cfg = NULL; |
470 | xconfig_size = | 472 | xconfig_size = |
471 | GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig); | 473 | GNUNET_TESTBED_compress_config_(config, config_size, &xconfig); |
472 | GNUNET_free (config); | 474 | GNUNET_free(config); |
473 | wc = GNUNET_new (struct WriteContext); | 475 | wc = GNUNET_new(struct WriteContext); |
474 | wc->length = xconfig_size + sizeof (struct GNUNET_TESTBED_HelperReply); | 476 | wc->length = xconfig_size + sizeof(struct GNUNET_TESTBED_HelperReply); |
475 | reply = GNUNET_realloc (xconfig, wc->length); | 477 | reply = GNUNET_realloc(xconfig, wc->length); |
476 | memmove (&reply[1], reply, xconfig_size); | 478 | memmove(&reply[1], reply, xconfig_size); |
477 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY); | 479 | reply->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY); |
478 | reply->header.size = htons ((uint16_t) wc->length); | 480 | reply->header.size = htons((uint16_t)wc->length); |
479 | reply->config_size = htons ((uint16_t) config_size); | 481 | reply->config_size = htons((uint16_t)config_size); |
480 | wc->data = reply; | 482 | wc->data = reply; |
481 | write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, | 483 | write_task_id = GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL, |
482 | stdout_fd, | 484 | stdout_fd, |
483 | &write_task, | 485 | &write_task, |
484 | wc); | 486 | wc); |
485 | child_death_task_id = GNUNET_SCHEDULER_add_read_file ( | 487 | child_death_task_id = GNUNET_SCHEDULER_add_read_file( |
486 | GNUNET_TIME_UNIT_FOREVER_REL, | 488 | GNUNET_TIME_UNIT_FOREVER_REL, |
487 | GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), | 489 | GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ), |
488 | &child_death_task, | 490 | &child_death_task, |
489 | NULL); | 491 | NULL); |
490 | return GNUNET_OK; | 492 | return GNUNET_OK; |
491 | 493 | ||
492 | error: | 494 | error: |
493 | status = GNUNET_SYSERR; | 495 | status = GNUNET_SYSERR; |
494 | GNUNET_SCHEDULER_shutdown (); | 496 | GNUNET_SCHEDULER_shutdown(); |
495 | return GNUNET_SYSERR; | 497 | return GNUNET_SYSERR; |
496 | } | 498 | } |
497 | 499 | ||
@@ -502,41 +504,41 @@ error: | |||
502 | * @param cls NULL | 504 | * @param cls NULL |
503 | */ | 505 | */ |
504 | static void | 506 | static void |
505 | read_task (void *cls) | 507 | read_task(void *cls) |
506 | { | 508 | { |
507 | char buf[GNUNET_MAX_MESSAGE_SIZE]; | 509 | char buf[GNUNET_MAX_MESSAGE_SIZE]; |
508 | ssize_t sread; | 510 | ssize_t sread; |
509 | 511 | ||
510 | read_task_id = NULL; | 512 | read_task_id = NULL; |
511 | sread = GNUNET_DISK_file_read (stdin_fd, buf, sizeof (buf)); | 513 | sread = GNUNET_DISK_file_read(stdin_fd, buf, sizeof(buf)); |
512 | if ((GNUNET_SYSERR == sread) || (0 == sread)) | 514 | if ((GNUNET_SYSERR == sread) || (0 == sread)) |
513 | { | 515 | { |
514 | LOG_DEBUG ("STDIN closed\n"); | 516 | LOG_DEBUG("STDIN closed\n"); |
515 | GNUNET_SCHEDULER_shutdown (); | 517 | GNUNET_SCHEDULER_shutdown(); |
516 | return; | 518 | return; |
517 | } | 519 | } |
518 | if (GNUNET_YES == done_reading) | 520 | if (GNUNET_YES == done_reading) |
519 | { | 521 | { |
520 | /* didn't expect any more data! */ | 522 | /* didn't expect any more data! */ |
521 | GNUNET_break_op (0); | 523 | GNUNET_break_op(0); |
522 | GNUNET_SCHEDULER_shutdown (); | 524 | GNUNET_SCHEDULER_shutdown(); |
523 | return; | 525 | return; |
524 | } | 526 | } |
525 | LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread); | 527 | LOG_DEBUG("Read %u bytes\n", (unsigned int)sread); |
526 | /* FIXME: could introduce a GNUNET_MST_read2 to read | 528 | /* FIXME: could introduce a GNUNET_MST_read2 to read |
527 | directly from 'stdin_fd' and save a memcpy() here */ | 529 | directly from 'stdin_fd' and save a memcpy() here */ |
528 | if (GNUNET_OK != | 530 | if (GNUNET_OK != |
529 | GNUNET_MST_from_buffer (tokenizer, buf, sread, GNUNET_NO, GNUNET_NO)) | 531 | GNUNET_MST_from_buffer(tokenizer, buf, sread, GNUNET_NO, GNUNET_NO)) |
530 | { | 532 | { |
531 | GNUNET_break (0); | 533 | GNUNET_break(0); |
532 | GNUNET_SCHEDULER_shutdown (); | 534 | GNUNET_SCHEDULER_shutdown(); |
533 | return; | 535 | return; |
534 | } | 536 | } |
535 | read_task_id /* No timeout while reading */ | 537 | read_task_id /* No timeout while reading */ |
536 | = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 538 | = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, |
537 | stdin_fd, | 539 | stdin_fd, |
538 | &read_task, | 540 | &read_task, |
539 | NULL); | 541 | NULL); |
540 | } | 542 | } |
541 | 543 | ||
542 | 544 | ||
@@ -549,20 +551,20 @@ read_task (void *cls) | |||
549 | * @param cfg configuration | 551 | * @param cfg configuration |
550 | */ | 552 | */ |
551 | static void | 553 | static void |
552 | run (void *cls, | 554 | run(void *cls, |
553 | char *const *args, | 555 | char *const *args, |
554 | const char *cfgfile, | 556 | const char *cfgfile, |
555 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 557 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
556 | { | 558 | { |
557 | LOG_DEBUG ("Starting testbed helper...\n"); | 559 | LOG_DEBUG("Starting testbed helper...\n"); |
558 | tokenizer = GNUNET_MST_create (&tokenizer_cb, NULL); | 560 | tokenizer = GNUNET_MST_create(&tokenizer_cb, NULL); |
559 | stdin_fd = GNUNET_DISK_get_handle_from_native (stdin); | 561 | stdin_fd = GNUNET_DISK_get_handle_from_native(stdin); |
560 | stdout_fd = GNUNET_DISK_get_handle_from_native (stdout); | 562 | stdout_fd = GNUNET_DISK_get_handle_from_native(stdout); |
561 | read_task_id = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 563 | read_task_id = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, |
562 | stdin_fd, | 564 | stdin_fd, |
563 | &read_task, | 565 | &read_task, |
564 | NULL); | 566 | NULL); |
565 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 567 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
566 | } | 568 | } |
567 | 569 | ||
568 | 570 | ||
@@ -570,18 +572,18 @@ run (void *cls, | |||
570 | * Signal handler called for SIGCHLD. | 572 | * Signal handler called for SIGCHLD. |
571 | */ | 573 | */ |
572 | static void | 574 | static void |
573 | sighandler_child_death () | 575 | sighandler_child_death() |
574 | { | 576 | { |
575 | static char c; | 577 | static char c; |
576 | int old_errno; /* back-up errno */ | 578 | int old_errno; /* back-up errno */ |
577 | 579 | ||
578 | old_errno = errno; | 580 | old_errno = errno; |
579 | GNUNET_break ( | 581 | GNUNET_break( |
580 | 1 == | 582 | 1 == |
581 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe, | 583 | GNUNET_DISK_file_write(GNUNET_DISK_pipe_handle(sigpipe, |
582 | GNUNET_DISK_PIPE_END_WRITE), | 584 | GNUNET_DISK_PIPE_END_WRITE), |
583 | &c, | 585 | &c, |
584 | sizeof (c))); | 586 | sizeof(c))); |
585 | errno = old_errno; | 587 | errno = old_errno; |
586 | } | 588 | } |
587 | 589 | ||
@@ -594,31 +596,31 @@ sighandler_child_death () | |||
594 | * @return return code | 596 | * @return return code |
595 | */ | 597 | */ |
596 | int | 598 | int |
597 | main (int argc, char **argv) | 599 | main(int argc, char **argv) |
598 | { | 600 | { |
599 | struct GNUNET_SIGNAL_Context *shc_chld; | 601 | struct GNUNET_SIGNAL_Context *shc_chld; |
600 | struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END}; | 602 | struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; |
601 | int ret; | 603 | int ret; |
602 | 604 | ||
603 | status = GNUNET_OK; | 605 | status = GNUNET_OK; |
604 | if (NULL == | 606 | if (NULL == |
605 | (sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO))) | 607 | (sigpipe = GNUNET_DISK_pipe(GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO))) |
606 | { | 608 | { |
607 | GNUNET_break (0); | 609 | GNUNET_break(0); |
608 | return 1; | 610 | return 1; |
609 | } | 611 | } |
610 | shc_chld = | 612 | shc_chld = |
611 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); | 613 | GNUNET_SIGNAL_handler_install(GNUNET_SIGCHLD, &sighandler_child_death); |
612 | ret = GNUNET_PROGRAM_run (argc, | 614 | ret = GNUNET_PROGRAM_run(argc, |
613 | argv, | 615 | argv, |
614 | "gnunet-helper-testbed", | 616 | "gnunet-helper-testbed", |
615 | "Helper for starting gnunet-service-testbed", | 617 | "Helper for starting gnunet-service-testbed", |
616 | options, | 618 | options, |
617 | &run, | 619 | &run, |
618 | NULL); | 620 | NULL); |
619 | GNUNET_SIGNAL_handler_uninstall (shc_chld); | 621 | GNUNET_SIGNAL_handler_uninstall(shc_chld); |
620 | shc_chld = NULL; | 622 | shc_chld = NULL; |
621 | GNUNET_DISK_pipe_close (sigpipe); | 623 | GNUNET_DISK_pipe_close(sigpipe); |
622 | if (GNUNET_OK != ret) | 624 | if (GNUNET_OK != ret) |
623 | return 1; | 625 | return 1; |
624 | return (GNUNET_OK == status) ? 0 : 1; | 626 | return (GNUNET_OK == status) ? 0 : 1; |
diff --git a/src/testbed/gnunet-service-test-barriers.c b/src/testbed/gnunet-service-test-barriers.c index 948daa633..5902a1576 100644 --- a/src/testbed/gnunet-service-test-barriers.c +++ b/src/testbed/gnunet-service-test-barriers.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -33,8 +33,8 @@ | |||
33 | /** | 33 | /** |
34 | * logging short hand | 34 | * logging short hand |
35 | */ | 35 | */ |
36 | #define LOG(type,...) \ | 36 | #define LOG(type, ...) \ |
37 | GNUNET_log (type, __VA_ARGS__); | 37 | GNUNET_log(type, __VA_ARGS__); |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * Our barrier wait handle | 40 | * Our barrier wait handle |
@@ -50,18 +50,18 @@ static struct GNUNET_SCHEDULER_Task *tt; | |||
50 | * @param cls NULL | 50 | * @param cls NULL |
51 | */ | 51 | */ |
52 | static void | 52 | static void |
53 | do_shutdown (void *cls) | 53 | do_shutdown(void *cls) |
54 | { | 54 | { |
55 | if (NULL != wh) | 55 | if (NULL != wh) |
56 | { | 56 | { |
57 | GNUNET_TESTBED_barrier_wait_cancel (wh); | 57 | GNUNET_TESTBED_barrier_wait_cancel(wh); |
58 | wh = NULL; | 58 | wh = NULL; |
59 | } | 59 | } |
60 | if (NULL != tt) | 60 | if (NULL != tt) |
61 | { | 61 | { |
62 | GNUNET_SCHEDULER_cancel (tt); | 62 | GNUNET_SCHEDULER_cancel(tt); |
63 | tt = NULL; | 63 | tt = NULL; |
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
67 | 67 | ||
@@ -76,13 +76,13 @@ do_shutdown (void *cls) | |||
76 | * #GNUNET_OK if the barrier is crossed | 76 | * #GNUNET_OK if the barrier is crossed |
77 | */ | 77 | */ |
78 | static void | 78 | static void |
79 | barrier_wait_cb (void *cls, | 79 | barrier_wait_cb(void *cls, |
80 | const char *name, | 80 | const char *name, |
81 | int status) | 81 | int status) |
82 | { | 82 | { |
83 | GNUNET_break (NULL == cls); | 83 | GNUNET_break(NULL == cls); |
84 | wh = NULL; | 84 | wh = NULL; |
85 | GNUNET_break (GNUNET_OK == status); | 85 | GNUNET_break(GNUNET_OK == status); |
86 | } | 86 | } |
87 | 87 | ||
88 | 88 | ||
@@ -93,13 +93,13 @@ barrier_wait_cb (void *cls, | |||
93 | * @return | 93 | * @return |
94 | */ | 94 | */ |
95 | static void | 95 | static void |
96 | do_wait (void *cls) | 96 | do_wait(void *cls) |
97 | { | 97 | { |
98 | tt = NULL; | 98 | tt = NULL; |
99 | wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME, | 99 | wh = GNUNET_TESTBED_barrier_wait(TEST_BARRIER_NAME, |
100 | &barrier_wait_cb, | 100 | &barrier_wait_cb, |
101 | NULL); | 101 | NULL); |
102 | GNUNET_break (NULL != wh); | 102 | GNUNET_break(NULL != wh); |
103 | } | 103 | } |
104 | 104 | ||
105 | 105 | ||
@@ -112,20 +112,20 @@ do_wait (void *cls) | |||
112 | * @param config the configuration file handle | 112 | * @param config the configuration file handle |
113 | */ | 113 | */ |
114 | static void | 114 | static void |
115 | run (void *cls, | 115 | run(void *cls, |
116 | char *const *args, | 116 | char *const *args, |
117 | const char *cfgfile, | 117 | const char *cfgfile, |
118 | const struct GNUNET_CONFIGURATION_Handle *config) | 118 | const struct GNUNET_CONFIGURATION_Handle *config) |
119 | { | 119 | { |
120 | unsigned int rsec; | 120 | unsigned int rsec; |
121 | 121 | ||
122 | rsec = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 122 | rsec = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, |
123 | 10); | 123 | 10); |
124 | tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 124 | tt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
125 | rsec), | 125 | rsec), |
126 | &do_wait, | 126 | &do_wait, |
127 | NULL); | 127 | NULL); |
128 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 128 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
129 | } | 129 | } |
130 | 130 | ||
131 | 131 | ||
@@ -134,7 +134,7 @@ run (void *cls, | |||
134 | * Main | 134 | * Main |
135 | */ | 135 | */ |
136 | int | 136 | int |
137 | main (int argc, char **argv) | 137 | main(int argc, char **argv) |
138 | { | 138 | { |
139 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 139 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
140 | GNUNET_GETOPT_OPTION_END | 140 | GNUNET_GETOPT_OPTION_END |
@@ -142,11 +142,11 @@ main (int argc, char **argv) | |||
142 | int ret; | 142 | int ret; |
143 | 143 | ||
144 | ret = | 144 | ret = |
145 | GNUNET_PROGRAM_run (argc, argv, | 145 | GNUNET_PROGRAM_run(argc, argv, |
146 | "test-barriers", | 146 | "test-barriers", |
147 | "nohelp", | 147 | "nohelp", |
148 | options, | 148 | options, |
149 | &run, | 149 | &run, |
150 | NULL); | 150 | NULL); |
151 | return ret; | 151 | return ret; |
152 | } | 152 | } |
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 8babeeb13..26f1a9c26 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2013, 2016 GNUnet e.V. | 3 | Copyright (C) 2008--2013, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/gnunet-service-testbed.c | 22 | * @file testbed/gnunet-service-testbed.c |
@@ -96,18 +96,18 @@ static char *hostname; | |||
96 | * already in use | 96 | * already in use |
97 | */ | 97 | */ |
98 | static int | 98 | static int |
99 | host_list_add (struct GNUNET_TESTBED_Host *host) | 99 | host_list_add(struct GNUNET_TESTBED_Host *host) |
100 | { | 100 | { |
101 | uint32_t host_id; | 101 | uint32_t host_id; |
102 | 102 | ||
103 | host_id = GNUNET_TESTBED_host_get_id_ (host); | 103 | host_id = GNUNET_TESTBED_host_get_id_(host); |
104 | if (GST_host_list_size <= host_id) | 104 | if (GST_host_list_size <= host_id) |
105 | GST_array_grow_large_enough (GST_host_list, GST_host_list_size, host_id); | 105 | GST_array_grow_large_enough(GST_host_list, GST_host_list_size, host_id); |
106 | if (NULL != GST_host_list[host_id]) | 106 | if (NULL != GST_host_list[host_id]) |
107 | { | 107 | { |
108 | LOG_DEBUG ("A host with id: %u already exists\n", host_id); | 108 | LOG_DEBUG("A host with id: %u already exists\n", host_id); |
109 | return GNUNET_SYSERR; | 109 | return GNUNET_SYSERR; |
110 | } | 110 | } |
111 | GST_host_list[host_id] = host; | 111 | GST_host_list[host_id] = host; |
112 | return GNUNET_OK; | 112 | return GNUNET_OK; |
113 | } | 113 | } |
@@ -121,25 +121,25 @@ host_list_add (struct GNUNET_TESTBED_Host *host) | |||
121 | * @param emsg the error message; can be NULL | 121 | * @param emsg the error message; can be NULL |
122 | */ | 122 | */ |
123 | void | 123 | void |
124 | GST_send_operation_fail_msg (struct GNUNET_SERVICE_Client *client, | 124 | GST_send_operation_fail_msg(struct GNUNET_SERVICE_Client *client, |
125 | uint64_t operation_id, | 125 | uint64_t operation_id, |
126 | const char *emsg) | 126 | const char *emsg) |
127 | { | 127 | { |
128 | struct GNUNET_MQ_Envelope *env; | 128 | struct GNUNET_MQ_Envelope *env; |
129 | struct GNUNET_TESTBED_OperationFailureEventMessage *msg; | 129 | struct GNUNET_TESTBED_OperationFailureEventMessage *msg; |
130 | uint16_t emsg_len; | 130 | uint16_t emsg_len; |
131 | 131 | ||
132 | emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1; | 132 | emsg_len = (NULL == emsg) ? 0 : strlen(emsg) + 1; |
133 | env = GNUNET_MQ_msg_extra (msg, | 133 | env = GNUNET_MQ_msg_extra(msg, |
134 | emsg_len, | 134 | emsg_len, |
135 | GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT); | 135 | GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT); |
136 | msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED); | 136 | msg->event_type = htonl(GNUNET_TESTBED_ET_OPERATION_FINISHED); |
137 | msg->operation_id = GNUNET_htonll (operation_id); | 137 | msg->operation_id = GNUNET_htonll(operation_id); |
138 | GNUNET_memcpy (&msg[1], | 138 | GNUNET_memcpy(&msg[1], |
139 | emsg, | 139 | emsg, |
140 | emsg_len); | 140 | emsg_len); |
141 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 141 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), |
142 | env); | 142 | env); |
143 | } | 143 | } |
144 | 144 | ||
145 | 145 | ||
@@ -150,18 +150,18 @@ GST_send_operation_fail_msg (struct GNUNET_SERVICE_Client *client, | |||
150 | * @param operation_id the id of the operation which was successful | 150 | * @param operation_id the id of the operation which was successful |
151 | */ | 151 | */ |
152 | void | 152 | void |
153 | GST_send_operation_success_msg (struct GNUNET_SERVICE_Client *client, | 153 | GST_send_operation_success_msg(struct GNUNET_SERVICE_Client *client, |
154 | uint64_t operation_id) | 154 | uint64_t operation_id) |
155 | { | 155 | { |
156 | struct GNUNET_MQ_Envelope *env; | 156 | struct GNUNET_MQ_Envelope *env; |
157 | struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg; | 157 | struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg; |
158 | 158 | ||
159 | env = GNUNET_MQ_msg (msg, | 159 | env = GNUNET_MQ_msg(msg, |
160 | GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS); | 160 | GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS); |
161 | msg->operation_id = GNUNET_htonll (operation_id); | 161 | msg->operation_id = GNUNET_htonll(operation_id); |
162 | msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED); | 162 | msg->event_type = htonl(GNUNET_TESTBED_ET_OPERATION_FINISHED); |
163 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 163 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), |
164 | env); | 164 | env); |
165 | } | 165 | } |
166 | 166 | ||
167 | 167 | ||
@@ -172,8 +172,8 @@ GST_send_operation_success_msg (struct GNUNET_SERVICE_Client *client, | |||
172 | * @param emsg the error message; NULL if host registration is successful | 172 | * @param emsg the error message; NULL if host registration is successful |
173 | */ | 173 | */ |
174 | static void | 174 | static void |
175 | hr_completion (void *cls, | 175 | hr_completion(void *cls, |
176 | const char *emsg); | 176 | const char *emsg); |
177 | 177 | ||
178 | 178 | ||
179 | /** | 179 | /** |
@@ -183,21 +183,21 @@ hr_completion (void *cls, | |||
183 | * for host registrations | 183 | * for host registrations |
184 | */ | 184 | */ |
185 | static void | 185 | static void |
186 | register_next_host (struct Slave *slave) | 186 | register_next_host(struct Slave *slave) |
187 | { | 187 | { |
188 | struct HostRegistration *hr; | 188 | struct HostRegistration *hr; |
189 | 189 | ||
190 | hr = slave->hr_dll_head; | 190 | hr = slave->hr_dll_head; |
191 | GNUNET_assert (NULL != hr); | 191 | GNUNET_assert(NULL != hr); |
192 | GNUNET_assert (NULL == slave->rhandle); | 192 | GNUNET_assert(NULL == slave->rhandle); |
193 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Registering host %u at %u\n", | 193 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Registering host %u at %u\n", |
194 | GNUNET_TESTBED_host_get_id_ (hr->host), | 194 | GNUNET_TESTBED_host_get_id_(hr->host), |
195 | GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id])); | 195 | GNUNET_TESTBED_host_get_id_(GST_host_list[slave->host_id])); |
196 | slave->rhandle | 196 | slave->rhandle |
197 | = GNUNET_TESTBED_register_host (slave->controller, | 197 | = GNUNET_TESTBED_register_host(slave->controller, |
198 | hr->host, | 198 | hr->host, |
199 | hr_completion, | 199 | hr_completion, |
200 | slave); | 200 | slave); |
201 | } | 201 | } |
202 | 202 | ||
203 | 203 | ||
@@ -208,28 +208,28 @@ register_next_host (struct Slave *slave) | |||
208 | * @param emsg the error message; NULL if host registration is successful | 208 | * @param emsg the error message; NULL if host registration is successful |
209 | */ | 209 | */ |
210 | static void | 210 | static void |
211 | hr_completion (void *cls, | 211 | hr_completion(void *cls, |
212 | const char *emsg) | 212 | const char *emsg) |
213 | { | 213 | { |
214 | struct Slave *slave = cls; | 214 | struct Slave *slave = cls; |
215 | struct HostRegistration *hr; | 215 | struct HostRegistration *hr; |
216 | 216 | ||
217 | slave->rhandle = NULL; | 217 | slave->rhandle = NULL; |
218 | hr = slave->hr_dll_head; | 218 | hr = slave->hr_dll_head; |
219 | GNUNET_assert (NULL != hr); | 219 | GNUNET_assert(NULL != hr); |
220 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 220 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
221 | "Registering host %u at %u successful\n", | 221 | "Registering host %u at %u successful\n", |
222 | GNUNET_TESTBED_host_get_id_ (hr->host), | 222 | GNUNET_TESTBED_host_get_id_(hr->host), |
223 | GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id])); | 223 | GNUNET_TESTBED_host_get_id_(GST_host_list[slave->host_id])); |
224 | GNUNET_CONTAINER_DLL_remove (slave->hr_dll_head, | 224 | GNUNET_CONTAINER_DLL_remove(slave->hr_dll_head, |
225 | slave->hr_dll_tail, | 225 | slave->hr_dll_tail, |
226 | hr); | 226 | hr); |
227 | if (NULL != hr->cb) | 227 | if (NULL != hr->cb) |
228 | hr->cb (hr->cb_cls, | 228 | hr->cb(hr->cb_cls, |
229 | emsg); | 229 | emsg); |
230 | GNUNET_free (hr); | 230 | GNUNET_free(hr); |
231 | if (NULL != slave->hr_dll_head) | 231 | if (NULL != slave->hr_dll_head) |
232 | register_next_host (slave); | 232 | register_next_host(slave); |
233 | } | 233 | } |
234 | 234 | ||
235 | 235 | ||
@@ -243,28 +243,28 @@ hr_completion (void *cls, | |||
243 | * @param host the host which has to be registered | 243 | * @param host the host which has to be registered |
244 | */ | 244 | */ |
245 | void | 245 | void |
246 | GST_queue_host_registration (struct Slave *slave, | 246 | GST_queue_host_registration(struct Slave *slave, |
247 | GNUNET_TESTBED_HostRegistrationCompletion cb, | 247 | GNUNET_TESTBED_HostRegistrationCompletion cb, |
248 | void *cb_cls, | 248 | void *cb_cls, |
249 | struct GNUNET_TESTBED_Host *host) | 249 | struct GNUNET_TESTBED_Host *host) |
250 | { | 250 | { |
251 | struct HostRegistration *hr; | 251 | struct HostRegistration *hr; |
252 | int call_register; | 252 | int call_register; |
253 | 253 | ||
254 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 254 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
255 | "Queueing host registration for host %u at %u\n", | 255 | "Queueing host registration for host %u at %u\n", |
256 | GNUNET_TESTBED_host_get_id_ (host), | 256 | GNUNET_TESTBED_host_get_id_(host), |
257 | GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id])); | 257 | GNUNET_TESTBED_host_get_id_(GST_host_list[slave->host_id])); |
258 | hr = GNUNET_new (struct HostRegistration); | 258 | hr = GNUNET_new(struct HostRegistration); |
259 | hr->cb = cb; | 259 | hr->cb = cb; |
260 | hr->cb_cls = cb_cls; | 260 | hr->cb_cls = cb_cls; |
261 | hr->host = host; | 261 | hr->host = host; |
262 | call_register = (NULL == slave->hr_dll_head) ? GNUNET_YES : GNUNET_NO; | 262 | call_register = (NULL == slave->hr_dll_head) ? GNUNET_YES : GNUNET_NO; |
263 | GNUNET_CONTAINER_DLL_insert_tail (slave->hr_dll_head, | 263 | GNUNET_CONTAINER_DLL_insert_tail(slave->hr_dll_head, |
264 | slave->hr_dll_tail, | 264 | slave->hr_dll_tail, |
265 | hr); | 265 | hr); |
266 | if (GNUNET_YES == call_register) | 266 | if (GNUNET_YES == call_register) |
267 | register_next_host (slave); | 267 | register_next_host(slave); |
268 | } | 268 | } |
269 | 269 | ||
270 | 270 | ||
@@ -275,23 +275,23 @@ GST_queue_host_registration (struct Slave *slave, | |||
275 | * @param msg the message to relay | 275 | * @param msg the message to relay |
276 | */ | 276 | */ |
277 | void | 277 | void |
278 | GST_forwarded_operation_reply_relay (void *cls, | 278 | GST_forwarded_operation_reply_relay(void *cls, |
279 | const struct GNUNET_MessageHeader *msg) | 279 | const struct GNUNET_MessageHeader *msg) |
280 | { | 280 | { |
281 | struct ForwardedOperationContext *fopc = cls; | 281 | struct ForwardedOperationContext *fopc = cls; |
282 | struct GNUNET_MQ_Envelope *env; | 282 | struct GNUNET_MQ_Envelope *env; |
283 | 283 | ||
284 | LOG_DEBUG ("Relaying message with type: %u, size: %u\n", | 284 | LOG_DEBUG("Relaying message with type: %u, size: %u\n", |
285 | ntohs (msg->type), | 285 | ntohs(msg->type), |
286 | ntohs (msg->size)); | 286 | ntohs(msg->size)); |
287 | env = GNUNET_MQ_msg_copy (msg); | 287 | env = GNUNET_MQ_msg_copy(msg); |
288 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (fopc->client), | 288 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(fopc->client), |
289 | env); | 289 | env); |
290 | GNUNET_SCHEDULER_cancel (fopc->timeout_task); | 290 | GNUNET_SCHEDULER_cancel(fopc->timeout_task); |
291 | GNUNET_CONTAINER_DLL_remove (fopcq_head, | 291 | GNUNET_CONTAINER_DLL_remove(fopcq_head, |
292 | fopcq_tail, | 292 | fopcq_tail, |
293 | fopc); | 293 | fopc); |
294 | GNUNET_free (fopc); | 294 | GNUNET_free(fopc); |
295 | } | 295 | } |
296 | 296 | ||
297 | 297 | ||
@@ -301,21 +301,21 @@ GST_forwarded_operation_reply_relay (void *cls, | |||
301 | * @param cls the ForwardedOperationContext | 301 | * @param cls the ForwardedOperationContext |
302 | */ | 302 | */ |
303 | void | 303 | void |
304 | GST_forwarded_operation_timeout (void *cls) | 304 | GST_forwarded_operation_timeout(void *cls) |
305 | { | 305 | { |
306 | struct ForwardedOperationContext *fopc = cls; | 306 | struct ForwardedOperationContext *fopc = cls; |
307 | 307 | ||
308 | fopc->timeout_task = NULL; | 308 | fopc->timeout_task = NULL; |
309 | GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc); | 309 | GNUNET_TESTBED_forward_operation_msg_cancel_(fopc->opc); |
310 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 310 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
311 | "A forwarded operation has timed out\n"); | 311 | "A forwarded operation has timed out\n"); |
312 | GST_send_operation_fail_msg (fopc->client, | 312 | GST_send_operation_fail_msg(fopc->client, |
313 | fopc->operation_id, | 313 | fopc->operation_id, |
314 | "A forwarded operation has timed out"); | 314 | "A forwarded operation has timed out"); |
315 | GNUNET_CONTAINER_DLL_remove (fopcq_head, | 315 | GNUNET_CONTAINER_DLL_remove(fopcq_head, |
316 | fopcq_tail, | 316 | fopcq_tail, |
317 | fopc); | 317 | fopc); |
318 | GNUNET_free (fopc); | 318 | GNUNET_free(fopc); |
319 | } | 319 | } |
320 | 320 | ||
321 | 321 | ||
@@ -329,51 +329,52 @@ GST_forwarded_operation_timeout (void *cls) | |||
329 | * upon empty service sharing specification. | 329 | * upon empty service sharing specification. |
330 | */ | 330 | */ |
331 | static struct GNUNET_TESTING_SharedService * | 331 | static struct GNUNET_TESTING_SharedService * |
332 | parse_shared_services (char *ss_str, | 332 | parse_shared_services(char *ss_str, |
333 | struct GNUNET_CONFIGURATION_Handle *cfg) | 333 | struct GNUNET_CONFIGURATION_Handle *cfg) |
334 | { | 334 | { |
335 | struct GNUNET_TESTING_SharedService ss; | 335 | struct GNUNET_TESTING_SharedService ss; |
336 | struct GNUNET_TESTING_SharedService *slist; | 336 | struct GNUNET_TESTING_SharedService *slist; |
337 | char service[256]; | 337 | char service[256]; |
338 | char *arg; | 338 | char *arg; |
339 | unsigned int n; | 339 | unsigned int n; |
340 | |||
340 | #define GROW_SS \ | 341 | #define GROW_SS \ |
341 | do { \ | 342 | do { \ |
342 | GNUNET_array_grow (slist, n, n+1); \ | 343 | GNUNET_array_grow(slist, n, n + 1); \ |
343 | GNUNET_memcpy (&slist[n - 1], &ss, \ | 344 | GNUNET_memcpy(&slist[n - 1], &ss, \ |
344 | sizeof (struct GNUNET_TESTING_SharedService)); \ | 345 | sizeof(struct GNUNET_TESTING_SharedService)); \ |
345 | } while (0) | 346 | } while (0) |
346 | 347 | ||
347 | slist = NULL; | 348 | slist = NULL; |
348 | n = 0; | 349 | n = 0; |
349 | ss.cfg = cfg; | 350 | ss.cfg = cfg; |
350 | for (; NULL != (arg = strtok (ss_str, " ")); ss_str = NULL) | 351 | for (; NULL != (arg = strtok(ss_str, " ")); ss_str = NULL) |
351 | { | ||
352 | ss.service = NULL; | ||
353 | ss.share = 0; | ||
354 | if (2 != sscanf (arg, "%255[^:]:%u", | ||
355 | service, | ||
356 | &ss.share)) | ||
357 | { | 352 | { |
358 | LOG (GNUNET_ERROR_TYPE_WARNING, | 353 | ss.service = NULL; |
359 | "Ignoring shared service spec: %s", | 354 | ss.share = 0; |
360 | arg); | 355 | if (2 != sscanf(arg, "%255[^:]:%u", |
361 | continue; | 356 | service, |
357 | &ss.share)) | ||
358 | { | ||
359 | LOG(GNUNET_ERROR_TYPE_WARNING, | ||
360 | "Ignoring shared service spec: %s", | ||
361 | arg); | ||
362 | continue; | ||
363 | } | ||
364 | LOG_DEBUG("Will be sharing %s service among %u peers\n", | ||
365 | service, | ||
366 | ss.share); | ||
367 | ss.service = GNUNET_strdup(service); | ||
368 | GROW_SS; | ||
362 | } | 369 | } |
363 | LOG_DEBUG ("Will be sharing %s service among %u peers\n", | ||
364 | service, | ||
365 | ss.share); | ||
366 | ss.service = GNUNET_strdup (service); | ||
367 | GROW_SS; | ||
368 | } | ||
369 | if (NULL != slist) | 370 | if (NULL != slist) |
370 | { | 371 | { |
371 | /* Add trailing NULL block */ | 372 | /* Add trailing NULL block */ |
372 | (void) memset (&ss, | 373 | (void)memset(&ss, |
373 | 0, | 374 | 0, |
374 | sizeof (struct GNUNET_TESTING_SharedService)); | 375 | sizeof(struct GNUNET_TESTING_SharedService)); |
375 | GROW_SS; | 376 | GROW_SS; |
376 | } | 377 | } |
377 | return slist; | 378 | return slist; |
378 | #undef GROW_SS | 379 | #undef GROW_SS |
379 | } | 380 | } |
@@ -387,19 +388,19 @@ parse_shared_services (char *ss_str, | |||
387 | * @return #GNUNET_OK if @a message is well-formed | 388 | * @return #GNUNET_OK if @a message is well-formed |
388 | */ | 389 | */ |
389 | static int | 390 | static int |
390 | check_init (void *cls, | 391 | check_init(void *cls, |
391 | const struct GNUNET_TESTBED_InitMessage *msg) | 392 | const struct GNUNET_TESTBED_InitMessage *msg) |
392 | { | 393 | { |
393 | const char *controller_hostname; | 394 | const char *controller_hostname; |
394 | uint16_t msize; | 395 | uint16_t msize; |
395 | 396 | ||
396 | msize = ntohs (msg->header.size) - sizeof (struct GNUNET_TESTBED_InitMessage); | 397 | msize = ntohs(msg->header.size) - sizeof(struct GNUNET_TESTBED_InitMessage); |
397 | controller_hostname = (const char *) &msg[1]; | 398 | controller_hostname = (const char *)&msg[1]; |
398 | if ('\0' != controller_hostname[msize - 1]) | 399 | if ('\0' != controller_hostname[msize - 1]) |
399 | { | 400 | { |
400 | GNUNET_break (0); | 401 | GNUNET_break(0); |
401 | return GNUNET_SYSERR; | 402 | return GNUNET_SYSERR; |
402 | } | 403 | } |
403 | return GNUNET_OK; | 404 | return GNUNET_OK; |
404 | } | 405 | } |
405 | 406 | ||
@@ -411,8 +412,8 @@ check_init (void *cls, | |||
411 | * @param message the actual message | 412 | * @param message the actual message |
412 | */ | 413 | */ |
413 | static void | 414 | static void |
414 | handle_init (void *cls, | 415 | handle_init(void *cls, |
415 | const struct GNUNET_TESTBED_InitMessage *msg) | 416 | const struct GNUNET_TESTBED_InitMessage *msg) |
416 | { | 417 | { |
417 | struct GNUNET_SERVICE_Client *client = cls; | 418 | struct GNUNET_SERVICE_Client *client = cls; |
418 | struct GNUNET_TESTBED_Host *host; | 419 | struct GNUNET_TESTBED_Host *host; |
@@ -422,56 +423,56 @@ handle_init (void *cls, | |||
422 | unsigned int cnt; | 423 | unsigned int cnt; |
423 | 424 | ||
424 | if (NULL != GST_context) | 425 | if (NULL != GST_context) |
425 | { | 426 | { |
426 | LOG_DEBUG ("We are being connected to laterally\n"); | 427 | LOG_DEBUG("We are being connected to laterally\n"); |
427 | GNUNET_SERVICE_client_continue (client); | 428 | GNUNET_SERVICE_client_continue(client); |
428 | return; | 429 | return; |
429 | } | 430 | } |
430 | controller_hostname = (const char *) &msg[1]; | 431 | controller_hostname = (const char *)&msg[1]; |
431 | ss_str = NULL; | 432 | ss_str = NULL; |
432 | ss = NULL; | 433 | ss = NULL; |
433 | if (GNUNET_OK == | 434 | if (GNUNET_OK == |
434 | GNUNET_CONFIGURATION_get_value_string (GST_config, | 435 | GNUNET_CONFIGURATION_get_value_string(GST_config, |
435 | "TESTBED", | 436 | "TESTBED", |
436 | "SHARED_SERVICES", | 437 | "SHARED_SERVICES", |
437 | &ss_str)) | 438 | &ss_str)) |
438 | { | 439 | { |
439 | ss = parse_shared_services (ss_str, | 440 | ss = parse_shared_services(ss_str, |
440 | GST_config); | 441 | GST_config); |
441 | GNUNET_free (ss_str); | 442 | GNUNET_free(ss_str); |
442 | ss_str = NULL; | 443 | ss_str = NULL; |
443 | } | 444 | } |
444 | GST_context = GNUNET_new (struct Context); | 445 | GST_context = GNUNET_new(struct Context); |
445 | GST_context->client = client; | 446 | GST_context->client = client; |
446 | GST_context->host_id = ntohl (msg->host_id); | 447 | GST_context->host_id = ntohl(msg->host_id); |
447 | GST_context->master_ip = GNUNET_strdup (controller_hostname); | 448 | GST_context->master_ip = GNUNET_strdup(controller_hostname); |
448 | LOG_DEBUG ("Our IP: %s\n", | 449 | LOG_DEBUG("Our IP: %s\n", |
449 | GST_context->master_ip); | 450 | GST_context->master_ip); |
450 | GST_context->system | 451 | GST_context->system |
451 | = GNUNET_TESTING_system_create ("testbed", | 452 | = GNUNET_TESTING_system_create("testbed", |
452 | GST_context->master_ip, | 453 | GST_context->master_ip, |
453 | hostname, | 454 | hostname, |
454 | ss); | 455 | ss); |
455 | if (NULL != ss) | 456 | if (NULL != ss) |
456 | { | ||
457 | for (cnt = 0; NULL != ss[cnt].service; cnt++) | ||
458 | { | 457 | { |
459 | ss_str = (char *) ss[cnt].service; | 458 | for (cnt = 0; NULL != ss[cnt].service; cnt++) |
460 | GNUNET_free (ss_str); | 459 | { |
460 | ss_str = (char *)ss[cnt].service; | ||
461 | GNUNET_free(ss_str); | ||
462 | } | ||
463 | GNUNET_free(ss); | ||
464 | ss = NULL; | ||
461 | } | 465 | } |
462 | GNUNET_free (ss); | ||
463 | ss = NULL; | ||
464 | } | ||
465 | host = | 466 | host = |
466 | GNUNET_TESTBED_host_create_with_id (GST_context->host_id, | 467 | GNUNET_TESTBED_host_create_with_id(GST_context->host_id, |
467 | GST_context->master_ip, | 468 | GST_context->master_ip, |
468 | NULL, | 469 | NULL, |
469 | GST_config, | 470 | GST_config, |
470 | 0); | 471 | 0); |
471 | host_list_add (host); | 472 | host_list_add(host); |
472 | LOG_DEBUG ("Created master context with host ID: %u\n", | 473 | LOG_DEBUG("Created master context with host ID: %u\n", |
473 | GST_context->host_id); | 474 | GST_context->host_id); |
474 | GNUNET_SERVICE_client_continue (client); | 475 | GNUNET_SERVICE_client_continue(client); |
475 | } | 476 | } |
476 | 477 | ||
477 | 478 | ||
@@ -483,29 +484,29 @@ handle_init (void *cls, | |||
483 | * @return #GNUNET_OK if @a message is well-formed | 484 | * @return #GNUNET_OK if @a message is well-formed |
484 | */ | 485 | */ |
485 | static int | 486 | static int |
486 | check_add_host (void *cls, | 487 | check_add_host(void *cls, |
487 | const struct GNUNET_TESTBED_AddHostMessage *msg) | 488 | const struct GNUNET_TESTBED_AddHostMessage *msg) |
488 | { | 489 | { |
489 | uint16_t username_length; | 490 | uint16_t username_length; |
490 | uint16_t hostname_length; | 491 | uint16_t hostname_length; |
491 | uint16_t msize; | 492 | uint16_t msize; |
492 | 493 | ||
493 | msize = ntohs (msg->header.size) - sizeof (struct GNUNET_TESTBED_AddHostMessage); | 494 | msize = ntohs(msg->header.size) - sizeof(struct GNUNET_TESTBED_AddHostMessage); |
494 | username_length = ntohs (msg->username_length); | 495 | username_length = ntohs(msg->username_length); |
495 | hostname_length = ntohs (msg->hostname_length); | 496 | hostname_length = ntohs(msg->hostname_length); |
496 | /* msg must contain hostname */ | 497 | /* msg must contain hostname */ |
497 | if ( (msize <= username_length) || | 498 | if ((msize <= username_length) || |
498 | (0 == hostname_length) ) | 499 | (0 == hostname_length)) |
499 | { | 500 | { |
500 | GNUNET_break (0); | 501 | GNUNET_break(0); |
501 | return GNUNET_SYSERR; | 502 | return GNUNET_SYSERR; |
502 | } | 503 | } |
503 | /* msg must contain configuration */ | 504 | /* msg must contain configuration */ |
504 | if (msize <= username_length + hostname_length) | 505 | if (msize <= username_length + hostname_length) |
505 | { | 506 | { |
506 | GNUNET_break (0); | 507 | GNUNET_break(0); |
507 | return GNUNET_SYSERR; | 508 | return GNUNET_SYSERR; |
508 | } | 509 | } |
509 | return GNUNET_OK; | 510 | return GNUNET_OK; |
510 | } | 511 | } |
511 | 512 | ||
@@ -517,8 +518,8 @@ check_add_host (void *cls, | |||
517 | * @param msg the actual message | 518 | * @param msg the actual message |
518 | */ | 519 | */ |
519 | static void | 520 | static void |
520 | handle_add_host (void *cls, | 521 | handle_add_host(void *cls, |
521 | const struct GNUNET_TESTBED_AddHostMessage *msg) | 522 | const struct GNUNET_TESTBED_AddHostMessage *msg) |
522 | { | 523 | { |
523 | struct GNUNET_SERVICE_Client *client = cls; | 524 | struct GNUNET_SERVICE_Client *client = cls; |
524 | struct GNUNET_TESTBED_Host *host; | 525 | struct GNUNET_TESTBED_Host *host; |
@@ -533,77 +534,77 @@ handle_add_host (void *cls, | |||
533 | uint16_t hostname_length; | 534 | uint16_t hostname_length; |
534 | struct GNUNET_MQ_Envelope *env; | 535 | struct GNUNET_MQ_Envelope *env; |
535 | 536 | ||
536 | username_length = ntohs (msg->username_length); | 537 | username_length = ntohs(msg->username_length); |
537 | hostname_length = ntohs (msg->hostname_length); | 538 | hostname_length = ntohs(msg->hostname_length); |
538 | username = NULL; | 539 | username = NULL; |
539 | hostname = NULL; | 540 | hostname = NULL; |
540 | ptr = &msg[1]; | 541 | ptr = &msg[1]; |
541 | if (0 != username_length) | 542 | if (0 != username_length) |
542 | { | 543 | { |
543 | username = GNUNET_malloc (username_length + 1); | 544 | username = GNUNET_malloc(username_length + 1); |
544 | GNUNET_strlcpy (username, ptr, username_length + 1); | 545 | GNUNET_strlcpy(username, ptr, username_length + 1); |
545 | ptr += username_length; | 546 | ptr += username_length; |
546 | } | 547 | } |
547 | hostname = GNUNET_malloc (hostname_length + 1); | 548 | hostname = GNUNET_malloc(hostname_length + 1); |
548 | GNUNET_strlcpy (hostname, ptr, hostname_length + 1); | 549 | GNUNET_strlcpy(hostname, ptr, hostname_length + 1); |
549 | if (NULL == (host_cfg = GNUNET_TESTBED_extract_config_ (&msg->header))) | 550 | if (NULL == (host_cfg = GNUNET_TESTBED_extract_config_(&msg->header))) |
550 | { | 551 | { |
551 | GNUNET_free_non_null (username); | 552 | GNUNET_free_non_null(username); |
552 | GNUNET_free_non_null (hostname); | 553 | GNUNET_free_non_null(hostname); |
553 | GNUNET_break_op (0); | 554 | GNUNET_break_op(0); |
554 | GNUNET_SERVICE_client_drop (client); | 555 | GNUNET_SERVICE_client_drop(client); |
555 | return; | 556 | return; |
556 | } | 557 | } |
557 | host_id = ntohl (msg->host_id); | 558 | host_id = ntohl(msg->host_id); |
558 | LOG_DEBUG ("Received ADDHOST %u message\n", host_id); | 559 | LOG_DEBUG("Received ADDHOST %u message\n", host_id); |
559 | LOG_DEBUG ("-------host id: %u\n", host_id); | 560 | LOG_DEBUG("-------host id: %u\n", host_id); |
560 | LOG_DEBUG ("-------hostname: %s\n", hostname); | 561 | LOG_DEBUG("-------hostname: %s\n", hostname); |
561 | if (NULL != username) | 562 | if (NULL != username) |
562 | LOG_DEBUG ("-------username: %s\n", username); | 563 | LOG_DEBUG("-------username: %s\n", username); |
563 | else | 564 | else |
564 | LOG_DEBUG ("-------username: <not given>\n"); | 565 | LOG_DEBUG("-------username: <not given>\n"); |
565 | LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port)); | 566 | LOG_DEBUG("-------ssh port: %u\n", ntohs(msg->ssh_port)); |
566 | host = GNUNET_TESTBED_host_create_with_id (host_id, | 567 | host = GNUNET_TESTBED_host_create_with_id(host_id, |
567 | hostname, | 568 | hostname, |
568 | username, | 569 | username, |
569 | host_cfg, | 570 | host_cfg, |
570 | ntohs (msg->ssh_port)); | 571 | ntohs(msg->ssh_port)); |
571 | GNUNET_free_non_null (username); | 572 | GNUNET_free_non_null(username); |
572 | GNUNET_free (hostname); | 573 | GNUNET_free(hostname); |
573 | GNUNET_CONFIGURATION_destroy (host_cfg); | 574 | GNUNET_CONFIGURATION_destroy(host_cfg); |
574 | if (NULL == host) | 575 | if (NULL == host) |
575 | { | 576 | { |
576 | GNUNET_break_op (0); | 577 | GNUNET_break_op(0); |
577 | GNUNET_SERVICE_client_drop (client); | 578 | GNUNET_SERVICE_client_drop(client); |
578 | return; | 579 | return; |
579 | } | 580 | } |
580 | if (GNUNET_OK != host_list_add (host)) | 581 | if (GNUNET_OK != host_list_add(host)) |
581 | { | 582 | { |
582 | /* We are unable to add a host */ | 583 | /* We are unable to add a host */ |
583 | emsg = "A host exists with given host-id"; | 584 | emsg = "A host exists with given host-id"; |
584 | LOG_DEBUG ("%s: %u", | 585 | LOG_DEBUG("%s: %u", |
585 | emsg, | 586 | emsg, |
586 | host_id); | 587 | host_id); |
587 | GNUNET_TESTBED_host_destroy (host); | 588 | GNUNET_TESTBED_host_destroy(host); |
588 | env = GNUNET_MQ_msg_extra (reply, | 589 | env = GNUNET_MQ_msg_extra(reply, |
589 | strlen (emsg) + 1, | 590 | strlen(emsg) + 1, |
590 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); | 591 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); |
591 | GNUNET_memcpy (&reply[1], | 592 | GNUNET_memcpy(&reply[1], |
592 | emsg, | 593 | emsg, |
593 | strlen (emsg) + 1); | 594 | strlen(emsg) + 1); |
594 | } | 595 | } |
595 | else | 596 | else |
596 | { | 597 | { |
597 | LOG_DEBUG ("Added host %u at %u\n", | 598 | LOG_DEBUG("Added host %u at %u\n", |
598 | host_id, | 599 | host_id, |
599 | GST_context->host_id); | 600 | GST_context->host_id); |
600 | env = GNUNET_MQ_msg (reply, | 601 | env = GNUNET_MQ_msg(reply, |
601 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); | 602 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); |
602 | } | 603 | } |
603 | reply->host_id = htonl (host_id); | 604 | reply->host_id = htonl(host_id); |
604 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 605 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), |
605 | env); | 606 | env); |
606 | GNUNET_SERVICE_client_continue (client); | 607 | GNUNET_SERVICE_client_continue(client); |
607 | } | 608 | } |
608 | 609 | ||
609 | 610 | ||
@@ -614,8 +615,8 @@ handle_add_host (void *cls, | |||
614 | * @param msg the actual message | 615 | * @param msg the actual message |
615 | */ | 616 | */ |
616 | static void | 617 | static void |
617 | handle_slave_get_config (void *cls, | 618 | handle_slave_get_config(void *cls, |
618 | const struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg) | 619 | const struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg) |
619 | { | 620 | { |
620 | struct GNUNET_SERVICE_Client *client = cls; | 621 | struct GNUNET_SERVICE_Client *client = cls; |
621 | struct Slave *slave; | 622 | struct Slave *slave; |
@@ -629,42 +630,42 @@ handle_slave_get_config (void *cls, | |||
629 | uint64_t op_id; | 630 | uint64_t op_id; |
630 | uint32_t slave_id; | 631 | uint32_t slave_id; |
631 | 632 | ||
632 | slave_id = ntohl (msg->slave_id); | 633 | slave_id = ntohl(msg->slave_id); |
633 | op_id = GNUNET_ntohll (msg->operation_id); | 634 | op_id = GNUNET_ntohll(msg->operation_id); |
634 | if ( (GST_slave_list_size <= slave_id) || | 635 | if ((GST_slave_list_size <= slave_id) || |
635 | (NULL == GST_slave_list[slave_id]) ) | 636 | (NULL == GST_slave_list[slave_id])) |
636 | { | 637 | { |
637 | /* FIXME: Add forwardings for this type of message here.. */ | 638 | /* FIXME: Add forwardings for this type of message here.. */ |
638 | GST_send_operation_fail_msg (client, | 639 | GST_send_operation_fail_msg(client, |
639 | op_id, | 640 | op_id, |
640 | "Slave not found"); | 641 | "Slave not found"); |
641 | GNUNET_SERVICE_client_continue (client); | 642 | GNUNET_SERVICE_client_continue(client); |
642 | return; | 643 | return; |
643 | } | 644 | } |
644 | slave = GST_slave_list[slave_id]; | 645 | slave = GST_slave_list[slave_id]; |
645 | GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (GST_host_list[slave->host_id]))); | 646 | GNUNET_assert(NULL != (cfg = GNUNET_TESTBED_host_get_cfg_(GST_host_list[slave->host_id]))); |
646 | config = GNUNET_CONFIGURATION_serialize (cfg, | 647 | config = GNUNET_CONFIGURATION_serialize(cfg, |
647 | &config_size); | 648 | &config_size); |
648 | /* FIXME: maybe we want to transmit the delta to the default here? */ | 649 | /* FIXME: maybe we want to transmit the delta to the default here? */ |
649 | xconfig_size = GNUNET_TESTBED_compress_config_ (config, | 650 | xconfig_size = GNUNET_TESTBED_compress_config_(config, |
650 | config_size, | 651 | config_size, |
651 | &xconfig); | 652 | &xconfig); |
652 | GNUNET_free (config); | 653 | GNUNET_free(config); |
653 | GNUNET_assert (xconfig_size + sizeof (struct GNUNET_TESTBED_SlaveConfiguration) <= UINT16_MAX); | 654 | GNUNET_assert(xconfig_size + sizeof(struct GNUNET_TESTBED_SlaveConfiguration) <= UINT16_MAX); |
654 | GNUNET_assert (xconfig_size <= UINT16_MAX); | 655 | GNUNET_assert(xconfig_size <= UINT16_MAX); |
655 | env = GNUNET_MQ_msg_extra (reply, | 656 | env = GNUNET_MQ_msg_extra(reply, |
656 | xconfig_size, | 657 | xconfig_size, |
657 | GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION); | 658 | GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION); |
658 | reply->slave_id = msg->slave_id; | 659 | reply->slave_id = msg->slave_id; |
659 | reply->operation_id = msg->operation_id; | 660 | reply->operation_id = msg->operation_id; |
660 | reply->config_size = htons ((uint16_t) config_size); | 661 | reply->config_size = htons((uint16_t)config_size); |
661 | GNUNET_memcpy (&reply[1], | 662 | GNUNET_memcpy(&reply[1], |
662 | xconfig, | 663 | xconfig, |
663 | xconfig_size); | 664 | xconfig_size); |
664 | GNUNET_free (xconfig); | 665 | GNUNET_free(xconfig); |
665 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 666 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), |
666 | env); | 667 | env); |
667 | GNUNET_SERVICE_client_continue (client); | 668 | GNUNET_SERVICE_client_continue(client); |
668 | } | 669 | } |
669 | 670 | ||
670 | 671 | ||
@@ -672,48 +673,52 @@ handle_slave_get_config (void *cls, | |||
672 | * Clears the forwarded operations queue | 673 | * Clears the forwarded operations queue |
673 | */ | 674 | */ |
674 | void | 675 | void |
675 | GST_clear_fopcq () | 676 | GST_clear_fopcq() |
676 | { | 677 | { |
677 | struct ForwardedOperationContext *fopc; | 678 | struct ForwardedOperationContext *fopc; |
678 | 679 | ||
679 | while (NULL != (fopc = fopcq_head)) | 680 | while (NULL != (fopc = fopcq_head)) |
680 | { | ||
681 | GNUNET_CONTAINER_DLL_remove (fopcq_head, | ||
682 | fopcq_tail, | ||
683 | fopc); | ||
684 | GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc); | ||
685 | if (NULL != fopc->timeout_task) | ||
686 | GNUNET_SCHEDULER_cancel (fopc->timeout_task); | ||
687 | switch (fopc->type) | ||
688 | { | 681 | { |
689 | case OP_PEER_CREATE: | 682 | GNUNET_CONTAINER_DLL_remove(fopcq_head, |
690 | GNUNET_free (fopc->cls); | 683 | fopcq_tail, |
691 | break; | 684 | fopc); |
692 | case OP_SHUTDOWN_PEERS: | 685 | GNUNET_TESTBED_forward_operation_msg_cancel_(fopc->opc); |
693 | { | 686 | if (NULL != fopc->timeout_task) |
694 | struct HandlerContext_ShutdownPeers *hc = fopc->cls; | 687 | GNUNET_SCHEDULER_cancel(fopc->timeout_task); |
695 | 688 | switch (fopc->type) | |
696 | GNUNET_assert (0 < hc->nslaves); | 689 | { |
697 | hc->nslaves--; | 690 | case OP_PEER_CREATE: |
698 | if (0 == hc->nslaves) | 691 | GNUNET_free(fopc->cls); |
699 | GNUNET_free (hc); | 692 | break; |
700 | } | 693 | |
701 | break; | 694 | case OP_SHUTDOWN_PEERS: |
702 | case OP_PEER_START: | 695 | { |
703 | case OP_PEER_STOP: | 696 | struct HandlerContext_ShutdownPeers *hc = fopc->cls; |
704 | case OP_PEER_DESTROY: | 697 | |
705 | case OP_PEER_INFO: | 698 | GNUNET_assert(0 < hc->nslaves); |
706 | case OP_OVERLAY_CONNECT: | 699 | hc->nslaves--; |
707 | case OP_LINK_CONTROLLERS: | 700 | if (0 == hc->nslaves) |
708 | case OP_GET_SLAVE_CONFIG: | 701 | GNUNET_free(hc); |
709 | case OP_MANAGE_SERVICE: | 702 | } |
710 | case OP_PEER_RECONFIGURE: | 703 | break; |
711 | break; | 704 | |
712 | case OP_FORWARDED: | 705 | case OP_PEER_START: |
713 | GNUNET_assert (0); | 706 | case OP_PEER_STOP: |
714 | }; | 707 | case OP_PEER_DESTROY: |
715 | GNUNET_free (fopc); | 708 | case OP_PEER_INFO: |
716 | } | 709 | case OP_OVERLAY_CONNECT: |
710 | case OP_LINK_CONTROLLERS: | ||
711 | case OP_GET_SLAVE_CONFIG: | ||
712 | case OP_MANAGE_SERVICE: | ||
713 | case OP_PEER_RECONFIGURE: | ||
714 | break; | ||
715 | |||
716 | case OP_FORWARDED: | ||
717 | GNUNET_assert(0); | ||
718 | } | ||
719 | ; | ||
720 | GNUNET_free(fopc); | ||
721 | } | ||
717 | } | 722 | } |
718 | 723 | ||
719 | 724 | ||
@@ -723,49 +728,49 @@ GST_clear_fopcq () | |||
723 | * @param cls NULL | 728 | * @param cls NULL |
724 | */ | 729 | */ |
725 | static void | 730 | static void |
726 | shutdown_task (void *cls) | 731 | shutdown_task(void *cls) |
727 | { | 732 | { |
728 | uint32_t id; | 733 | uint32_t id; |
729 | 734 | ||
730 | LOG_DEBUG ("Shutting down testbed service\n"); | 735 | LOG_DEBUG("Shutting down testbed service\n"); |
731 | /* cleanup any remaining forwarded operations */ | 736 | /* cleanup any remaining forwarded operations */ |
732 | GST_clear_fopcq (); | 737 | GST_clear_fopcq(); |
733 | GST_free_lcf (); | 738 | GST_free_lcf(); |
734 | GST_free_mctxq (); | 739 | GST_free_mctxq(); |
735 | GST_free_occq (); | 740 | GST_free_occq(); |
736 | GST_free_roccq (); | 741 | GST_free_roccq(); |
737 | GST_free_nccq (); | 742 | GST_free_nccq(); |
738 | GST_neighbour_list_clean(); | 743 | GST_neighbour_list_clean(); |
739 | GST_free_prcq (); | 744 | GST_free_prcq(); |
740 | /* Clear peer list */ | 745 | /* Clear peer list */ |
741 | GST_destroy_peers (); | 746 | GST_destroy_peers(); |
742 | /* Clear route list */ | 747 | /* Clear route list */ |
743 | GST_route_list_clear (); | 748 | GST_route_list_clear(); |
744 | /* Clear GST_slave_list */ | 749 | /* Clear GST_slave_list */ |
745 | GST_slave_list_clear (); | 750 | GST_slave_list_clear(); |
746 | /* Clear host list */ | 751 | /* Clear host list */ |
747 | for (id = 0; id < GST_host_list_size; id++) | 752 | for (id = 0; id < GST_host_list_size; id++) |
748 | if (NULL != GST_host_list[id]) | 753 | if (NULL != GST_host_list[id]) |
749 | GNUNET_TESTBED_host_destroy (GST_host_list[id]); | 754 | GNUNET_TESTBED_host_destroy(GST_host_list[id]); |
750 | GNUNET_free_non_null (GST_host_list); | 755 | GNUNET_free_non_null(GST_host_list); |
751 | if (NULL != GST_context) | 756 | if (NULL != GST_context) |
752 | { | 757 | { |
753 | GNUNET_free_non_null (GST_context->master_ip); | 758 | GNUNET_free_non_null(GST_context->master_ip); |
754 | if (NULL != GST_context->system) | 759 | if (NULL != GST_context->system) |
755 | GNUNET_TESTING_system_destroy (GST_context->system, | 760 | GNUNET_TESTING_system_destroy(GST_context->system, |
756 | GNUNET_YES); | 761 | GNUNET_YES); |
757 | GNUNET_free (GST_context); | 762 | GNUNET_free(GST_context); |
758 | GST_context = NULL; | 763 | GST_context = NULL; |
759 | } | 764 | } |
760 | GNUNET_free_non_null (hostname); | 765 | GNUNET_free_non_null(hostname); |
761 | /* Free hello cache */ | 766 | /* Free hello cache */ |
762 | GST_cache_clear (); | 767 | GST_cache_clear(); |
763 | GST_connection_pool_destroy (); | 768 | GST_connection_pool_destroy(); |
764 | GNUNET_TESTBED_operation_queue_destroy_ (GST_opq_openfds); | 769 | GNUNET_TESTBED_operation_queue_destroy_(GST_opq_openfds); |
765 | GST_opq_openfds = NULL; | 770 | GST_opq_openfds = NULL; |
766 | GST_stats_destroy (); | 771 | GST_stats_destroy(); |
767 | GST_barriers_destroy (); | 772 | GST_barriers_destroy(); |
768 | GNUNET_CONFIGURATION_destroy (GST_config); | 773 | GNUNET_CONFIGURATION_destroy(GST_config); |
769 | } | 774 | } |
770 | 775 | ||
771 | 776 | ||
@@ -778,9 +783,9 @@ shutdown_task (void *cls) | |||
778 | * @return @a client | 783 | * @return @a client |
779 | */ | 784 | */ |
780 | static void * | 785 | static void * |
781 | client_connect_cb (void *cls, | 786 | client_connect_cb(void *cls, |
782 | struct GNUNET_SERVICE_Client *client, | 787 | struct GNUNET_SERVICE_Client *client, |
783 | struct GNUNET_MQ_Handle *mq) | 788 | struct GNUNET_MQ_Handle *mq) |
784 | { | 789 | { |
785 | return client; | 790 | return client; |
786 | } | 791 | } |
@@ -794,41 +799,41 @@ client_connect_cb (void *cls, | |||
794 | * @param app_ctx should match @a client | 799 | * @param app_ctx should match @a client |
795 | */ | 800 | */ |
796 | static void | 801 | static void |
797 | client_disconnect_cb (void *cls, | 802 | client_disconnect_cb(void *cls, |
798 | struct GNUNET_SERVICE_Client *client, | 803 | struct GNUNET_SERVICE_Client *client, |
799 | void *app_ctx) | 804 | void *app_ctx) |
800 | { | 805 | { |
801 | struct ForwardedOperationContext *fopc; | 806 | struct ForwardedOperationContext *fopc; |
802 | struct ForwardedOperationContext *fopcn; | 807 | struct ForwardedOperationContext *fopcn; |
803 | 808 | ||
804 | GNUNET_assert (client == app_ctx); | 809 | GNUNET_assert(client == app_ctx); |
805 | GST_notify_client_disconnect_oc (client); | 810 | GST_notify_client_disconnect_oc(client); |
806 | GST_link_notify_disconnect (client); | 811 | GST_link_notify_disconnect(client); |
807 | GST_notify_client_disconnect_peers (client); | 812 | GST_notify_client_disconnect_peers(client); |
808 | for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) | 813 | for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) |
809 | { | ||
810 | fopcn = fopc->next; | ||
811 | if (fopc->client == client) | ||
812 | { | 814 | { |
813 | /* handle as if it were a timeout */ | 815 | fopcn = fopc->next; |
814 | GNUNET_SCHEDULER_cancel (fopc->timeout_task); | 816 | if (fopc->client == client) |
815 | GST_forwarded_operation_timeout (fopc); | 817 | { |
818 | /* handle as if it were a timeout */ | ||
819 | GNUNET_SCHEDULER_cancel(fopc->timeout_task); | ||
820 | GST_forwarded_operation_timeout(fopc); | ||
821 | } | ||
816 | } | 822 | } |
817 | } | ||
818 | if (NULL == GST_context) | 823 | if (NULL == GST_context) |
819 | return; | 824 | return; |
820 | if (client == GST_context->client) | 825 | if (client == GST_context->client) |
821 | { | 826 | { |
822 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 827 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
823 | "Master client disconnected\n"); | 828 | "Master client disconnected\n"); |
824 | GST_context->client = NULL; | 829 | GST_context->client = NULL; |
825 | /* should not be needed as we're terminated by failure to read | 830 | /* should not be needed as we're terminated by failure to read |
826 | * from stdin, but if stdin fails for some reason, this shouldn't | 831 | * from stdin, but if stdin fails for some reason, this shouldn't |
827 | * hurt for now --- might need to revise this later if we ever | 832 | * hurt for now --- might need to revise this later if we ever |
828 | * decide that master connections might be temporarily down | 833 | * decide that master connections might be temporarily down |
829 | * for some reason */ | 834 | * for some reason */ |
830 | //GNUNET_SCHEDULER_shutdown (); | 835 | //GNUNET_SCHEDULER_shutdown (); |
831 | } | 836 | } |
832 | } | 837 | } |
833 | 838 | ||
834 | 839 | ||
@@ -840,54 +845,54 @@ client_disconnect_cb (void *cls, | |||
840 | * @param service the initialized server | 845 | * @param service the initialized server |
841 | */ | 846 | */ |
842 | static void | 847 | static void |
843 | testbed_run (void *cls, | 848 | testbed_run(void *cls, |
844 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 849 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
845 | struct GNUNET_SERVICE_Handle *service) | 850 | struct GNUNET_SERVICE_Handle *service) |
846 | { | 851 | { |
847 | char *logfile; | 852 | char *logfile; |
848 | unsigned long long num; | 853 | unsigned long long num; |
849 | 854 | ||
850 | LOG_DEBUG ("Starting testbed\n"); | 855 | LOG_DEBUG("Starting testbed\n"); |
851 | if (GNUNET_OK == | 856 | if (GNUNET_OK == |
852 | GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED", "LOG_FILE", | 857 | GNUNET_CONFIGURATION_get_value_filename(cfg, "TESTBED", "LOG_FILE", |
853 | &logfile)) | 858 | &logfile)) |
854 | { | 859 | { |
855 | GNUNET_break (GNUNET_OK == | 860 | GNUNET_break(GNUNET_OK == |
856 | GNUNET_log_setup ("testbed", | 861 | GNUNET_log_setup("testbed", |
857 | "DEBUG", | 862 | "DEBUG", |
858 | logfile)); | 863 | logfile)); |
859 | GNUNET_free (logfile); | 864 | GNUNET_free(logfile); |
860 | } | 865 | } |
861 | GNUNET_assert (GNUNET_OK == | 866 | GNUNET_assert(GNUNET_OK == |
862 | GNUNET_CONFIGURATION_get_value_number (cfg, | 867 | GNUNET_CONFIGURATION_get_value_number(cfg, |
863 | "testbed", | 868 | "testbed", |
864 | "CACHE_SIZE", | 869 | "CACHE_SIZE", |
865 | &num)); | 870 | &num)); |
866 | GST_cache_init ((unsigned int) num); | 871 | GST_cache_init((unsigned int)num); |
867 | GST_connection_pool_init ((unsigned int) num); | 872 | GST_connection_pool_init((unsigned int)num); |
868 | GNUNET_assert (GNUNET_OK == | 873 | GNUNET_assert(GNUNET_OK == |
869 | GNUNET_CONFIGURATION_get_value_number (cfg, | 874 | GNUNET_CONFIGURATION_get_value_number(cfg, |
870 | "testbed", | 875 | "testbed", |
871 | "MAX_OPEN_FDS", | 876 | "MAX_OPEN_FDS", |
872 | &num)); | 877 | &num)); |
873 | GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, | 878 | GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_FIXED, |
874 | (unsigned int) num); | 879 | (unsigned int)num); |
875 | GNUNET_assert (GNUNET_OK == | 880 | GNUNET_assert(GNUNET_OK == |
876 | GNUNET_CONFIGURATION_get_value_time (cfg, | 881 | GNUNET_CONFIGURATION_get_value_time(cfg, |
882 | "testbed", | ||
883 | "OPERATION_TIMEOUT", | ||
884 | &GST_timeout)); | ||
885 | GNUNET_assert(GNUNET_OK == | ||
886 | GNUNET_CONFIGURATION_get_value_string(cfg, | ||
877 | "testbed", | 887 | "testbed", |
878 | "OPERATION_TIMEOUT", | 888 | "HOSTNAME", |
879 | &GST_timeout)); | 889 | &hostname)); |
880 | GNUNET_assert (GNUNET_OK == | 890 | GST_config = GNUNET_CONFIGURATION_dup(cfg); |
881 | GNUNET_CONFIGURATION_get_value_string (cfg, | 891 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, |
882 | "testbed", | 892 | NULL); |
883 | "HOSTNAME", | 893 | LOG_DEBUG("Testbed startup complete\n"); |
884 | &hostname)); | 894 | GST_stats_init(GST_config); |
885 | GST_config = GNUNET_CONFIGURATION_dup (cfg); | 895 | GST_barriers_init(GST_config); |
886 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
887 | NULL); | ||
888 | LOG_DEBUG ("Testbed startup complete\n"); | ||
889 | GST_stats_init (GST_config); | ||
890 | GST_barriers_init (GST_config); | ||
891 | } | 896 | } |
892 | 897 | ||
893 | 898 | ||
@@ -895,81 +900,81 @@ testbed_run (void *cls, | |||
895 | * Define "main" method using service macro. | 900 | * Define "main" method using service macro. |
896 | */ | 901 | */ |
897 | GNUNET_SERVICE_MAIN | 902 | GNUNET_SERVICE_MAIN |
898 | ("testbed", | 903 | ("testbed", |
899 | GNUNET_SERVICE_OPTION_NONE, | 904 | GNUNET_SERVICE_OPTION_NONE, |
900 | &testbed_run, | 905 | &testbed_run, |
901 | &client_connect_cb, | 906 | &client_connect_cb, |
902 | &client_disconnect_cb, | 907 | &client_disconnect_cb, |
903 | NULL, | 908 | NULL, |
904 | GNUNET_MQ_hd_var_size (init, | 909 | GNUNET_MQ_hd_var_size(init, |
905 | GNUNET_MESSAGE_TYPE_TESTBED_INIT, | 910 | GNUNET_MESSAGE_TYPE_TESTBED_INIT, |
906 | struct GNUNET_TESTBED_InitMessage, | 911 | struct GNUNET_TESTBED_InitMessage, |
907 | NULL), | 912 | NULL), |
908 | GNUNET_MQ_hd_var_size (add_host, | 913 | GNUNET_MQ_hd_var_size(add_host, |
909 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, | 914 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, |
910 | struct GNUNET_TESTBED_AddHostMessage, | 915 | struct GNUNET_TESTBED_AddHostMessage, |
911 | NULL), | 916 | NULL), |
912 | GNUNET_MQ_hd_fixed_size (slave_get_config, | 917 | GNUNET_MQ_hd_fixed_size(slave_get_config, |
913 | GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION, | 918 | GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION, |
914 | struct GNUNET_TESTBED_SlaveGetConfigurationMessage, | 919 | struct GNUNET_TESTBED_SlaveGetConfigurationMessage, |
915 | NULL), | 920 | NULL), |
916 | GNUNET_MQ_hd_fixed_size (link_controllers, | 921 | GNUNET_MQ_hd_fixed_size(link_controllers, |
917 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, | 922 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, |
918 | struct GNUNET_TESTBED_ControllerLinkRequest, | 923 | struct GNUNET_TESTBED_ControllerLinkRequest, |
919 | NULL), | 924 | NULL), |
920 | GNUNET_MQ_hd_var_size (remote_overlay_connect, | 925 | GNUNET_MQ_hd_var_size(remote_overlay_connect, |
921 | GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT, | 926 | GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT, |
922 | struct GNUNET_TESTBED_RemoteOverlayConnectMessage, | 927 | struct GNUNET_TESTBED_RemoteOverlayConnectMessage, |
923 | NULL), | 928 | NULL), |
924 | GNUNET_MQ_hd_fixed_size (overlay_connect, | 929 | GNUNET_MQ_hd_fixed_size(overlay_connect, |
925 | GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT, | 930 | GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT, |
926 | struct GNUNET_TESTBED_OverlayConnectMessage, | 931 | struct GNUNET_TESTBED_OverlayConnectMessage, |
927 | NULL), | 932 | NULL), |
928 | GNUNET_MQ_hd_var_size (peer_create, | 933 | GNUNET_MQ_hd_var_size(peer_create, |
929 | GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER, | 934 | GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER, |
930 | struct GNUNET_TESTBED_PeerCreateMessage, | 935 | struct GNUNET_TESTBED_PeerCreateMessage, |
931 | NULL), | 936 | NULL), |
932 | GNUNET_MQ_hd_fixed_size (peer_destroy, | 937 | GNUNET_MQ_hd_fixed_size(peer_destroy, |
933 | GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER, | 938 | GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER, |
934 | struct GNUNET_TESTBED_PeerDestroyMessage, | 939 | struct GNUNET_TESTBED_PeerDestroyMessage, |
935 | NULL), | 940 | NULL), |
936 | GNUNET_MQ_hd_fixed_size (peer_start, | 941 | GNUNET_MQ_hd_fixed_size(peer_start, |
937 | GNUNET_MESSAGE_TYPE_TESTBED_START_PEER, | 942 | GNUNET_MESSAGE_TYPE_TESTBED_START_PEER, |
938 | struct GNUNET_TESTBED_PeerStartMessage, | 943 | struct GNUNET_TESTBED_PeerStartMessage, |
939 | NULL), | 944 | NULL), |
940 | GNUNET_MQ_hd_fixed_size (peer_stop, | 945 | GNUNET_MQ_hd_fixed_size(peer_stop, |
941 | GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER, | 946 | GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER, |
942 | struct GNUNET_TESTBED_PeerStopMessage, | 947 | struct GNUNET_TESTBED_PeerStopMessage, |
943 | NULL), | 948 | NULL), |
944 | GNUNET_MQ_hd_fixed_size (peer_get_config, | 949 | GNUNET_MQ_hd_fixed_size(peer_get_config, |
945 | GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION, | 950 | GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION, |
946 | struct GNUNET_TESTBED_PeerGetConfigurationMessage, | 951 | struct GNUNET_TESTBED_PeerGetConfigurationMessage, |
947 | NULL), | 952 | NULL), |
948 | GNUNET_MQ_hd_var_size (manage_peer_service, | 953 | GNUNET_MQ_hd_var_size(manage_peer_service, |
949 | GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE, | 954 | GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE, |
950 | struct GNUNET_TESTBED_ManagePeerServiceMessage, | 955 | struct GNUNET_TESTBED_ManagePeerServiceMessage, |
951 | NULL), | 956 | NULL), |
952 | GNUNET_MQ_hd_fixed_size (shutdown_peers, | 957 | GNUNET_MQ_hd_fixed_size(shutdown_peers, |
953 | GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS, | 958 | GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS, |
954 | struct GNUNET_TESTBED_ShutdownPeersMessage, | 959 | struct GNUNET_TESTBED_ShutdownPeersMessage, |
955 | NULL), | 960 | NULL), |
956 | GNUNET_MQ_hd_var_size (peer_reconfigure, | 961 | GNUNET_MQ_hd_var_size(peer_reconfigure, |
957 | GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER, | 962 | GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER, |
958 | struct GNUNET_TESTBED_PeerReconfigureMessage, | 963 | struct GNUNET_TESTBED_PeerReconfigureMessage, |
959 | NULL), | 964 | NULL), |
960 | GNUNET_MQ_hd_var_size (barrier_init, | 965 | GNUNET_MQ_hd_var_size(barrier_init, |
961 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT, | 966 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT, |
962 | struct GNUNET_TESTBED_BarrierInit, | 967 | struct GNUNET_TESTBED_BarrierInit, |
963 | NULL), | 968 | NULL), |
964 | GNUNET_MQ_hd_var_size (barrier_cancel, | 969 | GNUNET_MQ_hd_var_size(barrier_cancel, |
965 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL, | 970 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL, |
966 | struct GNUNET_TESTBED_BarrierCancel, | 971 | struct GNUNET_TESTBED_BarrierCancel, |
967 | NULL), | 972 | NULL), |
968 | GNUNET_MQ_hd_var_size (barrier_status, | 973 | GNUNET_MQ_hd_var_size(barrier_status, |
969 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, | 974 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, |
970 | struct GNUNET_TESTBED_BarrierStatusMsg, | 975 | struct GNUNET_TESTBED_BarrierStatusMsg, |
971 | NULL), | 976 | NULL), |
972 | GNUNET_MQ_handler_end ()); | 977 | GNUNET_MQ_handler_end()); |
973 | 978 | ||
974 | 979 | ||
975 | /* end of gnunet-service-testbed.c */ | 980 | /* end of gnunet-service-testbed.c */ |
diff --git a/src/testbed/gnunet-service-testbed.h b/src/testbed/gnunet-service-testbed.h index 5e835392b..d68f8a3e4 100644 --- a/src/testbed/gnunet-service-testbed.h +++ b/src/testbed/gnunet-service-testbed.h | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2013 GNUnet e.V. | 3 | Copyright (C) 2008--2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/gnunet-service-testbed.h | 22 | * @file testbed/gnunet-service-testbed.h |
@@ -41,14 +41,14 @@ | |||
41 | /** | 41 | /** |
42 | * Generic logging | 42 | * Generic logging |
43 | */ | 43 | */ |
44 | #define LOG(kind,...) \ | 44 | #define LOG(kind, ...) \ |
45 | GNUNET_log (kind, __VA_ARGS__) | 45 | GNUNET_log(kind, __VA_ARGS__) |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Debug logging | 48 | * Debug logging |
49 | */ | 49 | */ |
50 | #define LOG_DEBUG(...) \ | 50 | #define LOG_DEBUG(...) \ |
51 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 51 | LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * By how much should the arrays lists grow | 54 | * By how much should the arrays lists grow |
@@ -59,8 +59,7 @@ | |||
59 | /** | 59 | /** |
60 | * A routing entry | 60 | * A routing entry |
61 | */ | 61 | */ |
62 | struct Route | 62 | struct Route { |
63 | { | ||
64 | /** | 63 | /** |
65 | * destination host | 64 | * destination host |
66 | */ | 65 | */ |
@@ -76,8 +75,7 @@ struct Route | |||
76 | /** | 75 | /** |
77 | * Context information for operations forwarded to subcontrollers | 76 | * Context information for operations forwarded to subcontrollers |
78 | */ | 77 | */ |
79 | struct ForwardedOperationContext | 78 | struct ForwardedOperationContext { |
80 | { | ||
81 | /** | 79 | /** |
82 | * The next pointer for DLL | 80 | * The next pointer for DLL |
83 | */ | 81 | */ |
@@ -117,15 +115,13 @@ struct ForwardedOperationContext | |||
117 | * The type of the operation which is forwarded | 115 | * The type of the operation which is forwarded |
118 | */ | 116 | */ |
119 | enum OperationType type; | 117 | enum OperationType type; |
120 | |||
121 | }; | 118 | }; |
122 | 119 | ||
123 | 120 | ||
124 | /** | 121 | /** |
125 | * A DLL of host registrations to be made | 122 | * A DLL of host registrations to be made |
126 | */ | 123 | */ |
127 | struct HostRegistration | 124 | struct HostRegistration { |
128 | { | ||
129 | /** | 125 | /** |
130 | * next registration in the DLL | 126 | * next registration in the DLL |
131 | */ | 127 | */ |
@@ -156,8 +152,7 @@ struct HostRegistration | |||
156 | /** | 152 | /** |
157 | * Context information used while linking controllers | 153 | * Context information used while linking controllers |
158 | */ | 154 | */ |
159 | struct LinkControllersContext | 155 | struct LinkControllersContext { |
160 | { | ||
161 | /** | 156 | /** |
162 | * The client which initiated the link controller operation | 157 | * The client which initiated the link controller operation |
163 | */ | 158 | */ |
@@ -167,20 +162,15 @@ struct LinkControllersContext | |||
167 | * The ID of the operation | 162 | * The ID of the operation |
168 | */ | 163 | */ |
169 | uint64_t operation_id; | 164 | uint64_t operation_id; |
170 | |||
171 | }; | 165 | }; |
172 | 166 | ||
173 | 167 | ||
174 | /** | 168 | /** |
175 | * A peer | 169 | * A peer |
176 | */ | 170 | */ |
177 | struct Peer | 171 | struct Peer { |
178 | { | 172 | union { |
179 | 173 | struct { | |
180 | union | ||
181 | { | ||
182 | struct | ||
183 | { | ||
184 | /** | 174 | /** |
185 | * The peer handle from testing API | 175 | * The peer handle from testing API |
186 | */ | 176 | */ |
@@ -196,11 +186,9 @@ struct Peer | |||
196 | * Is the peer running | 186 | * Is the peer running |
197 | */ | 187 | */ |
198 | int is_running; | 188 | int is_running; |
199 | |||
200 | } local; | 189 | } local; |
201 | 190 | ||
202 | struct | 191 | struct { |
203 | { | ||
204 | /** | 192 | /** |
205 | * The slave this peer is started through | 193 | * The slave this peer is started through |
206 | */ | 194 | */ |
@@ -210,9 +198,7 @@ struct Peer | |||
210 | * The id of the remote host this peer is running on | 198 | * The id of the remote host this peer is running on |
211 | */ | 199 | */ |
212 | uint32_t remote_host_id; | 200 | uint32_t remote_host_id; |
213 | |||
214 | } remote; | 201 | } remote; |
215 | |||
216 | } details; | 202 | } details; |
217 | 203 | ||
218 | /** | 204 | /** |
@@ -242,15 +228,13 @@ struct Peer | |||
242 | * the peer | 228 | * the peer |
243 | */ | 229 | */ |
244 | uint32_t destroy_flag; | 230 | uint32_t destroy_flag; |
245 | |||
246 | }; | 231 | }; |
247 | 232 | ||
248 | 233 | ||
249 | /** | 234 | /** |
250 | * The main context information associated with the client which started us | 235 | * The main context information associated with the client which started us |
251 | */ | 236 | */ |
252 | struct Context | 237 | struct Context { |
253 | { | ||
254 | /** | 238 | /** |
255 | * The client handle associated with this context | 239 | * The client handle associated with this context |
256 | */ | 240 | */ |
@@ -276,8 +260,7 @@ struct Context | |||
276 | /** | 260 | /** |
277 | * The structure for identifying a shared service | 261 | * The structure for identifying a shared service |
278 | */ | 262 | */ |
279 | struct SharedService | 263 | struct SharedService { |
280 | { | ||
281 | /** | 264 | /** |
282 | * The name of the shared service | 265 | * The name of the shared service |
283 | */ | 266 | */ |
@@ -302,8 +285,7 @@ struct RegisteredHostContext; | |||
302 | * Context information to used during operations which forward the overlay | 285 | * Context information to used during operations which forward the overlay |
303 | * connect message | 286 | * connect message |
304 | */ | 287 | */ |
305 | struct ForwardedOverlayConnectContext | 288 | struct ForwardedOverlayConnectContext { |
306 | { | ||
307 | /** | 289 | /** |
308 | * next ForwardedOverlayConnectContext in the DLL | 290 | * next ForwardedOverlayConnectContext in the DLL |
309 | */ | 291 | */ |
@@ -355,8 +337,7 @@ struct ForwardedOverlayConnectContext | |||
355 | * This context information will be created for each host that is registered at | 337 | * This context information will be created for each host that is registered at |
356 | * slave controllers during overlay connects. | 338 | * slave controllers during overlay connects. |
357 | */ | 339 | */ |
358 | struct RegisteredHostContext | 340 | struct RegisteredHostContext { |
359 | { | ||
360 | /** | 341 | /** |
361 | * The host which is being registered | 342 | * The host which is being registered |
362 | */ | 343 | */ |
@@ -380,9 +361,7 @@ struct RegisteredHostContext | |||
380 | /** | 361 | /** |
381 | * Enumeration of states for this context | 362 | * Enumeration of states for this context |
382 | */ | 363 | */ |
383 | enum RHCState | 364 | enum RHCState { |
384 | { | ||
385 | |||
386 | /** | 365 | /** |
387 | * The initial state | 366 | * The initial state |
388 | */ | 367 | */ |
@@ -393,15 +372,13 @@ struct RegisteredHostContext | |||
393 | */ | 372 | */ |
394 | RHC_DONE | 373 | RHC_DONE |
395 | } state; | 374 | } state; |
396 | |||
397 | }; | 375 | }; |
398 | 376 | ||
399 | 377 | ||
400 | /** | 378 | /** |
401 | * Context data for #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS handler | 379 | * Context data for #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS handler |
402 | */ | 380 | */ |
403 | struct HandlerContext_ShutdownPeers | 381 | struct HandlerContext_ShutdownPeers { |
404 | { | ||
405 | /** | 382 | /** |
406 | * The number of slave we expect to hear from since we forwarded the | 383 | * The number of slave we expect to hear from since we forwarded the |
407 | * #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS message to them | 384 | * #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS message to them |
@@ -480,13 +457,13 @@ extern char *GST_stats_dir; | |||
480 | * Condition to check if host id is valid | 457 | * Condition to check if host id is valid |
481 | */ | 458 | */ |
482 | #define VALID_HOST_ID(id) \ | 459 | #define VALID_HOST_ID(id) \ |
483 | ( ((id) < GST_host_list_size) && (NULL != GST_host_list[id]) ) | 460 | (((id) < GST_host_list_size) && (NULL != GST_host_list[id])) |
484 | 461 | ||
485 | /** | 462 | /** |
486 | * Condition to check if peer id is valid | 463 | * Condition to check if peer id is valid |
487 | */ | 464 | */ |
488 | #define VALID_PEER_ID(id) \ | 465 | #define VALID_PEER_ID(id) \ |
489 | ( ((id) < GST_peer_list_size) && (NULL != GST_peer_list[id]) ) | 466 | (((id) < GST_peer_list_size) && (NULL != GST_peer_list[id])) |
490 | 467 | ||
491 | 468 | ||
492 | /** | 469 | /** |
@@ -502,15 +479,15 @@ extern char *GST_stats_dir; | |||
502 | */ | 479 | */ |
503 | #define GST_array_grow_large_enough(ptr, size, accommodate_size) \ | 480 | #define GST_array_grow_large_enough(ptr, size, accommodate_size) \ |
504 | do \ | 481 | do \ |
505 | { \ | 482 | { \ |
506 | unsigned int growth_size; \ | 483 | unsigned int growth_size; \ |
507 | GNUNET_assert (size <= accommodate_size); \ | 484 | GNUNET_assert(size <= accommodate_size); \ |
508 | growth_size = size; \ | 485 | growth_size = size; \ |
509 | while (growth_size <= accommodate_size) \ | 486 | while (growth_size <= accommodate_size) \ |
510 | growth_size += LIST_GROW_STEP; \ | 487 | growth_size += LIST_GROW_STEP; \ |
511 | GNUNET_array_grow (ptr, size, growth_size); \ | 488 | GNUNET_array_grow (ptr, size, growth_size); \ |
512 | GNUNET_assert (size > accommodate_size); \ | 489 | GNUNET_assert(size > accommodate_size); \ |
513 | } while (0) | 490 | } while (0) |
514 | 491 | ||
515 | 492 | ||
516 | /** | 493 | /** |
@@ -519,14 +496,14 @@ extern char *GST_stats_dir; | |||
519 | * @param peer the peer structure to destroy | 496 | * @param peer the peer structure to destroy |
520 | */ | 497 | */ |
521 | void | 498 | void |
522 | GST_destroy_peer (struct Peer *peer); | 499 | GST_destroy_peer(struct Peer *peer); |
523 | 500 | ||
524 | 501 | ||
525 | /** | 502 | /** |
526 | * Stops and destroys all peers | 503 | * Stops and destroys all peers |
527 | */ | 504 | */ |
528 | void | 505 | void |
529 | GST_destroy_peers (void); | 506 | GST_destroy_peers(void); |
530 | 507 | ||
531 | 508 | ||
532 | /** | 509 | /** |
@@ -538,7 +515,7 @@ GST_destroy_peers (void); | |||
538 | * is found | 515 | * is found |
539 | */ | 516 | */ |
540 | struct Route * | 517 | struct Route * |
541 | GST_find_dest_route (uint32_t host_id); | 518 | GST_find_dest_route(uint32_t host_id); |
542 | 519 | ||
543 | 520 | ||
544 | /** | 521 | /** |
@@ -548,8 +525,8 @@ GST_find_dest_route (uint32_t host_id); | |||
548 | * @param msg the actual message | 525 | * @param msg the actual message |
549 | */ | 526 | */ |
550 | void | 527 | void |
551 | handle_overlay_connect (void *cls, | 528 | handle_overlay_connect(void *cls, |
552 | const struct GNUNET_TESTBED_OverlayConnectMessage *msg); | 529 | const struct GNUNET_TESTBED_OverlayConnectMessage *msg); |
553 | 530 | ||
554 | 531 | ||
555 | /** | 532 | /** |
@@ -562,9 +539,9 @@ handle_overlay_connect (void *cls, | |||
562 | * @param host the host which has to be registered | 539 | * @param host the host which has to be registered |
563 | */ | 540 | */ |
564 | void | 541 | void |
565 | GST_queue_host_registration (struct Slave *slave, | 542 | GST_queue_host_registration(struct Slave *slave, |
566 | GNUNET_TESTBED_HostRegistrationCompletion cb, | 543 | GNUNET_TESTBED_HostRegistrationCompletion cb, |
567 | void *cb_cls, struct GNUNET_TESTBED_Host *host); | 544 | void *cb_cls, struct GNUNET_TESTBED_Host *host); |
568 | 545 | ||
569 | 546 | ||
570 | /** | 547 | /** |
@@ -574,8 +551,8 @@ GST_queue_host_registration (struct Slave *slave, | |||
574 | * @param msg the message to relay | 551 | * @param msg the message to relay |
575 | */ | 552 | */ |
576 | void | 553 | void |
577 | GST_forwarded_operation_reply_relay (void *cls, | 554 | GST_forwarded_operation_reply_relay(void *cls, |
578 | const struct GNUNET_MessageHeader *msg); | 555 | const struct GNUNET_MessageHeader *msg); |
579 | 556 | ||
580 | 557 | ||
581 | /** | 558 | /** |
@@ -585,14 +562,14 @@ GST_forwarded_operation_reply_relay (void *cls, | |||
585 | * @param tc the task context from scheduler | 562 | * @param tc the task context from scheduler |
586 | */ | 563 | */ |
587 | void | 564 | void |
588 | GST_forwarded_operation_timeout (void *cls); | 565 | GST_forwarded_operation_timeout(void *cls); |
589 | 566 | ||
590 | 567 | ||
591 | /** | 568 | /** |
592 | * Clears the forwarded operations queue | 569 | * Clears the forwarded operations queue |
593 | */ | 570 | */ |
594 | void | 571 | void |
595 | GST_clear_fopcq (void); | 572 | GST_clear_fopcq(void); |
596 | 573 | ||
597 | 574 | ||
598 | /** | 575 | /** |
@@ -603,9 +580,9 @@ GST_clear_fopcq (void); | |||
603 | * @param emsg the error message; can be NULL | 580 | * @param emsg the error message; can be NULL |
604 | */ | 581 | */ |
605 | void | 582 | void |
606 | GST_send_operation_fail_msg (struct GNUNET_SERVICE_Client *client, | 583 | GST_send_operation_fail_msg(struct GNUNET_SERVICE_Client *client, |
607 | uint64_t operation_id, | 584 | uint64_t operation_id, |
608 | const char *emsg); | 585 | const char *emsg); |
609 | 586 | ||
610 | 587 | ||
611 | /** | 588 | /** |
@@ -614,7 +591,7 @@ GST_send_operation_fail_msg (struct GNUNET_SERVICE_Client *client, | |||
614 | * @param client the client that disconnected | 591 | * @param client the client that disconnected |
615 | */ | 592 | */ |
616 | void | 593 | void |
617 | GST_notify_client_disconnect_oc (struct GNUNET_SERVICE_Client *client); | 594 | GST_notify_client_disconnect_oc(struct GNUNET_SERVICE_Client *client); |
618 | 595 | ||
619 | 596 | ||
620 | /** | 597 | /** |
@@ -623,7 +600,7 @@ GST_notify_client_disconnect_oc (struct GNUNET_SERVICE_Client *client); | |||
623 | * @param client the client that disconnected | 600 | * @param client the client that disconnected |
624 | */ | 601 | */ |
625 | void | 602 | void |
626 | GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client); | 603 | GST_notify_client_disconnect_peers(struct GNUNET_SERVICE_Client *client); |
627 | 604 | ||
628 | 605 | ||
629 | /** | 606 | /** |
@@ -633,8 +610,8 @@ GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client); | |||
633 | * @param operation_id the id of the operation which was successful | 610 | * @param operation_id the id of the operation which was successful |
634 | */ | 611 | */ |
635 | void | 612 | void |
636 | GST_send_operation_success_msg (struct GNUNET_SERVICE_Client *client, | 613 | GST_send_operation_success_msg(struct GNUNET_SERVICE_Client *client, |
637 | uint64_t operation_id); | 614 | uint64_t operation_id); |
638 | 615 | ||
639 | 616 | ||
640 | /** | 617 | /** |
@@ -645,8 +622,8 @@ GST_send_operation_success_msg (struct GNUNET_SERVICE_Client *client, | |||
645 | * @return #GNUNET_OK if @a msg is well-formed | 622 | * @return #GNUNET_OK if @a msg is well-formed |
646 | */ | 623 | */ |
647 | int | 624 | int |
648 | check_remote_overlay_connect (void *cls, | 625 | check_remote_overlay_connect(void *cls, |
649 | const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg); | 626 | const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg); |
650 | 627 | ||
651 | 628 | ||
652 | /** | 629 | /** |
@@ -656,8 +633,8 @@ check_remote_overlay_connect (void *cls, | |||
656 | * @param msg the actual message | 633 | * @param msg the actual message |
657 | */ | 634 | */ |
658 | void | 635 | void |
659 | handle_remote_overlay_connect (void *cls, | 636 | handle_remote_overlay_connect(void *cls, |
660 | const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg); | 637 | const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg); |
661 | 638 | ||
662 | 639 | ||
663 | /** | 640 | /** |
@@ -668,8 +645,8 @@ handle_remote_overlay_connect (void *cls, | |||
668 | * @return #GNUNET_OK if @a msg is well-formed | 645 | * @return #GNUNET_OK if @a msg is well-formed |
669 | */ | 646 | */ |
670 | int | 647 | int |
671 | check_peer_create (void *cls, | 648 | check_peer_create(void *cls, |
672 | const struct GNUNET_TESTBED_PeerCreateMessage *msg); | 649 | const struct GNUNET_TESTBED_PeerCreateMessage *msg); |
673 | 650 | ||
674 | 651 | ||
675 | /** | 652 | /** |
@@ -679,8 +656,8 @@ check_peer_create (void *cls, | |||
679 | * @param message the actual message | 656 | * @param message the actual message |
680 | */ | 657 | */ |
681 | void | 658 | void |
682 | handle_peer_create (void *cls, | 659 | handle_peer_create(void *cls, |
683 | const struct GNUNET_TESTBED_PeerCreateMessage *msg); | 660 | const struct GNUNET_TESTBED_PeerCreateMessage *msg); |
684 | 661 | ||
685 | 662 | ||
686 | /** | 663 | /** |
@@ -690,8 +667,8 @@ handle_peer_create (void *cls, | |||
690 | * @param msg the actual message | 667 | * @param msg the actual message |
691 | */ | 668 | */ |
692 | void | 669 | void |
693 | handle_peer_destroy (void *cls, | 670 | handle_peer_destroy(void *cls, |
694 | const struct GNUNET_TESTBED_PeerDestroyMessage *msg); | 671 | const struct GNUNET_TESTBED_PeerDestroyMessage *msg); |
695 | 672 | ||
696 | 673 | ||
697 | /** | 674 | /** |
@@ -701,8 +678,8 @@ handle_peer_destroy (void *cls, | |||
701 | * @param msg the actual message | 678 | * @param msg the actual message |
702 | */ | 679 | */ |
703 | void | 680 | void |
704 | handle_peer_start (void *cls, | 681 | handle_peer_start(void *cls, |
705 | const struct GNUNET_TESTBED_PeerStartMessage *msg); | 682 | const struct GNUNET_TESTBED_PeerStartMessage *msg); |
706 | 683 | ||
707 | 684 | ||
708 | /** | 685 | /** |
@@ -712,8 +689,8 @@ handle_peer_start (void *cls, | |||
712 | * @param message the actual message | 689 | * @param message the actual message |
713 | */ | 690 | */ |
714 | void | 691 | void |
715 | handle_peer_stop (void *cls, | 692 | handle_peer_stop(void *cls, |
716 | const struct GNUNET_TESTBED_PeerStopMessage *msg); | 693 | const struct GNUNET_TESTBED_PeerStopMessage *msg); |
717 | 694 | ||
718 | 695 | ||
719 | /** | 696 | /** |
@@ -723,8 +700,8 @@ handle_peer_stop (void *cls, | |||
723 | * @param msg the actual message | 700 | * @param msg the actual message |
724 | */ | 701 | */ |
725 | void | 702 | void |
726 | handle_peer_get_config (void *cls, | 703 | handle_peer_get_config(void *cls, |
727 | const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg); | 704 | const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg); |
728 | 705 | ||
729 | 706 | ||
730 | /** | 707 | /** |
@@ -734,8 +711,8 @@ handle_peer_get_config (void *cls, | |||
734 | * @param msg the actual message | 711 | * @param msg the actual message |
735 | */ | 712 | */ |
736 | void | 713 | void |
737 | handle_shutdown_peers (void *cls, | 714 | handle_shutdown_peers(void *cls, |
738 | const struct GNUNET_TESTBED_ShutdownPeersMessage *msg); | 715 | const struct GNUNET_TESTBED_ShutdownPeersMessage *msg); |
739 | 716 | ||
740 | 717 | ||
741 | /** | 718 | /** |
@@ -746,8 +723,8 @@ handle_shutdown_peers (void *cls, | |||
746 | * @return #GNUNET_OK if @a msg is well-formed | 723 | * @return #GNUNET_OK if @a msg is well-formed |
747 | */ | 724 | */ |
748 | int | 725 | int |
749 | check_manage_peer_service (void *cls, | 726 | check_manage_peer_service(void *cls, |
750 | const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg); | 727 | const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg); |
751 | 728 | ||
752 | 729 | ||
753 | /** | 730 | /** |
@@ -757,8 +734,8 @@ check_manage_peer_service (void *cls, | |||
757 | * @param msg the actual message | 734 | * @param msg the actual message |
758 | */ | 735 | */ |
759 | void | 736 | void |
760 | handle_manage_peer_service (void *cls, | 737 | handle_manage_peer_service(void *cls, |
761 | const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg); | 738 | const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg); |
762 | 739 | ||
763 | 740 | ||
764 | 741 | ||
@@ -771,8 +748,8 @@ handle_manage_peer_service (void *cls, | |||
771 | * @return #GNUNET_OK if @a msg is well-formed | 748 | * @return #GNUNET_OK if @a msg is well-formed |
772 | */ | 749 | */ |
773 | int | 750 | int |
774 | check_peer_reconfigure (void *cls, | 751 | check_peer_reconfigure(void *cls, |
775 | const struct GNUNET_TESTBED_PeerReconfigureMessage *msg); | 752 | const struct GNUNET_TESTBED_PeerReconfigureMessage *msg); |
776 | 753 | ||
777 | 754 | ||
778 | /** | 755 | /** |
@@ -784,29 +761,29 @@ check_peer_reconfigure (void *cls, | |||
784 | * @param msg the actual message | 761 | * @param msg the actual message |
785 | */ | 762 | */ |
786 | void | 763 | void |
787 | handle_peer_reconfigure (void *cls, | 764 | handle_peer_reconfigure(void *cls, |
788 | const struct GNUNET_TESTBED_PeerReconfigureMessage *msg); | 765 | const struct GNUNET_TESTBED_PeerReconfigureMessage *msg); |
789 | 766 | ||
790 | 767 | ||
791 | /** | 768 | /** |
792 | * Frees the ManageServiceContext queue | 769 | * Frees the ManageServiceContext queue |
793 | */ | 770 | */ |
794 | void | 771 | void |
795 | GST_free_mctxq (void); | 772 | GST_free_mctxq(void); |
796 | 773 | ||
797 | 774 | ||
798 | /** | 775 | /** |
799 | * Cleans up the queue used for forwarding link controllers requests | 776 | * Cleans up the queue used for forwarding link controllers requests |
800 | */ | 777 | */ |
801 | void | 778 | void |
802 | GST_free_lcf (void); | 779 | GST_free_lcf(void); |
803 | 780 | ||
804 | 781 | ||
805 | /** | 782 | /** |
806 | * Cleans up the route list | 783 | * Cleans up the route list |
807 | */ | 784 | */ |
808 | void | 785 | void |
809 | GST_route_list_clear (void); | 786 | GST_route_list_clear(void); |
810 | 787 | ||
811 | 788 | ||
812 | /** | 789 | /** |
@@ -815,7 +792,7 @@ GST_route_list_clear (void); | |||
815 | * @param rhc the RegisteredHostContext | 792 | * @param rhc the RegisteredHostContext |
816 | */ | 793 | */ |
817 | void | 794 | void |
818 | GST_process_next_focc (struct RegisteredHostContext *rhc); | 795 | GST_process_next_focc(struct RegisteredHostContext *rhc); |
819 | 796 | ||
820 | 797 | ||
821 | /** | 798 | /** |
@@ -824,28 +801,28 @@ GST_process_next_focc (struct RegisteredHostContext *rhc); | |||
824 | * @param focc the ForwardedOverlayConnectContext to cleanup | 801 | * @param focc the ForwardedOverlayConnectContext to cleanup |
825 | */ | 802 | */ |
826 | void | 803 | void |
827 | GST_cleanup_focc (struct ForwardedOverlayConnectContext *focc); | 804 | GST_cleanup_focc(struct ForwardedOverlayConnectContext *focc); |
828 | 805 | ||
829 | 806 | ||
830 | /** | 807 | /** |
831 | * Clears all pending overlay connect contexts in queue | 808 | * Clears all pending overlay connect contexts in queue |
832 | */ | 809 | */ |
833 | void | 810 | void |
834 | GST_free_occq (void); | 811 | GST_free_occq(void); |
835 | 812 | ||
836 | 813 | ||
837 | /** | 814 | /** |
838 | * Clears all pending remote overlay connect contexts in queue | 815 | * Clears all pending remote overlay connect contexts in queue |
839 | */ | 816 | */ |
840 | void | 817 | void |
841 | GST_free_roccq (void); | 818 | GST_free_roccq(void); |
842 | 819 | ||
843 | 820 | ||
844 | /** | 821 | /** |
845 | * Cleans up the Peer reconfigure context list | 822 | * Cleans up the Peer reconfigure context list |
846 | */ | 823 | */ |
847 | void | 824 | void |
848 | GST_free_prcq (void); | 825 | GST_free_prcq(void); |
849 | 826 | ||
850 | 827 | ||
851 | /** | 828 | /** |
@@ -854,14 +831,14 @@ GST_free_prcq (void); | |||
854 | * @param size the size of the cache | 831 | * @param size the size of the cache |
855 | */ | 832 | */ |
856 | void | 833 | void |
857 | GST_cache_init (unsigned int size); | 834 | GST_cache_init(unsigned int size); |
858 | 835 | ||
859 | 836 | ||
860 | /** | 837 | /** |
861 | * Clear cache | 838 | * Clear cache |
862 | */ | 839 | */ |
863 | void | 840 | void |
864 | GST_cache_clear (void); | 841 | GST_cache_clear(void); |
865 | 842 | ||
866 | 843 | ||
867 | /** | 844 | /** |
@@ -871,7 +848,7 @@ GST_cache_clear (void); | |||
871 | * @return the HELLO message; NULL if not found | 848 | * @return the HELLO message; NULL if not found |
872 | */ | 849 | */ |
873 | const struct GNUNET_MessageHeader * | 850 | const struct GNUNET_MessageHeader * |
874 | GST_cache_lookup_hello (const unsigned int peer_id); | 851 | GST_cache_lookup_hello(const unsigned int peer_id); |
875 | 852 | ||
876 | 853 | ||
877 | /** | 854 | /** |
@@ -882,8 +859,8 @@ GST_cache_lookup_hello (const unsigned int peer_id); | |||
882 | * @param hello the HELLO message | 859 | * @param hello the HELLO message |
883 | */ | 860 | */ |
884 | void | 861 | void |
885 | GST_cache_add_hello (const unsigned int peer_id, | 862 | GST_cache_add_hello(const unsigned int peer_id, |
886 | const struct GNUNET_MessageHeader *hello); | 863 | const struct GNUNET_MessageHeader *hello); |
887 | 864 | ||
888 | 865 | ||
889 | /** | 866 | /** |
@@ -892,13 +869,13 @@ GST_cache_add_hello (const unsigned int peer_id, | |||
892 | * generated from the hostname and the process's PID. | 869 | * generated from the hostname and the process's PID. |
893 | */ | 870 | */ |
894 | void | 871 | void |
895 | GST_stats_init (const struct GNUNET_CONFIGURATION_Handle *cfg); | 872 | GST_stats_init(const struct GNUNET_CONFIGURATION_Handle *cfg); |
896 | 873 | ||
897 | 874 | ||
898 | /** | 875 | /** |
899 | * Shutdown the status calls module. | 876 | * Shutdown the status calls module. |
900 | */ | 877 | */ |
901 | void | 878 | void |
902 | GST_stats_destroy (void); | 879 | GST_stats_destroy(void); |
903 | 880 | ||
904 | /* End of gnunet-service-testbed.h */ | 881 | /* End of gnunet-service-testbed.h */ |
diff --git a/src/testbed/gnunet-service-testbed_barriers.c b/src/testbed/gnunet-service-testbed_barriers.c index dbcf5ed69..c2cb9a99c 100644 --- a/src/testbed/gnunet-service-testbed_barriers.c +++ b/src/testbed/gnunet-service-testbed_barriers.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2016 GNUnet e.V. | 3 | Copyright (C) 2008--2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/gnunet-service-testbed_barriers.c | 22 | * @file testbed/gnunet-service-testbed_barriers.c |
@@ -33,7 +33,7 @@ | |||
33 | * timeout for outgoing message transmissions in seconds | 33 | * timeout for outgoing message transmissions in seconds |
34 | */ | 34 | */ |
35 | #define MESSAGE_SEND_TIMEOUT(s) \ | 35 | #define MESSAGE_SEND_TIMEOUT(s) \ |
36 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, s) | 36 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, s) |
37 | 37 | ||
38 | 38 | ||
39 | /** | 39 | /** |
@@ -50,8 +50,8 @@ | |||
50 | /** | 50 | /** |
51 | * Logging shorthand | 51 | * Logging shorthand |
52 | */ | 52 | */ |
53 | #define LOG(kind,...) \ | 53 | #define LOG(kind, ...) \ |
54 | GNUNET_log_from (kind, "testbed-barriers", __VA_ARGS__) | 54 | GNUNET_log_from(kind, "testbed-barriers", __VA_ARGS__) |
55 | 55 | ||
56 | 56 | ||
57 | /** | 57 | /** |
@@ -63,8 +63,7 @@ struct Barrier; | |||
63 | /** | 63 | /** |
64 | * Context to be associated with each client | 64 | * Context to be associated with each client |
65 | */ | 65 | */ |
66 | struct ClientCtx | 66 | struct ClientCtx { |
67 | { | ||
68 | /** | 67 | /** |
69 | * The barrier this client is waiting for | 68 | * The barrier this client is waiting for |
70 | */ | 69 | */ |
@@ -84,15 +83,13 @@ struct ClientCtx | |||
84 | * The client handle | 83 | * The client handle |
85 | */ | 84 | */ |
86 | struct GNUNET_SERVICE_Client *client; | 85 | struct GNUNET_SERVICE_Client *client; |
87 | |||
88 | }; | 86 | }; |
89 | 87 | ||
90 | 88 | ||
91 | /** | 89 | /** |
92 | * Wrapper around Barrier handle | 90 | * Wrapper around Barrier handle |
93 | */ | 91 | */ |
94 | struct WBarrier | 92 | struct WBarrier { |
95 | { | ||
96 | /** | 93 | /** |
97 | * DLL next pointer | 94 | * DLL next pointer |
98 | */ | 95 | */ |
@@ -128,8 +125,7 @@ struct WBarrier | |||
128 | /** | 125 | /** |
129 | * Barrier | 126 | * Barrier |
130 | */ | 127 | */ |
131 | struct Barrier | 128 | struct Barrier { |
132 | { | ||
133 | /** | 129 | /** |
134 | * The hashcode of the barrier name | 130 | * The hashcode of the barrier name |
135 | */ | 131 | */ |
@@ -204,7 +200,6 @@ struct Barrier | |||
204 | * Quorum percentage to be reached | 200 | * Quorum percentage to be reached |
205 | */ | 201 | */ |
206 | uint8_t quorum; | 202 | uint8_t quorum; |
207 | |||
208 | }; | 203 | }; |
209 | 204 | ||
210 | 205 | ||
@@ -226,23 +221,23 @@ static struct GNUNET_SERVICE_Handle *ctx; | |||
226 | * @param barrier the barrier handle | 221 | * @param barrier the barrier handle |
227 | */ | 222 | */ |
228 | static void | 223 | static void |
229 | remove_barrier (struct Barrier *barrier) | 224 | remove_barrier(struct Barrier *barrier) |
230 | { | 225 | { |
231 | struct ClientCtx *ctx; | 226 | struct ClientCtx *ctx; |
232 | 227 | ||
233 | GNUNET_assert (GNUNET_YES == | 228 | GNUNET_assert(GNUNET_YES == |
234 | GNUNET_CONTAINER_multihashmap_remove (barrier_map, | 229 | GNUNET_CONTAINER_multihashmap_remove(barrier_map, |
235 | &barrier->hash, | 230 | &barrier->hash, |
236 | barrier)); | 231 | barrier)); |
237 | while (NULL != (ctx = barrier->head)) | 232 | while (NULL != (ctx = barrier->head)) |
238 | { | 233 | { |
239 | GNUNET_CONTAINER_DLL_remove (barrier->head, | 234 | GNUNET_CONTAINER_DLL_remove(barrier->head, |
240 | barrier->tail, | 235 | barrier->tail, |
241 | ctx); | 236 | ctx); |
242 | ctx->barrier = NULL; | 237 | ctx->barrier = NULL; |
243 | } | 238 | } |
244 | GNUNET_free (barrier->name); | 239 | GNUNET_free(barrier->name); |
245 | GNUNET_free (barrier); | 240 | GNUNET_free(barrier); |
246 | } | 241 | } |
247 | 242 | ||
248 | 243 | ||
@@ -252,18 +247,18 @@ remove_barrier (struct Barrier *barrier) | |||
252 | * @param barrier the local barrier | 247 | * @param barrier the local barrier |
253 | */ | 248 | */ |
254 | static void | 249 | static void |
255 | cancel_wrappers (struct Barrier *barrier) | 250 | cancel_wrappers(struct Barrier *barrier) |
256 | { | 251 | { |
257 | struct WBarrier *wrapper; | 252 | struct WBarrier *wrapper; |
258 | 253 | ||
259 | while (NULL != (wrapper = barrier->whead)) | 254 | while (NULL != (wrapper = barrier->whead)) |
260 | { | 255 | { |
261 | GNUNET_TESTBED_barrier_cancel (wrapper->hbarrier); | 256 | GNUNET_TESTBED_barrier_cancel(wrapper->hbarrier); |
262 | GNUNET_CONTAINER_DLL_remove (barrier->whead, | 257 | GNUNET_CONTAINER_DLL_remove(barrier->whead, |
263 | barrier->wtail, | 258 | barrier->wtail, |
264 | wrapper); | 259 | wrapper); |
265 | GNUNET_free (wrapper); | 260 | GNUNET_free(wrapper); |
266 | } | 261 | } |
267 | } | 262 | } |
268 | 263 | ||
269 | 264 | ||
@@ -277,33 +272,33 @@ cancel_wrappers (struct Barrier *barrier) | |||
277 | * status=GNUNET_TESTBED_BARRIERSTATUS_ERROR | 272 | * status=GNUNET_TESTBED_BARRIERSTATUS_ERROR |
278 | */ | 273 | */ |
279 | static void | 274 | static void |
280 | send_client_status_msg (struct GNUNET_SERVICE_Client *client, | 275 | send_client_status_msg(struct GNUNET_SERVICE_Client *client, |
281 | const char *name, | 276 | const char *name, |
282 | enum GNUNET_TESTBED_BarrierStatus status, | 277 | enum GNUNET_TESTBED_BarrierStatus status, |
283 | const char *emsg) | 278 | const char *emsg) |
284 | { | 279 | { |
285 | struct GNUNET_MQ_Envelope *env; | 280 | struct GNUNET_MQ_Envelope *env; |
286 | struct GNUNET_TESTBED_BarrierStatusMsg *msg; | 281 | struct GNUNET_TESTBED_BarrierStatusMsg *msg; |
287 | size_t name_len; | 282 | size_t name_len; |
288 | size_t err_len; | 283 | size_t err_len; |
289 | 284 | ||
290 | GNUNET_assert ( (NULL == emsg) || | 285 | GNUNET_assert((NULL == emsg) || |
291 | (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status) ); | 286 | (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status)); |
292 | name_len = strlen (name) + 1; | 287 | name_len = strlen(name) + 1; |
293 | err_len = ((NULL == emsg) ? 0 : (strlen (emsg) + 1)); | 288 | err_len = ((NULL == emsg) ? 0 : (strlen(emsg) + 1)); |
294 | env = GNUNET_MQ_msg_extra (msg, | 289 | env = GNUNET_MQ_msg_extra(msg, |
295 | name_len + err_len, | 290 | name_len + err_len, |
296 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS); | 291 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS); |
297 | msg->status = htons (status); | 292 | msg->status = htons(status); |
298 | msg->name_len = htons ((uint16_t) name_len - 1); | 293 | msg->name_len = htons((uint16_t)name_len - 1); |
299 | GNUNET_memcpy (msg->data, | 294 | GNUNET_memcpy(msg->data, |
300 | name, | 295 | name, |
301 | name_len); | 296 | name_len); |
302 | GNUNET_memcpy (msg->data + name_len, | 297 | GNUNET_memcpy(msg->data + name_len, |
303 | emsg, | 298 | emsg, |
304 | err_len); | 299 | err_len); |
305 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 300 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), |
306 | env); | 301 | env); |
307 | } | 302 | } |
308 | 303 | ||
309 | 304 | ||
@@ -315,14 +310,14 @@ send_client_status_msg (struct GNUNET_SERVICE_Client *client, | |||
315 | * status=GNUNET_TESTBED_BARRIERSTATUS_ERROR | 310 | * status=GNUNET_TESTBED_BARRIERSTATUS_ERROR |
316 | */ | 311 | */ |
317 | static void | 312 | static void |
318 | send_barrier_status_msg (struct Barrier *barrier, | 313 | send_barrier_status_msg(struct Barrier *barrier, |
319 | const char *emsg) | 314 | const char *emsg) |
320 | { | 315 | { |
321 | GNUNET_assert (0 != barrier->status); | 316 | GNUNET_assert(0 != barrier->status); |
322 | send_client_status_msg (barrier->mc, | 317 | send_client_status_msg(barrier->mc, |
323 | barrier->name, | 318 | barrier->name, |
324 | barrier->status, | 319 | barrier->status, |
325 | emsg); | 320 | emsg); |
326 | } | 321 | } |
327 | 322 | ||
328 | 323 | ||
@@ -333,8 +328,8 @@ send_barrier_status_msg (struct Barrier *barrier, | |||
333 | * @param message the actual message | 328 | * @param message the actual message |
334 | */ | 329 | */ |
335 | static int | 330 | static int |
336 | check_barrier_wait (void *cls, | 331 | check_barrier_wait(void *cls, |
337 | const struct GNUNET_TESTBED_BarrierWait *msg) | 332 | const struct GNUNET_TESTBED_BarrierWait *msg) |
338 | { | 333 | { |
339 | return GNUNET_OK; /* always well-formed */ | 334 | return GNUNET_OK; /* always well-formed */ |
340 | } | 335 | } |
@@ -352,8 +347,8 @@ check_barrier_wait (void *cls, | |||
352 | * @param message the actual message | 347 | * @param message the actual message |
353 | */ | 348 | */ |
354 | static void | 349 | static void |
355 | handle_barrier_wait (void *cls, | 350 | handle_barrier_wait(void *cls, |
356 | const struct GNUNET_TESTBED_BarrierWait *msg) | 351 | const struct GNUNET_TESTBED_BarrierWait *msg) |
357 | { | 352 | { |
358 | struct ClientCtx *client_ctx = cls; | 353 | struct ClientCtx *client_ctx = cls; |
359 | struct Barrier *barrier; | 354 | struct Barrier *barrier; |
@@ -362,50 +357,50 @@ handle_barrier_wait (void *cls, | |||
362 | size_t name_len; | 357 | size_t name_len; |
363 | uint16_t msize; | 358 | uint16_t msize; |
364 | 359 | ||
365 | msize = ntohs (msg->header.size); | 360 | msize = ntohs(msg->header.size); |
366 | if (NULL == barrier_map) | 361 | if (NULL == barrier_map) |
367 | { | 362 | { |
368 | GNUNET_break (0); | 363 | GNUNET_break(0); |
369 | GNUNET_SERVICE_client_drop (client_ctx->client); | 364 | GNUNET_SERVICE_client_drop(client_ctx->client); |
370 | return; | 365 | return; |
371 | } | 366 | } |
372 | name_len = msize - sizeof (struct GNUNET_TESTBED_BarrierWait); | 367 | name_len = msize - sizeof(struct GNUNET_TESTBED_BarrierWait); |
373 | name = GNUNET_malloc (name_len + 1); | 368 | name = GNUNET_malloc(name_len + 1); |
374 | name[name_len] = '\0'; | 369 | name[name_len] = '\0'; |
375 | GNUNET_memcpy (name, | 370 | GNUNET_memcpy(name, |
376 | msg->name, | 371 | msg->name, |
377 | name_len); | 372 | name_len); |
378 | LOG_DEBUG ("Received BARRIER_WAIT for barrier `%s'\n", | 373 | LOG_DEBUG("Received BARRIER_WAIT for barrier `%s'\n", |
379 | name); | 374 | name); |
380 | GNUNET_CRYPTO_hash (name, | 375 | GNUNET_CRYPTO_hash(name, |
381 | name_len, | 376 | name_len, |
382 | &key); | 377 | &key); |
383 | GNUNET_free (name); | 378 | GNUNET_free(name); |
384 | if (NULL == (barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, &key))) | 379 | if (NULL == (barrier = GNUNET_CONTAINER_multihashmap_get(barrier_map, &key))) |
385 | { | 380 | { |
386 | GNUNET_break (0); | 381 | GNUNET_break(0); |
387 | GNUNET_SERVICE_client_drop (client_ctx->client); | 382 | GNUNET_SERVICE_client_drop(client_ctx->client); |
388 | return; | 383 | return; |
389 | } | 384 | } |
390 | if (NULL != client_ctx->barrier) | 385 | if (NULL != client_ctx->barrier) |
391 | { | 386 | { |
392 | GNUNET_break (0); | 387 | GNUNET_break(0); |
393 | GNUNET_SERVICE_client_drop (client_ctx->client); | 388 | GNUNET_SERVICE_client_drop(client_ctx->client); |
394 | return; | 389 | return; |
395 | } | 390 | } |
396 | client_ctx->barrier = barrier; | 391 | client_ctx->barrier = barrier; |
397 | GNUNET_CONTAINER_DLL_insert_tail (barrier->head, | 392 | GNUNET_CONTAINER_DLL_insert_tail(barrier->head, |
398 | barrier->tail, | 393 | barrier->tail, |
399 | client_ctx); | 394 | client_ctx); |
400 | barrier->nreached++; | 395 | barrier->nreached++; |
401 | if ( (barrier->num_wbarriers_reached == barrier->num_wbarriers) && | 396 | if ((barrier->num_wbarriers_reached == barrier->num_wbarriers) && |
402 | (LOCAL_QUORUM_REACHED (barrier)) ) | 397 | (LOCAL_QUORUM_REACHED(barrier))) |
403 | { | 398 | { |
404 | barrier->status = GNUNET_TESTBED_BARRIERSTATUS_CROSSED; | 399 | barrier->status = GNUNET_TESTBED_BARRIERSTATUS_CROSSED; |
405 | send_barrier_status_msg (barrier, | 400 | send_barrier_status_msg(barrier, |
406 | NULL); | 401 | NULL); |
407 | } | 402 | } |
408 | GNUNET_SERVICE_client_continue (client_ctx->client); | 403 | GNUNET_SERVICE_client_continue(client_ctx->client); |
409 | } | 404 | } |
410 | 405 | ||
411 | 406 | ||
@@ -418,14 +413,14 @@ handle_barrier_wait (void *cls, | |||
418 | * @return our `struct ClientCtx` | 413 | * @return our `struct ClientCtx` |
419 | */ | 414 | */ |
420 | static void * | 415 | static void * |
421 | connect_cb (void *cls, | 416 | connect_cb(void *cls, |
422 | struct GNUNET_SERVICE_Client *client, | 417 | struct GNUNET_SERVICE_Client *client, |
423 | struct GNUNET_MQ_Handle *mq) | 418 | struct GNUNET_MQ_Handle *mq) |
424 | { | 419 | { |
425 | struct ClientCtx *client_ctx; | 420 | struct ClientCtx *client_ctx; |
426 | 421 | ||
427 | LOG_DEBUG ("Client connected to testbed-barrier service\n"); | 422 | LOG_DEBUG("Client connected to testbed-barrier service\n"); |
428 | client_ctx = GNUNET_new (struct ClientCtx); | 423 | client_ctx = GNUNET_new(struct ClientCtx); |
429 | client_ctx->client = client; | 424 | client_ctx->client = client; |
430 | return client_ctx; | 425 | return client_ctx; |
431 | } | 426 | } |
@@ -440,22 +435,22 @@ connect_cb (void *cls, | |||
440 | * for the last call when the server is destroyed | 435 | * for the last call when the server is destroyed |
441 | */ | 436 | */ |
442 | static void | 437 | static void |
443 | disconnect_cb (void *cls, | 438 | disconnect_cb(void *cls, |
444 | struct GNUNET_SERVICE_Client *client, | 439 | struct GNUNET_SERVICE_Client *client, |
445 | void *app_ctx) | 440 | void *app_ctx) |
446 | { | 441 | { |
447 | struct ClientCtx *client_ctx = app_ctx; | 442 | struct ClientCtx *client_ctx = app_ctx; |
448 | struct Barrier *barrier = client_ctx->barrier; | 443 | struct Barrier *barrier = client_ctx->barrier; |
449 | 444 | ||
450 | if (NULL != barrier) | 445 | if (NULL != barrier) |
451 | { | 446 | { |
452 | GNUNET_CONTAINER_DLL_remove (barrier->head, | 447 | GNUNET_CONTAINER_DLL_remove(barrier->head, |
453 | barrier->tail, | 448 | barrier->tail, |
454 | client_ctx); | 449 | client_ctx); |
455 | client_ctx->barrier = NULL; | 450 | client_ctx->barrier = NULL; |
456 | } | 451 | } |
457 | GNUNET_free (client_ctx); | 452 | GNUNET_free(client_ctx); |
458 | LOG_DEBUG ("Client disconnected from testbed-barrier service\n"); | 453 | LOG_DEBUG("Client disconnected from testbed-barrier service\n"); |
459 | } | 454 | } |
460 | 455 | ||
461 | 456 | ||
@@ -465,25 +460,25 @@ disconnect_cb (void *cls, | |||
465 | * @param cfg the configuration to use for initialisation | 460 | * @param cfg the configuration to use for initialisation |
466 | */ | 461 | */ |
467 | void | 462 | void |
468 | GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg) | 463 | GST_barriers_init(struct GNUNET_CONFIGURATION_Handle *cfg) |
469 | { | 464 | { |
470 | struct GNUNET_MQ_MessageHandler message_handlers[] = { | 465 | struct GNUNET_MQ_MessageHandler message_handlers[] = { |
471 | GNUNET_MQ_hd_var_size (barrier_wait, | 466 | GNUNET_MQ_hd_var_size(barrier_wait, |
472 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT, | 467 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT, |
473 | struct GNUNET_TESTBED_BarrierWait, | 468 | struct GNUNET_TESTBED_BarrierWait, |
474 | NULL), | 469 | NULL), |
475 | GNUNET_MQ_handler_end () | 470 | GNUNET_MQ_handler_end() |
476 | }; | 471 | }; |
477 | 472 | ||
478 | LOG_DEBUG ("Launching testbed-barrier service\n"); | 473 | LOG_DEBUG("Launching testbed-barrier service\n"); |
479 | barrier_map = GNUNET_CONTAINER_multihashmap_create (3, | 474 | barrier_map = GNUNET_CONTAINER_multihashmap_create(3, |
480 | GNUNET_YES); | 475 | GNUNET_YES); |
481 | ctx = GNUNET_SERVICE_start ("testbed-barrier", | 476 | ctx = GNUNET_SERVICE_start("testbed-barrier", |
482 | cfg, | 477 | cfg, |
483 | &connect_cb, | 478 | &connect_cb, |
484 | &disconnect_cb, | 479 | &disconnect_cb, |
485 | NULL, | 480 | NULL, |
486 | message_handlers); | 481 | message_handlers); |
487 | } | 482 | } |
488 | 483 | ||
489 | 484 | ||
@@ -498,15 +493,15 @@ GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg) | |||
498 | * #GNUNET_NO if not. | 493 | * #GNUNET_NO if not. |
499 | */ | 494 | */ |
500 | static int | 495 | static int |
501 | barrier_destroy_iterator (void *cls, | 496 | barrier_destroy_iterator(void *cls, |
502 | const struct GNUNET_HashCode *key, | 497 | const struct GNUNET_HashCode *key, |
503 | void *value) | 498 | void *value) |
504 | { | 499 | { |
505 | struct Barrier *barrier = value; | 500 | struct Barrier *barrier = value; |
506 | 501 | ||
507 | GNUNET_assert (NULL != barrier); | 502 | GNUNET_assert(NULL != barrier); |
508 | cancel_wrappers (barrier); | 503 | cancel_wrappers(barrier); |
509 | remove_barrier (barrier); | 504 | remove_barrier(barrier); |
510 | return GNUNET_YES; | 505 | return GNUNET_YES; |
511 | } | 506 | } |
512 | 507 | ||
@@ -515,16 +510,16 @@ barrier_destroy_iterator (void *cls, | |||
515 | * Function to stop the barrier service | 510 | * Function to stop the barrier service |
516 | */ | 511 | */ |
517 | void | 512 | void |
518 | GST_barriers_destroy () | 513 | GST_barriers_destroy() |
519 | { | 514 | { |
520 | GNUNET_assert (NULL != barrier_map); | 515 | GNUNET_assert(NULL != barrier_map); |
521 | GNUNET_assert (GNUNET_SYSERR != | 516 | GNUNET_assert(GNUNET_SYSERR != |
522 | GNUNET_CONTAINER_multihashmap_iterate (barrier_map, | 517 | GNUNET_CONTAINER_multihashmap_iterate(barrier_map, |
523 | &barrier_destroy_iterator, | 518 | &barrier_destroy_iterator, |
524 | NULL)); | 519 | NULL)); |
525 | GNUNET_CONTAINER_multihashmap_destroy (barrier_map); | 520 | GNUNET_CONTAINER_multihashmap_destroy(barrier_map); |
526 | GNUNET_assert (NULL != ctx); | 521 | GNUNET_assert(NULL != ctx); |
527 | GNUNET_SERVICE_stop (ctx); | 522 | GNUNET_SERVICE_stop(ctx); |
528 | } | 523 | } |
529 | 524 | ||
530 | 525 | ||
@@ -542,57 +537,59 @@ GST_barriers_destroy () | |||
542 | * error messsage | 537 | * error messsage |
543 | */ | 538 | */ |
544 | static void | 539 | static void |
545 | wbarrier_status_cb (void *cls, | 540 | wbarrier_status_cb(void *cls, |
546 | const char *name, | 541 | const char *name, |
547 | struct GNUNET_TESTBED_Barrier *b_, | 542 | struct GNUNET_TESTBED_Barrier *b_, |
548 | enum GNUNET_TESTBED_BarrierStatus status, | 543 | enum GNUNET_TESTBED_BarrierStatus status, |
549 | const char *emsg) | 544 | const char *emsg) |
550 | { | 545 | { |
551 | struct WBarrier *wrapper = cls; | 546 | struct WBarrier *wrapper = cls; |
552 | struct Barrier *barrier = wrapper->barrier; | 547 | struct Barrier *barrier = wrapper->barrier; |
553 | 548 | ||
554 | GNUNET_assert (b_ == wrapper->hbarrier); | 549 | GNUNET_assert(b_ == wrapper->hbarrier); |
555 | switch (status) | 550 | switch (status) |
556 | { | ||
557 | case GNUNET_TESTBED_BARRIERSTATUS_ERROR: | ||
558 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
559 | "Initialising barrier `%s' failed at a sub-controller: %s\n", | ||
560 | barrier->name, | ||
561 | (NULL != emsg) ? emsg : "NULL"); | ||
562 | cancel_wrappers (barrier); | ||
563 | if (NULL == emsg) | ||
564 | emsg = "Initialisation failed at a sub-controller"; | ||
565 | barrier->status = GNUNET_TESTBED_BARRIERSTATUS_ERROR; | ||
566 | send_barrier_status_msg (barrier, emsg); | ||
567 | return; | ||
568 | case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: | ||
569 | if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED != barrier->status) | ||
570 | { | 551 | { |
571 | GNUNET_break_op (0); | 552 | case GNUNET_TESTBED_BARRIERSTATUS_ERROR: |
553 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
554 | "Initialising barrier `%s' failed at a sub-controller: %s\n", | ||
555 | barrier->name, | ||
556 | (NULL != emsg) ? emsg : "NULL"); | ||
557 | cancel_wrappers(barrier); | ||
558 | if (NULL == emsg) | ||
559 | emsg = "Initialisation failed at a sub-controller"; | ||
560 | barrier->status = GNUNET_TESTBED_BARRIERSTATUS_ERROR; | ||
561 | send_barrier_status_msg(barrier, emsg); | ||
572 | return; | 562 | return; |
573 | } | 563 | |
574 | barrier->num_wbarriers_reached++; | 564 | case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: |
575 | if ((barrier->num_wbarriers_reached == barrier->num_wbarriers) | 565 | if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED != barrier->status) |
576 | && (LOCAL_QUORUM_REACHED (barrier))) | 566 | { |
577 | { | 567 | GNUNET_break_op(0); |
578 | barrier->status = GNUNET_TESTBED_BARRIERSTATUS_CROSSED; | 568 | return; |
579 | send_barrier_status_msg (barrier, NULL); | 569 | } |
580 | } | 570 | barrier->num_wbarriers_reached++; |
581 | return; | 571 | if ((barrier->num_wbarriers_reached == barrier->num_wbarriers) |
582 | case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: | 572 | && (LOCAL_QUORUM_REACHED(barrier))) |
583 | if (0 != barrier->status) | 573 | { |
584 | { | 574 | barrier->status = GNUNET_TESTBED_BARRIERSTATUS_CROSSED; |
585 | GNUNET_break_op (0); | 575 | send_barrier_status_msg(barrier, NULL); |
576 | } | ||
577 | return; | ||
578 | |||
579 | case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: | ||
580 | if (0 != barrier->status) | ||
581 | { | ||
582 | GNUNET_break_op(0); | ||
583 | return; | ||
584 | } | ||
585 | barrier->num_wbarriers_inited++; | ||
586 | if (barrier->num_wbarriers_inited == barrier->num_wbarriers) | ||
587 | { | ||
588 | barrier->status = GNUNET_TESTBED_BARRIERSTATUS_INITIALISED; | ||
589 | send_barrier_status_msg(barrier, NULL); | ||
590 | } | ||
586 | return; | 591 | return; |
587 | } | 592 | } |
588 | barrier->num_wbarriers_inited++; | ||
589 | if (barrier->num_wbarriers_inited == barrier->num_wbarriers) | ||
590 | { | ||
591 | barrier->status = GNUNET_TESTBED_BARRIERSTATUS_INITIALISED; | ||
592 | send_barrier_status_msg (barrier, NULL); | ||
593 | } | ||
594 | return; | ||
595 | } | ||
596 | } | 593 | } |
597 | 594 | ||
598 | 595 | ||
@@ -603,15 +600,15 @@ wbarrier_status_cb (void *cls, | |||
603 | * @param cls barrier | 600 | * @param cls barrier |
604 | */ | 601 | */ |
605 | static void | 602 | static void |
606 | fwd_tout_barrier_init (void *cls) | 603 | fwd_tout_barrier_init(void *cls) |
607 | { | 604 | { |
608 | struct Barrier *barrier = cls; | 605 | struct Barrier *barrier = cls; |
609 | 606 | ||
610 | cancel_wrappers (barrier); | 607 | cancel_wrappers(barrier); |
611 | barrier->status = GNUNET_TESTBED_BARRIERSTATUS_ERROR; | 608 | barrier->status = GNUNET_TESTBED_BARRIERSTATUS_ERROR; |
612 | send_barrier_status_msg (barrier, | 609 | send_barrier_status_msg(barrier, |
613 | "Timedout while propagating barrier initialisation\n"); | 610 | "Timedout while propagating barrier initialisation\n"); |
614 | remove_barrier (barrier); | 611 | remove_barrier(barrier); |
615 | } | 612 | } |
616 | 613 | ||
617 | 614 | ||
@@ -624,8 +621,8 @@ fwd_tout_barrier_init (void *cls) | |||
624 | * @return #GNUNET_OK if @a msg is well-formed | 621 | * @return #GNUNET_OK if @a msg is well-formed |
625 | */ | 622 | */ |
626 | int | 623 | int |
627 | check_barrier_init (void *cls, | 624 | check_barrier_init(void *cls, |
628 | const struct GNUNET_TESTBED_BarrierInit *msg) | 625 | const struct GNUNET_TESTBED_BarrierInit *msg) |
629 | { | 626 | { |
630 | return GNUNET_OK; /* always well-formed */ | 627 | return GNUNET_OK; /* always well-formed */ |
631 | } | 628 | } |
@@ -643,8 +640,8 @@ check_barrier_init (void *cls, | |||
643 | * @param msg the actual message | 640 | * @param msg the actual message |
644 | */ | 641 | */ |
645 | void | 642 | void |
646 | handle_barrier_init (void *cls, | 643 | handle_barrier_init(void *cls, |
647 | const struct GNUNET_TESTBED_BarrierInit *msg) | 644 | const struct GNUNET_TESTBED_BarrierInit *msg) |
648 | { | 645 | { |
649 | struct GNUNET_SERVICE_Client *client = cls; | 646 | struct GNUNET_SERVICE_Client *client = cls; |
650 | char *name; | 647 | char *name; |
@@ -657,81 +654,82 @@ handle_barrier_init (void *cls, | |||
657 | uint16_t msize; | 654 | uint16_t msize; |
658 | 655 | ||
659 | if (NULL == GST_context) | 656 | if (NULL == GST_context) |
660 | { | 657 | { |
661 | GNUNET_break_op (0); | 658 | GNUNET_break_op(0); |
662 | GNUNET_SERVICE_client_drop (client); | 659 | GNUNET_SERVICE_client_drop(client); |
663 | return; | 660 | return; |
664 | } | 661 | } |
665 | if (client != GST_context->client) | 662 | if (client != GST_context->client) |
666 | { | 663 | { |
667 | GNUNET_break_op (0); | 664 | GNUNET_break_op(0); |
668 | GNUNET_SERVICE_client_drop (client); | 665 | GNUNET_SERVICE_client_drop(client); |
669 | return; | 666 | return; |
670 | } | 667 | } |
671 | msize = ntohs (msg->header.size); | 668 | msize = ntohs(msg->header.size); |
672 | name_len = (size_t) msize - sizeof (struct GNUNET_TESTBED_BarrierInit); | 669 | name_len = (size_t)msize - sizeof(struct GNUNET_TESTBED_BarrierInit); |
673 | name = GNUNET_malloc (name_len + 1); | 670 | name = GNUNET_malloc(name_len + 1); |
674 | GNUNET_memcpy (name, msg->name, name_len); | 671 | GNUNET_memcpy(name, msg->name, name_len); |
675 | GNUNET_CRYPTO_hash (name, name_len, &hash); | 672 | GNUNET_CRYPTO_hash(name, name_len, &hash); |
676 | LOG_DEBUG ("Received BARRIER_INIT for barrier `%s'\n", | 673 | LOG_DEBUG("Received BARRIER_INIT for barrier `%s'\n", |
677 | name); | 674 | name); |
678 | if (GNUNET_YES == | 675 | if (GNUNET_YES == |
679 | GNUNET_CONTAINER_multihashmap_contains (barrier_map, | 676 | GNUNET_CONTAINER_multihashmap_contains(barrier_map, |
680 | &hash)) | 677 | &hash)) |
681 | { | 678 | { |
682 | send_client_status_msg (client, | 679 | send_client_status_msg(client, |
683 | name, | 680 | name, |
684 | GNUNET_TESTBED_BARRIERSTATUS_ERROR, | 681 | GNUNET_TESTBED_BARRIERSTATUS_ERROR, |
685 | "A barrier with the same name already exists"); | 682 | "A barrier with the same name already exists"); |
686 | GNUNET_free (name); | 683 | GNUNET_free(name); |
687 | GNUNET_SERVICE_client_continue (client); | 684 | GNUNET_SERVICE_client_continue(client); |
688 | return; | 685 | return; |
689 | } | 686 | } |
690 | barrier = GNUNET_new (struct Barrier); | 687 | barrier = GNUNET_new(struct Barrier); |
691 | barrier->hash = hash; | 688 | barrier->hash = hash; |
692 | barrier->quorum = msg->quorum; | 689 | barrier->quorum = msg->quorum; |
693 | barrier->name = name; | 690 | barrier->name = name; |
694 | barrier->mc = client; | 691 | barrier->mc = client; |
695 | GNUNET_assert (GNUNET_OK == | 692 | GNUNET_assert(GNUNET_OK == |
696 | GNUNET_CONTAINER_multihashmap_put (barrier_map, | 693 | GNUNET_CONTAINER_multihashmap_put(barrier_map, |
697 | &barrier->hash, | 694 | &barrier->hash, |
698 | barrier, | 695 | barrier, |
699 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 696 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
700 | GNUNET_SERVICE_client_continue (client); | 697 | GNUNET_SERVICE_client_continue(client); |
701 | /* Propagate barrier init to subcontrollers */ | 698 | /* Propagate barrier init to subcontrollers */ |
702 | for (cnt = 0; cnt < GST_slave_list_size; cnt++) | 699 | for (cnt = 0; cnt < GST_slave_list_size; cnt++) |
703 | { | ||
704 | if (NULL == (slave = GST_slave_list[cnt])) | ||
705 | continue; | ||
706 | if (NULL == slave->controller) | ||
707 | { | 700 | { |
708 | GNUNET_break (0);/* May happen when we are connecting to the controller */ | 701 | if (NULL == (slave = GST_slave_list[cnt])) |
709 | continue; | 702 | continue; |
703 | if (NULL == slave->controller) | ||
704 | { | ||
705 | GNUNET_break(0);/* May happen when we are connecting to the controller */ | ||
706 | continue; | ||
707 | } | ||
708 | wrapper = GNUNET_new(struct WBarrier); | ||
709 | wrapper->barrier = barrier; | ||
710 | wrapper->controller = slave->controller; | ||
711 | GNUNET_CONTAINER_DLL_insert_tail(barrier->whead, | ||
712 | barrier->wtail, | ||
713 | wrapper); | ||
714 | barrier->num_wbarriers++; | ||
715 | wrapper->hbarrier = GNUNET_TESTBED_barrier_init_(wrapper->controller, | ||
716 | barrier->name, | ||
717 | barrier->quorum, | ||
718 | &wbarrier_status_cb, | ||
719 | wrapper, | ||
720 | GNUNET_NO); | ||
710 | } | 721 | } |
711 | wrapper = GNUNET_new (struct WBarrier); | ||
712 | wrapper->barrier = barrier; | ||
713 | wrapper->controller = slave->controller; | ||
714 | GNUNET_CONTAINER_DLL_insert_tail (barrier->whead, | ||
715 | barrier->wtail, | ||
716 | wrapper); | ||
717 | barrier->num_wbarriers++; | ||
718 | wrapper->hbarrier = GNUNET_TESTBED_barrier_init_ (wrapper->controller, | ||
719 | barrier->name, | ||
720 | barrier->quorum, | ||
721 | &wbarrier_status_cb, | ||
722 | wrapper, | ||
723 | GNUNET_NO); | ||
724 | } | ||
725 | if (NULL == barrier->whead) /* No further propagation */ | 722 | if (NULL == barrier->whead) /* No further propagation */ |
726 | { | 723 | { |
727 | barrier->status = GNUNET_TESTBED_BARRIERSTATUS_INITIALISED; | 724 | barrier->status = GNUNET_TESTBED_BARRIERSTATUS_INITIALISED; |
728 | LOG_DEBUG ("Sending GNUNET_TESTBED_BARRIERSTATUS_INITIALISED for barrier `%s'\n", | 725 | LOG_DEBUG("Sending GNUNET_TESTBED_BARRIERSTATUS_INITIALISED for barrier `%s'\n", |
729 | barrier->name); | 726 | barrier->name); |
730 | send_barrier_status_msg (barrier, NULL); | 727 | send_barrier_status_msg(barrier, NULL); |
731 | }else | 728 | } |
732 | barrier->tout_task = GNUNET_SCHEDULER_add_delayed (MESSAGE_SEND_TIMEOUT (30), | 729 | else |
733 | &fwd_tout_barrier_init, | 730 | barrier->tout_task = GNUNET_SCHEDULER_add_delayed(MESSAGE_SEND_TIMEOUT(30), |
734 | barrier); | 731 | &fwd_tout_barrier_init, |
732 | barrier); | ||
735 | } | 733 | } |
736 | 734 | ||
737 | 735 | ||
@@ -743,8 +741,8 @@ handle_barrier_init (void *cls, | |||
743 | * @return #GNUNET_OK if @a msg is well-formed | 741 | * @return #GNUNET_OK if @a msg is well-formed |
744 | */ | 742 | */ |
745 | int | 743 | int |
746 | check_barrier_cancel (void *cls, | 744 | check_barrier_cancel(void *cls, |
747 | const struct GNUNET_TESTBED_BarrierCancel *msg) | 745 | const struct GNUNET_TESTBED_BarrierCancel *msg) |
748 | { | 746 | { |
749 | return GNUNET_OK; /* all are well-formed */ | 747 | return GNUNET_OK; /* all are well-formed */ |
750 | } | 748 | } |
@@ -762,8 +760,8 @@ check_barrier_cancel (void *cls, | |||
762 | * @param msg the actual message | 760 | * @param msg the actual message |
763 | */ | 761 | */ |
764 | void | 762 | void |
765 | handle_barrier_cancel (void *cls, | 763 | handle_barrier_cancel(void *cls, |
766 | const struct GNUNET_TESTBED_BarrierCancel *msg) | 764 | const struct GNUNET_TESTBED_BarrierCancel *msg) |
767 | { | 765 | { |
768 | struct GNUNET_SERVICE_Client *client = cls; | 766 | struct GNUNET_SERVICE_Client *client = cls; |
769 | char *name; | 767 | char *name; |
@@ -773,42 +771,42 @@ handle_barrier_cancel (void *cls, | |||
773 | uint16_t msize; | 771 | uint16_t msize; |
774 | 772 | ||
775 | if (NULL == GST_context) | 773 | if (NULL == GST_context) |
776 | { | 774 | { |
777 | GNUNET_break_op (0); | 775 | GNUNET_break_op(0); |
778 | GNUNET_SERVICE_client_drop (client); | 776 | GNUNET_SERVICE_client_drop(client); |
779 | return; | 777 | return; |
780 | } | 778 | } |
781 | if (client != GST_context->client) | 779 | if (client != GST_context->client) |
782 | { | 780 | { |
783 | GNUNET_break_op (0); | 781 | GNUNET_break_op(0); |
784 | GNUNET_SERVICE_client_drop (client); | 782 | GNUNET_SERVICE_client_drop(client); |
785 | return; | 783 | return; |
786 | } | 784 | } |
787 | msize = ntohs (msg->header.size); | 785 | msize = ntohs(msg->header.size); |
788 | name_len = msize - sizeof (struct GNUNET_TESTBED_BarrierCancel); | 786 | name_len = msize - sizeof(struct GNUNET_TESTBED_BarrierCancel); |
789 | name = GNUNET_malloc (name_len + 1); | 787 | name = GNUNET_malloc(name_len + 1); |
790 | GNUNET_memcpy (name, | 788 | GNUNET_memcpy(name, |
791 | msg->name, | 789 | msg->name, |
792 | name_len); | 790 | name_len); |
793 | LOG_DEBUG ("Received BARRIER_CANCEL for barrier `%s'\n", | 791 | LOG_DEBUG("Received BARRIER_CANCEL for barrier `%s'\n", |
794 | name); | 792 | name); |
795 | GNUNET_CRYPTO_hash (name, | 793 | GNUNET_CRYPTO_hash(name, |
796 | name_len, | 794 | name_len, |
797 | &hash); | 795 | &hash); |
798 | if (GNUNET_NO == | 796 | if (GNUNET_NO == |
799 | GNUNET_CONTAINER_multihashmap_contains (barrier_map, | 797 | GNUNET_CONTAINER_multihashmap_contains(barrier_map, |
800 | &hash)) | 798 | &hash)) |
801 | { | 799 | { |
802 | GNUNET_break_op (0); | 800 | GNUNET_break_op(0); |
803 | GNUNET_SERVICE_client_drop (client); | 801 | GNUNET_SERVICE_client_drop(client); |
804 | return; | 802 | return; |
805 | } | 803 | } |
806 | barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, | 804 | barrier = GNUNET_CONTAINER_multihashmap_get(barrier_map, |
807 | &hash); | 805 | &hash); |
808 | GNUNET_assert (NULL != barrier); | 806 | GNUNET_assert(NULL != barrier); |
809 | cancel_wrappers (barrier); | 807 | cancel_wrappers(barrier); |
810 | remove_barrier (barrier); | 808 | remove_barrier(barrier); |
811 | GNUNET_SERVICE_client_continue (client); | 809 | GNUNET_SERVICE_client_continue(client); |
812 | } | 810 | } |
813 | 811 | ||
814 | 812 | ||
@@ -820,34 +818,34 @@ handle_barrier_cancel (void *cls, | |||
820 | * @return #GNUNET_OK if @a msg is well-formed | 818 | * @return #GNUNET_OK if @a msg is well-formed |
821 | */ | 819 | */ |
822 | int | 820 | int |
823 | check_barrier_status (void *cls, | 821 | check_barrier_status(void *cls, |
824 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) | 822 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) |
825 | { | 823 | { |
826 | uint16_t msize; | 824 | uint16_t msize; |
827 | uint16_t name_len; | 825 | uint16_t name_len; |
828 | const char *name; | 826 | const char *name; |
829 | enum GNUNET_TESTBED_BarrierStatus status; | 827 | enum GNUNET_TESTBED_BarrierStatus status; |
830 | 828 | ||
831 | msize = ntohs (msg->header.size) - sizeof (*msg); | 829 | msize = ntohs(msg->header.size) - sizeof(*msg); |
832 | status = ntohs (msg->status); | 830 | status = ntohs(msg->status); |
833 | if (GNUNET_TESTBED_BARRIERSTATUS_CROSSED != status) | 831 | if (GNUNET_TESTBED_BARRIERSTATUS_CROSSED != status) |
834 | { | 832 | { |
835 | GNUNET_break_op (0); /* current we only expect BARRIER_CROSSED | 833 | GNUNET_break_op(0); /* current we only expect BARRIER_CROSSED |
836 | status message this way */ | 834 | status message this way */ |
837 | return GNUNET_SYSERR; | 835 | return GNUNET_SYSERR; |
838 | } | 836 | } |
839 | name = msg->data; | 837 | name = msg->data; |
840 | name_len = ntohs (msg->name_len); | 838 | name_len = ntohs(msg->name_len); |
841 | if ((name_len + 1) != msize) | 839 | if ((name_len + 1) != msize) |
842 | { | 840 | { |
843 | GNUNET_break_op (0); | 841 | GNUNET_break_op(0); |
844 | return GNUNET_SYSERR; | 842 | return GNUNET_SYSERR; |
845 | } | 843 | } |
846 | if ('\0' != name[name_len]) | 844 | if ('\0' != name[name_len]) |
847 | { | 845 | { |
848 | GNUNET_break_op (0); | 846 | GNUNET_break_op(0); |
849 | return GNUNET_SYSERR; | 847 | return GNUNET_SYSERR; |
850 | } | 848 | } |
851 | return GNUNET_OK; | 849 | return GNUNET_OK; |
852 | } | 850 | } |
853 | 851 | ||
@@ -861,8 +859,8 @@ check_barrier_status (void *cls, | |||
861 | * @param msg the actual message | 859 | * @param msg the actual message |
862 | */ | 860 | */ |
863 | void | 861 | void |
864 | handle_barrier_status (void *cls, | 862 | handle_barrier_status(void *cls, |
865 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) | 863 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) |
866 | { | 864 | { |
867 | struct GNUNET_SERVICE_Client *client = cls; | 865 | struct GNUNET_SERVICE_Client *client = cls; |
868 | struct Barrier *barrier; | 866 | struct Barrier *barrier; |
@@ -874,48 +872,48 @@ handle_barrier_status (void *cls, | |||
874 | struct GNUNET_MQ_Envelope *env; | 872 | struct GNUNET_MQ_Envelope *env; |
875 | 873 | ||
876 | if (NULL == GST_context) | 874 | if (NULL == GST_context) |
877 | { | 875 | { |
878 | GNUNET_break_op (0); | 876 | GNUNET_break_op(0); |
879 | GNUNET_SERVICE_client_drop (client); | 877 | GNUNET_SERVICE_client_drop(client); |
880 | return; | 878 | return; |
881 | } | 879 | } |
882 | if (client != GST_context->client) | 880 | if (client != GST_context->client) |
883 | { | 881 | { |
884 | GNUNET_break_op (0); | 882 | GNUNET_break_op(0); |
885 | GNUNET_SERVICE_client_drop (client); | 883 | GNUNET_SERVICE_client_drop(client); |
886 | return; | 884 | return; |
887 | } | 885 | } |
888 | name = msg->data; | 886 | name = msg->data; |
889 | name_len = ntohs (msg->name_len); | 887 | name_len = ntohs(msg->name_len); |
890 | LOG_DEBUG ("Received BARRIER_STATUS for barrier `%s'\n", | 888 | LOG_DEBUG("Received BARRIER_STATUS for barrier `%s'\n", |
891 | name); | 889 | name); |
892 | GNUNET_CRYPTO_hash (name, | 890 | GNUNET_CRYPTO_hash(name, |
893 | name_len, | 891 | name_len, |
894 | &key); | 892 | &key); |
895 | barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, | 893 | barrier = GNUNET_CONTAINER_multihashmap_get(barrier_map, |
896 | &key); | 894 | &key); |
897 | if (NULL == barrier) | 895 | if (NULL == barrier) |
898 | { | 896 | { |
899 | GNUNET_break_op (0); | 897 | GNUNET_break_op(0); |
900 | GNUNET_SERVICE_client_drop (client); | 898 | GNUNET_SERVICE_client_drop(client); |
901 | return; | 899 | return; |
902 | } | 900 | } |
903 | GNUNET_SERVICE_client_continue (client); | 901 | GNUNET_SERVICE_client_continue(client); |
904 | for(client_ctx = barrier->head; NULL != client_ctx; client_ctx = client_ctx->next) /* Notify peers */ | 902 | for (client_ctx = barrier->head; NULL != client_ctx; client_ctx = client_ctx->next) /* Notify peers */ |
905 | { | 903 | { |
906 | env = GNUNET_MQ_msg_copy (&msg->header); | 904 | env = GNUNET_MQ_msg_copy(&msg->header); |
907 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client_ctx->client), | 905 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client_ctx->client), |
908 | env); | 906 | env); |
909 | } | 907 | } |
910 | /** | 908 | /** |
911 | * The wrapper barriers do not echo the barrier status, so we have to do it | 909 | * The wrapper barriers do not echo the barrier status, so we have to do it |
912 | * here | 910 | * here |
913 | */ | 911 | */ |
914 | for (wrapper = barrier->whead; NULL != wrapper; wrapper = wrapper->next) | 912 | for (wrapper = barrier->whead; NULL != wrapper; wrapper = wrapper->next) |
915 | { | 913 | { |
916 | GNUNET_TESTBED_queue_message_ (wrapper->controller, | 914 | GNUNET_TESTBED_queue_message_(wrapper->controller, |
917 | GNUNET_copy_message (&msg->header)); | 915 | GNUNET_copy_message(&msg->header)); |
918 | } | 916 | } |
919 | } | 917 | } |
920 | 918 | ||
921 | /* end of gnunet-service-testbed_barriers.c */ | 919 | /* end of gnunet-service-testbed_barriers.c */ |
diff --git a/src/testbed/gnunet-service-testbed_barriers.h b/src/testbed/gnunet-service-testbed_barriers.h index c5547867f..a16a4aa0d 100644 --- a/src/testbed/gnunet-service-testbed_barriers.h +++ b/src/testbed/gnunet-service-testbed_barriers.h | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2013 GNUnet e.V. | 3 | Copyright (C) 2008--2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/gnunet-service-testbed_barriers.h | 22 | * @file testbed/gnunet-service-testbed_barriers.h |
@@ -33,14 +33,14 @@ | |||
33 | * @param cfg the configuration to use for initialisation | 33 | * @param cfg the configuration to use for initialisation |
34 | */ | 34 | */ |
35 | void | 35 | void |
36 | GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg); | 36 | GST_barriers_init(struct GNUNET_CONFIGURATION_Handle *cfg); |
37 | 37 | ||
38 | 38 | ||
39 | /** | 39 | /** |
40 | * Function to stop the barrier service | 40 | * Function to stop the barrier service |
41 | */ | 41 | */ |
42 | void | 42 | void |
43 | GST_barriers_destroy (void); | 43 | GST_barriers_destroy(void); |
44 | 44 | ||
45 | 45 | ||
46 | /** | 46 | /** |
@@ -51,8 +51,8 @@ GST_barriers_destroy (void); | |||
51 | * @return #GNUNET_OK if @a msg is well-formed | 51 | * @return #GNUNET_OK if @a msg is well-formed |
52 | */ | 52 | */ |
53 | int | 53 | int |
54 | check_barrier_init (void *cls, | 54 | check_barrier_init(void *cls, |
55 | const struct GNUNET_TESTBED_BarrierInit *msg); | 55 | const struct GNUNET_TESTBED_BarrierInit *msg); |
56 | 56 | ||
57 | 57 | ||
58 | /** | 58 | /** |
@@ -67,8 +67,8 @@ check_barrier_init (void *cls, | |||
67 | * @param msg the actual message | 67 | * @param msg the actual message |
68 | */ | 68 | */ |
69 | void | 69 | void |
70 | handle_barrier_init (void *cls, | 70 | handle_barrier_init(void *cls, |
71 | const struct GNUNET_TESTBED_BarrierInit *msg); | 71 | const struct GNUNET_TESTBED_BarrierInit *msg); |
72 | 72 | ||
73 | 73 | ||
74 | /** | 74 | /** |
@@ -79,8 +79,8 @@ handle_barrier_init (void *cls, | |||
79 | * @return #GNUNET_OK if @a msg is well-formed | 79 | * @return #GNUNET_OK if @a msg is well-formed |
80 | */ | 80 | */ |
81 | int | 81 | int |
82 | check_barrier_cancel (void *cls, | 82 | check_barrier_cancel(void *cls, |
83 | const struct GNUNET_TESTBED_BarrierCancel *msg); | 83 | const struct GNUNET_TESTBED_BarrierCancel *msg); |
84 | 84 | ||
85 | 85 | ||
86 | /** | 86 | /** |
@@ -95,8 +95,8 @@ check_barrier_cancel (void *cls, | |||
95 | * @param msg the actual message | 95 | * @param msg the actual message |
96 | */ | 96 | */ |
97 | void | 97 | void |
98 | handle_barrier_cancel (void *cls, | 98 | handle_barrier_cancel(void *cls, |
99 | const struct GNUNET_TESTBED_BarrierCancel *msg); | 99 | const struct GNUNET_TESTBED_BarrierCancel *msg); |
100 | 100 | ||
101 | 101 | ||
102 | /** | 102 | /** |
@@ -107,8 +107,8 @@ handle_barrier_cancel (void *cls, | |||
107 | * @return #GNUNET_OK if @a msg is well-formed | 107 | * @return #GNUNET_OK if @a msg is well-formed |
108 | */ | 108 | */ |
109 | int | 109 | int |
110 | check_barrier_status (void *cls, | 110 | check_barrier_status(void *cls, |
111 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg); | 111 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg); |
112 | 112 | ||
113 | 113 | ||
114 | /** | 114 | /** |
@@ -120,8 +120,8 @@ check_barrier_status (void *cls, | |||
120 | * @param msg the actual message | 120 | * @param msg the actual message |
121 | */ | 121 | */ |
122 | void | 122 | void |
123 | handle_barrier_status (void *cls, | 123 | handle_barrier_status(void *cls, |
124 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg); | 124 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg); |
125 | 125 | ||
126 | #endif /* GNUNET_SERVER_TESTBED_BARRIERS_H_ */ | 126 | #endif /* GNUNET_SERVER_TESTBED_BARRIERS_H_ */ |
127 | 127 | ||
diff --git a/src/testbed/gnunet-service-testbed_cache.c b/src/testbed/gnunet-service-testbed_cache.c index 80b0aed0c..901065da1 100644 --- a/src/testbed/gnunet-service-testbed_cache.c +++ b/src/testbed/gnunet-service-testbed_cache.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2013 GNUnet e.V. | 3 | Copyright (C) 2008--2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/gnunet-service-testbed_cache.c | 22 | * @file testbed/gnunet-service-testbed_cache.c |
@@ -31,15 +31,14 @@ | |||
31 | #ifdef LOG | 31 | #ifdef LOG |
32 | #undef LOG | 32 | #undef LOG |
33 | #endif | 33 | #endif |
34 | #define LOG(kind,...) \ | 34 | #define LOG(kind, ...) \ |
35 | GNUNET_log_from (kind, "testbed-cache", __VA_ARGS__) | 35 | GNUNET_log_from(kind, "testbed-cache", __VA_ARGS__) |
36 | 36 | ||
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Cache entry | 39 | * Cache entry |
40 | */ | 40 | */ |
41 | struct CacheEntry | 41 | struct CacheEntry { |
42 | { | ||
43 | /** | 42 | /** |
44 | * DLL next ptr for least recently used cache entries | 43 | * DLL next ptr for least recently used cache entries |
45 | */ | 44 | */ |
@@ -97,16 +96,16 @@ static unsigned int cache_size; | |||
97 | * @return the HELLO message; NULL if not found | 96 | * @return the HELLO message; NULL if not found |
98 | */ | 97 | */ |
99 | static struct CacheEntry * | 98 | static struct CacheEntry * |
100 | cache_lookup (unsigned int peer_id) | 99 | cache_lookup(unsigned int peer_id) |
101 | { | 100 | { |
102 | struct CacheEntry *entry; | 101 | struct CacheEntry *entry; |
103 | 102 | ||
104 | GNUNET_assert (NULL != cache); | 103 | GNUNET_assert(NULL != cache); |
105 | entry = GNUNET_CONTAINER_multihashmap32_get (cache, peer_id); | 104 | entry = GNUNET_CONTAINER_multihashmap32_get(cache, peer_id); |
106 | if (NULL == entry) | 105 | if (NULL == entry) |
107 | return NULL; | 106 | return NULL; |
108 | GNUNET_CONTAINER_DLL_remove (cache_head, cache_tail, entry); | 107 | GNUNET_CONTAINER_DLL_remove(cache_head, cache_tail, entry); |
109 | GNUNET_CONTAINER_DLL_insert_tail (cache_head, cache_tail, entry); | 108 | GNUNET_CONTAINER_DLL_insert_tail(cache_head, cache_tail, entry); |
110 | return entry; | 109 | return entry; |
111 | } | 110 | } |
112 | 111 | ||
@@ -117,11 +116,11 @@ cache_lookup (unsigned int peer_id) | |||
117 | * @param entry the cache entry to free | 116 | * @param entry the cache entry to free |
118 | */ | 117 | */ |
119 | static void | 118 | static void |
120 | free_entry (struct CacheEntry *entry) | 119 | free_entry(struct CacheEntry *entry) |
121 | { | 120 | { |
122 | GNUNET_CONTAINER_DLL_remove (cache_head, cache_tail, entry); | 121 | GNUNET_CONTAINER_DLL_remove(cache_head, cache_tail, entry); |
123 | GNUNET_free_non_null (entry->hello); | 122 | GNUNET_free_non_null(entry->hello); |
124 | GNUNET_free (entry); | 123 | GNUNET_free(entry); |
125 | } | 124 | } |
126 | 125 | ||
127 | 126 | ||
@@ -132,29 +131,29 @@ free_entry (struct CacheEntry *entry) | |||
132 | * @return the newly created entry | 131 | * @return the newly created entry |
133 | */ | 132 | */ |
134 | static struct CacheEntry * | 133 | static struct CacheEntry * |
135 | add_entry (unsigned int peer_id) | 134 | add_entry(unsigned int peer_id) |
136 | { | 135 | { |
137 | struct CacheEntry *entry; | 136 | struct CacheEntry *entry; |
138 | 137 | ||
139 | GNUNET_assert (NULL != cache); | 138 | GNUNET_assert(NULL != cache); |
140 | if (cache_size == GNUNET_CONTAINER_multihashmap32_size (cache)) | 139 | if (cache_size == GNUNET_CONTAINER_multihashmap32_size(cache)) |
141 | { | 140 | { |
142 | /* remove the LRU head */ | 141 | /* remove the LRU head */ |
143 | entry = cache_head; | 142 | entry = cache_head; |
144 | GNUNET_assert (GNUNET_OK == | 143 | GNUNET_assert(GNUNET_OK == |
145 | GNUNET_CONTAINER_multihashmap32_remove (cache, (uint32_t) | 144 | GNUNET_CONTAINER_multihashmap32_remove(cache, (uint32_t) |
146 | entry->peer_id, | 145 | entry->peer_id, |
147 | entry)); | 146 | entry)); |
148 | free_entry (entry); | 147 | free_entry(entry); |
149 | } | 148 | } |
150 | entry = GNUNET_new (struct CacheEntry); | 149 | entry = GNUNET_new(struct CacheEntry); |
151 | entry->peer_id = peer_id; | 150 | entry->peer_id = peer_id; |
152 | GNUNET_assert (GNUNET_OK == | 151 | GNUNET_assert(GNUNET_OK == |
153 | GNUNET_CONTAINER_multihashmap32_put (cache, | 152 | GNUNET_CONTAINER_multihashmap32_put(cache, |
154 | (uint32_t) peer_id, | 153 | (uint32_t)peer_id, |
155 | entry, | 154 | entry, |
156 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 155 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
157 | GNUNET_CONTAINER_DLL_insert_tail (cache_head, cache_tail, entry); | 156 | GNUNET_CONTAINER_DLL_insert_tail(cache_head, cache_tail, entry); |
158 | return entry; | 157 | return entry; |
159 | } | 158 | } |
160 | 159 | ||
@@ -170,14 +169,14 @@ add_entry (unsigned int peer_id) | |||
170 | * GNUNET_NO if not. | 169 | * GNUNET_NO if not. |
171 | */ | 170 | */ |
172 | static int | 171 | static int |
173 | cache_clear_iterator (void *cls, uint32_t key, void *value) | 172 | cache_clear_iterator(void *cls, uint32_t key, void *value) |
174 | { | 173 | { |
175 | struct CacheEntry *entry = value; | 174 | struct CacheEntry *entry = value; |
176 | 175 | ||
177 | GNUNET_assert (NULL != entry); | 176 | GNUNET_assert(NULL != entry); |
178 | GNUNET_assert (GNUNET_YES == | 177 | GNUNET_assert(GNUNET_YES == |
179 | GNUNET_CONTAINER_multihashmap32_remove (cache, key, value)); | 178 | GNUNET_CONTAINER_multihashmap32_remove(cache, key, value)); |
180 | free_entry (entry); | 179 | free_entry(entry); |
181 | return GNUNET_YES; | 180 | return GNUNET_YES; |
182 | } | 181 | } |
183 | 182 | ||
@@ -186,15 +185,15 @@ cache_clear_iterator (void *cls, uint32_t key, void *value) | |||
186 | * Clear cache | 185 | * Clear cache |
187 | */ | 186 | */ |
188 | void | 187 | void |
189 | GST_cache_clear () | 188 | GST_cache_clear() |
190 | { | 189 | { |
191 | if (NULL != cache) | 190 | if (NULL != cache) |
192 | { | 191 | { |
193 | GNUNET_CONTAINER_multihashmap32_iterate (cache, &cache_clear_iterator, NULL); | 192 | GNUNET_CONTAINER_multihashmap32_iterate(cache, &cache_clear_iterator, NULL); |
194 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (cache)); | 193 | GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap32_size(cache)); |
195 | GNUNET_CONTAINER_multihashmap32_destroy (cache); | 194 | GNUNET_CONTAINER_multihashmap32_destroy(cache); |
196 | cache = NULL; | 195 | cache = NULL; |
197 | } | 196 | } |
198 | cache_size = 0; | 197 | cache_size = 0; |
199 | cache_head = NULL; | 198 | cache_head = NULL; |
200 | cache_tail = NULL; | 199 | cache_tail = NULL; |
@@ -207,12 +206,12 @@ GST_cache_clear () | |||
207 | * @param size the size of the cache | 206 | * @param size the size of the cache |
208 | */ | 207 | */ |
209 | void | 208 | void |
210 | GST_cache_init (unsigned int size) | 209 | GST_cache_init(unsigned int size) |
211 | { | 210 | { |
212 | if (0 == size) | 211 | if (0 == size) |
213 | return; | 212 | return; |
214 | cache_size = size; | 213 | cache_size = size; |
215 | cache = GNUNET_CONTAINER_multihashmap32_create (cache_size); | 214 | cache = GNUNET_CONTAINER_multihashmap32_create(cache_size); |
216 | } | 215 | } |
217 | 216 | ||
218 | 217 | ||
@@ -223,21 +222,21 @@ GST_cache_init (unsigned int size) | |||
223 | * @return the HELLO message; NULL if not found | 222 | * @return the HELLO message; NULL if not found |
224 | */ | 223 | */ |
225 | const struct GNUNET_MessageHeader * | 224 | const struct GNUNET_MessageHeader * |
226 | GST_cache_lookup_hello (const unsigned int peer_id) | 225 | GST_cache_lookup_hello(const unsigned int peer_id) |
227 | { | 226 | { |
228 | struct CacheEntry *entry; | 227 | struct CacheEntry *entry; |
229 | 228 | ||
230 | LOG_DEBUG ("Looking up HELLO for peer %u\n", peer_id); | 229 | LOG_DEBUG("Looking up HELLO for peer %u\n", peer_id); |
231 | if (NULL == cache) | 230 | if (NULL == cache) |
232 | { | 231 | { |
233 | LOG_DEBUG ("Caching disabled\n"); | 232 | LOG_DEBUG("Caching disabled\n"); |
234 | return NULL; | 233 | return NULL; |
235 | } | 234 | } |
236 | entry = cache_lookup (peer_id); | 235 | entry = cache_lookup(peer_id); |
237 | if (NULL == entry) | 236 | if (NULL == entry) |
238 | return NULL; | 237 | return NULL; |
239 | if (NULL != entry->hello) | 238 | if (NULL != entry->hello) |
240 | LOG_DEBUG ("HELLO found for peer %u\n", peer_id); | 239 | LOG_DEBUG("HELLO found for peer %u\n", peer_id); |
241 | return entry->hello; | 240 | return entry->hello; |
242 | } | 241 | } |
243 | 242 | ||
@@ -250,18 +249,18 @@ GST_cache_lookup_hello (const unsigned int peer_id) | |||
250 | * @param hello the HELLO message | 249 | * @param hello the HELLO message |
251 | */ | 250 | */ |
252 | void | 251 | void |
253 | GST_cache_add_hello (const unsigned int peer_id, | 252 | GST_cache_add_hello(const unsigned int peer_id, |
254 | const struct GNUNET_MessageHeader *hello) | 253 | const struct GNUNET_MessageHeader *hello) |
255 | { | 254 | { |
256 | struct CacheEntry *entry; | 255 | struct CacheEntry *entry; |
257 | 256 | ||
258 | if (NULL == cache) | 257 | if (NULL == cache) |
259 | return; | 258 | return; |
260 | entry = cache_lookup (peer_id); | 259 | entry = cache_lookup(peer_id); |
261 | if (NULL == entry) | 260 | if (NULL == entry) |
262 | entry = add_entry (peer_id); | 261 | entry = add_entry(peer_id); |
263 | GNUNET_free_non_null (entry->hello); | 262 | GNUNET_free_non_null(entry->hello); |
264 | entry->hello = GNUNET_copy_message (hello); | 263 | entry->hello = GNUNET_copy_message(hello); |
265 | } | 264 | } |
266 | 265 | ||
267 | /* end of gnunet-service-testbed_hc.c */ | 266 | /* end of gnunet-service-testbed_hc.c */ |
diff --git a/src/testbed/gnunet-service-testbed_connectionpool.c b/src/testbed/gnunet-service-testbed_connectionpool.c index e173a2349..fdb10f987 100644 --- a/src/testbed/gnunet-service-testbed_connectionpool.c +++ b/src/testbed/gnunet-service-testbed_connectionpool.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2015 GNUnet e.V. | 3 | Copyright (C) 2008--2015 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/gnunet-service-testbed_connectionpool.c | 22 | * @file testbed/gnunet-service-testbed_connectionpool.c |
@@ -36,14 +36,14 @@ | |||
36 | #undef LOG | 36 | #undef LOG |
37 | #endif | 37 | #endif |
38 | #define LOG(kind, ...) \ | 38 | #define LOG(kind, ...) \ |
39 | GNUNET_log_from (kind, "testbed-connectionpool", __VA_ARGS__) | 39 | GNUNET_log_from(kind, "testbed-connectionpool", __VA_ARGS__) |
40 | 40 | ||
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Time to expire a cache entry | 43 | * Time to expire a cache entry |
44 | */ | 44 | */ |
45 | #define CACHE_EXPIRY \ | 45 | #define CACHE_EXPIRY \ |
46 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 46 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) |
47 | 47 | ||
48 | 48 | ||
49 | /** | 49 | /** |
@@ -55,8 +55,7 @@ struct GST_ConnectionPool_GetHandle; | |||
55 | /** | 55 | /** |
56 | * A pooled connection | 56 | * A pooled connection |
57 | */ | 57 | */ |
58 | struct PooledConnection | 58 | struct PooledConnection { |
59 | { | ||
60 | /** | 59 | /** |
61 | * Next ptr for placing this object in the DLL of least recently used pooled | 60 | * Next ptr for placing this object in the DLL of least recently used pooled |
62 | * connections | 61 | * connections |
@@ -169,8 +168,7 @@ struct PooledConnection | |||
169 | /** | 168 | /** |
170 | * The request handle for obtaining a pooled connection | 169 | * The request handle for obtaining a pooled connection |
171 | */ | 170 | */ |
172 | struct GST_ConnectionPool_GetHandle | 171 | struct GST_ConnectionPool_GetHandle { |
173 | { | ||
174 | /** | 172 | /** |
175 | * The next ptr for inclusion in the notification DLLs. At first the object | 173 | * The next ptr for inclusion in the notification DLLs. At first the object |
176 | * is placed in the waiting DLL of the corresponding #PooledConnection | 174 | * is placed in the waiting DLL of the corresponding #PooledConnection |
@@ -274,7 +272,7 @@ static unsigned int max_size; | |||
274 | * @param entry the #PooledConnection object | 272 | * @param entry the #PooledConnection object |
275 | */ | 273 | */ |
276 | static void | 274 | static void |
277 | expire_task_cancel (struct PooledConnection *entry); | 275 | expire_task_cancel(struct PooledConnection *entry); |
278 | 276 | ||
279 | 277 | ||
280 | /** | 278 | /** |
@@ -283,49 +281,49 @@ expire_task_cancel (struct PooledConnection *entry); | |||
283 | * @param entry the #PooledConnection object | 281 | * @param entry the #PooledConnection object |
284 | */ | 282 | */ |
285 | static void | 283 | static void |
286 | destroy_pooled_connection (struct PooledConnection *entry) | 284 | destroy_pooled_connection(struct PooledConnection *entry) |
287 | { | 285 | { |
288 | GNUNET_assert ((NULL == entry->head_notify) && (NULL == entry->tail_notify)); | 286 | GNUNET_assert((NULL == entry->head_notify) && (NULL == entry->tail_notify)); |
289 | GNUNET_assert ((NULL == entry->head_waiting) && | 287 | GNUNET_assert((NULL == entry->head_waiting) && |
290 | (NULL == entry->tail_waiting)); | 288 | (NULL == entry->tail_waiting)); |
291 | GNUNET_assert (0 == entry->demand); | 289 | GNUNET_assert(0 == entry->demand); |
292 | expire_task_cancel (entry); | 290 | expire_task_cancel(entry); |
293 | if (entry->in_lru) | 291 | if (entry->in_lru) |
294 | GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry); | 292 | GNUNET_CONTAINER_DLL_remove(head_lru, tail_lru, entry); |
295 | if (entry->in_pool) | 293 | if (entry->in_pool) |
296 | GNUNET_assert ( | 294 | GNUNET_assert( |
297 | GNUNET_OK == | 295 | GNUNET_OK == |
298 | GNUNET_CONTAINER_multihashmap32_remove (map, entry->index, entry)); | 296 | GNUNET_CONTAINER_multihashmap32_remove(map, entry->index, entry)); |
299 | if (NULL != entry->notify_task) | 297 | if (NULL != entry->notify_task) |
300 | { | 298 | { |
301 | GNUNET_SCHEDULER_cancel (entry->notify_task); | 299 | GNUNET_SCHEDULER_cancel(entry->notify_task); |
302 | entry->notify_task = NULL; | 300 | entry->notify_task = NULL; |
303 | } | 301 | } |
304 | LOG_DEBUG ("Cleaning up handles of a pooled connection\n"); | 302 | LOG_DEBUG("Cleaning up handles of a pooled connection\n"); |
305 | if (NULL != entry->handle_transport) | 303 | if (NULL != entry->handle_transport) |
306 | GNUNET_assert (NULL != entry->op_transport); | 304 | GNUNET_assert(NULL != entry->op_transport); |
307 | if (NULL != entry->op_transport) | 305 | if (NULL != entry->op_transport) |
308 | { | 306 | { |
309 | GNUNET_TESTBED_operation_done (entry->op_transport); | 307 | GNUNET_TESTBED_operation_done(entry->op_transport); |
310 | entry->op_transport = NULL; | 308 | entry->op_transport = NULL; |
311 | } | 309 | } |
312 | if (NULL != entry->handle_ats_connectivity) | 310 | if (NULL != entry->handle_ats_connectivity) |
313 | GNUNET_assert (NULL != entry->op_ats_connectivity); | 311 | GNUNET_assert(NULL != entry->op_ats_connectivity); |
314 | if (NULL != entry->op_ats_connectivity) | 312 | if (NULL != entry->op_ats_connectivity) |
315 | { | 313 | { |
316 | GNUNET_TESTBED_operation_done (entry->op_ats_connectivity); | 314 | GNUNET_TESTBED_operation_done(entry->op_ats_connectivity); |
317 | entry->op_ats_connectivity = NULL; | 315 | entry->op_ats_connectivity = NULL; |
318 | } | 316 | } |
319 | if (NULL != entry->op_core) | 317 | if (NULL != entry->op_core) |
320 | { | 318 | { |
321 | GNUNET_TESTBED_operation_done (entry->op_core); | 319 | GNUNET_TESTBED_operation_done(entry->op_core); |
322 | entry->op_core = NULL; | 320 | entry->op_core = NULL; |
323 | } | 321 | } |
324 | GNUNET_assert (NULL == entry->handle_core); | 322 | GNUNET_assert(NULL == entry->handle_core); |
325 | GNUNET_assert (NULL == entry->handle_ats_connectivity); | 323 | GNUNET_assert(NULL == entry->handle_ats_connectivity); |
326 | GNUNET_assert (NULL == entry->handle_transport); | 324 | GNUNET_assert(NULL == entry->handle_transport); |
327 | GNUNET_CONFIGURATION_destroy (entry->cfg); | 325 | GNUNET_CONFIGURATION_destroy(entry->cfg); |
328 | GNUNET_free (entry); | 326 | GNUNET_free(entry); |
329 | } | 327 | } |
330 | 328 | ||
331 | 329 | ||
@@ -335,12 +333,12 @@ destroy_pooled_connection (struct PooledConnection *entry) | |||
335 | * @param cls the #PooledConnection object | 333 | * @param cls the #PooledConnection object |
336 | */ | 334 | */ |
337 | static void | 335 | static void |
338 | expire (void *cls) | 336 | expire(void *cls) |
339 | { | 337 | { |
340 | struct PooledConnection *entry = cls; | 338 | struct PooledConnection *entry = cls; |
341 | 339 | ||
342 | entry->expire_task = NULL; | 340 | entry->expire_task = NULL; |
343 | destroy_pooled_connection (entry); | 341 | destroy_pooled_connection(entry); |
344 | } | 342 | } |
345 | 343 | ||
346 | 344 | ||
@@ -350,13 +348,13 @@ expire (void *cls) | |||
350 | * @param entry the #PooledConnection object | 348 | * @param entry the #PooledConnection object |
351 | */ | 349 | */ |
352 | static void | 350 | static void |
353 | expire_task_cancel (struct PooledConnection *entry) | 351 | expire_task_cancel(struct PooledConnection *entry) |
354 | { | 352 | { |
355 | if (NULL != entry->expire_task) | 353 | if (NULL != entry->expire_task) |
356 | { | 354 | { |
357 | GNUNET_SCHEDULER_cancel (entry->expire_task); | 355 | GNUNET_SCHEDULER_cancel(entry->expire_task); |
358 | entry->expire_task = NULL; | 356 | entry->expire_task = NULL; |
359 | } | 357 | } |
360 | } | 358 | } |
361 | 359 | ||
362 | 360 | ||
@@ -366,15 +364,15 @@ expire_task_cancel (struct PooledConnection *entry) | |||
366 | * @param entry the #PooledConnection object | 364 | * @param entry the #PooledConnection object |
367 | */ | 365 | */ |
368 | static void | 366 | static void |
369 | add_to_lru (struct PooledConnection *entry) | 367 | add_to_lru(struct PooledConnection *entry) |
370 | { | 368 | { |
371 | GNUNET_assert (0 == entry->demand); | 369 | GNUNET_assert(0 == entry->demand); |
372 | GNUNET_assert (! entry->in_lru); | 370 | GNUNET_assert(!entry->in_lru); |
373 | GNUNET_CONTAINER_DLL_insert_tail (head_lru, tail_lru, entry); | 371 | GNUNET_CONTAINER_DLL_insert_tail(head_lru, tail_lru, entry); |
374 | entry->in_lru = GNUNET_YES; | 372 | entry->in_lru = GNUNET_YES; |
375 | GNUNET_assert (NULL == entry->expire_task); | 373 | GNUNET_assert(NULL == entry->expire_task); |
376 | entry->expire_task = | 374 | entry->expire_task = |
377 | GNUNET_SCHEDULER_add_delayed (CACHE_EXPIRY, &expire, entry); | 375 | GNUNET_SCHEDULER_add_delayed(CACHE_EXPIRY, &expire, entry); |
378 | } | 376 | } |
379 | 377 | ||
380 | 378 | ||
@@ -390,32 +388,34 @@ add_to_lru (struct PooledConnection *entry) | |||
390 | * is found | 388 | * is found |
391 | */ | 389 | */ |
392 | static struct GST_ConnectionPool_GetHandle * | 390 | static struct GST_ConnectionPool_GetHandle * |
393 | search_waiting (const struct PooledConnection *entry, | 391 | search_waiting(const struct PooledConnection *entry, |
394 | struct GST_ConnectionPool_GetHandle *head) | 392 | struct GST_ConnectionPool_GetHandle *head) |
395 | { | 393 | { |
396 | struct GST_ConnectionPool_GetHandle *gh; | 394 | struct GST_ConnectionPool_GetHandle *gh; |
397 | 395 | ||
398 | for (gh = head; NULL != gh; gh = gh->next) | 396 | for (gh = head; NULL != gh; gh = gh->next) |
399 | { | ||
400 | switch (gh->service) | ||
401 | { | 397 | { |
402 | case GST_CONNECTIONPOOL_SERVICE_CORE: | 398 | switch (gh->service) |
403 | if (NULL == entry->handle_core) | 399 | { |
404 | continue; | 400 | case GST_CONNECTIONPOOL_SERVICE_CORE: |
405 | if (NULL == entry->peer_identity) | 401 | if (NULL == entry->handle_core) |
406 | continue; /* CORE connection isn't ready yet */ | 402 | continue; |
407 | break; | 403 | if (NULL == entry->peer_identity) |
408 | case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: | 404 | continue; /* CORE connection isn't ready yet */ |
409 | if (NULL == entry->handle_transport) | 405 | break; |
410 | continue; | 406 | |
411 | break; | 407 | case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: |
412 | case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: | 408 | if (NULL == entry->handle_transport) |
413 | if (NULL == entry->handle_ats_connectivity) | 409 | continue; |
414 | continue; | 410 | break; |
411 | |||
412 | case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: | ||
413 | if (NULL == entry->handle_ats_connectivity) | ||
414 | continue; | ||
415 | break; | ||
416 | } | ||
415 | break; | 417 | break; |
416 | } | 418 | } |
417 | break; | ||
418 | } | ||
419 | return gh; | 419 | return gh; |
420 | } | 420 | } |
421 | 421 | ||
@@ -430,37 +430,37 @@ search_waiting (const struct PooledConnection *entry, | |||
430 | * @param cls the #PooledConnection object | 430 | * @param cls the #PooledConnection object |
431 | */ | 431 | */ |
432 | static void | 432 | static void |
433 | connection_ready (void *cls) | 433 | connection_ready(void *cls) |
434 | { | 434 | { |
435 | struct PooledConnection *entry = cls; | 435 | struct PooledConnection *entry = cls; |
436 | struct GST_ConnectionPool_GetHandle *gh; | 436 | struct GST_ConnectionPool_GetHandle *gh; |
437 | struct GST_ConnectionPool_GetHandle *gh_next; | 437 | struct GST_ConnectionPool_GetHandle *gh_next; |
438 | 438 | ||
439 | GNUNET_assert (NULL != entry->notify_task); | 439 | GNUNET_assert(NULL != entry->notify_task); |
440 | entry->notify_task = NULL; | 440 | entry->notify_task = NULL; |
441 | gh = search_waiting (entry, entry->head_waiting); | 441 | gh = search_waiting(entry, entry->head_waiting); |
442 | GNUNET_assert (NULL != gh); | 442 | GNUNET_assert(NULL != gh); |
443 | gh_next = NULL; | 443 | gh_next = NULL; |
444 | if (NULL != gh->next) | 444 | if (NULL != gh->next) |
445 | gh_next = search_waiting (entry, gh->next); | 445 | gh_next = search_waiting(entry, gh->next); |
446 | GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh); | 446 | GNUNET_CONTAINER_DLL_remove(entry->head_waiting, entry->tail_waiting, gh); |
447 | gh->connection_ready_called = 1; | 447 | gh->connection_ready_called = 1; |
448 | if (NULL != gh_next) | 448 | if (NULL != gh_next) |
449 | entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry); | 449 | entry->notify_task = GNUNET_SCHEDULER_add_now(&connection_ready, entry); |
450 | if ((NULL != gh->target) && (NULL != gh->connect_notify_cb)) | 450 | if ((NULL != gh->target) && (NULL != gh->connect_notify_cb)) |
451 | { | 451 | { |
452 | GNUNET_CONTAINER_DLL_insert_tail (entry->head_notify, | 452 | GNUNET_CONTAINER_DLL_insert_tail(entry->head_notify, |
453 | entry->tail_notify, | 453 | entry->tail_notify, |
454 | gh); | 454 | gh); |
455 | gh->notify_waiting = 1; | 455 | gh->notify_waiting = 1; |
456 | } | 456 | } |
457 | LOG_DEBUG ("Connection ready for handle type %u\n", gh->service); | 457 | LOG_DEBUG("Connection ready for handle type %u\n", gh->service); |
458 | gh->cb (gh->cb_cls, | 458 | gh->cb(gh->cb_cls, |
459 | entry->handle_core, | 459 | entry->handle_core, |
460 | entry->handle_transport, | 460 | entry->handle_transport, |
461 | entry->handle_ats_connectivity, | 461 | entry->handle_ats_connectivity, |
462 | entry->peer_identity, | 462 | entry->peer_identity, |
463 | entry->cfg); | 463 | entry->cfg); |
464 | } | 464 | } |
465 | 465 | ||
466 | 466 | ||
@@ -474,9 +474,9 @@ connection_ready (void *cls) | |||
474 | * @param service the service where this notification has originated | 474 | * @param service the service where this notification has originated |
475 | */ | 475 | */ |
476 | static void | 476 | static void |
477 | peer_connect_notify_cb (void *cls, | 477 | peer_connect_notify_cb(void *cls, |
478 | const struct GNUNET_PeerIdentity *peer, | 478 | const struct GNUNET_PeerIdentity *peer, |
479 | const enum GST_ConnectionPool_Service service) | 479 | const enum GST_ConnectionPool_Service service) |
480 | { | 480 | { |
481 | struct PooledConnection *entry = cls; | 481 | struct PooledConnection *entry = cls; |
482 | struct GST_ConnectionPool_GetHandle *gh; | 482 | struct GST_ConnectionPool_GetHandle *gh; |
@@ -485,31 +485,31 @@ peer_connect_notify_cb (void *cls, | |||
485 | void *cb_cls; | 485 | void *cb_cls; |
486 | 486 | ||
487 | for (gh = entry->head_notify; NULL != gh;) | 487 | for (gh = entry->head_notify; NULL != gh;) |
488 | { | ||
489 | GNUNET_assert (NULL != gh->target); | ||
490 | GNUNET_assert (NULL != gh->connect_notify_cb); | ||
491 | GNUNET_assert (gh->connection_ready_called); | ||
492 | if (service != gh->service) | ||
493 | { | 488 | { |
494 | gh = gh->next; | 489 | GNUNET_assert(NULL != gh->target); |
495 | continue; | 490 | GNUNET_assert(NULL != gh->connect_notify_cb); |
491 | GNUNET_assert(gh->connection_ready_called); | ||
492 | if (service != gh->service) | ||
493 | { | ||
494 | gh = gh->next; | ||
495 | continue; | ||
496 | } | ||
497 | if (0 != memcmp(gh->target, peer, sizeof(struct GNUNET_PeerIdentity))) | ||
498 | { | ||
499 | gh = gh->next; | ||
500 | continue; | ||
501 | } | ||
502 | cb = gh->connect_notify_cb; | ||
503 | cb_cls = gh->connect_notify_cb_cls; | ||
504 | gh_next = gh->next; | ||
505 | GNUNET_CONTAINER_DLL_remove(entry->head_notify, entry->tail_notify, gh); | ||
506 | gh->notify_waiting = 0; | ||
507 | LOG_DEBUG("Peer connected to peer %u at service %u\n", | ||
508 | entry->index, | ||
509 | gh->service); | ||
510 | gh = gh_next; | ||
511 | cb(cb_cls, peer); | ||
496 | } | 512 | } |
497 | if (0 != memcmp (gh->target, peer, sizeof (struct GNUNET_PeerIdentity))) | ||
498 | { | ||
499 | gh = gh->next; | ||
500 | continue; | ||
501 | } | ||
502 | cb = gh->connect_notify_cb; | ||
503 | cb_cls = gh->connect_notify_cb_cls; | ||
504 | gh_next = gh->next; | ||
505 | GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh); | ||
506 | gh->notify_waiting = 0; | ||
507 | LOG_DEBUG ("Peer connected to peer %u at service %u\n", | ||
508 | entry->index, | ||
509 | gh->service); | ||
510 | gh = gh_next; | ||
511 | cb (cb_cls, peer); | ||
512 | } | ||
513 | } | 513 | } |
514 | 514 | ||
515 | 515 | ||
@@ -523,13 +523,13 @@ peer_connect_notify_cb (void *cls, | |||
523 | * @return NULL | 523 | * @return NULL |
524 | */ | 524 | */ |
525 | static void * | 525 | static void * |
526 | transport_peer_connect_notify_cb (void *cls, | 526 | transport_peer_connect_notify_cb(void *cls, |
527 | const struct GNUNET_PeerIdentity *peer, | 527 | const struct GNUNET_PeerIdentity *peer, |
528 | struct GNUNET_MQ_Handle *mq) | 528 | struct GNUNET_MQ_Handle *mq) |
529 | { | 529 | { |
530 | struct PooledConnection *entry = cls; | 530 | struct PooledConnection *entry = cls; |
531 | 531 | ||
532 | peer_connect_notify_cb (entry, peer, GST_CONNECTIONPOOL_SERVICE_TRANSPORT); | 532 | peer_connect_notify_cb(entry, peer, GST_CONNECTIONPOOL_SERVICE_TRANSPORT); |
533 | return NULL; | 533 | return NULL; |
534 | } | 534 | } |
535 | 535 | ||
@@ -541,34 +541,34 @@ transport_peer_connect_notify_cb (void *cls, | |||
541 | * @param cls the #PooledConnection object | 541 | * @param cls the #PooledConnection object |
542 | */ | 542 | */ |
543 | static void | 543 | static void |
544 | opstart_get_handle_transport (void *cls) | 544 | opstart_get_handle_transport(void *cls) |
545 | { | 545 | { |
546 | struct PooledConnection *entry = cls; | 546 | struct PooledConnection *entry = cls; |
547 | 547 | ||
548 | GNUNET_assert (NULL != entry); | 548 | GNUNET_assert(NULL != entry); |
549 | LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->index); | 549 | LOG_DEBUG("Opening a transport connection to peer %u\n", entry->index); |
550 | entry->handle_transport = | 550 | entry->handle_transport = |
551 | GNUNET_TRANSPORT_core_connect (entry->cfg, | 551 | GNUNET_TRANSPORT_core_connect(entry->cfg, |
552 | NULL, | 552 | NULL, |
553 | NULL, | 553 | NULL, |
554 | entry, | 554 | entry, |
555 | &transport_peer_connect_notify_cb, | 555 | &transport_peer_connect_notify_cb, |
556 | NULL, | 556 | NULL, |
557 | NULL); | 557 | NULL); |
558 | if (NULL == entry->handle_transport) | 558 | if (NULL == entry->handle_transport) |
559 | { | 559 | { |
560 | GNUNET_break (0); | 560 | GNUNET_break(0); |
561 | return; | 561 | return; |
562 | } | 562 | } |
563 | if (0 == entry->demand) | 563 | if (0 == entry->demand) |
564 | return; | 564 | return; |
565 | if (NULL != entry->notify_task) | 565 | if (NULL != entry->notify_task) |
566 | return; | 566 | return; |
567 | if (NULL != search_waiting (entry, entry->head_waiting)) | 567 | if (NULL != search_waiting(entry, entry->head_waiting)) |
568 | { | 568 | { |
569 | entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry); | 569 | entry->notify_task = GNUNET_SCHEDULER_add_now(&connection_ready, entry); |
570 | return; | 570 | return; |
571 | } | 571 | } |
572 | } | 572 | } |
573 | 573 | ||
574 | 574 | ||
@@ -579,13 +579,13 @@ opstart_get_handle_transport (void *cls) | |||
579 | * @param cls the cache entry | 579 | * @param cls the cache entry |
580 | */ | 580 | */ |
581 | static void | 581 | static void |
582 | oprelease_get_handle_transport (void *cls) | 582 | oprelease_get_handle_transport(void *cls) |
583 | { | 583 | { |
584 | struct PooledConnection *entry = cls; | 584 | struct PooledConnection *entry = cls; |
585 | 585 | ||
586 | if (NULL == entry->handle_transport) | 586 | if (NULL == entry->handle_transport) |
587 | return; | 587 | return; |
588 | GNUNET_TRANSPORT_core_disconnect (entry->handle_transport); | 588 | GNUNET_TRANSPORT_core_disconnect(entry->handle_transport); |
589 | entry->handle_transport = NULL; | 589 | entry->handle_transport = NULL; |
590 | } | 590 | } |
591 | 591 | ||
@@ -599,14 +599,14 @@ oprelease_get_handle_transport (void *cls) | |||
599 | * @return peer | 599 | * @return peer |
600 | */ | 600 | */ |
601 | static void * | 601 | static void * |
602 | core_peer_connect_cb (void *cls, | 602 | core_peer_connect_cb(void *cls, |
603 | const struct GNUNET_PeerIdentity *peer, | 603 | const struct GNUNET_PeerIdentity *peer, |
604 | struct GNUNET_MQ_Handle *mq) | 604 | struct GNUNET_MQ_Handle *mq) |
605 | { | 605 | { |
606 | struct PooledConnection *entry = cls; | 606 | struct PooledConnection *entry = cls; |
607 | 607 | ||
608 | peer_connect_notify_cb (entry, peer, GST_CONNECTIONPOOL_SERVICE_CORE); | 608 | peer_connect_notify_cb(entry, peer, GST_CONNECTIONPOOL_SERVICE_CORE); |
609 | return (void *) peer; | 609 | return (void *)peer; |
610 | } | 610 | } |
611 | 611 | ||
612 | 612 | ||
@@ -623,27 +623,27 @@ core_peer_connect_cb (void *cls, | |||
623 | * @param my_identity ID of this peer, NULL if we failed | 623 | * @param my_identity ID of this peer, NULL if we failed |
624 | */ | 624 | */ |
625 | static void | 625 | static void |
626 | core_startup_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) | 626 | core_startup_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity) |
627 | { | 627 | { |
628 | struct PooledConnection *entry = cls; | 628 | struct PooledConnection *entry = cls; |
629 | 629 | ||
630 | if (NULL == my_identity) | 630 | if (NULL == my_identity) |
631 | { | 631 | { |
632 | GNUNET_break (0); | 632 | GNUNET_break(0); |
633 | return; | 633 | return; |
634 | } | 634 | } |
635 | GNUNET_assert (NULL == entry->peer_identity); | 635 | GNUNET_assert(NULL == entry->peer_identity); |
636 | entry->peer_identity = GNUNET_new (struct GNUNET_PeerIdentity); | 636 | entry->peer_identity = GNUNET_new(struct GNUNET_PeerIdentity); |
637 | *entry->peer_identity = *my_identity; | 637 | *entry->peer_identity = *my_identity; |
638 | if (0 == entry->demand) | 638 | if (0 == entry->demand) |
639 | return; | 639 | return; |
640 | if (NULL != entry->notify_task) | 640 | if (NULL != entry->notify_task) |
641 | return; | 641 | return; |
642 | if (NULL != search_waiting (entry, entry->head_waiting)) | 642 | if (NULL != search_waiting(entry, entry->head_waiting)) |
643 | { | 643 | { |
644 | entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry); | 644 | entry->notify_task = GNUNET_SCHEDULER_add_now(&connection_ready, entry); |
645 | return; | 645 | return; |
646 | } | 646 | } |
647 | } | 647 | } |
648 | 648 | ||
649 | 649 | ||
@@ -654,19 +654,19 @@ core_startup_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) | |||
654 | * @param cls the #PooledConnection object | 654 | * @param cls the #PooledConnection object |
655 | */ | 655 | */ |
656 | static void | 656 | static void |
657 | opstart_get_handle_core (void *cls) | 657 | opstart_get_handle_core(void *cls) |
658 | { | 658 | { |
659 | struct PooledConnection *entry = cls; | 659 | struct PooledConnection *entry = cls; |
660 | 660 | ||
661 | GNUNET_assert (NULL != entry); | 661 | GNUNET_assert(NULL != entry); |
662 | LOG_DEBUG ("Opening a CORE connection to peer %u\n", entry->index); | 662 | LOG_DEBUG("Opening a CORE connection to peer %u\n", entry->index); |
663 | entry->handle_core = | 663 | entry->handle_core = |
664 | GNUNET_CORE_connect (entry->cfg, | 664 | GNUNET_CORE_connect(entry->cfg, |
665 | entry, /* closure */ | 665 | entry, /* closure */ |
666 | &core_startup_cb, /* core startup notify */ | 666 | &core_startup_cb, /* core startup notify */ |
667 | &core_peer_connect_cb, /* peer connect notify */ | 667 | &core_peer_connect_cb, /* peer connect notify */ |
668 | NULL, /* peer disconnect notify */ | 668 | NULL, /* peer disconnect notify */ |
669 | NULL); | 669 | NULL); |
670 | } | 670 | } |
671 | 671 | ||
672 | 672 | ||
@@ -677,15 +677,15 @@ opstart_get_handle_core (void *cls) | |||
677 | * @param cls the #PooledConnection object | 677 | * @param cls the #PooledConnection object |
678 | */ | 678 | */ |
679 | static void | 679 | static void |
680 | oprelease_get_handle_core (void *cls) | 680 | oprelease_get_handle_core(void *cls) |
681 | { | 681 | { |
682 | struct PooledConnection *entry = cls; | 682 | struct PooledConnection *entry = cls; |
683 | 683 | ||
684 | if (NULL == entry->handle_core) | 684 | if (NULL == entry->handle_core) |
685 | return; | 685 | return; |
686 | GNUNET_CORE_disconnect (entry->handle_core); | 686 | GNUNET_CORE_disconnect(entry->handle_core); |
687 | entry->handle_core = NULL; | 687 | entry->handle_core = NULL; |
688 | GNUNET_free_non_null (entry->peer_identity); | 688 | GNUNET_free_non_null(entry->peer_identity); |
689 | entry->peer_identity = NULL; | 689 | entry->peer_identity = NULL; |
690 | } | 690 | } |
691 | 691 | ||
@@ -697,11 +697,11 @@ oprelease_get_handle_core (void *cls) | |||
697 | * @param cls the #PooledConnection object | 697 | * @param cls the #PooledConnection object |
698 | */ | 698 | */ |
699 | static void | 699 | static void |
700 | opstart_get_handle_ats_connectivity (void *cls) | 700 | opstart_get_handle_ats_connectivity(void *cls) |
701 | { | 701 | { |
702 | struct PooledConnection *entry = cls; | 702 | struct PooledConnection *entry = cls; |
703 | 703 | ||
704 | entry->handle_ats_connectivity = GNUNET_ATS_connectivity_init (entry->cfg); | 704 | entry->handle_ats_connectivity = GNUNET_ATS_connectivity_init(entry->cfg); |
705 | } | 705 | } |
706 | 706 | ||
707 | 707 | ||
@@ -712,13 +712,13 @@ opstart_get_handle_ats_connectivity (void *cls) | |||
712 | * @param cls the #PooledConnection object | 712 | * @param cls the #PooledConnection object |
713 | */ | 713 | */ |
714 | static void | 714 | static void |
715 | oprelease_get_handle_ats_connectivity (void *cls) | 715 | oprelease_get_handle_ats_connectivity(void *cls) |
716 | { | 716 | { |
717 | struct PooledConnection *entry = cls; | 717 | struct PooledConnection *entry = cls; |
718 | 718 | ||
719 | if (NULL == entry->handle_ats_connectivity) | 719 | if (NULL == entry->handle_ats_connectivity) |
720 | return; | 720 | return; |
721 | GNUNET_ATS_connectivity_done (entry->handle_ats_connectivity); | 721 | GNUNET_ATS_connectivity_done(entry->handle_ats_connectivity); |
722 | entry->handle_ats_connectivity = NULL; | 722 | entry->handle_ats_connectivity = NULL; |
723 | } | 723 | } |
724 | 724 | ||
@@ -734,12 +734,12 @@ oprelease_get_handle_ats_connectivity (void *cls) | |||
734 | * #GNUNET_NO if not. | 734 | * #GNUNET_NO if not. |
735 | */ | 735 | */ |
736 | static int | 736 | static int |
737 | cleanup_iterator (void *cls, uint32_t key, void *value) | 737 | cleanup_iterator(void *cls, uint32_t key, void *value) |
738 | { | 738 | { |
739 | struct PooledConnection *entry = value; | 739 | struct PooledConnection *entry = value; |
740 | 740 | ||
741 | GNUNET_assert (NULL != entry); | 741 | GNUNET_assert(NULL != entry); |
742 | destroy_pooled_connection (entry); | 742 | destroy_pooled_connection(entry); |
743 | return GNUNET_YES; | 743 | return GNUNET_YES; |
744 | } | 744 | } |
745 | 745 | ||
@@ -752,13 +752,13 @@ cleanup_iterator (void *cls, uint32_t key, void *value) | |||
752 | * #GST_ConnectionPool_Service | 752 | * #GST_ConnectionPool_Service |
753 | */ | 753 | */ |
754 | void | 754 | void |
755 | GST_connection_pool_init (unsigned int size) | 755 | GST_connection_pool_init(unsigned int size) |
756 | { | 756 | { |
757 | max_size = size; | 757 | max_size = size; |
758 | if (0 == max_size) | 758 | if (0 == max_size) |
759 | return; | 759 | return; |
760 | GNUNET_assert (NULL == map); | 760 | GNUNET_assert(NULL == map); |
761 | map = GNUNET_CONTAINER_multihashmap32_create (((size * 3) / 4) + 1); | 761 | map = GNUNET_CONTAINER_multihashmap32_create(((size * 3) / 4) + 1); |
762 | } | 762 | } |
763 | 763 | ||
764 | 764 | ||
@@ -766,24 +766,24 @@ GST_connection_pool_init (unsigned int size) | |||
766 | * Cleanup the connection pool | 766 | * Cleanup the connection pool |
767 | */ | 767 | */ |
768 | void | 768 | void |
769 | GST_connection_pool_destroy () | 769 | GST_connection_pool_destroy() |
770 | { | 770 | { |
771 | struct PooledConnection *entry; | 771 | struct PooledConnection *entry; |
772 | 772 | ||
773 | if (NULL != map) | 773 | if (NULL != map) |
774 | { | 774 | { |
775 | GNUNET_assert ( | 775 | GNUNET_assert( |
776 | GNUNET_SYSERR != | 776 | GNUNET_SYSERR != |
777 | GNUNET_CONTAINER_multihashmap32_iterate (map, &cleanup_iterator, NULL)); | 777 | GNUNET_CONTAINER_multihashmap32_iterate(map, &cleanup_iterator, NULL)); |
778 | GNUNET_CONTAINER_multihashmap32_destroy (map); | 778 | GNUNET_CONTAINER_multihashmap32_destroy(map); |
779 | map = NULL; | 779 | map = NULL; |
780 | } | 780 | } |
781 | while (NULL != (entry = head_lru)) | 781 | while (NULL != (entry = head_lru)) |
782 | { | 782 | { |
783 | GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry); | 783 | GNUNET_CONTAINER_DLL_remove(head_lru, tail_lru, entry); |
784 | destroy_pooled_connection (entry); | 784 | destroy_pooled_connection(entry); |
785 | } | 785 | } |
786 | GNUNET_assert (NULL == head_not_pooled); | 786 | GNUNET_assert(NULL == head_not_pooled); |
787 | } | 787 | } |
788 | 788 | ||
789 | 789 | ||
@@ -820,7 +820,7 @@ GST_connection_pool_destroy () | |||
820 | * longer being used | 820 | * longer being used |
821 | */ | 821 | */ |
822 | struct GST_ConnectionPool_GetHandle * | 822 | struct GST_ConnectionPool_GetHandle * |
823 | GST_connection_pool_get_handle ( | 823 | GST_connection_pool_get_handle( |
824 | unsigned int peer_id, | 824 | unsigned int peer_id, |
825 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 825 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
826 | enum GST_ConnectionPool_Service service, | 826 | enum GST_ConnectionPool_Service service, |
@@ -836,64 +836,66 @@ GST_connection_pool_get_handle ( | |||
836 | void *handle; | 836 | void *handle; |
837 | uint32_t peer_id32; | 837 | uint32_t peer_id32; |
838 | 838 | ||
839 | peer_id32 = (uint32_t) peer_id; | 839 | peer_id32 = (uint32_t)peer_id; |
840 | handle = NULL; | 840 | handle = NULL; |
841 | entry = NULL; | 841 | entry = NULL; |
842 | if (NULL != map) | 842 | if (NULL != map) |
843 | entry = GNUNET_CONTAINER_multihashmap32_get (map, peer_id32); | 843 | entry = GNUNET_CONTAINER_multihashmap32_get(map, peer_id32); |
844 | if (NULL != entry) | 844 | if (NULL != entry) |
845 | { | ||
846 | if (entry->in_lru) | ||
847 | { | 845 | { |
848 | GNUNET_assert (0 == entry->demand); | 846 | if (entry->in_lru) |
849 | expire_task_cancel (entry); | 847 | { |
850 | GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry); | 848 | GNUNET_assert(0 == entry->demand); |
851 | entry->in_lru = GNUNET_NO; | 849 | expire_task_cancel(entry); |
850 | GNUNET_CONTAINER_DLL_remove(head_lru, tail_lru, entry); | ||
851 | entry->in_lru = GNUNET_NO; | ||
852 | } | ||
853 | switch (service) | ||
854 | { | ||
855 | case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: | ||
856 | handle = entry->handle_transport; | ||
857 | if (NULL != handle) | ||
858 | LOG_DEBUG("Found TRANSPORT handle for peer %u\n", entry->index); | ||
859 | break; | ||
860 | |||
861 | case GST_CONNECTIONPOOL_SERVICE_CORE: | ||
862 | handle = entry->handle_core; | ||
863 | if (NULL != handle) | ||
864 | LOG_DEBUG("Found CORE handle for peer %u\n", entry->index); | ||
865 | break; | ||
866 | |||
867 | case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: | ||
868 | handle = entry->handle_ats_connectivity; | ||
869 | if (NULL != handle) | ||
870 | LOG_DEBUG("Found ATS CONNECTIVITY handle for peer %u\n", entry->index); | ||
871 | break; | ||
872 | } | ||
852 | } | 873 | } |
853 | switch (service) | ||
854 | { | ||
855 | case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: | ||
856 | handle = entry->handle_transport; | ||
857 | if (NULL != handle) | ||
858 | LOG_DEBUG ("Found TRANSPORT handle for peer %u\n", entry->index); | ||
859 | break; | ||
860 | case GST_CONNECTIONPOOL_SERVICE_CORE: | ||
861 | handle = entry->handle_core; | ||
862 | if (NULL != handle) | ||
863 | LOG_DEBUG ("Found CORE handle for peer %u\n", entry->index); | ||
864 | break; | ||
865 | case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: | ||
866 | handle = entry->handle_ats_connectivity; | ||
867 | if (NULL != handle) | ||
868 | LOG_DEBUG ("Found ATS CONNECTIVITY handle for peer %u\n", entry->index); | ||
869 | break; | ||
870 | } | ||
871 | } | ||
872 | else | 874 | else |
873 | { | ||
874 | entry = GNUNET_new (struct PooledConnection); | ||
875 | entry->index = peer_id32; | ||
876 | if ((NULL != map) && | ||
877 | (GNUNET_CONTAINER_multihashmap32_size (map) < max_size)) | ||
878 | { | 875 | { |
879 | GNUNET_assert (GNUNET_OK == | 876 | entry = GNUNET_new(struct PooledConnection); |
880 | GNUNET_CONTAINER_multihashmap32_put ( | 877 | entry->index = peer_id32; |
881 | map, | 878 | if ((NULL != map) && |
882 | entry->index, | 879 | (GNUNET_CONTAINER_multihashmap32_size(map) < max_size)) |
883 | entry, | 880 | { |
884 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 881 | GNUNET_assert(GNUNET_OK == |
885 | entry->in_pool = GNUNET_YES; | 882 | GNUNET_CONTAINER_multihashmap32_put( |
886 | } | 883 | map, |
887 | else | 884 | entry->index, |
888 | { | 885 | entry, |
889 | GNUNET_CONTAINER_DLL_insert_tail (head_not_pooled, | 886 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
890 | tail_not_pooled, | 887 | entry->in_pool = GNUNET_YES; |
891 | entry); | 888 | } |
889 | else | ||
890 | { | ||
891 | GNUNET_CONTAINER_DLL_insert_tail(head_not_pooled, | ||
892 | tail_not_pooled, | ||
893 | entry); | ||
894 | } | ||
895 | entry->cfg = GNUNET_CONFIGURATION_dup(cfg); | ||
892 | } | 896 | } |
893 | entry->cfg = GNUNET_CONFIGURATION_dup (cfg); | ||
894 | } | ||
895 | entry->demand++; | 897 | entry->demand++; |
896 | gh = GNUNET_new (struct GST_ConnectionPool_GetHandle); | 898 | gh = GNUNET_new(struct GST_ConnectionPool_GetHandle); |
897 | gh->entry = entry; | 899 | gh->entry = entry; |
898 | gh->cb = cb; | 900 | gh->cb = cb; |
899 | gh->cb_cls = cb_cls; | 901 | gh->cb_cls = cb_cls; |
@@ -901,48 +903,50 @@ GST_connection_pool_get_handle ( | |||
901 | gh->connect_notify_cb = connect_notify_cb; | 903 | gh->connect_notify_cb = connect_notify_cb; |
902 | gh->connect_notify_cb_cls = connect_notify_cb_cls; | 904 | gh->connect_notify_cb_cls = connect_notify_cb_cls; |
903 | gh->service = service; | 905 | gh->service = service; |
904 | GNUNET_CONTAINER_DLL_insert (entry->head_waiting, entry->tail_waiting, gh); | 906 | GNUNET_CONTAINER_DLL_insert(entry->head_waiting, entry->tail_waiting, gh); |
905 | if (NULL != handle) | 907 | if (NULL != handle) |
906 | { | ||
907 | if (NULL == entry->notify_task) | ||
908 | { | 908 | { |
909 | if (NULL != search_waiting (entry, entry->head_waiting)) | 909 | if (NULL == entry->notify_task) |
910 | entry->notify_task = | 910 | { |
911 | GNUNET_SCHEDULER_add_now (&connection_ready, entry); | 911 | if (NULL != search_waiting(entry, entry->head_waiting)) |
912 | entry->notify_task = | ||
913 | GNUNET_SCHEDULER_add_now(&connection_ready, entry); | ||
914 | } | ||
915 | return gh; | ||
912 | } | 916 | } |
913 | return gh; | ||
914 | } | ||
915 | op = NULL; | 917 | op = NULL; |
916 | switch (gh->service) | 918 | switch (gh->service) |
917 | { | 919 | { |
918 | case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: | 920 | case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: |
919 | if (NULL != entry->op_transport) | 921 | if (NULL != entry->op_transport) |
920 | return gh; /* Operation pending */ | 922 | return gh; /* Operation pending */ |
921 | op = GNUNET_TESTBED_operation_create_ (entry, | 923 | op = GNUNET_TESTBED_operation_create_(entry, |
922 | &opstart_get_handle_transport, | 924 | &opstart_get_handle_transport, |
923 | &oprelease_get_handle_transport); | 925 | &oprelease_get_handle_transport); |
924 | entry->op_transport = op; | 926 | entry->op_transport = op; |
925 | break; | 927 | break; |
926 | case GST_CONNECTIONPOOL_SERVICE_CORE: | 928 | |
927 | if (NULL != entry->op_core) | 929 | case GST_CONNECTIONPOOL_SERVICE_CORE: |
928 | return gh; /* Operation pending */ | 930 | if (NULL != entry->op_core) |
929 | op = GNUNET_TESTBED_operation_create_ (entry, | 931 | return gh; /* Operation pending */ |
930 | &opstart_get_handle_core, | 932 | op = GNUNET_TESTBED_operation_create_(entry, |
931 | &oprelease_get_handle_core); | 933 | &opstart_get_handle_core, |
932 | entry->op_core = op; | 934 | &oprelease_get_handle_core); |
933 | break; | 935 | entry->op_core = op; |
934 | case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: | 936 | break; |
935 | if (NULL != entry->op_ats_connectivity) | 937 | |
936 | return gh; /* Operation pending */ | 938 | case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: |
937 | op = | 939 | if (NULL != entry->op_ats_connectivity) |
938 | GNUNET_TESTBED_operation_create_ (entry, | 940 | return gh; /* Operation pending */ |
939 | &opstart_get_handle_ats_connectivity, | 941 | op = |
940 | &oprelease_get_handle_ats_connectivity); | 942 | GNUNET_TESTBED_operation_create_(entry, |
941 | entry->op_ats_connectivity = op; | 943 | &opstart_get_handle_ats_connectivity, |
942 | break; | 944 | &oprelease_get_handle_ats_connectivity); |
943 | } | 945 | entry->op_ats_connectivity = op; |
944 | GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, op); | 946 | break; |
945 | GNUNET_TESTBED_operation_begin_wait_ (op); | 947 | } |
948 | GNUNET_TESTBED_operation_queue_insert_(GST_opq_openfds, op); | ||
949 | GNUNET_TESTBED_operation_begin_wait_(op); | ||
946 | return gh; | 950 | return gh; |
947 | } | 951 | } |
948 | 952 | ||
@@ -960,66 +964,66 @@ GST_connection_pool_get_handle ( | |||
960 | * @param gh the handle | 964 | * @param gh the handle |
961 | */ | 965 | */ |
962 | void | 966 | void |
963 | GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh) | 967 | GST_connection_pool_get_handle_done(struct GST_ConnectionPool_GetHandle *gh) |
964 | { | 968 | { |
965 | struct PooledConnection *entry; | 969 | struct PooledConnection *entry; |
966 | 970 | ||
967 | if (NULL == gh) | 971 | if (NULL == gh) |
968 | return; | 972 | return; |
969 | entry = gh->entry; | 973 | entry = gh->entry; |
970 | LOG_DEBUG ("Cleaning up get handle %p for service %u, peer %u\n", | 974 | LOG_DEBUG("Cleaning up get handle %p for service %u, peer %u\n", |
971 | gh, | 975 | gh, |
972 | gh->service, | 976 | gh->service, |
973 | entry->index); | 977 | entry->index); |
974 | if (! gh->connection_ready_called) | 978 | if (!gh->connection_ready_called) |
975 | { | ||
976 | GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh); | ||
977 | if ((NULL == search_waiting (entry, entry->head_waiting)) && | ||
978 | (NULL != entry->notify_task)) | ||
979 | { | 979 | { |
980 | GNUNET_SCHEDULER_cancel (entry->notify_task); | 980 | GNUNET_CONTAINER_DLL_remove(entry->head_waiting, entry->tail_waiting, gh); |
981 | entry->notify_task = NULL; | 981 | if ((NULL == search_waiting(entry, entry->head_waiting)) && |
982 | (NULL != entry->notify_task)) | ||
983 | { | ||
984 | GNUNET_SCHEDULER_cancel(entry->notify_task); | ||
985 | entry->notify_task = NULL; | ||
986 | } | ||
982 | } | 987 | } |
983 | } | ||
984 | if (gh->notify_waiting) | 988 | if (gh->notify_waiting) |
985 | { | 989 | { |
986 | GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh); | 990 | GNUNET_CONTAINER_DLL_remove(entry->head_notify, entry->tail_notify, gh); |
987 | gh->notify_waiting = 0; | 991 | gh->notify_waiting = 0; |
988 | } | 992 | } |
989 | GNUNET_free (gh); | 993 | GNUNET_free(gh); |
990 | gh = NULL; | 994 | gh = NULL; |
991 | GNUNET_assert (! entry->in_lru); | 995 | GNUNET_assert(!entry->in_lru); |
992 | if (! entry->in_pool) | 996 | if (!entry->in_pool) |
993 | GNUNET_CONTAINER_DLL_remove (head_not_pooled, tail_not_pooled, entry); | 997 | GNUNET_CONTAINER_DLL_remove(head_not_pooled, tail_not_pooled, entry); |
994 | if (NULL != map) | 998 | if (NULL != map) |
995 | { | ||
996 | if (GNUNET_YES == | ||
997 | GNUNET_CONTAINER_multihashmap32_contains (map, entry->index)) | ||
998 | goto unallocate; | ||
999 | if (GNUNET_CONTAINER_multihashmap32_size (map) == max_size) | ||
1000 | { | 999 | { |
1001 | if (NULL == head_lru) | 1000 | if (GNUNET_YES == |
1001 | GNUNET_CONTAINER_multihashmap32_contains(map, entry->index)) | ||
1002 | goto unallocate; | 1002 | goto unallocate; |
1003 | destroy_pooled_connection (head_lru); | 1003 | if (GNUNET_CONTAINER_multihashmap32_size(map) == max_size) |
1004 | { | ||
1005 | if (NULL == head_lru) | ||
1006 | goto unallocate; | ||
1007 | destroy_pooled_connection(head_lru); | ||
1008 | } | ||
1009 | GNUNET_assert(GNUNET_OK == | ||
1010 | GNUNET_CONTAINER_multihashmap32_put( | ||
1011 | map, | ||
1012 | entry->index, | ||
1013 | entry, | ||
1014 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1015 | entry->in_pool = GNUNET_YES; | ||
1004 | } | 1016 | } |
1005 | GNUNET_assert (GNUNET_OK == | ||
1006 | GNUNET_CONTAINER_multihashmap32_put ( | ||
1007 | map, | ||
1008 | entry->index, | ||
1009 | entry, | ||
1010 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1011 | entry->in_pool = GNUNET_YES; | ||
1012 | } | ||
1013 | 1017 | ||
1014 | unallocate: | 1018 | unallocate: |
1015 | GNUNET_assert (0 < entry->demand); | 1019 | GNUNET_assert(0 < entry->demand); |
1016 | entry->demand--; | 1020 | entry->demand--; |
1017 | if (0 != entry->demand) | 1021 | if (0 != entry->demand) |
1018 | return; | 1022 | return; |
1019 | if (entry->in_pool) | 1023 | if (entry->in_pool) |
1020 | { | 1024 | { |
1021 | add_to_lru (entry); | 1025 | add_to_lru(entry); |
1022 | return; | 1026 | return; |
1023 | } | 1027 | } |
1024 | destroy_pooled_connection (entry); | 1028 | destroy_pooled_connection(entry); |
1025 | } | 1029 | } |
diff --git a/src/testbed/gnunet-service-testbed_connectionpool.h b/src/testbed/gnunet-service-testbed_connectionpool.h index 558918c30..40c937353 100644 --- a/src/testbed/gnunet-service-testbed_connectionpool.h +++ b/src/testbed/gnunet-service-testbed_connectionpool.h | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2015 GNUnet e.V. | 3 | Copyright (C) 2008--2015 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/gnunet-service-testbed_connectionpool.h | 22 | * @file testbed/gnunet-service-testbed_connectionpool.h |
@@ -36,8 +36,7 @@ struct GST_ConnectionPool_GetHandle; | |||
36 | /** | 36 | /** |
37 | * The type of service | 37 | * The type of service |
38 | */ | 38 | */ |
39 | enum GST_ConnectionPool_Service | 39 | enum GST_ConnectionPool_Service { |
40 | { | ||
41 | /** | 40 | /** |
42 | * Transport service | 41 | * Transport service |
43 | */ | 42 | */ |
@@ -63,14 +62,14 @@ enum GST_ConnectionPool_Service | |||
63 | * #GST_ConnectionPool_Service | 62 | * #GST_ConnectionPool_Service |
64 | */ | 63 | */ |
65 | void | 64 | void |
66 | GST_connection_pool_init (unsigned int size); | 65 | GST_connection_pool_init(unsigned int size); |
67 | 66 | ||
68 | 67 | ||
69 | /** | 68 | /** |
70 | * Cleanup the connection pool | 69 | * Cleanup the connection pool |
71 | */ | 70 | */ |
72 | void | 71 | void |
73 | GST_connection_pool_destroy (void); | 72 | GST_connection_pool_destroy(void); |
74 | 73 | ||
75 | /** | 74 | /** |
76 | * Functions of this type are called when the needed handle is available for | 75 | * Functions of this type are called when the needed handle is available for |
@@ -142,7 +141,7 @@ typedef void (*GST_connection_pool_peer_connect_notify) ( | |||
142 | * longer being used | 141 | * longer being used |
143 | */ | 142 | */ |
144 | struct GST_ConnectionPool_GetHandle * | 143 | struct GST_ConnectionPool_GetHandle * |
145 | GST_connection_pool_get_handle ( | 144 | GST_connection_pool_get_handle( |
146 | unsigned int peer_id, | 145 | unsigned int peer_id, |
147 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 146 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
148 | enum GST_ConnectionPool_Service service, | 147 | enum GST_ConnectionPool_Service service, |
@@ -166,7 +165,7 @@ GST_connection_pool_get_handle ( | |||
166 | * @param gh the handle | 165 | * @param gh the handle |
167 | */ | 166 | */ |
168 | void | 167 | void |
169 | GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh); | 168 | GST_connection_pool_get_handle_done(struct GST_ConnectionPool_GetHandle *gh); |
170 | 169 | ||
171 | 170 | ||
172 | /* End of gnunet-service-testbed_connectionpool.h */ | 171 | /* End of gnunet-service-testbed_connectionpool.h */ |
diff --git a/src/testbed/gnunet-service-testbed_cpustatus.c b/src/testbed/gnunet-service-testbed_cpustatus.c index d715036c7..a8796ea11 100644 --- a/src/testbed/gnunet-service-testbed_cpustatus.c +++ b/src/testbed/gnunet-service-testbed_cpustatus.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/gnunet-service-testbed_cpustatus.c | 22 | * @file testbed/gnunet-service-testbed_cpustatus.c |
@@ -90,7 +90,7 @@ struct GNUNET_SCHEDULER_Task * sample_load_task_id; | |||
90 | 90 | ||
91 | #ifdef OSX | 91 | #ifdef OSX |
92 | static int | 92 | static int |
93 | initMachCpuStats () | 93 | initMachCpuStats() |
94 | { | 94 | { |
95 | unsigned int cpu_count; | 95 | unsigned int cpu_count; |
96 | processor_cpu_load_info_t cpu_load; | 96 | processor_cpu_load_info_t cpu_load; |
@@ -98,17 +98,17 @@ initMachCpuStats () | |||
98 | kern_return_t kret; | 98 | kern_return_t kret; |
99 | int i, j; | 99 | int i, j; |
100 | 100 | ||
101 | kret = host_processor_info (mach_host_self (), | 101 | kret = host_processor_info(mach_host_self(), |
102 | PROCESSOR_CPU_LOAD_INFO, | 102 | PROCESSOR_CPU_LOAD_INFO, |
103 | &cpu_count, | 103 | &cpu_count, |
104 | (processor_info_array_t *) & cpu_load, | 104 | (processor_info_array_t *)&cpu_load, |
105 | &cpu_msg_count); | 105 | &cpu_msg_count); |
106 | if (kret != KERN_SUCCESS) | 106 | if (kret != KERN_SUCCESS) |
107 | { | 107 | { |
108 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "host_processor_info failed."); | 108 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "host_processor_info failed."); |
109 | return GNUNET_SYSERR; | 109 | return GNUNET_SYSERR; |
110 | } | 110 | } |
111 | prev_cpu_load = GNUNET_malloc (cpu_count * sizeof (*prev_cpu_load)); | 111 | prev_cpu_load = GNUNET_malloc(cpu_count * sizeof(*prev_cpu_load)); |
112 | for (i = 0; i < cpu_count; i++) | 112 | for (i = 0; i < cpu_count; i++) |
113 | { | 113 | { |
114 | for (j = 0; j < CPU_STATE_MAX; j++) | 114 | for (j = 0; j < CPU_STATE_MAX; j++) |
@@ -116,9 +116,9 @@ initMachCpuStats () | |||
116 | prev_cpu_load[i].cpu_ticks[j] = cpu_load[i].cpu_ticks[j]; | 116 | prev_cpu_load[i].cpu_ticks[j] = cpu_load[i].cpu_ticks[j]; |
117 | } | 117 | } |
118 | } | 118 | } |
119 | vm_deallocate (mach_task_self (), | 119 | vm_deallocate(mach_task_self(), |
120 | (vm_address_t) cpu_load, | 120 | (vm_address_t)cpu_load, |
121 | (vm_size_t) (cpu_msg_count * sizeof (*cpu_load))); | 121 | (vm_size_t)(cpu_msg_count * sizeof(*cpu_load))); |
122 | return GNUNET_OK; | 122 | return GNUNET_OK; |
123 | } | 123 | } |
124 | #endif | 124 | #endif |
@@ -130,7 +130,7 @@ initMachCpuStats () | |||
130 | * If there is an error the method returns -1. | 130 | * If there is an error the method returns -1. |
131 | */ | 131 | */ |
132 | static int | 132 | static int |
133 | updateUsage () | 133 | updateUsage() |
134 | { | 134 | { |
135 | currentIOLoad = -1; | 135 | currentIOLoad = -1; |
136 | currentCPULoad = -1; | 136 | currentCPULoad = -1; |
@@ -145,30 +145,30 @@ updateUsage () | |||
145 | int ret; | 145 | int ret; |
146 | char line[256]; | 146 | char line[256]; |
147 | unsigned long long user_read, system_read, nice_read, idle_read, | 147 | unsigned long long user_read, system_read, nice_read, idle_read, |
148 | iowait_read; | 148 | iowait_read; |
149 | unsigned long long user, system, nice, idle, iowait; | 149 | unsigned long long user, system, nice, idle, iowait; |
150 | unsigned long long usage_time = 0, total_time = 1; | 150 | unsigned long long usage_time = 0, total_time = 1; |
151 | 151 | ||
152 | /* Get the first line with the data */ | 152 | /* Get the first line with the data */ |
153 | rewind (proc_stat); | 153 | rewind(proc_stat); |
154 | fflush (proc_stat); | 154 | fflush(proc_stat); |
155 | if (NULL == fgets (line, 256, proc_stat)) | 155 | if (NULL == fgets(line, 256, proc_stat)) |
156 | { | 156 | { |
157 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 157 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, |
158 | "fgets", "/proc/stat"); | 158 | "fgets", "/proc/stat"); |
159 | proc_stat = NULL; /* don't try again */ | 159 | proc_stat = NULL; /* don't try again */ |
160 | } | 160 | } |
161 | else | 161 | else |
162 | { | 162 | { |
163 | iowait_read = 0; | 163 | iowait_read = 0; |
164 | ret = sscanf (line, "%*s %llu %llu %llu %llu %llu", | 164 | ret = sscanf(line, "%*s %llu %llu %llu %llu %llu", |
165 | &user_read, | 165 | &user_read, |
166 | &system_read, &nice_read, &idle_read, &iowait_read); | 166 | &system_read, &nice_read, &idle_read, &iowait_read); |
167 | if (ret < 4) | 167 | if (ret < 4) |
168 | { | 168 | { |
169 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 169 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, |
170 | "fgets-sscanf", "/proc/stat"); | 170 | "fgets-sscanf", "/proc/stat"); |
171 | fclose (proc_stat); | 171 | fclose(proc_stat); |
172 | proc_stat = NULL; /* don't try again */ | 172 | proc_stat = NULL; /* don't try again */ |
173 | have_last_cpu = GNUNET_NO; | 173 | have_last_cpu = GNUNET_NO; |
174 | } | 174 | } |
@@ -185,9 +185,9 @@ updateUsage () | |||
185 | total_time = usage_time + idle + iowait; | 185 | total_time = usage_time + idle + iowait; |
186 | if ((total_time > 0) && (have_last_cpu == GNUNET_YES)) | 186 | if ((total_time > 0) && (have_last_cpu == GNUNET_YES)) |
187 | { | 187 | { |
188 | currentCPULoad = (int) (100L * usage_time / total_time); | 188 | currentCPULoad = (int)(100L * usage_time / total_time); |
189 | if (ret > 4) | 189 | if (ret > 4) |
190 | currentIOLoad = (int) (100L * iowait / total_time); | 190 | currentIOLoad = (int)(100L * iowait / total_time); |
191 | else | 191 | else |
192 | currentIOLoad = -1; /* 2.4 kernel */ | 192 | currentIOLoad = -1; /* 2.4 kernel */ |
193 | } | 193 | } |
@@ -215,10 +215,10 @@ updateUsage () | |||
215 | int i, j; | 215 | int i, j; |
216 | 216 | ||
217 | t_idle_all = t_total_all = 0; | 217 | t_idle_all = t_total_all = 0; |
218 | kret = host_processor_info (mach_host_self (), PROCESSOR_CPU_LOAD_INFO, | 218 | kret = host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, |
219 | &cpu_count, | 219 | &cpu_count, |
220 | (processor_info_array_t *) & cpu_load, | 220 | (processor_info_array_t *)&cpu_load, |
221 | &cpu_msg_count); | 221 | &cpu_msg_count); |
222 | if (kret == KERN_SUCCESS) | 222 | if (kret == KERN_SUCCESS) |
223 | { | 223 | { |
224 | for (i = 0; i < cpu_count; i++) | 224 | for (i = 0; i < cpu_count; i++) |
@@ -227,52 +227,52 @@ updateUsage () | |||
227 | prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM]) | 227 | prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM]) |
228 | { | 228 | { |
229 | t_sys = cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM] - | 229 | t_sys = cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM] - |
230 | prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM]; | 230 | prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM]; |
231 | } | 231 | } |
232 | else | 232 | else |
233 | { | 233 | { |
234 | t_sys = cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM] + | 234 | t_sys = cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM] + |
235 | (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM] + | 235 | (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM] + |
236 | 1); | 236 | 1); |
237 | } | 237 | } |
238 | 238 | ||
239 | if (cpu_load[i].cpu_ticks[CPU_STATE_USER] >= | 239 | if (cpu_load[i].cpu_ticks[CPU_STATE_USER] >= |
240 | prev_cpu_load[i].cpu_ticks[CPU_STATE_USER]) | 240 | prev_cpu_load[i].cpu_ticks[CPU_STATE_USER]) |
241 | { | 241 | { |
242 | t_user = cpu_load[i].cpu_ticks[CPU_STATE_USER] - | 242 | t_user = cpu_load[i].cpu_ticks[CPU_STATE_USER] - |
243 | prev_cpu_load[i].cpu_ticks[CPU_STATE_USER]; | 243 | prev_cpu_load[i].cpu_ticks[CPU_STATE_USER]; |
244 | } | 244 | } |
245 | else | 245 | else |
246 | { | 246 | { |
247 | t_user = cpu_load[i].cpu_ticks[CPU_STATE_USER] + | 247 | t_user = cpu_load[i].cpu_ticks[CPU_STATE_USER] + |
248 | (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_USER] + | 248 | (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_USER] + |
249 | 1); | 249 | 1); |
250 | } | 250 | } |
251 | 251 | ||
252 | if (cpu_load[i].cpu_ticks[CPU_STATE_NICE] >= | 252 | if (cpu_load[i].cpu_ticks[CPU_STATE_NICE] >= |
253 | prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE]) | 253 | prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE]) |
254 | { | 254 | { |
255 | t_nice = cpu_load[i].cpu_ticks[CPU_STATE_NICE] - | 255 | t_nice = cpu_load[i].cpu_ticks[CPU_STATE_NICE] - |
256 | prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE]; | 256 | prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE]; |
257 | } | 257 | } |
258 | else | 258 | else |
259 | { | 259 | { |
260 | t_nice = cpu_load[i].cpu_ticks[CPU_STATE_NICE] + | 260 | t_nice = cpu_load[i].cpu_ticks[CPU_STATE_NICE] + |
261 | (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE] + | 261 | (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE] + |
262 | 1); | 262 | 1); |
263 | } | 263 | } |
264 | 264 | ||
265 | if (cpu_load[i].cpu_ticks[CPU_STATE_IDLE] >= | 265 | if (cpu_load[i].cpu_ticks[CPU_STATE_IDLE] >= |
266 | prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE]) | 266 | prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE]) |
267 | { | 267 | { |
268 | t_idle = cpu_load[i].cpu_ticks[CPU_STATE_IDLE] - | 268 | t_idle = cpu_load[i].cpu_ticks[CPU_STATE_IDLE] - |
269 | prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE]; | 269 | prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE]; |
270 | } | 270 | } |
271 | else | 271 | else |
272 | { | 272 | { |
273 | t_idle = cpu_load[i].cpu_ticks[CPU_STATE_IDLE] + | 273 | t_idle = cpu_load[i].cpu_ticks[CPU_STATE_IDLE] + |
274 | (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE] + | 274 | (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE] + |
275 | 1); | 275 | 1); |
276 | } | 276 | } |
277 | t_total = t_sys + t_user + t_nice + t_idle; | 277 | t_total = t_sys + t_user + t_nice + t_idle; |
278 | t_idle_all += t_idle; | 278 | t_idle_all += t_idle; |
@@ -289,15 +289,15 @@ updateUsage () | |||
289 | currentCPULoad = 100 - (100 * t_idle_all) / t_total_all; | 289 | currentCPULoad = 100 - (100 * t_idle_all) / t_total_all; |
290 | else | 290 | else |
291 | currentCPULoad = -1; | 291 | currentCPULoad = -1; |
292 | vm_deallocate (mach_task_self (), | 292 | vm_deallocate(mach_task_self(), |
293 | (vm_address_t) cpu_load, | 293 | (vm_address_t)cpu_load, |
294 | (vm_size_t) (cpu_msg_count * sizeof (*cpu_load))); | 294 | (vm_size_t)(cpu_msg_count * sizeof(*cpu_load))); |
295 | currentIOLoad = -1; /* FIXME-OSX! */ | 295 | currentIOLoad = -1; /* FIXME-OSX! */ |
296 | return GNUNET_OK; | 296 | return GNUNET_OK; |
297 | } | 297 | } |
298 | else | 298 | else |
299 | { | 299 | { |
300 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "host_processor_info failed."); | 300 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "host_processor_info failed."); |
301 | return GNUNET_SYSERR; | 301 | return GNUNET_SYSERR; |
302 | } | 302 | } |
303 | } | 303 | } |
@@ -318,10 +318,10 @@ updateUsage () | |||
318 | 318 | ||
319 | if (kstat_once == 1) | 319 | if (kstat_once == 1) |
320 | goto ABORT_KSTAT; | 320 | goto ABORT_KSTAT; |
321 | kc = kstat_open (); | 321 | kc = kstat_open(); |
322 | if (kc == NULL) | 322 | if (kc == NULL) |
323 | { | 323 | { |
324 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kstat_close"); | 324 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kstat_close"); |
325 | goto ABORT_KSTAT; | 325 | goto ABORT_KSTAT; |
326 | } | 326 | } |
327 | 327 | ||
@@ -331,29 +331,29 @@ updateUsage () | |||
331 | { | 331 | { |
332 | cpu_stat_t stats; | 332 | cpu_stat_t stats; |
333 | 333 | ||
334 | if (0 != strncmp (khelper->ks_name, "cpu_stat", strlen ("cpu_stat"))) | 334 | if (0 != strncmp(khelper->ks_name, "cpu_stat", strlen("cpu_stat"))) |
335 | continue; | 335 | continue; |
336 | if (khelper->ks_data_size > sizeof (cpu_stat_t)) | 336 | if (khelper->ks_data_size > sizeof(cpu_stat_t)) |
337 | continue; /* better save then sorry! */ | 337 | continue; /* better save then sorry! */ |
338 | if (-1 != kstat_read (kc, khelper, &stats)) | 338 | if (-1 != kstat_read(kc, khelper, &stats)) |
339 | { | 339 | { |
340 | idlecount += stats.cpu_sysinfo.cpu[CPU_IDLE]; | 340 | idlecount += stats.cpu_sysinfo.cpu[CPU_IDLE]; |
341 | totalcount | 341 | totalcount |
342 | += stats.cpu_sysinfo.cpu[CPU_IDLE] + | 342 | += stats.cpu_sysinfo.cpu[CPU_IDLE] + |
343 | stats.cpu_sysinfo.cpu[CPU_USER] + | 343 | stats.cpu_sysinfo.cpu[CPU_USER] + |
344 | stats.cpu_sysinfo.cpu[CPU_KERNEL] + | 344 | stats.cpu_sysinfo.cpu[CPU_KERNEL] + |
345 | stats.cpu_sysinfo.cpu[CPU_WAIT]; | 345 | stats.cpu_sysinfo.cpu[CPU_WAIT]; |
346 | } | 346 | } |
347 | } | 347 | } |
348 | if (0 != kstat_close (kc)) | 348 | if (0 != kstat_close(kc)) |
349 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kstat_close"); | 349 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kstat_close"); |
350 | if ((idlecount == 0) && (totalcount == 0)) | 350 | if ((idlecount == 0) && (totalcount == 0)) |
351 | goto ABORT_KSTAT; /* no stats found => abort */ | 351 | goto ABORT_KSTAT; /* no stats found => abort */ |
352 | deltaidle = idlecount - last_idlecount; | 352 | deltaidle = idlecount - last_idlecount; |
353 | deltatotal = totalcount - last_totalcount; | 353 | deltatotal = totalcount - last_totalcount; |
354 | if ((deltatotal > 0) && (last_totalcount > 0)) | 354 | if ((deltatotal > 0) && (last_totalcount > 0)) |
355 | { | 355 | { |
356 | currentCPULoad = (unsigned int) (100.0 * deltaidle / deltatotal); | 356 | currentCPULoad = (unsigned int)(100.0 * deltaidle / deltatotal); |
357 | if (currentCPULoad > 100) | 357 | if (currentCPULoad > 100) |
358 | currentCPULoad = 100; /* odd */ | 358 | currentCPULoad = 100; /* odd */ |
359 | if (currentCPULoad < 0) | 359 | if (currentCPULoad < 0) |
@@ -366,7 +366,7 @@ updateUsage () | |||
366 | last_idlecount = idlecount; | 366 | last_idlecount = idlecount; |
367 | last_totalcount = totalcount; | 367 | last_totalcount = totalcount; |
368 | return GNUNET_OK; | 368 | return GNUNET_OK; |
369 | ABORT_KSTAT: | 369 | ABORT_KSTAT: |
370 | kstat_once = 1; /* failed, don't try again */ | 370 | kstat_once = 1; /* failed, don't try again */ |
371 | return GNUNET_SYSERR; | 371 | return GNUNET_SYSERR; |
372 | } | 372 | } |
@@ -380,21 +380,21 @@ updateUsage () | |||
380 | { | 380 | { |
381 | static int warnOnce = 0; | 381 | static int warnOnce = 0; |
382 | double loadavg; | 382 | double loadavg; |
383 | if (1 != getloadavg (&loadavg, 1)) | 383 | if (1 != getloadavg(&loadavg, 1)) |
384 | { | 384 | { |
385 | /* only warn once, if there is a problem with | 385 | /* only warn once, if there is a problem with |
386 | getloadavg, we're going to hit it frequently... */ | 386 | getloadavg, we're going to hit it frequently... */ |
387 | if (warnOnce == 0) | 387 | if (warnOnce == 0) |
388 | { | 388 | { |
389 | warnOnce = 1; | 389 | warnOnce = 1; |
390 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "getloadavg"); | 390 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "getloadavg"); |
391 | } | 391 | } |
392 | return GNUNET_SYSERR; | 392 | return GNUNET_SYSERR; |
393 | } | 393 | } |
394 | else | 394 | else |
395 | { | 395 | { |
396 | /* success with getloadavg */ | 396 | /* success with getloadavg */ |
397 | currentCPULoad = (int) (100 * loadavg); | 397 | currentCPULoad = (int)(100 * loadavg); |
398 | currentIOLoad = -1; /* FIXME */ | 398 | currentIOLoad = -1; /* FIXME */ |
399 | return GNUNET_OK; | 399 | return GNUNET_OK; |
400 | } | 400 | } |
@@ -416,14 +416,14 @@ updateUsage () | |||
416 | double dDiffUser; | 416 | double dDiffUser; |
417 | SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION theInfo; | 417 | SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION theInfo; |
418 | 418 | ||
419 | if (GNNtQuerySystemInformation (SystemProcessorPerformanceInformation, | 419 | if (GNNtQuerySystemInformation(SystemProcessorPerformanceInformation, |
420 | &theInfo, | 420 | &theInfo, |
421 | sizeof (theInfo), NULL) == NO_ERROR) | 421 | sizeof(theInfo), NULL) == NO_ERROR) |
422 | { | 422 | { |
423 | /* PORT-ME MINGW: Multi-processor? */ | 423 | /* PORT-ME MINGW: Multi-processor? */ |
424 | dKernel = Li2Double (theInfo.KernelTime); | 424 | dKernel = Li2Double(theInfo.KernelTime); |
425 | dIdle = Li2Double (theInfo.IdleTime); | 425 | dIdle = Li2Double(theInfo.IdleTime); |
426 | dUser = Li2Double (theInfo.UserTime); | 426 | dUser = Li2Double(theInfo.UserTime); |
427 | dDiffKernel = dKernel - dLastKernel; | 427 | dDiffKernel = dKernel - dLastKernel; |
428 | dDiffIdle = dIdle - dLastIdle; | 428 | dDiffIdle = dIdle - dLastIdle; |
429 | dDiffUser = dUser - dLastUser; | 429 | dDiffUser = dUser - dLastUser; |
@@ -450,8 +450,8 @@ updateUsage () | |||
450 | if (once == 0) | 450 | if (once == 0) |
451 | { | 451 | { |
452 | once = 1; | 452 | once = 1; |
453 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 453 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
454 | "Cannot query the CPU usage (Windows NT).\n"); | 454 | "Cannot query the CPU usage (Windows NT).\n"); |
455 | } | 455 | } |
456 | return GNUNET_SYSERR; | 456 | return GNUNET_SYSERR; |
457 | } | 457 | } |
@@ -462,48 +462,48 @@ updateUsage () | |||
462 | DWORD dwDataSize, dwType, dwDummy; | 462 | DWORD dwDataSize, dwType, dwDummy; |
463 | 463 | ||
464 | /* Start query */ | 464 | /* Start query */ |
465 | if (RegOpenKeyEx (HKEY_DYN_DATA, | 465 | if (RegOpenKeyEx(HKEY_DYN_DATA, |
466 | "PerfStats\\StartSrv", | 466 | "PerfStats\\StartSrv", |
467 | 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS) | 467 | 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS) |
468 | { | 468 | { |
469 | /* only warn once */ | 469 | /* only warn once */ |
470 | static int once = 0; | 470 | static int once = 0; |
471 | if (once == 0) | 471 | if (once == 0) |
472 | { | 472 | { |
473 | once = 1; | 473 | once = 1; |
474 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 474 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
475 | "Cannot query the CPU usage (Win 9x)\n"); | 475 | "Cannot query the CPU usage (Win 9x)\n"); |
476 | } | 476 | } |
477 | } | 477 | } |
478 | 478 | ||
479 | RegOpenKeyEx (HKEY_DYN_DATA, | 479 | RegOpenKeyEx(HKEY_DYN_DATA, |
480 | "PerfStats\\StartStat", 0, KEY_ALL_ACCESS, &hKey); | 480 | "PerfStats\\StartStat", 0, KEY_ALL_ACCESS, &hKey); |
481 | dwDataSize = sizeof (dwDummy); | 481 | dwDataSize = sizeof(dwDummy); |
482 | RegQueryValueEx (hKey, | 482 | RegQueryValueEx(hKey, |
483 | "KERNEL\\CPUUsage", | 483 | "KERNEL\\CPUUsage", |
484 | NULL, &dwType, (LPBYTE) & dwDummy, &dwDataSize); | 484 | NULL, &dwType, (LPBYTE)&dwDummy, &dwDataSize); |
485 | RegCloseKey (hKey); | 485 | RegCloseKey(hKey); |
486 | 486 | ||
487 | /* Get CPU usage */ | 487 | /* Get CPU usage */ |
488 | RegOpenKeyEx (HKEY_DYN_DATA, | 488 | RegOpenKeyEx(HKEY_DYN_DATA, |
489 | "PerfStats\\StatData", 0, KEY_ALL_ACCESS, &hKey); | 489 | "PerfStats\\StatData", 0, KEY_ALL_ACCESS, &hKey); |
490 | dwDataSize = sizeof (currentCPULoad); | 490 | dwDataSize = sizeof(currentCPULoad); |
491 | RegQueryValueEx (hKey, | 491 | RegQueryValueEx(hKey, |
492 | "KERNEL\\CPUUsage", | 492 | "KERNEL\\CPUUsage", |
493 | NULL, &dwType, (LPBYTE) & currentCPULoad, &dwDataSize); | 493 | NULL, &dwType, (LPBYTE)¤tCPULoad, &dwDataSize); |
494 | RegCloseKey (hKey); | 494 | RegCloseKey(hKey); |
495 | currentIOLoad = -1; /* FIXME-MINGW! */ | 495 | currentIOLoad = -1; /* FIXME-MINGW! */ |
496 | 496 | ||
497 | /* Stop query */ | 497 | /* Stop query */ |
498 | RegOpenKeyEx (HKEY_DYN_DATA, | 498 | RegOpenKeyEx(HKEY_DYN_DATA, |
499 | "PerfStats\\StopStat", 0, KEY_ALL_ACCESS, &hKey); | 499 | "PerfStats\\StopStat", 0, KEY_ALL_ACCESS, &hKey); |
500 | RegOpenKeyEx (HKEY_DYN_DATA, | 500 | RegOpenKeyEx(HKEY_DYN_DATA, |
501 | "PerfStats\\StopSrv", 0, KEY_ALL_ACCESS, &hKey); | 501 | "PerfStats\\StopSrv", 0, KEY_ALL_ACCESS, &hKey); |
502 | dwDataSize = sizeof (dwDummy); | 502 | dwDataSize = sizeof(dwDummy); |
503 | RegQueryValueEx (hKey, | 503 | RegQueryValueEx(hKey, |
504 | "KERNEL\\CPUUsage", | 504 | "KERNEL\\CPUUsage", |
505 | NULL, &dwType, (LPBYTE) & dwDummy, &dwDataSize); | 505 | NULL, &dwType, (LPBYTE)&dwDummy, &dwDataSize); |
506 | RegCloseKey (hKey); | 506 | RegCloseKey(hKey); |
507 | 507 | ||
508 | return GNUNET_OK; | 508 | return GNUNET_OK; |
509 | } | 509 | } |
@@ -523,21 +523,21 @@ updateUsage () | |||
523 | * that lock has already been obtained. | 523 | * that lock has already been obtained. |
524 | */ | 524 | */ |
525 | static void | 525 | static void |
526 | updateAgedLoad () | 526 | updateAgedLoad() |
527 | { | 527 | { |
528 | static struct GNUNET_TIME_Absolute lastCall; | 528 | static struct GNUNET_TIME_Absolute lastCall; |
529 | struct GNUNET_TIME_Relative age; | 529 | struct GNUNET_TIME_Relative age; |
530 | 530 | ||
531 | age = GNUNET_TIME_absolute_get_duration (lastCall); | 531 | age = GNUNET_TIME_absolute_get_duration(lastCall); |
532 | if ( (agedCPULoad == -1) | 532 | if ((agedCPULoad == -1) |
533 | || (age.rel_value_us > 500000) ) | 533 | || (age.rel_value_us > 500000)) |
534 | { | 534 | { |
535 | /* use smoothing, but do NOT update lastRet at frequencies higher | 535 | /* use smoothing, but do NOT update lastRet at frequencies higher |
536 | than 500ms; this makes the smoothing (mostly) independent from | 536 | than 500ms; this makes the smoothing (mostly) independent from |
537 | the frequency at which getCPULoad is called (and we don't spend | 537 | the frequency at which getCPULoad is called (and we don't spend |
538 | more time measuring CPU than actually computing something). */ | 538 | more time measuring CPU than actually computing something). */ |
539 | lastCall = GNUNET_TIME_absolute_get (); | 539 | lastCall = GNUNET_TIME_absolute_get(); |
540 | updateUsage (); | 540 | updateUsage(); |
541 | if (currentCPULoad == -1) | 541 | if (currentCPULoad == -1) |
542 | { | 542 | { |
543 | agedCPULoad = -1; | 543 | agedCPULoad = -1; |
@@ -581,10 +581,10 @@ updateAgedLoad () | |||
581 | * (100 is equivalent to full load) | 581 | * (100 is equivalent to full load) |
582 | */ | 582 | */ |
583 | static int | 583 | static int |
584 | cpu_get_load () | 584 | cpu_get_load() |
585 | { | 585 | { |
586 | updateAgedLoad (); | 586 | updateAgedLoad(); |
587 | return (int) agedCPULoad; | 587 | return (int)agedCPULoad; |
588 | } | 588 | } |
589 | 589 | ||
590 | 590 | ||
@@ -594,10 +594,10 @@ cpu_get_load () | |||
594 | * (100 is equivalent to full load) | 594 | * (100 is equivalent to full load) |
595 | */ | 595 | */ |
596 | static int | 596 | static int |
597 | disk_get_load () | 597 | disk_get_load() |
598 | { | 598 | { |
599 | updateAgedLoad (); | 599 | updateAgedLoad(); |
600 | return (int) agedIOLoad; | 600 | return (int)agedIOLoad; |
601 | } | 601 | } |
602 | 602 | ||
603 | /** | 603 | /** |
@@ -606,13 +606,13 @@ disk_get_load () | |||
606 | * @return the percentage of memory used | 606 | * @return the percentage of memory used |
607 | */ | 607 | */ |
608 | static unsigned int | 608 | static unsigned int |
609 | mem_get_usage () | 609 | mem_get_usage() |
610 | { | 610 | { |
611 | double percentage; | 611 | double percentage; |
612 | 612 | ||
613 | meminfo (); | 613 | meminfo(); |
614 | percentage = ( ((double) kb_main_used) / ((double) kb_main_total) * 100.0 ); | 614 | percentage = (((double)kb_main_used) / ((double)kb_main_total) * 100.0); |
615 | return (unsigned int) percentage; | 615 | return (unsigned int)percentage; |
616 | } | 616 | } |
617 | 617 | ||
618 | 618 | ||
@@ -624,29 +624,29 @@ mem_get_usage () | |||
624 | * @return the number of processes | 624 | * @return the number of processes |
625 | */ | 625 | */ |
626 | static unsigned int | 626 | static unsigned int |
627 | get_nproc () | 627 | get_nproc() |
628 | { | 628 | { |
629 | DIR *dir; | 629 | DIR *dir; |
630 | struct dirent *ent; | 630 | struct dirent *ent; |
631 | unsigned int nproc; | 631 | unsigned int nproc; |
632 | 632 | ||
633 | dir = opendir ("/proc"); | 633 | dir = opendir("/proc"); |
634 | if (NULL == dir) | 634 | if (NULL == dir) |
635 | return 0; | 635 | return 0; |
636 | nproc = 0; | 636 | nproc = 0; |
637 | while (NULL != (ent = readdir (dir))) | 637 | while (NULL != (ent = readdir(dir))) |
638 | { | 638 | { |
639 | if((*ent->d_name > '0') && (*ent->d_name <= '9')) | 639 | if ((*ent->d_name > '0') && (*ent->d_name <= '9')) |
640 | nproc++; | 640 | nproc++; |
641 | } | 641 | } |
642 | closedir (dir); | 642 | closedir(dir); |
643 | return nproc; | 643 | return nproc; |
644 | } | 644 | } |
645 | #endif | 645 | #endif |
646 | 646 | ||
647 | 647 | ||
648 | static void | 648 | static void |
649 | sample_load_task (void *cls) | 649 | sample_load_task(void *cls) |
650 | { | 650 | { |
651 | struct GNUNET_TIME_Absolute now; | 651 | struct GNUNET_TIME_Absolute now; |
652 | char *str; | 652 | char *str; |
@@ -657,31 +657,31 @@ sample_load_task (void *cls) | |||
657 | unsigned int nproc; | 657 | unsigned int nproc; |
658 | 658 | ||
659 | sample_load_task_id = NULL; | 659 | sample_load_task_id = NULL; |
660 | ld_cpu = cpu_get_load (); | 660 | ld_cpu = cpu_get_load(); |
661 | ld_disk = disk_get_load (); | 661 | ld_disk = disk_get_load(); |
662 | if ( (-1 == ld_cpu) || (-1 == ld_disk) ) | 662 | if ((-1 == ld_cpu) || (-1 == ld_disk)) |
663 | goto reschedule; | 663 | goto reschedule; |
664 | mem_usage = mem_get_usage (); | 664 | mem_usage = mem_get_usage(); |
665 | #ifdef LINUX | 665 | #ifdef LINUX |
666 | nproc = get_nproc (); | 666 | nproc = get_nproc(); |
667 | #else | 667 | #else |
668 | nproc = 0; | 668 | nproc = 0; |
669 | #endif | 669 | #endif |
670 | now = GNUNET_TIME_absolute_get (); | 670 | now = GNUNET_TIME_absolute_get(); |
671 | nbs = GNUNET_asprintf (&str, "%llu %d %d %u %u\n", now.abs_value_us / 1000LL / 1000LL, | 671 | nbs = GNUNET_asprintf(&str, "%llu %d %d %u %u\n", now.abs_value_us / 1000LL / 1000LL, |
672 | ld_cpu, ld_disk, mem_usage, nproc); | 672 | ld_cpu, ld_disk, mem_usage, nproc); |
673 | if (0 < nbs) | 673 | if (0 < nbs) |
674 | { | 674 | { |
675 | GNUNET_BIO_write (bw, str, nbs); | 675 | GNUNET_BIO_write(bw, str, nbs); |
676 | } | 676 | } |
677 | else | 677 | else |
678 | GNUNET_break (0); | 678 | GNUNET_break(0); |
679 | GNUNET_free (str); | 679 | GNUNET_free(str); |
680 | 680 | ||
681 | reschedule: | 681 | reschedule: |
682 | sample_load_task_id = | 682 | sample_load_task_id = |
683 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 683 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
684 | &sample_load_task, NULL); | 684 | &sample_load_task, NULL); |
685 | } | 685 | } |
686 | 686 | ||
687 | 687 | ||
@@ -691,7 +691,7 @@ sample_load_task (void *cls) | |||
691 | * generated from the hostname and the process's PID. | 691 | * generated from the hostname and the process's PID. |
692 | */ | 692 | */ |
693 | void | 693 | void |
694 | GST_stats_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | 694 | GST_stats_init(const struct GNUNET_CONFIGURATION_Handle *cfg) |
695 | { | 695 | { |
696 | char *hostname; | 696 | char *hostname; |
697 | char *stats_dir; | 697 | char *stats_dir; |
@@ -699,49 +699,48 @@ GST_stats_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
699 | size_t len; | 699 | size_t len; |
700 | 700 | ||
701 | #if MINGW | 701 | #if MINGW |
702 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 702 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
703 | "Load statistics logging now available for windows\n"); | 703 | "Load statistics logging now available for windows\n"); |
704 | return; /* No logging on windows for now :( */ | 704 | return; /* No logging on windows for now :( */ |
705 | #endif | 705 | #endif |
706 | 706 | ||
707 | if (GNUNET_OK != | 707 | if (GNUNET_OK != |
708 | GNUNET_CONFIGURATION_get_value_filename (cfg, "testbed", | 708 | GNUNET_CONFIGURATION_get_value_filename(cfg, "testbed", |
709 | "STATS_DIR", &stats_dir)) | 709 | "STATS_DIR", &stats_dir)) |
710 | return; | 710 | return; |
711 | len = GNUNET_OS_get_hostname_max_length (); | 711 | len = GNUNET_OS_get_hostname_max_length(); |
712 | hostname = GNUNET_malloc (len); | 712 | hostname = GNUNET_malloc(len); |
713 | if (0 != gethostname (hostname, len)) | 713 | if (0 != gethostname(hostname, len)) |
714 | { | 714 | { |
715 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "gethostname"); | 715 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "gethostname"); |
716 | GNUNET_free (stats_dir); | 716 | GNUNET_free(stats_dir); |
717 | GNUNET_free (hostname); | 717 | GNUNET_free(hostname); |
718 | return; | 718 | return; |
719 | } | 719 | } |
720 | fn = NULL; | 720 | fn = NULL; |
721 | (void) GNUNET_asprintf (&fn, "%s/%.*s-%jd.dat", stats_dir, len, | 721 | (void)GNUNET_asprintf(&fn, "%s/%.*s-%jd.dat", stats_dir, len, |
722 | hostname, (intmax_t) getpid()); | 722 | hostname, (intmax_t)getpid()); |
723 | GNUNET_free (stats_dir); | 723 | GNUNET_free(stats_dir); |
724 | GNUNET_free (hostname); | 724 | GNUNET_free(hostname); |
725 | if (NULL == (bw = GNUNET_BIO_write_open (fn))) | 725 | if (NULL == (bw = GNUNET_BIO_write_open(fn))) |
726 | { | 726 | { |
727 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 727 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
728 | _("Cannot open %s for writing load statistics. " | 728 | _("Cannot open %s for writing load statistics. " |
729 | "Not logging load statistics\n"), fn); | 729 | "Not logging load statistics\n"), fn); |
730 | GNUNET_free (fn); | 730 | GNUNET_free(fn); |
731 | return; | 731 | return; |
732 | } | 732 | } |
733 | GNUNET_free (fn); | 733 | GNUNET_free(fn); |
734 | sample_load_task_id = GNUNET_SCHEDULER_add_now (&sample_load_task, NULL); | 734 | sample_load_task_id = GNUNET_SCHEDULER_add_now(&sample_load_task, NULL); |
735 | #ifdef LINUX | 735 | #ifdef LINUX |
736 | proc_stat = fopen ("/proc/stat", "r"); | 736 | proc_stat = fopen("/proc/stat", "r"); |
737 | if (NULL == proc_stat) | 737 | if (NULL == proc_stat) |
738 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 738 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, |
739 | "fopen", "/proc/stat"); | 739 | "fopen", "/proc/stat"); |
740 | #elif OSX | 740 | #elif OSX |
741 | initMachCpuStats (); | 741 | initMachCpuStats(); |
742 | #endif | 742 | #endif |
743 | updateUsage (); /* initialize */ | 743 | updateUsage(); /* initialize */ |
744 | |||
745 | } | 744 | } |
746 | 745 | ||
747 | 746 | ||
@@ -749,7 +748,7 @@ GST_stats_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
749 | * Shutdown the status calls module. | 748 | * Shutdown the status calls module. |
750 | */ | 749 | */ |
751 | void | 750 | void |
752 | GST_stats_destroy () | 751 | GST_stats_destroy() |
753 | { | 752 | { |
754 | #if MINGW | 753 | #if MINGW |
755 | return; | 754 | return; |
@@ -759,18 +758,18 @@ GST_stats_destroy () | |||
759 | #ifdef LINUX | 758 | #ifdef LINUX |
760 | if (proc_stat != NULL) | 759 | if (proc_stat != NULL) |
761 | { | 760 | { |
762 | fclose (proc_stat); | 761 | fclose(proc_stat); |
763 | proc_stat = NULL; | 762 | proc_stat = NULL; |
764 | } | 763 | } |
765 | #elif OSX | 764 | #elif OSX |
766 | GNUNET_free_non_null (prev_cpu_load); | 765 | GNUNET_free_non_null(prev_cpu_load); |
767 | #endif | 766 | #endif |
768 | if (NULL != sample_load_task_id) | 767 | if (NULL != sample_load_task_id) |
769 | { | 768 | { |
770 | GNUNET_SCHEDULER_cancel (sample_load_task_id); | 769 | GNUNET_SCHEDULER_cancel(sample_load_task_id); |
771 | sample_load_task_id = NULL; | 770 | sample_load_task_id = NULL; |
772 | } | 771 | } |
773 | GNUNET_break (GNUNET_OK == GNUNET_BIO_write_close (bw)); | 772 | GNUNET_break(GNUNET_OK == GNUNET_BIO_write_close(bw)); |
774 | bw = NULL; | 773 | bw = NULL; |
775 | } | 774 | } |
776 | 775 | ||
diff --git a/src/testbed/gnunet-service-testbed_links.c b/src/testbed/gnunet-service-testbed_links.c index 62f65387e..d7715a16e 100644 --- a/src/testbed/gnunet-service-testbed_links.c +++ b/src/testbed/gnunet-service-testbed_links.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2013 GNUnet e.V. | 3 | Copyright (C) 2008--2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/gnunet-service-testbed_links.c | 22 | * @file testbed/gnunet-service-testbed_links.c |
@@ -33,8 +33,8 @@ | |||
33 | #ifdef LOG | 33 | #ifdef LOG |
34 | #undef LOG | 34 | #undef LOG |
35 | #endif | 35 | #endif |
36 | #define LOG(kind,...) \ | 36 | #define LOG(kind, ...) \ |
37 | GNUNET_log_from (kind, "testbed-links", __VA_ARGS__) | 37 | GNUNET_log_from(kind, "testbed-links", __VA_ARGS__) |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * The event mask for the events we listen from sub-controllers | 40 | * The event mask for the events we listen from sub-controllers |
@@ -45,8 +45,7 @@ | |||
45 | /** | 45 | /** |
46 | * States of LCFContext | 46 | * States of LCFContext |
47 | */ | 47 | */ |
48 | enum LCFContextState | 48 | enum LCFContextState { |
49 | { | ||
50 | /** | 49 | /** |
51 | * The Context has been initialized; Nothing has been done on it | 50 | * The Context has been initialized; Nothing has been done on it |
52 | */ | 51 | */ |
@@ -72,8 +71,7 @@ enum LCFContextState | |||
72 | /** | 71 | /** |
73 | * Link controllers request forwarding context | 72 | * Link controllers request forwarding context |
74 | */ | 73 | */ |
75 | struct LCFContext | 74 | struct LCFContext { |
76 | { | ||
77 | /** | 75 | /** |
78 | * The LCFContext | 76 | * The LCFContext |
79 | */ | 77 | */ |
@@ -128,7 +126,6 @@ struct LCFContext | |||
128 | * The slave host | 126 | * The slave host |
129 | */ | 127 | */ |
130 | uint32_t slave_host_id; | 128 | uint32_t slave_host_id; |
131 | |||
132 | }; | 129 | }; |
133 | 130 | ||
134 | 131 | ||
@@ -136,8 +133,7 @@ struct LCFContext | |||
136 | * Notification context to be used to notify when connection to the neighbour's | 133 | * Notification context to be used to notify when connection to the neighbour's |
137 | * controller is opened | 134 | * controller is opened |
138 | */ | 135 | */ |
139 | struct NeighbourConnectNotification | 136 | struct NeighbourConnectNotification { |
140 | { | ||
141 | /** | 137 | /** |
142 | * DLL next for inclusion in neighbour's list of notification requests | 138 | * DLL next for inclusion in neighbour's list of notification requests |
143 | */ | 139 | */ |
@@ -168,8 +164,7 @@ struct NeighbourConnectNotification | |||
168 | /** | 164 | /** |
169 | * A connected controller which is not our child | 165 | * A connected controller which is not our child |
170 | */ | 166 | */ |
171 | struct Neighbour | 167 | struct Neighbour { |
172 | { | ||
173 | /** | 168 | /** |
174 | * The controller handle | 169 | * The controller handle |
175 | */ | 170 | */ |
@@ -228,8 +223,7 @@ static unsigned int neighbour_list_size; | |||
228 | * Context information for establishing a link to neighbour (Used is | 223 | * Context information for establishing a link to neighbour (Used is |
229 | * GST_handle_link_controllers() | 224 | * GST_handle_link_controllers() |
230 | */ | 225 | */ |
231 | struct NeighbourConnectCtxt | 226 | struct NeighbourConnectCtxt { |
232 | { | ||
233 | /** | 227 | /** |
234 | * DLL next for inclusion in the corresponding context list | 228 | * DLL next for inclusion in the corresponding context list |
235 | */ | 229 | */ |
@@ -319,13 +313,13 @@ static unsigned int route_list_size; | |||
319 | * @param slave the slave controller to add | 313 | * @param slave the slave controller to add |
320 | */ | 314 | */ |
321 | static void | 315 | static void |
322 | slave_list_add (struct Slave *slave) | 316 | slave_list_add(struct Slave *slave) |
323 | { | 317 | { |
324 | if (slave->host_id >= GST_slave_list_size) | 318 | if (slave->host_id >= GST_slave_list_size) |
325 | GST_array_grow_large_enough (GST_slave_list, | 319 | GST_array_grow_large_enough(GST_slave_list, |
326 | GST_slave_list_size, | 320 | GST_slave_list_size, |
327 | slave->host_id); | 321 | slave->host_id); |
328 | GNUNET_assert (NULL == GST_slave_list[slave->host_id]); | 322 | GNUNET_assert(NULL == GST_slave_list[slave->host_id]); |
329 | GST_slave_list[slave->host_id] = slave; | 323 | GST_slave_list[slave->host_id] = slave; |
330 | } | 324 | } |
331 | 325 | ||
@@ -340,9 +334,9 @@ slave_list_add (struct Slave *slave) | |||
340 | * @return #GNUNET_OK (continue iterating) | 334 | * @return #GNUNET_OK (continue iterating) |
341 | */ | 335 | */ |
342 | static int | 336 | static int |
343 | drop_client_entries (void *cls, | 337 | drop_client_entries(void *cls, |
344 | const struct GNUNET_HashCode *key, | 338 | const struct GNUNET_HashCode *key, |
345 | void *value) | 339 | void *value) |
346 | { | 340 | { |
347 | struct GNUNET_SERVICE_Client *client = cls; | 341 | struct GNUNET_SERVICE_Client *client = cls; |
348 | struct RegisteredHostContext *rhc = value; | 342 | struct RegisteredHostContext *rhc = value; |
@@ -350,11 +344,11 @@ drop_client_entries (void *cls, | |||
350 | struct ForwardedOverlayConnectContext *foccn; | 344 | struct ForwardedOverlayConnectContext *foccn; |
351 | 345 | ||
352 | for (focc = rhc->focc_dll_head; NULL != focc; focc = foccn) | 346 | for (focc = rhc->focc_dll_head; NULL != focc; focc = foccn) |
353 | { | 347 | { |
354 | foccn = focc->next; | 348 | foccn = focc->next; |
355 | if (focc->client == client) | 349 | if (focc->client == client) |
356 | GST_cleanup_focc (focc); | 350 | GST_cleanup_focc(focc); |
357 | } | 351 | } |
358 | return GNUNET_OK; | 352 | return GNUNET_OK; |
359 | } | 353 | } |
360 | 354 | ||
@@ -365,11 +359,11 @@ drop_client_entries (void *cls, | |||
365 | * @param route the route to add | 359 | * @param route the route to add |
366 | */ | 360 | */ |
367 | static void | 361 | static void |
368 | route_list_add (struct Route *route) | 362 | route_list_add(struct Route *route) |
369 | { | 363 | { |
370 | if (route->dest >= route_list_size) | 364 | if (route->dest >= route_list_size) |
371 | GST_array_grow_large_enough (route_list, route_list_size, route->dest); | 365 | GST_array_grow_large_enough(route_list, route_list_size, route->dest); |
372 | GNUNET_assert (NULL == route_list[route->dest]); | 366 | GNUNET_assert(NULL == route_list[route->dest]); |
373 | route_list[route->dest] = route; | 367 | route_list[route->dest] = route; |
374 | } | 368 | } |
375 | 369 | ||
@@ -381,11 +375,11 @@ route_list_add (struct Route *route) | |||
381 | * @param n the neighbour to add | 375 | * @param n the neighbour to add |
382 | */ | 376 | */ |
383 | static void | 377 | static void |
384 | neighbour_list_add (struct Neighbour *n) | 378 | neighbour_list_add(struct Neighbour *n) |
385 | { | 379 | { |
386 | if (n->host_id >= neighbour_list_size) | 380 | if (n->host_id >= neighbour_list_size) |
387 | GST_array_grow_large_enough (neighbour_list, neighbour_list_size, n->host_id); | 381 | GST_array_grow_large_enough(neighbour_list, neighbour_list_size, n->host_id); |
388 | GNUNET_assert (NULL == neighbour_list[n->host_id]); | 382 | GNUNET_assert(NULL == neighbour_list[n->host_id]); |
389 | neighbour_list[n->host_id] = n; | 383 | neighbour_list[n->host_id] = n; |
390 | } | 384 | } |
391 | 385 | ||
@@ -394,14 +388,14 @@ neighbour_list_add (struct Neighbour *n) | |||
394 | * Cleans up the route list | 388 | * Cleans up the route list |
395 | */ | 389 | */ |
396 | void | 390 | void |
397 | GST_route_list_clear () | 391 | GST_route_list_clear() |
398 | { | 392 | { |
399 | unsigned int id; | 393 | unsigned int id; |
400 | 394 | ||
401 | for (id = 0; id < route_list_size; id++) | 395 | for (id = 0; id < route_list_size; id++) |
402 | if (NULL != route_list[id]) | 396 | if (NULL != route_list[id]) |
403 | GNUNET_free (route_list[id]); | 397 | GNUNET_free(route_list[id]); |
404 | GNUNET_free_non_null (route_list); | 398 | GNUNET_free_non_null(route_list); |
405 | route_list = NULL; | 399 | route_list = NULL; |
406 | } | 400 | } |
407 | 401 | ||
@@ -416,20 +410,20 @@ GST_route_list_clear () | |||
416 | * #GNUNET_NO if not. | 410 | * #GNUNET_NO if not. |
417 | */ | 411 | */ |
418 | static int | 412 | static int |
419 | reghost_free_iterator (void *cls, | 413 | reghost_free_iterator(void *cls, |
420 | const struct GNUNET_HashCode *key, | 414 | const struct GNUNET_HashCode *key, |
421 | void *value) | 415 | void *value) |
422 | { | 416 | { |
423 | struct Slave *slave = cls; | 417 | struct Slave *slave = cls; |
424 | struct RegisteredHostContext *rhc = value; | 418 | struct RegisteredHostContext *rhc = value; |
425 | struct ForwardedOverlayConnectContext *focc; | 419 | struct ForwardedOverlayConnectContext *focc; |
426 | 420 | ||
427 | GNUNET_assert (GNUNET_YES == | 421 | GNUNET_assert(GNUNET_YES == |
428 | GNUNET_CONTAINER_multihashmap_remove (slave->reghost_map, key, | 422 | GNUNET_CONTAINER_multihashmap_remove(slave->reghost_map, key, |
429 | value)); | 423 | value)); |
430 | while (NULL != (focc = rhc->focc_dll_head)) | 424 | while (NULL != (focc = rhc->focc_dll_head)) |
431 | GST_cleanup_focc (focc); | 425 | GST_cleanup_focc(focc); |
432 | GNUNET_free (value); | 426 | GNUNET_free(value); |
433 | return GNUNET_YES; | 427 | return GNUNET_YES; |
434 | } | 428 | } |
435 | 429 | ||
@@ -440,30 +434,30 @@ reghost_free_iterator (void *cls, | |||
440 | * @param slave the #Slave object | 434 | * @param slave the #Slave object |
441 | */ | 435 | */ |
442 | static void | 436 | static void |
443 | kill_slave (struct Slave *slave) | 437 | kill_slave(struct Slave *slave) |
444 | { | 438 | { |
445 | struct HostRegistration *hr_entry; | 439 | struct HostRegistration *hr_entry; |
446 | 440 | ||
447 | while (NULL != (hr_entry = slave->hr_dll_head)) | 441 | while (NULL != (hr_entry = slave->hr_dll_head)) |
448 | { | 442 | { |
449 | GNUNET_CONTAINER_DLL_remove (slave->hr_dll_head, slave->hr_dll_tail, | 443 | GNUNET_CONTAINER_DLL_remove(slave->hr_dll_head, slave->hr_dll_tail, |
450 | hr_entry); | 444 | hr_entry); |
451 | GNUNET_free (hr_entry); | 445 | GNUNET_free(hr_entry); |
452 | } | 446 | } |
453 | if (NULL != slave->rhandle) | 447 | if (NULL != slave->rhandle) |
454 | GNUNET_TESTBED_cancel_registration (slave->rhandle); | 448 | GNUNET_TESTBED_cancel_registration(slave->rhandle); |
455 | GNUNET_assert (GNUNET_SYSERR != | 449 | GNUNET_assert(GNUNET_SYSERR != |
456 | GNUNET_CONTAINER_multihashmap_iterate (slave->reghost_map, | 450 | GNUNET_CONTAINER_multihashmap_iterate(slave->reghost_map, |
457 | reghost_free_iterator, | 451 | reghost_free_iterator, |
458 | slave)); | 452 | slave)); |
459 | GNUNET_CONTAINER_multihashmap_destroy (slave->reghost_map); | 453 | GNUNET_CONTAINER_multihashmap_destroy(slave->reghost_map); |
460 | if (NULL != slave->controller) | 454 | if (NULL != slave->controller) |
461 | GNUNET_TESTBED_controller_disconnect (slave->controller); | 455 | GNUNET_TESTBED_controller_disconnect(slave->controller); |
462 | if (NULL != slave->controller_proc) | 456 | if (NULL != slave->controller_proc) |
463 | { | 457 | { |
464 | LOG_DEBUG ("Stopping a slave\n"); | 458 | LOG_DEBUG("Stopping a slave\n"); |
465 | GNUNET_TESTBED_controller_kill_ (slave->controller_proc); | 459 | GNUNET_TESTBED_controller_kill_(slave->controller_proc); |
466 | } | 460 | } |
467 | } | 461 | } |
468 | 462 | ||
469 | 463 | ||
@@ -473,15 +467,15 @@ kill_slave (struct Slave *slave) | |||
473 | * @param slave the #Slave object | 467 | * @param slave the #Slave object |
474 | */ | 468 | */ |
475 | static void | 469 | static void |
476 | destroy_slave (struct Slave *slave) | 470 | destroy_slave(struct Slave *slave) |
477 | { | 471 | { |
478 | if (NULL != slave->controller_proc) | 472 | if (NULL != slave->controller_proc) |
479 | { | 473 | { |
480 | GNUNET_TESTBED_controller_destroy_ (slave->controller_proc); | 474 | GNUNET_TESTBED_controller_destroy_(slave->controller_proc); |
481 | LOG_DEBUG ("Slave stopped\n"); | 475 | LOG_DEBUG("Slave stopped\n"); |
482 | } | 476 | } |
483 | GST_slave_list[slave->host_id] = NULL; | 477 | GST_slave_list[slave->host_id] = NULL; |
484 | GNUNET_free (slave); | 478 | GNUNET_free(slave); |
485 | } | 479 | } |
486 | 480 | ||
487 | 481 | ||
@@ -489,26 +483,26 @@ destroy_slave (struct Slave *slave) | |||
489 | * Cleans up the slave list | 483 | * Cleans up the slave list |
490 | */ | 484 | */ |
491 | void | 485 | void |
492 | GST_slave_list_clear () | 486 | GST_slave_list_clear() |
493 | { | 487 | { |
494 | struct Slave *slave; | 488 | struct Slave *slave; |
495 | unsigned int id; | 489 | unsigned int id; |
496 | 490 | ||
497 | for (id = 0; id < GST_slave_list_size; id++) | 491 | for (id = 0; id < GST_slave_list_size; id++) |
498 | { | 492 | { |
499 | slave = GST_slave_list[id]; | 493 | slave = GST_slave_list[id]; |
500 | if (NULL == slave) | 494 | if (NULL == slave) |
501 | continue; | 495 | continue; |
502 | kill_slave (slave); | 496 | kill_slave(slave); |
503 | } | 497 | } |
504 | for (id = 0; id < GST_slave_list_size; id++) | 498 | for (id = 0; id < GST_slave_list_size; id++) |
505 | { | 499 | { |
506 | slave = GST_slave_list[id]; | 500 | slave = GST_slave_list[id]; |
507 | if (NULL == slave) | 501 | if (NULL == slave) |
508 | continue; | 502 | continue; |
509 | destroy_slave (slave); | 503 | destroy_slave(slave); |
510 | } | 504 | } |
511 | GNUNET_free_non_null (GST_slave_list); | 505 | GNUNET_free_non_null(GST_slave_list); |
512 | GST_slave_list = NULL; | 506 | GST_slave_list = NULL; |
513 | } | 507 | } |
514 | 508 | ||
@@ -522,18 +516,18 @@ GST_slave_list_clear () | |||
522 | * is found | 516 | * is found |
523 | */ | 517 | */ |
524 | struct Route * | 518 | struct Route * |
525 | GST_find_dest_route (uint32_t host_id) | 519 | GST_find_dest_route(uint32_t host_id) |
526 | { | 520 | { |
527 | struct Route *route; | 521 | struct Route *route; |
528 | 522 | ||
529 | if (route_list_size <= host_id) | 523 | if (route_list_size <= host_id) |
530 | return NULL; | 524 | return NULL; |
531 | while (NULL != (route = route_list[host_id])) | 525 | while (NULL != (route = route_list[host_id])) |
532 | { | 526 | { |
533 | if (route->thru == GST_context->host_id) | 527 | if (route->thru == GST_context->host_id) |
534 | break; | 528 | break; |
535 | host_id = route->thru; | 529 | host_id = route->thru; |
536 | } | 530 | } |
537 | return route; | 531 | return route; |
538 | } | 532 | } |
539 | 533 | ||
@@ -551,10 +545,10 @@ GST_find_dest_route (uint32_t host_id) | |||
551 | * NULL if cfg is set! | 545 | * NULL if cfg is set! |
552 | */ | 546 | */ |
553 | static void | 547 | static void |
554 | send_controller_link_response (struct GNUNET_SERVICE_Client *client, | 548 | send_controller_link_response(struct GNUNET_SERVICE_Client *client, |
555 | uint64_t operation_id, | 549 | uint64_t operation_id, |
556 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 550 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
557 | const char *emsg) | 551 | const char *emsg) |
558 | { | 552 | { |
559 | struct GNUNET_MQ_Envelope *env; | 553 | struct GNUNET_MQ_Envelope *env; |
560 | struct GNUNET_TESTBED_ControllerLinkResponse *msg; | 554 | struct GNUNET_TESTBED_ControllerLinkResponse *msg; |
@@ -563,40 +557,40 @@ send_controller_link_response (struct GNUNET_SERVICE_Client *client, | |||
563 | size_t xconfig_size; | 557 | size_t xconfig_size; |
564 | uint16_t msize; | 558 | uint16_t msize; |
565 | 559 | ||
566 | GNUNET_assert ((NULL == cfg) || (NULL == emsg)); | 560 | GNUNET_assert((NULL == cfg) || (NULL == emsg)); |
567 | xconfig = NULL; | 561 | xconfig = NULL; |
568 | xconfig_size = 0; | 562 | xconfig_size = 0; |
569 | config_size = 0; | 563 | config_size = 0; |
570 | msize = 0; | 564 | msize = 0; |
571 | if (NULL != cfg) | 565 | if (NULL != cfg) |
572 | { | 566 | { |
573 | xconfig = GNUNET_TESTBED_compress_cfg_ (cfg, | 567 | xconfig = GNUNET_TESTBED_compress_cfg_(cfg, |
574 | &config_size, | 568 | &config_size, |
575 | &xconfig_size); | 569 | &xconfig_size); |
576 | msize += xconfig_size; | 570 | msize += xconfig_size; |
577 | } | 571 | } |
578 | if (NULL != emsg) | 572 | if (NULL != emsg) |
579 | msize += strlen (emsg); | 573 | msize += strlen(emsg); |
580 | env = GNUNET_MQ_msg_extra (msg, | 574 | env = GNUNET_MQ_msg_extra(msg, |
581 | msize, | 575 | msize, |
582 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT); | 576 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT); |
583 | if (NULL == emsg) | 577 | if (NULL == emsg) |
584 | msg->success = htons (GNUNET_YES); | 578 | msg->success = htons(GNUNET_YES); |
585 | msg->operation_id = GNUNET_htonll (operation_id); | 579 | msg->operation_id = GNUNET_htonll(operation_id); |
586 | msg->config_size = htons ((uint16_t) config_size); | 580 | msg->config_size = htons((uint16_t)config_size); |
587 | if (NULL != xconfig) | 581 | if (NULL != xconfig) |
588 | { | 582 | { |
589 | GNUNET_memcpy (&msg[1], | 583 | GNUNET_memcpy(&msg[1], |
590 | xconfig, | 584 | xconfig, |
591 | xconfig_size); | 585 | xconfig_size); |
592 | GNUNET_free (xconfig); | 586 | GNUNET_free(xconfig); |
593 | } | 587 | } |
594 | if (NULL != emsg) | 588 | if (NULL != emsg) |
595 | GNUNET_memcpy (&msg[1], | 589 | GNUNET_memcpy(&msg[1], |
596 | emsg, | 590 | emsg, |
597 | strlen (emsg)); | 591 | strlen(emsg)); |
598 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 592 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), |
599 | env); | 593 | env); |
600 | } | 594 | } |
601 | 595 | ||
602 | 596 | ||
@@ -606,7 +600,7 @@ send_controller_link_response (struct GNUNET_SERVICE_Client *client, | |||
606 | * @param cls the LCFContext | 600 | * @param cls the LCFContext |
607 | */ | 601 | */ |
608 | static void | 602 | static void |
609 | lcf_proc_task (void *cls); | 603 | lcf_proc_task(void *cls); |
610 | 604 | ||
611 | 605 | ||
612 | /** | 606 | /** |
@@ -616,38 +610,40 @@ lcf_proc_task (void *cls); | |||
616 | * @param emsg the error message; NULL if host registration is successful | 610 | * @param emsg the error message; NULL if host registration is successful |
617 | */ | 611 | */ |
618 | static void | 612 | static void |
619 | lcf_proc_cc (void *cls, | 613 | lcf_proc_cc(void *cls, |
620 | const char *emsg) | 614 | const char *emsg) |
621 | { | 615 | { |
622 | struct LCFContext *lcf = cls; | 616 | struct LCFContext *lcf = cls; |
623 | 617 | ||
624 | GNUNET_assert (NULL == lcf_proc_task_id); | 618 | GNUNET_assert(NULL == lcf_proc_task_id); |
625 | switch (lcf->state) | 619 | switch (lcf->state) |
626 | { | 620 | { |
627 | case INIT: | 621 | case INIT: |
628 | if (NULL != emsg) | 622 | if (NULL != emsg) |
629 | goto registration_error; | 623 | goto registration_error; |
630 | lcf->state = DELEGATED_HOST_REGISTERED; | 624 | lcf->state = DELEGATED_HOST_REGISTERED; |
631 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); | 625 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); |
632 | break; | 626 | break; |
633 | case DELEGATED_HOST_REGISTERED: | 627 | |
634 | if (NULL != emsg) | 628 | case DELEGATED_HOST_REGISTERED: |
635 | goto registration_error; | 629 | if (NULL != emsg) |
636 | lcf->state = SLAVE_HOST_REGISTERED; | 630 | goto registration_error; |
637 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); | 631 | lcf->state = SLAVE_HOST_REGISTERED; |
638 | break; | 632 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); |
639 | default: | 633 | break; |
640 | GNUNET_assert (0); /* Shouldn't reach here */ | 634 | |
641 | } | 635 | default: |
636 | GNUNET_assert(0); /* Shouldn't reach here */ | ||
637 | } | ||
642 | return; | 638 | return; |
643 | 639 | ||
644 | registration_error: | 640 | registration_error: |
645 | LOG (GNUNET_ERROR_TYPE_WARNING, | 641 | LOG(GNUNET_ERROR_TYPE_WARNING, |
646 | "Host registration failed with message: %s\n", | 642 | "Host registration failed with message: %s\n", |
647 | emsg); | 643 | emsg); |
648 | lcf->state = FINISHED; | 644 | lcf->state = FINISHED; |
649 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, | 645 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, |
650 | lcf); | 646 | lcf); |
651 | } | 647 | } |
652 | 648 | ||
653 | 649 | ||
@@ -657,7 +653,7 @@ registration_error: | |||
657 | * @param cls the LCFContext | 653 | * @param cls the LCFContext |
658 | */ | 654 | */ |
659 | static void | 655 | static void |
660 | lcf_proc_task (void *cls); | 656 | lcf_proc_task(void *cls); |
661 | 657 | ||
662 | 658 | ||
663 | /** | 659 | /** |
@@ -666,21 +662,21 @@ lcf_proc_task (void *cls); | |||
666 | * @param cls the LCFContext | 662 | * @param cls the LCFContext |
667 | */ | 663 | */ |
668 | static void | 664 | static void |
669 | lcf_forwarded_operation_timeout (void *cls) | 665 | lcf_forwarded_operation_timeout(void *cls) |
670 | { | 666 | { |
671 | struct LCFContext *lcf = cls; | 667 | struct LCFContext *lcf = cls; |
672 | 668 | ||
673 | lcf->timeout_task = NULL; | 669 | lcf->timeout_task = NULL; |
674 | // GST_forwarded_operation_timeout (lcf->fopc, tc); | 670 | // GST_forwarded_operation_timeout (lcf->fopc, tc); |
675 | LOG (GNUNET_ERROR_TYPE_WARNING, | 671 | LOG(GNUNET_ERROR_TYPE_WARNING, |
676 | "A forwarded controller link operation has timed out\n"); | 672 | "A forwarded controller link operation has timed out\n"); |
677 | send_controller_link_response (lcf->client, | 673 | send_controller_link_response(lcf->client, |
678 | lcf->operation_id, | 674 | lcf->operation_id, |
679 | NULL, | 675 | NULL, |
680 | "A forwarded controller link operation has timed out\n"); | 676 | "A forwarded controller link operation has timed out\n"); |
681 | GNUNET_assert (NULL == lcf_proc_task_id); | 677 | GNUNET_assert(NULL == lcf_proc_task_id); |
682 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, | 678 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, |
683 | lcf); | 679 | lcf); |
684 | } | 680 | } |
685 | 681 | ||
686 | 682 | ||
@@ -690,65 +686,68 @@ lcf_forwarded_operation_timeout (void *cls) | |||
690 | * @param cls the LCFContext | 686 | * @param cls the LCFContext |
691 | */ | 687 | */ |
692 | static void | 688 | static void |
693 | lcf_proc_task (void *cls) | 689 | lcf_proc_task(void *cls) |
694 | { | 690 | { |
695 | struct LCFContext *lcf = cls; | 691 | struct LCFContext *lcf = cls; |
696 | 692 | ||
697 | lcf_proc_task_id = NULL; | 693 | lcf_proc_task_id = NULL; |
698 | switch (lcf->state) | 694 | switch (lcf->state) |
699 | { | ||
700 | case INIT: | ||
701 | if (GNUNET_NO == | ||
702 | GNUNET_TESTBED_is_host_registered_ (GST_host_list | ||
703 | [lcf->delegated_host_id], | ||
704 | lcf->gateway->controller)) | ||
705 | { | ||
706 | GST_queue_host_registration (lcf->gateway, lcf_proc_cc, lcf, | ||
707 | GST_host_list[lcf->delegated_host_id]); | ||
708 | } | ||
709 | else | ||
710 | { | ||
711 | lcf->state = DELEGATED_HOST_REGISTERED; | ||
712 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); | ||
713 | } | ||
714 | break; | ||
715 | case DELEGATED_HOST_REGISTERED: | ||
716 | if (GNUNET_NO == | ||
717 | GNUNET_TESTBED_is_host_registered_ (GST_host_list[lcf->slave_host_id], | ||
718 | lcf->gateway->controller)) | ||
719 | { | ||
720 | GST_queue_host_registration (lcf->gateway, lcf_proc_cc, lcf, | ||
721 | GST_host_list[lcf->slave_host_id]); | ||
722 | } | ||
723 | else | ||
724 | { | 695 | { |
725 | lcf->state = SLAVE_HOST_REGISTERED; | 696 | case INIT: |
726 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); | 697 | if (GNUNET_NO == |
698 | GNUNET_TESTBED_is_host_registered_(GST_host_list | ||
699 | [lcf->delegated_host_id], | ||
700 | lcf->gateway->controller)) | ||
701 | { | ||
702 | GST_queue_host_registration(lcf->gateway, lcf_proc_cc, lcf, | ||
703 | GST_host_list[lcf->delegated_host_id]); | ||
704 | } | ||
705 | else | ||
706 | { | ||
707 | lcf->state = DELEGATED_HOST_REGISTERED; | ||
708 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); | ||
709 | } | ||
710 | break; | ||
711 | |||
712 | case DELEGATED_HOST_REGISTERED: | ||
713 | if (GNUNET_NO == | ||
714 | GNUNET_TESTBED_is_host_registered_(GST_host_list[lcf->slave_host_id], | ||
715 | lcf->gateway->controller)) | ||
716 | { | ||
717 | GST_queue_host_registration(lcf->gateway, lcf_proc_cc, lcf, | ||
718 | GST_host_list[lcf->slave_host_id]); | ||
719 | } | ||
720 | else | ||
721 | { | ||
722 | lcf->state = SLAVE_HOST_REGISTERED; | ||
723 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); | ||
724 | } | ||
725 | break; | ||
726 | |||
727 | case SLAVE_HOST_REGISTERED: | ||
728 | lcf->op = GNUNET_TESTBED_controller_link(lcf, | ||
729 | lcf->gateway->controller, | ||
730 | GST_host_list[lcf->delegated_host_id], | ||
731 | GST_host_list[lcf->slave_host_id], | ||
732 | lcf->is_subordinate); | ||
733 | lcf->timeout_task = | ||
734 | GNUNET_SCHEDULER_add_delayed(GST_timeout, | ||
735 | &lcf_forwarded_operation_timeout, | ||
736 | lcf); | ||
737 | lcf->state = FINISHED; | ||
738 | break; | ||
739 | |||
740 | case FINISHED: | ||
741 | if (NULL != lcf->op) | ||
742 | GNUNET_TESTBED_operation_done(lcf->op); | ||
743 | GNUNET_CONTAINER_DLL_remove(lcf_head, | ||
744 | lcf_tail, | ||
745 | lcf); | ||
746 | GNUNET_free(lcf); | ||
747 | if (NULL != lcf_head) | ||
748 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, | ||
749 | lcf_head); | ||
727 | } | 750 | } |
728 | break; | ||
729 | case SLAVE_HOST_REGISTERED: | ||
730 | lcf->op = GNUNET_TESTBED_controller_link (lcf, | ||
731 | lcf->gateway->controller, | ||
732 | GST_host_list[lcf->delegated_host_id], | ||
733 | GST_host_list[lcf->slave_host_id], | ||
734 | lcf->is_subordinate); | ||
735 | lcf->timeout_task = | ||
736 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | ||
737 | &lcf_forwarded_operation_timeout, | ||
738 | lcf); | ||
739 | lcf->state = FINISHED; | ||
740 | break; | ||
741 | case FINISHED: | ||
742 | if (NULL != lcf->op) | ||
743 | GNUNET_TESTBED_operation_done (lcf->op); | ||
744 | GNUNET_CONTAINER_DLL_remove (lcf_head, | ||
745 | lcf_tail, | ||
746 | lcf); | ||
747 | GNUNET_free (lcf); | ||
748 | if (NULL != lcf_head) | ||
749 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, | ||
750 | lcf_head); | ||
751 | } | ||
752 | } | 751 | } |
753 | 752 | ||
754 | 753 | ||
@@ -759,30 +758,30 @@ lcf_proc_task (void *cls) | |||
759 | * @param event information about the event | 758 | * @param event information about the event |
760 | */ | 759 | */ |
761 | static void | 760 | static void |
762 | slave_event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | 761 | slave_event_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) |
763 | { | 762 | { |
764 | struct LCFContext *lcf; | 763 | struct LCFContext *lcf; |
765 | 764 | ||
766 | /* We currently only get here when working on LCFContexts */ | 765 | /* We currently only get here when working on LCFContexts */ |
767 | GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); | 766 | GNUNET_assert(GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); |
768 | lcf = event->op_cls; | 767 | lcf = event->op_cls; |
769 | GNUNET_assert (lcf->op == event->op); | 768 | GNUNET_assert(lcf->op == event->op); |
770 | GNUNET_TESTBED_operation_done (lcf->op); | 769 | GNUNET_TESTBED_operation_done(lcf->op); |
771 | lcf->op = NULL; | 770 | lcf->op = NULL; |
772 | GNUNET_assert (FINISHED == lcf->state); | 771 | GNUNET_assert(FINISHED == lcf->state); |
773 | GNUNET_assert (NULL != lcf->timeout_task); | 772 | GNUNET_assert(NULL != lcf->timeout_task); |
774 | GNUNET_SCHEDULER_cancel (lcf->timeout_task); | 773 | GNUNET_SCHEDULER_cancel(lcf->timeout_task); |
775 | if (NULL == event->details.operation_finished.emsg) | 774 | if (NULL == event->details.operation_finished.emsg) |
776 | send_controller_link_response (lcf->client, lcf->operation_id, | 775 | send_controller_link_response(lcf->client, lcf->operation_id, |
777 | GNUNET_TESTBED_host_get_cfg_ | 776 | GNUNET_TESTBED_host_get_cfg_ |
778 | (GST_host_list[lcf->delegated_host_id]), | 777 | (GST_host_list[lcf->delegated_host_id]), |
779 | NULL); | 778 | NULL); |
780 | else | 779 | else |
781 | send_controller_link_response (lcf->client, lcf->operation_id, | 780 | send_controller_link_response(lcf->client, lcf->operation_id, |
782 | NULL, | 781 | NULL, |
783 | event->details.operation_finished.emsg); | 782 | event->details.operation_finished.emsg); |
784 | GNUNET_assert (NULL == lcf_proc_task_id); | 783 | GNUNET_assert(NULL == lcf_proc_task_id); |
785 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf); | 784 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); |
786 | return; | 785 | return; |
787 | } | 786 | } |
788 | 787 | ||
@@ -797,56 +796,56 @@ slave_event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
797 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case | 796 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case |
798 | */ | 797 | */ |
799 | static void | 798 | static void |
800 | slave_status_cb (void *cls, | 799 | slave_status_cb(void *cls, |
801 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 800 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
802 | int status) | 801 | int status) |
803 | { | 802 | { |
804 | struct Slave *slave = cls; | 803 | struct Slave *slave = cls; |
805 | struct LinkControllersContext *lcc; | 804 | struct LinkControllersContext *lcc; |
806 | 805 | ||
807 | lcc = slave->lcc; | 806 | lcc = slave->lcc; |
808 | if (GNUNET_SYSERR == status) | 807 | if (GNUNET_SYSERR == status) |
809 | { | 808 | { |
810 | slave->controller_proc = NULL; | 809 | slave->controller_proc = NULL; |
811 | /* Stop all link controller forwarding tasks since we shutdown here anyway | 810 | /* Stop all link controller forwarding tasks since we shutdown here anyway |
812 | and as these tasks they depend on the operation queues which are created | 811 | and as these tasks they depend on the operation queues which are created |
813 | through GNUNET_TESTBED_controller_connect() and in kill_slave() we call | 812 | through GNUNET_TESTBED_controller_connect() and in kill_slave() we call |
814 | the destructor function GNUNET_TESTBED_controller_disconnect() */ | 813 | the destructor function GNUNET_TESTBED_controller_disconnect() */ |
815 | GST_free_lcf (); | 814 | GST_free_lcf(); |
816 | kill_slave (slave); | 815 | kill_slave(slave); |
817 | destroy_slave (slave); | 816 | destroy_slave(slave); |
818 | slave = NULL; | 817 | slave = NULL; |
819 | LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n"); | 818 | LOG(GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n"); |
820 | GNUNET_SCHEDULER_shutdown (); /* We too shutdown */ | 819 | GNUNET_SCHEDULER_shutdown(); /* We too shutdown */ |
821 | goto clean_lcc; | 820 | goto clean_lcc; |
822 | } | 821 | } |
823 | slave->controller = | 822 | slave->controller = |
824 | GNUNET_TESTBED_controller_connect (GST_host_list[slave->host_id], | 823 | GNUNET_TESTBED_controller_connect(GST_host_list[slave->host_id], |
825 | EVENT_MASK, &slave_event_cb, | 824 | EVENT_MASK, &slave_event_cb, |
826 | slave); | 825 | slave); |
827 | if (NULL != slave->controller) | 826 | if (NULL != slave->controller) |
828 | { | 827 | { |
829 | send_controller_link_response (lcc->client, lcc->operation_id, cfg, NULL); | 828 | send_controller_link_response(lcc->client, lcc->operation_id, cfg, NULL); |
830 | } | 829 | } |
831 | else | 830 | else |
832 | { | 831 | { |
833 | send_controller_link_response (lcc->client, lcc->operation_id, NULL, | 832 | send_controller_link_response(lcc->client, lcc->operation_id, NULL, |
834 | "Could not connect to delegated controller"); | 833 | "Could not connect to delegated controller"); |
835 | kill_slave (slave); | 834 | kill_slave(slave); |
836 | destroy_slave (slave); | 835 | destroy_slave(slave); |
837 | slave = NULL; | 836 | slave = NULL; |
838 | } | 837 | } |
839 | 838 | ||
840 | clean_lcc: | 839 | clean_lcc: |
841 | if (NULL != lcc) | 840 | if (NULL != lcc) |
842 | { | ||
843 | if (NULL != lcc->client) | ||
844 | { | 841 | { |
845 | GNUNET_SERVICE_client_continue (lcc->client); | 842 | if (NULL != lcc->client) |
846 | lcc->client = NULL; | 843 | { |
844 | GNUNET_SERVICE_client_continue(lcc->client); | ||
845 | lcc->client = NULL; | ||
846 | } | ||
847 | GNUNET_free(lcc); | ||
847 | } | 848 | } |
848 | GNUNET_free (lcc); | ||
849 | } | ||
850 | if (NULL != slave) | 849 | if (NULL != slave) |
851 | slave->lcc = NULL; | 850 | slave->lcc = NULL; |
852 | } | 851 | } |
@@ -861,7 +860,7 @@ slave_status_cb (void *cls, | |||
861 | * @param n the neighbour | 860 | * @param n the neighbour |
862 | */ | 861 | */ |
863 | static void | 862 | static void |
864 | trigger_notifications (struct Neighbour *n); | 863 | trigger_notifications(struct Neighbour *n); |
865 | 864 | ||
866 | 865 | ||
867 | /** | 866 | /** |
@@ -871,19 +870,19 @@ trigger_notifications (struct Neighbour *n); | |||
871 | * @param cls the neighbour | 870 | * @param cls the neighbour |
872 | */ | 871 | */ |
873 | static void | 872 | static void |
874 | neighbour_connect_notify_task (void *cls) | 873 | neighbour_connect_notify_task(void *cls) |
875 | { | 874 | { |
876 | struct Neighbour *n = cls; | 875 | struct Neighbour *n = cls; |
877 | struct NeighbourConnectNotification *h; | 876 | struct NeighbourConnectNotification *h; |
878 | 877 | ||
879 | GNUNET_assert (NULL != (h = n->nl_head)); | 878 | GNUNET_assert(NULL != (h = n->nl_head)); |
880 | GNUNET_assert (NULL != n->notify_task); | 879 | GNUNET_assert(NULL != n->notify_task); |
881 | n->notify_task = NULL; | 880 | n->notify_task = NULL; |
882 | GNUNET_assert (NULL != n->controller); | 881 | GNUNET_assert(NULL != n->controller); |
883 | GNUNET_CONTAINER_DLL_remove (n->nl_head, n->nl_tail, h); | 882 | GNUNET_CONTAINER_DLL_remove(n->nl_head, n->nl_tail, h); |
884 | trigger_notifications (n); | 883 | trigger_notifications(n); |
885 | h->cb (h->cb_cls, n->controller); | 884 | h->cb(h->cb_cls, n->controller); |
886 | GNUNET_free (h); | 885 | GNUNET_free(h); |
887 | } | 886 | } |
888 | 887 | ||
889 | 888 | ||
@@ -896,9 +895,9 @@ neighbour_connect_notify_task (void *cls) | |||
896 | * @param n the neighbour | 895 | * @param n the neighbour |
897 | */ | 896 | */ |
898 | static void | 897 | static void |
899 | trigger_notifications (struct Neighbour *n) | 898 | trigger_notifications(struct Neighbour *n) |
900 | { | 899 | { |
901 | GNUNET_assert (NULL != n->conn_op); | 900 | GNUNET_assert(NULL != n->conn_op); |
902 | if (NULL == n->nl_head) | 901 | if (NULL == n->nl_head) |
903 | return; | 902 | return; |
904 | if (NULL == n->controller) | 903 | if (NULL == n->controller) |
@@ -906,14 +905,14 @@ trigger_notifications (struct Neighbour *n) | |||
906 | if (NULL != n->notify_task) | 905 | if (NULL != n->notify_task) |
907 | return; | 906 | return; |
908 | if (1 == n->inactive) | 907 | if (1 == n->inactive) |
909 | { | 908 | { |
910 | GNUNET_assert (0 == n->reference_cnt); | 909 | GNUNET_assert(0 == n->reference_cnt); |
911 | GNUNET_TESTBED_operation_activate_ (n->conn_op); | 910 | GNUNET_TESTBED_operation_activate_(n->conn_op); |
912 | n->inactive = 0; | 911 | n->inactive = 0; |
913 | } | 912 | } |
914 | n->reference_cnt++; | 913 | n->reference_cnt++; |
915 | n->notify_task = | 914 | n->notify_task = |
916 | GNUNET_SCHEDULER_add_now (&neighbour_connect_notify_task, n); | 915 | GNUNET_SCHEDULER_add_now(&neighbour_connect_notify_task, n); |
917 | } | 916 | } |
918 | 917 | ||
919 | 918 | ||
@@ -925,18 +924,18 @@ trigger_notifications (struct Neighbour *n) | |||
925 | * @param cls the neighbour | 924 | * @param cls the neighbour |
926 | */ | 925 | */ |
927 | static void | 926 | static void |
928 | opstart_neighbour_conn (void *cls) | 927 | opstart_neighbour_conn(void *cls) |
929 | { | 928 | { |
930 | struct Neighbour *n = cls; | 929 | struct Neighbour *n = cls; |
931 | 930 | ||
932 | GNUNET_assert (NULL != n->conn_op); | 931 | GNUNET_assert(NULL != n->conn_op); |
933 | GNUNET_assert (NULL == n->controller); | 932 | GNUNET_assert(NULL == n->controller); |
934 | LOG_DEBUG ("Opening connection to controller on host %u\n", n->host_id); | 933 | LOG_DEBUG("Opening connection to controller on host %u\n", n->host_id); |
935 | n->controller = GNUNET_TESTBED_controller_connect (GST_host_list[n->host_id], | 934 | n->controller = GNUNET_TESTBED_controller_connect(GST_host_list[n->host_id], |
936 | EVENT_MASK, | 935 | EVENT_MASK, |
937 | &slave_event_cb, | 936 | &slave_event_cb, |
938 | NULL); | 937 | NULL); |
939 | trigger_notifications (n); | 938 | trigger_notifications(n); |
940 | } | 939 | } |
941 | 940 | ||
942 | 941 | ||
@@ -946,21 +945,21 @@ opstart_neighbour_conn (void *cls) | |||
946 | * @param cls the neighbour | 945 | * @param cls the neighbour |
947 | */ | 946 | */ |
948 | static void | 947 | static void |
949 | oprelease_neighbour_conn (void *cls) | 948 | oprelease_neighbour_conn(void *cls) |
950 | { | 949 | { |
951 | struct Neighbour *n = cls; | 950 | struct Neighbour *n = cls; |
952 | 951 | ||
953 | GNUNET_assert (0 == n->reference_cnt); | 952 | GNUNET_assert(0 == n->reference_cnt); |
954 | GNUNET_assert (NULL == n->notify_task); | 953 | GNUNET_assert(NULL == n->notify_task); |
955 | GNUNET_assert (NULL == n->nl_head); | 954 | GNUNET_assert(NULL == n->nl_head); |
956 | if (NULL != n->controller) | 955 | if (NULL != n->controller) |
957 | { | 956 | { |
958 | LOG_DEBUG ("Closing connection to controller on host %u\n", n->host_id); | 957 | LOG_DEBUG("Closing connection to controller on host %u\n", n->host_id); |
959 | GNUNET_TESTBED_controller_disconnect (n->controller); | 958 | GNUNET_TESTBED_controller_disconnect(n->controller); |
960 | n->controller = NULL; | 959 | n->controller = NULL; |
961 | } | 960 | } |
962 | n->conn_op = NULL; | 961 | n->conn_op = NULL; |
963 | n->inactive = 0; | 962 | n->inactive = 0; |
964 | } | 963 | } |
965 | 964 | ||
966 | 965 | ||
@@ -976,30 +975,30 @@ oprelease_neighbour_conn (void *cls) | |||
976 | * @param cb_cls the closure for the above callback | 975 | * @param cb_cls the closure for the above callback |
977 | */ | 976 | */ |
978 | struct NeighbourConnectNotification * | 977 | struct NeighbourConnectNotification * |
979 | GST_neighbour_get_connection (struct Neighbour *n, | 978 | GST_neighbour_get_connection(struct Neighbour *n, |
980 | GST_NeigbourConnectNotifyCallback cb, | 979 | GST_NeigbourConnectNotifyCallback cb, |
981 | void *cb_cls) | 980 | void *cb_cls) |
982 | { | 981 | { |
983 | struct NeighbourConnectNotification *h; | 982 | struct NeighbourConnectNotification *h; |
984 | 983 | ||
985 | GNUNET_assert (NULL != cb); | 984 | GNUNET_assert(NULL != cb); |
986 | LOG_DEBUG ("Attempting to get connection to controller on host %u\n", | 985 | LOG_DEBUG("Attempting to get connection to controller on host %u\n", |
987 | n->host_id); | 986 | n->host_id); |
988 | h = GNUNET_new (struct NeighbourConnectNotification); | 987 | h = GNUNET_new(struct NeighbourConnectNotification); |
989 | h->n = n; | 988 | h->n = n; |
990 | h->cb = cb; | 989 | h->cb = cb; |
991 | h->cb_cls = cb_cls; | 990 | h->cb_cls = cb_cls; |
992 | GNUNET_CONTAINER_DLL_insert_tail (n->nl_head, n->nl_tail, h); | 991 | GNUNET_CONTAINER_DLL_insert_tail(n->nl_head, n->nl_tail, h); |
993 | if (NULL == n->conn_op) | 992 | if (NULL == n->conn_op) |
994 | { | 993 | { |
995 | GNUNET_assert (NULL == n->controller); | 994 | GNUNET_assert(NULL == n->controller); |
996 | n->conn_op = GNUNET_TESTBED_operation_create_ (n, &opstart_neighbour_conn, | 995 | n->conn_op = GNUNET_TESTBED_operation_create_(n, &opstart_neighbour_conn, |
997 | &oprelease_neighbour_conn); | 996 | &oprelease_neighbour_conn); |
998 | GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, n->conn_op); | 997 | GNUNET_TESTBED_operation_queue_insert_(GST_opq_openfds, n->conn_op); |
999 | GNUNET_TESTBED_operation_begin_wait_ (n->conn_op); | 998 | GNUNET_TESTBED_operation_begin_wait_(n->conn_op); |
1000 | return h; | 999 | return h; |
1001 | } | 1000 | } |
1002 | trigger_notifications (n); | 1001 | trigger_notifications(n); |
1003 | return h; | 1002 | return h; |
1004 | } | 1003 | } |
1005 | 1004 | ||
@@ -1010,33 +1009,33 @@ GST_neighbour_get_connection (struct Neighbour *n, | |||
1010 | * @param h the notification handle | 1009 | * @param h the notification handle |
1011 | */ | 1010 | */ |
1012 | void | 1011 | void |
1013 | GST_neighbour_get_connection_cancel (struct NeighbourConnectNotification *h) | 1012 | GST_neighbour_get_connection_cancel(struct NeighbourConnectNotification *h) |
1014 | { | 1013 | { |
1015 | struct Neighbour *n; | 1014 | struct Neighbour *n; |
1016 | int cleanup_task; | 1015 | int cleanup_task; |
1017 | 1016 | ||
1018 | n = h->n; | 1017 | n = h->n; |
1019 | cleanup_task = (h == n->nl_head) ? GNUNET_YES : GNUNET_NO; | 1018 | cleanup_task = (h == n->nl_head) ? GNUNET_YES : GNUNET_NO; |
1020 | GNUNET_CONTAINER_DLL_remove (n->nl_head, n->nl_tail, h); | 1019 | GNUNET_CONTAINER_DLL_remove(n->nl_head, n->nl_tail, h); |
1021 | GNUNET_free (h); | 1020 | GNUNET_free(h); |
1022 | if (GNUNET_NO == cleanup_task) | 1021 | if (GNUNET_NO == cleanup_task) |
1023 | return; | 1022 | return; |
1024 | if (NULL == n->notify_task) | 1023 | if (NULL == n->notify_task) |
1025 | return; | 1024 | return; |
1026 | GNUNET_assert (0 < n->reference_cnt); | 1025 | GNUNET_assert(0 < n->reference_cnt); |
1027 | n->reference_cnt--; | 1026 | n->reference_cnt--; |
1028 | GNUNET_SCHEDULER_cancel (n->notify_task); | 1027 | GNUNET_SCHEDULER_cancel(n->notify_task); |
1029 | n->notify_task = NULL; | 1028 | n->notify_task = NULL; |
1030 | if (NULL == n->nl_head) | 1029 | if (NULL == n->nl_head) |
1031 | { | ||
1032 | if ( (0 == n->reference_cnt) && (0 == n->inactive) ) | ||
1033 | { | 1030 | { |
1034 | n->inactive = 1; | 1031 | if ((0 == n->reference_cnt) && (0 == n->inactive)) |
1035 | GNUNET_TESTBED_operation_inactivate_ (n->conn_op); | 1032 | { |
1033 | n->inactive = 1; | ||
1034 | GNUNET_TESTBED_operation_inactivate_(n->conn_op); | ||
1035 | } | ||
1036 | return; | ||
1036 | } | 1037 | } |
1037 | return; | 1038 | trigger_notifications(n); |
1038 | } | ||
1039 | trigger_notifications (n); | ||
1040 | } | 1039 | } |
1041 | 1040 | ||
1042 | 1041 | ||
@@ -1048,16 +1047,16 @@ GST_neighbour_get_connection_cancel (struct NeighbourConnectNotification *h) | |||
1048 | * @param n the neighbour whose connection can be closed | 1047 | * @param n the neighbour whose connection can be closed |
1049 | */ | 1048 | */ |
1050 | void | 1049 | void |
1051 | GST_neighbour_release_connection (struct Neighbour *n) | 1050 | GST_neighbour_release_connection(struct Neighbour *n) |
1052 | { | 1051 | { |
1053 | GNUNET_assert (0 == n->inactive); | 1052 | GNUNET_assert(0 == n->inactive); |
1054 | GNUNET_assert (0 < n->reference_cnt); | 1053 | GNUNET_assert(0 < n->reference_cnt); |
1055 | n->reference_cnt--; | 1054 | n->reference_cnt--; |
1056 | if (0 == n->reference_cnt) | 1055 | if (0 == n->reference_cnt) |
1057 | { | 1056 | { |
1058 | n->inactive = 1; | 1057 | n->inactive = 1; |
1059 | GNUNET_TESTBED_operation_inactivate_ (n->conn_op); | 1058 | GNUNET_TESTBED_operation_inactivate_(n->conn_op); |
1060 | } | 1059 | } |
1061 | } | 1060 | } |
1062 | 1061 | ||
1063 | 1062 | ||
@@ -1067,16 +1066,16 @@ GST_neighbour_release_connection (struct Neighbour *n) | |||
1067 | * @param ncc the neighbour connect context to cleanup | 1066 | * @param ncc the neighbour connect context to cleanup |
1068 | */ | 1067 | */ |
1069 | static void | 1068 | static void |
1070 | cleanup_ncc (struct NeighbourConnectCtxt *ncc) | 1069 | cleanup_ncc(struct NeighbourConnectCtxt *ncc) |
1071 | { | 1070 | { |
1072 | if (NULL != ncc->nh) | 1071 | if (NULL != ncc->nh) |
1073 | GST_neighbour_get_connection_cancel (ncc->nh); | 1072 | GST_neighbour_get_connection_cancel(ncc->nh); |
1074 | if (NULL != ncc->timeout_task) | 1073 | if (NULL != ncc->timeout_task) |
1075 | GNUNET_SCHEDULER_cancel (ncc->timeout_task); | 1074 | GNUNET_SCHEDULER_cancel(ncc->timeout_task); |
1076 | GNUNET_CONTAINER_DLL_remove (ncc_head, | 1075 | GNUNET_CONTAINER_DLL_remove(ncc_head, |
1077 | ncc_tail, | 1076 | ncc_tail, |
1078 | ncc); | 1077 | ncc); |
1079 | GNUNET_free (ncc); | 1078 | GNUNET_free(ncc); |
1080 | } | 1079 | } |
1081 | 1080 | ||
1082 | 1081 | ||
@@ -1084,21 +1083,21 @@ cleanup_ncc (struct NeighbourConnectCtxt *ncc) | |||
1084 | * Cleans up the neighbour list | 1083 | * Cleans up the neighbour list |
1085 | */ | 1084 | */ |
1086 | void | 1085 | void |
1087 | GST_neighbour_list_clean () | 1086 | GST_neighbour_list_clean() |
1088 | { | 1087 | { |
1089 | struct Neighbour *n; | 1088 | struct Neighbour *n; |
1090 | unsigned int id; | 1089 | unsigned int id; |
1091 | 1090 | ||
1092 | for (id = 0; id < neighbour_list_size; id++) | 1091 | for (id = 0; id < neighbour_list_size; id++) |
1093 | { | 1092 | { |
1094 | if (NULL == (n = neighbour_list[id])) | 1093 | if (NULL == (n = neighbour_list[id])) |
1095 | continue; | 1094 | continue; |
1096 | if (NULL != n->conn_op) | 1095 | if (NULL != n->conn_op) |
1097 | GNUNET_TESTBED_operation_release_ (n->conn_op); | 1096 | GNUNET_TESTBED_operation_release_(n->conn_op); |
1098 | GNUNET_free (n); | 1097 | GNUNET_free(n); |
1099 | neighbour_list[id] = NULL; | 1098 | neighbour_list[id] = NULL; |
1100 | } | 1099 | } |
1101 | GNUNET_free_non_null (neighbour_list); | 1100 | GNUNET_free_non_null(neighbour_list); |
1102 | } | 1101 | } |
1103 | 1102 | ||
1104 | 1103 | ||
@@ -1110,7 +1109,7 @@ GST_neighbour_list_clean () | |||
1110 | * the list size or neighbour at that index is NULL) | 1109 | * the list size or neighbour at that index is NULL) |
1111 | */ | 1110 | */ |
1112 | struct Neighbour * | 1111 | struct Neighbour * |
1113 | GST_get_neighbour (uint32_t id) | 1112 | GST_get_neighbour(uint32_t id) |
1114 | { | 1113 | { |
1115 | if (neighbour_list_size <= id) | 1114 | if (neighbour_list_size <= id) |
1116 | return NULL; | 1115 | return NULL; |
@@ -1122,10 +1121,10 @@ GST_get_neighbour (uint32_t id) | |||
1122 | * Function to cleanup the neighbour connect contexts | 1121 | * Function to cleanup the neighbour connect contexts |
1123 | */ | 1122 | */ |
1124 | void | 1123 | void |
1125 | GST_free_nccq () | 1124 | GST_free_nccq() |
1126 | { | 1125 | { |
1127 | while (NULL != ncc_head) | 1126 | while (NULL != ncc_head) |
1128 | cleanup_ncc (ncc_head); | 1127 | cleanup_ncc(ncc_head); |
1129 | } | 1128 | } |
1130 | 1129 | ||
1131 | 1130 | ||
@@ -1135,16 +1134,16 @@ GST_free_nccq () | |||
1135 | * @param cls the NeighbourConnectCtxt created in GST_handle_link_controllers() | 1134 | * @param cls the NeighbourConnectCtxt created in GST_handle_link_controllers() |
1136 | */ | 1135 | */ |
1137 | static void | 1136 | static void |
1138 | timeout_neighbour_connect (void *cls) | 1137 | timeout_neighbour_connect(void *cls) |
1139 | { | 1138 | { |
1140 | struct NeighbourConnectCtxt *ncc = cls; | 1139 | struct NeighbourConnectCtxt *ncc = cls; |
1141 | 1140 | ||
1142 | ncc->timeout_task = NULL; | 1141 | ncc->timeout_task = NULL; |
1143 | send_controller_link_response (ncc->client, | 1142 | send_controller_link_response(ncc->client, |
1144 | ncc->op_id, | 1143 | ncc->op_id, |
1145 | NULL, | 1144 | NULL, |
1146 | "Could not connect to delegated controller"); | 1145 | "Could not connect to delegated controller"); |
1147 | cleanup_ncc (ncc); | 1146 | cleanup_ncc(ncc); |
1148 | } | 1147 | } |
1149 | 1148 | ||
1150 | 1149 | ||
@@ -1155,20 +1154,20 @@ timeout_neighbour_connect (void *cls) | |||
1155 | * @param c the handle the neighbour's controller | 1154 | * @param c the handle the neighbour's controller |
1156 | */ | 1155 | */ |
1157 | static void | 1156 | static void |
1158 | neighbour_connect_cb (void *cls, | 1157 | neighbour_connect_cb(void *cls, |
1159 | struct GNUNET_TESTBED_Controller *c) | 1158 | struct GNUNET_TESTBED_Controller *c) |
1160 | { | 1159 | { |
1161 | struct NeighbourConnectCtxt *ncc = cls; | 1160 | struct NeighbourConnectCtxt *ncc = cls; |
1162 | 1161 | ||
1163 | GNUNET_SCHEDULER_cancel (ncc->timeout_task); | 1162 | GNUNET_SCHEDULER_cancel(ncc->timeout_task); |
1164 | ncc->timeout_task = NULL; | 1163 | ncc->timeout_task = NULL; |
1165 | ncc->nh = NULL; | 1164 | ncc->nh = NULL; |
1166 | GST_neighbour_release_connection (ncc->n); | 1165 | GST_neighbour_release_connection(ncc->n); |
1167 | send_controller_link_response (ncc->client, | 1166 | send_controller_link_response(ncc->client, |
1168 | ncc->op_id, | 1167 | ncc->op_id, |
1169 | NULL, | 1168 | NULL, |
1170 | NULL); | 1169 | NULL); |
1171 | cleanup_ncc (ncc); | 1170 | cleanup_ncc(ncc); |
1172 | } | 1171 | } |
1173 | 1172 | ||
1174 | 1173 | ||
@@ -1178,13 +1177,13 @@ neighbour_connect_cb (void *cls, | |||
1178 | * @param host the host of the neighbour | 1177 | * @param host the host of the neighbour |
1179 | */ | 1178 | */ |
1180 | struct Neighbour * | 1179 | struct Neighbour * |
1181 | GST_create_neighbour (struct GNUNET_TESTBED_Host *host) | 1180 | GST_create_neighbour(struct GNUNET_TESTBED_Host *host) |
1182 | { | 1181 | { |
1183 | struct Neighbour *n; | 1182 | struct Neighbour *n; |
1184 | 1183 | ||
1185 | n = GNUNET_new (struct Neighbour); | 1184 | n = GNUNET_new(struct Neighbour); |
1186 | n->host_id = GNUNET_TESTBED_host_get_id_ (host); | 1185 | n->host_id = GNUNET_TESTBED_host_get_id_(host); |
1187 | neighbour_list_add (n); /* just add; connect on-demand */ | 1186 | neighbour_list_add(n); /* just add; connect on-demand */ |
1188 | return n; | 1187 | return n; |
1189 | } | 1188 | } |
1190 | 1189 | ||
@@ -1196,8 +1195,8 @@ GST_create_neighbour (struct GNUNET_TESTBED_Host *host) | |||
1196 | * @param msg the actual message | 1195 | * @param msg the actual message |
1197 | */ | 1196 | */ |
1198 | void | 1197 | void |
1199 | handle_link_controllers (void *cls, | 1198 | handle_link_controllers(void *cls, |
1200 | const struct GNUNET_TESTBED_ControllerLinkRequest *msg) | 1199 | const struct GNUNET_TESTBED_ControllerLinkRequest *msg) |
1201 | { | 1200 | { |
1202 | struct GNUNET_SERVICE_Client *client = cls; | 1201 | struct GNUNET_SERVICE_Client *client = cls; |
1203 | struct LCFContext *lcf; | 1202 | struct LCFContext *lcf; |
@@ -1208,169 +1207,169 @@ handle_link_controllers (void *cls, | |||
1208 | uint32_t slave_host_id; | 1207 | uint32_t slave_host_id; |
1209 | 1208 | ||
1210 | if (NULL == GST_context) | 1209 | if (NULL == GST_context) |
1211 | { | 1210 | { |
1212 | GNUNET_break (0); | 1211 | GNUNET_break(0); |
1213 | GNUNET_SERVICE_client_drop (client); | 1212 | GNUNET_SERVICE_client_drop(client); |
1214 | return; | 1213 | return; |
1215 | } | 1214 | } |
1216 | delegated_host_id = ntohl (msg->delegated_host_id); | 1215 | delegated_host_id = ntohl(msg->delegated_host_id); |
1217 | if (delegated_host_id == GST_context->host_id) | 1216 | if (delegated_host_id == GST_context->host_id) |
1218 | { | 1217 | { |
1219 | GNUNET_break (0); | 1218 | GNUNET_break(0); |
1220 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1219 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1221 | "Trying to link ourselves\n"); | 1220 | "Trying to link ourselves\n"); |
1222 | GNUNET_SERVICE_client_drop (client); | 1221 | GNUNET_SERVICE_client_drop(client); |
1223 | return; | 1222 | return; |
1224 | } | 1223 | } |
1225 | if ((delegated_host_id >= GST_host_list_size) || | 1224 | if ((delegated_host_id >= GST_host_list_size) || |
1226 | (NULL == GST_host_list[delegated_host_id])) | 1225 | (NULL == GST_host_list[delegated_host_id])) |
1227 | { | 1226 | { |
1228 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1227 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1229 | "Delegated host %u not registered with us\n", | 1228 | "Delegated host %u not registered with us\n", |
1230 | delegated_host_id); | 1229 | delegated_host_id); |
1231 | GNUNET_SERVICE_client_drop (client); | 1230 | GNUNET_SERVICE_client_drop(client); |
1232 | return; | 1231 | return; |
1233 | } | 1232 | } |
1234 | slave_host_id = ntohl (msg->slave_host_id); | 1233 | slave_host_id = ntohl(msg->slave_host_id); |
1235 | if ((slave_host_id >= GST_host_list_size) || | 1234 | if ((slave_host_id >= GST_host_list_size) || |
1236 | (NULL == GST_host_list[slave_host_id])) | 1235 | (NULL == GST_host_list[slave_host_id])) |
1237 | { | 1236 | { |
1238 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1237 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1239 | "Slave host %u not registered with us\n", | 1238 | "Slave host %u not registered with us\n", |
1240 | slave_host_id); | 1239 | slave_host_id); |
1241 | GNUNET_SERVICE_client_drop (client); | 1240 | GNUNET_SERVICE_client_drop(client); |
1242 | return; | 1241 | return; |
1243 | } | 1242 | } |
1244 | if (slave_host_id == delegated_host_id) | 1243 | if (slave_host_id == delegated_host_id) |
1245 | { | ||
1246 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1247 | "Slave and delegated host are same\n"); | ||
1248 | GNUNET_SERVICE_client_drop (client); | ||
1249 | return; | ||
1250 | } | ||
1251 | op_id = GNUNET_ntohll (msg->operation_id); | ||
1252 | if (slave_host_id == GST_context->host_id) /* Link from us */ | ||
1253 | { | ||
1254 | struct Slave *slave; | ||
1255 | struct LinkControllersContext *lcc; | ||
1256 | |||
1257 | if (1 != msg->is_subordinate) | ||
1258 | { | 1244 | { |
1259 | struct Neighbour *n; | 1245 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1260 | struct NeighbourConnectCtxt *ncc; | 1246 | "Slave and delegated host are same\n"); |
1261 | 1247 | GNUNET_SERVICE_client_drop(client); | |
1262 | if ((delegated_host_id < neighbour_list_size) && | ||
1263 | (NULL != neighbour_list[delegated_host_id])) | ||
1264 | { | ||
1265 | GNUNET_break (0); | ||
1266 | GNUNET_SERVICE_client_drop (client); | ||
1267 | return; | ||
1268 | } | ||
1269 | LOG_DEBUG ("Received request to establish a link to host %u\n", | ||
1270 | delegated_host_id); | ||
1271 | n = GST_create_neighbour (GST_host_list[delegated_host_id]); | ||
1272 | ncc = GNUNET_new (struct NeighbourConnectCtxt); | ||
1273 | ncc->n = n; | ||
1274 | ncc->op_id = op_id; | ||
1275 | ncc->client = client; | ||
1276 | ncc->nh = GST_neighbour_get_connection (n, | ||
1277 | &neighbour_connect_cb, | ||
1278 | ncc); | ||
1279 | ncc->timeout_task | ||
1280 | = GNUNET_SCHEDULER_add_delayed (GST_timeout, | ||
1281 | &timeout_neighbour_connect, | ||
1282 | ncc); | ||
1283 | GNUNET_CONTAINER_DLL_insert_tail (ncc_head, | ||
1284 | ncc_tail, | ||
1285 | ncc); | ||
1286 | GNUNET_SERVICE_client_continue (client); | ||
1287 | return; | 1248 | return; |
1288 | } | 1249 | } |
1289 | if ( (delegated_host_id < GST_slave_list_size) && | 1250 | op_id = GNUNET_ntohll(msg->operation_id); |
1290 | (NULL != GST_slave_list[delegated_host_id]) ) | 1251 | if (slave_host_id == GST_context->host_id) /* Link from us */ |
1291 | { | 1252 | { |
1292 | GNUNET_break (0); | 1253 | struct Slave *slave; |
1293 | GNUNET_SERVICE_client_drop (client); | 1254 | struct LinkControllersContext *lcc; |
1255 | |||
1256 | if (1 != msg->is_subordinate) | ||
1257 | { | ||
1258 | struct Neighbour *n; | ||
1259 | struct NeighbourConnectCtxt *ncc; | ||
1260 | |||
1261 | if ((delegated_host_id < neighbour_list_size) && | ||
1262 | (NULL != neighbour_list[delegated_host_id])) | ||
1263 | { | ||
1264 | GNUNET_break(0); | ||
1265 | GNUNET_SERVICE_client_drop(client); | ||
1266 | return; | ||
1267 | } | ||
1268 | LOG_DEBUG("Received request to establish a link to host %u\n", | ||
1269 | delegated_host_id); | ||
1270 | n = GST_create_neighbour(GST_host_list[delegated_host_id]); | ||
1271 | ncc = GNUNET_new(struct NeighbourConnectCtxt); | ||
1272 | ncc->n = n; | ||
1273 | ncc->op_id = op_id; | ||
1274 | ncc->client = client; | ||
1275 | ncc->nh = GST_neighbour_get_connection(n, | ||
1276 | &neighbour_connect_cb, | ||
1277 | ncc); | ||
1278 | ncc->timeout_task | ||
1279 | = GNUNET_SCHEDULER_add_delayed(GST_timeout, | ||
1280 | &timeout_neighbour_connect, | ||
1281 | ncc); | ||
1282 | GNUNET_CONTAINER_DLL_insert_tail(ncc_head, | ||
1283 | ncc_tail, | ||
1284 | ncc); | ||
1285 | GNUNET_SERVICE_client_continue(client); | ||
1286 | return; | ||
1287 | } | ||
1288 | if ((delegated_host_id < GST_slave_list_size) && | ||
1289 | (NULL != GST_slave_list[delegated_host_id])) | ||
1290 | { | ||
1291 | GNUNET_break(0); | ||
1292 | GNUNET_SERVICE_client_drop(client); | ||
1293 | return; | ||
1294 | } | ||
1295 | LOG_DEBUG("Received request to start and establish a link to host %u\n", | ||
1296 | delegated_host_id); | ||
1297 | slave = GNUNET_new(struct Slave); | ||
1298 | slave->host_id = delegated_host_id; | ||
1299 | slave->reghost_map = GNUNET_CONTAINER_multihashmap_create(100, | ||
1300 | GNUNET_NO); | ||
1301 | slave_list_add(slave); | ||
1302 | lcc = GNUNET_new(struct LinkControllersContext); | ||
1303 | lcc->operation_id = op_id; | ||
1304 | lcc->client = client; | ||
1305 | slave->lcc = lcc; | ||
1306 | slave->controller_proc | ||
1307 | = GNUNET_TESTBED_controller_start(GST_context->master_ip, | ||
1308 | GST_host_list[slave->host_id], | ||
1309 | &slave_status_cb, | ||
1310 | slave); | ||
1311 | new_route = GNUNET_new(struct Route); | ||
1312 | new_route->dest = delegated_host_id; | ||
1313 | new_route->thru = GST_context->host_id; | ||
1314 | route_list_add(new_route); | ||
1294 | return; | 1315 | return; |
1295 | } | 1316 | } |
1296 | LOG_DEBUG ("Received request to start and establish a link to host %u\n", | ||
1297 | delegated_host_id); | ||
1298 | slave = GNUNET_new (struct Slave); | ||
1299 | slave->host_id = delegated_host_id; | ||
1300 | slave->reghost_map = GNUNET_CONTAINER_multihashmap_create (100, | ||
1301 | GNUNET_NO); | ||
1302 | slave_list_add (slave); | ||
1303 | lcc = GNUNET_new (struct LinkControllersContext); | ||
1304 | lcc->operation_id = op_id; | ||
1305 | lcc->client = client; | ||
1306 | slave->lcc = lcc; | ||
1307 | slave->controller_proc | ||
1308 | = GNUNET_TESTBED_controller_start (GST_context->master_ip, | ||
1309 | GST_host_list[slave->host_id], | ||
1310 | &slave_status_cb, | ||
1311 | slave); | ||
1312 | new_route = GNUNET_new (struct Route); | ||
1313 | new_route->dest = delegated_host_id; | ||
1314 | new_route->thru = GST_context->host_id; | ||
1315 | route_list_add (new_route); | ||
1316 | return; | ||
1317 | } | ||
1318 | 1317 | ||
1319 | /* Route the request */ | 1318 | /* Route the request */ |
1320 | if (slave_host_id >= route_list_size) | 1319 | if (slave_host_id >= route_list_size) |
1321 | { | 1320 | { |
1322 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1321 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1323 | "No route towards slave host"); | 1322 | "No route towards slave host"); |
1324 | GNUNET_SERVICE_client_drop (client); | 1323 | GNUNET_SERVICE_client_drop(client); |
1325 | return; | 1324 | return; |
1326 | } | 1325 | } |
1327 | lcf = GNUNET_new (struct LCFContext); | 1326 | lcf = GNUNET_new(struct LCFContext); |
1328 | lcf->delegated_host_id = delegated_host_id; | 1327 | lcf->delegated_host_id = delegated_host_id; |
1329 | lcf->slave_host_id = slave_host_id; | 1328 | lcf->slave_host_id = slave_host_id; |
1330 | route = GST_find_dest_route (slave_host_id); | 1329 | route = GST_find_dest_route(slave_host_id); |
1331 | GNUNET_assert (NULL != route); /* because we add routes carefully */ | 1330 | GNUNET_assert(NULL != route); /* because we add routes carefully */ |
1332 | GNUNET_assert (route->dest < GST_slave_list_size); | 1331 | GNUNET_assert(route->dest < GST_slave_list_size); |
1333 | GNUNET_assert (NULL != GST_slave_list[route->dest]); | 1332 | GNUNET_assert(NULL != GST_slave_list[route->dest]); |
1334 | lcf->is_subordinate = msg->is_subordinate; | 1333 | lcf->is_subordinate = msg->is_subordinate; |
1335 | lcf->state = INIT; | 1334 | lcf->state = INIT; |
1336 | lcf->operation_id = op_id; | 1335 | lcf->operation_id = op_id; |
1337 | lcf->gateway = GST_slave_list[route->dest]; | 1336 | lcf->gateway = GST_slave_list[route->dest]; |
1338 | lcf->client = client; | 1337 | lcf->client = client; |
1339 | if (NULL == lcf_head) | 1338 | if (NULL == lcf_head) |
1340 | { | 1339 | { |
1341 | GNUNET_assert (NULL == lcf_proc_task_id); | 1340 | GNUNET_assert(NULL == lcf_proc_task_id); |
1342 | GNUNET_CONTAINER_DLL_insert_tail (lcf_head, | 1341 | GNUNET_CONTAINER_DLL_insert_tail(lcf_head, |
1343 | lcf_tail, | 1342 | lcf_tail, |
1344 | lcf); | 1343 | lcf); |
1345 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, | 1344 | lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, |
1346 | lcf); | 1345 | lcf); |
1347 | } | 1346 | } |
1348 | else | 1347 | else |
1349 | { | 1348 | { |
1350 | GNUNET_CONTAINER_DLL_insert_tail (lcf_head, | 1349 | GNUNET_CONTAINER_DLL_insert_tail(lcf_head, |
1351 | lcf_tail, | 1350 | lcf_tail, |
1352 | lcf); | 1351 | lcf); |
1353 | } | 1352 | } |
1354 | /* FIXME: Adding a new route should happen after the controllers are linked | 1353 | /* FIXME: Adding a new route should happen after the controllers are linked |
1355 | * successfully */ | 1354 | * successfully */ |
1356 | if (1 != msg->is_subordinate) | 1355 | if (1 != msg->is_subordinate) |
1357 | { | 1356 | { |
1358 | GNUNET_SERVICE_client_continue (client); | 1357 | GNUNET_SERVICE_client_continue(client); |
1359 | return; | 1358 | return; |
1360 | } | 1359 | } |
1361 | if ( (delegated_host_id < route_list_size) && | 1360 | if ((delegated_host_id < route_list_size) && |
1362 | (NULL != route_list[delegated_host_id]) ) | 1361 | (NULL != route_list[delegated_host_id])) |
1363 | { | 1362 | { |
1364 | GNUNET_break_op (0); /* Are you trying to link delegated host twice | 1363 | GNUNET_break_op(0); /* Are you trying to link delegated host twice |
1365 | * with is subordinate flag set to GNUNET_YES? */ | 1364 | * with is subordinate flag set to GNUNET_YES? */ |
1366 | GNUNET_SERVICE_client_drop (client); | 1365 | GNUNET_SERVICE_client_drop(client); |
1367 | return; | 1366 | return; |
1368 | } | 1367 | } |
1369 | new_route = GNUNET_new (struct Route); | 1368 | new_route = GNUNET_new(struct Route); |
1370 | new_route->dest = delegated_host_id; | 1369 | new_route->dest = delegated_host_id; |
1371 | new_route->thru = route->dest; | 1370 | new_route->thru = route->dest; |
1372 | route_list_add (new_route); | 1371 | route_list_add(new_route); |
1373 | GNUNET_SERVICE_client_continue (client); | 1372 | GNUNET_SERVICE_client_continue(client); |
1374 | } | 1373 | } |
1375 | 1374 | ||
1376 | 1375 | ||
@@ -1381,7 +1380,7 @@ handle_link_controllers (void *cls, | |||
1381 | * @param client the client that is history | 1380 | * @param client the client that is history |
1382 | */ | 1381 | */ |
1383 | void | 1382 | void |
1384 | GST_link_notify_disconnect (struct GNUNET_SERVICE_Client *client) | 1383 | GST_link_notify_disconnect(struct GNUNET_SERVICE_Client *client) |
1385 | { | 1384 | { |
1386 | struct NeighbourConnectCtxt *ncc; | 1385 | struct NeighbourConnectCtxt *ncc; |
1387 | struct NeighbourConnectCtxt *nccn; | 1386 | struct NeighbourConnectCtxt *nccn; |
@@ -1389,44 +1388,44 @@ GST_link_notify_disconnect (struct GNUNET_SERVICE_Client *client) | |||
1389 | struct LCFContext *lcfn; | 1388 | struct LCFContext *lcfn; |
1390 | 1389 | ||
1391 | for (ncc = ncc_head; NULL != ncc; ncc = nccn) | 1390 | for (ncc = ncc_head; NULL != ncc; ncc = nccn) |
1392 | { | ||
1393 | nccn = ncc->next; | ||
1394 | if (ncc->client == client) | ||
1395 | cleanup_ncc (ncc); | ||
1396 | } | ||
1397 | for (unsigned int i=0;i<GST_slave_list_size;i++) | ||
1398 | { | ||
1399 | struct Slave *slave = GST_slave_list[i]; | ||
1400 | struct LinkControllersContext *lcc; | ||
1401 | |||
1402 | if (NULL == slave) | ||
1403 | continue; | ||
1404 | GNUNET_CONTAINER_multihashmap_iterate (slave->reghost_map, | ||
1405 | &drop_client_entries, | ||
1406 | client); | ||
1407 | lcc = slave->lcc; | ||
1408 | if (NULL == lcc) | ||
1409 | continue; | ||
1410 | if (lcc->client == client) | ||
1411 | { | 1391 | { |
1412 | slave->lcc = NULL; | 1392 | nccn = ncc->next; |
1413 | GNUNET_free (lcc); | 1393 | if (ncc->client == client) |
1394 | cleanup_ncc(ncc); | ||
1395 | } | ||
1396 | for (unsigned int i = 0; i < GST_slave_list_size; i++) | ||
1397 | { | ||
1398 | struct Slave *slave = GST_slave_list[i]; | ||
1399 | struct LinkControllersContext *lcc; | ||
1400 | |||
1401 | if (NULL == slave) | ||
1402 | continue; | ||
1403 | GNUNET_CONTAINER_multihashmap_iterate(slave->reghost_map, | ||
1404 | &drop_client_entries, | ||
1405 | client); | ||
1406 | lcc = slave->lcc; | ||
1407 | if (NULL == lcc) | ||
1408 | continue; | ||
1409 | if (lcc->client == client) | ||
1410 | { | ||
1411 | slave->lcc = NULL; | ||
1412 | GNUNET_free(lcc); | ||
1413 | } | ||
1414 | } | 1414 | } |
1415 | } | ||
1416 | for (lcf = lcf_head; NULL != lcf; lcf = lcfn) | 1415 | for (lcf = lcf_head; NULL != lcf; lcf = lcfn) |
1417 | { | ||
1418 | lcfn = lcf->next; | ||
1419 | if ( (NULL != lcf) && | ||
1420 | (client == lcf->client) ) | ||
1421 | { | 1416 | { |
1422 | if (NULL != lcf->op) | 1417 | lcfn = lcf->next; |
1423 | GNUNET_TESTBED_operation_done (lcf->op); | 1418 | if ((NULL != lcf) && |
1424 | GNUNET_CONTAINER_DLL_remove (lcf_head, | 1419 | (client == lcf->client)) |
1425 | lcf_tail, | 1420 | { |
1426 | lcf); | 1421 | if (NULL != lcf->op) |
1427 | GNUNET_free (lcf); | 1422 | GNUNET_TESTBED_operation_done(lcf->op); |
1423 | GNUNET_CONTAINER_DLL_remove(lcf_head, | ||
1424 | lcf_tail, | ||
1425 | lcf); | ||
1426 | GNUNET_free(lcf); | ||
1427 | } | ||
1428 | } | 1428 | } |
1429 | } | ||
1430 | } | 1429 | } |
1431 | 1430 | ||
1432 | 1431 | ||
@@ -1434,28 +1433,28 @@ GST_link_notify_disconnect (struct GNUNET_SERVICE_Client *client) | |||
1434 | * Cleans up the queue used for forwarding link controllers requests | 1433 | * Cleans up the queue used for forwarding link controllers requests |
1435 | */ | 1434 | */ |
1436 | void | 1435 | void |
1437 | GST_free_lcf () | 1436 | GST_free_lcf() |
1438 | { | 1437 | { |
1439 | struct LCFContext *lcf; | 1438 | struct LCFContext *lcf; |
1440 | 1439 | ||
1441 | if (NULL != lcf_head) | 1440 | if (NULL != lcf_head) |
1442 | { | ||
1443 | if (NULL != lcf_proc_task_id) | ||
1444 | { | 1441 | { |
1445 | GNUNET_SCHEDULER_cancel (lcf_proc_task_id); | 1442 | if (NULL != lcf_proc_task_id) |
1446 | lcf_proc_task_id = NULL; | 1443 | { |
1444 | GNUNET_SCHEDULER_cancel(lcf_proc_task_id); | ||
1445 | lcf_proc_task_id = NULL; | ||
1446 | } | ||
1447 | } | 1447 | } |
1448 | } | 1448 | GNUNET_assert(NULL == lcf_proc_task_id); |
1449 | GNUNET_assert (NULL == lcf_proc_task_id); | ||
1450 | for (lcf = lcf_head; NULL != lcf; lcf = lcf_head) | 1449 | for (lcf = lcf_head; NULL != lcf; lcf = lcf_head) |
1451 | { | 1450 | { |
1452 | if (NULL != lcf->op) | 1451 | if (NULL != lcf->op) |
1453 | GNUNET_TESTBED_operation_done (lcf->op); | 1452 | GNUNET_TESTBED_operation_done(lcf->op); |
1454 | if (NULL != lcf->timeout_task) | 1453 | if (NULL != lcf->timeout_task) |
1455 | GNUNET_SCHEDULER_cancel (lcf->timeout_task); | 1454 | GNUNET_SCHEDULER_cancel(lcf->timeout_task); |
1456 | GNUNET_CONTAINER_DLL_remove (lcf_head, | 1455 | GNUNET_CONTAINER_DLL_remove(lcf_head, |
1457 | lcf_tail, | 1456 | lcf_tail, |
1458 | lcf); | 1457 | lcf); |
1459 | GNUNET_free (lcf); | 1458 | GNUNET_free(lcf); |
1460 | } | 1459 | } |
1461 | } | 1460 | } |
diff --git a/src/testbed/gnunet-service-testbed_links.h b/src/testbed/gnunet-service-testbed_links.h index e4824ede9..594ef29dc 100644 --- a/src/testbed/gnunet-service-testbed_links.h +++ b/src/testbed/gnunet-service-testbed_links.h | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2013 GNUnet e.V. | 3 | Copyright (C) 2008--2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/gnunet-service-testbed_links.h | 22 | * @file testbed/gnunet-service-testbed_links.h |
@@ -35,8 +35,7 @@ struct Neighbour; | |||
35 | /** | 35 | /** |
36 | * Structure representing a connected(directly-linked) controller | 36 | * Structure representing a connected(directly-linked) controller |
37 | */ | 37 | */ |
38 | struct Slave | 38 | struct Slave { |
39 | { | ||
40 | /** | 39 | /** |
41 | * The controller process handle if we had started the controller | 40 | * The controller process handle if we had started the controller |
42 | */ | 41 | */ |
@@ -94,7 +93,7 @@ extern unsigned int GST_slave_list_size; | |||
94 | * Cleans up the neighbour list | 93 | * Cleans up the neighbour list |
95 | */ | 94 | */ |
96 | void | 95 | void |
97 | GST_neighbour_list_clean (void); | 96 | GST_neighbour_list_clean(void); |
98 | 97 | ||
99 | 98 | ||
100 | /** | 99 | /** |
@@ -105,14 +104,14 @@ GST_neighbour_list_clean (void); | |||
105 | * the list size or neighbour at that index is NULL) | 104 | * the list size or neighbour at that index is NULL) |
106 | */ | 105 | */ |
107 | struct Neighbour * | 106 | struct Neighbour * |
108 | GST_get_neighbour (uint32_t id); | 107 | GST_get_neighbour(uint32_t id); |
109 | 108 | ||
110 | 109 | ||
111 | /** | 110 | /** |
112 | * Function to cleanup the neighbour connect contexts | 111 | * Function to cleanup the neighbour connect contexts |
113 | */ | 112 | */ |
114 | void | 113 | void |
115 | GST_free_nccq (void); | 114 | GST_free_nccq(void); |
116 | 115 | ||
117 | 116 | ||
118 | /** | 117 | /** |
@@ -145,9 +144,9 @@ typedef void | |||
145 | * @param cb_cls the closure for the above callback | 144 | * @param cb_cls the closure for the above callback |
146 | */ | 145 | */ |
147 | struct NeighbourConnectNotification * | 146 | struct NeighbourConnectNotification * |
148 | GST_neighbour_get_connection (struct Neighbour *n, | 147 | GST_neighbour_get_connection(struct Neighbour *n, |
149 | GST_NeigbourConnectNotifyCallback cb, | 148 | GST_NeigbourConnectNotifyCallback cb, |
150 | void *cb_cls); | 149 | void *cb_cls); |
151 | 150 | ||
152 | 151 | ||
153 | /** | 152 | /** |
@@ -156,7 +155,7 @@ GST_neighbour_get_connection (struct Neighbour *n, | |||
156 | * @param h the notification handle | 155 | * @param h the notification handle |
157 | */ | 156 | */ |
158 | void | 157 | void |
159 | GST_neighbour_get_connection_cancel (struct NeighbourConnectNotification *h); | 158 | GST_neighbour_get_connection_cancel(struct NeighbourConnectNotification *h); |
160 | 159 | ||
161 | 160 | ||
162 | /** | 161 | /** |
@@ -167,7 +166,7 @@ GST_neighbour_get_connection_cancel (struct NeighbourConnectNotification *h); | |||
167 | * @param n the neighbour whose connection can be closed | 166 | * @param n the neighbour whose connection can be closed |
168 | */ | 167 | */ |
169 | void | 168 | void |
170 | GST_neighbour_release_connection (struct Neighbour *n); | 169 | GST_neighbour_release_connection(struct Neighbour *n); |
171 | 170 | ||
172 | 171 | ||
173 | /** | 172 | /** |
@@ -176,7 +175,7 @@ GST_neighbour_release_connection (struct Neighbour *n); | |||
176 | * @param host the host of the neighbour | 175 | * @param host the host of the neighbour |
177 | */ | 176 | */ |
178 | struct Neighbour * | 177 | struct Neighbour * |
179 | GST_create_neighbour (struct GNUNET_TESTBED_Host *host); | 178 | GST_create_neighbour(struct GNUNET_TESTBED_Host *host); |
180 | 179 | ||
181 | 180 | ||
182 | /** | 181 | /** |
@@ -186,8 +185,8 @@ GST_create_neighbour (struct GNUNET_TESTBED_Host *host); | |||
186 | * @param msg the actual message | 185 | * @param msg the actual message |
187 | */ | 186 | */ |
188 | void | 187 | void |
189 | handle_link_controllers (void *cls, | 188 | handle_link_controllers(void *cls, |
190 | const struct GNUNET_TESTBED_ControllerLinkRequest *msg); | 189 | const struct GNUNET_TESTBED_ControllerLinkRequest *msg); |
191 | 190 | ||
192 | 191 | ||
193 | /** | 192 | /** |
@@ -197,11 +196,11 @@ handle_link_controllers (void *cls, | |||
197 | * @param client the client that is history | 196 | * @param client the client that is history |
198 | */ | 197 | */ |
199 | void | 198 | void |
200 | GST_link_notify_disconnect (struct GNUNET_SERVICE_Client *client); | 199 | GST_link_notify_disconnect(struct GNUNET_SERVICE_Client *client); |
201 | 200 | ||
202 | 201 | ||
203 | /** | 202 | /** |
204 | * Cleans up the slave list | 203 | * Cleans up the slave list |
205 | */ | 204 | */ |
206 | void | 205 | void |
207 | GST_slave_list_clear (void); | 206 | GST_slave_list_clear(void); |
diff --git a/src/testbed/gnunet-service-testbed_meminfo.c b/src/testbed/gnunet-service-testbed_meminfo.c index 7b42331b5..27778447c 100644 --- a/src/testbed/gnunet-service-testbed_meminfo.c +++ b/src/testbed/gnunet-service-testbed_meminfo.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | #include "platform.h" | 21 | #include "platform.h" |
22 | #include "gnunet_util_lib.h" | 22 | #include "gnunet_util_lib.h" |
@@ -42,11 +42,11 @@ | |||
42 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 42 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
43 | */ | 43 | */ |
44 | 44 | ||
45 | #define BAD_OPEN_MESSAGE \ | 45 | #define BAD_OPEN_MESSAGE \ |
46 | "Error: /proc must be mounted\n" \ | 46 | "Error: /proc must be mounted\n" \ |
47 | " To mount /proc at boot you need an /etc/fstab line like:\n" \ | 47 | " To mount /proc at boot you need an /etc/fstab line like:\n" \ |
48 | " proc /proc proc defaults\n" \ | 48 | " proc /proc proc defaults\n" \ |
49 | " In the meantime, run \"mount proc /proc -t proc\"\n" | 49 | " In the meantime, run \"mount proc /proc -t proc\"\n" |
50 | 50 | ||
51 | #define STAT_FILE "/proc/stat" | 51 | #define STAT_FILE "/proc/stat" |
52 | //static int stat_fd = -1; | 52 | //static int stat_fd = -1; |
@@ -67,21 +67,21 @@ static char buf[2048]; | |||
67 | * that successive calls to the functions are more efficient. | 67 | * that successive calls to the functions are more efficient. |
68 | * It also reads the current contents of the file into the global buf. | 68 | * It also reads the current contents of the file into the global buf. |
69 | */ | 69 | */ |
70 | #define FILE_TO_BUF(filename, fd) do{ \ | 70 | #define FILE_TO_BUF(filename, fd) do { \ |
71 | static int local_n; \ | 71 | static int local_n; \ |
72 | if (fd == -1 && (fd = open(filename, O_RDONLY)) == -1) { \ | 72 | if (fd == -1 && (fd = open(filename, O_RDONLY)) == -1) { \ |
73 | fputs(BAD_OPEN_MESSAGE, stderr); \ | 73 | fputs(BAD_OPEN_MESSAGE, stderr); \ |
74 | fflush(NULL); \ | 74 | fflush(NULL); \ |
75 | _exit(102); \ | 75 | _exit(102); \ |
76 | } \ | 76 | } \ |
77 | lseek(fd, 0L, SEEK_SET); \ | 77 | lseek(fd, 0L, SEEK_SET); \ |
78 | if ((local_n = read(fd, buf, sizeof buf - 1)) < 0) { \ | 78 | if ((local_n = read(fd, buf, sizeof buf - 1)) < 0) { \ |
79 | perror(filename); \ | 79 | perror(filename); \ |
80 | fflush(NULL); \ | 80 | fflush(NULL); \ |
81 | _exit(103); \ | 81 | _exit(103); \ |
82 | } \ | 82 | } \ |
83 | buf[local_n] = '\0'; \ | 83 | buf[local_n] = '\0'; \ |
84 | }while(0) | 84 | } while (0) |
85 | 85 | ||
86 | 86 | ||
87 | /***********************************************************************/ | 87 | /***********************************************************************/ |
@@ -101,8 +101,9 @@ typedef struct mem_table_struct { | |||
101 | unsigned long *slot; /* slot in return struct */ | 101 | unsigned long *slot; /* slot in return struct */ |
102 | } mem_table_struct; | 102 | } mem_table_struct; |
103 | 103 | ||
104 | static int compare_mem_table_structs(const void *a, const void *b){ | 104 | static int compare_mem_table_structs(const void *a, const void *b) |
105 | return strcmp(((const mem_table_struct*)a)->name,((const mem_table_struct*)b)->name); | 105 | { |
106 | return strcmp(((const mem_table_struct*)a)->name, ((const mem_table_struct*)b)->name); | ||
106 | } | 107 | } |
107 | 108 | ||
108 | /* example data, following junk, with comments added: | 109 | /* example data, following junk, with comments added: |
@@ -182,82 +183,90 @@ static unsigned long kb_nfs_unstable; | |||
182 | static unsigned long kb_swap_reclaimable; | 183 | static unsigned long kb_swap_reclaimable; |
183 | static unsigned long kb_swap_unreclaimable; | 184 | static unsigned long kb_swap_unreclaimable; |
184 | 185 | ||
185 | void meminfo(void){ | 186 | void meminfo(void) |
187 | { | ||
186 | char namebuf[16]; /* big enough to hold any row name */ | 188 | char namebuf[16]; /* big enough to hold any row name */ |
187 | mem_table_struct findme = { namebuf, NULL}; | 189 | mem_table_struct findme = { namebuf, NULL }; |
188 | mem_table_struct *found; | 190 | mem_table_struct *found; |
189 | char *head; | 191 | char *head; |
190 | char *tail; | 192 | char *tail; |
191 | static const mem_table_struct mem_table[] = { | 193 | static const mem_table_struct mem_table[] = { |
192 | {"Active", &kb_active}, // important | 194 | { "Active", &kb_active }, // important |
193 | {"AnonPages", &kb_anon_pages}, | 195 | { "AnonPages", &kb_anon_pages }, |
194 | {"Bounce", &kb_bounce}, | 196 | { "Bounce", &kb_bounce }, |
195 | {"Buffers", &kb_main_buffers}, // important | 197 | { "Buffers", &kb_main_buffers }, // important |
196 | {"Cached", &kb_main_cached}, // important | 198 | { "Cached", &kb_main_cached }, // important |
197 | {"CommitLimit", &kb_commit_limit}, | 199 | { "CommitLimit", &kb_commit_limit }, |
198 | {"Committed_AS", &kb_committed_as}, | 200 | { "Committed_AS", &kb_committed_as }, |
199 | {"Dirty", &kb_dirty}, // kB version of vmstat nr_dirty | 201 | { "Dirty", &kb_dirty }, // kB version of vmstat nr_dirty |
200 | {"HighFree", &kb_high_free}, | 202 | { "HighFree", &kb_high_free }, |
201 | {"HighTotal", &kb_high_total}, | 203 | { "HighTotal", &kb_high_total }, |
202 | {"Inact_clean", &kb_inact_clean}, | 204 | { "Inact_clean", &kb_inact_clean }, |
203 | {"Inact_dirty", &kb_inact_dirty}, | 205 | { "Inact_dirty", &kb_inact_dirty }, |
204 | {"Inact_laundry",&kb_inact_laundry}, | 206 | { "Inact_laundry", &kb_inact_laundry }, |
205 | {"Inact_target", &kb_inact_target}, | 207 | { "Inact_target", &kb_inact_target }, |
206 | {"Inactive", &kb_inactive}, // important | 208 | { "Inactive", &kb_inactive }, // important |
207 | {"LowFree", &kb_low_free}, | 209 | { "LowFree", &kb_low_free }, |
208 | {"LowTotal", &kb_low_total}, | 210 | { "LowTotal", &kb_low_total }, |
209 | {"Mapped", &kb_mapped}, // kB version of vmstat nr_mapped | 211 | { "Mapped", &kb_mapped }, // kB version of vmstat nr_mapped |
210 | {"MemFree", &kb_main_free}, // important | 212 | { "MemFree", &kb_main_free }, // important |
211 | {"MemShared", &kb_main_shared}, // important, but now gone! | 213 | { "MemShared", &kb_main_shared }, // important, but now gone! |
212 | {"MemTotal", &kb_main_total}, // important | 214 | { "MemTotal", &kb_main_total }, // important |
213 | {"NFS_Unstable", &kb_nfs_unstable}, | 215 | { "NFS_Unstable", &kb_nfs_unstable }, |
214 | {"PageTables", &kb_pagetables}, // kB version of vmstat nr_page_table_pages | 216 | { "PageTables", &kb_pagetables }, // kB version of vmstat nr_page_table_pages |
215 | {"ReverseMaps", &nr_reversemaps}, // same as vmstat nr_page_table_pages | 217 | { "ReverseMaps", &nr_reversemaps }, // same as vmstat nr_page_table_pages |
216 | {"SReclaimable", &kb_swap_reclaimable}, // "swap reclaimable" (dentry and inode structures) | 218 | { "SReclaimable", &kb_swap_reclaimable }, // "swap reclaimable" (dentry and inode structures) |
217 | {"SUnreclaim", &kb_swap_unreclaimable}, | 219 | { "SUnreclaim", &kb_swap_unreclaimable }, |
218 | {"Slab", &kb_slab}, // kB version of vmstat nr_slab | 220 | { "Slab", &kb_slab }, // kB version of vmstat nr_slab |
219 | {"SwapCached", &kb_swap_cached}, | 221 | { "SwapCached", &kb_swap_cached }, |
220 | {"SwapFree", &kb_swap_free}, // important | 222 | { "SwapFree", &kb_swap_free }, // important |
221 | {"SwapTotal", &kb_swap_total}, // important | 223 | { "SwapTotal", &kb_swap_total }, // important |
222 | {"VmallocChunk", &kb_vmalloc_chunk}, | 224 | { "VmallocChunk", &kb_vmalloc_chunk }, |
223 | {"VmallocTotal", &kb_vmalloc_total}, | 225 | { "VmallocTotal", &kb_vmalloc_total }, |
224 | {"VmallocUsed", &kb_vmalloc_used}, | 226 | { "VmallocUsed", &kb_vmalloc_used }, |
225 | {"Writeback", &kb_writeback}, // kB version of vmstat nr_writeback | 227 | { "Writeback", &kb_writeback }, // kB version of vmstat nr_writeback |
226 | }; | 228 | }; |
227 | const int mem_table_count = sizeof(mem_table)/sizeof(mem_table_struct); | 229 | const int mem_table_count = sizeof(mem_table) / sizeof(mem_table_struct); |
228 | 230 | ||
229 | FILE_TO_BUF(MEMINFO_FILE,meminfo_fd); | 231 | FILE_TO_BUF(MEMINFO_FILE, meminfo_fd); |
230 | 232 | ||
231 | kb_inactive = ~0UL; | 233 | kb_inactive = ~0UL; |
232 | 234 | ||
233 | head = buf; | 235 | head = buf; |
234 | for(;;){ | 236 | for (;;) |
235 | tail = strchr(head, ':'); | 237 | { |
236 | if(!tail) break; | 238 | tail = strchr(head, ':'); |
237 | *tail = '\0'; | 239 | if (!tail) |
238 | if(strlen(head) >= sizeof(namebuf)){ | 240 | break; |
239 | head = tail+1; | 241 | *tail = '\0'; |
240 | goto nextline; | 242 | if (strlen(head) >= sizeof(namebuf)) |
241 | } | 243 | { |
242 | strcpy(namebuf,head); | 244 | head = tail + 1; |
243 | found = bsearch(&findme, mem_table, mem_table_count, | 245 | goto nextline; |
244 | sizeof(mem_table_struct), compare_mem_table_structs | 246 | } |
245 | ); | 247 | strcpy(namebuf, head); |
246 | head = tail+1; | 248 | found = bsearch(&findme, mem_table, mem_table_count, |
247 | if(!found) goto nextline; | 249 | sizeof(mem_table_struct), compare_mem_table_structs |
248 | *(found->slot) = (unsigned long)strtoull(head,&tail,10); | 250 | ); |
251 | head = tail + 1; | ||
252 | if (!found) | ||
253 | goto nextline; | ||
254 | *(found->slot) = (unsigned long)strtoull(head, &tail, 10); | ||
249 | nextline: | 255 | nextline: |
250 | tail = strchr(head, '\n'); | 256 | tail = strchr(head, '\n'); |
251 | if(!tail) break; | 257 | if (!tail) |
252 | head = tail+1; | 258 | break; |
253 | } | 259 | head = tail + 1; |
254 | if(!kb_low_total){ /* low==main except with large-memory support */ | 260 | } |
255 | kb_low_total = kb_main_total; | 261 | if (!kb_low_total) /* low==main except with large-memory support */ |
256 | kb_low_free = kb_main_free; | 262 | { |
257 | } | 263 | kb_low_total = kb_main_total; |
258 | if(kb_inactive==~0UL){ | 264 | kb_low_free = kb_main_free; |
259 | kb_inactive = kb_inact_dirty + kb_inact_clean + kb_inact_laundry; | 265 | } |
260 | } | 266 | if (kb_inactive == ~0UL) |
267 | { | ||
268 | kb_inactive = kb_inact_dirty + kb_inact_clean + kb_inact_laundry; | ||
269 | } | ||
261 | kb_swap_used = kb_swap_total - kb_swap_free; | 270 | kb_swap_used = kb_swap_total - kb_swap_free; |
262 | kb_main_used = kb_main_total - kb_main_free; | 271 | kb_main_used = kb_main_total - kb_main_free; |
263 | } | 272 | } |
diff --git a/src/testbed/gnunet-service-testbed_meminfo.h b/src/testbed/gnunet-service-testbed_meminfo.h index 6f51bdfb7..ceaae8999 100644 --- a/src/testbed/gnunet-service-testbed_meminfo.h +++ b/src/testbed/gnunet-service-testbed_meminfo.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /* obsolete */ | 21 | /* obsolete */ |
22 | extern unsigned long kb_main_shared; | 22 | extern unsigned long kb_main_shared; |
diff --git a/src/testbed/gnunet-service-testbed_oc.c b/src/testbed/gnunet-service-testbed_oc.c index 4d6a4d446..391b95b12 100644 --- a/src/testbed/gnunet-service-testbed_oc.c +++ b/src/testbed/gnunet-service-testbed_oc.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2016 GNUnet e.V. | 3 | Copyright (C) 2008--2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/gnunet-service-testbed_oc.c | 22 | * @file testbed/gnunet-service-testbed_oc.c |
@@ -34,16 +34,14 @@ | |||
34 | #ifdef LOG | 34 | #ifdef LOG |
35 | #undef LOG | 35 | #undef LOG |
36 | #endif | 36 | #endif |
37 | #define LOG(kind,...) \ | 37 | #define LOG(kind, ...) \ |
38 | GNUNET_log_from (kind, "testbed-OC", __VA_ARGS__) | 38 | GNUNET_log_from(kind, "testbed-OC", __VA_ARGS__) |
39 | 39 | ||
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Context information for requesting ATS to connect to a peer | 42 | * Context information for requesting ATS to connect to a peer |
43 | */ | 43 | */ |
44 | struct ConnectivitySuggestContext | 44 | struct ConnectivitySuggestContext { |
45 | { | ||
46 | |||
47 | /** | 45 | /** |
48 | * The transport handle obtained from cache. Do NOT close/disconnect. | 46 | * The transport handle obtained from cache. Do NOT close/disconnect. |
49 | */ | 47 | */ |
@@ -69,15 +67,13 @@ struct ConnectivitySuggestContext | |||
69 | * The ATS handle for the connectivity suggestion. | 67 | * The ATS handle for the connectivity suggestion. |
70 | */ | 68 | */ |
71 | struct GNUNET_ATS_ConnectivitySuggestHandle *csh; | 69 | struct GNUNET_ATS_ConnectivitySuggestHandle *csh; |
72 | |||
73 | }; | 70 | }; |
74 | 71 | ||
75 | 72 | ||
76 | /** | 73 | /** |
77 | * Types for context information we create for overlay connect requests | 74 | * Types for context information we create for overlay connect requests |
78 | */ | 75 | */ |
79 | enum OverlayConnectContextType | 76 | enum OverlayConnectContextType { |
80 | { | ||
81 | /** | 77 | /** |
82 | * This type is used if the overlay connection is local i.e. the connection | 78 | * This type is used if the overlay connection is local i.e. the connection |
83 | * has to be made between local peers | 79 | * has to be made between local peers |
@@ -102,8 +98,7 @@ enum OverlayConnectContextType | |||
102 | * Context data for operations on second peer in local overlay connection | 98 | * Context data for operations on second peer in local overlay connection |
103 | * contexts | 99 | * contexts |
104 | */ | 100 | */ |
105 | struct LocalPeer2Context | 101 | struct LocalPeer2Context { |
106 | { | ||
107 | /** | 102 | /** |
108 | * The handle for offering the HELLO of the first peer to the second | 103 | * The handle for offering the HELLO of the first peer to the second |
109 | * peer. | 104 | * peer. |
@@ -121,8 +116,7 @@ struct LocalPeer2Context | |||
121 | * Context data for operations on second peer in remote overlay connection | 116 | * Context data for operations on second peer in remote overlay connection |
122 | * contexts | 117 | * contexts |
123 | */ | 118 | */ |
124 | struct RemotePeer2Context | 119 | struct RemotePeer2Context { |
125 | { | ||
126 | /** | 120 | /** |
127 | * Controller of peer 2; If #OCC_TYPE_REMOTE_LATERAL is the type of overlay | 121 | * Controller of peer 2; If #OCC_TYPE_REMOTE_LATERAL is the type of overlay |
128 | * connection then this can be NULL until the connection to the controller is | 122 | * connection then this can be NULL until the connection to the controller is |
@@ -152,8 +146,7 @@ struct RemotePeer2Context | |||
152 | /** | 146 | /** |
153 | * Context information for connecting 2 peers in overlay. | 147 | * Context information for connecting 2 peers in overlay. |
154 | */ | 148 | */ |
155 | struct OverlayConnectContext | 149 | struct OverlayConnectContext { |
156 | { | ||
157 | /** | 150 | /** |
158 | * The next pointer for maintaining a DLL of all OverlayConnectContexts | 151 | * The next pointer for maintaining a DLL of all OverlayConnectContexts |
159 | */ | 152 | */ |
@@ -211,7 +204,6 @@ struct OverlayConnectContext | |||
211 | * Context information for operations on the second peer | 204 | * Context information for operations on the second peer |
212 | */ | 205 | */ |
213 | union { | 206 | union { |
214 | |||
215 | /** | 207 | /** |
216 | * Context information to be used if the second peer is local | 208 | * Context information to be used if the second peer is local |
217 | */ | 209 | */ |
@@ -221,7 +213,6 @@ struct OverlayConnectContext | |||
221 | * Context information to be used if the second peer is remote | 213 | * Context information to be used if the second peer is remote |
222 | */ | 214 | */ |
223 | struct RemotePeer2Context remote; | 215 | struct RemotePeer2Context remote; |
224 | |||
225 | } p2ctx; | 216 | } p2ctx; |
226 | 217 | ||
227 | /** | 218 | /** |
@@ -274,8 +265,7 @@ struct OverlayConnectContext | |||
274 | * peer A to make peer B connect to peer A by sending the controller of peer B | 265 | * peer A to make peer B connect to peer A by sending the controller of peer B |
275 | * the HELLO of peer A. | 266 | * the HELLO of peer A. |
276 | */ | 267 | */ |
277 | struct RemoteOverlayConnectCtx | 268 | struct RemoteOverlayConnectCtx { |
278 | { | ||
279 | /** | 269 | /** |
280 | * the next pointer for DLL | 270 | * the next pointer for DLL |
281 | */ | 271 | */ |
@@ -356,15 +346,15 @@ static struct RemoteOverlayConnectCtx *roccq_tail; | |||
356 | * @param focc the ForwardedOverlayConnectContext to cleanup | 346 | * @param focc the ForwardedOverlayConnectContext to cleanup |
357 | */ | 347 | */ |
358 | void | 348 | void |
359 | GST_cleanup_focc (struct ForwardedOverlayConnectContext *focc) | 349 | GST_cleanup_focc(struct ForwardedOverlayConnectContext *focc) |
360 | { | 350 | { |
361 | struct RegisteredHostContext *rhc = focc->rhc; | 351 | struct RegisteredHostContext *rhc = focc->rhc; |
362 | 352 | ||
363 | GNUNET_CONTAINER_DLL_remove (rhc->focc_dll_head, | 353 | GNUNET_CONTAINER_DLL_remove(rhc->focc_dll_head, |
364 | rhc->focc_dll_tail, | 354 | rhc->focc_dll_tail, |
365 | focc); | 355 | focc); |
366 | GNUNET_free_non_null (focc->orig_msg); | 356 | GNUNET_free_non_null(focc->orig_msg); |
367 | GNUNET_free (focc); | 357 | GNUNET_free(focc); |
368 | } | 358 | } |
369 | 359 | ||
370 | 360 | ||
@@ -374,7 +364,7 @@ GST_cleanup_focc (struct ForwardedOverlayConnectContext *focc) | |||
374 | * @param cls the `struct ForwardedOperationContext` | 364 | * @param cls the `struct ForwardedOperationContext` |
375 | */ | 365 | */ |
376 | static void | 366 | static void |
377 | forwarded_overlay_connect_timeout (void *cls) | 367 | forwarded_overlay_connect_timeout(void *cls) |
378 | { | 368 | { |
379 | struct ForwardedOperationContext *fopc = cls; | 369 | struct ForwardedOperationContext *fopc = cls; |
380 | struct RegisteredHostContext *rhc; | 370 | struct RegisteredHostContext *rhc; |
@@ -383,13 +373,13 @@ forwarded_overlay_connect_timeout (void *cls) | |||
383 | fopc->timeout_task = NULL; | 373 | fopc->timeout_task = NULL; |
384 | rhc = fopc->cls; | 374 | rhc = fopc->cls; |
385 | focc = rhc->focc_dll_head; | 375 | focc = rhc->focc_dll_head; |
386 | LOG_DEBUG ("Overlay linking between peers %u and %u failed\n", | 376 | LOG_DEBUG("Overlay linking between peers %u and %u failed\n", |
387 | focc->peer1, | 377 | focc->peer1, |
388 | focc->peer2); | 378 | focc->peer2); |
389 | GST_cleanup_focc (focc); | 379 | GST_cleanup_focc(focc); |
390 | GST_forwarded_operation_timeout (fopc); | 380 | GST_forwarded_operation_timeout(fopc); |
391 | if (NULL != rhc->focc_dll_head) | 381 | if (NULL != rhc->focc_dll_head) |
392 | GST_process_next_focc (rhc); | 382 | GST_process_next_focc(rhc); |
393 | } | 383 | } |
394 | 384 | ||
395 | 385 | ||
@@ -402,19 +392,19 @@ forwarded_overlay_connect_timeout (void *cls) | |||
402 | * @param msg the peer create success message | 392 | * @param msg the peer create success message |
403 | */ | 393 | */ |
404 | static void | 394 | static void |
405 | forwarded_overlay_connect_listener (void *cls, | 395 | forwarded_overlay_connect_listener(void *cls, |
406 | const struct GNUNET_MessageHeader *msg) | 396 | const struct GNUNET_MessageHeader *msg) |
407 | { | 397 | { |
408 | struct ForwardedOperationContext *fopc = cls; | 398 | struct ForwardedOperationContext *fopc = cls; |
409 | struct RegisteredHostContext *rhc; | 399 | struct RegisteredHostContext *rhc; |
410 | struct ForwardedOverlayConnectContext *focc; | 400 | struct ForwardedOverlayConnectContext *focc; |
411 | 401 | ||
412 | rhc = fopc->cls; | 402 | rhc = fopc->cls; |
413 | GST_forwarded_operation_reply_relay (cls, msg); | 403 | GST_forwarded_operation_reply_relay(cls, msg); |
414 | focc = rhc->focc_dll_head; | 404 | focc = rhc->focc_dll_head; |
415 | GST_cleanup_focc (focc); | 405 | GST_cleanup_focc(focc); |
416 | if (NULL != rhc->focc_dll_head) | 406 | if (NULL != rhc->focc_dll_head) |
417 | GST_process_next_focc (rhc); | 407 | GST_process_next_focc(rhc); |
418 | } | 408 | } |
419 | 409 | ||
420 | 410 | ||
@@ -424,7 +414,7 @@ forwarded_overlay_connect_listener (void *cls, | |||
424 | * @param rhc the RegisteredHostContext | 414 | * @param rhc the RegisteredHostContext |
425 | */ | 415 | */ |
426 | void | 416 | void |
427 | GST_process_next_focc (struct RegisteredHostContext *rhc) | 417 | GST_process_next_focc(struct RegisteredHostContext *rhc) |
428 | { | 418 | { |
429 | struct ForwardedOperationContext *fopc; | 419 | struct ForwardedOperationContext *fopc; |
430 | struct ForwardedOverlayConnectContext *focc; | 420 | struct ForwardedOverlayConnectContext *focc; |
@@ -432,31 +422,31 @@ GST_process_next_focc (struct RegisteredHostContext *rhc) | |||
432 | struct Slave *slave; | 422 | struct Slave *slave; |
433 | 423 | ||
434 | focc = rhc->focc_dll_head; | 424 | focc = rhc->focc_dll_head; |
435 | GNUNET_assert (NULL != focc); | 425 | GNUNET_assert(NULL != focc); |
436 | GNUNET_assert (RHC_DONE == rhc->state); | 426 | GNUNET_assert(RHC_DONE == rhc->state); |
437 | GNUNET_assert (VALID_PEER_ID (focc->peer1)); | 427 | GNUNET_assert(VALID_PEER_ID(focc->peer1)); |
438 | peer = GST_peer_list[focc->peer1]; | 428 | peer = GST_peer_list[focc->peer1]; |
439 | GNUNET_assert (GNUNET_YES == peer->is_remote); | 429 | GNUNET_assert(GNUNET_YES == peer->is_remote); |
440 | GNUNET_assert (NULL != (slave = peer->details.remote.slave)); | 430 | GNUNET_assert(NULL != (slave = peer->details.remote.slave)); |
441 | fopc = GNUNET_new (struct ForwardedOperationContext); | 431 | fopc = GNUNET_new(struct ForwardedOperationContext); |
442 | fopc->client = focc->client; | 432 | fopc->client = focc->client; |
443 | fopc->operation_id = focc->operation_id; | 433 | fopc->operation_id = focc->operation_id; |
444 | fopc->cls = rhc; | 434 | fopc->cls = rhc; |
445 | fopc->type = OP_OVERLAY_CONNECT; | 435 | fopc->type = OP_OVERLAY_CONNECT; |
446 | fopc->opc = | 436 | fopc->opc = |
447 | GNUNET_TESTBED_forward_operation_msg_ (slave->controller, | 437 | GNUNET_TESTBED_forward_operation_msg_(slave->controller, |
448 | focc->operation_id, | 438 | focc->operation_id, |
449 | focc->orig_msg, | 439 | focc->orig_msg, |
450 | &forwarded_overlay_connect_listener, | 440 | &forwarded_overlay_connect_listener, |
451 | fopc); | 441 | fopc); |
452 | GNUNET_free (focc->orig_msg); | 442 | GNUNET_free(focc->orig_msg); |
453 | focc->orig_msg = NULL; | 443 | focc->orig_msg = NULL; |
454 | fopc->timeout_task = GNUNET_SCHEDULER_add_delayed (GST_timeout, | 444 | fopc->timeout_task = GNUNET_SCHEDULER_add_delayed(GST_timeout, |
455 | &forwarded_overlay_connect_timeout, | 445 | &forwarded_overlay_connect_timeout, |
456 | fopc); | 446 | fopc); |
457 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 447 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
458 | fopcq_tail, | 448 | fopcq_tail, |
459 | fopc); | 449 | fopc); |
460 | } | 450 | } |
461 | 451 | ||
462 | 452 | ||
@@ -466,28 +456,28 @@ GST_process_next_focc (struct RegisteredHostContext *rhc) | |||
466 | * @param lp2c the local peer2 context information | 456 | * @param lp2c the local peer2 context information |
467 | */ | 457 | */ |
468 | static void | 458 | static void |
469 | cleanup_occ_lp2c (struct LocalPeer2Context *lp2c) | 459 | cleanup_occ_lp2c(struct LocalPeer2Context *lp2c) |
470 | { | 460 | { |
471 | if (NULL != lp2c->ohh) | 461 | if (NULL != lp2c->ohh) |
472 | { | 462 | { |
473 | GNUNET_TRANSPORT_offer_hello_cancel (lp2c->ohh); | 463 | GNUNET_TRANSPORT_offer_hello_cancel(lp2c->ohh); |
474 | lp2c->ohh = NULL; | 464 | lp2c->ohh = NULL; |
475 | } | 465 | } |
476 | if (NULL != lp2c->tcc.cgh_p2_th) | 466 | if (NULL != lp2c->tcc.cgh_p2_th) |
477 | { | 467 | { |
478 | GST_connection_pool_get_handle_done (lp2c->tcc.cgh_p2_th); | 468 | GST_connection_pool_get_handle_done(lp2c->tcc.cgh_p2_th); |
479 | lp2c->tcc.cgh_p2_th = NULL; | 469 | lp2c->tcc.cgh_p2_th = NULL; |
480 | } | 470 | } |
481 | if (NULL != lp2c->tcc.cgh_p2_ats) | 471 | if (NULL != lp2c->tcc.cgh_p2_ats) |
482 | { | 472 | { |
483 | GST_connection_pool_get_handle_done (lp2c->tcc.cgh_p2_ats); | 473 | GST_connection_pool_get_handle_done(lp2c->tcc.cgh_p2_ats); |
484 | lp2c->tcc.cgh_p2_ats = NULL; | 474 | lp2c->tcc.cgh_p2_ats = NULL; |
485 | } | 475 | } |
486 | if (NULL != lp2c->tcc.csh) | 476 | if (NULL != lp2c->tcc.csh) |
487 | { | 477 | { |
488 | GNUNET_ATS_connectivity_suggest_cancel (lp2c->tcc.csh); | 478 | GNUNET_ATS_connectivity_suggest_cancel(lp2c->tcc.csh); |
489 | lp2c->tcc.csh = NULL; | 479 | lp2c->tcc.csh = NULL; |
490 | } | 480 | } |
491 | } | 481 | } |
492 | 482 | ||
493 | 483 | ||
@@ -498,23 +488,23 @@ cleanup_occ_lp2c (struct LocalPeer2Context *lp2c) | |||
498 | * @param rp2c the remote peer2 context information | 488 | * @param rp2c the remote peer2 context information |
499 | */ | 489 | */ |
500 | static void | 490 | static void |
501 | cleanup_occ_rp2c (struct RemotePeer2Context *rp2c) | 491 | cleanup_occ_rp2c(struct RemotePeer2Context *rp2c) |
502 | { | 492 | { |
503 | if (NULL != rp2c->opc) | 493 | if (NULL != rp2c->opc) |
504 | { | 494 | { |
505 | GNUNET_TESTBED_forward_operation_msg_cancel_ (rp2c->opc); | 495 | GNUNET_TESTBED_forward_operation_msg_cancel_(rp2c->opc); |
506 | rp2c->opc = NULL; | 496 | rp2c->opc = NULL; |
507 | } | 497 | } |
508 | if (NULL != rp2c->ncn) | 498 | if (NULL != rp2c->ncn) |
509 | { | 499 | { |
510 | GST_neighbour_get_connection_cancel (rp2c->ncn); | 500 | GST_neighbour_get_connection_cancel(rp2c->ncn); |
511 | rp2c->ncn = NULL; | 501 | rp2c->ncn = NULL; |
512 | } | 502 | } |
513 | if ( (NULL != rp2c->p2c) && (NULL != rp2c->p2n) ) | 503 | if ((NULL != rp2c->p2c) && (NULL != rp2c->p2n)) |
514 | { | 504 | { |
515 | GST_neighbour_release_connection (rp2c->p2n); | 505 | GST_neighbour_release_connection(rp2c->p2n); |
516 | rp2c->p2n = NULL; | 506 | rp2c->p2n = NULL; |
517 | } | 507 | } |
518 | } | 508 | } |
519 | 509 | ||
520 | /** | 510 | /** |
@@ -523,7 +513,7 @@ cleanup_occ_rp2c (struct RemotePeer2Context *rp2c) | |||
523 | * @param peer the peer to check | 513 | * @param peer the peer to check |
524 | */ | 514 | */ |
525 | #define PEER_EXPIRED(peer) \ | 515 | #define PEER_EXPIRED(peer) \ |
526 | ( (GNUNET_YES == peer->destroy_flag) && (0 == peer->reference_cnt) ) | 516 | ((GNUNET_YES == peer->destroy_flag) && (0 == peer->reference_cnt)) |
527 | 517 | ||
528 | /** | 518 | /** |
529 | * Cleanup overlay connect context structure | 519 | * Cleanup overlay connect context structure |
@@ -531,49 +521,50 @@ cleanup_occ_rp2c (struct RemotePeer2Context *rp2c) | |||
531 | * @param occ the overlay connect context | 521 | * @param occ the overlay connect context |
532 | */ | 522 | */ |
533 | static void | 523 | static void |
534 | cleanup_occ (struct OverlayConnectContext *occ) | 524 | cleanup_occ(struct OverlayConnectContext *occ) |
535 | { | 525 | { |
536 | struct Peer *peer2; | 526 | struct Peer *peer2; |
537 | 527 | ||
538 | LOG_DEBUG ("0x%llx: Cleaning up occ\n", | 528 | LOG_DEBUG("0x%llx: Cleaning up occ\n", |
539 | occ->op_id); | 529 | occ->op_id); |
540 | GNUNET_free_non_null (occ->emsg); | 530 | GNUNET_free_non_null(occ->emsg); |
541 | GNUNET_free_non_null (occ->hello); | 531 | GNUNET_free_non_null(occ->hello); |
542 | if (NULL != occ->send_hello_task) | 532 | if (NULL != occ->send_hello_task) |
543 | GNUNET_SCHEDULER_cancel (occ->send_hello_task); | 533 | GNUNET_SCHEDULER_cancel(occ->send_hello_task); |
544 | if (NULL != occ->cleanup_task) | 534 | if (NULL != occ->cleanup_task) |
545 | GNUNET_SCHEDULER_cancel (occ->cleanup_task); | 535 | GNUNET_SCHEDULER_cancel(occ->cleanup_task); |
546 | if (NULL != occ->timeout_task) | 536 | if (NULL != occ->timeout_task) |
547 | GNUNET_SCHEDULER_cancel (occ->timeout_task); | 537 | GNUNET_SCHEDULER_cancel(occ->timeout_task); |
548 | if (NULL != occ->cgh_ch) | 538 | if (NULL != occ->cgh_ch) |
549 | GST_connection_pool_get_handle_done (occ->cgh_ch); | 539 | GST_connection_pool_get_handle_done(occ->cgh_ch); |
550 | if (NULL != occ->ghh) | 540 | if (NULL != occ->ghh) |
551 | GNUNET_TRANSPORT_hello_get_cancel (occ->ghh); | 541 | GNUNET_TRANSPORT_hello_get_cancel(occ->ghh); |
552 | GST_connection_pool_get_handle_done (occ->cgh_p1th); | 542 | GST_connection_pool_get_handle_done(occ->cgh_p1th); |
553 | GNUNET_assert (NULL != GST_peer_list); | 543 | GNUNET_assert(NULL != GST_peer_list); |
554 | GNUNET_assert (occ->peer->reference_cnt > 0); | 544 | GNUNET_assert(occ->peer->reference_cnt > 0); |
555 | occ->peer->reference_cnt--; | 545 | occ->peer->reference_cnt--; |
556 | if (PEER_EXPIRED (occ->peer)) | 546 | if (PEER_EXPIRED(occ->peer)) |
557 | GST_destroy_peer (occ->peer); | 547 | GST_destroy_peer(occ->peer); |
558 | switch (occ->type) | 548 | switch (occ->type) |
559 | { | 549 | { |
560 | case OCC_TYPE_LOCAL: | 550 | case OCC_TYPE_LOCAL: |
561 | peer2 = GST_peer_list[occ->other_peer_id]; | 551 | peer2 = GST_peer_list[occ->other_peer_id]; |
562 | GNUNET_assert (peer2->reference_cnt > 0); | 552 | GNUNET_assert(peer2->reference_cnt > 0); |
563 | peer2->reference_cnt--; | 553 | peer2->reference_cnt--; |
564 | if (PEER_EXPIRED (peer2)) | 554 | if (PEER_EXPIRED(peer2)) |
565 | GST_destroy_peer (peer2); | 555 | GST_destroy_peer(peer2); |
566 | cleanup_occ_lp2c (&occ->p2ctx.local); | 556 | cleanup_occ_lp2c(&occ->p2ctx.local); |
567 | break; | 557 | break; |
568 | case OCC_TYPE_REMOTE_SLAVE: | 558 | |
569 | case OCC_TYPE_REMOTE_LATERAL: | 559 | case OCC_TYPE_REMOTE_SLAVE: |
570 | cleanup_occ_rp2c (&occ->p2ctx.remote); | 560 | case OCC_TYPE_REMOTE_LATERAL: |
571 | break; | 561 | cleanup_occ_rp2c(&occ->p2ctx.remote); |
572 | } | 562 | break; |
573 | GNUNET_CONTAINER_DLL_remove (occq_head, | 563 | } |
574 | occq_tail, | 564 | GNUNET_CONTAINER_DLL_remove(occq_head, |
575 | occ); | 565 | occq_tail, |
576 | GNUNET_free (occ); | 566 | occ); |
567 | GNUNET_free(occ); | ||
577 | } | 568 | } |
578 | 569 | ||
579 | 570 | ||
@@ -583,12 +574,12 @@ cleanup_occ (struct OverlayConnectContext *occ) | |||
583 | * @param cls the overlay connect context | 574 | * @param cls the overlay connect context |
584 | */ | 575 | */ |
585 | static void | 576 | static void |
586 | do_cleanup_occ (void *cls) | 577 | do_cleanup_occ(void *cls) |
587 | { | 578 | { |
588 | struct OverlayConnectContext *occ = cls; | 579 | struct OverlayConnectContext *occ = cls; |
589 | 580 | ||
590 | occ->cleanup_task = NULL; | 581 | occ->cleanup_task = NULL; |
591 | cleanup_occ (occ); | 582 | cleanup_occ(occ); |
592 | } | 583 | } |
593 | 584 | ||
594 | 585 | ||
@@ -598,19 +589,19 @@ do_cleanup_occ (void *cls) | |||
598 | * @param cls the OverlayConnectContext | 589 | * @param cls the OverlayConnectContext |
599 | */ | 590 | */ |
600 | static void | 591 | static void |
601 | timeout_overlay_connect (void *cls) | 592 | timeout_overlay_connect(void *cls) |
602 | { | 593 | { |
603 | struct OverlayConnectContext *occ = cls; | 594 | struct OverlayConnectContext *occ = cls; |
604 | 595 | ||
605 | GNUNET_assert (NULL != occ->timeout_task); | 596 | GNUNET_assert(NULL != occ->timeout_task); |
606 | occ->timeout_task = NULL; | 597 | occ->timeout_task = NULL; |
607 | /* LOG (GNUNET_ERROR_TYPE_WARNING, */ | 598 | /* LOG (GNUNET_ERROR_TYPE_WARNING, */ |
608 | /* "0x%llx: Timeout while connecting peers %u and %u: %s\n", occ->op_id, */ | 599 | /* "0x%llx: Timeout while connecting peers %u and %u: %s\n", occ->op_id, */ |
609 | /* occ->peer->id, occ->other_peer_id, occ->emsg); */ | 600 | /* occ->peer->id, occ->other_peer_id, occ->emsg); */ |
610 | GST_send_operation_fail_msg (occ->client, | 601 | GST_send_operation_fail_msg(occ->client, |
611 | occ->op_id, | 602 | occ->op_id, |
612 | occ->emsg); | 603 | occ->emsg); |
613 | cleanup_occ (occ); | 604 | cleanup_occ(occ); |
614 | } | 605 | } |
615 | 606 | ||
616 | 607 | ||
@@ -620,7 +611,7 @@ timeout_overlay_connect (void *cls) | |||
620 | * @param client the client that disconnected | 611 | * @param client the client that disconnected |
621 | */ | 612 | */ |
622 | void | 613 | void |
623 | GST_notify_client_disconnect_oc (struct GNUNET_SERVICE_Client *client) | 614 | GST_notify_client_disconnect_oc(struct GNUNET_SERVICE_Client *client) |
624 | { | 615 | { |
625 | struct ForwardedOperationContext *fopc; | 616 | struct ForwardedOperationContext *fopc; |
626 | struct ForwardedOperationContext *fopcn; | 617 | struct ForwardedOperationContext *fopcn; |
@@ -628,20 +619,20 @@ GST_notify_client_disconnect_oc (struct GNUNET_SERVICE_Client *client) | |||
628 | struct OverlayConnectContext *occn; | 619 | struct OverlayConnectContext *occn; |
629 | 620 | ||
630 | for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) | 621 | for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) |
631 | { | ||
632 | fopcn = fopc->next; | ||
633 | if (fopc->client == client) | ||
634 | { | 622 | { |
635 | GNUNET_SCHEDULER_cancel (fopc->timeout_task); | 623 | fopcn = fopc->next; |
636 | GST_forwarded_operation_timeout (fopc); | 624 | if (fopc->client == client) |
625 | { | ||
626 | GNUNET_SCHEDULER_cancel(fopc->timeout_task); | ||
627 | GST_forwarded_operation_timeout(fopc); | ||
628 | } | ||
637 | } | 629 | } |
638 | } | ||
639 | for (occ = occq_head; NULL != occ; occ = occn) | 630 | for (occ = occq_head; NULL != occ; occ = occn) |
640 | { | 631 | { |
641 | occn = occ->next; | 632 | occn = occ->next; |
642 | if (occ->client == client) | 633 | if (occ->client == client) |
643 | cleanup_occ (occ); | 634 | cleanup_occ(occ); |
644 | } | 635 | } |
645 | // FIXME: implement clean up for client_keep replacements! | 636 | // FIXME: implement clean up for client_keep replacements! |
646 | } | 637 | } |
647 | 638 | ||
@@ -652,21 +643,21 @@ GST_notify_client_disconnect_oc (struct GNUNET_SERVICE_Client *client) | |||
652 | * FIXME. | 643 | * FIXME. |
653 | */ | 644 | */ |
654 | static void | 645 | static void |
655 | send_overlay_connect_success_msg (struct OverlayConnectContext *occ) | 646 | send_overlay_connect_success_msg(struct OverlayConnectContext *occ) |
656 | { | 647 | { |
657 | struct GNUNET_MQ_Envelope *env; | 648 | struct GNUNET_MQ_Envelope *env; |
658 | struct GNUNET_TESTBED_ConnectionEventMessage *msg; | 649 | struct GNUNET_TESTBED_ConnectionEventMessage *msg; |
659 | 650 | ||
660 | LOG_DEBUG ("0x%llx: Peers connected - Sending overlay connect success\n", | 651 | LOG_DEBUG("0x%llx: Peers connected - Sending overlay connect success\n", |
661 | occ->op_id); | 652 | occ->op_id); |
662 | env = GNUNET_MQ_msg (msg, | 653 | env = GNUNET_MQ_msg(msg, |
663 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT); | 654 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT); |
664 | msg->event_type = htonl (GNUNET_TESTBED_ET_CONNECT); | 655 | msg->event_type = htonl(GNUNET_TESTBED_ET_CONNECT); |
665 | msg->peer1 = htonl (occ->peer->id); | 656 | msg->peer1 = htonl(occ->peer->id); |
666 | msg->peer2 = htonl (occ->other_peer_id); | 657 | msg->peer2 = htonl(occ->other_peer_id); |
667 | msg->operation_id = GNUNET_htonll (occ->op_id); | 658 | msg->operation_id = GNUNET_htonll(occ->op_id); |
668 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (occ->client), | 659 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(occ->client), |
669 | env); | 660 | env); |
670 | } | 661 | } |
671 | 662 | ||
672 | 663 | ||
@@ -678,61 +669,62 @@ send_overlay_connect_success_msg (struct OverlayConnectContext *occ) | |||
678 | * @param new_peer the peer that connected | 669 | * @param new_peer the peer that connected |
679 | */ | 670 | */ |
680 | static void | 671 | static void |
681 | overlay_connect_notify (void *cls, | 672 | overlay_connect_notify(void *cls, |
682 | const struct GNUNET_PeerIdentity *new_peer) | 673 | const struct GNUNET_PeerIdentity *new_peer) |
683 | { | 674 | { |
684 | struct OverlayConnectContext *occ = cls; | 675 | struct OverlayConnectContext *occ = cls; |
685 | char *new_peer_str; | 676 | char *new_peer_str; |
686 | char *other_peer_str; | 677 | char *other_peer_str; |
687 | 678 | ||
688 | LOG_DEBUG ("Overlay connect notify\n"); | 679 | LOG_DEBUG("Overlay connect notify\n"); |
689 | if (0 == | 680 | if (0 == |
690 | memcmp (new_peer, &occ->peer_identity, | 681 | memcmp(new_peer, &occ->peer_identity, |
691 | sizeof (struct GNUNET_PeerIdentity))) | 682 | sizeof(struct GNUNET_PeerIdentity))) |
692 | return; | 683 | return; |
693 | new_peer_str = GNUNET_strdup (GNUNET_i2s (new_peer)); | 684 | new_peer_str = GNUNET_strdup(GNUNET_i2s(new_peer)); |
694 | other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity)); | 685 | other_peer_str = GNUNET_strdup(GNUNET_i2s(&occ->other_peer_identity)); |
695 | if (0 != | 686 | if (0 != |
696 | memcmp (new_peer, | 687 | memcmp(new_peer, |
697 | &occ->other_peer_identity, | 688 | &occ->other_peer_identity, |
698 | sizeof (struct GNUNET_PeerIdentity))) | 689 | sizeof(struct GNUNET_PeerIdentity))) |
699 | { | 690 | { |
700 | LOG_DEBUG ("Unexpected peer %s connected when expecting peer %s\n", | 691 | LOG_DEBUG("Unexpected peer %s connected when expecting peer %s\n", |
701 | new_peer_str, | 692 | new_peer_str, |
702 | other_peer_str); | 693 | other_peer_str); |
703 | GNUNET_free (new_peer_str); | 694 | GNUNET_free(new_peer_str); |
704 | GNUNET_free (other_peer_str); | 695 | GNUNET_free(other_peer_str); |
705 | return; | 696 | return; |
706 | } | 697 | } |
707 | GNUNET_free (new_peer_str); | 698 | GNUNET_free(new_peer_str); |
708 | LOG_DEBUG ("0x%llx: Peer %s connected to peer %s\n", | 699 | LOG_DEBUG("0x%llx: Peer %s connected to peer %s\n", |
709 | occ->op_id, | 700 | occ->op_id, |
710 | other_peer_str, | 701 | other_peer_str, |
711 | GNUNET_i2s (&occ->peer_identity)); | 702 | GNUNET_i2s(&occ->peer_identity)); |
712 | GNUNET_free (other_peer_str); | 703 | GNUNET_free(other_peer_str); |
713 | if (NULL != occ->send_hello_task) | 704 | if (NULL != occ->send_hello_task) |
714 | { | 705 | { |
715 | GNUNET_SCHEDULER_cancel (occ->send_hello_task); | 706 | GNUNET_SCHEDULER_cancel(occ->send_hello_task); |
716 | occ->send_hello_task = NULL; | 707 | occ->send_hello_task = NULL; |
717 | } | 708 | } |
718 | GNUNET_assert (NULL != occ->timeout_task); | 709 | GNUNET_assert(NULL != occ->timeout_task); |
719 | GNUNET_SCHEDULER_cancel (occ->timeout_task); | 710 | GNUNET_SCHEDULER_cancel(occ->timeout_task); |
720 | occ->timeout_task = NULL; | 711 | occ->timeout_task = NULL; |
721 | switch (occ->type) | 712 | switch (occ->type) |
722 | { | 713 | { |
723 | case OCC_TYPE_LOCAL: | 714 | case OCC_TYPE_LOCAL: |
724 | cleanup_occ_lp2c (&occ->p2ctx.local); | 715 | cleanup_occ_lp2c(&occ->p2ctx.local); |
725 | break; | 716 | break; |
726 | case OCC_TYPE_REMOTE_SLAVE: | 717 | |
727 | case OCC_TYPE_REMOTE_LATERAL: | 718 | case OCC_TYPE_REMOTE_SLAVE: |
728 | cleanup_occ_rp2c (&occ->p2ctx.remote); | 719 | case OCC_TYPE_REMOTE_LATERAL: |
729 | break; | 720 | cleanup_occ_rp2c(&occ->p2ctx.remote); |
730 | } | 721 | break; |
731 | GNUNET_free_non_null (occ->emsg); | 722 | } |
723 | GNUNET_free_non_null(occ->emsg); | ||
732 | occ->emsg = NULL; | 724 | occ->emsg = NULL; |
733 | send_overlay_connect_success_msg (occ); | 725 | send_overlay_connect_success_msg(occ); |
734 | occ->cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup_occ, | 726 | occ->cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup_occ, |
735 | occ); | 727 | occ); |
736 | } | 728 | } |
737 | 729 | ||
738 | 730 | ||
@@ -747,43 +739,43 @@ overlay_connect_notify (void *cls, | |||
747 | * @param cfg configuration of the peer | 739 | * @param cfg configuration of the peer |
748 | */ | 740 | */ |
749 | static void | 741 | static void |
750 | occ_cache_get_handle_ats_occ_cb (void *cls, | 742 | occ_cache_get_handle_ats_occ_cb(void *cls, |
751 | struct GNUNET_CORE_Handle *ch, | 743 | struct GNUNET_CORE_Handle *ch, |
752 | struct GNUNET_TRANSPORT_CoreHandle *th, | 744 | struct GNUNET_TRANSPORT_CoreHandle *th, |
753 | struct GNUNET_ATS_ConnectivityHandle *ac, | 745 | struct GNUNET_ATS_ConnectivityHandle *ac, |
754 | const struct GNUNET_PeerIdentity *my_identity, | 746 | const struct GNUNET_PeerIdentity *my_identity, |
755 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 747 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
756 | { | 748 | { |
757 | struct OverlayConnectContext *occ = cls; | 749 | struct OverlayConnectContext *occ = cls; |
758 | struct LocalPeer2Context *lp2c; | 750 | struct LocalPeer2Context *lp2c; |
759 | 751 | ||
760 | GNUNET_assert (OCC_TYPE_LOCAL == occ->type); | 752 | GNUNET_assert(OCC_TYPE_LOCAL == occ->type); |
761 | GNUNET_assert (NULL != occ->timeout_task); | 753 | GNUNET_assert(NULL != occ->timeout_task); |
762 | GNUNET_free_non_null (occ->emsg); | 754 | GNUNET_free_non_null(occ->emsg); |
763 | if (NULL == ac) | 755 | if (NULL == ac) |
764 | { | 756 | { |
765 | GNUNET_asprintf (&occ->emsg, | 757 | GNUNET_asprintf(&occ->emsg, |
766 | "0x%llx: Failed to connect to ATS of peer with id: %u", | 758 | "0x%llx: Failed to connect to ATS of peer with id: %u", |
767 | occ->op_id, | 759 | occ->op_id, |
768 | occ->peer->id); | 760 | occ->peer->id); |
769 | GNUNET_SCHEDULER_cancel (occ->timeout_task); | 761 | GNUNET_SCHEDULER_cancel(occ->timeout_task); |
770 | occ->timeout_task = | 762 | occ->timeout_task = |
771 | GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, | 763 | GNUNET_SCHEDULER_add_now(&timeout_overlay_connect, |
772 | occ); | 764 | occ); |
773 | return; | 765 | return; |
774 | } | 766 | } |
775 | occ->emsg = NULL; | 767 | occ->emsg = NULL; |
776 | 768 | ||
777 | GNUNET_asprintf (&occ->emsg, | 769 | GNUNET_asprintf(&occ->emsg, |
778 | "0x%llx: Timeout during GNUNET_ATS_connectivity_suggest() at peer %s", | 770 | "0x%llx: Timeout during GNUNET_ATS_connectivity_suggest() at peer %s", |
779 | occ->op_id, | 771 | occ->op_id, |
780 | GNUNET_i2s (&occ->other_peer_identity)); | 772 | GNUNET_i2s(&occ->other_peer_identity)); |
781 | 773 | ||
782 | lp2c = &occ->p2ctx.local; | 774 | lp2c = &occ->p2ctx.local; |
783 | lp2c->tcc.csh = | 775 | lp2c->tcc.csh = |
784 | GNUNET_ATS_connectivity_suggest (ac, | 776 | GNUNET_ATS_connectivity_suggest(ac, |
785 | &occ->peer_identity, | 777 | &occ->peer_identity, |
786 | 1); | 778 | 1); |
787 | } | 779 | } |
788 | 780 | ||
789 | 781 | ||
@@ -797,19 +789,19 @@ occ_cache_get_handle_ats_occ_cb (void *cls, | |||
797 | * @param my_identity the identity of our peer | 789 | * @param my_identity the identity of our peer |
798 | */ | 790 | */ |
799 | static void | 791 | static void |
800 | occ_cache_get_handle_ats_rocc_cb (void *cls, | 792 | occ_cache_get_handle_ats_rocc_cb(void *cls, |
801 | struct GNUNET_CORE_Handle *ch, | 793 | struct GNUNET_CORE_Handle *ch, |
802 | struct GNUNET_TRANSPORT_CoreHandle *th, | 794 | struct GNUNET_TRANSPORT_CoreHandle *th, |
803 | struct GNUNET_ATS_ConnectivityHandle *ac, | 795 | struct GNUNET_ATS_ConnectivityHandle *ac, |
804 | const struct GNUNET_PeerIdentity *my_identity, | 796 | const struct GNUNET_PeerIdentity *my_identity, |
805 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 797 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
806 | { | 798 | { |
807 | struct RemoteOverlayConnectCtx *rocc = cls; | 799 | struct RemoteOverlayConnectCtx *rocc = cls; |
808 | 800 | ||
809 | rocc->tcc.csh = | 801 | rocc->tcc.csh = |
810 | GNUNET_ATS_connectivity_suggest (ac, | 802 | GNUNET_ATS_connectivity_suggest(ac, |
811 | &rocc->a_id, | 803 | &rocc->a_id, |
812 | 1); | 804 | 1); |
813 | } | 805 | } |
814 | 806 | ||
815 | 807 | ||
@@ -820,7 +812,7 @@ occ_cache_get_handle_ats_rocc_cb (void *cls, | |||
820 | * @param cls the OverlayConnectContext | 812 | * @param cls the OverlayConnectContext |
821 | */ | 813 | */ |
822 | static void | 814 | static void |
823 | send_hello (void *cls); | 815 | send_hello(void *cls); |
824 | 816 | ||
825 | 817 | ||
826 | /** | 818 | /** |
@@ -831,31 +823,31 @@ send_hello (void *cls); | |||
831 | * @param cls the overlay connect context | 823 | * @param cls the overlay connect context |
832 | */ | 824 | */ |
833 | static void | 825 | static void |
834 | occ_hello_sent_cb (void *cls) | 826 | occ_hello_sent_cb(void *cls) |
835 | { | 827 | { |
836 | struct OverlayConnectContext *occ = cls; | 828 | struct OverlayConnectContext *occ = cls; |
837 | struct LocalPeer2Context *lp2c; | 829 | struct LocalPeer2Context *lp2c; |
838 | struct Peer *peer2; | 830 | struct Peer *peer2; |
839 | 831 | ||
840 | GNUNET_assert (OCC_TYPE_LOCAL == occ->type); | 832 | GNUNET_assert(OCC_TYPE_LOCAL == occ->type); |
841 | GNUNET_assert (NULL != occ->timeout_task); | 833 | GNUNET_assert(NULL != occ->timeout_task); |
842 | lp2c = &occ->p2ctx.local; | 834 | lp2c = &occ->p2ctx.local; |
843 | lp2c->ohh = NULL; | 835 | lp2c->ohh = NULL; |
844 | 836 | ||
845 | GNUNET_assert (NULL == occ->send_hello_task); | 837 | GNUNET_assert(NULL == occ->send_hello_task); |
846 | GNUNET_free_non_null (occ->emsg); | 838 | GNUNET_free_non_null(occ->emsg); |
847 | 839 | ||
848 | GNUNET_asprintf (&occ->emsg, | 840 | GNUNET_asprintf(&occ->emsg, |
849 | "0x%llx: Timeout while acquiring ATS of %s from cache", | 841 | "0x%llx: Timeout while acquiring ATS of %s from cache", |
850 | occ->op_id, | 842 | occ->op_id, |
851 | GNUNET_i2s (&occ->other_peer_identity)); | 843 | GNUNET_i2s(&occ->other_peer_identity)); |
852 | GNUNET_assert (NULL != (peer2 = GST_peer_list[occ->other_peer_id])); | 844 | GNUNET_assert(NULL != (peer2 = GST_peer_list[occ->other_peer_id])); |
853 | lp2c->tcc.cgh_p2_ats = | 845 | lp2c->tcc.cgh_p2_ats = |
854 | GST_connection_pool_get_handle (occ->other_peer_id, | 846 | GST_connection_pool_get_handle(occ->other_peer_id, |
855 | peer2->details.local.cfg, | 847 | peer2->details.local.cfg, |
856 | GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY, | 848 | GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY, |
857 | &occ_cache_get_handle_ats_occ_cb, | 849 | &occ_cache_get_handle_ats_occ_cb, |
858 | occ, NULL, NULL, NULL); | 850 | occ, NULL, NULL, NULL); |
859 | } | 851 | } |
860 | 852 | ||
861 | 853 | ||
@@ -867,36 +859,36 @@ occ_hello_sent_cb (void *cls) | |||
867 | * #OCC_TYPE_REMOTE_SLAVE or #OCC_TYPE_REMOTE_LATERAL | 859 | * #OCC_TYPE_REMOTE_SLAVE or #OCC_TYPE_REMOTE_LATERAL |
868 | */ | 860 | */ |
869 | static void | 861 | static void |
870 | send_hello_thru_rocc (struct OverlayConnectContext *occ) | 862 | send_hello_thru_rocc(struct OverlayConnectContext *occ) |
871 | { | 863 | { |
872 | struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg; | 864 | struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg; |
873 | char *other_peer_str; | 865 | char *other_peer_str; |
874 | uint16_t msize; | 866 | uint16_t msize; |
875 | uint16_t hello_size; | 867 | uint16_t hello_size; |
876 | 868 | ||
877 | GNUNET_assert (OCC_TYPE_LOCAL != occ->type); | 869 | GNUNET_assert(OCC_TYPE_LOCAL != occ->type); |
878 | GNUNET_assert (NULL != occ->hello); | 870 | GNUNET_assert(NULL != occ->hello); |
879 | other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity)); | 871 | other_peer_str = GNUNET_strdup(GNUNET_i2s(&occ->other_peer_identity)); |
880 | LOG_DEBUG ("0x%llx: Offering HELLO of %s (size: %u) to %s via Remote Overlay Request\n", | 872 | LOG_DEBUG("0x%llx: Offering HELLO of %s (size: %u) to %s via Remote Overlay Request\n", |
881 | occ->op_id, | 873 | occ->op_id, |
882 | GNUNET_i2s (&occ->peer_identity), | 874 | GNUNET_i2s(&occ->peer_identity), |
883 | ntohs (occ->hello->size), | 875 | ntohs(occ->hello->size), |
884 | other_peer_str); | 876 | other_peer_str); |
885 | GNUNET_free (other_peer_str); | 877 | GNUNET_free(other_peer_str); |
886 | hello_size = ntohs (occ->hello->size); | 878 | hello_size = ntohs(occ->hello->size); |
887 | msize = sizeof (struct GNUNET_TESTBED_RemoteOverlayConnectMessage) + hello_size; | 879 | msize = sizeof(struct GNUNET_TESTBED_RemoteOverlayConnectMessage) + hello_size; |
888 | msg = GNUNET_malloc (msize); | 880 | msg = GNUNET_malloc(msize); |
889 | msg->header.type = | 881 | msg->header.type = |
890 | htons (GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT); | 882 | htons(GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT); |
891 | msg->header.size = htons (msize); | 883 | msg->header.size = htons(msize); |
892 | msg->peer = htonl (occ->other_peer_id); | 884 | msg->peer = htonl(occ->other_peer_id); |
893 | msg->operation_id = GNUNET_htonll (occ->op_id); | 885 | msg->operation_id = GNUNET_htonll(occ->op_id); |
894 | msg->peer_identity = occ->peer_identity; | 886 | msg->peer_identity = occ->peer_identity; |
895 | GNUNET_memcpy (msg->hello, | 887 | GNUNET_memcpy(msg->hello, |
896 | occ->hello, | 888 | occ->hello, |
897 | hello_size); | 889 | hello_size); |
898 | GNUNET_TESTBED_queue_message_ (occ->p2ctx.remote.p2c, | 890 | GNUNET_TESTBED_queue_message_(occ->p2ctx.remote.p2c, |
899 | &msg->header); | 891 | &msg->header); |
900 | } | 892 | } |
901 | 893 | ||
902 | 894 | ||
@@ -908,43 +900,43 @@ send_hello_thru_rocc (struct OverlayConnectContext *occ) | |||
908 | * @param cls the OverlayConnectContext | 900 | * @param cls the OverlayConnectContext |
909 | */ | 901 | */ |
910 | static void | 902 | static void |
911 | send_hello (void *cls) | 903 | send_hello(void *cls) |
912 | { | 904 | { |
913 | struct OverlayConnectContext *occ = cls; | 905 | struct OverlayConnectContext *occ = cls; |
914 | struct LocalPeer2Context *lp2c; | 906 | struct LocalPeer2Context *lp2c; |
915 | char *other_peer_str; | 907 | char *other_peer_str; |
916 | 908 | ||
917 | occ->send_hello_task = NULL; | 909 | occ->send_hello_task = NULL; |
918 | GNUNET_assert (NULL != occ->timeout_task); | 910 | GNUNET_assert(NULL != occ->timeout_task); |
919 | GNUNET_assert (NULL != occ->hello); | 911 | GNUNET_assert(NULL != occ->hello); |
920 | if (OCC_TYPE_LOCAL != occ->type) | 912 | if (OCC_TYPE_LOCAL != occ->type) |
921 | { | 913 | { |
922 | send_hello_thru_rocc (occ); | 914 | send_hello_thru_rocc(occ); |
923 | return; | 915 | return; |
924 | } | 916 | } |
925 | lp2c = &occ->p2ctx.local; | 917 | lp2c = &occ->p2ctx.local; |
926 | other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity)); | 918 | other_peer_str = GNUNET_strdup(GNUNET_i2s(&occ->other_peer_identity)); |
927 | LOG_DEBUG ("0x%llx: Offering HELLO of %s to %s\n", | 919 | LOG_DEBUG("0x%llx: Offering HELLO of %s to %s\n", |
928 | occ->op_id, | 920 | occ->op_id, |
929 | GNUNET_i2s (&occ->peer_identity), | 921 | GNUNET_i2s(&occ->peer_identity), |
930 | other_peer_str); | 922 | other_peer_str); |
931 | GNUNET_free (other_peer_str); | 923 | GNUNET_free(other_peer_str); |
932 | lp2c->ohh = | 924 | lp2c->ohh = |
933 | GNUNET_TRANSPORT_offer_hello (lp2c->tcc.cfg, | 925 | GNUNET_TRANSPORT_offer_hello(lp2c->tcc.cfg, |
934 | occ->hello, | 926 | occ->hello, |
935 | &occ_hello_sent_cb, | 927 | &occ_hello_sent_cb, |
936 | occ); | 928 | occ); |
937 | if (NULL == lp2c->ohh) | 929 | if (NULL == lp2c->ohh) |
938 | { | 930 | { |
939 | GNUNET_break (0); | 931 | GNUNET_break(0); |
940 | occ->send_hello_task = | 932 | occ->send_hello_task = |
941 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 933 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
942 | (GNUNET_TIME_UNIT_MILLISECONDS, | 934 | (GNUNET_TIME_UNIT_MILLISECONDS, |
943 | 100 + | 935 | 100 + |
944 | GNUNET_CRYPTO_random_u32 | 936 | GNUNET_CRYPTO_random_u32 |
945 | (GNUNET_CRYPTO_QUALITY_WEAK, 500)), | 937 | (GNUNET_CRYPTO_QUALITY_WEAK, 500)), |
946 | &send_hello, occ); | 938 | &send_hello, occ); |
947 | } | 939 | } |
948 | } | 940 | } |
949 | 941 | ||
950 | 942 | ||
@@ -957,36 +949,36 @@ send_hello (void *cls) | |||
957 | * @param ac the handle to ATS. Can be NULL if it is not requested | 949 | * @param ac the handle to ATS. Can be NULL if it is not requested |
958 | * @param ignore_ peer identity which is ignored in this callback | 950 | * @param ignore_ peer identity which is ignored in this callback |
959 | * @param cfg configuration of the peer | 951 | * @param cfg configuration of the peer |
960 | */ | 952 | */ |
961 | static void | 953 | static void |
962 | p2_transport_connect_cache_callback (void *cls, | 954 | p2_transport_connect_cache_callback(void *cls, |
963 | struct GNUNET_CORE_Handle *ch, | 955 | struct GNUNET_CORE_Handle *ch, |
964 | struct GNUNET_TRANSPORT_CoreHandle *th, | 956 | struct GNUNET_TRANSPORT_CoreHandle *th, |
965 | struct GNUNET_ATS_ConnectivityHandle *ac, | 957 | struct GNUNET_ATS_ConnectivityHandle *ac, |
966 | const struct GNUNET_PeerIdentity *ignore_, | 958 | const struct GNUNET_PeerIdentity *ignore_, |
967 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 959 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
968 | { | 960 | { |
969 | struct OverlayConnectContext *occ = cls; | 961 | struct OverlayConnectContext *occ = cls; |
970 | 962 | ||
971 | GNUNET_assert (OCC_TYPE_LOCAL == occ->type); | 963 | GNUNET_assert(OCC_TYPE_LOCAL == occ->type); |
972 | if (NULL == th) | 964 | if (NULL == th) |
973 | { | 965 | { |
974 | GNUNET_asprintf (&occ->emsg, | 966 | GNUNET_asprintf(&occ->emsg, |
975 | "0x%llx: Cannot connect to TRANSPORT of %s", | 967 | "0x%llx: Cannot connect to TRANSPORT of %s", |
976 | occ->op_id, | 968 | occ->op_id, |
977 | GNUNET_i2s (&occ->other_peer_identity)); | 969 | GNUNET_i2s(&occ->other_peer_identity)); |
978 | GNUNET_SCHEDULER_cancel (occ->timeout_task); | 970 | GNUNET_SCHEDULER_cancel(occ->timeout_task); |
979 | occ->timeout_task = | 971 | occ->timeout_task = |
980 | GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); | 972 | GNUNET_SCHEDULER_add_now(&timeout_overlay_connect, occ); |
981 | return; | 973 | return; |
982 | } | 974 | } |
983 | occ->p2ctx.local.tcc.th_ = th; | 975 | occ->p2ctx.local.tcc.th_ = th; |
984 | occ->p2ctx.local.tcc.cfg = cfg; | 976 | occ->p2ctx.local.tcc.cfg = cfg; |
985 | GNUNET_asprintf (&occ->emsg, | 977 | GNUNET_asprintf(&occ->emsg, |
986 | "0x%llx: Timeout while offering HELLO to %s", | 978 | "0x%llx: Timeout while offering HELLO to %s", |
987 | occ->op_id, | 979 | occ->op_id, |
988 | GNUNET_i2s (&occ->other_peer_identity)); | 980 | GNUNET_i2s(&occ->other_peer_identity)); |
989 | occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ); | 981 | occ->send_hello_task = GNUNET_SCHEDULER_add_now(&send_hello, occ); |
990 | } | 982 | } |
991 | 983 | ||
992 | 984 | ||
@@ -997,36 +989,36 @@ p2_transport_connect_cache_callback (void *cls, | |||
997 | * @param occ the overlay connect context | 989 | * @param occ the overlay connect context |
998 | */ | 990 | */ |
999 | static void | 991 | static void |
1000 | p2_transport_connect (struct OverlayConnectContext *occ) | 992 | p2_transport_connect(struct OverlayConnectContext *occ) |
1001 | { | 993 | { |
1002 | struct Peer *peer2; | 994 | struct Peer *peer2; |
1003 | 995 | ||
1004 | /* HUH? Why to *obtain* HELLO? Seems we use this to *SEND* the | 996 | /* HUH? Why to *obtain* HELLO? Seems we use this to *SEND* the |
1005 | HELLO! */ | 997 | HELLO! */ |
1006 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 998 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1007 | "Connecting to transport of peer %s to obtain HELLO\n", | 999 | "Connecting to transport of peer %s to obtain HELLO\n", |
1008 | GNUNET_i2s (&occ->other_peer_identity)); | 1000 | GNUNET_i2s(&occ->other_peer_identity)); |
1009 | GNUNET_assert (NULL == occ->emsg); | 1001 | GNUNET_assert(NULL == occ->emsg); |
1010 | GNUNET_assert (NULL != occ->hello); | 1002 | GNUNET_assert(NULL != occ->hello); |
1011 | GNUNET_assert (NULL == occ->ghh); | 1003 | GNUNET_assert(NULL == occ->ghh); |
1012 | GNUNET_assert (NULL == occ->p1th_); | 1004 | GNUNET_assert(NULL == occ->p1th_); |
1013 | GNUNET_assert (NULL == occ->cgh_p1th); | 1005 | GNUNET_assert(NULL == occ->cgh_p1th); |
1014 | if (OCC_TYPE_LOCAL == occ->type) | 1006 | if (OCC_TYPE_LOCAL == occ->type) |
1015 | { | 1007 | { |
1016 | GNUNET_assert (NULL != (peer2 = GST_peer_list[occ->other_peer_id])); | 1008 | GNUNET_assert(NULL != (peer2 = GST_peer_list[occ->other_peer_id])); |
1017 | occ->p2ctx.local.tcc.cgh_p2_th = | 1009 | occ->p2ctx.local.tcc.cgh_p2_th = |
1018 | GST_connection_pool_get_handle (occ->other_peer_id, | 1010 | GST_connection_pool_get_handle(occ->other_peer_id, |
1019 | peer2->details.local.cfg, | 1011 | peer2->details.local.cfg, |
1020 | GST_CONNECTIONPOOL_SERVICE_TRANSPORT, | 1012 | GST_CONNECTIONPOOL_SERVICE_TRANSPORT, |
1021 | &p2_transport_connect_cache_callback, | 1013 | &p2_transport_connect_cache_callback, |
1022 | occ, NULL, NULL, NULL); | 1014 | occ, NULL, NULL, NULL); |
1023 | return; | 1015 | return; |
1024 | } | 1016 | } |
1025 | GNUNET_asprintf (&occ->emsg, | 1017 | GNUNET_asprintf(&occ->emsg, |
1026 | "0x%llx: Timeout while offering HELLO to %s", | 1018 | "0x%llx: Timeout while offering HELLO to %s", |
1027 | occ->op_id, | 1019 | occ->op_id, |
1028 | GNUNET_i2s (&occ->other_peer_identity)); | 1020 | GNUNET_i2s(&occ->other_peer_identity)); |
1029 | occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ); | 1021 | occ->send_hello_task = GNUNET_SCHEDULER_add_now(&send_hello, occ); |
1030 | } | 1022 | } |
1031 | 1023 | ||
1032 | 1024 | ||
@@ -1039,9 +1031,9 @@ p2_transport_connect (struct OverlayConnectContext *occ) | |||
1039 | * @return #GNUNET_OK | 1031 | * @return #GNUNET_OK |
1040 | */ | 1032 | */ |
1041 | static int | 1033 | static int |
1042 | test_address (void *cls, | 1034 | test_address(void *cls, |
1043 | const struct GNUNET_HELLO_Address *address, | 1035 | const struct GNUNET_HELLO_Address *address, |
1044 | struct GNUNET_TIME_Absolute expiration) | 1036 | struct GNUNET_TIME_Absolute expiration) |
1045 | { | 1037 | { |
1046 | int *empty = cls; | 1038 | int *empty = cls; |
1047 | 1039 | ||
@@ -1059,40 +1051,40 @@ test_address (void *cls, | |||
1059 | * @param hello our updated HELLO | 1051 | * @param hello our updated HELLO |
1060 | */ | 1052 | */ |
1061 | static void | 1053 | static void |
1062 | hello_update_cb (void *cls, | 1054 | hello_update_cb(void *cls, |
1063 | const struct GNUNET_MessageHeader *hello) | 1055 | const struct GNUNET_MessageHeader *hello) |
1064 | { | 1056 | { |
1065 | struct OverlayConnectContext *occ = cls; | 1057 | struct OverlayConnectContext *occ = cls; |
1066 | int empty; | 1058 | int empty; |
1067 | uint16_t msize; | 1059 | uint16_t msize; |
1068 | 1060 | ||
1069 | msize = ntohs (hello->size); | 1061 | msize = ntohs(hello->size); |
1070 | empty = GNUNET_YES; | 1062 | empty = GNUNET_YES; |
1071 | (void) GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message *) | 1063 | (void)GNUNET_HELLO_iterate_addresses((const struct GNUNET_HELLO_Message *) |
1072 | hello, GNUNET_NO, | 1064 | hello, GNUNET_NO, |
1073 | &test_address, | 1065 | &test_address, |
1074 | &empty); | 1066 | &empty); |
1075 | if (GNUNET_YES == empty) | 1067 | if (GNUNET_YES == empty) |
1076 | { | 1068 | { |
1077 | LOG_DEBUG ("0x%llx: HELLO of %s is empty\n", | 1069 | LOG_DEBUG("0x%llx: HELLO of %s is empty\n", |
1078 | occ->op_id, | 1070 | occ->op_id, |
1079 | GNUNET_i2s (&occ->peer_identity)); | 1071 | GNUNET_i2s(&occ->peer_identity)); |
1080 | return; | 1072 | return; |
1081 | } | 1073 | } |
1082 | LOG_DEBUG ("0x%llx: Received HELLO of %s\n", | 1074 | LOG_DEBUG("0x%llx: Received HELLO of %s\n", |
1083 | occ->op_id, | 1075 | occ->op_id, |
1084 | GNUNET_i2s (&occ->peer_identity)); | 1076 | GNUNET_i2s(&occ->peer_identity)); |
1085 | occ->hello = GNUNET_malloc (msize); | 1077 | occ->hello = GNUNET_malloc(msize); |
1086 | GST_cache_add_hello (occ->peer->id, hello); | 1078 | GST_cache_add_hello(occ->peer->id, hello); |
1087 | GNUNET_memcpy (occ->hello, hello, msize); | 1079 | GNUNET_memcpy(occ->hello, hello, msize); |
1088 | GNUNET_TRANSPORT_hello_get_cancel (occ->ghh); | 1080 | GNUNET_TRANSPORT_hello_get_cancel(occ->ghh); |
1089 | occ->ghh = NULL; | 1081 | occ->ghh = NULL; |
1090 | GST_connection_pool_get_handle_done (occ->cgh_p1th); | 1082 | GST_connection_pool_get_handle_done(occ->cgh_p1th); |
1091 | occ->cgh_p1th = NULL; | 1083 | occ->cgh_p1th = NULL; |
1092 | occ->p1th_ = NULL; | 1084 | occ->p1th_ = NULL; |
1093 | GNUNET_free_non_null (occ->emsg); | 1085 | GNUNET_free_non_null(occ->emsg); |
1094 | occ->emsg = NULL; | 1086 | occ->emsg = NULL; |
1095 | p2_transport_connect (occ); | 1087 | p2_transport_connect(occ); |
1096 | } | 1088 | } |
1097 | 1089 | ||
1098 | 1090 | ||
@@ -1106,39 +1098,39 @@ hello_update_cb (void *cls, | |||
1106 | * @param ignore_ peer identity which is ignored in this callback | 1098 | * @param ignore_ peer identity which is ignored in this callback |
1107 | */ | 1099 | */ |
1108 | static void | 1100 | static void |
1109 | p1_transport_connect_cache_callback (void *cls, | 1101 | p1_transport_connect_cache_callback(void *cls, |
1110 | struct GNUNET_CORE_Handle *ch, | 1102 | struct GNUNET_CORE_Handle *ch, |
1111 | struct GNUNET_TRANSPORT_CoreHandle *th, | 1103 | struct GNUNET_TRANSPORT_CoreHandle *th, |
1112 | struct GNUNET_ATS_ConnectivityHandle *ac, | 1104 | struct GNUNET_ATS_ConnectivityHandle *ac, |
1113 | const struct GNUNET_PeerIdentity *ignore_, | 1105 | const struct GNUNET_PeerIdentity *ignore_, |
1114 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1106 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1115 | { | 1107 | { |
1116 | struct OverlayConnectContext *occ = cls; | 1108 | struct OverlayConnectContext *occ = cls; |
1117 | 1109 | ||
1118 | GNUNET_free_non_null (occ->emsg); | 1110 | GNUNET_free_non_null(occ->emsg); |
1119 | occ->emsg = NULL; | 1111 | occ->emsg = NULL; |
1120 | if (NULL == th) | 1112 | if (NULL == th) |
1121 | { | 1113 | { |
1122 | GNUNET_asprintf (&occ->emsg, | 1114 | GNUNET_asprintf(&occ->emsg, |
1123 | "0x%llx: Cannot connect to TRANSPORT of %s", | 1115 | "0x%llx: Cannot connect to TRANSPORT of %s", |
1124 | occ->op_id, | 1116 | occ->op_id, |
1125 | GNUNET_i2s (&occ->peer_identity)); | 1117 | GNUNET_i2s(&occ->peer_identity)); |
1126 | GNUNET_SCHEDULER_cancel (occ->timeout_task); | 1118 | GNUNET_SCHEDULER_cancel(occ->timeout_task); |
1127 | occ->timeout_task = | 1119 | occ->timeout_task = |
1128 | GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); | 1120 | GNUNET_SCHEDULER_add_now(&timeout_overlay_connect, occ); |
1129 | return; | 1121 | return; |
1130 | } | 1122 | } |
1131 | GNUNET_assert (NULL == occ->p1th_); | 1123 | GNUNET_assert(NULL == occ->p1th_); |
1132 | GNUNET_assert (NULL != occ->cgh_p1th); | 1124 | GNUNET_assert(NULL != occ->cgh_p1th); |
1133 | occ->p1th_ = th; | 1125 | occ->p1th_ = th; |
1134 | GNUNET_asprintf (&occ->emsg, | 1126 | GNUNET_asprintf(&occ->emsg, |
1135 | "0x%llx: Timeout while acquiring HELLO of peer %s", | 1127 | "0x%llx: Timeout while acquiring HELLO of peer %s", |
1136 | occ->op_id, | 1128 | occ->op_id, |
1137 | GNUNET_i2s (&occ->peer_identity)); | 1129 | GNUNET_i2s(&occ->peer_identity)); |
1138 | occ->ghh = GNUNET_TRANSPORT_hello_get (cfg, | 1130 | occ->ghh = GNUNET_TRANSPORT_hello_get(cfg, |
1139 | GNUNET_TRANSPORT_AC_ANY, | 1131 | GNUNET_TRANSPORT_AC_ANY, |
1140 | &hello_update_cb, | 1132 | &hello_update_cb, |
1141 | occ); | 1133 | occ); |
1142 | } | 1134 | } |
1143 | 1135 | ||
1144 | 1136 | ||
@@ -1152,68 +1144,68 @@ p1_transport_connect_cache_callback (void *cls, | |||
1152 | * @param my_identity the identity of our peer | 1144 | * @param my_identity the identity of our peer |
1153 | */ | 1145 | */ |
1154 | static void | 1146 | static void |
1155 | occ_cache_get_handle_core_cb (void *cls, | 1147 | occ_cache_get_handle_core_cb(void *cls, |
1156 | struct GNUNET_CORE_Handle *ch, | 1148 | struct GNUNET_CORE_Handle *ch, |
1157 | struct GNUNET_TRANSPORT_CoreHandle *th, | 1149 | struct GNUNET_TRANSPORT_CoreHandle *th, |
1158 | struct GNUNET_ATS_ConnectivityHandle *ac, | 1150 | struct GNUNET_ATS_ConnectivityHandle *ac, |
1159 | const struct GNUNET_PeerIdentity *my_identity, | 1151 | const struct GNUNET_PeerIdentity *my_identity, |
1160 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1152 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1161 | { | 1153 | { |
1162 | struct OverlayConnectContext *occ = cls; | 1154 | struct OverlayConnectContext *occ = cls; |
1163 | const struct GNUNET_MessageHeader *hello; | 1155 | const struct GNUNET_MessageHeader *hello; |
1164 | 1156 | ||
1165 | GNUNET_assert (NULL != occ->timeout_task); | 1157 | GNUNET_assert(NULL != occ->timeout_task); |
1166 | GNUNET_free_non_null (occ->emsg); | 1158 | GNUNET_free_non_null(occ->emsg); |
1167 | if ((NULL == ch) || (NULL == my_identity)) | 1159 | if ((NULL == ch) || (NULL == my_identity)) |
1168 | { | 1160 | { |
1169 | GNUNET_asprintf (&occ->emsg, | 1161 | GNUNET_asprintf(&occ->emsg, |
1170 | "0x%llx: Failed to connect to CORE of peer with " | 1162 | "0x%llx: Failed to connect to CORE of peer with " |
1171 | "id: %u", | 1163 | "id: %u", |
1172 | occ->op_id, | 1164 | occ->op_id, |
1173 | occ->peer->id); | 1165 | occ->peer->id); |
1174 | GNUNET_SCHEDULER_cancel (occ->timeout_task); | 1166 | GNUNET_SCHEDULER_cancel(occ->timeout_task); |
1175 | occ->timeout_task = | 1167 | occ->timeout_task = |
1176 | GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); | 1168 | GNUNET_SCHEDULER_add_now(&timeout_overlay_connect, occ); |
1177 | return; | 1169 | return; |
1178 | } | 1170 | } |
1179 | occ->emsg = NULL; | 1171 | occ->emsg = NULL; |
1180 | if (NULL != | 1172 | if (NULL != |
1181 | GNUNET_CORE_get_mq (ch, | 1173 | GNUNET_CORE_get_mq(ch, |
1182 | &occ->other_peer_identity)) | 1174 | &occ->other_peer_identity)) |
1183 | { | 1175 | { |
1184 | LOG_DEBUG ("0x%llx: Target peer already connected\n", | 1176 | LOG_DEBUG("0x%llx: Target peer already connected\n", |
1185 | occ->op_id); | 1177 | occ->op_id); |
1186 | GNUNET_SCHEDULER_cancel (occ->timeout_task); | 1178 | GNUNET_SCHEDULER_cancel(occ->timeout_task); |
1187 | occ->timeout_task = NULL; | 1179 | occ->timeout_task = NULL; |
1188 | send_overlay_connect_success_msg (occ); | 1180 | send_overlay_connect_success_msg(occ); |
1189 | occ->cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup_occ, occ); | 1181 | occ->cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup_occ, occ); |
1190 | return; | 1182 | return; |
1191 | } | 1183 | } |
1192 | occ->peer_identity = *my_identity; | 1184 | occ->peer_identity = *my_identity; |
1193 | LOG_DEBUG ("0x%llx: Acquiring HELLO of peer %s\n", | 1185 | LOG_DEBUG("0x%llx: Acquiring HELLO of peer %s\n", |
1194 | occ->op_id, | 1186 | occ->op_id, |
1195 | GNUNET_i2s (&occ->peer_identity)); | 1187 | GNUNET_i2s(&occ->peer_identity)); |
1196 | /* Lookup for HELLO in hello cache */ | 1188 | /* Lookup for HELLO in hello cache */ |
1197 | if (NULL != (hello = GST_cache_lookup_hello (occ->peer->id))) | 1189 | if (NULL != (hello = GST_cache_lookup_hello(occ->peer->id))) |
1198 | { | 1190 | { |
1199 | LOG_DEBUG ("0x%llx: HELLO of peer %s found in cache\n", | 1191 | LOG_DEBUG("0x%llx: HELLO of peer %s found in cache\n", |
1200 | occ->op_id, | 1192 | occ->op_id, |
1201 | GNUNET_i2s (&occ->peer_identity)); | 1193 | GNUNET_i2s(&occ->peer_identity)); |
1202 | occ->hello = GNUNET_copy_message (hello); | 1194 | occ->hello = GNUNET_copy_message(hello); |
1203 | p2_transport_connect (occ); | 1195 | p2_transport_connect(occ); |
1204 | return; | 1196 | return; |
1205 | } | 1197 | } |
1206 | GNUNET_asprintf (&occ->emsg, | 1198 | GNUNET_asprintf(&occ->emsg, |
1207 | "0x%llx: Timeout while acquiring TRANSPORT of %s from cache", | 1199 | "0x%llx: Timeout while acquiring TRANSPORT of %s from cache", |
1208 | occ->op_id, | 1200 | occ->op_id, |
1209 | GNUNET_i2s (&occ->peer_identity)); | 1201 | GNUNET_i2s(&occ->peer_identity)); |
1210 | occ->cgh_p1th = | 1202 | occ->cgh_p1th = |
1211 | GST_connection_pool_get_handle (occ->peer->id, | 1203 | GST_connection_pool_get_handle(occ->peer->id, |
1212 | occ->peer->details.local.cfg, | 1204 | occ->peer->details.local.cfg, |
1213 | GST_CONNECTIONPOOL_SERVICE_TRANSPORT, | 1205 | GST_CONNECTIONPOOL_SERVICE_TRANSPORT, |
1214 | p1_transport_connect_cache_callback, | 1206 | p1_transport_connect_cache_callback, |
1215 | occ, | 1207 | occ, |
1216 | NULL, NULL, NULL); | 1208 | NULL, NULL, NULL); |
1217 | } | 1209 | } |
1218 | 1210 | ||
1219 | 1211 | ||
@@ -1226,41 +1218,41 @@ occ_cache_get_handle_core_cb (void *cls, | |||
1226 | * @param msg the peer create success message | 1218 | * @param msg the peer create success message |
1227 | */ | 1219 | */ |
1228 | static void | 1220 | static void |
1229 | overlay_connect_get_config (void *cls, | 1221 | overlay_connect_get_config(void *cls, |
1230 | const struct GNUNET_MessageHeader *msg) | 1222 | const struct GNUNET_MessageHeader *msg) |
1231 | { | 1223 | { |
1232 | struct OverlayConnectContext *occ = cls; | 1224 | struct OverlayConnectContext *occ = cls; |
1233 | struct RemotePeer2Context *rp2c; | 1225 | struct RemotePeer2Context *rp2c; |
1234 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *cmsg; | 1226 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *cmsg; |
1235 | 1227 | ||
1236 | GNUNET_assert (OCC_TYPE_LOCAL != occ->type); | 1228 | GNUNET_assert(OCC_TYPE_LOCAL != occ->type); |
1237 | rp2c = &occ->p2ctx.remote; | 1229 | rp2c = &occ->p2ctx.remote; |
1238 | rp2c->opc = NULL; | 1230 | rp2c->opc = NULL; |
1239 | GNUNET_assert (NULL != occ->timeout_task); | 1231 | GNUNET_assert(NULL != occ->timeout_task); |
1240 | if (GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION != ntohs (msg->type)) | 1232 | if (GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION != ntohs(msg->type)) |
1241 | { | 1233 | { |
1242 | GNUNET_SCHEDULER_cancel (occ->timeout_task); | 1234 | GNUNET_SCHEDULER_cancel(occ->timeout_task); |
1243 | occ->timeout_task = | 1235 | occ->timeout_task = |
1244 | GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); | 1236 | GNUNET_SCHEDULER_add_now(&timeout_overlay_connect, occ); |
1245 | } | 1237 | } |
1246 | cmsg = | 1238 | cmsg = |
1247 | (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg; | 1239 | (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *)msg; |
1248 | occ->other_peer_identity = cmsg->peer_identity; | 1240 | occ->other_peer_identity = cmsg->peer_identity; |
1249 | GNUNET_free_non_null (occ->emsg); | 1241 | GNUNET_free_non_null(occ->emsg); |
1250 | GNUNET_asprintf (&occ->emsg, | 1242 | GNUNET_asprintf(&occ->emsg, |
1251 | "0x%llx: Timeout while connecting to CORE of peer with " | 1243 | "0x%llx: Timeout while connecting to CORE of peer with " |
1252 | "id: %u", | 1244 | "id: %u", |
1253 | occ->op_id, | 1245 | occ->op_id, |
1254 | occ->peer->id); | 1246 | occ->peer->id); |
1255 | occ->cgh_ch = | 1247 | occ->cgh_ch = |
1256 | GST_connection_pool_get_handle (occ->peer->id, | 1248 | GST_connection_pool_get_handle(occ->peer->id, |
1257 | occ->peer->details.local.cfg, | 1249 | occ->peer->details.local.cfg, |
1258 | GST_CONNECTIONPOOL_SERVICE_CORE, | 1250 | GST_CONNECTIONPOOL_SERVICE_CORE, |
1259 | occ_cache_get_handle_core_cb, | 1251 | occ_cache_get_handle_core_cb, |
1260 | occ, | 1252 | occ, |
1261 | &occ->other_peer_identity, | 1253 | &occ->other_peer_identity, |
1262 | &overlay_connect_notify, | 1254 | &overlay_connect_notify, |
1263 | occ); | 1255 | occ); |
1264 | return; | 1256 | return; |
1265 | } | 1257 | } |
1266 | 1258 | ||
@@ -1272,12 +1264,12 @@ overlay_connect_get_config (void *cls, | |||
1272 | * @param emsg the error message; NULL if host registration is successful | 1264 | * @param emsg the error message; NULL if host registration is successful |
1273 | */ | 1265 | */ |
1274 | static void | 1266 | static void |
1275 | host_registration_comp (void *cls, const char *emsg) | 1267 | host_registration_comp(void *cls, const char *emsg) |
1276 | { | 1268 | { |
1277 | struct RegisteredHostContext *rhc = cls; | 1269 | struct RegisteredHostContext *rhc = cls; |
1278 | 1270 | ||
1279 | rhc->state = RHC_DONE; | 1271 | rhc->state = RHC_DONE; |
1280 | GST_process_next_focc (rhc); | 1272 | GST_process_next_focc(rhc); |
1281 | } | 1273 | } |
1282 | 1274 | ||
1283 | 1275 | ||
@@ -1292,19 +1284,19 @@ host_registration_comp (void *cls, const char *emsg) | |||
1292 | * #GNUNET_NO if not. | 1284 | * #GNUNET_NO if not. |
1293 | */ | 1285 | */ |
1294 | static int | 1286 | static int |
1295 | reghost_match_iterator (void *cls, | 1287 | reghost_match_iterator(void *cls, |
1296 | const struct GNUNET_HashCode *key, | 1288 | const struct GNUNET_HashCode *key, |
1297 | void *value) | 1289 | void *value) |
1298 | { | 1290 | { |
1299 | struct RegisteredHostContext **rh = cls; | 1291 | struct RegisteredHostContext **rh = cls; |
1300 | struct RegisteredHostContext *rh_val = value; | 1292 | struct RegisteredHostContext *rh_val = value; |
1301 | 1293 | ||
1302 | if ((rh_val->host == (*rh)->host) && (rh_val->reg_host == (*rh)->reg_host)) | 1294 | if ((rh_val->host == (*rh)->host) && (rh_val->reg_host == (*rh)->reg_host)) |
1303 | { | 1295 | { |
1304 | GNUNET_free (*rh); | 1296 | GNUNET_free(*rh); |
1305 | *rh = rh_val; | 1297 | *rh = rh_val; |
1306 | return GNUNET_NO; | 1298 | return GNUNET_NO; |
1307 | } | 1299 | } |
1308 | return GNUNET_YES; | 1300 | return GNUNET_YES; |
1309 | } | 1301 | } |
1310 | 1302 | ||
@@ -1317,15 +1309,15 @@ reghost_match_iterator (void *cls, | |||
1317 | * @return the hashcode | 1309 | * @return the hashcode |
1318 | */ | 1310 | */ |
1319 | static struct GNUNET_HashCode | 1311 | static struct GNUNET_HashCode |
1320 | hash_hosts (struct GNUNET_TESTBED_Host *reg_host, | 1312 | hash_hosts(struct GNUNET_TESTBED_Host *reg_host, |
1321 | struct GNUNET_TESTBED_Host *host) | 1313 | struct GNUNET_TESTBED_Host *host) |
1322 | { | 1314 | { |
1323 | struct GNUNET_HashCode hash; | 1315 | struct GNUNET_HashCode hash; |
1324 | uint32_t host_ids[2]; | 1316 | uint32_t host_ids[2]; |
1325 | 1317 | ||
1326 | host_ids[0] = GNUNET_TESTBED_host_get_id_ (reg_host); | 1318 | host_ids[0] = GNUNET_TESTBED_host_get_id_(reg_host); |
1327 | host_ids[1] = GNUNET_TESTBED_host_get_id_ (host); | 1319 | host_ids[1] = GNUNET_TESTBED_host_get_id_(host); |
1328 | GNUNET_CRYPTO_hash (host_ids, sizeof (host_ids), &hash); | 1320 | GNUNET_CRYPTO_hash(host_ids, sizeof(host_ids), &hash); |
1329 | return hash; | 1321 | return hash; |
1330 | } | 1322 | } |
1331 | 1323 | ||
@@ -1344,48 +1336,48 @@ hash_hosts (struct GNUNET_TESTBED_Host *reg_host, | |||
1344 | * already registered, NULL is returned. | 1336 | * already registered, NULL is returned. |
1345 | */ | 1337 | */ |
1346 | static struct RegisteredHostContext * | 1338 | static struct RegisteredHostContext * |
1347 | register_host (struct Slave *slave, | 1339 | register_host(struct Slave *slave, |
1348 | struct GNUNET_TESTBED_Host *host) | 1340 | struct GNUNET_TESTBED_Host *host) |
1349 | { | 1341 | { |
1350 | struct GNUNET_HashCode hash; | 1342 | struct GNUNET_HashCode hash; |
1351 | struct RegisteredHostContext *rhc; | 1343 | struct RegisteredHostContext *rhc; |
1352 | 1344 | ||
1353 | rhc = GNUNET_new (struct RegisteredHostContext); | 1345 | rhc = GNUNET_new(struct RegisteredHostContext); |
1354 | rhc->reg_host = host; | 1346 | rhc->reg_host = host; |
1355 | rhc->host = GST_host_list[slave->host_id]; | 1347 | rhc->host = GST_host_list[slave->host_id]; |
1356 | GNUNET_assert (NULL != rhc->reg_host); | 1348 | GNUNET_assert(NULL != rhc->reg_host); |
1357 | GNUNET_assert (NULL != rhc->host); | 1349 | GNUNET_assert(NULL != rhc->host); |
1358 | rhc->state = RHC_INIT; | 1350 | rhc->state = RHC_INIT; |
1359 | hash = hash_hosts (rhc->reg_host, rhc->host); | 1351 | hash = hash_hosts(rhc->reg_host, rhc->host); |
1360 | if ((GNUNET_NO == | 1352 | if ((GNUNET_NO == |
1361 | GNUNET_CONTAINER_multihashmap_contains (slave->reghost_map, | 1353 | GNUNET_CONTAINER_multihashmap_contains(slave->reghost_map, |
1362 | &hash)) || | 1354 | &hash)) || |
1363 | (GNUNET_SYSERR != | 1355 | (GNUNET_SYSERR != |
1364 | GNUNET_CONTAINER_multihashmap_get_multiple (slave->reghost_map, | 1356 | GNUNET_CONTAINER_multihashmap_get_multiple(slave->reghost_map, |
1365 | &hash, | 1357 | &hash, |
1366 | reghost_match_iterator, | 1358 | reghost_match_iterator, |
1367 | &rhc))) | 1359 | &rhc))) |
1368 | { | 1360 | { |
1369 | /* create and add a new registerd host context */ | 1361 | /* create and add a new registerd host context */ |
1370 | /* add the focc to its queue */ | 1362 | /* add the focc to its queue */ |
1371 | GNUNET_CONTAINER_multihashmap_put (slave->reghost_map, | 1363 | GNUNET_CONTAINER_multihashmap_put(slave->reghost_map, |
1372 | &hash, | 1364 | &hash, |
1373 | rhc, | 1365 | rhc, |
1374 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 1366 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
1375 | GST_queue_host_registration (slave, | 1367 | GST_queue_host_registration(slave, |
1376 | host_registration_comp, | 1368 | host_registration_comp, |
1377 | rhc, | 1369 | rhc, |
1378 | rhc->reg_host); | 1370 | rhc->reg_host); |
1379 | } | 1371 | } |
1380 | else | 1372 | else |
1381 | { | 1373 | { |
1382 | /* rhc is now set to the existing one from the hash map by | 1374 | /* rhc is now set to the existing one from the hash map by |
1383 | * reghost_match_iterator() */ | 1375 | * reghost_match_iterator() */ |
1384 | /* if queue is empty then ignore creating focc and proceed with normal | 1376 | /* if queue is empty then ignore creating focc and proceed with normal |
1385 | * forwarding */ | 1377 | * forwarding */ |
1386 | if (RHC_DONE == rhc->state) | 1378 | if (RHC_DONE == rhc->state) |
1387 | return NULL; | 1379 | return NULL; |
1388 | } | 1380 | } |
1389 | return rhc; | 1381 | return rhc; |
1390 | } | 1382 | } |
1391 | 1383 | ||
@@ -1400,8 +1392,8 @@ register_host (struct Slave *slave, | |||
1400 | * be notified | 1392 | * be notified |
1401 | */ | 1393 | */ |
1402 | static void | 1394 | static void |
1403 | forward_overlay_connect (const struct GNUNET_TESTBED_OverlayConnectMessage *msg, | 1395 | forward_overlay_connect(const struct GNUNET_TESTBED_OverlayConnectMessage *msg, |
1404 | struct GNUNET_SERVICE_Client *client) | 1396 | struct GNUNET_SERVICE_Client *client) |
1405 | { | 1397 | { |
1406 | struct ForwardedOperationContext *fopc; | 1398 | struct ForwardedOperationContext *fopc; |
1407 | struct Route *route_to_peer2_host; | 1399 | struct Route *route_to_peer2_host; |
@@ -1414,61 +1406,61 @@ forward_overlay_connect (const struct GNUNET_TESTBED_OverlayConnectMessage *msg, | |||
1414 | uint32_t p1; | 1406 | uint32_t p1; |
1415 | uint32_t p2; | 1407 | uint32_t p2; |
1416 | 1408 | ||
1417 | p1 = ntohl (msg->peer1); | 1409 | p1 = ntohl(msg->peer1); |
1418 | p2 = ntohl (msg->peer2); | 1410 | p2 = ntohl(msg->peer2); |
1419 | op_id = GNUNET_ntohll (msg->operation_id); | 1411 | op_id = GNUNET_ntohll(msg->operation_id); |
1420 | peer2_host_id = ntohl (msg->peer2_host_id); | 1412 | peer2_host_id = ntohl(msg->peer2_host_id); |
1421 | GNUNET_assert (VALID_PEER_ID (p1)); | 1413 | GNUNET_assert(VALID_PEER_ID(p1)); |
1422 | GNUNET_assert (VALID_HOST_ID (peer2_host_id)); | 1414 | GNUNET_assert(VALID_HOST_ID(peer2_host_id)); |
1423 | peer = GST_peer_list[p1]; | 1415 | peer = GST_peer_list[p1]; |
1424 | GNUNET_assert (GNUNET_YES == peer->is_remote); | 1416 | GNUNET_assert(GNUNET_YES == peer->is_remote); |
1425 | LOG_DEBUG ("0x%llx: Forwarding overlay connect\n", op_id); | 1417 | LOG_DEBUG("0x%llx: Forwarding overlay connect\n", op_id); |
1426 | route_to_peer2_host = GST_find_dest_route (peer2_host_id); | 1418 | route_to_peer2_host = GST_find_dest_route(peer2_host_id); |
1427 | route_to_peer1_host = GST_find_dest_route | 1419 | route_to_peer1_host = GST_find_dest_route |
1428 | (peer->details.remote.remote_host_id); | 1420 | (peer->details.remote.remote_host_id); |
1429 | GNUNET_assert (NULL != route_to_peer1_host); | 1421 | GNUNET_assert(NULL != route_to_peer1_host); |
1430 | if ((NULL != route_to_peer2_host) && | 1422 | if ((NULL != route_to_peer2_host) && |
1431 | (route_to_peer1_host->dest == route_to_peer2_host->dest)) | 1423 | (route_to_peer1_host->dest == route_to_peer2_host->dest)) |
1432 | goto forward; | 1424 | goto forward; |
1433 | /* Peer2 is either with us OR peer1 and peer2 can be reached through | 1425 | /* Peer2 is either with us OR peer1 and peer2 can be reached through |
1434 | different subtrees OR peer2 is on a subtree unknown to us */ | 1426 | different subtrees OR peer2 is on a subtree unknown to us */ |
1435 | if (NULL != (rhc = register_host (peer->details.remote.slave, | 1427 | if (NULL != (rhc = register_host(peer->details.remote.slave, |
1436 | GST_host_list[peer2_host_id]))) | 1428 | GST_host_list[peer2_host_id]))) |
1437 | { | 1429 | { |
1438 | LOG_DEBUG ("Queueing forwarding FOCC for connecting peers %u and %u\n", p1, p2); | 1430 | LOG_DEBUG("Queueing forwarding FOCC for connecting peers %u and %u\n", p1, p2); |
1439 | focc = GNUNET_new (struct ForwardedOverlayConnectContext); | 1431 | focc = GNUNET_new(struct ForwardedOverlayConnectContext); |
1440 | focc->rhc = rhc; | 1432 | focc->rhc = rhc; |
1441 | focc->peer1 = p1; | 1433 | focc->peer1 = p1; |
1442 | focc->peer2 = p2; | 1434 | focc->peer2 = p2; |
1443 | focc->peer2_host_id = peer2_host_id; | 1435 | focc->peer2_host_id = peer2_host_id; |
1444 | focc->orig_msg = GNUNET_copy_message (&msg->header); | 1436 | focc->orig_msg = GNUNET_copy_message(&msg->header); |
1445 | focc->operation_id = op_id; | 1437 | focc->operation_id = op_id; |
1446 | focc->client = client; | 1438 | focc->client = client; |
1447 | GNUNET_CONTAINER_DLL_insert_tail (rhc->focc_dll_head, | 1439 | GNUNET_CONTAINER_DLL_insert_tail(rhc->focc_dll_head, |
1448 | rhc->focc_dll_tail, | 1440 | rhc->focc_dll_tail, |
1449 | focc); | 1441 | focc); |
1450 | return; | 1442 | return; |
1451 | } | 1443 | } |
1452 | 1444 | ||
1453 | forward: | 1445 | forward: |
1454 | LOG_DEBUG ("Forwarding without FOCC for connecting peers %u and %u\n", p1, p2); | 1446 | LOG_DEBUG("Forwarding without FOCC for connecting peers %u and %u\n", p1, p2); |
1455 | fopc = GNUNET_new (struct ForwardedOperationContext); | 1447 | fopc = GNUNET_new(struct ForwardedOperationContext); |
1456 | fopc->client = client; | 1448 | fopc->client = client; |
1457 | fopc->operation_id = op_id; | 1449 | fopc->operation_id = op_id; |
1458 | fopc->type = OP_OVERLAY_CONNECT; | 1450 | fopc->type = OP_OVERLAY_CONNECT; |
1459 | fopc->opc = | 1451 | fopc->opc = |
1460 | GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. | 1452 | GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. |
1461 | slave->controller, op_id, | 1453 | slave->controller, op_id, |
1462 | &msg->header, | 1454 | &msg->header, |
1463 | &GST_forwarded_operation_reply_relay, | 1455 | &GST_forwarded_operation_reply_relay, |
1464 | fopc); | 1456 | fopc); |
1465 | fopc->timeout_task = | 1457 | fopc->timeout_task = |
1466 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 1458 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
1467 | &GST_forwarded_operation_timeout, | 1459 | &GST_forwarded_operation_timeout, |
1468 | fopc); | 1460 | fopc); |
1469 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 1461 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
1470 | fopcq_tail, | 1462 | fopcq_tail, |
1471 | fopc); | 1463 | fopc); |
1472 | } | 1464 | } |
1473 | 1465 | ||
1474 | 1466 | ||
@@ -1480,35 +1472,35 @@ forward_overlay_connect (const struct GNUNET_TESTBED_OverlayConnectMessage *msg, | |||
1480 | * @param c handle to the controller connection | 1472 | * @param c handle to the controller connection |
1481 | */ | 1473 | */ |
1482 | static void | 1474 | static void |
1483 | p2_controller_connect_cb (void *cls, | 1475 | p2_controller_connect_cb(void *cls, |
1484 | struct GNUNET_TESTBED_Controller *c) | 1476 | struct GNUNET_TESTBED_Controller *c) |
1485 | { | 1477 | { |
1486 | struct OverlayConnectContext *occ = cls; | 1478 | struct OverlayConnectContext *occ = cls; |
1487 | struct RemotePeer2Context *rp2c; | 1479 | struct RemotePeer2Context *rp2c; |
1488 | struct GNUNET_TESTBED_PeerGetConfigurationMessage cmsg; | 1480 | struct GNUNET_TESTBED_PeerGetConfigurationMessage cmsg; |
1489 | 1481 | ||
1490 | GNUNET_assert (OCC_TYPE_LOCAL != occ->type); | 1482 | GNUNET_assert(OCC_TYPE_LOCAL != occ->type); |
1491 | rp2c = &occ->p2ctx.remote; | 1483 | rp2c = &occ->p2ctx.remote; |
1492 | rp2c->ncn = NULL; | 1484 | rp2c->ncn = NULL; |
1493 | rp2c->p2c = c; | 1485 | rp2c->p2c = c; |
1494 | cmsg.header.size = | 1486 | cmsg.header.size = |
1495 | htons (sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); | 1487 | htons(sizeof(struct GNUNET_TESTBED_PeerGetConfigurationMessage)); |
1496 | cmsg.header.type = | 1488 | cmsg.header.type = |
1497 | htons (GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION); | 1489 | htons(GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION); |
1498 | cmsg.peer_id = htonl (occ->other_peer_id); | 1490 | cmsg.peer_id = htonl(occ->other_peer_id); |
1499 | cmsg.operation_id = GNUNET_htonll (occ->op_id); | 1491 | cmsg.operation_id = GNUNET_htonll(occ->op_id); |
1500 | rp2c->opc = | 1492 | rp2c->opc = |
1501 | GNUNET_TESTBED_forward_operation_msg_ (rp2c->p2c, | 1493 | GNUNET_TESTBED_forward_operation_msg_(rp2c->p2c, |
1502 | occ->op_id, | 1494 | occ->op_id, |
1503 | &cmsg.header, | 1495 | &cmsg.header, |
1504 | &overlay_connect_get_config, | 1496 | &overlay_connect_get_config, |
1505 | occ); | 1497 | occ); |
1506 | GNUNET_free_non_null (occ->emsg); | 1498 | GNUNET_free_non_null(occ->emsg); |
1507 | GNUNET_asprintf (&occ->emsg, | 1499 | GNUNET_asprintf(&occ->emsg, |
1508 | "0x%llx: Timeout while getting peer identity of peer " | 1500 | "0x%llx: Timeout while getting peer identity of peer " |
1509 | "with id: %u", | 1501 | "with id: %u", |
1510 | occ->op_id, | 1502 | occ->op_id, |
1511 | occ->other_peer_id); | 1503 | occ->other_peer_id); |
1512 | } | 1504 | } |
1513 | 1505 | ||
1514 | 1506 | ||
@@ -1519,8 +1511,8 @@ p2_controller_connect_cb (void *cls, | |||
1519 | * @param msg the actual message | 1511 | * @param msg the actual message |
1520 | */ | 1512 | */ |
1521 | void | 1513 | void |
1522 | handle_overlay_connect (void *cls, | 1514 | handle_overlay_connect(void *cls, |
1523 | const struct GNUNET_TESTBED_OverlayConnectMessage *msg) | 1515 | const struct GNUNET_TESTBED_OverlayConnectMessage *msg) |
1524 | { | 1516 | { |
1525 | struct GNUNET_SERVICE_Client *client = cls; | 1517 | struct GNUNET_SERVICE_Client *client = cls; |
1526 | struct Peer *peer; | 1518 | struct Peer *peer; |
@@ -1532,112 +1524,114 @@ handle_overlay_connect (void *cls, | |||
1532 | uint32_t p2; | 1524 | uint32_t p2; |
1533 | uint32_t peer2_host_id; | 1525 | uint32_t peer2_host_id; |
1534 | 1526 | ||
1535 | p1 = ntohl (msg->peer1); | 1527 | p1 = ntohl(msg->peer1); |
1536 | p2 = ntohl (msg->peer2); | 1528 | p2 = ntohl(msg->peer2); |
1537 | if (! VALID_PEER_ID (p1)) | 1529 | if (!VALID_PEER_ID(p1)) |
1538 | { | 1530 | { |
1539 | GNUNET_break (0); | 1531 | GNUNET_break(0); |
1540 | GNUNET_SERVICE_client_drop (client); | 1532 | GNUNET_SERVICE_client_drop(client); |
1541 | return; | 1533 | return; |
1542 | } | 1534 | } |
1543 | peer = GST_peer_list[p1]; | 1535 | peer = GST_peer_list[p1]; |
1544 | operation_id = GNUNET_ntohll (msg->operation_id); | 1536 | operation_id = GNUNET_ntohll(msg->operation_id); |
1545 | LOG_DEBUG | 1537 | LOG_DEBUG |
1546 | ("Received overlay connect for peers %u and %u with op id: 0x%llx\n", | 1538 | ("Received overlay connect for peers %u and %u with op id: 0x%llx\n", |
1547 | p1, | 1539 | p1, |
1548 | p2, | 1540 | p2, |
1549 | operation_id); | 1541 | operation_id); |
1550 | peer2_host_id = ntohl (msg->peer2_host_id); | 1542 | peer2_host_id = ntohl(msg->peer2_host_id); |
1551 | if (GNUNET_YES == peer->is_remote) | 1543 | if (GNUNET_YES == peer->is_remote) |
1552 | { | ||
1553 | if (! VALID_HOST_ID (peer2_host_id)) | ||
1554 | { | 1544 | { |
1555 | GNUNET_break (0); | 1545 | if (!VALID_HOST_ID(peer2_host_id)) |
1556 | GNUNET_SERVICE_client_drop (client); | 1546 | { |
1547 | GNUNET_break(0); | ||
1548 | GNUNET_SERVICE_client_drop(client); | ||
1549 | return; | ||
1550 | } | ||
1551 | forward_overlay_connect(msg, client); | ||
1552 | GNUNET_SERVICE_client_continue(client); | ||
1557 | return; | 1553 | return; |
1558 | } | 1554 | } |
1559 | forward_overlay_connect (msg, client); | ||
1560 | GNUNET_SERVICE_client_continue (client); | ||
1561 | return; | ||
1562 | } | ||
1563 | p2n = NULL; | 1555 | p2n = NULL; |
1564 | occ = GNUNET_new (struct OverlayConnectContext); | 1556 | occ = GNUNET_new(struct OverlayConnectContext); |
1565 | occ->type = OCC_TYPE_LOCAL; | 1557 | occ->type = OCC_TYPE_LOCAL; |
1566 | if (! VALID_PEER_ID (p2)) /* May be peer2 is on a another controller */ | 1558 | if (!VALID_PEER_ID(p2)) /* May be peer2 is on a another controller */ |
1567 | { | ||
1568 | if (NULL == (p2n = GST_get_neighbour (peer2_host_id))) | ||
1569 | { | 1559 | { |
1570 | if (! VALID_HOST_ID (peer2_host_id)) | 1560 | if (NULL == (p2n = GST_get_neighbour(peer2_host_id))) |
1571 | { | 1561 | { |
1572 | GNUNET_break (0); | 1562 | if (!VALID_HOST_ID(peer2_host_id)) |
1573 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1563 | { |
1574 | "0x%llx: Peer %u's host not in our neighbours list\n", | 1564 | GNUNET_break(0); |
1575 | operation_id, p2); | 1565 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1576 | GNUNET_SERVICE_client_drop (client); | 1566 | "0x%llx: Peer %u's host not in our neighbours list\n", |
1577 | GNUNET_free (occ); | 1567 | operation_id, p2); |
1578 | return; | 1568 | GNUNET_SERVICE_client_drop(client); |
1579 | } | 1569 | GNUNET_free(occ); |
1580 | p2n = GST_create_neighbour (GST_host_list[peer2_host_id]); | 1570 | return; |
1571 | } | ||
1572 | p2n = GST_create_neighbour(GST_host_list[peer2_host_id]); | ||
1573 | } | ||
1574 | occ->type = OCC_TYPE_REMOTE_LATERAL; | ||
1575 | occ->p2ctx.remote.p2n = p2n; | ||
1581 | } | 1576 | } |
1582 | occ->type = OCC_TYPE_REMOTE_LATERAL; | ||
1583 | occ->p2ctx.remote.p2n = p2n; | ||
1584 | } | ||
1585 | else if (GNUNET_YES == GST_peer_list[p2]->is_remote) | 1577 | else if (GNUNET_YES == GST_peer_list[p2]->is_remote) |
1586 | { | 1578 | { |
1587 | occ->type = OCC_TYPE_REMOTE_SLAVE; | 1579 | occ->type = OCC_TYPE_REMOTE_SLAVE; |
1588 | occ->p2ctx.remote.p2c = GST_peer_list[p2]->details.remote.slave->controller; | 1580 | occ->p2ctx.remote.p2c = GST_peer_list[p2]->details.remote.slave->controller; |
1589 | } | 1581 | } |
1590 | GNUNET_CONTAINER_DLL_insert_tail (occq_head, | 1582 | GNUNET_CONTAINER_DLL_insert_tail(occq_head, |
1591 | occq_tail, | 1583 | occq_tail, |
1592 | occ); | 1584 | occ); |
1593 | occ->client = client; | 1585 | occ->client = client; |
1594 | occ->other_peer_id = p2; | 1586 | occ->other_peer_id = p2; |
1595 | GST_peer_list[p1]->reference_cnt++; | 1587 | GST_peer_list[p1]->reference_cnt++; |
1596 | occ->peer = GST_peer_list[p1]; | 1588 | occ->peer = GST_peer_list[p1]; |
1597 | occ->op_id = operation_id; | 1589 | occ->op_id = operation_id; |
1598 | GNUNET_assert (NULL == occ->timeout_task); | 1590 | GNUNET_assert(NULL == occ->timeout_task); |
1599 | occ->timeout_task = | 1591 | occ->timeout_task = |
1600 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 1592 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
1601 | &timeout_overlay_connect, | 1593 | &timeout_overlay_connect, |
1602 | occ); | 1594 | occ); |
1603 | switch (occ->type) | 1595 | switch (occ->type) |
1604 | { | 1596 | { |
1605 | case OCC_TYPE_REMOTE_LATERAL: | 1597 | case OCC_TYPE_REMOTE_LATERAL: |
1606 | GNUNET_asprintf (&occ->emsg, | 1598 | GNUNET_asprintf(&occ->emsg, |
1607 | "0x%llx: Timeout while acquiring connection to peer %u's " | 1599 | "0x%llx: Timeout while acquiring connection to peer %u's " |
1608 | "host: %u\n", | 1600 | "host: %u\n", |
1609 | occ->op_id, | 1601 | occ->op_id, |
1610 | occ->other_peer_id, | 1602 | occ->other_peer_id, |
1611 | peer2_host_id); | 1603 | peer2_host_id); |
1612 | occ->p2ctx.remote.ncn | 1604 | occ->p2ctx.remote.ncn |
1613 | = GST_neighbour_get_connection (p2n, | 1605 | = GST_neighbour_get_connection(p2n, |
1614 | &p2_controller_connect_cb, | 1606 | &p2_controller_connect_cb, |
1615 | occ); | 1607 | occ); |
1616 | break; | 1608 | break; |
1617 | case OCC_TYPE_REMOTE_SLAVE: | 1609 | |
1618 | p2_controller_connect_cb (occ, | 1610 | case OCC_TYPE_REMOTE_SLAVE: |
1619 | occ->p2ctx.remote.p2c); | 1611 | p2_controller_connect_cb(occ, |
1620 | break; | 1612 | occ->p2ctx.remote.p2c); |
1621 | case OCC_TYPE_LOCAL: | 1613 | break; |
1622 | peer2 = GST_peer_list[occ->other_peer_id]; | 1614 | |
1623 | peer2->reference_cnt++; | 1615 | case OCC_TYPE_LOCAL: |
1624 | GNUNET_TESTING_peer_get_identity (peer2->details.local.peer, | 1616 | peer2 = GST_peer_list[occ->other_peer_id]; |
1625 | &occ->other_peer_identity); | 1617 | peer2->reference_cnt++; |
1626 | GNUNET_asprintf (&occ->emsg, | 1618 | GNUNET_TESTING_peer_get_identity(peer2->details.local.peer, |
1627 | "0x%llx: Timeout while connecting to CORE of peer with " | 1619 | &occ->other_peer_identity); |
1628 | "id: %u", | 1620 | GNUNET_asprintf(&occ->emsg, |
1629 | occ->op_id, | 1621 | "0x%llx: Timeout while connecting to CORE of peer with " |
1630 | occ->peer->id); | 1622 | "id: %u", |
1631 | occ->cgh_ch = | 1623 | occ->op_id, |
1632 | GST_connection_pool_get_handle (occ->peer->id, | 1624 | occ->peer->id); |
1633 | occ->peer->details.local.cfg, | 1625 | occ->cgh_ch = |
1634 | GST_CONNECTIONPOOL_SERVICE_CORE, | 1626 | GST_connection_pool_get_handle(occ->peer->id, |
1635 | occ_cache_get_handle_core_cb, occ, | 1627 | occ->peer->details.local.cfg, |
1636 | &occ->other_peer_identity, | 1628 | GST_CONNECTIONPOOL_SERVICE_CORE, |
1637 | &overlay_connect_notify, occ); | 1629 | occ_cache_get_handle_core_cb, occ, |
1638 | break; | 1630 | &occ->other_peer_identity, |
1639 | } | 1631 | &overlay_connect_notify, occ); |
1640 | GNUNET_SERVICE_client_continue (client); | 1632 | break; |
1633 | } | ||
1634 | GNUNET_SERVICE_client_continue(client); | ||
1641 | } | 1635 | } |
1642 | 1636 | ||
1643 | 1637 | ||
@@ -1648,30 +1642,30 @@ handle_overlay_connect (void *cls, | |||
1648 | * @param rocc the RemoteOverlayConnectCtx | 1642 | * @param rocc the RemoteOverlayConnectCtx |
1649 | */ | 1643 | */ |
1650 | static void | 1644 | static void |
1651 | cleanup_rocc (struct RemoteOverlayConnectCtx *rocc) | 1645 | cleanup_rocc(struct RemoteOverlayConnectCtx *rocc) |
1652 | { | 1646 | { |
1653 | LOG_DEBUG ("0x%llx: Cleaning up rocc\n", | 1647 | LOG_DEBUG("0x%llx: Cleaning up rocc\n", |
1654 | rocc->op_id); | 1648 | rocc->op_id); |
1655 | if (NULL != rocc->attempt_connect_task_id) | 1649 | if (NULL != rocc->attempt_connect_task_id) |
1656 | GNUNET_SCHEDULER_cancel (rocc->attempt_connect_task_id); | 1650 | GNUNET_SCHEDULER_cancel(rocc->attempt_connect_task_id); |
1657 | if (NULL != rocc->timeout_rocc_task_id) | 1651 | if (NULL != rocc->timeout_rocc_task_id) |
1658 | GNUNET_SCHEDULER_cancel (rocc->timeout_rocc_task_id); | 1652 | GNUNET_SCHEDULER_cancel(rocc->timeout_rocc_task_id); |
1659 | if (NULL != rocc->ohh) | 1653 | if (NULL != rocc->ohh) |
1660 | GNUNET_TRANSPORT_offer_hello_cancel (rocc->ohh); | 1654 | GNUNET_TRANSPORT_offer_hello_cancel(rocc->ohh); |
1661 | if (NULL != rocc->tcc.csh) | 1655 | if (NULL != rocc->tcc.csh) |
1662 | GNUNET_ATS_connectivity_suggest_cancel (rocc->tcc.csh); | 1656 | GNUNET_ATS_connectivity_suggest_cancel(rocc->tcc.csh); |
1663 | GST_connection_pool_get_handle_done (rocc->tcc.cgh_p2_th); | 1657 | GST_connection_pool_get_handle_done(rocc->tcc.cgh_p2_th); |
1664 | GST_connection_pool_get_handle_done (rocc->tcc.cgh_p2_ats); | 1658 | GST_connection_pool_get_handle_done(rocc->tcc.cgh_p2_ats); |
1665 | GNUNET_assert (rocc->peer->reference_cnt > 0); | 1659 | GNUNET_assert(rocc->peer->reference_cnt > 0); |
1666 | rocc->peer->reference_cnt--; | 1660 | rocc->peer->reference_cnt--; |
1667 | if ((GNUNET_YES == rocc->peer->destroy_flag) && | 1661 | if ((GNUNET_YES == rocc->peer->destroy_flag) && |
1668 | (0 == rocc->peer->reference_cnt)) | 1662 | (0 == rocc->peer->reference_cnt)) |
1669 | GST_destroy_peer (rocc->peer); | 1663 | GST_destroy_peer(rocc->peer); |
1670 | GNUNET_free_non_null (rocc->hello); | 1664 | GNUNET_free_non_null(rocc->hello); |
1671 | GNUNET_CONTAINER_DLL_remove (roccq_head, | 1665 | GNUNET_CONTAINER_DLL_remove(roccq_head, |
1672 | roccq_tail, | 1666 | roccq_tail, |
1673 | rocc); | 1667 | rocc); |
1674 | GNUNET_free (rocc); | 1668 | GNUNET_free(rocc); |
1675 | } | 1669 | } |
1676 | 1670 | ||
1677 | 1671 | ||
@@ -1681,15 +1675,15 @@ cleanup_rocc (struct RemoteOverlayConnectCtx *rocc) | |||
1681 | * @param cls the RemoteOverlayConnectCtx | 1675 | * @param cls the RemoteOverlayConnectCtx |
1682 | */ | 1676 | */ |
1683 | static void | 1677 | static void |
1684 | timeout_rocc_task (void *cls) | 1678 | timeout_rocc_task(void *cls) |
1685 | { | 1679 | { |
1686 | struct RemoteOverlayConnectCtx *rocc = cls; | 1680 | struct RemoteOverlayConnectCtx *rocc = cls; |
1687 | 1681 | ||
1688 | GNUNET_assert (rocc->timeout_rocc_task_id != NULL); | 1682 | GNUNET_assert(rocc->timeout_rocc_task_id != NULL); |
1689 | rocc->timeout_rocc_task_id = NULL; | 1683 | rocc->timeout_rocc_task_id = NULL; |
1690 | LOG_DEBUG ("0x%llx: rocc timed out\n", | 1684 | LOG_DEBUG("0x%llx: rocc timed out\n", |
1691 | rocc->op_id); | 1685 | rocc->op_id); |
1692 | cleanup_rocc (rocc); | 1686 | cleanup_rocc(rocc); |
1693 | } | 1687 | } |
1694 | 1688 | ||
1695 | 1689 | ||
@@ -1701,20 +1695,20 @@ timeout_rocc_task (void *cls) | |||
1701 | * @param new_peer the peer that connected | 1695 | * @param new_peer the peer that connected |
1702 | */ | 1696 | */ |
1703 | static void | 1697 | static void |
1704 | cache_transport_peer_connect_notify (void *cls, | 1698 | cache_transport_peer_connect_notify(void *cls, |
1705 | const struct GNUNET_PeerIdentity *new_peer) | 1699 | const struct GNUNET_PeerIdentity *new_peer) |
1706 | { | 1700 | { |
1707 | struct RemoteOverlayConnectCtx *rocc = cls; | 1701 | struct RemoteOverlayConnectCtx *rocc = cls; |
1708 | 1702 | ||
1709 | LOG_DEBUG ("0x%llx: Request Overlay connect notify\n", | 1703 | LOG_DEBUG("0x%llx: Request Overlay connect notify\n", |
1710 | rocc->op_id); | 1704 | rocc->op_id); |
1711 | GNUNET_assert (0 == | 1705 | GNUNET_assert(0 == |
1712 | memcmp (new_peer, &rocc->a_id, | 1706 | memcmp(new_peer, &rocc->a_id, |
1713 | sizeof (struct GNUNET_PeerIdentity))); | 1707 | sizeof(struct GNUNET_PeerIdentity))); |
1714 | LOG_DEBUG ("0x%llx: Peer %s connected\n", | 1708 | LOG_DEBUG("0x%llx: Peer %s connected\n", |
1715 | rocc->op_id, | 1709 | rocc->op_id, |
1716 | GNUNET_i2s (&rocc->a_id)); | 1710 | GNUNET_i2s(&rocc->a_id)); |
1717 | cleanup_rocc (rocc); | 1711 | cleanup_rocc(rocc); |
1718 | } | 1712 | } |
1719 | 1713 | ||
1720 | 1714 | ||
@@ -1725,7 +1719,7 @@ cache_transport_peer_connect_notify (void *cls, | |||
1725 | * @param cls the RemoteOverlayConnectCtx | 1719 | * @param cls the RemoteOverlayConnectCtx |
1726 | */ | 1720 | */ |
1727 | static void | 1721 | static void |
1728 | attempt_connect_task (void *cls); | 1722 | attempt_connect_task(void *cls); |
1729 | 1723 | ||
1730 | 1724 | ||
1731 | /** | 1725 | /** |
@@ -1736,22 +1730,22 @@ attempt_connect_task (void *cls); | |||
1736 | * @param cls the overlay connect context | 1730 | * @param cls the overlay connect context |
1737 | */ | 1731 | */ |
1738 | static void | 1732 | static void |
1739 | rocc_hello_sent_cb (void *cls) | 1733 | rocc_hello_sent_cb(void *cls) |
1740 | { | 1734 | { |
1741 | struct RemoteOverlayConnectCtx *rocc = cls; | 1735 | struct RemoteOverlayConnectCtx *rocc = cls; |
1742 | 1736 | ||
1743 | rocc->ohh = NULL; | 1737 | rocc->ohh = NULL; |
1744 | GNUNET_assert (NULL == rocc->attempt_connect_task_id); | 1738 | GNUNET_assert(NULL == rocc->attempt_connect_task_id); |
1745 | LOG_DEBUG ("0x%llx: HELLO of peer %s delivered to local peer with id: %u\n", | 1739 | LOG_DEBUG("0x%llx: HELLO of peer %s delivered to local peer with id: %u\n", |
1746 | rocc->op_id, | 1740 | rocc->op_id, |
1747 | GNUNET_i2s (&rocc->a_id), | 1741 | GNUNET_i2s(&rocc->a_id), |
1748 | rocc->peer->id); | 1742 | rocc->peer->id); |
1749 | rocc->tcc.cgh_p2_ats = | 1743 | rocc->tcc.cgh_p2_ats = |
1750 | GST_connection_pool_get_handle (rocc->peer->id, | 1744 | GST_connection_pool_get_handle(rocc->peer->id, |
1751 | rocc->peer->details.local.cfg, | 1745 | rocc->peer->details.local.cfg, |
1752 | GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY, | 1746 | GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY, |
1753 | &occ_cache_get_handle_ats_rocc_cb, | 1747 | &occ_cache_get_handle_ats_rocc_cb, |
1754 | rocc, NULL, NULL, NULL); | 1748 | rocc, NULL, NULL, NULL); |
1755 | } | 1749 | } |
1756 | 1750 | ||
1757 | 1751 | ||
@@ -1762,29 +1756,29 @@ rocc_hello_sent_cb (void *cls) | |||
1762 | * @param cls the RemoteOverlayConnectCtx | 1756 | * @param cls the RemoteOverlayConnectCtx |
1763 | */ | 1757 | */ |
1764 | static void | 1758 | static void |
1765 | attempt_connect_task (void *cls) | 1759 | attempt_connect_task(void *cls) |
1766 | { | 1760 | { |
1767 | struct RemoteOverlayConnectCtx *rocc = cls; | 1761 | struct RemoteOverlayConnectCtx *rocc = cls; |
1768 | 1762 | ||
1769 | GNUNET_assert (NULL != rocc->attempt_connect_task_id); | 1763 | GNUNET_assert(NULL != rocc->attempt_connect_task_id); |
1770 | rocc->attempt_connect_task_id = NULL; | 1764 | rocc->attempt_connect_task_id = NULL; |
1771 | LOG_DEBUG ("0x%llx: Offering HELLO of peer %s to remote peer with id: %u\n", | 1765 | LOG_DEBUG("0x%llx: Offering HELLO of peer %s to remote peer with id: %u\n", |
1772 | rocc->op_id, | 1766 | rocc->op_id, |
1773 | GNUNET_i2s (&rocc->a_id), | 1767 | GNUNET_i2s(&rocc->a_id), |
1774 | rocc->peer->id); | 1768 | rocc->peer->id); |
1775 | rocc->ohh = | 1769 | rocc->ohh = |
1776 | GNUNET_TRANSPORT_offer_hello (rocc->tcc.cfg, | 1770 | GNUNET_TRANSPORT_offer_hello(rocc->tcc.cfg, |
1777 | rocc->hello, | 1771 | rocc->hello, |
1778 | &rocc_hello_sent_cb, | 1772 | &rocc_hello_sent_cb, |
1779 | rocc); | 1773 | rocc); |
1780 | if (NULL == rocc->ohh) | 1774 | if (NULL == rocc->ohh) |
1781 | rocc->attempt_connect_task_id = | 1775 | rocc->attempt_connect_task_id = |
1782 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 1776 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
1783 | (GNUNET_TIME_UNIT_MILLISECONDS, | 1777 | (GNUNET_TIME_UNIT_MILLISECONDS, |
1784 | 100 + | 1778 | 100 + |
1785 | GNUNET_CRYPTO_random_u32 | 1779 | GNUNET_CRYPTO_random_u32 |
1786 | (GNUNET_CRYPTO_QUALITY_WEAK, 500)), | 1780 | (GNUNET_CRYPTO_QUALITY_WEAK, 500)), |
1787 | &attempt_connect_task, rocc); | 1781 | &attempt_connect_task, rocc); |
1788 | } | 1782 | } |
1789 | 1783 | ||
1790 | 1784 | ||
@@ -1798,36 +1792,36 @@ attempt_connect_task (void *cls) | |||
1798 | * @param ignore_ peer identity which is ignored in this callback | 1792 | * @param ignore_ peer identity which is ignored in this callback |
1799 | */ | 1793 | */ |
1800 | static void | 1794 | static void |
1801 | rocc_cache_get_handle_transport_cb (void *cls, | 1795 | rocc_cache_get_handle_transport_cb(void *cls, |
1802 | struct GNUNET_CORE_Handle *ch, | 1796 | struct GNUNET_CORE_Handle *ch, |
1803 | struct GNUNET_TRANSPORT_CoreHandle *th, | 1797 | struct GNUNET_TRANSPORT_CoreHandle *th, |
1804 | struct GNUNET_ATS_ConnectivityHandle *ac, | 1798 | struct GNUNET_ATS_ConnectivityHandle *ac, |
1805 | const struct GNUNET_PeerIdentity *ignore_, | 1799 | const struct GNUNET_PeerIdentity *ignore_, |
1806 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1800 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1807 | { | 1801 | { |
1808 | struct RemoteOverlayConnectCtx *rocc = cls; | 1802 | struct RemoteOverlayConnectCtx *rocc = cls; |
1809 | 1803 | ||
1810 | if (NULL == th) | 1804 | if (NULL == th) |
1811 | { | 1805 | { |
1812 | rocc->timeout_rocc_task_id = | 1806 | rocc->timeout_rocc_task_id = |
1813 | GNUNET_SCHEDULER_add_now (&timeout_rocc_task, rocc); | 1807 | GNUNET_SCHEDULER_add_now(&timeout_rocc_task, rocc); |
1814 | return; | 1808 | return; |
1815 | } | 1809 | } |
1816 | rocc->tcc.th_ = th; | 1810 | rocc->tcc.th_ = th; |
1817 | rocc->tcc.cfg = cfg; | 1811 | rocc->tcc.cfg = cfg; |
1818 | if (NULL != | 1812 | if (NULL != |
1819 | GNUNET_TRANSPORT_core_get_mq (rocc->tcc.th_, | 1813 | GNUNET_TRANSPORT_core_get_mq(rocc->tcc.th_, |
1820 | &rocc->a_id)) | 1814 | &rocc->a_id)) |
1821 | { | 1815 | { |
1822 | LOG_DEBUG ("0x%llx: Target peer %s already connected to local peer: %u\n", | 1816 | LOG_DEBUG("0x%llx: Target peer %s already connected to local peer: %u\n", |
1823 | rocc->op_id, | 1817 | rocc->op_id, |
1824 | GNUNET_i2s (&rocc->a_id), | 1818 | GNUNET_i2s(&rocc->a_id), |
1825 | rocc->peer->id); | 1819 | rocc->peer->id); |
1826 | cleanup_rocc (rocc); | 1820 | cleanup_rocc(rocc); |
1827 | return; | 1821 | return; |
1828 | } | 1822 | } |
1829 | rocc->attempt_connect_task_id = | 1823 | rocc->attempt_connect_task_id = |
1830 | GNUNET_SCHEDULER_add_now (&attempt_connect_task, rocc); | 1824 | GNUNET_SCHEDULER_add_now(&attempt_connect_task, rocc); |
1831 | } | 1825 | } |
1832 | 1826 | ||
1833 | 1827 | ||
@@ -1839,32 +1833,32 @@ rocc_cache_get_handle_transport_cb (void *cls, | |||
1839 | * @return #GNUNET_OK if @a msg is well-formed | 1833 | * @return #GNUNET_OK if @a msg is well-formed |
1840 | */ | 1834 | */ |
1841 | int | 1835 | int |
1842 | check_remote_overlay_connect (void *cls, | 1836 | check_remote_overlay_connect(void *cls, |
1843 | const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg) | 1837 | const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg) |
1844 | { | 1838 | { |
1845 | uint32_t peer_id; | 1839 | uint32_t peer_id; |
1846 | uint16_t msize; | 1840 | uint16_t msize; |
1847 | uint16_t hsize; | 1841 | uint16_t hsize; |
1848 | 1842 | ||
1849 | msize = ntohs (msg->header.size); | 1843 | msize = ntohs(msg->header.size); |
1850 | if (GNUNET_MESSAGE_TYPE_HELLO != ntohs (msg->hello->type)) | 1844 | if (GNUNET_MESSAGE_TYPE_HELLO != ntohs(msg->hello->type)) |
1851 | { | 1845 | { |
1852 | GNUNET_break (0); | 1846 | GNUNET_break(0); |
1853 | return GNUNET_SYSERR; | 1847 | return GNUNET_SYSERR; |
1854 | } | 1848 | } |
1855 | hsize = ntohs (msg->hello->size); | 1849 | hsize = ntohs(msg->hello->size); |
1856 | if ((sizeof (struct GNUNET_TESTBED_RemoteOverlayConnectMessage) + hsize) != msize) | 1850 | if ((sizeof(struct GNUNET_TESTBED_RemoteOverlayConnectMessage) + hsize) != msize) |
1857 | { | 1851 | { |
1858 | GNUNET_break (0); | 1852 | GNUNET_break(0); |
1859 | return GNUNET_SYSERR; | 1853 | return GNUNET_SYSERR; |
1860 | } | 1854 | } |
1861 | peer_id = ntohl (msg->peer); | 1855 | peer_id = ntohl(msg->peer); |
1862 | if ((peer_id >= GST_peer_list_size) || | 1856 | if ((peer_id >= GST_peer_list_size) || |
1863 | (NULL == GST_peer_list[peer_id])) | 1857 | (NULL == GST_peer_list[peer_id])) |
1864 | { | 1858 | { |
1865 | GNUNET_break_op (0); | 1859 | GNUNET_break_op(0); |
1866 | return GNUNET_SYSERR; | 1860 | return GNUNET_SYSERR; |
1867 | } | 1861 | } |
1868 | return GNUNET_OK; | 1862 | return GNUNET_OK; |
1869 | } | 1863 | } |
1870 | 1864 | ||
@@ -1876,8 +1870,8 @@ check_remote_overlay_connect (void *cls, | |||
1876 | * @param msg the actual message | 1870 | * @param msg the actual message |
1877 | */ | 1871 | */ |
1878 | void | 1872 | void |
1879 | handle_remote_overlay_connect (void *cls, | 1873 | handle_remote_overlay_connect(void *cls, |
1880 | const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg) | 1874 | const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg) |
1881 | { | 1875 | { |
1882 | struct GNUNET_SERVICE_Client *client = cls; | 1876 | struct GNUNET_SERVICE_Client *client = cls; |
1883 | struct RemoteOverlayConnectCtx *rocc; | 1877 | struct RemoteOverlayConnectCtx *rocc; |
@@ -1887,55 +1881,55 @@ handle_remote_overlay_connect (void *cls, | |||
1887 | uint32_t peer_id; | 1881 | uint32_t peer_id; |
1888 | uint16_t hsize; | 1882 | uint16_t hsize; |
1889 | 1883 | ||
1890 | hsize = ntohs (msg->hello->size); | 1884 | hsize = ntohs(msg->hello->size); |
1891 | peer_id = ntohl (msg->peer); | 1885 | peer_id = ntohl(msg->peer); |
1892 | peer = GST_peer_list[peer_id]; | 1886 | peer = GST_peer_list[peer_id]; |
1893 | if (GNUNET_YES == peer->is_remote) | 1887 | if (GNUNET_YES == peer->is_remote) |
1894 | { | 1888 | { |
1895 | struct GNUNET_MessageHeader *msg2; | 1889 | struct GNUNET_MessageHeader *msg2; |
1896 | 1890 | ||
1897 | msg2 = GNUNET_copy_message (&msg->header); | 1891 | msg2 = GNUNET_copy_message(&msg->header); |
1898 | GNUNET_TESTBED_queue_message_ (peer->details.remote.slave->controller, | 1892 | GNUNET_TESTBED_queue_message_(peer->details.remote.slave->controller, |
1899 | msg2); | 1893 | msg2); |
1900 | GNUNET_SERVICE_client_continue (client); | 1894 | GNUNET_SERVICE_client_continue(client); |
1901 | return; | 1895 | return; |
1902 | } | 1896 | } |
1903 | rocc = GNUNET_new (struct RemoteOverlayConnectCtx); | 1897 | rocc = GNUNET_new(struct RemoteOverlayConnectCtx); |
1904 | rocc->op_id = GNUNET_ntohll (msg->operation_id); | 1898 | rocc->op_id = GNUNET_ntohll(msg->operation_id); |
1905 | GNUNET_CONTAINER_DLL_insert_tail (roccq_head, | 1899 | GNUNET_CONTAINER_DLL_insert_tail(roccq_head, |
1906 | roccq_tail, | 1900 | roccq_tail, |
1907 | rocc); | 1901 | rocc); |
1908 | rocc->a_id = msg->peer_identity; | 1902 | rocc->a_id = msg->peer_identity; |
1909 | GNUNET_TESTING_peer_get_identity (peer->details.local.peer, | 1903 | GNUNET_TESTING_peer_get_identity(peer->details.local.peer, |
1910 | &pid); | 1904 | &pid); |
1911 | (void) GNUNET_strlcpy (pid_str, | 1905 | (void)GNUNET_strlcpy(pid_str, |
1912 | GNUNET_i2s (&pid), | 1906 | GNUNET_i2s(&pid), |
1913 | sizeof (pid_str)); | 1907 | sizeof(pid_str)); |
1914 | LOG_DEBUG ("0x%llx: Remote overlay connect %s to peer %s with hello size: %u\n", | 1908 | LOG_DEBUG("0x%llx: Remote overlay connect %s to peer %s with hello size: %u\n", |
1915 | rocc->op_id, | 1909 | rocc->op_id, |
1916 | pid_str, | 1910 | pid_str, |
1917 | GNUNET_i2s (&rocc->a_id), | 1911 | GNUNET_i2s(&rocc->a_id), |
1918 | hsize); | 1912 | hsize); |
1919 | rocc->peer = peer; | 1913 | rocc->peer = peer; |
1920 | rocc->peer->reference_cnt++; | 1914 | rocc->peer->reference_cnt++; |
1921 | rocc->hello = GNUNET_malloc (hsize); | 1915 | rocc->hello = GNUNET_malloc(hsize); |
1922 | GNUNET_memcpy (rocc->hello, | 1916 | GNUNET_memcpy(rocc->hello, |
1923 | msg->hello, | 1917 | msg->hello, |
1924 | hsize); | 1918 | hsize); |
1925 | rocc->tcc.cgh_p2_th = | 1919 | rocc->tcc.cgh_p2_th = |
1926 | GST_connection_pool_get_handle (peer_id, | 1920 | GST_connection_pool_get_handle(peer_id, |
1927 | rocc->peer->details.local.cfg, | 1921 | rocc->peer->details.local.cfg, |
1928 | GST_CONNECTIONPOOL_SERVICE_TRANSPORT, | 1922 | GST_CONNECTIONPOOL_SERVICE_TRANSPORT, |
1929 | &rocc_cache_get_handle_transport_cb, | 1923 | &rocc_cache_get_handle_transport_cb, |
1930 | rocc, | 1924 | rocc, |
1931 | &rocc->a_id, | 1925 | &rocc->a_id, |
1932 | &cache_transport_peer_connect_notify, | 1926 | &cache_transport_peer_connect_notify, |
1933 | rocc); | 1927 | rocc); |
1934 | rocc->timeout_rocc_task_id = | 1928 | rocc->timeout_rocc_task_id = |
1935 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 1929 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
1936 | &timeout_rocc_task, | 1930 | &timeout_rocc_task, |
1937 | rocc); | 1931 | rocc); |
1938 | GNUNET_SERVICE_client_continue (client); | 1932 | GNUNET_SERVICE_client_continue(client); |
1939 | } | 1933 | } |
1940 | 1934 | ||
1941 | 1935 | ||
@@ -1943,12 +1937,12 @@ handle_remote_overlay_connect (void *cls, | |||
1943 | * Clears all pending overlay connect contexts in queue | 1937 | * Clears all pending overlay connect contexts in queue |
1944 | */ | 1938 | */ |
1945 | void | 1939 | void |
1946 | GST_free_occq () | 1940 | GST_free_occq() |
1947 | { | 1941 | { |
1948 | struct OverlayConnectContext *occ; | 1942 | struct OverlayConnectContext *occ; |
1949 | 1943 | ||
1950 | while (NULL != (occ = occq_head)) | 1944 | while (NULL != (occ = occq_head)) |
1951 | cleanup_occ (occ); | 1945 | cleanup_occ(occ); |
1952 | } | 1946 | } |
1953 | 1947 | ||
1954 | 1948 | ||
@@ -1956,10 +1950,10 @@ GST_free_occq () | |||
1956 | * Clears all pending remote overlay connect contexts in queue | 1950 | * Clears all pending remote overlay connect contexts in queue |
1957 | */ | 1951 | */ |
1958 | void | 1952 | void |
1959 | GST_free_roccq () | 1953 | GST_free_roccq() |
1960 | { | 1954 | { |
1961 | struct RemoteOverlayConnectCtx *rocc; | 1955 | struct RemoteOverlayConnectCtx *rocc; |
1962 | 1956 | ||
1963 | while (NULL != (rocc = roccq_head)) | 1957 | while (NULL != (rocc = roccq_head)) |
1964 | cleanup_rocc (rocc); | 1958 | cleanup_rocc(rocc); |
1965 | } | 1959 | } |
diff --git a/src/testbed/gnunet-service-testbed_peers.c b/src/testbed/gnunet-service-testbed_peers.c index b88812e7e..743c7e849 100644 --- a/src/testbed/gnunet-service-testbed_peers.c +++ b/src/testbed/gnunet-service-testbed_peers.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2013, 2016 GNUnet e.V. | 3 | Copyright (C) 2008--2013, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | 21 | ||
22 | /** | 22 | /** |
@@ -44,8 +44,7 @@ unsigned int GST_num_local_peers; | |||
44 | /** | 44 | /** |
45 | * Context information to manage peers' services | 45 | * Context information to manage peers' services |
46 | */ | 46 | */ |
47 | struct ManageServiceContext | 47 | struct ManageServiceContext { |
48 | { | ||
49 | /** | 48 | /** |
50 | * DLL next ptr | 49 | * DLL next ptr |
51 | */ | 50 | */ |
@@ -97,8 +96,7 @@ struct ManageServiceContext | |||
97 | /** | 96 | /** |
98 | * Context information for peer re-configure operations | 97 | * Context information for peer re-configure operations |
99 | */ | 98 | */ |
100 | struct PeerReconfigureContext | 99 | struct PeerReconfigureContext { |
101 | { | ||
102 | /** | 100 | /** |
103 | * DLL next for inclusoin in peer reconfigure operations list | 101 | * DLL next for inclusoin in peer reconfigure operations list |
104 | */ | 102 | */ |
@@ -166,11 +164,11 @@ static struct ManageServiceContext *mctx_tail; | |||
166 | * @param peer the peer to add | 164 | * @param peer the peer to add |
167 | */ | 165 | */ |
168 | static void | 166 | static void |
169 | peer_list_add (struct Peer *peer) | 167 | peer_list_add(struct Peer *peer) |
170 | { | 168 | { |
171 | if (peer->id >= GST_peer_list_size) | 169 | if (peer->id >= GST_peer_list_size) |
172 | GST_array_grow_large_enough (GST_peer_list, GST_peer_list_size, peer->id); | 170 | GST_array_grow_large_enough(GST_peer_list, GST_peer_list_size, peer->id); |
173 | GNUNET_assert (NULL == GST_peer_list[peer->id]); | 171 | GNUNET_assert(NULL == GST_peer_list[peer->id]); |
174 | GST_peer_list[peer->id] = peer; | 172 | GST_peer_list[peer->id] = peer; |
175 | if (GNUNET_NO == peer->is_remote) | 173 | if (GNUNET_NO == peer->is_remote) |
176 | GST_num_local_peers++; | 174 | GST_num_local_peers++; |
@@ -183,7 +181,7 @@ peer_list_add (struct Peer *peer) | |||
183 | * @param peer the peer to be removed | 181 | * @param peer the peer to be removed |
184 | */ | 182 | */ |
185 | static void | 183 | static void |
186 | peer_list_remove (struct Peer *peer) | 184 | peer_list_remove(struct Peer *peer) |
187 | { | 185 | { |
188 | unsigned int orig_size; | 186 | unsigned int orig_size; |
189 | uint32_t id; | 187 | uint32_t id; |
@@ -193,21 +191,21 @@ peer_list_remove (struct Peer *peer) | |||
193 | GST_peer_list[peer->id] = NULL; | 191 | GST_peer_list[peer->id] = NULL; |
194 | orig_size = GST_peer_list_size; | 192 | orig_size = GST_peer_list_size; |
195 | while (GST_peer_list_size >= LIST_GROW_STEP) | 193 | while (GST_peer_list_size >= LIST_GROW_STEP) |
196 | { | 194 | { |
197 | for (id = GST_peer_list_size - 1; | 195 | for (id = GST_peer_list_size - 1; |
198 | (id >= GST_peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX); | 196 | (id >= GST_peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX); |
199 | id--) | 197 | id--) |
200 | if (NULL != GST_peer_list[id]) | 198 | if (NULL != GST_peer_list[id]) |
199 | break; | ||
200 | if (id != ((GST_peer_list_size - LIST_GROW_STEP) - 1)) | ||
201 | break; | 201 | break; |
202 | if (id != ((GST_peer_list_size - LIST_GROW_STEP) - 1)) | 202 | GST_peer_list_size -= LIST_GROW_STEP; |
203 | break; | 203 | } |
204 | GST_peer_list_size -= LIST_GROW_STEP; | ||
205 | } | ||
206 | if (orig_size == GST_peer_list_size) | 204 | if (orig_size == GST_peer_list_size) |
207 | return; | 205 | return; |
208 | GST_peer_list = | 206 | GST_peer_list = |
209 | GNUNET_realloc (GST_peer_list, | 207 | GNUNET_realloc(GST_peer_list, |
210 | sizeof (struct Peer *) * GST_peer_list_size); | 208 | sizeof(struct Peer *) * GST_peer_list_size); |
211 | } | 209 | } |
212 | 210 | ||
213 | 211 | ||
@@ -218,12 +216,12 @@ peer_list_remove (struct Peer *peer) | |||
218 | * @param cls the FowardedOperationContext | 216 | * @param cls the FowardedOperationContext |
219 | */ | 217 | */ |
220 | static void | 218 | static void |
221 | peer_create_forward_timeout (void *cls) | 219 | peer_create_forward_timeout(void *cls) |
222 | { | 220 | { |
223 | struct ForwardedOperationContext *fopc = cls; | 221 | struct ForwardedOperationContext *fopc = cls; |
224 | 222 | ||
225 | GNUNET_free (fopc->cls); | 223 | GNUNET_free(fopc->cls); |
226 | GST_forwarded_operation_timeout (fopc); | 224 | GST_forwarded_operation_timeout(fopc); |
227 | } | 225 | } |
228 | 226 | ||
229 | 227 | ||
@@ -235,19 +233,19 @@ peer_create_forward_timeout (void *cls) | |||
235 | * @param msg the peer create success message | 233 | * @param msg the peer create success message |
236 | */ | 234 | */ |
237 | static void | 235 | static void |
238 | peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg) | 236 | peer_create_success_cb(void *cls, const struct GNUNET_MessageHeader *msg) |
239 | { | 237 | { |
240 | struct ForwardedOperationContext *fopc = cls; | 238 | struct ForwardedOperationContext *fopc = cls; |
241 | struct Peer *remote_peer; | 239 | struct Peer *remote_peer; |
242 | 240 | ||
243 | if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS) | 241 | if (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS) |
244 | { | 242 | { |
245 | GNUNET_assert (NULL != fopc->cls); | 243 | GNUNET_assert(NULL != fopc->cls); |
246 | remote_peer = fopc->cls; | 244 | remote_peer = fopc->cls; |
247 | peer_list_add (remote_peer); | 245 | peer_list_add(remote_peer); |
248 | } | 246 | } |
249 | GST_forwarded_operation_reply_relay (fopc, | 247 | GST_forwarded_operation_reply_relay(fopc, |
250 | msg); | 248 | msg); |
251 | } | 249 | } |
252 | 250 | ||
253 | 251 | ||
@@ -257,24 +255,24 @@ peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg) | |||
257 | * @param peer the peer structure to destroy | 255 | * @param peer the peer structure to destroy |
258 | */ | 256 | */ |
259 | void | 257 | void |
260 | GST_destroy_peer (struct Peer *peer) | 258 | GST_destroy_peer(struct Peer *peer) |
261 | { | 259 | { |
262 | GNUNET_break (0 == peer->reference_cnt); | 260 | GNUNET_break(0 == peer->reference_cnt); |
263 | if (GNUNET_YES == peer->is_remote) | 261 | if (GNUNET_YES == peer->is_remote) |
264 | { | 262 | { |
265 | peer_list_remove (peer); | 263 | peer_list_remove(peer); |
266 | GNUNET_free (peer); | 264 | GNUNET_free(peer); |
267 | return; | 265 | return; |
268 | } | 266 | } |
269 | if (GNUNET_YES == peer->details.local.is_running) | 267 | if (GNUNET_YES == peer->details.local.is_running) |
270 | { | 268 | { |
271 | GNUNET_TESTING_peer_stop (peer->details.local.peer); | 269 | GNUNET_TESTING_peer_stop(peer->details.local.peer); |
272 | peer->details.local.is_running = GNUNET_NO; | 270 | peer->details.local.is_running = GNUNET_NO; |
273 | } | 271 | } |
274 | GNUNET_TESTING_peer_destroy (peer->details.local.peer); | 272 | GNUNET_TESTING_peer_destroy(peer->details.local.peer); |
275 | GNUNET_CONFIGURATION_destroy (peer->details.local.cfg); | 273 | GNUNET_CONFIGURATION_destroy(peer->details.local.cfg); |
276 | peer_list_remove (peer); | 274 | peer_list_remove(peer); |
277 | GNUNET_free (peer); | 275 | GNUNET_free(peer); |
278 | } | 276 | } |
279 | 277 | ||
280 | 278 | ||
@@ -284,20 +282,20 @@ GST_destroy_peer (struct Peer *peer) | |||
284 | * @param mctx the ManageServiceContext | 282 | * @param mctx the ManageServiceContext |
285 | */ | 283 | */ |
286 | static void | 284 | static void |
287 | cleanup_mctx (struct ManageServiceContext *mctx) | 285 | cleanup_mctx(struct ManageServiceContext *mctx) |
288 | { | 286 | { |
289 | mctx->expired = GNUNET_YES; | 287 | mctx->expired = GNUNET_YES; |
290 | GNUNET_CONTAINER_DLL_remove (mctx_head, | 288 | GNUNET_CONTAINER_DLL_remove(mctx_head, |
291 | mctx_tail, | 289 | mctx_tail, |
292 | mctx); | 290 | mctx); |
293 | GNUNET_ARM_disconnect (mctx->ah); | 291 | GNUNET_ARM_disconnect(mctx->ah); |
294 | GNUNET_assert (0 < mctx->peer->reference_cnt); | 292 | GNUNET_assert(0 < mctx->peer->reference_cnt); |
295 | mctx->peer->reference_cnt--; | 293 | mctx->peer->reference_cnt--; |
296 | if ( (GNUNET_YES == mctx->peer->destroy_flag) && | 294 | if ((GNUNET_YES == mctx->peer->destroy_flag) && |
297 | (0 == mctx->peer->reference_cnt) ) | 295 | (0 == mctx->peer->reference_cnt)) |
298 | GST_destroy_peer (mctx->peer); | 296 | GST_destroy_peer(mctx->peer); |
299 | GNUNET_free (mctx->service); | 297 | GNUNET_free(mctx->service); |
300 | GNUNET_free (mctx); | 298 | GNUNET_free(mctx); |
301 | } | 299 | } |
302 | 300 | ||
303 | 301 | ||
@@ -308,10 +306,10 @@ cleanup_mctx (struct ManageServiceContext *mctx) | |||
308 | * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure | 306 | * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure |
309 | */ | 307 | */ |
310 | static int | 308 | static int |
311 | stop_peer (struct Peer *peer) | 309 | stop_peer(struct Peer *peer) |
312 | { | 310 | { |
313 | GNUNET_assert (GNUNET_NO == peer->is_remote); | 311 | GNUNET_assert(GNUNET_NO == peer->is_remote); |
314 | if (GNUNET_OK != GNUNET_TESTING_peer_kill (peer->details.local.peer)) | 312 | if (GNUNET_OK != GNUNET_TESTING_peer_kill(peer->details.local.peer)) |
315 | return GNUNET_SYSERR; | 313 | return GNUNET_SYSERR; |
316 | peer->details.local.is_running = GNUNET_NO; | 314 | peer->details.local.is_running = GNUNET_NO; |
317 | return GNUNET_OK; | 315 | return GNUNET_OK; |
@@ -324,25 +322,25 @@ stop_peer (struct Peer *peer) | |||
324 | * @param prc the PeerReconfigureContext | 322 | * @param prc the PeerReconfigureContext |
325 | */ | 323 | */ |
326 | static void | 324 | static void |
327 | cleanup_prc (struct PeerReconfigureContext *prc) | 325 | cleanup_prc(struct PeerReconfigureContext *prc) |
328 | { | 326 | { |
329 | struct Peer *peer; | 327 | struct Peer *peer; |
330 | 328 | ||
331 | if (VALID_PEER_ID (prc->peer_id)) | 329 | if (VALID_PEER_ID(prc->peer_id)) |
332 | { | ||
333 | peer = GST_peer_list [prc->peer_id]; | ||
334 | if (1 != prc->stopped) | ||
335 | { | 330 | { |
336 | GNUNET_TESTING_peer_stop_async_cancel (peer->details.local.peer); | 331 | peer = GST_peer_list [prc->peer_id]; |
337 | stop_peer (peer); /* Stop the peer synchronously */ | 332 | if (1 != prc->stopped) |
333 | { | ||
334 | GNUNET_TESTING_peer_stop_async_cancel(peer->details.local.peer); | ||
335 | stop_peer(peer); /* Stop the peer synchronously */ | ||
336 | } | ||
338 | } | 337 | } |
339 | } | ||
340 | if (NULL != prc->cfg) | 338 | if (NULL != prc->cfg) |
341 | GNUNET_CONFIGURATION_destroy (prc->cfg); | 339 | GNUNET_CONFIGURATION_destroy(prc->cfg); |
342 | GNUNET_CONTAINER_DLL_remove (prc_head, | 340 | GNUNET_CONTAINER_DLL_remove(prc_head, |
343 | prc_tail, | 341 | prc_tail, |
344 | prc); | 342 | prc); |
345 | GNUNET_free (prc); | 343 | GNUNET_free(prc); |
346 | } | 344 | } |
347 | 345 | ||
348 | 346 | ||
@@ -352,7 +350,7 @@ cleanup_prc (struct PeerReconfigureContext *prc) | |||
352 | * @param client the client that disconnected | 350 | * @param client the client that disconnected |
353 | */ | 351 | */ |
354 | void | 352 | void |
355 | GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client) | 353 | GST_notify_client_disconnect_peers(struct GNUNET_SERVICE_Client *client) |
356 | { | 354 | { |
357 | struct ForwardedOperationContext *fopc; | 355 | struct ForwardedOperationContext *fopc; |
358 | struct ForwardedOperationContext *fopcn; | 356 | struct ForwardedOperationContext *fopcn; |
@@ -362,28 +360,28 @@ GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client) | |||
362 | struct PeerReconfigureContext *prcn; | 360 | struct PeerReconfigureContext *prcn; |
363 | 361 | ||
364 | for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) | 362 | for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) |
365 | { | ||
366 | fopcn = fopc->next; | ||
367 | if (client == fopc->client) | ||
368 | { | 363 | { |
369 | if (OP_PEER_CREATE == fopc->type) | 364 | fopcn = fopc->next; |
370 | GNUNET_free (fopc->cls); | 365 | if (client == fopc->client) |
371 | GNUNET_SCHEDULER_cancel (fopc->timeout_task); | 366 | { |
372 | GST_forwarded_operation_timeout (fopc); | 367 | if (OP_PEER_CREATE == fopc->type) |
368 | GNUNET_free(fopc->cls); | ||
369 | GNUNET_SCHEDULER_cancel(fopc->timeout_task); | ||
370 | GST_forwarded_operation_timeout(fopc); | ||
371 | } | ||
373 | } | 372 | } |
374 | } | ||
375 | for (mctx = mctx_head; NULL != mctx; mctx = mctxn) | 373 | for (mctx = mctx_head; NULL != mctx; mctx = mctxn) |
376 | { | 374 | { |
377 | mctxn = mctx->next; | 375 | mctxn = mctx->next; |
378 | if (client == mctx->client) | 376 | if (client == mctx->client) |
379 | cleanup_mctx (mctx); | 377 | cleanup_mctx(mctx); |
380 | } | 378 | } |
381 | for (prc = prc_head; NULL != prc; prc = prcn) | 379 | for (prc = prc_head; NULL != prc; prc = prcn) |
382 | { | 380 | { |
383 | prcn = prc->next; | 381 | prcn = prc->next; |
384 | if (client == prc->client) | 382 | if (client == prc->client) |
385 | cleanup_prc (prc); | 383 | cleanup_prc(prc); |
386 | } | 384 | } |
387 | } | 385 | } |
388 | 386 | ||
389 | 387 | ||
@@ -395,22 +393,22 @@ GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client) | |||
395 | * @param msg the peer create success message | 393 | * @param msg the peer create success message |
396 | */ | 394 | */ |
397 | static void | 395 | static void |
398 | peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg) | 396 | peer_destroy_success_cb(void *cls, const struct GNUNET_MessageHeader *msg) |
399 | { | 397 | { |
400 | struct ForwardedOperationContext *fopc = cls; | 398 | struct ForwardedOperationContext *fopc = cls; |
401 | struct Peer *remote_peer; | 399 | struct Peer *remote_peer; |
402 | 400 | ||
403 | if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS == | 401 | if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS == |
404 | ntohs (msg->type)) | 402 | ntohs(msg->type)) |
405 | { | 403 | { |
406 | remote_peer = fopc->cls; | 404 | remote_peer = fopc->cls; |
407 | GNUNET_assert (NULL != remote_peer); | 405 | GNUNET_assert(NULL != remote_peer); |
408 | remote_peer->destroy_flag = GNUNET_YES; | 406 | remote_peer->destroy_flag = GNUNET_YES; |
409 | if (0 == remote_peer->reference_cnt) | 407 | if (0 == remote_peer->reference_cnt) |
410 | GST_destroy_peer (remote_peer); | 408 | GST_destroy_peer(remote_peer); |
411 | } | 409 | } |
412 | GST_forwarded_operation_reply_relay (fopc, | 410 | GST_forwarded_operation_reply_relay(fopc, |
413 | msg); | 411 | msg); |
414 | } | 412 | } |
415 | 413 | ||
416 | 414 | ||
@@ -422,8 +420,8 @@ peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg) | |||
422 | * @return #GNUNET_OK if @a msg is well-formed | 420 | * @return #GNUNET_OK if @a msg is well-formed |
423 | */ | 421 | */ |
424 | int | 422 | int |
425 | check_peer_create (void *cls, | 423 | check_peer_create(void *cls, |
426 | const struct GNUNET_TESTBED_PeerCreateMessage *msg) | 424 | const struct GNUNET_TESTBED_PeerCreateMessage *msg) |
427 | { | 425 | { |
428 | return GNUNET_OK; /* checked later */ | 426 | return GNUNET_OK; /* checked later */ |
429 | } | 427 | } |
@@ -436,8 +434,8 @@ check_peer_create (void *cls, | |||
436 | * @param msg the actual message | 434 | * @param msg the actual message |
437 | */ | 435 | */ |
438 | void | 436 | void |
439 | handle_peer_create (void *cls, | 437 | handle_peer_create(void *cls, |
440 | const struct GNUNET_TESTBED_PeerCreateMessage *msg) | 438 | const struct GNUNET_TESTBED_PeerCreateMessage *msg) |
441 | { | 439 | { |
442 | struct GNUNET_SERVICE_Client *client = cls; | 440 | struct GNUNET_SERVICE_Client *client = cls; |
443 | struct GNUNET_MQ_Envelope *env; | 441 | struct GNUNET_MQ_Envelope *env; |
@@ -450,114 +448,114 @@ handle_peer_create (void *cls, | |||
450 | uint32_t host_id; | 448 | uint32_t host_id; |
451 | uint32_t peer_id; | 449 | uint32_t peer_id; |
452 | 450 | ||
453 | host_id = ntohl (msg->host_id); | 451 | host_id = ntohl(msg->host_id); |
454 | peer_id = ntohl (msg->peer_id); | 452 | peer_id = ntohl(msg->peer_id); |
455 | if (VALID_PEER_ID (peer_id)) | 453 | if (VALID_PEER_ID(peer_id)) |
456 | { | 454 | { |
457 | (void) GNUNET_asprintf (&emsg, | 455 | (void)GNUNET_asprintf(&emsg, |
458 | "Peer with ID %u already exists", | 456 | "Peer with ID %u already exists", |
459 | peer_id); | 457 | peer_id); |
460 | GST_send_operation_fail_msg (client, | 458 | GST_send_operation_fail_msg(client, |
461 | GNUNET_ntohll (msg->operation_id), | 459 | GNUNET_ntohll(msg->operation_id), |
462 | emsg); | 460 | emsg); |
463 | GNUNET_free (emsg); | 461 | GNUNET_free(emsg); |
464 | GNUNET_SERVICE_client_continue (client); | 462 | GNUNET_SERVICE_client_continue(client); |
465 | return; | 463 | return; |
466 | } | 464 | } |
467 | if (UINT32_MAX == peer_id) | 465 | if (UINT32_MAX == peer_id) |
468 | { | ||
469 | GST_send_operation_fail_msg (client, | ||
470 | GNUNET_ntohll (msg->operation_id), | ||
471 | "Cannot create peer with given ID"); | ||
472 | GNUNET_SERVICE_client_continue (client); | ||
473 | return; | ||
474 | } | ||
475 | if (host_id == GST_context->host_id) | ||
476 | { | ||
477 | /* We are responsible for this peer */ | ||
478 | cfg = GNUNET_TESTBED_extract_config_ (&msg->header); | ||
479 | if (NULL == cfg) | ||
480 | { | 466 | { |
481 | GNUNET_break (0); | 467 | GST_send_operation_fail_msg(client, |
482 | GNUNET_SERVICE_client_drop (client); | 468 | GNUNET_ntohll(msg->operation_id), |
469 | "Cannot create peer with given ID"); | ||
470 | GNUNET_SERVICE_client_continue(client); | ||
483 | return; | 471 | return; |
484 | } | 472 | } |
485 | GNUNET_CONFIGURATION_set_value_number (cfg, | 473 | if (host_id == GST_context->host_id) |
486 | "TESTBED", | ||
487 | "PEERID", | ||
488 | (unsigned long long) peer_id); | ||
489 | |||
490 | GNUNET_CONFIGURATION_set_value_number (cfg, | ||
491 | "PATHS", | ||
492 | "PEERID", | ||
493 | (unsigned long long) peer_id); | ||
494 | peer = GNUNET_new (struct Peer); | ||
495 | peer->is_remote = GNUNET_NO; | ||
496 | peer->details.local.cfg = cfg; | ||
497 | peer->id = peer_id; | ||
498 | LOG_DEBUG ("Creating peer with id: %u\n", | ||
499 | (unsigned int) peer->id); | ||
500 | peer->details.local.peer = | ||
501 | GNUNET_TESTING_peer_configure (GST_context->system, | ||
502 | peer->details.local.cfg, peer->id, | ||
503 | NULL /* Peer id */ , | ||
504 | &emsg); | ||
505 | if (NULL == peer->details.local.peer) | ||
506 | { | 474 | { |
507 | LOG (GNUNET_ERROR_TYPE_WARNING, | 475 | /* We are responsible for this peer */ |
508 | "Configuring peer failed: %s\n", | 476 | cfg = GNUNET_TESTBED_extract_config_(&msg->header); |
509 | emsg); | 477 | if (NULL == cfg) |
510 | GNUNET_free (emsg); | 478 | { |
511 | GNUNET_free (peer); | 479 | GNUNET_break(0); |
512 | GNUNET_break (0); | 480 | GNUNET_SERVICE_client_drop(client); |
513 | GNUNET_SERVICE_client_drop (client); | 481 | return; |
482 | } | ||
483 | GNUNET_CONFIGURATION_set_value_number(cfg, | ||
484 | "TESTBED", | ||
485 | "PEERID", | ||
486 | (unsigned long long)peer_id); | ||
487 | |||
488 | GNUNET_CONFIGURATION_set_value_number(cfg, | ||
489 | "PATHS", | ||
490 | "PEERID", | ||
491 | (unsigned long long)peer_id); | ||
492 | peer = GNUNET_new(struct Peer); | ||
493 | peer->is_remote = GNUNET_NO; | ||
494 | peer->details.local.cfg = cfg; | ||
495 | peer->id = peer_id; | ||
496 | LOG_DEBUG("Creating peer with id: %u\n", | ||
497 | (unsigned int)peer->id); | ||
498 | peer->details.local.peer = | ||
499 | GNUNET_TESTING_peer_configure(GST_context->system, | ||
500 | peer->details.local.cfg, peer->id, | ||
501 | NULL /* Peer id */, | ||
502 | &emsg); | ||
503 | if (NULL == peer->details.local.peer) | ||
504 | { | ||
505 | LOG(GNUNET_ERROR_TYPE_WARNING, | ||
506 | "Configuring peer failed: %s\n", | ||
507 | emsg); | ||
508 | GNUNET_free(emsg); | ||
509 | GNUNET_free(peer); | ||
510 | GNUNET_break(0); | ||
511 | GNUNET_SERVICE_client_drop(client); | ||
512 | return; | ||
513 | } | ||
514 | peer->details.local.is_running = GNUNET_NO; | ||
515 | peer_list_add(peer); | ||
516 | env = GNUNET_MQ_msg(reply, | ||
517 | GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS); | ||
518 | reply->peer_id = msg->peer_id; | ||
519 | reply->operation_id = msg->operation_id; | ||
520 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), | ||
521 | env); | ||
522 | GNUNET_SERVICE_client_continue(client); | ||
514 | return; | 523 | return; |
515 | } | 524 | } |
516 | peer->details.local.is_running = GNUNET_NO; | ||
517 | peer_list_add (peer); | ||
518 | env = GNUNET_MQ_msg (reply, | ||
519 | GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS); | ||
520 | reply->peer_id = msg->peer_id; | ||
521 | reply->operation_id = msg->operation_id; | ||
522 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | ||
523 | env); | ||
524 | GNUNET_SERVICE_client_continue (client); | ||
525 | return; | ||
526 | } | ||
527 | 525 | ||
528 | /* Forward peer create request */ | 526 | /* Forward peer create request */ |
529 | route = GST_find_dest_route (host_id); | 527 | route = GST_find_dest_route(host_id); |
530 | if (NULL == route) | 528 | if (NULL == route) |
531 | { | 529 | { |
532 | GNUNET_break (0); | 530 | GNUNET_break(0); |
533 | GNUNET_SERVICE_client_continue (client); // ? | 531 | GNUNET_SERVICE_client_continue(client); // ? |
534 | return; | 532 | return; |
535 | } | 533 | } |
536 | peer = GNUNET_new (struct Peer); | 534 | peer = GNUNET_new(struct Peer); |
537 | peer->is_remote = GNUNET_YES; | 535 | peer->is_remote = GNUNET_YES; |
538 | peer->id = peer_id; | 536 | peer->id = peer_id; |
539 | peer->details.remote.slave = GST_slave_list[route->dest]; | 537 | peer->details.remote.slave = GST_slave_list[route->dest]; |
540 | peer->details.remote.remote_host_id = host_id; | 538 | peer->details.remote.remote_host_id = host_id; |
541 | fo_ctxt = GNUNET_new (struct ForwardedOperationContext); | 539 | fo_ctxt = GNUNET_new(struct ForwardedOperationContext); |
542 | fo_ctxt->client = client; | 540 | fo_ctxt->client = client; |
543 | fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id); | 541 | fo_ctxt->operation_id = GNUNET_ntohll(msg->operation_id); |
544 | fo_ctxt->cls = peer; | 542 | fo_ctxt->cls = peer; |
545 | fo_ctxt->type = OP_PEER_CREATE; | 543 | fo_ctxt->type = OP_PEER_CREATE; |
546 | fo_ctxt->opc = | 544 | fo_ctxt->opc = |
547 | GNUNET_TESTBED_forward_operation_msg_ (GST_slave_list | 545 | GNUNET_TESTBED_forward_operation_msg_(GST_slave_list |
548 | [route->dest]->controller, | 546 | [route->dest]->controller, |
549 | fo_ctxt->operation_id, | 547 | fo_ctxt->operation_id, |
550 | &msg->header, | 548 | &msg->header, |
551 | &peer_create_success_cb, | 549 | &peer_create_success_cb, |
552 | fo_ctxt); | 550 | fo_ctxt); |
553 | fo_ctxt->timeout_task = | 551 | fo_ctxt->timeout_task = |
554 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 552 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
555 | &peer_create_forward_timeout, | 553 | &peer_create_forward_timeout, |
556 | fo_ctxt); | 554 | fo_ctxt); |
557 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 555 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
558 | fopcq_tail, | 556 | fopcq_tail, |
559 | fo_ctxt); | 557 | fo_ctxt); |
560 | GNUNET_SERVICE_client_continue (client); | 558 | GNUNET_SERVICE_client_continue(client); |
561 | } | 559 | } |
562 | 560 | ||
563 | 561 | ||
@@ -568,63 +566,63 @@ handle_peer_create (void *cls, | |||
568 | * @param msg the actual message | 566 | * @param msg the actual message |
569 | */ | 567 | */ |
570 | void | 568 | void |
571 | handle_peer_destroy (void *cls, | 569 | handle_peer_destroy(void *cls, |
572 | const struct GNUNET_TESTBED_PeerDestroyMessage *msg) | 570 | const struct GNUNET_TESTBED_PeerDestroyMessage *msg) |
573 | { | 571 | { |
574 | struct GNUNET_SERVICE_Client *client = cls; | 572 | struct GNUNET_SERVICE_Client *client = cls; |
575 | struct ForwardedOperationContext *fopc; | 573 | struct ForwardedOperationContext *fopc; |
576 | struct Peer *peer; | 574 | struct Peer *peer; |
577 | uint32_t peer_id; | 575 | uint32_t peer_id; |
578 | 576 | ||
579 | peer_id = ntohl (msg->peer_id); | 577 | peer_id = ntohl(msg->peer_id); |
580 | LOG_DEBUG ("Received peer destory on peer: %u and operation id: %llu\n", | 578 | LOG_DEBUG("Received peer destory on peer: %u and operation id: %llu\n", |
581 | (unsigned int) peer_id, | 579 | (unsigned int)peer_id, |
582 | (unsigned long long) GNUNET_ntohll (msg->operation_id)); | 580 | (unsigned long long)GNUNET_ntohll(msg->operation_id)); |
583 | if (!VALID_PEER_ID (peer_id)) | 581 | if (!VALID_PEER_ID(peer_id)) |
584 | { | 582 | { |
585 | LOG (GNUNET_ERROR_TYPE_ERROR, | 583 | LOG(GNUNET_ERROR_TYPE_ERROR, |
586 | "Asked to destroy a non existent peer with id: %u\n", peer_id); | 584 | "Asked to destroy a non existent peer with id: %u\n", peer_id); |
587 | GST_send_operation_fail_msg (client, | 585 | GST_send_operation_fail_msg(client, |
588 | GNUNET_ntohll (msg->operation_id), | 586 | GNUNET_ntohll(msg->operation_id), |
589 | "Peer doesn't exist"); | 587 | "Peer doesn't exist"); |
590 | GNUNET_SERVICE_client_continue (client); | 588 | GNUNET_SERVICE_client_continue(client); |
591 | return; | 589 | return; |
592 | } | 590 | } |
593 | peer = GST_peer_list[peer_id]; | 591 | peer = GST_peer_list[peer_id]; |
594 | if (GNUNET_YES == peer->is_remote) | 592 | if (GNUNET_YES == peer->is_remote) |
595 | { | 593 | { |
596 | /* Forward the destory message to sub controller */ | 594 | /* Forward the destory message to sub controller */ |
597 | fopc = GNUNET_new (struct ForwardedOperationContext); | 595 | fopc = GNUNET_new(struct ForwardedOperationContext); |
598 | fopc->client = client; | 596 | fopc->client = client; |
599 | fopc->cls = peer; | 597 | fopc->cls = peer; |
600 | fopc->type = OP_PEER_DESTROY; | 598 | fopc->type = OP_PEER_DESTROY; |
601 | fopc->operation_id = GNUNET_ntohll (msg->operation_id); | 599 | fopc->operation_id = GNUNET_ntohll(msg->operation_id); |
602 | fopc->opc = | 600 | fopc->opc = |
603 | GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. | 601 | GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. |
604 | slave->controller, | 602 | slave->controller, |
605 | fopc->operation_id, | 603 | fopc->operation_id, |
606 | &msg->header, | 604 | &msg->header, |
607 | &peer_destroy_success_cb, | 605 | &peer_destroy_success_cb, |
608 | fopc); | 606 | fopc); |
609 | fopc->timeout_task = | 607 | fopc->timeout_task = |
610 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 608 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
611 | &GST_forwarded_operation_timeout, | 609 | &GST_forwarded_operation_timeout, |
612 | fopc); | 610 | fopc); |
613 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 611 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
614 | fopcq_tail, | 612 | fopcq_tail, |
615 | fopc); | 613 | fopc); |
616 | GNUNET_SERVICE_client_continue (client); | 614 | GNUNET_SERVICE_client_continue(client); |
617 | return; | 615 | return; |
618 | } | 616 | } |
619 | peer->destroy_flag = GNUNET_YES; | 617 | peer->destroy_flag = GNUNET_YES; |
620 | if (0 == peer->reference_cnt) | 618 | if (0 == peer->reference_cnt) |
621 | GST_destroy_peer (peer); | 619 | GST_destroy_peer(peer); |
622 | else | 620 | else |
623 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 621 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
624 | "Delaying peer destroy as peer is currently in use\n"); | 622 | "Delaying peer destroy as peer is currently in use\n"); |
625 | GST_send_operation_success_msg (client, | 623 | GST_send_operation_success_msg(client, |
626 | GNUNET_ntohll (msg->operation_id)); | 624 | GNUNET_ntohll(msg->operation_id)); |
627 | GNUNET_SERVICE_client_continue (client); | 625 | GNUNET_SERVICE_client_continue(client); |
628 | } | 626 | } |
629 | 627 | ||
630 | 628 | ||
@@ -635,10 +633,10 @@ handle_peer_destroy (void *cls, | |||
635 | * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure | 633 | * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure |
636 | */ | 634 | */ |
637 | static int | 635 | static int |
638 | start_peer (struct Peer *peer) | 636 | start_peer(struct Peer *peer) |
639 | { | 637 | { |
640 | GNUNET_assert (GNUNET_NO == peer->is_remote); | 638 | GNUNET_assert(GNUNET_NO == peer->is_remote); |
641 | if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer)) | 639 | if (GNUNET_OK != GNUNET_TESTING_peer_start(peer->details.local.peer)) |
642 | return GNUNET_SYSERR; | 640 | return GNUNET_SYSERR; |
643 | peer->details.local.is_running = GNUNET_YES; | 641 | peer->details.local.is_running = GNUNET_YES; |
644 | return GNUNET_OK; | 642 | return GNUNET_OK; |
@@ -652,8 +650,8 @@ start_peer (struct Peer *peer) | |||
652 | * @param msg the actual message | 650 | * @param msg the actual message |
653 | */ | 651 | */ |
654 | void | 652 | void |
655 | handle_peer_start (void *cls, | 653 | handle_peer_start(void *cls, |
656 | const struct GNUNET_TESTBED_PeerStartMessage *msg) | 654 | const struct GNUNET_TESTBED_PeerStartMessage *msg) |
657 | { | 655 | { |
658 | struct GNUNET_SERVICE_Client *client = cls; | 656 | struct GNUNET_SERVICE_Client *client = cls; |
659 | struct GNUNET_MQ_Envelope *env; | 657 | struct GNUNET_MQ_Envelope *env; |
@@ -662,55 +660,55 @@ handle_peer_start (void *cls, | |||
662 | struct Peer *peer; | 660 | struct Peer *peer; |
663 | uint32_t peer_id; | 661 | uint32_t peer_id; |
664 | 662 | ||
665 | peer_id = ntohl (msg->peer_id); | 663 | peer_id = ntohl(msg->peer_id); |
666 | if (! VALID_PEER_ID (peer_id)) | 664 | if (!VALID_PEER_ID(peer_id)) |
667 | { | 665 | { |
668 | GNUNET_break (0); | 666 | GNUNET_break(0); |
669 | LOG (GNUNET_ERROR_TYPE_ERROR, | 667 | LOG(GNUNET_ERROR_TYPE_ERROR, |
670 | "Asked to start a non existent peer with id: %u\n", | 668 | "Asked to start a non existent peer with id: %u\n", |
671 | peer_id); | 669 | peer_id); |
672 | GNUNET_SERVICE_client_continue (client); | 670 | GNUNET_SERVICE_client_continue(client); |
673 | return; | 671 | return; |
674 | } | 672 | } |
675 | peer = GST_peer_list[peer_id]; | 673 | peer = GST_peer_list[peer_id]; |
676 | if (GNUNET_YES == peer->is_remote) | 674 | if (GNUNET_YES == peer->is_remote) |
677 | { | 675 | { |
678 | fopc = GNUNET_new (struct ForwardedOperationContext); | 676 | fopc = GNUNET_new(struct ForwardedOperationContext); |
679 | fopc->client = client; | 677 | fopc->client = client; |
680 | fopc->operation_id = GNUNET_ntohll (msg->operation_id); | 678 | fopc->operation_id = GNUNET_ntohll(msg->operation_id); |
681 | fopc->type = OP_PEER_START; | 679 | fopc->type = OP_PEER_START; |
682 | fopc->opc = | 680 | fopc->opc = |
683 | GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. | 681 | GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. |
684 | slave->controller, | 682 | slave->controller, |
685 | fopc->operation_id, &msg->header, | 683 | fopc->operation_id, &msg->header, |
686 | &GST_forwarded_operation_reply_relay, | 684 | &GST_forwarded_operation_reply_relay, |
687 | fopc); | 685 | fopc); |
688 | fopc->timeout_task = | 686 | fopc->timeout_task = |
689 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 687 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
690 | &GST_forwarded_operation_timeout, | 688 | &GST_forwarded_operation_timeout, |
691 | fopc); | 689 | fopc); |
692 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 690 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
693 | fopcq_tail, | 691 | fopcq_tail, |
694 | fopc); | 692 | fopc); |
695 | GNUNET_SERVICE_client_continue (client); | 693 | GNUNET_SERVICE_client_continue(client); |
696 | return; | 694 | return; |
697 | } | 695 | } |
698 | if (GNUNET_OK != start_peer (peer)) | 696 | if (GNUNET_OK != start_peer(peer)) |
699 | { | 697 | { |
700 | GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id), | 698 | GST_send_operation_fail_msg(client, GNUNET_ntohll(msg->operation_id), |
701 | "Failed to start"); | 699 | "Failed to start"); |
702 | GNUNET_SERVICE_client_continue (client); | 700 | GNUNET_SERVICE_client_continue(client); |
703 | return; | 701 | return; |
704 | } | 702 | } |
705 | env = GNUNET_MQ_msg (reply, | 703 | env = GNUNET_MQ_msg(reply, |
706 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); | 704 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); |
707 | reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START); | 705 | reply->event_type = htonl(GNUNET_TESTBED_ET_PEER_START); |
708 | reply->host_id = htonl (GST_context->host_id); | 706 | reply->host_id = htonl(GST_context->host_id); |
709 | reply->peer_id = msg->peer_id; | 707 | reply->peer_id = msg->peer_id; |
710 | reply->operation_id = msg->operation_id; | 708 | reply->operation_id = msg->operation_id; |
711 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 709 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), |
712 | env); | 710 | env); |
713 | GNUNET_SERVICE_client_continue (client); | 711 | GNUNET_SERVICE_client_continue(client); |
714 | } | 712 | } |
715 | 713 | ||
716 | 714 | ||
@@ -721,8 +719,8 @@ handle_peer_start (void *cls, | |||
721 | * @param msg the actual message | 719 | * @param msg the actual message |
722 | */ | 720 | */ |
723 | void | 721 | void |
724 | handle_peer_stop (void *cls, | 722 | handle_peer_stop(void *cls, |
725 | const struct GNUNET_TESTBED_PeerStopMessage *msg) | 723 | const struct GNUNET_TESTBED_PeerStopMessage *msg) |
726 | { | 724 | { |
727 | struct GNUNET_SERVICE_Client *client = cls; | 725 | struct GNUNET_SERVICE_Client *client = cls; |
728 | struct GNUNET_MQ_Envelope *env; | 726 | struct GNUNET_MQ_Envelope *env; |
@@ -731,69 +729,69 @@ handle_peer_stop (void *cls, | |||
731 | struct Peer *peer; | 729 | struct Peer *peer; |
732 | uint32_t peer_id; | 730 | uint32_t peer_id; |
733 | 731 | ||
734 | peer_id = ntohl (msg->peer_id); | 732 | peer_id = ntohl(msg->peer_id); |
735 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 733 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
736 | "Received PEER_STOP for peer %u\n", | 734 | "Received PEER_STOP for peer %u\n", |
737 | (unsigned int) peer_id); | 735 | (unsigned int)peer_id); |
738 | if (! VALID_PEER_ID (peer_id)) | 736 | if (!VALID_PEER_ID(peer_id)) |
739 | { | 737 | { |
740 | GST_send_operation_fail_msg (client, | 738 | GST_send_operation_fail_msg(client, |
741 | GNUNET_ntohll (msg->operation_id), | 739 | GNUNET_ntohll(msg->operation_id), |
742 | "Peer not found"); | 740 | "Peer not found"); |
743 | GNUNET_SERVICE_client_continue (client); | 741 | GNUNET_SERVICE_client_continue(client); |
744 | return; | 742 | return; |
745 | } | 743 | } |
746 | peer = GST_peer_list[peer_id]; | 744 | peer = GST_peer_list[peer_id]; |
747 | if (GNUNET_YES == peer->is_remote) | 745 | if (GNUNET_YES == peer->is_remote) |
748 | { | 746 | { |
749 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 747 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
750 | "Forwarding PEER_STOP for peer %u\n", | 748 | "Forwarding PEER_STOP for peer %u\n", |
751 | (unsigned int) peer_id); | 749 | (unsigned int)peer_id); |
752 | fopc = GNUNET_new (struct ForwardedOperationContext); | 750 | fopc = GNUNET_new(struct ForwardedOperationContext); |
753 | fopc->client = client; | 751 | fopc->client = client; |
754 | fopc->operation_id = GNUNET_ntohll (msg->operation_id); | 752 | fopc->operation_id = GNUNET_ntohll(msg->operation_id); |
755 | fopc->type = OP_PEER_STOP; | 753 | fopc->type = OP_PEER_STOP; |
756 | fopc->opc = | 754 | fopc->opc = |
757 | GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. | 755 | GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. |
758 | slave->controller, | 756 | slave->controller, |
759 | fopc->operation_id, | 757 | fopc->operation_id, |
760 | &msg->header, | 758 | &msg->header, |
761 | &GST_forwarded_operation_reply_relay, | 759 | &GST_forwarded_operation_reply_relay, |
762 | fopc); | 760 | fopc); |
763 | fopc->timeout_task = | 761 | fopc->timeout_task = |
764 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 762 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
765 | &GST_forwarded_operation_timeout, | 763 | &GST_forwarded_operation_timeout, |
766 | fopc); | 764 | fopc); |
767 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 765 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
768 | fopcq_tail, | 766 | fopcq_tail, |
769 | fopc); | 767 | fopc); |
770 | GNUNET_SERVICE_client_continue (client); | 768 | GNUNET_SERVICE_client_continue(client); |
771 | return; | 769 | return; |
772 | } | 770 | } |
773 | if (GNUNET_OK != stop_peer (peer)) | 771 | if (GNUNET_OK != stop_peer(peer)) |
774 | { | 772 | { |
775 | LOG (GNUNET_ERROR_TYPE_WARNING, | 773 | LOG(GNUNET_ERROR_TYPE_WARNING, |
776 | "Stopping peer %u failed\n", | 774 | "Stopping peer %u failed\n", |
777 | (unsigned int) peer_id); | 775 | (unsigned int)peer_id); |
778 | GST_send_operation_fail_msg (client, | 776 | GST_send_operation_fail_msg(client, |
779 | GNUNET_ntohll (msg->operation_id), | 777 | GNUNET_ntohll(msg->operation_id), |
780 | "Peer not running"); | 778 | "Peer not running"); |
781 | GNUNET_SERVICE_client_continue (client); | 779 | GNUNET_SERVICE_client_continue(client); |
782 | return; | 780 | return; |
783 | } | 781 | } |
784 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 782 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
785 | "Peer %u successfully stopped\n", | 783 | "Peer %u successfully stopped\n", |
786 | (unsigned int) peer_id); | 784 | (unsigned int)peer_id); |
787 | env = GNUNET_MQ_msg (reply, | 785 | env = GNUNET_MQ_msg(reply, |
788 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); | 786 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); |
789 | reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP); | 787 | reply->event_type = htonl(GNUNET_TESTBED_ET_PEER_STOP); |
790 | reply->host_id = htonl (GST_context->host_id); | 788 | reply->host_id = htonl(GST_context->host_id); |
791 | reply->peer_id = msg->peer_id; | 789 | reply->peer_id = msg->peer_id; |
792 | reply->operation_id = msg->operation_id; | 790 | reply->operation_id = msg->operation_id; |
793 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 791 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), |
794 | env); | 792 | env); |
795 | GNUNET_SERVICE_client_continue (client); | 793 | GNUNET_SERVICE_client_continue(client); |
796 | GNUNET_TESTING_peer_wait (peer->details.local.peer); | 794 | GNUNET_TESTING_peer_wait(peer->details.local.peer); |
797 | } | 795 | } |
798 | 796 | ||
799 | 797 | ||
@@ -804,8 +802,8 @@ handle_peer_stop (void *cls, | |||
804 | * @param msg the actual message | 802 | * @param msg the actual message |
805 | */ | 803 | */ |
806 | void | 804 | void |
807 | handle_peer_get_config (void *cls, | 805 | handle_peer_get_config(void *cls, |
808 | const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg) | 806 | const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg) |
809 | { | 807 | { |
810 | struct GNUNET_SERVICE_Client *client = cls; | 808 | struct GNUNET_SERVICE_Client *client = cls; |
811 | struct GNUNET_MQ_Envelope *env; | 809 | struct GNUNET_MQ_Envelope *env; |
@@ -818,67 +816,67 @@ handle_peer_get_config (void *cls, | |||
818 | size_t xc_size; | 816 | size_t xc_size; |
819 | uint32_t peer_id; | 817 | uint32_t peer_id; |
820 | 818 | ||
821 | peer_id = ntohl (msg->peer_id); | 819 | peer_id = ntohl(msg->peer_id); |
822 | LOG_DEBUG ("Received GET_CONFIG for peer %u\n", | 820 | LOG_DEBUG("Received GET_CONFIG for peer %u\n", |
823 | (unsigned int) peer_id); | 821 | (unsigned int)peer_id); |
824 | if (!VALID_PEER_ID (peer_id)) | 822 | if (!VALID_PEER_ID(peer_id)) |
825 | { | 823 | { |
826 | GST_send_operation_fail_msg (client, | 824 | GST_send_operation_fail_msg(client, |
827 | GNUNET_ntohll (msg->operation_id), | 825 | GNUNET_ntohll(msg->operation_id), |
828 | "Peer not found"); | 826 | "Peer not found"); |
829 | GNUNET_SERVICE_client_continue (client); | 827 | GNUNET_SERVICE_client_continue(client); |
830 | return; | 828 | return; |
831 | } | 829 | } |
832 | peer = GST_peer_list[peer_id]; | 830 | peer = GST_peer_list[peer_id]; |
833 | if (GNUNET_YES == peer->is_remote) | 831 | if (GNUNET_YES == peer->is_remote) |
834 | { | 832 | { |
835 | LOG_DEBUG ("Forwarding PEER_GET_CONFIG for peer: %u\n", | 833 | LOG_DEBUG("Forwarding PEER_GET_CONFIG for peer: %u\n", |
836 | (unsigned int) peer_id); | 834 | (unsigned int)peer_id); |
837 | fopc = GNUNET_new (struct ForwardedOperationContext); | 835 | fopc = GNUNET_new(struct ForwardedOperationContext); |
838 | fopc->client = client; | 836 | fopc->client = client; |
839 | fopc->operation_id = GNUNET_ntohll (msg->operation_id); | 837 | fopc->operation_id = GNUNET_ntohll(msg->operation_id); |
840 | fopc->type = OP_PEER_INFO; | 838 | fopc->type = OP_PEER_INFO; |
841 | fopc->opc = | 839 | fopc->opc = |
842 | GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. | 840 | GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. |
843 | slave->controller, | 841 | slave->controller, |
844 | fopc->operation_id, | 842 | fopc->operation_id, |
845 | &msg->header, | 843 | &msg->header, |
846 | &GST_forwarded_operation_reply_relay, | 844 | &GST_forwarded_operation_reply_relay, |
847 | fopc); | 845 | fopc); |
848 | fopc->timeout_task = | 846 | fopc->timeout_task = |
849 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 847 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
850 | &GST_forwarded_operation_timeout, | 848 | &GST_forwarded_operation_timeout, |
851 | fopc); | 849 | fopc); |
852 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 850 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
853 | fopcq_tail, | 851 | fopcq_tail, |
854 | fopc); | 852 | fopc); |
855 | GNUNET_SERVICE_client_continue (client); | 853 | GNUNET_SERVICE_client_continue(client); |
856 | return; | 854 | return; |
857 | } | 855 | } |
858 | LOG_DEBUG ("Received PEER_GET_CONFIG for peer: %u\n", | 856 | LOG_DEBUG("Received PEER_GET_CONFIG for peer: %u\n", |
859 | peer_id); | 857 | peer_id); |
860 | config = | 858 | config = |
861 | GNUNET_CONFIGURATION_serialize (GST_peer_list[peer_id]->details.local.cfg, | 859 | GNUNET_CONFIGURATION_serialize(GST_peer_list[peer_id]->details.local.cfg, |
862 | &c_size); | 860 | &c_size); |
863 | xc_size = GNUNET_TESTBED_compress_config_ (config, | 861 | xc_size = GNUNET_TESTBED_compress_config_(config, |
864 | c_size, | 862 | c_size, |
865 | &xconfig); | 863 | &xconfig); |
866 | GNUNET_free (config); | 864 | GNUNET_free(config); |
867 | env = GNUNET_MQ_msg_extra (reply, | 865 | env = GNUNET_MQ_msg_extra(reply, |
868 | xc_size, | 866 | xc_size, |
869 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION); | 867 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION); |
870 | reply->peer_id = msg->peer_id; | 868 | reply->peer_id = msg->peer_id; |
871 | reply->operation_id = msg->operation_id; | 869 | reply->operation_id = msg->operation_id; |
872 | GNUNET_TESTING_peer_get_identity (GST_peer_list[peer_id]->details.local.peer, | 870 | GNUNET_TESTING_peer_get_identity(GST_peer_list[peer_id]->details.local.peer, |
873 | &reply->peer_identity); | 871 | &reply->peer_identity); |
874 | reply->config_size = htons ((uint16_t) c_size); | 872 | reply->config_size = htons((uint16_t)c_size); |
875 | GNUNET_memcpy (&reply[1], | 873 | GNUNET_memcpy(&reply[1], |
876 | xconfig, | 874 | xconfig, |
877 | xc_size); | 875 | xc_size); |
878 | GNUNET_free (xconfig); | 876 | GNUNET_free(xconfig); |
879 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 877 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), |
880 | env); | 878 | env); |
881 | GNUNET_SERVICE_client_continue (client); | 879 | GNUNET_SERVICE_client_continue(client); |
882 | } | 880 | } |
883 | 881 | ||
884 | 882 | ||
@@ -886,10 +884,10 @@ handle_peer_get_config (void *cls, | |||
886 | * Cleans up the Peer reconfigure context list | 884 | * Cleans up the Peer reconfigure context list |
887 | */ | 885 | */ |
888 | void | 886 | void |
889 | GST_free_prcq () | 887 | GST_free_prcq() |
890 | { | 888 | { |
891 | while (NULL != prc_head) | 889 | while (NULL != prc_head) |
892 | cleanup_prc (prc_head); | 890 | cleanup_prc(prc_head); |
893 | } | 891 | } |
894 | 892 | ||
895 | 893 | ||
@@ -901,21 +899,21 @@ GST_free_prcq () | |||
901 | * @return error message (freshly allocated); NULL upon success | 899 | * @return error message (freshly allocated); NULL upon success |
902 | */ | 900 | */ |
903 | static char * | 901 | static char * |
904 | update_peer_config (struct Peer *peer, | 902 | update_peer_config(struct Peer *peer, |
905 | struct GNUNET_CONFIGURATION_Handle *cfg) | 903 | struct GNUNET_CONFIGURATION_Handle *cfg) |
906 | { | 904 | { |
907 | char *emsg; | 905 | char *emsg; |
908 | 906 | ||
909 | GNUNET_TESTING_peer_destroy (peer->details.local.peer); | 907 | GNUNET_TESTING_peer_destroy(peer->details.local.peer); |
910 | GNUNET_CONFIGURATION_destroy (peer->details.local.cfg); | 908 | GNUNET_CONFIGURATION_destroy(peer->details.local.cfg); |
911 | peer->details.local.cfg = cfg; | 909 | peer->details.local.cfg = cfg; |
912 | emsg = NULL; | 910 | emsg = NULL; |
913 | peer->details.local.peer | 911 | peer->details.local.peer |
914 | = GNUNET_TESTING_peer_configure (GST_context->system, | 912 | = GNUNET_TESTING_peer_configure(GST_context->system, |
915 | peer->details.local.cfg, | 913 | peer->details.local.cfg, |
916 | peer->id, | 914 | peer->id, |
917 | NULL /* Peer id */ , | 915 | NULL /* Peer id */, |
918 | &emsg); | 916 | &emsg); |
919 | return emsg; | 917 | return emsg; |
920 | } | 918 | } |
921 | 919 | ||
@@ -929,39 +927,39 @@ update_peer_config (struct Peer *peer, | |||
929 | * error | 927 | * error |
930 | */ | 928 | */ |
931 | static void | 929 | static void |
932 | prc_stop_cb (void *cls, | 930 | prc_stop_cb(void *cls, |
933 | struct GNUNET_TESTING_Peer *p, | 931 | struct GNUNET_TESTING_Peer *p, |
934 | int success) | 932 | int success) |
935 | { | 933 | { |
936 | struct PeerReconfigureContext *prc = cls; | 934 | struct PeerReconfigureContext *prc = cls; |
937 | struct Peer *peer; | 935 | struct Peer *peer; |
938 | char *emsg; | 936 | char *emsg; |
939 | 937 | ||
940 | GNUNET_assert (VALID_PEER_ID (prc->peer_id)); | 938 | GNUNET_assert(VALID_PEER_ID(prc->peer_id)); |
941 | peer = GST_peer_list [prc->peer_id]; | 939 | peer = GST_peer_list [prc->peer_id]; |
942 | GNUNET_assert (GNUNET_NO == peer->is_remote); | 940 | GNUNET_assert(GNUNET_NO == peer->is_remote); |
943 | emsg = update_peer_config (peer, prc->cfg); | 941 | emsg = update_peer_config(peer, prc->cfg); |
944 | prc->cfg = NULL; | 942 | prc->cfg = NULL; |
945 | prc->stopped = 1; | 943 | prc->stopped = 1; |
946 | if (NULL != emsg) | 944 | if (NULL != emsg) |
947 | { | 945 | { |
948 | GST_send_operation_fail_msg (prc->client, | 946 | GST_send_operation_fail_msg(prc->client, |
949 | prc->op_id, | 947 | prc->op_id, |
950 | emsg); | 948 | emsg); |
951 | goto cleanup; | 949 | goto cleanup; |
952 | } | 950 | } |
953 | if (GNUNET_OK != start_peer (peer)) | 951 | if (GNUNET_OK != start_peer(peer)) |
954 | { | 952 | { |
955 | GST_send_operation_fail_msg (prc->client, | 953 | GST_send_operation_fail_msg(prc->client, |
956 | prc->op_id, | 954 | prc->op_id, |
957 | "Failed to start reconfigured peer"); | 955 | "Failed to start reconfigured peer"); |
958 | goto cleanup; | 956 | goto cleanup; |
959 | } | 957 | } |
960 | GST_send_operation_success_msg (prc->client, | 958 | GST_send_operation_success_msg(prc->client, |
961 | prc->op_id); | 959 | prc->op_id); |
962 | 960 | ||
963 | cleanup: | 961 | cleanup: |
964 | cleanup_prc (prc); | 962 | cleanup_prc(prc); |
965 | return; | 963 | return; |
966 | } | 964 | } |
967 | 965 | ||
@@ -974,8 +972,8 @@ prc_stop_cb (void *cls, | |||
974 | * @return #GNUNET_OK if @a msg is well-formed | 972 | * @return #GNUNET_OK if @a msg is well-formed |
975 | */ | 973 | */ |
976 | int | 974 | int |
977 | check_peer_reconfigure (void *cls, | 975 | check_peer_reconfigure(void *cls, |
978 | const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) | 976 | const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) |
979 | { | 977 | { |
980 | return GNUNET_OK; /* checked later */ | 978 | return GNUNET_OK; /* checked later */ |
981 | } | 979 | } |
@@ -990,8 +988,8 @@ check_peer_reconfigure (void *cls, | |||
990 | * @param msg the actual message | 988 | * @param msg the actual message |
991 | */ | 989 | */ |
992 | void | 990 | void |
993 | handle_peer_reconfigure (void *cls, | 991 | handle_peer_reconfigure(void *cls, |
994 | const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) | 992 | const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) |
995 | { | 993 | { |
996 | struct GNUNET_SERVICE_Client *client = cls; | 994 | struct GNUNET_SERVICE_Client *client = cls; |
997 | struct Peer *peer; | 995 | struct Peer *peer; |
@@ -1002,114 +1000,114 @@ handle_peer_reconfigure (void *cls, | |||
1002 | uint64_t op_id; | 1000 | uint64_t op_id; |
1003 | uint32_t peer_id; | 1001 | uint32_t peer_id; |
1004 | 1002 | ||
1005 | peer_id = ntohl (msg->peer_id); | 1003 | peer_id = ntohl(msg->peer_id); |
1006 | op_id = GNUNET_ntohll (msg->operation_id); | 1004 | op_id = GNUNET_ntohll(msg->operation_id); |
1007 | if (! VALID_PEER_ID (peer_id)) | 1005 | if (!VALID_PEER_ID(peer_id)) |
1008 | { | 1006 | { |
1009 | GNUNET_break (0); | 1007 | GNUNET_break(0); |
1010 | GST_send_operation_fail_msg (client, | 1008 | GST_send_operation_fail_msg(client, |
1011 | op_id, | 1009 | op_id, |
1012 | "Peer not found"); | 1010 | "Peer not found"); |
1013 | GNUNET_SERVICE_client_continue (client); | 1011 | GNUNET_SERVICE_client_continue(client); |
1014 | return; | 1012 | return; |
1015 | } | 1013 | } |
1016 | peer = GST_peer_list[peer_id]; | 1014 | peer = GST_peer_list[peer_id]; |
1017 | if (GNUNET_YES == peer->is_remote) | 1015 | if (GNUNET_YES == peer->is_remote) |
1018 | { | 1016 | { |
1019 | LOG_DEBUG ("Forwarding PEER_RECONFIGURE for peer: %u\n", peer_id); | 1017 | LOG_DEBUG("Forwarding PEER_RECONFIGURE for peer: %u\n", peer_id); |
1020 | fopc = GNUNET_new (struct ForwardedOperationContext); | 1018 | fopc = GNUNET_new(struct ForwardedOperationContext); |
1021 | fopc->client = client; | 1019 | fopc->client = client; |
1022 | fopc->operation_id = op_id; | 1020 | fopc->operation_id = op_id; |
1023 | fopc->type = OP_PEER_RECONFIGURE; | 1021 | fopc->type = OP_PEER_RECONFIGURE; |
1024 | fopc->opc = | 1022 | fopc->opc = |
1025 | GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. | 1023 | GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. |
1026 | slave->controller, | 1024 | slave->controller, |
1027 | fopc->operation_id, | 1025 | fopc->operation_id, |
1028 | &msg->header, | 1026 | &msg->header, |
1029 | &GST_forwarded_operation_reply_relay, | 1027 | &GST_forwarded_operation_reply_relay, |
1030 | fopc); | 1028 | fopc); |
1031 | fopc->timeout_task = | 1029 | fopc->timeout_task = |
1032 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 1030 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
1033 | &GST_forwarded_operation_timeout, | 1031 | &GST_forwarded_operation_timeout, |
1034 | fopc); | 1032 | fopc); |
1035 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 1033 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
1036 | fopcq_tail, | 1034 | fopcq_tail, |
1037 | fopc); | 1035 | fopc); |
1038 | GNUNET_SERVICE_client_continue (client); | 1036 | GNUNET_SERVICE_client_continue(client); |
1039 | return; | 1037 | return; |
1040 | } | 1038 | } |
1041 | LOG_DEBUG ("Received PEER_RECONFIGURE for peer %u\n", | 1039 | LOG_DEBUG("Received PEER_RECONFIGURE for peer %u\n", |
1042 | (unsigned int) peer_id); | 1040 | (unsigned int)peer_id); |
1043 | if (0 < peer->reference_cnt) | 1041 | if (0 < peer->reference_cnt) |
1044 | { | 1042 | { |
1045 | GNUNET_break (0); | 1043 | GNUNET_break(0); |
1046 | GST_send_operation_fail_msg (client, | 1044 | GST_send_operation_fail_msg(client, |
1047 | op_id, | 1045 | op_id, |
1048 | "Peer in use"); | 1046 | "Peer in use"); |
1049 | GNUNET_SERVICE_client_continue (client); | 1047 | GNUNET_SERVICE_client_continue(client); |
1050 | return; | 1048 | return; |
1051 | } | 1049 | } |
1052 | if (GNUNET_YES == peer->destroy_flag) | 1050 | if (GNUNET_YES == peer->destroy_flag) |
1053 | { | 1051 | { |
1054 | GNUNET_break (0); | 1052 | GNUNET_break(0); |
1055 | GST_send_operation_fail_msg (client, | 1053 | GST_send_operation_fail_msg(client, |
1056 | op_id, | 1054 | op_id, |
1057 | "Peer is being destroyed"); | 1055 | "Peer is being destroyed"); |
1058 | GNUNET_SERVICE_client_continue (client); | 1056 | GNUNET_SERVICE_client_continue(client); |
1059 | return; | 1057 | return; |
1060 | } | 1058 | } |
1061 | cfg = GNUNET_TESTBED_extract_config_ (&msg->header); | 1059 | cfg = GNUNET_TESTBED_extract_config_(&msg->header); |
1062 | if (NULL == cfg) | 1060 | if (NULL == cfg) |
1063 | { | 1061 | { |
1064 | GNUNET_break (0); | 1062 | GNUNET_break(0); |
1065 | GST_send_operation_fail_msg (client, | 1063 | GST_send_operation_fail_msg(client, |
1066 | op_id, | 1064 | op_id, |
1067 | "Compression error"); | 1065 | "Compression error"); |
1068 | GNUNET_SERVICE_client_continue (client); | 1066 | GNUNET_SERVICE_client_continue(client); |
1069 | return; | 1067 | return; |
1070 | } | 1068 | } |
1071 | if (GNUNET_NO == peer->details.local.is_running) | 1069 | if (GNUNET_NO == peer->details.local.is_running) |
1072 | { | 1070 | { |
1073 | emsg = update_peer_config (peer, | 1071 | emsg = update_peer_config(peer, |
1074 | cfg); | 1072 | cfg); |
1075 | if (NULL != emsg) | 1073 | if (NULL != emsg) |
1076 | GST_send_operation_fail_msg (client, | 1074 | GST_send_operation_fail_msg(client, |
1077 | op_id, | 1075 | op_id, |
1078 | emsg); | 1076 | emsg); |
1079 | GST_send_operation_success_msg (client, | 1077 | GST_send_operation_success_msg(client, |
1080 | op_id); | 1078 | op_id); |
1081 | GNUNET_SERVICE_client_continue (client); | 1079 | GNUNET_SERVICE_client_continue(client); |
1082 | GNUNET_free_non_null (emsg); | 1080 | GNUNET_free_non_null(emsg); |
1083 | return; | 1081 | return; |
1084 | } | 1082 | } |
1085 | prc = GNUNET_new (struct PeerReconfigureContext); | 1083 | prc = GNUNET_new(struct PeerReconfigureContext); |
1086 | if (GNUNET_OK != | 1084 | if (GNUNET_OK != |
1087 | GNUNET_TESTING_peer_stop_async (peer->details.local.peer, | 1085 | GNUNET_TESTING_peer_stop_async(peer->details.local.peer, |
1088 | &prc_stop_cb, | 1086 | &prc_stop_cb, |
1089 | prc)) | 1087 | prc)) |
1090 | { | 1088 | { |
1091 | GNUNET_assert (0 < GNUNET_asprintf (&emsg, | 1089 | GNUNET_assert(0 < GNUNET_asprintf(&emsg, |
1092 | "Error trying to stop peer %u asynchronously\n", | 1090 | "Error trying to stop peer %u asynchronously\n", |
1093 | peer_id)); | 1091 | peer_id)); |
1094 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1092 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1095 | "%s\n", | 1093 | "%s\n", |
1096 | emsg); | 1094 | emsg); |
1097 | GST_send_operation_fail_msg (client, | 1095 | GST_send_operation_fail_msg(client, |
1098 | op_id, | 1096 | op_id, |
1099 | emsg); | 1097 | emsg); |
1100 | GNUNET_SERVICE_client_continue (client); | 1098 | GNUNET_SERVICE_client_continue(client); |
1101 | GNUNET_free (prc); | 1099 | GNUNET_free(prc); |
1102 | GNUNET_free (emsg); | 1100 | GNUNET_free(emsg); |
1103 | return; | 1101 | return; |
1104 | } | 1102 | } |
1105 | prc->cfg = cfg; | 1103 | prc->cfg = cfg; |
1106 | prc->peer_id = peer_id; | 1104 | prc->peer_id = peer_id; |
1107 | prc->op_id = op_id; | 1105 | prc->op_id = op_id; |
1108 | prc->client = client; | 1106 | prc->client = client; |
1109 | GNUNET_CONTAINER_DLL_insert_tail (prc_head, | 1107 | GNUNET_CONTAINER_DLL_insert_tail(prc_head, |
1110 | prc_tail, | 1108 | prc_tail, |
1111 | prc); | 1109 | prc); |
1112 | GNUNET_SERVICE_client_continue (client); | 1110 | GNUNET_SERVICE_client_continue(client); |
1113 | } | 1111 | } |
1114 | 1112 | ||
1115 | 1113 | ||
@@ -1117,10 +1115,10 @@ handle_peer_reconfigure (void *cls, | |||
1117 | * Frees the ManageServiceContext queue | 1115 | * Frees the ManageServiceContext queue |
1118 | */ | 1116 | */ |
1119 | void | 1117 | void |
1120 | GST_free_mctxq () | 1118 | GST_free_mctxq() |
1121 | { | 1119 | { |
1122 | while (NULL != mctx_head) | 1120 | while (NULL != mctx_head) |
1123 | cleanup_mctx (mctx_head); | 1121 | cleanup_mctx(mctx_head); |
1124 | } | 1122 | } |
1125 | 1123 | ||
1126 | 1124 | ||
@@ -1131,15 +1129,16 @@ GST_free_mctxq () | |||
1131 | * @return a string interpretation of the request status | 1129 | * @return a string interpretation of the request status |
1132 | */ | 1130 | */ |
1133 | static const char * | 1131 | static const char * |
1134 | arm_req_string (enum GNUNET_ARM_RequestStatus rs) | 1132 | arm_req_string(enum GNUNET_ARM_RequestStatus rs) |
1135 | { | 1133 | { |
1136 | switch (rs) | 1134 | switch (rs) |
1137 | { | 1135 | { |
1138 | case GNUNET_ARM_REQUEST_SENT_OK: | 1136 | case GNUNET_ARM_REQUEST_SENT_OK: |
1139 | return _("Message was sent successfully"); | 1137 | return _("Message was sent successfully"); |
1140 | case GNUNET_ARM_REQUEST_DISCONNECTED: | 1138 | |
1141 | return _("We disconnected from ARM before we could send a request"); | 1139 | case GNUNET_ARM_REQUEST_DISCONNECTED: |
1142 | } | 1140 | return _("We disconnected from ARM before we could send a request"); |
1141 | } | ||
1143 | return _("Unknown request status"); | 1142 | return _("Unknown request status"); |
1144 | } | 1143 | } |
1145 | 1144 | ||
@@ -1151,31 +1150,40 @@ arm_req_string (enum GNUNET_ARM_RequestStatus rs) | |||
1151 | * @return a string interpretation | 1150 | * @return a string interpretation |
1152 | */ | 1151 | */ |
1153 | static const char * | 1152 | static const char * |
1154 | arm_ret_string (enum GNUNET_ARM_Result result) | 1153 | arm_ret_string(enum GNUNET_ARM_Result result) |
1155 | { | 1154 | { |
1156 | switch (result) | 1155 | switch (result) |
1157 | { | 1156 | { |
1158 | case GNUNET_ARM_RESULT_STOPPED: | 1157 | case GNUNET_ARM_RESULT_STOPPED: |
1159 | return _("%s is stopped"); | 1158 | return _("%s is stopped"); |
1160 | case GNUNET_ARM_RESULT_STARTING: | 1159 | |
1161 | return _("%s is starting"); | 1160 | case GNUNET_ARM_RESULT_STARTING: |
1162 | case GNUNET_ARM_RESULT_STOPPING: | 1161 | return _("%s is starting"); |
1163 | return _("%s is stopping"); | 1162 | |
1164 | case GNUNET_ARM_RESULT_IS_STARTING_ALREADY: | 1163 | case GNUNET_ARM_RESULT_STOPPING: |
1165 | return _("%s is starting already"); | 1164 | return _("%s is stopping"); |
1166 | case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY: | 1165 | |
1167 | return _("%s is stopping already"); | 1166 | case GNUNET_ARM_RESULT_IS_STARTING_ALREADY: |
1168 | case GNUNET_ARM_RESULT_IS_STARTED_ALREADY: | 1167 | return _("%s is starting already"); |
1169 | return _("%s is started already"); | 1168 | |
1170 | case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY: | 1169 | case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY: |
1171 | return _("%s is stopped already"); | 1170 | return _("%s is stopping already"); |
1172 | case GNUNET_ARM_RESULT_IS_NOT_KNOWN: | 1171 | |
1173 | return _("%s service is not known to ARM"); | 1172 | case GNUNET_ARM_RESULT_IS_STARTED_ALREADY: |
1174 | case GNUNET_ARM_RESULT_START_FAILED: | 1173 | return _("%s is started already"); |
1175 | return _("%s service failed to start"); | 1174 | |
1176 | case GNUNET_ARM_RESULT_IN_SHUTDOWN: | 1175 | case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY: |
1177 | return _("%s service can't be started because ARM is shutting down"); | 1176 | return _("%s is stopped already"); |
1178 | } | 1177 | |
1178 | case GNUNET_ARM_RESULT_IS_NOT_KNOWN: | ||
1179 | return _("%s service is not known to ARM"); | ||
1180 | |||
1181 | case GNUNET_ARM_RESULT_START_FAILED: | ||
1182 | return _("%s service failed to start"); | ||
1183 | |||
1184 | case GNUNET_ARM_RESULT_IN_SHUTDOWN: | ||
1185 | return _("%s service can't be started because ARM is shutting down"); | ||
1186 | } | ||
1179 | return _("%.s Unknown result code."); | 1187 | return _("%.s Unknown result code."); |
1180 | } | 1188 | } |
1181 | 1189 | ||
@@ -1191,9 +1199,9 @@ arm_ret_string (enum GNUNET_ARM_Result result) | |||
1191 | * @param result result of the operation | 1199 | * @param result result of the operation |
1192 | */ | 1200 | */ |
1193 | static void | 1201 | static void |
1194 | service_manage_result_cb (void *cls, | 1202 | service_manage_result_cb(void *cls, |
1195 | enum GNUNET_ARM_RequestStatus rs, | 1203 | enum GNUNET_ARM_RequestStatus rs, |
1196 | enum GNUNET_ARM_Result result) | 1204 | enum GNUNET_ARM_Result result) |
1197 | { | 1205 | { |
1198 | struct ManageServiceContext *mctx = cls; | 1206 | struct ManageServiceContext *mctx = cls; |
1199 | char *emsg; | 1207 | char *emsg; |
@@ -1202,55 +1210,55 @@ service_manage_result_cb (void *cls, | |||
1202 | if (GNUNET_YES == mctx->expired) | 1210 | if (GNUNET_YES == mctx->expired) |
1203 | return; | 1211 | return; |
1204 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 1212 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
1205 | { | 1213 | { |
1206 | GNUNET_asprintf (&emsg, | 1214 | GNUNET_asprintf(&emsg, |
1207 | "Error communicating with Peer %u's ARM: %s", | 1215 | "Error communicating with Peer %u's ARM: %s", |
1208 | mctx->peer->id, | 1216 | mctx->peer->id, |
1209 | arm_req_string (rs)); | 1217 | arm_req_string(rs)); |
1210 | goto ret; | 1218 | goto ret; |
1211 | } | 1219 | } |
1212 | if (1 == mctx->start) | 1220 | if (1 == mctx->start) |
1213 | goto service_start_check; | 1221 | goto service_start_check; |
1214 | if (! ((GNUNET_ARM_RESULT_STOPPED == result) | 1222 | if (!((GNUNET_ARM_RESULT_STOPPED == result) |
1215 | || (GNUNET_ARM_RESULT_STOPPING == result) | 1223 | || (GNUNET_ARM_RESULT_STOPPING == result) |
1216 | || (GNUNET_ARM_RESULT_IS_STOPPING_ALREADY == result) | 1224 | || (GNUNET_ARM_RESULT_IS_STOPPING_ALREADY == result) |
1217 | || (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY == result)) ) | 1225 | || (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY == result))) |
1218 | { | 1226 | { |
1219 | /* stopping a service failed */ | 1227 | /* stopping a service failed */ |
1220 | GNUNET_asprintf (&emsg, | 1228 | GNUNET_asprintf(&emsg, |
1221 | arm_ret_string (result), | 1229 | arm_ret_string(result), |
1222 | mctx->service); | 1230 | mctx->service); |
1223 | goto ret; | 1231 | goto ret; |
1224 | } | 1232 | } |
1225 | /* service stopped successfully */ | 1233 | /* service stopped successfully */ |
1226 | goto ret; | 1234 | goto ret; |
1227 | 1235 | ||
1228 | service_start_check: | 1236 | service_start_check: |
1229 | if (! ((GNUNET_ARM_RESULT_STARTING == result) | 1237 | if (!((GNUNET_ARM_RESULT_STARTING == result) |
1230 | || (GNUNET_ARM_RESULT_IS_STARTING_ALREADY == result) | 1238 | || (GNUNET_ARM_RESULT_IS_STARTING_ALREADY == result) |
1231 | || (GNUNET_ARM_RESULT_IS_STARTED_ALREADY == result)) ) | 1239 | || (GNUNET_ARM_RESULT_IS_STARTED_ALREADY == result))) |
1232 | { | 1240 | { |
1233 | /* starting a service failed */ | 1241 | /* starting a service failed */ |
1234 | GNUNET_asprintf (&emsg, | 1242 | GNUNET_asprintf(&emsg, |
1235 | arm_ret_string (result), | 1243 | arm_ret_string(result), |
1236 | mctx->service); | 1244 | mctx->service); |
1237 | goto ret; | 1245 | goto ret; |
1238 | } | 1246 | } |
1239 | /* service started successfully */ | 1247 | /* service started successfully */ |
1240 | 1248 | ||
1241 | ret: | 1249 | ret: |
1242 | if (NULL != emsg) | 1250 | if (NULL != emsg) |
1243 | { | 1251 | { |
1244 | LOG_DEBUG ("%s\n", emsg); | 1252 | LOG_DEBUG("%s\n", emsg); |
1245 | GST_send_operation_fail_msg (mctx->client, | 1253 | GST_send_operation_fail_msg(mctx->client, |
1246 | mctx->op_id, | 1254 | mctx->op_id, |
1247 | emsg); | 1255 | emsg); |
1248 | } | 1256 | } |
1249 | else | 1257 | else |
1250 | GST_send_operation_success_msg (mctx->client, | 1258 | GST_send_operation_success_msg(mctx->client, |
1251 | mctx->op_id); | 1259 | mctx->op_id); |
1252 | GNUNET_free_non_null (emsg); | 1260 | GNUNET_free_non_null(emsg); |
1253 | cleanup_mctx (mctx); | 1261 | cleanup_mctx(mctx); |
1254 | } | 1262 | } |
1255 | 1263 | ||
1256 | 1264 | ||
@@ -1262,25 +1270,25 @@ service_manage_result_cb (void *cls, | |||
1262 | * @return #GNUNET_OK if @a msg is well-formed | 1270 | * @return #GNUNET_OK if @a msg is well-formed |
1263 | */ | 1271 | */ |
1264 | int | 1272 | int |
1265 | check_manage_peer_service (void *cls, | 1273 | check_manage_peer_service(void *cls, |
1266 | const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) | 1274 | const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) |
1267 | { | 1275 | { |
1268 | uint16_t msize; | 1276 | uint16_t msize; |
1269 | const char* service; | 1277 | const char* service; |
1270 | 1278 | ||
1271 | msize = ntohs (msg->header.size); | 1279 | msize = ntohs(msg->header.size); |
1272 | service = (const char *) &msg[1]; | 1280 | service = (const char *)&msg[1]; |
1273 | if ('\0' != service[msize - sizeof | 1281 | if ('\0' != service[msize - sizeof |
1274 | (struct GNUNET_TESTBED_ManagePeerServiceMessage) - 1]) | 1282 | (struct GNUNET_TESTBED_ManagePeerServiceMessage) - 1]) |
1275 | { | 1283 | { |
1276 | GNUNET_break_op (0); | 1284 | GNUNET_break_op(0); |
1277 | return GNUNET_SYSERR; | 1285 | return GNUNET_SYSERR; |
1278 | } | 1286 | } |
1279 | if (1 < msg->start) | 1287 | if (1 < msg->start) |
1280 | { | 1288 | { |
1281 | GNUNET_break_op (0); | 1289 | GNUNET_break_op(0); |
1282 | return GNUNET_SYSERR; | 1290 | return GNUNET_SYSERR; |
1283 | } | 1291 | } |
1284 | return GNUNET_OK; | 1292 | return GNUNET_OK; |
1285 | } | 1293 | } |
1286 | 1294 | ||
@@ -1292,8 +1300,8 @@ check_manage_peer_service (void *cls, | |||
1292 | * @param msg the actual message | 1300 | * @param msg the actual message |
1293 | */ | 1301 | */ |
1294 | void | 1302 | void |
1295 | handle_manage_peer_service (void *cls, | 1303 | handle_manage_peer_service(void *cls, |
1296 | const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) | 1304 | const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) |
1297 | { | 1305 | { |
1298 | struct GNUNET_SERVICE_Client *client = cls; | 1306 | struct GNUNET_SERVICE_Client *client = cls; |
1299 | const char* service; | 1307 | const char* service; |
@@ -1305,100 +1313,100 @@ handle_manage_peer_service (void *cls, | |||
1305 | uint64_t op_id; | 1313 | uint64_t op_id; |
1306 | uint32_t peer_id; | 1314 | uint32_t peer_id; |
1307 | 1315 | ||
1308 | service = (const char *) &msg[1]; | 1316 | service = (const char *)&msg[1]; |
1309 | peer_id = ntohl (msg->peer_id); | 1317 | peer_id = ntohl(msg->peer_id); |
1310 | op_id = GNUNET_ntohll (msg->operation_id); | 1318 | op_id = GNUNET_ntohll(msg->operation_id); |
1311 | LOG_DEBUG ("Received request to manage service %s on peer %u\n", | 1319 | LOG_DEBUG("Received request to manage service %s on peer %u\n", |
1312 | service, (unsigned int) peer_id); | 1320 | service, (unsigned int)peer_id); |
1313 | if ((GST_peer_list_size <= peer_id) | 1321 | if ((GST_peer_list_size <= peer_id) |
1314 | || (NULL == (peer = GST_peer_list[peer_id]))) | 1322 | || (NULL == (peer = GST_peer_list[peer_id]))) |
1315 | { | 1323 | { |
1316 | GNUNET_asprintf (&emsg, "Asked to manage service of a non existent peer " | 1324 | GNUNET_asprintf(&emsg, "Asked to manage service of a non existent peer " |
1317 | "with id: %u", peer_id); | 1325 | "with id: %u", peer_id); |
1318 | goto err_ret; | 1326 | goto err_ret; |
1319 | } | 1327 | } |
1320 | if (0 == strcasecmp ("arm", service)) | 1328 | if (0 == strcasecmp("arm", service)) |
1321 | { | 1329 | { |
1322 | emsg = GNUNET_strdup ("Cannot start/stop peer's ARM service. " | 1330 | emsg = GNUNET_strdup("Cannot start/stop peer's ARM service. " |
1323 | "Use peer start/stop for that"); | 1331 | "Use peer start/stop for that"); |
1324 | goto err_ret; | 1332 | goto err_ret; |
1325 | } | 1333 | } |
1326 | if (GNUNET_YES == peer->is_remote) | 1334 | if (GNUNET_YES == peer->is_remote) |
1327 | { | 1335 | { |
1328 | /* Forward the destory message to sub controller */ | 1336 | /* Forward the destory message to sub controller */ |
1329 | fopc = GNUNET_new (struct ForwardedOperationContext); | 1337 | fopc = GNUNET_new(struct ForwardedOperationContext); |
1330 | fopc->client = client; | 1338 | fopc->client = client; |
1331 | fopc->cls = peer; | 1339 | fopc->cls = peer; |
1332 | fopc->type = OP_MANAGE_SERVICE; | 1340 | fopc->type = OP_MANAGE_SERVICE; |
1333 | fopc->operation_id = op_id; | 1341 | fopc->operation_id = op_id; |
1334 | fopc->opc = | 1342 | fopc->opc = |
1335 | GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. | 1343 | GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. |
1336 | slave->controller, | 1344 | slave->controller, |
1337 | fopc->operation_id, | 1345 | fopc->operation_id, |
1338 | &msg->header, | 1346 | &msg->header, |
1339 | &GST_forwarded_operation_reply_relay, | 1347 | &GST_forwarded_operation_reply_relay, |
1340 | fopc); | 1348 | fopc); |
1341 | fopc->timeout_task = | 1349 | fopc->timeout_task = |
1342 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 1350 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
1343 | &GST_forwarded_operation_timeout, | 1351 | &GST_forwarded_operation_timeout, |
1344 | fopc); | 1352 | fopc); |
1345 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 1353 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
1346 | fopcq_tail, | 1354 | fopcq_tail, |
1347 | fopc); | 1355 | fopc); |
1348 | GNUNET_SERVICE_client_continue (client); | 1356 | GNUNET_SERVICE_client_continue(client); |
1349 | return; | 1357 | return; |
1350 | } | 1358 | } |
1351 | if (GNUNET_NO == peer->details.local.is_running) | 1359 | if (GNUNET_NO == peer->details.local.is_running) |
1352 | { | 1360 | { |
1353 | emsg = GNUNET_strdup ("Peer not running\n"); | 1361 | emsg = GNUNET_strdup("Peer not running\n"); |
1354 | goto err_ret; | 1362 | goto err_ret; |
1355 | } | 1363 | } |
1356 | if ((0 != peer->reference_cnt) | 1364 | if ((0 != peer->reference_cnt) |
1357 | && ( (0 == strcasecmp ("core", service)) | 1365 | && ((0 == strcasecmp("core", service)) |
1358 | || (0 == strcasecmp ("transport", service)) ) ) | 1366 | || (0 == strcasecmp("transport", service)))) |
1359 | { | 1367 | { |
1360 | GNUNET_asprintf (&emsg, "Cannot stop %s service of peer with id: %u " | 1368 | GNUNET_asprintf(&emsg, "Cannot stop %s service of peer with id: %u " |
1361 | "since it is required by existing operations", | 1369 | "since it is required by existing operations", |
1362 | service, peer_id); | 1370 | service, peer_id); |
1363 | goto err_ret; | 1371 | goto err_ret; |
1364 | } | 1372 | } |
1365 | ah = GNUNET_ARM_connect (peer->details.local.cfg, NULL, NULL); | 1373 | ah = GNUNET_ARM_connect(peer->details.local.cfg, NULL, NULL); |
1366 | if (NULL == ah) | 1374 | if (NULL == ah) |
1367 | { | 1375 | { |
1368 | GNUNET_asprintf (&emsg, | 1376 | GNUNET_asprintf(&emsg, |
1369 | "Cannot connect to ARM service of peer with id: %u", | 1377 | "Cannot connect to ARM service of peer with id: %u", |
1370 | peer_id); | 1378 | peer_id); |
1371 | goto err_ret; | 1379 | goto err_ret; |
1372 | } | 1380 | } |
1373 | mctx = GNUNET_new (struct ManageServiceContext); | 1381 | mctx = GNUNET_new(struct ManageServiceContext); |
1374 | mctx->peer = peer; | 1382 | mctx->peer = peer; |
1375 | peer->reference_cnt++; | 1383 | peer->reference_cnt++; |
1376 | mctx->op_id = op_id; | 1384 | mctx->op_id = op_id; |
1377 | mctx->ah = ah; | 1385 | mctx->ah = ah; |
1378 | mctx->client = client; | 1386 | mctx->client = client; |
1379 | mctx->start = msg->start; | 1387 | mctx->start = msg->start; |
1380 | mctx->service = GNUNET_strdup (service); | 1388 | mctx->service = GNUNET_strdup(service); |
1381 | GNUNET_CONTAINER_DLL_insert_tail (mctx_head, | 1389 | GNUNET_CONTAINER_DLL_insert_tail(mctx_head, |
1382 | mctx_tail, | 1390 | mctx_tail, |
1383 | mctx); | 1391 | mctx); |
1384 | if (1 == mctx->start) | 1392 | if (1 == mctx->start) |
1385 | GNUNET_ARM_request_service_start (mctx->ah, | 1393 | GNUNET_ARM_request_service_start(mctx->ah, |
1386 | service, | 1394 | service, |
1387 | GNUNET_OS_INHERIT_STD_ERR, | 1395 | GNUNET_OS_INHERIT_STD_ERR, |
1388 | &service_manage_result_cb, | ||
1389 | mctx); | ||
1390 | else | ||
1391 | GNUNET_ARM_request_service_stop (mctx->ah, service, | ||
1392 | &service_manage_result_cb, | 1396 | &service_manage_result_cb, |
1393 | mctx); | 1397 | mctx); |
1394 | GNUNET_SERVICE_client_continue (client); | 1398 | else |
1399 | GNUNET_ARM_request_service_stop(mctx->ah, service, | ||
1400 | &service_manage_result_cb, | ||
1401 | mctx); | ||
1402 | GNUNET_SERVICE_client_continue(client); | ||
1395 | return; | 1403 | return; |
1396 | 1404 | ||
1397 | err_ret: | 1405 | err_ret: |
1398 | LOG (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); | 1406 | LOG(GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); |
1399 | GST_send_operation_fail_msg (client, op_id, emsg); | 1407 | GST_send_operation_fail_msg(client, op_id, emsg); |
1400 | GNUNET_free (emsg); | 1408 | GNUNET_free(emsg); |
1401 | GNUNET_SERVICE_client_continue (client); | 1409 | GNUNET_SERVICE_client_continue(client); |
1402 | } | 1410 | } |
1403 | 1411 | ||
1404 | 1412 | ||
@@ -1406,7 +1414,7 @@ handle_manage_peer_service (void *cls, | |||
1406 | * Stops and destroys all peers | 1414 | * Stops and destroys all peers |
1407 | */ | 1415 | */ |
1408 | void | 1416 | void |
1409 | GST_destroy_peers () | 1417 | GST_destroy_peers() |
1410 | { | 1418 | { |
1411 | struct Peer *peer; | 1419 | struct Peer *peer; |
1412 | unsigned int id; | 1420 | unsigned int id; |
@@ -1414,34 +1422,34 @@ GST_destroy_peers () | |||
1414 | if (NULL == GST_peer_list) | 1422 | if (NULL == GST_peer_list) |
1415 | return; | 1423 | return; |
1416 | for (id = 0; id < GST_peer_list_size; id++) | 1424 | for (id = 0; id < GST_peer_list_size; id++) |
1417 | { | 1425 | { |
1418 | peer = GST_peer_list[id]; | 1426 | peer = GST_peer_list[id]; |
1419 | if (NULL == peer) | 1427 | if (NULL == peer) |
1420 | continue; | 1428 | continue; |
1421 | /* If destroy flag is set it means that this peer should have been | 1429 | /* If destroy flag is set it means that this peer should have been |
1422 | * destroyed by a context which we destroy before */ | 1430 | * destroyed by a context which we destroy before */ |
1423 | GNUNET_break (GNUNET_NO == peer->destroy_flag); | 1431 | GNUNET_break(GNUNET_NO == peer->destroy_flag); |
1424 | /* counter should be zero as we free all contexts before */ | 1432 | /* counter should be zero as we free all contexts before */ |
1425 | GNUNET_break (0 == peer->reference_cnt); | 1433 | GNUNET_break(0 == peer->reference_cnt); |
1426 | if ((GNUNET_NO == peer->is_remote) && | 1434 | if ((GNUNET_NO == peer->is_remote) && |
1427 | (GNUNET_YES == peer->details.local.is_running)) | 1435 | (GNUNET_YES == peer->details.local.is_running)) |
1428 | GNUNET_TESTING_peer_kill (peer->details.local.peer); | 1436 | GNUNET_TESTING_peer_kill(peer->details.local.peer); |
1429 | } | 1437 | } |
1430 | for (id = 0; id < GST_peer_list_size; id++) | 1438 | for (id = 0; id < GST_peer_list_size; id++) |
1431 | { | ||
1432 | peer = GST_peer_list[id]; | ||
1433 | if (NULL == peer) | ||
1434 | continue; | ||
1435 | if (GNUNET_NO == peer->is_remote) | ||
1436 | { | 1439 | { |
1437 | if (GNUNET_YES == peer->details.local.is_running) | 1440 | peer = GST_peer_list[id]; |
1438 | GNUNET_TESTING_peer_wait (peer->details.local.peer); | 1441 | if (NULL == peer) |
1439 | GNUNET_TESTING_peer_destroy (peer->details.local.peer); | 1442 | continue; |
1440 | GNUNET_CONFIGURATION_destroy (peer->details.local.cfg); | 1443 | if (GNUNET_NO == peer->is_remote) |
1444 | { | ||
1445 | if (GNUNET_YES == peer->details.local.is_running) | ||
1446 | GNUNET_TESTING_peer_wait(peer->details.local.peer); | ||
1447 | GNUNET_TESTING_peer_destroy(peer->details.local.peer); | ||
1448 | GNUNET_CONFIGURATION_destroy(peer->details.local.cfg); | ||
1449 | } | ||
1450 | GNUNET_free(peer); | ||
1441 | } | 1451 | } |
1442 | GNUNET_free (peer); | 1452 | GNUNET_free_non_null(GST_peer_list); |
1443 | } | ||
1444 | GNUNET_free_non_null (GST_peer_list); | ||
1445 | GST_peer_list = NULL; | 1453 | GST_peer_list = NULL; |
1446 | GST_peer_list_size = 0; | 1454 | GST_peer_list_size = 0; |
1447 | } | 1455 | } |
@@ -1456,34 +1464,34 @@ GST_destroy_peers () | |||
1456 | * @param msg the message to relay | 1464 | * @param msg the message to relay |
1457 | */ | 1465 | */ |
1458 | static void | 1466 | static void |
1459 | shutdown_peers_reply_cb (void *cls, | 1467 | shutdown_peers_reply_cb(void *cls, |
1460 | const struct GNUNET_MessageHeader *msg) | 1468 | const struct GNUNET_MessageHeader *msg) |
1461 | { | 1469 | { |
1462 | struct ForwardedOperationContext *fo_ctxt = cls; | 1470 | struct ForwardedOperationContext *fo_ctxt = cls; |
1463 | struct HandlerContext_ShutdownPeers *hc; | 1471 | struct HandlerContext_ShutdownPeers *hc; |
1464 | 1472 | ||
1465 | hc = fo_ctxt->cls; | 1473 | hc = fo_ctxt->cls; |
1466 | GNUNET_assert (0 < hc->nslaves); | 1474 | GNUNET_assert(0 < hc->nslaves); |
1467 | hc->nslaves--; | 1475 | hc->nslaves--; |
1468 | if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS != | 1476 | if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS != |
1469 | ntohs (msg->type)) | 1477 | ntohs(msg->type)) |
1470 | hc->timeout = GNUNET_YES; | 1478 | hc->timeout = GNUNET_YES; |
1471 | if (0 == hc->nslaves) | 1479 | if (0 == hc->nslaves) |
1472 | { | 1480 | { |
1473 | if (GNUNET_YES == hc->timeout) | 1481 | if (GNUNET_YES == hc->timeout) |
1474 | GST_send_operation_fail_msg (fo_ctxt->client, | 1482 | GST_send_operation_fail_msg(fo_ctxt->client, |
1475 | fo_ctxt->operation_id, | 1483 | fo_ctxt->operation_id, |
1476 | "Timeout at a slave controller"); | 1484 | "Timeout at a slave controller"); |
1477 | else | 1485 | else |
1478 | GST_send_operation_success_msg (fo_ctxt->client, | 1486 | GST_send_operation_success_msg(fo_ctxt->client, |
1479 | fo_ctxt->operation_id); | 1487 | fo_ctxt->operation_id); |
1480 | GNUNET_free (hc); | 1488 | GNUNET_free(hc); |
1481 | hc = NULL; | 1489 | hc = NULL; |
1482 | } | 1490 | } |
1483 | GNUNET_CONTAINER_DLL_remove (fopcq_head, | 1491 | GNUNET_CONTAINER_DLL_remove(fopcq_head, |
1484 | fopcq_tail, | 1492 | fopcq_tail, |
1485 | fo_ctxt); | 1493 | fo_ctxt); |
1486 | GNUNET_free (fo_ctxt); | 1494 | GNUNET_free(fo_ctxt); |
1487 | } | 1495 | } |
1488 | 1496 | ||
1489 | 1497 | ||
@@ -1494,8 +1502,8 @@ shutdown_peers_reply_cb (void *cls, | |||
1494 | * @param msg the actual message | 1502 | * @param msg the actual message |
1495 | */ | 1503 | */ |
1496 | void | 1504 | void |
1497 | handle_shutdown_peers (void *cls, | 1505 | handle_shutdown_peers(void *cls, |
1498 | const struct GNUNET_TESTBED_ShutdownPeersMessage *msg) | 1506 | const struct GNUNET_TESTBED_ShutdownPeersMessage *msg) |
1499 | { | 1507 | { |
1500 | struct GNUNET_SERVICE_Client *client = cls; | 1508 | struct GNUNET_SERVICE_Client *client = cls; |
1501 | struct HandlerContext_ShutdownPeers *hc; | 1509 | struct HandlerContext_ShutdownPeers *hc; |
@@ -1504,48 +1512,48 @@ handle_shutdown_peers (void *cls, | |||
1504 | uint64_t op_id; | 1512 | uint64_t op_id; |
1505 | unsigned int cnt; | 1513 | unsigned int cnt; |
1506 | 1514 | ||
1507 | LOG_DEBUG ("Received SHUTDOWN_PEERS\n"); | 1515 | LOG_DEBUG("Received SHUTDOWN_PEERS\n"); |
1508 | /* Stop and destroy all peers */ | 1516 | /* Stop and destroy all peers */ |
1509 | GST_free_mctxq (); | 1517 | GST_free_mctxq(); |
1510 | GST_free_occq (); | 1518 | GST_free_occq(); |
1511 | GST_free_roccq (); | 1519 | GST_free_roccq(); |
1512 | GST_clear_fopcq (); | 1520 | GST_clear_fopcq(); |
1513 | /* Forward to all slaves which we have started */ | 1521 | /* Forward to all slaves which we have started */ |
1514 | op_id = GNUNET_ntohll (msg->operation_id); | 1522 | op_id = GNUNET_ntohll(msg->operation_id); |
1515 | hc = GNUNET_new (struct HandlerContext_ShutdownPeers); | 1523 | hc = GNUNET_new(struct HandlerContext_ShutdownPeers); |
1516 | /* FIXME: have a better implementation where we track which slaves are | 1524 | /* FIXME: have a better implementation where we track which slaves are |
1517 | started by this controller */ | 1525 | started by this controller */ |
1518 | for (cnt = 0; cnt < GST_slave_list_size; cnt++) | 1526 | for (cnt = 0; cnt < GST_slave_list_size; cnt++) |
1519 | { | 1527 | { |
1520 | slave = GST_slave_list[cnt]; | 1528 | slave = GST_slave_list[cnt]; |
1521 | if (NULL == slave) | 1529 | if (NULL == slave) |
1522 | continue; | 1530 | continue; |
1523 | if (NULL == slave->controller_proc) /* We didn't start the slave */ | 1531 | if (NULL == slave->controller_proc) /* We didn't start the slave */ |
1524 | continue; | 1532 | continue; |
1525 | LOG_DEBUG ("Forwarding SHUTDOWN_PEERS\n"); | 1533 | LOG_DEBUG("Forwarding SHUTDOWN_PEERS\n"); |
1526 | hc->nslaves++; | 1534 | hc->nslaves++; |
1527 | fo_ctxt = GNUNET_new (struct ForwardedOperationContext); | 1535 | fo_ctxt = GNUNET_new(struct ForwardedOperationContext); |
1528 | fo_ctxt->client = client; | 1536 | fo_ctxt->client = client; |
1529 | fo_ctxt->operation_id = op_id; | 1537 | fo_ctxt->operation_id = op_id; |
1530 | fo_ctxt->cls = hc; | 1538 | fo_ctxt->cls = hc; |
1531 | fo_ctxt->type = OP_SHUTDOWN_PEERS; | 1539 | fo_ctxt->type = OP_SHUTDOWN_PEERS; |
1532 | fo_ctxt->opc = | 1540 | fo_ctxt->opc = |
1533 | GNUNET_TESTBED_forward_operation_msg_ (slave->controller, | 1541 | GNUNET_TESTBED_forward_operation_msg_(slave->controller, |
1534 | fo_ctxt->operation_id, | 1542 | fo_ctxt->operation_id, |
1535 | &msg->header, | 1543 | &msg->header, |
1536 | shutdown_peers_reply_cb, | 1544 | shutdown_peers_reply_cb, |
1537 | fo_ctxt); | 1545 | fo_ctxt); |
1538 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 1546 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
1539 | fopcq_tail, | 1547 | fopcq_tail, |
1540 | fo_ctxt); | 1548 | fo_ctxt); |
1541 | } | 1549 | } |
1542 | LOG_DEBUG ("Shutting down peers\n"); | 1550 | LOG_DEBUG("Shutting down peers\n"); |
1543 | GST_destroy_peers (); | 1551 | GST_destroy_peers(); |
1544 | if (0 == hc->nslaves) | 1552 | if (0 == hc->nslaves) |
1545 | { | 1553 | { |
1546 | GST_send_operation_success_msg (client, | 1554 | GST_send_operation_success_msg(client, |
1547 | op_id); | 1555 | op_id); |
1548 | GNUNET_free (hc); | 1556 | GNUNET_free(hc); |
1549 | } | 1557 | } |
1550 | GNUNET_SERVICE_client_continue (client); | 1558 | GNUNET_SERVICE_client_continue(client); |
1551 | } | 1559 | } |
diff --git a/src/testbed/gnunet-testbed-profiler.c b/src/testbed/gnunet-testbed-profiler.c index d9401286c..e65ae6202 100644 --- a/src/testbed/gnunet-testbed-profiler.c +++ b/src/testbed/gnunet-testbed-profiler.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 | /** | 21 | /** |
22 | * @file testbed/gnunet-testbed-profiler.c | 22 | * @file testbed/gnunet-testbed-profiler.c |
@@ -32,8 +32,8 @@ | |||
32 | /** | 32 | /** |
33 | * Generic loggins shorthand | 33 | * Generic loggins shorthand |
34 | */ | 34 | */ |
35 | #define LOG(kind,...) \ | 35 | #define LOG(kind, ...) \ |
36 | GNUNET_log (kind, __VA_ARGS__) | 36 | GNUNET_log(kind, __VA_ARGS__) |
37 | 37 | ||
38 | 38 | ||
39 | /** | 39 | /** |
@@ -104,18 +104,18 @@ static int noninteractive; | |||
104 | * @param cls NULL | 104 | * @param cls NULL |
105 | */ | 105 | */ |
106 | static void | 106 | static void |
107 | do_shutdown (void *cls) | 107 | do_shutdown(void *cls) |
108 | { | 108 | { |
109 | if (NULL != abort_task) | 109 | if (NULL != abort_task) |
110 | { | 110 | { |
111 | GNUNET_SCHEDULER_cancel (abort_task); | 111 | GNUNET_SCHEDULER_cancel(abort_task); |
112 | abort_task = NULL; | 112 | abort_task = NULL; |
113 | } | 113 | } |
114 | if (NULL != cfg) | 114 | if (NULL != cfg) |
115 | { | 115 | { |
116 | GNUNET_CONFIGURATION_destroy (cfg); | 116 | GNUNET_CONFIGURATION_destroy(cfg); |
117 | cfg = NULL; | 117 | cfg = NULL; |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
@@ -125,13 +125,13 @@ do_shutdown (void *cls) | |||
125 | * @param cls NULL | 125 | * @param cls NULL |
126 | */ | 126 | */ |
127 | static void | 127 | static void |
128 | do_abort (void *cls) | 128 | do_abort(void *cls) |
129 | { | 129 | { |
130 | abort_task = NULL; | 130 | abort_task = NULL; |
131 | LOG (GNUNET_ERROR_TYPE_WARNING, | 131 | LOG(GNUNET_ERROR_TYPE_WARNING, |
132 | "Aborting\n"); | 132 | "Aborting\n"); |
133 | result = GNUNET_SYSERR; | 133 | result = GNUNET_SYSERR; |
134 | GNUNET_SCHEDULER_shutdown (); | 134 | GNUNET_SCHEDULER_shutdown(); |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
@@ -140,15 +140,15 @@ do_abort (void *cls) | |||
140 | * many failed | 140 | * many failed |
141 | */ | 141 | */ |
142 | static void | 142 | static void |
143 | print_overlay_links_summary () | 143 | print_overlay_links_summary() |
144 | { | 144 | { |
145 | static int printed_already; | 145 | static int printed_already; |
146 | 146 | ||
147 | if (GNUNET_YES == printed_already) | 147 | if (GNUNET_YES == printed_already) |
148 | return; | 148 | return; |
149 | printed_already = GNUNET_YES; | 149 | printed_already = GNUNET_YES; |
150 | printf ("%u links succeeded\n", established_links); | 150 | printf("%u links succeeded\n", established_links); |
151 | printf ("%u links failed due to timeouts\n", failed_links); | 151 | printf("%u links failed due to timeouts\n", failed_links); |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
@@ -159,41 +159,43 @@ print_overlay_links_summary () | |||
159 | * @param event the controller event | 159 | * @param event the controller event |
160 | */ | 160 | */ |
161 | static void | 161 | static void |
162 | controller_event_cb (void *cls, | 162 | controller_event_cb(void *cls, |
163 | const struct GNUNET_TESTBED_EventInformation *event) | 163 | const struct GNUNET_TESTBED_EventInformation *event) |
164 | { | 164 | { |
165 | switch (event->type) | 165 | switch (event->type) |
166 | { | ||
167 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
168 | /* Control reaches here when a peer linking operation fails */ | ||
169 | if (NULL != event->details.operation_finished.emsg) | ||
170 | { | 166 | { |
171 | printf ("F"); | 167 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: |
172 | fflush (stdout); | 168 | /* Control reaches here when a peer linking operation fails */ |
173 | failed_links++; | 169 | if (NULL != event->details.operation_finished.emsg) |
174 | if (++cont_fails > num_cont_fails) | 170 | { |
175 | { | 171 | printf("F"); |
176 | printf ("\nAborting due to very high failure rate\n"); | 172 | fflush(stdout); |
177 | print_overlay_links_summary (); | 173 | failed_links++; |
178 | GNUNET_SCHEDULER_shutdown (); | 174 | if (++cont_fails > num_cont_fails) |
179 | return; | 175 | { |
180 | } | 176 | printf("\nAborting due to very high failure rate\n"); |
177 | print_overlay_links_summary(); | ||
178 | GNUNET_SCHEDULER_shutdown(); | ||
179 | return; | ||
180 | } | ||
181 | } | ||
182 | break; | ||
183 | |||
184 | case GNUNET_TESTBED_ET_CONNECT: | ||
185 | { | ||
186 | if (0 != cont_fails) | ||
187 | cont_fails--; | ||
188 | if (0 == established_links) | ||
189 | printf("Establishing links. Please wait\n"); | ||
190 | printf("."); | ||
191 | fflush(stdout); | ||
192 | established_links++; | ||
181 | } | 193 | } |
182 | break; | 194 | break; |
183 | case GNUNET_TESTBED_ET_CONNECT: | 195 | |
184 | { | 196 | default: |
185 | if (0 != cont_fails) | 197 | GNUNET_break(0); |
186 | cont_fails--; | 198 | } |
187 | if (0 == established_links) | ||
188 | printf ("Establishing links. Please wait\n"); | ||
189 | printf ("."); | ||
190 | fflush (stdout); | ||
191 | established_links++; | ||
192 | } | ||
193 | break; | ||
194 | default: | ||
195 | GNUNET_break (0); | ||
196 | } | ||
197 | } | 199 | } |
198 | 200 | ||
199 | 201 | ||
@@ -209,30 +211,30 @@ controller_event_cb (void *cls, | |||
209 | * @param links_failed the number of overlay link | 211 | * @param links_failed the number of overlay link |
210 | */ | 212 | */ |
211 | static void | 213 | static void |
212 | test_run (void *cls, | 214 | test_run(void *cls, |
213 | struct GNUNET_TESTBED_RunHandle *h, | 215 | struct GNUNET_TESTBED_RunHandle *h, |
214 | unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, | 216 | unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, |
215 | unsigned int links_succeeded, | 217 | unsigned int links_succeeded, |
216 | unsigned int links_failed) | 218 | unsigned int links_failed) |
217 | { | 219 | { |
218 | result = GNUNET_OK; | 220 | result = GNUNET_OK; |
219 | fprintf (stdout, "\n"); | 221 | fprintf(stdout, "\n"); |
220 | print_overlay_links_summary (); | 222 | print_overlay_links_summary(); |
221 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 223 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
222 | if (noninteractive) | 224 | if (noninteractive) |
223 | { | 225 | { |
224 | GNUNET_SCHEDULER_cancel (abort_task); | 226 | GNUNET_SCHEDULER_cancel(abort_task); |
225 | abort_task = NULL; | 227 | abort_task = NULL; |
226 | return; | 228 | return; |
227 | } | 229 | } |
228 | #if (!ENABLE_SUPERMUC) | 230 | #if (!ENABLE_SUPERMUC) |
229 | fprintf (stdout, "Testbed running, waiting for keystroke to shut down\n"); | 231 | fprintf(stdout, "Testbed running, waiting for keystroke to shut down\n"); |
230 | fflush (stdout); | 232 | fflush(stdout); |
231 | (void) getc (stdin); | 233 | (void)getc(stdin); |
232 | #endif | 234 | #endif |
233 | fprintf (stdout, "Shutting down. Please wait\n"); | 235 | fprintf(stdout, "Shutting down. Please wait\n"); |
234 | fflush (stdout); | 236 | fflush(stdout); |
235 | GNUNET_SCHEDULER_shutdown (); | 237 | GNUNET_SCHEDULER_shutdown(); |
236 | } | 238 | } |
237 | 239 | ||
238 | 240 | ||
@@ -245,25 +247,25 @@ test_run (void *cls, | |||
245 | * @param config configuration | 247 | * @param config configuration |
246 | */ | 248 | */ |
247 | static void | 249 | static void |
248 | run (void *cls, char *const *args, const char *cfgfile, | 250 | run(void *cls, char *const *args, const char *cfgfile, |
249 | const struct GNUNET_CONFIGURATION_Handle *config) | 251 | const struct GNUNET_CONFIGURATION_Handle *config) |
250 | { | 252 | { |
251 | if (0 == num_peers) | 253 | if (0 == num_peers) |
252 | { | 254 | { |
253 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Exiting as the number of peers is %u\n"), | 255 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Exiting as the number of peers is %u\n"), |
254 | num_peers); | 256 | num_peers); |
255 | return; | 257 | return; |
256 | } | 258 | } |
257 | cfg = GNUNET_CONFIGURATION_dup (config); | 259 | cfg = GNUNET_CONFIGURATION_dup(config); |
258 | event_mask = 0; | 260 | event_mask = 0; |
259 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | 261 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); |
260 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 262 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
261 | GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask, | 263 | GNUNET_TESTBED_run(hosts_file, cfg, num_peers, event_mask, |
262 | &controller_event_cb, NULL, | 264 | &controller_event_cb, NULL, |
263 | &test_run, NULL); | 265 | &test_run, NULL); |
264 | abort_task = | 266 | abort_task = |
265 | GNUNET_SCHEDULER_add_shutdown (&do_abort, | 267 | GNUNET_SCHEDULER_add_shutdown(&do_abort, |
266 | NULL); | 268 | NULL); |
267 | } | 269 | } |
268 | 270 | ||
269 | 271 | ||
@@ -273,47 +275,47 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
273 | * @return 0 on success | 275 | * @return 0 on success |
274 | */ | 276 | */ |
275 | int | 277 | int |
276 | main (int argc, char *const *argv) | 278 | main(int argc, char *const *argv) |
277 | { | 279 | { |
278 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 280 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
279 | GNUNET_GETOPT_option_uint ('p', | 281 | GNUNET_GETOPT_option_uint('p', |
280 | "num-peers", | 282 | "num-peers", |
281 | "COUNT", | 283 | "COUNT", |
282 | gettext_noop ("create COUNT number of peers"), | 284 | gettext_noop("create COUNT number of peers"), |
283 | &num_peers), | 285 | &num_peers), |
284 | GNUNET_GETOPT_option_uint ('e', | 286 | GNUNET_GETOPT_option_uint('e', |
285 | "num-errors", | 287 | "num-errors", |
286 | "COUNT", | 288 | "COUNT", |
287 | gettext_noop ("tolerate COUNT number of continious timeout failures"), | 289 | gettext_noop("tolerate COUNT number of continious timeout failures"), |
288 | &num_cont_fails), | 290 | &num_cont_fails), |
289 | GNUNET_GETOPT_option_flag ('n', | 291 | GNUNET_GETOPT_option_flag('n', |
290 | "non-interactive", | 292 | "non-interactive", |
291 | gettext_noop ("run profiler in non-interactive mode where upon " | 293 | gettext_noop("run profiler in non-interactive mode where upon " |
292 | "testbed setup the profiler does not wait for a " | 294 | "testbed setup the profiler does not wait for a " |
293 | "keystroke but continues to run until a termination " | 295 | "keystroke but continues to run until a termination " |
294 | "signal is received"), | 296 | "signal is received"), |
295 | &noninteractive), | 297 | &noninteractive), |
296 | #if !ENABLE_SUPERMUC | 298 | #if !ENABLE_SUPERMUC |
297 | GNUNET_GETOPT_option_string ('H', | 299 | GNUNET_GETOPT_option_string('H', |
298 | "hosts", | 300 | "hosts", |
299 | "FILENAME", | 301 | "FILENAME", |
300 | gettext_noop ("name of the file with the login information for the testbed"), | 302 | gettext_noop("name of the file with the login information for the testbed"), |
301 | &hosts_file), | 303 | &hosts_file), |
302 | #endif | 304 | #endif |
303 | GNUNET_GETOPT_OPTION_END | 305 | GNUNET_GETOPT_OPTION_END |
304 | }; | 306 | }; |
305 | const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]"; | 307 | const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]"; |
306 | int ret; | 308 | int ret; |
307 | 309 | ||
308 | unsetenv ("XDG_DATA_HOME"); | 310 | unsetenv("XDG_DATA_HOME"); |
309 | unsetenv ("XDG_CONFIG_HOME"); | 311 | unsetenv("XDG_CONFIG_HOME"); |
310 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 312 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
311 | return 2; | 313 | return 2; |
312 | result = GNUNET_SYSERR; | 314 | result = GNUNET_SYSERR; |
313 | ret = | 315 | ret = |
314 | GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-profiler", binaryHelp, | 316 | GNUNET_PROGRAM_run(argc, argv, "gnunet-testbed-profiler", binaryHelp, |
315 | options, &run, NULL); | 317 | options, &run, NULL); |
316 | GNUNET_free ((void *) argv); | 318 | GNUNET_free((void *)argv); |
317 | if (GNUNET_OK != ret) | 319 | if (GNUNET_OK != ret) |
318 | return ret; | 320 | return ret; |
319 | if (GNUNET_OK != result) | 321 | if (GNUNET_OK != result) |
diff --git a/src/testbed/gnunet_mpi_test.c b/src/testbed/gnunet_mpi_test.c index 7fe7a75d7..1c2696048 100644 --- a/src/testbed/gnunet_mpi_test.c +++ b/src/testbed/gnunet_mpi_test.c | |||
@@ -5,11 +5,11 @@ | |||
5 | /** | 5 | /** |
6 | * Generic logging shorthand | 6 | * Generic logging shorthand |
7 | */ | 7 | */ |
8 | #define LOG(kind,...) \ | 8 | #define LOG(kind, ...) \ |
9 | GNUNET_log_from (kind, "gnunet-mpi-test", __VA_ARGS__) | 9 | GNUNET_log_from(kind, "gnunet-mpi-test", __VA_ARGS__) |
10 | 10 | ||
11 | int | 11 | int |
12 | main (int argc, char *argv[]) | 12 | main(int argc, char *argv[]) |
13 | { | 13 | { |
14 | char *msg; | 14 | char *msg; |
15 | char *filename; | 15 | char *filename; |
@@ -26,82 +26,82 @@ main (int argc, char *argv[]) | |||
26 | 26 | ||
27 | ret = GNUNET_SYSERR; | 27 | ret = GNUNET_SYSERR; |
28 | if (argc < 2) | 28 | if (argc < 2) |
29 | { | 29 | { |
30 | printf ("Need arguments: gnunet-mpi-test <cmd> <cmd_args>"); | 30 | printf("Need arguments: gnunet-mpi-test <cmd> <cmd_args>"); |
31 | return 1; | 31 | return 1; |
32 | } | 32 | } |
33 | if (MPI_SUCCESS != MPI_Init (&argc, &argv)) | 33 | if (MPI_SUCCESS != MPI_Init(&argc, &argv)) |
34 | { | 34 | { |
35 | GNUNET_break (0); | 35 | GNUNET_break(0); |
36 | return 1; | 36 | return 1; |
37 | } | 37 | } |
38 | if (MPI_SUCCESS != MPI_Comm_size (MPI_COMM_WORLD, &ntasks)) | 38 | if (MPI_SUCCESS != MPI_Comm_size(MPI_COMM_WORLD, &ntasks)) |
39 | { | 39 | { |
40 | GNUNET_break (0); | 40 | GNUNET_break(0); |
41 | goto finalize; | 41 | goto finalize; |
42 | } | 42 | } |
43 | if (MPI_SUCCESS != MPI_Comm_rank (MPI_COMM_WORLD, &rank)) | 43 | if (MPI_SUCCESS != MPI_Comm_rank(MPI_COMM_WORLD, &rank)) |
44 | { | 44 | { |
45 | GNUNET_break (0); | 45 | GNUNET_break(0); |
46 | goto finalize; | 46 | goto finalize; |
47 | } | 47 | } |
48 | pid = getpid (); | 48 | pid = getpid(); |
49 | (void) GNUNET_asprintf (&filename, "%d-%d.mpiout", (int) pid, rank); | 49 | (void)GNUNET_asprintf(&filename, "%d-%d.mpiout", (int)pid, rank); |
50 | msg_size = GNUNET_asprintf (&msg, "My rank is: %d\n", rank); | 50 | msg_size = GNUNET_asprintf(&msg, "My rank is: %d\n", rank); |
51 | printf ("%s", msg); | 51 | printf("%s", msg); |
52 | if (msg_size == | 52 | if (msg_size == |
53 | GNUNET_DISK_fn_write (filename, msg, msg_size, | 53 | GNUNET_DISK_fn_write(filename, msg, msg_size, |
54 | GNUNET_DISK_PERM_USER_READ | | 54 | GNUNET_DISK_PERM_USER_READ | |
55 | GNUNET_DISK_PERM_GROUP_READ | | 55 | GNUNET_DISK_PERM_GROUP_READ | |
56 | GNUNET_DISK_PERM_USER_WRITE | | 56 | GNUNET_DISK_PERM_USER_WRITE | |
57 | GNUNET_DISK_PERM_GROUP_WRITE)) | 57 | GNUNET_DISK_PERM_GROUP_WRITE)) |
58 | ret = GNUNET_OK; | 58 | ret = GNUNET_OK; |
59 | GNUNET_free (filename); | 59 | GNUNET_free(filename); |
60 | GNUNET_free (msg); | 60 | GNUNET_free(msg); |
61 | if (GNUNET_OK != ret) | 61 | if (GNUNET_OK != ret) |
62 | { | 62 | { |
63 | GNUNET_break (0); | 63 | GNUNET_break(0); |
64 | goto finalize; | 64 | goto finalize; |
65 | } | 65 | } |
66 | 66 | ||
67 | ret = GNUNET_SYSERR; | 67 | ret = GNUNET_SYSERR; |
68 | argv2 = GNUNET_malloc (sizeof (char *) * (argc)); | 68 | argv2 = GNUNET_malloc(sizeof(char *) * (argc)); |
69 | for (cnt = 1; cnt < argc; cnt++) | 69 | for (cnt = 1; cnt < argc; cnt++) |
70 | argv2[cnt - 1] = argv[cnt]; | 70 | argv2[cnt - 1] = argv[cnt]; |
71 | proc = | 71 | proc = |
72 | GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, | 72 | GNUNET_OS_start_process_vap(GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, |
73 | NULL, NULL, argv2[0], argv2); | 73 | NULL, NULL, argv2[0], argv2); |
74 | if (NULL == proc) | 74 | if (NULL == proc) |
75 | { | 75 | { |
76 | printf ("Cannot exec\n"); | 76 | printf("Cannot exec\n"); |
77 | GNUNET_free (argv2); | 77 | GNUNET_free(argv2); |
78 | goto finalize; | 78 | goto finalize; |
79 | } | 79 | } |
80 | do | 80 | do |
81 | { | 81 | { |
82 | (void) sleep (1); | 82 | (void)sleep(1); |
83 | ret = GNUNET_OS_process_status (proc, &proc_status, &code); | 83 | ret = GNUNET_OS_process_status(proc, &proc_status, &code); |
84 | } | 84 | } |
85 | while (GNUNET_NO == ret); | 85 | while (GNUNET_NO == ret); |
86 | GNUNET_free (argv2); | 86 | GNUNET_free(argv2); |
87 | GNUNET_assert (GNUNET_NO != ret); | 87 | GNUNET_assert(GNUNET_NO != ret); |
88 | if (GNUNET_OK == ret) | 88 | if (GNUNET_OK == ret) |
89 | { | ||
90 | if (0 != code) | ||
91 | { | 89 | { |
92 | LOG (GNUNET_ERROR_TYPE_WARNING, "Child terminated abnormally\n"); | 90 | if (0 != code) |
93 | ret = GNUNET_SYSERR; | 91 | { |
94 | GNUNET_break (0); | 92 | LOG(GNUNET_ERROR_TYPE_WARNING, "Child terminated abnormally\n"); |
95 | goto finalize; | 93 | ret = GNUNET_SYSERR; |
94 | GNUNET_break(0); | ||
95 | goto finalize; | ||
96 | } | ||
96 | } | 97 | } |
97 | } | ||
98 | else | 98 | else |
99 | GNUNET_break (0); | 99 | GNUNET_break(0); |
100 | 100 | ||
101 | finalize: | 101 | finalize: |
102 | (void) MPI_Finalize (); | 102 | (void)MPI_Finalize(); |
103 | if (GNUNET_OK == ret) | 103 | if (GNUNET_OK == ret) |
104 | return 0; | 104 | return 0; |
105 | printf ("Something went wrong\n"); | 105 | printf("Something went wrong\n"); |
106 | return 1; | 106 | return 1; |
107 | } | 107 | } |
diff --git a/src/testbed/gnunet_testbed_mpi_spawn.c b/src/testbed/gnunet_testbed_mpi_spawn.c index d69812cd2..b79c431c4 100644 --- a/src/testbed/gnunet_testbed_mpi_spawn.c +++ b/src/testbed/gnunet_testbed_mpi_spawn.c | |||
@@ -6,14 +6,14 @@ | |||
6 | /** | 6 | /** |
7 | * Generic logging shorthand | 7 | * Generic logging shorthand |
8 | */ | 8 | */ |
9 | #define LOG(kind,...) \ | 9 | #define LOG(kind, ...) \ |
10 | GNUNET_log (kind, __VA_ARGS__) | 10 | GNUNET_log(kind, __VA_ARGS__) |
11 | 11 | ||
12 | /** | 12 | /** |
13 | * Debug logging shorthand | 13 | * Debug logging shorthand |
14 | */ | 14 | */ |
15 | #define LOG_DEBUG(...) \ | 15 | #define LOG_DEBUG(...) \ |
16 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 16 | LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * Global result | 19 | * Global result |
@@ -69,53 +69,54 @@ static struct GNUNET_SCHEDULER_Task * child_death_task_id; | |||
69 | * The shutdown task | 69 | * The shutdown task |
70 | */ | 70 | */ |
71 | static void | 71 | static void |
72 | shutdown_task (void *cls) | 72 | shutdown_task(void *cls) |
73 | { | 73 | { |
74 | if (0 != child_exit_code) | 74 | if (0 != child_exit_code) |
75 | { | 75 | { |
76 | LOG (GNUNET_ERROR_TYPE_WARNING, "Child exited with error code: %lu\n", | 76 | LOG(GNUNET_ERROR_TYPE_WARNING, "Child exited with error code: %lu\n", |
77 | child_exit_code); | 77 | child_exit_code); |
78 | ret = 128 + (int) child_exit_code; | 78 | ret = 128 + (int)child_exit_code; |
79 | } | 79 | } |
80 | if (0 != fh) | 80 | if (0 != fh) |
81 | { | 81 | { |
82 | close (fh); | 82 | close(fh); |
83 | } | 83 | } |
84 | if ((NULL != fn) && (0 != unlink (fn))) | 84 | if ((NULL != fn) && (0 != unlink(fn))) |
85 | { | 85 | { |
86 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "open"); | 86 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "open"); |
87 | ret = GNUNET_SYSERR; | 87 | ret = GNUNET_SYSERR; |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | 91 | ||
92 | static void | 92 | static void |
93 | terminate_task (void *cls) | 93 | terminate_task(void *cls) |
94 | { | 94 | { |
95 | static int hard_kill; | 95 | static int hard_kill; |
96 | 96 | ||
97 | GNUNET_assert (NULL != child); | 97 | GNUNET_assert(NULL != child); |
98 | terminate_task_id = | 98 | terminate_task_id = |
99 | GNUNET_SCHEDULER_add_shutdown (&terminate_task, NULL); | 99 | GNUNET_SCHEDULER_add_shutdown(&terminate_task, NULL); |
100 | if (0 != hard_kill) | 100 | if (0 != hard_kill) |
101 | { | ||
102 | switch (hard_kill) | ||
103 | { | 101 | { |
104 | case 1: | 102 | switch (hard_kill) |
105 | case 2: | 103 | { |
106 | LOG (GNUNET_ERROR_TYPE_WARNING, | 104 | case 1: |
107 | "%d more interrupts needed to send SIGKILL to the child\n", | 105 | case 2: |
108 | 3 - hard_kill); | 106 | LOG(GNUNET_ERROR_TYPE_WARNING, |
109 | hard_kill++; | 107 | "%d more interrupts needed to send SIGKILL to the child\n", |
110 | return; | 108 | 3 - hard_kill); |
111 | case 3: | 109 | hard_kill++; |
112 | GNUNET_break (0 == GNUNET_OS_process_kill (child, SIGKILL)); | 110 | return; |
113 | return; | 111 | |
112 | case 3: | ||
113 | GNUNET_break(0 == GNUNET_OS_process_kill(child, SIGKILL)); | ||
114 | return; | ||
115 | } | ||
114 | } | 116 | } |
115 | } | ||
116 | hard_kill++; | 117 | hard_kill++; |
117 | GNUNET_break (0 == GNUNET_OS_process_kill (child, GNUNET_TERM_SIG)); | 118 | GNUNET_break(0 == GNUNET_OS_process_kill(child, GNUNET_TERM_SIG)); |
118 | LOG (GNUNET_ERROR_TYPE_INFO, _("Waiting for child to exit.\n")); | 119 | LOG(GNUNET_ERROR_TYPE_INFO, _("Waiting for child to exit.\n")); |
119 | } | 120 | } |
120 | 121 | ||
121 | 122 | ||
@@ -126,33 +127,33 @@ terminate_task (void *cls) | |||
126 | * @param cls closure, NULL if we need to self-restart | 127 | * @param cls closure, NULL if we need to self-restart |
127 | */ | 128 | */ |
128 | static void | 129 | static void |
129 | child_death_task (void *cls) | 130 | child_death_task(void *cls) |
130 | { | 131 | { |
131 | const struct GNUNET_DISK_FileHandle *pr; | 132 | const struct GNUNET_DISK_FileHandle *pr; |
132 | char c[16]; | 133 | char c[16]; |
133 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 134 | const struct GNUNET_SCHEDULER_TaskContext *tc; |
134 | 135 | ||
135 | 136 | ||
136 | pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); | 137 | pr = GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ); |
137 | child_death_task_id = NULL; | 138 | child_death_task_id = NULL; |
138 | tc = GNUNET_SCHEDULER_get_task_context (); | 139 | tc = GNUNET_SCHEDULER_get_task_context(); |
139 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) | 140 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) |
140 | { | 141 | { |
141 | child_death_task_id = | 142 | child_death_task_id = |
142 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 143 | GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, |
143 | pr, &child_death_task, NULL); | 144 | pr, &child_death_task, NULL); |
144 | return; | 145 | return; |
145 | } | 146 | } |
146 | /* consume the signal */ | 147 | /* consume the signal */ |
147 | GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c))); | 148 | GNUNET_break(0 < GNUNET_DISK_file_read(pr, &c, sizeof(c))); |
148 | LOG_DEBUG ("Child died\n"); | 149 | LOG_DEBUG("Child died\n"); |
149 | GNUNET_SCHEDULER_cancel (terminate_task_id); | 150 | GNUNET_SCHEDULER_cancel(terminate_task_id); |
150 | terminate_task_id = NULL; | 151 | terminate_task_id = NULL; |
151 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_status (child, &child_status, | 152 | GNUNET_assert(GNUNET_OK == GNUNET_OS_process_status(child, &child_status, |
152 | &child_exit_code)); | 153 | &child_exit_code)); |
153 | GNUNET_OS_process_destroy (child); | 154 | GNUNET_OS_process_destroy(child); |
154 | child = NULL; | 155 | child = NULL; |
155 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 156 | GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); |
156 | } | 157 | } |
157 | 158 | ||
158 | 159 | ||
@@ -161,11 +162,11 @@ destroy_hosts(struct GNUNET_TESTBED_Host **hosts, unsigned int nhosts) | |||
161 | { | 162 | { |
162 | unsigned int host; | 163 | unsigned int host; |
163 | 164 | ||
164 | GNUNET_assert (NULL != hosts); | 165 | GNUNET_assert(NULL != hosts); |
165 | for (host = 0; host < nhosts; host++) | 166 | for (host = 0; host < nhosts; host++) |
166 | if (NULL != hosts[host]) | 167 | if (NULL != hosts[host]) |
167 | GNUNET_TESTBED_host_destroy (hosts[host]); | 168 | GNUNET_TESTBED_host_destroy(hosts[host]); |
168 | GNUNET_free (hosts); | 169 | GNUNET_free(hosts); |
169 | hosts = NULL; | 170 | hosts = NULL; |
170 | } | 171 | } |
171 | 172 | ||
@@ -176,7 +177,7 @@ destroy_hosts(struct GNUNET_TESTBED_Host **hosts, unsigned int nhosts) | |||
176 | * @param cls NULL | 177 | * @param cls NULL |
177 | */ | 178 | */ |
178 | static void | 179 | static void |
179 | run (void *cls) | 180 | run(void *cls) |
180 | { | 181 | { |
181 | struct GNUNET_TESTBED_Host **hosts; | 182 | struct GNUNET_TESTBED_Host **hosts; |
182 | const struct GNUNET_CONFIGURATION_Handle *null_cfg; | 183 | const struct GNUNET_CONFIGURATION_Handle *null_cfg; |
@@ -185,78 +186,78 @@ run (void *cls) | |||
185 | size_t hostname_len; | 186 | size_t hostname_len; |
186 | unsigned int nhosts; | 187 | unsigned int nhosts; |
187 | 188 | ||
188 | null_cfg = GNUNET_CONFIGURATION_create (); | 189 | null_cfg = GNUNET_CONFIGURATION_create(); |
189 | nhosts = GNUNET_TESTBED_hosts_load_from_loadleveler (null_cfg, &hosts); | 190 | nhosts = GNUNET_TESTBED_hosts_load_from_loadleveler(null_cfg, &hosts); |
190 | if (0 == nhosts) | 191 | if (0 == nhosts) |
191 | { | 192 | { |
192 | GNUNET_break (0); | 193 | GNUNET_break(0); |
193 | ret = GNUNET_SYSERR; | 194 | ret = GNUNET_SYSERR; |
194 | return; | 195 | return; |
195 | } | 196 | } |
196 | hostname_len = GNUNET_OS_get_hostname_max_length (); | 197 | hostname_len = GNUNET_OS_get_hostname_max_length(); |
197 | hostname = GNUNET_malloc (hostname_len); | 198 | hostname = GNUNET_malloc(hostname_len); |
198 | if (0 != gethostname (hostname, hostname_len)) | 199 | if (0 != gethostname(hostname, hostname_len)) |
199 | { | 200 | { |
200 | LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot get hostname. Exiting\n"); | 201 | LOG(GNUNET_ERROR_TYPE_ERROR, "Cannot get hostname. Exiting\n"); |
201 | GNUNET_free (hostname); | 202 | GNUNET_free(hostname); |
202 | destroy_hosts (hosts, nhosts); | 203 | destroy_hosts(hosts, nhosts); |
203 | ret = GNUNET_SYSERR; | 204 | ret = GNUNET_SYSERR; |
204 | return; | 205 | return; |
205 | } | 206 | } |
206 | if (NULL == strstr (GNUNET_TESTBED_host_get_hostname (hosts[0]), hostname)) | 207 | if (NULL == strstr(GNUNET_TESTBED_host_get_hostname(hosts[0]), hostname)) |
207 | { | 208 | { |
208 | LOG_DEBUG ("Exiting as `%s' is not the lowest host\n", hostname); | 209 | LOG_DEBUG("Exiting as `%s' is not the lowest host\n", hostname); |
209 | GNUNET_free (hostname); | 210 | GNUNET_free(hostname); |
210 | ret = GNUNET_OK; | 211 | ret = GNUNET_OK; |
211 | return; | 212 | return; |
212 | } | 213 | } |
213 | LOG_DEBUG ("Will be executing `%s' on host `%s'\n", argv2[0], hostname); | 214 | LOG_DEBUG("Will be executing `%s' on host `%s'\n", argv2[0], hostname); |
214 | GNUNET_free (hostname); | 215 | GNUNET_free(hostname); |
215 | destroy_hosts (hosts, nhosts); | 216 | destroy_hosts(hosts, nhosts); |
216 | tmpdir = getenv ("TMPDIR"); | 217 | tmpdir = getenv("TMPDIR"); |
217 | if (NULL == tmpdir) | 218 | if (NULL == tmpdir) |
218 | tmpdir = getenv ("TMP"); | 219 | tmpdir = getenv("TMP"); |
219 | if (NULL == tmpdir) | 220 | if (NULL == tmpdir) |
220 | tmpdir = getenv ("TEMP"); | 221 | tmpdir = getenv("TEMP"); |
221 | if (NULL == tmpdir) | 222 | if (NULL == tmpdir) |
222 | tmpdir = "/tmp"; | 223 | tmpdir = "/tmp"; |
223 | (void) GNUNET_asprintf (&fn, "%s/gnunet-testbed-spawn.lock", tmpdir); | 224 | (void)GNUNET_asprintf(&fn, "%s/gnunet-testbed-spawn.lock", tmpdir); |
224 | /* Open the unique file; we can create it then we can spawn the child process | 225 | /* Open the unique file; we can create it then we can spawn the child process |
225 | else we exit */ | 226 | else we exit */ |
226 | fh = open (fn, O_CREAT | O_EXCL | O_CLOEXEC, | 227 | fh = open(fn, O_CREAT | O_EXCL | O_CLOEXEC, |
227 | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); | 228 | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); |
228 | if (-1 == fh) | 229 | if (-1 == fh) |
229 | { | ||
230 | if (EEXIST == errno) | ||
231 | { | 230 | { |
232 | LOG_DEBUG ("Lock file already created by other process. Exiting\n"); | 231 | if (EEXIST == errno) |
233 | ret = GNUNET_OK; | 232 | { |
233 | LOG_DEBUG("Lock file already created by other process. Exiting\n"); | ||
234 | ret = GNUNET_OK; | ||
235 | return; | ||
236 | } | ||
237 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "open"); | ||
238 | ret = GNUNET_SYSERR; | ||
234 | return; | 239 | return; |
235 | } | 240 | } |
236 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "open"); | ||
237 | ret = GNUNET_SYSERR; | ||
238 | return; | ||
239 | } | ||
240 | /* Spawn the new process here */ | 241 | /* Spawn the new process here */ |
241 | LOG (GNUNET_ERROR_TYPE_INFO, _("Spawning process `%s'\n"), argv2[0]); | 242 | LOG(GNUNET_ERROR_TYPE_INFO, _("Spawning process `%s'\n"), argv2[0]); |
242 | child = GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, | 243 | child = GNUNET_OS_start_process_vap(GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, |
243 | NULL, NULL, | 244 | NULL, NULL, |
244 | argv2[0], argv2); | 245 | argv2[0], argv2); |
245 | if (NULL == child) | 246 | if (NULL == child) |
246 | { | 247 | { |
247 | GNUNET_break (0); | 248 | GNUNET_break(0); |
248 | ret = GNUNET_SYSERR; | 249 | ret = GNUNET_SYSERR; |
249 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 250 | GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); |
250 | return; | 251 | return; |
251 | } | 252 | } |
252 | ret = GNUNET_OK; | 253 | ret = GNUNET_OK; |
253 | terminate_task_id = | 254 | terminate_task_id = |
254 | GNUNET_SCHEDULER_add_shutdown (&terminate_task, NULL); | 255 | GNUNET_SCHEDULER_add_shutdown(&terminate_task, NULL); |
255 | child_death_task_id = | 256 | child_death_task_id = |
256 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 257 | GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, |
257 | GNUNET_DISK_pipe_handle (sigpipe, | 258 | GNUNET_DISK_pipe_handle(sigpipe, |
258 | GNUNET_DISK_PIPE_END_READ), | 259 | GNUNET_DISK_PIPE_END_READ), |
259 | &child_death_task, NULL); | 260 | &child_death_task, NULL); |
260 | } | 261 | } |
261 | 262 | ||
262 | 263 | ||
@@ -264,16 +265,16 @@ run (void *cls) | |||
264 | * Signal handler called for SIGCHLD. | 265 | * Signal handler called for SIGCHLD. |
265 | */ | 266 | */ |
266 | static void | 267 | static void |
267 | sighandler_child_death () | 268 | sighandler_child_death() |
268 | { | 269 | { |
269 | static char c; | 270 | static char c; |
270 | int old_errno = errno; /* back-up errno */ | 271 | int old_errno = errno; /* back-up errno */ |
271 | 272 | ||
272 | GNUNET_break (1 == | 273 | GNUNET_break(1 == |
273 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle | 274 | GNUNET_DISK_file_write(GNUNET_DISK_pipe_handle |
274 | (sigpipe, GNUNET_DISK_PIPE_END_WRITE), | 275 | (sigpipe, GNUNET_DISK_PIPE_END_WRITE), |
275 | &c, sizeof (c))); | 276 | &c, sizeof(c))); |
276 | errno = old_errno; /* restore errno */ | 277 | errno = old_errno; /* restore errno */ |
277 | } | 278 | } |
278 | 279 | ||
279 | 280 | ||
@@ -281,45 +282,45 @@ sighandler_child_death () | |||
281 | * Execution start point | 282 | * Execution start point |
282 | */ | 283 | */ |
283 | int | 284 | int |
284 | main (int argc, char *argv[]) | 285 | main(int argc, char *argv[]) |
285 | { | 286 | { |
286 | struct GNUNET_SIGNAL_Context *shc_chld; | 287 | struct GNUNET_SIGNAL_Context *shc_chld; |
287 | unsigned int cnt; | 288 | unsigned int cnt; |
288 | 289 | ||
289 | ret = -1; | 290 | ret = -1; |
290 | if (argc < 2) | 291 | if (argc < 2) |
291 | { | 292 | { |
292 | printf ("Need arguments: gnunet-testbed-mpi-spawn <cmd> <cmd_args>"); | 293 | printf("Need arguments: gnunet-testbed-mpi-spawn <cmd> <cmd_args>"); |
293 | return 1; | 294 | return 1; |
294 | } | 295 | } |
295 | if (GNUNET_OK != GNUNET_log_setup ("gnunet-testbed-spawn", NULL, NULL)) | 296 | if (GNUNET_OK != GNUNET_log_setup("gnunet-testbed-spawn", NULL, NULL)) |
296 | { | 297 | { |
297 | GNUNET_break (0); | 298 | GNUNET_break(0); |
298 | return 1; | 299 | return 1; |
299 | } | 300 | } |
300 | if (NULL == (sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, | 301 | if (NULL == (sigpipe = GNUNET_DISK_pipe(GNUNET_NO, GNUNET_NO, |
301 | GNUNET_NO, GNUNET_NO))) | 302 | GNUNET_NO, GNUNET_NO))) |
302 | { | 303 | { |
303 | GNUNET_break (0); | 304 | GNUNET_break(0); |
304 | ret = GNUNET_SYSERR; | 305 | ret = GNUNET_SYSERR; |
305 | return 1; | 306 | return 1; |
306 | } | 307 | } |
307 | shc_chld = | 308 | shc_chld = |
308 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); | 309 | GNUNET_SIGNAL_handler_install(GNUNET_SIGCHLD, &sighandler_child_death); |
309 | if (NULL == shc_chld) | 310 | if (NULL == shc_chld) |
310 | { | 311 | { |
311 | LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot install a signal handler\n"); | 312 | LOG(GNUNET_ERROR_TYPE_ERROR, "Cannot install a signal handler\n"); |
312 | return 1; | 313 | return 1; |
313 | } | 314 | } |
314 | argv2 = GNUNET_malloc (sizeof (char *) * argc); | 315 | argv2 = GNUNET_malloc(sizeof(char *) * argc); |
315 | for (cnt = 1; cnt < argc; cnt++) | 316 | for (cnt = 1; cnt < argc; cnt++) |
316 | argv2[cnt - 1] = argv[cnt]; | 317 | argv2[cnt - 1] = argv[cnt]; |
317 | GNUNET_SCHEDULER_run (run, NULL); | 318 | GNUNET_SCHEDULER_run(run, NULL); |
318 | GNUNET_free (argv2); | 319 | GNUNET_free(argv2); |
319 | GNUNET_SIGNAL_handler_uninstall (shc_chld); | 320 | GNUNET_SIGNAL_handler_uninstall(shc_chld); |
320 | shc_chld = NULL; | 321 | shc_chld = NULL; |
321 | GNUNET_DISK_pipe_close (sigpipe); | 322 | GNUNET_DISK_pipe_close(sigpipe); |
322 | GNUNET_free_non_null (fn); | 323 | GNUNET_free_non_null(fn); |
323 | if (GNUNET_OK != ret) | 324 | if (GNUNET_OK != ret) |
324 | return ret; | 325 | return ret; |
325 | return 0; | 326 | return 0; |
diff --git a/src/testbed/test_gnunet_helper_testbed.c b/src/testbed/test_gnunet_helper_testbed.c index 851375291..8bf1fd7ca 100644 --- a/src/testbed/test_gnunet_helper_testbed.c +++ b/src/testbed/test_gnunet_helper_testbed.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -36,8 +36,8 @@ | |||
36 | /** | 36 | /** |
37 | * Generic logging shortcut | 37 | * Generic logging shortcut |
38 | */ | 38 | */ |
39 | #define LOG(kind,...) \ | 39 | #define LOG(kind, ...) \ |
40 | GNUNET_log (kind, __VA_ARGS__) | 40 | GNUNET_log(kind, __VA_ARGS__) |
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
@@ -82,15 +82,15 @@ static int result; | |||
82 | * @param cls NULL | 82 | * @param cls NULL |
83 | */ | 83 | */ |
84 | static void | 84 | static void |
85 | do_shutdown (void *cls) | 85 | do_shutdown(void *cls) |
86 | { | 86 | { |
87 | if (NULL != abort_task) | 87 | if (NULL != abort_task) |
88 | GNUNET_SCHEDULER_cancel (abort_task); | 88 | GNUNET_SCHEDULER_cancel(abort_task); |
89 | if (NULL != helper) | 89 | if (NULL != helper) |
90 | GNUNET_HELPER_stop (helper, GNUNET_NO); | 90 | GNUNET_HELPER_stop(helper, GNUNET_NO); |
91 | GNUNET_free_non_null (msg); | 91 | GNUNET_free_non_null(msg); |
92 | if (NULL != cfg) | 92 | if (NULL != cfg) |
93 | GNUNET_CONFIGURATION_destroy (cfg); | 93 | GNUNET_CONFIGURATION_destroy(cfg); |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
@@ -100,15 +100,15 @@ do_shutdown (void *cls) | |||
100 | * @param cls NULL | 100 | * @param cls NULL |
101 | */ | 101 | */ |
102 | static void | 102 | static void |
103 | do_abort (void *cls) | 103 | do_abort(void *cls) |
104 | { | 104 | { |
105 | abort_task = NULL; | 105 | abort_task = NULL; |
106 | LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); | 106 | LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); |
107 | result = GNUNET_SYSERR; | 107 | result = GNUNET_SYSERR; |
108 | if (NULL != shandle) | 108 | if (NULL != shandle) |
109 | GNUNET_HELPER_send_cancel (shandle); | 109 | GNUNET_HELPER_send_cancel(shandle); |
110 | if (NULL == shutdown_task) | 110 | if (NULL == shutdown_task) |
111 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 111 | shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
112 | } | 112 | } |
113 | 113 | ||
114 | 114 | ||
@@ -121,13 +121,13 @@ do_abort (void *cls) | |||
121 | * #GNUNET_SYSERR during GNUNET_HELPER_stop() | 121 | * #GNUNET_SYSERR during GNUNET_HELPER_stop() |
122 | */ | 122 | */ |
123 | static void | 123 | static void |
124 | cont_cb (void *cls, | 124 | cont_cb(void *cls, |
125 | int result) | 125 | int result) |
126 | { | 126 | { |
127 | shandle = NULL; | 127 | shandle = NULL; |
128 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 128 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
129 | "Message sent\n"); | 129 | "Message sent\n"); |
130 | GNUNET_assert (GNUNET_OK == result); | 130 | GNUNET_assert(GNUNET_OK == result); |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
@@ -143,35 +143,35 @@ cont_cb (void *cls, | |||
143 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing | 143 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing |
144 | */ | 144 | */ |
145 | static int | 145 | static int |
146 | mst_cb (void *cls, | 146 | mst_cb(void *cls, |
147 | const struct GNUNET_MessageHeader *message) | 147 | const struct GNUNET_MessageHeader *message) |
148 | { | 148 | { |
149 | const struct GNUNET_TESTBED_HelperReply *msg; | 149 | const struct GNUNET_TESTBED_HelperReply *msg; |
150 | char *config; | 150 | char *config; |
151 | uLongf config_size; | 151 | uLongf config_size; |
152 | uLongf xconfig_size; | 152 | uLongf xconfig_size; |
153 | 153 | ||
154 | msg = (const struct GNUNET_TESTBED_HelperReply *) message; | 154 | msg = (const struct GNUNET_TESTBED_HelperReply *)message; |
155 | config_size = 0; | 155 | config_size = 0; |
156 | xconfig_size = 0; | 156 | xconfig_size = 0; |
157 | GNUNET_assert (sizeof (struct GNUNET_TESTBED_HelperReply) < | 157 | GNUNET_assert(sizeof(struct GNUNET_TESTBED_HelperReply) < |
158 | ntohs (msg->header.size)); | 158 | ntohs(msg->header.size)); |
159 | GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY == | 159 | GNUNET_assert(GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY == |
160 | ntohs (msg->header.type)); | 160 | ntohs(msg->header.type)); |
161 | config_size = (uLongf) ntohs (msg->config_size); | 161 | config_size = (uLongf)ntohs(msg->config_size); |
162 | xconfig_size = | 162 | xconfig_size = |
163 | (uLongf) (ntohs (msg->header.size) - | 163 | (uLongf)(ntohs(msg->header.size) - |
164 | sizeof (struct GNUNET_TESTBED_HelperReply)); | 164 | sizeof(struct GNUNET_TESTBED_HelperReply)); |
165 | config = GNUNET_malloc (config_size); | 165 | config = GNUNET_malloc(config_size); |
166 | GNUNET_assert (Z_OK == | 166 | GNUNET_assert(Z_OK == |
167 | uncompress ((Bytef *) config, &config_size, | 167 | uncompress((Bytef *)config, &config_size, |
168 | (const Bytef *) &msg[1], xconfig_size)); | 168 | (const Bytef *)&msg[1], xconfig_size)); |
169 | GNUNET_free (config); | 169 | GNUNET_free(config); |
170 | if (NULL == shutdown_task) | 170 | if (NULL == shutdown_task) |
171 | shutdown_task = | 171 | shutdown_task = |
172 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 172 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
173 | (GNUNET_TIME_UNIT_SECONDS, 1), | 173 | (GNUNET_TIME_UNIT_SECONDS, 1), |
174 | &do_shutdown, NULL); | 174 | &do_shutdown, NULL); |
175 | return GNUNET_OK; | 175 | return GNUNET_OK; |
176 | } | 176 | } |
177 | 177 | ||
@@ -183,7 +183,7 @@ mst_cb (void *cls, | |||
183 | * @param cls the closure from GNUNET_HELPER_start() | 183 | * @param cls the closure from GNUNET_HELPER_start() |
184 | */ | 184 | */ |
185 | static void | 185 | static void |
186 | exp_cb (void *cls) | 186 | exp_cb(void *cls) |
187 | { | 187 | { |
188 | helper = NULL; | 188 | helper = NULL; |
189 | result = GNUNET_SYSERR; | 189 | result = GNUNET_SYSERR; |
@@ -199,8 +199,8 @@ exp_cb (void *cls) | |||
199 | * @param cfg configuration | 199 | * @param cfg configuration |
200 | */ | 200 | */ |
201 | static void | 201 | static void |
202 | run (void *cls, char *const *args, const char *cfgfile, | 202 | run(void *cls, char *const *args, const char *cfgfile, |
203 | const struct GNUNET_CONFIGURATION_Handle *cfg2) | 203 | const struct GNUNET_CONFIGURATION_Handle *cfg2) |
204 | { | 204 | { |
205 | static char *const binary_argv[] = { | 205 | static char *const binary_argv[] = { |
206 | "gnunet-helper-testbed", | 206 | "gnunet-helper-testbed", |
@@ -209,22 +209,22 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
209 | const char *trusted_ip = "127.0.0.1"; | 209 | const char *trusted_ip = "127.0.0.1"; |
210 | 210 | ||
211 | helper = | 211 | helper = |
212 | GNUNET_HELPER_start (GNUNET_YES, | 212 | GNUNET_HELPER_start(GNUNET_YES, |
213 | "gnunet-helper-testbed", | 213 | "gnunet-helper-testbed", |
214 | binary_argv, | 214 | binary_argv, |
215 | &mst_cb, | 215 | &mst_cb, |
216 | &exp_cb, | 216 | &exp_cb, |
217 | NULL); | 217 | NULL); |
218 | GNUNET_assert (NULL != helper); | 218 | GNUNET_assert(NULL != helper); |
219 | cfg = GNUNET_CONFIGURATION_dup (cfg2); | 219 | cfg = GNUNET_CONFIGURATION_dup(cfg2); |
220 | msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, NULL, cfg); | 220 | msg = GNUNET_TESTBED_create_helper_init_msg_(trusted_ip, NULL, cfg); |
221 | shandle = | 221 | shandle = |
222 | GNUNET_HELPER_send (helper, &msg->header, GNUNET_NO, &cont_cb, NULL); | 222 | GNUNET_HELPER_send(helper, &msg->header, GNUNET_NO, &cont_cb, NULL); |
223 | GNUNET_assert (NULL != shandle); | 223 | GNUNET_assert(NULL != shandle); |
224 | abort_task = | 224 | abort_task = |
225 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 225 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
226 | (GNUNET_TIME_UNIT_MINUTES, 1), &do_abort, | 226 | (GNUNET_TIME_UNIT_MINUTES, 1), &do_abort, |
227 | NULL); | 227 | NULL); |
228 | } | 228 | } |
229 | 229 | ||
230 | 230 | ||
@@ -236,7 +236,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
236 | * @return return code | 236 | * @return return code |
237 | */ | 237 | */ |
238 | int | 238 | int |
239 | main (int argc, char **argv) | 239 | main(int argc, char **argv) |
240 | { | 240 | { |
241 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 241 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
242 | GNUNET_GETOPT_OPTION_END | 242 | GNUNET_GETOPT_OPTION_END |
@@ -244,9 +244,9 @@ main (int argc, char **argv) | |||
244 | 244 | ||
245 | result = GNUNET_OK; | 245 | result = GNUNET_OK; |
246 | if (GNUNET_OK != | 246 | if (GNUNET_OK != |
247 | GNUNET_PROGRAM_run (argc, argv, "test_gnunet_helper_testbed", | 247 | GNUNET_PROGRAM_run(argc, argv, "test_gnunet_helper_testbed", |
248 | "Testcase for testing gnunet-helper-testbed.c", | 248 | "Testcase for testing gnunet-helper-testbed.c", |
249 | options, &run, NULL)) | 249 | options, &run, NULL)) |
250 | return 1; | 250 | return 1; |
251 | return (GNUNET_OK == result) ? 0 : 1; | 251 | return (GNUNET_OK == result) ? 0 : 1; |
252 | } | 252 | } |
diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c index 00d53dc25..37dc362ea 100644 --- a/src/testbed/test_testbed_api.c +++ b/src/testbed/test_testbed_api.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -33,14 +33,14 @@ | |||
33 | /** | 33 | /** |
34 | * Generic logging shortcut | 34 | * Generic logging shortcut |
35 | */ | 35 | */ |
36 | #define LOG(kind,...) \ | 36 | #define LOG(kind, ...) \ |
37 | GNUNET_log (kind, __VA_ARGS__) | 37 | GNUNET_log(kind, __VA_ARGS__) |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * Relative time seconds shorthand | 40 | * Relative time seconds shorthand |
41 | */ | 41 | */ |
42 | #define TIME_REL_SECS(sec) \ | 42 | #define TIME_REL_SECS(sec) \ |
43 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) | 43 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, sec) |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Our localhost | 46 | * Our localhost |
@@ -101,8 +101,7 @@ static int result; | |||
101 | /** | 101 | /** |
102 | * Enumeration of sub testcases | 102 | * Enumeration of sub testcases |
103 | */ | 103 | */ |
104 | enum Test | 104 | enum Test { |
105 | { | ||
106 | /** | 105 | /** |
107 | * Test cases which are not covered by the below ones | 106 | * Test cases which are not covered by the below ones |
108 | */ | 107 | */ |
@@ -136,23 +135,23 @@ static enum Test sub_test; | |||
136 | * @param tc the task context | 135 | * @param tc the task context |
137 | */ | 136 | */ |
138 | static void | 137 | static void |
139 | do_shutdown (void *cls) | 138 | do_shutdown(void *cls) |
140 | { | 139 | { |
141 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down...\n"); | 140 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Shutting down...\n"); |
142 | if (NULL != abort_task) | 141 | if (NULL != abort_task) |
143 | GNUNET_SCHEDULER_cancel (abort_task); | 142 | GNUNET_SCHEDULER_cancel(abort_task); |
144 | if (NULL != reg_handle) | 143 | if (NULL != reg_handle) |
145 | GNUNET_TESTBED_cancel_registration (reg_handle); | 144 | GNUNET_TESTBED_cancel_registration(reg_handle); |
146 | if (NULL != controller) | 145 | if (NULL != controller) |
147 | GNUNET_TESTBED_controller_disconnect (controller); | 146 | GNUNET_TESTBED_controller_disconnect(controller); |
148 | if (NULL != cfg) | 147 | if (NULL != cfg) |
149 | GNUNET_CONFIGURATION_destroy (cfg); | 148 | GNUNET_CONFIGURATION_destroy(cfg); |
150 | if (NULL != cp) | 149 | if (NULL != cp) |
151 | GNUNET_TESTBED_controller_stop (cp); | 150 | GNUNET_TESTBED_controller_stop(cp); |
152 | if (NULL != neighbour) | 151 | if (NULL != neighbour) |
153 | GNUNET_TESTBED_host_destroy (neighbour); | 152 | GNUNET_TESTBED_host_destroy(neighbour); |
154 | if (NULL != host) | 153 | if (NULL != host) |
155 | GNUNET_TESTBED_host_destroy (host); | 154 | GNUNET_TESTBED_host_destroy(host); |
156 | } | 155 | } |
157 | 156 | ||
158 | 157 | ||
@@ -160,14 +159,14 @@ do_shutdown (void *cls) | |||
160 | * shortcut to exit during failure | 159 | * shortcut to exit during failure |
161 | */ | 160 | */ |
162 | #define FAIL_TEST(cond, ret) do { \ | 161 | #define FAIL_TEST(cond, ret) do { \ |
163 | if (!(cond)) { \ | 162 | if (!(cond)) { \ |
164 | GNUNET_break(0); \ | 163 | GNUNET_break(0); \ |
165 | if (NULL != abort_task) \ | 164 | if (NULL != abort_task) \ |
166 | GNUNET_SCHEDULER_cancel (abort_task); \ | 165 | GNUNET_SCHEDULER_cancel (abort_task); \ |
167 | abort_task = NULL; \ | 166 | abort_task = NULL; \ |
168 | GNUNET_SCHEDULER_add_now (do_shutdown, NULL); \ | 167 | GNUNET_SCHEDULER_add_now(do_shutdown, NULL); \ |
169 | ret; \ | 168 | ret; \ |
170 | } \ | 169 | } \ |
171 | } while (0) | 170 | } while (0) |
172 | 171 | ||
173 | 172 | ||
@@ -178,11 +177,11 @@ do_shutdown (void *cls) | |||
178 | * @param tc the task context | 177 | * @param tc the task context |
179 | */ | 178 | */ |
180 | static void | 179 | static void |
181 | do_abort (void *cls) | 180 | do_abort(void *cls) |
182 | { | 181 | { |
183 | LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); | 182 | LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); |
184 | abort_task = NULL; | 183 | abort_task = NULL; |
185 | do_shutdown (cls); | 184 | do_shutdown(cls); |
186 | } | 185 | } |
187 | 186 | ||
188 | 187 | ||
@@ -197,13 +196,13 @@ do_abort (void *cls) | |||
197 | * @return service handle to return in 'op_result', NULL on error | 196 | * @return service handle to return in 'op_result', NULL on error |
198 | */ | 197 | */ |
199 | static void * | 198 | static void * |
200 | arm_connect_adapter (void *cls, | 199 | arm_connect_adapter(void *cls, |
201 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 200 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
202 | { | 201 | { |
203 | FAIL_TEST (NULL == cls, return NULL); | 202 | FAIL_TEST(NULL == cls, return NULL); |
204 | FAIL_TEST (OTHER == sub_test, return NULL); | 203 | FAIL_TEST(OTHER == sub_test, return NULL); |
205 | sub_test = PEER_SERVICE_CONNECT; | 204 | sub_test = PEER_SERVICE_CONNECT; |
206 | arm_handle = GNUNET_ARM_connect (cfg, NULL, NULL); | 205 | arm_handle = GNUNET_ARM_connect(cfg, NULL, NULL); |
207 | return arm_handle; | 206 | return arm_handle; |
208 | } | 207 | } |
209 | 208 | ||
@@ -216,17 +215,17 @@ arm_connect_adapter (void *cls, | |||
216 | * @param op_result service handle returned from the connect adapter | 215 | * @param op_result service handle returned from the connect adapter |
217 | */ | 216 | */ |
218 | static void | 217 | static void |
219 | arm_disconnect_adapter (void *cls, | 218 | arm_disconnect_adapter(void *cls, |
220 | void *op_result) | 219 | void *op_result) |
221 | { | 220 | { |
222 | FAIL_TEST (NULL != op_result, return); | 221 | FAIL_TEST(NULL != op_result, return ); |
223 | FAIL_TEST (op_result == arm_handle, return); | 222 | FAIL_TEST(op_result == arm_handle, return ); |
224 | GNUNET_ARM_disconnect (arm_handle); | 223 | GNUNET_ARM_disconnect(arm_handle); |
225 | arm_handle = NULL; | 224 | arm_handle = NULL; |
226 | FAIL_TEST (PEER_SERVICE_CONNECT == sub_test, return); | 225 | FAIL_TEST(PEER_SERVICE_CONNECT == sub_test, return ); |
227 | FAIL_TEST (NULL != operation, return); | 226 | FAIL_TEST(NULL != operation, return ); |
228 | operation = GNUNET_TESTBED_peer_stop (NULL, peer, NULL, NULL); | 227 | operation = GNUNET_TESTBED_peer_stop(NULL, peer, NULL, NULL); |
229 | FAIL_TEST (NULL != operation, return); | 228 | FAIL_TEST(NULL != operation, return ); |
230 | } | 229 | } |
231 | 230 | ||
232 | 231 | ||
@@ -240,24 +239,25 @@ arm_disconnect_adapter (void *cls, | |||
240 | * operation has executed successfully. | 239 | * operation has executed successfully. |
241 | */ | 240 | */ |
242 | static void | 241 | static void |
243 | service_connect_comp_cb (void *cls, | 242 | service_connect_comp_cb(void *cls, |
244 | struct GNUNET_TESTBED_Operation *op, | 243 | struct GNUNET_TESTBED_Operation *op, |
245 | void *ca_result, | 244 | void *ca_result, |
246 | const char *emsg) | 245 | const char *emsg) |
247 | { | 246 | { |
248 | switch (sub_test) | 247 | switch (sub_test) |
249 | { | 248 | { |
250 | case PEER_SERVICE_CONNECT: | 249 | case PEER_SERVICE_CONNECT: |
251 | FAIL_TEST (operation == op, return); | 250 | FAIL_TEST(operation == op, return ); |
252 | FAIL_TEST (NULL == emsg, return); | 251 | FAIL_TEST(NULL == emsg, return ); |
253 | FAIL_TEST (NULL == cls, return); | 252 | FAIL_TEST(NULL == cls, return ); |
254 | FAIL_TEST (ca_result == arm_handle, return); | 253 | FAIL_TEST(ca_result == arm_handle, return ); |
255 | GNUNET_TESTBED_operation_done (operation); /* This results in call to | 254 | GNUNET_TESTBED_operation_done(operation); /* This results in call to |
256 | * disconnect adapter */ | 255 | * disconnect adapter */ |
257 | break; | 256 | break; |
258 | default: | 257 | |
259 | FAIL_TEST (0, return); | 258 | default: |
260 | } | 259 | FAIL_TEST(0, return ); |
260 | } | ||
261 | } | 261 | } |
262 | 262 | ||
263 | 263 | ||
@@ -272,27 +272,28 @@ service_connect_comp_cb (void *cls, | |||
272 | * operation is successfull | 272 | * operation is successfull |
273 | */ | 273 | */ |
274 | static void | 274 | static void |
275 | peerinfo_cb (void *cb_cls, | 275 | peerinfo_cb(void *cb_cls, |
276 | struct GNUNET_TESTBED_Operation *op, | 276 | struct GNUNET_TESTBED_Operation *op, |
277 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | 277 | const struct GNUNET_TESTBED_PeerInformation *pinfo, |
278 | const char *emsg) | 278 | const char *emsg) |
279 | { | 279 | { |
280 | switch (sub_test) | 280 | switch (sub_test) |
281 | { | 281 | { |
282 | case PEER_GETCONFIG: | 282 | case PEER_GETCONFIG: |
283 | FAIL_TEST (NULL != pinfo, return); | 283 | FAIL_TEST(NULL != pinfo, return ); |
284 | FAIL_TEST (NULL == emsg, return); | 284 | FAIL_TEST(NULL == emsg, return ); |
285 | FAIL_TEST (NULL == cb_cls, return); | 285 | FAIL_TEST(NULL == cb_cls, return ); |
286 | FAIL_TEST (operation == op, return); | 286 | FAIL_TEST(operation == op, return ); |
287 | FAIL_TEST (GNUNET_TESTBED_PIT_CONFIGURATION == pinfo->pit, return); | 287 | FAIL_TEST(GNUNET_TESTBED_PIT_CONFIGURATION == pinfo->pit, return ); |
288 | FAIL_TEST (NULL != pinfo->result.cfg, return); | 288 | FAIL_TEST(NULL != pinfo->result.cfg, return ); |
289 | sub_test = PEER_DESTROY; | 289 | sub_test = PEER_DESTROY; |
290 | GNUNET_TESTBED_operation_done (operation); | 290 | GNUNET_TESTBED_operation_done(operation); |
291 | operation = GNUNET_TESTBED_peer_destroy (peer); | 291 | operation = GNUNET_TESTBED_peer_destroy(peer); |
292 | break; | 292 | break; |
293 | default: | 293 | |
294 | FAIL_TEST (0, return); | 294 | default: |
295 | } | 295 | FAIL_TEST(0, return ); |
296 | } | ||
296 | } | 297 | } |
297 | 298 | ||
298 | 299 | ||
@@ -304,60 +305,65 @@ peerinfo_cb (void *cb_cls, | |||
304 | * @param event information about the event | 305 | * @param event information about the event |
305 | */ | 306 | */ |
306 | static void | 307 | static void |
307 | controller_cb (void *cls, | 308 | controller_cb(void *cls, |
308 | const struct GNUNET_TESTBED_EventInformation *event) | 309 | const struct GNUNET_TESTBED_EventInformation *event) |
309 | { | 310 | { |
310 | switch (event->type) | 311 | switch (event->type) |
311 | { | ||
312 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
313 | switch (sub_test) | ||
314 | { | 312 | { |
315 | case PEER_DESTROY: | 313 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: |
316 | FAIL_TEST (event->op == operation, return); | 314 | switch (sub_test) |
317 | FAIL_TEST (NULL == event->op_cls, return); | 315 | { |
318 | FAIL_TEST (NULL == event->details.operation_finished.emsg, return); | 316 | case PEER_DESTROY: |
319 | FAIL_TEST (NULL == event->details.operation_finished.generic, return); | 317 | FAIL_TEST(event->op == operation, return ); |
320 | GNUNET_TESTBED_operation_done (operation); | 318 | FAIL_TEST(NULL == event->op_cls, return ); |
321 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 319 | FAIL_TEST(NULL == event->details.operation_finished.emsg, return ); |
320 | FAIL_TEST(NULL == event->details.operation_finished.generic, return ); | ||
321 | GNUNET_TESTBED_operation_done(operation); | ||
322 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); | ||
323 | break; | ||
324 | |||
325 | case PEER_SERVICE_CONNECT: | ||
326 | FAIL_TEST(event->op == operation, return ); | ||
327 | FAIL_TEST(NULL == event->op_cls, return ); | ||
328 | FAIL_TEST(NULL == event->details.operation_finished.emsg, return ); | ||
329 | FAIL_TEST(NULL != arm_handle, return ); | ||
330 | FAIL_TEST(event->details.operation_finished.generic == arm_handle, return ); | ||
331 | break; | ||
332 | |||
333 | default: | ||
334 | FAIL_TEST(0, return ); | ||
335 | break; | ||
336 | } | ||
322 | break; | 337 | break; |
323 | case PEER_SERVICE_CONNECT: | 338 | |
324 | FAIL_TEST (event->op == operation, return); | 339 | case GNUNET_TESTBED_ET_PEER_START: |
325 | FAIL_TEST (NULL == event->op_cls, return); | 340 | FAIL_TEST(event->details.peer_start.host == host, return ); |
326 | FAIL_TEST (NULL == event->details.operation_finished.emsg, return); | 341 | FAIL_TEST(event->details.peer_start.peer == peer, return ); |
327 | FAIL_TEST (NULL != arm_handle, return); | 342 | FAIL_TEST(OTHER == sub_test, return ); |
328 | FAIL_TEST (event->details.operation_finished.generic == arm_handle, return); | 343 | GNUNET_TESTBED_operation_done(operation); |
344 | operation = | ||
345 | GNUNET_TESTBED_service_connect(NULL, peer, "dht", | ||
346 | &service_connect_comp_cb, NULL, | ||
347 | &arm_connect_adapter, | ||
348 | &arm_disconnect_adapter, NULL); | ||
349 | FAIL_TEST(NULL != operation, return ); | ||
329 | break; | 350 | break; |
330 | default: | 351 | |
331 | FAIL_TEST (0, return); | 352 | case GNUNET_TESTBED_ET_PEER_STOP: |
353 | FAIL_TEST(event->details.peer_stop.peer == peer, return ); | ||
354 | FAIL_TEST(PEER_SERVICE_CONNECT == sub_test, return ); | ||
355 | result = GNUNET_YES; | ||
356 | sub_test = PEER_GETCONFIG; | ||
357 | GNUNET_TESTBED_operation_done(operation); | ||
358 | operation = | ||
359 | GNUNET_TESTBED_peer_get_information(peer, | ||
360 | GNUNET_TESTBED_PIT_CONFIGURATION, | ||
361 | &peerinfo_cb, NULL); | ||
332 | break; | 362 | break; |
363 | |||
364 | default: | ||
365 | FAIL_TEST(0, return ); /* We should never reach this state */ | ||
333 | } | 366 | } |
334 | break; | ||
335 | case GNUNET_TESTBED_ET_PEER_START: | ||
336 | FAIL_TEST (event->details.peer_start.host == host, return); | ||
337 | FAIL_TEST (event->details.peer_start.peer == peer, return); | ||
338 | FAIL_TEST (OTHER == sub_test, return); | ||
339 | GNUNET_TESTBED_operation_done (operation); | ||
340 | operation = | ||
341 | GNUNET_TESTBED_service_connect (NULL, peer, "dht", | ||
342 | &service_connect_comp_cb, NULL, | ||
343 | &arm_connect_adapter, | ||
344 | &arm_disconnect_adapter, NULL); | ||
345 | FAIL_TEST (NULL != operation, return); | ||
346 | break; | ||
347 | case GNUNET_TESTBED_ET_PEER_STOP: | ||
348 | FAIL_TEST (event->details.peer_stop.peer == peer, return); | ||
349 | FAIL_TEST (PEER_SERVICE_CONNECT == sub_test, return); | ||
350 | result = GNUNET_YES; | ||
351 | sub_test = PEER_GETCONFIG; | ||
352 | GNUNET_TESTBED_operation_done (operation); | ||
353 | operation = | ||
354 | GNUNET_TESTBED_peer_get_information (peer, | ||
355 | GNUNET_TESTBED_PIT_CONFIGURATION, | ||
356 | &peerinfo_cb, NULL); | ||
357 | break; | ||
358 | default: | ||
359 | FAIL_TEST (0, return); /* We should never reach this state */ | ||
360 | } | ||
361 | } | 367 | } |
362 | 368 | ||
363 | 369 | ||
@@ -371,22 +377,22 @@ controller_cb (void *cls, | |||
371 | * @param emsg NULL if peer is not NULL; else MAY contain the error description | 377 | * @param emsg NULL if peer is not NULL; else MAY contain the error description |
372 | */ | 378 | */ |
373 | static void | 379 | static void |
374 | peer_create_cb (void *cls, | 380 | peer_create_cb(void *cls, |
375 | struct GNUNET_TESTBED_Peer *peer, | 381 | struct GNUNET_TESTBED_Peer *peer, |
376 | const char *emsg) | 382 | const char *emsg) |
377 | { | 383 | { |
378 | struct GNUNET_TESTBED_Peer **peer_ptr; | 384 | struct GNUNET_TESTBED_Peer **peer_ptr; |
379 | 385 | ||
380 | peer_ptr = cls; | 386 | peer_ptr = cls; |
381 | FAIL_TEST (NULL != peer, return); | 387 | FAIL_TEST(NULL != peer, return ); |
382 | FAIL_TEST (NULL != peer_ptr, return); | 388 | FAIL_TEST(NULL != peer_ptr, return ); |
383 | *peer_ptr = peer; | 389 | *peer_ptr = peer; |
384 | GNUNET_TESTBED_operation_done (operation); | 390 | GNUNET_TESTBED_operation_done(operation); |
385 | operation = GNUNET_TESTBED_peer_start (NULL, | 391 | operation = GNUNET_TESTBED_peer_start(NULL, |
386 | peer, | 392 | peer, |
387 | NULL, | 393 | NULL, |
388 | NULL); | 394 | NULL); |
389 | FAIL_TEST (NULL != operation, return); | 395 | FAIL_TEST(NULL != operation, return ); |
390 | } | 396 | } |
391 | 397 | ||
392 | 398 | ||
@@ -397,18 +403,18 @@ peer_create_cb (void *cls, | |||
397 | * @param emsg the error message; NULL if host registration is successful | 403 | * @param emsg the error message; NULL if host registration is successful |
398 | */ | 404 | */ |
399 | static void | 405 | static void |
400 | registration_comp (void *cls, | 406 | registration_comp(void *cls, |
401 | const char *emsg) | 407 | const char *emsg) |
402 | { | 408 | { |
403 | FAIL_TEST (cls == neighbour, return); | 409 | FAIL_TEST(cls == neighbour, return ); |
404 | reg_handle = NULL; | 410 | reg_handle = NULL; |
405 | operation = | 411 | operation = |
406 | GNUNET_TESTBED_peer_create (controller, | 412 | GNUNET_TESTBED_peer_create(controller, |
407 | host, | 413 | host, |
408 | cfg, | 414 | cfg, |
409 | &peer_create_cb, | 415 | &peer_create_cb, |
410 | &peer); | 416 | &peer); |
411 | FAIL_TEST (NULL != operation, return); | 417 | FAIL_TEST(NULL != operation, return ); |
412 | } | 418 | } |
413 | 419 | ||
414 | 420 | ||
@@ -422,33 +428,33 @@ registration_comp (void *cls, | |||
422 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case | 428 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case |
423 | */ | 429 | */ |
424 | static void | 430 | static void |
425 | status_cb (void *cls, | 431 | status_cb(void *cls, |
426 | const struct GNUNET_CONFIGURATION_Handle *cfg_, | 432 | const struct GNUNET_CONFIGURATION_Handle *cfg_, |
427 | int status) | 433 | int status) |
428 | { | 434 | { |
429 | uint64_t event_mask; | 435 | uint64_t event_mask; |
430 | 436 | ||
431 | if (GNUNET_OK != status) | 437 | if (GNUNET_OK != status) |
432 | { | 438 | { |
433 | cp = NULL; | 439 | cp = NULL; |
434 | FAIL_TEST (0, return); | 440 | FAIL_TEST(0, return ); |
435 | return; | 441 | return; |
436 | } | 442 | } |
437 | event_mask = 0; | 443 | event_mask = 0; |
438 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); | 444 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); |
439 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); | 445 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); |
440 | event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); | 446 | event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); |
441 | event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 447 | event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
442 | controller = | 448 | controller = |
443 | GNUNET_TESTBED_controller_connect (host, event_mask, &controller_cb, | 449 | GNUNET_TESTBED_controller_connect(host, event_mask, &controller_cb, |
444 | NULL); | 450 | NULL); |
445 | FAIL_TEST (NULL != controller, return); | 451 | FAIL_TEST(NULL != controller, return ); |
446 | neighbour = GNUNET_TESTBED_host_create ("localhost", NULL, cfg, 0); | 452 | neighbour = GNUNET_TESTBED_host_create("localhost", NULL, cfg, 0); |
447 | FAIL_TEST (NULL != neighbour, return); | 453 | FAIL_TEST(NULL != neighbour, return ); |
448 | reg_handle = | 454 | reg_handle = |
449 | GNUNET_TESTBED_register_host (controller, neighbour, ®istration_comp, | 455 | GNUNET_TESTBED_register_host(controller, neighbour, ®istration_comp, |
450 | neighbour); | 456 | neighbour); |
451 | FAIL_TEST (NULL != reg_handle, return); | 457 | FAIL_TEST(NULL != reg_handle, return ); |
452 | } | 458 | } |
453 | 459 | ||
454 | 460 | ||
@@ -462,22 +468,22 @@ status_cb (void *cls, | |||
462 | * @param cfg the configuration file handle | 468 | * @param cfg the configuration file handle |
463 | */ | 469 | */ |
464 | static void | 470 | static void |
465 | run (void *cls, | 471 | run(void *cls, |
466 | char *const *args, | 472 | char *const *args, |
467 | const char *cfgfile, | 473 | const char *cfgfile, |
468 | const struct GNUNET_CONFIGURATION_Handle *config) | 474 | const struct GNUNET_CONFIGURATION_Handle *config) |
469 | { | 475 | { |
470 | cfg = GNUNET_CONFIGURATION_dup (config); | 476 | cfg = GNUNET_CONFIGURATION_dup(config); |
471 | host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0); | 477 | host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0); |
472 | FAIL_TEST (NULL != host, return); | 478 | FAIL_TEST(NULL != host, return ); |
473 | cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, | 479 | cp = GNUNET_TESTBED_controller_start("127.0.0.1", host, |
474 | &status_cb, | 480 | &status_cb, |
475 | NULL); | 481 | NULL); |
476 | abort_task = | 482 | abort_task = |
477 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 483 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
478 | (GNUNET_TIME_UNIT_MINUTES, 5), | 484 | (GNUNET_TIME_UNIT_MINUTES, 5), |
479 | &do_abort, | 485 | &do_abort, |
480 | NULL); | 486 | NULL); |
481 | } | 487 | } |
482 | 488 | ||
483 | 489 | ||
@@ -485,22 +491,21 @@ run (void *cls, | |||
485 | * Main function | 491 | * Main function |
486 | */ | 492 | */ |
487 | int | 493 | int |
488 | main (int argc, char **argv) | 494 | main(int argc, char **argv) |
489 | { | 495 | { |
490 | int ret; | 496 | int ret; |
491 | 497 | ||
492 | char *const argv2[] = { "test_testbed_api", | 498 | char *const argv2[] = { "test_testbed_api", |
493 | "-c", "test_testbed_api.conf", | 499 | "-c", "test_testbed_api.conf", |
494 | NULL | 500 | NULL }; |
495 | }; | ||
496 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 501 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
497 | GNUNET_GETOPT_OPTION_END | 502 | GNUNET_GETOPT_OPTION_END |
498 | }; | 503 | }; |
499 | 504 | ||
500 | result = GNUNET_SYSERR; | 505 | result = GNUNET_SYSERR; |
501 | ret = | 506 | ret = |
502 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | 507 | GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, |
503 | "test_testbed_api", "nohelp", options, &run, NULL); | 508 | "test_testbed_api", "nohelp", options, &run, NULL); |
504 | if ((GNUNET_OK != ret) || (GNUNET_OK != result)) | 509 | if ((GNUNET_OK != ret) || (GNUNET_OK != result)) |
505 | return 1; | 510 | return 1; |
506 | return 0; | 511 | return 0; |
diff --git a/src/testbed/test_testbed_api_2peers_1controller.c b/src/testbed/test_testbed_api_2peers_1controller.c index dcb6a174f..23d9823f5 100644 --- a/src/testbed/test_testbed_api_2peers_1controller.c +++ b/src/testbed/test_testbed_api_2peers_1controller.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -34,20 +34,19 @@ | |||
34 | /** | 34 | /** |
35 | * Generic logging shortcut | 35 | * Generic logging shortcut |
36 | */ | 36 | */ |
37 | #define LOG(kind,...) \ | 37 | #define LOG(kind, ...) \ |
38 | GNUNET_log (kind, __VA_ARGS__) | 38 | GNUNET_log(kind, __VA_ARGS__) |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Relative time seconds shorthand | 41 | * Relative time seconds shorthand |
42 | */ | 42 | */ |
43 | #define TIME_REL_SECS(sec) \ | 43 | #define TIME_REL_SECS(sec) \ |
44 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) | 44 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, sec) |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * Peer context | 47 | * Peer context |
48 | */ | 48 | */ |
49 | struct PeerContext | 49 | struct PeerContext { |
50 | { | ||
51 | /** | 50 | /** |
52 | * The peer handle | 51 | * The peer handle |
53 | */ | 52 | */ |
@@ -122,9 +121,7 @@ static struct GNUNET_SCHEDULER_Task * delayed_connect_task; | |||
122 | /** | 121 | /** |
123 | * Different stages in testing | 122 | * Different stages in testing |
124 | */ | 123 | */ |
125 | enum Stage | 124 | enum Stage { |
126 | { | ||
127 | |||
128 | /** | 125 | /** |
129 | * Initial stage | 126 | * Initial stage |
130 | */ | 127 | */ |
@@ -171,14 +168,14 @@ static enum Stage result; | |||
171 | * shortcut to exit during failure | 168 | * shortcut to exit during failure |
172 | */ | 169 | */ |
173 | #define FAIL_TEST(cond) do { \ | 170 | #define FAIL_TEST(cond) do { \ |
174 | if (!(cond)) { \ | 171 | if (!(cond)) { \ |
175 | GNUNET_break(0); \ | 172 | GNUNET_break(0); \ |
176 | if (NULL != abort_task) \ | 173 | if (NULL != abort_task) \ |
177 | GNUNET_SCHEDULER_cancel (abort_task); \ | 174 | GNUNET_SCHEDULER_cancel (abort_task); \ |
178 | abort_task = NULL; \ | 175 | abort_task = NULL; \ |
179 | GNUNET_SCHEDULER_add_now (do_shutdown, NULL); \ | 176 | GNUNET_SCHEDULER_add_now(do_shutdown, NULL); \ |
180 | return; \ | 177 | return; \ |
181 | } \ | 178 | } \ |
182 | } while (0) | 179 | } while (0) |
183 | 180 | ||
184 | 181 | ||
@@ -188,20 +185,20 @@ static enum Stage result; | |||
188 | * @param cls NULL | 185 | * @param cls NULL |
189 | */ | 186 | */ |
190 | static void | 187 | static void |
191 | do_shutdown (void *cls) | 188 | do_shutdown(void *cls) |
192 | { | 189 | { |
193 | if (NULL != abort_task) | 190 | if (NULL != abort_task) |
194 | GNUNET_SCHEDULER_cancel (abort_task); | 191 | GNUNET_SCHEDULER_cancel(abort_task); |
195 | if (NULL != delayed_connect_task) | 192 | if (NULL != delayed_connect_task) |
196 | GNUNET_SCHEDULER_cancel (delayed_connect_task); | 193 | GNUNET_SCHEDULER_cancel(delayed_connect_task); |
197 | if (NULL != reg_handle) | 194 | if (NULL != reg_handle) |
198 | GNUNET_TESTBED_cancel_registration (reg_handle); | 195 | GNUNET_TESTBED_cancel_registration(reg_handle); |
199 | GNUNET_TESTBED_controller_disconnect (controller); | 196 | GNUNET_TESTBED_controller_disconnect(controller); |
200 | GNUNET_CONFIGURATION_destroy (cfg); | 197 | GNUNET_CONFIGURATION_destroy(cfg); |
201 | if (NULL != cp) | 198 | if (NULL != cp) |
202 | GNUNET_TESTBED_controller_stop (cp); | 199 | GNUNET_TESTBED_controller_stop(cp); |
203 | GNUNET_TESTBED_host_destroy (neighbour); | 200 | GNUNET_TESTBED_host_destroy(neighbour); |
204 | GNUNET_TESTBED_host_destroy (host); | 201 | GNUNET_TESTBED_host_destroy(host); |
205 | } | 202 | } |
206 | 203 | ||
207 | 204 | ||
@@ -211,11 +208,11 @@ do_shutdown (void *cls) | |||
211 | * @param cls NULL | 208 | * @param cls NULL |
212 | */ | 209 | */ |
213 | static void | 210 | static void |
214 | do_abort (void *cls) | 211 | do_abort(void *cls) |
215 | { | 212 | { |
216 | LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); | 213 | LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); |
217 | abort_task = NULL; | 214 | abort_task = NULL; |
218 | do_shutdown (cls); | 215 | do_shutdown(cls); |
219 | } | 216 | } |
220 | 217 | ||
221 | 218 | ||
@@ -228,7 +225,7 @@ do_abort (void *cls) | |||
228 | * operation has executed successfully. | 225 | * operation has executed successfully. |
229 | */ | 226 | */ |
230 | static void | 227 | static void |
231 | op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg); | 228 | op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg); |
232 | 229 | ||
233 | 230 | ||
234 | /** | 231 | /** |
@@ -237,13 +234,13 @@ op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg); | |||
237 | * @param cls NULL | 234 | * @param cls NULL |
238 | */ | 235 | */ |
239 | static void | 236 | static void |
240 | do_delayed_connect (void *cls) | 237 | do_delayed_connect(void *cls) |
241 | { | 238 | { |
242 | delayed_connect_task = NULL; | 239 | delayed_connect_task = NULL; |
243 | FAIL_TEST (NULL == common_operation); | 240 | FAIL_TEST(NULL == common_operation); |
244 | common_operation = | 241 | common_operation = |
245 | GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer, | 242 | GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer1.peer, |
246 | peer2.peer); | 243 | peer2.peer); |
247 | } | 244 | } |
248 | 245 | ||
249 | 246 | ||
@@ -256,24 +253,26 @@ do_delayed_connect (void *cls) | |||
256 | * operation has executed successfully. | 253 | * operation has executed successfully. |
257 | */ | 254 | */ |
258 | static void | 255 | static void |
259 | op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) | 256 | op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) |
260 | { | 257 | { |
261 | FAIL_TEST (common_operation == op); | 258 | FAIL_TEST(common_operation == op); |
262 | switch (result) | 259 | switch (result) |
263 | { | 260 | { |
264 | case PEERS_STARTED: | 261 | case PEERS_STARTED: |
265 | FAIL_TEST (NULL == peer1.operation); | 262 | FAIL_TEST(NULL == peer1.operation); |
266 | FAIL_TEST (NULL == peer2.operation); | 263 | FAIL_TEST(NULL == peer2.operation); |
267 | FAIL_TEST (NULL != common_operation); | 264 | FAIL_TEST(NULL != common_operation); |
268 | break; | 265 | break; |
269 | case PEERS_CONNECTED: | 266 | |
270 | FAIL_TEST (NULL == peer1.operation); | 267 | case PEERS_CONNECTED: |
271 | FAIL_TEST (NULL == peer2.operation); | 268 | FAIL_TEST(NULL == peer1.operation); |
272 | FAIL_TEST (NULL != common_operation); | 269 | FAIL_TEST(NULL == peer2.operation); |
273 | break; | 270 | FAIL_TEST(NULL != common_operation); |
274 | default: | 271 | break; |
275 | FAIL_TEST (0); | 272 | |
276 | } | 273 | default: |
274 | FAIL_TEST(0); | ||
275 | } | ||
277 | } | 276 | } |
278 | 277 | ||
279 | 278 | ||
@@ -285,114 +284,121 @@ op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) | |||
285 | * @param event information about the event | 284 | * @param event information about the event |
286 | */ | 285 | */ |
287 | static void | 286 | static void |
288 | controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | 287 | controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) |
289 | { | 288 | { |
290 | switch (event->type) | 289 | switch (event->type) |
291 | { | ||
292 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: /* Will be reached when we destroy peers */ | ||
293 | FAIL_TEST (PEERS_STOPPED == result); | ||
294 | FAIL_TEST (NULL == event->op_cls); | ||
295 | FAIL_TEST (NULL == event->details.operation_finished.emsg); | ||
296 | FAIL_TEST (NULL == event->details.operation_finished.generic); | ||
297 | if (event->op == peer1.operation) | ||
298 | { | ||
299 | GNUNET_TESTBED_operation_done (peer1.operation); | ||
300 | peer1.operation = NULL; | ||
301 | peer1.peer = NULL; | ||
302 | } | ||
303 | else if (event->op == peer2.operation) | ||
304 | { | ||
305 | GNUNET_TESTBED_operation_done (peer2.operation); | ||
306 | peer2.operation = NULL; | ||
307 | peer2.peer = NULL; | ||
308 | } | ||
309 | else | ||
310 | FAIL_TEST (0); | ||
311 | if ((NULL == peer1.peer) && (NULL == peer2.peer)) | ||
312 | { | ||
313 | result = SUCCESS; | ||
314 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
315 | } | ||
316 | break; | ||
317 | case GNUNET_TESTBED_ET_PEER_START: | ||
318 | FAIL_TEST (INIT == result); | ||
319 | FAIL_TEST (event->details.peer_start.host == host); | ||
320 | if (event->details.peer_start.peer == peer1.peer) | ||
321 | { | ||
322 | peer1.is_running = GNUNET_YES; | ||
323 | GNUNET_TESTBED_operation_done (peer1.operation); | ||
324 | peer1.operation = NULL; | ||
325 | } | ||
326 | else if (event->details.peer_start.peer == peer2.peer) | ||
327 | { | ||
328 | peer2.is_running = GNUNET_YES; | ||
329 | GNUNET_TESTBED_operation_done (peer2.operation); | ||
330 | peer2.operation = NULL; | ||
331 | } | ||
332 | else | ||
333 | FAIL_TEST (0); | ||
334 | if ((GNUNET_YES == peer1.is_running) && (GNUNET_YES == peer2.is_running)) | ||
335 | { | ||
336 | result = PEERS_STARTED; | ||
337 | common_operation = | ||
338 | GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer, | ||
339 | peer2.peer); | ||
340 | } | ||
341 | break; | ||
342 | case GNUNET_TESTBED_ET_PEER_STOP: | ||
343 | FAIL_TEST (PEERS_CONNECTED_2 == result); | ||
344 | if (event->details.peer_stop.peer == peer1.peer) | ||
345 | { | 290 | { |
346 | peer1.is_running = GNUNET_NO; | 291 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: /* Will be reached when we destroy peers */ |
347 | GNUNET_TESTBED_operation_done (peer1.operation); | 292 | FAIL_TEST(PEERS_STOPPED == result); |
348 | peer1.operation = GNUNET_TESTBED_peer_destroy (peer1.peer); | 293 | FAIL_TEST(NULL == event->op_cls); |
349 | } | 294 | FAIL_TEST(NULL == event->details.operation_finished.emsg); |
350 | else if (event->details.peer_stop.peer == peer2.peer) | 295 | FAIL_TEST(NULL == event->details.operation_finished.generic); |
351 | { | 296 | if (event->op == peer1.operation) |
352 | peer2.is_running = GNUNET_NO; | 297 | { |
353 | GNUNET_TESTBED_operation_done (peer2.operation); | 298 | GNUNET_TESTBED_operation_done(peer1.operation); |
354 | peer2.operation = GNUNET_TESTBED_peer_destroy (peer2.peer); | 299 | peer1.operation = NULL; |
355 | } | 300 | peer1.peer = NULL; |
356 | else | 301 | } |
357 | FAIL_TEST (0); | 302 | else if (event->op == peer2.operation) |
358 | if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running)) | 303 | { |
359 | result = PEERS_STOPPED; | 304 | GNUNET_TESTBED_operation_done(peer2.operation); |
360 | break; | 305 | peer2.operation = NULL; |
361 | case GNUNET_TESTBED_ET_CONNECT: | 306 | peer2.peer = NULL; |
362 | switch (result) | 307 | } |
363 | { | 308 | else |
364 | case PEERS_STARTED: | 309 | FAIL_TEST(0); |
365 | FAIL_TEST (NULL == peer1.operation); | 310 | if ((NULL == peer1.peer) && (NULL == peer2.peer)) |
366 | FAIL_TEST (NULL == peer2.operation); | 311 | { |
367 | FAIL_TEST (NULL != common_operation); | 312 | result = SUCCESS; |
368 | FAIL_TEST ((event->details.peer_connect.peer1 == peer1.peer) && | 313 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
369 | (event->details.peer_connect.peer2 == peer2.peer)); | 314 | } |
370 | GNUNET_TESTBED_operation_done (common_operation); | ||
371 | common_operation = NULL; | ||
372 | result = PEERS_CONNECTED; | ||
373 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n"); | ||
374 | delayed_connect_task = | ||
375 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3), &do_delayed_connect, | ||
376 | NULL); | ||
377 | break; | 315 | break; |
378 | case PEERS_CONNECTED: | 316 | |
379 | FAIL_TEST (NULL == peer1.operation); | 317 | case GNUNET_TESTBED_ET_PEER_START: |
380 | FAIL_TEST (NULL == peer2.operation); | 318 | FAIL_TEST(INIT == result); |
381 | FAIL_TEST (NULL != common_operation); | 319 | FAIL_TEST(event->details.peer_start.host == host); |
382 | GNUNET_TESTBED_operation_done (common_operation); | 320 | if (event->details.peer_start.peer == peer1.peer) |
383 | common_operation = NULL; | 321 | { |
384 | result = PEERS_CONNECTED_2; | 322 | peer1.is_running = GNUNET_YES; |
385 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n"); | 323 | GNUNET_TESTBED_operation_done(peer1.operation); |
386 | peer1.operation = GNUNET_TESTBED_peer_stop (NULL, peer1.peer, NULL, NULL); | 324 | peer1.operation = NULL; |
387 | peer2.operation = GNUNET_TESTBED_peer_stop (NULL, peer2.peer, NULL, NULL); | 325 | } |
326 | else if (event->details.peer_start.peer == peer2.peer) | ||
327 | { | ||
328 | peer2.is_running = GNUNET_YES; | ||
329 | GNUNET_TESTBED_operation_done(peer2.operation); | ||
330 | peer2.operation = NULL; | ||
331 | } | ||
332 | else | ||
333 | FAIL_TEST(0); | ||
334 | if ((GNUNET_YES == peer1.is_running) && (GNUNET_YES == peer2.is_running)) | ||
335 | { | ||
336 | result = PEERS_STARTED; | ||
337 | common_operation = | ||
338 | GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer1.peer, | ||
339 | peer2.peer); | ||
340 | } | ||
341 | break; | ||
342 | |||
343 | case GNUNET_TESTBED_ET_PEER_STOP: | ||
344 | FAIL_TEST(PEERS_CONNECTED_2 == result); | ||
345 | if (event->details.peer_stop.peer == peer1.peer) | ||
346 | { | ||
347 | peer1.is_running = GNUNET_NO; | ||
348 | GNUNET_TESTBED_operation_done(peer1.operation); | ||
349 | peer1.operation = GNUNET_TESTBED_peer_destroy(peer1.peer); | ||
350 | } | ||
351 | else if (event->details.peer_stop.peer == peer2.peer) | ||
352 | { | ||
353 | peer2.is_running = GNUNET_NO; | ||
354 | GNUNET_TESTBED_operation_done(peer2.operation); | ||
355 | peer2.operation = GNUNET_TESTBED_peer_destroy(peer2.peer); | ||
356 | } | ||
357 | else | ||
358 | FAIL_TEST(0); | ||
359 | if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running)) | ||
360 | result = PEERS_STOPPED; | ||
361 | break; | ||
362 | |||
363 | case GNUNET_TESTBED_ET_CONNECT: | ||
364 | switch (result) | ||
365 | { | ||
366 | case PEERS_STARTED: | ||
367 | FAIL_TEST(NULL == peer1.operation); | ||
368 | FAIL_TEST(NULL == peer2.operation); | ||
369 | FAIL_TEST(NULL != common_operation); | ||
370 | FAIL_TEST((event->details.peer_connect.peer1 == peer1.peer) && | ||
371 | (event->details.peer_connect.peer2 == peer2.peer)); | ||
372 | GNUNET_TESTBED_operation_done(common_operation); | ||
373 | common_operation = NULL; | ||
374 | result = PEERS_CONNECTED; | ||
375 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n"); | ||
376 | delayed_connect_task = | ||
377 | GNUNET_SCHEDULER_add_delayed(TIME_REL_SECS(3), &do_delayed_connect, | ||
378 | NULL); | ||
379 | break; | ||
380 | |||
381 | case PEERS_CONNECTED: | ||
382 | FAIL_TEST(NULL == peer1.operation); | ||
383 | FAIL_TEST(NULL == peer2.operation); | ||
384 | FAIL_TEST(NULL != common_operation); | ||
385 | GNUNET_TESTBED_operation_done(common_operation); | ||
386 | common_operation = NULL; | ||
387 | result = PEERS_CONNECTED_2; | ||
388 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n"); | ||
389 | peer1.operation = GNUNET_TESTBED_peer_stop(NULL, peer1.peer, NULL, NULL); | ||
390 | peer2.operation = GNUNET_TESTBED_peer_stop(NULL, peer2.peer, NULL, NULL); | ||
391 | break; | ||
392 | |||
393 | default: | ||
394 | FAIL_TEST(0); | ||
395 | } | ||
388 | break; | 396 | break; |
397 | |||
389 | default: | 398 | default: |
390 | FAIL_TEST (0); | 399 | FAIL_TEST(0); |
391 | } | 400 | } |
392 | break; | 401 | ; |
393 | default: | ||
394 | FAIL_TEST (0); | ||
395 | }; | ||
396 | } | 402 | } |
397 | 403 | ||
398 | 404 | ||
@@ -406,16 +412,16 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
406 | * @param emsg NULL if peer is not NULL; else MAY contain the error description | 412 | * @param emsg NULL if peer is not NULL; else MAY contain the error description |
407 | */ | 413 | */ |
408 | static void | 414 | static void |
409 | peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | 415 | peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) |
410 | { | 416 | { |
411 | struct PeerContext *pc = cls; | 417 | struct PeerContext *pc = cls; |
412 | 418 | ||
413 | FAIL_TEST (NULL != pc->operation); | 419 | FAIL_TEST(NULL != pc->operation); |
414 | FAIL_TEST (NULL != peer); | 420 | FAIL_TEST(NULL != peer); |
415 | FAIL_TEST (NULL == pc->peer); | 421 | FAIL_TEST(NULL == pc->peer); |
416 | pc->peer = peer; | 422 | pc->peer = peer; |
417 | GNUNET_TESTBED_operation_done (pc->operation); | 423 | GNUNET_TESTBED_operation_done(pc->operation); |
418 | pc->operation = GNUNET_TESTBED_peer_start (NULL, pc->peer, NULL, NULL); | 424 | pc->operation = GNUNET_TESTBED_peer_start(NULL, pc->peer, NULL, NULL); |
419 | } | 425 | } |
420 | 426 | ||
421 | 427 | ||
@@ -426,18 +432,18 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | |||
426 | * @param emsg the error message; NULL if host registration is successful | 432 | * @param emsg the error message; NULL if host registration is successful |
427 | */ | 433 | */ |
428 | static void | 434 | static void |
429 | registration_comp (void *cls, const char *emsg) | 435 | registration_comp(void *cls, const char *emsg) |
430 | { | 436 | { |
431 | FAIL_TEST (cls == neighbour); | 437 | FAIL_TEST(cls == neighbour); |
432 | reg_handle = NULL; | 438 | reg_handle = NULL; |
433 | peer1.operation = | 439 | peer1.operation = |
434 | GNUNET_TESTBED_peer_create (controller, host, cfg, &peer_create_cb, | 440 | GNUNET_TESTBED_peer_create(controller, host, cfg, &peer_create_cb, |
435 | &peer1); | 441 | &peer1); |
436 | peer2.operation = | 442 | peer2.operation = |
437 | GNUNET_TESTBED_peer_create (controller, host, cfg, &peer_create_cb, | 443 | GNUNET_TESTBED_peer_create(controller, host, cfg, &peer_create_cb, |
438 | &peer2); | 444 | &peer2); |
439 | FAIL_TEST (NULL != peer1.operation); | 445 | FAIL_TEST(NULL != peer1.operation); |
440 | FAIL_TEST (NULL != peer2.operation); | 446 | FAIL_TEST(NULL != peer2.operation); |
441 | } | 447 | } |
442 | 448 | ||
443 | 449 | ||
@@ -451,30 +457,30 @@ registration_comp (void *cls, const char *emsg) | |||
451 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case | 457 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case |
452 | */ | 458 | */ |
453 | static void | 459 | static void |
454 | status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg_, int status) | 460 | status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg_, int status) |
455 | { | 461 | { |
456 | uint64_t event_mask; | 462 | uint64_t event_mask; |
457 | 463 | ||
458 | if (GNUNET_OK != status) | 464 | if (GNUNET_OK != status) |
459 | { | 465 | { |
460 | cp = NULL; | 466 | cp = NULL; |
461 | FAIL_TEST (0); | 467 | FAIL_TEST(0); |
462 | } | 468 | } |
463 | event_mask = 0; | 469 | event_mask = 0; |
464 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); | 470 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); |
465 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); | 471 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); |
466 | event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); | 472 | event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); |
467 | event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 473 | event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
468 | controller = | 474 | controller = |
469 | GNUNET_TESTBED_controller_connect (host, event_mask, &controller_cb, | 475 | GNUNET_TESTBED_controller_connect(host, event_mask, &controller_cb, |
470 | NULL); | 476 | NULL); |
471 | FAIL_TEST (NULL != controller); | 477 | FAIL_TEST(NULL != controller); |
472 | neighbour = GNUNET_TESTBED_host_create ("localhost", NULL, cfg, 0); | 478 | neighbour = GNUNET_TESTBED_host_create("localhost", NULL, cfg, 0); |
473 | FAIL_TEST (NULL != neighbour); | 479 | FAIL_TEST(NULL != neighbour); |
474 | reg_handle = | 480 | reg_handle = |
475 | GNUNET_TESTBED_register_host (controller, neighbour, ®istration_comp, | 481 | GNUNET_TESTBED_register_host(controller, neighbour, ®istration_comp, |
476 | neighbour); | 482 | neighbour); |
477 | FAIL_TEST (NULL != reg_handle); | 483 | FAIL_TEST(NULL != reg_handle); |
478 | } | 484 | } |
479 | 485 | ||
480 | 486 | ||
@@ -488,18 +494,18 @@ status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg_, int status | |||
488 | * @param cfg the configuration file handle | 494 | * @param cfg the configuration file handle |
489 | */ | 495 | */ |
490 | static void | 496 | static void |
491 | run (void *cls, char *const *args, const char *cfgfile, | 497 | run(void *cls, char *const *args, const char *cfgfile, |
492 | const struct GNUNET_CONFIGURATION_Handle *config) | 498 | const struct GNUNET_CONFIGURATION_Handle *config) |
493 | { | 499 | { |
494 | cfg = GNUNET_CONFIGURATION_dup (config); | 500 | cfg = GNUNET_CONFIGURATION_dup(config); |
495 | host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0); | 501 | host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0); |
496 | FAIL_TEST (NULL != host); | 502 | FAIL_TEST(NULL != host); |
497 | cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb, | 503 | cp = GNUNET_TESTBED_controller_start("127.0.0.1", host, status_cb, |
498 | NULL); | 504 | NULL); |
499 | abort_task = | 505 | abort_task = |
500 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 506 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
501 | (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, | 507 | (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, |
502 | NULL); | 508 | NULL); |
503 | } | 509 | } |
504 | 510 | ||
505 | 511 | ||
@@ -507,22 +513,22 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
507 | * Main function | 513 | * Main function |
508 | */ | 514 | */ |
509 | int | 515 | int |
510 | main (int argc, char **argv) | 516 | main(int argc, char **argv) |
511 | { | 517 | { |
512 | int ret; | 518 | int ret; |
513 | 519 | ||
514 | char *const argv2[] = { "test_testbed_api_2peers_1controller", | 520 | char *const argv2[] = { "test_testbed_api_2peers_1controller", |
515 | "-c", "test_testbed_api.conf", | 521 | "-c", "test_testbed_api.conf", |
516 | NULL | 522 | NULL }; |
517 | }; | ||
518 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 523 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
519 | GNUNET_GETOPT_OPTION_END | 524 | GNUNET_GETOPT_OPTION_END |
520 | }; | 525 | }; |
526 | |||
521 | result = INIT; | 527 | result = INIT; |
522 | ret = | 528 | ret = |
523 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | 529 | GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, |
524 | "test_testbed_api_2peers_1controller", "nohelp", | 530 | "test_testbed_api_2peers_1controller", "nohelp", |
525 | options, &run, NULL); | 531 | options, &run, NULL); |
526 | if ((GNUNET_OK != ret) || (SUCCESS != result)) | 532 | if ((GNUNET_OK != ret) || (SUCCESS != result)) |
527 | return 1; | 533 | return 1; |
528 | return 0; | 534 | return 0; |
diff --git a/src/testbed/test_testbed_api_3peers_3controllers.c b/src/testbed/test_testbed_api_3peers_3controllers.c index 1d1d1ce44..ec396d6ca 100644 --- a/src/testbed/test_testbed_api_3peers_3controllers.c +++ b/src/testbed/test_testbed_api_3peers_3controllers.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -51,21 +51,20 @@ | |||
51 | /** | 51 | /** |
52 | * Generic logging shortcut | 52 | * Generic logging shortcut |
53 | */ | 53 | */ |
54 | #define LOG(kind,...) \ | 54 | #define LOG(kind, ...) \ |
55 | GNUNET_log (kind, __VA_ARGS__) | 55 | GNUNET_log(kind, __VA_ARGS__) |
56 | 56 | ||
57 | /** | 57 | /** |
58 | * Relative time seconds shorthand | 58 | * Relative time seconds shorthand |
59 | */ | 59 | */ |
60 | #define TIME_REL_SECS(sec) \ | 60 | #define TIME_REL_SECS(sec) \ |
61 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) | 61 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, sec) |
62 | 62 | ||
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Peer context | 65 | * Peer context |
66 | */ | 66 | */ |
67 | struct PeerContext | 67 | struct PeerContext { |
68 | { | ||
69 | /** | 68 | /** |
70 | * The peer handle | 69 | * The peer handle |
71 | */ | 70 | */ |
@@ -161,9 +160,7 @@ static struct GNUNET_SCHEDULER_Task * delayed_connect_task; | |||
161 | /** | 160 | /** |
162 | * Different stages in testing | 161 | * Different stages in testing |
163 | */ | 162 | */ |
164 | enum Stage | 163 | enum Stage { |
165 | { | ||
166 | |||
167 | /** | 164 | /** |
168 | * Initial stage | 165 | * Initial stage |
169 | */ | 166 | */ |
@@ -256,30 +253,30 @@ static enum Stage result; | |||
256 | * @param cls NULL | 253 | * @param cls NULL |
257 | */ | 254 | */ |
258 | static void | 255 | static void |
259 | do_shutdown (void *cls) | 256 | do_shutdown(void *cls) |
260 | { | 257 | { |
261 | if (NULL != abort_task) | 258 | if (NULL != abort_task) |
262 | GNUNET_SCHEDULER_cancel (abort_task); | 259 | GNUNET_SCHEDULER_cancel(abort_task); |
263 | if (NULL != hc_handle) | 260 | if (NULL != hc_handle) |
264 | GNUNET_TESTBED_is_host_habitable_cancel (hc_handle); | 261 | GNUNET_TESTBED_is_host_habitable_cancel(hc_handle); |
265 | GNUNET_assert (NULL == delayed_connect_task); | 262 | GNUNET_assert(NULL == delayed_connect_task); |
266 | if (NULL != common_operation) | 263 | if (NULL != common_operation) |
267 | GNUNET_TESTBED_operation_done (common_operation); | 264 | GNUNET_TESTBED_operation_done(common_operation); |
268 | if (NULL != reg_handle) | 265 | if (NULL != reg_handle) |
269 | GNUNET_TESTBED_cancel_registration (reg_handle); | 266 | GNUNET_TESTBED_cancel_registration(reg_handle); |
270 | if (NULL != controller1) | 267 | if (NULL != controller1) |
271 | GNUNET_TESTBED_controller_disconnect (controller1); | 268 | GNUNET_TESTBED_controller_disconnect(controller1); |
272 | GNUNET_CONFIGURATION_destroy (cfg); | 269 | GNUNET_CONFIGURATION_destroy(cfg); |
273 | if (NULL != cfg2) | 270 | if (NULL != cfg2) |
274 | GNUNET_CONFIGURATION_destroy (cfg2); | 271 | GNUNET_CONFIGURATION_destroy(cfg2); |
275 | if (NULL != cp1) | 272 | if (NULL != cp1) |
276 | GNUNET_TESTBED_controller_stop (cp1); | 273 | GNUNET_TESTBED_controller_stop(cp1); |
277 | if (NULL != host) | 274 | if (NULL != host) |
278 | GNUNET_TESTBED_host_destroy (host); | 275 | GNUNET_TESTBED_host_destroy(host); |
279 | if (NULL != neighbour1) | 276 | if (NULL != neighbour1) |
280 | GNUNET_TESTBED_host_destroy (neighbour1); | 277 | GNUNET_TESTBED_host_destroy(neighbour1); |
281 | if (NULL != neighbour2) | 278 | if (NULL != neighbour2) |
282 | GNUNET_TESTBED_host_destroy (neighbour2); | 279 | GNUNET_TESTBED_host_destroy(neighbour2); |
283 | } | 280 | } |
284 | 281 | ||
285 | 282 | ||
@@ -289,25 +286,25 @@ do_shutdown (void *cls) | |||
289 | * @param cls NULL | 286 | * @param cls NULL |
290 | */ | 287 | */ |
291 | static void | 288 | static void |
292 | do_abort (void *cls) | 289 | do_abort(void *cls) |
293 | { | 290 | { |
294 | LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); | 291 | LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); |
295 | abort_task = NULL; | 292 | abort_task = NULL; |
296 | if (NULL != delayed_connect_task) | 293 | if (NULL != delayed_connect_task) |
297 | { | 294 | { |
298 | GNUNET_SCHEDULER_cancel (delayed_connect_task); | 295 | GNUNET_SCHEDULER_cancel(delayed_connect_task); |
299 | delayed_connect_task = NULL; | 296 | delayed_connect_task = NULL; |
300 | } | 297 | } |
301 | do_shutdown (cls); | 298 | do_shutdown(cls); |
302 | } | 299 | } |
303 | 300 | ||
304 | 301 | ||
305 | static void | 302 | static void |
306 | abort_test () | 303 | abort_test() |
307 | { | 304 | { |
308 | if (NULL != abort_task) | 305 | if (NULL != abort_task) |
309 | GNUNET_SCHEDULER_cancel (abort_task); | 306 | GNUNET_SCHEDULER_cancel(abort_task); |
310 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); | 307 | abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); |
311 | } | 308 | } |
312 | 309 | ||
313 | 310 | ||
@@ -320,7 +317,7 @@ abort_test () | |||
320 | * operation has executed successfully. | 317 | * operation has executed successfully. |
321 | */ | 318 | */ |
322 | static void | 319 | static void |
323 | op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg); | 320 | op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg); |
324 | 321 | ||
325 | 322 | ||
326 | /** | 323 | /** |
@@ -329,18 +326,18 @@ op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg); | |||
329 | * @param cls NULL | 326 | * @param cls NULL |
330 | */ | 327 | */ |
331 | static void | 328 | static void |
332 | do_delayed_connect (void *cls) | 329 | do_delayed_connect(void *cls) |
333 | { | 330 | { |
334 | delayed_connect_task = NULL; | 331 | delayed_connect_task = NULL; |
335 | if (NULL != common_operation) | 332 | if (NULL != common_operation) |
336 | { | 333 | { |
337 | GNUNET_break (0); | 334 | GNUNET_break(0); |
338 | abort_test (); | 335 | abort_test(); |
339 | return; | 336 | return; |
340 | } | 337 | } |
341 | common_operation = | 338 | common_operation = |
342 | GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer, | 339 | GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer1.peer, |
343 | peer2.peer); | 340 | peer2.peer); |
344 | } | 341 | } |
345 | 342 | ||
346 | 343 | ||
@@ -353,33 +350,34 @@ do_delayed_connect (void *cls) | |||
353 | * operation has executed successfully. | 350 | * operation has executed successfully. |
354 | */ | 351 | */ |
355 | static void | 352 | static void |
356 | op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) | 353 | op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) |
357 | { | 354 | { |
358 | if (common_operation != op) | 355 | if (common_operation != op) |
359 | { | 356 | { |
360 | GNUNET_break (0); | 357 | GNUNET_break(0); |
361 | abort_test (); | 358 | abort_test(); |
362 | return; | 359 | return; |
363 | } | 360 | } |
364 | 361 | ||
365 | switch (result) | 362 | switch (result) |
366 | { | 363 | { |
367 | case PEER3_STARTED: | 364 | case PEER3_STARTED: |
368 | case PEERS_2_3_CONNECTED: | 365 | case PEERS_2_3_CONNECTED: |
369 | case PEERS_1_2_CONNECTED: | 366 | case PEERS_1_2_CONNECTED: |
370 | break; | 367 | break; |
371 | default: | 368 | |
372 | GNUNET_break (0); | 369 | default: |
373 | abort_test (); | 370 | GNUNET_break(0); |
374 | return; | 371 | abort_test(); |
375 | } | 372 | return; |
373 | } | ||
376 | if ((NULL != peer1.operation) || (NULL != peer2.operation) || | 374 | if ((NULL != peer1.operation) || (NULL != peer2.operation) || |
377 | (NULL != peer3.operation)) | 375 | (NULL != peer3.operation)) |
378 | { | 376 | { |
379 | GNUNET_break (0); | 377 | GNUNET_break(0); |
380 | abort_test (); | 378 | abort_test(); |
381 | return; | 379 | return; |
382 | } | 380 | } |
383 | } | 381 | } |
384 | 382 | ||
385 | 383 | ||
@@ -393,51 +391,54 @@ op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) | |||
393 | * @param emsg NULL if peer is not NULL; else MAY contain the error description | 391 | * @param emsg NULL if peer is not NULL; else MAY contain the error description |
394 | */ | 392 | */ |
395 | static void | 393 | static void |
396 | peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | 394 | peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) |
397 | { | 395 | { |
398 | switch (result) | 396 | switch (result) |
399 | { | ||
400 | case CONTROLLER1_UP: | ||
401 | if ((NULL == peer1.operation) || (NULL == peer) || (NULL != peer1.peer)) | ||
402 | { | ||
403 | GNUNET_break (0); | ||
404 | abort_test (); | ||
405 | return; | ||
406 | } | ||
407 | peer1.peer = peer; | ||
408 | GNUNET_TESTBED_operation_done (peer1.operation); | ||
409 | result = PEER1_CREATED; | ||
410 | peer1.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL); | ||
411 | break; | ||
412 | case CONTROLLER2_UP: | ||
413 | if ((NULL == peer2.operation) || (NULL == peer) || (NULL != peer2.peer)) | ||
414 | { | ||
415 | GNUNET_break (0); | ||
416 | abort_test (); | ||
417 | return; | ||
418 | } | ||
419 | peer2.peer = peer; | ||
420 | GNUNET_TESTBED_operation_done (peer2.operation); | ||
421 | result = PEER2_CREATED; | ||
422 | peer2.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL); | ||
423 | break; | ||
424 | case CONTROLLER3_UP: | ||
425 | if ((NULL == peer3.operation) || (NULL == peer) || (NULL != peer3.peer)) | ||
426 | { | 397 | { |
427 | GNUNET_break (0); | 398 | case CONTROLLER1_UP: |
428 | abort_test (); | 399 | if ((NULL == peer1.operation) || (NULL == peer) || (NULL != peer1.peer)) |
400 | { | ||
401 | GNUNET_break(0); | ||
402 | abort_test(); | ||
403 | return; | ||
404 | } | ||
405 | peer1.peer = peer; | ||
406 | GNUNET_TESTBED_operation_done(peer1.operation); | ||
407 | result = PEER1_CREATED; | ||
408 | peer1.operation = GNUNET_TESTBED_peer_start(NULL, peer, NULL, NULL); | ||
409 | break; | ||
410 | |||
411 | case CONTROLLER2_UP: | ||
412 | if ((NULL == peer2.operation) || (NULL == peer) || (NULL != peer2.peer)) | ||
413 | { | ||
414 | GNUNET_break(0); | ||
415 | abort_test(); | ||
416 | return; | ||
417 | } | ||
418 | peer2.peer = peer; | ||
419 | GNUNET_TESTBED_operation_done(peer2.operation); | ||
420 | result = PEER2_CREATED; | ||
421 | peer2.operation = GNUNET_TESTBED_peer_start(NULL, peer, NULL, NULL); | ||
422 | break; | ||
423 | |||
424 | case CONTROLLER3_UP: | ||
425 | if ((NULL == peer3.operation) || (NULL == peer) || (NULL != peer3.peer)) | ||
426 | { | ||
427 | GNUNET_break(0); | ||
428 | abort_test(); | ||
429 | return; | ||
430 | } | ||
431 | peer3.peer = peer; | ||
432 | GNUNET_TESTBED_operation_done(peer3.operation); | ||
433 | result = PEER3_CREATED; | ||
434 | peer3.operation = GNUNET_TESTBED_peer_start(NULL, peer, NULL, NULL); | ||
435 | break; | ||
436 | |||
437 | default: | ||
438 | GNUNET_break(0); | ||
439 | abort_test(); | ||
429 | return; | 440 | return; |
430 | } | 441 | } |
431 | peer3.peer = peer; | ||
432 | GNUNET_TESTBED_operation_done (peer3.operation); | ||
433 | result = PEER3_CREATED; | ||
434 | peer3.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL); | ||
435 | break; | ||
436 | default: | ||
437 | GNUNET_break (0); | ||
438 | abort_test (); | ||
439 | return; | ||
440 | } | ||
441 | } | 442 | } |
442 | 443 | ||
443 | 444 | ||
@@ -449,276 +450,289 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | |||
449 | * @param event information about the event | 450 | * @param event information about the event |
450 | */ | 451 | */ |
451 | static void | 452 | static void |
452 | controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | 453 | controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) |
453 | { | 454 | { |
454 | switch (event->type) | 455 | switch (event->type) |
455 | { | ||
456 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
457 | if ((NULL != event->op_cls) || | ||
458 | (NULL != event->details.operation_finished.emsg)) | ||
459 | { | ||
460 | GNUNET_break (0); | ||
461 | abort_test (); | ||
462 | return; | ||
463 | } | ||
464 | switch (result) | ||
465 | { | ||
466 | case PEERS_STOPPED: | ||
467 | if (NULL != event->details.operation_finished.generic) | ||
468 | { | ||
469 | GNUNET_break (0); | ||
470 | abort_test (); | ||
471 | return; | ||
472 | } | ||
473 | if (event->op == peer1.operation) | ||
474 | { | ||
475 | GNUNET_TESTBED_operation_done (peer1.operation); | ||
476 | peer1.operation = NULL; | ||
477 | peer1.peer = NULL; | ||
478 | } | ||
479 | else if (event->op == peer2.operation) | ||
480 | { | ||
481 | GNUNET_TESTBED_operation_done (peer2.operation); | ||
482 | peer2.operation = NULL; | ||
483 | peer2.peer = NULL; | ||
484 | } | ||
485 | else if (event->op == peer3.operation) | ||
486 | { | ||
487 | GNUNET_TESTBED_operation_done (peer3.operation); | ||
488 | peer3.operation = NULL; | ||
489 | peer3.peer = NULL; | ||
490 | } | ||
491 | else | ||
492 | { | ||
493 | GNUNET_break (0); | ||
494 | abort_test (); | ||
495 | return; | ||
496 | } | ||
497 | if ((NULL == peer1.peer) && (NULL == peer2.peer) && (NULL == peer3.peer)) | ||
498 | { | ||
499 | result = SUCCESS; | ||
500 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
501 | } | ||
502 | break; | ||
503 | case PEER1_STARTED: | ||
504 | if ((NULL != event->details.operation_finished.generic) || | ||
505 | (NULL == common_operation)) | ||
506 | { | ||
507 | GNUNET_break (0); | ||
508 | abort_test (); | ||
509 | return; | ||
510 | } | ||
511 | GNUNET_TESTBED_operation_done (common_operation); | ||
512 | common_operation = NULL; | ||
513 | result = CONTROLLER2_UP; | ||
514 | peer2.operation = | ||
515 | GNUNET_TESTBED_peer_create (controller1, neighbour1, cfg, | ||
516 | &peer_create_cb, NULL); | ||
517 | if (NULL == peer2.operation) | ||
518 | { | ||
519 | GNUNET_break (0); | ||
520 | abort_test (); | ||
521 | return; | ||
522 | } | ||
523 | break; | ||
524 | case PEER2_STARTED: | ||
525 | if ((NULL != event->details.operation_finished.generic) || | ||
526 | (NULL == common_operation)) | ||
527 | { | ||
528 | GNUNET_break (0); | ||
529 | abort_test (); | ||
530 | return; | ||
531 | } | ||
532 | GNUNET_TESTBED_operation_done (common_operation); | ||
533 | common_operation = NULL; | ||
534 | result = CONTROLLER3_UP; | ||
535 | peer3.operation = | ||
536 | GNUNET_TESTBED_peer_create (controller1, neighbour2, cfg, | ||
537 | &peer_create_cb, NULL); | ||
538 | if (NULL == peer3.operation) | ||
539 | { | ||
540 | GNUNET_break (0); | ||
541 | abort_test (); | ||
542 | return; | ||
543 | } | ||
544 | break; | ||
545 | default: | ||
546 | GNUNET_break (0); | ||
547 | abort_test (); | ||
548 | return; | ||
549 | } | ||
550 | break; | ||
551 | case GNUNET_TESTBED_ET_PEER_START: | ||
552 | switch (result) | ||
553 | { | 456 | { |
554 | case PEER1_CREATED: | 457 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: |
555 | if (event->details.peer_start.host != host) | 458 | if ((NULL != event->op_cls) || |
556 | { | 459 | (NULL != event->details.operation_finished.emsg)) |
557 | GNUNET_break (0); | 460 | { |
558 | abort_test (); | 461 | GNUNET_break(0); |
559 | return; | 462 | abort_test(); |
560 | } | 463 | return; |
561 | peer1.is_running = GNUNET_YES; | 464 | } |
562 | GNUNET_TESTBED_operation_done (peer1.operation); | 465 | switch (result) |
563 | peer1.operation = NULL; | 466 | { |
564 | result = PEER1_STARTED; | 467 | case PEERS_STOPPED: |
565 | common_operation = | 468 | if (NULL != event->details.operation_finished.generic) |
566 | GNUNET_TESTBED_controller_link (NULL, controller1, neighbour1, NULL, | 469 | { |
567 | GNUNET_YES); | 470 | GNUNET_break(0); |
568 | break; | 471 | abort_test(); |
569 | case PEER2_CREATED: | 472 | return; |
570 | if (event->details.peer_start.host != neighbour1) | 473 | } |
571 | { | 474 | if (event->op == peer1.operation) |
572 | GNUNET_break (0); | 475 | { |
573 | abort_test (); | 476 | GNUNET_TESTBED_operation_done(peer1.operation); |
574 | return; | 477 | peer1.operation = NULL; |
575 | } | 478 | peer1.peer = NULL; |
576 | peer2.is_running = GNUNET_YES; | 479 | } |
577 | GNUNET_TESTBED_operation_done (peer2.operation); | 480 | else if (event->op == peer2.operation) |
578 | peer2.operation = NULL; | 481 | { |
579 | result = PEER2_STARTED; | 482 | GNUNET_TESTBED_operation_done(peer2.operation); |
580 | if (NULL != common_operation) | 483 | peer2.operation = NULL; |
581 | { | 484 | peer2.peer = NULL; |
582 | GNUNET_break (0); | 485 | } |
583 | abort_test (); | 486 | else if (event->op == peer3.operation) |
584 | return; | 487 | { |
585 | } | 488 | GNUNET_TESTBED_operation_done(peer3.operation); |
586 | common_operation = | 489 | peer3.operation = NULL; |
587 | GNUNET_TESTBED_controller_link (NULL, controller1, neighbour2, NULL, | 490 | peer3.peer = NULL; |
588 | GNUNET_YES); | 491 | } |
589 | if (NULL == common_operation) | 492 | else |
590 | { | 493 | { |
591 | GNUNET_break (0); | 494 | GNUNET_break(0); |
592 | abort_test (); | 495 | abort_test(); |
593 | return; | 496 | return; |
594 | } | 497 | } |
498 | if ((NULL == peer1.peer) && (NULL == peer2.peer) && (NULL == peer3.peer)) | ||
499 | { | ||
500 | result = SUCCESS; | ||
501 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); | ||
502 | } | ||
503 | break; | ||
504 | |||
505 | case PEER1_STARTED: | ||
506 | if ((NULL != event->details.operation_finished.generic) || | ||
507 | (NULL == common_operation)) | ||
508 | { | ||
509 | GNUNET_break(0); | ||
510 | abort_test(); | ||
511 | return; | ||
512 | } | ||
513 | GNUNET_TESTBED_operation_done(common_operation); | ||
514 | common_operation = NULL; | ||
515 | result = CONTROLLER2_UP; | ||
516 | peer2.operation = | ||
517 | GNUNET_TESTBED_peer_create(controller1, neighbour1, cfg, | ||
518 | &peer_create_cb, NULL); | ||
519 | if (NULL == peer2.operation) | ||
520 | { | ||
521 | GNUNET_break(0); | ||
522 | abort_test(); | ||
523 | return; | ||
524 | } | ||
525 | break; | ||
526 | |||
527 | case PEER2_STARTED: | ||
528 | if ((NULL != event->details.operation_finished.generic) || | ||
529 | (NULL == common_operation)) | ||
530 | { | ||
531 | GNUNET_break(0); | ||
532 | abort_test(); | ||
533 | return; | ||
534 | } | ||
535 | GNUNET_TESTBED_operation_done(common_operation); | ||
536 | common_operation = NULL; | ||
537 | result = CONTROLLER3_UP; | ||
538 | peer3.operation = | ||
539 | GNUNET_TESTBED_peer_create(controller1, neighbour2, cfg, | ||
540 | &peer_create_cb, NULL); | ||
541 | if (NULL == peer3.operation) | ||
542 | { | ||
543 | GNUNET_break(0); | ||
544 | abort_test(); | ||
545 | return; | ||
546 | } | ||
547 | break; | ||
548 | |||
549 | default: | ||
550 | GNUNET_break(0); | ||
551 | abort_test(); | ||
552 | return; | ||
553 | } | ||
595 | break; | 554 | break; |
596 | case PEER3_CREATED: | 555 | |
597 | if (event->details.peer_start.host != neighbour2) | 556 | case GNUNET_TESTBED_ET_PEER_START: |
598 | { | 557 | switch (result) |
599 | GNUNET_break (0); | 558 | { |
600 | abort_test (); | 559 | case PEER1_CREATED: |
601 | return; | 560 | if (event->details.peer_start.host != host) |
602 | } | 561 | { |
603 | peer3.is_running = GNUNET_YES; | 562 | GNUNET_break(0); |
604 | GNUNET_TESTBED_operation_done (peer3.operation); | 563 | abort_test(); |
605 | peer3.operation = NULL; | 564 | return; |
606 | result = PEER3_STARTED; | 565 | } |
607 | common_operation = | 566 | peer1.is_running = GNUNET_YES; |
608 | GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer, | 567 | GNUNET_TESTBED_operation_done(peer1.operation); |
609 | peer1.peer); | 568 | peer1.operation = NULL; |
610 | break; | 569 | result = PEER1_STARTED; |
611 | default: | 570 | common_operation = |
612 | GNUNET_break (0); | 571 | GNUNET_TESTBED_controller_link(NULL, controller1, neighbour1, NULL, |
613 | abort_test (); | 572 | GNUNET_YES); |
614 | return; | 573 | break; |
615 | } | 574 | |
616 | break; | 575 | case PEER2_CREATED: |
617 | case GNUNET_TESTBED_ET_PEER_STOP: | 576 | if (event->details.peer_start.host != neighbour1) |
618 | if (PEERS_CONNECTED_2 != result) | 577 | { |
619 | { | 578 | GNUNET_break(0); |
620 | GNUNET_break (0); | 579 | abort_test(); |
621 | abort_test (); | 580 | return; |
622 | return; | 581 | } |
623 | } | 582 | peer2.is_running = GNUNET_YES; |
624 | if (event->details.peer_stop.peer == peer1.peer) | 583 | GNUNET_TESTBED_operation_done(peer2.operation); |
625 | { | 584 | peer2.operation = NULL; |
626 | peer1.is_running = GNUNET_NO; | 585 | result = PEER2_STARTED; |
627 | GNUNET_TESTBED_operation_done (peer1.operation); | 586 | if (NULL != common_operation) |
628 | } | 587 | { |
629 | else if (event->details.peer_stop.peer == peer2.peer) | 588 | GNUNET_break(0); |
630 | { | 589 | abort_test(); |
631 | peer2.is_running = GNUNET_NO; | 590 | return; |
632 | GNUNET_TESTBED_operation_done (peer2.operation); | 591 | } |
633 | } | 592 | common_operation = |
634 | else if (event->details.peer_stop.peer == peer3.peer) | 593 | GNUNET_TESTBED_controller_link(NULL, controller1, neighbour2, NULL, |
635 | { | 594 | GNUNET_YES); |
636 | peer3.is_running = GNUNET_NO; | 595 | if (NULL == common_operation) |
637 | GNUNET_TESTBED_operation_done (peer3.operation); | 596 | { |
638 | } | 597 | GNUNET_break(0); |
639 | else | 598 | abort_test(); |
640 | { | 599 | return; |
641 | GNUNET_break (0); | 600 | } |
642 | abort_test (); | 601 | break; |
643 | return; | 602 | |
644 | } | 603 | case PEER3_CREATED: |
645 | if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running) && | 604 | if (event->details.peer_start.host != neighbour2) |
646 | (GNUNET_NO == peer3.is_running)) | 605 | { |
647 | { | 606 | GNUNET_break(0); |
648 | result = PEERS_STOPPED; | 607 | abort_test(); |
649 | peer1.operation = GNUNET_TESTBED_peer_destroy (peer1.peer); | 608 | return; |
650 | peer2.operation = GNUNET_TESTBED_peer_destroy (peer2.peer); | 609 | } |
651 | peer3.operation = GNUNET_TESTBED_peer_destroy (peer3.peer); | 610 | peer3.is_running = GNUNET_YES; |
652 | } | 611 | GNUNET_TESTBED_operation_done(peer3.operation); |
653 | break; | 612 | peer3.operation = NULL; |
654 | case GNUNET_TESTBED_ET_CONNECT: | 613 | result = PEER3_STARTED; |
655 | if ((NULL != peer1.operation) || (NULL != peer2.operation) || | 614 | common_operation = |
656 | (NULL != peer3.operation) || (NULL == common_operation)) | 615 | GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer2.peer, |
657 | { | 616 | peer1.peer); |
658 | GNUNET_break (0); | 617 | break; |
659 | abort_test (); | 618 | |
660 | return; | 619 | default: |
661 | } | 620 | GNUNET_break(0); |
662 | switch (result) | 621 | abort_test(); |
663 | { | 622 | return; |
664 | case PEER3_STARTED: | 623 | } |
665 | if ((event->details.peer_connect.peer1 != peer2.peer) || | ||
666 | (event->details.peer_connect.peer2 != peer1.peer)) | ||
667 | { | ||
668 | GNUNET_break (0); | ||
669 | abort_test (); | ||
670 | return; | ||
671 | } | ||
672 | GNUNET_TESTBED_operation_done (common_operation); | ||
673 | common_operation = NULL; | ||
674 | result = PEERS_1_2_CONNECTED; | ||
675 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n"); | ||
676 | common_operation = | ||
677 | GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer, | ||
678 | peer3.peer); | ||
679 | break; | 624 | break; |
680 | case PEERS_1_2_CONNECTED: | 625 | |
681 | if ((event->details.peer_connect.peer1 != peer2.peer) || | 626 | case GNUNET_TESTBED_ET_PEER_STOP: |
682 | (event->details.peer_connect.peer2 != peer3.peer)) | 627 | if (PEERS_CONNECTED_2 != result) |
683 | { | 628 | { |
684 | GNUNET_break (0); | 629 | GNUNET_break(0); |
685 | abort_test (); | 630 | abort_test(); |
686 | return; | 631 | return; |
687 | } | 632 | } |
688 | GNUNET_TESTBED_operation_done (common_operation); | 633 | if (event->details.peer_stop.peer == peer1.peer) |
689 | common_operation = NULL; | 634 | { |
690 | result = PEERS_2_3_CONNECTED; | 635 | peer1.is_running = GNUNET_NO; |
691 | delayed_connect_task = | 636 | GNUNET_TESTBED_operation_done(peer1.operation); |
692 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3), &do_delayed_connect, | 637 | } |
693 | NULL); | 638 | else if (event->details.peer_stop.peer == peer2.peer) |
639 | { | ||
640 | peer2.is_running = GNUNET_NO; | ||
641 | GNUNET_TESTBED_operation_done(peer2.operation); | ||
642 | } | ||
643 | else if (event->details.peer_stop.peer == peer3.peer) | ||
644 | { | ||
645 | peer3.is_running = GNUNET_NO; | ||
646 | GNUNET_TESTBED_operation_done(peer3.operation); | ||
647 | } | ||
648 | else | ||
649 | { | ||
650 | GNUNET_break(0); | ||
651 | abort_test(); | ||
652 | return; | ||
653 | } | ||
654 | if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running) && | ||
655 | (GNUNET_NO == peer3.is_running)) | ||
656 | { | ||
657 | result = PEERS_STOPPED; | ||
658 | peer1.operation = GNUNET_TESTBED_peer_destroy(peer1.peer); | ||
659 | peer2.operation = GNUNET_TESTBED_peer_destroy(peer2.peer); | ||
660 | peer3.operation = GNUNET_TESTBED_peer_destroy(peer3.peer); | ||
661 | } | ||
694 | break; | 662 | break; |
695 | case PEERS_2_3_CONNECTED: | 663 | |
696 | if ((event->details.peer_connect.peer1 != peer1.peer) || | 664 | case GNUNET_TESTBED_ET_CONNECT: |
697 | (event->details.peer_connect.peer2 != peer2.peer)) | 665 | if ((NULL != peer1.operation) || (NULL != peer2.operation) || |
698 | { | 666 | (NULL != peer3.operation) || (NULL == common_operation)) |
699 | GNUNET_break (0); | 667 | { |
700 | abort_test (); | 668 | GNUNET_break(0); |
701 | return; | 669 | abort_test(); |
702 | } | 670 | return; |
703 | GNUNET_TESTBED_operation_done (common_operation); | 671 | } |
704 | common_operation = NULL; | 672 | switch (result) |
705 | result = PEERS_CONNECTED_2; | 673 | { |
706 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n"); | 674 | case PEER3_STARTED: |
707 | peer1.operation = GNUNET_TESTBED_peer_stop (NULL, peer1.peer, NULL, NULL); | 675 | if ((event->details.peer_connect.peer1 != peer2.peer) || |
708 | peer2.operation = GNUNET_TESTBED_peer_stop (NULL, peer2.peer, NULL, NULL); | 676 | (event->details.peer_connect.peer2 != peer1.peer)) |
709 | peer3.operation = GNUNET_TESTBED_peer_stop (NULL, peer3.peer, NULL, NULL); | 677 | { |
678 | GNUNET_break(0); | ||
679 | abort_test(); | ||
680 | return; | ||
681 | } | ||
682 | GNUNET_TESTBED_operation_done(common_operation); | ||
683 | common_operation = NULL; | ||
684 | result = PEERS_1_2_CONNECTED; | ||
685 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n"); | ||
686 | common_operation = | ||
687 | GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer2.peer, | ||
688 | peer3.peer); | ||
689 | break; | ||
690 | |||
691 | case PEERS_1_2_CONNECTED: | ||
692 | if ((event->details.peer_connect.peer1 != peer2.peer) || | ||
693 | (event->details.peer_connect.peer2 != peer3.peer)) | ||
694 | { | ||
695 | GNUNET_break(0); | ||
696 | abort_test(); | ||
697 | return; | ||
698 | } | ||
699 | GNUNET_TESTBED_operation_done(common_operation); | ||
700 | common_operation = NULL; | ||
701 | result = PEERS_2_3_CONNECTED; | ||
702 | delayed_connect_task = | ||
703 | GNUNET_SCHEDULER_add_delayed(TIME_REL_SECS(3), &do_delayed_connect, | ||
704 | NULL); | ||
705 | break; | ||
706 | |||
707 | case PEERS_2_3_CONNECTED: | ||
708 | if ((event->details.peer_connect.peer1 != peer1.peer) || | ||
709 | (event->details.peer_connect.peer2 != peer2.peer)) | ||
710 | { | ||
711 | GNUNET_break(0); | ||
712 | abort_test(); | ||
713 | return; | ||
714 | } | ||
715 | GNUNET_TESTBED_operation_done(common_operation); | ||
716 | common_operation = NULL; | ||
717 | result = PEERS_CONNECTED_2; | ||
718 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n"); | ||
719 | peer1.operation = GNUNET_TESTBED_peer_stop(NULL, peer1.peer, NULL, NULL); | ||
720 | peer2.operation = GNUNET_TESTBED_peer_stop(NULL, peer2.peer, NULL, NULL); | ||
721 | peer3.operation = GNUNET_TESTBED_peer_stop(NULL, peer3.peer, NULL, NULL); | ||
722 | break; | ||
723 | |||
724 | default: | ||
725 | GNUNET_break(0); | ||
726 | abort_test(); | ||
727 | return; | ||
728 | } | ||
710 | break; | 729 | break; |
730 | |||
711 | default: | 731 | default: |
712 | GNUNET_break (0); | 732 | GNUNET_break(0); |
713 | abort_test (); | 733 | abort_test(); |
714 | return; | 734 | return; |
715 | } | 735 | } |
716 | break; | ||
717 | default: | ||
718 | GNUNET_break (0); | ||
719 | abort_test (); | ||
720 | return; | ||
721 | } | ||
722 | } | 736 | } |
723 | 737 | ||
724 | 738 | ||
@@ -729,44 +743,44 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
729 | * @param emsg the error message; NULL if host registration is successful | 743 | * @param emsg the error message; NULL if host registration is successful |
730 | */ | 744 | */ |
731 | static void | 745 | static void |
732 | registration_comp (void *cls, const char *emsg) | 746 | registration_comp(void *cls, const char *emsg) |
733 | { | 747 | { |
734 | reg_handle = NULL; | 748 | reg_handle = NULL; |
735 | if (cls == neighbour1) | 749 | if (cls == neighbour1) |
736 | { | ||
737 | neighbour2 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, cfg, 0); | ||
738 | if (NULL == neighbour2) | ||
739 | { | 750 | { |
740 | GNUNET_break (0); | 751 | neighbour2 = GNUNET_TESTBED_host_create("127.0.0.1", NULL, cfg, 0); |
741 | abort_test (); | 752 | if (NULL == neighbour2) |
753 | { | ||
754 | GNUNET_break(0); | ||
755 | abort_test(); | ||
756 | return; | ||
757 | } | ||
758 | reg_handle = | ||
759 | GNUNET_TESTBED_register_host(controller1, neighbour2, | ||
760 | ®istration_comp, neighbour2); | ||
761 | if (NULL == reg_handle) | ||
762 | { | ||
763 | GNUNET_break(0); | ||
764 | abort_test(); | ||
765 | return; | ||
766 | } | ||
742 | return; | 767 | return; |
743 | } | 768 | } |
744 | reg_handle = | 769 | if (cls != neighbour2) |
745 | GNUNET_TESTBED_register_host (controller1, neighbour2, | ||
746 | ®istration_comp, neighbour2); | ||
747 | if (NULL == reg_handle) | ||
748 | { | 770 | { |
749 | GNUNET_break (0); | 771 | GNUNET_break(0); |
750 | abort_test (); | 772 | abort_test(); |
751 | return; | 773 | return; |
752 | } | 774 | } |
753 | return; | ||
754 | } | ||
755 | if (cls != neighbour2) | ||
756 | { | ||
757 | GNUNET_break (0); | ||
758 | abort_test (); | ||
759 | return; | ||
760 | } | ||
761 | peer1.operation = | 775 | peer1.operation = |
762 | GNUNET_TESTBED_peer_create (controller1, host, cfg, &peer_create_cb, | 776 | GNUNET_TESTBED_peer_create(controller1, host, cfg, &peer_create_cb, |
763 | &peer1); | 777 | &peer1); |
764 | if (NULL == peer1.operation) | 778 | if (NULL == peer1.operation) |
765 | { | 779 | { |
766 | GNUNET_break (0); | 780 | GNUNET_break(0); |
767 | abort_test (); | 781 | abort_test(); |
768 | return; | 782 | return; |
769 | } | 783 | } |
770 | } | 784 | } |
771 | 785 | ||
772 | 786 | ||
@@ -780,58 +794,59 @@ registration_comp (void *cls, const char *emsg) | |||
780 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case | 794 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case |
781 | */ | 795 | */ |
782 | static void | 796 | static void |
783 | status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, | 797 | status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *config, |
784 | int status) | 798 | int status) |
785 | { | 799 | { |
786 | uint64_t event_mask; | 800 | uint64_t event_mask; |
787 | 801 | ||
788 | if (GNUNET_OK != status) | 802 | if (GNUNET_OK != status) |
789 | { | 803 | { |
790 | GNUNET_break (0); | 804 | GNUNET_break(0); |
791 | cp1 = NULL; | 805 | cp1 = NULL; |
792 | abort_test (); | 806 | abort_test(); |
793 | return; | 807 | return; |
794 | } | 808 | } |
795 | event_mask = 0; | 809 | event_mask = 0; |
796 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); | 810 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); |
797 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); | 811 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); |
798 | event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); | 812 | event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); |
799 | event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 813 | event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
800 | switch (result) | 814 | switch (result) |
801 | { | ||
802 | case INIT: | ||
803 | controller1 = | ||
804 | GNUNET_TESTBED_controller_connect (host, event_mask, | ||
805 | &controller_cb, NULL); | ||
806 | if (NULL == controller1) | ||
807 | { | ||
808 | GNUNET_break (0); | ||
809 | abort_test (); | ||
810 | return; | ||
811 | } | ||
812 | result = CONTROLLER1_UP; | ||
813 | neighbour1 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, cfg, 0); | ||
814 | if (NULL == neighbour1) | ||
815 | { | ||
816 | GNUNET_break (0); | ||
817 | abort_test (); | ||
818 | return; | ||
819 | } | ||
820 | reg_handle = | ||
821 | GNUNET_TESTBED_register_host (controller1, neighbour1, | ||
822 | ®istration_comp, neighbour1); | ||
823 | if (NULL == reg_handle) | ||
824 | { | 815 | { |
825 | GNUNET_break (0); | 816 | case INIT: |
826 | abort_test (); | 817 | controller1 = |
818 | GNUNET_TESTBED_controller_connect(host, event_mask, | ||
819 | &controller_cb, NULL); | ||
820 | if (NULL == controller1) | ||
821 | { | ||
822 | GNUNET_break(0); | ||
823 | abort_test(); | ||
824 | return; | ||
825 | } | ||
826 | result = CONTROLLER1_UP; | ||
827 | neighbour1 = GNUNET_TESTBED_host_create("127.0.0.1", NULL, cfg, 0); | ||
828 | if (NULL == neighbour1) | ||
829 | { | ||
830 | GNUNET_break(0); | ||
831 | abort_test(); | ||
832 | return; | ||
833 | } | ||
834 | reg_handle = | ||
835 | GNUNET_TESTBED_register_host(controller1, neighbour1, | ||
836 | ®istration_comp, neighbour1); | ||
837 | if (NULL == reg_handle) | ||
838 | { | ||
839 | GNUNET_break(0); | ||
840 | abort_test(); | ||
841 | return; | ||
842 | } | ||
843 | break; | ||
844 | |||
845 | default: | ||
846 | GNUNET_break(0); | ||
847 | abort_test(); | ||
827 | return; | 848 | return; |
828 | } | 849 | } |
829 | break; | ||
830 | default: | ||
831 | GNUNET_break (0); | ||
832 | abort_test (); | ||
833 | return; | ||
834 | } | ||
835 | } | 850 | } |
836 | 851 | ||
837 | 852 | ||
@@ -846,25 +861,25 @@ status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, | |||
846 | * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not | 861 | * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not |
847 | */ | 862 | */ |
848 | static void | 863 | static void |
849 | host_habitable_cb (void *cls, | 864 | host_habitable_cb(void *cls, |
850 | const struct GNUNET_TESTBED_Host *_host, | 865 | const struct GNUNET_TESTBED_Host *_host, |
851 | int status) | 866 | int status) |
852 | { | 867 | { |
853 | hc_handle = NULL; | 868 | hc_handle = NULL; |
854 | if (GNUNET_NO == status) | 869 | if (GNUNET_NO == status) |
855 | { | 870 | { |
856 | (void) printf ("%s", | 871 | (void)printf("%s", |
857 | "Unable to run the test as this system is not configured " | 872 | "Unable to run the test as this system is not configured " |
858 | "to use password less SSH logins to localhost.\n" | 873 | "to use password less SSH logins to localhost.\n" |
859 | "Skipping test\n"); | 874 | "Skipping test\n"); |
860 | GNUNET_SCHEDULER_cancel (abort_task); | 875 | GNUNET_SCHEDULER_cancel(abort_task); |
861 | abort_task = NULL; | 876 | abort_task = NULL; |
862 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 877 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
863 | result = SKIP; | 878 | result = SKIP; |
864 | return; | 879 | return; |
865 | } | 880 | } |
866 | cp1 = | 881 | cp1 = |
867 | GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb, NULL); | 882 | GNUNET_TESTBED_controller_start("127.0.0.1", host, status_cb, NULL); |
868 | } | 883 | } |
869 | 884 | ||
870 | 885 | ||
@@ -877,35 +892,35 @@ host_habitable_cb (void *cls, | |||
877 | * @param cfg the configuration file handle | 892 | * @param cfg the configuration file handle |
878 | */ | 893 | */ |
879 | static void | 894 | static void |
880 | run (void *cls, char *const *args, const char *cfgfile, | 895 | run(void *cls, char *const *args, const char *cfgfile, |
881 | const struct GNUNET_CONFIGURATION_Handle *config) | 896 | const struct GNUNET_CONFIGURATION_Handle *config) |
882 | { | 897 | { |
883 | cfg = GNUNET_CONFIGURATION_dup (config); | 898 | cfg = GNUNET_CONFIGURATION_dup(config); |
884 | host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0); | 899 | host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0); |
885 | if (NULL == host) | 900 | if (NULL == host) |
886 | { | 901 | { |
887 | GNUNET_break (0); | 902 | GNUNET_break(0); |
888 | abort_test (); | 903 | abort_test(); |
889 | return; | 904 | return; |
890 | } | 905 | } |
891 | if (NULL == | 906 | if (NULL == |
892 | (hc_handle = | 907 | (hc_handle = |
893 | GNUNET_TESTBED_is_host_habitable (host, config, &host_habitable_cb, | 908 | GNUNET_TESTBED_is_host_habitable(host, config, &host_habitable_cb, |
894 | NULL))) | 909 | NULL))) |
895 | { | 910 | { |
896 | GNUNET_TESTBED_host_destroy (host); | 911 | GNUNET_TESTBED_host_destroy(host); |
897 | host = NULL; | 912 | host = NULL; |
898 | (void) printf ("%s", | 913 | (void)printf("%s", |
899 | "Unable to run the test as this system is not configured " | 914 | "Unable to run the test as this system is not configured " |
900 | "to use password less SSH logins to localhost.\n" | 915 | "to use password less SSH logins to localhost.\n" |
901 | "Skipping test\n"); | 916 | "Skipping test\n"); |
902 | result = SKIP; | 917 | result = SKIP; |
903 | return; | 918 | return; |
904 | } | 919 | } |
905 | abort_task = | 920 | abort_task = |
906 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 921 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
907 | (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, | 922 | (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, |
908 | NULL); | 923 | NULL); |
909 | } | 924 | } |
910 | 925 | ||
911 | 926 | ||
@@ -913,12 +928,11 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
913 | * Main function | 928 | * Main function |
914 | */ | 929 | */ |
915 | int | 930 | int |
916 | main (int argc, char **argv) | 931 | main(int argc, char **argv) |
917 | { | 932 | { |
918 | char *const argv2[] = { "test_testbed_api_3peers_3controllers", | 933 | char *const argv2[] = { "test_testbed_api_3peers_3controllers", |
919 | "-c", "test_testbed_api.conf", | 934 | "-c", "test_testbed_api.conf", |
920 | NULL | 935 | NULL }; |
921 | }; | ||
922 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 936 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
923 | GNUNET_GETOPT_OPTION_END | 937 | GNUNET_GETOPT_OPTION_END |
924 | }; | 938 | }; |
@@ -926,20 +940,22 @@ main (int argc, char **argv) | |||
926 | 940 | ||
927 | result = INIT; | 941 | result = INIT; |
928 | ret = | 942 | ret = |
929 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | 943 | GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, |
930 | "test_testbed_api_3peers_3controllers", "nohelp", | 944 | "test_testbed_api_3peers_3controllers", "nohelp", |
931 | options, &run, NULL); | 945 | options, &run, NULL); |
932 | if (GNUNET_OK != ret) | 946 | if (GNUNET_OK != ret) |
933 | return 1; | 947 | return 1; |
934 | switch (result) | 948 | switch (result) |
935 | { | 949 | { |
936 | case SUCCESS: | 950 | case SUCCESS: |
937 | return 0; | 951 | return 0; |
938 | case SKIP: | 952 | |
939 | return 77; /* Mark test as skipped */ | 953 | case SKIP: |
940 | default: | 954 | return 77; /* Mark test as skipped */ |
941 | return 1; | 955 | |
942 | } | 956 | default: |
957 | return 1; | ||
958 | } | ||
943 | } | 959 | } |
944 | 960 | ||
945 | /* end of test_testbed_api_3peers_3controllers.c */ | 961 | /* end of test_testbed_api_3peers_3controllers.c */ |
diff --git a/src/testbed/test_testbed_api_barriers.c b/src/testbed/test_testbed_api_barriers.c index 9383ab85b..b07dd5339 100644 --- a/src/testbed/test_testbed_api_barriers.c +++ b/src/testbed/test_testbed_api_barriers.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -33,8 +33,8 @@ | |||
33 | /** | 33 | /** |
34 | * logging short hand | 34 | * logging short hand |
35 | */ | 35 | */ |
36 | #define LOG(type,...) \ | 36 | #define LOG(type, ...) \ |
37 | GNUNET_log (type, __VA_ARGS__); | 37 | GNUNET_log(type, __VA_ARGS__); |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * Number of peers we start in this test case | 40 | * Number of peers we start in this test case |
@@ -65,10 +65,10 @@ static void | |||
65 | shutdown_handler(void *cls) | 65 | shutdown_handler(void *cls) |
66 | { | 66 | { |
67 | if (NULL != timeout_task) | 67 | if (NULL != timeout_task) |
68 | { | 68 | { |
69 | GNUNET_SCHEDULER_cancel(timeout_task); | 69 | GNUNET_SCHEDULER_cancel(timeout_task); |
70 | timeout_task = NULL; | 70 | timeout_task = NULL; |
71 | } | 71 | } |
72 | } | 72 | } |
73 | 73 | ||
74 | 74 | ||
@@ -78,12 +78,12 @@ shutdown_handler(void *cls) | |||
78 | * @param cls NULL | 78 | * @param cls NULL |
79 | */ | 79 | */ |
80 | static void | 80 | static void |
81 | do_timeout (void *cls) | 81 | do_timeout(void *cls) |
82 | { | 82 | { |
83 | timeout_task = NULL; | 83 | timeout_task = NULL; |
84 | if (barrier != NULL) | 84 | if (barrier != NULL) |
85 | GNUNET_TESTBED_barrier_cancel (barrier); | 85 | GNUNET_TESTBED_barrier_cancel(barrier); |
86 | GNUNET_SCHEDULER_shutdown (); | 86 | GNUNET_SCHEDULER_shutdown(); |
87 | } | 87 | } |
88 | 88 | ||
89 | 89 | ||
@@ -101,40 +101,43 @@ do_timeout (void *cls) | |||
101 | * error messsage | 101 | * error messsage |
102 | */ | 102 | */ |
103 | static void | 103 | static void |
104 | barrier_cb (void *cls, | 104 | barrier_cb(void *cls, |
105 | const char *name, | 105 | const char *name, |
106 | struct GNUNET_TESTBED_Barrier *_barrier, | 106 | struct GNUNET_TESTBED_Barrier *_barrier, |
107 | enum GNUNET_TESTBED_BarrierStatus status, | 107 | enum GNUNET_TESTBED_BarrierStatus status, |
108 | const char *emsg) | 108 | const char *emsg) |
109 | { | 109 | { |
110 | static enum GNUNET_TESTBED_BarrierStatus old_status; | 110 | static enum GNUNET_TESTBED_BarrierStatus old_status; |
111 | 111 | ||
112 | GNUNET_assert (NULL == cls); | 112 | GNUNET_assert(NULL == cls); |
113 | GNUNET_assert (_barrier == barrier); | 113 | GNUNET_assert(_barrier == barrier); |
114 | switch (status) | 114 | switch (status) |
115 | { | 115 | { |
116 | case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: | 116 | case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: |
117 | LOG (GNUNET_ERROR_TYPE_INFO, | 117 | LOG(GNUNET_ERROR_TYPE_INFO, |
118 | "Barrier initialised\n"); | 118 | "Barrier initialised\n"); |
119 | old_status = status; | 119 | old_status = status; |
120 | return; | 120 | return; |
121 | case GNUNET_TESTBED_BARRIERSTATUS_ERROR: | 121 | |
122 | LOG (GNUNET_ERROR_TYPE_ERROR, | 122 | case GNUNET_TESTBED_BARRIERSTATUS_ERROR: |
123 | "Barrier initialisation failed: %s", | 123 | LOG(GNUNET_ERROR_TYPE_ERROR, |
124 | (NULL == emsg) ? "unknown reason" : emsg); | 124 | "Barrier initialisation failed: %s", |
125 | break; | 125 | (NULL == emsg) ? "unknown reason" : emsg); |
126 | case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: | 126 | break; |
127 | LOG (GNUNET_ERROR_TYPE_INFO, | 127 | |
128 | "Barrier crossed\n"); | 128 | case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: |
129 | if (old_status == GNUNET_TESTBED_BARRIERSTATUS_INITIALISED) | 129 | LOG(GNUNET_ERROR_TYPE_INFO, |
130 | result = GNUNET_OK; | 130 | "Barrier crossed\n"); |
131 | break; | 131 | if (old_status == GNUNET_TESTBED_BARRIERSTATUS_INITIALISED) |
132 | default: | 132 | result = GNUNET_OK; |
133 | GNUNET_assert (0); | 133 | break; |
134 | return; | 134 | |
135 | } | 135 | default: |
136 | GNUNET_assert(0); | ||
137 | return; | ||
138 | } | ||
136 | barrier = NULL; | 139 | barrier = NULL; |
137 | GNUNET_SCHEDULER_shutdown (); | 140 | GNUNET_SCHEDULER_shutdown(); |
138 | } | 141 | } |
139 | 142 | ||
140 | 143 | ||
@@ -151,34 +154,34 @@ barrier_cb (void *cls, | |||
151 | * failed | 154 | * failed |
152 | */ | 155 | */ |
153 | static void | 156 | static void |
154 | test_master (void *cls, | 157 | test_master(void *cls, |
155 | struct GNUNET_TESTBED_RunHandle *h, | 158 | struct GNUNET_TESTBED_RunHandle *h, |
156 | unsigned int num_peers, | 159 | unsigned int num_peers, |
157 | struct GNUNET_TESTBED_Peer **peers_, | 160 | struct GNUNET_TESTBED_Peer **peers_, |
158 | unsigned int links_succeeded, | 161 | unsigned int links_succeeded, |
159 | unsigned int links_failed) | 162 | unsigned int links_failed) |
160 | { | 163 | { |
161 | struct GNUNET_TESTBED_Controller *c; | 164 | struct GNUNET_TESTBED_Controller *c; |
162 | 165 | ||
163 | GNUNET_assert (NULL == cls); | 166 | GNUNET_assert(NULL == cls); |
164 | if (NULL == peers_) | 167 | if (NULL == peers_) |
165 | { | 168 | { |
166 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 169 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
167 | "Failing test due to timeout\n"); | 170 | "Failing test due to timeout\n"); |
168 | return; | 171 | return; |
169 | } | 172 | } |
170 | GNUNET_assert (NUM_PEERS == num_peers); | 173 | GNUNET_assert(NUM_PEERS == num_peers); |
171 | c = GNUNET_TESTBED_run_get_controller_handle (h); | 174 | c = GNUNET_TESTBED_run_get_controller_handle(h); |
172 | barrier = GNUNET_TESTBED_barrier_init (c, | 175 | barrier = GNUNET_TESTBED_barrier_init(c, |
173 | TEST_BARRIER_NAME, | 176 | TEST_BARRIER_NAME, |
174 | 100, | 177 | 100, |
175 | &barrier_cb, | 178 | &barrier_cb, |
176 | NULL); | 179 | NULL); |
177 | timeout_task = | 180 | timeout_task = |
178 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 181 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
179 | (GNUNET_TIME_UNIT_SECONDS, | 182 | (GNUNET_TIME_UNIT_SECONDS, |
180 | 10 * (NUM_PEERS + 1)), | 183 | 10 * (NUM_PEERS + 1)), |
181 | &do_timeout, NULL); | 184 | &do_timeout, NULL); |
182 | GNUNET_SCHEDULER_add_shutdown(&shutdown_handler, NULL); | 185 | GNUNET_SCHEDULER_add_shutdown(&shutdown_handler, NULL); |
183 | } | 186 | } |
184 | 187 | ||
@@ -195,7 +198,7 @@ test_master (void *cls, | |||
195 | * Main function | 198 | * Main function |
196 | */ | 199 | */ |
197 | int | 200 | int |
198 | main (int argc, char **argv) | 201 | main(int argc, char **argv) |
199 | { | 202 | { |
200 | struct GNUNET_CONFIGURATION_Handle *cfg; | 203 | struct GNUNET_CONFIGURATION_Handle *cfg; |
201 | char pwd[PATH_MAX]; | 204 | char pwd[PATH_MAX]; |
@@ -204,26 +207,26 @@ main (int argc, char **argv) | |||
204 | 207 | ||
205 | result = GNUNET_SYSERR; | 208 | result = GNUNET_SYSERR; |
206 | event_mask = 0; | 209 | event_mask = 0; |
207 | cfg = GNUNET_CONFIGURATION_create (); | 210 | cfg = GNUNET_CONFIGURATION_create(); |
208 | GNUNET_assert (GNUNET_YES == | 211 | GNUNET_assert(GNUNET_YES == |
209 | GNUNET_CONFIGURATION_parse (cfg, | 212 | GNUNET_CONFIGURATION_parse(cfg, |
210 | "test_testbed_api_barriers.conf.in")); | 213 | "test_testbed_api_barriers.conf.in")); |
211 | if (NULL == getcwd (pwd, PATH_MAX)) | 214 | if (NULL == getcwd(pwd, PATH_MAX)) |
212 | return 1; | 215 | return 1; |
213 | GNUNET_assert (0 < GNUNET_asprintf (&binary, "%s/%s", pwd, | 216 | GNUNET_assert(0 < GNUNET_asprintf(&binary, "%s/%s", pwd, |
214 | "gnunet-service-test-barriers")); | 217 | "gnunet-service-test-barriers")); |
215 | GNUNET_CONFIGURATION_set_value_string (cfg, "test-barriers","BINARY", binary); | 218 | GNUNET_CONFIGURATION_set_value_string(cfg, "test-barriers", "BINARY", binary); |
216 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write | 219 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_write |
217 | (cfg, "test_testbed_api_barriers.conf")); | 220 | (cfg, "test_testbed_api_barriers.conf")); |
218 | GNUNET_CONFIGURATION_destroy (cfg); | 221 | GNUNET_CONFIGURATION_destroy(cfg); |
219 | cfg = NULL; | 222 | cfg = NULL; |
220 | GNUNET_free (binary); | 223 | GNUNET_free(binary); |
221 | binary = NULL; | 224 | binary = NULL; |
222 | (void) GNUNET_TESTBED_test_run ("test_testbed_api_barriers", | 225 | (void)GNUNET_TESTBED_test_run("test_testbed_api_barriers", |
223 | "test_testbed_api_barriers.conf", NUM_PEERS, | 226 | "test_testbed_api_barriers.conf", NUM_PEERS, |
224 | event_mask, NULL, NULL, | 227 | event_mask, NULL, NULL, |
225 | &test_master, NULL); | 228 | &test_master, NULL); |
226 | (void) unlink ("test_testbed_api_barriers.conf"); | 229 | (void)unlink("test_testbed_api_barriers.conf"); |
227 | if (GNUNET_OK != result) | 230 | if (GNUNET_OK != result) |
228 | return 1; | 231 | return 1; |
229 | return 0; | 232 | return 0; |
diff --git a/src/testbed/test_testbed_api_controllerlink.c b/src/testbed/test_testbed_api_controllerlink.c index 6c1a24f9c..ffcbebf00 100644 --- a/src/testbed/test_testbed_api_controllerlink.c +++ b/src/testbed/test_testbed_api_controllerlink.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -45,19 +45,17 @@ | |||
45 | /** | 45 | /** |
46 | * Generic logging shortcut | 46 | * Generic logging shortcut |
47 | */ | 47 | */ |
48 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | 48 | #define LOG(kind, ...) GNUNET_log(kind, __VA_ARGS__) |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * Debug logging shorthand | 51 | * Debug logging shorthand |
52 | */ | 52 | */ |
53 | #define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 53 | #define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Different stages in testing | 56 | * Different stages in testing |
57 | */ | 57 | */ |
58 | enum Stage | 58 | enum Stage { |
59 | { | ||
60 | |||
61 | /** | 59 | /** |
62 | * Initial stage | 60 | * Initial stage |
63 | */ | 61 | */ |
@@ -294,17 +292,17 @@ static enum Stage result; | |||
294 | */ | 292 | */ |
295 | #define FAIL_TEST(cond) \ | 293 | #define FAIL_TEST(cond) \ |
296 | do \ | 294 | do \ |
297 | { \ | 295 | { \ |
298 | if (! (cond)) \ | 296 | if (!(cond)) \ |
299 | { \ | 297 | { \ |
300 | GNUNET_break (0); \ | 298 | GNUNET_break(0); \ |
301 | if (NULL != abort_task) \ | 299 | if (NULL != abort_task) \ |
302 | GNUNET_SCHEDULER_cancel (abort_task); \ | 300 | GNUNET_SCHEDULER_cancel (abort_task); \ |
303 | abort_task = NULL; \ | 301 | abort_task = NULL; \ |
304 | GNUNET_SCHEDULER_shutdown (); \ | 302 | GNUNET_SCHEDULER_shutdown(); \ |
305 | return; \ | 303 | return; \ |
306 | } \ | 304 | } \ |
307 | } while (0) | 305 | } while (0) |
308 | 306 | ||
309 | 307 | ||
310 | /** | 308 | /** |
@@ -313,40 +311,40 @@ static enum Stage result; | |||
313 | * @param cls NULL | 311 | * @param cls NULL |
314 | */ | 312 | */ |
315 | static void | 313 | static void |
316 | do_shutdown (void *cls) | 314 | do_shutdown(void *cls) |
317 | { | 315 | { |
318 | if (NULL != abort_task) | 316 | if (NULL != abort_task) |
319 | GNUNET_SCHEDULER_cancel (abort_task); | 317 | GNUNET_SCHEDULER_cancel(abort_task); |
320 | if (NULL != delay_task_id) | 318 | if (NULL != delay_task_id) |
321 | { | 319 | { |
322 | GNUNET_SCHEDULER_cancel (delay_task_id); | 320 | GNUNET_SCHEDULER_cancel(delay_task_id); |
323 | delay_task_id = NULL; | 321 | delay_task_id = NULL; |
324 | } | 322 | } |
325 | if (NULL != hc_handle) | 323 | if (NULL != hc_handle) |
326 | GNUNET_TESTBED_is_host_habitable_cancel (hc_handle); | 324 | GNUNET_TESTBED_is_host_habitable_cancel(hc_handle); |
327 | if (NULL != op) | 325 | if (NULL != op) |
328 | { | 326 | { |
329 | GNUNET_TESTBED_operation_done (op); | 327 | GNUNET_TESTBED_operation_done(op); |
330 | op = NULL; | 328 | op = NULL; |
331 | } | 329 | } |
332 | if (NULL != mc) | 330 | if (NULL != mc) |
333 | GNUNET_TESTBED_controller_disconnect (mc); | 331 | GNUNET_TESTBED_controller_disconnect(mc); |
334 | if (NULL != cp) | 332 | if (NULL != cp) |
335 | GNUNET_TESTBED_controller_stop (cp); | 333 | GNUNET_TESTBED_controller_stop(cp); |
336 | if (NULL != slave3) | 334 | if (NULL != slave3) |
337 | GNUNET_TESTBED_host_destroy (slave3); | 335 | GNUNET_TESTBED_host_destroy(slave3); |
338 | if (NULL != slave2) | 336 | if (NULL != slave2) |
339 | GNUNET_TESTBED_host_destroy (slave2); | 337 | GNUNET_TESTBED_host_destroy(slave2); |
340 | if (NULL != slave) | 338 | if (NULL != slave) |
341 | GNUNET_TESTBED_host_destroy (slave); | 339 | GNUNET_TESTBED_host_destroy(slave); |
342 | if (NULL != host) | 340 | if (NULL != host) |
343 | GNUNET_TESTBED_host_destroy (host); | 341 | GNUNET_TESTBED_host_destroy(host); |
344 | if (NULL != cfg) | 342 | if (NULL != cfg) |
345 | GNUNET_CONFIGURATION_destroy (cfg); | 343 | GNUNET_CONFIGURATION_destroy(cfg); |
346 | if (NULL != cfg3) | 344 | if (NULL != cfg3) |
347 | GNUNET_CONFIGURATION_destroy (cfg3); | 345 | GNUNET_CONFIGURATION_destroy(cfg3); |
348 | if (NULL != rh) | 346 | if (NULL != rh) |
349 | GNUNET_TESTBED_cancel_registration (rh); | 347 | GNUNET_TESTBED_cancel_registration(rh); |
350 | } | 348 | } |
351 | 349 | ||
352 | 350 | ||
@@ -356,11 +354,11 @@ do_shutdown (void *cls) | |||
356 | * @param cls NULL | 354 | * @param cls NULL |
357 | */ | 355 | */ |
358 | static void | 356 | static void |
359 | do_abort (void *cls) | 357 | do_abort(void *cls) |
360 | { | 358 | { |
361 | LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting in stage %d\n", result); | 359 | LOG(GNUNET_ERROR_TYPE_WARNING, "Aborting in stage %d\n", result); |
362 | abort_task = NULL; | 360 | abort_task = NULL; |
363 | GNUNET_SCHEDULER_shutdown (); | 361 | GNUNET_SCHEDULER_shutdown(); |
364 | } | 362 | } |
365 | 363 | ||
366 | 364 | ||
@@ -371,11 +369,11 @@ do_abort (void *cls) | |||
371 | * @return | 369 | * @return |
372 | */ | 370 | */ |
373 | static void | 371 | static void |
374 | do_abort_now (void *cls) | 372 | do_abort_now(void *cls) |
375 | { | 373 | { |
376 | if (NULL != abort_task) | 374 | if (NULL != abort_task) |
377 | GNUNET_SCHEDULER_cancel (abort_task); | 375 | GNUNET_SCHEDULER_cancel(abort_task); |
378 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); | 376 | abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); |
379 | } | 377 | } |
380 | 378 | ||
381 | 379 | ||
@@ -386,7 +384,7 @@ do_abort_now (void *cls) | |||
386 | * @param emsg the error message; NULL if host registration is successful | 384 | * @param emsg the error message; NULL if host registration is successful |
387 | */ | 385 | */ |
388 | static void | 386 | static void |
389 | registration_cont (void *cls, const char *emsg); | 387 | registration_cont(void *cls, const char *emsg); |
390 | 388 | ||
391 | 389 | ||
392 | /** | 390 | /** |
@@ -396,26 +394,29 @@ registration_cont (void *cls, const char *emsg); | |||
396 | * @return | 394 | * @return |
397 | */ | 395 | */ |
398 | static void | 396 | static void |
399 | delay_task (void *cls) | 397 | delay_task(void *cls) |
400 | { | 398 | { |
401 | delay_task_id = NULL; | 399 | delay_task_id = NULL; |
402 | switch (result) | 400 | switch (result) |
403 | { | 401 | { |
404 | case SLAVE2_PEER_CREATE_SUCCESS: | 402 | case SLAVE2_PEER_CREATE_SUCCESS: |
405 | op = GNUNET_TESTBED_peer_stop (NULL, slave1_peer, NULL, NULL); | 403 | op = GNUNET_TESTBED_peer_stop(NULL, slave1_peer, NULL, NULL); |
406 | FAIL_TEST (NULL != op); | 404 | FAIL_TEST(NULL != op); |
407 | break; | 405 | break; |
408 | case MASTER_SLAVE2_PEERS_CONNECTED: | 406 | |
409 | slave3 = GNUNET_TESTBED_host_create_with_id (3, "127.0.0.1", NULL, cfg, 0); | 407 | case MASTER_SLAVE2_PEERS_CONNECTED: |
410 | rh = GNUNET_TESTBED_register_host (mc, slave3, ®istration_cont, NULL); | 408 | slave3 = GNUNET_TESTBED_host_create_with_id(3, "127.0.0.1", NULL, cfg, 0); |
411 | break; | 409 | rh = GNUNET_TESTBED_register_host(mc, slave3, ®istration_cont, NULL); |
412 | case SLAVE2_SLAVE3_PEERS_CONNECTED: | 410 | break; |
413 | op = GNUNET_TESTBED_peer_stop (NULL, slave2_peer, NULL, NULL); | 411 | |
414 | FAIL_TEST (NULL != op); | 412 | case SLAVE2_SLAVE3_PEERS_CONNECTED: |
415 | break; | 413 | op = GNUNET_TESTBED_peer_stop(NULL, slave2_peer, NULL, NULL); |
416 | default: | 414 | FAIL_TEST(NULL != op); |
417 | FAIL_TEST (0); | 415 | break; |
418 | } | 416 | |
417 | default: | ||
418 | FAIL_TEST(0); | ||
419 | } | ||
419 | } | 420 | } |
420 | 421 | ||
421 | 422 | ||
@@ -429,44 +430,48 @@ delay_task (void *cls) | |||
429 | * @param emsg NULL if peer is not NULL; else MAY contain the error description | 430 | * @param emsg NULL if peer is not NULL; else MAY contain the error description |
430 | */ | 431 | */ |
431 | static void | 432 | static void |
432 | peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | 433 | peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) |
433 | { | 434 | { |
434 | FAIL_TEST (NULL != peer); | 435 | FAIL_TEST(NULL != peer); |
435 | FAIL_TEST (NULL == emsg); | 436 | FAIL_TEST(NULL == emsg); |
436 | switch (result) | 437 | switch (result) |
437 | { | 438 | { |
438 | case MASTER_STARTED: | 439 | case MASTER_STARTED: |
439 | result = MASTER_PEER_CREATE_SUCCESS; | 440 | result = MASTER_PEER_CREATE_SUCCESS; |
440 | master_peer = peer; | 441 | master_peer = peer; |
441 | GNUNET_TESTBED_operation_done (op); | 442 | GNUNET_TESTBED_operation_done(op); |
442 | op = GNUNET_TESTBED_peer_start (NULL, master_peer, NULL, NULL); | 443 | op = GNUNET_TESTBED_peer_start(NULL, master_peer, NULL, NULL); |
443 | break; | 444 | break; |
444 | case SLAVE1_LINK_SUCCESS: | 445 | |
445 | result = SLAVE1_PEER_CREATE_SUCCESS; | 446 | case SLAVE1_LINK_SUCCESS: |
446 | slave1_peer = peer; | 447 | result = SLAVE1_PEER_CREATE_SUCCESS; |
447 | GNUNET_TESTBED_operation_done (op); | 448 | slave1_peer = peer; |
448 | op = GNUNET_TESTBED_peer_start (NULL, slave1_peer, NULL, NULL); | 449 | GNUNET_TESTBED_operation_done(op); |
449 | break; | 450 | op = GNUNET_TESTBED_peer_start(NULL, slave1_peer, NULL, NULL); |
450 | case SLAVE2_LINK_SUCCESS: | 451 | break; |
451 | result = SLAVE2_PEER_CREATE_SUCCESS; | 452 | |
452 | slave2_peer = peer; | 453 | case SLAVE2_LINK_SUCCESS: |
453 | GNUNET_TESTBED_operation_done (op); | 454 | result = SLAVE2_PEER_CREATE_SUCCESS; |
454 | op = NULL; | 455 | slave2_peer = peer; |
455 | delay_task_id = GNUNET_SCHEDULER_add_delayed ( | 456 | GNUNET_TESTBED_operation_done(op); |
456 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), | 457 | op = NULL; |
457 | &delay_task, | 458 | delay_task_id = GNUNET_SCHEDULER_add_delayed( |
458 | NULL); | 459 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), |
459 | return; | 460 | &delay_task, |
460 | case SLAVE3_STARTED: | 461 | NULL); |
461 | result = SLAVE3_PEER_CREATE_SUCCESS; | 462 | return; |
462 | slave3_peer = peer; | 463 | |
463 | GNUNET_TESTBED_operation_done (op); | 464 | case SLAVE3_STARTED: |
464 | op = GNUNET_TESTBED_peer_start (NULL, slave3_peer, NULL, NULL); | 465 | result = SLAVE3_PEER_CREATE_SUCCESS; |
465 | break; | 466 | slave3_peer = peer; |
466 | default: | 467 | GNUNET_TESTBED_operation_done(op); |
467 | FAIL_TEST (0); | 468 | op = GNUNET_TESTBED_peer_start(NULL, slave3_peer, NULL, NULL); |
468 | } | 469 | break; |
469 | FAIL_TEST (NULL != op); | 470 | |
471 | default: | ||
472 | FAIL_TEST(0); | ||
473 | } | ||
474 | FAIL_TEST(NULL != op); | ||
470 | } | 475 | } |
471 | 476 | ||
472 | 477 | ||
@@ -477,14 +482,14 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | |||
477 | * @param event the event information to check | 482 | * @param event the event information to check |
478 | */ | 483 | */ |
479 | static void | 484 | static void |
480 | check_operation_success (const struct GNUNET_TESTBED_EventInformation *event) | 485 | check_operation_success(const struct GNUNET_TESTBED_EventInformation *event) |
481 | { | 486 | { |
482 | FAIL_TEST (NULL != event); | 487 | FAIL_TEST(NULL != event); |
483 | FAIL_TEST (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); | 488 | FAIL_TEST(GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); |
484 | FAIL_TEST (event->op == op); | 489 | FAIL_TEST(event->op == op); |
485 | FAIL_TEST (NULL == event->op_cls); | 490 | FAIL_TEST(NULL == event->op_cls); |
486 | FAIL_TEST (NULL == event->details.operation_finished.emsg); | 491 | FAIL_TEST(NULL == event->details.operation_finished.emsg); |
487 | FAIL_TEST (NULL == event->details.operation_finished.generic); | 492 | FAIL_TEST(NULL == event->details.operation_finished.generic); |
488 | } | 493 | } |
489 | 494 | ||
490 | 495 | ||
@@ -496,163 +501,180 @@ check_operation_success (const struct GNUNET_TESTBED_EventInformation *event) | |||
496 | * @param event information about the event | 501 | * @param event information about the event |
497 | */ | 502 | */ |
498 | static void | 503 | static void |
499 | controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | 504 | controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) |
500 | { | 505 | { |
501 | switch (result) | 506 | switch (result) |
502 | { | 507 | { |
503 | case SLAVE2_REGISTERED: | 508 | case SLAVE2_REGISTERED: |
504 | check_operation_success (event); | 509 | check_operation_success(event); |
505 | GNUNET_TESTBED_operation_done (op); | 510 | GNUNET_TESTBED_operation_done(op); |
506 | op = NULL; | 511 | op = NULL; |
507 | result = SLAVE1_LINK_SUCCESS; | 512 | result = SLAVE1_LINK_SUCCESS; |
508 | FAIL_TEST (NULL != slave2); | 513 | FAIL_TEST(NULL != slave2); |
509 | FAIL_TEST (NULL != slave); | 514 | FAIL_TEST(NULL != slave); |
510 | op = GNUNET_TESTBED_peer_create (mc, slave, cfg, peer_create_cb, NULL); | 515 | op = GNUNET_TESTBED_peer_create(mc, slave, cfg, peer_create_cb, NULL); |
511 | FAIL_TEST (NULL != op); | 516 | FAIL_TEST(NULL != op); |
512 | break; | 517 | break; |
513 | case SLAVE1_PEER_START_SUCCESS: | 518 | |
514 | check_operation_success (event); | 519 | case SLAVE1_PEER_START_SUCCESS: |
515 | GNUNET_TESTBED_operation_done (op); | 520 | check_operation_success(event); |
516 | result = SLAVE2_LINK_SUCCESS; | 521 | GNUNET_TESTBED_operation_done(op); |
517 | op = GNUNET_TESTBED_peer_create (mc, slave2, cfg, peer_create_cb, NULL); | 522 | result = SLAVE2_LINK_SUCCESS; |
518 | FAIL_TEST (NULL != op); | 523 | op = GNUNET_TESTBED_peer_create(mc, slave2, cfg, peer_create_cb, NULL); |
519 | break; | 524 | FAIL_TEST(NULL != op); |
520 | case MASTER_PEER_CREATE_SUCCESS: | 525 | break; |
521 | FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); | 526 | |
522 | FAIL_TEST (event->details.peer_start.host == host); | 527 | case MASTER_PEER_CREATE_SUCCESS: |
523 | FAIL_TEST (event->details.peer_start.peer == master_peer); | 528 | FAIL_TEST(GNUNET_TESTBED_ET_PEER_START == event->type); |
524 | GNUNET_TESTBED_operation_done (op); | 529 | FAIL_TEST(event->details.peer_start.host == host); |
525 | op = NULL; | 530 | FAIL_TEST(event->details.peer_start.peer == master_peer); |
526 | result = MASTER_PEER_START_SUCCESS; | 531 | GNUNET_TESTBED_operation_done(op); |
527 | slave = GNUNET_TESTBED_host_create_with_id (1, "127.0.0.1", NULL, cfg, 0); | 532 | op = NULL; |
528 | FAIL_TEST (NULL != slave); | 533 | result = MASTER_PEER_START_SUCCESS; |
529 | rh = GNUNET_TESTBED_register_host (mc, slave, ®istration_cont, NULL); | 534 | slave = GNUNET_TESTBED_host_create_with_id(1, "127.0.0.1", NULL, cfg, 0); |
530 | FAIL_TEST (NULL != rh); | 535 | FAIL_TEST(NULL != slave); |
531 | break; | 536 | rh = GNUNET_TESTBED_register_host(mc, slave, ®istration_cont, NULL); |
532 | case SLAVE1_PEER_CREATE_SUCCESS: | 537 | FAIL_TEST(NULL != rh); |
533 | FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); | 538 | break; |
534 | FAIL_TEST (event->details.peer_start.host == slave); | 539 | |
535 | FAIL_TEST (event->details.peer_start.peer == slave1_peer); | 540 | case SLAVE1_PEER_CREATE_SUCCESS: |
536 | GNUNET_TESTBED_operation_done (op); | 541 | FAIL_TEST(GNUNET_TESTBED_ET_PEER_START == event->type); |
537 | result = SLAVE1_PEER_START_SUCCESS; | 542 | FAIL_TEST(event->details.peer_start.host == slave); |
538 | op = GNUNET_TESTBED_controller_link (NULL, mc, slave2, slave, GNUNET_YES); | 543 | FAIL_TEST(event->details.peer_start.peer == slave1_peer); |
539 | break; | 544 | GNUNET_TESTBED_operation_done(op); |
540 | case SLAVE2_PEER_CREATE_SUCCESS: | 545 | result = SLAVE1_PEER_START_SUCCESS; |
541 | FAIL_TEST (GNUNET_TESTBED_ET_PEER_STOP == event->type); | 546 | op = GNUNET_TESTBED_controller_link(NULL, mc, slave2, slave, GNUNET_YES); |
542 | FAIL_TEST (event->details.peer_stop.peer == slave1_peer); | 547 | break; |
543 | GNUNET_TESTBED_operation_done (op); | 548 | |
544 | result = SLAVE1_PEER_STOP_SUCCESS; | 549 | case SLAVE2_PEER_CREATE_SUCCESS: |
545 | op = GNUNET_TESTBED_peer_start (NULL, slave2_peer, NULL, NULL); | 550 | FAIL_TEST(GNUNET_TESTBED_ET_PEER_STOP == event->type); |
546 | FAIL_TEST (NULL != op); | 551 | FAIL_TEST(event->details.peer_stop.peer == slave1_peer); |
547 | break; | 552 | GNUNET_TESTBED_operation_done(op); |
548 | case SLAVE3_PEER_CREATE_SUCCESS: | 553 | result = SLAVE1_PEER_STOP_SUCCESS; |
549 | FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); | 554 | op = GNUNET_TESTBED_peer_start(NULL, slave2_peer, NULL, NULL); |
550 | FAIL_TEST (event->details.peer_start.host == slave3); | 555 | FAIL_TEST(NULL != op); |
551 | FAIL_TEST (event->details.peer_start.peer == slave3_peer); | 556 | break; |
552 | GNUNET_TESTBED_operation_done (op); | 557 | |
553 | result = SLAVE3_PEER_START_SUCCESS; | 558 | case SLAVE3_PEER_CREATE_SUCCESS: |
554 | sleep (1); | 559 | FAIL_TEST(GNUNET_TESTBED_ET_PEER_START == event->type); |
555 | LOG_DEBUG ("**************************************\n"); | 560 | FAIL_TEST(event->details.peer_start.host == slave3); |
556 | op = | 561 | FAIL_TEST(event->details.peer_start.peer == slave3_peer); |
557 | GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, slave2_peer, slave3_peer); | 562 | GNUNET_TESTBED_operation_done(op); |
558 | FAIL_TEST (NULL != op); | 563 | result = SLAVE3_PEER_START_SUCCESS; |
559 | break; | 564 | sleep(1); |
560 | case SLAVE3_PEER_START_SUCCESS: | 565 | LOG_DEBUG("**************************************\n"); |
561 | FAIL_TEST (NULL != event); | 566 | op = |
562 | FAIL_TEST (GNUNET_TESTBED_ET_CONNECT == event->type); | 567 | GNUNET_TESTBED_overlay_connect(mc, NULL, NULL, slave2_peer, slave3_peer); |
563 | FAIL_TEST (event->details.peer_connect.peer1 == slave2_peer); | 568 | FAIL_TEST(NULL != op); |
564 | FAIL_TEST (event->details.peer_connect.peer2 == slave3_peer); | 569 | break; |
565 | result = SLAVE2_SLAVE3_PEERS_CONNECTED; | 570 | |
566 | GNUNET_TESTBED_operation_done (op); | 571 | case SLAVE3_PEER_START_SUCCESS: |
567 | op = NULL; | 572 | FAIL_TEST(NULL != event); |
568 | delay_task_id = GNUNET_SCHEDULER_add_delayed ( | 573 | FAIL_TEST(GNUNET_TESTBED_ET_CONNECT == event->type); |
569 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), | 574 | FAIL_TEST(event->details.peer_connect.peer1 == slave2_peer); |
570 | &delay_task, | 575 | FAIL_TEST(event->details.peer_connect.peer2 == slave3_peer); |
571 | NULL); | 576 | result = SLAVE2_SLAVE3_PEERS_CONNECTED; |
572 | break; | 577 | GNUNET_TESTBED_operation_done(op); |
573 | case SLAVE1_PEER_STOP_SUCCESS: | 578 | op = NULL; |
574 | FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type); | 579 | delay_task_id = GNUNET_SCHEDULER_add_delayed( |
575 | FAIL_TEST (event->details.peer_start.host == slave2); | 580 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), |
576 | FAIL_TEST (event->details.peer_start.peer == slave2_peer); | 581 | &delay_task, |
577 | GNUNET_TESTBED_operation_done (op); | 582 | NULL); |
578 | result = SLAVE2_PEER_START_SUCCESS; | 583 | break; |
579 | op = | 584 | |
580 | GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, master_peer, slave2_peer); | 585 | case SLAVE1_PEER_STOP_SUCCESS: |
581 | break; | 586 | FAIL_TEST(GNUNET_TESTBED_ET_PEER_START == event->type); |
582 | case SLAVE2_PEER_START_SUCCESS: | 587 | FAIL_TEST(event->details.peer_start.host == slave2); |
583 | FAIL_TEST (NULL != event); | 588 | FAIL_TEST(event->details.peer_start.peer == slave2_peer); |
584 | FAIL_TEST (GNUNET_TESTBED_ET_CONNECT == event->type); | 589 | GNUNET_TESTBED_operation_done(op); |
585 | FAIL_TEST (event->details.peer_connect.peer1 == master_peer); | 590 | result = SLAVE2_PEER_START_SUCCESS; |
586 | FAIL_TEST (event->details.peer_connect.peer2 == slave2_peer); | 591 | op = |
587 | result = MASTER_SLAVE2_PEERS_CONNECTED; | 592 | GNUNET_TESTBED_overlay_connect(mc, NULL, NULL, master_peer, slave2_peer); |
588 | GNUNET_TESTBED_operation_done (op); | 593 | break; |
589 | op = NULL; | 594 | |
590 | delay_task_id = GNUNET_SCHEDULER_add_delayed ( | 595 | case SLAVE2_PEER_START_SUCCESS: |
591 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), | 596 | FAIL_TEST(NULL != event); |
592 | &delay_task, | 597 | FAIL_TEST(GNUNET_TESTBED_ET_CONNECT == event->type); |
593 | NULL); | 598 | FAIL_TEST(event->details.peer_connect.peer1 == master_peer); |
594 | break; | 599 | FAIL_TEST(event->details.peer_connect.peer2 == slave2_peer); |
595 | case SLAVE2_SLAVE3_PEERS_CONNECTED: | 600 | result = MASTER_SLAVE2_PEERS_CONNECTED; |
596 | FAIL_TEST (GNUNET_TESTBED_ET_PEER_STOP == event->type); | 601 | GNUNET_TESTBED_operation_done(op); |
597 | FAIL_TEST (event->details.peer_stop.peer == slave2_peer); | 602 | op = NULL; |
598 | GNUNET_TESTBED_operation_done (op); | 603 | delay_task_id = GNUNET_SCHEDULER_add_delayed( |
599 | result = SLAVE2_PEER_STOP_SUCCESS; | 604 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), |
600 | op = GNUNET_TESTBED_peer_destroy (slave1_peer); | 605 | &delay_task, |
601 | FAIL_TEST (NULL != op); | 606 | NULL); |
602 | break; | 607 | break; |
603 | case SLAVE2_PEER_STOP_SUCCESS: | 608 | |
604 | check_operation_success (event); | 609 | case SLAVE2_SLAVE3_PEERS_CONNECTED: |
605 | GNUNET_TESTBED_operation_done (op); | 610 | FAIL_TEST(GNUNET_TESTBED_ET_PEER_STOP == event->type); |
606 | result = SLAVE1_PEER_DESTROY_SUCCESS; | 611 | FAIL_TEST(event->details.peer_stop.peer == slave2_peer); |
607 | op = GNUNET_TESTBED_peer_destroy (slave2_peer); | 612 | GNUNET_TESTBED_operation_done(op); |
608 | FAIL_TEST (NULL != op); | 613 | result = SLAVE2_PEER_STOP_SUCCESS; |
609 | break; | 614 | op = GNUNET_TESTBED_peer_destroy(slave1_peer); |
610 | case SLAVE1_PEER_DESTROY_SUCCESS: | 615 | FAIL_TEST(NULL != op); |
611 | check_operation_success (event); | 616 | break; |
612 | GNUNET_TESTBED_operation_done (op); | 617 | |
613 | op = NULL; | 618 | case SLAVE2_PEER_STOP_SUCCESS: |
614 | result = SLAVE2_PEER_DESTROY_SUCCESS; | 619 | check_operation_success(event); |
615 | op = GNUNET_TESTBED_get_slave_config (NULL, mc, slave3); | 620 | GNUNET_TESTBED_operation_done(op); |
616 | FAIL_TEST (NULL != op); | 621 | result = SLAVE1_PEER_DESTROY_SUCCESS; |
617 | break; | 622 | op = GNUNET_TESTBED_peer_destroy(slave2_peer); |
618 | case SLAVE2_PEER_DESTROY_SUCCESS: | 623 | FAIL_TEST(NULL != op); |
619 | FAIL_TEST (NULL != event); | 624 | break; |
620 | FAIL_TEST (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); | 625 | |
621 | FAIL_TEST (event->op == op); | 626 | case SLAVE1_PEER_DESTROY_SUCCESS: |
622 | FAIL_TEST (NULL == event->op_cls); | 627 | check_operation_success(event); |
623 | FAIL_TEST (NULL == event->details.operation_finished.emsg); | 628 | GNUNET_TESTBED_operation_done(op); |
624 | cfg3 = GNUNET_CONFIGURATION_dup (event->details.operation_finished.generic); | 629 | op = NULL; |
625 | GNUNET_TESTBED_operation_done (op); | 630 | result = SLAVE2_PEER_DESTROY_SUCCESS; |
626 | result = SLAVE3_GET_CONFIG_SUCCESS; | 631 | op = GNUNET_TESTBED_get_slave_config(NULL, mc, slave3); |
627 | op = GNUNET_TESTBED_controller_link (NULL, mc, slave3, slave, GNUNET_NO); | 632 | FAIL_TEST(NULL != op); |
628 | break; | 633 | break; |
629 | case SLAVE3_REGISTERED: | 634 | |
630 | check_operation_success (event); | 635 | case SLAVE2_PEER_DESTROY_SUCCESS: |
631 | GNUNET_TESTBED_operation_done (op); | 636 | FAIL_TEST(NULL != event); |
632 | result = SLAVE3_STARTED; | 637 | FAIL_TEST(GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); |
633 | op = GNUNET_TESTBED_peer_create (mc, slave3, cfg, peer_create_cb, NULL); | 638 | FAIL_TEST(event->op == op); |
634 | FAIL_TEST (NULL != op); | 639 | FAIL_TEST(NULL == event->op_cls); |
635 | break; | 640 | FAIL_TEST(NULL == event->details.operation_finished.emsg); |
636 | case SLAVE3_GET_CONFIG_SUCCESS: | 641 | cfg3 = GNUNET_CONFIGURATION_dup(event->details.operation_finished.generic); |
637 | result = SLAVE3_LINK_SUCCESS; | 642 | GNUNET_TESTBED_operation_done(op); |
638 | GNUNET_TESTBED_operation_done (op); | 643 | result = SLAVE3_GET_CONFIG_SUCCESS; |
639 | op = GNUNET_TESTBED_peer_destroy (master_peer); | 644 | op = GNUNET_TESTBED_controller_link(NULL, mc, slave3, slave, GNUNET_NO); |
640 | break; | 645 | break; |
641 | case SLAVE3_LINK_SUCCESS: | 646 | |
642 | check_operation_success (event); | 647 | case SLAVE3_REGISTERED: |
643 | result = MASTER_PEER_DESTROY_SUCCESS; | 648 | check_operation_success(event); |
644 | GNUNET_TESTBED_operation_done (op); | 649 | GNUNET_TESTBED_operation_done(op); |
645 | op = GNUNET_TESTBED_peer_destroy (slave3_peer); | 650 | result = SLAVE3_STARTED; |
646 | break; | 651 | op = GNUNET_TESTBED_peer_create(mc, slave3, cfg, peer_create_cb, NULL); |
647 | case MASTER_PEER_DESTROY_SUCCESS: | 652 | FAIL_TEST(NULL != op); |
648 | result = SUCCESS; | 653 | break; |
649 | GNUNET_TESTBED_operation_done (op); | 654 | |
650 | op = NULL; | 655 | case SLAVE3_GET_CONFIG_SUCCESS: |
651 | GNUNET_SCHEDULER_shutdown (); | 656 | result = SLAVE3_LINK_SUCCESS; |
652 | break; | 657 | GNUNET_TESTBED_operation_done(op); |
653 | default: | 658 | op = GNUNET_TESTBED_peer_destroy(master_peer); |
654 | FAIL_TEST (0); | 659 | break; |
655 | } | 660 | |
661 | case SLAVE3_LINK_SUCCESS: | ||
662 | check_operation_success(event); | ||
663 | result = MASTER_PEER_DESTROY_SUCCESS; | ||
664 | GNUNET_TESTBED_operation_done(op); | ||
665 | op = GNUNET_TESTBED_peer_destroy(slave3_peer); | ||
666 | break; | ||
667 | |||
668 | case MASTER_PEER_DESTROY_SUCCESS: | ||
669 | result = SUCCESS; | ||
670 | GNUNET_TESTBED_operation_done(op); | ||
671 | op = NULL; | ||
672 | GNUNET_SCHEDULER_shutdown(); | ||
673 | break; | ||
674 | |||
675 | default: | ||
676 | FAIL_TEST(0); | ||
677 | } | ||
656 | } | 678 | } |
657 | 679 | ||
658 | 680 | ||
@@ -663,40 +685,43 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
663 | * @param emsg the error message; NULL if host registration is successful | 685 | * @param emsg the error message; NULL if host registration is successful |
664 | */ | 686 | */ |
665 | static void | 687 | static void |
666 | registration_cont (void *cls, const char *emsg) | 688 | registration_cont(void *cls, const char *emsg) |
667 | { | 689 | { |
668 | rh = NULL; | 690 | rh = NULL; |
669 | switch (result) | 691 | switch (result) |
670 | { | 692 | { |
671 | case MASTER_PEER_START_SUCCESS: | 693 | case MASTER_PEER_START_SUCCESS: |
672 | FAIL_TEST (NULL == emsg); | 694 | FAIL_TEST(NULL == emsg); |
673 | FAIL_TEST (NULL != mc); | 695 | FAIL_TEST(NULL != mc); |
674 | result = SLAVE1_REGISTERED; | 696 | result = SLAVE1_REGISTERED; |
675 | slave2 = GNUNET_TESTBED_host_create_with_id (2, "127.0.0.1", NULL, cfg, 0); | 697 | slave2 = GNUNET_TESTBED_host_create_with_id(2, "127.0.0.1", NULL, cfg, 0); |
676 | FAIL_TEST (NULL != slave2); | 698 | FAIL_TEST(NULL != slave2); |
677 | rh = GNUNET_TESTBED_register_host (mc, slave2, ®istration_cont, NULL); | 699 | rh = GNUNET_TESTBED_register_host(mc, slave2, ®istration_cont, NULL); |
678 | FAIL_TEST (NULL != rh); | 700 | FAIL_TEST(NULL != rh); |
679 | break; | 701 | break; |
680 | case SLAVE1_REGISTERED: | 702 | |
681 | FAIL_TEST (NULL == emsg); | 703 | case SLAVE1_REGISTERED: |
682 | FAIL_TEST (NULL != mc); | 704 | FAIL_TEST(NULL == emsg); |
683 | result = SLAVE2_REGISTERED; | 705 | FAIL_TEST(NULL != mc); |
684 | FAIL_TEST (NULL != cfg); | 706 | result = SLAVE2_REGISTERED; |
685 | op = GNUNET_TESTBED_controller_link (NULL, mc, slave, NULL, GNUNET_YES); | 707 | FAIL_TEST(NULL != cfg); |
686 | FAIL_TEST (NULL != op); | 708 | op = GNUNET_TESTBED_controller_link(NULL, mc, slave, NULL, GNUNET_YES); |
687 | break; | 709 | FAIL_TEST(NULL != op); |
688 | case MASTER_SLAVE2_PEERS_CONNECTED: | 710 | break; |
689 | FAIL_TEST (NULL == emsg); | 711 | |
690 | FAIL_TEST (NULL != mc); | 712 | case MASTER_SLAVE2_PEERS_CONNECTED: |
691 | FAIL_TEST (NULL == op); | 713 | FAIL_TEST(NULL == emsg); |
692 | result = SLAVE3_REGISTERED; | 714 | FAIL_TEST(NULL != mc); |
693 | op = GNUNET_TESTBED_controller_link (NULL, mc, slave3, NULL, GNUNET_YES); | 715 | FAIL_TEST(NULL == op); |
694 | FAIL_TEST (NULL != op); | 716 | result = SLAVE3_REGISTERED; |
695 | break; | 717 | op = GNUNET_TESTBED_controller_link(NULL, mc, slave3, NULL, GNUNET_YES); |
696 | default: | 718 | FAIL_TEST(NULL != op); |
697 | GNUNET_break (0); | 719 | break; |
698 | do_abort_now (NULL); | 720 | |
699 | } | 721 | default: |
722 | GNUNET_break(0); | ||
723 | do_abort_now(NULL); | ||
724 | } | ||
700 | } | 725 | } |
701 | 726 | ||
702 | /** | 727 | /** |
@@ -709,33 +734,34 @@ registration_cont (void *cls, const char *emsg) | |||
709 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case | 734 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case |
710 | */ | 735 | */ |
711 | static void | 736 | static void |
712 | status_cb (void *cls, | 737 | status_cb(void *cls, |
713 | const struct GNUNET_CONFIGURATION_Handle *config, | 738 | const struct GNUNET_CONFIGURATION_Handle *config, |
714 | int status) | 739 | int status) |
715 | { | 740 | { |
716 | switch (result) | 741 | switch (result) |
717 | { | 742 | { |
718 | case INIT: | 743 | case INIT: |
719 | FAIL_TEST (GNUNET_OK == status); | 744 | FAIL_TEST(GNUNET_OK == status); |
720 | event_mask = 0; | 745 | event_mask = 0; |
721 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); | 746 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); |
722 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); | 747 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); |
723 | event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); | 748 | event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); |
724 | event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 749 | event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
725 | mc = GNUNET_TESTBED_controller_connect (host, | 750 | mc = GNUNET_TESTBED_controller_connect(host, |
726 | event_mask, | 751 | event_mask, |
727 | &controller_cb, | 752 | &controller_cb, |
728 | NULL); | 753 | NULL); |
729 | FAIL_TEST (NULL != mc); | 754 | FAIL_TEST(NULL != mc); |
730 | result = MASTER_STARTED; | 755 | result = MASTER_STARTED; |
731 | op = GNUNET_TESTBED_peer_create (mc, host, cfg, peer_create_cb, NULL); | 756 | op = GNUNET_TESTBED_peer_create(mc, host, cfg, peer_create_cb, NULL); |
732 | FAIL_TEST (NULL != op); | 757 | FAIL_TEST(NULL != op); |
733 | break; | 758 | break; |
734 | default: | 759 | |
735 | GNUNET_break (0); | 760 | default: |
736 | cp = NULL; | 761 | GNUNET_break(0); |
737 | do_abort_now (NULL); | 762 | cp = NULL; |
738 | } | 763 | do_abort_now(NULL); |
764 | } | ||
739 | } | 765 | } |
740 | 766 | ||
741 | 767 | ||
@@ -750,24 +776,24 @@ status_cb (void *cls, | |||
750 | * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not | 776 | * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not |
751 | */ | 777 | */ |
752 | static void | 778 | static void |
753 | host_habitable_cb (void *cls, | 779 | host_habitable_cb(void *cls, |
754 | const struct GNUNET_TESTBED_Host *_host, | 780 | const struct GNUNET_TESTBED_Host *_host, |
755 | int status) | 781 | int status) |
756 | { | 782 | { |
757 | hc_handle = NULL; | 783 | hc_handle = NULL; |
758 | if (GNUNET_NO == status) | 784 | if (GNUNET_NO == status) |
759 | { | 785 | { |
760 | (void) printf ("%s", | 786 | (void)printf("%s", |
761 | "Unable to run the test as this system is not configured " | 787 | "Unable to run the test as this system is not configured " |
762 | "to use password less SSH logins to localhost.\n" | 788 | "to use password less SSH logins to localhost.\n" |
763 | "Skipping test\n"); | 789 | "Skipping test\n"); |
764 | GNUNET_SCHEDULER_cancel (abort_task); | 790 | GNUNET_SCHEDULER_cancel(abort_task); |
765 | abort_task = NULL; | 791 | abort_task = NULL; |
766 | GNUNET_SCHEDULER_shutdown (); | 792 | GNUNET_SCHEDULER_shutdown(); |
767 | result = SKIP; | 793 | result = SKIP; |
768 | return; | 794 | return; |
769 | } | 795 | } |
770 | cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb, NULL); | 796 | cp = GNUNET_TESTBED_controller_start("127.0.0.1", host, status_cb, NULL); |
771 | } | 797 | } |
772 | 798 | ||
773 | 799 | ||
@@ -780,35 +806,35 @@ host_habitable_cb (void *cls, | |||
780 | * @param cfg the configuration file handle | 806 | * @param cfg the configuration file handle |
781 | */ | 807 | */ |
782 | static void | 808 | static void |
783 | run (void *cls, | 809 | run(void *cls, |
784 | char *const *args, | 810 | char *const *args, |
785 | const char *cfgfile, | 811 | const char *cfgfile, |
786 | const struct GNUNET_CONFIGURATION_Handle *config) | 812 | const struct GNUNET_CONFIGURATION_Handle *config) |
787 | { | 813 | { |
788 | cfg = GNUNET_CONFIGURATION_dup (config); | 814 | cfg = GNUNET_CONFIGURATION_dup(config); |
789 | host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0); | 815 | host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0); |
790 | FAIL_TEST (NULL != host); | 816 | FAIL_TEST(NULL != host); |
791 | if (NULL == (hc_handle = GNUNET_TESTBED_is_host_habitable (host, | 817 | if (NULL == (hc_handle = GNUNET_TESTBED_is_host_habitable(host, |
792 | config, | 818 | config, |
793 | &host_habitable_cb, | 819 | &host_habitable_cb, |
794 | NULL))) | 820 | NULL))) |
795 | { | 821 | { |
796 | GNUNET_TESTBED_host_destroy (host); | 822 | GNUNET_TESTBED_host_destroy(host); |
797 | GNUNET_CONFIGURATION_destroy (cfg); | 823 | GNUNET_CONFIGURATION_destroy(cfg); |
798 | cfg = NULL; | 824 | cfg = NULL; |
799 | host = NULL; | 825 | host = NULL; |
800 | (void) printf ("%s", | 826 | (void)printf("%s", |
801 | "Unable to run the test as this system is not configured " | 827 | "Unable to run the test as this system is not configured " |
802 | "to use password less SSH logins to localhost.\n" | 828 | "to use password less SSH logins to localhost.\n" |
803 | "Marking test as successful\n"); | 829 | "Marking test as successful\n"); |
804 | result = SKIP; | 830 | result = SKIP; |
805 | return; | 831 | return; |
806 | } | 832 | } |
807 | abort_task = GNUNET_SCHEDULER_add_delayed ( | 833 | abort_task = GNUNET_SCHEDULER_add_delayed( |
808 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5), | 834 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), |
809 | &do_abort, | 835 | &do_abort, |
810 | NULL); | 836 | NULL); |
811 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 837 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
812 | } | 838 | } |
813 | 839 | ||
814 | 840 | ||
@@ -816,34 +842,36 @@ run (void *cls, | |||
816 | * Main function | 842 | * Main function |
817 | */ | 843 | */ |
818 | int | 844 | int |
819 | main (int argc, char **argv) | 845 | main(int argc, char **argv) |
820 | { | 846 | { |
821 | char *const argv2[] = {"test_testbed_api_controllerlink", | 847 | char *const argv2[] = { "test_testbed_api_controllerlink", |
822 | "-c", | 848 | "-c", |
823 | "test_testbed_api.conf", | 849 | "test_testbed_api.conf", |
824 | NULL}; | 850 | NULL }; |
825 | struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END}; | 851 | struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; |
826 | int ret; | 852 | int ret; |
827 | 853 | ||
828 | result = INIT; | 854 | result = INIT; |
829 | ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, | 855 | ret = GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, |
830 | argv2, | 856 | argv2, |
831 | "test_testbed_api_controllerlink", | 857 | "test_testbed_api_controllerlink", |
832 | "nohelp", | 858 | "nohelp", |
833 | options, | 859 | options, |
834 | &run, | 860 | &run, |
835 | NULL); | 861 | NULL); |
836 | if (GNUNET_OK != ret) | 862 | if (GNUNET_OK != ret) |
837 | return 1; | 863 | return 1; |
838 | switch (result) | 864 | switch (result) |
839 | { | 865 | { |
840 | case SUCCESS: | 866 | case SUCCESS: |
841 | return 0; | 867 | return 0; |
842 | case SKIP: | 868 | |
843 | return 77; /* Mark test as skipped */ | 869 | case SKIP: |
844 | default: | 870 | return 77; /* Mark test as skipped */ |
845 | return 1; | 871 | |
846 | } | 872 | default: |
873 | return 1; | ||
874 | } | ||
847 | } | 875 | } |
848 | 876 | ||
849 | /* end of test_testbed_api_controllerlink.c */ | 877 | /* end of test_testbed_api_controllerlink.c */ |
diff --git a/src/testbed/test_testbed_api_hosts.c b/src/testbed/test_testbed_api_hosts.c index c3f565949..f9656d17f 100644 --- a/src/testbed/test_testbed_api_hosts.c +++ b/src/testbed/test_testbed_api_hosts.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -30,8 +30,8 @@ | |||
30 | #include "testbed_api_hosts.h" | 30 | #include "testbed_api_hosts.h" |
31 | 31 | ||
32 | 32 | ||
33 | #define TIME_REL_SECS(sec) \ | 33 | #define TIME_REL_SECS(sec) \ |
34 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) | 34 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, sec) |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * configuration handle to use as template configuration while creating hosts | 37 | * configuration handle to use as template configuration while creating hosts |
@@ -65,20 +65,20 @@ static int status; | |||
65 | * @param cls NULL | 65 | * @param cls NULL |
66 | */ | 66 | */ |
67 | static void | 67 | static void |
68 | do_shutdown (void *cls) | 68 | do_shutdown(void *cls) |
69 | { | 69 | { |
70 | GNUNET_TESTBED_host_destroy (host); | 70 | GNUNET_TESTBED_host_destroy(host); |
71 | while (0 != num_hosts) | 71 | while (0 != num_hosts) |
72 | { | 72 | { |
73 | GNUNET_TESTBED_host_destroy (hosts[num_hosts - 1]); | 73 | GNUNET_TESTBED_host_destroy(hosts[num_hosts - 1]); |
74 | num_hosts--; | 74 | num_hosts--; |
75 | } | 75 | } |
76 | GNUNET_free (hosts); | 76 | GNUNET_free(hosts); |
77 | if (NULL != cfg) | 77 | if (NULL != cfg) |
78 | { | 78 | { |
79 | GNUNET_CONFIGURATION_destroy (cfg); | 79 | GNUNET_CONFIGURATION_destroy(cfg); |
80 | cfg = NULL; | 80 | cfg = NULL; |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | 84 | ||
@@ -91,90 +91,89 @@ do_shutdown (void *cls) | |||
91 | * @param cfg the configuration file handle | 91 | * @param cfg the configuration file handle |
92 | */ | 92 | */ |
93 | static void | 93 | static void |
94 | run (void *cls, char *const *args, const char *cfgfile, | 94 | run(void *cls, char *const *args, const char *cfgfile, |
95 | const struct GNUNET_CONFIGURATION_Handle *config) | 95 | const struct GNUNET_CONFIGURATION_Handle *config) |
96 | { | 96 | { |
97 | unsigned int cnt; | 97 | unsigned int cnt; |
98 | 98 | ||
99 | cfg = GNUNET_CONFIGURATION_dup (config); | 99 | cfg = GNUNET_CONFIGURATION_dup(config); |
100 | host = GNUNET_TESTBED_host_create ("localhost", NULL, cfg, 0); | 100 | host = GNUNET_TESTBED_host_create("localhost", NULL, cfg, 0); |
101 | GNUNET_assert (NULL != host); | 101 | GNUNET_assert(NULL != host); |
102 | GNUNET_assert (0 != GNUNET_TESTBED_host_get_id_ (host)); | 102 | GNUNET_assert(0 != GNUNET_TESTBED_host_get_id_(host)); |
103 | GNUNET_TESTBED_host_destroy (host); | 103 | GNUNET_TESTBED_host_destroy(host); |
104 | host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0); | 104 | host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0); |
105 | GNUNET_assert (NULL != host); | 105 | GNUNET_assert(NULL != host); |
106 | GNUNET_assert (0 == GNUNET_TESTBED_host_get_id_ (host)); | 106 | GNUNET_assert(0 == GNUNET_TESTBED_host_get_id_(host)); |
107 | GNUNET_assert (host == GNUNET_TESTBED_host_lookup_by_id_ (0)); | 107 | GNUNET_assert(host == GNUNET_TESTBED_host_lookup_by_id_(0)); |
108 | hosts = NULL; | 108 | hosts = NULL; |
109 | num_hosts = GNUNET_TESTBED_hosts_load_from_file ("sample_hosts.txt", cfg, &hosts); | 109 | num_hosts = GNUNET_TESTBED_hosts_load_from_file("sample_hosts.txt", cfg, &hosts); |
110 | GNUNET_assert (7 == num_hosts); | 110 | GNUNET_assert(7 == num_hosts); |
111 | GNUNET_assert (NULL != hosts); | 111 | GNUNET_assert(NULL != hosts); |
112 | for (cnt = 0; cnt < num_hosts; cnt++) | 112 | for (cnt = 0; cnt < num_hosts; cnt++) |
113 | { | ||
114 | if (cnt < 3) | ||
115 | { | ||
116 | GNUNET_assert (0 == strcmp ("totakura", | ||
117 | GNUNET_TESTBED_host_get_username_ | ||
118 | (hosts[cnt]))); | ||
119 | GNUNET_assert (NULL != GNUNET_TESTBED_host_get_hostname (hosts[cnt])); | ||
120 | GNUNET_assert (22 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt])); | ||
121 | } | ||
122 | if (3 == cnt) | ||
123 | { | 113 | { |
124 | GNUNET_assert (0 == strcmp ("totakura", | 114 | if (cnt < 3) |
125 | GNUNET_TESTBED_host_get_username_ | 115 | { |
126 | (hosts[cnt]))); | 116 | GNUNET_assert(0 == strcmp("totakura", |
127 | GNUNET_assert (NULL != GNUNET_TESTBED_host_get_hostname (hosts[cnt])); | 117 | GNUNET_TESTBED_host_get_username_ |
128 | GNUNET_assert (2022 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt])); | 118 | (hosts[cnt]))); |
119 | GNUNET_assert(NULL != GNUNET_TESTBED_host_get_hostname(hosts[cnt])); | ||
120 | GNUNET_assert(22 == GNUNET_TESTBED_host_get_ssh_port_(hosts[cnt])); | ||
121 | } | ||
122 | if (3 == cnt) | ||
123 | { | ||
124 | GNUNET_assert(0 == strcmp("totakura", | ||
125 | GNUNET_TESTBED_host_get_username_ | ||
126 | (hosts[cnt]))); | ||
127 | GNUNET_assert(NULL != GNUNET_TESTBED_host_get_hostname(hosts[cnt])); | ||
128 | GNUNET_assert(2022 == GNUNET_TESTBED_host_get_ssh_port_(hosts[cnt])); | ||
129 | } | ||
130 | if (4 == cnt) | ||
131 | { | ||
132 | GNUNET_assert(0 == strcmp("totakura", | ||
133 | GNUNET_TESTBED_host_get_username_ | ||
134 | (hosts[cnt]))); | ||
135 | GNUNET_assert(0 == strcmp("asgard.realm", | ||
136 | GNUNET_TESTBED_host_get_hostname | ||
137 | (hosts[cnt]))); | ||
138 | GNUNET_assert(22 == GNUNET_TESTBED_host_get_ssh_port_(hosts[cnt])); | ||
139 | } | ||
140 | if (5 == cnt) | ||
141 | { | ||
142 | GNUNET_assert(NULL == GNUNET_TESTBED_host_get_username_(hosts[cnt])); | ||
143 | GNUNET_assert(0 == strcmp("rivendal", | ||
144 | GNUNET_TESTBED_host_get_hostname | ||
145 | (hosts[cnt]))); | ||
146 | GNUNET_assert(22 == GNUNET_TESTBED_host_get_ssh_port_(hosts[cnt])); | ||
147 | } | ||
148 | if (6 == cnt) | ||
149 | { | ||
150 | GNUNET_assert(NULL == GNUNET_TESTBED_host_get_username_(hosts[cnt])); | ||
151 | GNUNET_assert(0 == strcmp("rohan", | ||
152 | GNUNET_TESTBED_host_get_hostname | ||
153 | (hosts[cnt]))); | ||
154 | GNUNET_assert(561 == GNUNET_TESTBED_host_get_ssh_port_(hosts[cnt])); | ||
155 | } | ||
129 | } | 156 | } |
130 | if (4 == cnt) | ||
131 | { | ||
132 | GNUNET_assert (0 == strcmp ("totakura", | ||
133 | GNUNET_TESTBED_host_get_username_ | ||
134 | (hosts[cnt]))); | ||
135 | GNUNET_assert (0 == strcmp ("asgard.realm", | ||
136 | GNUNET_TESTBED_host_get_hostname | ||
137 | (hosts[cnt]))); | ||
138 | GNUNET_assert (22 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt])); | ||
139 | } | ||
140 | if (5 == cnt) | ||
141 | { | ||
142 | GNUNET_assert (NULL == GNUNET_TESTBED_host_get_username_ (hosts[cnt])); | ||
143 | GNUNET_assert (0 == strcmp ("rivendal", | ||
144 | GNUNET_TESTBED_host_get_hostname | ||
145 | (hosts[cnt]))); | ||
146 | GNUNET_assert (22 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt])); | ||
147 | } | ||
148 | if (6 == cnt) | ||
149 | { | ||
150 | GNUNET_assert (NULL == GNUNET_TESTBED_host_get_username_ (hosts[cnt])); | ||
151 | GNUNET_assert (0 == strcmp ("rohan", | ||
152 | GNUNET_TESTBED_host_get_hostname | ||
153 | (hosts[cnt]))); | ||
154 | GNUNET_assert (561 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt])); | ||
155 | } | ||
156 | } | ||
157 | status = GNUNET_YES; | 157 | status = GNUNET_YES; |
158 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 158 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
159 | } | 159 | } |
160 | 160 | ||
161 | 161 | ||
162 | int | 162 | int |
163 | main (int argc, char **argv) | 163 | main(int argc, char **argv) |
164 | { | 164 | { |
165 | char *const argv2[] = { "test_testbed_api_hosts", | 165 | char *const argv2[] = { "test_testbed_api_hosts", |
166 | "-c", "test_testbed_api.conf", | 166 | "-c", "test_testbed_api.conf", |
167 | NULL | 167 | NULL }; |
168 | }; | ||
169 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 168 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
170 | GNUNET_GETOPT_OPTION_END | 169 | GNUNET_GETOPT_OPTION_END |
171 | }; | 170 | }; |
172 | 171 | ||
173 | status = GNUNET_SYSERR; | 172 | status = GNUNET_SYSERR; |
174 | if (GNUNET_OK != | 173 | if (GNUNET_OK != |
175 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | 174 | GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, |
176 | "test_testbed_api_hosts", "nohelp", options, &run, | 175 | "test_testbed_api_hosts", "nohelp", options, &run, |
177 | NULL)) | 176 | NULL)) |
178 | return 1; | 177 | return 1; |
179 | return (GNUNET_OK == status) ? 0 : 1; | 178 | return (GNUNET_OK == status) ? 0 : 1; |
180 | } | 179 | } |
diff --git a/src/testbed/test_testbed_api_operations.c b/src/testbed/test_testbed_api_operations.c index dfa8abc99..f88f85304 100644 --- a/src/testbed/test_testbed_api_operations.c +++ b/src/testbed/test_testbed_api_operations.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -31,14 +31,14 @@ | |||
31 | /** | 31 | /** |
32 | * Generic logging shortcut | 32 | * Generic logging shortcut |
33 | */ | 33 | */ |
34 | #define LOG(kind,...) \ | 34 | #define LOG(kind, ...) \ |
35 | GNUNET_log (kind, __VA_ARGS__) | 35 | GNUNET_log(kind, __VA_ARGS__) |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Delay to start step task | 38 | * Delay to start step task |
39 | */ | 39 | */ |
40 | #define STEP_DELAY \ | 40 | #define STEP_DELAY \ |
41 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500) | 41 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500) |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Queue A. Initially the max active is set to 2 and then reduced to 0 - this | 44 | * Queue A. Initially the max active is set to 2 and then reduced to 0 - this |
@@ -121,21 +121,20 @@ struct GNUNET_SCHEDULER_Task * step_task; | |||
121 | /** | 121 | /** |
122 | * Enumeration of test stages | 122 | * Enumeration of test stages |
123 | */ | 123 | */ |
124 | enum Test | 124 | enum Test { |
125 | { | 125 | /** |
126 | /** | 126 | * Initial stage |
127 | * Initial stage | 127 | */ |
128 | */ | ||
129 | TEST_INIT, | 128 | TEST_INIT, |
130 | 129 | ||
131 | /** | 130 | /** |
132 | * op1 has been started | 131 | * op1 has been started |
133 | */ | 132 | */ |
134 | TEST_OP1_STARTED, | 133 | TEST_OP1_STARTED, |
135 | 134 | ||
136 | /** | 135 | /** |
137 | * op1 has been released | 136 | * op1 has been released |
138 | */ | 137 | */ |
139 | TEST_OP1_RELEASED, | 138 | TEST_OP1_RELEASED, |
140 | 139 | ||
141 | /** | 140 | /** |
@@ -144,14 +143,14 @@ enum Test | |||
144 | */ | 143 | */ |
145 | TEST_PAUSE, | 144 | TEST_PAUSE, |
146 | 145 | ||
147 | /** | 146 | /** |
148 | * op2 has started | 147 | * op2 has started |
149 | */ | 148 | */ |
150 | TEST_OP2_STARTED, | 149 | TEST_OP2_STARTED, |
151 | 150 | ||
152 | /** | 151 | /** |
153 | * op2 released | 152 | * op2 released |
154 | */ | 153 | */ |
155 | TEST_OP2_RELEASED, | 154 | TEST_OP2_RELEASED, |
156 | 155 | ||
157 | /** | 156 | /** |
@@ -242,7 +241,7 @@ enum Test result; | |||
242 | * operation can be activated. | 241 | * operation can be activated. |
243 | */ | 242 | */ |
244 | static void | 243 | static void |
245 | start_cb (void *cls); | 244 | start_cb(void *cls); |
246 | 245 | ||
247 | 246 | ||
248 | /** | 247 | /** |
@@ -255,7 +254,7 @@ start_cb (void *cls); | |||
255 | * in 'cls' and release all resources associated with the operation. | 254 | * in 'cls' and release all resources associated with the operation. |
256 | */ | 255 | */ |
257 | static void | 256 | static void |
258 | release_cb (void *cls); | 257 | release_cb(void *cls); |
259 | 258 | ||
260 | 259 | ||
261 | /** | 260 | /** |
@@ -264,69 +263,79 @@ release_cb (void *cls); | |||
264 | * @param cls NULL | 263 | * @param cls NULL |
265 | */ | 264 | */ |
266 | static void | 265 | static void |
267 | step (void *cls) | 266 | step(void *cls) |
268 | { | 267 | { |
269 | GNUNET_assert (NULL != step_task); | 268 | GNUNET_assert(NULL != step_task); |
270 | step_task = NULL; | 269 | step_task = NULL; |
271 | switch (result) | 270 | switch (result) |
272 | { | 271 | { |
273 | case TEST_OP1_STARTED: | 272 | case TEST_OP1_STARTED: |
274 | GNUNET_TESTBED_operation_release_ (op1); | 273 | GNUNET_TESTBED_operation_release_(op1); |
275 | GNUNET_TESTBED_operation_queue_reset_max_active_ (q1, 0); | 274 | GNUNET_TESTBED_operation_queue_reset_max_active_(q1, 0); |
276 | op3 = GNUNET_TESTBED_operation_create_ (&op3, &start_cb, &release_cb); | 275 | op3 = GNUNET_TESTBED_operation_create_(&op3, &start_cb, &release_cb); |
277 | GNUNET_TESTBED_operation_queue_insert2_ (q1, op3, 2); | 276 | GNUNET_TESTBED_operation_queue_insert2_(q1, op3, 2); |
278 | GNUNET_TESTBED_operation_queue_insert2_ (q2, op3, 2); | 277 | GNUNET_TESTBED_operation_queue_insert2_(q2, op3, 2); |
279 | GNUNET_TESTBED_operation_begin_wait_ (op3); | 278 | GNUNET_TESTBED_operation_begin_wait_(op3); |
280 | op4 = GNUNET_TESTBED_operation_create_ (&op4, &start_cb, &release_cb); | 279 | op4 = GNUNET_TESTBED_operation_create_(&op4, &start_cb, &release_cb); |
281 | GNUNET_TESTBED_operation_queue_insert2_ (q1, op4, 2); | 280 | GNUNET_TESTBED_operation_queue_insert2_(q1, op4, 2); |
282 | GNUNET_TESTBED_operation_queue_insert2_ (q2, op4, 2); | 281 | GNUNET_TESTBED_operation_queue_insert2_(q2, op4, 2); |
283 | GNUNET_TESTBED_operation_begin_wait_ (op4); | 282 | GNUNET_TESTBED_operation_begin_wait_(op4); |
284 | break; | 283 | break; |
285 | case TEST_OP1_RELEASED: | 284 | |
286 | result = TEST_PAUSE; | 285 | case TEST_OP1_RELEASED: |
287 | GNUNET_TESTBED_operation_queue_reset_max_active_ (q1, 2); | 286 | result = TEST_PAUSE; |
288 | break; | 287 | GNUNET_TESTBED_operation_queue_reset_max_active_(q1, 2); |
289 | case TEST_OP2_STARTED: | 288 | break; |
290 | GNUNET_TESTBED_operation_release_ (op2); | 289 | |
291 | break; | 290 | case TEST_OP2_STARTED: |
292 | case TEST_OP3_STARTED: | 291 | GNUNET_TESTBED_operation_release_(op2); |
293 | GNUNET_TESTBED_operation_release_ (op3); | 292 | break; |
294 | break; | 293 | |
295 | case TEST_OP4_STARTED: | 294 | case TEST_OP3_STARTED: |
296 | GNUNET_TESTBED_operation_release_ (op4); | 295 | GNUNET_TESTBED_operation_release_(op3); |
297 | break; | 296 | break; |
298 | case TEST_OP6_RELEASED: | 297 | |
299 | op8 = GNUNET_TESTBED_operation_create_ (&op8, &start_cb, &release_cb); | 298 | case TEST_OP4_STARTED: |
300 | GNUNET_TESTBED_operation_queue_insert2_ (q1, op8, 2); | 299 | GNUNET_TESTBED_operation_release_(op4); |
301 | GNUNET_TESTBED_operation_queue_insert2_ (q2, op8, 2); | 300 | break; |
302 | result = TEST_OP8_WAITING; | 301 | |
303 | GNUNET_TESTBED_operation_begin_wait_ (op8); | 302 | case TEST_OP6_RELEASED: |
304 | break; | 303 | op8 = GNUNET_TESTBED_operation_create_(&op8, &start_cb, &release_cb); |
305 | case TEST_OP8_STARTED: | 304 | GNUNET_TESTBED_operation_queue_insert2_(q1, op8, 2); |
306 | GNUNET_TESTBED_operation_inactivate_ (op8); | 305 | GNUNET_TESTBED_operation_queue_insert2_(q2, op8, 2); |
307 | result = TEST_OP8_INACTIVE_1; | 306 | result = TEST_OP8_WAITING; |
308 | step_task = GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); | 307 | GNUNET_TESTBED_operation_begin_wait_(op8); |
309 | break; | 308 | break; |
310 | case TEST_OP8_INACTIVE_1: | 309 | |
311 | GNUNET_TESTBED_operation_activate_ (op8); | 310 | case TEST_OP8_STARTED: |
312 | result = TEST_OP8_ACTIVE; | 311 | GNUNET_TESTBED_operation_inactivate_(op8); |
313 | op9 = GNUNET_TESTBED_operation_create_ (&op9, &start_cb, &release_cb); | 312 | result = TEST_OP8_INACTIVE_1; |
314 | GNUNET_TESTBED_operation_queue_insert2_ (q1, op9, 1); | 313 | step_task = GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); |
315 | GNUNET_TESTBED_operation_queue_insert2_ (q2, op9, 1); | 314 | break; |
316 | GNUNET_TESTBED_operation_begin_wait_ (op9); | 315 | |
317 | step_task = GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); | 316 | case TEST_OP8_INACTIVE_1: |
318 | break; | 317 | GNUNET_TESTBED_operation_activate_(op8); |
319 | case TEST_OP8_ACTIVE: | 318 | result = TEST_OP8_ACTIVE; |
320 | GNUNET_TESTBED_operation_inactivate_ (op8); | 319 | op9 = GNUNET_TESTBED_operation_create_(&op9, &start_cb, &release_cb); |
321 | /* op8 should be released by now due to above call */ | 320 | GNUNET_TESTBED_operation_queue_insert2_(q1, op9, 1); |
322 | GNUNET_assert (TEST_OP8_RELEASED == result); | 321 | GNUNET_TESTBED_operation_queue_insert2_(q2, op9, 1); |
323 | break; | 322 | GNUNET_TESTBED_operation_begin_wait_(op9); |
324 | case TEST_OP9_STARTED: | 323 | step_task = GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); |
325 | GNUNET_TESTBED_operation_release_ (op9); | 324 | break; |
326 | break; | 325 | |
327 | default: | 326 | case TEST_OP8_ACTIVE: |
328 | GNUNET_assert (0); | 327 | GNUNET_TESTBED_operation_inactivate_(op8); |
329 | } | 328 | /* op8 should be released by now due to above call */ |
329 | GNUNET_assert(TEST_OP8_RELEASED == result); | ||
330 | break; | ||
331 | |||
332 | case TEST_OP9_STARTED: | ||
333 | GNUNET_TESTBED_operation_release_(op9); | ||
334 | break; | ||
335 | |||
336 | default: | ||
337 | GNUNET_assert(0); | ||
338 | } | ||
330 | } | 339 | } |
331 | 340 | ||
332 | 341 | ||
@@ -336,64 +345,71 @@ step (void *cls) | |||
336 | * operation can be activated. | 345 | * operation can be activated. |
337 | */ | 346 | */ |
338 | static void | 347 | static void |
339 | start_cb (void *cls) | 348 | start_cb(void *cls) |
340 | { | 349 | { |
341 | switch (result) | 350 | switch (result) |
342 | { | ||
343 | case TEST_INIT: | ||
344 | GNUNET_assert (&op1 == cls); | ||
345 | result = TEST_OP1_STARTED; | ||
346 | GNUNET_assert (NULL == step_task); | ||
347 | step_task = | ||
348 | GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); | ||
349 | break; | ||
350 | case TEST_PAUSE: | ||
351 | GNUNET_assert (&op2 == cls); | ||
352 | result = TEST_OP2_STARTED; | ||
353 | GNUNET_assert (NULL == step_task); | ||
354 | step_task = | ||
355 | GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); | ||
356 | break; | ||
357 | case TEST_OP2_RELEASED: | ||
358 | GNUNET_assert (&op3 == cls); | ||
359 | result = TEST_OP3_STARTED; | ||
360 | GNUNET_assert (NULL == step_task); | ||
361 | step_task = | ||
362 | GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); | ||
363 | break; | ||
364 | case TEST_OP3_RELEASED: | ||
365 | GNUNET_assert (&op4 == cls); | ||
366 | result = TEST_OP4_STARTED; | ||
367 | GNUNET_assert (NULL == step_task); | ||
368 | step_task = | ||
369 | GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); | ||
370 | break; | ||
371 | case TEST_OP4_RELEASED: | ||
372 | { | ||
373 | static int nops; | ||
374 | |||
375 | nops++; | ||
376 | if (nops == 3) | ||
377 | { | 351 | { |
378 | result = TEST_OP5_6_7_STARTED; | 352 | case TEST_INIT: |
379 | GNUNET_TESTBED_operation_release_ (op5); | 353 | GNUNET_assert(&op1 == cls); |
380 | op5 = NULL; | 354 | result = TEST_OP1_STARTED; |
355 | GNUNET_assert(NULL == step_task); | ||
356 | step_task = | ||
357 | GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); | ||
358 | break; | ||
359 | |||
360 | case TEST_PAUSE: | ||
361 | GNUNET_assert(&op2 == cls); | ||
362 | result = TEST_OP2_STARTED; | ||
363 | GNUNET_assert(NULL == step_task); | ||
364 | step_task = | ||
365 | GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); | ||
366 | break; | ||
367 | |||
368 | case TEST_OP2_RELEASED: | ||
369 | GNUNET_assert(&op3 == cls); | ||
370 | result = TEST_OP3_STARTED; | ||
371 | GNUNET_assert(NULL == step_task); | ||
372 | step_task = | ||
373 | GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); | ||
374 | break; | ||
375 | |||
376 | case TEST_OP3_RELEASED: | ||
377 | GNUNET_assert(&op4 == cls); | ||
378 | result = TEST_OP4_STARTED; | ||
379 | GNUNET_assert(NULL == step_task); | ||
380 | step_task = | ||
381 | GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); | ||
382 | break; | ||
383 | |||
384 | case TEST_OP4_RELEASED: | ||
385 | { | ||
386 | static int nops; | ||
387 | |||
388 | nops++; | ||
389 | if (nops == 3) | ||
390 | { | ||
391 | result = TEST_OP5_6_7_STARTED; | ||
392 | GNUNET_TESTBED_operation_release_(op5); | ||
393 | op5 = NULL; | ||
394 | } | ||
381 | } | 395 | } |
382 | } | ||
383 | break; | 396 | break; |
384 | case TEST_OP7_RELEASED: | 397 | |
385 | GNUNET_assert (&op8 == cls); | 398 | case TEST_OP7_RELEASED: |
386 | result = TEST_OP8_STARTED; | 399 | GNUNET_assert(&op8 == cls); |
387 | step_task = GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); | 400 | result = TEST_OP8_STARTED; |
388 | break; | 401 | step_task = GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); |
389 | case TEST_OP8_RELEASED: | 402 | break; |
390 | GNUNET_assert (&op9 == cls); | 403 | |
391 | result = TEST_OP9_STARTED; | 404 | case TEST_OP8_RELEASED: |
392 | step_task = GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); | 405 | GNUNET_assert(&op9 == cls); |
393 | break; | 406 | result = TEST_OP9_STARTED; |
394 | default: | 407 | step_task = GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); |
395 | GNUNET_assert (0); | 408 | break; |
396 | } | 409 | |
410 | default: | ||
411 | GNUNET_assert(0); | ||
412 | } | ||
397 | } | 413 | } |
398 | 414 | ||
399 | 415 | ||
@@ -407,73 +423,82 @@ start_cb (void *cls) | |||
407 | * in 'cls' and release all resources associated with the operation. | 423 | * in 'cls' and release all resources associated with the operation. |
408 | */ | 424 | */ |
409 | static void | 425 | static void |
410 | release_cb (void *cls) | 426 | release_cb(void *cls) |
411 | { | 427 | { |
412 | switch (result) | 428 | switch (result) |
413 | { | 429 | { |
414 | case TEST_OP1_STARTED: | 430 | case TEST_OP1_STARTED: |
415 | GNUNET_assert (&op1 == cls); | 431 | GNUNET_assert(&op1 == cls); |
416 | result = TEST_OP1_RELEASED; | 432 | result = TEST_OP1_RELEASED; |
417 | op1 = NULL; | 433 | op1 = NULL; |
418 | step_task = | 434 | step_task = |
419 | GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL); | 435 | GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); |
420 | break; | 436 | break; |
421 | case TEST_OP2_STARTED: | 437 | |
422 | GNUNET_assert (&op2 == cls); | 438 | case TEST_OP2_STARTED: |
423 | result = TEST_OP2_RELEASED; | 439 | GNUNET_assert(&op2 == cls); |
424 | GNUNET_assert (NULL == step_task); | 440 | result = TEST_OP2_RELEASED; |
425 | break; | 441 | GNUNET_assert(NULL == step_task); |
426 | case TEST_OP3_STARTED: | 442 | break; |
427 | GNUNET_assert (&op3 == cls); | 443 | |
428 | result = TEST_OP3_RELEASED; | 444 | case TEST_OP3_STARTED: |
429 | GNUNET_assert (NULL == step_task); | 445 | GNUNET_assert(&op3 == cls); |
430 | break; | 446 | result = TEST_OP3_RELEASED; |
431 | case TEST_OP4_STARTED: | 447 | GNUNET_assert(NULL == step_task); |
432 | GNUNET_assert (&op4 == cls); | 448 | break; |
433 | result = TEST_OP4_RELEASED; | 449 | |
434 | GNUNET_assert (NULL == step_task); | 450 | case TEST_OP4_STARTED: |
435 | op5 = GNUNET_TESTBED_operation_create_ (&op5, &start_cb, &release_cb); | 451 | GNUNET_assert(&op4 == cls); |
436 | GNUNET_TESTBED_operation_queue_insert2_ (q1, op5, 1); | 452 | result = TEST_OP4_RELEASED; |
437 | GNUNET_TESTBED_operation_begin_wait_ (op5); | 453 | GNUNET_assert(NULL == step_task); |
438 | op6 = GNUNET_TESTBED_operation_create_ (&op6, &start_cb, &release_cb); | 454 | op5 = GNUNET_TESTBED_operation_create_(&op5, &start_cb, &release_cb); |
439 | GNUNET_TESTBED_operation_queue_insert2_ (q2, op6, 1); | 455 | GNUNET_TESTBED_operation_queue_insert2_(q1, op5, 1); |
440 | GNUNET_TESTBED_operation_begin_wait_ (op6); | 456 | GNUNET_TESTBED_operation_begin_wait_(op5); |
441 | op7 = GNUNET_TESTBED_operation_create_ (&op7, &start_cb, &release_cb); | 457 | op6 = GNUNET_TESTBED_operation_create_(&op6, &start_cb, &release_cb); |
442 | GNUNET_TESTBED_operation_queue_insert2_ (q1, op7, 1); | 458 | GNUNET_TESTBED_operation_queue_insert2_(q2, op6, 1); |
443 | GNUNET_TESTBED_operation_queue_insert2_ (q2, op7, 1); | 459 | GNUNET_TESTBED_operation_begin_wait_(op6); |
444 | GNUNET_TESTBED_operation_begin_wait_ (op7); | 460 | op7 = GNUNET_TESTBED_operation_create_(&op7, &start_cb, &release_cb); |
445 | break; | 461 | GNUNET_TESTBED_operation_queue_insert2_(q1, op7, 1); |
446 | case TEST_OP5_6_7_STARTED: | 462 | GNUNET_TESTBED_operation_queue_insert2_(q2, op7, 1); |
447 | result = TEST_OP5_RELEASED; | 463 | GNUNET_TESTBED_operation_begin_wait_(op7); |
448 | op5 = NULL; | 464 | break; |
449 | GNUNET_TESTBED_operation_release_ (op6); | 465 | |
450 | break; | 466 | case TEST_OP5_6_7_STARTED: |
451 | case TEST_OP5_RELEASED: | 467 | result = TEST_OP5_RELEASED; |
452 | op6 = NULL; | 468 | op5 = NULL; |
453 | result = TEST_OP6_RELEASED; | 469 | GNUNET_TESTBED_operation_release_(op6); |
454 | GNUNET_TESTBED_operation_inactivate_ (op7); | 470 | break; |
455 | step_task = GNUNET_SCHEDULER_add_now (&step, NULL); | 471 | |
456 | break; | 472 | case TEST_OP5_RELEASED: |
457 | case TEST_OP8_WAITING: | 473 | op6 = NULL; |
458 | GNUNET_assert (&op7 == cls); | 474 | result = TEST_OP6_RELEASED; |
459 | op7 = NULL; | 475 | GNUNET_TESTBED_operation_inactivate_(op7); |
460 | result = TEST_OP7_RELEASED; | 476 | step_task = GNUNET_SCHEDULER_add_now(&step, NULL); |
461 | break; | 477 | break; |
462 | case TEST_OP8_ACTIVE: | 478 | |
463 | result = TEST_OP8_RELEASED; | 479 | case TEST_OP8_WAITING: |
464 | op8 = NULL; | 480 | GNUNET_assert(&op7 == cls); |
465 | break; | 481 | op7 = NULL; |
466 | case TEST_OP9_STARTED: | 482 | result = TEST_OP7_RELEASED; |
467 | GNUNET_assert (&op9 == cls); | 483 | break; |
468 | result = TEST_OP9_RELEASED; | 484 | |
469 | GNUNET_TESTBED_operation_queue_destroy_ (q1); | 485 | case TEST_OP8_ACTIVE: |
470 | GNUNET_TESTBED_operation_queue_destroy_ (q2); | 486 | result = TEST_OP8_RELEASED; |
471 | q1 = NULL; | 487 | op8 = NULL; |
472 | q2 = NULL; | 488 | break; |
473 | break; | 489 | |
474 | default: | 490 | case TEST_OP9_STARTED: |
475 | GNUNET_assert (0); | 491 | GNUNET_assert(&op9 == cls); |
476 | } | 492 | result = TEST_OP9_RELEASED; |
493 | GNUNET_TESTBED_operation_queue_destroy_(q1); | ||
494 | GNUNET_TESTBED_operation_queue_destroy_(q2); | ||
495 | q1 = NULL; | ||
496 | q2 = NULL; | ||
497 | break; | ||
498 | |||
499 | default: | ||
500 | GNUNET_assert(0); | ||
501 | } | ||
477 | } | 502 | } |
478 | 503 | ||
479 | 504 | ||
@@ -486,22 +511,22 @@ release_cb (void *cls) | |||
486 | * @param cfg the configuration file handle | 511 | * @param cfg the configuration file handle |
487 | */ | 512 | */ |
488 | static void | 513 | static void |
489 | run (void *cls, char *const *args, const char *cfgfile, | 514 | run(void *cls, char *const *args, const char *cfgfile, |
490 | const struct GNUNET_CONFIGURATION_Handle *config) | 515 | const struct GNUNET_CONFIGURATION_Handle *config) |
491 | { | 516 | { |
492 | q1 = GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, 1); | 517 | q1 = GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_FIXED, 1); |
493 | GNUNET_assert (NULL != q1); | 518 | GNUNET_assert(NULL != q1); |
494 | q2 = GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, 2); | 519 | q2 = GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_FIXED, 2); |
495 | GNUNET_assert (NULL != q2); | 520 | GNUNET_assert(NULL != q2); |
496 | op1 = GNUNET_TESTBED_operation_create_ (&op1, start_cb, release_cb); | 521 | op1 = GNUNET_TESTBED_operation_create_(&op1, start_cb, release_cb); |
497 | GNUNET_assert (NULL != op1); | 522 | GNUNET_assert(NULL != op1); |
498 | op2 = GNUNET_TESTBED_operation_create_ (&op2, start_cb, release_cb); | 523 | op2 = GNUNET_TESTBED_operation_create_(&op2, start_cb, release_cb); |
499 | GNUNET_TESTBED_operation_queue_insert_ (q1, op1); | 524 | GNUNET_TESTBED_operation_queue_insert_(q1, op1); |
500 | GNUNET_TESTBED_operation_queue_insert_ (q2, op1); | 525 | GNUNET_TESTBED_operation_queue_insert_(q2, op1); |
501 | GNUNET_TESTBED_operation_begin_wait_ (op1); | 526 | GNUNET_TESTBED_operation_begin_wait_(op1); |
502 | GNUNET_TESTBED_operation_queue_insert_ (q1, op2); | 527 | GNUNET_TESTBED_operation_queue_insert_(q1, op2); |
503 | GNUNET_TESTBED_operation_queue_insert_ (q2, op2); | 528 | GNUNET_TESTBED_operation_queue_insert_(q2, op2); |
504 | GNUNET_TESTBED_operation_begin_wait_ (op2); | 529 | GNUNET_TESTBED_operation_begin_wait_(op2); |
505 | result = TEST_INIT; | 530 | result = TEST_INIT; |
506 | } | 531 | } |
507 | 532 | ||
@@ -510,18 +535,18 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
510 | * Main function | 535 | * Main function |
511 | */ | 536 | */ |
512 | int | 537 | int |
513 | main (int argc, char **argv) | 538 | main(int argc, char **argv) |
514 | { | 539 | { |
515 | int ret; | 540 | int ret; |
516 | char *const argv2[] = | 541 | char *const argv2[] = |
517 | { "test_testbed_api_operations", "-c", "test_testbed_api.conf", NULL }; | 542 | { "test_testbed_api_operations", "-c", "test_testbed_api.conf", NULL }; |
518 | struct GNUNET_GETOPT_CommandLineOption options[] = | 543 | struct GNUNET_GETOPT_CommandLineOption options[] = |
519 | { GNUNET_GETOPT_OPTION_END }; | 544 | { GNUNET_GETOPT_OPTION_END }; |
520 | 545 | ||
521 | ret = | 546 | ret = |
522 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | 547 | GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, |
523 | "test_testbed_api_operations", "nohelp", options, | 548 | "test_testbed_api_operations", "nohelp", options, |
524 | &run, NULL); | 549 | &run, NULL); |
525 | if ((GNUNET_OK != ret) || (TEST_OP9_RELEASED != result)) | 550 | if ((GNUNET_OK != ret) || (TEST_OP9_RELEASED != result)) |
526 | return 1; | 551 | return 1; |
527 | op1 = NULL; | 552 | op1 = NULL; |
diff --git a/src/testbed/test_testbed_api_peer_reconfiguration.c b/src/testbed/test_testbed_api_peer_reconfiguration.c index e79876997..40791a9cc 100644 --- a/src/testbed/test_testbed_api_peer_reconfiguration.c +++ b/src/testbed/test_testbed_api_peer_reconfiguration.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -53,7 +53,6 @@ static struct GNUNET_SCHEDULER_Task * abort_task; | |||
53 | * States in this test | 53 | * States in this test |
54 | */ | 54 | */ |
55 | enum { | 55 | enum { |
56 | |||
57 | /** | 56 | /** |
58 | * Test has just been initialized | 57 | * Test has just been initialized |
59 | */ | 58 | */ |
@@ -68,20 +67,19 @@ enum { | |||
68 | * Peer has been reconfigured. Test completed successfully | 67 | * Peer has been reconfigured. Test completed successfully |
69 | */ | 68 | */ |
70 | STATE_PEER_RECONFIGURED | 69 | STATE_PEER_RECONFIGURED |
71 | |||
72 | } state; | 70 | } state; |
73 | 71 | ||
74 | /** | 72 | /** |
75 | * Fail testcase | 73 | * Fail testcase |
76 | */ | 74 | */ |
77 | #define FAIL_TEST(cond, ret) do { \ | 75 | #define FAIL_TEST(cond, ret) do { \ |
78 | if (!(cond)) { \ | 76 | if (!(cond)) { \ |
79 | GNUNET_break(0); \ | 77 | GNUNET_break(0); \ |
80 | if (NULL != abort_task) \ | 78 | if (NULL != abort_task) \ |
81 | GNUNET_SCHEDULER_cancel (abort_task); \ | 79 | GNUNET_SCHEDULER_cancel (abort_task); \ |
82 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \ | 80 | abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); \ |
83 | ret; \ | 81 | ret; \ |
84 | } \ | 82 | } \ |
85 | } while (0) | 83 | } while (0) |
86 | 84 | ||
87 | 85 | ||
@@ -91,15 +89,15 @@ enum { | |||
91 | * @param cls NULL | 89 | * @param cls NULL |
92 | */ | 90 | */ |
93 | static void | 91 | static void |
94 | do_abort (void *cls) | 92 | do_abort(void *cls) |
95 | { | 93 | { |
96 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Aborting\n"); | 94 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Aborting\n"); |
97 | abort_task = NULL; | 95 | abort_task = NULL; |
98 | if (NULL != op) | 96 | if (NULL != op) |
99 | { | 97 | { |
100 | GNUNET_TESTBED_operation_done (op); | 98 | GNUNET_TESTBED_operation_done(op); |
101 | op = NULL; | 99 | op = NULL; |
102 | } | 100 | } |
103 | GNUNET_SCHEDULER_shutdown(); | 101 | GNUNET_SCHEDULER_shutdown(); |
104 | } | 102 | } |
105 | 103 | ||
@@ -112,29 +110,29 @@ do_abort (void *cls) | |||
112 | * @param event information about the event | 110 | * @param event information about the event |
113 | */ | 111 | */ |
114 | static void | 112 | static void |
115 | controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | 113 | controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) |
116 | { | 114 | { |
117 | if (STATE_PEER_STARTED != state) | 115 | if (STATE_PEER_STARTED != state) |
118 | return; | 116 | return; |
119 | if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type) | 117 | if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type) |
120 | { | 118 | { |
121 | GNUNET_TESTBED_operation_done (op); | 119 | GNUNET_TESTBED_operation_done(op); |
122 | op = NULL; | 120 | op = NULL; |
123 | FAIL_TEST (0, return); | 121 | FAIL_TEST(0, return ); |
124 | } | 122 | } |
125 | if (NULL != event->details.operation_finished.emsg) | 123 | if (NULL != event->details.operation_finished.emsg) |
126 | { | 124 | { |
127 | fprintf (stderr, "Operation failed: %s\n", | 125 | fprintf(stderr, "Operation failed: %s\n", |
128 | event->details.operation_finished.emsg); | 126 | event->details.operation_finished.emsg); |
129 | GNUNET_TESTBED_operation_done (op); | 127 | GNUNET_TESTBED_operation_done(op); |
130 | op = NULL; | 128 | op = NULL; |
131 | FAIL_TEST (0, return); | 129 | FAIL_TEST(0, return ); |
132 | } | 130 | } |
133 | GNUNET_TESTBED_operation_done (op); | 131 | GNUNET_TESTBED_operation_done(op); |
134 | state = STATE_PEER_RECONFIGURED; | 132 | state = STATE_PEER_RECONFIGURED; |
135 | GNUNET_SCHEDULER_cancel (abort_task); | 133 | GNUNET_SCHEDULER_cancel(abort_task); |
136 | abort_task = NULL; | 134 | abort_task = NULL; |
137 | GNUNET_SCHEDULER_shutdown (); | 135 | GNUNET_SCHEDULER_shutdown(); |
138 | } | 136 | } |
139 | 137 | ||
140 | 138 | ||
@@ -151,27 +149,27 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
151 | * failed | 149 | * failed |
152 | */ | 150 | */ |
153 | static void | 151 | static void |
154 | test_master (void *cls, | 152 | test_master(void *cls, |
155 | struct GNUNET_TESTBED_RunHandle *h, | 153 | struct GNUNET_TESTBED_RunHandle *h, |
156 | unsigned int num_peers, | 154 | unsigned int num_peers, |
157 | struct GNUNET_TESTBED_Peer **peers_, | 155 | struct GNUNET_TESTBED_Peer **peers_, |
158 | unsigned int links_succeeded, | 156 | unsigned int links_succeeded, |
159 | unsigned int links_failed) | 157 | unsigned int links_failed) |
160 | { | 158 | { |
161 | struct GNUNET_CONFIGURATION_Handle *cfg; | 159 | struct GNUNET_CONFIGURATION_Handle *cfg; |
162 | 160 | ||
163 | FAIL_TEST (NUM_PEERS == num_peers, return); | 161 | FAIL_TEST(NUM_PEERS == num_peers, return ); |
164 | state = STATE_PEER_STARTED; | 162 | state = STATE_PEER_STARTED; |
165 | peers = peers_; | 163 | peers = peers_; |
166 | cfg = GNUNET_CONFIGURATION_create (); | 164 | cfg = GNUNET_CONFIGURATION_create(); |
167 | FAIL_TEST (GNUNET_OK == GNUNET_CONFIGURATION_load | 165 | FAIL_TEST(GNUNET_OK == GNUNET_CONFIGURATION_load |
168 | (cfg, "test_testbed_api_testbed_run_topologyrandom.conf"), return); | 166 | (cfg, "test_testbed_api_testbed_run_topologyrandom.conf"), return ); |
169 | op = GNUNET_TESTBED_peer_update_configuration (peers[0], cfg); | 167 | op = GNUNET_TESTBED_peer_update_configuration(peers[0], cfg); |
170 | GNUNET_CONFIGURATION_destroy (cfg); | 168 | GNUNET_CONFIGURATION_destroy(cfg); |
171 | FAIL_TEST (NULL != op, return); | 169 | FAIL_TEST(NULL != op, return ); |
172 | abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 170 | abort_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
173 | (GNUNET_TIME_UNIT_SECONDS, 30), | 171 | (GNUNET_TIME_UNIT_SECONDS, 30), |
174 | &do_abort, NULL); | 172 | &do_abort, NULL); |
175 | } | 173 | } |
176 | 174 | ||
177 | 175 | ||
@@ -179,15 +177,15 @@ test_master (void *cls, | |||
179 | * Main function | 177 | * Main function |
180 | */ | 178 | */ |
181 | int | 179 | int |
182 | main (int argc, char **argv) | 180 | main(int argc, char **argv) |
183 | { | 181 | { |
184 | state = STATE_INIT; | 182 | state = STATE_INIT; |
185 | (void) GNUNET_TESTBED_test_run ("test_testbed_api_peer_reconfiguration", | 183 | (void)GNUNET_TESTBED_test_run("test_testbed_api_peer_reconfiguration", |
186 | "test_testbed_api.conf", | 184 | "test_testbed_api.conf", |
187 | NUM_PEERS, | 185 | NUM_PEERS, |
188 | 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED, | 186 | 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED, |
189 | &controller_cb, NULL, | 187 | &controller_cb, NULL, |
190 | &test_master, NULL); | 188 | &test_master, NULL); |
191 | if (STATE_PEER_RECONFIGURED != state) | 189 | if (STATE_PEER_RECONFIGURED != state) |
192 | return 1; | 190 | return 1; |
193 | return 0; | 191 | return 0; |
diff --git a/src/testbed/test_testbed_api_peers_manage_services.c b/src/testbed/test_testbed_api_peers_manage_services.c index c5e2b2646..d6597890f 100644 --- a/src/testbed/test_testbed_api_peers_manage_services.c +++ b/src/testbed/test_testbed_api_peers_manage_services.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -47,7 +47,7 @@ static struct GNUNET_TESTBED_Operation *op; | |||
47 | /** | 47 | /** |
48 | * dummy pointer | 48 | * dummy pointer |
49 | */ | 49 | */ |
50 | static void *dummy_cls = (void *) 0xDEAD0001; | 50 | static void *dummy_cls = (void *)0xDEAD0001; |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Abort task identifier | 53 | * Abort task identifier |
@@ -58,7 +58,6 @@ static struct GNUNET_SCHEDULER_Task * abort_task; | |||
58 | * States in this test | 58 | * States in this test |
59 | */ | 59 | */ |
60 | enum { | 60 | enum { |
61 | |||
62 | /** | 61 | /** |
63 | * Test has just been initialized | 62 | * Test has just been initialized |
64 | */ | 63 | */ |
@@ -89,13 +88,13 @@ enum { | |||
89 | * Fail testcase | 88 | * Fail testcase |
90 | */ | 89 | */ |
91 | #define FAIL_TEST(cond, ret) do { \ | 90 | #define FAIL_TEST(cond, ret) do { \ |
92 | if (!(cond)) { \ | 91 | if (!(cond)) { \ |
93 | GNUNET_break(0); \ | 92 | GNUNET_break(0); \ |
94 | if (NULL != abort_task) \ | 93 | if (NULL != abort_task) \ |
95 | GNUNET_SCHEDULER_cancel (abort_task); \ | 94 | GNUNET_SCHEDULER_cancel (abort_task); \ |
96 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \ | 95 | abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); \ |
97 | ret; \ | 96 | ret; \ |
98 | } \ | 97 | } \ |
99 | } while (0) | 98 | } while (0) |
100 | 99 | ||
101 | 100 | ||
@@ -105,15 +104,15 @@ enum { | |||
105 | * @param cls NULL | 104 | * @param cls NULL |
106 | */ | 105 | */ |
107 | static void | 106 | static void |
108 | do_abort (void *cls) | 107 | do_abort(void *cls) |
109 | { | 108 | { |
110 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Aborting\n"); | 109 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Aborting\n"); |
111 | abort_task = NULL; | 110 | abort_task = NULL; |
112 | if (NULL != op) | 111 | if (NULL != op) |
113 | { | 112 | { |
114 | GNUNET_TESTBED_operation_done (op); | 113 | GNUNET_TESTBED_operation_done(op); |
115 | op = NULL; | 114 | op = NULL; |
116 | } | 115 | } |
117 | GNUNET_SCHEDULER_shutdown(); | 116 | GNUNET_SCHEDULER_shutdown(); |
118 | } | 117 | } |
119 | 118 | ||
@@ -127,36 +126,38 @@ do_abort (void *cls) | |||
127 | * operation has executed successfully. | 126 | * operation has executed successfully. |
128 | */ | 127 | */ |
129 | static void | 128 | static void |
130 | op_comp_cb (void *cls, | 129 | op_comp_cb(void *cls, |
131 | struct GNUNET_TESTBED_Operation *op, | 130 | struct GNUNET_TESTBED_Operation *op, |
132 | const char *emsg) | 131 | const char *emsg) |
133 | { | 132 | { |
134 | FAIL_TEST (cls == dummy_cls, return); | 133 | FAIL_TEST(cls == dummy_cls, return ); |
135 | FAIL_TEST (NULL == emsg, return); | 134 | FAIL_TEST(NULL == emsg, return ); |
136 | GNUNET_TESTBED_operation_done (op); | 135 | GNUNET_TESTBED_operation_done(op); |
137 | op = NULL; | 136 | op = NULL; |
138 | switch (state) | 137 | switch (state) |
139 | { | 138 | { |
140 | case STATE_PEERS_STARTED: | 139 | case STATE_PEERS_STARTED: |
141 | state = STATE_SERVICE_DOWN; | 140 | state = STATE_SERVICE_DOWN; |
142 | op = GNUNET_TESTBED_peer_manage_service (dummy_cls, | 141 | op = GNUNET_TESTBED_peer_manage_service(dummy_cls, |
143 | peers[1], | 142 | peers[1], |
144 | "topology", | 143 | "topology", |
145 | op_comp_cb, | 144 | op_comp_cb, |
146 | dummy_cls, | 145 | dummy_cls, |
147 | 0); | 146 | 0); |
148 | GNUNET_assert (NULL != op); | 147 | GNUNET_assert(NULL != op); |
149 | break; | 148 | break; |
150 | case STATE_SERVICE_DOWN: | 149 | |
151 | state = STATE_SERVICE_UP; | 150 | case STATE_SERVICE_DOWN: |
152 | GNUNET_SCHEDULER_cancel (abort_task); | 151 | state = STATE_SERVICE_UP; |
153 | abort_task = NULL; | 152 | GNUNET_SCHEDULER_cancel(abort_task); |
154 | state = STATE_OK; | 153 | abort_task = NULL; |
155 | GNUNET_SCHEDULER_shutdown (); | 154 | state = STATE_OK; |
156 | break; | 155 | GNUNET_SCHEDULER_shutdown(); |
157 | default: | 156 | break; |
158 | FAIL_TEST (0, return); | 157 | |
159 | } | 158 | default: |
159 | FAIL_TEST(0, return ); | ||
160 | } | ||
160 | } | 161 | } |
161 | 162 | ||
162 | 163 | ||
@@ -173,26 +174,26 @@ op_comp_cb (void *cls, | |||
173 | * failed | 174 | * failed |
174 | */ | 175 | */ |
175 | static void | 176 | static void |
176 | test_master (void *cls, | 177 | test_master(void *cls, |
177 | struct GNUNET_TESTBED_RunHandle *h, | 178 | struct GNUNET_TESTBED_RunHandle *h, |
178 | unsigned int num_peers, | 179 | unsigned int num_peers, |
179 | struct GNUNET_TESTBED_Peer **peers_, | 180 | struct GNUNET_TESTBED_Peer **peers_, |
180 | unsigned int links_succeeded, | 181 | unsigned int links_succeeded, |
181 | unsigned int links_failed) | 182 | unsigned int links_failed) |
182 | { | 183 | { |
183 | FAIL_TEST (NUM_PEERS == num_peers, return); | 184 | FAIL_TEST(NUM_PEERS == num_peers, return ); |
184 | state = STATE_PEERS_STARTED; | 185 | state = STATE_PEERS_STARTED; |
185 | peers = peers_; | 186 | peers = peers_; |
186 | op = GNUNET_TESTBED_peer_manage_service (dummy_cls, | 187 | op = GNUNET_TESTBED_peer_manage_service(dummy_cls, |
187 | peers[1], | 188 | peers[1], |
188 | "topology", | 189 | "topology", |
189 | op_comp_cb, | 190 | op_comp_cb, |
190 | dummy_cls, | 191 | dummy_cls, |
191 | 1); | 192 | 1); |
192 | FAIL_TEST (NULL != op, return); | 193 | FAIL_TEST(NULL != op, return ); |
193 | abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 194 | abort_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
194 | (GNUNET_TIME_UNIT_MINUTES, 1), | 195 | (GNUNET_TIME_UNIT_MINUTES, 1), |
195 | &do_abort, NULL); | 196 | &do_abort, NULL); |
196 | } | 197 | } |
197 | 198 | ||
198 | 199 | ||
@@ -200,14 +201,14 @@ test_master (void *cls, | |||
200 | * Main function | 201 | * Main function |
201 | */ | 202 | */ |
202 | int | 203 | int |
203 | main (int argc, char **argv) | 204 | main(int argc, char **argv) |
204 | { | 205 | { |
205 | state = STATE_INIT; | 206 | state = STATE_INIT; |
206 | (void) GNUNET_TESTBED_test_run ("test_testbed_api_peers_manage_services", | 207 | (void)GNUNET_TESTBED_test_run("test_testbed_api_peers_manage_services", |
207 | "test_testbed_api.conf", | 208 | "test_testbed_api.conf", |
208 | NUM_PEERS, | 209 | NUM_PEERS, |
209 | 1LL, NULL, NULL, | 210 | 1LL, NULL, NULL, |
210 | &test_master, NULL); | 211 | &test_master, NULL); |
211 | if (STATE_OK != state) | 212 | if (STATE_OK != state) |
212 | return 1; | 213 | return 1; |
213 | return 0; | 214 | return 0; |
diff --git a/src/testbed/test_testbed_api_sd.c b/src/testbed/test_testbed_api_sd.c index 1a7b4adbd..81b8dba41 100644 --- a/src/testbed/test_testbed_api_sd.c +++ b/src/testbed/test_testbed_api_sd.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -43,47 +43,47 @@ static int ret; | |||
43 | * @param cfg the configuration file handle | 43 | * @param cfg the configuration file handle |
44 | */ | 44 | */ |
45 | static void | 45 | static void |
46 | run (void *cls, char *const *args, const char *cfgfile, | 46 | run(void *cls, char *const *args, const char *cfgfile, |
47 | const struct GNUNET_CONFIGURATION_Handle *config) | 47 | const struct GNUNET_CONFIGURATION_Handle *config) |
48 | { | 48 | { |
49 | struct SDHandle *h = GNUNET_TESTBED_SD_init_ (20); | 49 | struct SDHandle *h = GNUNET_TESTBED_SD_init_(20); |
50 | int sd; | 50 | int sd; |
51 | 51 | ||
52 | ret = 0; | 52 | ret = 0; |
53 | GNUNET_TESTBED_SD_add_data_ (h, 40); | 53 | GNUNET_TESTBED_SD_add_data_(h, 40); |
54 | if (GNUNET_SYSERR != GNUNET_TESTBED_SD_deviation_factor_ (h, 10, &sd)) | 54 | if (GNUNET_SYSERR != GNUNET_TESTBED_SD_deviation_factor_(h, 10, &sd)) |
55 | { | 55 | { |
56 | GNUNET_break (0); | 56 | GNUNET_break(0); |
57 | ret = 1; | 57 | ret = 1; |
58 | goto err; | 58 | goto err; |
59 | } | 59 | } |
60 | GNUNET_TESTBED_SD_add_data_ (h, 30); | 60 | GNUNET_TESTBED_SD_add_data_(h, 30); |
61 | if (GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 80, &sd)) | 61 | if (GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_(h, 80, &sd)) |
62 | { | 62 | { |
63 | GNUNET_break (0); | 63 | GNUNET_break(0); |
64 | ret = 1; | 64 | ret = 1; |
65 | goto err; | 65 | goto err; |
66 | } | 66 | } |
67 | GNUNET_TESTBED_SD_add_data_ (h, 40); | 67 | GNUNET_TESTBED_SD_add_data_(h, 40); |
68 | if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 30, &sd)) | 68 | if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_(h, 30, &sd)) |
69 | || (-2 != sd)) | 69 | || (-2 != sd)) |
70 | { | 70 | { |
71 | GNUNET_break (0); | 71 | GNUNET_break(0); |
72 | ret = 1; | 72 | ret = 1; |
73 | goto err; | 73 | goto err; |
74 | } | 74 | } |
75 | GNUNET_TESTBED_SD_add_data_ (h, 10); | 75 | GNUNET_TESTBED_SD_add_data_(h, 10); |
76 | GNUNET_TESTBED_SD_add_data_ (h, 30); | 76 | GNUNET_TESTBED_SD_add_data_(h, 30); |
77 | if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_ (h, 60, &sd)) | 77 | if ((GNUNET_SYSERR == GNUNET_TESTBED_SD_deviation_factor_(h, 60, &sd)) |
78 | || (3 != sd)) | 78 | || (3 != sd)) |
79 | { | 79 | { |
80 | GNUNET_break (0); | 80 | GNUNET_break(0); |
81 | ret = 1; | 81 | ret = 1; |
82 | goto err; | 82 | goto err; |
83 | } | 83 | } |
84 | 84 | ||
85 | err: | 85 | err: |
86 | GNUNET_TESTBED_SD_destroy_ (h); | 86 | GNUNET_TESTBED_SD_destroy_(h); |
87 | } | 87 | } |
88 | 88 | ||
89 | 89 | ||
@@ -91,7 +91,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
91 | * Main function | 91 | * Main function |
92 | */ | 92 | */ |
93 | int | 93 | int |
94 | main (int argc, char **argv) | 94 | main(int argc, char **argv) |
95 | { | 95 | { |
96 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 96 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
97 | GNUNET_GETOPT_OPTION_END | 97 | GNUNET_GETOPT_OPTION_END |
@@ -100,8 +100,8 @@ main (int argc, char **argv) | |||
100 | 100 | ||
101 | result = GNUNET_SYSERR; | 101 | result = GNUNET_SYSERR; |
102 | result = | 102 | result = |
103 | GNUNET_PROGRAM_run (argc, argv, | 103 | GNUNET_PROGRAM_run(argc, argv, |
104 | "test_testbed_api_sd", "nohelp", options, &run, NULL); | 104 | "test_testbed_api_sd", "nohelp", options, &run, NULL); |
105 | if ((GNUNET_OK != result)) | 105 | if ((GNUNET_OK != result)) |
106 | return 1; | 106 | return 1; |
107 | return ret; | 107 | return ret; |
diff --git a/src/testbed/test_testbed_api_statistics.c b/src/testbed/test_testbed_api_statistics.c index 6d1673cef..26f90cfff 100644 --- a/src/testbed/test_testbed_api_statistics.c +++ b/src/testbed/test_testbed_api_statistics.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -46,7 +46,7 @@ static struct GNUNET_TESTBED_Operation *op; | |||
46 | /** | 46 | /** |
47 | * dummy pointer | 47 | * dummy pointer |
48 | */ | 48 | */ |
49 | static void *dummy_cls = (void *) 0xDEAD0001; | 49 | static void *dummy_cls = (void *)0xDEAD0001; |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * Abort task identifier | 52 | * Abort task identifier |
@@ -73,13 +73,13 @@ static unsigned int num_seen_peers; | |||
73 | * Fail testcase | 73 | * Fail testcase |
74 | */ | 74 | */ |
75 | #define FAIL_TEST(cond, ret) do { \ | 75 | #define FAIL_TEST(cond, ret) do { \ |
76 | if (!(cond)) { \ | 76 | if (!(cond)) { \ |
77 | GNUNET_break(0); \ | 77 | GNUNET_break(0); \ |
78 | if (NULL != abort_task) \ | 78 | if (NULL != abort_task) \ |
79 | GNUNET_SCHEDULER_cancel (abort_task); \ | 79 | GNUNET_SCHEDULER_cancel (abort_task); \ |
80 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \ | 80 | abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); \ |
81 | ret; \ | 81 | ret; \ |
82 | } \ | 82 | } \ |
83 | } while (0) | 83 | } while (0) |
84 | 84 | ||
85 | 85 | ||
@@ -89,15 +89,15 @@ static unsigned int num_seen_peers; | |||
89 | * @param cls NULL | 89 | * @param cls NULL |
90 | */ | 90 | */ |
91 | static void | 91 | static void |
92 | do_abort (void *cls) | 92 | do_abort(void *cls) |
93 | { | 93 | { |
94 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test timed out -- Aborting\n"); | 94 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Test timed out -- Aborting\n"); |
95 | abort_task = NULL; | 95 | abort_task = NULL; |
96 | if (NULL != op) | 96 | if (NULL != op) |
97 | { | 97 | { |
98 | GNUNET_TESTBED_operation_done (op); | 98 | GNUNET_TESTBED_operation_done(op); |
99 | op = NULL; | 99 | op = NULL; |
100 | } | 100 | } |
101 | result = GNUNET_SYSERR; | 101 | result = GNUNET_SYSERR; |
102 | } | 102 | } |
103 | 103 | ||
@@ -114,20 +114,20 @@ do_abort (void *cls) | |||
114 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | 114 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration |
115 | */ | 115 | */ |
116 | static int | 116 | static int |
117 | stats_iterator (void *cls, | 117 | stats_iterator(void *cls, |
118 | const struct GNUNET_TESTBED_Peer *peer, | 118 | const struct GNUNET_TESTBED_Peer *peer, |
119 | const char *subsystem, const char *name, uint64_t value, | 119 | const char *subsystem, const char *name, uint64_t value, |
120 | int is_persistent) | 120 | int is_persistent) |
121 | { | 121 | { |
122 | unsigned int cnt; | 122 | unsigned int cnt; |
123 | 123 | ||
124 | FAIL_TEST (cls == dummy_cls, return GNUNET_SYSERR); | 124 | FAIL_TEST(cls == dummy_cls, return GNUNET_SYSERR); |
125 | for (cnt = 0; cnt < num_seen_peers; cnt++) | 125 | for (cnt = 0; cnt < num_seen_peers; cnt++) |
126 | FAIL_TEST (peer != seen_peers[cnt], return GNUNET_SYSERR); | 126 | FAIL_TEST(peer != seen_peers[cnt], return GNUNET_SYSERR); |
127 | FAIL_TEST (NULL != subsystem, return GNUNET_SYSERR); | 127 | FAIL_TEST(NULL != subsystem, return GNUNET_SYSERR); |
128 | FAIL_TEST (NULL != name, return GNUNET_SYSERR); | 128 | FAIL_TEST(NULL != name, return GNUNET_SYSERR); |
129 | GNUNET_array_append (seen_peers, num_seen_peers, | 129 | GNUNET_array_append(seen_peers, num_seen_peers, |
130 | (struct GNUNET_TESTBED_Peer *) peer); | 130 | (struct GNUNET_TESTBED_Peer *)peer); |
131 | return GNUNET_SYSERR; | 131 | return GNUNET_SYSERR; |
132 | } | 132 | } |
133 | 133 | ||
@@ -141,16 +141,16 @@ stats_iterator (void *cls, | |||
141 | * operation has executed successfully. | 141 | * operation has executed successfully. |
142 | */ | 142 | */ |
143 | static void | 143 | static void |
144 | op_comp_cb (void *cls, | 144 | op_comp_cb(void *cls, |
145 | struct GNUNET_TESTBED_Operation *op, | 145 | struct GNUNET_TESTBED_Operation *op, |
146 | const char *emsg) | 146 | const char *emsg) |
147 | { | 147 | { |
148 | FAIL_TEST (cls == dummy_cls, return); | 148 | FAIL_TEST(cls == dummy_cls, return ); |
149 | result = GNUNET_OK; | 149 | result = GNUNET_OK; |
150 | GNUNET_TESTBED_operation_done (op); | 150 | GNUNET_TESTBED_operation_done(op); |
151 | op = NULL; | 151 | op = NULL; |
152 | GNUNET_SCHEDULER_cancel (abort_task); | 152 | GNUNET_SCHEDULER_cancel(abort_task); |
153 | GNUNET_SCHEDULER_shutdown (); | 153 | GNUNET_SCHEDULER_shutdown(); |
154 | } | 154 | } |
155 | 155 | ||
156 | 156 | ||
@@ -167,23 +167,23 @@ op_comp_cb (void *cls, | |||
167 | * failed | 167 | * failed |
168 | */ | 168 | */ |
169 | static void | 169 | static void |
170 | test_master (void *cls, | 170 | test_master(void *cls, |
171 | struct GNUNET_TESTBED_RunHandle *h, | 171 | struct GNUNET_TESTBED_RunHandle *h, |
172 | unsigned int num_peers, | 172 | unsigned int num_peers, |
173 | struct GNUNET_TESTBED_Peer **peers_, | 173 | struct GNUNET_TESTBED_Peer **peers_, |
174 | unsigned int links_succeeded, | 174 | unsigned int links_succeeded, |
175 | unsigned int links_failed) | 175 | unsigned int links_failed) |
176 | { | 176 | { |
177 | FAIL_TEST (NUM_PEERS == num_peers, return); | 177 | FAIL_TEST(NUM_PEERS == num_peers, return ); |
178 | peers = peers_; | 178 | peers = peers_; |
179 | op = GNUNET_TESTBED_get_statistics (num_peers, peers, | 179 | op = GNUNET_TESTBED_get_statistics(num_peers, peers, |
180 | NULL, NULL, | 180 | NULL, NULL, |
181 | &stats_iterator, | 181 | &stats_iterator, |
182 | &op_comp_cb, | 182 | &op_comp_cb, |
183 | dummy_cls); | 183 | dummy_cls); |
184 | abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 184 | abort_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
185 | (GNUNET_TIME_UNIT_MINUTES, 1), | 185 | (GNUNET_TIME_UNIT_MINUTES, 1), |
186 | &do_abort, NULL); | 186 | &do_abort, NULL); |
187 | } | 187 | } |
188 | 188 | ||
189 | 189 | ||
@@ -191,14 +191,14 @@ test_master (void *cls, | |||
191 | * Main function | 191 | * Main function |
192 | */ | 192 | */ |
193 | int | 193 | int |
194 | main (int argc, char **argv) | 194 | main(int argc, char **argv) |
195 | { | 195 | { |
196 | (void) GNUNET_TESTBED_test_run ("test_testbed_api_statistics", | 196 | (void)GNUNET_TESTBED_test_run("test_testbed_api_statistics", |
197 | "test_testbed_api_statistics.conf", | 197 | "test_testbed_api_statistics.conf", |
198 | NUM_PEERS, | 198 | NUM_PEERS, |
199 | 1LL, NULL, NULL, | 199 | 1LL, NULL, NULL, |
200 | &test_master, NULL); | 200 | &test_master, NULL); |
201 | GNUNET_free_non_null (seen_peers); | 201 | GNUNET_free_non_null(seen_peers); |
202 | if (GNUNET_OK != result) | 202 | if (GNUNET_OK != result) |
203 | return 1; | 203 | return 1; |
204 | return 0; | 204 | return 0; |
diff --git a/src/testbed/test_testbed_api_test.c b/src/testbed/test_testbed_api_test.c index 372ac1ebe..3f8f536e7 100644 --- a/src/testbed/test_testbed_api_test.c +++ b/src/testbed/test_testbed_api_test.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2008--2013 GNUnet e.V. | 3 | Copyright (C) 2008--2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file src/testbed/test_testbed_api_test.c | 22 | * @file src/testbed/test_testbed_api_test.c |
@@ -32,8 +32,8 @@ | |||
32 | /** | 32 | /** |
33 | * Generic logging shortcut | 33 | * Generic logging shortcut |
34 | */ | 34 | */ |
35 | #define LOG(kind,...) \ | 35 | #define LOG(kind, ...) \ |
36 | GNUNET_log (kind, __VA_ARGS__) | 36 | GNUNET_log(kind, __VA_ARGS__) |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Number of peers we want to start | 39 | * Number of peers we want to start |
@@ -72,29 +72,29 @@ static int result; | |||
72 | * @param cls NULL | 72 | * @param cls NULL |
73 | */ | 73 | */ |
74 | static void | 74 | static void |
75 | do_shutdown (void *cls) | 75 | do_shutdown(void *cls) |
76 | { | 76 | { |
77 | shutdown_task = NULL; | 77 | shutdown_task = NULL; |
78 | if (NULL != abort_task) | 78 | if (NULL != abort_task) |
79 | GNUNET_SCHEDULER_cancel (abort_task); | 79 | GNUNET_SCHEDULER_cancel(abort_task); |
80 | if (NULL != op) | 80 | if (NULL != op) |
81 | GNUNET_TESTBED_operation_done (op); | 81 | GNUNET_TESTBED_operation_done(op); |
82 | GNUNET_SCHEDULER_shutdown (); | 82 | GNUNET_SCHEDULER_shutdown(); |
83 | } | 83 | } |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * shortcut to exit during failure | 86 | * shortcut to exit during failure |
87 | */ | 87 | */ |
88 | #define FAIL_TEST(cond) do { \ | 88 | #define FAIL_TEST(cond) do { \ |
89 | if (!(cond)) { \ | 89 | if (!(cond)) { \ |
90 | GNUNET_break(0); \ | 90 | GNUNET_break(0); \ |
91 | if (NULL != abort_task) \ | 91 | if (NULL != abort_task) \ |
92 | GNUNET_SCHEDULER_cancel (abort_task); \ | 92 | GNUNET_SCHEDULER_cancel (abort_task); \ |
93 | abort_task = NULL; \ | 93 | abort_task = NULL; \ |
94 | if (NULL == shutdown_task) \ | 94 | if (NULL == shutdown_task) \ |
95 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); \ | 95 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); \ |
96 | return; \ | 96 | return; \ |
97 | } \ | 97 | } \ |
98 | } while (0) | 98 | } while (0) |
99 | 99 | ||
100 | 100 | ||
@@ -104,13 +104,13 @@ do_shutdown (void *cls) | |||
104 | * @param cls NULL | 104 | * @param cls NULL |
105 | */ | 105 | */ |
106 | static void | 106 | static void |
107 | do_abort (void *cls) | 107 | do_abort(void *cls) |
108 | { | 108 | { |
109 | LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); | 109 | LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); |
110 | abort_task = NULL; | 110 | abort_task = NULL; |
111 | if (NULL != shutdown_task) | 111 | if (NULL != shutdown_task) |
112 | GNUNET_SCHEDULER_cancel (shutdown_task); | 112 | GNUNET_SCHEDULER_cancel(shutdown_task); |
113 | do_shutdown (cls); | 113 | do_shutdown(cls); |
114 | } | 114 | } |
115 | 115 | ||
116 | 116 | ||
@@ -124,19 +124,19 @@ do_abort (void *cls) | |||
124 | * operation is successfull | 124 | * operation is successfull |
125 | */ | 125 | */ |
126 | static void | 126 | static void |
127 | peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_, | 127 | peerinfo_cb(void *cb_cls, struct GNUNET_TESTBED_Operation *op_, |
128 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | 128 | const struct GNUNET_TESTBED_PeerInformation *pinfo, |
129 | const char *emsg) | 129 | const char *emsg) |
130 | { | 130 | { |
131 | FAIL_TEST (op == op_); | 131 | FAIL_TEST(op == op_); |
132 | FAIL_TEST (NULL == cb_cls); | 132 | FAIL_TEST(NULL == cb_cls); |
133 | FAIL_TEST (NULL == emsg); | 133 | FAIL_TEST(NULL == emsg); |
134 | FAIL_TEST (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit); | 134 | FAIL_TEST(GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit); |
135 | FAIL_TEST (NULL != pinfo->result.id); | 135 | FAIL_TEST(NULL != pinfo->result.id); |
136 | GNUNET_TESTBED_operation_done (op); | 136 | GNUNET_TESTBED_operation_done(op); |
137 | op = NULL; | 137 | op = NULL; |
138 | result = GNUNET_OK; | 138 | result = GNUNET_OK; |
139 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 139 | shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
140 | } | 140 | } |
141 | 141 | ||
142 | 142 | ||
@@ -149,19 +149,19 @@ peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_, | |||
149 | * operation has executed successfully. | 149 | * operation has executed successfully. |
150 | */ | 150 | */ |
151 | static void | 151 | static void |
152 | op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg) | 152 | op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg) |
153 | { | 153 | { |
154 | FAIL_TEST (NULL == cls); | 154 | FAIL_TEST(NULL == cls); |
155 | FAIL_TEST (op == op_); | 155 | FAIL_TEST(op == op_); |
156 | if (NULL != emsg) | 156 | if (NULL != emsg) |
157 | { | 157 | { |
158 | LOG (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg); | 158 | LOG(GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg); |
159 | FAIL_TEST (0); | 159 | FAIL_TEST(0); |
160 | } | 160 | } |
161 | GNUNET_TESTBED_operation_done (op); | 161 | GNUNET_TESTBED_operation_done(op); |
162 | op = GNUNET_TESTBED_peer_get_information (peers[0], | 162 | op = GNUNET_TESTBED_peer_get_information(peers[0], |
163 | GNUNET_TESTBED_PIT_IDENTITY, | 163 | GNUNET_TESTBED_PIT_IDENTITY, |
164 | &peerinfo_cb, NULL); | 164 | &peerinfo_cb, NULL); |
165 | } | 165 | } |
166 | 166 | ||
167 | 167 | ||
@@ -172,18 +172,19 @@ op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg) | |||
172 | * @param event the controller event | 172 | * @param event the controller event |
173 | */ | 173 | */ |
174 | static void | 174 | static void |
175 | controller_event_cb (void *cls, | 175 | controller_event_cb(void *cls, |
176 | const struct GNUNET_TESTBED_EventInformation *event) | 176 | const struct GNUNET_TESTBED_EventInformation *event) |
177 | { | 177 | { |
178 | switch (event->type) | 178 | switch (event->type) |
179 | { | 179 | { |
180 | case GNUNET_TESTBED_ET_CONNECT: | 180 | case GNUNET_TESTBED_ET_CONNECT: |
181 | FAIL_TEST (event->details.peer_connect.peer1 == peers[0]); | 181 | FAIL_TEST(event->details.peer_connect.peer1 == peers[0]); |
182 | FAIL_TEST (event->details.peer_connect.peer2 == peers[1]); | 182 | FAIL_TEST(event->details.peer_connect.peer2 == peers[1]); |
183 | break; | 183 | break; |
184 | default: | 184 | |
185 | FAIL_TEST (0); | 185 | default: |
186 | } | 186 | FAIL_TEST(0); |
187 | } | ||
187 | } | 188 | } |
188 | 189 | ||
189 | 190 | ||
@@ -200,27 +201,27 @@ controller_event_cb (void *cls, | |||
200 | * failed | 201 | * failed |
201 | */ | 202 | */ |
202 | static void | 203 | static void |
203 | test_master (void *cls, | 204 | test_master(void *cls, |
204 | struct GNUNET_TESTBED_RunHandle *h, | 205 | struct GNUNET_TESTBED_RunHandle *h, |
205 | unsigned int num_peers, | 206 | unsigned int num_peers, |
206 | struct GNUNET_TESTBED_Peer **peers_, | 207 | struct GNUNET_TESTBED_Peer **peers_, |
207 | unsigned int links_succeeded, | 208 | unsigned int links_succeeded, |
208 | unsigned int links_failed) | 209 | unsigned int links_failed) |
209 | { | 210 | { |
210 | unsigned int peer; | 211 | unsigned int peer; |
211 | 212 | ||
212 | FAIL_TEST (NULL == cls); | 213 | FAIL_TEST(NULL == cls); |
213 | FAIL_TEST (NUM_PEERS == num_peers); | 214 | FAIL_TEST(NUM_PEERS == num_peers); |
214 | FAIL_TEST (NULL != peers_); | 215 | FAIL_TEST(NULL != peers_); |
215 | for (peer = 0; peer < num_peers; peer++) | 216 | for (peer = 0; peer < num_peers; peer++) |
216 | FAIL_TEST (NULL != peers_[peer]); | 217 | FAIL_TEST(NULL != peers_[peer]); |
217 | peers = peers_; | 218 | peers = peers_; |
218 | op = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peers[0], | 219 | op = GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peers[0], |
219 | peers[1]); | 220 | peers[1]); |
220 | abort_task = | 221 | abort_task = |
221 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 222 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
222 | (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, | 223 | (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, |
223 | NULL); | 224 | NULL); |
224 | } | 225 | } |
225 | 226 | ||
226 | 227 | ||
@@ -228,7 +229,7 @@ test_master (void *cls, | |||
228 | * Main function | 229 | * Main function |
229 | */ | 230 | */ |
230 | int | 231 | int |
231 | main (int argc, char **argv) | 232 | main(int argc, char **argv) |
232 | { | 233 | { |
233 | uint64_t event_mask; | 234 | uint64_t event_mask; |
234 | 235 | ||
@@ -236,10 +237,10 @@ main (int argc, char **argv) | |||
236 | event_mask = 0; | 237 | event_mask = 0; |
237 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | 238 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); |
238 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 239 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
239 | (void) GNUNET_TESTBED_test_run ("test_testbed_api_test", | 240 | (void)GNUNET_TESTBED_test_run("test_testbed_api_test", |
240 | "test_testbed_api.conf", NUM_PEERS, | 241 | "test_testbed_api.conf", NUM_PEERS, |
241 | event_mask, &controller_event_cb, NULL, | 242 | event_mask, &controller_event_cb, NULL, |
242 | &test_master, NULL); | 243 | &test_master, NULL); |
243 | if (GNUNET_OK != result) | 244 | if (GNUNET_OK != result) |
244 | return 1; | 245 | return 1; |
245 | return 0; | 246 | return 0; |
diff --git a/src/testbed/test_testbed_api_test_timeout.c b/src/testbed/test_testbed_api_test_timeout.c index 68233e207..c5cfea7c0 100644 --- a/src/testbed/test_testbed_api_test_timeout.c +++ b/src/testbed/test_testbed_api_test_timeout.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2008--2013 GNUnet e.V. | 3 | Copyright (C) 2008--2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file src/testbed/test_testbed_api_test.c | 22 | * @file src/testbed/test_testbed_api_test.c |
@@ -34,8 +34,8 @@ | |||
34 | /** | 34 | /** |
35 | * Generic logging shortcut | 35 | * Generic logging shortcut |
36 | */ | 36 | */ |
37 | #define LOG(kind,...) \ | 37 | #define LOG(kind, ...) \ |
38 | GNUNET_log (kind, __VA_ARGS__) | 38 | GNUNET_log(kind, __VA_ARGS__) |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Number of peers we want to start | 41 | * Number of peers we want to start |
@@ -52,11 +52,11 @@ static int result; | |||
52 | * shortcut to exit during failure | 52 | * shortcut to exit during failure |
53 | */ | 53 | */ |
54 | #define FAIL_TEST(cond) do { \ | 54 | #define FAIL_TEST(cond) do { \ |
55 | if (!(cond)) { \ | 55 | if (!(cond)) { \ |
56 | GNUNET_break(0); \ | 56 | GNUNET_break(0); \ |
57 | GNUNET_SCHEDULER_shutdown (); \ | 57 | GNUNET_SCHEDULER_shutdown(); \ |
58 | return; \ | 58 | return; \ |
59 | } \ | 59 | } \ |
60 | } while (0) | 60 | } while (0) |
61 | 61 | ||
62 | 62 | ||
@@ -67,10 +67,10 @@ static int result; | |||
67 | * @param event the controller event | 67 | * @param event the controller event |
68 | */ | 68 | */ |
69 | static void | 69 | static void |
70 | controller_event_cb (void *cls, | 70 | controller_event_cb(void *cls, |
71 | const struct GNUNET_TESTBED_EventInformation *event) | 71 | const struct GNUNET_TESTBED_EventInformation *event) |
72 | { | 72 | { |
73 | FAIL_TEST (0); | 73 | FAIL_TEST(0); |
74 | } | 74 | } |
75 | 75 | ||
76 | 76 | ||
@@ -87,18 +87,18 @@ controller_event_cb (void *cls, | |||
87 | * failed | 87 | * failed |
88 | */ | 88 | */ |
89 | static void | 89 | static void |
90 | test_master (void *cls, | 90 | test_master(void *cls, |
91 | struct GNUNET_TESTBED_RunHandle *h, | 91 | struct GNUNET_TESTBED_RunHandle *h, |
92 | unsigned int num_peers, | 92 | unsigned int num_peers, |
93 | struct GNUNET_TESTBED_Peer **peers_, | 93 | struct GNUNET_TESTBED_Peer **peers_, |
94 | unsigned int links_succeeded, | 94 | unsigned int links_succeeded, |
95 | unsigned int links_failed) | 95 | unsigned int links_failed) |
96 | { | 96 | { |
97 | FAIL_TEST (NULL == cls); | 97 | FAIL_TEST(NULL == cls); |
98 | FAIL_TEST (0 == num_peers); | 98 | FAIL_TEST(0 == num_peers); |
99 | FAIL_TEST (NULL == peers_); | 99 | FAIL_TEST(NULL == peers_); |
100 | result = GNUNET_OK; | 100 | result = GNUNET_OK; |
101 | GNUNET_SCHEDULER_shutdown (); | 101 | GNUNET_SCHEDULER_shutdown(); |
102 | } | 102 | } |
103 | 103 | ||
104 | 104 | ||
@@ -106,16 +106,16 @@ test_master (void *cls, | |||
106 | * Main function | 106 | * Main function |
107 | */ | 107 | */ |
108 | int | 108 | int |
109 | main (int argc, char **argv) | 109 | main(int argc, char **argv) |
110 | { | 110 | { |
111 | uint64_t event_mask; | 111 | uint64_t event_mask; |
112 | 112 | ||
113 | result = GNUNET_SYSERR; | 113 | result = GNUNET_SYSERR; |
114 | event_mask = 0; | 114 | event_mask = 0; |
115 | (void) GNUNET_TESTBED_test_run ("test_testbed_api_test", | 115 | (void)GNUNET_TESTBED_test_run("test_testbed_api_test", |
116 | "test_testbed_api_test_timeout.conf", NUM_PEERS, | 116 | "test_testbed_api_test_timeout.conf", NUM_PEERS, |
117 | event_mask, &controller_event_cb, NULL, | 117 | event_mask, &controller_event_cb, NULL, |
118 | &test_master, NULL); | 118 | &test_master, NULL); |
119 | if (GNUNET_OK != result) | 119 | if (GNUNET_OK != result) |
120 | return 1; | 120 | return 1; |
121 | return 0; | 121 | return 0; |
diff --git a/src/testbed/test_testbed_api_testbed_run.c b/src/testbed/test_testbed_api_testbed_run.c index 27f5b13e7..39bc9bfe7 100644 --- a/src/testbed/test_testbed_api_testbed_run.c +++ b/src/testbed/test_testbed_api_testbed_run.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2008--2013 GNUnet e.V. | 3 | Copyright (C) 2008--2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/test_testbed_api_testbed_run.c | 22 | * @file testbed/test_testbed_api_testbed_run.c |
@@ -70,11 +70,11 @@ static int wait_forever; | |||
70 | * @param cls NULL | 70 | * @param cls NULL |
71 | */ | 71 | */ |
72 | static void | 72 | static void |
73 | do_shutdown (void *cls) | 73 | do_shutdown(void *cls) |
74 | { | 74 | { |
75 | if (NULL != abort_task) | 75 | if (NULL != abort_task) |
76 | GNUNET_SCHEDULER_cancel (abort_task); | 76 | GNUNET_SCHEDULER_cancel(abort_task); |
77 | GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */ | 77 | GNUNET_SCHEDULER_shutdown(); /* Stop scheduler to shutdown testbed run */ |
78 | } | 78 | } |
79 | 79 | ||
80 | 80 | ||
@@ -84,12 +84,12 @@ do_shutdown (void *cls) | |||
84 | * @param cls NULL | 84 | * @param cls NULL |
85 | */ | 85 | */ |
86 | static void | 86 | static void |
87 | do_abort (void *cls) | 87 | do_abort(void *cls) |
88 | { | 88 | { |
89 | abort_task = NULL; | 89 | abort_task = NULL; |
90 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 90 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
91 | "Test timed out -- Aborting\n"); | 91 | "Test timed out -- Aborting\n"); |
92 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 92 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
93 | } | 93 | } |
94 | 94 | ||
95 | 95 | ||
@@ -106,26 +106,26 @@ do_abort (void *cls) | |||
106 | * failed | 106 | * failed |
107 | */ | 107 | */ |
108 | static void | 108 | static void |
109 | test_master (void *cls, | 109 | test_master(void *cls, |
110 | struct GNUNET_TESTBED_RunHandle *h, | 110 | struct GNUNET_TESTBED_RunHandle *h, |
111 | unsigned int num_peers, | 111 | unsigned int num_peers, |
112 | struct GNUNET_TESTBED_Peer **peers_, | 112 | struct GNUNET_TESTBED_Peer **peers_, |
113 | unsigned int links_succeeded, | 113 | unsigned int links_succeeded, |
114 | unsigned int links_failed) | 114 | unsigned int links_failed) |
115 | { | 115 | { |
116 | result = GNUNET_OK; | 116 | result = GNUNET_OK; |
117 | if (GNUNET_YES == wait_forever) | 117 | if (GNUNET_YES == wait_forever) |
118 | { | 118 | { |
119 | if (NULL == abort_task) | 119 | if (NULL == abort_task) |
120 | return; /* abort already scheduled */ | 120 | return; /* abort already scheduled */ |
121 | GNUNET_SCHEDULER_cancel (abort_task); | 121 | GNUNET_SCHEDULER_cancel(abort_task); |
122 | abort_task = NULL; | 122 | abort_task = NULL; |
123 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 123 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
124 | return; | 124 | return; |
125 | } | 125 | } |
126 | GNUNET_assert (NULL != peers[0]); | 126 | GNUNET_assert(NULL != peers[0]); |
127 | op = GNUNET_TESTBED_peer_stop (NULL, peers[0], NULL, NULL); | 127 | op = GNUNET_TESTBED_peer_stop(NULL, peers[0], NULL, NULL); |
128 | GNUNET_assert (NULL != op); | 128 | GNUNET_assert(NULL != op); |
129 | } | 129 | } |
130 | 130 | ||
131 | 131 | ||
@@ -136,26 +136,27 @@ test_master (void *cls, | |||
136 | * @param event the controller event | 136 | * @param event the controller event |
137 | */ | 137 | */ |
138 | static void | 138 | static void |
139 | controller_event_cb (void *cls, | 139 | controller_event_cb(void *cls, |
140 | const struct GNUNET_TESTBED_EventInformation *event) | 140 | const struct GNUNET_TESTBED_EventInformation *event) |
141 | { | 141 | { |
142 | |||
143 | switch (event->type) | 142 | switch (event->type) |
144 | { | 143 | { |
145 | case GNUNET_TESTBED_ET_PEER_START: | 144 | case GNUNET_TESTBED_ET_PEER_START: |
146 | GNUNET_assert (NULL == peers[peer_id]); | 145 | GNUNET_assert(NULL == peers[peer_id]); |
147 | GNUNET_assert (NULL != event->details.peer_start.peer); | 146 | GNUNET_assert(NULL != event->details.peer_start.peer); |
148 | peers[peer_id++] = event->details.peer_start.peer; | 147 | peers[peer_id++] = event->details.peer_start.peer; |
149 | break; | 148 | break; |
150 | case GNUNET_TESTBED_ET_PEER_STOP: | 149 | |
151 | GNUNET_assert (NULL != op); | 150 | case GNUNET_TESTBED_ET_PEER_STOP: |
152 | GNUNET_TESTBED_operation_done (op); | 151 | GNUNET_assert(NULL != op); |
153 | GNUNET_assert (peers[0] == event->details.peer_stop.peer); | 152 | GNUNET_TESTBED_operation_done(op); |
154 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 153 | GNUNET_assert(peers[0] == event->details.peer_stop.peer); |
155 | break; | 154 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
156 | default: | 155 | break; |
157 | GNUNET_assert (0); | 156 | |
158 | } | 157 | default: |
158 | GNUNET_assert(0); | ||
159 | } | ||
159 | } | 160 | } |
160 | 161 | ||
161 | 162 | ||
@@ -168,24 +169,24 @@ controller_event_cb (void *cls, | |||
168 | * @param cfg the configuration file handle | 169 | * @param cfg the configuration file handle |
169 | */ | 170 | */ |
170 | static void | 171 | static void |
171 | run (void *cls, | 172 | run(void *cls, |
172 | char *const *args, | 173 | char *const *args, |
173 | const char *cfgfile, | 174 | const char *cfgfile, |
174 | const struct GNUNET_CONFIGURATION_Handle *config) | 175 | const struct GNUNET_CONFIGURATION_Handle *config) |
175 | { | 176 | { |
176 | uint64_t event_mask; | 177 | uint64_t event_mask; |
177 | 178 | ||
178 | event_mask = 0; | 179 | event_mask = 0; |
179 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); | 180 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); |
180 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); | 181 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); |
181 | GNUNET_TESTBED_run (NULL, config, NUM_PEERS, event_mask, | 182 | GNUNET_TESTBED_run(NULL, config, NUM_PEERS, event_mask, |
182 | &controller_event_cb, NULL, | 183 | &controller_event_cb, NULL, |
183 | &test_master, NULL); | 184 | &test_master, NULL); |
184 | abort_task = | 185 | abort_task = |
185 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 186 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
186 | (GNUNET_TIME_UNIT_SECONDS, 300), | 187 | (GNUNET_TIME_UNIT_SECONDS, 300), |
187 | &do_abort, | 188 | &do_abort, |
188 | NULL); | 189 | NULL); |
189 | } | 190 | } |
190 | 191 | ||
191 | 192 | ||
@@ -193,7 +194,7 @@ run (void *cls, | |||
193 | * Main function | 194 | * Main function |
194 | */ | 195 | */ |
195 | int | 196 | int |
196 | main (int argc, char **argv) | 197 | main(int argc, char **argv) |
197 | { | 198 | { |
198 | char *argv2[] = { | 199 | char *argv2[] = { |
199 | "test_testbed_api_testbed_run", | 200 | "test_testbed_api_testbed_run", |
@@ -207,42 +208,42 @@ main (int argc, char **argv) | |||
207 | char *config_filename; | 208 | char *config_filename; |
208 | int ret; | 209 | int ret; |
209 | 210 | ||
210 | if (NULL == (testname = strrchr (argv[0], (int) '_'))) | 211 | if (NULL == (testname = strrchr(argv[0], (int)'_'))) |
211 | { | 212 | { |
212 | GNUNET_break (0); | 213 | GNUNET_break(0); |
213 | return 1; | 214 | return 1; |
214 | } | 215 | } |
215 | testname++; | 216 | testname++; |
216 | testname = GNUNET_strdup (testname); | 217 | testname = GNUNET_strdup(testname); |
217 | #ifdef MINGW | 218 | #ifdef MINGW |
218 | { | 219 | { |
219 | char *period; | 220 | char *period; |
220 | 221 | ||
221 | /* check and remove .exe extension */ | 222 | /* check and remove .exe extension */ |
222 | period = strrchr (testname, (int) '.'); | 223 | period = strrchr(testname, (int)'.'); |
223 | if (NULL != period) | 224 | if (NULL != period) |
224 | *period = '\0'; | 225 | *period = '\0'; |
225 | else | 226 | else |
226 | GNUNET_break (0); /* Windows with no .exe? */ | 227 | GNUNET_break(0); /* Windows with no .exe? */ |
227 | } | 228 | } |
228 | #endif | 229 | #endif |
229 | if (0 == strcmp ("waitforever", testname)) | 230 | if (0 == strcmp("waitforever", testname)) |
230 | wait_forever = GNUNET_YES; | 231 | wait_forever = GNUNET_YES; |
231 | if ( (GNUNET_YES != wait_forever) && (0 != strcmp ("run", testname)) ) | 232 | if ((GNUNET_YES != wait_forever) && (0 != strcmp("run", testname))) |
232 | { | 233 | { |
233 | GNUNET_asprintf (&config_filename, "test_testbed_api_testbed_run_%s.conf", | 234 | GNUNET_asprintf(&config_filename, "test_testbed_api_testbed_run_%s.conf", |
234 | testname); | 235 | testname); |
235 | } | 236 | } |
236 | else | 237 | else |
237 | config_filename = GNUNET_strdup ("test_testbed_api.conf"); | 238 | config_filename = GNUNET_strdup("test_testbed_api.conf"); |
238 | GNUNET_free (testname); | 239 | GNUNET_free(testname); |
239 | argv2[2] = config_filename; | 240 | argv2[2] = config_filename; |
240 | result = GNUNET_SYSERR; | 241 | result = GNUNET_SYSERR; |
241 | ret = | 242 | ret = |
242 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | 243 | GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, |
243 | "test_testbed_api_testbed_run", "nohelp", options, | 244 | "test_testbed_api_testbed_run", "nohelp", options, |
244 | &run, NULL); | 245 | &run, NULL); |
245 | GNUNET_free (config_filename); | 246 | GNUNET_free(config_filename); |
246 | if ((GNUNET_OK != ret) || (GNUNET_OK != result)) | 247 | if ((GNUNET_OK != ret) || (GNUNET_OK != result)) |
247 | return 1; | 248 | return 1; |
248 | return 0; | 249 | return 0; |
diff --git a/src/testbed/test_testbed_api_topology.c b/src/testbed/test_testbed_api_topology.c index d1b8da31a..c6e25c656 100644 --- a/src/testbed/test_testbed_api_topology.c +++ b/src/testbed/test_testbed_api_topology.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2008--2013 GNUnet e.V. | 3 | Copyright (C) 2008--2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file src/testbed/test_testbed_api_topology.c | 22 | * @file src/testbed/test_testbed_api_topology.c |
@@ -65,15 +65,15 @@ static unsigned int overlay_connects; | |||
65 | * @param cls NULL | 65 | * @param cls NULL |
66 | */ | 66 | */ |
67 | static void | 67 | static void |
68 | do_shutdown (void *cls) | 68 | do_shutdown(void *cls) |
69 | { | 69 | { |
70 | shutdown_task = NULL; | 70 | shutdown_task = NULL; |
71 | if (NULL != op) | 71 | if (NULL != op) |
72 | { | 72 | { |
73 | GNUNET_TESTBED_operation_done (op); | 73 | GNUNET_TESTBED_operation_done(op); |
74 | op = NULL; | 74 | op = NULL; |
75 | } | 75 | } |
76 | GNUNET_SCHEDULER_shutdown (); | 76 | GNUNET_SCHEDULER_shutdown(); |
77 | } | 77 | } |
78 | 78 | ||
79 | /** | 79 | /** |
@@ -83,34 +83,36 @@ do_shutdown (void *cls) | |||
83 | * @param event the controller event | 83 | * @param event the controller event |
84 | */ | 84 | */ |
85 | static void | 85 | static void |
86 | controller_event_cb (void *cls, | 86 | controller_event_cb(void *cls, |
87 | const struct GNUNET_TESTBED_EventInformation *event) | 87 | const struct GNUNET_TESTBED_EventInformation *event) |
88 | { | 88 | { |
89 | switch (event->type) | 89 | switch (event->type) |
90 | { | ||
91 | case GNUNET_TESTBED_ET_CONNECT: | ||
92 | overlay_connects++; | ||
93 | if ((NUM_PEERS) == overlay_connects) | ||
94 | { | 90 | { |
95 | result = GNUNET_OK; | 91 | case GNUNET_TESTBED_ET_CONNECT: |
96 | GNUNET_SCHEDULER_cancel (shutdown_task); | 92 | overlay_connects++; |
97 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 93 | if ((NUM_PEERS) == overlay_connects) |
94 | { | ||
95 | result = GNUNET_OK; | ||
96 | GNUNET_SCHEDULER_cancel(shutdown_task); | ||
97 | shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); | ||
98 | } | ||
99 | break; | ||
100 | |||
101 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
102 | GNUNET_assert(NULL != event->details.operation_finished.emsg); | ||
103 | break; | ||
104 | |||
105 | default: | ||
106 | GNUNET_break(0); | ||
107 | if ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) && | ||
108 | (NULL != event->details.operation_finished.emsg)) | ||
109 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
110 | "An operation failed with error: %s\n", | ||
111 | event->details.operation_finished.emsg); | ||
112 | result = GNUNET_SYSERR; | ||
113 | GNUNET_SCHEDULER_cancel(shutdown_task); | ||
114 | shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); | ||
98 | } | 115 | } |
99 | break; | ||
100 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
101 | GNUNET_assert (NULL != event->details.operation_finished.emsg); | ||
102 | break; | ||
103 | default: | ||
104 | GNUNET_break (0); | ||
105 | if ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) && | ||
106 | (NULL != event->details.operation_finished.emsg)) | ||
107 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
108 | "An operation failed with error: %s\n", | ||
109 | event->details.operation_finished.emsg); | ||
110 | result = GNUNET_SYSERR; | ||
111 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
112 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
113 | } | ||
114 | } | 116 | } |
115 | 117 | ||
116 | 118 | ||
@@ -127,37 +129,37 @@ controller_event_cb (void *cls, | |||
127 | * failed | 129 | * failed |
128 | */ | 130 | */ |
129 | static void | 131 | static void |
130 | test_master (void *cls, | 132 | test_master(void *cls, |
131 | struct GNUNET_TESTBED_RunHandle *h, | 133 | struct GNUNET_TESTBED_RunHandle *h, |
132 | unsigned int num_peers, | 134 | unsigned int num_peers, |
133 | struct GNUNET_TESTBED_Peer **peers_, | 135 | struct GNUNET_TESTBED_Peer **peers_, |
134 | unsigned int links_succeeded, | 136 | unsigned int links_succeeded, |
135 | unsigned int links_failed) | 137 | unsigned int links_failed) |
136 | { | 138 | { |
137 | unsigned int peer; | 139 | unsigned int peer; |
138 | 140 | ||
139 | GNUNET_assert (NULL == cls); | 141 | GNUNET_assert(NULL == cls); |
140 | if (NULL == peers_) | 142 | if (NULL == peers_) |
141 | { | 143 | { |
142 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n"); | 144 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n"); |
143 | return; | 145 | return; |
144 | } | 146 | } |
145 | GNUNET_assert (NUM_PEERS == num_peers); | 147 | GNUNET_assert(NUM_PEERS == num_peers); |
146 | for (peer = 0; peer < num_peers; peer++) | 148 | for (peer = 0; peer < num_peers; peer++) |
147 | GNUNET_assert (NULL != peers_[peer]); | 149 | GNUNET_assert(NULL != peers_[peer]); |
148 | peers = peers_; | 150 | peers = peers_; |
149 | overlay_connects = 0; | 151 | overlay_connects = 0; |
150 | op = GNUNET_TESTBED_overlay_configure_topology (NULL, NUM_PEERS, peers, NULL, | 152 | op = GNUNET_TESTBED_overlay_configure_topology(NULL, NUM_PEERS, peers, NULL, |
151 | NULL, | 153 | NULL, |
152 | NULL, | 154 | NULL, |
153 | GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, | 155 | GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, |
154 | NUM_PEERS, | 156 | NUM_PEERS, |
155 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); | 157 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); |
156 | GNUNET_assert (NULL != op); | 158 | GNUNET_assert(NULL != op); |
157 | shutdown_task = | 159 | shutdown_task = |
158 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 160 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
159 | (GNUNET_TIME_UNIT_SECONDS, 300), | 161 | (GNUNET_TIME_UNIT_SECONDS, 300), |
160 | do_shutdown, NULL); | 162 | do_shutdown, NULL); |
161 | } | 163 | } |
162 | 164 | ||
163 | 165 | ||
@@ -165,7 +167,7 @@ test_master (void *cls, | |||
165 | * Main function | 167 | * Main function |
166 | */ | 168 | */ |
167 | int | 169 | int |
168 | main (int argc, char **argv) | 170 | main(int argc, char **argv) |
169 | { | 171 | { |
170 | uint64_t event_mask; | 172 | uint64_t event_mask; |
171 | 173 | ||
@@ -173,10 +175,10 @@ main (int argc, char **argv) | |||
173 | event_mask = 0; | 175 | event_mask = 0; |
174 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | 176 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); |
175 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 177 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
176 | (void) GNUNET_TESTBED_test_run ("test_testbed_api_test", | 178 | (void)GNUNET_TESTBED_test_run("test_testbed_api_test", |
177 | "test_testbed_api.conf", NUM_PEERS, | 179 | "test_testbed_api.conf", NUM_PEERS, |
178 | event_mask, &controller_event_cb, NULL, | 180 | event_mask, &controller_event_cb, NULL, |
179 | &test_master, NULL); | 181 | &test_master, NULL); |
180 | if (GNUNET_OK != result) | 182 | if (GNUNET_OK != result) |
181 | return 1; | 183 | return 1; |
182 | return 0; | 184 | return 0; |
diff --git a/src/testbed/test_testbed_api_topology_clique.c b/src/testbed/test_testbed_api_topology_clique.c index 4cc34dfaf..866ec83c5 100644 --- a/src/testbed/test_testbed_api_topology_clique.c +++ b/src/testbed/test_testbed_api_topology_clique.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2008--2013 GNUnet e.V. | 3 | Copyright (C) 2008--2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file src/testbed/test_testbed_api_topology.c | 22 | * @file src/testbed/test_testbed_api_topology.c |
@@ -65,15 +65,15 @@ static unsigned int overlay_connects; | |||
65 | * @param cls NULL | 65 | * @param cls NULL |
66 | */ | 66 | */ |
67 | static void | 67 | static void |
68 | do_shutdown (void *cls) | 68 | do_shutdown(void *cls) |
69 | { | 69 | { |
70 | shutdown_task = NULL; | 70 | shutdown_task = NULL; |
71 | if (NULL != op) | 71 | if (NULL != op) |
72 | { | 72 | { |
73 | GNUNET_TESTBED_operation_done (op); | 73 | GNUNET_TESTBED_operation_done(op); |
74 | op = NULL; | 74 | op = NULL; |
75 | } | 75 | } |
76 | GNUNET_SCHEDULER_shutdown (); | 76 | GNUNET_SCHEDULER_shutdown(); |
77 | } | 77 | } |
78 | 78 | ||
79 | /** | 79 | /** |
@@ -83,29 +83,31 @@ do_shutdown (void *cls) | |||
83 | * @param event the controller event | 83 | * @param event the controller event |
84 | */ | 84 | */ |
85 | static void | 85 | static void |
86 | controller_event_cb (void *cls, | 86 | controller_event_cb(void *cls, |
87 | const struct GNUNET_TESTBED_EventInformation *event) | 87 | const struct GNUNET_TESTBED_EventInformation *event) |
88 | { | 88 | { |
89 | switch (event->type) | 89 | switch (event->type) |
90 | { | ||
91 | case GNUNET_TESTBED_ET_CONNECT: | ||
92 | overlay_connects++; | ||
93 | if ((NUM_PEERS * (NUM_PEERS - 1)) == overlay_connects) | ||
94 | { | 90 | { |
95 | result = GNUNET_OK; | 91 | case GNUNET_TESTBED_ET_CONNECT: |
96 | GNUNET_SCHEDULER_cancel (shutdown_task); | 92 | overlay_connects++; |
97 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 93 | if ((NUM_PEERS * (NUM_PEERS - 1)) == overlay_connects) |
94 | { | ||
95 | result = GNUNET_OK; | ||
96 | GNUNET_SCHEDULER_cancel(shutdown_task); | ||
97 | shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); | ||
98 | } | ||
99 | break; | ||
100 | |||
101 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
102 | GNUNET_assert(NULL != event->details.operation_finished.emsg); | ||
103 | break; | ||
104 | |||
105 | default: | ||
106 | GNUNET_break(0); | ||
107 | result = GNUNET_SYSERR; | ||
108 | GNUNET_SCHEDULER_cancel(shutdown_task); | ||
109 | shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); | ||
98 | } | 110 | } |
99 | break; | ||
100 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
101 | GNUNET_assert (NULL != event->details.operation_finished.emsg); | ||
102 | break; | ||
103 | default: | ||
104 | GNUNET_break (0); | ||
105 | result = GNUNET_SYSERR; | ||
106 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
107 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
108 | } | ||
109 | } | 111 | } |
110 | 112 | ||
111 | 113 | ||
@@ -122,38 +124,38 @@ controller_event_cb (void *cls, | |||
122 | * failed | 124 | * failed |
123 | */ | 125 | */ |
124 | static void | 126 | static void |
125 | test_master (void *cls, | 127 | test_master(void *cls, |
126 | struct GNUNET_TESTBED_RunHandle *h, | 128 | struct GNUNET_TESTBED_RunHandle *h, |
127 | unsigned int num_peers, | 129 | unsigned int num_peers, |
128 | struct GNUNET_TESTBED_Peer **peers_, | 130 | struct GNUNET_TESTBED_Peer **peers_, |
129 | unsigned int links_succeeded, | 131 | unsigned int links_succeeded, |
130 | unsigned int links_failed) | 132 | unsigned int links_failed) |
131 | { | 133 | { |
132 | unsigned int peer; | 134 | unsigned int peer; |
133 | 135 | ||
134 | GNUNET_assert (NULL == cls); | 136 | GNUNET_assert(NULL == cls); |
135 | if (NULL == peers_) | 137 | if (NULL == peers_) |
136 | { | 138 | { |
137 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n"); | 139 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n"); |
138 | return; | 140 | return; |
139 | } | 141 | } |
140 | GNUNET_assert (NUM_PEERS == num_peers); | 142 | GNUNET_assert(NUM_PEERS == num_peers); |
141 | for (peer = 0; peer < num_peers; peer++) | 143 | for (peer = 0; peer < num_peers; peer++) |
142 | GNUNET_assert (NULL != peers_[peer]); | 144 | GNUNET_assert(NULL != peers_[peer]); |
143 | peers = peers_; | 145 | peers = peers_; |
144 | overlay_connects = 0; | 146 | overlay_connects = 0; |
145 | op = GNUNET_TESTBED_overlay_configure_topology (NULL, NUM_PEERS, peers, NULL, | 147 | op = GNUNET_TESTBED_overlay_configure_topology(NULL, NUM_PEERS, peers, NULL, |
146 | NULL, | 148 | NULL, |
147 | NULL, | 149 | NULL, |
148 | GNUNET_TESTBED_TOPOLOGY_CLIQUE, | 150 | GNUNET_TESTBED_TOPOLOGY_CLIQUE, |
149 | /* GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, */ | 151 | /* GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, */ |
150 | /* NUM_PEERS, */ | 152 | /* NUM_PEERS, */ |
151 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); | 153 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); |
152 | GNUNET_assert (NULL != op); | 154 | GNUNET_assert(NULL != op); |
153 | shutdown_task = | 155 | shutdown_task = |
154 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 156 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
155 | (GNUNET_TIME_UNIT_SECONDS, 300), | 157 | (GNUNET_TIME_UNIT_SECONDS, 300), |
156 | do_shutdown, NULL); | 158 | do_shutdown, NULL); |
157 | } | 159 | } |
158 | 160 | ||
159 | 161 | ||
@@ -161,7 +163,7 @@ test_master (void *cls, | |||
161 | * Main function | 163 | * Main function |
162 | */ | 164 | */ |
163 | int | 165 | int |
164 | main (int argc, char **argv) | 166 | main(int argc, char **argv) |
165 | { | 167 | { |
166 | uint64_t event_mask; | 168 | uint64_t event_mask; |
167 | 169 | ||
@@ -169,10 +171,10 @@ main (int argc, char **argv) | |||
169 | event_mask = 0; | 171 | event_mask = 0; |
170 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | 172 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); |
171 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 173 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
172 | (void) GNUNET_TESTBED_test_run ("test_testbed_api_test", | 174 | (void)GNUNET_TESTBED_test_run("test_testbed_api_test", |
173 | "test_testbed_api.conf", NUM_PEERS, | 175 | "test_testbed_api.conf", NUM_PEERS, |
174 | event_mask, &controller_event_cb, NULL, | 176 | event_mask, &controller_event_cb, NULL, |
175 | &test_master, NULL); | 177 | &test_master, NULL); |
176 | if (GNUNET_OK != result) | 178 | if (GNUNET_OK != result) |
177 | return 1; | 179 | return 1; |
178 | return 0; | 180 | return 0; |
diff --git a/src/testbed/test_testbed_underlay.c b/src/testbed/test_testbed_underlay.c index 41aa43ce5..fad4282d7 100644 --- a/src/testbed/test_testbed_underlay.c +++ b/src/testbed/test_testbed_underlay.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -49,10 +49,10 @@ static struct GNUNET_TESTBED_Operation *op; | |||
49 | * @param tc scheduler task context | 49 | * @param tc scheduler task context |
50 | */ | 50 | */ |
51 | static void | 51 | static void |
52 | do_shutdown (void *cls) | 52 | do_shutdown(void *cls) |
53 | { | 53 | { |
54 | if (NULL != op) | 54 | if (NULL != op) |
55 | GNUNET_TESTBED_operation_done (op); | 55 | GNUNET_TESTBED_operation_done(op); |
56 | op = NULL; | 56 | op = NULL; |
57 | } | 57 | } |
58 | 58 | ||
@@ -66,21 +66,21 @@ do_shutdown (void *cls) | |||
66 | * operation has executed successfully. | 66 | * operation has executed successfully. |
67 | */ | 67 | */ |
68 | static void | 68 | static void |
69 | overlay_connect_status (void *cls, | 69 | overlay_connect_status(void *cls, |
70 | struct GNUNET_TESTBED_Operation *op_, | 70 | struct GNUNET_TESTBED_Operation *op_, |
71 | const char *emsg) | 71 | const char *emsg) |
72 | { | 72 | { |
73 | GNUNET_assert (op_ == op); | 73 | GNUNET_assert(op_ == op); |
74 | GNUNET_TESTBED_operation_done (op); | 74 | GNUNET_TESTBED_operation_done(op); |
75 | op = NULL; | 75 | op = NULL; |
76 | if (NULL == emsg) | 76 | if (NULL == emsg) |
77 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peers 0 and 2 should not get connected\n"); | 77 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Peers 0 and 2 should not get connected\n"); |
78 | else | 78 | else |
79 | { | 79 | { |
80 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers 0 and 2 not connected: %s. Success!\n", emsg); | 80 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peers 0 and 2 not connected: %s. Success!\n", emsg); |
81 | result = GNUNET_OK; | 81 | result = GNUNET_OK; |
82 | } | 82 | } |
83 | GNUNET_SCHEDULER_shutdown (); | 83 | GNUNET_SCHEDULER_shutdown(); |
84 | } | 84 | } |
85 | 85 | ||
86 | 86 | ||
@@ -98,29 +98,29 @@ overlay_connect_status (void *cls, | |||
98 | * failed | 98 | * failed |
99 | */ | 99 | */ |
100 | static void | 100 | static void |
101 | test_master (void *cls, | 101 | test_master(void *cls, |
102 | struct GNUNET_TESTBED_RunHandle *h, | 102 | struct GNUNET_TESTBED_RunHandle *h, |
103 | unsigned int num_peers, | 103 | unsigned int num_peers, |
104 | struct GNUNET_TESTBED_Peer **peers_, | 104 | struct GNUNET_TESTBED_Peer **peers_, |
105 | unsigned int links_succeeded, | 105 | unsigned int links_succeeded, |
106 | unsigned int links_failed) | 106 | unsigned int links_failed) |
107 | { | 107 | { |
108 | GNUNET_assert (NULL == cls); | 108 | GNUNET_assert(NULL == cls); |
109 | if (NULL == peers_) | 109 | if (NULL == peers_) |
110 | { | 110 | { |
111 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n"); | 111 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n"); |
112 | GNUNET_SCHEDULER_shutdown (); | 112 | GNUNET_SCHEDULER_shutdown(); |
113 | return; | 113 | return; |
114 | } | 114 | } |
115 | GNUNET_assert (NUM_PEERS == num_peers); | 115 | GNUNET_assert(NUM_PEERS == num_peers); |
116 | op = GNUNET_TESTBED_overlay_connect (NULL, | 116 | op = GNUNET_TESTBED_overlay_connect(NULL, |
117 | &overlay_connect_status, | 117 | &overlay_connect_status, |
118 | NULL, | 118 | NULL, |
119 | peers_[0], | 119 | peers_[0], |
120 | peers_[2]); | 120 | peers_[2]); |
121 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 121 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
122 | 60), | 122 | 60), |
123 | &do_shutdown, NULL); | 123 | &do_shutdown, NULL); |
124 | } | 124 | } |
125 | 125 | ||
126 | 126 | ||
@@ -136,7 +136,7 @@ test_master (void *cls, | |||
136 | * Main function | 136 | * Main function |
137 | */ | 137 | */ |
138 | int | 138 | int |
139 | main (int argc, char **argv) | 139 | main(int argc, char **argv) |
140 | { | 140 | { |
141 | struct GNUNET_CONFIGURATION_Handle *cfg; | 141 | struct GNUNET_CONFIGURATION_Handle *cfg; |
142 | char pwd[PATH_MAX]; | 142 | char pwd[PATH_MAX]; |
@@ -145,26 +145,26 @@ main (int argc, char **argv) | |||
145 | 145 | ||
146 | result = GNUNET_SYSERR; | 146 | result = GNUNET_SYSERR; |
147 | event_mask = 0; | 147 | event_mask = 0; |
148 | cfg = GNUNET_CONFIGURATION_create (); | 148 | cfg = GNUNET_CONFIGURATION_create(); |
149 | GNUNET_assert (GNUNET_YES == | 149 | GNUNET_assert(GNUNET_YES == |
150 | GNUNET_CONFIGURATION_parse (cfg, | 150 | GNUNET_CONFIGURATION_parse(cfg, |
151 | "test_testbed_underlay.conf.in")); | 151 | "test_testbed_underlay.conf.in")); |
152 | if (NULL == getcwd (pwd, PATH_MAX)) | 152 | if (NULL == getcwd(pwd, PATH_MAX)) |
153 | return 1; | 153 | return 1; |
154 | GNUNET_assert (0 < GNUNET_asprintf (&dbfile, "%s/%s", pwd, | 154 | GNUNET_assert(0 < GNUNET_asprintf(&dbfile, "%s/%s", pwd, |
155 | "test-underlay.sqlite")); | 155 | "test-underlay.sqlite")); |
156 | GNUNET_CONFIGURATION_set_value_string (cfg, "TESTBED-UNDERLAY","DBFILE", dbfile); | 156 | GNUNET_CONFIGURATION_set_value_string(cfg, "TESTBED-UNDERLAY", "DBFILE", dbfile); |
157 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write | 157 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_write |
158 | (cfg, "test_testbed_underlay.conf")); | 158 | (cfg, "test_testbed_underlay.conf")); |
159 | GNUNET_CONFIGURATION_destroy (cfg); | 159 | GNUNET_CONFIGURATION_destroy(cfg); |
160 | cfg = NULL; | 160 | cfg = NULL; |
161 | GNUNET_free (dbfile); | 161 | GNUNET_free(dbfile); |
162 | dbfile = NULL; | 162 | dbfile = NULL; |
163 | (void) GNUNET_TESTBED_test_run ("test_testbed_underlay", | 163 | (void)GNUNET_TESTBED_test_run("test_testbed_underlay", |
164 | "test_testbed_underlay.conf", NUM_PEERS, | 164 | "test_testbed_underlay.conf", NUM_PEERS, |
165 | event_mask, NULL, NULL, | 165 | event_mask, NULL, NULL, |
166 | &test_master, NULL); | 166 | &test_master, NULL); |
167 | (void) unlink ("test_testbed_underlay.conf"); | 167 | (void)unlink("test_testbed_underlay.conf"); |
168 | if (GNUNET_OK != result) | 168 | if (GNUNET_OK != result) |
169 | return 1; | 169 | return 1; |
170 | return 0; | 170 | return 0; |
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h index b659a3408..8ab957b88 100644 --- a/src/testbed/testbed.h +++ b/src/testbed/testbed.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -33,9 +33,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
33 | /** | 33 | /** |
34 | * Initial message from a client to a testing control service. | 34 | * Initial message from a client to a testing control service. |
35 | */ | 35 | */ |
36 | struct GNUNET_TESTBED_InitMessage | 36 | struct GNUNET_TESTBED_InitMessage { |
37 | { | ||
38 | |||
39 | /** | 37 | /** |
40 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_INIT | 38 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_INIT |
41 | */ | 39 | */ |
@@ -62,9 +60,7 @@ struct GNUNET_TESTBED_InitMessage | |||
62 | /** | 60 | /** |
63 | * Notify the service about a host that we intend to use. | 61 | * Notify the service about a host that we intend to use. |
64 | */ | 62 | */ |
65 | struct GNUNET_TESTBED_AddHostMessage | 63 | struct GNUNET_TESTBED_AddHostMessage { |
66 | { | ||
67 | |||
68 | /** | 64 | /** |
69 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST | 65 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST |
70 | */ | 66 | */ |
@@ -105,7 +101,6 @@ struct GNUNET_TESTBED_AddHostMessage | |||
105 | /* followed by gzip compressed configuration to start or connect to a | 101 | /* followed by gzip compressed configuration to start or connect to a |
106 | controller on this host. While starting the controller this configuration | 102 | controller on this host. While starting the controller this configuration |
107 | is used as a template */ | 103 | is used as a template */ |
108 | |||
109 | }; | 104 | }; |
110 | 105 | ||
111 | 106 | ||
@@ -114,9 +109,7 @@ struct GNUNET_TESTBED_AddHostMessage | |||
114 | * worked (or failed). | 109 | * worked (or failed). |
115 | * FIXME: Where is this required? | 110 | * FIXME: Where is this required? |
116 | */ | 111 | */ |
117 | struct GNUNET_TESTBED_HostConfirmedMessage | 112 | struct GNUNET_TESTBED_HostConfirmedMessage { |
118 | { | ||
119 | |||
120 | /** | 113 | /** |
121 | * Type is GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS | 114 | * Type is GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS |
122 | */ | 115 | */ |
@@ -129,7 +122,6 @@ struct GNUNET_TESTBED_HostConfirmedMessage | |||
129 | 122 | ||
130 | /* followed by the 0-terminated error message (on failure) | 123 | /* followed by the 0-terminated error message (on failure) |
131 | * (typical errors include host-id already in use) */ | 124 | * (typical errors include host-id already in use) */ |
132 | |||
133 | }; | 125 | }; |
134 | 126 | ||
135 | 127 | ||
@@ -138,9 +130,7 @@ struct GNUNET_TESTBED_HostConfirmedMessage | |||
138 | * requests for a particular client to a particular | 130 | * requests for a particular client to a particular |
139 | * sub-controller. | 131 | * sub-controller. |
140 | */ | 132 | */ |
141 | struct GNUNET_TESTBED_ControllerLinkRequest | 133 | struct GNUNET_TESTBED_ControllerLinkRequest { |
142 | { | ||
143 | |||
144 | /** | 134 | /** |
145 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS | 135 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS |
146 | */ | 136 | */ |
@@ -166,16 +156,13 @@ struct GNUNET_TESTBED_ControllerLinkRequest | |||
166 | * the slave host (and thus responsible for starting it?). 0 if not | 156 | * the slave host (and thus responsible for starting it?). 0 if not |
167 | */ | 157 | */ |
168 | uint8_t is_subordinate; | 158 | uint8_t is_subordinate; |
169 | |||
170 | }; | 159 | }; |
171 | 160 | ||
172 | 161 | ||
173 | /** | 162 | /** |
174 | * Response message for ControllerLinkRequest message | 163 | * Response message for ControllerLinkRequest message |
175 | */ | 164 | */ |
176 | struct GNUNET_TESTBED_ControllerLinkResponse | 165 | struct GNUNET_TESTBED_ControllerLinkResponse { |
177 | { | ||
178 | |||
179 | /** | 166 | /** |
180 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT | 167 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT |
181 | */ | 168 | */ |
@@ -202,7 +189,6 @@ struct GNUNET_TESTBED_ControllerLinkResponse | |||
202 | * running at the delegate host */ | 189 | * running at the delegate host */ |
203 | 190 | ||
204 | /* In case of failure, here comes the error message (without \0 termination)*/ | 191 | /* In case of failure, here comes the error message (without \0 termination)*/ |
205 | |||
206 | }; | 192 | }; |
207 | 193 | ||
208 | 194 | ||
@@ -210,9 +196,7 @@ struct GNUNET_TESTBED_ControllerLinkResponse | |||
210 | * Message sent from client to testing service to | 196 | * Message sent from client to testing service to |
211 | * create (configure, but not start) a peer. | 197 | * create (configure, but not start) a peer. |
212 | */ | 198 | */ |
213 | struct GNUNET_TESTBED_PeerCreateMessage | 199 | struct GNUNET_TESTBED_PeerCreateMessage { |
214 | { | ||
215 | |||
216 | /** | 200 | /** |
217 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER | 201 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER |
218 | */ | 202 | */ |
@@ -239,8 +223,7 @@ struct GNUNET_TESTBED_PeerCreateMessage | |||
239 | uint16_t config_size GNUNET_PACKED; | 223 | uint16_t config_size GNUNET_PACKED; |
240 | 224 | ||
241 | /* followed by serialized peer configuration; | 225 | /* followed by serialized peer configuration; |
242 | * gzip'ed configuration file in INI format */ | 226 | * gzip'ed configuration file in INI format */ |
243 | |||
244 | }; | 227 | }; |
245 | 228 | ||
246 | 229 | ||
@@ -248,9 +231,7 @@ struct GNUNET_TESTBED_PeerCreateMessage | |||
248 | * Message sent from client to testing service to | 231 | * Message sent from client to testing service to |
249 | * reconfigure a (stopped) a peer. | 232 | * reconfigure a (stopped) a peer. |
250 | */ | 233 | */ |
251 | struct GNUNET_TESTBED_PeerReconfigureMessage | 234 | struct GNUNET_TESTBED_PeerReconfigureMessage { |
252 | { | ||
253 | |||
254 | /** | 235 | /** |
255 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER | 236 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER |
256 | */ | 237 | */ |
@@ -272,8 +253,7 @@ struct GNUNET_TESTBED_PeerReconfigureMessage | |||
272 | uint16_t config_size GNUNET_PACKED; | 253 | uint16_t config_size GNUNET_PACKED; |
273 | 254 | ||
274 | /* followed by serialized peer configuration; | 255 | /* followed by serialized peer configuration; |
275 | * gzip'ed configuration file in INI format */ | 256 | * gzip'ed configuration file in INI format */ |
276 | |||
277 | }; | 257 | }; |
278 | 258 | ||
279 | 259 | ||
@@ -281,9 +261,7 @@ struct GNUNET_TESTBED_PeerReconfigureMessage | |||
281 | * Message sent from client to testing service to | 261 | * Message sent from client to testing service to |
282 | * start a peer. | 262 | * start a peer. |
283 | */ | 263 | */ |
284 | struct GNUNET_TESTBED_PeerStartMessage | 264 | struct GNUNET_TESTBED_PeerStartMessage { |
285 | { | ||
286 | |||
287 | /** | 265 | /** |
288 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_START_PEER | 266 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_START_PEER |
289 | */ | 267 | */ |
@@ -298,7 +276,6 @@ struct GNUNET_TESTBED_PeerStartMessage | |||
298 | * Operation ID that is used to identify this operation. | 276 | * Operation ID that is used to identify this operation. |
299 | */ | 277 | */ |
300 | uint64_t operation_id GNUNET_PACKED; | 278 | uint64_t operation_id GNUNET_PACKED; |
301 | |||
302 | }; | 279 | }; |
303 | 280 | ||
304 | 281 | ||
@@ -306,9 +283,7 @@ struct GNUNET_TESTBED_PeerStartMessage | |||
306 | * Message sent from client to testing service to | 283 | * Message sent from client to testing service to |
307 | * stop a peer. | 284 | * stop a peer. |
308 | */ | 285 | */ |
309 | struct GNUNET_TESTBED_PeerStopMessage | 286 | struct GNUNET_TESTBED_PeerStopMessage { |
310 | { | ||
311 | |||
312 | /** | 287 | /** |
313 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER | 288 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER |
314 | */ | 289 | */ |
@@ -323,7 +298,6 @@ struct GNUNET_TESTBED_PeerStopMessage | |||
323 | * Operation ID that is used to identify this operation. | 298 | * Operation ID that is used to identify this operation. |
324 | */ | 299 | */ |
325 | uint64_t operation_id GNUNET_PACKED; | 300 | uint64_t operation_id GNUNET_PACKED; |
326 | |||
327 | }; | 301 | }; |
328 | 302 | ||
329 | 303 | ||
@@ -331,9 +305,7 @@ struct GNUNET_TESTBED_PeerStopMessage | |||
331 | * Message sent from client to testing service to | 305 | * Message sent from client to testing service to |
332 | * destroy a (stopped) peer. | 306 | * destroy a (stopped) peer. |
333 | */ | 307 | */ |
334 | struct GNUNET_TESTBED_PeerDestroyMessage | 308 | struct GNUNET_TESTBED_PeerDestroyMessage { |
335 | { | ||
336 | |||
337 | /** | 309 | /** |
338 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER | 310 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER |
339 | */ | 311 | */ |
@@ -348,7 +320,6 @@ struct GNUNET_TESTBED_PeerDestroyMessage | |||
348 | * Operation ID that is used to identify this operation. | 320 | * Operation ID that is used to identify this operation. |
349 | */ | 321 | */ |
350 | uint64_t operation_id GNUNET_PACKED; | 322 | uint64_t operation_id GNUNET_PACKED; |
351 | |||
352 | }; | 323 | }; |
353 | 324 | ||
354 | 325 | ||
@@ -356,9 +327,7 @@ struct GNUNET_TESTBED_PeerDestroyMessage | |||
356 | * Message sent from client to testing service to | 327 | * Message sent from client to testing service to |
357 | * (re)configure a "physical" link between two peers. | 328 | * (re)configure a "physical" link between two peers. |
358 | */ | 329 | */ |
359 | struct GNUNET_TESTBED_ConfigureUnderlayLinkMessage | 330 | struct GNUNET_TESTBED_ConfigureUnderlayLinkMessage { |
360 | { | ||
361 | |||
362 | /** | 331 | /** |
363 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_CONFIGURE_UNDERLAY_LINK | 332 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_CONFIGURE_UNDERLAY_LINK |
364 | */ | 333 | */ |
@@ -385,7 +354,6 @@ struct GNUNET_TESTBED_ConfigureUnderlayLinkMessage | |||
385 | uint64_t operation_id GNUNET_PACKED; | 354 | uint64_t operation_id GNUNET_PACKED; |
386 | 355 | ||
387 | /* followed by option-dependent variable-size values */ | 356 | /* followed by option-dependent variable-size values */ |
388 | |||
389 | }; | 357 | }; |
390 | 358 | ||
391 | 359 | ||
@@ -393,9 +361,7 @@ struct GNUNET_TESTBED_ConfigureUnderlayLinkMessage | |||
393 | * Message sent from client to testing service to | 361 | * Message sent from client to testing service to |
394 | * connect two peers. | 362 | * connect two peers. |
395 | */ | 363 | */ |
396 | struct GNUNET_TESTBED_OverlayConnectMessage | 364 | struct GNUNET_TESTBED_OverlayConnectMessage { |
397 | { | ||
398 | |||
399 | /** | 365 | /** |
400 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT | 366 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT |
401 | */ | 367 | */ |
@@ -420,7 +386,6 @@ struct GNUNET_TESTBED_OverlayConnectMessage | |||
420 | * The ID of the host which runs peer2 | 386 | * The ID of the host which runs peer2 |
421 | */ | 387 | */ |
422 | uint32_t peer2_host_id GNUNET_PACKED; | 388 | uint32_t peer2_host_id GNUNET_PACKED; |
423 | |||
424 | }; | 389 | }; |
425 | 390 | ||
426 | 391 | ||
@@ -428,8 +393,7 @@ struct GNUNET_TESTBED_OverlayConnectMessage | |||
428 | * Message sent from host controller of a peer(A) to the host controller of | 393 | * Message sent from host controller of a peer(A) to the host controller of |
429 | * another peer(B) to request B to connect to A | 394 | * another peer(B) to request B to connect to A |
430 | */ | 395 | */ |
431 | struct GNUNET_TESTBED_RemoteOverlayConnectMessage | 396 | struct GNUNET_TESTBED_RemoteOverlayConnectMessage { |
432 | { | ||
433 | /** | 397 | /** |
434 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT | 398 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT |
435 | */ | 399 | */ |
@@ -456,16 +420,13 @@ struct GNUNET_TESTBED_RemoteOverlayConnectMessage | |||
456 | struct GNUNET_MessageHeader hello[0]; | 420 | struct GNUNET_MessageHeader hello[0]; |
457 | // FIXME: we usually do not use this gcc-hack as some | 421 | // FIXME: we usually do not use this gcc-hack as some |
458 | // compilers / tools really get messed up by it... | 422 | // compilers / tools really get messed up by it... |
459 | |||
460 | }; | 423 | }; |
461 | 424 | ||
462 | 425 | ||
463 | /** | 426 | /** |
464 | * Event notification from a controller to a client. | 427 | * Event notification from a controller to a client. |
465 | */ | 428 | */ |
466 | struct GNUNET_TESTBED_PeerEventMessage | 429 | struct GNUNET_TESTBED_PeerEventMessage { |
467 | { | ||
468 | |||
469 | /** | 430 | /** |
470 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT | 431 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT |
471 | */ | 432 | */ |
@@ -491,16 +452,13 @@ struct GNUNET_TESTBED_PeerEventMessage | |||
491 | * Operation ID that is used to identify this operation. | 452 | * Operation ID that is used to identify this operation. |
492 | */ | 453 | */ |
493 | uint64_t operation_id GNUNET_PACKED; | 454 | uint64_t operation_id GNUNET_PACKED; |
494 | |||
495 | }; | 455 | }; |
496 | 456 | ||
497 | 457 | ||
498 | /** | 458 | /** |
499 | * Event notification from a controller to a client. | 459 | * Event notification from a controller to a client. |
500 | */ | 460 | */ |
501 | struct GNUNET_TESTBED_ConnectionEventMessage | 461 | struct GNUNET_TESTBED_ConnectionEventMessage { |
502 | { | ||
503 | |||
504 | /** | 462 | /** |
505 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT | 463 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT |
506 | */ | 464 | */ |
@@ -526,16 +484,13 @@ struct GNUNET_TESTBED_ConnectionEventMessage | |||
526 | * Operation ID that is used to identify this operation. | 484 | * Operation ID that is used to identify this operation. |
527 | */ | 485 | */ |
528 | uint64_t operation_id GNUNET_PACKED; | 486 | uint64_t operation_id GNUNET_PACKED; |
529 | |||
530 | }; | 487 | }; |
531 | 488 | ||
532 | 489 | ||
533 | /** | 490 | /** |
534 | * Event notification from a controller to a client. | 491 | * Event notification from a controller to a client. |
535 | */ | 492 | */ |
536 | struct GNUNET_TESTBED_OperationFailureEventMessage | 493 | struct GNUNET_TESTBED_OperationFailureEventMessage { |
537 | { | ||
538 | |||
539 | /** | 494 | /** |
540 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT | 495 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT |
541 | */ | 496 | */ |
@@ -553,16 +508,13 @@ struct GNUNET_TESTBED_OperationFailureEventMessage | |||
553 | uint64_t operation_id GNUNET_PACKED; | 508 | uint64_t operation_id GNUNET_PACKED; |
554 | 509 | ||
555 | /* followed by 0-terminated error message */ | 510 | /* followed by 0-terminated error message */ |
556 | |||
557 | }; | 511 | }; |
558 | 512 | ||
559 | 513 | ||
560 | /** | 514 | /** |
561 | * Event notification from a controller to a client. | 515 | * Event notification from a controller to a client. |
562 | */ | 516 | */ |
563 | struct GNUNET_TESTBED_PeerCreateSuccessEventMessage | 517 | struct GNUNET_TESTBED_PeerCreateSuccessEventMessage { |
564 | { | ||
565 | |||
566 | /** | 518 | /** |
567 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS | 519 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS |
568 | */ | 520 | */ |
@@ -577,7 +529,6 @@ struct GNUNET_TESTBED_PeerCreateSuccessEventMessage | |||
577 | * Operation ID of the operation that created this event. | 529 | * Operation ID of the operation that created this event. |
578 | */ | 530 | */ |
579 | uint64_t operation_id GNUNET_PACKED; | 531 | uint64_t operation_id GNUNET_PACKED; |
580 | |||
581 | }; | 532 | }; |
582 | 533 | ||
583 | 534 | ||
@@ -586,9 +537,7 @@ struct GNUNET_TESTBED_PeerCreateSuccessEventMessage | |||
586 | * a generic operational success where the operation does | 537 | * a generic operational success where the operation does |
587 | * not return any data. | 538 | * not return any data. |
588 | */ | 539 | */ |
589 | struct GNUNET_TESTBED_GenericOperationSuccessEventMessage | 540 | struct GNUNET_TESTBED_GenericOperationSuccessEventMessage { |
590 | { | ||
591 | |||
592 | /** | 541 | /** |
593 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS | 542 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS |
594 | */ | 543 | */ |
@@ -604,7 +553,6 @@ struct GNUNET_TESTBED_GenericOperationSuccessEventMessage | |||
604 | * Operation ID of the operation that created this event. | 553 | * Operation ID of the operation that created this event. |
605 | */ | 554 | */ |
606 | uint64_t operation_id GNUNET_PACKED; | 555 | uint64_t operation_id GNUNET_PACKED; |
607 | |||
608 | }; | 556 | }; |
609 | 557 | ||
610 | 558 | ||
@@ -612,9 +560,7 @@ struct GNUNET_TESTBED_GenericOperationSuccessEventMessage | |||
612 | * Message sent from client to testing service to | 560 | * Message sent from client to testing service to |
613 | * obtain the configuration of a peer. | 561 | * obtain the configuration of a peer. |
614 | */ | 562 | */ |
615 | struct GNUNET_TESTBED_PeerGetConfigurationMessage | 563 | struct GNUNET_TESTBED_PeerGetConfigurationMessage { |
616 | { | ||
617 | |||
618 | /** | 564 | /** |
619 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION | 565 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION |
620 | */ | 566 | */ |
@@ -629,16 +575,13 @@ struct GNUNET_TESTBED_PeerGetConfigurationMessage | |||
629 | * Operation ID that is used to identify this operation. | 575 | * Operation ID that is used to identify this operation. |
630 | */ | 576 | */ |
631 | uint64_t operation_id GNUNET_PACKED; | 577 | uint64_t operation_id GNUNET_PACKED; |
632 | |||
633 | }; | 578 | }; |
634 | 579 | ||
635 | 580 | ||
636 | /** | 581 | /** |
637 | * Peer configuration and identity reply from controller to a client. | 582 | * Peer configuration and identity reply from controller to a client. |
638 | */ | 583 | */ |
639 | struct GNUNET_TESTBED_PeerConfigurationInformationMessage | 584 | struct GNUNET_TESTBED_PeerConfigurationInformationMessage { |
640 | { | ||
641 | |||
642 | /** | 585 | /** |
643 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION | 586 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION |
644 | */ | 587 | */ |
@@ -665,15 +608,13 @@ struct GNUNET_TESTBED_PeerConfigurationInformationMessage | |||
665 | uint16_t config_size GNUNET_PACKED; | 608 | uint16_t config_size GNUNET_PACKED; |
666 | 609 | ||
667 | /* followed by gzip-compressed configuration of the peer */ | 610 | /* followed by gzip-compressed configuration of the peer */ |
668 | |||
669 | }; | 611 | }; |
670 | 612 | ||
671 | 613 | ||
672 | /** | 614 | /** |
673 | * Message to request configuration of a slave controller | 615 | * Message to request configuration of a slave controller |
674 | */ | 616 | */ |
675 | struct GNUNET_TESTBED_SlaveGetConfigurationMessage | 617 | struct GNUNET_TESTBED_SlaveGetConfigurationMessage { |
676 | { | ||
677 | /** | 618 | /** |
678 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION | 619 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION |
679 | */ | 620 | */ |
@@ -688,15 +629,13 @@ struct GNUNET_TESTBED_SlaveGetConfigurationMessage | |||
688 | * Operation ID | 629 | * Operation ID |
689 | */ | 630 | */ |
690 | uint64_t operation_id GNUNET_PACKED; | 631 | uint64_t operation_id GNUNET_PACKED; |
691 | |||
692 | }; | 632 | }; |
693 | 633 | ||
694 | 634 | ||
695 | /** | 635 | /** |
696 | * Reply to #GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION message | 636 | * Reply to #GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION message |
697 | */ | 637 | */ |
698 | struct GNUNET_TESTBED_SlaveConfiguration | 638 | struct GNUNET_TESTBED_SlaveConfiguration { |
699 | { | ||
700 | /** | 639 | /** |
701 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION | 640 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION |
702 | */ | 641 | */ |
@@ -718,15 +657,13 @@ struct GNUNET_TESTBED_SlaveConfiguration | |||
718 | uint16_t config_size GNUNET_PACKED; | 657 | uint16_t config_size GNUNET_PACKED; |
719 | 658 | ||
720 | /* followed by gzip-compressed configuration of the peer */ | 659 | /* followed by gzip-compressed configuration of the peer */ |
721 | |||
722 | }; | 660 | }; |
723 | 661 | ||
724 | 662 | ||
725 | /** | 663 | /** |
726 | * Shutdown peers message | 664 | * Shutdown peers message |
727 | */ | 665 | */ |
728 | struct GNUNET_TESTBED_ShutdownPeersMessage | 666 | struct GNUNET_TESTBED_ShutdownPeersMessage { |
729 | { | ||
730 | /** | 667 | /** |
731 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS | 668 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS |
732 | */ | 669 | */ |
@@ -742,8 +679,7 @@ struct GNUNET_TESTBED_ShutdownPeersMessage | |||
742 | /** | 679 | /** |
743 | * Message to start/stop services of a peer | 680 | * Message to start/stop services of a peer |
744 | */ | 681 | */ |
745 | struct GNUNET_TESTBED_ManagePeerServiceMessage | 682 | struct GNUNET_TESTBED_ManagePeerServiceMessage { |
746 | { | ||
747 | /** | 683 | /** |
748 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS | 684 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS |
749 | */ | 685 | */ |
@@ -774,8 +710,7 @@ struct GNUNET_TESTBED_ManagePeerServiceMessage | |||
774 | * Message to send underlay link model of a peer. This message will be | 710 | * Message to send underlay link model of a peer. This message will be |
775 | * forwarded to the controller running the peer. | 711 | * forwarded to the controller running the peer. |
776 | */ | 712 | */ |
777 | struct GNUNET_TESTBED_UnderlayLinkModelMsg | 713 | struct GNUNET_TESTBED_UnderlayLinkModelMsg { |
778 | { | ||
779 | /** | 714 | /** |
780 | * Type is #GNUNET_MESSAGE_TYPE_UNDERLAYLINKMODELMSG | 715 | * Type is #GNUNET_MESSAGE_TYPE_UNDERLAYLINKMODELMSG |
781 | */ | 716 | */ |
@@ -801,7 +736,6 @@ struct GNUNET_TESTBED_UnderlayLinkModelMsg | |||
801 | * sequence of four integers of type uint32_t: peer_id, latency, loss and | 736 | * sequence of four integers of type uint32_t: peer_id, latency, loss and |
802 | * bandwidth. | 737 | * bandwidth. |
803 | */ | 738 | */ |
804 | |||
805 | }; | 739 | }; |
806 | 740 | ||
807 | 741 | ||
@@ -820,8 +754,7 @@ struct GNUNET_TESTBED_UnderlayLinkModelMsg | |||
820 | /** | 754 | /** |
821 | * Message to initialise a barrier | 755 | * Message to initialise a barrier |
822 | */ | 756 | */ |
823 | struct GNUNET_TESTBED_BarrierInit | 757 | struct GNUNET_TESTBED_BarrierInit { |
824 | { | ||
825 | /** | 758 | /** |
826 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT | 759 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT |
827 | */ | 760 | */ |
@@ -842,8 +775,7 @@ struct GNUNET_TESTBED_BarrierInit | |||
842 | /** | 775 | /** |
843 | * Message to cancel a barrier | 776 | * Message to cancel a barrier |
844 | */ | 777 | */ |
845 | struct GNUNET_TESTBED_BarrierCancel | 778 | struct GNUNET_TESTBED_BarrierCancel { |
846 | { | ||
847 | /** | 779 | /** |
848 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL | 780 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL |
849 | */ | 781 | */ |
@@ -859,8 +791,7 @@ struct GNUNET_TESTBED_BarrierCancel | |||
859 | /** | 791 | /** |
860 | * Message for signalling status changes of a barrier | 792 | * Message for signalling status changes of a barrier |
861 | */ | 793 | */ |
862 | struct GNUNET_TESTBED_BarrierStatusMsg | 794 | struct GNUNET_TESTBED_BarrierStatusMsg { |
863 | { | ||
864 | /** | 795 | /** |
865 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS | 796 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS |
866 | */ | 797 | */ |
@@ -888,8 +819,7 @@ struct GNUNET_TESTBED_BarrierStatusMsg | |||
888 | * Message sent from peers to the testbed-barrier service to indicate that they | 819 | * Message sent from peers to the testbed-barrier service to indicate that they |
889 | * have reached a barrier and are waiting for it to be crossed | 820 | * have reached a barrier and are waiting for it to be crossed |
890 | */ | 821 | */ |
891 | struct GNUNET_TESTBED_BarrierWait | 822 | struct GNUNET_TESTBED_BarrierWait { |
892 | { | ||
893 | /** | 823 | /** |
894 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT | 824 | * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT |
895 | */ | 825 | */ |
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 7df5f1270..8ca96dcbe 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -44,32 +44,30 @@ | |||
44 | /** | 44 | /** |
45 | * Generic logging shorthand | 45 | * Generic logging shorthand |
46 | */ | 46 | */ |
47 | #define LOG(kind, ...) GNUNET_log_from (kind, "testbed-api", __VA_ARGS__) | 47 | #define LOG(kind, ...) GNUNET_log_from(kind, "testbed-api", __VA_ARGS__) |
48 | 48 | ||
49 | /** | 49 | /** |
50 | * Debug logging | 50 | * Debug logging |
51 | */ | 51 | */ |
52 | #define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 52 | #define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Relative time seconds shorthand | 55 | * Relative time seconds shorthand |
56 | */ | 56 | */ |
57 | #define TIME_REL_SECS(sec) \ | 57 | #define TIME_REL_SECS(sec) \ |
58 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) | 58 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, sec) |
59 | 59 | ||
60 | 60 | ||
61 | /** | 61 | /** |
62 | * Default server message sending retry timeout | 62 | * Default server message sending retry timeout |
63 | */ | 63 | */ |
64 | #define TIMEOUT_REL TIME_REL_SECS (1) | 64 | #define TIMEOUT_REL TIME_REL_SECS(1) |
65 | 65 | ||
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Context data for forwarded Operation | 68 | * Context data for forwarded Operation |
69 | */ | 69 | */ |
70 | struct ForwardedOperationData | 70 | struct ForwardedOperationData { |
71 | { | ||
72 | |||
73 | /** | 71 | /** |
74 | * The callback to call when reply is available | 72 | * The callback to call when reply is available |
75 | */ | 73 | */ |
@@ -85,8 +83,7 @@ struct ForwardedOperationData | |||
85 | /** | 83 | /** |
86 | * Context data for get slave config operations | 84 | * Context data for get slave config operations |
87 | */ | 85 | */ |
88 | struct GetSlaveConfigData | 86 | struct GetSlaveConfigData { |
89 | { | ||
90 | /** | 87 | /** |
91 | * The id of the slave controller | 88 | * The id of the slave controller |
92 | */ | 89 | */ |
@@ -97,8 +94,7 @@ struct GetSlaveConfigData | |||
97 | /** | 94 | /** |
98 | * Context data for controller link operations | 95 | * Context data for controller link operations |
99 | */ | 96 | */ |
100 | struct ControllerLinkData | 97 | struct ControllerLinkData { |
101 | { | ||
102 | /** | 98 | /** |
103 | * The controller link message | 99 | * The controller link message |
104 | */ | 100 | */ |
@@ -114,8 +110,7 @@ struct ControllerLinkData | |||
114 | /** | 110 | /** |
115 | * Date context for OP_SHUTDOWN_PEERS operations | 111 | * Date context for OP_SHUTDOWN_PEERS operations |
116 | */ | 112 | */ |
117 | struct ShutdownPeersData | 113 | struct ShutdownPeersData { |
118 | { | ||
119 | /** | 114 | /** |
120 | * The operation completion callback to call | 115 | * The operation completion callback to call |
121 | */ | 116 | */ |
@@ -131,8 +126,7 @@ struct ShutdownPeersData | |||
131 | /** | 126 | /** |
132 | * An entry in the stack for keeping operations which are about to expire | 127 | * An entry in the stack for keeping operations which are about to expire |
133 | */ | 128 | */ |
134 | struct ExpireOperationEntry | 129 | struct ExpireOperationEntry { |
135 | { | ||
136 | /** | 130 | /** |
137 | * DLL head; new entries are to be inserted here | 131 | * DLL head; new entries are to be inserted here |
138 | */ | 132 | */ |
@@ -167,13 +161,13 @@ static struct ExpireOperationEntry *exop_tail; | |||
167 | * @param op the operation to insert | 161 | * @param op the operation to insert |
168 | */ | 162 | */ |
169 | static void | 163 | static void |
170 | exop_insert (struct GNUNET_TESTBED_Operation *op) | 164 | exop_insert(struct GNUNET_TESTBED_Operation *op) |
171 | { | 165 | { |
172 | struct ExpireOperationEntry *entry; | 166 | struct ExpireOperationEntry *entry; |
173 | 167 | ||
174 | entry = GNUNET_new (struct ExpireOperationEntry); | 168 | entry = GNUNET_new(struct ExpireOperationEntry); |
175 | entry->op = op; | 169 | entry->op = op; |
176 | GNUNET_CONTAINER_DLL_insert_tail (exop_head, exop_tail, entry); | 170 | GNUNET_CONTAINER_DLL_insert_tail(exop_head, exop_tail, entry); |
177 | } | 171 | } |
178 | 172 | ||
179 | 173 | ||
@@ -189,7 +183,7 @@ exop_insert (struct GNUNET_TESTBED_Operation *op) | |||
189 | * paramenter will return GNUNET_NO) | 183 | * paramenter will return GNUNET_NO) |
190 | */ | 184 | */ |
191 | static int | 185 | static int |
192 | exop_check (const struct GNUNET_TESTBED_Operation *const op) | 186 | exop_check(const struct GNUNET_TESTBED_Operation *const op) |
193 | { | 187 | { |
194 | struct ExpireOperationEntry *entry; | 188 | struct ExpireOperationEntry *entry; |
195 | struct ExpireOperationEntry *entry2; | 189 | struct ExpireOperationEntry *entry2; |
@@ -198,24 +192,24 @@ exop_check (const struct GNUNET_TESTBED_Operation *const op) | |||
198 | found = GNUNET_NO; | 192 | found = GNUNET_NO; |
199 | entry = exop_head; | 193 | entry = exop_head; |
200 | while (NULL != entry) | 194 | while (NULL != entry) |
201 | { | ||
202 | if (op == entry->op) | ||
203 | { | 195 | { |
204 | found = GNUNET_YES; | 196 | if (op == entry->op) |
205 | break; | 197 | { |
198 | found = GNUNET_YES; | ||
199 | break; | ||
200 | } | ||
201 | entry = entry->next; | ||
206 | } | 202 | } |
207 | entry = entry->next; | ||
208 | } | ||
209 | if (GNUNET_NO == found) | 203 | if (GNUNET_NO == found) |
210 | return GNUNET_NO; | 204 | return GNUNET_NO; |
211 | /* Truncate the tail */ | 205 | /* Truncate the tail */ |
212 | while (NULL != entry) | 206 | while (NULL != entry) |
213 | { | 207 | { |
214 | entry2 = entry->next; | 208 | entry2 = entry->next; |
215 | GNUNET_CONTAINER_DLL_remove (exop_head, exop_tail, entry); | 209 | GNUNET_CONTAINER_DLL_remove(exop_head, exop_tail, entry); |
216 | GNUNET_free (entry); | 210 | GNUNET_free(entry); |
217 | entry = entry2; | 211 | entry = entry2; |
218 | } | 212 | } |
219 | return GNUNET_YES; | 213 | return GNUNET_YES; |
220 | } | 214 | } |
221 | 215 | ||
@@ -223,8 +217,7 @@ exop_check (const struct GNUNET_TESTBED_Operation *const op) | |||
223 | /** | 217 | /** |
224 | * Context information to be used while searching for operation contexts | 218 | * Context information to be used while searching for operation contexts |
225 | */ | 219 | */ |
226 | struct SearchContext | 220 | struct SearchContext { |
227 | { | ||
228 | /** | 221 | /** |
229 | * The result of the search | 222 | * The result of the search |
230 | */ | 223 | */ |
@@ -247,13 +240,13 @@ struct SearchContext | |||
247 | * #GNUNET_NO if not. | 240 | * #GNUNET_NO if not. |
248 | */ | 241 | */ |
249 | static int | 242 | static int |
250 | opc_search_iterator (void *cls, uint32_t key, void *value) | 243 | opc_search_iterator(void *cls, uint32_t key, void *value) |
251 | { | 244 | { |
252 | struct SearchContext *sc = cls; | 245 | struct SearchContext *sc = cls; |
253 | struct OperationContext *opc = value; | 246 | struct OperationContext *opc = value; |
254 | 247 | ||
255 | GNUNET_assert (NULL != opc); | 248 | GNUNET_assert(NULL != opc); |
256 | GNUNET_assert (NULL == sc->opc); | 249 | GNUNET_assert(NULL == sc->opc); |
257 | if (opc->id != sc->id) | 250 | if (opc->id != sc->id) |
258 | return GNUNET_YES; | 251 | return GNUNET_YES; |
259 | sc->opc = opc; | 252 | sc->opc = opc; |
@@ -270,18 +263,18 @@ opc_search_iterator (void *cls, uint32_t key, void *value) | |||
270 | * @return the matching operation context; NULL if no match found | 263 | * @return the matching operation context; NULL if no match found |
271 | */ | 264 | */ |
272 | static struct OperationContext * | 265 | static struct OperationContext * |
273 | find_opc (const struct GNUNET_TESTBED_Controller *c, const uint64_t id) | 266 | find_opc(const struct GNUNET_TESTBED_Controller *c, const uint64_t id) |
274 | { | 267 | { |
275 | struct SearchContext sc; | 268 | struct SearchContext sc; |
276 | 269 | ||
277 | sc.id = id; | 270 | sc.id = id; |
278 | sc.opc = NULL; | 271 | sc.opc = NULL; |
279 | GNUNET_assert (NULL != c->opc_map); | 272 | GNUNET_assert(NULL != c->opc_map); |
280 | if (GNUNET_SYSERR != | 273 | if (GNUNET_SYSERR != |
281 | GNUNET_CONTAINER_multihashmap32_get_multiple (c->opc_map, | 274 | GNUNET_CONTAINER_multihashmap32_get_multiple(c->opc_map, |
282 | (uint32_t) id, | 275 | (uint32_t)id, |
283 | &opc_search_iterator, | 276 | &opc_search_iterator, |
284 | &sc)) | 277 | &sc)) |
285 | return NULL; | 278 | return NULL; |
286 | return sc.opc; | 279 | return sc.opc; |
287 | } | 280 | } |
@@ -296,16 +289,16 @@ find_opc (const struct GNUNET_TESTBED_Controller *c, const uint64_t id) | |||
296 | * @param opc the operation context to be inserted | 289 | * @param opc the operation context to be inserted |
297 | */ | 290 | */ |
298 | void | 291 | void |
299 | GNUNET_TESTBED_insert_opc_ (struct GNUNET_TESTBED_Controller *c, | 292 | GNUNET_TESTBED_insert_opc_(struct GNUNET_TESTBED_Controller *c, |
300 | struct OperationContext *opc) | 293 | struct OperationContext *opc) |
301 | { | 294 | { |
302 | if (NULL == c->opc_map) | 295 | if (NULL == c->opc_map) |
303 | c->opc_map = GNUNET_CONTAINER_multihashmap32_create (256); | 296 | c->opc_map = GNUNET_CONTAINER_multihashmap32_create(256); |
304 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap32_put ( | 297 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap32_put( |
305 | c->opc_map, | 298 | c->opc_map, |
306 | (uint32_t) opc->id, | 299 | (uint32_t)opc->id, |
307 | opc, | 300 | opc, |
308 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 301 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
309 | } | 302 | } |
310 | 303 | ||
311 | 304 | ||
@@ -317,17 +310,17 @@ GNUNET_TESTBED_insert_opc_ (struct GNUNET_TESTBED_Controller *c, | |||
317 | * @param opc the operation context to remove | 310 | * @param opc the operation context to remove |
318 | */ | 311 | */ |
319 | void | 312 | void |
320 | GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c, | 313 | GNUNET_TESTBED_remove_opc_(const struct GNUNET_TESTBED_Controller *c, |
321 | struct OperationContext *opc) | 314 | struct OperationContext *opc) |
322 | { | 315 | { |
323 | GNUNET_assert (NULL != c->opc_map); | 316 | GNUNET_assert(NULL != c->opc_map); |
324 | GNUNET_assert (GNUNET_YES == | 317 | GNUNET_assert(GNUNET_YES == |
325 | GNUNET_CONTAINER_multihashmap32_remove (c->opc_map, | 318 | GNUNET_CONTAINER_multihashmap32_remove(c->opc_map, |
326 | (uint32_t) opc->id, | 319 | (uint32_t)opc->id, |
327 | opc)); | 320 | opc)); |
328 | if ((0 == GNUNET_CONTAINER_multihashmap32_size (c->opc_map)) && | 321 | if ((0 == GNUNET_CONTAINER_multihashmap32_size(c->opc_map)) && |
329 | (NULL != c->opcq_empty_cb)) | 322 | (NULL != c->opcq_empty_cb)) |
330 | c->opcq_empty_cb (c->opcq_empty_cls); | 323 | c->opcq_empty_cb(c->opcq_empty_cls); |
331 | } | 324 | } |
332 | 325 | ||
333 | 326 | ||
@@ -339,22 +332,22 @@ GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c, | |||
339 | * @return #GNUNET_OK if message is well-formed | 332 | * @return #GNUNET_OK if message is well-formed |
340 | */ | 333 | */ |
341 | static int | 334 | static int |
342 | check_add_host_confirm (void *cls, | 335 | check_add_host_confirm(void *cls, |
343 | const struct GNUNET_TESTBED_HostConfirmedMessage *msg) | 336 | const struct GNUNET_TESTBED_HostConfirmedMessage *msg) |
344 | { | 337 | { |
345 | const char *emsg; | 338 | const char *emsg; |
346 | uint16_t msg_size; | 339 | uint16_t msg_size; |
347 | 340 | ||
348 | msg_size = ntohs (msg->header.size) - sizeof (*msg); | 341 | msg_size = ntohs(msg->header.size) - sizeof(*msg); |
349 | if (0 == msg_size) | 342 | if (0 == msg_size) |
350 | return GNUNET_OK; | 343 | return GNUNET_OK; |
351 | /* We have an error message */ | 344 | /* We have an error message */ |
352 | emsg = (const char *) &msg[1]; | 345 | emsg = (const char *)&msg[1]; |
353 | if ('\0' != emsg[msg_size - 1]) | 346 | if ('\0' != emsg[msg_size - 1]) |
354 | { | 347 | { |
355 | GNUNET_break (0); | 348 | GNUNET_break(0); |
356 | return GNUNET_SYSERR; | 349 | return GNUNET_SYSERR; |
357 | } | 350 | } |
358 | return GNUNET_OK; | 351 | return GNUNET_OK; |
359 | } | 352 | } |
360 | 353 | ||
@@ -367,8 +360,8 @@ check_add_host_confirm (void *cls, | |||
367 | * @param msg message received | 360 | * @param msg message received |
368 | */ | 361 | */ |
369 | static void | 362 | static void |
370 | handle_add_host_confirm (void *cls, | 363 | handle_add_host_confirm(void *cls, |
371 | const struct GNUNET_TESTBED_HostConfirmedMessage *msg) | 364 | const struct GNUNET_TESTBED_HostConfirmedMessage *msg) |
372 | { | 365 | { |
373 | struct GNUNET_TESTBED_Controller *c = cls; | 366 | struct GNUNET_TESTBED_Controller *c = cls; |
374 | struct GNUNET_TESTBED_HostRegistrationHandle *rh = c->rh; | 367 | struct GNUNET_TESTBED_HostRegistrationHandle *rh = c->rh; |
@@ -377,31 +370,31 @@ handle_add_host_confirm (void *cls, | |||
377 | 370 | ||
378 | if (NULL == rh) | 371 | if (NULL == rh) |
379 | return; | 372 | return; |
380 | if (GNUNET_TESTBED_host_get_id_ (rh->host) != ntohl (msg->host_id)) | 373 | if (GNUNET_TESTBED_host_get_id_(rh->host) != ntohl(msg->host_id)) |
381 | { | 374 | { |
382 | LOG_DEBUG ("Mismatch in host id's %u, %u of host confirm msg\n", | 375 | LOG_DEBUG("Mismatch in host id's %u, %u of host confirm msg\n", |
383 | GNUNET_TESTBED_host_get_id_ (rh->host), | 376 | GNUNET_TESTBED_host_get_id_(rh->host), |
384 | ntohl (msg->host_id)); | 377 | ntohl(msg->host_id)); |
385 | return; | 378 | return; |
386 | } | 379 | } |
387 | c->rh = NULL; | 380 | c->rh = NULL; |
388 | msg_size = ntohs (msg->header.size) - sizeof (*msg); | 381 | msg_size = ntohs(msg->header.size) - sizeof(*msg); |
389 | if (0 == msg_size) | 382 | if (0 == msg_size) |
390 | { | 383 | { |
391 | LOG_DEBUG ("Host %u successfully registered\n", ntohl (msg->host_id)); | 384 | LOG_DEBUG("Host %u successfully registered\n", ntohl(msg->host_id)); |
392 | GNUNET_TESTBED_mark_host_registered_at_ (rh->host, c); | 385 | GNUNET_TESTBED_mark_host_registered_at_(rh->host, c); |
393 | rh->cc (rh->cc_cls, NULL); | 386 | rh->cc(rh->cc_cls, NULL); |
394 | GNUNET_free (rh); | 387 | GNUNET_free(rh); |
395 | return; | 388 | return; |
396 | } | 389 | } |
397 | /* We have an error message */ | 390 | /* We have an error message */ |
398 | emsg = (const char *) &msg[1]; | 391 | emsg = (const char *)&msg[1]; |
399 | LOG (GNUNET_ERROR_TYPE_ERROR, | 392 | LOG(GNUNET_ERROR_TYPE_ERROR, |
400 | _ ("Adding host %u failed with error: %s\n"), | 393 | _("Adding host %u failed with error: %s\n"), |
401 | ntohl (msg->host_id), | 394 | ntohl(msg->host_id), |
402 | emsg); | 395 | emsg); |
403 | rh->cc (rh->cc_cls, emsg); | 396 | rh->cc(rh->cc_cls, emsg); |
404 | GNUNET_free (rh); | 397 | GNUNET_free(rh); |
405 | } | 398 | } |
406 | 399 | ||
407 | 400 | ||
@@ -413,19 +406,19 @@ handle_add_host_confirm (void *cls, | |||
413 | * @param msg the message | 406 | * @param msg the message |
414 | */ | 407 | */ |
415 | static void | 408 | static void |
416 | handle_forwarded_operation_msg (void *cls, | 409 | handle_forwarded_operation_msg(void *cls, |
417 | struct OperationContext *opc, | 410 | struct OperationContext *opc, |
418 | const struct GNUNET_MessageHeader *msg) | 411 | const struct GNUNET_MessageHeader *msg) |
419 | { | 412 | { |
420 | struct GNUNET_TESTBED_Controller *c = cls; | 413 | struct GNUNET_TESTBED_Controller *c = cls; |
421 | struct ForwardedOperationData *fo_data; | 414 | struct ForwardedOperationData *fo_data; |
422 | 415 | ||
423 | fo_data = opc->data; | 416 | fo_data = opc->data; |
424 | if (NULL != fo_data->cc) | 417 | if (NULL != fo_data->cc) |
425 | fo_data->cc (fo_data->cc_cls, msg); | 418 | fo_data->cc(fo_data->cc_cls, msg); |
426 | GNUNET_TESTBED_remove_opc_ (c, opc); | 419 | GNUNET_TESTBED_remove_opc_(c, opc); |
427 | GNUNET_free (fo_data); | 420 | GNUNET_free(fo_data); |
428 | GNUNET_free (opc); | 421 | GNUNET_free(opc); |
429 | } | 422 | } |
430 | 423 | ||
431 | 424 | ||
@@ -437,7 +430,7 @@ handle_forwarded_operation_msg (void *cls, | |||
437 | * @param msg message received | 430 | * @param msg message received |
438 | */ | 431 | */ |
439 | static void | 432 | static void |
440 | handle_opsuccess ( | 433 | handle_opsuccess( |
441 | void *cls, | 434 | void *cls, |
442 | const struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg) | 435 | const struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg) |
443 | { | 436 | { |
@@ -448,13 +441,13 @@ handle_opsuccess ( | |||
448 | struct GNUNET_TESTBED_EventInformation event; | 441 | struct GNUNET_TESTBED_EventInformation event; |
449 | uint64_t op_id; | 442 | uint64_t op_id; |
450 | 443 | ||
451 | op_id = GNUNET_ntohll (msg->operation_id); | 444 | op_id = GNUNET_ntohll(msg->operation_id); |
452 | LOG_DEBUG ("Operation %lu successful\n", op_id); | 445 | LOG_DEBUG("Operation %lu successful\n", op_id); |
453 | if (NULL == (opc = find_opc (c, op_id))) | 446 | if (NULL == (opc = find_opc(c, op_id))) |
454 | { | 447 | { |
455 | LOG_DEBUG ("Operation not found\n"); | 448 | LOG_DEBUG("Operation not found\n"); |
456 | return; | 449 | return; |
457 | } | 450 | } |
458 | event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; | 451 | event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; |
459 | event.op = opc->op; | 452 | event.op = opc->op; |
460 | event.op_cls = opc->op_cls; | 453 | event.op_cls = opc->op_cls; |
@@ -463,66 +456,71 @@ handle_opsuccess ( | |||
463 | op_comp_cb = NULL; | 456 | op_comp_cb = NULL; |
464 | op_comp_cb_cls = NULL; | 457 | op_comp_cb_cls = NULL; |
465 | switch (opc->type) | 458 | switch (opc->type) |
466 | { | 459 | { |
467 | case OP_FORWARDED: { | 460 | case OP_FORWARDED: { |
468 | handle_forwarded_operation_msg (c, | 461 | handle_forwarded_operation_msg(c, |
469 | opc, | 462 | opc, |
470 | (const struct GNUNET_MessageHeader *) msg); | 463 | (const struct GNUNET_MessageHeader *)msg); |
471 | return; | 464 | return; |
472 | } | 465 | } |
473 | break; | 466 | break; |
474 | case OP_PEER_DESTROY: { | 467 | |
475 | struct GNUNET_TESTBED_Peer *peer; | 468 | case OP_PEER_DESTROY: { |
476 | 469 | struct GNUNET_TESTBED_Peer *peer; | |
477 | peer = opc->data; | 470 | |
478 | GNUNET_TESTBED_peer_deregister_ (peer); | 471 | peer = opc->data; |
479 | GNUNET_free (peer); | 472 | GNUNET_TESTBED_peer_deregister_(peer); |
480 | opc->data = NULL; | 473 | GNUNET_free(peer); |
481 | //PEERDESTROYDATA | 474 | opc->data = NULL; |
482 | } | 475 | //PEERDESTROYDATA |
483 | break; | 476 | } |
484 | case OP_SHUTDOWN_PEERS: { | 477 | break; |
485 | struct ShutdownPeersData *data; | 478 | |
486 | 479 | case OP_SHUTDOWN_PEERS: { | |
487 | data = opc->data; | 480 | struct ShutdownPeersData *data; |
488 | op_comp_cb = data->cb; | 481 | |
489 | op_comp_cb_cls = data->cb_cls; | 482 | data = opc->data; |
490 | GNUNET_free (data); | 483 | op_comp_cb = data->cb; |
491 | opc->data = NULL; | 484 | op_comp_cb_cls = data->cb_cls; |
492 | GNUNET_TESTBED_cleanup_peers_ (); | 485 | GNUNET_free(data); |
493 | } | 486 | opc->data = NULL; |
494 | break; | 487 | GNUNET_TESTBED_cleanup_peers_(); |
495 | case OP_MANAGE_SERVICE: { | 488 | } |
496 | struct ManageServiceData *data; | 489 | break; |
497 | 490 | ||
498 | GNUNET_assert (NULL != (data = opc->data)); | 491 | case OP_MANAGE_SERVICE: { |
499 | op_comp_cb = data->cb; | 492 | struct ManageServiceData *data; |
500 | op_comp_cb_cls = data->cb_cls; | 493 | |
501 | GNUNET_free (data); | 494 | GNUNET_assert(NULL != (data = opc->data)); |
502 | opc->data = NULL; | 495 | op_comp_cb = data->cb; |
503 | } | 496 | op_comp_cb_cls = data->cb_cls; |
504 | break; | 497 | GNUNET_free(data); |
505 | case OP_PEER_RECONFIGURE: | 498 | opc->data = NULL; |
499 | } | ||
506 | break; | 500 | break; |
507 | default: | 501 | |
508 | GNUNET_assert (0); | 502 | case OP_PEER_RECONFIGURE: |
509 | } | 503 | break; |
510 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 504 | |
505 | default: | ||
506 | GNUNET_assert(0); | ||
507 | } | ||
508 | GNUNET_TESTBED_remove_opc_(opc->c, opc); | ||
511 | opc->state = OPC_STATE_FINISHED; | 509 | opc->state = OPC_STATE_FINISHED; |
512 | exop_insert (event.op); | 510 | exop_insert(event.op); |
513 | if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) | 511 | if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) |
514 | { | 512 | { |
515 | if (NULL != c->cc) | 513 | if (NULL != c->cc) |
516 | c->cc (c->cc_cls, &event); | 514 | c->cc(c->cc_cls, &event); |
517 | if (GNUNET_NO == exop_check (event.op)) | 515 | if (GNUNET_NO == exop_check(event.op)) |
518 | return; | 516 | return; |
519 | } | 517 | } |
520 | else | 518 | else |
521 | LOG_DEBUG ("Not calling callback\n"); | 519 | LOG_DEBUG("Not calling callback\n"); |
522 | if (NULL != op_comp_cb) | 520 | if (NULL != op_comp_cb) |
523 | op_comp_cb (op_comp_cb_cls, event.op, NULL); | 521 | op_comp_cb(op_comp_cb_cls, event.op, NULL); |
524 | /* You could have marked the operation as done by now */ | 522 | /* You could have marked the operation as done by now */ |
525 | GNUNET_break (GNUNET_NO == exop_check (event.op)); | 523 | GNUNET_break(GNUNET_NO == exop_check(event.op)); |
526 | } | 524 | } |
527 | 525 | ||
528 | 526 | ||
@@ -534,7 +532,7 @@ handle_opsuccess ( | |||
534 | * @param msg message received | 532 | * @param msg message received |
535 | */ | 533 | */ |
536 | static void | 534 | static void |
537 | handle_peer_create_success ( | 535 | handle_peer_create_success( |
538 | void *cls, | 536 | void *cls, |
539 | const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *msg) | 537 | const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *msg) |
540 | { | 538 | { |
@@ -547,40 +545,40 @@ handle_peer_create_success ( | |||
547 | void *cb_cls; | 545 | void *cb_cls; |
548 | uint64_t op_id; | 546 | uint64_t op_id; |
549 | 547 | ||
550 | GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage) == | 548 | GNUNET_assert(sizeof(struct GNUNET_TESTBED_PeerCreateSuccessEventMessage) == |
551 | ntohs (msg->header.size)); | 549 | ntohs(msg->header.size)); |
552 | op_id = GNUNET_ntohll (msg->operation_id); | 550 | op_id = GNUNET_ntohll(msg->operation_id); |
553 | if (NULL == (opc = find_opc (c, op_id))) | 551 | if (NULL == (opc = find_opc(c, op_id))) |
554 | { | 552 | { |
555 | LOG_DEBUG ("Operation context for PeerCreateSuccessEvent not found\n"); | 553 | LOG_DEBUG("Operation context for PeerCreateSuccessEvent not found\n"); |
556 | return; | 554 | return; |
557 | } | 555 | } |
558 | if (OP_FORWARDED == opc->type) | 556 | if (OP_FORWARDED == opc->type) |
559 | { | 557 | { |
560 | handle_forwarded_operation_msg (c, | 558 | handle_forwarded_operation_msg(c, |
561 | opc, | 559 | opc, |
562 | (const struct GNUNET_MessageHeader *) msg); | 560 | (const struct GNUNET_MessageHeader *)msg); |
563 | return; | 561 | return; |
564 | } | 562 | } |
565 | GNUNET_assert (OP_PEER_CREATE == opc->type); | 563 | GNUNET_assert(OP_PEER_CREATE == opc->type); |
566 | GNUNET_assert (NULL != opc->data); | 564 | GNUNET_assert(NULL != opc->data); |
567 | data = opc->data; | 565 | data = opc->data; |
568 | GNUNET_assert (NULL != data->peer); | 566 | GNUNET_assert(NULL != data->peer); |
569 | peer = data->peer; | 567 | peer = data->peer; |
570 | GNUNET_assert (peer->unique_id == ntohl (msg->peer_id)); | 568 | GNUNET_assert(peer->unique_id == ntohl(msg->peer_id)); |
571 | peer->state = TESTBED_PS_CREATED; | 569 | peer->state = TESTBED_PS_CREATED; |
572 | GNUNET_TESTBED_peer_register_ (peer); | 570 | GNUNET_TESTBED_peer_register_(peer); |
573 | cb = data->cb; | 571 | cb = data->cb; |
574 | cb_cls = data->cls; | 572 | cb_cls = data->cls; |
575 | op = opc->op; | 573 | op = opc->op; |
576 | GNUNET_free (opc->data); | 574 | GNUNET_free(opc->data); |
577 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 575 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
578 | opc->state = OPC_STATE_FINISHED; | 576 | opc->state = OPC_STATE_FINISHED; |
579 | exop_insert (op); | 577 | exop_insert(op); |
580 | if (NULL != cb) | 578 | if (NULL != cb) |
581 | cb (cb_cls, peer, NULL); | 579 | cb(cb_cls, peer, NULL); |
582 | /* You could have marked the operation as done by now */ | 580 | /* You could have marked the operation as done by now */ |
583 | GNUNET_break (GNUNET_NO == exop_check (op)); | 581 | GNUNET_break(GNUNET_NO == exop_check(op)); |
584 | } | 582 | } |
585 | 583 | ||
586 | 584 | ||
@@ -592,7 +590,7 @@ handle_peer_create_success ( | |||
592 | * @param msg message received | 590 | * @param msg message received |
593 | */ | 591 | */ |
594 | static void | 592 | static void |
595 | handle_peer_event (void *cls, const struct GNUNET_TESTBED_PeerEventMessage *msg) | 593 | handle_peer_event(void *cls, const struct GNUNET_TESTBED_PeerEventMessage *msg) |
596 | { | 594 | { |
597 | struct GNUNET_TESTBED_Controller *c = cls; | 595 | struct GNUNET_TESTBED_Controller *c = cls; |
598 | struct OperationContext *opc; | 596 | struct OperationContext *opc; |
@@ -604,62 +602,64 @@ handle_peer_event (void *cls, const struct GNUNET_TESTBED_PeerEventMessage *msg) | |||
604 | uint64_t op_id; | 602 | uint64_t op_id; |
605 | uint64_t mask; | 603 | uint64_t mask; |
606 | 604 | ||
607 | GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerEventMessage) == | 605 | GNUNET_assert(sizeof(struct GNUNET_TESTBED_PeerEventMessage) == |
608 | ntohs (msg->header.size)); | 606 | ntohs(msg->header.size)); |
609 | op_id = GNUNET_ntohll (msg->operation_id); | 607 | op_id = GNUNET_ntohll(msg->operation_id); |
610 | if (NULL == (opc = find_opc (c, op_id))) | 608 | if (NULL == (opc = find_opc(c, op_id))) |
611 | { | 609 | { |
612 | LOG_DEBUG ("Operation not found\n"); | 610 | LOG_DEBUG("Operation not found\n"); |
613 | return; | 611 | return; |
614 | } | 612 | } |
615 | if (OP_FORWARDED == opc->type) | 613 | if (OP_FORWARDED == opc->type) |
616 | { | 614 | { |
617 | handle_forwarded_operation_msg (c, | 615 | handle_forwarded_operation_msg(c, |
618 | opc, | 616 | opc, |
619 | (const struct GNUNET_MessageHeader *) msg); | 617 | (const struct GNUNET_MessageHeader *)msg); |
620 | return; | 618 | return; |
621 | } | 619 | } |
622 | GNUNET_assert ((OP_PEER_START == opc->type) || (OP_PEER_STOP == opc->type)); | 620 | GNUNET_assert((OP_PEER_START == opc->type) || (OP_PEER_STOP == opc->type)); |
623 | data = opc->data; | 621 | data = opc->data; |
624 | GNUNET_assert (NULL != data); | 622 | GNUNET_assert(NULL != data); |
625 | peer = data->peer; | 623 | peer = data->peer; |
626 | GNUNET_assert (NULL != peer); | 624 | GNUNET_assert(NULL != peer); |
627 | event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type); | 625 | event.type = (enum GNUNET_TESTBED_EventType)ntohl(msg->event_type); |
628 | event.op = opc->op; | 626 | event.op = opc->op; |
629 | event.op_cls = opc->op_cls; | 627 | event.op_cls = opc->op_cls; |
630 | switch (event.type) | 628 | switch (event.type) |
631 | { | 629 | { |
632 | case GNUNET_TESTBED_ET_PEER_START: | 630 | case GNUNET_TESTBED_ET_PEER_START: |
633 | peer->state = TESTBED_PS_STARTED; | 631 | peer->state = TESTBED_PS_STARTED; |
634 | event.details.peer_start.host = peer->host; | 632 | event.details.peer_start.host = peer->host; |
635 | event.details.peer_start.peer = peer; | 633 | event.details.peer_start.peer = peer; |
636 | break; | 634 | break; |
637 | case GNUNET_TESTBED_ET_PEER_STOP: | 635 | |
638 | peer->state = TESTBED_PS_STOPPED; | 636 | case GNUNET_TESTBED_ET_PEER_STOP: |
639 | event.details.peer_stop.peer = peer; | 637 | peer->state = TESTBED_PS_STOPPED; |
640 | break; | 638 | event.details.peer_stop.peer = peer; |
641 | default: | 639 | break; |
642 | GNUNET_assert (0); /* We should never reach this state */ | 640 | |
643 | } | 641 | default: |
642 | GNUNET_assert(0); /* We should never reach this state */ | ||
643 | } | ||
644 | pcc = data->pcc; | 644 | pcc = data->pcc; |
645 | pcc_cls = data->pcc_cls; | 645 | pcc_cls = data->pcc_cls; |
646 | GNUNET_free (data); | 646 | GNUNET_free(data); |
647 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 647 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
648 | opc->state = OPC_STATE_FINISHED; | 648 | opc->state = OPC_STATE_FINISHED; |
649 | exop_insert (event.op); | 649 | exop_insert(event.op); |
650 | mask = 1LL << GNUNET_TESTBED_ET_PEER_START; | 650 | mask = 1LL << GNUNET_TESTBED_ET_PEER_START; |
651 | mask |= 1LL << GNUNET_TESTBED_ET_PEER_STOP; | 651 | mask |= 1LL << GNUNET_TESTBED_ET_PEER_STOP; |
652 | if (0 != (mask & c->event_mask)) | 652 | if (0 != (mask & c->event_mask)) |
653 | { | 653 | { |
654 | if (NULL != c->cc) | 654 | if (NULL != c->cc) |
655 | c->cc (c->cc_cls, &event); | 655 | c->cc(c->cc_cls, &event); |
656 | if (GNUNET_NO == exop_check (event.op)) | 656 | if (GNUNET_NO == exop_check(event.op)) |
657 | return; | 657 | return; |
658 | } | 658 | } |
659 | if (NULL != pcc) | 659 | if (NULL != pcc) |
660 | pcc (pcc_cls, NULL); | 660 | pcc(pcc_cls, NULL); |
661 | /* You could have marked the operation as done by now */ | 661 | /* You could have marked the operation as done by now */ |
662 | GNUNET_break (GNUNET_NO == exop_check (event.op)); | 662 | GNUNET_break(GNUNET_NO == exop_check(event.op)); |
663 | } | 663 | } |
664 | 664 | ||
665 | 665 | ||
@@ -671,8 +671,8 @@ handle_peer_event (void *cls, const struct GNUNET_TESTBED_PeerEventMessage *msg) | |||
671 | * @param msg message received | 671 | * @param msg message received |
672 | */ | 672 | */ |
673 | static void | 673 | static void |
674 | handle_peer_conevent (void *cls, | 674 | handle_peer_conevent(void *cls, |
675 | const struct GNUNET_TESTBED_ConnectionEventMessage *msg) | 675 | const struct GNUNET_TESTBED_ConnectionEventMessage *msg) |
676 | { | 676 | { |
677 | struct GNUNET_TESTBED_Controller *c = cls; | 677 | struct GNUNET_TESTBED_Controller *c = cls; |
678 | struct OperationContext *opc; | 678 | struct OperationContext *opc; |
@@ -683,57 +683,59 @@ handle_peer_conevent (void *cls, | |||
683 | uint64_t op_id; | 683 | uint64_t op_id; |
684 | uint64_t mask; | 684 | uint64_t mask; |
685 | 685 | ||
686 | op_id = GNUNET_ntohll (msg->operation_id); | 686 | op_id = GNUNET_ntohll(msg->operation_id); |
687 | if (NULL == (opc = find_opc (c, op_id))) | 687 | if (NULL == (opc = find_opc(c, op_id))) |
688 | { | 688 | { |
689 | LOG_DEBUG ("Operation not found\n"); | 689 | LOG_DEBUG("Operation not found\n"); |
690 | return; | 690 | return; |
691 | } | 691 | } |
692 | if (OP_FORWARDED == opc->type) | 692 | if (OP_FORWARDED == opc->type) |
693 | { | 693 | { |
694 | handle_forwarded_operation_msg (c, | 694 | handle_forwarded_operation_msg(c, |
695 | opc, | 695 | opc, |
696 | (const struct GNUNET_MessageHeader *) msg); | 696 | (const struct GNUNET_MessageHeader *)msg); |
697 | return; | 697 | return; |
698 | } | 698 | } |
699 | GNUNET_assert (OP_OVERLAY_CONNECT == opc->type); | 699 | GNUNET_assert(OP_OVERLAY_CONNECT == opc->type); |
700 | GNUNET_assert (NULL != (data = opc->data)); | 700 | GNUNET_assert(NULL != (data = opc->data)); |
701 | GNUNET_assert ((ntohl (msg->peer1) == data->p1->unique_id) && | 701 | GNUNET_assert((ntohl(msg->peer1) == data->p1->unique_id) && |
702 | (ntohl (msg->peer2) == data->p2->unique_id)); | 702 | (ntohl(msg->peer2) == data->p2->unique_id)); |
703 | event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type); | 703 | event.type = (enum GNUNET_TESTBED_EventType)ntohl(msg->event_type); |
704 | event.op = opc->op; | 704 | event.op = opc->op; |
705 | event.op_cls = opc->op_cls; | 705 | event.op_cls = opc->op_cls; |
706 | switch (event.type) | 706 | switch (event.type) |
707 | { | 707 | { |
708 | case GNUNET_TESTBED_ET_CONNECT: | 708 | case GNUNET_TESTBED_ET_CONNECT: |
709 | event.details.peer_connect.peer1 = data->p1; | 709 | event.details.peer_connect.peer1 = data->p1; |
710 | event.details.peer_connect.peer2 = data->p2; | 710 | event.details.peer_connect.peer2 = data->p2; |
711 | break; | 711 | break; |
712 | case GNUNET_TESTBED_ET_DISCONNECT: | 712 | |
713 | GNUNET_assert (0); /* FIXME: implement */ | 713 | case GNUNET_TESTBED_ET_DISCONNECT: |
714 | break; | 714 | GNUNET_assert(0); /* FIXME: implement */ |
715 | default: | 715 | break; |
716 | GNUNET_assert (0); /* Should never reach here */ | 716 | |
717 | break; | 717 | default: |
718 | } | 718 | GNUNET_assert(0); /* Should never reach here */ |
719 | break; | ||
720 | } | ||
719 | cb = data->cb; | 721 | cb = data->cb; |
720 | cb_cls = data->cb_cls; | 722 | cb_cls = data->cb_cls; |
721 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 723 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
722 | opc->state = OPC_STATE_FINISHED; | 724 | opc->state = OPC_STATE_FINISHED; |
723 | exop_insert (event.op); | 725 | exop_insert(event.op); |
724 | mask = 1LL << GNUNET_TESTBED_ET_CONNECT; | 726 | mask = 1LL << GNUNET_TESTBED_ET_CONNECT; |
725 | mask |= 1LL << GNUNET_TESTBED_ET_DISCONNECT; | 727 | mask |= 1LL << GNUNET_TESTBED_ET_DISCONNECT; |
726 | if (0 != (mask & c->event_mask)) | 728 | if (0 != (mask & c->event_mask)) |
727 | { | 729 | { |
728 | if (NULL != c->cc) | 730 | if (NULL != c->cc) |
729 | c->cc (c->cc_cls, &event); | 731 | c->cc(c->cc_cls, &event); |
730 | if (GNUNET_NO == exop_check (event.op)) | 732 | if (GNUNET_NO == exop_check(event.op)) |
731 | return; | 733 | return; |
732 | } | 734 | } |
733 | if (NULL != cb) | 735 | if (NULL != cb) |
734 | cb (cb_cls, opc->op, NULL); | 736 | cb(cb_cls, opc->op, NULL); |
735 | /* You could have marked the operation as done by now */ | 737 | /* You could have marked the operation as done by now */ |
736 | GNUNET_break (GNUNET_NO == exop_check (event.op)); | 738 | GNUNET_break(GNUNET_NO == exop_check(event.op)); |
737 | } | 739 | } |
738 | 740 | ||
739 | 741 | ||
@@ -745,7 +747,7 @@ handle_peer_conevent (void *cls, | |||
745 | * @param msg message received | 747 | * @param msg message received |
746 | */ | 748 | */ |
747 | static int | 749 | static int |
748 | check_peer_config ( | 750 | check_peer_config( |
749 | void *cls, | 751 | void *cls, |
750 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg) | 752 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg) |
751 | { | 753 | { |
@@ -762,7 +764,7 @@ check_peer_config ( | |||
762 | * @param msg message received | 764 | * @param msg message received |
763 | */ | 765 | */ |
764 | static void | 766 | static void |
765 | handle_peer_config ( | 767 | handle_peer_config( |
766 | void *cls, | 768 | void *cls, |
767 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg) | 769 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg) |
768 | { | 770 | { |
@@ -775,52 +777,54 @@ handle_peer_config ( | |||
775 | void *cb_cls; | 777 | void *cb_cls; |
776 | uint64_t op_id; | 778 | uint64_t op_id; |
777 | 779 | ||
778 | op_id = GNUNET_ntohll (msg->operation_id); | 780 | op_id = GNUNET_ntohll(msg->operation_id); |
779 | if (NULL == (opc = find_opc (c, op_id))) | 781 | if (NULL == (opc = find_opc(c, op_id))) |
780 | { | 782 | { |
781 | LOG_DEBUG ("Operation not found\n"); | 783 | LOG_DEBUG("Operation not found\n"); |
782 | return; | 784 | return; |
783 | } | 785 | } |
784 | if (OP_FORWARDED == opc->type) | 786 | if (OP_FORWARDED == opc->type) |
785 | { | 787 | { |
786 | handle_forwarded_operation_msg (c, opc, &msg->header); | 788 | handle_forwarded_operation_msg(c, opc, &msg->header); |
787 | return; | 789 | return; |
788 | } | 790 | } |
789 | data = opc->data; | 791 | data = opc->data; |
790 | GNUNET_assert (NULL != data); | 792 | GNUNET_assert(NULL != data); |
791 | peer = data->peer; | 793 | peer = data->peer; |
792 | GNUNET_assert (NULL != peer); | 794 | GNUNET_assert(NULL != peer); |
793 | GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id); | 795 | GNUNET_assert(ntohl(msg->peer_id) == peer->unique_id); |
794 | pinfo = GNUNET_new (struct GNUNET_TESTBED_PeerInformation); | 796 | pinfo = GNUNET_new(struct GNUNET_TESTBED_PeerInformation); |
795 | pinfo->pit = data->pit; | 797 | pinfo->pit = data->pit; |
796 | cb = data->cb; | 798 | cb = data->cb; |
797 | cb_cls = data->cb_cls; | 799 | cb_cls = data->cb_cls; |
798 | GNUNET_assert (NULL != cb); | 800 | GNUNET_assert(NULL != cb); |
799 | GNUNET_free (data); | 801 | GNUNET_free(data); |
800 | opc->data = NULL; | 802 | opc->data = NULL; |
801 | switch (pinfo->pit) | 803 | switch (pinfo->pit) |
802 | { | 804 | { |
803 | case GNUNET_TESTBED_PIT_IDENTITY: | 805 | case GNUNET_TESTBED_PIT_IDENTITY: |
804 | pinfo->result.id = GNUNET_new (struct GNUNET_PeerIdentity); | 806 | pinfo->result.id = GNUNET_new(struct GNUNET_PeerIdentity); |
805 | GNUNET_memcpy (pinfo->result.id, | 807 | GNUNET_memcpy(pinfo->result.id, |
806 | &msg->peer_identity, | 808 | &msg->peer_identity, |
807 | sizeof (struct GNUNET_PeerIdentity)); | 809 | sizeof(struct GNUNET_PeerIdentity)); |
808 | break; | 810 | break; |
809 | case GNUNET_TESTBED_PIT_CONFIGURATION: | 811 | |
810 | pinfo->result.cfg = /* Freed in oprelease_peer_getinfo */ | 812 | case GNUNET_TESTBED_PIT_CONFIGURATION: |
811 | GNUNET_TESTBED_extract_config_ (&msg->header); | 813 | pinfo->result.cfg = /* Freed in oprelease_peer_getinfo */ |
812 | break; | 814 | GNUNET_TESTBED_extract_config_(&msg->header); |
813 | case GNUNET_TESTBED_PIT_GENERIC: | 815 | break; |
814 | GNUNET_assert (0); /* never reach here */ | 816 | |
815 | break; | 817 | case GNUNET_TESTBED_PIT_GENERIC: |
816 | } | 818 | GNUNET_assert(0); /* never reach here */ |
819 | break; | ||
820 | } | ||
817 | opc->data = pinfo; | 821 | opc->data = pinfo; |
818 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 822 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
819 | opc->state = OPC_STATE_FINISHED; | 823 | opc->state = OPC_STATE_FINISHED; |
820 | cb (cb_cls, opc->op, pinfo, NULL); | 824 | cb(cb_cls, opc->op, pinfo, NULL); |
821 | /* We dont check whether the operation is marked as done here as the | 825 | /* We dont check whether the operation is marked as done here as the |
822 | operation contains data (cfg/identify) which will be freed at a later point | 826 | operation contains data (cfg/identify) which will be freed at a later point |
823 | */ | 827 | */ |
824 | } | 828 | } |
825 | 829 | ||
826 | 830 | ||
@@ -833,7 +837,7 @@ handle_peer_config ( | |||
833 | * @return #GNUNET_OK if message is well-formed | 837 | * @return #GNUNET_OK if message is well-formed |
834 | */ | 838 | */ |
835 | static int | 839 | static int |
836 | check_op_fail_event ( | 840 | check_op_fail_event( |
837 | void *cls, | 841 | void *cls, |
838 | const struct GNUNET_TESTBED_OperationFailureEventMessage *msg) | 842 | const struct GNUNET_TESTBED_OperationFailureEventMessage *msg) |
839 | { | 843 | { |
@@ -850,7 +854,7 @@ check_op_fail_event ( | |||
850 | * @param msg message received | 854 | * @param msg message received |
851 | */ | 855 | */ |
852 | static void | 856 | static void |
853 | handle_op_fail_event ( | 857 | handle_op_fail_event( |
854 | void *cls, | 858 | void *cls, |
855 | const struct GNUNET_TESTBED_OperationFailureEventMessage *msg) | 859 | const struct GNUNET_TESTBED_OperationFailureEventMessage *msg) |
856 | { | 860 | { |
@@ -861,34 +865,34 @@ handle_op_fail_event ( | |||
861 | uint64_t mask; | 865 | uint64_t mask; |
862 | struct GNUNET_TESTBED_EventInformation event; | 866 | struct GNUNET_TESTBED_EventInformation event; |
863 | 867 | ||
864 | op_id = GNUNET_ntohll (msg->operation_id); | 868 | op_id = GNUNET_ntohll(msg->operation_id); |
865 | if (NULL == (opc = find_opc (c, op_id))) | 869 | if (NULL == (opc = find_opc(c, op_id))) |
866 | { | 870 | { |
867 | LOG_DEBUG ("Operation not found\n"); | 871 | LOG_DEBUG("Operation not found\n"); |
868 | return; | 872 | return; |
869 | } | 873 | } |
870 | if (OP_FORWARDED == opc->type) | 874 | if (OP_FORWARDED == opc->type) |
871 | { | 875 | { |
872 | handle_forwarded_operation_msg (c, | 876 | handle_forwarded_operation_msg(c, |
873 | opc, | 877 | opc, |
874 | (const struct GNUNET_MessageHeader *) msg); | 878 | (const struct GNUNET_MessageHeader *)msg); |
875 | return; | 879 | return; |
876 | } | 880 | } |
877 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 881 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
878 | opc->state = OPC_STATE_FINISHED; | 882 | opc->state = OPC_STATE_FINISHED; |
879 | emsg = GNUNET_TESTBED_parse_error_string_ (msg); | 883 | emsg = GNUNET_TESTBED_parse_error_string_(msg); |
880 | if (NULL == emsg) | 884 | if (NULL == emsg) |
881 | emsg = "Unknown error"; | 885 | emsg = "Unknown error"; |
882 | if (OP_PEER_INFO == opc->type) | 886 | if (OP_PEER_INFO == opc->type) |
883 | { | 887 | { |
884 | struct PeerInfoData *data; | 888 | struct PeerInfoData *data; |
885 | 889 | ||
886 | data = opc->data; | 890 | data = opc->data; |
887 | if (NULL != data->cb) | 891 | if (NULL != data->cb) |
888 | data->cb (data->cb_cls, opc->op, NULL, emsg); | 892 | data->cb(data->cb_cls, opc->op, NULL, emsg); |
889 | GNUNET_free (data); | 893 | GNUNET_free(data); |
890 | return; /* We do not call controller callback for peer info */ | 894 | return; /* We do not call controller callback for peer info */ |
891 | } | 895 | } |
892 | event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; | 896 | event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; |
893 | event.op = opc->op; | 897 | event.op = opc->op; |
894 | event.op_cls = opc->op_cls; | 898 | event.op_cls = opc->op_cls; |
@@ -896,79 +900,88 @@ handle_op_fail_event ( | |||
896 | event.details.operation_finished.generic = NULL; | 900 | event.details.operation_finished.generic = NULL; |
897 | mask = (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 901 | mask = (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
898 | if ((0 != (mask & c->event_mask)) && (NULL != c->cc)) | 902 | if ((0 != (mask & c->event_mask)) && (NULL != c->cc)) |
899 | { | 903 | { |
900 | exop_insert (event.op); | 904 | exop_insert(event.op); |
901 | c->cc (c->cc_cls, &event); | 905 | c->cc(c->cc_cls, &event); |
902 | if (GNUNET_NO == exop_check (event.op)) | 906 | if (GNUNET_NO == exop_check(event.op)) |
903 | return; | 907 | return; |
904 | } | 908 | } |
905 | switch (opc->type) | 909 | switch (opc->type) |
906 | { | 910 | { |
907 | case OP_PEER_CREATE: { | 911 | case OP_PEER_CREATE: { |
908 | struct PeerCreateData *data; | 912 | struct PeerCreateData *data; |
909 | 913 | ||
910 | data = opc->data; | 914 | data = opc->data; |
911 | GNUNET_free (data->peer); | 915 | GNUNET_free(data->peer); |
912 | if (NULL != data->cb) | 916 | if (NULL != data->cb) |
913 | data->cb (data->cls, NULL, emsg); | 917 | data->cb(data->cls, NULL, emsg); |
914 | GNUNET_free (data); | 918 | GNUNET_free(data); |
915 | } | 919 | } |
916 | break; | ||
917 | case OP_PEER_START: | ||
918 | case OP_PEER_STOP: { | ||
919 | struct PeerEventData *data; | ||
920 | |||
921 | data = opc->data; | ||
922 | if (NULL != data->pcc) | ||
923 | data->pcc (data->pcc_cls, emsg); | ||
924 | GNUNET_free (data); | ||
925 | } | ||
926 | break; | ||
927 | case OP_PEER_DESTROY: | ||
928 | break; | 920 | break; |
929 | case OP_PEER_INFO: | 921 | |
930 | GNUNET_assert (0); | 922 | case OP_PEER_START: |
931 | case OP_OVERLAY_CONNECT: { | 923 | case OP_PEER_STOP: { |
932 | struct OverlayConnectData *data; | 924 | struct PeerEventData *data; |
933 | 925 | ||
934 | data = opc->data; | 926 | data = opc->data; |
935 | GNUNET_TESTBED_operation_mark_failed (opc->op); | 927 | if (NULL != data->pcc) |
936 | if (NULL != data->cb) | 928 | data->pcc(data->pcc_cls, emsg); |
937 | data->cb (data->cb_cls, opc->op, emsg); | 929 | GNUNET_free(data); |
938 | } | 930 | } |
939 | break; | 931 | break; |
940 | case OP_FORWARDED: | 932 | |
941 | GNUNET_assert (0); | 933 | case OP_PEER_DESTROY: |
942 | case OP_LINK_CONTROLLERS: /* No secondary callback */ | 934 | break; |
935 | |||
936 | case OP_PEER_INFO: | ||
937 | GNUNET_assert(0); | ||
938 | |||
939 | case OP_OVERLAY_CONNECT: { | ||
940 | struct OverlayConnectData *data; | ||
941 | |||
942 | data = opc->data; | ||
943 | GNUNET_TESTBED_operation_mark_failed(opc->op); | ||
944 | if (NULL != data->cb) | ||
945 | data->cb(data->cb_cls, opc->op, emsg); | ||
946 | } | ||
943 | break; | 947 | break; |
944 | case OP_SHUTDOWN_PEERS: { | 948 | |
945 | struct ShutdownPeersData *data; | 949 | case OP_FORWARDED: |
946 | 950 | GNUNET_assert(0); | |
947 | data = opc->data; | 951 | |
948 | GNUNET_free (data); /* FIXME: Decide whether we call data->op_cb */ | 952 | case OP_LINK_CONTROLLERS: /* No secondary callback */ |
949 | opc->data = NULL; | 953 | break; |
950 | } | 954 | |
951 | break; | 955 | case OP_SHUTDOWN_PEERS: { |
952 | case OP_MANAGE_SERVICE: { | 956 | struct ShutdownPeersData *data; |
953 | struct ManageServiceData *data = opc->data; | 957 | |
954 | GNUNET_TESTBED_OperationCompletionCallback cb; | 958 | data = opc->data; |
955 | void *cb_cls; | 959 | GNUNET_free(data); /* FIXME: Decide whether we call data->op_cb */ |
956 | 960 | opc->data = NULL; | |
957 | GNUNET_assert (NULL != data); | 961 | } |
958 | cb = data->cb; | 962 | break; |
959 | cb_cls = data->cb_cls; | 963 | |
960 | GNUNET_free (data); | 964 | case OP_MANAGE_SERVICE: { |
961 | opc->data = NULL; | 965 | struct ManageServiceData *data = opc->data; |
962 | exop_insert (event.op); | 966 | GNUNET_TESTBED_OperationCompletionCallback cb; |
963 | if (NULL != cb) | 967 | void *cb_cls; |
964 | cb (cb_cls, opc->op, emsg); | 968 | |
965 | /* You could have marked the operation as done by now */ | 969 | GNUNET_assert(NULL != data); |
966 | GNUNET_break (GNUNET_NO == exop_check (event.op)); | 970 | cb = data->cb; |
967 | } | 971 | cb_cls = data->cb_cls; |
968 | break; | 972 | GNUNET_free(data); |
969 | default: | 973 | opc->data = NULL; |
970 | GNUNET_break (0); | 974 | exop_insert(event.op); |
971 | } | 975 | if (NULL != cb) |
976 | cb(cb_cls, opc->op, emsg); | ||
977 | /* You could have marked the operation as done by now */ | ||
978 | GNUNET_break(GNUNET_NO == exop_check(event.op)); | ||
979 | } | ||
980 | break; | ||
981 | |||
982 | default: | ||
983 | GNUNET_break(0); | ||
984 | } | ||
972 | } | 985 | } |
973 | 986 | ||
974 | 987 | ||
@@ -980,18 +993,18 @@ handle_op_fail_event ( | |||
980 | * @return newly allocated SlaveGetConfigurationMessage | 993 | * @return newly allocated SlaveGetConfigurationMessage |
981 | */ | 994 | */ |
982 | static struct GNUNET_TESTBED_SlaveGetConfigurationMessage * | 995 | static struct GNUNET_TESTBED_SlaveGetConfigurationMessage * |
983 | GNUNET_TESTBED_generate_slavegetconfig_msg_ (uint64_t op_id, uint32_t slave_id) | 996 | GNUNET_TESTBED_generate_slavegetconfig_msg_(uint64_t op_id, uint32_t slave_id) |
984 | { | 997 | { |
985 | struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg; | 998 | struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg; |
986 | uint16_t msize; | 999 | uint16_t msize; |
987 | 1000 | ||
988 | msize = sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage); | 1001 | msize = sizeof(struct GNUNET_TESTBED_SlaveGetConfigurationMessage); |
989 | msg = GNUNET_malloc (msize); | 1002 | msg = GNUNET_malloc(msize); |
990 | msg->header.size = htons (msize); | 1003 | msg->header.size = htons(msize); |
991 | msg->header.type = | 1004 | msg->header.type = |
992 | htons (GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION); | 1005 | htons(GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION); |
993 | msg->operation_id = GNUNET_htonll (op_id); | 1006 | msg->operation_id = GNUNET_htonll(op_id); |
994 | msg->slave_id = htonl (slave_id); | 1007 | msg->slave_id = htonl(slave_id); |
995 | return msg; | 1008 | return msg; |
996 | } | 1009 | } |
997 | 1010 | ||
@@ -1004,8 +1017,8 @@ GNUNET_TESTBED_generate_slavegetconfig_msg_ (uint64_t op_id, uint32_t slave_id) | |||
1004 | * @param msg message received | 1017 | * @param msg message received |
1005 | */ | 1018 | */ |
1006 | static int | 1019 | static int |
1007 | check_slave_config (void *cls, | 1020 | check_slave_config(void *cls, |
1008 | const struct GNUNET_TESTBED_SlaveConfiguration *msg) | 1021 | const struct GNUNET_TESTBED_SlaveConfiguration *msg) |
1009 | { | 1022 | { |
1010 | /* anything goes? */ | 1023 | /* anything goes? */ |
1011 | return GNUNET_OK; | 1024 | return GNUNET_OK; |
@@ -1020,8 +1033,8 @@ check_slave_config (void *cls, | |||
1020 | * @param msg message received | 1033 | * @param msg message received |
1021 | */ | 1034 | */ |
1022 | static void | 1035 | static void |
1023 | handle_slave_config (void *cls, | 1036 | handle_slave_config(void *cls, |
1024 | const struct GNUNET_TESTBED_SlaveConfiguration *msg) | 1037 | const struct GNUNET_TESTBED_SlaveConfiguration *msg) |
1025 | { | 1038 | { |
1026 | struct GNUNET_TESTBED_Controller *c = cls; | 1039 | struct GNUNET_TESTBED_Controller *c = cls; |
1027 | struct OperationContext *opc; | 1040 | struct OperationContext *opc; |
@@ -1029,30 +1042,30 @@ handle_slave_config (void *cls, | |||
1029 | uint64_t mask; | 1042 | uint64_t mask; |
1030 | struct GNUNET_TESTBED_EventInformation event; | 1043 | struct GNUNET_TESTBED_EventInformation event; |
1031 | 1044 | ||
1032 | op_id = GNUNET_ntohll (msg->operation_id); | 1045 | op_id = GNUNET_ntohll(msg->operation_id); |
1033 | if (NULL == (opc = find_opc (c, op_id))) | 1046 | if (NULL == (opc = find_opc(c, op_id))) |
1034 | { | 1047 | { |
1035 | LOG_DEBUG ("Operation not found\n"); | 1048 | LOG_DEBUG("Operation not found\n"); |
1036 | return; | 1049 | return; |
1037 | } | 1050 | } |
1038 | if (OP_GET_SLAVE_CONFIG != opc->type) | 1051 | if (OP_GET_SLAVE_CONFIG != opc->type) |
1039 | { | 1052 | { |
1040 | GNUNET_break (0); | 1053 | GNUNET_break(0); |
1041 | return; | 1054 | return; |
1042 | } | 1055 | } |
1043 | opc->state = OPC_STATE_FINISHED; | 1056 | opc->state = OPC_STATE_FINISHED; |
1044 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 1057 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
1045 | mask = 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED; | 1058 | mask = 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED; |
1046 | if ((0 != (mask & c->event_mask)) && (NULL != c->cc)) | 1059 | if ((0 != (mask & c->event_mask)) && (NULL != c->cc)) |
1047 | { | 1060 | { |
1048 | opc->data = GNUNET_TESTBED_extract_config_ (&msg->header); | 1061 | opc->data = GNUNET_TESTBED_extract_config_(&msg->header); |
1049 | event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; | 1062 | event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; |
1050 | event.op = opc->op; | 1063 | event.op = opc->op; |
1051 | event.op_cls = opc->op_cls; | 1064 | event.op_cls = opc->op_cls; |
1052 | event.details.operation_finished.generic = opc->data; | 1065 | event.details.operation_finished.generic = opc->data; |
1053 | event.details.operation_finished.emsg = NULL; | 1066 | event.details.operation_finished.emsg = NULL; |
1054 | c->cc (c->cc_cls, &event); | 1067 | c->cc(c->cc_cls, &event); |
1055 | } | 1068 | } |
1056 | } | 1069 | } |
1057 | 1070 | ||
1058 | 1071 | ||
@@ -1065,7 +1078,7 @@ handle_slave_config (void *cls, | |||
1065 | * @return #GNUNET_OK if @a msg is well-formed | 1078 | * @return #GNUNET_OK if @a msg is well-formed |
1066 | */ | 1079 | */ |
1067 | static int | 1080 | static int |
1068 | check_link_controllers_result ( | 1081 | check_link_controllers_result( |
1069 | void *cls, | 1082 | void *cls, |
1070 | const struct GNUNET_TESTBED_ControllerLinkResponse *msg) | 1083 | const struct GNUNET_TESTBED_ControllerLinkResponse *msg) |
1071 | { | 1084 | { |
@@ -1082,7 +1095,7 @@ check_link_controllers_result ( | |||
1082 | * @param msg message received | 1095 | * @param msg message received |
1083 | */ | 1096 | */ |
1084 | static void | 1097 | static void |
1085 | handle_link_controllers_result ( | 1098 | handle_link_controllers_result( |
1086 | void *cls, | 1099 | void *cls, |
1087 | const struct GNUNET_TESTBED_ControllerLinkResponse *msg) | 1100 | const struct GNUNET_TESTBED_ControllerLinkResponse *msg) |
1088 | { | 1101 | { |
@@ -1095,31 +1108,31 @@ handle_link_controllers_result ( | |||
1095 | uint64_t op_id; | 1108 | uint64_t op_id; |
1096 | struct GNUNET_TESTBED_EventInformation event; | 1109 | struct GNUNET_TESTBED_EventInformation event; |
1097 | 1110 | ||
1098 | op_id = GNUNET_ntohll (msg->operation_id); | 1111 | op_id = GNUNET_ntohll(msg->operation_id); |
1099 | if (NULL == (opc = find_opc (c, op_id))) | 1112 | if (NULL == (opc = find_opc(c, op_id))) |
1100 | { | 1113 | { |
1101 | LOG_DEBUG ("Operation not found\n"); | 1114 | LOG_DEBUG("Operation not found\n"); |
1102 | return; | 1115 | return; |
1103 | } | 1116 | } |
1104 | if (OP_FORWARDED == opc->type) | 1117 | if (OP_FORWARDED == opc->type) |
1105 | { | 1118 | { |
1106 | handle_forwarded_operation_msg (c, | 1119 | handle_forwarded_operation_msg(c, |
1107 | opc, | 1120 | opc, |
1108 | (const struct GNUNET_MessageHeader *) msg); | 1121 | (const struct GNUNET_MessageHeader *)msg); |
1109 | return; | 1122 | return; |
1110 | } | 1123 | } |
1111 | if (OP_LINK_CONTROLLERS != opc->type) | 1124 | if (OP_LINK_CONTROLLERS != opc->type) |
1112 | { | 1125 | { |
1113 | GNUNET_break (0); | 1126 | GNUNET_break(0); |
1114 | return; | 1127 | return; |
1115 | } | 1128 | } |
1116 | GNUNET_assert (NULL != (data = opc->data)); | 1129 | GNUNET_assert(NULL != (data = opc->data)); |
1117 | host = GNUNET_TESTBED_host_lookup_by_id_ (data->host_id); | 1130 | host = GNUNET_TESTBED_host_lookup_by_id_(data->host_id); |
1118 | GNUNET_assert (NULL != host); | 1131 | GNUNET_assert(NULL != host); |
1119 | GNUNET_free (data); | 1132 | GNUNET_free(data); |
1120 | opc->data = NULL; | 1133 | opc->data = NULL; |
1121 | opc->state = OPC_STATE_FINISHED; | 1134 | opc->state = OPC_STATE_FINISHED; |
1122 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 1135 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
1123 | event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; | 1136 | event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; |
1124 | event.op = opc->op; | 1137 | event.op = opc->op; |
1125 | event.op_cls = opc->op_cls; | 1138 | event.op_cls = opc->op_cls; |
@@ -1127,37 +1140,37 @@ handle_link_controllers_result ( | |||
1127 | event.details.operation_finished.generic = NULL; | 1140 | event.details.operation_finished.generic = NULL; |
1128 | emsg = NULL; | 1141 | emsg = NULL; |
1129 | cfg = NULL; | 1142 | cfg = NULL; |
1130 | if (GNUNET_NO == ntohs (msg->success)) | 1143 | if (GNUNET_NO == ntohs(msg->success)) |
1131 | { | 1144 | { |
1132 | emsg = | 1145 | emsg = |
1133 | GNUNET_malloc (ntohs (msg->header.size) - | 1146 | GNUNET_malloc(ntohs(msg->header.size) - |
1134 | sizeof (struct GNUNET_TESTBED_ControllerLinkResponse) + 1); | 1147 | sizeof(struct GNUNET_TESTBED_ControllerLinkResponse) + 1); |
1135 | GNUNET_memcpy (emsg, | 1148 | GNUNET_memcpy(emsg, |
1136 | &msg[1], | 1149 | &msg[1], |
1137 | ntohs (msg->header.size) - | 1150 | ntohs(msg->header.size) - |
1138 | sizeof (struct GNUNET_TESTBED_ControllerLinkResponse)); | 1151 | sizeof(struct GNUNET_TESTBED_ControllerLinkResponse)); |
1139 | event.details.operation_finished.emsg = emsg; | 1152 | event.details.operation_finished.emsg = emsg; |
1140 | } | 1153 | } |
1141 | else | 1154 | else |
1142 | { | ||
1143 | if (0 != ntohs (msg->config_size)) | ||
1144 | { | 1155 | { |
1145 | cfg = GNUNET_TESTBED_extract_config_ ( | 1156 | if (0 != ntohs(msg->config_size)) |
1146 | (const struct GNUNET_MessageHeader *) msg); | 1157 | { |
1147 | GNUNET_assert (NULL != cfg); | 1158 | cfg = GNUNET_TESTBED_extract_config_( |
1148 | GNUNET_TESTBED_host_replace_cfg_ (host, cfg); | 1159 | (const struct GNUNET_MessageHeader *)msg); |
1160 | GNUNET_assert(NULL != cfg); | ||
1161 | GNUNET_TESTBED_host_replace_cfg_(host, cfg); | ||
1162 | } | ||
1149 | } | 1163 | } |
1150 | } | ||
1151 | if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) | 1164 | if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) |
1152 | { | 1165 | { |
1153 | if (NULL != c->cc) | 1166 | if (NULL != c->cc) |
1154 | c->cc (c->cc_cls, &event); | 1167 | c->cc(c->cc_cls, &event); |
1155 | } | 1168 | } |
1156 | else | 1169 | else |
1157 | LOG_DEBUG ("Not calling callback\n"); | 1170 | LOG_DEBUG("Not calling callback\n"); |
1158 | if (NULL != cfg) | 1171 | if (NULL != cfg) |
1159 | GNUNET_CONFIGURATION_destroy (cfg); | 1172 | GNUNET_CONFIGURATION_destroy(cfg); |
1160 | GNUNET_free_non_null (emsg); | 1173 | GNUNET_free_non_null(emsg); |
1161 | } | 1174 | } |
1162 | 1175 | ||
1163 | 1176 | ||
@@ -1171,8 +1184,8 @@ handle_link_controllers_result ( | |||
1171 | * down signalling an error (message malformed) | 1184 | * down signalling an error (message malformed) |
1172 | */ | 1185 | */ |
1173 | static int | 1186 | static int |
1174 | check_barrier_status (void *cls, | 1187 | check_barrier_status(void *cls, |
1175 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) | 1188 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) |
1176 | { | 1189 | { |
1177 | uint16_t msize; | 1190 | uint16_t msize; |
1178 | uint16_t name_len; | 1191 | uint16_t name_len; |
@@ -1180,31 +1193,31 @@ check_barrier_status (void *cls, | |||
1180 | const char *name; | 1193 | const char *name; |
1181 | size_t emsg_len; | 1194 | size_t emsg_len; |
1182 | 1195 | ||
1183 | msize = ntohs (msg->header.size); | 1196 | msize = ntohs(msg->header.size); |
1184 | name = msg->data; | 1197 | name = msg->data; |
1185 | name_len = ntohs (msg->name_len); | 1198 | name_len = ntohs(msg->name_len); |
1186 | 1199 | ||
1187 | if (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len + 1 > msize) | 1200 | if (sizeof(struct GNUNET_TESTBED_BarrierStatusMsg) + name_len + 1 > msize) |
1188 | { | 1201 | { |
1189 | GNUNET_break_op (0); | 1202 | GNUNET_break_op(0); |
1190 | return GNUNET_SYSERR; | 1203 | return GNUNET_SYSERR; |
1191 | } | 1204 | } |
1192 | if ('\0' != name[name_len]) | 1205 | if ('\0' != name[name_len]) |
1193 | { | ||
1194 | GNUNET_break_op (0); | ||
1195 | return GNUNET_SYSERR; | ||
1196 | } | ||
1197 | status = ntohs (msg->status); | ||
1198 | if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status) | ||
1199 | { | ||
1200 | emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + | ||
1201 | name_len + 1); /* +1!? */ | ||
1202 | if (0 == emsg_len) | ||
1203 | { | 1206 | { |
1204 | GNUNET_break_op (0); | 1207 | GNUNET_break_op(0); |
1205 | return GNUNET_SYSERR; | 1208 | return GNUNET_SYSERR; |
1206 | } | 1209 | } |
1207 | } | 1210 | status = ntohs(msg->status); |
1211 | if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status) | ||
1212 | { | ||
1213 | emsg_len = msize - (sizeof(struct GNUNET_TESTBED_BarrierStatusMsg) + | ||
1214 | name_len + 1); /* +1!? */ | ||
1215 | if (0 == emsg_len) | ||
1216 | { | ||
1217 | GNUNET_break_op(0); | ||
1218 | return GNUNET_SYSERR; | ||
1219 | } | ||
1220 | } | ||
1208 | return GNUNET_OK; | 1221 | return GNUNET_OK; |
1209 | } | 1222 | } |
1210 | 1223 | ||
@@ -1217,8 +1230,8 @@ check_barrier_status (void *cls, | |||
1217 | * @param msg the barrier status message | 1230 | * @param msg the barrier status message |
1218 | */ | 1231 | */ |
1219 | static void | 1232 | static void |
1220 | handle_barrier_status (void *cls, | 1233 | handle_barrier_status(void *cls, |
1221 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) | 1234 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) |
1222 | { | 1235 | { |
1223 | struct GNUNET_TESTBED_Controller *c = cls; | 1236 | struct GNUNET_TESTBED_Controller *c = cls; |
1224 | struct GNUNET_TESTBED_Barrier *barrier; | 1237 | struct GNUNET_TESTBED_Barrier *barrier; |
@@ -1232,68 +1245,68 @@ handle_barrier_status (void *cls, | |||
1232 | 1245 | ||
1233 | emsg = NULL; | 1246 | emsg = NULL; |
1234 | barrier = NULL; | 1247 | barrier = NULL; |
1235 | msize = ntohs (msg->header.size); | 1248 | msize = ntohs(msg->header.size); |
1236 | if (msize <= sizeof (struct GNUNET_TESTBED_BarrierStatusMsg)) | 1249 | if (msize <= sizeof(struct GNUNET_TESTBED_BarrierStatusMsg)) |
1237 | { | 1250 | { |
1238 | GNUNET_break_op (0); | 1251 | GNUNET_break_op(0); |
1239 | goto cleanup; | 1252 | goto cleanup; |
1240 | } | 1253 | } |
1241 | name = msg->data; | 1254 | name = msg->data; |
1242 | name_len = ntohs (msg->name_len); | 1255 | name_len = ntohs(msg->name_len); |
1243 | if (name_len >= //name_len is strlen(barrier_name) | 1256 | if (name_len >= //name_len is strlen(barrier_name) |
1244 | (msize - ((sizeof msg->header) + sizeof (msg->status)))) | 1257 | (msize - ((sizeof msg->header) + sizeof(msg->status)))) |
1245 | { | ||
1246 | GNUNET_break_op (0); | ||
1247 | goto cleanup; | ||
1248 | } | ||
1249 | if ('\0' != name[name_len]) | ||
1250 | { | ||
1251 | GNUNET_break_op (0); | ||
1252 | goto cleanup; | ||
1253 | } | ||
1254 | LOG_DEBUG ("Received BARRIER_STATUS msg\n"); | ||
1255 | status = ntohs (msg->status); | ||
1256 | if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status) | ||
1257 | { | ||
1258 | status = -1; | ||
1259 | //unlike name_len, emsg_len includes the trailing zero | ||
1260 | emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + | ||
1261 | (name_len + 1)); | ||
1262 | if (0 == emsg_len) | ||
1263 | { | 1258 | { |
1264 | GNUNET_break_op (0); | 1259 | GNUNET_break_op(0); |
1265 | goto cleanup; | 1260 | goto cleanup; |
1266 | } | 1261 | } |
1267 | if ('\0' != (msg->data[(name_len + 1) + (emsg_len - 1)])) | 1262 | if ('\0' != name[name_len]) |
1268 | { | 1263 | { |
1269 | GNUNET_break_op (0); | 1264 | GNUNET_break_op(0); |
1270 | goto cleanup; | 1265 | goto cleanup; |
1271 | } | 1266 | } |
1272 | emsg = GNUNET_malloc (emsg_len); | 1267 | LOG_DEBUG("Received BARRIER_STATUS msg\n"); |
1273 | GNUNET_memcpy (emsg, msg->data + name_len + 1, emsg_len); | 1268 | status = ntohs(msg->status); |
1274 | } | 1269 | if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status) |
1270 | { | ||
1271 | status = -1; | ||
1272 | //unlike name_len, emsg_len includes the trailing zero | ||
1273 | emsg_len = msize - (sizeof(struct GNUNET_TESTBED_BarrierStatusMsg) + | ||
1274 | (name_len + 1)); | ||
1275 | if (0 == emsg_len) | ||
1276 | { | ||
1277 | GNUNET_break_op(0); | ||
1278 | goto cleanup; | ||
1279 | } | ||
1280 | if ('\0' != (msg->data[(name_len + 1) + (emsg_len - 1)])) | ||
1281 | { | ||
1282 | GNUNET_break_op(0); | ||
1283 | goto cleanup; | ||
1284 | } | ||
1285 | emsg = GNUNET_malloc(emsg_len); | ||
1286 | GNUNET_memcpy(emsg, msg->data + name_len + 1, emsg_len); | ||
1287 | } | ||
1275 | if (NULL == c->barrier_map) | 1288 | if (NULL == c->barrier_map) |
1276 | { | 1289 | { |
1277 | GNUNET_break_op (0); | 1290 | GNUNET_break_op(0); |
1278 | goto cleanup; | 1291 | goto cleanup; |
1279 | } | 1292 | } |
1280 | GNUNET_CRYPTO_hash (name, name_len, &key); | 1293 | GNUNET_CRYPTO_hash(name, name_len, &key); |
1281 | barrier = GNUNET_CONTAINER_multihashmap_get (c->barrier_map, &key); | 1294 | barrier = GNUNET_CONTAINER_multihashmap_get(c->barrier_map, &key); |
1282 | if (NULL == barrier) | 1295 | if (NULL == barrier) |
1283 | { | 1296 | { |
1284 | GNUNET_break_op (0); | 1297 | GNUNET_break_op(0); |
1285 | goto cleanup; | 1298 | goto cleanup; |
1286 | } | 1299 | } |
1287 | GNUNET_assert (NULL != barrier->cb); | 1300 | GNUNET_assert(NULL != barrier->cb); |
1288 | if ((GNUNET_YES == barrier->echo) && | 1301 | if ((GNUNET_YES == barrier->echo) && |
1289 | (GNUNET_TESTBED_BARRIERSTATUS_CROSSED == status)) | 1302 | (GNUNET_TESTBED_BARRIERSTATUS_CROSSED == status)) |
1290 | GNUNET_TESTBED_queue_message_ (c, GNUNET_copy_message (&msg->header)); | 1303 | GNUNET_TESTBED_queue_message_(c, GNUNET_copy_message(&msg->header)); |
1291 | barrier->cb (barrier->cls, name, barrier, status, emsg); | 1304 | barrier->cb(barrier->cls, name, barrier, status, emsg); |
1292 | if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED == status) | 1305 | if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED == status) |
1293 | return; /* just initialised; skip cleanup */ | 1306 | return; /* just initialised; skip cleanup */ |
1294 | 1307 | ||
1295 | cleanup: | 1308 | cleanup: |
1296 | GNUNET_free_non_null (emsg); | 1309 | GNUNET_free_non_null(emsg); |
1297 | /** | 1310 | /** |
1298 | * Do not remove the barrier if we did not echo the status back; this is | 1311 | * Do not remove the barrier if we did not echo the status back; this is |
1299 | * required at the chained testbed controller setup to ensure the only the | 1312 | * required at the chained testbed controller setup to ensure the only the |
@@ -1301,7 +1314,7 @@ cleanup: | |||
1301 | * propagates the status. | 1314 | * propagates the status. |
1302 | */ | 1315 | */ |
1303 | if ((NULL != barrier) && (GNUNET_YES == barrier->echo)) | 1316 | if ((NULL != barrier) && (GNUNET_YES == barrier->echo)) |
1304 | GNUNET_TESTBED_barrier_remove_ (barrier); | 1317 | GNUNET_TESTBED_barrier_remove_(barrier); |
1305 | } | 1318 | } |
1306 | 1319 | ||
1307 | 1320 | ||
@@ -1312,22 +1325,22 @@ cleanup: | |||
1312 | * @param msg the message to queue | 1325 | * @param msg the message to queue |
1313 | */ | 1326 | */ |
1314 | void | 1327 | void |
1315 | GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, | 1328 | GNUNET_TESTBED_queue_message_(struct GNUNET_TESTBED_Controller *controller, |
1316 | struct GNUNET_MessageHeader *msg) | 1329 | struct GNUNET_MessageHeader *msg) |
1317 | { | 1330 | { |
1318 | struct GNUNET_MQ_Envelope *env; | 1331 | struct GNUNET_MQ_Envelope *env; |
1319 | struct GNUNET_MessageHeader *m2; | 1332 | struct GNUNET_MessageHeader *m2; |
1320 | uint16_t type; | 1333 | uint16_t type; |
1321 | uint16_t size; | 1334 | uint16_t size; |
1322 | 1335 | ||
1323 | type = ntohs (msg->type); | 1336 | type = ntohs(msg->type); |
1324 | size = ntohs (msg->size); | 1337 | size = ntohs(msg->size); |
1325 | GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) && | 1338 | GNUNET_assert((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) && |
1326 | (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type)); | 1339 | (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type)); |
1327 | env = GNUNET_MQ_msg_extra (m2, size - sizeof (*m2), type); | 1340 | env = GNUNET_MQ_msg_extra(m2, size - sizeof(*m2), type); |
1328 | GNUNET_memcpy (m2, msg, size); | 1341 | GNUNET_memcpy(m2, msg, size); |
1329 | GNUNET_free (msg); | 1342 | GNUNET_free(msg); |
1330 | GNUNET_MQ_send (controller->mq, env); | 1343 | GNUNET_MQ_send(controller->mq, env); |
1331 | } | 1344 | } |
1332 | 1345 | ||
1333 | 1346 | ||
@@ -1346,7 +1359,7 @@ GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, | |||
1346 | * operation | 1359 | * operation |
1347 | */ | 1360 | */ |
1348 | struct OperationContext * | 1361 | struct OperationContext * |
1349 | GNUNET_TESTBED_forward_operation_msg_ ( | 1362 | GNUNET_TESTBED_forward_operation_msg_( |
1350 | struct GNUNET_TESTBED_Controller *controller, | 1363 | struct GNUNET_TESTBED_Controller *controller, |
1351 | uint64_t operation_id, | 1364 | uint64_t operation_id, |
1352 | const struct GNUNET_MessageHeader *msg, | 1365 | const struct GNUNET_MessageHeader *msg, |
@@ -1357,21 +1370,21 @@ GNUNET_TESTBED_forward_operation_msg_ ( | |||
1357 | struct ForwardedOperationData *data; | 1370 | struct ForwardedOperationData *data; |
1358 | struct GNUNET_MQ_Envelope *env; | 1371 | struct GNUNET_MQ_Envelope *env; |
1359 | struct GNUNET_MessageHeader *m2; | 1372 | struct GNUNET_MessageHeader *m2; |
1360 | uint16_t type = ntohs (msg->type); | 1373 | uint16_t type = ntohs(msg->type); |
1361 | uint16_t size = ntohs (msg->size); | 1374 | uint16_t size = ntohs(msg->size); |
1362 | 1375 | ||
1363 | env = GNUNET_MQ_msg_extra (m2, size - sizeof (*m2), type); | 1376 | env = GNUNET_MQ_msg_extra(m2, size - sizeof(*m2), type); |
1364 | GNUNET_memcpy (m2, msg, size); | 1377 | GNUNET_memcpy(m2, msg, size); |
1365 | GNUNET_MQ_send (controller->mq, env); | 1378 | GNUNET_MQ_send(controller->mq, env); |
1366 | data = GNUNET_new (struct ForwardedOperationData); | 1379 | data = GNUNET_new(struct ForwardedOperationData); |
1367 | data->cc = cc; | 1380 | data->cc = cc; |
1368 | data->cc_cls = cc_cls; | 1381 | data->cc_cls = cc_cls; |
1369 | opc = GNUNET_new (struct OperationContext); | 1382 | opc = GNUNET_new(struct OperationContext); |
1370 | opc->c = controller; | 1383 | opc->c = controller; |
1371 | opc->type = OP_FORWARDED; | 1384 | opc->type = OP_FORWARDED; |
1372 | opc->data = data; | 1385 | opc->data = data; |
1373 | opc->id = operation_id; | 1386 | opc->id = operation_id; |
1374 | GNUNET_TESTBED_insert_opc_ (controller, opc); | 1387 | GNUNET_TESTBED_insert_opc_(controller, opc); |
1375 | return opc; | 1388 | return opc; |
1376 | } | 1389 | } |
1377 | 1390 | ||
@@ -1383,11 +1396,11 @@ GNUNET_TESTBED_forward_operation_msg_ ( | |||
1383 | * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_() | 1396 | * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_() |
1384 | */ | 1397 | */ |
1385 | void | 1398 | void |
1386 | GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc) | 1399 | GNUNET_TESTBED_forward_operation_msg_cancel_(struct OperationContext *opc) |
1387 | { | 1400 | { |
1388 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 1401 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
1389 | GNUNET_free (opc->data); | 1402 | GNUNET_free(opc->data); |
1390 | GNUNET_free (opc); | 1403 | GNUNET_free(opc); |
1391 | } | 1404 | } |
1392 | 1405 | ||
1393 | 1406 | ||
@@ -1398,19 +1411,19 @@ GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc) | |||
1398 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 1411 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
1399 | */ | 1412 | */ |
1400 | static void | 1413 | static void |
1401 | opstart_link_controllers (void *cls) | 1414 | opstart_link_controllers(void *cls) |
1402 | { | 1415 | { |
1403 | struct OperationContext *opc = cls; | 1416 | struct OperationContext *opc = cls; |
1404 | struct ControllerLinkData *data; | 1417 | struct ControllerLinkData *data; |
1405 | struct GNUNET_TESTBED_ControllerLinkRequest *msg; | 1418 | struct GNUNET_TESTBED_ControllerLinkRequest *msg; |
1406 | 1419 | ||
1407 | GNUNET_assert (NULL != opc->data); | 1420 | GNUNET_assert(NULL != opc->data); |
1408 | data = opc->data; | 1421 | data = opc->data; |
1409 | msg = data->msg; | 1422 | msg = data->msg; |
1410 | data->msg = NULL; | 1423 | data->msg = NULL; |
1411 | opc->state = OPC_STATE_STARTED; | 1424 | opc->state = OPC_STATE_STARTED; |
1412 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | 1425 | GNUNET_TESTBED_insert_opc_(opc->c, opc); |
1413 | GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); | 1426 | GNUNET_TESTBED_queue_message_(opc->c, &msg->header); |
1414 | } | 1427 | } |
1415 | 1428 | ||
1416 | 1429 | ||
@@ -1420,25 +1433,27 @@ opstart_link_controllers (void *cls) | |||
1420 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 1433 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
1421 | */ | 1434 | */ |
1422 | static void | 1435 | static void |
1423 | oprelease_link_controllers (void *cls) | 1436 | oprelease_link_controllers(void *cls) |
1424 | { | 1437 | { |
1425 | struct OperationContext *opc = cls; | 1438 | struct OperationContext *opc = cls; |
1426 | struct ControllerLinkData *data; | 1439 | struct ControllerLinkData *data; |
1427 | 1440 | ||
1428 | data = opc->data; | 1441 | data = opc->data; |
1429 | switch (opc->state) | 1442 | switch (opc->state) |
1430 | { | 1443 | { |
1431 | case OPC_STATE_INIT: | 1444 | case OPC_STATE_INIT: |
1432 | GNUNET_free (data->msg); | 1445 | GNUNET_free(data->msg); |
1433 | break; | 1446 | break; |
1434 | case OPC_STATE_STARTED: | 1447 | |
1435 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 1448 | case OPC_STATE_STARTED: |
1436 | break; | 1449 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
1437 | case OPC_STATE_FINISHED: | 1450 | break; |
1438 | break; | 1451 | |
1439 | } | 1452 | case OPC_STATE_FINISHED: |
1440 | GNUNET_free_non_null (data); | 1453 | break; |
1441 | GNUNET_free (opc); | 1454 | } |
1455 | GNUNET_free_non_null(data); | ||
1456 | GNUNET_free(opc); | ||
1442 | } | 1457 | } |
1443 | 1458 | ||
1444 | 1459 | ||
@@ -1448,19 +1463,19 @@ oprelease_link_controllers (void *cls) | |||
1448 | * @param cls the OperationContext of type OP_GET_SLAVE_CONFIG | 1463 | * @param cls the OperationContext of type OP_GET_SLAVE_CONFIG |
1449 | */ | 1464 | */ |
1450 | static void | 1465 | static void |
1451 | opstart_get_slave_config (void *cls) | 1466 | opstart_get_slave_config(void *cls) |
1452 | { | 1467 | { |
1453 | struct OperationContext *opc = cls; | 1468 | struct OperationContext *opc = cls; |
1454 | struct GetSlaveConfigData *data = opc->data; | 1469 | struct GetSlaveConfigData *data = opc->data; |
1455 | struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg; | 1470 | struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg; |
1456 | 1471 | ||
1457 | GNUNET_assert (NULL != data); | 1472 | GNUNET_assert(NULL != data); |
1458 | msg = GNUNET_TESTBED_generate_slavegetconfig_msg_ (opc->id, data->slave_id); | 1473 | msg = GNUNET_TESTBED_generate_slavegetconfig_msg_(opc->id, data->slave_id); |
1459 | GNUNET_free (opc->data); | 1474 | GNUNET_free(opc->data); |
1460 | data = NULL; | 1475 | data = NULL; |
1461 | opc->data = NULL; | 1476 | opc->data = NULL; |
1462 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | 1477 | GNUNET_TESTBED_insert_opc_(opc->c, opc); |
1463 | GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); | 1478 | GNUNET_TESTBED_queue_message_(opc->c, &msg->header); |
1464 | opc->state = OPC_STATE_STARTED; | 1479 | opc->state = OPC_STATE_STARTED; |
1465 | } | 1480 | } |
1466 | 1481 | ||
@@ -1471,24 +1486,26 @@ opstart_get_slave_config (void *cls) | |||
1471 | * @param cls the OperationContext of type OP_GET_SLAVE_CONFIG | 1486 | * @param cls the OperationContext of type OP_GET_SLAVE_CONFIG |
1472 | */ | 1487 | */ |
1473 | static void | 1488 | static void |
1474 | oprelease_get_slave_config (void *cls) | 1489 | oprelease_get_slave_config(void *cls) |
1475 | { | 1490 | { |
1476 | struct OperationContext *opc = cls; | 1491 | struct OperationContext *opc = cls; |
1477 | 1492 | ||
1478 | switch (opc->state) | 1493 | switch (opc->state) |
1479 | { | 1494 | { |
1480 | case OPC_STATE_INIT: | 1495 | case OPC_STATE_INIT: |
1481 | GNUNET_free (opc->data); | 1496 | GNUNET_free(opc->data); |
1482 | break; | 1497 | break; |
1483 | case OPC_STATE_STARTED: | 1498 | |
1484 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 1499 | case OPC_STATE_STARTED: |
1485 | break; | 1500 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
1486 | case OPC_STATE_FINISHED: | 1501 | break; |
1487 | if (NULL != opc->data) | 1502 | |
1488 | GNUNET_CONFIGURATION_destroy (opc->data); | 1503 | case OPC_STATE_FINISHED: |
1489 | break; | 1504 | if (NULL != opc->data) |
1490 | } | 1505 | GNUNET_CONFIGURATION_destroy(opc->data); |
1491 | GNUNET_free (opc); | 1506 | break; |
1507 | } | ||
1508 | GNUNET_free(opc); | ||
1492 | } | 1509 | } |
1493 | 1510 | ||
1494 | 1511 | ||
@@ -1501,13 +1518,13 @@ oprelease_get_slave_config (void *cls) | |||
1501 | * @param error error code | 1518 | * @param error error code |
1502 | */ | 1519 | */ |
1503 | static void | 1520 | static void |
1504 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 1521 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
1505 | { | 1522 | { |
1506 | /* struct GNUNET_TESTBED_Controller *c = cls; */ | 1523 | /* struct GNUNET_TESTBED_Controller *c = cls; */ |
1507 | 1524 | ||
1508 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Encountered MQ error: %d\n", error); | 1525 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Encountered MQ error: %d\n", error); |
1509 | /* now what? */ | 1526 | /* now what? */ |
1510 | GNUNET_SCHEDULER_shutdown (); /* seems most reasonable */ | 1527 | GNUNET_SCHEDULER_shutdown(); /* seems most reasonable */ |
1511 | } | 1528 | } |
1512 | 1529 | ||
1513 | 1530 | ||
@@ -1527,58 +1544,58 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
1527 | * @return handle to the controller | 1544 | * @return handle to the controller |
1528 | */ | 1545 | */ |
1529 | struct GNUNET_TESTBED_Controller * | 1546 | struct GNUNET_TESTBED_Controller * |
1530 | GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, | 1547 | GNUNET_TESTBED_controller_connect(struct GNUNET_TESTBED_Host *host, |
1531 | uint64_t event_mask, | 1548 | uint64_t event_mask, |
1532 | GNUNET_TESTBED_ControllerCallback cc, | 1549 | GNUNET_TESTBED_ControllerCallback cc, |
1533 | void *cc_cls) | 1550 | void *cc_cls) |
1534 | { | 1551 | { |
1535 | struct GNUNET_TESTBED_Controller *controller = | 1552 | struct GNUNET_TESTBED_Controller *controller = |
1536 | GNUNET_new (struct GNUNET_TESTBED_Controller); | 1553 | GNUNET_new(struct GNUNET_TESTBED_Controller); |
1537 | struct GNUNET_MQ_MessageHandler handlers[] = | 1554 | struct GNUNET_MQ_MessageHandler handlers[] = |
1538 | {GNUNET_MQ_hd_var_size (add_host_confirm, | 1555 | { GNUNET_MQ_hd_var_size(add_host_confirm, |
1539 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS, | 1556 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS, |
1540 | struct GNUNET_TESTBED_HostConfirmedMessage, | 1557 | struct GNUNET_TESTBED_HostConfirmedMessage, |
1541 | controller), | 1558 | controller), |
1542 | GNUNET_MQ_hd_fixed_size (peer_conevent, | 1559 | GNUNET_MQ_hd_fixed_size(peer_conevent, |
1543 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT, | 1560 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT, |
1544 | struct GNUNET_TESTBED_ConnectionEventMessage, | 1561 | struct GNUNET_TESTBED_ConnectionEventMessage, |
1545 | controller), | ||
1546 | GNUNET_MQ_hd_fixed_size (opsuccess, | ||
1547 | GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS, | ||
1548 | struct | ||
1549 | GNUNET_TESTBED_GenericOperationSuccessEventMessage, | ||
1550 | controller), | ||
1551 | GNUNET_MQ_hd_var_size (op_fail_event, | ||
1552 | GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT, | ||
1553 | struct GNUNET_TESTBED_OperationFailureEventMessage, | ||
1554 | controller), | 1562 | controller), |
1555 | GNUNET_MQ_hd_fixed_size (peer_create_success, | 1563 | GNUNET_MQ_hd_fixed_size(opsuccess, |
1556 | GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS, | 1564 | GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS, |
1557 | struct | ||
1558 | GNUNET_TESTBED_PeerCreateSuccessEventMessage, | ||
1559 | controller), | ||
1560 | GNUNET_MQ_hd_fixed_size (peer_event, | ||
1561 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT, | ||
1562 | struct GNUNET_TESTBED_PeerEventMessage, | ||
1563 | controller), | ||
1564 | GNUNET_MQ_hd_var_size (peer_config, | ||
1565 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION, | ||
1566 | struct | 1565 | struct |
1567 | GNUNET_TESTBED_PeerConfigurationInformationMessage, | 1566 | GNUNET_TESTBED_GenericOperationSuccessEventMessage, |
1568 | controller), | 1567 | controller), |
1569 | GNUNET_MQ_hd_var_size (slave_config, | 1568 | GNUNET_MQ_hd_var_size(op_fail_event, |
1570 | GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION, | 1569 | GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT, |
1571 | struct GNUNET_TESTBED_SlaveConfiguration, | 1570 | struct GNUNET_TESTBED_OperationFailureEventMessage, |
1572 | controller), | 1571 | controller), |
1573 | GNUNET_MQ_hd_var_size (link_controllers_result, | 1572 | GNUNET_MQ_hd_fixed_size(peer_create_success, |
1574 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT, | 1573 | GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS, |
1575 | struct GNUNET_TESTBED_ControllerLinkResponse, | 1574 | struct |
1575 | GNUNET_TESTBED_PeerCreateSuccessEventMessage, | ||
1576 | controller), | 1576 | controller), |
1577 | GNUNET_MQ_hd_var_size (barrier_status, | 1577 | GNUNET_MQ_hd_fixed_size(peer_event, |
1578 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, | 1578 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT, |
1579 | struct GNUNET_TESTBED_BarrierStatusMsg, | 1579 | struct GNUNET_TESTBED_PeerEventMessage, |
1580 | controller), | 1580 | controller), |
1581 | GNUNET_MQ_handler_end ()}; | 1581 | GNUNET_MQ_hd_var_size(peer_config, |
1582 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION, | ||
1583 | struct | ||
1584 | GNUNET_TESTBED_PeerConfigurationInformationMessage, | ||
1585 | controller), | ||
1586 | GNUNET_MQ_hd_var_size(slave_config, | ||
1587 | GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION, | ||
1588 | struct GNUNET_TESTBED_SlaveConfiguration, | ||
1589 | controller), | ||
1590 | GNUNET_MQ_hd_var_size(link_controllers_result, | ||
1591 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT, | ||
1592 | struct GNUNET_TESTBED_ControllerLinkResponse, | ||
1593 | controller), | ||
1594 | GNUNET_MQ_hd_var_size(barrier_status, | ||
1595 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, | ||
1596 | struct GNUNET_TESTBED_BarrierStatusMsg, | ||
1597 | controller), | ||
1598 | GNUNET_MQ_handler_end() }; | ||
1582 | struct GNUNET_TESTBED_InitMessage *msg; | 1599 | struct GNUNET_TESTBED_InitMessage *msg; |
1583 | struct GNUNET_MQ_Envelope *env; | 1600 | struct GNUNET_MQ_Envelope *env; |
1584 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 1601 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
@@ -1588,75 +1605,75 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, | |||
1588 | unsigned long long max_parallel_topology_config_operations; | 1605 | unsigned long long max_parallel_topology_config_operations; |
1589 | size_t slen; | 1606 | size_t slen; |
1590 | 1607 | ||
1591 | GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host))); | 1608 | GNUNET_assert(NULL != (cfg = GNUNET_TESTBED_host_get_cfg_(host))); |
1592 | if (GNUNET_OK != | 1609 | if (GNUNET_OK != |
1593 | GNUNET_CONFIGURATION_get_value_number (cfg, | 1610 | GNUNET_CONFIGURATION_get_value_number(cfg, |
1594 | "testbed", | 1611 | "testbed", |
1595 | "MAX_PARALLEL_OPERATIONS", | 1612 | "MAX_PARALLEL_OPERATIONS", |
1596 | &max_parallel_operations)) | 1613 | &max_parallel_operations)) |
1597 | { | 1614 | { |
1598 | GNUNET_break (0); | 1615 | GNUNET_break(0); |
1599 | GNUNET_free (controller); | 1616 | GNUNET_free(controller); |
1600 | return NULL; | 1617 | return NULL; |
1601 | } | 1618 | } |
1602 | if (GNUNET_OK != | 1619 | if (GNUNET_OK != |
1603 | GNUNET_CONFIGURATION_get_value_number (cfg, | 1620 | GNUNET_CONFIGURATION_get_value_number(cfg, |
1604 | "testbed", | 1621 | "testbed", |
1605 | "MAX_PARALLEL_SERVICE_CONNECTIONS", | 1622 | "MAX_PARALLEL_SERVICE_CONNECTIONS", |
1606 | &max_parallel_service_connections)) | 1623 | &max_parallel_service_connections)) |
1607 | { | 1624 | { |
1608 | GNUNET_break (0); | 1625 | GNUNET_break(0); |
1609 | GNUNET_free (controller); | 1626 | GNUNET_free(controller); |
1610 | return NULL; | 1627 | return NULL; |
1611 | } | 1628 | } |
1612 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number ( | 1629 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number( |
1613 | cfg, | 1630 | cfg, |
1614 | "testbed", | 1631 | "testbed", |
1615 | "MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS", | 1632 | "MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS", |
1616 | &max_parallel_topology_config_operations)) | 1633 | &max_parallel_topology_config_operations)) |
1617 | { | 1634 | { |
1618 | GNUNET_break (0); | 1635 | GNUNET_break(0); |
1619 | GNUNET_free (controller); | 1636 | GNUNET_free(controller); |
1620 | return NULL; | 1637 | return NULL; |
1621 | } | 1638 | } |
1622 | controller->cc = cc; | 1639 | controller->cc = cc; |
1623 | controller->cc_cls = cc_cls; | 1640 | controller->cc_cls = cc_cls; |
1624 | controller->event_mask = event_mask; | 1641 | controller->event_mask = event_mask; |
1625 | controller->cfg = GNUNET_CONFIGURATION_dup (cfg); | 1642 | controller->cfg = GNUNET_CONFIGURATION_dup(cfg); |
1626 | controller->mq = GNUNET_CLIENT_connect (controller->cfg, | 1643 | controller->mq = GNUNET_CLIENT_connect(controller->cfg, |
1627 | "testbed", | 1644 | "testbed", |
1628 | handlers, | 1645 | handlers, |
1629 | &mq_error_handler, | 1646 | &mq_error_handler, |
1630 | controller); | 1647 | controller); |
1631 | if (NULL == controller->mq) | 1648 | if (NULL == controller->mq) |
1632 | { | 1649 | { |
1633 | GNUNET_break (0); | 1650 | GNUNET_break(0); |
1634 | GNUNET_TESTBED_controller_disconnect (controller); | 1651 | GNUNET_TESTBED_controller_disconnect(controller); |
1635 | return NULL; | 1652 | return NULL; |
1636 | } | 1653 | } |
1637 | GNUNET_TESTBED_mark_host_registered_at_ (host, controller); | 1654 | GNUNET_TESTBED_mark_host_registered_at_(host, controller); |
1638 | controller->host = host; | 1655 | controller->host = host; |
1639 | controller->opq_parallel_operations = | 1656 | controller->opq_parallel_operations = |
1640 | GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, | 1657 | GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_FIXED, |
1641 | (unsigned int) | 1658 | (unsigned int) |
1642 | max_parallel_operations); | 1659 | max_parallel_operations); |
1643 | controller->opq_parallel_service_connections = | 1660 | controller->opq_parallel_service_connections = |
1644 | GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, | 1661 | GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_FIXED, |
1645 | (unsigned int) | 1662 | (unsigned int) |
1646 | max_parallel_service_connections); | 1663 | max_parallel_service_connections); |
1647 | controller->opq_parallel_topology_config_operations = | 1664 | controller->opq_parallel_topology_config_operations = |
1648 | GNUNET_TESTBED_operation_queue_create_ ( | 1665 | GNUNET_TESTBED_operation_queue_create_( |
1649 | OPERATION_QUEUE_TYPE_FIXED, | 1666 | OPERATION_QUEUE_TYPE_FIXED, |
1650 | (unsigned int) max_parallel_topology_config_operations); | 1667 | (unsigned int)max_parallel_topology_config_operations); |
1651 | controller_hostname = GNUNET_TESTBED_host_get_hostname (host); | 1668 | controller_hostname = GNUNET_TESTBED_host_get_hostname(host); |
1652 | if (NULL == controller_hostname) | 1669 | if (NULL == controller_hostname) |
1653 | controller_hostname = "127.0.0.1"; | 1670 | controller_hostname = "127.0.0.1"; |
1654 | slen = strlen (controller_hostname) + 1; | 1671 | slen = strlen(controller_hostname) + 1; |
1655 | env = GNUNET_MQ_msg_extra (msg, slen, GNUNET_MESSAGE_TYPE_TESTBED_INIT); | 1672 | env = GNUNET_MQ_msg_extra(msg, slen, GNUNET_MESSAGE_TYPE_TESTBED_INIT); |
1656 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); | 1673 | msg->host_id = htonl(GNUNET_TESTBED_host_get_id_(host)); |
1657 | msg->event_mask = GNUNET_htonll (controller->event_mask); | 1674 | msg->event_mask = GNUNET_htonll(controller->event_mask); |
1658 | GNUNET_memcpy (&msg[1], controller_hostname, slen); | 1675 | GNUNET_memcpy(&msg[1], controller_hostname, slen); |
1659 | GNUNET_MQ_send (controller->mq, env); | 1676 | GNUNET_MQ_send(controller->mq, env); |
1660 | return controller; | 1677 | return controller; |
1661 | } | 1678 | } |
1662 | 1679 | ||
@@ -1671,16 +1688,16 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, | |||
1671 | * #GNUNET_NO if not. | 1688 | * #GNUNET_NO if not. |
1672 | */ | 1689 | */ |
1673 | static int | 1690 | static int |
1674 | opc_free_iterator (void *cls, uint32_t key, void *value) | 1691 | opc_free_iterator(void *cls, uint32_t key, void *value) |
1675 | { | 1692 | { |
1676 | struct GNUNET_CONTAINER_MultiHashMap32 *map = cls; | 1693 | struct GNUNET_CONTAINER_MultiHashMap32 *map = cls; |
1677 | struct OperationContext *opc = value; | 1694 | struct OperationContext *opc = value; |
1678 | 1695 | ||
1679 | GNUNET_assert (NULL != opc); | 1696 | GNUNET_assert(NULL != opc); |
1680 | GNUNET_break (0); | 1697 | GNUNET_break(0); |
1681 | GNUNET_assert (GNUNET_YES == | 1698 | GNUNET_assert(GNUNET_YES == |
1682 | GNUNET_CONTAINER_multihashmap32_remove (map, key, value)); | 1699 | GNUNET_CONTAINER_multihashmap32_remove(map, key, value)); |
1683 | GNUNET_free (opc); | 1700 | GNUNET_free(opc); |
1684 | return GNUNET_YES; | 1701 | return GNUNET_YES; |
1685 | } | 1702 | } |
1686 | 1703 | ||
@@ -1693,30 +1710,30 @@ opc_free_iterator (void *cls, uint32_t key, void *value) | |||
1693 | * @param c handle to controller to stop | 1710 | * @param c handle to controller to stop |
1694 | */ | 1711 | */ |
1695 | void | 1712 | void |
1696 | GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c) | 1713 | GNUNET_TESTBED_controller_disconnect(struct GNUNET_TESTBED_Controller *c) |
1697 | { | 1714 | { |
1698 | if (NULL != c->mq) | 1715 | if (NULL != c->mq) |
1699 | { | 1716 | { |
1700 | GNUNET_MQ_destroy (c->mq); | 1717 | GNUNET_MQ_destroy(c->mq); |
1701 | c->mq = NULL; | 1718 | c->mq = NULL; |
1702 | } | 1719 | } |
1703 | if (NULL != c->host) | 1720 | if (NULL != c->host) |
1704 | GNUNET_TESTBED_deregister_host_at_ (c->host, c); | 1721 | GNUNET_TESTBED_deregister_host_at_(c->host, c); |
1705 | GNUNET_CONFIGURATION_destroy (c->cfg); | 1722 | GNUNET_CONFIGURATION_destroy(c->cfg); |
1706 | GNUNET_TESTBED_operation_queue_destroy_ (c->opq_parallel_operations); | 1723 | GNUNET_TESTBED_operation_queue_destroy_(c->opq_parallel_operations); |
1707 | GNUNET_TESTBED_operation_queue_destroy_ (c->opq_parallel_service_connections); | 1724 | GNUNET_TESTBED_operation_queue_destroy_(c->opq_parallel_service_connections); |
1708 | GNUNET_TESTBED_operation_queue_destroy_ ( | 1725 | GNUNET_TESTBED_operation_queue_destroy_( |
1709 | c->opq_parallel_topology_config_operations); | 1726 | c->opq_parallel_topology_config_operations); |
1710 | if (NULL != c->opc_map) | 1727 | if (NULL != c->opc_map) |
1711 | { | 1728 | { |
1712 | GNUNET_assert (GNUNET_SYSERR != | 1729 | GNUNET_assert(GNUNET_SYSERR != |
1713 | GNUNET_CONTAINER_multihashmap32_iterate (c->opc_map, | 1730 | GNUNET_CONTAINER_multihashmap32_iterate(c->opc_map, |
1714 | &opc_free_iterator, | 1731 | &opc_free_iterator, |
1715 | c->opc_map)); | 1732 | c->opc_map)); |
1716 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (c->opc_map)); | 1733 | GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap32_size(c->opc_map)); |
1717 | GNUNET_CONTAINER_multihashmap32_destroy (c->opc_map); | 1734 | GNUNET_CONTAINER_multihashmap32_destroy(c->opc_map); |
1718 | } | 1735 | } |
1719 | GNUNET_free (c); | 1736 | GNUNET_free(c); |
1720 | } | 1737 | } |
1721 | 1738 | ||
1722 | 1739 | ||
@@ -1730,19 +1747,19 @@ GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c) | |||
1730 | * @return the size of the xconfig | 1747 | * @return the size of the xconfig |
1731 | */ | 1748 | */ |
1732 | size_t | 1749 | size_t |
1733 | GNUNET_TESTBED_compress_config_ (const char *config, | 1750 | GNUNET_TESTBED_compress_config_(const char *config, |
1734 | size_t size, | 1751 | size_t size, |
1735 | char **xconfig) | 1752 | char **xconfig) |
1736 | { | 1753 | { |
1737 | size_t xsize; | 1754 | size_t xsize; |
1738 | 1755 | ||
1739 | xsize = compressBound ((uLong) size); | 1756 | xsize = compressBound((uLong)size); |
1740 | *xconfig = GNUNET_malloc (xsize); | 1757 | *xconfig = GNUNET_malloc(xsize); |
1741 | GNUNET_assert (Z_OK == compress2 ((Bytef *) *xconfig, | 1758 | GNUNET_assert(Z_OK == compress2((Bytef *)*xconfig, |
1742 | (uLongf *) &xsize, | 1759 | (uLongf *)&xsize, |
1743 | (const Bytef *) config, | 1760 | (const Bytef *)config, |
1744 | (uLongf) size, | 1761 | (uLongf)size, |
1745 | Z_BEST_SPEED)); | 1762 | Z_BEST_SPEED)); |
1746 | return xsize; | 1763 | return xsize; |
1747 | } | 1764 | } |
1748 | 1765 | ||
@@ -1757,18 +1774,18 @@ GNUNET_TESTBED_compress_config_ (const char *config, | |||
1757 | * @return the serialized and compressed configuration | 1774 | * @return the serialized and compressed configuration |
1758 | */ | 1775 | */ |
1759 | char * | 1776 | char * |
1760 | GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg, | 1777 | GNUNET_TESTBED_compress_cfg_(const struct GNUNET_CONFIGURATION_Handle *cfg, |
1761 | size_t *size, | 1778 | size_t *size, |
1762 | size_t *xsize) | 1779 | size_t *xsize) |
1763 | { | 1780 | { |
1764 | char *config; | 1781 | char *config; |
1765 | char *xconfig; | 1782 | char *xconfig; |
1766 | size_t size_; | 1783 | size_t size_; |
1767 | size_t xsize_; | 1784 | size_t xsize_; |
1768 | 1785 | ||
1769 | config = GNUNET_CONFIGURATION_serialize (cfg, &size_); | 1786 | config = GNUNET_CONFIGURATION_serialize(cfg, &size_); |
1770 | xsize_ = GNUNET_TESTBED_compress_config_ (config, size_, &xconfig); | 1787 | xsize_ = GNUNET_TESTBED_compress_config_(config, size_, &xconfig); |
1771 | GNUNET_free (config); | 1788 | GNUNET_free(config); |
1772 | *size = size_; | 1789 | *size = size_; |
1773 | *xsize = xsize_; | 1790 | *xsize = xsize_; |
1774 | return xconfig; | 1791 | return xconfig; |
@@ -1804,11 +1821,11 @@ GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1804 | * @return the operation handle | 1821 | * @return the operation handle |
1805 | */ | 1822 | */ |
1806 | struct GNUNET_TESTBED_Operation * | 1823 | struct GNUNET_TESTBED_Operation * |
1807 | GNUNET_TESTBED_controller_link (void *op_cls, | 1824 | GNUNET_TESTBED_controller_link(void *op_cls, |
1808 | struct GNUNET_TESTBED_Controller *master, | 1825 | struct GNUNET_TESTBED_Controller *master, |
1809 | struct GNUNET_TESTBED_Host *delegated_host, | 1826 | struct GNUNET_TESTBED_Host *delegated_host, |
1810 | struct GNUNET_TESTBED_Host *slave_host, | 1827 | struct GNUNET_TESTBED_Host *slave_host, |
1811 | int is_subordinate) | 1828 | int is_subordinate) |
1812 | { | 1829 | { |
1813 | struct OperationContext *opc; | 1830 | struct OperationContext *opc; |
1814 | struct GNUNET_TESTBED_ControllerLinkRequest *msg; | 1831 | struct GNUNET_TESTBED_ControllerLinkRequest *msg; |
@@ -1817,38 +1834,38 @@ GNUNET_TESTBED_controller_link (void *op_cls, | |||
1817 | uint32_t delegated_host_id; | 1834 | uint32_t delegated_host_id; |
1818 | uint16_t msg_size; | 1835 | uint16_t msg_size; |
1819 | 1836 | ||
1820 | GNUNET_assert (GNUNET_YES == | 1837 | GNUNET_assert(GNUNET_YES == |
1821 | GNUNET_TESTBED_is_host_registered_ (delegated_host, master)); | 1838 | GNUNET_TESTBED_is_host_registered_(delegated_host, master)); |
1822 | slave_host_id = GNUNET_TESTBED_host_get_id_ ( | 1839 | slave_host_id = GNUNET_TESTBED_host_get_id_( |
1823 | (NULL != slave_host) ? slave_host : master->host); | 1840 | (NULL != slave_host) ? slave_host : master->host); |
1824 | delegated_host_id = GNUNET_TESTBED_host_get_id_ (delegated_host); | 1841 | delegated_host_id = GNUNET_TESTBED_host_get_id_(delegated_host); |
1825 | if ((NULL != slave_host) && (0 != slave_host_id)) | 1842 | if ((NULL != slave_host) && (0 != slave_host_id)) |
1826 | GNUNET_assert (GNUNET_YES == | 1843 | GNUNET_assert(GNUNET_YES == |
1827 | GNUNET_TESTBED_is_host_registered_ (slave_host, master)); | 1844 | GNUNET_TESTBED_is_host_registered_(slave_host, master)); |
1828 | msg_size = sizeof (struct GNUNET_TESTBED_ControllerLinkRequest); | 1845 | msg_size = sizeof(struct GNUNET_TESTBED_ControllerLinkRequest); |
1829 | msg = GNUNET_malloc (msg_size); | 1846 | msg = GNUNET_malloc(msg_size); |
1830 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS); | 1847 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS); |
1831 | msg->header.size = htons (msg_size); | 1848 | msg->header.size = htons(msg_size); |
1832 | msg->delegated_host_id = htonl (delegated_host_id); | 1849 | msg->delegated_host_id = htonl(delegated_host_id); |
1833 | msg->slave_host_id = htonl (slave_host_id); | 1850 | msg->slave_host_id = htonl(slave_host_id); |
1834 | msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0; | 1851 | msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0; |
1835 | data = GNUNET_new (struct ControllerLinkData); | 1852 | data = GNUNET_new(struct ControllerLinkData); |
1836 | data->msg = msg; | 1853 | data->msg = msg; |
1837 | data->host_id = delegated_host_id; | 1854 | data->host_id = delegated_host_id; |
1838 | opc = GNUNET_new (struct OperationContext); | 1855 | opc = GNUNET_new(struct OperationContext); |
1839 | opc->c = master; | 1856 | opc->c = master; |
1840 | opc->data = data; | 1857 | opc->data = data; |
1841 | opc->type = OP_LINK_CONTROLLERS; | 1858 | opc->type = OP_LINK_CONTROLLERS; |
1842 | opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); | 1859 | opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); |
1843 | opc->state = OPC_STATE_INIT; | 1860 | opc->state = OPC_STATE_INIT; |
1844 | opc->op_cls = op_cls; | 1861 | opc->op_cls = op_cls; |
1845 | msg->operation_id = GNUNET_htonll (opc->id); | 1862 | msg->operation_id = GNUNET_htonll(opc->id); |
1846 | opc->op = GNUNET_TESTBED_operation_create_ (opc, | 1863 | opc->op = GNUNET_TESTBED_operation_create_(opc, |
1847 | &opstart_link_controllers, | 1864 | &opstart_link_controllers, |
1848 | &oprelease_link_controllers); | 1865 | &oprelease_link_controllers); |
1849 | GNUNET_TESTBED_operation_queue_insert_ (master->opq_parallel_operations, | 1866 | GNUNET_TESTBED_operation_queue_insert_(master->opq_parallel_operations, |
1850 | opc->op); | 1867 | opc->op); |
1851 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | 1868 | GNUNET_TESTBED_operation_begin_wait_(opc->op); |
1852 | return opc->op; | 1869 | return opc->op; |
1853 | } | 1870 | } |
1854 | 1871 | ||
@@ -1866,28 +1883,28 @@ GNUNET_TESTBED_controller_link (void *op_cls, | |||
1866 | * @return the operation handle; | 1883 | * @return the operation handle; |
1867 | */ | 1884 | */ |
1868 | struct GNUNET_TESTBED_Operation * | 1885 | struct GNUNET_TESTBED_Operation * |
1869 | GNUNET_TESTBED_get_slave_config_ (void *op_cls, | 1886 | GNUNET_TESTBED_get_slave_config_(void *op_cls, |
1870 | struct GNUNET_TESTBED_Controller *master, | 1887 | struct GNUNET_TESTBED_Controller *master, |
1871 | uint32_t slave_host_id) | 1888 | uint32_t slave_host_id) |
1872 | { | 1889 | { |
1873 | struct OperationContext *opc; | 1890 | struct OperationContext *opc; |
1874 | struct GetSlaveConfigData *data; | 1891 | struct GetSlaveConfigData *data; |
1875 | 1892 | ||
1876 | data = GNUNET_new (struct GetSlaveConfigData); | 1893 | data = GNUNET_new(struct GetSlaveConfigData); |
1877 | data->slave_id = slave_host_id; | 1894 | data->slave_id = slave_host_id; |
1878 | opc = GNUNET_new (struct OperationContext); | 1895 | opc = GNUNET_new(struct OperationContext); |
1879 | opc->state = OPC_STATE_INIT; | 1896 | opc->state = OPC_STATE_INIT; |
1880 | opc->c = master; | 1897 | opc->c = master; |
1881 | opc->id = GNUNET_TESTBED_get_next_op_id (master); | 1898 | opc->id = GNUNET_TESTBED_get_next_op_id(master); |
1882 | opc->type = OP_GET_SLAVE_CONFIG; | 1899 | opc->type = OP_GET_SLAVE_CONFIG; |
1883 | opc->data = data; | 1900 | opc->data = data; |
1884 | opc->op_cls = op_cls; | 1901 | opc->op_cls = op_cls; |
1885 | opc->op = GNUNET_TESTBED_operation_create_ (opc, | 1902 | opc->op = GNUNET_TESTBED_operation_create_(opc, |
1886 | &opstart_get_slave_config, | 1903 | &opstart_get_slave_config, |
1887 | &oprelease_get_slave_config); | 1904 | &oprelease_get_slave_config); |
1888 | GNUNET_TESTBED_operation_queue_insert_ (master->opq_parallel_operations, | 1905 | GNUNET_TESTBED_operation_queue_insert_(master->opq_parallel_operations, |
1889 | opc->op); | 1906 | opc->op); |
1890 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | 1907 | GNUNET_TESTBED_operation_begin_wait_(opc->op); |
1891 | return opc->op; | 1908 | return opc->op; |
1892 | } | 1909 | } |
1893 | 1910 | ||
@@ -1908,16 +1925,16 @@ GNUNET_TESTBED_get_slave_config_ (void *op_cls, | |||
1908 | * master | 1925 | * master |
1909 | */ | 1926 | */ |
1910 | struct GNUNET_TESTBED_Operation * | 1927 | struct GNUNET_TESTBED_Operation * |
1911 | GNUNET_TESTBED_get_slave_config (void *op_cls, | 1928 | GNUNET_TESTBED_get_slave_config(void *op_cls, |
1912 | struct GNUNET_TESTBED_Controller *master, | 1929 | struct GNUNET_TESTBED_Controller *master, |
1913 | struct GNUNET_TESTBED_Host *slave_host) | 1930 | struct GNUNET_TESTBED_Host *slave_host) |
1914 | { | 1931 | { |
1915 | if (GNUNET_NO == GNUNET_TESTBED_is_host_registered_ (slave_host, master)) | 1932 | if (GNUNET_NO == GNUNET_TESTBED_is_host_registered_(slave_host, master)) |
1916 | return NULL; | 1933 | return NULL; |
1917 | return GNUNET_TESTBED_get_slave_config_ (op_cls, | 1934 | return GNUNET_TESTBED_get_slave_config_(op_cls, |
1918 | master, | 1935 | master, |
1919 | GNUNET_TESTBED_host_get_id_ ( | 1936 | GNUNET_TESTBED_host_get_id_( |
1920 | slave_host)); | 1937 | slave_host)); |
1921 | } | 1938 | } |
1922 | 1939 | ||
1923 | 1940 | ||
@@ -1931,11 +1948,11 @@ GNUNET_TESTBED_get_slave_config (void *op_cls, | |||
1931 | * be written to. | 1948 | * be written to. |
1932 | */ | 1949 | */ |
1933 | void | 1950 | void |
1934 | GNUNET_TESTBED_overlay_write_topology_to_file ( | 1951 | GNUNET_TESTBED_overlay_write_topology_to_file( |
1935 | struct GNUNET_TESTBED_Controller *controller, | 1952 | struct GNUNET_TESTBED_Controller *controller, |
1936 | const char *filename) | 1953 | const char *filename) |
1937 | { | 1954 | { |
1938 | GNUNET_break (0); | 1955 | GNUNET_break(0); |
1939 | } | 1956 | } |
1940 | 1957 | ||
1941 | 1958 | ||
@@ -1953,7 +1970,7 @@ GNUNET_TESTBED_overlay_write_topology_to_file ( | |||
1953 | * @return the initialization message | 1970 | * @return the initialization message |
1954 | */ | 1971 | */ |
1955 | struct GNUNET_TESTBED_HelperInit * | 1972 | struct GNUNET_TESTBED_HelperInit * |
1956 | GNUNET_TESTBED_create_helper_init_msg_ ( | 1973 | GNUNET_TESTBED_create_helper_init_msg_( |
1957 | const char *trusted_ip, | 1974 | const char *trusted_ip, |
1958 | const char *hostname, | 1975 | const char *hostname, |
1959 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1976 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
@@ -1967,30 +1984,30 @@ GNUNET_TESTBED_create_helper_init_msg_ ( | |||
1967 | uint16_t hostname_len; | 1984 | uint16_t hostname_len; |
1968 | uint16_t msg_size; | 1985 | uint16_t msg_size; |
1969 | 1986 | ||
1970 | config = GNUNET_CONFIGURATION_serialize (cfg, &config_size); | 1987 | config = GNUNET_CONFIGURATION_serialize(cfg, &config_size); |
1971 | GNUNET_assert (NULL != config); | 1988 | GNUNET_assert(NULL != config); |
1972 | xconfig_size = | 1989 | xconfig_size = |
1973 | GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig); | 1990 | GNUNET_TESTBED_compress_config_(config, config_size, &xconfig); |
1974 | GNUNET_free (config); | 1991 | GNUNET_free(config); |
1975 | trusted_ip_len = strlen (trusted_ip); | 1992 | trusted_ip_len = strlen(trusted_ip); |
1976 | hostname_len = (NULL == hostname) ? 0 : strlen (hostname); | 1993 | hostname_len = (NULL == hostname) ? 0 : strlen(hostname); |
1977 | msg_size = xconfig_size + trusted_ip_len + 1 + | 1994 | msg_size = xconfig_size + trusted_ip_len + 1 + |
1978 | sizeof (struct GNUNET_TESTBED_HelperInit); | 1995 | sizeof(struct GNUNET_TESTBED_HelperInit); |
1979 | msg_size += hostname_len; | 1996 | msg_size += hostname_len; |
1980 | msg = GNUNET_realloc (xconfig, msg_size); | 1997 | msg = GNUNET_realloc(xconfig, msg_size); |
1981 | (void) memmove (((void *) &msg[1]) + trusted_ip_len + 1 + hostname_len, | 1998 | (void)memmove(((void *)&msg[1]) + trusted_ip_len + 1 + hostname_len, |
1982 | msg, | 1999 | msg, |
1983 | xconfig_size); | 2000 | xconfig_size); |
1984 | msg->header.size = htons (msg_size); | 2001 | msg->header.size = htons(msg_size); |
1985 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT); | 2002 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT); |
1986 | msg->trusted_ip_size = htons (trusted_ip_len); | 2003 | msg->trusted_ip_size = htons(trusted_ip_len); |
1987 | msg->hostname_size = htons (hostname_len); | 2004 | msg->hostname_size = htons(hostname_len); |
1988 | msg->config_size = htons (config_size); | 2005 | msg->config_size = htons(config_size); |
1989 | (void) strcpy ((char *) &msg[1], trusted_ip); | 2006 | (void)strcpy((char *)&msg[1], trusted_ip); |
1990 | if (0 != hostname_len) | 2007 | if (0 != hostname_len) |
1991 | GNUNET_memcpy ((char *) &msg[1] + trusted_ip_len + 1, | 2008 | GNUNET_memcpy((char *)&msg[1] + trusted_ip_len + 1, |
1992 | hostname, | 2009 | hostname, |
1993 | hostname_len); | 2010 | hostname_len); |
1994 | return msg; | 2011 | return msg; |
1995 | } | 2012 | } |
1996 | 2013 | ||
@@ -2017,10 +2034,10 @@ GNUNET_TESTBED_create_helper_init_msg_ ( | |||
2017 | * @param operation operation to signal completion or cancellation | 2034 | * @param operation operation to signal completion or cancellation |
2018 | */ | 2035 | */ |
2019 | void | 2036 | void |
2020 | GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation) | 2037 | GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation) |
2021 | { | 2038 | { |
2022 | (void) exop_check (operation); | 2039 | (void)exop_check(operation); |
2023 | GNUNET_TESTBED_operation_release_ (operation); | 2040 | GNUNET_TESTBED_operation_release_(operation); |
2024 | } | 2041 | } |
2025 | 2042 | ||
2026 | 2043 | ||
@@ -2039,7 +2056,7 @@ GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation) | |||
2039 | * @return handle to the parsed configuration; NULL upon error while parsing the message | 2056 | * @return handle to the parsed configuration; NULL upon error while parsing the message |
2040 | */ | 2057 | */ |
2041 | struct GNUNET_CONFIGURATION_Handle * | 2058 | struct GNUNET_CONFIGURATION_Handle * |
2042 | GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg) | 2059 | GNUNET_TESTBED_extract_config_(const struct GNUNET_MessageHeader *msg) |
2043 | { | 2060 | { |
2044 | struct GNUNET_CONFIGURATION_Handle *cfg; | 2061 | struct GNUNET_CONFIGURATION_Handle *cfg; |
2045 | Bytef *data; | 2062 | Bytef *data; |
@@ -2048,93 +2065,99 @@ GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg) | |||
2048 | uLong xdata_len; | 2065 | uLong xdata_len; |
2049 | int ret; | 2066 | int ret; |
2050 | 2067 | ||
2051 | switch (ntohs (msg->type)) | 2068 | switch (ntohs(msg->type)) |
2052 | { | 2069 | { |
2053 | case GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION: { | 2070 | case GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION: { |
2054 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg; | 2071 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg; |
2055 | 2072 | ||
2056 | imsg = | 2073 | imsg = |
2057 | (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg; | 2074 | (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *)msg; |
2058 | data_len = (uLong) ntohs (imsg->config_size); | 2075 | data_len = (uLong)ntohs(imsg->config_size); |
2059 | xdata_len = | 2076 | xdata_len = |
2060 | ntohs (imsg->header.size) - | 2077 | ntohs(imsg->header.size) - |
2061 | sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage); | 2078 | sizeof(struct GNUNET_TESTBED_PeerConfigurationInformationMessage); |
2062 | xdata = (const Bytef *) &imsg[1]; | 2079 | xdata = (const Bytef *)&imsg[1]; |
2063 | } | 2080 | } |
2064 | break; | 2081 | break; |
2065 | case GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION: { | 2082 | |
2066 | const struct GNUNET_TESTBED_SlaveConfiguration *imsg; | 2083 | case GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION: { |
2067 | 2084 | const struct GNUNET_TESTBED_SlaveConfiguration *imsg; | |
2068 | imsg = (const struct GNUNET_TESTBED_SlaveConfiguration *) msg; | 2085 | |
2069 | data_len = (uLong) ntohs (imsg->config_size); | 2086 | imsg = (const struct GNUNET_TESTBED_SlaveConfiguration *)msg; |
2070 | xdata_len = ntohs (imsg->header.size) - | 2087 | data_len = (uLong)ntohs(imsg->config_size); |
2071 | sizeof (struct GNUNET_TESTBED_SlaveConfiguration); | 2088 | xdata_len = ntohs(imsg->header.size) - |
2072 | xdata = (const Bytef *) &imsg[1]; | 2089 | sizeof(struct GNUNET_TESTBED_SlaveConfiguration); |
2073 | } | 2090 | xdata = (const Bytef *)&imsg[1]; |
2074 | break; | 2091 | } |
2075 | case GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST: { | 2092 | break; |
2076 | const struct GNUNET_TESTBED_AddHostMessage *imsg; | 2093 | |
2077 | uint16_t osize; | 2094 | case GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST: { |
2078 | 2095 | const struct GNUNET_TESTBED_AddHostMessage *imsg; | |
2079 | imsg = (const struct GNUNET_TESTBED_AddHostMessage *) msg; | 2096 | uint16_t osize; |
2080 | data_len = (uLong) ntohs (imsg->config_size); | 2097 | |
2081 | osize = sizeof (struct GNUNET_TESTBED_AddHostMessage) + | 2098 | imsg = (const struct GNUNET_TESTBED_AddHostMessage *)msg; |
2082 | ntohs (imsg->username_length) + ntohs (imsg->hostname_length); | 2099 | data_len = (uLong)ntohs(imsg->config_size); |
2083 | xdata_len = ntohs (imsg->header.size) - osize; | 2100 | osize = sizeof(struct GNUNET_TESTBED_AddHostMessage) + |
2084 | xdata = (const Bytef *) ((const void *) imsg + osize); | 2101 | ntohs(imsg->username_length) + ntohs(imsg->hostname_length); |
2085 | } | 2102 | xdata_len = ntohs(imsg->header.size) - osize; |
2086 | break; | 2103 | xdata = (const Bytef *)((const void *)imsg + osize); |
2087 | case GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT: { | 2104 | } |
2088 | const struct GNUNET_TESTBED_ControllerLinkResponse *imsg; | 2105 | break; |
2089 | 2106 | ||
2090 | imsg = (const struct GNUNET_TESTBED_ControllerLinkResponse *) msg; | 2107 | case GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT: { |
2091 | data_len = ntohs (imsg->config_size); | 2108 | const struct GNUNET_TESTBED_ControllerLinkResponse *imsg; |
2092 | xdata_len = ntohs (imsg->header.size) - | 2109 | |
2093 | sizeof (const struct GNUNET_TESTBED_ControllerLinkResponse); | 2110 | imsg = (const struct GNUNET_TESTBED_ControllerLinkResponse *)msg; |
2094 | xdata = (const Bytef *) &imsg[1]; | 2111 | data_len = ntohs(imsg->config_size); |
2095 | } | 2112 | xdata_len = ntohs(imsg->header.size) - |
2096 | break; | 2113 | sizeof(const struct GNUNET_TESTBED_ControllerLinkResponse); |
2097 | case GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER: { | 2114 | xdata = (const Bytef *)&imsg[1]; |
2098 | const struct GNUNET_TESTBED_PeerCreateMessage *imsg; | 2115 | } |
2099 | 2116 | break; | |
2100 | imsg = (const struct GNUNET_TESTBED_PeerCreateMessage *) msg; | 2117 | |
2101 | data_len = ntohs (imsg->config_size); | 2118 | case GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER: { |
2102 | xdata_len = ntohs (imsg->header.size) - | 2119 | const struct GNUNET_TESTBED_PeerCreateMessage *imsg; |
2103 | sizeof (struct GNUNET_TESTBED_PeerCreateMessage); | 2120 | |
2104 | xdata = (const Bytef *) &imsg[1]; | 2121 | imsg = (const struct GNUNET_TESTBED_PeerCreateMessage *)msg; |
2105 | } | 2122 | data_len = ntohs(imsg->config_size); |
2106 | break; | 2123 | xdata_len = ntohs(imsg->header.size) - |
2107 | case GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER: { | 2124 | sizeof(struct GNUNET_TESTBED_PeerCreateMessage); |
2108 | const struct GNUNET_TESTBED_PeerReconfigureMessage *imsg; | 2125 | xdata = (const Bytef *)&imsg[1]; |
2109 | 2126 | } | |
2110 | imsg = (const struct GNUNET_TESTBED_PeerReconfigureMessage *) msg; | 2127 | break; |
2111 | data_len = ntohs (imsg->config_size); | 2128 | |
2112 | xdata_len = ntohs (imsg->header.size) - | 2129 | case GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER: { |
2113 | sizeof (struct GNUNET_TESTBED_PeerReconfigureMessage); | 2130 | const struct GNUNET_TESTBED_PeerReconfigureMessage *imsg; |
2114 | xdata = (const Bytef *) &imsg[1]; | 2131 | |
2115 | } | 2132 | imsg = (const struct GNUNET_TESTBED_PeerReconfigureMessage *)msg; |
2116 | break; | 2133 | data_len = ntohs(imsg->config_size); |
2117 | default: | 2134 | xdata_len = ntohs(imsg->header.size) - |
2118 | GNUNET_assert (0); | 2135 | sizeof(struct GNUNET_TESTBED_PeerReconfigureMessage); |
2119 | } | 2136 | xdata = (const Bytef *)&imsg[1]; |
2120 | data = GNUNET_malloc (data_len); | 2137 | } |
2121 | if (Z_OK != (ret = uncompress (data, &data_len, xdata, xdata_len))) | 2138 | break; |
2122 | { | 2139 | |
2123 | GNUNET_free (data); | 2140 | default: |
2124 | GNUNET_break_op (0); /* Un-compression failure */ | 2141 | GNUNET_assert(0); |
2125 | return NULL; | 2142 | } |
2126 | } | 2143 | data = GNUNET_malloc(data_len); |
2127 | cfg = GNUNET_CONFIGURATION_create (); | 2144 | if (Z_OK != (ret = uncompress(data, &data_len, xdata, xdata_len))) |
2128 | if (GNUNET_OK != GNUNET_CONFIGURATION_deserialize (cfg, | 2145 | { |
2129 | (const char *) data, | 2146 | GNUNET_free(data); |
2130 | (size_t) data_len, | 2147 | GNUNET_break_op(0); /* Un-compression failure */ |
2131 | NULL)) | 2148 | return NULL; |
2132 | { | 2149 | } |
2133 | GNUNET_free (data); | 2150 | cfg = GNUNET_CONFIGURATION_create(); |
2134 | GNUNET_break_op (0); /* De-serialization failure */ | 2151 | if (GNUNET_OK != GNUNET_CONFIGURATION_deserialize(cfg, |
2135 | return NULL; | 2152 | (const char *)data, |
2136 | } | 2153 | (size_t)data_len, |
2137 | GNUNET_free (data); | 2154 | NULL)) |
2155 | { | ||
2156 | GNUNET_free(data); | ||
2157 | GNUNET_break_op(0); /* De-serialization failure */ | ||
2158 | return NULL; | ||
2159 | } | ||
2160 | GNUNET_free(data); | ||
2138 | return cfg; | 2161 | return cfg; |
2139 | } | 2162 | } |
2140 | 2163 | ||
@@ -2147,22 +2170,22 @@ GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg) | |||
2147 | * @return the error message | 2170 | * @return the error message |
2148 | */ | 2171 | */ |
2149 | const char * | 2172 | const char * |
2150 | GNUNET_TESTBED_parse_error_string_ ( | 2173 | GNUNET_TESTBED_parse_error_string_( |
2151 | const struct GNUNET_TESTBED_OperationFailureEventMessage *msg) | 2174 | const struct GNUNET_TESTBED_OperationFailureEventMessage *msg) |
2152 | { | 2175 | { |
2153 | uint16_t msize; | 2176 | uint16_t msize; |
2154 | const char *emsg; | 2177 | const char *emsg; |
2155 | 2178 | ||
2156 | msize = ntohs (msg->header.size); | 2179 | msize = ntohs(msg->header.size); |
2157 | if (sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage) >= msize) | 2180 | if (sizeof(struct GNUNET_TESTBED_OperationFailureEventMessage) >= msize) |
2158 | return NULL; | 2181 | return NULL; |
2159 | msize -= sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage); | 2182 | msize -= sizeof(struct GNUNET_TESTBED_OperationFailureEventMessage); |
2160 | emsg = (const char *) &msg[1]; | 2183 | emsg = (const char *)&msg[1]; |
2161 | if ('\0' != emsg[msize - 1]) | 2184 | if ('\0' != emsg[msize - 1]) |
2162 | { | 2185 | { |
2163 | GNUNET_break (0); | 2186 | GNUNET_break(0); |
2164 | return NULL; | 2187 | return NULL; |
2165 | } | 2188 | } |
2166 | return emsg; | 2189 | return emsg; |
2167 | } | 2190 | } |
2168 | 2191 | ||
@@ -2175,13 +2198,13 @@ GNUNET_TESTBED_parse_error_string_ ( | |||
2175 | * @return the incremented operation id. | 2198 | * @return the incremented operation id. |
2176 | */ | 2199 | */ |
2177 | uint64_t | 2200 | uint64_t |
2178 | GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller) | 2201 | GNUNET_TESTBED_get_next_op_id(struct GNUNET_TESTBED_Controller *controller) |
2179 | { | 2202 | { |
2180 | uint64_t op_id; | 2203 | uint64_t op_id; |
2181 | 2204 | ||
2182 | op_id = (uint64_t) GNUNET_TESTBED_host_get_id_ (controller->host); | 2205 | op_id = (uint64_t)GNUNET_TESTBED_host_get_id_(controller->host); |
2183 | op_id = op_id << 32; | 2206 | op_id = op_id << 32; |
2184 | op_id |= (uint64_t) controller->operation_counter++; | 2207 | op_id |= (uint64_t)controller->operation_counter++; |
2185 | return op_id; | 2208 | return op_id; |
2186 | } | 2209 | } |
2187 | 2210 | ||
@@ -2192,17 +2215,17 @@ GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller) | |||
2192 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 2215 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
2193 | */ | 2216 | */ |
2194 | static void | 2217 | static void |
2195 | opstart_shutdown_peers (void *cls) | 2218 | opstart_shutdown_peers(void *cls) |
2196 | { | 2219 | { |
2197 | struct OperationContext *opc = cls; | 2220 | struct OperationContext *opc = cls; |
2198 | struct GNUNET_MQ_Envelope *env; | 2221 | struct GNUNET_MQ_Envelope *env; |
2199 | struct GNUNET_TESTBED_ShutdownPeersMessage *msg; | 2222 | struct GNUNET_TESTBED_ShutdownPeersMessage *msg; |
2200 | 2223 | ||
2201 | opc->state = OPC_STATE_STARTED; | 2224 | opc->state = OPC_STATE_STARTED; |
2202 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS); | 2225 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS); |
2203 | msg->operation_id = GNUNET_htonll (opc->id); | 2226 | msg->operation_id = GNUNET_htonll(opc->id); |
2204 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | 2227 | GNUNET_TESTBED_insert_opc_(opc->c, opc); |
2205 | GNUNET_MQ_send (opc->c->mq, env); | 2228 | GNUNET_MQ_send(opc->c->mq, env); |
2206 | } | 2229 | } |
2207 | 2230 | ||
2208 | 2231 | ||
@@ -2212,22 +2235,24 @@ opstart_shutdown_peers (void *cls) | |||
2212 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 2235 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
2213 | */ | 2236 | */ |
2214 | static void | 2237 | static void |
2215 | oprelease_shutdown_peers (void *cls) | 2238 | oprelease_shutdown_peers(void *cls) |
2216 | { | 2239 | { |
2217 | struct OperationContext *opc = cls; | 2240 | struct OperationContext *opc = cls; |
2218 | 2241 | ||
2219 | switch (opc->state) | 2242 | switch (opc->state) |
2220 | { | 2243 | { |
2221 | case OPC_STATE_STARTED: | 2244 | case OPC_STATE_STARTED: |
2222 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 2245 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
2246 | |||
2223 | /* no break; continue */ | 2247 | /* no break; continue */ |
2224 | case OPC_STATE_INIT: | 2248 | case OPC_STATE_INIT: |
2225 | GNUNET_free (opc->data); | 2249 | GNUNET_free(opc->data); |
2226 | break; | 2250 | break; |
2227 | case OPC_STATE_FINISHED: | 2251 | |
2228 | break; | 2252 | case OPC_STATE_FINISHED: |
2229 | } | 2253 | break; |
2230 | GNUNET_free (opc); | 2254 | } |
2255 | GNUNET_free(opc); | ||
2231 | } | 2256 | } |
2232 | 2257 | ||
2233 | 2258 | ||
@@ -2247,32 +2272,32 @@ oprelease_shutdown_peers (void *cls) | |||
2247 | * present | 2272 | * present |
2248 | */ | 2273 | */ |
2249 | struct GNUNET_TESTBED_Operation * | 2274 | struct GNUNET_TESTBED_Operation * |
2250 | GNUNET_TESTBED_shutdown_peers (struct GNUNET_TESTBED_Controller *c, | 2275 | GNUNET_TESTBED_shutdown_peers(struct GNUNET_TESTBED_Controller *c, |
2251 | void *op_cls, | 2276 | void *op_cls, |
2252 | GNUNET_TESTBED_OperationCompletionCallback cb, | 2277 | GNUNET_TESTBED_OperationCompletionCallback cb, |
2253 | void *cb_cls) | 2278 | void *cb_cls) |
2254 | { | 2279 | { |
2255 | struct OperationContext *opc; | 2280 | struct OperationContext *opc; |
2256 | struct ShutdownPeersData *data; | 2281 | struct ShutdownPeersData *data; |
2257 | 2282 | ||
2258 | if (0 != GNUNET_CONTAINER_multihashmap32_size (c->opc_map)) | 2283 | if (0 != GNUNET_CONTAINER_multihashmap32_size(c->opc_map)) |
2259 | return NULL; | 2284 | return NULL; |
2260 | data = GNUNET_new (struct ShutdownPeersData); | 2285 | data = GNUNET_new(struct ShutdownPeersData); |
2261 | data->cb = cb; | 2286 | data->cb = cb; |
2262 | data->cb_cls = cb_cls; | 2287 | data->cb_cls = cb_cls; |
2263 | opc = GNUNET_new (struct OperationContext); | 2288 | opc = GNUNET_new(struct OperationContext); |
2264 | opc->c = c; | 2289 | opc->c = c; |
2265 | opc->op_cls = op_cls; | 2290 | opc->op_cls = op_cls; |
2266 | opc->data = data; | 2291 | opc->data = data; |
2267 | opc->id = GNUNET_TESTBED_get_next_op_id (c); | 2292 | opc->id = GNUNET_TESTBED_get_next_op_id(c); |
2268 | opc->type = OP_SHUTDOWN_PEERS; | 2293 | opc->type = OP_SHUTDOWN_PEERS; |
2269 | opc->state = OPC_STATE_INIT; | 2294 | opc->state = OPC_STATE_INIT; |
2270 | opc->op = GNUNET_TESTBED_operation_create_ (opc, | 2295 | opc->op = GNUNET_TESTBED_operation_create_(opc, |
2271 | &opstart_shutdown_peers, | 2296 | &opstart_shutdown_peers, |
2272 | &oprelease_shutdown_peers); | 2297 | &oprelease_shutdown_peers); |
2273 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, | 2298 | GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, |
2274 | opc->op); | 2299 | opc->op); |
2275 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | 2300 | GNUNET_TESTBED_operation_begin_wait_(opc->op); |
2276 | return opc->op; | 2301 | return opc->op; |
2277 | } | 2302 | } |
2278 | 2303 | ||
@@ -2286,7 +2311,7 @@ GNUNET_TESTBED_shutdown_peers (struct GNUNET_TESTBED_Controller *c, | |||
2286 | * @return The peer's unique ID. | 2311 | * @return The peer's unique ID. |
2287 | */ | 2312 | */ |
2288 | uint32_t | 2313 | uint32_t |
2289 | GNUNET_TESTBED_get_index (const struct GNUNET_TESTBED_Peer *peer) | 2314 | GNUNET_TESTBED_get_index(const struct GNUNET_TESTBED_Peer *peer) |
2290 | { | 2315 | { |
2291 | return peer->unique_id; | 2316 | return peer->unique_id; |
2292 | } | 2317 | } |
@@ -2299,22 +2324,22 @@ GNUNET_TESTBED_get_index (const struct GNUNET_TESTBED_Peer *peer) | |||
2299 | * @param barrier the barrier to remove | 2324 | * @param barrier the barrier to remove |
2300 | */ | 2325 | */ |
2301 | void | 2326 | void |
2302 | GNUNET_TESTBED_barrier_remove_ (struct GNUNET_TESTBED_Barrier *barrier) | 2327 | GNUNET_TESTBED_barrier_remove_(struct GNUNET_TESTBED_Barrier *barrier) |
2303 | { | 2328 | { |
2304 | struct GNUNET_TESTBED_Controller *c = barrier->c; | 2329 | struct GNUNET_TESTBED_Controller *c = barrier->c; |
2305 | 2330 | ||
2306 | GNUNET_assert (NULL != c->barrier_map); /* No barriers present */ | 2331 | GNUNET_assert(NULL != c->barrier_map); /* No barriers present */ |
2307 | GNUNET_assert (GNUNET_OK == | 2332 | GNUNET_assert(GNUNET_OK == |
2308 | GNUNET_CONTAINER_multihashmap_remove (c->barrier_map, | 2333 | GNUNET_CONTAINER_multihashmap_remove(c->barrier_map, |
2309 | &barrier->key, | 2334 | &barrier->key, |
2310 | barrier)); | 2335 | barrier)); |
2311 | GNUNET_free (barrier->name); | 2336 | GNUNET_free(barrier->name); |
2312 | GNUNET_free (barrier); | 2337 | GNUNET_free(barrier); |
2313 | if (0 == GNUNET_CONTAINER_multihashmap_size (c->barrier_map)) | 2338 | if (0 == GNUNET_CONTAINER_multihashmap_size(c->barrier_map)) |
2314 | { | 2339 | { |
2315 | GNUNET_CONTAINER_multihashmap_destroy (c->barrier_map); | 2340 | GNUNET_CONTAINER_multihashmap_destroy(c->barrier_map); |
2316 | c->barrier_map = NULL; | 2341 | c->barrier_map = NULL; |
2317 | } | 2342 | } |
2318 | } | 2343 | } |
2319 | 2344 | ||
2320 | 2345 | ||
@@ -2335,12 +2360,12 @@ GNUNET_TESTBED_barrier_remove_ (struct GNUNET_TESTBED_Barrier *barrier) | |||
2335 | * @return barrier handle; NULL upon error | 2360 | * @return barrier handle; NULL upon error |
2336 | */ | 2361 | */ |
2337 | struct GNUNET_TESTBED_Barrier * | 2362 | struct GNUNET_TESTBED_Barrier * |
2338 | GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller, | 2363 | GNUNET_TESTBED_barrier_init_(struct GNUNET_TESTBED_Controller *controller, |
2339 | const char *name, | 2364 | const char *name, |
2340 | unsigned int quorum, | 2365 | unsigned int quorum, |
2341 | GNUNET_TESTBED_barrier_status_cb cb, | 2366 | GNUNET_TESTBED_barrier_status_cb cb, |
2342 | void *cls, | 2367 | void *cls, |
2343 | int echo) | 2368 | int echo) |
2344 | { | 2369 | { |
2345 | struct GNUNET_TESTBED_BarrierInit *msg; | 2370 | struct GNUNET_TESTBED_BarrierInit *msg; |
2346 | struct GNUNET_MQ_Envelope *env; | 2371 | struct GNUNET_MQ_Envelope *env; |
@@ -2348,41 +2373,41 @@ GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller, | |||
2348 | struct GNUNET_HashCode key; | 2373 | struct GNUNET_HashCode key; |
2349 | size_t name_len; | 2374 | size_t name_len; |
2350 | 2375 | ||
2351 | GNUNET_assert (quorum <= 100); | 2376 | GNUNET_assert(quorum <= 100); |
2352 | GNUNET_assert (NULL != cb); | 2377 | GNUNET_assert(NULL != cb); |
2353 | name_len = strlen (name); | 2378 | name_len = strlen(name); |
2354 | GNUNET_assert (0 < name_len); | 2379 | GNUNET_assert(0 < name_len); |
2355 | GNUNET_CRYPTO_hash (name, name_len, &key); | 2380 | GNUNET_CRYPTO_hash(name, name_len, &key); |
2356 | if (NULL == controller->barrier_map) | 2381 | if (NULL == controller->barrier_map) |
2357 | controller->barrier_map = | 2382 | controller->barrier_map = |
2358 | GNUNET_CONTAINER_multihashmap_create (3, GNUNET_YES); | 2383 | GNUNET_CONTAINER_multihashmap_create(3, GNUNET_YES); |
2359 | if (GNUNET_YES == | 2384 | if (GNUNET_YES == |
2360 | GNUNET_CONTAINER_multihashmap_contains (controller->barrier_map, &key)) | 2385 | GNUNET_CONTAINER_multihashmap_contains(controller->barrier_map, &key)) |
2361 | { | 2386 | { |
2362 | GNUNET_break (0); | 2387 | GNUNET_break(0); |
2363 | return NULL; | 2388 | return NULL; |
2364 | } | 2389 | } |
2365 | LOG_DEBUG ("Initialising barrier `%s'\n", name); | 2390 | LOG_DEBUG("Initialising barrier `%s'\n", name); |
2366 | barrier = GNUNET_new (struct GNUNET_TESTBED_Barrier); | 2391 | barrier = GNUNET_new(struct GNUNET_TESTBED_Barrier); |
2367 | barrier->c = controller; | 2392 | barrier->c = controller; |
2368 | barrier->name = GNUNET_strdup (name); | 2393 | barrier->name = GNUNET_strdup(name); |
2369 | barrier->cb = cb; | 2394 | barrier->cb = cb; |
2370 | barrier->cls = cls; | 2395 | barrier->cls = cls; |
2371 | barrier->echo = echo; | 2396 | barrier->echo = echo; |
2372 | GNUNET_memcpy (&barrier->key, &key, sizeof (struct GNUNET_HashCode)); | 2397 | GNUNET_memcpy(&barrier->key, &key, sizeof(struct GNUNET_HashCode)); |
2373 | GNUNET_assert (GNUNET_OK == | 2398 | GNUNET_assert(GNUNET_OK == |
2374 | GNUNET_CONTAINER_multihashmap_put ( | 2399 | GNUNET_CONTAINER_multihashmap_put( |
2375 | controller->barrier_map, | 2400 | controller->barrier_map, |
2376 | &barrier->key, | 2401 | &barrier->key, |
2377 | barrier, | 2402 | barrier, |
2378 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 2403 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
2379 | 2404 | ||
2380 | env = GNUNET_MQ_msg_extra (msg, | 2405 | env = GNUNET_MQ_msg_extra(msg, |
2381 | name_len, | 2406 | name_len, |
2382 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT); | 2407 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT); |
2383 | msg->quorum = (uint8_t) quorum; | 2408 | msg->quorum = (uint8_t)quorum; |
2384 | GNUNET_memcpy (msg->name, barrier->name, name_len); | 2409 | GNUNET_memcpy(msg->name, barrier->name, name_len); |
2385 | GNUNET_MQ_send (barrier->c->mq, env); | 2410 | GNUNET_MQ_send(barrier->c->mq, env); |
2386 | return barrier; | 2411 | return barrier; |
2387 | } | 2412 | } |
2388 | 2413 | ||
@@ -2402,18 +2427,18 @@ GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller, | |||
2402 | * @return barrier handle; NULL upon error | 2427 | * @return barrier handle; NULL upon error |
2403 | */ | 2428 | */ |
2404 | struct GNUNET_TESTBED_Barrier * | 2429 | struct GNUNET_TESTBED_Barrier * |
2405 | GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller, | 2430 | GNUNET_TESTBED_barrier_init(struct GNUNET_TESTBED_Controller *controller, |
2406 | const char *name, | 2431 | const char *name, |
2407 | unsigned int quorum, | 2432 | unsigned int quorum, |
2408 | GNUNET_TESTBED_barrier_status_cb cb, | 2433 | GNUNET_TESTBED_barrier_status_cb cb, |
2409 | void *cls) | 2434 | void *cls) |
2410 | { | 2435 | { |
2411 | return GNUNET_TESTBED_barrier_init_ (controller, | 2436 | return GNUNET_TESTBED_barrier_init_(controller, |
2412 | name, | 2437 | name, |
2413 | quorum, | 2438 | quorum, |
2414 | cb, | 2439 | cb, |
2415 | cls, | 2440 | cls, |
2416 | GNUNET_YES); | 2441 | GNUNET_YES); |
2417 | } | 2442 | } |
2418 | 2443 | ||
2419 | 2444 | ||
@@ -2423,18 +2448,18 @@ GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller, | |||
2423 | * @param barrier the barrier handle | 2448 | * @param barrier the barrier handle |
2424 | */ | 2449 | */ |
2425 | void | 2450 | void |
2426 | GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier) | 2451 | GNUNET_TESTBED_barrier_cancel(struct GNUNET_TESTBED_Barrier *barrier) |
2427 | { | 2452 | { |
2428 | struct GNUNET_MQ_Envelope *env; | 2453 | struct GNUNET_MQ_Envelope *env; |
2429 | struct GNUNET_TESTBED_BarrierCancel *msg; | 2454 | struct GNUNET_TESTBED_BarrierCancel *msg; |
2430 | size_t slen; | 2455 | size_t slen; |
2431 | 2456 | ||
2432 | slen = strlen (barrier->name); | 2457 | slen = strlen(barrier->name); |
2433 | env = | 2458 | env = |
2434 | GNUNET_MQ_msg_extra (msg, slen, GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL); | 2459 | GNUNET_MQ_msg_extra(msg, slen, GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL); |
2435 | GNUNET_memcpy (msg->name, barrier->name, slen); | 2460 | GNUNET_memcpy(msg->name, barrier->name, slen); |
2436 | GNUNET_MQ_send (barrier->c->mq, env); | 2461 | GNUNET_MQ_send(barrier->c->mq, env); |
2437 | GNUNET_TESTBED_barrier_remove_ (barrier); | 2462 | GNUNET_TESTBED_barrier_remove_(barrier); |
2438 | } | 2463 | } |
2439 | 2464 | ||
2440 | 2465 | ||
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h index a9c2a0b71..c79c35a5e 100644 --- a/src/testbed/testbed_api.h +++ b/src/testbed/testbed_api.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -41,31 +41,30 @@ | |||
41 | /** | 41 | /** |
42 | * Enumeration of operations | 42 | * Enumeration of operations |
43 | */ | 43 | */ |
44 | enum OperationType | 44 | enum OperationType { |
45 | { | 45 | /** |
46 | /** | 46 | * Peer create operation |
47 | * Peer create operation | 47 | */ |
48 | */ | ||
49 | OP_PEER_CREATE, | 48 | OP_PEER_CREATE, |
50 | 49 | ||
51 | /** | 50 | /** |
52 | * Peer start operation | 51 | * Peer start operation |
53 | */ | 52 | */ |
54 | OP_PEER_START, | 53 | OP_PEER_START, |
55 | 54 | ||
56 | /** | 55 | /** |
57 | * Peer stop operation | 56 | * Peer stop operation |
58 | */ | 57 | */ |
59 | OP_PEER_STOP, | 58 | OP_PEER_STOP, |
60 | 59 | ||
61 | /** | 60 | /** |
62 | * Peer destroy operation | 61 | * Peer destroy operation |
63 | */ | 62 | */ |
64 | OP_PEER_DESTROY, | 63 | OP_PEER_DESTROY, |
65 | 64 | ||
66 | /** | 65 | /** |
67 | * Get peer information operation | 66 | * Get peer information operation |
68 | */ | 67 | */ |
69 | OP_PEER_INFO, | 68 | OP_PEER_INFO, |
70 | 69 | ||
71 | /** | 70 | /** |
@@ -73,19 +72,19 @@ enum OperationType | |||
73 | */ | 72 | */ |
74 | OP_PEER_RECONFIGURE, | 73 | OP_PEER_RECONFIGURE, |
75 | 74 | ||
76 | /** | 75 | /** |
77 | * Overlay connection operation | 76 | * Overlay connection operation |
78 | */ | 77 | */ |
79 | OP_OVERLAY_CONNECT, | 78 | OP_OVERLAY_CONNECT, |
80 | 79 | ||
81 | /** | 80 | /** |
82 | * Forwarded operation | 81 | * Forwarded operation |
83 | */ | 82 | */ |
84 | OP_FORWARDED, | 83 | OP_FORWARDED, |
85 | 84 | ||
86 | /** | 85 | /** |
87 | * Link controllers operation | 86 | * Link controllers operation |
88 | */ | 87 | */ |
89 | OP_LINK_CONTROLLERS, | 88 | OP_LINK_CONTROLLERS, |
90 | 89 | ||
91 | /** | 90 | /** |
@@ -109,8 +108,7 @@ enum OperationType | |||
109 | /** | 108 | /** |
110 | * Enumeration of states of OperationContext | 109 | * Enumeration of states of OperationContext |
111 | */ | 110 | */ |
112 | enum OperationContextState | 111 | enum OperationContextState { |
113 | { | ||
114 | /** | 112 | /** |
115 | * The initial state where the associated operation has just been created | 113 | * The initial state where the associated operation has just been created |
116 | * and is waiting in the operation queues to be started | 114 | * and is waiting in the operation queues to be started |
@@ -134,8 +132,7 @@ enum OperationContextState | |||
134 | /** | 132 | /** |
135 | * Context information for GNUNET_TESTBED_Operation | 133 | * Context information for GNUNET_TESTBED_Operation |
136 | */ | 134 | */ |
137 | struct OperationContext | 135 | struct OperationContext { |
138 | { | ||
139 | /** | 136 | /** |
140 | * The controller to which this operation context belongs to | 137 | * The controller to which this operation context belongs to |
141 | */ | 138 | */ |
@@ -191,8 +188,7 @@ typedef void | |||
191 | * controllers can interact with each other (in a P2P fashion); those | 188 | * controllers can interact with each other (in a P2P fashion); those |
192 | * links are established via TCP/IP on the controller's service port. | 189 | * links are established via TCP/IP on the controller's service port. |
193 | */ | 190 | */ |
194 | struct GNUNET_TESTBED_Controller | 191 | struct GNUNET_TESTBED_Controller { |
195 | { | ||
196 | /** | 192 | /** |
197 | * The host where the controller is running | 193 | * The host where the controller is running |
198 | */ | 194 | */ |
@@ -269,15 +265,13 @@ struct GNUNET_TESTBED_Controller | |||
269 | * The operation id counter. use current value and increment | 265 | * The operation id counter. use current value and increment |
270 | */ | 266 | */ |
271 | uint32_t operation_counter; | 267 | uint32_t operation_counter; |
272 | |||
273 | }; | 268 | }; |
274 | 269 | ||
275 | 270 | ||
276 | /** | 271 | /** |
277 | * Handle for barrier | 272 | * Handle for barrier |
278 | */ | 273 | */ |
279 | struct GNUNET_TESTBED_Barrier | 274 | struct GNUNET_TESTBED_Barrier { |
280 | { | ||
281 | /** | 275 | /** |
282 | * hashcode identifying this barrier in the hashmap | 276 | * hashcode identifying this barrier in the hashmap |
283 | */ | 277 | */ |
@@ -319,8 +313,8 @@ struct GNUNET_TESTBED_Barrier | |||
319 | * @deprecated | 313 | * @deprecated |
320 | */ | 314 | */ |
321 | void | 315 | void |
322 | GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, | 316 | GNUNET_TESTBED_queue_message_(struct GNUNET_TESTBED_Controller *controller, |
323 | struct GNUNET_MessageHeader *msg); | 317 | struct GNUNET_MessageHeader *msg); |
324 | 318 | ||
325 | 319 | ||
326 | /** | 320 | /** |
@@ -332,8 +326,8 @@ GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, | |||
332 | * @param opc the operation context to be inserted | 326 | * @param opc the operation context to be inserted |
333 | */ | 327 | */ |
334 | void | 328 | void |
335 | GNUNET_TESTBED_insert_opc_ (struct GNUNET_TESTBED_Controller *c, | 329 | GNUNET_TESTBED_insert_opc_(struct GNUNET_TESTBED_Controller *c, |
336 | struct OperationContext *opc); | 330 | struct OperationContext *opc); |
337 | 331 | ||
338 | 332 | ||
339 | /** | 333 | /** |
@@ -344,8 +338,8 @@ GNUNET_TESTBED_insert_opc_ (struct GNUNET_TESTBED_Controller *c, | |||
344 | * @param opc the operation context to remove | 338 | * @param opc the operation context to remove |
345 | */ | 339 | */ |
346 | void | 340 | void |
347 | GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c, | 341 | GNUNET_TESTBED_remove_opc_(const struct GNUNET_TESTBED_Controller *c, |
348 | struct OperationContext *opc); | 342 | struct OperationContext *opc); |
349 | 343 | ||
350 | 344 | ||
351 | /** | 345 | /** |
@@ -358,9 +352,9 @@ GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c, | |||
358 | * @return the size of the xconfig | 352 | * @return the size of the xconfig |
359 | */ | 353 | */ |
360 | size_t | 354 | size_t |
361 | GNUNET_TESTBED_compress_config_ (const char *config, | 355 | GNUNET_TESTBED_compress_config_(const char *config, |
362 | size_t size, | 356 | size_t size, |
363 | char **xconfig); | 357 | char **xconfig); |
364 | 358 | ||
365 | 359 | ||
366 | /** | 360 | /** |
@@ -373,9 +367,9 @@ GNUNET_TESTBED_compress_config_ (const char *config, | |||
373 | * @return the serialized and compressed configuration | 367 | * @return the serialized and compressed configuration |
374 | */ | 368 | */ |
375 | char * | 369 | char * |
376 | GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg, | 370 | GNUNET_TESTBED_compress_cfg_(const struct GNUNET_CONFIGURATION_Handle *cfg, |
377 | size_t *size, | 371 | size_t *size, |
378 | size_t *xsize); | 372 | size_t *xsize); |
379 | 373 | ||
380 | 374 | ||
381 | /** | 375 | /** |
@@ -392,9 +386,9 @@ GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
392 | * @return the initialization message | 386 | * @return the initialization message |
393 | */ | 387 | */ |
394 | struct GNUNET_TESTBED_HelperInit * | 388 | struct GNUNET_TESTBED_HelperInit * |
395 | GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, | 389 | GNUNET_TESTBED_create_helper_init_msg_(const char *cname, |
396 | const char *hostname, | 390 | const char *hostname, |
397 | const struct GNUNET_CONFIGURATION_Handle *cfg); | 391 | const struct GNUNET_CONFIGURATION_Handle *cfg); |
398 | 392 | ||
399 | 393 | ||
400 | /** | 394 | /** |
@@ -412,11 +406,11 @@ GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, | |||
412 | * operation | 406 | * operation |
413 | */ | 407 | */ |
414 | struct OperationContext * | 408 | struct OperationContext * |
415 | GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller *controller, | 409 | GNUNET_TESTBED_forward_operation_msg_(struct GNUNET_TESTBED_Controller *controller, |
416 | uint64_t operation_id, | 410 | uint64_t operation_id, |
417 | const struct GNUNET_MessageHeader *msg, | 411 | const struct GNUNET_MessageHeader *msg, |
418 | GNUNET_MQ_MessageCallback cc, | 412 | GNUNET_MQ_MessageCallback cc, |
419 | void *cc_cls); | 413 | void *cc_cls); |
420 | 414 | ||
421 | /** | 415 | /** |
422 | * Function to cancel an operation created by simply forwarding an operation | 416 | * Function to cancel an operation created by simply forwarding an operation |
@@ -425,7 +419,7 @@ GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller *control | |||
425 | * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_() | 419 | * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_() |
426 | */ | 420 | */ |
427 | void | 421 | void |
428 | GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc); | 422 | GNUNET_TESTBED_forward_operation_msg_cancel_(struct OperationContext *opc); |
429 | 423 | ||
430 | 424 | ||
431 | /** | 425 | /** |
@@ -438,7 +432,7 @@ GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc); | |||
438 | * @return handle to the parsed configuration | 432 | * @return handle to the parsed configuration |
439 | */ | 433 | */ |
440 | struct GNUNET_CONFIGURATION_Handle * | 434 | struct GNUNET_CONFIGURATION_Handle * |
441 | GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg); | 435 | GNUNET_TESTBED_extract_config_(const struct GNUNET_MessageHeader *msg); |
442 | 436 | ||
443 | 437 | ||
444 | /** | 438 | /** |
@@ -449,7 +443,7 @@ GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg); | |||
449 | * @return the error message | 443 | * @return the error message |
450 | */ | 444 | */ |
451 | const char * | 445 | const char * |
452 | GNUNET_TESTBED_parse_error_string_ (const struct GNUNET_TESTBED_OperationFailureEventMessage *msg); | 446 | GNUNET_TESTBED_parse_error_string_(const struct GNUNET_TESTBED_OperationFailureEventMessage *msg); |
453 | 447 | ||
454 | 448 | ||
455 | /** | 449 | /** |
@@ -460,7 +454,7 @@ GNUNET_TESTBED_parse_error_string_ (const struct GNUNET_TESTBED_OperationFailure | |||
460 | * @return the incremented operation id. | 454 | * @return the incremented operation id. |
461 | */ | 455 | */ |
462 | uint64_t | 456 | uint64_t |
463 | GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller); | 457 | GNUNET_TESTBED_get_next_op_id(struct GNUNET_TESTBED_Controller *controller); |
464 | 458 | ||
465 | 459 | ||
466 | /** | 460 | /** |
@@ -476,9 +470,9 @@ GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller); | |||
476 | * @return the operation handle; | 470 | * @return the operation handle; |
477 | */ | 471 | */ |
478 | struct GNUNET_TESTBED_Operation * | 472 | struct GNUNET_TESTBED_Operation * |
479 | GNUNET_TESTBED_get_slave_config_ (void *op_cls, | 473 | GNUNET_TESTBED_get_slave_config_(void *op_cls, |
480 | struct GNUNET_TESTBED_Controller *master, | 474 | struct GNUNET_TESTBED_Controller *master, |
481 | uint32_t slave_host_id); | 475 | uint32_t slave_host_id); |
482 | 476 | ||
483 | 477 | ||
484 | 478 | ||
@@ -499,12 +493,12 @@ GNUNET_TESTBED_get_slave_config_ (void *op_cls, | |||
499 | * @return barrier handle; NULL upon error | 493 | * @return barrier handle; NULL upon error |
500 | */ | 494 | */ |
501 | struct GNUNET_TESTBED_Barrier * | 495 | struct GNUNET_TESTBED_Barrier * |
502 | GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller, | 496 | GNUNET_TESTBED_barrier_init_(struct GNUNET_TESTBED_Controller *controller, |
503 | const char *name, | 497 | const char *name, |
504 | unsigned int quorum, | 498 | unsigned int quorum, |
505 | GNUNET_TESTBED_barrier_status_cb cb, | 499 | GNUNET_TESTBED_barrier_status_cb cb, |
506 | void *cls, | 500 | void *cls, |
507 | int echo); | 501 | int echo); |
508 | 502 | ||
509 | 503 | ||
510 | /** | 504 | /** |
@@ -514,7 +508,7 @@ GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller, | |||
514 | * @param barrier the barrier to remove | 508 | * @param barrier the barrier to remove |
515 | */ | 509 | */ |
516 | void | 510 | void |
517 | GNUNET_TESTBED_barrier_remove_ (struct GNUNET_TESTBED_Barrier *barrier); | 511 | GNUNET_TESTBED_barrier_remove_(struct GNUNET_TESTBED_Barrier *barrier); |
518 | 512 | ||
519 | 513 | ||
520 | 514 | ||
diff --git a/src/testbed/testbed_api_barriers.c b/src/testbed/testbed_api_barriers.c index f811b6381..7e38b4297 100644 --- a/src/testbed/testbed_api_barriers.c +++ b/src/testbed/testbed_api_barriers.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2013, 2016 GNUnet e.V. | 3 | Copyright (C) 2008--2013, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/testbed_api_barriers.c | 22 | * @file testbed/testbed_api_barriers.c |
@@ -31,20 +31,19 @@ | |||
31 | * Logging shorthand | 31 | * Logging shorthand |
32 | */ | 32 | */ |
33 | #define LOG(type, ...) \ | 33 | #define LOG(type, ...) \ |
34 | GNUNET_log_from (type, "testbed-api-barriers", __VA_ARGS__); | 34 | GNUNET_log_from(type, "testbed-api-barriers", __VA_ARGS__); |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Debug logging shorthand | 37 | * Debug logging shorthand |
38 | */ | 38 | */ |
39 | #define LOG_DEBUG(...) \ | 39 | #define LOG_DEBUG(...) \ |
40 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); | 40 | LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); |
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Barrier wait handle | 44 | * Barrier wait handle |
45 | */ | 45 | */ |
46 | struct GNUNET_TESTBED_BarrierWaitHandle | 46 | struct GNUNET_TESTBED_BarrierWaitHandle { |
47 | { | ||
48 | /** | 47 | /** |
49 | * The name of the barrier | 48 | * The name of the barrier |
50 | */ | 49 | */ |
@@ -81,8 +80,8 @@ struct GNUNET_TESTBED_BarrierWaitHandle | |||
81 | * @return #GNUNET_OK if the message is well-formed. | 80 | * @return #GNUNET_OK if the message is well-formed. |
82 | */ | 81 | */ |
83 | static int | 82 | static int |
84 | check_status (void *cls, | 83 | check_status(void *cls, |
85 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) | 84 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) |
86 | { | 85 | { |
87 | /* FIXME: this fails to actually check that the message | 86 | /* FIXME: this fails to actually check that the message |
88 | follows the protocol spec (0-terminations!). However, | 87 | follows the protocol spec (0-terminations!). However, |
@@ -100,40 +99,43 @@ check_status (void *cls, | |||
100 | * @param msg received message | 99 | * @param msg received message |
101 | */ | 100 | */ |
102 | static void | 101 | static void |
103 | handle_status (void *cls, | 102 | handle_status(void *cls, |
104 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) | 103 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) |
105 | { | 104 | { |
106 | struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; | 105 | struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; |
107 | 106 | ||
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 107 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
109 | "Got barrier status %d\n", | 108 | "Got barrier status %d\n", |
110 | (int) ntohs (msg->status)); | 109 | (int)ntohs(msg->status)); |
111 | switch (ntohs (msg->status)) | 110 | switch (ntohs(msg->status)) |
112 | { | 111 | { |
113 | case GNUNET_TESTBED_BARRIERSTATUS_ERROR: | 112 | case GNUNET_TESTBED_BARRIERSTATUS_ERROR: |
114 | h->cb (h->cb_cls, | 113 | h->cb(h->cb_cls, |
115 | h->name, | 114 | h->name, |
116 | GNUNET_SYSERR); | 115 | GNUNET_SYSERR); |
117 | break; | 116 | break; |
118 | case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: | 117 | |
119 | h->cb (h->cb_cls, | 118 | case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: |
120 | h->name, | 119 | h->cb(h->cb_cls, |
121 | GNUNET_SYSERR); | 120 | h->name, |
122 | GNUNET_break (0); | 121 | GNUNET_SYSERR); |
123 | break; | 122 | GNUNET_break(0); |
124 | case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: | 123 | break; |
125 | h->cb (h->cb_cls, | 124 | |
126 | h->name, | 125 | case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: |
127 | GNUNET_OK); | 126 | h->cb(h->cb_cls, |
128 | break; | 127 | h->name, |
129 | default: | 128 | GNUNET_OK); |
130 | GNUNET_break_op (0); | 129 | break; |
131 | h->cb (h->cb_cls, | 130 | |
132 | h->name, | 131 | default: |
133 | GNUNET_SYSERR); | 132 | GNUNET_break_op(0); |
134 | break; | 133 | h->cb(h->cb_cls, |
135 | } | 134 | h->name, |
136 | GNUNET_TESTBED_barrier_wait_cancel (h); | 135 | GNUNET_SYSERR); |
136 | break; | ||
137 | } | ||
138 | GNUNET_TESTBED_barrier_wait_cancel(h); | ||
137 | } | 139 | } |
138 | 140 | ||
139 | 141 | ||
@@ -146,15 +148,15 @@ handle_status (void *cls, | |||
146 | * @param error error code | 148 | * @param error error code |
147 | */ | 149 | */ |
148 | static void | 150 | static void |
149 | mq_error_handler (void *cls, | 151 | mq_error_handler(void *cls, |
150 | enum GNUNET_MQ_Error error) | 152 | enum GNUNET_MQ_Error error) |
151 | { | 153 | { |
152 | struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; | 154 | struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; |
153 | 155 | ||
154 | h->cb (h->cb_cls, | 156 | h->cb(h->cb_cls, |
155 | h->name, | 157 | h->name, |
156 | GNUNET_SYSERR); | 158 | GNUNET_SYSERR); |
157 | GNUNET_TESTBED_barrier_wait_cancel (h); | 159 | GNUNET_TESTBED_barrier_wait_cancel(h); |
158 | } | 160 | } |
159 | 161 | ||
160 | 162 | ||
@@ -170,72 +172,72 @@ mq_error_handler (void *cls, | |||
170 | * anytime before the callback is called. NULL upon error. | 172 | * anytime before the callback is called. NULL upon error. |
171 | */ | 173 | */ |
172 | struct GNUNET_TESTBED_BarrierWaitHandle * | 174 | struct GNUNET_TESTBED_BarrierWaitHandle * |
173 | GNUNET_TESTBED_barrier_wait (const char *name, | 175 | GNUNET_TESTBED_barrier_wait(const char *name, |
174 | GNUNET_TESTBED_barrier_wait_cb cb, | 176 | GNUNET_TESTBED_barrier_wait_cb cb, |
175 | void *cb_cls) | 177 | void *cb_cls) |
176 | { | 178 | { |
177 | struct GNUNET_TESTBED_BarrierWaitHandle *h | 179 | struct GNUNET_TESTBED_BarrierWaitHandle *h |
178 | = GNUNET_new (struct GNUNET_TESTBED_BarrierWaitHandle); | 180 | = GNUNET_new(struct GNUNET_TESTBED_BarrierWaitHandle); |
179 | struct GNUNET_MQ_MessageHandler handlers[] = { | 181 | struct GNUNET_MQ_MessageHandler handlers[] = { |
180 | GNUNET_MQ_hd_var_size (status, | 182 | GNUNET_MQ_hd_var_size(status, |
181 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, | 183 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, |
182 | struct GNUNET_TESTBED_BarrierStatusMsg, | 184 | struct GNUNET_TESTBED_BarrierStatusMsg, |
183 | h), | 185 | h), |
184 | GNUNET_MQ_handler_end () | 186 | GNUNET_MQ_handler_end() |
185 | }; | 187 | }; |
186 | struct GNUNET_MQ_Envelope *env; | 188 | struct GNUNET_MQ_Envelope *env; |
187 | struct GNUNET_TESTBED_BarrierWait *msg; | 189 | struct GNUNET_TESTBED_BarrierWait *msg; |
188 | const char *cfg_filename; | 190 | const char *cfg_filename; |
189 | size_t name_len; | 191 | size_t name_len; |
190 | 192 | ||
191 | GNUNET_assert (NULL != cb); | 193 | GNUNET_assert(NULL != cb); |
192 | cfg_filename = getenv (ENV_TESTBED_CONFIG); | 194 | cfg_filename = getenv(ENV_TESTBED_CONFIG); |
193 | if (NULL == cfg_filename) | 195 | if (NULL == cfg_filename) |
194 | { | 196 | { |
195 | LOG (GNUNET_ERROR_TYPE_ERROR, | 197 | LOG(GNUNET_ERROR_TYPE_ERROR, |
196 | "Are you running under testbed?\n"); | 198 | "Are you running under testbed?\n"); |
197 | GNUNET_free (h); | 199 | GNUNET_free(h); |
198 | return NULL; | 200 | return NULL; |
199 | } | 201 | } |
200 | h->cfg = GNUNET_CONFIGURATION_create (); | 202 | h->cfg = GNUNET_CONFIGURATION_create(); |
201 | if (GNUNET_OK != | 203 | if (GNUNET_OK != |
202 | GNUNET_CONFIGURATION_load (h->cfg, | 204 | GNUNET_CONFIGURATION_load(h->cfg, |
203 | cfg_filename)) | 205 | cfg_filename)) |
204 | { | 206 | { |
205 | LOG (GNUNET_ERROR_TYPE_ERROR, | 207 | LOG(GNUNET_ERROR_TYPE_ERROR, |
206 | "Unable to load configuration from file `%s'\n", | 208 | "Unable to load configuration from file `%s'\n", |
207 | cfg_filename); | 209 | cfg_filename); |
208 | GNUNET_CONFIGURATION_destroy (h->cfg); | 210 | GNUNET_CONFIGURATION_destroy(h->cfg); |
209 | GNUNET_free (h); | 211 | GNUNET_free(h); |
210 | return NULL; | 212 | return NULL; |
211 | } | 213 | } |
212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 214 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
213 | "Waiting on barrier `%s'\n", | 215 | "Waiting on barrier `%s'\n", |
214 | name); | 216 | name); |
215 | h->name = GNUNET_strdup (name); | 217 | h->name = GNUNET_strdup(name); |
216 | h->cb = cb; | 218 | h->cb = cb; |
217 | h->cb_cls = cb_cls; | 219 | h->cb_cls = cb_cls; |
218 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 220 | h->mq = GNUNET_CLIENT_connect(h->cfg, |
219 | "testbed-barrier", | 221 | "testbed-barrier", |
220 | handlers, | 222 | handlers, |
221 | &mq_error_handler, | 223 | &mq_error_handler, |
222 | h); | 224 | h); |
223 | if (NULL == h->mq) | 225 | if (NULL == h->mq) |
224 | { | 226 | { |
225 | LOG (GNUNET_ERROR_TYPE_ERROR, | 227 | LOG(GNUNET_ERROR_TYPE_ERROR, |
226 | "Unable to connect to local testbed-barrier service\n"); | 228 | "Unable to connect to local testbed-barrier service\n"); |
227 | GNUNET_TESTBED_barrier_wait_cancel (h); | 229 | GNUNET_TESTBED_barrier_wait_cancel(h); |
228 | return NULL; | 230 | return NULL; |
229 | } | 231 | } |
230 | name_len = strlen (name); /* NOTE: unusual to not have 0-termination, change? */ | 232 | name_len = strlen(name); /* NOTE: unusual to not have 0-termination, change? */ |
231 | env = GNUNET_MQ_msg_extra (msg, | 233 | env = GNUNET_MQ_msg_extra(msg, |
232 | name_len, | 234 | name_len, |
233 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT); | 235 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT); |
234 | GNUNET_memcpy (msg->name, | 236 | GNUNET_memcpy(msg->name, |
235 | name, | 237 | name, |
236 | name_len); | 238 | name_len); |
237 | GNUNET_MQ_send (h->mq, | 239 | GNUNET_MQ_send(h->mq, |
238 | env); | 240 | env); |
239 | return h; | 241 | return h; |
240 | } | 242 | } |
241 | 243 | ||
@@ -246,16 +248,16 @@ GNUNET_TESTBED_barrier_wait (const char *name, | |||
246 | * @param h the barrier wait handle | 248 | * @param h the barrier wait handle |
247 | */ | 249 | */ |
248 | void | 250 | void |
249 | GNUNET_TESTBED_barrier_wait_cancel (struct GNUNET_TESTBED_BarrierWaitHandle *h) | 251 | GNUNET_TESTBED_barrier_wait_cancel(struct GNUNET_TESTBED_BarrierWaitHandle *h) |
250 | { | 252 | { |
251 | if (NULL != h->mq) | 253 | if (NULL != h->mq) |
252 | { | 254 | { |
253 | GNUNET_MQ_destroy (h->mq); | 255 | GNUNET_MQ_destroy(h->mq); |
254 | h->mq = NULL; | 256 | h->mq = NULL; |
255 | } | 257 | } |
256 | GNUNET_free (h->name); | 258 | GNUNET_free(h->name); |
257 | GNUNET_CONFIGURATION_destroy (h->cfg); | 259 | GNUNET_CONFIGURATION_destroy(h->cfg); |
258 | GNUNET_free (h); | 260 | GNUNET_free(h); |
259 | } | 261 | } |
260 | 262 | ||
261 | /* end of testbed_api_barriers.c */ | 263 | /* end of testbed_api_barriers.c */ |
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index e824a5f23..cbcfe1a18 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -42,24 +42,24 @@ | |||
42 | /** | 42 | /** |
43 | * Generic logging shorthand | 43 | * Generic logging shorthand |
44 | */ | 44 | */ |
45 | #define LOG(kind, ...) GNUNET_log_from (kind, "testbed-api-hosts", __VA_ARGS__); | 45 | #define LOG(kind, ...) GNUNET_log_from(kind, "testbed-api-hosts", __VA_ARGS__); |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Debug logging shorthand | 48 | * Debug logging shorthand |
49 | */ | 49 | */ |
50 | #define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); | 50 | #define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Prints API violation message | 53 | * Prints API violation message |
54 | */ | 54 | */ |
55 | #define API_VIOLATION(cond, errstr) \ | 55 | #define API_VIOLATION(cond, errstr) \ |
56 | do \ | 56 | do \ |
57 | { \ | 57 | { \ |
58 | if (cond) \ | 58 | if (cond) \ |
59 | break; \ | 59 | break; \ |
60 | LOG (GNUNET_ERROR_TYPE_ERROR, "API violation detected: %s\n", errstr); \ | 60 | LOG (GNUNET_ERROR_TYPE_ERROR, "API violation detected: %s\n", errstr); \ |
61 | GNUNET_assert (0); \ | 61 | GNUNET_assert(0); \ |
62 | } while (0) | 62 | } while (0) |
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Log an error message at log-level 'level' that indicates a failure of the | 65 | * Log an error message at log-level 'level' that indicates a failure of the |
@@ -67,14 +67,14 @@ | |||
67 | */ | 67 | */ |
68 | #define LOG_GAI(level, cmd, rc) \ | 68 | #define LOG_GAI(level, cmd, rc) \ |
69 | do \ | 69 | do \ |
70 | { \ | 70 | { \ |
71 | LOG (level, \ | 71 | LOG(level, \ |
72 | _ ("`%s' failed at %s:%d with error: %s\n"), \ | 72 | _("`%s' failed at %s:%d with error: %s\n"), \ |
73 | cmd, \ | 73 | cmd, \ |
74 | __FILE__, \ | 74 | __FILE__, \ |
75 | __LINE__, \ | 75 | __LINE__, \ |
76 | gai_strerror (rc)); \ | 76 | gai_strerror(rc)); \ |
77 | } while (0) | 77 | } while (0) |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * Number of extra elements we create space for when we grow host list | 80 | * Number of extra elements we create space for when we grow host list |
@@ -85,8 +85,7 @@ | |||
85 | /** | 85 | /** |
86 | * A list entry for registered controllers list | 86 | * A list entry for registered controllers list |
87 | */ | 87 | */ |
88 | struct RegisteredController | 88 | struct RegisteredController { |
89 | { | ||
90 | /** | 89 | /** |
91 | * The controller at which this host is registered | 90 | * The controller at which this host is registered |
92 | */ | 91 | */ |
@@ -109,9 +108,7 @@ struct RegisteredController | |||
109 | * The master process must be able to SSH to this host without password (via | 108 | * The master process must be able to SSH to this host without password (via |
110 | * ssh-agent). | 109 | * ssh-agent). |
111 | */ | 110 | */ |
112 | struct GNUNET_TESTBED_Host | 111 | struct GNUNET_TESTBED_Host { |
113 | { | ||
114 | |||
115 | /** | 112 | /** |
116 | * The hostname of the host; NULL for localhost | 113 | * The hostname of the host; NULL for localhost |
117 | */ | 114 | */ |
@@ -187,7 +184,7 @@ static unsigned int host_list_size; | |||
187 | * @return handle to the host, NULL if host not found | 184 | * @return handle to the host, NULL if host not found |
188 | */ | 185 | */ |
189 | struct GNUNET_TESTBED_Host * | 186 | struct GNUNET_TESTBED_Host * |
190 | GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id) | 187 | GNUNET_TESTBED_host_lookup_by_id_(uint32_t id) |
191 | { | 188 | { |
192 | if (host_list_size <= id) | 189 | if (host_list_size <= id) |
193 | return NULL; | 190 | return NULL; |
@@ -208,11 +205,11 @@ GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id) | |||
208 | * @return handle to the host, NULL on error | 205 | * @return handle to the host, NULL on error |
209 | */ | 206 | */ |
210 | struct GNUNET_TESTBED_Host * | 207 | struct GNUNET_TESTBED_Host * |
211 | GNUNET_TESTBED_host_create_by_id_ ( | 208 | GNUNET_TESTBED_host_create_by_id_( |
212 | uint32_t id, | 209 | uint32_t id, |
213 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 210 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
214 | { | 211 | { |
215 | return GNUNET_TESTBED_host_create_with_id (id, NULL, NULL, cfg, 0); | 212 | return GNUNET_TESTBED_host_create_with_id(id, NULL, NULL, cfg, 0); |
216 | } | 213 | } |
217 | 214 | ||
218 | 215 | ||
@@ -224,7 +221,7 @@ GNUNET_TESTBED_host_create_by_id_ ( | |||
224 | * 'localhost', but then obviously not globally unique) | 221 | * 'localhost', but then obviously not globally unique) |
225 | */ | 222 | */ |
226 | uint32_t | 223 | uint32_t |
227 | GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host) | 224 | GNUNET_TESTBED_host_get_id_(const struct GNUNET_TESTBED_Host *host) |
228 | { | 225 | { |
229 | return host->id; | 226 | return host->id; |
230 | } | 227 | } |
@@ -237,7 +234,7 @@ GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host) | |||
237 | * @return hostname of the host | 234 | * @return hostname of the host |
238 | */ | 235 | */ |
239 | const char * | 236 | const char * |
240 | GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host) | 237 | GNUNET_TESTBED_host_get_hostname(const struct GNUNET_TESTBED_Host *host) |
241 | { | 238 | { |
242 | return host->hostname; | 239 | return host->hostname; |
243 | } | 240 | } |
@@ -250,7 +247,7 @@ GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host) | |||
250 | * @return username to login to the host | 247 | * @return username to login to the host |
251 | */ | 248 | */ |
252 | const char * | 249 | const char * |
253 | GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host) | 250 | GNUNET_TESTBED_host_get_username_(const struct GNUNET_TESTBED_Host *host) |
254 | { | 251 | { |
255 | return host->username; | 252 | return host->username; |
256 | } | 253 | } |
@@ -263,7 +260,7 @@ GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host) | |||
263 | * @return username to login to the host | 260 | * @return username to login to the host |
264 | */ | 261 | */ |
265 | uint16_t | 262 | uint16_t |
266 | GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host) | 263 | GNUNET_TESTBED_host_get_ssh_port_(const struct GNUNET_TESTBED_Host *host) |
267 | { | 264 | { |
268 | return host->port; | 265 | return host->port; |
269 | } | 266 | } |
@@ -276,7 +273,7 @@ GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host) | |||
276 | * @return GNUNET_YES if the controller is already started; GNUNET_NO if not | 273 | * @return GNUNET_YES if the controller is already started; GNUNET_NO if not |
277 | */ | 274 | */ |
278 | int | 275 | int |
279 | GNUNET_TESTBED_host_controller_started (const struct GNUNET_TESTBED_Host *host) | 276 | GNUNET_TESTBED_host_controller_started(const struct GNUNET_TESTBED_Host *host) |
280 | { | 277 | { |
281 | return host->controller_started; | 278 | return host->controller_started; |
282 | } | 279 | } |
@@ -289,7 +286,7 @@ GNUNET_TESTBED_host_controller_started (const struct GNUNET_TESTBED_Host *host) | |||
289 | * @return the host's configuration template | 286 | * @return the host's configuration template |
290 | */ | 287 | */ |
291 | const struct GNUNET_CONFIGURATION_Handle * | 288 | const struct GNUNET_CONFIGURATION_Handle * |
292 | GNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host) | 289 | GNUNET_TESTBED_host_get_cfg_(const struct GNUNET_TESTBED_Host *host) |
293 | { | 290 | { |
294 | return host->cfg; | 291 | return host->cfg; |
295 | } | 292 | } |
@@ -302,12 +299,12 @@ GNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host) | |||
302 | * @param new_cfg the new configuration to replace the old one | 299 | * @param new_cfg the new configuration to replace the old one |
303 | */ | 300 | */ |
304 | void | 301 | void |
305 | GNUNET_TESTBED_host_replace_cfg_ ( | 302 | GNUNET_TESTBED_host_replace_cfg_( |
306 | struct GNUNET_TESTBED_Host *host, | 303 | struct GNUNET_TESTBED_Host *host, |
307 | const struct GNUNET_CONFIGURATION_Handle *new_cfg) | 304 | const struct GNUNET_CONFIGURATION_Handle *new_cfg) |
308 | { | 305 | { |
309 | GNUNET_CONFIGURATION_destroy (host->cfg); | 306 | GNUNET_CONFIGURATION_destroy(host->cfg); |
310 | host->cfg = GNUNET_CONFIGURATION_dup (new_cfg); | 307 | host->cfg = GNUNET_CONFIGURATION_dup(new_cfg); |
311 | } | 308 | } |
312 | 309 | ||
313 | 310 | ||
@@ -325,7 +322,7 @@ GNUNET_TESTBED_host_replace_cfg_ ( | |||
325 | * @return handle to the host, NULL on error | 322 | * @return handle to the host, NULL on error |
326 | */ | 323 | */ |
327 | struct GNUNET_TESTBED_Host * | 324 | struct GNUNET_TESTBED_Host * |
328 | GNUNET_TESTBED_host_create_with_id ( | 325 | GNUNET_TESTBED_host_create_with_id( |
329 | uint32_t id, | 326 | uint32_t id, |
330 | const char *hostname, | 327 | const char *hostname, |
331 | const char *username, | 328 | const char *username, |
@@ -336,26 +333,26 @@ GNUNET_TESTBED_host_create_with_id ( | |||
336 | unsigned int new_size; | 333 | unsigned int new_size; |
337 | 334 | ||
338 | if ((id < host_list_size) && (NULL != host_list[id])) | 335 | if ((id < host_list_size) && (NULL != host_list[id])) |
339 | { | 336 | { |
340 | LOG (GNUNET_ERROR_TYPE_WARNING, "Host with id: %u already created\n", id); | 337 | LOG(GNUNET_ERROR_TYPE_WARNING, "Host with id: %u already created\n", id); |
341 | return NULL; | 338 | return NULL; |
342 | } | 339 | } |
343 | host = GNUNET_new (struct GNUNET_TESTBED_Host); | 340 | host = GNUNET_new(struct GNUNET_TESTBED_Host); |
344 | host->hostname = (NULL != hostname) ? GNUNET_strdup (hostname) : NULL; | 341 | host->hostname = (NULL != hostname) ? GNUNET_strdup(hostname) : NULL; |
345 | host->username = (NULL != username) ? GNUNET_strdup (username) : NULL; | 342 | host->username = (NULL != username) ? GNUNET_strdup(username) : NULL; |
346 | host->id = id; | 343 | host->id = id; |
347 | host->port = (0 == port) ? 22 : port; | 344 | host->port = (0 == port) ? 22 : port; |
348 | host->cfg = GNUNET_CONFIGURATION_dup (cfg); | 345 | host->cfg = GNUNET_CONFIGURATION_dup(cfg); |
349 | host->opq_parallel_overlay_connect_operations = | 346 | host->opq_parallel_overlay_connect_operations = |
350 | GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_ADAPTIVE, | 347 | GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_ADAPTIVE, |
351 | UINT_MAX); | 348 | UINT_MAX); |
352 | new_size = host_list_size; | 349 | new_size = host_list_size; |
353 | while (id >= new_size) | 350 | while (id >= new_size) |
354 | new_size += HOST_LIST_GROW_STEP; | 351 | new_size += HOST_LIST_GROW_STEP; |
355 | if (new_size != host_list_size) | 352 | if (new_size != host_list_size) |
356 | GNUNET_array_grow (host_list, host_list_size, new_size); | 353 | GNUNET_array_grow(host_list, host_list_size, new_size); |
357 | GNUNET_assert (id < host_list_size); | 354 | GNUNET_assert(id < host_list_size); |
358 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding host with id: %u\n", host->id); | 355 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Adding host with id: %u\n", host->id); |
359 | host_list[id] = host; | 356 | host_list[id] = host; |
360 | return host; | 357 | return host; |
361 | } | 358 | } |
@@ -373,24 +370,24 @@ GNUNET_TESTBED_host_create_with_id ( | |||
373 | * @return handle to the host, NULL on error | 370 | * @return handle to the host, NULL on error |
374 | */ | 371 | */ |
375 | struct GNUNET_TESTBED_Host * | 372 | struct GNUNET_TESTBED_Host * |
376 | GNUNET_TESTBED_host_create (const char *hostname, | 373 | GNUNET_TESTBED_host_create(const char *hostname, |
377 | const char *username, | 374 | const char *username, |
378 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 375 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
379 | uint16_t port) | 376 | uint16_t port) |
380 | { | 377 | { |
381 | static uint32_t uid_generator; | 378 | static uint32_t uid_generator; |
382 | 379 | ||
383 | if (NULL == hostname) | 380 | if (NULL == hostname) |
384 | return GNUNET_TESTBED_host_create_with_id (0, | 381 | return GNUNET_TESTBED_host_create_with_id(0, |
385 | hostname, | 382 | hostname, |
386 | username, | 383 | username, |
387 | cfg, | 384 | cfg, |
388 | port); | 385 | port); |
389 | return GNUNET_TESTBED_host_create_with_id (++uid_generator, | 386 | return GNUNET_TESTBED_host_create_with_id(++uid_generator, |
390 | hostname, | 387 | hostname, |
391 | username, | 388 | username, |
392 | cfg, | 389 | cfg, |
393 | port); | 390 | port); |
394 | } | 391 | } |
395 | 392 | ||
396 | 393 | ||
@@ -406,7 +403,7 @@ GNUNET_TESTBED_host_create (const char *hostname, | |||
406 | * @return number of hosts returned in 'hosts', 0 on error | 403 | * @return number of hosts returned in 'hosts', 0 on error |
407 | */ | 404 | */ |
408 | unsigned int | 405 | unsigned int |
409 | GNUNET_TESTBED_hosts_load_from_file ( | 406 | GNUNET_TESTBED_hosts_load_from_file( |
410 | const char *filename, | 407 | const char *filename, |
411 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 408 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
412 | struct GNUNET_TESTBED_Host ***hosts) | 409 | struct GNUNET_TESTBED_Host ***hosts) |
@@ -424,104 +421,104 @@ GNUNET_TESTBED_hosts_load_from_file ( | |||
424 | unsigned int count; | 421 | unsigned int count; |
425 | 422 | ||
426 | 423 | ||
427 | GNUNET_assert (NULL != filename); | 424 | GNUNET_assert(NULL != filename); |
428 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | 425 | if (GNUNET_YES != GNUNET_DISK_file_test(filename)) |
429 | { | 426 | { |
430 | LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Hosts file %s not found\n"), filename); | 427 | LOG(GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s not found\n"), filename); |
431 | return 0; | 428 | return 0; |
432 | } | 429 | } |
433 | if (GNUNET_OK != | 430 | if (GNUNET_OK != |
434 | GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) | 431 | GNUNET_DISK_file_size(filename, &fs, GNUNET_YES, GNUNET_YES)) |
435 | fs = 0; | 432 | fs = 0; |
436 | if (0 == fs) | 433 | if (0 == fs) |
437 | { | 434 | { |
438 | LOG (GNUNET_ERROR_TYPE_WARNING, | 435 | LOG(GNUNET_ERROR_TYPE_WARNING, |
439 | _ ("Hosts file %s has no data\n"), | 436 | _("Hosts file %s has no data\n"), |
440 | filename); | 437 | filename); |
441 | return 0; | 438 | return 0; |
442 | } | 439 | } |
443 | data = GNUNET_malloc (fs); | 440 | data = GNUNET_malloc(fs); |
444 | if (fs != GNUNET_DISK_fn_read (filename, data, fs)) | 441 | if (fs != GNUNET_DISK_fn_read(filename, data, fs)) |
445 | { | 442 | { |
446 | GNUNET_free (data); | 443 | GNUNET_free(data); |
447 | LOG (GNUNET_ERROR_TYPE_WARNING, | 444 | LOG(GNUNET_ERROR_TYPE_WARNING, |
448 | _ ("Hosts file %s cannot be read\n"), | 445 | _("Hosts file %s cannot be read\n"), |
449 | filename); | 446 | filename); |
450 | return 0; | 447 | return 0; |
451 | } | 448 | } |
452 | buf = data; | 449 | buf = data; |
453 | offset = 0; | 450 | offset = 0; |
454 | starting_host = NULL; | 451 | starting_host = NULL; |
455 | count = 0; | 452 | count = 0; |
456 | /* refer RFC 952 and RFC 1123 for valid hostnames */ | 453 | /* refer RFC 952 and RFC 1123 for valid hostnames */ |
457 | GNUNET_assert (0 == regcomp (&rex, | 454 | GNUNET_assert(0 == regcomp(&rex, |
458 | "^(([[:alnum:]]+)@)?" /* username */ | 455 | "^(([[:alnum:]]+)@)?" /* username */ |
459 | "([[:alnum:]]+[-[:alnum:]_\\.]+)" /* hostname */ | 456 | "([[:alnum:]]+[-[:alnum:]_\\.]+)" /* hostname */ |
460 | "(:([[:digit:]]{1,5}))?", /* port */ | 457 | "(:([[:digit:]]{1,5}))?", /* port */ |
461 | REG_EXTENDED | REG_ICASE)); | 458 | REG_EXTENDED | REG_ICASE)); |
462 | while (offset < (fs - 1)) | 459 | while (offset < (fs - 1)) |
463 | { | ||
464 | offset++; | ||
465 | if (((data[offset] == '\n')) && (buf != &data[offset])) | ||
466 | { | 460 | { |
467 | unsigned int size; | 461 | offset++; |
468 | 462 | if (((data[offset] == '\n')) && (buf != &data[offset])) | |
469 | data[offset] = '\0'; | 463 | { |
470 | username = NULL; | 464 | unsigned int size; |
471 | hostname = NULL; | 465 | |
472 | port = 0; | 466 | data[offset] = '\0'; |
473 | if ((REG_NOMATCH == regexec (&rex, buf, 6, pmatch, 0)) || | 467 | username = NULL; |
474 | (-1 == pmatch[3].rm_so)) | 468 | hostname = NULL; |
475 | { | 469 | port = 0; |
476 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 470 | if ((REG_NOMATCH == regexec(&rex, buf, 6, pmatch, 0)) || |
477 | "Error reading line `%s' in hostfile\n", | 471 | (-1 == pmatch[3].rm_so)) |
478 | buf); | 472 | { |
473 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
474 | "Error reading line `%s' in hostfile\n", | ||
475 | buf); | ||
476 | buf = &data[offset + 1]; | ||
477 | continue; | ||
478 | } | ||
479 | if (-1 != pmatch[2].rm_so) | ||
480 | { | ||
481 | size = pmatch[2].rm_eo - pmatch[2].rm_so; | ||
482 | username = GNUNET_malloc(size + 1); | ||
483 | GNUNET_assert( | ||
484 | 0 != GNUNET_strlcpy(username, buf + pmatch[2].rm_so, size + 1)); | ||
485 | } | ||
486 | if (-1 != pmatch[5].rm_so) | ||
487 | { | ||
488 | (void)sscanf(buf + pmatch[5].rm_so, "%5hd", &port); | ||
489 | } | ||
490 | size = pmatch[3].rm_eo - pmatch[3].rm_so; | ||
491 | hostname = GNUNET_malloc(size + 1); | ||
492 | GNUNET_assert( | ||
493 | 0 != GNUNET_strlcpy(hostname, buf + pmatch[3].rm_so, size + 1)); | ||
494 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
495 | "Successfully read host %s, port %d and user %s from file\n", | ||
496 | (NULL == hostname) ? "NULL" : hostname, | ||
497 | port, | ||
498 | (NULL == username) ? "NULL" : username); | ||
499 | /* We store hosts in a static list; hence we only require the starting | ||
500 | * host pointer in that list to access the newly created list of hosts */ | ||
501 | if (NULL == starting_host) | ||
502 | starting_host = | ||
503 | GNUNET_TESTBED_host_create(hostname, username, cfg, port); | ||
504 | else | ||
505 | (void)GNUNET_TESTBED_host_create(hostname, username, cfg, port); | ||
506 | count++; | ||
507 | GNUNET_free_non_null(username); | ||
508 | GNUNET_free(hostname); | ||
509 | buf = &data[offset + 1]; | ||
510 | } | ||
511 | else if ((data[offset] == '\n') || (data[offset] == '\0')) | ||
479 | buf = &data[offset + 1]; | 512 | buf = &data[offset + 1]; |
480 | continue; | ||
481 | } | ||
482 | if (-1 != pmatch[2].rm_so) | ||
483 | { | ||
484 | size = pmatch[2].rm_eo - pmatch[2].rm_so; | ||
485 | username = GNUNET_malloc (size + 1); | ||
486 | GNUNET_assert ( | ||
487 | 0 != GNUNET_strlcpy (username, buf + pmatch[2].rm_so, size + 1)); | ||
488 | } | ||
489 | if (-1 != pmatch[5].rm_so) | ||
490 | { | ||
491 | (void) sscanf (buf + pmatch[5].rm_so, "%5hd", &port); | ||
492 | } | ||
493 | size = pmatch[3].rm_eo - pmatch[3].rm_so; | ||
494 | hostname = GNUNET_malloc (size + 1); | ||
495 | GNUNET_assert ( | ||
496 | 0 != GNUNET_strlcpy (hostname, buf + pmatch[3].rm_so, size + 1)); | ||
497 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
498 | "Successfully read host %s, port %d and user %s from file\n", | ||
499 | (NULL == hostname) ? "NULL" : hostname, | ||
500 | port, | ||
501 | (NULL == username) ? "NULL" : username); | ||
502 | /* We store hosts in a static list; hence we only require the starting | ||
503 | * host pointer in that list to access the newly created list of hosts */ | ||
504 | if (NULL == starting_host) | ||
505 | starting_host = | ||
506 | GNUNET_TESTBED_host_create (hostname, username, cfg, port); | ||
507 | else | ||
508 | (void) GNUNET_TESTBED_host_create (hostname, username, cfg, port); | ||
509 | count++; | ||
510 | GNUNET_free_non_null (username); | ||
511 | GNUNET_free (hostname); | ||
512 | buf = &data[offset + 1]; | ||
513 | } | 513 | } |
514 | else if ((data[offset] == '\n') || (data[offset] == '\0')) | 514 | regfree(&rex); |
515 | buf = &data[offset + 1]; | 515 | GNUNET_free(data); |
516 | } | ||
517 | regfree (&rex); | ||
518 | GNUNET_free (data); | ||
519 | if (NULL == starting_host) | 516 | if (NULL == starting_host) |
520 | return 0; | 517 | return 0; |
521 | *hosts = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *) * count); | 518 | *hosts = GNUNET_malloc(sizeof(struct GNUNET_TESTBED_Host *) * count); |
522 | GNUNET_memcpy (*hosts, | 519 | GNUNET_memcpy(*hosts, |
523 | &host_list[GNUNET_TESTBED_host_get_id_ (starting_host)], | 520 | &host_list[GNUNET_TESTBED_host_get_id_(starting_host)], |
524 | sizeof (struct GNUNET_TESTBED_Host *) * count); | 521 | sizeof(struct GNUNET_TESTBED_Host *) * count); |
525 | return count; | 522 | return count; |
526 | } | 523 | } |
527 | 524 | ||
@@ -533,7 +530,7 @@ GNUNET_TESTBED_hosts_load_from_file ( | |||
533 | * @return the string representing the IPv4 address of the given host; NULL upon error | 530 | * @return the string representing the IPv4 address of the given host; NULL upon error |
534 | */ | 531 | */ |
535 | const char * | 532 | const char * |
536 | simple_resolve (const char *host) | 533 | simple_resolve(const char *host) |
537 | { | 534 | { |
538 | struct addrinfo *res; | 535 | struct addrinfo *res; |
539 | const struct sockaddr_in *in_addr; | 536 | const struct sockaddr_in *in_addr; |
@@ -550,20 +547,20 @@ simple_resolve (const char *host) | |||
550 | hint.ai_next = NULL; | 547 | hint.ai_next = NULL; |
551 | hint.ai_flags = AI_NUMERICSERV; | 548 | hint.ai_flags = AI_NUMERICSERV; |
552 | res = NULL; | 549 | res = NULL; |
553 | LOG_DEBUG ("Resolving [%s]\n", host); | 550 | LOG_DEBUG("Resolving [%s]\n", host); |
554 | if (0 != (rc = getaddrinfo (host, "22", &hint, &res))) | 551 | if (0 != (rc = getaddrinfo(host, "22", &hint, &res))) |
555 | { | 552 | { |
556 | LOG_GAI (GNUNET_ERROR_TYPE_ERROR, "getaddrinfo", rc); | 553 | LOG_GAI(GNUNET_ERROR_TYPE_ERROR, "getaddrinfo", rc); |
557 | return NULL; | 554 | return NULL; |
558 | } | 555 | } |
559 | GNUNET_assert (NULL != res); | 556 | GNUNET_assert(NULL != res); |
560 | GNUNET_assert (NULL != res->ai_addr); | 557 | GNUNET_assert(NULL != res->ai_addr); |
561 | GNUNET_assert (sizeof (struct sockaddr_in) == res->ai_addrlen); | 558 | GNUNET_assert(sizeof(struct sockaddr_in) == res->ai_addrlen); |
562 | in_addr = (const struct sockaddr_in *) res->ai_addr; | 559 | in_addr = (const struct sockaddr_in *)res->ai_addr; |
563 | hostip = inet_ntoa (in_addr->sin_addr); | 560 | hostip = inet_ntoa(in_addr->sin_addr); |
564 | GNUNET_assert (NULL != hostip); | 561 | GNUNET_assert(NULL != hostip); |
565 | freeaddrinfo (res); | 562 | freeaddrinfo(res); |
566 | LOG_DEBUG ("Resolved [%s] to [%s]\n", host, hostip); | 563 | LOG_DEBUG("Resolved [%s] to [%s]\n", host, hostip); |
567 | return hostip; | 564 | return hostip; |
568 | } | 565 | } |
569 | 566 | ||
@@ -581,24 +578,24 @@ simple_resolve (const char *host) | |||
581 | * @return number of hosts returned in 'hosts', 0 on error | 578 | * @return number of hosts returned in 'hosts', 0 on error |
582 | */ | 579 | */ |
583 | unsigned int | 580 | unsigned int |
584 | GNUNET_TESTBED_hosts_load_from_loadleveler ( | 581 | GNUNET_TESTBED_hosts_load_from_loadleveler( |
585 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 582 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
586 | struct GNUNET_TESTBED_Host ***hosts) | 583 | struct GNUNET_TESTBED_Host ***hosts) |
587 | { | 584 | { |
588 | #if ! ENABLE_SUPERMUC | 585 | #if !ENABLE_SUPERMUC |
589 | LOG (GNUNET_ERROR_TYPE_ERROR, | 586 | LOG(GNUNET_ERROR_TYPE_ERROR, |
590 | _ ("The function %s is only available when compiled with (--with-ll)\n"), | 587 | _("The function %s is only available when compiled with (--with-ll)\n"), |
591 | __func__); | 588 | __func__); |
592 | GNUNET_assert (0); | 589 | GNUNET_assert(0); |
593 | #else | 590 | #else |
594 | const char *hostfile; | 591 | const char *hostfile; |
595 | 592 | ||
596 | if (NULL == (hostfile = getenv ("MP_SAVEHOSTFILE"))) | 593 | if (NULL == (hostfile = getenv("MP_SAVEHOSTFILE"))) |
597 | { | 594 | { |
598 | GNUNET_break (0); | 595 | GNUNET_break(0); |
599 | return 0; | 596 | return 0; |
600 | } | 597 | } |
601 | return GNUNET_TESTBED_hosts_load_from_file (hostfile, cfg, hosts); | 598 | return GNUNET_TESTBED_hosts_load_from_file(hostfile, cfg, hosts); |
602 | #endif | 599 | #endif |
603 | } | 600 | } |
604 | 601 | ||
@@ -610,41 +607,41 @@ GNUNET_TESTBED_hosts_load_from_loadleveler ( | |||
610 | * @param host handle to destroy | 607 | * @param host handle to destroy |
611 | */ | 608 | */ |
612 | void | 609 | void |
613 | GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) | 610 | GNUNET_TESTBED_host_destroy(struct GNUNET_TESTBED_Host *host) |
614 | { | 611 | { |
615 | struct RegisteredController *rc; | 612 | struct RegisteredController *rc; |
616 | uint32_t id; | 613 | uint32_t id; |
617 | 614 | ||
618 | GNUNET_assert (host->id < host_list_size); | 615 | GNUNET_assert(host->id < host_list_size); |
619 | GNUNET_assert (host_list[host->id] == host); | 616 | GNUNET_assert(host_list[host->id] == host); |
620 | host_list[host->id] = NULL; | 617 | host_list[host->id] = NULL; |
621 | /* clear registered controllers list */ | 618 | /* clear registered controllers list */ |
622 | for (rc = host->rc_head; NULL != rc; rc = host->rc_head) | 619 | for (rc = host->rc_head; NULL != rc; rc = host->rc_head) |
623 | { | 620 | { |
624 | GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc); | 621 | GNUNET_CONTAINER_DLL_remove(host->rc_head, host->rc_tail, rc); |
625 | GNUNET_free (rc); | 622 | GNUNET_free(rc); |
626 | } | 623 | } |
627 | GNUNET_free_non_null ((char *) host->username); | 624 | GNUNET_free_non_null((char *)host->username); |
628 | GNUNET_free_non_null ((char *) host->hostname); | 625 | GNUNET_free_non_null((char *)host->hostname); |
629 | GNUNET_TESTBED_operation_queue_destroy_ ( | 626 | GNUNET_TESTBED_operation_queue_destroy_( |
630 | host->opq_parallel_overlay_connect_operations); | 627 | host->opq_parallel_overlay_connect_operations); |
631 | GNUNET_CONFIGURATION_destroy (host->cfg); | 628 | GNUNET_CONFIGURATION_destroy(host->cfg); |
632 | GNUNET_free (host); | 629 | GNUNET_free(host); |
633 | while (host_list_size >= HOST_LIST_GROW_STEP) | 630 | while (host_list_size >= HOST_LIST_GROW_STEP) |
634 | { | 631 | { |
635 | for (id = host_list_size - 1; id > host_list_size - HOST_LIST_GROW_STEP; | 632 | for (id = host_list_size - 1; id > host_list_size - HOST_LIST_GROW_STEP; |
636 | id--) | 633 | id--) |
634 | if (NULL != host_list[id]) | ||
635 | break; | ||
636 | if (id != host_list_size - HOST_LIST_GROW_STEP) | ||
637 | break; | ||
637 | if (NULL != host_list[id]) | 638 | if (NULL != host_list[id]) |
638 | break; | 639 | break; |
639 | if (id != host_list_size - HOST_LIST_GROW_STEP) | 640 | host_list_size -= HOST_LIST_GROW_STEP; |
640 | break; | 641 | } |
641 | if (NULL != host_list[id]) | ||
642 | break; | ||
643 | host_list_size -= HOST_LIST_GROW_STEP; | ||
644 | } | ||
645 | host_list = | 642 | host_list = |
646 | GNUNET_realloc (host_list, | 643 | GNUNET_realloc(host_list, |
647 | sizeof (struct GNUNET_TESTBED_Host *) * host_list_size); | 644 | sizeof(struct GNUNET_TESTBED_Host *) * host_list_size); |
648 | } | 645 | } |
649 | 646 | ||
650 | 647 | ||
@@ -655,23 +652,23 @@ GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) | |||
655 | * @param controller the controller at which this host is registered | 652 | * @param controller the controller at which this host is registered |
656 | */ | 653 | */ |
657 | void | 654 | void |
658 | GNUNET_TESTBED_mark_host_registered_at_ ( | 655 | GNUNET_TESTBED_mark_host_registered_at_( |
659 | struct GNUNET_TESTBED_Host *host, | 656 | struct GNUNET_TESTBED_Host *host, |
660 | const struct GNUNET_TESTBED_Controller *const controller) | 657 | const struct GNUNET_TESTBED_Controller *const controller) |
661 | { | 658 | { |
662 | struct RegisteredController *rc; | 659 | struct RegisteredController *rc; |
663 | 660 | ||
664 | for (rc = host->rc_head; NULL != rc; rc = rc->next) | 661 | for (rc = host->rc_head; NULL != rc; rc = rc->next) |
665 | { | ||
666 | if (controller == rc->controller) /* already registered at controller */ | ||
667 | { | 662 | { |
668 | GNUNET_break (0); | 663 | if (controller == rc->controller) /* already registered at controller */ |
669 | return; | 664 | { |
665 | GNUNET_break(0); | ||
666 | return; | ||
667 | } | ||
670 | } | 668 | } |
671 | } | 669 | rc = GNUNET_new(struct RegisteredController); |
672 | rc = GNUNET_new (struct RegisteredController); | ||
673 | rc->controller = controller; | 670 | rc->controller = controller; |
674 | GNUNET_CONTAINER_DLL_insert_tail (host->rc_head, host->rc_tail, rc); | 671 | GNUNET_CONTAINER_DLL_insert_tail(host->rc_head, host->rc_tail, rc); |
675 | } | 672 | } |
676 | 673 | ||
677 | 674 | ||
@@ -682,7 +679,7 @@ GNUNET_TESTBED_mark_host_registered_at_ ( | |||
682 | * @param controller the controller at which this host has to be unmarked | 679 | * @param controller the controller at which this host has to be unmarked |
683 | */ | 680 | */ |
684 | void | 681 | void |
685 | GNUNET_TESTBED_deregister_host_at_ ( | 682 | GNUNET_TESTBED_deregister_host_at_( |
686 | struct GNUNET_TESTBED_Host *host, | 683 | struct GNUNET_TESTBED_Host *host, |
687 | const struct GNUNET_TESTBED_Controller *const controller) | 684 | const struct GNUNET_TESTBED_Controller *const controller) |
688 | { | 685 | { |
@@ -692,12 +689,12 @@ GNUNET_TESTBED_deregister_host_at_ ( | |||
692 | if (controller == rc->controller) | 689 | if (controller == rc->controller) |
693 | break; | 690 | break; |
694 | if (NULL == rc) | 691 | if (NULL == rc) |
695 | { | 692 | { |
696 | GNUNET_break (0); | 693 | GNUNET_break(0); |
697 | return; | 694 | return; |
698 | } | 695 | } |
699 | GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc); | 696 | GNUNET_CONTAINER_DLL_remove(host->rc_head, host->rc_tail, rc); |
700 | GNUNET_free (rc); | 697 | GNUNET_free(rc); |
701 | } | 698 | } |
702 | 699 | ||
703 | 700 | ||
@@ -709,19 +706,19 @@ GNUNET_TESTBED_deregister_host_at_ ( | |||
709 | * @return GNUNET_YES if registered; GNUNET_NO if not | 706 | * @return GNUNET_YES if registered; GNUNET_NO if not |
710 | */ | 707 | */ |
711 | int | 708 | int |
712 | GNUNET_TESTBED_is_host_registered_ ( | 709 | GNUNET_TESTBED_is_host_registered_( |
713 | const struct GNUNET_TESTBED_Host *host, | 710 | const struct GNUNET_TESTBED_Host *host, |
714 | const struct GNUNET_TESTBED_Controller *const controller) | 711 | const struct GNUNET_TESTBED_Controller *const controller) |
715 | { | 712 | { |
716 | struct RegisteredController *rc; | 713 | struct RegisteredController *rc; |
717 | 714 | ||
718 | for (rc = host->rc_head; NULL != rc; rc = rc->next) | 715 | for (rc = host->rc_head; NULL != rc; rc = rc->next) |
719 | { | ||
720 | if (controller == rc->controller) /* already registered at controller */ | ||
721 | { | 716 | { |
722 | return GNUNET_YES; | 717 | if (controller == rc->controller) /* already registered at controller */ |
718 | { | ||
719 | return GNUNET_YES; | ||
720 | } | ||
723 | } | 721 | } |
724 | } | ||
725 | return GNUNET_NO; | 722 | return GNUNET_NO; |
726 | } | 723 | } |
727 | 724 | ||
@@ -729,8 +726,7 @@ GNUNET_TESTBED_is_host_registered_ ( | |||
729 | /** | 726 | /** |
730 | * Handle for controller process | 727 | * Handle for controller process |
731 | */ | 728 | */ |
732 | struct GNUNET_TESTBED_ControllerProc | 729 | struct GNUNET_TESTBED_ControllerProc { |
733 | { | ||
734 | /** | 730 | /** |
735 | * The process handle | 731 | * The process handle |
736 | */ | 732 | */ |
@@ -775,17 +771,17 @@ struct GNUNET_TESTBED_ControllerProc | |||
775 | * @return the copied NULL terminated arguments | 771 | * @return the copied NULL terminated arguments |
776 | */ | 772 | */ |
777 | static char ** | 773 | static char ** |
778 | copy_argv (const char *const *argv) | 774 | copy_argv(const char *const *argv) |
779 | { | 775 | { |
780 | char **argv_dup; | 776 | char **argv_dup; |
781 | unsigned int argp; | 777 | unsigned int argp; |
782 | 778 | ||
783 | GNUNET_assert (NULL != argv); | 779 | GNUNET_assert(NULL != argv); |
784 | for (argp = 0; NULL != argv[argp]; argp++) | 780 | for (argp = 0; NULL != argv[argp]; argp++) |
785 | ; | 781 | ; |
786 | argv_dup = GNUNET_malloc (sizeof (char *) * (argp + 1)); | 782 | argv_dup = GNUNET_malloc(sizeof(char *) * (argp + 1)); |
787 | for (argp = 0; NULL != argv[argp]; argp++) | 783 | for (argp = 0; NULL != argv[argp]; argp++) |
788 | argv_dup[argp] = GNUNET_strdup (argv[argp]); | 784 | argv_dup[argp] = GNUNET_strdup(argv[argp]); |
789 | return argv_dup; | 785 | return argv_dup; |
790 | } | 786 | } |
791 | 787 | ||
@@ -798,7 +794,7 @@ copy_argv (const char *const *argv) | |||
798 | * @return the joined NULL terminated arguments | 794 | * @return the joined NULL terminated arguments |
799 | */ | 795 | */ |
800 | static char ** | 796 | static char ** |
801 | join_argv (const char *const *argv1, const char *const *argv2) | 797 | join_argv(const char *const *argv1, const char *const *argv2) |
802 | { | 798 | { |
803 | char **argvj; | 799 | char **argvj; |
804 | char *argv; | 800 | char *argv; |
@@ -808,16 +804,16 @@ join_argv (const char *const *argv1, const char *const *argv2) | |||
808 | carg = 0; | 804 | carg = 0; |
809 | argvj = NULL; | 805 | argvj = NULL; |
810 | for (cnt = 0; NULL != argv1[cnt]; cnt++) | 806 | for (cnt = 0; NULL != argv1[cnt]; cnt++) |
811 | { | 807 | { |
812 | argv = GNUNET_strdup (argv1[cnt]); | 808 | argv = GNUNET_strdup(argv1[cnt]); |
813 | GNUNET_array_append (argvj, carg, argv); | 809 | GNUNET_array_append(argvj, carg, argv); |
814 | } | 810 | } |
815 | for (cnt = 0; NULL != argv2[cnt]; cnt++) | 811 | for (cnt = 0; NULL != argv2[cnt]; cnt++) |
816 | { | 812 | { |
817 | argv = GNUNET_strdup (argv2[cnt]); | 813 | argv = GNUNET_strdup(argv2[cnt]); |
818 | GNUNET_array_append (argvj, carg, argv); | 814 | GNUNET_array_append(argvj, carg, argv); |
819 | } | 815 | } |
820 | GNUNET_array_append (argvj, carg, NULL); | 816 | GNUNET_array_append(argvj, carg, NULL); |
821 | return argvj; | 817 | return argvj; |
822 | } | 818 | } |
823 | 819 | ||
@@ -828,13 +824,13 @@ join_argv (const char *const *argv1, const char *const *argv2) | |||
828 | * @param argv the NULL terminated list of arguments | 824 | * @param argv the NULL terminated list of arguments |
829 | */ | 825 | */ |
830 | static void | 826 | static void |
831 | free_argv (char **argv) | 827 | free_argv(char **argv) |
832 | { | 828 | { |
833 | unsigned int argp; | 829 | unsigned int argp; |
834 | 830 | ||
835 | for (argp = 0; NULL != argv[argp]; argp++) | 831 | for (argp = 0; NULL != argv[argp]; argp++) |
836 | GNUNET_free (argv[argp]); | 832 | GNUNET_free(argv[argp]); |
837 | GNUNET_free (argv); | 833 | GNUNET_free(argv); |
838 | } | 834 | } |
839 | 835 | ||
840 | 836 | ||
@@ -853,20 +849,20 @@ free_argv (char **argv) | |||
853 | * @return NULL terminated list of arguments | 849 | * @return NULL terminated list of arguments |
854 | */ | 850 | */ |
855 | static char ** | 851 | static char ** |
856 | gen_rsh_args (const char *port, const char *hostname, const char *username) | 852 | gen_rsh_args(const char *port, const char *hostname, const char *username) |
857 | { | 853 | { |
858 | static const char *default_ssh_args[] = | 854 | static const char *default_ssh_args[] = |
859 | {"ssh", | 855 | { "ssh", |
860 | "-o", | 856 | "-o", |
861 | "BatchMode=yes", | 857 | "BatchMode=yes", |
862 | "-o", | 858 | "-o", |
863 | "NoHostAuthenticationForLocalhost=yes", | 859 | "NoHostAuthenticationForLocalhost=yes", |
864 | "-o", | 860 | "-o", |
865 | "StrictHostKeyChecking=no", | 861 | "StrictHostKeyChecking=no", |
866 | "-o", | 862 | "-o", |
867 | "PasswordAuthentication=no", | 863 | "PasswordAuthentication=no", |
868 | "%h", | 864 | "%h", |
869 | NULL}; | 865 | NULL }; |
870 | char **ssh_args; | 866 | char **ssh_args; |
871 | char *ssh_cmd; | 867 | char *ssh_cmd; |
872 | char *ssh_cmd_cp; | 868 | char *ssh_cmd_cp; |
@@ -876,48 +872,48 @@ gen_rsh_args (const char *port, const char *hostname, const char *username) | |||
876 | unsigned int cnt; | 872 | unsigned int cnt; |
877 | 873 | ||
878 | ssh_args = NULL; | 874 | ssh_args = NULL; |
879 | if (NULL != (ssh_cmd = getenv ("GNUNET_TESTBED_RSH_CMD"))) | 875 | if (NULL != (ssh_cmd = getenv("GNUNET_TESTBED_RSH_CMD"))) |
880 | { | 876 | { |
881 | ssh_cmd = GNUNET_strdup (ssh_cmd); | 877 | ssh_cmd = GNUNET_strdup(ssh_cmd); |
882 | ssh_cmd_cp = ssh_cmd; | 878 | ssh_cmd_cp = ssh_cmd; |
883 | for (size = 0; NULL != (arg = strtok (ssh_cmd, " ")); ssh_cmd = NULL) | 879 | for (size = 0; NULL != (arg = strtok(ssh_cmd, " ")); ssh_cmd = NULL) |
884 | GNUNET_array_append (ssh_args, size, GNUNET_strdup (arg)); | 880 | GNUNET_array_append(ssh_args, size, GNUNET_strdup(arg)); |
885 | GNUNET_free (ssh_cmd_cp); | 881 | GNUNET_free(ssh_cmd_cp); |
886 | } | 882 | } |
887 | else | 883 | else |
888 | { | 884 | { |
889 | ssh_args = copy_argv (default_ssh_args); | 885 | ssh_args = copy_argv(default_ssh_args); |
890 | size = (sizeof (default_ssh_args)) / (sizeof (const char *)); | 886 | size = (sizeof(default_ssh_args)) / (sizeof(const char *)); |
891 | GNUNET_array_grow (ssh_args, size, size - 1); | 887 | GNUNET_array_grow(ssh_args, size, size - 1); |
892 | } | 888 | } |
893 | for (cnt = 0; cnt < size; cnt++) | 889 | for (cnt = 0; cnt < size; cnt++) |
894 | { | ||
895 | arg = ssh_args[cnt]; | ||
896 | if ('%' != arg[0]) | ||
897 | continue; | ||
898 | switch (arg[1]) | ||
899 | { | 890 | { |
900 | case 'p': | 891 | arg = ssh_args[cnt]; |
901 | new_arg = port; | 892 | if ('%' != arg[0]) |
902 | break; | 893 | continue; |
903 | 894 | switch (arg[1]) | |
904 | case 'u': | 895 | { |
905 | new_arg = username; | 896 | case 'p': |
906 | break; | 897 | new_arg = port; |
907 | 898 | break; | |
908 | case 'h': | 899 | |
909 | new_arg = hostname; | 900 | case 'u': |
910 | break; | 901 | new_arg = username; |
911 | 902 | break; | |
912 | default: | 903 | |
913 | continue; | 904 | case 'h': |
905 | new_arg = hostname; | ||
906 | break; | ||
907 | |||
908 | default: | ||
909 | continue; | ||
910 | } | ||
911 | if (NULL == new_arg) | ||
912 | continue; | ||
913 | GNUNET_free(arg); | ||
914 | ssh_args[cnt] = GNUNET_strdup(new_arg); | ||
914 | } | 915 | } |
915 | if (NULL == new_arg) | 916 | GNUNET_array_append(ssh_args, size, NULL); |
916 | continue; | ||
917 | GNUNET_free (arg); | ||
918 | ssh_args[cnt] = GNUNET_strdup (new_arg); | ||
919 | } | ||
920 | GNUNET_array_append (ssh_args, size, NULL); | ||
921 | return ssh_args; | 917 | return ssh_args; |
922 | } | 918 | } |
923 | 919 | ||
@@ -933,7 +929,7 @@ gen_rsh_args (const char *port, const char *hostname, const char *username) | |||
933 | * @return NULL-terminated args | 929 | * @return NULL-terminated args |
934 | */ | 930 | */ |
935 | static char ** | 931 | static char ** |
936 | gen_rsh_suffix_args (const char *const *append_args) | 932 | gen_rsh_suffix_args(const char *const *append_args) |
937 | { | 933 | { |
938 | char **rshell_args; | 934 | char **rshell_args; |
939 | char *rshell_cmd; | 935 | char *rshell_cmd; |
@@ -944,22 +940,22 @@ gen_rsh_suffix_args (const char *const *append_args) | |||
944 | 940 | ||
945 | rshell_args = NULL; | 941 | rshell_args = NULL; |
946 | cnt = 0; | 942 | cnt = 0; |
947 | if (NULL != (rshell_cmd = getenv ("GNUNET_TESTBED_RSH_CMD_SUFFIX"))) | 943 | if (NULL != (rshell_cmd = getenv("GNUNET_TESTBED_RSH_CMD_SUFFIX"))) |
948 | { | 944 | { |
949 | rshell_cmd = GNUNET_strdup (rshell_cmd); | 945 | rshell_cmd = GNUNET_strdup(rshell_cmd); |
950 | rshell_cmd_cp = rshell_cmd; | 946 | rshell_cmd_cp = rshell_cmd; |
951 | for (; NULL != (arg = strtok (rshell_cmd, " ")); rshell_cmd = NULL) | 947 | for (; NULL != (arg = strtok(rshell_cmd, " ")); rshell_cmd = NULL) |
952 | GNUNET_array_append (rshell_args, cnt, GNUNET_strdup (arg)); | 948 | GNUNET_array_append(rshell_args, cnt, GNUNET_strdup(arg)); |
953 | GNUNET_free (rshell_cmd_cp); | 949 | GNUNET_free(rshell_cmd_cp); |
954 | } | 950 | } |
955 | if (NULL != append_args) | 951 | if (NULL != append_args) |
956 | { | 952 | { |
957 | for (append_cnt = 0; NULL != append_args[append_cnt]; append_cnt++) | 953 | for (append_cnt = 0; NULL != append_args[append_cnt]; append_cnt++) |
958 | GNUNET_array_append (rshell_args, | 954 | GNUNET_array_append(rshell_args, |
959 | cnt, | 955 | cnt, |
960 | GNUNET_strdup (append_args[append_cnt])); | 956 | GNUNET_strdup(append_args[append_cnt])); |
961 | } | 957 | } |
962 | GNUNET_array_append (rshell_args, cnt, NULL); | 958 | GNUNET_array_append(rshell_args, cnt, NULL); |
963 | return rshell_args; | 959 | return rshell_args; |
964 | } | 960 | } |
965 | 961 | ||
@@ -977,7 +973,7 @@ gen_rsh_suffix_args (const char *const *append_args) | |||
977 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing | 973 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing |
978 | */ | 974 | */ |
979 | static int | 975 | static int |
980 | helper_mst (void *cls, const struct GNUNET_MessageHeader *message) | 976 | helper_mst(void *cls, const struct GNUNET_MessageHeader *message) |
981 | { | 977 | { |
982 | struct GNUNET_TESTBED_ControllerProc *cp = cls; | 978 | struct GNUNET_TESTBED_ControllerProc *cp = cls; |
983 | const struct GNUNET_TESTBED_HelperReply *msg; | 979 | const struct GNUNET_TESTBED_HelperReply *msg; |
@@ -986,38 +982,38 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) | |||
986 | uLongf config_size; | 982 | uLongf config_size; |
987 | uLongf xconfig_size; | 983 | uLongf xconfig_size; |
988 | 984 | ||
989 | msg = (const struct GNUNET_TESTBED_HelperReply *) message; | 985 | msg = (const struct GNUNET_TESTBED_HelperReply *)message; |
990 | GNUNET_assert (sizeof (struct GNUNET_TESTBED_HelperReply) < | 986 | GNUNET_assert(sizeof(struct GNUNET_TESTBED_HelperReply) < |
991 | ntohs (msg->header.size)); | 987 | ntohs(msg->header.size)); |
992 | GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY == | 988 | GNUNET_assert(GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY == |
993 | ntohs (msg->header.type)); | 989 | ntohs(msg->header.type)); |
994 | config_size = (uLongf) ntohs (msg->config_size); | 990 | config_size = (uLongf)ntohs(msg->config_size); |
995 | xconfig_size = (uLongf) (ntohs (msg->header.size) - | 991 | xconfig_size = (uLongf)(ntohs(msg->header.size) - |
996 | sizeof (struct GNUNET_TESTBED_HelperReply)); | 992 | sizeof(struct GNUNET_TESTBED_HelperReply)); |
997 | config = GNUNET_malloc (config_size); | 993 | config = GNUNET_malloc(config_size); |
998 | GNUNET_assert (Z_OK == uncompress ((Bytef *) config, | 994 | GNUNET_assert(Z_OK == uncompress((Bytef *)config, |
999 | &config_size, | 995 | &config_size, |
1000 | (const Bytef *) &msg[1], | 996 | (const Bytef *)&msg[1], |
1001 | xconfig_size)); | 997 | xconfig_size)); |
1002 | /* Replace the configuration template present in the host with the | 998 | /* Replace the configuration template present in the host with the |
1003 | controller's running configuration */ | 999 | controller's running configuration */ |
1004 | GNUNET_CONFIGURATION_destroy (cp->host->cfg); | 1000 | GNUNET_CONFIGURATION_destroy(cp->host->cfg); |
1005 | cp->host->cfg = GNUNET_CONFIGURATION_create (); | 1001 | cp->host->cfg = GNUNET_CONFIGURATION_create(); |
1006 | GNUNET_assert (GNUNET_CONFIGURATION_deserialize (cp->host->cfg, | 1002 | GNUNET_assert(GNUNET_CONFIGURATION_deserialize(cp->host->cfg, |
1007 | config, | 1003 | config, |
1008 | config_size, | 1004 | config_size, |
1009 | NULL)); | 1005 | NULL)); |
1010 | GNUNET_free (config); | 1006 | GNUNET_free(config); |
1011 | if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host))) | 1007 | if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname(cp->host))) |
1012 | hostname = "localhost"; | 1008 | hostname = "localhost"; |
1013 | /* Change the hostname so that we can connect to it */ | 1009 | /* Change the hostname so that we can connect to it */ |
1014 | GNUNET_CONFIGURATION_set_value_string (cp->host->cfg, | 1010 | GNUNET_CONFIGURATION_set_value_string(cp->host->cfg, |
1015 | "testbed", | 1011 | "testbed", |
1016 | "hostname", | 1012 | "hostname", |
1017 | hostname); | 1013 | hostname); |
1018 | cp->host->locked = GNUNET_NO; | 1014 | cp->host->locked = GNUNET_NO; |
1019 | cp->host->controller_started = GNUNET_YES; | 1015 | cp->host->controller_started = GNUNET_YES; |
1020 | cp->cb (cp->cls, cp->host->cfg, GNUNET_OK); | 1016 | cp->cb(cp->cls, cp->host->cfg, GNUNET_OK); |
1021 | return GNUNET_OK; | 1017 | return GNUNET_OK; |
1022 | } | 1018 | } |
1023 | 1019 | ||
@@ -1031,13 +1027,13 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) | |||
1031 | * GNUNET_SYSERR during GNUNET_HELPER_stop | 1027 | * GNUNET_SYSERR during GNUNET_HELPER_stop |
1032 | */ | 1028 | */ |
1033 | static void | 1029 | static void |
1034 | clear_msg (void *cls, int result) | 1030 | clear_msg(void *cls, int result) |
1035 | { | 1031 | { |
1036 | struct GNUNET_TESTBED_ControllerProc *cp = cls; | 1032 | struct GNUNET_TESTBED_ControllerProc *cp = cls; |
1037 | 1033 | ||
1038 | GNUNET_assert (NULL != cp->shandle); | 1034 | GNUNET_assert(NULL != cp->shandle); |
1039 | cp->shandle = NULL; | 1035 | cp->shandle = NULL; |
1040 | GNUNET_free (cp->msg); | 1036 | GNUNET_free(cp->msg); |
1041 | cp->msg = NULL; | 1037 | cp->msg = NULL; |
1042 | } | 1038 | } |
1043 | 1039 | ||
@@ -1049,7 +1045,7 @@ clear_msg (void *cls, int result) | |||
1049 | * @param cls the closure from GNUNET_HELPER_start() | 1045 | * @param cls the closure from GNUNET_HELPER_start() |
1050 | */ | 1046 | */ |
1051 | static void | 1047 | static void |
1052 | helper_exp_cb (void *cls) | 1048 | helper_exp_cb(void *cls) |
1053 | { | 1049 | { |
1054 | struct GNUNET_TESTBED_ControllerProc *cp = cls; | 1050 | struct GNUNET_TESTBED_ControllerProc *cp = cls; |
1055 | GNUNET_TESTBED_ControllerStatusCallback cb; | 1051 | GNUNET_TESTBED_ControllerStatusCallback cb; |
@@ -1058,9 +1054,9 @@ helper_exp_cb (void *cls) | |||
1058 | cb = cp->cb; | 1054 | cb = cp->cb; |
1059 | cb_cls = cp->cls; | 1055 | cb_cls = cp->cls; |
1060 | cp->helper = NULL; | 1056 | cp->helper = NULL; |
1061 | GNUNET_TESTBED_controller_stop (cp); | 1057 | GNUNET_TESTBED_controller_stop(cp); |
1062 | if (NULL != cb) | 1058 | if (NULL != cb) |
1063 | cb (cb_cls, NULL, GNUNET_SYSERR); | 1059 | cb(cb_cls, NULL, GNUNET_SYSERR); |
1064 | } | 1060 | } |
1065 | 1061 | ||
1066 | 1062 | ||
@@ -1088,106 +1084,106 @@ helper_exp_cb (void *cls) | |||
1088 | * @return the controller process handle, NULL on errors | 1084 | * @return the controller process handle, NULL on errors |
1089 | */ | 1085 | */ |
1090 | struct GNUNET_TESTBED_ControllerProc * | 1086 | struct GNUNET_TESTBED_ControllerProc * |
1091 | GNUNET_TESTBED_controller_start (const char *trusted_ip, | 1087 | GNUNET_TESTBED_controller_start(const char *trusted_ip, |
1092 | struct GNUNET_TESTBED_Host *host, | 1088 | struct GNUNET_TESTBED_Host *host, |
1093 | GNUNET_TESTBED_ControllerStatusCallback cb, | 1089 | GNUNET_TESTBED_ControllerStatusCallback cb, |
1094 | void *cls) | 1090 | void *cls) |
1095 | { | 1091 | { |
1096 | struct GNUNET_TESTBED_ControllerProc *cp; | 1092 | struct GNUNET_TESTBED_ControllerProc *cp; |
1097 | struct GNUNET_TESTBED_HelperInit *msg; | 1093 | struct GNUNET_TESTBED_HelperInit *msg; |
1098 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 1094 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
1099 | const char *hostname; | 1095 | const char *hostname; |
1100 | static char *const binary_argv[] = {HELPER_TESTBED_BINARY, NULL}; | 1096 | static char *const binary_argv[] = { HELPER_TESTBED_BINARY, NULL }; |
1101 | 1097 | ||
1102 | GNUNET_assert (NULL != host); | 1098 | GNUNET_assert(NULL != host); |
1103 | GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host))); | 1099 | GNUNET_assert(NULL != (cfg = GNUNET_TESTBED_host_get_cfg_(host))); |
1104 | hostname = NULL; | 1100 | hostname = NULL; |
1105 | API_VIOLATION ( | 1101 | API_VIOLATION( |
1106 | GNUNET_NO == host->locked, | 1102 | GNUNET_NO == host->locked, |
1107 | "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()"); | 1103 | "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()"); |
1108 | host->locked = GNUNET_YES; | 1104 | host->locked = GNUNET_YES; |
1109 | API_VIOLATION ( | 1105 | API_VIOLATION( |
1110 | GNUNET_NO == host->controller_started, | 1106 | GNUNET_NO == host->controller_started, |
1111 | "Attempting to start a controller on a host which is already started a controller"); | 1107 | "Attempting to start a controller on a host which is already started a controller"); |
1112 | cp = GNUNET_new (struct GNUNET_TESTBED_ControllerProc); | 1108 | cp = GNUNET_new(struct GNUNET_TESTBED_ControllerProc); |
1113 | if (0 == GNUNET_TESTBED_host_get_id_ (host)) | 1109 | if (0 == GNUNET_TESTBED_host_get_id_(host)) |
1114 | { | 1110 | { |
1115 | cp->helper = GNUNET_HELPER_start (GNUNET_YES, | 1111 | cp->helper = GNUNET_HELPER_start(GNUNET_YES, |
1116 | HELPER_TESTBED_BINARY, | 1112 | HELPER_TESTBED_BINARY, |
1117 | binary_argv, | 1113 | binary_argv, |
1118 | &helper_mst, | 1114 | &helper_mst, |
1119 | &helper_exp_cb, | 1115 | &helper_exp_cb, |
1120 | cp); | 1116 | cp); |
1121 | } | 1117 | } |
1122 | else | 1118 | else |
1123 | { | ||
1124 | char *helper_binary_path_args[2]; | ||
1125 | char **rsh_args; | ||
1126 | char **rsh_suffix_args; | ||
1127 | const char *username; | ||
1128 | char *port; | ||
1129 | char *argstr; | ||
1130 | char *aux; | ||
1131 | unsigned int cnt; | ||
1132 | |||
1133 | username = host->username; | ||
1134 | hostname = host->hostname; | ||
1135 | GNUNET_asprintf (&port, "%u", host->port); | ||
1136 | LOG_DEBUG ("Starting remote connection to destination %s\n", hostname); | ||
1137 | if (GNUNET_OK != | ||
1138 | GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
1139 | "testbed", | ||
1140 | "HELPER_BINARY_PATH", | ||
1141 | &helper_binary_path_args[0])) | ||
1142 | helper_binary_path_args[0] = | ||
1143 | GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY); | ||
1144 | helper_binary_path_args[1] = NULL; | ||
1145 | rsh_args = gen_rsh_args (port, hostname, username); | ||
1146 | rsh_suffix_args = | ||
1147 | gen_rsh_suffix_args ((const char **) helper_binary_path_args); | ||
1148 | cp->helper_argv = | ||
1149 | join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args); | ||
1150 | free_argv (rsh_args); | ||
1151 | free_argv (rsh_suffix_args); | ||
1152 | GNUNET_free (port); | ||
1153 | argstr = GNUNET_strdup (""); | ||
1154 | for (cnt = 0; NULL != cp->helper_argv[cnt]; cnt++) | ||
1155 | { | 1119 | { |
1156 | aux = argstr; | 1120 | char *helper_binary_path_args[2]; |
1157 | GNUNET_assert ( | 1121 | char **rsh_args; |
1158 | 0 < GNUNET_asprintf (&argstr, "%s %s", aux, cp->helper_argv[cnt])); | 1122 | char **rsh_suffix_args; |
1159 | GNUNET_free (aux); | 1123 | const char *username; |
1124 | char *port; | ||
1125 | char *argstr; | ||
1126 | char *aux; | ||
1127 | unsigned int cnt; | ||
1128 | |||
1129 | username = host->username; | ||
1130 | hostname = host->hostname; | ||
1131 | GNUNET_asprintf(&port, "%u", host->port); | ||
1132 | LOG_DEBUG("Starting remote connection to destination %s\n", hostname); | ||
1133 | if (GNUNET_OK != | ||
1134 | GNUNET_CONFIGURATION_get_value_filename(cfg, | ||
1135 | "testbed", | ||
1136 | "HELPER_BINARY_PATH", | ||
1137 | &helper_binary_path_args[0])) | ||
1138 | helper_binary_path_args[0] = | ||
1139 | GNUNET_OS_get_libexec_binary_path(HELPER_TESTBED_BINARY); | ||
1140 | helper_binary_path_args[1] = NULL; | ||
1141 | rsh_args = gen_rsh_args(port, hostname, username); | ||
1142 | rsh_suffix_args = | ||
1143 | gen_rsh_suffix_args((const char **)helper_binary_path_args); | ||
1144 | cp->helper_argv = | ||
1145 | join_argv((const char **)rsh_args, (const char **)rsh_suffix_args); | ||
1146 | free_argv(rsh_args); | ||
1147 | free_argv(rsh_suffix_args); | ||
1148 | GNUNET_free(port); | ||
1149 | argstr = GNUNET_strdup(""); | ||
1150 | for (cnt = 0; NULL != cp->helper_argv[cnt]; cnt++) | ||
1151 | { | ||
1152 | aux = argstr; | ||
1153 | GNUNET_assert( | ||
1154 | 0 < GNUNET_asprintf(&argstr, "%s %s", aux, cp->helper_argv[cnt])); | ||
1155 | GNUNET_free(aux); | ||
1156 | } | ||
1157 | LOG_DEBUG("Helper cmd str: %s\n", argstr); | ||
1158 | GNUNET_free(argstr); | ||
1159 | cp->helper = GNUNET_HELPER_start(GNUNET_NO, | ||
1160 | cp->helper_argv[0], | ||
1161 | cp->helper_argv, | ||
1162 | &helper_mst, | ||
1163 | &helper_exp_cb, | ||
1164 | cp); | ||
1165 | GNUNET_free(helper_binary_path_args[0]); | ||
1160 | } | 1166 | } |
1161 | LOG_DEBUG ("Helper cmd str: %s\n", argstr); | ||
1162 | GNUNET_free (argstr); | ||
1163 | cp->helper = GNUNET_HELPER_start (GNUNET_NO, | ||
1164 | cp->helper_argv[0], | ||
1165 | cp->helper_argv, | ||
1166 | &helper_mst, | ||
1167 | &helper_exp_cb, | ||
1168 | cp); | ||
1169 | GNUNET_free (helper_binary_path_args[0]); | ||
1170 | } | ||
1171 | if (NULL == cp->helper) | 1167 | if (NULL == cp->helper) |
1172 | { | 1168 | { |
1173 | if (NULL != cp->helper_argv) | 1169 | if (NULL != cp->helper_argv) |
1174 | free_argv (cp->helper_argv); | 1170 | free_argv(cp->helper_argv); |
1175 | GNUNET_free (cp); | 1171 | GNUNET_free(cp); |
1176 | return NULL; | 1172 | return NULL; |
1177 | } | 1173 | } |
1178 | cp->host = host; | 1174 | cp->host = host; |
1179 | cp->cb = cb; | 1175 | cp->cb = cb; |
1180 | cp->cls = cls; | 1176 | cp->cls = cls; |
1181 | msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, hostname, cfg); | 1177 | msg = GNUNET_TESTBED_create_helper_init_msg_(trusted_ip, hostname, cfg); |
1182 | cp->msg = &msg->header; | 1178 | cp->msg = &msg->header; |
1183 | cp->shandle = | 1179 | cp->shandle = |
1184 | GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp); | 1180 | GNUNET_HELPER_send(cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp); |
1185 | if (NULL == cp->shandle) | 1181 | if (NULL == cp->shandle) |
1186 | { | 1182 | { |
1187 | GNUNET_free (msg); | 1183 | GNUNET_free(msg); |
1188 | GNUNET_TESTBED_controller_stop (cp); | 1184 | GNUNET_TESTBED_controller_stop(cp); |
1189 | return NULL; | 1185 | return NULL; |
1190 | } | 1186 | } |
1191 | return cp; | 1187 | return cp; |
1192 | } | 1188 | } |
1193 | 1189 | ||
@@ -1198,12 +1194,12 @@ GNUNET_TESTBED_controller_start (const char *trusted_ip, | |||
1198 | * @param cproc the handle to the controller's helper process | 1194 | * @param cproc the handle to the controller's helper process |
1199 | */ | 1195 | */ |
1200 | void | 1196 | void |
1201 | GNUNET_TESTBED_controller_kill_ (struct GNUNET_TESTBED_ControllerProc *cproc) | 1197 | GNUNET_TESTBED_controller_kill_(struct GNUNET_TESTBED_ControllerProc *cproc) |
1202 | { | 1198 | { |
1203 | if (NULL != cproc->shandle) | 1199 | if (NULL != cproc->shandle) |
1204 | GNUNET_HELPER_send_cancel (cproc->shandle); | 1200 | GNUNET_HELPER_send_cancel(cproc->shandle); |
1205 | if (NULL != cproc->helper) | 1201 | if (NULL != cproc->helper) |
1206 | GNUNET_HELPER_kill (cproc->helper, GNUNET_YES); | 1202 | GNUNET_HELPER_kill(cproc->helper, GNUNET_YES); |
1207 | } | 1203 | } |
1208 | 1204 | ||
1209 | 1205 | ||
@@ -1213,19 +1209,19 @@ GNUNET_TESTBED_controller_kill_ (struct GNUNET_TESTBED_ControllerProc *cproc) | |||
1213 | * @param cproc the handle to the controller's helper process | 1209 | * @param cproc the handle to the controller's helper process |
1214 | */ | 1210 | */ |
1215 | void | 1211 | void |
1216 | GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc *cproc) | 1212 | GNUNET_TESTBED_controller_destroy_(struct GNUNET_TESTBED_ControllerProc *cproc) |
1217 | { | 1213 | { |
1218 | if (NULL != cproc->helper) | 1214 | if (NULL != cproc->helper) |
1219 | { | 1215 | { |
1220 | GNUNET_break (GNUNET_OK == GNUNET_HELPER_wait (cproc->helper)); | 1216 | GNUNET_break(GNUNET_OK == GNUNET_HELPER_wait(cproc->helper)); |
1221 | GNUNET_HELPER_destroy (cproc->helper); | 1217 | GNUNET_HELPER_destroy(cproc->helper); |
1222 | } | 1218 | } |
1223 | if (NULL != cproc->helper_argv) | 1219 | if (NULL != cproc->helper_argv) |
1224 | free_argv (cproc->helper_argv); | 1220 | free_argv(cproc->helper_argv); |
1225 | cproc->host->controller_started = GNUNET_NO; | 1221 | cproc->host->controller_started = GNUNET_NO; |
1226 | cproc->host->locked = GNUNET_NO; | 1222 | cproc->host->locked = GNUNET_NO; |
1227 | GNUNET_free_non_null (cproc->msg); | 1223 | GNUNET_free_non_null(cproc->msg); |
1228 | GNUNET_free (cproc); | 1224 | GNUNET_free(cproc); |
1229 | } | 1225 | } |
1230 | 1226 | ||
1231 | 1227 | ||
@@ -1238,18 +1234,17 @@ GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc *cproc) | |||
1238 | * @param cproc the controller process handle | 1234 | * @param cproc the controller process handle |
1239 | */ | 1235 | */ |
1240 | void | 1236 | void |
1241 | GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc) | 1237 | GNUNET_TESTBED_controller_stop(struct GNUNET_TESTBED_ControllerProc *cproc) |
1242 | { | 1238 | { |
1243 | GNUNET_TESTBED_controller_kill_ (cproc); | 1239 | GNUNET_TESTBED_controller_kill_(cproc); |
1244 | GNUNET_TESTBED_controller_destroy_ (cproc); | 1240 | GNUNET_TESTBED_controller_destroy_(cproc); |
1245 | } | 1241 | } |
1246 | 1242 | ||
1247 | 1243 | ||
1248 | /** | 1244 | /** |
1249 | * The handle for whether a host is habitable or not | 1245 | * The handle for whether a host is habitable or not |
1250 | */ | 1246 | */ |
1251 | struct GNUNET_TESTBED_HostHabitableCheckHandle | 1247 | struct GNUNET_TESTBED_HostHabitableCheckHandle { |
1252 | { | ||
1253 | /** | 1248 | /** |
1254 | * The host to check | 1249 | * The host to check |
1255 | */ | 1250 | */ |
@@ -1294,7 +1289,7 @@ struct GNUNET_TESTBED_HostHabitableCheckHandle | |||
1294 | * @param cls GNUNET_TESTBED_HostHabitableCheckHandle | 1289 | * @param cls GNUNET_TESTBED_HostHabitableCheckHandle |
1295 | */ | 1290 | */ |
1296 | static void | 1291 | static void |
1297 | habitability_check (void *cls) | 1292 | habitability_check(void *cls) |
1298 | { | 1293 | { |
1299 | struct GNUNET_TESTBED_HostHabitableCheckHandle *h = cls; | 1294 | struct GNUNET_TESTBED_HostHabitableCheckHandle *h = cls; |
1300 | void *cb_cls; | 1295 | void *cb_cls; |
@@ -1305,34 +1300,34 @@ habitability_check (void *cls) | |||
1305 | int ret; | 1300 | int ret; |
1306 | 1301 | ||
1307 | h->habitability_check_task = NULL; | 1302 | h->habitability_check_task = NULL; |
1308 | ret = GNUNET_OS_process_status (h->auxp, &type, &code); | 1303 | ret = GNUNET_OS_process_status(h->auxp, &type, &code); |
1309 | if (GNUNET_SYSERR == ret) | 1304 | if (GNUNET_SYSERR == ret) |
1310 | { | 1305 | { |
1311 | GNUNET_break (0); | 1306 | GNUNET_break(0); |
1312 | ret = GNUNET_NO; | 1307 | ret = GNUNET_NO; |
1313 | goto call_cb; | 1308 | goto call_cb; |
1314 | } | 1309 | } |
1315 | if (GNUNET_NO == ret) | 1310 | if (GNUNET_NO == ret) |
1316 | { | 1311 | { |
1317 | h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time); | 1312 | h->wait_time = GNUNET_TIME_STD_BACKOFF(h->wait_time); |
1318 | h->habitability_check_task = | 1313 | h->habitability_check_task = |
1319 | GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h); | 1314 | GNUNET_SCHEDULER_add_delayed(h->wait_time, &habitability_check, h); |
1320 | return; | 1315 | return; |
1321 | } | 1316 | } |
1322 | GNUNET_OS_process_destroy (h->auxp); | 1317 | GNUNET_OS_process_destroy(h->auxp); |
1323 | h->auxp = NULL; | 1318 | h->auxp = NULL; |
1324 | ret = (0 != code) ? GNUNET_NO : GNUNET_YES; | 1319 | ret = (0 != code) ? GNUNET_NO : GNUNET_YES; |
1325 | 1320 | ||
1326 | call_cb: | 1321 | call_cb: |
1327 | if (NULL != h->auxp) | 1322 | if (NULL != h->auxp) |
1328 | GNUNET_OS_process_destroy (h->auxp); | 1323 | GNUNET_OS_process_destroy(h->auxp); |
1329 | cb = h->cb; | 1324 | cb = h->cb; |
1330 | cb_cls = h->cb_cls; | 1325 | cb_cls = h->cb_cls; |
1331 | host = h->host; | 1326 | host = h->host; |
1332 | free_argv (h->helper_argv); | 1327 | free_argv(h->helper_argv); |
1333 | GNUNET_free (h); | 1328 | GNUNET_free(h); |
1334 | if (NULL != cb) | 1329 | if (NULL != cb) |
1335 | cb (cb_cls, host, ret); | 1330 | cb(cb_cls, host, ret); |
1336 | } | 1331 | } |
1337 | 1332 | ||
1338 | 1333 | ||
@@ -1348,7 +1343,7 @@ call_cb: | |||
1348 | * GNUNET_TESTBED_is_host_habitable_cancel() | 1343 | * GNUNET_TESTBED_is_host_habitable_cancel() |
1349 | */ | 1344 | */ |
1350 | struct GNUNET_TESTBED_HostHabitableCheckHandle * | 1345 | struct GNUNET_TESTBED_HostHabitableCheckHandle * |
1351 | GNUNET_TESTBED_is_host_habitable ( | 1346 | GNUNET_TESTBED_is_host_habitable( |
1352 | const struct GNUNET_TESTBED_Host *host, | 1347 | const struct GNUNET_TESTBED_Host *host, |
1353 | const struct GNUNET_CONFIGURATION_Handle *config, | 1348 | const struct GNUNET_CONFIGURATION_Handle *config, |
1354 | GNUNET_TESTBED_HostHabitableCallback cb, | 1349 | GNUNET_TESTBED_HostHabitableCallback cb, |
@@ -1361,45 +1356,45 @@ GNUNET_TESTBED_is_host_habitable ( | |||
1361 | const char *hostname; | 1356 | const char *hostname; |
1362 | char *port; | 1357 | char *port; |
1363 | 1358 | ||
1364 | h = GNUNET_new (struct GNUNET_TESTBED_HostHabitableCheckHandle); | 1359 | h = GNUNET_new(struct GNUNET_TESTBED_HostHabitableCheckHandle); |
1365 | h->cb = cb; | 1360 | h->cb = cb; |
1366 | h->cb_cls = cb_cls; | 1361 | h->cb_cls = cb_cls; |
1367 | h->host = host; | 1362 | h->host = host; |
1368 | hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname; | 1363 | hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname; |
1369 | if (GNUNET_OK != | 1364 | if (GNUNET_OK != |
1370 | GNUNET_CONFIGURATION_get_value_filename (config, | 1365 | GNUNET_CONFIGURATION_get_value_filename(config, |
1371 | "testbed", | 1366 | "testbed", |
1372 | "HELPER_BINARY_PATH", | 1367 | "HELPER_BINARY_PATH", |
1373 | &stat_args[1])) | 1368 | &stat_args[1])) |
1374 | stat_args[1] = GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY); | 1369 | stat_args[1] = GNUNET_OS_get_libexec_binary_path(HELPER_TESTBED_BINARY); |
1375 | GNUNET_asprintf (&port, "%u", host->port); | 1370 | GNUNET_asprintf(&port, "%u", host->port); |
1376 | rsh_args = gen_rsh_args (port, hostname, host->username); | 1371 | rsh_args = gen_rsh_args(port, hostname, host->username); |
1377 | GNUNET_free (port); | 1372 | GNUNET_free(port); |
1378 | port = NULL; | 1373 | port = NULL; |
1379 | stat_args[0] = "stat"; | 1374 | stat_args[0] = "stat"; |
1380 | stat_args[2] = NULL; | 1375 | stat_args[2] = NULL; |
1381 | rsh_suffix_args = gen_rsh_suffix_args ((const char **) stat_args); | 1376 | rsh_suffix_args = gen_rsh_suffix_args((const char **)stat_args); |
1382 | GNUNET_free (stat_args[1]); | 1377 | GNUNET_free(stat_args[1]); |
1383 | h->helper_argv = | 1378 | h->helper_argv = |
1384 | join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args); | 1379 | join_argv((const char **)rsh_args, (const char **)rsh_suffix_args); |
1385 | free_argv (rsh_suffix_args); | 1380 | free_argv(rsh_suffix_args); |
1386 | free_argv (rsh_args); | 1381 | free_argv(rsh_args); |
1387 | h->auxp = GNUNET_OS_start_process_vap (GNUNET_NO, | 1382 | h->auxp = GNUNET_OS_start_process_vap(GNUNET_NO, |
1388 | GNUNET_OS_INHERIT_STD_ERR, | 1383 | GNUNET_OS_INHERIT_STD_ERR, |
1389 | NULL, | 1384 | NULL, |
1390 | NULL, | 1385 | NULL, |
1391 | NULL, | 1386 | NULL, |
1392 | h->helper_argv[0], | 1387 | h->helper_argv[0], |
1393 | h->helper_argv); | 1388 | h->helper_argv); |
1394 | if (NULL == h->auxp) | 1389 | if (NULL == h->auxp) |
1395 | { | 1390 | { |
1396 | GNUNET_break (0); /* Cannot exec SSH? */ | 1391 | GNUNET_break(0); /* Cannot exec SSH? */ |
1397 | GNUNET_free (h); | 1392 | GNUNET_free(h); |
1398 | return NULL; | 1393 | return NULL; |
1399 | } | 1394 | } |
1400 | h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time); | 1395 | h->wait_time = GNUNET_TIME_STD_BACKOFF(h->wait_time); |
1401 | h->habitability_check_task = | 1396 | h->habitability_check_task = |
1402 | GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h); | 1397 | GNUNET_SCHEDULER_add_delayed(h->wait_time, &habitability_check, h); |
1403 | return h; | 1398 | return h; |
1404 | } | 1399 | } |
1405 | 1400 | ||
@@ -1410,15 +1405,15 @@ GNUNET_TESTBED_is_host_habitable ( | |||
1410 | * @param handle the habitability check handle | 1405 | * @param handle the habitability check handle |
1411 | */ | 1406 | */ |
1412 | void | 1407 | void |
1413 | GNUNET_TESTBED_is_host_habitable_cancel ( | 1408 | GNUNET_TESTBED_is_host_habitable_cancel( |
1414 | struct GNUNET_TESTBED_HostHabitableCheckHandle *handle) | 1409 | struct GNUNET_TESTBED_HostHabitableCheckHandle *handle) |
1415 | { | 1410 | { |
1416 | GNUNET_SCHEDULER_cancel (handle->habitability_check_task); | 1411 | GNUNET_SCHEDULER_cancel(handle->habitability_check_task); |
1417 | (void) GNUNET_OS_process_kill (handle->auxp, GNUNET_TERM_SIG); | 1412 | (void)GNUNET_OS_process_kill(handle->auxp, GNUNET_TERM_SIG); |
1418 | (void) GNUNET_OS_process_wait (handle->auxp); | 1413 | (void)GNUNET_OS_process_wait(handle->auxp); |
1419 | GNUNET_OS_process_destroy (handle->auxp); | 1414 | GNUNET_OS_process_destroy(handle->auxp); |
1420 | free_argv (handle->helper_argv); | 1415 | free_argv(handle->helper_argv); |
1421 | GNUNET_free (handle); | 1416 | GNUNET_free(handle); |
1422 | } | 1417 | } |
1423 | 1418 | ||
1424 | 1419 | ||
@@ -1435,10 +1430,10 @@ GNUNET_TESTBED_is_host_habitable_cancel ( | |||
1435 | * registration | 1430 | * registration |
1436 | */ | 1431 | */ |
1437 | struct GNUNET_TESTBED_HostRegistrationHandle * | 1432 | struct GNUNET_TESTBED_HostRegistrationHandle * |
1438 | GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller, | 1433 | GNUNET_TESTBED_register_host(struct GNUNET_TESTBED_Controller *controller, |
1439 | struct GNUNET_TESTBED_Host *host, | 1434 | struct GNUNET_TESTBED_Host *host, |
1440 | GNUNET_TESTBED_HostRegistrationCompletion cc, | 1435 | GNUNET_TESTBED_HostRegistrationCompletion cc, |
1441 | void *cc_cls) | 1436 | void *cc_cls) |
1442 | { | 1437 | { |
1443 | struct GNUNET_TESTBED_HostRegistrationHandle *rh; | 1438 | struct GNUNET_TESTBED_HostRegistrationHandle *rh; |
1444 | struct GNUNET_TESTBED_AddHostMessage *msg; | 1439 | struct GNUNET_TESTBED_AddHostMessage *msg; |
@@ -1455,57 +1450,57 @@ GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller, | |||
1455 | 1450 | ||
1456 | if (NULL != controller->rh) | 1451 | if (NULL != controller->rh) |
1457 | return NULL; | 1452 | return NULL; |
1458 | hostname = GNUNET_TESTBED_host_get_hostname (host); | 1453 | hostname = GNUNET_TESTBED_host_get_hostname(host); |
1459 | if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_ (host, controller)) | 1454 | if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_(host, controller)) |
1460 | { | 1455 | { |
1461 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1456 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1462 | "Host hostname: %s already registered\n", | 1457 | "Host hostname: %s already registered\n", |
1463 | (NULL == hostname) ? "localhost" : hostname); | 1458 | (NULL == hostname) ? "localhost" : hostname); |
1464 | return NULL; | 1459 | return NULL; |
1465 | } | 1460 | } |
1466 | rh = GNUNET_new (struct GNUNET_TESTBED_HostRegistrationHandle); | 1461 | rh = GNUNET_new(struct GNUNET_TESTBED_HostRegistrationHandle); |
1467 | rh->host = host; | 1462 | rh->host = host; |
1468 | rh->c = controller; | 1463 | rh->c = controller; |
1469 | GNUNET_assert (NULL != cc); | 1464 | GNUNET_assert(NULL != cc); |
1470 | rh->cc = cc; | 1465 | rh->cc = cc; |
1471 | rh->cc_cls = cc_cls; | 1466 | rh->cc_cls = cc_cls; |
1472 | controller->rh = rh; | 1467 | controller->rh = rh; |
1473 | username = GNUNET_TESTBED_host_get_username_ (host); | 1468 | username = GNUNET_TESTBED_host_get_username_(host); |
1474 | username_length = 0; | 1469 | username_length = 0; |
1475 | if (NULL != username) | 1470 | if (NULL != username) |
1476 | username_length = strlen (username); | 1471 | username_length = strlen(username); |
1477 | GNUNET_assert (NULL != hostname); /* Hostname must be present */ | 1472 | GNUNET_assert(NULL != hostname); /* Hostname must be present */ |
1478 | hostname_length = strlen (hostname); | 1473 | hostname_length = strlen(hostname); |
1479 | GNUNET_assert (NULL != host->cfg); | 1474 | GNUNET_assert(NULL != host->cfg); |
1480 | config = GNUNET_CONFIGURATION_serialize (host->cfg, &config_size); | 1475 | config = GNUNET_CONFIGURATION_serialize(host->cfg, &config_size); |
1481 | cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig); | 1476 | cc_size = GNUNET_TESTBED_compress_config_(config, config_size, &cconfig); |
1482 | GNUNET_free (config); | 1477 | GNUNET_free(config); |
1483 | msg_size = (sizeof (struct GNUNET_TESTBED_AddHostMessage)); | 1478 | msg_size = (sizeof(struct GNUNET_TESTBED_AddHostMessage)); |
1484 | msg_size += username_length; | 1479 | msg_size += username_length; |
1485 | msg_size += hostname_length; | 1480 | msg_size += hostname_length; |
1486 | msg_size += cc_size; | 1481 | msg_size += cc_size; |
1487 | msg = GNUNET_malloc (msg_size); | 1482 | msg = GNUNET_malloc(msg_size); |
1488 | msg->header.size = htons (msg_size); | 1483 | msg->header.size = htons(msg_size); |
1489 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST); | 1484 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST); |
1490 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host)); | 1485 | msg->host_id = htonl(GNUNET_TESTBED_host_get_id_(host)); |
1491 | msg->ssh_port = htons (GNUNET_TESTBED_host_get_ssh_port_ (host)); | 1486 | msg->ssh_port = htons(GNUNET_TESTBED_host_get_ssh_port_(host)); |
1492 | ptr = &msg[1]; | 1487 | ptr = &msg[1]; |
1493 | if (NULL != username) | 1488 | if (NULL != username) |
1494 | { | 1489 | { |
1495 | msg->username_length = htons (username_length); | 1490 | msg->username_length = htons(username_length); |
1496 | GNUNET_memcpy (ptr, username, username_length); | 1491 | GNUNET_memcpy(ptr, username, username_length); |
1497 | ptr += username_length; | 1492 | ptr += username_length; |
1498 | } | 1493 | } |
1499 | msg->hostname_length = htons (hostname_length); | 1494 | msg->hostname_length = htons(hostname_length); |
1500 | GNUNET_memcpy (ptr, hostname, hostname_length); | 1495 | GNUNET_memcpy(ptr, hostname, hostname_length); |
1501 | ptr += hostname_length; | 1496 | ptr += hostname_length; |
1502 | msg->config_size = htons (config_size); | 1497 | msg->config_size = htons(config_size); |
1503 | GNUNET_memcpy (ptr, cconfig, cc_size); | 1498 | GNUNET_memcpy(ptr, cconfig, cc_size); |
1504 | ptr += cc_size; | 1499 | ptr += cc_size; |
1505 | GNUNET_assert ((ptr - (void *) msg) == msg_size); | 1500 | GNUNET_assert((ptr - (void *)msg) == msg_size); |
1506 | GNUNET_free (cconfig); | 1501 | GNUNET_free(cconfig); |
1507 | GNUNET_TESTBED_queue_message_ (controller, | 1502 | GNUNET_TESTBED_queue_message_(controller, |
1508 | (struct GNUNET_MessageHeader *) msg); | 1503 | (struct GNUNET_MessageHeader *)msg); |
1509 | return rh; | 1504 | return rh; |
1510 | } | 1505 | } |
1511 | 1506 | ||
@@ -1518,16 +1513,16 @@ GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller, | |||
1518 | * @param handle the registration handle to cancel | 1513 | * @param handle the registration handle to cancel |
1519 | */ | 1514 | */ |
1520 | void | 1515 | void |
1521 | GNUNET_TESTBED_cancel_registration ( | 1516 | GNUNET_TESTBED_cancel_registration( |
1522 | struct GNUNET_TESTBED_HostRegistrationHandle *handle) | 1517 | struct GNUNET_TESTBED_HostRegistrationHandle *handle) |
1523 | { | 1518 | { |
1524 | if (handle != handle->c->rh) | 1519 | if (handle != handle->c->rh) |
1525 | { | 1520 | { |
1526 | GNUNET_break (0); | 1521 | GNUNET_break(0); |
1527 | return; | 1522 | return; |
1528 | } | 1523 | } |
1529 | handle->c->rh = NULL; | 1524 | handle->c->rh = NULL; |
1530 | GNUNET_free (handle); | 1525 | GNUNET_free(handle); |
1531 | } | 1526 | } |
1532 | 1527 | ||
1533 | 1528 | ||
@@ -1540,11 +1535,11 @@ GNUNET_TESTBED_cancel_registration ( | |||
1540 | * queue | 1535 | * queue |
1541 | */ | 1536 | */ |
1542 | void | 1537 | void |
1543 | GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, | 1538 | GNUNET_TESTBED_host_queue_oc_(struct GNUNET_TESTBED_Host *h, |
1544 | struct GNUNET_TESTBED_Operation *op) | 1539 | struct GNUNET_TESTBED_Operation *op) |
1545 | { | 1540 | { |
1546 | GNUNET_TESTBED_operation_queue_insert_ (h->opq_parallel_overlay_connect_operations, | 1541 | GNUNET_TESTBED_operation_queue_insert_(h->opq_parallel_overlay_connect_operations, |
1547 | op); | 1542 | op); |
1548 | } | 1543 | } |
1549 | 1544 | ||
1550 | 1545 | ||
@@ -1554,20 +1549,20 @@ GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, | |||
1554 | * @param host the host whose hostname is to be resolved | 1549 | * @param host the host whose hostname is to be resolved |
1555 | */ | 1550 | */ |
1556 | void | 1551 | void |
1557 | GNUNET_TESTBED_host_resolve_ (struct GNUNET_TESTBED_Host *host) | 1552 | GNUNET_TESTBED_host_resolve_(struct GNUNET_TESTBED_Host *host) |
1558 | { | 1553 | { |
1559 | char *hostname; | 1554 | char *hostname; |
1560 | 1555 | ||
1561 | hostname = (char *) host->hostname; | 1556 | hostname = (char *)host->hostname; |
1562 | host->hostname = simple_resolve (hostname); | 1557 | host->hostname = simple_resolve(hostname); |
1563 | if (NULL == host->hostname) | 1558 | if (NULL == host->hostname) |
1564 | { | 1559 | { |
1565 | GNUNET_break (0); | 1560 | GNUNET_break(0); |
1566 | host->hostname = hostname; | 1561 | host->hostname = hostname; |
1567 | return; | 1562 | return; |
1568 | } | 1563 | } |
1569 | GNUNET_free (hostname); | 1564 | GNUNET_free(hostname); |
1570 | host->hostname = GNUNET_strdup (host->hostname); | 1565 | host->hostname = GNUNET_strdup(host->hostname); |
1571 | } | 1566 | } |
1572 | 1567 | ||
1573 | /* end of testbed_api_hosts.c */ | 1568 | /* end of testbed_api_hosts.c */ |
diff --git a/src/testbed/testbed_api_hosts.h b/src/testbed/testbed_api_hosts.h index bc5e988d3..369a6da1b 100644 --- a/src/testbed/testbed_api_hosts.h +++ b/src/testbed/testbed_api_hosts.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -35,8 +35,7 @@ | |||
35 | /** | 35 | /** |
36 | * handle for host registration | 36 | * handle for host registration |
37 | */ | 37 | */ |
38 | struct GNUNET_TESTBED_HostRegistrationHandle | 38 | struct GNUNET_TESTBED_HostRegistrationHandle { |
39 | { | ||
40 | /** | 39 | /** |
41 | * The host being registered | 40 | * The host being registered |
42 | */ | 41 | */ |
@@ -67,7 +66,7 @@ struct GNUNET_TESTBED_HostRegistrationHandle | |||
67 | * @return handle to the host, NULL on error | 66 | * @return handle to the host, NULL on error |
68 | */ | 67 | */ |
69 | struct GNUNET_TESTBED_Host * | 68 | struct GNUNET_TESTBED_Host * |
70 | GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id); | 69 | GNUNET_TESTBED_host_lookup_by_id_(uint32_t id); |
71 | 70 | ||
72 | 71 | ||
73 | /** | 72 | /** |
@@ -83,9 +82,9 @@ GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id); | |||
83 | * @return handle to the host, NULL on error | 82 | * @return handle to the host, NULL on error |
84 | */ | 83 | */ |
85 | struct GNUNET_TESTBED_Host * | 84 | struct GNUNET_TESTBED_Host * |
86 | GNUNET_TESTBED_host_create_by_id_ (uint32_t id, | 85 | GNUNET_TESTBED_host_create_by_id_(uint32_t id, |
87 | const struct GNUNET_CONFIGURATION_Handle | 86 | const struct GNUNET_CONFIGURATION_Handle |
88 | *cfg); | 87 | *cfg); |
89 | 88 | ||
90 | 89 | ||
91 | /** | 90 | /** |
@@ -96,7 +95,7 @@ GNUNET_TESTBED_host_create_by_id_ (uint32_t id, | |||
96 | * 'localhost', but then obviously not globally unique) | 95 | * 'localhost', but then obviously not globally unique) |
97 | */ | 96 | */ |
98 | uint32_t | 97 | uint32_t |
99 | GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host); | 98 | GNUNET_TESTBED_host_get_id_(const struct GNUNET_TESTBED_Host *host); |
100 | 99 | ||
101 | 100 | ||
102 | /** | 101 | /** |
@@ -106,7 +105,7 @@ GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host); | |||
106 | * @return username to login to the host | 105 | * @return username to login to the host |
107 | */ | 106 | */ |
108 | const char * | 107 | const char * |
109 | GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host); | 108 | GNUNET_TESTBED_host_get_username_(const struct GNUNET_TESTBED_Host *host); |
110 | 109 | ||
111 | 110 | ||
112 | /** | 111 | /** |
@@ -116,7 +115,7 @@ GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host); | |||
116 | * @return username to login to the host | 115 | * @return username to login to the host |
117 | */ | 116 | */ |
118 | uint16_t | 117 | uint16_t |
119 | GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host); | 118 | GNUNET_TESTBED_host_get_ssh_port_(const struct GNUNET_TESTBED_Host *host); |
120 | 119 | ||
121 | 120 | ||
122 | /** | 121 | /** |
@@ -126,7 +125,7 @@ GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host); | |||
126 | * @return the host's configuration template | 125 | * @return the host's configuration template |
127 | */ | 126 | */ |
128 | const struct GNUNET_CONFIGURATION_Handle * | 127 | const struct GNUNET_CONFIGURATION_Handle * |
129 | GNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host); | 128 | GNUNET_TESTBED_host_get_cfg_(const struct GNUNET_TESTBED_Host *host); |
130 | 129 | ||
131 | 130 | ||
132 | /** | 131 | /** |
@@ -136,8 +135,8 @@ GNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host); | |||
136 | * @param new_cfg the new configuration to replace the old one | 135 | * @param new_cfg the new configuration to replace the old one |
137 | */ | 136 | */ |
138 | void | 137 | void |
139 | GNUNET_TESTBED_host_replace_cfg_ (struct GNUNET_TESTBED_Host *host, | 138 | GNUNET_TESTBED_host_replace_cfg_(struct GNUNET_TESTBED_Host *host, |
140 | const struct GNUNET_CONFIGURATION_Handle *new_cfg); | 139 | const struct GNUNET_CONFIGURATION_Handle *new_cfg); |
141 | 140 | ||
142 | 141 | ||
143 | /** | 142 | /** |
@@ -147,9 +146,9 @@ GNUNET_TESTBED_host_replace_cfg_ (struct GNUNET_TESTBED_Host *host, | |||
147 | * @param controller the controller at which this host is registered | 146 | * @param controller the controller at which this host is registered |
148 | */ | 147 | */ |
149 | void | 148 | void |
150 | GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host, | 149 | GNUNET_TESTBED_mark_host_registered_at_(struct GNUNET_TESTBED_Host *host, |
151 | const struct GNUNET_TESTBED_Controller | 150 | const struct GNUNET_TESTBED_Controller |
152 | *controller); | 151 | *controller); |
153 | 152 | ||
154 | 153 | ||
155 | /** | 154 | /** |
@@ -159,9 +158,9 @@ GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host, | |||
159 | * @param controller the controller at which this host has to be unmarked | 158 | * @param controller the controller at which this host has to be unmarked |
160 | */ | 159 | */ |
161 | void | 160 | void |
162 | GNUNET_TESTBED_deregister_host_at_ (struct GNUNET_TESTBED_Host *host, | 161 | GNUNET_TESTBED_deregister_host_at_(struct GNUNET_TESTBED_Host *host, |
163 | const struct GNUNET_TESTBED_Controller | 162 | const struct GNUNET_TESTBED_Controller |
164 | *const controller); | 163 | *const controller); |
165 | 164 | ||
166 | 165 | ||
167 | /** | 166 | /** |
@@ -172,9 +171,9 @@ GNUNET_TESTBED_deregister_host_at_ (struct GNUNET_TESTBED_Host *host, | |||
172 | * @return GNUNET_YES if registered; GNUNET_NO if not | 171 | * @return GNUNET_YES if registered; GNUNET_NO if not |
173 | */ | 172 | */ |
174 | int | 173 | int |
175 | GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host, | 174 | GNUNET_TESTBED_is_host_registered_(const struct GNUNET_TESTBED_Host *host, |
176 | const struct GNUNET_TESTBED_Controller | 175 | const struct GNUNET_TESTBED_Controller |
177 | *controller); | 176 | *controller); |
178 | 177 | ||
179 | 178 | ||
180 | /** | 179 | /** |
@@ -186,8 +185,8 @@ GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host, | |||
186 | * queue | 185 | * queue |
187 | */ | 186 | */ |
188 | void | 187 | void |
189 | GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, | 188 | GNUNET_TESTBED_host_queue_oc_(struct GNUNET_TESTBED_Host *h, |
190 | struct GNUNET_TESTBED_Operation *op); | 189 | struct GNUNET_TESTBED_Operation *op); |
191 | 190 | ||
192 | 191 | ||
193 | /** | 192 | /** |
@@ -196,7 +195,7 @@ GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, | |||
196 | * @param cproc the handle to the controller's helper process | 195 | * @param cproc the handle to the controller's helper process |
197 | */ | 196 | */ |
198 | void | 197 | void |
199 | GNUNET_TESTBED_controller_kill_ (struct GNUNET_TESTBED_ControllerProc *cproc); | 198 | GNUNET_TESTBED_controller_kill_(struct GNUNET_TESTBED_ControllerProc *cproc); |
200 | 199 | ||
201 | 200 | ||
202 | /** | 201 | /** |
@@ -205,8 +204,8 @@ GNUNET_TESTBED_controller_kill_ (struct GNUNET_TESTBED_ControllerProc *cproc); | |||
205 | * @param cproc the handle to the controller's helper process | 204 | * @param cproc the handle to the controller's helper process |
206 | */ | 205 | */ |
207 | void | 206 | void |
208 | GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc | 207 | GNUNET_TESTBED_controller_destroy_(struct GNUNET_TESTBED_ControllerProc |
209 | *cproc); | 208 | *cproc); |
210 | 209 | ||
211 | 210 | ||
212 | /** | 211 | /** |
@@ -215,7 +214,7 @@ GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc | |||
215 | * @param host the host whose hostname is to be resolved | 214 | * @param host the host whose hostname is to be resolved |
216 | */ | 215 | */ |
217 | void | 216 | void |
218 | GNUNET_TESTBED_host_resolve_ (struct GNUNET_TESTBED_Host *host); | 217 | GNUNET_TESTBED_host_resolve_(struct GNUNET_TESTBED_Host *host); |
219 | 218 | ||
220 | 219 | ||
221 | #endif | 220 | #endif |
diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c index 167e1b833..194dc2655 100644 --- a/src/testbed/testbed_api_operations.c +++ b/src/testbed/testbed_api_operations.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -44,8 +44,7 @@ | |||
44 | /** | 44 | /** |
45 | * An entry in the operation queue | 45 | * An entry in the operation queue |
46 | */ | 46 | */ |
47 | struct QueueEntry | 47 | struct QueueEntry { |
48 | { | ||
49 | /** | 48 | /** |
50 | * The next DLL pointer | 49 | * The next DLL pointer |
51 | */ | 50 | */ |
@@ -78,8 +77,7 @@ struct OperationQueue; | |||
78 | /** | 77 | /** |
79 | * A slot to record time taken by an operation | 78 | * A slot to record time taken by an operation |
80 | */ | 79 | */ |
81 | struct TimeSlot | 80 | struct TimeSlot { |
82 | { | ||
83 | /** | 81 | /** |
84 | * DLL next pointer | 82 | * DLL next pointer |
85 | */ | 83 | */ |
@@ -115,8 +113,7 @@ struct TimeSlot | |||
115 | /** | 113 | /** |
116 | * Context for operation queues of type OPERATION_QUEUE_TYPE_ADAPTIVE | 114 | * Context for operation queues of type OPERATION_QUEUE_TYPE_ADAPTIVE |
117 | */ | 115 | */ |
118 | struct FeedbackCtx | 116 | struct FeedbackCtx { |
119 | { | ||
120 | /** | 117 | /** |
121 | * Handle for calculating standard deviation | 118 | * Handle for calculating standard deviation |
122 | */ | 119 | */ |
@@ -159,8 +156,7 @@ struct FeedbackCtx | |||
159 | * Queue of operations where we can only support a certain | 156 | * Queue of operations where we can only support a certain |
160 | * number of concurrent operations of a particular type. | 157 | * number of concurrent operations of a particular type. |
161 | */ | 158 | */ |
162 | struct OperationQueue | 159 | struct OperationQueue { |
163 | { | ||
164 | /** | 160 | /** |
165 | * DLL head for the wait queue. Operations which are waiting for this | 161 | * DLL head for the wait queue. Operations which are waiting for this |
166 | * operation queue are put here | 162 | * operation queue are put here |
@@ -247,8 +243,7 @@ struct OperationQueue | |||
247 | /** | 243 | /** |
248 | * Operation state | 244 | * Operation state |
249 | */ | 245 | */ |
250 | enum OperationState | 246 | enum OperationState { |
251 | { | ||
252 | /** | 247 | /** |
253 | * The operation is just created and is in initial state | 248 | * The operation is just created and is in initial state |
254 | */ | 249 | */ |
@@ -282,8 +277,7 @@ enum OperationState | |||
282 | /** | 277 | /** |
283 | * An entry in the ready queue (implemented as DLL) | 278 | * An entry in the ready queue (implemented as DLL) |
284 | */ | 279 | */ |
285 | struct ReadyQueueEntry | 280 | struct ReadyQueueEntry { |
286 | { | ||
287 | /** | 281 | /** |
288 | * next ptr for DLL | 282 | * next ptr for DLL |
289 | */ | 283 | */ |
@@ -304,8 +298,7 @@ struct ReadyQueueEntry | |||
304 | /** | 298 | /** |
305 | * Opaque handle to an abstract operation to be executed by the testing framework. | 299 | * Opaque handle to an abstract operation to be executed by the testing framework. |
306 | */ | 300 | */ |
307 | struct GNUNET_TESTBED_Operation | 301 | struct GNUNET_TESTBED_Operation { |
308 | { | ||
309 | /** | 302 | /** |
310 | * Function to call when we have the resources to begin the operation. | 303 | * Function to call when we have the resources to begin the operation. |
311 | */ | 304 | */ |
@@ -374,7 +367,6 @@ struct GNUNET_TESTBED_Operation | |||
374 | * Is this a failed operation? | 367 | * Is this a failed operation? |
375 | */ | 368 | */ |
376 | int failed; | 369 | int failed; |
377 | |||
378 | }; | 370 | }; |
379 | 371 | ||
380 | /** | 372 | /** |
@@ -411,17 +403,17 @@ struct GNUNET_SCHEDULER_Task *process_rq_task_id; | |||
411 | * @return the timeslot | 403 | * @return the timeslot |
412 | */ | 404 | */ |
413 | static void | 405 | static void |
414 | assign_timeslot (struct GNUNET_TESTBED_Operation *op, | 406 | assign_timeslot(struct GNUNET_TESTBED_Operation *op, |
415 | struct OperationQueue *queue) | 407 | struct OperationQueue *queue) |
416 | { | 408 | { |
417 | struct FeedbackCtx *fctx = queue->fctx; | 409 | struct FeedbackCtx *fctx = queue->fctx; |
418 | struct TimeSlot *tslot; | 410 | struct TimeSlot *tslot; |
419 | 411 | ||
420 | GNUNET_assert (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type); | 412 | GNUNET_assert(OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type); |
421 | tslot = fctx->alloc_head; | 413 | tslot = fctx->alloc_head; |
422 | GNUNET_assert (NULL != tslot); | 414 | GNUNET_assert(NULL != tslot); |
423 | GNUNET_CONTAINER_DLL_remove (fctx->alloc_head, fctx->alloc_tail, tslot); | 415 | GNUNET_CONTAINER_DLL_remove(fctx->alloc_head, fctx->alloc_tail, tslot); |
424 | GNUNET_CONTAINER_DLL_insert_tail (op->tslots_head, op->tslots_tail, tslot); | 416 | GNUNET_CONTAINER_DLL_insert_tail(op->tslots_head, op->tslots_tail, tslot); |
425 | tslot->op = op; | 417 | tslot->op = op; |
426 | } | 418 | } |
427 | 419 | ||
@@ -434,7 +426,7 @@ assign_timeslot (struct GNUNET_TESTBED_Operation *op, | |||
434 | * @param index the index of the entry in the operation's array of queue entries | 426 | * @param index the index of the entry in the operation's array of queue entries |
435 | */ | 427 | */ |
436 | static void | 428 | static void |
437 | remove_queue_entry (struct GNUNET_TESTBED_Operation *op, unsigned int index) | 429 | remove_queue_entry(struct GNUNET_TESTBED_Operation *op, unsigned int index) |
438 | { | 430 | { |
439 | struct OperationQueue *opq; | 431 | struct OperationQueue *opq; |
440 | struct QueueEntry *entry; | 432 | struct QueueEntry *entry; |
@@ -442,23 +434,27 @@ remove_queue_entry (struct GNUNET_TESTBED_Operation *op, unsigned int index) | |||
442 | opq = op->queues[index]; | 434 | opq = op->queues[index]; |
443 | entry = op->qentries[index]; | 435 | entry = op->qentries[index]; |
444 | switch (op->state) | 436 | switch (op->state) |
445 | { | 437 | { |
446 | case OP_STATE_INIT: | 438 | case OP_STATE_INIT: |
447 | GNUNET_assert (0); | 439 | GNUNET_assert(0); |
448 | break; | 440 | break; |
449 | case OP_STATE_WAITING: | 441 | |
450 | GNUNET_CONTAINER_DLL_remove (opq->wq_head, opq->wq_tail, entry); | 442 | case OP_STATE_WAITING: |
451 | break; | 443 | GNUNET_CONTAINER_DLL_remove(opq->wq_head, opq->wq_tail, entry); |
452 | case OP_STATE_READY: | 444 | break; |
453 | GNUNET_CONTAINER_DLL_remove (opq->rq_head, opq->rq_tail, entry); | 445 | |
454 | break; | 446 | case OP_STATE_READY: |
455 | case OP_STATE_ACTIVE: | 447 | GNUNET_CONTAINER_DLL_remove(opq->rq_head, opq->rq_tail, entry); |
456 | GNUNET_CONTAINER_DLL_remove (opq->aq_head, opq->aq_tail, entry); | 448 | break; |
457 | break; | 449 | |
458 | case OP_STATE_INACTIVE: | 450 | case OP_STATE_ACTIVE: |
459 | GNUNET_CONTAINER_DLL_remove (opq->nq_head, opq->nq_tail, entry); | 451 | GNUNET_CONTAINER_DLL_remove(opq->aq_head, opq->aq_tail, entry); |
460 | break; | 452 | break; |
461 | } | 453 | |
454 | case OP_STATE_INACTIVE: | ||
455 | GNUNET_CONTAINER_DLL_remove(opq->nq_head, opq->nq_tail, entry); | ||
456 | break; | ||
457 | } | ||
462 | } | 458 | } |
463 | 459 | ||
464 | 460 | ||
@@ -470,53 +466,57 @@ remove_queue_entry (struct GNUNET_TESTBED_Operation *op, unsigned int index) | |||
470 | * @param state the state the operation should have. It cannot be OP_STATE_INIT | 466 | * @param state the state the operation should have. It cannot be OP_STATE_INIT |
471 | */ | 467 | */ |
472 | static void | 468 | static void |
473 | change_state (struct GNUNET_TESTBED_Operation *op, enum OperationState state) | 469 | change_state(struct GNUNET_TESTBED_Operation *op, enum OperationState state) |
474 | { | 470 | { |
475 | struct QueueEntry *entry; | 471 | struct QueueEntry *entry; |
476 | struct OperationQueue *opq; | 472 | struct OperationQueue *opq; |
477 | unsigned int cnt; | 473 | unsigned int cnt; |
478 | unsigned int s; | 474 | unsigned int s; |
479 | 475 | ||
480 | GNUNET_assert (OP_STATE_INIT != state); | 476 | GNUNET_assert(OP_STATE_INIT != state); |
481 | GNUNET_assert (NULL != op->queues); | 477 | GNUNET_assert(NULL != op->queues); |
482 | GNUNET_assert (NULL != op->nres); | 478 | GNUNET_assert(NULL != op->nres); |
483 | GNUNET_assert ((OP_STATE_INIT == op->state) || (NULL != op->qentries)); | 479 | GNUNET_assert((OP_STATE_INIT == op->state) || (NULL != op->qentries)); |
484 | GNUNET_assert (op->state != state); | 480 | GNUNET_assert(op->state != state); |
485 | for (cnt = 0; cnt < op->nqueues; cnt++) | 481 | for (cnt = 0; cnt < op->nqueues; cnt++) |
486 | { | ||
487 | if (OP_STATE_INIT == op->state) | ||
488 | { | ||
489 | entry = GNUNET_new (struct QueueEntry); | ||
490 | entry->op = op; | ||
491 | entry->nres = op->nres[cnt]; | ||
492 | s = cnt; | ||
493 | GNUNET_array_append (op->qentries, s, entry); | ||
494 | } | ||
495 | else | ||
496 | { | 482 | { |
497 | entry = op->qentries[cnt]; | 483 | if (OP_STATE_INIT == op->state) |
498 | remove_queue_entry (op, cnt); | 484 | { |
485 | entry = GNUNET_new(struct QueueEntry); | ||
486 | entry->op = op; | ||
487 | entry->nres = op->nres[cnt]; | ||
488 | s = cnt; | ||
489 | GNUNET_array_append(op->qentries, s, entry); | ||
490 | } | ||
491 | else | ||
492 | { | ||
493 | entry = op->qentries[cnt]; | ||
494 | remove_queue_entry(op, cnt); | ||
495 | } | ||
496 | opq = op->queues[cnt]; | ||
497 | switch (state) | ||
498 | { | ||
499 | case OP_STATE_INIT: | ||
500 | GNUNET_assert(0); | ||
501 | break; | ||
502 | |||
503 | case OP_STATE_WAITING: | ||
504 | GNUNET_CONTAINER_DLL_insert_tail(opq->wq_head, opq->wq_tail, entry); | ||
505 | break; | ||
506 | |||
507 | case OP_STATE_READY: | ||
508 | GNUNET_CONTAINER_DLL_insert_tail(opq->rq_head, opq->rq_tail, entry); | ||
509 | break; | ||
510 | |||
511 | case OP_STATE_ACTIVE: | ||
512 | GNUNET_CONTAINER_DLL_insert_tail(opq->aq_head, opq->aq_tail, entry); | ||
513 | break; | ||
514 | |||
515 | case OP_STATE_INACTIVE: | ||
516 | GNUNET_CONTAINER_DLL_insert_tail(opq->nq_head, opq->nq_tail, entry); | ||
517 | break; | ||
518 | } | ||
499 | } | 519 | } |
500 | opq = op->queues[cnt]; | ||
501 | switch (state) | ||
502 | { | ||
503 | case OP_STATE_INIT: | ||
504 | GNUNET_assert (0); | ||
505 | break; | ||
506 | case OP_STATE_WAITING: | ||
507 | GNUNET_CONTAINER_DLL_insert_tail (opq->wq_head, opq->wq_tail, entry); | ||
508 | break; | ||
509 | case OP_STATE_READY: | ||
510 | GNUNET_CONTAINER_DLL_insert_tail (opq->rq_head, opq->rq_tail, entry); | ||
511 | break; | ||
512 | case OP_STATE_ACTIVE: | ||
513 | GNUNET_CONTAINER_DLL_insert_tail (opq->aq_head, opq->aq_tail, entry); | ||
514 | break; | ||
515 | case OP_STATE_INACTIVE: | ||
516 | GNUNET_CONTAINER_DLL_insert_tail (opq->nq_head, opq->nq_tail, entry); | ||
517 | break; | ||
518 | } | ||
519 | } | ||
520 | op->state = state; | 520 | op->state = state; |
521 | } | 521 | } |
522 | 522 | ||
@@ -528,17 +528,17 @@ change_state (struct GNUNET_TESTBED_Operation *op, enum OperationState state) | |||
528 | * @param op the operation to be removed | 528 | * @param op the operation to be removed |
529 | */ | 529 | */ |
530 | static void | 530 | static void |
531 | rq_remove (struct GNUNET_TESTBED_Operation *op) | 531 | rq_remove(struct GNUNET_TESTBED_Operation *op) |
532 | { | 532 | { |
533 | GNUNET_assert (NULL != op->rq_entry); | 533 | GNUNET_assert(NULL != op->rq_entry); |
534 | GNUNET_CONTAINER_DLL_remove (rq_head, rq_tail, op->rq_entry); | 534 | GNUNET_CONTAINER_DLL_remove(rq_head, rq_tail, op->rq_entry); |
535 | GNUNET_free (op->rq_entry); | 535 | GNUNET_free(op->rq_entry); |
536 | op->rq_entry = NULL; | 536 | op->rq_entry = NULL; |
537 | if ( (NULL == rq_head) && (NULL != process_rq_task_id) ) | 537 | if ((NULL == rq_head) && (NULL != process_rq_task_id)) |
538 | { | 538 | { |
539 | GNUNET_SCHEDULER_cancel (process_rq_task_id); | 539 | GNUNET_SCHEDULER_cancel(process_rq_task_id); |
540 | process_rq_task_id = NULL; | 540 | process_rq_task_id = NULL; |
541 | } | 541 | } |
542 | } | 542 | } |
543 | 543 | ||
544 | 544 | ||
@@ -551,28 +551,28 @@ rq_remove (struct GNUNET_TESTBED_Operation *op) | |||
551 | * @param cls NULL | 551 | * @param cls NULL |
552 | */ | 552 | */ |
553 | static void | 553 | static void |
554 | process_rq_task (void *cls) | 554 | process_rq_task(void *cls) |
555 | { | 555 | { |
556 | struct GNUNET_TESTBED_Operation *op; | 556 | struct GNUNET_TESTBED_Operation *op; |
557 | struct OperationQueue *queue; | 557 | struct OperationQueue *queue; |
558 | unsigned int cnt; | 558 | unsigned int cnt; |
559 | 559 | ||
560 | process_rq_task_id = NULL; | 560 | process_rq_task_id = NULL; |
561 | GNUNET_assert (NULL != rq_head); | 561 | GNUNET_assert(NULL != rq_head); |
562 | GNUNET_assert (NULL != (op = rq_head->op)); | 562 | GNUNET_assert(NULL != (op = rq_head->op)); |
563 | rq_remove (op); | 563 | rq_remove(op); |
564 | if (NULL != rq_head) | 564 | if (NULL != rq_head) |
565 | process_rq_task_id = GNUNET_SCHEDULER_add_now (&process_rq_task, NULL); | 565 | process_rq_task_id = GNUNET_SCHEDULER_add_now(&process_rq_task, NULL); |
566 | change_state (op, OP_STATE_ACTIVE); | 566 | change_state(op, OP_STATE_ACTIVE); |
567 | for (cnt = 0; cnt < op->nqueues; cnt++) | 567 | for (cnt = 0; cnt < op->nqueues; cnt++) |
568 | { | 568 | { |
569 | queue = op->queues[cnt]; | 569 | queue = op->queues[cnt]; |
570 | if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type) | 570 | if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type) |
571 | assign_timeslot (op, queue); | 571 | assign_timeslot(op, queue); |
572 | } | 572 | } |
573 | op->tstart = GNUNET_TIME_absolute_get (); | 573 | op->tstart = GNUNET_TIME_absolute_get(); |
574 | if (NULL != op->start) | 574 | if (NULL != op->start) |
575 | op->start (op->cb_cls); | 575 | op->start(op->cb_cls); |
576 | } | 576 | } |
577 | 577 | ||
578 | 578 | ||
@@ -582,17 +582,17 @@ process_rq_task (void *cls) | |||
582 | * @param op the operation to be queued | 582 | * @param op the operation to be queued |
583 | */ | 583 | */ |
584 | static void | 584 | static void |
585 | rq_add (struct GNUNET_TESTBED_Operation *op) | 585 | rq_add(struct GNUNET_TESTBED_Operation *op) |
586 | { | 586 | { |
587 | struct ReadyQueueEntry *rq_entry; | 587 | struct ReadyQueueEntry *rq_entry; |
588 | 588 | ||
589 | GNUNET_assert (NULL == op->rq_entry); | 589 | GNUNET_assert(NULL == op->rq_entry); |
590 | rq_entry = GNUNET_new (struct ReadyQueueEntry); | 590 | rq_entry = GNUNET_new(struct ReadyQueueEntry); |
591 | rq_entry->op = op; | 591 | rq_entry->op = op; |
592 | GNUNET_CONTAINER_DLL_insert_tail (rq_head, rq_tail, rq_entry); | 592 | GNUNET_CONTAINER_DLL_insert_tail(rq_head, rq_tail, rq_entry); |
593 | op->rq_entry = rq_entry; | 593 | op->rq_entry = rq_entry; |
594 | if (NULL == process_rq_task_id) | 594 | if (NULL == process_rq_task_id) |
595 | process_rq_task_id = GNUNET_SCHEDULER_add_now (&process_rq_task, NULL); | 595 | process_rq_task_id = GNUNET_SCHEDULER_add_now(&process_rq_task, NULL); |
596 | } | 596 | } |
597 | 597 | ||
598 | 598 | ||
@@ -604,12 +604,12 @@ rq_add (struct GNUNET_TESTBED_Operation *op) | |||
604 | * otherwise | 604 | * otherwise |
605 | */ | 605 | */ |
606 | static int | 606 | static int |
607 | is_queue_empty (struct OperationQueue *opq) | 607 | is_queue_empty(struct OperationQueue *opq) |
608 | { | 608 | { |
609 | if ( (NULL != opq->wq_head) | 609 | if ((NULL != opq->wq_head) |
610 | || (NULL != opq->rq_head) | 610 | || (NULL != opq->rq_head) |
611 | || (NULL != opq->aq_head) | 611 | || (NULL != opq->aq_head) |
612 | || (NULL != opq->nq_head) ) | 612 | || (NULL != opq->nq_head)) |
613 | return GNUNET_NO; | 613 | return GNUNET_NO; |
614 | return GNUNET_YES; | 614 | return GNUNET_YES; |
615 | } | 615 | } |
@@ -632,10 +632,10 @@ is_queue_empty (struct OperationQueue *opq) | |||
632 | * be set to NULL and 0 respectively. | 632 | * be set to NULL and 0 respectively. |
633 | */ | 633 | */ |
634 | static int | 634 | static int |
635 | decide_capacity (struct OperationQueue *opq, | 635 | decide_capacity(struct OperationQueue *opq, |
636 | struct QueueEntry *entry, | 636 | struct QueueEntry *entry, |
637 | struct GNUNET_TESTBED_Operation ***ops_, | 637 | struct GNUNET_TESTBED_Operation ***ops_, |
638 | unsigned int *n_ops_) | 638 | unsigned int *n_ops_) |
639 | { | 639 | { |
640 | struct QueueEntry **evict_entries; | 640 | struct QueueEntry **evict_entries; |
641 | struct GNUNET_TESTBED_Operation **ops; | 641 | struct GNUNET_TESTBED_Operation **ops; |
@@ -647,53 +647,53 @@ decide_capacity (struct OperationQueue *opq, | |||
647 | int deficit; | 647 | int deficit; |
648 | int rval; | 648 | int rval; |
649 | 649 | ||
650 | GNUNET_assert (NULL != (op = entry->op)); | 650 | GNUNET_assert(NULL != (op = entry->op)); |
651 | GNUNET_assert (0 < (need = entry->nres)); | 651 | GNUNET_assert(0 < (need = entry->nres)); |
652 | ops = NULL; | 652 | ops = NULL; |
653 | n_ops = 0; | 653 | n_ops = 0; |
654 | evict_entries = NULL; | 654 | evict_entries = NULL; |
655 | n_evict_entries = 0; | 655 | n_evict_entries = 0; |
656 | rval = GNUNET_YES; | 656 | rval = GNUNET_YES; |
657 | if (OPERATION_QUEUE_TYPE_ADAPTIVE == opq->type) | 657 | if (OPERATION_QUEUE_TYPE_ADAPTIVE == opq->type) |
658 | { | 658 | { |
659 | GNUNET_assert (NULL != opq->fctx); | 659 | GNUNET_assert(NULL != opq->fctx); |
660 | GNUNET_assert (opq->max_active >= opq->overload); | 660 | GNUNET_assert(opq->max_active >= opq->overload); |
661 | max = opq->max_active - opq->overload; | 661 | max = opq->max_active - opq->overload; |
662 | } | 662 | } |
663 | else | 663 | else |
664 | max = opq->max_active; | 664 | max = opq->max_active; |
665 | if (opq->active > max) | 665 | if (opq->active > max) |
666 | { | 666 | { |
667 | rval = GNUNET_NO; | 667 | rval = GNUNET_NO; |
668 | goto ret; | 668 | goto ret; |
669 | } | 669 | } |
670 | if ((opq->active + need) <= max) | 670 | if ((opq->active + need) <= max) |
671 | goto ret; | 671 | goto ret; |
672 | deficit = need - (max - opq->active); | 672 | deficit = need - (max - opq->active); |
673 | for (entry = opq->nq_head; | 673 | for (entry = opq->nq_head; |
674 | (0 < deficit) && (NULL != entry); | 674 | (0 < deficit) && (NULL != entry); |
675 | entry = entry->next) | 675 | entry = entry->next) |
676 | { | 676 | { |
677 | GNUNET_array_append (evict_entries, n_evict_entries, entry); | 677 | GNUNET_array_append(evict_entries, n_evict_entries, entry); |
678 | deficit -= entry->nres; | 678 | deficit -= entry->nres; |
679 | } | 679 | } |
680 | if (0 < deficit) | 680 | if (0 < deficit) |
681 | { | 681 | { |
682 | rval = GNUNET_NO; | 682 | rval = GNUNET_NO; |
683 | goto ret; | 683 | goto ret; |
684 | } | 684 | } |
685 | for (n_ops = 0; n_ops < n_evict_entries;) | 685 | for (n_ops = 0; n_ops < n_evict_entries;) |
686 | { | 686 | { |
687 | op = evict_entries[n_ops]->op; | 687 | op = evict_entries[n_ops]->op; |
688 | GNUNET_array_append (ops, n_ops, op); /* increments n-ops */ | 688 | GNUNET_array_append(ops, n_ops, op); /* increments n-ops */ |
689 | } | 689 | } |
690 | 690 | ||
691 | ret: | 691 | ret: |
692 | GNUNET_free_non_null (evict_entries); | 692 | GNUNET_free_non_null(evict_entries); |
693 | if (NULL != ops_) | 693 | if (NULL != ops_) |
694 | *ops_ = ops; | 694 | *ops_ = ops; |
695 | else | 695 | else |
696 | GNUNET_free (ops); | 696 | GNUNET_free(ops); |
697 | if (NULL != n_ops_) | 697 | if (NULL != n_ops_) |
698 | *n_ops_ = n_ops; | 698 | *n_ops_ = n_ops; |
699 | return rval; | 699 | return rval; |
@@ -710,30 +710,30 @@ decide_capacity (struct OperationQueue *opq, | |||
710 | * @param n_new the number of operations in new array | 710 | * @param n_new the number of operations in new array |
711 | */ | 711 | */ |
712 | static void | 712 | static void |
713 | merge_ops (struct GNUNET_TESTBED_Operation ***old, | 713 | merge_ops(struct GNUNET_TESTBED_Operation ***old, |
714 | unsigned int *n_old, | 714 | unsigned int *n_old, |
715 | struct GNUNET_TESTBED_Operation **new, | 715 | struct GNUNET_TESTBED_Operation **new, |
716 | unsigned int n_new) | 716 | unsigned int n_new) |
717 | { | 717 | { |
718 | struct GNUNET_TESTBED_Operation **cur; | 718 | struct GNUNET_TESTBED_Operation **cur; |
719 | unsigned int i; | 719 | unsigned int i; |
720 | unsigned int j; | 720 | unsigned int j; |
721 | unsigned int n_cur; | 721 | unsigned int n_cur; |
722 | 722 | ||
723 | GNUNET_assert (NULL != old); | 723 | GNUNET_assert(NULL != old); |
724 | n_cur = *n_old; | 724 | n_cur = *n_old; |
725 | cur = *old; | 725 | cur = *old; |
726 | for (i = 0; i < n_new; i++) | 726 | for (i = 0; i < n_new; i++) |
727 | { | ||
728 | for (j = 0; j < *n_old; j++) | ||
729 | { | 727 | { |
730 | if (new[i] == cur[j]) | 728 | for (j = 0; j < *n_old; j++) |
731 | break; | 729 | { |
730 | if (new[i] == cur[j]) | ||
731 | break; | ||
732 | } | ||
733 | if (j < *n_old) | ||
734 | continue; | ||
735 | GNUNET_array_append(cur, n_cur, new[j]); | ||
732 | } | 736 | } |
733 | if (j < *n_old) | ||
734 | continue; | ||
735 | GNUNET_array_append (cur, n_cur, new[j]); | ||
736 | } | ||
737 | *old = cur; | 737 | *old = cur; |
738 | *n_old = n_cur; | 738 | *n_old = n_cur; |
739 | } | 739 | } |
@@ -746,7 +746,7 @@ merge_ops (struct GNUNET_TESTBED_Operation ***old, | |||
746 | * @param op the operation | 746 | * @param op the operation |
747 | */ | 747 | */ |
748 | static int | 748 | static int |
749 | check_readiness (struct GNUNET_TESTBED_Operation *op) | 749 | check_readiness(struct GNUNET_TESTBED_Operation *op) |
750 | { | 750 | { |
751 | struct GNUNET_TESTBED_Operation **evict_ops; | 751 | struct GNUNET_TESTBED_Operation **evict_ops; |
752 | struct GNUNET_TESTBED_Operation **ops; | 752 | struct GNUNET_TESTBED_Operation **ops; |
@@ -754,39 +754,39 @@ check_readiness (struct GNUNET_TESTBED_Operation *op) | |||
754 | unsigned int n_evict_ops; | 754 | unsigned int n_evict_ops; |
755 | unsigned int i; | 755 | unsigned int i; |
756 | 756 | ||
757 | GNUNET_assert (NULL == op->rq_entry); | 757 | GNUNET_assert(NULL == op->rq_entry); |
758 | GNUNET_assert (OP_STATE_WAITING == op->state); | 758 | GNUNET_assert(OP_STATE_WAITING == op->state); |
759 | evict_ops = NULL; | 759 | evict_ops = NULL; |
760 | n_evict_ops = 0; | 760 | n_evict_ops = 0; |
761 | for (i = 0; i < op->nqueues; i++) | 761 | for (i = 0; i < op->nqueues; i++) |
762 | { | ||
763 | ops = NULL; | ||
764 | n_ops = 0; | ||
765 | if (GNUNET_NO == decide_capacity (op->queues[i], op->qentries[i], | ||
766 | &ops, &n_ops)) | ||
767 | { | 762 | { |
768 | GNUNET_free_non_null (evict_ops); | 763 | ops = NULL; |
769 | return GNUNET_NO; | 764 | n_ops = 0; |
765 | if (GNUNET_NO == decide_capacity(op->queues[i], op->qentries[i], | ||
766 | &ops, &n_ops)) | ||
767 | { | ||
768 | GNUNET_free_non_null(evict_ops); | ||
769 | return GNUNET_NO; | ||
770 | } | ||
771 | if (NULL == ops) | ||
772 | continue; | ||
773 | merge_ops(&evict_ops, &n_evict_ops, ops, n_ops); | ||
774 | GNUNET_free(ops); | ||
770 | } | 775 | } |
771 | if (NULL == ops) | ||
772 | continue; | ||
773 | merge_ops (&evict_ops, &n_evict_ops, ops, n_ops); | ||
774 | GNUNET_free (ops); | ||
775 | } | ||
776 | if (NULL != evict_ops) | 776 | if (NULL != evict_ops) |
777 | { | 777 | { |
778 | for (i = 0; i < n_evict_ops; i++) | 778 | for (i = 0; i < n_evict_ops; i++) |
779 | GNUNET_TESTBED_operation_release_ (evict_ops[i]); | 779 | GNUNET_TESTBED_operation_release_(evict_ops[i]); |
780 | GNUNET_free (evict_ops); | 780 | GNUNET_free(evict_ops); |
781 | evict_ops = NULL; | 781 | evict_ops = NULL; |
782 | /* Evicting the operations should schedule this operation */ | 782 | /* Evicting the operations should schedule this operation */ |
783 | GNUNET_assert (OP_STATE_READY == op->state); | 783 | GNUNET_assert(OP_STATE_READY == op->state); |
784 | return GNUNET_YES; | 784 | return GNUNET_YES; |
785 | } | 785 | } |
786 | for (i = 0; i < op->nqueues; i++) | 786 | for (i = 0; i < op->nqueues; i++) |
787 | op->queues[i]->active += op->nres[i]; | 787 | op->queues[i]->active += op->nres[i]; |
788 | change_state (op, OP_STATE_READY); | 788 | change_state(op, OP_STATE_READY); |
789 | rq_add (op); | 789 | rq_add(op); |
790 | return GNUNET_YES; | 790 | return GNUNET_YES; |
791 | } | 791 | } |
792 | 792 | ||
@@ -797,18 +797,18 @@ check_readiness (struct GNUNET_TESTBED_Operation *op) | |||
797 | * @param op the operation to defer | 797 | * @param op the operation to defer |
798 | */ | 798 | */ |
799 | static void | 799 | static void |
800 | defer (struct GNUNET_TESTBED_Operation *op) | 800 | defer(struct GNUNET_TESTBED_Operation *op) |
801 | { | 801 | { |
802 | unsigned int i; | 802 | unsigned int i; |
803 | 803 | ||
804 | GNUNET_assert (OP_STATE_READY == op->state); | 804 | GNUNET_assert(OP_STATE_READY == op->state); |
805 | rq_remove (op); | 805 | rq_remove(op); |
806 | for (i = 0; i < op->nqueues; i++) | 806 | for (i = 0; i < op->nqueues; i++) |
807 | { | 807 | { |
808 | GNUNET_assert (op->queues[i]->active >= op->nres[i]); | 808 | GNUNET_assert(op->queues[i]->active >= op->nres[i]); |
809 | op->queues[i]->active -= op->nres[i]; | 809 | op->queues[i]->active -= op->nres[i]; |
810 | } | 810 | } |
811 | change_state (op, OP_STATE_WAITING); | 811 | change_state(op, OP_STATE_WAITING); |
812 | } | 812 | } |
813 | 813 | ||
814 | 814 | ||
@@ -820,23 +820,23 @@ defer (struct GNUNET_TESTBED_Operation *op) | |||
820 | * @param queue the operation queue | 820 | * @param queue the operation queue |
821 | */ | 821 | */ |
822 | static void | 822 | static void |
823 | cleanup_tslots (struct OperationQueue *queue) | 823 | cleanup_tslots(struct OperationQueue *queue) |
824 | { | 824 | { |
825 | struct FeedbackCtx *fctx = queue->fctx; | 825 | struct FeedbackCtx *fctx = queue->fctx; |
826 | struct TimeSlot *tslot; | 826 | struct TimeSlot *tslot; |
827 | struct GNUNET_TESTBED_Operation *op; | 827 | struct GNUNET_TESTBED_Operation *op; |
828 | unsigned int cnt; | 828 | unsigned int cnt; |
829 | 829 | ||
830 | GNUNET_assert (NULL != fctx); | 830 | GNUNET_assert(NULL != fctx); |
831 | for (cnt = 0; cnt < queue->max_active; cnt++) | 831 | for (cnt = 0; cnt < queue->max_active; cnt++) |
832 | { | 832 | { |
833 | tslot = &fctx->tslots_freeptr[cnt]; | 833 | tslot = &fctx->tslots_freeptr[cnt]; |
834 | op = tslot->op; | 834 | op = tslot->op; |
835 | if (NULL == op) | 835 | if (NULL == op) |
836 | continue; | 836 | continue; |
837 | GNUNET_CONTAINER_DLL_remove (op->tslots_head, op->tslots_tail, tslot); | 837 | GNUNET_CONTAINER_DLL_remove(op->tslots_head, op->tslots_tail, tslot); |
838 | } | 838 | } |
839 | GNUNET_free_non_null (fctx->tslots_freeptr); | 839 | GNUNET_free_non_null(fctx->tslots_freeptr); |
840 | fctx->tslots_freeptr = NULL; | 840 | fctx->tslots_freeptr = NULL; |
841 | fctx->alloc_head = NULL; | 841 | fctx->alloc_head = NULL; |
842 | fctx->alloc_tail = NULL; | 842 | fctx->alloc_tail = NULL; |
@@ -854,23 +854,23 @@ cleanup_tslots (struct OperationQueue *queue) | |||
854 | * will be selected as n | 854 | * will be selected as n |
855 | */ | 855 | */ |
856 | static void | 856 | static void |
857 | adaptive_queue_set_max_active (struct OperationQueue *queue, unsigned int n) | 857 | adaptive_queue_set_max_active(struct OperationQueue *queue, unsigned int n) |
858 | { | 858 | { |
859 | struct FeedbackCtx *fctx = queue->fctx; | 859 | struct FeedbackCtx *fctx = queue->fctx; |
860 | struct TimeSlot *tslot; | 860 | struct TimeSlot *tslot; |
861 | unsigned int cnt; | 861 | unsigned int cnt; |
862 | 862 | ||
863 | cleanup_tslots (queue); | 863 | cleanup_tslots(queue); |
864 | n = GNUNET_MIN (n ,fctx->max_active_bound); | 864 | n = GNUNET_MIN(n, fctx->max_active_bound); |
865 | fctx->tslots_freeptr = GNUNET_malloc (n * sizeof (struct TimeSlot)); | 865 | fctx->tslots_freeptr = GNUNET_malloc(n * sizeof(struct TimeSlot)); |
866 | fctx->nfailed = 0; | 866 | fctx->nfailed = 0; |
867 | for (cnt = 0; cnt < n; cnt++) | 867 | for (cnt = 0; cnt < n; cnt++) |
868 | { | 868 | { |
869 | tslot = &fctx->tslots_freeptr[cnt]; | 869 | tslot = &fctx->tslots_freeptr[cnt]; |
870 | tslot->queue = queue; | 870 | tslot->queue = queue; |
871 | GNUNET_CONTAINER_DLL_insert_tail (fctx->alloc_head, fctx->alloc_tail, tslot); | 871 | GNUNET_CONTAINER_DLL_insert_tail(fctx->alloc_head, fctx->alloc_tail, tslot); |
872 | } | 872 | } |
873 | GNUNET_TESTBED_operation_queue_reset_max_active_ (queue, n); | 873 | GNUNET_TESTBED_operation_queue_reset_max_active_(queue, n); |
874 | } | 874 | } |
875 | 875 | ||
876 | 876 | ||
@@ -881,7 +881,7 @@ adaptive_queue_set_max_active (struct OperationQueue *queue, unsigned int n) | |||
881 | * @param queue the queue | 881 | * @param queue the queue |
882 | */ | 882 | */ |
883 | static void | 883 | static void |
884 | adapt_parallelism (struct OperationQueue *queue) | 884 | adapt_parallelism(struct OperationQueue *queue) |
885 | { | 885 | { |
886 | struct GNUNET_TIME_Relative avg; | 886 | struct GNUNET_TIME_Relative avg; |
887 | struct FeedbackCtx *fctx; | 887 | struct FeedbackCtx *fctx; |
@@ -895,32 +895,32 @@ adapt_parallelism (struct OperationQueue *queue) | |||
895 | nvals = 0; | 895 | nvals = 0; |
896 | fctx = queue->fctx; | 896 | fctx = queue->fctx; |
897 | for (cnt = 0; cnt < queue->max_active; cnt++) | 897 | for (cnt = 0; cnt < queue->max_active; cnt++) |
898 | { | 898 | { |
899 | tslot = &fctx->tslots_freeptr[cnt]; | 899 | tslot = &fctx->tslots_freeptr[cnt]; |
900 | avg = GNUNET_TIME_relative_add (avg, tslot->tsum); | 900 | avg = GNUNET_TIME_relative_add(avg, tslot->tsum); |
901 | nvals += tslot->nvals; | 901 | nvals += tslot->nvals; |
902 | } | 902 | } |
903 | GNUNET_assert (nvals >= queue->max_active); | 903 | GNUNET_assert(nvals >= queue->max_active); |
904 | GNUNET_assert (fctx->nfailed <= nvals); | 904 | GNUNET_assert(fctx->nfailed <= nvals); |
905 | nvals -= fctx->nfailed; | 905 | nvals -= fctx->nfailed; |
906 | if (0 == nvals) | 906 | if (0 == nvals) |
907 | { | 907 | { |
908 | if (1 == queue->max_active) | 908 | if (1 == queue->max_active) |
909 | adaptive_queue_set_max_active (queue, 1); | 909 | adaptive_queue_set_max_active(queue, 1); |
910 | else | 910 | else |
911 | adaptive_queue_set_max_active (queue, queue->max_active / 2); | 911 | adaptive_queue_set_max_active(queue, queue->max_active / 2); |
912 | return; | 912 | return; |
913 | } | 913 | } |
914 | avg = GNUNET_TIME_relative_divide (avg, nvals); | 914 | avg = GNUNET_TIME_relative_divide(avg, nvals); |
915 | GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us); | 915 | GNUNET_TESTBED_SD_add_data_(fctx->sd, (unsigned int)avg.rel_value_us); |
916 | if (GNUNET_SYSERR == | 916 | if (GNUNET_SYSERR == |
917 | GNUNET_TESTBED_SD_deviation_factor_ (fctx->sd, | 917 | GNUNET_TESTBED_SD_deviation_factor_(fctx->sd, |
918 | (unsigned int) avg.rel_value_us, | 918 | (unsigned int)avg.rel_value_us, |
919 | &sd)) | 919 | &sd)) |
920 | { | 920 | { |
921 | adaptive_queue_set_max_active (queue, queue->max_active); /* no change */ | 921 | adaptive_queue_set_max_active(queue, queue->max_active); /* no change */ |
922 | return; | 922 | return; |
923 | } | 923 | } |
924 | 924 | ||
925 | parallelism = 0; | 925 | parallelism = 0; |
926 | if (-1 == sd) | 926 | if (-1 == sd) |
@@ -931,36 +931,36 @@ adapt_parallelism (struct OperationQueue *queue) | |||
931 | parallelism = queue->max_active - 1; | 931 | parallelism = queue->max_active - 1; |
932 | if (2 <= sd) | 932 | if (2 <= sd) |
933 | parallelism = queue->max_active / 2; | 933 | parallelism = queue->max_active / 2; |
934 | parallelism = GNUNET_MAX (parallelism, ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE); | 934 | parallelism = GNUNET_MAX(parallelism, ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE); |
935 | adaptive_queue_set_max_active (queue, parallelism); | 935 | adaptive_queue_set_max_active(queue, parallelism); |
936 | 936 | ||
937 | #if 0 | 937 | #if 0 |
938 | /* old algorithm */ | 938 | /* old algorithm */ |
939 | if (sd < 0) | 939 | if (sd < 0) |
940 | sd = 0; | 940 | sd = 0; |
941 | GNUNET_assert (0 <= sd); | 941 | GNUNET_assert(0 <= sd); |
942 | //GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us); | 942 | //GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us); |
943 | if (0 == sd) | 943 | if (0 == sd) |
944 | { | 944 | { |
945 | adaptive_queue_set_max_active (queue, queue->max_active * 2); | 945 | adaptive_queue_set_max_active(queue, queue->max_active * 2); |
946 | return; | 946 | return; |
947 | } | 947 | } |
948 | if (1 == sd) | 948 | if (1 == sd) |
949 | { | 949 | { |
950 | adaptive_queue_set_max_active (queue, queue->max_active + 1); | 950 | adaptive_queue_set_max_active(queue, queue->max_active + 1); |
951 | return; | 951 | return; |
952 | } | 952 | } |
953 | if (1 == queue->max_active) | 953 | if (1 == queue->max_active) |
954 | { | 954 | { |
955 | adaptive_queue_set_max_active (queue, 1); | 955 | adaptive_queue_set_max_active(queue, 1); |
956 | return; | 956 | return; |
957 | } | 957 | } |
958 | if (2 == sd) | 958 | if (2 == sd) |
959 | { | 959 | { |
960 | adaptive_queue_set_max_active (queue, queue->max_active - 1); | 960 | adaptive_queue_set_max_active(queue, queue->max_active - 1); |
961 | return; | 961 | return; |
962 | } | 962 | } |
963 | adaptive_queue_set_max_active (queue, queue->max_active / 2); | 963 | adaptive_queue_set_max_active(queue, queue->max_active / 2); |
964 | #endif | 964 | #endif |
965 | } | 965 | } |
966 | 966 | ||
@@ -973,7 +973,7 @@ adapt_parallelism (struct OperationQueue *queue) | |||
973 | * @param op the operation | 973 | * @param op the operation |
974 | */ | 974 | */ |
975 | static void | 975 | static void |
976 | update_tslots (struct GNUNET_TESTBED_Operation *op) | 976 | update_tslots(struct GNUNET_TESTBED_Operation *op) |
977 | { | 977 | { |
978 | struct OperationQueue *queue; | 978 | struct OperationQueue *queue; |
979 | struct GNUNET_TIME_Relative t; | 979 | struct GNUNET_TIME_Relative t; |
@@ -981,31 +981,31 @@ update_tslots (struct GNUNET_TESTBED_Operation *op) | |||
981 | struct FeedbackCtx *fctx; | 981 | struct FeedbackCtx *fctx; |
982 | unsigned int i; | 982 | unsigned int i; |
983 | 983 | ||
984 | t = GNUNET_TIME_absolute_get_duration (op->tstart); | 984 | t = GNUNET_TIME_absolute_get_duration(op->tstart); |
985 | while (NULL != (tslot = op->tslots_head)) /* update time slots */ | 985 | while (NULL != (tslot = op->tslots_head)) /* update time slots */ |
986 | { | ||
987 | queue = tslot->queue; | ||
988 | fctx = queue->fctx; | ||
989 | GNUNET_CONTAINER_DLL_remove (op->tslots_head, op->tslots_tail, tslot); | ||
990 | tslot->op = NULL; | ||
991 | GNUNET_CONTAINER_DLL_insert_tail (fctx->alloc_head, fctx->alloc_tail, | ||
992 | tslot); | ||
993 | if (op->failed) | ||
994 | { | 986 | { |
995 | fctx->nfailed++; | 987 | queue = tslot->queue; |
996 | for (i = 0; i < op->nqueues; i++) | 988 | fctx = queue->fctx; |
997 | if (queue == op->queues[i]) | 989 | GNUNET_CONTAINER_DLL_remove(op->tslots_head, op->tslots_tail, tslot); |
998 | break; | 990 | tslot->op = NULL; |
999 | GNUNET_assert (i != op->nqueues); | 991 | GNUNET_CONTAINER_DLL_insert_tail(fctx->alloc_head, fctx->alloc_tail, |
1000 | op->queues[i]->overload += op->nres[i]; | 992 | tslot); |
993 | if (op->failed) | ||
994 | { | ||
995 | fctx->nfailed++; | ||
996 | for (i = 0; i < op->nqueues; i++) | ||
997 | if (queue == op->queues[i]) | ||
998 | break; | ||
999 | GNUNET_assert(i != op->nqueues); | ||
1000 | op->queues[i]->overload += op->nres[i]; | ||
1001 | } | ||
1002 | tslot->tsum = GNUNET_TIME_relative_add(tslot->tsum, t); | ||
1003 | if (0 != tslot->nvals++) | ||
1004 | continue; | ||
1005 | fctx->tslots_filled++; | ||
1006 | if (queue->max_active == fctx->tslots_filled) | ||
1007 | adapt_parallelism(queue); | ||
1001 | } | 1008 | } |
1002 | tslot->tsum = GNUNET_TIME_relative_add (tslot->tsum, t); | ||
1003 | if (0 != tslot->nvals++) | ||
1004 | continue; | ||
1005 | fctx->tslots_filled++; | ||
1006 | if (queue->max_active == fctx->tslots_filled) | ||
1007 | adapt_parallelism (queue); | ||
1008 | } | ||
1009 | } | 1009 | } |
1010 | 1010 | ||
1011 | 1011 | ||
@@ -1018,12 +1018,12 @@ update_tslots (struct GNUNET_TESTBED_Operation *op) | |||
1018 | * @return handle to the operation | 1018 | * @return handle to the operation |
1019 | */ | 1019 | */ |
1020 | struct GNUNET_TESTBED_Operation * | 1020 | struct GNUNET_TESTBED_Operation * |
1021 | GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start, | 1021 | GNUNET_TESTBED_operation_create_(void *cls, OperationStart start, |
1022 | OperationRelease release) | 1022 | OperationRelease release) |
1023 | { | 1023 | { |
1024 | struct GNUNET_TESTBED_Operation *op; | 1024 | struct GNUNET_TESTBED_Operation *op; |
1025 | 1025 | ||
1026 | op = GNUNET_new (struct GNUNET_TESTBED_Operation); | 1026 | op = GNUNET_new(struct GNUNET_TESTBED_Operation); |
1027 | op->start = start; | 1027 | op->start = start; |
1028 | op->state = OP_STATE_INIT; | 1028 | op->state = OP_STATE_INIT; |
1029 | op->release = release; | 1029 | op->release = release; |
@@ -1041,26 +1041,26 @@ GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start, | |||
1041 | * @return handle to the queue | 1041 | * @return handle to the queue |
1042 | */ | 1042 | */ |
1043 | struct OperationQueue * | 1043 | struct OperationQueue * |
1044 | GNUNET_TESTBED_operation_queue_create_ (enum OperationQueueType type, | 1044 | GNUNET_TESTBED_operation_queue_create_(enum OperationQueueType type, |
1045 | unsigned int max_active) | 1045 | unsigned int max_active) |
1046 | { | 1046 | { |
1047 | struct OperationQueue *queue; | 1047 | struct OperationQueue *queue; |
1048 | struct FeedbackCtx *fctx; | 1048 | struct FeedbackCtx *fctx; |
1049 | 1049 | ||
1050 | queue = GNUNET_new (struct OperationQueue); | 1050 | queue = GNUNET_new(struct OperationQueue); |
1051 | queue->type = type; | 1051 | queue->type = type; |
1052 | if (OPERATION_QUEUE_TYPE_FIXED == type) | 1052 | if (OPERATION_QUEUE_TYPE_FIXED == type) |
1053 | { | 1053 | { |
1054 | queue->max_active = max_active; | 1054 | queue->max_active = max_active; |
1055 | } | 1055 | } |
1056 | else | 1056 | else |
1057 | { | 1057 | { |
1058 | fctx = GNUNET_new (struct FeedbackCtx); | 1058 | fctx = GNUNET_new(struct FeedbackCtx); |
1059 | fctx->max_active_bound = max_active; | 1059 | fctx->max_active_bound = max_active; |
1060 | fctx->sd = GNUNET_TESTBED_SD_init_ (ADAPTIVE_QUEUE_DEFAULT_HISTORY); | 1060 | fctx->sd = GNUNET_TESTBED_SD_init_(ADAPTIVE_QUEUE_DEFAULT_HISTORY); |
1061 | queue->fctx = fctx; | 1061 | queue->fctx = fctx; |
1062 | adaptive_queue_set_max_active (queue, ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE); | 1062 | adaptive_queue_set_max_active(queue, ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE); |
1063 | } | 1063 | } |
1064 | return queue; | 1064 | return queue; |
1065 | } | 1065 | } |
1066 | 1066 | ||
@@ -1071,18 +1071,18 @@ GNUNET_TESTBED_operation_queue_create_ (enum OperationQueueType type, | |||
1071 | * @param queue the operation queue to destroy | 1071 | * @param queue the operation queue to destroy |
1072 | */ | 1072 | */ |
1073 | static void | 1073 | static void |
1074 | queue_destroy (struct OperationQueue *queue) | 1074 | queue_destroy(struct OperationQueue *queue) |
1075 | { | 1075 | { |
1076 | struct FeedbackCtx *fctx; | 1076 | struct FeedbackCtx *fctx; |
1077 | 1077 | ||
1078 | if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type) | 1078 | if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type) |
1079 | { | 1079 | { |
1080 | cleanup_tslots (queue); | 1080 | cleanup_tslots(queue); |
1081 | fctx = queue->fctx; | 1081 | fctx = queue->fctx; |
1082 | GNUNET_TESTBED_SD_destroy_ (fctx->sd); | 1082 | GNUNET_TESTBED_SD_destroy_(fctx->sd); |
1083 | GNUNET_free (fctx); | 1083 | GNUNET_free(fctx); |
1084 | } | 1084 | } |
1085 | GNUNET_free (queue); | 1085 | GNUNET_free(queue); |
1086 | } | 1086 | } |
1087 | 1087 | ||
1088 | 1088 | ||
@@ -1094,16 +1094,16 @@ queue_destroy (struct OperationQueue *queue) | |||
1094 | * @param queue queue to destroy | 1094 | * @param queue queue to destroy |
1095 | */ | 1095 | */ |
1096 | void | 1096 | void |
1097 | GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue) | 1097 | GNUNET_TESTBED_operation_queue_destroy_(struct OperationQueue *queue) |
1098 | { | 1098 | { |
1099 | if (GNUNET_YES != is_queue_empty (queue)) | 1099 | if (GNUNET_YES != is_queue_empty(queue)) |
1100 | { | 1100 | { |
1101 | GNUNET_assert (0 == queue->expired); /* Are you calling twice on same queue? */ | 1101 | GNUNET_assert(0 == queue->expired); /* Are you calling twice on same queue? */ |
1102 | queue->expired = 1; | 1102 | queue->expired = 1; |
1103 | GNUNET_array_append (expired_opqs, n_expired_opqs, queue); | 1103 | GNUNET_array_append(expired_opqs, n_expired_opqs, queue); |
1104 | return; | 1104 | return; |
1105 | } | 1105 | } |
1106 | queue_destroy (queue); | 1106 | queue_destroy(queue); |
1107 | } | 1107 | } |
1108 | 1108 | ||
1109 | 1109 | ||
@@ -1115,11 +1115,11 @@ GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue) | |||
1115 | * is not empty) | 1115 | * is not empty) |
1116 | */ | 1116 | */ |
1117 | int | 1117 | int |
1118 | GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue) | 1118 | GNUNET_TESTBED_operation_queue_destroy_empty_(struct OperationQueue *queue) |
1119 | { | 1119 | { |
1120 | if (GNUNET_NO == is_queue_empty (queue)) | 1120 | if (GNUNET_NO == is_queue_empty(queue)) |
1121 | return GNUNET_NO; | 1121 | return GNUNET_NO; |
1122 | GNUNET_TESTBED_operation_queue_destroy_ (queue); | 1122 | GNUNET_TESTBED_operation_queue_destroy_(queue); |
1123 | return GNUNET_YES; | 1123 | return GNUNET_YES; |
1124 | } | 1124 | } |
1125 | 1125 | ||
@@ -1131,19 +1131,19 @@ GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue) | |||
1131 | * @param opq the operation queue | 1131 | * @param opq the operation queue |
1132 | */ | 1132 | */ |
1133 | static void | 1133 | static void |
1134 | recheck_waiting (struct OperationQueue *opq) | 1134 | recheck_waiting(struct OperationQueue *opq) |
1135 | { | 1135 | { |
1136 | struct QueueEntry *entry; | 1136 | struct QueueEntry *entry; |
1137 | struct QueueEntry *entry2; | 1137 | struct QueueEntry *entry2; |
1138 | 1138 | ||
1139 | entry = opq->wq_head; | 1139 | entry = opq->wq_head; |
1140 | while (NULL != entry) | 1140 | while (NULL != entry) |
1141 | { | 1141 | { |
1142 | entry2 = entry->next; | 1142 | entry2 = entry->next; |
1143 | if (GNUNET_NO == check_readiness (entry->op)) | 1143 | if (GNUNET_NO == check_readiness(entry->op)) |
1144 | break; | 1144 | break; |
1145 | entry = entry2; | 1145 | entry = entry2; |
1146 | } | 1146 | } |
1147 | } | 1147 | } |
1148 | 1148 | ||
1149 | 1149 | ||
@@ -1156,17 +1156,17 @@ recheck_waiting (struct OperationQueue *opq) | |||
1156 | * @param max_active the new maximum number of active operations | 1156 | * @param max_active the new maximum number of active operations |
1157 | */ | 1157 | */ |
1158 | void | 1158 | void |
1159 | GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue, | 1159 | GNUNET_TESTBED_operation_queue_reset_max_active_(struct OperationQueue *queue, |
1160 | unsigned int max_active) | 1160 | unsigned int max_active) |
1161 | { | 1161 | { |
1162 | struct QueueEntry *entry; | 1162 | struct QueueEntry *entry; |
1163 | 1163 | ||
1164 | queue->max_active = max_active; | 1164 | queue->max_active = max_active; |
1165 | queue->overload = 0; | 1165 | queue->overload = 0; |
1166 | while ( (queue->active > queue->max_active) | 1166 | while ((queue->active > queue->max_active) |
1167 | && (NULL != (entry = queue->rq_head)) ) | 1167 | && (NULL != (entry = queue->rq_head))) |
1168 | defer (entry->op); | 1168 | defer(entry->op); |
1169 | recheck_waiting (queue); | 1169 | recheck_waiting(queue); |
1170 | } | 1170 | } |
1171 | 1171 | ||
1172 | 1172 | ||
@@ -1182,17 +1182,17 @@ GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue, | |||
1182 | * operation. Should be greater than 0. | 1182 | * operation. Should be greater than 0. |
1183 | */ | 1183 | */ |
1184 | void | 1184 | void |
1185 | GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue, | 1185 | GNUNET_TESTBED_operation_queue_insert2_(struct OperationQueue *queue, |
1186 | struct GNUNET_TESTBED_Operation *op, | 1186 | struct GNUNET_TESTBED_Operation *op, |
1187 | unsigned int nres) | 1187 | unsigned int nres) |
1188 | { | 1188 | { |
1189 | unsigned int qsize; | 1189 | unsigned int qsize; |
1190 | 1190 | ||
1191 | GNUNET_assert (0 < nres); | 1191 | GNUNET_assert(0 < nres); |
1192 | qsize = op->nqueues; | 1192 | qsize = op->nqueues; |
1193 | GNUNET_array_append (op->queues, op->nqueues, queue); | 1193 | GNUNET_array_append(op->queues, op->nqueues, queue); |
1194 | GNUNET_array_append (op->nres, qsize, nres); | 1194 | GNUNET_array_append(op->nres, qsize, nres); |
1195 | GNUNET_assert (qsize == op->nqueues); | 1195 | GNUNET_assert(qsize == op->nqueues); |
1196 | } | 1196 | } |
1197 | 1197 | ||
1198 | 1198 | ||
@@ -1208,10 +1208,10 @@ GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue, | |||
1208 | * @param op operation to add to the queue | 1208 | * @param op operation to add to the queue |
1209 | */ | 1209 | */ |
1210 | void | 1210 | void |
1211 | GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue, | 1211 | GNUNET_TESTBED_operation_queue_insert_(struct OperationQueue *queue, |
1212 | struct GNUNET_TESTBED_Operation *op) | 1212 | struct GNUNET_TESTBED_Operation *op) |
1213 | { | 1213 | { |
1214 | return GNUNET_TESTBED_operation_queue_insert2_ (queue, op, 1); | 1214 | return GNUNET_TESTBED_operation_queue_insert2_(queue, op, 1); |
1215 | } | 1215 | } |
1216 | 1216 | ||
1217 | 1217 | ||
@@ -1225,11 +1225,11 @@ GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue, | |||
1225 | * @param op the operation to marks as waiting | 1225 | * @param op the operation to marks as waiting |
1226 | */ | 1226 | */ |
1227 | void | 1227 | void |
1228 | GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation *op) | 1228 | GNUNET_TESTBED_operation_begin_wait_(struct GNUNET_TESTBED_Operation *op) |
1229 | { | 1229 | { |
1230 | GNUNET_assert (NULL == op->rq_entry); | 1230 | GNUNET_assert(NULL == op->rq_entry); |
1231 | change_state (op, OP_STATE_WAITING); | 1231 | change_state(op, OP_STATE_WAITING); |
1232 | (void) check_readiness (op); | 1232 | (void)check_readiness(op); |
1233 | } | 1233 | } |
1234 | 1234 | ||
1235 | 1235 | ||
@@ -1243,24 +1243,24 @@ GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation *op) | |||
1243 | * it as inactive. | 1243 | * it as inactive. |
1244 | */ | 1244 | */ |
1245 | void | 1245 | void |
1246 | GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op) | 1246 | GNUNET_TESTBED_operation_inactivate_(struct GNUNET_TESTBED_Operation *op) |
1247 | { | 1247 | { |
1248 | struct OperationQueue **queues; | 1248 | struct OperationQueue **queues; |
1249 | size_t ms; | 1249 | size_t ms; |
1250 | unsigned int nqueues; | 1250 | unsigned int nqueues; |
1251 | unsigned int i; | 1251 | unsigned int i; |
1252 | 1252 | ||
1253 | GNUNET_assert (OP_STATE_ACTIVE == op->state); | 1253 | GNUNET_assert(OP_STATE_ACTIVE == op->state); |
1254 | change_state (op, OP_STATE_INACTIVE); | 1254 | change_state(op, OP_STATE_INACTIVE); |
1255 | nqueues = op->nqueues; | 1255 | nqueues = op->nqueues; |
1256 | ms = sizeof (struct OperationQueue *) * nqueues; | 1256 | ms = sizeof(struct OperationQueue *) * nqueues; |
1257 | queues = GNUNET_malloc (ms); | 1257 | queues = GNUNET_malloc(ms); |
1258 | /* Cloning is needed as the operation be released by waiting operations and | 1258 | /* Cloning is needed as the operation be released by waiting operations and |
1259 | hence its nqueues memory ptr will be freed */ | 1259 | hence its nqueues memory ptr will be freed */ |
1260 | GNUNET_memcpy (queues, op->queues, ms); | 1260 | GNUNET_memcpy(queues, op->queues, ms); |
1261 | for (i = 0; i < nqueues; i++) | 1261 | for (i = 0; i < nqueues; i++) |
1262 | recheck_waiting (queues[i]); | 1262 | recheck_waiting(queues[i]); |
1263 | GNUNET_free (queues); | 1263 | GNUNET_free(queues); |
1264 | } | 1264 | } |
1265 | 1265 | ||
1266 | 1266 | ||
@@ -1272,11 +1272,10 @@ GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op) | |||
1272 | * @param op the operation to be marked as active | 1272 | * @param op the operation to be marked as active |
1273 | */ | 1273 | */ |
1274 | void | 1274 | void |
1275 | GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op) | 1275 | GNUNET_TESTBED_operation_activate_(struct GNUNET_TESTBED_Operation *op) |
1276 | { | 1276 | { |
1277 | 1277 | GNUNET_assert(OP_STATE_INACTIVE == op->state); | |
1278 | GNUNET_assert (OP_STATE_INACTIVE == op->state); | 1278 | change_state(op, OP_STATE_ACTIVE); |
1279 | change_state (op, OP_STATE_ACTIVE); | ||
1280 | } | 1279 | } |
1281 | 1280 | ||
1282 | 1281 | ||
@@ -1287,54 +1286,56 @@ GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op) | |||
1287 | * @param op operation that finished | 1286 | * @param op operation that finished |
1288 | */ | 1287 | */ |
1289 | void | 1288 | void |
1290 | GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op) | 1289 | GNUNET_TESTBED_operation_release_(struct GNUNET_TESTBED_Operation *op) |
1291 | { | 1290 | { |
1292 | struct QueueEntry *entry; | 1291 | struct QueueEntry *entry; |
1293 | struct OperationQueue *opq; | 1292 | struct OperationQueue *opq; |
1294 | unsigned int i; | 1293 | unsigned int i; |
1295 | 1294 | ||
1296 | if (OP_STATE_INIT == op->state) | 1295 | if (OP_STATE_INIT == op->state) |
1297 | { | 1296 | { |
1298 | GNUNET_free (op); | 1297 | GNUNET_free(op); |
1299 | return; | 1298 | return; |
1300 | } | 1299 | } |
1301 | if (OP_STATE_READY == op->state) | 1300 | if (OP_STATE_READY == op->state) |
1302 | rq_remove (op); | 1301 | rq_remove(op); |
1303 | if (OP_STATE_INACTIVE == op->state) /* Activate the operation if inactive */ | 1302 | if (OP_STATE_INACTIVE == op->state) /* Activate the operation if inactive */ |
1304 | GNUNET_TESTBED_operation_activate_ (op); | 1303 | GNUNET_TESTBED_operation_activate_(op); |
1305 | if (OP_STATE_ACTIVE == op->state) | 1304 | if (OP_STATE_ACTIVE == op->state) |
1306 | update_tslots (op); | 1305 | update_tslots(op); |
1307 | GNUNET_assert (NULL != op->queues); | 1306 | GNUNET_assert(NULL != op->queues); |
1308 | GNUNET_assert (NULL != op->qentries); | 1307 | GNUNET_assert(NULL != op->qentries); |
1309 | for (i = 0; i < op->nqueues; i++) | 1308 | for (i = 0; i < op->nqueues; i++) |
1310 | { | ||
1311 | entry = op->qentries[i]; | ||
1312 | remove_queue_entry (op, i); | ||
1313 | opq = op->queues[i]; | ||
1314 | switch (op->state) | ||
1315 | { | 1309 | { |
1316 | case OP_STATE_INIT: | 1310 | entry = op->qentries[i]; |
1317 | case OP_STATE_INACTIVE: | 1311 | remove_queue_entry(op, i); |
1318 | GNUNET_assert (0); | 1312 | opq = op->queues[i]; |
1319 | break; | 1313 | switch (op->state) |
1320 | case OP_STATE_WAITING: | 1314 | { |
1321 | break; | 1315 | case OP_STATE_INIT: |
1322 | case OP_STATE_ACTIVE: | 1316 | case OP_STATE_INACTIVE: |
1323 | case OP_STATE_READY: | 1317 | GNUNET_assert(0); |
1324 | GNUNET_assert (0 != opq->active); | 1318 | break; |
1325 | GNUNET_assert (opq->active >= entry->nres); | 1319 | |
1326 | opq->active -= entry->nres; | 1320 | case OP_STATE_WAITING: |
1327 | recheck_waiting (opq); | 1321 | break; |
1328 | break; | 1322 | |
1323 | case OP_STATE_ACTIVE: | ||
1324 | case OP_STATE_READY: | ||
1325 | GNUNET_assert(0 != opq->active); | ||
1326 | GNUNET_assert(opq->active >= entry->nres); | ||
1327 | opq->active -= entry->nres; | ||
1328 | recheck_waiting(opq); | ||
1329 | break; | ||
1330 | } | ||
1331 | GNUNET_free(entry); | ||
1329 | } | 1332 | } |
1330 | GNUNET_free (entry); | 1333 | GNUNET_free_non_null(op->qentries); |
1331 | } | 1334 | GNUNET_free(op->queues); |
1332 | GNUNET_free_non_null (op->qentries); | 1335 | GNUNET_free(op->nres); |
1333 | GNUNET_free (op->queues); | ||
1334 | GNUNET_free (op->nres); | ||
1335 | if (NULL != op->release) | 1336 | if (NULL != op->release) |
1336 | op->release (op->cb_cls); | 1337 | op->release(op->cb_cls); |
1337 | GNUNET_free (op); | 1338 | GNUNET_free(op); |
1338 | } | 1339 | } |
1339 | 1340 | ||
1340 | 1341 | ||
@@ -1344,7 +1345,7 @@ GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op) | |||
1344 | * @param op the operation to be marked as failed | 1345 | * @param op the operation to be marked as failed |
1345 | */ | 1346 | */ |
1346 | void | 1347 | void |
1347 | GNUNET_TESTBED_operation_mark_failed (struct GNUNET_TESTBED_Operation *op) | 1348 | GNUNET_TESTBED_operation_mark_failed(struct GNUNET_TESTBED_Operation *op) |
1348 | { | 1349 | { |
1349 | op->failed = GNUNET_YES; | 1350 | op->failed = GNUNET_YES; |
1350 | } | 1351 | } |
@@ -1355,24 +1356,23 @@ GNUNET_TESTBED_operation_mark_failed (struct GNUNET_TESTBED_Operation *op) | |||
1355 | * operations which are not completed and warn about them. | 1356 | * operations which are not completed and warn about them. |
1356 | */ | 1357 | */ |
1357 | void __attribute__ ((destructor)) | 1358 | void __attribute__ ((destructor)) |
1358 | GNUNET_TESTBED_operations_fini () | 1359 | GNUNET_TESTBED_operations_fini() |
1359 | { | 1360 | { |
1360 | struct OperationQueue *queue; | 1361 | struct OperationQueue *queue; |
1361 | unsigned int i; | 1362 | unsigned int i; |
1362 | int warn = 0; | 1363 | int warn = 0; |
1363 | 1364 | ||
1364 | for (i=0; i < n_expired_opqs; i++) | 1365 | for (i = 0; i < n_expired_opqs; i++) |
1365 | { | 1366 | { |
1366 | queue = expired_opqs[i]; | 1367 | queue = expired_opqs[i]; |
1367 | if (GNUNET_NO == is_queue_empty (queue)) | 1368 | if (GNUNET_NO == is_queue_empty(queue)) |
1368 | warn = 1; | 1369 | warn = 1; |
1369 | queue_destroy (queue); | 1370 | queue_destroy(queue); |
1370 | } | 1371 | } |
1371 | GNUNET_free_non_null (expired_opqs); | 1372 | GNUNET_free_non_null(expired_opqs); |
1372 | n_expired_opqs = 0; | 1373 | n_expired_opqs = 0; |
1373 | if (warn) | 1374 | if (warn) |
1374 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1375 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1375 | "Be disciplined. Some operations were not marked as done.\n"); | 1376 | "Be disciplined. Some operations were not marked as done.\n"); |
1376 | |||
1377 | } | 1377 | } |
1378 | /* end of testbed_api_operations.c */ | 1378 | /* end of testbed_api_operations.c */ |
diff --git a/src/testbed/testbed_api_operations.h b/src/testbed/testbed_api_operations.h index 28d64e8bb..fec518077 100644 --- a/src/testbed/testbed_api_operations.h +++ b/src/testbed/testbed_api_operations.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -40,8 +40,7 @@ struct OperationQueue; | |||
40 | /** | 40 | /** |
41 | * The type of operation queue | 41 | * The type of operation queue |
42 | */ | 42 | */ |
43 | enum OperationQueueType | 43 | enum OperationQueueType { |
44 | { | ||
45 | /** | 44 | /** |
46 | * Operation queue which permits a fixed maximum number of operations to be | 45 | * Operation queue which permits a fixed maximum number of operations to be |
47 | * active at any time | 46 | * active at any time |
@@ -65,8 +64,8 @@ enum OperationQueueType | |||
65 | * @return handle to the queue | 64 | * @return handle to the queue |
66 | */ | 65 | */ |
67 | struct OperationQueue * | 66 | struct OperationQueue * |
68 | GNUNET_TESTBED_operation_queue_create_ (enum OperationQueueType type, | 67 | GNUNET_TESTBED_operation_queue_create_(enum OperationQueueType type, |
69 | unsigned int max_active); | 68 | unsigned int max_active); |
70 | 69 | ||
71 | 70 | ||
72 | /** | 71 | /** |
@@ -76,7 +75,7 @@ GNUNET_TESTBED_operation_queue_create_ (enum OperationQueueType type, | |||
76 | * @param queue queue to destroy | 75 | * @param queue queue to destroy |
77 | */ | 76 | */ |
78 | void | 77 | void |
79 | GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue); | 78 | GNUNET_TESTBED_operation_queue_destroy_(struct OperationQueue *queue); |
80 | 79 | ||
81 | 80 | ||
82 | /** | 81 | /** |
@@ -87,7 +86,7 @@ GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue); | |||
87 | * is not empty) | 86 | * is not empty) |
88 | */ | 87 | */ |
89 | int | 88 | int |
90 | GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue); | 89 | GNUNET_TESTBED_operation_queue_destroy_empty_(struct OperationQueue *queue); |
91 | 90 | ||
92 | 91 | ||
93 | /** | 92 | /** |
@@ -99,8 +98,8 @@ GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue); | |||
99 | * @param max_active the new maximum number of active operations | 98 | * @param max_active the new maximum number of active operations |
100 | */ | 99 | */ |
101 | void | 100 | void |
102 | GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue, | 101 | GNUNET_TESTBED_operation_queue_reset_max_active_(struct OperationQueue *queue, |
103 | unsigned int max_active); | 102 | unsigned int max_active); |
104 | 103 | ||
105 | 104 | ||
106 | /** | 105 | /** |
@@ -115,9 +114,9 @@ GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue, | |||
115 | * operation. Should be greater than 0. | 114 | * operation. Should be greater than 0. |
116 | */ | 115 | */ |
117 | void | 116 | void |
118 | GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue, | 117 | GNUNET_TESTBED_operation_queue_insert2_(struct OperationQueue *queue, |
119 | struct GNUNET_TESTBED_Operation *op, | 118 | struct GNUNET_TESTBED_Operation *op, |
120 | unsigned int nres); | 119 | unsigned int nres); |
121 | 120 | ||
122 | 121 | ||
123 | /** | 122 | /** |
@@ -130,8 +129,8 @@ GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue, | |||
130 | * @param op operation to add to the queue | 129 | * @param op operation to add to the queue |
131 | */ | 130 | */ |
132 | void | 131 | void |
133 | GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue, | 132 | GNUNET_TESTBED_operation_queue_insert_(struct OperationQueue *queue, |
134 | struct GNUNET_TESTBED_Operation *op); | 133 | struct GNUNET_TESTBED_Operation *op); |
135 | 134 | ||
136 | 135 | ||
137 | /** | 136 | /** |
@@ -144,7 +143,7 @@ GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue, | |||
144 | * @param op the operation to marks as waiting | 143 | * @param op the operation to marks as waiting |
145 | */ | 144 | */ |
146 | void | 145 | void |
147 | GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation *op); | 146 | GNUNET_TESTBED_operation_begin_wait_(struct GNUNET_TESTBED_Operation *op); |
148 | 147 | ||
149 | 148 | ||
150 | /** | 149 | /** |
@@ -182,8 +181,8 @@ typedef void (*OperationRelease) (void *cls); | |||
182 | * @return handle to the operation | 181 | * @return handle to the operation |
183 | */ | 182 | */ |
184 | struct GNUNET_TESTBED_Operation * | 183 | struct GNUNET_TESTBED_Operation * |
185 | GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start, | 184 | GNUNET_TESTBED_operation_create_(void *cls, OperationStart start, |
186 | OperationRelease release); | 185 | OperationRelease release); |
187 | 186 | ||
188 | 187 | ||
189 | /** | 188 | /** |
@@ -193,7 +192,7 @@ GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start, | |||
193 | * @param op operation that finished | 192 | * @param op operation that finished |
194 | */ | 193 | */ |
195 | void | 194 | void |
196 | GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op); | 195 | GNUNET_TESTBED_operation_release_(struct GNUNET_TESTBED_Operation *op); |
197 | 196 | ||
198 | 197 | ||
199 | /** | 198 | /** |
@@ -206,7 +205,7 @@ GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op); | |||
206 | * it as inactive. | 205 | * it as inactive. |
207 | */ | 206 | */ |
208 | void | 207 | void |
209 | GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op); | 208 | GNUNET_TESTBED_operation_inactivate_(struct GNUNET_TESTBED_Operation *op); |
210 | 209 | ||
211 | 210 | ||
212 | /** | 211 | /** |
@@ -217,7 +216,7 @@ GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op); | |||
217 | * @param op the operation to be marked as active | 216 | * @param op the operation to be marked as active |
218 | */ | 217 | */ |
219 | void | 218 | void |
220 | GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op); | 219 | GNUNET_TESTBED_operation_activate_(struct GNUNET_TESTBED_Operation *op); |
221 | 220 | ||
222 | 221 | ||
223 | /** | 222 | /** |
@@ -226,7 +225,7 @@ GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op); | |||
226 | * @param op the operation to be marked as failed | 225 | * @param op the operation to be marked as failed |
227 | */ | 226 | */ |
228 | void | 227 | void |
229 | GNUNET_TESTBED_operation_mark_failed (struct GNUNET_TESTBED_Operation *op); | 228 | GNUNET_TESTBED_operation_mark_failed(struct GNUNET_TESTBED_Operation *op); |
230 | 229 | ||
231 | 230 | ||
232 | #endif | 231 | #endif |
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index 5b7820e39..78ed71a42 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -51,9 +51,9 @@ static struct GNUNET_TESTBED_Peer *peer_list_tail; | |||
51 | * @param peer the peer to add to the peer list | 51 | * @param peer the peer to add to the peer list |
52 | */ | 52 | */ |
53 | void | 53 | void |
54 | GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer) | 54 | GNUNET_TESTBED_peer_register_(struct GNUNET_TESTBED_Peer *peer) |
55 | { | 55 | { |
56 | GNUNET_CONTAINER_DLL_insert_tail (peer_list_head, peer_list_tail, peer); | 56 | GNUNET_CONTAINER_DLL_insert_tail(peer_list_head, peer_list_tail, peer); |
57 | } | 57 | } |
58 | 58 | ||
59 | 59 | ||
@@ -63,9 +63,9 @@ GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer) | |||
63 | * @param peer the peer to remove | 63 | * @param peer the peer to remove |
64 | */ | 64 | */ |
65 | void | 65 | void |
66 | GNUNET_TESTBED_peer_deregister_ (struct GNUNET_TESTBED_Peer *peer) | 66 | GNUNET_TESTBED_peer_deregister_(struct GNUNET_TESTBED_Peer *peer) |
67 | { | 67 | { |
68 | GNUNET_CONTAINER_DLL_remove (peer_list_head, peer_list_tail, peer); | 68 | GNUNET_CONTAINER_DLL_remove(peer_list_head, peer_list_tail, peer); |
69 | } | 69 | } |
70 | 70 | ||
71 | 71 | ||
@@ -73,15 +73,15 @@ GNUNET_TESTBED_peer_deregister_ (struct GNUNET_TESTBED_Peer *peer) | |||
73 | * Frees all peers | 73 | * Frees all peers |
74 | */ | 74 | */ |
75 | void | 75 | void |
76 | GNUNET_TESTBED_cleanup_peers_ (void) | 76 | GNUNET_TESTBED_cleanup_peers_(void) |
77 | { | 77 | { |
78 | struct GNUNET_TESTBED_Peer *peer; | 78 | struct GNUNET_TESTBED_Peer *peer; |
79 | 79 | ||
80 | while (NULL != (peer = peer_list_head)) | 80 | while (NULL != (peer = peer_list_head)) |
81 | { | 81 | { |
82 | GNUNET_TESTBED_peer_deregister_ (peer); | 82 | GNUNET_TESTBED_peer_deregister_(peer); |
83 | GNUNET_free (peer); | 83 | GNUNET_free(peer); |
84 | } | 84 | } |
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
@@ -94,7 +94,7 @@ GNUNET_TESTBED_cleanup_peers_ (void) | |||
94 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 94 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
95 | */ | 95 | */ |
96 | static void | 96 | static void |
97 | opstart_peer_create (void *cls) | 97 | opstart_peer_create(void *cls) |
98 | { | 98 | { |
99 | struct OperationContext *opc = cls; | 99 | struct OperationContext *opc = cls; |
100 | struct PeerCreateData *data = opc->data; | 100 | struct PeerCreateData *data = opc->data; |
@@ -105,30 +105,30 @@ opstart_peer_create (void *cls) | |||
105 | size_t c_size; | 105 | size_t c_size; |
106 | size_t xc_size; | 106 | size_t xc_size; |
107 | 107 | ||
108 | GNUNET_assert (OP_PEER_CREATE == opc->type); | 108 | GNUNET_assert(OP_PEER_CREATE == opc->type); |
109 | GNUNET_assert (NULL != data); | 109 | GNUNET_assert(NULL != data); |
110 | GNUNET_assert (NULL != data->peer); | 110 | GNUNET_assert(NULL != data->peer); |
111 | opc->state = OPC_STATE_STARTED; | 111 | opc->state = OPC_STATE_STARTED; |
112 | config = GNUNET_CONFIGURATION_serialize (data->cfg, | 112 | config = GNUNET_CONFIGURATION_serialize(data->cfg, |
113 | &c_size); | 113 | &c_size); |
114 | xc_size = GNUNET_TESTBED_compress_config_ (config, | 114 | xc_size = GNUNET_TESTBED_compress_config_(config, |
115 | c_size, | 115 | c_size, |
116 | &xconfig); | 116 | &xconfig); |
117 | GNUNET_free (config); | 117 | GNUNET_free(config); |
118 | env = GNUNET_MQ_msg_extra (msg, | 118 | env = GNUNET_MQ_msg_extra(msg, |
119 | xc_size, | 119 | xc_size, |
120 | GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER); | 120 | GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER); |
121 | msg->operation_id = GNUNET_htonll (opc->id); | 121 | msg->operation_id = GNUNET_htonll(opc->id); |
122 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->peer->host)); | 122 | msg->host_id = htonl(GNUNET_TESTBED_host_get_id_(data->peer->host)); |
123 | msg->peer_id = htonl (data->peer->unique_id); | 123 | msg->peer_id = htonl(data->peer->unique_id); |
124 | msg->config_size = htons ((uint16_t) c_size); | 124 | msg->config_size = htons((uint16_t)c_size); |
125 | GNUNET_memcpy (&msg[1], | 125 | GNUNET_memcpy(&msg[1], |
126 | xconfig, | 126 | xconfig, |
127 | xc_size); | 127 | xc_size); |
128 | GNUNET_MQ_send (opc->c->mq, | 128 | GNUNET_MQ_send(opc->c->mq, |
129 | env); | 129 | env); |
130 | GNUNET_free (xconfig); | 130 | GNUNET_free(xconfig); |
131 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | 131 | GNUNET_TESTBED_insert_opc_(opc->c, opc); |
132 | } | 132 | } |
133 | 133 | ||
134 | 134 | ||
@@ -138,23 +138,25 @@ opstart_peer_create (void *cls) | |||
138 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 138 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
139 | */ | 139 | */ |
140 | static void | 140 | static void |
141 | oprelease_peer_create (void *cls) | 141 | oprelease_peer_create(void *cls) |
142 | { | 142 | { |
143 | struct OperationContext *opc = cls; | 143 | struct OperationContext *opc = cls; |
144 | 144 | ||
145 | switch (opc->state) | 145 | switch (opc->state) |
146 | { | 146 | { |
147 | case OPC_STATE_STARTED: | 147 | case OPC_STATE_STARTED: |
148 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 148 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
149 | |||
149 | /* No break we continue flow */ | 150 | /* No break we continue flow */ |
150 | case OPC_STATE_INIT: | 151 | case OPC_STATE_INIT: |
151 | GNUNET_free (((struct PeerCreateData *) opc->data)->peer); | 152 | GNUNET_free(((struct PeerCreateData *)opc->data)->peer); |
152 | GNUNET_free (opc->data); | 153 | GNUNET_free(opc->data); |
153 | break; | 154 | break; |
154 | case OPC_STATE_FINISHED: | 155 | |
155 | break; | 156 | case OPC_STATE_FINISHED: |
156 | } | 157 | break; |
157 | GNUNET_free (opc); | 158 | } |
159 | GNUNET_free(opc); | ||
158 | } | 160 | } |
159 | 161 | ||
160 | 162 | ||
@@ -164,23 +166,23 @@ oprelease_peer_create (void *cls) | |||
164 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 166 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
165 | */ | 167 | */ |
166 | static void | 168 | static void |
167 | opstart_peer_destroy (void *cls) | 169 | opstart_peer_destroy(void *cls) |
168 | { | 170 | { |
169 | struct OperationContext *opc = cls; | 171 | struct OperationContext *opc = cls; |
170 | struct GNUNET_TESTBED_Peer *peer = opc->data; | 172 | struct GNUNET_TESTBED_Peer *peer = opc->data; |
171 | struct GNUNET_TESTBED_PeerDestroyMessage *msg; | 173 | struct GNUNET_TESTBED_PeerDestroyMessage *msg; |
172 | struct GNUNET_MQ_Envelope *env; | 174 | struct GNUNET_MQ_Envelope *env; |
173 | 175 | ||
174 | GNUNET_assert (OP_PEER_DESTROY == opc->type); | 176 | GNUNET_assert(OP_PEER_DESTROY == opc->type); |
175 | GNUNET_assert (NULL != peer); | 177 | GNUNET_assert(NULL != peer); |
176 | opc->state = OPC_STATE_STARTED; | 178 | opc->state = OPC_STATE_STARTED; |
177 | env = GNUNET_MQ_msg (msg, | 179 | env = GNUNET_MQ_msg(msg, |
178 | GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER); | 180 | GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER); |
179 | msg->peer_id = htonl (peer->unique_id); | 181 | msg->peer_id = htonl(peer->unique_id); |
180 | msg->operation_id = GNUNET_htonll (opc->id); | 182 | msg->operation_id = GNUNET_htonll(opc->id); |
181 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | 183 | GNUNET_TESTBED_insert_opc_(opc->c, opc); |
182 | GNUNET_MQ_send (peer->controller->mq, | 184 | GNUNET_MQ_send(peer->controller->mq, |
183 | env); | 185 | env); |
184 | } | 186 | } |
185 | 187 | ||
186 | 188 | ||
@@ -190,21 +192,23 @@ opstart_peer_destroy (void *cls) | |||
190 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 192 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
191 | */ | 193 | */ |
192 | static void | 194 | static void |
193 | oprelease_peer_destroy (void *cls) | 195 | oprelease_peer_destroy(void *cls) |
194 | { | 196 | { |
195 | struct OperationContext *opc = cls; | 197 | struct OperationContext *opc = cls; |
196 | 198 | ||
197 | switch (opc->state) | 199 | switch (opc->state) |
198 | { | 200 | { |
199 | case OPC_STATE_STARTED: | 201 | case OPC_STATE_STARTED: |
200 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 202 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
203 | |||
201 | /* no break; continue */ | 204 | /* no break; continue */ |
202 | case OPC_STATE_INIT: | 205 | case OPC_STATE_INIT: |
203 | break; | 206 | break; |
204 | case OPC_STATE_FINISHED: | 207 | |
205 | break; | 208 | case OPC_STATE_FINISHED: |
206 | } | 209 | break; |
207 | GNUNET_free (opc); | 210 | } |
211 | GNUNET_free(opc); | ||
208 | } | 212 | } |
209 | 213 | ||
210 | 214 | ||
@@ -214,7 +218,7 @@ oprelease_peer_destroy (void *cls) | |||
214 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 218 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
215 | */ | 219 | */ |
216 | static void | 220 | static void |
217 | opstart_peer_start (void *cls) | 221 | opstart_peer_start(void *cls) |
218 | { | 222 | { |
219 | struct OperationContext *opc = cls; | 223 | struct OperationContext *opc = cls; |
220 | struct GNUNET_TESTBED_PeerStartMessage *msg; | 224 | struct GNUNET_TESTBED_PeerStartMessage *msg; |
@@ -222,18 +226,18 @@ opstart_peer_start (void *cls) | |||
222 | struct PeerEventData *data; | 226 | struct PeerEventData *data; |
223 | struct GNUNET_TESTBED_Peer *peer; | 227 | struct GNUNET_TESTBED_Peer *peer; |
224 | 228 | ||
225 | GNUNET_assert (OP_PEER_START == opc->type); | 229 | GNUNET_assert(OP_PEER_START == opc->type); |
226 | GNUNET_assert (NULL != (data = opc->data)); | 230 | GNUNET_assert(NULL != (data = opc->data)); |
227 | GNUNET_assert (NULL != (peer = data->peer)); | 231 | GNUNET_assert(NULL != (peer = data->peer)); |
228 | GNUNET_assert ((TESTBED_PS_CREATED == peer->state) || (TESTBED_PS_STOPPED == peer->state)); | 232 | GNUNET_assert((TESTBED_PS_CREATED == peer->state) || (TESTBED_PS_STOPPED == peer->state)); |
229 | opc->state = OPC_STATE_STARTED; | 233 | opc->state = OPC_STATE_STARTED; |
230 | env = GNUNET_MQ_msg (msg, | 234 | env = GNUNET_MQ_msg(msg, |
231 | GNUNET_MESSAGE_TYPE_TESTBED_START_PEER); | 235 | GNUNET_MESSAGE_TYPE_TESTBED_START_PEER); |
232 | msg->peer_id = htonl (peer->unique_id); | 236 | msg->peer_id = htonl(peer->unique_id); |
233 | msg->operation_id = GNUNET_htonll (opc->id); | 237 | msg->operation_id = GNUNET_htonll(opc->id); |
234 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | 238 | GNUNET_TESTBED_insert_opc_(opc->c, opc); |
235 | GNUNET_MQ_send (peer->controller->mq, | 239 | GNUNET_MQ_send(peer->controller->mq, |
236 | env); | 240 | env); |
237 | } | 241 | } |
238 | 242 | ||
239 | 243 | ||
@@ -243,22 +247,24 @@ opstart_peer_start (void *cls) | |||
243 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 247 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
244 | */ | 248 | */ |
245 | static void | 249 | static void |
246 | oprelease_peer_start (void *cls) | 250 | oprelease_peer_start(void *cls) |
247 | { | 251 | { |
248 | struct OperationContext *opc = cls; | 252 | struct OperationContext *opc = cls; |
249 | 253 | ||
250 | switch (opc->state) | 254 | switch (opc->state) |
251 | { | 255 | { |
252 | case OPC_STATE_STARTED: | 256 | case OPC_STATE_STARTED: |
253 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 257 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
258 | |||
254 | /* no break; continue */ | 259 | /* no break; continue */ |
255 | case OPC_STATE_INIT: | 260 | case OPC_STATE_INIT: |
256 | GNUNET_free (opc->data); | 261 | GNUNET_free(opc->data); |
257 | break; | 262 | break; |
258 | case OPC_STATE_FINISHED: | 263 | |
259 | break; | 264 | case OPC_STATE_FINISHED: |
260 | } | 265 | break; |
261 | GNUNET_free (opc); | 266 | } |
267 | GNUNET_free(opc); | ||
262 | } | 268 | } |
263 | 269 | ||
264 | 270 | ||
@@ -268,7 +274,7 @@ oprelease_peer_start (void *cls) | |||
268 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 274 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
269 | */ | 275 | */ |
270 | static void | 276 | static void |
271 | opstart_peer_stop (void *cls) | 277 | opstart_peer_stop(void *cls) |
272 | { | 278 | { |
273 | struct OperationContext *opc = cls; | 279 | struct OperationContext *opc = cls; |
274 | struct GNUNET_TESTBED_PeerStopMessage *msg; | 280 | struct GNUNET_TESTBED_PeerStopMessage *msg; |
@@ -276,17 +282,17 @@ opstart_peer_stop (void *cls) | |||
276 | struct GNUNET_TESTBED_Peer *peer; | 282 | struct GNUNET_TESTBED_Peer *peer; |
277 | struct GNUNET_MQ_Envelope *env; | 283 | struct GNUNET_MQ_Envelope *env; |
278 | 284 | ||
279 | GNUNET_assert (NULL != (data = opc->data)); | 285 | GNUNET_assert(NULL != (data = opc->data)); |
280 | GNUNET_assert (NULL != (peer = data->peer)); | 286 | GNUNET_assert(NULL != (peer = data->peer)); |
281 | GNUNET_assert (TESTBED_PS_STARTED == peer->state); | 287 | GNUNET_assert(TESTBED_PS_STARTED == peer->state); |
282 | opc->state = OPC_STATE_STARTED; | 288 | opc->state = OPC_STATE_STARTED; |
283 | env = GNUNET_MQ_msg (msg, | 289 | env = GNUNET_MQ_msg(msg, |
284 | GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER); | 290 | GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER); |
285 | msg->peer_id = htonl (peer->unique_id); | 291 | msg->peer_id = htonl(peer->unique_id); |
286 | msg->operation_id = GNUNET_htonll (opc->id); | 292 | msg->operation_id = GNUNET_htonll(opc->id); |
287 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | 293 | GNUNET_TESTBED_insert_opc_(opc->c, opc); |
288 | GNUNET_MQ_send (peer->controller->mq, | 294 | GNUNET_MQ_send(peer->controller->mq, |
289 | env); | 295 | env); |
290 | } | 296 | } |
291 | 297 | ||
292 | 298 | ||
@@ -296,22 +302,24 @@ opstart_peer_stop (void *cls) | |||
296 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 302 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
297 | */ | 303 | */ |
298 | static void | 304 | static void |
299 | oprelease_peer_stop (void *cls) | 305 | oprelease_peer_stop(void *cls) |
300 | { | 306 | { |
301 | struct OperationContext *opc = cls; | 307 | struct OperationContext *opc = cls; |
302 | 308 | ||
303 | switch (opc->state) | 309 | switch (opc->state) |
304 | { | 310 | { |
305 | case OPC_STATE_STARTED: | 311 | case OPC_STATE_STARTED: |
306 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 312 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
313 | |||
307 | /* no break; continue */ | 314 | /* no break; continue */ |
308 | case OPC_STATE_INIT: | 315 | case OPC_STATE_INIT: |
309 | GNUNET_free (opc->data); | 316 | GNUNET_free(opc->data); |
310 | break; | 317 | break; |
311 | case OPC_STATE_FINISHED: | 318 | |
312 | break; | 319 | case OPC_STATE_FINISHED: |
313 | } | 320 | break; |
314 | GNUNET_free (opc); | 321 | } |
322 | GNUNET_free(opc); | ||
315 | } | 323 | } |
316 | 324 | ||
317 | 325 | ||
@@ -324,19 +332,19 @@ oprelease_peer_stop (void *cls) | |||
324 | * @return the PeerGetConfigurationMessage | 332 | * @return the PeerGetConfigurationMessage |
325 | */ | 333 | */ |
326 | struct GNUNET_TESTBED_PeerGetConfigurationMessage * | 334 | struct GNUNET_TESTBED_PeerGetConfigurationMessage * |
327 | GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id, | 335 | GNUNET_TESTBED_generate_peergetconfig_msg_(uint32_t peer_id, |
328 | uint64_t operation_id) | 336 | uint64_t operation_id) |
329 | { | 337 | { |
330 | struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; | 338 | struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; |
331 | 339 | ||
332 | msg = | 340 | msg = |
333 | GNUNET_malloc (sizeof | 341 | GNUNET_malloc(sizeof |
334 | (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); | 342 | (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); |
335 | msg->header.size = | 343 | msg->header.size = |
336 | htons (sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); | 344 | htons(sizeof(struct GNUNET_TESTBED_PeerGetConfigurationMessage)); |
337 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION); | 345 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION); |
338 | msg->peer_id = htonl (peer_id); | 346 | msg->peer_id = htonl(peer_id); |
339 | msg->operation_id = GNUNET_htonll (operation_id); | 347 | msg->operation_id = GNUNET_htonll(operation_id); |
340 | return msg; | 348 | return msg; |
341 | } | 349 | } |
342 | 350 | ||
@@ -347,19 +355,19 @@ GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id, | |||
347 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 355 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
348 | */ | 356 | */ |
349 | static void | 357 | static void |
350 | opstart_peer_getinfo (void *cls) | 358 | opstart_peer_getinfo(void *cls) |
351 | { | 359 | { |
352 | struct OperationContext *opc = cls; | 360 | struct OperationContext *opc = cls; |
353 | struct PeerInfoData *data = opc->data; | 361 | struct PeerInfoData *data = opc->data; |
354 | struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; | 362 | struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; |
355 | 363 | ||
356 | GNUNET_assert (NULL != data); | 364 | GNUNET_assert(NULL != data); |
357 | opc->state = OPC_STATE_STARTED; | 365 | opc->state = OPC_STATE_STARTED; |
358 | msg = | 366 | msg = |
359 | GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id, | 367 | GNUNET_TESTBED_generate_peergetconfig_msg_(data->peer->unique_id, |
360 | opc->id); | 368 | opc->id); |
361 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | 369 | GNUNET_TESTBED_insert_opc_(opc->c, opc); |
362 | GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); | 370 | GNUNET_TESTBED_queue_message_(opc->c, &msg->header); |
363 | } | 371 | } |
364 | 372 | ||
365 | 373 | ||
@@ -369,38 +377,42 @@ opstart_peer_getinfo (void *cls) | |||
369 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 377 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
370 | */ | 378 | */ |
371 | static void | 379 | static void |
372 | oprelease_peer_getinfo (void *cls) | 380 | oprelease_peer_getinfo(void *cls) |
373 | { | 381 | { |
374 | struct OperationContext *opc = cls; | 382 | struct OperationContext *opc = cls; |
375 | struct GNUNET_TESTBED_PeerInformation *data; | 383 | struct GNUNET_TESTBED_PeerInformation *data; |
376 | 384 | ||
377 | switch (opc->state) | 385 | switch (opc->state) |
378 | { | ||
379 | case OPC_STATE_STARTED: | ||
380 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | ||
381 | /* no break; continue */ | ||
382 | case OPC_STATE_INIT: | ||
383 | GNUNET_free (opc->data); | ||
384 | break; | ||
385 | case OPC_STATE_FINISHED: | ||
386 | data = opc->data; | ||
387 | GNUNET_assert (NULL != data); | ||
388 | switch (data->pit) | ||
389 | { | 386 | { |
390 | case GNUNET_TESTBED_PIT_CONFIGURATION: | 387 | case OPC_STATE_STARTED: |
391 | if (NULL != data->result.cfg) | 388 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
392 | GNUNET_CONFIGURATION_destroy (data->result.cfg); | 389 | |
390 | /* no break; continue */ | ||
391 | case OPC_STATE_INIT: | ||
392 | GNUNET_free(opc->data); | ||
393 | break; | 393 | break; |
394 | case GNUNET_TESTBED_PIT_IDENTITY: | 394 | |
395 | GNUNET_free (data->result.id); | 395 | case OPC_STATE_FINISHED: |
396 | data = opc->data; | ||
397 | GNUNET_assert(NULL != data); | ||
398 | switch (data->pit) | ||
399 | { | ||
400 | case GNUNET_TESTBED_PIT_CONFIGURATION: | ||
401 | if (NULL != data->result.cfg) | ||
402 | GNUNET_CONFIGURATION_destroy(data->result.cfg); | ||
403 | break; | ||
404 | |||
405 | case GNUNET_TESTBED_PIT_IDENTITY: | ||
406 | GNUNET_free(data->result.id); | ||
407 | break; | ||
408 | |||
409 | default: | ||
410 | GNUNET_assert(0); /* We should never reach here */ | ||
411 | } | ||
412 | GNUNET_free(data); | ||
396 | break; | 413 | break; |
397 | default: | ||
398 | GNUNET_assert (0); /* We should never reach here */ | ||
399 | } | 414 | } |
400 | GNUNET_free (data); | 415 | GNUNET_free(opc); |
401 | break; | ||
402 | } | ||
403 | GNUNET_free (opc); | ||
404 | } | 416 | } |
405 | 417 | ||
406 | 418 | ||
@@ -410,7 +422,7 @@ oprelease_peer_getinfo (void *cls) | |||
410 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 422 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
411 | */ | 423 | */ |
412 | static void | 424 | static void |
413 | opstart_overlay_connect (void *cls) | 425 | opstart_overlay_connect(void *cls) |
414 | { | 426 | { |
415 | struct OperationContext *opc = cls; | 427 | struct OperationContext *opc = cls; |
416 | struct GNUNET_MQ_Envelope *env; | 428 | struct GNUNET_MQ_Envelope *env; |
@@ -419,17 +431,17 @@ opstart_overlay_connect (void *cls) | |||
419 | 431 | ||
420 | opc->state = OPC_STATE_STARTED; | 432 | opc->state = OPC_STATE_STARTED; |
421 | data = opc->data; | 433 | data = opc->data; |
422 | GNUNET_assert (NULL != data); | 434 | GNUNET_assert(NULL != data); |
423 | env = GNUNET_MQ_msg (msg, | 435 | env = GNUNET_MQ_msg(msg, |
424 | GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT); | 436 | GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT); |
425 | msg->peer1 = htonl (data->p1->unique_id); | 437 | msg->peer1 = htonl(data->p1->unique_id); |
426 | msg->peer2 = htonl (data->p2->unique_id); | 438 | msg->peer2 = htonl(data->p2->unique_id); |
427 | msg->operation_id = GNUNET_htonll (opc->id); | 439 | msg->operation_id = GNUNET_htonll(opc->id); |
428 | msg->peer2_host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->p2->host)); | 440 | msg->peer2_host_id = htonl(GNUNET_TESTBED_host_get_id_(data->p2->host)); |
429 | GNUNET_TESTBED_insert_opc_ (opc->c, | 441 | GNUNET_TESTBED_insert_opc_(opc->c, |
430 | opc); | 442 | opc); |
431 | GNUNET_MQ_send (opc->c->mq, | 443 | GNUNET_MQ_send(opc->c->mq, |
432 | env); | 444 | env); |
433 | } | 445 | } |
434 | 446 | ||
435 | 447 | ||
@@ -439,24 +451,26 @@ opstart_overlay_connect (void *cls) | |||
439 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 451 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
440 | */ | 452 | */ |
441 | static void | 453 | static void |
442 | oprelease_overlay_connect (void *cls) | 454 | oprelease_overlay_connect(void *cls) |
443 | { | 455 | { |
444 | struct OperationContext *opc = cls; | 456 | struct OperationContext *opc = cls; |
445 | struct OverlayConnectData *data; | 457 | struct OverlayConnectData *data; |
446 | 458 | ||
447 | data = opc->data; | 459 | data = opc->data; |
448 | switch (opc->state) | 460 | switch (opc->state) |
449 | { | 461 | { |
450 | case OPC_STATE_INIT: | 462 | case OPC_STATE_INIT: |
451 | break; | 463 | break; |
452 | case OPC_STATE_STARTED: | 464 | |
453 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 465 | case OPC_STATE_STARTED: |
454 | break; | 466 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
455 | case OPC_STATE_FINISHED: | 467 | break; |
456 | break; | 468 | |
457 | } | 469 | case OPC_STATE_FINISHED: |
458 | GNUNET_free (data); | 470 | break; |
459 | GNUNET_free (opc); | 471 | } |
472 | GNUNET_free(data); | ||
473 | GNUNET_free(opc); | ||
460 | } | 474 | } |
461 | 475 | ||
462 | 476 | ||
@@ -466,7 +480,7 @@ oprelease_overlay_connect (void *cls) | |||
466 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 480 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
467 | */ | 481 | */ |
468 | static void | 482 | static void |
469 | opstart_peer_reconfigure (void *cls) | 483 | opstart_peer_reconfigure(void *cls) |
470 | { | 484 | { |
471 | struct OperationContext *opc = cls; | 485 | struct OperationContext *opc = cls; |
472 | struct PeerReconfigureData *data = opc->data; | 486 | struct PeerReconfigureData *data = opc->data; |
@@ -476,28 +490,28 @@ opstart_peer_reconfigure (void *cls) | |||
476 | size_t xc_size; | 490 | size_t xc_size; |
477 | 491 | ||
478 | opc->state = OPC_STATE_STARTED; | 492 | opc->state = OPC_STATE_STARTED; |
479 | GNUNET_assert (NULL != data); | 493 | GNUNET_assert(NULL != data); |
480 | xc_size = GNUNET_TESTBED_compress_config_ (data->config, | 494 | xc_size = GNUNET_TESTBED_compress_config_(data->config, |
481 | data->cfg_size, | 495 | data->cfg_size, |
482 | &xconfig); | 496 | &xconfig); |
483 | GNUNET_free (data->config); | 497 | GNUNET_free(data->config); |
484 | data->config = NULL; | 498 | data->config = NULL; |
485 | GNUNET_assert (xc_size < UINT16_MAX - sizeof (*msg)); | 499 | GNUNET_assert(xc_size < UINT16_MAX - sizeof(*msg)); |
486 | env = GNUNET_MQ_msg_extra (msg, | 500 | env = GNUNET_MQ_msg_extra(msg, |
487 | xc_size, | 501 | xc_size, |
488 | GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER); | 502 | GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER); |
489 | msg->peer_id = htonl (data->peer->unique_id); | 503 | msg->peer_id = htonl(data->peer->unique_id); |
490 | msg->operation_id = GNUNET_htonll (opc->id); | 504 | msg->operation_id = GNUNET_htonll(opc->id); |
491 | msg->config_size = htons (data->cfg_size); | 505 | msg->config_size = htons(data->cfg_size); |
492 | GNUNET_memcpy (&msg[1], | 506 | GNUNET_memcpy(&msg[1], |
493 | xconfig, | 507 | xconfig, |
494 | xc_size); | 508 | xc_size); |
495 | GNUNET_free (xconfig); | 509 | GNUNET_free(xconfig); |
496 | GNUNET_free (data); | 510 | GNUNET_free(data); |
497 | opc->data = NULL; | 511 | opc->data = NULL; |
498 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | 512 | GNUNET_TESTBED_insert_opc_(opc->c, opc); |
499 | GNUNET_MQ_send (opc->c->mq, | 513 | GNUNET_MQ_send(opc->c->mq, |
500 | env); | 514 | env); |
501 | } | 515 | } |
502 | 516 | ||
503 | 517 | ||
@@ -507,24 +521,26 @@ opstart_peer_reconfigure (void *cls) | |||
507 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 521 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
508 | */ | 522 | */ |
509 | static void | 523 | static void |
510 | oprelease_peer_reconfigure (void *cls) | 524 | oprelease_peer_reconfigure(void *cls) |
511 | { | 525 | { |
512 | struct OperationContext *opc = cls; | 526 | struct OperationContext *opc = cls; |
513 | struct PeerReconfigureData *data = opc->data; | 527 | struct PeerReconfigureData *data = opc->data; |
514 | 528 | ||
515 | switch (opc->state) | 529 | switch (opc->state) |
516 | { | 530 | { |
517 | case OPC_STATE_INIT: | 531 | case OPC_STATE_INIT: |
518 | GNUNET_free (data->config); | 532 | GNUNET_free(data->config); |
519 | GNUNET_free (data); | 533 | GNUNET_free(data); |
520 | break; | 534 | break; |
521 | case OPC_STATE_STARTED: | 535 | |
522 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 536 | case OPC_STATE_STARTED: |
523 | break; | 537 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
524 | case OPC_STATE_FINISHED: | 538 | break; |
525 | break; | 539 | |
526 | } | 540 | case OPC_STATE_FINISHED: |
527 | GNUNET_free (opc); | 541 | break; |
542 | } | ||
543 | GNUNET_free(opc); | ||
528 | } | 544 | } |
529 | 545 | ||
530 | 546 | ||
@@ -535,9 +551,9 @@ oprelease_peer_reconfigure (void *cls) | |||
535 | * @return handle to the host, NULL on error | 551 | * @return handle to the host, NULL on error |
536 | */ | 552 | */ |
537 | struct GNUNET_TESTBED_Peer * | 553 | struct GNUNET_TESTBED_Peer * |
538 | GNUNET_TESTBED_peer_lookup_by_id_ (uint32_t id) | 554 | GNUNET_TESTBED_peer_lookup_by_id_(uint32_t id) |
539 | { | 555 | { |
540 | GNUNET_break (0); | 556 | GNUNET_break(0); |
541 | return NULL; | 557 | return NULL; |
542 | } | 558 | } |
543 | 559 | ||
@@ -572,39 +588,38 @@ GNUNET_TESTBED_peer_lookup_by_id_ (uint32_t id) | |||
572 | * @return the operation handle | 588 | * @return the operation handle |
573 | */ | 589 | */ |
574 | struct GNUNET_TESTBED_Operation * | 590 | struct GNUNET_TESTBED_Operation * |
575 | GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller, | 591 | GNUNET_TESTBED_peer_create(struct GNUNET_TESTBED_Controller *controller, |
576 | struct GNUNET_TESTBED_Host *host, | 592 | struct GNUNET_TESTBED_Host *host, |
577 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 593 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
578 | GNUNET_TESTBED_PeerCreateCallback cb, void *cls) | 594 | GNUNET_TESTBED_PeerCreateCallback cb, void *cls) |
579 | { | 595 | { |
580 | |||
581 | struct GNUNET_TESTBED_Peer *peer; | 596 | struct GNUNET_TESTBED_Peer *peer; |
582 | struct PeerCreateData *data; | 597 | struct PeerCreateData *data; |
583 | struct OperationContext *opc; | 598 | struct OperationContext *opc; |
584 | static uint32_t id_gen; | 599 | static uint32_t id_gen; |
585 | 600 | ||
586 | peer = GNUNET_new (struct GNUNET_TESTBED_Peer); | 601 | peer = GNUNET_new(struct GNUNET_TESTBED_Peer); |
587 | peer->controller = controller; | 602 | peer->controller = controller; |
588 | peer->host = host; | 603 | peer->host = host; |
589 | peer->unique_id = id_gen++; | 604 | peer->unique_id = id_gen++; |
590 | peer->state = TESTBED_PS_INVALID; | 605 | peer->state = TESTBED_PS_INVALID; |
591 | data = GNUNET_new (struct PeerCreateData); | 606 | data = GNUNET_new(struct PeerCreateData); |
592 | data->host = host; | 607 | data->host = host; |
593 | data->cfg = cfg; | 608 | data->cfg = cfg; |
594 | data->cb = cb; | 609 | data->cb = cb; |
595 | data->cls = cls; | 610 | data->cls = cls; |
596 | data->peer = peer; | 611 | data->peer = peer; |
597 | opc = GNUNET_new (struct OperationContext); | 612 | opc = GNUNET_new(struct OperationContext); |
598 | opc->c = controller; | 613 | opc->c = controller; |
599 | opc->data = data; | 614 | opc->data = data; |
600 | opc->id = GNUNET_TESTBED_get_next_op_id (controller); | 615 | opc->id = GNUNET_TESTBED_get_next_op_id(controller); |
601 | opc->type = OP_PEER_CREATE; | 616 | opc->type = OP_PEER_CREATE; |
602 | opc->op = | 617 | opc->op = |
603 | GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_create, | 618 | GNUNET_TESTBED_operation_create_(opc, &opstart_peer_create, |
604 | &oprelease_peer_create); | 619 | &oprelease_peer_create); |
605 | GNUNET_TESTBED_operation_queue_insert_ (controller->opq_parallel_operations, | 620 | GNUNET_TESTBED_operation_queue_insert_(controller->opq_parallel_operations, |
606 | opc->op); | 621 | opc->op); |
607 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | 622 | GNUNET_TESTBED_operation_begin_wait_(opc->op); |
608 | return opc->op; | 623 | return opc->op; |
609 | } | 624 | } |
610 | 625 | ||
@@ -620,28 +635,28 @@ GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller, | |||
620 | * @return handle to the operation | 635 | * @return handle to the operation |
621 | */ | 636 | */ |
622 | struct GNUNET_TESTBED_Operation * | 637 | struct GNUNET_TESTBED_Operation * |
623 | GNUNET_TESTBED_peer_start (void *op_cls, struct GNUNET_TESTBED_Peer *peer, | 638 | GNUNET_TESTBED_peer_start(void *op_cls, struct GNUNET_TESTBED_Peer *peer, |
624 | GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls) | 639 | GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls) |
625 | { | 640 | { |
626 | struct OperationContext *opc; | 641 | struct OperationContext *opc; |
627 | struct PeerEventData *data; | 642 | struct PeerEventData *data; |
628 | 643 | ||
629 | data = GNUNET_new (struct PeerEventData); | 644 | data = GNUNET_new(struct PeerEventData); |
630 | data->peer = peer; | 645 | data->peer = peer; |
631 | data->pcc = pcc; | 646 | data->pcc = pcc; |
632 | data->pcc_cls = pcc_cls; | 647 | data->pcc_cls = pcc_cls; |
633 | opc = GNUNET_new (struct OperationContext); | 648 | opc = GNUNET_new(struct OperationContext); |
634 | opc->c = peer->controller; | 649 | opc->c = peer->controller; |
635 | opc->data = data; | 650 | opc->data = data; |
636 | opc->op_cls = op_cls; | 651 | opc->op_cls = op_cls; |
637 | opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); | 652 | opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); |
638 | opc->type = OP_PEER_START; | 653 | opc->type = OP_PEER_START; |
639 | opc->op = | 654 | opc->op = |
640 | GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_start, | 655 | GNUNET_TESTBED_operation_create_(opc, &opstart_peer_start, |
641 | &oprelease_peer_start); | 656 | &oprelease_peer_start); |
642 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, | 657 | GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, |
643 | opc->op); | 658 | opc->op); |
644 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | 659 | GNUNET_TESTBED_operation_begin_wait_(opc->op); |
645 | return opc->op; | 660 | return opc->op; |
646 | } | 661 | } |
647 | 662 | ||
@@ -659,29 +674,29 @@ GNUNET_TESTBED_peer_start (void *op_cls, struct GNUNET_TESTBED_Peer *peer, | |||
659 | * @return handle to the operation | 674 | * @return handle to the operation |
660 | */ | 675 | */ |
661 | struct GNUNET_TESTBED_Operation * | 676 | struct GNUNET_TESTBED_Operation * |
662 | GNUNET_TESTBED_peer_stop (void *op_cls, | 677 | GNUNET_TESTBED_peer_stop(void *op_cls, |
663 | struct GNUNET_TESTBED_Peer *peer, | 678 | struct GNUNET_TESTBED_Peer *peer, |
664 | GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls) | 679 | GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls) |
665 | { | 680 | { |
666 | struct OperationContext *opc; | 681 | struct OperationContext *opc; |
667 | struct PeerEventData *data; | 682 | struct PeerEventData *data; |
668 | 683 | ||
669 | data = GNUNET_new (struct PeerEventData); | 684 | data = GNUNET_new(struct PeerEventData); |
670 | data->peer = peer; | 685 | data->peer = peer; |
671 | data->pcc = pcc; | 686 | data->pcc = pcc; |
672 | data->pcc_cls = pcc_cls; | 687 | data->pcc_cls = pcc_cls; |
673 | opc = GNUNET_new (struct OperationContext); | 688 | opc = GNUNET_new(struct OperationContext); |
674 | opc->c = peer->controller; | 689 | opc->c = peer->controller; |
675 | opc->data = data; | 690 | opc->data = data; |
676 | opc->op_cls = op_cls; | 691 | opc->op_cls = op_cls; |
677 | opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); | 692 | opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); |
678 | opc->type = OP_PEER_STOP; | 693 | opc->type = OP_PEER_STOP; |
679 | opc->op = | 694 | opc->op = |
680 | GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_stop, | 695 | GNUNET_TESTBED_operation_create_(opc, &opstart_peer_stop, |
681 | &oprelease_peer_stop); | 696 | &oprelease_peer_stop); |
682 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, | 697 | GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, |
683 | opc->op); | 698 | opc->op); |
684 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | 699 | GNUNET_TESTBED_operation_begin_wait_(opc->op); |
685 | return opc->op; | 700 | return opc->op; |
686 | } | 701 | } |
687 | 702 | ||
@@ -701,32 +716,32 @@ GNUNET_TESTBED_peer_stop (void *op_cls, | |||
701 | * @return handle to the operation | 716 | * @return handle to the operation |
702 | */ | 717 | */ |
703 | struct GNUNET_TESTBED_Operation * | 718 | struct GNUNET_TESTBED_Operation * |
704 | GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, | 719 | GNUNET_TESTBED_peer_get_information(struct GNUNET_TESTBED_Peer *peer, |
705 | enum GNUNET_TESTBED_PeerInformationType | 720 | enum GNUNET_TESTBED_PeerInformationType |
706 | pit, GNUNET_TESTBED_PeerInfoCallback cb, | 721 | pit, GNUNET_TESTBED_PeerInfoCallback cb, |
707 | void *cb_cls) | 722 | void *cb_cls) |
708 | { | 723 | { |
709 | struct OperationContext *opc; | 724 | struct OperationContext *opc; |
710 | struct PeerInfoData *data; | 725 | struct PeerInfoData *data; |
711 | 726 | ||
712 | GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC != pit); | 727 | GNUNET_assert(GNUNET_TESTBED_PIT_GENERIC != pit); |
713 | GNUNET_assert (NULL != cb); | 728 | GNUNET_assert(NULL != cb); |
714 | data = GNUNET_new (struct PeerInfoData); | 729 | data = GNUNET_new(struct PeerInfoData); |
715 | data->peer = peer; | 730 | data->peer = peer; |
716 | data->pit = pit; | 731 | data->pit = pit; |
717 | data->cb = cb; | 732 | data->cb = cb; |
718 | data->cb_cls = cb_cls; | 733 | data->cb_cls = cb_cls; |
719 | opc = GNUNET_new (struct OperationContext); | 734 | opc = GNUNET_new(struct OperationContext); |
720 | opc->c = peer->controller; | 735 | opc->c = peer->controller; |
721 | opc->data = data; | 736 | opc->data = data; |
722 | opc->type = OP_PEER_INFO; | 737 | opc->type = OP_PEER_INFO; |
723 | opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); | 738 | opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); |
724 | opc->op = | 739 | opc->op = |
725 | GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_getinfo, | 740 | GNUNET_TESTBED_operation_create_(opc, &opstart_peer_getinfo, |
726 | &oprelease_peer_getinfo); | 741 | &oprelease_peer_getinfo); |
727 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, | 742 | GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, |
728 | opc->op); | 743 | opc->op); |
729 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | 744 | GNUNET_TESTBED_operation_begin_wait_(opc->op); |
730 | return opc->op; | 745 | return opc->op; |
731 | } | 746 | } |
732 | 747 | ||
@@ -742,41 +757,41 @@ GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, | |||
742 | * @return handle to the operation | 757 | * @return handle to the operation |
743 | */ | 758 | */ |
744 | struct GNUNET_TESTBED_Operation * | 759 | struct GNUNET_TESTBED_Operation * |
745 | GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer, | 760 | GNUNET_TESTBED_peer_update_configuration(struct GNUNET_TESTBED_Peer *peer, |
746 | const struct | 761 | const struct |
747 | GNUNET_CONFIGURATION_Handle *cfg) | 762 | GNUNET_CONFIGURATION_Handle *cfg) |
748 | { | 763 | { |
749 | struct OperationContext *opc; | 764 | struct OperationContext *opc; |
750 | struct PeerReconfigureData *data; | 765 | struct PeerReconfigureData *data; |
751 | size_t csize; | 766 | size_t csize; |
752 | 767 | ||
753 | data = GNUNET_new (struct PeerReconfigureData); | 768 | data = GNUNET_new(struct PeerReconfigureData); |
754 | data->peer = peer; | 769 | data->peer = peer; |
755 | data->config = GNUNET_CONFIGURATION_serialize (cfg, &csize); | 770 | data->config = GNUNET_CONFIGURATION_serialize(cfg, &csize); |
756 | if (NULL == data->config) | 771 | if (NULL == data->config) |
757 | { | 772 | { |
758 | GNUNET_free (data); | 773 | GNUNET_free(data); |
759 | return NULL; | 774 | return NULL; |
760 | } | 775 | } |
761 | if (csize > UINT16_MAX) | 776 | if (csize > UINT16_MAX) |
762 | { | 777 | { |
763 | GNUNET_break (0); | 778 | GNUNET_break(0); |
764 | GNUNET_free (data->config); | 779 | GNUNET_free(data->config); |
765 | GNUNET_free (data); | 780 | GNUNET_free(data); |
766 | return NULL; | 781 | return NULL; |
767 | } | 782 | } |
768 | data->cfg_size = (uint16_t) csize; | 783 | data->cfg_size = (uint16_t)csize; |
769 | opc = GNUNET_new (struct OperationContext); | 784 | opc = GNUNET_new(struct OperationContext); |
770 | opc->c = peer->controller; | 785 | opc->c = peer->controller; |
771 | opc->data = data; | 786 | opc->data = data; |
772 | opc->type = OP_PEER_RECONFIGURE; | 787 | opc->type = OP_PEER_RECONFIGURE; |
773 | opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); | 788 | opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); |
774 | opc->op = | 789 | opc->op = |
775 | GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_reconfigure, | 790 | GNUNET_TESTBED_operation_create_(opc, &opstart_peer_reconfigure, |
776 | &oprelease_peer_reconfigure); | 791 | &oprelease_peer_reconfigure); |
777 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, | 792 | GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, |
778 | opc->op); | 793 | opc->op); |
779 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | 794 | GNUNET_TESTBED_operation_begin_wait_(opc->op); |
780 | return opc->op; | 795 | return opc->op; |
781 | } | 796 | } |
782 | 797 | ||
@@ -789,21 +804,21 @@ GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer, | |||
789 | * @return handle to the operation | 804 | * @return handle to the operation |
790 | */ | 805 | */ |
791 | struct GNUNET_TESTBED_Operation * | 806 | struct GNUNET_TESTBED_Operation * |
792 | GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer) | 807 | GNUNET_TESTBED_peer_destroy(struct GNUNET_TESTBED_Peer *peer) |
793 | { | 808 | { |
794 | struct OperationContext *opc; | 809 | struct OperationContext *opc; |
795 | 810 | ||
796 | opc = GNUNET_new (struct OperationContext); | 811 | opc = GNUNET_new(struct OperationContext); |
797 | opc->data = peer; | 812 | opc->data = peer; |
798 | opc->c = peer->controller; | 813 | opc->c = peer->controller; |
799 | opc->id = GNUNET_TESTBED_get_next_op_id (peer->controller); | 814 | opc->id = GNUNET_TESTBED_get_next_op_id(peer->controller); |
800 | opc->type = OP_PEER_DESTROY; | 815 | opc->type = OP_PEER_DESTROY; |
801 | opc->op = | 816 | opc->op = |
802 | GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_destroy, | 817 | GNUNET_TESTBED_operation_create_(opc, &opstart_peer_destroy, |
803 | &oprelease_peer_destroy); | 818 | &oprelease_peer_destroy); |
804 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, | 819 | GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, |
805 | opc->op); | 820 | opc->op); |
806 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | 821 | GNUNET_TESTBED_operation_begin_wait_(opc->op); |
807 | return opc->op; | 822 | return opc->op; |
808 | } | 823 | } |
809 | 824 | ||
@@ -821,13 +836,13 @@ GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer) | |||
821 | * time is not allowed | 836 | * time is not allowed |
822 | */ | 837 | */ |
823 | struct GNUNET_TESTBED_Operation * | 838 | struct GNUNET_TESTBED_Operation * |
824 | GNUNET_TESTBED_underlay_configure_link (void *op_cls, | 839 | GNUNET_TESTBED_underlay_configure_link(void *op_cls, |
825 | struct GNUNET_TESTBED_Peer *p1, | 840 | struct GNUNET_TESTBED_Peer *p1, |
826 | struct GNUNET_TESTBED_Peer *p2, | 841 | struct GNUNET_TESTBED_Peer *p2, |
827 | enum GNUNET_TESTBED_ConnectOption co, | 842 | enum GNUNET_TESTBED_ConnectOption co, |
828 | ...) | 843 | ...) |
829 | { | 844 | { |
830 | GNUNET_break (0); | 845 | GNUNET_break(0); |
831 | return NULL; | 846 | return NULL; |
832 | } | 847 | } |
833 | 848 | ||
@@ -847,31 +862,31 @@ GNUNET_TESTBED_underlay_configure_link (void *op_cls, | |||
847 | * not running or underlay disallows) | 862 | * not running or underlay disallows) |
848 | */ | 863 | */ |
849 | struct GNUNET_TESTBED_Operation * | 864 | struct GNUNET_TESTBED_Operation * |
850 | GNUNET_TESTBED_overlay_connect (void *op_cls, | 865 | GNUNET_TESTBED_overlay_connect(void *op_cls, |
851 | GNUNET_TESTBED_OperationCompletionCallback cb, | 866 | GNUNET_TESTBED_OperationCompletionCallback cb, |
852 | void *cb_cls, struct GNUNET_TESTBED_Peer *p1, | 867 | void *cb_cls, struct GNUNET_TESTBED_Peer *p1, |
853 | struct GNUNET_TESTBED_Peer *p2) | 868 | struct GNUNET_TESTBED_Peer *p2) |
854 | { | 869 | { |
855 | struct OperationContext *opc; | 870 | struct OperationContext *opc; |
856 | struct OverlayConnectData *data; | 871 | struct OverlayConnectData *data; |
857 | 872 | ||
858 | GNUNET_assert ((TESTBED_PS_STARTED == p1->state) && (TESTBED_PS_STARTED == p2->state)); | 873 | GNUNET_assert((TESTBED_PS_STARTED == p1->state) && (TESTBED_PS_STARTED == p2->state)); |
859 | data = GNUNET_new (struct OverlayConnectData); | 874 | data = GNUNET_new(struct OverlayConnectData); |
860 | data->p1 = p1; | 875 | data->p1 = p1; |
861 | data->p2 = p2; | 876 | data->p2 = p2; |
862 | data->cb = cb; | 877 | data->cb = cb; |
863 | data->cb_cls = cb_cls; | 878 | data->cb_cls = cb_cls; |
864 | opc = GNUNET_new (struct OperationContext); | 879 | opc = GNUNET_new(struct OperationContext); |
865 | opc->data = data; | 880 | opc->data = data; |
866 | opc->c = p1->controller; | 881 | opc->c = p1->controller; |
867 | opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); | 882 | opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); |
868 | opc->type = OP_OVERLAY_CONNECT; | 883 | opc->type = OP_OVERLAY_CONNECT; |
869 | opc->op_cls = op_cls; | 884 | opc->op_cls = op_cls; |
870 | opc->op = | 885 | opc->op = |
871 | GNUNET_TESTBED_operation_create_ (opc, &opstart_overlay_connect, | 886 | GNUNET_TESTBED_operation_create_(opc, &opstart_overlay_connect, |
872 | &oprelease_overlay_connect); | 887 | &oprelease_overlay_connect); |
873 | GNUNET_TESTBED_host_queue_oc_ (p1->host, opc->op); | 888 | GNUNET_TESTBED_host_queue_oc_(p1->host, opc->op); |
874 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | 889 | GNUNET_TESTBED_operation_begin_wait_(opc->op); |
875 | return opc->op; | 890 | return opc->op; |
876 | } | 891 | } |
877 | 892 | ||
@@ -882,7 +897,7 @@ GNUNET_TESTBED_overlay_connect (void *op_cls, | |||
882 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 897 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
883 | */ | 898 | */ |
884 | static void | 899 | static void |
885 | opstart_manage_service (void *cls) | 900 | opstart_manage_service(void *cls) |
886 | { | 901 | { |
887 | struct OperationContext *opc = cls; | 902 | struct OperationContext *opc = cls; |
888 | struct ManageServiceData *data = opc->data; | 903 | struct ManageServiceData *data = opc->data; |
@@ -890,23 +905,23 @@ opstart_manage_service (void *cls) | |||
890 | struct GNUNET_TESTBED_ManagePeerServiceMessage *msg; | 905 | struct GNUNET_TESTBED_ManagePeerServiceMessage *msg; |
891 | size_t xlen; | 906 | size_t xlen; |
892 | 907 | ||
893 | GNUNET_assert (NULL != data); | 908 | GNUNET_assert(NULL != data); |
894 | xlen = data->msize - sizeof (struct GNUNET_TESTBED_ManagePeerServiceMessage); | 909 | xlen = data->msize - sizeof(struct GNUNET_TESTBED_ManagePeerServiceMessage); |
895 | env = GNUNET_MQ_msg_extra (msg, | 910 | env = GNUNET_MQ_msg_extra(msg, |
896 | xlen, | 911 | xlen, |
897 | GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE); | 912 | GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE); |
898 | msg->peer_id = htonl (data->peer->unique_id); | 913 | msg->peer_id = htonl(data->peer->unique_id); |
899 | msg->operation_id = GNUNET_htonll (opc->id); | 914 | msg->operation_id = GNUNET_htonll(opc->id); |
900 | msg->start = (uint8_t) data->start; | 915 | msg->start = (uint8_t)data->start; |
901 | GNUNET_memcpy (&msg[1], | 916 | GNUNET_memcpy(&msg[1], |
902 | data->service_name, | 917 | data->service_name, |
903 | xlen); | 918 | xlen); |
904 | GNUNET_free (data->service_name); | 919 | GNUNET_free(data->service_name); |
905 | data->service_name = NULL; | 920 | data->service_name = NULL; |
906 | opc->state = OPC_STATE_STARTED; | 921 | opc->state = OPC_STATE_STARTED; |
907 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | 922 | GNUNET_TESTBED_insert_opc_(opc->c, opc); |
908 | GNUNET_MQ_send (opc->c->mq, | 923 | GNUNET_MQ_send(opc->c->mq, |
909 | env); | 924 | env); |
910 | } | 925 | } |
911 | 926 | ||
912 | 927 | ||
@@ -916,26 +931,28 @@ opstart_manage_service (void *cls) | |||
916 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 931 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
917 | */ | 932 | */ |
918 | static void | 933 | static void |
919 | oprelease_manage_service (void *cls) | 934 | oprelease_manage_service(void *cls) |
920 | { | 935 | { |
921 | struct OperationContext *opc = cls; | 936 | struct OperationContext *opc = cls; |
922 | struct ManageServiceData *data; | 937 | struct ManageServiceData *data; |
923 | 938 | ||
924 | data = opc->data; | 939 | data = opc->data; |
925 | switch (opc->state) | 940 | switch (opc->state) |
926 | { | 941 | { |
927 | case OPC_STATE_STARTED: | 942 | case OPC_STATE_STARTED: |
928 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | 943 | GNUNET_TESTBED_remove_opc_(opc->c, opc); |
929 | break; | 944 | break; |
930 | case OPC_STATE_INIT: | 945 | |
931 | GNUNET_assert (NULL != data); | 946 | case OPC_STATE_INIT: |
932 | GNUNET_free (data->service_name); | 947 | GNUNET_assert(NULL != data); |
933 | break; | 948 | GNUNET_free(data->service_name); |
934 | case OPC_STATE_FINISHED: | 949 | break; |
935 | break; | 950 | |
936 | } | 951 | case OPC_STATE_FINISHED: |
937 | GNUNET_free_non_null (data); | 952 | break; |
938 | GNUNET_free (opc); | 953 | } |
954 | GNUNET_free_non_null(data); | ||
955 | GNUNET_free(opc); | ||
939 | } | 956 | } |
940 | 957 | ||
941 | 958 | ||
@@ -955,41 +972,41 @@ oprelease_manage_service (void *cls) | |||
955 | * @return an operation handle; NULL upon error (peer not running) | 972 | * @return an operation handle; NULL upon error (peer not running) |
956 | */ | 973 | */ |
957 | struct GNUNET_TESTBED_Operation * | 974 | struct GNUNET_TESTBED_Operation * |
958 | GNUNET_TESTBED_peer_manage_service (void *op_cls, | 975 | GNUNET_TESTBED_peer_manage_service(void *op_cls, |
959 | struct GNUNET_TESTBED_Peer *peer, | 976 | struct GNUNET_TESTBED_Peer *peer, |
960 | const char *service_name, | 977 | const char *service_name, |
961 | GNUNET_TESTBED_OperationCompletionCallback cb, | 978 | GNUNET_TESTBED_OperationCompletionCallback cb, |
962 | void *cb_cls, | 979 | void *cb_cls, |
963 | unsigned int start) | 980 | unsigned int start) |
964 | { | 981 | { |
965 | struct ManageServiceData *data; | 982 | struct ManageServiceData *data; |
966 | struct OperationContext *opc; | 983 | struct OperationContext *opc; |
967 | size_t msize; | 984 | size_t msize; |
968 | 985 | ||
969 | GNUNET_assert (TESTBED_PS_STARTED == peer->state); /* peer is not running? */ | 986 | GNUNET_assert(TESTBED_PS_STARTED == peer->state); /* peer is not running? */ |
970 | msize = strlen (service_name) + 1; | 987 | msize = strlen(service_name) + 1; |
971 | msize += sizeof (struct GNUNET_TESTBED_ManagePeerServiceMessage); | 988 | msize += sizeof(struct GNUNET_TESTBED_ManagePeerServiceMessage); |
972 | if (GNUNET_MAX_MESSAGE_SIZE < msize) | 989 | if (GNUNET_MAX_MESSAGE_SIZE < msize) |
973 | return NULL; | 990 | return NULL; |
974 | data = GNUNET_new (struct ManageServiceData); | 991 | data = GNUNET_new(struct ManageServiceData); |
975 | data->cb = cb; | 992 | data->cb = cb; |
976 | data->cb_cls = cb_cls; | 993 | data->cb_cls = cb_cls; |
977 | data->peer = peer; | 994 | data->peer = peer; |
978 | data->service_name = GNUNET_strdup (service_name); | 995 | data->service_name = GNUNET_strdup(service_name); |
979 | data->start = start; | 996 | data->start = start; |
980 | data->msize = (uint16_t) msize; | 997 | data->msize = (uint16_t)msize; |
981 | opc = GNUNET_new (struct OperationContext); | 998 | opc = GNUNET_new(struct OperationContext); |
982 | opc->data = data; | 999 | opc->data = data; |
983 | opc->c = peer->controller; | 1000 | opc->c = peer->controller; |
984 | opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); | 1001 | opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); |
985 | opc->type = OP_MANAGE_SERVICE; | 1002 | opc->type = OP_MANAGE_SERVICE; |
986 | opc->op_cls = op_cls; | 1003 | opc->op_cls = op_cls; |
987 | opc->op = | 1004 | opc->op = |
988 | GNUNET_TESTBED_operation_create_ (opc, &opstart_manage_service, | 1005 | GNUNET_TESTBED_operation_create_(opc, &opstart_manage_service, |
989 | &oprelease_manage_service); | 1006 | &oprelease_manage_service); |
990 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, | 1007 | GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, |
991 | opc->op); | 1008 | opc->op); |
992 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | 1009 | GNUNET_TESTBED_operation_begin_wait_(opc->op); |
993 | return opc->op; | 1010 | return opc->op; |
994 | } | 1011 | } |
995 | 1012 | ||
diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h index cf0624eec..6a9b89e7c 100644 --- a/src/testbed/testbed_api_peers.h +++ b/src/testbed/testbed_api_peers.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -35,26 +35,25 @@ | |||
35 | /** | 35 | /** |
36 | * Enumeration of possible states a peer could be in | 36 | * Enumeration of possible states a peer could be in |
37 | */ | 37 | */ |
38 | enum PeerState | 38 | enum PeerState { |
39 | { | 39 | /** |
40 | /** | 40 | * State to signify that this peer is invalid |
41 | * State to signify that this peer is invalid | 41 | */ |
42 | */ | ||
43 | TESTBED_PS_INVALID, | 42 | TESTBED_PS_INVALID, |
44 | 43 | ||
45 | /** | 44 | /** |
46 | * The peer has been created | 45 | * The peer has been created |
47 | */ | 46 | */ |
48 | TESTBED_PS_CREATED, | 47 | TESTBED_PS_CREATED, |
49 | 48 | ||
50 | /** | 49 | /** |
51 | * The peer is running | 50 | * The peer is running |
52 | */ | 51 | */ |
53 | TESTBED_PS_STARTED, | 52 | TESTBED_PS_STARTED, |
54 | 53 | ||
55 | /** | 54 | /** |
56 | * The peer is stopped | 55 | * The peer is stopped |
57 | */ | 56 | */ |
58 | TESTBED_PS_STOPPED, | 57 | TESTBED_PS_STOPPED, |
59 | }; | 58 | }; |
60 | 59 | ||
@@ -63,8 +62,7 @@ enum PeerState | |||
63 | * A peer controlled by the testing framework. A peer runs | 62 | * A peer controlled by the testing framework. A peer runs |
64 | * at a particular host. | 63 | * at a particular host. |
65 | */ | 64 | */ |
66 | struct GNUNET_TESTBED_Peer | 65 | struct GNUNET_TESTBED_Peer { |
67 | { | ||
68 | /** | 66 | /** |
69 | * peer list DLL | 67 | * peer list DLL |
70 | */ | 68 | */ |
@@ -106,8 +104,7 @@ struct GNUNET_TESTBED_Peer | |||
106 | /** | 104 | /** |
107 | * Data for the OperationType OP_PEER_CREATE | 105 | * Data for the OperationType OP_PEER_CREATE |
108 | */ | 106 | */ |
109 | struct PeerCreateData | 107 | struct PeerCreateData { |
110 | { | ||
111 | /** | 108 | /** |
112 | * The host where the peer has to be created | 109 | * The host where the peer has to be created |
113 | */ | 110 | */ |
@@ -132,15 +129,13 @@ struct PeerCreateData | |||
132 | * The peer structure to return when we get success message | 129 | * The peer structure to return when we get success message |
133 | */ | 130 | */ |
134 | struct GNUNET_TESTBED_Peer *peer; | 131 | struct GNUNET_TESTBED_Peer *peer; |
135 | |||
136 | }; | 132 | }; |
137 | 133 | ||
138 | 134 | ||
139 | /** | 135 | /** |
140 | * Data for OperationType OP_PEER_START and OP_PEER_STOP | 136 | * Data for OperationType OP_PEER_START and OP_PEER_STOP |
141 | */ | 137 | */ |
142 | struct PeerEventData | 138 | struct PeerEventData { |
143 | { | ||
144 | /** | 139 | /** |
145 | * The handle of the peer to start | 140 | * The handle of the peer to start |
146 | */ | 141 | */ |
@@ -155,15 +150,13 @@ struct PeerEventData | |||
155 | * Closure for the above callback | 150 | * Closure for the above callback |
156 | */ | 151 | */ |
157 | void *pcc_cls; | 152 | void *pcc_cls; |
158 | |||
159 | }; | 153 | }; |
160 | 154 | ||
161 | 155 | ||
162 | /** | 156 | /** |
163 | * Data for the OperationType OP_PEER_DESTROY; | 157 | * Data for the OperationType OP_PEER_DESTROY; |
164 | */ | 158 | */ |
165 | struct PeerDestroyData | 159 | struct PeerDestroyData { |
166 | { | ||
167 | /** | 160 | /** |
168 | * The peer structure | 161 | * The peer structure |
169 | */ | 162 | */ |
@@ -176,8 +169,7 @@ struct PeerDestroyData | |||
176 | /** | 169 | /** |
177 | * Data for the OperationType OP_PEER_INFO | 170 | * Data for the OperationType OP_PEER_INFO |
178 | */ | 171 | */ |
179 | struct PeerInfoData | 172 | struct PeerInfoData { |
180 | { | ||
181 | /** | 173 | /** |
182 | * The peer whose information has been requested | 174 | * The peer whose information has been requested |
183 | */ | 175 | */ |
@@ -203,8 +195,7 @@ struct PeerInfoData | |||
203 | /** | 195 | /** |
204 | * Data for the operations of type OP_PEER_RECONFIGURE | 196 | * Data for the operations of type OP_PEER_RECONFIGURE |
205 | */ | 197 | */ |
206 | struct PeerReconfigureData | 198 | struct PeerReconfigureData { |
207 | { | ||
208 | /** | 199 | /** |
209 | * The peer whose information has been requested | 200 | * The peer whose information has been requested |
210 | */ | 201 | */ |
@@ -225,9 +216,7 @@ struct PeerReconfigureData | |||
225 | /** | 216 | /** |
226 | * Data structure for OperationType OP_OVERLAY_CONNECT | 217 | * Data structure for OperationType OP_OVERLAY_CONNECT |
227 | */ | 218 | */ |
228 | struct OverlayConnectData | 219 | struct OverlayConnectData { |
229 | { | ||
230 | |||
231 | /** | 220 | /** |
232 | * Peer A to connect to peer B | 221 | * Peer A to connect to peer B |
233 | */ | 222 | */ |
@@ -254,7 +243,6 @@ struct OverlayConnectData | |||
254 | * overlay connection between peer 1 and peer 2. | 243 | * overlay connection between peer 1 and peer 2. |
255 | */ | 244 | */ |
256 | struct OperationContext *sub_opc; | 245 | struct OperationContext *sub_opc; |
257 | |||
258 | }; | 246 | }; |
259 | 247 | ||
260 | 248 | ||
@@ -270,7 +258,6 @@ struct ManageServiceData { | |||
270 | unsigned int start; | 258 | unsigned int start; |
271 | 259 | ||
272 | uint16_t msize; | 260 | uint16_t msize; |
273 | |||
274 | }; | 261 | }; |
275 | 262 | ||
276 | 263 | ||
@@ -283,8 +270,8 @@ struct ManageServiceData { | |||
283 | * @return the PeerGetConfigurationMessage | 270 | * @return the PeerGetConfigurationMessage |
284 | */ | 271 | */ |
285 | struct GNUNET_TESTBED_PeerGetConfigurationMessage * | 272 | struct GNUNET_TESTBED_PeerGetConfigurationMessage * |
286 | GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id, | 273 | GNUNET_TESTBED_generate_peergetconfig_msg_(uint32_t peer_id, |
287 | uint64_t operation_id); | 274 | uint64_t operation_id); |
288 | 275 | ||
289 | 276 | ||
290 | /** | 277 | /** |
@@ -293,7 +280,7 @@ GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id, | |||
293 | * @param peer the peer to add to the peer list | 280 | * @param peer the peer to add to the peer list |
294 | */ | 281 | */ |
295 | void | 282 | void |
296 | GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer); | 283 | GNUNET_TESTBED_peer_register_(struct GNUNET_TESTBED_Peer *peer); |
297 | 284 | ||
298 | 285 | ||
299 | /** | 286 | /** |
@@ -302,14 +289,14 @@ GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer); | |||
302 | * @param peer the peer to remove | 289 | * @param peer the peer to remove |
303 | */ | 290 | */ |
304 | void | 291 | void |
305 | GNUNET_TESTBED_peer_deregister_ (struct GNUNET_TESTBED_Peer *peer); | 292 | GNUNET_TESTBED_peer_deregister_(struct GNUNET_TESTBED_Peer *peer); |
306 | 293 | ||
307 | 294 | ||
308 | /** | 295 | /** |
309 | * Frees all peers | 296 | * Frees all peers |
310 | */ | 297 | */ |
311 | void | 298 | void |
312 | GNUNET_TESTBED_cleanup_peers_ (void); | 299 | GNUNET_TESTBED_cleanup_peers_(void); |
313 | 300 | ||
314 | #endif | 301 | #endif |
315 | /* end of testbed_api_peers.h */ | 302 | /* end of testbed_api_peers.h */ |
diff --git a/src/testbed/testbed_api_sd.c b/src/testbed/testbed_api_sd.c index c9cbb27a1..2bff246a7 100644 --- a/src/testbed/testbed_api_sd.c +++ b/src/testbed/testbed_api_sd.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -31,8 +31,7 @@ | |||
31 | /** | 31 | /** |
32 | * An entry to hold data which will be used to calculate SD | 32 | * An entry to hold data which will be used to calculate SD |
33 | */ | 33 | */ |
34 | struct SDEntry | 34 | struct SDEntry { |
35 | { | ||
36 | /** | 35 | /** |
37 | * DLL next pointer | 36 | * DLL next pointer |
38 | */ | 37 | */ |
@@ -53,8 +52,7 @@ struct SDEntry | |||
53 | /** | 52 | /** |
54 | * Opaque handle for calculating SD | 53 | * Opaque handle for calculating SD |
55 | */ | 54 | */ |
56 | struct SDHandle | 55 | struct SDHandle { |
57 | { | ||
58 | /** | 56 | /** |
59 | * DLL head for storing entries | 57 | * DLL head for storing entries |
60 | */ | 58 | */ |
@@ -104,12 +102,12 @@ struct SDHandle | |||
104 | * @return the initialized handle | 102 | * @return the initialized handle |
105 | */ | 103 | */ |
106 | struct SDHandle * | 104 | struct SDHandle * |
107 | GNUNET_TESTBED_SD_init_ (unsigned int max_cnt) | 105 | GNUNET_TESTBED_SD_init_(unsigned int max_cnt) |
108 | { | 106 | { |
109 | struct SDHandle *h; | 107 | struct SDHandle *h; |
110 | 108 | ||
111 | GNUNET_assert (1 < max_cnt); | 109 | GNUNET_assert(1 < max_cnt); |
112 | h = GNUNET_new (struct SDHandle); | 110 | h = GNUNET_new(struct SDHandle); |
113 | h->max_cnt = max_cnt; | 111 | h->max_cnt = max_cnt; |
114 | return h; | 112 | return h; |
115 | } | 113 | } |
@@ -121,16 +119,16 @@ GNUNET_TESTBED_SD_init_ (unsigned int max_cnt) | |||
121 | * @param h the SD handle | 119 | * @param h the SD handle |
122 | */ | 120 | */ |
123 | void | 121 | void |
124 | GNUNET_TESTBED_SD_destroy_ (struct SDHandle *h) | 122 | GNUNET_TESTBED_SD_destroy_(struct SDHandle *h) |
125 | { | 123 | { |
126 | struct SDEntry *entry; | 124 | struct SDEntry *entry; |
127 | 125 | ||
128 | while (NULL != (entry = h->head)) | 126 | while (NULL != (entry = h->head)) |
129 | { | 127 | { |
130 | GNUNET_CONTAINER_DLL_remove (h->head, h->tail, entry); | 128 | GNUNET_CONTAINER_DLL_remove(h->head, h->tail, entry); |
131 | GNUNET_free (entry); | 129 | GNUNET_free(entry); |
132 | } | 130 | } |
133 | GNUNET_free (h); | 131 | GNUNET_free(h); |
134 | } | 132 | } |
135 | 133 | ||
136 | 134 | ||
@@ -141,7 +139,7 @@ GNUNET_TESTBED_SD_destroy_ (struct SDHandle *h) | |||
141 | * @param amount the reading value | 139 | * @param amount the reading value |
142 | */ | 140 | */ |
143 | void | 141 | void |
144 | GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount) | 142 | GNUNET_TESTBED_SD_add_data_(struct SDHandle *h, unsigned int amount) |
145 | { | 143 | { |
146 | struct SDEntry *entry; | 144 | struct SDEntry *entry; |
147 | double sqavg; | 145 | double sqavg; |
@@ -149,25 +147,25 @@ GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount) | |||
149 | 147 | ||
150 | entry = NULL; | 148 | entry = NULL; |
151 | if (h->cnt == h->max_cnt) | 149 | if (h->cnt == h->max_cnt) |
152 | { | 150 | { |
153 | entry = h->head; | 151 | entry = h->head; |
154 | GNUNET_CONTAINER_DLL_remove (h->head, h->tail, entry); | 152 | GNUNET_CONTAINER_DLL_remove(h->head, h->tail, entry); |
155 | h->sum -= entry->amount; | 153 | h->sum -= entry->amount; |
156 | h->sqsum -= | 154 | h->sqsum -= |
157 | ((unsigned long) entry->amount) * ((unsigned long) entry->amount); | 155 | ((unsigned long)entry->amount) * ((unsigned long)entry->amount); |
158 | h->cnt--; | 156 | h->cnt--; |
159 | } | 157 | } |
160 | GNUNET_assert (h->cnt < h->max_cnt); | 158 | GNUNET_assert(h->cnt < h->max_cnt); |
161 | if (NULL == entry) | 159 | if (NULL == entry) |
162 | entry = GNUNET_new (struct SDEntry); | 160 | entry = GNUNET_new(struct SDEntry); |
163 | entry->amount = amount; | 161 | entry->amount = amount; |
164 | GNUNET_CONTAINER_DLL_insert_tail (h->head, h->tail, entry); | 162 | GNUNET_CONTAINER_DLL_insert_tail(h->head, h->tail, entry); |
165 | h->sum += amount; | 163 | h->sum += amount; |
166 | h->cnt++; | 164 | h->cnt++; |
167 | h->avg = ((float) h->sum) / ((float) h->cnt); | 165 | h->avg = ((float)h->sum) / ((float)h->cnt); |
168 | h->sqsum += ((unsigned long) amount) * ((unsigned long) amount); | 166 | h->sqsum += ((unsigned long)amount) * ((unsigned long)amount); |
169 | sqsum_avg = ((double) h->sqsum) / ((double) h->cnt); | 167 | sqsum_avg = ((double)h->sqsum) / ((double)h->cnt); |
170 | sqavg = ((double) h->avg) * ((double) h->avg); | 168 | sqavg = ((double)h->avg) * ((double)h->avg); |
171 | h->vr = sqsum_avg - sqavg; | 169 | h->vr = sqsum_avg - sqavg; |
172 | } | 170 | } |
173 | 171 | ||
@@ -182,8 +180,8 @@ GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount) | |||
182 | * be calculated; GNUNET_OK if the deviation is returned through factor | 180 | * be calculated; GNUNET_OK if the deviation is returned through factor |
183 | */ | 181 | */ |
184 | int | 182 | int |
185 | GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount, | 183 | GNUNET_TESTBED_SD_deviation_factor_(struct SDHandle *h, unsigned int amount, |
186 | int *factor) | 184 | int *factor) |
187 | { | 185 | { |
188 | double diff; | 186 | double diff; |
189 | int f; | 187 | int f; |
@@ -191,19 +189,19 @@ GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount, | |||
191 | 189 | ||
192 | if (h->cnt < 2) | 190 | if (h->cnt < 2) |
193 | return GNUNET_SYSERR; | 191 | return GNUNET_SYSERR; |
194 | if (((float) amount) > h->avg) | 192 | if (((float)amount) > h->avg) |
195 | { | 193 | { |
196 | diff = ((float) amount) - h->avg; | 194 | diff = ((float)amount) - h->avg; |
197 | f = 1; | 195 | f = 1; |
198 | } | 196 | } |
199 | else | 197 | else |
200 | { | 198 | { |
201 | diff = h->avg - ((float) amount); | 199 | diff = h->avg - ((float)amount); |
202 | f = -1; | 200 | f = -1; |
203 | } | 201 | } |
204 | diff *= diff; | 202 | diff *= diff; |
205 | for (n = 1; n < 4; n++) | 203 | for (n = 1; n < 4; n++) |
206 | if (diff < (((double) (n * n)) * h->vr)) | 204 | if (diff < (((double)(n * n)) * h->vr)) |
207 | break; | 205 | break; |
208 | *factor = f * n; | 206 | *factor = f * n; |
209 | return GNUNET_OK; | 207 | return GNUNET_OK; |
diff --git a/src/testbed/testbed_api_sd.h b/src/testbed/testbed_api_sd.h index a924857bb..6e4cc621a 100644 --- a/src/testbed/testbed_api_sd.h +++ b/src/testbed/testbed_api_sd.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -41,7 +41,7 @@ struct SDHandle; | |||
41 | * @return the initialized handle | 41 | * @return the initialized handle |
42 | */ | 42 | */ |
43 | struct SDHandle * | 43 | struct SDHandle * |
44 | GNUNET_TESTBED_SD_init_ (unsigned int max_cnt); | 44 | GNUNET_TESTBED_SD_init_(unsigned int max_cnt); |
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
@@ -50,7 +50,7 @@ GNUNET_TESTBED_SD_init_ (unsigned int max_cnt); | |||
50 | * @param h the SD handle | 50 | * @param h the SD handle |
51 | */ | 51 | */ |
52 | void | 52 | void |
53 | GNUNET_TESTBED_SD_destroy_ (struct SDHandle *h); | 53 | GNUNET_TESTBED_SD_destroy_(struct SDHandle *h); |
54 | 54 | ||
55 | 55 | ||
56 | /** | 56 | /** |
@@ -60,7 +60,7 @@ GNUNET_TESTBED_SD_destroy_ (struct SDHandle *h); | |||
60 | * @param amount the reading value | 60 | * @param amount the reading value |
61 | */ | 61 | */ |
62 | void | 62 | void |
63 | GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount); | 63 | GNUNET_TESTBED_SD_add_data_(struct SDHandle *h, unsigned int amount); |
64 | 64 | ||
65 | 65 | ||
66 | /** | 66 | /** |
@@ -74,8 +74,8 @@ GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount); | |||
74 | * maximum of 4 is returned for deviations equal to or larger than 4 | 74 | * maximum of 4 is returned for deviations equal to or larger than 4 |
75 | */ | 75 | */ |
76 | int | 76 | int |
77 | GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount, | 77 | GNUNET_TESTBED_SD_deviation_factor_(struct SDHandle *h, unsigned int amount, |
78 | int *factor); | 78 | int *factor); |
79 | 79 | ||
80 | #endif | 80 | #endif |
81 | /* end of testbed_api.h */ | 81 | /* end of testbed_api.h */ |
diff --git a/src/testbed/testbed_api_services.c b/src/testbed/testbed_api_services.c index c2b74e580..ee4a65817 100644 --- a/src/testbed/testbed_api_services.c +++ b/src/testbed/testbed_api_services.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -32,8 +32,7 @@ | |||
32 | /** | 32 | /** |
33 | * States for Service connect operations | 33 | * States for Service connect operations |
34 | */ | 34 | */ |
35 | enum State | 35 | enum State { |
36 | { | ||
37 | /** | 36 | /** |
38 | * Initial state | 37 | * Initial state |
39 | */ | 38 | */ |
@@ -54,8 +53,7 @@ enum State | |||
54 | /** | 53 | /** |
55 | * Data accessed during service connections | 54 | * Data accessed during service connections |
56 | */ | 55 | */ |
57 | struct ServiceConnectData | 56 | struct ServiceConnectData { |
58 | { | ||
59 | /** | 57 | /** |
60 | * helper function callback to establish the connection | 58 | * helper function callback to establish the connection |
61 | */ | 59 | */ |
@@ -120,7 +118,6 @@ struct ServiceConnectData | |||
120 | * State information | 118 | * State information |
121 | */ | 119 | */ |
122 | enum State state; | 120 | enum State state; |
123 | |||
124 | }; | 121 | }; |
125 | 122 | ||
126 | 123 | ||
@@ -132,7 +129,7 @@ struct ServiceConnectData | |||
132 | * @param msg message received, NULL on timeout or fatal error | 129 | * @param msg message received, NULL on timeout or fatal error |
133 | */ | 130 | */ |
134 | static void | 131 | static void |
135 | configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg) | 132 | configuration_receiver(void *cls, const struct GNUNET_MessageHeader *msg) |
136 | { | 133 | { |
137 | struct ServiceConnectData *data = cls; | 134 | struct ServiceConnectData *data = cls; |
138 | struct GNUNET_TESTBED_Controller *c; | 135 | struct GNUNET_TESTBED_Controller *c; |
@@ -141,26 +138,26 @@ configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg) | |||
141 | uint16_t mtype; | 138 | uint16_t mtype; |
142 | 139 | ||
143 | c = data->peer->controller; | 140 | c = data->peer->controller; |
144 | mtype = ntohs (msg->type); | 141 | mtype = ntohs(msg->type); |
145 | emsg = NULL; | 142 | emsg = NULL; |
146 | info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; | 143 | info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; |
147 | info.op = data->operation; | 144 | info.op = data->operation; |
148 | info.op_cls = data->op_cls; | 145 | info.op_cls = data->op_cls; |
149 | if (GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT == mtype) | 146 | if (GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT == mtype) |
150 | { | 147 | { |
151 | emsg = | 148 | emsg = |
152 | GNUNET_TESTBED_parse_error_string_ ((const struct | 149 | GNUNET_TESTBED_parse_error_string_((const struct |
153 | GNUNET_TESTBED_OperationFailureEventMessage | 150 | GNUNET_TESTBED_OperationFailureEventMessage |
154 | *) msg); | 151 | *)msg); |
155 | if (NULL == emsg) | 152 | if (NULL == emsg) |
156 | emsg = "Unknown error"; | 153 | emsg = "Unknown error"; |
157 | info.details.operation_finished.emsg = emsg; | 154 | info.details.operation_finished.emsg = emsg; |
158 | info.details.operation_finished.generic = NULL; | 155 | info.details.operation_finished.generic = NULL; |
159 | goto call_cb; | 156 | goto call_cb; |
160 | } | 157 | } |
161 | data->cfg = GNUNET_TESTBED_extract_config_ (msg); | 158 | data->cfg = GNUNET_TESTBED_extract_config_(msg); |
162 | GNUNET_assert (NULL == data->op_result); | 159 | GNUNET_assert(NULL == data->op_result); |
163 | data->op_result = data->ca (data->cada_cls, data->cfg); | 160 | data->op_result = data->ca(data->cada_cls, data->cfg); |
164 | info.details.operation_finished.emsg = NULL; | 161 | info.details.operation_finished.emsg = NULL; |
165 | info.details.operation_finished.generic = data->op_result; | 162 | info.details.operation_finished.generic = data->op_result; |
166 | data->state = SERVICE_CONNECTED; | 163 | data->state = SERVICE_CONNECTED; |
@@ -168,9 +165,9 @@ configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg) | |||
168 | call_cb: | 165 | call_cb: |
169 | if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) && | 166 | if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) && |
170 | (NULL != c->cc)) | 167 | (NULL != c->cc)) |
171 | c->cc (c->cc_cls, &info); | 168 | c->cc(c->cc_cls, &info); |
172 | if (NULL != data->cb) | 169 | if (NULL != data->cb) |
173 | data->cb (data->cb_cls, data->operation, data->op_result, emsg); | 170 | data->cb(data->cb_cls, data->operation, data->op_result, emsg); |
174 | } | 171 | } |
175 | 172 | ||
176 | 173 | ||
@@ -180,23 +177,23 @@ call_cb: | |||
180 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 177 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
181 | */ | 178 | */ |
182 | static void | 179 | static void |
183 | opstart_service_connect (void *cls) | 180 | opstart_service_connect(void *cls) |
184 | { | 181 | { |
185 | struct ServiceConnectData *data = cls; | 182 | struct ServiceConnectData *data = cls; |
186 | struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; | 183 | struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; |
187 | struct GNUNET_TESTBED_Controller *c; | 184 | struct GNUNET_TESTBED_Controller *c; |
188 | uint64_t op_id; | 185 | uint64_t op_id; |
189 | 186 | ||
190 | GNUNET_assert (NULL != data); | 187 | GNUNET_assert(NULL != data); |
191 | GNUNET_assert (NULL != data->peer); | 188 | GNUNET_assert(NULL != data->peer); |
192 | c = data->peer->controller; | 189 | c = data->peer->controller; |
193 | op_id = GNUNET_TESTBED_get_next_op_id (c); | 190 | op_id = GNUNET_TESTBED_get_next_op_id(c); |
194 | msg = | 191 | msg = |
195 | GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id, op_id); | 192 | GNUNET_TESTBED_generate_peergetconfig_msg_(data->peer->unique_id, op_id); |
196 | data->opc = | 193 | data->opc = |
197 | GNUNET_TESTBED_forward_operation_msg_ (c, op_id, &msg->header, | 194 | GNUNET_TESTBED_forward_operation_msg_(c, op_id, &msg->header, |
198 | &configuration_receiver, data); | 195 | &configuration_receiver, data); |
199 | GNUNET_free (msg); | 196 | GNUNET_free(msg); |
200 | data->state = CFG_REQUEST_QUEUED; | 197 | data->state = CFG_REQUEST_QUEUED; |
201 | } | 198 | } |
202 | 199 | ||
@@ -208,26 +205,28 @@ opstart_service_connect (void *cls) | |||
208 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 205 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
209 | */ | 206 | */ |
210 | static void | 207 | static void |
211 | oprelease_service_connect (void *cls) | 208 | oprelease_service_connect(void *cls) |
212 | { | 209 | { |
213 | struct ServiceConnectData *data = cls; | 210 | struct ServiceConnectData *data = cls; |
214 | 211 | ||
215 | switch (data->state) | 212 | switch (data->state) |
216 | { | 213 | { |
217 | case INIT: | 214 | case INIT: |
218 | break; | 215 | break; |
219 | case CFG_REQUEST_QUEUED: | 216 | |
220 | GNUNET_assert (NULL != data->opc); | 217 | case CFG_REQUEST_QUEUED: |
221 | GNUNET_TESTBED_forward_operation_msg_cancel_ (data->opc); | 218 | GNUNET_assert(NULL != data->opc); |
222 | break; | 219 | GNUNET_TESTBED_forward_operation_msg_cancel_(data->opc); |
223 | case SERVICE_CONNECTED: | 220 | break; |
224 | GNUNET_assert (NULL != data->cfg); | 221 | |
225 | GNUNET_CONFIGURATION_destroy (data->cfg); | 222 | case SERVICE_CONNECTED: |
226 | if (NULL != data->da) | 223 | GNUNET_assert(NULL != data->cfg); |
227 | data->da (data->cada_cls, data->op_result); | 224 | GNUNET_CONFIGURATION_destroy(data->cfg); |
228 | break; | 225 | if (NULL != data->da) |
229 | } | 226 | data->da(data->cada_cls, data->op_result); |
230 | GNUNET_free (data); | 227 | break; |
228 | } | ||
229 | GNUNET_free(data); | ||
231 | } | 230 | } |
232 | 231 | ||
233 | 232 | ||
@@ -253,17 +252,17 @@ oprelease_service_connect (void *cls) | |||
253 | * @return handle for the operation | 252 | * @return handle for the operation |
254 | */ | 253 | */ |
255 | struct GNUNET_TESTBED_Operation * | 254 | struct GNUNET_TESTBED_Operation * |
256 | GNUNET_TESTBED_service_connect (void *op_cls, struct GNUNET_TESTBED_Peer *peer, | 255 | GNUNET_TESTBED_service_connect(void *op_cls, struct GNUNET_TESTBED_Peer *peer, |
257 | const char *service_name, | 256 | const char *service_name, |
258 | GNUNET_TESTBED_ServiceConnectCompletionCallback | 257 | GNUNET_TESTBED_ServiceConnectCompletionCallback |
259 | cb, void *cb_cls, | 258 | cb, void *cb_cls, |
260 | GNUNET_TESTBED_ConnectAdapter ca, | 259 | GNUNET_TESTBED_ConnectAdapter ca, |
261 | GNUNET_TESTBED_DisconnectAdapter da, | 260 | GNUNET_TESTBED_DisconnectAdapter da, |
262 | void *cada_cls) | 261 | void *cada_cls) |
263 | { | 262 | { |
264 | struct ServiceConnectData *data; | 263 | struct ServiceConnectData *data; |
265 | 264 | ||
266 | data = GNUNET_new (struct ServiceConnectData); | 265 | data = GNUNET_new(struct ServiceConnectData); |
267 | data->ca = ca; | 266 | data->ca = ca; |
268 | data->da = da; | 267 | data->da = da; |
269 | data->cada_cls = cada_cls; | 268 | data->cada_cls = cada_cls; |
@@ -273,15 +272,15 @@ GNUNET_TESTBED_service_connect (void *op_cls, struct GNUNET_TESTBED_Peer *peer, | |||
273 | data->cb = cb; | 272 | data->cb = cb; |
274 | data->cb_cls = cb_cls; | 273 | data->cb_cls = cb_cls; |
275 | data->operation = | 274 | data->operation = |
276 | GNUNET_TESTBED_operation_create_ (data, &opstart_service_connect, | 275 | GNUNET_TESTBED_operation_create_(data, &opstart_service_connect, |
277 | &oprelease_service_connect); | 276 | &oprelease_service_connect); |
278 | GNUNET_TESTBED_operation_queue_insert_ (peer-> | 277 | GNUNET_TESTBED_operation_queue_insert_(peer-> |
279 | controller->opq_parallel_service_connections, | 278 | controller->opq_parallel_service_connections, |
280 | data->operation); | 279 | data->operation); |
281 | GNUNET_TESTBED_operation_queue_insert_ (peer-> | 280 | GNUNET_TESTBED_operation_queue_insert_(peer-> |
282 | controller->opq_parallel_operations, | 281 | controller->opq_parallel_operations, |
283 | data->operation); | 282 | data->operation); |
284 | GNUNET_TESTBED_operation_begin_wait_ (data->operation); | 283 | GNUNET_TESTBED_operation_begin_wait_(data->operation); |
285 | return data->operation; | 284 | return data->operation; |
286 | } | 285 | } |
287 | 286 | ||
diff --git a/src/testbed/testbed_api_statistics.c b/src/testbed/testbed_api_statistics.c index 6115f6e61..e7440dfa1 100644 --- a/src/testbed/testbed_api_statistics.c +++ b/src/testbed/testbed_api_statistics.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -34,21 +34,20 @@ | |||
34 | /** | 34 | /** |
35 | * Generic logging shorthand | 35 | * Generic logging shorthand |
36 | */ | 36 | */ |
37 | #define LOG(kind,...) \ | 37 | #define LOG(kind, ...) \ |
38 | GNUNET_log_from (kind, "testbed-api-statistics", __VA_ARGS__) | 38 | GNUNET_log_from(kind, "testbed-api-statistics", __VA_ARGS__) |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Debug logging shorthand | 41 | * Debug logging shorthand |
42 | */ | 42 | */ |
43 | #define LOG_DEBUG(...) \ | 43 | #define LOG_DEBUG(...) \ |
44 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 44 | LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Context information for use in GNUNET_TESTBED_get_statistics() | 48 | * Context information for use in GNUNET_TESTBED_get_statistics() |
49 | */ | 49 | */ |
50 | struct GetStatsContext | 50 | struct GetStatsContext { |
51 | { | ||
52 | /** | 51 | /** |
53 | * The main operation we generate while creating this context | 52 | * The main operation we generate while creating this context |
54 | */ | 53 | */ |
@@ -106,15 +105,13 @@ struct GetStatsContext | |||
106 | * How many peers' statistics have we iterated through | 105 | * How many peers' statistics have we iterated through |
107 | */ | 106 | */ |
108 | unsigned int num_completed; | 107 | unsigned int num_completed; |
109 | |||
110 | }; | 108 | }; |
111 | 109 | ||
112 | 110 | ||
113 | /** | 111 | /** |
114 | * Context information with respect to a particular peer | 112 | * Context information with respect to a particular peer |
115 | */ | 113 | */ |
116 | struct PeerGetStatsContext | 114 | struct PeerGetStatsContext { |
117 | { | ||
118 | /** | 115 | /** |
119 | * The GetStatsContext which is associated with this context | 116 | * The GetStatsContext which is associated with this context |
120 | */ | 117 | */ |
@@ -152,14 +149,14 @@ static struct OperationQueue *no_wait_queue; | |||
152 | * @param cls the GetStatsContext | 149 | * @param cls the GetStatsContext |
153 | */ | 150 | */ |
154 | static void | 151 | static void |
155 | call_completion_task (void *cls) | 152 | call_completion_task(void *cls) |
156 | { | 153 | { |
157 | struct GetStatsContext *sc = cls; | 154 | struct GetStatsContext *sc = cls; |
158 | 155 | ||
159 | GNUNET_assert (sc->call_completion_task_id != NULL); | 156 | GNUNET_assert(sc->call_completion_task_id != NULL); |
160 | sc->call_completion_task_id = NULL; | 157 | sc->call_completion_task_id = NULL; |
161 | LOG_DEBUG ("Calling get_statistics() continuation callback\n"); | 158 | LOG_DEBUG("Calling get_statistics() continuation callback\n"); |
162 | sc->cont (sc->cb_cls, sc->main_op, NULL); | 159 | sc->cont(sc->cb_cls, sc->main_op, NULL); |
163 | } | 160 | } |
164 | 161 | ||
165 | 162 | ||
@@ -170,7 +167,7 @@ call_completion_task (void *cls) | |||
170 | * @param cls the PeerGetStatsContext | 167 | * @param cls the PeerGetStatsContext |
171 | */ | 168 | */ |
172 | static void | 169 | static void |
173 | op_done_task (void *cls) | 170 | op_done_task(void *cls) |
174 | { | 171 | { |
175 | struct PeerGetStatsContext *peer_sc = cls; | 172 | struct PeerGetStatsContext *peer_sc = cls; |
176 | struct GetStatsContext *sc; | 173 | struct GetStatsContext *sc; |
@@ -179,8 +176,8 @@ op_done_task (void *cls) | |||
179 | sc = peer_sc->sc; | 176 | sc = peer_sc->sc; |
180 | peer_sc->op_done_task_id = NULL; | 177 | peer_sc->op_done_task_id = NULL; |
181 | op = &sc->ops[peer_sc->peer_index]; | 178 | op = &sc->ops[peer_sc->peer_index]; |
182 | GNUNET_assert (NULL != *op); | 179 | GNUNET_assert(NULL != *op); |
183 | GNUNET_TESTBED_operation_done (*op); | 180 | GNUNET_TESTBED_operation_done(*op); |
184 | *op = NULL; | 181 | *op = NULL; |
185 | } | 182 | } |
186 | 183 | ||
@@ -193,22 +190,22 @@ op_done_task (void *cls) | |||
193 | * successfully obtained, GNUNET_SYSERR if not. | 190 | * successfully obtained, GNUNET_SYSERR if not. |
194 | */ | 191 | */ |
195 | static void | 192 | static void |
196 | iteration_completion_cb (void *cls, int success) | 193 | iteration_completion_cb(void *cls, int success) |
197 | { | 194 | { |
198 | struct PeerGetStatsContext *peer_sc = cls; | 195 | struct PeerGetStatsContext *peer_sc = cls; |
199 | struct GetStatsContext *sc; | 196 | struct GetStatsContext *sc; |
200 | 197 | ||
201 | GNUNET_break (GNUNET_OK == success); | 198 | GNUNET_break(GNUNET_OK == success); |
202 | sc = peer_sc->sc; | 199 | sc = peer_sc->sc; |
203 | peer_sc->get_handle = NULL; | 200 | peer_sc->get_handle = NULL; |
204 | sc->num_completed++; | 201 | sc->num_completed++; |
205 | peer_sc->op_done_task_id = GNUNET_SCHEDULER_add_now (&op_done_task, peer_sc); | 202 | peer_sc->op_done_task_id = GNUNET_SCHEDULER_add_now(&op_done_task, peer_sc); |
206 | if (sc->num_completed == sc->num_peers) | 203 | if (sc->num_completed == sc->num_peers) |
207 | { | 204 | { |
208 | LOG_DEBUG ("Scheduling to call iteration completion callback\n"); | 205 | LOG_DEBUG("Scheduling to call iteration completion callback\n"); |
209 | sc->call_completion_task_id = | 206 | sc->call_completion_task_id = |
210 | GNUNET_SCHEDULER_add_now (&call_completion_task, sc); | 207 | GNUNET_SCHEDULER_add_now(&call_completion_task, sc); |
211 | } | 208 | } |
212 | } | 209 | } |
213 | 210 | ||
214 | 211 | ||
@@ -223,9 +220,9 @@ iteration_completion_cb (void *cls, int success) | |||
223 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | 220 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration |
224 | */ | 221 | */ |
225 | static int | 222 | static int |
226 | iterator_cb (void *cls, const char *subsystem, | 223 | iterator_cb(void *cls, const char *subsystem, |
227 | const char *name, uint64_t value, | 224 | const char *name, uint64_t value, |
228 | int is_persistent) | 225 | int is_persistent) |
229 | { | 226 | { |
230 | struct PeerGetStatsContext *peer_sc = cls; | 227 | struct PeerGetStatsContext *peer_sc = cls; |
231 | struct GetStatsContext *sc; | 228 | struct GetStatsContext *sc; |
@@ -234,12 +231,12 @@ iterator_cb (void *cls, const char *subsystem, | |||
234 | 231 | ||
235 | sc = peer_sc->sc; | 232 | sc = peer_sc->sc; |
236 | peer = sc->peers[peer_sc->peer_index]; | 233 | peer = sc->peers[peer_sc->peer_index]; |
237 | LOG_DEBUG ("Peer %u: [%s,%s] -> %lu\n", peer_sc->peer_index, | 234 | LOG_DEBUG("Peer %u: [%s,%s] -> %lu\n", peer_sc->peer_index, |
238 | subsystem, name, (unsigned long) value); | 235 | subsystem, name, (unsigned long)value); |
239 | ret = sc->proc (sc->cb_cls, peer, | 236 | ret = sc->proc(sc->cb_cls, peer, |
240 | subsystem, name, value, is_persistent); | 237 | subsystem, name, value, is_persistent); |
241 | if (GNUNET_SYSERR == ret) | 238 | if (GNUNET_SYSERR == ret) |
242 | LOG_DEBUG ("Aborting iteration for peer %u\n", peer_sc->peer_index); | 239 | LOG_DEBUG("Aborting iteration for peer %u\n", peer_sc->peer_index); |
243 | return ret; | 240 | return ret; |
244 | } | 241 | } |
245 | 242 | ||
@@ -254,21 +251,21 @@ iterator_cb (void *cls, const char *subsystem, | |||
254 | * operation has executed successfully. | 251 | * operation has executed successfully. |
255 | */ | 252 | */ |
256 | static void | 253 | static void |
257 | service_connect_comp (void *cls, | 254 | service_connect_comp(void *cls, |
258 | struct GNUNET_TESTBED_Operation *op, | 255 | struct GNUNET_TESTBED_Operation *op, |
259 | void *ca_result, | 256 | void *ca_result, |
260 | const char *emsg) | 257 | const char *emsg) |
261 | { | 258 | { |
262 | struct PeerGetStatsContext *peer_sc = cls; | 259 | struct PeerGetStatsContext *peer_sc = cls; |
263 | struct GNUNET_STATISTICS_Handle *h = ca_result; | 260 | struct GNUNET_STATISTICS_Handle *h = ca_result; |
264 | 261 | ||
265 | LOG_DEBUG ("Retrieving statistics of peer %u\n", | 262 | LOG_DEBUG("Retrieving statistics of peer %u\n", |
266 | peer_sc->peer_index); | 263 | peer_sc->peer_index); |
267 | peer_sc->get_handle = | 264 | peer_sc->get_handle = |
268 | GNUNET_STATISTICS_get (h, peer_sc->sc->subsystem, | 265 | GNUNET_STATISTICS_get(h, peer_sc->sc->subsystem, |
269 | peer_sc->sc->name, | 266 | peer_sc->sc->name, |
270 | &iteration_completion_cb, | 267 | &iteration_completion_cb, |
271 | iterator_cb, peer_sc); | 268 | iterator_cb, peer_sc); |
272 | } | 269 | } |
273 | 270 | ||
274 | 271 | ||
@@ -283,13 +280,13 @@ service_connect_comp (void *cls, | |||
283 | * @return service handle to return in 'op_result', NULL on error | 280 | * @return service handle to return in 'op_result', NULL on error |
284 | */ | 281 | */ |
285 | static void * | 282 | static void * |
286 | statistics_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 283 | statistics_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
287 | { | 284 | { |
288 | struct PeerGetStatsContext *peer_sc = cls; | 285 | struct PeerGetStatsContext *peer_sc = cls; |
289 | 286 | ||
290 | LOG_DEBUG ("Connecting to statistics service of peer %u\n", | 287 | LOG_DEBUG("Connecting to statistics service of peer %u\n", |
291 | peer_sc->peer_index); | 288 | peer_sc->peer_index); |
292 | return GNUNET_STATISTICS_create ("<testbed-api>", cfg); | 289 | return GNUNET_STATISTICS_create("<testbed-api>", cfg); |
293 | } | 290 | } |
294 | 291 | ||
295 | 292 | ||
@@ -300,20 +297,20 @@ statistics_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
300 | * @param op_result service handle returned from the connect adapter | 297 | * @param op_result service handle returned from the connect adapter |
301 | */ | 298 | */ |
302 | static void | 299 | static void |
303 | statistics_da (void *cls, void *op_result) | 300 | statistics_da(void *cls, void *op_result) |
304 | { | 301 | { |
305 | struct PeerGetStatsContext *peer_sc = cls; | 302 | struct PeerGetStatsContext *peer_sc = cls; |
306 | struct GNUNET_STATISTICS_Handle *sh = op_result; | 303 | struct GNUNET_STATISTICS_Handle *sh = op_result; |
307 | 304 | ||
308 | if (NULL != peer_sc->get_handle) | 305 | if (NULL != peer_sc->get_handle) |
309 | { | 306 | { |
310 | GNUNET_STATISTICS_get_cancel (peer_sc->get_handle); | 307 | GNUNET_STATISTICS_get_cancel(peer_sc->get_handle); |
311 | peer_sc->get_handle = NULL; | 308 | peer_sc->get_handle = NULL; |
312 | } | 309 | } |
313 | GNUNET_STATISTICS_destroy (sh, GNUNET_NO); | 310 | GNUNET_STATISTICS_destroy(sh, GNUNET_NO); |
314 | if (NULL != peer_sc->op_done_task_id) | 311 | if (NULL != peer_sc->op_done_task_id) |
315 | GNUNET_SCHEDULER_cancel (peer_sc->op_done_task_id); | 312 | GNUNET_SCHEDULER_cancel(peer_sc->op_done_task_id); |
316 | GNUNET_free (peer_sc); | 313 | GNUNET_free(peer_sc); |
317 | } | 314 | } |
318 | 315 | ||
319 | 316 | ||
@@ -323,33 +320,33 @@ statistics_da (void *cls, void *op_result) | |||
323 | * @param cls the GetStatsContext | 320 | * @param cls the GetStatsContext |
324 | */ | 321 | */ |
325 | static void | 322 | static void |
326 | opstart_get_stats (void *cls) | 323 | opstart_get_stats(void *cls) |
327 | { | 324 | { |
328 | struct GetStatsContext *sc = cls; | 325 | struct GetStatsContext *sc = cls; |
329 | struct PeerGetStatsContext *peer_sc; | 326 | struct PeerGetStatsContext *peer_sc; |
330 | unsigned int peer; | 327 | unsigned int peer; |
331 | 328 | ||
332 | LOG_DEBUG ("Starting get_statistics operation\n"); | 329 | LOG_DEBUG("Starting get_statistics operation\n"); |
333 | sc->ops = GNUNET_malloc (sc->num_peers * | 330 | sc->ops = GNUNET_malloc(sc->num_peers * |
334 | sizeof (struct GNUNET_TESTBED_Operation *)); | 331 | sizeof(struct GNUNET_TESTBED_Operation *)); |
335 | for (peer = 0; peer < sc->num_peers; peer++) | 332 | for (peer = 0; peer < sc->num_peers; peer++) |
336 | { | ||
337 | if (NULL == sc->peers[peer]) | ||
338 | { | 333 | { |
339 | GNUNET_break (0); | 334 | if (NULL == sc->peers[peer]) |
340 | continue; | 335 | { |
336 | GNUNET_break(0); | ||
337 | continue; | ||
338 | } | ||
339 | peer_sc = GNUNET_new(struct PeerGetStatsContext); | ||
340 | peer_sc->sc = sc; | ||
341 | peer_sc->peer_index = peer; | ||
342 | sc->ops[peer] = | ||
343 | GNUNET_TESTBED_service_connect(sc, sc->peers[peer], "statistics", | ||
344 | &service_connect_comp, | ||
345 | peer_sc, | ||
346 | &statistics_ca, | ||
347 | &statistics_da, | ||
348 | peer_sc); | ||
341 | } | 349 | } |
342 | peer_sc = GNUNET_new (struct PeerGetStatsContext); | ||
343 | peer_sc->sc = sc; | ||
344 | peer_sc->peer_index = peer; | ||
345 | sc->ops[peer] = | ||
346 | GNUNET_TESTBED_service_connect (sc, sc->peers[peer], "statistics", | ||
347 | &service_connect_comp, | ||
348 | peer_sc, | ||
349 | &statistics_ca, | ||
350 | &statistics_da, | ||
351 | peer_sc); | ||
352 | } | ||
353 | } | 350 | } |
354 | 351 | ||
355 | 352 | ||
@@ -359,31 +356,31 @@ opstart_get_stats (void *cls) | |||
359 | * @param cls the GetStatsContext | 356 | * @param cls the GetStatsContext |
360 | */ | 357 | */ |
361 | static void | 358 | static void |
362 | oprelease_get_stats (void *cls) | 359 | oprelease_get_stats(void *cls) |
363 | { | 360 | { |
364 | struct GetStatsContext *sc = cls; | 361 | struct GetStatsContext *sc = cls; |
365 | unsigned int peer; | 362 | unsigned int peer; |
366 | 363 | ||
367 | LOG_DEBUG ("Cleaning up get_statistics operation\n"); | 364 | LOG_DEBUG("Cleaning up get_statistics operation\n"); |
368 | if (NULL != sc->call_completion_task_id) | 365 | if (NULL != sc->call_completion_task_id) |
369 | GNUNET_SCHEDULER_cancel (sc->call_completion_task_id); | 366 | GNUNET_SCHEDULER_cancel(sc->call_completion_task_id); |
370 | if (NULL != sc->ops) | 367 | if (NULL != sc->ops) |
371 | { | ||
372 | for (peer = 0; peer < sc->num_peers; peer++) | ||
373 | { | 368 | { |
374 | if (NULL != sc->ops[peer]) | 369 | for (peer = 0; peer < sc->num_peers; peer++) |
375 | { | 370 | { |
376 | GNUNET_TESTBED_operation_done (sc->ops[peer]); | 371 | if (NULL != sc->ops[peer]) |
377 | sc->ops[peer] = NULL; | 372 | { |
378 | } | 373 | GNUNET_TESTBED_operation_done(sc->ops[peer]); |
374 | sc->ops[peer] = NULL; | ||
375 | } | ||
376 | } | ||
377 | GNUNET_free(sc->ops); | ||
379 | } | 378 | } |
380 | GNUNET_free (sc->ops); | 379 | GNUNET_free_non_null(sc->subsystem); |
381 | } | 380 | GNUNET_free_non_null(sc->name); |
382 | GNUNET_free_non_null (sc->subsystem); | 381 | GNUNET_free(sc); |
383 | GNUNET_free_non_null (sc->name); | ||
384 | GNUNET_free (sc); | ||
385 | if (GNUNET_YES == | 382 | if (GNUNET_YES == |
386 | GNUNET_TESTBED_operation_queue_destroy_empty_ (no_wait_queue)) | 383 | GNUNET_TESTBED_operation_queue_destroy_empty_(no_wait_queue)) |
387 | no_wait_queue = NULL; | 384 | no_wait_queue = NULL; |
388 | } | 385 | } |
389 | 386 | ||
@@ -402,33 +399,33 @@ oprelease_get_stats (void *cls) | |||
402 | * @return operation handle to cancel the operation | 399 | * @return operation handle to cancel the operation |
403 | */ | 400 | */ |
404 | struct GNUNET_TESTBED_Operation * | 401 | struct GNUNET_TESTBED_Operation * |
405 | GNUNET_TESTBED_get_statistics (unsigned int num_peers, | 402 | GNUNET_TESTBED_get_statistics(unsigned int num_peers, |
406 | struct GNUNET_TESTBED_Peer **peers, | 403 | struct GNUNET_TESTBED_Peer **peers, |
407 | const char *subsystem, const char *name, | 404 | const char *subsystem, const char *name, |
408 | GNUNET_TESTBED_StatisticsIterator proc, | 405 | GNUNET_TESTBED_StatisticsIterator proc, |
409 | GNUNET_TESTBED_OperationCompletionCallback cont, | 406 | GNUNET_TESTBED_OperationCompletionCallback cont, |
410 | void *cls) | 407 | void *cls) |
411 | { | 408 | { |
412 | struct GetStatsContext *sc; | 409 | struct GetStatsContext *sc; |
413 | 410 | ||
414 | GNUNET_assert (NULL != proc); | 411 | GNUNET_assert(NULL != proc); |
415 | GNUNET_assert (NULL != cont); | 412 | GNUNET_assert(NULL != cont); |
416 | if (NULL == no_wait_queue) | 413 | if (NULL == no_wait_queue) |
417 | no_wait_queue = GNUNET_TESTBED_operation_queue_create_ | 414 | no_wait_queue = GNUNET_TESTBED_operation_queue_create_ |
418 | (OPERATION_QUEUE_TYPE_FIXED, UINT_MAX); | 415 | (OPERATION_QUEUE_TYPE_FIXED, UINT_MAX); |
419 | sc = GNUNET_new (struct GetStatsContext); | 416 | sc = GNUNET_new(struct GetStatsContext); |
420 | sc->peers = peers; | 417 | sc->peers = peers; |
421 | sc->subsystem = (NULL == subsystem) ? NULL : GNUNET_strdup (subsystem); | 418 | sc->subsystem = (NULL == subsystem) ? NULL : GNUNET_strdup(subsystem); |
422 | sc->name = (NULL == name) ? NULL : GNUNET_strdup (name); | 419 | sc->name = (NULL == name) ? NULL : GNUNET_strdup(name); |
423 | sc->proc = proc; | 420 | sc->proc = proc; |
424 | sc->cont = cont; | 421 | sc->cont = cont; |
425 | sc->cb_cls = cls; | 422 | sc->cb_cls = cls; |
426 | sc->num_peers = num_peers; | 423 | sc->num_peers = num_peers; |
427 | sc->main_op = | 424 | sc->main_op = |
428 | GNUNET_TESTBED_operation_create_ (sc, &opstart_get_stats, | 425 | GNUNET_TESTBED_operation_create_(sc, &opstart_get_stats, |
429 | &oprelease_get_stats); | 426 | &oprelease_get_stats); |
430 | GNUNET_TESTBED_operation_queue_insert_ (no_wait_queue, sc->main_op); | 427 | GNUNET_TESTBED_operation_queue_insert_(no_wait_queue, sc->main_op); |
431 | GNUNET_TESTBED_operation_begin_wait_ (sc->main_op); | 428 | GNUNET_TESTBED_operation_begin_wait_(sc->main_op); |
432 | return sc->main_op; | 429 | return sc->main_op; |
433 | } | 430 | } |
434 | 431 | ||
diff --git a/src/testbed/testbed_api_test.c b/src/testbed/testbed_api_test.c index 3f9400bda..7294a137e 100644 --- a/src/testbed/testbed_api_test.c +++ b/src/testbed/testbed_api_test.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -31,8 +31,7 @@ | |||
31 | /** | 31 | /** |
32 | * Context information for test run | 32 | * Context information for test run |
33 | */ | 33 | */ |
34 | struct TestRunContext | 34 | struct TestRunContext { |
35 | { | ||
36 | /** | 35 | /** |
37 | * Test master callback | 36 | * Test master callback |
38 | */ | 37 | */ |
@@ -74,13 +73,13 @@ struct TestRunContext | |||
74 | * @param config the configuration file handle | 73 | * @param config the configuration file handle |
75 | */ | 74 | */ |
76 | static void | 75 | static void |
77 | run (void *cls, char *const *args, const char *cfgfile, | 76 | run(void *cls, char *const *args, const char *cfgfile, |
78 | const struct GNUNET_CONFIGURATION_Handle *config) | 77 | const struct GNUNET_CONFIGURATION_Handle *config) |
79 | { | 78 | { |
80 | struct TestRunContext *rc = cls; | 79 | struct TestRunContext *rc = cls; |
81 | 80 | ||
82 | GNUNET_TESTBED_run (NULL, config, rc->num_peers, rc->event_mask, rc->cc, | 81 | GNUNET_TESTBED_run(NULL, config, rc->num_peers, rc->event_mask, rc->cc, |
83 | rc->cc_cls, rc->test_master, rc->test_master_cls); | 82 | rc->cc_cls, rc->test_master, rc->test_master_cls); |
84 | } | 83 | } |
85 | 84 | ||
86 | 85 | ||
@@ -118,14 +117,14 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
118 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | 117 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success |
119 | */ | 118 | */ |
120 | int | 119 | int |
121 | GNUNET_TESTBED_test_run (const char *testname, | 120 | GNUNET_TESTBED_test_run(const char *testname, |
122 | const char *cfg_filename, | 121 | const char *cfg_filename, |
123 | unsigned int num_peers, | 122 | unsigned int num_peers, |
124 | uint64_t event_mask, | 123 | uint64_t event_mask, |
125 | GNUNET_TESTBED_ControllerCallback cc, | 124 | GNUNET_TESTBED_ControllerCallback cc, |
126 | void *cc_cls, | 125 | void *cc_cls, |
127 | GNUNET_TESTBED_TestMaster test_master, | 126 | GNUNET_TESTBED_TestMaster test_master, |
128 | void *test_master_cls) | 127 | void *test_master_cls) |
129 | { | 128 | { |
130 | char *argv2[] = { | 129 | char *argv2[] = { |
131 | NULL, | 130 | NULL, |
@@ -139,23 +138,23 @@ GNUNET_TESTBED_test_run (const char *testname, | |||
139 | struct TestRunContext *rc; | 138 | struct TestRunContext *rc; |
140 | int ret; | 139 | int ret; |
141 | 140 | ||
142 | argv2[0] = GNUNET_strdup (testname); | 141 | argv2[0] = GNUNET_strdup(testname); |
143 | argv2[2] = GNUNET_strdup (cfg_filename); | 142 | argv2[2] = GNUNET_strdup(cfg_filename); |
144 | GNUNET_assert (NULL != test_master); | 143 | GNUNET_assert(NULL != test_master); |
145 | GNUNET_assert (num_peers > 0); | 144 | GNUNET_assert(num_peers > 0); |
146 | rc = GNUNET_malloc (sizeof (struct TestRunContext) + | 145 | rc = GNUNET_malloc(sizeof(struct TestRunContext) + |
147 | (num_peers * sizeof (struct GNUNET_TESTBED_Peer *))); | 146 | (num_peers * sizeof(struct GNUNET_TESTBED_Peer *))); |
148 | rc->test_master = test_master; | 147 | rc->test_master = test_master; |
149 | rc->test_master_cls = test_master_cls; | 148 | rc->test_master_cls = test_master_cls; |
150 | rc->num_peers = num_peers; | 149 | rc->num_peers = num_peers; |
151 | rc->event_mask = event_mask; | 150 | rc->event_mask = event_mask; |
152 | rc->cc = cc; | 151 | rc->cc = cc; |
153 | rc->cc_cls = cc_cls; | 152 | rc->cc_cls = cc_cls; |
154 | ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | 153 | ret = GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, |
155 | testname, "nohelp", options, &run, rc); | 154 | testname, "nohelp", options, &run, rc); |
156 | GNUNET_free (rc); | 155 | GNUNET_free(rc); |
157 | GNUNET_free (argv2[0]); | 156 | GNUNET_free(argv2[0]); |
158 | GNUNET_free (argv2[2]); | 157 | GNUNET_free(argv2[2]); |
159 | return ret; | 158 | return ret; |
160 | } | 159 | } |
161 | 160 | ||
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c index c61934a40..4615afca9 100644 --- a/src/testbed/testbed_api_testbed.c +++ b/src/testbed/testbed_api_testbed.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2008--2013 GNUnet e.V. | 3 | Copyright (C) 2008--2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/testbed_api_testbed.c | 22 | * @file testbed/testbed_api_testbed.c |
@@ -36,14 +36,14 @@ | |||
36 | /** | 36 | /** |
37 | * Generic loggins shorthand | 37 | * Generic loggins shorthand |
38 | */ | 38 | */ |
39 | #define LOG(kind,...) \ | 39 | #define LOG(kind, ...) \ |
40 | GNUNET_log_from (kind, "testbed-api-testbed", __VA_ARGS__) | 40 | GNUNET_log_from(kind, "testbed-api-testbed", __VA_ARGS__) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Debug logging shortcut | 43 | * Debug logging shortcut |
44 | */ | 44 | */ |
45 | #define DEBUG(...) \ | 45 | #define DEBUG(...) \ |
46 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 46 | LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * The default setup timeout in seconds | 49 | * The default setup timeout in seconds |
@@ -71,8 +71,7 @@ | |||
71 | /** | 71 | /** |
72 | * Context information for the operation we start | 72 | * Context information for the operation we start |
73 | */ | 73 | */ |
74 | struct RunContextOperation | 74 | struct RunContextOperation { |
75 | { | ||
76 | /** | 75 | /** |
77 | * The testbed operation handle | 76 | * The testbed operation handle |
78 | */ | 77 | */ |
@@ -87,15 +86,13 @@ struct RunContextOperation | |||
87 | * Closure | 86 | * Closure |
88 | */ | 87 | */ |
89 | void *cls; | 88 | void *cls; |
90 | |||
91 | }; | 89 | }; |
92 | 90 | ||
93 | 91 | ||
94 | /** | 92 | /** |
95 | * States of RunContext | 93 | * States of RunContext |
96 | */ | 94 | */ |
97 | enum State | 95 | enum State { |
98 | { | ||
99 | /** | 96 | /** |
100 | * Initial state | 97 | * Initial state |
101 | */ | 98 | */ |
@@ -138,8 +135,7 @@ enum State | |||
138 | /** | 135 | /** |
139 | * Context for host compability checks | 136 | * Context for host compability checks |
140 | */ | 137 | */ |
141 | struct CompatibilityCheckContext | 138 | struct CompatibilityCheckContext { |
142 | { | ||
143 | /** | 139 | /** |
144 | * The run context | 140 | * The run context |
145 | */ | 141 | */ |
@@ -160,8 +156,7 @@ struct CompatibilityCheckContext | |||
160 | /** | 156 | /** |
161 | * Testbed Run Handle | 157 | * Testbed Run Handle |
162 | */ | 158 | */ |
163 | struct GNUNET_TESTBED_RunHandle | 159 | struct GNUNET_TESTBED_RunHandle { |
164 | { | ||
165 | /** | 160 | /** |
166 | * The controller handle | 161 | * The controller handle |
167 | */ | 162 | */ |
@@ -326,7 +321,6 @@ struct GNUNET_TESTBED_RunHandle | |||
326 | * the number of overlay link connection attempts that failed | 321 | * the number of overlay link connection attempts that failed |
327 | */ | 322 | */ |
328 | unsigned int links_failed; | 323 | unsigned int links_failed; |
329 | |||
330 | }; | 324 | }; |
331 | 325 | ||
332 | 326 | ||
@@ -337,17 +331,16 @@ struct GNUNET_TESTBED_RunHandle | |||
337 | * @return 32-bit key | 331 | * @return 32-bit key |
338 | */ | 332 | */ |
339 | static uint32_t | 333 | static uint32_t |
340 | rcop_key (void *rcop) | 334 | rcop_key(void *rcop) |
341 | { | 335 | { |
342 | return * ((uint32_t *) &rcop); | 336 | return *((uint32_t *)&rcop); |
343 | } | 337 | } |
344 | 338 | ||
345 | 339 | ||
346 | /** | 340 | /** |
347 | * Context information used for finding a pointer in the rcop_map | 341 | * Context information used for finding a pointer in the rcop_map |
348 | */ | 342 | */ |
349 | struct SearchContext | 343 | struct SearchContext { |
350 | { | ||
351 | /** | 344 | /** |
352 | * The operation pointer to look for | 345 | * The operation pointer to look for |
353 | */ | 346 | */ |
@@ -369,18 +362,18 @@ struct SearchContext | |||
369 | * @return GNUNET_YES to continue iteration; GNUNET_NO to cancel it | 362 | * @return GNUNET_YES to continue iteration; GNUNET_NO to cancel it |
370 | */ | 363 | */ |
371 | static int | 364 | static int |
372 | search_iterator (void *cls, uint32_t key, void *value) | 365 | search_iterator(void *cls, uint32_t key, void *value) |
373 | { | 366 | { |
374 | struct RunContextOperation *rcop = value; | 367 | struct RunContextOperation *rcop = value; |
375 | struct SearchContext *sc = cls; | 368 | struct SearchContext *sc = cls; |
376 | 369 | ||
377 | GNUNET_assert (NULL != rcop); | 370 | GNUNET_assert(NULL != rcop); |
378 | if (sc->query == rcop->op) | 371 | if (sc->query == rcop->op) |
379 | { | 372 | { |
380 | GNUNET_assert (NULL == sc->result); | 373 | GNUNET_assert(NULL == sc->result); |
381 | sc->result = rcop; | 374 | sc->result = rcop; |
382 | return GNUNET_NO; | 375 | return GNUNET_NO; |
383 | } | 376 | } |
384 | return GNUNET_YES; | 377 | return GNUNET_YES; |
385 | } | 378 | } |
386 | 379 | ||
@@ -394,21 +387,21 @@ search_iterator (void *cls, uint32_t key, void *value) | |||
394 | * @return the matching RunContextOperation if found; NULL if not | 387 | * @return the matching RunContextOperation if found; NULL if not |
395 | */ | 388 | */ |
396 | static struct RunContextOperation * | 389 | static struct RunContextOperation * |
397 | search_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct GNUNET_TESTBED_Operation *op) | 390 | search_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct GNUNET_TESTBED_Operation *op) |
398 | { | 391 | { |
399 | struct SearchContext sc; | 392 | struct SearchContext sc; |
400 | 393 | ||
401 | sc.query = op; | 394 | sc.query = op; |
402 | sc.result = NULL; | 395 | sc.result = NULL; |
403 | if (GNUNET_SYSERR == | 396 | if (GNUNET_SYSERR == |
404 | GNUNET_CONTAINER_multihashmap32_get_multiple (rc->rcop_map, | 397 | GNUNET_CONTAINER_multihashmap32_get_multiple(rc->rcop_map, |
405 | rcop_key (op), | 398 | rcop_key(op), |
406 | &search_iterator, | 399 | &search_iterator, |
407 | &sc)) | 400 | &sc)) |
408 | { | 401 | { |
409 | GNUNET_assert (NULL != sc.result); | 402 | GNUNET_assert(NULL != sc.result); |
410 | return sc.result; | 403 | return sc.result; |
411 | } | 404 | } |
412 | return NULL; | 405 | return NULL; |
413 | } | 406 | } |
414 | 407 | ||
@@ -420,12 +413,12 @@ search_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct GNUNET_TESTBED_Operatio | |||
420 | * @param rcop the RunContextOperation to insert | 413 | * @param rcop the RunContextOperation to insert |
421 | */ | 414 | */ |
422 | static void | 415 | static void |
423 | insert_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rcop) | 416 | insert_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rcop) |
424 | { | 417 | { |
425 | GNUNET_assert (GNUNET_OK == | 418 | GNUNET_assert(GNUNET_OK == |
426 | GNUNET_CONTAINER_multihashmap32_put (rc->rcop_map, | 419 | GNUNET_CONTAINER_multihashmap32_put(rc->rcop_map, |
427 | rcop_key (rcop->op), rcop, | 420 | rcop_key(rcop->op), rcop, |
428 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 421 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
429 | } | 422 | } |
430 | 423 | ||
431 | 424 | ||
@@ -437,12 +430,12 @@ insert_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rc | |||
437 | * @param rcop the RunContextOperation | 430 | * @param rcop the RunContextOperation |
438 | */ | 431 | */ |
439 | static void | 432 | static void |
440 | remove_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rcop) | 433 | remove_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rcop) |
441 | { | 434 | { |
442 | GNUNET_assert (GNUNET_YES == | 435 | GNUNET_assert(GNUNET_YES == |
443 | GNUNET_CONTAINER_multihashmap32_remove (rc->rcop_map, | 436 | GNUNET_CONTAINER_multihashmap32_remove(rc->rcop_map, |
444 | rcop_key (rcop->op), | 437 | rcop_key(rcop->op), |
445 | rcop)); | 438 | rcop)); |
446 | } | 439 | } |
447 | 440 | ||
448 | /** | 441 | /** |
@@ -451,31 +444,31 @@ remove_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rc | |||
451 | * @param rc the run context | 444 | * @param rc the run context |
452 | */ | 445 | */ |
453 | static void | 446 | static void |
454 | cleanup (struct GNUNET_TESTBED_RunHandle *rc) | 447 | cleanup(struct GNUNET_TESTBED_RunHandle *rc) |
455 | { | 448 | { |
456 | unsigned int hid; | 449 | unsigned int hid; |
457 | 450 | ||
458 | GNUNET_assert (NULL == rc->register_hosts_task); | 451 | GNUNET_assert(NULL == rc->register_hosts_task); |
459 | GNUNET_assert (NULL == rc->reg_handle); | 452 | GNUNET_assert(NULL == rc->reg_handle); |
460 | GNUNET_assert (NULL == rc->peers); | 453 | GNUNET_assert(NULL == rc->peers); |
461 | GNUNET_assert (NULL == rc->hclist); | 454 | GNUNET_assert(NULL == rc->hclist); |
462 | GNUNET_assert (RC_PEERS_SHUTDOWN == rc->state); | 455 | GNUNET_assert(RC_PEERS_SHUTDOWN == rc->state); |
463 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (rc->rcop_map)); | 456 | GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap32_size(rc->rcop_map)); |
464 | GNUNET_CONTAINER_multihashmap32_destroy (rc->rcop_map); | 457 | GNUNET_CONTAINER_multihashmap32_destroy(rc->rcop_map); |
465 | if (NULL != rc->c) | 458 | if (NULL != rc->c) |
466 | GNUNET_TESTBED_controller_disconnect (rc->c); | 459 | GNUNET_TESTBED_controller_disconnect(rc->c); |
467 | if (NULL != rc->cproc) | 460 | if (NULL != rc->cproc) |
468 | GNUNET_TESTBED_controller_stop (rc->cproc); | 461 | GNUNET_TESTBED_controller_stop(rc->cproc); |
469 | if (NULL != rc->h) | 462 | if (NULL != rc->h) |
470 | GNUNET_TESTBED_host_destroy (rc->h); | 463 | GNUNET_TESTBED_host_destroy(rc->h); |
471 | for (hid = 0; hid < rc->num_hosts; hid++) | 464 | for (hid = 0; hid < rc->num_hosts; hid++) |
472 | GNUNET_TESTBED_host_destroy (rc->hosts[hid]); | 465 | GNUNET_TESTBED_host_destroy(rc->hosts[hid]); |
473 | GNUNET_free_non_null (rc->hosts); | 466 | GNUNET_free_non_null(rc->hosts); |
474 | if (NULL != rc->cfg) | 467 | if (NULL != rc->cfg) |
475 | GNUNET_CONFIGURATION_destroy (rc->cfg); | 468 | GNUNET_CONFIGURATION_destroy(rc->cfg); |
476 | GNUNET_free_non_null (rc->topo_file); | 469 | GNUNET_free_non_null(rc->topo_file); |
477 | GNUNET_free_non_null (rc->trusted_ip); | 470 | GNUNET_free_non_null(rc->trusted_ip); |
478 | GNUNET_free (rc); | 471 | GNUNET_free(rc); |
479 | } | 472 | } |
480 | 473 | ||
481 | 474 | ||
@@ -488,15 +481,15 @@ cleanup (struct GNUNET_TESTBED_RunHandle *rc) | |||
488 | * @return always GNUNET_YES | 481 | * @return always GNUNET_YES |
489 | */ | 482 | */ |
490 | static int | 483 | static int |
491 | rcop_cleanup_iterator (void *cls, uint32_t key, void *value) | 484 | rcop_cleanup_iterator(void *cls, uint32_t key, void *value) |
492 | { | 485 | { |
493 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 486 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
494 | struct RunContextOperation *rcop = value; | 487 | struct RunContextOperation *rcop = value; |
495 | 488 | ||
496 | GNUNET_assert (rc == rcop->rc); | 489 | GNUNET_assert(rc == rcop->rc); |
497 | remove_rcop (rc, rcop); | 490 | remove_rcop(rc, rcop); |
498 | GNUNET_TESTBED_operation_done (rcop->op); | 491 | GNUNET_TESTBED_operation_done(rcop->op); |
499 | GNUNET_free (rcop); | 492 | GNUNET_free(rcop); |
500 | return GNUNET_YES; | 493 | return GNUNET_YES; |
501 | } | 494 | } |
502 | 495 | ||
@@ -507,48 +500,48 @@ rcop_cleanup_iterator (void *cls, uint32_t key, void *value) | |||
507 | * @param rc the RunContext | 500 | * @param rc the RunContext |
508 | */ | 501 | */ |
509 | static void | 502 | static void |
510 | rc_cleanup_operations (struct GNUNET_TESTBED_RunHandle *rc) | 503 | rc_cleanup_operations(struct GNUNET_TESTBED_RunHandle *rc) |
511 | { | 504 | { |
512 | struct CompatibilityCheckContext *hc; | 505 | struct CompatibilityCheckContext *hc; |
513 | unsigned int nhost; | 506 | unsigned int nhost; |
514 | 507 | ||
515 | if (NULL != rc->hclist) | 508 | if (NULL != rc->hclist) |
516 | { | ||
517 | for (nhost = 0; nhost < rc->num_hosts; nhost++) | ||
518 | { | 509 | { |
519 | hc = &rc->hclist[nhost]; | 510 | for (nhost = 0; nhost < rc->num_hosts; nhost++) |
520 | if (NULL != hc->h) | 511 | { |
521 | GNUNET_TESTBED_is_host_habitable_cancel (hc->h); | 512 | hc = &rc->hclist[nhost]; |
513 | if (NULL != hc->h) | ||
514 | GNUNET_TESTBED_is_host_habitable_cancel(hc->h); | ||
515 | } | ||
516 | GNUNET_free(rc->hclist); | ||
517 | rc->hclist = NULL; | ||
522 | } | 518 | } |
523 | GNUNET_free (rc->hclist); | ||
524 | rc->hclist = NULL; | ||
525 | } | ||
526 | /* Stop register hosts task if it is running */ | 519 | /* Stop register hosts task if it is running */ |
527 | if (NULL != rc->register_hosts_task) | 520 | if (NULL != rc->register_hosts_task) |
528 | { | 521 | { |
529 | GNUNET_SCHEDULER_cancel (rc->register_hosts_task); | 522 | GNUNET_SCHEDULER_cancel(rc->register_hosts_task); |
530 | rc->register_hosts_task = NULL; | 523 | rc->register_hosts_task = NULL; |
531 | } | 524 | } |
532 | if (NULL != rc->timeout_task) | 525 | if (NULL != rc->timeout_task) |
533 | { | 526 | { |
534 | GNUNET_SCHEDULER_cancel (rc->timeout_task); | 527 | GNUNET_SCHEDULER_cancel(rc->timeout_task); |
535 | rc->timeout_task = NULL; | 528 | rc->timeout_task = NULL; |
536 | } | 529 | } |
537 | if (NULL != rc->reg_handle) | 530 | if (NULL != rc->reg_handle) |
538 | { | 531 | { |
539 | GNUNET_TESTBED_cancel_registration (rc->reg_handle); | 532 | GNUNET_TESTBED_cancel_registration(rc->reg_handle); |
540 | rc->reg_handle = NULL; | 533 | rc->reg_handle = NULL; |
541 | } | 534 | } |
542 | if (NULL != rc->topology_operation) | 535 | if (NULL != rc->topology_operation) |
543 | { | 536 | { |
544 | GNUNET_TESTBED_operation_done (rc->topology_operation); | 537 | GNUNET_TESTBED_operation_done(rc->topology_operation); |
545 | rc->topology_operation = NULL; | 538 | rc->topology_operation = NULL; |
546 | } | 539 | } |
547 | /* cancel any exiting operations */ | 540 | /* cancel any exiting operations */ |
548 | GNUNET_assert (GNUNET_SYSERR != | 541 | GNUNET_assert(GNUNET_SYSERR != |
549 | GNUNET_CONTAINER_multihashmap32_iterate (rc->rcop_map, | 542 | GNUNET_CONTAINER_multihashmap32_iterate(rc->rcop_map, |
550 | &rcop_cleanup_iterator, | 543 | &rcop_cleanup_iterator, |
551 | rc)); | 544 | rc)); |
552 | } | 545 | } |
553 | 546 | ||
554 | 547 | ||
@@ -558,9 +551,9 @@ rc_cleanup_operations (struct GNUNET_TESTBED_RunHandle *rc) | |||
558 | * @param rc the run context | 551 | * @param rc the run context |
559 | */ | 552 | */ |
560 | static void | 553 | static void |
561 | cancel_interrupt_task (struct GNUNET_TESTBED_RunHandle *rc) | 554 | cancel_interrupt_task(struct GNUNET_TESTBED_RunHandle *rc) |
562 | { | 555 | { |
563 | GNUNET_SCHEDULER_cancel (rc->interrupt_task); | 556 | GNUNET_SCHEDULER_cancel(rc->interrupt_task); |
564 | rc->interrupt_task = NULL; | 557 | rc->interrupt_task = NULL; |
565 | } | 558 | } |
566 | 559 | ||
@@ -572,38 +565,38 @@ cancel_interrupt_task (struct GNUNET_TESTBED_RunHandle *rc) | |||
572 | * @param cls run context | 565 | * @param cls run context |
573 | */ | 566 | */ |
574 | static void | 567 | static void |
575 | wait_op_completion (void *cls) | 568 | wait_op_completion(void *cls) |
576 | { | 569 | { |
577 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 570 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
578 | struct RunContextOperation *rcop; | 571 | struct RunContextOperation *rcop; |
579 | 572 | ||
580 | if ( (NULL == rc->cproc) | 573 | if ((NULL == rc->cproc) |
581 | || (NULL == rc->c) | 574 | || (NULL == rc->c) |
582 | || (GNUNET_YES == rc->shutdown) ) | 575 | || (GNUNET_YES == rc->shutdown)) |
583 | { | ||
584 | if (NULL != rc->peers) | ||
585 | { | 576 | { |
586 | GNUNET_free (rc->peers); | 577 | if (NULL != rc->peers) |
587 | rc->peers = NULL; | 578 | { |
579 | GNUNET_free(rc->peers); | ||
580 | rc->peers = NULL; | ||
581 | } | ||
582 | goto cleanup_; | ||
588 | } | 583 | } |
589 | goto cleanup_; | ||
590 | } | ||
591 | if (NULL == rc->peers) | 584 | if (NULL == rc->peers) |
592 | goto cleanup_; | 585 | goto cleanup_; |
593 | rc->shutdown = GNUNET_YES; | 586 | rc->shutdown = GNUNET_YES; |
594 | rcop = GNUNET_new (struct RunContextOperation); | 587 | rcop = GNUNET_new(struct RunContextOperation); |
595 | rcop->rc = rc; | 588 | rcop->rc = rc; |
596 | rcop->op = GNUNET_TESTBED_shutdown_peers (rc->c, rcop, NULL, NULL); | 589 | rcop->op = GNUNET_TESTBED_shutdown_peers(rc->c, rcop, NULL, NULL); |
597 | GNUNET_assert (NULL != rcop->op); | 590 | GNUNET_assert(NULL != rcop->op); |
598 | DEBUG ("Shutting down peers\n"); | 591 | DEBUG("Shutting down peers\n"); |
599 | rc->pstart_time = GNUNET_TIME_absolute_get (); | 592 | rc->pstart_time = GNUNET_TIME_absolute_get(); |
600 | insert_rcop (rc, rcop); | 593 | insert_rcop(rc, rcop); |
601 | return; | 594 | return; |
602 | 595 | ||
603 | cleanup_: | 596 | cleanup_: |
604 | rc->state = RC_PEERS_SHUTDOWN; | 597 | rc->state = RC_PEERS_SHUTDOWN; |
605 | cancel_interrupt_task (rc); | 598 | cancel_interrupt_task(rc); |
606 | cleanup (rc); | 599 | cleanup(rc); |
607 | } | 600 | } |
608 | 601 | ||
609 | 602 | ||
@@ -613,28 +606,28 @@ wait_op_completion (void *cls) | |||
613 | * @param cls the RunContext which has to be acted upon | 606 | * @param cls the RunContext which has to be acted upon |
614 | */ | 607 | */ |
615 | static void | 608 | static void |
616 | interrupt (void *cls) | 609 | interrupt(void *cls) |
617 | { | 610 | { |
618 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 611 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
619 | struct GNUNET_TESTBED_Controller *c = rc->c; | 612 | struct GNUNET_TESTBED_Controller *c = rc->c; |
620 | unsigned int size; | 613 | unsigned int size; |
621 | 614 | ||
622 | /* reschedule */ | 615 | /* reschedule */ |
623 | rc->interrupt_task = GNUNET_SCHEDULER_add_shutdown (&interrupt, rc); | 616 | rc->interrupt_task = GNUNET_SCHEDULER_add_shutdown(&interrupt, rc); |
624 | rc_cleanup_operations (rc); | 617 | rc_cleanup_operations(rc); |
625 | if ( (GNUNET_NO == rc->shutdown) && | 618 | if ((GNUNET_NO == rc->shutdown) && |
626 | (NULL != c) && | 619 | (NULL != c) && |
627 | (NULL != c->opc_map) && | 620 | (NULL != c->opc_map) && |
628 | (0 != (size = GNUNET_CONTAINER_multihashmap32_size (c->opc_map)))) | 621 | (0 != (size = GNUNET_CONTAINER_multihashmap32_size(c->opc_map)))) |
629 | { | 622 | { |
630 | LOG (GNUNET_ERROR_TYPE_WARNING, | 623 | LOG(GNUNET_ERROR_TYPE_WARNING, |
631 | "Shutdown postponed as there are %u operations currently active\n", | 624 | "Shutdown postponed as there are %u operations currently active\n", |
632 | size); | 625 | size); |
633 | c->opcq_empty_cb = &wait_op_completion; | 626 | c->opcq_empty_cb = &wait_op_completion; |
634 | c->opcq_empty_cls = rc; | 627 | c->opcq_empty_cls = rc; |
635 | return; | 628 | return; |
636 | } | 629 | } |
637 | wait_op_completion (rc); | 630 | wait_op_completion(rc); |
638 | } | 631 | } |
639 | 632 | ||
640 | 633 | ||
@@ -646,12 +639,12 @@ interrupt (void *cls) | |||
646 | * @return the representation string; this is NOT reentrant | 639 | * @return the representation string; this is NOT reentrant |
647 | */ | 640 | */ |
648 | static const char * | 641 | static const char * |
649 | prof_time (struct GNUNET_TESTBED_RunHandle *rc) | 642 | prof_time(struct GNUNET_TESTBED_RunHandle *rc) |
650 | { | 643 | { |
651 | struct GNUNET_TIME_Relative ptime; | 644 | struct GNUNET_TIME_Relative ptime; |
652 | 645 | ||
653 | ptime = GNUNET_TIME_absolute_get_duration (rc->pstart_time); | 646 | ptime = GNUNET_TIME_absolute_get_duration(rc->pstart_time); |
654 | return GNUNET_STRINGS_relative_time_to_string (ptime, GNUNET_YES); | 647 | return GNUNET_STRINGS_relative_time_to_string(ptime, GNUNET_YES); |
655 | } | 648 | } |
656 | 649 | ||
657 | 650 | ||
@@ -661,23 +654,23 @@ prof_time (struct GNUNET_TESTBED_RunHandle *rc) | |||
661 | * @param cls the RunHandle | 654 | * @param cls the RunHandle |
662 | */ | 655 | */ |
663 | static void | 656 | static void |
664 | start_peers_task (void *cls) | 657 | start_peers_task(void *cls) |
665 | { | 658 | { |
666 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 659 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
667 | struct RunContextOperation *rcop; | 660 | struct RunContextOperation *rcop; |
668 | unsigned int peer; | 661 | unsigned int peer; |
669 | 662 | ||
670 | DEBUG ("Starting Peers\n"); | 663 | DEBUG("Starting Peers\n"); |
671 | rc->pstart_time = GNUNET_TIME_absolute_get (); | 664 | rc->pstart_time = GNUNET_TIME_absolute_get(); |
672 | for (peer = 0; peer < rc->num_peers; peer++) | 665 | for (peer = 0; peer < rc->num_peers; peer++) |
673 | { | 666 | { |
674 | rcop = GNUNET_new (struct RunContextOperation); | 667 | rcop = GNUNET_new(struct RunContextOperation); |
675 | rcop->rc = rc; | 668 | rcop->rc = rc; |
676 | rcop->op = GNUNET_TESTBED_peer_start (NULL, rc->peers[peer], NULL, NULL); | 669 | rcop->op = GNUNET_TESTBED_peer_start(NULL, rc->peers[peer], NULL, NULL); |
677 | GNUNET_assert (NULL != rcop->op); | 670 | GNUNET_assert(NULL != rcop->op); |
678 | rcop->cls = rc->peers[peer]; | 671 | rcop->cls = rc->peers[peer]; |
679 | insert_rcop (rc, rcop); | 672 | insert_rcop(rc, rcop); |
680 | } | 673 | } |
681 | rc->peer_count = 0; | 674 | rc->peer_count = 0; |
682 | } | 675 | } |
683 | 676 | ||
@@ -692,31 +685,31 @@ start_peers_task (void *cls) | |||
692 | * @param emsg NULL if peer is not NULL; else MAY contain the error description | 685 | * @param emsg NULL if peer is not NULL; else MAY contain the error description |
693 | */ | 686 | */ |
694 | static void | 687 | static void |
695 | peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | 688 | peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) |
696 | { | 689 | { |
697 | struct RunContextOperation *rcop = cls; | 690 | struct RunContextOperation *rcop = cls; |
698 | struct GNUNET_TESTBED_RunHandle *rc; | 691 | struct GNUNET_TESTBED_RunHandle *rc; |
699 | 692 | ||
700 | GNUNET_assert (NULL != rcop); | 693 | GNUNET_assert(NULL != rcop); |
701 | GNUNET_assert (NULL != (rc = rcop->rc)); | 694 | GNUNET_assert(NULL != (rc = rcop->rc)); |
702 | remove_rcop (rc, rcop); | 695 | remove_rcop(rc, rcop); |
703 | GNUNET_TESTBED_operation_done (rcop->op); | 696 | GNUNET_TESTBED_operation_done(rcop->op); |
704 | GNUNET_free (rcop); | 697 | GNUNET_free(rcop); |
705 | if (NULL == peer) | 698 | if (NULL == peer) |
706 | { | 699 | { |
707 | if (NULL != emsg) | 700 | if (NULL != emsg) |
708 | LOG (GNUNET_ERROR_TYPE_ERROR, "Error while creating a peer: %s\n", | 701 | LOG(GNUNET_ERROR_TYPE_ERROR, "Error while creating a peer: %s\n", |
709 | emsg); | 702 | emsg); |
710 | GNUNET_SCHEDULER_shutdown (); | 703 | GNUNET_SCHEDULER_shutdown(); |
711 | return; | 704 | return; |
712 | } | 705 | } |
713 | rc->peers[rc->peer_count] = peer; | 706 | rc->peers[rc->peer_count] = peer; |
714 | rc->peer_count++; | 707 | rc->peer_count++; |
715 | if (rc->peer_count < rc->num_peers) | 708 | if (rc->peer_count < rc->num_peers) |
716 | return; | 709 | return; |
717 | DEBUG ("%u peers created in %s\n", rc->num_peers, prof_time (rc)); | 710 | DEBUG("%u peers created in %s\n", rc->num_peers, prof_time(rc)); |
718 | rc->state = RC_PEERS_CREATED; | 711 | rc->state = RC_PEERS_CREATED; |
719 | GNUNET_SCHEDULER_add_now (&start_peers_task, rc); | 712 | GNUNET_SCHEDULER_add_now(&start_peers_task, rc); |
720 | } | 713 | } |
721 | 714 | ||
722 | 715 | ||
@@ -726,13 +719,13 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | |||
726 | * @param rc the RunContext | 719 | * @param rc the RunContext |
727 | */ | 720 | */ |
728 | static void | 721 | static void |
729 | call_master (struct GNUNET_TESTBED_RunHandle *rc) | 722 | call_master(struct GNUNET_TESTBED_RunHandle *rc) |
730 | { | 723 | { |
731 | GNUNET_SCHEDULER_cancel (rc->timeout_task); | 724 | GNUNET_SCHEDULER_cancel(rc->timeout_task); |
732 | rc->timeout_task = NULL; | 725 | rc->timeout_task = NULL; |
733 | if (NULL != rc->test_master) | 726 | if (NULL != rc->test_master) |
734 | rc->test_master (rc->test_master_cls, rc, rc->num_peers, rc->peers, | 727 | rc->test_master(rc->test_master_cls, rc, rc->num_peers, rc->peers, |
735 | rc->links_succeeded, rc->links_failed); | 728 | rc->links_succeeded, rc->links_failed); |
736 | } | 729 | } |
737 | 730 | ||
738 | 731 | ||
@@ -746,18 +739,18 @@ call_master (struct GNUNET_TESTBED_RunHandle *rc) | |||
746 | * @param nfailures the number of overlay connects which failed | 739 | * @param nfailures the number of overlay connects which failed |
747 | */ | 740 | */ |
748 | static void | 741 | static void |
749 | topology_completion_callback (void *cls, unsigned int nsuccess, | 742 | topology_completion_callback(void *cls, unsigned int nsuccess, |
750 | unsigned int nfailures) | 743 | unsigned int nfailures) |
751 | { | 744 | { |
752 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 745 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
753 | 746 | ||
754 | DEBUG ("Overlay topology generated in %s\n", prof_time (rc)); | 747 | DEBUG("Overlay topology generated in %s\n", prof_time(rc)); |
755 | GNUNET_TESTBED_operation_done (rc->topology_operation); | 748 | GNUNET_TESTBED_operation_done(rc->topology_operation); |
756 | rc->topology_operation = NULL; | 749 | rc->topology_operation = NULL; |
757 | rc->links_succeeded = nsuccess; | 750 | rc->links_succeeded = nsuccess; |
758 | rc->links_failed = nfailures; | 751 | rc->links_failed = nfailures; |
759 | rc->state = RC_READY; | 752 | rc->state = RC_READY; |
760 | call_master (rc); | 753 | call_master(rc); |
761 | } | 754 | } |
762 | 755 | ||
763 | 756 | ||
@@ -767,30 +760,30 @@ topology_completion_callback (void *cls, unsigned int nsuccess, | |||
767 | * @param rc the RunContext | 760 | * @param rc the RunContext |
768 | */ | 761 | */ |
769 | static void | 762 | static void |
770 | create_peers (struct GNUNET_TESTBED_RunHandle *rc) | 763 | create_peers(struct GNUNET_TESTBED_RunHandle *rc) |
771 | { | 764 | { |
772 | struct RunContextOperation *rcop; | 765 | struct RunContextOperation *rcop; |
773 | unsigned int peer; | 766 | unsigned int peer; |
774 | 767 | ||
775 | DEBUG ("Creating peers\n"); | 768 | DEBUG("Creating peers\n"); |
776 | rc->pstart_time = GNUNET_TIME_absolute_get (); | 769 | rc->pstart_time = GNUNET_TIME_absolute_get(); |
777 | rc->peers = | 770 | rc->peers = |
778 | GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer *) * rc->num_peers); | 771 | GNUNET_malloc(sizeof(struct GNUNET_TESTBED_Peer *) * rc->num_peers); |
779 | GNUNET_assert (NULL != rc->c); | 772 | GNUNET_assert(NULL != rc->c); |
780 | rc->peer_count = 0; | 773 | rc->peer_count = 0; |
781 | for (peer = 0; peer < rc->num_peers; peer++) | 774 | for (peer = 0; peer < rc->num_peers; peer++) |
782 | { | 775 | { |
783 | rcop = GNUNET_new (struct RunContextOperation); | 776 | rcop = GNUNET_new(struct RunContextOperation); |
784 | rcop->rc = rc; | 777 | rcop->rc = rc; |
785 | rcop->op = | 778 | rcop->op = |
786 | GNUNET_TESTBED_peer_create (rc->c, | 779 | GNUNET_TESTBED_peer_create(rc->c, |
787 | (0 == | 780 | (0 == |
788 | rc->num_hosts) ? rc->h : rc->hosts[peer % | 781 | rc->num_hosts) ? rc->h : rc->hosts[peer % |
789 | rc->num_hosts], | 782 | rc->num_hosts], |
790 | rc->cfg, &peer_create_cb, rcop); | 783 | rc->cfg, &peer_create_cb, rcop); |
791 | GNUNET_assert (NULL != rcop->op); | 784 | GNUNET_assert(NULL != rcop->op); |
792 | insert_rcop (rc, rcop); | 785 | insert_rcop(rc, rcop); |
793 | } | 786 | } |
794 | } | 787 | } |
795 | 788 | ||
796 | 789 | ||
@@ -802,160 +795,166 @@ create_peers (struct GNUNET_TESTBED_RunHandle *rc) | |||
802 | * @param event information about the event | 795 | * @param event information about the event |
803 | */ | 796 | */ |
804 | static void | 797 | static void |
805 | event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | 798 | event_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) |
806 | { | 799 | { |
807 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 800 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
808 | struct RunContextOperation *rcop; | 801 | struct RunContextOperation *rcop; |
809 | 802 | ||
810 | if (RC_INIT == rc->state) | 803 | if (RC_INIT == rc->state) |
811 | { | ||
812 | switch (event->type) | ||
813 | { | 804 | { |
814 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | 805 | switch (event->type) |
815 | rcop = event->op_cls; | 806 | { |
816 | if (NULL != event->details.operation_finished.emsg) | 807 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: |
817 | { | 808 | rcop = event->op_cls; |
818 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Linking controllers failed. Exiting")); | 809 | if (NULL != event->details.operation_finished.emsg) |
819 | GNUNET_SCHEDULER_shutdown (); | 810 | { |
820 | } | 811 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Linking controllers failed. Exiting")); |
821 | else | 812 | GNUNET_SCHEDULER_shutdown(); |
822 | rc->reg_hosts++; | 813 | } |
823 | GNUNET_assert (event->op == rcop->op); | 814 | else |
824 | remove_rcop (rc, rcop); | 815 | rc->reg_hosts++; |
825 | GNUNET_TESTBED_operation_done (rcop->op); | 816 | GNUNET_assert(event->op == rcop->op); |
826 | GNUNET_free (rcop); | 817 | remove_rcop(rc, rcop); |
827 | if (rc->reg_hosts == rc->num_hosts) | 818 | GNUNET_TESTBED_operation_done(rcop->op); |
828 | { | 819 | GNUNET_free(rcop); |
829 | rc->state = RC_LINKED; | 820 | if (rc->reg_hosts == rc->num_hosts) |
830 | create_peers (rc); | 821 | { |
831 | } | 822 | rc->state = RC_LINKED; |
832 | return; | 823 | create_peers(rc); |
833 | default: | 824 | } |
834 | GNUNET_break (0); | 825 | return; |
835 | GNUNET_SCHEDULER_shutdown (); | 826 | |
836 | return; | 827 | default: |
828 | GNUNET_break(0); | ||
829 | GNUNET_SCHEDULER_shutdown(); | ||
830 | return; | ||
831 | } | ||
837 | } | 832 | } |
838 | } | ||
839 | if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type) | 833 | if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type) |
840 | goto call_cc; | 834 | goto call_cc; |
841 | if (NULL == (rcop = search_rcop (rc, event->op))) | 835 | if (NULL == (rcop = search_rcop(rc, event->op))) |
842 | goto call_cc; | 836 | goto call_cc; |
843 | remove_rcop (rc, rcop); | 837 | remove_rcop(rc, rcop); |
844 | GNUNET_TESTBED_operation_done (rcop->op); | 838 | GNUNET_TESTBED_operation_done(rcop->op); |
845 | GNUNET_free (rcop); | 839 | GNUNET_free(rcop); |
846 | if ( (GNUNET_NO == rc->shutdown) | 840 | if ((GNUNET_NO == rc->shutdown) |
847 | && (NULL != event->details.operation_finished.emsg) ) | 841 | && (NULL != event->details.operation_finished.emsg)) |
848 | { | 842 | { |
849 | LOG (GNUNET_ERROR_TYPE_ERROR, "A operation has failed with error: %s\n", | 843 | LOG(GNUNET_ERROR_TYPE_ERROR, "A operation has failed with error: %s\n", |
850 | event->details.operation_finished.emsg); | 844 | event->details.operation_finished.emsg); |
851 | GNUNET_SCHEDULER_shutdown (); | 845 | GNUNET_SCHEDULER_shutdown(); |
852 | return; | 846 | return; |
853 | } | 847 | } |
854 | GNUNET_assert (GNUNET_YES == rc->shutdown); | 848 | GNUNET_assert(GNUNET_YES == rc->shutdown); |
855 | switch (rc->state) | 849 | switch (rc->state) |
856 | { | 850 | { |
857 | case RC_LINKED: | 851 | case RC_LINKED: |
858 | case RC_PEERS_CREATED: | 852 | case RC_PEERS_CREATED: |
859 | case RC_READY: | 853 | case RC_READY: |
860 | rc->state = RC_PEERS_SHUTDOWN; | 854 | rc->state = RC_PEERS_SHUTDOWN; |
861 | GNUNET_free_non_null (rc->peers); | 855 | GNUNET_free_non_null(rc->peers); |
862 | rc->peers = NULL; | 856 | rc->peers = NULL; |
863 | DEBUG ("Peers shut down in %s\n", prof_time (rc)); | 857 | DEBUG("Peers shut down in %s\n", prof_time(rc)); |
864 | GNUNET_SCHEDULER_shutdown (); | 858 | GNUNET_SCHEDULER_shutdown(); |
865 | break; | 859 | break; |
866 | default: | 860 | |
867 | GNUNET_assert (0); | 861 | default: |
868 | } | 862 | GNUNET_assert(0); |
863 | } | ||
869 | return; | 864 | return; |
870 | 865 | ||
871 | call_cc: | 866 | call_cc: |
872 | if ((0 != (rc->event_mask & (1LL << event->type))) && (NULL != rc->cc)) | 867 | if ((0 != (rc->event_mask & (1LL << event->type))) && (NULL != rc->cc)) |
873 | rc->cc (rc->cc_cls, event); | 868 | rc->cc(rc->cc_cls, event); |
874 | if (GNUNET_TESTBED_ET_PEER_START != event->type) | 869 | if (GNUNET_TESTBED_ET_PEER_START != event->type) |
875 | return; | 870 | return; |
876 | if (NULL == (rcop = search_rcop (rc, event->op))) /* Not our operation */ | 871 | if (NULL == (rcop = search_rcop(rc, event->op))) /* Not our operation */ |
877 | return; | 872 | return; |
878 | remove_rcop (rc, rcop); | 873 | remove_rcop(rc, rcop); |
879 | GNUNET_TESTBED_operation_done (rcop->op); | 874 | GNUNET_TESTBED_operation_done(rcop->op); |
880 | GNUNET_free (rcop); | 875 | GNUNET_free(rcop); |
881 | rc->peer_count++; | 876 | rc->peer_count++; |
882 | if (rc->peer_count < rc->num_peers) | 877 | if (rc->peer_count < rc->num_peers) |
883 | return; | 878 | return; |
884 | DEBUG ("%u peers started in %s\n", rc->num_peers, prof_time (rc)); | 879 | DEBUG("%u peers started in %s\n", rc->num_peers, prof_time(rc)); |
885 | if (GNUNET_TESTBED_TOPOLOGY_NONE != rc->topology) | 880 | if (GNUNET_TESTBED_TOPOLOGY_NONE != rc->topology) |
886 | { | ||
887 | switch (rc->topology) | ||
888 | { | 881 | { |
889 | case GNUNET_TESTBED_TOPOLOGY_NONE: | 882 | switch (rc->topology) |
890 | GNUNET_assert (0); | 883 | { |
891 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: | 884 | case GNUNET_TESTBED_TOPOLOGY_NONE: |
892 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: | 885 | GNUNET_assert(0); |
893 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: | 886 | |
894 | rc->topology_operation = | 887 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: |
895 | GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers, | 888 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: |
896 | rc->peers, &rc->num_oc, | 889 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: |
897 | &topology_completion_callback, | 890 | rc->topology_operation = |
898 | rc, | 891 | GNUNET_TESTBED_overlay_configure_topology(NULL, rc->num_peers, |
899 | rc->topology, | 892 | rc->peers, &rc->num_oc, |
900 | rc->random_links, | 893 | &topology_completion_callback, |
901 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); | 894 | rc, |
902 | break; | 895 | rc->topology, |
903 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: | 896 | rc->random_links, |
904 | GNUNET_assert (NULL != rc->topo_file); | 897 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); |
905 | rc->topology_operation = | 898 | break; |
906 | GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers, | 899 | |
907 | rc->peers, &rc->num_oc, | 900 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: |
908 | &topology_completion_callback, | 901 | GNUNET_assert(NULL != rc->topo_file); |
909 | rc, | 902 | rc->topology_operation = |
910 | rc->topology, | 903 | GNUNET_TESTBED_overlay_configure_topology(NULL, rc->num_peers, |
911 | rc->topo_file, | 904 | rc->peers, &rc->num_oc, |
912 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); | 905 | &topology_completion_callback, |
913 | break; | 906 | rc, |
914 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: | 907 | rc->topology, |
915 | { | 908 | rc->topo_file, |
916 | unsigned long long number; | 909 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); |
917 | unsigned int cap; | 910 | break; |
918 | GNUNET_assert (GNUNET_OK == | 911 | |
919 | GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION, | 912 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: |
913 | { | ||
914 | unsigned long long number; | ||
915 | unsigned int cap; | ||
916 | GNUNET_assert(GNUNET_OK == | ||
917 | GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, | ||
920 | SCALE_FREE_CAP, | 918 | SCALE_FREE_CAP, |
921 | &number)); | 919 | &number)); |
922 | cap = (unsigned int) number; | 920 | cap = (unsigned int)number; |
923 | GNUNET_assert (GNUNET_OK == | 921 | GNUNET_assert(GNUNET_OK == |
924 | GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION, | 922 | GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, |
925 | SCALE_FREE_M, | 923 | SCALE_FREE_M, |
926 | &number)); | 924 | &number)); |
927 | rc->topology_operation = | 925 | rc->topology_operation = |
928 | GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers, | 926 | GNUNET_TESTBED_overlay_configure_topology(NULL, rc->num_peers, |
929 | rc->peers, &rc->num_oc, | 927 | rc->peers, &rc->num_oc, |
930 | &topology_completion_callback, | 928 | &topology_completion_callback, |
931 | rc, | 929 | rc, |
932 | rc->topology, | 930 | rc->topology, |
933 | cap, /* uint16_t */ | 931 | cap, /* uint16_t */ |
934 | (unsigned int) number, /* uint8_t */ | 932 | (unsigned int)number, /* uint8_t */ |
935 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); | 933 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); |
936 | } | 934 | } |
937 | break; | 935 | break; |
938 | default: | 936 | |
939 | rc->topology_operation = | 937 | default: |
940 | GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers, | 938 | rc->topology_operation = |
941 | rc->peers, &rc->num_oc, | 939 | GNUNET_TESTBED_overlay_configure_topology(NULL, rc->num_peers, |
942 | &topology_completion_callback, | 940 | rc->peers, &rc->num_oc, |
943 | rc, | 941 | &topology_completion_callback, |
944 | rc->topology, | 942 | rc, |
945 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); | 943 | rc->topology, |
946 | } | 944 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); |
947 | if (NULL == rc->topology_operation) | 945 | } |
948 | LOG (GNUNET_ERROR_TYPE_WARNING, | 946 | if (NULL == rc->topology_operation) |
949 | "Not generating a topology. Check number of peers\n"); | 947 | LOG(GNUNET_ERROR_TYPE_WARNING, |
950 | else | 948 | "Not generating a topology. Check number of peers\n"); |
951 | { | 949 | else |
952 | DEBUG ("Creating overlay topology\n"); | 950 | { |
953 | rc->pstart_time = GNUNET_TIME_absolute_get (); | 951 | DEBUG("Creating overlay topology\n"); |
954 | return; | 952 | rc->pstart_time = GNUNET_TIME_absolute_get(); |
953 | return; | ||
954 | } | ||
955 | } | 955 | } |
956 | } | ||
957 | rc->state = RC_READY; | 956 | rc->state = RC_READY; |
958 | call_master (rc); | 957 | call_master(rc); |
959 | } | 958 | } |
960 | 959 | ||
961 | 960 | ||
@@ -965,7 +964,7 @@ call_cc: | |||
965 | * @param cls the RunContext | 964 | * @param cls the RunContext |
966 | */ | 965 | */ |
967 | static void | 966 | static void |
968 | register_hosts (void *cls); | 967 | register_hosts(void *cls); |
969 | 968 | ||
970 | 969 | ||
971 | /** | 970 | /** |
@@ -975,20 +974,20 @@ register_hosts (void *cls); | |||
975 | * @param emsg the error message; NULL if host registration is successful | 974 | * @param emsg the error message; NULL if host registration is successful |
976 | */ | 975 | */ |
977 | static void | 976 | static void |
978 | host_registration_completion (void *cls, const char *emsg) | 977 | host_registration_completion(void *cls, const char *emsg) |
979 | { | 978 | { |
980 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 979 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
981 | 980 | ||
982 | rc->reg_handle = NULL; | 981 | rc->reg_handle = NULL; |
983 | if (NULL != emsg) | 982 | if (NULL != emsg) |
984 | { | 983 | { |
985 | LOG (GNUNET_ERROR_TYPE_WARNING, | 984 | LOG(GNUNET_ERROR_TYPE_WARNING, |
986 | _("Host registration failed for a host. Error: %s\n"), emsg); | 985 | _("Host registration failed for a host. Error: %s\n"), emsg); |
987 | GNUNET_SCHEDULER_shutdown (); | 986 | GNUNET_SCHEDULER_shutdown(); |
988 | return; | 987 | return; |
989 | } | 988 | } |
990 | rc->register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, | 989 | rc->register_hosts_task = GNUNET_SCHEDULER_add_now(®ister_hosts, |
991 | rc); | 990 | rc); |
992 | } | 991 | } |
993 | 992 | ||
994 | 993 | ||
@@ -998,7 +997,7 @@ host_registration_completion (void *cls, const char *emsg) | |||
998 | * @param cls RunContext | 997 | * @param cls RunContext |
999 | */ | 998 | */ |
1000 | static void | 999 | static void |
1001 | register_hosts (void *cls) | 1000 | register_hosts(void *cls) |
1002 | { | 1001 | { |
1003 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 1002 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
1004 | struct RunContextOperation *rcop; | 1003 | struct RunContextOperation *rcop; |
@@ -1006,25 +1005,25 @@ register_hosts (void *cls) | |||
1006 | 1005 | ||
1007 | rc->register_hosts_task = NULL; | 1006 | rc->register_hosts_task = NULL; |
1008 | if (rc->reg_hosts == rc->num_hosts) | 1007 | if (rc->reg_hosts == rc->num_hosts) |
1009 | { | ||
1010 | DEBUG ("All hosts successfully registered\n"); | ||
1011 | /* Start slaves */ | ||
1012 | for (slave = 0; slave < rc->num_hosts; slave++) | ||
1013 | { | 1008 | { |
1014 | rcop = GNUNET_new (struct RunContextOperation); | 1009 | DEBUG("All hosts successfully registered\n"); |
1015 | rcop->rc = rc; | 1010 | /* Start slaves */ |
1016 | rcop->op = | 1011 | for (slave = 0; slave < rc->num_hosts; slave++) |
1017 | GNUNET_TESTBED_controller_link (rcop, rc->c, rc->hosts[slave], | 1012 | { |
1018 | rc->h, GNUNET_YES); | 1013 | rcop = GNUNET_new(struct RunContextOperation); |
1019 | GNUNET_assert (NULL != rcop->op); | 1014 | rcop->rc = rc; |
1020 | insert_rcop (rc, rcop); | 1015 | rcop->op = |
1016 | GNUNET_TESTBED_controller_link(rcop, rc->c, rc->hosts[slave], | ||
1017 | rc->h, GNUNET_YES); | ||
1018 | GNUNET_assert(NULL != rcop->op); | ||
1019 | insert_rcop(rc, rcop); | ||
1020 | } | ||
1021 | rc->reg_hosts = 0; | ||
1022 | return; | ||
1021 | } | 1023 | } |
1022 | rc->reg_hosts = 0; | ||
1023 | return; | ||
1024 | } | ||
1025 | rc->reg_handle = | 1024 | rc->reg_handle = |
1026 | GNUNET_TESTBED_register_host (rc->c, rc->hosts[rc->reg_hosts], | 1025 | GNUNET_TESTBED_register_host(rc->c, rc->hosts[rc->reg_hosts], |
1027 | host_registration_completion, rc); | 1026 | host_registration_completion, rc); |
1028 | rc->reg_hosts++; | 1027 | rc->reg_hosts++; |
1029 | } | 1028 | } |
1030 | 1029 | ||
@@ -1039,37 +1038,37 @@ register_hosts (void *cls) | |||
1039 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case | 1038 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case |
1040 | */ | 1039 | */ |
1041 | static void | 1040 | static void |
1042 | controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | 1041 | controller_status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, |
1043 | int status) | 1042 | int status) |
1044 | { | 1043 | { |
1045 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 1044 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
1046 | uint64_t event_mask; | 1045 | uint64_t event_mask; |
1047 | 1046 | ||
1048 | if (status != GNUNET_OK) | 1047 | if (status != GNUNET_OK) |
1049 | { | 1048 | { |
1050 | rc->cproc = NULL; | 1049 | rc->cproc = NULL; |
1051 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1050 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1052 | _("Controller crash detected. Shutting down.\n")); | 1051 | _("Controller crash detected. Shutting down.\n")); |
1053 | GNUNET_SCHEDULER_shutdown (); | 1052 | GNUNET_SCHEDULER_shutdown(); |
1054 | return; | 1053 | return; |
1055 | } | 1054 | } |
1056 | GNUNET_CONFIGURATION_destroy (rc->cfg); | 1055 | GNUNET_CONFIGURATION_destroy(rc->cfg); |
1057 | rc->cfg = GNUNET_CONFIGURATION_dup (cfg); | 1056 | rc->cfg = GNUNET_CONFIGURATION_dup(cfg); |
1058 | event_mask = rc->event_mask; | 1057 | event_mask = rc->event_mask; |
1059 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 1058 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
1060 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); | 1059 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); |
1061 | if (rc->topology < GNUNET_TESTBED_TOPOLOGY_NONE) | 1060 | if (rc->topology < GNUNET_TESTBED_TOPOLOGY_NONE) |
1062 | event_mask |= GNUNET_TESTBED_ET_CONNECT; | 1061 | event_mask |= GNUNET_TESTBED_ET_CONNECT; |
1063 | rc->c = | 1062 | rc->c = |
1064 | GNUNET_TESTBED_controller_connect (rc->h, event_mask, &event_cb, rc); | 1063 | GNUNET_TESTBED_controller_connect(rc->h, event_mask, &event_cb, rc); |
1065 | if (0 < rc->num_hosts) | 1064 | if (0 < rc->num_hosts) |
1066 | { | 1065 | { |
1067 | rc->reg_hosts = 0; | 1066 | rc->reg_hosts = 0; |
1068 | rc->register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, rc); | 1067 | rc->register_hosts_task = GNUNET_SCHEDULER_add_now(®ister_hosts, rc); |
1069 | return; | 1068 | return; |
1070 | } | 1069 | } |
1071 | rc->state = RC_LINKED; | 1070 | rc->state = RC_LINKED; |
1072 | create_peers (rc); | 1071 | create_peers(rc); |
1073 | } | 1072 | } |
1074 | 1073 | ||
1075 | 1074 | ||
@@ -1086,26 +1085,26 @@ controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1086 | * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort | 1085 | * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort |
1087 | */ | 1086 | */ |
1088 | static int | 1087 | static int |
1089 | netint_proc (void *cls, const char *name, int isDefault, | 1088 | netint_proc(void *cls, const char *name, int isDefault, |
1090 | const struct sockaddr *addr, const struct sockaddr *broadcast_addr, | 1089 | const struct sockaddr *addr, const struct sockaddr *broadcast_addr, |
1091 | const struct sockaddr *netmask, socklen_t addrlen) | 1090 | const struct sockaddr *netmask, socklen_t addrlen) |
1092 | { | 1091 | { |
1093 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 1092 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
1094 | char hostip[NI_MAXHOST]; | 1093 | char hostip[NI_MAXHOST]; |
1095 | char *buf; | 1094 | char *buf; |
1096 | 1095 | ||
1097 | if (sizeof (struct sockaddr_in) != addrlen) | 1096 | if (sizeof(struct sockaddr_in) != addrlen) |
1098 | return GNUNET_OK; /* Only consider IPv4 for now */ | 1097 | return GNUNET_OK; /* Only consider IPv4 for now */ |
1099 | if (0 != | 1098 | if (0 != |
1100 | getnameinfo (addr, addrlen, hostip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) | 1099 | getnameinfo(addr, addrlen, hostip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) |
1101 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "getnameinfo"); | 1100 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "getnameinfo"); |
1102 | if (NULL == rc->trusted_ip) | 1101 | if (NULL == rc->trusted_ip) |
1103 | { | 1102 | { |
1104 | rc->trusted_ip = GNUNET_strdup (hostip); | 1103 | rc->trusted_ip = GNUNET_strdup(hostip); |
1105 | return GNUNET_YES; | 1104 | return GNUNET_YES; |
1106 | } | 1105 | } |
1107 | (void) GNUNET_asprintf (&buf, "%s; %s", rc->trusted_ip, hostip); | 1106 | (void)GNUNET_asprintf(&buf, "%s; %s", rc->trusted_ip, hostip); |
1108 | GNUNET_free (rc->trusted_ip); | 1107 | GNUNET_free(rc->trusted_ip); |
1109 | rc->trusted_ip = buf; | 1108 | rc->trusted_ip = buf; |
1110 | return GNUNET_YES; | 1109 | return GNUNET_YES; |
1111 | } | 1110 | } |
@@ -1122,67 +1121,67 @@ netint_proc (void *cls, const char *name, int isDefault, | |||
1122 | * @param status GNUNET_YES if it is habitable; GNUNET_NO if not | 1121 | * @param status GNUNET_YES if it is habitable; GNUNET_NO if not |
1123 | */ | 1122 | */ |
1124 | static void | 1123 | static void |
1125 | host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host, | 1124 | host_habitable_cb(void *cls, const struct GNUNET_TESTBED_Host *host, |
1126 | int status) | 1125 | int status) |
1127 | { | 1126 | { |
1128 | struct CompatibilityCheckContext *hc = cls; | 1127 | struct CompatibilityCheckContext *hc = cls; |
1129 | struct GNUNET_TESTBED_RunHandle *rc; | 1128 | struct GNUNET_TESTBED_RunHandle *rc; |
1130 | struct GNUNET_TESTBED_Host **old_hosts; | 1129 | struct GNUNET_TESTBED_Host **old_hosts; |
1131 | unsigned int nhost; | 1130 | unsigned int nhost; |
1132 | 1131 | ||
1133 | GNUNET_assert (NULL != (rc = hc->rc)); | 1132 | GNUNET_assert(NULL != (rc = hc->rc)); |
1134 | nhost = hc->index; | 1133 | nhost = hc->index; |
1135 | GNUNET_assert (nhost <= rc->num_hosts); | 1134 | GNUNET_assert(nhost <= rc->num_hosts); |
1136 | GNUNET_assert (host == rc->hosts[nhost]); | 1135 | GNUNET_assert(host == rc->hosts[nhost]); |
1137 | hc->h = NULL; | 1136 | hc->h = NULL; |
1138 | if (GNUNET_NO == status) | 1137 | if (GNUNET_NO == status) |
1139 | { | 1138 | { |
1140 | if ((NULL != host) && (NULL != GNUNET_TESTBED_host_get_hostname (host))) | 1139 | if ((NULL != host) && (NULL != GNUNET_TESTBED_host_get_hostname(host))) |
1141 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Host %s cannot start testbed\n"), | 1140 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Host %s cannot start testbed\n"), |
1142 | GNUNET_TESTBED_host_get_hostname (host)); | 1141 | GNUNET_TESTBED_host_get_hostname(host)); |
1143 | else | 1142 | else |
1144 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1143 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1145 | _("Testbed cannot be started on localhost\n")); | 1144 | _("Testbed cannot be started on localhost\n")); |
1146 | GNUNET_SCHEDULER_shutdown (); | 1145 | GNUNET_SCHEDULER_shutdown(); |
1147 | return; | 1146 | return; |
1148 | } | 1147 | } |
1149 | rc->reg_hosts++; | 1148 | rc->reg_hosts++; |
1150 | if (rc->reg_hosts < rc->num_hosts) | 1149 | if (rc->reg_hosts < rc->num_hosts) |
1151 | return; | 1150 | return; |
1152 | GNUNET_free (rc->hclist); | 1151 | GNUNET_free(rc->hclist); |
1153 | rc->hclist = NULL; | 1152 | rc->hclist = NULL; |
1154 | rc->h = rc->hosts[0]; | 1153 | rc->h = rc->hosts[0]; |
1155 | rc->num_hosts--; | 1154 | rc->num_hosts--; |
1156 | if (0 < rc->num_hosts) | 1155 | if (0 < rc->num_hosts) |
1157 | { | 1156 | { |
1158 | old_hosts = rc->hosts; | 1157 | old_hosts = rc->hosts; |
1159 | rc->hosts = | 1158 | rc->hosts = |
1160 | GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *) * rc->num_hosts); | 1159 | GNUNET_malloc(sizeof(struct GNUNET_TESTBED_Host *) * rc->num_hosts); |
1161 | GNUNET_memcpy (rc->hosts, &old_hosts[1], | 1160 | GNUNET_memcpy(rc->hosts, &old_hosts[1], |
1162 | (sizeof (struct GNUNET_TESTBED_Host *) * rc->num_hosts)); | 1161 | (sizeof(struct GNUNET_TESTBED_Host *) * rc->num_hosts)); |
1163 | GNUNET_free (old_hosts); | 1162 | GNUNET_free(old_hosts); |
1164 | } | 1163 | } |
1165 | else | 1164 | else |
1166 | { | 1165 | { |
1167 | GNUNET_free (rc->hosts); | 1166 | GNUNET_free(rc->hosts); |
1168 | rc->hosts = NULL; | 1167 | rc->hosts = NULL; |
1169 | } | 1168 | } |
1170 | GNUNET_TESTBED_host_resolve_ (rc->h); | 1169 | GNUNET_TESTBED_host_resolve_(rc->h); |
1171 | for (nhost = 0; nhost < rc->num_hosts; nhost++) | 1170 | for (nhost = 0; nhost < rc->num_hosts; nhost++) |
1172 | GNUNET_TESTBED_host_resolve_ (rc->hosts[nhost]); | 1171 | GNUNET_TESTBED_host_resolve_(rc->hosts[nhost]); |
1173 | GNUNET_OS_network_interfaces_list (netint_proc, rc); | 1172 | GNUNET_OS_network_interfaces_list(netint_proc, rc); |
1174 | if (NULL == rc->trusted_ip) | 1173 | if (NULL == rc->trusted_ip) |
1175 | rc->trusted_ip = GNUNET_strdup ("127.0.0.1"); | 1174 | rc->trusted_ip = GNUNET_strdup("127.0.0.1"); |
1176 | rc->cproc = | 1175 | rc->cproc = |
1177 | GNUNET_TESTBED_controller_start (rc->trusted_ip, rc->h, | 1176 | GNUNET_TESTBED_controller_start(rc->trusted_ip, rc->h, |
1178 | &controller_status_cb, rc); | 1177 | &controller_status_cb, rc); |
1179 | GNUNET_free (rc->trusted_ip); | 1178 | GNUNET_free(rc->trusted_ip); |
1180 | rc->trusted_ip = NULL; | 1179 | rc->trusted_ip = NULL; |
1181 | if (NULL == rc->cproc) | 1180 | if (NULL == rc->cproc) |
1182 | { | 1181 | { |
1183 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot start the master controller")); | 1182 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Cannot start the master controller")); |
1184 | GNUNET_SCHEDULER_shutdown (); | 1183 | GNUNET_SCHEDULER_shutdown(); |
1185 | } | 1184 | } |
1186 | } | 1185 | } |
1187 | 1186 | ||
1188 | 1187 | ||
@@ -1192,17 +1191,17 @@ host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host, | |||
1192 | * @param cls the RunContext | 1191 | * @param cls the RunContext |
1193 | */ | 1192 | */ |
1194 | static void | 1193 | static void |
1195 | timeout_task (void *cls) | 1194 | timeout_task(void *cls) |
1196 | { | 1195 | { |
1197 | struct GNUNET_TESTBED_RunHandle *rc = cls; | 1196 | struct GNUNET_TESTBED_RunHandle *rc = cls; |
1198 | 1197 | ||
1199 | rc->timeout_task = NULL; | 1198 | rc->timeout_task = NULL; |
1200 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1199 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1201 | _("Shutting down testbed due to timeout while setup.\n")); | 1200 | _("Shutting down testbed due to timeout while setup.\n")); |
1202 | GNUNET_SCHEDULER_shutdown (); | 1201 | GNUNET_SCHEDULER_shutdown(); |
1203 | if (NULL != rc->test_master) | 1202 | if (NULL != rc->test_master) |
1204 | rc->test_master (rc->test_master_cls, rc, 0, NULL, 0, 0); | 1203 | rc->test_master(rc->test_master_cls, rc, 0, NULL, 0, 0); |
1205 | rc->test_master = NULL; | 1204 | rc->test_master = NULL; |
1206 | } | 1205 | } |
1207 | 1206 | ||
1208 | 1207 | ||
@@ -1234,12 +1233,12 @@ timeout_task (void *cls) | |||
1234 | * @param test_master_cls closure for 'test_master'. | 1233 | * @param test_master_cls closure for 'test_master'. |
1235 | */ | 1234 | */ |
1236 | void | 1235 | void |
1237 | GNUNET_TESTBED_run (const char *host_filename, | 1236 | GNUNET_TESTBED_run(const char *host_filename, |
1238 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1237 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1239 | unsigned int num_peers, uint64_t event_mask, | 1238 | unsigned int num_peers, uint64_t event_mask, |
1240 | GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, | 1239 | GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, |
1241 | GNUNET_TESTBED_TestMaster test_master, | 1240 | GNUNET_TESTBED_TestMaster test_master, |
1242 | void *test_master_cls) | 1241 | void *test_master_cls) |
1243 | { | 1242 | { |
1244 | struct GNUNET_TESTBED_RunHandle *rc; | 1243 | struct GNUNET_TESTBED_RunHandle *rc; |
1245 | char *topology; | 1244 | char *topology; |
@@ -1249,33 +1248,33 @@ GNUNET_TESTBED_run (const char *host_filename, | |||
1249 | unsigned int hid; | 1248 | unsigned int hid; |
1250 | unsigned int nhost; | 1249 | unsigned int nhost; |
1251 | 1250 | ||
1252 | GNUNET_assert (num_peers > 0); | 1251 | GNUNET_assert(num_peers > 0); |
1253 | rc = GNUNET_new (struct GNUNET_TESTBED_RunHandle); | 1252 | rc = GNUNET_new(struct GNUNET_TESTBED_RunHandle); |
1254 | rc->cfg = GNUNET_CONFIGURATION_dup (cfg); | 1253 | rc->cfg = GNUNET_CONFIGURATION_dup(cfg); |
1255 | #if ENABLE_SUPERMUC | 1254 | #if ENABLE_SUPERMUC |
1256 | rc->num_hosts = GNUNET_TESTBED_hosts_load_from_loadleveler (rc->cfg, | 1255 | rc->num_hosts = GNUNET_TESTBED_hosts_load_from_loadleveler(rc->cfg, |
1257 | &rc->hosts); | 1256 | &rc->hosts); |
1258 | if (0 == rc->num_hosts) | 1257 | if (0 == rc->num_hosts) |
1259 | { | 1258 | { |
1260 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1259 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1261 | _("No hosts loaded from LoadLeveler. Need at least one host\n")); | 1260 | _("No hosts loaded from LoadLeveler. Need at least one host\n")); |
1262 | goto error_cleanup; | 1261 | goto error_cleanup; |
1263 | } | 1262 | } |
1264 | #else | 1263 | #else |
1265 | if (NULL != host_filename) | 1264 | if (NULL != host_filename) |
1266 | { | ||
1267 | rc->num_hosts = | ||
1268 | GNUNET_TESTBED_hosts_load_from_file (host_filename, rc->cfg, | ||
1269 | &rc->hosts); | ||
1270 | if (0 == rc->num_hosts) | ||
1271 | { | 1265 | { |
1272 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1266 | rc->num_hosts = |
1273 | _("No hosts loaded. Need at least one host\n")); | 1267 | GNUNET_TESTBED_hosts_load_from_file(host_filename, rc->cfg, |
1274 | goto error_cleanup; | 1268 | &rc->hosts); |
1269 | if (0 == rc->num_hosts) | ||
1270 | { | ||
1271 | LOG(GNUNET_ERROR_TYPE_WARNING, | ||
1272 | _("No hosts loaded. Need at least one host\n")); | ||
1273 | goto error_cleanup; | ||
1274 | } | ||
1275 | } | 1275 | } |
1276 | } | ||
1277 | else | 1276 | else |
1278 | rc->h = GNUNET_TESTBED_host_create (NULL, NULL, rc->cfg, 0); | 1277 | rc->h = GNUNET_TESTBED_host_create(NULL, NULL, rc->cfg, 0); |
1279 | #endif | 1278 | #endif |
1280 | rc->num_peers = num_peers; | 1279 | rc->num_peers = num_peers; |
1281 | rc->event_mask = event_mask; | 1280 | rc->event_mask = event_mask; |
@@ -1286,158 +1285,162 @@ GNUNET_TESTBED_run (const char *host_filename, | |||
1286 | rc->state = RC_INIT; | 1285 | rc->state = RC_INIT; |
1287 | rc->topology = GNUNET_TESTBED_TOPOLOGY_NONE; | 1286 | rc->topology = GNUNET_TESTBED_TOPOLOGY_NONE; |
1288 | if (GNUNET_OK == | 1287 | if (GNUNET_OK == |
1289 | GNUNET_CONFIGURATION_get_value_string (rc->cfg, TESTBED_CONFIG_SECTION, | 1288 | GNUNET_CONFIGURATION_get_value_string(rc->cfg, TESTBED_CONFIG_SECTION, |
1290 | "OVERLAY_TOPOLOGY", &topology)) | 1289 | "OVERLAY_TOPOLOGY", &topology)) |
1291 | { | ||
1292 | if (GNUNET_NO == GNUNET_TESTBED_topology_get_ (&rc->topology, topology)) | ||
1293 | { | 1290 | { |
1294 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, | 1291 | if (GNUNET_NO == GNUNET_TESTBED_topology_get_(&rc->topology, topology)) |
1295 | "OVERLAY_TOPLOGY", | 1292 | { |
1296 | _ | 1293 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, |
1297 | ("Specified topology must be supported by testbed")); | 1294 | "OVERLAY_TOPLOGY", |
1295 | _ | ||
1296 | ("Specified topology must be supported by testbed")); | ||
1297 | } | ||
1298 | GNUNET_free(topology); | ||
1298 | } | 1299 | } |
1299 | GNUNET_free (topology); | ||
1300 | } | ||
1301 | switch (rc->topology) | 1300 | switch (rc->topology) |
1302 | { | ||
1303 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: | ||
1304 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: | ||
1305 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: | ||
1306 | if (GNUNET_OK != | ||
1307 | GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION, | ||
1308 | "OVERLAY_RANDOM_LINKS", | ||
1309 | &number)) | ||
1310 | { | ||
1311 | /* OVERLAY option RANDOM & SMALL_WORLD_RING requires OVERLAY_RANDOM_LINKS | ||
1312 | * option to be set to the number of random links to be established */ | ||
1313 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, | ||
1314 | "OVERLAY_RANDOM_LINKS"); | ||
1315 | goto error_cleanup; | ||
1316 | } | ||
1317 | if (number > UINT32_MAX) | ||
1318 | { | 1301 | { |
1319 | GNUNET_break (0); /* Too big number */ | 1302 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: |
1320 | goto error_cleanup; | 1303 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: |
1321 | } | 1304 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: |
1322 | rc->random_links = (unsigned int) number; | 1305 | if (GNUNET_OK != |
1323 | break; | 1306 | GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, |
1324 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: | 1307 | "OVERLAY_RANDOM_LINKS", |
1325 | if (GNUNET_OK != | 1308 | &number)) |
1326 | GNUNET_CONFIGURATION_get_value_filename (rc->cfg, TESTBED_CONFIG_SECTION, | 1309 | { |
1327 | "OVERLAY_TOPOLOGY_FILE", | 1310 | /* OVERLAY option RANDOM & SMALL_WORLD_RING requires OVERLAY_RANDOM_LINKS |
1328 | &rc->topo_file)) | 1311 | * option to be set to the number of random links to be established */ |
1329 | { | 1312 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, |
1330 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, | 1313 | "OVERLAY_RANDOM_LINKS"); |
1331 | "OVERLAY_TOPOLOGY_FILE"); | 1314 | goto error_cleanup; |
1332 | goto error_cleanup; | 1315 | } |
1333 | } | 1316 | if (number > UINT32_MAX) |
1334 | goto warn_ignore; | 1317 | { |
1335 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: | 1318 | GNUNET_break(0); /* Too big number */ |
1336 | if (GNUNET_OK != | 1319 | goto error_cleanup; |
1337 | GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION, | 1320 | } |
1338 | SCALE_FREE_CAP, &number)) | 1321 | rc->random_links = (unsigned int)number; |
1339 | { | 1322 | break; |
1340 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, | 1323 | |
1341 | SCALE_FREE_CAP); | 1324 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: |
1342 | goto error_cleanup; | 1325 | if (GNUNET_OK != |
1343 | } | 1326 | GNUNET_CONFIGURATION_get_value_filename(rc->cfg, TESTBED_CONFIG_SECTION, |
1344 | if (UINT16_MAX < number) | 1327 | "OVERLAY_TOPOLOGY_FILE", |
1345 | { | 1328 | &rc->topo_file)) |
1346 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1329 | { |
1347 | _("Maximum number of edges a peer can have in a scale free topology" | 1330 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, |
1348 | " cannot be more than %u. Given `%s = %llu'"), UINT16_MAX, | 1331 | "OVERLAY_TOPOLOGY_FILE"); |
1349 | SCALE_FREE_CAP, number); | 1332 | goto error_cleanup; |
1350 | goto error_cleanup; | 1333 | } |
1351 | } | 1334 | goto warn_ignore; |
1352 | if (GNUNET_OK != | 1335 | |
1353 | GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION, | 1336 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: |
1354 | SCALE_FREE_M, &number)) | 1337 | if (GNUNET_OK != |
1355 | { | 1338 | GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, |
1356 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, | 1339 | SCALE_FREE_CAP, &number)) |
1357 | SCALE_FREE_M); | 1340 | { |
1358 | goto error_cleanup; | 1341 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, |
1359 | } | 1342 | SCALE_FREE_CAP); |
1360 | if (UINT8_MAX < number) | 1343 | goto error_cleanup; |
1361 | { | 1344 | } |
1362 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1345 | if (UINT16_MAX < number) |
1363 | _("The number of edges that can established when adding a new node" | 1346 | { |
1364 | " to scale free topology cannot be more than %u. Given `%s = %llu'"), | 1347 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1365 | UINT8_MAX, SCALE_FREE_M, number); | 1348 | _("Maximum number of edges a peer can have in a scale free topology" |
1366 | goto error_cleanup; | 1349 | " cannot be more than %u. Given `%s = %llu'"), UINT16_MAX, |
1350 | SCALE_FREE_CAP, number); | ||
1351 | goto error_cleanup; | ||
1352 | } | ||
1353 | if (GNUNET_OK != | ||
1354 | GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, | ||
1355 | SCALE_FREE_M, &number)) | ||
1356 | { | ||
1357 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, | ||
1358 | SCALE_FREE_M); | ||
1359 | goto error_cleanup; | ||
1360 | } | ||
1361 | if (UINT8_MAX < number) | ||
1362 | { | ||
1363 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
1364 | _("The number of edges that can established when adding a new node" | ||
1365 | " to scale free topology cannot be more than %u. Given `%s = %llu'"), | ||
1366 | UINT8_MAX, SCALE_FREE_M, number); | ||
1367 | goto error_cleanup; | ||
1368 | } | ||
1369 | goto warn_ignore; | ||
1370 | |||
1371 | case GNUNET_TESTBED_TOPOLOGY_OPTION_END: | ||
1372 | /* not allowed! */ | ||
1373 | GNUNET_assert(0); | ||
1374 | |||
1375 | default: | ||
1376 | warn_ignore: | ||
1377 | /* Warn if OVERLAY_RANDOM_LINKS is present that it will be ignored */ | ||
1378 | if (GNUNET_YES == | ||
1379 | GNUNET_CONFIGURATION_have_value(rc->cfg, TESTBED_CONFIG_SECTION, | ||
1380 | "OVERLAY_RANDOM_LINKS")) | ||
1381 | LOG(GNUNET_ERROR_TYPE_WARNING, | ||
1382 | "Ignoring value of `OVERLAY_RANDOM_LINKS' in given configuration\n"); | ||
1383 | break; | ||
1367 | } | 1384 | } |
1368 | goto warn_ignore; | ||
1369 | case GNUNET_TESTBED_TOPOLOGY_OPTION_END: | ||
1370 | /* not allowed! */ | ||
1371 | GNUNET_assert (0); | ||
1372 | default: | ||
1373 | warn_ignore: | ||
1374 | /* Warn if OVERLAY_RANDOM_LINKS is present that it will be ignored */ | ||
1375 | if (GNUNET_YES == | ||
1376 | GNUNET_CONFIGURATION_have_value (rc->cfg, TESTBED_CONFIG_SECTION, | ||
1377 | "OVERLAY_RANDOM_LINKS")) | ||
1378 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1379 | "Ignoring value of `OVERLAY_RANDOM_LINKS' in given configuration\n"); | ||
1380 | break; | ||
1381 | } | ||
1382 | if (0 != rc->num_hosts) | 1385 | if (0 != rc->num_hosts) |
1383 | { | ||
1384 | rc->hclist = GNUNET_malloc (sizeof (struct CompatibilityCheckContext) | ||
1385 | * rc->num_hosts); | ||
1386 | for (nhost = 0; nhost < rc->num_hosts; nhost++) | ||
1387 | { | 1386 | { |
1388 | hc = &rc->hclist[nhost]; | 1387 | rc->hclist = GNUNET_malloc(sizeof(struct CompatibilityCheckContext) |
1389 | hc->index = nhost; | 1388 | * rc->num_hosts); |
1390 | hc->rc = rc; | 1389 | for (nhost = 0; nhost < rc->num_hosts; nhost++) |
1391 | hc->h = GNUNET_TESTBED_is_host_habitable (rc->hosts[nhost], rc->cfg, | ||
1392 | &host_habitable_cb, hc); | ||
1393 | if (NULL == hc->h) | ||
1394 | { | ||
1395 | GNUNET_break (0); | ||
1396 | for (nhost = 0; nhost < rc->num_hosts; nhost++) | ||
1397 | { | 1390 | { |
1398 | hc = &rc->hclist[nhost]; | 1391 | hc = &rc->hclist[nhost]; |
1399 | if (NULL != hc->h) | 1392 | hc->index = nhost; |
1400 | GNUNET_TESTBED_is_host_habitable_cancel (hc->h); | 1393 | hc->rc = rc; |
1394 | hc->h = GNUNET_TESTBED_is_host_habitable(rc->hosts[nhost], rc->cfg, | ||
1395 | &host_habitable_cb, hc); | ||
1396 | if (NULL == hc->h) | ||
1397 | { | ||
1398 | GNUNET_break(0); | ||
1399 | for (nhost = 0; nhost < rc->num_hosts; nhost++) | ||
1400 | { | ||
1401 | hc = &rc->hclist[nhost]; | ||
1402 | if (NULL != hc->h) | ||
1403 | GNUNET_TESTBED_is_host_habitable_cancel(hc->h); | ||
1404 | } | ||
1405 | GNUNET_free(rc->hclist); | ||
1406 | rc->hclist = NULL; | ||
1407 | goto error_cleanup; | ||
1408 | } | ||
1401 | } | 1409 | } |
1402 | GNUNET_free (rc->hclist); | ||
1403 | rc->hclist = NULL; | ||
1404 | goto error_cleanup; | ||
1405 | } | ||
1406 | } | 1410 | } |
1407 | } | ||
1408 | else | 1411 | else |
1409 | rc->cproc = | 1412 | rc->cproc = |
1410 | GNUNET_TESTBED_controller_start ("127.0.0.1", rc->h, | 1413 | GNUNET_TESTBED_controller_start("127.0.0.1", rc->h, |
1411 | &controller_status_cb, rc); | 1414 | &controller_status_cb, rc); |
1412 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, TESTBED_CONFIG_SECTION, | 1415 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(cfg, TESTBED_CONFIG_SECTION, |
1413 | "SETUP_TIMEOUT", | 1416 | "SETUP_TIMEOUT", |
1414 | &timeout)) | 1417 | &timeout)) |
1415 | { | 1418 | { |
1416 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 1419 | timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
1417 | DEFAULT_SETUP_TIMEOUT); | 1420 | DEFAULT_SETUP_TIMEOUT); |
1418 | } | 1421 | } |
1419 | rc->rcop_map = GNUNET_CONTAINER_multihashmap32_create (256); | 1422 | rc->rcop_map = GNUNET_CONTAINER_multihashmap32_create(256); |
1420 | rc->timeout_task = | 1423 | rc->timeout_task = |
1421 | GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, rc); | 1424 | GNUNET_SCHEDULER_add_delayed(timeout, &timeout_task, rc); |
1422 | GNUNET_assert (NULL == rc->interrupt_task); | 1425 | GNUNET_assert(NULL == rc->interrupt_task); |
1423 | rc->interrupt_task = | 1426 | rc->interrupt_task = |
1424 | GNUNET_SCHEDULER_add_shutdown (&interrupt, | 1427 | GNUNET_SCHEDULER_add_shutdown(&interrupt, |
1425 | rc); | 1428 | rc); |
1426 | return; | 1429 | return; |
1427 | 1430 | ||
1428 | error_cleanup: | 1431 | error_cleanup: |
1429 | if (NULL != rc->h) | 1432 | if (NULL != rc->h) |
1430 | GNUNET_TESTBED_host_destroy (rc->h); | 1433 | GNUNET_TESTBED_host_destroy(rc->h); |
1431 | if (NULL != rc->hosts) | 1434 | if (NULL != rc->hosts) |
1432 | { | 1435 | { |
1433 | for (hid = 0; hid < rc->num_hosts; hid++) | 1436 | for (hid = 0; hid < rc->num_hosts; hid++) |
1434 | if (NULL != rc->hosts[hid]) | 1437 | if (NULL != rc->hosts[hid]) |
1435 | GNUNET_TESTBED_host_destroy (rc->hosts[hid]); | 1438 | GNUNET_TESTBED_host_destroy(rc->hosts[hid]); |
1436 | GNUNET_free (rc->hosts); | 1439 | GNUNET_free(rc->hosts); |
1437 | } | 1440 | } |
1438 | if (NULL != rc->cfg) | 1441 | if (NULL != rc->cfg) |
1439 | GNUNET_CONFIGURATION_destroy (rc->cfg); | 1442 | GNUNET_CONFIGURATION_destroy(rc->cfg); |
1440 | GNUNET_free (rc); | 1443 | GNUNET_free(rc); |
1441 | } | 1444 | } |
1442 | 1445 | ||
1443 | 1446 | ||
@@ -1449,7 +1452,7 @@ error_cleanup: | |||
1449 | * @return handle to the master controller | 1452 | * @return handle to the master controller |
1450 | */ | 1453 | */ |
1451 | struct GNUNET_TESTBED_Controller * | 1454 | struct GNUNET_TESTBED_Controller * |
1452 | GNUNET_TESTBED_run_get_controller_handle (struct GNUNET_TESTBED_RunHandle *h) | 1455 | GNUNET_TESTBED_run_get_controller_handle(struct GNUNET_TESTBED_RunHandle *h) |
1453 | { | 1456 | { |
1454 | return h->c; | 1457 | return h->c; |
1455 | } | 1458 | } |
diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c index 59512d59f..58ccf4580 100644 --- a/src/testbed/testbed_api_topology.c +++ b/src/testbed/testbed_api_topology.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -33,8 +33,8 @@ | |||
33 | /** | 33 | /** |
34 | * Generic loggins shorthand | 34 | * Generic loggins shorthand |
35 | */ | 35 | */ |
36 | #define LOG(kind,...) \ | 36 | #define LOG(kind, ...) \ |
37 | GNUNET_log_from (kind, "testbed-api-topology", __VA_ARGS__) | 37 | GNUNET_log_from(kind, "testbed-api-topology", __VA_ARGS__) |
38 | 38 | ||
39 | 39 | ||
40 | /** | 40 | /** |
@@ -52,9 +52,7 @@ struct TopologyContext; | |||
52 | /** | 52 | /** |
53 | * Representation of an overlay link | 53 | * Representation of an overlay link |
54 | */ | 54 | */ |
55 | struct OverlayLink | 55 | struct OverlayLink { |
56 | { | ||
57 | |||
58 | /** | 56 | /** |
59 | * An operation corresponding to this link | 57 | * An operation corresponding to this link |
60 | */ | 58 | */ |
@@ -74,15 +72,13 @@ struct OverlayLink | |||
74 | * position of peer B's handle in peers array | 72 | * position of peer B's handle in peers array |
75 | */ | 73 | */ |
76 | uint32_t B; | 74 | uint32_t B; |
77 | |||
78 | }; | 75 | }; |
79 | 76 | ||
80 | 77 | ||
81 | /** | 78 | /** |
82 | * Representation of an underlay link | 79 | * Representation of an underlay link |
83 | */ | 80 | */ |
84 | struct UnderlayLink | 81 | struct UnderlayLink { |
85 | { | ||
86 | /** | 82 | /** |
87 | * position of peer A's handle in peers array | 83 | * position of peer A's handle in peers array |
88 | */ | 84 | */ |
@@ -110,8 +106,7 @@ struct UnderlayLink | |||
110 | }; | 106 | }; |
111 | 107 | ||
112 | 108 | ||
113 | struct RetryListEntry | 109 | struct RetryListEntry { |
114 | { | ||
115 | /** | 110 | /** |
116 | * the next pointer for the DLL | 111 | * the next pointer for the DLL |
117 | */ | 112 | */ |
@@ -132,8 +127,7 @@ struct RetryListEntry | |||
132 | /** | 127 | /** |
133 | * Context information for overlay topologies | 128 | * Context information for overlay topologies |
134 | */ | 129 | */ |
135 | struct TopologyContextOverlay | 130 | struct TopologyContextOverlay { |
136 | { | ||
137 | /** | 131 | /** |
138 | * The array of peers | 132 | * The array of peers |
139 | */ | 133 | */ |
@@ -199,8 +193,7 @@ struct TopologyContextOverlay | |||
199 | /** | 193 | /** |
200 | * Topology context information for underlay topologies | 194 | * Topology context information for underlay topologies |
201 | */ | 195 | */ |
202 | struct TopologyContextUnderlay | 196 | struct TopologyContextUnderlay { |
203 | { | ||
204 | /** | 197 | /** |
205 | * The link array | 198 | * The link array |
206 | */ | 199 | */ |
@@ -211,13 +204,11 @@ struct TopologyContextUnderlay | |||
211 | /** | 204 | /** |
212 | * Context information for topology operations | 205 | * Context information for topology operations |
213 | */ | 206 | */ |
214 | struct TopologyContext | 207 | struct TopologyContext { |
215 | { | ||
216 | /** | 208 | /** |
217 | * The type of this context | 209 | * The type of this context |
218 | */ | 210 | */ |
219 | enum { | 211 | enum { |
220 | |||
221 | /** | 212 | /** |
222 | * Type for underlay topology | 213 | * Type for underlay topology |
223 | */ | 214 | */ |
@@ -227,11 +218,9 @@ struct TopologyContext | |||
227 | * Type for overlay topology | 218 | * Type for overlay topology |
228 | */ | 219 | */ |
229 | TOPOLOGYCONTEXT_TYPE_OVERLAY | 220 | TOPOLOGYCONTEXT_TYPE_OVERLAY |
230 | |||
231 | } type; | 221 | } type; |
232 | 222 | ||
233 | union { | 223 | union { |
234 | |||
235 | /** | 224 | /** |
236 | * Topology context information for overlay topology | 225 | * Topology context information for overlay topology |
237 | */ | 226 | */ |
@@ -252,7 +241,6 @@ struct TopologyContext | |||
252 | * The size of the link array | 241 | * The size of the link array |
253 | */ | 242 | */ |
254 | unsigned int link_array_size; | 243 | unsigned int link_array_size; |
255 | |||
256 | }; | 244 | }; |
257 | 245 | ||
258 | 246 | ||
@@ -261,78 +249,77 @@ struct TopologyContext | |||
261 | * GNUNET_TESTBED_TopologyOption | 249 | * GNUNET_TESTBED_TopologyOption |
262 | */ | 250 | */ |
263 | static const char *topology_strings[] = { | 251 | static const char *topology_strings[] = { |
264 | 252 | /** | |
265 | /** | 253 | * A clique (everyone connected to everyone else). No options. If there are N |
266 | * A clique (everyone connected to everyone else). No options. If there are N | 254 | * peers this topology results in (N * (N -1)) connections. |
267 | * peers this topology results in (N * (N -1)) connections. | 255 | */ |
268 | */ | ||
269 | "CLIQUE", | 256 | "CLIQUE", |
270 | 257 | ||
271 | /* | 258 | /* |
272 | * Small-world network (2d torus plus random links). Followed | 259 | * Small-world network (2d torus plus random links). Followed |
273 | * by the number of random links to add (unsigned int). | 260 | * by the number of random links to add (unsigned int). |
274 | */ | 261 | */ |
275 | "SMALL_WORLD", | 262 | "SMALL_WORLD", |
276 | 263 | ||
277 | /** | 264 | /** |
278 | * Small-world network (ring plus random links). Followed | 265 | * Small-world network (ring plus random links). Followed |
279 | * by the number of random links to add (unsigned int). | 266 | * by the number of random links to add (unsigned int). |
280 | */ | 267 | */ |
281 | "SMALL_WORLD_RING", | 268 | "SMALL_WORLD_RING", |
282 | 269 | ||
283 | /** | 270 | /** |
284 | * Ring topology. No options. | 271 | * Ring topology. No options. |
285 | */ | 272 | */ |
286 | "RING", | 273 | "RING", |
287 | 274 | ||
288 | /** | 275 | /** |
289 | * Star topology. No options. | 276 | * Star topology. No options. |
290 | */ | 277 | */ |
291 | "STAR", | 278 | "STAR", |
292 | 279 | ||
293 | /** | 280 | /** |
294 | * 2-d torus. No options. | 281 | * 2-d torus. No options. |
295 | */ | 282 | */ |
296 | "2D_TORUS", | 283 | "2D_TORUS", |
297 | 284 | ||
298 | /** | 285 | /** |
299 | * Random graph. Followed by the number of random links to be established | 286 | * Random graph. Followed by the number of random links to be established |
300 | * (unsigned int) | 287 | * (unsigned int) |
301 | */ | 288 | */ |
302 | "RANDOM", // GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI | 289 | "RANDOM", // GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI |
303 | 290 | ||
304 | /** | 291 | /** |
305 | * Certain percentage of peers are unable to communicate directly | 292 | * Certain percentage of peers are unable to communicate directly |
306 | * replicating NAT conditions. Followed by the fraction of | 293 | * replicating NAT conditions. Followed by the fraction of |
307 | * NAT'ed peers (float). | 294 | * NAT'ed peers (float). |
308 | */ | 295 | */ |
309 | "INTERNAT", | 296 | "INTERNAT", |
310 | 297 | ||
311 | /** | 298 | /** |
312 | * Scale free topology. Followed by the maximum number of links a node can | 299 | * Scale free topology. Followed by the maximum number of links a node can |
313 | * have (unsigned int); and the number of links a new node should have when | 300 | * have (unsigned int); and the number of links a new node should have when |
314 | * it is added to the network (unsigned int) | 301 | * it is added to the network (unsigned int) |
315 | */ | 302 | */ |
316 | "SCALE_FREE", | 303 | "SCALE_FREE", |
317 | 304 | ||
318 | /** | 305 | /** |
319 | * Straight line topology. No options. | 306 | * Straight line topology. No options. |
320 | */ | 307 | */ |
321 | "LINE", | 308 | "LINE", |
322 | 309 | ||
323 | /** | 310 | /** |
324 | * Read a topology from a given file. Followed by the name of the file (const char *). | 311 | * Read a topology from a given file. Followed by the name of the file (const char *). |
325 | */ | 312 | */ |
326 | "FROM_FILE", | 313 | "FROM_FILE", |
327 | 314 | ||
328 | /** | 315 | /** |
329 | * All peers are disconnected. No options. | 316 | * All peers are disconnected. No options. |
330 | */ | 317 | */ |
331 | "NONE", | 318 | "NONE", |
332 | 319 | ||
333 | /** | 320 | /** |
334 | * End of strings | 321 | * End of strings |
335 | */ | 322 | */ |
336 | NULL | 323 | NULL |
337 | }; | 324 | }; |
338 | 325 | ||
@@ -346,69 +333,69 @@ static const char *topology_strings[] = { | |||
346 | * operation has executed successfully. | 333 | * operation has executed successfully. |
347 | */ | 334 | */ |
348 | static void | 335 | static void |
349 | overlay_link_completed (void *cls, | 336 | overlay_link_completed(void *cls, |
350 | struct GNUNET_TESTBED_Operation *op, | 337 | struct GNUNET_TESTBED_Operation *op, |
351 | const char *emsg) | 338 | const char *emsg) |
352 | { | 339 | { |
353 | struct OverlayLink *link = cls; | 340 | struct OverlayLink *link = cls; |
354 | struct TopologyContext *tc; | 341 | struct TopologyContext *tc; |
355 | struct TopologyContextOverlay *overlay; | 342 | struct TopologyContextOverlay *overlay; |
356 | struct RetryListEntry *retry_entry; | 343 | struct RetryListEntry *retry_entry; |
357 | 344 | ||
358 | GNUNET_assert (op == link->op); | 345 | GNUNET_assert(op == link->op); |
359 | GNUNET_TESTBED_operation_done (op); | 346 | GNUNET_TESTBED_operation_done(op); |
360 | link->op = NULL; | 347 | link->op = NULL; |
361 | tc = link->tc; | 348 | tc = link->tc; |
362 | GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); | 349 | GNUNET_assert(TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); |
363 | overlay = &tc->u.overlay; | 350 | overlay = &tc->u.overlay; |
364 | if (NULL != emsg) | 351 | if (NULL != emsg) |
365 | { | ||
366 | overlay->nfailures++; | ||
367 | if (0 != overlay->retry_cnt) | ||
368 | { | 352 | { |
369 | LOG (GNUNET_ERROR_TYPE_WARNING, | 353 | overlay->nfailures++; |
370 | "Error while establishing a link: %s -- Retrying\n", | 354 | if (0 != overlay->retry_cnt) |
371 | emsg); | 355 | { |
372 | retry_entry = GNUNET_new (struct RetryListEntry); | 356 | LOG(GNUNET_ERROR_TYPE_WARNING, |
373 | retry_entry->link = link; | 357 | "Error while establishing a link: %s -- Retrying\n", |
374 | GNUNET_CONTAINER_DLL_insert_tail (overlay->rl_head, | 358 | emsg); |
375 | overlay->rl_tail, | 359 | retry_entry = GNUNET_new(struct RetryListEntry); |
376 | retry_entry); | 360 | retry_entry->link = link; |
361 | GNUNET_CONTAINER_DLL_insert_tail(overlay->rl_head, | ||
362 | overlay->rl_tail, | ||
363 | retry_entry); | ||
364 | } | ||
377 | } | 365 | } |
378 | } | ||
379 | else | 366 | else |
380 | overlay->nsuccess++; | 367 | overlay->nsuccess++; |
381 | overlay->ncompleted++; | 368 | overlay->ncompleted++; |
382 | if (overlay->ncompleted < overlay->nlinks) | 369 | if (overlay->ncompleted < overlay->nlinks) |
383 | return; | 370 | return; |
384 | if ((0 != overlay->retry_cnt) && (NULL != overlay->rl_head)) | 371 | if ((0 != overlay->retry_cnt) && (NULL != overlay->rl_head)) |
385 | { | ||
386 | overlay->retry_cnt--; | ||
387 | overlay->ncompleted = 0; | ||
388 | overlay->nlinks = 0; | ||
389 | while (NULL != (retry_entry = overlay->rl_head)) | ||
390 | { | 372 | { |
391 | link = retry_entry->link; | 373 | overlay->retry_cnt--; |
392 | link->op = | 374 | overlay->ncompleted = 0; |
393 | GNUNET_TESTBED_overlay_connect (overlay->op_cls, | 375 | overlay->nlinks = 0; |
394 | &overlay_link_completed, | 376 | while (NULL != (retry_entry = overlay->rl_head)) |
395 | link, | 377 | { |
396 | overlay->peers[link->A], | 378 | link = retry_entry->link; |
397 | overlay->peers[link->B]); | 379 | link->op = |
398 | overlay->nlinks++; | 380 | GNUNET_TESTBED_overlay_connect(overlay->op_cls, |
399 | GNUNET_CONTAINER_DLL_remove (overlay->rl_head, | 381 | &overlay_link_completed, |
400 | overlay->rl_tail, | 382 | link, |
401 | retry_entry); | 383 | overlay->peers[link->A], |
402 | GNUNET_free (retry_entry); | 384 | overlay->peers[link->B]); |
385 | overlay->nlinks++; | ||
386 | GNUNET_CONTAINER_DLL_remove(overlay->rl_head, | ||
387 | overlay->rl_tail, | ||
388 | retry_entry); | ||
389 | GNUNET_free(retry_entry); | ||
390 | } | ||
391 | return; | ||
403 | } | 392 | } |
404 | return; | ||
405 | } | ||
406 | if (NULL != overlay->comp_cb) | 393 | if (NULL != overlay->comp_cb) |
407 | { | 394 | { |
408 | overlay->comp_cb (overlay->comp_cb_cls, | 395 | overlay->comp_cb(overlay->comp_cb_cls, |
409 | overlay->nsuccess, | 396 | overlay->nsuccess, |
410 | overlay->nfailures); | 397 | overlay->nfailures); |
411 | } | 398 | } |
412 | } | 399 | } |
413 | 400 | ||
414 | 401 | ||
@@ -419,24 +406,24 @@ overlay_link_completed (void *cls, | |||
419 | * @param cls the Topology context | 406 | * @param cls the Topology context |
420 | */ | 407 | */ |
421 | static void | 408 | static void |
422 | opstart_overlay_configure_topology (void *cls) | 409 | opstart_overlay_configure_topology(void *cls) |
423 | { | 410 | { |
424 | struct TopologyContext *tc = cls; | 411 | struct TopologyContext *tc = cls; |
425 | struct TopologyContextOverlay *overlay; | 412 | struct TopologyContextOverlay *overlay; |
426 | unsigned int p; | 413 | unsigned int p; |
427 | 414 | ||
428 | GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); | 415 | GNUNET_assert(TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); |
429 | overlay = &tc->u.overlay; | 416 | overlay = &tc->u.overlay; |
430 | overlay->nlinks = tc->link_array_size; | 417 | overlay->nlinks = tc->link_array_size; |
431 | for (p = 0; p < tc->link_array_size; p++) | 418 | for (p = 0; p < tc->link_array_size; p++) |
432 | { | 419 | { |
433 | overlay->link_array[p].op = | 420 | overlay->link_array[p].op = |
434 | GNUNET_TESTBED_overlay_connect (overlay->op_cls, | 421 | GNUNET_TESTBED_overlay_connect(overlay->op_cls, |
435 | &overlay_link_completed, | 422 | &overlay_link_completed, |
436 | &overlay->link_array[p], | 423 | &overlay->link_array[p], |
437 | overlay->peers[overlay->link_array[p].A], | 424 | overlay->peers[overlay->link_array[p].A], |
438 | overlay->peers[overlay->link_array[p].B]); | 425 | overlay->peers[overlay->link_array[p].B]); |
439 | } | 426 | } |
440 | } | 427 | } |
441 | 428 | ||
442 | 429 | ||
@@ -446,28 +433,28 @@ opstart_overlay_configure_topology (void *cls) | |||
446 | * @param cls the Topology context | 433 | * @param cls the Topology context |
447 | */ | 434 | */ |
448 | static void | 435 | static void |
449 | oprelease_overlay_configure_topology (void *cls) | 436 | oprelease_overlay_configure_topology(void *cls) |
450 | { | 437 | { |
451 | struct TopologyContext *tc = cls; | 438 | struct TopologyContext *tc = cls; |
452 | struct TopologyContextOverlay *overlay; | 439 | struct TopologyContextOverlay *overlay; |
453 | struct RetryListEntry *retry_entry; | 440 | struct RetryListEntry *retry_entry; |
454 | unsigned int p; | 441 | unsigned int p; |
455 | 442 | ||
456 | GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); | 443 | GNUNET_assert(TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); |
457 | overlay = &tc->u.overlay; | 444 | overlay = &tc->u.overlay; |
458 | while (NULL != (retry_entry = overlay->rl_head)) | 445 | while (NULL != (retry_entry = overlay->rl_head)) |
459 | { | 446 | { |
460 | GNUNET_CONTAINER_DLL_remove (overlay->rl_head, overlay->rl_tail, retry_entry); | 447 | GNUNET_CONTAINER_DLL_remove(overlay->rl_head, overlay->rl_tail, retry_entry); |
461 | GNUNET_free (retry_entry); | 448 | GNUNET_free(retry_entry); |
462 | } | 449 | } |
463 | if (NULL != overlay->link_array) | 450 | if (NULL != overlay->link_array) |
464 | { | 451 | { |
465 | for (p = 0; p < tc->link_array_size; p++) | 452 | for (p = 0; p < tc->link_array_size; p++) |
466 | if (NULL != overlay->link_array[p].op) | 453 | if (NULL != overlay->link_array[p].op) |
467 | GNUNET_TESTBED_operation_done (overlay->link_array[p].op); | 454 | GNUNET_TESTBED_operation_done(overlay->link_array[p].op); |
468 | GNUNET_free (overlay->link_array); | 455 | GNUNET_free(overlay->link_array); |
469 | } | 456 | } |
470 | GNUNET_free (tc); | 457 | GNUNET_free(tc); |
471 | } | 458 | } |
472 | 459 | ||
473 | 460 | ||
@@ -481,42 +468,43 @@ oprelease_overlay_configure_topology (void *cls) | |||
481 | * @return | 468 | * @return |
482 | */ | 469 | */ |
483 | static void | 470 | static void |
484 | make_link (unsigned int offset, | 471 | make_link(unsigned int offset, |
485 | uint32_t A, | 472 | uint32_t A, |
486 | uint32_t B, | 473 | uint32_t B, |
487 | struct TopologyContext *tc) | 474 | struct TopologyContext *tc) |
488 | { | 475 | { |
489 | GNUNET_assert (A != B); | 476 | GNUNET_assert(A != B); |
490 | switch (tc->type) | 477 | switch (tc->type) |
491 | { | 478 | { |
492 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: | 479 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: |
493 | { | 480 | { |
494 | struct TopologyContextOverlay *overlay; | 481 | struct TopologyContextOverlay *overlay; |
495 | struct OverlayLink *olink; | 482 | struct OverlayLink *olink; |
496 | 483 | ||
497 | overlay = &tc->u.overlay; | 484 | overlay = &tc->u.overlay; |
498 | GNUNET_assert (offset < tc->link_array_size); | 485 | GNUNET_assert(offset < tc->link_array_size); |
499 | olink = &overlay->link_array[offset]; | 486 | olink = &overlay->link_array[offset]; |
500 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %u to %u\n", B, A); | 487 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %u to %u\n", B, A); |
501 | olink->A = A; | 488 | olink->A = A; |
502 | olink->B = B; | 489 | olink->B = B; |
503 | olink->op = NULL; | 490 | olink->op = NULL; |
504 | olink->tc = tc; | 491 | olink->tc = tc; |
505 | } | 492 | } |
506 | break; | 493 | break; |
507 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | 494 | |
495 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | ||
508 | { | 496 | { |
509 | struct TopologyContextUnderlay *underlay; | 497 | struct TopologyContextUnderlay *underlay; |
510 | struct UnderlayLink *ulink; | 498 | struct UnderlayLink *ulink; |
511 | 499 | ||
512 | underlay = &tc->u.underlay; | 500 | underlay = &tc->u.underlay; |
513 | GNUNET_assert (offset < tc->link_array_size); | 501 | GNUNET_assert(offset < tc->link_array_size); |
514 | ulink = &underlay->link_array[offset]; | 502 | ulink = &underlay->link_array[offset]; |
515 | ulink->A = A; | 503 | ulink->A = A; |
516 | ulink->B = B; | 504 | ulink->B = B; |
517 | } | 505 | } |
518 | break; | 506 | break; |
519 | } | 507 | } |
520 | } | 508 | } |
521 | 509 | ||
522 | 510 | ||
@@ -526,36 +514,37 @@ make_link (unsigned int offset, | |||
526 | * @param tc the topology context | 514 | * @param tc the topology context |
527 | */ | 515 | */ |
528 | static void | 516 | static void |
529 | gen_topo_line (struct TopologyContext *tc) | 517 | gen_topo_line(struct TopologyContext *tc) |
530 | { | 518 | { |
531 | unsigned int cnt; | 519 | unsigned int cnt; |
532 | 520 | ||
533 | tc->link_array_size = tc->num_peers - 1; | 521 | tc->link_array_size = tc->num_peers - 1; |
534 | switch (tc->type) | 522 | switch (tc->type) |
535 | { | 523 | { |
536 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: | 524 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: |
537 | { | 525 | { |
538 | struct TopologyContextOverlay *overlay; | 526 | struct TopologyContextOverlay *overlay; |
539 | 527 | ||
540 | overlay = &tc->u.overlay; | 528 | overlay = &tc->u.overlay; |
541 | overlay->link_array = | 529 | overlay->link_array = |
542 | GNUNET_new_array (tc->link_array_size, | 530 | GNUNET_new_array(tc->link_array_size, |
543 | struct OverlayLink); | 531 | struct OverlayLink); |
544 | } | 532 | } |
545 | break; | 533 | break; |
546 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | 534 | |
535 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | ||
547 | { | 536 | { |
548 | struct TopologyContextUnderlay *underlay; | 537 | struct TopologyContextUnderlay *underlay; |
549 | 538 | ||
550 | underlay = &tc->u.underlay; | 539 | underlay = &tc->u.underlay; |
551 | underlay->link_array = | 540 | underlay->link_array = |
552 | GNUNET_new_array (tc->link_array_size, | 541 | GNUNET_new_array(tc->link_array_size, |
553 | struct UnderlayLink); | 542 | struct UnderlayLink); |
554 | } | 543 | } |
555 | break; | 544 | break; |
556 | } | 545 | } |
557 | for (cnt = 0; cnt < (tc->link_array_size); cnt++) | 546 | for (cnt = 0; cnt < (tc->link_array_size); cnt++) |
558 | make_link (cnt, cnt, cnt + 1, tc); | 547 | make_link(cnt, cnt, cnt + 1, tc); |
559 | } | 548 | } |
560 | 549 | ||
561 | 550 | ||
@@ -565,39 +554,40 @@ gen_topo_line (struct TopologyContext *tc) | |||
565 | * @param tc the topology context | 554 | * @param tc the topology context |
566 | */ | 555 | */ |
567 | static void | 556 | static void |
568 | gen_topo_star (struct TopologyContext *tc) | 557 | gen_topo_star(struct TopologyContext *tc) |
569 | { | 558 | { |
570 | unsigned int cnt; | 559 | unsigned int cnt; |
571 | 560 | ||
572 | tc->link_array_size = tc->num_peers - 1; | 561 | tc->link_array_size = tc->num_peers - 1; |
573 | switch (tc->type) | 562 | switch (tc->type) |
574 | { | 563 | { |
575 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: | 564 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: |
576 | { | 565 | { |
577 | struct TopologyContextOverlay *overlay; | 566 | struct TopologyContextOverlay *overlay; |
578 | 567 | ||
579 | overlay = &tc->u.overlay; | 568 | overlay = &tc->u.overlay; |
580 | overlay->link_array = | 569 | overlay->link_array = |
581 | GNUNET_new_array (tc->link_array_size, | 570 | GNUNET_new_array(tc->link_array_size, |
582 | struct OverlayLink); | 571 | struct OverlayLink); |
583 | } | 572 | } |
584 | break; | 573 | break; |
585 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | 574 | |
575 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | ||
586 | { | 576 | { |
587 | struct TopologyContextUnderlay *underlay; | 577 | struct TopologyContextUnderlay *underlay; |
588 | 578 | ||
589 | underlay = &tc->u.underlay; | 579 | underlay = &tc->u.underlay; |
590 | underlay->link_array = | 580 | underlay->link_array = |
591 | GNUNET_new_array (tc->link_array_size, | 581 | GNUNET_new_array(tc->link_array_size, |
592 | struct UnderlayLink); | 582 | struct UnderlayLink); |
593 | } | 583 | } |
594 | break; | 584 | break; |
595 | } | 585 | } |
596 | for (cnt = tc->link_array_size; cnt; cnt--) | 586 | for (cnt = tc->link_array_size; cnt; cnt--) |
597 | make_link (cnt - 1, | 587 | make_link(cnt - 1, |
598 | 0, | 588 | 0, |
599 | cnt, | 589 | cnt, |
600 | tc); | 590 | tc); |
601 | } | 591 | } |
602 | 592 | ||
603 | 593 | ||
@@ -607,34 +597,35 @@ gen_topo_star (struct TopologyContext *tc) | |||
607 | * @param tc the topology context | 597 | * @param tc the topology context |
608 | */ | 598 | */ |
609 | static void | 599 | static void |
610 | gen_topo_ring (struct TopologyContext *tc) | 600 | gen_topo_ring(struct TopologyContext *tc) |
611 | { | 601 | { |
612 | gen_topo_line (tc); | 602 | gen_topo_line(tc); |
613 | tc->link_array_size++; | 603 | tc->link_array_size++; |
614 | switch (tc->type) | 604 | switch (tc->type) |
615 | { | 605 | { |
616 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: | 606 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: |
617 | { | 607 | { |
618 | struct TopologyContextOverlay *overlay; | 608 | struct TopologyContextOverlay *overlay; |
619 | 609 | ||
620 | overlay = &tc->u.overlay; | 610 | overlay = &tc->u.overlay; |
621 | overlay->link_array = | 611 | overlay->link_array = |
622 | GNUNET_realloc (overlay->link_array, sizeof (struct OverlayLink) * | 612 | GNUNET_realloc(overlay->link_array, sizeof(struct OverlayLink) * |
623 | tc->link_array_size); | 613 | tc->link_array_size); |
624 | } | 614 | } |
625 | break; | 615 | break; |
626 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | 616 | |
617 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | ||
627 | { | 618 | { |
628 | struct TopologyContextUnderlay *underlay; | 619 | struct TopologyContextUnderlay *underlay; |
629 | 620 | ||
630 | underlay = &tc->u.underlay; | 621 | underlay = &tc->u.underlay; |
631 | underlay->link_array = | 622 | underlay->link_array = |
632 | GNUNET_realloc (underlay->link_array, sizeof (struct UnderlayLink) * | 623 | GNUNET_realloc(underlay->link_array, sizeof(struct UnderlayLink) * |
633 | tc->link_array_size); | 624 | tc->link_array_size); |
634 | } | 625 | } |
635 | break; | 626 | break; |
636 | } | 627 | } |
637 | make_link (tc->link_array_size - 1, tc->num_peers - 1, 0, tc); | 628 | make_link(tc->link_array_size - 1, tc->num_peers - 1, 0, tc); |
638 | } | 629 | } |
639 | 630 | ||
640 | 631 | ||
@@ -651,8 +642,8 @@ gen_topo_ring (struct TopologyContext *tc) | |||
651 | * given number of peers | 642 | * given number of peers |
652 | */ | 643 | */ |
653 | unsigned int | 644 | unsigned int |
654 | GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows, | 645 | GNUNET_TESTBED_2dtorus_calc_links(unsigned int num_peers, unsigned int *rows, |
655 | unsigned int **rows_len) | 646 | unsigned int **rows_len) |
656 | { | 647 | { |
657 | double sq; | 648 | double sq; |
658 | unsigned int sq_floor; | 649 | unsigned int sq_floor; |
@@ -663,11 +654,11 @@ GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows, | |||
663 | unsigned int _num_peers; | 654 | unsigned int _num_peers; |
664 | unsigned int cnt; | 655 | unsigned int cnt; |
665 | 656 | ||
666 | sq = sqrt (num_peers); | 657 | sq = sqrt(num_peers); |
667 | sq = floor (sq); | 658 | sq = floor(sq); |
668 | sq_floor = (unsigned int) sq; | 659 | sq_floor = (unsigned int)sq; |
669 | _rows = (sq_floor + 1); | 660 | _rows = (sq_floor + 1); |
670 | _rows_len = GNUNET_malloc (sizeof (unsigned int) * _rows); | 661 | _rows_len = GNUNET_malloc(sizeof(unsigned int) * _rows); |
671 | for (y = 0; y < _rows - 1; y++) | 662 | for (y = 0; y < _rows - 1; y++) |
672 | _rows_len[y] = sq_floor; | 663 | _rows_len[y] = sq_floor; |
673 | _num_peers = sq_floor * sq_floor; | 664 | _num_peers = sq_floor * sq_floor; |
@@ -675,13 +666,13 @@ GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows, | |||
675 | x = 0; | 666 | x = 0; |
676 | y = 0; | 667 | y = 0; |
677 | while (_num_peers < num_peers) | 668 | while (_num_peers < num_peers) |
678 | { | 669 | { |
679 | if (x < y) | 670 | if (x < y) |
680 | _rows_len[_rows - 1] = ++x; | 671 | _rows_len[_rows - 1] = ++x; |
681 | else | 672 | else |
682 | _rows_len[y++]++; | 673 | _rows_len[y++]++; |
683 | _num_peers++; | 674 | _num_peers++; |
684 | } | 675 | } |
685 | cnt += (x < 2) ? x : 2 * x; | 676 | cnt += (x < 2) ? x : 2 * x; |
686 | cnt += (y < 2) ? y : 2 * y; | 677 | cnt += (y < 2) ? y : 2 * y; |
687 | if (0 == _rows_len[_rows - 1]) | 678 | if (0 == _rows_len[_rows - 1]) |
@@ -691,7 +682,7 @@ GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows, | |||
691 | if (NULL != rows_len) | 682 | if (NULL != rows_len) |
692 | *rows_len = _rows_len; | 683 | *rows_len = _rows_len; |
693 | else | 684 | else |
694 | GNUNET_free (_rows_len); | 685 | GNUNET_free(_rows_len); |
695 | return cnt; | 686 | return cnt; |
696 | } | 687 | } |
697 | 688 | ||
@@ -702,7 +693,7 @@ GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows, | |||
702 | * @param tc the topology context | 693 | * @param tc the topology context |
703 | */ | 694 | */ |
704 | static void | 695 | static void |
705 | gen_topo_2dtorus (struct TopologyContext *tc) | 696 | gen_topo_2dtorus(struct TopologyContext *tc) |
706 | { | 697 | { |
707 | unsigned int rows; | 698 | unsigned int rows; |
708 | unsigned int *rows_len; | 699 | unsigned int *rows_len; |
@@ -712,62 +703,63 @@ gen_topo_2dtorus (struct TopologyContext *tc) | |||
712 | unsigned int offset; | 703 | unsigned int offset; |
713 | 704 | ||
714 | tc->link_array_size = | 705 | tc->link_array_size = |
715 | GNUNET_TESTBED_2dtorus_calc_links (tc->num_peers, &rows, &rows_len); | 706 | GNUNET_TESTBED_2dtorus_calc_links(tc->num_peers, &rows, &rows_len); |
716 | switch (tc->type) | 707 | switch (tc->type) |
717 | { | 708 | { |
718 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: | 709 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: |
719 | { | 710 | { |
720 | struct TopologyContextOverlay *overlay; | 711 | struct TopologyContextOverlay *overlay; |
721 | 712 | ||
722 | overlay = &tc->u.overlay; | 713 | overlay = &tc->u.overlay; |
723 | overlay->link_array = | 714 | overlay->link_array = |
724 | GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size); | 715 | GNUNET_malloc(sizeof(struct OverlayLink) * tc->link_array_size); |
725 | } | 716 | } |
726 | break; | 717 | break; |
727 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | 718 | |
719 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | ||
728 | { | 720 | { |
729 | struct TopologyContextUnderlay *underlay; | 721 | struct TopologyContextUnderlay *underlay; |
730 | 722 | ||
731 | underlay = &tc->u.underlay; | 723 | underlay = &tc->u.underlay; |
732 | underlay->link_array = | 724 | underlay->link_array = |
733 | GNUNET_malloc (sizeof (struct UnderlayLink) * tc->link_array_size); | 725 | GNUNET_malloc(sizeof(struct UnderlayLink) * tc->link_array_size); |
734 | break; | 726 | break; |
735 | } | 727 | } |
736 | } | 728 | } |
737 | cnt = 0; | 729 | cnt = 0; |
738 | offset = 0; | 730 | offset = 0; |
739 | for (y = 0; y < rows; y++) | 731 | for (y = 0; y < rows; y++) |
740 | { | ||
741 | for (x = 0; x < rows_len[y] - 1; x++) | ||
742 | { | 732 | { |
743 | make_link (cnt, offset + x, offset + x + 1, tc); | 733 | for (x = 0; x < rows_len[y] - 1; x++) |
734 | { | ||
735 | make_link(cnt, offset + x, offset + x + 1, tc); | ||
736 | cnt++; | ||
737 | } | ||
738 | if (0 == x) | ||
739 | break; | ||
740 | make_link(cnt, offset + x, offset, tc); | ||
744 | cnt++; | 741 | cnt++; |
742 | offset += rows_len[y]; | ||
745 | } | 743 | } |
746 | if (0 == x) | ||
747 | break; | ||
748 | make_link (cnt, offset + x, offset, tc); | ||
749 | cnt++; | ||
750 | offset += rows_len[y]; | ||
751 | } | ||
752 | for (x = 0; x < rows_len[0]; x++) | 744 | for (x = 0; x < rows_len[0]; x++) |
753 | { | ||
754 | offset = 0; | ||
755 | for (y = 0; y < rows - 1; y++) | ||
756 | { | 745 | { |
757 | if (x >= rows_len[y + 1]) | 746 | offset = 0; |
747 | for (y = 0; y < rows - 1; y++) | ||
748 | { | ||
749 | if (x >= rows_len[y + 1]) | ||
750 | break; | ||
751 | GNUNET_assert(x < rows_len[y + 1]); | ||
752 | make_link(cnt, offset + x, offset + rows_len[y] + x, tc); | ||
753 | offset += rows_len[y]; | ||
754 | cnt++; | ||
755 | } | ||
756 | if (0 == offset) | ||
758 | break; | 757 | break; |
759 | GNUNET_assert (x < rows_len[y + 1]); | 758 | make_link(cnt, offset + x, x, tc); |
760 | make_link (cnt, offset + x, offset + rows_len[y] + x, tc); | ||
761 | offset += rows_len[y]; | ||
762 | cnt++; | 759 | cnt++; |
763 | } | 760 | } |
764 | if (0 == offset) | 761 | GNUNET_assert(cnt == tc->link_array_size); |
765 | break; | 762 | GNUNET_free(rows_len); |
766 | make_link (cnt, offset + x, x, tc); | ||
767 | cnt++; | ||
768 | } | ||
769 | GNUNET_assert (cnt == tc->link_array_size); | ||
770 | GNUNET_free (rows_len); | ||
771 | } | 763 | } |
772 | 764 | ||
773 | 765 | ||
@@ -780,9 +772,9 @@ gen_topo_2dtorus (struct TopologyContext *tc) | |||
780 | * create a new link array | 772 | * create a new link array |
781 | */ | 773 | */ |
782 | static void | 774 | static void |
783 | gen_topo_random (struct TopologyContext *tc, | 775 | gen_topo_random(struct TopologyContext *tc, |
784 | unsigned int links, | 776 | unsigned int links, |
785 | int append) | 777 | int append) |
786 | { | 778 | { |
787 | unsigned int cnt; | 779 | unsigned int cnt; |
788 | unsigned int index; | 780 | unsigned int index; |
@@ -792,66 +784,67 @@ gen_topo_random (struct TopologyContext *tc, | |||
792 | if (1 == tc->num_peers) | 784 | if (1 == tc->num_peers) |
793 | return; | 785 | return; |
794 | if (GNUNET_YES == append) | 786 | if (GNUNET_YES == append) |
795 | { | 787 | { |
796 | index = tc->link_array_size; | 788 | index = tc->link_array_size; |
797 | tc->link_array_size += links; | 789 | tc->link_array_size += links; |
798 | } | 790 | } |
799 | else | 791 | else |
800 | { | 792 | { |
801 | index = 0; | 793 | index = 0; |
802 | tc->link_array_size = links; | 794 | tc->link_array_size = links; |
803 | } | 795 | } |
804 | switch (tc->type) | 796 | switch (tc->type) |
805 | { | 797 | { |
806 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: | 798 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: |
807 | { | 799 | { |
808 | struct TopologyContextOverlay *overlay; | 800 | struct TopologyContextOverlay *overlay; |
809 | 801 | ||
810 | overlay = &tc->u.overlay; | 802 | overlay = &tc->u.overlay; |
811 | if (GNUNET_YES != append) | 803 | if (GNUNET_YES != append) |
812 | { | 804 | { |
813 | GNUNET_assert (NULL == overlay->link_array); | 805 | GNUNET_assert(NULL == overlay->link_array); |
814 | overlay->link_array = | 806 | overlay->link_array = |
815 | GNUNET_malloc (sizeof (struct OverlayLink) * tc->link_array_size); | 807 | GNUNET_malloc(sizeof(struct OverlayLink) * tc->link_array_size); |
816 | break; | 808 | break; |
817 | } | 809 | } |
818 | GNUNET_assert ((0 < tc->link_array_size) && (NULL != overlay->link_array)); | 810 | GNUNET_assert((0 < tc->link_array_size) && (NULL != overlay->link_array)); |
819 | overlay->link_array = | 811 | overlay->link_array = |
820 | GNUNET_realloc (overlay->link_array, | 812 | GNUNET_realloc(overlay->link_array, |
821 | sizeof (struct OverlayLink) * tc->link_array_size); | 813 | sizeof(struct OverlayLink) * tc->link_array_size); |
822 | break; | 814 | break; |
823 | } | 815 | } |
824 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | 816 | |
817 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | ||
825 | { | 818 | { |
826 | struct TopologyContextUnderlay *underlay; | 819 | struct TopologyContextUnderlay *underlay; |
827 | 820 | ||
828 | underlay = &tc->u.underlay; | 821 | underlay = &tc->u.underlay; |
829 | if (GNUNET_YES != append) | 822 | if (GNUNET_YES != append) |
830 | { | 823 | { |
831 | GNUNET_assert (NULL == underlay->link_array); | 824 | GNUNET_assert(NULL == underlay->link_array); |
832 | underlay->link_array = | 825 | underlay->link_array = |
833 | GNUNET_malloc (sizeof (struct UnderlayLink) * tc->link_array_size); | 826 | GNUNET_malloc(sizeof(struct UnderlayLink) * tc->link_array_size); |
834 | break; | 827 | break; |
835 | } | 828 | } |
836 | GNUNET_assert ((0 < tc->link_array_size) && (NULL != underlay->link_array)); | 829 | GNUNET_assert((0 < tc->link_array_size) && (NULL != underlay->link_array)); |
837 | underlay->link_array = | 830 | underlay->link_array = |
838 | GNUNET_realloc (underlay->link_array, | 831 | GNUNET_realloc(underlay->link_array, |
839 | sizeof (struct UnderlayLink) * tc->link_array_size); | 832 | sizeof(struct UnderlayLink) * tc->link_array_size); |
840 | break; | 833 | break; |
841 | } | 834 | } |
842 | } | 835 | } |
843 | for (cnt = 0; cnt < links; cnt++) | 836 | for (cnt = 0; cnt < links; cnt++) |
844 | { | ||
845 | do | ||
846 | { | 837 | { |
847 | A_rand = | 838 | do |
848 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers); | 839 | { |
849 | B_rand = | 840 | A_rand = |
850 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers); | 841 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers); |
842 | B_rand = | ||
843 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers); | ||
844 | } | ||
845 | while (A_rand == B_rand); | ||
846 | make_link(index + cnt, A_rand, B_rand, tc); | ||
851 | } | 847 | } |
852 | while (A_rand == B_rand); | ||
853 | make_link (index+cnt, A_rand, B_rand, tc); | ||
854 | } | ||
855 | } | 848 | } |
856 | 849 | ||
857 | 850 | ||
@@ -866,9 +859,9 @@ gen_topo_random (struct TopologyContext *tc, | |||
866 | * network | 859 | * network |
867 | */ | 860 | */ |
868 | static void | 861 | static void |
869 | gen_topo_scale_free (struct TopologyContext *tc, | 862 | gen_topo_scale_free(struct TopologyContext *tc, |
870 | uint16_t cap, | 863 | uint16_t cap, |
871 | uint8_t m) | 864 | uint8_t m) |
872 | { | 865 | { |
873 | unsigned int *deg; | 866 | unsigned int *deg; |
874 | unsigned int *etab; | 867 | unsigned int *etab; |
@@ -885,106 +878,108 @@ gen_topo_scale_free (struct TopologyContext *tc, | |||
885 | etaboff = 0; | 878 | etaboff = 0; |
886 | tc->link_array_size = tc->num_peers * m; | 879 | tc->link_array_size = tc->num_peers * m; |
887 | switch (tc->type) | 880 | switch (tc->type) |
888 | { | 881 | { |
889 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: | 882 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: |
890 | { | 883 | { |
891 | struct TopologyContextOverlay *overlay; | 884 | struct TopologyContextOverlay *overlay; |
892 | 885 | ||
893 | overlay = &tc->u.overlay; | 886 | overlay = &tc->u.overlay; |
894 | overlay->link_array = GNUNET_malloc_large (sizeof (struct OverlayLink) * | 887 | overlay->link_array = GNUNET_malloc_large(sizeof(struct OverlayLink) * |
895 | tc->link_array_size); | 888 | tc->link_array_size); |
896 | } | 889 | } |
897 | break; | 890 | break; |
898 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | 891 | |
892 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | ||
899 | { | 893 | { |
900 | struct TopologyContextUnderlay *underlay; | 894 | struct TopologyContextUnderlay *underlay; |
901 | 895 | ||
902 | underlay = &tc->u.underlay; | 896 | underlay = &tc->u.underlay; |
903 | underlay->link_array = GNUNET_malloc_large (sizeof (struct UnderlayLink) * | 897 | underlay->link_array = GNUNET_malloc_large(sizeof(struct UnderlayLink) * |
904 | tc->link_array_size); | 898 | tc->link_array_size); |
905 | } | 899 | } |
906 | break; | 900 | break; |
907 | } | 901 | } |
908 | etab = GNUNET_malloc_large (sizeof (unsigned int) * 2 * tc->link_array_size); | 902 | etab = GNUNET_malloc_large(sizeof(unsigned int) * 2 * tc->link_array_size); |
909 | deg = GNUNET_malloc (sizeof (unsigned int) * tc->num_peers); | 903 | deg = GNUNET_malloc(sizeof(unsigned int) * tc->num_peers); |
910 | used = GNUNET_malloc (sizeof (unsigned int) * m); | 904 | used = GNUNET_malloc(sizeof(unsigned int) * m); |
911 | /* start by connecting peer 1 to peer 0 */ | 905 | /* start by connecting peer 1 to peer 0 */ |
912 | make_link (0, 0, 1, tc); | 906 | make_link(0, 0, 1, tc); |
913 | deg[0]++; | 907 | deg[0]++; |
914 | deg[1]++; | 908 | deg[1]++; |
915 | etab[etaboff++] = 0; | 909 | etab[etaboff++] = 0; |
916 | etab[etaboff++] = 1; | 910 | etab[etaboff++] = 1; |
917 | links = 1; | 911 | links = 1; |
918 | for (peer = 2; peer < tc->num_peers; peer++) | 912 | for (peer = 2; peer < tc->num_peers; peer++) |
919 | { | ||
920 | if (cap < deg[peer]) | ||
921 | continue; | ||
922 | for (cnt = 0; cnt < GNUNET_MIN (peer, m); cnt++) | ||
923 | { | 913 | { |
924 | redo_threshold = 0; | 914 | if (cap < deg[peer]) |
925 | redo: | 915 | continue; |
926 | off = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, etaboff); | 916 | for (cnt = 0; cnt < GNUNET_MIN(peer, m); cnt++) |
927 | random_peer = etab[off]; | ||
928 | if (cap < deg[random_peer]) | ||
929 | { | ||
930 | if (++redo_threshold > GNUNET_MAX (1, cap / 2)) | ||
931 | { | 917 | { |
932 | redo_threshold = 0; | 918 | redo_threshold = 0; |
933 | off = 0; | 919 | redo: |
934 | for (cnt2 = 0; cnt2 < etaboff; cnt2++) | 920 | off = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, etaboff); |
935 | { | 921 | random_peer = etab[off]; |
936 | if (random_peer == etab[cnt2]) | 922 | if (cap < deg[random_peer]) |
937 | { | 923 | { |
938 | off++; | 924 | if (++redo_threshold > GNUNET_MAX(1, cap / 2)) |
939 | continue; | 925 | { |
926 | redo_threshold = 0; | ||
927 | off = 0; | ||
928 | for (cnt2 = 0; cnt2 < etaboff; cnt2++) | ||
929 | { | ||
930 | if (random_peer == etab[cnt2]) | ||
931 | { | ||
932 | off++; | ||
933 | continue; | ||
934 | } | ||
935 | etab[cnt2 - off] = etab[cnt2]; | ||
936 | } | ||
937 | etaboff -= off; | ||
938 | } | ||
939 | goto redo; | ||
940 | } | 940 | } |
941 | etab[cnt2 - off] = etab[cnt2]; | 941 | for (cnt2 = 0; cnt2 < cnt; cnt2++) |
942 | } | 942 | if (random_peer == used[cnt2]) |
943 | etaboff -= off; | 943 | goto redo; |
944 | make_link(links + cnt, random_peer, peer, tc); | ||
945 | deg[random_peer]++; | ||
946 | deg[peer]++; | ||
947 | used[cnt] = random_peer; | ||
944 | } | 948 | } |
945 | goto redo; | 949 | for (cnt = 0; cnt < GNUNET_MIN(peer, m); cnt++) |
946 | } | 950 | { |
947 | for (cnt2 = 0; cnt2 < cnt; cnt2++) | 951 | etab[etaboff++] = used[cnt]; |
948 | if (random_peer == used[cnt2]) | 952 | etab[etaboff++] = peer; |
949 | goto redo; | 953 | } |
950 | make_link (links + cnt, random_peer, peer, tc); | 954 | links += GNUNET_MIN(peer, m); |
951 | deg[random_peer]++; | ||
952 | deg[peer]++; | ||
953 | used[cnt] = random_peer; | ||
954 | } | ||
955 | for (cnt = 0; cnt < GNUNET_MIN (peer, m); cnt++) | ||
956 | { | ||
957 | etab[etaboff++] = used[cnt]; | ||
958 | etab[etaboff++] = peer; | ||
959 | } | 955 | } |
960 | links += GNUNET_MIN (peer, m); | 956 | GNUNET_free(etab); |
961 | } | 957 | GNUNET_free(used); |
962 | GNUNET_free (etab); | 958 | GNUNET_free(deg); |
963 | GNUNET_free (used); | 959 | GNUNET_assert(links <= tc->link_array_size); |
964 | GNUNET_free (deg); | ||
965 | GNUNET_assert (links <= tc->link_array_size); | ||
966 | tc->link_array_size = links; | 960 | tc->link_array_size = links; |
967 | switch (tc->type) | 961 | switch (tc->type) |
968 | { | 962 | { |
969 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: | 963 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: |
970 | { | 964 | { |
971 | struct TopologyContextOverlay *overlay; | 965 | struct TopologyContextOverlay *overlay; |
972 | 966 | ||
973 | overlay = &tc->u.overlay; | 967 | overlay = &tc->u.overlay; |
974 | overlay->link_array = | 968 | overlay->link_array = |
975 | GNUNET_realloc (overlay->link_array, sizeof (struct OverlayLink) * tc->link_array_size); | 969 | GNUNET_realloc(overlay->link_array, sizeof(struct OverlayLink) * tc->link_array_size); |
976 | } | 970 | } |
977 | break; | 971 | break; |
978 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | 972 | |
973 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | ||
979 | { | 974 | { |
980 | struct TopologyContextUnderlay *underlay; | 975 | struct TopologyContextUnderlay *underlay; |
981 | 976 | ||
982 | underlay = &tc->u.underlay; | 977 | underlay = &tc->u.underlay; |
983 | underlay->link_array = | 978 | underlay->link_array = |
984 | GNUNET_realloc (underlay->link_array, sizeof (struct UnderlayLink) * tc->link_array_size); | 979 | GNUNET_realloc(underlay->link_array, sizeof(struct UnderlayLink) * tc->link_array_size); |
985 | } | 980 | } |
986 | break; | 981 | break; |
987 | } | 982 | } |
988 | } | 983 | } |
989 | 984 | ||
990 | 985 | ||
@@ -995,8 +990,8 @@ gen_topo_scale_free (struct TopologyContext *tc, | |||
995 | * @param filename the filename of the file containing topology data | 990 | * @param filename the filename of the file containing topology data |
996 | */ | 991 | */ |
997 | static void | 992 | static void |
998 | gen_topo_from_file (struct TopologyContext *tc, | 993 | gen_topo_from_file(struct TopologyContext *tc, |
999 | const char *filename) | 994 | const char *filename) |
1000 | { | 995 | { |
1001 | char *data; | 996 | char *data; |
1002 | char *end; | 997 | char *end; |
@@ -1005,9 +1000,7 @@ gen_topo_from_file (struct TopologyContext *tc, | |||
1005 | uint64_t offset; | 1000 | uint64_t offset; |
1006 | unsigned long int peer_id; | 1001 | unsigned long int peer_id; |
1007 | unsigned long int other_peer_id; | 1002 | unsigned long int other_peer_id; |
1008 | enum ParseState | 1003 | enum ParseState { |
1009 | { | ||
1010 | |||
1011 | /** | 1004 | /** |
1012 | * We read the peer index | 1005 | * We read the peer index |
1013 | */ | 1006 | */ |
@@ -1017,179 +1010,181 @@ gen_topo_from_file (struct TopologyContext *tc, | |||
1017 | * We read the other peer indices | 1010 | * We read the other peer indices |
1018 | */ | 1011 | */ |
1019 | OTHER_PEER_INDEX, | 1012 | OTHER_PEER_INDEX, |
1020 | |||
1021 | } state; | 1013 | } state; |
1022 | int status; | 1014 | int status; |
1023 | 1015 | ||
1024 | status = GNUNET_SYSERR; | 1016 | status = GNUNET_SYSERR; |
1025 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | 1017 | if (GNUNET_YES != GNUNET_DISK_file_test(filename)) |
1026 | { | 1018 | { |
1027 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1019 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1028 | _("Topology file %s not found\n"), | 1020 | _("Topology file %s not found\n"), |
1029 | filename); | 1021 | filename); |
1030 | return; | 1022 | return; |
1031 | } | 1023 | } |
1032 | if (GNUNET_OK != | 1024 | if (GNUNET_OK != |
1033 | GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) | 1025 | GNUNET_DISK_file_size(filename, &fs, GNUNET_YES, GNUNET_YES)) |
1034 | { | 1026 | { |
1035 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1027 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1036 | _("Topology file %s has no data\n"), | 1028 | _("Topology file %s has no data\n"), |
1037 | filename); | 1029 | filename); |
1038 | return; | 1030 | return; |
1039 | } | 1031 | } |
1040 | data = GNUNET_malloc (fs); | 1032 | data = GNUNET_malloc(fs); |
1041 | if (fs != GNUNET_DISK_fn_read (filename, data, fs)) | 1033 | if (fs != GNUNET_DISK_fn_read(filename, data, fs)) |
1042 | { | 1034 | { |
1043 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1035 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1044 | _("Topology file %s cannot be read\n"), | 1036 | _("Topology file %s cannot be read\n"), |
1045 | filename); | 1037 | filename); |
1046 | goto _exit; | 1038 | goto _exit; |
1047 | } | 1039 | } |
1048 | 1040 | ||
1049 | offset = 0; | 1041 | offset = 0; |
1050 | peer_id = 0; | 1042 | peer_id = 0; |
1051 | state = PEER_INDEX; | 1043 | state = PEER_INDEX; |
1052 | while (offset < fs) | 1044 | while (offset < fs) |
1053 | { | ||
1054 | if (0 != isspace ((unsigned char) data[offset])) | ||
1055 | { | ||
1056 | offset++; | ||
1057 | continue; | ||
1058 | } | ||
1059 | switch (state) | ||
1060 | { | 1045 | { |
1061 | case PEER_INDEX: | 1046 | if (0 != isspace((unsigned char)data[offset])) |
1062 | buf = strchr (&data[offset], ':'); | ||
1063 | if (NULL == buf) | ||
1064 | { | ||
1065 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1066 | _("Failed to read peer index from toology file: %s"), filename); | ||
1067 | goto _exit; | ||
1068 | } | ||
1069 | *buf = '\0'; | ||
1070 | errno = 0; | ||
1071 | peer_id = (unsigned int) strtoul (&data[offset], &end, 10); | ||
1072 | if (0 != errno) | ||
1073 | { | ||
1074 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1075 | _("Value in given topology file: %s out of range\n"), filename); | ||
1076 | goto _exit; | ||
1077 | } | ||
1078 | if (&data[offset] == end) | ||
1079 | { | ||
1080 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1081 | _("Failed to read peer index from topology file: %s"), filename); | ||
1082 | goto _exit; | ||
1083 | } | ||
1084 | if (tc->num_peers <= peer_id) | ||
1085 | { | ||
1086 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1087 | _("Topology file needs more peers than given ones\n"), filename); | ||
1088 | goto _exit; | ||
1089 | } | ||
1090 | state = OTHER_PEER_INDEX; | ||
1091 | offset += ((unsigned int) (buf - &data[offset])) + 1; | ||
1092 | break; | ||
1093 | case OTHER_PEER_INDEX: | ||
1094 | errno = 0; | ||
1095 | other_peer_id = (unsigned int) strtoul (&data[offset], &end, 10); | ||
1096 | if (0 != errno) | ||
1097 | { | ||
1098 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1099 | _("Value in given topology file: %s out of range\n"), filename); | ||
1100 | goto _exit; | ||
1101 | } | ||
1102 | if (&data[offset] == end) | ||
1103 | { | ||
1104 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1105 | _("Failed to read peer index from topology file: %s"), filename); | ||
1106 | goto _exit; | ||
1107 | } | ||
1108 | if (tc->num_peers <= other_peer_id) | ||
1109 | { | ||
1110 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1111 | _("Topology file needs more peers than given ones\n"), filename); | ||
1112 | goto _exit; | ||
1113 | } | ||
1114 | if (peer_id != other_peer_id) | ||
1115 | { | ||
1116 | tc->link_array_size++; | ||
1117 | switch (tc->type) | ||
1118 | { | 1047 | { |
1119 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: | 1048 | offset++; |
1120 | { | 1049 | continue; |
1121 | struct TopologyContextOverlay *overlay; | 1050 | } |
1122 | 1051 | switch (state) | |
1123 | overlay = &tc->u.overlay; | 1052 | { |
1124 | overlay->link_array = | 1053 | case PEER_INDEX: |
1125 | GNUNET_realloc (overlay->link_array, | 1054 | buf = strchr(&data[offset], ':'); |
1126 | sizeof (struct OverlayLink) * tc->link_array_size); | 1055 | if (NULL == buf) |
1127 | } | 1056 | { |
1057 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
1058 | _("Failed to read peer index from toology file: %s"), filename); | ||
1059 | goto _exit; | ||
1060 | } | ||
1061 | *buf = '\0'; | ||
1062 | errno = 0; | ||
1063 | peer_id = (unsigned int)strtoul(&data[offset], &end, 10); | ||
1064 | if (0 != errno) | ||
1065 | { | ||
1066 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
1067 | _("Value in given topology file: %s out of range\n"), filename); | ||
1068 | goto _exit; | ||
1069 | } | ||
1070 | if (&data[offset] == end) | ||
1071 | { | ||
1072 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
1073 | _("Failed to read peer index from topology file: %s"), filename); | ||
1074 | goto _exit; | ||
1075 | } | ||
1076 | if (tc->num_peers <= peer_id) | ||
1077 | { | ||
1078 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
1079 | _("Topology file needs more peers than given ones\n"), filename); | ||
1080 | goto _exit; | ||
1081 | } | ||
1082 | state = OTHER_PEER_INDEX; | ||
1083 | offset += ((unsigned int)(buf - &data[offset])) + 1; | ||
1128 | break; | 1084 | break; |
1129 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | 1085 | |
1130 | { | 1086 | case OTHER_PEER_INDEX: |
1131 | struct TopologyContextUnderlay *underlay; | 1087 | errno = 0; |
1132 | 1088 | other_peer_id = (unsigned int)strtoul(&data[offset], &end, 10); | |
1133 | underlay = &tc->u.underlay; | 1089 | if (0 != errno) |
1134 | underlay->link_array = | 1090 | { |
1135 | GNUNET_realloc (underlay->link_array, | 1091 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1136 | sizeof (struct UnderlayLink) * tc->link_array_size); | 1092 | _("Value in given topology file: %s out of range\n"), filename); |
1137 | } | 1093 | goto _exit; |
1094 | } | ||
1095 | if (&data[offset] == end) | ||
1096 | { | ||
1097 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
1098 | _("Failed to read peer index from topology file: %s"), filename); | ||
1099 | goto _exit; | ||
1100 | } | ||
1101 | if (tc->num_peers <= other_peer_id) | ||
1102 | { | ||
1103 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
1104 | _("Topology file needs more peers than given ones\n"), filename); | ||
1105 | goto _exit; | ||
1106 | } | ||
1107 | if (peer_id != other_peer_id) | ||
1108 | { | ||
1109 | tc->link_array_size++; | ||
1110 | switch (tc->type) | ||
1111 | { | ||
1112 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: | ||
1113 | { | ||
1114 | struct TopologyContextOverlay *overlay; | ||
1115 | |||
1116 | overlay = &tc->u.overlay; | ||
1117 | overlay->link_array = | ||
1118 | GNUNET_realloc(overlay->link_array, | ||
1119 | sizeof(struct OverlayLink) * tc->link_array_size); | ||
1120 | } | ||
1121 | break; | ||
1122 | |||
1123 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | ||
1124 | { | ||
1125 | struct TopologyContextUnderlay *underlay; | ||
1126 | |||
1127 | underlay = &tc->u.underlay; | ||
1128 | underlay->link_array = | ||
1129 | GNUNET_realloc(underlay->link_array, | ||
1130 | sizeof(struct UnderlayLink) * tc->link_array_size); | ||
1131 | } | ||
1132 | break; | ||
1133 | } | ||
1134 | offset += end - &data[offset]; | ||
1135 | make_link(tc->link_array_size - 1, peer_id, other_peer_id, tc); | ||
1136 | } | ||
1137 | else | ||
1138 | LOG(GNUNET_ERROR_TYPE_WARNING, | ||
1139 | _("Ignoring to connect peer %u to peer %u\n"), | ||
1140 | peer_id, | ||
1141 | other_peer_id); | ||
1142 | while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs)) | ||
1143 | offset++; | ||
1144 | if ((offset < fs) && | ||
1145 | ('\n' == data[offset])) | ||
1146 | state = PEER_INDEX; | ||
1147 | else if ((offset < fs) && | ||
1148 | ('|' == data[offset])) | ||
1149 | { | ||
1150 | state = OTHER_PEER_INDEX; | ||
1151 | offset++; | ||
1152 | } | ||
1138 | break; | 1153 | break; |
1139 | } | 1154 | } |
1140 | offset += end - &data[offset]; | ||
1141 | make_link (tc->link_array_size - 1, peer_id, other_peer_id, tc); | ||
1142 | } | ||
1143 | else | ||
1144 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1145 | _("Ignoring to connect peer %u to peer %u\n"), | ||
1146 | peer_id, | ||
1147 | other_peer_id); | ||
1148 | while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs)) | ||
1149 | offset++; | ||
1150 | if ( (offset < fs) && | ||
1151 | ('\n' == data[offset]) ) | ||
1152 | state = PEER_INDEX; | ||
1153 | else if ( (offset < fs) && | ||
1154 | ('|' == data[offset]) ) | ||
1155 | { | ||
1156 | state = OTHER_PEER_INDEX; | ||
1157 | offset++; | ||
1158 | } | ||
1159 | break; | ||
1160 | } | 1155 | } |
1161 | } | ||
1162 | status = GNUNET_OK; | 1156 | status = GNUNET_OK; |
1163 | 1157 | ||
1164 | _exit: | 1158 | _exit: |
1165 | GNUNET_free (data); | 1159 | GNUNET_free(data); |
1166 | if (GNUNET_OK != status) | 1160 | if (GNUNET_OK != status) |
1167 | { | ||
1168 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1169 | "Removing link data read from the file\n"); | ||
1170 | tc->link_array_size = 0; | ||
1171 | switch (tc->type) | ||
1172 | { | 1161 | { |
1173 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: | 1162 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1174 | { | 1163 | "Removing link data read from the file\n"); |
1175 | struct TopologyContextOverlay *overlay; | 1164 | tc->link_array_size = 0; |
1165 | switch (tc->type) | ||
1166 | { | ||
1167 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: | ||
1168 | { | ||
1169 | struct TopologyContextOverlay *overlay; | ||
1176 | 1170 | ||
1177 | overlay = &tc->u.overlay; | 1171 | overlay = &tc->u.overlay; |
1178 | GNUNET_free_non_null (overlay->link_array); | 1172 | GNUNET_free_non_null(overlay->link_array); |
1179 | overlay->link_array = NULL; | 1173 | overlay->link_array = NULL; |
1180 | } | 1174 | } |
1181 | break; | 1175 | break; |
1182 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | ||
1183 | { | ||
1184 | struct TopologyContextUnderlay *underlay; | ||
1185 | 1176 | ||
1186 | underlay = &tc->u.underlay; | 1177 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: |
1187 | GNUNET_free_non_null (underlay->link_array); | 1178 | { |
1188 | underlay->link_array = NULL; | 1179 | struct TopologyContextUnderlay *underlay; |
1189 | } | 1180 | |
1190 | break; | 1181 | underlay = &tc->u.underlay; |
1182 | GNUNET_free_non_null(underlay->link_array); | ||
1183 | underlay->link_array = NULL; | ||
1184 | } | ||
1185 | break; | ||
1186 | } | ||
1191 | } | 1187 | } |
1192 | } | ||
1193 | } | 1188 | } |
1194 | 1189 | ||
1195 | 1190 | ||
@@ -1199,7 +1194,7 @@ _exit: | |||
1199 | * @param tc the topology context | 1194 | * @param tc the topology context |
1200 | */ | 1195 | */ |
1201 | static void | 1196 | static void |
1202 | gen_topo_clique (struct TopologyContext *tc) | 1197 | gen_topo_clique(struct TopologyContext *tc) |
1203 | { | 1198 | { |
1204 | unsigned int cnt; | 1199 | unsigned int cnt; |
1205 | unsigned int offset; | 1200 | unsigned int offset; |
@@ -1207,36 +1202,37 @@ gen_topo_clique (struct TopologyContext *tc) | |||
1207 | 1202 | ||
1208 | tc->link_array_size = tc->num_peers * (tc->num_peers - 1); | 1203 | tc->link_array_size = tc->num_peers * (tc->num_peers - 1); |
1209 | switch (tc->type) | 1204 | switch (tc->type) |
1210 | { | 1205 | { |
1211 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: | 1206 | case TOPOLOGYCONTEXT_TYPE_OVERLAY: |
1212 | { | 1207 | { |
1213 | struct TopologyContextOverlay *overlay; | 1208 | struct TopologyContextOverlay *overlay; |
1214 | 1209 | ||
1215 | overlay = &tc->u.overlay; | 1210 | overlay = &tc->u.overlay; |
1216 | overlay->link_array = GNUNET_new_array (tc->link_array_size, | 1211 | overlay->link_array = GNUNET_new_array(tc->link_array_size, |
1217 | struct OverlayLink); | 1212 | struct OverlayLink); |
1218 | } | 1213 | } |
1219 | break; | 1214 | break; |
1220 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | 1215 | |
1216 | case TOPOLOGYCONTEXT_TYPE_UNDERLAY: | ||
1221 | { | 1217 | { |
1222 | struct TopologyContextUnderlay *underlay; | 1218 | struct TopologyContextUnderlay *underlay; |
1223 | 1219 | ||
1224 | underlay = &tc->u.underlay; | 1220 | underlay = &tc->u.underlay; |
1225 | underlay->link_array = GNUNET_new_array (tc->link_array_size, | 1221 | underlay->link_array = GNUNET_new_array(tc->link_array_size, |
1226 | struct UnderlayLink); | 1222 | struct UnderlayLink); |
1223 | } | ||
1227 | } | 1224 | } |
1228 | } | ||
1229 | offset = 0; | 1225 | offset = 0; |
1230 | for (cnt = 0; cnt < tc->num_peers; cnt++) | 1226 | for (cnt = 0; cnt < tc->num_peers; cnt++) |
1231 | { | ||
1232 | for (neighbour = 0; neighbour < tc->num_peers; neighbour++) | ||
1233 | { | 1227 | { |
1234 | if (neighbour == cnt) | 1228 | for (neighbour = 0; neighbour < tc->num_peers; neighbour++) |
1235 | continue; | 1229 | { |
1236 | make_link (offset, cnt, neighbour, tc); | 1230 | if (neighbour == cnt) |
1237 | offset++; | 1231 | continue; |
1232 | make_link(offset, cnt, neighbour, tc); | ||
1233 | offset++; | ||
1234 | } | ||
1238 | } | 1235 | } |
1239 | } | ||
1240 | } | 1236 | } |
1241 | 1237 | ||
1242 | 1238 | ||
@@ -1252,15 +1248,15 @@ gen_topo_clique (struct TopologyContext *tc) | |||
1252 | * is not allowed at this time | 1248 | * is not allowed at this time |
1253 | */ | 1249 | */ |
1254 | struct GNUNET_TESTBED_Operation * | 1250 | struct GNUNET_TESTBED_Operation * |
1255 | GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls, | 1251 | GNUNET_TESTBED_underlay_configure_topology_va(void *op_cls, |
1256 | unsigned int num_peers, | 1252 | unsigned int num_peers, |
1257 | struct GNUNET_TESTBED_Peer | 1253 | struct GNUNET_TESTBED_Peer |
1258 | **peers, | 1254 | **peers, |
1259 | enum | 1255 | enum |
1260 | GNUNET_TESTBED_TopologyOption | 1256 | GNUNET_TESTBED_TopologyOption |
1261 | topo, va_list ap) | 1257 | topo, va_list ap) |
1262 | { | 1258 | { |
1263 | GNUNET_break (0); | 1259 | GNUNET_break(0); |
1264 | return NULL; | 1260 | return NULL; |
1265 | } | 1261 | } |
1266 | 1262 | ||
@@ -1277,13 +1273,13 @@ GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls, | |||
1277 | * is not allowed at this time | 1273 | * is not allowed at this time |
1278 | */ | 1274 | */ |
1279 | struct GNUNET_TESTBED_Operation * | 1275 | struct GNUNET_TESTBED_Operation * |
1280 | GNUNET_TESTBED_underlay_configure_topology (void *op_cls, | 1276 | GNUNET_TESTBED_underlay_configure_topology(void *op_cls, |
1281 | unsigned int num_peers, | 1277 | unsigned int num_peers, |
1282 | struct GNUNET_TESTBED_Peer **peers, | 1278 | struct GNUNET_TESTBED_Peer **peers, |
1283 | enum GNUNET_TESTBED_TopologyOption | 1279 | enum GNUNET_TESTBED_TopologyOption |
1284 | topo, ...) | 1280 | topo, ...) |
1285 | { | 1281 | { |
1286 | GNUNET_break (0); | 1282 | GNUNET_break(0); |
1287 | return NULL; | 1283 | return NULL; |
1288 | } | 1284 | } |
1289 | 1285 | ||
@@ -1309,15 +1305,15 @@ GNUNET_TESTBED_underlay_configure_topology (void *op_cls, | |||
1309 | * not running or underlay disallows) or if num_peers is less than 2 | 1305 | * not running or underlay disallows) or if num_peers is less than 2 |
1310 | */ | 1306 | */ |
1311 | struct GNUNET_TESTBED_Operation * | 1307 | struct GNUNET_TESTBED_Operation * |
1312 | GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, | 1308 | GNUNET_TESTBED_overlay_configure_topology_va(void *op_cls, |
1313 | unsigned int num_peers, | 1309 | unsigned int num_peers, |
1314 | struct GNUNET_TESTBED_Peer **peers, | 1310 | struct GNUNET_TESTBED_Peer **peers, |
1315 | unsigned int *max_connections, | 1311 | unsigned int *max_connections, |
1316 | GNUNET_TESTBED_TopologyCompletionCallback | 1312 | GNUNET_TESTBED_TopologyCompletionCallback |
1317 | comp_cb, | 1313 | comp_cb, |
1318 | void *comp_cb_cls, | 1314 | void *comp_cb_cls, |
1319 | enum GNUNET_TESTBED_TopologyOption topo, | 1315 | enum GNUNET_TESTBED_TopologyOption topo, |
1320 | va_list va) | 1316 | va_list va) |
1321 | { | 1317 | { |
1322 | struct TopologyContext *tc; | 1318 | struct TopologyContext *tc; |
1323 | struct TopologyContextOverlay *overlay; | 1319 | struct TopologyContextOverlay *overlay; |
@@ -1328,7 +1324,7 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, | |||
1328 | if (num_peers < 2) | 1324 | if (num_peers < 2) |
1329 | return NULL; | 1325 | return NULL; |
1330 | c = peers[0]->controller; | 1326 | c = peers[0]->controller; |
1331 | tc = GNUNET_new (struct TopologyContext); | 1327 | tc = GNUNET_new(struct TopologyContext); |
1332 | tc->type = TOPOLOGYCONTEXT_TYPE_OVERLAY; | 1328 | tc->type = TOPOLOGYCONTEXT_TYPE_OVERLAY; |
1333 | overlay = &tc->u.overlay; | 1329 | overlay = &tc->u.overlay; |
1334 | overlay->peers = peers; | 1330 | overlay->peers = peers; |
@@ -1338,88 +1334,100 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, | |||
1338 | overlay->comp_cb = comp_cb; | 1334 | overlay->comp_cb = comp_cb; |
1339 | overlay->comp_cb_cls = comp_cb_cls; | 1335 | overlay->comp_cb_cls = comp_cb_cls; |
1340 | switch (topo) | 1336 | switch (topo) |
1341 | { | 1337 | { |
1342 | case GNUNET_TESTBED_TOPOLOGY_LINE: | 1338 | case GNUNET_TESTBED_TOPOLOGY_LINE: |
1343 | gen_topo_line (tc); | 1339 | gen_topo_line(tc); |
1344 | break; | 1340 | break; |
1345 | case GNUNET_TESTBED_TOPOLOGY_STAR: | ||
1346 | gen_topo_star (tc); | ||
1347 | break; | ||
1348 | case GNUNET_TESTBED_TOPOLOGY_RING: | ||
1349 | gen_topo_ring (tc); | ||
1350 | break; | ||
1351 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: | ||
1352 | gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_NO); | ||
1353 | break; | ||
1354 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: | ||
1355 | gen_topo_ring (tc); | ||
1356 | gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_YES); | ||
1357 | break; | ||
1358 | case GNUNET_TESTBED_TOPOLOGY_CLIQUE: | ||
1359 | gen_topo_clique (tc); | ||
1360 | break; | ||
1361 | case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: | ||
1362 | gen_topo_2dtorus (tc); | ||
1363 | break; | ||
1364 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: | ||
1365 | gen_topo_2dtorus (tc); | ||
1366 | gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_YES); | ||
1367 | 1341 | ||
1368 | break; | 1342 | case GNUNET_TESTBED_TOPOLOGY_STAR: |
1369 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: | 1343 | gen_topo_star(tc); |
1344 | break; | ||
1345 | |||
1346 | case GNUNET_TESTBED_TOPOLOGY_RING: | ||
1347 | gen_topo_ring(tc); | ||
1348 | break; | ||
1349 | |||
1350 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: | ||
1351 | gen_topo_random(tc, va_arg(va, unsigned int), GNUNET_NO); | ||
1352 | break; | ||
1353 | |||
1354 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: | ||
1355 | gen_topo_ring(tc); | ||
1356 | gen_topo_random(tc, va_arg(va, unsigned int), GNUNET_YES); | ||
1357 | break; | ||
1358 | |||
1359 | case GNUNET_TESTBED_TOPOLOGY_CLIQUE: | ||
1360 | gen_topo_clique(tc); | ||
1361 | break; | ||
1362 | |||
1363 | case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: | ||
1364 | gen_topo_2dtorus(tc); | ||
1365 | break; | ||
1366 | |||
1367 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: | ||
1368 | gen_topo_2dtorus(tc); | ||
1369 | gen_topo_random(tc, va_arg(va, unsigned int), GNUNET_YES); | ||
1370 | |||
1371 | break; | ||
1372 | |||
1373 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: | ||
1370 | { | 1374 | { |
1371 | uint16_t cap; | 1375 | uint16_t cap; |
1372 | uint8_t m; | 1376 | uint8_t m; |
1373 | 1377 | ||
1374 | cap = (uint16_t) va_arg (va, unsigned int); | 1378 | cap = (uint16_t)va_arg(va, unsigned int); |
1375 | m = (uint8_t) va_arg (va, unsigned int); | 1379 | m = (uint8_t)va_arg(va, unsigned int); |
1376 | gen_topo_scale_free (tc, cap, m); | 1380 | gen_topo_scale_free(tc, cap, m); |
1377 | } | 1381 | } |
1378 | break; | 1382 | break; |
1379 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: | ||
1380 | { | ||
1381 | const char *filename; | ||
1382 | 1383 | ||
1383 | filename = va_arg (va, const char *); | 1384 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: |
1385 | { | ||
1386 | const char *filename; | ||
1387 | |||
1388 | filename = va_arg(va, const char *); | ||
1384 | 1389 | ||
1385 | GNUNET_assert (NULL != filename); | 1390 | GNUNET_assert(NULL != filename); |
1386 | gen_topo_from_file (tc, filename); | 1391 | gen_topo_from_file(tc, filename); |
1387 | } | 1392 | } |
1388 | break; | 1393 | break; |
1389 | default: | ||
1390 | GNUNET_break (0); | ||
1391 | GNUNET_free (tc); | ||
1392 | return NULL; | ||
1393 | } | ||
1394 | do | ||
1395 | { | ||
1396 | secondary_option = GNUNET_VA_ARG_ENUM (va, GNUNET_TESTBED_TopologyOption); | ||
1397 | 1394 | ||
1398 | switch (secondary_option) | ||
1399 | { | ||
1400 | case GNUNET_TESTBED_TOPOLOGY_RETRY_CNT: | ||
1401 | overlay->retry_cnt = va_arg (va, unsigned int); | ||
1402 | break; | ||
1403 | case GNUNET_TESTBED_TOPOLOGY_OPTION_END: | ||
1404 | break; | ||
1405 | default: | 1395 | default: |
1406 | GNUNET_break (0); /* Should not use any other option apart from | 1396 | GNUNET_break(0); |
1407 | * the ones handled here */ | 1397 | GNUNET_free(tc); |
1408 | GNUNET_free_non_null (overlay->link_array); | ||
1409 | GNUNET_free (tc); | ||
1410 | return NULL; | 1398 | return NULL; |
1411 | } | 1399 | } |
1412 | } | 1400 | do |
1401 | { | ||
1402 | secondary_option = GNUNET_VA_ARG_ENUM(va, GNUNET_TESTBED_TopologyOption); | ||
1403 | |||
1404 | switch (secondary_option) | ||
1405 | { | ||
1406 | case GNUNET_TESTBED_TOPOLOGY_RETRY_CNT: | ||
1407 | overlay->retry_cnt = va_arg(va, unsigned int); | ||
1408 | break; | ||
1409 | |||
1410 | case GNUNET_TESTBED_TOPOLOGY_OPTION_END: | ||
1411 | break; | ||
1412 | |||
1413 | default: | ||
1414 | GNUNET_break(0); /* Should not use any other option apart from | ||
1415 | * the ones handled here */ | ||
1416 | GNUNET_free_non_null(overlay->link_array); | ||
1417 | GNUNET_free(tc); | ||
1418 | return NULL; | ||
1419 | } | ||
1420 | } | ||
1413 | while (GNUNET_TESTBED_TOPOLOGY_OPTION_END != secondary_option); | 1421 | while (GNUNET_TESTBED_TOPOLOGY_OPTION_END != secondary_option); |
1414 | op = GNUNET_TESTBED_operation_create_ (tc, | 1422 | op = GNUNET_TESTBED_operation_create_(tc, |
1415 | &opstart_overlay_configure_topology, | 1423 | &opstart_overlay_configure_topology, |
1416 | &oprelease_overlay_configure_topology); | 1424 | &oprelease_overlay_configure_topology); |
1417 | GNUNET_TESTBED_operation_queue_insert_ | 1425 | GNUNET_TESTBED_operation_queue_insert_ |
1418 | (c->opq_parallel_topology_config_operations, op); | 1426 | (c->opq_parallel_topology_config_operations, op); |
1419 | GNUNET_TESTBED_operation_begin_wait_ (op); | 1427 | GNUNET_TESTBED_operation_begin_wait_(op); |
1420 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1428 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1421 | "Generated %u connections\n", | 1429 | "Generated %u connections\n", |
1422 | tc->link_array_size); | 1430 | tc->link_array_size); |
1423 | if (NULL != max_connections) | 1431 | if (NULL != max_connections) |
1424 | *max_connections = tc->link_array_size; | 1432 | *max_connections = tc->link_array_size; |
1425 | return op; | 1433 | return op; |
@@ -1447,27 +1455,27 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, | |||
1447 | * not running or underlay disallows) or if num_peers is less than 2 | 1455 | * not running or underlay disallows) or if num_peers is less than 2 |
1448 | */ | 1456 | */ |
1449 | struct GNUNET_TESTBED_Operation * | 1457 | struct GNUNET_TESTBED_Operation * |
1450 | GNUNET_TESTBED_overlay_configure_topology (void *op_cls, | 1458 | GNUNET_TESTBED_overlay_configure_topology(void *op_cls, |
1451 | unsigned int num_peers, | 1459 | unsigned int num_peers, |
1452 | struct GNUNET_TESTBED_Peer **peers, | 1460 | struct GNUNET_TESTBED_Peer **peers, |
1453 | unsigned int *max_connections, | 1461 | unsigned int *max_connections, |
1454 | GNUNET_TESTBED_TopologyCompletionCallback | 1462 | GNUNET_TESTBED_TopologyCompletionCallback |
1455 | comp_cb, | 1463 | comp_cb, |
1456 | void *comp_cb_cls, | 1464 | void *comp_cb_cls, |
1457 | enum GNUNET_TESTBED_TopologyOption topo, | 1465 | enum GNUNET_TESTBED_TopologyOption topo, |
1458 | ...) | 1466 | ...) |
1459 | { | 1467 | { |
1460 | struct GNUNET_TESTBED_Operation *op; | 1468 | struct GNUNET_TESTBED_Operation *op; |
1461 | va_list vargs; | 1469 | va_list vargs; |
1462 | 1470 | ||
1463 | GNUNET_assert (topo < GNUNET_TESTBED_TOPOLOGY_OPTION_END); | 1471 | GNUNET_assert(topo < GNUNET_TESTBED_TOPOLOGY_OPTION_END); |
1464 | va_start (vargs, topo); | 1472 | va_start(vargs, topo); |
1465 | op = GNUNET_TESTBED_overlay_configure_topology_va (op_cls, num_peers, peers, | 1473 | op = GNUNET_TESTBED_overlay_configure_topology_va(op_cls, num_peers, peers, |
1466 | max_connections, | 1474 | max_connections, |
1467 | comp_cb, comp_cb_cls, | 1475 | comp_cb, comp_cb_cls, |
1468 | topo, | 1476 | topo, |
1469 | vargs); | 1477 | vargs); |
1470 | va_end (vargs); | 1478 | va_end(vargs); |
1471 | return op; | 1479 | return op; |
1472 | } | 1480 | } |
1473 | 1481 | ||
@@ -1482,21 +1490,21 @@ GNUNET_TESTBED_overlay_configure_topology (void *op_cls, | |||
1482 | * known topology, #GNUNET_NO if not | 1490 | * known topology, #GNUNET_NO if not |
1483 | */ | 1491 | */ |
1484 | int | 1492 | int |
1485 | GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology, | 1493 | GNUNET_TESTBED_topology_get_(enum GNUNET_TESTBED_TopologyOption *topology, |
1486 | const char *topology_string) | 1494 | const char *topology_string) |
1487 | { | 1495 | { |
1488 | unsigned int cnt; | 1496 | unsigned int cnt; |
1489 | 1497 | ||
1490 | for (cnt = 0; NULL != topology_strings[cnt]; cnt++) | 1498 | for (cnt = 0; NULL != topology_strings[cnt]; cnt++) |
1491 | { | ||
1492 | if (0 == strcasecmp (topology_string, topology_strings[cnt])) | ||
1493 | { | 1499 | { |
1494 | if (NULL != topology) | 1500 | if (0 == strcasecmp(topology_string, topology_strings[cnt])) |
1495 | *topology = (enum GNUNET_TESTBED_TopologyOption) cnt; | 1501 | { |
1496 | GNUNET_assert (GNUNET_TESTBED_TOPOLOGY_OPTION_END != (enum GNUNET_TESTBED_TopologyOption) cnt); | 1502 | if (NULL != topology) |
1497 | return GNUNET_YES; | 1503 | *topology = (enum GNUNET_TESTBED_TopologyOption)cnt; |
1504 | GNUNET_assert(GNUNET_TESTBED_TOPOLOGY_OPTION_END != (enum GNUNET_TESTBED_TopologyOption)cnt); | ||
1505 | return GNUNET_YES; | ||
1506 | } | ||
1498 | } | 1507 | } |
1499 | } | ||
1500 | return GNUNET_NO; | 1508 | return GNUNET_NO; |
1501 | } | 1509 | } |
1502 | 1510 | ||
@@ -1509,11 +1517,11 @@ GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology, | |||
1509 | * expressed as a string | 1517 | * expressed as a string |
1510 | */ | 1518 | */ |
1511 | char * | 1519 | char * |
1512 | GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology) | 1520 | GNUNET_TESTBED_topology_to_str_(enum GNUNET_TESTBED_TopologyOption topology) |
1513 | { | 1521 | { |
1514 | if (GNUNET_TESTBED_TOPOLOGY_OPTION_END <= topology) | 1522 | if (GNUNET_TESTBED_TOPOLOGY_OPTION_END <= topology) |
1515 | return NULL; | 1523 | return NULL; |
1516 | return GNUNET_strdup (topology_strings[topology]); | 1524 | return GNUNET_strdup(topology_strings[topology]); |
1517 | } | 1525 | } |
1518 | 1526 | ||
1519 | 1527 | ||
@@ -1534,10 +1542,10 @@ GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology) | |||
1534 | * underlay link processor returned #GNUNET_SYSERR | 1542 | * underlay link processor returned #GNUNET_SYSERR |
1535 | */ | 1543 | */ |
1536 | int | 1544 | int |
1537 | GNUNET_TESTBED_underlay_construct_ (int num_peers, | 1545 | GNUNET_TESTBED_underlay_construct_(int num_peers, |
1538 | underlay_link_processor proc, | 1546 | underlay_link_processor proc, |
1539 | void *cls, | 1547 | void *cls, |
1540 | ...) | 1548 | ...) |
1541 | { | 1549 | { |
1542 | struct TopologyContext tc; | 1550 | struct TopologyContext tc; |
1543 | struct TopologyContextUnderlay *underlay; | 1551 | struct TopologyContextUnderlay *underlay; |
@@ -1547,78 +1555,88 @@ GNUNET_TESTBED_underlay_construct_ (int num_peers, | |||
1547 | unsigned int cnt; | 1555 | unsigned int cnt; |
1548 | int ret; | 1556 | int ret; |
1549 | 1557 | ||
1550 | GNUNET_assert (NULL != proc); | 1558 | GNUNET_assert(NULL != proc); |
1551 | ret = GNUNET_OK; | 1559 | ret = GNUNET_OK; |
1552 | memset (&tc, 0, sizeof (tc)); | 1560 | memset(&tc, 0, sizeof(tc)); |
1553 | tc.num_peers = num_peers; | 1561 | tc.num_peers = num_peers; |
1554 | tc.type = TOPOLOGYCONTEXT_TYPE_UNDERLAY; | 1562 | tc.type = TOPOLOGYCONTEXT_TYPE_UNDERLAY; |
1555 | underlay = &tc.u.underlay; | 1563 | underlay = &tc.u.underlay; |
1556 | va_start (vargs, cls); | 1564 | va_start(vargs, cls); |
1557 | topology = GNUNET_VA_ARG_ENUM (vargs, GNUNET_TESTBED_TopologyOption); | 1565 | topology = GNUNET_VA_ARG_ENUM(vargs, GNUNET_TESTBED_TopologyOption); |
1558 | switch (topology) | 1566 | switch (topology) |
1559 | { | 1567 | { |
1560 | case GNUNET_TESTBED_TOPOLOGY_LINE: | 1568 | case GNUNET_TESTBED_TOPOLOGY_LINE: |
1561 | gen_topo_line (&tc); | 1569 | gen_topo_line(&tc); |
1562 | break; | 1570 | break; |
1563 | case GNUNET_TESTBED_TOPOLOGY_STAR: | 1571 | |
1564 | gen_topo_star (&tc); | 1572 | case GNUNET_TESTBED_TOPOLOGY_STAR: |
1565 | break; | 1573 | gen_topo_star(&tc); |
1566 | case GNUNET_TESTBED_TOPOLOGY_RING: | 1574 | break; |
1567 | gen_topo_ring (&tc); | 1575 | |
1568 | break; | 1576 | case GNUNET_TESTBED_TOPOLOGY_RING: |
1569 | case GNUNET_TESTBED_TOPOLOGY_CLIQUE: | 1577 | gen_topo_ring(&tc); |
1570 | gen_topo_clique (&tc); | 1578 | break; |
1571 | break; | 1579 | |
1572 | case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: | 1580 | case GNUNET_TESTBED_TOPOLOGY_CLIQUE: |
1573 | gen_topo_2dtorus (&tc); | 1581 | gen_topo_clique(&tc); |
1574 | break; | 1582 | break; |
1575 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: | 1583 | |
1576 | gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_NO); | 1584 | case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: |
1577 | break; | 1585 | gen_topo_2dtorus(&tc); |
1578 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: | 1586 | break; |
1579 | gen_topo_ring (&tc); | 1587 | |
1580 | gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES); | 1588 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: |
1581 | break; | 1589 | gen_topo_random(&tc, va_arg(vargs, unsigned int), GNUNET_NO); |
1582 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: | 1590 | break; |
1583 | gen_topo_2dtorus (&tc); | 1591 | |
1584 | gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES); | 1592 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: |
1585 | break; | 1593 | gen_topo_ring(&tc); |
1586 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: | 1594 | gen_topo_random(&tc, va_arg(vargs, unsigned int), GNUNET_YES); |
1595 | break; | ||
1596 | |||
1597 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: | ||
1598 | gen_topo_2dtorus(&tc); | ||
1599 | gen_topo_random(&tc, va_arg(vargs, unsigned int), GNUNET_YES); | ||
1600 | break; | ||
1601 | |||
1602 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: | ||
1587 | { | 1603 | { |
1588 | const char *filename; | 1604 | const char *filename; |
1589 | filename = va_arg (vargs, char *); | 1605 | filename = va_arg(vargs, char *); |
1590 | GNUNET_assert (NULL != filename); | 1606 | GNUNET_assert(NULL != filename); |
1591 | gen_topo_from_file (&tc, filename); | 1607 | gen_topo_from_file(&tc, filename); |
1592 | } | 1608 | } |
1593 | break; | 1609 | break; |
1594 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: | 1610 | |
1611 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: | ||
1595 | { | 1612 | { |
1596 | uint16_t cap; | 1613 | uint16_t cap; |
1597 | uint8_t m; | 1614 | uint8_t m; |
1598 | cap = (uint16_t) va_arg (vargs, unsigned int); | 1615 | cap = (uint16_t)va_arg(vargs, unsigned int); |
1599 | m = (uint8_t) va_arg (vargs, unsigned int); | 1616 | m = (uint8_t)va_arg(vargs, unsigned int); |
1600 | gen_topo_scale_free (&tc, cap, m); | 1617 | gen_topo_scale_free(&tc, cap, m); |
1601 | } | 1618 | } |
1602 | break; | 1619 | break; |
1603 | default: | 1620 | |
1604 | GNUNET_assert (0); | 1621 | default: |
1605 | } | 1622 | GNUNET_assert(0); |
1606 | va_end (vargs); | 1623 | } |
1624 | va_end(vargs); | ||
1607 | for (cnt = 0; cnt < tc.link_array_size; cnt++) | 1625 | for (cnt = 0; cnt < tc.link_array_size; cnt++) |
1608 | { | ||
1609 | ulink = &underlay->link_array[cnt]; | ||
1610 | if (GNUNET_SYSERR == proc (cls, | ||
1611 | ulink->A, | ||
1612 | ulink->B, | ||
1613 | ulink->bandwidth, | ||
1614 | ulink->latency, | ||
1615 | ulink->loss)) | ||
1616 | { | 1626 | { |
1617 | ret = GNUNET_SYSERR; | 1627 | ulink = &underlay->link_array[cnt]; |
1618 | break; | 1628 | if (GNUNET_SYSERR == proc(cls, |
1629 | ulink->A, | ||
1630 | ulink->B, | ||
1631 | ulink->bandwidth, | ||
1632 | ulink->latency, | ||
1633 | ulink->loss)) | ||
1634 | { | ||
1635 | ret = GNUNET_SYSERR; | ||
1636 | break; | ||
1637 | } | ||
1619 | } | 1638 | } |
1620 | } | 1639 | GNUNET_free_non_null(underlay->link_array); |
1621 | GNUNET_free_non_null (underlay->link_array); | ||
1622 | return ret; | 1640 | return ret; |
1623 | } | 1641 | } |
1624 | 1642 | ||
diff --git a/src/testbed/testbed_api_topology.h b/src/testbed/testbed_api_topology.h index 7feec5f75..c2b00e094 100644 --- a/src/testbed/testbed_api_topology.h +++ b/src/testbed/testbed_api_topology.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -38,8 +38,8 @@ | |||
38 | * fresh. The caller should free it. Can be NULL. | 38 | * fresh. The caller should free it. Can be NULL. |
39 | */ | 39 | */ |
40 | unsigned int | 40 | unsigned int |
41 | GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows, | 41 | GNUNET_TESTBED_2dtorus_calc_links(unsigned int num_peers, unsigned int *rows, |
42 | unsigned int **rows_len); | 42 | unsigned int **rows_len); |
43 | 43 | ||
44 | 44 | ||
45 | /** | 45 | /** |
@@ -52,8 +52,8 @@ GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows, | |||
52 | * known topology, GNUNET_NO if not | 52 | * known topology, GNUNET_NO if not |
53 | */ | 53 | */ |
54 | int | 54 | int |
55 | GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology, | 55 | GNUNET_TESTBED_topology_get_(enum GNUNET_TESTBED_TopologyOption *topology, |
56 | const char *topology_string); | 56 | const char *topology_string); |
57 | 57 | ||
58 | 58 | ||
59 | /** | 59 | /** |
@@ -64,7 +64,7 @@ GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology, | |||
64 | * expressed as a string | 64 | * expressed as a string |
65 | */ | 65 | */ |
66 | char * | 66 | char * |
67 | GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology); | 67 | GNUNET_TESTBED_topology_to_str_(enum GNUNET_TESTBED_TopologyOption topology); |
68 | 68 | ||
69 | 69 | ||
70 | /** | 70 | /** |
@@ -104,10 +104,10 @@ typedef int (*underlay_link_processor) (void *cls, | |||
104 | * underlay link processor returned GNUNET_SYSERR | 104 | * underlay link processor returned GNUNET_SYSERR |
105 | */ | 105 | */ |
106 | int | 106 | int |
107 | GNUNET_TESTBED_underlay_construct_ (int num_peers, | 107 | GNUNET_TESTBED_underlay_construct_(int num_peers, |
108 | underlay_link_processor proc, | 108 | underlay_link_processor proc, |
109 | void *cls, | 109 | void *cls, |
110 | ...); | 110 | ...); |
111 | 111 | ||
112 | #endif | 112 | #endif |
113 | /* end of testbed_api_topology.h */ | 113 | /* end of testbed_api_topology.h */ |
diff --git a/src/testbed/testbed_api_underlay.c b/src/testbed/testbed_api_underlay.c index 5cc8d8597..b0c712ca6 100644 --- a/src/testbed/testbed_api_underlay.c +++ b/src/testbed/testbed_api_underlay.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2013 GNUnet e.V. | 3 | Copyright (C) 2008--2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | /** | 21 | /** |
22 | * @file testbed/testbed_api_underlay.c | 22 | * @file testbed/testbed_api_underlay.c |
@@ -30,8 +30,7 @@ | |||
30 | /** | 30 | /** |
31 | * An underlay link | 31 | * An underlay link |
32 | */ | 32 | */ |
33 | struct LinkProperty | 33 | struct LinkProperty { |
34 | { | ||
35 | /** | 34 | /** |
36 | * next pointer for list | 35 | * next pointer for list |
37 | */ | 36 | */ |
@@ -62,8 +61,7 @@ struct LinkProperty | |||
62 | /** | 61 | /** |
63 | * Container for holding a peer in whitelist/blacklist | 62 | * Container for holding a peer in whitelist/blacklist |
64 | */ | 63 | */ |
65 | struct ListEntry | 64 | struct ListEntry { |
66 | { | ||
67 | /** | 65 | /** |
68 | * the next pointer | 66 | * the next pointer |
69 | */ | 67 | */ |
@@ -80,8 +78,7 @@ struct ListEntry | |||
80 | * Model for configuring underlay links of a peer | 78 | * Model for configuring underlay links of a peer |
81 | * @ingroup underlay | 79 | * @ingroup underlay |
82 | */ | 80 | */ |
83 | struct GNUNET_TESTBED_UnderlayLinkModel | 81 | struct GNUNET_TESTBED_UnderlayLinkModel { |
84 | { | ||
85 | /** | 82 | /** |
86 | * The peer associated with this model | 83 | * The peer associated with this model |
87 | */ | 84 | */ |
@@ -110,15 +107,15 @@ struct GNUNET_TESTBED_UnderlayLinkModel | |||
110 | * @param model the model | 107 | * @param model the model |
111 | */ | 108 | */ |
112 | static void | 109 | static void |
113 | free_entries (struct GNUNET_TESTBED_UnderlayLinkModel *model) | 110 | free_entries(struct GNUNET_TESTBED_UnderlayLinkModel *model) |
114 | { | 111 | { |
115 | struct ListEntry *e; | 112 | struct ListEntry *e; |
116 | 113 | ||
117 | while (NULL != (e = model->entries)) | 114 | while (NULL != (e = model->entries)) |
118 | { | 115 | { |
119 | model->entries = e->next; | 116 | model->entries = e->next; |
120 | GNUNET_free (e); | 117 | GNUNET_free(e); |
121 | } | 118 | } |
122 | } | 119 | } |
123 | 120 | ||
124 | 121 | ||
@@ -128,15 +125,15 @@ free_entries (struct GNUNET_TESTBED_UnderlayLinkModel *model) | |||
128 | * @param model the model | 125 | * @param model the model |
129 | */ | 126 | */ |
130 | static void | 127 | static void |
131 | free_link_properties (struct GNUNET_TESTBED_UnderlayLinkModel *model) | 128 | free_link_properties(struct GNUNET_TESTBED_UnderlayLinkModel *model) |
132 | { | 129 | { |
133 | struct LinkProperty *p; | 130 | struct LinkProperty *p; |
134 | 131 | ||
135 | while (NULL != (p = model->props)) | 132 | while (NULL != (p = model->props)) |
136 | { | 133 | { |
137 | model->props = p->next; | 134 | model->props = p->next; |
138 | GNUNET_free (p); | 135 | GNUNET_free(p); |
139 | } | 136 | } |
140 | } | 137 | } |
141 | 138 | ||
142 | 139 | ||
@@ -150,13 +147,13 @@ free_link_properties (struct GNUNET_TESTBED_UnderlayLinkModel *model) | |||
150 | * @return the model | 147 | * @return the model |
151 | */ | 148 | */ |
152 | struct GNUNET_TESTBED_UnderlayLinkModel * | 149 | struct GNUNET_TESTBED_UnderlayLinkModel * |
153 | GNUNET_TESTBED_underlaylinkmodel_create (struct GNUNET_TESTBED_Peer *peer, | 150 | GNUNET_TESTBED_underlaylinkmodel_create(struct GNUNET_TESTBED_Peer *peer, |
154 | enum GNUNET_TESTBED_UnderlayLinkModelType type) | 151 | enum GNUNET_TESTBED_UnderlayLinkModelType type) |
155 | { | 152 | { |
156 | struct GNUNET_TESTBED_UnderlayLinkModel *m; | 153 | struct GNUNET_TESTBED_UnderlayLinkModel *m; |
157 | 154 | ||
158 | GNUNET_assert (0 == peer->underlay_model_exists); | 155 | GNUNET_assert(0 == peer->underlay_model_exists); |
159 | m = GNUNET_new (struct GNUNET_TESTBED_UnderlayLinkModel); | 156 | m = GNUNET_new(struct GNUNET_TESTBED_UnderlayLinkModel); |
160 | peer->underlay_model_exists = 1; | 157 | peer->underlay_model_exists = 1; |
161 | m->type = type; | 158 | m->type = type; |
162 | return m; | 159 | return m; |
@@ -173,12 +170,12 @@ GNUNET_TESTBED_underlaylinkmodel_create (struct GNUNET_TESTBED_Peer *peer, | |||
173 | * @param peer the peer to add | 170 | * @param peer the peer to add |
174 | */ | 171 | */ |
175 | void | 172 | void |
176 | GNUNET_TESTBED_underlaylinkmodel_add_peer (struct GNUNET_TESTBED_UnderlayLinkModel *model, | 173 | GNUNET_TESTBED_underlaylinkmodel_add_peer(struct GNUNET_TESTBED_UnderlayLinkModel *model, |
177 | struct GNUNET_TESTBED_Peer *peer) | 174 | struct GNUNET_TESTBED_Peer *peer) |
178 | { | 175 | { |
179 | struct ListEntry *entry; | 176 | struct ListEntry *entry; |
180 | 177 | ||
181 | entry = GNUNET_new (struct ListEntry); | 178 | entry = GNUNET_new(struct ListEntry); |
182 | entry->peer = peer; | 179 | entry->peer = peer; |
183 | entry->next = model->entries; | 180 | entry->next = model->entries; |
184 | model->entries = entry; | 181 | model->entries = entry; |
@@ -197,15 +194,15 @@ GNUNET_TESTBED_underlaylinkmodel_add_peer (struct GNUNET_TESTBED_UnderlayLinkMod | |||
197 | * @param bandwidth bandwidth of the link in kilobytes per second [kB/s] | 194 | * @param bandwidth bandwidth of the link in kilobytes per second [kB/s] |
198 | */ | 195 | */ |
199 | void | 196 | void |
200 | GNUNET_TESTBED_underlaylinkmodel_set_link (struct GNUNET_TESTBED_UnderlayLinkModel *model, | 197 | GNUNET_TESTBED_underlaylinkmodel_set_link(struct GNUNET_TESTBED_UnderlayLinkModel *model, |
201 | struct GNUNET_TESTBED_Peer *peer, | 198 | struct GNUNET_TESTBED_Peer *peer, |
202 | uint32_t latency, | 199 | uint32_t latency, |
203 | uint32_t loss, | 200 | uint32_t loss, |
204 | uint32_t bandwidth) | 201 | uint32_t bandwidth) |
205 | { | 202 | { |
206 | struct LinkProperty *prop; | 203 | struct LinkProperty *prop; |
207 | 204 | ||
208 | prop = GNUNET_new (struct LinkProperty); | 205 | prop = GNUNET_new(struct LinkProperty); |
209 | prop->peer = peer; | 206 | prop->peer = peer; |
210 | prop->latency = latency; | 207 | prop->latency = latency; |
211 | prop->loss = loss; | 208 | prop->loss = loss; |
@@ -224,12 +221,12 @@ GNUNET_TESTBED_underlaylinkmodel_set_link (struct GNUNET_TESTBED_UnderlayLinkMod | |||
224 | * @param model the model to unallocate | 221 | * @param model the model to unallocate |
225 | */ | 222 | */ |
226 | void | 223 | void |
227 | GNUNET_TESTBED_underlaylinkmodel_free (struct GNUNET_TESTBED_UnderlayLinkModel *model) | 224 | GNUNET_TESTBED_underlaylinkmodel_free(struct GNUNET_TESTBED_UnderlayLinkModel *model) |
228 | { | 225 | { |
229 | model->peer->underlay_model_exists = 0; | 226 | model->peer->underlay_model_exists = 0; |
230 | free_entries (model); | 227 | free_entries(model); |
231 | free_link_properties (model); | 228 | free_link_properties(model); |
232 | gnunet_free (model); | 229 | gnunet_free(model); |
233 | } | 230 | } |
234 | 231 | ||
235 | 232 | ||
@@ -240,12 +237,12 @@ GNUNET_TESTBED_underlaylinkmodel_free (struct GNUNET_TESTBED_UnderlayLinkModel * | |||
240 | * @param model the model to commit | 237 | * @param model the model to commit |
241 | */ | 238 | */ |
242 | void | 239 | void |
243 | GNUNET_TESTBED_underlaylinkmodel_commit (struct GNUNET_TESTBED_UnderlayLinkModel *model) | 240 | GNUNET_TESTBED_underlaylinkmodel_commit(struct GNUNET_TESTBED_UnderlayLinkModel *model) |
244 | { | 241 | { |
245 | /* FIXME: Marshal the model into a message */ | 242 | /* FIXME: Marshal the model into a message */ |
246 | GNUNET_break (0); | 243 | GNUNET_break(0); |
247 | /* do not reset the value of model->peer->underlay_model_exists */ | 244 | /* do not reset the value of model->peer->underlay_model_exists */ |
248 | free_entries (model); | 245 | free_entries(model); |
249 | free_link_properties (model); | 246 | free_link_properties(model); |
250 | GNUNET_free (model); | 247 | GNUNET_free(model); |
251 | } | 248 | } |
diff --git a/src/testbed/testbed_helper.h b/src/testbed/testbed_helper.h index 472d07271..304c4f6b6 100644 --- a/src/testbed/testbed_helper.h +++ b/src/testbed/testbed_helper.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | ||
@@ -32,8 +32,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
32 | /** | 32 | /** |
33 | * Initialization message for gnunet-helper-testbed to start testbed service | 33 | * Initialization message for gnunet-helper-testbed to start testbed service |
34 | */ | 34 | */ |
35 | struct GNUNET_TESTBED_HelperInit | 35 | struct GNUNET_TESTBED_HelperInit { |
36 | { | ||
37 | /** | 36 | /** |
38 | * Type is GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT | 37 | * Type is GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT |
39 | */ | 38 | */ |
@@ -68,8 +67,7 @@ struct GNUNET_TESTBED_HelperInit | |||
68 | /** | 67 | /** |
69 | * Reply message from helper process | 68 | * Reply message from helper process |
70 | */ | 69 | */ |
71 | struct GNUNET_TESTBED_HelperReply | 70 | struct GNUNET_TESTBED_HelperReply { |
72 | { | ||
73 | /** | 71 | /** |
74 | * Type is GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY | 72 | * Type is GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY |
75 | */ | 73 | */ |