aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/testbed
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/generate-underlay-topology.c376
-rw-r--r--src/testbed/gnunet-daemon-latency-logger.c228
-rw-r--r--src/testbed/gnunet-daemon-testbed-blacklist.c159
-rw-r--r--src/testbed/gnunet-daemon-testbed-underlay.c360
-rw-r--r--src/testbed/gnunet-helper-testbed.c558
-rw-r--r--src/testbed/gnunet-service-test-barriers.c77
-rw-r--r--src/testbed/gnunet-service-testbed.c982
-rw-r--r--src/testbed/gnunet-service-testbed.h191
-rw-r--r--src/testbed/gnunet-service-testbed_barriers.c701
-rw-r--r--src/testbed/gnunet-service-testbed_barriers.h28
-rw-r--r--src/testbed/gnunet-service-testbed_cache.c114
-rw-r--r--src/testbed/gnunet-service-testbed_connectionpool.c656
-rw-r--r--src/testbed/gnunet-service-testbed_connectionpool.h11
-rw-r--r--src/testbed/gnunet-service-testbed_cpustatus.c631
-rw-r--r--src/testbed/gnunet-service-testbed_links.c1101
-rw-r--r--src/testbed/gnunet-service-testbed_links.h33
-rw-r--r--src/testbed/gnunet-service-testbed_meminfo.c107
-rw-r--r--src/testbed/gnunet-service-testbed_meminfo.h2
-rw-r--r--src/testbed/gnunet-service-testbed_oc.c1627
-rw-r--r--src/testbed/gnunet-service-testbed_peers.c1591
-rw-r--r--src/testbed/gnunet-testbed-profiler.c215
-rw-r--r--src/testbed/gnunet_mpi_test.c120
-rw-r--r--src/testbed/gnunet_testbed_mpi_spawn.c295
-rw-r--r--src/testbed/test_gnunet_helper_testbed.c112
-rw-r--r--src/testbed/test_testbed_api.c354
-rw-r--r--src/testbed/test_testbed_api_2peers_1controller.c391
-rw-r--r--src/testbed/test_testbed_api_3peers_3controllers.c970
-rw-r--r--src/testbed/test_testbed_api_barriers.c167
-rw-r--r--src/testbed/test_testbed_api_barriers.h1
-rw-r--r--src/testbed/test_testbed_api_controllerlink.c786
-rw-r--r--src/testbed/test_testbed_api_hosts.c147
-rw-r--r--src/testbed/test_testbed_api_operations.c445
-rw-r--r--src/testbed/test_testbed_api_peer_reconfiguration.c114
-rw-r--r--src/testbed/test_testbed_api_peers_manage_services.c141
-rw-r--r--src/testbed/test_testbed_api_sd.c72
-rw-r--r--src/testbed/test_testbed_api_statistics.c110
-rw-r--r--src/testbed/test_testbed_api_test.c146
-rw-r--r--src/testbed/test_testbed_api_test_timeout.c51
-rw-r--r--src/testbed/test_testbed_api_testbed_run.c148
-rw-r--r--src/testbed/test_testbed_api_topology.c122
-rw-r--r--src/testbed/test_testbed_api_topology_clique.c114
-rw-r--r--src/testbed/test_testbed_underlay.c108
-rw-r--r--src/testbed/testbed.h87
-rw-r--r--src/testbed/testbed_api.c1858
-rw-r--r--src/testbed/testbed_api.h87
-rw-r--r--src/testbed/testbed_api_barriers.c205
-rw-r--r--src/testbed/testbed_api_hosts.c1053
-rw-r--r--src/testbed/testbed_api_hosts.h58
-rw-r--r--src/testbed/testbed_api_operations.c770
-rw-r--r--src/testbed/testbed_api_operations.h39
-rw-r--r--src/testbed/testbed_api_peers.c747
-rw-r--r--src/testbed/testbed_api_peers.h39
-rw-r--r--src/testbed/testbed_api_sd.c80
-rw-r--r--src/testbed/testbed_api_sd.h10
-rw-r--r--src/testbed/testbed_api_services.c129
-rw-r--r--src/testbed/testbed_api_statistics.c204
-rw-r--r--src/testbed/testbed_api_test.c49
-rw-r--r--src/testbed/testbed_api_testbed.c1143
-rw-r--r--src/testbed/testbed_api_topology.c1236
-rw-r--r--src/testbed/testbed_api_topology.h18
-rw-r--r--src/testbed/testbed_api_underlay.c81
-rw-r--r--src/testbed/testbed_helper.h6
62 files changed, 11409 insertions, 11152 deletions
diff --git a/src/testbed/generate-underlay-topology.c b/src/testbed/generate-underlay-topology.c
index a463d384a..726bed179 100644
--- a/src/testbed/generate-underlay-topology.c
+++ b/src/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 */
100static int 100static int
101link_processor(void *cls, 101link_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 */
150static int 150static int
151setup_db(const char *dbfile) 151setup_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
203err_ret: 203err_ret:
@@ -214,10 +214,10 @@ err_ret:
214 * @param cfg the configuration file handle 214 * @param cfg the configuration file handle
215 */ 215 */
216static void 216static void
217run(void *cls, 217run (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,125 +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 { 239 {
240 LOG_ERROR(_("Database filename missing\n")); 240 LOG_ERROR (_ ("Database filename missing\n"));
241 return; 241 return;
242 } 242 }
243 if (GNUNET_OK != setup_db(dbfile)) 243 if (GNUNET_OK != setup_db (dbfile))
244 return; 244 return;
245 if (NULL == (topology_string = args[argc++])) 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++]))
246 { 264 {
247 LOG_ERROR(_("Topology string missing\n")); 265 LOG_ERROR (_ ("An argument is missing for given topology `%s'\n"),
266 topology_string);
248 return; 267 return;
249 } 268 }
250 if (GNUNET_YES != GNUNET_TESTBED_topology_get_(&topology, topology_string)) 269 if (-1 == sscanf (value, "%u", &arg_uint1))
251 { 270 {
252 LOG_ERROR(_("Invalid topology: %s\n"), topology_string); 271 LOG_ERROR (_ ("Invalid argument `%s' given as topology argument\n"),
272 value);
253 return; 273 return;
254 } 274 }
255 arg_str1 = NULL; 275 break;
256 /* parse for first TOPOOPT. This can either be arg_uint1 or arg_str1 */ 276
257 switch (topology) 277 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
278 if (NULL == (arg_str1 = args[argc++]))
258 { 279 {
259 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: 280 LOG_ERROR (_ ("Filename argument missing for topology `%s'\n"),
260 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: 281 topology_string);
261 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: 282 return;
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;
288 } 283 }
284 break;
285
286 default:
287 break;
288 }
289 /* parse for second TOPOOPT. Only required for SCALE_FREE topology */ 289 /* parse for second TOPOOPT. Only required for SCALE_FREE topology */
290 switch (topology) 290 switch (topology)
291 {
292 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
293 if (NULL == (value = args[argc++]))
291 { 294 {
292 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: 295 LOG_ERROR (_ ("Second argument for topology `%s' is missing\n"),
293 if (NULL == (value = args[argc++])) 296 topology_string);
294 { 297 return;
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;
308 } 298 }
309 /* contruct topologies */ 299 if (-1 == sscanf (value, "%u", &arg_uint2))
310 switch (topology)
311 { 300 {
312 case GNUNET_TESTBED_TOPOLOGY_LINE: 301 LOG_ERROR (_ ("Invalid argument `%s'; expecting unsigned int\n"), value);
313 case GNUNET_TESTBED_TOPOLOGY_RING: 302 return;
314 case GNUNET_TESTBED_TOPOLOGY_STAR:
315 case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
316 case GNUNET_TESTBED_TOPOLOGY_2D_TORUS:
317 GNUNET_TESTBED_underlay_construct_(num_peers,
318 link_processor,
319 NULL,
320 topology);
321 break;
322
323 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
324 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
325 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
326 GNUNET_TESTBED_underlay_construct_(num_peers,
327 link_processor,
328 NULL,
329 topology,
330 arg_uint1);
331 break;
332
333 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
334 GNUNET_TESTBED_underlay_construct_(num_peers,
335 link_processor,
336 NULL,
337 topology,
338 arg_str1);
339 break;
340
341 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
342 GNUNET_TESTBED_underlay_construct_(num_peers,
343 link_processor,
344 NULL,
345 topology,
346 arg_uint1,
347 arg_uint2);
348 break;
349
350 default:
351 GNUNET_assert(0);
352 } 303 }
304 break;
305
306 default:
307 break;
308 }
309 /* contruct topologies */
310 switch (topology)
311 {
312 case GNUNET_TESTBED_TOPOLOGY_LINE:
313 case GNUNET_TESTBED_TOPOLOGY_RING:
314 case GNUNET_TESTBED_TOPOLOGY_STAR:
315 case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
316 case GNUNET_TESTBED_TOPOLOGY_2D_TORUS:
317 GNUNET_TESTBED_underlay_construct_ (num_peers,
318 link_processor,
319 NULL,
320 topology);
321 break;
322
323 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
324 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
325 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
326 GNUNET_TESTBED_underlay_construct_ (num_peers,
327 link_processor,
328 NULL,
329 topology,
330 arg_uint1);
331 break;
332
333 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
334 GNUNET_TESTBED_underlay_construct_ (num_peers,
335 link_processor,
336 NULL,
337 topology,
338 arg_str1);
339 break;
340
341 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
342 GNUNET_TESTBED_underlay_construct_ (num_peers,
343 link_processor,
344 NULL,
345 topology,
346 arg_uint1,
347 arg_uint2);
348 break;
349
350 default:
351 GNUNET_assert (0);
352 }
353} 353}
354 354
355 355
@@ -357,25 +357,25 @@ run(void *cls,
357 * Main 357 * Main
358 */ 358 */
359int 359int
360main(int argc, char *const argv[]) 360main (int argc, char *const argv[])
361{ 361{
362 struct GNUNET_GETOPT_CommandLineOption option[] = { 362 struct GNUNET_GETOPT_CommandLineOption option[] = {
363 GNUNET_GETOPT_option_uint('p', 363 GNUNET_GETOPT_option_uint ('p',
364 "num-peers", 364 "num-peers",
365 "COUNT", 365 "COUNT",
366 gettext_noop("create COUNT number of peers"), 366 gettext_noop ("create COUNT number of peers"),
367 &num_peers), 367 &num_peers),
368 GNUNET_GETOPT_OPTION_END 368 GNUNET_GETOPT_OPTION_END
369 }; 369 };
370 370
371 int ret; 371 int ret;
372 372
373 exit_result = GNUNET_SYSERR; 373 exit_result = GNUNET_SYSERR;
374 ret = GNUNET_PROGRAM_run( 374 ret = GNUNET_PROGRAM_run (
375 argc, 375 argc,
376 argv, 376 argv,
377 "gnunet-underlay-topology", 377 "gnunet-underlay-topology",
378 _( 378 _ (
379 "Generates SQLite3 database representing a given underlay topology.\n" 379 "Generates SQLite3 database representing a given underlay topology.\n"
380 "Usage: gnunet-underlay-topology [OPTIONS] db-filename TOPO [TOPOOPTS]\n" 380 "Usage: gnunet-underlay-topology [OPTIONS] db-filename TOPO [TOPOOPTS]\n"
381 "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"
@@ -398,9 +398,9 @@ main(int argc, char *const argv[])
398 &run, 398 &run,
399 NULL); 399 NULL);
400 if (NULL != stmt_insert) 400 if (NULL != stmt_insert)
401 sqlite3_finalize(stmt_insert); 401 sqlite3_finalize (stmt_insert);
402 if (NULL != db) 402 if (NULL != db)
403 GNUNET_break(SQLITE_OK == sqlite3_close(db)); 403 GNUNET_break (SQLITE_OK == sqlite3_close (db));
404 if ((GNUNET_OK != ret) || (GNUNET_OK != exit_result)) 404 if ((GNUNET_OK != ret) || (GNUNET_OK != exit_result))
405 return 1; 405 return 1;
406 return 0; 406 return 0;
diff --git a/src/testbed/gnunet-daemon-latency-logger.c b/src/testbed/gnunet-daemon-latency-logger.c
index 5e0fffe2b..c35282048 100644
--- a/src/testbed/gnunet-daemon-latency-logger.c
+++ b/src/testbed/gnunet-daemon-latency-logger.c
@@ -34,13 +34,13 @@
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,18 +49,20 @@
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", _ ( \
53 cmd, __FILE__, __LINE__, sqlite3_errmsg(db)); \ 53 "`%s' failed at %s:%d with error: %s\n"), \
54 if (msg != NULL) \ 54 cmd, __FILE__, __LINE__, sqlite3_errmsg (db)); \
55 GNUNET_asprintf (msg, _("`%s' failed at %s:%u with error: %s"), cmd, \ 55 if (msg != NULL) \
56 __FILE__, __LINE__, sqlite3_errmsg(db)); \ 56 GNUNET_asprintf (msg, _ ("`%s' failed at %s:%u with error: %s"), cmd, \
57 } while (0) 57 __FILE__, __LINE__, sqlite3_errmsg (db)); \
58 } while (0)
58 59
59 60
60/** 61/**
61 * Entry type to be used in the map to store old latency values 62 * Entry type to be used in the map to store old latency values
62 */ 63 */
63struct Entry { 64struct Entry
65{
64 /** 66 /**
65 * The peer's identity 67 * The peer's identity
66 */ 68 */
@@ -107,15 +109,15 @@ static struct sqlite3_stmt *stmt_insert;
107 * #GNUNET_NO if not. 109 * #GNUNET_NO if not.
108 */ 110 */
109static int 111static int
110free_iterator(void *cls, 112free_iterator (void *cls,
111 const struct GNUNET_PeerIdentity *key, 113 const struct GNUNET_PeerIdentity *key,
112 void *value) 114 void *value)
113{ 115{
114 struct Entry *e = cls; 116 struct Entry *e = cls;
115 117
116 GNUNET_assert(GNUNET_YES == 118 GNUNET_assert (GNUNET_YES ==
117 GNUNET_CONTAINER_multipeermap_remove(map, key, e)); 119 GNUNET_CONTAINER_multipeermap_remove (map, key, e));
118 GNUNET_free(e); 120 GNUNET_free (e);
119 return GNUNET_YES; 121 return GNUNET_YES;
120} 122}
121 123
@@ -127,24 +129,25 @@ free_iterator(void *cls,
127 * @return 129 * @return
128 */ 130 */
129static void 131static void
130do_shutdown(void *cls) 132do_shutdown (void *cls)
131{ 133{
132 GNUNET_ATS_performance_done(ats); 134 GNUNET_ATS_performance_done (ats);
133 ats = NULL; 135 ats = NULL;
134 if (NULL != stmt_insert) 136 if (NULL != stmt_insert)
135 { 137 {
136 sqlite3_finalize(stmt_insert); 138 sqlite3_finalize (stmt_insert);
137 stmt_insert = NULL; 139 stmt_insert = NULL;
138 } 140 }
139 GNUNET_break(SQLITE_OK == sqlite3_close(db)); 141 GNUNET_break (SQLITE_OK == sqlite3_close (db));
140 db = NULL; 142 db = NULL;
141 if (NULL != map) 143 if (NULL != map)
142 { 144 {
143 GNUNET_assert(GNUNET_SYSERR != 145 GNUNET_assert (GNUNET_SYSERR !=
144 GNUNET_CONTAINER_multipeermap_iterate(map, free_iterator, NULL)); 146 GNUNET_CONTAINER_multipeermap_iterate (map, free_iterator,
145 GNUNET_CONTAINER_multipeermap_destroy(map); 147 NULL));
146 map = NULL; 148 GNUNET_CONTAINER_multipeermap_destroy (map);
147 } 149 map = NULL;
150 }
148} 151}
149 152
150/** 153/**
@@ -161,12 +164,12 @@ do_shutdown(void *cls)
161 * @param prop performance data for the address (as far as known) 164 * @param prop performance data for the address (as far as known)
162 */ 165 */
163static void 166static void
164addr_info_cb(void *cls, 167addr_info_cb (void *cls,
165 const struct GNUNET_HELLO_Address *address, 168 const struct GNUNET_HELLO_Address *address,
166 int address_active, 169 int address_active,
167 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 170 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
168 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 171 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
169 const struct GNUNET_ATS_Properties *prop) 172 const struct GNUNET_ATS_Properties *prop)
170{ 173{
171 static const char *query_insert = 174 static const char *query_insert =
172 "INSERT INTO ats_info(" 175 "INSERT INTO ats_info("
@@ -182,64 +185,64 @@ addr_info_cb(void *cls,
182 int latency; /* FIXME: type!? */ 185 int latency; /* FIXME: type!? */
183 186
184 if (NULL == address) 187 if (NULL == address)
185 { 188 {
186 /* ATS service temporarily disconnected */ 189 /* ATS service temporarily disconnected */
187 return; 190 return;
188 } 191 }
189 192
190 GNUNET_assert(NULL != db); 193 GNUNET_assert (NULL != db);
191 if (GNUNET_YES != address_active) 194 if (GNUNET_YES != address_active)
192 return; 195 return;
193 latency = (int)prop->delay.rel_value_us; 196 latency = (int) prop->delay.rel_value_us;
194 entry = NULL; 197 entry = NULL;
195 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(map, 198 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (map,
196 &address->peer)) 199 &address->peer))
197 { 200 {
198 entry = GNUNET_CONTAINER_multipeermap_get(map, &address->peer); 201 entry = GNUNET_CONTAINER_multipeermap_get (map, &address->peer);
199 GNUNET_assert(NULL != entry); 202 GNUNET_assert (NULL != entry);
200 if (latency == entry->latency) 203 if (latency == entry->latency)
201 return; 204 return;
202 } 205 }
203 if (NULL == stmt_insert) 206 if (NULL == stmt_insert)
207 {
208 if (SQLITE_OK != sqlite3_prepare_v2 (db, query_insert, -1, &stmt_insert,
209 NULL))
204 { 210 {
205 if (SQLITE_OK != sqlite3_prepare_v2(db, query_insert, -1, &stmt_insert, 211 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2");
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");
228 goto err_shutdown; 212 goto err_shutdown;
229 } 213 }
214 }
215 if ((SQLITE_OK != sqlite3_bind_text (stmt_insert, 1,
216 GNUNET_i2s (&address->peer), -1,
217 SQLITE_STATIC)) ||
218 (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, latency)))
219 {
220 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_text");
221 goto err_shutdown;
222 }
223 if (SQLITE_DONE != sqlite3_step (stmt_insert))
224 {
225 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step");
226 goto err_shutdown;
227 }
228 if (SQLITE_OK != sqlite3_reset (stmt_insert))
229 {
230 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_insert");
231 goto err_shutdown;
232 }
230 if (NULL == entry) 233 if (NULL == entry)
231 { 234 {
232 entry = GNUNET_new(struct Entry); 235 entry = GNUNET_new (struct Entry);
233 entry->id = address->peer; 236 entry->id = address->peer;
234 GNUNET_CONTAINER_multipeermap_put(map, 237 GNUNET_CONTAINER_multipeermap_put (map,
235 &entry->id, entry, 238 &entry->id, entry,
236 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 239 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
237 } 240 }
238 entry->latency = latency; 241 entry->latency = latency;
239 return; 242 return;
240 243
241err_shutdown: 244err_shutdown:
242 GNUNET_SCHEDULER_shutdown(); 245 GNUNET_SCHEDULER_shutdown ();
243} 246}
244 247
245 248
@@ -252,8 +255,8 @@ err_shutdown:
252 * @param c configuration 255 * @param c configuration
253 */ 256 */
254static void 257static void
255run(void *cls, char *const *args, const char *cfgfile, 258run (void *cls, char *const *args, const char *cfgfile,
256 const struct GNUNET_CONFIGURATION_Handle *c) 259 const struct GNUNET_CONFIGURATION_Handle *c)
257{ 260{
258 const char *query_create = 261 const char *query_create =
259 "CREATE TABLE ats_info (" 262 "CREATE TABLE ats_info ("
@@ -263,34 +266,34 @@ run(void *cls, char *const *args, const char *cfgfile,
263 ");"; 266 ");";
264 char *dbfile; 267 char *dbfile;
265 268
266 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(c, "LATENCY-LOGGER", 269 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "LATENCY-LOGGER",
267 "DBFILE", 270 "DBFILE",
268 &dbfile)) 271 &dbfile))
269 { 272 {
270 GNUNET_break(0); 273 GNUNET_break (0);
271 return; 274 return;
272 } 275 }
273 if (SQLITE_OK != sqlite3_open(dbfile, &db)) 276 if (SQLITE_OK != sqlite3_open (dbfile, &db))
277 {
278 if (NULL != db)
274 { 279 {
275 if (NULL != db) 280 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_open_v2");
276 { 281 GNUNET_break (SQLITE_OK == sqlite3_close (db));
277 LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_open_v2");
278 GNUNET_break(SQLITE_OK == sqlite3_close(db));
279 }
280 else
281 LOG(GNUNET_ERROR_TYPE_ERROR, "Cannot open sqlite file %s\n", dbfile);
282 GNUNET_free(dbfile);
283 return;
284 } 282 }
285 if (0 != sqlite3_exec(db, query_create, NULL, NULL, NULL)) 283 else
286 DEBUG("SQLite Error: %d. Perhaps the database `%s' already exits.\n", 284 LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot open sqlite file %s\n", dbfile);
287 sqlite3_errcode(db), dbfile); 285 GNUNET_free (dbfile);
288 DEBUG("Opened database %s\n", dbfile); 286 return;
289 GNUNET_free(dbfile); 287 }
288 if (0 != sqlite3_exec (db, query_create, NULL, NULL, NULL))
289 DEBUG ("SQLite Error: %d. Perhaps the database `%s' already exits.\n",
290 sqlite3_errcode (db), dbfile);
291 DEBUG ("Opened database %s\n", dbfile);
292 GNUNET_free (dbfile);
290 dbfile = NULL; 293 dbfile = NULL;
291 ats = GNUNET_ATS_performance_init(c, &addr_info_cb, NULL); 294 ats = GNUNET_ATS_performance_init (c, &addr_info_cb, NULL);
292 map = GNUNET_CONTAINER_multipeermap_create(30, GNUNET_YES); 295 map = GNUNET_CONTAINER_multipeermap_create (30, GNUNET_YES);
293 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); 296 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
294} 297}
295 298
296 299
@@ -298,20 +301,21 @@ run(void *cls, char *const *args, const char *cfgfile,
298 * Execution entry point 301 * Execution entry point
299 */ 302 */
300int 303int
301main(int argc, char * const *argv) 304main (int argc, char *const *argv)
302{ 305{
303 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 306 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
304 GNUNET_GETOPT_OPTION_END 307 GNUNET_GETOPT_OPTION_END
305 }; 308 };
306 int ret; 309 int ret;
307 310
308 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 311 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
309 return 2; 312 return 2;
310 ret = 313 ret =
311 (GNUNET_OK == 314 (GNUNET_OK ==
312 GNUNET_PROGRAM_run(argc, argv, "gnunet-daemon-latency-logger", 315 GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-latency-logger",
313 _("Daemon to log latency values of connections to neighbours"), 316 _ (
314 options, &run, NULL)) ? 0 : 1; 317 "Daemon to log latency values of connections to neighbours"),
315 GNUNET_free((void*)argv); 318 options, &run, NULL)) ? 0 : 1;
319 GNUNET_free ((void*) argv);
316 return ret; 320 return ret;
317} 321}
diff --git a/src/testbed/gnunet-daemon-testbed-blacklist.c b/src/testbed/gnunet-daemon-testbed-blacklist.c
index e894fb79d..4872ea870 100644
--- a/src/testbed/gnunet-daemon-testbed-blacklist.c
+++ b/src/testbed/gnunet-daemon-testbed-blacklist.c
@@ -35,13 +35,13 @@
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 */
81static void 81static void
82cleanup_map() 82cleanup_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 */
97static void 97static void
98do_shutdown(void *cls) 98do_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 */
113static int 113static int
114check_access(void *cls, const struct GNUNET_PeerIdentity * pid) 114check_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 */
135static void 135static void
136setup_ac(const char *fname, 136setup_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))
159 { 164 {
160 if (GNUNET_SYSERR == 165 cleanup_map ();
161 GNUNET_CONTAINER_multipeermap_put(map, &ilist[cnt], 166 GNUNET_free (ilist);
162 &ilist[cnt], 167 return;
163 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
164 {
165 cleanup_map();
166 GNUNET_free(ilist);
167 return;
168 }
169 } 168 }
170 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); 169 }
171 bh = GNUNET_TRANSPORT_blacklist(cfg, &check_access, NULL); 170 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 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 */
183static void 183static void
184run(void *cls, 184run (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 */
233int 233int
234main(int argc, char *const *argv) 234main (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,16 @@ 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 _ (
250 options, &run, NULL)) ? 0 : 1; 250 "Daemon to restrict incoming transport layer connections during testbed deployments"),
251 GNUNET_free((void*)argv); 251 options, &run, NULL)) ? 0 : 1;
252 GNUNET_free ((void*) argv);
252 return ret; 253 return ret;
253} 254}
diff --git a/src/testbed/gnunet-daemon-testbed-underlay.c b/src/testbed/gnunet-daemon-testbed-underlay.c
index 0c6a3c3df..2cc25b0ed 100644
--- a/src/testbed/gnunet-daemon-testbed-underlay.c
+++ b/src/testbed/gnunet-daemon-testbed-underlay.c
@@ -38,13 +38,13 @@
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,13 @@
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", _ ( \
57 cmd, __FILE__, __LINE__, sqlite3_errmsg(db)); \ 57 "`%s' failed at %s:%d with error: %s\n"), \
58 if (msg != NULL) \ 58 cmd, __FILE__, __LINE__, sqlite3_errmsg (db)); \
59 GNUNET_asprintf (msg, _("`%s' failed at %s:%u with error: %s"), cmd, \ 59 if (msg != NULL) \
60 __FILE__, __LINE__, sqlite3_errmsg(db)); \ 60 GNUNET_asprintf (msg, _ ("`%s' failed at %s:%u with error: %s"), cmd, \
61 } while (0) 61 __FILE__, __LINE__, sqlite3_errmsg (db)); \
62 } while (0)
62 63
63 64
64/** 65/**
@@ -115,10 +116,10 @@ static unsigned int num_hostkeys;
115 * #GNUNET_NO if not. 116 * #GNUNET_NO if not.
116 */ 117 */
117static int 118static int
118iterator(void *cls, const struct GNUNET_PeerIdentity *key, void *value) 119iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
119{ 120{
120 GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove(map, key, 121 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (map, key,
121 value)); 122 value));
122 return GNUNET_YES; 123 return GNUNET_YES;
123} 124}
124 125
@@ -127,16 +128,17 @@ iterator(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
127 * Cleaup and destroy the map 128 * Cleaup and destroy the map
128 */ 129 */
129static void 130static void
130cleanup_map() 131cleanup_map ()
131{ 132{
132 if (NULL != map) 133 if (NULL != map)
133 { 134 {
134 GNUNET_assert(GNUNET_SYSERR != GNUNET_CONTAINER_multipeermap_iterate(map, 135 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONTAINER_multipeermap_iterate (map,
135 &iterator, 136 &
137 iterator,
136 NULL)); 138 NULL));
137 GNUNET_CONTAINER_multipeermap_destroy(map); 139 GNUNET_CONTAINER_multipeermap_destroy (map);
138 map = NULL; 140 map = NULL;
139 } 141 }
140} 142}
141 143
142 144
@@ -148,35 +150,35 @@ cleanup_map()
148 * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not 150 * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not
149 */ 151 */
150static int 152static int
151check_access(void *cls, const struct GNUNET_PeerIdentity * pid) 153check_access (void *cls, const struct GNUNET_PeerIdentity *pid)
152{ 154{
153 int contains; 155 int contains;
154 156
155 GNUNET_assert(NULL != map); 157 GNUNET_assert (NULL != map);
156 contains = GNUNET_CONTAINER_multipeermap_contains(map, pid); 158 contains = GNUNET_CONTAINER_multipeermap_contains (map, pid);
157 if (GNUNET_YES == contains) 159 if (GNUNET_YES == contains)
158 { 160 {
159 DEBUG("Permitting `%s'\n", GNUNET_i2s(pid)); 161 DEBUG ("Permitting `%s'\n", GNUNET_i2s (pid));
160 return GNUNET_OK; 162 return GNUNET_OK;
161 } 163 }
162 DEBUG("Not permitting `%s'\n", GNUNET_i2s(pid)); 164 DEBUG ("Not permitting `%s'\n", GNUNET_i2s (pid));
163 return GNUNET_SYSERR; 165 return GNUNET_SYSERR;
164} 166}
165 167
166 168
167static int 169static int
168get_identity(unsigned int offset, 170get_identity (unsigned int offset,
169 struct GNUNET_PeerIdentity *id) 171 struct GNUNET_PeerIdentity *id)
170{ 172{
171 struct GNUNET_CRYPTO_EddsaPrivateKey private_key; 173 struct GNUNET_CRYPTO_EddsaPrivateKey private_key;
172 174
173 if (offset >= num_hostkeys) 175 if (offset >= num_hostkeys)
174 return GNUNET_SYSERR; 176 return GNUNET_SYSERR;
175 GNUNET_memcpy(&private_key, 177 GNUNET_memcpy (&private_key,
176 hostkeys_data + (offset * GNUNET_TESTING_HOSTKEYFILESIZE), 178 hostkeys_data + (offset * GNUNET_TESTING_HOSTKEYFILESIZE),
177 GNUNET_TESTING_HOSTKEYFILESIZE); 179 GNUNET_TESTING_HOSTKEYFILESIZE);
178 GNUNET_CRYPTO_eddsa_key_get_public(&private_key, 180 GNUNET_CRYPTO_eddsa_key_get_public (&private_key,
179 &id->public_key); 181 &id->public_key);
180 return GNUNET_OK; 182 return GNUNET_OK;
181} 183}
182 184
@@ -184,7 +186,8 @@ get_identity(unsigned int offset,
184/** 186/**
185 * Whilelist entry 187 * Whilelist entry
186 */ 188 */
187struct WhiteListRow { 189struct WhiteListRow
190{
188 /** 191 /**
189 * Next ptr 192 * Next ptr
190 */ 193 */
@@ -206,7 +209,7 @@ struct WhiteListRow {
206 * Function to load keys 209 * Function to load keys
207 */ 210 */
208static int 211static int
209load_keys(const struct GNUNET_CONFIGURATION_Handle *c) 212load_keys (const struct GNUNET_CONFIGURATION_Handle *c)
210{ 213{
211 char *data_dir; 214 char *data_dir;
212 char *idfile; 215 char *idfile;
@@ -215,42 +218,42 @@ load_keys(const struct GNUNET_CONFIGURATION_Handle *c)
215 data_dir = NULL; 218 data_dir = NULL;
216 idfile = NULL; 219 idfile = NULL;
217 fsize = 0; 220 fsize = 0;
218 data_dir = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_DATADIR); 221 data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
219 GNUNET_asprintf(&idfile, "%s/testing_hostkeys.ecc", data_dir); 222 GNUNET_asprintf (&idfile, "%s/testing_hostkeys.ecc", data_dir);
220 GNUNET_free(data_dir); 223 GNUNET_free (data_dir);
221 data_dir = NULL; 224 data_dir = NULL;
222 if (GNUNET_OK != 225 if (GNUNET_OK !=
223 GNUNET_DISK_file_size(idfile, &fsize, GNUNET_YES, GNUNET_YES)) 226 GNUNET_DISK_file_size (idfile, &fsize, GNUNET_YES, GNUNET_YES))
224 { 227 {
225 GNUNET_free(idfile); 228 GNUNET_free (idfile);
226 return GNUNET_SYSERR; 229 return GNUNET_SYSERR;
227 } 230 }
228 if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE)) 231 if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE))
229 { 232 {
230 LOG(GNUNET_ERROR_TYPE_ERROR, 233 LOG (GNUNET_ERROR_TYPE_ERROR,
231 _("Incorrect hostkey file format: %s\n"), idfile); 234 _ ("Incorrect hostkey file format: %s\n"), idfile);
232 GNUNET_free(idfile); 235 GNUNET_free (idfile);
233 return GNUNET_SYSERR; 236 return GNUNET_SYSERR;
234 } 237 }
235 hostkeys_fd = GNUNET_DISK_file_open(idfile, GNUNET_DISK_OPEN_READ, 238 hostkeys_fd = GNUNET_DISK_file_open (idfile, GNUNET_DISK_OPEN_READ,
236 GNUNET_DISK_PERM_NONE); 239 GNUNET_DISK_PERM_NONE);
237 if (NULL == hostkeys_fd) 240 if (NULL == hostkeys_fd)
238 { 241 {
239 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", idfile); 242 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", idfile);
240 GNUNET_free(idfile); 243 GNUNET_free (idfile);
241 return GNUNET_SYSERR; 244 return GNUNET_SYSERR;
242 } 245 }
243 GNUNET_free(idfile); 246 GNUNET_free (idfile);
244 idfile = NULL; 247 idfile = NULL;
245 hostkeys_data = GNUNET_DISK_file_map(hostkeys_fd, 248 hostkeys_data = GNUNET_DISK_file_map (hostkeys_fd,
246 &hostkeys_map, 249 &hostkeys_map,
247 GNUNET_DISK_MAP_TYPE_READ, 250 GNUNET_DISK_MAP_TYPE_READ,
248 fsize); 251 fsize);
249 if (NULL == hostkeys_data) 252 if (NULL == hostkeys_data)
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 }
254 num_hostkeys = fsize / GNUNET_TESTING_HOSTKEYFILESIZE; 257 num_hostkeys = fsize / GNUNET_TESTING_HOSTKEYFILESIZE;
255 return GNUNET_OK; 258 return GNUNET_OK;
256} 259}
@@ -260,20 +263,20 @@ load_keys(const struct GNUNET_CONFIGURATION_Handle *c)
260 * Function to unload keys 263 * Function to unload keys
261 */ 264 */
262static void 265static void
263unload_keys() 266unload_keys ()
264{ 267{
265 if (NULL != hostkeys_map) 268 if (NULL != hostkeys_map)
266 { 269 {
267 GNUNET_assert(NULL != hostkeys_data); 270 GNUNET_assert (NULL != hostkeys_data);
268 GNUNET_DISK_file_unmap(hostkeys_map); 271 GNUNET_DISK_file_unmap (hostkeys_map);
269 hostkeys_map = NULL; 272 hostkeys_map = NULL;
270 hostkeys_data = NULL; 273 hostkeys_data = NULL;
271 } 274 }
272 if (NULL != hostkeys_fd) 275 if (NULL != hostkeys_fd)
273 { 276 {
274 GNUNET_DISK_file_close(hostkeys_fd); 277 GNUNET_DISK_file_close (hostkeys_fd);
275 hostkeys_fd = NULL; 278 hostkeys_fd = NULL;
276 } 279 }
277} 280}
278 281
279 282
@@ -283,17 +286,17 @@ unload_keys()
283 * @param cls NULL 286 * @param cls NULL
284 */ 287 */
285static void 288static void
286do_shutdown(void *cls) 289do_shutdown (void *cls)
287{ 290{
288 if (NULL != transport) 291 if (NULL != transport)
289 { 292 {
290 GNUNET_TRANSPORT_manipulation_disconnect(transport); 293 GNUNET_TRANSPORT_manipulation_disconnect (transport);
291 transport = NULL; 294 transport = NULL;
292 } 295 }
293 cleanup_map(); 296 cleanup_map ();
294 unload_keys(); 297 unload_keys ();
295 if (NULL != bh) 298 if (NULL != bh)
296 GNUNET_TRANSPORT_blacklist_cancel(bh); 299 GNUNET_TRANSPORT_blacklist_cancel (bh);
297} 300}
298 301
299 302
@@ -306,40 +309,42 @@ do_shutdown(void *cls)
306 * @return GNUNET_SYSERR upon error OR the number of rows retrieved 309 * @return GNUNET_SYSERR upon error OR the number of rows retrieved
307 */ 310 */
308static int 311static int
309db_read_whitelist(struct sqlite3 *db, int pid, struct WhiteListRow **wl_rows) 312db_read_whitelist (struct sqlite3 *db, int pid, struct WhiteListRow **wl_rows)
310{ 313{
311 static const char *query_wl = "SELECT oid, latency FROM whitelist WHERE (id == ?);"; 314 static const char *query_wl =
315 "SELECT oid, latency FROM whitelist WHERE (id == ?);";
312 struct sqlite3_stmt *stmt_wl; 316 struct sqlite3_stmt *stmt_wl;
313 struct WhiteListRow *lr; 317 struct WhiteListRow *lr;
314 int nrows; 318 int nrows;
315 int ret; 319 int ret;
316 320
317 if (SQLITE_OK != (ret = sqlite3_prepare_v2(db, query_wl, -1, &stmt_wl, NULL))) 321 if (SQLITE_OK != (ret = sqlite3_prepare_v2 (db, query_wl, -1, &stmt_wl,
318 { 322 NULL)))
319 LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2"); 323 {
320 return GNUNET_SYSERR; 324 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2");
321 } 325 return GNUNET_SYSERR;
322 if (SQLITE_OK != (ret = sqlite3_bind_int(stmt_wl, 1, pid))) 326 }
323 { 327 if (SQLITE_OK != (ret = sqlite3_bind_int (stmt_wl, 1, pid)))
324 LOG_SQLITE(db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int"); 328 {
325 sqlite3_finalize(stmt_wl); 329 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int");
326 return GNUNET_SYSERR; 330 sqlite3_finalize (stmt_wl);
327 } 331 return GNUNET_SYSERR;
332 }
328 nrows = 0; 333 nrows = 0;
329 do 334 do
330 { 335 {
331 ret = sqlite3_step(stmt_wl); 336 ret = sqlite3_step (stmt_wl);
332 if (SQLITE_ROW != ret) 337 if (SQLITE_ROW != ret)
333 break; 338 break;
334 nrows++; 339 nrows++;
335 lr = GNUNET_new(struct WhiteListRow); 340 lr = GNUNET_new (struct WhiteListRow);
336 lr->id = sqlite3_column_int(stmt_wl, 0); 341 lr->id = sqlite3_column_int (stmt_wl, 0);
337 lr->latency = sqlite3_column_int(stmt_wl, 1); 342 lr->latency = sqlite3_column_int (stmt_wl, 1);
338 lr->next = *wl_rows; 343 lr->next = *wl_rows;
339 *wl_rows = lr; 344 *wl_rows = lr;
340 } 345 }
341 while (1); 346 while (1);
342 sqlite3_finalize(stmt_wl); 347 sqlite3_finalize (stmt_wl);
343 return nrows; 348 return nrows;
344} 349}
345 350
@@ -353,8 +358,8 @@ db_read_whitelist(struct sqlite3 *db, int pid, struct WhiteListRow **wl_rows)
353 * @param c configuration 358 * @param c configuration
354 */ 359 */
355static void 360static void
356run(void *cls, char *const *args, const char *cfgfile, 361run (void *cls, char *const *args, const char *cfgfile,
357 const struct GNUNET_CONFIGURATION_Handle *c) 362 const struct GNUNET_CONFIGURATION_Handle *c)
358{ 363{
359 char *dbfile; 364 char *dbfile;
360 struct WhiteListRow *wl_head; 365 struct WhiteListRow *wl_head;
@@ -367,78 +372,80 @@ run(void *cls, char *const *args, const char *cfgfile,
367 int ret; 372 int ret;
368 373
369 if (GNUNET_OK != 374 if (GNUNET_OK !=
370 GNUNET_CONFIGURATION_get_value_number(c, "TESTBED", 375 GNUNET_CONFIGURATION_get_value_number (c, "TESTBED",
371 "PEERID", &pid)) 376 "PEERID", &pid))
377 {
378 GNUNET_break (0);
379 return;
380 }
381 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c,
382 "TESTBED-UNDERLAY",
383 "DBFILE",
384 &dbfile))
385 {
386 GNUNET_break (0);
387 return;
388 }
389 if (SQLITE_OK != (ret = sqlite3_open_v2 (dbfile, &db, SQLITE_OPEN_READONLY,
390 NULL)))
391 {
392 if (NULL != db)
372 { 393 {
373 GNUNET_break(0); 394 LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_open_v2");
374 return; 395 GNUNET_break (SQLITE_OK == sqlite3_close (db));
375 } 396 }
376 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(c, "TESTBED-UNDERLAY", 397 else
377 "DBFILE", 398 LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot open sqlite file %s\n", dbfile);
378 &dbfile)) 399 GNUNET_free (dbfile);
379 { 400 return;
380 GNUNET_break(0); 401 }
381 return; 402 DEBUG ("Opened database %s\n", dbfile);
382 } 403 GNUNET_free (dbfile);
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);
397 dbfile = NULL; 404 dbfile = NULL;
398 wl_head = NULL; 405 wl_head = NULL;
399 if (GNUNET_OK != load_keys(c)) 406 if (GNUNET_OK != load_keys (c))
400 goto close_db; 407 goto close_db;
401 408
402 transport = GNUNET_TRANSPORT_manipulation_connect(c); 409 transport = GNUNET_TRANSPORT_manipulation_connect (c);
403 if (NULL == transport) 410 if (NULL == transport)
404 { 411 {
405 GNUNET_break(0); 412 GNUNET_break (0);
406 return; 413 return;
407 } 414 }
408 /* read and process whitelist */ 415 /* read and process whitelist */
409 nrows = 0; 416 nrows = 0;
410 wl_head = NULL; 417 wl_head = NULL;
411 nrows = db_read_whitelist(db, pid, &wl_head); 418 nrows = db_read_whitelist (db, pid, &wl_head);
412 if ((GNUNET_SYSERR == nrows) || (0 == nrows)) 419 if ((GNUNET_SYSERR == nrows) || (0 == nrows))
413 { 420 {
414 GNUNET_TRANSPORT_manipulation_disconnect(transport); 421 GNUNET_TRANSPORT_manipulation_disconnect (transport);
415 goto close_db; 422 goto close_db;
416 } 423 }
417 map = GNUNET_CONTAINER_multipeermap_create(nrows, GNUNET_NO); 424 map = GNUNET_CONTAINER_multipeermap_create (nrows, GNUNET_NO);
418 while (NULL != (wl_entry = wl_head)) 425 while (NULL != (wl_entry = wl_head))
419 { 426 {
420 wl_head = wl_entry->next; 427 wl_head = wl_entry->next;
421 delay.rel_value_us = wl_entry->latency; 428 delay.rel_value_us = wl_entry->latency;
422 memset(&prop, 0, sizeof(prop)); 429 memset (&prop, 0, sizeof(prop));
423 GNUNET_assert(GNUNET_OK == get_identity(wl_entry->id, &identity)); 430 GNUNET_assert (GNUNET_OK == get_identity (wl_entry->id, &identity));
424 GNUNET_break(GNUNET_OK == 431 GNUNET_break (GNUNET_OK ==
425 GNUNET_CONTAINER_multipeermap_put(map, &identity, &identity, 432 GNUNET_CONTAINER_multipeermap_put (map, &identity, &identity,
426 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 433 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
427 DEBUG("Setting %u ms latency to peer `%s'\n", 434 DEBUG ("Setting %u ms latency to peer `%s'\n",
428 wl_entry->latency, 435 wl_entry->latency,
429 GNUNET_i2s(&identity)); 436 GNUNET_i2s (&identity));
430 GNUNET_TRANSPORT_manipulation_set(transport, 437 GNUNET_TRANSPORT_manipulation_set (transport,
431 &identity, 438 &identity,
432 &prop, 439 &prop,
433 delay, 440 delay,
434 delay); 441 delay);
435 GNUNET_free(wl_entry); 442 GNUNET_free (wl_entry);
436 } 443 }
437 bh = GNUNET_TRANSPORT_blacklist(c, &check_access, NULL); 444 bh = GNUNET_TRANSPORT_blacklist (c, &check_access, NULL);
438 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); 445 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
439 446
440close_db: 447close_db:
441 GNUNET_break(SQLITE_OK == sqlite3_close(db)); 448 GNUNET_break (SQLITE_OK == sqlite3_close (db));
442} 449}
443 450
444 451
@@ -450,24 +457,25 @@ close_db:
450 * @return 0 ok, 1 on error 457 * @return 0 ok, 1 on error
451 */ 458 */
452int 459int
453main(int argc, char *const *argv) 460main (int argc, char *const *argv)
454{ 461{
455 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 462 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
456 GNUNET_GETOPT_OPTION_END 463 GNUNET_GETOPT_OPTION_END
457 }; 464 };
458 int ret; 465 int ret;
459 466
460 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 467 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
461 return 2; 468 return 2;
462#ifdef SQLITE_CONFIG_MMAP_SIZE 469#ifdef SQLITE_CONFIG_MMAP_SIZE
463 (void)sqlite3_config(SQLITE_CONFIG_MMAP_SIZE, 512000, 256000000); 470 (void) sqlite3_config (SQLITE_CONFIG_MMAP_SIZE, 512000, 256000000);
464#endif 471#endif
465 ret = 472 ret =
466 (GNUNET_OK == 473 (GNUNET_OK ==
467 GNUNET_PROGRAM_run(argc, argv, "testbed-underlay", 474 GNUNET_PROGRAM_run (argc, argv, "testbed-underlay",
468 _ 475 _
469 ("Daemon to restrict underlay network in testbed deployments"), 476 (
470 options, &run, NULL)) ? 0 : 1; 477 "Daemon to restrict underlay network in testbed deployments"),
471 GNUNET_free((void*)argv); 478 options, &run, NULL)) ? 0 : 1;
479 GNUNET_free ((void*) argv);
472 return ret; 480 return ret;
473} 481}
diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c
index 0650e7dbd..f7d089d93 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/**
@@ -66,7 +66,8 @@
66/** 66/**
67 * Context for a single write on a chunk of memory 67 * Context for a single write on a chunk of memory
68 */ 68 */
69struct WriteContext { 69struct WriteContext
70{
70 /** 71 /**
71 * The data to write 72 * The data to write
72 */ 73 */
@@ -146,50 +147,50 @@ static int status;
146 * @param cls NULL 147 * @param cls NULL
147 */ 148 */
148static void 149static void
149shutdown_task(void *cls) 150shutdown_task (void *cls)
150{ 151{
151 LOG_DEBUG("Shutting down\n"); 152 LOG_DEBUG ("Shutting down\n");
152 if (NULL != testbed) 153 if (NULL != testbed)
153 { 154 {
154 LOG_DEBUG("Killing testbed\n"); 155 LOG_DEBUG ("Killing testbed\n");
155 GNUNET_break(0 == GNUNET_OS_process_kill(testbed, GNUNET_TERM_SIG)); 156 GNUNET_break (0 == GNUNET_OS_process_kill (testbed, GNUNET_TERM_SIG));
156 } 157 }
157 if (NULL != read_task_id) 158 if (NULL != read_task_id)
158 { 159 {
159 GNUNET_SCHEDULER_cancel(read_task_id); 160 GNUNET_SCHEDULER_cancel (read_task_id);
160 read_task_id = NULL; 161 read_task_id = NULL;
161 } 162 }
162 if (NULL != write_task_id) 163 if (NULL != write_task_id)
163 { 164 {
164 struct WriteContext *wc; 165 struct WriteContext *wc;
165 166
166 wc = GNUNET_SCHEDULER_cancel(write_task_id); 167 wc = GNUNET_SCHEDULER_cancel (write_task_id);
167 write_task_id = NULL; 168 write_task_id = NULL;
168 GNUNET_free(wc->data); 169 GNUNET_free (wc->data);
169 GNUNET_free(wc); 170 GNUNET_free (wc);
170 } 171 }
171 if (NULL != child_death_task_id) 172 if (NULL != child_death_task_id)
172 { 173 {
173 GNUNET_SCHEDULER_cancel(child_death_task_id); 174 GNUNET_SCHEDULER_cancel (child_death_task_id);
174 child_death_task_id = NULL; 175 child_death_task_id = NULL;
175 } 176 }
176 if (NULL != stdin_fd) 177 if (NULL != stdin_fd)
177 (void)GNUNET_DISK_file_close(stdin_fd); 178 (void) GNUNET_DISK_file_close (stdin_fd);
178 if (NULL != stdout_fd) 179 if (NULL != stdout_fd)
179 (void)GNUNET_DISK_file_close(stdout_fd); 180 (void) GNUNET_DISK_file_close (stdout_fd);
180 GNUNET_MST_destroy(tokenizer); 181 GNUNET_MST_destroy (tokenizer);
181 tokenizer = NULL; 182 tokenizer = NULL;
182 if (NULL != testbed) 183 if (NULL != testbed)
183 { 184 {
184 GNUNET_break(GNUNET_OK == GNUNET_OS_process_wait(testbed)); 185 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (testbed));
185 GNUNET_OS_process_destroy(testbed); 186 GNUNET_OS_process_destroy (testbed);
186 testbed = NULL; 187 testbed = NULL;
187 } 188 }
188 if (NULL != test_system) 189 if (NULL != test_system)
189 { 190 {
190 GNUNET_TESTING_system_destroy(test_system, GNUNET_YES); 191 GNUNET_TESTING_system_destroy (test_system, GNUNET_YES);
191 test_system = NULL; 192 test_system = NULL;
192 } 193 }
193} 194}
194 195
195 196
@@ -199,34 +200,34 @@ shutdown_task(void *cls)
199 * @param cls the WriteContext 200 * @param cls the WriteContext
200 */ 201 */
201static void 202static void
202write_task(void *cls) 203write_task (void *cls)
203{ 204{
204 struct WriteContext *wc = cls; 205 struct WriteContext *wc = cls;
205 ssize_t bytes_wrote; 206 ssize_t bytes_wrote;
206 207
207 GNUNET_assert(NULL != wc); 208 GNUNET_assert (NULL != wc);
208 write_task_id = NULL; 209 write_task_id = NULL;
209 bytes_wrote = GNUNET_DISK_file_write(stdout_fd, 210 bytes_wrote = GNUNET_DISK_file_write (stdout_fd,
210 wc->data + wc->pos, 211 wc->data + wc->pos,
211 wc->length - wc->pos); 212 wc->length - wc->pos);
212 if (GNUNET_SYSERR == bytes_wrote) 213 if (GNUNET_SYSERR == bytes_wrote)
213 { 214 {
214 LOG(GNUNET_ERROR_TYPE_WARNING, "Cannot reply back configuration\n"); 215 LOG (GNUNET_ERROR_TYPE_WARNING, "Cannot reply back configuration\n");
215 GNUNET_free(wc->data); 216 GNUNET_free (wc->data);
216 GNUNET_free(wc); 217 GNUNET_free (wc);
217 return; 218 return;
218 } 219 }
219 wc->pos += bytes_wrote; 220 wc->pos += bytes_wrote;
220 if (wc->pos == wc->length) 221 if (wc->pos == wc->length)
221 { 222 {
222 GNUNET_free(wc->data); 223 GNUNET_free (wc->data);
223 GNUNET_free(wc); 224 GNUNET_free (wc);
224 return; 225 return;
225 } 226 }
226 write_task_id = GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL, 227 write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
227 stdout_fd, 228 stdout_fd,
228 &write_task, 229 &write_task,
229 wc); 230 wc);
230} 231}
231 232
232 233
@@ -237,7 +238,7 @@ write_task(void *cls)
237 * @param cls closure, NULL if we need to self-restart 238 * @param cls closure, NULL if we need to self-restart
238 */ 239 */
239static void 240static void
240child_death_task(void *cls) 241child_death_task (void *cls)
241{ 242{
242 const struct GNUNET_DISK_FileHandle *pr; 243 const struct GNUNET_DISK_FileHandle *pr;
243 char c[16]; 244 char c[16];
@@ -245,36 +246,36 @@ child_death_task(void *cls)
245 unsigned long code; 246 unsigned long code;
246 int ret; 247 int ret;
247 248
248 pr = GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ); 249 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
249 child_death_task_id = NULL; 250 child_death_task_id = NULL;
250 /* consume the signal */ 251 /* consume the signal */
251 GNUNET_break(0 < GNUNET_DISK_file_read(pr, &c, sizeof(c))); 252 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof(c)));
252 LOG_DEBUG("Got SIGCHLD\n"); 253 LOG_DEBUG ("Got SIGCHLD\n");
253 if (NULL == testbed) 254 if (NULL == testbed)
254 { 255 {
255 GNUNET_break(0); 256 GNUNET_break (0);
256 return; 257 return;
257 } 258 }
258 GNUNET_break(GNUNET_SYSERR != 259 GNUNET_break (GNUNET_SYSERR !=
259 (ret = GNUNET_OS_process_status(testbed, &type, &code))); 260 (ret = GNUNET_OS_process_status (testbed, &type, &code)));
260 if (GNUNET_NO != ret) 261 if (GNUNET_NO != ret)
262 {
263 GNUNET_OS_process_destroy (testbed);
264 testbed = NULL;
265 /* Send SIGTERM to our process group */
266 if (0 != kill (0, GNUNET_TERM_SIG))
261 { 267 {
262 GNUNET_OS_process_destroy(testbed); 268 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "signal");
263 testbed = NULL; 269 GNUNET_SCHEDULER_shutdown (); /* Couldn't send the signal, we shutdown frowning */
264 /* Send SIGTERM to our process group */
265 if (0 != kill(0, GNUNET_TERM_SIG))
266 {
267 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "signal");
268 GNUNET_SCHEDULER_shutdown(); /* Couldn't send the signal, we shutdown frowning */
269 }
270 return;
271 } 270 }
272 LOG_DEBUG("Child hasn't died. Resuming to monitor its status\n"); 271 return;
272 }
273 LOG_DEBUG ("Child hasn't died. Resuming to monitor its status\n");
273 child_death_task_id = 274 child_death_task_id =
274 GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, 275 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
275 pr, 276 pr,
276 &child_death_task, 277 &child_death_task,
277 NULL); 278 NULL);
278} 279}
279 280
280 281
@@ -291,7 +292,7 @@ child_death_task(void *cls)
291 * #GNUNET_SYSERR to stop further processing with error 292 * #GNUNET_SYSERR to stop further processing with error
292 */ 293 */
293static int 294static int
294tokenizer_cb(void *cls, const struct GNUNET_MessageHeader *message) 295tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
295{ 296{
296 const struct GNUNET_TESTBED_HelperInit *msg; 297 const struct GNUNET_TESTBED_HelperInit *msg;
297 struct GNUNET_TESTBED_HelperReply *reply; 298 struct GNUNET_TESTBED_HelperReply *reply;
@@ -303,7 +304,7 @@ tokenizer_cb(void *cls, const struct GNUNET_MessageHeader *message)
303 char *config; 304 char *config;
304 char *xconfig; 305 char *xconfig;
305 char *evstr; 306 char *evstr;
306 //char *str; 307 // char *str;
307 size_t config_size; 308 size_t config_size;
308 uLongf ul_config_size; 309 uLongf ul_config_size;
309 size_t xconfig_size; 310 size_t xconfig_size;
@@ -311,177 +312,177 @@ tokenizer_cb(void *cls, const struct GNUNET_MessageHeader *message)
311 uint16_t hostname_size; 312 uint16_t hostname_size;
312 uint16_t msize; 313 uint16_t msize;
313 314
314 msize = ntohs(message->size); 315 msize = ntohs (message->size);
315 if ((sizeof(struct GNUNET_TESTBED_HelperInit) >= msize) || 316 if ((sizeof(struct GNUNET_TESTBED_HelperInit) >= msize) ||
316 (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT != ntohs(message->type))) 317 (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT != ntohs (message->type)))
317 { 318 {
318 LOG(GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); 319 LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n");
319 goto error; 320 goto error;
320 } 321 }
321 msg = (const struct GNUNET_TESTBED_HelperInit *)message; 322 msg = (const struct GNUNET_TESTBED_HelperInit *) message;
322 trusted_ip_size = ntohs(msg->trusted_ip_size); 323 trusted_ip_size = ntohs (msg->trusted_ip_size);
323 trusted_ip = (char *)&msg[1]; 324 trusted_ip = (char *) &msg[1];
324 if ('\0' != trusted_ip[trusted_ip_size]) 325 if ('\0' != trusted_ip[trusted_ip_size])
325 { 326 {
326 LOG(GNUNET_ERROR_TYPE_WARNING, "Trusted IP cannot be empty -- exiting\n"); 327 LOG (GNUNET_ERROR_TYPE_WARNING, "Trusted IP cannot be empty -- exiting\n");
327 goto error; 328 goto error;
328 } 329 }
329 hostname_size = ntohs(msg->hostname_size); 330 hostname_size = ntohs (msg->hostname_size);
330 if ((sizeof(struct GNUNET_TESTBED_HelperInit) + trusted_ip_size + 1 + 331 if ((sizeof(struct GNUNET_TESTBED_HelperInit) + trusted_ip_size + 1
331 hostname_size) >= msize) 332 + hostname_size) >= msize)
332 { 333 {
333 GNUNET_break(0); 334 GNUNET_break (0);
334 LOG(GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); 335 LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n");
335 goto error; 336 goto error;
336 } 337 }
337 ul_config_size = (uLongf)ntohs(msg->config_size); 338 ul_config_size = (uLongf) ntohs (msg->config_size);
338 config = GNUNET_malloc(ul_config_size); 339 config = GNUNET_malloc (ul_config_size);
339 xconfig_size = msize - (trusted_ip_size + 1 + hostname_size + 340 xconfig_size = msize - (trusted_ip_size + 1 + hostname_size
340 sizeof(struct GNUNET_TESTBED_HelperInit)); 341 + sizeof(struct GNUNET_TESTBED_HelperInit));
341 int ret = uncompress((Bytef *)config, 342 int ret = uncompress ((Bytef *) config,
342 &ul_config_size, 343 &ul_config_size,
343 (const Bytef *)(trusted_ip + trusted_ip_size + 1 + 344 (const Bytef *) (trusted_ip + trusted_ip_size + 1
344 hostname_size), 345 + hostname_size),
345 (uLongf)xconfig_size); 346 (uLongf) xconfig_size);
346 if (Z_OK != ret) 347 if (Z_OK != ret)
348 {
349 switch (ret)
347 { 350 {
348 switch (ret) 351 case Z_MEM_ERROR:
349 { 352 LOG (GNUNET_ERROR_TYPE_ERROR, "Not enough memory for decompression\n");
350 case Z_MEM_ERROR: 353 break;
351 LOG(GNUNET_ERROR_TYPE_ERROR, "Not enough memory for decompression\n"); 354
352 break; 355 case Z_BUF_ERROR:
353 356 LOG (GNUNET_ERROR_TYPE_ERROR, "Output buffer too small\n");
354 case Z_BUF_ERROR: 357 break;
355 LOG(GNUNET_ERROR_TYPE_ERROR, "Output buffer too small\n"); 358
356 break; 359 case Z_DATA_ERROR:
357 360 LOG (GNUNET_ERROR_TYPE_ERROR, "Data corrupted/incomplete\n");
358 case Z_DATA_ERROR: 361 break;
359 LOG(GNUNET_ERROR_TYPE_ERROR, "Data corrupted/incomplete\n"); 362
360 break; 363 default:
361 364 GNUNET_break (0);
362 default:
363 GNUNET_break(0);
364 }
365 LOG(GNUNET_ERROR_TYPE_ERROR,
366 "Error while uncompressing config -- exiting\n");
367 GNUNET_free(config);
368 goto error;
369 } 365 }
370 cfg = GNUNET_CONFIGURATION_create(); 366 LOG (GNUNET_ERROR_TYPE_ERROR,
367 "Error while uncompressing config -- exiting\n");
368 GNUNET_free (config);
369 goto error;
370 }
371 cfg = GNUNET_CONFIGURATION_create ();
371 if (GNUNET_OK != 372 if (GNUNET_OK !=
372 GNUNET_CONFIGURATION_deserialize(cfg, config, ul_config_size, NULL)) 373 GNUNET_CONFIGURATION_deserialize (cfg, config, ul_config_size, NULL))
373 { 374 {
374 LOG(GNUNET_ERROR_TYPE_ERROR, "Unable to deserialize config -- exiting\n"); 375 LOG (GNUNET_ERROR_TYPE_ERROR, "Unable to deserialize config -- exiting\n");
375 GNUNET_free(config); 376 GNUNET_free (config);
376 goto error; 377 goto error;
377 } 378 }
378 GNUNET_free(config); 379 GNUNET_free (config);
379 hostname = NULL; 380 hostname = NULL;
380 if (0 != hostname_size) 381 if (0 != hostname_size)
381 { 382 {
382 hostname = GNUNET_malloc(hostname_size + 1); 383 hostname = GNUNET_malloc (hostname_size + 1);
383 GNUNET_strlcpy(hostname, 384 GNUNET_strlcpy (hostname,
384 ((char *)&msg[1]) + trusted_ip_size + 1, 385 ((char *) &msg[1]) + trusted_ip_size + 1,
385 hostname_size + 1); 386 hostname_size + 1);
386 } 387 }
387 /* unset GNUNET_TESTING_PREFIX if present as it is more relevant for testbed */ 388 /* unset GNUNET_TESTING_PREFIX if present as it is more relevant for testbed */
388 evstr = getenv(GNUNET_TESTING_PREFIX); 389 evstr = getenv (GNUNET_TESTING_PREFIX);
389 if (NULL != evstr) 390 if (NULL != evstr)
390 { 391 {
391 /* unsetting the variable will invalidate the pointer! */ 392 /* unsetting the variable will invalidate the pointer! */
392 evstr = GNUNET_strdup(evstr); 393 evstr = GNUNET_strdup (evstr);
393 GNUNET_break(0 == unsetenv(GNUNET_TESTING_PREFIX)); 394 GNUNET_break (0 == unsetenv (GNUNET_TESTING_PREFIX));
394 } 395 }
395 test_system = 396 test_system =
396 GNUNET_TESTING_system_create("testbed-helper", trusted_ip, hostname, NULL); 397 GNUNET_TESTING_system_create ("testbed-helper", trusted_ip, hostname, NULL);
397 if (NULL != evstr) 398 if (NULL != evstr)
398 { 399 {
399 char *evar; 400 char *evar;
400 401
401 GNUNET_asprintf(&evar, GNUNET_TESTING_PREFIX "=%s", evstr); 402 GNUNET_asprintf (&evar, GNUNET_TESTING_PREFIX "=%s", evstr);
402 GNUNET_assert(0 == putenv(evar)); /* consumes 'evar', 403 GNUNET_assert (0 == putenv (evar)); /* consumes 'evar',
403 see putenv(): becomes part of envrionment! */ 404 see putenv(): becomes part of envrionment! */
404 GNUNET_free(evstr); 405 GNUNET_free (evstr);
405 evstr = NULL; 406 evstr = NULL;
406 } 407 }
407 GNUNET_free_non_null(hostname); 408 GNUNET_free_non_null (hostname);
408 hostname = NULL; 409 hostname = NULL;
409 GNUNET_assert(NULL != test_system); 410 GNUNET_assert (NULL != test_system);
410 GNUNET_assert(GNUNET_OK == 411 GNUNET_assert (GNUNET_OK ==
411 GNUNET_TESTING_configuration_create(test_system, cfg)); 412 GNUNET_TESTING_configuration_create (test_system, cfg));
412 GNUNET_assert(GNUNET_OK == 413 GNUNET_assert (GNUNET_OK ==
413 GNUNET_CONFIGURATION_get_value_filename(cfg, 414 GNUNET_CONFIGURATION_get_value_filename (cfg,
414 "PATHS", 415 "PATHS",
415 "DEFAULTCONFIG", 416 "DEFAULTCONFIG",
416 &config)); 417 &config));
417 if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg, config)) 418 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config))
418 { 419 {
419 LOG(GNUNET_ERROR_TYPE_WARNING, 420 LOG (GNUNET_ERROR_TYPE_WARNING,
420 "Unable to write config file: %s -- exiting\n", 421 "Unable to write config file: %s -- exiting\n",
421 config); 422 config);
422 GNUNET_CONFIGURATION_destroy(cfg); 423 GNUNET_CONFIGURATION_destroy (cfg);
423 GNUNET_free(config); 424 GNUNET_free (config);
424 goto error; 425 goto error;
425 } 426 }
426 LOG_DEBUG("Staring testbed with config: %s\n", config); 427 LOG_DEBUG ("Staring testbed with config: %s\n", config);
427 binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-testbed"); 428 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-testbed");
428 { 429 {
429 char *evar; 430 char *evar;
430 431
431 /* expose testbed configuration through env variable */ 432 /* expose testbed configuration through env variable */
432 GNUNET_asprintf(&evar, "%s=%s", ENV_TESTBED_CONFIG, config); 433 GNUNET_asprintf (&evar, "%s=%s", ENV_TESTBED_CONFIG, config);
433 GNUNET_assert(0 == putenv(evar)); /* consumes 'evar', 434 GNUNET_assert (0 == putenv (evar)); /* consumes 'evar',
434 see putenv(): becomes part of envrionment! */ 435 see putenv(): becomes part of envrionment! */
435 evstr = NULL; 436 evstr = NULL;
436 } 437 }
437 testbed = GNUNET_OS_start_process(PIPE_CONTROL, 438 testbed = GNUNET_OS_start_process (PIPE_CONTROL,
438 GNUNET_OS_INHERIT_STD_ERR /*verbose? */, 439 GNUNET_OS_INHERIT_STD_ERR /*verbose? */,
439 NULL, 440 NULL,
440 NULL, 441 NULL,
441 NULL, 442 NULL,
442 binary, 443 binary,
443 "gnunet-service-testbed", 444 "gnunet-service-testbed",
444 "-c", 445 "-c",
445 config, 446 config,
446 NULL); 447 NULL);
447 GNUNET_free(binary); 448 GNUNET_free (binary);
448 GNUNET_free(config); 449 GNUNET_free (config);
449 if (NULL == testbed) 450 if (NULL == testbed)
450 { 451 {
451 LOG(GNUNET_ERROR_TYPE_WARNING, 452 LOG (GNUNET_ERROR_TYPE_WARNING,
452 "Error starting gnunet-service-testbed -- exiting\n"); 453 "Error starting gnunet-service-testbed -- exiting\n");
453 GNUNET_CONFIGURATION_destroy(cfg); 454 GNUNET_CONFIGURATION_destroy (cfg);
454 goto error; 455 goto error;
455 } 456 }
456 done_reading = GNUNET_YES; 457 done_reading = GNUNET_YES;
457 config = GNUNET_CONFIGURATION_serialize(cfg, &config_size); 458 config = GNUNET_CONFIGURATION_serialize (cfg, &config_size);
458 GNUNET_CONFIGURATION_destroy(cfg); 459 GNUNET_CONFIGURATION_destroy (cfg);
459 cfg = NULL; 460 cfg = NULL;
460 xconfig_size = 461 xconfig_size =
461 GNUNET_TESTBED_compress_config_(config, config_size, &xconfig); 462 GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig);
462 GNUNET_free(config); 463 GNUNET_free (config);
463 wc = GNUNET_new(struct WriteContext); 464 wc = GNUNET_new (struct WriteContext);
464 wc->length = xconfig_size + sizeof(struct GNUNET_TESTBED_HelperReply); 465 wc->length = xconfig_size + sizeof(struct GNUNET_TESTBED_HelperReply);
465 reply = GNUNET_realloc(xconfig, wc->length); 466 reply = GNUNET_realloc (xconfig, wc->length);
466 memmove(&reply[1], reply, xconfig_size); 467 memmove (&reply[1], reply, xconfig_size);
467 reply->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY); 468 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY);
468 reply->header.size = htons((uint16_t)wc->length); 469 reply->header.size = htons ((uint16_t) wc->length);
469 reply->config_size = htons((uint16_t)config_size); 470 reply->config_size = htons ((uint16_t) config_size);
470 wc->data = reply; 471 wc->data = reply;
471 write_task_id = GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL, 472 write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
472 stdout_fd, 473 stdout_fd,
473 &write_task, 474 &write_task,
474 wc); 475 wc);
475 child_death_task_id = GNUNET_SCHEDULER_add_read_file( 476 child_death_task_id = GNUNET_SCHEDULER_add_read_file (
476 GNUNET_TIME_UNIT_FOREVER_REL, 477 GNUNET_TIME_UNIT_FOREVER_REL,
477 GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ), 478 GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ),
478 &child_death_task, 479 &child_death_task,
479 NULL); 480 NULL);
480 return GNUNET_OK; 481 return GNUNET_OK;
481 482
482error: 483error:
483 status = GNUNET_SYSERR; 484 status = GNUNET_SYSERR;
484 GNUNET_SCHEDULER_shutdown(); 485 GNUNET_SCHEDULER_shutdown ();
485 return GNUNET_SYSERR; 486 return GNUNET_SYSERR;
486} 487}
487 488
@@ -492,41 +493,41 @@ error:
492 * @param cls NULL 493 * @param cls NULL
493 */ 494 */
494static void 495static void
495read_task(void *cls) 496read_task (void *cls)
496{ 497{
497 char buf[GNUNET_MAX_MESSAGE_SIZE]; 498 char buf[GNUNET_MAX_MESSAGE_SIZE];
498 ssize_t sread; 499 ssize_t sread;
499 500
500 read_task_id = NULL; 501 read_task_id = NULL;
501 sread = GNUNET_DISK_file_read(stdin_fd, buf, sizeof(buf)); 502 sread = GNUNET_DISK_file_read (stdin_fd, buf, sizeof(buf));
502 if ((GNUNET_SYSERR == sread) || (0 == sread)) 503 if ((GNUNET_SYSERR == sread) || (0 == sread))
503 { 504 {
504 LOG_DEBUG("STDIN closed\n"); 505 LOG_DEBUG ("STDIN closed\n");
505 GNUNET_SCHEDULER_shutdown(); 506 GNUNET_SCHEDULER_shutdown ();
506 return; 507 return;
507 } 508 }
508 if (GNUNET_YES == done_reading) 509 if (GNUNET_YES == done_reading)
509 { 510 {
510 /* didn't expect any more data! */ 511 /* didn't expect any more data! */
511 GNUNET_break_op(0); 512 GNUNET_break_op (0);
512 GNUNET_SCHEDULER_shutdown(); 513 GNUNET_SCHEDULER_shutdown ();
513 return; 514 return;
514 } 515 }
515 LOG_DEBUG("Read %u bytes\n", (unsigned int)sread); 516 LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread);
516 /* FIXME: could introduce a GNUNET_MST_read2 to read 517 /* FIXME: could introduce a GNUNET_MST_read2 to read
517 directly from 'stdin_fd' and save a memcpy() here */ 518 directly from 'stdin_fd' and save a memcpy() here */
518 if (GNUNET_OK != 519 if (GNUNET_OK !=
519 GNUNET_MST_from_buffer(tokenizer, buf, sread, GNUNET_NO, GNUNET_NO)) 520 GNUNET_MST_from_buffer (tokenizer, buf, sread, GNUNET_NO, GNUNET_NO))
520 { 521 {
521 GNUNET_break(0); 522 GNUNET_break (0);
522 GNUNET_SCHEDULER_shutdown(); 523 GNUNET_SCHEDULER_shutdown ();
523 return; 524 return;
524 } 525 }
525 read_task_id /* No timeout while reading */ 526 read_task_id /* No timeout while reading */
526 = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, 527 = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
527 stdin_fd, 528 stdin_fd,
528 &read_task, 529 &read_task,
529 NULL); 530 NULL);
530} 531}
531 532
532 533
@@ -539,20 +540,20 @@ read_task(void *cls)
539 * @param cfg configuration 540 * @param cfg configuration
540 */ 541 */
541static void 542static void
542run(void *cls, 543run (void *cls,
543 char *const *args, 544 char *const *args,
544 const char *cfgfile, 545 const char *cfgfile,
545 const struct GNUNET_CONFIGURATION_Handle *cfg) 546 const struct GNUNET_CONFIGURATION_Handle *cfg)
546{ 547{
547 LOG_DEBUG("Starting testbed helper...\n"); 548 LOG_DEBUG ("Starting testbed helper...\n");
548 tokenizer = GNUNET_MST_create(&tokenizer_cb, NULL); 549 tokenizer = GNUNET_MST_create (&tokenizer_cb, NULL);
549 stdin_fd = GNUNET_DISK_get_handle_from_native(stdin); 550 stdin_fd = GNUNET_DISK_get_handle_from_native (stdin);
550 stdout_fd = GNUNET_DISK_get_handle_from_native(stdout); 551 stdout_fd = GNUNET_DISK_get_handle_from_native (stdout);
551 read_task_id = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, 552 read_task_id = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
552 stdin_fd, 553 stdin_fd,
553 &read_task, 554 &read_task,
554 NULL); 555 NULL);
555 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); 556 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
556} 557}
557 558
558 559
@@ -560,18 +561,18 @@ run(void *cls,
560 * Signal handler called for SIGCHLD. 561 * Signal handler called for SIGCHLD.
561 */ 562 */
562static void 563static void
563sighandler_child_death() 564sighandler_child_death ()
564{ 565{
565 static char c; 566 static char c;
566 int old_errno; /* back-up errno */ 567 int old_errno; /* back-up errno */
567 568
568 old_errno = errno; 569 old_errno = errno;
569 GNUNET_break( 570 GNUNET_break (
570 1 == 571 1 ==
571 GNUNET_DISK_file_write(GNUNET_DISK_pipe_handle(sigpipe, 572 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe,
572 GNUNET_DISK_PIPE_END_WRITE), 573 GNUNET_DISK_PIPE_END_WRITE),
573 &c, 574 &c,
574 sizeof(c))); 575 sizeof(c)));
575 errno = old_errno; 576 errno = old_errno;
576} 577}
577 578
@@ -584,31 +585,32 @@ sighandler_child_death()
584 * @return return code 585 * @return return code
585 */ 586 */
586int 587int
587main(int argc, char **argv) 588main (int argc, char **argv)
588{ 589{
589 struct GNUNET_SIGNAL_Context *shc_chld; 590 struct GNUNET_SIGNAL_Context *shc_chld;
590 struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; 591 struct GNUNET_GETOPT_CommandLineOption options[] =
592 { GNUNET_GETOPT_OPTION_END };
591 int ret; 593 int ret;
592 594
593 status = GNUNET_OK; 595 status = GNUNET_OK;
594 if (NULL == 596 if (NULL ==
595 (sigpipe = GNUNET_DISK_pipe(GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO))) 597 (sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO)))
596 { 598 {
597 GNUNET_break(0); 599 GNUNET_break (0);
598 return 1; 600 return 1;
599 } 601 }
600 shc_chld = 602 shc_chld =
601 GNUNET_SIGNAL_handler_install(GNUNET_SIGCHLD, &sighandler_child_death); 603 GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
602 ret = GNUNET_PROGRAM_run(argc, 604 ret = GNUNET_PROGRAM_run (argc,
603 argv, 605 argv,
604 "gnunet-helper-testbed", 606 "gnunet-helper-testbed",
605 "Helper for starting gnunet-service-testbed", 607 "Helper for starting gnunet-service-testbed",
606 options, 608 options,
607 &run, 609 &run,
608 NULL); 610 NULL);
609 GNUNET_SIGNAL_handler_uninstall(shc_chld); 611 GNUNET_SIGNAL_handler_uninstall (shc_chld);
610 shc_chld = NULL; 612 shc_chld = NULL;
611 GNUNET_DISK_pipe_close(sigpipe); 613 GNUNET_DISK_pipe_close (sigpipe);
612 if (GNUNET_OK != ret) 614 if (GNUNET_OK != ret)
613 return 1; 615 return 1;
614 return (GNUNET_OK == status) ? 0 : 1; 616 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 5902a1576..b28f343a1 100644
--- a/src/testbed/gnunet-service-test-barriers.c
+++ b/src/testbed/gnunet-service-test-barriers.c
@@ -34,7 +34,7 @@
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 */
52static void 52static void
53do_shutdown(void *cls) 53do_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 */
78static void 78static void
79barrier_wait_cb(void *cls, 79barrier_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 */
95static void 95static void
96do_wait(void *cls) 96do_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,21 @@ do_wait(void *cls)
112 * @param config the configuration file handle 112 * @param config the configuration file handle
113 */ 113 */
114static void 114static void
115run(void *cls, 115run (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 (
125 rsec), 125 GNUNET_TIME_UNIT_SECONDS,
126 &do_wait, 126 rsec),
127 NULL); 127 &do_wait,
128 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); 128 NULL);
129 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
129} 130}
130 131
131 132
@@ -134,7 +135,7 @@ run(void *cls,
134 * Main 135 * Main
135 */ 136 */
136int 137int
137main(int argc, char **argv) 138main (int argc, char **argv)
138{ 139{
139 struct GNUNET_GETOPT_CommandLineOption options[] = { 140 struct GNUNET_GETOPT_CommandLineOption options[] = {
140 GNUNET_GETOPT_OPTION_END 141 GNUNET_GETOPT_OPTION_END
@@ -142,11 +143,11 @@ main(int argc, char **argv)
142 int ret; 143 int ret;
143 144
144 ret = 145 ret =
145 GNUNET_PROGRAM_run(argc, argv, 146 GNUNET_PROGRAM_run (argc, argv,
146 "test-barriers", 147 "test-barriers",
147 "nohelp", 148 "nohelp",
148 options, 149 options,
149 &run, 150 &run,
150 NULL); 151 NULL);
151 return ret; 152 return ret;
152} 153}
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index 26f1a9c26..b34550339 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -96,18 +96,18 @@ static char *hostname;
96 * already in use 96 * already in use
97 */ 97 */
98static int 98static int
99host_list_add(struct GNUNET_TESTBED_Host *host) 99host_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 */
123void 123void
124GST_send_operation_fail_msg(struct GNUNET_SERVICE_Client *client, 124GST_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 */
152void 152void
153GST_send_operation_success_msg(struct GNUNET_SERVICE_Client *client, 153GST_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 */
174static void 174static void
175hr_completion(void *cls, 175hr_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 */
185static void 185static void
186register_next_host(struct Slave *slave) 186register_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 */
210static void 210static void
211hr_completion(void *cls, 211hr_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 */
245void 245void
246GST_queue_host_registration(struct Slave *slave, 246GST_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 */
277void 277void
278GST_forwarded_operation_reply_relay(void *cls, 278GST_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 */
303void 303void
304GST_forwarded_operation_timeout(void *cls) 304GST_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,8 +329,8 @@ GST_forwarded_operation_timeout(void *cls)
329 * upon empty service sharing specification. 329 * upon empty service sharing specification.
330 */ 330 */
331static struct GNUNET_TESTING_SharedService * 331static struct GNUNET_TESTING_SharedService *
332parse_shared_services(char *ss_str, 332parse_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;
@@ -340,41 +340,41 @@ parse_shared_services(char *ss_str,
340 340
341#define GROW_SS \ 341#define GROW_SS \
342 do { \ 342 do { \
343 GNUNET_array_grow(slist, n, n + 1); \ 343 GNUNET_array_grow (slist, n, n + 1); \
344 GNUNET_memcpy(&slist[n - 1], &ss, \ 344 GNUNET_memcpy (&slist[n - 1], &ss, \
345 sizeof(struct GNUNET_TESTING_SharedService)); \ 345 sizeof(struct GNUNET_TESTING_SharedService)); \
346 } while (0) 346 } while (0)
347 347
348 slist = NULL; 348 slist = NULL;
349 n = 0; 349 n = 0;
350 ss.cfg = cfg; 350 ss.cfg = cfg;
351 for (; NULL != (arg = strtok(ss_str, " ")); ss_str = NULL) 351 for (; NULL != (arg = strtok (ss_str, " ")); ss_str = NULL)
352 {
353 ss.service = NULL;
354 ss.share = 0;
355 if (2 != sscanf (arg, "%255[^:]:%u",
356 service,
357 &ss.share))
352 { 358 {
353 ss.service = NULL; 359 LOG (GNUNET_ERROR_TYPE_WARNING,
354 ss.share = 0; 360 "Ignoring shared service spec: %s",
355 if (2 != sscanf(arg, "%255[^:]:%u", 361 arg);
356 service, 362 continue;
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;
369 } 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;
369 }
370 if (NULL != slist) 370 if (NULL != slist)
371 { 371 {
372 /* Add trailing NULL block */ 372 /* Add trailing NULL block */
373 (void)memset(&ss, 373 (void) memset (&ss,
374 0, 374 0,
375 sizeof(struct GNUNET_TESTING_SharedService)); 375 sizeof(struct GNUNET_TESTING_SharedService));
376 GROW_SS; 376 GROW_SS;
377 } 377 }
378 return slist; 378 return slist;
379#undef GROW_SS 379#undef GROW_SS
380} 380}
@@ -388,19 +388,19 @@ parse_shared_services(char *ss_str,
388 * @return #GNUNET_OK if @a message is well-formed 388 * @return #GNUNET_OK if @a message is well-formed
389 */ 389 */
390static int 390static int
391check_init(void *cls, 391check_init (void *cls,
392 const struct GNUNET_TESTBED_InitMessage *msg) 392 const struct GNUNET_TESTBED_InitMessage *msg)
393{ 393{
394 const char *controller_hostname; 394 const char *controller_hostname;
395 uint16_t msize; 395 uint16_t msize;
396 396
397 msize = ntohs(msg->header.size) - sizeof(struct GNUNET_TESTBED_InitMessage); 397 msize = ntohs (msg->header.size) - sizeof(struct GNUNET_TESTBED_InitMessage);
398 controller_hostname = (const char *)&msg[1]; 398 controller_hostname = (const char *) &msg[1];
399 if ('\0' != controller_hostname[msize - 1]) 399 if ('\0' != controller_hostname[msize - 1])
400 { 400 {
401 GNUNET_break(0); 401 GNUNET_break (0);
402 return GNUNET_SYSERR; 402 return GNUNET_SYSERR;
403 } 403 }
404 return GNUNET_OK; 404 return GNUNET_OK;
405} 405}
406 406
@@ -412,8 +412,8 @@ check_init(void *cls,
412 * @param message the actual message 412 * @param message the actual message
413 */ 413 */
414static void 414static void
415handle_init(void *cls, 415handle_init (void *cls,
416 const struct GNUNET_TESTBED_InitMessage *msg) 416 const struct GNUNET_TESTBED_InitMessage *msg)
417{ 417{
418 struct GNUNET_SERVICE_Client *client = cls; 418 struct GNUNET_SERVICE_Client *client = cls;
419 struct GNUNET_TESTBED_Host *host; 419 struct GNUNET_TESTBED_Host *host;
@@ -423,56 +423,56 @@ handle_init(void *cls,
423 unsigned int cnt; 423 unsigned int cnt;
424 424
425 if (NULL != GST_context) 425 if (NULL != GST_context)
426 { 426 {
427 LOG_DEBUG("We are being connected to laterally\n"); 427 LOG_DEBUG ("We are being connected to laterally\n");
428 GNUNET_SERVICE_client_continue(client); 428 GNUNET_SERVICE_client_continue (client);
429 return; 429 return;
430 } 430 }
431 controller_hostname = (const char *)&msg[1]; 431 controller_hostname = (const char *) &msg[1];
432 ss_str = NULL; 432 ss_str = NULL;
433 ss = NULL; 433 ss = NULL;
434 if (GNUNET_OK == 434 if (GNUNET_OK ==
435 GNUNET_CONFIGURATION_get_value_string(GST_config, 435 GNUNET_CONFIGURATION_get_value_string (GST_config,
436 "TESTBED", 436 "TESTBED",
437 "SHARED_SERVICES", 437 "SHARED_SERVICES",
438 &ss_str)) 438 &ss_str))
439 { 439 {
440 ss = parse_shared_services(ss_str, 440 ss = parse_shared_services (ss_str,
441 GST_config); 441 GST_config);
442 GNUNET_free(ss_str); 442 GNUNET_free (ss_str);
443 ss_str = NULL; 443 ss_str = NULL;
444 } 444 }
445 GST_context = GNUNET_new(struct Context); 445 GST_context = GNUNET_new (struct Context);
446 GST_context->client = client; 446 GST_context->client = client;
447 GST_context->host_id = ntohl(msg->host_id); 447 GST_context->host_id = ntohl (msg->host_id);
448 GST_context->master_ip = GNUNET_strdup(controller_hostname); 448 GST_context->master_ip = GNUNET_strdup (controller_hostname);
449 LOG_DEBUG("Our IP: %s\n", 449 LOG_DEBUG ("Our IP: %s\n",
450 GST_context->master_ip); 450 GST_context->master_ip);
451 GST_context->system 451 GST_context->system
452 = GNUNET_TESTING_system_create("testbed", 452 = GNUNET_TESTING_system_create ("testbed",
453 GST_context->master_ip, 453 GST_context->master_ip,
454 hostname, 454 hostname,
455 ss); 455 ss);
456 if (NULL != ss) 456 if (NULL != ss)
457 {
458 for (cnt = 0; NULL != ss[cnt].service; cnt++)
457 { 459 {
458 for (cnt = 0; NULL != ss[cnt].service; cnt++) 460 ss_str = (char *) ss[cnt].service;
459 { 461 GNUNET_free (ss_str);
460 ss_str = (char *)ss[cnt].service;
461 GNUNET_free(ss_str);
462 }
463 GNUNET_free(ss);
464 ss = NULL;
465 } 462 }
463 GNUNET_free (ss);
464 ss = NULL;
465 }
466 host = 466 host =
467 GNUNET_TESTBED_host_create_with_id(GST_context->host_id, 467 GNUNET_TESTBED_host_create_with_id (GST_context->host_id,
468 GST_context->master_ip, 468 GST_context->master_ip,
469 NULL, 469 NULL,
470 GST_config, 470 GST_config,
471 0); 471 0);
472 host_list_add(host); 472 host_list_add (host);
473 LOG_DEBUG("Created master context with host ID: %u\n", 473 LOG_DEBUG ("Created master context with host ID: %u\n",
474 GST_context->host_id); 474 GST_context->host_id);
475 GNUNET_SERVICE_client_continue(client); 475 GNUNET_SERVICE_client_continue (client);
476} 476}
477 477
478 478
@@ -484,29 +484,30 @@ handle_init(void *cls,
484 * @return #GNUNET_OK if @a message is well-formed 484 * @return #GNUNET_OK if @a message is well-formed
485 */ 485 */
486static int 486static int
487check_add_host(void *cls, 487check_add_host (void *cls,
488 const struct GNUNET_TESTBED_AddHostMessage *msg) 488 const struct GNUNET_TESTBED_AddHostMessage *msg)
489{ 489{
490 uint16_t username_length; 490 uint16_t username_length;
491 uint16_t hostname_length; 491 uint16_t hostname_length;
492 uint16_t msize; 492 uint16_t msize;
493 493
494 msize = ntohs(msg->header.size) - sizeof(struct GNUNET_TESTBED_AddHostMessage); 494 msize = ntohs (msg->header.size) - sizeof(struct
495 username_length = ntohs(msg->username_length); 495 GNUNET_TESTBED_AddHostMessage);
496 hostname_length = ntohs(msg->hostname_length); 496 username_length = ntohs (msg->username_length);
497 hostname_length = ntohs (msg->hostname_length);
497 /* msg must contain hostname */ 498 /* msg must contain hostname */
498 if ((msize <= username_length) || 499 if ((msize <= username_length) ||
499 (0 == hostname_length)) 500 (0 == hostname_length))
500 { 501 {
501 GNUNET_break(0); 502 GNUNET_break (0);
502 return GNUNET_SYSERR; 503 return GNUNET_SYSERR;
503 } 504 }
504 /* msg must contain configuration */ 505 /* msg must contain configuration */
505 if (msize <= username_length + hostname_length) 506 if (msize <= username_length + hostname_length)
506 { 507 {
507 GNUNET_break(0); 508 GNUNET_break (0);
508 return GNUNET_SYSERR; 509 return GNUNET_SYSERR;
509 } 510 }
510 return GNUNET_OK; 511 return GNUNET_OK;
511} 512}
512 513
@@ -518,8 +519,8 @@ check_add_host(void *cls,
518 * @param msg the actual message 519 * @param msg the actual message
519 */ 520 */
520static void 521static void
521handle_add_host(void *cls, 522handle_add_host (void *cls,
522 const struct GNUNET_TESTBED_AddHostMessage *msg) 523 const struct GNUNET_TESTBED_AddHostMessage *msg)
523{ 524{
524 struct GNUNET_SERVICE_Client *client = cls; 525 struct GNUNET_SERVICE_Client *client = cls;
525 struct GNUNET_TESTBED_Host *host; 526 struct GNUNET_TESTBED_Host *host;
@@ -534,77 +535,77 @@ handle_add_host(void *cls,
534 uint16_t hostname_length; 535 uint16_t hostname_length;
535 struct GNUNET_MQ_Envelope *env; 536 struct GNUNET_MQ_Envelope *env;
536 537
537 username_length = ntohs(msg->username_length); 538 username_length = ntohs (msg->username_length);
538 hostname_length = ntohs(msg->hostname_length); 539 hostname_length = ntohs (msg->hostname_length);
539 username = NULL; 540 username = NULL;
540 hostname = NULL; 541 hostname = NULL;
541 ptr = &msg[1]; 542 ptr = &msg[1];
542 if (0 != username_length) 543 if (0 != username_length)
543 { 544 {
544 username = GNUNET_malloc(username_length + 1); 545 username = GNUNET_malloc (username_length + 1);
545 GNUNET_strlcpy(username, ptr, username_length + 1); 546 GNUNET_strlcpy (username, ptr, username_length + 1);
546 ptr += username_length; 547 ptr += username_length;
547 } 548 }
548 hostname = GNUNET_malloc(hostname_length + 1); 549 hostname = GNUNET_malloc (hostname_length + 1);
549 GNUNET_strlcpy(hostname, ptr, hostname_length + 1); 550 GNUNET_strlcpy (hostname, ptr, hostname_length + 1);
550 if (NULL == (host_cfg = GNUNET_TESTBED_extract_config_(&msg->header))) 551 if (NULL == (host_cfg = GNUNET_TESTBED_extract_config_ (&msg->header)))
551 { 552 {
552 GNUNET_free_non_null(username); 553 GNUNET_free_non_null (username);
553 GNUNET_free_non_null(hostname); 554 GNUNET_free_non_null (hostname);
554 GNUNET_break_op(0); 555 GNUNET_break_op (0);
555 GNUNET_SERVICE_client_drop(client); 556 GNUNET_SERVICE_client_drop (client);
556 return; 557 return;
557 } 558 }
558 host_id = ntohl(msg->host_id); 559 host_id = ntohl (msg->host_id);
559 LOG_DEBUG("Received ADDHOST %u message\n", host_id); 560 LOG_DEBUG ("Received ADDHOST %u message\n", host_id);
560 LOG_DEBUG("-------host id: %u\n", host_id); 561 LOG_DEBUG ("-------host id: %u\n", host_id);
561 LOG_DEBUG("-------hostname: %s\n", hostname); 562 LOG_DEBUG ("-------hostname: %s\n", hostname);
562 if (NULL != username) 563 if (NULL != username)
563 LOG_DEBUG("-------username: %s\n", username); 564 LOG_DEBUG ("-------username: %s\n", username);
564 else 565 else
565 LOG_DEBUG("-------username: <not given>\n"); 566 LOG_DEBUG ("-------username: <not given>\n");
566 LOG_DEBUG("-------ssh port: %u\n", ntohs(msg->ssh_port)); 567 LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
567 host = GNUNET_TESTBED_host_create_with_id(host_id, 568 host = GNUNET_TESTBED_host_create_with_id (host_id,
568 hostname, 569 hostname,
569 username, 570 username,
570 host_cfg, 571 host_cfg,
571 ntohs(msg->ssh_port)); 572 ntohs (msg->ssh_port));
572 GNUNET_free_non_null(username); 573 GNUNET_free_non_null (username);
573 GNUNET_free(hostname); 574 GNUNET_free (hostname);
574 GNUNET_CONFIGURATION_destroy(host_cfg); 575 GNUNET_CONFIGURATION_destroy (host_cfg);
575 if (NULL == host) 576 if (NULL == host)
576 { 577 {
577 GNUNET_break_op(0); 578 GNUNET_break_op (0);
578 GNUNET_SERVICE_client_drop(client); 579 GNUNET_SERVICE_client_drop (client);
579 return; 580 return;
580 } 581 }
581 if (GNUNET_OK != host_list_add(host)) 582 if (GNUNET_OK != host_list_add (host))
582 { 583 {
583 /* We are unable to add a host */ 584 /* We are unable to add a host */
584 emsg = "A host exists with given host-id"; 585 emsg = "A host exists with given host-id";
585 LOG_DEBUG("%s: %u", 586 LOG_DEBUG ("%s: %u",
586 emsg, 587 emsg,
587 host_id); 588 host_id);
588 GNUNET_TESTBED_host_destroy(host); 589 GNUNET_TESTBED_host_destroy (host);
589 env = GNUNET_MQ_msg_extra(reply, 590 env = GNUNET_MQ_msg_extra (reply,
590 strlen(emsg) + 1, 591 strlen (emsg) + 1,
591 GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); 592 GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS);
592 GNUNET_memcpy(&reply[1], 593 GNUNET_memcpy (&reply[1],
593 emsg, 594 emsg,
594 strlen(emsg) + 1); 595 strlen (emsg) + 1);
595 } 596 }
596 else 597 else
597 { 598 {
598 LOG_DEBUG("Added host %u at %u\n", 599 LOG_DEBUG ("Added host %u at %u\n",
599 host_id, 600 host_id,
600 GST_context->host_id); 601 GST_context->host_id);
601 env = GNUNET_MQ_msg(reply, 602 env = GNUNET_MQ_msg (reply,
602 GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); 603 GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS);
603 } 604 }
604 reply->host_id = htonl(host_id); 605 reply->host_id = htonl (host_id);
605 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), 606 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
606 env); 607 env);
607 GNUNET_SERVICE_client_continue(client); 608 GNUNET_SERVICE_client_continue (client);
608} 609}
609 610
610 611
@@ -615,8 +616,9 @@ handle_add_host(void *cls,
615 * @param msg the actual message 616 * @param msg the actual message
616 */ 617 */
617static void 618static void
618handle_slave_get_config(void *cls, 619handle_slave_get_config (void *cls,
619 const struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg) 620 const struct
621 GNUNET_TESTBED_SlaveGetConfigurationMessage *msg)
620{ 622{
621 struct GNUNET_SERVICE_Client *client = cls; 623 struct GNUNET_SERVICE_Client *client = cls;
622 struct Slave *slave; 624 struct Slave *slave;
@@ -630,42 +632,45 @@ handle_slave_get_config(void *cls,
630 uint64_t op_id; 632 uint64_t op_id;
631 uint32_t slave_id; 633 uint32_t slave_id;
632 634
633 slave_id = ntohl(msg->slave_id); 635 slave_id = ntohl (msg->slave_id);
634 op_id = GNUNET_ntohll(msg->operation_id); 636 op_id = GNUNET_ntohll (msg->operation_id);
635 if ((GST_slave_list_size <= slave_id) || 637 if ((GST_slave_list_size <= slave_id) ||
636 (NULL == GST_slave_list[slave_id])) 638 (NULL == GST_slave_list[slave_id]))
637 { 639 {
638 /* FIXME: Add forwardings for this type of message here.. */ 640 /* FIXME: Add forwardings for this type of message here.. */
639 GST_send_operation_fail_msg(client, 641 GST_send_operation_fail_msg (client,
640 op_id, 642 op_id,
641 "Slave not found"); 643 "Slave not found");
642 GNUNET_SERVICE_client_continue(client); 644 GNUNET_SERVICE_client_continue (client);
643 return; 645 return;
644 } 646 }
645 slave = GST_slave_list[slave_id]; 647 slave = GST_slave_list[slave_id];
646 GNUNET_assert(NULL != (cfg = GNUNET_TESTBED_host_get_cfg_(GST_host_list[slave->host_id]))); 648 GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (
647 config = GNUNET_CONFIGURATION_serialize(cfg, 649 GST_host_list[slave->host_id])));
648 &config_size); 650 config = GNUNET_CONFIGURATION_serialize (cfg,
651 &config_size);
649 /* FIXME: maybe we want to transmit the delta to the default here? */ 652 /* FIXME: maybe we want to transmit the delta to the default here? */
650 xconfig_size = GNUNET_TESTBED_compress_config_(config, 653 xconfig_size = GNUNET_TESTBED_compress_config_ (config,
651 config_size, 654 config_size,
652 &xconfig); 655 &xconfig);
653 GNUNET_free(config); 656 GNUNET_free (config);
654 GNUNET_assert(xconfig_size + sizeof(struct GNUNET_TESTBED_SlaveConfiguration) <= UINT16_MAX); 657 GNUNET_assert (xconfig_size + sizeof(struct
655 GNUNET_assert(xconfig_size <= UINT16_MAX); 658 GNUNET_TESTBED_SlaveConfiguration) <=
656 env = GNUNET_MQ_msg_extra(reply, 659 UINT16_MAX);
657 xconfig_size, 660 GNUNET_assert (xconfig_size <= UINT16_MAX);
658 GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION); 661 env = GNUNET_MQ_msg_extra (reply,
662 xconfig_size,
663 GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION);
659 reply->slave_id = msg->slave_id; 664 reply->slave_id = msg->slave_id;
660 reply->operation_id = msg->operation_id; 665 reply->operation_id = msg->operation_id;
661 reply->config_size = htons((uint16_t)config_size); 666 reply->config_size = htons ((uint16_t) config_size);
662 GNUNET_memcpy(&reply[1], 667 GNUNET_memcpy (&reply[1],
663 xconfig, 668 xconfig,
664 xconfig_size); 669 xconfig_size);
665 GNUNET_free(xconfig); 670 GNUNET_free (xconfig);
666 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), 671 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
667 env); 672 env);
668 GNUNET_SERVICE_client_continue(client); 673 GNUNET_SERVICE_client_continue (client);
669} 674}
670 675
671 676
@@ -673,52 +678,52 @@ handle_slave_get_config(void *cls,
673 * Clears the forwarded operations queue 678 * Clears the forwarded operations queue
674 */ 679 */
675void 680void
676GST_clear_fopcq() 681GST_clear_fopcq ()
677{ 682{
678 struct ForwardedOperationContext *fopc; 683 struct ForwardedOperationContext *fopc;
679 684
680 while (NULL != (fopc = fopcq_head)) 685 while (NULL != (fopc = fopcq_head))
686 {
687 GNUNET_CONTAINER_DLL_remove (fopcq_head,
688 fopcq_tail,
689 fopc);
690 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
691 if (NULL != fopc->timeout_task)
692 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
693 switch (fopc->type)
681 { 694 {
682 GNUNET_CONTAINER_DLL_remove(fopcq_head, 695 case OP_PEER_CREATE:
683 fopcq_tail, 696 GNUNET_free (fopc->cls);
684 fopc); 697 break;
685 GNUNET_TESTBED_forward_operation_msg_cancel_(fopc->opc); 698
686 if (NULL != fopc->timeout_task) 699 case OP_SHUTDOWN_PEERS:
687 GNUNET_SCHEDULER_cancel(fopc->timeout_task); 700 {
688 switch (fopc->type) 701 struct HandlerContext_ShutdownPeers *hc = fopc->cls;
689 { 702
690 case OP_PEER_CREATE: 703 GNUNET_assert (0 < hc->nslaves);
691 GNUNET_free(fopc->cls); 704 hc->nslaves--;
692 break; 705 if (0 == hc->nslaves)
693 706 GNUNET_free (hc);
694 case OP_SHUTDOWN_PEERS: 707 }
695 { 708 break;
696 struct HandlerContext_ShutdownPeers *hc = fopc->cls; 709
697 710 case OP_PEER_START:
698 GNUNET_assert(0 < hc->nslaves); 711 case OP_PEER_STOP:
699 hc->nslaves--; 712 case OP_PEER_DESTROY:
700 if (0 == hc->nslaves) 713 case OP_PEER_INFO:
701 GNUNET_free(hc); 714 case OP_OVERLAY_CONNECT:
702 } 715 case OP_LINK_CONTROLLERS:
703 break; 716 case OP_GET_SLAVE_CONFIG:
704 717 case OP_MANAGE_SERVICE:
705 case OP_PEER_START: 718 case OP_PEER_RECONFIGURE:
706 case OP_PEER_STOP: 719 break;
707 case OP_PEER_DESTROY: 720
708 case OP_PEER_INFO: 721 case OP_FORWARDED:
709 case OP_OVERLAY_CONNECT: 722 GNUNET_assert (0);
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 } 723 }
724 ;
725 GNUNET_free (fopc);
726 }
722} 727}
723 728
724 729
@@ -728,49 +733,49 @@ GST_clear_fopcq()
728 * @param cls NULL 733 * @param cls NULL
729 */ 734 */
730static void 735static void
731shutdown_task(void *cls) 736shutdown_task (void *cls)
732{ 737{
733 uint32_t id; 738 uint32_t id;
734 739
735 LOG_DEBUG("Shutting down testbed service\n"); 740 LOG_DEBUG ("Shutting down testbed service\n");
736 /* cleanup any remaining forwarded operations */ 741 /* cleanup any remaining forwarded operations */
737 GST_clear_fopcq(); 742 GST_clear_fopcq ();
738 GST_free_lcf(); 743 GST_free_lcf ();
739 GST_free_mctxq(); 744 GST_free_mctxq ();
740 GST_free_occq(); 745 GST_free_occq ();
741 GST_free_roccq(); 746 GST_free_roccq ();
742 GST_free_nccq(); 747 GST_free_nccq ();
743 GST_neighbour_list_clean(); 748 GST_neighbour_list_clean ();
744 GST_free_prcq(); 749 GST_free_prcq ();
745 /* Clear peer list */ 750 /* Clear peer list */
746 GST_destroy_peers(); 751 GST_destroy_peers ();
747 /* Clear route list */ 752 /* Clear route list */
748 GST_route_list_clear(); 753 GST_route_list_clear ();
749 /* Clear GST_slave_list */ 754 /* Clear GST_slave_list */
750 GST_slave_list_clear(); 755 GST_slave_list_clear ();
751 /* Clear host list */ 756 /* Clear host list */
752 for (id = 0; id < GST_host_list_size; id++) 757 for (id = 0; id < GST_host_list_size; id++)
753 if (NULL != GST_host_list[id]) 758 if (NULL != GST_host_list[id])
754 GNUNET_TESTBED_host_destroy(GST_host_list[id]); 759 GNUNET_TESTBED_host_destroy (GST_host_list[id]);
755 GNUNET_free_non_null(GST_host_list); 760 GNUNET_free_non_null (GST_host_list);
756 if (NULL != GST_context) 761 if (NULL != GST_context)
757 { 762 {
758 GNUNET_free_non_null(GST_context->master_ip); 763 GNUNET_free_non_null (GST_context->master_ip);
759 if (NULL != GST_context->system) 764 if (NULL != GST_context->system)
760 GNUNET_TESTING_system_destroy(GST_context->system, 765 GNUNET_TESTING_system_destroy (GST_context->system,
761 GNUNET_YES); 766 GNUNET_YES);
762 GNUNET_free(GST_context); 767 GNUNET_free (GST_context);
763 GST_context = NULL; 768 GST_context = NULL;
764 } 769 }
765 GNUNET_free_non_null(hostname); 770 GNUNET_free_non_null (hostname);
766 /* Free hello cache */ 771 /* Free hello cache */
767 GST_cache_clear(); 772 GST_cache_clear ();
768 GST_connection_pool_destroy(); 773 GST_connection_pool_destroy ();
769 GNUNET_TESTBED_operation_queue_destroy_(GST_opq_openfds); 774 GNUNET_TESTBED_operation_queue_destroy_ (GST_opq_openfds);
770 GST_opq_openfds = NULL; 775 GST_opq_openfds = NULL;
771 GST_stats_destroy(); 776 GST_stats_destroy ();
772 GST_barriers_destroy(); 777 GST_barriers_destroy ();
773 GNUNET_CONFIGURATION_destroy(GST_config); 778 GNUNET_CONFIGURATION_destroy (GST_config);
774} 779}
775 780
776 781
@@ -783,9 +788,9 @@ shutdown_task(void *cls)
783 * @return @a client 788 * @return @a client
784 */ 789 */
785static void * 790static void *
786client_connect_cb(void *cls, 791client_connect_cb (void *cls,
787 struct GNUNET_SERVICE_Client *client, 792 struct GNUNET_SERVICE_Client *client,
788 struct GNUNET_MQ_Handle *mq) 793 struct GNUNET_MQ_Handle *mq)
789{ 794{
790 return client; 795 return client;
791} 796}
@@ -799,41 +804,41 @@ client_connect_cb(void *cls,
799 * @param app_ctx should match @a client 804 * @param app_ctx should match @a client
800 */ 805 */
801static void 806static void
802client_disconnect_cb(void *cls, 807client_disconnect_cb (void *cls,
803 struct GNUNET_SERVICE_Client *client, 808 struct GNUNET_SERVICE_Client *client,
804 void *app_ctx) 809 void *app_ctx)
805{ 810{
806 struct ForwardedOperationContext *fopc; 811 struct ForwardedOperationContext *fopc;
807 struct ForwardedOperationContext *fopcn; 812 struct ForwardedOperationContext *fopcn;
808 813
809 GNUNET_assert(client == app_ctx); 814 GNUNET_assert (client == app_ctx);
810 GST_notify_client_disconnect_oc(client); 815 GST_notify_client_disconnect_oc (client);
811 GST_link_notify_disconnect(client); 816 GST_link_notify_disconnect (client);
812 GST_notify_client_disconnect_peers(client); 817 GST_notify_client_disconnect_peers (client);
813 for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) 818 for (fopc = fopcq_head; NULL != fopc; fopc = fopcn)
819 {
820 fopcn = fopc->next;
821 if (fopc->client == client)
814 { 822 {
815 fopcn = fopc->next; 823 /* handle as if it were a timeout */
816 if (fopc->client == client) 824 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
817 { 825 GST_forwarded_operation_timeout (fopc);
818 /* handle as if it were a timeout */
819 GNUNET_SCHEDULER_cancel(fopc->timeout_task);
820 GST_forwarded_operation_timeout(fopc);
821 }
822 } 826 }
827 }
823 if (NULL == GST_context) 828 if (NULL == GST_context)
824 return; 829 return;
825 if (client == GST_context->client) 830 if (client == GST_context->client)
826 { 831 {
827 LOG(GNUNET_ERROR_TYPE_DEBUG, 832 LOG (GNUNET_ERROR_TYPE_DEBUG,
828 "Master client disconnected\n"); 833 "Master client disconnected\n");
829 GST_context->client = NULL; 834 GST_context->client = NULL;
830 /* should not be needed as we're terminated by failure to read 835 /* should not be needed as we're terminated by failure to read
831 * from stdin, but if stdin fails for some reason, this shouldn't 836 * from stdin, but if stdin fails for some reason, this shouldn't
832 * hurt for now --- might need to revise this later if we ever 837 * hurt for now --- might need to revise this later if we ever
833 * decide that master connections might be temporarily down 838 * decide that master connections might be temporarily down
834 * for some reason */ 839 * for some reason */
835 //GNUNET_SCHEDULER_shutdown (); 840 // GNUNET_SCHEDULER_shutdown ();
836 } 841 }
837} 842}
838 843
839 844
@@ -845,54 +850,55 @@ client_disconnect_cb(void *cls,
845 * @param service the initialized server 850 * @param service the initialized server
846 */ 851 */
847static void 852static void
848testbed_run(void *cls, 853testbed_run (void *cls,
849 const struct GNUNET_CONFIGURATION_Handle *cfg, 854 const struct GNUNET_CONFIGURATION_Handle *cfg,
850 struct GNUNET_SERVICE_Handle *service) 855 struct GNUNET_SERVICE_Handle *service)
851{ 856{
852 char *logfile; 857 char *logfile;
853 unsigned long long num; 858 unsigned long long num;
854 859
855 LOG_DEBUG("Starting testbed\n"); 860 LOG_DEBUG ("Starting testbed\n");
856 if (GNUNET_OK == 861 if (GNUNET_OK ==
857 GNUNET_CONFIGURATION_get_value_filename(cfg, "TESTBED", "LOG_FILE", 862 GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED", "LOG_FILE",
858 &logfile)) 863 &logfile))
859 { 864 {
860 GNUNET_break(GNUNET_OK == 865 GNUNET_break (GNUNET_OK ==
861 GNUNET_log_setup("testbed", 866 GNUNET_log_setup ("testbed",
862 "DEBUG", 867 "DEBUG",
863 logfile)); 868 logfile));
864 GNUNET_free(logfile); 869 GNUNET_free (logfile);
865 } 870 }
866 GNUNET_assert(GNUNET_OK == 871 GNUNET_assert (GNUNET_OK ==
867 GNUNET_CONFIGURATION_get_value_number(cfg, 872 GNUNET_CONFIGURATION_get_value_number (cfg,
868 "testbed", 873 "testbed",
869 "CACHE_SIZE", 874 "CACHE_SIZE",
870 &num)); 875 &num));
871 GST_cache_init((unsigned int)num); 876 GST_cache_init ((unsigned int) num);
872 GST_connection_pool_init((unsigned int)num); 877 GST_connection_pool_init ((unsigned int) num);
873 GNUNET_assert(GNUNET_OK == 878 GNUNET_assert (GNUNET_OK ==
874 GNUNET_CONFIGURATION_get_value_number(cfg, 879 GNUNET_CONFIGURATION_get_value_number (cfg,
875 "testbed", 880 "testbed",
876 "MAX_OPEN_FDS", 881 "MAX_OPEN_FDS",
877 &num)); 882 &num));
878 GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_FIXED, 883 GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_ (
879 (unsigned int)num); 884 OPERATION_QUEUE_TYPE_FIXED,
880 GNUNET_assert(GNUNET_OK == 885 (unsigned int) num);
881 GNUNET_CONFIGURATION_get_value_time(cfg, 886 GNUNET_assert (GNUNET_OK ==
882 "testbed", 887 GNUNET_CONFIGURATION_get_value_time (cfg,
883 "OPERATION_TIMEOUT",
884 &GST_timeout));
885 GNUNET_assert(GNUNET_OK ==
886 GNUNET_CONFIGURATION_get_value_string(cfg,
887 "testbed", 888 "testbed",
888 "HOSTNAME", 889 "OPERATION_TIMEOUT",
889 &hostname)); 890 &GST_timeout));
890 GST_config = GNUNET_CONFIGURATION_dup(cfg); 891 GNUNET_assert (GNUNET_OK ==
891 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, 892 GNUNET_CONFIGURATION_get_value_string (cfg,
892 NULL); 893 "testbed",
893 LOG_DEBUG("Testbed startup complete\n"); 894 "HOSTNAME",
894 GST_stats_init(GST_config); 895 &hostname));
895 GST_barriers_init(GST_config); 896 GST_config = GNUNET_CONFIGURATION_dup (cfg);
897 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
898 NULL);
899 LOG_DEBUG ("Testbed startup complete\n");
900 GST_stats_init (GST_config);
901 GST_barriers_init (GST_config);
896} 902}
897 903
898 904
@@ -906,75 +912,75 @@ GNUNET_SERVICE_MAIN
906 &client_connect_cb, 912 &client_connect_cb,
907 &client_disconnect_cb, 913 &client_disconnect_cb,
908 NULL, 914 NULL,
909 GNUNET_MQ_hd_var_size(init, 915 GNUNET_MQ_hd_var_size (init,
910 GNUNET_MESSAGE_TYPE_TESTBED_INIT, 916 GNUNET_MESSAGE_TYPE_TESTBED_INIT,
911 struct GNUNET_TESTBED_InitMessage, 917 struct GNUNET_TESTBED_InitMessage,
912 NULL), 918 NULL),
913 GNUNET_MQ_hd_var_size(add_host, 919 GNUNET_MQ_hd_var_size (add_host,
914 GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 920 GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST,
915 struct GNUNET_TESTBED_AddHostMessage, 921 struct GNUNET_TESTBED_AddHostMessage,
916 NULL), 922 NULL),
917 GNUNET_MQ_hd_fixed_size(slave_get_config, 923 GNUNET_MQ_hd_fixed_size (slave_get_config,
918 GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION, 924 GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION,
919 struct GNUNET_TESTBED_SlaveGetConfigurationMessage, 925 struct GNUNET_TESTBED_SlaveGetConfigurationMessage,
920 NULL), 926 NULL),
921 GNUNET_MQ_hd_fixed_size(link_controllers, 927 GNUNET_MQ_hd_fixed_size (link_controllers,
922 GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, 928 GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS,
923 struct GNUNET_TESTBED_ControllerLinkRequest, 929 struct GNUNET_TESTBED_ControllerLinkRequest,
924 NULL), 930 NULL),
925 GNUNET_MQ_hd_var_size(remote_overlay_connect, 931 GNUNET_MQ_hd_var_size (remote_overlay_connect,
926 GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT, 932 GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT,
927 struct GNUNET_TESTBED_RemoteOverlayConnectMessage, 933 struct GNUNET_TESTBED_RemoteOverlayConnectMessage,
928 NULL), 934 NULL),
929 GNUNET_MQ_hd_fixed_size(overlay_connect, 935 GNUNET_MQ_hd_fixed_size (overlay_connect,
930 GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT, 936 GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT,
931 struct GNUNET_TESTBED_OverlayConnectMessage, 937 struct GNUNET_TESTBED_OverlayConnectMessage,
932 NULL), 938 NULL),
933 GNUNET_MQ_hd_var_size(peer_create, 939 GNUNET_MQ_hd_var_size (peer_create,
934 GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER, 940 GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER,
935 struct GNUNET_TESTBED_PeerCreateMessage, 941 struct GNUNET_TESTBED_PeerCreateMessage,
936 NULL), 942 NULL),
937 GNUNET_MQ_hd_fixed_size(peer_destroy, 943 GNUNET_MQ_hd_fixed_size (peer_destroy,
938 GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER, 944 GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER,
939 struct GNUNET_TESTBED_PeerDestroyMessage, 945 struct GNUNET_TESTBED_PeerDestroyMessage,
940 NULL), 946 NULL),
941 GNUNET_MQ_hd_fixed_size(peer_start, 947 GNUNET_MQ_hd_fixed_size (peer_start,
942 GNUNET_MESSAGE_TYPE_TESTBED_START_PEER, 948 GNUNET_MESSAGE_TYPE_TESTBED_START_PEER,
943 struct GNUNET_TESTBED_PeerStartMessage, 949 struct GNUNET_TESTBED_PeerStartMessage,
944 NULL), 950 NULL),
945 GNUNET_MQ_hd_fixed_size(peer_stop, 951 GNUNET_MQ_hd_fixed_size (peer_stop,
946 GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER, 952 GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER,
947 struct GNUNET_TESTBED_PeerStopMessage, 953 struct GNUNET_TESTBED_PeerStopMessage,
948 NULL), 954 NULL),
949 GNUNET_MQ_hd_fixed_size(peer_get_config, 955 GNUNET_MQ_hd_fixed_size (peer_get_config,
950 GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION, 956 GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION,
951 struct GNUNET_TESTBED_PeerGetConfigurationMessage, 957 struct GNUNET_TESTBED_PeerGetConfigurationMessage,
952 NULL), 958 NULL),
953 GNUNET_MQ_hd_var_size(manage_peer_service, 959 GNUNET_MQ_hd_var_size (manage_peer_service,
954 GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE, 960 GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE,
955 struct GNUNET_TESTBED_ManagePeerServiceMessage, 961 struct GNUNET_TESTBED_ManagePeerServiceMessage,
956 NULL), 962 NULL),
957 GNUNET_MQ_hd_fixed_size(shutdown_peers, 963 GNUNET_MQ_hd_fixed_size (shutdown_peers,
958 GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS, 964 GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS,
959 struct GNUNET_TESTBED_ShutdownPeersMessage, 965 struct GNUNET_TESTBED_ShutdownPeersMessage,
960 NULL), 966 NULL),
961 GNUNET_MQ_hd_var_size(peer_reconfigure, 967 GNUNET_MQ_hd_var_size (peer_reconfigure,
962 GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER, 968 GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER,
963 struct GNUNET_TESTBED_PeerReconfigureMessage, 969 struct GNUNET_TESTBED_PeerReconfigureMessage,
964 NULL), 970 NULL),
965 GNUNET_MQ_hd_var_size(barrier_init, 971 GNUNET_MQ_hd_var_size (barrier_init,
966 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT, 972 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT,
967 struct GNUNET_TESTBED_BarrierInit, 973 struct GNUNET_TESTBED_BarrierInit,
968 NULL), 974 NULL),
969 GNUNET_MQ_hd_var_size(barrier_cancel, 975 GNUNET_MQ_hd_var_size (barrier_cancel,
970 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL, 976 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL,
971 struct GNUNET_TESTBED_BarrierCancel, 977 struct GNUNET_TESTBED_BarrierCancel,
972 NULL), 978 NULL),
973 GNUNET_MQ_hd_var_size(barrier_status, 979 GNUNET_MQ_hd_var_size (barrier_status,
974 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, 980 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS,
975 struct GNUNET_TESTBED_BarrierStatusMsg, 981 struct GNUNET_TESTBED_BarrierStatusMsg,
976 NULL), 982 NULL),
977 GNUNET_MQ_handler_end()); 983 GNUNET_MQ_handler_end ());
978 984
979 985
980/* end of gnunet-service-testbed.c */ 986/* end of gnunet-service-testbed.c */
diff --git a/src/testbed/gnunet-service-testbed.h b/src/testbed/gnunet-service-testbed.h
index d68f8a3e4..032dd54ed 100644
--- a/src/testbed/gnunet-service-testbed.h
+++ b/src/testbed/gnunet-service-testbed.h
@@ -42,13 +42,13 @@
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,7 +59,8 @@
59/** 59/**
60 * A routing entry 60 * A routing entry
61 */ 61 */
62struct Route { 62struct Route
63{
63 /** 64 /**
64 * destination host 65 * destination host
65 */ 66 */
@@ -75,7 +76,8 @@ struct Route {
75/** 76/**
76 * Context information for operations forwarded to subcontrollers 77 * Context information for operations forwarded to subcontrollers
77 */ 78 */
78struct ForwardedOperationContext { 79struct ForwardedOperationContext
80{
79 /** 81 /**
80 * The next pointer for DLL 82 * The next pointer for DLL
81 */ 83 */
@@ -104,7 +106,7 @@ struct ForwardedOperationContext {
104 /** 106 /**
105 * Task ID for the timeout task 107 * Task ID for the timeout task
106 */ 108 */
107 struct GNUNET_SCHEDULER_Task * timeout_task; 109 struct GNUNET_SCHEDULER_Task *timeout_task;
108 110
109 /** 111 /**
110 * The id of the operation that has been forwarded 112 * The id of the operation that has been forwarded
@@ -121,7 +123,8 @@ struct ForwardedOperationContext {
121/** 123/**
122 * A DLL of host registrations to be made 124 * A DLL of host registrations to be made
123 */ 125 */
124struct HostRegistration { 126struct HostRegistration
127{
125 /** 128 /**
126 * next registration in the DLL 129 * next registration in the DLL
127 */ 130 */
@@ -152,7 +155,8 @@ struct HostRegistration {
152/** 155/**
153 * Context information used while linking controllers 156 * Context information used while linking controllers
154 */ 157 */
155struct LinkControllersContext { 158struct LinkControllersContext
159{
156 /** 160 /**
157 * The client which initiated the link controller operation 161 * The client which initiated the link controller operation
158 */ 162 */
@@ -168,9 +172,12 @@ struct LinkControllersContext {
168/** 172/**
169 * A peer 173 * A peer
170 */ 174 */
171struct Peer { 175struct Peer
172 union { 176{
173 struct { 177 union
178 {
179 struct
180 {
174 /** 181 /**
175 * The peer handle from testing API 182 * The peer handle from testing API
176 */ 183 */
@@ -188,7 +195,8 @@ struct Peer {
188 int is_running; 195 int is_running;
189 } local; 196 } local;
190 197
191 struct { 198 struct
199 {
192 /** 200 /**
193 * The slave this peer is started through 201 * The slave this peer is started through
194 */ 202 */
@@ -234,7 +242,8 @@ struct Peer {
234/** 242/**
235 * The main context information associated with the client which started us 243 * The main context information associated with the client which started us
236 */ 244 */
237struct Context { 245struct Context
246{
238 /** 247 /**
239 * The client handle associated with this context 248 * The client handle associated with this context
240 */ 249 */
@@ -260,7 +269,8 @@ struct Context {
260/** 269/**
261 * The structure for identifying a shared service 270 * The structure for identifying a shared service
262 */ 271 */
263struct SharedService { 272struct SharedService
273{
264 /** 274 /**
265 * The name of the shared service 275 * The name of the shared service
266 */ 276 */
@@ -285,7 +295,8 @@ struct RegisteredHostContext;
285 * Context information to used during operations which forward the overlay 295 * Context information to used during operations which forward the overlay
286 * connect message 296 * connect message
287 */ 297 */
288struct ForwardedOverlayConnectContext { 298struct ForwardedOverlayConnectContext
299{
289 /** 300 /**
290 * next ForwardedOverlayConnectContext in the DLL 301 * next ForwardedOverlayConnectContext in the DLL
291 */ 302 */
@@ -337,7 +348,8 @@ struct ForwardedOverlayConnectContext {
337 * This context information will be created for each host that is registered at 348 * This context information will be created for each host that is registered at
338 * slave controllers during overlay connects. 349 * slave controllers during overlay connects.
339 */ 350 */
340struct RegisteredHostContext { 351struct RegisteredHostContext
352{
341 /** 353 /**
342 * The host which is being registered 354 * The host which is being registered
343 */ 355 */
@@ -361,7 +373,8 @@ struct RegisteredHostContext {
361 /** 373 /**
362 * Enumeration of states for this context 374 * Enumeration of states for this context
363 */ 375 */
364 enum RHCState { 376 enum RHCState
377 {
365 /** 378 /**
366 * The initial state 379 * The initial state
367 */ 380 */
@@ -378,7 +391,8 @@ struct RegisteredHostContext {
378/** 391/**
379 * Context data for #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS handler 392 * Context data for #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS handler
380 */ 393 */
381struct HandlerContext_ShutdownPeers { 394struct HandlerContext_ShutdownPeers
395{
382 /** 396 /**
383 * The number of slave we expect to hear from since we forwarded the 397 * The number of slave we expect to hear from since we forwarded the
384 * #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS message to them 398 * #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS message to them
@@ -479,15 +493,15 @@ extern char *GST_stats_dir;
479 */ 493 */
480#define GST_array_grow_large_enough(ptr, size, accommodate_size) \ 494#define GST_array_grow_large_enough(ptr, size, accommodate_size) \
481 do \ 495 do \
482 { \ 496 { \
483 unsigned int growth_size; \ 497 unsigned int growth_size; \
484 GNUNET_assert(size <= accommodate_size); \ 498 GNUNET_assert (size <= accommodate_size); \
485 growth_size = size; \ 499 growth_size = size; \
486 while (growth_size <= accommodate_size) \ 500 while (growth_size <= accommodate_size) \
487 growth_size += LIST_GROW_STEP; \ 501 growth_size += LIST_GROW_STEP; \
488 GNUNET_array_grow (ptr, size, growth_size); \ 502 GNUNET_array_grow (ptr, size, growth_size); \
489 GNUNET_assert(size > accommodate_size); \ 503 GNUNET_assert (size > accommodate_size); \
490 } while (0) 504 } while (0)
491 505
492 506
493/** 507/**
@@ -496,14 +510,14 @@ extern char *GST_stats_dir;
496 * @param peer the peer structure to destroy 510 * @param peer the peer structure to destroy
497 */ 511 */
498void 512void
499GST_destroy_peer(struct Peer *peer); 513GST_destroy_peer (struct Peer *peer);
500 514
501 515
502/** 516/**
503 * Stops and destroys all peers 517 * Stops and destroys all peers
504 */ 518 */
505void 519void
506GST_destroy_peers(void); 520GST_destroy_peers (void);
507 521
508 522
509/** 523/**
@@ -515,7 +529,7 @@ GST_destroy_peers(void);
515 * is found 529 * is found
516 */ 530 */
517struct Route * 531struct Route *
518GST_find_dest_route(uint32_t host_id); 532GST_find_dest_route (uint32_t host_id);
519 533
520 534
521/** 535/**
@@ -525,8 +539,8 @@ GST_find_dest_route(uint32_t host_id);
525 * @param msg the actual message 539 * @param msg the actual message
526 */ 540 */
527void 541void
528handle_overlay_connect(void *cls, 542handle_overlay_connect (void *cls,
529 const struct GNUNET_TESTBED_OverlayConnectMessage *msg); 543 const struct GNUNET_TESTBED_OverlayConnectMessage *msg);
530 544
531 545
532/** 546/**
@@ -539,9 +553,9 @@ handle_overlay_connect(void *cls,
539 * @param host the host which has to be registered 553 * @param host the host which has to be registered
540 */ 554 */
541void 555void
542GST_queue_host_registration(struct Slave *slave, 556GST_queue_host_registration (struct Slave *slave,
543 GNUNET_TESTBED_HostRegistrationCompletion cb, 557 GNUNET_TESTBED_HostRegistrationCompletion cb,
544 void *cb_cls, struct GNUNET_TESTBED_Host *host); 558 void *cb_cls, struct GNUNET_TESTBED_Host *host);
545 559
546 560
547/** 561/**
@@ -551,8 +565,8 @@ GST_queue_host_registration(struct Slave *slave,
551 * @param msg the message to relay 565 * @param msg the message to relay
552 */ 566 */
553void 567void
554GST_forwarded_operation_reply_relay(void *cls, 568GST_forwarded_operation_reply_relay (void *cls,
555 const struct GNUNET_MessageHeader *msg); 569 const struct GNUNET_MessageHeader *msg);
556 570
557 571
558/** 572/**
@@ -562,14 +576,14 @@ GST_forwarded_operation_reply_relay(void *cls,
562 * @param tc the task context from scheduler 576 * @param tc the task context from scheduler
563 */ 577 */
564void 578void
565GST_forwarded_operation_timeout(void *cls); 579GST_forwarded_operation_timeout (void *cls);
566 580
567 581
568/** 582/**
569 * Clears the forwarded operations queue 583 * Clears the forwarded operations queue
570 */ 584 */
571void 585void
572GST_clear_fopcq(void); 586GST_clear_fopcq (void);
573 587
574 588
575/** 589/**
@@ -580,9 +594,9 @@ GST_clear_fopcq(void);
580 * @param emsg the error message; can be NULL 594 * @param emsg the error message; can be NULL
581 */ 595 */
582void 596void
583GST_send_operation_fail_msg(struct GNUNET_SERVICE_Client *client, 597GST_send_operation_fail_msg (struct GNUNET_SERVICE_Client *client,
584 uint64_t operation_id, 598 uint64_t operation_id,
585 const char *emsg); 599 const char *emsg);
586 600
587 601
588/** 602/**
@@ -591,7 +605,7 @@ GST_send_operation_fail_msg(struct GNUNET_SERVICE_Client *client,
591 * @param client the client that disconnected 605 * @param client the client that disconnected
592 */ 606 */
593void 607void
594GST_notify_client_disconnect_oc(struct GNUNET_SERVICE_Client *client); 608GST_notify_client_disconnect_oc (struct GNUNET_SERVICE_Client *client);
595 609
596 610
597/** 611/**
@@ -600,7 +614,7 @@ GST_notify_client_disconnect_oc(struct GNUNET_SERVICE_Client *client);
600 * @param client the client that disconnected 614 * @param client the client that disconnected
601 */ 615 */
602void 616void
603GST_notify_client_disconnect_peers(struct GNUNET_SERVICE_Client *client); 617GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client);
604 618
605 619
606/** 620/**
@@ -610,8 +624,8 @@ GST_notify_client_disconnect_peers(struct GNUNET_SERVICE_Client *client);
610 * @param operation_id the id of the operation which was successful 624 * @param operation_id the id of the operation which was successful
611 */ 625 */
612void 626void
613GST_send_operation_success_msg(struct GNUNET_SERVICE_Client *client, 627GST_send_operation_success_msg (struct GNUNET_SERVICE_Client *client,
614 uint64_t operation_id); 628 uint64_t operation_id);
615 629
616 630
617/** 631/**
@@ -622,8 +636,9 @@ GST_send_operation_success_msg(struct GNUNET_SERVICE_Client *client,
622 * @return #GNUNET_OK if @a msg is well-formed 636 * @return #GNUNET_OK if @a msg is well-formed
623 */ 637 */
624int 638int
625check_remote_overlay_connect(void *cls, 639check_remote_overlay_connect (void *cls,
626 const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg); 640 const struct
641 GNUNET_TESTBED_RemoteOverlayConnectMessage *msg);
627 642
628 643
629/** 644/**
@@ -633,8 +648,9 @@ check_remote_overlay_connect(void *cls,
633 * @param msg the actual message 648 * @param msg the actual message
634 */ 649 */
635void 650void
636handle_remote_overlay_connect(void *cls, 651handle_remote_overlay_connect (void *cls,
637 const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg); 652 const struct
653 GNUNET_TESTBED_RemoteOverlayConnectMessage *msg);
638 654
639 655
640/** 656/**
@@ -645,8 +661,8 @@ handle_remote_overlay_connect(void *cls,
645 * @return #GNUNET_OK if @a msg is well-formed 661 * @return #GNUNET_OK if @a msg is well-formed
646 */ 662 */
647int 663int
648check_peer_create(void *cls, 664check_peer_create (void *cls,
649 const struct GNUNET_TESTBED_PeerCreateMessage *msg); 665 const struct GNUNET_TESTBED_PeerCreateMessage *msg);
650 666
651 667
652/** 668/**
@@ -656,8 +672,8 @@ check_peer_create(void *cls,
656 * @param message the actual message 672 * @param message the actual message
657 */ 673 */
658void 674void
659handle_peer_create(void *cls, 675handle_peer_create (void *cls,
660 const struct GNUNET_TESTBED_PeerCreateMessage *msg); 676 const struct GNUNET_TESTBED_PeerCreateMessage *msg);
661 677
662 678
663/** 679/**
@@ -667,8 +683,8 @@ handle_peer_create(void *cls,
667 * @param msg the actual message 683 * @param msg the actual message
668 */ 684 */
669void 685void
670handle_peer_destroy(void *cls, 686handle_peer_destroy (void *cls,
671 const struct GNUNET_TESTBED_PeerDestroyMessage *msg); 687 const struct GNUNET_TESTBED_PeerDestroyMessage *msg);
672 688
673 689
674/** 690/**
@@ -678,8 +694,8 @@ handle_peer_destroy(void *cls,
678 * @param msg the actual message 694 * @param msg the actual message
679 */ 695 */
680void 696void
681handle_peer_start(void *cls, 697handle_peer_start (void *cls,
682 const struct GNUNET_TESTBED_PeerStartMessage *msg); 698 const struct GNUNET_TESTBED_PeerStartMessage *msg);
683 699
684 700
685/** 701/**
@@ -689,8 +705,8 @@ handle_peer_start(void *cls,
689 * @param message the actual message 705 * @param message the actual message
690 */ 706 */
691void 707void
692handle_peer_stop(void *cls, 708handle_peer_stop (void *cls,
693 const struct GNUNET_TESTBED_PeerStopMessage *msg); 709 const struct GNUNET_TESTBED_PeerStopMessage *msg);
694 710
695 711
696/** 712/**
@@ -700,8 +716,9 @@ handle_peer_stop(void *cls,
700 * @param msg the actual message 716 * @param msg the actual message
701 */ 717 */
702void 718void
703handle_peer_get_config(void *cls, 719handle_peer_get_config (void *cls,
704 const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg); 720 const struct
721 GNUNET_TESTBED_PeerGetConfigurationMessage *msg);
705 722
706 723
707/** 724/**
@@ -711,8 +728,8 @@ handle_peer_get_config(void *cls,
711 * @param msg the actual message 728 * @param msg the actual message
712 */ 729 */
713void 730void
714handle_shutdown_peers(void *cls, 731handle_shutdown_peers (void *cls,
715 const struct GNUNET_TESTBED_ShutdownPeersMessage *msg); 732 const struct GNUNET_TESTBED_ShutdownPeersMessage *msg);
716 733
717 734
718/** 735/**
@@ -723,8 +740,9 @@ handle_shutdown_peers(void *cls,
723 * @return #GNUNET_OK if @a msg is well-formed 740 * @return #GNUNET_OK if @a msg is well-formed
724 */ 741 */
725int 742int
726check_manage_peer_service(void *cls, 743check_manage_peer_service (void *cls,
727 const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg); 744 const struct
745 GNUNET_TESTBED_ManagePeerServiceMessage *msg);
728 746
729 747
730/** 748/**
@@ -734,8 +752,9 @@ check_manage_peer_service(void *cls,
734 * @param msg the actual message 752 * @param msg the actual message
735 */ 753 */
736void 754void
737handle_manage_peer_service(void *cls, 755handle_manage_peer_service (void *cls,
738 const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg); 756 const struct
757 GNUNET_TESTBED_ManagePeerServiceMessage *msg);
739 758
740 759
741 760
@@ -748,8 +767,9 @@ handle_manage_peer_service(void *cls,
748 * @return #GNUNET_OK if @a msg is well-formed 767 * @return #GNUNET_OK if @a msg is well-formed
749 */ 768 */
750int 769int
751check_peer_reconfigure(void *cls, 770check_peer_reconfigure (void *cls,
752 const struct GNUNET_TESTBED_PeerReconfigureMessage *msg); 771 const struct
772 GNUNET_TESTBED_PeerReconfigureMessage *msg);
753 773
754 774
755/** 775/**
@@ -761,29 +781,30 @@ check_peer_reconfigure(void *cls,
761 * @param msg the actual message 781 * @param msg the actual message
762 */ 782 */
763void 783void
764handle_peer_reconfigure(void *cls, 784handle_peer_reconfigure (void *cls,
765 const struct GNUNET_TESTBED_PeerReconfigureMessage *msg); 785 const struct
786 GNUNET_TESTBED_PeerReconfigureMessage *msg);
766 787
767 788
768/** 789/**
769 * Frees the ManageServiceContext queue 790 * Frees the ManageServiceContext queue
770 */ 791 */
771void 792void
772GST_free_mctxq(void); 793GST_free_mctxq (void);
773 794
774 795
775/** 796/**
776 * Cleans up the queue used for forwarding link controllers requests 797 * Cleans up the queue used for forwarding link controllers requests
777 */ 798 */
778void 799void
779GST_free_lcf(void); 800GST_free_lcf (void);
780 801
781 802
782/** 803/**
783 * Cleans up the route list 804 * Cleans up the route list
784 */ 805 */
785void 806void
786GST_route_list_clear(void); 807GST_route_list_clear (void);
787 808
788 809
789/** 810/**
@@ -792,7 +813,7 @@ GST_route_list_clear(void);
792 * @param rhc the RegisteredHostContext 813 * @param rhc the RegisteredHostContext
793 */ 814 */
794void 815void
795GST_process_next_focc(struct RegisteredHostContext *rhc); 816GST_process_next_focc (struct RegisteredHostContext *rhc);
796 817
797 818
798/** 819/**
@@ -801,28 +822,28 @@ GST_process_next_focc(struct RegisteredHostContext *rhc);
801 * @param focc the ForwardedOverlayConnectContext to cleanup 822 * @param focc the ForwardedOverlayConnectContext to cleanup
802 */ 823 */
803void 824void
804GST_cleanup_focc(struct ForwardedOverlayConnectContext *focc); 825GST_cleanup_focc (struct ForwardedOverlayConnectContext *focc);
805 826
806 827
807/** 828/**
808 * Clears all pending overlay connect contexts in queue 829 * Clears all pending overlay connect contexts in queue
809 */ 830 */
810void 831void
811GST_free_occq(void); 832GST_free_occq (void);
812 833
813 834
814/** 835/**
815 * Clears all pending remote overlay connect contexts in queue 836 * Clears all pending remote overlay connect contexts in queue
816 */ 837 */
817void 838void
818GST_free_roccq(void); 839GST_free_roccq (void);
819 840
820 841
821/** 842/**
822 * Cleans up the Peer reconfigure context list 843 * Cleans up the Peer reconfigure context list
823 */ 844 */
824void 845void
825GST_free_prcq(void); 846GST_free_prcq (void);
826 847
827 848
828/** 849/**
@@ -831,14 +852,14 @@ GST_free_prcq(void);
831 * @param size the size of the cache 852 * @param size the size of the cache
832 */ 853 */
833void 854void
834GST_cache_init(unsigned int size); 855GST_cache_init (unsigned int size);
835 856
836 857
837/** 858/**
838 * Clear cache 859 * Clear cache
839 */ 860 */
840void 861void
841GST_cache_clear(void); 862GST_cache_clear (void);
842 863
843 864
844/** 865/**
@@ -848,7 +869,7 @@ GST_cache_clear(void);
848 * @return the HELLO message; NULL if not found 869 * @return the HELLO message; NULL if not found
849 */ 870 */
850const struct GNUNET_MessageHeader * 871const struct GNUNET_MessageHeader *
851GST_cache_lookup_hello(const unsigned int peer_id); 872GST_cache_lookup_hello (const unsigned int peer_id);
852 873
853 874
854/** 875/**
@@ -859,8 +880,8 @@ GST_cache_lookup_hello(const unsigned int peer_id);
859 * @param hello the HELLO message 880 * @param hello the HELLO message
860 */ 881 */
861void 882void
862GST_cache_add_hello(const unsigned int peer_id, 883GST_cache_add_hello (const unsigned int peer_id,
863 const struct GNUNET_MessageHeader *hello); 884 const struct GNUNET_MessageHeader *hello);
864 885
865 886
866/** 887/**
@@ -869,13 +890,13 @@ GST_cache_add_hello(const unsigned int peer_id,
869 * generated from the hostname and the process's PID. 890 * generated from the hostname and the process's PID.
870 */ 891 */
871void 892void
872GST_stats_init(const struct GNUNET_CONFIGURATION_Handle *cfg); 893GST_stats_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
873 894
874 895
875/** 896/**
876 * Shutdown the status calls module. 897 * Shutdown the status calls module.
877 */ 898 */
878void 899void
879GST_stats_destroy(void); 900GST_stats_destroy (void);
880 901
881/* End of gnunet-service-testbed.h */ 902/* 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 c2cb9a99c..7ea1df662 100644
--- a/src/testbed/gnunet-service-testbed_barriers.c
+++ b/src/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/**
@@ -51,7 +51,7 @@
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,7 +63,8 @@ struct Barrier;
63/** 63/**
64 * Context to be associated with each client 64 * Context to be associated with each client
65 */ 65 */
66struct ClientCtx { 66struct ClientCtx
67{
67 /** 68 /**
68 * The barrier this client is waiting for 69 * The barrier this client is waiting for
69 */ 70 */
@@ -89,7 +90,8 @@ struct ClientCtx {
89/** 90/**
90 * Wrapper around Barrier handle 91 * Wrapper around Barrier handle
91 */ 92 */
92struct WBarrier { 93struct WBarrier
94{
93 /** 95 /**
94 * DLL next pointer 96 * DLL next pointer
95 */ 97 */
@@ -125,7 +127,8 @@ struct WBarrier {
125/** 127/**
126 * Barrier 128 * Barrier
127 */ 129 */
128struct Barrier { 130struct Barrier
131{
129 /** 132 /**
130 * The hashcode of the barrier name 133 * The hashcode of the barrier name
131 */ 134 */
@@ -221,23 +224,23 @@ static struct GNUNET_SERVICE_Handle *ctx;
221 * @param barrier the barrier handle 224 * @param barrier the barrier handle
222 */ 225 */
223static void 226static void
224remove_barrier(struct Barrier *barrier) 227remove_barrier (struct Barrier *barrier)
225{ 228{
226 struct ClientCtx *ctx; 229 struct ClientCtx *ctx;
227 230
228 GNUNET_assert(GNUNET_YES == 231 GNUNET_assert (GNUNET_YES ==
229 GNUNET_CONTAINER_multihashmap_remove(barrier_map, 232 GNUNET_CONTAINER_multihashmap_remove (barrier_map,
230 &barrier->hash, 233 &barrier->hash,
231 barrier)); 234 barrier));
232 while (NULL != (ctx = barrier->head)) 235 while (NULL != (ctx = barrier->head))
233 { 236 {
234 GNUNET_CONTAINER_DLL_remove(barrier->head, 237 GNUNET_CONTAINER_DLL_remove (barrier->head,
235 barrier->tail, 238 barrier->tail,
236 ctx); 239 ctx);
237 ctx->barrier = NULL; 240 ctx->barrier = NULL;
238 } 241 }
239 GNUNET_free(barrier->name); 242 GNUNET_free (barrier->name);
240 GNUNET_free(barrier); 243 GNUNET_free (barrier);
241} 244}
242 245
243 246
@@ -247,18 +250,18 @@ remove_barrier(struct Barrier *barrier)
247 * @param barrier the local barrier 250 * @param barrier the local barrier
248 */ 251 */
249static void 252static void
250cancel_wrappers(struct Barrier *barrier) 253cancel_wrappers (struct Barrier *barrier)
251{ 254{
252 struct WBarrier *wrapper; 255 struct WBarrier *wrapper;
253 256
254 while (NULL != (wrapper = barrier->whead)) 257 while (NULL != (wrapper = barrier->whead))
255 { 258 {
256 GNUNET_TESTBED_barrier_cancel(wrapper->hbarrier); 259 GNUNET_TESTBED_barrier_cancel (wrapper->hbarrier);
257 GNUNET_CONTAINER_DLL_remove(barrier->whead, 260 GNUNET_CONTAINER_DLL_remove (barrier->whead,
258 barrier->wtail, 261 barrier->wtail,
259 wrapper); 262 wrapper);
260 GNUNET_free(wrapper); 263 GNUNET_free (wrapper);
261 } 264 }
262} 265}
263 266
264 267
@@ -272,33 +275,33 @@ cancel_wrappers(struct Barrier *barrier)
272 * status=GNUNET_TESTBED_BARRIERSTATUS_ERROR 275 * status=GNUNET_TESTBED_BARRIERSTATUS_ERROR
273 */ 276 */
274static void 277static void
275send_client_status_msg(struct GNUNET_SERVICE_Client *client, 278send_client_status_msg (struct GNUNET_SERVICE_Client *client,
276 const char *name, 279 const char *name,
277 enum GNUNET_TESTBED_BarrierStatus status, 280 enum GNUNET_TESTBED_BarrierStatus status,
278 const char *emsg) 281 const char *emsg)
279{ 282{
280 struct GNUNET_MQ_Envelope *env; 283 struct GNUNET_MQ_Envelope *env;
281 struct GNUNET_TESTBED_BarrierStatusMsg *msg; 284 struct GNUNET_TESTBED_BarrierStatusMsg *msg;
282 size_t name_len; 285 size_t name_len;
283 size_t err_len; 286 size_t err_len;
284 287
285 GNUNET_assert((NULL == emsg) || 288 GNUNET_assert ((NULL == emsg) ||
286 (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status)); 289 (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status));
287 name_len = strlen(name) + 1; 290 name_len = strlen (name) + 1;
288 err_len = ((NULL == emsg) ? 0 : (strlen(emsg) + 1)); 291 err_len = ((NULL == emsg) ? 0 : (strlen (emsg) + 1));
289 env = GNUNET_MQ_msg_extra(msg, 292 env = GNUNET_MQ_msg_extra (msg,
290 name_len + err_len, 293 name_len + err_len,
291 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS); 294 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS);
292 msg->status = htons(status); 295 msg->status = htons (status);
293 msg->name_len = htons((uint16_t)name_len - 1); 296 msg->name_len = htons ((uint16_t) name_len - 1);
294 GNUNET_memcpy(msg->data, 297 GNUNET_memcpy (msg->data,
295 name, 298 name,
296 name_len); 299 name_len);
297 GNUNET_memcpy(msg->data + name_len, 300 GNUNET_memcpy (msg->data + name_len,
298 emsg, 301 emsg,
299 err_len); 302 err_len);
300 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), 303 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
301 env); 304 env);
302} 305}
303 306
304 307
@@ -310,14 +313,14 @@ send_client_status_msg(struct GNUNET_SERVICE_Client *client,
310 * status=GNUNET_TESTBED_BARRIERSTATUS_ERROR 313 * status=GNUNET_TESTBED_BARRIERSTATUS_ERROR
311 */ 314 */
312static void 315static void
313send_barrier_status_msg(struct Barrier *barrier, 316send_barrier_status_msg (struct Barrier *barrier,
314 const char *emsg) 317 const char *emsg)
315{ 318{
316 GNUNET_assert(0 != barrier->status); 319 GNUNET_assert (0 != barrier->status);
317 send_client_status_msg(barrier->mc, 320 send_client_status_msg (barrier->mc,
318 barrier->name, 321 barrier->name,
319 barrier->status, 322 barrier->status,
320 emsg); 323 emsg);
321} 324}
322 325
323 326
@@ -328,8 +331,8 @@ send_barrier_status_msg(struct Barrier *barrier,
328 * @param message the actual message 331 * @param message the actual message
329 */ 332 */
330static int 333static int
331check_barrier_wait(void *cls, 334check_barrier_wait (void *cls,
332 const struct GNUNET_TESTBED_BarrierWait *msg) 335 const struct GNUNET_TESTBED_BarrierWait *msg)
333{ 336{
334 return GNUNET_OK; /* always well-formed */ 337 return GNUNET_OK; /* always well-formed */
335} 338}
@@ -347,8 +350,8 @@ check_barrier_wait(void *cls,
347 * @param message the actual message 350 * @param message the actual message
348 */ 351 */
349static void 352static void
350handle_barrier_wait(void *cls, 353handle_barrier_wait (void *cls,
351 const struct GNUNET_TESTBED_BarrierWait *msg) 354 const struct GNUNET_TESTBED_BarrierWait *msg)
352{ 355{
353 struct ClientCtx *client_ctx = cls; 356 struct ClientCtx *client_ctx = cls;
354 struct Barrier *barrier; 357 struct Barrier *barrier;
@@ -357,50 +360,50 @@ handle_barrier_wait(void *cls,
357 size_t name_len; 360 size_t name_len;
358 uint16_t msize; 361 uint16_t msize;
359 362
360 msize = ntohs(msg->header.size); 363 msize = ntohs (msg->header.size);
361 if (NULL == barrier_map) 364 if (NULL == barrier_map)
362 { 365 {
363 GNUNET_break(0); 366 GNUNET_break (0);
364 GNUNET_SERVICE_client_drop(client_ctx->client); 367 GNUNET_SERVICE_client_drop (client_ctx->client);
365 return; 368 return;
366 } 369 }
367 name_len = msize - sizeof(struct GNUNET_TESTBED_BarrierWait); 370 name_len = msize - sizeof(struct GNUNET_TESTBED_BarrierWait);
368 name = GNUNET_malloc(name_len + 1); 371 name = GNUNET_malloc (name_len + 1);
369 name[name_len] = '\0'; 372 name[name_len] = '\0';
370 GNUNET_memcpy(name, 373 GNUNET_memcpy (name,
371 msg->name, 374 msg->name,
372 name_len); 375 name_len);
373 LOG_DEBUG("Received BARRIER_WAIT for barrier `%s'\n", 376 LOG_DEBUG ("Received BARRIER_WAIT for barrier `%s'\n",
374 name); 377 name);
375 GNUNET_CRYPTO_hash(name, 378 GNUNET_CRYPTO_hash (name,
376 name_len, 379 name_len,
377 &key); 380 &key);
378 GNUNET_free(name); 381 GNUNET_free (name);
379 if (NULL == (barrier = GNUNET_CONTAINER_multihashmap_get(barrier_map, &key))) 382 if (NULL == (barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, &key)))
380 { 383 {
381 GNUNET_break(0); 384 GNUNET_break (0);
382 GNUNET_SERVICE_client_drop(client_ctx->client); 385 GNUNET_SERVICE_client_drop (client_ctx->client);
383 return; 386 return;
384 } 387 }
385 if (NULL != client_ctx->barrier) 388 if (NULL != client_ctx->barrier)
386 { 389 {
387 GNUNET_break(0); 390 GNUNET_break (0);
388 GNUNET_SERVICE_client_drop(client_ctx->client); 391 GNUNET_SERVICE_client_drop (client_ctx->client);
389 return; 392 return;
390 } 393 }
391 client_ctx->barrier = barrier; 394 client_ctx->barrier = barrier;
392 GNUNET_CONTAINER_DLL_insert_tail(barrier->head, 395 GNUNET_CONTAINER_DLL_insert_tail (barrier->head,
393 barrier->tail, 396 barrier->tail,
394 client_ctx); 397 client_ctx);
395 barrier->nreached++; 398 barrier->nreached++;
396 if ((barrier->num_wbarriers_reached == barrier->num_wbarriers) && 399 if ((barrier->num_wbarriers_reached == barrier->num_wbarriers) &&
397 (LOCAL_QUORUM_REACHED(barrier))) 400 (LOCAL_QUORUM_REACHED (barrier)))
398 { 401 {
399 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_CROSSED; 402 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_CROSSED;
400 send_barrier_status_msg(barrier, 403 send_barrier_status_msg (barrier,
401 NULL); 404 NULL);
402 } 405 }
403 GNUNET_SERVICE_client_continue(client_ctx->client); 406 GNUNET_SERVICE_client_continue (client_ctx->client);
404} 407}
405 408
406 409
@@ -413,14 +416,14 @@ handle_barrier_wait(void *cls,
413 * @return our `struct ClientCtx` 416 * @return our `struct ClientCtx`
414 */ 417 */
415static void * 418static void *
416connect_cb(void *cls, 419connect_cb (void *cls,
417 struct GNUNET_SERVICE_Client *client, 420 struct GNUNET_SERVICE_Client *client,
418 struct GNUNET_MQ_Handle *mq) 421 struct GNUNET_MQ_Handle *mq)
419{ 422{
420 struct ClientCtx *client_ctx; 423 struct ClientCtx *client_ctx;
421 424
422 LOG_DEBUG("Client connected to testbed-barrier service\n"); 425 LOG_DEBUG ("Client connected to testbed-barrier service\n");
423 client_ctx = GNUNET_new(struct ClientCtx); 426 client_ctx = GNUNET_new (struct ClientCtx);
424 client_ctx->client = client; 427 client_ctx->client = client;
425 return client_ctx; 428 return client_ctx;
426} 429}
@@ -435,22 +438,22 @@ connect_cb(void *cls,
435 * for the last call when the server is destroyed 438 * for the last call when the server is destroyed
436 */ 439 */
437static void 440static void
438disconnect_cb(void *cls, 441disconnect_cb (void *cls,
439 struct GNUNET_SERVICE_Client *client, 442 struct GNUNET_SERVICE_Client *client,
440 void *app_ctx) 443 void *app_ctx)
441{ 444{
442 struct ClientCtx *client_ctx = app_ctx; 445 struct ClientCtx *client_ctx = app_ctx;
443 struct Barrier *barrier = client_ctx->barrier; 446 struct Barrier *barrier = client_ctx->barrier;
444 447
445 if (NULL != barrier) 448 if (NULL != barrier)
446 { 449 {
447 GNUNET_CONTAINER_DLL_remove(barrier->head, 450 GNUNET_CONTAINER_DLL_remove (barrier->head,
448 barrier->tail, 451 barrier->tail,
449 client_ctx); 452 client_ctx);
450 client_ctx->barrier = NULL; 453 client_ctx->barrier = NULL;
451 } 454 }
452 GNUNET_free(client_ctx); 455 GNUNET_free (client_ctx);
453 LOG_DEBUG("Client disconnected from testbed-barrier service\n"); 456 LOG_DEBUG ("Client disconnected from testbed-barrier service\n");
454} 457}
455 458
456 459
@@ -460,25 +463,25 @@ disconnect_cb(void *cls,
460 * @param cfg the configuration to use for initialisation 463 * @param cfg the configuration to use for initialisation
461 */ 464 */
462void 465void
463GST_barriers_init(struct GNUNET_CONFIGURATION_Handle *cfg) 466GST_barriers_init (struct GNUNET_CONFIGURATION_Handle *cfg)
464{ 467{
465 struct GNUNET_MQ_MessageHandler message_handlers[] = { 468 struct GNUNET_MQ_MessageHandler message_handlers[] = {
466 GNUNET_MQ_hd_var_size(barrier_wait, 469 GNUNET_MQ_hd_var_size (barrier_wait,
467 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT, 470 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT,
468 struct GNUNET_TESTBED_BarrierWait, 471 struct GNUNET_TESTBED_BarrierWait,
469 NULL), 472 NULL),
470 GNUNET_MQ_handler_end() 473 GNUNET_MQ_handler_end ()
471 }; 474 };
472 475
473 LOG_DEBUG("Launching testbed-barrier service\n"); 476 LOG_DEBUG ("Launching testbed-barrier service\n");
474 barrier_map = GNUNET_CONTAINER_multihashmap_create(3, 477 barrier_map = GNUNET_CONTAINER_multihashmap_create (3,
475 GNUNET_YES); 478 GNUNET_YES);
476 ctx = GNUNET_SERVICE_start("testbed-barrier", 479 ctx = GNUNET_SERVICE_start ("testbed-barrier",
477 cfg, 480 cfg,
478 &connect_cb, 481 &connect_cb,
479 &disconnect_cb, 482 &disconnect_cb,
480 NULL, 483 NULL,
481 message_handlers); 484 message_handlers);
482} 485}
483 486
484 487
@@ -493,15 +496,15 @@ GST_barriers_init(struct GNUNET_CONFIGURATION_Handle *cfg)
493 * #GNUNET_NO if not. 496 * #GNUNET_NO if not.
494 */ 497 */
495static int 498static int
496barrier_destroy_iterator(void *cls, 499barrier_destroy_iterator (void *cls,
497 const struct GNUNET_HashCode *key, 500 const struct GNUNET_HashCode *key,
498 void *value) 501 void *value)
499{ 502{
500 struct Barrier *barrier = value; 503 struct Barrier *barrier = value;
501 504
502 GNUNET_assert(NULL != barrier); 505 GNUNET_assert (NULL != barrier);
503 cancel_wrappers(barrier); 506 cancel_wrappers (barrier);
504 remove_barrier(barrier); 507 remove_barrier (barrier);
505 return GNUNET_YES; 508 return GNUNET_YES;
506} 509}
507 510
@@ -510,16 +513,17 @@ barrier_destroy_iterator(void *cls,
510 * Function to stop the barrier service 513 * Function to stop the barrier service
511 */ 514 */
512void 515void
513GST_barriers_destroy() 516GST_barriers_destroy ()
514{ 517{
515 GNUNET_assert(NULL != barrier_map); 518 GNUNET_assert (NULL != barrier_map);
516 GNUNET_assert(GNUNET_SYSERR != 519 GNUNET_assert (GNUNET_SYSERR !=
517 GNUNET_CONTAINER_multihashmap_iterate(barrier_map, 520 GNUNET_CONTAINER_multihashmap_iterate (barrier_map,
518 &barrier_destroy_iterator, 521 &
519 NULL)); 522 barrier_destroy_iterator,
520 GNUNET_CONTAINER_multihashmap_destroy(barrier_map); 523 NULL));
521 GNUNET_assert(NULL != ctx); 524 GNUNET_CONTAINER_multihashmap_destroy (barrier_map);
522 GNUNET_SERVICE_stop(ctx); 525 GNUNET_assert (NULL != ctx);
526 GNUNET_SERVICE_stop (ctx);
523} 527}
524 528
525 529
@@ -537,59 +541,59 @@ GST_barriers_destroy()
537 * error messsage 541 * error messsage
538 */ 542 */
539static void 543static void
540wbarrier_status_cb(void *cls, 544wbarrier_status_cb (void *cls,
541 const char *name, 545 const char *name,
542 struct GNUNET_TESTBED_Barrier *b_, 546 struct GNUNET_TESTBED_Barrier *b_,
543 enum GNUNET_TESTBED_BarrierStatus status, 547 enum GNUNET_TESTBED_BarrierStatus status,
544 const char *emsg) 548 const char *emsg)
545{ 549{
546 struct WBarrier *wrapper = cls; 550 struct WBarrier *wrapper = cls;
547 struct Barrier *barrier = wrapper->barrier; 551 struct Barrier *barrier = wrapper->barrier;
548 552
549 GNUNET_assert(b_ == wrapper->hbarrier); 553 GNUNET_assert (b_ == wrapper->hbarrier);
550 switch (status) 554 switch (status)
555 {
556 case GNUNET_TESTBED_BARRIERSTATUS_ERROR:
557 LOG (GNUNET_ERROR_TYPE_ERROR,
558 "Initialising barrier `%s' failed at a sub-controller: %s\n",
559 barrier->name,
560 (NULL != emsg) ? emsg : "NULL");
561 cancel_wrappers (barrier);
562 if (NULL == emsg)
563 emsg = "Initialisation failed at a sub-controller";
564 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_ERROR;
565 send_barrier_status_msg (barrier, emsg);
566 return;
567
568 case GNUNET_TESTBED_BARRIERSTATUS_CROSSED:
569 if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED != barrier->status)
551 { 570 {
552 case GNUNET_TESTBED_BARRIERSTATUS_ERROR: 571 GNUNET_break_op (0);
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);
562 return;
563
564 case GNUNET_TESTBED_BARRIERSTATUS_CROSSED:
565 if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED != barrier->status)
566 {
567 GNUNET_break_op(0);
568 return;
569 }
570 barrier->num_wbarriers_reached++;
571 if ((barrier->num_wbarriers_reached == barrier->num_wbarriers)
572 && (LOCAL_QUORUM_REACHED(barrier)))
573 {
574 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_CROSSED;
575 send_barrier_status_msg(barrier, NULL);
576 }
577 return; 572 return;
573 }
574 barrier->num_wbarriers_reached++;
575 if ((barrier->num_wbarriers_reached == barrier->num_wbarriers)
576 && (LOCAL_QUORUM_REACHED (barrier)))
577 {
578 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_CROSSED;
579 send_barrier_status_msg (barrier, NULL);
580 }
581 return;
578 582
579 case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: 583 case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED:
580 if (0 != barrier->status) 584 if (0 != barrier->status)
581 { 585 {
582 GNUNET_break_op(0); 586 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 }
591 return; 587 return;
592 } 588 }
589 barrier->num_wbarriers_inited++;
590 if (barrier->num_wbarriers_inited == barrier->num_wbarriers)
591 {
592 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_INITIALISED;
593 send_barrier_status_msg (barrier, NULL);
594 }
595 return;
596 }
593} 597}
594 598
595 599
@@ -600,15 +604,15 @@ wbarrier_status_cb(void *cls,
600 * @param cls barrier 604 * @param cls barrier
601 */ 605 */
602static void 606static void
603fwd_tout_barrier_init(void *cls) 607fwd_tout_barrier_init (void *cls)
604{ 608{
605 struct Barrier *barrier = cls; 609 struct Barrier *barrier = cls;
606 610
607 cancel_wrappers(barrier); 611 cancel_wrappers (barrier);
608 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_ERROR; 612 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_ERROR;
609 send_barrier_status_msg(barrier, 613 send_barrier_status_msg (barrier,
610 "Timedout while propagating barrier initialisation\n"); 614 "Timedout while propagating barrier initialisation\n");
611 remove_barrier(barrier); 615 remove_barrier (barrier);
612} 616}
613 617
614 618
@@ -621,8 +625,8 @@ fwd_tout_barrier_init(void *cls)
621 * @return #GNUNET_OK if @a msg is well-formed 625 * @return #GNUNET_OK if @a msg is well-formed
622 */ 626 */
623int 627int
624check_barrier_init(void *cls, 628check_barrier_init (void *cls,
625 const struct GNUNET_TESTBED_BarrierInit *msg) 629 const struct GNUNET_TESTBED_BarrierInit *msg)
626{ 630{
627 return GNUNET_OK; /* always well-formed */ 631 return GNUNET_OK; /* always well-formed */
628} 632}
@@ -640,8 +644,8 @@ check_barrier_init(void *cls,
640 * @param msg the actual message 644 * @param msg the actual message
641 */ 645 */
642void 646void
643handle_barrier_init(void *cls, 647handle_barrier_init (void *cls,
644 const struct GNUNET_TESTBED_BarrierInit *msg) 648 const struct GNUNET_TESTBED_BarrierInit *msg)
645{ 649{
646 struct GNUNET_SERVICE_Client *client = cls; 650 struct GNUNET_SERVICE_Client *client = cls;
647 char *name; 651 char *name;
@@ -654,82 +658,84 @@ handle_barrier_init(void *cls,
654 uint16_t msize; 658 uint16_t msize;
655 659
656 if (NULL == GST_context) 660 if (NULL == GST_context)
657 { 661 {
658 GNUNET_break_op(0); 662 GNUNET_break_op (0);
659 GNUNET_SERVICE_client_drop(client); 663 GNUNET_SERVICE_client_drop (client);
660 return; 664 return;
661 } 665 }
662 if (client != GST_context->client) 666 if (client != GST_context->client)
663 { 667 {
664 GNUNET_break_op(0); 668 GNUNET_break_op (0);
665 GNUNET_SERVICE_client_drop(client); 669 GNUNET_SERVICE_client_drop (client);
666 return; 670 return;
667 } 671 }
668 msize = ntohs(msg->header.size); 672 msize = ntohs (msg->header.size);
669 name_len = (size_t)msize - sizeof(struct GNUNET_TESTBED_BarrierInit); 673 name_len = (size_t) msize - sizeof(struct GNUNET_TESTBED_BarrierInit);
670 name = GNUNET_malloc(name_len + 1); 674 name = GNUNET_malloc (name_len + 1);
671 GNUNET_memcpy(name, msg->name, name_len); 675 GNUNET_memcpy (name, msg->name, name_len);
672 GNUNET_CRYPTO_hash(name, name_len, &hash); 676 GNUNET_CRYPTO_hash (name, name_len, &hash);
673 LOG_DEBUG("Received BARRIER_INIT for barrier `%s'\n", 677 LOG_DEBUG ("Received BARRIER_INIT for barrier `%s'\n",
674 name); 678 name);
675 if (GNUNET_YES == 679 if (GNUNET_YES ==
676 GNUNET_CONTAINER_multihashmap_contains(barrier_map, 680 GNUNET_CONTAINER_multihashmap_contains (barrier_map,
677 &hash)) 681 &hash))
678 { 682 {
679 send_client_status_msg(client, 683 send_client_status_msg (client,
680 name, 684 name,
681 GNUNET_TESTBED_BARRIERSTATUS_ERROR, 685 GNUNET_TESTBED_BARRIERSTATUS_ERROR,
682 "A barrier with the same name already exists"); 686 "A barrier with the same name already exists");
683 GNUNET_free(name); 687 GNUNET_free (name);
684 GNUNET_SERVICE_client_continue(client); 688 GNUNET_SERVICE_client_continue (client);
685 return; 689 return;
686 } 690 }
687 barrier = GNUNET_new(struct Barrier); 691 barrier = GNUNET_new (struct Barrier);
688 barrier->hash = hash; 692 barrier->hash = hash;
689 barrier->quorum = msg->quorum; 693 barrier->quorum = msg->quorum;
690 barrier->name = name; 694 barrier->name = name;
691 barrier->mc = client; 695 barrier->mc = client;
692 GNUNET_assert(GNUNET_OK == 696 GNUNET_assert (GNUNET_OK ==
693 GNUNET_CONTAINER_multihashmap_put(barrier_map, 697 GNUNET_CONTAINER_multihashmap_put (barrier_map,
694 &barrier->hash, 698 &barrier->hash,
695 barrier, 699 barrier,
696 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 700 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
697 GNUNET_SERVICE_client_continue(client); 701 GNUNET_SERVICE_client_continue (client);
698 /* Propagate barrier init to subcontrollers */ 702 /* Propagate barrier init to subcontrollers */
699 for (cnt = 0; cnt < GST_slave_list_size; cnt++) 703 for (cnt = 0; cnt < GST_slave_list_size; cnt++)
704 {
705 if (NULL == (slave = GST_slave_list[cnt]))
706 continue;
707 if (NULL == slave->controller)
700 { 708 {
701 if (NULL == (slave = GST_slave_list[cnt])) 709 GNUNET_break (0); /* May happen when we are connecting to the controller */
702 continue; 710 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);
721 } 711 }
712 wrapper = GNUNET_new (struct WBarrier);
713 wrapper->barrier = barrier;
714 wrapper->controller = slave->controller;
715 GNUNET_CONTAINER_DLL_insert_tail (barrier->whead,
716 barrier->wtail,
717 wrapper);
718 barrier->num_wbarriers++;
719 wrapper->hbarrier = GNUNET_TESTBED_barrier_init_ (wrapper->controller,
720 barrier->name,
721 barrier->quorum,
722 &wbarrier_status_cb,
723 wrapper,
724 GNUNET_NO);
725 }
722 if (NULL == barrier->whead) /* No further propagation */ 726 if (NULL == barrier->whead) /* No further propagation */
723 { 727 {
724 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_INITIALISED; 728 barrier->status = GNUNET_TESTBED_BARRIERSTATUS_INITIALISED;
725 LOG_DEBUG("Sending GNUNET_TESTBED_BARRIERSTATUS_INITIALISED for barrier `%s'\n", 729 LOG_DEBUG (
726 barrier->name); 730 "Sending GNUNET_TESTBED_BARRIERSTATUS_INITIALISED for barrier `%s'\n",
727 send_barrier_status_msg(barrier, NULL); 731 barrier->name);
728 } 732 send_barrier_status_msg (barrier, NULL);
733 }
729 else 734 else
730 barrier->tout_task = GNUNET_SCHEDULER_add_delayed(MESSAGE_SEND_TIMEOUT(30), 735 barrier->tout_task = GNUNET_SCHEDULER_add_delayed (MESSAGE_SEND_TIMEOUT (
731 &fwd_tout_barrier_init, 736 30),
732 barrier); 737 &fwd_tout_barrier_init,
738 barrier);
733} 739}
734 740
735 741
@@ -741,8 +747,8 @@ handle_barrier_init(void *cls,
741 * @return #GNUNET_OK if @a msg is well-formed 747 * @return #GNUNET_OK if @a msg is well-formed
742 */ 748 */
743int 749int
744check_barrier_cancel(void *cls, 750check_barrier_cancel (void *cls,
745 const struct GNUNET_TESTBED_BarrierCancel *msg) 751 const struct GNUNET_TESTBED_BarrierCancel *msg)
746{ 752{
747 return GNUNET_OK; /* all are well-formed */ 753 return GNUNET_OK; /* all are well-formed */
748} 754}
@@ -760,8 +766,8 @@ check_barrier_cancel(void *cls,
760 * @param msg the actual message 766 * @param msg the actual message
761 */ 767 */
762void 768void
763handle_barrier_cancel(void *cls, 769handle_barrier_cancel (void *cls,
764 const struct GNUNET_TESTBED_BarrierCancel *msg) 770 const struct GNUNET_TESTBED_BarrierCancel *msg)
765{ 771{
766 struct GNUNET_SERVICE_Client *client = cls; 772 struct GNUNET_SERVICE_Client *client = cls;
767 char *name; 773 char *name;
@@ -771,42 +777,42 @@ handle_barrier_cancel(void *cls,
771 uint16_t msize; 777 uint16_t msize;
772 778
773 if (NULL == GST_context) 779 if (NULL == GST_context)
774 { 780 {
775 GNUNET_break_op(0); 781 GNUNET_break_op (0);
776 GNUNET_SERVICE_client_drop(client); 782 GNUNET_SERVICE_client_drop (client);
777 return; 783 return;
778 } 784 }
779 if (client != GST_context->client) 785 if (client != GST_context->client)
780 { 786 {
781 GNUNET_break_op(0); 787 GNUNET_break_op (0);
782 GNUNET_SERVICE_client_drop(client); 788 GNUNET_SERVICE_client_drop (client);
783 return; 789 return;
784 } 790 }
785 msize = ntohs(msg->header.size); 791 msize = ntohs (msg->header.size);
786 name_len = msize - sizeof(struct GNUNET_TESTBED_BarrierCancel); 792 name_len = msize - sizeof(struct GNUNET_TESTBED_BarrierCancel);
787 name = GNUNET_malloc(name_len + 1); 793 name = GNUNET_malloc (name_len + 1);
788 GNUNET_memcpy(name, 794 GNUNET_memcpy (name,
789 msg->name, 795 msg->name,
790 name_len); 796 name_len);
791 LOG_DEBUG("Received BARRIER_CANCEL for barrier `%s'\n", 797 LOG_DEBUG ("Received BARRIER_CANCEL for barrier `%s'\n",
792 name); 798 name);
793 GNUNET_CRYPTO_hash(name, 799 GNUNET_CRYPTO_hash (name,
794 name_len, 800 name_len,
795 &hash); 801 &hash);
796 if (GNUNET_NO == 802 if (GNUNET_NO ==
797 GNUNET_CONTAINER_multihashmap_contains(barrier_map, 803 GNUNET_CONTAINER_multihashmap_contains (barrier_map,
798 &hash)) 804 &hash))
799 { 805 {
800 GNUNET_break_op(0); 806 GNUNET_break_op (0);
801 GNUNET_SERVICE_client_drop(client); 807 GNUNET_SERVICE_client_drop (client);
802 return; 808 return;
803 } 809 }
804 barrier = GNUNET_CONTAINER_multihashmap_get(barrier_map, 810 barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map,
805 &hash); 811 &hash);
806 GNUNET_assert(NULL != barrier); 812 GNUNET_assert (NULL != barrier);
807 cancel_wrappers(barrier); 813 cancel_wrappers (barrier);
808 remove_barrier(barrier); 814 remove_barrier (barrier);
809 GNUNET_SERVICE_client_continue(client); 815 GNUNET_SERVICE_client_continue (client);
810} 816}
811 817
812 818
@@ -818,34 +824,34 @@ handle_barrier_cancel(void *cls,
818 * @return #GNUNET_OK if @a msg is well-formed 824 * @return #GNUNET_OK if @a msg is well-formed
819 */ 825 */
820int 826int
821check_barrier_status(void *cls, 827check_barrier_status (void *cls,
822 const struct GNUNET_TESTBED_BarrierStatusMsg *msg) 828 const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
823{ 829{
824 uint16_t msize; 830 uint16_t msize;
825 uint16_t name_len; 831 uint16_t name_len;
826 const char *name; 832 const char *name;
827 enum GNUNET_TESTBED_BarrierStatus status; 833 enum GNUNET_TESTBED_BarrierStatus status;
828 834
829 msize = ntohs(msg->header.size) - sizeof(*msg); 835 msize = ntohs (msg->header.size) - sizeof(*msg);
830 status = ntohs(msg->status); 836 status = ntohs (msg->status);
831 if (GNUNET_TESTBED_BARRIERSTATUS_CROSSED != status) 837 if (GNUNET_TESTBED_BARRIERSTATUS_CROSSED != status)
832 { 838 {
833 GNUNET_break_op(0); /* current we only expect BARRIER_CROSSED 839 GNUNET_break_op (0); /* current we only expect BARRIER_CROSSED
834 status message this way */ 840 status message this way */
835 return GNUNET_SYSERR; 841 return GNUNET_SYSERR;
836 } 842 }
837 name = msg->data; 843 name = msg->data;
838 name_len = ntohs(msg->name_len); 844 name_len = ntohs (msg->name_len);
839 if ((name_len + 1) != msize) 845 if ((name_len + 1) != msize)
840 { 846 {
841 GNUNET_break_op(0); 847 GNUNET_break_op (0);
842 return GNUNET_SYSERR; 848 return GNUNET_SYSERR;
843 } 849 }
844 if ('\0' != name[name_len]) 850 if ('\0' != name[name_len])
845 { 851 {
846 GNUNET_break_op(0); 852 GNUNET_break_op (0);
847 return GNUNET_SYSERR; 853 return GNUNET_SYSERR;
848 } 854 }
849 return GNUNET_OK; 855 return GNUNET_OK;
850} 856}
851 857
@@ -859,8 +865,8 @@ check_barrier_status(void *cls,
859 * @param msg the actual message 865 * @param msg the actual message
860 */ 866 */
861void 867void
862handle_barrier_status(void *cls, 868handle_barrier_status (void *cls,
863 const struct GNUNET_TESTBED_BarrierStatusMsg *msg) 869 const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
864{ 870{
865 struct GNUNET_SERVICE_Client *client = cls; 871 struct GNUNET_SERVICE_Client *client = cls;
866 struct Barrier *barrier; 872 struct Barrier *barrier;
@@ -872,48 +878,49 @@ handle_barrier_status(void *cls,
872 struct GNUNET_MQ_Envelope *env; 878 struct GNUNET_MQ_Envelope *env;
873 879
874 if (NULL == GST_context) 880 if (NULL == GST_context)
875 { 881 {
876 GNUNET_break_op(0); 882 GNUNET_break_op (0);
877 GNUNET_SERVICE_client_drop(client); 883 GNUNET_SERVICE_client_drop (client);
878 return; 884 return;
879 } 885 }
880 if (client != GST_context->client) 886 if (client != GST_context->client)
881 { 887 {
882 GNUNET_break_op(0); 888 GNUNET_break_op (0);
883 GNUNET_SERVICE_client_drop(client); 889 GNUNET_SERVICE_client_drop (client);
884 return; 890 return;
885 } 891 }
886 name = msg->data; 892 name = msg->data;
887 name_len = ntohs(msg->name_len); 893 name_len = ntohs (msg->name_len);
888 LOG_DEBUG("Received BARRIER_STATUS for barrier `%s'\n", 894 LOG_DEBUG ("Received BARRIER_STATUS for barrier `%s'\n",
889 name); 895 name);
890 GNUNET_CRYPTO_hash(name, 896 GNUNET_CRYPTO_hash (name,
891 name_len, 897 name_len,
892 &key); 898 &key);
893 barrier = GNUNET_CONTAINER_multihashmap_get(barrier_map, 899 barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map,
894 &key); 900 &key);
895 if (NULL == barrier) 901 if (NULL == barrier)
896 { 902 {
897 GNUNET_break_op(0); 903 GNUNET_break_op (0);
898 GNUNET_SERVICE_client_drop(client); 904 GNUNET_SERVICE_client_drop (client);
899 return; 905 return;
900 } 906 }
901 GNUNET_SERVICE_client_continue(client); 907 GNUNET_SERVICE_client_continue (client);
902 for (client_ctx = barrier->head; NULL != client_ctx; client_ctx = client_ctx->next) /* Notify peers */ 908 for (client_ctx = barrier->head; NULL != client_ctx; client_ctx =
903 { 909 client_ctx->next) /* Notify peers */
904 env = GNUNET_MQ_msg_copy(&msg->header); 910 {
905 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client_ctx->client), 911 env = GNUNET_MQ_msg_copy (&msg->header);
906 env); 912 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client_ctx->client),
907 } 913 env);
914 }
908 /** 915 /**
909 * The wrapper barriers do not echo the barrier status, so we have to do it 916 * The wrapper barriers do not echo the barrier status, so we have to do it
910 * here 917 * here
911 */ 918 */
912 for (wrapper = barrier->whead; NULL != wrapper; wrapper = wrapper->next) 919 for (wrapper = barrier->whead; NULL != wrapper; wrapper = wrapper->next)
913 { 920 {
914 GNUNET_TESTBED_queue_message_(wrapper->controller, 921 GNUNET_TESTBED_queue_message_ (wrapper->controller,
915 GNUNET_copy_message(&msg->header)); 922 GNUNET_copy_message (&msg->header));
916 } 923 }
917} 924}
918 925
919/* end of gnunet-service-testbed_barriers.c */ 926/* 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 a16a4aa0d..f58e10609 100644
--- a/src/testbed/gnunet-service-testbed_barriers.h
+++ b/src/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 */
35void 35void
36GST_barriers_init(struct GNUNET_CONFIGURATION_Handle *cfg); 36GST_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 */
42void 42void
43GST_barriers_destroy(void); 43GST_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 */
53int 53int
54check_barrier_init(void *cls, 54check_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 */
69void 69void
70handle_barrier_init(void *cls, 70handle_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 */
81int 81int
82check_barrier_cancel(void *cls, 82check_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 */
97void 97void
98handle_barrier_cancel(void *cls, 98handle_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 */
109int 109int
110check_barrier_status(void *cls, 110check_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 */
122void 122void
123handle_barrier_status(void *cls, 123handle_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 901065da1..4afa06645 100644
--- a/src/testbed/gnunet-service-testbed_cache.c
+++ b/src/testbed/gnunet-service-testbed_cache.c
@@ -32,13 +32,14 @@
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 */
41struct CacheEntry { 41struct CacheEntry
42{
42 /** 43 /**
43 * DLL next ptr for least recently used cache entries 44 * DLL next ptr for least recently used cache entries
44 */ 45 */
@@ -96,16 +97,16 @@ static unsigned int cache_size;
96 * @return the HELLO message; NULL if not found 97 * @return the HELLO message; NULL if not found
97 */ 98 */
98static struct CacheEntry * 99static struct CacheEntry *
99cache_lookup(unsigned int peer_id) 100cache_lookup (unsigned int peer_id)
100{ 101{
101 struct CacheEntry *entry; 102 struct CacheEntry *entry;
102 103
103 GNUNET_assert(NULL != cache); 104 GNUNET_assert (NULL != cache);
104 entry = GNUNET_CONTAINER_multihashmap32_get(cache, peer_id); 105 entry = GNUNET_CONTAINER_multihashmap32_get (cache, peer_id);
105 if (NULL == entry) 106 if (NULL == entry)
106 return NULL; 107 return NULL;
107 GNUNET_CONTAINER_DLL_remove(cache_head, cache_tail, entry); 108 GNUNET_CONTAINER_DLL_remove (cache_head, cache_tail, entry);
108 GNUNET_CONTAINER_DLL_insert_tail(cache_head, cache_tail, entry); 109 GNUNET_CONTAINER_DLL_insert_tail (cache_head, cache_tail, entry);
109 return entry; 110 return entry;
110} 111}
111 112
@@ -116,11 +117,11 @@ cache_lookup(unsigned int peer_id)
116 * @param entry the cache entry to free 117 * @param entry the cache entry to free
117 */ 118 */
118static void 119static void
119free_entry(struct CacheEntry *entry) 120free_entry (struct CacheEntry *entry)
120{ 121{
121 GNUNET_CONTAINER_DLL_remove(cache_head, cache_tail, entry); 122 GNUNET_CONTAINER_DLL_remove (cache_head, cache_tail, entry);
122 GNUNET_free_non_null(entry->hello); 123 GNUNET_free_non_null (entry->hello);
123 GNUNET_free(entry); 124 GNUNET_free (entry);
124} 125}
125 126
126 127
@@ -131,29 +132,29 @@ free_entry(struct CacheEntry *entry)
131 * @return the newly created entry 132 * @return the newly created entry
132 */ 133 */
133static struct CacheEntry * 134static struct CacheEntry *
134add_entry(unsigned int peer_id) 135add_entry (unsigned int peer_id)
135{ 136{
136 struct CacheEntry *entry; 137 struct CacheEntry *entry;
137 138
138 GNUNET_assert(NULL != cache); 139 GNUNET_assert (NULL != cache);
139 if (cache_size == GNUNET_CONTAINER_multihashmap32_size(cache)) 140 if (cache_size == GNUNET_CONTAINER_multihashmap32_size (cache))
140 { 141 {
141 /* remove the LRU head */ 142 /* remove the LRU head */
142 entry = cache_head; 143 entry = cache_head;
143 GNUNET_assert(GNUNET_OK == 144 GNUNET_assert (GNUNET_OK ==
144 GNUNET_CONTAINER_multihashmap32_remove(cache, (uint32_t) 145 GNUNET_CONTAINER_multihashmap32_remove (cache, (uint32_t)
145 entry->peer_id, 146 entry->peer_id,
146 entry)); 147 entry));
147 free_entry(entry); 148 free_entry (entry);
148 } 149 }
149 entry = GNUNET_new(struct CacheEntry); 150 entry = GNUNET_new (struct CacheEntry);
150 entry->peer_id = peer_id; 151 entry->peer_id = peer_id;
151 GNUNET_assert(GNUNET_OK == 152 GNUNET_assert (GNUNET_OK ==
152 GNUNET_CONTAINER_multihashmap32_put(cache, 153 GNUNET_CONTAINER_multihashmap32_put (cache,
153 (uint32_t)peer_id, 154 (uint32_t) peer_id,
154 entry, 155 entry,
155 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 156 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
156 GNUNET_CONTAINER_DLL_insert_tail(cache_head, cache_tail, entry); 157 GNUNET_CONTAINER_DLL_insert_tail (cache_head, cache_tail, entry);
157 return entry; 158 return entry;
158} 159}
159 160
@@ -169,14 +170,14 @@ add_entry(unsigned int peer_id)
169 * GNUNET_NO if not. 170 * GNUNET_NO if not.
170 */ 171 */
171static int 172static int
172cache_clear_iterator(void *cls, uint32_t key, void *value) 173cache_clear_iterator (void *cls, uint32_t key, void *value)
173{ 174{
174 struct CacheEntry *entry = value; 175 struct CacheEntry *entry = value;
175 176
176 GNUNET_assert(NULL != entry); 177 GNUNET_assert (NULL != entry);
177 GNUNET_assert(GNUNET_YES == 178 GNUNET_assert (GNUNET_YES ==
178 GNUNET_CONTAINER_multihashmap32_remove(cache, key, value)); 179 GNUNET_CONTAINER_multihashmap32_remove (cache, key, value));
179 free_entry(entry); 180 free_entry (entry);
180 return GNUNET_YES; 181 return GNUNET_YES;
181} 182}
182 183
@@ -185,15 +186,16 @@ cache_clear_iterator(void *cls, uint32_t key, void *value)
185 * Clear cache 186 * Clear cache
186 */ 187 */
187void 188void
188GST_cache_clear() 189GST_cache_clear ()
189{ 190{
190 if (NULL != cache) 191 if (NULL != cache)
191 { 192 {
192 GNUNET_CONTAINER_multihashmap32_iterate(cache, &cache_clear_iterator, NULL); 193 GNUNET_CONTAINER_multihashmap32_iterate (cache, &cache_clear_iterator,
193 GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap32_size(cache)); 194 NULL);
194 GNUNET_CONTAINER_multihashmap32_destroy(cache); 195 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (cache));
195 cache = NULL; 196 GNUNET_CONTAINER_multihashmap32_destroy (cache);
196 } 197 cache = NULL;
198 }
197 cache_size = 0; 199 cache_size = 0;
198 cache_head = NULL; 200 cache_head = NULL;
199 cache_tail = NULL; 201 cache_tail = NULL;
@@ -206,12 +208,12 @@ GST_cache_clear()
206 * @param size the size of the cache 208 * @param size the size of the cache
207 */ 209 */
208void 210void
209GST_cache_init(unsigned int size) 211GST_cache_init (unsigned int size)
210{ 212{
211 if (0 == size) 213 if (0 == size)
212 return; 214 return;
213 cache_size = size; 215 cache_size = size;
214 cache = GNUNET_CONTAINER_multihashmap32_create(cache_size); 216 cache = GNUNET_CONTAINER_multihashmap32_create (cache_size);
215} 217}
216 218
217 219
@@ -222,21 +224,21 @@ GST_cache_init(unsigned int size)
222 * @return the HELLO message; NULL if not found 224 * @return the HELLO message; NULL if not found
223 */ 225 */
224const struct GNUNET_MessageHeader * 226const struct GNUNET_MessageHeader *
225GST_cache_lookup_hello(const unsigned int peer_id) 227GST_cache_lookup_hello (const unsigned int peer_id)
226{ 228{
227 struct CacheEntry *entry; 229 struct CacheEntry *entry;
228 230
229 LOG_DEBUG("Looking up HELLO for peer %u\n", peer_id); 231 LOG_DEBUG ("Looking up HELLO for peer %u\n", peer_id);
230 if (NULL == cache) 232 if (NULL == cache)
231 { 233 {
232 LOG_DEBUG("Caching disabled\n"); 234 LOG_DEBUG ("Caching disabled\n");
233 return NULL; 235 return NULL;
234 } 236 }
235 entry = cache_lookup(peer_id); 237 entry = cache_lookup (peer_id);
236 if (NULL == entry) 238 if (NULL == entry)
237 return NULL; 239 return NULL;
238 if (NULL != entry->hello) 240 if (NULL != entry->hello)
239 LOG_DEBUG("HELLO found for peer %u\n", peer_id); 241 LOG_DEBUG ("HELLO found for peer %u\n", peer_id);
240 return entry->hello; 242 return entry->hello;
241} 243}
242 244
@@ -249,18 +251,18 @@ GST_cache_lookup_hello(const unsigned int peer_id)
249 * @param hello the HELLO message 251 * @param hello the HELLO message
250 */ 252 */
251void 253void
252GST_cache_add_hello(const unsigned int peer_id, 254GST_cache_add_hello (const unsigned int peer_id,
253 const struct GNUNET_MessageHeader *hello) 255 const struct GNUNET_MessageHeader *hello)
254{ 256{
255 struct CacheEntry *entry; 257 struct CacheEntry *entry;
256 258
257 if (NULL == cache) 259 if (NULL == cache)
258 return; 260 return;
259 entry = cache_lookup(peer_id); 261 entry = cache_lookup (peer_id);
260 if (NULL == entry) 262 if (NULL == entry)
261 entry = add_entry(peer_id); 263 entry = add_entry (peer_id);
262 GNUNET_free_non_null(entry->hello); 264 GNUNET_free_non_null (entry->hello);
263 entry->hello = GNUNET_copy_message(hello); 265 entry->hello = GNUNET_copy_message (hello);
264} 266}
265 267
266/* end of gnunet-service-testbed_hc.c */ 268/* 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 fdb10f987..7f9c9fd57 100644
--- a/src/testbed/gnunet-service-testbed_connectionpool.c
+++ b/src/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,7 +55,8 @@ struct GST_ConnectionPool_GetHandle;
55/** 55/**
56 * A pooled connection 56 * A pooled connection
57 */ 57 */
58struct PooledConnection { 58struct PooledConnection
59{
59 /** 60 /**
60 * Next ptr for placing this object in the DLL of least recently used pooled 61 * Next ptr for placing this object in the DLL of least recently used pooled
61 * connections 62 * connections
@@ -168,7 +169,8 @@ struct PooledConnection {
168/** 169/**
169 * The request handle for obtaining a pooled connection 170 * The request handle for obtaining a pooled connection
170 */ 171 */
171struct GST_ConnectionPool_GetHandle { 172struct GST_ConnectionPool_GetHandle
173{
172 /** 174 /**
173 * The next ptr for inclusion in the notification DLLs. At first the object 175 * The next ptr for inclusion in the notification DLLs. At first the object
174 * is placed in the waiting DLL of the corresponding #PooledConnection 176 * is placed in the waiting DLL of the corresponding #PooledConnection
@@ -272,7 +274,7 @@ static unsigned int max_size;
272 * @param entry the #PooledConnection object 274 * @param entry the #PooledConnection object
273 */ 275 */
274static void 276static void
275expire_task_cancel(struct PooledConnection *entry); 277expire_task_cancel (struct PooledConnection *entry);
276 278
277 279
278/** 280/**
@@ -281,49 +283,49 @@ expire_task_cancel(struct PooledConnection *entry);
281 * @param entry the #PooledConnection object 283 * @param entry the #PooledConnection object
282 */ 284 */
283static void 285static void
284destroy_pooled_connection(struct PooledConnection *entry) 286destroy_pooled_connection (struct PooledConnection *entry)
285{ 287{
286 GNUNET_assert((NULL == entry->head_notify) && (NULL == entry->tail_notify)); 288 GNUNET_assert ((NULL == entry->head_notify) && (NULL == entry->tail_notify));
287 GNUNET_assert((NULL == entry->head_waiting) && 289 GNUNET_assert ((NULL == entry->head_waiting) &&
288 (NULL == entry->tail_waiting)); 290 (NULL == entry->tail_waiting));
289 GNUNET_assert(0 == entry->demand); 291 GNUNET_assert (0 == entry->demand);
290 expire_task_cancel(entry); 292 expire_task_cancel (entry);
291 if (entry->in_lru) 293 if (entry->in_lru)
292 GNUNET_CONTAINER_DLL_remove(head_lru, tail_lru, entry); 294 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
293 if (entry->in_pool) 295 if (entry->in_pool)
294 GNUNET_assert( 296 GNUNET_assert (
295 GNUNET_OK == 297 GNUNET_OK ==
296 GNUNET_CONTAINER_multihashmap32_remove(map, entry->index, entry)); 298 GNUNET_CONTAINER_multihashmap32_remove (map, entry->index, entry));
297 if (NULL != entry->notify_task) 299 if (NULL != entry->notify_task)
298 { 300 {
299 GNUNET_SCHEDULER_cancel(entry->notify_task); 301 GNUNET_SCHEDULER_cancel (entry->notify_task);
300 entry->notify_task = NULL; 302 entry->notify_task = NULL;
301 } 303 }
302 LOG_DEBUG("Cleaning up handles of a pooled connection\n"); 304 LOG_DEBUG ("Cleaning up handles of a pooled connection\n");
303 if (NULL != entry->handle_transport) 305 if (NULL != entry->handle_transport)
304 GNUNET_assert(NULL != entry->op_transport); 306 GNUNET_assert (NULL != entry->op_transport);
305 if (NULL != entry->op_transport) 307 if (NULL != entry->op_transport)
306 { 308 {
307 GNUNET_TESTBED_operation_done(entry->op_transport); 309 GNUNET_TESTBED_operation_done (entry->op_transport);
308 entry->op_transport = NULL; 310 entry->op_transport = NULL;
309 } 311 }
310 if (NULL != entry->handle_ats_connectivity) 312 if (NULL != entry->handle_ats_connectivity)
311 GNUNET_assert(NULL != entry->op_ats_connectivity); 313 GNUNET_assert (NULL != entry->op_ats_connectivity);
312 if (NULL != entry->op_ats_connectivity) 314 if (NULL != entry->op_ats_connectivity)
313 { 315 {
314 GNUNET_TESTBED_operation_done(entry->op_ats_connectivity); 316 GNUNET_TESTBED_operation_done (entry->op_ats_connectivity);
315 entry->op_ats_connectivity = NULL; 317 entry->op_ats_connectivity = NULL;
316 } 318 }
317 if (NULL != entry->op_core) 319 if (NULL != entry->op_core)
318 { 320 {
319 GNUNET_TESTBED_operation_done(entry->op_core); 321 GNUNET_TESTBED_operation_done (entry->op_core);
320 entry->op_core = NULL; 322 entry->op_core = NULL;
321 } 323 }
322 GNUNET_assert(NULL == entry->handle_core); 324 GNUNET_assert (NULL == entry->handle_core);
323 GNUNET_assert(NULL == entry->handle_ats_connectivity); 325 GNUNET_assert (NULL == entry->handle_ats_connectivity);
324 GNUNET_assert(NULL == entry->handle_transport); 326 GNUNET_assert (NULL == entry->handle_transport);
325 GNUNET_CONFIGURATION_destroy(entry->cfg); 327 GNUNET_CONFIGURATION_destroy (entry->cfg);
326 GNUNET_free(entry); 328 GNUNET_free (entry);
327} 329}
328 330
329 331
@@ -333,12 +335,12 @@ destroy_pooled_connection(struct PooledConnection *entry)
333 * @param cls the #PooledConnection object 335 * @param cls the #PooledConnection object
334 */ 336 */
335static void 337static void
336expire(void *cls) 338expire (void *cls)
337{ 339{
338 struct PooledConnection *entry = cls; 340 struct PooledConnection *entry = cls;
339 341
340 entry->expire_task = NULL; 342 entry->expire_task = NULL;
341 destroy_pooled_connection(entry); 343 destroy_pooled_connection (entry);
342} 344}
343 345
344 346
@@ -348,13 +350,13 @@ expire(void *cls)
348 * @param entry the #PooledConnection object 350 * @param entry the #PooledConnection object
349 */ 351 */
350static void 352static void
351expire_task_cancel(struct PooledConnection *entry) 353expire_task_cancel (struct PooledConnection *entry)
352{ 354{
353 if (NULL != entry->expire_task) 355 if (NULL != entry->expire_task)
354 { 356 {
355 GNUNET_SCHEDULER_cancel(entry->expire_task); 357 GNUNET_SCHEDULER_cancel (entry->expire_task);
356 entry->expire_task = NULL; 358 entry->expire_task = NULL;
357 } 359 }
358} 360}
359 361
360 362
@@ -364,15 +366,15 @@ expire_task_cancel(struct PooledConnection *entry)
364 * @param entry the #PooledConnection object 366 * @param entry the #PooledConnection object
365 */ 367 */
366static void 368static void
367add_to_lru(struct PooledConnection *entry) 369add_to_lru (struct PooledConnection *entry)
368{ 370{
369 GNUNET_assert(0 == entry->demand); 371 GNUNET_assert (0 == entry->demand);
370 GNUNET_assert(!entry->in_lru); 372 GNUNET_assert (! entry->in_lru);
371 GNUNET_CONTAINER_DLL_insert_tail(head_lru, tail_lru, entry); 373 GNUNET_CONTAINER_DLL_insert_tail (head_lru, tail_lru, entry);
372 entry->in_lru = GNUNET_YES; 374 entry->in_lru = GNUNET_YES;
373 GNUNET_assert(NULL == entry->expire_task); 375 GNUNET_assert (NULL == entry->expire_task);
374 entry->expire_task = 376 entry->expire_task =
375 GNUNET_SCHEDULER_add_delayed(CACHE_EXPIRY, &expire, entry); 377 GNUNET_SCHEDULER_add_delayed (CACHE_EXPIRY, &expire, entry);
376} 378}
377 379
378 380
@@ -388,34 +390,34 @@ add_to_lru(struct PooledConnection *entry)
388 * is found 390 * is found
389 */ 391 */
390static struct GST_ConnectionPool_GetHandle * 392static struct GST_ConnectionPool_GetHandle *
391search_waiting(const struct PooledConnection *entry, 393search_waiting (const struct PooledConnection *entry,
392 struct GST_ConnectionPool_GetHandle *head) 394 struct GST_ConnectionPool_GetHandle *head)
393{ 395{
394 struct GST_ConnectionPool_GetHandle *gh; 396 struct GST_ConnectionPool_GetHandle *gh;
395 397
396 for (gh = head; NULL != gh; gh = gh->next) 398 for (gh = head; NULL != gh; gh = gh->next)
399 {
400 switch (gh->service)
397 { 401 {
398 switch (gh->service) 402 case GST_CONNECTIONPOOL_SERVICE_CORE:
399 { 403 if (NULL == entry->handle_core)
400 case GST_CONNECTIONPOOL_SERVICE_CORE: 404 continue;
401 if (NULL == entry->handle_core) 405 if (NULL == entry->peer_identity)
402 continue; 406 continue; /* CORE connection isn't ready yet */
403 if (NULL == entry->peer_identity) 407 break;
404 continue; /* CORE connection isn't ready yet */ 408
405 break; 409 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT:
406 410 if (NULL == entry->handle_transport)
407 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: 411 continue;
408 if (NULL == entry->handle_transport) 412 break;
409 continue; 413
410 break; 414 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY:
411 415 if (NULL == entry->handle_ats_connectivity)
412 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: 416 continue;
413 if (NULL == entry->handle_ats_connectivity)
414 continue;
415 break;
416 }
417 break; 417 break;
418 } 418 }
419 break;
420 }
419 return gh; 421 return gh;
420} 422}
421 423
@@ -430,37 +432,37 @@ search_waiting(const struct PooledConnection *entry,
430 * @param cls the #PooledConnection object 432 * @param cls the #PooledConnection object
431 */ 433 */
432static void 434static void
433connection_ready(void *cls) 435connection_ready (void *cls)
434{ 436{
435 struct PooledConnection *entry = cls; 437 struct PooledConnection *entry = cls;
436 struct GST_ConnectionPool_GetHandle *gh; 438 struct GST_ConnectionPool_GetHandle *gh;
437 struct GST_ConnectionPool_GetHandle *gh_next; 439 struct GST_ConnectionPool_GetHandle *gh_next;
438 440
439 GNUNET_assert(NULL != entry->notify_task); 441 GNUNET_assert (NULL != entry->notify_task);
440 entry->notify_task = NULL; 442 entry->notify_task = NULL;
441 gh = search_waiting(entry, entry->head_waiting); 443 gh = search_waiting (entry, entry->head_waiting);
442 GNUNET_assert(NULL != gh); 444 GNUNET_assert (NULL != gh);
443 gh_next = NULL; 445 gh_next = NULL;
444 if (NULL != gh->next) 446 if (NULL != gh->next)
445 gh_next = search_waiting(entry, gh->next); 447 gh_next = search_waiting (entry, gh->next);
446 GNUNET_CONTAINER_DLL_remove(entry->head_waiting, entry->tail_waiting, gh); 448 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh);
447 gh->connection_ready_called = 1; 449 gh->connection_ready_called = 1;
448 if (NULL != gh_next) 450 if (NULL != gh_next)
449 entry->notify_task = GNUNET_SCHEDULER_add_now(&connection_ready, entry); 451 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry);
450 if ((NULL != gh->target) && (NULL != gh->connect_notify_cb)) 452 if ((NULL != gh->target) && (NULL != gh->connect_notify_cb))
451 { 453 {
452 GNUNET_CONTAINER_DLL_insert_tail(entry->head_notify, 454 GNUNET_CONTAINER_DLL_insert_tail (entry->head_notify,
453 entry->tail_notify, 455 entry->tail_notify,
454 gh); 456 gh);
455 gh->notify_waiting = 1; 457 gh->notify_waiting = 1;
456 } 458 }
457 LOG_DEBUG("Connection ready for handle type %u\n", gh->service); 459 LOG_DEBUG ("Connection ready for handle type %u\n", gh->service);
458 gh->cb(gh->cb_cls, 460 gh->cb (gh->cb_cls,
459 entry->handle_core, 461 entry->handle_core,
460 entry->handle_transport, 462 entry->handle_transport,
461 entry->handle_ats_connectivity, 463 entry->handle_ats_connectivity,
462 entry->peer_identity, 464 entry->peer_identity,
463 entry->cfg); 465 entry->cfg);
464} 466}
465 467
466 468
@@ -474,9 +476,9 @@ connection_ready(void *cls)
474 * @param service the service where this notification has originated 476 * @param service the service where this notification has originated
475 */ 477 */
476static void 478static void
477peer_connect_notify_cb(void *cls, 479peer_connect_notify_cb (void *cls,
478 const struct GNUNET_PeerIdentity *peer, 480 const struct GNUNET_PeerIdentity *peer,
479 const enum GST_ConnectionPool_Service service) 481 const enum GST_ConnectionPool_Service service)
480{ 482{
481 struct PooledConnection *entry = cls; 483 struct PooledConnection *entry = cls;
482 struct GST_ConnectionPool_GetHandle *gh; 484 struct GST_ConnectionPool_GetHandle *gh;
@@ -485,31 +487,31 @@ peer_connect_notify_cb(void *cls,
485 void *cb_cls; 487 void *cb_cls;
486 488
487 for (gh = entry->head_notify; NULL != gh;) 489 for (gh = entry->head_notify; NULL != gh;)
490 {
491 GNUNET_assert (NULL != gh->target);
492 GNUNET_assert (NULL != gh->connect_notify_cb);
493 GNUNET_assert (gh->connection_ready_called);
494 if (service != gh->service)
488 { 495 {
489 GNUNET_assert(NULL != gh->target); 496 gh = gh->next;
490 GNUNET_assert(NULL != gh->connect_notify_cb); 497 continue;
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);
512 } 498 }
499 if (0 != memcmp (gh->target, peer, sizeof(struct GNUNET_PeerIdentity)))
500 {
501 gh = gh->next;
502 continue;
503 }
504 cb = gh->connect_notify_cb;
505 cb_cls = gh->connect_notify_cb_cls;
506 gh_next = gh->next;
507 GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh);
508 gh->notify_waiting = 0;
509 LOG_DEBUG ("Peer connected to peer %u at service %u\n",
510 entry->index,
511 gh->service);
512 gh = gh_next;
513 cb (cb_cls, peer);
514 }
513} 515}
514 516
515 517
@@ -523,13 +525,13 @@ peer_connect_notify_cb(void *cls,
523 * @return NULL 525 * @return NULL
524 */ 526 */
525static void * 527static void *
526transport_peer_connect_notify_cb(void *cls, 528transport_peer_connect_notify_cb (void *cls,
527 const struct GNUNET_PeerIdentity *peer, 529 const struct GNUNET_PeerIdentity *peer,
528 struct GNUNET_MQ_Handle *mq) 530 struct GNUNET_MQ_Handle *mq)
529{ 531{
530 struct PooledConnection *entry = cls; 532 struct PooledConnection *entry = cls;
531 533
532 peer_connect_notify_cb(entry, peer, GST_CONNECTIONPOOL_SERVICE_TRANSPORT); 534 peer_connect_notify_cb (entry, peer, GST_CONNECTIONPOOL_SERVICE_TRANSPORT);
533 return NULL; 535 return NULL;
534} 536}
535 537
@@ -541,34 +543,34 @@ transport_peer_connect_notify_cb(void *cls,
541 * @param cls the #PooledConnection object 543 * @param cls the #PooledConnection object
542 */ 544 */
543static void 545static void
544opstart_get_handle_transport(void *cls) 546opstart_get_handle_transport (void *cls)
545{ 547{
546 struct PooledConnection *entry = cls; 548 struct PooledConnection *entry = cls;
547 549
548 GNUNET_assert(NULL != entry); 550 GNUNET_assert (NULL != entry);
549 LOG_DEBUG("Opening a transport connection to peer %u\n", entry->index); 551 LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->index);
550 entry->handle_transport = 552 entry->handle_transport =
551 GNUNET_TRANSPORT_core_connect(entry->cfg, 553 GNUNET_TRANSPORT_core_connect (entry->cfg,
552 NULL, 554 NULL,
553 NULL, 555 NULL,
554 entry, 556 entry,
555 &transport_peer_connect_notify_cb, 557 &transport_peer_connect_notify_cb,
556 NULL, 558 NULL,
557 NULL); 559 NULL);
558 if (NULL == entry->handle_transport) 560 if (NULL == entry->handle_transport)
559 { 561 {
560 GNUNET_break(0); 562 GNUNET_break (0);
561 return; 563 return;
562 } 564 }
563 if (0 == entry->demand) 565 if (0 == entry->demand)
564 return; 566 return;
565 if (NULL != entry->notify_task) 567 if (NULL != entry->notify_task)
566 return; 568 return;
567 if (NULL != search_waiting(entry, entry->head_waiting)) 569 if (NULL != search_waiting (entry, entry->head_waiting))
568 { 570 {
569 entry->notify_task = GNUNET_SCHEDULER_add_now(&connection_ready, entry); 571 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry);
570 return; 572 return;
571 } 573 }
572} 574}
573 575
574 576
@@ -579,13 +581,13 @@ opstart_get_handle_transport(void *cls)
579 * @param cls the cache entry 581 * @param cls the cache entry
580 */ 582 */
581static void 583static void
582oprelease_get_handle_transport(void *cls) 584oprelease_get_handle_transport (void *cls)
583{ 585{
584 struct PooledConnection *entry = cls; 586 struct PooledConnection *entry = cls;
585 587
586 if (NULL == entry->handle_transport) 588 if (NULL == entry->handle_transport)
587 return; 589 return;
588 GNUNET_TRANSPORT_core_disconnect(entry->handle_transport); 590 GNUNET_TRANSPORT_core_disconnect (entry->handle_transport);
589 entry->handle_transport = NULL; 591 entry->handle_transport = NULL;
590} 592}
591 593
@@ -599,14 +601,14 @@ oprelease_get_handle_transport(void *cls)
599 * @return peer 601 * @return peer
600 */ 602 */
601static void * 603static void *
602core_peer_connect_cb(void *cls, 604core_peer_connect_cb (void *cls,
603 const struct GNUNET_PeerIdentity *peer, 605 const struct GNUNET_PeerIdentity *peer,
604 struct GNUNET_MQ_Handle *mq) 606 struct GNUNET_MQ_Handle *mq)
605{ 607{
606 struct PooledConnection *entry = cls; 608 struct PooledConnection *entry = cls;
607 609
608 peer_connect_notify_cb(entry, peer, GST_CONNECTIONPOOL_SERVICE_CORE); 610 peer_connect_notify_cb (entry, peer, GST_CONNECTIONPOOL_SERVICE_CORE);
609 return (void *)peer; 611 return (void *) peer;
610} 612}
611 613
612 614
@@ -623,27 +625,27 @@ core_peer_connect_cb(void *cls,
623 * @param my_identity ID of this peer, NULL if we failed 625 * @param my_identity ID of this peer, NULL if we failed
624 */ 626 */
625static void 627static void
626core_startup_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity) 628core_startup_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity)
627{ 629{
628 struct PooledConnection *entry = cls; 630 struct PooledConnection *entry = cls;
629 631
630 if (NULL == my_identity) 632 if (NULL == my_identity)
631 { 633 {
632 GNUNET_break(0); 634 GNUNET_break (0);
633 return; 635 return;
634 } 636 }
635 GNUNET_assert(NULL == entry->peer_identity); 637 GNUNET_assert (NULL == entry->peer_identity);
636 entry->peer_identity = GNUNET_new(struct GNUNET_PeerIdentity); 638 entry->peer_identity = GNUNET_new (struct GNUNET_PeerIdentity);
637 *entry->peer_identity = *my_identity; 639 *entry->peer_identity = *my_identity;
638 if (0 == entry->demand) 640 if (0 == entry->demand)
639 return; 641 return;
640 if (NULL != entry->notify_task) 642 if (NULL != entry->notify_task)
641 return; 643 return;
642 if (NULL != search_waiting(entry, entry->head_waiting)) 644 if (NULL != search_waiting (entry, entry->head_waiting))
643 { 645 {
644 entry->notify_task = GNUNET_SCHEDULER_add_now(&connection_ready, entry); 646 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry);
645 return; 647 return;
646 } 648 }
647} 649}
648 650
649 651
@@ -654,19 +656,19 @@ core_startup_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity)
654 * @param cls the #PooledConnection object 656 * @param cls the #PooledConnection object
655 */ 657 */
656static void 658static void
657opstart_get_handle_core(void *cls) 659opstart_get_handle_core (void *cls)
658{ 660{
659 struct PooledConnection *entry = cls; 661 struct PooledConnection *entry = cls;
660 662
661 GNUNET_assert(NULL != entry); 663 GNUNET_assert (NULL != entry);
662 LOG_DEBUG("Opening a CORE connection to peer %u\n", entry->index); 664 LOG_DEBUG ("Opening a CORE connection to peer %u\n", entry->index);
663 entry->handle_core = 665 entry->handle_core =
664 GNUNET_CORE_connect(entry->cfg, 666 GNUNET_CORE_connect (entry->cfg,
665 entry, /* closure */ 667 entry, /* closure */
666 &core_startup_cb, /* core startup notify */ 668 &core_startup_cb, /* core startup notify */
667 &core_peer_connect_cb, /* peer connect notify */ 669 &core_peer_connect_cb, /* peer connect notify */
668 NULL, /* peer disconnect notify */ 670 NULL, /* peer disconnect notify */
669 NULL); 671 NULL);
670} 672}
671 673
672 674
@@ -677,15 +679,15 @@ opstart_get_handle_core(void *cls)
677 * @param cls the #PooledConnection object 679 * @param cls the #PooledConnection object
678 */ 680 */
679static void 681static void
680oprelease_get_handle_core(void *cls) 682oprelease_get_handle_core (void *cls)
681{ 683{
682 struct PooledConnection *entry = cls; 684 struct PooledConnection *entry = cls;
683 685
684 if (NULL == entry->handle_core) 686 if (NULL == entry->handle_core)
685 return; 687 return;
686 GNUNET_CORE_disconnect(entry->handle_core); 688 GNUNET_CORE_disconnect (entry->handle_core);
687 entry->handle_core = NULL; 689 entry->handle_core = NULL;
688 GNUNET_free_non_null(entry->peer_identity); 690 GNUNET_free_non_null (entry->peer_identity);
689 entry->peer_identity = NULL; 691 entry->peer_identity = NULL;
690} 692}
691 693
@@ -697,11 +699,11 @@ oprelease_get_handle_core(void *cls)
697 * @param cls the #PooledConnection object 699 * @param cls the #PooledConnection object
698 */ 700 */
699static void 701static void
700opstart_get_handle_ats_connectivity(void *cls) 702opstart_get_handle_ats_connectivity (void *cls)
701{ 703{
702 struct PooledConnection *entry = cls; 704 struct PooledConnection *entry = cls;
703 705
704 entry->handle_ats_connectivity = GNUNET_ATS_connectivity_init(entry->cfg); 706 entry->handle_ats_connectivity = GNUNET_ATS_connectivity_init (entry->cfg);
705} 707}
706 708
707 709
@@ -712,13 +714,13 @@ opstart_get_handle_ats_connectivity(void *cls)
712 * @param cls the #PooledConnection object 714 * @param cls the #PooledConnection object
713 */ 715 */
714static void 716static void
715oprelease_get_handle_ats_connectivity(void *cls) 717oprelease_get_handle_ats_connectivity (void *cls)
716{ 718{
717 struct PooledConnection *entry = cls; 719 struct PooledConnection *entry = cls;
718 720
719 if (NULL == entry->handle_ats_connectivity) 721 if (NULL == entry->handle_ats_connectivity)
720 return; 722 return;
721 GNUNET_ATS_connectivity_done(entry->handle_ats_connectivity); 723 GNUNET_ATS_connectivity_done (entry->handle_ats_connectivity);
722 entry->handle_ats_connectivity = NULL; 724 entry->handle_ats_connectivity = NULL;
723} 725}
724 726
@@ -734,12 +736,12 @@ oprelease_get_handle_ats_connectivity(void *cls)
734 * #GNUNET_NO if not. 736 * #GNUNET_NO if not.
735 */ 737 */
736static int 738static int
737cleanup_iterator(void *cls, uint32_t key, void *value) 739cleanup_iterator (void *cls, uint32_t key, void *value)
738{ 740{
739 struct PooledConnection *entry = value; 741 struct PooledConnection *entry = value;
740 742
741 GNUNET_assert(NULL != entry); 743 GNUNET_assert (NULL != entry);
742 destroy_pooled_connection(entry); 744 destroy_pooled_connection (entry);
743 return GNUNET_YES; 745 return GNUNET_YES;
744} 746}
745 747
@@ -752,13 +754,13 @@ cleanup_iterator(void *cls, uint32_t key, void *value)
752 * #GST_ConnectionPool_Service 754 * #GST_ConnectionPool_Service
753 */ 755 */
754void 756void
755GST_connection_pool_init(unsigned int size) 757GST_connection_pool_init (unsigned int size)
756{ 758{
757 max_size = size; 759 max_size = size;
758 if (0 == max_size) 760 if (0 == max_size)
759 return; 761 return;
760 GNUNET_assert(NULL == map); 762 GNUNET_assert (NULL == map);
761 map = GNUNET_CONTAINER_multihashmap32_create(((size * 3) / 4) + 1); 763 map = GNUNET_CONTAINER_multihashmap32_create (((size * 3) / 4) + 1);
762} 764}
763 765
764 766
@@ -766,24 +768,24 @@ GST_connection_pool_init(unsigned int size)
766 * Cleanup the connection pool 768 * Cleanup the connection pool
767 */ 769 */
768void 770void
769GST_connection_pool_destroy() 771GST_connection_pool_destroy ()
770{ 772{
771 struct PooledConnection *entry; 773 struct PooledConnection *entry;
772 774
773 if (NULL != map) 775 if (NULL != map)
774 { 776 {
775 GNUNET_assert( 777 GNUNET_assert (
776 GNUNET_SYSERR != 778 GNUNET_SYSERR !=
777 GNUNET_CONTAINER_multihashmap32_iterate(map, &cleanup_iterator, NULL)); 779 GNUNET_CONTAINER_multihashmap32_iterate (map, &cleanup_iterator, NULL));
778 GNUNET_CONTAINER_multihashmap32_destroy(map); 780 GNUNET_CONTAINER_multihashmap32_destroy (map);
779 map = NULL; 781 map = NULL;
780 } 782 }
781 while (NULL != (entry = head_lru)) 783 while (NULL != (entry = head_lru))
782 { 784 {
783 GNUNET_CONTAINER_DLL_remove(head_lru, tail_lru, entry); 785 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
784 destroy_pooled_connection(entry); 786 destroy_pooled_connection (entry);
785 } 787 }
786 GNUNET_assert(NULL == head_not_pooled); 788 GNUNET_assert (NULL == head_not_pooled);
787} 789}
788 790
789 791
@@ -820,7 +822,7 @@ GST_connection_pool_destroy()
820 * longer being used 822 * longer being used
821 */ 823 */
822struct GST_ConnectionPool_GetHandle * 824struct GST_ConnectionPool_GetHandle *
823GST_connection_pool_get_handle( 825GST_connection_pool_get_handle (
824 unsigned int peer_id, 826 unsigned int peer_id,
825 const struct GNUNET_CONFIGURATION_Handle *cfg, 827 const struct GNUNET_CONFIGURATION_Handle *cfg,
826 enum GST_ConnectionPool_Service service, 828 enum GST_ConnectionPool_Service service,
@@ -836,66 +838,66 @@ GST_connection_pool_get_handle(
836 void *handle; 838 void *handle;
837 uint32_t peer_id32; 839 uint32_t peer_id32;
838 840
839 peer_id32 = (uint32_t)peer_id; 841 peer_id32 = (uint32_t) peer_id;
840 handle = NULL; 842 handle = NULL;
841 entry = NULL; 843 entry = NULL;
842 if (NULL != map) 844 if (NULL != map)
843 entry = GNUNET_CONTAINER_multihashmap32_get(map, peer_id32); 845 entry = GNUNET_CONTAINER_multihashmap32_get (map, peer_id32);
844 if (NULL != entry) 846 if (NULL != entry)
847 {
848 if (entry->in_lru)
845 { 849 {
846 if (entry->in_lru) 850 GNUNET_assert (0 == entry->demand);
847 { 851 expire_task_cancel (entry);
848 GNUNET_assert(0 == entry->demand); 852 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
849 expire_task_cancel(entry); 853 entry->in_lru = GNUNET_NO;
850 GNUNET_CONTAINER_DLL_remove(head_lru, tail_lru, entry); 854 }
851 entry->in_lru = GNUNET_NO; 855 switch (service)
852 } 856 {
853 switch (service) 857 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT:
854 { 858 handle = entry->handle_transport;
855 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: 859 if (NULL != handle)
856 handle = entry->handle_transport; 860 LOG_DEBUG ("Found TRANSPORT handle for peer %u\n", entry->index);
857 if (NULL != handle) 861 break;
858 LOG_DEBUG("Found TRANSPORT handle for peer %u\n", entry->index); 862
859 break; 863 case GST_CONNECTIONPOOL_SERVICE_CORE:
860 864 handle = entry->handle_core;
861 case GST_CONNECTIONPOOL_SERVICE_CORE: 865 if (NULL != handle)
862 handle = entry->handle_core; 866 LOG_DEBUG ("Found CORE handle for peer %u\n", entry->index);
863 if (NULL != handle) 867 break;
864 LOG_DEBUG("Found CORE handle for peer %u\n", entry->index); 868
865 break; 869 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY:
866 870 handle = entry->handle_ats_connectivity;
867 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: 871 if (NULL != handle)
868 handle = entry->handle_ats_connectivity; 872 LOG_DEBUG ("Found ATS CONNECTIVITY handle for peer %u\n", entry->index);
869 if (NULL != handle) 873 break;
870 LOG_DEBUG("Found ATS CONNECTIVITY handle for peer %u\n", entry->index);
871 break;
872 }
873 } 874 }
875 }
874 else 876 else
877 {
878 entry = GNUNET_new (struct PooledConnection);
879 entry->index = peer_id32;
880 if ((NULL != map) &&
881 (GNUNET_CONTAINER_multihashmap32_size (map) < max_size))
882 {
883 GNUNET_assert (GNUNET_OK ==
884 GNUNET_CONTAINER_multihashmap32_put (
885 map,
886 entry->index,
887 entry,
888 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
889 entry->in_pool = GNUNET_YES;
890 }
891 else
875 { 892 {
876 entry = GNUNET_new(struct PooledConnection); 893 GNUNET_CONTAINER_DLL_insert_tail (head_not_pooled,
877 entry->index = peer_id32; 894 tail_not_pooled,
878 if ((NULL != map) && 895 entry);
879 (GNUNET_CONTAINER_multihashmap32_size(map) < max_size))
880 {
881 GNUNET_assert(GNUNET_OK ==
882 GNUNET_CONTAINER_multihashmap32_put(
883 map,
884 entry->index,
885 entry,
886 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
887 entry->in_pool = GNUNET_YES;
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);
896 } 896 }
897 entry->cfg = GNUNET_CONFIGURATION_dup (cfg);
898 }
897 entry->demand++; 899 entry->demand++;
898 gh = GNUNET_new(struct GST_ConnectionPool_GetHandle); 900 gh = GNUNET_new (struct GST_ConnectionPool_GetHandle);
899 gh->entry = entry; 901 gh->entry = entry;
900 gh->cb = cb; 902 gh->cb = cb;
901 gh->cb_cls = cb_cls; 903 gh->cb_cls = cb_cls;
@@ -903,50 +905,50 @@ GST_connection_pool_get_handle(
903 gh->connect_notify_cb = connect_notify_cb; 905 gh->connect_notify_cb = connect_notify_cb;
904 gh->connect_notify_cb_cls = connect_notify_cb_cls; 906 gh->connect_notify_cb_cls = connect_notify_cb_cls;
905 gh->service = service; 907 gh->service = service;
906 GNUNET_CONTAINER_DLL_insert(entry->head_waiting, entry->tail_waiting, gh); 908 GNUNET_CONTAINER_DLL_insert (entry->head_waiting, entry->tail_waiting, gh);
907 if (NULL != handle) 909 if (NULL != handle)
910 {
911 if (NULL == entry->notify_task)
908 { 912 {
909 if (NULL == entry->notify_task) 913 if (NULL != search_waiting (entry, entry->head_waiting))
910 { 914 entry->notify_task =
911 if (NULL != search_waiting(entry, entry->head_waiting)) 915 GNUNET_SCHEDULER_add_now (&connection_ready, entry);
912 entry->notify_task =
913 GNUNET_SCHEDULER_add_now(&connection_ready, entry);
914 }
915 return gh;
916 } 916 }
917 return gh;
918 }
917 op = NULL; 919 op = NULL;
918 switch (gh->service) 920 switch (gh->service)
919 { 921 {
920 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: 922 case GST_CONNECTIONPOOL_SERVICE_TRANSPORT:
921 if (NULL != entry->op_transport) 923 if (NULL != entry->op_transport)
922 return gh; /* Operation pending */ 924 return gh; /* Operation pending */
923 op = GNUNET_TESTBED_operation_create_(entry, 925 op = GNUNET_TESTBED_operation_create_ (entry,
924 &opstart_get_handle_transport, 926 &opstart_get_handle_transport,
925 &oprelease_get_handle_transport); 927 &oprelease_get_handle_transport);
926 entry->op_transport = op; 928 entry->op_transport = op;
927 break; 929 break;
928 930
929 case GST_CONNECTIONPOOL_SERVICE_CORE: 931 case GST_CONNECTIONPOOL_SERVICE_CORE:
930 if (NULL != entry->op_core) 932 if (NULL != entry->op_core)
931 return gh; /* Operation pending */ 933 return gh; /* Operation pending */
932 op = GNUNET_TESTBED_operation_create_(entry, 934 op = GNUNET_TESTBED_operation_create_ (entry,
933 &opstart_get_handle_core, 935 &opstart_get_handle_core,
934 &oprelease_get_handle_core); 936 &oprelease_get_handle_core);
935 entry->op_core = op; 937 entry->op_core = op;
936 break; 938 break;
937 939
938 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: 940 case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY:
939 if (NULL != entry->op_ats_connectivity) 941 if (NULL != entry->op_ats_connectivity)
940 return gh; /* Operation pending */ 942 return gh; /* Operation pending */
941 op = 943 op =
942 GNUNET_TESTBED_operation_create_(entry, 944 GNUNET_TESTBED_operation_create_ (entry,
943 &opstart_get_handle_ats_connectivity, 945 &opstart_get_handle_ats_connectivity,
944 &oprelease_get_handle_ats_connectivity); 946 &oprelease_get_handle_ats_connectivity);
945 entry->op_ats_connectivity = op; 947 entry->op_ats_connectivity = op;
946 break; 948 break;
947 } 949 }
948 GNUNET_TESTBED_operation_queue_insert_(GST_opq_openfds, op); 950 GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, op);
949 GNUNET_TESTBED_operation_begin_wait_(op); 951 GNUNET_TESTBED_operation_begin_wait_ (op);
950 return gh; 952 return gh;
951} 953}
952 954
@@ -964,66 +966,66 @@ GST_connection_pool_get_handle(
964 * @param gh the handle 966 * @param gh the handle
965 */ 967 */
966void 968void
967GST_connection_pool_get_handle_done(struct GST_ConnectionPool_GetHandle *gh) 969GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh)
968{ 970{
969 struct PooledConnection *entry; 971 struct PooledConnection *entry;
970 972
971 if (NULL == gh) 973 if (NULL == gh)
972 return; 974 return;
973 entry = gh->entry; 975 entry = gh->entry;
974 LOG_DEBUG("Cleaning up get handle %p for service %u, peer %u\n", 976 LOG_DEBUG ("Cleaning up get handle %p for service %u, peer %u\n",
975 gh, 977 gh,
976 gh->service, 978 gh->service,
977 entry->index); 979 entry->index);
978 if (!gh->connection_ready_called) 980 if (! gh->connection_ready_called)
981 {
982 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh);
983 if ((NULL == search_waiting (entry, entry->head_waiting)) &&
984 (NULL != entry->notify_task))
979 { 985 {
980 GNUNET_CONTAINER_DLL_remove(entry->head_waiting, entry->tail_waiting, gh); 986 GNUNET_SCHEDULER_cancel (entry->notify_task);
981 if ((NULL == search_waiting(entry, entry->head_waiting)) && 987 entry->notify_task = NULL;
982 (NULL != entry->notify_task))
983 {
984 GNUNET_SCHEDULER_cancel(entry->notify_task);
985 entry->notify_task = NULL;
986 }
987 } 988 }
989 }
988 if (gh->notify_waiting) 990 if (gh->notify_waiting)
989 { 991 {
990 GNUNET_CONTAINER_DLL_remove(entry->head_notify, entry->tail_notify, gh); 992 GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh);
991 gh->notify_waiting = 0; 993 gh->notify_waiting = 0;
992 } 994 }
993 GNUNET_free(gh); 995 GNUNET_free (gh);
994 gh = NULL; 996 gh = NULL;
995 GNUNET_assert(!entry->in_lru); 997 GNUNET_assert (! entry->in_lru);
996 if (!entry->in_pool) 998 if (! entry->in_pool)
997 GNUNET_CONTAINER_DLL_remove(head_not_pooled, tail_not_pooled, entry); 999 GNUNET_CONTAINER_DLL_remove (head_not_pooled, tail_not_pooled, entry);
998 if (NULL != map) 1000 if (NULL != map)
1001 {
1002 if (GNUNET_YES ==
1003 GNUNET_CONTAINER_multihashmap32_contains (map, entry->index))
1004 goto unallocate;
1005 if (GNUNET_CONTAINER_multihashmap32_size (map) == max_size)
999 { 1006 {
1000 if (GNUNET_YES == 1007 if (NULL == head_lru)
1001 GNUNET_CONTAINER_multihashmap32_contains(map, entry->index))
1002 goto unallocate; 1008 goto unallocate;
1003 if (GNUNET_CONTAINER_multihashmap32_size(map) == max_size) 1009 destroy_pooled_connection (head_lru);
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;
1016 } 1010 }
1011 GNUNET_assert (GNUNET_OK ==
1012 GNUNET_CONTAINER_multihashmap32_put (
1013 map,
1014 entry->index,
1015 entry,
1016 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1017 entry->in_pool = GNUNET_YES;
1018 }
1017 1019
1018unallocate: 1020unallocate:
1019 GNUNET_assert(0 < entry->demand); 1021 GNUNET_assert (0 < entry->demand);
1020 entry->demand--; 1022 entry->demand--;
1021 if (0 != entry->demand) 1023 if (0 != entry->demand)
1022 return; 1024 return;
1023 if (entry->in_pool) 1025 if (entry->in_pool)
1024 { 1026 {
1025 add_to_lru(entry); 1027 add_to_lru (entry);
1026 return; 1028 return;
1027 } 1029 }
1028 destroy_pooled_connection(entry); 1030 destroy_pooled_connection (entry);
1029} 1031}
diff --git a/src/testbed/gnunet-service-testbed_connectionpool.h b/src/testbed/gnunet-service-testbed_connectionpool.h
index 40c937353..cbab151be 100644
--- a/src/testbed/gnunet-service-testbed_connectionpool.h
+++ b/src/testbed/gnunet-service-testbed_connectionpool.h
@@ -36,7 +36,8 @@ struct GST_ConnectionPool_GetHandle;
36/** 36/**
37 * The type of service 37 * The type of service
38 */ 38 */
39enum GST_ConnectionPool_Service { 39enum GST_ConnectionPool_Service
40{
40 /** 41 /**
41 * Transport service 42 * Transport service
42 */ 43 */
@@ -62,14 +63,14 @@ enum GST_ConnectionPool_Service {
62 * #GST_ConnectionPool_Service 63 * #GST_ConnectionPool_Service
63 */ 64 */
64void 65void
65GST_connection_pool_init(unsigned int size); 66GST_connection_pool_init (unsigned int size);
66 67
67 68
68/** 69/**
69 * Cleanup the connection pool 70 * Cleanup the connection pool
70 */ 71 */
71void 72void
72GST_connection_pool_destroy(void); 73GST_connection_pool_destroy (void);
73 74
74/** 75/**
75 * Functions of this type are called when the needed handle is available for 76 * Functions of this type are called when the needed handle is available for
@@ -141,7 +142,7 @@ typedef void (*GST_connection_pool_peer_connect_notify) (
141 * longer being used 142 * longer being used
142 */ 143 */
143struct GST_ConnectionPool_GetHandle * 144struct GST_ConnectionPool_GetHandle *
144GST_connection_pool_get_handle( 145GST_connection_pool_get_handle (
145 unsigned int peer_id, 146 unsigned int peer_id,
146 const struct GNUNET_CONFIGURATION_Handle *cfg, 147 const struct GNUNET_CONFIGURATION_Handle *cfg,
147 enum GST_ConnectionPool_Service service, 148 enum GST_ConnectionPool_Service service,
@@ -165,7 +166,7 @@ GST_connection_pool_get_handle(
165 * @param gh the handle 166 * @param gh the handle
166 */ 167 */
167void 168void
168GST_connection_pool_get_handle_done(struct GST_ConnectionPool_GetHandle *gh); 169GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh);
169 170
170 171
171/* End of gnunet-service-testbed_connectionpool.h */ 172/* 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 f3df9a96e..ae6450176 100644
--- a/src/testbed/gnunet-service-testbed_cpustatus.c
+++ b/src/testbed/gnunet-service-testbed_cpustatus.c
@@ -82,12 +82,12 @@ static double agedIOLoad = -1;
82 */ 82 */
83struct GNUNET_BIO_WriteHandle *bw; 83struct GNUNET_BIO_WriteHandle *bw;
84 84
85struct GNUNET_SCHEDULER_Task * sample_load_task_id; 85struct GNUNET_SCHEDULER_Task *sample_load_task_id;
86 86
87 87
88#ifdef OSX 88#ifdef OSX
89static int 89static int
90initMachCpuStats() 90initMachCpuStats ()
91{ 91{
92 unsigned int cpu_count; 92 unsigned int cpu_count;
93 processor_cpu_load_info_t cpu_load; 93 processor_cpu_load_info_t cpu_load;
@@ -95,27 +95,27 @@ initMachCpuStats()
95 kern_return_t kret; 95 kern_return_t kret;
96 int i, j; 96 int i, j;
97 97
98 kret = host_processor_info(mach_host_self(), 98 kret = host_processor_info (mach_host_self (),
99 PROCESSOR_CPU_LOAD_INFO, 99 PROCESSOR_CPU_LOAD_INFO,
100 &cpu_count, 100 &cpu_count,
101 (processor_info_array_t *)&cpu_load, 101 (processor_info_array_t *) &cpu_load,
102 &cpu_msg_count); 102 &cpu_msg_count);
103 if (kret != KERN_SUCCESS) 103 if (kret != KERN_SUCCESS)
104 { 104 {
105 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "host_processor_info failed."); 105 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "host_processor_info failed.");
106 return GNUNET_SYSERR; 106 return GNUNET_SYSERR;
107 } 107 }
108 prev_cpu_load = GNUNET_malloc(cpu_count * sizeof(*prev_cpu_load)); 108 prev_cpu_load = GNUNET_malloc (cpu_count * sizeof(*prev_cpu_load));
109 for (i = 0; i < cpu_count; i++) 109 for (i = 0; i < cpu_count; i++)
110 {
111 for (j = 0; j < CPU_STATE_MAX; j++)
110 { 112 {
111 for (j = 0; j < CPU_STATE_MAX; j++) 113 prev_cpu_load[i].cpu_ticks[j] = cpu_load[i].cpu_ticks[j];
112 {
113 prev_cpu_load[i].cpu_ticks[j] = cpu_load[i].cpu_ticks[j];
114 }
115 } 114 }
116 vm_deallocate(mach_task_self(), 115 }
117 (vm_address_t)cpu_load, 116 vm_deallocate (mach_task_self (),
118 (vm_size_t)(cpu_msg_count * sizeof(*cpu_load))); 117 (vm_address_t) cpu_load,
118 (vm_size_t) (cpu_msg_count * sizeof(*cpu_load)));
119 return GNUNET_OK; 119 return GNUNET_OK;
120} 120}
121#endif 121#endif
@@ -127,7 +127,7 @@ initMachCpuStats()
127 * If there is an error the method returns -1. 127 * If there is an error the method returns -1.
128 */ 128 */
129static int 129static int
130updateUsage() 130updateUsage ()
131{ 131{
132 currentIOLoad = -1; 132 currentIOLoad = -1;
133 currentCPULoad = -1; 133 currentCPULoad = -1;
@@ -136,69 +136,69 @@ updateUsage()
136 if that does not work, disable /proc/stat for the future 136 if that does not work, disable /proc/stat for the future
137 by closing the file and use the next-best method. */ 137 by closing the file and use the next-best method. */
138 if (proc_stat != NULL) 138 if (proc_stat != NULL)
139 {
140 static unsigned long long last_cpu_results[5] = { 0, 0, 0, 0, 0 };
141 static int have_last_cpu = GNUNET_NO;
142 int ret;
143 char line[256];
144 unsigned long long user_read, system_read, nice_read, idle_read,
145 iowait_read;
146 unsigned long long user, system, nice, idle, iowait;
147 unsigned long long usage_time = 0, total_time = 1;
148
149 /* Get the first line with the data */
150 rewind (proc_stat);
151 fflush (proc_stat);
152 if (NULL == fgets (line, 256, proc_stat))
139 { 153 {
140 static unsigned long long last_cpu_results[5] = { 0, 0, 0, 0, 0 }; 154 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
141 static int have_last_cpu = GNUNET_NO; 155 "fgets", "/proc/stat");
142 int ret; 156 proc_stat = NULL; /* don't try again */
143 char line[256]; 157 }
144 unsigned long long user_read, system_read, nice_read, idle_read, 158 else
145 iowait_read; 159 {
146 unsigned long long user, system, nice, idle, iowait; 160 iowait_read = 0;
147 unsigned long long usage_time = 0, total_time = 1; 161 ret = sscanf (line, "%*s %llu %llu %llu %llu %llu",
148 162 &user_read,
149 /* Get the first line with the data */ 163 &system_read, &nice_read, &idle_read, &iowait_read);
150 rewind(proc_stat); 164 if (ret < 4)
151 fflush(proc_stat); 165 {
152 if (NULL == fgets(line, 256, proc_stat)) 166 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
153 { 167 "fgets-sscanf", "/proc/stat");
154 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, 168 fclose (proc_stat);
155 "fgets", "/proc/stat"); 169 proc_stat = NULL; /* don't try again */
156 proc_stat = NULL; /* don't try again */ 170 have_last_cpu = GNUNET_NO;
157 } 171 }
158 else 172 else
173 {
174 /* Store the current usage */
175 user = user_read - last_cpu_results[0];
176 system = system_read - last_cpu_results[1];
177 nice = nice_read - last_cpu_results[2];
178 idle = idle_read - last_cpu_results[3];
179 iowait = iowait_read - last_cpu_results[4];
180 /* Calculate the % usage */
181 usage_time = user + system + nice;
182 total_time = usage_time + idle + iowait;
183 if ((total_time > 0) && (have_last_cpu == GNUNET_YES))
159 { 184 {
160 iowait_read = 0; 185 currentCPULoad = (int) (100L * usage_time / total_time);
161 ret = sscanf(line, "%*s %llu %llu %llu %llu %llu", 186 if (ret > 4)
162 &user_read, 187 currentIOLoad = (int) (100L * iowait / total_time);
163 &system_read, &nice_read, &idle_read, &iowait_read);
164 if (ret < 4)
165 {
166 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING,
167 "fgets-sscanf", "/proc/stat");
168 fclose(proc_stat);
169 proc_stat = NULL; /* don't try again */
170 have_last_cpu = GNUNET_NO;
171 }
172 else 188 else
173 { 189 currentIOLoad = -1; /* 2.4 kernel */
174 /* Store the current usage */
175 user = user_read - last_cpu_results[0];
176 system = system_read - last_cpu_results[1];
177 nice = nice_read - last_cpu_results[2];
178 idle = idle_read - last_cpu_results[3];
179 iowait = iowait_read - last_cpu_results[4];
180 /* Calculate the % usage */
181 usage_time = user + system + nice;
182 total_time = usage_time + idle + iowait;
183 if ((total_time > 0) && (have_last_cpu == GNUNET_YES))
184 {
185 currentCPULoad = (int)(100L * usage_time / total_time);
186 if (ret > 4)
187 currentIOLoad = (int)(100L * iowait / total_time);
188 else
189 currentIOLoad = -1; /* 2.4 kernel */
190 }
191 /* Store the values for the next calculation */
192 last_cpu_results[0] = user_read;
193 last_cpu_results[1] = system_read;
194 last_cpu_results[2] = nice_read;
195 last_cpu_results[3] = idle_read;
196 last_cpu_results[4] = iowait_read;
197 have_last_cpu = GNUNET_YES;
198 return GNUNET_OK;
199 }
200 } 190 }
191 /* Store the values for the next calculation */
192 last_cpu_results[0] = user_read;
193 last_cpu_results[1] = system_read;
194 last_cpu_results[2] = nice_read;
195 last_cpu_results[3] = idle_read;
196 last_cpu_results[4] = iowait_read;
197 have_last_cpu = GNUNET_YES;
198 return GNUNET_OK;
199 }
201 } 200 }
201 }
202#endif 202#endif
203 203
204#ifdef OSX 204#ifdef OSX
@@ -212,91 +212,91 @@ updateUsage()
212 int i, j; 212 int i, j;
213 213
214 t_idle_all = t_total_all = 0; 214 t_idle_all = t_total_all = 0;
215 kret = host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, 215 kret = host_processor_info (mach_host_self (), PROCESSOR_CPU_LOAD_INFO,
216 &cpu_count, 216 &cpu_count,
217 (processor_info_array_t *)&cpu_load, 217 (processor_info_array_t *) &cpu_load,
218 &cpu_msg_count); 218 &cpu_msg_count);
219 if (kret == KERN_SUCCESS) 219 if (kret == KERN_SUCCESS)
220 {
221 for (i = 0; i < cpu_count; i++)
220 { 222 {
221 for (i = 0; i < cpu_count; i++) 223 if (cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM] >=
222 { 224 prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM])
223 if (cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM] >= 225 {
224 prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM]) 226 t_sys = cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM]
225 { 227 - prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM];
226 t_sys = cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM] - 228 }
227 prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM];
228 }
229 else
230 {
231 t_sys = cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM] +
232 (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM] +
233 1);
234 }
235
236 if (cpu_load[i].cpu_ticks[CPU_STATE_USER] >=
237 prev_cpu_load[i].cpu_ticks[CPU_STATE_USER])
238 {
239 t_user = cpu_load[i].cpu_ticks[CPU_STATE_USER] -
240 prev_cpu_load[i].cpu_ticks[CPU_STATE_USER];
241 }
242 else
243 {
244 t_user = cpu_load[i].cpu_ticks[CPU_STATE_USER] +
245 (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_USER] +
246 1);
247 }
248
249 if (cpu_load[i].cpu_ticks[CPU_STATE_NICE] >=
250 prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE])
251 {
252 t_nice = cpu_load[i].cpu_ticks[CPU_STATE_NICE] -
253 prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE];
254 }
255 else
256 {
257 t_nice = cpu_load[i].cpu_ticks[CPU_STATE_NICE] +
258 (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE] +
259 1);
260 }
261
262 if (cpu_load[i].cpu_ticks[CPU_STATE_IDLE] >=
263 prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE])
264 {
265 t_idle = cpu_load[i].cpu_ticks[CPU_STATE_IDLE] -
266 prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE];
267 }
268 else
269 {
270 t_idle = cpu_load[i].cpu_ticks[CPU_STATE_IDLE] +
271 (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE] +
272 1);
273 }
274 t_total = t_sys + t_user + t_nice + t_idle;
275 t_idle_all += t_idle;
276 t_total_all += t_total;
277 }
278 for (i = 0; i < cpu_count; i++)
279 {
280 for (j = 0; j < CPU_STATE_MAX; j++)
281 {
282 prev_cpu_load[i].cpu_ticks[j] = cpu_load[i].cpu_ticks[j];
283 }
284 }
285 if (t_total_all > 0)
286 currentCPULoad = 100 - (100 * t_idle_all) / t_total_all;
287 else 229 else
288 currentCPULoad = -1; 230 {
289 vm_deallocate(mach_task_self(), 231 t_sys = cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM]
290 (vm_address_t)cpu_load, 232 + (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_SYSTEM]
291 (vm_size_t)(cpu_msg_count * sizeof(*cpu_load))); 233 + 1);
292 currentIOLoad = -1; /* FIXME-OSX! */ 234 }
293 return GNUNET_OK; 235
236 if (cpu_load[i].cpu_ticks[CPU_STATE_USER] >=
237 prev_cpu_load[i].cpu_ticks[CPU_STATE_USER])
238 {
239 t_user = cpu_load[i].cpu_ticks[CPU_STATE_USER]
240 - prev_cpu_load[i].cpu_ticks[CPU_STATE_USER];
241 }
242 else
243 {
244 t_user = cpu_load[i].cpu_ticks[CPU_STATE_USER]
245 + (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_USER]
246 + 1);
247 }
248
249 if (cpu_load[i].cpu_ticks[CPU_STATE_NICE] >=
250 prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE])
251 {
252 t_nice = cpu_load[i].cpu_ticks[CPU_STATE_NICE]
253 - prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE];
254 }
255 else
256 {
257 t_nice = cpu_load[i].cpu_ticks[CPU_STATE_NICE]
258 + (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_NICE]
259 + 1);
260 }
261
262 if (cpu_load[i].cpu_ticks[CPU_STATE_IDLE] >=
263 prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE])
264 {
265 t_idle = cpu_load[i].cpu_ticks[CPU_STATE_IDLE]
266 - prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE];
267 }
268 else
269 {
270 t_idle = cpu_load[i].cpu_ticks[CPU_STATE_IDLE]
271 + (ULONG_MAX - prev_cpu_load[i].cpu_ticks[CPU_STATE_IDLE]
272 + 1);
273 }
274 t_total = t_sys + t_user + t_nice + t_idle;
275 t_idle_all += t_idle;
276 t_total_all += t_total;
294 } 277 }
295 else 278 for (i = 0; i < cpu_count; i++)
296 { 279 {
297 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "host_processor_info failed."); 280 for (j = 0; j < CPU_STATE_MAX; j++)
298 return GNUNET_SYSERR; 281 {
282 prev_cpu_load[i].cpu_ticks[j] = cpu_load[i].cpu_ticks[j];
283 }
299 } 284 }
285 if (t_total_all > 0)
286 currentCPULoad = 100 - (100 * t_idle_all) / t_total_all;
287 else
288 currentCPULoad = -1;
289 vm_deallocate (mach_task_self (),
290 (vm_address_t) cpu_load,
291 (vm_size_t) (cpu_msg_count * sizeof(*cpu_load)));
292 currentIOLoad = -1; /* FIXME-OSX! */
293 return GNUNET_OK;
294 }
295 else
296 {
297 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "host_processor_info failed.");
298 return GNUNET_SYSERR;
299 }
300 } 300 }
301#endif 301#endif
302 /* try kstat (Solaris only) */ 302 /* try kstat (Solaris only) */
@@ -315,48 +315,48 @@ updateUsage()
315 315
316 if (kstat_once == 1) 316 if (kstat_once == 1)
317 goto ABORT_KSTAT; 317 goto ABORT_KSTAT;
318 kc = kstat_open(); 318 kc = kstat_open ();
319 if (kc == NULL) 319 if (kc == NULL)
320 { 320 {
321 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kstat_close"); 321 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kstat_close");
322 goto ABORT_KSTAT; 322 goto ABORT_KSTAT;
323 } 323 }
324 324
325 idlecount = 0; 325 idlecount = 0;
326 totalcount = 0; 326 totalcount = 0;
327 for (khelper = kc->kc_chain; khelper != NULL; khelper = khelper->ks_next) 327 for (khelper = kc->kc_chain; khelper != NULL; khelper = khelper->ks_next)
328 {
329 cpu_stat_t stats;
330
331 if (0 != strncmp (khelper->ks_name, "cpu_stat", strlen ("cpu_stat")))
332 continue;
333 if (khelper->ks_data_size > sizeof(cpu_stat_t))
334 continue; /* better save then sorry! */
335 if (-1 != kstat_read (kc, khelper, &stats))
328 { 336 {
329 cpu_stat_t stats; 337 idlecount += stats.cpu_sysinfo.cpu[CPU_IDLE];
330 338 totalcount
331 if (0 != strncmp(khelper->ks_name, "cpu_stat", strlen("cpu_stat"))) 339 += stats.cpu_sysinfo.cpu[CPU_IDLE]
332 continue; 340 + stats.cpu_sysinfo.cpu[CPU_USER]
333 if (khelper->ks_data_size > sizeof(cpu_stat_t)) 341 + stats.cpu_sysinfo.cpu[CPU_KERNEL]
334 continue; /* better save then sorry! */ 342 + stats.cpu_sysinfo.cpu[CPU_WAIT];
335 if (-1 != kstat_read(kc, khelper, &stats))
336 {
337 idlecount += stats.cpu_sysinfo.cpu[CPU_IDLE];
338 totalcount
339 += stats.cpu_sysinfo.cpu[CPU_IDLE] +
340 stats.cpu_sysinfo.cpu[CPU_USER] +
341 stats.cpu_sysinfo.cpu[CPU_KERNEL] +
342 stats.cpu_sysinfo.cpu[CPU_WAIT];
343 }
344 } 343 }
345 if (0 != kstat_close(kc)) 344 }
346 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kstat_close"); 345 if (0 != kstat_close (kc))
346 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kstat_close");
347 if ((idlecount == 0) && (totalcount == 0)) 347 if ((idlecount == 0) && (totalcount == 0))
348 goto ABORT_KSTAT; /* no stats found => abort */ 348 goto ABORT_KSTAT; /* no stats found => abort */
349 deltaidle = idlecount - last_idlecount; 349 deltaidle = idlecount - last_idlecount;
350 deltatotal = totalcount - last_totalcount; 350 deltatotal = totalcount - last_totalcount;
351 if ((deltatotal > 0) && (last_totalcount > 0)) 351 if ((deltatotal > 0) && (last_totalcount > 0))
352 { 352 {
353 currentCPULoad = (unsigned int)(100.0 * deltaidle / deltatotal); 353 currentCPULoad = (unsigned int) (100.0 * deltaidle / deltatotal);
354 if (currentCPULoad > 100) 354 if (currentCPULoad > 100)
355 currentCPULoad = 100; /* odd */ 355 currentCPULoad = 100; /* odd */
356 if (currentCPULoad < 0) 356 if (currentCPULoad < 0)
357 currentCPULoad = 0; /* odd */ 357 currentCPULoad = 0; /* odd */
358 currentCPULoad = 100 - currentCPULoad; /* computed idle-load before! */ 358 currentCPULoad = 100 - currentCPULoad; /* computed idle-load before! */
359 } 359 }
360 else 360 else
361 currentCPULoad = -1; 361 currentCPULoad = -1;
362 currentIOLoad = -1; /* FIXME-SOLARIS! */ 362 currentIOLoad = -1; /* FIXME-SOLARIS! */
@@ -377,24 +377,24 @@ ABORT_KSTAT:
377 { 377 {
378 static int warnOnce = 0; 378 static int warnOnce = 0;
379 double loadavg; 379 double loadavg;
380 if (1 != getloadavg(&loadavg, 1)) 380 if (1 != getloadavg (&loadavg, 1))
381 {
382 /* only warn once, if there is a problem with
383 getloadavg, we're going to hit it frequently... */
384 if (warnOnce == 0)
381 { 385 {
382 /* only warn once, if there is a problem with 386 warnOnce = 1;
383 getloadavg, we're going to hit it frequently... */ 387 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "getloadavg");
384 if (warnOnce == 0)
385 {
386 warnOnce = 1;
387 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "getloadavg");
388 }
389 return GNUNET_SYSERR;
390 } 388 }
389 return GNUNET_SYSERR;
390 }
391 else 391 else
392 { 392 {
393 /* success with getloadavg */ 393 /* success with getloadavg */
394 currentCPULoad = (int)(100 * loadavg); 394 currentCPULoad = (int) (100 * loadavg);
395 currentIOLoad = -1; /* FIXME */ 395 currentIOLoad = -1; /* FIXME */
396 return GNUNET_OK; 396 return GNUNET_OK;
397 } 397 }
398 } 398 }
399#endif 399#endif
400 400
@@ -412,56 +412,56 @@ ABORT_KSTAT:
412 * that lock has already been obtained. 412 * that lock has already been obtained.
413 */ 413 */
414static void 414static void
415updateAgedLoad() 415updateAgedLoad ()
416{ 416{
417 static struct GNUNET_TIME_Absolute lastCall; 417 static struct GNUNET_TIME_Absolute lastCall;
418 struct GNUNET_TIME_Relative age; 418 struct GNUNET_TIME_Relative age;
419 419
420 age = GNUNET_TIME_absolute_get_duration(lastCall); 420 age = GNUNET_TIME_absolute_get_duration (lastCall);
421 if ((agedCPULoad == -1) 421 if ((agedCPULoad == -1)
422 || (age.rel_value_us > 500000)) 422 || (age.rel_value_us > 500000))
423 {
424 /* use smoothing, but do NOT update lastRet at frequencies higher
425 than 500ms; this makes the smoothing (mostly) independent from
426 the frequency at which getCPULoad is called (and we don't spend
427 more time measuring CPU than actually computing something). */
428 lastCall = GNUNET_TIME_absolute_get ();
429 updateUsage ();
430 if (currentCPULoad == -1)
423 { 431 {
424 /* use smoothing, but do NOT update lastRet at frequencies higher 432 agedCPULoad = -1;
425 than 500ms; this makes the smoothing (mostly) independent from 433 }
426 the frequency at which getCPULoad is called (and we don't spend 434 else
427 more time measuring CPU than actually computing something). */ 435 {
428 lastCall = GNUNET_TIME_absolute_get(); 436 if (agedCPULoad == -1)
429 updateUsage(); 437 {
430 if (currentCPULoad == -1) 438 agedCPULoad = currentCPULoad;
431 { 439 }
432 agedCPULoad = -1;
433 }
434 else 440 else
435 { 441 {
436 if (agedCPULoad == -1) 442 /* for CPU, we don't do the 'fast increase' since CPU is much
437 { 443 more jitterish to begin with */
438 agedCPULoad = currentCPULoad; 444 agedCPULoad = (agedCPULoad * 31 + currentCPULoad) / 32;
439 } 445 }
440 else 446 }
441 { 447 if (currentIOLoad == -1)
442 /* for CPU, we don't do the 'fast increase' since CPU is much 448 {
443 more jitterish to begin with */ 449 agedIOLoad = -1;
444 agedCPULoad = (agedCPULoad * 31 + currentCPULoad) / 32; 450 }
445 } 451 else
446 } 452 {
447 if (currentIOLoad == -1) 453 if (agedIOLoad == -1)
448 { 454 {
449 agedIOLoad = -1; 455 agedIOLoad = currentIOLoad;
450 } 456 }
451 else 457 else
452 { 458 {
453 if (agedIOLoad == -1) 459 /* for IO, we don't do the 'fast increase' since IO is much
454 { 460 more jitterish to begin with */
455 agedIOLoad = currentIOLoad; 461 agedIOLoad = (agedIOLoad * 31 + currentIOLoad) / 32;
456 } 462 }
457 else
458 {
459 /* for IO, we don't do the 'fast increase' since IO is much
460 more jitterish to begin with */
461 agedIOLoad = (agedIOLoad * 31 + currentIOLoad) / 32;
462 }
463 }
464 } 463 }
464 }
465} 465}
466 466
467/** 467/**
@@ -470,10 +470,10 @@ updateAgedLoad()
470 * (100 is equivalent to full load) 470 * (100 is equivalent to full load)
471 */ 471 */
472static int 472static int
473cpu_get_load() 473cpu_get_load ()
474{ 474{
475 updateAgedLoad(); 475 updateAgedLoad ();
476 return (int)agedCPULoad; 476 return (int) agedCPULoad;
477} 477}
478 478
479 479
@@ -483,10 +483,10 @@ cpu_get_load()
483 * (100 is equivalent to full load) 483 * (100 is equivalent to full load)
484 */ 484 */
485static int 485static int
486disk_get_load() 486disk_get_load ()
487{ 487{
488 updateAgedLoad(); 488 updateAgedLoad ();
489 return (int)agedIOLoad; 489 return (int) agedIOLoad;
490} 490}
491 491
492/** 492/**
@@ -495,13 +495,13 @@ disk_get_load()
495 * @return the percentage of memory used 495 * @return the percentage of memory used
496 */ 496 */
497static unsigned int 497static unsigned int
498mem_get_usage() 498mem_get_usage ()
499{ 499{
500 double percentage; 500 double percentage;
501 501
502 meminfo(); 502 meminfo ();
503 percentage = (((double)kb_main_used) / ((double)kb_main_total) * 100.0); 503 percentage = (((double) kb_main_used) / ((double) kb_main_total) * 100.0);
504 return (unsigned int)percentage; 504 return (unsigned int) percentage;
505} 505}
506 506
507 507
@@ -513,29 +513,29 @@ mem_get_usage()
513 * @return the number of processes 513 * @return the number of processes
514 */ 514 */
515static unsigned int 515static unsigned int
516get_nproc() 516get_nproc ()
517{ 517{
518 DIR *dir; 518 DIR *dir;
519 struct dirent *ent; 519 struct dirent *ent;
520 unsigned int nproc; 520 unsigned int nproc;
521 521
522 dir = opendir("/proc"); 522 dir = opendir ("/proc");
523 if (NULL == dir) 523 if (NULL == dir)
524 return 0; 524 return 0;
525 nproc = 0; 525 nproc = 0;
526 while (NULL != (ent = readdir(dir))) 526 while (NULL != (ent = readdir (dir)))
527 { 527 {
528 if ((*ent->d_name > '0') && (*ent->d_name <= '9')) 528 if ((*ent->d_name > '0') && (*ent->d_name <= '9'))
529 nproc++; 529 nproc++;
530 } 530 }
531 closedir(dir); 531 closedir (dir);
532 return nproc; 532 return nproc;
533} 533}
534#endif 534#endif
535 535
536 536
537static void 537static void
538sample_load_task(void *cls) 538sample_load_task (void *cls)
539{ 539{
540 struct GNUNET_TIME_Absolute now; 540 struct GNUNET_TIME_Absolute now;
541 char *str; 541 char *str;
@@ -546,31 +546,32 @@ sample_load_task(void *cls)
546 unsigned int nproc; 546 unsigned int nproc;
547 547
548 sample_load_task_id = NULL; 548 sample_load_task_id = NULL;
549 ld_cpu = cpu_get_load(); 549 ld_cpu = cpu_get_load ();
550 ld_disk = disk_get_load(); 550 ld_disk = disk_get_load ();
551 if ((-1 == ld_cpu) || (-1 == ld_disk)) 551 if ((-1 == ld_cpu) || (-1 == ld_disk))
552 goto reschedule; 552 goto reschedule;
553 mem_usage = mem_get_usage(); 553 mem_usage = mem_get_usage ();
554#ifdef LINUX 554#ifdef LINUX
555 nproc = get_nproc(); 555 nproc = get_nproc ();
556#else 556#else
557 nproc = 0; 557 nproc = 0;
558#endif 558#endif
559 now = GNUNET_TIME_absolute_get(); 559 now = GNUNET_TIME_absolute_get ();
560 nbs = GNUNET_asprintf(&str, "%llu %d %d %u %u\n", now.abs_value_us / 1000LL / 1000LL, 560 nbs = GNUNET_asprintf (&str, "%llu %d %d %u %u\n", now.abs_value_us / 1000LL
561 ld_cpu, ld_disk, mem_usage, nproc); 561 / 1000LL,
562 ld_cpu, ld_disk, mem_usage, nproc);
562 if (0 < nbs) 563 if (0 < nbs)
563 { 564 {
564 GNUNET_BIO_write(bw, str, nbs); 565 GNUNET_BIO_write (bw, str, nbs);
565 } 566 }
566 else 567 else
567 GNUNET_break(0); 568 GNUNET_break (0);
568 GNUNET_free(str); 569 GNUNET_free (str);
569 570
570reschedule: 571reschedule:
571 sample_load_task_id = 572 sample_load_task_id =
572 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 573 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
573 &sample_load_task, NULL); 574 &sample_load_task, NULL);
574} 575}
575 576
576 577
@@ -580,7 +581,7 @@ reschedule:
580 * generated from the hostname and the process's PID. 581 * generated from the hostname and the process's PID.
581 */ 582 */
582void 583void
583GST_stats_init(const struct GNUNET_CONFIGURATION_Handle *cfg) 584GST_stats_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
584{ 585{
585 char *hostname; 586 char *hostname;
586 char *stats_dir; 587 char *stats_dir;
@@ -588,42 +589,42 @@ GST_stats_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
588 size_t len; 589 size_t len;
589 590
590 if (GNUNET_OK != 591 if (GNUNET_OK !=
591 GNUNET_CONFIGURATION_get_value_filename(cfg, "testbed", 592 GNUNET_CONFIGURATION_get_value_filename (cfg, "testbed",
592 "STATS_DIR", &stats_dir)) 593 "STATS_DIR", &stats_dir))
593 return; 594 return;
594 len = GNUNET_OS_get_hostname_max_length(); 595 len = GNUNET_OS_get_hostname_max_length ();
595 hostname = GNUNET_malloc(len); 596 hostname = GNUNET_malloc (len);
596 if (0 != gethostname(hostname, len)) 597 if (0 != gethostname (hostname, len))
597 { 598 {
598 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "gethostname"); 599 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "gethostname");
599 GNUNET_free(stats_dir); 600 GNUNET_free (stats_dir);
600 GNUNET_free(hostname); 601 GNUNET_free (hostname);
601 return; 602 return;
602 } 603 }
603 fn = NULL; 604 fn = NULL;
604 (void)GNUNET_asprintf(&fn, "%s/%.*s-%jd.dat", stats_dir, len, 605 (void) GNUNET_asprintf (&fn, "%s/%.*s-%jd.dat", stats_dir, len,
605 hostname, (intmax_t)getpid()); 606 hostname, (intmax_t) getpid ());
606 GNUNET_free(stats_dir); 607 GNUNET_free (stats_dir);
607 GNUNET_free(hostname); 608 GNUNET_free (hostname);
608 if (NULL == (bw = GNUNET_BIO_write_open(fn))) 609 if (NULL == (bw = GNUNET_BIO_write_open (fn)))
609 { 610 {
610 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 611 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
611 _("Cannot open %s for writing load statistics. " 612 _ ("Cannot open %s for writing load statistics. "
612 "Not logging load statistics\n"), fn); 613 "Not logging load statistics\n"), fn);
613 GNUNET_free(fn); 614 GNUNET_free (fn);
614 return; 615 return;
615 } 616 }
616 GNUNET_free(fn); 617 GNUNET_free (fn);
617 sample_load_task_id = GNUNET_SCHEDULER_add_now(&sample_load_task, NULL); 618 sample_load_task_id = GNUNET_SCHEDULER_add_now (&sample_load_task, NULL);
618#ifdef LINUX 619#ifdef LINUX
619 proc_stat = fopen("/proc/stat", "r"); 620 proc_stat = fopen ("/proc/stat", "r");
620 if (NULL == proc_stat) 621 if (NULL == proc_stat)
621 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, 622 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
622 "fopen", "/proc/stat"); 623 "fopen", "/proc/stat");
623#elif OSX 624#elif OSX
624 initMachCpuStats(); 625 initMachCpuStats ();
625#endif 626#endif
626 updateUsage(); /* initialize */ 627 updateUsage (); /* initialize */
627} 628}
628 629
629 630
@@ -631,25 +632,25 @@ GST_stats_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
631 * Shutdown the status calls module. 632 * Shutdown the status calls module.
632 */ 633 */
633void 634void
634GST_stats_destroy() 635GST_stats_destroy ()
635{ 636{
636 if (NULL == bw) 637 if (NULL == bw)
637 return; 638 return;
638#ifdef LINUX 639#ifdef LINUX
639 if (proc_stat != NULL) 640 if (proc_stat != NULL)
640 { 641 {
641 fclose(proc_stat); 642 fclose (proc_stat);
642 proc_stat = NULL; 643 proc_stat = NULL;
643 } 644 }
644#elif OSX 645#elif OSX
645 GNUNET_free_non_null(prev_cpu_load); 646 GNUNET_free_non_null (prev_cpu_load);
646#endif 647#endif
647 if (NULL != sample_load_task_id) 648 if (NULL != sample_load_task_id)
648 { 649 {
649 GNUNET_SCHEDULER_cancel(sample_load_task_id); 650 GNUNET_SCHEDULER_cancel (sample_load_task_id);
650 sample_load_task_id = NULL; 651 sample_load_task_id = NULL;
651 } 652 }
652 GNUNET_break(GNUNET_OK == GNUNET_BIO_write_close(bw)); 653 GNUNET_break (GNUNET_OK == GNUNET_BIO_write_close (bw));
653 bw = NULL; 654 bw = NULL;
654} 655}
655 656
diff --git a/src/testbed/gnunet-service-testbed_links.c b/src/testbed/gnunet-service-testbed_links.c
index d7715a16e..ee00e4be0 100644
--- a/src/testbed/gnunet-service-testbed_links.c
+++ b/src/testbed/gnunet-service-testbed_links.c
@@ -34,7 +34,7 @@
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,7 +45,8 @@
45/** 45/**
46 * States of LCFContext 46 * States of LCFContext
47 */ 47 */
48enum LCFContextState { 48enum LCFContextState
49{
49 /** 50 /**
50 * The Context has been initialized; Nothing has been done on it 51 * The Context has been initialized; Nothing has been done on it
51 */ 52 */
@@ -71,7 +72,8 @@ enum LCFContextState {
71/** 72/**
72 * Link controllers request forwarding context 73 * Link controllers request forwarding context
73 */ 74 */
74struct LCFContext { 75struct LCFContext
76{
75 /** 77 /**
76 * The LCFContext 78 * The LCFContext
77 */ 79 */
@@ -133,7 +135,8 @@ struct LCFContext {
133 * Notification context to be used to notify when connection to the neighbour's 135 * Notification context to be used to notify when connection to the neighbour's
134 * controller is opened 136 * controller is opened
135 */ 137 */
136struct NeighbourConnectNotification { 138struct NeighbourConnectNotification
139{
137 /** 140 /**
138 * DLL next for inclusion in neighbour's list of notification requests 141 * DLL next for inclusion in neighbour's list of notification requests
139 */ 142 */
@@ -164,7 +167,8 @@ struct NeighbourConnectNotification {
164/** 167/**
165 * A connected controller which is not our child 168 * A connected controller which is not our child
166 */ 169 */
167struct Neighbour { 170struct Neighbour
171{
168 /** 172 /**
169 * The controller handle 173 * The controller handle
170 */ 174 */
@@ -189,7 +193,7 @@ struct Neighbour {
189 /** 193 /**
190 * Task id for the task to call notifications from the notification list 194 * Task id for the task to call notifications from the notification list
191 */ 195 */
192 struct GNUNET_SCHEDULER_Task * notify_task; 196 struct GNUNET_SCHEDULER_Task *notify_task;
193 197
194 /** 198 /**
195 * How many references are present currently to this neighbour's connection 199 * How many references are present currently to this neighbour's connection
@@ -223,7 +227,8 @@ static unsigned int neighbour_list_size;
223 * Context information for establishing a link to neighbour (Used is 227 * Context information for establishing a link to neighbour (Used is
224 * GST_handle_link_controllers() 228 * GST_handle_link_controllers()
225 */ 229 */
226struct NeighbourConnectCtxt { 230struct NeighbourConnectCtxt
231{
227 /** 232 /**
228 * DLL next for inclusion in the corresponding context list 233 * DLL next for inclusion in the corresponding context list
229 */ 234 */
@@ -299,7 +304,7 @@ static struct LCFContext *lcf_tail;
299/** 304/**
300 * The lcf_task handle 305 * The lcf_task handle
301 */ 306 */
302static struct GNUNET_SCHEDULER_Task * lcf_proc_task_id; 307static struct GNUNET_SCHEDULER_Task *lcf_proc_task_id;
303 308
304/** 309/**
305 * The size of the route list 310 * The size of the route list
@@ -313,13 +318,13 @@ static unsigned int route_list_size;
313 * @param slave the slave controller to add 318 * @param slave the slave controller to add
314 */ 319 */
315static void 320static void
316slave_list_add(struct Slave *slave) 321slave_list_add (struct Slave *slave)
317{ 322{
318 if (slave->host_id >= GST_slave_list_size) 323 if (slave->host_id >= GST_slave_list_size)
319 GST_array_grow_large_enough(GST_slave_list, 324 GST_array_grow_large_enough (GST_slave_list,
320 GST_slave_list_size, 325 GST_slave_list_size,
321 slave->host_id); 326 slave->host_id);
322 GNUNET_assert(NULL == GST_slave_list[slave->host_id]); 327 GNUNET_assert (NULL == GST_slave_list[slave->host_id]);
323 GST_slave_list[slave->host_id] = slave; 328 GST_slave_list[slave->host_id] = slave;
324} 329}
325 330
@@ -334,9 +339,9 @@ slave_list_add(struct Slave *slave)
334 * @return #GNUNET_OK (continue iterating) 339 * @return #GNUNET_OK (continue iterating)
335 */ 340 */
336static int 341static int
337drop_client_entries(void *cls, 342drop_client_entries (void *cls,
338 const struct GNUNET_HashCode *key, 343 const struct GNUNET_HashCode *key,
339 void *value) 344 void *value)
340{ 345{
341 struct GNUNET_SERVICE_Client *client = cls; 346 struct GNUNET_SERVICE_Client *client = cls;
342 struct RegisteredHostContext *rhc = value; 347 struct RegisteredHostContext *rhc = value;
@@ -344,11 +349,11 @@ drop_client_entries(void *cls,
344 struct ForwardedOverlayConnectContext *foccn; 349 struct ForwardedOverlayConnectContext *foccn;
345 350
346 for (focc = rhc->focc_dll_head; NULL != focc; focc = foccn) 351 for (focc = rhc->focc_dll_head; NULL != focc; focc = foccn)
347 { 352 {
348 foccn = focc->next; 353 foccn = focc->next;
349 if (focc->client == client) 354 if (focc->client == client)
350 GST_cleanup_focc(focc); 355 GST_cleanup_focc (focc);
351 } 356 }
352 return GNUNET_OK; 357 return GNUNET_OK;
353} 358}
354 359
@@ -359,11 +364,11 @@ drop_client_entries(void *cls,
359 * @param route the route to add 364 * @param route the route to add
360 */ 365 */
361static void 366static void
362route_list_add(struct Route *route) 367route_list_add (struct Route *route)
363{ 368{
364 if (route->dest >= route_list_size) 369 if (route->dest >= route_list_size)
365 GST_array_grow_large_enough(route_list, route_list_size, route->dest); 370 GST_array_grow_large_enough (route_list, route_list_size, route->dest);
366 GNUNET_assert(NULL == route_list[route->dest]); 371 GNUNET_assert (NULL == route_list[route->dest]);
367 route_list[route->dest] = route; 372 route_list[route->dest] = route;
368} 373}
369 374
@@ -375,11 +380,12 @@ route_list_add(struct Route *route)
375 * @param n the neighbour to add 380 * @param n the neighbour to add
376 */ 381 */
377static void 382static void
378neighbour_list_add(struct Neighbour *n) 383neighbour_list_add (struct Neighbour *n)
379{ 384{
380 if (n->host_id >= neighbour_list_size) 385 if (n->host_id >= neighbour_list_size)
381 GST_array_grow_large_enough(neighbour_list, neighbour_list_size, n->host_id); 386 GST_array_grow_large_enough (neighbour_list, neighbour_list_size,
382 GNUNET_assert(NULL == neighbour_list[n->host_id]); 387 n->host_id);
388 GNUNET_assert (NULL == neighbour_list[n->host_id]);
383 neighbour_list[n->host_id] = n; 389 neighbour_list[n->host_id] = n;
384} 390}
385 391
@@ -388,14 +394,14 @@ neighbour_list_add(struct Neighbour *n)
388 * Cleans up the route list 394 * Cleans up the route list
389 */ 395 */
390void 396void
391GST_route_list_clear() 397GST_route_list_clear ()
392{ 398{
393 unsigned int id; 399 unsigned int id;
394 400
395 for (id = 0; id < route_list_size; id++) 401 for (id = 0; id < route_list_size; id++)
396 if (NULL != route_list[id]) 402 if (NULL != route_list[id])
397 GNUNET_free(route_list[id]); 403 GNUNET_free (route_list[id]);
398 GNUNET_free_non_null(route_list); 404 GNUNET_free_non_null (route_list);
399 route_list = NULL; 405 route_list = NULL;
400} 406}
401 407
@@ -410,20 +416,20 @@ GST_route_list_clear()
410 * #GNUNET_NO if not. 416 * #GNUNET_NO if not.
411 */ 417 */
412static int 418static int
413reghost_free_iterator(void *cls, 419reghost_free_iterator (void *cls,
414 const struct GNUNET_HashCode *key, 420 const struct GNUNET_HashCode *key,
415 void *value) 421 void *value)
416{ 422{
417 struct Slave *slave = cls; 423 struct Slave *slave = cls;
418 struct RegisteredHostContext *rhc = value; 424 struct RegisteredHostContext *rhc = value;
419 struct ForwardedOverlayConnectContext *focc; 425 struct ForwardedOverlayConnectContext *focc;
420 426
421 GNUNET_assert(GNUNET_YES == 427 GNUNET_assert (GNUNET_YES ==
422 GNUNET_CONTAINER_multihashmap_remove(slave->reghost_map, key, 428 GNUNET_CONTAINER_multihashmap_remove (slave->reghost_map, key,
423 value)); 429 value));
424 while (NULL != (focc = rhc->focc_dll_head)) 430 while (NULL != (focc = rhc->focc_dll_head))
425 GST_cleanup_focc(focc); 431 GST_cleanup_focc (focc);
426 GNUNET_free(value); 432 GNUNET_free (value);
427 return GNUNET_YES; 433 return GNUNET_YES;
428} 434}
429 435
@@ -434,30 +440,30 @@ reghost_free_iterator(void *cls,
434 * @param slave the #Slave object 440 * @param slave the #Slave object
435 */ 441 */
436static void 442static void
437kill_slave(struct Slave *slave) 443kill_slave (struct Slave *slave)
438{ 444{
439 struct HostRegistration *hr_entry; 445 struct HostRegistration *hr_entry;
440 446
441 while (NULL != (hr_entry = slave->hr_dll_head)) 447 while (NULL != (hr_entry = slave->hr_dll_head))
442 { 448 {
443 GNUNET_CONTAINER_DLL_remove(slave->hr_dll_head, slave->hr_dll_tail, 449 GNUNET_CONTAINER_DLL_remove (slave->hr_dll_head, slave->hr_dll_tail,
444 hr_entry); 450 hr_entry);
445 GNUNET_free(hr_entry); 451 GNUNET_free (hr_entry);
446 } 452 }
447 if (NULL != slave->rhandle) 453 if (NULL != slave->rhandle)
448 GNUNET_TESTBED_cancel_registration(slave->rhandle); 454 GNUNET_TESTBED_cancel_registration (slave->rhandle);
449 GNUNET_assert(GNUNET_SYSERR != 455 GNUNET_assert (GNUNET_SYSERR !=
450 GNUNET_CONTAINER_multihashmap_iterate(slave->reghost_map, 456 GNUNET_CONTAINER_multihashmap_iterate (slave->reghost_map,
451 reghost_free_iterator, 457 reghost_free_iterator,
452 slave)); 458 slave));
453 GNUNET_CONTAINER_multihashmap_destroy(slave->reghost_map); 459 GNUNET_CONTAINER_multihashmap_destroy (slave->reghost_map);
454 if (NULL != slave->controller) 460 if (NULL != slave->controller)
455 GNUNET_TESTBED_controller_disconnect(slave->controller); 461 GNUNET_TESTBED_controller_disconnect (slave->controller);
456 if (NULL != slave->controller_proc) 462 if (NULL != slave->controller_proc)
457 { 463 {
458 LOG_DEBUG("Stopping a slave\n"); 464 LOG_DEBUG ("Stopping a slave\n");
459 GNUNET_TESTBED_controller_kill_(slave->controller_proc); 465 GNUNET_TESTBED_controller_kill_ (slave->controller_proc);
460 } 466 }
461} 467}
462 468
463 469
@@ -467,15 +473,15 @@ kill_slave(struct Slave *slave)
467 * @param slave the #Slave object 473 * @param slave the #Slave object
468 */ 474 */
469static void 475static void
470destroy_slave(struct Slave *slave) 476destroy_slave (struct Slave *slave)
471{ 477{
472 if (NULL != slave->controller_proc) 478 if (NULL != slave->controller_proc)
473 { 479 {
474 GNUNET_TESTBED_controller_destroy_(slave->controller_proc); 480 GNUNET_TESTBED_controller_destroy_ (slave->controller_proc);
475 LOG_DEBUG("Slave stopped\n"); 481 LOG_DEBUG ("Slave stopped\n");
476 } 482 }
477 GST_slave_list[slave->host_id] = NULL; 483 GST_slave_list[slave->host_id] = NULL;
478 GNUNET_free(slave); 484 GNUNET_free (slave);
479} 485}
480 486
481 487
@@ -483,26 +489,26 @@ destroy_slave(struct Slave *slave)
483 * Cleans up the slave list 489 * Cleans up the slave list
484 */ 490 */
485void 491void
486GST_slave_list_clear() 492GST_slave_list_clear ()
487{ 493{
488 struct Slave *slave; 494 struct Slave *slave;
489 unsigned int id; 495 unsigned int id;
490 496
491 for (id = 0; id < GST_slave_list_size; id++) 497 for (id = 0; id < GST_slave_list_size; id++)
492 { 498 {
493 slave = GST_slave_list[id]; 499 slave = GST_slave_list[id];
494 if (NULL == slave) 500 if (NULL == slave)
495 continue; 501 continue;
496 kill_slave(slave); 502 kill_slave (slave);
497 } 503 }
498 for (id = 0; id < GST_slave_list_size; id++) 504 for (id = 0; id < GST_slave_list_size; id++)
499 { 505 {
500 slave = GST_slave_list[id]; 506 slave = GST_slave_list[id];
501 if (NULL == slave) 507 if (NULL == slave)
502 continue; 508 continue;
503 destroy_slave(slave); 509 destroy_slave (slave);
504 } 510 }
505 GNUNET_free_non_null(GST_slave_list); 511 GNUNET_free_non_null (GST_slave_list);
506 GST_slave_list = NULL; 512 GST_slave_list = NULL;
507} 513}
508 514
@@ -516,18 +522,18 @@ GST_slave_list_clear()
516 * is found 522 * is found
517 */ 523 */
518struct Route * 524struct Route *
519GST_find_dest_route(uint32_t host_id) 525GST_find_dest_route (uint32_t host_id)
520{ 526{
521 struct Route *route; 527 struct Route *route;
522 528
523 if (route_list_size <= host_id) 529 if (route_list_size <= host_id)
524 return NULL; 530 return NULL;
525 while (NULL != (route = route_list[host_id])) 531 while (NULL != (route = route_list[host_id]))
526 { 532 {
527 if (route->thru == GST_context->host_id) 533 if (route->thru == GST_context->host_id)
528 break; 534 break;
529 host_id = route->thru; 535 host_id = route->thru;
530 } 536 }
531 return route; 537 return route;
532} 538}
533 539
@@ -545,10 +551,10 @@ GST_find_dest_route(uint32_t host_id)
545 * NULL if cfg is set! 551 * NULL if cfg is set!
546 */ 552 */
547static void 553static void
548send_controller_link_response(struct GNUNET_SERVICE_Client *client, 554send_controller_link_response (struct GNUNET_SERVICE_Client *client,
549 uint64_t operation_id, 555 uint64_t operation_id,
550 const struct GNUNET_CONFIGURATION_Handle *cfg, 556 const struct GNUNET_CONFIGURATION_Handle *cfg,
551 const char *emsg) 557 const char *emsg)
552{ 558{
553 struct GNUNET_MQ_Envelope *env; 559 struct GNUNET_MQ_Envelope *env;
554 struct GNUNET_TESTBED_ControllerLinkResponse *msg; 560 struct GNUNET_TESTBED_ControllerLinkResponse *msg;
@@ -557,40 +563,40 @@ send_controller_link_response(struct GNUNET_SERVICE_Client *client,
557 size_t xconfig_size; 563 size_t xconfig_size;
558 uint16_t msize; 564 uint16_t msize;
559 565
560 GNUNET_assert((NULL == cfg) || (NULL == emsg)); 566 GNUNET_assert ((NULL == cfg) || (NULL == emsg));
561 xconfig = NULL; 567 xconfig = NULL;
562 xconfig_size = 0; 568 xconfig_size = 0;
563 config_size = 0; 569 config_size = 0;
564 msize = 0; 570 msize = 0;
565 if (NULL != cfg) 571 if (NULL != cfg)
566 { 572 {
567 xconfig = GNUNET_TESTBED_compress_cfg_(cfg, 573 xconfig = GNUNET_TESTBED_compress_cfg_ (cfg,
568 &config_size, 574 &config_size,
569 &xconfig_size); 575 &xconfig_size);
570 msize += xconfig_size; 576 msize += xconfig_size;
571 } 577 }
572 if (NULL != emsg) 578 if (NULL != emsg)
573 msize += strlen(emsg); 579 msize += strlen (emsg);
574 env = GNUNET_MQ_msg_extra(msg, 580 env = GNUNET_MQ_msg_extra (msg,
575 msize, 581 msize,
576 GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT); 582 GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT);
577 if (NULL == emsg) 583 if (NULL == emsg)
578 msg->success = htons(GNUNET_YES); 584 msg->success = htons (GNUNET_YES);
579 msg->operation_id = GNUNET_htonll(operation_id); 585 msg->operation_id = GNUNET_htonll (operation_id);
580 msg->config_size = htons((uint16_t)config_size); 586 msg->config_size = htons ((uint16_t) config_size);
581 if (NULL != xconfig) 587 if (NULL != xconfig)
582 { 588 {
583 GNUNET_memcpy(&msg[1], 589 GNUNET_memcpy (&msg[1],
584 xconfig, 590 xconfig,
585 xconfig_size); 591 xconfig_size);
586 GNUNET_free(xconfig); 592 GNUNET_free (xconfig);
587 } 593 }
588 if (NULL != emsg) 594 if (NULL != emsg)
589 GNUNET_memcpy(&msg[1], 595 GNUNET_memcpy (&msg[1],
590 emsg, 596 emsg,
591 strlen(emsg)); 597 strlen (emsg));
592 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), 598 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
593 env); 599 env);
594} 600}
595 601
596 602
@@ -600,7 +606,7 @@ send_controller_link_response(struct GNUNET_SERVICE_Client *client,
600 * @param cls the LCFContext 606 * @param cls the LCFContext
601 */ 607 */
602static void 608static void
603lcf_proc_task(void *cls); 609lcf_proc_task (void *cls);
604 610
605 611
606/** 612/**
@@ -610,40 +616,40 @@ lcf_proc_task(void *cls);
610 * @param emsg the error message; NULL if host registration is successful 616 * @param emsg the error message; NULL if host registration is successful
611 */ 617 */
612static void 618static void
613lcf_proc_cc(void *cls, 619lcf_proc_cc (void *cls,
614 const char *emsg) 620 const char *emsg)
615{ 621{
616 struct LCFContext *lcf = cls; 622 struct LCFContext *lcf = cls;
617 623
618 GNUNET_assert(NULL == lcf_proc_task_id); 624 GNUNET_assert (NULL == lcf_proc_task_id);
619 switch (lcf->state) 625 switch (lcf->state)
620 { 626 {
621 case INIT: 627 case INIT:
622 if (NULL != emsg) 628 if (NULL != emsg)
623 goto registration_error; 629 goto registration_error;
624 lcf->state = DELEGATED_HOST_REGISTERED; 630 lcf->state = DELEGATED_HOST_REGISTERED;
625 lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); 631 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
626 break; 632 break;
627 633
628 case DELEGATED_HOST_REGISTERED: 634 case DELEGATED_HOST_REGISTERED:
629 if (NULL != emsg) 635 if (NULL != emsg)
630 goto registration_error; 636 goto registration_error;
631 lcf->state = SLAVE_HOST_REGISTERED; 637 lcf->state = SLAVE_HOST_REGISTERED;
632 lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); 638 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
633 break; 639 break;
634 640
635 default: 641 default:
636 GNUNET_assert(0); /* Shouldn't reach here */ 642 GNUNET_assert (0); /* Shouldn't reach here */
637 } 643 }
638 return; 644 return;
639 645
640registration_error: 646registration_error:
641 LOG(GNUNET_ERROR_TYPE_WARNING, 647 LOG (GNUNET_ERROR_TYPE_WARNING,
642 "Host registration failed with message: %s\n", 648 "Host registration failed with message: %s\n",
643 emsg); 649 emsg);
644 lcf->state = FINISHED; 650 lcf->state = FINISHED;
645 lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, 651 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task,
646 lcf); 652 lcf);
647} 653}
648 654
649 655
@@ -653,7 +659,7 @@ registration_error:
653 * @param cls the LCFContext 659 * @param cls the LCFContext
654 */ 660 */
655static void 661static void
656lcf_proc_task(void *cls); 662lcf_proc_task (void *cls);
657 663
658 664
659/** 665/**
@@ -662,21 +668,21 @@ lcf_proc_task(void *cls);
662 * @param cls the LCFContext 668 * @param cls the LCFContext
663 */ 669 */
664static void 670static void
665lcf_forwarded_operation_timeout(void *cls) 671lcf_forwarded_operation_timeout (void *cls)
666{ 672{
667 struct LCFContext *lcf = cls; 673 struct LCFContext *lcf = cls;
668 674
669 lcf->timeout_task = NULL; 675 lcf->timeout_task = NULL;
670 // GST_forwarded_operation_timeout (lcf->fopc, tc); 676 // GST_forwarded_operation_timeout (lcf->fopc, tc);
671 LOG(GNUNET_ERROR_TYPE_WARNING, 677 LOG (GNUNET_ERROR_TYPE_WARNING,
672 "A forwarded controller link operation has timed out\n"); 678 "A forwarded controller link operation has timed out\n");
673 send_controller_link_response(lcf->client, 679 send_controller_link_response (lcf->client,
674 lcf->operation_id, 680 lcf->operation_id,
675 NULL, 681 NULL,
676 "A forwarded controller link operation has timed out\n"); 682 "A forwarded controller link operation has timed out\n");
677 GNUNET_assert(NULL == lcf_proc_task_id); 683 GNUNET_assert (NULL == lcf_proc_task_id);
678 lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, 684 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task,
679 lcf); 685 lcf);
680} 686}
681 687
682 688
@@ -686,68 +692,69 @@ lcf_forwarded_operation_timeout(void *cls)
686 * @param cls the LCFContext 692 * @param cls the LCFContext
687 */ 693 */
688static void 694static void
689lcf_proc_task(void *cls) 695lcf_proc_task (void *cls)
690{ 696{
691 struct LCFContext *lcf = cls; 697 struct LCFContext *lcf = cls;
692 698
693 lcf_proc_task_id = NULL; 699 lcf_proc_task_id = NULL;
694 switch (lcf->state) 700 switch (lcf->state)
701 {
702 case INIT:
703 if (GNUNET_NO ==
704 GNUNET_TESTBED_is_host_registered_ (GST_host_list
705 [lcf->delegated_host_id],
706 lcf->gateway->controller))
695 { 707 {
696 case INIT: 708 GST_queue_host_registration (lcf->gateway, lcf_proc_cc, lcf,
697 if (GNUNET_NO == 709 GST_host_list[lcf->delegated_host_id]);
698 GNUNET_TESTBED_is_host_registered_(GST_host_list 710 }
699 [lcf->delegated_host_id], 711 else
700 lcf->gateway->controller)) 712 {
701 { 713 lcf->state = DELEGATED_HOST_REGISTERED;
702 GST_queue_host_registration(lcf->gateway, lcf_proc_cc, lcf, 714 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
703 GST_host_list[lcf->delegated_host_id]); 715 }
704 } 716 break;
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 717
740 case FINISHED: 718 case DELEGATED_HOST_REGISTERED:
741 if (NULL != lcf->op) 719 if (GNUNET_NO ==
742 GNUNET_TESTBED_operation_done(lcf->op); 720 GNUNET_TESTBED_is_host_registered_ (GST_host_list[lcf->slave_host_id],
743 GNUNET_CONTAINER_DLL_remove(lcf_head, 721 lcf->gateway->controller))
744 lcf_tail, 722 {
745 lcf); 723 GST_queue_host_registration (lcf->gateway, lcf_proc_cc, lcf,
746 GNUNET_free(lcf); 724 GST_host_list[lcf->slave_host_id]);
747 if (NULL != lcf_head)
748 lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task,
749 lcf_head);
750 } 725 }
726 else
727 {
728 lcf->state = SLAVE_HOST_REGISTERED;
729 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
730 }
731 break;
732
733 case SLAVE_HOST_REGISTERED:
734 lcf->op = GNUNET_TESTBED_controller_link (lcf,
735 lcf->gateway->controller,
736 GST_host_list[lcf->
737 delegated_host_id],
738 GST_host_list[lcf->slave_host_id],
739 lcf->is_subordinate);
740 lcf->timeout_task =
741 GNUNET_SCHEDULER_add_delayed (GST_timeout,
742 &lcf_forwarded_operation_timeout,
743 lcf);
744 lcf->state = FINISHED;
745 break;
746
747 case FINISHED:
748 if (NULL != lcf->op)
749 GNUNET_TESTBED_operation_done (lcf->op);
750 GNUNET_CONTAINER_DLL_remove (lcf_head,
751 lcf_tail,
752 lcf);
753 GNUNET_free (lcf);
754 if (NULL != lcf_head)
755 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task,
756 lcf_head);
757 }
751} 758}
752 759
753 760
@@ -758,30 +765,30 @@ lcf_proc_task(void *cls)
758 * @param event information about the event 765 * @param event information about the event
759 */ 766 */
760static void 767static void
761slave_event_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) 768slave_event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
762{ 769{
763 struct LCFContext *lcf; 770 struct LCFContext *lcf;
764 771
765 /* We currently only get here when working on LCFContexts */ 772 /* We currently only get here when working on LCFContexts */
766 GNUNET_assert(GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); 773 GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
767 lcf = event->op_cls; 774 lcf = event->op_cls;
768 GNUNET_assert(lcf->op == event->op); 775 GNUNET_assert (lcf->op == event->op);
769 GNUNET_TESTBED_operation_done(lcf->op); 776 GNUNET_TESTBED_operation_done (lcf->op);
770 lcf->op = NULL; 777 lcf->op = NULL;
771 GNUNET_assert(FINISHED == lcf->state); 778 GNUNET_assert (FINISHED == lcf->state);
772 GNUNET_assert(NULL != lcf->timeout_task); 779 GNUNET_assert (NULL != lcf->timeout_task);
773 GNUNET_SCHEDULER_cancel(lcf->timeout_task); 780 GNUNET_SCHEDULER_cancel (lcf->timeout_task);
774 if (NULL == event->details.operation_finished.emsg) 781 if (NULL == event->details.operation_finished.emsg)
775 send_controller_link_response(lcf->client, lcf->operation_id, 782 send_controller_link_response (lcf->client, lcf->operation_id,
776 GNUNET_TESTBED_host_get_cfg_ 783 GNUNET_TESTBED_host_get_cfg_
777 (GST_host_list[lcf->delegated_host_id]), 784 (GST_host_list[lcf->delegated_host_id]),
778 NULL); 785 NULL);
779 else 786 else
780 send_controller_link_response(lcf->client, lcf->operation_id, 787 send_controller_link_response (lcf->client, lcf->operation_id,
781 NULL, 788 NULL,
782 event->details.operation_finished.emsg); 789 event->details.operation_finished.emsg);
783 GNUNET_assert(NULL == lcf_proc_task_id); 790 GNUNET_assert (NULL == lcf_proc_task_id);
784 lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, lcf); 791 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
785 return; 792 return;
786} 793}
787 794
@@ -796,56 +803,56 @@ slave_event_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
796 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case 803 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
797 */ 804 */
798static void 805static void
799slave_status_cb(void *cls, 806slave_status_cb (void *cls,
800 const struct GNUNET_CONFIGURATION_Handle *cfg, 807 const struct GNUNET_CONFIGURATION_Handle *cfg,
801 int status) 808 int status)
802{ 809{
803 struct Slave *slave = cls; 810 struct Slave *slave = cls;
804 struct LinkControllersContext *lcc; 811 struct LinkControllersContext *lcc;
805 812
806 lcc = slave->lcc; 813 lcc = slave->lcc;
807 if (GNUNET_SYSERR == status) 814 if (GNUNET_SYSERR == status)
808 { 815 {
809 slave->controller_proc = NULL; 816 slave->controller_proc = NULL;
810 /* Stop all link controller forwarding tasks since we shutdown here anyway 817 /* Stop all link controller forwarding tasks since we shutdown here anyway
811 and as these tasks they depend on the operation queues which are created 818 and as these tasks they depend on the operation queues which are created
812 through GNUNET_TESTBED_controller_connect() and in kill_slave() we call 819 through GNUNET_TESTBED_controller_connect() and in kill_slave() we call
813 the destructor function GNUNET_TESTBED_controller_disconnect() */ 820 the destructor function GNUNET_TESTBED_controller_disconnect() */
814 GST_free_lcf(); 821 GST_free_lcf ();
815 kill_slave(slave); 822 kill_slave (slave);
816 destroy_slave(slave); 823 destroy_slave (slave);
817 slave = NULL; 824 slave = NULL;
818 LOG(GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n"); 825 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n");
819 GNUNET_SCHEDULER_shutdown(); /* We too shutdown */ 826 GNUNET_SCHEDULER_shutdown (); /* We too shutdown */
820 goto clean_lcc; 827 goto clean_lcc;
821 } 828 }
822 slave->controller = 829 slave->controller =
823 GNUNET_TESTBED_controller_connect(GST_host_list[slave->host_id], 830 GNUNET_TESTBED_controller_connect (GST_host_list[slave->host_id],
824 EVENT_MASK, &slave_event_cb, 831 EVENT_MASK, &slave_event_cb,
825 slave); 832 slave);
826 if (NULL != slave->controller) 833 if (NULL != slave->controller)
827 { 834 {
828 send_controller_link_response(lcc->client, lcc->operation_id, cfg, NULL); 835 send_controller_link_response (lcc->client, lcc->operation_id, cfg, NULL);
829 } 836 }
830 else 837 else
831 { 838 {
832 send_controller_link_response(lcc->client, lcc->operation_id, NULL, 839 send_controller_link_response (lcc->client, lcc->operation_id, NULL,
833 "Could not connect to delegated controller"); 840 "Could not connect to delegated controller");
834 kill_slave(slave); 841 kill_slave (slave);
835 destroy_slave(slave); 842 destroy_slave (slave);
836 slave = NULL; 843 slave = NULL;
837 } 844 }
838 845
839clean_lcc: 846clean_lcc:
840 if (NULL != lcc) 847 if (NULL != lcc)
848 {
849 if (NULL != lcc->client)
841 { 850 {
842 if (NULL != lcc->client) 851 GNUNET_SERVICE_client_continue (lcc->client);
843 { 852 lcc->client = NULL;
844 GNUNET_SERVICE_client_continue(lcc->client);
845 lcc->client = NULL;
846 }
847 GNUNET_free(lcc);
848 } 853 }
854 GNUNET_free (lcc);
855 }
849 if (NULL != slave) 856 if (NULL != slave)
850 slave->lcc = NULL; 857 slave->lcc = NULL;
851} 858}
@@ -860,7 +867,7 @@ clean_lcc:
860 * @param n the neighbour 867 * @param n the neighbour
861 */ 868 */
862static void 869static void
863trigger_notifications(struct Neighbour *n); 870trigger_notifications (struct Neighbour *n);
864 871
865 872
866/** 873/**
@@ -870,19 +877,19 @@ trigger_notifications(struct Neighbour *n);
870 * @param cls the neighbour 877 * @param cls the neighbour
871 */ 878 */
872static void 879static void
873neighbour_connect_notify_task(void *cls) 880neighbour_connect_notify_task (void *cls)
874{ 881{
875 struct Neighbour *n = cls; 882 struct Neighbour *n = cls;
876 struct NeighbourConnectNotification *h; 883 struct NeighbourConnectNotification *h;
877 884
878 GNUNET_assert(NULL != (h = n->nl_head)); 885 GNUNET_assert (NULL != (h = n->nl_head));
879 GNUNET_assert(NULL != n->notify_task); 886 GNUNET_assert (NULL != n->notify_task);
880 n->notify_task = NULL; 887 n->notify_task = NULL;
881 GNUNET_assert(NULL != n->controller); 888 GNUNET_assert (NULL != n->controller);
882 GNUNET_CONTAINER_DLL_remove(n->nl_head, n->nl_tail, h); 889 GNUNET_CONTAINER_DLL_remove (n->nl_head, n->nl_tail, h);
883 trigger_notifications(n); 890 trigger_notifications (n);
884 h->cb(h->cb_cls, n->controller); 891 h->cb (h->cb_cls, n->controller);
885 GNUNET_free(h); 892 GNUNET_free (h);
886} 893}
887 894
888 895
@@ -895,9 +902,9 @@ neighbour_connect_notify_task(void *cls)
895 * @param n the neighbour 902 * @param n the neighbour
896 */ 903 */
897static void 904static void
898trigger_notifications(struct Neighbour *n) 905trigger_notifications (struct Neighbour *n)
899{ 906{
900 GNUNET_assert(NULL != n->conn_op); 907 GNUNET_assert (NULL != n->conn_op);
901 if (NULL == n->nl_head) 908 if (NULL == n->nl_head)
902 return; 909 return;
903 if (NULL == n->controller) 910 if (NULL == n->controller)
@@ -905,14 +912,14 @@ trigger_notifications(struct Neighbour *n)
905 if (NULL != n->notify_task) 912 if (NULL != n->notify_task)
906 return; 913 return;
907 if (1 == n->inactive) 914 if (1 == n->inactive)
908 { 915 {
909 GNUNET_assert(0 == n->reference_cnt); 916 GNUNET_assert (0 == n->reference_cnt);
910 GNUNET_TESTBED_operation_activate_(n->conn_op); 917 GNUNET_TESTBED_operation_activate_ (n->conn_op);
911 n->inactive = 0; 918 n->inactive = 0;
912 } 919 }
913 n->reference_cnt++; 920 n->reference_cnt++;
914 n->notify_task = 921 n->notify_task =
915 GNUNET_SCHEDULER_add_now(&neighbour_connect_notify_task, n); 922 GNUNET_SCHEDULER_add_now (&neighbour_connect_notify_task, n);
916} 923}
917 924
918 925
@@ -924,18 +931,18 @@ trigger_notifications(struct Neighbour *n)
924 * @param cls the neighbour 931 * @param cls the neighbour
925 */ 932 */
926static void 933static void
927opstart_neighbour_conn(void *cls) 934opstart_neighbour_conn (void *cls)
928{ 935{
929 struct Neighbour *n = cls; 936 struct Neighbour *n = cls;
930 937
931 GNUNET_assert(NULL != n->conn_op); 938 GNUNET_assert (NULL != n->conn_op);
932 GNUNET_assert(NULL == n->controller); 939 GNUNET_assert (NULL == n->controller);
933 LOG_DEBUG("Opening connection to controller on host %u\n", n->host_id); 940 LOG_DEBUG ("Opening connection to controller on host %u\n", n->host_id);
934 n->controller = GNUNET_TESTBED_controller_connect(GST_host_list[n->host_id], 941 n->controller = GNUNET_TESTBED_controller_connect (GST_host_list[n->host_id],
935 EVENT_MASK, 942 EVENT_MASK,
936 &slave_event_cb, 943 &slave_event_cb,
937 NULL); 944 NULL);
938 trigger_notifications(n); 945 trigger_notifications (n);
939} 946}
940 947
941 948
@@ -945,19 +952,19 @@ opstart_neighbour_conn(void *cls)
945 * @param cls the neighbour 952 * @param cls the neighbour
946 */ 953 */
947static void 954static void
948oprelease_neighbour_conn(void *cls) 955oprelease_neighbour_conn (void *cls)
949{ 956{
950 struct Neighbour *n = cls; 957 struct Neighbour *n = cls;
951 958
952 GNUNET_assert(0 == n->reference_cnt); 959 GNUNET_assert (0 == n->reference_cnt);
953 GNUNET_assert(NULL == n->notify_task); 960 GNUNET_assert (NULL == n->notify_task);
954 GNUNET_assert(NULL == n->nl_head); 961 GNUNET_assert (NULL == n->nl_head);
955 if (NULL != n->controller) 962 if (NULL != n->controller)
956 { 963 {
957 LOG_DEBUG("Closing connection to controller on host %u\n", n->host_id); 964 LOG_DEBUG ("Closing connection to controller on host %u\n", n->host_id);
958 GNUNET_TESTBED_controller_disconnect(n->controller); 965 GNUNET_TESTBED_controller_disconnect (n->controller);
959 n->controller = NULL; 966 n->controller = NULL;
960 } 967 }
961 n->conn_op = NULL; 968 n->conn_op = NULL;
962 n->inactive = 0; 969 n->inactive = 0;
963} 970}
@@ -975,30 +982,30 @@ oprelease_neighbour_conn(void *cls)
975 * @param cb_cls the closure for the above callback 982 * @param cb_cls the closure for the above callback
976 */ 983 */
977struct NeighbourConnectNotification * 984struct NeighbourConnectNotification *
978GST_neighbour_get_connection(struct Neighbour *n, 985GST_neighbour_get_connection (struct Neighbour *n,
979 GST_NeigbourConnectNotifyCallback cb, 986 GST_NeigbourConnectNotifyCallback cb,
980 void *cb_cls) 987 void *cb_cls)
981{ 988{
982 struct NeighbourConnectNotification *h; 989 struct NeighbourConnectNotification *h;
983 990
984 GNUNET_assert(NULL != cb); 991 GNUNET_assert (NULL != cb);
985 LOG_DEBUG("Attempting to get connection to controller on host %u\n", 992 LOG_DEBUG ("Attempting to get connection to controller on host %u\n",
986 n->host_id); 993 n->host_id);
987 h = GNUNET_new(struct NeighbourConnectNotification); 994 h = GNUNET_new (struct NeighbourConnectNotification);
988 h->n = n; 995 h->n = n;
989 h->cb = cb; 996 h->cb = cb;
990 h->cb_cls = cb_cls; 997 h->cb_cls = cb_cls;
991 GNUNET_CONTAINER_DLL_insert_tail(n->nl_head, n->nl_tail, h); 998 GNUNET_CONTAINER_DLL_insert_tail (n->nl_head, n->nl_tail, h);
992 if (NULL == n->conn_op) 999 if (NULL == n->conn_op)
993 { 1000 {
994 GNUNET_assert(NULL == n->controller); 1001 GNUNET_assert (NULL == n->controller);
995 n->conn_op = GNUNET_TESTBED_operation_create_(n, &opstart_neighbour_conn, 1002 n->conn_op = GNUNET_TESTBED_operation_create_ (n, &opstart_neighbour_conn,
996 &oprelease_neighbour_conn); 1003 &oprelease_neighbour_conn);
997 GNUNET_TESTBED_operation_queue_insert_(GST_opq_openfds, n->conn_op); 1004 GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, n->conn_op);
998 GNUNET_TESTBED_operation_begin_wait_(n->conn_op); 1005 GNUNET_TESTBED_operation_begin_wait_ (n->conn_op);
999 return h; 1006 return h;
1000 } 1007 }
1001 trigger_notifications(n); 1008 trigger_notifications (n);
1002 return h; 1009 return h;
1003} 1010}
1004 1011
@@ -1009,33 +1016,33 @@ GST_neighbour_get_connection(struct Neighbour *n,
1009 * @param h the notification handle 1016 * @param h the notification handle
1010 */ 1017 */
1011void 1018void
1012GST_neighbour_get_connection_cancel(struct NeighbourConnectNotification *h) 1019GST_neighbour_get_connection_cancel (struct NeighbourConnectNotification *h)
1013{ 1020{
1014 struct Neighbour *n; 1021 struct Neighbour *n;
1015 int cleanup_task; 1022 int cleanup_task;
1016 1023
1017 n = h->n; 1024 n = h->n;
1018 cleanup_task = (h == n->nl_head) ? GNUNET_YES : GNUNET_NO; 1025 cleanup_task = (h == n->nl_head) ? GNUNET_YES : GNUNET_NO;
1019 GNUNET_CONTAINER_DLL_remove(n->nl_head, n->nl_tail, h); 1026 GNUNET_CONTAINER_DLL_remove (n->nl_head, n->nl_tail, h);
1020 GNUNET_free(h); 1027 GNUNET_free (h);
1021 if (GNUNET_NO == cleanup_task) 1028 if (GNUNET_NO == cleanup_task)
1022 return; 1029 return;
1023 if (NULL == n->notify_task) 1030 if (NULL == n->notify_task)
1024 return; 1031 return;
1025 GNUNET_assert(0 < n->reference_cnt); 1032 GNUNET_assert (0 < n->reference_cnt);
1026 n->reference_cnt--; 1033 n->reference_cnt--;
1027 GNUNET_SCHEDULER_cancel(n->notify_task); 1034 GNUNET_SCHEDULER_cancel (n->notify_task);
1028 n->notify_task = NULL; 1035 n->notify_task = NULL;
1029 if (NULL == n->nl_head) 1036 if (NULL == n->nl_head)
1037 {
1038 if ((0 == n->reference_cnt) && (0 == n->inactive))
1030 { 1039 {
1031 if ((0 == n->reference_cnt) && (0 == n->inactive)) 1040 n->inactive = 1;
1032 { 1041 GNUNET_TESTBED_operation_inactivate_ (n->conn_op);
1033 n->inactive = 1;
1034 GNUNET_TESTBED_operation_inactivate_(n->conn_op);
1035 }
1036 return;
1037 } 1042 }
1038 trigger_notifications(n); 1043 return;
1044 }
1045 trigger_notifications (n);
1039} 1046}
1040 1047
1041 1048
@@ -1047,16 +1054,16 @@ GST_neighbour_get_connection_cancel(struct NeighbourConnectNotification *h)
1047 * @param n the neighbour whose connection can be closed 1054 * @param n the neighbour whose connection can be closed
1048 */ 1055 */
1049void 1056void
1050GST_neighbour_release_connection(struct Neighbour *n) 1057GST_neighbour_release_connection (struct Neighbour *n)
1051{ 1058{
1052 GNUNET_assert(0 == n->inactive); 1059 GNUNET_assert (0 == n->inactive);
1053 GNUNET_assert(0 < n->reference_cnt); 1060 GNUNET_assert (0 < n->reference_cnt);
1054 n->reference_cnt--; 1061 n->reference_cnt--;
1055 if (0 == n->reference_cnt) 1062 if (0 == n->reference_cnt)
1056 { 1063 {
1057 n->inactive = 1; 1064 n->inactive = 1;
1058 GNUNET_TESTBED_operation_inactivate_(n->conn_op); 1065 GNUNET_TESTBED_operation_inactivate_ (n->conn_op);
1059 } 1066 }
1060} 1067}
1061 1068
1062 1069
@@ -1066,16 +1073,16 @@ GST_neighbour_release_connection(struct Neighbour *n)
1066 * @param ncc the neighbour connect context to cleanup 1073 * @param ncc the neighbour connect context to cleanup
1067 */ 1074 */
1068static void 1075static void
1069cleanup_ncc(struct NeighbourConnectCtxt *ncc) 1076cleanup_ncc (struct NeighbourConnectCtxt *ncc)
1070{ 1077{
1071 if (NULL != ncc->nh) 1078 if (NULL != ncc->nh)
1072 GST_neighbour_get_connection_cancel(ncc->nh); 1079 GST_neighbour_get_connection_cancel (ncc->nh);
1073 if (NULL != ncc->timeout_task) 1080 if (NULL != ncc->timeout_task)
1074 GNUNET_SCHEDULER_cancel(ncc->timeout_task); 1081 GNUNET_SCHEDULER_cancel (ncc->timeout_task);
1075 GNUNET_CONTAINER_DLL_remove(ncc_head, 1082 GNUNET_CONTAINER_DLL_remove (ncc_head,
1076 ncc_tail, 1083 ncc_tail,
1077 ncc); 1084 ncc);
1078 GNUNET_free(ncc); 1085 GNUNET_free (ncc);
1079} 1086}
1080 1087
1081 1088
@@ -1083,21 +1090,21 @@ cleanup_ncc(struct NeighbourConnectCtxt *ncc)
1083 * Cleans up the neighbour list 1090 * Cleans up the neighbour list
1084 */ 1091 */
1085void 1092void
1086GST_neighbour_list_clean() 1093GST_neighbour_list_clean ()
1087{ 1094{
1088 struct Neighbour *n; 1095 struct Neighbour *n;
1089 unsigned int id; 1096 unsigned int id;
1090 1097
1091 for (id = 0; id < neighbour_list_size; id++) 1098 for (id = 0; id < neighbour_list_size; id++)
1092 { 1099 {
1093 if (NULL == (n = neighbour_list[id])) 1100 if (NULL == (n = neighbour_list[id]))
1094 continue; 1101 continue;
1095 if (NULL != n->conn_op) 1102 if (NULL != n->conn_op)
1096 GNUNET_TESTBED_operation_release_(n->conn_op); 1103 GNUNET_TESTBED_operation_release_ (n->conn_op);
1097 GNUNET_free(n); 1104 GNUNET_free (n);
1098 neighbour_list[id] = NULL; 1105 neighbour_list[id] = NULL;
1099 } 1106 }
1100 GNUNET_free_non_null(neighbour_list); 1107 GNUNET_free_non_null (neighbour_list);
1101} 1108}
1102 1109
1103 1110
@@ -1109,7 +1116,7 @@ GST_neighbour_list_clean()
1109 * the list size or neighbour at that index is NULL) 1116 * the list size or neighbour at that index is NULL)
1110 */ 1117 */
1111struct Neighbour * 1118struct Neighbour *
1112GST_get_neighbour(uint32_t id) 1119GST_get_neighbour (uint32_t id)
1113{ 1120{
1114 if (neighbour_list_size <= id) 1121 if (neighbour_list_size <= id)
1115 return NULL; 1122 return NULL;
@@ -1121,10 +1128,10 @@ GST_get_neighbour(uint32_t id)
1121 * Function to cleanup the neighbour connect contexts 1128 * Function to cleanup the neighbour connect contexts
1122 */ 1129 */
1123void 1130void
1124GST_free_nccq() 1131GST_free_nccq ()
1125{ 1132{
1126 while (NULL != ncc_head) 1133 while (NULL != ncc_head)
1127 cleanup_ncc(ncc_head); 1134 cleanup_ncc (ncc_head);
1128} 1135}
1129 1136
1130 1137
@@ -1134,16 +1141,16 @@ GST_free_nccq()
1134 * @param cls the NeighbourConnectCtxt created in GST_handle_link_controllers() 1141 * @param cls the NeighbourConnectCtxt created in GST_handle_link_controllers()
1135 */ 1142 */
1136static void 1143static void
1137timeout_neighbour_connect(void *cls) 1144timeout_neighbour_connect (void *cls)
1138{ 1145{
1139 struct NeighbourConnectCtxt *ncc = cls; 1146 struct NeighbourConnectCtxt *ncc = cls;
1140 1147
1141 ncc->timeout_task = NULL; 1148 ncc->timeout_task = NULL;
1142 send_controller_link_response(ncc->client, 1149 send_controller_link_response (ncc->client,
1143 ncc->op_id, 1150 ncc->op_id,
1144 NULL, 1151 NULL,
1145 "Could not connect to delegated controller"); 1152 "Could not connect to delegated controller");
1146 cleanup_ncc(ncc); 1153 cleanup_ncc (ncc);
1147} 1154}
1148 1155
1149 1156
@@ -1154,20 +1161,20 @@ timeout_neighbour_connect(void *cls)
1154 * @param c the handle the neighbour's controller 1161 * @param c the handle the neighbour's controller
1155 */ 1162 */
1156static void 1163static void
1157neighbour_connect_cb(void *cls, 1164neighbour_connect_cb (void *cls,
1158 struct GNUNET_TESTBED_Controller *c) 1165 struct GNUNET_TESTBED_Controller *c)
1159{ 1166{
1160 struct NeighbourConnectCtxt *ncc = cls; 1167 struct NeighbourConnectCtxt *ncc = cls;
1161 1168
1162 GNUNET_SCHEDULER_cancel(ncc->timeout_task); 1169 GNUNET_SCHEDULER_cancel (ncc->timeout_task);
1163 ncc->timeout_task = NULL; 1170 ncc->timeout_task = NULL;
1164 ncc->nh = NULL; 1171 ncc->nh = NULL;
1165 GST_neighbour_release_connection(ncc->n); 1172 GST_neighbour_release_connection (ncc->n);
1166 send_controller_link_response(ncc->client, 1173 send_controller_link_response (ncc->client,
1167 ncc->op_id, 1174 ncc->op_id,
1168 NULL, 1175 NULL,
1169 NULL); 1176 NULL);
1170 cleanup_ncc(ncc); 1177 cleanup_ncc (ncc);
1171} 1178}
1172 1179
1173 1180
@@ -1177,13 +1184,13 @@ neighbour_connect_cb(void *cls,
1177 * @param host the host of the neighbour 1184 * @param host the host of the neighbour
1178 */ 1185 */
1179struct Neighbour * 1186struct Neighbour *
1180GST_create_neighbour(struct GNUNET_TESTBED_Host *host) 1187GST_create_neighbour (struct GNUNET_TESTBED_Host *host)
1181{ 1188{
1182 struct Neighbour *n; 1189 struct Neighbour *n;
1183 1190
1184 n = GNUNET_new(struct Neighbour); 1191 n = GNUNET_new (struct Neighbour);
1185 n->host_id = GNUNET_TESTBED_host_get_id_(host); 1192 n->host_id = GNUNET_TESTBED_host_get_id_ (host);
1186 neighbour_list_add(n); /* just add; connect on-demand */ 1193 neighbour_list_add (n); /* just add; connect on-demand */
1187 return n; 1194 return n;
1188} 1195}
1189 1196
@@ -1195,8 +1202,8 @@ GST_create_neighbour(struct GNUNET_TESTBED_Host *host)
1195 * @param msg the actual message 1202 * @param msg the actual message
1196 */ 1203 */
1197void 1204void
1198handle_link_controllers(void *cls, 1205handle_link_controllers (void *cls,
1199 const struct GNUNET_TESTBED_ControllerLinkRequest *msg) 1206 const struct GNUNET_TESTBED_ControllerLinkRequest *msg)
1200{ 1207{
1201 struct GNUNET_SERVICE_Client *client = cls; 1208 struct GNUNET_SERVICE_Client *client = cls;
1202 struct LCFContext *lcf; 1209 struct LCFContext *lcf;
@@ -1207,169 +1214,169 @@ handle_link_controllers(void *cls,
1207 uint32_t slave_host_id; 1214 uint32_t slave_host_id;
1208 1215
1209 if (NULL == GST_context) 1216 if (NULL == GST_context)
1210 { 1217 {
1211 GNUNET_break(0); 1218 GNUNET_break (0);
1212 GNUNET_SERVICE_client_drop(client); 1219 GNUNET_SERVICE_client_drop (client);
1213 return; 1220 return;
1214 } 1221 }
1215 delegated_host_id = ntohl(msg->delegated_host_id); 1222 delegated_host_id = ntohl (msg->delegated_host_id);
1216 if (delegated_host_id == GST_context->host_id) 1223 if (delegated_host_id == GST_context->host_id)
1217 { 1224 {
1218 GNUNET_break(0); 1225 GNUNET_break (0);
1219 LOG(GNUNET_ERROR_TYPE_WARNING, 1226 LOG (GNUNET_ERROR_TYPE_WARNING,
1220 "Trying to link ourselves\n"); 1227 "Trying to link ourselves\n");
1221 GNUNET_SERVICE_client_drop(client); 1228 GNUNET_SERVICE_client_drop (client);
1222 return; 1229 return;
1223 } 1230 }
1224 if ((delegated_host_id >= GST_host_list_size) || 1231 if ((delegated_host_id >= GST_host_list_size) ||
1225 (NULL == GST_host_list[delegated_host_id])) 1232 (NULL == GST_host_list[delegated_host_id]))
1226 { 1233 {
1227 LOG(GNUNET_ERROR_TYPE_WARNING, 1234 LOG (GNUNET_ERROR_TYPE_WARNING,
1228 "Delegated host %u not registered with us\n", 1235 "Delegated host %u not registered with us\n",
1229 delegated_host_id); 1236 delegated_host_id);
1230 GNUNET_SERVICE_client_drop(client); 1237 GNUNET_SERVICE_client_drop (client);
1231 return; 1238 return;
1232 } 1239 }
1233 slave_host_id = ntohl(msg->slave_host_id); 1240 slave_host_id = ntohl (msg->slave_host_id);
1234 if ((slave_host_id >= GST_host_list_size) || 1241 if ((slave_host_id >= GST_host_list_size) ||
1235 (NULL == GST_host_list[slave_host_id])) 1242 (NULL == GST_host_list[slave_host_id]))
1236 { 1243 {
1237 LOG(GNUNET_ERROR_TYPE_WARNING, 1244 LOG (GNUNET_ERROR_TYPE_WARNING,
1238 "Slave host %u not registered with us\n", 1245 "Slave host %u not registered with us\n",
1239 slave_host_id); 1246 slave_host_id);
1240 GNUNET_SERVICE_client_drop(client); 1247 GNUNET_SERVICE_client_drop (client);
1241 return; 1248 return;
1242 } 1249 }
1243 if (slave_host_id == delegated_host_id) 1250 if (slave_host_id == delegated_host_id)
1251 {
1252 LOG (GNUNET_ERROR_TYPE_WARNING,
1253 "Slave and delegated host are same\n");
1254 GNUNET_SERVICE_client_drop (client);
1255 return;
1256 }
1257 op_id = GNUNET_ntohll (msg->operation_id);
1258 if (slave_host_id == GST_context->host_id) /* Link from us */
1259 {
1260 struct Slave *slave;
1261 struct LinkControllersContext *lcc;
1262
1263 if (1 != msg->is_subordinate)
1244 { 1264 {
1245 LOG(GNUNET_ERROR_TYPE_WARNING, 1265 struct Neighbour *n;
1246 "Slave and delegated host are same\n"); 1266 struct NeighbourConnectCtxt *ncc;
1247 GNUNET_SERVICE_client_drop(client); 1267
1268 if ((delegated_host_id < neighbour_list_size) &&
1269 (NULL != neighbour_list[delegated_host_id]))
1270 {
1271 GNUNET_break (0);
1272 GNUNET_SERVICE_client_drop (client);
1273 return;
1274 }
1275 LOG_DEBUG ("Received request to establish a link to host %u\n",
1276 delegated_host_id);
1277 n = GST_create_neighbour (GST_host_list[delegated_host_id]);
1278 ncc = GNUNET_new (struct NeighbourConnectCtxt);
1279 ncc->n = n;
1280 ncc->op_id = op_id;
1281 ncc->client = client;
1282 ncc->nh = GST_neighbour_get_connection (n,
1283 &neighbour_connect_cb,
1284 ncc);
1285 ncc->timeout_task
1286 = GNUNET_SCHEDULER_add_delayed (GST_timeout,
1287 &timeout_neighbour_connect,
1288 ncc);
1289 GNUNET_CONTAINER_DLL_insert_tail (ncc_head,
1290 ncc_tail,
1291 ncc);
1292 GNUNET_SERVICE_client_continue (client);
1248 return; 1293 return;
1249 } 1294 }
1250 op_id = GNUNET_ntohll(msg->operation_id); 1295 if ((delegated_host_id < GST_slave_list_size) &&
1251 if (slave_host_id == GST_context->host_id) /* Link from us */ 1296 (NULL != GST_slave_list[delegated_host_id]))
1252 { 1297 {
1253 struct Slave *slave; 1298 GNUNET_break (0);
1254 struct LinkControllersContext *lcc; 1299 GNUNET_SERVICE_client_drop (client);
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);
1315 return; 1300 return;
1316 } 1301 }
1302 LOG_DEBUG ("Received request to start and establish a link to host %u\n",
1303 delegated_host_id);
1304 slave = GNUNET_new (struct Slave);
1305 slave->host_id = delegated_host_id;
1306 slave->reghost_map = GNUNET_CONTAINER_multihashmap_create (100,
1307 GNUNET_NO);
1308 slave_list_add (slave);
1309 lcc = GNUNET_new (struct LinkControllersContext);
1310 lcc->operation_id = op_id;
1311 lcc->client = client;
1312 slave->lcc = lcc;
1313 slave->controller_proc
1314 = GNUNET_TESTBED_controller_start (GST_context->master_ip,
1315 GST_host_list[slave->host_id],
1316 &slave_status_cb,
1317 slave);
1318 new_route = GNUNET_new (struct Route);
1319 new_route->dest = delegated_host_id;
1320 new_route->thru = GST_context->host_id;
1321 route_list_add (new_route);
1322 return;
1323 }
1317 1324
1318 /* Route the request */ 1325 /* Route the request */
1319 if (slave_host_id >= route_list_size) 1326 if (slave_host_id >= route_list_size)
1320 { 1327 {
1321 LOG(GNUNET_ERROR_TYPE_WARNING, 1328 LOG (GNUNET_ERROR_TYPE_WARNING,
1322 "No route towards slave host"); 1329 "No route towards slave host");
1323 GNUNET_SERVICE_client_drop(client); 1330 GNUNET_SERVICE_client_drop (client);
1324 return; 1331 return;
1325 } 1332 }
1326 lcf = GNUNET_new(struct LCFContext); 1333 lcf = GNUNET_new (struct LCFContext);
1327 lcf->delegated_host_id = delegated_host_id; 1334 lcf->delegated_host_id = delegated_host_id;
1328 lcf->slave_host_id = slave_host_id; 1335 lcf->slave_host_id = slave_host_id;
1329 route = GST_find_dest_route(slave_host_id); 1336 route = GST_find_dest_route (slave_host_id);
1330 GNUNET_assert(NULL != route); /* because we add routes carefully */ 1337 GNUNET_assert (NULL != route); /* because we add routes carefully */
1331 GNUNET_assert(route->dest < GST_slave_list_size); 1338 GNUNET_assert (route->dest < GST_slave_list_size);
1332 GNUNET_assert(NULL != GST_slave_list[route->dest]); 1339 GNUNET_assert (NULL != GST_slave_list[route->dest]);
1333 lcf->is_subordinate = msg->is_subordinate; 1340 lcf->is_subordinate = msg->is_subordinate;
1334 lcf->state = INIT; 1341 lcf->state = INIT;
1335 lcf->operation_id = op_id; 1342 lcf->operation_id = op_id;
1336 lcf->gateway = GST_slave_list[route->dest]; 1343 lcf->gateway = GST_slave_list[route->dest];
1337 lcf->client = client; 1344 lcf->client = client;
1338 if (NULL == lcf_head) 1345 if (NULL == lcf_head)
1339 { 1346 {
1340 GNUNET_assert(NULL == lcf_proc_task_id); 1347 GNUNET_assert (NULL == lcf_proc_task_id);
1341 GNUNET_CONTAINER_DLL_insert_tail(lcf_head, 1348 GNUNET_CONTAINER_DLL_insert_tail (lcf_head,
1342 lcf_tail, 1349 lcf_tail,
1343 lcf); 1350 lcf);
1344 lcf_proc_task_id = GNUNET_SCHEDULER_add_now(&lcf_proc_task, 1351 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task,
1345 lcf); 1352 lcf);
1346 } 1353 }
1347 else 1354 else
1348 { 1355 {
1349 GNUNET_CONTAINER_DLL_insert_tail(lcf_head, 1356 GNUNET_CONTAINER_DLL_insert_tail (lcf_head,
1350 lcf_tail, 1357 lcf_tail,
1351 lcf); 1358 lcf);
1352 } 1359 }
1353 /* FIXME: Adding a new route should happen after the controllers are linked 1360 /* FIXME: Adding a new route should happen after the controllers are linked
1354 * successfully */ 1361 * successfully */
1355 if (1 != msg->is_subordinate) 1362 if (1 != msg->is_subordinate)
1356 { 1363 {
1357 GNUNET_SERVICE_client_continue(client); 1364 GNUNET_SERVICE_client_continue (client);
1358 return; 1365 return;
1359 } 1366 }
1360 if ((delegated_host_id < route_list_size) && 1367 if ((delegated_host_id < route_list_size) &&
1361 (NULL != route_list[delegated_host_id])) 1368 (NULL != route_list[delegated_host_id]))
1362 { 1369 {
1363 GNUNET_break_op(0); /* Are you trying to link delegated host twice 1370 GNUNET_break_op (0); /* Are you trying to link delegated host twice
1364 * with is subordinate flag set to GNUNET_YES? */ 1371 * with is subordinate flag set to GNUNET_YES? */
1365 GNUNET_SERVICE_client_drop(client); 1372 GNUNET_SERVICE_client_drop (client);
1366 return; 1373 return;
1367 } 1374 }
1368 new_route = GNUNET_new(struct Route); 1375 new_route = GNUNET_new (struct Route);
1369 new_route->dest = delegated_host_id; 1376 new_route->dest = delegated_host_id;
1370 new_route->thru = route->dest; 1377 new_route->thru = route->dest;
1371 route_list_add(new_route); 1378 route_list_add (new_route);
1372 GNUNET_SERVICE_client_continue(client); 1379 GNUNET_SERVICE_client_continue (client);
1373} 1380}
1374 1381
1375 1382
@@ -1380,7 +1387,7 @@ handle_link_controllers(void *cls,
1380 * @param client the client that is history 1387 * @param client the client that is history
1381 */ 1388 */
1382void 1389void
1383GST_link_notify_disconnect(struct GNUNET_SERVICE_Client *client) 1390GST_link_notify_disconnect (struct GNUNET_SERVICE_Client *client)
1384{ 1391{
1385 struct NeighbourConnectCtxt *ncc; 1392 struct NeighbourConnectCtxt *ncc;
1386 struct NeighbourConnectCtxt *nccn; 1393 struct NeighbourConnectCtxt *nccn;
@@ -1388,44 +1395,44 @@ GST_link_notify_disconnect(struct GNUNET_SERVICE_Client *client)
1388 struct LCFContext *lcfn; 1395 struct LCFContext *lcfn;
1389 1396
1390 for (ncc = ncc_head; NULL != ncc; ncc = nccn) 1397 for (ncc = ncc_head; NULL != ncc; ncc = nccn)
1391 { 1398 {
1392 nccn = ncc->next; 1399 nccn = ncc->next;
1393 if (ncc->client == client) 1400 if (ncc->client == client)
1394 cleanup_ncc(ncc); 1401 cleanup_ncc (ncc);
1395 } 1402 }
1396 for (unsigned int i = 0; i < GST_slave_list_size; i++) 1403 for (unsigned int i = 0; i < GST_slave_list_size; i++)
1404 {
1405 struct Slave *slave = GST_slave_list[i];
1406 struct LinkControllersContext *lcc;
1407
1408 if (NULL == slave)
1409 continue;
1410 GNUNET_CONTAINER_multihashmap_iterate (slave->reghost_map,
1411 &drop_client_entries,
1412 client);
1413 lcc = slave->lcc;
1414 if (NULL == lcc)
1415 continue;
1416 if (lcc->client == client)
1397 { 1417 {
1398 struct Slave *slave = GST_slave_list[i]; 1418 slave->lcc = NULL;
1399 struct LinkControllersContext *lcc; 1419 GNUNET_free (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 } 1420 }
1421 }
1415 for (lcf = lcf_head; NULL != lcf; lcf = lcfn) 1422 for (lcf = lcf_head; NULL != lcf; lcf = lcfn)
1423 {
1424 lcfn = lcf->next;
1425 if ((NULL != lcf) &&
1426 (client == lcf->client))
1416 { 1427 {
1417 lcfn = lcf->next; 1428 if (NULL != lcf->op)
1418 if ((NULL != lcf) && 1429 GNUNET_TESTBED_operation_done (lcf->op);
1419 (client == lcf->client)) 1430 GNUNET_CONTAINER_DLL_remove (lcf_head,
1420 { 1431 lcf_tail,
1421 if (NULL != lcf->op) 1432 lcf);
1422 GNUNET_TESTBED_operation_done(lcf->op); 1433 GNUNET_free (lcf);
1423 GNUNET_CONTAINER_DLL_remove(lcf_head,
1424 lcf_tail,
1425 lcf);
1426 GNUNET_free(lcf);
1427 }
1428 } 1434 }
1435 }
1429} 1436}
1430 1437
1431 1438
@@ -1433,28 +1440,28 @@ GST_link_notify_disconnect(struct GNUNET_SERVICE_Client *client)
1433 * Cleans up the queue used for forwarding link controllers requests 1440 * Cleans up the queue used for forwarding link controllers requests
1434 */ 1441 */
1435void 1442void
1436GST_free_lcf() 1443GST_free_lcf ()
1437{ 1444{
1438 struct LCFContext *lcf; 1445 struct LCFContext *lcf;
1439 1446
1440 if (NULL != lcf_head) 1447 if (NULL != lcf_head)
1448 {
1449 if (NULL != lcf_proc_task_id)
1441 { 1450 {
1442 if (NULL != lcf_proc_task_id) 1451 GNUNET_SCHEDULER_cancel (lcf_proc_task_id);
1443 { 1452 lcf_proc_task_id = NULL;
1444 GNUNET_SCHEDULER_cancel(lcf_proc_task_id);
1445 lcf_proc_task_id = NULL;
1446 }
1447 } 1453 }
1448 GNUNET_assert(NULL == lcf_proc_task_id); 1454 }
1455 GNUNET_assert (NULL == lcf_proc_task_id);
1449 for (lcf = lcf_head; NULL != lcf; lcf = lcf_head) 1456 for (lcf = lcf_head; NULL != lcf; lcf = lcf_head)
1450 { 1457 {
1451 if (NULL != lcf->op) 1458 if (NULL != lcf->op)
1452 GNUNET_TESTBED_operation_done(lcf->op); 1459 GNUNET_TESTBED_operation_done (lcf->op);
1453 if (NULL != lcf->timeout_task) 1460 if (NULL != lcf->timeout_task)
1454 GNUNET_SCHEDULER_cancel(lcf->timeout_task); 1461 GNUNET_SCHEDULER_cancel (lcf->timeout_task);
1455 GNUNET_CONTAINER_DLL_remove(lcf_head, 1462 GNUNET_CONTAINER_DLL_remove (lcf_head,
1456 lcf_tail, 1463 lcf_tail,
1457 lcf); 1464 lcf);
1458 GNUNET_free(lcf); 1465 GNUNET_free (lcf);
1459 } 1466 }
1460} 1467}
diff --git a/src/testbed/gnunet-service-testbed_links.h b/src/testbed/gnunet-service-testbed_links.h
index 594ef29dc..021895b1c 100644
--- a/src/testbed/gnunet-service-testbed_links.h
+++ b/src/testbed/gnunet-service-testbed_links.h
@@ -35,7 +35,8 @@ struct Neighbour;
35/** 35/**
36 * Structure representing a connected(directly-linked) controller 36 * Structure representing a connected(directly-linked) controller
37 */ 37 */
38struct Slave { 38struct Slave
39{
39 /** 40 /**
40 * The controller process handle if we had started the controller 41 * The controller process handle if we had started the controller
41 */ 42 */
@@ -93,7 +94,7 @@ extern unsigned int GST_slave_list_size;
93 * Cleans up the neighbour list 94 * Cleans up the neighbour list
94 */ 95 */
95void 96void
96GST_neighbour_list_clean(void); 97GST_neighbour_list_clean (void);
97 98
98 99
99/** 100/**
@@ -104,14 +105,14 @@ GST_neighbour_list_clean(void);
104 * the list size or neighbour at that index is NULL) 105 * the list size or neighbour at that index is NULL)
105 */ 106 */
106struct Neighbour * 107struct Neighbour *
107GST_get_neighbour(uint32_t id); 108GST_get_neighbour (uint32_t id);
108 109
109 110
110/** 111/**
111 * Function to cleanup the neighbour connect contexts 112 * Function to cleanup the neighbour connect contexts
112 */ 113 */
113void 114void
114GST_free_nccq(void); 115GST_free_nccq (void);
115 116
116 117
117/** 118/**
@@ -129,7 +130,8 @@ struct NeighbourConnectNotification;
129 */ 130 */
130typedef void 131typedef void
131(*GST_NeigbourConnectNotifyCallback) (void *cls, 132(*GST_NeigbourConnectNotifyCallback) (void *cls,
132 struct GNUNET_TESTBED_Controller *controller); 133 struct GNUNET_TESTBED_Controller *
134 controller);
133 135
134 136
135/** 137/**
@@ -144,9 +146,9 @@ typedef void
144 * @param cb_cls the closure for the above callback 146 * @param cb_cls the closure for the above callback
145 */ 147 */
146struct NeighbourConnectNotification * 148struct NeighbourConnectNotification *
147GST_neighbour_get_connection(struct Neighbour *n, 149GST_neighbour_get_connection (struct Neighbour *n,
148 GST_NeigbourConnectNotifyCallback cb, 150 GST_NeigbourConnectNotifyCallback cb,
149 void *cb_cls); 151 void *cb_cls);
150 152
151 153
152/** 154/**
@@ -155,7 +157,7 @@ GST_neighbour_get_connection(struct Neighbour *n,
155 * @param h the notification handle 157 * @param h the notification handle
156 */ 158 */
157void 159void
158GST_neighbour_get_connection_cancel(struct NeighbourConnectNotification *h); 160GST_neighbour_get_connection_cancel (struct NeighbourConnectNotification *h);
159 161
160 162
161/** 163/**
@@ -166,7 +168,7 @@ GST_neighbour_get_connection_cancel(struct NeighbourConnectNotification *h);
166 * @param n the neighbour whose connection can be closed 168 * @param n the neighbour whose connection can be closed
167 */ 169 */
168void 170void
169GST_neighbour_release_connection(struct Neighbour *n); 171GST_neighbour_release_connection (struct Neighbour *n);
170 172
171 173
172/** 174/**
@@ -175,7 +177,7 @@ GST_neighbour_release_connection(struct Neighbour *n);
175 * @param host the host of the neighbour 177 * @param host the host of the neighbour
176 */ 178 */
177struct Neighbour * 179struct Neighbour *
178GST_create_neighbour(struct GNUNET_TESTBED_Host *host); 180GST_create_neighbour (struct GNUNET_TESTBED_Host *host);
179 181
180 182
181/** 183/**
@@ -185,8 +187,9 @@ GST_create_neighbour(struct GNUNET_TESTBED_Host *host);
185 * @param msg the actual message 187 * @param msg the actual message
186 */ 188 */
187void 189void
188handle_link_controllers(void *cls, 190handle_link_controllers (void *cls,
189 const struct GNUNET_TESTBED_ControllerLinkRequest *msg); 191 const struct
192 GNUNET_TESTBED_ControllerLinkRequest *msg);
190 193
191 194
192/** 195/**
@@ -196,11 +199,11 @@ handle_link_controllers(void *cls,
196 * @param client the client that is history 199 * @param client the client that is history
197 */ 200 */
198void 201void
199GST_link_notify_disconnect(struct GNUNET_SERVICE_Client *client); 202GST_link_notify_disconnect (struct GNUNET_SERVICE_Client *client);
200 203
201 204
202/** 205/**
203 * Cleans up the slave list 206 * Cleans up the slave list
204 */ 207 */
205void 208void
206GST_slave_list_clear(void); 209GST_slave_list_clear (void);
diff --git a/src/testbed/gnunet-service-testbed_meminfo.c b/src/testbed/gnunet-service-testbed_meminfo.c
index 27778447c..5afce288b 100644
--- a/src/testbed/gnunet-service-testbed_meminfo.c
+++ b/src/testbed/gnunet-service-testbed_meminfo.c
@@ -49,15 +49,15 @@
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;
53#define UPTIME_FILE "/proc/uptime" 53#define UPTIME_FILE "/proc/uptime"
54//static int uptime_fd = -1; 54// static int uptime_fd = -1;
55#define LOADAVG_FILE "/proc/loadavg" 55#define LOADAVG_FILE "/proc/loadavg"
56//static int loadavg_fd = -1; 56// static int loadavg_fd = -1;
57#define MEMINFO_FILE "/proc/meminfo" 57#define MEMINFO_FILE "/proc/meminfo"
58static int meminfo_fd = -1; 58static int meminfo_fd = -1;
59#define VMINFO_FILE "/proc/vmstat" 59#define VMINFO_FILE "/proc/vmstat"
60//static int vminfo_fd = -1; 60// static int vminfo_fd = -1;
61 61
62// As of 2.6.24 /proc/meminfo seems to need 888 on 64-bit, 62// As of 2.6.24 /proc/meminfo seems to need 888 on 64-bit,
63// and would need 1258 if the obsolete fields were there. 63// and would need 1258 if the obsolete fields were there.
@@ -68,20 +68,20 @@ static char buf[2048];
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/***********************************************************************/
@@ -96,14 +96,17 @@ static char buf[2048];
96 * GNU Library General Public License for more details. 96 * GNU Library General Public License for more details.
97 */ 97 */
98 98
99typedef struct mem_table_struct { 99typedef struct mem_table_struct
100{
100 const char *name; /* memory type name */ 101 const char *name; /* memory type name */
101 unsigned long *slot; /* slot in return struct */ 102 unsigned long *slot; /* slot in return struct */
102} mem_table_struct; 103} mem_table_struct;
103 104
104static int compare_mem_table_structs(const void *a, const void *b) 105static int compare_mem_table_structs (const void *a, const void *b)
105{ 106{
106 return strcmp(((const mem_table_struct*)a)->name, ((const mem_table_struct*)b)->name); 107 return strcmp (((const mem_table_struct*) a)->name, ((const
108 mem_table_struct*) b)->
109 name);
107} 110}
108 111
109/* example data, following junk, with comments added: 112/* example data, following junk, with comments added:
@@ -183,7 +186,7 @@ static unsigned long kb_nfs_unstable;
183static unsigned long kb_swap_reclaimable; 186static unsigned long kb_swap_reclaimable;
184static unsigned long kb_swap_unreclaimable; 187static unsigned long kb_swap_unreclaimable;
185 188
186void meminfo(void) 189void meminfo (void)
187{ 190{
188 char namebuf[16]; /* big enough to hold any row name */ 191 char namebuf[16]; /* big enough to hold any row name */
189 mem_table_struct findme = { namebuf, NULL }; 192 mem_table_struct findme = { namebuf, NULL };
@@ -228,45 +231,45 @@ void meminfo(void)
228 }; 231 };
229 const int mem_table_count = sizeof(mem_table) / sizeof(mem_table_struct); 232 const int mem_table_count = sizeof(mem_table) / sizeof(mem_table_struct);
230 233
231 FILE_TO_BUF(MEMINFO_FILE, meminfo_fd); 234 FILE_TO_BUF (MEMINFO_FILE, meminfo_fd);
232 235
233 kb_inactive = ~0UL; 236 kb_inactive = ~0UL;
234 237
235 head = buf; 238 head = buf;
236 for (;;) 239 for (;;)
240 {
241 tail = strchr (head, ':');
242 if (! tail)
243 break;
244 *tail = '\0';
245 if (strlen (head) >= sizeof(namebuf))
237 { 246 {
238 tail = strchr(head, ':');
239 if (!tail)
240 break;
241 *tail = '\0';
242 if (strlen(head) >= sizeof(namebuf))
243 {
244 head = tail + 1;
245 goto nextline;
246 }
247 strcpy(namebuf, head);
248 found = bsearch(&findme, mem_table, mem_table_count,
249 sizeof(mem_table_struct), compare_mem_table_structs
250 );
251 head = tail + 1;
252 if (!found)
253 goto nextline;
254 *(found->slot) = (unsigned long)strtoull(head, &tail, 10);
255nextline:
256 tail = strchr(head, '\n');
257 if (!tail)
258 break;
259 head = tail + 1; 247 head = tail + 1;
248 goto nextline;
260 } 249 }
261 if (!kb_low_total) /* low==main except with large-memory support */ 250 strcpy (namebuf, head);
262 { 251 found = bsearch (&findme, mem_table, mem_table_count,
263 kb_low_total = kb_main_total; 252 sizeof(mem_table_struct), compare_mem_table_structs
264 kb_low_free = kb_main_free; 253 );
265 } 254 head = tail + 1;
255 if (! found)
256 goto nextline;
257 *(found->slot) = (unsigned long) strtoull (head, &tail, 10);
258nextline:
259 tail = strchr (head, '\n');
260 if (! tail)
261 break;
262 head = tail + 1;
263 }
264 if (! kb_low_total) /* low==main except with large-memory support */
265 {
266 kb_low_total = kb_main_total;
267 kb_low_free = kb_main_free;
268 }
266 if (kb_inactive == ~0UL) 269 if (kb_inactive == ~0UL)
267 { 270 {
268 kb_inactive = kb_inact_dirty + kb_inact_clean + kb_inact_laundry; 271 kb_inactive = kb_inact_dirty + kb_inact_clean + kb_inact_laundry;
269 } 272 }
270 kb_swap_used = kb_swap_total - kb_swap_free; 273 kb_swap_used = kb_swap_total - kb_swap_free;
271 kb_main_used = kb_main_total - kb_main_free; 274 kb_main_used = kb_main_total - kb_main_free;
272} 275}
diff --git a/src/testbed/gnunet-service-testbed_meminfo.h b/src/testbed/gnunet-service-testbed_meminfo.h
index ceaae8999..b993a8a97 100644
--- a/src/testbed/gnunet-service-testbed_meminfo.h
+++ b/src/testbed/gnunet-service-testbed_meminfo.h
@@ -52,4 +52,4 @@ extern unsigned long kb_inactive;
52extern unsigned long kb_mapped; 52extern unsigned long kb_mapped;
53extern unsigned long kb_pagetables; 53extern unsigned long kb_pagetables;
54 54
55extern void meminfo(void); 55extern void meminfo (void);
diff --git a/src/testbed/gnunet-service-testbed_oc.c b/src/testbed/gnunet-service-testbed_oc.c
index 391b95b12..817a8b2fc 100644
--- a/src/testbed/gnunet-service-testbed_oc.c
+++ b/src/testbed/gnunet-service-testbed_oc.c
@@ -35,13 +35,14 @@
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 */
44struct ConnectivitySuggestContext { 44struct ConnectivitySuggestContext
45{
45 /** 46 /**
46 * The transport handle obtained from cache. Do NOT close/disconnect. 47 * The transport handle obtained from cache. Do NOT close/disconnect.
47 */ 48 */
@@ -73,7 +74,8 @@ struct ConnectivitySuggestContext {
73/** 74/**
74 * Types for context information we create for overlay connect requests 75 * Types for context information we create for overlay connect requests
75 */ 76 */
76enum OverlayConnectContextType { 77enum OverlayConnectContextType
78{
77 /** 79 /**
78 * This type is used if the overlay connection is local i.e. the connection 80 * This type is used if the overlay connection is local i.e. the connection
79 * has to be made between local peers 81 * has to be made between local peers
@@ -98,7 +100,8 @@ enum OverlayConnectContextType {
98 * Context data for operations on second peer in local overlay connection 100 * Context data for operations on second peer in local overlay connection
99 * contexts 101 * contexts
100 */ 102 */
101struct LocalPeer2Context { 103struct LocalPeer2Context
104{
102 /** 105 /**
103 * The handle for offering the HELLO of the first peer to the second 106 * The handle for offering the HELLO of the first peer to the second
104 * peer. 107 * peer.
@@ -116,7 +119,8 @@ struct LocalPeer2Context {
116 * Context data for operations on second peer in remote overlay connection 119 * Context data for operations on second peer in remote overlay connection
117 * contexts 120 * contexts
118 */ 121 */
119struct RemotePeer2Context { 122struct RemotePeer2Context
123{
120 /** 124 /**
121 * Controller of peer 2; If #OCC_TYPE_REMOTE_LATERAL is the type of overlay 125 * Controller of peer 2; If #OCC_TYPE_REMOTE_LATERAL is the type of overlay
122 * connection then this can be NULL until the connection to the controller is 126 * connection then this can be NULL until the connection to the controller is
@@ -146,7 +150,8 @@ struct RemotePeer2Context {
146/** 150/**
147 * Context information for connecting 2 peers in overlay. 151 * Context information for connecting 2 peers in overlay.
148 */ 152 */
149struct OverlayConnectContext { 153struct OverlayConnectContext
154{
150 /** 155 /**
151 * The next pointer for maintaining a DLL of all OverlayConnectContexts 156 * The next pointer for maintaining a DLL of all OverlayConnectContexts
152 */ 157 */
@@ -203,7 +208,8 @@ struct OverlayConnectContext {
203 /** 208 /**
204 * Context information for operations on the second peer 209 * Context information for operations on the second peer
205 */ 210 */
206 union { 211 union
212 {
207 /** 213 /**
208 * Context information to be used if the second peer is local 214 * Context information to be used if the second peer is local
209 */ 215 */
@@ -265,7 +271,8 @@ struct OverlayConnectContext {
265 * peer A to make peer B connect to peer A by sending the controller of peer B 271 * peer A to make peer B connect to peer A by sending the controller of peer B
266 * the HELLO of peer A. 272 * the HELLO of peer A.
267 */ 273 */
268struct RemoteOverlayConnectCtx { 274struct RemoteOverlayConnectCtx
275{
269 /** 276 /**
270 * the next pointer for DLL 277 * the next pointer for DLL
271 */ 278 */
@@ -346,15 +353,15 @@ static struct RemoteOverlayConnectCtx *roccq_tail;
346 * @param focc the ForwardedOverlayConnectContext to cleanup 353 * @param focc the ForwardedOverlayConnectContext to cleanup
347 */ 354 */
348void 355void
349GST_cleanup_focc(struct ForwardedOverlayConnectContext *focc) 356GST_cleanup_focc (struct ForwardedOverlayConnectContext *focc)
350{ 357{
351 struct RegisteredHostContext *rhc = focc->rhc; 358 struct RegisteredHostContext *rhc = focc->rhc;
352 359
353 GNUNET_CONTAINER_DLL_remove(rhc->focc_dll_head, 360 GNUNET_CONTAINER_DLL_remove (rhc->focc_dll_head,
354 rhc->focc_dll_tail, 361 rhc->focc_dll_tail,
355 focc); 362 focc);
356 GNUNET_free_non_null(focc->orig_msg); 363 GNUNET_free_non_null (focc->orig_msg);
357 GNUNET_free(focc); 364 GNUNET_free (focc);
358} 365}
359 366
360 367
@@ -364,7 +371,7 @@ GST_cleanup_focc(struct ForwardedOverlayConnectContext *focc)
364 * @param cls the `struct ForwardedOperationContext` 371 * @param cls the `struct ForwardedOperationContext`
365 */ 372 */
366static void 373static void
367forwarded_overlay_connect_timeout(void *cls) 374forwarded_overlay_connect_timeout (void *cls)
368{ 375{
369 struct ForwardedOperationContext *fopc = cls; 376 struct ForwardedOperationContext *fopc = cls;
370 struct RegisteredHostContext *rhc; 377 struct RegisteredHostContext *rhc;
@@ -373,13 +380,13 @@ forwarded_overlay_connect_timeout(void *cls)
373 fopc->timeout_task = NULL; 380 fopc->timeout_task = NULL;
374 rhc = fopc->cls; 381 rhc = fopc->cls;
375 focc = rhc->focc_dll_head; 382 focc = rhc->focc_dll_head;
376 LOG_DEBUG("Overlay linking between peers %u and %u failed\n", 383 LOG_DEBUG ("Overlay linking between peers %u and %u failed\n",
377 focc->peer1, 384 focc->peer1,
378 focc->peer2); 385 focc->peer2);
379 GST_cleanup_focc(focc); 386 GST_cleanup_focc (focc);
380 GST_forwarded_operation_timeout(fopc); 387 GST_forwarded_operation_timeout (fopc);
381 if (NULL != rhc->focc_dll_head) 388 if (NULL != rhc->focc_dll_head)
382 GST_process_next_focc(rhc); 389 GST_process_next_focc (rhc);
383} 390}
384 391
385 392
@@ -392,19 +399,19 @@ forwarded_overlay_connect_timeout(void *cls)
392 * @param msg the peer create success message 399 * @param msg the peer create success message
393 */ 400 */
394static void 401static void
395forwarded_overlay_connect_listener(void *cls, 402forwarded_overlay_connect_listener (void *cls,
396 const struct GNUNET_MessageHeader *msg) 403 const struct GNUNET_MessageHeader *msg)
397{ 404{
398 struct ForwardedOperationContext *fopc = cls; 405 struct ForwardedOperationContext *fopc = cls;
399 struct RegisteredHostContext *rhc; 406 struct RegisteredHostContext *rhc;
400 struct ForwardedOverlayConnectContext *focc; 407 struct ForwardedOverlayConnectContext *focc;
401 408
402 rhc = fopc->cls; 409 rhc = fopc->cls;
403 GST_forwarded_operation_reply_relay(cls, msg); 410 GST_forwarded_operation_reply_relay (cls, msg);
404 focc = rhc->focc_dll_head; 411 focc = rhc->focc_dll_head;
405 GST_cleanup_focc(focc); 412 GST_cleanup_focc (focc);
406 if (NULL != rhc->focc_dll_head) 413 if (NULL != rhc->focc_dll_head)
407 GST_process_next_focc(rhc); 414 GST_process_next_focc (rhc);
408} 415}
409 416
410 417
@@ -414,7 +421,7 @@ forwarded_overlay_connect_listener(void *cls,
414 * @param rhc the RegisteredHostContext 421 * @param rhc the RegisteredHostContext
415 */ 422 */
416void 423void
417GST_process_next_focc(struct RegisteredHostContext *rhc) 424GST_process_next_focc (struct RegisteredHostContext *rhc)
418{ 425{
419 struct ForwardedOperationContext *fopc; 426 struct ForwardedOperationContext *fopc;
420 struct ForwardedOverlayConnectContext *focc; 427 struct ForwardedOverlayConnectContext *focc;
@@ -422,31 +429,32 @@ GST_process_next_focc(struct RegisteredHostContext *rhc)
422 struct Slave *slave; 429 struct Slave *slave;
423 430
424 focc = rhc->focc_dll_head; 431 focc = rhc->focc_dll_head;
425 GNUNET_assert(NULL != focc); 432 GNUNET_assert (NULL != focc);
426 GNUNET_assert(RHC_DONE == rhc->state); 433 GNUNET_assert (RHC_DONE == rhc->state);
427 GNUNET_assert(VALID_PEER_ID(focc->peer1)); 434 GNUNET_assert (VALID_PEER_ID (focc->peer1));
428 peer = GST_peer_list[focc->peer1]; 435 peer = GST_peer_list[focc->peer1];
429 GNUNET_assert(GNUNET_YES == peer->is_remote); 436 GNUNET_assert (GNUNET_YES == peer->is_remote);
430 GNUNET_assert(NULL != (slave = peer->details.remote.slave)); 437 GNUNET_assert (NULL != (slave = peer->details.remote.slave));
431 fopc = GNUNET_new(struct ForwardedOperationContext); 438 fopc = GNUNET_new (struct ForwardedOperationContext);
432 fopc->client = focc->client; 439 fopc->client = focc->client;
433 fopc->operation_id = focc->operation_id; 440 fopc->operation_id = focc->operation_id;
434 fopc->cls = rhc; 441 fopc->cls = rhc;
435 fopc->type = OP_OVERLAY_CONNECT; 442 fopc->type = OP_OVERLAY_CONNECT;
436 fopc->opc = 443 fopc->opc =
437 GNUNET_TESTBED_forward_operation_msg_(slave->controller, 444 GNUNET_TESTBED_forward_operation_msg_ (slave->controller,
438 focc->operation_id, 445 focc->operation_id,
439 focc->orig_msg, 446 focc->orig_msg,
440 &forwarded_overlay_connect_listener, 447 &forwarded_overlay_connect_listener,
441 fopc); 448 fopc);
442 GNUNET_free(focc->orig_msg); 449 GNUNET_free (focc->orig_msg);
443 focc->orig_msg = NULL; 450 focc->orig_msg = NULL;
444 fopc->timeout_task = GNUNET_SCHEDULER_add_delayed(GST_timeout, 451 fopc->timeout_task = GNUNET_SCHEDULER_add_delayed (GST_timeout,
445 &forwarded_overlay_connect_timeout, 452 &
446 fopc); 453 forwarded_overlay_connect_timeout,
447 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 454 fopc);
448 fopcq_tail, 455 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
449 fopc); 456 fopcq_tail,
457 fopc);
450} 458}
451 459
452 460
@@ -456,28 +464,28 @@ GST_process_next_focc(struct RegisteredHostContext *rhc)
456 * @param lp2c the local peer2 context information 464 * @param lp2c the local peer2 context information
457 */ 465 */
458static void 466static void
459cleanup_occ_lp2c(struct LocalPeer2Context *lp2c) 467cleanup_occ_lp2c (struct LocalPeer2Context *lp2c)
460{ 468{
461 if (NULL != lp2c->ohh) 469 if (NULL != lp2c->ohh)
462 { 470 {
463 GNUNET_TRANSPORT_offer_hello_cancel(lp2c->ohh); 471 GNUNET_TRANSPORT_offer_hello_cancel (lp2c->ohh);
464 lp2c->ohh = NULL; 472 lp2c->ohh = NULL;
465 } 473 }
466 if (NULL != lp2c->tcc.cgh_p2_th) 474 if (NULL != lp2c->tcc.cgh_p2_th)
467 { 475 {
468 GST_connection_pool_get_handle_done(lp2c->tcc.cgh_p2_th); 476 GST_connection_pool_get_handle_done (lp2c->tcc.cgh_p2_th);
469 lp2c->tcc.cgh_p2_th = NULL; 477 lp2c->tcc.cgh_p2_th = NULL;
470 } 478 }
471 if (NULL != lp2c->tcc.cgh_p2_ats) 479 if (NULL != lp2c->tcc.cgh_p2_ats)
472 { 480 {
473 GST_connection_pool_get_handle_done(lp2c->tcc.cgh_p2_ats); 481 GST_connection_pool_get_handle_done (lp2c->tcc.cgh_p2_ats);
474 lp2c->tcc.cgh_p2_ats = NULL; 482 lp2c->tcc.cgh_p2_ats = NULL;
475 } 483 }
476 if (NULL != lp2c->tcc.csh) 484 if (NULL != lp2c->tcc.csh)
477 { 485 {
478 GNUNET_ATS_connectivity_suggest_cancel(lp2c->tcc.csh); 486 GNUNET_ATS_connectivity_suggest_cancel (lp2c->tcc.csh);
479 lp2c->tcc.csh = NULL; 487 lp2c->tcc.csh = NULL;
480 } 488 }
481} 489}
482 490
483 491
@@ -488,23 +496,23 @@ cleanup_occ_lp2c(struct LocalPeer2Context *lp2c)
488 * @param rp2c the remote peer2 context information 496 * @param rp2c the remote peer2 context information
489 */ 497 */
490static void 498static void
491cleanup_occ_rp2c(struct RemotePeer2Context *rp2c) 499cleanup_occ_rp2c (struct RemotePeer2Context *rp2c)
492{ 500{
493 if (NULL != rp2c->opc) 501 if (NULL != rp2c->opc)
494 { 502 {
495 GNUNET_TESTBED_forward_operation_msg_cancel_(rp2c->opc); 503 GNUNET_TESTBED_forward_operation_msg_cancel_ (rp2c->opc);
496 rp2c->opc = NULL; 504 rp2c->opc = NULL;
497 } 505 }
498 if (NULL != rp2c->ncn) 506 if (NULL != rp2c->ncn)
499 { 507 {
500 GST_neighbour_get_connection_cancel(rp2c->ncn); 508 GST_neighbour_get_connection_cancel (rp2c->ncn);
501 rp2c->ncn = NULL; 509 rp2c->ncn = NULL;
502 } 510 }
503 if ((NULL != rp2c->p2c) && (NULL != rp2c->p2n)) 511 if ((NULL != rp2c->p2c) && (NULL != rp2c->p2n))
504 { 512 {
505 GST_neighbour_release_connection(rp2c->p2n); 513 GST_neighbour_release_connection (rp2c->p2n);
506 rp2c->p2n = NULL; 514 rp2c->p2n = NULL;
507 } 515 }
508} 516}
509 517
510/** 518/**
@@ -521,50 +529,50 @@ cleanup_occ_rp2c(struct RemotePeer2Context *rp2c)
521 * @param occ the overlay connect context 529 * @param occ the overlay connect context
522 */ 530 */
523static void 531static void
524cleanup_occ(struct OverlayConnectContext *occ) 532cleanup_occ (struct OverlayConnectContext *occ)
525{ 533{
526 struct Peer *peer2; 534 struct Peer *peer2;
527 535
528 LOG_DEBUG("0x%llx: Cleaning up occ\n", 536 LOG_DEBUG ("0x%llx: Cleaning up occ\n",
529 occ->op_id); 537 occ->op_id);
530 GNUNET_free_non_null(occ->emsg); 538 GNUNET_free_non_null (occ->emsg);
531 GNUNET_free_non_null(occ->hello); 539 GNUNET_free_non_null (occ->hello);
532 if (NULL != occ->send_hello_task) 540 if (NULL != occ->send_hello_task)
533 GNUNET_SCHEDULER_cancel(occ->send_hello_task); 541 GNUNET_SCHEDULER_cancel (occ->send_hello_task);
534 if (NULL != occ->cleanup_task) 542 if (NULL != occ->cleanup_task)
535 GNUNET_SCHEDULER_cancel(occ->cleanup_task); 543 GNUNET_SCHEDULER_cancel (occ->cleanup_task);
536 if (NULL != occ->timeout_task) 544 if (NULL != occ->timeout_task)
537 GNUNET_SCHEDULER_cancel(occ->timeout_task); 545 GNUNET_SCHEDULER_cancel (occ->timeout_task);
538 if (NULL != occ->cgh_ch) 546 if (NULL != occ->cgh_ch)
539 GST_connection_pool_get_handle_done(occ->cgh_ch); 547 GST_connection_pool_get_handle_done (occ->cgh_ch);
540 if (NULL != occ->ghh) 548 if (NULL != occ->ghh)
541 GNUNET_TRANSPORT_hello_get_cancel(occ->ghh); 549 GNUNET_TRANSPORT_hello_get_cancel (occ->ghh);
542 GST_connection_pool_get_handle_done(occ->cgh_p1th); 550 GST_connection_pool_get_handle_done (occ->cgh_p1th);
543 GNUNET_assert(NULL != GST_peer_list); 551 GNUNET_assert (NULL != GST_peer_list);
544 GNUNET_assert(occ->peer->reference_cnt > 0); 552 GNUNET_assert (occ->peer->reference_cnt > 0);
545 occ->peer->reference_cnt--; 553 occ->peer->reference_cnt--;
546 if (PEER_EXPIRED(occ->peer)) 554 if (PEER_EXPIRED (occ->peer))
547 GST_destroy_peer(occ->peer); 555 GST_destroy_peer (occ->peer);
548 switch (occ->type) 556 switch (occ->type)
549 { 557 {
550 case OCC_TYPE_LOCAL: 558 case OCC_TYPE_LOCAL:
551 peer2 = GST_peer_list[occ->other_peer_id]; 559 peer2 = GST_peer_list[occ->other_peer_id];
552 GNUNET_assert(peer2->reference_cnt > 0); 560 GNUNET_assert (peer2->reference_cnt > 0);
553 peer2->reference_cnt--; 561 peer2->reference_cnt--;
554 if (PEER_EXPIRED(peer2)) 562 if (PEER_EXPIRED (peer2))
555 GST_destroy_peer(peer2); 563 GST_destroy_peer (peer2);
556 cleanup_occ_lp2c(&occ->p2ctx.local); 564 cleanup_occ_lp2c (&occ->p2ctx.local);
557 break; 565 break;
558 566
559 case OCC_TYPE_REMOTE_SLAVE: 567 case OCC_TYPE_REMOTE_SLAVE:
560 case OCC_TYPE_REMOTE_LATERAL: 568 case OCC_TYPE_REMOTE_LATERAL:
561 cleanup_occ_rp2c(&occ->p2ctx.remote); 569 cleanup_occ_rp2c (&occ->p2ctx.remote);
562 break; 570 break;
563 } 571 }
564 GNUNET_CONTAINER_DLL_remove(occq_head, 572 GNUNET_CONTAINER_DLL_remove (occq_head,
565 occq_tail, 573 occq_tail,
566 occ); 574 occ);
567 GNUNET_free(occ); 575 GNUNET_free (occ);
568} 576}
569 577
570 578
@@ -574,12 +582,12 @@ cleanup_occ(struct OverlayConnectContext *occ)
574 * @param cls the overlay connect context 582 * @param cls the overlay connect context
575 */ 583 */
576static void 584static void
577do_cleanup_occ(void *cls) 585do_cleanup_occ (void *cls)
578{ 586{
579 struct OverlayConnectContext *occ = cls; 587 struct OverlayConnectContext *occ = cls;
580 588
581 occ->cleanup_task = NULL; 589 occ->cleanup_task = NULL;
582 cleanup_occ(occ); 590 cleanup_occ (occ);
583} 591}
584 592
585 593
@@ -589,19 +597,19 @@ do_cleanup_occ(void *cls)
589 * @param cls the OverlayConnectContext 597 * @param cls the OverlayConnectContext
590 */ 598 */
591static void 599static void
592timeout_overlay_connect(void *cls) 600timeout_overlay_connect (void *cls)
593{ 601{
594 struct OverlayConnectContext *occ = cls; 602 struct OverlayConnectContext *occ = cls;
595 603
596 GNUNET_assert(NULL != occ->timeout_task); 604 GNUNET_assert (NULL != occ->timeout_task);
597 occ->timeout_task = NULL; 605 occ->timeout_task = NULL;
598 /* LOG (GNUNET_ERROR_TYPE_WARNING, */ 606 /* LOG (GNUNET_ERROR_TYPE_WARNING, */
599 /* "0x%llx: Timeout while connecting peers %u and %u: %s\n", occ->op_id, */ 607 /* "0x%llx: Timeout while connecting peers %u and %u: %s\n", occ->op_id, */
600 /* occ->peer->id, occ->other_peer_id, occ->emsg); */ 608 /* occ->peer->id, occ->other_peer_id, occ->emsg); */
601 GST_send_operation_fail_msg(occ->client, 609 GST_send_operation_fail_msg (occ->client,
602 occ->op_id, 610 occ->op_id,
603 occ->emsg); 611 occ->emsg);
604 cleanup_occ(occ); 612 cleanup_occ (occ);
605} 613}
606 614
607 615
@@ -611,7 +619,7 @@ timeout_overlay_connect(void *cls)
611 * @param client the client that disconnected 619 * @param client the client that disconnected
612 */ 620 */
613void 621void
614GST_notify_client_disconnect_oc(struct GNUNET_SERVICE_Client *client) 622GST_notify_client_disconnect_oc (struct GNUNET_SERVICE_Client *client)
615{ 623{
616 struct ForwardedOperationContext *fopc; 624 struct ForwardedOperationContext *fopc;
617 struct ForwardedOperationContext *fopcn; 625 struct ForwardedOperationContext *fopcn;
@@ -619,20 +627,20 @@ GST_notify_client_disconnect_oc(struct GNUNET_SERVICE_Client *client)
619 struct OverlayConnectContext *occn; 627 struct OverlayConnectContext *occn;
620 628
621 for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) 629 for (fopc = fopcq_head; NULL != fopc; fopc = fopcn)
630 {
631 fopcn = fopc->next;
632 if (fopc->client == client)
622 { 633 {
623 fopcn = fopc->next; 634 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
624 if (fopc->client == client) 635 GST_forwarded_operation_timeout (fopc);
625 {
626 GNUNET_SCHEDULER_cancel(fopc->timeout_task);
627 GST_forwarded_operation_timeout(fopc);
628 }
629 } 636 }
637 }
630 for (occ = occq_head; NULL != occ; occ = occn) 638 for (occ = occq_head; NULL != occ; occ = occn)
631 { 639 {
632 occn = occ->next; 640 occn = occ->next;
633 if (occ->client == client) 641 if (occ->client == client)
634 cleanup_occ(occ); 642 cleanup_occ (occ);
635 } 643 }
636 // FIXME: implement clean up for client_keep replacements! 644 // FIXME: implement clean up for client_keep replacements!
637} 645}
638 646
@@ -643,21 +651,21 @@ GST_notify_client_disconnect_oc(struct GNUNET_SERVICE_Client *client)
643 * FIXME. 651 * FIXME.
644 */ 652 */
645static void 653static void
646send_overlay_connect_success_msg(struct OverlayConnectContext *occ) 654send_overlay_connect_success_msg (struct OverlayConnectContext *occ)
647{ 655{
648 struct GNUNET_MQ_Envelope *env; 656 struct GNUNET_MQ_Envelope *env;
649 struct GNUNET_TESTBED_ConnectionEventMessage *msg; 657 struct GNUNET_TESTBED_ConnectionEventMessage *msg;
650 658
651 LOG_DEBUG("0x%llx: Peers connected - Sending overlay connect success\n", 659 LOG_DEBUG ("0x%llx: Peers connected - Sending overlay connect success\n",
652 occ->op_id); 660 occ->op_id);
653 env = GNUNET_MQ_msg(msg, 661 env = GNUNET_MQ_msg (msg,
654 GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT); 662 GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT);
655 msg->event_type = htonl(GNUNET_TESTBED_ET_CONNECT); 663 msg->event_type = htonl (GNUNET_TESTBED_ET_CONNECT);
656 msg->peer1 = htonl(occ->peer->id); 664 msg->peer1 = htonl (occ->peer->id);
657 msg->peer2 = htonl(occ->other_peer_id); 665 msg->peer2 = htonl (occ->other_peer_id);
658 msg->operation_id = GNUNET_htonll(occ->op_id); 666 msg->operation_id = GNUNET_htonll (occ->op_id);
659 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(occ->client), 667 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (occ->client),
660 env); 668 env);
661} 669}
662 670
663 671
@@ -669,62 +677,62 @@ send_overlay_connect_success_msg(struct OverlayConnectContext *occ)
669 * @param new_peer the peer that connected 677 * @param new_peer the peer that connected
670 */ 678 */
671static void 679static void
672overlay_connect_notify(void *cls, 680overlay_connect_notify (void *cls,
673 const struct GNUNET_PeerIdentity *new_peer) 681 const struct GNUNET_PeerIdentity *new_peer)
674{ 682{
675 struct OverlayConnectContext *occ = cls; 683 struct OverlayConnectContext *occ = cls;
676 char *new_peer_str; 684 char *new_peer_str;
677 char *other_peer_str; 685 char *other_peer_str;
678 686
679 LOG_DEBUG("Overlay connect notify\n"); 687 LOG_DEBUG ("Overlay connect notify\n");
680 if (0 == 688 if (0 ==
681 memcmp(new_peer, &occ->peer_identity, 689 memcmp (new_peer, &occ->peer_identity,
682 sizeof(struct GNUNET_PeerIdentity))) 690 sizeof(struct GNUNET_PeerIdentity)))
683 return; 691 return;
684 new_peer_str = GNUNET_strdup(GNUNET_i2s(new_peer)); 692 new_peer_str = GNUNET_strdup (GNUNET_i2s (new_peer));
685 other_peer_str = GNUNET_strdup(GNUNET_i2s(&occ->other_peer_identity)); 693 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity));
686 if (0 != 694 if (0 !=
687 memcmp(new_peer, 695 memcmp (new_peer,
688 &occ->other_peer_identity, 696 &occ->other_peer_identity,
689 sizeof(struct GNUNET_PeerIdentity))) 697 sizeof(struct GNUNET_PeerIdentity)))
690 { 698 {
691 LOG_DEBUG("Unexpected peer %s connected when expecting peer %s\n", 699 LOG_DEBUG ("Unexpected peer %s connected when expecting peer %s\n",
692 new_peer_str, 700 new_peer_str,
693 other_peer_str); 701 other_peer_str);
694 GNUNET_free(new_peer_str); 702 GNUNET_free (new_peer_str);
695 GNUNET_free(other_peer_str); 703 GNUNET_free (other_peer_str);
696 return; 704 return;
697 } 705 }
698 GNUNET_free(new_peer_str); 706 GNUNET_free (new_peer_str);
699 LOG_DEBUG("0x%llx: Peer %s connected to peer %s\n", 707 LOG_DEBUG ("0x%llx: Peer %s connected to peer %s\n",
700 occ->op_id, 708 occ->op_id,
701 other_peer_str, 709 other_peer_str,
702 GNUNET_i2s(&occ->peer_identity)); 710 GNUNET_i2s (&occ->peer_identity));
703 GNUNET_free(other_peer_str); 711 GNUNET_free (other_peer_str);
704 if (NULL != occ->send_hello_task) 712 if (NULL != occ->send_hello_task)
705 { 713 {
706 GNUNET_SCHEDULER_cancel(occ->send_hello_task); 714 GNUNET_SCHEDULER_cancel (occ->send_hello_task);
707 occ->send_hello_task = NULL; 715 occ->send_hello_task = NULL;
708 } 716 }
709 GNUNET_assert(NULL != occ->timeout_task); 717 GNUNET_assert (NULL != occ->timeout_task);
710 GNUNET_SCHEDULER_cancel(occ->timeout_task); 718 GNUNET_SCHEDULER_cancel (occ->timeout_task);
711 occ->timeout_task = NULL; 719 occ->timeout_task = NULL;
712 switch (occ->type) 720 switch (occ->type)
713 { 721 {
714 case OCC_TYPE_LOCAL: 722 case OCC_TYPE_LOCAL:
715 cleanup_occ_lp2c(&occ->p2ctx.local); 723 cleanup_occ_lp2c (&occ->p2ctx.local);
716 break; 724 break;
717 725
718 case OCC_TYPE_REMOTE_SLAVE: 726 case OCC_TYPE_REMOTE_SLAVE:
719 case OCC_TYPE_REMOTE_LATERAL: 727 case OCC_TYPE_REMOTE_LATERAL:
720 cleanup_occ_rp2c(&occ->p2ctx.remote); 728 cleanup_occ_rp2c (&occ->p2ctx.remote);
721 break; 729 break;
722 } 730 }
723 GNUNET_free_non_null(occ->emsg); 731 GNUNET_free_non_null (occ->emsg);
724 occ->emsg = NULL; 732 occ->emsg = NULL;
725 send_overlay_connect_success_msg(occ); 733 send_overlay_connect_success_msg (occ);
726 occ->cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup_occ, 734 occ->cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup_occ,
727 occ); 735 occ);
728} 736}
729 737
730 738
@@ -739,43 +747,43 @@ overlay_connect_notify(void *cls,
739 * @param cfg configuration of the peer 747 * @param cfg configuration of the peer
740 */ 748 */
741static void 749static void
742occ_cache_get_handle_ats_occ_cb(void *cls, 750occ_cache_get_handle_ats_occ_cb (void *cls,
743 struct GNUNET_CORE_Handle *ch, 751 struct GNUNET_CORE_Handle *ch,
744 struct GNUNET_TRANSPORT_CoreHandle *th, 752 struct GNUNET_TRANSPORT_CoreHandle *th,
745 struct GNUNET_ATS_ConnectivityHandle *ac, 753 struct GNUNET_ATS_ConnectivityHandle *ac,
746 const struct GNUNET_PeerIdentity *my_identity, 754 const struct GNUNET_PeerIdentity *my_identity,
747 const struct GNUNET_CONFIGURATION_Handle *cfg) 755 const struct GNUNET_CONFIGURATION_Handle *cfg)
748{ 756{
749 struct OverlayConnectContext *occ = cls; 757 struct OverlayConnectContext *occ = cls;
750 struct LocalPeer2Context *lp2c; 758 struct LocalPeer2Context *lp2c;
751 759
752 GNUNET_assert(OCC_TYPE_LOCAL == occ->type); 760 GNUNET_assert (OCC_TYPE_LOCAL == occ->type);
753 GNUNET_assert(NULL != occ->timeout_task); 761 GNUNET_assert (NULL != occ->timeout_task);
754 GNUNET_free_non_null(occ->emsg); 762 GNUNET_free_non_null (occ->emsg);
755 if (NULL == ac) 763 if (NULL == ac)
756 { 764 {
757 GNUNET_asprintf(&occ->emsg, 765 GNUNET_asprintf (&occ->emsg,
758 "0x%llx: Failed to connect to ATS of peer with id: %u", 766 "0x%llx: Failed to connect to ATS of peer with id: %u",
759 occ->op_id, 767 occ->op_id,
760 occ->peer->id); 768 occ->peer->id);
761 GNUNET_SCHEDULER_cancel(occ->timeout_task); 769 GNUNET_SCHEDULER_cancel (occ->timeout_task);
762 occ->timeout_task = 770 occ->timeout_task =
763 GNUNET_SCHEDULER_add_now(&timeout_overlay_connect, 771 GNUNET_SCHEDULER_add_now (&timeout_overlay_connect,
764 occ); 772 occ);
765 return; 773 return;
766 } 774 }
767 occ->emsg = NULL; 775 occ->emsg = NULL;
768 776
769 GNUNET_asprintf(&occ->emsg, 777 GNUNET_asprintf (&occ->emsg,
770 "0x%llx: Timeout during GNUNET_ATS_connectivity_suggest() at peer %s", 778 "0x%llx: Timeout during GNUNET_ATS_connectivity_suggest() at peer %s",
771 occ->op_id, 779 occ->op_id,
772 GNUNET_i2s(&occ->other_peer_identity)); 780 GNUNET_i2s (&occ->other_peer_identity));
773 781
774 lp2c = &occ->p2ctx.local; 782 lp2c = &occ->p2ctx.local;
775 lp2c->tcc.csh = 783 lp2c->tcc.csh =
776 GNUNET_ATS_connectivity_suggest(ac, 784 GNUNET_ATS_connectivity_suggest (ac,
777 &occ->peer_identity, 785 &occ->peer_identity,
778 1); 786 1);
779} 787}
780 788
781 789
@@ -789,19 +797,19 @@ occ_cache_get_handle_ats_occ_cb(void *cls,
789 * @param my_identity the identity of our peer 797 * @param my_identity the identity of our peer
790 */ 798 */
791static void 799static void
792occ_cache_get_handle_ats_rocc_cb(void *cls, 800occ_cache_get_handle_ats_rocc_cb (void *cls,
793 struct GNUNET_CORE_Handle *ch, 801 struct GNUNET_CORE_Handle *ch,
794 struct GNUNET_TRANSPORT_CoreHandle *th, 802 struct GNUNET_TRANSPORT_CoreHandle *th,
795 struct GNUNET_ATS_ConnectivityHandle *ac, 803 struct GNUNET_ATS_ConnectivityHandle *ac,
796 const struct GNUNET_PeerIdentity *my_identity, 804 const struct GNUNET_PeerIdentity *my_identity,
797 const struct GNUNET_CONFIGURATION_Handle *cfg) 805 const struct GNUNET_CONFIGURATION_Handle *cfg)
798{ 806{
799 struct RemoteOverlayConnectCtx *rocc = cls; 807 struct RemoteOverlayConnectCtx *rocc = cls;
800 808
801 rocc->tcc.csh = 809 rocc->tcc.csh =
802 GNUNET_ATS_connectivity_suggest(ac, 810 GNUNET_ATS_connectivity_suggest (ac,
803 &rocc->a_id, 811 &rocc->a_id,
804 1); 812 1);
805} 813}
806 814
807 815
@@ -812,7 +820,7 @@ occ_cache_get_handle_ats_rocc_cb(void *cls,
812 * @param cls the OverlayConnectContext 820 * @param cls the OverlayConnectContext
813 */ 821 */
814static void 822static void
815send_hello(void *cls); 823send_hello (void *cls);
816 824
817 825
818/** 826/**
@@ -823,31 +831,31 @@ send_hello(void *cls);
823 * @param cls the overlay connect context 831 * @param cls the overlay connect context
824 */ 832 */
825static void 833static void
826occ_hello_sent_cb(void *cls) 834occ_hello_sent_cb (void *cls)
827{ 835{
828 struct OverlayConnectContext *occ = cls; 836 struct OverlayConnectContext *occ = cls;
829 struct LocalPeer2Context *lp2c; 837 struct LocalPeer2Context *lp2c;
830 struct Peer *peer2; 838 struct Peer *peer2;
831 839
832 GNUNET_assert(OCC_TYPE_LOCAL == occ->type); 840 GNUNET_assert (OCC_TYPE_LOCAL == occ->type);
833 GNUNET_assert(NULL != occ->timeout_task); 841 GNUNET_assert (NULL != occ->timeout_task);
834 lp2c = &occ->p2ctx.local; 842 lp2c = &occ->p2ctx.local;
835 lp2c->ohh = NULL; 843 lp2c->ohh = NULL;
836 844
837 GNUNET_assert(NULL == occ->send_hello_task); 845 GNUNET_assert (NULL == occ->send_hello_task);
838 GNUNET_free_non_null(occ->emsg); 846 GNUNET_free_non_null (occ->emsg);
839 847
840 GNUNET_asprintf(&occ->emsg, 848 GNUNET_asprintf (&occ->emsg,
841 "0x%llx: Timeout while acquiring ATS of %s from cache", 849 "0x%llx: Timeout while acquiring ATS of %s from cache",
842 occ->op_id, 850 occ->op_id,
843 GNUNET_i2s(&occ->other_peer_identity)); 851 GNUNET_i2s (&occ->other_peer_identity));
844 GNUNET_assert(NULL != (peer2 = GST_peer_list[occ->other_peer_id])); 852 GNUNET_assert (NULL != (peer2 = GST_peer_list[occ->other_peer_id]));
845 lp2c->tcc.cgh_p2_ats = 853 lp2c->tcc.cgh_p2_ats =
846 GST_connection_pool_get_handle(occ->other_peer_id, 854 GST_connection_pool_get_handle (occ->other_peer_id,
847 peer2->details.local.cfg, 855 peer2->details.local.cfg,
848 GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY, 856 GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY,
849 &occ_cache_get_handle_ats_occ_cb, 857 &occ_cache_get_handle_ats_occ_cb,
850 occ, NULL, NULL, NULL); 858 occ, NULL, NULL, NULL);
851} 859}
852 860
853 861
@@ -859,36 +867,38 @@ occ_hello_sent_cb(void *cls)
859 * #OCC_TYPE_REMOTE_SLAVE or #OCC_TYPE_REMOTE_LATERAL 867 * #OCC_TYPE_REMOTE_SLAVE or #OCC_TYPE_REMOTE_LATERAL
860 */ 868 */
861static void 869static void
862send_hello_thru_rocc(struct OverlayConnectContext *occ) 870send_hello_thru_rocc (struct OverlayConnectContext *occ)
863{ 871{
864 struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg; 872 struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg;
865 char *other_peer_str; 873 char *other_peer_str;
866 uint16_t msize; 874 uint16_t msize;
867 uint16_t hello_size; 875 uint16_t hello_size;
868 876
869 GNUNET_assert(OCC_TYPE_LOCAL != occ->type); 877 GNUNET_assert (OCC_TYPE_LOCAL != occ->type);
870 GNUNET_assert(NULL != occ->hello); 878 GNUNET_assert (NULL != occ->hello);
871 other_peer_str = GNUNET_strdup(GNUNET_i2s(&occ->other_peer_identity)); 879 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity));
872 LOG_DEBUG("0x%llx: Offering HELLO of %s (size: %u) to %s via Remote Overlay Request\n", 880 LOG_DEBUG (
873 occ->op_id, 881 "0x%llx: Offering HELLO of %s (size: %u) to %s via Remote Overlay Request\n",
874 GNUNET_i2s(&occ->peer_identity), 882 occ->op_id,
875 ntohs(occ->hello->size), 883 GNUNET_i2s (&occ->peer_identity),
876 other_peer_str); 884 ntohs (occ->hello->size),
877 GNUNET_free(other_peer_str); 885 other_peer_str);
878 hello_size = ntohs(occ->hello->size); 886 GNUNET_free (other_peer_str);
879 msize = sizeof(struct GNUNET_TESTBED_RemoteOverlayConnectMessage) + hello_size; 887 hello_size = ntohs (occ->hello->size);
880 msg = GNUNET_malloc(msize); 888 msize = sizeof(struct GNUNET_TESTBED_RemoteOverlayConnectMessage)
889 + hello_size;
890 msg = GNUNET_malloc (msize);
881 msg->header.type = 891 msg->header.type =
882 htons(GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT); 892 htons (GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT);
883 msg->header.size = htons(msize); 893 msg->header.size = htons (msize);
884 msg->peer = htonl(occ->other_peer_id); 894 msg->peer = htonl (occ->other_peer_id);
885 msg->operation_id = GNUNET_htonll(occ->op_id); 895 msg->operation_id = GNUNET_htonll (occ->op_id);
886 msg->peer_identity = occ->peer_identity; 896 msg->peer_identity = occ->peer_identity;
887 GNUNET_memcpy(msg->hello, 897 GNUNET_memcpy (msg->hello,
888 occ->hello, 898 occ->hello,
889 hello_size); 899 hello_size);
890 GNUNET_TESTBED_queue_message_(occ->p2ctx.remote.p2c, 900 GNUNET_TESTBED_queue_message_ (occ->p2ctx.remote.p2c,
891 &msg->header); 901 &msg->header);
892} 902}
893 903
894 904
@@ -900,43 +910,43 @@ send_hello_thru_rocc(struct OverlayConnectContext *occ)
900 * @param cls the OverlayConnectContext 910 * @param cls the OverlayConnectContext
901 */ 911 */
902static void 912static void
903send_hello(void *cls) 913send_hello (void *cls)
904{ 914{
905 struct OverlayConnectContext *occ = cls; 915 struct OverlayConnectContext *occ = cls;
906 struct LocalPeer2Context *lp2c; 916 struct LocalPeer2Context *lp2c;
907 char *other_peer_str; 917 char *other_peer_str;
908 918
909 occ->send_hello_task = NULL; 919 occ->send_hello_task = NULL;
910 GNUNET_assert(NULL != occ->timeout_task); 920 GNUNET_assert (NULL != occ->timeout_task);
911 GNUNET_assert(NULL != occ->hello); 921 GNUNET_assert (NULL != occ->hello);
912 if (OCC_TYPE_LOCAL != occ->type) 922 if (OCC_TYPE_LOCAL != occ->type)
913 { 923 {
914 send_hello_thru_rocc(occ); 924 send_hello_thru_rocc (occ);
915 return; 925 return;
916 } 926 }
917 lp2c = &occ->p2ctx.local; 927 lp2c = &occ->p2ctx.local;
918 other_peer_str = GNUNET_strdup(GNUNET_i2s(&occ->other_peer_identity)); 928 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity));
919 LOG_DEBUG("0x%llx: Offering HELLO of %s to %s\n", 929 LOG_DEBUG ("0x%llx: Offering HELLO of %s to %s\n",
920 occ->op_id, 930 occ->op_id,
921 GNUNET_i2s(&occ->peer_identity), 931 GNUNET_i2s (&occ->peer_identity),
922 other_peer_str); 932 other_peer_str);
923 GNUNET_free(other_peer_str); 933 GNUNET_free (other_peer_str);
924 lp2c->ohh = 934 lp2c->ohh =
925 GNUNET_TRANSPORT_offer_hello(lp2c->tcc.cfg, 935 GNUNET_TRANSPORT_offer_hello (lp2c->tcc.cfg,
926 occ->hello, 936 occ->hello,
927 &occ_hello_sent_cb, 937 &occ_hello_sent_cb,
928 occ); 938 occ);
929 if (NULL == lp2c->ohh) 939 if (NULL == lp2c->ohh)
930 { 940 {
931 GNUNET_break(0); 941 GNUNET_break (0);
932 occ->send_hello_task = 942 occ->send_hello_task =
933 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 943 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
934 (GNUNET_TIME_UNIT_MILLISECONDS, 944 (GNUNET_TIME_UNIT_MILLISECONDS,
935 100 + 945 100
936 GNUNET_CRYPTO_random_u32 946 + GNUNET_CRYPTO_random_u32
937 (GNUNET_CRYPTO_QUALITY_WEAK, 500)), 947 (GNUNET_CRYPTO_QUALITY_WEAK, 500)),
938 &send_hello, occ); 948 &send_hello, occ);
939 } 949 }
940} 950}
941 951
942 952
@@ -951,34 +961,35 @@ send_hello(void *cls)
951 * @param cfg configuration of the peer 961 * @param cfg configuration of the peer
952 */ 962 */
953static void 963static void
954p2_transport_connect_cache_callback(void *cls, 964p2_transport_connect_cache_callback (void *cls,
955 struct GNUNET_CORE_Handle *ch, 965 struct GNUNET_CORE_Handle *ch,
956 struct GNUNET_TRANSPORT_CoreHandle *th, 966 struct GNUNET_TRANSPORT_CoreHandle *th,
957 struct GNUNET_ATS_ConnectivityHandle *ac, 967 struct GNUNET_ATS_ConnectivityHandle *ac,
958 const struct GNUNET_PeerIdentity *ignore_, 968 const struct GNUNET_PeerIdentity *ignore_,
959 const struct GNUNET_CONFIGURATION_Handle *cfg) 969 const struct
970 GNUNET_CONFIGURATION_Handle *cfg)
960{ 971{
961 struct OverlayConnectContext *occ = cls; 972 struct OverlayConnectContext *occ = cls;
962 973
963 GNUNET_assert(OCC_TYPE_LOCAL == occ->type); 974 GNUNET_assert (OCC_TYPE_LOCAL == occ->type);
964 if (NULL == th) 975 if (NULL == th)
965 { 976 {
966 GNUNET_asprintf(&occ->emsg, 977 GNUNET_asprintf (&occ->emsg,
967 "0x%llx: Cannot connect to TRANSPORT of %s", 978 "0x%llx: Cannot connect to TRANSPORT of %s",
968 occ->op_id, 979 occ->op_id,
969 GNUNET_i2s(&occ->other_peer_identity)); 980 GNUNET_i2s (&occ->other_peer_identity));
970 GNUNET_SCHEDULER_cancel(occ->timeout_task); 981 GNUNET_SCHEDULER_cancel (occ->timeout_task);
971 occ->timeout_task = 982 occ->timeout_task =
972 GNUNET_SCHEDULER_add_now(&timeout_overlay_connect, occ); 983 GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
973 return; 984 return;
974 } 985 }
975 occ->p2ctx.local.tcc.th_ = th; 986 occ->p2ctx.local.tcc.th_ = th;
976 occ->p2ctx.local.tcc.cfg = cfg; 987 occ->p2ctx.local.tcc.cfg = cfg;
977 GNUNET_asprintf(&occ->emsg, 988 GNUNET_asprintf (&occ->emsg,
978 "0x%llx: Timeout while offering HELLO to %s", 989 "0x%llx: Timeout while offering HELLO to %s",
979 occ->op_id, 990 occ->op_id,
980 GNUNET_i2s(&occ->other_peer_identity)); 991 GNUNET_i2s (&occ->other_peer_identity));
981 occ->send_hello_task = GNUNET_SCHEDULER_add_now(&send_hello, occ); 992 occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ);
982} 993}
983 994
984 995
@@ -989,36 +1000,36 @@ p2_transport_connect_cache_callback(void *cls,
989 * @param occ the overlay connect context 1000 * @param occ the overlay connect context
990 */ 1001 */
991static void 1002static void
992p2_transport_connect(struct OverlayConnectContext *occ) 1003p2_transport_connect (struct OverlayConnectContext *occ)
993{ 1004{
994 struct Peer *peer2; 1005 struct Peer *peer2;
995 1006
996 /* HUH? Why to *obtain* HELLO? Seems we use this to *SEND* the 1007 /* HUH? Why to *obtain* HELLO? Seems we use this to *SEND* the
997 HELLO! */ 1008 HELLO! */
998 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1009 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
999 "Connecting to transport of peer %s to obtain HELLO\n", 1010 "Connecting to transport of peer %s to obtain HELLO\n",
1000 GNUNET_i2s(&occ->other_peer_identity)); 1011 GNUNET_i2s (&occ->other_peer_identity));
1001 GNUNET_assert(NULL == occ->emsg); 1012 GNUNET_assert (NULL == occ->emsg);
1002 GNUNET_assert(NULL != occ->hello); 1013 GNUNET_assert (NULL != occ->hello);
1003 GNUNET_assert(NULL == occ->ghh); 1014 GNUNET_assert (NULL == occ->ghh);
1004 GNUNET_assert(NULL == occ->p1th_); 1015 GNUNET_assert (NULL == occ->p1th_);
1005 GNUNET_assert(NULL == occ->cgh_p1th); 1016 GNUNET_assert (NULL == occ->cgh_p1th);
1006 if (OCC_TYPE_LOCAL == occ->type) 1017 if (OCC_TYPE_LOCAL == occ->type)
1007 { 1018 {
1008 GNUNET_assert(NULL != (peer2 = GST_peer_list[occ->other_peer_id])); 1019 GNUNET_assert (NULL != (peer2 = GST_peer_list[occ->other_peer_id]));
1009 occ->p2ctx.local.tcc.cgh_p2_th = 1020 occ->p2ctx.local.tcc.cgh_p2_th =
1010 GST_connection_pool_get_handle(occ->other_peer_id, 1021 GST_connection_pool_get_handle (occ->other_peer_id,
1011 peer2->details.local.cfg, 1022 peer2->details.local.cfg,
1012 GST_CONNECTIONPOOL_SERVICE_TRANSPORT, 1023 GST_CONNECTIONPOOL_SERVICE_TRANSPORT,
1013 &p2_transport_connect_cache_callback, 1024 &p2_transport_connect_cache_callback,
1014 occ, NULL, NULL, NULL); 1025 occ, NULL, NULL, NULL);
1015 return; 1026 return;
1016 } 1027 }
1017 GNUNET_asprintf(&occ->emsg, 1028 GNUNET_asprintf (&occ->emsg,
1018 "0x%llx: Timeout while offering HELLO to %s", 1029 "0x%llx: Timeout while offering HELLO to %s",
1019 occ->op_id, 1030 occ->op_id,
1020 GNUNET_i2s(&occ->other_peer_identity)); 1031 GNUNET_i2s (&occ->other_peer_identity));
1021 occ->send_hello_task = GNUNET_SCHEDULER_add_now(&send_hello, occ); 1032 occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ);
1022} 1033}
1023 1034
1024 1035
@@ -1031,9 +1042,9 @@ p2_transport_connect(struct OverlayConnectContext *occ)
1031 * @return #GNUNET_OK 1042 * @return #GNUNET_OK
1032 */ 1043 */
1033static int 1044static int
1034test_address(void *cls, 1045test_address (void *cls,
1035 const struct GNUNET_HELLO_Address *address, 1046 const struct GNUNET_HELLO_Address *address,
1036 struct GNUNET_TIME_Absolute expiration) 1047 struct GNUNET_TIME_Absolute expiration)
1037{ 1048{
1038 int *empty = cls; 1049 int *empty = cls;
1039 1050
@@ -1051,40 +1062,40 @@ test_address(void *cls,
1051 * @param hello our updated HELLO 1062 * @param hello our updated HELLO
1052 */ 1063 */
1053static void 1064static void
1054hello_update_cb(void *cls, 1065hello_update_cb (void *cls,
1055 const struct GNUNET_MessageHeader *hello) 1066 const struct GNUNET_MessageHeader *hello)
1056{ 1067{
1057 struct OverlayConnectContext *occ = cls; 1068 struct OverlayConnectContext *occ = cls;
1058 int empty; 1069 int empty;
1059 uint16_t msize; 1070 uint16_t msize;
1060 1071
1061 msize = ntohs(hello->size); 1072 msize = ntohs (hello->size);
1062 empty = GNUNET_YES; 1073 empty = GNUNET_YES;
1063 (void)GNUNET_HELLO_iterate_addresses((const struct GNUNET_HELLO_Message *) 1074 (void) GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message *)
1064 hello, GNUNET_NO, 1075 hello, GNUNET_NO,
1065 &test_address, 1076 &test_address,
1066 &empty); 1077 &empty);
1067 if (GNUNET_YES == empty) 1078 if (GNUNET_YES == empty)
1068 { 1079 {
1069 LOG_DEBUG("0x%llx: HELLO of %s is empty\n", 1080 LOG_DEBUG ("0x%llx: HELLO of %s is empty\n",
1070 occ->op_id, 1081 occ->op_id,
1071 GNUNET_i2s(&occ->peer_identity)); 1082 GNUNET_i2s (&occ->peer_identity));
1072 return; 1083 return;
1073 } 1084 }
1074 LOG_DEBUG("0x%llx: Received HELLO of %s\n", 1085 LOG_DEBUG ("0x%llx: Received HELLO of %s\n",
1075 occ->op_id, 1086 occ->op_id,
1076 GNUNET_i2s(&occ->peer_identity)); 1087 GNUNET_i2s (&occ->peer_identity));
1077 occ->hello = GNUNET_malloc(msize); 1088 occ->hello = GNUNET_malloc (msize);
1078 GST_cache_add_hello(occ->peer->id, hello); 1089 GST_cache_add_hello (occ->peer->id, hello);
1079 GNUNET_memcpy(occ->hello, hello, msize); 1090 GNUNET_memcpy (occ->hello, hello, msize);
1080 GNUNET_TRANSPORT_hello_get_cancel(occ->ghh); 1091 GNUNET_TRANSPORT_hello_get_cancel (occ->ghh);
1081 occ->ghh = NULL; 1092 occ->ghh = NULL;
1082 GST_connection_pool_get_handle_done(occ->cgh_p1th); 1093 GST_connection_pool_get_handle_done (occ->cgh_p1th);
1083 occ->cgh_p1th = NULL; 1094 occ->cgh_p1th = NULL;
1084 occ->p1th_ = NULL; 1095 occ->p1th_ = NULL;
1085 GNUNET_free_non_null(occ->emsg); 1096 GNUNET_free_non_null (occ->emsg);
1086 occ->emsg = NULL; 1097 occ->emsg = NULL;
1087 p2_transport_connect(occ); 1098 p2_transport_connect (occ);
1088} 1099}
1089 1100
1090 1101
@@ -1098,39 +1109,40 @@ hello_update_cb(void *cls,
1098 * @param ignore_ peer identity which is ignored in this callback 1109 * @param ignore_ peer identity which is ignored in this callback
1099 */ 1110 */
1100static void 1111static void
1101p1_transport_connect_cache_callback(void *cls, 1112p1_transport_connect_cache_callback (void *cls,
1102 struct GNUNET_CORE_Handle *ch, 1113 struct GNUNET_CORE_Handle *ch,
1103 struct GNUNET_TRANSPORT_CoreHandle *th, 1114 struct GNUNET_TRANSPORT_CoreHandle *th,
1104 struct GNUNET_ATS_ConnectivityHandle *ac, 1115 struct GNUNET_ATS_ConnectivityHandle *ac,
1105 const struct GNUNET_PeerIdentity *ignore_, 1116 const struct GNUNET_PeerIdentity *ignore_,
1106 const struct GNUNET_CONFIGURATION_Handle *cfg) 1117 const struct
1118 GNUNET_CONFIGURATION_Handle *cfg)
1107{ 1119{
1108 struct OverlayConnectContext *occ = cls; 1120 struct OverlayConnectContext *occ = cls;
1109 1121
1110 GNUNET_free_non_null(occ->emsg); 1122 GNUNET_free_non_null (occ->emsg);
1111 occ->emsg = NULL; 1123 occ->emsg = NULL;
1112 if (NULL == th) 1124 if (NULL == th)
1113 { 1125 {
1114 GNUNET_asprintf(&occ->emsg, 1126 GNUNET_asprintf (&occ->emsg,
1115 "0x%llx: Cannot connect to TRANSPORT of %s", 1127 "0x%llx: Cannot connect to TRANSPORT of %s",
1116 occ->op_id, 1128 occ->op_id,
1117 GNUNET_i2s(&occ->peer_identity)); 1129 GNUNET_i2s (&occ->peer_identity));
1118 GNUNET_SCHEDULER_cancel(occ->timeout_task); 1130 GNUNET_SCHEDULER_cancel (occ->timeout_task);
1119 occ->timeout_task = 1131 occ->timeout_task =
1120 GNUNET_SCHEDULER_add_now(&timeout_overlay_connect, occ); 1132 GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
1121 return; 1133 return;
1122 } 1134 }
1123 GNUNET_assert(NULL == occ->p1th_); 1135 GNUNET_assert (NULL == occ->p1th_);
1124 GNUNET_assert(NULL != occ->cgh_p1th); 1136 GNUNET_assert (NULL != occ->cgh_p1th);
1125 occ->p1th_ = th; 1137 occ->p1th_ = th;
1126 GNUNET_asprintf(&occ->emsg, 1138 GNUNET_asprintf (&occ->emsg,
1127 "0x%llx: Timeout while acquiring HELLO of peer %s", 1139 "0x%llx: Timeout while acquiring HELLO of peer %s",
1128 occ->op_id, 1140 occ->op_id,
1129 GNUNET_i2s(&occ->peer_identity)); 1141 GNUNET_i2s (&occ->peer_identity));
1130 occ->ghh = GNUNET_TRANSPORT_hello_get(cfg, 1142 occ->ghh = GNUNET_TRANSPORT_hello_get (cfg,
1131 GNUNET_TRANSPORT_AC_ANY, 1143 GNUNET_TRANSPORT_AC_ANY,
1132 &hello_update_cb, 1144 &hello_update_cb,
1133 occ); 1145 occ);
1134} 1146}
1135 1147
1136 1148
@@ -1144,68 +1156,68 @@ p1_transport_connect_cache_callback(void *cls,
1144 * @param my_identity the identity of our peer 1156 * @param my_identity the identity of our peer
1145 */ 1157 */
1146static void 1158static void
1147occ_cache_get_handle_core_cb(void *cls, 1159occ_cache_get_handle_core_cb (void *cls,
1148 struct GNUNET_CORE_Handle *ch, 1160 struct GNUNET_CORE_Handle *ch,
1149 struct GNUNET_TRANSPORT_CoreHandle *th, 1161 struct GNUNET_TRANSPORT_CoreHandle *th,
1150 struct GNUNET_ATS_ConnectivityHandle *ac, 1162 struct GNUNET_ATS_ConnectivityHandle *ac,
1151 const struct GNUNET_PeerIdentity *my_identity, 1163 const struct GNUNET_PeerIdentity *my_identity,
1152 const struct GNUNET_CONFIGURATION_Handle *cfg) 1164 const struct GNUNET_CONFIGURATION_Handle *cfg)
1153{ 1165{
1154 struct OverlayConnectContext *occ = cls; 1166 struct OverlayConnectContext *occ = cls;
1155 const struct GNUNET_MessageHeader *hello; 1167 const struct GNUNET_MessageHeader *hello;
1156 1168
1157 GNUNET_assert(NULL != occ->timeout_task); 1169 GNUNET_assert (NULL != occ->timeout_task);
1158 GNUNET_free_non_null(occ->emsg); 1170 GNUNET_free_non_null (occ->emsg);
1159 if ((NULL == ch) || (NULL == my_identity)) 1171 if ((NULL == ch) || (NULL == my_identity))
1160 { 1172 {
1161 GNUNET_asprintf(&occ->emsg, 1173 GNUNET_asprintf (&occ->emsg,
1162 "0x%llx: Failed to connect to CORE of peer with " 1174 "0x%llx: Failed to connect to CORE of peer with "
1163 "id: %u", 1175 "id: %u",
1164 occ->op_id, 1176 occ->op_id,
1165 occ->peer->id); 1177 occ->peer->id);
1166 GNUNET_SCHEDULER_cancel(occ->timeout_task); 1178 GNUNET_SCHEDULER_cancel (occ->timeout_task);
1167 occ->timeout_task = 1179 occ->timeout_task =
1168 GNUNET_SCHEDULER_add_now(&timeout_overlay_connect, occ); 1180 GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
1169 return; 1181 return;
1170 } 1182 }
1171 occ->emsg = NULL; 1183 occ->emsg = NULL;
1172 if (NULL != 1184 if (NULL !=
1173 GNUNET_CORE_get_mq(ch, 1185 GNUNET_CORE_get_mq (ch,
1174 &occ->other_peer_identity)) 1186 &occ->other_peer_identity))
1175 { 1187 {
1176 LOG_DEBUG("0x%llx: Target peer already connected\n", 1188 LOG_DEBUG ("0x%llx: Target peer already connected\n",
1177 occ->op_id); 1189 occ->op_id);
1178 GNUNET_SCHEDULER_cancel(occ->timeout_task); 1190 GNUNET_SCHEDULER_cancel (occ->timeout_task);
1179 occ->timeout_task = NULL; 1191 occ->timeout_task = NULL;
1180 send_overlay_connect_success_msg(occ); 1192 send_overlay_connect_success_msg (occ);
1181 occ->cleanup_task = GNUNET_SCHEDULER_add_now(&do_cleanup_occ, occ); 1193 occ->cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup_occ, occ);
1182 return; 1194 return;
1183 } 1195 }
1184 occ->peer_identity = *my_identity; 1196 occ->peer_identity = *my_identity;
1185 LOG_DEBUG("0x%llx: Acquiring HELLO of peer %s\n", 1197 LOG_DEBUG ("0x%llx: Acquiring HELLO of peer %s\n",
1186 occ->op_id, 1198 occ->op_id,
1187 GNUNET_i2s(&occ->peer_identity)); 1199 GNUNET_i2s (&occ->peer_identity));
1188 /* Lookup for HELLO in hello cache */ 1200 /* Lookup for HELLO in hello cache */
1189 if (NULL != (hello = GST_cache_lookup_hello(occ->peer->id))) 1201 if (NULL != (hello = GST_cache_lookup_hello (occ->peer->id)))
1190 { 1202 {
1191 LOG_DEBUG("0x%llx: HELLO of peer %s found in cache\n", 1203 LOG_DEBUG ("0x%llx: HELLO of peer %s found in cache\n",
1192 occ->op_id, 1204 occ->op_id,
1193 GNUNET_i2s(&occ->peer_identity)); 1205 GNUNET_i2s (&occ->peer_identity));
1194 occ->hello = GNUNET_copy_message(hello); 1206 occ->hello = GNUNET_copy_message (hello);
1195 p2_transport_connect(occ); 1207 p2_transport_connect (occ);
1196 return; 1208 return;
1197 } 1209 }
1198 GNUNET_asprintf(&occ->emsg, 1210 GNUNET_asprintf (&occ->emsg,
1199 "0x%llx: Timeout while acquiring TRANSPORT of %s from cache", 1211 "0x%llx: Timeout while acquiring TRANSPORT of %s from cache",
1200 occ->op_id, 1212 occ->op_id,
1201 GNUNET_i2s(&occ->peer_identity)); 1213 GNUNET_i2s (&occ->peer_identity));
1202 occ->cgh_p1th = 1214 occ->cgh_p1th =
1203 GST_connection_pool_get_handle(occ->peer->id, 1215 GST_connection_pool_get_handle (occ->peer->id,
1204 occ->peer->details.local.cfg, 1216 occ->peer->details.local.cfg,
1205 GST_CONNECTIONPOOL_SERVICE_TRANSPORT, 1217 GST_CONNECTIONPOOL_SERVICE_TRANSPORT,
1206 p1_transport_connect_cache_callback, 1218 p1_transport_connect_cache_callback,
1207 occ, 1219 occ,
1208 NULL, NULL, NULL); 1220 NULL, NULL, NULL);
1209} 1221}
1210 1222
1211 1223
@@ -1218,41 +1230,41 @@ occ_cache_get_handle_core_cb(void *cls,
1218 * @param msg the peer create success message 1230 * @param msg the peer create success message
1219 */ 1231 */
1220static void 1232static void
1221overlay_connect_get_config(void *cls, 1233overlay_connect_get_config (void *cls,
1222 const struct GNUNET_MessageHeader *msg) 1234 const struct GNUNET_MessageHeader *msg)
1223{ 1235{
1224 struct OverlayConnectContext *occ = cls; 1236 struct OverlayConnectContext *occ = cls;
1225 struct RemotePeer2Context *rp2c; 1237 struct RemotePeer2Context *rp2c;
1226 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *cmsg; 1238 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *cmsg;
1227 1239
1228 GNUNET_assert(OCC_TYPE_LOCAL != occ->type); 1240 GNUNET_assert (OCC_TYPE_LOCAL != occ->type);
1229 rp2c = &occ->p2ctx.remote; 1241 rp2c = &occ->p2ctx.remote;
1230 rp2c->opc = NULL; 1242 rp2c->opc = NULL;
1231 GNUNET_assert(NULL != occ->timeout_task); 1243 GNUNET_assert (NULL != occ->timeout_task);
1232 if (GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION != ntohs(msg->type)) 1244 if (GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION != ntohs (msg->type))
1233 { 1245 {
1234 GNUNET_SCHEDULER_cancel(occ->timeout_task); 1246 GNUNET_SCHEDULER_cancel (occ->timeout_task);
1235 occ->timeout_task = 1247 occ->timeout_task =
1236 GNUNET_SCHEDULER_add_now(&timeout_overlay_connect, occ); 1248 GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
1237 } 1249 }
1238 cmsg = 1250 cmsg =
1239 (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *)msg; 1251 (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg;
1240 occ->other_peer_identity = cmsg->peer_identity; 1252 occ->other_peer_identity = cmsg->peer_identity;
1241 GNUNET_free_non_null(occ->emsg); 1253 GNUNET_free_non_null (occ->emsg);
1242 GNUNET_asprintf(&occ->emsg, 1254 GNUNET_asprintf (&occ->emsg,
1243 "0x%llx: Timeout while connecting to CORE of peer with " 1255 "0x%llx: Timeout while connecting to CORE of peer with "
1244 "id: %u", 1256 "id: %u",
1245 occ->op_id, 1257 occ->op_id,
1246 occ->peer->id); 1258 occ->peer->id);
1247 occ->cgh_ch = 1259 occ->cgh_ch =
1248 GST_connection_pool_get_handle(occ->peer->id, 1260 GST_connection_pool_get_handle (occ->peer->id,
1249 occ->peer->details.local.cfg, 1261 occ->peer->details.local.cfg,
1250 GST_CONNECTIONPOOL_SERVICE_CORE, 1262 GST_CONNECTIONPOOL_SERVICE_CORE,
1251 occ_cache_get_handle_core_cb, 1263 occ_cache_get_handle_core_cb,
1252 occ, 1264 occ,
1253 &occ->other_peer_identity, 1265 &occ->other_peer_identity,
1254 &overlay_connect_notify, 1266 &overlay_connect_notify,
1255 occ); 1267 occ);
1256 return; 1268 return;
1257} 1269}
1258 1270
@@ -1264,12 +1276,12 @@ overlay_connect_get_config(void *cls,
1264 * @param emsg the error message; NULL if host registration is successful 1276 * @param emsg the error message; NULL if host registration is successful
1265 */ 1277 */
1266static void 1278static void
1267host_registration_comp(void *cls, const char *emsg) 1279host_registration_comp (void *cls, const char *emsg)
1268{ 1280{
1269 struct RegisteredHostContext *rhc = cls; 1281 struct RegisteredHostContext *rhc = cls;
1270 1282
1271 rhc->state = RHC_DONE; 1283 rhc->state = RHC_DONE;
1272 GST_process_next_focc(rhc); 1284 GST_process_next_focc (rhc);
1273} 1285}
1274 1286
1275 1287
@@ -1284,19 +1296,19 @@ host_registration_comp(void *cls, const char *emsg)
1284 * #GNUNET_NO if not. 1296 * #GNUNET_NO if not.
1285 */ 1297 */
1286static int 1298static int
1287reghost_match_iterator(void *cls, 1299reghost_match_iterator (void *cls,
1288 const struct GNUNET_HashCode *key, 1300 const struct GNUNET_HashCode *key,
1289 void *value) 1301 void *value)
1290{ 1302{
1291 struct RegisteredHostContext **rh = cls; 1303 struct RegisteredHostContext **rh = cls;
1292 struct RegisteredHostContext *rh_val = value; 1304 struct RegisteredHostContext *rh_val = value;
1293 1305
1294 if ((rh_val->host == (*rh)->host) && (rh_val->reg_host == (*rh)->reg_host)) 1306 if ((rh_val->host == (*rh)->host) && (rh_val->reg_host == (*rh)->reg_host))
1295 { 1307 {
1296 GNUNET_free(*rh); 1308 GNUNET_free (*rh);
1297 *rh = rh_val; 1309 *rh = rh_val;
1298 return GNUNET_NO; 1310 return GNUNET_NO;
1299 } 1311 }
1300 return GNUNET_YES; 1312 return GNUNET_YES;
1301} 1313}
1302 1314
@@ -1309,15 +1321,15 @@ reghost_match_iterator(void *cls,
1309 * @return the hashcode 1321 * @return the hashcode
1310 */ 1322 */
1311static struct GNUNET_HashCode 1323static struct GNUNET_HashCode
1312hash_hosts(struct GNUNET_TESTBED_Host *reg_host, 1324hash_hosts (struct GNUNET_TESTBED_Host *reg_host,
1313 struct GNUNET_TESTBED_Host *host) 1325 struct GNUNET_TESTBED_Host *host)
1314{ 1326{
1315 struct GNUNET_HashCode hash; 1327 struct GNUNET_HashCode hash;
1316 uint32_t host_ids[2]; 1328 uint32_t host_ids[2];
1317 1329
1318 host_ids[0] = GNUNET_TESTBED_host_get_id_(reg_host); 1330 host_ids[0] = GNUNET_TESTBED_host_get_id_ (reg_host);
1319 host_ids[1] = GNUNET_TESTBED_host_get_id_(host); 1331 host_ids[1] = GNUNET_TESTBED_host_get_id_ (host);
1320 GNUNET_CRYPTO_hash(host_ids, sizeof(host_ids), &hash); 1332 GNUNET_CRYPTO_hash (host_ids, sizeof(host_ids), &hash);
1321 return hash; 1333 return hash;
1322} 1334}
1323 1335
@@ -1336,48 +1348,48 @@ hash_hosts(struct GNUNET_TESTBED_Host *reg_host,
1336 * already registered, NULL is returned. 1348 * already registered, NULL is returned.
1337 */ 1349 */
1338static struct RegisteredHostContext * 1350static struct RegisteredHostContext *
1339register_host(struct Slave *slave, 1351register_host (struct Slave *slave,
1340 struct GNUNET_TESTBED_Host *host) 1352 struct GNUNET_TESTBED_Host *host)
1341{ 1353{
1342 struct GNUNET_HashCode hash; 1354 struct GNUNET_HashCode hash;
1343 struct RegisteredHostContext *rhc; 1355 struct RegisteredHostContext *rhc;
1344 1356
1345 rhc = GNUNET_new(struct RegisteredHostContext); 1357 rhc = GNUNET_new (struct RegisteredHostContext);
1346 rhc->reg_host = host; 1358 rhc->reg_host = host;
1347 rhc->host = GST_host_list[slave->host_id]; 1359 rhc->host = GST_host_list[slave->host_id];
1348 GNUNET_assert(NULL != rhc->reg_host); 1360 GNUNET_assert (NULL != rhc->reg_host);
1349 GNUNET_assert(NULL != rhc->host); 1361 GNUNET_assert (NULL != rhc->host);
1350 rhc->state = RHC_INIT; 1362 rhc->state = RHC_INIT;
1351 hash = hash_hosts(rhc->reg_host, rhc->host); 1363 hash = hash_hosts (rhc->reg_host, rhc->host);
1352 if ((GNUNET_NO == 1364 if ((GNUNET_NO ==
1353 GNUNET_CONTAINER_multihashmap_contains(slave->reghost_map, 1365 GNUNET_CONTAINER_multihashmap_contains (slave->reghost_map,
1354 &hash)) || 1366 &hash)) ||
1355 (GNUNET_SYSERR != 1367 (GNUNET_SYSERR !=
1356 GNUNET_CONTAINER_multihashmap_get_multiple(slave->reghost_map, 1368 GNUNET_CONTAINER_multihashmap_get_multiple (slave->reghost_map,
1357 &hash, 1369 &hash,
1358 reghost_match_iterator, 1370 reghost_match_iterator,
1359 &rhc))) 1371 &rhc)))
1360 { 1372 {
1361 /* create and add a new registerd host context */ 1373 /* create and add a new registerd host context */
1362 /* add the focc to its queue */ 1374 /* add the focc to its queue */
1363 GNUNET_CONTAINER_multihashmap_put(slave->reghost_map, 1375 GNUNET_CONTAINER_multihashmap_put (slave->reghost_map,
1364 &hash, 1376 &hash,
1365 rhc, 1377 rhc,
1366 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1378 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1367 GST_queue_host_registration(slave, 1379 GST_queue_host_registration (slave,
1368 host_registration_comp, 1380 host_registration_comp,
1369 rhc, 1381 rhc,
1370 rhc->reg_host); 1382 rhc->reg_host);
1371 } 1383 }
1372 else 1384 else
1373 { 1385 {
1374 /* rhc is now set to the existing one from the hash map by 1386 /* rhc is now set to the existing one from the hash map by
1375 * reghost_match_iterator() */ 1387 * reghost_match_iterator() */
1376 /* if queue is empty then ignore creating focc and proceed with normal 1388 /* if queue is empty then ignore creating focc and proceed with normal
1377 * forwarding */ 1389 * forwarding */
1378 if (RHC_DONE == rhc->state) 1390 if (RHC_DONE == rhc->state)
1379 return NULL; 1391 return NULL;
1380 } 1392 }
1381 return rhc; 1393 return rhc;
1382} 1394}
1383 1395
@@ -1392,8 +1404,8 @@ register_host(struct Slave *slave,
1392 * be notified 1404 * be notified
1393 */ 1405 */
1394static void 1406static void
1395forward_overlay_connect(const struct GNUNET_TESTBED_OverlayConnectMessage *msg, 1407forward_overlay_connect (const struct GNUNET_TESTBED_OverlayConnectMessage *msg,
1396 struct GNUNET_SERVICE_Client *client) 1408 struct GNUNET_SERVICE_Client *client)
1397{ 1409{
1398 struct ForwardedOperationContext *fopc; 1410 struct ForwardedOperationContext *fopc;
1399 struct Route *route_to_peer2_host; 1411 struct Route *route_to_peer2_host;
@@ -1406,61 +1418,63 @@ forward_overlay_connect(const struct GNUNET_TESTBED_OverlayConnectMessage *msg,
1406 uint32_t p1; 1418 uint32_t p1;
1407 uint32_t p2; 1419 uint32_t p2;
1408 1420
1409 p1 = ntohl(msg->peer1); 1421 p1 = ntohl (msg->peer1);
1410 p2 = ntohl(msg->peer2); 1422 p2 = ntohl (msg->peer2);
1411 op_id = GNUNET_ntohll(msg->operation_id); 1423 op_id = GNUNET_ntohll (msg->operation_id);
1412 peer2_host_id = ntohl(msg->peer2_host_id); 1424 peer2_host_id = ntohl (msg->peer2_host_id);
1413 GNUNET_assert(VALID_PEER_ID(p1)); 1425 GNUNET_assert (VALID_PEER_ID (p1));
1414 GNUNET_assert(VALID_HOST_ID(peer2_host_id)); 1426 GNUNET_assert (VALID_HOST_ID (peer2_host_id));
1415 peer = GST_peer_list[p1]; 1427 peer = GST_peer_list[p1];
1416 GNUNET_assert(GNUNET_YES == peer->is_remote); 1428 GNUNET_assert (GNUNET_YES == peer->is_remote);
1417 LOG_DEBUG("0x%llx: Forwarding overlay connect\n", op_id); 1429 LOG_DEBUG ("0x%llx: Forwarding overlay connect\n", op_id);
1418 route_to_peer2_host = GST_find_dest_route(peer2_host_id); 1430 route_to_peer2_host = GST_find_dest_route (peer2_host_id);
1419 route_to_peer1_host = GST_find_dest_route 1431 route_to_peer1_host = GST_find_dest_route
1420 (peer->details.remote.remote_host_id); 1432 (peer->details.remote.remote_host_id);
1421 GNUNET_assert(NULL != route_to_peer1_host); 1433 GNUNET_assert (NULL != route_to_peer1_host);
1422 if ((NULL != route_to_peer2_host) && 1434 if ((NULL != route_to_peer2_host) &&
1423 (route_to_peer1_host->dest == route_to_peer2_host->dest)) 1435 (route_to_peer1_host->dest == route_to_peer2_host->dest))
1424 goto forward; 1436 goto forward;
1425 /* Peer2 is either with us OR peer1 and peer2 can be reached through 1437 /* Peer2 is either with us OR peer1 and peer2 can be reached through
1426 different subtrees OR peer2 is on a subtree unknown to us */ 1438 different subtrees OR peer2 is on a subtree unknown to us */
1427 if (NULL != (rhc = register_host(peer->details.remote.slave, 1439 if (NULL != (rhc = register_host (peer->details.remote.slave,
1428 GST_host_list[peer2_host_id]))) 1440 GST_host_list[peer2_host_id])))
1429 { 1441 {
1430 LOG_DEBUG("Queueing forwarding FOCC for connecting peers %u and %u\n", p1, p2); 1442 LOG_DEBUG ("Queueing forwarding FOCC for connecting peers %u and %u\n", p1,
1431 focc = GNUNET_new(struct ForwardedOverlayConnectContext); 1443 p2);
1432 focc->rhc = rhc; 1444 focc = GNUNET_new (struct ForwardedOverlayConnectContext);
1433 focc->peer1 = p1; 1445 focc->rhc = rhc;
1434 focc->peer2 = p2; 1446 focc->peer1 = p1;
1435 focc->peer2_host_id = peer2_host_id; 1447 focc->peer2 = p2;
1436 focc->orig_msg = GNUNET_copy_message(&msg->header); 1448 focc->peer2_host_id = peer2_host_id;
1437 focc->operation_id = op_id; 1449 focc->orig_msg = GNUNET_copy_message (&msg->header);
1438 focc->client = client; 1450 focc->operation_id = op_id;
1439 GNUNET_CONTAINER_DLL_insert_tail(rhc->focc_dll_head, 1451 focc->client = client;
1440 rhc->focc_dll_tail, 1452 GNUNET_CONTAINER_DLL_insert_tail (rhc->focc_dll_head,
1441 focc); 1453 rhc->focc_dll_tail,
1442 return; 1454 focc);
1443 } 1455 return;
1456 }
1444 1457
1445forward: 1458forward:
1446 LOG_DEBUG("Forwarding without FOCC for connecting peers %u and %u\n", p1, p2); 1459 LOG_DEBUG ("Forwarding without FOCC for connecting peers %u and %u\n", p1,
1447 fopc = GNUNET_new(struct ForwardedOperationContext); 1460 p2);
1461 fopc = GNUNET_new (struct ForwardedOperationContext);
1448 fopc->client = client; 1462 fopc->client = client;
1449 fopc->operation_id = op_id; 1463 fopc->operation_id = op_id;
1450 fopc->type = OP_OVERLAY_CONNECT; 1464 fopc->type = OP_OVERLAY_CONNECT;
1451 fopc->opc = 1465 fopc->opc =
1452 GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. 1466 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1453 slave->controller, op_id, 1467 slave->controller, op_id,
1454 &msg->header, 1468 &msg->header,
1455 &GST_forwarded_operation_reply_relay, 1469 &GST_forwarded_operation_reply_relay,
1456 fopc); 1470 fopc);
1457 fopc->timeout_task = 1471 fopc->timeout_task =
1458 GNUNET_SCHEDULER_add_delayed(GST_timeout, 1472 GNUNET_SCHEDULER_add_delayed (GST_timeout,
1459 &GST_forwarded_operation_timeout, 1473 &GST_forwarded_operation_timeout,
1460 fopc); 1474 fopc);
1461 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 1475 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
1462 fopcq_tail, 1476 fopcq_tail,
1463 fopc); 1477 fopc);
1464} 1478}
1465 1479
1466 1480
@@ -1472,35 +1486,35 @@ forward:
1472 * @param c handle to the controller connection 1486 * @param c handle to the controller connection
1473 */ 1487 */
1474static void 1488static void
1475p2_controller_connect_cb(void *cls, 1489p2_controller_connect_cb (void *cls,
1476 struct GNUNET_TESTBED_Controller *c) 1490 struct GNUNET_TESTBED_Controller *c)
1477{ 1491{
1478 struct OverlayConnectContext *occ = cls; 1492 struct OverlayConnectContext *occ = cls;
1479 struct RemotePeer2Context *rp2c; 1493 struct RemotePeer2Context *rp2c;
1480 struct GNUNET_TESTBED_PeerGetConfigurationMessage cmsg; 1494 struct GNUNET_TESTBED_PeerGetConfigurationMessage cmsg;
1481 1495
1482 GNUNET_assert(OCC_TYPE_LOCAL != occ->type); 1496 GNUNET_assert (OCC_TYPE_LOCAL != occ->type);
1483 rp2c = &occ->p2ctx.remote; 1497 rp2c = &occ->p2ctx.remote;
1484 rp2c->ncn = NULL; 1498 rp2c->ncn = NULL;
1485 rp2c->p2c = c; 1499 rp2c->p2c = c;
1486 cmsg.header.size = 1500 cmsg.header.size =
1487 htons(sizeof(struct GNUNET_TESTBED_PeerGetConfigurationMessage)); 1501 htons (sizeof(struct GNUNET_TESTBED_PeerGetConfigurationMessage));
1488 cmsg.header.type = 1502 cmsg.header.type =
1489 htons(GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION); 1503 htons (GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION);
1490 cmsg.peer_id = htonl(occ->other_peer_id); 1504 cmsg.peer_id = htonl (occ->other_peer_id);
1491 cmsg.operation_id = GNUNET_htonll(occ->op_id); 1505 cmsg.operation_id = GNUNET_htonll (occ->op_id);
1492 rp2c->opc = 1506 rp2c->opc =
1493 GNUNET_TESTBED_forward_operation_msg_(rp2c->p2c, 1507 GNUNET_TESTBED_forward_operation_msg_ (rp2c->p2c,
1494 occ->op_id, 1508 occ->op_id,
1495 &cmsg.header, 1509 &cmsg.header,
1496 &overlay_connect_get_config, 1510 &overlay_connect_get_config,
1497 occ); 1511 occ);
1498 GNUNET_free_non_null(occ->emsg); 1512 GNUNET_free_non_null (occ->emsg);
1499 GNUNET_asprintf(&occ->emsg, 1513 GNUNET_asprintf (&occ->emsg,
1500 "0x%llx: Timeout while getting peer identity of peer " 1514 "0x%llx: Timeout while getting peer identity of peer "
1501 "with id: %u", 1515 "with id: %u",
1502 occ->op_id, 1516 occ->op_id,
1503 occ->other_peer_id); 1517 occ->other_peer_id);
1504} 1518}
1505 1519
1506 1520
@@ -1511,8 +1525,8 @@ p2_controller_connect_cb(void *cls,
1511 * @param msg the actual message 1525 * @param msg the actual message
1512 */ 1526 */
1513void 1527void
1514handle_overlay_connect(void *cls, 1528handle_overlay_connect (void *cls,
1515 const struct GNUNET_TESTBED_OverlayConnectMessage *msg) 1529 const struct GNUNET_TESTBED_OverlayConnectMessage *msg)
1516{ 1530{
1517 struct GNUNET_SERVICE_Client *client = cls; 1531 struct GNUNET_SERVICE_Client *client = cls;
1518 struct Peer *peer; 1532 struct Peer *peer;
@@ -1524,114 +1538,114 @@ handle_overlay_connect(void *cls,
1524 uint32_t p2; 1538 uint32_t p2;
1525 uint32_t peer2_host_id; 1539 uint32_t peer2_host_id;
1526 1540
1527 p1 = ntohl(msg->peer1); 1541 p1 = ntohl (msg->peer1);
1528 p2 = ntohl(msg->peer2); 1542 p2 = ntohl (msg->peer2);
1529 if (!VALID_PEER_ID(p1)) 1543 if (! VALID_PEER_ID (p1))
1530 { 1544 {
1531 GNUNET_break(0); 1545 GNUNET_break (0);
1532 GNUNET_SERVICE_client_drop(client); 1546 GNUNET_SERVICE_client_drop (client);
1533 return; 1547 return;
1534 } 1548 }
1535 peer = GST_peer_list[p1]; 1549 peer = GST_peer_list[p1];
1536 operation_id = GNUNET_ntohll(msg->operation_id); 1550 operation_id = GNUNET_ntohll (msg->operation_id);
1537 LOG_DEBUG 1551 LOG_DEBUG
1538 ("Received overlay connect for peers %u and %u with op id: 0x%llx\n", 1552 ("Received overlay connect for peers %u and %u with op id: 0x%llx\n",
1539 p1, 1553 p1,
1540 p2, 1554 p2,
1541 operation_id); 1555 operation_id);
1542 peer2_host_id = ntohl(msg->peer2_host_id); 1556 peer2_host_id = ntohl (msg->peer2_host_id);
1543 if (GNUNET_YES == peer->is_remote) 1557 if (GNUNET_YES == peer->is_remote)
1558 {
1559 if (! VALID_HOST_ID (peer2_host_id))
1544 { 1560 {
1545 if (!VALID_HOST_ID(peer2_host_id)) 1561 GNUNET_break (0);
1546 { 1562 GNUNET_SERVICE_client_drop (client);
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);
1553 return; 1563 return;
1554 } 1564 }
1565 forward_overlay_connect (msg, client);
1566 GNUNET_SERVICE_client_continue (client);
1567 return;
1568 }
1555 p2n = NULL; 1569 p2n = NULL;
1556 occ = GNUNET_new(struct OverlayConnectContext); 1570 occ = GNUNET_new (struct OverlayConnectContext);
1557 occ->type = OCC_TYPE_LOCAL; 1571 occ->type = OCC_TYPE_LOCAL;
1558 if (!VALID_PEER_ID(p2)) /* May be peer2 is on a another controller */ 1572 if (! VALID_PEER_ID (p2)) /* May be peer2 is on a another controller */
1573 {
1574 if (NULL == (p2n = GST_get_neighbour (peer2_host_id)))
1559 { 1575 {
1560 if (NULL == (p2n = GST_get_neighbour(peer2_host_id))) 1576 if (! VALID_HOST_ID (peer2_host_id))
1561 { 1577 {
1562 if (!VALID_HOST_ID(peer2_host_id)) 1578 GNUNET_break (0);
1563 { 1579 LOG (GNUNET_ERROR_TYPE_WARNING,
1564 GNUNET_break(0); 1580 "0x%llx: Peer %u's host not in our neighbours list\n",
1565 LOG(GNUNET_ERROR_TYPE_WARNING, 1581 operation_id, p2);
1566 "0x%llx: Peer %u's host not in our neighbours list\n", 1582 GNUNET_SERVICE_client_drop (client);
1567 operation_id, p2); 1583 GNUNET_free (occ);
1568 GNUNET_SERVICE_client_drop(client); 1584 return;
1569 GNUNET_free(occ); 1585 }
1570 return; 1586 p2n = GST_create_neighbour (GST_host_list[peer2_host_id]);
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;
1576 } 1587 }
1588 occ->type = OCC_TYPE_REMOTE_LATERAL;
1589 occ->p2ctx.remote.p2n = p2n;
1590 }
1577 else if (GNUNET_YES == GST_peer_list[p2]->is_remote) 1591 else if (GNUNET_YES == GST_peer_list[p2]->is_remote)
1578 { 1592 {
1579 occ->type = OCC_TYPE_REMOTE_SLAVE; 1593 occ->type = OCC_TYPE_REMOTE_SLAVE;
1580 occ->p2ctx.remote.p2c = GST_peer_list[p2]->details.remote.slave->controller; 1594 occ->p2ctx.remote.p2c = GST_peer_list[p2]->details.remote.slave->controller;
1581 } 1595 }
1582 GNUNET_CONTAINER_DLL_insert_tail(occq_head, 1596 GNUNET_CONTAINER_DLL_insert_tail (occq_head,
1583 occq_tail, 1597 occq_tail,
1584 occ); 1598 occ);
1585 occ->client = client; 1599 occ->client = client;
1586 occ->other_peer_id = p2; 1600 occ->other_peer_id = p2;
1587 GST_peer_list[p1]->reference_cnt++; 1601 GST_peer_list[p1]->reference_cnt++;
1588 occ->peer = GST_peer_list[p1]; 1602 occ->peer = GST_peer_list[p1];
1589 occ->op_id = operation_id; 1603 occ->op_id = operation_id;
1590 GNUNET_assert(NULL == occ->timeout_task); 1604 GNUNET_assert (NULL == occ->timeout_task);
1591 occ->timeout_task = 1605 occ->timeout_task =
1592 GNUNET_SCHEDULER_add_delayed(GST_timeout, 1606 GNUNET_SCHEDULER_add_delayed (GST_timeout,
1593 &timeout_overlay_connect, 1607 &timeout_overlay_connect,
1594 occ); 1608 occ);
1595 switch (occ->type) 1609 switch (occ->type)
1596 { 1610 {
1597 case OCC_TYPE_REMOTE_LATERAL: 1611 case OCC_TYPE_REMOTE_LATERAL:
1598 GNUNET_asprintf(&occ->emsg, 1612 GNUNET_asprintf (&occ->emsg,
1599 "0x%llx: Timeout while acquiring connection to peer %u's " 1613 "0x%llx: Timeout while acquiring connection to peer %u's "
1600 "host: %u\n", 1614 "host: %u\n",
1601 occ->op_id, 1615 occ->op_id,
1602 occ->other_peer_id, 1616 occ->other_peer_id,
1603 peer2_host_id); 1617 peer2_host_id);
1604 occ->p2ctx.remote.ncn 1618 occ->p2ctx.remote.ncn
1605 = GST_neighbour_get_connection(p2n, 1619 = GST_neighbour_get_connection (p2n,
1606 &p2_controller_connect_cb, 1620 &p2_controller_connect_cb,
1607 occ); 1621 occ);
1608 break; 1622 break;
1609 1623
1610 case OCC_TYPE_REMOTE_SLAVE: 1624 case OCC_TYPE_REMOTE_SLAVE:
1611 p2_controller_connect_cb(occ, 1625 p2_controller_connect_cb (occ,
1612 occ->p2ctx.remote.p2c); 1626 occ->p2ctx.remote.p2c);
1613 break; 1627 break;
1614 1628
1615 case OCC_TYPE_LOCAL: 1629 case OCC_TYPE_LOCAL:
1616 peer2 = GST_peer_list[occ->other_peer_id]; 1630 peer2 = GST_peer_list[occ->other_peer_id];
1617 peer2->reference_cnt++; 1631 peer2->reference_cnt++;
1618 GNUNET_TESTING_peer_get_identity(peer2->details.local.peer, 1632 GNUNET_TESTING_peer_get_identity (peer2->details.local.peer,
1619 &occ->other_peer_identity); 1633 &occ->other_peer_identity);
1620 GNUNET_asprintf(&occ->emsg, 1634 GNUNET_asprintf (&occ->emsg,
1621 "0x%llx: Timeout while connecting to CORE of peer with " 1635 "0x%llx: Timeout while connecting to CORE of peer with "
1622 "id: %u", 1636 "id: %u",
1623 occ->op_id, 1637 occ->op_id,
1624 occ->peer->id); 1638 occ->peer->id);
1625 occ->cgh_ch = 1639 occ->cgh_ch =
1626 GST_connection_pool_get_handle(occ->peer->id, 1640 GST_connection_pool_get_handle (occ->peer->id,
1627 occ->peer->details.local.cfg, 1641 occ->peer->details.local.cfg,
1628 GST_CONNECTIONPOOL_SERVICE_CORE, 1642 GST_CONNECTIONPOOL_SERVICE_CORE,
1629 occ_cache_get_handle_core_cb, occ, 1643 occ_cache_get_handle_core_cb, occ,
1630 &occ->other_peer_identity, 1644 &occ->other_peer_identity,
1631 &overlay_connect_notify, occ); 1645 &overlay_connect_notify, occ);
1632 break; 1646 break;
1633 } 1647 }
1634 GNUNET_SERVICE_client_continue(client); 1648 GNUNET_SERVICE_client_continue (client);
1635} 1649}
1636 1650
1637 1651
@@ -1642,30 +1656,30 @@ handle_overlay_connect(void *cls,
1642 * @param rocc the RemoteOverlayConnectCtx 1656 * @param rocc the RemoteOverlayConnectCtx
1643 */ 1657 */
1644static void 1658static void
1645cleanup_rocc(struct RemoteOverlayConnectCtx *rocc) 1659cleanup_rocc (struct RemoteOverlayConnectCtx *rocc)
1646{ 1660{
1647 LOG_DEBUG("0x%llx: Cleaning up rocc\n", 1661 LOG_DEBUG ("0x%llx: Cleaning up rocc\n",
1648 rocc->op_id); 1662 rocc->op_id);
1649 if (NULL != rocc->attempt_connect_task_id) 1663 if (NULL != rocc->attempt_connect_task_id)
1650 GNUNET_SCHEDULER_cancel(rocc->attempt_connect_task_id); 1664 GNUNET_SCHEDULER_cancel (rocc->attempt_connect_task_id);
1651 if (NULL != rocc->timeout_rocc_task_id) 1665 if (NULL != rocc->timeout_rocc_task_id)
1652 GNUNET_SCHEDULER_cancel(rocc->timeout_rocc_task_id); 1666 GNUNET_SCHEDULER_cancel (rocc->timeout_rocc_task_id);
1653 if (NULL != rocc->ohh) 1667 if (NULL != rocc->ohh)
1654 GNUNET_TRANSPORT_offer_hello_cancel(rocc->ohh); 1668 GNUNET_TRANSPORT_offer_hello_cancel (rocc->ohh);
1655 if (NULL != rocc->tcc.csh) 1669 if (NULL != rocc->tcc.csh)
1656 GNUNET_ATS_connectivity_suggest_cancel(rocc->tcc.csh); 1670 GNUNET_ATS_connectivity_suggest_cancel (rocc->tcc.csh);
1657 GST_connection_pool_get_handle_done(rocc->tcc.cgh_p2_th); 1671 GST_connection_pool_get_handle_done (rocc->tcc.cgh_p2_th);
1658 GST_connection_pool_get_handle_done(rocc->tcc.cgh_p2_ats); 1672 GST_connection_pool_get_handle_done (rocc->tcc.cgh_p2_ats);
1659 GNUNET_assert(rocc->peer->reference_cnt > 0); 1673 GNUNET_assert (rocc->peer->reference_cnt > 0);
1660 rocc->peer->reference_cnt--; 1674 rocc->peer->reference_cnt--;
1661 if ((GNUNET_YES == rocc->peer->destroy_flag) && 1675 if ((GNUNET_YES == rocc->peer->destroy_flag) &&
1662 (0 == rocc->peer->reference_cnt)) 1676 (0 == rocc->peer->reference_cnt))
1663 GST_destroy_peer(rocc->peer); 1677 GST_destroy_peer (rocc->peer);
1664 GNUNET_free_non_null(rocc->hello); 1678 GNUNET_free_non_null (rocc->hello);
1665 GNUNET_CONTAINER_DLL_remove(roccq_head, 1679 GNUNET_CONTAINER_DLL_remove (roccq_head,
1666 roccq_tail, 1680 roccq_tail,
1667 rocc); 1681 rocc);
1668 GNUNET_free(rocc); 1682 GNUNET_free (rocc);
1669} 1683}
1670 1684
1671 1685
@@ -1675,15 +1689,15 @@ cleanup_rocc(struct RemoteOverlayConnectCtx *rocc)
1675 * @param cls the RemoteOverlayConnectCtx 1689 * @param cls the RemoteOverlayConnectCtx
1676 */ 1690 */
1677static void 1691static void
1678timeout_rocc_task(void *cls) 1692timeout_rocc_task (void *cls)
1679{ 1693{
1680 struct RemoteOverlayConnectCtx *rocc = cls; 1694 struct RemoteOverlayConnectCtx *rocc = cls;
1681 1695
1682 GNUNET_assert(rocc->timeout_rocc_task_id != NULL); 1696 GNUNET_assert (rocc->timeout_rocc_task_id != NULL);
1683 rocc->timeout_rocc_task_id = NULL; 1697 rocc->timeout_rocc_task_id = NULL;
1684 LOG_DEBUG("0x%llx: rocc timed out\n", 1698 LOG_DEBUG ("0x%llx: rocc timed out\n",
1685 rocc->op_id); 1699 rocc->op_id);
1686 cleanup_rocc(rocc); 1700 cleanup_rocc (rocc);
1687} 1701}
1688 1702
1689 1703
@@ -1695,20 +1709,20 @@ timeout_rocc_task(void *cls)
1695 * @param new_peer the peer that connected 1709 * @param new_peer the peer that connected
1696 */ 1710 */
1697static void 1711static void
1698cache_transport_peer_connect_notify(void *cls, 1712cache_transport_peer_connect_notify (void *cls,
1699 const struct GNUNET_PeerIdentity *new_peer) 1713 const struct GNUNET_PeerIdentity *new_peer)
1700{ 1714{
1701 struct RemoteOverlayConnectCtx *rocc = cls; 1715 struct RemoteOverlayConnectCtx *rocc = cls;
1702 1716
1703 LOG_DEBUG("0x%llx: Request Overlay connect notify\n", 1717 LOG_DEBUG ("0x%llx: Request Overlay connect notify\n",
1704 rocc->op_id); 1718 rocc->op_id);
1705 GNUNET_assert(0 == 1719 GNUNET_assert (0 ==
1706 memcmp(new_peer, &rocc->a_id, 1720 memcmp (new_peer, &rocc->a_id,
1707 sizeof(struct GNUNET_PeerIdentity))); 1721 sizeof(struct GNUNET_PeerIdentity)));
1708 LOG_DEBUG("0x%llx: Peer %s connected\n", 1722 LOG_DEBUG ("0x%llx: Peer %s connected\n",
1709 rocc->op_id, 1723 rocc->op_id,
1710 GNUNET_i2s(&rocc->a_id)); 1724 GNUNET_i2s (&rocc->a_id));
1711 cleanup_rocc(rocc); 1725 cleanup_rocc (rocc);
1712} 1726}
1713 1727
1714 1728
@@ -1719,7 +1733,7 @@ cache_transport_peer_connect_notify(void *cls,
1719 * @param cls the RemoteOverlayConnectCtx 1733 * @param cls the RemoteOverlayConnectCtx
1720 */ 1734 */
1721static void 1735static void
1722attempt_connect_task(void *cls); 1736attempt_connect_task (void *cls);
1723 1737
1724 1738
1725/** 1739/**
@@ -1730,22 +1744,22 @@ attempt_connect_task(void *cls);
1730 * @param cls the overlay connect context 1744 * @param cls the overlay connect context
1731 */ 1745 */
1732static void 1746static void
1733rocc_hello_sent_cb(void *cls) 1747rocc_hello_sent_cb (void *cls)
1734{ 1748{
1735 struct RemoteOverlayConnectCtx *rocc = cls; 1749 struct RemoteOverlayConnectCtx *rocc = cls;
1736 1750
1737 rocc->ohh = NULL; 1751 rocc->ohh = NULL;
1738 GNUNET_assert(NULL == rocc->attempt_connect_task_id); 1752 GNUNET_assert (NULL == rocc->attempt_connect_task_id);
1739 LOG_DEBUG("0x%llx: HELLO of peer %s delivered to local peer with id: %u\n", 1753 LOG_DEBUG ("0x%llx: HELLO of peer %s delivered to local peer with id: %u\n",
1740 rocc->op_id, 1754 rocc->op_id,
1741 GNUNET_i2s(&rocc->a_id), 1755 GNUNET_i2s (&rocc->a_id),
1742 rocc->peer->id); 1756 rocc->peer->id);
1743 rocc->tcc.cgh_p2_ats = 1757 rocc->tcc.cgh_p2_ats =
1744 GST_connection_pool_get_handle(rocc->peer->id, 1758 GST_connection_pool_get_handle (rocc->peer->id,
1745 rocc->peer->details.local.cfg, 1759 rocc->peer->details.local.cfg,
1746 GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY, 1760 GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY,
1747 &occ_cache_get_handle_ats_rocc_cb, 1761 &occ_cache_get_handle_ats_rocc_cb,
1748 rocc, NULL, NULL, NULL); 1762 rocc, NULL, NULL, NULL);
1749} 1763}
1750 1764
1751 1765
@@ -1756,29 +1770,29 @@ rocc_hello_sent_cb(void *cls)
1756 * @param cls the RemoteOverlayConnectCtx 1770 * @param cls the RemoteOverlayConnectCtx
1757 */ 1771 */
1758static void 1772static void
1759attempt_connect_task(void *cls) 1773attempt_connect_task (void *cls)
1760{ 1774{
1761 struct RemoteOverlayConnectCtx *rocc = cls; 1775 struct RemoteOverlayConnectCtx *rocc = cls;
1762 1776
1763 GNUNET_assert(NULL != rocc->attempt_connect_task_id); 1777 GNUNET_assert (NULL != rocc->attempt_connect_task_id);
1764 rocc->attempt_connect_task_id = NULL; 1778 rocc->attempt_connect_task_id = NULL;
1765 LOG_DEBUG("0x%llx: Offering HELLO of peer %s to remote peer with id: %u\n", 1779 LOG_DEBUG ("0x%llx: Offering HELLO of peer %s to remote peer with id: %u\n",
1766 rocc->op_id, 1780 rocc->op_id,
1767 GNUNET_i2s(&rocc->a_id), 1781 GNUNET_i2s (&rocc->a_id),
1768 rocc->peer->id); 1782 rocc->peer->id);
1769 rocc->ohh = 1783 rocc->ohh =
1770 GNUNET_TRANSPORT_offer_hello(rocc->tcc.cfg, 1784 GNUNET_TRANSPORT_offer_hello (rocc->tcc.cfg,
1771 rocc->hello, 1785 rocc->hello,
1772 &rocc_hello_sent_cb, 1786 &rocc_hello_sent_cb,
1773 rocc); 1787 rocc);
1774 if (NULL == rocc->ohh) 1788 if (NULL == rocc->ohh)
1775 rocc->attempt_connect_task_id = 1789 rocc->attempt_connect_task_id =
1776 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 1790 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1777 (GNUNET_TIME_UNIT_MILLISECONDS, 1791 (GNUNET_TIME_UNIT_MILLISECONDS,
1778 100 + 1792 100
1779 GNUNET_CRYPTO_random_u32 1793 + GNUNET_CRYPTO_random_u32
1780 (GNUNET_CRYPTO_QUALITY_WEAK, 500)), 1794 (GNUNET_CRYPTO_QUALITY_WEAK, 500)),
1781 &attempt_connect_task, rocc); 1795 &attempt_connect_task, rocc);
1782} 1796}
1783 1797
1784 1798
@@ -1792,36 +1806,37 @@ attempt_connect_task(void *cls)
1792 * @param ignore_ peer identity which is ignored in this callback 1806 * @param ignore_ peer identity which is ignored in this callback
1793 */ 1807 */
1794static void 1808static void
1795rocc_cache_get_handle_transport_cb(void *cls, 1809rocc_cache_get_handle_transport_cb (void *cls,
1796 struct GNUNET_CORE_Handle *ch, 1810 struct GNUNET_CORE_Handle *ch,
1797 struct GNUNET_TRANSPORT_CoreHandle *th, 1811 struct GNUNET_TRANSPORT_CoreHandle *th,
1798 struct GNUNET_ATS_ConnectivityHandle *ac, 1812 struct GNUNET_ATS_ConnectivityHandle *ac,
1799 const struct GNUNET_PeerIdentity *ignore_, 1813 const struct GNUNET_PeerIdentity *ignore_,
1800 const struct GNUNET_CONFIGURATION_Handle *cfg) 1814 const struct
1815 GNUNET_CONFIGURATION_Handle *cfg)
1801{ 1816{
1802 struct RemoteOverlayConnectCtx *rocc = cls; 1817 struct RemoteOverlayConnectCtx *rocc = cls;
1803 1818
1804 if (NULL == th) 1819 if (NULL == th)
1805 { 1820 {
1806 rocc->timeout_rocc_task_id = 1821 rocc->timeout_rocc_task_id =
1807 GNUNET_SCHEDULER_add_now(&timeout_rocc_task, rocc); 1822 GNUNET_SCHEDULER_add_now (&timeout_rocc_task, rocc);
1808 return; 1823 return;
1809 } 1824 }
1810 rocc->tcc.th_ = th; 1825 rocc->tcc.th_ = th;
1811 rocc->tcc.cfg = cfg; 1826 rocc->tcc.cfg = cfg;
1812 if (NULL != 1827 if (NULL !=
1813 GNUNET_TRANSPORT_core_get_mq(rocc->tcc.th_, 1828 GNUNET_TRANSPORT_core_get_mq (rocc->tcc.th_,
1814 &rocc->a_id)) 1829 &rocc->a_id))
1815 { 1830 {
1816 LOG_DEBUG("0x%llx: Target peer %s already connected to local peer: %u\n", 1831 LOG_DEBUG ("0x%llx: Target peer %s already connected to local peer: %u\n",
1817 rocc->op_id, 1832 rocc->op_id,
1818 GNUNET_i2s(&rocc->a_id), 1833 GNUNET_i2s (&rocc->a_id),
1819 rocc->peer->id); 1834 rocc->peer->id);
1820 cleanup_rocc(rocc); 1835 cleanup_rocc (rocc);
1821 return; 1836 return;
1822 } 1837 }
1823 rocc->attempt_connect_task_id = 1838 rocc->attempt_connect_task_id =
1824 GNUNET_SCHEDULER_add_now(&attempt_connect_task, rocc); 1839 GNUNET_SCHEDULER_add_now (&attempt_connect_task, rocc);
1825} 1840}
1826 1841
1827 1842
@@ -1833,32 +1848,34 @@ rocc_cache_get_handle_transport_cb(void *cls,
1833 * @return #GNUNET_OK if @a msg is well-formed 1848 * @return #GNUNET_OK if @a msg is well-formed
1834 */ 1849 */
1835int 1850int
1836check_remote_overlay_connect(void *cls, 1851check_remote_overlay_connect (void *cls,
1837 const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg) 1852 const struct
1853 GNUNET_TESTBED_RemoteOverlayConnectMessage *msg)
1838{ 1854{
1839 uint32_t peer_id; 1855 uint32_t peer_id;
1840 uint16_t msize; 1856 uint16_t msize;
1841 uint16_t hsize; 1857 uint16_t hsize;
1842 1858
1843 msize = ntohs(msg->header.size); 1859 msize = ntohs (msg->header.size);
1844 if (GNUNET_MESSAGE_TYPE_HELLO != ntohs(msg->hello->type)) 1860 if (GNUNET_MESSAGE_TYPE_HELLO != ntohs (msg->hello->type))
1845 { 1861 {
1846 GNUNET_break(0); 1862 GNUNET_break (0);
1847 return GNUNET_SYSERR; 1863 return GNUNET_SYSERR;
1848 } 1864 }
1849 hsize = ntohs(msg->hello->size); 1865 hsize = ntohs (msg->hello->size);
1850 if ((sizeof(struct GNUNET_TESTBED_RemoteOverlayConnectMessage) + hsize) != msize) 1866 if ((sizeof(struct GNUNET_TESTBED_RemoteOverlayConnectMessage) + hsize) !=
1851 { 1867 msize)
1852 GNUNET_break(0); 1868 {
1853 return GNUNET_SYSERR; 1869 GNUNET_break (0);
1854 } 1870 return GNUNET_SYSERR;
1855 peer_id = ntohl(msg->peer); 1871 }
1872 peer_id = ntohl (msg->peer);
1856 if ((peer_id >= GST_peer_list_size) || 1873 if ((peer_id >= GST_peer_list_size) ||
1857 (NULL == GST_peer_list[peer_id])) 1874 (NULL == GST_peer_list[peer_id]))
1858 { 1875 {
1859 GNUNET_break_op(0); 1876 GNUNET_break_op (0);
1860 return GNUNET_SYSERR; 1877 return GNUNET_SYSERR;
1861 } 1878 }
1862 return GNUNET_OK; 1879 return GNUNET_OK;
1863} 1880}
1864 1881
@@ -1870,8 +1887,9 @@ check_remote_overlay_connect(void *cls,
1870 * @param msg the actual message 1887 * @param msg the actual message
1871 */ 1888 */
1872void 1889void
1873handle_remote_overlay_connect(void *cls, 1890handle_remote_overlay_connect (void *cls,
1874 const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg) 1891 const struct
1892 GNUNET_TESTBED_RemoteOverlayConnectMessage *msg)
1875{ 1893{
1876 struct GNUNET_SERVICE_Client *client = cls; 1894 struct GNUNET_SERVICE_Client *client = cls;
1877 struct RemoteOverlayConnectCtx *rocc; 1895 struct RemoteOverlayConnectCtx *rocc;
@@ -1881,55 +1899,56 @@ handle_remote_overlay_connect(void *cls,
1881 uint32_t peer_id; 1899 uint32_t peer_id;
1882 uint16_t hsize; 1900 uint16_t hsize;
1883 1901
1884 hsize = ntohs(msg->hello->size); 1902 hsize = ntohs (msg->hello->size);
1885 peer_id = ntohl(msg->peer); 1903 peer_id = ntohl (msg->peer);
1886 peer = GST_peer_list[peer_id]; 1904 peer = GST_peer_list[peer_id];
1887 if (GNUNET_YES == peer->is_remote) 1905 if (GNUNET_YES == peer->is_remote)
1888 { 1906 {
1889 struct GNUNET_MessageHeader *msg2; 1907 struct GNUNET_MessageHeader *msg2;
1890 1908
1891 msg2 = GNUNET_copy_message(&msg->header); 1909 msg2 = GNUNET_copy_message (&msg->header);
1892 GNUNET_TESTBED_queue_message_(peer->details.remote.slave->controller, 1910 GNUNET_TESTBED_queue_message_ (peer->details.remote.slave->controller,
1893 msg2); 1911 msg2);
1894 GNUNET_SERVICE_client_continue(client); 1912 GNUNET_SERVICE_client_continue (client);
1895 return; 1913 return;
1896 } 1914 }
1897 rocc = GNUNET_new(struct RemoteOverlayConnectCtx); 1915 rocc = GNUNET_new (struct RemoteOverlayConnectCtx);
1898 rocc->op_id = GNUNET_ntohll(msg->operation_id); 1916 rocc->op_id = GNUNET_ntohll (msg->operation_id);
1899 GNUNET_CONTAINER_DLL_insert_tail(roccq_head, 1917 GNUNET_CONTAINER_DLL_insert_tail (roccq_head,
1900 roccq_tail, 1918 roccq_tail,
1901 rocc); 1919 rocc);
1902 rocc->a_id = msg->peer_identity; 1920 rocc->a_id = msg->peer_identity;
1903 GNUNET_TESTING_peer_get_identity(peer->details.local.peer, 1921 GNUNET_TESTING_peer_get_identity (peer->details.local.peer,
1904 &pid); 1922 &pid);
1905 (void)GNUNET_strlcpy(pid_str, 1923 (void) GNUNET_strlcpy (pid_str,
1906 GNUNET_i2s(&pid), 1924 GNUNET_i2s (&pid),
1907 sizeof(pid_str)); 1925 sizeof(pid_str));
1908 LOG_DEBUG("0x%llx: Remote overlay connect %s to peer %s with hello size: %u\n", 1926 LOG_DEBUG (
1909 rocc->op_id, 1927 "0x%llx: Remote overlay connect %s to peer %s with hello size: %u\n",
1910 pid_str, 1928 rocc->op_id,
1911 GNUNET_i2s(&rocc->a_id), 1929 pid_str,
1912 hsize); 1930 GNUNET_i2s (&rocc->a_id),
1931 hsize);
1913 rocc->peer = peer; 1932 rocc->peer = peer;
1914 rocc->peer->reference_cnt++; 1933 rocc->peer->reference_cnt++;
1915 rocc->hello = GNUNET_malloc(hsize); 1934 rocc->hello = GNUNET_malloc (hsize);
1916 GNUNET_memcpy(rocc->hello, 1935 GNUNET_memcpy (rocc->hello,
1917 msg->hello, 1936 msg->hello,
1918 hsize); 1937 hsize);
1919 rocc->tcc.cgh_p2_th = 1938 rocc->tcc.cgh_p2_th =
1920 GST_connection_pool_get_handle(peer_id, 1939 GST_connection_pool_get_handle (peer_id,
1921 rocc->peer->details.local.cfg, 1940 rocc->peer->details.local.cfg,
1922 GST_CONNECTIONPOOL_SERVICE_TRANSPORT, 1941 GST_CONNECTIONPOOL_SERVICE_TRANSPORT,
1923 &rocc_cache_get_handle_transport_cb, 1942 &rocc_cache_get_handle_transport_cb,
1924 rocc, 1943 rocc,
1925 &rocc->a_id, 1944 &rocc->a_id,
1926 &cache_transport_peer_connect_notify, 1945 &cache_transport_peer_connect_notify,
1927 rocc); 1946 rocc);
1928 rocc->timeout_rocc_task_id = 1947 rocc->timeout_rocc_task_id =
1929 GNUNET_SCHEDULER_add_delayed(GST_timeout, 1948 GNUNET_SCHEDULER_add_delayed (GST_timeout,
1930 &timeout_rocc_task, 1949 &timeout_rocc_task,
1931 rocc); 1950 rocc);
1932 GNUNET_SERVICE_client_continue(client); 1951 GNUNET_SERVICE_client_continue (client);
1933} 1952}
1934 1953
1935 1954
@@ -1937,12 +1956,12 @@ handle_remote_overlay_connect(void *cls,
1937 * Clears all pending overlay connect contexts in queue 1956 * Clears all pending overlay connect contexts in queue
1938 */ 1957 */
1939void 1958void
1940GST_free_occq() 1959GST_free_occq ()
1941{ 1960{
1942 struct OverlayConnectContext *occ; 1961 struct OverlayConnectContext *occ;
1943 1962
1944 while (NULL != (occ = occq_head)) 1963 while (NULL != (occ = occq_head))
1945 cleanup_occ(occ); 1964 cleanup_occ (occ);
1946} 1965}
1947 1966
1948 1967
@@ -1950,10 +1969,10 @@ GST_free_occq()
1950 * Clears all pending remote overlay connect contexts in queue 1969 * Clears all pending remote overlay connect contexts in queue
1951 */ 1970 */
1952void 1971void
1953GST_free_roccq() 1972GST_free_roccq ()
1954{ 1973{
1955 struct RemoteOverlayConnectCtx *rocc; 1974 struct RemoteOverlayConnectCtx *rocc;
1956 1975
1957 while (NULL != (rocc = roccq_head)) 1976 while (NULL != (rocc = roccq_head))
1958 cleanup_rocc(rocc); 1977 cleanup_rocc (rocc);
1959} 1978}
diff --git a/src/testbed/gnunet-service-testbed_peers.c b/src/testbed/gnunet-service-testbed_peers.c
index 743c7e849..836f05464 100644
--- a/src/testbed/gnunet-service-testbed_peers.c
+++ b/src/testbed/gnunet-service-testbed_peers.c
@@ -44,7 +44,8 @@ unsigned int GST_num_local_peers;
44/** 44/**
45 * Context information to manage peers' services 45 * Context information to manage peers' services
46 */ 46 */
47struct ManageServiceContext { 47struct ManageServiceContext
48{
48 /** 49 /**
49 * DLL next ptr 50 * DLL next ptr
50 */ 51 */
@@ -96,7 +97,8 @@ struct ManageServiceContext {
96/** 97/**
97 * Context information for peer re-configure operations 98 * Context information for peer re-configure operations
98 */ 99 */
99struct PeerReconfigureContext { 100struct PeerReconfigureContext
101{
100 /** 102 /**
101 * DLL next for inclusoin in peer reconfigure operations list 103 * DLL next for inclusoin in peer reconfigure operations list
102 */ 104 */
@@ -164,11 +166,11 @@ static struct ManageServiceContext *mctx_tail;
164 * @param peer the peer to add 166 * @param peer the peer to add
165 */ 167 */
166static void 168static void
167peer_list_add(struct Peer *peer) 169peer_list_add (struct Peer *peer)
168{ 170{
169 if (peer->id >= GST_peer_list_size) 171 if (peer->id >= GST_peer_list_size)
170 GST_array_grow_large_enough(GST_peer_list, GST_peer_list_size, peer->id); 172 GST_array_grow_large_enough (GST_peer_list, GST_peer_list_size, peer->id);
171 GNUNET_assert(NULL == GST_peer_list[peer->id]); 173 GNUNET_assert (NULL == GST_peer_list[peer->id]);
172 GST_peer_list[peer->id] = peer; 174 GST_peer_list[peer->id] = peer;
173 if (GNUNET_NO == peer->is_remote) 175 if (GNUNET_NO == peer->is_remote)
174 GST_num_local_peers++; 176 GST_num_local_peers++;
@@ -181,7 +183,7 @@ peer_list_add(struct Peer *peer)
181 * @param peer the peer to be removed 183 * @param peer the peer to be removed
182 */ 184 */
183static void 185static void
184peer_list_remove(struct Peer *peer) 186peer_list_remove (struct Peer *peer)
185{ 187{
186 unsigned int orig_size; 188 unsigned int orig_size;
187 uint32_t id; 189 uint32_t id;
@@ -191,21 +193,21 @@ peer_list_remove(struct Peer *peer)
191 GST_peer_list[peer->id] = NULL; 193 GST_peer_list[peer->id] = NULL;
192 orig_size = GST_peer_list_size; 194 orig_size = GST_peer_list_size;
193 while (GST_peer_list_size >= LIST_GROW_STEP) 195 while (GST_peer_list_size >= LIST_GROW_STEP)
194 { 196 {
195 for (id = GST_peer_list_size - 1; 197 for (id = GST_peer_list_size - 1;
196 (id >= GST_peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX); 198 (id >= GST_peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX);
197 id--) 199 id--)
198 if (NULL != GST_peer_list[id]) 200 if (NULL != GST_peer_list[id])
199 break;
200 if (id != ((GST_peer_list_size - LIST_GROW_STEP) - 1))
201 break; 201 break;
202 GST_peer_list_size -= LIST_GROW_STEP; 202 if (id != ((GST_peer_list_size - LIST_GROW_STEP) - 1))
203 } 203 break;
204 GST_peer_list_size -= LIST_GROW_STEP;
205 }
204 if (orig_size == GST_peer_list_size) 206 if (orig_size == GST_peer_list_size)
205 return; 207 return;
206 GST_peer_list = 208 GST_peer_list =
207 GNUNET_realloc(GST_peer_list, 209 GNUNET_realloc (GST_peer_list,
208 sizeof(struct Peer *) * GST_peer_list_size); 210 sizeof(struct Peer *) * GST_peer_list_size);
209} 211}
210 212
211 213
@@ -216,12 +218,12 @@ peer_list_remove(struct Peer *peer)
216 * @param cls the FowardedOperationContext 218 * @param cls the FowardedOperationContext
217 */ 219 */
218static void 220static void
219peer_create_forward_timeout(void *cls) 221peer_create_forward_timeout (void *cls)
220{ 222{
221 struct ForwardedOperationContext *fopc = cls; 223 struct ForwardedOperationContext *fopc = cls;
222 224
223 GNUNET_free(fopc->cls); 225 GNUNET_free (fopc->cls);
224 GST_forwarded_operation_timeout(fopc); 226 GST_forwarded_operation_timeout (fopc);
225} 227}
226 228
227 229
@@ -233,19 +235,19 @@ peer_create_forward_timeout(void *cls)
233 * @param msg the peer create success message 235 * @param msg the peer create success message
234 */ 236 */
235static void 237static void
236peer_create_success_cb(void *cls, const struct GNUNET_MessageHeader *msg) 238peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
237{ 239{
238 struct ForwardedOperationContext *fopc = cls; 240 struct ForwardedOperationContext *fopc = cls;
239 struct Peer *remote_peer; 241 struct Peer *remote_peer;
240 242
241 if (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS) 243 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS)
242 { 244 {
243 GNUNET_assert(NULL != fopc->cls); 245 GNUNET_assert (NULL != fopc->cls);
244 remote_peer = fopc->cls; 246 remote_peer = fopc->cls;
245 peer_list_add(remote_peer); 247 peer_list_add (remote_peer);
246 } 248 }
247 GST_forwarded_operation_reply_relay(fopc, 249 GST_forwarded_operation_reply_relay (fopc,
248 msg); 250 msg);
249} 251}
250 252
251 253
@@ -255,24 +257,24 @@ peer_create_success_cb(void *cls, const struct GNUNET_MessageHeader *msg)
255 * @param peer the peer structure to destroy 257 * @param peer the peer structure to destroy
256 */ 258 */
257void 259void
258GST_destroy_peer(struct Peer *peer) 260GST_destroy_peer (struct Peer *peer)
259{ 261{
260 GNUNET_break(0 == peer->reference_cnt); 262 GNUNET_break (0 == peer->reference_cnt);
261 if (GNUNET_YES == peer->is_remote) 263 if (GNUNET_YES == peer->is_remote)
262 { 264 {
263 peer_list_remove(peer); 265 peer_list_remove (peer);
264 GNUNET_free(peer); 266 GNUNET_free (peer);
265 return; 267 return;
266 } 268 }
267 if (GNUNET_YES == peer->details.local.is_running) 269 if (GNUNET_YES == peer->details.local.is_running)
268 { 270 {
269 GNUNET_TESTING_peer_stop(peer->details.local.peer); 271 GNUNET_TESTING_peer_stop (peer->details.local.peer);
270 peer->details.local.is_running = GNUNET_NO; 272 peer->details.local.is_running = GNUNET_NO;
271 } 273 }
272 GNUNET_TESTING_peer_destroy(peer->details.local.peer); 274 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
273 GNUNET_CONFIGURATION_destroy(peer->details.local.cfg); 275 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
274 peer_list_remove(peer); 276 peer_list_remove (peer);
275 GNUNET_free(peer); 277 GNUNET_free (peer);
276} 278}
277 279
278 280
@@ -282,20 +284,20 @@ GST_destroy_peer(struct Peer *peer)
282 * @param mctx the ManageServiceContext 284 * @param mctx the ManageServiceContext
283 */ 285 */
284static void 286static void
285cleanup_mctx(struct ManageServiceContext *mctx) 287cleanup_mctx (struct ManageServiceContext *mctx)
286{ 288{
287 mctx->expired = GNUNET_YES; 289 mctx->expired = GNUNET_YES;
288 GNUNET_CONTAINER_DLL_remove(mctx_head, 290 GNUNET_CONTAINER_DLL_remove (mctx_head,
289 mctx_tail, 291 mctx_tail,
290 mctx); 292 mctx);
291 GNUNET_ARM_disconnect(mctx->ah); 293 GNUNET_ARM_disconnect (mctx->ah);
292 GNUNET_assert(0 < mctx->peer->reference_cnt); 294 GNUNET_assert (0 < mctx->peer->reference_cnt);
293 mctx->peer->reference_cnt--; 295 mctx->peer->reference_cnt--;
294 if ((GNUNET_YES == mctx->peer->destroy_flag) && 296 if ((GNUNET_YES == mctx->peer->destroy_flag) &&
295 (0 == mctx->peer->reference_cnt)) 297 (0 == mctx->peer->reference_cnt))
296 GST_destroy_peer(mctx->peer); 298 GST_destroy_peer (mctx->peer);
297 GNUNET_free(mctx->service); 299 GNUNET_free (mctx->service);
298 GNUNET_free(mctx); 300 GNUNET_free (mctx);
299} 301}
300 302
301 303
@@ -306,10 +308,10 @@ cleanup_mctx(struct ManageServiceContext *mctx)
306 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 308 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
307 */ 309 */
308static int 310static int
309stop_peer(struct Peer *peer) 311stop_peer (struct Peer *peer)
310{ 312{
311 GNUNET_assert(GNUNET_NO == peer->is_remote); 313 GNUNET_assert (GNUNET_NO == peer->is_remote);
312 if (GNUNET_OK != GNUNET_TESTING_peer_kill(peer->details.local.peer)) 314 if (GNUNET_OK != GNUNET_TESTING_peer_kill (peer->details.local.peer))
313 return GNUNET_SYSERR; 315 return GNUNET_SYSERR;
314 peer->details.local.is_running = GNUNET_NO; 316 peer->details.local.is_running = GNUNET_NO;
315 return GNUNET_OK; 317 return GNUNET_OK;
@@ -322,25 +324,25 @@ stop_peer(struct Peer *peer)
322 * @param prc the PeerReconfigureContext 324 * @param prc the PeerReconfigureContext
323 */ 325 */
324static void 326static void
325cleanup_prc(struct PeerReconfigureContext *prc) 327cleanup_prc (struct PeerReconfigureContext *prc)
326{ 328{
327 struct Peer *peer; 329 struct Peer *peer;
328 330
329 if (VALID_PEER_ID(prc->peer_id)) 331 if (VALID_PEER_ID (prc->peer_id))
332 {
333 peer = GST_peer_list [prc->peer_id];
334 if (1 != prc->stopped)
330 { 335 {
331 peer = GST_peer_list [prc->peer_id]; 336 GNUNET_TESTING_peer_stop_async_cancel (peer->details.local.peer);
332 if (1 != prc->stopped) 337 stop_peer (peer); /* Stop the peer synchronously */
333 {
334 GNUNET_TESTING_peer_stop_async_cancel(peer->details.local.peer);
335 stop_peer(peer); /* Stop the peer synchronously */
336 }
337 } 338 }
339 }
338 if (NULL != prc->cfg) 340 if (NULL != prc->cfg)
339 GNUNET_CONFIGURATION_destroy(prc->cfg); 341 GNUNET_CONFIGURATION_destroy (prc->cfg);
340 GNUNET_CONTAINER_DLL_remove(prc_head, 342 GNUNET_CONTAINER_DLL_remove (prc_head,
341 prc_tail, 343 prc_tail,
342 prc); 344 prc);
343 GNUNET_free(prc); 345 GNUNET_free (prc);
344} 346}
345 347
346 348
@@ -350,7 +352,7 @@ cleanup_prc(struct PeerReconfigureContext *prc)
350 * @param client the client that disconnected 352 * @param client the client that disconnected
351 */ 353 */
352void 354void
353GST_notify_client_disconnect_peers(struct GNUNET_SERVICE_Client *client) 355GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client)
354{ 356{
355 struct ForwardedOperationContext *fopc; 357 struct ForwardedOperationContext *fopc;
356 struct ForwardedOperationContext *fopcn; 358 struct ForwardedOperationContext *fopcn;
@@ -360,28 +362,28 @@ GST_notify_client_disconnect_peers(struct GNUNET_SERVICE_Client *client)
360 struct PeerReconfigureContext *prcn; 362 struct PeerReconfigureContext *prcn;
361 363
362 for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) 364 for (fopc = fopcq_head; NULL != fopc; fopc = fopcn)
365 {
366 fopcn = fopc->next;
367 if (client == fopc->client)
363 { 368 {
364 fopcn = fopc->next; 369 if (OP_PEER_CREATE == fopc->type)
365 if (client == fopc->client) 370 GNUNET_free (fopc->cls);
366 { 371 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
367 if (OP_PEER_CREATE == fopc->type) 372 GST_forwarded_operation_timeout (fopc);
368 GNUNET_free(fopc->cls);
369 GNUNET_SCHEDULER_cancel(fopc->timeout_task);
370 GST_forwarded_operation_timeout(fopc);
371 }
372 } 373 }
374 }
373 for (mctx = mctx_head; NULL != mctx; mctx = mctxn) 375 for (mctx = mctx_head; NULL != mctx; mctx = mctxn)
374 { 376 {
375 mctxn = mctx->next; 377 mctxn = mctx->next;
376 if (client == mctx->client) 378 if (client == mctx->client)
377 cleanup_mctx(mctx); 379 cleanup_mctx (mctx);
378 } 380 }
379 for (prc = prc_head; NULL != prc; prc = prcn) 381 for (prc = prc_head; NULL != prc; prc = prcn)
380 { 382 {
381 prcn = prc->next; 383 prcn = prc->next;
382 if (client == prc->client) 384 if (client == prc->client)
383 cleanup_prc(prc); 385 cleanup_prc (prc);
384 } 386 }
385} 387}
386 388
387 389
@@ -393,22 +395,22 @@ GST_notify_client_disconnect_peers(struct GNUNET_SERVICE_Client *client)
393 * @param msg the peer create success message 395 * @param msg the peer create success message
394 */ 396 */
395static void 397static void
396peer_destroy_success_cb(void *cls, const struct GNUNET_MessageHeader *msg) 398peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
397{ 399{
398 struct ForwardedOperationContext *fopc = cls; 400 struct ForwardedOperationContext *fopc = cls;
399 struct Peer *remote_peer; 401 struct Peer *remote_peer;
400 402
401 if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS == 403 if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS ==
402 ntohs(msg->type)) 404 ntohs (msg->type))
403 { 405 {
404 remote_peer = fopc->cls; 406 remote_peer = fopc->cls;
405 GNUNET_assert(NULL != remote_peer); 407 GNUNET_assert (NULL != remote_peer);
406 remote_peer->destroy_flag = GNUNET_YES; 408 remote_peer->destroy_flag = GNUNET_YES;
407 if (0 == remote_peer->reference_cnt) 409 if (0 == remote_peer->reference_cnt)
408 GST_destroy_peer(remote_peer); 410 GST_destroy_peer (remote_peer);
409 } 411 }
410 GST_forwarded_operation_reply_relay(fopc, 412 GST_forwarded_operation_reply_relay (fopc,
411 msg); 413 msg);
412} 414}
413 415
414 416
@@ -420,8 +422,8 @@ peer_destroy_success_cb(void *cls, const struct GNUNET_MessageHeader *msg)
420 * @return #GNUNET_OK if @a msg is well-formed 422 * @return #GNUNET_OK if @a msg is well-formed
421 */ 423 */
422int 424int
423check_peer_create(void *cls, 425check_peer_create (void *cls,
424 const struct GNUNET_TESTBED_PeerCreateMessage *msg) 426 const struct GNUNET_TESTBED_PeerCreateMessage *msg)
425{ 427{
426 return GNUNET_OK; /* checked later */ 428 return GNUNET_OK; /* checked later */
427} 429}
@@ -434,8 +436,8 @@ check_peer_create(void *cls,
434 * @param msg the actual message 436 * @param msg the actual message
435 */ 437 */
436void 438void
437handle_peer_create(void *cls, 439handle_peer_create (void *cls,
438 const struct GNUNET_TESTBED_PeerCreateMessage *msg) 440 const struct GNUNET_TESTBED_PeerCreateMessage *msg)
439{ 441{
440 struct GNUNET_SERVICE_Client *client = cls; 442 struct GNUNET_SERVICE_Client *client = cls;
441 struct GNUNET_MQ_Envelope *env; 443 struct GNUNET_MQ_Envelope *env;
@@ -448,114 +450,114 @@ handle_peer_create(void *cls,
448 uint32_t host_id; 450 uint32_t host_id;
449 uint32_t peer_id; 451 uint32_t peer_id;
450 452
451 host_id = ntohl(msg->host_id); 453 host_id = ntohl (msg->host_id);
452 peer_id = ntohl(msg->peer_id); 454 peer_id = ntohl (msg->peer_id);
453 if (VALID_PEER_ID(peer_id)) 455 if (VALID_PEER_ID (peer_id))
454 { 456 {
455 (void)GNUNET_asprintf(&emsg, 457 (void) GNUNET_asprintf (&emsg,
456 "Peer with ID %u already exists", 458 "Peer with ID %u already exists",
457 peer_id); 459 peer_id);
458 GST_send_operation_fail_msg(client, 460 GST_send_operation_fail_msg (client,
459 GNUNET_ntohll(msg->operation_id), 461 GNUNET_ntohll (msg->operation_id),
460 emsg); 462 emsg);
461 GNUNET_free(emsg); 463 GNUNET_free (emsg);
462 GNUNET_SERVICE_client_continue(client); 464 GNUNET_SERVICE_client_continue (client);
463 return; 465 return;
464 } 466 }
465 if (UINT32_MAX == peer_id) 467 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)
466 { 480 {
467 GST_send_operation_fail_msg(client, 481 GNUNET_break (0);
468 GNUNET_ntohll(msg->operation_id), 482 GNUNET_SERVICE_client_drop (client);
469 "Cannot create peer with given ID");
470 GNUNET_SERVICE_client_continue(client);
471 return; 483 return;
472 } 484 }
473 if (host_id == GST_context->host_id) 485 GNUNET_CONFIGURATION_set_value_number (cfg,
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)
474 { 506 {
475 /* We are responsible for this peer */ 507 LOG (GNUNET_ERROR_TYPE_WARNING,
476 cfg = GNUNET_TESTBED_extract_config_(&msg->header); 508 "Configuring peer failed: %s\n",
477 if (NULL == cfg) 509 emsg);
478 { 510 GNUNET_free (emsg);
479 GNUNET_break(0); 511 GNUNET_free (peer);
480 GNUNET_SERVICE_client_drop(client); 512 GNUNET_break (0);
481 return; 513 GNUNET_SERVICE_client_drop (client);
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);
523 return; 514 return;
524 } 515 }
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 }
525 527
526 /* Forward peer create request */ 528 /* Forward peer create request */
527 route = GST_find_dest_route(host_id); 529 route = GST_find_dest_route (host_id);
528 if (NULL == route) 530 if (NULL == route)
529 { 531 {
530 GNUNET_break(0); 532 GNUNET_break (0);
531 GNUNET_SERVICE_client_continue(client); // ? 533 GNUNET_SERVICE_client_continue (client); // ?
532 return; 534 return;
533 } 535 }
534 peer = GNUNET_new(struct Peer); 536 peer = GNUNET_new (struct Peer);
535 peer->is_remote = GNUNET_YES; 537 peer->is_remote = GNUNET_YES;
536 peer->id = peer_id; 538 peer->id = peer_id;
537 peer->details.remote.slave = GST_slave_list[route->dest]; 539 peer->details.remote.slave = GST_slave_list[route->dest];
538 peer->details.remote.remote_host_id = host_id; 540 peer->details.remote.remote_host_id = host_id;
539 fo_ctxt = GNUNET_new(struct ForwardedOperationContext); 541 fo_ctxt = GNUNET_new (struct ForwardedOperationContext);
540 fo_ctxt->client = client; 542 fo_ctxt->client = client;
541 fo_ctxt->operation_id = GNUNET_ntohll(msg->operation_id); 543 fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
542 fo_ctxt->cls = peer; 544 fo_ctxt->cls = peer;
543 fo_ctxt->type = OP_PEER_CREATE; 545 fo_ctxt->type = OP_PEER_CREATE;
544 fo_ctxt->opc = 546 fo_ctxt->opc =
545 GNUNET_TESTBED_forward_operation_msg_(GST_slave_list 547 GNUNET_TESTBED_forward_operation_msg_ (GST_slave_list
546 [route->dest]->controller, 548 [route->dest]->controller,
547 fo_ctxt->operation_id, 549 fo_ctxt->operation_id,
548 &msg->header, 550 &msg->header,
549 &peer_create_success_cb, 551 &peer_create_success_cb,
550 fo_ctxt); 552 fo_ctxt);
551 fo_ctxt->timeout_task = 553 fo_ctxt->timeout_task =
552 GNUNET_SCHEDULER_add_delayed(GST_timeout, 554 GNUNET_SCHEDULER_add_delayed (GST_timeout,
553 &peer_create_forward_timeout, 555 &peer_create_forward_timeout,
554 fo_ctxt); 556 fo_ctxt);
555 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 557 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
556 fopcq_tail, 558 fopcq_tail,
557 fo_ctxt); 559 fo_ctxt);
558 GNUNET_SERVICE_client_continue(client); 560 GNUNET_SERVICE_client_continue (client);
559} 561}
560 562
561 563
@@ -566,63 +568,63 @@ handle_peer_create(void *cls,
566 * @param msg the actual message 568 * @param msg the actual message
567 */ 569 */
568void 570void
569handle_peer_destroy(void *cls, 571handle_peer_destroy (void *cls,
570 const struct GNUNET_TESTBED_PeerDestroyMessage *msg) 572 const struct GNUNET_TESTBED_PeerDestroyMessage *msg)
571{ 573{
572 struct GNUNET_SERVICE_Client *client = cls; 574 struct GNUNET_SERVICE_Client *client = cls;
573 struct ForwardedOperationContext *fopc; 575 struct ForwardedOperationContext *fopc;
574 struct Peer *peer; 576 struct Peer *peer;
575 uint32_t peer_id; 577 uint32_t peer_id;
576 578
577 peer_id = ntohl(msg->peer_id); 579 peer_id = ntohl (msg->peer_id);
578 LOG_DEBUG("Received peer destory on peer: %u and operation id: %llu\n", 580 LOG_DEBUG ("Received peer destory on peer: %u and operation id: %llu\n",
579 (unsigned int)peer_id, 581 (unsigned int) peer_id,
580 (unsigned long long)GNUNET_ntohll(msg->operation_id)); 582 (unsigned long long) GNUNET_ntohll (msg->operation_id));
581 if (!VALID_PEER_ID(peer_id)) 583 if (! VALID_PEER_ID (peer_id))
582 { 584 {
583 LOG(GNUNET_ERROR_TYPE_ERROR, 585 LOG (GNUNET_ERROR_TYPE_ERROR,
584 "Asked to destroy a non existent peer with id: %u\n", peer_id); 586 "Asked to destroy a non existent peer with id: %u\n", peer_id);
585 GST_send_operation_fail_msg(client, 587 GST_send_operation_fail_msg (client,
586 GNUNET_ntohll(msg->operation_id), 588 GNUNET_ntohll (msg->operation_id),
587 "Peer doesn't exist"); 589 "Peer doesn't exist");
588 GNUNET_SERVICE_client_continue(client); 590 GNUNET_SERVICE_client_continue (client);
589 return; 591 return;
590 } 592 }
591 peer = GST_peer_list[peer_id]; 593 peer = GST_peer_list[peer_id];
592 if (GNUNET_YES == peer->is_remote) 594 if (GNUNET_YES == peer->is_remote)
593 { 595 {
594 /* Forward the destory message to sub controller */ 596 /* Forward the destory message to sub controller */
595 fopc = GNUNET_new(struct ForwardedOperationContext); 597 fopc = GNUNET_new (struct ForwardedOperationContext);
596 fopc->client = client; 598 fopc->client = client;
597 fopc->cls = peer; 599 fopc->cls = peer;
598 fopc->type = OP_PEER_DESTROY; 600 fopc->type = OP_PEER_DESTROY;
599 fopc->operation_id = GNUNET_ntohll(msg->operation_id); 601 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
600 fopc->opc = 602 fopc->opc =
601 GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. 603 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
602 slave->controller, 604 slave->controller,
603 fopc->operation_id, 605 fopc->operation_id,
604 &msg->header, 606 &msg->header,
605 &peer_destroy_success_cb, 607 &peer_destroy_success_cb,
606 fopc); 608 fopc);
607 fopc->timeout_task = 609 fopc->timeout_task =
608 GNUNET_SCHEDULER_add_delayed(GST_timeout, 610 GNUNET_SCHEDULER_add_delayed (GST_timeout,
609 &GST_forwarded_operation_timeout, 611 &GST_forwarded_operation_timeout,
610 fopc); 612 fopc);
611 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 613 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
612 fopcq_tail, 614 fopcq_tail,
613 fopc); 615 fopc);
614 GNUNET_SERVICE_client_continue(client); 616 GNUNET_SERVICE_client_continue (client);
615 return; 617 return;
616 } 618 }
617 peer->destroy_flag = GNUNET_YES; 619 peer->destroy_flag = GNUNET_YES;
618 if (0 == peer->reference_cnt) 620 if (0 == peer->reference_cnt)
619 GST_destroy_peer(peer); 621 GST_destroy_peer (peer);
620 else 622 else
621 LOG(GNUNET_ERROR_TYPE_DEBUG, 623 LOG (GNUNET_ERROR_TYPE_DEBUG,
622 "Delaying peer destroy as peer is currently in use\n"); 624 "Delaying peer destroy as peer is currently in use\n");
623 GST_send_operation_success_msg(client, 625 GST_send_operation_success_msg (client,
624 GNUNET_ntohll(msg->operation_id)); 626 GNUNET_ntohll (msg->operation_id));
625 GNUNET_SERVICE_client_continue(client); 627 GNUNET_SERVICE_client_continue (client);
626} 628}
627 629
628 630
@@ -633,10 +635,10 @@ handle_peer_destroy(void *cls,
633 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 635 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
634 */ 636 */
635static int 637static int
636start_peer(struct Peer *peer) 638start_peer (struct Peer *peer)
637{ 639{
638 GNUNET_assert(GNUNET_NO == peer->is_remote); 640 GNUNET_assert (GNUNET_NO == peer->is_remote);
639 if (GNUNET_OK != GNUNET_TESTING_peer_start(peer->details.local.peer)) 641 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer))
640 return GNUNET_SYSERR; 642 return GNUNET_SYSERR;
641 peer->details.local.is_running = GNUNET_YES; 643 peer->details.local.is_running = GNUNET_YES;
642 return GNUNET_OK; 644 return GNUNET_OK;
@@ -650,8 +652,8 @@ start_peer(struct Peer *peer)
650 * @param msg the actual message 652 * @param msg the actual message
651 */ 653 */
652void 654void
653handle_peer_start(void *cls, 655handle_peer_start (void *cls,
654 const struct GNUNET_TESTBED_PeerStartMessage *msg) 656 const struct GNUNET_TESTBED_PeerStartMessage *msg)
655{ 657{
656 struct GNUNET_SERVICE_Client *client = cls; 658 struct GNUNET_SERVICE_Client *client = cls;
657 struct GNUNET_MQ_Envelope *env; 659 struct GNUNET_MQ_Envelope *env;
@@ -660,55 +662,56 @@ handle_peer_start(void *cls,
660 struct Peer *peer; 662 struct Peer *peer;
661 uint32_t peer_id; 663 uint32_t peer_id;
662 664
663 peer_id = ntohl(msg->peer_id); 665 peer_id = ntohl (msg->peer_id);
664 if (!VALID_PEER_ID(peer_id)) 666 if (! VALID_PEER_ID (peer_id))
665 { 667 {
666 GNUNET_break(0); 668 GNUNET_break (0);
667 LOG(GNUNET_ERROR_TYPE_ERROR, 669 LOG (GNUNET_ERROR_TYPE_ERROR,
668 "Asked to start a non existent peer with id: %u\n", 670 "Asked to start a non existent peer with id: %u\n",
669 peer_id); 671 peer_id);
670 GNUNET_SERVICE_client_continue(client); 672 GNUNET_SERVICE_client_continue (client);
671 return; 673 return;
672 } 674 }
673 peer = GST_peer_list[peer_id]; 675 peer = GST_peer_list[peer_id];
674 if (GNUNET_YES == peer->is_remote) 676 if (GNUNET_YES == peer->is_remote)
675 { 677 {
676 fopc = GNUNET_new(struct ForwardedOperationContext); 678 fopc = GNUNET_new (struct ForwardedOperationContext);
677 fopc->client = client; 679 fopc->client = client;
678 fopc->operation_id = GNUNET_ntohll(msg->operation_id); 680 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
679 fopc->type = OP_PEER_START; 681 fopc->type = OP_PEER_START;
680 fopc->opc = 682 fopc->opc =
681 GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. 683 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
682 slave->controller, 684 slave->controller,
683 fopc->operation_id, &msg->header, 685 fopc->operation_id, &msg->header,
684 &GST_forwarded_operation_reply_relay, 686 &
685 fopc); 687 GST_forwarded_operation_reply_relay,
686 fopc->timeout_task = 688 fopc);
687 GNUNET_SCHEDULER_add_delayed(GST_timeout, 689 fopc->timeout_task =
688 &GST_forwarded_operation_timeout, 690 GNUNET_SCHEDULER_add_delayed (GST_timeout,
689 fopc); 691 &GST_forwarded_operation_timeout,
690 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 692 fopc);
691 fopcq_tail, 693 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
692 fopc); 694 fopcq_tail,
693 GNUNET_SERVICE_client_continue(client); 695 fopc);
694 return; 696 GNUNET_SERVICE_client_continue (client);
695 } 697 return;
696 if (GNUNET_OK != start_peer(peer)) 698 }
697 { 699 if (GNUNET_OK != start_peer (peer))
698 GST_send_operation_fail_msg(client, GNUNET_ntohll(msg->operation_id), 700 {
699 "Failed to start"); 701 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
700 GNUNET_SERVICE_client_continue(client); 702 "Failed to start");
701 return; 703 GNUNET_SERVICE_client_continue (client);
702 } 704 return;
703 env = GNUNET_MQ_msg(reply, 705 }
704 GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); 706 env = GNUNET_MQ_msg (reply,
705 reply->event_type = htonl(GNUNET_TESTBED_ET_PEER_START); 707 GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT);
706 reply->host_id = htonl(GST_context->host_id); 708 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START);
709 reply->host_id = htonl (GST_context->host_id);
707 reply->peer_id = msg->peer_id; 710 reply->peer_id = msg->peer_id;
708 reply->operation_id = msg->operation_id; 711 reply->operation_id = msg->operation_id;
709 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), 712 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
710 env); 713 env);
711 GNUNET_SERVICE_client_continue(client); 714 GNUNET_SERVICE_client_continue (client);
712} 715}
713 716
714 717
@@ -719,8 +722,8 @@ handle_peer_start(void *cls,
719 * @param msg the actual message 722 * @param msg the actual message
720 */ 723 */
721void 724void
722handle_peer_stop(void *cls, 725handle_peer_stop (void *cls,
723 const struct GNUNET_TESTBED_PeerStopMessage *msg) 726 const struct GNUNET_TESTBED_PeerStopMessage *msg)
724{ 727{
725 struct GNUNET_SERVICE_Client *client = cls; 728 struct GNUNET_SERVICE_Client *client = cls;
726 struct GNUNET_MQ_Envelope *env; 729 struct GNUNET_MQ_Envelope *env;
@@ -729,69 +732,70 @@ handle_peer_stop(void *cls,
729 struct Peer *peer; 732 struct Peer *peer;
730 uint32_t peer_id; 733 uint32_t peer_id;
731 734
732 peer_id = ntohl(msg->peer_id); 735 peer_id = ntohl (msg->peer_id);
733 LOG(GNUNET_ERROR_TYPE_DEBUG, 736 LOG (GNUNET_ERROR_TYPE_DEBUG,
734 "Received PEER_STOP for peer %u\n", 737 "Received PEER_STOP for peer %u\n",
735 (unsigned int)peer_id); 738 (unsigned int) peer_id);
736 if (!VALID_PEER_ID(peer_id)) 739 if (! VALID_PEER_ID (peer_id))
737 { 740 {
738 GST_send_operation_fail_msg(client, 741 GST_send_operation_fail_msg (client,
739 GNUNET_ntohll(msg->operation_id), 742 GNUNET_ntohll (msg->operation_id),
740 "Peer not found"); 743 "Peer not found");
741 GNUNET_SERVICE_client_continue(client); 744 GNUNET_SERVICE_client_continue (client);
742 return; 745 return;
743 } 746 }
744 peer = GST_peer_list[peer_id]; 747 peer = GST_peer_list[peer_id];
745 if (GNUNET_YES == peer->is_remote) 748 if (GNUNET_YES == peer->is_remote)
746 { 749 {
747 LOG(GNUNET_ERROR_TYPE_DEBUG, 750 LOG (GNUNET_ERROR_TYPE_DEBUG,
748 "Forwarding PEER_STOP for peer %u\n", 751 "Forwarding PEER_STOP for peer %u\n",
749 (unsigned int)peer_id); 752 (unsigned int) peer_id);
750 fopc = GNUNET_new(struct ForwardedOperationContext); 753 fopc = GNUNET_new (struct ForwardedOperationContext);
751 fopc->client = client; 754 fopc->client = client;
752 fopc->operation_id = GNUNET_ntohll(msg->operation_id); 755 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
753 fopc->type = OP_PEER_STOP; 756 fopc->type = OP_PEER_STOP;
754 fopc->opc = 757 fopc->opc =
755 GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. 758 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
756 slave->controller, 759 slave->controller,
757 fopc->operation_id, 760 fopc->operation_id,
758 &msg->header, 761 &msg->header,
759 &GST_forwarded_operation_reply_relay, 762 &
760 fopc); 763 GST_forwarded_operation_reply_relay,
761 fopc->timeout_task = 764 fopc);
762 GNUNET_SCHEDULER_add_delayed(GST_timeout, 765 fopc->timeout_task =
763 &GST_forwarded_operation_timeout, 766 GNUNET_SCHEDULER_add_delayed (GST_timeout,
764 fopc); 767 &GST_forwarded_operation_timeout,
765 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 768 fopc);
766 fopcq_tail, 769 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
767 fopc); 770 fopcq_tail,
768 GNUNET_SERVICE_client_continue(client); 771 fopc);
769 return; 772 GNUNET_SERVICE_client_continue (client);
770 } 773 return;
771 if (GNUNET_OK != stop_peer(peer)) 774 }
772 { 775 if (GNUNET_OK != stop_peer (peer))
773 LOG(GNUNET_ERROR_TYPE_WARNING, 776 {
774 "Stopping peer %u failed\n", 777 LOG (GNUNET_ERROR_TYPE_WARNING,
775 (unsigned int)peer_id); 778 "Stopping peer %u failed\n",
776 GST_send_operation_fail_msg(client, 779 (unsigned int) peer_id);
777 GNUNET_ntohll(msg->operation_id), 780 GST_send_operation_fail_msg (client,
778 "Peer not running"); 781 GNUNET_ntohll (msg->operation_id),
779 GNUNET_SERVICE_client_continue(client); 782 "Peer not running");
780 return; 783 GNUNET_SERVICE_client_continue (client);
781 } 784 return;
782 LOG(GNUNET_ERROR_TYPE_DEBUG, 785 }
783 "Peer %u successfully stopped\n", 786 LOG (GNUNET_ERROR_TYPE_DEBUG,
784 (unsigned int)peer_id); 787 "Peer %u successfully stopped\n",
785 env = GNUNET_MQ_msg(reply, 788 (unsigned int) peer_id);
786 GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); 789 env = GNUNET_MQ_msg (reply,
787 reply->event_type = htonl(GNUNET_TESTBED_ET_PEER_STOP); 790 GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT);
788 reply->host_id = htonl(GST_context->host_id); 791 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP);
792 reply->host_id = htonl (GST_context->host_id);
789 reply->peer_id = msg->peer_id; 793 reply->peer_id = msg->peer_id;
790 reply->operation_id = msg->operation_id; 794 reply->operation_id = msg->operation_id;
791 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), 795 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
792 env); 796 env);
793 GNUNET_SERVICE_client_continue(client); 797 GNUNET_SERVICE_client_continue (client);
794 GNUNET_TESTING_peer_wait(peer->details.local.peer); 798 GNUNET_TESTING_peer_wait (peer->details.local.peer);
795} 799}
796 800
797 801
@@ -802,8 +806,9 @@ handle_peer_stop(void *cls,
802 * @param msg the actual message 806 * @param msg the actual message
803 */ 807 */
804void 808void
805handle_peer_get_config(void *cls, 809handle_peer_get_config (void *cls,
806 const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg) 810 const struct
811 GNUNET_TESTBED_PeerGetConfigurationMessage *msg)
807{ 812{
808 struct GNUNET_SERVICE_Client *client = cls; 813 struct GNUNET_SERVICE_Client *client = cls;
809 struct GNUNET_MQ_Envelope *env; 814 struct GNUNET_MQ_Envelope *env;
@@ -816,67 +821,68 @@ handle_peer_get_config(void *cls,
816 size_t xc_size; 821 size_t xc_size;
817 uint32_t peer_id; 822 uint32_t peer_id;
818 823
819 peer_id = ntohl(msg->peer_id); 824 peer_id = ntohl (msg->peer_id);
820 LOG_DEBUG("Received GET_CONFIG for peer %u\n", 825 LOG_DEBUG ("Received GET_CONFIG for peer %u\n",
821 (unsigned int)peer_id); 826 (unsigned int) peer_id);
822 if (!VALID_PEER_ID(peer_id)) 827 if (! VALID_PEER_ID (peer_id))
823 { 828 {
824 GST_send_operation_fail_msg(client, 829 GST_send_operation_fail_msg (client,
825 GNUNET_ntohll(msg->operation_id), 830 GNUNET_ntohll (msg->operation_id),
826 "Peer not found"); 831 "Peer not found");
827 GNUNET_SERVICE_client_continue(client); 832 GNUNET_SERVICE_client_continue (client);
828 return; 833 return;
829 } 834 }
830 peer = GST_peer_list[peer_id]; 835 peer = GST_peer_list[peer_id];
831 if (GNUNET_YES == peer->is_remote) 836 if (GNUNET_YES == peer->is_remote)
832 { 837 {
833 LOG_DEBUG("Forwarding PEER_GET_CONFIG for peer: %u\n", 838 LOG_DEBUG ("Forwarding PEER_GET_CONFIG for peer: %u\n",
834 (unsigned int)peer_id); 839 (unsigned int) peer_id);
835 fopc = GNUNET_new(struct ForwardedOperationContext); 840 fopc = GNUNET_new (struct ForwardedOperationContext);
836 fopc->client = client; 841 fopc->client = client;
837 fopc->operation_id = GNUNET_ntohll(msg->operation_id); 842 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
838 fopc->type = OP_PEER_INFO; 843 fopc->type = OP_PEER_INFO;
839 fopc->opc = 844 fopc->opc =
840 GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. 845 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
841 slave->controller, 846 slave->controller,
842 fopc->operation_id, 847 fopc->operation_id,
843 &msg->header, 848 &msg->header,
844 &GST_forwarded_operation_reply_relay, 849 &
845 fopc); 850 GST_forwarded_operation_reply_relay,
846 fopc->timeout_task = 851 fopc);
847 GNUNET_SCHEDULER_add_delayed(GST_timeout, 852 fopc->timeout_task =
848 &GST_forwarded_operation_timeout, 853 GNUNET_SCHEDULER_add_delayed (GST_timeout,
849 fopc); 854 &GST_forwarded_operation_timeout,
850 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 855 fopc);
851 fopcq_tail, 856 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
852 fopc); 857 fopcq_tail,
853 GNUNET_SERVICE_client_continue(client); 858 fopc);
854 return; 859 GNUNET_SERVICE_client_continue (client);
855 } 860 return;
856 LOG_DEBUG("Received PEER_GET_CONFIG for peer: %u\n", 861 }
857 peer_id); 862 LOG_DEBUG ("Received PEER_GET_CONFIG for peer: %u\n",
863 peer_id);
858 config = 864 config =
859 GNUNET_CONFIGURATION_serialize(GST_peer_list[peer_id]->details.local.cfg, 865 GNUNET_CONFIGURATION_serialize (GST_peer_list[peer_id]->details.local.cfg,
860 &c_size); 866 &c_size);
861 xc_size = GNUNET_TESTBED_compress_config_(config, 867 xc_size = GNUNET_TESTBED_compress_config_ (config,
862 c_size, 868 c_size,
863 &xconfig); 869 &xconfig);
864 GNUNET_free(config); 870 GNUNET_free (config);
865 env = GNUNET_MQ_msg_extra(reply, 871 env = GNUNET_MQ_msg_extra (reply,
866 xc_size, 872 xc_size,
867 GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION); 873 GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION);
868 reply->peer_id = msg->peer_id; 874 reply->peer_id = msg->peer_id;
869 reply->operation_id = msg->operation_id; 875 reply->operation_id = msg->operation_id;
870 GNUNET_TESTING_peer_get_identity(GST_peer_list[peer_id]->details.local.peer, 876 GNUNET_TESTING_peer_get_identity (GST_peer_list[peer_id]->details.local.peer,
871 &reply->peer_identity); 877 &reply->peer_identity);
872 reply->config_size = htons((uint16_t)c_size); 878 reply->config_size = htons ((uint16_t) c_size);
873 GNUNET_memcpy(&reply[1], 879 GNUNET_memcpy (&reply[1],
874 xconfig, 880 xconfig,
875 xc_size); 881 xc_size);
876 GNUNET_free(xconfig); 882 GNUNET_free (xconfig);
877 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), 883 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
878 env); 884 env);
879 GNUNET_SERVICE_client_continue(client); 885 GNUNET_SERVICE_client_continue (client);
880} 886}
881 887
882 888
@@ -884,10 +890,10 @@ handle_peer_get_config(void *cls,
884 * Cleans up the Peer reconfigure context list 890 * Cleans up the Peer reconfigure context list
885 */ 891 */
886void 892void
887GST_free_prcq() 893GST_free_prcq ()
888{ 894{
889 while (NULL != prc_head) 895 while (NULL != prc_head)
890 cleanup_prc(prc_head); 896 cleanup_prc (prc_head);
891} 897}
892 898
893 899
@@ -899,21 +905,21 @@ GST_free_prcq()
899 * @return error message (freshly allocated); NULL upon success 905 * @return error message (freshly allocated); NULL upon success
900 */ 906 */
901static char * 907static char *
902update_peer_config(struct Peer *peer, 908update_peer_config (struct Peer *peer,
903 struct GNUNET_CONFIGURATION_Handle *cfg) 909 struct GNUNET_CONFIGURATION_Handle *cfg)
904{ 910{
905 char *emsg; 911 char *emsg;
906 912
907 GNUNET_TESTING_peer_destroy(peer->details.local.peer); 913 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
908 GNUNET_CONFIGURATION_destroy(peer->details.local.cfg); 914 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
909 peer->details.local.cfg = cfg; 915 peer->details.local.cfg = cfg;
910 emsg = NULL; 916 emsg = NULL;
911 peer->details.local.peer 917 peer->details.local.peer
912 = GNUNET_TESTING_peer_configure(GST_context->system, 918 = GNUNET_TESTING_peer_configure (GST_context->system,
913 peer->details.local.cfg, 919 peer->details.local.cfg,
914 peer->id, 920 peer->id,
915 NULL /* Peer id */, 921 NULL /* Peer id */,
916 &emsg); 922 &emsg);
917 return emsg; 923 return emsg;
918} 924}
919 925
@@ -927,39 +933,39 @@ update_peer_config(struct Peer *peer,
927 * error 933 * error
928 */ 934 */
929static void 935static void
930prc_stop_cb(void *cls, 936prc_stop_cb (void *cls,
931 struct GNUNET_TESTING_Peer *p, 937 struct GNUNET_TESTING_Peer *p,
932 int success) 938 int success)
933{ 939{
934 struct PeerReconfigureContext *prc = cls; 940 struct PeerReconfigureContext *prc = cls;
935 struct Peer *peer; 941 struct Peer *peer;
936 char *emsg; 942 char *emsg;
937 943
938 GNUNET_assert(VALID_PEER_ID(prc->peer_id)); 944 GNUNET_assert (VALID_PEER_ID (prc->peer_id));
939 peer = GST_peer_list [prc->peer_id]; 945 peer = GST_peer_list [prc->peer_id];
940 GNUNET_assert(GNUNET_NO == peer->is_remote); 946 GNUNET_assert (GNUNET_NO == peer->is_remote);
941 emsg = update_peer_config(peer, prc->cfg); 947 emsg = update_peer_config (peer, prc->cfg);
942 prc->cfg = NULL; 948 prc->cfg = NULL;
943 prc->stopped = 1; 949 prc->stopped = 1;
944 if (NULL != emsg) 950 if (NULL != emsg)
945 { 951 {
946 GST_send_operation_fail_msg(prc->client, 952 GST_send_operation_fail_msg (prc->client,
947 prc->op_id, 953 prc->op_id,
948 emsg); 954 emsg);
949 goto cleanup; 955 goto cleanup;
950 } 956 }
951 if (GNUNET_OK != start_peer(peer)) 957 if (GNUNET_OK != start_peer (peer))
952 { 958 {
953 GST_send_operation_fail_msg(prc->client, 959 GST_send_operation_fail_msg (prc->client,
954 prc->op_id, 960 prc->op_id,
955 "Failed to start reconfigured peer"); 961 "Failed to start reconfigured peer");
956 goto cleanup; 962 goto cleanup;
957 } 963 }
958 GST_send_operation_success_msg(prc->client, 964 GST_send_operation_success_msg (prc->client,
959 prc->op_id); 965 prc->op_id);
960 966
961cleanup: 967cleanup:
962 cleanup_prc(prc); 968 cleanup_prc (prc);
963 return; 969 return;
964} 970}
965 971
@@ -972,8 +978,8 @@ cleanup:
972 * @return #GNUNET_OK if @a msg is well-formed 978 * @return #GNUNET_OK if @a msg is well-formed
973 */ 979 */
974int 980int
975check_peer_reconfigure(void *cls, 981check_peer_reconfigure (void *cls,
976 const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) 982 const struct GNUNET_TESTBED_PeerReconfigureMessage *msg)
977{ 983{
978 return GNUNET_OK; /* checked later */ 984 return GNUNET_OK; /* checked later */
979} 985}
@@ -988,8 +994,9 @@ check_peer_reconfigure(void *cls,
988 * @param msg the actual message 994 * @param msg the actual message
989 */ 995 */
990void 996void
991handle_peer_reconfigure(void *cls, 997handle_peer_reconfigure (void *cls,
992 const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) 998 const struct
999 GNUNET_TESTBED_PeerReconfigureMessage *msg)
993{ 1000{
994 struct GNUNET_SERVICE_Client *client = cls; 1001 struct GNUNET_SERVICE_Client *client = cls;
995 struct Peer *peer; 1002 struct Peer *peer;
@@ -1000,114 +1007,115 @@ handle_peer_reconfigure(void *cls,
1000 uint64_t op_id; 1007 uint64_t op_id;
1001 uint32_t peer_id; 1008 uint32_t peer_id;
1002 1009
1003 peer_id = ntohl(msg->peer_id); 1010 peer_id = ntohl (msg->peer_id);
1004 op_id = GNUNET_ntohll(msg->operation_id); 1011 op_id = GNUNET_ntohll (msg->operation_id);
1005 if (!VALID_PEER_ID(peer_id)) 1012 if (! VALID_PEER_ID (peer_id))
1006 { 1013 {
1007 GNUNET_break(0); 1014 GNUNET_break (0);
1008 GST_send_operation_fail_msg(client, 1015 GST_send_operation_fail_msg (client,
1009 op_id, 1016 op_id,
1010 "Peer not found"); 1017 "Peer not found");
1011 GNUNET_SERVICE_client_continue(client); 1018 GNUNET_SERVICE_client_continue (client);
1012 return; 1019 return;
1013 } 1020 }
1014 peer = GST_peer_list[peer_id]; 1021 peer = GST_peer_list[peer_id];
1015 if (GNUNET_YES == peer->is_remote) 1022 if (GNUNET_YES == peer->is_remote)
1016 { 1023 {
1017 LOG_DEBUG("Forwarding PEER_RECONFIGURE for peer: %u\n", peer_id); 1024 LOG_DEBUG ("Forwarding PEER_RECONFIGURE for peer: %u\n", peer_id);
1018 fopc = GNUNET_new(struct ForwardedOperationContext); 1025 fopc = GNUNET_new (struct ForwardedOperationContext);
1019 fopc->client = client; 1026 fopc->client = client;
1020 fopc->operation_id = op_id; 1027 fopc->operation_id = op_id;
1021 fopc->type = OP_PEER_RECONFIGURE; 1028 fopc->type = OP_PEER_RECONFIGURE;
1022 fopc->opc = 1029 fopc->opc =
1023 GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. 1030 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1024 slave->controller, 1031 slave->controller,
1025 fopc->operation_id, 1032 fopc->operation_id,
1026 &msg->header, 1033 &msg->header,
1027 &GST_forwarded_operation_reply_relay, 1034 &
1028 fopc); 1035 GST_forwarded_operation_reply_relay,
1029 fopc->timeout_task = 1036 fopc);
1030 GNUNET_SCHEDULER_add_delayed(GST_timeout, 1037 fopc->timeout_task =
1031 &GST_forwarded_operation_timeout, 1038 GNUNET_SCHEDULER_add_delayed (GST_timeout,
1032 fopc); 1039 &GST_forwarded_operation_timeout,
1033 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 1040 fopc);
1034 fopcq_tail, 1041 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
1035 fopc); 1042 fopcq_tail,
1036 GNUNET_SERVICE_client_continue(client); 1043 fopc);
1037 return; 1044 GNUNET_SERVICE_client_continue (client);
1038 } 1045 return;
1039 LOG_DEBUG("Received PEER_RECONFIGURE for peer %u\n", 1046 }
1040 (unsigned int)peer_id); 1047 LOG_DEBUG ("Received PEER_RECONFIGURE for peer %u\n",
1048 (unsigned int) peer_id);
1041 if (0 < peer->reference_cnt) 1049 if (0 < peer->reference_cnt)
1042 { 1050 {
1043 GNUNET_break(0); 1051 GNUNET_break (0);
1044 GST_send_operation_fail_msg(client, 1052 GST_send_operation_fail_msg (client,
1045 op_id, 1053 op_id,
1046 "Peer in use"); 1054 "Peer in use");
1047 GNUNET_SERVICE_client_continue(client); 1055 GNUNET_SERVICE_client_continue (client);
1048 return; 1056 return;
1049 } 1057 }
1050 if (GNUNET_YES == peer->destroy_flag) 1058 if (GNUNET_YES == peer->destroy_flag)
1051 { 1059 {
1052 GNUNET_break(0); 1060 GNUNET_break (0);
1053 GST_send_operation_fail_msg(client, 1061 GST_send_operation_fail_msg (client,
1054 op_id, 1062 op_id,
1055 "Peer is being destroyed"); 1063 "Peer is being destroyed");
1056 GNUNET_SERVICE_client_continue(client); 1064 GNUNET_SERVICE_client_continue (client);
1057 return; 1065 return;
1058 } 1066 }
1059 cfg = GNUNET_TESTBED_extract_config_(&msg->header); 1067 cfg = GNUNET_TESTBED_extract_config_ (&msg->header);
1060 if (NULL == cfg) 1068 if (NULL == cfg)
1061 { 1069 {
1062 GNUNET_break(0); 1070 GNUNET_break (0);
1063 GST_send_operation_fail_msg(client, 1071 GST_send_operation_fail_msg (client,
1064 op_id, 1072 op_id,
1065 "Compression error"); 1073 "Compression error");
1066 GNUNET_SERVICE_client_continue(client); 1074 GNUNET_SERVICE_client_continue (client);
1067 return; 1075 return;
1068 } 1076 }
1069 if (GNUNET_NO == peer->details.local.is_running) 1077 if (GNUNET_NO == peer->details.local.is_running)
1070 { 1078 {
1071 emsg = update_peer_config(peer, 1079 emsg = update_peer_config (peer,
1072 cfg); 1080 cfg);
1073 if (NULL != emsg) 1081 if (NULL != emsg)
1074 GST_send_operation_fail_msg(client, 1082 GST_send_operation_fail_msg (client,
1075 op_id, 1083 op_id,
1076 emsg); 1084 emsg);
1077 GST_send_operation_success_msg(client, 1085 GST_send_operation_success_msg (client,
1078 op_id); 1086 op_id);
1079 GNUNET_SERVICE_client_continue(client); 1087 GNUNET_SERVICE_client_continue (client);
1080 GNUNET_free_non_null(emsg); 1088 GNUNET_free_non_null (emsg);
1081 return; 1089 return;
1082 } 1090 }
1083 prc = GNUNET_new(struct PeerReconfigureContext); 1091 prc = GNUNET_new (struct PeerReconfigureContext);
1084 if (GNUNET_OK != 1092 if (GNUNET_OK !=
1085 GNUNET_TESTING_peer_stop_async(peer->details.local.peer, 1093 GNUNET_TESTING_peer_stop_async (peer->details.local.peer,
1086 &prc_stop_cb, 1094 &prc_stop_cb,
1087 prc)) 1095 prc))
1088 { 1096 {
1089 GNUNET_assert(0 < GNUNET_asprintf(&emsg, 1097 GNUNET_assert (0 < GNUNET_asprintf (&emsg,
1090 "Error trying to stop peer %u asynchronously\n", 1098 "Error trying to stop peer %u asynchronously\n",
1091 peer_id)); 1099 peer_id));
1092 LOG(GNUNET_ERROR_TYPE_ERROR, 1100 LOG (GNUNET_ERROR_TYPE_ERROR,
1093 "%s\n", 1101 "%s\n",
1094 emsg); 1102 emsg);
1095 GST_send_operation_fail_msg(client, 1103 GST_send_operation_fail_msg (client,
1096 op_id, 1104 op_id,
1097 emsg); 1105 emsg);
1098 GNUNET_SERVICE_client_continue(client); 1106 GNUNET_SERVICE_client_continue (client);
1099 GNUNET_free(prc); 1107 GNUNET_free (prc);
1100 GNUNET_free(emsg); 1108 GNUNET_free (emsg);
1101 return; 1109 return;
1102 } 1110 }
1103 prc->cfg = cfg; 1111 prc->cfg = cfg;
1104 prc->peer_id = peer_id; 1112 prc->peer_id = peer_id;
1105 prc->op_id = op_id; 1113 prc->op_id = op_id;
1106 prc->client = client; 1114 prc->client = client;
1107 GNUNET_CONTAINER_DLL_insert_tail(prc_head, 1115 GNUNET_CONTAINER_DLL_insert_tail (prc_head,
1108 prc_tail, 1116 prc_tail,
1109 prc); 1117 prc);
1110 GNUNET_SERVICE_client_continue(client); 1118 GNUNET_SERVICE_client_continue (client);
1111} 1119}
1112 1120
1113 1121
@@ -1115,10 +1123,10 @@ handle_peer_reconfigure(void *cls,
1115 * Frees the ManageServiceContext queue 1123 * Frees the ManageServiceContext queue
1116 */ 1124 */
1117void 1125void
1118GST_free_mctxq() 1126GST_free_mctxq ()
1119{ 1127{
1120 while (NULL != mctx_head) 1128 while (NULL != mctx_head)
1121 cleanup_mctx(mctx_head); 1129 cleanup_mctx (mctx_head);
1122} 1130}
1123 1131
1124 1132
@@ -1129,17 +1137,17 @@ GST_free_mctxq()
1129 * @return a string interpretation of the request status 1137 * @return a string interpretation of the request status
1130 */ 1138 */
1131static const char * 1139static const char *
1132arm_req_string(enum GNUNET_ARM_RequestStatus rs) 1140arm_req_string (enum GNUNET_ARM_RequestStatus rs)
1133{ 1141{
1134 switch (rs) 1142 switch (rs)
1135 { 1143 {
1136 case GNUNET_ARM_REQUEST_SENT_OK: 1144 case GNUNET_ARM_REQUEST_SENT_OK:
1137 return _("Message was sent successfully"); 1145 return _ ("Message was sent successfully");
1138 1146
1139 case GNUNET_ARM_REQUEST_DISCONNECTED: 1147 case GNUNET_ARM_REQUEST_DISCONNECTED:
1140 return _("We disconnected from ARM before we could send a request"); 1148 return _ ("We disconnected from ARM before we could send a request");
1141 } 1149 }
1142 return _("Unknown request status"); 1150 return _ ("Unknown request status");
1143} 1151}
1144 1152
1145 1153
@@ -1150,41 +1158,41 @@ arm_req_string(enum GNUNET_ARM_RequestStatus rs)
1150 * @return a string interpretation 1158 * @return a string interpretation
1151 */ 1159 */
1152static const char * 1160static const char *
1153arm_ret_string(enum GNUNET_ARM_Result result) 1161arm_ret_string (enum GNUNET_ARM_Result result)
1154{ 1162{
1155 switch (result) 1163 switch (result)
1156 { 1164 {
1157 case GNUNET_ARM_RESULT_STOPPED: 1165 case GNUNET_ARM_RESULT_STOPPED:
1158 return _("%s is stopped"); 1166 return _ ("%s is stopped");
1159 1167
1160 case GNUNET_ARM_RESULT_STARTING: 1168 case GNUNET_ARM_RESULT_STARTING:
1161 return _("%s is starting"); 1169 return _ ("%s is starting");
1162 1170
1163 case GNUNET_ARM_RESULT_STOPPING: 1171 case GNUNET_ARM_RESULT_STOPPING:
1164 return _("%s is stopping"); 1172 return _ ("%s is stopping");
1165 1173
1166 case GNUNET_ARM_RESULT_IS_STARTING_ALREADY: 1174 case GNUNET_ARM_RESULT_IS_STARTING_ALREADY:
1167 return _("%s is starting already"); 1175 return _ ("%s is starting already");
1168 1176
1169 case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY: 1177 case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY:
1170 return _("%s is stopping already"); 1178 return _ ("%s is stopping already");
1171 1179
1172 case GNUNET_ARM_RESULT_IS_STARTED_ALREADY: 1180 case GNUNET_ARM_RESULT_IS_STARTED_ALREADY:
1173 return _("%s is started already"); 1181 return _ ("%s is started already");
1174 1182
1175 case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY: 1183 case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY:
1176 return _("%s is stopped already"); 1184 return _ ("%s is stopped already");
1177 1185
1178 case GNUNET_ARM_RESULT_IS_NOT_KNOWN: 1186 case GNUNET_ARM_RESULT_IS_NOT_KNOWN:
1179 return _("%s service is not known to ARM"); 1187 return _ ("%s service is not known to ARM");
1180 1188
1181 case GNUNET_ARM_RESULT_START_FAILED: 1189 case GNUNET_ARM_RESULT_START_FAILED:
1182 return _("%s service failed to start"); 1190 return _ ("%s service failed to start");
1183 1191
1184 case GNUNET_ARM_RESULT_IN_SHUTDOWN: 1192 case GNUNET_ARM_RESULT_IN_SHUTDOWN:
1185 return _("%s service can't be started because ARM is shutting down"); 1193 return _ ("%s service can't be started because ARM is shutting down");
1186 } 1194 }
1187 return _("%.s Unknown result code."); 1195 return _ ("%.s Unknown result code.");
1188} 1196}
1189 1197
1190 1198
@@ -1199,9 +1207,9 @@ arm_ret_string(enum GNUNET_ARM_Result result)
1199 * @param result result of the operation 1207 * @param result result of the operation
1200 */ 1208 */
1201static void 1209static void
1202service_manage_result_cb(void *cls, 1210service_manage_result_cb (void *cls,
1203 enum GNUNET_ARM_RequestStatus rs, 1211 enum GNUNET_ARM_RequestStatus rs,
1204 enum GNUNET_ARM_Result result) 1212 enum GNUNET_ARM_Result result)
1205{ 1213{
1206 struct ManageServiceContext *mctx = cls; 1214 struct ManageServiceContext *mctx = cls;
1207 char *emsg; 1215 char *emsg;
@@ -1210,55 +1218,55 @@ service_manage_result_cb(void *cls,
1210 if (GNUNET_YES == mctx->expired) 1218 if (GNUNET_YES == mctx->expired)
1211 return; 1219 return;
1212 if (GNUNET_ARM_REQUEST_SENT_OK != rs) 1220 if (GNUNET_ARM_REQUEST_SENT_OK != rs)
1213 { 1221 {
1214 GNUNET_asprintf(&emsg, 1222 GNUNET_asprintf (&emsg,
1215 "Error communicating with Peer %u's ARM: %s", 1223 "Error communicating with Peer %u's ARM: %s",
1216 mctx->peer->id, 1224 mctx->peer->id,
1217 arm_req_string(rs)); 1225 arm_req_string (rs));
1218 goto ret; 1226 goto ret;
1219 } 1227 }
1220 if (1 == mctx->start) 1228 if (1 == mctx->start)
1221 goto service_start_check; 1229 goto service_start_check;
1222 if (!((GNUNET_ARM_RESULT_STOPPED == result) 1230 if (! ((GNUNET_ARM_RESULT_STOPPED == result)
1223 || (GNUNET_ARM_RESULT_STOPPING == result) 1231 || (GNUNET_ARM_RESULT_STOPPING == result)
1224 || (GNUNET_ARM_RESULT_IS_STOPPING_ALREADY == result) 1232 || (GNUNET_ARM_RESULT_IS_STOPPING_ALREADY == result)
1225 || (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY == result))) 1233 || (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY == result)))
1226 { 1234 {
1227 /* stopping a service failed */ 1235 /* stopping a service failed */
1228 GNUNET_asprintf(&emsg, 1236 GNUNET_asprintf (&emsg,
1229 arm_ret_string(result), 1237 arm_ret_string (result),
1230 mctx->service); 1238 mctx->service);
1231 goto ret; 1239 goto ret;
1232 } 1240 }
1233 /* service stopped successfully */ 1241 /* service stopped successfully */
1234 goto ret; 1242 goto ret;
1235 1243
1236service_start_check: 1244service_start_check:
1237 if (!((GNUNET_ARM_RESULT_STARTING == result) 1245 if (! ((GNUNET_ARM_RESULT_STARTING == result)
1238 || (GNUNET_ARM_RESULT_IS_STARTING_ALREADY == result) 1246 || (GNUNET_ARM_RESULT_IS_STARTING_ALREADY == result)
1239 || (GNUNET_ARM_RESULT_IS_STARTED_ALREADY == result))) 1247 || (GNUNET_ARM_RESULT_IS_STARTED_ALREADY == result)))
1240 { 1248 {
1241 /* starting a service failed */ 1249 /* starting a service failed */
1242 GNUNET_asprintf(&emsg, 1250 GNUNET_asprintf (&emsg,
1243 arm_ret_string(result), 1251 arm_ret_string (result),
1244 mctx->service); 1252 mctx->service);
1245 goto ret; 1253 goto ret;
1246 } 1254 }
1247 /* service started successfully */ 1255 /* service started successfully */
1248 1256
1249ret: 1257ret:
1250 if (NULL != emsg) 1258 if (NULL != emsg)
1251 { 1259 {
1252 LOG_DEBUG("%s\n", emsg); 1260 LOG_DEBUG ("%s\n", emsg);
1253 GST_send_operation_fail_msg(mctx->client, 1261 GST_send_operation_fail_msg (mctx->client,
1254 mctx->op_id, 1262 mctx->op_id,
1255 emsg); 1263 emsg);
1256 } 1264 }
1257 else 1265 else
1258 GST_send_operation_success_msg(mctx->client, 1266 GST_send_operation_success_msg (mctx->client,
1259 mctx->op_id); 1267 mctx->op_id);
1260 GNUNET_free_non_null(emsg); 1268 GNUNET_free_non_null (emsg);
1261 cleanup_mctx(mctx); 1269 cleanup_mctx (mctx);
1262} 1270}
1263 1271
1264 1272
@@ -1270,25 +1278,26 @@ ret:
1270 * @return #GNUNET_OK if @a msg is well-formed 1278 * @return #GNUNET_OK if @a msg is well-formed
1271 */ 1279 */
1272int 1280int
1273check_manage_peer_service(void *cls, 1281check_manage_peer_service (void *cls,
1274 const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) 1282 const struct
1283 GNUNET_TESTBED_ManagePeerServiceMessage *msg)
1275{ 1284{
1276 uint16_t msize; 1285 uint16_t msize;
1277 const char* service; 1286 const char*service;
1278 1287
1279 msize = ntohs(msg->header.size); 1288 msize = ntohs (msg->header.size);
1280 service = (const char *)&msg[1]; 1289 service = (const char *) &msg[1];
1281 if ('\0' != service[msize - sizeof 1290 if ('\0' != service[msize - sizeof
1282 (struct GNUNET_TESTBED_ManagePeerServiceMessage) - 1]) 1291 (struct GNUNET_TESTBED_ManagePeerServiceMessage) - 1])
1283 { 1292 {
1284 GNUNET_break_op(0); 1293 GNUNET_break_op (0);
1285 return GNUNET_SYSERR; 1294 return GNUNET_SYSERR;
1286 } 1295 }
1287 if (1 < msg->start) 1296 if (1 < msg->start)
1288 { 1297 {
1289 GNUNET_break_op(0); 1298 GNUNET_break_op (0);
1290 return GNUNET_SYSERR; 1299 return GNUNET_SYSERR;
1291 } 1300 }
1292 return GNUNET_OK; 1301 return GNUNET_OK;
1293} 1302}
1294 1303
@@ -1300,11 +1309,12 @@ check_manage_peer_service(void *cls,
1300 * @param msg the actual message 1309 * @param msg the actual message
1301 */ 1310 */
1302void 1311void
1303handle_manage_peer_service(void *cls, 1312handle_manage_peer_service (void *cls,
1304 const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) 1313 const struct
1314 GNUNET_TESTBED_ManagePeerServiceMessage *msg)
1305{ 1315{
1306 struct GNUNET_SERVICE_Client *client = cls; 1316 struct GNUNET_SERVICE_Client *client = cls;
1307 const char* service; 1317 const char*service;
1308 struct Peer *peer; 1318 struct Peer *peer;
1309 char *emsg; 1319 char *emsg;
1310 struct GNUNET_ARM_Handle *ah; 1320 struct GNUNET_ARM_Handle *ah;
@@ -1313,100 +1323,101 @@ handle_manage_peer_service(void *cls,
1313 uint64_t op_id; 1323 uint64_t op_id;
1314 uint32_t peer_id; 1324 uint32_t peer_id;
1315 1325
1316 service = (const char *)&msg[1]; 1326 service = (const char *) &msg[1];
1317 peer_id = ntohl(msg->peer_id); 1327 peer_id = ntohl (msg->peer_id);
1318 op_id = GNUNET_ntohll(msg->operation_id); 1328 op_id = GNUNET_ntohll (msg->operation_id);
1319 LOG_DEBUG("Received request to manage service %s on peer %u\n", 1329 LOG_DEBUG ("Received request to manage service %s on peer %u\n",
1320 service, (unsigned int)peer_id); 1330 service, (unsigned int) peer_id);
1321 if ((GST_peer_list_size <= peer_id) 1331 if ((GST_peer_list_size <= peer_id)
1322 || (NULL == (peer = GST_peer_list[peer_id]))) 1332 || (NULL == (peer = GST_peer_list[peer_id])))
1323 { 1333 {
1324 GNUNET_asprintf(&emsg, "Asked to manage service of a non existent peer " 1334 GNUNET_asprintf (&emsg, "Asked to manage service of a non existent peer "
1325 "with id: %u", peer_id); 1335 "with id: %u", peer_id);
1326 goto err_ret; 1336 goto err_ret;
1327 } 1337 }
1328 if (0 == strcasecmp("arm", service)) 1338 if (0 == strcasecmp ("arm", service))
1329 { 1339 {
1330 emsg = GNUNET_strdup("Cannot start/stop peer's ARM service. " 1340 emsg = GNUNET_strdup ("Cannot start/stop peer's ARM service. "
1331 "Use peer start/stop for that"); 1341 "Use peer start/stop for that");
1332 goto err_ret; 1342 goto err_ret;
1333 } 1343 }
1334 if (GNUNET_YES == peer->is_remote) 1344 if (GNUNET_YES == peer->is_remote)
1335 { 1345 {
1336 /* Forward the destory message to sub controller */ 1346 /* Forward the destory message to sub controller */
1337 fopc = GNUNET_new(struct ForwardedOperationContext); 1347 fopc = GNUNET_new (struct ForwardedOperationContext);
1338 fopc->client = client; 1348 fopc->client = client;
1339 fopc->cls = peer; 1349 fopc->cls = peer;
1340 fopc->type = OP_MANAGE_SERVICE; 1350 fopc->type = OP_MANAGE_SERVICE;
1341 fopc->operation_id = op_id; 1351 fopc->operation_id = op_id;
1342 fopc->opc = 1352 fopc->opc =
1343 GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. 1353 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1344 slave->controller, 1354 slave->controller,
1345 fopc->operation_id, 1355 fopc->operation_id,
1346 &msg->header, 1356 &msg->header,
1347 &GST_forwarded_operation_reply_relay, 1357 &
1348 fopc); 1358 GST_forwarded_operation_reply_relay,
1349 fopc->timeout_task = 1359 fopc);
1350 GNUNET_SCHEDULER_add_delayed(GST_timeout, 1360 fopc->timeout_task =
1351 &GST_forwarded_operation_timeout, 1361 GNUNET_SCHEDULER_add_delayed (GST_timeout,
1352 fopc); 1362 &GST_forwarded_operation_timeout,
1353 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 1363 fopc);
1354 fopcq_tail, 1364 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
1355 fopc); 1365 fopcq_tail,
1356 GNUNET_SERVICE_client_continue(client); 1366 fopc);
1357 return; 1367 GNUNET_SERVICE_client_continue (client);
1358 } 1368 return;
1369 }
1359 if (GNUNET_NO == peer->details.local.is_running) 1370 if (GNUNET_NO == peer->details.local.is_running)
1360 { 1371 {
1361 emsg = GNUNET_strdup("Peer not running\n"); 1372 emsg = GNUNET_strdup ("Peer not running\n");
1362 goto err_ret; 1373 goto err_ret;
1363 } 1374 }
1364 if ((0 != peer->reference_cnt) 1375 if ((0 != peer->reference_cnt)
1365 && ((0 == strcasecmp("core", service)) 1376 && ((0 == strcasecmp ("core", service))
1366 || (0 == strcasecmp("transport", service)))) 1377 || (0 == strcasecmp ("transport", service))))
1367 { 1378 {
1368 GNUNET_asprintf(&emsg, "Cannot stop %s service of peer with id: %u " 1379 GNUNET_asprintf (&emsg, "Cannot stop %s service of peer with id: %u "
1369 "since it is required by existing operations", 1380 "since it is required by existing operations",
1370 service, peer_id); 1381 service, peer_id);
1371 goto err_ret; 1382 goto err_ret;
1372 } 1383 }
1373 ah = GNUNET_ARM_connect(peer->details.local.cfg, NULL, NULL); 1384 ah = GNUNET_ARM_connect (peer->details.local.cfg, NULL, NULL);
1374 if (NULL == ah) 1385 if (NULL == ah)
1375 { 1386 {
1376 GNUNET_asprintf(&emsg, 1387 GNUNET_asprintf (&emsg,
1377 "Cannot connect to ARM service of peer with id: %u", 1388 "Cannot connect to ARM service of peer with id: %u",
1378 peer_id); 1389 peer_id);
1379 goto err_ret; 1390 goto err_ret;
1380 } 1391 }
1381 mctx = GNUNET_new(struct ManageServiceContext); 1392 mctx = GNUNET_new (struct ManageServiceContext);
1382 mctx->peer = peer; 1393 mctx->peer = peer;
1383 peer->reference_cnt++; 1394 peer->reference_cnt++;
1384 mctx->op_id = op_id; 1395 mctx->op_id = op_id;
1385 mctx->ah = ah; 1396 mctx->ah = ah;
1386 mctx->client = client; 1397 mctx->client = client;
1387 mctx->start = msg->start; 1398 mctx->start = msg->start;
1388 mctx->service = GNUNET_strdup(service); 1399 mctx->service = GNUNET_strdup (service);
1389 GNUNET_CONTAINER_DLL_insert_tail(mctx_head, 1400 GNUNET_CONTAINER_DLL_insert_tail (mctx_head,
1390 mctx_tail, 1401 mctx_tail,
1391 mctx); 1402 mctx);
1392 if (1 == mctx->start) 1403 if (1 == mctx->start)
1393 GNUNET_ARM_request_service_start(mctx->ah, 1404 GNUNET_ARM_request_service_start (mctx->ah,
1394 service, 1405 service,
1395 GNUNET_OS_INHERIT_STD_ERR, 1406 GNUNET_OS_INHERIT_STD_ERR,
1407 &service_manage_result_cb,
1408 mctx);
1409 else
1410 GNUNET_ARM_request_service_stop (mctx->ah, service,
1396 &service_manage_result_cb, 1411 &service_manage_result_cb,
1397 mctx); 1412 mctx);
1398 else 1413 GNUNET_SERVICE_client_continue (client);
1399 GNUNET_ARM_request_service_stop(mctx->ah, service,
1400 &service_manage_result_cb,
1401 mctx);
1402 GNUNET_SERVICE_client_continue(client);
1403 return; 1414 return;
1404 1415
1405err_ret: 1416err_ret:
1406 LOG(GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); 1417 LOG (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg);
1407 GST_send_operation_fail_msg(client, op_id, emsg); 1418 GST_send_operation_fail_msg (client, op_id, emsg);
1408 GNUNET_free(emsg); 1419 GNUNET_free (emsg);
1409 GNUNET_SERVICE_client_continue(client); 1420 GNUNET_SERVICE_client_continue (client);
1410} 1421}
1411 1422
1412 1423
@@ -1414,7 +1425,7 @@ err_ret:
1414 * Stops and destroys all peers 1425 * Stops and destroys all peers
1415 */ 1426 */
1416void 1427void
1417GST_destroy_peers() 1428GST_destroy_peers ()
1418{ 1429{
1419 struct Peer *peer; 1430 struct Peer *peer;
1420 unsigned int id; 1431 unsigned int id;
@@ -1422,34 +1433,34 @@ GST_destroy_peers()
1422 if (NULL == GST_peer_list) 1433 if (NULL == GST_peer_list)
1423 return; 1434 return;
1424 for (id = 0; id < GST_peer_list_size; id++) 1435 for (id = 0; id < GST_peer_list_size; id++)
1425 { 1436 {
1426 peer = GST_peer_list[id]; 1437 peer = GST_peer_list[id];
1427 if (NULL == peer) 1438 if (NULL == peer)
1428 continue; 1439 continue;
1429 /* If destroy flag is set it means that this peer should have been 1440 /* If destroy flag is set it means that this peer should have been
1430 * destroyed by a context which we destroy before */ 1441 * destroyed by a context which we destroy before */
1431 GNUNET_break(GNUNET_NO == peer->destroy_flag); 1442 GNUNET_break (GNUNET_NO == peer->destroy_flag);
1432 /* counter should be zero as we free all contexts before */ 1443 /* counter should be zero as we free all contexts before */
1433 GNUNET_break(0 == peer->reference_cnt); 1444 GNUNET_break (0 == peer->reference_cnt);
1434 if ((GNUNET_NO == peer->is_remote) && 1445 if ((GNUNET_NO == peer->is_remote) &&
1435 (GNUNET_YES == peer->details.local.is_running)) 1446 (GNUNET_YES == peer->details.local.is_running))
1436 GNUNET_TESTING_peer_kill(peer->details.local.peer); 1447 GNUNET_TESTING_peer_kill (peer->details.local.peer);
1437 } 1448 }
1438 for (id = 0; id < GST_peer_list_size; id++) 1449 for (id = 0; id < GST_peer_list_size; id++)
1450 {
1451 peer = GST_peer_list[id];
1452 if (NULL == peer)
1453 continue;
1454 if (GNUNET_NO == peer->is_remote)
1439 { 1455 {
1440 peer = GST_peer_list[id]; 1456 if (GNUNET_YES == peer->details.local.is_running)
1441 if (NULL == peer) 1457 GNUNET_TESTING_peer_wait (peer->details.local.peer);
1442 continue; 1458 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
1443 if (GNUNET_NO == peer->is_remote) 1459 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
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);
1451 } 1460 }
1452 GNUNET_free_non_null(GST_peer_list); 1461 GNUNET_free (peer);
1462 }
1463 GNUNET_free_non_null (GST_peer_list);
1453 GST_peer_list = NULL; 1464 GST_peer_list = NULL;
1454 GST_peer_list_size = 0; 1465 GST_peer_list_size = 0;
1455} 1466}
@@ -1464,34 +1475,34 @@ GST_destroy_peers()
1464 * @param msg the message to relay 1475 * @param msg the message to relay
1465 */ 1476 */
1466static void 1477static void
1467shutdown_peers_reply_cb(void *cls, 1478shutdown_peers_reply_cb (void *cls,
1468 const struct GNUNET_MessageHeader *msg) 1479 const struct GNUNET_MessageHeader *msg)
1469{ 1480{
1470 struct ForwardedOperationContext *fo_ctxt = cls; 1481 struct ForwardedOperationContext *fo_ctxt = cls;
1471 struct HandlerContext_ShutdownPeers *hc; 1482 struct HandlerContext_ShutdownPeers *hc;
1472 1483
1473 hc = fo_ctxt->cls; 1484 hc = fo_ctxt->cls;
1474 GNUNET_assert(0 < hc->nslaves); 1485 GNUNET_assert (0 < hc->nslaves);
1475 hc->nslaves--; 1486 hc->nslaves--;
1476 if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS != 1487 if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS !=
1477 ntohs(msg->type)) 1488 ntohs (msg->type))
1478 hc->timeout = GNUNET_YES; 1489 hc->timeout = GNUNET_YES;
1479 if (0 == hc->nslaves) 1490 if (0 == hc->nslaves)
1480 { 1491 {
1481 if (GNUNET_YES == hc->timeout) 1492 if (GNUNET_YES == hc->timeout)
1482 GST_send_operation_fail_msg(fo_ctxt->client, 1493 GST_send_operation_fail_msg (fo_ctxt->client,
1483 fo_ctxt->operation_id, 1494 fo_ctxt->operation_id,
1484 "Timeout at a slave controller"); 1495 "Timeout at a slave controller");
1485 else 1496 else
1486 GST_send_operation_success_msg(fo_ctxt->client, 1497 GST_send_operation_success_msg (fo_ctxt->client,
1487 fo_ctxt->operation_id); 1498 fo_ctxt->operation_id);
1488 GNUNET_free(hc); 1499 GNUNET_free (hc);
1489 hc = NULL; 1500 hc = NULL;
1490 } 1501 }
1491 GNUNET_CONTAINER_DLL_remove(fopcq_head, 1502 GNUNET_CONTAINER_DLL_remove (fopcq_head,
1492 fopcq_tail, 1503 fopcq_tail,
1493 fo_ctxt); 1504 fo_ctxt);
1494 GNUNET_free(fo_ctxt); 1505 GNUNET_free (fo_ctxt);
1495} 1506}
1496 1507
1497 1508
@@ -1502,8 +1513,8 @@ shutdown_peers_reply_cb(void *cls,
1502 * @param msg the actual message 1513 * @param msg the actual message
1503 */ 1514 */
1504void 1515void
1505handle_shutdown_peers(void *cls, 1516handle_shutdown_peers (void *cls,
1506 const struct GNUNET_TESTBED_ShutdownPeersMessage *msg) 1517 const struct GNUNET_TESTBED_ShutdownPeersMessage *msg)
1507{ 1518{
1508 struct GNUNET_SERVICE_Client *client = cls; 1519 struct GNUNET_SERVICE_Client *client = cls;
1509 struct HandlerContext_ShutdownPeers *hc; 1520 struct HandlerContext_ShutdownPeers *hc;
@@ -1512,48 +1523,48 @@ handle_shutdown_peers(void *cls,
1512 uint64_t op_id; 1523 uint64_t op_id;
1513 unsigned int cnt; 1524 unsigned int cnt;
1514 1525
1515 LOG_DEBUG("Received SHUTDOWN_PEERS\n"); 1526 LOG_DEBUG ("Received SHUTDOWN_PEERS\n");
1516 /* Stop and destroy all peers */ 1527 /* Stop and destroy all peers */
1517 GST_free_mctxq(); 1528 GST_free_mctxq ();
1518 GST_free_occq(); 1529 GST_free_occq ();
1519 GST_free_roccq(); 1530 GST_free_roccq ();
1520 GST_clear_fopcq(); 1531 GST_clear_fopcq ();
1521 /* Forward to all slaves which we have started */ 1532 /* Forward to all slaves which we have started */
1522 op_id = GNUNET_ntohll(msg->operation_id); 1533 op_id = GNUNET_ntohll (msg->operation_id);
1523 hc = GNUNET_new(struct HandlerContext_ShutdownPeers); 1534 hc = GNUNET_new (struct HandlerContext_ShutdownPeers);
1524 /* FIXME: have a better implementation where we track which slaves are 1535 /* FIXME: have a better implementation where we track which slaves are
1525 started by this controller */ 1536 started by this controller */
1526 for (cnt = 0; cnt < GST_slave_list_size; cnt++) 1537 for (cnt = 0; cnt < GST_slave_list_size; cnt++)
1527 { 1538 {
1528 slave = GST_slave_list[cnt]; 1539 slave = GST_slave_list[cnt];
1529 if (NULL == slave) 1540 if (NULL == slave)
1530 continue; 1541 continue;
1531 if (NULL == slave->controller_proc) /* We didn't start the slave */ 1542 if (NULL == slave->controller_proc) /* We didn't start the slave */
1532 continue; 1543 continue;
1533 LOG_DEBUG("Forwarding SHUTDOWN_PEERS\n"); 1544 LOG_DEBUG ("Forwarding SHUTDOWN_PEERS\n");
1534 hc->nslaves++; 1545 hc->nslaves++;
1535 fo_ctxt = GNUNET_new(struct ForwardedOperationContext); 1546 fo_ctxt = GNUNET_new (struct ForwardedOperationContext);
1536 fo_ctxt->client = client; 1547 fo_ctxt->client = client;
1537 fo_ctxt->operation_id = op_id; 1548 fo_ctxt->operation_id = op_id;
1538 fo_ctxt->cls = hc; 1549 fo_ctxt->cls = hc;
1539 fo_ctxt->type = OP_SHUTDOWN_PEERS; 1550 fo_ctxt->type = OP_SHUTDOWN_PEERS;
1540 fo_ctxt->opc = 1551 fo_ctxt->opc =
1541 GNUNET_TESTBED_forward_operation_msg_(slave->controller, 1552 GNUNET_TESTBED_forward_operation_msg_ (slave->controller,
1542 fo_ctxt->operation_id, 1553 fo_ctxt->operation_id,
1543 &msg->header, 1554 &msg->header,
1544 shutdown_peers_reply_cb, 1555 shutdown_peers_reply_cb,
1545 fo_ctxt); 1556 fo_ctxt);
1546 GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, 1557 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
1547 fopcq_tail, 1558 fopcq_tail,
1548 fo_ctxt); 1559 fo_ctxt);
1549 } 1560 }
1550 LOG_DEBUG("Shutting down peers\n"); 1561 LOG_DEBUG ("Shutting down peers\n");
1551 GST_destroy_peers(); 1562 GST_destroy_peers ();
1552 if (0 == hc->nslaves) 1563 if (0 == hc->nslaves)
1553 { 1564 {
1554 GST_send_operation_success_msg(client, 1565 GST_send_operation_success_msg (client,
1555 op_id); 1566 op_id);
1556 GNUNET_free(hc); 1567 GNUNET_free (hc);
1557 } 1568 }
1558 GNUNET_SERVICE_client_continue(client); 1569 GNUNET_SERVICE_client_continue (client);
1559} 1570}
diff --git a/src/testbed/gnunet-testbed-profiler.c b/src/testbed/gnunet-testbed-profiler.c
index e65ae6202..cfc6367fe 100644
--- a/src/testbed/gnunet-testbed-profiler.c
+++ b/src/testbed/gnunet-testbed-profiler.c
@@ -33,7 +33,7 @@
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 */
106static void 106static void
107do_shutdown(void *cls) 107do_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 */
127static void 127static void
128do_abort(void *cls) 128do_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 */
142static void 142static void
143print_overlay_links_summary() 143print_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,43 +159,43 @@ print_overlay_links_summary()
159 * @param event the controller event 159 * @param event the controller event
160 */ 160 */
161static void 161static void
162controller_event_cb(void *cls, 162controller_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)
166 { 170 {
167 case GNUNET_TESTBED_ET_OPERATION_FINISHED: 171 printf ("F");
168 /* Control reaches here when a peer linking operation fails */ 172 fflush (stdout);
169 if (NULL != event->details.operation_finished.emsg) 173 failed_links++;
170 { 174 if (++cont_fails > num_cont_fails)
171 printf("F"); 175 {
172 fflush(stdout); 176 printf ("\nAborting due to very high failure rate\n");
173 failed_links++; 177 print_overlay_links_summary ();
174 if (++cont_fails > num_cont_fails) 178 GNUNET_SCHEDULER_shutdown ();
175 { 179 return;
176 printf("\nAborting due to very high failure rate\n"); 180 }
177 print_overlay_links_summary(); 181 }
178 GNUNET_SCHEDULER_shutdown(); 182 break;
179 return; 183
180 } 184 case GNUNET_TESTBED_ET_CONNECT:
181 }
182 break;
183
184 case GNUNET_TESTBED_ET_CONNECT:
185 { 185 {
186 if (0 != cont_fails) 186 if (0 != cont_fails)
187 cont_fails--; 187 cont_fails--;
188 if (0 == established_links) 188 if (0 == established_links)
189 printf("Establishing links. Please wait\n"); 189 printf ("Establishing links. Please wait\n");
190 printf("."); 190 printf (".");
191 fflush(stdout); 191 fflush (stdout);
192 established_links++; 192 established_links++;
193 } 193 }
194 break; 194 break;
195 195
196 default: 196 default:
197 GNUNET_break(0); 197 GNUNET_break (0);
198 } 198 }
199} 199}
200 200
201 201
@@ -211,30 +211,30 @@ controller_event_cb(void *cls,
211 * @param links_failed the number of overlay link 211 * @param links_failed the number of overlay link
212 */ 212 */
213static void 213static void
214test_run(void *cls, 214test_run (void *cls,
215 struct GNUNET_TESTBED_RunHandle *h, 215 struct GNUNET_TESTBED_RunHandle *h,
216 unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, 216 unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers,
217 unsigned int links_succeeded, 217 unsigned int links_succeeded,
218 unsigned int links_failed) 218 unsigned int links_failed)
219{ 219{
220 result = GNUNET_OK; 220 result = GNUNET_OK;
221 fprintf(stdout, "\n"); 221 fprintf (stdout, "\n");
222 print_overlay_links_summary(); 222 print_overlay_links_summary ();
223 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); 223 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
224 if (noninteractive) 224 if (noninteractive)
225 { 225 {
226 GNUNET_SCHEDULER_cancel(abort_task); 226 GNUNET_SCHEDULER_cancel (abort_task);
227 abort_task = NULL; 227 abort_task = NULL;
228 return; 228 return;
229 } 229 }
230#if (!ENABLE_SUPERMUC) 230#if (! ENABLE_SUPERMUC)
231 fprintf(stdout, "Testbed running, waiting for keystroke to shut down\n"); 231 fprintf (stdout, "Testbed running, waiting for keystroke to shut down\n");
232 fflush(stdout); 232 fflush (stdout);
233 (void)getc(stdin); 233 (void) getc (stdin);
234#endif 234#endif
235 fprintf(stdout, "Shutting down. Please wait\n"); 235 fprintf (stdout, "Shutting down. Please wait\n");
236 fflush(stdout); 236 fflush (stdout);
237 GNUNET_SCHEDULER_shutdown(); 237 GNUNET_SCHEDULER_shutdown ();
238} 238}
239 239
240 240
@@ -247,25 +247,25 @@ test_run(void *cls,
247 * @param config configuration 247 * @param config configuration
248 */ 248 */
249static void 249static void
250run(void *cls, char *const *args, const char *cfgfile, 250run (void *cls, char *const *args, const char *cfgfile,
251 const struct GNUNET_CONFIGURATION_Handle *config) 251 const struct GNUNET_CONFIGURATION_Handle *config)
252{ 252{
253 if (0 == num_peers) 253 if (0 == num_peers)
254 { 254 {
255 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"),
256 num_peers); 256 num_peers);
257 return; 257 return;
258 } 258 }
259 cfg = GNUNET_CONFIGURATION_dup(config); 259 cfg = GNUNET_CONFIGURATION_dup (config);
260 event_mask = 0; 260 event_mask = 0;
261 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); 261 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
262 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); 262 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
263 GNUNET_TESTBED_run(hosts_file, cfg, num_peers, event_mask, 263 GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask,
264 &controller_event_cb, NULL, 264 &controller_event_cb, NULL,
265 &test_run, NULL); 265 &test_run, NULL);
266 abort_task = 266 abort_task =
267 GNUNET_SCHEDULER_add_shutdown(&do_abort, 267 GNUNET_SCHEDULER_add_shutdown (&do_abort,
268 NULL); 268 NULL);
269} 269}
270 270
271 271
@@ -275,47 +275,50 @@ run(void *cls, char *const *args, const char *cfgfile,
275 * @return 0 on success 275 * @return 0 on success
276 */ 276 */
277int 277int
278main(int argc, char *const *argv) 278main (int argc, char *const *argv)
279{ 279{
280 struct GNUNET_GETOPT_CommandLineOption options[] = { 280 struct GNUNET_GETOPT_CommandLineOption options[] = {
281 GNUNET_GETOPT_option_uint('p', 281 GNUNET_GETOPT_option_uint ('p',
282 "num-peers", 282 "num-peers",
283 "COUNT", 283 "COUNT",
284 gettext_noop("create COUNT number of peers"), 284 gettext_noop ("create COUNT number of peers"),
285 &num_peers), 285 &num_peers),
286 GNUNET_GETOPT_option_uint('e', 286 GNUNET_GETOPT_option_uint ('e',
287 "num-errors", 287 "num-errors",
288 "COUNT", 288 "COUNT",
289 gettext_noop("tolerate COUNT number of continious timeout failures"), 289 gettext_noop (
290 &num_cont_fails), 290 "tolerate COUNT number of continious timeout failures"),
291 GNUNET_GETOPT_option_flag('n', 291 &num_cont_fails),
292 "non-interactive", 292 GNUNET_GETOPT_option_flag ('n',
293 gettext_noop("run profiler in non-interactive mode where upon " 293 "non-interactive",
294 "testbed setup the profiler does not wait for a " 294 gettext_noop (
295 "keystroke but continues to run until a termination " 295 "run profiler in non-interactive mode where upon "
296 "signal is received"), 296 "testbed setup the profiler does not wait for a "
297 &noninteractive), 297 "keystroke but continues to run until a termination "
298#if !ENABLE_SUPERMUC 298 "signal is received"),
299 GNUNET_GETOPT_option_string('H', 299 &noninteractive),
300 "hosts", 300#if ! ENABLE_SUPERMUC
301 "FILENAME", 301 GNUNET_GETOPT_option_string ('H',
302 gettext_noop("name of the file with the login information for the testbed"), 302 "hosts",
303 &hosts_file), 303 "FILENAME",
304 gettext_noop (
305 "name of the file with the login information for the testbed"),
306 &hosts_file),
304#endif 307#endif
305 GNUNET_GETOPT_OPTION_END 308 GNUNET_GETOPT_OPTION_END
306 }; 309 };
307 const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]"; 310 const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]";
308 int ret; 311 int ret;
309 312
310 unsetenv("XDG_DATA_HOME"); 313 unsetenv ("XDG_DATA_HOME");
311 unsetenv("XDG_CONFIG_HOME"); 314 unsetenv ("XDG_CONFIG_HOME");
312 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 315 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
313 return 2; 316 return 2;
314 result = GNUNET_SYSERR; 317 result = GNUNET_SYSERR;
315 ret = 318 ret =
316 GNUNET_PROGRAM_run(argc, argv, "gnunet-testbed-profiler", binaryHelp, 319 GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-profiler", binaryHelp,
317 options, &run, NULL); 320 options, &run, NULL);
318 GNUNET_free((void *)argv); 321 GNUNET_free ((void *) argv);
319 if (GNUNET_OK != ret) 322 if (GNUNET_OK != ret)
320 return ret; 323 return ret;
321 if (GNUNET_OK != result) 324 if (GNUNET_OK != result)
diff --git a/src/testbed/gnunet_mpi_test.c b/src/testbed/gnunet_mpi_test.c
index 1c2696048..e0caf9676 100644
--- a/src/testbed/gnunet_mpi_test.c
+++ b/src/testbed/gnunet_mpi_test.c
@@ -6,10 +6,10 @@
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
11int 11int
12main(int argc, char *argv[]) 12main (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)
89 { 91 {
90 if (0 != code) 92 LOG (GNUNET_ERROR_TYPE_WARNING, "Child terminated abnormally\n");
91 { 93 ret = GNUNET_SYSERR;
92 LOG(GNUNET_ERROR_TYPE_WARNING, "Child terminated abnormally\n"); 94 GNUNET_break (0);
93 ret = GNUNET_SYSERR; 95 goto finalize;
94 GNUNET_break(0);
95 goto finalize;
96 }
97 } 96 }
97 }
98 else 98 else
99 GNUNET_break(0); 99 GNUNET_break (0);
100 100
101finalize: 101finalize:
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 b79c431c4..8b67523a1 100644
--- a/src/testbed/gnunet_testbed_mpi_spawn.c
+++ b/src/testbed/gnunet_testbed_mpi_spawn.c
@@ -7,13 +7,13 @@
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
@@ -58,65 +58,65 @@ static enum GNUNET_OS_ProcessStatusType child_status;
58/** 58/**
59 * Task to kill the child 59 * Task to kill the child
60 */ 60 */
61static struct GNUNET_SCHEDULER_Task * terminate_task_id; 61static struct GNUNET_SCHEDULER_Task *terminate_task_id;
62 62
63/** 63/**
64 * Task to kill the child 64 * Task to kill the child
65 */ 65 */
66static struct GNUNET_SCHEDULER_Task * child_death_task_id; 66static struct GNUNET_SCHEDULER_Task *child_death_task_id;
67 67
68/** 68/**
69 * The shutdown task 69 * The shutdown task
70 */ 70 */
71static void 71static void
72shutdown_task(void *cls) 72shutdown_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
92static void 92static void
93terminate_task(void *cls) 93terminate_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)
101 { 103 {
102 switch (hard_kill) 104 case 1:
103 { 105 case 2:
104 case 1: 106 LOG (GNUNET_ERROR_TYPE_WARNING,
105 case 2: 107 "%d more interrupts needed to send SIGKILL to the child\n",
106 LOG(GNUNET_ERROR_TYPE_WARNING, 108 3 - hard_kill);
107 "%d more interrupts needed to send SIGKILL to the child\n", 109 hard_kill++;
108 3 - hard_kill); 110 return;
109 hard_kill++; 111
110 return; 112 case 3:
111 113 GNUNET_break (0 == GNUNET_OS_process_kill (child, SIGKILL));
112 case 3: 114 return;
113 GNUNET_break(0 == GNUNET_OS_process_kill(child, SIGKILL));
114 return;
115 }
116 } 115 }
116 }
117 hard_kill++; 117 hard_kill++;
118 GNUNET_break(0 == GNUNET_OS_process_kill(child, GNUNET_TERM_SIG)); 118 GNUNET_break (0 == GNUNET_OS_process_kill (child, GNUNET_TERM_SIG));
119 LOG(GNUNET_ERROR_TYPE_INFO, _("Waiting for child to exit.\n")); 119 LOG (GNUNET_ERROR_TYPE_INFO, _ ("Waiting for child to exit.\n"));
120} 120}
121 121
122 122
@@ -127,46 +127,46 @@ terminate_task(void *cls)
127 * @param cls closure, NULL if we need to self-restart 127 * @param cls closure, NULL if we need to self-restart
128 */ 128 */
129static void 129static void
130child_death_task(void *cls) 130child_death_task (void *cls)
131{ 131{
132 const struct GNUNET_DISK_FileHandle *pr; 132 const struct GNUNET_DISK_FileHandle *pr;
133 char c[16]; 133 char c[16];
134 const struct GNUNET_SCHEDULER_TaskContext *tc; 134 const struct GNUNET_SCHEDULER_TaskContext *tc;
135 135
136 136
137 pr = GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ); 137 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
138 child_death_task_id = NULL; 138 child_death_task_id = NULL;
139 tc = GNUNET_SCHEDULER_get_task_context(); 139 tc = GNUNET_SCHEDULER_get_task_context ();
140 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) 140 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
141 { 141 {
142 child_death_task_id = 142 child_death_task_id =
143 GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, 143 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
144 pr, &child_death_task, NULL); 144 pr, &child_death_task, NULL);
145 return; 145 return;
146 } 146 }
147 /* consume the signal */ 147 /* consume the signal */
148 GNUNET_break(0 < GNUNET_DISK_file_read(pr, &c, sizeof(c))); 148 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof(c)));
149 LOG_DEBUG("Child died\n"); 149 LOG_DEBUG ("Child died\n");
150 GNUNET_SCHEDULER_cancel(terminate_task_id); 150 GNUNET_SCHEDULER_cancel (terminate_task_id);
151 terminate_task_id = NULL; 151 terminate_task_id = NULL;
152 GNUNET_assert(GNUNET_OK == GNUNET_OS_process_status(child, &child_status, 152 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_status (child, &child_status,
153 &child_exit_code)); 153 &child_exit_code));
154 GNUNET_OS_process_destroy(child); 154 GNUNET_OS_process_destroy (child);
155 child = NULL; 155 child = NULL;
156 GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); 156 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
157} 157}
158 158
159 159
160static void 160static void
161destroy_hosts(struct GNUNET_TESTBED_Host **hosts, unsigned int nhosts) 161destroy_hosts (struct GNUNET_TESTBED_Host **hosts, unsigned int nhosts)
162{ 162{
163 unsigned int host; 163 unsigned int host;
164 164
165 GNUNET_assert(NULL != hosts); 165 GNUNET_assert (NULL != hosts);
166 for (host = 0; host < nhosts; host++) 166 for (host = 0; host < nhosts; host++)
167 if (NULL != hosts[host]) 167 if (NULL != hosts[host])
168 GNUNET_TESTBED_host_destroy(hosts[host]); 168 GNUNET_TESTBED_host_destroy (hosts[host]);
169 GNUNET_free(hosts); 169 GNUNET_free (hosts);
170 hosts = NULL; 170 hosts = NULL;
171} 171}
172 172
@@ -177,7 +177,7 @@ destroy_hosts(struct GNUNET_TESTBED_Host **hosts, unsigned int nhosts)
177 * @param cls NULL 177 * @param cls NULL
178 */ 178 */
179static void 179static void
180run(void *cls) 180run (void *cls)
181{ 181{
182 struct GNUNET_TESTBED_Host **hosts; 182 struct GNUNET_TESTBED_Host **hosts;
183 const struct GNUNET_CONFIGURATION_Handle *null_cfg; 183 const struct GNUNET_CONFIGURATION_Handle *null_cfg;
@@ -186,78 +186,79 @@ run(void *cls)
186 size_t hostname_len; 186 size_t hostname_len;
187 unsigned int nhosts; 187 unsigned int nhosts;
188 188
189 null_cfg = GNUNET_CONFIGURATION_create(); 189 null_cfg = GNUNET_CONFIGURATION_create ();
190 nhosts = GNUNET_TESTBED_hosts_load_from_loadleveler(null_cfg, &hosts); 190 nhosts = GNUNET_TESTBED_hosts_load_from_loadleveler (null_cfg, &hosts);
191 if (0 == nhosts) 191 if (0 == nhosts)
192 { 192 {
193 GNUNET_break(0); 193 GNUNET_break (0);
194 ret = GNUNET_SYSERR; 194 ret = GNUNET_SYSERR;
195 return; 195 return;
196 } 196 }
197 hostname_len = GNUNET_OS_get_hostname_max_length(); 197 hostname_len = GNUNET_OS_get_hostname_max_length ();
198 hostname = GNUNET_malloc(hostname_len); 198 hostname = GNUNET_malloc (hostname_len);
199 if (0 != gethostname(hostname, hostname_len)) 199 if (0 != gethostname (hostname, hostname_len))
200 { 200 {
201 LOG(GNUNET_ERROR_TYPE_ERROR, "Cannot get hostname. Exiting\n"); 201 LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot get hostname. Exiting\n");
202 GNUNET_free(hostname); 202 GNUNET_free (hostname);
203 destroy_hosts(hosts, nhosts); 203 destroy_hosts (hosts, nhosts);
204 ret = GNUNET_SYSERR; 204 ret = GNUNET_SYSERR;
205 return; 205 return;
206 } 206 }
207 if (NULL == strstr(GNUNET_TESTBED_host_get_hostname(hosts[0]), hostname)) 207 if (NULL == strstr (GNUNET_TESTBED_host_get_hostname (hosts[0]), hostname))
208 { 208 {
209 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);
210 GNUNET_free(hostname); 210 GNUNET_free (hostname);
211 ret = GNUNET_OK; 211 ret = GNUNET_OK;
212 return; 212 return;
213 } 213 }
214 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);
215 GNUNET_free(hostname); 215 GNUNET_free (hostname);
216 destroy_hosts(hosts, nhosts); 216 destroy_hosts (hosts, nhosts);
217 tmpdir = getenv("TMPDIR"); 217 tmpdir = getenv ("TMPDIR");
218 if (NULL == tmpdir) 218 if (NULL == tmpdir)
219 tmpdir = getenv("TMP"); 219 tmpdir = getenv ("TMP");
220 if (NULL == tmpdir) 220 if (NULL == tmpdir)
221 tmpdir = getenv("TEMP"); 221 tmpdir = getenv ("TEMP");
222 if (NULL == tmpdir) 222 if (NULL == tmpdir)
223 tmpdir = "/tmp"; 223 tmpdir = "/tmp";
224 (void)GNUNET_asprintf(&fn, "%s/gnunet-testbed-spawn.lock", tmpdir); 224 (void) GNUNET_asprintf (&fn, "%s/gnunet-testbed-spawn.lock", tmpdir);
225 /* 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
226 else we exit */ 226 else we exit */
227 fh = open(fn, O_CREAT | O_EXCL | O_CLOEXEC, 227 fh = open (fn, O_CREAT | O_EXCL | O_CLOEXEC,
228 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); 228 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
229 if (-1 == fh) 229 if (-1 == fh)
230 {
231 if (EEXIST == errno)
230 { 232 {
231 if (EEXIST == errno) 233 LOG_DEBUG ("Lock file already created by other process. Exiting\n");
232 { 234 ret = GNUNET_OK;
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;
239 return; 235 return;
240 } 236 }
237 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "open");
238 ret = GNUNET_SYSERR;
239 return;
240 }
241 /* Spawn the new process here */ 241 /* Spawn the new process here */
242 LOG(GNUNET_ERROR_TYPE_INFO, _("Spawning process `%s'\n"), argv2[0]); 242 LOG (GNUNET_ERROR_TYPE_INFO, _ ("Spawning process `%s'\n"), argv2[0]);
243 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,
244 NULL, NULL, 244 NULL,
245 argv2[0], argv2); 245 NULL, NULL,
246 argv2[0], argv2);
246 if (NULL == child) 247 if (NULL == child)
247 { 248 {
248 GNUNET_break(0); 249 GNUNET_break (0);
249 ret = GNUNET_SYSERR; 250 ret = GNUNET_SYSERR;
250 GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); 251 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
251 return; 252 return;
252 } 253 }
253 ret = GNUNET_OK; 254 ret = GNUNET_OK;
254 terminate_task_id = 255 terminate_task_id =
255 GNUNET_SCHEDULER_add_shutdown(&terminate_task, NULL); 256 GNUNET_SCHEDULER_add_shutdown (&terminate_task, NULL);
256 child_death_task_id = 257 child_death_task_id =
257 GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, 258 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
258 GNUNET_DISK_pipe_handle(sigpipe, 259 GNUNET_DISK_pipe_handle (sigpipe,
259 GNUNET_DISK_PIPE_END_READ), 260 GNUNET_DISK_PIPE_END_READ),
260 &child_death_task, NULL); 261 &child_death_task, NULL);
261} 262}
262 263
263 264
@@ -265,15 +266,15 @@ run(void *cls)
265 * Signal handler called for SIGCHLD. 266 * Signal handler called for SIGCHLD.
266 */ 267 */
267static void 268static void
268sighandler_child_death() 269sighandler_child_death ()
269{ 270{
270 static char c; 271 static char c;
271 int old_errno = errno; /* back-up errno */ 272 int old_errno = errno; /* back-up errno */
272 273
273 GNUNET_break(1 == 274 GNUNET_break (1 ==
274 GNUNET_DISK_file_write(GNUNET_DISK_pipe_handle 275 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
275 (sigpipe, GNUNET_DISK_PIPE_END_WRITE), 276 (sigpipe, GNUNET_DISK_PIPE_END_WRITE),
276 &c, sizeof(c))); 277 &c, sizeof(c)));
277 errno = old_errno; /* restore errno */ 278 errno = old_errno; /* restore errno */
278} 279}
279 280
@@ -282,45 +283,45 @@ sighandler_child_death()
282 * Execution start point 283 * Execution start point
283 */ 284 */
284int 285int
285main(int argc, char *argv[]) 286main (int argc, char *argv[])
286{ 287{
287 struct GNUNET_SIGNAL_Context *shc_chld; 288 struct GNUNET_SIGNAL_Context *shc_chld;
288 unsigned int cnt; 289 unsigned int cnt;
289 290
290 ret = -1; 291 ret = -1;
291 if (argc < 2) 292 if (argc < 2)
292 { 293 {
293 printf("Need arguments: gnunet-testbed-mpi-spawn <cmd> <cmd_args>"); 294 printf ("Need arguments: gnunet-testbed-mpi-spawn <cmd> <cmd_args>");
294 return 1; 295 return 1;
295 } 296 }
296 if (GNUNET_OK != GNUNET_log_setup("gnunet-testbed-spawn", NULL, NULL)) 297 if (GNUNET_OK != GNUNET_log_setup ("gnunet-testbed-spawn", NULL, NULL))
297 { 298 {
298 GNUNET_break(0); 299 GNUNET_break (0);
299 return 1; 300 return 1;
300 } 301 }
301 if (NULL == (sigpipe = GNUNET_DISK_pipe(GNUNET_NO, GNUNET_NO, 302 if (NULL == (sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO,
302 GNUNET_NO, GNUNET_NO))) 303 GNUNET_NO, GNUNET_NO)))
303 { 304 {
304 GNUNET_break(0); 305 GNUNET_break (0);
305 ret = GNUNET_SYSERR; 306 ret = GNUNET_SYSERR;
306 return 1; 307 return 1;
307 } 308 }
308 shc_chld = 309 shc_chld =
309 GNUNET_SIGNAL_handler_install(GNUNET_SIGCHLD, &sighandler_child_death); 310 GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
310 if (NULL == shc_chld) 311 if (NULL == shc_chld)
311 { 312 {
312 LOG(GNUNET_ERROR_TYPE_ERROR, "Cannot install a signal handler\n"); 313 LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot install a signal handler\n");
313 return 1; 314 return 1;
314 } 315 }
315 argv2 = GNUNET_malloc(sizeof(char *) * argc); 316 argv2 = GNUNET_malloc (sizeof(char *) * argc);
316 for (cnt = 1; cnt < argc; cnt++) 317 for (cnt = 1; cnt < argc; cnt++)
317 argv2[cnt - 1] = argv[cnt]; 318 argv2[cnt - 1] = argv[cnt];
318 GNUNET_SCHEDULER_run(run, NULL); 319 GNUNET_SCHEDULER_run (run, NULL);
319 GNUNET_free(argv2); 320 GNUNET_free (argv2);
320 GNUNET_SIGNAL_handler_uninstall(shc_chld); 321 GNUNET_SIGNAL_handler_uninstall (shc_chld);
321 shc_chld = NULL; 322 shc_chld = NULL;
322 GNUNET_DISK_pipe_close(sigpipe); 323 GNUNET_DISK_pipe_close (sigpipe);
323 GNUNET_free_non_null(fn); 324 GNUNET_free_non_null (fn);
324 if (GNUNET_OK != ret) 325 if (GNUNET_OK != ret)
325 return ret; 326 return ret;
326 return 0; 327 return 0;
diff --git a/src/testbed/test_gnunet_helper_testbed.c b/src/testbed/test_gnunet_helper_testbed.c
index 8bf1fd7ca..caf33c71b 100644
--- a/src/testbed/test_gnunet_helper_testbed.c
+++ b/src/testbed/test_gnunet_helper_testbed.c
@@ -37,7 +37,7 @@
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/**
@@ -58,12 +58,12 @@ static struct GNUNET_HELPER_SendHandle *shandle;
58/** 58/**
59 * Abort task identifier 59 * Abort task identifier
60 */ 60 */
61static struct GNUNET_SCHEDULER_Task * abort_task; 61static struct GNUNET_SCHEDULER_Task *abort_task;
62 62
63/** 63/**
64 * Shutdown task identifier 64 * Shutdown task identifier
65 */ 65 */
66static struct GNUNET_SCHEDULER_Task * shutdown_task; 66static struct GNUNET_SCHEDULER_Task *shutdown_task;
67 67
68/** 68/**
69 * Configuratin handler 69 * Configuratin handler
@@ -82,15 +82,15 @@ static int result;
82 * @param cls NULL 82 * @param cls NULL
83 */ 83 */
84static void 84static void
85do_shutdown(void *cls) 85do_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 */
102static void 102static void
103do_abort(void *cls) 103do_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 */
123static void 123static void
124cont_cb(void *cls, 124cont_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 */
145static int 145static int
146mst_cb(void *cls, 146mst_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 */
185static void 185static void
186exp_cb(void *cls) 186exp_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 */
201static void 201static void
202run(void *cls, char *const *args, const char *cfgfile, 202run (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 */
238int 238int
239main(int argc, char **argv) 239main (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 37dc362ea..ad71aa35e 100644
--- a/src/testbed/test_testbed_api.c
+++ b/src/testbed/test_testbed_api.c
@@ -34,13 +34,13 @@
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,7 +101,8 @@ static int result;
101/** 101/**
102 * Enumeration of sub testcases 102 * Enumeration of sub testcases
103 */ 103 */
104enum Test { 104enum Test
105{
105 /** 106 /**
106 * Test cases which are not covered by the below ones 107 * Test cases which are not covered by the below ones
107 */ 108 */
@@ -135,23 +136,23 @@ static enum Test sub_test;
135 * @param tc the task context 136 * @param tc the task context
136 */ 137 */
137static void 138static void
138do_shutdown(void *cls) 139do_shutdown (void *cls)
139{ 140{
140 LOG(GNUNET_ERROR_TYPE_DEBUG, "Shutting down...\n"); 141 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down...\n");
141 if (NULL != abort_task) 142 if (NULL != abort_task)
142 GNUNET_SCHEDULER_cancel(abort_task); 143 GNUNET_SCHEDULER_cancel (abort_task);
143 if (NULL != reg_handle) 144 if (NULL != reg_handle)
144 GNUNET_TESTBED_cancel_registration(reg_handle); 145 GNUNET_TESTBED_cancel_registration (reg_handle);
145 if (NULL != controller) 146 if (NULL != controller)
146 GNUNET_TESTBED_controller_disconnect(controller); 147 GNUNET_TESTBED_controller_disconnect (controller);
147 if (NULL != cfg) 148 if (NULL != cfg)
148 GNUNET_CONFIGURATION_destroy(cfg); 149 GNUNET_CONFIGURATION_destroy (cfg);
149 if (NULL != cp) 150 if (NULL != cp)
150 GNUNET_TESTBED_controller_stop(cp); 151 GNUNET_TESTBED_controller_stop (cp);
151 if (NULL != neighbour) 152 if (NULL != neighbour)
152 GNUNET_TESTBED_host_destroy(neighbour); 153 GNUNET_TESTBED_host_destroy (neighbour);
153 if (NULL != host) 154 if (NULL != host)
154 GNUNET_TESTBED_host_destroy(host); 155 GNUNET_TESTBED_host_destroy (host);
155} 156}
156 157
157 158
@@ -159,15 +160,15 @@ do_shutdown(void *cls)
159 * shortcut to exit during failure 160 * shortcut to exit during failure
160 */ 161 */
161#define FAIL_TEST(cond, ret) do { \ 162#define FAIL_TEST(cond, ret) do { \
162 if (!(cond)) { \ 163 if (! (cond)) { \
163 GNUNET_break(0); \ 164 GNUNET_break (0); \
164 if (NULL != abort_task) \ 165 if (NULL != abort_task) \
165 GNUNET_SCHEDULER_cancel (abort_task); \ 166 GNUNET_SCHEDULER_cancel (abort_task); \
166 abort_task = NULL; \ 167 abort_task = NULL; \
167 GNUNET_SCHEDULER_add_now(do_shutdown, NULL); \ 168 GNUNET_SCHEDULER_add_now (do_shutdown, NULL); \
168 ret; \ 169 ret; \
169 } \ 170 } \
170 } while (0) 171} while (0)
171 172
172 173
173/** 174/**
@@ -177,11 +178,11 @@ do_shutdown(void *cls)
177 * @param tc the task context 178 * @param tc the task context
178 */ 179 */
179static void 180static void
180do_abort(void *cls) 181do_abort (void *cls)
181{ 182{
182 LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); 183 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
183 abort_task = NULL; 184 abort_task = NULL;
184 do_shutdown(cls); 185 do_shutdown (cls);
185} 186}
186 187
187 188
@@ -196,13 +197,13 @@ do_abort(void *cls)
196 * @return service handle to return in 'op_result', NULL on error 197 * @return service handle to return in 'op_result', NULL on error
197 */ 198 */
198static void * 199static void *
199arm_connect_adapter(void *cls, 200arm_connect_adapter (void *cls,
200 const struct GNUNET_CONFIGURATION_Handle *cfg) 201 const struct GNUNET_CONFIGURATION_Handle *cfg)
201{ 202{
202 FAIL_TEST(NULL == cls, return NULL); 203 FAIL_TEST (NULL == cls, return NULL);
203 FAIL_TEST(OTHER == sub_test, return NULL); 204 FAIL_TEST (OTHER == sub_test, return NULL);
204 sub_test = PEER_SERVICE_CONNECT; 205 sub_test = PEER_SERVICE_CONNECT;
205 arm_handle = GNUNET_ARM_connect(cfg, NULL, NULL); 206 arm_handle = GNUNET_ARM_connect (cfg, NULL, NULL);
206 return arm_handle; 207 return arm_handle;
207} 208}
208 209
@@ -215,17 +216,17 @@ arm_connect_adapter(void *cls,
215 * @param op_result service handle returned from the connect adapter 216 * @param op_result service handle returned from the connect adapter
216 */ 217 */
217static void 218static void
218arm_disconnect_adapter(void *cls, 219arm_disconnect_adapter (void *cls,
219 void *op_result) 220 void *op_result)
220{ 221{
221 FAIL_TEST(NULL != op_result, return ); 222 FAIL_TEST (NULL != op_result, return );
222 FAIL_TEST(op_result == arm_handle, return ); 223 FAIL_TEST (op_result == arm_handle, return );
223 GNUNET_ARM_disconnect(arm_handle); 224 GNUNET_ARM_disconnect (arm_handle);
224 arm_handle = NULL; 225 arm_handle = NULL;
225 FAIL_TEST(PEER_SERVICE_CONNECT == sub_test, return ); 226 FAIL_TEST (PEER_SERVICE_CONNECT == sub_test, return );
226 FAIL_TEST(NULL != operation, return ); 227 FAIL_TEST (NULL != operation, return );
227 operation = GNUNET_TESTBED_peer_stop(NULL, peer, NULL, NULL); 228 operation = GNUNET_TESTBED_peer_stop (NULL, peer, NULL, NULL);
228 FAIL_TEST(NULL != operation, return ); 229 FAIL_TEST (NULL != operation, return );
229} 230}
230 231
231 232
@@ -239,25 +240,25 @@ arm_disconnect_adapter(void *cls,
239 * operation has executed successfully. 240 * operation has executed successfully.
240 */ 241 */
241static void 242static void
242service_connect_comp_cb(void *cls, 243service_connect_comp_cb (void *cls,
243 struct GNUNET_TESTBED_Operation *op, 244 struct GNUNET_TESTBED_Operation *op,
244 void *ca_result, 245 void *ca_result,
245 const char *emsg) 246 const char *emsg)
246{ 247{
247 switch (sub_test) 248 switch (sub_test)
248 { 249 {
249 case PEER_SERVICE_CONNECT: 250 case PEER_SERVICE_CONNECT:
250 FAIL_TEST(operation == op, return ); 251 FAIL_TEST (operation == op, return );
251 FAIL_TEST(NULL == emsg, return ); 252 FAIL_TEST (NULL == emsg, return );
252 FAIL_TEST(NULL == cls, return ); 253 FAIL_TEST (NULL == cls, return );
253 FAIL_TEST(ca_result == arm_handle, return ); 254 FAIL_TEST (ca_result == arm_handle, return );
254 GNUNET_TESTBED_operation_done(operation); /* This results in call to 255 GNUNET_TESTBED_operation_done (operation); /* This results in call to
255 * disconnect adapter */ 256 * disconnect adapter */
256 break; 257 break;
257 258
258 default: 259 default:
259 FAIL_TEST(0, return ); 260 FAIL_TEST (0, return );
260 } 261 }
261} 262}
262 263
263 264
@@ -272,28 +273,28 @@ service_connect_comp_cb(void *cls,
272 * operation is successfull 273 * operation is successfull
273 */ 274 */
274static void 275static void
275peerinfo_cb(void *cb_cls, 276peerinfo_cb (void *cb_cls,
276 struct GNUNET_TESTBED_Operation *op, 277 struct GNUNET_TESTBED_Operation *op,
277 const struct GNUNET_TESTBED_PeerInformation *pinfo, 278 const struct GNUNET_TESTBED_PeerInformation *pinfo,
278 const char *emsg) 279 const char *emsg)
279{ 280{
280 switch (sub_test) 281 switch (sub_test)
281 { 282 {
282 case PEER_GETCONFIG: 283 case PEER_GETCONFIG:
283 FAIL_TEST(NULL != pinfo, return ); 284 FAIL_TEST (NULL != pinfo, return );
284 FAIL_TEST(NULL == emsg, return ); 285 FAIL_TEST (NULL == emsg, return );
285 FAIL_TEST(NULL == cb_cls, return ); 286 FAIL_TEST (NULL == cb_cls, return );
286 FAIL_TEST(operation == op, return ); 287 FAIL_TEST (operation == op, return );
287 FAIL_TEST(GNUNET_TESTBED_PIT_CONFIGURATION == pinfo->pit, return ); 288 FAIL_TEST (GNUNET_TESTBED_PIT_CONFIGURATION == pinfo->pit, return );
288 FAIL_TEST(NULL != pinfo->result.cfg, return ); 289 FAIL_TEST (NULL != pinfo->result.cfg, return );
289 sub_test = PEER_DESTROY; 290 sub_test = PEER_DESTROY;
290 GNUNET_TESTBED_operation_done(operation); 291 GNUNET_TESTBED_operation_done (operation);
291 operation = GNUNET_TESTBED_peer_destroy(peer); 292 operation = GNUNET_TESTBED_peer_destroy (peer);
292 break; 293 break;
293 294
294 default: 295 default:
295 FAIL_TEST(0, return ); 296 FAIL_TEST (0, return );
296 } 297 }
297} 298}
298 299
299 300
@@ -305,65 +306,66 @@ peerinfo_cb(void *cb_cls,
305 * @param event information about the event 306 * @param event information about the event
306 */ 307 */
307static void 308static void
308controller_cb(void *cls, 309controller_cb (void *cls,
309 const struct GNUNET_TESTBED_EventInformation *event) 310 const struct GNUNET_TESTBED_EventInformation *event)
310{ 311{
311 switch (event->type) 312 switch (event->type)
313 {
314 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
315 switch (sub_test)
312 { 316 {
313 case GNUNET_TESTBED_ET_OPERATION_FINISHED: 317 case PEER_DESTROY:
314 switch (sub_test) 318 FAIL_TEST (event->op == operation, return );
315 { 319 FAIL_TEST (NULL == event->op_cls, return );
316 case PEER_DESTROY: 320 FAIL_TEST (NULL == event->details.operation_finished.emsg, return );
317 FAIL_TEST(event->op == operation, return ); 321 FAIL_TEST (NULL == event->details.operation_finished.generic, return );
318 FAIL_TEST(NULL == event->op_cls, return ); 322 GNUNET_TESTBED_operation_done (operation);
319 FAIL_TEST(NULL == event->details.operation_finished.emsg, return ); 323 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
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 }
337 break; 324 break;
338 325
339 case GNUNET_TESTBED_ET_PEER_START: 326 case PEER_SERVICE_CONNECT:
340 FAIL_TEST(event->details.peer_start.host == host, return ); 327 FAIL_TEST (event->op == operation, return );
341 FAIL_TEST(event->details.peer_start.peer == peer, return ); 328 FAIL_TEST (NULL == event->op_cls, return );
342 FAIL_TEST(OTHER == sub_test, return ); 329 FAIL_TEST (NULL == event->details.operation_finished.emsg, return );
343 GNUNET_TESTBED_operation_done(operation); 330 FAIL_TEST (NULL != arm_handle, return );
344 operation = 331 FAIL_TEST (event->details.operation_finished.generic == arm_handle,
345 GNUNET_TESTBED_service_connect(NULL, peer, "dht", 332 return );
346 &service_connect_comp_cb, NULL,
347 &arm_connect_adapter,
348 &arm_disconnect_adapter, NULL);
349 FAIL_TEST(NULL != operation, return );
350 break;
351
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);
362 break; 333 break;
363 334
364 default: 335 default:
365 FAIL_TEST(0, return ); /* We should never reach this state */ 336 FAIL_TEST (0, return );
337 break;
366 } 338 }
339 break;
340
341 case GNUNET_TESTBED_ET_PEER_START:
342 FAIL_TEST (event->details.peer_start.host == host, return );
343 FAIL_TEST (event->details.peer_start.peer == peer, return );
344 FAIL_TEST (OTHER == sub_test, return );
345 GNUNET_TESTBED_operation_done (operation);
346 operation =
347 GNUNET_TESTBED_service_connect (NULL, peer, "dht",
348 &service_connect_comp_cb, NULL,
349 &arm_connect_adapter,
350 &arm_disconnect_adapter, NULL);
351 FAIL_TEST (NULL != operation, return );
352 break;
353
354 case GNUNET_TESTBED_ET_PEER_STOP:
355 FAIL_TEST (event->details.peer_stop.peer == peer, return );
356 FAIL_TEST (PEER_SERVICE_CONNECT == sub_test, return );
357 result = GNUNET_YES;
358 sub_test = PEER_GETCONFIG;
359 GNUNET_TESTBED_operation_done (operation);
360 operation =
361 GNUNET_TESTBED_peer_get_information (peer,
362 GNUNET_TESTBED_PIT_CONFIGURATION,
363 &peerinfo_cb, NULL);
364 break;
365
366 default:
367 FAIL_TEST (0, return ); /* We should never reach this state */
368 }
367} 369}
368 370
369 371
@@ -377,22 +379,22 @@ controller_cb(void *cls,
377 * @param emsg NULL if peer is not NULL; else MAY contain the error description 379 * @param emsg NULL if peer is not NULL; else MAY contain the error description
378 */ 380 */
379static void 381static void
380peer_create_cb(void *cls, 382peer_create_cb (void *cls,
381 struct GNUNET_TESTBED_Peer *peer, 383 struct GNUNET_TESTBED_Peer *peer,
382 const char *emsg) 384 const char *emsg)
383{ 385{
384 struct GNUNET_TESTBED_Peer **peer_ptr; 386 struct GNUNET_TESTBED_Peer **peer_ptr;
385 387
386 peer_ptr = cls; 388 peer_ptr = cls;
387 FAIL_TEST(NULL != peer, return ); 389 FAIL_TEST (NULL != peer, return );
388 FAIL_TEST(NULL != peer_ptr, return ); 390 FAIL_TEST (NULL != peer_ptr, return );
389 *peer_ptr = peer; 391 *peer_ptr = peer;
390 GNUNET_TESTBED_operation_done(operation); 392 GNUNET_TESTBED_operation_done (operation);
391 operation = GNUNET_TESTBED_peer_start(NULL, 393 operation = GNUNET_TESTBED_peer_start (NULL,
392 peer, 394 peer,
393 NULL, 395 NULL,
394 NULL); 396 NULL);
395 FAIL_TEST(NULL != operation, return ); 397 FAIL_TEST (NULL != operation, return );
396} 398}
397 399
398 400
@@ -403,18 +405,18 @@ peer_create_cb(void *cls,
403 * @param emsg the error message; NULL if host registration is successful 405 * @param emsg the error message; NULL if host registration is successful
404 */ 406 */
405static void 407static void
406registration_comp(void *cls, 408registration_comp (void *cls,
407 const char *emsg) 409 const char *emsg)
408{ 410{
409 FAIL_TEST(cls == neighbour, return ); 411 FAIL_TEST (cls == neighbour, return );
410 reg_handle = NULL; 412 reg_handle = NULL;
411 operation = 413 operation =
412 GNUNET_TESTBED_peer_create(controller, 414 GNUNET_TESTBED_peer_create (controller,
413 host, 415 host,
414 cfg, 416 cfg,
415 &peer_create_cb, 417 &peer_create_cb,
416 &peer); 418 &peer);
417 FAIL_TEST(NULL != operation, return ); 419 FAIL_TEST (NULL != operation, return );
418} 420}
419 421
420 422
@@ -428,33 +430,33 @@ registration_comp(void *cls,
428 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case 430 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
429 */ 431 */
430static void 432static void
431status_cb(void *cls, 433status_cb (void *cls,
432 const struct GNUNET_CONFIGURATION_Handle *cfg_, 434 const struct GNUNET_CONFIGURATION_Handle *cfg_,
433 int status) 435 int status)
434{ 436{
435 uint64_t event_mask; 437 uint64_t event_mask;
436 438
437 if (GNUNET_OK != status) 439 if (GNUNET_OK != status)
438 { 440 {
439 cp = NULL; 441 cp = NULL;
440 FAIL_TEST(0, return ); 442 FAIL_TEST (0, return );
441 return; 443 return;
442 } 444 }
443 event_mask = 0; 445 event_mask = 0;
444 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); 446 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
445 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); 447 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
446 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); 448 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
447 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); 449 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
448 controller = 450 controller =
449 GNUNET_TESTBED_controller_connect(host, event_mask, &controller_cb, 451 GNUNET_TESTBED_controller_connect (host, event_mask, &controller_cb,
450 NULL); 452 NULL);
451 FAIL_TEST(NULL != controller, return ); 453 FAIL_TEST (NULL != controller, return );
452 neighbour = GNUNET_TESTBED_host_create("localhost", NULL, cfg, 0); 454 neighbour = GNUNET_TESTBED_host_create ("localhost", NULL, cfg, 0);
453 FAIL_TEST(NULL != neighbour, return ); 455 FAIL_TEST (NULL != neighbour, return );
454 reg_handle = 456 reg_handle =
455 GNUNET_TESTBED_register_host(controller, neighbour, &registration_comp, 457 GNUNET_TESTBED_register_host (controller, neighbour, &registration_comp,
456 neighbour); 458 neighbour);
457 FAIL_TEST(NULL != reg_handle, return ); 459 FAIL_TEST (NULL != reg_handle, return );
458} 460}
459 461
460 462
@@ -468,22 +470,22 @@ status_cb(void *cls,
468 * @param cfg the configuration file handle 470 * @param cfg the configuration file handle
469 */ 471 */
470static void 472static void
471run(void *cls, 473run (void *cls,
472 char *const *args, 474 char *const *args,
473 const char *cfgfile, 475 const char *cfgfile,
474 const struct GNUNET_CONFIGURATION_Handle *config) 476 const struct GNUNET_CONFIGURATION_Handle *config)
475{ 477{
476 cfg = GNUNET_CONFIGURATION_dup(config); 478 cfg = GNUNET_CONFIGURATION_dup (config);
477 host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0); 479 host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0);
478 FAIL_TEST(NULL != host, return ); 480 FAIL_TEST (NULL != host, return );
479 cp = GNUNET_TESTBED_controller_start("127.0.0.1", host, 481 cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host,
480 &status_cb, 482 &status_cb,
481 NULL); 483 NULL);
482 abort_task = 484 abort_task =
483 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 485 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
484 (GNUNET_TIME_UNIT_MINUTES, 5), 486 (GNUNET_TIME_UNIT_MINUTES, 5),
485 &do_abort, 487 &do_abort,
486 NULL); 488 NULL);
487} 489}
488 490
489 491
@@ -491,7 +493,7 @@ run(void *cls,
491 * Main function 493 * Main function
492 */ 494 */
493int 495int
494main(int argc, char **argv) 496main (int argc, char **argv)
495{ 497{
496 int ret; 498 int ret;
497 499
@@ -504,8 +506,8 @@ main(int argc, char **argv)
504 506
505 result = GNUNET_SYSERR; 507 result = GNUNET_SYSERR;
506 ret = 508 ret =
507 GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, 509 GNUNET_PROGRAM_run ((sizeof(argv2) / sizeof(char *)) - 1, argv2,
508 "test_testbed_api", "nohelp", options, &run, NULL); 510 "test_testbed_api", "nohelp", options, &run, NULL);
509 if ((GNUNET_OK != ret) || (GNUNET_OK != result)) 511 if ((GNUNET_OK != ret) || (GNUNET_OK != result))
510 return 1; 512 return 1;
511 return 0; 513 return 0;
diff --git a/src/testbed/test_testbed_api_2peers_1controller.c b/src/testbed/test_testbed_api_2peers_1controller.c
index 23d9823f5..de56ec88a 100644
--- a/src/testbed/test_testbed_api_2peers_1controller.c
+++ b/src/testbed/test_testbed_api_2peers_1controller.c
@@ -35,18 +35,19 @@
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 */
49struct PeerContext { 49struct PeerContext
50{
50 /** 51 /**
51 * The peer handle 52 * The peer handle
52 */ 53 */
@@ -111,17 +112,18 @@ static struct GNUNET_TESTBED_Operation *common_operation;
111/** 112/**
112 * Abort task identifier 113 * Abort task identifier
113 */ 114 */
114static struct GNUNET_SCHEDULER_Task * abort_task; 115static struct GNUNET_SCHEDULER_Task *abort_task;
115 116
116/** 117/**
117 * Delayed connect job identifier 118 * Delayed connect job identifier
118 */ 119 */
119static struct GNUNET_SCHEDULER_Task * delayed_connect_task; 120static struct GNUNET_SCHEDULER_Task *delayed_connect_task;
120 121
121/** 122/**
122 * Different stages in testing 123 * Different stages in testing
123 */ 124 */
124enum Stage { 125enum Stage
126{
125 /** 127 /**
126 * Initial stage 128 * Initial stage
127 */ 129 */
@@ -168,15 +170,15 @@ static enum Stage result;
168 * shortcut to exit during failure 170 * shortcut to exit during failure
169 */ 171 */
170#define FAIL_TEST(cond) do { \ 172#define FAIL_TEST(cond) do { \
171 if (!(cond)) { \ 173 if (! (cond)) { \
172 GNUNET_break(0); \ 174 GNUNET_break (0); \
173 if (NULL != abort_task) \ 175 if (NULL != abort_task) \
174 GNUNET_SCHEDULER_cancel (abort_task); \ 176 GNUNET_SCHEDULER_cancel (abort_task); \
175 abort_task = NULL; \ 177 abort_task = NULL; \
176 GNUNET_SCHEDULER_add_now(do_shutdown, NULL); \ 178 GNUNET_SCHEDULER_add_now (do_shutdown, NULL); \
177 return; \ 179 return; \
178 } \ 180 } \
179 } while (0) 181} while (0)
180 182
181 183
182/** 184/**
@@ -185,20 +187,20 @@ static enum Stage result;
185 * @param cls NULL 187 * @param cls NULL
186 */ 188 */
187static void 189static void
188do_shutdown(void *cls) 190do_shutdown (void *cls)
189{ 191{
190 if (NULL != abort_task) 192 if (NULL != abort_task)
191 GNUNET_SCHEDULER_cancel(abort_task); 193 GNUNET_SCHEDULER_cancel (abort_task);
192 if (NULL != delayed_connect_task) 194 if (NULL != delayed_connect_task)
193 GNUNET_SCHEDULER_cancel(delayed_connect_task); 195 GNUNET_SCHEDULER_cancel (delayed_connect_task);
194 if (NULL != reg_handle) 196 if (NULL != reg_handle)
195 GNUNET_TESTBED_cancel_registration(reg_handle); 197 GNUNET_TESTBED_cancel_registration (reg_handle);
196 GNUNET_TESTBED_controller_disconnect(controller); 198 GNUNET_TESTBED_controller_disconnect (controller);
197 GNUNET_CONFIGURATION_destroy(cfg); 199 GNUNET_CONFIGURATION_destroy (cfg);
198 if (NULL != cp) 200 if (NULL != cp)
199 GNUNET_TESTBED_controller_stop(cp); 201 GNUNET_TESTBED_controller_stop (cp);
200 GNUNET_TESTBED_host_destroy(neighbour); 202 GNUNET_TESTBED_host_destroy (neighbour);
201 GNUNET_TESTBED_host_destroy(host); 203 GNUNET_TESTBED_host_destroy (host);
202} 204}
203 205
204 206
@@ -208,11 +210,11 @@ do_shutdown(void *cls)
208 * @param cls NULL 210 * @param cls NULL
209 */ 211 */
210static void 212static void
211do_abort(void *cls) 213do_abort (void *cls)
212{ 214{
213 LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); 215 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
214 abort_task = NULL; 216 abort_task = NULL;
215 do_shutdown(cls); 217 do_shutdown (cls);
216} 218}
217 219
218 220
@@ -225,7 +227,7 @@ do_abort(void *cls)
225 * operation has executed successfully. 227 * operation has executed successfully.
226 */ 228 */
227static void 229static void
228op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg); 230op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg);
229 231
230 232
231/** 233/**
@@ -234,13 +236,13 @@ op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg);
234 * @param cls NULL 236 * @param cls NULL
235 */ 237 */
236static void 238static void
237do_delayed_connect(void *cls) 239do_delayed_connect (void *cls)
238{ 240{
239 delayed_connect_task = NULL; 241 delayed_connect_task = NULL;
240 FAIL_TEST(NULL == common_operation); 242 FAIL_TEST (NULL == common_operation);
241 common_operation = 243 common_operation =
242 GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer1.peer, 244 GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer,
243 peer2.peer); 245 peer2.peer);
244} 246}
245 247
246 248
@@ -253,26 +255,26 @@ do_delayed_connect(void *cls)
253 * operation has executed successfully. 255 * operation has executed successfully.
254 */ 256 */
255static void 257static void
256op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) 258op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
257{ 259{
258 FAIL_TEST(common_operation == op); 260 FAIL_TEST (common_operation == op);
259 switch (result) 261 switch (result)
260 { 262 {
261 case PEERS_STARTED: 263 case PEERS_STARTED:
262 FAIL_TEST(NULL == peer1.operation); 264 FAIL_TEST (NULL == peer1.operation);
263 FAIL_TEST(NULL == peer2.operation); 265 FAIL_TEST (NULL == peer2.operation);
264 FAIL_TEST(NULL != common_operation); 266 FAIL_TEST (NULL != common_operation);
265 break; 267 break;
266 268
267 case PEERS_CONNECTED: 269 case PEERS_CONNECTED:
268 FAIL_TEST(NULL == peer1.operation); 270 FAIL_TEST (NULL == peer1.operation);
269 FAIL_TEST(NULL == peer2.operation); 271 FAIL_TEST (NULL == peer2.operation);
270 FAIL_TEST(NULL != common_operation); 272 FAIL_TEST (NULL != common_operation);
271 break; 273 break;
272 274
273 default: 275 default:
274 FAIL_TEST(0); 276 FAIL_TEST (0);
275 } 277 }
276} 278}
277 279
278 280
@@ -284,120 +286,120 @@ op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
284 * @param event information about the event 286 * @param event information about the event
285 */ 287 */
286static void 288static void
287controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) 289controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
288{ 290{
289 switch (event->type) 291 switch (event->type)
292 {
293 case GNUNET_TESTBED_ET_OPERATION_FINISHED: /* Will be reached when we destroy peers */
294 FAIL_TEST (PEERS_STOPPED == result);
295 FAIL_TEST (NULL == event->op_cls);
296 FAIL_TEST (NULL == event->details.operation_finished.emsg);
297 FAIL_TEST (NULL == event->details.operation_finished.generic);
298 if (event->op == peer1.operation)
290 { 299 {
291 case GNUNET_TESTBED_ET_OPERATION_FINISHED: /* Will be reached when we destroy peers */ 300 GNUNET_TESTBED_operation_done (peer1.operation);
292 FAIL_TEST(PEERS_STOPPED == result); 301 peer1.operation = NULL;
293 FAIL_TEST(NULL == event->op_cls); 302 peer1.peer = NULL;
294 FAIL_TEST(NULL == event->details.operation_finished.emsg); 303 }
295 FAIL_TEST(NULL == event->details.operation_finished.generic); 304 else if (event->op == peer2.operation)
296 if (event->op == peer1.operation) 305 {
297 { 306 GNUNET_TESTBED_operation_done (peer2.operation);
298 GNUNET_TESTBED_operation_done(peer1.operation); 307 peer2.operation = NULL;
299 peer1.operation = NULL; 308 peer2.peer = NULL;
300 peer1.peer = NULL; 309 }
301 } 310 else
302 else if (event->op == peer2.operation) 311 FAIL_TEST (0);
303 { 312 if ((NULL == peer1.peer) && (NULL == peer2.peer))
304 GNUNET_TESTBED_operation_done(peer2.operation); 313 {
305 peer2.operation = NULL; 314 result = SUCCESS;
306 peer2.peer = NULL; 315 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
307 } 316 }
308 else 317 break;
309 FAIL_TEST(0);
310 if ((NULL == peer1.peer) && (NULL == peer2.peer))
311 {
312 result = SUCCESS;
313 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL);
314 }
315 break;
316 318
317 case GNUNET_TESTBED_ET_PEER_START: 319 case GNUNET_TESTBED_ET_PEER_START:
318 FAIL_TEST(INIT == result); 320 FAIL_TEST (INIT == result);
319 FAIL_TEST(event->details.peer_start.host == host); 321 FAIL_TEST (event->details.peer_start.host == host);
320 if (event->details.peer_start.peer == peer1.peer) 322 if (event->details.peer_start.peer == peer1.peer)
321 { 323 {
322 peer1.is_running = GNUNET_YES; 324 peer1.is_running = GNUNET_YES;
323 GNUNET_TESTBED_operation_done(peer1.operation); 325 GNUNET_TESTBED_operation_done (peer1.operation);
324 peer1.operation = NULL; 326 peer1.operation = NULL;
325 } 327 }
326 else if (event->details.peer_start.peer == peer2.peer) 328 else if (event->details.peer_start.peer == peer2.peer)
327 { 329 {
328 peer2.is_running = GNUNET_YES; 330 peer2.is_running = GNUNET_YES;
329 GNUNET_TESTBED_operation_done(peer2.operation); 331 GNUNET_TESTBED_operation_done (peer2.operation);
330 peer2.operation = NULL; 332 peer2.operation = NULL;
331 } 333 }
332 else 334 else
333 FAIL_TEST(0); 335 FAIL_TEST (0);
334 if ((GNUNET_YES == peer1.is_running) && (GNUNET_YES == peer2.is_running)) 336 if ((GNUNET_YES == peer1.is_running) && (GNUNET_YES == peer2.is_running))
335 { 337 {
336 result = PEERS_STARTED; 338 result = PEERS_STARTED;
337 common_operation = 339 common_operation =
338 GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer1.peer, 340 GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer,
339 peer2.peer); 341 peer2.peer);
340 } 342 }
341 break; 343 break;
342 344
343 case GNUNET_TESTBED_ET_PEER_STOP: 345 case GNUNET_TESTBED_ET_PEER_STOP:
344 FAIL_TEST(PEERS_CONNECTED_2 == result); 346 FAIL_TEST (PEERS_CONNECTED_2 == result);
345 if (event->details.peer_stop.peer == peer1.peer) 347 if (event->details.peer_stop.peer == peer1.peer)
346 { 348 {
347 peer1.is_running = GNUNET_NO; 349 peer1.is_running = GNUNET_NO;
348 GNUNET_TESTBED_operation_done(peer1.operation); 350 GNUNET_TESTBED_operation_done (peer1.operation);
349 peer1.operation = GNUNET_TESTBED_peer_destroy(peer1.peer); 351 peer1.operation = GNUNET_TESTBED_peer_destroy (peer1.peer);
350 } 352 }
351 else if (event->details.peer_stop.peer == peer2.peer) 353 else if (event->details.peer_stop.peer == peer2.peer)
352 { 354 {
353 peer2.is_running = GNUNET_NO; 355 peer2.is_running = GNUNET_NO;
354 GNUNET_TESTBED_operation_done(peer2.operation); 356 GNUNET_TESTBED_operation_done (peer2.operation);
355 peer2.operation = GNUNET_TESTBED_peer_destroy(peer2.peer); 357 peer2.operation = GNUNET_TESTBED_peer_destroy (peer2.peer);
356 } 358 }
357 else 359 else
358 FAIL_TEST(0); 360 FAIL_TEST (0);
359 if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running)) 361 if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running))
360 result = PEERS_STOPPED; 362 result = PEERS_STOPPED;
363 break;
364
365 case GNUNET_TESTBED_ET_CONNECT:
366 switch (result)
367 {
368 case PEERS_STARTED:
369 FAIL_TEST (NULL == peer1.operation);
370 FAIL_TEST (NULL == peer2.operation);
371 FAIL_TEST (NULL != common_operation);
372 FAIL_TEST ((event->details.peer_connect.peer1 == peer1.peer) &&
373 (event->details.peer_connect.peer2 == peer2.peer));
374 GNUNET_TESTBED_operation_done (common_operation);
375 common_operation = NULL;
376 result = PEERS_CONNECTED;
377 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n");
378 delayed_connect_task =
379 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3), &do_delayed_connect,
380 NULL);
361 break; 381 break;
362 382
363 case GNUNET_TESTBED_ET_CONNECT: 383 case PEERS_CONNECTED:
364 switch (result) 384 FAIL_TEST (NULL == peer1.operation);
365 { 385 FAIL_TEST (NULL == peer2.operation);
366 case PEERS_STARTED: 386 FAIL_TEST (NULL != common_operation);
367 FAIL_TEST(NULL == peer1.operation); 387 GNUNET_TESTBED_operation_done (common_operation);
368 FAIL_TEST(NULL == peer2.operation); 388 common_operation = NULL;
369 FAIL_TEST(NULL != common_operation); 389 result = PEERS_CONNECTED_2;
370 FAIL_TEST((event->details.peer_connect.peer1 == peer1.peer) && 390 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n");
371 (event->details.peer_connect.peer2 == peer2.peer)); 391 peer1.operation = GNUNET_TESTBED_peer_stop (NULL, peer1.peer, NULL, NULL);
372 GNUNET_TESTBED_operation_done(common_operation); 392 peer2.operation = GNUNET_TESTBED_peer_stop (NULL, peer2.peer, NULL, NULL);
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 }
396 break; 393 break;
397 394
398 default: 395 default:
399 FAIL_TEST(0); 396 FAIL_TEST (0);
400 } 397 }
398 break;
399
400 default:
401 FAIL_TEST (0);
402 }
401 ; 403 ;
402} 404}
403 405
@@ -412,16 +414,16 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
412 * @param emsg NULL if peer is not NULL; else MAY contain the error description 414 * @param emsg NULL if peer is not NULL; else MAY contain the error description
413 */ 415 */
414static void 416static void
415peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) 417peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
416{ 418{
417 struct PeerContext *pc = cls; 419 struct PeerContext *pc = cls;
418 420
419 FAIL_TEST(NULL != pc->operation); 421 FAIL_TEST (NULL != pc->operation);
420 FAIL_TEST(NULL != peer); 422 FAIL_TEST (NULL != peer);
421 FAIL_TEST(NULL == pc->peer); 423 FAIL_TEST (NULL == pc->peer);
422 pc->peer = peer; 424 pc->peer = peer;
423 GNUNET_TESTBED_operation_done(pc->operation); 425 GNUNET_TESTBED_operation_done (pc->operation);
424 pc->operation = GNUNET_TESTBED_peer_start(NULL, pc->peer, NULL, NULL); 426 pc->operation = GNUNET_TESTBED_peer_start (NULL, pc->peer, NULL, NULL);
425} 427}
426 428
427 429
@@ -432,18 +434,18 @@ peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
432 * @param emsg the error message; NULL if host registration is successful 434 * @param emsg the error message; NULL if host registration is successful
433 */ 435 */
434static void 436static void
435registration_comp(void *cls, const char *emsg) 437registration_comp (void *cls, const char *emsg)
436{ 438{
437 FAIL_TEST(cls == neighbour); 439 FAIL_TEST (cls == neighbour);
438 reg_handle = NULL; 440 reg_handle = NULL;
439 peer1.operation = 441 peer1.operation =
440 GNUNET_TESTBED_peer_create(controller, host, cfg, &peer_create_cb, 442 GNUNET_TESTBED_peer_create (controller, host, cfg, &peer_create_cb,
441 &peer1); 443 &peer1);
442 peer2.operation = 444 peer2.operation =
443 GNUNET_TESTBED_peer_create(controller, host, cfg, &peer_create_cb, 445 GNUNET_TESTBED_peer_create (controller, host, cfg, &peer_create_cb,
444 &peer2); 446 &peer2);
445 FAIL_TEST(NULL != peer1.operation); 447 FAIL_TEST (NULL != peer1.operation);
446 FAIL_TEST(NULL != peer2.operation); 448 FAIL_TEST (NULL != peer2.operation);
447} 449}
448 450
449 451
@@ -457,30 +459,31 @@ registration_comp(void *cls, const char *emsg)
457 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case 459 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
458 */ 460 */
459static void 461static void
460status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg_, int status) 462status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg_, int
463 status)
461{ 464{
462 uint64_t event_mask; 465 uint64_t event_mask;
463 466
464 if (GNUNET_OK != status) 467 if (GNUNET_OK != status)
465 { 468 {
466 cp = NULL; 469 cp = NULL;
467 FAIL_TEST(0); 470 FAIL_TEST (0);
468 } 471 }
469 event_mask = 0; 472 event_mask = 0;
470 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); 473 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
471 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); 474 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
472 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); 475 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
473 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); 476 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
474 controller = 477 controller =
475 GNUNET_TESTBED_controller_connect(host, event_mask, &controller_cb, 478 GNUNET_TESTBED_controller_connect (host, event_mask, &controller_cb,
476 NULL); 479 NULL);
477 FAIL_TEST(NULL != controller); 480 FAIL_TEST (NULL != controller);
478 neighbour = GNUNET_TESTBED_host_create("localhost", NULL, cfg, 0); 481 neighbour = GNUNET_TESTBED_host_create ("localhost", NULL, cfg, 0);
479 FAIL_TEST(NULL != neighbour); 482 FAIL_TEST (NULL != neighbour);
480 reg_handle = 483 reg_handle =
481 GNUNET_TESTBED_register_host(controller, neighbour, &registration_comp, 484 GNUNET_TESTBED_register_host (controller, neighbour, &registration_comp,
482 neighbour); 485 neighbour);
483 FAIL_TEST(NULL != reg_handle); 486 FAIL_TEST (NULL != reg_handle);
484} 487}
485 488
486 489
@@ -494,18 +497,18 @@ status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg_, int status)
494 * @param cfg the configuration file handle 497 * @param cfg the configuration file handle
495 */ 498 */
496static void 499static void
497run(void *cls, char *const *args, const char *cfgfile, 500run (void *cls, char *const *args, const char *cfgfile,
498 const struct GNUNET_CONFIGURATION_Handle *config) 501 const struct GNUNET_CONFIGURATION_Handle *config)
499{ 502{
500 cfg = GNUNET_CONFIGURATION_dup(config); 503 cfg = GNUNET_CONFIGURATION_dup (config);
501 host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0); 504 host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0);
502 FAIL_TEST(NULL != host); 505 FAIL_TEST (NULL != host);
503 cp = GNUNET_TESTBED_controller_start("127.0.0.1", host, status_cb, 506 cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb,
504 NULL); 507 NULL);
505 abort_task = 508 abort_task =
506 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 509 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
507 (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, 510 (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort,
508 NULL); 511 NULL);
509} 512}
510 513
511 514
@@ -513,7 +516,7 @@ run(void *cls, char *const *args, const char *cfgfile,
513 * Main function 516 * Main function
514 */ 517 */
515int 518int
516main(int argc, char **argv) 519main (int argc, char **argv)
517{ 520{
518 int ret; 521 int ret;
519 522
@@ -526,9 +529,9 @@ main(int argc, char **argv)
526 529
527 result = INIT; 530 result = INIT;
528 ret = 531 ret =
529 GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, 532 GNUNET_PROGRAM_run ((sizeof(argv2) / sizeof(char *)) - 1, argv2,
530 "test_testbed_api_2peers_1controller", "nohelp", 533 "test_testbed_api_2peers_1controller", "nohelp",
531 options, &run, NULL); 534 options, &run, NULL);
532 if ((GNUNET_OK != ret) || (SUCCESS != result)) 535 if ((GNUNET_OK != ret) || (SUCCESS != result))
533 return 1; 536 return 1;
534 return 0; 537 return 0;
diff --git a/src/testbed/test_testbed_api_3peers_3controllers.c b/src/testbed/test_testbed_api_3peers_3controllers.c
index ec396d6ca..1de635fd9 100644
--- a/src/testbed/test_testbed_api_3peers_3controllers.c
+++ b/src/testbed/test_testbed_api_3peers_3controllers.c
@@ -52,19 +52,20 @@
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 */
67struct PeerContext { 67struct PeerContext
68{
68 /** 69 /**
69 * The peer handle 70 * The peer handle
70 */ 71 */
@@ -150,17 +151,18 @@ struct GNUNET_TESTBED_HostHabitableCheckHandle *hc_handle;
150/** 151/**
151 * Abort task identifier 152 * Abort task identifier
152 */ 153 */
153static struct GNUNET_SCHEDULER_Task * abort_task; 154static struct GNUNET_SCHEDULER_Task *abort_task;
154 155
155/** 156/**
156 * Delayed connect job identifier 157 * Delayed connect job identifier
157 */ 158 */
158static struct GNUNET_SCHEDULER_Task * delayed_connect_task; 159static struct GNUNET_SCHEDULER_Task *delayed_connect_task;
159 160
160/** 161/**
161 * Different stages in testing 162 * Different stages in testing
162 */ 163 */
163enum Stage { 164enum Stage
165{
164 /** 166 /**
165 * Initial stage 167 * Initial stage
166 */ 168 */
@@ -253,30 +255,30 @@ static enum Stage result;
253 * @param cls NULL 255 * @param cls NULL
254 */ 256 */
255static void 257static void
256do_shutdown(void *cls) 258do_shutdown (void *cls)
257{ 259{
258 if (NULL != abort_task) 260 if (NULL != abort_task)
259 GNUNET_SCHEDULER_cancel(abort_task); 261 GNUNET_SCHEDULER_cancel (abort_task);
260 if (NULL != hc_handle) 262 if (NULL != hc_handle)
261 GNUNET_TESTBED_is_host_habitable_cancel(hc_handle); 263 GNUNET_TESTBED_is_host_habitable_cancel (hc_handle);
262 GNUNET_assert(NULL == delayed_connect_task); 264 GNUNET_assert (NULL == delayed_connect_task);
263 if (NULL != common_operation) 265 if (NULL != common_operation)
264 GNUNET_TESTBED_operation_done(common_operation); 266 GNUNET_TESTBED_operation_done (common_operation);
265 if (NULL != reg_handle) 267 if (NULL != reg_handle)
266 GNUNET_TESTBED_cancel_registration(reg_handle); 268 GNUNET_TESTBED_cancel_registration (reg_handle);
267 if (NULL != controller1) 269 if (NULL != controller1)
268 GNUNET_TESTBED_controller_disconnect(controller1); 270 GNUNET_TESTBED_controller_disconnect (controller1);
269 GNUNET_CONFIGURATION_destroy(cfg); 271 GNUNET_CONFIGURATION_destroy (cfg);
270 if (NULL != cfg2) 272 if (NULL != cfg2)
271 GNUNET_CONFIGURATION_destroy(cfg2); 273 GNUNET_CONFIGURATION_destroy (cfg2);
272 if (NULL != cp1) 274 if (NULL != cp1)
273 GNUNET_TESTBED_controller_stop(cp1); 275 GNUNET_TESTBED_controller_stop (cp1);
274 if (NULL != host) 276 if (NULL != host)
275 GNUNET_TESTBED_host_destroy(host); 277 GNUNET_TESTBED_host_destroy (host);
276 if (NULL != neighbour1) 278 if (NULL != neighbour1)
277 GNUNET_TESTBED_host_destroy(neighbour1); 279 GNUNET_TESTBED_host_destroy (neighbour1);
278 if (NULL != neighbour2) 280 if (NULL != neighbour2)
279 GNUNET_TESTBED_host_destroy(neighbour2); 281 GNUNET_TESTBED_host_destroy (neighbour2);
280} 282}
281 283
282 284
@@ -286,25 +288,25 @@ do_shutdown(void *cls)
286 * @param cls NULL 288 * @param cls NULL
287 */ 289 */
288static void 290static void
289do_abort(void *cls) 291do_abort (void *cls)
290{ 292{
291 LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); 293 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
292 abort_task = NULL; 294 abort_task = NULL;
293 if (NULL != delayed_connect_task) 295 if (NULL != delayed_connect_task)
294 { 296 {
295 GNUNET_SCHEDULER_cancel(delayed_connect_task); 297 GNUNET_SCHEDULER_cancel (delayed_connect_task);
296 delayed_connect_task = NULL; 298 delayed_connect_task = NULL;
297 } 299 }
298 do_shutdown(cls); 300 do_shutdown (cls);
299} 301}
300 302
301 303
302static void 304static void
303abort_test() 305abort_test ()
304{ 306{
305 if (NULL != abort_task) 307 if (NULL != abort_task)
306 GNUNET_SCHEDULER_cancel(abort_task); 308 GNUNET_SCHEDULER_cancel (abort_task);
307 abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); 309 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
308} 310}
309 311
310 312
@@ -317,7 +319,7 @@ abort_test()
317 * operation has executed successfully. 319 * operation has executed successfully.
318 */ 320 */
319static void 321static void
320op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg); 322op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg);
321 323
322 324
323/** 325/**
@@ -326,18 +328,18 @@ op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg);
326 * @param cls NULL 328 * @param cls NULL
327 */ 329 */
328static void 330static void
329do_delayed_connect(void *cls) 331do_delayed_connect (void *cls)
330{ 332{
331 delayed_connect_task = NULL; 333 delayed_connect_task = NULL;
332 if (NULL != common_operation) 334 if (NULL != common_operation)
333 { 335 {
334 GNUNET_break(0); 336 GNUNET_break (0);
335 abort_test(); 337 abort_test ();
336 return; 338 return;
337 } 339 }
338 common_operation = 340 common_operation =
339 GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer1.peer, 341 GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer,
340 peer2.peer); 342 peer2.peer);
341} 343}
342 344
343 345
@@ -350,34 +352,34 @@ do_delayed_connect(void *cls)
350 * operation has executed successfully. 352 * operation has executed successfully.
351 */ 353 */
352static void 354static void
353op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) 355op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
354{ 356{
355 if (common_operation != op) 357 if (common_operation != op)
356 { 358 {
357 GNUNET_break(0); 359 GNUNET_break (0);
358 abort_test(); 360 abort_test ();
359 return; 361 return;
360 } 362 }
361 363
362 switch (result) 364 switch (result)
363 { 365 {
364 case PEER3_STARTED: 366 case PEER3_STARTED:
365 case PEERS_2_3_CONNECTED: 367 case PEERS_2_3_CONNECTED:
366 case PEERS_1_2_CONNECTED: 368 case PEERS_1_2_CONNECTED:
367 break; 369 break;
368 370
369 default: 371 default:
370 GNUNET_break(0); 372 GNUNET_break (0);
371 abort_test(); 373 abort_test ();
372 return; 374 return;
373 } 375 }
374 if ((NULL != peer1.operation) || (NULL != peer2.operation) || 376 if ((NULL != peer1.operation) || (NULL != peer2.operation) ||
375 (NULL != peer3.operation)) 377 (NULL != peer3.operation))
376 { 378 {
377 GNUNET_break(0); 379 GNUNET_break (0);
378 abort_test(); 380 abort_test ();
379 return; 381 return;
380 } 382 }
381} 383}
382 384
383 385
@@ -391,54 +393,54 @@ op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
391 * @param emsg NULL if peer is not NULL; else MAY contain the error description 393 * @param emsg NULL if peer is not NULL; else MAY contain the error description
392 */ 394 */
393static void 395static void
394peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) 396peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
395{ 397{
396 switch (result) 398 switch (result)
399 {
400 case CONTROLLER1_UP:
401 if ((NULL == peer1.operation) || (NULL == peer) || (NULL != peer1.peer))
397 { 402 {
398 case CONTROLLER1_UP: 403 GNUNET_break (0);
399 if ((NULL == peer1.operation) || (NULL == peer) || (NULL != peer1.peer)) 404 abort_test ();
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();
440 return; 405 return;
441 } 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
413 case CONTROLLER2_UP:
414 if ((NULL == peer2.operation) || (NULL == peer) || (NULL != peer2.peer))
415 {
416 GNUNET_break (0);
417 abort_test ();
418 return;
419 }
420 peer2.peer = peer;
421 GNUNET_TESTBED_operation_done (peer2.operation);
422 result = PEER2_CREATED;
423 peer2.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
424 break;
425
426 case CONTROLLER3_UP:
427 if ((NULL == peer3.operation) || (NULL == peer) || (NULL != peer3.peer))
428 {
429 GNUNET_break (0);
430 abort_test ();
431 return;
432 }
433 peer3.peer = peer;
434 GNUNET_TESTBED_operation_done (peer3.operation);
435 result = PEER3_CREATED;
436 peer3.operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL);
437 break;
438
439 default:
440 GNUNET_break (0);
441 abort_test ();
442 return;
443 }
442} 444}
443 445
444 446
@@ -450,289 +452,289 @@ peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
450 * @param event information about the event 452 * @param event information about the event
451 */ 453 */
452static void 454static void
453controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) 455controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
454{ 456{
455 switch (event->type) 457 switch (event->type)
458 {
459 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
460 if ((NULL != event->op_cls) ||
461 (NULL != event->details.operation_finished.emsg))
462 {
463 GNUNET_break (0);
464 abort_test ();
465 return;
466 }
467 switch (result)
456 { 468 {
457 case GNUNET_TESTBED_ET_OPERATION_FINISHED: 469 case PEERS_STOPPED:
458 if ((NULL != event->op_cls) || 470 if (NULL != event->details.operation_finished.generic)
459 (NULL != event->details.operation_finished.emsg)) 471 {
460 { 472 GNUNET_break (0);
461 GNUNET_break(0); 473 abort_test ();
462 abort_test(); 474 return;
463 return; 475 }
464 } 476 if (event->op == peer1.operation)
465 switch (result) 477 {
466 { 478 GNUNET_TESTBED_operation_done (peer1.operation);
467 case PEERS_STOPPED: 479 peer1.operation = NULL;
468 if (NULL != event->details.operation_finished.generic) 480 peer1.peer = NULL;
469 { 481 }
470 GNUNET_break(0); 482 else if (event->op == peer2.operation)
471 abort_test(); 483 {
472 return; 484 GNUNET_TESTBED_operation_done (peer2.operation);
473 } 485 peer2.operation = NULL;
474 if (event->op == peer1.operation) 486 peer2.peer = NULL;
475 { 487 }
476 GNUNET_TESTBED_operation_done(peer1.operation); 488 else if (event->op == peer3.operation)
477 peer1.operation = NULL; 489 {
478 peer1.peer = NULL; 490 GNUNET_TESTBED_operation_done (peer3.operation);
479 } 491 peer3.operation = NULL;
480 else if (event->op == peer2.operation) 492 peer3.peer = NULL;
481 { 493 }
482 GNUNET_TESTBED_operation_done(peer2.operation); 494 else
483 peer2.operation = NULL; 495 {
484 peer2.peer = NULL; 496 GNUNET_break (0);
485 } 497 abort_test ();
486 else if (event->op == peer3.operation) 498 return;
487 { 499 }
488 GNUNET_TESTBED_operation_done(peer3.operation); 500 if ((NULL == peer1.peer) && (NULL == peer2.peer) && (NULL == peer3.peer))
489 peer3.operation = NULL; 501 {
490 peer3.peer = NULL; 502 result = SUCCESS;
491 } 503 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
492 else 504 }
493 {
494 GNUNET_break(0);
495 abort_test();
496 return;
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 }
554 break; 505 break;
555 506
556 case GNUNET_TESTBED_ET_PEER_START: 507 case PEER1_STARTED:
557 switch (result) 508 if ((NULL != event->details.operation_finished.generic) ||
558 { 509 (NULL == common_operation))
559 case PEER1_CREATED: 510 {
560 if (event->details.peer_start.host != host) 511 GNUNET_break (0);
561 { 512 abort_test ();
562 GNUNET_break(0); 513 return;
563 abort_test(); 514 }
564 return; 515 GNUNET_TESTBED_operation_done (common_operation);
565 } 516 common_operation = NULL;
566 peer1.is_running = GNUNET_YES; 517 result = CONTROLLER2_UP;
567 GNUNET_TESTBED_operation_done(peer1.operation); 518 peer2.operation =
568 peer1.operation = NULL; 519 GNUNET_TESTBED_peer_create (controller1, neighbour1, cfg,
569 result = PEER1_STARTED; 520 &peer_create_cb, NULL);
570 common_operation = 521 if (NULL == peer2.operation)
571 GNUNET_TESTBED_controller_link(NULL, controller1, neighbour1, NULL, 522 {
572 GNUNET_YES); 523 GNUNET_break (0);
573 break; 524 abort_test ();
574 525 return;
575 case PEER2_CREATED: 526 }
576 if (event->details.peer_start.host != neighbour1)
577 {
578 GNUNET_break(0);
579 abort_test();
580 return;
581 }
582 peer2.is_running = GNUNET_YES;
583 GNUNET_TESTBED_operation_done(peer2.operation);
584 peer2.operation = NULL;
585 result = PEER2_STARTED;
586 if (NULL != common_operation)
587 {
588 GNUNET_break(0);
589 abort_test();
590 return;
591 }
592 common_operation =
593 GNUNET_TESTBED_controller_link(NULL, controller1, neighbour2, NULL,
594 GNUNET_YES);
595 if (NULL == common_operation)
596 {
597 GNUNET_break(0);
598 abort_test();
599 return;
600 }
601 break;
602
603 case PEER3_CREATED:
604 if (event->details.peer_start.host != neighbour2)
605 {
606 GNUNET_break(0);
607 abort_test();
608 return;
609 }
610 peer3.is_running = GNUNET_YES;
611 GNUNET_TESTBED_operation_done(peer3.operation);
612 peer3.operation = NULL;
613 result = PEER3_STARTED;
614 common_operation =
615 GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer2.peer,
616 peer1.peer);
617 break;
618
619 default:
620 GNUNET_break(0);
621 abort_test();
622 return;
623 }
624 break; 527 break;
625 528
626 case GNUNET_TESTBED_ET_PEER_STOP: 529 case PEER2_STARTED:
627 if (PEERS_CONNECTED_2 != result) 530 if ((NULL != event->details.operation_finished.generic) ||
628 { 531 (NULL == common_operation))
629 GNUNET_break(0); 532 {
630 abort_test(); 533 GNUNET_break (0);
631 return; 534 abort_test ();
632 } 535 return;
633 if (event->details.peer_stop.peer == peer1.peer) 536 }
634 { 537 GNUNET_TESTBED_operation_done (common_operation);
635 peer1.is_running = GNUNET_NO; 538 common_operation = NULL;
636 GNUNET_TESTBED_operation_done(peer1.operation); 539 result = CONTROLLER3_UP;
637 } 540 peer3.operation =
638 else if (event->details.peer_stop.peer == peer2.peer) 541 GNUNET_TESTBED_peer_create (controller1, neighbour2, cfg,
639 { 542 &peer_create_cb, NULL);
640 peer2.is_running = GNUNET_NO; 543 if (NULL == peer3.operation)
641 GNUNET_TESTBED_operation_done(peer2.operation); 544 {
642 } 545 GNUNET_break (0);
643 else if (event->details.peer_stop.peer == peer3.peer) 546 abort_test ();
644 { 547 return;
645 peer3.is_running = GNUNET_NO; 548 }
646 GNUNET_TESTBED_operation_done(peer3.operation); 549 break;
647 } 550
648 else 551 default:
649 { 552 GNUNET_break (0);
650 GNUNET_break(0); 553 abort_test ();
651 abort_test(); 554 return;
652 return; 555 }
653 } 556 break;
654 if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running) && 557
655 (GNUNET_NO == peer3.is_running)) 558 case GNUNET_TESTBED_ET_PEER_START:
656 { 559 switch (result)
657 result = PEERS_STOPPED; 560 {
658 peer1.operation = GNUNET_TESTBED_peer_destroy(peer1.peer); 561 case PEER1_CREATED:
659 peer2.operation = GNUNET_TESTBED_peer_destroy(peer2.peer); 562 if (event->details.peer_start.host != host)
660 peer3.operation = GNUNET_TESTBED_peer_destroy(peer3.peer); 563 {
661 } 564 GNUNET_break (0);
565 abort_test ();
566 return;
567 }
568 peer1.is_running = GNUNET_YES;
569 GNUNET_TESTBED_operation_done (peer1.operation);
570 peer1.operation = NULL;
571 result = PEER1_STARTED;
572 common_operation =
573 GNUNET_TESTBED_controller_link (NULL, controller1, neighbour1, NULL,
574 GNUNET_YES);
662 break; 575 break;
663 576
664 case GNUNET_TESTBED_ET_CONNECT: 577 case PEER2_CREATED:
665 if ((NULL != peer1.operation) || (NULL != peer2.operation) || 578 if (event->details.peer_start.host != neighbour1)
666 (NULL != peer3.operation) || (NULL == common_operation)) 579 {
667 { 580 GNUNET_break (0);
668 GNUNET_break(0); 581 abort_test ();
669 abort_test(); 582 return;
670 return; 583 }
671 } 584 peer2.is_running = GNUNET_YES;
672 switch (result) 585 GNUNET_TESTBED_operation_done (peer2.operation);
673 { 586 peer2.operation = NULL;
674 case PEER3_STARTED: 587 result = PEER2_STARTED;
675 if ((event->details.peer_connect.peer1 != peer2.peer) || 588 if (NULL != common_operation)
676 (event->details.peer_connect.peer2 != peer1.peer)) 589 {
677 { 590 GNUNET_break (0);
678 GNUNET_break(0); 591 abort_test ();
679 abort_test(); 592 return;
680 return; 593 }
681 } 594 common_operation =
682 GNUNET_TESTBED_operation_done(common_operation); 595 GNUNET_TESTBED_controller_link (NULL, controller1, neighbour2, NULL,
683 common_operation = NULL; 596 GNUNET_YES);
684 result = PEERS_1_2_CONNECTED; 597 if (NULL == common_operation)
685 LOG(GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n"); 598 {
686 common_operation = 599 GNUNET_break (0);
687 GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peer2.peer, 600 abort_test ();
688 peer3.peer); 601 return;
689 break; 602 }
690 603 break;
691 case PEERS_1_2_CONNECTED: 604
692 if ((event->details.peer_connect.peer1 != peer2.peer) || 605 case PEER3_CREATED:
693 (event->details.peer_connect.peer2 != peer3.peer)) 606 if (event->details.peer_start.host != neighbour2)
694 { 607 {
695 GNUNET_break(0); 608 GNUNET_break (0);
696 abort_test(); 609 abort_test ();
697 return; 610 return;
698 } 611 }
699 GNUNET_TESTBED_operation_done(common_operation); 612 peer3.is_running = GNUNET_YES;
700 common_operation = NULL; 613 GNUNET_TESTBED_operation_done (peer3.operation);
701 result = PEERS_2_3_CONNECTED; 614 peer3.operation = NULL;
702 delayed_connect_task = 615 result = PEER3_STARTED;
703 GNUNET_SCHEDULER_add_delayed(TIME_REL_SECS(3), &do_delayed_connect, 616 common_operation =
704 NULL); 617 GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer,
705 break; 618 peer1.peer);
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 }
729 break; 619 break;
730 620
731 default: 621 default:
732 GNUNET_break(0); 622 GNUNET_break (0);
733 abort_test(); 623 abort_test ();
624 return;
625 }
626 break;
627
628 case GNUNET_TESTBED_ET_PEER_STOP:
629 if (PEERS_CONNECTED_2 != result)
630 {
631 GNUNET_break (0);
632 abort_test ();
734 return; 633 return;
735 } 634 }
635 if (event->details.peer_stop.peer == peer1.peer)
636 {
637 peer1.is_running = GNUNET_NO;
638 GNUNET_TESTBED_operation_done (peer1.operation);
639 }
640 else if (event->details.peer_stop.peer == peer2.peer)
641 {
642 peer2.is_running = GNUNET_NO;
643 GNUNET_TESTBED_operation_done (peer2.operation);
644 }
645 else if (event->details.peer_stop.peer == peer3.peer)
646 {
647 peer3.is_running = GNUNET_NO;
648 GNUNET_TESTBED_operation_done (peer3.operation);
649 }
650 else
651 {
652 GNUNET_break (0);
653 abort_test ();
654 return;
655 }
656 if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running) &&
657 (GNUNET_NO == peer3.is_running))
658 {
659 result = PEERS_STOPPED;
660 peer1.operation = GNUNET_TESTBED_peer_destroy (peer1.peer);
661 peer2.operation = GNUNET_TESTBED_peer_destroy (peer2.peer);
662 peer3.operation = GNUNET_TESTBED_peer_destroy (peer3.peer);
663 }
664 break;
665
666 case GNUNET_TESTBED_ET_CONNECT:
667 if ((NULL != peer1.operation) || (NULL != peer2.operation) ||
668 (NULL != peer3.operation) || (NULL == common_operation))
669 {
670 GNUNET_break (0);
671 abort_test ();
672 return;
673 }
674 switch (result)
675 {
676 case PEER3_STARTED:
677 if ((event->details.peer_connect.peer1 != peer2.peer) ||
678 (event->details.peer_connect.peer2 != peer1.peer))
679 {
680 GNUNET_break (0);
681 abort_test ();
682 return;
683 }
684 GNUNET_TESTBED_operation_done (common_operation);
685 common_operation = NULL;
686 result = PEERS_1_2_CONNECTED;
687 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n");
688 common_operation =
689 GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer2.peer,
690 peer3.peer);
691 break;
692
693 case PEERS_1_2_CONNECTED:
694 if ((event->details.peer_connect.peer1 != peer2.peer) ||
695 (event->details.peer_connect.peer2 != peer3.peer))
696 {
697 GNUNET_break (0);
698 abort_test ();
699 return;
700 }
701 GNUNET_TESTBED_operation_done (common_operation);
702 common_operation = NULL;
703 result = PEERS_2_3_CONNECTED;
704 delayed_connect_task =
705 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3), &do_delayed_connect,
706 NULL);
707 break;
708
709 case PEERS_2_3_CONNECTED:
710 if ((event->details.peer_connect.peer1 != peer1.peer) ||
711 (event->details.peer_connect.peer2 != peer2.peer))
712 {
713 GNUNET_break (0);
714 abort_test ();
715 return;
716 }
717 GNUNET_TESTBED_operation_done (common_operation);
718 common_operation = NULL;
719 result = PEERS_CONNECTED_2;
720 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n");
721 peer1.operation = GNUNET_TESTBED_peer_stop (NULL, peer1.peer, NULL, NULL);
722 peer2.operation = GNUNET_TESTBED_peer_stop (NULL, peer2.peer, NULL, NULL);
723 peer3.operation = GNUNET_TESTBED_peer_stop (NULL, peer3.peer, NULL, NULL);
724 break;
725
726 default:
727 GNUNET_break (0);
728 abort_test ();
729 return;
730 }
731 break;
732
733 default:
734 GNUNET_break (0);
735 abort_test ();
736 return;
737 }
736} 738}
737 739
738 740
@@ -743,44 +745,44 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
743 * @param emsg the error message; NULL if host registration is successful 745 * @param emsg the error message; NULL if host registration is successful
744 */ 746 */
745static void 747static void
746registration_comp(void *cls, const char *emsg) 748registration_comp (void *cls, const char *emsg)
747{ 749{
748 reg_handle = NULL; 750 reg_handle = NULL;
749 if (cls == neighbour1) 751 if (cls == neighbour1)
752 {
753 neighbour2 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, cfg, 0);
754 if (NULL == neighbour2)
750 { 755 {
751 neighbour2 = GNUNET_TESTBED_host_create("127.0.0.1", NULL, cfg, 0); 756 GNUNET_break (0);
752 if (NULL == neighbour2) 757 abort_test ();
753 {
754 GNUNET_break(0);
755 abort_test();
756 return;
757 }
758 reg_handle =
759 GNUNET_TESTBED_register_host(controller1, neighbour2,
760 &registration_comp, neighbour2);
761 if (NULL == reg_handle)
762 {
763 GNUNET_break(0);
764 abort_test();
765 return;
766 }
767 return; 758 return;
768 } 759 }
769 if (cls != neighbour2) 760 reg_handle =
761 GNUNET_TESTBED_register_host (controller1, neighbour2,
762 &registration_comp, neighbour2);
763 if (NULL == reg_handle)
770 { 764 {
771 GNUNET_break(0); 765 GNUNET_break (0);
772 abort_test(); 766 abort_test ();
773 return; 767 return;
774 } 768 }
769 return;
770 }
771 if (cls != neighbour2)
772 {
773 GNUNET_break (0);
774 abort_test ();
775 return;
776 }
775 peer1.operation = 777 peer1.operation =
776 GNUNET_TESTBED_peer_create(controller1, host, cfg, &peer_create_cb, 778 GNUNET_TESTBED_peer_create (controller1, host, cfg, &peer_create_cb,
777 &peer1); 779 &peer1);
778 if (NULL == peer1.operation) 780 if (NULL == peer1.operation)
779 { 781 {
780 GNUNET_break(0); 782 GNUNET_break (0);
781 abort_test(); 783 abort_test ();
782 return; 784 return;
783 } 785 }
784} 786}
785 787
786 788
@@ -794,59 +796,59 @@ registration_comp(void *cls, const char *emsg)
794 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case 796 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
795 */ 797 */
796static void 798static void
797status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *config, 799status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config,
798 int status) 800 int status)
799{ 801{
800 uint64_t event_mask; 802 uint64_t event_mask;
801 803
802 if (GNUNET_OK != status) 804 if (GNUNET_OK != status)
803 { 805 {
804 GNUNET_break(0); 806 GNUNET_break (0);
805 cp1 = NULL; 807 cp1 = NULL;
806 abort_test(); 808 abort_test ();
807 return; 809 return;
808 } 810 }
809 event_mask = 0; 811 event_mask = 0;
810 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); 812 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
811 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); 813 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
812 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); 814 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
813 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); 815 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
814 switch (result) 816 switch (result)
817 {
818 case INIT:
819 controller1 =
820 GNUNET_TESTBED_controller_connect (host, event_mask,
821 &controller_cb, NULL);
822 if (NULL == controller1)
815 { 823 {
816 case INIT: 824 GNUNET_break (0);
817 controller1 = 825 abort_test ();
818 GNUNET_TESTBED_controller_connect(host, event_mask, 826 return;
819 &controller_cb, NULL); 827 }
820 if (NULL == controller1) 828 result = CONTROLLER1_UP;
821 { 829 neighbour1 = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, cfg, 0);
822 GNUNET_break(0); 830 if (NULL == neighbour1)
823 abort_test(); 831 {
824 return; 832 GNUNET_break (0);
825 } 833 abort_test ();
826 result = CONTROLLER1_UP; 834 return;
827 neighbour1 = GNUNET_TESTBED_host_create("127.0.0.1", NULL, cfg, 0); 835 }
828 if (NULL == neighbour1) 836 reg_handle =
829 { 837 GNUNET_TESTBED_register_host (controller1, neighbour1,
830 GNUNET_break(0); 838 &registration_comp, neighbour1);
831 abort_test(); 839 if (NULL == reg_handle)
832 return; 840 {
833 } 841 GNUNET_break (0);
834 reg_handle = 842 abort_test ();
835 GNUNET_TESTBED_register_host(controller1, neighbour1,
836 &registration_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();
848 return; 843 return;
849 } 844 }
845 break;
846
847 default:
848 GNUNET_break (0);
849 abort_test ();
850 return;
851 }
850} 852}
851 853
852 854
@@ -861,25 +863,25 @@ status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *config,
861 * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not 863 * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not
862 */ 864 */
863static void 865static void
864host_habitable_cb(void *cls, 866host_habitable_cb (void *cls,
865 const struct GNUNET_TESTBED_Host *_host, 867 const struct GNUNET_TESTBED_Host *_host,
866 int status) 868 int status)
867{ 869{
868 hc_handle = NULL; 870 hc_handle = NULL;
869 if (GNUNET_NO == status) 871 if (GNUNET_NO == status)
870 { 872 {
871 (void)printf("%s", 873 (void) printf ("%s",
872 "Unable to run the test as this system is not configured " 874 "Unable to run the test as this system is not configured "
873 "to use password less SSH logins to localhost.\n" 875 "to use password less SSH logins to localhost.\n"
874 "Skipping test\n"); 876 "Skipping test\n");
875 GNUNET_SCHEDULER_cancel(abort_task); 877 GNUNET_SCHEDULER_cancel (abort_task);
876 abort_task = NULL; 878 abort_task = NULL;
877 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); 879 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
878 result = SKIP; 880 result = SKIP;
879 return; 881 return;
880 } 882 }
881 cp1 = 883 cp1 =
882 GNUNET_TESTBED_controller_start("127.0.0.1", host, status_cb, NULL); 884 GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb, NULL);
883} 885}
884 886
885 887
@@ -892,35 +894,35 @@ host_habitable_cb(void *cls,
892 * @param cfg the configuration file handle 894 * @param cfg the configuration file handle
893 */ 895 */
894static void 896static void
895run(void *cls, char *const *args, const char *cfgfile, 897run (void *cls, char *const *args, const char *cfgfile,
896 const struct GNUNET_CONFIGURATION_Handle *config) 898 const struct GNUNET_CONFIGURATION_Handle *config)
897{ 899{
898 cfg = GNUNET_CONFIGURATION_dup(config); 900 cfg = GNUNET_CONFIGURATION_dup (config);
899 host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0); 901 host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0);
900 if (NULL == host) 902 if (NULL == host)
901 { 903 {
902 GNUNET_break(0); 904 GNUNET_break (0);
903 abort_test(); 905 abort_test ();
904 return; 906 return;
905 } 907 }
906 if (NULL == 908 if (NULL ==
907 (hc_handle = 909 (hc_handle =
908 GNUNET_TESTBED_is_host_habitable(host, config, &host_habitable_cb, 910 GNUNET_TESTBED_is_host_habitable (host, config, &host_habitable_cb,
909 NULL))) 911 NULL)))
910 { 912 {
911 GNUNET_TESTBED_host_destroy(host); 913 GNUNET_TESTBED_host_destroy (host);
912 host = NULL; 914 host = NULL;
913 (void)printf("%s", 915 (void) printf ("%s",
914 "Unable to run the test as this system is not configured " 916 "Unable to run the test as this system is not configured "
915 "to use password less SSH logins to localhost.\n" 917 "to use password less SSH logins to localhost.\n"
916 "Skipping test\n"); 918 "Skipping test\n");
917 result = SKIP; 919 result = SKIP;
918 return; 920 return;
919 } 921 }
920 abort_task = 922 abort_task =
921 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 923 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
922 (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, 924 (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort,
923 NULL); 925 NULL);
924} 926}
925 927
926 928
@@ -928,7 +930,7 @@ run(void *cls, char *const *args, const char *cfgfile,
928 * Main function 930 * Main function
929 */ 931 */
930int 932int
931main(int argc, char **argv) 933main (int argc, char **argv)
932{ 934{
933 char *const argv2[] = { "test_testbed_api_3peers_3controllers", 935 char *const argv2[] = { "test_testbed_api_3peers_3controllers",
934 "-c", "test_testbed_api.conf", 936 "-c", "test_testbed_api.conf",
@@ -940,22 +942,22 @@ main(int argc, char **argv)
940 942
941 result = INIT; 943 result = INIT;
942 ret = 944 ret =
943 GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, 945 GNUNET_PROGRAM_run ((sizeof(argv2) / sizeof(char *)) - 1, argv2,
944 "test_testbed_api_3peers_3controllers", "nohelp", 946 "test_testbed_api_3peers_3controllers", "nohelp",
945 options, &run, NULL); 947 options, &run, NULL);
946 if (GNUNET_OK != ret) 948 if (GNUNET_OK != ret)
947 return 1; 949 return 1;
948 switch (result) 950 switch (result)
949 { 951 {
950 case SUCCESS: 952 case SUCCESS:
951 return 0; 953 return 0;
952 954
953 case SKIP: 955 case SKIP:
954 return 77; /* Mark test as skipped */ 956 return 77; /* Mark test as skipped */
955 957
956 default: 958 default:
957 return 1; 959 return 1;
958 } 960 }
959} 961}
960 962
961/* end of test_testbed_api_3peers_3controllers.c */ 963/* 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 b07dd5339..f80e73ddd 100644
--- a/src/testbed/test_testbed_api_barriers.c
+++ b/src/testbed/test_testbed_api_barriers.c
@@ -34,7 +34,7 @@
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
@@ -62,13 +62,13 @@ static int result;
62 * Handle SIGINT and SIGTERM 62 * Handle SIGINT and SIGTERM
63 */ 63 */
64static void 64static void
65shutdown_handler(void *cls) 65shutdown_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 */
80static void 80static void
81do_timeout(void *cls) 81do_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,43 +101,43 @@ do_timeout(void *cls)
101 * error messsage 101 * error messsage
102 */ 102 */
103static void 103static void
104barrier_cb(void *cls, 104barrier_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 121
122 case GNUNET_TESTBED_BARRIERSTATUS_ERROR: 122 case GNUNET_TESTBED_BARRIERSTATUS_ERROR:
123 LOG(GNUNET_ERROR_TYPE_ERROR, 123 LOG (GNUNET_ERROR_TYPE_ERROR,
124 "Barrier initialisation failed: %s", 124 "Barrier initialisation failed: %s",
125 (NULL == emsg) ? "unknown reason" : emsg); 125 (NULL == emsg) ? "unknown reason" : emsg);
126 break; 126 break;
127 127
128 case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: 128 case GNUNET_TESTBED_BARRIERSTATUS_CROSSED:
129 LOG(GNUNET_ERROR_TYPE_INFO, 129 LOG (GNUNET_ERROR_TYPE_INFO,
130 "Barrier crossed\n"); 130 "Barrier crossed\n");
131 if (old_status == GNUNET_TESTBED_BARRIERSTATUS_INITIALISED) 131 if (old_status == GNUNET_TESTBED_BARRIERSTATUS_INITIALISED)
132 result = GNUNET_OK; 132 result = GNUNET_OK;
133 break; 133 break;
134 134
135 default: 135 default:
136 GNUNET_assert(0); 136 GNUNET_assert (0);
137 return; 137 return;
138 } 138 }
139 barrier = NULL; 139 barrier = NULL;
140 GNUNET_SCHEDULER_shutdown(); 140 GNUNET_SCHEDULER_shutdown ();
141} 141}
142 142
143 143
@@ -154,35 +154,35 @@ barrier_cb(void *cls,
154 * failed 154 * failed
155 */ 155 */
156static void 156static void
157test_master(void *cls, 157test_master (void *cls,
158 struct GNUNET_TESTBED_RunHandle *h, 158 struct GNUNET_TESTBED_RunHandle *h,
159 unsigned int num_peers, 159 unsigned int num_peers,
160 struct GNUNET_TESTBED_Peer **peers_, 160 struct GNUNET_TESTBED_Peer **peers_,
161 unsigned int links_succeeded, 161 unsigned int links_succeeded,
162 unsigned int links_failed) 162 unsigned int links_failed)
163{ 163{
164 struct GNUNET_TESTBED_Controller *c; 164 struct GNUNET_TESTBED_Controller *c;
165 165
166 GNUNET_assert(NULL == cls); 166 GNUNET_assert (NULL == cls);
167 if (NULL == peers_) 167 if (NULL == peers_)
168 { 168 {
169 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 169 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
170 "Failing test due to timeout\n"); 170 "Failing test due to timeout\n");
171 return; 171 return;
172 } 172 }
173 GNUNET_assert(NUM_PEERS == num_peers); 173 GNUNET_assert (NUM_PEERS == num_peers);
174 c = GNUNET_TESTBED_run_get_controller_handle(h); 174 c = GNUNET_TESTBED_run_get_controller_handle (h);
175 barrier = GNUNET_TESTBED_barrier_init(c, 175 barrier = GNUNET_TESTBED_barrier_init (c,
176 TEST_BARRIER_NAME, 176 TEST_BARRIER_NAME,
177 100, 177 100,
178 &barrier_cb, 178 &barrier_cb,
179 NULL); 179 NULL);
180 timeout_task = 180 timeout_task =
181 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 181 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
182 (GNUNET_TIME_UNIT_SECONDS, 182 (GNUNET_TIME_UNIT_SECONDS,
183 10 * (NUM_PEERS + 1)), 183 10 * (NUM_PEERS + 1)),
184 &do_timeout, NULL); 184 &do_timeout, NULL);
185 GNUNET_SCHEDULER_add_shutdown(&shutdown_handler, NULL); 185 GNUNET_SCHEDULER_add_shutdown (&shutdown_handler, NULL);
186} 186}
187 187
188 188
@@ -198,7 +198,7 @@ test_master(void *cls,
198 * Main function 198 * Main function
199 */ 199 */
200int 200int
201main(int argc, char **argv) 201main (int argc, char **argv)
202{ 202{
203 struct GNUNET_CONFIGURATION_Handle *cfg; 203 struct GNUNET_CONFIGURATION_Handle *cfg;
204 char pwd[PATH_MAX]; 204 char pwd[PATH_MAX];
@@ -207,26 +207,27 @@ main(int argc, char **argv)
207 207
208 result = GNUNET_SYSERR; 208 result = GNUNET_SYSERR;
209 event_mask = 0; 209 event_mask = 0;
210 cfg = GNUNET_CONFIGURATION_create(); 210 cfg = GNUNET_CONFIGURATION_create ();
211 GNUNET_assert(GNUNET_YES == 211 GNUNET_assert (GNUNET_YES ==
212 GNUNET_CONFIGURATION_parse(cfg, 212 GNUNET_CONFIGURATION_parse (cfg,
213 "test_testbed_api_barriers.conf.in")); 213 "test_testbed_api_barriers.conf.in"));
214 if (NULL == getcwd(pwd, PATH_MAX)) 214 if (NULL == getcwd (pwd, PATH_MAX))
215 return 1; 215 return 1;
216 GNUNET_assert(0 < GNUNET_asprintf(&binary, "%s/%s", pwd, 216 GNUNET_assert (0 < GNUNET_asprintf (&binary, "%s/%s", pwd,
217 "gnunet-service-test-barriers")); 217 "gnunet-service-test-barriers"));
218 GNUNET_CONFIGURATION_set_value_string(cfg, "test-barriers", "BINARY", binary); 218 GNUNET_CONFIGURATION_set_value_string (cfg, "test-barriers", "BINARY",
219 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_write 219 binary);
220 (cfg, "test_testbed_api_barriers.conf")); 220 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write
221 GNUNET_CONFIGURATION_destroy(cfg); 221 (cfg, "test_testbed_api_barriers.conf"));
222 GNUNET_CONFIGURATION_destroy (cfg);
222 cfg = NULL; 223 cfg = NULL;
223 GNUNET_free(binary); 224 GNUNET_free (binary);
224 binary = NULL; 225 binary = NULL;
225 (void)GNUNET_TESTBED_test_run("test_testbed_api_barriers", 226 (void) GNUNET_TESTBED_test_run ("test_testbed_api_barriers",
226 "test_testbed_api_barriers.conf", NUM_PEERS, 227 "test_testbed_api_barriers.conf", NUM_PEERS,
227 event_mask, NULL, NULL, 228 event_mask, NULL, NULL,
228 &test_master, NULL); 229 &test_master, NULL);
229 (void)unlink("test_testbed_api_barriers.conf"); 230 (void) unlink ("test_testbed_api_barriers.conf");
230 if (GNUNET_OK != result) 231 if (GNUNET_OK != result)
231 return 1; 232 return 1;
232 return 0; 233 return 0;
diff --git a/src/testbed/test_testbed_api_barriers.h b/src/testbed/test_testbed_api_barriers.h
index dbcdbd80f..c0a34472d 100644
--- a/src/testbed/test_testbed_api_barriers.h
+++ b/src/testbed/test_testbed_api_barriers.h
@@ -1,4 +1,3 @@
1
2/** 1/**
3 * The name to use for the barrier in the test cases 2 * The name to use for the barrier in the test cases
4 */ 3 */
diff --git a/src/testbed/test_testbed_api_controllerlink.c b/src/testbed/test_testbed_api_controllerlink.c
index ffcbebf00..55ec184ea 100644
--- a/src/testbed/test_testbed_api_controllerlink.c
+++ b/src/testbed/test_testbed_api_controllerlink.c
@@ -45,17 +45,18 @@
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 */
58enum Stage { 58enum Stage
59{
59 /** 60 /**
60 * Initial stage 61 * Initial stage
61 */ 62 */
@@ -292,17 +293,17 @@ static enum Stage result;
292 */ 293 */
293#define FAIL_TEST(cond) \ 294#define FAIL_TEST(cond) \
294 do \ 295 do \
295 { \ 296 { \
296 if (!(cond)) \ 297 if (! (cond)) \
297 { \ 298 { \
298 GNUNET_break(0); \ 299 GNUNET_break (0); \
299 if (NULL != abort_task) \ 300 if (NULL != abort_task) \
300 GNUNET_SCHEDULER_cancel (abort_task); \ 301 GNUNET_SCHEDULER_cancel (abort_task); \
301 abort_task = NULL; \ 302 abort_task = NULL; \
302 GNUNET_SCHEDULER_shutdown(); \ 303 GNUNET_SCHEDULER_shutdown (); \
303 return; \ 304 return; \
304 } \ 305 } \
305 } while (0) 306 } while (0)
306 307
307 308
308/** 309/**
@@ -311,40 +312,40 @@ static enum Stage result;
311 * @param cls NULL 312 * @param cls NULL
312 */ 313 */
313static void 314static void
314do_shutdown(void *cls) 315do_shutdown (void *cls)
315{ 316{
316 if (NULL != abort_task) 317 if (NULL != abort_task)
317 GNUNET_SCHEDULER_cancel(abort_task); 318 GNUNET_SCHEDULER_cancel (abort_task);
318 if (NULL != delay_task_id) 319 if (NULL != delay_task_id)
319 { 320 {
320 GNUNET_SCHEDULER_cancel(delay_task_id); 321 GNUNET_SCHEDULER_cancel (delay_task_id);
321 delay_task_id = NULL; 322 delay_task_id = NULL;
322 } 323 }
323 if (NULL != hc_handle) 324 if (NULL != hc_handle)
324 GNUNET_TESTBED_is_host_habitable_cancel(hc_handle); 325 GNUNET_TESTBED_is_host_habitable_cancel (hc_handle);
325 if (NULL != op) 326 if (NULL != op)
326 { 327 {
327 GNUNET_TESTBED_operation_done(op); 328 GNUNET_TESTBED_operation_done (op);
328 op = NULL; 329 op = NULL;
329 } 330 }
330 if (NULL != mc) 331 if (NULL != mc)
331 GNUNET_TESTBED_controller_disconnect(mc); 332 GNUNET_TESTBED_controller_disconnect (mc);
332 if (NULL != cp) 333 if (NULL != cp)
333 GNUNET_TESTBED_controller_stop(cp); 334 GNUNET_TESTBED_controller_stop (cp);
334 if (NULL != slave3) 335 if (NULL != slave3)
335 GNUNET_TESTBED_host_destroy(slave3); 336 GNUNET_TESTBED_host_destroy (slave3);
336 if (NULL != slave2) 337 if (NULL != slave2)
337 GNUNET_TESTBED_host_destroy(slave2); 338 GNUNET_TESTBED_host_destroy (slave2);
338 if (NULL != slave) 339 if (NULL != slave)
339 GNUNET_TESTBED_host_destroy(slave); 340 GNUNET_TESTBED_host_destroy (slave);
340 if (NULL != host) 341 if (NULL != host)
341 GNUNET_TESTBED_host_destroy(host); 342 GNUNET_TESTBED_host_destroy (host);
342 if (NULL != cfg) 343 if (NULL != cfg)
343 GNUNET_CONFIGURATION_destroy(cfg); 344 GNUNET_CONFIGURATION_destroy (cfg);
344 if (NULL != cfg3) 345 if (NULL != cfg3)
345 GNUNET_CONFIGURATION_destroy(cfg3); 346 GNUNET_CONFIGURATION_destroy (cfg3);
346 if (NULL != rh) 347 if (NULL != rh)
347 GNUNET_TESTBED_cancel_registration(rh); 348 GNUNET_TESTBED_cancel_registration (rh);
348} 349}
349 350
350 351
@@ -354,11 +355,11 @@ do_shutdown(void *cls)
354 * @param cls NULL 355 * @param cls NULL
355 */ 356 */
356static void 357static void
357do_abort(void *cls) 358do_abort (void *cls)
358{ 359{
359 LOG(GNUNET_ERROR_TYPE_WARNING, "Aborting in stage %d\n", result); 360 LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting in stage %d\n", result);
360 abort_task = NULL; 361 abort_task = NULL;
361 GNUNET_SCHEDULER_shutdown(); 362 GNUNET_SCHEDULER_shutdown ();
362} 363}
363 364
364 365
@@ -369,11 +370,11 @@ do_abort(void *cls)
369 * @return 370 * @return
370 */ 371 */
371static void 372static void
372do_abort_now(void *cls) 373do_abort_now (void *cls)
373{ 374{
374 if (NULL != abort_task) 375 if (NULL != abort_task)
375 GNUNET_SCHEDULER_cancel(abort_task); 376 GNUNET_SCHEDULER_cancel (abort_task);
376 abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); 377 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
377} 378}
378 379
379 380
@@ -384,7 +385,7 @@ do_abort_now(void *cls)
384 * @param emsg the error message; NULL if host registration is successful 385 * @param emsg the error message; NULL if host registration is successful
385 */ 386 */
386static void 387static void
387registration_cont(void *cls, const char *emsg); 388registration_cont (void *cls, const char *emsg);
388 389
389 390
390/** 391/**
@@ -394,29 +395,29 @@ registration_cont(void *cls, const char *emsg);
394 * @return 395 * @return
395 */ 396 */
396static void 397static void
397delay_task(void *cls) 398delay_task (void *cls)
398{ 399{
399 delay_task_id = NULL; 400 delay_task_id = NULL;
400 switch (result) 401 switch (result)
401 { 402 {
402 case SLAVE2_PEER_CREATE_SUCCESS: 403 case SLAVE2_PEER_CREATE_SUCCESS:
403 op = GNUNET_TESTBED_peer_stop(NULL, slave1_peer, NULL, NULL); 404 op = GNUNET_TESTBED_peer_stop (NULL, slave1_peer, NULL, NULL);
404 FAIL_TEST(NULL != op); 405 FAIL_TEST (NULL != op);
405 break; 406 break;
406 407
407 case MASTER_SLAVE2_PEERS_CONNECTED: 408 case MASTER_SLAVE2_PEERS_CONNECTED:
408 slave3 = GNUNET_TESTBED_host_create_with_id(3, "127.0.0.1", NULL, cfg, 0); 409 slave3 = GNUNET_TESTBED_host_create_with_id (3, "127.0.0.1", NULL, cfg, 0);
409 rh = GNUNET_TESTBED_register_host(mc, slave3, &registration_cont, NULL); 410 rh = GNUNET_TESTBED_register_host (mc, slave3, &registration_cont, NULL);
410 break; 411 break;
411 412
412 case SLAVE2_SLAVE3_PEERS_CONNECTED: 413 case SLAVE2_SLAVE3_PEERS_CONNECTED:
413 op = GNUNET_TESTBED_peer_stop(NULL, slave2_peer, NULL, NULL); 414 op = GNUNET_TESTBED_peer_stop (NULL, slave2_peer, NULL, NULL);
414 FAIL_TEST(NULL != op); 415 FAIL_TEST (NULL != op);
415 break; 416 break;
416 417
417 default: 418 default:
418 FAIL_TEST(0); 419 FAIL_TEST (0);
419 } 420 }
420} 421}
421 422
422 423
@@ -430,48 +431,48 @@ delay_task(void *cls)
430 * @param emsg NULL if peer is not NULL; else MAY contain the error description 431 * @param emsg NULL if peer is not NULL; else MAY contain the error description
431 */ 432 */
432static void 433static void
433peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) 434peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
434{ 435{
435 FAIL_TEST(NULL != peer); 436 FAIL_TEST (NULL != peer);
436 FAIL_TEST(NULL == emsg); 437 FAIL_TEST (NULL == emsg);
437 switch (result) 438 switch (result)
438 { 439 {
439 case MASTER_STARTED: 440 case MASTER_STARTED:
440 result = MASTER_PEER_CREATE_SUCCESS; 441 result = MASTER_PEER_CREATE_SUCCESS;
441 master_peer = peer; 442 master_peer = peer;
442 GNUNET_TESTBED_operation_done(op); 443 GNUNET_TESTBED_operation_done (op);
443 op = GNUNET_TESTBED_peer_start(NULL, master_peer, NULL, NULL); 444 op = GNUNET_TESTBED_peer_start (NULL, master_peer, NULL, NULL);
444 break; 445 break;
445 446
446 case SLAVE1_LINK_SUCCESS: 447 case SLAVE1_LINK_SUCCESS:
447 result = SLAVE1_PEER_CREATE_SUCCESS; 448 result = SLAVE1_PEER_CREATE_SUCCESS;
448 slave1_peer = peer; 449 slave1_peer = peer;
449 GNUNET_TESTBED_operation_done(op); 450 GNUNET_TESTBED_operation_done (op);
450 op = GNUNET_TESTBED_peer_start(NULL, slave1_peer, NULL, NULL); 451 op = GNUNET_TESTBED_peer_start (NULL, slave1_peer, NULL, NULL);
451 break; 452 break;
452 453
453 case SLAVE2_LINK_SUCCESS: 454 case SLAVE2_LINK_SUCCESS:
454 result = SLAVE2_PEER_CREATE_SUCCESS; 455 result = SLAVE2_PEER_CREATE_SUCCESS;
455 slave2_peer = peer; 456 slave2_peer = peer;
456 GNUNET_TESTBED_operation_done(op); 457 GNUNET_TESTBED_operation_done (op);
457 op = NULL; 458 op = NULL;
458 delay_task_id = GNUNET_SCHEDULER_add_delayed( 459 delay_task_id = GNUNET_SCHEDULER_add_delayed (
459 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), 460 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
460 &delay_task, 461 &delay_task,
461 NULL); 462 NULL);
462 return; 463 return;
463 464
464 case SLAVE3_STARTED: 465 case SLAVE3_STARTED:
465 result = SLAVE3_PEER_CREATE_SUCCESS; 466 result = SLAVE3_PEER_CREATE_SUCCESS;
466 slave3_peer = peer; 467 slave3_peer = peer;
467 GNUNET_TESTBED_operation_done(op); 468 GNUNET_TESTBED_operation_done (op);
468 op = GNUNET_TESTBED_peer_start(NULL, slave3_peer, NULL, NULL); 469 op = GNUNET_TESTBED_peer_start (NULL, slave3_peer, NULL, NULL);
469 break; 470 break;
470 471
471 default: 472 default:
472 FAIL_TEST(0); 473 FAIL_TEST (0);
473 } 474 }
474 FAIL_TEST(NULL != op); 475 FAIL_TEST (NULL != op);
475} 476}
476 477
477 478
@@ -482,14 +483,14 @@ peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
482 * @param event the event information to check 483 * @param event the event information to check
483 */ 484 */
484static void 485static void
485check_operation_success(const struct GNUNET_TESTBED_EventInformation *event) 486check_operation_success (const struct GNUNET_TESTBED_EventInformation *event)
486{ 487{
487 FAIL_TEST(NULL != event); 488 FAIL_TEST (NULL != event);
488 FAIL_TEST(GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); 489 FAIL_TEST (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
489 FAIL_TEST(event->op == op); 490 FAIL_TEST (event->op == op);
490 FAIL_TEST(NULL == event->op_cls); 491 FAIL_TEST (NULL == event->op_cls);
491 FAIL_TEST(NULL == event->details.operation_finished.emsg); 492 FAIL_TEST (NULL == event->details.operation_finished.emsg);
492 FAIL_TEST(NULL == event->details.operation_finished.generic); 493 FAIL_TEST (NULL == event->details.operation_finished.generic);
493} 494}
494 495
495 496
@@ -501,180 +502,180 @@ check_operation_success(const struct GNUNET_TESTBED_EventInformation *event)
501 * @param event information about the event 502 * @param event information about the event
502 */ 503 */
503static void 504static void
504controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) 505controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
505{ 506{
506 switch (result) 507 switch (result)
507 { 508 {
508 case SLAVE2_REGISTERED: 509 case SLAVE2_REGISTERED:
509 check_operation_success(event); 510 check_operation_success (event);
510 GNUNET_TESTBED_operation_done(op); 511 GNUNET_TESTBED_operation_done (op);
511 op = NULL; 512 op = NULL;
512 result = SLAVE1_LINK_SUCCESS; 513 result = SLAVE1_LINK_SUCCESS;
513 FAIL_TEST(NULL != slave2); 514 FAIL_TEST (NULL != slave2);
514 FAIL_TEST(NULL != slave); 515 FAIL_TEST (NULL != slave);
515 op = GNUNET_TESTBED_peer_create(mc, slave, cfg, peer_create_cb, NULL); 516 op = GNUNET_TESTBED_peer_create (mc, slave, cfg, peer_create_cb, NULL);
516 FAIL_TEST(NULL != op); 517 FAIL_TEST (NULL != op);
517 break; 518 break;
518 519
519 case SLAVE1_PEER_START_SUCCESS: 520 case SLAVE1_PEER_START_SUCCESS:
520 check_operation_success(event); 521 check_operation_success (event);
521 GNUNET_TESTBED_operation_done(op); 522 GNUNET_TESTBED_operation_done (op);
522 result = SLAVE2_LINK_SUCCESS; 523 result = SLAVE2_LINK_SUCCESS;
523 op = GNUNET_TESTBED_peer_create(mc, slave2, cfg, peer_create_cb, NULL); 524 op = GNUNET_TESTBED_peer_create (mc, slave2, cfg, peer_create_cb, NULL);
524 FAIL_TEST(NULL != op); 525 FAIL_TEST (NULL != op);
525 break; 526 break;
526 527
527 case MASTER_PEER_CREATE_SUCCESS: 528 case MASTER_PEER_CREATE_SUCCESS:
528 FAIL_TEST(GNUNET_TESTBED_ET_PEER_START == event->type); 529 FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type);
529 FAIL_TEST(event->details.peer_start.host == host); 530 FAIL_TEST (event->details.peer_start.host == host);
530 FAIL_TEST(event->details.peer_start.peer == master_peer); 531 FAIL_TEST (event->details.peer_start.peer == master_peer);
531 GNUNET_TESTBED_operation_done(op); 532 GNUNET_TESTBED_operation_done (op);
532 op = NULL; 533 op = NULL;
533 result = MASTER_PEER_START_SUCCESS; 534 result = MASTER_PEER_START_SUCCESS;
534 slave = GNUNET_TESTBED_host_create_with_id(1, "127.0.0.1", NULL, cfg, 0); 535 slave = GNUNET_TESTBED_host_create_with_id (1, "127.0.0.1", NULL, cfg, 0);
535 FAIL_TEST(NULL != slave); 536 FAIL_TEST (NULL != slave);
536 rh = GNUNET_TESTBED_register_host(mc, slave, &registration_cont, NULL); 537 rh = GNUNET_TESTBED_register_host (mc, slave, &registration_cont, NULL);
537 FAIL_TEST(NULL != rh); 538 FAIL_TEST (NULL != rh);
538 break; 539 break;
539 540
540 case SLAVE1_PEER_CREATE_SUCCESS: 541 case SLAVE1_PEER_CREATE_SUCCESS:
541 FAIL_TEST(GNUNET_TESTBED_ET_PEER_START == event->type); 542 FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type);
542 FAIL_TEST(event->details.peer_start.host == slave); 543 FAIL_TEST (event->details.peer_start.host == slave);
543 FAIL_TEST(event->details.peer_start.peer == slave1_peer); 544 FAIL_TEST (event->details.peer_start.peer == slave1_peer);
544 GNUNET_TESTBED_operation_done(op); 545 GNUNET_TESTBED_operation_done (op);
545 result = SLAVE1_PEER_START_SUCCESS; 546 result = SLAVE1_PEER_START_SUCCESS;
546 op = GNUNET_TESTBED_controller_link(NULL, mc, slave2, slave, GNUNET_YES); 547 op = GNUNET_TESTBED_controller_link (NULL, mc, slave2, slave, GNUNET_YES);
547 break; 548 break;
548 549
549 case SLAVE2_PEER_CREATE_SUCCESS: 550 case SLAVE2_PEER_CREATE_SUCCESS:
550 FAIL_TEST(GNUNET_TESTBED_ET_PEER_STOP == event->type); 551 FAIL_TEST (GNUNET_TESTBED_ET_PEER_STOP == event->type);
551 FAIL_TEST(event->details.peer_stop.peer == slave1_peer); 552 FAIL_TEST (event->details.peer_stop.peer == slave1_peer);
552 GNUNET_TESTBED_operation_done(op); 553 GNUNET_TESTBED_operation_done (op);
553 result = SLAVE1_PEER_STOP_SUCCESS; 554 result = SLAVE1_PEER_STOP_SUCCESS;
554 op = GNUNET_TESTBED_peer_start(NULL, slave2_peer, NULL, NULL); 555 op = GNUNET_TESTBED_peer_start (NULL, slave2_peer, NULL, NULL);
555 FAIL_TEST(NULL != op); 556 FAIL_TEST (NULL != op);
556 break; 557 break;
557 558
558 case SLAVE3_PEER_CREATE_SUCCESS: 559 case SLAVE3_PEER_CREATE_SUCCESS:
559 FAIL_TEST(GNUNET_TESTBED_ET_PEER_START == event->type); 560 FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type);
560 FAIL_TEST(event->details.peer_start.host == slave3); 561 FAIL_TEST (event->details.peer_start.host == slave3);
561 FAIL_TEST(event->details.peer_start.peer == slave3_peer); 562 FAIL_TEST (event->details.peer_start.peer == slave3_peer);
562 GNUNET_TESTBED_operation_done(op); 563 GNUNET_TESTBED_operation_done (op);
563 result = SLAVE3_PEER_START_SUCCESS; 564 result = SLAVE3_PEER_START_SUCCESS;
564 sleep(1); 565 sleep (1);
565 LOG_DEBUG("**************************************\n"); 566 LOG_DEBUG ("**************************************\n");
566 op = 567 op =
567 GNUNET_TESTBED_overlay_connect(mc, NULL, NULL, slave2_peer, slave3_peer); 568 GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, slave2_peer, slave3_peer);
568 FAIL_TEST(NULL != op); 569 FAIL_TEST (NULL != op);
569 break; 570 break;
570 571
571 case SLAVE3_PEER_START_SUCCESS: 572 case SLAVE3_PEER_START_SUCCESS:
572 FAIL_TEST(NULL != event); 573 FAIL_TEST (NULL != event);
573 FAIL_TEST(GNUNET_TESTBED_ET_CONNECT == event->type); 574 FAIL_TEST (GNUNET_TESTBED_ET_CONNECT == event->type);
574 FAIL_TEST(event->details.peer_connect.peer1 == slave2_peer); 575 FAIL_TEST (event->details.peer_connect.peer1 == slave2_peer);
575 FAIL_TEST(event->details.peer_connect.peer2 == slave3_peer); 576 FAIL_TEST (event->details.peer_connect.peer2 == slave3_peer);
576 result = SLAVE2_SLAVE3_PEERS_CONNECTED; 577 result = SLAVE2_SLAVE3_PEERS_CONNECTED;
577 GNUNET_TESTBED_operation_done(op); 578 GNUNET_TESTBED_operation_done (op);
578 op = NULL; 579 op = NULL;
579 delay_task_id = GNUNET_SCHEDULER_add_delayed( 580 delay_task_id = GNUNET_SCHEDULER_add_delayed (
580 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), 581 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
581 &delay_task, 582 &delay_task,
582 NULL); 583 NULL);
583 break; 584 break;
584 585
585 case SLAVE1_PEER_STOP_SUCCESS: 586 case SLAVE1_PEER_STOP_SUCCESS:
586 FAIL_TEST(GNUNET_TESTBED_ET_PEER_START == event->type); 587 FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type);
587 FAIL_TEST(event->details.peer_start.host == slave2); 588 FAIL_TEST (event->details.peer_start.host == slave2);
588 FAIL_TEST(event->details.peer_start.peer == slave2_peer); 589 FAIL_TEST (event->details.peer_start.peer == slave2_peer);
589 GNUNET_TESTBED_operation_done(op); 590 GNUNET_TESTBED_operation_done (op);
590 result = SLAVE2_PEER_START_SUCCESS; 591 result = SLAVE2_PEER_START_SUCCESS;
591 op = 592 op =
592 GNUNET_TESTBED_overlay_connect(mc, NULL, NULL, master_peer, slave2_peer); 593 GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, master_peer, slave2_peer);
593 break; 594 break;
594 595
595 case SLAVE2_PEER_START_SUCCESS: 596 case SLAVE2_PEER_START_SUCCESS:
596 FAIL_TEST(NULL != event); 597 FAIL_TEST (NULL != event);
597 FAIL_TEST(GNUNET_TESTBED_ET_CONNECT == event->type); 598 FAIL_TEST (GNUNET_TESTBED_ET_CONNECT == event->type);
598 FAIL_TEST(event->details.peer_connect.peer1 == master_peer); 599 FAIL_TEST (event->details.peer_connect.peer1 == master_peer);
599 FAIL_TEST(event->details.peer_connect.peer2 == slave2_peer); 600 FAIL_TEST (event->details.peer_connect.peer2 == slave2_peer);
600 result = MASTER_SLAVE2_PEERS_CONNECTED; 601 result = MASTER_SLAVE2_PEERS_CONNECTED;
601 GNUNET_TESTBED_operation_done(op); 602 GNUNET_TESTBED_operation_done (op);
602 op = NULL; 603 op = NULL;
603 delay_task_id = GNUNET_SCHEDULER_add_delayed( 604 delay_task_id = GNUNET_SCHEDULER_add_delayed (
604 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), 605 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
605 &delay_task, 606 &delay_task,
606 NULL); 607 NULL);
607 break; 608 break;
608 609
609 case SLAVE2_SLAVE3_PEERS_CONNECTED: 610 case SLAVE2_SLAVE3_PEERS_CONNECTED:
610 FAIL_TEST(GNUNET_TESTBED_ET_PEER_STOP == event->type); 611 FAIL_TEST (GNUNET_TESTBED_ET_PEER_STOP == event->type);
611 FAIL_TEST(event->details.peer_stop.peer == slave2_peer); 612 FAIL_TEST (event->details.peer_stop.peer == slave2_peer);
612 GNUNET_TESTBED_operation_done(op); 613 GNUNET_TESTBED_operation_done (op);
613 result = SLAVE2_PEER_STOP_SUCCESS; 614 result = SLAVE2_PEER_STOP_SUCCESS;
614 op = GNUNET_TESTBED_peer_destroy(slave1_peer); 615 op = GNUNET_TESTBED_peer_destroy (slave1_peer);
615 FAIL_TEST(NULL != op); 616 FAIL_TEST (NULL != op);
616 break; 617 break;
617 618
618 case SLAVE2_PEER_STOP_SUCCESS: 619 case SLAVE2_PEER_STOP_SUCCESS:
619 check_operation_success(event); 620 check_operation_success (event);
620 GNUNET_TESTBED_operation_done(op); 621 GNUNET_TESTBED_operation_done (op);
621 result = SLAVE1_PEER_DESTROY_SUCCESS; 622 result = SLAVE1_PEER_DESTROY_SUCCESS;
622 op = GNUNET_TESTBED_peer_destroy(slave2_peer); 623 op = GNUNET_TESTBED_peer_destroy (slave2_peer);
623 FAIL_TEST(NULL != op); 624 FAIL_TEST (NULL != op);
624 break; 625 break;
625 626
626 case SLAVE1_PEER_DESTROY_SUCCESS: 627 case SLAVE1_PEER_DESTROY_SUCCESS:
627 check_operation_success(event); 628 check_operation_success (event);
628 GNUNET_TESTBED_operation_done(op); 629 GNUNET_TESTBED_operation_done (op);
629 op = NULL; 630 op = NULL;
630 result = SLAVE2_PEER_DESTROY_SUCCESS; 631 result = SLAVE2_PEER_DESTROY_SUCCESS;
631 op = GNUNET_TESTBED_get_slave_config(NULL, mc, slave3); 632 op = GNUNET_TESTBED_get_slave_config (NULL, mc, slave3);
632 FAIL_TEST(NULL != op); 633 FAIL_TEST (NULL != op);
633 break; 634 break;
634 635
635 case SLAVE2_PEER_DESTROY_SUCCESS: 636 case SLAVE2_PEER_DESTROY_SUCCESS:
636 FAIL_TEST(NULL != event); 637 FAIL_TEST (NULL != event);
637 FAIL_TEST(GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); 638 FAIL_TEST (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
638 FAIL_TEST(event->op == op); 639 FAIL_TEST (event->op == op);
639 FAIL_TEST(NULL == event->op_cls); 640 FAIL_TEST (NULL == event->op_cls);
640 FAIL_TEST(NULL == event->details.operation_finished.emsg); 641 FAIL_TEST (NULL == event->details.operation_finished.emsg);
641 cfg3 = GNUNET_CONFIGURATION_dup(event->details.operation_finished.generic); 642 cfg3 = GNUNET_CONFIGURATION_dup (event->details.operation_finished.generic);
642 GNUNET_TESTBED_operation_done(op); 643 GNUNET_TESTBED_operation_done (op);
643 result = SLAVE3_GET_CONFIG_SUCCESS; 644 result = SLAVE3_GET_CONFIG_SUCCESS;
644 op = GNUNET_TESTBED_controller_link(NULL, mc, slave3, slave, GNUNET_NO); 645 op = GNUNET_TESTBED_controller_link (NULL, mc, slave3, slave, GNUNET_NO);
645 break; 646 break;
646 647
647 case SLAVE3_REGISTERED: 648 case SLAVE3_REGISTERED:
648 check_operation_success(event); 649 check_operation_success (event);
649 GNUNET_TESTBED_operation_done(op); 650 GNUNET_TESTBED_operation_done (op);
650 result = SLAVE3_STARTED; 651 result = SLAVE3_STARTED;
651 op = GNUNET_TESTBED_peer_create(mc, slave3, cfg, peer_create_cb, NULL); 652 op = GNUNET_TESTBED_peer_create (mc, slave3, cfg, peer_create_cb, NULL);
652 FAIL_TEST(NULL != op); 653 FAIL_TEST (NULL != op);
653 break; 654 break;
654 655
655 case SLAVE3_GET_CONFIG_SUCCESS: 656 case SLAVE3_GET_CONFIG_SUCCESS:
656 result = SLAVE3_LINK_SUCCESS; 657 result = SLAVE3_LINK_SUCCESS;
657 GNUNET_TESTBED_operation_done(op); 658 GNUNET_TESTBED_operation_done (op);
658 op = GNUNET_TESTBED_peer_destroy(master_peer); 659 op = GNUNET_TESTBED_peer_destroy (master_peer);
659 break; 660 break;
660 661
661 case SLAVE3_LINK_SUCCESS: 662 case SLAVE3_LINK_SUCCESS:
662 check_operation_success(event); 663 check_operation_success (event);
663 result = MASTER_PEER_DESTROY_SUCCESS; 664 result = MASTER_PEER_DESTROY_SUCCESS;
664 GNUNET_TESTBED_operation_done(op); 665 GNUNET_TESTBED_operation_done (op);
665 op = GNUNET_TESTBED_peer_destroy(slave3_peer); 666 op = GNUNET_TESTBED_peer_destroy (slave3_peer);
666 break; 667 break;
667 668
668 case MASTER_PEER_DESTROY_SUCCESS: 669 case MASTER_PEER_DESTROY_SUCCESS:
669 result = SUCCESS; 670 result = SUCCESS;
670 GNUNET_TESTBED_operation_done(op); 671 GNUNET_TESTBED_operation_done (op);
671 op = NULL; 672 op = NULL;
672 GNUNET_SCHEDULER_shutdown(); 673 GNUNET_SCHEDULER_shutdown ();
673 break; 674 break;
674 675
675 default: 676 default:
676 FAIL_TEST(0); 677 FAIL_TEST (0);
677 } 678 }
678} 679}
679 680
680 681
@@ -685,43 +686,43 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
685 * @param emsg the error message; NULL if host registration is successful 686 * @param emsg the error message; NULL if host registration is successful
686 */ 687 */
687static void 688static void
688registration_cont(void *cls, const char *emsg) 689registration_cont (void *cls, const char *emsg)
689{ 690{
690 rh = NULL; 691 rh = NULL;
691 switch (result) 692 switch (result)
692 { 693 {
693 case MASTER_PEER_START_SUCCESS: 694 case MASTER_PEER_START_SUCCESS:
694 FAIL_TEST(NULL == emsg); 695 FAIL_TEST (NULL == emsg);
695 FAIL_TEST(NULL != mc); 696 FAIL_TEST (NULL != mc);
696 result = SLAVE1_REGISTERED; 697 result = SLAVE1_REGISTERED;
697 slave2 = GNUNET_TESTBED_host_create_with_id(2, "127.0.0.1", NULL, cfg, 0); 698 slave2 = GNUNET_TESTBED_host_create_with_id (2, "127.0.0.1", NULL, cfg, 0);
698 FAIL_TEST(NULL != slave2); 699 FAIL_TEST (NULL != slave2);
699 rh = GNUNET_TESTBED_register_host(mc, slave2, &registration_cont, NULL); 700 rh = GNUNET_TESTBED_register_host (mc, slave2, &registration_cont, NULL);
700 FAIL_TEST(NULL != rh); 701 FAIL_TEST (NULL != rh);
701 break; 702 break;
702 703
703 case SLAVE1_REGISTERED: 704 case SLAVE1_REGISTERED:
704 FAIL_TEST(NULL == emsg); 705 FAIL_TEST (NULL == emsg);
705 FAIL_TEST(NULL != mc); 706 FAIL_TEST (NULL != mc);
706 result = SLAVE2_REGISTERED; 707 result = SLAVE2_REGISTERED;
707 FAIL_TEST(NULL != cfg); 708 FAIL_TEST (NULL != cfg);
708 op = GNUNET_TESTBED_controller_link(NULL, mc, slave, NULL, GNUNET_YES); 709 op = GNUNET_TESTBED_controller_link (NULL, mc, slave, NULL, GNUNET_YES);
709 FAIL_TEST(NULL != op); 710 FAIL_TEST (NULL != op);
710 break; 711 break;
711 712
712 case MASTER_SLAVE2_PEERS_CONNECTED: 713 case MASTER_SLAVE2_PEERS_CONNECTED:
713 FAIL_TEST(NULL == emsg); 714 FAIL_TEST (NULL == emsg);
714 FAIL_TEST(NULL != mc); 715 FAIL_TEST (NULL != mc);
715 FAIL_TEST(NULL == op); 716 FAIL_TEST (NULL == op);
716 result = SLAVE3_REGISTERED; 717 result = SLAVE3_REGISTERED;
717 op = GNUNET_TESTBED_controller_link(NULL, mc, slave3, NULL, GNUNET_YES); 718 op = GNUNET_TESTBED_controller_link (NULL, mc, slave3, NULL, GNUNET_YES);
718 FAIL_TEST(NULL != op); 719 FAIL_TEST (NULL != op);
719 break; 720 break;
720 721
721 default: 722 default:
722 GNUNET_break(0); 723 GNUNET_break (0);
723 do_abort_now(NULL); 724 do_abort_now (NULL);
724 } 725 }
725} 726}
726 727
727/** 728/**
@@ -734,34 +735,34 @@ registration_cont(void *cls, const char *emsg)
734 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case 735 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
735 */ 736 */
736static void 737static void
737status_cb(void *cls, 738status_cb (void *cls,
738 const struct GNUNET_CONFIGURATION_Handle *config, 739 const struct GNUNET_CONFIGURATION_Handle *config,
739 int status) 740 int status)
740{ 741{
741 switch (result) 742 switch (result)
742 { 743 {
743 case INIT: 744 case INIT:
744 FAIL_TEST(GNUNET_OK == status); 745 FAIL_TEST (GNUNET_OK == status);
745 event_mask = 0; 746 event_mask = 0;
746 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); 747 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
747 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); 748 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
748 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); 749 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
749 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); 750 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
750 mc = GNUNET_TESTBED_controller_connect(host, 751 mc = GNUNET_TESTBED_controller_connect (host,
751 event_mask, 752 event_mask,
752 &controller_cb, 753 &controller_cb,
753 NULL); 754 NULL);
754 FAIL_TEST(NULL != mc); 755 FAIL_TEST (NULL != mc);
755 result = MASTER_STARTED; 756 result = MASTER_STARTED;
756 op = GNUNET_TESTBED_peer_create(mc, host, cfg, peer_create_cb, NULL); 757 op = GNUNET_TESTBED_peer_create (mc, host, cfg, peer_create_cb, NULL);
757 FAIL_TEST(NULL != op); 758 FAIL_TEST (NULL != op);
758 break; 759 break;
759 760
760 default: 761 default:
761 GNUNET_break(0); 762 GNUNET_break (0);
762 cp = NULL; 763 cp = NULL;
763 do_abort_now(NULL); 764 do_abort_now (NULL);
764 } 765 }
765} 766}
766 767
767 768
@@ -776,24 +777,24 @@ status_cb(void *cls,
776 * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not 777 * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not
777 */ 778 */
778static void 779static void
779host_habitable_cb(void *cls, 780host_habitable_cb (void *cls,
780 const struct GNUNET_TESTBED_Host *_host, 781 const struct GNUNET_TESTBED_Host *_host,
781 int status) 782 int status)
782{ 783{
783 hc_handle = NULL; 784 hc_handle = NULL;
784 if (GNUNET_NO == status) 785 if (GNUNET_NO == status)
785 { 786 {
786 (void)printf("%s", 787 (void) printf ("%s",
787 "Unable to run the test as this system is not configured " 788 "Unable to run the test as this system is not configured "
788 "to use password less SSH logins to localhost.\n" 789 "to use password less SSH logins to localhost.\n"
789 "Skipping test\n"); 790 "Skipping test\n");
790 GNUNET_SCHEDULER_cancel(abort_task); 791 GNUNET_SCHEDULER_cancel (abort_task);
791 abort_task = NULL; 792 abort_task = NULL;
792 GNUNET_SCHEDULER_shutdown(); 793 GNUNET_SCHEDULER_shutdown ();
793 result = SKIP; 794 result = SKIP;
794 return; 795 return;
795 } 796 }
796 cp = GNUNET_TESTBED_controller_start("127.0.0.1", host, status_cb, NULL); 797 cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb, NULL);
797} 798}
798 799
799 800
@@ -806,35 +807,35 @@ host_habitable_cb(void *cls,
806 * @param cfg the configuration file handle 807 * @param cfg the configuration file handle
807 */ 808 */
808static void 809static void
809run(void *cls, 810run (void *cls,
810 char *const *args, 811 char *const *args,
811 const char *cfgfile, 812 const char *cfgfile,
812 const struct GNUNET_CONFIGURATION_Handle *config) 813 const struct GNUNET_CONFIGURATION_Handle *config)
813{ 814{
814 cfg = GNUNET_CONFIGURATION_dup(config); 815 cfg = GNUNET_CONFIGURATION_dup (config);
815 host = GNUNET_TESTBED_host_create(NULL, NULL, cfg, 0); 816 host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0);
816 FAIL_TEST(NULL != host); 817 FAIL_TEST (NULL != host);
817 if (NULL == (hc_handle = GNUNET_TESTBED_is_host_habitable(host, 818 if (NULL == (hc_handle = GNUNET_TESTBED_is_host_habitable (host,
818 config, 819 config,
819 &host_habitable_cb, 820 &host_habitable_cb,
820 NULL))) 821 NULL)))
821 { 822 {
822 GNUNET_TESTBED_host_destroy(host); 823 GNUNET_TESTBED_host_destroy (host);
823 GNUNET_CONFIGURATION_destroy(cfg); 824 GNUNET_CONFIGURATION_destroy (cfg);
824 cfg = NULL; 825 cfg = NULL;
825 host = NULL; 826 host = NULL;
826 (void)printf("%s", 827 (void) printf ("%s",
827 "Unable to run the test as this system is not configured " 828 "Unable to run the test as this system is not configured "
828 "to use password less SSH logins to localhost.\n" 829 "to use password less SSH logins to localhost.\n"
829 "Marking test as successful\n"); 830 "Marking test as successful\n");
830 result = SKIP; 831 result = SKIP;
831 return; 832 return;
832 } 833 }
833 abort_task = GNUNET_SCHEDULER_add_delayed( 834 abort_task = GNUNET_SCHEDULER_add_delayed (
834 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), 835 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5),
835 &do_abort, 836 &do_abort,
836 NULL); 837 NULL);
837 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); 838 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
838} 839}
839 840
840 841
@@ -842,36 +843,37 @@ run(void *cls,
842 * Main function 843 * Main function
843 */ 844 */
844int 845int
845main(int argc, char **argv) 846main (int argc, char **argv)
846{ 847{
847 char *const argv2[] = { "test_testbed_api_controllerlink", 848 char *const argv2[] = { "test_testbed_api_controllerlink",
848 "-c", 849 "-c",
849 "test_testbed_api.conf", 850 "test_testbed_api.conf",
850 NULL }; 851 NULL };
851 struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; 852 struct GNUNET_GETOPT_CommandLineOption options[] =
853 { GNUNET_GETOPT_OPTION_END };
852 int ret; 854 int ret;
853 855
854 result = INIT; 856 result = INIT;
855 ret = GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, 857 ret = GNUNET_PROGRAM_run ((sizeof(argv2) / sizeof(char *)) - 1,
856 argv2, 858 argv2,
857 "test_testbed_api_controllerlink", 859 "test_testbed_api_controllerlink",
858 "nohelp", 860 "nohelp",
859 options, 861 options,
860 &run, 862 &run,
861 NULL); 863 NULL);
862 if (GNUNET_OK != ret) 864 if (GNUNET_OK != ret)
863 return 1; 865 return 1;
864 switch (result) 866 switch (result)
865 { 867 {
866 case SUCCESS: 868 case SUCCESS:
867 return 0; 869 return 0;
868 870
869 case SKIP: 871 case SKIP:
870 return 77; /* Mark test as skipped */ 872 return 77; /* Mark test as skipped */
871 873
872 default: 874 default:
873 return 1; 875 return 1;
874 } 876 }
875} 877}
876 878
877/* end of test_testbed_api_controllerlink.c */ 879/* 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 f9656d17f..9c2a96fb7 100644
--- a/src/testbed/test_testbed_api_hosts.c
+++ b/src/testbed/test_testbed_api_hosts.c
@@ -31,7 +31,7 @@
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 */
67static void 67static void
68do_shutdown(void *cls) 68do_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,76 +91,77 @@ do_shutdown(void *cls)
91 * @param cfg the configuration file handle 91 * @param cfg the configuration file handle
92 */ 92 */
93static void 93static void
94run(void *cls, char *const *args, const char *cfgfile, 94run (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,
110 GNUNET_assert(7 == num_hosts); 110 &hosts);
111 GNUNET_assert(NULL != hosts); 111 GNUNET_assert (7 == num_hosts);
112 GNUNET_assert (NULL != hosts);
112 for (cnt = 0; cnt < num_hosts; cnt++) 113 for (cnt = 0; cnt < num_hosts; cnt++)
114 {
115 if (cnt < 3)
116 {
117 GNUNET_assert (0 == strcmp ("totakura",
118 GNUNET_TESTBED_host_get_username_
119 (hosts[cnt])));
120 GNUNET_assert (NULL != GNUNET_TESTBED_host_get_hostname (hosts[cnt]));
121 GNUNET_assert (22 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt]));
122 }
123 if (3 == cnt)
124 {
125 GNUNET_assert (0 == strcmp ("totakura",
126 GNUNET_TESTBED_host_get_username_
127 (hosts[cnt])));
128 GNUNET_assert (NULL != GNUNET_TESTBED_host_get_hostname (hosts[cnt]));
129 GNUNET_assert (2022 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt]));
130 }
131 if (4 == cnt)
132 {
133 GNUNET_assert (0 == strcmp ("totakura",
134 GNUNET_TESTBED_host_get_username_
135 (hosts[cnt])));
136 GNUNET_assert (0 == strcmp ("asgard.realm",
137 GNUNET_TESTBED_host_get_hostname
138 (hosts[cnt])));
139 GNUNET_assert (22 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt]));
140 }
141 if (5 == cnt)
142 {
143 GNUNET_assert (NULL == GNUNET_TESTBED_host_get_username_ (hosts[cnt]));
144 GNUNET_assert (0 == strcmp ("rivendal",
145 GNUNET_TESTBED_host_get_hostname
146 (hosts[cnt])));
147 GNUNET_assert (22 == GNUNET_TESTBED_host_get_ssh_port_ (hosts[cnt]));
148 }
149 if (6 == cnt)
113 { 150 {
114 if (cnt < 3) 151 GNUNET_assert (NULL == GNUNET_TESTBED_host_get_username_ (hosts[cnt]));
115 { 152 GNUNET_assert (0 == strcmp ("rohan",
116 GNUNET_assert(0 == strcmp("totakura", 153 GNUNET_TESTBED_host_get_hostname
117 GNUNET_TESTBED_host_get_username_ 154 (hosts[cnt])));
118 (hosts[cnt]))); 155 GNUNET_assert (561 == GNUNET_TESTBED_host_get_ssh_port_ (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 }
156 } 156 }
157 }
157 status = GNUNET_YES; 158 status = GNUNET_YES;
158 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); 159 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
159} 160}
160 161
161 162
162int 163int
163main(int argc, char **argv) 164main (int argc, char **argv)
164{ 165{
165 char *const argv2[] = { "test_testbed_api_hosts", 166 char *const argv2[] = { "test_testbed_api_hosts",
166 "-c", "test_testbed_api.conf", 167 "-c", "test_testbed_api.conf",
@@ -171,9 +172,9 @@ main(int argc, char **argv)
171 172
172 status = GNUNET_SYSERR; 173 status = GNUNET_SYSERR;
173 if (GNUNET_OK != 174 if (GNUNET_OK !=
174 GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, 175 GNUNET_PROGRAM_run ((sizeof(argv2) / sizeof(char *)) - 1, argv2,
175 "test_testbed_api_hosts", "nohelp", options, &run, 176 "test_testbed_api_hosts", "nohelp", options, &run,
176 NULL)) 177 NULL))
177 return 1; 178 return 1;
178 return (GNUNET_OK == status) ? 0 : 1; 179 return (GNUNET_OK == status) ? 0 : 1;
179} 180}
diff --git a/src/testbed/test_testbed_api_operations.c b/src/testbed/test_testbed_api_operations.c
index f88f85304..832a42576 100644
--- a/src/testbed/test_testbed_api_operations.c
+++ b/src/testbed/test_testbed_api_operations.c
@@ -32,13 +32,13 @@
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
@@ -115,13 +115,14 @@ struct GNUNET_TESTBED_Operation *op9;
115/** 115/**
116 * The delay task identifier 116 * The delay task identifier
117 */ 117 */
118struct GNUNET_SCHEDULER_Task * step_task; 118struct GNUNET_SCHEDULER_Task *step_task;
119 119
120 120
121/** 121/**
122 * Enumeration of test stages 122 * Enumeration of test stages
123 */ 123 */
124enum Test { 124enum Test
125{
125 /** 126 /**
126 * Initial stage 127 * Initial stage
127 */ 128 */
@@ -241,7 +242,7 @@ enum Test result;
241 * operation can be activated. 242 * operation can be activated.
242 */ 243 */
243static void 244static void
244start_cb(void *cls); 245start_cb (void *cls);
245 246
246 247
247/** 248/**
@@ -254,7 +255,7 @@ start_cb(void *cls);
254 * in 'cls' and release all resources associated with the operation. 255 * in 'cls' and release all resources associated with the operation.
255 */ 256 */
256static void 257static void
257release_cb(void *cls); 258release_cb (void *cls);
258 259
259 260
260/** 261/**
@@ -263,79 +264,79 @@ release_cb(void *cls);
263 * @param cls NULL 264 * @param cls NULL
264 */ 265 */
265static void 266static void
266step(void *cls) 267step (void *cls)
267{ 268{
268 GNUNET_assert(NULL != step_task); 269 GNUNET_assert (NULL != step_task);
269 step_task = NULL; 270 step_task = NULL;
270 switch (result) 271 switch (result)
271 { 272 {
272 case TEST_OP1_STARTED: 273 case TEST_OP1_STARTED:
273 GNUNET_TESTBED_operation_release_(op1); 274 GNUNET_TESTBED_operation_release_ (op1);
274 GNUNET_TESTBED_operation_queue_reset_max_active_(q1, 0); 275 GNUNET_TESTBED_operation_queue_reset_max_active_ (q1, 0);
275 op3 = GNUNET_TESTBED_operation_create_(&op3, &start_cb, &release_cb); 276 op3 = GNUNET_TESTBED_operation_create_ (&op3, &start_cb, &release_cb);
276 GNUNET_TESTBED_operation_queue_insert2_(q1, op3, 2); 277 GNUNET_TESTBED_operation_queue_insert2_ (q1, op3, 2);
277 GNUNET_TESTBED_operation_queue_insert2_(q2, op3, 2); 278 GNUNET_TESTBED_operation_queue_insert2_ (q2, op3, 2);
278 GNUNET_TESTBED_operation_begin_wait_(op3); 279 GNUNET_TESTBED_operation_begin_wait_ (op3);
279 op4 = GNUNET_TESTBED_operation_create_(&op4, &start_cb, &release_cb); 280 op4 = GNUNET_TESTBED_operation_create_ (&op4, &start_cb, &release_cb);
280 GNUNET_TESTBED_operation_queue_insert2_(q1, op4, 2); 281 GNUNET_TESTBED_operation_queue_insert2_ (q1, op4, 2);
281 GNUNET_TESTBED_operation_queue_insert2_(q2, op4, 2); 282 GNUNET_TESTBED_operation_queue_insert2_ (q2, op4, 2);
282 GNUNET_TESTBED_operation_begin_wait_(op4); 283 GNUNET_TESTBED_operation_begin_wait_ (op4);
283 break; 284 break;
284 285
285 case TEST_OP1_RELEASED: 286 case TEST_OP1_RELEASED:
286 result = TEST_PAUSE; 287 result = TEST_PAUSE;
287 GNUNET_TESTBED_operation_queue_reset_max_active_(q1, 2); 288 GNUNET_TESTBED_operation_queue_reset_max_active_ (q1, 2);
288 break; 289 break;
289 290
290 case TEST_OP2_STARTED: 291 case TEST_OP2_STARTED:
291 GNUNET_TESTBED_operation_release_(op2); 292 GNUNET_TESTBED_operation_release_ (op2);
292 break; 293 break;
293 294
294 case TEST_OP3_STARTED: 295 case TEST_OP3_STARTED:
295 GNUNET_TESTBED_operation_release_(op3); 296 GNUNET_TESTBED_operation_release_ (op3);
296 break; 297 break;
297 298
298 case TEST_OP4_STARTED: 299 case TEST_OP4_STARTED:
299 GNUNET_TESTBED_operation_release_(op4); 300 GNUNET_TESTBED_operation_release_ (op4);
300 break; 301 break;
301 302
302 case TEST_OP6_RELEASED: 303 case TEST_OP6_RELEASED:
303 op8 = GNUNET_TESTBED_operation_create_(&op8, &start_cb, &release_cb); 304 op8 = GNUNET_TESTBED_operation_create_ (&op8, &start_cb, &release_cb);
304 GNUNET_TESTBED_operation_queue_insert2_(q1, op8, 2); 305 GNUNET_TESTBED_operation_queue_insert2_ (q1, op8, 2);
305 GNUNET_TESTBED_operation_queue_insert2_(q2, op8, 2); 306 GNUNET_TESTBED_operation_queue_insert2_ (q2, op8, 2);
306 result = TEST_OP8_WAITING; 307 result = TEST_OP8_WAITING;
307 GNUNET_TESTBED_operation_begin_wait_(op8); 308 GNUNET_TESTBED_operation_begin_wait_ (op8);
308 break; 309 break;
309 310
310 case TEST_OP8_STARTED: 311 case TEST_OP8_STARTED:
311 GNUNET_TESTBED_operation_inactivate_(op8); 312 GNUNET_TESTBED_operation_inactivate_ (op8);
312 result = TEST_OP8_INACTIVE_1; 313 result = TEST_OP8_INACTIVE_1;
313 step_task = GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); 314 step_task = GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL);
314 break; 315 break;
315 316
316 case TEST_OP8_INACTIVE_1: 317 case TEST_OP8_INACTIVE_1:
317 GNUNET_TESTBED_operation_activate_(op8); 318 GNUNET_TESTBED_operation_activate_ (op8);
318 result = TEST_OP8_ACTIVE; 319 result = TEST_OP8_ACTIVE;
319 op9 = GNUNET_TESTBED_operation_create_(&op9, &start_cb, &release_cb); 320 op9 = GNUNET_TESTBED_operation_create_ (&op9, &start_cb, &release_cb);
320 GNUNET_TESTBED_operation_queue_insert2_(q1, op9, 1); 321 GNUNET_TESTBED_operation_queue_insert2_ (q1, op9, 1);
321 GNUNET_TESTBED_operation_queue_insert2_(q2, op9, 1); 322 GNUNET_TESTBED_operation_queue_insert2_ (q2, op9, 1);
322 GNUNET_TESTBED_operation_begin_wait_(op9); 323 GNUNET_TESTBED_operation_begin_wait_ (op9);
323 step_task = GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); 324 step_task = GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL);
324 break; 325 break;
325 326
326 case TEST_OP8_ACTIVE: 327 case TEST_OP8_ACTIVE:
327 GNUNET_TESTBED_operation_inactivate_(op8); 328 GNUNET_TESTBED_operation_inactivate_ (op8);
328 /* op8 should be released by now due to above call */ 329 /* op8 should be released by now due to above call */
329 GNUNET_assert(TEST_OP8_RELEASED == result); 330 GNUNET_assert (TEST_OP8_RELEASED == result);
330 break; 331 break;
331 332
332 case TEST_OP9_STARTED: 333 case TEST_OP9_STARTED:
333 GNUNET_TESTBED_operation_release_(op9); 334 GNUNET_TESTBED_operation_release_ (op9);
334 break; 335 break;
335 336
336 default: 337 default:
337 GNUNET_assert(0); 338 GNUNET_assert (0);
338 } 339 }
339} 340}
340 341
341 342
@@ -345,71 +346,71 @@ step(void *cls)
345 * operation can be activated. 346 * operation can be activated.
346 */ 347 */
347static void 348static void
348start_cb(void *cls) 349start_cb (void *cls)
349{ 350{
350 switch (result) 351 switch (result)
351 { 352 {
352 case TEST_INIT: 353 case TEST_INIT:
353 GNUNET_assert(&op1 == cls); 354 GNUNET_assert (&op1 == cls);
354 result = TEST_OP1_STARTED; 355 result = TEST_OP1_STARTED;
355 GNUNET_assert(NULL == step_task); 356 GNUNET_assert (NULL == step_task);
356 step_task = 357 step_task =
357 GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); 358 GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL);
358 break; 359 break;
359 360
360 case TEST_PAUSE: 361 case TEST_PAUSE:
361 GNUNET_assert(&op2 == cls); 362 GNUNET_assert (&op2 == cls);
362 result = TEST_OP2_STARTED; 363 result = TEST_OP2_STARTED;
363 GNUNET_assert(NULL == step_task); 364 GNUNET_assert (NULL == step_task);
364 step_task = 365 step_task =
365 GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); 366 GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL);
366 break; 367 break;
367 368
368 case TEST_OP2_RELEASED: 369 case TEST_OP2_RELEASED:
369 GNUNET_assert(&op3 == cls); 370 GNUNET_assert (&op3 == cls);
370 result = TEST_OP3_STARTED; 371 result = TEST_OP3_STARTED;
371 GNUNET_assert(NULL == step_task); 372 GNUNET_assert (NULL == step_task);
372 step_task = 373 step_task =
373 GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); 374 GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL);
374 break; 375 break;
375 376
376 case TEST_OP3_RELEASED: 377 case TEST_OP3_RELEASED:
377 GNUNET_assert(&op4 == cls); 378 GNUNET_assert (&op4 == cls);
378 result = TEST_OP4_STARTED; 379 result = TEST_OP4_STARTED;
379 GNUNET_assert(NULL == step_task); 380 GNUNET_assert (NULL == step_task);
380 step_task = 381 step_task =
381 GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); 382 GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL);
382 break; 383 break;
383 384
384 case TEST_OP4_RELEASED: 385 case TEST_OP4_RELEASED:
385 { 386 {
386 static int nops; 387 static int nops;
387 388
388 nops++; 389 nops++;
389 if (nops == 3) 390 if (nops == 3)
390 { 391 {
391 result = TEST_OP5_6_7_STARTED; 392 result = TEST_OP5_6_7_STARTED;
392 GNUNET_TESTBED_operation_release_(op5); 393 GNUNET_TESTBED_operation_release_ (op5);
393 op5 = NULL; 394 op5 = NULL;
394 } 395 }
395 } 396 }
396 break; 397 break;
397 398
398 case TEST_OP7_RELEASED: 399 case TEST_OP7_RELEASED:
399 GNUNET_assert(&op8 == cls); 400 GNUNET_assert (&op8 == cls);
400 result = TEST_OP8_STARTED; 401 result = TEST_OP8_STARTED;
401 step_task = GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); 402 step_task = GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL);
402 break; 403 break;
403 404
404 case TEST_OP8_RELEASED: 405 case TEST_OP8_RELEASED:
405 GNUNET_assert(&op9 == cls); 406 GNUNET_assert (&op9 == cls);
406 result = TEST_OP9_STARTED; 407 result = TEST_OP9_STARTED;
407 step_task = GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); 408 step_task = GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL);
408 break; 409 break;
409 410
410 default: 411 default:
411 GNUNET_assert(0); 412 GNUNET_assert (0);
412 } 413 }
413} 414}
414 415
415 416
@@ -423,82 +424,82 @@ start_cb(void *cls)
423 * in 'cls' and release all resources associated with the operation. 424 * in 'cls' and release all resources associated with the operation.
424 */ 425 */
425static void 426static void
426release_cb(void *cls) 427release_cb (void *cls)
427{ 428{
428 switch (result) 429 switch (result)
429 { 430 {
430 case TEST_OP1_STARTED: 431 case TEST_OP1_STARTED:
431 GNUNET_assert(&op1 == cls); 432 GNUNET_assert (&op1 == cls);
432 result = TEST_OP1_RELEASED; 433 result = TEST_OP1_RELEASED;
433 op1 = NULL; 434 op1 = NULL;
434 step_task = 435 step_task =
435 GNUNET_SCHEDULER_add_delayed(STEP_DELAY, &step, NULL); 436 GNUNET_SCHEDULER_add_delayed (STEP_DELAY, &step, NULL);
436 break; 437 break;
437 438
438 case TEST_OP2_STARTED: 439 case TEST_OP2_STARTED:
439 GNUNET_assert(&op2 == cls); 440 GNUNET_assert (&op2 == cls);
440 result = TEST_OP2_RELEASED; 441 result = TEST_OP2_RELEASED;
441 GNUNET_assert(NULL == step_task); 442 GNUNET_assert (NULL == step_task);
442 break; 443 break;
443 444
444 case TEST_OP3_STARTED: 445 case TEST_OP3_STARTED:
445 GNUNET_assert(&op3 == cls); 446 GNUNET_assert (&op3 == cls);
446 result = TEST_OP3_RELEASED; 447 result = TEST_OP3_RELEASED;
447 GNUNET_assert(NULL == step_task); 448 GNUNET_assert (NULL == step_task);
448 break; 449 break;
449 450
450 case TEST_OP4_STARTED: 451 case TEST_OP4_STARTED:
451 GNUNET_assert(&op4 == cls); 452 GNUNET_assert (&op4 == cls);
452 result = TEST_OP4_RELEASED; 453 result = TEST_OP4_RELEASED;
453 GNUNET_assert(NULL == step_task); 454 GNUNET_assert (NULL == step_task);
454 op5 = GNUNET_TESTBED_operation_create_(&op5, &start_cb, &release_cb); 455 op5 = GNUNET_TESTBED_operation_create_ (&op5, &start_cb, &release_cb);
455 GNUNET_TESTBED_operation_queue_insert2_(q1, op5, 1); 456 GNUNET_TESTBED_operation_queue_insert2_ (q1, op5, 1);
456 GNUNET_TESTBED_operation_begin_wait_(op5); 457 GNUNET_TESTBED_operation_begin_wait_ (op5);
457 op6 = GNUNET_TESTBED_operation_create_(&op6, &start_cb, &release_cb); 458 op6 = GNUNET_TESTBED_operation_create_ (&op6, &start_cb, &release_cb);
458 GNUNET_TESTBED_operation_queue_insert2_(q2, op6, 1); 459 GNUNET_TESTBED_operation_queue_insert2_ (q2, op6, 1);
459 GNUNET_TESTBED_operation_begin_wait_(op6); 460 GNUNET_TESTBED_operation_begin_wait_ (op6);
460 op7 = GNUNET_TESTBED_operation_create_(&op7, &start_cb, &release_cb); 461 op7 = GNUNET_TESTBED_operation_create_ (&op7, &start_cb, &release_cb);
461 GNUNET_TESTBED_operation_queue_insert2_(q1, op7, 1); 462 GNUNET_TESTBED_operation_queue_insert2_ (q1, op7, 1);
462 GNUNET_TESTBED_operation_queue_insert2_(q2, op7, 1); 463 GNUNET_TESTBED_operation_queue_insert2_ (q2, op7, 1);
463 GNUNET_TESTBED_operation_begin_wait_(op7); 464 GNUNET_TESTBED_operation_begin_wait_ (op7);
464 break; 465 break;
465 466
466 case TEST_OP5_6_7_STARTED: 467 case TEST_OP5_6_7_STARTED:
467 result = TEST_OP5_RELEASED; 468 result = TEST_OP5_RELEASED;
468 op5 = NULL; 469 op5 = NULL;
469 GNUNET_TESTBED_operation_release_(op6); 470 GNUNET_TESTBED_operation_release_ (op6);
470 break; 471 break;
471 472
472 case TEST_OP5_RELEASED: 473 case TEST_OP5_RELEASED:
473 op6 = NULL; 474 op6 = NULL;
474 result = TEST_OP6_RELEASED; 475 result = TEST_OP6_RELEASED;
475 GNUNET_TESTBED_operation_inactivate_(op7); 476 GNUNET_TESTBED_operation_inactivate_ (op7);
476 step_task = GNUNET_SCHEDULER_add_now(&step, NULL); 477 step_task = GNUNET_SCHEDULER_add_now (&step, NULL);
477 break; 478 break;
478 479
479 case TEST_OP8_WAITING: 480 case TEST_OP8_WAITING:
480 GNUNET_assert(&op7 == cls); 481 GNUNET_assert (&op7 == cls);
481 op7 = NULL; 482 op7 = NULL;
482 result = TEST_OP7_RELEASED; 483 result = TEST_OP7_RELEASED;
483 break; 484 break;
484 485
485 case TEST_OP8_ACTIVE: 486 case TEST_OP8_ACTIVE:
486 result = TEST_OP8_RELEASED; 487 result = TEST_OP8_RELEASED;
487 op8 = NULL; 488 op8 = NULL;
488 break; 489 break;
489 490
490 case TEST_OP9_STARTED: 491 case TEST_OP9_STARTED:
491 GNUNET_assert(&op9 == cls); 492 GNUNET_assert (&op9 == cls);
492 result = TEST_OP9_RELEASED; 493 result = TEST_OP9_RELEASED;
493 GNUNET_TESTBED_operation_queue_destroy_(q1); 494 GNUNET_TESTBED_operation_queue_destroy_ (q1);
494 GNUNET_TESTBED_operation_queue_destroy_(q2); 495 GNUNET_TESTBED_operation_queue_destroy_ (q2);
495 q1 = NULL; 496 q1 = NULL;
496 q2 = NULL; 497 q2 = NULL;
497 break; 498 break;
498 499
499 default: 500 default:
500 GNUNET_assert(0); 501 GNUNET_assert (0);
501 } 502 }
502} 503}
503 504
504 505
@@ -511,22 +512,22 @@ release_cb(void *cls)
511 * @param cfg the configuration file handle 512 * @param cfg the configuration file handle
512 */ 513 */
513static void 514static void
514run(void *cls, char *const *args, const char *cfgfile, 515run (void *cls, char *const *args, const char *cfgfile,
515 const struct GNUNET_CONFIGURATION_Handle *config) 516 const struct GNUNET_CONFIGURATION_Handle *config)
516{ 517{
517 q1 = GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_FIXED, 1); 518 q1 = GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, 1);
518 GNUNET_assert(NULL != q1); 519 GNUNET_assert (NULL != q1);
519 q2 = GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_FIXED, 2); 520 q2 = GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, 2);
520 GNUNET_assert(NULL != q2); 521 GNUNET_assert (NULL != q2);
521 op1 = GNUNET_TESTBED_operation_create_(&op1, start_cb, release_cb); 522 op1 = GNUNET_TESTBED_operation_create_ (&op1, start_cb, release_cb);
522 GNUNET_assert(NULL != op1); 523 GNUNET_assert (NULL != op1);
523 op2 = GNUNET_TESTBED_operation_create_(&op2, start_cb, release_cb); 524 op2 = GNUNET_TESTBED_operation_create_ (&op2, start_cb, release_cb);
524 GNUNET_TESTBED_operation_queue_insert_(q1, op1); 525 GNUNET_TESTBED_operation_queue_insert_ (q1, op1);
525 GNUNET_TESTBED_operation_queue_insert_(q2, op1); 526 GNUNET_TESTBED_operation_queue_insert_ (q2, op1);
526 GNUNET_TESTBED_operation_begin_wait_(op1); 527 GNUNET_TESTBED_operation_begin_wait_ (op1);
527 GNUNET_TESTBED_operation_queue_insert_(q1, op2); 528 GNUNET_TESTBED_operation_queue_insert_ (q1, op2);
528 GNUNET_TESTBED_operation_queue_insert_(q2, op2); 529 GNUNET_TESTBED_operation_queue_insert_ (q2, op2);
529 GNUNET_TESTBED_operation_begin_wait_(op2); 530 GNUNET_TESTBED_operation_begin_wait_ (op2);
530 result = TEST_INIT; 531 result = TEST_INIT;
531} 532}
532 533
@@ -535,7 +536,7 @@ run(void *cls, char *const *args, const char *cfgfile,
535 * Main function 536 * Main function
536 */ 537 */
537int 538int
538main(int argc, char **argv) 539main (int argc, char **argv)
539{ 540{
540 int ret; 541 int ret;
541 char *const argv2[] = 542 char *const argv2[] =
@@ -544,9 +545,9 @@ main(int argc, char **argv)
544 { GNUNET_GETOPT_OPTION_END }; 545 { GNUNET_GETOPT_OPTION_END };
545 546
546 ret = 547 ret =
547 GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, 548 GNUNET_PROGRAM_run ((sizeof(argv2) / sizeof(char *)) - 1, argv2,
548 "test_testbed_api_operations", "nohelp", options, 549 "test_testbed_api_operations", "nohelp", options,
549 &run, NULL); 550 &run, NULL);
550 if ((GNUNET_OK != ret) || (TEST_OP9_RELEASED != result)) 551 if ((GNUNET_OK != ret) || (TEST_OP9_RELEASED != result))
551 return 1; 552 return 1;
552 op1 = NULL; 553 op1 = NULL;
diff --git a/src/testbed/test_testbed_api_peer_reconfiguration.c b/src/testbed/test_testbed_api_peer_reconfiguration.c
index 40791a9cc..91955c13d 100644
--- a/src/testbed/test_testbed_api_peer_reconfiguration.c
+++ b/src/testbed/test_testbed_api_peer_reconfiguration.c
@@ -47,12 +47,13 @@ static struct GNUNET_TESTBED_Operation *op;
47/** 47/**
48 * Abort task identifier 48 * Abort task identifier
49 */ 49 */
50static struct GNUNET_SCHEDULER_Task * abort_task; 50static struct GNUNET_SCHEDULER_Task *abort_task;
51 51
52/** 52/**
53 * States in this test 53 * States in this test
54 */ 54 */
55enum { 55enum
56{
56 /** 57 /**
57 * Test has just been initialized 58 * Test has just been initialized
58 */ 59 */
@@ -73,14 +74,14 @@ enum {
73 * Fail testcase 74 * Fail testcase
74 */ 75 */
75#define FAIL_TEST(cond, ret) do { \ 76#define FAIL_TEST(cond, ret) do { \
76 if (!(cond)) { \ 77 if (! (cond)) { \
77 GNUNET_break(0); \ 78 GNUNET_break (0); \
78 if (NULL != abort_task) \ 79 if (NULL != abort_task) \
79 GNUNET_SCHEDULER_cancel (abort_task); \ 80 GNUNET_SCHEDULER_cancel (abort_task); \
80 abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); \ 81 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \
81 ret; \ 82 ret; \
82 } \ 83 } \
83 } while (0) 84} while (0)
84 85
85 86
86/** 87/**
@@ -89,16 +90,16 @@ enum {
89 * @param cls NULL 90 * @param cls NULL
90 */ 91 */
91static void 92static void
92do_abort(void *cls) 93do_abort (void *cls)
93{ 94{
94 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Aborting\n"); 95 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Aborting\n");
95 abort_task = NULL; 96 abort_task = NULL;
96 if (NULL != op) 97 if (NULL != op)
97 { 98 {
98 GNUNET_TESTBED_operation_done(op); 99 GNUNET_TESTBED_operation_done (op);
99 op = NULL; 100 op = NULL;
100 } 101 }
101 GNUNET_SCHEDULER_shutdown(); 102 GNUNET_SCHEDULER_shutdown ();
102} 103}
103 104
104 105
@@ -110,29 +111,29 @@ do_abort(void *cls)
110 * @param event information about the event 111 * @param event information about the event
111 */ 112 */
112static void 113static void
113controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) 114controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
114{ 115{
115 if (STATE_PEER_STARTED != state) 116 if (STATE_PEER_STARTED != state)
116 return; 117 return;
117 if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type) 118 if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type)
118 { 119 {
119 GNUNET_TESTBED_operation_done(op); 120 GNUNET_TESTBED_operation_done (op);
120 op = NULL; 121 op = NULL;
121 FAIL_TEST(0, return ); 122 FAIL_TEST (0, return );
122 } 123 }
123 if (NULL != event->details.operation_finished.emsg) 124 if (NULL != event->details.operation_finished.emsg)
124 { 125 {
125 fprintf(stderr, "Operation failed: %s\n", 126 fprintf (stderr, "Operation failed: %s\n",
126 event->details.operation_finished.emsg); 127 event->details.operation_finished.emsg);
127 GNUNET_TESTBED_operation_done(op); 128 GNUNET_TESTBED_operation_done (op);
128 op = NULL; 129 op = NULL;
129 FAIL_TEST(0, return ); 130 FAIL_TEST (0, return );
130 } 131 }
131 GNUNET_TESTBED_operation_done(op); 132 GNUNET_TESTBED_operation_done (op);
132 state = STATE_PEER_RECONFIGURED; 133 state = STATE_PEER_RECONFIGURED;
133 GNUNET_SCHEDULER_cancel(abort_task); 134 GNUNET_SCHEDULER_cancel (abort_task);
134 abort_task = NULL; 135 abort_task = NULL;
135 GNUNET_SCHEDULER_shutdown(); 136 GNUNET_SCHEDULER_shutdown ();
136} 137}
137 138
138 139
@@ -149,27 +150,28 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
149 * failed 150 * failed
150 */ 151 */
151static void 152static void
152test_master(void *cls, 153test_master (void *cls,
153 struct GNUNET_TESTBED_RunHandle *h, 154 struct GNUNET_TESTBED_RunHandle *h,
154 unsigned int num_peers, 155 unsigned int num_peers,
155 struct GNUNET_TESTBED_Peer **peers_, 156 struct GNUNET_TESTBED_Peer **peers_,
156 unsigned int links_succeeded, 157 unsigned int links_succeeded,
157 unsigned int links_failed) 158 unsigned int links_failed)
158{ 159{
159 struct GNUNET_CONFIGURATION_Handle *cfg; 160 struct GNUNET_CONFIGURATION_Handle *cfg;
160 161
161 FAIL_TEST(NUM_PEERS == num_peers, return ); 162 FAIL_TEST (NUM_PEERS == num_peers, return );
162 state = STATE_PEER_STARTED; 163 state = STATE_PEER_STARTED;
163 peers = peers_; 164 peers = peers_;
164 cfg = GNUNET_CONFIGURATION_create(); 165 cfg = GNUNET_CONFIGURATION_create ();
165 FAIL_TEST(GNUNET_OK == GNUNET_CONFIGURATION_load 166 FAIL_TEST (GNUNET_OK == GNUNET_CONFIGURATION_load
166 (cfg, "test_testbed_api_testbed_run_topologyrandom.conf"), return ); 167 (cfg, "test_testbed_api_testbed_run_topologyrandom.conf"),
167 op = GNUNET_TESTBED_peer_update_configuration(peers[0], cfg); 168 return );
168 GNUNET_CONFIGURATION_destroy(cfg); 169 op = GNUNET_TESTBED_peer_update_configuration (peers[0], cfg);
169 FAIL_TEST(NULL != op, return ); 170 GNUNET_CONFIGURATION_destroy (cfg);
170 abort_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 171 FAIL_TEST (NULL != op, return );
171 (GNUNET_TIME_UNIT_SECONDS, 30), 172 abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
172 &do_abort, NULL); 173 (GNUNET_TIME_UNIT_SECONDS, 30),
174 &do_abort, NULL);
173} 175}
174 176
175 177
@@ -177,15 +179,15 @@ test_master(void *cls,
177 * Main function 179 * Main function
178 */ 180 */
179int 181int
180main(int argc, char **argv) 182main (int argc, char **argv)
181{ 183{
182 state = STATE_INIT; 184 state = STATE_INIT;
183 (void)GNUNET_TESTBED_test_run("test_testbed_api_peer_reconfiguration", 185 (void) GNUNET_TESTBED_test_run ("test_testbed_api_peer_reconfiguration",
184 "test_testbed_api.conf", 186 "test_testbed_api.conf",
185 NUM_PEERS, 187 NUM_PEERS,
186 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED, 188 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED,
187 &controller_cb, NULL, 189 &controller_cb, NULL,
188 &test_master, NULL); 190 &test_master, NULL);
189 if (STATE_PEER_RECONFIGURED != state) 191 if (STATE_PEER_RECONFIGURED != state)
190 return 1; 192 return 1;
191 return 0; 193 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 d6597890f..6d4f8196a 100644
--- a/src/testbed/test_testbed_api_peers_manage_services.c
+++ b/src/testbed/test_testbed_api_peers_manage_services.c
@@ -47,17 +47,18 @@ static struct GNUNET_TESTBED_Operation *op;
47/** 47/**
48 * dummy pointer 48 * dummy pointer
49 */ 49 */
50static void *dummy_cls = (void *)0xDEAD0001; 50static void *dummy_cls = (void *) 0xDEAD0001;
51 51
52/** 52/**
53 * Abort task identifier 53 * Abort task identifier
54 */ 54 */
55static struct GNUNET_SCHEDULER_Task * abort_task; 55static struct GNUNET_SCHEDULER_Task *abort_task;
56 56
57/** 57/**
58 * States in this test 58 * States in this test
59 */ 59 */
60enum { 60enum
61{
61 /** 62 /**
62 * Test has just been initialized 63 * Test has just been initialized
63 */ 64 */
@@ -88,14 +89,14 @@ enum {
88 * Fail testcase 89 * Fail testcase
89 */ 90 */
90#define FAIL_TEST(cond, ret) do { \ 91#define FAIL_TEST(cond, ret) do { \
91 if (!(cond)) { \ 92 if (! (cond)) { \
92 GNUNET_break(0); \ 93 GNUNET_break (0); \
93 if (NULL != abort_task) \ 94 if (NULL != abort_task) \
94 GNUNET_SCHEDULER_cancel (abort_task); \ 95 GNUNET_SCHEDULER_cancel (abort_task); \
95 abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); \ 96 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \
96 ret; \ 97 ret; \
97 } \ 98 } \
98 } while (0) 99} while (0)
99 100
100 101
101/** 102/**
@@ -104,16 +105,16 @@ enum {
104 * @param cls NULL 105 * @param cls NULL
105 */ 106 */
106static void 107static void
107do_abort(void *cls) 108do_abort (void *cls)
108{ 109{
109 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Aborting\n"); 110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Aborting\n");
110 abort_task = NULL; 111 abort_task = NULL;
111 if (NULL != op) 112 if (NULL != op)
112 { 113 {
113 GNUNET_TESTBED_operation_done(op); 114 GNUNET_TESTBED_operation_done (op);
114 op = NULL; 115 op = NULL;
115 } 116 }
116 GNUNET_SCHEDULER_shutdown(); 117 GNUNET_SCHEDULER_shutdown ();
117} 118}
118 119
119 120
@@ -126,38 +127,38 @@ do_abort(void *cls)
126 * operation has executed successfully. 127 * operation has executed successfully.
127 */ 128 */
128static void 129static void
129op_comp_cb(void *cls, 130op_comp_cb (void *cls,
130 struct GNUNET_TESTBED_Operation *op, 131 struct GNUNET_TESTBED_Operation *op,
131 const char *emsg) 132 const char *emsg)
132{ 133{
133 FAIL_TEST(cls == dummy_cls, return ); 134 FAIL_TEST (cls == dummy_cls, return );
134 FAIL_TEST(NULL == emsg, return ); 135 FAIL_TEST (NULL == emsg, return );
135 GNUNET_TESTBED_operation_done(op); 136 GNUNET_TESTBED_operation_done (op);
136 op = NULL; 137 op = NULL;
137 switch (state) 138 switch (state)
138 { 139 {
139 case STATE_PEERS_STARTED: 140 case STATE_PEERS_STARTED:
140 state = STATE_SERVICE_DOWN; 141 state = STATE_SERVICE_DOWN;
141 op = GNUNET_TESTBED_peer_manage_service(dummy_cls, 142 op = GNUNET_TESTBED_peer_manage_service (dummy_cls,
142 peers[1], 143 peers[1],
143 "topology", 144 "topology",
144 op_comp_cb, 145 op_comp_cb,
145 dummy_cls, 146 dummy_cls,
146 0); 147 0);
147 GNUNET_assert(NULL != op); 148 GNUNET_assert (NULL != op);
148 break; 149 break;
149 150
150 case STATE_SERVICE_DOWN: 151 case STATE_SERVICE_DOWN:
151 state = STATE_SERVICE_UP; 152 state = STATE_SERVICE_UP;
152 GNUNET_SCHEDULER_cancel(abort_task); 153 GNUNET_SCHEDULER_cancel (abort_task);
153 abort_task = NULL; 154 abort_task = NULL;
154 state = STATE_OK; 155 state = STATE_OK;
155 GNUNET_SCHEDULER_shutdown(); 156 GNUNET_SCHEDULER_shutdown ();
156 break; 157 break;
157 158
158 default: 159 default:
159 FAIL_TEST(0, return ); 160 FAIL_TEST (0, return );
160 } 161 }
161} 162}
162 163
163 164
@@ -174,26 +175,26 @@ op_comp_cb(void *cls,
174 * failed 175 * failed
175 */ 176 */
176static void 177static void
177test_master(void *cls, 178test_master (void *cls,
178 struct GNUNET_TESTBED_RunHandle *h, 179 struct GNUNET_TESTBED_RunHandle *h,
179 unsigned int num_peers, 180 unsigned int num_peers,
180 struct GNUNET_TESTBED_Peer **peers_, 181 struct GNUNET_TESTBED_Peer **peers_,
181 unsigned int links_succeeded, 182 unsigned int links_succeeded,
182 unsigned int links_failed) 183 unsigned int links_failed)
183{ 184{
184 FAIL_TEST(NUM_PEERS == num_peers, return ); 185 FAIL_TEST (NUM_PEERS == num_peers, return );
185 state = STATE_PEERS_STARTED; 186 state = STATE_PEERS_STARTED;
186 peers = peers_; 187 peers = peers_;
187 op = GNUNET_TESTBED_peer_manage_service(dummy_cls, 188 op = GNUNET_TESTBED_peer_manage_service (dummy_cls,
188 peers[1], 189 peers[1],
189 "topology", 190 "topology",
190 op_comp_cb, 191 op_comp_cb,
191 dummy_cls, 192 dummy_cls,
192 1); 193 1);
193 FAIL_TEST(NULL != op, return ); 194 FAIL_TEST (NULL != op, return );
194 abort_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 195 abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
195 (GNUNET_TIME_UNIT_MINUTES, 1), 196 (GNUNET_TIME_UNIT_MINUTES, 1),
196 &do_abort, NULL); 197 &do_abort, NULL);
197} 198}
198 199
199 200
@@ -201,14 +202,14 @@ test_master(void *cls,
201 * Main function 202 * Main function
202 */ 203 */
203int 204int
204main(int argc, char **argv) 205main (int argc, char **argv)
205{ 206{
206 state = STATE_INIT; 207 state = STATE_INIT;
207 (void)GNUNET_TESTBED_test_run("test_testbed_api_peers_manage_services", 208 (void) GNUNET_TESTBED_test_run ("test_testbed_api_peers_manage_services",
208 "test_testbed_api.conf", 209 "test_testbed_api.conf",
209 NUM_PEERS, 210 NUM_PEERS,
210 1LL, NULL, NULL, 211 1LL, NULL, NULL,
211 &test_master, NULL); 212 &test_master, NULL);
212 if (STATE_OK != state) 213 if (STATE_OK != state)
213 return 1; 214 return 1;
214 return 0; 215 return 0;
diff --git a/src/testbed/test_testbed_api_sd.c b/src/testbed/test_testbed_api_sd.c
index 81b8dba41..f7c60ea4d 100644
--- a/src/testbed/test_testbed_api_sd.c
+++ b/src/testbed/test_testbed_api_sd.c
@@ -43,47 +43,47 @@ static int ret;
43 * @param cfg the configuration file handle 43 * @param cfg the configuration file handle
44 */ 44 */
45static void 45static void
46run(void *cls, char *const *args, const char *cfgfile, 46run (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
85err: 85err:
86 GNUNET_TESTBED_SD_destroy_(h); 86 GNUNET_TESTBED_SD_destroy_ (h);
87} 87}
88 88
89 89
@@ -91,7 +91,7 @@ err:
91 * Main function 91 * Main function
92 */ 92 */
93int 93int
94main(int argc, char **argv) 94main (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 26f90cfff..2d0e2d6b8 100644
--- a/src/testbed/test_testbed_api_statistics.c
+++ b/src/testbed/test_testbed_api_statistics.c
@@ -46,12 +46,12 @@ static struct GNUNET_TESTBED_Operation *op;
46/** 46/**
47 * dummy pointer 47 * dummy pointer
48 */ 48 */
49static void *dummy_cls = (void *)0xDEAD0001; 49static void *dummy_cls = (void *) 0xDEAD0001;
50 50
51/** 51/**
52 * Abort task identifier 52 * Abort task identifier
53 */ 53 */
54static struct GNUNET_SCHEDULER_Task * abort_task; 54static struct GNUNET_SCHEDULER_Task *abort_task;
55 55
56/** 56/**
57 * Global testing result 57 * Global testing result
@@ -73,14 +73,14 @@ 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
86/** 86/**
@@ -89,15 +89,15 @@ static unsigned int num_seen_peers;
89 * @param cls NULL 89 * @param cls NULL
90 */ 90 */
91static void 91static void
92do_abort(void *cls) 92do_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 */
116static int 116static int
117stats_iterator(void *cls, 117stats_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 */
143static void 143static void
144op_comp_cb(void *cls, 144op_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 */
169static void 169static void
170test_master(void *cls, 170test_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 */
193int 193int
194main(int argc, char **argv) 194main (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 3f8f536e7..f0d8d1d25 100644
--- a/src/testbed/test_testbed_api_test.c
+++ b/src/testbed/test_testbed_api_test.c
@@ -33,7 +33,7 @@
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
@@ -53,12 +53,12 @@ static struct GNUNET_TESTBED_Operation *op;
53/** 53/**
54 * Abort task identifier 54 * Abort task identifier
55 */ 55 */
56static struct GNUNET_SCHEDULER_Task * abort_task; 56static struct GNUNET_SCHEDULER_Task *abort_task;
57 57
58/** 58/**
59 * shutdown task identifier 59 * shutdown task identifier
60 */ 60 */
61static struct GNUNET_SCHEDULER_Task * shutdown_task; 61static struct GNUNET_SCHEDULER_Task *shutdown_task;
62 62
63/** 63/**
64 * Testing result 64 * Testing result
@@ -72,30 +72,30 @@ static int result;
72 * @param cls NULL 72 * @param cls NULL
73 */ 73 */
74static void 74static void
75do_shutdown(void *cls) 75do_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
101/** 101/**
@@ -104,13 +104,13 @@ do_shutdown(void *cls)
104 * @param cls NULL 104 * @param cls NULL
105 */ 105 */
106static void 106static void
107do_abort(void *cls) 107do_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 */
126static void 126static void
127peerinfo_cb(void *cb_cls, struct GNUNET_TESTBED_Operation *op_, 127peerinfo_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 */
151static void 151static void
152op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg) 152op_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,19 +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 */
174static void 174static void
175controller_event_cb(void *cls, 175controller_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 184
185 default: 185 default:
186 FAIL_TEST(0); 186 FAIL_TEST (0);
187 } 187 }
188} 188}
189 189
190 190
@@ -201,27 +201,27 @@ controller_event_cb(void *cls,
201 * failed 201 * failed
202 */ 202 */
203static void 203static void
204test_master(void *cls, 204test_master (void *cls,
205 struct GNUNET_TESTBED_RunHandle *h, 205 struct GNUNET_TESTBED_RunHandle *h,
206 unsigned int num_peers, 206 unsigned int num_peers,
207 struct GNUNET_TESTBED_Peer **peers_, 207 struct GNUNET_TESTBED_Peer **peers_,
208 unsigned int links_succeeded, 208 unsigned int links_succeeded,
209 unsigned int links_failed) 209 unsigned int links_failed)
210{ 210{
211 unsigned int peer; 211 unsigned int peer;
212 212
213 FAIL_TEST(NULL == cls); 213 FAIL_TEST (NULL == cls);
214 FAIL_TEST(NUM_PEERS == num_peers); 214 FAIL_TEST (NUM_PEERS == num_peers);
215 FAIL_TEST(NULL != peers_); 215 FAIL_TEST (NULL != peers_);
216 for (peer = 0; peer < num_peers; peer++) 216 for (peer = 0; peer < num_peers; peer++)
217 FAIL_TEST(NULL != peers_[peer]); 217 FAIL_TEST (NULL != peers_[peer]);
218 peers = peers_; 218 peers = peers_;
219 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],
220 peers[1]); 220 peers[1]);
221 abort_task = 221 abort_task =
222 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 222 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
223 (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, 223 (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort,
224 NULL); 224 NULL);
225} 225}
226 226
227 227
@@ -229,7 +229,7 @@ test_master(void *cls,
229 * Main function 229 * Main function
230 */ 230 */
231int 231int
232main(int argc, char **argv) 232main (int argc, char **argv)
233{ 233{
234 uint64_t event_mask; 234 uint64_t event_mask;
235 235
@@ -237,10 +237,10 @@ main(int argc, char **argv)
237 event_mask = 0; 237 event_mask = 0;
238 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); 238 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
239 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); 239 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
240 (void)GNUNET_TESTBED_test_run("test_testbed_api_test", 240 (void) GNUNET_TESTBED_test_run ("test_testbed_api_test",
241 "test_testbed_api.conf", NUM_PEERS, 241 "test_testbed_api.conf", NUM_PEERS,
242 event_mask, &controller_event_cb, NULL, 242 event_mask, &controller_event_cb, NULL,
243 &test_master, NULL); 243 &test_master, NULL);
244 if (GNUNET_OK != result) 244 if (GNUNET_OK != result)
245 return 1; 245 return 1;
246 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 c5cfea7c0..65cda0b33 100644
--- a/src/testbed/test_testbed_api_test_timeout.c
+++ b/src/testbed/test_testbed_api_test_timeout.c
@@ -35,7 +35,7 @@
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,12 +52,12 @@ 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
63/** 63/**
@@ -67,10 +67,10 @@ static int result;
67 * @param event the controller event 67 * @param event the controller event
68 */ 68 */
69static void 69static void
70controller_event_cb(void *cls, 70controller_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 */
89static void 89static void
90test_master(void *cls, 90test_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,17 @@ test_master(void *cls,
106 * Main function 106 * Main function
107 */ 107 */
108int 108int
109main(int argc, char **argv) 109main (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",
117 event_mask, &controller_event_cb, NULL, 117 NUM_PEERS,
118 &test_master, NULL); 118 event_mask, &controller_event_cb, NULL,
119 &test_master, NULL);
119 if (GNUNET_OK != result) 120 if (GNUNET_OK != result)
120 return 1; 121 return 1;
121 return 0; 122 return 0;
diff --git a/src/testbed/test_testbed_api_testbed_run.c b/src/testbed/test_testbed_api_testbed_run.c
index a3bd415dd..66f857222 100644
--- a/src/testbed/test_testbed_api_testbed_run.c
+++ b/src/testbed/test_testbed_api_testbed_run.c
@@ -46,7 +46,7 @@ static struct GNUNET_TESTBED_Operation *op;
46/** 46/**
47 * Abort task identifier 47 * Abort task identifier
48 */ 48 */
49static struct GNUNET_SCHEDULER_Task * abort_task; 49static struct GNUNET_SCHEDULER_Task *abort_task;
50 50
51/** 51/**
52 * Current peer id 52 * Current peer id
@@ -70,11 +70,11 @@ static int wait_forever;
70 * @param cls NULL 70 * @param cls NULL
71 */ 71 */
72static void 72static void
73do_shutdown(void *cls) 73do_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 */
86static void 86static void
87do_abort(void *cls) 87do_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 */
108static void 108static void
109test_master(void *cls, 109test_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,27 +136,27 @@ test_master(void *cls,
136 * @param event the controller event 136 * @param event the controller event
137 */ 137 */
138static void 138static void
139controller_event_cb(void *cls, 139controller_event_cb (void *cls,
140 const struct GNUNET_TESTBED_EventInformation *event) 140 const struct GNUNET_TESTBED_EventInformation *event)
141{ 141{
142 switch (event->type) 142 switch (event->type)
143 { 143 {
144 case GNUNET_TESTBED_ET_PEER_START: 144 case GNUNET_TESTBED_ET_PEER_START:
145 GNUNET_assert(NULL == peers[peer_id]); 145 GNUNET_assert (NULL == peers[peer_id]);
146 GNUNET_assert(NULL != event->details.peer_start.peer); 146 GNUNET_assert (NULL != event->details.peer_start.peer);
147 peers[peer_id++] = event->details.peer_start.peer; 147 peers[peer_id++] = event->details.peer_start.peer;
148 break; 148 break;
149 149
150 case GNUNET_TESTBED_ET_PEER_STOP: 150 case GNUNET_TESTBED_ET_PEER_STOP:
151 GNUNET_assert(NULL != op); 151 GNUNET_assert (NULL != op);
152 GNUNET_TESTBED_operation_done(op); 152 GNUNET_TESTBED_operation_done (op);
153 GNUNET_assert(peers[0] == event->details.peer_stop.peer); 153 GNUNET_assert (peers[0] == event->details.peer_stop.peer);
154 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); 154 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
155 break; 155 break;
156 156
157 default: 157 default:
158 GNUNET_assert(0); 158 GNUNET_assert (0);
159 } 159 }
160} 160}
161 161
162 162
@@ -169,24 +169,24 @@ controller_event_cb(void *cls,
169 * @param cfg the configuration file handle 169 * @param cfg the configuration file handle
170 */ 170 */
171static void 171static void
172run(void *cls, 172run (void *cls,
173 char *const *args, 173 char *const *args,
174 const char *cfgfile, 174 const char *cfgfile,
175 const struct GNUNET_CONFIGURATION_Handle *config) 175 const struct GNUNET_CONFIGURATION_Handle *config)
176{ 176{
177 uint64_t event_mask; 177 uint64_t event_mask;
178 178
179 event_mask = 0; 179 event_mask = 0;
180 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); 180 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
181 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); 181 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
182 GNUNET_TESTBED_run(NULL, config, NUM_PEERS, event_mask, 182 GNUNET_TESTBED_run (NULL, config, NUM_PEERS, event_mask,
183 &controller_event_cb, NULL, 183 &controller_event_cb, NULL,
184 &test_master, NULL); 184 &test_master, NULL);
185 abort_task = 185 abort_task =
186 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 186 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
187 (GNUNET_TIME_UNIT_SECONDS, 300), 187 (GNUNET_TIME_UNIT_SECONDS, 300),
188 &do_abort, 188 &do_abort,
189 NULL); 189 NULL);
190} 190}
191 191
192 192
@@ -194,7 +194,7 @@ run(void *cls,
194 * Main function 194 * Main function
195 */ 195 */
196int 196int
197main(int argc, char **argv) 197main (int argc, char **argv)
198{ 198{
199 char *argv2[] = { 199 char *argv2[] = {
200 "test_testbed_api_testbed_run", 200 "test_testbed_api_testbed_run",
@@ -208,31 +208,31 @@ main(int argc, char **argv)
208 char *config_filename; 208 char *config_filename;
209 int ret; 209 int ret;
210 210
211 if (NULL == (testname = strrchr(argv[0], (int)'_'))) 211 if (NULL == (testname = strrchr (argv[0], (int) '_')))
212 { 212 {
213 GNUNET_break(0); 213 GNUNET_break (0);
214 return 1; 214 return 1;
215 } 215 }
216 testname++; 216 testname++;
217 testname = GNUNET_strdup(testname); 217 testname = GNUNET_strdup (testname);
218 218
219 if (0 == strcmp("waitforever", testname)) 219 if (0 == strcmp ("waitforever", testname))
220 wait_forever = GNUNET_YES; 220 wait_forever = GNUNET_YES;
221 if ((GNUNET_YES != wait_forever) && (0 != strcmp("run", testname))) 221 if ((GNUNET_YES != wait_forever) && (0 != strcmp ("run", testname)))
222 { 222 {
223 GNUNET_asprintf(&config_filename, "test_testbed_api_testbed_run_%s.conf", 223 GNUNET_asprintf (&config_filename, "test_testbed_api_testbed_run_%s.conf",
224 testname); 224 testname);
225 } 225 }
226 else 226 else
227 config_filename = GNUNET_strdup("test_testbed_api.conf"); 227 config_filename = GNUNET_strdup ("test_testbed_api.conf");
228 GNUNET_free(testname); 228 GNUNET_free (testname);
229 argv2[2] = config_filename; 229 argv2[2] = config_filename;
230 result = GNUNET_SYSERR; 230 result = GNUNET_SYSERR;
231 ret = 231 ret =
232 GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, 232 GNUNET_PROGRAM_run ((sizeof(argv2) / sizeof(char *)) - 1, argv2,
233 "test_testbed_api_testbed_run", "nohelp", options, 233 "test_testbed_api_testbed_run", "nohelp", options,
234 &run, NULL); 234 &run, NULL);
235 GNUNET_free(config_filename); 235 GNUNET_free (config_filename);
236 if ((GNUNET_OK != ret) || (GNUNET_OK != result)) 236 if ((GNUNET_OK != ret) || (GNUNET_OK != result))
237 return 1; 237 return 1;
238 return 0; 238 return 0;
diff --git a/src/testbed/test_testbed_api_topology.c b/src/testbed/test_testbed_api_topology.c
index c6e25c656..1fa13bf4f 100644
--- a/src/testbed/test_testbed_api_topology.c
+++ b/src/testbed/test_testbed_api_topology.c
@@ -46,7 +46,7 @@ static struct GNUNET_TESTBED_Operation *op;
46/** 46/**
47 * Shutdown task 47 * Shutdown task
48 */ 48 */
49static struct GNUNET_SCHEDULER_Task * shutdown_task; 49static struct GNUNET_SCHEDULER_Task *shutdown_task;
50 50
51/** 51/**
52 * Testing result 52 * Testing result
@@ -65,15 +65,15 @@ static unsigned int overlay_connects;
65 * @param cls NULL 65 * @param cls NULL
66 */ 66 */
67static void 67static void
68do_shutdown(void *cls) 68do_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,36 +83,36 @@ do_shutdown(void *cls)
83 * @param event the controller event 83 * @param event the controller event
84 */ 84 */
85static void 85static void
86controller_event_cb(void *cls, 86controller_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)
90 { 94 {
91 case GNUNET_TESTBED_ET_CONNECT: 95 result = GNUNET_OK;
92 overlay_connects++; 96 GNUNET_SCHEDULER_cancel (shutdown_task);
93 if ((NUM_PEERS) == overlay_connects) 97 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
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);
115 } 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);
115 }
116} 116}
117 117
118 118
@@ -129,37 +129,37 @@ controller_event_cb(void *cls,
129 * failed 129 * failed
130 */ 130 */
131static void 131static void
132test_master(void *cls, 132test_master (void *cls,
133 struct GNUNET_TESTBED_RunHandle *h, 133 struct GNUNET_TESTBED_RunHandle *h,
134 unsigned int num_peers, 134 unsigned int num_peers,
135 struct GNUNET_TESTBED_Peer **peers_, 135 struct GNUNET_TESTBED_Peer **peers_,
136 unsigned int links_succeeded, 136 unsigned int links_succeeded,
137 unsigned int links_failed) 137 unsigned int links_failed)
138{ 138{
139 unsigned int peer; 139 unsigned int peer;
140 140
141 GNUNET_assert(NULL == cls); 141 GNUNET_assert (NULL == cls);
142 if (NULL == peers_) 142 if (NULL == peers_)
143 { 143 {
144 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");
145 return; 145 return;
146 } 146 }
147 GNUNET_assert(NUM_PEERS == num_peers); 147 GNUNET_assert (NUM_PEERS == num_peers);
148 for (peer = 0; peer < num_peers; peer++) 148 for (peer = 0; peer < num_peers; peer++)
149 GNUNET_assert(NULL != peers_[peer]); 149 GNUNET_assert (NULL != peers_[peer]);
150 peers = peers_; 150 peers = peers_;
151 overlay_connects = 0; 151 overlay_connects = 0;
152 op = GNUNET_TESTBED_overlay_configure_topology(NULL, NUM_PEERS, peers, NULL, 152 op = GNUNET_TESTBED_overlay_configure_topology (NULL, NUM_PEERS, peers, NULL,
153 NULL, 153 NULL,
154 NULL, 154 NULL,
155 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, 155 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
156 NUM_PEERS, 156 NUM_PEERS,
157 GNUNET_TESTBED_TOPOLOGY_OPTION_END); 157 GNUNET_TESTBED_TOPOLOGY_OPTION_END);
158 GNUNET_assert(NULL != op); 158 GNUNET_assert (NULL != op);
159 shutdown_task = 159 shutdown_task =
160 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 160 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
161 (GNUNET_TIME_UNIT_SECONDS, 300), 161 (GNUNET_TIME_UNIT_SECONDS, 300),
162 do_shutdown, NULL); 162 do_shutdown, NULL);
163} 163}
164 164
165 165
@@ -167,7 +167,7 @@ test_master(void *cls,
167 * Main function 167 * Main function
168 */ 168 */
169int 169int
170main(int argc, char **argv) 170main (int argc, char **argv)
171{ 171{
172 uint64_t event_mask; 172 uint64_t event_mask;
173 173
@@ -175,10 +175,10 @@ main(int argc, char **argv)
175 event_mask = 0; 175 event_mask = 0;
176 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); 176 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
177 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); 177 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
178 (void)GNUNET_TESTBED_test_run("test_testbed_api_test", 178 (void) GNUNET_TESTBED_test_run ("test_testbed_api_test",
179 "test_testbed_api.conf", NUM_PEERS, 179 "test_testbed_api.conf", NUM_PEERS,
180 event_mask, &controller_event_cb, NULL, 180 event_mask, &controller_event_cb, NULL,
181 &test_master, NULL); 181 &test_master, NULL);
182 if (GNUNET_OK != result) 182 if (GNUNET_OK != result)
183 return 1; 183 return 1;
184 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 866ec83c5..33569a2b9 100644
--- a/src/testbed/test_testbed_api_topology_clique.c
+++ b/src/testbed/test_testbed_api_topology_clique.c
@@ -46,7 +46,7 @@ static struct GNUNET_TESTBED_Operation *op;
46/** 46/**
47 * Shutdown task 47 * Shutdown task
48 */ 48 */
49static struct GNUNET_SCHEDULER_Task * shutdown_task; 49static struct GNUNET_SCHEDULER_Task *shutdown_task;
50 50
51/** 51/**
52 * Testing result 52 * Testing result
@@ -65,15 +65,15 @@ static unsigned int overlay_connects;
65 * @param cls NULL 65 * @param cls NULL
66 */ 66 */
67static void 67static void
68do_shutdown(void *cls) 68do_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,31 +83,31 @@ do_shutdown(void *cls)
83 * @param event the controller event 83 * @param event the controller event
84 */ 84 */
85static void 85static void
86controller_event_cb(void *cls, 86controller_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)
90 { 94 {
91 case GNUNET_TESTBED_ET_CONNECT: 95 result = GNUNET_OK;
92 overlay_connects++; 96 GNUNET_SCHEDULER_cancel (shutdown_task);
93 if ((NUM_PEERS * (NUM_PEERS - 1)) == overlay_connects) 97 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
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);
110 } 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);
110 }
111} 111}
112 112
113 113
@@ -124,38 +124,38 @@ controller_event_cb(void *cls,
124 * failed 124 * failed
125 */ 125 */
126static void 126static void
127test_master(void *cls, 127test_master (void *cls,
128 struct GNUNET_TESTBED_RunHandle *h, 128 struct GNUNET_TESTBED_RunHandle *h,
129 unsigned int num_peers, 129 unsigned int num_peers,
130 struct GNUNET_TESTBED_Peer **peers_, 130 struct GNUNET_TESTBED_Peer **peers_,
131 unsigned int links_succeeded, 131 unsigned int links_succeeded,
132 unsigned int links_failed) 132 unsigned int links_failed)
133{ 133{
134 unsigned int peer; 134 unsigned int peer;
135 135
136 GNUNET_assert(NULL == cls); 136 GNUNET_assert (NULL == cls);
137 if (NULL == peers_) 137 if (NULL == peers_)
138 { 138 {
139 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");
140 return; 140 return;
141 } 141 }
142 GNUNET_assert(NUM_PEERS == num_peers); 142 GNUNET_assert (NUM_PEERS == num_peers);
143 for (peer = 0; peer < num_peers; peer++) 143 for (peer = 0; peer < num_peers; peer++)
144 GNUNET_assert(NULL != peers_[peer]); 144 GNUNET_assert (NULL != peers_[peer]);
145 peers = peers_; 145 peers = peers_;
146 overlay_connects = 0; 146 overlay_connects = 0;
147 op = GNUNET_TESTBED_overlay_configure_topology(NULL, NUM_PEERS, peers, NULL, 147 op = GNUNET_TESTBED_overlay_configure_topology (NULL, NUM_PEERS, peers, NULL,
148 NULL, 148 NULL,
149 NULL, 149 NULL,
150 GNUNET_TESTBED_TOPOLOGY_CLIQUE, 150 GNUNET_TESTBED_TOPOLOGY_CLIQUE,
151 /* GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, */ 151 /* GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, */
152 /* NUM_PEERS, */ 152 /* NUM_PEERS, */
153 GNUNET_TESTBED_TOPOLOGY_OPTION_END); 153 GNUNET_TESTBED_TOPOLOGY_OPTION_END);
154 GNUNET_assert(NULL != op); 154 GNUNET_assert (NULL != op);
155 shutdown_task = 155 shutdown_task =
156 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 156 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
157 (GNUNET_TIME_UNIT_SECONDS, 300), 157 (GNUNET_TIME_UNIT_SECONDS, 300),
158 do_shutdown, NULL); 158 do_shutdown, NULL);
159} 159}
160 160
161 161
@@ -163,7 +163,7 @@ test_master(void *cls,
163 * Main function 163 * Main function
164 */ 164 */
165int 165int
166main(int argc, char **argv) 166main (int argc, char **argv)
167{ 167{
168 uint64_t event_mask; 168 uint64_t event_mask;
169 169
@@ -171,10 +171,10 @@ main(int argc, char **argv)
171 event_mask = 0; 171 event_mask = 0;
172 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); 172 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
173 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); 173 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
174 (void)GNUNET_TESTBED_test_run("test_testbed_api_test", 174 (void) GNUNET_TESTBED_test_run ("test_testbed_api_test",
175 "test_testbed_api.conf", NUM_PEERS, 175 "test_testbed_api.conf", NUM_PEERS,
176 event_mask, &controller_event_cb, NULL, 176 event_mask, &controller_event_cb, NULL,
177 &test_master, NULL); 177 &test_master, NULL);
178 if (GNUNET_OK != result) 178 if (GNUNET_OK != result)
179 return 1; 179 return 1;
180 return 0; 180 return 0;
diff --git a/src/testbed/test_testbed_underlay.c b/src/testbed/test_testbed_underlay.c
index fad4282d7..e0434379b 100644
--- a/src/testbed/test_testbed_underlay.c
+++ b/src/testbed/test_testbed_underlay.c
@@ -49,10 +49,10 @@ static struct GNUNET_TESTBED_Operation *op;
49 * @param tc scheduler task context 49 * @param tc scheduler task context
50 */ 50 */
51static void 51static void
52do_shutdown(void *cls) 52do_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,23 @@ do_shutdown(void *cls)
66 * operation has executed successfully. 66 * operation has executed successfully.
67 */ 67 */
68static void 68static void
69overlay_connect_status(void *cls, 69overlay_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,
78 "Peers 0 and 2 should not get connected\n");
78 else 79 else
79 { 80 {
80 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peers 0 and 2 not connected: %s. Success!\n", emsg); 81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
81 result = GNUNET_OK; 82 "Peers 0 and 2 not connected: %s. Success!\n", emsg);
82 } 83 result = GNUNET_OK;
83 GNUNET_SCHEDULER_shutdown(); 84 }
85 GNUNET_SCHEDULER_shutdown ();
84} 86}
85 87
86 88
@@ -98,29 +100,30 @@ overlay_connect_status(void *cls,
98 * failed 100 * failed
99 */ 101 */
100static void 102static void
101test_master(void *cls, 103test_master (void *cls,
102 struct GNUNET_TESTBED_RunHandle *h, 104 struct GNUNET_TESTBED_RunHandle *h,
103 unsigned int num_peers, 105 unsigned int num_peers,
104 struct GNUNET_TESTBED_Peer **peers_, 106 struct GNUNET_TESTBED_Peer **peers_,
105 unsigned int links_succeeded, 107 unsigned int links_succeeded,
106 unsigned int links_failed) 108 unsigned int links_failed)
107{ 109{
108 GNUNET_assert(NULL == cls); 110 GNUNET_assert (NULL == cls);
109 if (NULL == peers_) 111 if (NULL == peers_)
110 { 112 {
111 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n"); 113 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n");
112 GNUNET_SCHEDULER_shutdown(); 114 GNUNET_SCHEDULER_shutdown ();
113 return; 115 return;
114 } 116 }
115 GNUNET_assert(NUM_PEERS == num_peers); 117 GNUNET_assert (NUM_PEERS == num_peers);
116 op = GNUNET_TESTBED_overlay_connect(NULL, 118 op = GNUNET_TESTBED_overlay_connect (NULL,
117 &overlay_connect_status, 119 &overlay_connect_status,
118 NULL, 120 NULL,
119 peers_[0], 121 peers_[0],
120 peers_[2]); 122 peers_[2]);
121 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 123 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
122 60), 124 GNUNET_TIME_UNIT_SECONDS,
123 &do_shutdown, NULL); 125 60),
126 &do_shutdown, NULL);
124} 127}
125 128
126 129
@@ -136,7 +139,7 @@ test_master(void *cls,
136 * Main function 139 * Main function
137 */ 140 */
138int 141int
139main(int argc, char **argv) 142main (int argc, char **argv)
140{ 143{
141 struct GNUNET_CONFIGURATION_Handle *cfg; 144 struct GNUNET_CONFIGURATION_Handle *cfg;
142 char pwd[PATH_MAX]; 145 char pwd[PATH_MAX];
@@ -145,26 +148,27 @@ main(int argc, char **argv)
145 148
146 result = GNUNET_SYSERR; 149 result = GNUNET_SYSERR;
147 event_mask = 0; 150 event_mask = 0;
148 cfg = GNUNET_CONFIGURATION_create(); 151 cfg = GNUNET_CONFIGURATION_create ();
149 GNUNET_assert(GNUNET_YES == 152 GNUNET_assert (GNUNET_YES ==
150 GNUNET_CONFIGURATION_parse(cfg, 153 GNUNET_CONFIGURATION_parse (cfg,
151 "test_testbed_underlay.conf.in")); 154 "test_testbed_underlay.conf.in"));
152 if (NULL == getcwd(pwd, PATH_MAX)) 155 if (NULL == getcwd (pwd, PATH_MAX))
153 return 1; 156 return 1;
154 GNUNET_assert(0 < GNUNET_asprintf(&dbfile, "%s/%s", pwd, 157 GNUNET_assert (0 < GNUNET_asprintf (&dbfile, "%s/%s", pwd,
155 "test-underlay.sqlite")); 158 "test-underlay.sqlite"));
156 GNUNET_CONFIGURATION_set_value_string(cfg, "TESTBED-UNDERLAY", "DBFILE", dbfile); 159 GNUNET_CONFIGURATION_set_value_string (cfg, "TESTBED-UNDERLAY", "DBFILE",
157 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_write 160 dbfile);
158 (cfg, "test_testbed_underlay.conf")); 161 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write
159 GNUNET_CONFIGURATION_destroy(cfg); 162 (cfg, "test_testbed_underlay.conf"));
163 GNUNET_CONFIGURATION_destroy (cfg);
160 cfg = NULL; 164 cfg = NULL;
161 GNUNET_free(dbfile); 165 GNUNET_free (dbfile);
162 dbfile = NULL; 166 dbfile = NULL;
163 (void)GNUNET_TESTBED_test_run("test_testbed_underlay", 167 (void) GNUNET_TESTBED_test_run ("test_testbed_underlay",
164 "test_testbed_underlay.conf", NUM_PEERS, 168 "test_testbed_underlay.conf", NUM_PEERS,
165 event_mask, NULL, NULL, 169 event_mask, NULL, NULL,
166 &test_master, NULL); 170 &test_master, NULL);
167 (void)unlink("test_testbed_underlay.conf"); 171 (void) unlink ("test_testbed_underlay.conf");
168 if (GNUNET_OK != result) 172 if (GNUNET_OK != result)
169 return 1; 173 return 1;
170 return 0; 174 return 0;
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h
index 8ab957b88..0f86c149b 100644
--- a/src/testbed/testbed.h
+++ b/src/testbed/testbed.h
@@ -33,7 +33,8 @@ 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 */
36struct GNUNET_TESTBED_InitMessage { 36struct GNUNET_TESTBED_InitMessage
37{
37 /** 38 /**
38 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_INIT 39 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_INIT
39 */ 40 */
@@ -60,7 +61,8 @@ struct GNUNET_TESTBED_InitMessage {
60/** 61/**
61 * Notify the service about a host that we intend to use. 62 * Notify the service about a host that we intend to use.
62 */ 63 */
63struct GNUNET_TESTBED_AddHostMessage { 64struct GNUNET_TESTBED_AddHostMessage
65{
64 /** 66 /**
65 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST 67 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST
66 */ 68 */
@@ -109,7 +111,8 @@ struct GNUNET_TESTBED_AddHostMessage {
109 * worked (or failed). 111 * worked (or failed).
110 * FIXME: Where is this required? 112 * FIXME: Where is this required?
111 */ 113 */
112struct GNUNET_TESTBED_HostConfirmedMessage { 114struct GNUNET_TESTBED_HostConfirmedMessage
115{
113 /** 116 /**
114 * Type is GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS 117 * Type is GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS
115 */ 118 */
@@ -130,7 +133,8 @@ struct GNUNET_TESTBED_HostConfirmedMessage {
130 * requests for a particular client to a particular 133 * requests for a particular client to a particular
131 * sub-controller. 134 * sub-controller.
132 */ 135 */
133struct GNUNET_TESTBED_ControllerLinkRequest { 136struct GNUNET_TESTBED_ControllerLinkRequest
137{
134 /** 138 /**
135 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS 139 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS
136 */ 140 */
@@ -162,7 +166,8 @@ struct GNUNET_TESTBED_ControllerLinkRequest {
162/** 166/**
163 * Response message for ControllerLinkRequest message 167 * Response message for ControllerLinkRequest message
164 */ 168 */
165struct GNUNET_TESTBED_ControllerLinkResponse { 169struct GNUNET_TESTBED_ControllerLinkResponse
170{
166 /** 171 /**
167 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT 172 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT
168 */ 173 */
@@ -196,7 +201,8 @@ struct GNUNET_TESTBED_ControllerLinkResponse {
196 * Message sent from client to testing service to 201 * Message sent from client to testing service to
197 * create (configure, but not start) a peer. 202 * create (configure, but not start) a peer.
198 */ 203 */
199struct GNUNET_TESTBED_PeerCreateMessage { 204struct GNUNET_TESTBED_PeerCreateMessage
205{
200 /** 206 /**
201 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER 207 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER
202 */ 208 */
@@ -231,7 +237,8 @@ struct GNUNET_TESTBED_PeerCreateMessage {
231 * Message sent from client to testing service to 237 * Message sent from client to testing service to
232 * reconfigure a (stopped) a peer. 238 * reconfigure a (stopped) a peer.
233 */ 239 */
234struct GNUNET_TESTBED_PeerReconfigureMessage { 240struct GNUNET_TESTBED_PeerReconfigureMessage
241{
235 /** 242 /**
236 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER 243 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER
237 */ 244 */
@@ -261,7 +268,8 @@ struct GNUNET_TESTBED_PeerReconfigureMessage {
261 * Message sent from client to testing service to 268 * Message sent from client to testing service to
262 * start a peer. 269 * start a peer.
263 */ 270 */
264struct GNUNET_TESTBED_PeerStartMessage { 271struct GNUNET_TESTBED_PeerStartMessage
272{
265 /** 273 /**
266 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_START_PEER 274 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_START_PEER
267 */ 275 */
@@ -283,7 +291,8 @@ struct GNUNET_TESTBED_PeerStartMessage {
283 * Message sent from client to testing service to 291 * Message sent from client to testing service to
284 * stop a peer. 292 * stop a peer.
285 */ 293 */
286struct GNUNET_TESTBED_PeerStopMessage { 294struct GNUNET_TESTBED_PeerStopMessage
295{
287 /** 296 /**
288 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER 297 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER
289 */ 298 */
@@ -305,7 +314,8 @@ struct GNUNET_TESTBED_PeerStopMessage {
305 * Message sent from client to testing service to 314 * Message sent from client to testing service to
306 * destroy a (stopped) peer. 315 * destroy a (stopped) peer.
307 */ 316 */
308struct GNUNET_TESTBED_PeerDestroyMessage { 317struct GNUNET_TESTBED_PeerDestroyMessage
318{
309 /** 319 /**
310 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER 320 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER
311 */ 321 */
@@ -327,7 +337,8 @@ struct GNUNET_TESTBED_PeerDestroyMessage {
327 * Message sent from client to testing service to 337 * Message sent from client to testing service to
328 * (re)configure a "physical" link between two peers. 338 * (re)configure a "physical" link between two peers.
329 */ 339 */
330struct GNUNET_TESTBED_ConfigureUnderlayLinkMessage { 340struct GNUNET_TESTBED_ConfigureUnderlayLinkMessage
341{
331 /** 342 /**
332 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_CONFIGURE_UNDERLAY_LINK 343 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_CONFIGURE_UNDERLAY_LINK
333 */ 344 */
@@ -361,7 +372,8 @@ struct GNUNET_TESTBED_ConfigureUnderlayLinkMessage {
361 * Message sent from client to testing service to 372 * Message sent from client to testing service to
362 * connect two peers. 373 * connect two peers.
363 */ 374 */
364struct GNUNET_TESTBED_OverlayConnectMessage { 375struct GNUNET_TESTBED_OverlayConnectMessage
376{
365 /** 377 /**
366 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT 378 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT
367 */ 379 */
@@ -393,7 +405,8 @@ struct GNUNET_TESTBED_OverlayConnectMessage {
393 * Message sent from host controller of a peer(A) to the host controller of 405 * Message sent from host controller of a peer(A) to the host controller of
394 * another peer(B) to request B to connect to A 406 * another peer(B) to request B to connect to A
395 */ 407 */
396struct GNUNET_TESTBED_RemoteOverlayConnectMessage { 408struct GNUNET_TESTBED_RemoteOverlayConnectMessage
409{
397 /** 410 /**
398 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT 411 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT
399 */ 412 */
@@ -426,7 +439,8 @@ struct GNUNET_TESTBED_RemoteOverlayConnectMessage {
426/** 439/**
427 * Event notification from a controller to a client. 440 * Event notification from a controller to a client.
428 */ 441 */
429struct GNUNET_TESTBED_PeerEventMessage { 442struct GNUNET_TESTBED_PeerEventMessage
443{
430 /** 444 /**
431 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT 445 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT
432 */ 446 */
@@ -458,7 +472,8 @@ struct GNUNET_TESTBED_PeerEventMessage {
458/** 472/**
459 * Event notification from a controller to a client. 473 * Event notification from a controller to a client.
460 */ 474 */
461struct GNUNET_TESTBED_ConnectionEventMessage { 475struct GNUNET_TESTBED_ConnectionEventMessage
476{
462 /** 477 /**
463 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT 478 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT
464 */ 479 */
@@ -490,7 +505,8 @@ struct GNUNET_TESTBED_ConnectionEventMessage {
490/** 505/**
491 * Event notification from a controller to a client. 506 * Event notification from a controller to a client.
492 */ 507 */
493struct GNUNET_TESTBED_OperationFailureEventMessage { 508struct GNUNET_TESTBED_OperationFailureEventMessage
509{
494 /** 510 /**
495 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT 511 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT
496 */ 512 */
@@ -514,7 +530,8 @@ struct GNUNET_TESTBED_OperationFailureEventMessage {
514/** 530/**
515 * Event notification from a controller to a client. 531 * Event notification from a controller to a client.
516 */ 532 */
517struct GNUNET_TESTBED_PeerCreateSuccessEventMessage { 533struct GNUNET_TESTBED_PeerCreateSuccessEventMessage
534{
518 /** 535 /**
519 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS 536 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS
520 */ 537 */
@@ -537,7 +554,8 @@ struct GNUNET_TESTBED_PeerCreateSuccessEventMessage {
537 * a generic operational success where the operation does 554 * a generic operational success where the operation does
538 * not return any data. 555 * not return any data.
539 */ 556 */
540struct GNUNET_TESTBED_GenericOperationSuccessEventMessage { 557struct GNUNET_TESTBED_GenericOperationSuccessEventMessage
558{
541 /** 559 /**
542 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS 560 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS
543 */ 561 */
@@ -560,7 +578,8 @@ struct GNUNET_TESTBED_GenericOperationSuccessEventMessage {
560 * Message sent from client to testing service to 578 * Message sent from client to testing service to
561 * obtain the configuration of a peer. 579 * obtain the configuration of a peer.
562 */ 580 */
563struct GNUNET_TESTBED_PeerGetConfigurationMessage { 581struct GNUNET_TESTBED_PeerGetConfigurationMessage
582{
564 /** 583 /**
565 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION 584 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION
566 */ 585 */
@@ -581,7 +600,8 @@ struct GNUNET_TESTBED_PeerGetConfigurationMessage {
581/** 600/**
582 * Peer configuration and identity reply from controller to a client. 601 * Peer configuration and identity reply from controller to a client.
583 */ 602 */
584struct GNUNET_TESTBED_PeerConfigurationInformationMessage { 603struct GNUNET_TESTBED_PeerConfigurationInformationMessage
604{
585 /** 605 /**
586 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION 606 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION
587 */ 607 */
@@ -614,7 +634,8 @@ struct GNUNET_TESTBED_PeerConfigurationInformationMessage {
614/** 634/**
615 * Message to request configuration of a slave controller 635 * Message to request configuration of a slave controller
616 */ 636 */
617struct GNUNET_TESTBED_SlaveGetConfigurationMessage { 637struct GNUNET_TESTBED_SlaveGetConfigurationMessage
638{
618 /** 639 /**
619 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION 640 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION
620 */ 641 */
@@ -635,7 +656,8 @@ struct GNUNET_TESTBED_SlaveGetConfigurationMessage {
635/** 656/**
636 * Reply to #GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION message 657 * Reply to #GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION message
637 */ 658 */
638struct GNUNET_TESTBED_SlaveConfiguration { 659struct GNUNET_TESTBED_SlaveConfiguration
660{
639 /** 661 /**
640 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION 662 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION
641 */ 663 */
@@ -663,7 +685,8 @@ struct GNUNET_TESTBED_SlaveConfiguration {
663/** 685/**
664 * Shutdown peers message 686 * Shutdown peers message
665 */ 687 */
666struct GNUNET_TESTBED_ShutdownPeersMessage { 688struct GNUNET_TESTBED_ShutdownPeersMessage
689{
667 /** 690 /**
668 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS 691 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS
669 */ 692 */
@@ -679,7 +702,8 @@ struct GNUNET_TESTBED_ShutdownPeersMessage {
679/** 702/**
680 * Message to start/stop services of a peer 703 * Message to start/stop services of a peer
681 */ 704 */
682struct GNUNET_TESTBED_ManagePeerServiceMessage { 705struct GNUNET_TESTBED_ManagePeerServiceMessage
706{
683 /** 707 /**
684 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS 708 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS
685 */ 709 */
@@ -710,7 +734,8 @@ struct GNUNET_TESTBED_ManagePeerServiceMessage {
710 * Message to send underlay link model of a peer. This message will be 734 * Message to send underlay link model of a peer. This message will be
711 * forwarded to the controller running the peer. 735 * forwarded to the controller running the peer.
712 */ 736 */
713struct GNUNET_TESTBED_UnderlayLinkModelMsg { 737struct GNUNET_TESTBED_UnderlayLinkModelMsg
738{
714 /** 739 /**
715 * Type is #GNUNET_MESSAGE_TYPE_UNDERLAYLINKMODELMSG 740 * Type is #GNUNET_MESSAGE_TYPE_UNDERLAYLINKMODELMSG
716 */ 741 */
@@ -754,7 +779,8 @@ struct GNUNET_TESTBED_UnderlayLinkModelMsg {
754/** 779/**
755 * Message to initialise a barrier 780 * Message to initialise a barrier
756 */ 781 */
757struct GNUNET_TESTBED_BarrierInit { 782struct GNUNET_TESTBED_BarrierInit
783{
758 /** 784 /**
759 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT 785 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT
760 */ 786 */
@@ -775,7 +801,8 @@ struct GNUNET_TESTBED_BarrierInit {
775/** 801/**
776 * Message to cancel a barrier 802 * Message to cancel a barrier
777 */ 803 */
778struct GNUNET_TESTBED_BarrierCancel { 804struct GNUNET_TESTBED_BarrierCancel
805{
779 /** 806 /**
780 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL 807 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL
781 */ 808 */
@@ -791,7 +818,8 @@ struct GNUNET_TESTBED_BarrierCancel {
791/** 818/**
792 * Message for signalling status changes of a barrier 819 * Message for signalling status changes of a barrier
793 */ 820 */
794struct GNUNET_TESTBED_BarrierStatusMsg { 821struct GNUNET_TESTBED_BarrierStatusMsg
822{
795 /** 823 /**
796 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS 824 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS
797 */ 825 */
@@ -819,7 +847,8 @@ struct GNUNET_TESTBED_BarrierStatusMsg {
819 * Message sent from peers to the testbed-barrier service to indicate that they 847 * Message sent from peers to the testbed-barrier service to indicate that they
820 * have reached a barrier and are waiting for it to be crossed 848 * have reached a barrier and are waiting for it to be crossed
821 */ 849 */
822struct GNUNET_TESTBED_BarrierWait { 850struct GNUNET_TESTBED_BarrierWait
851{
823 /** 852 /**
824 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT 853 * Type is #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT
825 */ 854 */
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index 8ca96dcbe..38913509b 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -44,30 +44,31 @@
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 */
70struct ForwardedOperationData { 70struct ForwardedOperationData
71{
71 /** 72 /**
72 * The callback to call when reply is available 73 * The callback to call when reply is available
73 */ 74 */
@@ -83,7 +84,8 @@ struct ForwardedOperationData {
83/** 84/**
84 * Context data for get slave config operations 85 * Context data for get slave config operations
85 */ 86 */
86struct GetSlaveConfigData { 87struct GetSlaveConfigData
88{
87 /** 89 /**
88 * The id of the slave controller 90 * The id of the slave controller
89 */ 91 */
@@ -94,7 +96,8 @@ struct GetSlaveConfigData {
94/** 96/**
95 * Context data for controller link operations 97 * Context data for controller link operations
96 */ 98 */
97struct ControllerLinkData { 99struct ControllerLinkData
100{
98 /** 101 /**
99 * The controller link message 102 * The controller link message
100 */ 103 */
@@ -110,7 +113,8 @@ struct ControllerLinkData {
110/** 113/**
111 * Date context for OP_SHUTDOWN_PEERS operations 114 * Date context for OP_SHUTDOWN_PEERS operations
112 */ 115 */
113struct ShutdownPeersData { 116struct ShutdownPeersData
117{
114 /** 118 /**
115 * The operation completion callback to call 119 * The operation completion callback to call
116 */ 120 */
@@ -126,7 +130,8 @@ struct ShutdownPeersData {
126/** 130/**
127 * An entry in the stack for keeping operations which are about to expire 131 * An entry in the stack for keeping operations which are about to expire
128 */ 132 */
129struct ExpireOperationEntry { 133struct ExpireOperationEntry
134{
130 /** 135 /**
131 * DLL head; new entries are to be inserted here 136 * DLL head; new entries are to be inserted here
132 */ 137 */
@@ -161,13 +166,13 @@ static struct ExpireOperationEntry *exop_tail;
161 * @param op the operation to insert 166 * @param op the operation to insert
162 */ 167 */
163static void 168static void
164exop_insert(struct GNUNET_TESTBED_Operation *op) 169exop_insert (struct GNUNET_TESTBED_Operation *op)
165{ 170{
166 struct ExpireOperationEntry *entry; 171 struct ExpireOperationEntry *entry;
167 172
168 entry = GNUNET_new(struct ExpireOperationEntry); 173 entry = GNUNET_new (struct ExpireOperationEntry);
169 entry->op = op; 174 entry->op = op;
170 GNUNET_CONTAINER_DLL_insert_tail(exop_head, exop_tail, entry); 175 GNUNET_CONTAINER_DLL_insert_tail (exop_head, exop_tail, entry);
171} 176}
172 177
173 178
@@ -183,7 +188,7 @@ exop_insert(struct GNUNET_TESTBED_Operation *op)
183 * paramenter will return GNUNET_NO) 188 * paramenter will return GNUNET_NO)
184 */ 189 */
185static int 190static int
186exop_check(const struct GNUNET_TESTBED_Operation *const op) 191exop_check (const struct GNUNET_TESTBED_Operation *const op)
187{ 192{
188 struct ExpireOperationEntry *entry; 193 struct ExpireOperationEntry *entry;
189 struct ExpireOperationEntry *entry2; 194 struct ExpireOperationEntry *entry2;
@@ -192,24 +197,24 @@ exop_check(const struct GNUNET_TESTBED_Operation *const op)
192 found = GNUNET_NO; 197 found = GNUNET_NO;
193 entry = exop_head; 198 entry = exop_head;
194 while (NULL != entry) 199 while (NULL != entry)
200 {
201 if (op == entry->op)
195 { 202 {
196 if (op == entry->op) 203 found = GNUNET_YES;
197 { 204 break;
198 found = GNUNET_YES;
199 break;
200 }
201 entry = entry->next;
202 } 205 }
206 entry = entry->next;
207 }
203 if (GNUNET_NO == found) 208 if (GNUNET_NO == found)
204 return GNUNET_NO; 209 return GNUNET_NO;
205 /* Truncate the tail */ 210 /* Truncate the tail */
206 while (NULL != entry) 211 while (NULL != entry)
207 { 212 {
208 entry2 = entry->next; 213 entry2 = entry->next;
209 GNUNET_CONTAINER_DLL_remove(exop_head, exop_tail, entry); 214 GNUNET_CONTAINER_DLL_remove (exop_head, exop_tail, entry);
210 GNUNET_free(entry); 215 GNUNET_free (entry);
211 entry = entry2; 216 entry = entry2;
212 } 217 }
213 return GNUNET_YES; 218 return GNUNET_YES;
214} 219}
215 220
@@ -217,7 +222,8 @@ exop_check(const struct GNUNET_TESTBED_Operation *const op)
217/** 222/**
218 * Context information to be used while searching for operation contexts 223 * Context information to be used while searching for operation contexts
219 */ 224 */
220struct SearchContext { 225struct SearchContext
226{
221 /** 227 /**
222 * The result of the search 228 * The result of the search
223 */ 229 */
@@ -240,13 +246,13 @@ struct SearchContext {
240 * #GNUNET_NO if not. 246 * #GNUNET_NO if not.
241 */ 247 */
242static int 248static int
243opc_search_iterator(void *cls, uint32_t key, void *value) 249opc_search_iterator (void *cls, uint32_t key, void *value)
244{ 250{
245 struct SearchContext *sc = cls; 251 struct SearchContext *sc = cls;
246 struct OperationContext *opc = value; 252 struct OperationContext *opc = value;
247 253
248 GNUNET_assert(NULL != opc); 254 GNUNET_assert (NULL != opc);
249 GNUNET_assert(NULL == sc->opc); 255 GNUNET_assert (NULL == sc->opc);
250 if (opc->id != sc->id) 256 if (opc->id != sc->id)
251 return GNUNET_YES; 257 return GNUNET_YES;
252 sc->opc = opc; 258 sc->opc = opc;
@@ -263,18 +269,18 @@ opc_search_iterator(void *cls, uint32_t key, void *value)
263 * @return the matching operation context; NULL if no match found 269 * @return the matching operation context; NULL if no match found
264 */ 270 */
265static struct OperationContext * 271static struct OperationContext *
266find_opc(const struct GNUNET_TESTBED_Controller *c, const uint64_t id) 272find_opc (const struct GNUNET_TESTBED_Controller *c, const uint64_t id)
267{ 273{
268 struct SearchContext sc; 274 struct SearchContext sc;
269 275
270 sc.id = id; 276 sc.id = id;
271 sc.opc = NULL; 277 sc.opc = NULL;
272 GNUNET_assert(NULL != c->opc_map); 278 GNUNET_assert (NULL != c->opc_map);
273 if (GNUNET_SYSERR != 279 if (GNUNET_SYSERR !=
274 GNUNET_CONTAINER_multihashmap32_get_multiple(c->opc_map, 280 GNUNET_CONTAINER_multihashmap32_get_multiple (c->opc_map,
275 (uint32_t)id, 281 (uint32_t) id,
276 &opc_search_iterator, 282 &opc_search_iterator,
277 &sc)) 283 &sc))
278 return NULL; 284 return NULL;
279 return sc.opc; 285 return sc.opc;
280} 286}
@@ -289,16 +295,16 @@ find_opc(const struct GNUNET_TESTBED_Controller *c, const uint64_t id)
289 * @param opc the operation context to be inserted 295 * @param opc the operation context to be inserted
290 */ 296 */
291void 297void
292GNUNET_TESTBED_insert_opc_(struct GNUNET_TESTBED_Controller *c, 298GNUNET_TESTBED_insert_opc_ (struct GNUNET_TESTBED_Controller *c,
293 struct OperationContext *opc) 299 struct OperationContext *opc)
294{ 300{
295 if (NULL == c->opc_map) 301 if (NULL == c->opc_map)
296 c->opc_map = GNUNET_CONTAINER_multihashmap32_create(256); 302 c->opc_map = GNUNET_CONTAINER_multihashmap32_create (256);
297 GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap32_put( 303 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap32_put (
298 c->opc_map, 304 c->opc_map,
299 (uint32_t)opc->id, 305 (uint32_t) opc->id,
300 opc, 306 opc,
301 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 307 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
302} 308}
303 309
304 310
@@ -310,17 +316,17 @@ GNUNET_TESTBED_insert_opc_(struct GNUNET_TESTBED_Controller *c,
310 * @param opc the operation context to remove 316 * @param opc the operation context to remove
311 */ 317 */
312void 318void
313GNUNET_TESTBED_remove_opc_(const struct GNUNET_TESTBED_Controller *c, 319GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c,
314 struct OperationContext *opc) 320 struct OperationContext *opc)
315{ 321{
316 GNUNET_assert(NULL != c->opc_map); 322 GNUNET_assert (NULL != c->opc_map);
317 GNUNET_assert(GNUNET_YES == 323 GNUNET_assert (GNUNET_YES ==
318 GNUNET_CONTAINER_multihashmap32_remove(c->opc_map, 324 GNUNET_CONTAINER_multihashmap32_remove (c->opc_map,
319 (uint32_t)opc->id, 325 (uint32_t) opc->id,
320 opc)); 326 opc));
321 if ((0 == GNUNET_CONTAINER_multihashmap32_size(c->opc_map)) && 327 if ((0 == GNUNET_CONTAINER_multihashmap32_size (c->opc_map)) &&
322 (NULL != c->opcq_empty_cb)) 328 (NULL != c->opcq_empty_cb))
323 c->opcq_empty_cb(c->opcq_empty_cls); 329 c->opcq_empty_cb (c->opcq_empty_cls);
324} 330}
325 331
326 332
@@ -332,22 +338,22 @@ GNUNET_TESTBED_remove_opc_(const struct GNUNET_TESTBED_Controller *c,
332 * @return #GNUNET_OK if message is well-formed 338 * @return #GNUNET_OK if message is well-formed
333 */ 339 */
334static int 340static int
335check_add_host_confirm(void *cls, 341check_add_host_confirm (void *cls,
336 const struct GNUNET_TESTBED_HostConfirmedMessage *msg) 342 const struct GNUNET_TESTBED_HostConfirmedMessage *msg)
337{ 343{
338 const char *emsg; 344 const char *emsg;
339 uint16_t msg_size; 345 uint16_t msg_size;
340 346
341 msg_size = ntohs(msg->header.size) - sizeof(*msg); 347 msg_size = ntohs (msg->header.size) - sizeof(*msg);
342 if (0 == msg_size) 348 if (0 == msg_size)
343 return GNUNET_OK; 349 return GNUNET_OK;
344 /* We have an error message */ 350 /* We have an error message */
345 emsg = (const char *)&msg[1]; 351 emsg = (const char *) &msg[1];
346 if ('\0' != emsg[msg_size - 1]) 352 if ('\0' != emsg[msg_size - 1])
347 { 353 {
348 GNUNET_break(0); 354 GNUNET_break (0);
349 return GNUNET_SYSERR; 355 return GNUNET_SYSERR;
350 } 356 }
351 return GNUNET_OK; 357 return GNUNET_OK;
352} 358}
353 359
@@ -360,8 +366,8 @@ check_add_host_confirm(void *cls,
360 * @param msg message received 366 * @param msg message received
361 */ 367 */
362static void 368static void
363handle_add_host_confirm(void *cls, 369handle_add_host_confirm (void *cls,
364 const struct GNUNET_TESTBED_HostConfirmedMessage *msg) 370 const struct GNUNET_TESTBED_HostConfirmedMessage *msg)
365{ 371{
366 struct GNUNET_TESTBED_Controller *c = cls; 372 struct GNUNET_TESTBED_Controller *c = cls;
367 struct GNUNET_TESTBED_HostRegistrationHandle *rh = c->rh; 373 struct GNUNET_TESTBED_HostRegistrationHandle *rh = c->rh;
@@ -370,31 +376,31 @@ handle_add_host_confirm(void *cls,
370 376
371 if (NULL == rh) 377 if (NULL == rh)
372 return; 378 return;
373 if (GNUNET_TESTBED_host_get_id_(rh->host) != ntohl(msg->host_id)) 379 if (GNUNET_TESTBED_host_get_id_ (rh->host) != ntohl (msg->host_id))
374 { 380 {
375 LOG_DEBUG("Mismatch in host id's %u, %u of host confirm msg\n", 381 LOG_DEBUG ("Mismatch in host id's %u, %u of host confirm msg\n",
376 GNUNET_TESTBED_host_get_id_(rh->host), 382 GNUNET_TESTBED_host_get_id_ (rh->host),
377 ntohl(msg->host_id)); 383 ntohl (msg->host_id));
378 return; 384 return;
379 } 385 }
380 c->rh = NULL; 386 c->rh = NULL;
381 msg_size = ntohs(msg->header.size) - sizeof(*msg); 387 msg_size = ntohs (msg->header.size) - sizeof(*msg);
382 if (0 == msg_size) 388 if (0 == msg_size)
383 { 389 {
384 LOG_DEBUG("Host %u successfully registered\n", ntohl(msg->host_id)); 390 LOG_DEBUG ("Host %u successfully registered\n", ntohl (msg->host_id));
385 GNUNET_TESTBED_mark_host_registered_at_(rh->host, c); 391 GNUNET_TESTBED_mark_host_registered_at_ (rh->host, c);
386 rh->cc(rh->cc_cls, NULL); 392 rh->cc (rh->cc_cls, NULL);
387 GNUNET_free(rh); 393 GNUNET_free (rh);
388 return; 394 return;
389 } 395 }
390 /* We have an error message */ 396 /* We have an error message */
391 emsg = (const char *)&msg[1]; 397 emsg = (const char *) &msg[1];
392 LOG(GNUNET_ERROR_TYPE_ERROR, 398 LOG (GNUNET_ERROR_TYPE_ERROR,
393 _("Adding host %u failed with error: %s\n"), 399 _ ("Adding host %u failed with error: %s\n"),
394 ntohl(msg->host_id), 400 ntohl (msg->host_id),
395 emsg); 401 emsg);
396 rh->cc(rh->cc_cls, emsg); 402 rh->cc (rh->cc_cls, emsg);
397 GNUNET_free(rh); 403 GNUNET_free (rh);
398} 404}
399 405
400 406
@@ -406,19 +412,19 @@ handle_add_host_confirm(void *cls,
406 * @param msg the message 412 * @param msg the message
407 */ 413 */
408static void 414static void
409handle_forwarded_operation_msg(void *cls, 415handle_forwarded_operation_msg (void *cls,
410 struct OperationContext *opc, 416 struct OperationContext *opc,
411 const struct GNUNET_MessageHeader *msg) 417 const struct GNUNET_MessageHeader *msg)
412{ 418{
413 struct GNUNET_TESTBED_Controller *c = cls; 419 struct GNUNET_TESTBED_Controller *c = cls;
414 struct ForwardedOperationData *fo_data; 420 struct ForwardedOperationData *fo_data;
415 421
416 fo_data = opc->data; 422 fo_data = opc->data;
417 if (NULL != fo_data->cc) 423 if (NULL != fo_data->cc)
418 fo_data->cc(fo_data->cc_cls, msg); 424 fo_data->cc (fo_data->cc_cls, msg);
419 GNUNET_TESTBED_remove_opc_(c, opc); 425 GNUNET_TESTBED_remove_opc_ (c, opc);
420 GNUNET_free(fo_data); 426 GNUNET_free (fo_data);
421 GNUNET_free(opc); 427 GNUNET_free (opc);
422} 428}
423 429
424 430
@@ -430,7 +436,7 @@ handle_forwarded_operation_msg(void *cls,
430 * @param msg message received 436 * @param msg message received
431 */ 437 */
432static void 438static void
433handle_opsuccess( 439handle_opsuccess (
434 void *cls, 440 void *cls,
435 const struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg) 441 const struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg)
436{ 442{
@@ -441,13 +447,13 @@ handle_opsuccess(
441 struct GNUNET_TESTBED_EventInformation event; 447 struct GNUNET_TESTBED_EventInformation event;
442 uint64_t op_id; 448 uint64_t op_id;
443 449
444 op_id = GNUNET_ntohll(msg->operation_id); 450 op_id = GNUNET_ntohll (msg->operation_id);
445 LOG_DEBUG("Operation %lu successful\n", op_id); 451 LOG_DEBUG ("Operation %lu successful\n", op_id);
446 if (NULL == (opc = find_opc(c, op_id))) 452 if (NULL == (opc = find_opc (c, op_id)))
447 { 453 {
448 LOG_DEBUG("Operation not found\n"); 454 LOG_DEBUG ("Operation not found\n");
449 return; 455 return;
450 } 456 }
451 event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; 457 event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED;
452 event.op = opc->op; 458 event.op = opc->op;
453 event.op_cls = opc->op_cls; 459 event.op_cls = opc->op_cls;
@@ -456,71 +462,72 @@ handle_opsuccess(
456 op_comp_cb = NULL; 462 op_comp_cb = NULL;
457 op_comp_cb_cls = NULL; 463 op_comp_cb_cls = NULL;
458 switch (opc->type) 464 switch (opc->type)
459 { 465 {
460 case OP_FORWARDED: { 466 case OP_FORWARDED: {
461 handle_forwarded_operation_msg(c, 467 handle_forwarded_operation_msg (c,
462 opc, 468 opc,
463 (const struct GNUNET_MessageHeader *)msg); 469 (const struct
470 GNUNET_MessageHeader *) msg);
464 return; 471 return;
465 } 472 }
466 break; 473 break;
467 474
468 case OP_PEER_DESTROY: { 475 case OP_PEER_DESTROY: {
469 struct GNUNET_TESTBED_Peer *peer; 476 struct GNUNET_TESTBED_Peer *peer;
470 477
471 peer = opc->data; 478 peer = opc->data;
472 GNUNET_TESTBED_peer_deregister_(peer); 479 GNUNET_TESTBED_peer_deregister_ (peer);
473 GNUNET_free(peer); 480 GNUNET_free (peer);
474 opc->data = NULL; 481 opc->data = NULL;
475 //PEERDESTROYDATA 482 // PEERDESTROYDATA
476 } 483 }
477 break; 484 break;
478 485
479 case OP_SHUTDOWN_PEERS: { 486 case OP_SHUTDOWN_PEERS: {
480 struct ShutdownPeersData *data; 487 struct ShutdownPeersData *data;
481 488
482 data = opc->data; 489 data = opc->data;
483 op_comp_cb = data->cb; 490 op_comp_cb = data->cb;
484 op_comp_cb_cls = data->cb_cls; 491 op_comp_cb_cls = data->cb_cls;
485 GNUNET_free(data); 492 GNUNET_free (data);
486 opc->data = NULL; 493 opc->data = NULL;
487 GNUNET_TESTBED_cleanup_peers_(); 494 GNUNET_TESTBED_cleanup_peers_ ();
488 } 495 }
489 break; 496 break;
490 497
491 case OP_MANAGE_SERVICE: { 498 case OP_MANAGE_SERVICE: {
492 struct ManageServiceData *data; 499 struct ManageServiceData *data;
493 500
494 GNUNET_assert(NULL != (data = opc->data)); 501 GNUNET_assert (NULL != (data = opc->data));
495 op_comp_cb = data->cb; 502 op_comp_cb = data->cb;
496 op_comp_cb_cls = data->cb_cls; 503 op_comp_cb_cls = data->cb_cls;
497 GNUNET_free(data); 504 GNUNET_free (data);
498 opc->data = NULL; 505 opc->data = NULL;
499 } 506 }
500 break; 507 break;
501 508
502 case OP_PEER_RECONFIGURE: 509 case OP_PEER_RECONFIGURE:
503 break; 510 break;
504 511
505 default: 512 default:
506 GNUNET_assert(0); 513 GNUNET_assert (0);
507 } 514 }
508 GNUNET_TESTBED_remove_opc_(opc->c, opc); 515 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
509 opc->state = OPC_STATE_FINISHED; 516 opc->state = OPC_STATE_FINISHED;
510 exop_insert(event.op); 517 exop_insert (event.op);
511 if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) 518 if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED)))
512 { 519 {
513 if (NULL != c->cc) 520 if (NULL != c->cc)
514 c->cc(c->cc_cls, &event); 521 c->cc (c->cc_cls, &event);
515 if (GNUNET_NO == exop_check(event.op)) 522 if (GNUNET_NO == exop_check (event.op))
516 return; 523 return;
517 } 524 }
518 else 525 else
519 LOG_DEBUG("Not calling callback\n"); 526 LOG_DEBUG ("Not calling callback\n");
520 if (NULL != op_comp_cb) 527 if (NULL != op_comp_cb)
521 op_comp_cb(op_comp_cb_cls, event.op, NULL); 528 op_comp_cb (op_comp_cb_cls, event.op, NULL);
522 /* You could have marked the operation as done by now */ 529 /* You could have marked the operation as done by now */
523 GNUNET_break(GNUNET_NO == exop_check(event.op)); 530 GNUNET_break (GNUNET_NO == exop_check (event.op));
524} 531}
525 532
526 533
@@ -532,7 +539,7 @@ handle_opsuccess(
532 * @param msg message received 539 * @param msg message received
533 */ 540 */
534static void 541static void
535handle_peer_create_success( 542handle_peer_create_success (
536 void *cls, 543 void *cls,
537 const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *msg) 544 const struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *msg)
538{ 545{
@@ -545,40 +552,40 @@ handle_peer_create_success(
545 void *cb_cls; 552 void *cb_cls;
546 uint64_t op_id; 553 uint64_t op_id;
547 554
548 GNUNET_assert(sizeof(struct GNUNET_TESTBED_PeerCreateSuccessEventMessage) == 555 GNUNET_assert (sizeof(struct GNUNET_TESTBED_PeerCreateSuccessEventMessage) ==
549 ntohs(msg->header.size)); 556 ntohs (msg->header.size));
550 op_id = GNUNET_ntohll(msg->operation_id); 557 op_id = GNUNET_ntohll (msg->operation_id);
551 if (NULL == (opc = find_opc(c, op_id))) 558 if (NULL == (opc = find_opc (c, op_id)))
552 { 559 {
553 LOG_DEBUG("Operation context for PeerCreateSuccessEvent not found\n"); 560 LOG_DEBUG ("Operation context for PeerCreateSuccessEvent not found\n");
554 return; 561 return;
555 } 562 }
556 if (OP_FORWARDED == opc->type) 563 if (OP_FORWARDED == opc->type)
557 { 564 {
558 handle_forwarded_operation_msg(c, 565 handle_forwarded_operation_msg (c,
559 opc, 566 opc,
560 (const struct GNUNET_MessageHeader *)msg); 567 (const struct GNUNET_MessageHeader *) msg);
561 return; 568 return;
562 } 569 }
563 GNUNET_assert(OP_PEER_CREATE == opc->type); 570 GNUNET_assert (OP_PEER_CREATE == opc->type);
564 GNUNET_assert(NULL != opc->data); 571 GNUNET_assert (NULL != opc->data);
565 data = opc->data; 572 data = opc->data;
566 GNUNET_assert(NULL != data->peer); 573 GNUNET_assert (NULL != data->peer);
567 peer = data->peer; 574 peer = data->peer;
568 GNUNET_assert(peer->unique_id == ntohl(msg->peer_id)); 575 GNUNET_assert (peer->unique_id == ntohl (msg->peer_id));
569 peer->state = TESTBED_PS_CREATED; 576 peer->state = TESTBED_PS_CREATED;
570 GNUNET_TESTBED_peer_register_(peer); 577 GNUNET_TESTBED_peer_register_ (peer);
571 cb = data->cb; 578 cb = data->cb;
572 cb_cls = data->cls; 579 cb_cls = data->cls;
573 op = opc->op; 580 op = opc->op;
574 GNUNET_free(opc->data); 581 GNUNET_free (opc->data);
575 GNUNET_TESTBED_remove_opc_(opc->c, opc); 582 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
576 opc->state = OPC_STATE_FINISHED; 583 opc->state = OPC_STATE_FINISHED;
577 exop_insert(op); 584 exop_insert (op);
578 if (NULL != cb) 585 if (NULL != cb)
579 cb(cb_cls, peer, NULL); 586 cb (cb_cls, peer, NULL);
580 /* You could have marked the operation as done by now */ 587 /* You could have marked the operation as done by now */
581 GNUNET_break(GNUNET_NO == exop_check(op)); 588 GNUNET_break (GNUNET_NO == exop_check (op));
582} 589}
583 590
584 591
@@ -590,7 +597,7 @@ handle_peer_create_success(
590 * @param msg message received 597 * @param msg message received
591 */ 598 */
592static void 599static void
593handle_peer_event(void *cls, const struct GNUNET_TESTBED_PeerEventMessage *msg) 600handle_peer_event (void *cls, const struct GNUNET_TESTBED_PeerEventMessage *msg)
594{ 601{
595 struct GNUNET_TESTBED_Controller *c = cls; 602 struct GNUNET_TESTBED_Controller *c = cls;
596 struct OperationContext *opc; 603 struct OperationContext *opc;
@@ -602,64 +609,64 @@ handle_peer_event(void *cls, const struct GNUNET_TESTBED_PeerEventMessage *msg)
602 uint64_t op_id; 609 uint64_t op_id;
603 uint64_t mask; 610 uint64_t mask;
604 611
605 GNUNET_assert(sizeof(struct GNUNET_TESTBED_PeerEventMessage) == 612 GNUNET_assert (sizeof(struct GNUNET_TESTBED_PeerEventMessage) ==
606 ntohs(msg->header.size)); 613 ntohs (msg->header.size));
607 op_id = GNUNET_ntohll(msg->operation_id); 614 op_id = GNUNET_ntohll (msg->operation_id);
608 if (NULL == (opc = find_opc(c, op_id))) 615 if (NULL == (opc = find_opc (c, op_id)))
609 { 616 {
610 LOG_DEBUG("Operation not found\n"); 617 LOG_DEBUG ("Operation not found\n");
611 return; 618 return;
612 } 619 }
613 if (OP_FORWARDED == opc->type) 620 if (OP_FORWARDED == opc->type)
614 { 621 {
615 handle_forwarded_operation_msg(c, 622 handle_forwarded_operation_msg (c,
616 opc, 623 opc,
617 (const struct GNUNET_MessageHeader *)msg); 624 (const struct GNUNET_MessageHeader *) msg);
618 return; 625 return;
619 } 626 }
620 GNUNET_assert((OP_PEER_START == opc->type) || (OP_PEER_STOP == opc->type)); 627 GNUNET_assert ((OP_PEER_START == opc->type) || (OP_PEER_STOP == opc->type));
621 data = opc->data; 628 data = opc->data;
622 GNUNET_assert(NULL != data); 629 GNUNET_assert (NULL != data);
623 peer = data->peer; 630 peer = data->peer;
624 GNUNET_assert(NULL != peer); 631 GNUNET_assert (NULL != peer);
625 event.type = (enum GNUNET_TESTBED_EventType)ntohl(msg->event_type); 632 event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type);
626 event.op = opc->op; 633 event.op = opc->op;
627 event.op_cls = opc->op_cls; 634 event.op_cls = opc->op_cls;
628 switch (event.type) 635 switch (event.type)
629 { 636 {
630 case GNUNET_TESTBED_ET_PEER_START: 637 case GNUNET_TESTBED_ET_PEER_START:
631 peer->state = TESTBED_PS_STARTED; 638 peer->state = TESTBED_PS_STARTED;
632 event.details.peer_start.host = peer->host; 639 event.details.peer_start.host = peer->host;
633 event.details.peer_start.peer = peer; 640 event.details.peer_start.peer = peer;
634 break; 641 break;
635 642
636 case GNUNET_TESTBED_ET_PEER_STOP: 643 case GNUNET_TESTBED_ET_PEER_STOP:
637 peer->state = TESTBED_PS_STOPPED; 644 peer->state = TESTBED_PS_STOPPED;
638 event.details.peer_stop.peer = peer; 645 event.details.peer_stop.peer = peer;
639 break; 646 break;
640 647
641 default: 648 default:
642 GNUNET_assert(0); /* We should never reach this state */ 649 GNUNET_assert (0); /* We should never reach this state */
643 } 650 }
644 pcc = data->pcc; 651 pcc = data->pcc;
645 pcc_cls = data->pcc_cls; 652 pcc_cls = data->pcc_cls;
646 GNUNET_free(data); 653 GNUNET_free (data);
647 GNUNET_TESTBED_remove_opc_(opc->c, opc); 654 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
648 opc->state = OPC_STATE_FINISHED; 655 opc->state = OPC_STATE_FINISHED;
649 exop_insert(event.op); 656 exop_insert (event.op);
650 mask = 1LL << GNUNET_TESTBED_ET_PEER_START; 657 mask = 1LL << GNUNET_TESTBED_ET_PEER_START;
651 mask |= 1LL << GNUNET_TESTBED_ET_PEER_STOP; 658 mask |= 1LL << GNUNET_TESTBED_ET_PEER_STOP;
652 if (0 != (mask & c->event_mask)) 659 if (0 != (mask & c->event_mask))
653 { 660 {
654 if (NULL != c->cc) 661 if (NULL != c->cc)
655 c->cc(c->cc_cls, &event); 662 c->cc (c->cc_cls, &event);
656 if (GNUNET_NO == exop_check(event.op)) 663 if (GNUNET_NO == exop_check (event.op))
657 return; 664 return;
658 } 665 }
659 if (NULL != pcc) 666 if (NULL != pcc)
660 pcc(pcc_cls, NULL); 667 pcc (pcc_cls, NULL);
661 /* You could have marked the operation as done by now */ 668 /* You could have marked the operation as done by now */
662 GNUNET_break(GNUNET_NO == exop_check(event.op)); 669 GNUNET_break (GNUNET_NO == exop_check (event.op));
663} 670}
664 671
665 672
@@ -671,8 +678,8 @@ handle_peer_event(void *cls, const struct GNUNET_TESTBED_PeerEventMessage *msg)
671 * @param msg message received 678 * @param msg message received
672 */ 679 */
673static void 680static void
674handle_peer_conevent(void *cls, 681handle_peer_conevent (void *cls,
675 const struct GNUNET_TESTBED_ConnectionEventMessage *msg) 682 const struct GNUNET_TESTBED_ConnectionEventMessage *msg)
676{ 683{
677 struct GNUNET_TESTBED_Controller *c = cls; 684 struct GNUNET_TESTBED_Controller *c = cls;
678 struct OperationContext *opc; 685 struct OperationContext *opc;
@@ -683,59 +690,59 @@ handle_peer_conevent(void *cls,
683 uint64_t op_id; 690 uint64_t op_id;
684 uint64_t mask; 691 uint64_t mask;
685 692
686 op_id = GNUNET_ntohll(msg->operation_id); 693 op_id = GNUNET_ntohll (msg->operation_id);
687 if (NULL == (opc = find_opc(c, op_id))) 694 if (NULL == (opc = find_opc (c, op_id)))
688 { 695 {
689 LOG_DEBUG("Operation not found\n"); 696 LOG_DEBUG ("Operation not found\n");
690 return; 697 return;
691 } 698 }
692 if (OP_FORWARDED == opc->type) 699 if (OP_FORWARDED == opc->type)
693 { 700 {
694 handle_forwarded_operation_msg(c, 701 handle_forwarded_operation_msg (c,
695 opc, 702 opc,
696 (const struct GNUNET_MessageHeader *)msg); 703 (const struct GNUNET_MessageHeader *) msg);
697 return; 704 return;
698 } 705 }
699 GNUNET_assert(OP_OVERLAY_CONNECT == opc->type); 706 GNUNET_assert (OP_OVERLAY_CONNECT == opc->type);
700 GNUNET_assert(NULL != (data = opc->data)); 707 GNUNET_assert (NULL != (data = opc->data));
701 GNUNET_assert((ntohl(msg->peer1) == data->p1->unique_id) && 708 GNUNET_assert ((ntohl (msg->peer1) == data->p1->unique_id) &&
702 (ntohl(msg->peer2) == data->p2->unique_id)); 709 (ntohl (msg->peer2) == data->p2->unique_id));
703 event.type = (enum GNUNET_TESTBED_EventType)ntohl(msg->event_type); 710 event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type);
704 event.op = opc->op; 711 event.op = opc->op;
705 event.op_cls = opc->op_cls; 712 event.op_cls = opc->op_cls;
706 switch (event.type) 713 switch (event.type)
707 { 714 {
708 case GNUNET_TESTBED_ET_CONNECT: 715 case GNUNET_TESTBED_ET_CONNECT:
709 event.details.peer_connect.peer1 = data->p1; 716 event.details.peer_connect.peer1 = data->p1;
710 event.details.peer_connect.peer2 = data->p2; 717 event.details.peer_connect.peer2 = data->p2;
711 break; 718 break;
712 719
713 case GNUNET_TESTBED_ET_DISCONNECT: 720 case GNUNET_TESTBED_ET_DISCONNECT:
714 GNUNET_assert(0); /* FIXME: implement */ 721 GNUNET_assert (0); /* FIXME: implement */
715 break; 722 break;
716 723
717 default: 724 default:
718 GNUNET_assert(0); /* Should never reach here */ 725 GNUNET_assert (0); /* Should never reach here */
719 break; 726 break;
720 } 727 }
721 cb = data->cb; 728 cb = data->cb;
722 cb_cls = data->cb_cls; 729 cb_cls = data->cb_cls;
723 GNUNET_TESTBED_remove_opc_(opc->c, opc); 730 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
724 opc->state = OPC_STATE_FINISHED; 731 opc->state = OPC_STATE_FINISHED;
725 exop_insert(event.op); 732 exop_insert (event.op);
726 mask = 1LL << GNUNET_TESTBED_ET_CONNECT; 733 mask = 1LL << GNUNET_TESTBED_ET_CONNECT;
727 mask |= 1LL << GNUNET_TESTBED_ET_DISCONNECT; 734 mask |= 1LL << GNUNET_TESTBED_ET_DISCONNECT;
728 if (0 != (mask & c->event_mask)) 735 if (0 != (mask & c->event_mask))
729 { 736 {
730 if (NULL != c->cc) 737 if (NULL != c->cc)
731 c->cc(c->cc_cls, &event); 738 c->cc (c->cc_cls, &event);
732 if (GNUNET_NO == exop_check(event.op)) 739 if (GNUNET_NO == exop_check (event.op))
733 return; 740 return;
734 } 741 }
735 if (NULL != cb) 742 if (NULL != cb)
736 cb(cb_cls, opc->op, NULL); 743 cb (cb_cls, opc->op, NULL);
737 /* You could have marked the operation as done by now */ 744 /* You could have marked the operation as done by now */
738 GNUNET_break(GNUNET_NO == exop_check(event.op)); 745 GNUNET_break (GNUNET_NO == exop_check (event.op));
739} 746}
740 747
741 748
@@ -747,7 +754,7 @@ handle_peer_conevent(void *cls,
747 * @param msg message received 754 * @param msg message received
748 */ 755 */
749static int 756static int
750check_peer_config( 757check_peer_config (
751 void *cls, 758 void *cls,
752 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg) 759 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg)
753{ 760{
@@ -764,7 +771,7 @@ check_peer_config(
764 * @param msg message received 771 * @param msg message received
765 */ 772 */
766static void 773static void
767handle_peer_config( 774handle_peer_config (
768 void *cls, 775 void *cls,
769 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg) 776 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg)
770{ 777{
@@ -777,51 +784,51 @@ handle_peer_config(
777 void *cb_cls; 784 void *cb_cls;
778 uint64_t op_id; 785 uint64_t op_id;
779 786
780 op_id = GNUNET_ntohll(msg->operation_id); 787 op_id = GNUNET_ntohll (msg->operation_id);
781 if (NULL == (opc = find_opc(c, op_id))) 788 if (NULL == (opc = find_opc (c, op_id)))
782 { 789 {
783 LOG_DEBUG("Operation not found\n"); 790 LOG_DEBUG ("Operation not found\n");
784 return; 791 return;
785 } 792 }
786 if (OP_FORWARDED == opc->type) 793 if (OP_FORWARDED == opc->type)
787 { 794 {
788 handle_forwarded_operation_msg(c, opc, &msg->header); 795 handle_forwarded_operation_msg (c, opc, &msg->header);
789 return; 796 return;
790 } 797 }
791 data = opc->data; 798 data = opc->data;
792 GNUNET_assert(NULL != data); 799 GNUNET_assert (NULL != data);
793 peer = data->peer; 800 peer = data->peer;
794 GNUNET_assert(NULL != peer); 801 GNUNET_assert (NULL != peer);
795 GNUNET_assert(ntohl(msg->peer_id) == peer->unique_id); 802 GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id);
796 pinfo = GNUNET_new(struct GNUNET_TESTBED_PeerInformation); 803 pinfo = GNUNET_new (struct GNUNET_TESTBED_PeerInformation);
797 pinfo->pit = data->pit; 804 pinfo->pit = data->pit;
798 cb = data->cb; 805 cb = data->cb;
799 cb_cls = data->cb_cls; 806 cb_cls = data->cb_cls;
800 GNUNET_assert(NULL != cb); 807 GNUNET_assert (NULL != cb);
801 GNUNET_free(data); 808 GNUNET_free (data);
802 opc->data = NULL; 809 opc->data = NULL;
803 switch (pinfo->pit) 810 switch (pinfo->pit)
804 { 811 {
805 case GNUNET_TESTBED_PIT_IDENTITY: 812 case GNUNET_TESTBED_PIT_IDENTITY:
806 pinfo->result.id = GNUNET_new(struct GNUNET_PeerIdentity); 813 pinfo->result.id = GNUNET_new (struct GNUNET_PeerIdentity);
807 GNUNET_memcpy(pinfo->result.id, 814 GNUNET_memcpy (pinfo->result.id,
808 &msg->peer_identity, 815 &msg->peer_identity,
809 sizeof(struct GNUNET_PeerIdentity)); 816 sizeof(struct GNUNET_PeerIdentity));
810 break; 817 break;
811 818
812 case GNUNET_TESTBED_PIT_CONFIGURATION: 819 case GNUNET_TESTBED_PIT_CONFIGURATION:
813 pinfo->result.cfg = /* Freed in oprelease_peer_getinfo */ 820 pinfo->result.cfg = /* Freed in oprelease_peer_getinfo */
814 GNUNET_TESTBED_extract_config_(&msg->header); 821 GNUNET_TESTBED_extract_config_ (&msg->header);
815 break; 822 break;
816 823
817 case GNUNET_TESTBED_PIT_GENERIC: 824 case GNUNET_TESTBED_PIT_GENERIC:
818 GNUNET_assert(0); /* never reach here */ 825 GNUNET_assert (0); /* never reach here */
819 break; 826 break;
820 } 827 }
821 opc->data = pinfo; 828 opc->data = pinfo;
822 GNUNET_TESTBED_remove_opc_(opc->c, opc); 829 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
823 opc->state = OPC_STATE_FINISHED; 830 opc->state = OPC_STATE_FINISHED;
824 cb(cb_cls, opc->op, pinfo, NULL); 831 cb (cb_cls, opc->op, pinfo, NULL);
825 /* We dont check whether the operation is marked as done here as the 832 /* We dont check whether the operation is marked as done here as the
826 operation contains data (cfg/identify) which will be freed at a later point 833 operation contains data (cfg/identify) which will be freed at a later point
827 */ 834 */
@@ -837,7 +844,7 @@ handle_peer_config(
837 * @return #GNUNET_OK if message is well-formed 844 * @return #GNUNET_OK if message is well-formed
838 */ 845 */
839static int 846static int
840check_op_fail_event( 847check_op_fail_event (
841 void *cls, 848 void *cls,
842 const struct GNUNET_TESTBED_OperationFailureEventMessage *msg) 849 const struct GNUNET_TESTBED_OperationFailureEventMessage *msg)
843{ 850{
@@ -854,7 +861,7 @@ check_op_fail_event(
854 * @param msg message received 861 * @param msg message received
855 */ 862 */
856static void 863static void
857handle_op_fail_event( 864handle_op_fail_event (
858 void *cls, 865 void *cls,
859 const struct GNUNET_TESTBED_OperationFailureEventMessage *msg) 866 const struct GNUNET_TESTBED_OperationFailureEventMessage *msg)
860{ 867{
@@ -865,34 +872,34 @@ handle_op_fail_event(
865 uint64_t mask; 872 uint64_t mask;
866 struct GNUNET_TESTBED_EventInformation event; 873 struct GNUNET_TESTBED_EventInformation event;
867 874
868 op_id = GNUNET_ntohll(msg->operation_id); 875 op_id = GNUNET_ntohll (msg->operation_id);
869 if (NULL == (opc = find_opc(c, op_id))) 876 if (NULL == (opc = find_opc (c, op_id)))
870 { 877 {
871 LOG_DEBUG("Operation not found\n"); 878 LOG_DEBUG ("Operation not found\n");
872 return; 879 return;
873 } 880 }
874 if (OP_FORWARDED == opc->type) 881 if (OP_FORWARDED == opc->type)
875 { 882 {
876 handle_forwarded_operation_msg(c, 883 handle_forwarded_operation_msg (c,
877 opc, 884 opc,
878 (const struct GNUNET_MessageHeader *)msg); 885 (const struct GNUNET_MessageHeader *) msg);
879 return; 886 return;
880 } 887 }
881 GNUNET_TESTBED_remove_opc_(opc->c, opc); 888 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
882 opc->state = OPC_STATE_FINISHED; 889 opc->state = OPC_STATE_FINISHED;
883 emsg = GNUNET_TESTBED_parse_error_string_(msg); 890 emsg = GNUNET_TESTBED_parse_error_string_ (msg);
884 if (NULL == emsg) 891 if (NULL == emsg)
885 emsg = "Unknown error"; 892 emsg = "Unknown error";
886 if (OP_PEER_INFO == opc->type) 893 if (OP_PEER_INFO == opc->type)
887 { 894 {
888 struct PeerInfoData *data; 895 struct PeerInfoData *data;
889 896
890 data = opc->data; 897 data = opc->data;
891 if (NULL != data->cb) 898 if (NULL != data->cb)
892 data->cb(data->cb_cls, opc->op, NULL, emsg); 899 data->cb (data->cb_cls, opc->op, NULL, emsg);
893 GNUNET_free(data); 900 GNUNET_free (data);
894 return; /* We do not call controller callback for peer info */ 901 return; /* We do not call controller callback for peer info */
895 } 902 }
896 event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; 903 event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED;
897 event.op = opc->op; 904 event.op = opc->op;
898 event.op_cls = opc->op_cls; 905 event.op_cls = opc->op_cls;
@@ -900,88 +907,88 @@ handle_op_fail_event(
900 event.details.operation_finished.generic = NULL; 907 event.details.operation_finished.generic = NULL;
901 mask = (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); 908 mask = (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
902 if ((0 != (mask & c->event_mask)) && (NULL != c->cc)) 909 if ((0 != (mask & c->event_mask)) && (NULL != c->cc))
903 { 910 {
904 exop_insert(event.op); 911 exop_insert (event.op);
905 c->cc(c->cc_cls, &event); 912 c->cc (c->cc_cls, &event);
906 if (GNUNET_NO == exop_check(event.op)) 913 if (GNUNET_NO == exop_check (event.op))
907 return; 914 return;
908 } 915 }
909 switch (opc->type) 916 switch (opc->type)
910 { 917 {
911 case OP_PEER_CREATE: { 918 case OP_PEER_CREATE: {
912 struct PeerCreateData *data; 919 struct PeerCreateData *data;
913 920
914 data = opc->data; 921 data = opc->data;
915 GNUNET_free(data->peer); 922 GNUNET_free (data->peer);
916 if (NULL != data->cb) 923 if (NULL != data->cb)
917 data->cb(data->cls, NULL, emsg); 924 data->cb (data->cls, NULL, emsg);
918 GNUNET_free(data); 925 GNUNET_free (data);
919 } 926 }
920 break; 927 break;
921 928
922 case OP_PEER_START: 929 case OP_PEER_START:
923 case OP_PEER_STOP: { 930 case OP_PEER_STOP: {
924 struct PeerEventData *data; 931 struct PeerEventData *data;
925 932
926 data = opc->data; 933 data = opc->data;
927 if (NULL != data->pcc) 934 if (NULL != data->pcc)
928 data->pcc(data->pcc_cls, emsg); 935 data->pcc (data->pcc_cls, emsg);
929 GNUNET_free(data); 936 GNUNET_free (data);
930 } 937 }
931 break; 938 break;
932 939
933 case OP_PEER_DESTROY: 940 case OP_PEER_DESTROY:
934 break; 941 break;
935 942
936 case OP_PEER_INFO: 943 case OP_PEER_INFO:
937 GNUNET_assert(0); 944 GNUNET_assert (0);
938 945
939 case OP_OVERLAY_CONNECT: { 946 case OP_OVERLAY_CONNECT: {
940 struct OverlayConnectData *data; 947 struct OverlayConnectData *data;
941 948
942 data = opc->data; 949 data = opc->data;
943 GNUNET_TESTBED_operation_mark_failed(opc->op); 950 GNUNET_TESTBED_operation_mark_failed (opc->op);
944 if (NULL != data->cb) 951 if (NULL != data->cb)
945 data->cb(data->cb_cls, opc->op, emsg); 952 data->cb (data->cb_cls, opc->op, emsg);
946 } 953 }
947 break; 954 break;
948 955
949 case OP_FORWARDED: 956 case OP_FORWARDED:
950 GNUNET_assert(0); 957 GNUNET_assert (0);
951 958
952 case OP_LINK_CONTROLLERS: /* No secondary callback */ 959 case OP_LINK_CONTROLLERS: /* No secondary callback */
953 break; 960 break;
954 961
955 case OP_SHUTDOWN_PEERS: { 962 case OP_SHUTDOWN_PEERS: {
956 struct ShutdownPeersData *data; 963 struct ShutdownPeersData *data;
957 964
958 data = opc->data; 965 data = opc->data;
959 GNUNET_free(data); /* FIXME: Decide whether we call data->op_cb */ 966 GNUNET_free (data); /* FIXME: Decide whether we call data->op_cb */
960 opc->data = NULL; 967 opc->data = NULL;
961 } 968 }
962 break; 969 break;
963 970
964 case OP_MANAGE_SERVICE: { 971 case OP_MANAGE_SERVICE: {
965 struct ManageServiceData *data = opc->data; 972 struct ManageServiceData *data = opc->data;
966 GNUNET_TESTBED_OperationCompletionCallback cb; 973 GNUNET_TESTBED_OperationCompletionCallback cb;
967 void *cb_cls; 974 void *cb_cls;
968 975
969 GNUNET_assert(NULL != data); 976 GNUNET_assert (NULL != data);
970 cb = data->cb; 977 cb = data->cb;
971 cb_cls = data->cb_cls; 978 cb_cls = data->cb_cls;
972 GNUNET_free(data); 979 GNUNET_free (data);
973 opc->data = NULL; 980 opc->data = NULL;
974 exop_insert(event.op); 981 exop_insert (event.op);
975 if (NULL != cb) 982 if (NULL != cb)
976 cb(cb_cls, opc->op, emsg); 983 cb (cb_cls, opc->op, emsg);
977 /* You could have marked the operation as done by now */ 984 /* You could have marked the operation as done by now */
978 GNUNET_break(GNUNET_NO == exop_check(event.op)); 985 GNUNET_break (GNUNET_NO == exop_check (event.op));
979 } 986 }
980 break; 987 break;
981 988
982 default: 989 default:
983 GNUNET_break(0); 990 GNUNET_break (0);
984 } 991 }
985} 992}
986 993
987 994
@@ -993,18 +1000,18 @@ handle_op_fail_event(
993 * @return newly allocated SlaveGetConfigurationMessage 1000 * @return newly allocated SlaveGetConfigurationMessage
994 */ 1001 */
995static struct GNUNET_TESTBED_SlaveGetConfigurationMessage * 1002static struct GNUNET_TESTBED_SlaveGetConfigurationMessage *
996GNUNET_TESTBED_generate_slavegetconfig_msg_(uint64_t op_id, uint32_t slave_id) 1003GNUNET_TESTBED_generate_slavegetconfig_msg_ (uint64_t op_id, uint32_t slave_id)
997{ 1004{
998 struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg; 1005 struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
999 uint16_t msize; 1006 uint16_t msize;
1000 1007
1001 msize = sizeof(struct GNUNET_TESTBED_SlaveGetConfigurationMessage); 1008 msize = sizeof(struct GNUNET_TESTBED_SlaveGetConfigurationMessage);
1002 msg = GNUNET_malloc(msize); 1009 msg = GNUNET_malloc (msize);
1003 msg->header.size = htons(msize); 1010 msg->header.size = htons (msize);
1004 msg->header.type = 1011 msg->header.type =
1005 htons(GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION); 1012 htons (GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION);
1006 msg->operation_id = GNUNET_htonll(op_id); 1013 msg->operation_id = GNUNET_htonll (op_id);
1007 msg->slave_id = htonl(slave_id); 1014 msg->slave_id = htonl (slave_id);
1008 return msg; 1015 return msg;
1009} 1016}
1010 1017
@@ -1017,8 +1024,8 @@ GNUNET_TESTBED_generate_slavegetconfig_msg_(uint64_t op_id, uint32_t slave_id)
1017 * @param msg message received 1024 * @param msg message received
1018 */ 1025 */
1019static int 1026static int
1020check_slave_config(void *cls, 1027check_slave_config (void *cls,
1021 const struct GNUNET_TESTBED_SlaveConfiguration *msg) 1028 const struct GNUNET_TESTBED_SlaveConfiguration *msg)
1022{ 1029{
1023 /* anything goes? */ 1030 /* anything goes? */
1024 return GNUNET_OK; 1031 return GNUNET_OK;
@@ -1033,8 +1040,8 @@ check_slave_config(void *cls,
1033 * @param msg message received 1040 * @param msg message received
1034 */ 1041 */
1035static void 1042static void
1036handle_slave_config(void *cls, 1043handle_slave_config (void *cls,
1037 const struct GNUNET_TESTBED_SlaveConfiguration *msg) 1044 const struct GNUNET_TESTBED_SlaveConfiguration *msg)
1038{ 1045{
1039 struct GNUNET_TESTBED_Controller *c = cls; 1046 struct GNUNET_TESTBED_Controller *c = cls;
1040 struct OperationContext *opc; 1047 struct OperationContext *opc;
@@ -1042,30 +1049,30 @@ handle_slave_config(void *cls,
1042 uint64_t mask; 1049 uint64_t mask;
1043 struct GNUNET_TESTBED_EventInformation event; 1050 struct GNUNET_TESTBED_EventInformation event;
1044 1051
1045 op_id = GNUNET_ntohll(msg->operation_id); 1052 op_id = GNUNET_ntohll (msg->operation_id);
1046 if (NULL == (opc = find_opc(c, op_id))) 1053 if (NULL == (opc = find_opc (c, op_id)))
1047 { 1054 {
1048 LOG_DEBUG("Operation not found\n"); 1055 LOG_DEBUG ("Operation not found\n");
1049 return; 1056 return;
1050 } 1057 }
1051 if (OP_GET_SLAVE_CONFIG != opc->type) 1058 if (OP_GET_SLAVE_CONFIG != opc->type)
1052 { 1059 {
1053 GNUNET_break(0); 1060 GNUNET_break (0);
1054 return; 1061 return;
1055 } 1062 }
1056 opc->state = OPC_STATE_FINISHED; 1063 opc->state = OPC_STATE_FINISHED;
1057 GNUNET_TESTBED_remove_opc_(opc->c, opc); 1064 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
1058 mask = 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED; 1065 mask = 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED;
1059 if ((0 != (mask & c->event_mask)) && (NULL != c->cc)) 1066 if ((0 != (mask & c->event_mask)) && (NULL != c->cc))
1060 { 1067 {
1061 opc->data = GNUNET_TESTBED_extract_config_(&msg->header); 1068 opc->data = GNUNET_TESTBED_extract_config_ (&msg->header);
1062 event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; 1069 event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED;
1063 event.op = opc->op; 1070 event.op = opc->op;
1064 event.op_cls = opc->op_cls; 1071 event.op_cls = opc->op_cls;
1065 event.details.operation_finished.generic = opc->data; 1072 event.details.operation_finished.generic = opc->data;
1066 event.details.operation_finished.emsg = NULL; 1073 event.details.operation_finished.emsg = NULL;
1067 c->cc(c->cc_cls, &event); 1074 c->cc (c->cc_cls, &event);
1068 } 1075 }
1069} 1076}
1070 1077
1071 1078
@@ -1078,7 +1085,7 @@ handle_slave_config(void *cls,
1078 * @return #GNUNET_OK if @a msg is well-formed 1085 * @return #GNUNET_OK if @a msg is well-formed
1079 */ 1086 */
1080static int 1087static int
1081check_link_controllers_result( 1088check_link_controllers_result (
1082 void *cls, 1089 void *cls,
1083 const struct GNUNET_TESTBED_ControllerLinkResponse *msg) 1090 const struct GNUNET_TESTBED_ControllerLinkResponse *msg)
1084{ 1091{
@@ -1095,7 +1102,7 @@ check_link_controllers_result(
1095 * @param msg message received 1102 * @param msg message received
1096 */ 1103 */
1097static void 1104static void
1098handle_link_controllers_result( 1105handle_link_controllers_result (
1099 void *cls, 1106 void *cls,
1100 const struct GNUNET_TESTBED_ControllerLinkResponse *msg) 1107 const struct GNUNET_TESTBED_ControllerLinkResponse *msg)
1101{ 1108{
@@ -1108,31 +1115,31 @@ handle_link_controllers_result(
1108 uint64_t op_id; 1115 uint64_t op_id;
1109 struct GNUNET_TESTBED_EventInformation event; 1116 struct GNUNET_TESTBED_EventInformation event;
1110 1117
1111 op_id = GNUNET_ntohll(msg->operation_id); 1118 op_id = GNUNET_ntohll (msg->operation_id);
1112 if (NULL == (opc = find_opc(c, op_id))) 1119 if (NULL == (opc = find_opc (c, op_id)))
1113 { 1120 {
1114 LOG_DEBUG("Operation not found\n"); 1121 LOG_DEBUG ("Operation not found\n");
1115 return; 1122 return;
1116 } 1123 }
1117 if (OP_FORWARDED == opc->type) 1124 if (OP_FORWARDED == opc->type)
1118 { 1125 {
1119 handle_forwarded_operation_msg(c, 1126 handle_forwarded_operation_msg (c,
1120 opc, 1127 opc,
1121 (const struct GNUNET_MessageHeader *)msg); 1128 (const struct GNUNET_MessageHeader *) msg);
1122 return; 1129 return;
1123 } 1130 }
1124 if (OP_LINK_CONTROLLERS != opc->type) 1131 if (OP_LINK_CONTROLLERS != opc->type)
1125 { 1132 {
1126 GNUNET_break(0); 1133 GNUNET_break (0);
1127 return; 1134 return;
1128 } 1135 }
1129 GNUNET_assert(NULL != (data = opc->data)); 1136 GNUNET_assert (NULL != (data = opc->data));
1130 host = GNUNET_TESTBED_host_lookup_by_id_(data->host_id); 1137 host = GNUNET_TESTBED_host_lookup_by_id_ (data->host_id);
1131 GNUNET_assert(NULL != host); 1138 GNUNET_assert (NULL != host);
1132 GNUNET_free(data); 1139 GNUNET_free (data);
1133 opc->data = NULL; 1140 opc->data = NULL;
1134 opc->state = OPC_STATE_FINISHED; 1141 opc->state = OPC_STATE_FINISHED;
1135 GNUNET_TESTBED_remove_opc_(opc->c, opc); 1142 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
1136 event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; 1143 event.type = GNUNET_TESTBED_ET_OPERATION_FINISHED;
1137 event.op = opc->op; 1144 event.op = opc->op;
1138 event.op_cls = opc->op_cls; 1145 event.op_cls = opc->op_cls;
@@ -1140,37 +1147,38 @@ handle_link_controllers_result(
1140 event.details.operation_finished.generic = NULL; 1147 event.details.operation_finished.generic = NULL;
1141 emsg = NULL; 1148 emsg = NULL;
1142 cfg = NULL; 1149 cfg = NULL;
1143 if (GNUNET_NO == ntohs(msg->success)) 1150 if (GNUNET_NO == ntohs (msg->success))
1144 { 1151 {
1145 emsg = 1152 emsg =
1146 GNUNET_malloc(ntohs(msg->header.size) - 1153 GNUNET_malloc (ntohs (msg->header.size)
1147 sizeof(struct GNUNET_TESTBED_ControllerLinkResponse) + 1); 1154 - sizeof(struct GNUNET_TESTBED_ControllerLinkResponse)
1148 GNUNET_memcpy(emsg, 1155 + 1);
1149 &msg[1], 1156 GNUNET_memcpy (emsg,
1150 ntohs(msg->header.size) - 1157 &msg[1],
1151 sizeof(struct GNUNET_TESTBED_ControllerLinkResponse)); 1158 ntohs (msg->header.size)
1152 event.details.operation_finished.emsg = emsg; 1159 - sizeof(struct GNUNET_TESTBED_ControllerLinkResponse));
1153 } 1160 event.details.operation_finished.emsg = emsg;
1161 }
1154 else 1162 else
1163 {
1164 if (0 != ntohs (msg->config_size))
1155 { 1165 {
1156 if (0 != ntohs(msg->config_size)) 1166 cfg = GNUNET_TESTBED_extract_config_ (
1157 { 1167 (const struct GNUNET_MessageHeader *) msg);
1158 cfg = GNUNET_TESTBED_extract_config_( 1168 GNUNET_assert (NULL != cfg);
1159 (const struct GNUNET_MessageHeader *)msg); 1169 GNUNET_TESTBED_host_replace_cfg_ (host, cfg);
1160 GNUNET_assert(NULL != cfg);
1161 GNUNET_TESTBED_host_replace_cfg_(host, cfg);
1162 }
1163 } 1170 }
1171 }
1164 if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) 1172 if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED)))
1165 { 1173 {
1166 if (NULL != c->cc) 1174 if (NULL != c->cc)
1167 c->cc(c->cc_cls, &event); 1175 c->cc (c->cc_cls, &event);
1168 } 1176 }
1169 else 1177 else
1170 LOG_DEBUG("Not calling callback\n"); 1178 LOG_DEBUG ("Not calling callback\n");
1171 if (NULL != cfg) 1179 if (NULL != cfg)
1172 GNUNET_CONFIGURATION_destroy(cfg); 1180 GNUNET_CONFIGURATION_destroy (cfg);
1173 GNUNET_free_non_null(emsg); 1181 GNUNET_free_non_null (emsg);
1174} 1182}
1175 1183
1176 1184
@@ -1184,8 +1192,8 @@ handle_link_controllers_result(
1184 * down signalling an error (message malformed) 1192 * down signalling an error (message malformed)
1185 */ 1193 */
1186static int 1194static int
1187check_barrier_status(void *cls, 1195check_barrier_status (void *cls,
1188 const struct GNUNET_TESTBED_BarrierStatusMsg *msg) 1196 const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
1189{ 1197{
1190 uint16_t msize; 1198 uint16_t msize;
1191 uint16_t name_len; 1199 uint16_t name_len;
@@ -1193,31 +1201,31 @@ check_barrier_status(void *cls,
1193 const char *name; 1201 const char *name;
1194 size_t emsg_len; 1202 size_t emsg_len;
1195 1203
1196 msize = ntohs(msg->header.size); 1204 msize = ntohs (msg->header.size);
1197 name = msg->data; 1205 name = msg->data;
1198 name_len = ntohs(msg->name_len); 1206 name_len = ntohs (msg->name_len);
1199 1207
1200 if (sizeof(struct GNUNET_TESTBED_BarrierStatusMsg) + name_len + 1 > msize) 1208 if (sizeof(struct GNUNET_TESTBED_BarrierStatusMsg) + name_len + 1 > msize)
1201 { 1209 {
1202 GNUNET_break_op(0); 1210 GNUNET_break_op (0);
1203 return GNUNET_SYSERR; 1211 return GNUNET_SYSERR;
1204 } 1212 }
1205 if ('\0' != name[name_len]) 1213 if ('\0' != name[name_len])
1206 { 1214 {
1207 GNUNET_break_op(0); 1215 GNUNET_break_op (0);
1208 return GNUNET_SYSERR; 1216 return GNUNET_SYSERR;
1209 } 1217 }
1210 status = ntohs(msg->status); 1218 status = ntohs (msg->status);
1211 if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status) 1219 if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status)
1220 {
1221 emsg_len = msize - (sizeof(struct GNUNET_TESTBED_BarrierStatusMsg)
1222 + name_len + 1); /* +1!? */
1223 if (0 == emsg_len)
1212 { 1224 {
1213 emsg_len = msize - (sizeof(struct GNUNET_TESTBED_BarrierStatusMsg) + 1225 GNUNET_break_op (0);
1214 name_len + 1); /* +1!? */ 1226 return GNUNET_SYSERR;
1215 if (0 == emsg_len)
1216 {
1217 GNUNET_break_op(0);
1218 return GNUNET_SYSERR;
1219 }
1220 } 1227 }
1228 }
1221 return GNUNET_OK; 1229 return GNUNET_OK;
1222} 1230}
1223 1231
@@ -1230,8 +1238,8 @@ check_barrier_status(void *cls,
1230 * @param msg the barrier status message 1238 * @param msg the barrier status message
1231 */ 1239 */
1232static void 1240static void
1233handle_barrier_status(void *cls, 1241handle_barrier_status (void *cls,
1234 const struct GNUNET_TESTBED_BarrierStatusMsg *msg) 1242 const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
1235{ 1243{
1236 struct GNUNET_TESTBED_Controller *c = cls; 1244 struct GNUNET_TESTBED_Controller *c = cls;
1237 struct GNUNET_TESTBED_Barrier *barrier; 1245 struct GNUNET_TESTBED_Barrier *barrier;
@@ -1245,68 +1253,68 @@ handle_barrier_status(void *cls,
1245 1253
1246 emsg = NULL; 1254 emsg = NULL;
1247 barrier = NULL; 1255 barrier = NULL;
1248 msize = ntohs(msg->header.size); 1256 msize = ntohs (msg->header.size);
1249 if (msize <= sizeof(struct GNUNET_TESTBED_BarrierStatusMsg)) 1257 if (msize <= sizeof(struct GNUNET_TESTBED_BarrierStatusMsg))
1250 { 1258 {
1251 GNUNET_break_op(0); 1259 GNUNET_break_op (0);
1252 goto cleanup; 1260 goto cleanup;
1253 } 1261 }
1254 name = msg->data; 1262 name = msg->data;
1255 name_len = ntohs(msg->name_len); 1263 name_len = ntohs (msg->name_len);
1256 if (name_len >= //name_len is strlen(barrier_name) 1264 if (name_len >= // name_len is strlen(barrier_name)
1257 (msize - ((sizeof msg->header) + sizeof(msg->status)))) 1265 (msize - ((sizeof msg->header) + sizeof(msg->status))))
1258 { 1266 {
1259 GNUNET_break_op(0); 1267 GNUNET_break_op (0);
1260 goto cleanup; 1268 goto cleanup;
1261 } 1269 }
1262 if ('\0' != name[name_len]) 1270 if ('\0' != name[name_len])
1263 { 1271 {
1264 GNUNET_break_op(0); 1272 GNUNET_break_op (0);
1265 goto cleanup; 1273 goto cleanup;
1266 } 1274 }
1267 LOG_DEBUG("Received BARRIER_STATUS msg\n"); 1275 LOG_DEBUG ("Received BARRIER_STATUS msg\n");
1268 status = ntohs(msg->status); 1276 status = ntohs (msg->status);
1269 if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status) 1277 if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status)
1278 {
1279 status = -1;
1280 // unlike name_len, emsg_len includes the trailing zero
1281 emsg_len = msize - (sizeof(struct GNUNET_TESTBED_BarrierStatusMsg)
1282 + (name_len + 1));
1283 if (0 == emsg_len)
1270 { 1284 {
1271 status = -1; 1285 GNUNET_break_op (0);
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 }
1288 if (NULL == c->barrier_map)
1289 {
1290 GNUNET_break_op(0);
1291 goto cleanup; 1286 goto cleanup;
1292 } 1287 }
1293 GNUNET_CRYPTO_hash(name, name_len, &key); 1288 if ('\0' != (msg->data[(name_len + 1) + (emsg_len - 1)]))
1294 barrier = GNUNET_CONTAINER_multihashmap_get(c->barrier_map, &key);
1295 if (NULL == barrier)
1296 { 1289 {
1297 GNUNET_break_op(0); 1290 GNUNET_break_op (0);
1298 goto cleanup; 1291 goto cleanup;
1299 } 1292 }
1300 GNUNET_assert(NULL != barrier->cb); 1293 emsg = GNUNET_malloc (emsg_len);
1294 GNUNET_memcpy (emsg, msg->data + name_len + 1, emsg_len);
1295 }
1296 if (NULL == c->barrier_map)
1297 {
1298 GNUNET_break_op (0);
1299 goto cleanup;
1300 }
1301 GNUNET_CRYPTO_hash (name, name_len, &key);
1302 barrier = GNUNET_CONTAINER_multihashmap_get (c->barrier_map, &key);
1303 if (NULL == barrier)
1304 {
1305 GNUNET_break_op (0);
1306 goto cleanup;
1307 }
1308 GNUNET_assert (NULL != barrier->cb);
1301 if ((GNUNET_YES == barrier->echo) && 1309 if ((GNUNET_YES == barrier->echo) &&
1302 (GNUNET_TESTBED_BARRIERSTATUS_CROSSED == status)) 1310 (GNUNET_TESTBED_BARRIERSTATUS_CROSSED == status))
1303 GNUNET_TESTBED_queue_message_(c, GNUNET_copy_message(&msg->header)); 1311 GNUNET_TESTBED_queue_message_ (c, GNUNET_copy_message (&msg->header));
1304 barrier->cb(barrier->cls, name, barrier, status, emsg); 1312 barrier->cb (barrier->cls, name, barrier, status, emsg);
1305 if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED == status) 1313 if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED == status)
1306 return; /* just initialised; skip cleanup */ 1314 return; /* just initialised; skip cleanup */
1307 1315
1308cleanup: 1316cleanup:
1309 GNUNET_free_non_null(emsg); 1317 GNUNET_free_non_null (emsg);
1310 /** 1318 /**
1311 * Do not remove the barrier if we did not echo the status back; this is 1319 * Do not remove the barrier if we did not echo the status back; this is
1312 * required at the chained testbed controller setup to ensure the only the 1320 * required at the chained testbed controller setup to ensure the only the
@@ -1314,7 +1322,7 @@ cleanup:
1314 * propagates the status. 1322 * propagates the status.
1315 */ 1323 */
1316 if ((NULL != barrier) && (GNUNET_YES == barrier->echo)) 1324 if ((NULL != barrier) && (GNUNET_YES == barrier->echo))
1317 GNUNET_TESTBED_barrier_remove_(barrier); 1325 GNUNET_TESTBED_barrier_remove_ (barrier);
1318} 1326}
1319 1327
1320 1328
@@ -1325,22 +1333,22 @@ cleanup:
1325 * @param msg the message to queue 1333 * @param msg the message to queue
1326 */ 1334 */
1327void 1335void
1328GNUNET_TESTBED_queue_message_(struct GNUNET_TESTBED_Controller *controller, 1336GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
1329 struct GNUNET_MessageHeader *msg) 1337 struct GNUNET_MessageHeader *msg)
1330{ 1338{
1331 struct GNUNET_MQ_Envelope *env; 1339 struct GNUNET_MQ_Envelope *env;
1332 struct GNUNET_MessageHeader *m2; 1340 struct GNUNET_MessageHeader *m2;
1333 uint16_t type; 1341 uint16_t type;
1334 uint16_t size; 1342 uint16_t size;
1335 1343
1336 type = ntohs(msg->type); 1344 type = ntohs (msg->type);
1337 size = ntohs(msg->size); 1345 size = ntohs (msg->size);
1338 GNUNET_assert((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) && 1346 GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) &&
1339 (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type)); 1347 (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type));
1340 env = GNUNET_MQ_msg_extra(m2, size - sizeof(*m2), type); 1348 env = GNUNET_MQ_msg_extra (m2, size - sizeof(*m2), type);
1341 GNUNET_memcpy(m2, msg, size); 1349 GNUNET_memcpy (m2, msg, size);
1342 GNUNET_free(msg); 1350 GNUNET_free (msg);
1343 GNUNET_MQ_send(controller->mq, env); 1351 GNUNET_MQ_send (controller->mq, env);
1344} 1352}
1345 1353
1346 1354
@@ -1359,7 +1367,7 @@ GNUNET_TESTBED_queue_message_(struct GNUNET_TESTBED_Controller *controller,
1359 * operation 1367 * operation
1360 */ 1368 */
1361struct OperationContext * 1369struct OperationContext *
1362GNUNET_TESTBED_forward_operation_msg_( 1370GNUNET_TESTBED_forward_operation_msg_ (
1363 struct GNUNET_TESTBED_Controller *controller, 1371 struct GNUNET_TESTBED_Controller *controller,
1364 uint64_t operation_id, 1372 uint64_t operation_id,
1365 const struct GNUNET_MessageHeader *msg, 1373 const struct GNUNET_MessageHeader *msg,
@@ -1370,21 +1378,21 @@ GNUNET_TESTBED_forward_operation_msg_(
1370 struct ForwardedOperationData *data; 1378 struct ForwardedOperationData *data;
1371 struct GNUNET_MQ_Envelope *env; 1379 struct GNUNET_MQ_Envelope *env;
1372 struct GNUNET_MessageHeader *m2; 1380 struct GNUNET_MessageHeader *m2;
1373 uint16_t type = ntohs(msg->type); 1381 uint16_t type = ntohs (msg->type);
1374 uint16_t size = ntohs(msg->size); 1382 uint16_t size = ntohs (msg->size);
1375 1383
1376 env = GNUNET_MQ_msg_extra(m2, size - sizeof(*m2), type); 1384 env = GNUNET_MQ_msg_extra (m2, size - sizeof(*m2), type);
1377 GNUNET_memcpy(m2, msg, size); 1385 GNUNET_memcpy (m2, msg, size);
1378 GNUNET_MQ_send(controller->mq, env); 1386 GNUNET_MQ_send (controller->mq, env);
1379 data = GNUNET_new(struct ForwardedOperationData); 1387 data = GNUNET_new (struct ForwardedOperationData);
1380 data->cc = cc; 1388 data->cc = cc;
1381 data->cc_cls = cc_cls; 1389 data->cc_cls = cc_cls;
1382 opc = GNUNET_new(struct OperationContext); 1390 opc = GNUNET_new (struct OperationContext);
1383 opc->c = controller; 1391 opc->c = controller;
1384 opc->type = OP_FORWARDED; 1392 opc->type = OP_FORWARDED;
1385 opc->data = data; 1393 opc->data = data;
1386 opc->id = operation_id; 1394 opc->id = operation_id;
1387 GNUNET_TESTBED_insert_opc_(controller, opc); 1395 GNUNET_TESTBED_insert_opc_ (controller, opc);
1388 return opc; 1396 return opc;
1389} 1397}
1390 1398
@@ -1396,11 +1404,11 @@ GNUNET_TESTBED_forward_operation_msg_(
1396 * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_() 1404 * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_()
1397 */ 1405 */
1398void 1406void
1399GNUNET_TESTBED_forward_operation_msg_cancel_(struct OperationContext *opc) 1407GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc)
1400{ 1408{
1401 GNUNET_TESTBED_remove_opc_(opc->c, opc); 1409 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
1402 GNUNET_free(opc->data); 1410 GNUNET_free (opc->data);
1403 GNUNET_free(opc); 1411 GNUNET_free (opc);
1404} 1412}
1405 1413
1406 1414
@@ -1411,19 +1419,19 @@ GNUNET_TESTBED_forward_operation_msg_cancel_(struct OperationContext *opc)
1411 * @param cls the closure from GNUNET_TESTBED_operation_create_() 1419 * @param cls the closure from GNUNET_TESTBED_operation_create_()
1412 */ 1420 */
1413static void 1421static void
1414opstart_link_controllers(void *cls) 1422opstart_link_controllers (void *cls)
1415{ 1423{
1416 struct OperationContext *opc = cls; 1424 struct OperationContext *opc = cls;
1417 struct ControllerLinkData *data; 1425 struct ControllerLinkData *data;
1418 struct GNUNET_TESTBED_ControllerLinkRequest *msg; 1426 struct GNUNET_TESTBED_ControllerLinkRequest *msg;
1419 1427
1420 GNUNET_assert(NULL != opc->data); 1428 GNUNET_assert (NULL != opc->data);
1421 data = opc->data; 1429 data = opc->data;
1422 msg = data->msg; 1430 msg = data->msg;
1423 data->msg = NULL; 1431 data->msg = NULL;
1424 opc->state = OPC_STATE_STARTED; 1432 opc->state = OPC_STATE_STARTED;
1425 GNUNET_TESTBED_insert_opc_(opc->c, opc); 1433 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
1426 GNUNET_TESTBED_queue_message_(opc->c, &msg->header); 1434 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
1427} 1435}
1428 1436
1429 1437
@@ -1433,27 +1441,27 @@ opstart_link_controllers(void *cls)
1433 * @param cls the closure from GNUNET_TESTBED_operation_create_() 1441 * @param cls the closure from GNUNET_TESTBED_operation_create_()
1434 */ 1442 */
1435static void 1443static void
1436oprelease_link_controllers(void *cls) 1444oprelease_link_controllers (void *cls)
1437{ 1445{
1438 struct OperationContext *opc = cls; 1446 struct OperationContext *opc = cls;
1439 struct ControllerLinkData *data; 1447 struct ControllerLinkData *data;
1440 1448
1441 data = opc->data; 1449 data = opc->data;
1442 switch (opc->state) 1450 switch (opc->state)
1443 { 1451 {
1444 case OPC_STATE_INIT: 1452 case OPC_STATE_INIT:
1445 GNUNET_free(data->msg); 1453 GNUNET_free (data->msg);
1446 break; 1454 break;
1447 1455
1448 case OPC_STATE_STARTED: 1456 case OPC_STATE_STARTED:
1449 GNUNET_TESTBED_remove_opc_(opc->c, opc); 1457 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
1450 break; 1458 break;
1451 1459
1452 case OPC_STATE_FINISHED: 1460 case OPC_STATE_FINISHED:
1453 break; 1461 break;
1454 } 1462 }
1455 GNUNET_free_non_null(data); 1463 GNUNET_free_non_null (data);
1456 GNUNET_free(opc); 1464 GNUNET_free (opc);
1457} 1465}
1458 1466
1459 1467
@@ -1463,19 +1471,19 @@ oprelease_link_controllers(void *cls)
1463 * @param cls the OperationContext of type OP_GET_SLAVE_CONFIG 1471 * @param cls the OperationContext of type OP_GET_SLAVE_CONFIG
1464 */ 1472 */
1465static void 1473static void
1466opstart_get_slave_config(void *cls) 1474opstart_get_slave_config (void *cls)
1467{ 1475{
1468 struct OperationContext *opc = cls; 1476 struct OperationContext *opc = cls;
1469 struct GetSlaveConfigData *data = opc->data; 1477 struct GetSlaveConfigData *data = opc->data;
1470 struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg; 1478 struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
1471 1479
1472 GNUNET_assert(NULL != data); 1480 GNUNET_assert (NULL != data);
1473 msg = GNUNET_TESTBED_generate_slavegetconfig_msg_(opc->id, data->slave_id); 1481 msg = GNUNET_TESTBED_generate_slavegetconfig_msg_ (opc->id, data->slave_id);
1474 GNUNET_free(opc->data); 1482 GNUNET_free (opc->data);
1475 data = NULL; 1483 data = NULL;
1476 opc->data = NULL; 1484 opc->data = NULL;
1477 GNUNET_TESTBED_insert_opc_(opc->c, opc); 1485 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
1478 GNUNET_TESTBED_queue_message_(opc->c, &msg->header); 1486 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
1479 opc->state = OPC_STATE_STARTED; 1487 opc->state = OPC_STATE_STARTED;
1480} 1488}
1481 1489
@@ -1486,26 +1494,26 @@ opstart_get_slave_config(void *cls)
1486 * @param cls the OperationContext of type OP_GET_SLAVE_CONFIG 1494 * @param cls the OperationContext of type OP_GET_SLAVE_CONFIG
1487 */ 1495 */
1488static void 1496static void
1489oprelease_get_slave_config(void *cls) 1497oprelease_get_slave_config (void *cls)
1490{ 1498{
1491 struct OperationContext *opc = cls; 1499 struct OperationContext *opc = cls;
1492 1500
1493 switch (opc->state) 1501 switch (opc->state)
1494 { 1502 {
1495 case OPC_STATE_INIT: 1503 case OPC_STATE_INIT:
1496 GNUNET_free(opc->data); 1504 GNUNET_free (opc->data);
1497 break; 1505 break;
1498 1506
1499 case OPC_STATE_STARTED: 1507 case OPC_STATE_STARTED:
1500 GNUNET_TESTBED_remove_opc_(opc->c, opc); 1508 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
1501 break; 1509 break;
1502 1510
1503 case OPC_STATE_FINISHED: 1511 case OPC_STATE_FINISHED:
1504 if (NULL != opc->data) 1512 if (NULL != opc->data)
1505 GNUNET_CONFIGURATION_destroy(opc->data); 1513 GNUNET_CONFIGURATION_destroy (opc->data);
1506 break; 1514 break;
1507 } 1515 }
1508 GNUNET_free(opc); 1516 GNUNET_free (opc);
1509} 1517}
1510 1518
1511 1519
@@ -1518,13 +1526,13 @@ oprelease_get_slave_config(void *cls)
1518 * @param error error code 1526 * @param error error code
1519 */ 1527 */
1520static void 1528static void
1521mq_error_handler(void *cls, enum GNUNET_MQ_Error error) 1529mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
1522{ 1530{
1523 /* struct GNUNET_TESTBED_Controller *c = cls; */ 1531 /* struct GNUNET_TESTBED_Controller *c = cls; */
1524 1532
1525 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Encountered MQ error: %d\n", error); 1533 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Encountered MQ error: %d\n", error);
1526 /* now what? */ 1534 /* now what? */
1527 GNUNET_SCHEDULER_shutdown(); /* seems most reasonable */ 1535 GNUNET_SCHEDULER_shutdown (); /* seems most reasonable */
1528} 1536}
1529 1537
1530 1538
@@ -1544,58 +1552,58 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
1544 * @return handle to the controller 1552 * @return handle to the controller
1545 */ 1553 */
1546struct GNUNET_TESTBED_Controller * 1554struct GNUNET_TESTBED_Controller *
1547GNUNET_TESTBED_controller_connect(struct GNUNET_TESTBED_Host *host, 1555GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
1548 uint64_t event_mask, 1556 uint64_t event_mask,
1549 GNUNET_TESTBED_ControllerCallback cc, 1557 GNUNET_TESTBED_ControllerCallback cc,
1550 void *cc_cls) 1558 void *cc_cls)
1551{ 1559{
1552 struct GNUNET_TESTBED_Controller *controller = 1560 struct GNUNET_TESTBED_Controller *controller =
1553 GNUNET_new(struct GNUNET_TESTBED_Controller); 1561 GNUNET_new (struct GNUNET_TESTBED_Controller);
1554 struct GNUNET_MQ_MessageHandler handlers[] = 1562 struct GNUNET_MQ_MessageHandler handlers[] =
1555 { GNUNET_MQ_hd_var_size(add_host_confirm, 1563 { GNUNET_MQ_hd_var_size (add_host_confirm,
1556 GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS, 1564 GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS,
1557 struct GNUNET_TESTBED_HostConfirmedMessage, 1565 struct GNUNET_TESTBED_HostConfirmedMessage,
1558 controller), 1566 controller),
1559 GNUNET_MQ_hd_fixed_size(peer_conevent, 1567 GNUNET_MQ_hd_fixed_size (peer_conevent,
1560 GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT, 1568 GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT,
1561 struct GNUNET_TESTBED_ConnectionEventMessage, 1569 struct GNUNET_TESTBED_ConnectionEventMessage,
1562 controller), 1570 controller),
1563 GNUNET_MQ_hd_fixed_size(opsuccess, 1571 GNUNET_MQ_hd_fixed_size (opsuccess,
1564 GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS, 1572 GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS,
1565 struct 1573 struct
1566 GNUNET_TESTBED_GenericOperationSuccessEventMessage, 1574 GNUNET_TESTBED_GenericOperationSuccessEventMessage,
1567 controller), 1575 controller),
1568 GNUNET_MQ_hd_var_size(op_fail_event, 1576 GNUNET_MQ_hd_var_size (op_fail_event,
1569 GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT, 1577 GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT,
1570 struct GNUNET_TESTBED_OperationFailureEventMessage, 1578 struct GNUNET_TESTBED_OperationFailureEventMessage,
1571 controller), 1579 controller),
1572 GNUNET_MQ_hd_fixed_size(peer_create_success, 1580 GNUNET_MQ_hd_fixed_size (peer_create_success,
1573 GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS, 1581 GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS,
1574 struct 1582 struct
1575 GNUNET_TESTBED_PeerCreateSuccessEventMessage, 1583 GNUNET_TESTBED_PeerCreateSuccessEventMessage,
1576 controller), 1584 controller),
1577 GNUNET_MQ_hd_fixed_size(peer_event, 1585 GNUNET_MQ_hd_fixed_size (peer_event,
1578 GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT, 1586 GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT,
1579 struct GNUNET_TESTBED_PeerEventMessage, 1587 struct GNUNET_TESTBED_PeerEventMessage,
1580 controller), 1588 controller),
1581 GNUNET_MQ_hd_var_size(peer_config, 1589 GNUNET_MQ_hd_var_size (peer_config,
1582 GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION, 1590 GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION,
1583 struct 1591 struct
1584 GNUNET_TESTBED_PeerConfigurationInformationMessage, 1592 GNUNET_TESTBED_PeerConfigurationInformationMessage,
1585 controller), 1593 controller),
1586 GNUNET_MQ_hd_var_size(slave_config, 1594 GNUNET_MQ_hd_var_size (slave_config,
1587 GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION, 1595 GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION,
1588 struct GNUNET_TESTBED_SlaveConfiguration, 1596 struct GNUNET_TESTBED_SlaveConfiguration,
1589 controller), 1597 controller),
1590 GNUNET_MQ_hd_var_size(link_controllers_result, 1598 GNUNET_MQ_hd_var_size (link_controllers_result,
1591 GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT, 1599 GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT,
1592 struct GNUNET_TESTBED_ControllerLinkResponse, 1600 struct GNUNET_TESTBED_ControllerLinkResponse,
1593 controller), 1601 controller),
1594 GNUNET_MQ_hd_var_size(barrier_status, 1602 GNUNET_MQ_hd_var_size (barrier_status,
1595 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, 1603 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS,
1596 struct GNUNET_TESTBED_BarrierStatusMsg, 1604 struct GNUNET_TESTBED_BarrierStatusMsg,
1597 controller), 1605 controller),
1598 GNUNET_MQ_handler_end() }; 1606 GNUNET_MQ_handler_end () };
1599 struct GNUNET_TESTBED_InitMessage *msg; 1607 struct GNUNET_TESTBED_InitMessage *msg;
1600 struct GNUNET_MQ_Envelope *env; 1608 struct GNUNET_MQ_Envelope *env;
1601 const struct GNUNET_CONFIGURATION_Handle *cfg; 1609 const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -1605,75 +1613,75 @@ GNUNET_TESTBED_controller_connect(struct GNUNET_TESTBED_Host *host,
1605 unsigned long long max_parallel_topology_config_operations; 1613 unsigned long long max_parallel_topology_config_operations;
1606 size_t slen; 1614 size_t slen;
1607 1615
1608 GNUNET_assert(NULL != (cfg = GNUNET_TESTBED_host_get_cfg_(host))); 1616 GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host)));
1609 if (GNUNET_OK != 1617 if (GNUNET_OK !=
1610 GNUNET_CONFIGURATION_get_value_number(cfg, 1618 GNUNET_CONFIGURATION_get_value_number (cfg,
1611 "testbed", 1619 "testbed",
1612 "MAX_PARALLEL_OPERATIONS", 1620 "MAX_PARALLEL_OPERATIONS",
1613 &max_parallel_operations)) 1621 &max_parallel_operations))
1614 { 1622 {
1615 GNUNET_break(0); 1623 GNUNET_break (0);
1616 GNUNET_free(controller); 1624 GNUNET_free (controller);
1617 return NULL; 1625 return NULL;
1618 } 1626 }
1619 if (GNUNET_OK != 1627 if (GNUNET_OK !=
1620 GNUNET_CONFIGURATION_get_value_number(cfg, 1628 GNUNET_CONFIGURATION_get_value_number (cfg,
1621 "testbed", 1629 "testbed",
1622 "MAX_PARALLEL_SERVICE_CONNECTIONS", 1630 "MAX_PARALLEL_SERVICE_CONNECTIONS",
1623 &max_parallel_service_connections)) 1631 &max_parallel_service_connections))
1624 { 1632 {
1625 GNUNET_break(0); 1633 GNUNET_break (0);
1626 GNUNET_free(controller); 1634 GNUNET_free (controller);
1627 return NULL; 1635 return NULL;
1628 } 1636 }
1629 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number( 1637 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (
1630 cfg, 1638 cfg,
1631 "testbed", 1639 "testbed",
1632 "MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS", 1640 "MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS",
1633 &max_parallel_topology_config_operations)) 1641 &max_parallel_topology_config_operations))
1634 { 1642 {
1635 GNUNET_break(0); 1643 GNUNET_break (0);
1636 GNUNET_free(controller); 1644 GNUNET_free (controller);
1637 return NULL; 1645 return NULL;
1638 } 1646 }
1639 controller->cc = cc; 1647 controller->cc = cc;
1640 controller->cc_cls = cc_cls; 1648 controller->cc_cls = cc_cls;
1641 controller->event_mask = event_mask; 1649 controller->event_mask = event_mask;
1642 controller->cfg = GNUNET_CONFIGURATION_dup(cfg); 1650 controller->cfg = GNUNET_CONFIGURATION_dup (cfg);
1643 controller->mq = GNUNET_CLIENT_connect(controller->cfg, 1651 controller->mq = GNUNET_CLIENT_connect (controller->cfg,
1644 "testbed", 1652 "testbed",
1645 handlers, 1653 handlers,
1646 &mq_error_handler, 1654 &mq_error_handler,
1647 controller); 1655 controller);
1648 if (NULL == controller->mq) 1656 if (NULL == controller->mq)
1649 { 1657 {
1650 GNUNET_break(0); 1658 GNUNET_break (0);
1651 GNUNET_TESTBED_controller_disconnect(controller); 1659 GNUNET_TESTBED_controller_disconnect (controller);
1652 return NULL; 1660 return NULL;
1653 } 1661 }
1654 GNUNET_TESTBED_mark_host_registered_at_(host, controller); 1662 GNUNET_TESTBED_mark_host_registered_at_ (host, controller);
1655 controller->host = host; 1663 controller->host = host;
1656 controller->opq_parallel_operations = 1664 controller->opq_parallel_operations =
1657 GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_FIXED, 1665 GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED,
1658 (unsigned int) 1666 (unsigned int)
1659 max_parallel_operations); 1667 max_parallel_operations);
1660 controller->opq_parallel_service_connections = 1668 controller->opq_parallel_service_connections =
1661 GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_FIXED, 1669 GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED,
1662 (unsigned int) 1670 (unsigned int)
1663 max_parallel_service_connections); 1671 max_parallel_service_connections);
1664 controller->opq_parallel_topology_config_operations = 1672 controller->opq_parallel_topology_config_operations =
1665 GNUNET_TESTBED_operation_queue_create_( 1673 GNUNET_TESTBED_operation_queue_create_ (
1666 OPERATION_QUEUE_TYPE_FIXED, 1674 OPERATION_QUEUE_TYPE_FIXED,
1667 (unsigned int)max_parallel_topology_config_operations); 1675 (unsigned int) max_parallel_topology_config_operations);
1668 controller_hostname = GNUNET_TESTBED_host_get_hostname(host); 1676 controller_hostname = GNUNET_TESTBED_host_get_hostname (host);
1669 if (NULL == controller_hostname) 1677 if (NULL == controller_hostname)
1670 controller_hostname = "127.0.0.1"; 1678 controller_hostname = "127.0.0.1";
1671 slen = strlen(controller_hostname) + 1; 1679 slen = strlen (controller_hostname) + 1;
1672 env = GNUNET_MQ_msg_extra(msg, slen, GNUNET_MESSAGE_TYPE_TESTBED_INIT); 1680 env = GNUNET_MQ_msg_extra (msg, slen, GNUNET_MESSAGE_TYPE_TESTBED_INIT);
1673 msg->host_id = htonl(GNUNET_TESTBED_host_get_id_(host)); 1681 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
1674 msg->event_mask = GNUNET_htonll(controller->event_mask); 1682 msg->event_mask = GNUNET_htonll (controller->event_mask);
1675 GNUNET_memcpy(&msg[1], controller_hostname, slen); 1683 GNUNET_memcpy (&msg[1], controller_hostname, slen);
1676 GNUNET_MQ_send(controller->mq, env); 1684 GNUNET_MQ_send (controller->mq, env);
1677 return controller; 1685 return controller;
1678} 1686}
1679 1687
@@ -1688,16 +1696,16 @@ GNUNET_TESTBED_controller_connect(struct GNUNET_TESTBED_Host *host,
1688 * #GNUNET_NO if not. 1696 * #GNUNET_NO if not.
1689 */ 1697 */
1690static int 1698static int
1691opc_free_iterator(void *cls, uint32_t key, void *value) 1699opc_free_iterator (void *cls, uint32_t key, void *value)
1692{ 1700{
1693 struct GNUNET_CONTAINER_MultiHashMap32 *map = cls; 1701 struct GNUNET_CONTAINER_MultiHashMap32 *map = cls;
1694 struct OperationContext *opc = value; 1702 struct OperationContext *opc = value;
1695 1703
1696 GNUNET_assert(NULL != opc); 1704 GNUNET_assert (NULL != opc);
1697 GNUNET_break(0); 1705 GNUNET_break (0);
1698 GNUNET_assert(GNUNET_YES == 1706 GNUNET_assert (GNUNET_YES ==
1699 GNUNET_CONTAINER_multihashmap32_remove(map, key, value)); 1707 GNUNET_CONTAINER_multihashmap32_remove (map, key, value));
1700 GNUNET_free(opc); 1708 GNUNET_free (opc);
1701 return GNUNET_YES; 1709 return GNUNET_YES;
1702} 1710}
1703 1711
@@ -1710,30 +1718,30 @@ opc_free_iterator(void *cls, uint32_t key, void *value)
1710 * @param c handle to controller to stop 1718 * @param c handle to controller to stop
1711 */ 1719 */
1712void 1720void
1713GNUNET_TESTBED_controller_disconnect(struct GNUNET_TESTBED_Controller *c) 1721GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c)
1714{ 1722{
1715 if (NULL != c->mq) 1723 if (NULL != c->mq)
1716 { 1724 {
1717 GNUNET_MQ_destroy(c->mq); 1725 GNUNET_MQ_destroy (c->mq);
1718 c->mq = NULL; 1726 c->mq = NULL;
1719 } 1727 }
1720 if (NULL != c->host) 1728 if (NULL != c->host)
1721 GNUNET_TESTBED_deregister_host_at_(c->host, c); 1729 GNUNET_TESTBED_deregister_host_at_ (c->host, c);
1722 GNUNET_CONFIGURATION_destroy(c->cfg); 1730 GNUNET_CONFIGURATION_destroy (c->cfg);
1723 GNUNET_TESTBED_operation_queue_destroy_(c->opq_parallel_operations); 1731 GNUNET_TESTBED_operation_queue_destroy_ (c->opq_parallel_operations);
1724 GNUNET_TESTBED_operation_queue_destroy_(c->opq_parallel_service_connections); 1732 GNUNET_TESTBED_operation_queue_destroy_ (c->opq_parallel_service_connections);
1725 GNUNET_TESTBED_operation_queue_destroy_( 1733 GNUNET_TESTBED_operation_queue_destroy_ (
1726 c->opq_parallel_topology_config_operations); 1734 c->opq_parallel_topology_config_operations);
1727 if (NULL != c->opc_map) 1735 if (NULL != c->opc_map)
1728 { 1736 {
1729 GNUNET_assert(GNUNET_SYSERR != 1737 GNUNET_assert (GNUNET_SYSERR !=
1730 GNUNET_CONTAINER_multihashmap32_iterate(c->opc_map, 1738 GNUNET_CONTAINER_multihashmap32_iterate (c->opc_map,
1731 &opc_free_iterator, 1739 &opc_free_iterator,
1732 c->opc_map)); 1740 c->opc_map));
1733 GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap32_size(c->opc_map)); 1741 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (c->opc_map));
1734 GNUNET_CONTAINER_multihashmap32_destroy(c->opc_map); 1742 GNUNET_CONTAINER_multihashmap32_destroy (c->opc_map);
1735 } 1743 }
1736 GNUNET_free(c); 1744 GNUNET_free (c);
1737} 1745}
1738 1746
1739 1747
@@ -1747,19 +1755,19 @@ GNUNET_TESTBED_controller_disconnect(struct GNUNET_TESTBED_Controller *c)
1747 * @return the size of the xconfig 1755 * @return the size of the xconfig
1748 */ 1756 */
1749size_t 1757size_t
1750GNUNET_TESTBED_compress_config_(const char *config, 1758GNUNET_TESTBED_compress_config_ (const char *config,
1751 size_t size, 1759 size_t size,
1752 char **xconfig) 1760 char **xconfig)
1753{ 1761{
1754 size_t xsize; 1762 size_t xsize;
1755 1763
1756 xsize = compressBound((uLong)size); 1764 xsize = compressBound ((uLong) size);
1757 *xconfig = GNUNET_malloc(xsize); 1765 *xconfig = GNUNET_malloc (xsize);
1758 GNUNET_assert(Z_OK == compress2((Bytef *)*xconfig, 1766 GNUNET_assert (Z_OK == compress2 ((Bytef *) *xconfig,
1759 (uLongf *)&xsize, 1767 (uLongf *) &xsize,
1760 (const Bytef *)config, 1768 (const Bytef *) config,
1761 (uLongf)size, 1769 (uLongf) size,
1762 Z_BEST_SPEED)); 1770 Z_BEST_SPEED));
1763 return xsize; 1771 return xsize;
1764} 1772}
1765 1773
@@ -1774,18 +1782,18 @@ GNUNET_TESTBED_compress_config_(const char *config,
1774 * @return the serialized and compressed configuration 1782 * @return the serialized and compressed configuration
1775 */ 1783 */
1776char * 1784char *
1777GNUNET_TESTBED_compress_cfg_(const struct GNUNET_CONFIGURATION_Handle *cfg, 1785GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg,
1778 size_t *size, 1786 size_t *size,
1779 size_t *xsize) 1787 size_t *xsize)
1780{ 1788{
1781 char *config; 1789 char *config;
1782 char *xconfig; 1790 char *xconfig;
1783 size_t size_; 1791 size_t size_;
1784 size_t xsize_; 1792 size_t xsize_;
1785 1793
1786 config = GNUNET_CONFIGURATION_serialize(cfg, &size_); 1794 config = GNUNET_CONFIGURATION_serialize (cfg, &size_);
1787 xsize_ = GNUNET_TESTBED_compress_config_(config, size_, &xconfig); 1795 xsize_ = GNUNET_TESTBED_compress_config_ (config, size_, &xconfig);
1788 GNUNET_free(config); 1796 GNUNET_free (config);
1789 *size = size_; 1797 *size = size_;
1790 *xsize = xsize_; 1798 *xsize = xsize_;
1791 return xconfig; 1799 return xconfig;
@@ -1821,11 +1829,11 @@ GNUNET_TESTBED_compress_cfg_(const struct GNUNET_CONFIGURATION_Handle *cfg,
1821 * @return the operation handle 1829 * @return the operation handle
1822 */ 1830 */
1823struct GNUNET_TESTBED_Operation * 1831struct GNUNET_TESTBED_Operation *
1824GNUNET_TESTBED_controller_link(void *op_cls, 1832GNUNET_TESTBED_controller_link (void *op_cls,
1825 struct GNUNET_TESTBED_Controller *master, 1833 struct GNUNET_TESTBED_Controller *master,
1826 struct GNUNET_TESTBED_Host *delegated_host, 1834 struct GNUNET_TESTBED_Host *delegated_host,
1827 struct GNUNET_TESTBED_Host *slave_host, 1835 struct GNUNET_TESTBED_Host *slave_host,
1828 int is_subordinate) 1836 int is_subordinate)
1829{ 1837{
1830 struct OperationContext *opc; 1838 struct OperationContext *opc;
1831 struct GNUNET_TESTBED_ControllerLinkRequest *msg; 1839 struct GNUNET_TESTBED_ControllerLinkRequest *msg;
@@ -1834,38 +1842,38 @@ GNUNET_TESTBED_controller_link(void *op_cls,
1834 uint32_t delegated_host_id; 1842 uint32_t delegated_host_id;
1835 uint16_t msg_size; 1843 uint16_t msg_size;
1836 1844
1837 GNUNET_assert(GNUNET_YES == 1845 GNUNET_assert (GNUNET_YES ==
1838 GNUNET_TESTBED_is_host_registered_(delegated_host, master)); 1846 GNUNET_TESTBED_is_host_registered_ (delegated_host, master));
1839 slave_host_id = GNUNET_TESTBED_host_get_id_( 1847 slave_host_id = GNUNET_TESTBED_host_get_id_ (
1840 (NULL != slave_host) ? slave_host : master->host); 1848 (NULL != slave_host) ? slave_host : master->host);
1841 delegated_host_id = GNUNET_TESTBED_host_get_id_(delegated_host); 1849 delegated_host_id = GNUNET_TESTBED_host_get_id_ (delegated_host);
1842 if ((NULL != slave_host) && (0 != slave_host_id)) 1850 if ((NULL != slave_host) && (0 != slave_host_id))
1843 GNUNET_assert(GNUNET_YES == 1851 GNUNET_assert (GNUNET_YES ==
1844 GNUNET_TESTBED_is_host_registered_(slave_host, master)); 1852 GNUNET_TESTBED_is_host_registered_ (slave_host, master));
1845 msg_size = sizeof(struct GNUNET_TESTBED_ControllerLinkRequest); 1853 msg_size = sizeof(struct GNUNET_TESTBED_ControllerLinkRequest);
1846 msg = GNUNET_malloc(msg_size); 1854 msg = GNUNET_malloc (msg_size);
1847 msg->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS); 1855 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS);
1848 msg->header.size = htons(msg_size); 1856 msg->header.size = htons (msg_size);
1849 msg->delegated_host_id = htonl(delegated_host_id); 1857 msg->delegated_host_id = htonl (delegated_host_id);
1850 msg->slave_host_id = htonl(slave_host_id); 1858 msg->slave_host_id = htonl (slave_host_id);
1851 msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0; 1859 msg->is_subordinate = (GNUNET_YES == is_subordinate) ? 1 : 0;
1852 data = GNUNET_new(struct ControllerLinkData); 1860 data = GNUNET_new (struct ControllerLinkData);
1853 data->msg = msg; 1861 data->msg = msg;
1854 data->host_id = delegated_host_id; 1862 data->host_id = delegated_host_id;
1855 opc = GNUNET_new(struct OperationContext); 1863 opc = GNUNET_new (struct OperationContext);
1856 opc->c = master; 1864 opc->c = master;
1857 opc->data = data; 1865 opc->data = data;
1858 opc->type = OP_LINK_CONTROLLERS; 1866 opc->type = OP_LINK_CONTROLLERS;
1859 opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); 1867 opc->id = GNUNET_TESTBED_get_next_op_id (opc->c);
1860 opc->state = OPC_STATE_INIT; 1868 opc->state = OPC_STATE_INIT;
1861 opc->op_cls = op_cls; 1869 opc->op_cls = op_cls;
1862 msg->operation_id = GNUNET_htonll(opc->id); 1870 msg->operation_id = GNUNET_htonll (opc->id);
1863 opc->op = GNUNET_TESTBED_operation_create_(opc, 1871 opc->op = GNUNET_TESTBED_operation_create_ (opc,
1864 &opstart_link_controllers, 1872 &opstart_link_controllers,
1865 &oprelease_link_controllers); 1873 &oprelease_link_controllers);
1866 GNUNET_TESTBED_operation_queue_insert_(master->opq_parallel_operations, 1874 GNUNET_TESTBED_operation_queue_insert_ (master->opq_parallel_operations,
1867 opc->op); 1875 opc->op);
1868 GNUNET_TESTBED_operation_begin_wait_(opc->op); 1876 GNUNET_TESTBED_operation_begin_wait_ (opc->op);
1869 return opc->op; 1877 return opc->op;
1870} 1878}
1871 1879
@@ -1883,28 +1891,28 @@ GNUNET_TESTBED_controller_link(void *op_cls,
1883 * @return the operation handle; 1891 * @return the operation handle;
1884 */ 1892 */
1885struct GNUNET_TESTBED_Operation * 1893struct GNUNET_TESTBED_Operation *
1886GNUNET_TESTBED_get_slave_config_(void *op_cls, 1894GNUNET_TESTBED_get_slave_config_ (void *op_cls,
1887 struct GNUNET_TESTBED_Controller *master, 1895 struct GNUNET_TESTBED_Controller *master,
1888 uint32_t slave_host_id) 1896 uint32_t slave_host_id)
1889{ 1897{
1890 struct OperationContext *opc; 1898 struct OperationContext *opc;
1891 struct GetSlaveConfigData *data; 1899 struct GetSlaveConfigData *data;
1892 1900
1893 data = GNUNET_new(struct GetSlaveConfigData); 1901 data = GNUNET_new (struct GetSlaveConfigData);
1894 data->slave_id = slave_host_id; 1902 data->slave_id = slave_host_id;
1895 opc = GNUNET_new(struct OperationContext); 1903 opc = GNUNET_new (struct OperationContext);
1896 opc->state = OPC_STATE_INIT; 1904 opc->state = OPC_STATE_INIT;
1897 opc->c = master; 1905 opc->c = master;
1898 opc->id = GNUNET_TESTBED_get_next_op_id(master); 1906 opc->id = GNUNET_TESTBED_get_next_op_id (master);
1899 opc->type = OP_GET_SLAVE_CONFIG; 1907 opc->type = OP_GET_SLAVE_CONFIG;
1900 opc->data = data; 1908 opc->data = data;
1901 opc->op_cls = op_cls; 1909 opc->op_cls = op_cls;
1902 opc->op = GNUNET_TESTBED_operation_create_(opc, 1910 opc->op = GNUNET_TESTBED_operation_create_ (opc,
1903 &opstart_get_slave_config, 1911 &opstart_get_slave_config,
1904 &oprelease_get_slave_config); 1912 &oprelease_get_slave_config);
1905 GNUNET_TESTBED_operation_queue_insert_(master->opq_parallel_operations, 1913 GNUNET_TESTBED_operation_queue_insert_ (master->opq_parallel_operations,
1906 opc->op); 1914 opc->op);
1907 GNUNET_TESTBED_operation_begin_wait_(opc->op); 1915 GNUNET_TESTBED_operation_begin_wait_ (opc->op);
1908 return opc->op; 1916 return opc->op;
1909} 1917}
1910 1918
@@ -1925,16 +1933,16 @@ GNUNET_TESTBED_get_slave_config_(void *op_cls,
1925 * master 1933 * master
1926 */ 1934 */
1927struct GNUNET_TESTBED_Operation * 1935struct GNUNET_TESTBED_Operation *
1928GNUNET_TESTBED_get_slave_config(void *op_cls, 1936GNUNET_TESTBED_get_slave_config (void *op_cls,
1929 struct GNUNET_TESTBED_Controller *master, 1937 struct GNUNET_TESTBED_Controller *master,
1930 struct GNUNET_TESTBED_Host *slave_host) 1938 struct GNUNET_TESTBED_Host *slave_host)
1931{ 1939{
1932 if (GNUNET_NO == GNUNET_TESTBED_is_host_registered_(slave_host, master)) 1940 if (GNUNET_NO == GNUNET_TESTBED_is_host_registered_ (slave_host, master))
1933 return NULL; 1941 return NULL;
1934 return GNUNET_TESTBED_get_slave_config_(op_cls, 1942 return GNUNET_TESTBED_get_slave_config_ (op_cls,
1935 master, 1943 master,
1936 GNUNET_TESTBED_host_get_id_( 1944 GNUNET_TESTBED_host_get_id_ (
1937 slave_host)); 1945 slave_host));
1938} 1946}
1939 1947
1940 1948
@@ -1948,11 +1956,11 @@ GNUNET_TESTBED_get_slave_config(void *op_cls,
1948 * be written to. 1956 * be written to.
1949 */ 1957 */
1950void 1958void
1951GNUNET_TESTBED_overlay_write_topology_to_file( 1959GNUNET_TESTBED_overlay_write_topology_to_file (
1952 struct GNUNET_TESTBED_Controller *controller, 1960 struct GNUNET_TESTBED_Controller *controller,
1953 const char *filename) 1961 const char *filename)
1954{ 1962{
1955 GNUNET_break(0); 1963 GNUNET_break (0);
1956} 1964}
1957 1965
1958 1966
@@ -1970,7 +1978,7 @@ GNUNET_TESTBED_overlay_write_topology_to_file(
1970 * @return the initialization message 1978 * @return the initialization message
1971 */ 1979 */
1972struct GNUNET_TESTBED_HelperInit * 1980struct GNUNET_TESTBED_HelperInit *
1973GNUNET_TESTBED_create_helper_init_msg_( 1981GNUNET_TESTBED_create_helper_init_msg_ (
1974 const char *trusted_ip, 1982 const char *trusted_ip,
1975 const char *hostname, 1983 const char *hostname,
1976 const struct GNUNET_CONFIGURATION_Handle *cfg) 1984 const struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -1984,30 +1992,30 @@ GNUNET_TESTBED_create_helper_init_msg_(
1984 uint16_t hostname_len; 1992 uint16_t hostname_len;
1985 uint16_t msg_size; 1993 uint16_t msg_size;
1986 1994
1987 config = GNUNET_CONFIGURATION_serialize(cfg, &config_size); 1995 config = GNUNET_CONFIGURATION_serialize (cfg, &config_size);
1988 GNUNET_assert(NULL != config); 1996 GNUNET_assert (NULL != config);
1989 xconfig_size = 1997 xconfig_size =
1990 GNUNET_TESTBED_compress_config_(config, config_size, &xconfig); 1998 GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig);
1991 GNUNET_free(config); 1999 GNUNET_free (config);
1992 trusted_ip_len = strlen(trusted_ip); 2000 trusted_ip_len = strlen (trusted_ip);
1993 hostname_len = (NULL == hostname) ? 0 : strlen(hostname); 2001 hostname_len = (NULL == hostname) ? 0 : strlen (hostname);
1994 msg_size = xconfig_size + trusted_ip_len + 1 + 2002 msg_size = xconfig_size + trusted_ip_len + 1
1995 sizeof(struct GNUNET_TESTBED_HelperInit); 2003 + sizeof(struct GNUNET_TESTBED_HelperInit);
1996 msg_size += hostname_len; 2004 msg_size += hostname_len;
1997 msg = GNUNET_realloc(xconfig, msg_size); 2005 msg = GNUNET_realloc (xconfig, msg_size);
1998 (void)memmove(((void *)&msg[1]) + trusted_ip_len + 1 + hostname_len, 2006 (void) memmove (((void *) &msg[1]) + trusted_ip_len + 1 + hostname_len,
1999 msg, 2007 msg,
2000 xconfig_size); 2008 xconfig_size);
2001 msg->header.size = htons(msg_size); 2009 msg->header.size = htons (msg_size);
2002 msg->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT); 2010 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT);
2003 msg->trusted_ip_size = htons(trusted_ip_len); 2011 msg->trusted_ip_size = htons (trusted_ip_len);
2004 msg->hostname_size = htons(hostname_len); 2012 msg->hostname_size = htons (hostname_len);
2005 msg->config_size = htons(config_size); 2013 msg->config_size = htons (config_size);
2006 (void)strcpy((char *)&msg[1], trusted_ip); 2014 (void) strcpy ((char *) &msg[1], trusted_ip);
2007 if (0 != hostname_len) 2015 if (0 != hostname_len)
2008 GNUNET_memcpy((char *)&msg[1] + trusted_ip_len + 1, 2016 GNUNET_memcpy ((char *) &msg[1] + trusted_ip_len + 1,
2009 hostname, 2017 hostname,
2010 hostname_len); 2018 hostname_len);
2011 return msg; 2019 return msg;
2012} 2020}
2013 2021
@@ -2034,10 +2042,10 @@ GNUNET_TESTBED_create_helper_init_msg_(
2034 * @param operation operation to signal completion or cancellation 2042 * @param operation operation to signal completion or cancellation
2035 */ 2043 */
2036void 2044void
2037GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation) 2045GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation)
2038{ 2046{
2039 (void)exop_check(operation); 2047 (void) exop_check (operation);
2040 GNUNET_TESTBED_operation_release_(operation); 2048 GNUNET_TESTBED_operation_release_ (operation);
2041} 2049}
2042 2050
2043 2051
@@ -2056,7 +2064,7 @@ GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
2056 * @return handle to the parsed configuration; NULL upon error while parsing the message 2064 * @return handle to the parsed configuration; NULL upon error while parsing the message
2057 */ 2065 */
2058struct GNUNET_CONFIGURATION_Handle * 2066struct GNUNET_CONFIGURATION_Handle *
2059GNUNET_TESTBED_extract_config_(const struct GNUNET_MessageHeader *msg) 2067GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg)
2060{ 2068{
2061 struct GNUNET_CONFIGURATION_Handle *cfg; 2069 struct GNUNET_CONFIGURATION_Handle *cfg;
2062 Bytef *data; 2070 Bytef *data;
@@ -2065,99 +2073,99 @@ GNUNET_TESTBED_extract_config_(const struct GNUNET_MessageHeader *msg)
2065 uLong xdata_len; 2073 uLong xdata_len;
2066 int ret; 2074 int ret;
2067 2075
2068 switch (ntohs(msg->type)) 2076 switch (ntohs (msg->type))
2069 { 2077 {
2070 case GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION: { 2078 case GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION: {
2071 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg; 2079 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg;
2072 2080
2073 imsg = 2081 imsg =
2074 (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *)msg; 2082 (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg;
2075 data_len = (uLong)ntohs(imsg->config_size); 2083 data_len = (uLong) ntohs (imsg->config_size);
2076 xdata_len = 2084 xdata_len =
2077 ntohs(imsg->header.size) - 2085 ntohs (imsg->header.size)
2078 sizeof(struct GNUNET_TESTBED_PeerConfigurationInformationMessage); 2086 - sizeof(struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
2079 xdata = (const Bytef *)&imsg[1]; 2087 xdata = (const Bytef *) &imsg[1];
2080 } 2088 }
2081 break; 2089 break;
2082 2090
2083 case GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION: { 2091 case GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION: {
2084 const struct GNUNET_TESTBED_SlaveConfiguration *imsg; 2092 const struct GNUNET_TESTBED_SlaveConfiguration *imsg;
2085 2093
2086 imsg = (const struct GNUNET_TESTBED_SlaveConfiguration *)msg; 2094 imsg = (const struct GNUNET_TESTBED_SlaveConfiguration *) msg;
2087 data_len = (uLong)ntohs(imsg->config_size); 2095 data_len = (uLong) ntohs (imsg->config_size);
2088 xdata_len = ntohs(imsg->header.size) - 2096 xdata_len = ntohs (imsg->header.size)
2089 sizeof(struct GNUNET_TESTBED_SlaveConfiguration); 2097 - sizeof(struct GNUNET_TESTBED_SlaveConfiguration);
2090 xdata = (const Bytef *)&imsg[1]; 2098 xdata = (const Bytef *) &imsg[1];
2091 } 2099 }
2092 break; 2100 break;
2093 2101
2094 case GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST: { 2102 case GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST: {
2095 const struct GNUNET_TESTBED_AddHostMessage *imsg; 2103 const struct GNUNET_TESTBED_AddHostMessage *imsg;
2096 uint16_t osize; 2104 uint16_t osize;
2097 2105
2098 imsg = (const struct GNUNET_TESTBED_AddHostMessage *)msg; 2106 imsg = (const struct GNUNET_TESTBED_AddHostMessage *) msg;
2099 data_len = (uLong)ntohs(imsg->config_size); 2107 data_len = (uLong) ntohs (imsg->config_size);
2100 osize = sizeof(struct GNUNET_TESTBED_AddHostMessage) + 2108 osize = sizeof(struct GNUNET_TESTBED_AddHostMessage)
2101 ntohs(imsg->username_length) + ntohs(imsg->hostname_length); 2109 + ntohs (imsg->username_length) + ntohs (imsg->hostname_length);
2102 xdata_len = ntohs(imsg->header.size) - osize; 2110 xdata_len = ntohs (imsg->header.size) - osize;
2103 xdata = (const Bytef *)((const void *)imsg + osize); 2111 xdata = (const Bytef *) ((const void *) imsg + osize);
2104 } 2112 }
2105 break; 2113 break;
2106 2114
2107 case GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT: { 2115 case GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT: {
2108 const struct GNUNET_TESTBED_ControllerLinkResponse *imsg; 2116 const struct GNUNET_TESTBED_ControllerLinkResponse *imsg;
2109 2117
2110 imsg = (const struct GNUNET_TESTBED_ControllerLinkResponse *)msg; 2118 imsg = (const struct GNUNET_TESTBED_ControllerLinkResponse *) msg;
2111 data_len = ntohs(imsg->config_size); 2119 data_len = ntohs (imsg->config_size);
2112 xdata_len = ntohs(imsg->header.size) - 2120 xdata_len = ntohs (imsg->header.size)
2113 sizeof(const struct GNUNET_TESTBED_ControllerLinkResponse); 2121 - sizeof(const struct GNUNET_TESTBED_ControllerLinkResponse);
2114 xdata = (const Bytef *)&imsg[1]; 2122 xdata = (const Bytef *) &imsg[1];
2115 } 2123 }
2116 break; 2124 break;
2117 2125
2118 case GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER: { 2126 case GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER: {
2119 const struct GNUNET_TESTBED_PeerCreateMessage *imsg; 2127 const struct GNUNET_TESTBED_PeerCreateMessage *imsg;
2120 2128
2121 imsg = (const struct GNUNET_TESTBED_PeerCreateMessage *)msg; 2129 imsg = (const struct GNUNET_TESTBED_PeerCreateMessage *) msg;
2122 data_len = ntohs(imsg->config_size); 2130 data_len = ntohs (imsg->config_size);
2123 xdata_len = ntohs(imsg->header.size) - 2131 xdata_len = ntohs (imsg->header.size)
2124 sizeof(struct GNUNET_TESTBED_PeerCreateMessage); 2132 - sizeof(struct GNUNET_TESTBED_PeerCreateMessage);
2125 xdata = (const Bytef *)&imsg[1]; 2133 xdata = (const Bytef *) &imsg[1];
2126 } 2134 }
2127 break; 2135 break;
2128 2136
2129 case GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER: { 2137 case GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER: {
2130 const struct GNUNET_TESTBED_PeerReconfigureMessage *imsg; 2138 const struct GNUNET_TESTBED_PeerReconfigureMessage *imsg;
2131 2139
2132 imsg = (const struct GNUNET_TESTBED_PeerReconfigureMessage *)msg; 2140 imsg = (const struct GNUNET_TESTBED_PeerReconfigureMessage *) msg;
2133 data_len = ntohs(imsg->config_size); 2141 data_len = ntohs (imsg->config_size);
2134 xdata_len = ntohs(imsg->header.size) - 2142 xdata_len = ntohs (imsg->header.size)
2135 sizeof(struct GNUNET_TESTBED_PeerReconfigureMessage); 2143 - sizeof(struct GNUNET_TESTBED_PeerReconfigureMessage);
2136 xdata = (const Bytef *)&imsg[1]; 2144 xdata = (const Bytef *) &imsg[1];
2137 } 2145 }
2138 break; 2146 break;
2139 2147
2140 default: 2148 default:
2141 GNUNET_assert(0); 2149 GNUNET_assert (0);
2142 } 2150 }
2143 data = GNUNET_malloc(data_len); 2151 data = GNUNET_malloc (data_len);
2144 if (Z_OK != (ret = uncompress(data, &data_len, xdata, xdata_len))) 2152 if (Z_OK != (ret = uncompress (data, &data_len, xdata, xdata_len)))
2145 { 2153 {
2146 GNUNET_free(data); 2154 GNUNET_free (data);
2147 GNUNET_break_op(0); /* Un-compression failure */ 2155 GNUNET_break_op (0); /* Un-compression failure */
2148 return NULL; 2156 return NULL;
2149 } 2157 }
2150 cfg = GNUNET_CONFIGURATION_create(); 2158 cfg = GNUNET_CONFIGURATION_create ();
2151 if (GNUNET_OK != GNUNET_CONFIGURATION_deserialize(cfg, 2159 if (GNUNET_OK != GNUNET_CONFIGURATION_deserialize (cfg,
2152 (const char *)data, 2160 (const char *) data,
2153 (size_t)data_len, 2161 (size_t) data_len,
2154 NULL)) 2162 NULL))
2155 { 2163 {
2156 GNUNET_free(data); 2164 GNUNET_free (data);
2157 GNUNET_break_op(0); /* De-serialization failure */ 2165 GNUNET_break_op (0); /* De-serialization failure */
2158 return NULL; 2166 return NULL;
2159 } 2167 }
2160 GNUNET_free(data); 2168 GNUNET_free (data);
2161 return cfg; 2169 return cfg;
2162} 2170}
2163 2171
@@ -2170,22 +2178,22 @@ GNUNET_TESTBED_extract_config_(const struct GNUNET_MessageHeader *msg)
2170 * @return the error message 2178 * @return the error message
2171 */ 2179 */
2172const char * 2180const char *
2173GNUNET_TESTBED_parse_error_string_( 2181GNUNET_TESTBED_parse_error_string_ (
2174 const struct GNUNET_TESTBED_OperationFailureEventMessage *msg) 2182 const struct GNUNET_TESTBED_OperationFailureEventMessage *msg)
2175{ 2183{
2176 uint16_t msize; 2184 uint16_t msize;
2177 const char *emsg; 2185 const char *emsg;
2178 2186
2179 msize = ntohs(msg->header.size); 2187 msize = ntohs (msg->header.size);
2180 if (sizeof(struct GNUNET_TESTBED_OperationFailureEventMessage) >= msize) 2188 if (sizeof(struct GNUNET_TESTBED_OperationFailureEventMessage) >= msize)
2181 return NULL; 2189 return NULL;
2182 msize -= sizeof(struct GNUNET_TESTBED_OperationFailureEventMessage); 2190 msize -= sizeof(struct GNUNET_TESTBED_OperationFailureEventMessage);
2183 emsg = (const char *)&msg[1]; 2191 emsg = (const char *) &msg[1];
2184 if ('\0' != emsg[msize - 1]) 2192 if ('\0' != emsg[msize - 1])
2185 { 2193 {
2186 GNUNET_break(0); 2194 GNUNET_break (0);
2187 return NULL; 2195 return NULL;
2188 } 2196 }
2189 return emsg; 2197 return emsg;
2190} 2198}
2191 2199
@@ -2198,13 +2206,13 @@ GNUNET_TESTBED_parse_error_string_(
2198 * @return the incremented operation id. 2206 * @return the incremented operation id.
2199 */ 2207 */
2200uint64_t 2208uint64_t
2201GNUNET_TESTBED_get_next_op_id(struct GNUNET_TESTBED_Controller *controller) 2209GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller)
2202{ 2210{
2203 uint64_t op_id; 2211 uint64_t op_id;
2204 2212
2205 op_id = (uint64_t)GNUNET_TESTBED_host_get_id_(controller->host); 2213 op_id = (uint64_t) GNUNET_TESTBED_host_get_id_ (controller->host);
2206 op_id = op_id << 32; 2214 op_id = op_id << 32;
2207 op_id |= (uint64_t)controller->operation_counter++; 2215 op_id |= (uint64_t) controller->operation_counter++;
2208 return op_id; 2216 return op_id;
2209} 2217}
2210 2218
@@ -2215,17 +2223,17 @@ GNUNET_TESTBED_get_next_op_id(struct GNUNET_TESTBED_Controller *controller)
2215 * @param cls the closure from GNUNET_TESTBED_operation_create_() 2223 * @param cls the closure from GNUNET_TESTBED_operation_create_()
2216 */ 2224 */
2217static void 2225static void
2218opstart_shutdown_peers(void *cls) 2226opstart_shutdown_peers (void *cls)
2219{ 2227{
2220 struct OperationContext *opc = cls; 2228 struct OperationContext *opc = cls;
2221 struct GNUNET_MQ_Envelope *env; 2229 struct GNUNET_MQ_Envelope *env;
2222 struct GNUNET_TESTBED_ShutdownPeersMessage *msg; 2230 struct GNUNET_TESTBED_ShutdownPeersMessage *msg;
2223 2231
2224 opc->state = OPC_STATE_STARTED; 2232 opc->state = OPC_STATE_STARTED;
2225 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS); 2233 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS);
2226 msg->operation_id = GNUNET_htonll(opc->id); 2234 msg->operation_id = GNUNET_htonll (opc->id);
2227 GNUNET_TESTBED_insert_opc_(opc->c, opc); 2235 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
2228 GNUNET_MQ_send(opc->c->mq, env); 2236 GNUNET_MQ_send (opc->c->mq, env);
2229} 2237}
2230 2238
2231 2239
@@ -2235,24 +2243,24 @@ opstart_shutdown_peers(void *cls)
2235 * @param cls the closure from GNUNET_TESTBED_operation_create_() 2243 * @param cls the closure from GNUNET_TESTBED_operation_create_()
2236 */ 2244 */
2237static void 2245static void
2238oprelease_shutdown_peers(void *cls) 2246oprelease_shutdown_peers (void *cls)
2239{ 2247{
2240 struct OperationContext *opc = cls; 2248 struct OperationContext *opc = cls;
2241 2249
2242 switch (opc->state) 2250 switch (opc->state)
2243 { 2251 {
2244 case OPC_STATE_STARTED: 2252 case OPC_STATE_STARTED:
2245 GNUNET_TESTBED_remove_opc_(opc->c, opc); 2253 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
2246 2254
2247 /* no break; continue */ 2255 /* no break; continue */
2248 case OPC_STATE_INIT: 2256 case OPC_STATE_INIT:
2249 GNUNET_free(opc->data); 2257 GNUNET_free (opc->data);
2250 break; 2258 break;
2251 2259
2252 case OPC_STATE_FINISHED: 2260 case OPC_STATE_FINISHED:
2253 break; 2261 break;
2254 } 2262 }
2255 GNUNET_free(opc); 2263 GNUNET_free (opc);
2256} 2264}
2257 2265
2258 2266
@@ -2272,32 +2280,32 @@ oprelease_shutdown_peers(void *cls)
2272 * present 2280 * present
2273 */ 2281 */
2274struct GNUNET_TESTBED_Operation * 2282struct GNUNET_TESTBED_Operation *
2275GNUNET_TESTBED_shutdown_peers(struct GNUNET_TESTBED_Controller *c, 2283GNUNET_TESTBED_shutdown_peers (struct GNUNET_TESTBED_Controller *c,
2276 void *op_cls, 2284 void *op_cls,
2277 GNUNET_TESTBED_OperationCompletionCallback cb, 2285 GNUNET_TESTBED_OperationCompletionCallback cb,
2278 void *cb_cls) 2286 void *cb_cls)
2279{ 2287{
2280 struct OperationContext *opc; 2288 struct OperationContext *opc;
2281 struct ShutdownPeersData *data; 2289 struct ShutdownPeersData *data;
2282 2290
2283 if (0 != GNUNET_CONTAINER_multihashmap32_size(c->opc_map)) 2291 if (0 != GNUNET_CONTAINER_multihashmap32_size (c->opc_map))
2284 return NULL; 2292 return NULL;
2285 data = GNUNET_new(struct ShutdownPeersData); 2293 data = GNUNET_new (struct ShutdownPeersData);
2286 data->cb = cb; 2294 data->cb = cb;
2287 data->cb_cls = cb_cls; 2295 data->cb_cls = cb_cls;
2288 opc = GNUNET_new(struct OperationContext); 2296 opc = GNUNET_new (struct OperationContext);
2289 opc->c = c; 2297 opc->c = c;
2290 opc->op_cls = op_cls; 2298 opc->op_cls = op_cls;
2291 opc->data = data; 2299 opc->data = data;
2292 opc->id = GNUNET_TESTBED_get_next_op_id(c); 2300 opc->id = GNUNET_TESTBED_get_next_op_id (c);
2293 opc->type = OP_SHUTDOWN_PEERS; 2301 opc->type = OP_SHUTDOWN_PEERS;
2294 opc->state = OPC_STATE_INIT; 2302 opc->state = OPC_STATE_INIT;
2295 opc->op = GNUNET_TESTBED_operation_create_(opc, 2303 opc->op = GNUNET_TESTBED_operation_create_ (opc,
2296 &opstart_shutdown_peers, 2304 &opstart_shutdown_peers,
2297 &oprelease_shutdown_peers); 2305 &oprelease_shutdown_peers);
2298 GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, 2306 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
2299 opc->op); 2307 opc->op);
2300 GNUNET_TESTBED_operation_begin_wait_(opc->op); 2308 GNUNET_TESTBED_operation_begin_wait_ (opc->op);
2301 return opc->op; 2309 return opc->op;
2302} 2310}
2303 2311
@@ -2311,7 +2319,7 @@ GNUNET_TESTBED_shutdown_peers(struct GNUNET_TESTBED_Controller *c,
2311 * @return The peer's unique ID. 2319 * @return The peer's unique ID.
2312 */ 2320 */
2313uint32_t 2321uint32_t
2314GNUNET_TESTBED_get_index(const struct GNUNET_TESTBED_Peer *peer) 2322GNUNET_TESTBED_get_index (const struct GNUNET_TESTBED_Peer *peer)
2315{ 2323{
2316 return peer->unique_id; 2324 return peer->unique_id;
2317} 2325}
@@ -2324,22 +2332,22 @@ GNUNET_TESTBED_get_index(const struct GNUNET_TESTBED_Peer *peer)
2324 * @param barrier the barrier to remove 2332 * @param barrier the barrier to remove
2325 */ 2333 */
2326void 2334void
2327GNUNET_TESTBED_barrier_remove_(struct GNUNET_TESTBED_Barrier *barrier) 2335GNUNET_TESTBED_barrier_remove_ (struct GNUNET_TESTBED_Barrier *barrier)
2328{ 2336{
2329 struct GNUNET_TESTBED_Controller *c = barrier->c; 2337 struct GNUNET_TESTBED_Controller *c = barrier->c;
2330 2338
2331 GNUNET_assert(NULL != c->barrier_map); /* No barriers present */ 2339 GNUNET_assert (NULL != c->barrier_map); /* No barriers present */
2332 GNUNET_assert(GNUNET_OK == 2340 GNUNET_assert (GNUNET_OK ==
2333 GNUNET_CONTAINER_multihashmap_remove(c->barrier_map, 2341 GNUNET_CONTAINER_multihashmap_remove (c->barrier_map,
2334 &barrier->key, 2342 &barrier->key,
2335 barrier)); 2343 barrier));
2336 GNUNET_free(barrier->name); 2344 GNUNET_free (barrier->name);
2337 GNUNET_free(barrier); 2345 GNUNET_free (barrier);
2338 if (0 == GNUNET_CONTAINER_multihashmap_size(c->barrier_map)) 2346 if (0 == GNUNET_CONTAINER_multihashmap_size (c->barrier_map))
2339 { 2347 {
2340 GNUNET_CONTAINER_multihashmap_destroy(c->barrier_map); 2348 GNUNET_CONTAINER_multihashmap_destroy (c->barrier_map);
2341 c->barrier_map = NULL; 2349 c->barrier_map = NULL;
2342 } 2350 }
2343} 2351}
2344 2352
2345 2353
@@ -2360,12 +2368,12 @@ GNUNET_TESTBED_barrier_remove_(struct GNUNET_TESTBED_Barrier *barrier)
2360 * @return barrier handle; NULL upon error 2368 * @return barrier handle; NULL upon error
2361 */ 2369 */
2362struct GNUNET_TESTBED_Barrier * 2370struct GNUNET_TESTBED_Barrier *
2363GNUNET_TESTBED_barrier_init_(struct GNUNET_TESTBED_Controller *controller, 2371GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller,
2364 const char *name, 2372 const char *name,
2365 unsigned int quorum, 2373 unsigned int quorum,
2366 GNUNET_TESTBED_barrier_status_cb cb, 2374 GNUNET_TESTBED_barrier_status_cb cb,
2367 void *cls, 2375 void *cls,
2368 int echo) 2376 int echo)
2369{ 2377{
2370 struct GNUNET_TESTBED_BarrierInit *msg; 2378 struct GNUNET_TESTBED_BarrierInit *msg;
2371 struct GNUNET_MQ_Envelope *env; 2379 struct GNUNET_MQ_Envelope *env;
@@ -2373,41 +2381,41 @@ GNUNET_TESTBED_barrier_init_(struct GNUNET_TESTBED_Controller *controller,
2373 struct GNUNET_HashCode key; 2381 struct GNUNET_HashCode key;
2374 size_t name_len; 2382 size_t name_len;
2375 2383
2376 GNUNET_assert(quorum <= 100); 2384 GNUNET_assert (quorum <= 100);
2377 GNUNET_assert(NULL != cb); 2385 GNUNET_assert (NULL != cb);
2378 name_len = strlen(name); 2386 name_len = strlen (name);
2379 GNUNET_assert(0 < name_len); 2387 GNUNET_assert (0 < name_len);
2380 GNUNET_CRYPTO_hash(name, name_len, &key); 2388 GNUNET_CRYPTO_hash (name, name_len, &key);
2381 if (NULL == controller->barrier_map) 2389 if (NULL == controller->barrier_map)
2382 controller->barrier_map = 2390 controller->barrier_map =
2383 GNUNET_CONTAINER_multihashmap_create(3, GNUNET_YES); 2391 GNUNET_CONTAINER_multihashmap_create (3, GNUNET_YES);
2384 if (GNUNET_YES == 2392 if (GNUNET_YES ==
2385 GNUNET_CONTAINER_multihashmap_contains(controller->barrier_map, &key)) 2393 GNUNET_CONTAINER_multihashmap_contains (controller->barrier_map, &key))
2386 { 2394 {
2387 GNUNET_break(0); 2395 GNUNET_break (0);
2388 return NULL; 2396 return NULL;
2389 } 2397 }
2390 LOG_DEBUG("Initialising barrier `%s'\n", name); 2398 LOG_DEBUG ("Initialising barrier `%s'\n", name);
2391 barrier = GNUNET_new(struct GNUNET_TESTBED_Barrier); 2399 barrier = GNUNET_new (struct GNUNET_TESTBED_Barrier);
2392 barrier->c = controller; 2400 barrier->c = controller;
2393 barrier->name = GNUNET_strdup(name); 2401 barrier->name = GNUNET_strdup (name);
2394 barrier->cb = cb; 2402 barrier->cb = cb;
2395 barrier->cls = cls; 2403 barrier->cls = cls;
2396 barrier->echo = echo; 2404 barrier->echo = echo;
2397 GNUNET_memcpy(&barrier->key, &key, sizeof(struct GNUNET_HashCode)); 2405 GNUNET_memcpy (&barrier->key, &key, sizeof(struct GNUNET_HashCode));
2398 GNUNET_assert(GNUNET_OK == 2406 GNUNET_assert (GNUNET_OK ==
2399 GNUNET_CONTAINER_multihashmap_put( 2407 GNUNET_CONTAINER_multihashmap_put (
2400 controller->barrier_map, 2408 controller->barrier_map,
2401 &barrier->key, 2409 &barrier->key,
2402 barrier, 2410 barrier,
2403 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 2411 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
2404 2412
2405 env = GNUNET_MQ_msg_extra(msg, 2413 env = GNUNET_MQ_msg_extra (msg,
2406 name_len, 2414 name_len,
2407 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT); 2415 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT);
2408 msg->quorum = (uint8_t)quorum; 2416 msg->quorum = (uint8_t) quorum;
2409 GNUNET_memcpy(msg->name, barrier->name, name_len); 2417 GNUNET_memcpy (msg->name, barrier->name, name_len);
2410 GNUNET_MQ_send(barrier->c->mq, env); 2418 GNUNET_MQ_send (barrier->c->mq, env);
2411 return barrier; 2419 return barrier;
2412} 2420}
2413 2421
@@ -2427,18 +2435,18 @@ GNUNET_TESTBED_barrier_init_(struct GNUNET_TESTBED_Controller *controller,
2427 * @return barrier handle; NULL upon error 2435 * @return barrier handle; NULL upon error
2428 */ 2436 */
2429struct GNUNET_TESTBED_Barrier * 2437struct GNUNET_TESTBED_Barrier *
2430GNUNET_TESTBED_barrier_init(struct GNUNET_TESTBED_Controller *controller, 2438GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller,
2431 const char *name, 2439 const char *name,
2432 unsigned int quorum, 2440 unsigned int quorum,
2433 GNUNET_TESTBED_barrier_status_cb cb, 2441 GNUNET_TESTBED_barrier_status_cb cb,
2434 void *cls) 2442 void *cls)
2435{ 2443{
2436 return GNUNET_TESTBED_barrier_init_(controller, 2444 return GNUNET_TESTBED_barrier_init_ (controller,
2437 name, 2445 name,
2438 quorum, 2446 quorum,
2439 cb, 2447 cb,
2440 cls, 2448 cls,
2441 GNUNET_YES); 2449 GNUNET_YES);
2442} 2450}
2443 2451
2444 2452
@@ -2448,18 +2456,18 @@ GNUNET_TESTBED_barrier_init(struct GNUNET_TESTBED_Controller *controller,
2448 * @param barrier the barrier handle 2456 * @param barrier the barrier handle
2449 */ 2457 */
2450void 2458void
2451GNUNET_TESTBED_barrier_cancel(struct GNUNET_TESTBED_Barrier *barrier) 2459GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier)
2452{ 2460{
2453 struct GNUNET_MQ_Envelope *env; 2461 struct GNUNET_MQ_Envelope *env;
2454 struct GNUNET_TESTBED_BarrierCancel *msg; 2462 struct GNUNET_TESTBED_BarrierCancel *msg;
2455 size_t slen; 2463 size_t slen;
2456 2464
2457 slen = strlen(barrier->name); 2465 slen = strlen (barrier->name);
2458 env = 2466 env =
2459 GNUNET_MQ_msg_extra(msg, slen, GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL); 2467 GNUNET_MQ_msg_extra (msg, slen, GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL);
2460 GNUNET_memcpy(msg->name, barrier->name, slen); 2468 GNUNET_memcpy (msg->name, barrier->name, slen);
2461 GNUNET_MQ_send(barrier->c->mq, env); 2469 GNUNET_MQ_send (barrier->c->mq, env);
2462 GNUNET_TESTBED_barrier_remove_(barrier); 2470 GNUNET_TESTBED_barrier_remove_ (barrier);
2463} 2471}
2464 2472
2465 2473
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h
index c79c35a5e..023d772a0 100644
--- a/src/testbed/testbed_api.h
+++ b/src/testbed/testbed_api.h
@@ -41,7 +41,8 @@
41/** 41/**
42 * Enumeration of operations 42 * Enumeration of operations
43 */ 43 */
44enum OperationType { 44enum OperationType
45{
45 /** 46 /**
46 * Peer create operation 47 * Peer create operation
47 */ 48 */
@@ -108,7 +109,8 @@ enum OperationType {
108/** 109/**
109 * Enumeration of states of OperationContext 110 * Enumeration of states of OperationContext
110 */ 111 */
111enum OperationContextState { 112enum OperationContextState
113{
112 /** 114 /**
113 * The initial state where the associated operation has just been created 115 * The initial state where the associated operation has just been created
114 * and is waiting in the operation queues to be started 116 * and is waiting in the operation queues to be started
@@ -132,7 +134,8 @@ enum OperationContextState {
132/** 134/**
133 * Context information for GNUNET_TESTBED_Operation 135 * Context information for GNUNET_TESTBED_Operation
134 */ 136 */
135struct OperationContext { 137struct OperationContext
138{
136 /** 139 /**
137 * The controller to which this operation context belongs to 140 * The controller to which this operation context belongs to
138 */ 141 */
@@ -188,7 +191,8 @@ typedef void
188 * controllers can interact with each other (in a P2P fashion); those 191 * controllers can interact with each other (in a P2P fashion); those
189 * links are established via TCP/IP on the controller's service port. 192 * links are established via TCP/IP on the controller's service port.
190 */ 193 */
191struct GNUNET_TESTBED_Controller { 194struct GNUNET_TESTBED_Controller
195{
192 /** 196 /**
193 * The host where the controller is running 197 * The host where the controller is running
194 */ 198 */
@@ -271,7 +275,8 @@ struct GNUNET_TESTBED_Controller {
271/** 275/**
272 * Handle for barrier 276 * Handle for barrier
273 */ 277 */
274struct GNUNET_TESTBED_Barrier { 278struct GNUNET_TESTBED_Barrier
279{
275 /** 280 /**
276 * hashcode identifying this barrier in the hashmap 281 * hashcode identifying this barrier in the hashmap
277 */ 282 */
@@ -313,8 +318,8 @@ struct GNUNET_TESTBED_Barrier {
313 * @deprecated 318 * @deprecated
314 */ 319 */
315void 320void
316GNUNET_TESTBED_queue_message_(struct GNUNET_TESTBED_Controller *controller, 321GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
317 struct GNUNET_MessageHeader *msg); 322 struct GNUNET_MessageHeader *msg);
318 323
319 324
320/** 325/**
@@ -326,8 +331,8 @@ GNUNET_TESTBED_queue_message_(struct GNUNET_TESTBED_Controller *controller,
326 * @param opc the operation context to be inserted 331 * @param opc the operation context to be inserted
327 */ 332 */
328void 333void
329GNUNET_TESTBED_insert_opc_(struct GNUNET_TESTBED_Controller *c, 334GNUNET_TESTBED_insert_opc_ (struct GNUNET_TESTBED_Controller *c,
330 struct OperationContext *opc); 335 struct OperationContext *opc);
331 336
332 337
333/** 338/**
@@ -338,8 +343,8 @@ GNUNET_TESTBED_insert_opc_(struct GNUNET_TESTBED_Controller *c,
338 * @param opc the operation context to remove 343 * @param opc the operation context to remove
339 */ 344 */
340void 345void
341GNUNET_TESTBED_remove_opc_(const struct GNUNET_TESTBED_Controller *c, 346GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c,
342 struct OperationContext *opc); 347 struct OperationContext *opc);
343 348
344 349
345/** 350/**
@@ -352,9 +357,9 @@ GNUNET_TESTBED_remove_opc_(const struct GNUNET_TESTBED_Controller *c,
352 * @return the size of the xconfig 357 * @return the size of the xconfig
353 */ 358 */
354size_t 359size_t
355GNUNET_TESTBED_compress_config_(const char *config, 360GNUNET_TESTBED_compress_config_ (const char *config,
356 size_t size, 361 size_t size,
357 char **xconfig); 362 char **xconfig);
358 363
359 364
360/** 365/**
@@ -367,9 +372,9 @@ GNUNET_TESTBED_compress_config_(const char *config,
367 * @return the serialized and compressed configuration 372 * @return the serialized and compressed configuration
368 */ 373 */
369char * 374char *
370GNUNET_TESTBED_compress_cfg_(const struct GNUNET_CONFIGURATION_Handle *cfg, 375GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg,
371 size_t *size, 376 size_t *size,
372 size_t *xsize); 377 size_t *xsize);
373 378
374 379
375/** 380/**
@@ -386,9 +391,10 @@ GNUNET_TESTBED_compress_cfg_(const struct GNUNET_CONFIGURATION_Handle *cfg,
386 * @return the initialization message 391 * @return the initialization message
387 */ 392 */
388struct GNUNET_TESTBED_HelperInit * 393struct GNUNET_TESTBED_HelperInit *
389GNUNET_TESTBED_create_helper_init_msg_(const char *cname, 394GNUNET_TESTBED_create_helper_init_msg_ (const char *cname,
390 const char *hostname, 395 const char *hostname,
391 const struct GNUNET_CONFIGURATION_Handle *cfg); 396 const struct
397 GNUNET_CONFIGURATION_Handle *cfg);
392 398
393 399
394/** 400/**
@@ -406,11 +412,12 @@ GNUNET_TESTBED_create_helper_init_msg_(const char *cname,
406 * operation 412 * operation
407 */ 413 */
408struct OperationContext * 414struct OperationContext *
409GNUNET_TESTBED_forward_operation_msg_(struct GNUNET_TESTBED_Controller *controller, 415GNUNET_TESTBED_forward_operation_msg_ (struct
410 uint64_t operation_id, 416 GNUNET_TESTBED_Controller *controller,
411 const struct GNUNET_MessageHeader *msg, 417 uint64_t operation_id,
412 GNUNET_MQ_MessageCallback cc, 418 const struct GNUNET_MessageHeader *msg,
413 void *cc_cls); 419 GNUNET_MQ_MessageCallback cc,
420 void *cc_cls);
414 421
415/** 422/**
416 * Function to cancel an operation created by simply forwarding an operation 423 * Function to cancel an operation created by simply forwarding an operation
@@ -419,7 +426,7 @@ GNUNET_TESTBED_forward_operation_msg_(struct GNUNET_TESTBED_Controller *controll
419 * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_() 426 * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_()
420 */ 427 */
421void 428void
422GNUNET_TESTBED_forward_operation_msg_cancel_(struct OperationContext *opc); 429GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc);
423 430
424 431
425/** 432/**
@@ -432,7 +439,7 @@ GNUNET_TESTBED_forward_operation_msg_cancel_(struct OperationContext *opc);
432 * @return handle to the parsed configuration 439 * @return handle to the parsed configuration
433 */ 440 */
434struct GNUNET_CONFIGURATION_Handle * 441struct GNUNET_CONFIGURATION_Handle *
435GNUNET_TESTBED_extract_config_(const struct GNUNET_MessageHeader *msg); 442GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg);
436 443
437 444
438/** 445/**
@@ -443,7 +450,9 @@ GNUNET_TESTBED_extract_config_(const struct GNUNET_MessageHeader *msg);
443 * @return the error message 450 * @return the error message
444 */ 451 */
445const char * 452const char *
446GNUNET_TESTBED_parse_error_string_(const struct GNUNET_TESTBED_OperationFailureEventMessage *msg); 453GNUNET_TESTBED_parse_error_string_ (const struct
454 GNUNET_TESTBED_OperationFailureEventMessage
455 *msg);
447 456
448 457
449/** 458/**
@@ -454,7 +463,7 @@ GNUNET_TESTBED_parse_error_string_(const struct GNUNET_TESTBED_OperationFailureE
454 * @return the incremented operation id. 463 * @return the incremented operation id.
455 */ 464 */
456uint64_t 465uint64_t
457GNUNET_TESTBED_get_next_op_id(struct GNUNET_TESTBED_Controller *controller); 466GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller);
458 467
459 468
460/** 469/**
@@ -470,9 +479,9 @@ GNUNET_TESTBED_get_next_op_id(struct GNUNET_TESTBED_Controller *controller);
470 * @return the operation handle; 479 * @return the operation handle;
471 */ 480 */
472struct GNUNET_TESTBED_Operation * 481struct GNUNET_TESTBED_Operation *
473GNUNET_TESTBED_get_slave_config_(void *op_cls, 482GNUNET_TESTBED_get_slave_config_ (void *op_cls,
474 struct GNUNET_TESTBED_Controller *master, 483 struct GNUNET_TESTBED_Controller *master,
475 uint32_t slave_host_id); 484 uint32_t slave_host_id);
476 485
477 486
478 487
@@ -493,12 +502,12 @@ GNUNET_TESTBED_get_slave_config_(void *op_cls,
493 * @return barrier handle; NULL upon error 502 * @return barrier handle; NULL upon error
494 */ 503 */
495struct GNUNET_TESTBED_Barrier * 504struct GNUNET_TESTBED_Barrier *
496GNUNET_TESTBED_barrier_init_(struct GNUNET_TESTBED_Controller *controller, 505GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller,
497 const char *name, 506 const char *name,
498 unsigned int quorum, 507 unsigned int quorum,
499 GNUNET_TESTBED_barrier_status_cb cb, 508 GNUNET_TESTBED_barrier_status_cb cb,
500 void *cls, 509 void *cls,
501 int echo); 510 int echo);
502 511
503 512
504/** 513/**
@@ -508,7 +517,7 @@ GNUNET_TESTBED_barrier_init_(struct GNUNET_TESTBED_Controller *controller,
508 * @param barrier the barrier to remove 517 * @param barrier the barrier to remove
509 */ 518 */
510void 519void
511GNUNET_TESTBED_barrier_remove_(struct GNUNET_TESTBED_Barrier *barrier); 520GNUNET_TESTBED_barrier_remove_ (struct GNUNET_TESTBED_Barrier *barrier);
512 521
513 522
514 523
diff --git a/src/testbed/testbed_api_barriers.c b/src/testbed/testbed_api_barriers.c
index 7e38b4297..988fa7a1e 100644
--- a/src/testbed/testbed_api_barriers.c
+++ b/src/testbed/testbed_api_barriers.c
@@ -31,19 +31,20 @@
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 */
46struct GNUNET_TESTBED_BarrierWaitHandle { 46struct GNUNET_TESTBED_BarrierWaitHandle
47{
47 /** 48 /**
48 * The name of the barrier 49 * The name of the barrier
49 */ 50 */
@@ -80,8 +81,8 @@ struct GNUNET_TESTBED_BarrierWaitHandle {
80 * @return #GNUNET_OK if the message is well-formed. 81 * @return #GNUNET_OK if the message is well-formed.
81 */ 82 */
82static int 83static int
83check_status(void *cls, 84check_status (void *cls,
84 const struct GNUNET_TESTBED_BarrierStatusMsg *msg) 85 const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
85{ 86{
86 /* FIXME: this fails to actually check that the message 87 /* FIXME: this fails to actually check that the message
87 follows the protocol spec (0-terminations!). However, 88 follows the protocol spec (0-terminations!). However,
@@ -99,43 +100,43 @@ check_status(void *cls,
99 * @param msg received message 100 * @param msg received message
100 */ 101 */
101static void 102static void
102handle_status(void *cls, 103handle_status (void *cls,
103 const struct GNUNET_TESTBED_BarrierStatusMsg *msg) 104 const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
104{ 105{
105 struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; 106 struct GNUNET_TESTBED_BarrierWaitHandle *h = cls;
106 107
107 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
108 "Got barrier status %d\n", 109 "Got barrier status %d\n",
109 (int)ntohs(msg->status)); 110 (int) ntohs (msg->status));
110 switch (ntohs(msg->status)) 111 switch (ntohs (msg->status))
111 { 112 {
112 case GNUNET_TESTBED_BARRIERSTATUS_ERROR: 113 case GNUNET_TESTBED_BARRIERSTATUS_ERROR:
113 h->cb(h->cb_cls, 114 h->cb (h->cb_cls,
114 h->name, 115 h->name,
115 GNUNET_SYSERR); 116 GNUNET_SYSERR);
116 break; 117 break;
117 118
118 case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: 119 case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED:
119 h->cb(h->cb_cls, 120 h->cb (h->cb_cls,
120 h->name, 121 h->name,
121 GNUNET_SYSERR); 122 GNUNET_SYSERR);
122 GNUNET_break(0); 123 GNUNET_break (0);
123 break; 124 break;
124 125
125 case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: 126 case GNUNET_TESTBED_BARRIERSTATUS_CROSSED:
126 h->cb(h->cb_cls, 127 h->cb (h->cb_cls,
127 h->name, 128 h->name,
128 GNUNET_OK); 129 GNUNET_OK);
129 break; 130 break;
130 131
131 default: 132 default:
132 GNUNET_break_op(0); 133 GNUNET_break_op (0);
133 h->cb(h->cb_cls, 134 h->cb (h->cb_cls,
134 h->name, 135 h->name,
135 GNUNET_SYSERR); 136 GNUNET_SYSERR);
136 break; 137 break;
137 } 138 }
138 GNUNET_TESTBED_barrier_wait_cancel(h); 139 GNUNET_TESTBED_barrier_wait_cancel (h);
139} 140}
140 141
141 142
@@ -148,15 +149,15 @@ handle_status(void *cls,
148 * @param error error code 149 * @param error error code
149 */ 150 */
150static void 151static void
151mq_error_handler(void *cls, 152mq_error_handler (void *cls,
152 enum GNUNET_MQ_Error error) 153 enum GNUNET_MQ_Error error)
153{ 154{
154 struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; 155 struct GNUNET_TESTBED_BarrierWaitHandle *h = cls;
155 156
156 h->cb(h->cb_cls, 157 h->cb (h->cb_cls,
157 h->name, 158 h->name,
158 GNUNET_SYSERR); 159 GNUNET_SYSERR);
159 GNUNET_TESTBED_barrier_wait_cancel(h); 160 GNUNET_TESTBED_barrier_wait_cancel (h);
160} 161}
161 162
162 163
@@ -172,72 +173,72 @@ mq_error_handler(void *cls,
172 * anytime before the callback is called. NULL upon error. 173 * anytime before the callback is called. NULL upon error.
173 */ 174 */
174struct GNUNET_TESTBED_BarrierWaitHandle * 175struct GNUNET_TESTBED_BarrierWaitHandle *
175GNUNET_TESTBED_barrier_wait(const char *name, 176GNUNET_TESTBED_barrier_wait (const char *name,
176 GNUNET_TESTBED_barrier_wait_cb cb, 177 GNUNET_TESTBED_barrier_wait_cb cb,
177 void *cb_cls) 178 void *cb_cls)
178{ 179{
179 struct GNUNET_TESTBED_BarrierWaitHandle *h 180 struct GNUNET_TESTBED_BarrierWaitHandle *h
180 = GNUNET_new(struct GNUNET_TESTBED_BarrierWaitHandle); 181 = GNUNET_new (struct GNUNET_TESTBED_BarrierWaitHandle);
181 struct GNUNET_MQ_MessageHandler handlers[] = { 182 struct GNUNET_MQ_MessageHandler handlers[] = {
182 GNUNET_MQ_hd_var_size(status, 183 GNUNET_MQ_hd_var_size (status,
183 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, 184 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS,
184 struct GNUNET_TESTBED_BarrierStatusMsg, 185 struct GNUNET_TESTBED_BarrierStatusMsg,
185 h), 186 h),
186 GNUNET_MQ_handler_end() 187 GNUNET_MQ_handler_end ()
187 }; 188 };
188 struct GNUNET_MQ_Envelope *env; 189 struct GNUNET_MQ_Envelope *env;
189 struct GNUNET_TESTBED_BarrierWait *msg; 190 struct GNUNET_TESTBED_BarrierWait *msg;
190 const char *cfg_filename; 191 const char *cfg_filename;
191 size_t name_len; 192 size_t name_len;
192 193
193 GNUNET_assert(NULL != cb); 194 GNUNET_assert (NULL != cb);
194 cfg_filename = getenv(ENV_TESTBED_CONFIG); 195 cfg_filename = getenv (ENV_TESTBED_CONFIG);
195 if (NULL == cfg_filename) 196 if (NULL == cfg_filename)
196 { 197 {
197 LOG(GNUNET_ERROR_TYPE_ERROR, 198 LOG (GNUNET_ERROR_TYPE_ERROR,
198 "Are you running under testbed?\n"); 199 "Are you running under testbed?\n");
199 GNUNET_free(h); 200 GNUNET_free (h);
200 return NULL; 201 return NULL;
201 } 202 }
202 h->cfg = GNUNET_CONFIGURATION_create(); 203 h->cfg = GNUNET_CONFIGURATION_create ();
203 if (GNUNET_OK != 204 if (GNUNET_OK !=
204 GNUNET_CONFIGURATION_load(h->cfg, 205 GNUNET_CONFIGURATION_load (h->cfg,
205 cfg_filename)) 206 cfg_filename))
206 { 207 {
207 LOG(GNUNET_ERROR_TYPE_ERROR, 208 LOG (GNUNET_ERROR_TYPE_ERROR,
208 "Unable to load configuration from file `%s'\n", 209 "Unable to load configuration from file `%s'\n",
209 cfg_filename); 210 cfg_filename);
210 GNUNET_CONFIGURATION_destroy(h->cfg); 211 GNUNET_CONFIGURATION_destroy (h->cfg);
211 GNUNET_free(h); 212 GNUNET_free (h);
212 return NULL; 213 return NULL;
213 } 214 }
214 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
215 "Waiting on barrier `%s'\n", 216 "Waiting on barrier `%s'\n",
216 name); 217 name);
217 h->name = GNUNET_strdup(name); 218 h->name = GNUNET_strdup (name);
218 h->cb = cb; 219 h->cb = cb;
219 h->cb_cls = cb_cls; 220 h->cb_cls = cb_cls;
220 h->mq = GNUNET_CLIENT_connect(h->cfg, 221 h->mq = GNUNET_CLIENT_connect (h->cfg,
221 "testbed-barrier", 222 "testbed-barrier",
222 handlers, 223 handlers,
223 &mq_error_handler, 224 &mq_error_handler,
224 h); 225 h);
225 if (NULL == h->mq) 226 if (NULL == h->mq)
226 { 227 {
227 LOG(GNUNET_ERROR_TYPE_ERROR, 228 LOG (GNUNET_ERROR_TYPE_ERROR,
228 "Unable to connect to local testbed-barrier service\n"); 229 "Unable to connect to local testbed-barrier service\n");
229 GNUNET_TESTBED_barrier_wait_cancel(h); 230 GNUNET_TESTBED_barrier_wait_cancel (h);
230 return NULL; 231 return NULL;
231 } 232 }
232 name_len = strlen(name); /* NOTE: unusual to not have 0-termination, change? */ 233 name_len = strlen (name); /* NOTE: unusual to not have 0-termination, change? */
233 env = GNUNET_MQ_msg_extra(msg, 234 env = GNUNET_MQ_msg_extra (msg,
234 name_len, 235 name_len,
235 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT); 236 GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT);
236 GNUNET_memcpy(msg->name, 237 GNUNET_memcpy (msg->name,
237 name, 238 name,
238 name_len); 239 name_len);
239 GNUNET_MQ_send(h->mq, 240 GNUNET_MQ_send (h->mq,
240 env); 241 env);
241 return h; 242 return h;
242} 243}
243 244
@@ -248,16 +249,16 @@ GNUNET_TESTBED_barrier_wait(const char *name,
248 * @param h the barrier wait handle 249 * @param h the barrier wait handle
249 */ 250 */
250void 251void
251GNUNET_TESTBED_barrier_wait_cancel(struct GNUNET_TESTBED_BarrierWaitHandle *h) 252GNUNET_TESTBED_barrier_wait_cancel (struct GNUNET_TESTBED_BarrierWaitHandle *h)
252{ 253{
253 if (NULL != h->mq) 254 if (NULL != h->mq)
254 { 255 {
255 GNUNET_MQ_destroy(h->mq); 256 GNUNET_MQ_destroy (h->mq);
256 h->mq = NULL; 257 h->mq = NULL;
257 } 258 }
258 GNUNET_free(h->name); 259 GNUNET_free (h->name);
259 GNUNET_CONFIGURATION_destroy(h->cfg); 260 GNUNET_CONFIGURATION_destroy (h->cfg);
260 GNUNET_free(h); 261 GNUNET_free (h);
261} 262}
262 263
263/* end of testbed_api_barriers.c */ 264/* end of testbed_api_barriers.c */
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c
index cbcfe1a18..fdff952a0 100644
--- a/src/testbed/testbed_api_hosts.c
+++ b/src/testbed/testbed_api_hosts.c
@@ -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,7 +85,8 @@
85/** 85/**
86 * A list entry for registered controllers list 86 * A list entry for registered controllers list
87 */ 87 */
88struct RegisteredController { 88struct RegisteredController
89{
89 /** 90 /**
90 * The controller at which this host is registered 91 * The controller at which this host is registered
91 */ 92 */
@@ -108,7 +109,8 @@ struct RegisteredController {
108 * The master process must be able to SSH to this host without password (via 109 * The master process must be able to SSH to this host without password (via
109 * ssh-agent). 110 * ssh-agent).
110 */ 111 */
111struct GNUNET_TESTBED_Host { 112struct GNUNET_TESTBED_Host
113{
112 /** 114 /**
113 * The hostname of the host; NULL for localhost 115 * The hostname of the host; NULL for localhost
114 */ 116 */
@@ -184,7 +186,7 @@ static unsigned int host_list_size;
184 * @return handle to the host, NULL if host not found 186 * @return handle to the host, NULL if host not found
185 */ 187 */
186struct GNUNET_TESTBED_Host * 188struct GNUNET_TESTBED_Host *
187GNUNET_TESTBED_host_lookup_by_id_(uint32_t id) 189GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id)
188{ 190{
189 if (host_list_size <= id) 191 if (host_list_size <= id)
190 return NULL; 192 return NULL;
@@ -205,11 +207,11 @@ GNUNET_TESTBED_host_lookup_by_id_(uint32_t id)
205 * @return handle to the host, NULL on error 207 * @return handle to the host, NULL on error
206 */ 208 */
207struct GNUNET_TESTBED_Host * 209struct GNUNET_TESTBED_Host *
208GNUNET_TESTBED_host_create_by_id_( 210GNUNET_TESTBED_host_create_by_id_ (
209 uint32_t id, 211 uint32_t id,
210 const struct GNUNET_CONFIGURATION_Handle *cfg) 212 const struct GNUNET_CONFIGURATION_Handle *cfg)
211{ 213{
212 return GNUNET_TESTBED_host_create_with_id(id, NULL, NULL, cfg, 0); 214 return GNUNET_TESTBED_host_create_with_id (id, NULL, NULL, cfg, 0);
213} 215}
214 216
215 217
@@ -221,7 +223,7 @@ GNUNET_TESTBED_host_create_by_id_(
221 * 'localhost', but then obviously not globally unique) 223 * 'localhost', but then obviously not globally unique)
222 */ 224 */
223uint32_t 225uint32_t
224GNUNET_TESTBED_host_get_id_(const struct GNUNET_TESTBED_Host *host) 226GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host)
225{ 227{
226 return host->id; 228 return host->id;
227} 229}
@@ -234,7 +236,7 @@ GNUNET_TESTBED_host_get_id_(const struct GNUNET_TESTBED_Host *host)
234 * @return hostname of the host 236 * @return hostname of the host
235 */ 237 */
236const char * 238const char *
237GNUNET_TESTBED_host_get_hostname(const struct GNUNET_TESTBED_Host *host) 239GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host)
238{ 240{
239 return host->hostname; 241 return host->hostname;
240} 242}
@@ -247,7 +249,7 @@ GNUNET_TESTBED_host_get_hostname(const struct GNUNET_TESTBED_Host *host)
247 * @return username to login to the host 249 * @return username to login to the host
248 */ 250 */
249const char * 251const char *
250GNUNET_TESTBED_host_get_username_(const struct GNUNET_TESTBED_Host *host) 252GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host)
251{ 253{
252 return host->username; 254 return host->username;
253} 255}
@@ -260,7 +262,7 @@ GNUNET_TESTBED_host_get_username_(const struct GNUNET_TESTBED_Host *host)
260 * @return username to login to the host 262 * @return username to login to the host
261 */ 263 */
262uint16_t 264uint16_t
263GNUNET_TESTBED_host_get_ssh_port_(const struct GNUNET_TESTBED_Host *host) 265GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host)
264{ 266{
265 return host->port; 267 return host->port;
266} 268}
@@ -273,7 +275,7 @@ GNUNET_TESTBED_host_get_ssh_port_(const struct GNUNET_TESTBED_Host *host)
273 * @return GNUNET_YES if the controller is already started; GNUNET_NO if not 275 * @return GNUNET_YES if the controller is already started; GNUNET_NO if not
274 */ 276 */
275int 277int
276GNUNET_TESTBED_host_controller_started(const struct GNUNET_TESTBED_Host *host) 278GNUNET_TESTBED_host_controller_started (const struct GNUNET_TESTBED_Host *host)
277{ 279{
278 return host->controller_started; 280 return host->controller_started;
279} 281}
@@ -286,7 +288,7 @@ GNUNET_TESTBED_host_controller_started(const struct GNUNET_TESTBED_Host *host)
286 * @return the host's configuration template 288 * @return the host's configuration template
287 */ 289 */
288const struct GNUNET_CONFIGURATION_Handle * 290const struct GNUNET_CONFIGURATION_Handle *
289GNUNET_TESTBED_host_get_cfg_(const struct GNUNET_TESTBED_Host *host) 291GNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host)
290{ 292{
291 return host->cfg; 293 return host->cfg;
292} 294}
@@ -299,12 +301,12 @@ GNUNET_TESTBED_host_get_cfg_(const struct GNUNET_TESTBED_Host *host)
299 * @param new_cfg the new configuration to replace the old one 301 * @param new_cfg the new configuration to replace the old one
300 */ 302 */
301void 303void
302GNUNET_TESTBED_host_replace_cfg_( 304GNUNET_TESTBED_host_replace_cfg_ (
303 struct GNUNET_TESTBED_Host *host, 305 struct GNUNET_TESTBED_Host *host,
304 const struct GNUNET_CONFIGURATION_Handle *new_cfg) 306 const struct GNUNET_CONFIGURATION_Handle *new_cfg)
305{ 307{
306 GNUNET_CONFIGURATION_destroy(host->cfg); 308 GNUNET_CONFIGURATION_destroy (host->cfg);
307 host->cfg = GNUNET_CONFIGURATION_dup(new_cfg); 309 host->cfg = GNUNET_CONFIGURATION_dup (new_cfg);
308} 310}
309 311
310 312
@@ -322,7 +324,7 @@ GNUNET_TESTBED_host_replace_cfg_(
322 * @return handle to the host, NULL on error 324 * @return handle to the host, NULL on error
323 */ 325 */
324struct GNUNET_TESTBED_Host * 326struct GNUNET_TESTBED_Host *
325GNUNET_TESTBED_host_create_with_id( 327GNUNET_TESTBED_host_create_with_id (
326 uint32_t id, 328 uint32_t id,
327 const char *hostname, 329 const char *hostname,
328 const char *username, 330 const char *username,
@@ -333,26 +335,26 @@ GNUNET_TESTBED_host_create_with_id(
333 unsigned int new_size; 335 unsigned int new_size;
334 336
335 if ((id < host_list_size) && (NULL != host_list[id])) 337 if ((id < host_list_size) && (NULL != host_list[id]))
336 { 338 {
337 LOG(GNUNET_ERROR_TYPE_WARNING, "Host with id: %u already created\n", id); 339 LOG (GNUNET_ERROR_TYPE_WARNING, "Host with id: %u already created\n", id);
338 return NULL; 340 return NULL;
339 } 341 }
340 host = GNUNET_new(struct GNUNET_TESTBED_Host); 342 host = GNUNET_new (struct GNUNET_TESTBED_Host);
341 host->hostname = (NULL != hostname) ? GNUNET_strdup(hostname) : NULL; 343 host->hostname = (NULL != hostname) ? GNUNET_strdup (hostname) : NULL;
342 host->username = (NULL != username) ? GNUNET_strdup(username) : NULL; 344 host->username = (NULL != username) ? GNUNET_strdup (username) : NULL;
343 host->id = id; 345 host->id = id;
344 host->port = (0 == port) ? 22 : port; 346 host->port = (0 == port) ? 22 : port;
345 host->cfg = GNUNET_CONFIGURATION_dup(cfg); 347 host->cfg = GNUNET_CONFIGURATION_dup (cfg);
346 host->opq_parallel_overlay_connect_operations = 348 host->opq_parallel_overlay_connect_operations =
347 GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_ADAPTIVE, 349 GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_ADAPTIVE,
348 UINT_MAX); 350 UINT_MAX);
349 new_size = host_list_size; 351 new_size = host_list_size;
350 while (id >= new_size) 352 while (id >= new_size)
351 new_size += HOST_LIST_GROW_STEP; 353 new_size += HOST_LIST_GROW_STEP;
352 if (new_size != host_list_size) 354 if (new_size != host_list_size)
353 GNUNET_array_grow(host_list, host_list_size, new_size); 355 GNUNET_array_grow (host_list, host_list_size, new_size);
354 GNUNET_assert(id < host_list_size); 356 GNUNET_assert (id < host_list_size);
355 LOG(GNUNET_ERROR_TYPE_DEBUG, "Adding host with id: %u\n", host->id); 357 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding host with id: %u\n", host->id);
356 host_list[id] = host; 358 host_list[id] = host;
357 return host; 359 return host;
358} 360}
@@ -370,24 +372,24 @@ GNUNET_TESTBED_host_create_with_id(
370 * @return handle to the host, NULL on error 372 * @return handle to the host, NULL on error
371 */ 373 */
372struct GNUNET_TESTBED_Host * 374struct GNUNET_TESTBED_Host *
373GNUNET_TESTBED_host_create(const char *hostname, 375GNUNET_TESTBED_host_create (const char *hostname,
374 const char *username, 376 const char *username,
375 const struct GNUNET_CONFIGURATION_Handle *cfg, 377 const struct GNUNET_CONFIGURATION_Handle *cfg,
376 uint16_t port) 378 uint16_t port)
377{ 379{
378 static uint32_t uid_generator; 380 static uint32_t uid_generator;
379 381
380 if (NULL == hostname) 382 if (NULL == hostname)
381 return GNUNET_TESTBED_host_create_with_id(0, 383 return GNUNET_TESTBED_host_create_with_id (0,
382 hostname, 384 hostname,
383 username, 385 username,
384 cfg, 386 cfg,
385 port); 387 port);
386 return GNUNET_TESTBED_host_create_with_id(++uid_generator, 388 return GNUNET_TESTBED_host_create_with_id (++uid_generator,
387 hostname, 389 hostname,
388 username, 390 username,
389 cfg, 391 cfg,
390 port); 392 port);
391} 393}
392 394
393 395
@@ -403,7 +405,7 @@ GNUNET_TESTBED_host_create(const char *hostname,
403 * @return number of hosts returned in 'hosts', 0 on error 405 * @return number of hosts returned in 'hosts', 0 on error
404 */ 406 */
405unsigned int 407unsigned int
406GNUNET_TESTBED_hosts_load_from_file( 408GNUNET_TESTBED_hosts_load_from_file (
407 const char *filename, 409 const char *filename,
408 const struct GNUNET_CONFIGURATION_Handle *cfg, 410 const struct GNUNET_CONFIGURATION_Handle *cfg,
409 struct GNUNET_TESTBED_Host ***hosts) 411 struct GNUNET_TESTBED_Host ***hosts)
@@ -421,104 +423,104 @@ GNUNET_TESTBED_hosts_load_from_file(
421 unsigned int count; 423 unsigned int count;
422 424
423 425
424 GNUNET_assert(NULL != filename); 426 GNUNET_assert (NULL != filename);
425 if (GNUNET_YES != GNUNET_DISK_file_test(filename)) 427 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
426 { 428 {
427 LOG(GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s not found\n"), filename); 429 LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Hosts file %s not found\n"), filename);
428 return 0; 430 return 0;
429 } 431 }
430 if (GNUNET_OK != 432 if (GNUNET_OK !=
431 GNUNET_DISK_file_size(filename, &fs, GNUNET_YES, GNUNET_YES)) 433 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
432 fs = 0; 434 fs = 0;
433 if (0 == fs) 435 if (0 == fs)
434 { 436 {
435 LOG(GNUNET_ERROR_TYPE_WARNING, 437 LOG (GNUNET_ERROR_TYPE_WARNING,
436 _("Hosts file %s has no data\n"), 438 _ ("Hosts file %s has no data\n"),
437 filename); 439 filename);
438 return 0; 440 return 0;
439 } 441 }
440 data = GNUNET_malloc(fs); 442 data = GNUNET_malloc (fs);
441 if (fs != GNUNET_DISK_fn_read(filename, data, fs)) 443 if (fs != GNUNET_DISK_fn_read (filename, data, fs))
442 { 444 {
443 GNUNET_free(data); 445 GNUNET_free (data);
444 LOG(GNUNET_ERROR_TYPE_WARNING, 446 LOG (GNUNET_ERROR_TYPE_WARNING,
445 _("Hosts file %s cannot be read\n"), 447 _ ("Hosts file %s cannot be read\n"),
446 filename); 448 filename);
447 return 0; 449 return 0;
448 } 450 }
449 buf = data; 451 buf = data;
450 offset = 0; 452 offset = 0;
451 starting_host = NULL; 453 starting_host = NULL;
452 count = 0; 454 count = 0;
453 /* refer RFC 952 and RFC 1123 for valid hostnames */ 455 /* refer RFC 952 and RFC 1123 for valid hostnames */
454 GNUNET_assert(0 == regcomp(&rex, 456 GNUNET_assert (0 == regcomp (&rex,
455 "^(([[:alnum:]]+)@)?" /* username */ 457 "^(([[:alnum:]]+)@)?" /* username */
456 "([[:alnum:]]+[-[:alnum:]_\\.]+)" /* hostname */ 458 "([[:alnum:]]+[-[:alnum:]_\\.]+)" /* hostname */
457 "(:([[:digit:]]{1,5}))?", /* port */ 459 "(:([[:digit:]]{1,5}))?", /* port */
458 REG_EXTENDED | REG_ICASE)); 460 REG_EXTENDED | REG_ICASE));
459 while (offset < (fs - 1)) 461 while (offset < (fs - 1))
462 {
463 offset++;
464 if (((data[offset] == '\n')) && (buf != &data[offset]))
460 { 465 {
461 offset++; 466 unsigned int size;
462 if (((data[offset] == '\n')) && (buf != &data[offset])) 467
463 { 468 data[offset] = '\0';
464 unsigned int size; 469 username = NULL;
465 470 hostname = NULL;
466 data[offset] = '\0'; 471 port = 0;
467 username = NULL; 472 if ((REG_NOMATCH == regexec (&rex, buf, 6, pmatch, 0)) ||
468 hostname = NULL; 473 (-1 == pmatch[3].rm_so))
469 port = 0; 474 {
470 if ((REG_NOMATCH == regexec(&rex, buf, 6, pmatch, 0)) || 475 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
471 (-1 == pmatch[3].rm_so)) 476 "Error reading line `%s' in hostfile\n",
472 { 477 buf);
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'))
512 buf = &data[offset + 1]; 478 buf = &data[offset + 1];
479 continue;
480 }
481 if (-1 != pmatch[2].rm_so)
482 {
483 size = pmatch[2].rm_eo - pmatch[2].rm_so;
484 username = GNUNET_malloc (size + 1);
485 GNUNET_assert (
486 0 != GNUNET_strlcpy (username, buf + pmatch[2].rm_so, size + 1));
487 }
488 if (-1 != pmatch[5].rm_so)
489 {
490 (void) sscanf (buf + pmatch[5].rm_so, "%5hd", &port);
491 }
492 size = pmatch[3].rm_eo - pmatch[3].rm_so;
493 hostname = GNUNET_malloc (size + 1);
494 GNUNET_assert (
495 0 != GNUNET_strlcpy (hostname, buf + pmatch[3].rm_so, size + 1));
496 LOG (GNUNET_ERROR_TYPE_DEBUG,
497 "Successfully read host %s, port %d and user %s from file\n",
498 (NULL == hostname) ? "NULL" : hostname,
499 port,
500 (NULL == username) ? "NULL" : username);
501 /* We store hosts in a static list; hence we only require the starting
502 * host pointer in that list to access the newly created list of hosts */
503 if (NULL == starting_host)
504 starting_host =
505 GNUNET_TESTBED_host_create (hostname, username, cfg, port);
506 else
507 (void) GNUNET_TESTBED_host_create (hostname, username, cfg, port);
508 count++;
509 GNUNET_free_non_null (username);
510 GNUNET_free (hostname);
511 buf = &data[offset + 1];
513 } 512 }
514 regfree(&rex); 513 else if ((data[offset] == '\n') || (data[offset] == '\0'))
515 GNUNET_free(data); 514 buf = &data[offset + 1];
515 }
516 regfree (&rex);
517 GNUNET_free (data);
516 if (NULL == starting_host) 518 if (NULL == starting_host)
517 return 0; 519 return 0;
518 *hosts = GNUNET_malloc(sizeof(struct GNUNET_TESTBED_Host *) * count); 520 *hosts = GNUNET_malloc (sizeof(struct GNUNET_TESTBED_Host *) * count);
519 GNUNET_memcpy(*hosts, 521 GNUNET_memcpy (*hosts,
520 &host_list[GNUNET_TESTBED_host_get_id_(starting_host)], 522 &host_list[GNUNET_TESTBED_host_get_id_ (starting_host)],
521 sizeof(struct GNUNET_TESTBED_Host *) * count); 523 sizeof(struct GNUNET_TESTBED_Host *) * count);
522 return count; 524 return count;
523} 525}
524 526
@@ -530,7 +532,7 @@ GNUNET_TESTBED_hosts_load_from_file(
530 * @return the string representing the IPv4 address of the given host; NULL upon error 532 * @return the string representing the IPv4 address of the given host; NULL upon error
531 */ 533 */
532const char * 534const char *
533simple_resolve(const char *host) 535simple_resolve (const char *host)
534{ 536{
535 struct addrinfo *res; 537 struct addrinfo *res;
536 const struct sockaddr_in *in_addr; 538 const struct sockaddr_in *in_addr;
@@ -547,20 +549,20 @@ simple_resolve(const char *host)
547 hint.ai_next = NULL; 549 hint.ai_next = NULL;
548 hint.ai_flags = AI_NUMERICSERV; 550 hint.ai_flags = AI_NUMERICSERV;
549 res = NULL; 551 res = NULL;
550 LOG_DEBUG("Resolving [%s]\n", host); 552 LOG_DEBUG ("Resolving [%s]\n", host);
551 if (0 != (rc = getaddrinfo(host, "22", &hint, &res))) 553 if (0 != (rc = getaddrinfo (host, "22", &hint, &res)))
552 { 554 {
553 LOG_GAI(GNUNET_ERROR_TYPE_ERROR, "getaddrinfo", rc); 555 LOG_GAI (GNUNET_ERROR_TYPE_ERROR, "getaddrinfo", rc);
554 return NULL; 556 return NULL;
555 } 557 }
556 GNUNET_assert(NULL != res); 558 GNUNET_assert (NULL != res);
557 GNUNET_assert(NULL != res->ai_addr); 559 GNUNET_assert (NULL != res->ai_addr);
558 GNUNET_assert(sizeof(struct sockaddr_in) == res->ai_addrlen); 560 GNUNET_assert (sizeof(struct sockaddr_in) == res->ai_addrlen);
559 in_addr = (const struct sockaddr_in *)res->ai_addr; 561 in_addr = (const struct sockaddr_in *) res->ai_addr;
560 hostip = inet_ntoa(in_addr->sin_addr); 562 hostip = inet_ntoa (in_addr->sin_addr);
561 GNUNET_assert(NULL != hostip); 563 GNUNET_assert (NULL != hostip);
562 freeaddrinfo(res); 564 freeaddrinfo (res);
563 LOG_DEBUG("Resolved [%s] to [%s]\n", host, hostip); 565 LOG_DEBUG ("Resolved [%s] to [%s]\n", host, hostip);
564 return hostip; 566 return hostip;
565} 567}
566 568
@@ -578,24 +580,24 @@ simple_resolve(const char *host)
578 * @return number of hosts returned in 'hosts', 0 on error 580 * @return number of hosts returned in 'hosts', 0 on error
579 */ 581 */
580unsigned int 582unsigned int
581GNUNET_TESTBED_hosts_load_from_loadleveler( 583GNUNET_TESTBED_hosts_load_from_loadleveler (
582 const struct GNUNET_CONFIGURATION_Handle *cfg, 584 const struct GNUNET_CONFIGURATION_Handle *cfg,
583 struct GNUNET_TESTBED_Host ***hosts) 585 struct GNUNET_TESTBED_Host ***hosts)
584{ 586{
585#if !ENABLE_SUPERMUC 587#if ! ENABLE_SUPERMUC
586 LOG(GNUNET_ERROR_TYPE_ERROR, 588 LOG (GNUNET_ERROR_TYPE_ERROR,
587 _("The function %s is only available when compiled with (--with-ll)\n"), 589 _ ("The function %s is only available when compiled with (--with-ll)\n"),
588 __func__); 590 __func__);
589 GNUNET_assert(0); 591 GNUNET_assert (0);
590#else 592#else
591 const char *hostfile; 593 const char *hostfile;
592 594
593 if (NULL == (hostfile = getenv("MP_SAVEHOSTFILE"))) 595 if (NULL == (hostfile = getenv ("MP_SAVEHOSTFILE")))
594 { 596 {
595 GNUNET_break(0); 597 GNUNET_break (0);
596 return 0; 598 return 0;
597 } 599 }
598 return GNUNET_TESTBED_hosts_load_from_file(hostfile, cfg, hosts); 600 return GNUNET_TESTBED_hosts_load_from_file (hostfile, cfg, hosts);
599#endif 601#endif
600} 602}
601 603
@@ -607,41 +609,41 @@ GNUNET_TESTBED_hosts_load_from_loadleveler(
607 * @param host handle to destroy 609 * @param host handle to destroy
608 */ 610 */
609void 611void
610GNUNET_TESTBED_host_destroy(struct GNUNET_TESTBED_Host *host) 612GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host)
611{ 613{
612 struct RegisteredController *rc; 614 struct RegisteredController *rc;
613 uint32_t id; 615 uint32_t id;
614 616
615 GNUNET_assert(host->id < host_list_size); 617 GNUNET_assert (host->id < host_list_size);
616 GNUNET_assert(host_list[host->id] == host); 618 GNUNET_assert (host_list[host->id] == host);
617 host_list[host->id] = NULL; 619 host_list[host->id] = NULL;
618 /* clear registered controllers list */ 620 /* clear registered controllers list */
619 for (rc = host->rc_head; NULL != rc; rc = host->rc_head) 621 for (rc = host->rc_head; NULL != rc; rc = host->rc_head)
620 { 622 {
621 GNUNET_CONTAINER_DLL_remove(host->rc_head, host->rc_tail, rc); 623 GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc);
622 GNUNET_free(rc); 624 GNUNET_free (rc);
623 } 625 }
624 GNUNET_free_non_null((char *)host->username); 626 GNUNET_free_non_null ((char *) host->username);
625 GNUNET_free_non_null((char *)host->hostname); 627 GNUNET_free_non_null ((char *) host->hostname);
626 GNUNET_TESTBED_operation_queue_destroy_( 628 GNUNET_TESTBED_operation_queue_destroy_ (
627 host->opq_parallel_overlay_connect_operations); 629 host->opq_parallel_overlay_connect_operations);
628 GNUNET_CONFIGURATION_destroy(host->cfg); 630 GNUNET_CONFIGURATION_destroy (host->cfg);
629 GNUNET_free(host); 631 GNUNET_free (host);
630 while (host_list_size >= HOST_LIST_GROW_STEP) 632 while (host_list_size >= HOST_LIST_GROW_STEP)
631 { 633 {
632 for (id = host_list_size - 1; id > host_list_size - HOST_LIST_GROW_STEP; 634 for (id = host_list_size - 1; id > host_list_size - HOST_LIST_GROW_STEP;
633 id--) 635 id--)
634 if (NULL != host_list[id])
635 break;
636 if (id != host_list_size - HOST_LIST_GROW_STEP)
637 break;
638 if (NULL != host_list[id]) 636 if (NULL != host_list[id])
639 break; 637 break;
640 host_list_size -= HOST_LIST_GROW_STEP; 638 if (id != host_list_size - HOST_LIST_GROW_STEP)
641 } 639 break;
640 if (NULL != host_list[id])
641 break;
642 host_list_size -= HOST_LIST_GROW_STEP;
643 }
642 host_list = 644 host_list =
643 GNUNET_realloc(host_list, 645 GNUNET_realloc (host_list,
644 sizeof(struct GNUNET_TESTBED_Host *) * host_list_size); 646 sizeof(struct GNUNET_TESTBED_Host *) * host_list_size);
645} 647}
646 648
647 649
@@ -652,23 +654,23 @@ GNUNET_TESTBED_host_destroy(struct GNUNET_TESTBED_Host *host)
652 * @param controller the controller at which this host is registered 654 * @param controller the controller at which this host is registered
653 */ 655 */
654void 656void
655GNUNET_TESTBED_mark_host_registered_at_( 657GNUNET_TESTBED_mark_host_registered_at_ (
656 struct GNUNET_TESTBED_Host *host, 658 struct GNUNET_TESTBED_Host *host,
657 const struct GNUNET_TESTBED_Controller *const controller) 659 const struct GNUNET_TESTBED_Controller *const controller)
658{ 660{
659 struct RegisteredController *rc; 661 struct RegisteredController *rc;
660 662
661 for (rc = host->rc_head; NULL != rc; rc = rc->next) 663 for (rc = host->rc_head; NULL != rc; rc = rc->next)
664 {
665 if (controller == rc->controller) /* already registered at controller */
662 { 666 {
663 if (controller == rc->controller) /* already registered at controller */ 667 GNUNET_break (0);
664 { 668 return;
665 GNUNET_break(0);
666 return;
667 }
668 } 669 }
669 rc = GNUNET_new(struct RegisteredController); 670 }
671 rc = GNUNET_new (struct RegisteredController);
670 rc->controller = controller; 672 rc->controller = controller;
671 GNUNET_CONTAINER_DLL_insert_tail(host->rc_head, host->rc_tail, rc); 673 GNUNET_CONTAINER_DLL_insert_tail (host->rc_head, host->rc_tail, rc);
672} 674}
673 675
674 676
@@ -679,7 +681,7 @@ GNUNET_TESTBED_mark_host_registered_at_(
679 * @param controller the controller at which this host has to be unmarked 681 * @param controller the controller at which this host has to be unmarked
680 */ 682 */
681void 683void
682GNUNET_TESTBED_deregister_host_at_( 684GNUNET_TESTBED_deregister_host_at_ (
683 struct GNUNET_TESTBED_Host *host, 685 struct GNUNET_TESTBED_Host *host,
684 const struct GNUNET_TESTBED_Controller *const controller) 686 const struct GNUNET_TESTBED_Controller *const controller)
685{ 687{
@@ -689,12 +691,12 @@ GNUNET_TESTBED_deregister_host_at_(
689 if (controller == rc->controller) 691 if (controller == rc->controller)
690 break; 692 break;
691 if (NULL == rc) 693 if (NULL == rc)
692 { 694 {
693 GNUNET_break(0); 695 GNUNET_break (0);
694 return; 696 return;
695 } 697 }
696 GNUNET_CONTAINER_DLL_remove(host->rc_head, host->rc_tail, rc); 698 GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc);
697 GNUNET_free(rc); 699 GNUNET_free (rc);
698} 700}
699 701
700 702
@@ -706,19 +708,19 @@ GNUNET_TESTBED_deregister_host_at_(
706 * @return GNUNET_YES if registered; GNUNET_NO if not 708 * @return GNUNET_YES if registered; GNUNET_NO if not
707 */ 709 */
708int 710int
709GNUNET_TESTBED_is_host_registered_( 711GNUNET_TESTBED_is_host_registered_ (
710 const struct GNUNET_TESTBED_Host *host, 712 const struct GNUNET_TESTBED_Host *host,
711 const struct GNUNET_TESTBED_Controller *const controller) 713 const struct GNUNET_TESTBED_Controller *const controller)
712{ 714{
713 struct RegisteredController *rc; 715 struct RegisteredController *rc;
714 716
715 for (rc = host->rc_head; NULL != rc; rc = rc->next) 717 for (rc = host->rc_head; NULL != rc; rc = rc->next)
718 {
719 if (controller == rc->controller) /* already registered at controller */
716 { 720 {
717 if (controller == rc->controller) /* already registered at controller */ 721 return GNUNET_YES;
718 {
719 return GNUNET_YES;
720 }
721 } 722 }
723 }
722 return GNUNET_NO; 724 return GNUNET_NO;
723} 725}
724 726
@@ -726,7 +728,8 @@ GNUNET_TESTBED_is_host_registered_(
726/** 728/**
727 * Handle for controller process 729 * Handle for controller process
728 */ 730 */
729struct GNUNET_TESTBED_ControllerProc { 731struct GNUNET_TESTBED_ControllerProc
732{
730 /** 733 /**
731 * The process handle 734 * The process handle
732 */ 735 */
@@ -771,17 +774,17 @@ struct GNUNET_TESTBED_ControllerProc {
771 * @return the copied NULL terminated arguments 774 * @return the copied NULL terminated arguments
772 */ 775 */
773static char ** 776static char **
774copy_argv(const char *const *argv) 777copy_argv (const char *const *argv)
775{ 778{
776 char **argv_dup; 779 char **argv_dup;
777 unsigned int argp; 780 unsigned int argp;
778 781
779 GNUNET_assert(NULL != argv); 782 GNUNET_assert (NULL != argv);
780 for (argp = 0; NULL != argv[argp]; argp++) 783 for (argp = 0; NULL != argv[argp]; argp++)
781 ; 784 ;
782 argv_dup = GNUNET_malloc(sizeof(char *) * (argp + 1)); 785 argv_dup = GNUNET_malloc (sizeof(char *) * (argp + 1));
783 for (argp = 0; NULL != argv[argp]; argp++) 786 for (argp = 0; NULL != argv[argp]; argp++)
784 argv_dup[argp] = GNUNET_strdup(argv[argp]); 787 argv_dup[argp] = GNUNET_strdup (argv[argp]);
785 return argv_dup; 788 return argv_dup;
786} 789}
787 790
@@ -794,7 +797,7 @@ copy_argv(const char *const *argv)
794 * @return the joined NULL terminated arguments 797 * @return the joined NULL terminated arguments
795 */ 798 */
796static char ** 799static char **
797join_argv(const char *const *argv1, const char *const *argv2) 800join_argv (const char *const *argv1, const char *const *argv2)
798{ 801{
799 char **argvj; 802 char **argvj;
800 char *argv; 803 char *argv;
@@ -804,16 +807,16 @@ join_argv(const char *const *argv1, const char *const *argv2)
804 carg = 0; 807 carg = 0;
805 argvj = NULL; 808 argvj = NULL;
806 for (cnt = 0; NULL != argv1[cnt]; cnt++) 809 for (cnt = 0; NULL != argv1[cnt]; cnt++)
807 { 810 {
808 argv = GNUNET_strdup(argv1[cnt]); 811 argv = GNUNET_strdup (argv1[cnt]);
809 GNUNET_array_append(argvj, carg, argv); 812 GNUNET_array_append (argvj, carg, argv);
810 } 813 }
811 for (cnt = 0; NULL != argv2[cnt]; cnt++) 814 for (cnt = 0; NULL != argv2[cnt]; cnt++)
812 { 815 {
813 argv = GNUNET_strdup(argv2[cnt]); 816 argv = GNUNET_strdup (argv2[cnt]);
814 GNUNET_array_append(argvj, carg, argv); 817 GNUNET_array_append (argvj, carg, argv);
815 } 818 }
816 GNUNET_array_append(argvj, carg, NULL); 819 GNUNET_array_append (argvj, carg, NULL);
817 return argvj; 820 return argvj;
818} 821}
819 822
@@ -824,13 +827,13 @@ join_argv(const char *const *argv1, const char *const *argv2)
824 * @param argv the NULL terminated list of arguments 827 * @param argv the NULL terminated list of arguments
825 */ 828 */
826static void 829static void
827free_argv(char **argv) 830free_argv (char **argv)
828{ 831{
829 unsigned int argp; 832 unsigned int argp;
830 833
831 for (argp = 0; NULL != argv[argp]; argp++) 834 for (argp = 0; NULL != argv[argp]; argp++)
832 GNUNET_free(argv[argp]); 835 GNUNET_free (argv[argp]);
833 GNUNET_free(argv); 836 GNUNET_free (argv);
834} 837}
835 838
836 839
@@ -849,7 +852,7 @@ free_argv(char **argv)
849 * @return NULL terminated list of arguments 852 * @return NULL terminated list of arguments
850 */ 853 */
851static char ** 854static char **
852gen_rsh_args(const char *port, const char *hostname, const char *username) 855gen_rsh_args (const char *port, const char *hostname, const char *username)
853{ 856{
854 static const char *default_ssh_args[] = 857 static const char *default_ssh_args[] =
855 { "ssh", 858 { "ssh",
@@ -872,48 +875,48 @@ gen_rsh_args(const char *port, const char *hostname, const char *username)
872 unsigned int cnt; 875 unsigned int cnt;
873 876
874 ssh_args = NULL; 877 ssh_args = NULL;
875 if (NULL != (ssh_cmd = getenv("GNUNET_TESTBED_RSH_CMD"))) 878 if (NULL != (ssh_cmd = getenv ("GNUNET_TESTBED_RSH_CMD")))
876 { 879 {
877 ssh_cmd = GNUNET_strdup(ssh_cmd); 880 ssh_cmd = GNUNET_strdup (ssh_cmd);
878 ssh_cmd_cp = ssh_cmd; 881 ssh_cmd_cp = ssh_cmd;
879 for (size = 0; NULL != (arg = strtok(ssh_cmd, " ")); ssh_cmd = NULL) 882 for (size = 0; NULL != (arg = strtok (ssh_cmd, " ")); ssh_cmd = NULL)
880 GNUNET_array_append(ssh_args, size, GNUNET_strdup(arg)); 883 GNUNET_array_append (ssh_args, size, GNUNET_strdup (arg));
881 GNUNET_free(ssh_cmd_cp); 884 GNUNET_free (ssh_cmd_cp);
882 } 885 }
883 else 886 else
884 { 887 {
885 ssh_args = copy_argv(default_ssh_args); 888 ssh_args = copy_argv (default_ssh_args);
886 size = (sizeof(default_ssh_args)) / (sizeof(const char *)); 889 size = (sizeof(default_ssh_args)) / (sizeof(const char *));
887 GNUNET_array_grow(ssh_args, size, size - 1); 890 GNUNET_array_grow (ssh_args, size, size - 1);
888 } 891 }
889 for (cnt = 0; cnt < size; cnt++) 892 for (cnt = 0; cnt < size; cnt++)
893 {
894 arg = ssh_args[cnt];
895 if ('%' != arg[0])
896 continue;
897 switch (arg[1])
890 { 898 {
891 arg = ssh_args[cnt]; 899 case 'p':
892 if ('%' != arg[0]) 900 new_arg = port;
893 continue; 901 break;
894 switch (arg[1]) 902
895 { 903 case 'u':
896 case 'p': 904 new_arg = username;
897 new_arg = port; 905 break;
898 break; 906
899 907 case 'h':
900 case 'u': 908 new_arg = hostname;
901 new_arg = username; 909 break;
902 break; 910
903 911 default:
904 case 'h': 912 continue;
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);
915 } 913 }
916 GNUNET_array_append(ssh_args, size, NULL); 914 if (NULL == new_arg)
915 continue;
916 GNUNET_free (arg);
917 ssh_args[cnt] = GNUNET_strdup (new_arg);
918 }
919 GNUNET_array_append (ssh_args, size, NULL);
917 return ssh_args; 920 return ssh_args;
918} 921}
919 922
@@ -929,7 +932,7 @@ gen_rsh_args(const char *port, const char *hostname, const char *username)
929 * @return NULL-terminated args 932 * @return NULL-terminated args
930 */ 933 */
931static char ** 934static char **
932gen_rsh_suffix_args(const char *const *append_args) 935gen_rsh_suffix_args (const char *const *append_args)
933{ 936{
934 char **rshell_args; 937 char **rshell_args;
935 char *rshell_cmd; 938 char *rshell_cmd;
@@ -940,22 +943,22 @@ gen_rsh_suffix_args(const char *const *append_args)
940 943
941 rshell_args = NULL; 944 rshell_args = NULL;
942 cnt = 0; 945 cnt = 0;
943 if (NULL != (rshell_cmd = getenv("GNUNET_TESTBED_RSH_CMD_SUFFIX"))) 946 if (NULL != (rshell_cmd = getenv ("GNUNET_TESTBED_RSH_CMD_SUFFIX")))
944 { 947 {
945 rshell_cmd = GNUNET_strdup(rshell_cmd); 948 rshell_cmd = GNUNET_strdup (rshell_cmd);
946 rshell_cmd_cp = rshell_cmd; 949 rshell_cmd_cp = rshell_cmd;
947 for (; NULL != (arg = strtok(rshell_cmd, " ")); rshell_cmd = NULL) 950 for (; NULL != (arg = strtok (rshell_cmd, " ")); rshell_cmd = NULL)
948 GNUNET_array_append(rshell_args, cnt, GNUNET_strdup(arg)); 951 GNUNET_array_append (rshell_args, cnt, GNUNET_strdup (arg));
949 GNUNET_free(rshell_cmd_cp); 952 GNUNET_free (rshell_cmd_cp);
950 } 953 }
951 if (NULL != append_args) 954 if (NULL != append_args)
952 { 955 {
953 for (append_cnt = 0; NULL != append_args[append_cnt]; append_cnt++) 956 for (append_cnt = 0; NULL != append_args[append_cnt]; append_cnt++)
954 GNUNET_array_append(rshell_args, 957 GNUNET_array_append (rshell_args,
955 cnt, 958 cnt,
956 GNUNET_strdup(append_args[append_cnt])); 959 GNUNET_strdup (append_args[append_cnt]));
957 } 960 }
958 GNUNET_array_append(rshell_args, cnt, NULL); 961 GNUNET_array_append (rshell_args, cnt, NULL);
959 return rshell_args; 962 return rshell_args;
960} 963}
961 964
@@ -973,7 +976,7 @@ gen_rsh_suffix_args(const char *const *append_args)
973 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 976 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
974 */ 977 */
975static int 978static int
976helper_mst(void *cls, const struct GNUNET_MessageHeader *message) 979helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
977{ 980{
978 struct GNUNET_TESTBED_ControllerProc *cp = cls; 981 struct GNUNET_TESTBED_ControllerProc *cp = cls;
979 const struct GNUNET_TESTBED_HelperReply *msg; 982 const struct GNUNET_TESTBED_HelperReply *msg;
@@ -982,38 +985,38 @@ helper_mst(void *cls, const struct GNUNET_MessageHeader *message)
982 uLongf config_size; 985 uLongf config_size;
983 uLongf xconfig_size; 986 uLongf xconfig_size;
984 987
985 msg = (const struct GNUNET_TESTBED_HelperReply *)message; 988 msg = (const struct GNUNET_TESTBED_HelperReply *) message;
986 GNUNET_assert(sizeof(struct GNUNET_TESTBED_HelperReply) < 989 GNUNET_assert (sizeof(struct GNUNET_TESTBED_HelperReply) <
987 ntohs(msg->header.size)); 990 ntohs (msg->header.size));
988 GNUNET_assert(GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY == 991 GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY ==
989 ntohs(msg->header.type)); 992 ntohs (msg->header.type));
990 config_size = (uLongf)ntohs(msg->config_size); 993 config_size = (uLongf) ntohs (msg->config_size);
991 xconfig_size = (uLongf)(ntohs(msg->header.size) - 994 xconfig_size = (uLongf) (ntohs (msg->header.size)
992 sizeof(struct GNUNET_TESTBED_HelperReply)); 995 - sizeof(struct GNUNET_TESTBED_HelperReply));
993 config = GNUNET_malloc(config_size); 996 config = GNUNET_malloc (config_size);
994 GNUNET_assert(Z_OK == uncompress((Bytef *)config, 997 GNUNET_assert (Z_OK == uncompress ((Bytef *) config,
995 &config_size, 998 &config_size,
996 (const Bytef *)&msg[1], 999 (const Bytef *) &msg[1],
997 xconfig_size)); 1000 xconfig_size));
998 /* Replace the configuration template present in the host with the 1001 /* Replace the configuration template present in the host with the
999 controller's running configuration */ 1002 controller's running configuration */
1000 GNUNET_CONFIGURATION_destroy(cp->host->cfg); 1003 GNUNET_CONFIGURATION_destroy (cp->host->cfg);
1001 cp->host->cfg = GNUNET_CONFIGURATION_create(); 1004 cp->host->cfg = GNUNET_CONFIGURATION_create ();
1002 GNUNET_assert(GNUNET_CONFIGURATION_deserialize(cp->host->cfg, 1005 GNUNET_assert (GNUNET_CONFIGURATION_deserialize (cp->host->cfg,
1003 config, 1006 config,
1004 config_size, 1007 config_size,
1005 NULL)); 1008 NULL));
1006 GNUNET_free(config); 1009 GNUNET_free (config);
1007 if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname(cp->host))) 1010 if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host)))
1008 hostname = "localhost"; 1011 hostname = "localhost";
1009 /* Change the hostname so that we can connect to it */ 1012 /* Change the hostname so that we can connect to it */
1010 GNUNET_CONFIGURATION_set_value_string(cp->host->cfg, 1013 GNUNET_CONFIGURATION_set_value_string (cp->host->cfg,
1011 "testbed", 1014 "testbed",
1012 "hostname", 1015 "hostname",
1013 hostname); 1016 hostname);
1014 cp->host->locked = GNUNET_NO; 1017 cp->host->locked = GNUNET_NO;
1015 cp->host->controller_started = GNUNET_YES; 1018 cp->host->controller_started = GNUNET_YES;
1016 cp->cb(cp->cls, cp->host->cfg, GNUNET_OK); 1019 cp->cb (cp->cls, cp->host->cfg, GNUNET_OK);
1017 return GNUNET_OK; 1020 return GNUNET_OK;
1018} 1021}
1019 1022
@@ -1027,13 +1030,13 @@ helper_mst(void *cls, const struct GNUNET_MessageHeader *message)
1027 * GNUNET_SYSERR during GNUNET_HELPER_stop 1030 * GNUNET_SYSERR during GNUNET_HELPER_stop
1028 */ 1031 */
1029static void 1032static void
1030clear_msg(void *cls, int result) 1033clear_msg (void *cls, int result)
1031{ 1034{
1032 struct GNUNET_TESTBED_ControllerProc *cp = cls; 1035 struct GNUNET_TESTBED_ControllerProc *cp = cls;
1033 1036
1034 GNUNET_assert(NULL != cp->shandle); 1037 GNUNET_assert (NULL != cp->shandle);
1035 cp->shandle = NULL; 1038 cp->shandle = NULL;
1036 GNUNET_free(cp->msg); 1039 GNUNET_free (cp->msg);
1037 cp->msg = NULL; 1040 cp->msg = NULL;
1038} 1041}
1039 1042
@@ -1045,7 +1048,7 @@ clear_msg(void *cls, int result)
1045 * @param cls the closure from GNUNET_HELPER_start() 1048 * @param cls the closure from GNUNET_HELPER_start()
1046 */ 1049 */
1047static void 1050static void
1048helper_exp_cb(void *cls) 1051helper_exp_cb (void *cls)
1049{ 1052{
1050 struct GNUNET_TESTBED_ControllerProc *cp = cls; 1053 struct GNUNET_TESTBED_ControllerProc *cp = cls;
1051 GNUNET_TESTBED_ControllerStatusCallback cb; 1054 GNUNET_TESTBED_ControllerStatusCallback cb;
@@ -1054,9 +1057,9 @@ helper_exp_cb(void *cls)
1054 cb = cp->cb; 1057 cb = cp->cb;
1055 cb_cls = cp->cls; 1058 cb_cls = cp->cls;
1056 cp->helper = NULL; 1059 cp->helper = NULL;
1057 GNUNET_TESTBED_controller_stop(cp); 1060 GNUNET_TESTBED_controller_stop (cp);
1058 if (NULL != cb) 1061 if (NULL != cb)
1059 cb(cb_cls, NULL, GNUNET_SYSERR); 1062 cb (cb_cls, NULL, GNUNET_SYSERR);
1060} 1063}
1061 1064
1062 1065
@@ -1084,10 +1087,10 @@ helper_exp_cb(void *cls)
1084 * @return the controller process handle, NULL on errors 1087 * @return the controller process handle, NULL on errors
1085 */ 1088 */
1086struct GNUNET_TESTBED_ControllerProc * 1089struct GNUNET_TESTBED_ControllerProc *
1087GNUNET_TESTBED_controller_start(const char *trusted_ip, 1090GNUNET_TESTBED_controller_start (const char *trusted_ip,
1088 struct GNUNET_TESTBED_Host *host, 1091 struct GNUNET_TESTBED_Host *host,
1089 GNUNET_TESTBED_ControllerStatusCallback cb, 1092 GNUNET_TESTBED_ControllerStatusCallback cb,
1090 void *cls) 1093 void *cls)
1091{ 1094{
1092 struct GNUNET_TESTBED_ControllerProc *cp; 1095 struct GNUNET_TESTBED_ControllerProc *cp;
1093 struct GNUNET_TESTBED_HelperInit *msg; 1096 struct GNUNET_TESTBED_HelperInit *msg;
@@ -1095,95 +1098,95 @@ GNUNET_TESTBED_controller_start(const char *trusted_ip,
1095 const char *hostname; 1098 const char *hostname;
1096 static char *const binary_argv[] = { HELPER_TESTBED_BINARY, NULL }; 1099 static char *const binary_argv[] = { HELPER_TESTBED_BINARY, NULL };
1097 1100
1098 GNUNET_assert(NULL != host); 1101 GNUNET_assert (NULL != host);
1099 GNUNET_assert(NULL != (cfg = GNUNET_TESTBED_host_get_cfg_(host))); 1102 GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host)));
1100 hostname = NULL; 1103 hostname = NULL;
1101 API_VIOLATION( 1104 API_VIOLATION (
1102 GNUNET_NO == host->locked, 1105 GNUNET_NO == host->locked,
1103 "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()"); 1106 "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()");
1104 host->locked = GNUNET_YES; 1107 host->locked = GNUNET_YES;
1105 API_VIOLATION( 1108 API_VIOLATION (
1106 GNUNET_NO == host->controller_started, 1109 GNUNET_NO == host->controller_started,
1107 "Attempting to start a controller on a host which is already started a controller"); 1110 "Attempting to start a controller on a host which is already started a controller");
1108 cp = GNUNET_new(struct GNUNET_TESTBED_ControllerProc); 1111 cp = GNUNET_new (struct GNUNET_TESTBED_ControllerProc);
1109 if (0 == GNUNET_TESTBED_host_get_id_(host)) 1112 if (0 == GNUNET_TESTBED_host_get_id_ (host))
1110 { 1113 {
1111 cp->helper = GNUNET_HELPER_start(GNUNET_YES, 1114 cp->helper = GNUNET_HELPER_start (GNUNET_YES,
1112 HELPER_TESTBED_BINARY, 1115 HELPER_TESTBED_BINARY,
1113 binary_argv, 1116 binary_argv,
1114 &helper_mst, 1117 &helper_mst,
1115 &helper_exp_cb, 1118 &helper_exp_cb,
1116 cp); 1119 cp);
1117 } 1120 }
1118 else 1121 else
1122 {
1123 char *helper_binary_path_args[2];
1124 char **rsh_args;
1125 char **rsh_suffix_args;
1126 const char *username;
1127 char *port;
1128 char *argstr;
1129 char *aux;
1130 unsigned int cnt;
1131
1132 username = host->username;
1133 hostname = host->hostname;
1134 GNUNET_asprintf (&port, "%u", host->port);
1135 LOG_DEBUG ("Starting remote connection to destination %s\n", hostname);
1136 if (GNUNET_OK !=
1137 GNUNET_CONFIGURATION_get_value_filename (cfg,
1138 "testbed",
1139 "HELPER_BINARY_PATH",
1140 &helper_binary_path_args[0]))
1141 helper_binary_path_args[0] =
1142 GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
1143 helper_binary_path_args[1] = NULL;
1144 rsh_args = gen_rsh_args (port, hostname, username);
1145 rsh_suffix_args =
1146 gen_rsh_suffix_args ((const char **) helper_binary_path_args);
1147 cp->helper_argv =
1148 join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args);
1149 free_argv (rsh_args);
1150 free_argv (rsh_suffix_args);
1151 GNUNET_free (port);
1152 argstr = GNUNET_strdup ("");
1153 for (cnt = 0; NULL != cp->helper_argv[cnt]; cnt++)
1119 { 1154 {
1120 char *helper_binary_path_args[2]; 1155 aux = argstr;
1121 char **rsh_args; 1156 GNUNET_assert (
1122 char **rsh_suffix_args; 1157 0 < GNUNET_asprintf (&argstr, "%s %s", aux, cp->helper_argv[cnt]));
1123 const char *username; 1158 GNUNET_free (aux);
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]);
1166 } 1159 }
1160 LOG_DEBUG ("Helper cmd str: %s\n", argstr);
1161 GNUNET_free (argstr);
1162 cp->helper = GNUNET_HELPER_start (GNUNET_NO,
1163 cp->helper_argv[0],
1164 cp->helper_argv,
1165 &helper_mst,
1166 &helper_exp_cb,
1167 cp);
1168 GNUNET_free (helper_binary_path_args[0]);
1169 }
1167 if (NULL == cp->helper) 1170 if (NULL == cp->helper)
1168 { 1171 {
1169 if (NULL != cp->helper_argv) 1172 if (NULL != cp->helper_argv)
1170 free_argv(cp->helper_argv); 1173 free_argv (cp->helper_argv);
1171 GNUNET_free(cp); 1174 GNUNET_free (cp);
1172 return NULL; 1175 return NULL;
1173 } 1176 }
1174 cp->host = host; 1177 cp->host = host;
1175 cp->cb = cb; 1178 cp->cb = cb;
1176 cp->cls = cls; 1179 cp->cls = cls;
1177 msg = GNUNET_TESTBED_create_helper_init_msg_(trusted_ip, hostname, cfg); 1180 msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, hostname, cfg);
1178 cp->msg = &msg->header; 1181 cp->msg = &msg->header;
1179 cp->shandle = 1182 cp->shandle =
1180 GNUNET_HELPER_send(cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp); 1183 GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp);
1181 if (NULL == cp->shandle) 1184 if (NULL == cp->shandle)
1182 { 1185 {
1183 GNUNET_free(msg); 1186 GNUNET_free (msg);
1184 GNUNET_TESTBED_controller_stop(cp); 1187 GNUNET_TESTBED_controller_stop (cp);
1185 return NULL; 1188 return NULL;
1186 } 1189 }
1187 return cp; 1190 return cp;
1188} 1191}
1189 1192
@@ -1194,12 +1197,12 @@ GNUNET_TESTBED_controller_start(const char *trusted_ip,
1194 * @param cproc the handle to the controller's helper process 1197 * @param cproc the handle to the controller's helper process
1195 */ 1198 */
1196void 1199void
1197GNUNET_TESTBED_controller_kill_(struct GNUNET_TESTBED_ControllerProc *cproc) 1200GNUNET_TESTBED_controller_kill_ (struct GNUNET_TESTBED_ControllerProc *cproc)
1198{ 1201{
1199 if (NULL != cproc->shandle) 1202 if (NULL != cproc->shandle)
1200 GNUNET_HELPER_send_cancel(cproc->shandle); 1203 GNUNET_HELPER_send_cancel (cproc->shandle);
1201 if (NULL != cproc->helper) 1204 if (NULL != cproc->helper)
1202 GNUNET_HELPER_kill(cproc->helper, GNUNET_YES); 1205 GNUNET_HELPER_kill (cproc->helper, GNUNET_YES);
1203} 1206}
1204 1207
1205 1208
@@ -1209,19 +1212,19 @@ GNUNET_TESTBED_controller_kill_(struct GNUNET_TESTBED_ControllerProc *cproc)
1209 * @param cproc the handle to the controller's helper process 1212 * @param cproc the handle to the controller's helper process
1210 */ 1213 */
1211void 1214void
1212GNUNET_TESTBED_controller_destroy_(struct GNUNET_TESTBED_ControllerProc *cproc) 1215GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc *cproc)
1213{ 1216{
1214 if (NULL != cproc->helper) 1217 if (NULL != cproc->helper)
1215 { 1218 {
1216 GNUNET_break(GNUNET_OK == GNUNET_HELPER_wait(cproc->helper)); 1219 GNUNET_break (GNUNET_OK == GNUNET_HELPER_wait (cproc->helper));
1217 GNUNET_HELPER_destroy(cproc->helper); 1220 GNUNET_HELPER_destroy (cproc->helper);
1218 } 1221 }
1219 if (NULL != cproc->helper_argv) 1222 if (NULL != cproc->helper_argv)
1220 free_argv(cproc->helper_argv); 1223 free_argv (cproc->helper_argv);
1221 cproc->host->controller_started = GNUNET_NO; 1224 cproc->host->controller_started = GNUNET_NO;
1222 cproc->host->locked = GNUNET_NO; 1225 cproc->host->locked = GNUNET_NO;
1223 GNUNET_free_non_null(cproc->msg); 1226 GNUNET_free_non_null (cproc->msg);
1224 GNUNET_free(cproc); 1227 GNUNET_free (cproc);
1225} 1228}
1226 1229
1227 1230
@@ -1234,17 +1237,18 @@ GNUNET_TESTBED_controller_destroy_(struct GNUNET_TESTBED_ControllerProc *cproc)
1234 * @param cproc the controller process handle 1237 * @param cproc the controller process handle
1235 */ 1238 */
1236void 1239void
1237GNUNET_TESTBED_controller_stop(struct GNUNET_TESTBED_ControllerProc *cproc) 1240GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc)
1238{ 1241{
1239 GNUNET_TESTBED_controller_kill_(cproc); 1242 GNUNET_TESTBED_controller_kill_ (cproc);
1240 GNUNET_TESTBED_controller_destroy_(cproc); 1243 GNUNET_TESTBED_controller_destroy_ (cproc);
1241} 1244}
1242 1245
1243 1246
1244/** 1247/**
1245 * The handle for whether a host is habitable or not 1248 * The handle for whether a host is habitable or not
1246 */ 1249 */
1247struct GNUNET_TESTBED_HostHabitableCheckHandle { 1250struct GNUNET_TESTBED_HostHabitableCheckHandle
1251{
1248 /** 1252 /**
1249 * The host to check 1253 * The host to check
1250 */ 1254 */
@@ -1289,7 +1293,7 @@ struct GNUNET_TESTBED_HostHabitableCheckHandle {
1289 * @param cls GNUNET_TESTBED_HostHabitableCheckHandle 1293 * @param cls GNUNET_TESTBED_HostHabitableCheckHandle
1290 */ 1294 */
1291static void 1295static void
1292habitability_check(void *cls) 1296habitability_check (void *cls)
1293{ 1297{
1294 struct GNUNET_TESTBED_HostHabitableCheckHandle *h = cls; 1298 struct GNUNET_TESTBED_HostHabitableCheckHandle *h = cls;
1295 void *cb_cls; 1299 void *cb_cls;
@@ -1300,34 +1304,34 @@ habitability_check(void *cls)
1300 int ret; 1304 int ret;
1301 1305
1302 h->habitability_check_task = NULL; 1306 h->habitability_check_task = NULL;
1303 ret = GNUNET_OS_process_status(h->auxp, &type, &code); 1307 ret = GNUNET_OS_process_status (h->auxp, &type, &code);
1304 if (GNUNET_SYSERR == ret) 1308 if (GNUNET_SYSERR == ret)
1305 { 1309 {
1306 GNUNET_break(0); 1310 GNUNET_break (0);
1307 ret = GNUNET_NO; 1311 ret = GNUNET_NO;
1308 goto call_cb; 1312 goto call_cb;
1309 } 1313 }
1310 if (GNUNET_NO == ret) 1314 if (GNUNET_NO == ret)
1311 { 1315 {
1312 h->wait_time = GNUNET_TIME_STD_BACKOFF(h->wait_time); 1316 h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time);
1313 h->habitability_check_task = 1317 h->habitability_check_task =
1314 GNUNET_SCHEDULER_add_delayed(h->wait_time, &habitability_check, h); 1318 GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h);
1315 return; 1319 return;
1316 } 1320 }
1317 GNUNET_OS_process_destroy(h->auxp); 1321 GNUNET_OS_process_destroy (h->auxp);
1318 h->auxp = NULL; 1322 h->auxp = NULL;
1319 ret = (0 != code) ? GNUNET_NO : GNUNET_YES; 1323 ret = (0 != code) ? GNUNET_NO : GNUNET_YES;
1320 1324
1321call_cb: 1325call_cb:
1322 if (NULL != h->auxp) 1326 if (NULL != h->auxp)
1323 GNUNET_OS_process_destroy(h->auxp); 1327 GNUNET_OS_process_destroy (h->auxp);
1324 cb = h->cb; 1328 cb = h->cb;
1325 cb_cls = h->cb_cls; 1329 cb_cls = h->cb_cls;
1326 host = h->host; 1330 host = h->host;
1327 free_argv(h->helper_argv); 1331 free_argv (h->helper_argv);
1328 GNUNET_free(h); 1332 GNUNET_free (h);
1329 if (NULL != cb) 1333 if (NULL != cb)
1330 cb(cb_cls, host, ret); 1334 cb (cb_cls, host, ret);
1331} 1335}
1332 1336
1333 1337
@@ -1343,7 +1347,7 @@ call_cb:
1343 * GNUNET_TESTBED_is_host_habitable_cancel() 1347 * GNUNET_TESTBED_is_host_habitable_cancel()
1344 */ 1348 */
1345struct GNUNET_TESTBED_HostHabitableCheckHandle * 1349struct GNUNET_TESTBED_HostHabitableCheckHandle *
1346GNUNET_TESTBED_is_host_habitable( 1350GNUNET_TESTBED_is_host_habitable (
1347 const struct GNUNET_TESTBED_Host *host, 1351 const struct GNUNET_TESTBED_Host *host,
1348 const struct GNUNET_CONFIGURATION_Handle *config, 1352 const struct GNUNET_CONFIGURATION_Handle *config,
1349 GNUNET_TESTBED_HostHabitableCallback cb, 1353 GNUNET_TESTBED_HostHabitableCallback cb,
@@ -1356,45 +1360,45 @@ GNUNET_TESTBED_is_host_habitable(
1356 const char *hostname; 1360 const char *hostname;
1357 char *port; 1361 char *port;
1358 1362
1359 h = GNUNET_new(struct GNUNET_TESTBED_HostHabitableCheckHandle); 1363 h = GNUNET_new (struct GNUNET_TESTBED_HostHabitableCheckHandle);
1360 h->cb = cb; 1364 h->cb = cb;
1361 h->cb_cls = cb_cls; 1365 h->cb_cls = cb_cls;
1362 h->host = host; 1366 h->host = host;
1363 hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname; 1367 hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname;
1364 if (GNUNET_OK != 1368 if (GNUNET_OK !=
1365 GNUNET_CONFIGURATION_get_value_filename(config, 1369 GNUNET_CONFIGURATION_get_value_filename (config,
1366 "testbed", 1370 "testbed",
1367 "HELPER_BINARY_PATH", 1371 "HELPER_BINARY_PATH",
1368 &stat_args[1])) 1372 &stat_args[1]))
1369 stat_args[1] = GNUNET_OS_get_libexec_binary_path(HELPER_TESTBED_BINARY); 1373 stat_args[1] = GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
1370 GNUNET_asprintf(&port, "%u", host->port); 1374 GNUNET_asprintf (&port, "%u", host->port);
1371 rsh_args = gen_rsh_args(port, hostname, host->username); 1375 rsh_args = gen_rsh_args (port, hostname, host->username);
1372 GNUNET_free(port); 1376 GNUNET_free (port);
1373 port = NULL; 1377 port = NULL;
1374 stat_args[0] = "stat"; 1378 stat_args[0] = "stat";
1375 stat_args[2] = NULL; 1379 stat_args[2] = NULL;
1376 rsh_suffix_args = gen_rsh_suffix_args((const char **)stat_args); 1380 rsh_suffix_args = gen_rsh_suffix_args ((const char **) stat_args);
1377 GNUNET_free(stat_args[1]); 1381 GNUNET_free (stat_args[1]);
1378 h->helper_argv = 1382 h->helper_argv =
1379 join_argv((const char **)rsh_args, (const char **)rsh_suffix_args); 1383 join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args);
1380 free_argv(rsh_suffix_args); 1384 free_argv (rsh_suffix_args);
1381 free_argv(rsh_args); 1385 free_argv (rsh_args);
1382 h->auxp = GNUNET_OS_start_process_vap(GNUNET_NO, 1386 h->auxp = GNUNET_OS_start_process_vap (GNUNET_NO,
1383 GNUNET_OS_INHERIT_STD_ERR, 1387 GNUNET_OS_INHERIT_STD_ERR,
1384 NULL, 1388 NULL,
1385 NULL, 1389 NULL,
1386 NULL, 1390 NULL,
1387 h->helper_argv[0], 1391 h->helper_argv[0],
1388 h->helper_argv); 1392 h->helper_argv);
1389 if (NULL == h->auxp) 1393 if (NULL == h->auxp)
1390 { 1394 {
1391 GNUNET_break(0); /* Cannot exec SSH? */ 1395 GNUNET_break (0); /* Cannot exec SSH? */
1392 GNUNET_free(h); 1396 GNUNET_free (h);
1393 return NULL; 1397 return NULL;
1394 } 1398 }
1395 h->wait_time = GNUNET_TIME_STD_BACKOFF(h->wait_time); 1399 h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time);
1396 h->habitability_check_task = 1400 h->habitability_check_task =
1397 GNUNET_SCHEDULER_add_delayed(h->wait_time, &habitability_check, h); 1401 GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h);
1398 return h; 1402 return h;
1399} 1403}
1400 1404
@@ -1405,15 +1409,15 @@ GNUNET_TESTBED_is_host_habitable(
1405 * @param handle the habitability check handle 1409 * @param handle the habitability check handle
1406 */ 1410 */
1407void 1411void
1408GNUNET_TESTBED_is_host_habitable_cancel( 1412GNUNET_TESTBED_is_host_habitable_cancel (
1409 struct GNUNET_TESTBED_HostHabitableCheckHandle *handle) 1413 struct GNUNET_TESTBED_HostHabitableCheckHandle *handle)
1410{ 1414{
1411 GNUNET_SCHEDULER_cancel(handle->habitability_check_task); 1415 GNUNET_SCHEDULER_cancel (handle->habitability_check_task);
1412 (void)GNUNET_OS_process_kill(handle->auxp, GNUNET_TERM_SIG); 1416 (void) GNUNET_OS_process_kill (handle->auxp, GNUNET_TERM_SIG);
1413 (void)GNUNET_OS_process_wait(handle->auxp); 1417 (void) GNUNET_OS_process_wait (handle->auxp);
1414 GNUNET_OS_process_destroy(handle->auxp); 1418 GNUNET_OS_process_destroy (handle->auxp);
1415 free_argv(handle->helper_argv); 1419 free_argv (handle->helper_argv);
1416 GNUNET_free(handle); 1420 GNUNET_free (handle);
1417} 1421}
1418 1422
1419 1423
@@ -1430,10 +1434,10 @@ GNUNET_TESTBED_is_host_habitable_cancel(
1430 * registration 1434 * registration
1431 */ 1435 */
1432struct GNUNET_TESTBED_HostRegistrationHandle * 1436struct GNUNET_TESTBED_HostRegistrationHandle *
1433GNUNET_TESTBED_register_host(struct GNUNET_TESTBED_Controller *controller, 1437GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
1434 struct GNUNET_TESTBED_Host *host, 1438 struct GNUNET_TESTBED_Host *host,
1435 GNUNET_TESTBED_HostRegistrationCompletion cc, 1439 GNUNET_TESTBED_HostRegistrationCompletion cc,
1436 void *cc_cls) 1440 void *cc_cls)
1437{ 1441{
1438 struct GNUNET_TESTBED_HostRegistrationHandle *rh; 1442 struct GNUNET_TESTBED_HostRegistrationHandle *rh;
1439 struct GNUNET_TESTBED_AddHostMessage *msg; 1443 struct GNUNET_TESTBED_AddHostMessage *msg;
@@ -1450,57 +1454,57 @@ GNUNET_TESTBED_register_host(struct GNUNET_TESTBED_Controller *controller,
1450 1454
1451 if (NULL != controller->rh) 1455 if (NULL != controller->rh)
1452 return NULL; 1456 return NULL;
1453 hostname = GNUNET_TESTBED_host_get_hostname(host); 1457 hostname = GNUNET_TESTBED_host_get_hostname (host);
1454 if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_(host, controller)) 1458 if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_ (host, controller))
1455 { 1459 {
1456 LOG(GNUNET_ERROR_TYPE_WARNING, 1460 LOG (GNUNET_ERROR_TYPE_WARNING,
1457 "Host hostname: %s already registered\n", 1461 "Host hostname: %s already registered\n",
1458 (NULL == hostname) ? "localhost" : hostname); 1462 (NULL == hostname) ? "localhost" : hostname);
1459 return NULL; 1463 return NULL;
1460 } 1464 }
1461 rh = GNUNET_new(struct GNUNET_TESTBED_HostRegistrationHandle); 1465 rh = GNUNET_new (struct GNUNET_TESTBED_HostRegistrationHandle);
1462 rh->host = host; 1466 rh->host = host;
1463 rh->c = controller; 1467 rh->c = controller;
1464 GNUNET_assert(NULL != cc); 1468 GNUNET_assert (NULL != cc);
1465 rh->cc = cc; 1469 rh->cc = cc;
1466 rh->cc_cls = cc_cls; 1470 rh->cc_cls = cc_cls;
1467 controller->rh = rh; 1471 controller->rh = rh;
1468 username = GNUNET_TESTBED_host_get_username_(host); 1472 username = GNUNET_TESTBED_host_get_username_ (host);
1469 username_length = 0; 1473 username_length = 0;
1470 if (NULL != username) 1474 if (NULL != username)
1471 username_length = strlen(username); 1475 username_length = strlen (username);
1472 GNUNET_assert(NULL != hostname); /* Hostname must be present */ 1476 GNUNET_assert (NULL != hostname); /* Hostname must be present */
1473 hostname_length = strlen(hostname); 1477 hostname_length = strlen (hostname);
1474 GNUNET_assert(NULL != host->cfg); 1478 GNUNET_assert (NULL != host->cfg);
1475 config = GNUNET_CONFIGURATION_serialize(host->cfg, &config_size); 1479 config = GNUNET_CONFIGURATION_serialize (host->cfg, &config_size);
1476 cc_size = GNUNET_TESTBED_compress_config_(config, config_size, &cconfig); 1480 cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig);
1477 GNUNET_free(config); 1481 GNUNET_free (config);
1478 msg_size = (sizeof(struct GNUNET_TESTBED_AddHostMessage)); 1482 msg_size = (sizeof(struct GNUNET_TESTBED_AddHostMessage));
1479 msg_size += username_length; 1483 msg_size += username_length;
1480 msg_size += hostname_length; 1484 msg_size += hostname_length;
1481 msg_size += cc_size; 1485 msg_size += cc_size;
1482 msg = GNUNET_malloc(msg_size); 1486 msg = GNUNET_malloc (msg_size);
1483 msg->header.size = htons(msg_size); 1487 msg->header.size = htons (msg_size);
1484 msg->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST); 1488 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST);
1485 msg->host_id = htonl(GNUNET_TESTBED_host_get_id_(host)); 1489 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
1486 msg->ssh_port = htons(GNUNET_TESTBED_host_get_ssh_port_(host)); 1490 msg->ssh_port = htons (GNUNET_TESTBED_host_get_ssh_port_ (host));
1487 ptr = &msg[1]; 1491 ptr = &msg[1];
1488 if (NULL != username) 1492 if (NULL != username)
1489 { 1493 {
1490 msg->username_length = htons(username_length); 1494 msg->username_length = htons (username_length);
1491 GNUNET_memcpy(ptr, username, username_length); 1495 GNUNET_memcpy (ptr, username, username_length);
1492 ptr += username_length; 1496 ptr += username_length;
1493 } 1497 }
1494 msg->hostname_length = htons(hostname_length); 1498 msg->hostname_length = htons (hostname_length);
1495 GNUNET_memcpy(ptr, hostname, hostname_length); 1499 GNUNET_memcpy (ptr, hostname, hostname_length);
1496 ptr += hostname_length; 1500 ptr += hostname_length;
1497 msg->config_size = htons(config_size); 1501 msg->config_size = htons (config_size);
1498 GNUNET_memcpy(ptr, cconfig, cc_size); 1502 GNUNET_memcpy (ptr, cconfig, cc_size);
1499 ptr += cc_size; 1503 ptr += cc_size;
1500 GNUNET_assert((ptr - (void *)msg) == msg_size); 1504 GNUNET_assert ((ptr - (void *) msg) == msg_size);
1501 GNUNET_free(cconfig); 1505 GNUNET_free (cconfig);
1502 GNUNET_TESTBED_queue_message_(controller, 1506 GNUNET_TESTBED_queue_message_ (controller,
1503 (struct GNUNET_MessageHeader *)msg); 1507 (struct GNUNET_MessageHeader *) msg);
1504 return rh; 1508 return rh;
1505} 1509}
1506 1510
@@ -1513,16 +1517,16 @@ GNUNET_TESTBED_register_host(struct GNUNET_TESTBED_Controller *controller,
1513 * @param handle the registration handle to cancel 1517 * @param handle the registration handle to cancel
1514 */ 1518 */
1515void 1519void
1516GNUNET_TESTBED_cancel_registration( 1520GNUNET_TESTBED_cancel_registration (
1517 struct GNUNET_TESTBED_HostRegistrationHandle *handle) 1521 struct GNUNET_TESTBED_HostRegistrationHandle *handle)
1518{ 1522{
1519 if (handle != handle->c->rh) 1523 if (handle != handle->c->rh)
1520 { 1524 {
1521 GNUNET_break(0); 1525 GNUNET_break (0);
1522 return; 1526 return;
1523 } 1527 }
1524 handle->c->rh = NULL; 1528 handle->c->rh = NULL;
1525 GNUNET_free(handle); 1529 GNUNET_free (handle);
1526} 1530}
1527 1531
1528 1532
@@ -1535,11 +1539,12 @@ GNUNET_TESTBED_cancel_registration(
1535 * queue 1539 * queue
1536 */ 1540 */
1537void 1541void
1538GNUNET_TESTBED_host_queue_oc_(struct GNUNET_TESTBED_Host *h, 1542GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h,
1539 struct GNUNET_TESTBED_Operation *op) 1543 struct GNUNET_TESTBED_Operation *op)
1540{ 1544{
1541 GNUNET_TESTBED_operation_queue_insert_(h->opq_parallel_overlay_connect_operations, 1545 GNUNET_TESTBED_operation_queue_insert_ (
1542 op); 1546 h->opq_parallel_overlay_connect_operations,
1547 op);
1543} 1548}
1544 1549
1545 1550
@@ -1549,20 +1554,20 @@ GNUNET_TESTBED_host_queue_oc_(struct GNUNET_TESTBED_Host *h,
1549 * @param host the host whose hostname is to be resolved 1554 * @param host the host whose hostname is to be resolved
1550 */ 1555 */
1551void 1556void
1552GNUNET_TESTBED_host_resolve_(struct GNUNET_TESTBED_Host *host) 1557GNUNET_TESTBED_host_resolve_ (struct GNUNET_TESTBED_Host *host)
1553{ 1558{
1554 char *hostname; 1559 char *hostname;
1555 1560
1556 hostname = (char *)host->hostname; 1561 hostname = (char *) host->hostname;
1557 host->hostname = simple_resolve(hostname); 1562 host->hostname = simple_resolve (hostname);
1558 if (NULL == host->hostname) 1563 if (NULL == host->hostname)
1559 { 1564 {
1560 GNUNET_break(0); 1565 GNUNET_break (0);
1561 host->hostname = hostname; 1566 host->hostname = hostname;
1562 return; 1567 return;
1563 } 1568 }
1564 GNUNET_free(hostname); 1569 GNUNET_free (hostname);
1565 host->hostname = GNUNET_strdup(host->hostname); 1570 host->hostname = GNUNET_strdup (host->hostname);
1566} 1571}
1567 1572
1568/* end of testbed_api_hosts.c */ 1573/* end of testbed_api_hosts.c */
diff --git a/src/testbed/testbed_api_hosts.h b/src/testbed/testbed_api_hosts.h
index 369a6da1b..9b19eb8ec 100644
--- a/src/testbed/testbed_api_hosts.h
+++ b/src/testbed/testbed_api_hosts.h
@@ -27,15 +27,16 @@
27#ifndef TESTBED_API_HOSTS_H 27#ifndef TESTBED_API_HOSTS_H
28#define TESTBED_API_HOSTS_H 28#define TESTBED_API_HOSTS_H
29 29
30//#include "gnunet_testbed_service.h" 30// #include "gnunet_testbed_service.h"
31//#include "testbed_helper.h" 31// #include "testbed_helper.h"
32#include "testbed.h" 32#include "testbed.h"
33 33
34 34
35/** 35/**
36 * handle for host registration 36 * handle for host registration
37 */ 37 */
38struct GNUNET_TESTBED_HostRegistrationHandle { 38struct GNUNET_TESTBED_HostRegistrationHandle
39{
39 /** 40 /**
40 * The host being registered 41 * The host being registered
41 */ 42 */
@@ -66,7 +67,7 @@ struct GNUNET_TESTBED_HostRegistrationHandle {
66 * @return handle to the host, NULL on error 67 * @return handle to the host, NULL on error
67 */ 68 */
68struct GNUNET_TESTBED_Host * 69struct GNUNET_TESTBED_Host *
69GNUNET_TESTBED_host_lookup_by_id_(uint32_t id); 70GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id);
70 71
71 72
72/** 73/**
@@ -82,9 +83,9 @@ GNUNET_TESTBED_host_lookup_by_id_(uint32_t id);
82 * @return handle to the host, NULL on error 83 * @return handle to the host, NULL on error
83 */ 84 */
84struct GNUNET_TESTBED_Host * 85struct GNUNET_TESTBED_Host *
85GNUNET_TESTBED_host_create_by_id_(uint32_t id, 86GNUNET_TESTBED_host_create_by_id_ (uint32_t id,
86 const struct GNUNET_CONFIGURATION_Handle 87 const struct GNUNET_CONFIGURATION_Handle
87 *cfg); 88 *cfg);
88 89
89 90
90/** 91/**
@@ -95,7 +96,7 @@ GNUNET_TESTBED_host_create_by_id_(uint32_t id,
95 * 'localhost', but then obviously not globally unique) 96 * 'localhost', but then obviously not globally unique)
96 */ 97 */
97uint32_t 98uint32_t
98GNUNET_TESTBED_host_get_id_(const struct GNUNET_TESTBED_Host *host); 99GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host);
99 100
100 101
101/** 102/**
@@ -105,7 +106,7 @@ GNUNET_TESTBED_host_get_id_(const struct GNUNET_TESTBED_Host *host);
105 * @return username to login to the host 106 * @return username to login to the host
106 */ 107 */
107const char * 108const char *
108GNUNET_TESTBED_host_get_username_(const struct GNUNET_TESTBED_Host *host); 109GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host);
109 110
110 111
111/** 112/**
@@ -115,7 +116,7 @@ GNUNET_TESTBED_host_get_username_(const struct GNUNET_TESTBED_Host *host);
115 * @return username to login to the host 116 * @return username to login to the host
116 */ 117 */
117uint16_t 118uint16_t
118GNUNET_TESTBED_host_get_ssh_port_(const struct GNUNET_TESTBED_Host *host); 119GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host);
119 120
120 121
121/** 122/**
@@ -125,7 +126,7 @@ GNUNET_TESTBED_host_get_ssh_port_(const struct GNUNET_TESTBED_Host *host);
125 * @return the host's configuration template 126 * @return the host's configuration template
126 */ 127 */
127const struct GNUNET_CONFIGURATION_Handle * 128const struct GNUNET_CONFIGURATION_Handle *
128GNUNET_TESTBED_host_get_cfg_(const struct GNUNET_TESTBED_Host *host); 129GNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host);
129 130
130 131
131/** 132/**
@@ -135,8 +136,9 @@ GNUNET_TESTBED_host_get_cfg_(const struct GNUNET_TESTBED_Host *host);
135 * @param new_cfg the new configuration to replace the old one 136 * @param new_cfg the new configuration to replace the old one
136 */ 137 */
137void 138void
138GNUNET_TESTBED_host_replace_cfg_(struct GNUNET_TESTBED_Host *host, 139GNUNET_TESTBED_host_replace_cfg_ (struct GNUNET_TESTBED_Host *host,
139 const struct GNUNET_CONFIGURATION_Handle *new_cfg); 140 const struct
141 GNUNET_CONFIGURATION_Handle *new_cfg);
140 142
141 143
142/** 144/**
@@ -146,9 +148,9 @@ GNUNET_TESTBED_host_replace_cfg_(struct GNUNET_TESTBED_Host *host,
146 * @param controller the controller at which this host is registered 148 * @param controller the controller at which this host is registered
147 */ 149 */
148void 150void
149GNUNET_TESTBED_mark_host_registered_at_(struct GNUNET_TESTBED_Host *host, 151GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host,
150 const struct GNUNET_TESTBED_Controller 152 const struct GNUNET_TESTBED_Controller
151 *controller); 153 *controller);
152 154
153 155
154/** 156/**
@@ -158,9 +160,9 @@ GNUNET_TESTBED_mark_host_registered_at_(struct GNUNET_TESTBED_Host *host,
158 * @param controller the controller at which this host has to be unmarked 160 * @param controller the controller at which this host has to be unmarked
159 */ 161 */
160void 162void
161GNUNET_TESTBED_deregister_host_at_(struct GNUNET_TESTBED_Host *host, 163GNUNET_TESTBED_deregister_host_at_ (struct GNUNET_TESTBED_Host *host,
162 const struct GNUNET_TESTBED_Controller 164 const struct GNUNET_TESTBED_Controller
163 *const controller); 165 *const controller);
164 166
165 167
166/** 168/**
@@ -171,9 +173,9 @@ GNUNET_TESTBED_deregister_host_at_(struct GNUNET_TESTBED_Host *host,
171 * @return GNUNET_YES if registered; GNUNET_NO if not 173 * @return GNUNET_YES if registered; GNUNET_NO if not
172 */ 174 */
173int 175int
174GNUNET_TESTBED_is_host_registered_(const struct GNUNET_TESTBED_Host *host, 176GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host,
175 const struct GNUNET_TESTBED_Controller 177 const struct GNUNET_TESTBED_Controller
176 *controller); 178 *controller);
177 179
178 180
179/** 181/**
@@ -185,8 +187,8 @@ GNUNET_TESTBED_is_host_registered_(const struct GNUNET_TESTBED_Host *host,
185 * queue 187 * queue
186 */ 188 */
187void 189void
188GNUNET_TESTBED_host_queue_oc_(struct GNUNET_TESTBED_Host *h, 190GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h,
189 struct GNUNET_TESTBED_Operation *op); 191 struct GNUNET_TESTBED_Operation *op);
190 192
191 193
192/** 194/**
@@ -195,7 +197,7 @@ GNUNET_TESTBED_host_queue_oc_(struct GNUNET_TESTBED_Host *h,
195 * @param cproc the handle to the controller's helper process 197 * @param cproc the handle to the controller's helper process
196 */ 198 */
197void 199void
198GNUNET_TESTBED_controller_kill_(struct GNUNET_TESTBED_ControllerProc *cproc); 200GNUNET_TESTBED_controller_kill_ (struct GNUNET_TESTBED_ControllerProc *cproc);
199 201
200 202
201/** 203/**
@@ -204,8 +206,8 @@ GNUNET_TESTBED_controller_kill_(struct GNUNET_TESTBED_ControllerProc *cproc);
204 * @param cproc the handle to the controller's helper process 206 * @param cproc the handle to the controller's helper process
205 */ 207 */
206void 208void
207GNUNET_TESTBED_controller_destroy_(struct GNUNET_TESTBED_ControllerProc 209GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc
208 *cproc); 210 *cproc);
209 211
210 212
211/** 213/**
@@ -214,7 +216,7 @@ GNUNET_TESTBED_controller_destroy_(struct GNUNET_TESTBED_ControllerProc
214 * @param host the host whose hostname is to be resolved 216 * @param host the host whose hostname is to be resolved
215 */ 217 */
216void 218void
217GNUNET_TESTBED_host_resolve_(struct GNUNET_TESTBED_Host *host); 219GNUNET_TESTBED_host_resolve_ (struct GNUNET_TESTBED_Host *host);
218 220
219 221
220#endif 222#endif
diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c
index 194dc2655..185f62aa8 100644
--- a/src/testbed/testbed_api_operations.c
+++ b/src/testbed/testbed_api_operations.c
@@ -44,7 +44,8 @@
44/** 44/**
45 * An entry in the operation queue 45 * An entry in the operation queue
46 */ 46 */
47struct QueueEntry { 47struct QueueEntry
48{
48 /** 49 /**
49 * The next DLL pointer 50 * The next DLL pointer
50 */ 51 */
@@ -77,7 +78,8 @@ struct OperationQueue;
77/** 78/**
78 * A slot to record time taken by an operation 79 * A slot to record time taken by an operation
79 */ 80 */
80struct TimeSlot { 81struct TimeSlot
82{
81 /** 83 /**
82 * DLL next pointer 84 * DLL next pointer
83 */ 85 */
@@ -113,7 +115,8 @@ struct TimeSlot {
113/** 115/**
114 * Context for operation queues of type OPERATION_QUEUE_TYPE_ADAPTIVE 116 * Context for operation queues of type OPERATION_QUEUE_TYPE_ADAPTIVE
115 */ 117 */
116struct FeedbackCtx { 118struct FeedbackCtx
119{
117 /** 120 /**
118 * Handle for calculating standard deviation 121 * Handle for calculating standard deviation
119 */ 122 */
@@ -156,7 +159,8 @@ struct FeedbackCtx {
156 * Queue of operations where we can only support a certain 159 * Queue of operations where we can only support a certain
157 * number of concurrent operations of a particular type. 160 * number of concurrent operations of a particular type.
158 */ 161 */
159struct OperationQueue { 162struct OperationQueue
163{
160 /** 164 /**
161 * DLL head for the wait queue. Operations which are waiting for this 165 * DLL head for the wait queue. Operations which are waiting for this
162 * operation queue are put here 166 * operation queue are put here
@@ -243,7 +247,8 @@ struct OperationQueue {
243/** 247/**
244 * Operation state 248 * Operation state
245 */ 249 */
246enum OperationState { 250enum OperationState
251{
247 /** 252 /**
248 * The operation is just created and is in initial state 253 * The operation is just created and is in initial state
249 */ 254 */
@@ -277,7 +282,8 @@ enum OperationState {
277/** 282/**
278 * An entry in the ready queue (implemented as DLL) 283 * An entry in the ready queue (implemented as DLL)
279 */ 284 */
280struct ReadyQueueEntry { 285struct ReadyQueueEntry
286{
281 /** 287 /**
282 * next ptr for DLL 288 * next ptr for DLL
283 */ 289 */
@@ -298,7 +304,8 @@ struct ReadyQueueEntry {
298/** 304/**
299 * Opaque handle to an abstract operation to be executed by the testing framework. 305 * Opaque handle to an abstract operation to be executed by the testing framework.
300 */ 306 */
301struct GNUNET_TESTBED_Operation { 307struct GNUNET_TESTBED_Operation
308{
302 /** 309 /**
303 * Function to call when we have the resources to begin the operation. 310 * Function to call when we have the resources to begin the operation.
304 */ 311 */
@@ -403,17 +410,17 @@ struct GNUNET_SCHEDULER_Task *process_rq_task_id;
403 * @return the timeslot 410 * @return the timeslot
404 */ 411 */
405static void 412static void
406assign_timeslot(struct GNUNET_TESTBED_Operation *op, 413assign_timeslot (struct GNUNET_TESTBED_Operation *op,
407 struct OperationQueue *queue) 414 struct OperationQueue *queue)
408{ 415{
409 struct FeedbackCtx *fctx = queue->fctx; 416 struct FeedbackCtx *fctx = queue->fctx;
410 struct TimeSlot *tslot; 417 struct TimeSlot *tslot;
411 418
412 GNUNET_assert(OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type); 419 GNUNET_assert (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type);
413 tslot = fctx->alloc_head; 420 tslot = fctx->alloc_head;
414 GNUNET_assert(NULL != tslot); 421 GNUNET_assert (NULL != tslot);
415 GNUNET_CONTAINER_DLL_remove(fctx->alloc_head, fctx->alloc_tail, tslot); 422 GNUNET_CONTAINER_DLL_remove (fctx->alloc_head, fctx->alloc_tail, tslot);
416 GNUNET_CONTAINER_DLL_insert_tail(op->tslots_head, op->tslots_tail, tslot); 423 GNUNET_CONTAINER_DLL_insert_tail (op->tslots_head, op->tslots_tail, tslot);
417 tslot->op = op; 424 tslot->op = op;
418} 425}
419 426
@@ -426,7 +433,7 @@ assign_timeslot(struct GNUNET_TESTBED_Operation *op,
426 * @param index the index of the entry in the operation's array of queue entries 433 * @param index the index of the entry in the operation's array of queue entries
427 */ 434 */
428static void 435static void
429remove_queue_entry(struct GNUNET_TESTBED_Operation *op, unsigned int index) 436remove_queue_entry (struct GNUNET_TESTBED_Operation *op, unsigned int index)
430{ 437{
431 struct OperationQueue *opq; 438 struct OperationQueue *opq;
432 struct QueueEntry *entry; 439 struct QueueEntry *entry;
@@ -434,27 +441,27 @@ remove_queue_entry(struct GNUNET_TESTBED_Operation *op, unsigned int index)
434 opq = op->queues[index]; 441 opq = op->queues[index];
435 entry = op->qentries[index]; 442 entry = op->qentries[index];
436 switch (op->state) 443 switch (op->state)
437 { 444 {
438 case OP_STATE_INIT: 445 case OP_STATE_INIT:
439 GNUNET_assert(0); 446 GNUNET_assert (0);
440 break; 447 break;
441 448
442 case OP_STATE_WAITING: 449 case OP_STATE_WAITING:
443 GNUNET_CONTAINER_DLL_remove(opq->wq_head, opq->wq_tail, entry); 450 GNUNET_CONTAINER_DLL_remove (opq->wq_head, opq->wq_tail, entry);
444 break; 451 break;
445 452
446 case OP_STATE_READY: 453 case OP_STATE_READY:
447 GNUNET_CONTAINER_DLL_remove(opq->rq_head, opq->rq_tail, entry); 454 GNUNET_CONTAINER_DLL_remove (opq->rq_head, opq->rq_tail, entry);
448 break; 455 break;
449 456
450 case OP_STATE_ACTIVE: 457 case OP_STATE_ACTIVE:
451 GNUNET_CONTAINER_DLL_remove(opq->aq_head, opq->aq_tail, entry); 458 GNUNET_CONTAINER_DLL_remove (opq->aq_head, opq->aq_tail, entry);
452 break; 459 break;
453 460
454 case OP_STATE_INACTIVE: 461 case OP_STATE_INACTIVE:
455 GNUNET_CONTAINER_DLL_remove(opq->nq_head, opq->nq_tail, entry); 462 GNUNET_CONTAINER_DLL_remove (opq->nq_head, opq->nq_tail, entry);
456 break; 463 break;
457 } 464 }
458} 465}
459 466
460 467
@@ -466,57 +473,57 @@ remove_queue_entry(struct GNUNET_TESTBED_Operation *op, unsigned int index)
466 * @param state the state the operation should have. It cannot be OP_STATE_INIT 473 * @param state the state the operation should have. It cannot be OP_STATE_INIT
467 */ 474 */
468static void 475static void
469change_state(struct GNUNET_TESTBED_Operation *op, enum OperationState state) 476change_state (struct GNUNET_TESTBED_Operation *op, enum OperationState state)
470{ 477{
471 struct QueueEntry *entry; 478 struct QueueEntry *entry;
472 struct OperationQueue *opq; 479 struct OperationQueue *opq;
473 unsigned int cnt; 480 unsigned int cnt;
474 unsigned int s; 481 unsigned int s;
475 482
476 GNUNET_assert(OP_STATE_INIT != state); 483 GNUNET_assert (OP_STATE_INIT != state);
477 GNUNET_assert(NULL != op->queues); 484 GNUNET_assert (NULL != op->queues);
478 GNUNET_assert(NULL != op->nres); 485 GNUNET_assert (NULL != op->nres);
479 GNUNET_assert((OP_STATE_INIT == op->state) || (NULL != op->qentries)); 486 GNUNET_assert ((OP_STATE_INIT == op->state) || (NULL != op->qentries));
480 GNUNET_assert(op->state != state); 487 GNUNET_assert (op->state != state);
481 for (cnt = 0; cnt < op->nqueues; cnt++) 488 for (cnt = 0; cnt < op->nqueues; cnt++)
489 {
490 if (OP_STATE_INIT == op->state)
482 { 491 {
483 if (OP_STATE_INIT == op->state) 492 entry = GNUNET_new (struct QueueEntry);
484 { 493 entry->op = op;
485 entry = GNUNET_new(struct QueueEntry); 494 entry->nres = op->nres[cnt];
486 entry->op = op; 495 s = cnt;
487 entry->nres = op->nres[cnt]; 496 GNUNET_array_append (op->qentries, s, entry);
488 s = cnt; 497 }
489 GNUNET_array_append(op->qentries, s, entry); 498 else
490 } 499 {
491 else 500 entry = op->qentries[cnt];
492 { 501 remove_queue_entry (op, cnt);
493 entry = op->qentries[cnt]; 502 }
494 remove_queue_entry(op, cnt); 503 opq = op->queues[cnt];
495 } 504 switch (state)
496 opq = op->queues[cnt]; 505 {
497 switch (state) 506 case OP_STATE_INIT:
498 { 507 GNUNET_assert (0);
499 case OP_STATE_INIT: 508 break;
500 GNUNET_assert(0);
501 break;
502 509
503 case OP_STATE_WAITING: 510 case OP_STATE_WAITING:
504 GNUNET_CONTAINER_DLL_insert_tail(opq->wq_head, opq->wq_tail, entry); 511 GNUNET_CONTAINER_DLL_insert_tail (opq->wq_head, opq->wq_tail, entry);
505 break; 512 break;
506 513
507 case OP_STATE_READY: 514 case OP_STATE_READY:
508 GNUNET_CONTAINER_DLL_insert_tail(opq->rq_head, opq->rq_tail, entry); 515 GNUNET_CONTAINER_DLL_insert_tail (opq->rq_head, opq->rq_tail, entry);
509 break; 516 break;
510 517
511 case OP_STATE_ACTIVE: 518 case OP_STATE_ACTIVE:
512 GNUNET_CONTAINER_DLL_insert_tail(opq->aq_head, opq->aq_tail, entry); 519 GNUNET_CONTAINER_DLL_insert_tail (opq->aq_head, opq->aq_tail, entry);
513 break; 520 break;
514 521
515 case OP_STATE_INACTIVE: 522 case OP_STATE_INACTIVE:
516 GNUNET_CONTAINER_DLL_insert_tail(opq->nq_head, opq->nq_tail, entry); 523 GNUNET_CONTAINER_DLL_insert_tail (opq->nq_head, opq->nq_tail, entry);
517 break; 524 break;
518 }
519 } 525 }
526 }
520 op->state = state; 527 op->state = state;
521} 528}
522 529
@@ -528,17 +535,17 @@ change_state(struct GNUNET_TESTBED_Operation *op, enum OperationState state)
528 * @param op the operation to be removed 535 * @param op the operation to be removed
529 */ 536 */
530static void 537static void
531rq_remove(struct GNUNET_TESTBED_Operation *op) 538rq_remove (struct GNUNET_TESTBED_Operation *op)
532{ 539{
533 GNUNET_assert(NULL != op->rq_entry); 540 GNUNET_assert (NULL != op->rq_entry);
534 GNUNET_CONTAINER_DLL_remove(rq_head, rq_tail, op->rq_entry); 541 GNUNET_CONTAINER_DLL_remove (rq_head, rq_tail, op->rq_entry);
535 GNUNET_free(op->rq_entry); 542 GNUNET_free (op->rq_entry);
536 op->rq_entry = NULL; 543 op->rq_entry = NULL;
537 if ((NULL == rq_head) && (NULL != process_rq_task_id)) 544 if ((NULL == rq_head) && (NULL != process_rq_task_id))
538 { 545 {
539 GNUNET_SCHEDULER_cancel(process_rq_task_id); 546 GNUNET_SCHEDULER_cancel (process_rq_task_id);
540 process_rq_task_id = NULL; 547 process_rq_task_id = NULL;
541 } 548 }
542} 549}
543 550
544 551
@@ -551,28 +558,28 @@ rq_remove(struct GNUNET_TESTBED_Operation *op)
551 * @param cls NULL 558 * @param cls NULL
552 */ 559 */
553static void 560static void
554process_rq_task(void *cls) 561process_rq_task (void *cls)
555{ 562{
556 struct GNUNET_TESTBED_Operation *op; 563 struct GNUNET_TESTBED_Operation *op;
557 struct OperationQueue *queue; 564 struct OperationQueue *queue;
558 unsigned int cnt; 565 unsigned int cnt;
559 566
560 process_rq_task_id = NULL; 567 process_rq_task_id = NULL;
561 GNUNET_assert(NULL != rq_head); 568 GNUNET_assert (NULL != rq_head);
562 GNUNET_assert(NULL != (op = rq_head->op)); 569 GNUNET_assert (NULL != (op = rq_head->op));
563 rq_remove(op); 570 rq_remove (op);
564 if (NULL != rq_head) 571 if (NULL != rq_head)
565 process_rq_task_id = GNUNET_SCHEDULER_add_now(&process_rq_task, NULL); 572 process_rq_task_id = GNUNET_SCHEDULER_add_now (&process_rq_task, NULL);
566 change_state(op, OP_STATE_ACTIVE); 573 change_state (op, OP_STATE_ACTIVE);
567 for (cnt = 0; cnt < op->nqueues; cnt++) 574 for (cnt = 0; cnt < op->nqueues; cnt++)
568 { 575 {
569 queue = op->queues[cnt]; 576 queue = op->queues[cnt];
570 if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type) 577 if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type)
571 assign_timeslot(op, queue); 578 assign_timeslot (op, queue);
572 } 579 }
573 op->tstart = GNUNET_TIME_absolute_get(); 580 op->tstart = GNUNET_TIME_absolute_get ();
574 if (NULL != op->start) 581 if (NULL != op->start)
575 op->start(op->cb_cls); 582 op->start (op->cb_cls);
576} 583}
577 584
578 585
@@ -582,17 +589,17 @@ process_rq_task(void *cls)
582 * @param op the operation to be queued 589 * @param op the operation to be queued
583 */ 590 */
584static void 591static void
585rq_add(struct GNUNET_TESTBED_Operation *op) 592rq_add (struct GNUNET_TESTBED_Operation *op)
586{ 593{
587 struct ReadyQueueEntry *rq_entry; 594 struct ReadyQueueEntry *rq_entry;
588 595
589 GNUNET_assert(NULL == op->rq_entry); 596 GNUNET_assert (NULL == op->rq_entry);
590 rq_entry = GNUNET_new(struct ReadyQueueEntry); 597 rq_entry = GNUNET_new (struct ReadyQueueEntry);
591 rq_entry->op = op; 598 rq_entry->op = op;
592 GNUNET_CONTAINER_DLL_insert_tail(rq_head, rq_tail, rq_entry); 599 GNUNET_CONTAINER_DLL_insert_tail (rq_head, rq_tail, rq_entry);
593 op->rq_entry = rq_entry; 600 op->rq_entry = rq_entry;
594 if (NULL == process_rq_task_id) 601 if (NULL == process_rq_task_id)
595 process_rq_task_id = GNUNET_SCHEDULER_add_now(&process_rq_task, NULL); 602 process_rq_task_id = GNUNET_SCHEDULER_add_now (&process_rq_task, NULL);
596} 603}
597 604
598 605
@@ -604,7 +611,7 @@ rq_add(struct GNUNET_TESTBED_Operation *op)
604 * otherwise 611 * otherwise
605 */ 612 */
606static int 613static int
607is_queue_empty(struct OperationQueue *opq) 614is_queue_empty (struct OperationQueue *opq)
608{ 615{
609 if ((NULL != opq->wq_head) 616 if ((NULL != opq->wq_head)
610 || (NULL != opq->rq_head) 617 || (NULL != opq->rq_head)
@@ -632,10 +639,10 @@ is_queue_empty(struct OperationQueue *opq)
632 * be set to NULL and 0 respectively. 639 * be set to NULL and 0 respectively.
633 */ 640 */
634static int 641static int
635decide_capacity(struct OperationQueue *opq, 642decide_capacity (struct OperationQueue *opq,
636 struct QueueEntry *entry, 643 struct QueueEntry *entry,
637 struct GNUNET_TESTBED_Operation ***ops_, 644 struct GNUNET_TESTBED_Operation ***ops_,
638 unsigned int *n_ops_) 645 unsigned int *n_ops_)
639{ 646{
640 struct QueueEntry **evict_entries; 647 struct QueueEntry **evict_entries;
641 struct GNUNET_TESTBED_Operation **ops; 648 struct GNUNET_TESTBED_Operation **ops;
@@ -647,53 +654,53 @@ decide_capacity(struct OperationQueue *opq,
647 int deficit; 654 int deficit;
648 int rval; 655 int rval;
649 656
650 GNUNET_assert(NULL != (op = entry->op)); 657 GNUNET_assert (NULL != (op = entry->op));
651 GNUNET_assert(0 < (need = entry->nres)); 658 GNUNET_assert (0 < (need = entry->nres));
652 ops = NULL; 659 ops = NULL;
653 n_ops = 0; 660 n_ops = 0;
654 evict_entries = NULL; 661 evict_entries = NULL;
655 n_evict_entries = 0; 662 n_evict_entries = 0;
656 rval = GNUNET_YES; 663 rval = GNUNET_YES;
657 if (OPERATION_QUEUE_TYPE_ADAPTIVE == opq->type) 664 if (OPERATION_QUEUE_TYPE_ADAPTIVE == opq->type)
658 { 665 {
659 GNUNET_assert(NULL != opq->fctx); 666 GNUNET_assert (NULL != opq->fctx);
660 GNUNET_assert(opq->max_active >= opq->overload); 667 GNUNET_assert (opq->max_active >= opq->overload);
661 max = opq->max_active - opq->overload; 668 max = opq->max_active - opq->overload;
662 } 669 }
663 else 670 else
664 max = opq->max_active; 671 max = opq->max_active;
665 if (opq->active > max) 672 if (opq->active > max)
666 { 673 {
667 rval = GNUNET_NO; 674 rval = GNUNET_NO;
668 goto ret; 675 goto ret;
669 } 676 }
670 if ((opq->active + need) <= max) 677 if ((opq->active + need) <= max)
671 goto ret; 678 goto ret;
672 deficit = need - (max - opq->active); 679 deficit = need - (max - opq->active);
673 for (entry = opq->nq_head; 680 for (entry = opq->nq_head;
674 (0 < deficit) && (NULL != entry); 681 (0 < deficit) && (NULL != entry);
675 entry = entry->next) 682 entry = entry->next)
676 { 683 {
677 GNUNET_array_append(evict_entries, n_evict_entries, entry); 684 GNUNET_array_append (evict_entries, n_evict_entries, entry);
678 deficit -= entry->nres; 685 deficit -= entry->nres;
679 } 686 }
680 if (0 < deficit) 687 if (0 < deficit)
681 { 688 {
682 rval = GNUNET_NO; 689 rval = GNUNET_NO;
683 goto ret; 690 goto ret;
684 } 691 }
685 for (n_ops = 0; n_ops < n_evict_entries;) 692 for (n_ops = 0; n_ops < n_evict_entries;)
686 { 693 {
687 op = evict_entries[n_ops]->op; 694 op = evict_entries[n_ops]->op;
688 GNUNET_array_append(ops, n_ops, op); /* increments n-ops */ 695 GNUNET_array_append (ops, n_ops, op); /* increments n-ops */
689 } 696 }
690 697
691ret: 698ret:
692 GNUNET_free_non_null(evict_entries); 699 GNUNET_free_non_null (evict_entries);
693 if (NULL != ops_) 700 if (NULL != ops_)
694 *ops_ = ops; 701 *ops_ = ops;
695 else 702 else
696 GNUNET_free(ops); 703 GNUNET_free (ops);
697 if (NULL != n_ops_) 704 if (NULL != n_ops_)
698 *n_ops_ = n_ops; 705 *n_ops_ = n_ops;
699 return rval; 706 return rval;
@@ -710,30 +717,30 @@ ret:
710 * @param n_new the number of operations in new array 717 * @param n_new the number of operations in new array
711 */ 718 */
712static void 719static void
713merge_ops(struct GNUNET_TESTBED_Operation ***old, 720merge_ops (struct GNUNET_TESTBED_Operation ***old,
714 unsigned int *n_old, 721 unsigned int *n_old,
715 struct GNUNET_TESTBED_Operation **new, 722 struct GNUNET_TESTBED_Operation **new,
716 unsigned int n_new) 723 unsigned int n_new)
717{ 724{
718 struct GNUNET_TESTBED_Operation **cur; 725 struct GNUNET_TESTBED_Operation **cur;
719 unsigned int i; 726 unsigned int i;
720 unsigned int j; 727 unsigned int j;
721 unsigned int n_cur; 728 unsigned int n_cur;
722 729
723 GNUNET_assert(NULL != old); 730 GNUNET_assert (NULL != old);
724 n_cur = *n_old; 731 n_cur = *n_old;
725 cur = *old; 732 cur = *old;
726 for (i = 0; i < n_new; i++) 733 for (i = 0; i < n_new; i++)
734 {
735 for (j = 0; j < *n_old; j++)
727 { 736 {
728 for (j = 0; j < *n_old; j++) 737 if (new[i] == cur[j])
729 { 738 break;
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]);
736 } 739 }
740 if (j < *n_old)
741 continue;
742 GNUNET_array_append (cur, n_cur, new[j]);
743 }
737 *old = cur; 744 *old = cur;
738 *n_old = n_cur; 745 *n_old = n_cur;
739} 746}
@@ -746,7 +753,7 @@ merge_ops(struct GNUNET_TESTBED_Operation ***old,
746 * @param op the operation 753 * @param op the operation
747 */ 754 */
748static int 755static int
749check_readiness(struct GNUNET_TESTBED_Operation *op) 756check_readiness (struct GNUNET_TESTBED_Operation *op)
750{ 757{
751 struct GNUNET_TESTBED_Operation **evict_ops; 758 struct GNUNET_TESTBED_Operation **evict_ops;
752 struct GNUNET_TESTBED_Operation **ops; 759 struct GNUNET_TESTBED_Operation **ops;
@@ -754,39 +761,39 @@ check_readiness(struct GNUNET_TESTBED_Operation *op)
754 unsigned int n_evict_ops; 761 unsigned int n_evict_ops;
755 unsigned int i; 762 unsigned int i;
756 763
757 GNUNET_assert(NULL == op->rq_entry); 764 GNUNET_assert (NULL == op->rq_entry);
758 GNUNET_assert(OP_STATE_WAITING == op->state); 765 GNUNET_assert (OP_STATE_WAITING == op->state);
759 evict_ops = NULL; 766 evict_ops = NULL;
760 n_evict_ops = 0; 767 n_evict_ops = 0;
761 for (i = 0; i < op->nqueues; i++) 768 for (i = 0; i < op->nqueues; i++)
769 {
770 ops = NULL;
771 n_ops = 0;
772 if (GNUNET_NO == decide_capacity (op->queues[i], op->qentries[i],
773 &ops, &n_ops))
762 { 774 {
763 ops = NULL; 775 GNUNET_free_non_null (evict_ops);
764 n_ops = 0; 776 return GNUNET_NO;
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);
775 } 777 }
778 if (NULL == ops)
779 continue;
780 merge_ops (&evict_ops, &n_evict_ops, ops, n_ops);
781 GNUNET_free (ops);
782 }
776 if (NULL != evict_ops) 783 if (NULL != evict_ops)
777 { 784 {
778 for (i = 0; i < n_evict_ops; i++) 785 for (i = 0; i < n_evict_ops; i++)
779 GNUNET_TESTBED_operation_release_(evict_ops[i]); 786 GNUNET_TESTBED_operation_release_ (evict_ops[i]);
780 GNUNET_free(evict_ops); 787 GNUNET_free (evict_ops);
781 evict_ops = NULL; 788 evict_ops = NULL;
782 /* Evicting the operations should schedule this operation */ 789 /* Evicting the operations should schedule this operation */
783 GNUNET_assert(OP_STATE_READY == op->state); 790 GNUNET_assert (OP_STATE_READY == op->state);
784 return GNUNET_YES; 791 return GNUNET_YES;
785 } 792 }
786 for (i = 0; i < op->nqueues; i++) 793 for (i = 0; i < op->nqueues; i++)
787 op->queues[i]->active += op->nres[i]; 794 op->queues[i]->active += op->nres[i];
788 change_state(op, OP_STATE_READY); 795 change_state (op, OP_STATE_READY);
789 rq_add(op); 796 rq_add (op);
790 return GNUNET_YES; 797 return GNUNET_YES;
791} 798}
792 799
@@ -797,18 +804,18 @@ check_readiness(struct GNUNET_TESTBED_Operation *op)
797 * @param op the operation to defer 804 * @param op the operation to defer
798 */ 805 */
799static void 806static void
800defer(struct GNUNET_TESTBED_Operation *op) 807defer (struct GNUNET_TESTBED_Operation *op)
801{ 808{
802 unsigned int i; 809 unsigned int i;
803 810
804 GNUNET_assert(OP_STATE_READY == op->state); 811 GNUNET_assert (OP_STATE_READY == op->state);
805 rq_remove(op); 812 rq_remove (op);
806 for (i = 0; i < op->nqueues; i++) 813 for (i = 0; i < op->nqueues; i++)
807 { 814 {
808 GNUNET_assert(op->queues[i]->active >= op->nres[i]); 815 GNUNET_assert (op->queues[i]->active >= op->nres[i]);
809 op->queues[i]->active -= op->nres[i]; 816 op->queues[i]->active -= op->nres[i];
810 } 817 }
811 change_state(op, OP_STATE_WAITING); 818 change_state (op, OP_STATE_WAITING);
812} 819}
813 820
814 821
@@ -820,23 +827,23 @@ defer(struct GNUNET_TESTBED_Operation *op)
820 * @param queue the operation queue 827 * @param queue the operation queue
821 */ 828 */
822static void 829static void
823cleanup_tslots(struct OperationQueue *queue) 830cleanup_tslots (struct OperationQueue *queue)
824{ 831{
825 struct FeedbackCtx *fctx = queue->fctx; 832 struct FeedbackCtx *fctx = queue->fctx;
826 struct TimeSlot *tslot; 833 struct TimeSlot *tslot;
827 struct GNUNET_TESTBED_Operation *op; 834 struct GNUNET_TESTBED_Operation *op;
828 unsigned int cnt; 835 unsigned int cnt;
829 836
830 GNUNET_assert(NULL != fctx); 837 GNUNET_assert (NULL != fctx);
831 for (cnt = 0; cnt < queue->max_active; cnt++) 838 for (cnt = 0; cnt < queue->max_active; cnt++)
832 { 839 {
833 tslot = &fctx->tslots_freeptr[cnt]; 840 tslot = &fctx->tslots_freeptr[cnt];
834 op = tslot->op; 841 op = tslot->op;
835 if (NULL == op) 842 if (NULL == op)
836 continue; 843 continue;
837 GNUNET_CONTAINER_DLL_remove(op->tslots_head, op->tslots_tail, tslot); 844 GNUNET_CONTAINER_DLL_remove (op->tslots_head, op->tslots_tail, tslot);
838 } 845 }
839 GNUNET_free_non_null(fctx->tslots_freeptr); 846 GNUNET_free_non_null (fctx->tslots_freeptr);
840 fctx->tslots_freeptr = NULL; 847 fctx->tslots_freeptr = NULL;
841 fctx->alloc_head = NULL; 848 fctx->alloc_head = NULL;
842 fctx->alloc_tail = NULL; 849 fctx->alloc_tail = NULL;
@@ -854,23 +861,24 @@ cleanup_tslots(struct OperationQueue *queue)
854 * will be selected as n 861 * will be selected as n
855 */ 862 */
856static void 863static void
857adaptive_queue_set_max_active(struct OperationQueue *queue, unsigned int n) 864adaptive_queue_set_max_active (struct OperationQueue *queue, unsigned int n)
858{ 865{
859 struct FeedbackCtx *fctx = queue->fctx; 866 struct FeedbackCtx *fctx = queue->fctx;
860 struct TimeSlot *tslot; 867 struct TimeSlot *tslot;
861 unsigned int cnt; 868 unsigned int cnt;
862 869
863 cleanup_tslots(queue); 870 cleanup_tslots (queue);
864 n = GNUNET_MIN(n, fctx->max_active_bound); 871 n = GNUNET_MIN (n, fctx->max_active_bound);
865 fctx->tslots_freeptr = GNUNET_malloc(n * sizeof(struct TimeSlot)); 872 fctx->tslots_freeptr = GNUNET_malloc (n * sizeof(struct TimeSlot));
866 fctx->nfailed = 0; 873 fctx->nfailed = 0;
867 for (cnt = 0; cnt < n; cnt++) 874 for (cnt = 0; cnt < n; cnt++)
868 { 875 {
869 tslot = &fctx->tslots_freeptr[cnt]; 876 tslot = &fctx->tslots_freeptr[cnt];
870 tslot->queue = queue; 877 tslot->queue = queue;
871 GNUNET_CONTAINER_DLL_insert_tail(fctx->alloc_head, fctx->alloc_tail, tslot); 878 GNUNET_CONTAINER_DLL_insert_tail (fctx->alloc_head, fctx->alloc_tail,
872 } 879 tslot);
873 GNUNET_TESTBED_operation_queue_reset_max_active_(queue, n); 880 }
881 GNUNET_TESTBED_operation_queue_reset_max_active_ (queue, n);
874} 882}
875 883
876 884
@@ -881,7 +889,7 @@ adaptive_queue_set_max_active(struct OperationQueue *queue, unsigned int n)
881 * @param queue the queue 889 * @param queue the queue
882 */ 890 */
883static void 891static void
884adapt_parallelism(struct OperationQueue *queue) 892adapt_parallelism (struct OperationQueue *queue)
885{ 893{
886 struct GNUNET_TIME_Relative avg; 894 struct GNUNET_TIME_Relative avg;
887 struct FeedbackCtx *fctx; 895 struct FeedbackCtx *fctx;
@@ -895,32 +903,32 @@ adapt_parallelism(struct OperationQueue *queue)
895 nvals = 0; 903 nvals = 0;
896 fctx = queue->fctx; 904 fctx = queue->fctx;
897 for (cnt = 0; cnt < queue->max_active; cnt++) 905 for (cnt = 0; cnt < queue->max_active; cnt++)
898 { 906 {
899 tslot = &fctx->tslots_freeptr[cnt]; 907 tslot = &fctx->tslots_freeptr[cnt];
900 avg = GNUNET_TIME_relative_add(avg, tslot->tsum); 908 avg = GNUNET_TIME_relative_add (avg, tslot->tsum);
901 nvals += tslot->nvals; 909 nvals += tslot->nvals;
902 } 910 }
903 GNUNET_assert(nvals >= queue->max_active); 911 GNUNET_assert (nvals >= queue->max_active);
904 GNUNET_assert(fctx->nfailed <= nvals); 912 GNUNET_assert (fctx->nfailed <= nvals);
905 nvals -= fctx->nfailed; 913 nvals -= fctx->nfailed;
906 if (0 == nvals) 914 if (0 == nvals)
907 { 915 {
908 if (1 == queue->max_active) 916 if (1 == queue->max_active)
909 adaptive_queue_set_max_active(queue, 1); 917 adaptive_queue_set_max_active (queue, 1);
910 else 918 else
911 adaptive_queue_set_max_active(queue, queue->max_active / 2); 919 adaptive_queue_set_max_active (queue, queue->max_active / 2);
912 return; 920 return;
913 } 921 }
914 avg = GNUNET_TIME_relative_divide(avg, nvals); 922 avg = GNUNET_TIME_relative_divide (avg, nvals);
915 GNUNET_TESTBED_SD_add_data_(fctx->sd, (unsigned int)avg.rel_value_us); 923 GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us);
916 if (GNUNET_SYSERR == 924 if (GNUNET_SYSERR ==
917 GNUNET_TESTBED_SD_deviation_factor_(fctx->sd, 925 GNUNET_TESTBED_SD_deviation_factor_ (fctx->sd,
918 (unsigned int)avg.rel_value_us, 926 (unsigned int) avg.rel_value_us,
919 &sd)) 927 &sd))
920 { 928 {
921 adaptive_queue_set_max_active(queue, queue->max_active); /* no change */ 929 adaptive_queue_set_max_active (queue, queue->max_active); /* no change */
922 return; 930 return;
923 } 931 }
924 932
925 parallelism = 0; 933 parallelism = 0;
926 if (-1 == sd) 934 if (-1 == sd)
@@ -931,36 +939,36 @@ adapt_parallelism(struct OperationQueue *queue)
931 parallelism = queue->max_active - 1; 939 parallelism = queue->max_active - 1;
932 if (2 <= sd) 940 if (2 <= sd)
933 parallelism = queue->max_active / 2; 941 parallelism = queue->max_active / 2;
934 parallelism = GNUNET_MAX(parallelism, ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE); 942 parallelism = GNUNET_MAX (parallelism, ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE);
935 adaptive_queue_set_max_active(queue, parallelism); 943 adaptive_queue_set_max_active (queue, parallelism);
936 944
937#if 0 945#if 0
938 /* old algorithm */ 946 /* old algorithm */
939 if (sd < 0) 947 if (sd < 0)
940 sd = 0; 948 sd = 0;
941 GNUNET_assert(0 <= sd); 949 GNUNET_assert (0 <= sd);
942 //GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us); 950 // GNUNET_TESTBED_SD_add_data_ (fctx->sd, (unsigned int) avg.rel_value_us);
943 if (0 == sd) 951 if (0 == sd)
944 { 952 {
945 adaptive_queue_set_max_active(queue, queue->max_active * 2); 953 adaptive_queue_set_max_active (queue, queue->max_active * 2);
946 return; 954 return;
947 } 955 }
948 if (1 == sd) 956 if (1 == sd)
949 { 957 {
950 adaptive_queue_set_max_active(queue, queue->max_active + 1); 958 adaptive_queue_set_max_active (queue, queue->max_active + 1);
951 return; 959 return;
952 } 960 }
953 if (1 == queue->max_active) 961 if (1 == queue->max_active)
954 { 962 {
955 adaptive_queue_set_max_active(queue, 1); 963 adaptive_queue_set_max_active (queue, 1);
956 return; 964 return;
957 } 965 }
958 if (2 == sd) 966 if (2 == sd)
959 { 967 {
960 adaptive_queue_set_max_active(queue, queue->max_active - 1); 968 adaptive_queue_set_max_active (queue, queue->max_active - 1);
961 return; 969 return;
962 } 970 }
963 adaptive_queue_set_max_active(queue, queue->max_active / 2); 971 adaptive_queue_set_max_active (queue, queue->max_active / 2);
964#endif 972#endif
965} 973}
966 974
@@ -973,7 +981,7 @@ adapt_parallelism(struct OperationQueue *queue)
973 * @param op the operation 981 * @param op the operation
974 */ 982 */
975static void 983static void
976update_tslots(struct GNUNET_TESTBED_Operation *op) 984update_tslots (struct GNUNET_TESTBED_Operation *op)
977{ 985{
978 struct OperationQueue *queue; 986 struct OperationQueue *queue;
979 struct GNUNET_TIME_Relative t; 987 struct GNUNET_TIME_Relative t;
@@ -981,31 +989,31 @@ update_tslots(struct GNUNET_TESTBED_Operation *op)
981 struct FeedbackCtx *fctx; 989 struct FeedbackCtx *fctx;
982 unsigned int i; 990 unsigned int i;
983 991
984 t = GNUNET_TIME_absolute_get_duration(op->tstart); 992 t = GNUNET_TIME_absolute_get_duration (op->tstart);
985 while (NULL != (tslot = op->tslots_head)) /* update time slots */ 993 while (NULL != (tslot = op->tslots_head)) /* update time slots */
994 {
995 queue = tslot->queue;
996 fctx = queue->fctx;
997 GNUNET_CONTAINER_DLL_remove (op->tslots_head, op->tslots_tail, tslot);
998 tslot->op = NULL;
999 GNUNET_CONTAINER_DLL_insert_tail (fctx->alloc_head, fctx->alloc_tail,
1000 tslot);
1001 if (op->failed)
986 { 1002 {
987 queue = tslot->queue; 1003 fctx->nfailed++;
988 fctx = queue->fctx; 1004 for (i = 0; i < op->nqueues; i++)
989 GNUNET_CONTAINER_DLL_remove(op->tslots_head, op->tslots_tail, tslot); 1005 if (queue == op->queues[i])
990 tslot->op = NULL; 1006 break;
991 GNUNET_CONTAINER_DLL_insert_tail(fctx->alloc_head, fctx->alloc_tail, 1007 GNUNET_assert (i != op->nqueues);
992 tslot); 1008 op->queues[i]->overload += op->nres[i];
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);
1008 } 1009 }
1010 tslot->tsum = GNUNET_TIME_relative_add (tslot->tsum, t);
1011 if (0 != tslot->nvals++)
1012 continue;
1013 fctx->tslots_filled++;
1014 if (queue->max_active == fctx->tslots_filled)
1015 adapt_parallelism (queue);
1016 }
1009} 1017}
1010 1018
1011 1019
@@ -1018,12 +1026,12 @@ update_tslots(struct GNUNET_TESTBED_Operation *op)
1018 * @return handle to the operation 1026 * @return handle to the operation
1019 */ 1027 */
1020struct GNUNET_TESTBED_Operation * 1028struct GNUNET_TESTBED_Operation *
1021GNUNET_TESTBED_operation_create_(void *cls, OperationStart start, 1029GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start,
1022 OperationRelease release) 1030 OperationRelease release)
1023{ 1031{
1024 struct GNUNET_TESTBED_Operation *op; 1032 struct GNUNET_TESTBED_Operation *op;
1025 1033
1026 op = GNUNET_new(struct GNUNET_TESTBED_Operation); 1034 op = GNUNET_new (struct GNUNET_TESTBED_Operation);
1027 op->start = start; 1035 op->start = start;
1028 op->state = OP_STATE_INIT; 1036 op->state = OP_STATE_INIT;
1029 op->release = release; 1037 op->release = release;
@@ -1041,26 +1049,26 @@ GNUNET_TESTBED_operation_create_(void *cls, OperationStart start,
1041 * @return handle to the queue 1049 * @return handle to the queue
1042 */ 1050 */
1043struct OperationQueue * 1051struct OperationQueue *
1044GNUNET_TESTBED_operation_queue_create_(enum OperationQueueType type, 1052GNUNET_TESTBED_operation_queue_create_ (enum OperationQueueType type,
1045 unsigned int max_active) 1053 unsigned int max_active)
1046{ 1054{
1047 struct OperationQueue *queue; 1055 struct OperationQueue *queue;
1048 struct FeedbackCtx *fctx; 1056 struct FeedbackCtx *fctx;
1049 1057
1050 queue = GNUNET_new(struct OperationQueue); 1058 queue = GNUNET_new (struct OperationQueue);
1051 queue->type = type; 1059 queue->type = type;
1052 if (OPERATION_QUEUE_TYPE_FIXED == type) 1060 if (OPERATION_QUEUE_TYPE_FIXED == type)
1053 { 1061 {
1054 queue->max_active = max_active; 1062 queue->max_active = max_active;
1055 } 1063 }
1056 else 1064 else
1057 { 1065 {
1058 fctx = GNUNET_new(struct FeedbackCtx); 1066 fctx = GNUNET_new (struct FeedbackCtx);
1059 fctx->max_active_bound = max_active; 1067 fctx->max_active_bound = max_active;
1060 fctx->sd = GNUNET_TESTBED_SD_init_(ADAPTIVE_QUEUE_DEFAULT_HISTORY); 1068 fctx->sd = GNUNET_TESTBED_SD_init_ (ADAPTIVE_QUEUE_DEFAULT_HISTORY);
1061 queue->fctx = fctx; 1069 queue->fctx = fctx;
1062 adaptive_queue_set_max_active(queue, ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE); 1070 adaptive_queue_set_max_active (queue, ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE);
1063 } 1071 }
1064 return queue; 1072 return queue;
1065} 1073}
1066 1074
@@ -1071,18 +1079,18 @@ GNUNET_TESTBED_operation_queue_create_(enum OperationQueueType type,
1071 * @param queue the operation queue to destroy 1079 * @param queue the operation queue to destroy
1072 */ 1080 */
1073static void 1081static void
1074queue_destroy(struct OperationQueue *queue) 1082queue_destroy (struct OperationQueue *queue)
1075{ 1083{
1076 struct FeedbackCtx *fctx; 1084 struct FeedbackCtx *fctx;
1077 1085
1078 if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type) 1086 if (OPERATION_QUEUE_TYPE_ADAPTIVE == queue->type)
1079 { 1087 {
1080 cleanup_tslots(queue); 1088 cleanup_tslots (queue);
1081 fctx = queue->fctx; 1089 fctx = queue->fctx;
1082 GNUNET_TESTBED_SD_destroy_(fctx->sd); 1090 GNUNET_TESTBED_SD_destroy_ (fctx->sd);
1083 GNUNET_free(fctx); 1091 GNUNET_free (fctx);
1084 } 1092 }
1085 GNUNET_free(queue); 1093 GNUNET_free (queue);
1086} 1094}
1087 1095
1088 1096
@@ -1094,16 +1102,16 @@ queue_destroy(struct OperationQueue *queue)
1094 * @param queue queue to destroy 1102 * @param queue queue to destroy
1095 */ 1103 */
1096void 1104void
1097GNUNET_TESTBED_operation_queue_destroy_(struct OperationQueue *queue) 1105GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue)
1098{ 1106{
1099 if (GNUNET_YES != is_queue_empty(queue)) 1107 if (GNUNET_YES != is_queue_empty (queue))
1100 { 1108 {
1101 GNUNET_assert(0 == queue->expired); /* Are you calling twice on same queue? */ 1109 GNUNET_assert (0 == queue->expired); /* Are you calling twice on same queue? */
1102 queue->expired = 1; 1110 queue->expired = 1;
1103 GNUNET_array_append(expired_opqs, n_expired_opqs, queue); 1111 GNUNET_array_append (expired_opqs, n_expired_opqs, queue);
1104 return; 1112 return;
1105 } 1113 }
1106 queue_destroy(queue); 1114 queue_destroy (queue);
1107} 1115}
1108 1116
1109 1117
@@ -1115,11 +1123,11 @@ GNUNET_TESTBED_operation_queue_destroy_(struct OperationQueue *queue)
1115 * is not empty) 1123 * is not empty)
1116 */ 1124 */
1117int 1125int
1118GNUNET_TESTBED_operation_queue_destroy_empty_(struct OperationQueue *queue) 1126GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue)
1119{ 1127{
1120 if (GNUNET_NO == is_queue_empty(queue)) 1128 if (GNUNET_NO == is_queue_empty (queue))
1121 return GNUNET_NO; 1129 return GNUNET_NO;
1122 GNUNET_TESTBED_operation_queue_destroy_(queue); 1130 GNUNET_TESTBED_operation_queue_destroy_ (queue);
1123 return GNUNET_YES; 1131 return GNUNET_YES;
1124} 1132}
1125 1133
@@ -1131,19 +1139,19 @@ GNUNET_TESTBED_operation_queue_destroy_empty_(struct OperationQueue *queue)
1131 * @param opq the operation queue 1139 * @param opq the operation queue
1132 */ 1140 */
1133static void 1141static void
1134recheck_waiting(struct OperationQueue *opq) 1142recheck_waiting (struct OperationQueue *opq)
1135{ 1143{
1136 struct QueueEntry *entry; 1144 struct QueueEntry *entry;
1137 struct QueueEntry *entry2; 1145 struct QueueEntry *entry2;
1138 1146
1139 entry = opq->wq_head; 1147 entry = opq->wq_head;
1140 while (NULL != entry) 1148 while (NULL != entry)
1141 { 1149 {
1142 entry2 = entry->next; 1150 entry2 = entry->next;
1143 if (GNUNET_NO == check_readiness(entry->op)) 1151 if (GNUNET_NO == check_readiness (entry->op))
1144 break; 1152 break;
1145 entry = entry2; 1153 entry = entry2;
1146 } 1154 }
1147} 1155}
1148 1156
1149 1157
@@ -1156,8 +1164,8 @@ recheck_waiting(struct OperationQueue *opq)
1156 * @param max_active the new maximum number of active operations 1164 * @param max_active the new maximum number of active operations
1157 */ 1165 */
1158void 1166void
1159GNUNET_TESTBED_operation_queue_reset_max_active_(struct OperationQueue *queue, 1167GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue,
1160 unsigned int max_active) 1168 unsigned int max_active)
1161{ 1169{
1162 struct QueueEntry *entry; 1170 struct QueueEntry *entry;
1163 1171
@@ -1165,8 +1173,8 @@ GNUNET_TESTBED_operation_queue_reset_max_active_(struct OperationQueue *queue,
1165 queue->overload = 0; 1173 queue->overload = 0;
1166 while ((queue->active > queue->max_active) 1174 while ((queue->active > queue->max_active)
1167 && (NULL != (entry = queue->rq_head))) 1175 && (NULL != (entry = queue->rq_head)))
1168 defer(entry->op); 1176 defer (entry->op);
1169 recheck_waiting(queue); 1177 recheck_waiting (queue);
1170} 1178}
1171 1179
1172 1180
@@ -1182,17 +1190,17 @@ GNUNET_TESTBED_operation_queue_reset_max_active_(struct OperationQueue *queue,
1182 * operation. Should be greater than 0. 1190 * operation. Should be greater than 0.
1183 */ 1191 */
1184void 1192void
1185GNUNET_TESTBED_operation_queue_insert2_(struct OperationQueue *queue, 1193GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue,
1186 struct GNUNET_TESTBED_Operation *op, 1194 struct GNUNET_TESTBED_Operation *op,
1187 unsigned int nres) 1195 unsigned int nres)
1188{ 1196{
1189 unsigned int qsize; 1197 unsigned int qsize;
1190 1198
1191 GNUNET_assert(0 < nres); 1199 GNUNET_assert (0 < nres);
1192 qsize = op->nqueues; 1200 qsize = op->nqueues;
1193 GNUNET_array_append(op->queues, op->nqueues, queue); 1201 GNUNET_array_append (op->queues, op->nqueues, queue);
1194 GNUNET_array_append(op->nres, qsize, nres); 1202 GNUNET_array_append (op->nres, qsize, nres);
1195 GNUNET_assert(qsize == op->nqueues); 1203 GNUNET_assert (qsize == op->nqueues);
1196} 1204}
1197 1205
1198 1206
@@ -1208,10 +1216,10 @@ GNUNET_TESTBED_operation_queue_insert2_(struct OperationQueue *queue,
1208 * @param op operation to add to the queue 1216 * @param op operation to add to the queue
1209 */ 1217 */
1210void 1218void
1211GNUNET_TESTBED_operation_queue_insert_(struct OperationQueue *queue, 1219GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue,
1212 struct GNUNET_TESTBED_Operation *op) 1220 struct GNUNET_TESTBED_Operation *op)
1213{ 1221{
1214 return GNUNET_TESTBED_operation_queue_insert2_(queue, op, 1); 1222 return GNUNET_TESTBED_operation_queue_insert2_ (queue, op, 1);
1215} 1223}
1216 1224
1217 1225
@@ -1225,11 +1233,11 @@ GNUNET_TESTBED_operation_queue_insert_(struct OperationQueue *queue,
1225 * @param op the operation to marks as waiting 1233 * @param op the operation to marks as waiting
1226 */ 1234 */
1227void 1235void
1228GNUNET_TESTBED_operation_begin_wait_(struct GNUNET_TESTBED_Operation *op) 1236GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation *op)
1229{ 1237{
1230 GNUNET_assert(NULL == op->rq_entry); 1238 GNUNET_assert (NULL == op->rq_entry);
1231 change_state(op, OP_STATE_WAITING); 1239 change_state (op, OP_STATE_WAITING);
1232 (void)check_readiness(op); 1240 (void) check_readiness (op);
1233} 1241}
1234 1242
1235 1243
@@ -1243,24 +1251,24 @@ GNUNET_TESTBED_operation_begin_wait_(struct GNUNET_TESTBED_Operation *op)
1243 * it as inactive. 1251 * it as inactive.
1244 */ 1252 */
1245void 1253void
1246GNUNET_TESTBED_operation_inactivate_(struct GNUNET_TESTBED_Operation *op) 1254GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op)
1247{ 1255{
1248 struct OperationQueue **queues; 1256 struct OperationQueue **queues;
1249 size_t ms; 1257 size_t ms;
1250 unsigned int nqueues; 1258 unsigned int nqueues;
1251 unsigned int i; 1259 unsigned int i;
1252 1260
1253 GNUNET_assert(OP_STATE_ACTIVE == op->state); 1261 GNUNET_assert (OP_STATE_ACTIVE == op->state);
1254 change_state(op, OP_STATE_INACTIVE); 1262 change_state (op, OP_STATE_INACTIVE);
1255 nqueues = op->nqueues; 1263 nqueues = op->nqueues;
1256 ms = sizeof(struct OperationQueue *) * nqueues; 1264 ms = sizeof(struct OperationQueue *) * nqueues;
1257 queues = GNUNET_malloc(ms); 1265 queues = GNUNET_malloc (ms);
1258 /* Cloning is needed as the operation be released by waiting operations and 1266 /* Cloning is needed as the operation be released by waiting operations and
1259 hence its nqueues memory ptr will be freed */ 1267 hence its nqueues memory ptr will be freed */
1260 GNUNET_memcpy(queues, op->queues, ms); 1268 GNUNET_memcpy (queues, op->queues, ms);
1261 for (i = 0; i < nqueues; i++) 1269 for (i = 0; i < nqueues; i++)
1262 recheck_waiting(queues[i]); 1270 recheck_waiting (queues[i]);
1263 GNUNET_free(queues); 1271 GNUNET_free (queues);
1264} 1272}
1265 1273
1266 1274
@@ -1272,10 +1280,10 @@ GNUNET_TESTBED_operation_inactivate_(struct GNUNET_TESTBED_Operation *op)
1272 * @param op the operation to be marked as active 1280 * @param op the operation to be marked as active
1273 */ 1281 */
1274void 1282void
1275GNUNET_TESTBED_operation_activate_(struct GNUNET_TESTBED_Operation *op) 1283GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op)
1276{ 1284{
1277 GNUNET_assert(OP_STATE_INACTIVE == op->state); 1285 GNUNET_assert (OP_STATE_INACTIVE == op->state);
1278 change_state(op, OP_STATE_ACTIVE); 1286 change_state (op, OP_STATE_ACTIVE);
1279} 1287}
1280 1288
1281 1289
@@ -1286,56 +1294,56 @@ GNUNET_TESTBED_operation_activate_(struct GNUNET_TESTBED_Operation *op)
1286 * @param op operation that finished 1294 * @param op operation that finished
1287 */ 1295 */
1288void 1296void
1289GNUNET_TESTBED_operation_release_(struct GNUNET_TESTBED_Operation *op) 1297GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op)
1290{ 1298{
1291 struct QueueEntry *entry; 1299 struct QueueEntry *entry;
1292 struct OperationQueue *opq; 1300 struct OperationQueue *opq;
1293 unsigned int i; 1301 unsigned int i;
1294 1302
1295 if (OP_STATE_INIT == op->state) 1303 if (OP_STATE_INIT == op->state)
1296 { 1304 {
1297 GNUNET_free(op); 1305 GNUNET_free (op);
1298 return; 1306 return;
1299 } 1307 }
1300 if (OP_STATE_READY == op->state) 1308 if (OP_STATE_READY == op->state)
1301 rq_remove(op); 1309 rq_remove (op);
1302 if (OP_STATE_INACTIVE == op->state) /* Activate the operation if inactive */ 1310 if (OP_STATE_INACTIVE == op->state) /* Activate the operation if inactive */
1303 GNUNET_TESTBED_operation_activate_(op); 1311 GNUNET_TESTBED_operation_activate_ (op);
1304 if (OP_STATE_ACTIVE == op->state) 1312 if (OP_STATE_ACTIVE == op->state)
1305 update_tslots(op); 1313 update_tslots (op);
1306 GNUNET_assert(NULL != op->queues); 1314 GNUNET_assert (NULL != op->queues);
1307 GNUNET_assert(NULL != op->qentries); 1315 GNUNET_assert (NULL != op->qentries);
1308 for (i = 0; i < op->nqueues; i++) 1316 for (i = 0; i < op->nqueues; i++)
1317 {
1318 entry = op->qentries[i];
1319 remove_queue_entry (op, i);
1320 opq = op->queues[i];
1321 switch (op->state)
1309 { 1322 {
1310 entry = op->qentries[i]; 1323 case OP_STATE_INIT:
1311 remove_queue_entry(op, i); 1324 case OP_STATE_INACTIVE:
1312 opq = op->queues[i]; 1325 GNUNET_assert (0);
1313 switch (op->state) 1326 break;
1314 {
1315 case OP_STATE_INIT:
1316 case OP_STATE_INACTIVE:
1317 GNUNET_assert(0);
1318 break;
1319 1327
1320 case OP_STATE_WAITING: 1328 case OP_STATE_WAITING:
1321 break; 1329 break;
1322 1330
1323 case OP_STATE_ACTIVE: 1331 case OP_STATE_ACTIVE:
1324 case OP_STATE_READY: 1332 case OP_STATE_READY:
1325 GNUNET_assert(0 != opq->active); 1333 GNUNET_assert (0 != opq->active);
1326 GNUNET_assert(opq->active >= entry->nres); 1334 GNUNET_assert (opq->active >= entry->nres);
1327 opq->active -= entry->nres; 1335 opq->active -= entry->nres;
1328 recheck_waiting(opq); 1336 recheck_waiting (opq);
1329 break; 1337 break;
1330 }
1331 GNUNET_free(entry);
1332 } 1338 }
1333 GNUNET_free_non_null(op->qentries); 1339 GNUNET_free (entry);
1334 GNUNET_free(op->queues); 1340 }
1335 GNUNET_free(op->nres); 1341 GNUNET_free_non_null (op->qentries);
1342 GNUNET_free (op->queues);
1343 GNUNET_free (op->nres);
1336 if (NULL != op->release) 1344 if (NULL != op->release)
1337 op->release(op->cb_cls); 1345 op->release (op->cb_cls);
1338 GNUNET_free(op); 1346 GNUNET_free (op);
1339} 1347}
1340 1348
1341 1349
@@ -1345,7 +1353,7 @@ GNUNET_TESTBED_operation_release_(struct GNUNET_TESTBED_Operation *op)
1345 * @param op the operation to be marked as failed 1353 * @param op the operation to be marked as failed
1346 */ 1354 */
1347void 1355void
1348GNUNET_TESTBED_operation_mark_failed(struct GNUNET_TESTBED_Operation *op) 1356GNUNET_TESTBED_operation_mark_failed (struct GNUNET_TESTBED_Operation *op)
1349{ 1357{
1350 op->failed = GNUNET_YES; 1358 op->failed = GNUNET_YES;
1351} 1359}
@@ -1356,23 +1364,23 @@ GNUNET_TESTBED_operation_mark_failed(struct GNUNET_TESTBED_Operation *op)
1356 * operations which are not completed and warn about them. 1364 * operations which are not completed and warn about them.
1357 */ 1365 */
1358void __attribute__ ((destructor)) 1366void __attribute__ ((destructor))
1359GNUNET_TESTBED_operations_fini() 1367GNUNET_TESTBED_operations_fini ()
1360{ 1368{
1361 struct OperationQueue *queue; 1369 struct OperationQueue *queue;
1362 unsigned int i; 1370 unsigned int i;
1363 int warn = 0; 1371 int warn = 0;
1364 1372
1365 for (i = 0; i < n_expired_opqs; i++) 1373 for (i = 0; i < n_expired_opqs; i++)
1366 { 1374 {
1367 queue = expired_opqs[i]; 1375 queue = expired_opqs[i];
1368 if (GNUNET_NO == is_queue_empty(queue)) 1376 if (GNUNET_NO == is_queue_empty (queue))
1369 warn = 1; 1377 warn = 1;
1370 queue_destroy(queue); 1378 queue_destroy (queue);
1371 } 1379 }
1372 GNUNET_free_non_null(expired_opqs); 1380 GNUNET_free_non_null (expired_opqs);
1373 n_expired_opqs = 0; 1381 n_expired_opqs = 0;
1374 if (warn) 1382 if (warn)
1375 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1383 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1376 "Be disciplined. Some operations were not marked as done.\n"); 1384 "Be disciplined. Some operations were not marked as done.\n");
1377} 1385}
1378/* end of testbed_api_operations.c */ 1386/* end of testbed_api_operations.c */
diff --git a/src/testbed/testbed_api_operations.h b/src/testbed/testbed_api_operations.h
index fec518077..2ecbc7b66 100644
--- a/src/testbed/testbed_api_operations.h
+++ b/src/testbed/testbed_api_operations.h
@@ -40,7 +40,8 @@ struct OperationQueue;
40/** 40/**
41 * The type of operation queue 41 * The type of operation queue
42 */ 42 */
43enum OperationQueueType { 43enum OperationQueueType
44{
44 /** 45 /**
45 * Operation queue which permits a fixed maximum number of operations to be 46 * Operation queue which permits a fixed maximum number of operations to be
46 * active at any time 47 * active at any time
@@ -64,8 +65,8 @@ enum OperationQueueType {
64 * @return handle to the queue 65 * @return handle to the queue
65 */ 66 */
66struct OperationQueue * 67struct OperationQueue *
67GNUNET_TESTBED_operation_queue_create_(enum OperationQueueType type, 68GNUNET_TESTBED_operation_queue_create_ (enum OperationQueueType type,
68 unsigned int max_active); 69 unsigned int max_active);
69 70
70 71
71/** 72/**
@@ -75,7 +76,7 @@ GNUNET_TESTBED_operation_queue_create_(enum OperationQueueType type,
75 * @param queue queue to destroy 76 * @param queue queue to destroy
76 */ 77 */
77void 78void
78GNUNET_TESTBED_operation_queue_destroy_(struct OperationQueue *queue); 79GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue);
79 80
80 81
81/** 82/**
@@ -86,7 +87,7 @@ GNUNET_TESTBED_operation_queue_destroy_(struct OperationQueue *queue);
86 * is not empty) 87 * is not empty)
87 */ 88 */
88int 89int
89GNUNET_TESTBED_operation_queue_destroy_empty_(struct OperationQueue *queue); 90GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue);
90 91
91 92
92/** 93/**
@@ -98,8 +99,8 @@ GNUNET_TESTBED_operation_queue_destroy_empty_(struct OperationQueue *queue);
98 * @param max_active the new maximum number of active operations 99 * @param max_active the new maximum number of active operations
99 */ 100 */
100void 101void
101GNUNET_TESTBED_operation_queue_reset_max_active_(struct OperationQueue *queue, 102GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue,
102 unsigned int max_active); 103 unsigned int max_active);
103 104
104 105
105/** 106/**
@@ -114,9 +115,9 @@ GNUNET_TESTBED_operation_queue_reset_max_active_(struct OperationQueue *queue,
114 * operation. Should be greater than 0. 115 * operation. Should be greater than 0.
115 */ 116 */
116void 117void
117GNUNET_TESTBED_operation_queue_insert2_(struct OperationQueue *queue, 118GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue,
118 struct GNUNET_TESTBED_Operation *op, 119 struct GNUNET_TESTBED_Operation *op,
119 unsigned int nres); 120 unsigned int nres);
120 121
121 122
122/** 123/**
@@ -129,8 +130,8 @@ GNUNET_TESTBED_operation_queue_insert2_(struct OperationQueue *queue,
129 * @param op operation to add to the queue 130 * @param op operation to add to the queue
130 */ 131 */
131void 132void
132GNUNET_TESTBED_operation_queue_insert_(struct OperationQueue *queue, 133GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue,
133 struct GNUNET_TESTBED_Operation *op); 134 struct GNUNET_TESTBED_Operation *op);
134 135
135 136
136/** 137/**
@@ -143,7 +144,7 @@ GNUNET_TESTBED_operation_queue_insert_(struct OperationQueue *queue,
143 * @param op the operation to marks as waiting 144 * @param op the operation to marks as waiting
144 */ 145 */
145void 146void
146GNUNET_TESTBED_operation_begin_wait_(struct GNUNET_TESTBED_Operation *op); 147GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation *op);
147 148
148 149
149/** 150/**
@@ -181,8 +182,8 @@ typedef void (*OperationRelease) (void *cls);
181 * @return handle to the operation 182 * @return handle to the operation
182 */ 183 */
183struct GNUNET_TESTBED_Operation * 184struct GNUNET_TESTBED_Operation *
184GNUNET_TESTBED_operation_create_(void *cls, OperationStart start, 185GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start,
185 OperationRelease release); 186 OperationRelease release);
186 187
187 188
188/** 189/**
@@ -192,7 +193,7 @@ GNUNET_TESTBED_operation_create_(void *cls, OperationStart start,
192 * @param op operation that finished 193 * @param op operation that finished
193 */ 194 */
194void 195void
195GNUNET_TESTBED_operation_release_(struct GNUNET_TESTBED_Operation *op); 196GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op);
196 197
197 198
198/** 199/**
@@ -205,7 +206,7 @@ GNUNET_TESTBED_operation_release_(struct GNUNET_TESTBED_Operation *op);
205 * it as inactive. 206 * it as inactive.
206 */ 207 */
207void 208void
208GNUNET_TESTBED_operation_inactivate_(struct GNUNET_TESTBED_Operation *op); 209GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op);
209 210
210 211
211/** 212/**
@@ -216,7 +217,7 @@ GNUNET_TESTBED_operation_inactivate_(struct GNUNET_TESTBED_Operation *op);
216 * @param op the operation to be marked as active 217 * @param op the operation to be marked as active
217 */ 218 */
218void 219void
219GNUNET_TESTBED_operation_activate_(struct GNUNET_TESTBED_Operation *op); 220GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op);
220 221
221 222
222/** 223/**
@@ -225,7 +226,7 @@ GNUNET_TESTBED_operation_activate_(struct GNUNET_TESTBED_Operation *op);
225 * @param op the operation to be marked as failed 226 * @param op the operation to be marked as failed
226 */ 227 */
227void 228void
228GNUNET_TESTBED_operation_mark_failed(struct GNUNET_TESTBED_Operation *op); 229GNUNET_TESTBED_operation_mark_failed (struct GNUNET_TESTBED_Operation *op);
229 230
230 231
231#endif 232#endif
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index 78ed71a42..8d74d956f 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -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 */
53void 53void
54GNUNET_TESTBED_peer_register_(struct GNUNET_TESTBED_Peer *peer) 54GNUNET_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 */
65void 65void
66GNUNET_TESTBED_peer_deregister_(struct GNUNET_TESTBED_Peer *peer) 66GNUNET_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 */
75void 75void
76GNUNET_TESTBED_cleanup_peers_(void) 76GNUNET_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 */
96static void 96static void
97opstart_peer_create(void *cls) 97opstart_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,25 +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 */
140static void 140static void
141oprelease_peer_create(void *cls) 141oprelease_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
150 /* No break we continue flow */ 150 /* No break we continue flow */
151 case OPC_STATE_INIT: 151 case OPC_STATE_INIT:
152 GNUNET_free(((struct PeerCreateData *)opc->data)->peer); 152 GNUNET_free (((struct PeerCreateData *) opc->data)->peer);
153 GNUNET_free(opc->data); 153 GNUNET_free (opc->data);
154 break; 154 break;
155 155
156 case OPC_STATE_FINISHED: 156 case OPC_STATE_FINISHED:
157 break; 157 break;
158 } 158 }
159 GNUNET_free(opc); 159 GNUNET_free (opc);
160} 160}
161 161
162 162
@@ -166,23 +166,23 @@ oprelease_peer_create(void *cls)
166 * @param cls the closure from GNUNET_TESTBED_operation_create_() 166 * @param cls the closure from GNUNET_TESTBED_operation_create_()
167 */ 167 */
168static void 168static void
169opstart_peer_destroy(void *cls) 169opstart_peer_destroy (void *cls)
170{ 170{
171 struct OperationContext *opc = cls; 171 struct OperationContext *opc = cls;
172 struct GNUNET_TESTBED_Peer *peer = opc->data; 172 struct GNUNET_TESTBED_Peer *peer = opc->data;
173 struct GNUNET_TESTBED_PeerDestroyMessage *msg; 173 struct GNUNET_TESTBED_PeerDestroyMessage *msg;
174 struct GNUNET_MQ_Envelope *env; 174 struct GNUNET_MQ_Envelope *env;
175 175
176 GNUNET_assert(OP_PEER_DESTROY == opc->type); 176 GNUNET_assert (OP_PEER_DESTROY == opc->type);
177 GNUNET_assert(NULL != peer); 177 GNUNET_assert (NULL != peer);
178 opc->state = OPC_STATE_STARTED; 178 opc->state = OPC_STATE_STARTED;
179 env = GNUNET_MQ_msg(msg, 179 env = GNUNET_MQ_msg (msg,
180 GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER); 180 GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER);
181 msg->peer_id = htonl(peer->unique_id); 181 msg->peer_id = htonl (peer->unique_id);
182 msg->operation_id = GNUNET_htonll(opc->id); 182 msg->operation_id = GNUNET_htonll (opc->id);
183 GNUNET_TESTBED_insert_opc_(opc->c, opc); 183 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
184 GNUNET_MQ_send(peer->controller->mq, 184 GNUNET_MQ_send (peer->controller->mq,
185 env); 185 env);
186} 186}
187 187
188 188
@@ -192,23 +192,23 @@ opstart_peer_destroy(void *cls)
192 * @param cls the closure from GNUNET_TESTBED_operation_create_() 192 * @param cls the closure from GNUNET_TESTBED_operation_create_()
193 */ 193 */
194static void 194static void
195oprelease_peer_destroy(void *cls) 195oprelease_peer_destroy (void *cls)
196{ 196{
197 struct OperationContext *opc = cls; 197 struct OperationContext *opc = cls;
198 198
199 switch (opc->state) 199 switch (opc->state)
200 { 200 {
201 case OPC_STATE_STARTED: 201 case OPC_STATE_STARTED:
202 GNUNET_TESTBED_remove_opc_(opc->c, opc); 202 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
203 203
204 /* no break; continue */ 204 /* no break; continue */
205 case OPC_STATE_INIT: 205 case OPC_STATE_INIT:
206 break; 206 break;
207 207
208 case OPC_STATE_FINISHED: 208 case OPC_STATE_FINISHED:
209 break; 209 break;
210 } 210 }
211 GNUNET_free(opc); 211 GNUNET_free (opc);
212} 212}
213 213
214 214
@@ -218,7 +218,7 @@ oprelease_peer_destroy(void *cls)
218 * @param cls the closure from GNUNET_TESTBED_operation_create_() 218 * @param cls the closure from GNUNET_TESTBED_operation_create_()
219 */ 219 */
220static void 220static void
221opstart_peer_start(void *cls) 221opstart_peer_start (void *cls)
222{ 222{
223 struct OperationContext *opc = cls; 223 struct OperationContext *opc = cls;
224 struct GNUNET_TESTBED_PeerStartMessage *msg; 224 struct GNUNET_TESTBED_PeerStartMessage *msg;
@@ -226,18 +226,19 @@ opstart_peer_start(void *cls)
226 struct PeerEventData *data; 226 struct PeerEventData *data;
227 struct GNUNET_TESTBED_Peer *peer; 227 struct GNUNET_TESTBED_Peer *peer;
228 228
229 GNUNET_assert(OP_PEER_START == opc->type); 229 GNUNET_assert (OP_PEER_START == opc->type);
230 GNUNET_assert(NULL != (data = opc->data)); 230 GNUNET_assert (NULL != (data = opc->data));
231 GNUNET_assert(NULL != (peer = data->peer)); 231 GNUNET_assert (NULL != (peer = data->peer));
232 GNUNET_assert((TESTBED_PS_CREATED == peer->state) || (TESTBED_PS_STOPPED == peer->state)); 232 GNUNET_assert ((TESTBED_PS_CREATED == peer->state) || (TESTBED_PS_STOPPED ==
233 peer->state));
233 opc->state = OPC_STATE_STARTED; 234 opc->state = OPC_STATE_STARTED;
234 env = GNUNET_MQ_msg(msg, 235 env = GNUNET_MQ_msg (msg,
235 GNUNET_MESSAGE_TYPE_TESTBED_START_PEER); 236 GNUNET_MESSAGE_TYPE_TESTBED_START_PEER);
236 msg->peer_id = htonl(peer->unique_id); 237 msg->peer_id = htonl (peer->unique_id);
237 msg->operation_id = GNUNET_htonll(opc->id); 238 msg->operation_id = GNUNET_htonll (opc->id);
238 GNUNET_TESTBED_insert_opc_(opc->c, opc); 239 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
239 GNUNET_MQ_send(peer->controller->mq, 240 GNUNET_MQ_send (peer->controller->mq,
240 env); 241 env);
241} 242}
242 243
243 244
@@ -247,24 +248,24 @@ opstart_peer_start(void *cls)
247 * @param cls the closure from GNUNET_TESTBED_operation_create_() 248 * @param cls the closure from GNUNET_TESTBED_operation_create_()
248 */ 249 */
249static void 250static void
250oprelease_peer_start(void *cls) 251oprelease_peer_start (void *cls)
251{ 252{
252 struct OperationContext *opc = cls; 253 struct OperationContext *opc = cls;
253 254
254 switch (opc->state) 255 switch (opc->state)
255 { 256 {
256 case OPC_STATE_STARTED: 257 case OPC_STATE_STARTED:
257 GNUNET_TESTBED_remove_opc_(opc->c, opc); 258 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
258 259
259 /* no break; continue */ 260 /* no break; continue */
260 case OPC_STATE_INIT: 261 case OPC_STATE_INIT:
261 GNUNET_free(opc->data); 262 GNUNET_free (opc->data);
262 break; 263 break;
263 264
264 case OPC_STATE_FINISHED: 265 case OPC_STATE_FINISHED:
265 break; 266 break;
266 } 267 }
267 GNUNET_free(opc); 268 GNUNET_free (opc);
268} 269}
269 270
270 271
@@ -274,7 +275,7 @@ oprelease_peer_start(void *cls)
274 * @param cls the closure from GNUNET_TESTBED_operation_create_() 275 * @param cls the closure from GNUNET_TESTBED_operation_create_()
275 */ 276 */
276static void 277static void
277opstart_peer_stop(void *cls) 278opstart_peer_stop (void *cls)
278{ 279{
279 struct OperationContext *opc = cls; 280 struct OperationContext *opc = cls;
280 struct GNUNET_TESTBED_PeerStopMessage *msg; 281 struct GNUNET_TESTBED_PeerStopMessage *msg;
@@ -282,17 +283,17 @@ opstart_peer_stop(void *cls)
282 struct GNUNET_TESTBED_Peer *peer; 283 struct GNUNET_TESTBED_Peer *peer;
283 struct GNUNET_MQ_Envelope *env; 284 struct GNUNET_MQ_Envelope *env;
284 285
285 GNUNET_assert(NULL != (data = opc->data)); 286 GNUNET_assert (NULL != (data = opc->data));
286 GNUNET_assert(NULL != (peer = data->peer)); 287 GNUNET_assert (NULL != (peer = data->peer));
287 GNUNET_assert(TESTBED_PS_STARTED == peer->state); 288 GNUNET_assert (TESTBED_PS_STARTED == peer->state);
288 opc->state = OPC_STATE_STARTED; 289 opc->state = OPC_STATE_STARTED;
289 env = GNUNET_MQ_msg(msg, 290 env = GNUNET_MQ_msg (msg,
290 GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER); 291 GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER);
291 msg->peer_id = htonl(peer->unique_id); 292 msg->peer_id = htonl (peer->unique_id);
292 msg->operation_id = GNUNET_htonll(opc->id); 293 msg->operation_id = GNUNET_htonll (opc->id);
293 GNUNET_TESTBED_insert_opc_(opc->c, opc); 294 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
294 GNUNET_MQ_send(peer->controller->mq, 295 GNUNET_MQ_send (peer->controller->mq,
295 env); 296 env);
296} 297}
297 298
298 299
@@ -302,24 +303,24 @@ opstart_peer_stop(void *cls)
302 * @param cls the closure from GNUNET_TESTBED_operation_create_() 303 * @param cls the closure from GNUNET_TESTBED_operation_create_()
303 */ 304 */
304static void 305static void
305oprelease_peer_stop(void *cls) 306oprelease_peer_stop (void *cls)
306{ 307{
307 struct OperationContext *opc = cls; 308 struct OperationContext *opc = cls;
308 309
309 switch (opc->state) 310 switch (opc->state)
310 { 311 {
311 case OPC_STATE_STARTED: 312 case OPC_STATE_STARTED:
312 GNUNET_TESTBED_remove_opc_(opc->c, opc); 313 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
313 314
314 /* no break; continue */ 315 /* no break; continue */
315 case OPC_STATE_INIT: 316 case OPC_STATE_INIT:
316 GNUNET_free(opc->data); 317 GNUNET_free (opc->data);
317 break; 318 break;
318 319
319 case OPC_STATE_FINISHED: 320 case OPC_STATE_FINISHED:
320 break; 321 break;
321 } 322 }
322 GNUNET_free(opc); 323 GNUNET_free (opc);
323} 324}
324 325
325 326
@@ -332,19 +333,19 @@ oprelease_peer_stop(void *cls)
332 * @return the PeerGetConfigurationMessage 333 * @return the PeerGetConfigurationMessage
333 */ 334 */
334struct GNUNET_TESTBED_PeerGetConfigurationMessage * 335struct GNUNET_TESTBED_PeerGetConfigurationMessage *
335GNUNET_TESTBED_generate_peergetconfig_msg_(uint32_t peer_id, 336GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id,
336 uint64_t operation_id) 337 uint64_t operation_id)
337{ 338{
338 struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; 339 struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
339 340
340 msg = 341 msg =
341 GNUNET_malloc(sizeof 342 GNUNET_malloc (sizeof
342 (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); 343 (struct GNUNET_TESTBED_PeerGetConfigurationMessage));
343 msg->header.size = 344 msg->header.size =
344 htons(sizeof(struct GNUNET_TESTBED_PeerGetConfigurationMessage)); 345 htons (sizeof(struct GNUNET_TESTBED_PeerGetConfigurationMessage));
345 msg->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION); 346 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION);
346 msg->peer_id = htonl(peer_id); 347 msg->peer_id = htonl (peer_id);
347 msg->operation_id = GNUNET_htonll(operation_id); 348 msg->operation_id = GNUNET_htonll (operation_id);
348 return msg; 349 return msg;
349} 350}
350 351
@@ -355,19 +356,19 @@ GNUNET_TESTBED_generate_peergetconfig_msg_(uint32_t peer_id,
355 * @param cls the closure from GNUNET_TESTBED_operation_create_() 356 * @param cls the closure from GNUNET_TESTBED_operation_create_()
356 */ 357 */
357static void 358static void
358opstart_peer_getinfo(void *cls) 359opstart_peer_getinfo (void *cls)
359{ 360{
360 struct OperationContext *opc = cls; 361 struct OperationContext *opc = cls;
361 struct PeerInfoData *data = opc->data; 362 struct PeerInfoData *data = opc->data;
362 struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; 363 struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
363 364
364 GNUNET_assert(NULL != data); 365 GNUNET_assert (NULL != data);
365 opc->state = OPC_STATE_STARTED; 366 opc->state = OPC_STATE_STARTED;
366 msg = 367 msg =
367 GNUNET_TESTBED_generate_peergetconfig_msg_(data->peer->unique_id, 368 GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id,
368 opc->id); 369 opc->id);
369 GNUNET_TESTBED_insert_opc_(opc->c, opc); 370 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
370 GNUNET_TESTBED_queue_message_(opc->c, &msg->header); 371 GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
371} 372}
372 373
373 374
@@ -377,42 +378,42 @@ opstart_peer_getinfo(void *cls)
377 * @param cls the closure from GNUNET_TESTBED_operation_create_() 378 * @param cls the closure from GNUNET_TESTBED_operation_create_()
378 */ 379 */
379static void 380static void
380oprelease_peer_getinfo(void *cls) 381oprelease_peer_getinfo (void *cls)
381{ 382{
382 struct OperationContext *opc = cls; 383 struct OperationContext *opc = cls;
383 struct GNUNET_TESTBED_PeerInformation *data; 384 struct GNUNET_TESTBED_PeerInformation *data;
384 385
385 switch (opc->state) 386 switch (opc->state)
387 {
388 case OPC_STATE_STARTED:
389 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
390
391 /* no break; continue */
392 case OPC_STATE_INIT:
393 GNUNET_free (opc->data);
394 break;
395
396 case OPC_STATE_FINISHED:
397 data = opc->data;
398 GNUNET_assert (NULL != data);
399 switch (data->pit)
386 { 400 {
387 case OPC_STATE_STARTED: 401 case GNUNET_TESTBED_PIT_CONFIGURATION:
388 GNUNET_TESTBED_remove_opc_(opc->c, opc); 402 if (NULL != data->result.cfg)
389 403 GNUNET_CONFIGURATION_destroy (data->result.cfg);
390 /* no break; continue */
391 case OPC_STATE_INIT:
392 GNUNET_free(opc->data);
393 break; 404 break;
394 405
395 case OPC_STATE_FINISHED: 406 case GNUNET_TESTBED_PIT_IDENTITY:
396 data = opc->data; 407 GNUNET_free (data->result.id);
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);
413 break; 408 break;
409
410 default:
411 GNUNET_assert (0); /* We should never reach here */
414 } 412 }
415 GNUNET_free(opc); 413 GNUNET_free (data);
414 break;
415 }
416 GNUNET_free (opc);
416} 417}
417 418
418 419
@@ -422,7 +423,7 @@ oprelease_peer_getinfo(void *cls)
422 * @param cls the closure from GNUNET_TESTBED_operation_create_() 423 * @param cls the closure from GNUNET_TESTBED_operation_create_()
423 */ 424 */
424static void 425static void
425opstart_overlay_connect(void *cls) 426opstart_overlay_connect (void *cls)
426{ 427{
427 struct OperationContext *opc = cls; 428 struct OperationContext *opc = cls;
428 struct GNUNET_MQ_Envelope *env; 429 struct GNUNET_MQ_Envelope *env;
@@ -431,17 +432,17 @@ opstart_overlay_connect(void *cls)
431 432
432 opc->state = OPC_STATE_STARTED; 433 opc->state = OPC_STATE_STARTED;
433 data = opc->data; 434 data = opc->data;
434 GNUNET_assert(NULL != data); 435 GNUNET_assert (NULL != data);
435 env = GNUNET_MQ_msg(msg, 436 env = GNUNET_MQ_msg (msg,
436 GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT); 437 GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT);
437 msg->peer1 = htonl(data->p1->unique_id); 438 msg->peer1 = htonl (data->p1->unique_id);
438 msg->peer2 = htonl(data->p2->unique_id); 439 msg->peer2 = htonl (data->p2->unique_id);
439 msg->operation_id = GNUNET_htonll(opc->id); 440 msg->operation_id = GNUNET_htonll (opc->id);
440 msg->peer2_host_id = htonl(GNUNET_TESTBED_host_get_id_(data->p2->host)); 441 msg->peer2_host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->p2->host));
441 GNUNET_TESTBED_insert_opc_(opc->c, 442 GNUNET_TESTBED_insert_opc_ (opc->c,
442 opc); 443 opc);
443 GNUNET_MQ_send(opc->c->mq, 444 GNUNET_MQ_send (opc->c->mq,
444 env); 445 env);
445} 446}
446 447
447 448
@@ -451,26 +452,26 @@ opstart_overlay_connect(void *cls)
451 * @param cls the closure from GNUNET_TESTBED_operation_create_() 452 * @param cls the closure from GNUNET_TESTBED_operation_create_()
452 */ 453 */
453static void 454static void
454oprelease_overlay_connect(void *cls) 455oprelease_overlay_connect (void *cls)
455{ 456{
456 struct OperationContext *opc = cls; 457 struct OperationContext *opc = cls;
457 struct OverlayConnectData *data; 458 struct OverlayConnectData *data;
458 459
459 data = opc->data; 460 data = opc->data;
460 switch (opc->state) 461 switch (opc->state)
461 { 462 {
462 case OPC_STATE_INIT: 463 case OPC_STATE_INIT:
463 break; 464 break;
464 465
465 case OPC_STATE_STARTED: 466 case OPC_STATE_STARTED:
466 GNUNET_TESTBED_remove_opc_(opc->c, opc); 467 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
467 break; 468 break;
468 469
469 case OPC_STATE_FINISHED: 470 case OPC_STATE_FINISHED:
470 break; 471 break;
471 } 472 }
472 GNUNET_free(data); 473 GNUNET_free (data);
473 GNUNET_free(opc); 474 GNUNET_free (opc);
474} 475}
475 476
476 477
@@ -480,7 +481,7 @@ oprelease_overlay_connect(void *cls)
480 * @param cls the closure from GNUNET_TESTBED_operation_create_() 481 * @param cls the closure from GNUNET_TESTBED_operation_create_()
481 */ 482 */
482static void 483static void
483opstart_peer_reconfigure(void *cls) 484opstart_peer_reconfigure (void *cls)
484{ 485{
485 struct OperationContext *opc = cls; 486 struct OperationContext *opc = cls;
486 struct PeerReconfigureData *data = opc->data; 487 struct PeerReconfigureData *data = opc->data;
@@ -490,28 +491,28 @@ opstart_peer_reconfigure(void *cls)
490 size_t xc_size; 491 size_t xc_size;
491 492
492 opc->state = OPC_STATE_STARTED; 493 opc->state = OPC_STATE_STARTED;
493 GNUNET_assert(NULL != data); 494 GNUNET_assert (NULL != data);
494 xc_size = GNUNET_TESTBED_compress_config_(data->config, 495 xc_size = GNUNET_TESTBED_compress_config_ (data->config,
495 data->cfg_size, 496 data->cfg_size,
496 &xconfig); 497 &xconfig);
497 GNUNET_free(data->config); 498 GNUNET_free (data->config);
498 data->config = NULL; 499 data->config = NULL;
499 GNUNET_assert(xc_size < UINT16_MAX - sizeof(*msg)); 500 GNUNET_assert (xc_size < UINT16_MAX - sizeof(*msg));
500 env = GNUNET_MQ_msg_extra(msg, 501 env = GNUNET_MQ_msg_extra (msg,
501 xc_size, 502 xc_size,
502 GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER); 503 GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER);
503 msg->peer_id = htonl(data->peer->unique_id); 504 msg->peer_id = htonl (data->peer->unique_id);
504 msg->operation_id = GNUNET_htonll(opc->id); 505 msg->operation_id = GNUNET_htonll (opc->id);
505 msg->config_size = htons(data->cfg_size); 506 msg->config_size = htons (data->cfg_size);
506 GNUNET_memcpy(&msg[1], 507 GNUNET_memcpy (&msg[1],
507 xconfig, 508 xconfig,
508 xc_size); 509 xc_size);
509 GNUNET_free(xconfig); 510 GNUNET_free (xconfig);
510 GNUNET_free(data); 511 GNUNET_free (data);
511 opc->data = NULL; 512 opc->data = NULL;
512 GNUNET_TESTBED_insert_opc_(opc->c, opc); 513 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
513 GNUNET_MQ_send(opc->c->mq, 514 GNUNET_MQ_send (opc->c->mq,
514 env); 515 env);
515} 516}
516 517
517 518
@@ -521,26 +522,26 @@ opstart_peer_reconfigure(void *cls)
521 * @param cls the closure from GNUNET_TESTBED_operation_create_() 522 * @param cls the closure from GNUNET_TESTBED_operation_create_()
522 */ 523 */
523static void 524static void
524oprelease_peer_reconfigure(void *cls) 525oprelease_peer_reconfigure (void *cls)
525{ 526{
526 struct OperationContext *opc = cls; 527 struct OperationContext *opc = cls;
527 struct PeerReconfigureData *data = opc->data; 528 struct PeerReconfigureData *data = opc->data;
528 529
529 switch (opc->state) 530 switch (opc->state)
530 { 531 {
531 case OPC_STATE_INIT: 532 case OPC_STATE_INIT:
532 GNUNET_free(data->config); 533 GNUNET_free (data->config);
533 GNUNET_free(data); 534 GNUNET_free (data);
534 break; 535 break;
535 536
536 case OPC_STATE_STARTED: 537 case OPC_STATE_STARTED:
537 GNUNET_TESTBED_remove_opc_(opc->c, opc); 538 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
538 break; 539 break;
539 540
540 case OPC_STATE_FINISHED: 541 case OPC_STATE_FINISHED:
541 break; 542 break;
542 } 543 }
543 GNUNET_free(opc); 544 GNUNET_free (opc);
544} 545}
545 546
546 547
@@ -551,9 +552,9 @@ oprelease_peer_reconfigure(void *cls)
551 * @return handle to the host, NULL on error 552 * @return handle to the host, NULL on error
552 */ 553 */
553struct GNUNET_TESTBED_Peer * 554struct GNUNET_TESTBED_Peer *
554GNUNET_TESTBED_peer_lookup_by_id_(uint32_t id) 555GNUNET_TESTBED_peer_lookup_by_id_ (uint32_t id)
555{ 556{
556 GNUNET_break(0); 557 GNUNET_break (0);
557 return NULL; 558 return NULL;
558} 559}
559 560
@@ -588,38 +589,38 @@ GNUNET_TESTBED_peer_lookup_by_id_(uint32_t id)
588 * @return the operation handle 589 * @return the operation handle
589 */ 590 */
590struct GNUNET_TESTBED_Operation * 591struct GNUNET_TESTBED_Operation *
591GNUNET_TESTBED_peer_create(struct GNUNET_TESTBED_Controller *controller, 592GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
592 struct GNUNET_TESTBED_Host *host, 593 struct GNUNET_TESTBED_Host *host,
593 const struct GNUNET_CONFIGURATION_Handle *cfg, 594 const struct GNUNET_CONFIGURATION_Handle *cfg,
594 GNUNET_TESTBED_PeerCreateCallback cb, void *cls) 595 GNUNET_TESTBED_PeerCreateCallback cb, void *cls)
595{ 596{
596 struct GNUNET_TESTBED_Peer *peer; 597 struct GNUNET_TESTBED_Peer *peer;
597 struct PeerCreateData *data; 598 struct PeerCreateData *data;
598 struct OperationContext *opc; 599 struct OperationContext *opc;
599 static uint32_t id_gen; 600 static uint32_t id_gen;
600 601
601 peer = GNUNET_new(struct GNUNET_TESTBED_Peer); 602 peer = GNUNET_new (struct GNUNET_TESTBED_Peer);
602 peer->controller = controller; 603 peer->controller = controller;
603 peer->host = host; 604 peer->host = host;
604 peer->unique_id = id_gen++; 605 peer->unique_id = id_gen++;
605 peer->state = TESTBED_PS_INVALID; 606 peer->state = TESTBED_PS_INVALID;
606 data = GNUNET_new(struct PeerCreateData); 607 data = GNUNET_new (struct PeerCreateData);
607 data->host = host; 608 data->host = host;
608 data->cfg = cfg; 609 data->cfg = cfg;
609 data->cb = cb; 610 data->cb = cb;
610 data->cls = cls; 611 data->cls = cls;
611 data->peer = peer; 612 data->peer = peer;
612 opc = GNUNET_new(struct OperationContext); 613 opc = GNUNET_new (struct OperationContext);
613 opc->c = controller; 614 opc->c = controller;
614 opc->data = data; 615 opc->data = data;
615 opc->id = GNUNET_TESTBED_get_next_op_id(controller); 616 opc->id = GNUNET_TESTBED_get_next_op_id (controller);
616 opc->type = OP_PEER_CREATE; 617 opc->type = OP_PEER_CREATE;
617 opc->op = 618 opc->op =
618 GNUNET_TESTBED_operation_create_(opc, &opstart_peer_create, 619 GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_create,
619 &oprelease_peer_create); 620 &oprelease_peer_create);
620 GNUNET_TESTBED_operation_queue_insert_(controller->opq_parallel_operations, 621 GNUNET_TESTBED_operation_queue_insert_ (controller->opq_parallel_operations,
621 opc->op); 622 opc->op);
622 GNUNET_TESTBED_operation_begin_wait_(opc->op); 623 GNUNET_TESTBED_operation_begin_wait_ (opc->op);
623 return opc->op; 624 return opc->op;
624} 625}
625 626
@@ -635,28 +636,28 @@ GNUNET_TESTBED_peer_create(struct GNUNET_TESTBED_Controller *controller,
635 * @return handle to the operation 636 * @return handle to the operation
636 */ 637 */
637struct GNUNET_TESTBED_Operation * 638struct GNUNET_TESTBED_Operation *
638GNUNET_TESTBED_peer_start(void *op_cls, struct GNUNET_TESTBED_Peer *peer, 639GNUNET_TESTBED_peer_start (void *op_cls, struct GNUNET_TESTBED_Peer *peer,
639 GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls) 640 GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls)
640{ 641{
641 struct OperationContext *opc; 642 struct OperationContext *opc;
642 struct PeerEventData *data; 643 struct PeerEventData *data;
643 644
644 data = GNUNET_new(struct PeerEventData); 645 data = GNUNET_new (struct PeerEventData);
645 data->peer = peer; 646 data->peer = peer;
646 data->pcc = pcc; 647 data->pcc = pcc;
647 data->pcc_cls = pcc_cls; 648 data->pcc_cls = pcc_cls;
648 opc = GNUNET_new(struct OperationContext); 649 opc = GNUNET_new (struct OperationContext);
649 opc->c = peer->controller; 650 opc->c = peer->controller;
650 opc->data = data; 651 opc->data = data;
651 opc->op_cls = op_cls; 652 opc->op_cls = op_cls;
652 opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); 653 opc->id = GNUNET_TESTBED_get_next_op_id (opc->c);
653 opc->type = OP_PEER_START; 654 opc->type = OP_PEER_START;
654 opc->op = 655 opc->op =
655 GNUNET_TESTBED_operation_create_(opc, &opstart_peer_start, 656 GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_start,
656 &oprelease_peer_start); 657 &oprelease_peer_start);
657 GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, 658 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
658 opc->op); 659 opc->op);
659 GNUNET_TESTBED_operation_begin_wait_(opc->op); 660 GNUNET_TESTBED_operation_begin_wait_ (opc->op);
660 return opc->op; 661 return opc->op;
661} 662}
662 663
@@ -674,29 +675,29 @@ GNUNET_TESTBED_peer_start(void *op_cls, struct GNUNET_TESTBED_Peer *peer,
674 * @return handle to the operation 675 * @return handle to the operation
675 */ 676 */
676struct GNUNET_TESTBED_Operation * 677struct GNUNET_TESTBED_Operation *
677GNUNET_TESTBED_peer_stop(void *op_cls, 678GNUNET_TESTBED_peer_stop (void *op_cls,
678 struct GNUNET_TESTBED_Peer *peer, 679 struct GNUNET_TESTBED_Peer *peer,
679 GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls) 680 GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls)
680{ 681{
681 struct OperationContext *opc; 682 struct OperationContext *opc;
682 struct PeerEventData *data; 683 struct PeerEventData *data;
683 684
684 data = GNUNET_new(struct PeerEventData); 685 data = GNUNET_new (struct PeerEventData);
685 data->peer = peer; 686 data->peer = peer;
686 data->pcc = pcc; 687 data->pcc = pcc;
687 data->pcc_cls = pcc_cls; 688 data->pcc_cls = pcc_cls;
688 opc = GNUNET_new(struct OperationContext); 689 opc = GNUNET_new (struct OperationContext);
689 opc->c = peer->controller; 690 opc->c = peer->controller;
690 opc->data = data; 691 opc->data = data;
691 opc->op_cls = op_cls; 692 opc->op_cls = op_cls;
692 opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); 693 opc->id = GNUNET_TESTBED_get_next_op_id (opc->c);
693 opc->type = OP_PEER_STOP; 694 opc->type = OP_PEER_STOP;
694 opc->op = 695 opc->op =
695 GNUNET_TESTBED_operation_create_(opc, &opstart_peer_stop, 696 GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_stop,
696 &oprelease_peer_stop); 697 &oprelease_peer_stop);
697 GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, 698 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
698 opc->op); 699 opc->op);
699 GNUNET_TESTBED_operation_begin_wait_(opc->op); 700 GNUNET_TESTBED_operation_begin_wait_ (opc->op);
700 return opc->op; 701 return opc->op;
701} 702}
702 703
@@ -716,32 +717,32 @@ GNUNET_TESTBED_peer_stop(void *op_cls,
716 * @return handle to the operation 717 * @return handle to the operation
717 */ 718 */
718struct GNUNET_TESTBED_Operation * 719struct GNUNET_TESTBED_Operation *
719GNUNET_TESTBED_peer_get_information(struct GNUNET_TESTBED_Peer *peer, 720GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
720 enum GNUNET_TESTBED_PeerInformationType 721 enum GNUNET_TESTBED_PeerInformationType
721 pit, GNUNET_TESTBED_PeerInfoCallback cb, 722 pit, GNUNET_TESTBED_PeerInfoCallback cb,
722 void *cb_cls) 723 void *cb_cls)
723{ 724{
724 struct OperationContext *opc; 725 struct OperationContext *opc;
725 struct PeerInfoData *data; 726 struct PeerInfoData *data;
726 727
727 GNUNET_assert(GNUNET_TESTBED_PIT_GENERIC != pit); 728 GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC != pit);
728 GNUNET_assert(NULL != cb); 729 GNUNET_assert (NULL != cb);
729 data = GNUNET_new(struct PeerInfoData); 730 data = GNUNET_new (struct PeerInfoData);
730 data->peer = peer; 731 data->peer = peer;
731 data->pit = pit; 732 data->pit = pit;
732 data->cb = cb; 733 data->cb = cb;
733 data->cb_cls = cb_cls; 734 data->cb_cls = cb_cls;
734 opc = GNUNET_new(struct OperationContext); 735 opc = GNUNET_new (struct OperationContext);
735 opc->c = peer->controller; 736 opc->c = peer->controller;
736 opc->data = data; 737 opc->data = data;
737 opc->type = OP_PEER_INFO; 738 opc->type = OP_PEER_INFO;
738 opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); 739 opc->id = GNUNET_TESTBED_get_next_op_id (opc->c);
739 opc->op = 740 opc->op =
740 GNUNET_TESTBED_operation_create_(opc, &opstart_peer_getinfo, 741 GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_getinfo,
741 &oprelease_peer_getinfo); 742 &oprelease_peer_getinfo);
742 GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, 743 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
743 opc->op); 744 opc->op);
744 GNUNET_TESTBED_operation_begin_wait_(opc->op); 745 GNUNET_TESTBED_operation_begin_wait_ (opc->op);
745 return opc->op; 746 return opc->op;
746} 747}
747 748
@@ -757,41 +758,41 @@ GNUNET_TESTBED_peer_get_information(struct GNUNET_TESTBED_Peer *peer,
757 * @return handle to the operation 758 * @return handle to the operation
758 */ 759 */
759struct GNUNET_TESTBED_Operation * 760struct GNUNET_TESTBED_Operation *
760GNUNET_TESTBED_peer_update_configuration(struct GNUNET_TESTBED_Peer *peer, 761GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
761 const struct 762 const struct
762 GNUNET_CONFIGURATION_Handle *cfg) 763 GNUNET_CONFIGURATION_Handle *cfg)
763{ 764{
764 struct OperationContext *opc; 765 struct OperationContext *opc;
765 struct PeerReconfigureData *data; 766 struct PeerReconfigureData *data;
766 size_t csize; 767 size_t csize;
767 768
768 data = GNUNET_new(struct PeerReconfigureData); 769 data = GNUNET_new (struct PeerReconfigureData);
769 data->peer = peer; 770 data->peer = peer;
770 data->config = GNUNET_CONFIGURATION_serialize(cfg, &csize); 771 data->config = GNUNET_CONFIGURATION_serialize (cfg, &csize);
771 if (NULL == data->config) 772 if (NULL == data->config)
772 { 773 {
773 GNUNET_free(data); 774 GNUNET_free (data);
774 return NULL; 775 return NULL;
775 } 776 }
776 if (csize > UINT16_MAX) 777 if (csize > UINT16_MAX)
777 { 778 {
778 GNUNET_break(0); 779 GNUNET_break (0);
779 GNUNET_free(data->config); 780 GNUNET_free (data->config);
780 GNUNET_free(data); 781 GNUNET_free (data);
781 return NULL; 782 return NULL;
782 } 783 }
783 data->cfg_size = (uint16_t)csize; 784 data->cfg_size = (uint16_t) csize;
784 opc = GNUNET_new(struct OperationContext); 785 opc = GNUNET_new (struct OperationContext);
785 opc->c = peer->controller; 786 opc->c = peer->controller;
786 opc->data = data; 787 opc->data = data;
787 opc->type = OP_PEER_RECONFIGURE; 788 opc->type = OP_PEER_RECONFIGURE;
788 opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); 789 opc->id = GNUNET_TESTBED_get_next_op_id (opc->c);
789 opc->op = 790 opc->op =
790 GNUNET_TESTBED_operation_create_(opc, &opstart_peer_reconfigure, 791 GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_reconfigure,
791 &oprelease_peer_reconfigure); 792 &oprelease_peer_reconfigure);
792 GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, 793 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
793 opc->op); 794 opc->op);
794 GNUNET_TESTBED_operation_begin_wait_(opc->op); 795 GNUNET_TESTBED_operation_begin_wait_ (opc->op);
795 return opc->op; 796 return opc->op;
796} 797}
797 798
@@ -804,21 +805,21 @@ GNUNET_TESTBED_peer_update_configuration(struct GNUNET_TESTBED_Peer *peer,
804 * @return handle to the operation 805 * @return handle to the operation
805 */ 806 */
806struct GNUNET_TESTBED_Operation * 807struct GNUNET_TESTBED_Operation *
807GNUNET_TESTBED_peer_destroy(struct GNUNET_TESTBED_Peer *peer) 808GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer)
808{ 809{
809 struct OperationContext *opc; 810 struct OperationContext *opc;
810 811
811 opc = GNUNET_new(struct OperationContext); 812 opc = GNUNET_new (struct OperationContext);
812 opc->data = peer; 813 opc->data = peer;
813 opc->c = peer->controller; 814 opc->c = peer->controller;
814 opc->id = GNUNET_TESTBED_get_next_op_id(peer->controller); 815 opc->id = GNUNET_TESTBED_get_next_op_id (peer->controller);
815 opc->type = OP_PEER_DESTROY; 816 opc->type = OP_PEER_DESTROY;
816 opc->op = 817 opc->op =
817 GNUNET_TESTBED_operation_create_(opc, &opstart_peer_destroy, 818 GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_destroy,
818 &oprelease_peer_destroy); 819 &oprelease_peer_destroy);
819 GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, 820 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
820 opc->op); 821 opc->op);
821 GNUNET_TESTBED_operation_begin_wait_(opc->op); 822 GNUNET_TESTBED_operation_begin_wait_ (opc->op);
822 return opc->op; 823 return opc->op;
823} 824}
824 825
@@ -836,13 +837,13 @@ GNUNET_TESTBED_peer_destroy(struct GNUNET_TESTBED_Peer *peer)
836 * time is not allowed 837 * time is not allowed
837 */ 838 */
838struct GNUNET_TESTBED_Operation * 839struct GNUNET_TESTBED_Operation *
839GNUNET_TESTBED_underlay_configure_link(void *op_cls, 840GNUNET_TESTBED_underlay_configure_link (void *op_cls,
840 struct GNUNET_TESTBED_Peer *p1, 841 struct GNUNET_TESTBED_Peer *p1,
841 struct GNUNET_TESTBED_Peer *p2, 842 struct GNUNET_TESTBED_Peer *p2,
842 enum GNUNET_TESTBED_ConnectOption co, 843 enum GNUNET_TESTBED_ConnectOption co,
843 ...) 844 ...)
844{ 845{
845 GNUNET_break(0); 846 GNUNET_break (0);
846 return NULL; 847 return NULL;
847} 848}
848 849
@@ -862,31 +863,32 @@ GNUNET_TESTBED_underlay_configure_link(void *op_cls,
862 * not running or underlay disallows) 863 * not running or underlay disallows)
863 */ 864 */
864struct GNUNET_TESTBED_Operation * 865struct GNUNET_TESTBED_Operation *
865GNUNET_TESTBED_overlay_connect(void *op_cls, 866GNUNET_TESTBED_overlay_connect (void *op_cls,
866 GNUNET_TESTBED_OperationCompletionCallback cb, 867 GNUNET_TESTBED_OperationCompletionCallback cb,
867 void *cb_cls, struct GNUNET_TESTBED_Peer *p1, 868 void *cb_cls, struct GNUNET_TESTBED_Peer *p1,
868 struct GNUNET_TESTBED_Peer *p2) 869 struct GNUNET_TESTBED_Peer *p2)
869{ 870{
870 struct OperationContext *opc; 871 struct OperationContext *opc;
871 struct OverlayConnectData *data; 872 struct OverlayConnectData *data;
872 873
873 GNUNET_assert((TESTBED_PS_STARTED == p1->state) && (TESTBED_PS_STARTED == p2->state)); 874 GNUNET_assert ((TESTBED_PS_STARTED == p1->state) && (TESTBED_PS_STARTED ==
874 data = GNUNET_new(struct OverlayConnectData); 875 p2->state));
876 data = GNUNET_new (struct OverlayConnectData);
875 data->p1 = p1; 877 data->p1 = p1;
876 data->p2 = p2; 878 data->p2 = p2;
877 data->cb = cb; 879 data->cb = cb;
878 data->cb_cls = cb_cls; 880 data->cb_cls = cb_cls;
879 opc = GNUNET_new(struct OperationContext); 881 opc = GNUNET_new (struct OperationContext);
880 opc->data = data; 882 opc->data = data;
881 opc->c = p1->controller; 883 opc->c = p1->controller;
882 opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); 884 opc->id = GNUNET_TESTBED_get_next_op_id (opc->c);
883 opc->type = OP_OVERLAY_CONNECT; 885 opc->type = OP_OVERLAY_CONNECT;
884 opc->op_cls = op_cls; 886 opc->op_cls = op_cls;
885 opc->op = 887 opc->op =
886 GNUNET_TESTBED_operation_create_(opc, &opstart_overlay_connect, 888 GNUNET_TESTBED_operation_create_ (opc, &opstart_overlay_connect,
887 &oprelease_overlay_connect); 889 &oprelease_overlay_connect);
888 GNUNET_TESTBED_host_queue_oc_(p1->host, opc->op); 890 GNUNET_TESTBED_host_queue_oc_ (p1->host, opc->op);
889 GNUNET_TESTBED_operation_begin_wait_(opc->op); 891 GNUNET_TESTBED_operation_begin_wait_ (opc->op);
890 return opc->op; 892 return opc->op;
891} 893}
892 894
@@ -897,7 +899,7 @@ GNUNET_TESTBED_overlay_connect(void *op_cls,
897 * @param cls the closure from GNUNET_TESTBED_operation_create_() 899 * @param cls the closure from GNUNET_TESTBED_operation_create_()
898 */ 900 */
899static void 901static void
900opstart_manage_service(void *cls) 902opstart_manage_service (void *cls)
901{ 903{
902 struct OperationContext *opc = cls; 904 struct OperationContext *opc = cls;
903 struct ManageServiceData *data = opc->data; 905 struct ManageServiceData *data = opc->data;
@@ -905,23 +907,23 @@ opstart_manage_service(void *cls)
905 struct GNUNET_TESTBED_ManagePeerServiceMessage *msg; 907 struct GNUNET_TESTBED_ManagePeerServiceMessage *msg;
906 size_t xlen; 908 size_t xlen;
907 909
908 GNUNET_assert(NULL != data); 910 GNUNET_assert (NULL != data);
909 xlen = data->msize - sizeof(struct GNUNET_TESTBED_ManagePeerServiceMessage); 911 xlen = data->msize - sizeof(struct GNUNET_TESTBED_ManagePeerServiceMessage);
910 env = GNUNET_MQ_msg_extra(msg, 912 env = GNUNET_MQ_msg_extra (msg,
911 xlen, 913 xlen,
912 GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE); 914 GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE);
913 msg->peer_id = htonl(data->peer->unique_id); 915 msg->peer_id = htonl (data->peer->unique_id);
914 msg->operation_id = GNUNET_htonll(opc->id); 916 msg->operation_id = GNUNET_htonll (opc->id);
915 msg->start = (uint8_t)data->start; 917 msg->start = (uint8_t) data->start;
916 GNUNET_memcpy(&msg[1], 918 GNUNET_memcpy (&msg[1],
917 data->service_name, 919 data->service_name,
918 xlen); 920 xlen);
919 GNUNET_free(data->service_name); 921 GNUNET_free (data->service_name);
920 data->service_name = NULL; 922 data->service_name = NULL;
921 opc->state = OPC_STATE_STARTED; 923 opc->state = OPC_STATE_STARTED;
922 GNUNET_TESTBED_insert_opc_(opc->c, opc); 924 GNUNET_TESTBED_insert_opc_ (opc->c, opc);
923 GNUNET_MQ_send(opc->c->mq, 925 GNUNET_MQ_send (opc->c->mq,
924 env); 926 env);
925} 927}
926 928
927 929
@@ -931,28 +933,28 @@ opstart_manage_service(void *cls)
931 * @param cls the closure from GNUNET_TESTBED_operation_create_() 933 * @param cls the closure from GNUNET_TESTBED_operation_create_()
932 */ 934 */
933static void 935static void
934oprelease_manage_service(void *cls) 936oprelease_manage_service (void *cls)
935{ 937{
936 struct OperationContext *opc = cls; 938 struct OperationContext *opc = cls;
937 struct ManageServiceData *data; 939 struct ManageServiceData *data;
938 940
939 data = opc->data; 941 data = opc->data;
940 switch (opc->state) 942 switch (opc->state)
941 { 943 {
942 case OPC_STATE_STARTED: 944 case OPC_STATE_STARTED:
943 GNUNET_TESTBED_remove_opc_(opc->c, opc); 945 GNUNET_TESTBED_remove_opc_ (opc->c, opc);
944 break; 946 break;
945 947
946 case OPC_STATE_INIT: 948 case OPC_STATE_INIT:
947 GNUNET_assert(NULL != data); 949 GNUNET_assert (NULL != data);
948 GNUNET_free(data->service_name); 950 GNUNET_free (data->service_name);
949 break; 951 break;
950 952
951 case OPC_STATE_FINISHED: 953 case OPC_STATE_FINISHED:
952 break; 954 break;
953 } 955 }
954 GNUNET_free_non_null(data); 956 GNUNET_free_non_null (data);
955 GNUNET_free(opc); 957 GNUNET_free (opc);
956} 958}
957 959
958 960
@@ -972,41 +974,42 @@ oprelease_manage_service(void *cls)
972 * @return an operation handle; NULL upon error (peer not running) 974 * @return an operation handle; NULL upon error (peer not running)
973 */ 975 */
974struct GNUNET_TESTBED_Operation * 976struct GNUNET_TESTBED_Operation *
975GNUNET_TESTBED_peer_manage_service(void *op_cls, 977GNUNET_TESTBED_peer_manage_service (void *op_cls,
976 struct GNUNET_TESTBED_Peer *peer, 978 struct GNUNET_TESTBED_Peer *peer,
977 const char *service_name, 979 const char *service_name,
978 GNUNET_TESTBED_OperationCompletionCallback cb, 980 GNUNET_TESTBED_OperationCompletionCallback
979 void *cb_cls, 981 cb,
980 unsigned int start) 982 void *cb_cls,
983 unsigned int start)
981{ 984{
982 struct ManageServiceData *data; 985 struct ManageServiceData *data;
983 struct OperationContext *opc; 986 struct OperationContext *opc;
984 size_t msize; 987 size_t msize;
985 988
986 GNUNET_assert(TESTBED_PS_STARTED == peer->state); /* peer is not running? */ 989 GNUNET_assert (TESTBED_PS_STARTED == peer->state); /* peer is not running? */
987 msize = strlen(service_name) + 1; 990 msize = strlen (service_name) + 1;
988 msize += sizeof(struct GNUNET_TESTBED_ManagePeerServiceMessage); 991 msize += sizeof(struct GNUNET_TESTBED_ManagePeerServiceMessage);
989 if (GNUNET_MAX_MESSAGE_SIZE < msize) 992 if (GNUNET_MAX_MESSAGE_SIZE < msize)
990 return NULL; 993 return NULL;
991 data = GNUNET_new(struct ManageServiceData); 994 data = GNUNET_new (struct ManageServiceData);
992 data->cb = cb; 995 data->cb = cb;
993 data->cb_cls = cb_cls; 996 data->cb_cls = cb_cls;
994 data->peer = peer; 997 data->peer = peer;
995 data->service_name = GNUNET_strdup(service_name); 998 data->service_name = GNUNET_strdup (service_name);
996 data->start = start; 999 data->start = start;
997 data->msize = (uint16_t)msize; 1000 data->msize = (uint16_t) msize;
998 opc = GNUNET_new(struct OperationContext); 1001 opc = GNUNET_new (struct OperationContext);
999 opc->data = data; 1002 opc->data = data;
1000 opc->c = peer->controller; 1003 opc->c = peer->controller;
1001 opc->id = GNUNET_TESTBED_get_next_op_id(opc->c); 1004 opc->id = GNUNET_TESTBED_get_next_op_id (opc->c);
1002 opc->type = OP_MANAGE_SERVICE; 1005 opc->type = OP_MANAGE_SERVICE;
1003 opc->op_cls = op_cls; 1006 opc->op_cls = op_cls;
1004 opc->op = 1007 opc->op =
1005 GNUNET_TESTBED_operation_create_(opc, &opstart_manage_service, 1008 GNUNET_TESTBED_operation_create_ (opc, &opstart_manage_service,
1006 &oprelease_manage_service); 1009 &oprelease_manage_service);
1007 GNUNET_TESTBED_operation_queue_insert_(opc->c->opq_parallel_operations, 1010 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
1008 opc->op); 1011 opc->op);
1009 GNUNET_TESTBED_operation_begin_wait_(opc->op); 1012 GNUNET_TESTBED_operation_begin_wait_ (opc->op);
1010 return opc->op; 1013 return opc->op;
1011} 1014}
1012 1015
diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h
index 6a9b89e7c..9ca104081 100644
--- a/src/testbed/testbed_api_peers.h
+++ b/src/testbed/testbed_api_peers.h
@@ -35,7 +35,8 @@
35/** 35/**
36 * Enumeration of possible states a peer could be in 36 * Enumeration of possible states a peer could be in
37 */ 37 */
38enum PeerState { 38enum PeerState
39{
39 /** 40 /**
40 * State to signify that this peer is invalid 41 * State to signify that this peer is invalid
41 */ 42 */
@@ -62,7 +63,8 @@ enum PeerState {
62 * A peer controlled by the testing framework. A peer runs 63 * A peer controlled by the testing framework. A peer runs
63 * at a particular host. 64 * at a particular host.
64 */ 65 */
65struct GNUNET_TESTBED_Peer { 66struct GNUNET_TESTBED_Peer
67{
66 /** 68 /**
67 * peer list DLL 69 * peer list DLL
68 */ 70 */
@@ -104,7 +106,8 @@ struct GNUNET_TESTBED_Peer {
104/** 106/**
105 * Data for the OperationType OP_PEER_CREATE 107 * Data for the OperationType OP_PEER_CREATE
106 */ 108 */
107struct PeerCreateData { 109struct PeerCreateData
110{
108 /** 111 /**
109 * The host where the peer has to be created 112 * The host where the peer has to be created
110 */ 113 */
@@ -135,7 +138,8 @@ struct PeerCreateData {
135/** 138/**
136 * Data for OperationType OP_PEER_START and OP_PEER_STOP 139 * Data for OperationType OP_PEER_START and OP_PEER_STOP
137 */ 140 */
138struct PeerEventData { 141struct PeerEventData
142{
139 /** 143 /**
140 * The handle of the peer to start 144 * The handle of the peer to start
141 */ 145 */
@@ -156,20 +160,22 @@ struct PeerEventData {
156/** 160/**
157 * Data for the OperationType OP_PEER_DESTROY; 161 * Data for the OperationType OP_PEER_DESTROY;
158 */ 162 */
159struct PeerDestroyData { 163struct PeerDestroyData
164{
160 /** 165 /**
161 * The peer structure 166 * The peer structure
162 */ 167 */
163 struct GNUNET_TESTBED_Peer *peer; 168 struct GNUNET_TESTBED_Peer *peer;
164 169
165 //PEERDESTROYDATA 170 // PEERDESTROYDATA
166}; 171};
167 172
168 173
169/** 174/**
170 * Data for the OperationType OP_PEER_INFO 175 * Data for the OperationType OP_PEER_INFO
171 */ 176 */
172struct PeerInfoData { 177struct PeerInfoData
178{
173 /** 179 /**
174 * The peer whose information has been requested 180 * The peer whose information has been requested
175 */ 181 */
@@ -195,7 +201,8 @@ struct PeerInfoData {
195/** 201/**
196 * Data for the operations of type OP_PEER_RECONFIGURE 202 * Data for the operations of type OP_PEER_RECONFIGURE
197 */ 203 */
198struct PeerReconfigureData { 204struct PeerReconfigureData
205{
199 /** 206 /**
200 * The peer whose information has been requested 207 * The peer whose information has been requested
201 */ 208 */
@@ -216,7 +223,8 @@ struct PeerReconfigureData {
216/** 223/**
217 * Data structure for OperationType OP_OVERLAY_CONNECT 224 * Data structure for OperationType OP_OVERLAY_CONNECT
218 */ 225 */
219struct OverlayConnectData { 226struct OverlayConnectData
227{
220 /** 228 /**
221 * Peer A to connect to peer B 229 * Peer A to connect to peer B
222 */ 230 */
@@ -246,7 +254,8 @@ struct OverlayConnectData {
246}; 254};
247 255
248 256
249struct ManageServiceData { 257struct ManageServiceData
258{
250 GNUNET_TESTBED_OperationCompletionCallback cb; 259 GNUNET_TESTBED_OperationCompletionCallback cb;
251 260
252 void *cb_cls; 261 void *cb_cls;
@@ -270,8 +279,8 @@ struct ManageServiceData {
270 * @return the PeerGetConfigurationMessage 279 * @return the PeerGetConfigurationMessage
271 */ 280 */
272struct GNUNET_TESTBED_PeerGetConfigurationMessage * 281struct GNUNET_TESTBED_PeerGetConfigurationMessage *
273GNUNET_TESTBED_generate_peergetconfig_msg_(uint32_t peer_id, 282GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id,
274 uint64_t operation_id); 283 uint64_t operation_id);
275 284
276 285
277/** 286/**
@@ -280,7 +289,7 @@ GNUNET_TESTBED_generate_peergetconfig_msg_(uint32_t peer_id,
280 * @param peer the peer to add to the peer list 289 * @param peer the peer to add to the peer list
281 */ 290 */
282void 291void
283GNUNET_TESTBED_peer_register_(struct GNUNET_TESTBED_Peer *peer); 292GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer);
284 293
285 294
286/** 295/**
@@ -289,14 +298,14 @@ GNUNET_TESTBED_peer_register_(struct GNUNET_TESTBED_Peer *peer);
289 * @param peer the peer to remove 298 * @param peer the peer to remove
290 */ 299 */
291void 300void
292GNUNET_TESTBED_peer_deregister_(struct GNUNET_TESTBED_Peer *peer); 301GNUNET_TESTBED_peer_deregister_ (struct GNUNET_TESTBED_Peer *peer);
293 302
294 303
295/** 304/**
296 * Frees all peers 305 * Frees all peers
297 */ 306 */
298void 307void
299GNUNET_TESTBED_cleanup_peers_(void); 308GNUNET_TESTBED_cleanup_peers_ (void);
300 309
301#endif 310#endif
302/* end of testbed_api_peers.h */ 311/* end of testbed_api_peers.h */
diff --git a/src/testbed/testbed_api_sd.c b/src/testbed/testbed_api_sd.c
index 2bff246a7..9a40464d7 100644
--- a/src/testbed/testbed_api_sd.c
+++ b/src/testbed/testbed_api_sd.c
@@ -31,7 +31,8 @@
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 */
34struct SDEntry { 34struct SDEntry
35{
35 /** 36 /**
36 * DLL next pointer 37 * DLL next pointer
37 */ 38 */
@@ -52,7 +53,8 @@ struct SDEntry {
52/** 53/**
53 * Opaque handle for calculating SD 54 * Opaque handle for calculating SD
54 */ 55 */
55struct SDHandle { 56struct SDHandle
57{
56 /** 58 /**
57 * DLL head for storing entries 59 * DLL head for storing entries
58 */ 60 */
@@ -102,12 +104,12 @@ struct SDHandle {
102 * @return the initialized handle 104 * @return the initialized handle
103 */ 105 */
104struct SDHandle * 106struct SDHandle *
105GNUNET_TESTBED_SD_init_(unsigned int max_cnt) 107GNUNET_TESTBED_SD_init_ (unsigned int max_cnt)
106{ 108{
107 struct SDHandle *h; 109 struct SDHandle *h;
108 110
109 GNUNET_assert(1 < max_cnt); 111 GNUNET_assert (1 < max_cnt);
110 h = GNUNET_new(struct SDHandle); 112 h = GNUNET_new (struct SDHandle);
111 h->max_cnt = max_cnt; 113 h->max_cnt = max_cnt;
112 return h; 114 return h;
113} 115}
@@ -119,16 +121,16 @@ GNUNET_TESTBED_SD_init_(unsigned int max_cnt)
119 * @param h the SD handle 121 * @param h the SD handle
120 */ 122 */
121void 123void
122GNUNET_TESTBED_SD_destroy_(struct SDHandle *h) 124GNUNET_TESTBED_SD_destroy_ (struct SDHandle *h)
123{ 125{
124 struct SDEntry *entry; 126 struct SDEntry *entry;
125 127
126 while (NULL != (entry = h->head)) 128 while (NULL != (entry = h->head))
127 { 129 {
128 GNUNET_CONTAINER_DLL_remove(h->head, h->tail, entry); 130 GNUNET_CONTAINER_DLL_remove (h->head, h->tail, entry);
129 GNUNET_free(entry); 131 GNUNET_free (entry);
130 } 132 }
131 GNUNET_free(h); 133 GNUNET_free (h);
132} 134}
133 135
134 136
@@ -139,7 +141,7 @@ GNUNET_TESTBED_SD_destroy_(struct SDHandle *h)
139 * @param amount the reading value 141 * @param amount the reading value
140 */ 142 */
141void 143void
142GNUNET_TESTBED_SD_add_data_(struct SDHandle *h, unsigned int amount) 144GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount)
143{ 145{
144 struct SDEntry *entry; 146 struct SDEntry *entry;
145 double sqavg; 147 double sqavg;
@@ -147,25 +149,25 @@ GNUNET_TESTBED_SD_add_data_(struct SDHandle *h, unsigned int amount)
147 149
148 entry = NULL; 150 entry = NULL;
149 if (h->cnt == h->max_cnt) 151 if (h->cnt == h->max_cnt)
150 { 152 {
151 entry = h->head; 153 entry = h->head;
152 GNUNET_CONTAINER_DLL_remove(h->head, h->tail, entry); 154 GNUNET_CONTAINER_DLL_remove (h->head, h->tail, entry);
153 h->sum -= entry->amount; 155 h->sum -= entry->amount;
154 h->sqsum -= 156 h->sqsum -=
155 ((unsigned long)entry->amount) * ((unsigned long)entry->amount); 157 ((unsigned long) entry->amount) * ((unsigned long) entry->amount);
156 h->cnt--; 158 h->cnt--;
157 } 159 }
158 GNUNET_assert(h->cnt < h->max_cnt); 160 GNUNET_assert (h->cnt < h->max_cnt);
159 if (NULL == entry) 161 if (NULL == entry)
160 entry = GNUNET_new(struct SDEntry); 162 entry = GNUNET_new (struct SDEntry);
161 entry->amount = amount; 163 entry->amount = amount;
162 GNUNET_CONTAINER_DLL_insert_tail(h->head, h->tail, entry); 164 GNUNET_CONTAINER_DLL_insert_tail (h->head, h->tail, entry);
163 h->sum += amount; 165 h->sum += amount;
164 h->cnt++; 166 h->cnt++;
165 h->avg = ((float)h->sum) / ((float)h->cnt); 167 h->avg = ((float) h->sum) / ((float) h->cnt);
166 h->sqsum += ((unsigned long)amount) * ((unsigned long)amount); 168 h->sqsum += ((unsigned long) amount) * ((unsigned long) amount);
167 sqsum_avg = ((double)h->sqsum) / ((double)h->cnt); 169 sqsum_avg = ((double) h->sqsum) / ((double) h->cnt);
168 sqavg = ((double)h->avg) * ((double)h->avg); 170 sqavg = ((double) h->avg) * ((double) h->avg);
169 h->vr = sqsum_avg - sqavg; 171 h->vr = sqsum_avg - sqavg;
170} 172}
171 173
@@ -180,8 +182,8 @@ GNUNET_TESTBED_SD_add_data_(struct SDHandle *h, unsigned int amount)
180 * be calculated; GNUNET_OK if the deviation is returned through factor 182 * be calculated; GNUNET_OK if the deviation is returned through factor
181 */ 183 */
182int 184int
183GNUNET_TESTBED_SD_deviation_factor_(struct SDHandle *h, unsigned int amount, 185GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount,
184 int *factor) 186 int *factor)
185{ 187{
186 double diff; 188 double diff;
187 int f; 189 int f;
@@ -189,19 +191,19 @@ GNUNET_TESTBED_SD_deviation_factor_(struct SDHandle *h, unsigned int amount,
189 191
190 if (h->cnt < 2) 192 if (h->cnt < 2)
191 return GNUNET_SYSERR; 193 return GNUNET_SYSERR;
192 if (((float)amount) > h->avg) 194 if (((float) amount) > h->avg)
193 { 195 {
194 diff = ((float)amount) - h->avg; 196 diff = ((float) amount) - h->avg;
195 f = 1; 197 f = 1;
196 } 198 }
197 else 199 else
198 { 200 {
199 diff = h->avg - ((float)amount); 201 diff = h->avg - ((float) amount);
200 f = -1; 202 f = -1;
201 } 203 }
202 diff *= diff; 204 diff *= diff;
203 for (n = 1; n < 4; n++) 205 for (n = 1; n < 4; n++)
204 if (diff < (((double)(n * n)) * h->vr)) 206 if (diff < (((double) (n * n)) * h->vr))
205 break; 207 break;
206 *factor = f * n; 208 *factor = f * n;
207 return GNUNET_OK; 209 return GNUNET_OK;
diff --git a/src/testbed/testbed_api_sd.h b/src/testbed/testbed_api_sd.h
index 6e4cc621a..2872051e0 100644
--- a/src/testbed/testbed_api_sd.h
+++ b/src/testbed/testbed_api_sd.h
@@ -41,7 +41,7 @@ struct SDHandle;
41 * @return the initialized handle 41 * @return the initialized handle
42 */ 42 */
43struct SDHandle * 43struct SDHandle *
44GNUNET_TESTBED_SD_init_(unsigned int max_cnt); 44GNUNET_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 */
52void 52void
53GNUNET_TESTBED_SD_destroy_(struct SDHandle *h); 53GNUNET_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 */
62void 62void
63GNUNET_TESTBED_SD_add_data_(struct SDHandle *h, unsigned int amount); 63GNUNET_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 */
76int 76int
77GNUNET_TESTBED_SD_deviation_factor_(struct SDHandle *h, unsigned int amount, 77GNUNET_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 ee4a65817..692fe505f 100644
--- a/src/testbed/testbed_api_services.c
+++ b/src/testbed/testbed_api_services.c
@@ -32,7 +32,8 @@
32/** 32/**
33 * States for Service connect operations 33 * States for Service connect operations
34 */ 34 */
35enum State { 35enum State
36{
36 /** 37 /**
37 * Initial state 38 * Initial state
38 */ 39 */
@@ -53,7 +54,8 @@ enum State {
53/** 54/**
54 * Data accessed during service connections 55 * Data accessed during service connections
55 */ 56 */
56struct ServiceConnectData { 57struct ServiceConnectData
58{
57 /** 59 /**
58 * helper function callback to establish the connection 60 * helper function callback to establish the connection
59 */ 61 */
@@ -129,7 +131,7 @@ struct ServiceConnectData {
129 * @param msg message received, NULL on timeout or fatal error 131 * @param msg message received, NULL on timeout or fatal error
130 */ 132 */
131static void 133static void
132configuration_receiver(void *cls, const struct GNUNET_MessageHeader *msg) 134configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg)
133{ 135{
134 struct ServiceConnectData *data = cls; 136 struct ServiceConnectData *data = cls;
135 struct GNUNET_TESTBED_Controller *c; 137 struct GNUNET_TESTBED_Controller *c;
@@ -138,26 +140,26 @@ configuration_receiver(void *cls, const struct GNUNET_MessageHeader *msg)
138 uint16_t mtype; 140 uint16_t mtype;
139 141
140 c = data->peer->controller; 142 c = data->peer->controller;
141 mtype = ntohs(msg->type); 143 mtype = ntohs (msg->type);
142 emsg = NULL; 144 emsg = NULL;
143 info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; 145 info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED;
144 info.op = data->operation; 146 info.op = data->operation;
145 info.op_cls = data->op_cls; 147 info.op_cls = data->op_cls;
146 if (GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT == mtype) 148 if (GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT == mtype)
147 { 149 {
148 emsg = 150 emsg =
149 GNUNET_TESTBED_parse_error_string_((const struct 151 GNUNET_TESTBED_parse_error_string_ ((const struct
150 GNUNET_TESTBED_OperationFailureEventMessage 152 GNUNET_TESTBED_OperationFailureEventMessage
151 *)msg); 153 *) msg);
152 if (NULL == emsg) 154 if (NULL == emsg)
153 emsg = "Unknown error"; 155 emsg = "Unknown error";
154 info.details.operation_finished.emsg = emsg; 156 info.details.operation_finished.emsg = emsg;
155 info.details.operation_finished.generic = NULL; 157 info.details.operation_finished.generic = NULL;
156 goto call_cb; 158 goto call_cb;
157 } 159 }
158 data->cfg = GNUNET_TESTBED_extract_config_(msg); 160 data->cfg = GNUNET_TESTBED_extract_config_ (msg);
159 GNUNET_assert(NULL == data->op_result); 161 GNUNET_assert (NULL == data->op_result);
160 data->op_result = data->ca(data->cada_cls, data->cfg); 162 data->op_result = data->ca (data->cada_cls, data->cfg);
161 info.details.operation_finished.emsg = NULL; 163 info.details.operation_finished.emsg = NULL;
162 info.details.operation_finished.generic = data->op_result; 164 info.details.operation_finished.generic = data->op_result;
163 data->state = SERVICE_CONNECTED; 165 data->state = SERVICE_CONNECTED;
@@ -165,9 +167,9 @@ configuration_receiver(void *cls, const struct GNUNET_MessageHeader *msg)
165call_cb: 167call_cb:
166 if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) && 168 if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) &&
167 (NULL != c->cc)) 169 (NULL != c->cc))
168 c->cc(c->cc_cls, &info); 170 c->cc (c->cc_cls, &info);
169 if (NULL != data->cb) 171 if (NULL != data->cb)
170 data->cb(data->cb_cls, data->operation, data->op_result, emsg); 172 data->cb (data->cb_cls, data->operation, data->op_result, emsg);
171} 173}
172 174
173 175
@@ -177,23 +179,23 @@ call_cb:
177 * @param cls the closure from GNUNET_TESTBED_operation_create_() 179 * @param cls the closure from GNUNET_TESTBED_operation_create_()
178 */ 180 */
179static void 181static void
180opstart_service_connect(void *cls) 182opstart_service_connect (void *cls)
181{ 183{
182 struct ServiceConnectData *data = cls; 184 struct ServiceConnectData *data = cls;
183 struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; 185 struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
184 struct GNUNET_TESTBED_Controller *c; 186 struct GNUNET_TESTBED_Controller *c;
185 uint64_t op_id; 187 uint64_t op_id;
186 188
187 GNUNET_assert(NULL != data); 189 GNUNET_assert (NULL != data);
188 GNUNET_assert(NULL != data->peer); 190 GNUNET_assert (NULL != data->peer);
189 c = data->peer->controller; 191 c = data->peer->controller;
190 op_id = GNUNET_TESTBED_get_next_op_id(c); 192 op_id = GNUNET_TESTBED_get_next_op_id (c);
191 msg = 193 msg =
192 GNUNET_TESTBED_generate_peergetconfig_msg_(data->peer->unique_id, op_id); 194 GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id, op_id);
193 data->opc = 195 data->opc =
194 GNUNET_TESTBED_forward_operation_msg_(c, op_id, &msg->header, 196 GNUNET_TESTBED_forward_operation_msg_ (c, op_id, &msg->header,
195 &configuration_receiver, data); 197 &configuration_receiver, data);
196 GNUNET_free(msg); 198 GNUNET_free (msg);
197 data->state = CFG_REQUEST_QUEUED; 199 data->state = CFG_REQUEST_QUEUED;
198} 200}
199 201
@@ -205,28 +207,28 @@ opstart_service_connect(void *cls)
205 * @param cls the closure from GNUNET_TESTBED_operation_create_() 207 * @param cls the closure from GNUNET_TESTBED_operation_create_()
206 */ 208 */
207static void 209static void
208oprelease_service_connect(void *cls) 210oprelease_service_connect (void *cls)
209{ 211{
210 struct ServiceConnectData *data = cls; 212 struct ServiceConnectData *data = cls;
211 213
212 switch (data->state) 214 switch (data->state)
213 { 215 {
214 case INIT: 216 case INIT:
215 break; 217 break;
216 218
217 case CFG_REQUEST_QUEUED: 219 case CFG_REQUEST_QUEUED:
218 GNUNET_assert(NULL != data->opc); 220 GNUNET_assert (NULL != data->opc);
219 GNUNET_TESTBED_forward_operation_msg_cancel_(data->opc); 221 GNUNET_TESTBED_forward_operation_msg_cancel_ (data->opc);
220 break; 222 break;
221 223
222 case SERVICE_CONNECTED: 224 case SERVICE_CONNECTED:
223 GNUNET_assert(NULL != data->cfg); 225 GNUNET_assert (NULL != data->cfg);
224 GNUNET_CONFIGURATION_destroy(data->cfg); 226 GNUNET_CONFIGURATION_destroy (data->cfg);
225 if (NULL != data->da) 227 if (NULL != data->da)
226 data->da(data->cada_cls, data->op_result); 228 data->da (data->cada_cls, data->op_result);
227 break; 229 break;
228 } 230 }
229 GNUNET_free(data); 231 GNUNET_free (data);
230} 232}
231 233
232 234
@@ -252,17 +254,17 @@ oprelease_service_connect(void *cls)
252 * @return handle for the operation 254 * @return handle for the operation
253 */ 255 */
254struct GNUNET_TESTBED_Operation * 256struct GNUNET_TESTBED_Operation *
255GNUNET_TESTBED_service_connect(void *op_cls, struct GNUNET_TESTBED_Peer *peer, 257GNUNET_TESTBED_service_connect (void *op_cls, struct GNUNET_TESTBED_Peer *peer,
256 const char *service_name, 258 const char *service_name,
257 GNUNET_TESTBED_ServiceConnectCompletionCallback 259 GNUNET_TESTBED_ServiceConnectCompletionCallback
258 cb, void *cb_cls, 260 cb, void *cb_cls,
259 GNUNET_TESTBED_ConnectAdapter ca, 261 GNUNET_TESTBED_ConnectAdapter ca,
260 GNUNET_TESTBED_DisconnectAdapter da, 262 GNUNET_TESTBED_DisconnectAdapter da,
261 void *cada_cls) 263 void *cada_cls)
262{ 264{
263 struct ServiceConnectData *data; 265 struct ServiceConnectData *data;
264 266
265 data = GNUNET_new(struct ServiceConnectData); 267 data = GNUNET_new (struct ServiceConnectData);
266 data->ca = ca; 268 data->ca = ca;
267 data->da = da; 269 data->da = da;
268 data->cada_cls = cada_cls; 270 data->cada_cls = cada_cls;
@@ -272,15 +274,16 @@ GNUNET_TESTBED_service_connect(void *op_cls, struct GNUNET_TESTBED_Peer *peer,
272 data->cb = cb; 274 data->cb = cb;
273 data->cb_cls = cb_cls; 275 data->cb_cls = cb_cls;
274 data->operation = 276 data->operation =
275 GNUNET_TESTBED_operation_create_(data, &opstart_service_connect, 277 GNUNET_TESTBED_operation_create_ (data, &opstart_service_connect,
276 &oprelease_service_connect); 278 &oprelease_service_connect);
277 GNUNET_TESTBED_operation_queue_insert_(peer-> 279 GNUNET_TESTBED_operation_queue_insert_ (peer->
278 controller->opq_parallel_service_connections, 280 controller->
279 data->operation); 281 opq_parallel_service_connections,
280 GNUNET_TESTBED_operation_queue_insert_(peer-> 282 data->operation);
281 controller->opq_parallel_operations, 283 GNUNET_TESTBED_operation_queue_insert_ (peer->
282 data->operation); 284 controller->opq_parallel_operations,
283 GNUNET_TESTBED_operation_begin_wait_(data->operation); 285 data->operation);
286 GNUNET_TESTBED_operation_begin_wait_ (data->operation);
284 return data->operation; 287 return data->operation;
285} 288}
286 289
diff --git a/src/testbed/testbed_api_statistics.c b/src/testbed/testbed_api_statistics.c
index e7440dfa1..4858208cc 100644
--- a/src/testbed/testbed_api_statistics.c
+++ b/src/testbed/testbed_api_statistics.c
@@ -35,19 +35,20 @@
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 */
50struct GetStatsContext { 50struct GetStatsContext
51{
51 /** 52 /**
52 * The main operation we generate while creating this context 53 * The main operation we generate while creating this context
53 */ 54 */
@@ -93,7 +94,7 @@ struct GetStatsContext {
93 /** 94 /**
94 * The task for calling the continuation callback 95 * The task for calling the continuation callback
95 */ 96 */
96 struct GNUNET_SCHEDULER_Task * call_completion_task_id; 97 struct GNUNET_SCHEDULER_Task *call_completion_task_id;
97 98
98 /** 99 /**
99 * The number of peers present in the peers array. This number also 100 * The number of peers present in the peers array. This number also
@@ -111,7 +112,8 @@ struct GetStatsContext {
111/** 112/**
112 * Context information with respect to a particular peer 113 * Context information with respect to a particular peer
113 */ 114 */
114struct PeerGetStatsContext { 115struct PeerGetStatsContext
116{
115 /** 117 /**
116 * The GetStatsContext which is associated with this context 118 * The GetStatsContext which is associated with this context
117 */ 119 */
@@ -125,7 +127,7 @@ struct PeerGetStatsContext {
125 /** 127 /**
126 * Task to mark the statistics service connect operation as done 128 * Task to mark the statistics service connect operation as done
127 */ 129 */
128 struct GNUNET_SCHEDULER_Task * op_done_task_id; 130 struct GNUNET_SCHEDULER_Task *op_done_task_id;
129 131
130 /** 132 /**
131 * The index of this peer in the peers array of GetStatsContext 133 * The index of this peer in the peers array of GetStatsContext
@@ -149,14 +151,14 @@ static struct OperationQueue *no_wait_queue;
149 * @param cls the GetStatsContext 151 * @param cls the GetStatsContext
150 */ 152 */
151static void 153static void
152call_completion_task(void *cls) 154call_completion_task (void *cls)
153{ 155{
154 struct GetStatsContext *sc = cls; 156 struct GetStatsContext *sc = cls;
155 157
156 GNUNET_assert(sc->call_completion_task_id != NULL); 158 GNUNET_assert (sc->call_completion_task_id != NULL);
157 sc->call_completion_task_id = NULL; 159 sc->call_completion_task_id = NULL;
158 LOG_DEBUG("Calling get_statistics() continuation callback\n"); 160 LOG_DEBUG ("Calling get_statistics() continuation callback\n");
159 sc->cont(sc->cb_cls, sc->main_op, NULL); 161 sc->cont (sc->cb_cls, sc->main_op, NULL);
160} 162}
161 163
162 164
@@ -167,7 +169,7 @@ call_completion_task(void *cls)
167 * @param cls the PeerGetStatsContext 169 * @param cls the PeerGetStatsContext
168 */ 170 */
169static void 171static void
170op_done_task(void *cls) 172op_done_task (void *cls)
171{ 173{
172 struct PeerGetStatsContext *peer_sc = cls; 174 struct PeerGetStatsContext *peer_sc = cls;
173 struct GetStatsContext *sc; 175 struct GetStatsContext *sc;
@@ -176,8 +178,8 @@ op_done_task(void *cls)
176 sc = peer_sc->sc; 178 sc = peer_sc->sc;
177 peer_sc->op_done_task_id = NULL; 179 peer_sc->op_done_task_id = NULL;
178 op = &sc->ops[peer_sc->peer_index]; 180 op = &sc->ops[peer_sc->peer_index];
179 GNUNET_assert(NULL != *op); 181 GNUNET_assert (NULL != *op);
180 GNUNET_TESTBED_operation_done(*op); 182 GNUNET_TESTBED_operation_done (*op);
181 *op = NULL; 183 *op = NULL;
182} 184}
183 185
@@ -190,22 +192,22 @@ op_done_task(void *cls)
190 * successfully obtained, GNUNET_SYSERR if not. 192 * successfully obtained, GNUNET_SYSERR if not.
191 */ 193 */
192static void 194static void
193iteration_completion_cb(void *cls, int success) 195iteration_completion_cb (void *cls, int success)
194{ 196{
195 struct PeerGetStatsContext *peer_sc = cls; 197 struct PeerGetStatsContext *peer_sc = cls;
196 struct GetStatsContext *sc; 198 struct GetStatsContext *sc;
197 199
198 GNUNET_break(GNUNET_OK == success); 200 GNUNET_break (GNUNET_OK == success);
199 sc = peer_sc->sc; 201 sc = peer_sc->sc;
200 peer_sc->get_handle = NULL; 202 peer_sc->get_handle = NULL;
201 sc->num_completed++; 203 sc->num_completed++;
202 peer_sc->op_done_task_id = GNUNET_SCHEDULER_add_now(&op_done_task, peer_sc); 204 peer_sc->op_done_task_id = GNUNET_SCHEDULER_add_now (&op_done_task, peer_sc);
203 if (sc->num_completed == sc->num_peers) 205 if (sc->num_completed == sc->num_peers)
204 { 206 {
205 LOG_DEBUG("Scheduling to call iteration completion callback\n"); 207 LOG_DEBUG ("Scheduling to call iteration completion callback\n");
206 sc->call_completion_task_id = 208 sc->call_completion_task_id =
207 GNUNET_SCHEDULER_add_now(&call_completion_task, sc); 209 GNUNET_SCHEDULER_add_now (&call_completion_task, sc);
208 } 210 }
209} 211}
210 212
211 213
@@ -220,9 +222,9 @@ iteration_completion_cb(void *cls, int success)
220 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 222 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
221 */ 223 */
222static int 224static int
223iterator_cb(void *cls, const char *subsystem, 225iterator_cb (void *cls, const char *subsystem,
224 const char *name, uint64_t value, 226 const char *name, uint64_t value,
225 int is_persistent) 227 int is_persistent)
226{ 228{
227 struct PeerGetStatsContext *peer_sc = cls; 229 struct PeerGetStatsContext *peer_sc = cls;
228 struct GetStatsContext *sc; 230 struct GetStatsContext *sc;
@@ -231,12 +233,12 @@ iterator_cb(void *cls, const char *subsystem,
231 233
232 sc = peer_sc->sc; 234 sc = peer_sc->sc;
233 peer = sc->peers[peer_sc->peer_index]; 235 peer = sc->peers[peer_sc->peer_index];
234 LOG_DEBUG("Peer %u: [%s,%s] -> %lu\n", peer_sc->peer_index, 236 LOG_DEBUG ("Peer %u: [%s,%s] -> %lu\n", peer_sc->peer_index,
235 subsystem, name, (unsigned long)value); 237 subsystem, name, (unsigned long) value);
236 ret = sc->proc(sc->cb_cls, peer, 238 ret = sc->proc (sc->cb_cls, peer,
237 subsystem, name, value, is_persistent); 239 subsystem, name, value, is_persistent);
238 if (GNUNET_SYSERR == ret) 240 if (GNUNET_SYSERR == ret)
239 LOG_DEBUG("Aborting iteration for peer %u\n", peer_sc->peer_index); 241 LOG_DEBUG ("Aborting iteration for peer %u\n", peer_sc->peer_index);
240 return ret; 242 return ret;
241} 243}
242 244
@@ -251,21 +253,21 @@ iterator_cb(void *cls, const char *subsystem,
251 * operation has executed successfully. 253 * operation has executed successfully.
252 */ 254 */
253static void 255static void
254service_connect_comp(void *cls, 256service_connect_comp (void *cls,
255 struct GNUNET_TESTBED_Operation *op, 257 struct GNUNET_TESTBED_Operation *op,
256 void *ca_result, 258 void *ca_result,
257 const char *emsg) 259 const char *emsg)
258{ 260{
259 struct PeerGetStatsContext *peer_sc = cls; 261 struct PeerGetStatsContext *peer_sc = cls;
260 struct GNUNET_STATISTICS_Handle *h = ca_result; 262 struct GNUNET_STATISTICS_Handle *h = ca_result;
261 263
262 LOG_DEBUG("Retrieving statistics of peer %u\n", 264 LOG_DEBUG ("Retrieving statistics of peer %u\n",
263 peer_sc->peer_index); 265 peer_sc->peer_index);
264 peer_sc->get_handle = 266 peer_sc->get_handle =
265 GNUNET_STATISTICS_get(h, peer_sc->sc->subsystem, 267 GNUNET_STATISTICS_get (h, peer_sc->sc->subsystem,
266 peer_sc->sc->name, 268 peer_sc->sc->name,
267 &iteration_completion_cb, 269 &iteration_completion_cb,
268 iterator_cb, peer_sc); 270 iterator_cb, peer_sc);
269} 271}
270 272
271 273
@@ -280,13 +282,13 @@ service_connect_comp(void *cls,
280 * @return service handle to return in 'op_result', NULL on error 282 * @return service handle to return in 'op_result', NULL on error
281 */ 283 */
282static void * 284static void *
283statistics_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) 285statistics_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
284{ 286{
285 struct PeerGetStatsContext *peer_sc = cls; 287 struct PeerGetStatsContext *peer_sc = cls;
286 288
287 LOG_DEBUG("Connecting to statistics service of peer %u\n", 289 LOG_DEBUG ("Connecting to statistics service of peer %u\n",
288 peer_sc->peer_index); 290 peer_sc->peer_index);
289 return GNUNET_STATISTICS_create("<testbed-api>", cfg); 291 return GNUNET_STATISTICS_create ("<testbed-api>", cfg);
290} 292}
291 293
292 294
@@ -297,20 +299,20 @@ statistics_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
297 * @param op_result service handle returned from the connect adapter 299 * @param op_result service handle returned from the connect adapter
298 */ 300 */
299static void 301static void
300statistics_da(void *cls, void *op_result) 302statistics_da (void *cls, void *op_result)
301{ 303{
302 struct PeerGetStatsContext *peer_sc = cls; 304 struct PeerGetStatsContext *peer_sc = cls;
303 struct GNUNET_STATISTICS_Handle *sh = op_result; 305 struct GNUNET_STATISTICS_Handle *sh = op_result;
304 306
305 if (NULL != peer_sc->get_handle) 307 if (NULL != peer_sc->get_handle)
306 { 308 {
307 GNUNET_STATISTICS_get_cancel(peer_sc->get_handle); 309 GNUNET_STATISTICS_get_cancel (peer_sc->get_handle);
308 peer_sc->get_handle = NULL; 310 peer_sc->get_handle = NULL;
309 } 311 }
310 GNUNET_STATISTICS_destroy(sh, GNUNET_NO); 312 GNUNET_STATISTICS_destroy (sh, GNUNET_NO);
311 if (NULL != peer_sc->op_done_task_id) 313 if (NULL != peer_sc->op_done_task_id)
312 GNUNET_SCHEDULER_cancel(peer_sc->op_done_task_id); 314 GNUNET_SCHEDULER_cancel (peer_sc->op_done_task_id);
313 GNUNET_free(peer_sc); 315 GNUNET_free (peer_sc);
314} 316}
315 317
316 318
@@ -320,33 +322,33 @@ statistics_da(void *cls, void *op_result)
320 * @param cls the GetStatsContext 322 * @param cls the GetStatsContext
321 */ 323 */
322static void 324static void
323opstart_get_stats(void *cls) 325opstart_get_stats (void *cls)
324{ 326{
325 struct GetStatsContext *sc = cls; 327 struct GetStatsContext *sc = cls;
326 struct PeerGetStatsContext *peer_sc; 328 struct PeerGetStatsContext *peer_sc;
327 unsigned int peer; 329 unsigned int peer;
328 330
329 LOG_DEBUG("Starting get_statistics operation\n"); 331 LOG_DEBUG ("Starting get_statistics operation\n");
330 sc->ops = GNUNET_malloc(sc->num_peers * 332 sc->ops = GNUNET_malloc (sc->num_peers
331 sizeof(struct GNUNET_TESTBED_Operation *)); 333 * sizeof(struct GNUNET_TESTBED_Operation *));
332 for (peer = 0; peer < sc->num_peers; peer++) 334 for (peer = 0; peer < sc->num_peers; peer++)
335 {
336 if (NULL == sc->peers[peer])
333 { 337 {
334 if (NULL == sc->peers[peer]) 338 GNUNET_break (0);
335 { 339 continue;
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);
349 } 340 }
341 peer_sc = GNUNET_new (struct PeerGetStatsContext);
342 peer_sc->sc = sc;
343 peer_sc->peer_index = peer;
344 sc->ops[peer] =
345 GNUNET_TESTBED_service_connect (sc, sc->peers[peer], "statistics",
346 &service_connect_comp,
347 peer_sc,
348 &statistics_ca,
349 &statistics_da,
350 peer_sc);
351 }
350} 352}
351 353
352 354
@@ -356,31 +358,31 @@ opstart_get_stats(void *cls)
356 * @param cls the GetStatsContext 358 * @param cls the GetStatsContext
357 */ 359 */
358static void 360static void
359oprelease_get_stats(void *cls) 361oprelease_get_stats (void *cls)
360{ 362{
361 struct GetStatsContext *sc = cls; 363 struct GetStatsContext *sc = cls;
362 unsigned int peer; 364 unsigned int peer;
363 365
364 LOG_DEBUG("Cleaning up get_statistics operation\n"); 366 LOG_DEBUG ("Cleaning up get_statistics operation\n");
365 if (NULL != sc->call_completion_task_id) 367 if (NULL != sc->call_completion_task_id)
366 GNUNET_SCHEDULER_cancel(sc->call_completion_task_id); 368 GNUNET_SCHEDULER_cancel (sc->call_completion_task_id);
367 if (NULL != sc->ops) 369 if (NULL != sc->ops)
370 {
371 for (peer = 0; peer < sc->num_peers; peer++)
368 { 372 {
369 for (peer = 0; peer < sc->num_peers; peer++) 373 if (NULL != sc->ops[peer])
370 { 374 {
371 if (NULL != sc->ops[peer]) 375 GNUNET_TESTBED_operation_done (sc->ops[peer]);
372 { 376 sc->ops[peer] = NULL;
373 GNUNET_TESTBED_operation_done(sc->ops[peer]); 377 }
374 sc->ops[peer] = NULL;
375 }
376 }
377 GNUNET_free(sc->ops);
378 } 378 }
379 GNUNET_free_non_null(sc->subsystem); 379 GNUNET_free (sc->ops);
380 GNUNET_free_non_null(sc->name); 380 }
381 GNUNET_free(sc); 381 GNUNET_free_non_null (sc->subsystem);
382 GNUNET_free_non_null (sc->name);
383 GNUNET_free (sc);
382 if (GNUNET_YES == 384 if (GNUNET_YES ==
383 GNUNET_TESTBED_operation_queue_destroy_empty_(no_wait_queue)) 385 GNUNET_TESTBED_operation_queue_destroy_empty_ (no_wait_queue))
384 no_wait_queue = NULL; 386 no_wait_queue = NULL;
385} 387}
386 388
@@ -399,33 +401,33 @@ oprelease_get_stats(void *cls)
399 * @return operation handle to cancel the operation 401 * @return operation handle to cancel the operation
400 */ 402 */
401struct GNUNET_TESTBED_Operation * 403struct GNUNET_TESTBED_Operation *
402GNUNET_TESTBED_get_statistics(unsigned int num_peers, 404GNUNET_TESTBED_get_statistics (unsigned int num_peers,
403 struct GNUNET_TESTBED_Peer **peers, 405 struct GNUNET_TESTBED_Peer **peers,
404 const char *subsystem, const char *name, 406 const char *subsystem, const char *name,
405 GNUNET_TESTBED_StatisticsIterator proc, 407 GNUNET_TESTBED_StatisticsIterator proc,
406 GNUNET_TESTBED_OperationCompletionCallback cont, 408 GNUNET_TESTBED_OperationCompletionCallback cont,
407 void *cls) 409 void *cls)
408{ 410{
409 struct GetStatsContext *sc; 411 struct GetStatsContext *sc;
410 412
411 GNUNET_assert(NULL != proc); 413 GNUNET_assert (NULL != proc);
412 GNUNET_assert(NULL != cont); 414 GNUNET_assert (NULL != cont);
413 if (NULL == no_wait_queue) 415 if (NULL == no_wait_queue)
414 no_wait_queue = GNUNET_TESTBED_operation_queue_create_ 416 no_wait_queue = GNUNET_TESTBED_operation_queue_create_
415 (OPERATION_QUEUE_TYPE_FIXED, UINT_MAX); 417 (OPERATION_QUEUE_TYPE_FIXED, UINT_MAX);
416 sc = GNUNET_new(struct GetStatsContext); 418 sc = GNUNET_new (struct GetStatsContext);
417 sc->peers = peers; 419 sc->peers = peers;
418 sc->subsystem = (NULL == subsystem) ? NULL : GNUNET_strdup(subsystem); 420 sc->subsystem = (NULL == subsystem) ? NULL : GNUNET_strdup (subsystem);
419 sc->name = (NULL == name) ? NULL : GNUNET_strdup(name); 421 sc->name = (NULL == name) ? NULL : GNUNET_strdup (name);
420 sc->proc = proc; 422 sc->proc = proc;
421 sc->cont = cont; 423 sc->cont = cont;
422 sc->cb_cls = cls; 424 sc->cb_cls = cls;
423 sc->num_peers = num_peers; 425 sc->num_peers = num_peers;
424 sc->main_op = 426 sc->main_op =
425 GNUNET_TESTBED_operation_create_(sc, &opstart_get_stats, 427 GNUNET_TESTBED_operation_create_ (sc, &opstart_get_stats,
426 &oprelease_get_stats); 428 &oprelease_get_stats);
427 GNUNET_TESTBED_operation_queue_insert_(no_wait_queue, sc->main_op); 429 GNUNET_TESTBED_operation_queue_insert_ (no_wait_queue, sc->main_op);
428 GNUNET_TESTBED_operation_begin_wait_(sc->main_op); 430 GNUNET_TESTBED_operation_begin_wait_ (sc->main_op);
429 return sc->main_op; 431 return sc->main_op;
430} 432}
431 433
diff --git a/src/testbed/testbed_api_test.c b/src/testbed/testbed_api_test.c
index 7294a137e..5b57826ba 100644
--- a/src/testbed/testbed_api_test.c
+++ b/src/testbed/testbed_api_test.c
@@ -31,7 +31,8 @@
31/** 31/**
32 * Context information for test run 32 * Context information for test run
33 */ 33 */
34struct TestRunContext { 34struct TestRunContext
35{
35 /** 36 /**
36 * Test master callback 37 * Test master callback
37 */ 38 */
@@ -73,13 +74,13 @@ struct TestRunContext {
73 * @param config the configuration file handle 74 * @param config the configuration file handle
74 */ 75 */
75static void 76static void
76run(void *cls, char *const *args, const char *cfgfile, 77run (void *cls, char *const *args, const char *cfgfile,
77 const struct GNUNET_CONFIGURATION_Handle *config) 78 const struct GNUNET_CONFIGURATION_Handle *config)
78{ 79{
79 struct TestRunContext *rc = cls; 80 struct TestRunContext *rc = cls;
80 81
81 GNUNET_TESTBED_run(NULL, config, rc->num_peers, rc->event_mask, rc->cc, 82 GNUNET_TESTBED_run (NULL, config, rc->num_peers, rc->event_mask, rc->cc,
82 rc->cc_cls, rc->test_master, rc->test_master_cls); 83 rc->cc_cls, rc->test_master, rc->test_master_cls);
83} 84}
84 85
85 86
@@ -117,14 +118,14 @@ run(void *cls, char *const *args, const char *cfgfile,
117 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 118 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
118 */ 119 */
119int 120int
120GNUNET_TESTBED_test_run(const char *testname, 121GNUNET_TESTBED_test_run (const char *testname,
121 const char *cfg_filename, 122 const char *cfg_filename,
122 unsigned int num_peers, 123 unsigned int num_peers,
123 uint64_t event_mask, 124 uint64_t event_mask,
124 GNUNET_TESTBED_ControllerCallback cc, 125 GNUNET_TESTBED_ControllerCallback cc,
125 void *cc_cls, 126 void *cc_cls,
126 GNUNET_TESTBED_TestMaster test_master, 127 GNUNET_TESTBED_TestMaster test_master,
127 void *test_master_cls) 128 void *test_master_cls)
128{ 129{
129 char *argv2[] = { 130 char *argv2[] = {
130 NULL, 131 NULL,
@@ -138,23 +139,23 @@ GNUNET_TESTBED_test_run(const char *testname,
138 struct TestRunContext *rc; 139 struct TestRunContext *rc;
139 int ret; 140 int ret;
140 141
141 argv2[0] = GNUNET_strdup(testname); 142 argv2[0] = GNUNET_strdup (testname);
142 argv2[2] = GNUNET_strdup(cfg_filename); 143 argv2[2] = GNUNET_strdup (cfg_filename);
143 GNUNET_assert(NULL != test_master); 144 GNUNET_assert (NULL != test_master);
144 GNUNET_assert(num_peers > 0); 145 GNUNET_assert (num_peers > 0);
145 rc = GNUNET_malloc(sizeof(struct TestRunContext) + 146 rc = GNUNET_malloc (sizeof(struct TestRunContext)
146 (num_peers * sizeof(struct GNUNET_TESTBED_Peer *))); 147 + (num_peers * sizeof(struct GNUNET_TESTBED_Peer *)));
147 rc->test_master = test_master; 148 rc->test_master = test_master;
148 rc->test_master_cls = test_master_cls; 149 rc->test_master_cls = test_master_cls;
149 rc->num_peers = num_peers; 150 rc->num_peers = num_peers;
150 rc->event_mask = event_mask; 151 rc->event_mask = event_mask;
151 rc->cc = cc; 152 rc->cc = cc;
152 rc->cc_cls = cc_cls; 153 rc->cc_cls = cc_cls;
153 ret = GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2, 154 ret = GNUNET_PROGRAM_run ((sizeof(argv2) / sizeof(char *)) - 1, argv2,
154 testname, "nohelp", options, &run, rc); 155 testname, "nohelp", options, &run, rc);
155 GNUNET_free(rc); 156 GNUNET_free (rc);
156 GNUNET_free(argv2[0]); 157 GNUNET_free (argv2[0]);
157 GNUNET_free(argv2[2]); 158 GNUNET_free (argv2[2]);
158 return ret; 159 return ret;
159} 160}
160 161
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c
index 4615afca9..3c56dd024 100644
--- a/src/testbed/testbed_api_testbed.c
+++ b/src/testbed/testbed_api_testbed.c
@@ -37,13 +37,13 @@
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,7 +71,8 @@
71/** 71/**
72 * Context information for the operation we start 72 * Context information for the operation we start
73 */ 73 */
74struct RunContextOperation { 74struct RunContextOperation
75{
75 /** 76 /**
76 * The testbed operation handle 77 * The testbed operation handle
77 */ 78 */
@@ -92,7 +93,8 @@ struct RunContextOperation {
92/** 93/**
93 * States of RunContext 94 * States of RunContext
94 */ 95 */
95enum State { 96enum State
97{
96 /** 98 /**
97 * Initial state 99 * Initial state
98 */ 100 */
@@ -135,7 +137,8 @@ enum State {
135/** 137/**
136 * Context for host compability checks 138 * Context for host compability checks
137 */ 139 */
138struct CompatibilityCheckContext { 140struct CompatibilityCheckContext
141{
139 /** 142 /**
140 * The run context 143 * The run context
141 */ 144 */
@@ -156,7 +159,8 @@ struct CompatibilityCheckContext {
156/** 159/**
157 * Testbed Run Handle 160 * Testbed Run Handle
158 */ 161 */
159struct GNUNET_TESTBED_RunHandle { 162struct GNUNET_TESTBED_RunHandle
163{
160 /** 164 /**
161 * The controller handle 165 * The controller handle
162 */ 166 */
@@ -248,12 +252,12 @@ struct GNUNET_TESTBED_RunHandle {
248 /** 252 /**
249 * Host registration task 253 * Host registration task
250 */ 254 */
251 struct GNUNET_SCHEDULER_Task * register_hosts_task; 255 struct GNUNET_SCHEDULER_Task *register_hosts_task;
252 256
253 /** 257 /**
254 * Task to be run of a timeout 258 * Task to be run of a timeout
255 */ 259 */
256 struct GNUNET_SCHEDULER_Task * timeout_task; 260 struct GNUNET_SCHEDULER_Task *timeout_task;
257 261
258 /** 262 /**
259 * Task run upon shutdown interrupts 263 * Task run upon shutdown interrupts
@@ -331,16 +335,17 @@ struct GNUNET_TESTBED_RunHandle {
331 * @return 32-bit key 335 * @return 32-bit key
332 */ 336 */
333static uint32_t 337static uint32_t
334rcop_key(void *rcop) 338rcop_key (void *rcop)
335{ 339{
336 return *((uint32_t *)&rcop); 340 return *((uint32_t *) &rcop);
337} 341}
338 342
339 343
340/** 344/**
341 * Context information used for finding a pointer in the rcop_map 345 * Context information used for finding a pointer in the rcop_map
342 */ 346 */
343struct SearchContext { 347struct SearchContext
348{
344 /** 349 /**
345 * The operation pointer to look for 350 * The operation pointer to look for
346 */ 351 */
@@ -362,18 +367,18 @@ struct SearchContext {
362 * @return GNUNET_YES to continue iteration; GNUNET_NO to cancel it 367 * @return GNUNET_YES to continue iteration; GNUNET_NO to cancel it
363 */ 368 */
364static int 369static int
365search_iterator(void *cls, uint32_t key, void *value) 370search_iterator (void *cls, uint32_t key, void *value)
366{ 371{
367 struct RunContextOperation *rcop = value; 372 struct RunContextOperation *rcop = value;
368 struct SearchContext *sc = cls; 373 struct SearchContext *sc = cls;
369 374
370 GNUNET_assert(NULL != rcop); 375 GNUNET_assert (NULL != rcop);
371 if (sc->query == rcop->op) 376 if (sc->query == rcop->op)
372 { 377 {
373 GNUNET_assert(NULL == sc->result); 378 GNUNET_assert (NULL == sc->result);
374 sc->result = rcop; 379 sc->result = rcop;
375 return GNUNET_NO; 380 return GNUNET_NO;
376 } 381 }
377 return GNUNET_YES; 382 return GNUNET_YES;
378} 383}
379 384
@@ -387,21 +392,22 @@ search_iterator(void *cls, uint32_t key, void *value)
387 * @return the matching RunContextOperation if found; NULL if not 392 * @return the matching RunContextOperation if found; NULL if not
388 */ 393 */
389static struct RunContextOperation * 394static struct RunContextOperation *
390search_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct GNUNET_TESTBED_Operation *op) 395search_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct
396 GNUNET_TESTBED_Operation *op)
391{ 397{
392 struct SearchContext sc; 398 struct SearchContext sc;
393 399
394 sc.query = op; 400 sc.query = op;
395 sc.result = NULL; 401 sc.result = NULL;
396 if (GNUNET_SYSERR == 402 if (GNUNET_SYSERR ==
397 GNUNET_CONTAINER_multihashmap32_get_multiple(rc->rcop_map, 403 GNUNET_CONTAINER_multihashmap32_get_multiple (rc->rcop_map,
398 rcop_key(op), 404 rcop_key (op),
399 &search_iterator, 405 &search_iterator,
400 &sc)) 406 &sc))
401 { 407 {
402 GNUNET_assert(NULL != sc.result); 408 GNUNET_assert (NULL != sc.result);
403 return sc.result; 409 return sc.result;
404 } 410 }
405 return NULL; 411 return NULL;
406} 412}
407 413
@@ -413,12 +419,13 @@ search_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct GNUNET_TESTBED_Operation
413 * @param rcop the RunContextOperation to insert 419 * @param rcop the RunContextOperation to insert
414 */ 420 */
415static void 421static void
416insert_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rcop) 422insert_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct
423 RunContextOperation *rcop)
417{ 424{
418 GNUNET_assert(GNUNET_OK == 425 GNUNET_assert (GNUNET_OK ==
419 GNUNET_CONTAINER_multihashmap32_put(rc->rcop_map, 426 GNUNET_CONTAINER_multihashmap32_put (rc->rcop_map,
420 rcop_key(rcop->op), rcop, 427 rcop_key (rcop->op), rcop,
421 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 428 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
422} 429}
423 430
424 431
@@ -430,12 +437,13 @@ insert_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rco
430 * @param rcop the RunContextOperation 437 * @param rcop the RunContextOperation
431 */ 438 */
432static void 439static void
433remove_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rcop) 440remove_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct
441 RunContextOperation *rcop)
434{ 442{
435 GNUNET_assert(GNUNET_YES == 443 GNUNET_assert (GNUNET_YES ==
436 GNUNET_CONTAINER_multihashmap32_remove(rc->rcop_map, 444 GNUNET_CONTAINER_multihashmap32_remove (rc->rcop_map,
437 rcop_key(rcop->op), 445 rcop_key (rcop->op),
438 rcop)); 446 rcop));
439} 447}
440 448
441/** 449/**
@@ -444,31 +452,31 @@ remove_rcop(struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rco
444 * @param rc the run context 452 * @param rc the run context
445 */ 453 */
446static void 454static void
447cleanup(struct GNUNET_TESTBED_RunHandle *rc) 455cleanup (struct GNUNET_TESTBED_RunHandle *rc)
448{ 456{
449 unsigned int hid; 457 unsigned int hid;
450 458
451 GNUNET_assert(NULL == rc->register_hosts_task); 459 GNUNET_assert (NULL == rc->register_hosts_task);
452 GNUNET_assert(NULL == rc->reg_handle); 460 GNUNET_assert (NULL == rc->reg_handle);
453 GNUNET_assert(NULL == rc->peers); 461 GNUNET_assert (NULL == rc->peers);
454 GNUNET_assert(NULL == rc->hclist); 462 GNUNET_assert (NULL == rc->hclist);
455 GNUNET_assert(RC_PEERS_SHUTDOWN == rc->state); 463 GNUNET_assert (RC_PEERS_SHUTDOWN == rc->state);
456 GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap32_size(rc->rcop_map)); 464 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (rc->rcop_map));
457 GNUNET_CONTAINER_multihashmap32_destroy(rc->rcop_map); 465 GNUNET_CONTAINER_multihashmap32_destroy (rc->rcop_map);
458 if (NULL != rc->c) 466 if (NULL != rc->c)
459 GNUNET_TESTBED_controller_disconnect(rc->c); 467 GNUNET_TESTBED_controller_disconnect (rc->c);
460 if (NULL != rc->cproc) 468 if (NULL != rc->cproc)
461 GNUNET_TESTBED_controller_stop(rc->cproc); 469 GNUNET_TESTBED_controller_stop (rc->cproc);
462 if (NULL != rc->h) 470 if (NULL != rc->h)
463 GNUNET_TESTBED_host_destroy(rc->h); 471 GNUNET_TESTBED_host_destroy (rc->h);
464 for (hid = 0; hid < rc->num_hosts; hid++) 472 for (hid = 0; hid < rc->num_hosts; hid++)
465 GNUNET_TESTBED_host_destroy(rc->hosts[hid]); 473 GNUNET_TESTBED_host_destroy (rc->hosts[hid]);
466 GNUNET_free_non_null(rc->hosts); 474 GNUNET_free_non_null (rc->hosts);
467 if (NULL != rc->cfg) 475 if (NULL != rc->cfg)
468 GNUNET_CONFIGURATION_destroy(rc->cfg); 476 GNUNET_CONFIGURATION_destroy (rc->cfg);
469 GNUNET_free_non_null(rc->topo_file); 477 GNUNET_free_non_null (rc->topo_file);
470 GNUNET_free_non_null(rc->trusted_ip); 478 GNUNET_free_non_null (rc->trusted_ip);
471 GNUNET_free(rc); 479 GNUNET_free (rc);
472} 480}
473 481
474 482
@@ -481,15 +489,15 @@ cleanup(struct GNUNET_TESTBED_RunHandle *rc)
481 * @return always GNUNET_YES 489 * @return always GNUNET_YES
482 */ 490 */
483static int 491static int
484rcop_cleanup_iterator(void *cls, uint32_t key, void *value) 492rcop_cleanup_iterator (void *cls, uint32_t key, void *value)
485{ 493{
486 struct GNUNET_TESTBED_RunHandle *rc = cls; 494 struct GNUNET_TESTBED_RunHandle *rc = cls;
487 struct RunContextOperation *rcop = value; 495 struct RunContextOperation *rcop = value;
488 496
489 GNUNET_assert(rc == rcop->rc); 497 GNUNET_assert (rc == rcop->rc);
490 remove_rcop(rc, rcop); 498 remove_rcop (rc, rcop);
491 GNUNET_TESTBED_operation_done(rcop->op); 499 GNUNET_TESTBED_operation_done (rcop->op);
492 GNUNET_free(rcop); 500 GNUNET_free (rcop);
493 return GNUNET_YES; 501 return GNUNET_YES;
494} 502}
495 503
@@ -500,48 +508,48 @@ rcop_cleanup_iterator(void *cls, uint32_t key, void *value)
500 * @param rc the RunContext 508 * @param rc the RunContext
501 */ 509 */
502static void 510static void
503rc_cleanup_operations(struct GNUNET_TESTBED_RunHandle *rc) 511rc_cleanup_operations (struct GNUNET_TESTBED_RunHandle *rc)
504{ 512{
505 struct CompatibilityCheckContext *hc; 513 struct CompatibilityCheckContext *hc;
506 unsigned int nhost; 514 unsigned int nhost;
507 515
508 if (NULL != rc->hclist) 516 if (NULL != rc->hclist)
517 {
518 for (nhost = 0; nhost < rc->num_hosts; nhost++)
509 { 519 {
510 for (nhost = 0; nhost < rc->num_hosts; nhost++) 520 hc = &rc->hclist[nhost];
511 { 521 if (NULL != hc->h)
512 hc = &rc->hclist[nhost]; 522 GNUNET_TESTBED_is_host_habitable_cancel (hc->h);
513 if (NULL != hc->h)
514 GNUNET_TESTBED_is_host_habitable_cancel(hc->h);
515 }
516 GNUNET_free(rc->hclist);
517 rc->hclist = NULL;
518 } 523 }
524 GNUNET_free (rc->hclist);
525 rc->hclist = NULL;
526 }
519 /* Stop register hosts task if it is running */ 527 /* Stop register hosts task if it is running */
520 if (NULL != rc->register_hosts_task) 528 if (NULL != rc->register_hosts_task)
521 { 529 {
522 GNUNET_SCHEDULER_cancel(rc->register_hosts_task); 530 GNUNET_SCHEDULER_cancel (rc->register_hosts_task);
523 rc->register_hosts_task = NULL; 531 rc->register_hosts_task = NULL;
524 } 532 }
525 if (NULL != rc->timeout_task) 533 if (NULL != rc->timeout_task)
526 { 534 {
527 GNUNET_SCHEDULER_cancel(rc->timeout_task); 535 GNUNET_SCHEDULER_cancel (rc->timeout_task);
528 rc->timeout_task = NULL; 536 rc->timeout_task = NULL;
529 } 537 }
530 if (NULL != rc->reg_handle) 538 if (NULL != rc->reg_handle)
531 { 539 {
532 GNUNET_TESTBED_cancel_registration(rc->reg_handle); 540 GNUNET_TESTBED_cancel_registration (rc->reg_handle);
533 rc->reg_handle = NULL; 541 rc->reg_handle = NULL;
534 } 542 }
535 if (NULL != rc->topology_operation) 543 if (NULL != rc->topology_operation)
536 { 544 {
537 GNUNET_TESTBED_operation_done(rc->topology_operation); 545 GNUNET_TESTBED_operation_done (rc->topology_operation);
538 rc->topology_operation = NULL; 546 rc->topology_operation = NULL;
539 } 547 }
540 /* cancel any exiting operations */ 548 /* cancel any exiting operations */
541 GNUNET_assert(GNUNET_SYSERR != 549 GNUNET_assert (GNUNET_SYSERR !=
542 GNUNET_CONTAINER_multihashmap32_iterate(rc->rcop_map, 550 GNUNET_CONTAINER_multihashmap32_iterate (rc->rcop_map,
543 &rcop_cleanup_iterator, 551 &rcop_cleanup_iterator,
544 rc)); 552 rc));
545} 553}
546 554
547 555
@@ -551,9 +559,9 @@ rc_cleanup_operations(struct GNUNET_TESTBED_RunHandle *rc)
551 * @param rc the run context 559 * @param rc the run context
552 */ 560 */
553static void 561static void
554cancel_interrupt_task(struct GNUNET_TESTBED_RunHandle *rc) 562cancel_interrupt_task (struct GNUNET_TESTBED_RunHandle *rc)
555{ 563{
556 GNUNET_SCHEDULER_cancel(rc->interrupt_task); 564 GNUNET_SCHEDULER_cancel (rc->interrupt_task);
557 rc->interrupt_task = NULL; 565 rc->interrupt_task = NULL;
558} 566}
559 567
@@ -565,7 +573,7 @@ cancel_interrupt_task(struct GNUNET_TESTBED_RunHandle *rc)
565 * @param cls run context 573 * @param cls run context
566 */ 574 */
567static void 575static void
568wait_op_completion(void *cls) 576wait_op_completion (void *cls)
569{ 577{
570 struct GNUNET_TESTBED_RunHandle *rc = cls; 578 struct GNUNET_TESTBED_RunHandle *rc = cls;
571 struct RunContextOperation *rcop; 579 struct RunContextOperation *rcop;
@@ -573,30 +581,30 @@ wait_op_completion(void *cls)
573 if ((NULL == rc->cproc) 581 if ((NULL == rc->cproc)
574 || (NULL == rc->c) 582 || (NULL == rc->c)
575 || (GNUNET_YES == rc->shutdown)) 583 || (GNUNET_YES == rc->shutdown))
584 {
585 if (NULL != rc->peers)
576 { 586 {
577 if (NULL != rc->peers) 587 GNUNET_free (rc->peers);
578 { 588 rc->peers = NULL;
579 GNUNET_free(rc->peers);
580 rc->peers = NULL;
581 }
582 goto cleanup_;
583 } 589 }
590 goto cleanup_;
591 }
584 if (NULL == rc->peers) 592 if (NULL == rc->peers)
585 goto cleanup_; 593 goto cleanup_;
586 rc->shutdown = GNUNET_YES; 594 rc->shutdown = GNUNET_YES;
587 rcop = GNUNET_new(struct RunContextOperation); 595 rcop = GNUNET_new (struct RunContextOperation);
588 rcop->rc = rc; 596 rcop->rc = rc;
589 rcop->op = GNUNET_TESTBED_shutdown_peers(rc->c, rcop, NULL, NULL); 597 rcop->op = GNUNET_TESTBED_shutdown_peers (rc->c, rcop, NULL, NULL);
590 GNUNET_assert(NULL != rcop->op); 598 GNUNET_assert (NULL != rcop->op);
591 DEBUG("Shutting down peers\n"); 599 DEBUG ("Shutting down peers\n");
592 rc->pstart_time = GNUNET_TIME_absolute_get(); 600 rc->pstart_time = GNUNET_TIME_absolute_get ();
593 insert_rcop(rc, rcop); 601 insert_rcop (rc, rcop);
594 return; 602 return;
595 603
596cleanup_: 604cleanup_:
597 rc->state = RC_PEERS_SHUTDOWN; 605 rc->state = RC_PEERS_SHUTDOWN;
598 cancel_interrupt_task(rc); 606 cancel_interrupt_task (rc);
599 cleanup(rc); 607 cleanup (rc);
600} 608}
601 609
602 610
@@ -606,28 +614,28 @@ cleanup_:
606 * @param cls the RunContext which has to be acted upon 614 * @param cls the RunContext which has to be acted upon
607 */ 615 */
608static void 616static void
609interrupt(void *cls) 617interrupt (void *cls)
610{ 618{
611 struct GNUNET_TESTBED_RunHandle *rc = cls; 619 struct GNUNET_TESTBED_RunHandle *rc = cls;
612 struct GNUNET_TESTBED_Controller *c = rc->c; 620 struct GNUNET_TESTBED_Controller *c = rc->c;
613 unsigned int size; 621 unsigned int size;
614 622
615 /* reschedule */ 623 /* reschedule */
616 rc->interrupt_task = GNUNET_SCHEDULER_add_shutdown(&interrupt, rc); 624 rc->interrupt_task = GNUNET_SCHEDULER_add_shutdown (&interrupt, rc);
617 rc_cleanup_operations(rc); 625 rc_cleanup_operations (rc);
618 if ((GNUNET_NO == rc->shutdown) && 626 if ((GNUNET_NO == rc->shutdown) &&
619 (NULL != c) && 627 (NULL != c) &&
620 (NULL != c->opc_map) && 628 (NULL != c->opc_map) &&
621 (0 != (size = GNUNET_CONTAINER_multihashmap32_size(c->opc_map)))) 629 (0 != (size = GNUNET_CONTAINER_multihashmap32_size (c->opc_map))))
622 { 630 {
623 LOG(GNUNET_ERROR_TYPE_WARNING, 631 LOG (GNUNET_ERROR_TYPE_WARNING,
624 "Shutdown postponed as there are %u operations currently active\n", 632 "Shutdown postponed as there are %u operations currently active\n",
625 size); 633 size);
626 c->opcq_empty_cb = &wait_op_completion; 634 c->opcq_empty_cb = &wait_op_completion;
627 c->opcq_empty_cls = rc; 635 c->opcq_empty_cls = rc;
628 return; 636 return;
629 } 637 }
630 wait_op_completion(rc); 638 wait_op_completion (rc);
631} 639}
632 640
633 641
@@ -639,12 +647,12 @@ interrupt(void *cls)
639 * @return the representation string; this is NOT reentrant 647 * @return the representation string; this is NOT reentrant
640 */ 648 */
641static const char * 649static const char *
642prof_time(struct GNUNET_TESTBED_RunHandle *rc) 650prof_time (struct GNUNET_TESTBED_RunHandle *rc)
643{ 651{
644 struct GNUNET_TIME_Relative ptime; 652 struct GNUNET_TIME_Relative ptime;
645 653
646 ptime = GNUNET_TIME_absolute_get_duration(rc->pstart_time); 654 ptime = GNUNET_TIME_absolute_get_duration (rc->pstart_time);
647 return GNUNET_STRINGS_relative_time_to_string(ptime, GNUNET_YES); 655 return GNUNET_STRINGS_relative_time_to_string (ptime, GNUNET_YES);
648} 656}
649 657
650 658
@@ -654,23 +662,23 @@ prof_time(struct GNUNET_TESTBED_RunHandle *rc)
654 * @param cls the RunHandle 662 * @param cls the RunHandle
655 */ 663 */
656static void 664static void
657start_peers_task(void *cls) 665start_peers_task (void *cls)
658{ 666{
659 struct GNUNET_TESTBED_RunHandle *rc = cls; 667 struct GNUNET_TESTBED_RunHandle *rc = cls;
660 struct RunContextOperation *rcop; 668 struct RunContextOperation *rcop;
661 unsigned int peer; 669 unsigned int peer;
662 670
663 DEBUG("Starting Peers\n"); 671 DEBUG ("Starting Peers\n");
664 rc->pstart_time = GNUNET_TIME_absolute_get(); 672 rc->pstart_time = GNUNET_TIME_absolute_get ();
665 for (peer = 0; peer < rc->num_peers; peer++) 673 for (peer = 0; peer < rc->num_peers; peer++)
666 { 674 {
667 rcop = GNUNET_new(struct RunContextOperation); 675 rcop = GNUNET_new (struct RunContextOperation);
668 rcop->rc = rc; 676 rcop->rc = rc;
669 rcop->op = GNUNET_TESTBED_peer_start(NULL, rc->peers[peer], NULL, NULL); 677 rcop->op = GNUNET_TESTBED_peer_start (NULL, rc->peers[peer], NULL, NULL);
670 GNUNET_assert(NULL != rcop->op); 678 GNUNET_assert (NULL != rcop->op);
671 rcop->cls = rc->peers[peer]; 679 rcop->cls = rc->peers[peer];
672 insert_rcop(rc, rcop); 680 insert_rcop (rc, rcop);
673 } 681 }
674 rc->peer_count = 0; 682 rc->peer_count = 0;
675} 683}
676 684
@@ -685,31 +693,31 @@ start_peers_task(void *cls)
685 * @param emsg NULL if peer is not NULL; else MAY contain the error description 693 * @param emsg NULL if peer is not NULL; else MAY contain the error description
686 */ 694 */
687static void 695static void
688peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) 696peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
689{ 697{
690 struct RunContextOperation *rcop = cls; 698 struct RunContextOperation *rcop = cls;
691 struct GNUNET_TESTBED_RunHandle *rc; 699 struct GNUNET_TESTBED_RunHandle *rc;
692 700
693 GNUNET_assert(NULL != rcop); 701 GNUNET_assert (NULL != rcop);
694 GNUNET_assert(NULL != (rc = rcop->rc)); 702 GNUNET_assert (NULL != (rc = rcop->rc));
695 remove_rcop(rc, rcop); 703 remove_rcop (rc, rcop);
696 GNUNET_TESTBED_operation_done(rcop->op); 704 GNUNET_TESTBED_operation_done (rcop->op);
697 GNUNET_free(rcop); 705 GNUNET_free (rcop);
698 if (NULL == peer) 706 if (NULL == peer)
699 { 707 {
700 if (NULL != emsg) 708 if (NULL != emsg)
701 LOG(GNUNET_ERROR_TYPE_ERROR, "Error while creating a peer: %s\n", 709 LOG (GNUNET_ERROR_TYPE_ERROR, "Error while creating a peer: %s\n",
702 emsg); 710 emsg);
703 GNUNET_SCHEDULER_shutdown(); 711 GNUNET_SCHEDULER_shutdown ();
704 return; 712 return;
705 } 713 }
706 rc->peers[rc->peer_count] = peer; 714 rc->peers[rc->peer_count] = peer;
707 rc->peer_count++; 715 rc->peer_count++;
708 if (rc->peer_count < rc->num_peers) 716 if (rc->peer_count < rc->num_peers)
709 return; 717 return;
710 DEBUG("%u peers created in %s\n", rc->num_peers, prof_time(rc)); 718 DEBUG ("%u peers created in %s\n", rc->num_peers, prof_time (rc));
711 rc->state = RC_PEERS_CREATED; 719 rc->state = RC_PEERS_CREATED;
712 GNUNET_SCHEDULER_add_now(&start_peers_task, rc); 720 GNUNET_SCHEDULER_add_now (&start_peers_task, rc);
713} 721}
714 722
715 723
@@ -719,13 +727,13 @@ peer_create_cb(void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
719 * @param rc the RunContext 727 * @param rc the RunContext
720 */ 728 */
721static void 729static void
722call_master(struct GNUNET_TESTBED_RunHandle *rc) 730call_master (struct GNUNET_TESTBED_RunHandle *rc)
723{ 731{
724 GNUNET_SCHEDULER_cancel(rc->timeout_task); 732 GNUNET_SCHEDULER_cancel (rc->timeout_task);
725 rc->timeout_task = NULL; 733 rc->timeout_task = NULL;
726 if (NULL != rc->test_master) 734 if (NULL != rc->test_master)
727 rc->test_master(rc->test_master_cls, rc, rc->num_peers, rc->peers, 735 rc->test_master (rc->test_master_cls, rc, rc->num_peers, rc->peers,
728 rc->links_succeeded, rc->links_failed); 736 rc->links_succeeded, rc->links_failed);
729} 737}
730 738
731 739
@@ -739,18 +747,18 @@ call_master(struct GNUNET_TESTBED_RunHandle *rc)
739 * @param nfailures the number of overlay connects which failed 747 * @param nfailures the number of overlay connects which failed
740 */ 748 */
741static void 749static void
742topology_completion_callback(void *cls, unsigned int nsuccess, 750topology_completion_callback (void *cls, unsigned int nsuccess,
743 unsigned int nfailures) 751 unsigned int nfailures)
744{ 752{
745 struct GNUNET_TESTBED_RunHandle *rc = cls; 753 struct GNUNET_TESTBED_RunHandle *rc = cls;
746 754
747 DEBUG("Overlay topology generated in %s\n", prof_time(rc)); 755 DEBUG ("Overlay topology generated in %s\n", prof_time (rc));
748 GNUNET_TESTBED_operation_done(rc->topology_operation); 756 GNUNET_TESTBED_operation_done (rc->topology_operation);
749 rc->topology_operation = NULL; 757 rc->topology_operation = NULL;
750 rc->links_succeeded = nsuccess; 758 rc->links_succeeded = nsuccess;
751 rc->links_failed = nfailures; 759 rc->links_failed = nfailures;
752 rc->state = RC_READY; 760 rc->state = RC_READY;
753 call_master(rc); 761 call_master (rc);
754} 762}
755 763
756 764
@@ -760,30 +768,31 @@ topology_completion_callback(void *cls, unsigned int nsuccess,
760 * @param rc the RunContext 768 * @param rc the RunContext
761 */ 769 */
762static void 770static void
763create_peers(struct GNUNET_TESTBED_RunHandle *rc) 771create_peers (struct GNUNET_TESTBED_RunHandle *rc)
764{ 772{
765 struct RunContextOperation *rcop; 773 struct RunContextOperation *rcop;
766 unsigned int peer; 774 unsigned int peer;
767 775
768 DEBUG("Creating peers\n"); 776 DEBUG ("Creating peers\n");
769 rc->pstart_time = GNUNET_TIME_absolute_get(); 777 rc->pstart_time = GNUNET_TIME_absolute_get ();
770 rc->peers = 778 rc->peers =
771 GNUNET_malloc(sizeof(struct GNUNET_TESTBED_Peer *) * rc->num_peers); 779 GNUNET_malloc (sizeof(struct GNUNET_TESTBED_Peer *) * rc->num_peers);
772 GNUNET_assert(NULL != rc->c); 780 GNUNET_assert (NULL != rc->c);
773 rc->peer_count = 0; 781 rc->peer_count = 0;
774 for (peer = 0; peer < rc->num_peers; peer++) 782 for (peer = 0; peer < rc->num_peers; peer++)
775 { 783 {
776 rcop = GNUNET_new(struct RunContextOperation); 784 rcop = GNUNET_new (struct RunContextOperation);
777 rcop->rc = rc; 785 rcop->rc = rc;
778 rcop->op = 786 rcop->op =
779 GNUNET_TESTBED_peer_create(rc->c, 787 GNUNET_TESTBED_peer_create (rc->c,
780 (0 == 788 (0 ==
781 rc->num_hosts) ? rc->h : rc->hosts[peer % 789 rc->num_hosts) ? rc->h : rc->hosts[peer
782 rc->num_hosts], 790 % rc->
783 rc->cfg, &peer_create_cb, rcop); 791 num_hosts],
784 GNUNET_assert(NULL != rcop->op); 792 rc->cfg, &peer_create_cb, rcop);
785 insert_rcop(rc, rcop); 793 GNUNET_assert (NULL != rcop->op);
786 } 794 insert_rcop (rc, rcop);
795 }
787} 796}
788 797
789 798
@@ -795,166 +804,170 @@ create_peers(struct GNUNET_TESTBED_RunHandle *rc)
795 * @param event information about the event 804 * @param event information about the event
796 */ 805 */
797static void 806static void
798event_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) 807event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
799{ 808{
800 struct GNUNET_TESTBED_RunHandle *rc = cls; 809 struct GNUNET_TESTBED_RunHandle *rc = cls;
801 struct RunContextOperation *rcop; 810 struct RunContextOperation *rcop;
802 811
803 if (RC_INIT == rc->state) 812 if (RC_INIT == rc->state)
813 {
814 switch (event->type)
804 { 815 {
805 switch (event->type) 816 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
806 { 817 rcop = event->op_cls;
807 case GNUNET_TESTBED_ET_OPERATION_FINISHED: 818 if (NULL != event->details.operation_finished.emsg)
808 rcop = event->op_cls; 819 {
809 if (NULL != event->details.operation_finished.emsg) 820 LOG (GNUNET_ERROR_TYPE_ERROR, _ (
810 { 821 "Linking controllers failed. Exiting"));
811 LOG(GNUNET_ERROR_TYPE_ERROR, _("Linking controllers failed. Exiting")); 822 GNUNET_SCHEDULER_shutdown ();
812 GNUNET_SCHEDULER_shutdown(); 823 }
813 } 824 else
814 else 825 rc->reg_hosts++;
815 rc->reg_hosts++; 826 GNUNET_assert (event->op == rcop->op);
816 GNUNET_assert(event->op == rcop->op); 827 remove_rcop (rc, rcop);
817 remove_rcop(rc, rcop); 828 GNUNET_TESTBED_operation_done (rcop->op);
818 GNUNET_TESTBED_operation_done(rcop->op); 829 GNUNET_free (rcop);
819 GNUNET_free(rcop); 830 if (rc->reg_hosts == rc->num_hosts)
820 if (rc->reg_hosts == rc->num_hosts) 831 {
821 { 832 rc->state = RC_LINKED;
822 rc->state = RC_LINKED; 833 create_peers (rc);
823 create_peers(rc); 834 }
824 } 835 return;
825 return; 836
826 837 default:
827 default: 838 GNUNET_break (0);
828 GNUNET_break(0); 839 GNUNET_SCHEDULER_shutdown ();
829 GNUNET_SCHEDULER_shutdown(); 840 return;
830 return;
831 }
832 } 841 }
842 }
833 if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type) 843 if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type)
834 goto call_cc; 844 goto call_cc;
835 if (NULL == (rcop = search_rcop(rc, event->op))) 845 if (NULL == (rcop = search_rcop (rc, event->op)))
836 goto call_cc; 846 goto call_cc;
837 remove_rcop(rc, rcop); 847 remove_rcop (rc, rcop);
838 GNUNET_TESTBED_operation_done(rcop->op); 848 GNUNET_TESTBED_operation_done (rcop->op);
839 GNUNET_free(rcop); 849 GNUNET_free (rcop);
840 if ((GNUNET_NO == rc->shutdown) 850 if ((GNUNET_NO == rc->shutdown)
841 && (NULL != event->details.operation_finished.emsg)) 851 && (NULL != event->details.operation_finished.emsg))
842 { 852 {
843 LOG(GNUNET_ERROR_TYPE_ERROR, "A operation has failed with error: %s\n", 853 LOG (GNUNET_ERROR_TYPE_ERROR, "A operation has failed with error: %s\n",
844 event->details.operation_finished.emsg); 854 event->details.operation_finished.emsg);
845 GNUNET_SCHEDULER_shutdown(); 855 GNUNET_SCHEDULER_shutdown ();
846 return; 856 return;
847 } 857 }
848 GNUNET_assert(GNUNET_YES == rc->shutdown); 858 GNUNET_assert (GNUNET_YES == rc->shutdown);
849 switch (rc->state) 859 switch (rc->state)
850 { 860 {
851 case RC_LINKED: 861 case RC_LINKED:
852 case RC_PEERS_CREATED: 862 case RC_PEERS_CREATED:
853 case RC_READY: 863 case RC_READY:
854 rc->state = RC_PEERS_SHUTDOWN; 864 rc->state = RC_PEERS_SHUTDOWN;
855 GNUNET_free_non_null(rc->peers); 865 GNUNET_free_non_null (rc->peers);
856 rc->peers = NULL; 866 rc->peers = NULL;
857 DEBUG("Peers shut down in %s\n", prof_time(rc)); 867 DEBUG ("Peers shut down in %s\n", prof_time (rc));
858 GNUNET_SCHEDULER_shutdown(); 868 GNUNET_SCHEDULER_shutdown ();
859 break; 869 break;
860 870
861 default: 871 default:
862 GNUNET_assert(0); 872 GNUNET_assert (0);
863 } 873 }
864 return; 874 return;
865 875
866call_cc: 876call_cc:
867 if ((0 != (rc->event_mask & (1LL << event->type))) && (NULL != rc->cc)) 877 if ((0 != (rc->event_mask & (1LL << event->type))) && (NULL != rc->cc))
868 rc->cc(rc->cc_cls, event); 878 rc->cc (rc->cc_cls, event);
869 if (GNUNET_TESTBED_ET_PEER_START != event->type) 879 if (GNUNET_TESTBED_ET_PEER_START != event->type)
870 return; 880 return;
871 if (NULL == (rcop = search_rcop(rc, event->op))) /* Not our operation */ 881 if (NULL == (rcop = search_rcop (rc, event->op))) /* Not our operation */
872 return; 882 return;
873 remove_rcop(rc, rcop); 883 remove_rcop (rc, rcop);
874 GNUNET_TESTBED_operation_done(rcop->op); 884 GNUNET_TESTBED_operation_done (rcop->op);
875 GNUNET_free(rcop); 885 GNUNET_free (rcop);
876 rc->peer_count++; 886 rc->peer_count++;
877 if (rc->peer_count < rc->num_peers) 887 if (rc->peer_count < rc->num_peers)
878 return; 888 return;
879 DEBUG("%u peers started in %s\n", rc->num_peers, prof_time(rc)); 889 DEBUG ("%u peers started in %s\n", rc->num_peers, prof_time (rc));
880 if (GNUNET_TESTBED_TOPOLOGY_NONE != rc->topology) 890 if (GNUNET_TESTBED_TOPOLOGY_NONE != rc->topology)
891 {
892 switch (rc->topology)
881 { 893 {
882 switch (rc->topology) 894 case GNUNET_TESTBED_TOPOLOGY_NONE:
883 { 895 GNUNET_assert (0);
884 case GNUNET_TESTBED_TOPOLOGY_NONE: 896
885 GNUNET_assert(0); 897 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
886 898 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
887 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: 899 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
888 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: 900 rc->topology_operation =
889 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: 901 GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers,
890 rc->topology_operation = 902 rc->peers, &rc->num_oc,
891 GNUNET_TESTBED_overlay_configure_topology(NULL, rc->num_peers, 903 &topology_completion_callback,
892 rc->peers, &rc->num_oc, 904 rc,
893 &topology_completion_callback, 905 rc->topology,
894 rc, 906 rc->random_links,
895 rc->topology, 907 GNUNET_TESTBED_TOPOLOGY_OPTION_END);
896 rc->random_links, 908 break;
897 GNUNET_TESTBED_TOPOLOGY_OPTION_END); 909
898 break; 910 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
899 911 GNUNET_assert (NULL != rc->topo_file);
900 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: 912 rc->topology_operation =
901 GNUNET_assert(NULL != rc->topo_file); 913 GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers,
902 rc->topology_operation = 914 rc->peers, &rc->num_oc,
903 GNUNET_TESTBED_overlay_configure_topology(NULL, rc->num_peers, 915 &topology_completion_callback,
904 rc->peers, &rc->num_oc, 916 rc,
905 &topology_completion_callback, 917 rc->topology,
906 rc, 918 rc->topo_file,
907 rc->topology, 919 GNUNET_TESTBED_TOPOLOGY_OPTION_END);
908 rc->topo_file, 920 break;
909 GNUNET_TESTBED_TOPOLOGY_OPTION_END); 921
910 break; 922 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
911 923 {
912 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: 924 unsigned long long number;
913 { 925 unsigned int cap;
914 unsigned long long number; 926 GNUNET_assert (GNUNET_OK ==
915 unsigned int cap; 927 GNUNET_CONFIGURATION_get_value_number (rc->cfg,
916 GNUNET_assert(GNUNET_OK == 928 TESTBED_CONFIG_SECTION,
917 GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION,
918 SCALE_FREE_CAP, 929 SCALE_FREE_CAP,
919 &number)); 930 &number));
920 cap = (unsigned int)number; 931 cap = (unsigned int) number;
921 GNUNET_assert(GNUNET_OK == 932 GNUNET_assert (GNUNET_OK ==
922 GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, 933 GNUNET_CONFIGURATION_get_value_number (rc->cfg,
934 TESTBED_CONFIG_SECTION,
923 SCALE_FREE_M, 935 SCALE_FREE_M,
924 &number)); 936 &number));
925 rc->topology_operation = 937 rc->topology_operation =
926 GNUNET_TESTBED_overlay_configure_topology(NULL, rc->num_peers, 938 GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers,
927 rc->peers, &rc->num_oc, 939 rc->peers, &rc->num_oc,
928 &topology_completion_callback, 940 &
929 rc, 941 topology_completion_callback,
930 rc->topology, 942 rc,
931 cap, /* uint16_t */ 943 rc->topology,
932 (unsigned int)number, /* uint8_t */ 944 cap, /* uint16_t */
933 GNUNET_TESTBED_TOPOLOGY_OPTION_END); 945 (unsigned int) number, /* uint8_t */
934 } 946 GNUNET_TESTBED_TOPOLOGY_OPTION_END);
935 break; 947 }
936 948 break;
937 default: 949
938 rc->topology_operation = 950 default:
939 GNUNET_TESTBED_overlay_configure_topology(NULL, rc->num_peers, 951 rc->topology_operation =
940 rc->peers, &rc->num_oc, 952 GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers,
941 &topology_completion_callback, 953 rc->peers, &rc->num_oc,
942 rc, 954 &topology_completion_callback,
943 rc->topology, 955 rc,
944 GNUNET_TESTBED_TOPOLOGY_OPTION_END); 956 rc->topology,
945 } 957 GNUNET_TESTBED_TOPOLOGY_OPTION_END);
946 if (NULL == rc->topology_operation) 958 }
947 LOG(GNUNET_ERROR_TYPE_WARNING, 959 if (NULL == rc->topology_operation)
948 "Not generating a topology. Check number of peers\n"); 960 LOG (GNUNET_ERROR_TYPE_WARNING,
949 else 961 "Not generating a topology. Check number of peers\n");
950 { 962 else
951 DEBUG("Creating overlay topology\n"); 963 {
952 rc->pstart_time = GNUNET_TIME_absolute_get(); 964 DEBUG ("Creating overlay topology\n");
953 return; 965 rc->pstart_time = GNUNET_TIME_absolute_get ();
954 } 966 return;
955 } 967 }
968 }
956 rc->state = RC_READY; 969 rc->state = RC_READY;
957 call_master(rc); 970 call_master (rc);
958} 971}
959 972
960 973
@@ -964,7 +977,7 @@ call_cc:
964 * @param cls the RunContext 977 * @param cls the RunContext
965 */ 978 */
966static void 979static void
967register_hosts(void *cls); 980register_hosts (void *cls);
968 981
969 982
970/** 983/**
@@ -974,20 +987,20 @@ register_hosts(void *cls);
974 * @param emsg the error message; NULL if host registration is successful 987 * @param emsg the error message; NULL if host registration is successful
975 */ 988 */
976static void 989static void
977host_registration_completion(void *cls, const char *emsg) 990host_registration_completion (void *cls, const char *emsg)
978{ 991{
979 struct GNUNET_TESTBED_RunHandle *rc = cls; 992 struct GNUNET_TESTBED_RunHandle *rc = cls;
980 993
981 rc->reg_handle = NULL; 994 rc->reg_handle = NULL;
982 if (NULL != emsg) 995 if (NULL != emsg)
983 { 996 {
984 LOG(GNUNET_ERROR_TYPE_WARNING, 997 LOG (GNUNET_ERROR_TYPE_WARNING,
985 _("Host registration failed for a host. Error: %s\n"), emsg); 998 _ ("Host registration failed for a host. Error: %s\n"), emsg);
986 GNUNET_SCHEDULER_shutdown(); 999 GNUNET_SCHEDULER_shutdown ();
987 return; 1000 return;
988 } 1001 }
989 rc->register_hosts_task = GNUNET_SCHEDULER_add_now(&register_hosts, 1002 rc->register_hosts_task = GNUNET_SCHEDULER_add_now (&register_hosts,
990 rc); 1003 rc);
991} 1004}
992 1005
993 1006
@@ -997,7 +1010,7 @@ host_registration_completion(void *cls, const char *emsg)
997 * @param cls RunContext 1010 * @param cls RunContext
998 */ 1011 */
999static void 1012static void
1000register_hosts(void *cls) 1013register_hosts (void *cls)
1001{ 1014{
1002 struct GNUNET_TESTBED_RunHandle *rc = cls; 1015 struct GNUNET_TESTBED_RunHandle *rc = cls;
1003 struct RunContextOperation *rcop; 1016 struct RunContextOperation *rcop;
@@ -1005,25 +1018,25 @@ register_hosts(void *cls)
1005 1018
1006 rc->register_hosts_task = NULL; 1019 rc->register_hosts_task = NULL;
1007 if (rc->reg_hosts == rc->num_hosts) 1020 if (rc->reg_hosts == rc->num_hosts)
1021 {
1022 DEBUG ("All hosts successfully registered\n");
1023 /* Start slaves */
1024 for (slave = 0; slave < rc->num_hosts; slave++)
1008 { 1025 {
1009 DEBUG("All hosts successfully registered\n"); 1026 rcop = GNUNET_new (struct RunContextOperation);
1010 /* Start slaves */ 1027 rcop->rc = rc;
1011 for (slave = 0; slave < rc->num_hosts; slave++) 1028 rcop->op =
1012 { 1029 GNUNET_TESTBED_controller_link (rcop, rc->c, rc->hosts[slave],
1013 rcop = GNUNET_new(struct RunContextOperation); 1030 rc->h, GNUNET_YES);
1014 rcop->rc = rc; 1031 GNUNET_assert (NULL != rcop->op);
1015 rcop->op = 1032 insert_rcop (rc, rcop);
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;
1023 } 1033 }
1034 rc->reg_hosts = 0;
1035 return;
1036 }
1024 rc->reg_handle = 1037 rc->reg_handle =
1025 GNUNET_TESTBED_register_host(rc->c, rc->hosts[rc->reg_hosts], 1038 GNUNET_TESTBED_register_host (rc->c, rc->hosts[rc->reg_hosts],
1026 host_registration_completion, rc); 1039 host_registration_completion, rc);
1027 rc->reg_hosts++; 1040 rc->reg_hosts++;
1028} 1041}
1029 1042
@@ -1038,37 +1051,37 @@ register_hosts(void *cls)
1038 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case 1051 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
1039 */ 1052 */
1040static void 1053static void
1041controller_status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, 1054controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
1042 int status) 1055 int status)
1043{ 1056{
1044 struct GNUNET_TESTBED_RunHandle *rc = cls; 1057 struct GNUNET_TESTBED_RunHandle *rc = cls;
1045 uint64_t event_mask; 1058 uint64_t event_mask;
1046 1059
1047 if (status != GNUNET_OK) 1060 if (status != GNUNET_OK)
1048 { 1061 {
1049 rc->cproc = NULL; 1062 rc->cproc = NULL;
1050 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1063 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1051 _("Controller crash detected. Shutting down.\n")); 1064 _ ("Controller crash detected. Shutting down.\n"));
1052 GNUNET_SCHEDULER_shutdown(); 1065 GNUNET_SCHEDULER_shutdown ();
1053 return; 1066 return;
1054 } 1067 }
1055 GNUNET_CONFIGURATION_destroy(rc->cfg); 1068 GNUNET_CONFIGURATION_destroy (rc->cfg);
1056 rc->cfg = GNUNET_CONFIGURATION_dup(cfg); 1069 rc->cfg = GNUNET_CONFIGURATION_dup (cfg);
1057 event_mask = rc->event_mask; 1070 event_mask = rc->event_mask;
1058 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); 1071 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
1059 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); 1072 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
1060 if (rc->topology < GNUNET_TESTBED_TOPOLOGY_NONE) 1073 if (rc->topology < GNUNET_TESTBED_TOPOLOGY_NONE)
1061 event_mask |= GNUNET_TESTBED_ET_CONNECT; 1074 event_mask |= GNUNET_TESTBED_ET_CONNECT;
1062 rc->c = 1075 rc->c =
1063 GNUNET_TESTBED_controller_connect(rc->h, event_mask, &event_cb, rc); 1076 GNUNET_TESTBED_controller_connect (rc->h, event_mask, &event_cb, rc);
1064 if (0 < rc->num_hosts) 1077 if (0 < rc->num_hosts)
1065 { 1078 {
1066 rc->reg_hosts = 0; 1079 rc->reg_hosts = 0;
1067 rc->register_hosts_task = GNUNET_SCHEDULER_add_now(&register_hosts, rc); 1080 rc->register_hosts_task = GNUNET_SCHEDULER_add_now (&register_hosts, rc);
1068 return; 1081 return;
1069 } 1082 }
1070 rc->state = RC_LINKED; 1083 rc->state = RC_LINKED;
1071 create_peers(rc); 1084 create_peers (rc);
1072} 1085}
1073 1086
1074 1087
@@ -1085,9 +1098,9 @@ controller_status_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
1085 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort 1098 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
1086 */ 1099 */
1087static int 1100static int
1088netint_proc(void *cls, const char *name, int isDefault, 1101netint_proc (void *cls, const char *name, int isDefault,
1089 const struct sockaddr *addr, const struct sockaddr *broadcast_addr, 1102 const struct sockaddr *addr, const struct sockaddr *broadcast_addr,
1090 const struct sockaddr *netmask, socklen_t addrlen) 1103 const struct sockaddr *netmask, socklen_t addrlen)
1091{ 1104{
1092 struct GNUNET_TESTBED_RunHandle *rc = cls; 1105 struct GNUNET_TESTBED_RunHandle *rc = cls;
1093 char hostip[NI_MAXHOST]; 1106 char hostip[NI_MAXHOST];
@@ -1096,15 +1109,15 @@ netint_proc(void *cls, const char *name, int isDefault,
1096 if (sizeof(struct sockaddr_in) != addrlen) 1109 if (sizeof(struct sockaddr_in) != addrlen)
1097 return GNUNET_OK; /* Only consider IPv4 for now */ 1110 return GNUNET_OK; /* Only consider IPv4 for now */
1098 if (0 != 1111 if (0 !=
1099 getnameinfo(addr, addrlen, hostip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) 1112 getnameinfo (addr, addrlen, hostip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST))
1100 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "getnameinfo"); 1113 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "getnameinfo");
1101 if (NULL == rc->trusted_ip) 1114 if (NULL == rc->trusted_ip)
1102 { 1115 {
1103 rc->trusted_ip = GNUNET_strdup(hostip); 1116 rc->trusted_ip = GNUNET_strdup (hostip);
1104 return GNUNET_YES; 1117 return GNUNET_YES;
1105 } 1118 }
1106 (void)GNUNET_asprintf(&buf, "%s; %s", rc->trusted_ip, hostip); 1119 (void) GNUNET_asprintf (&buf, "%s; %s", rc->trusted_ip, hostip);
1107 GNUNET_free(rc->trusted_ip); 1120 GNUNET_free (rc->trusted_ip);
1108 rc->trusted_ip = buf; 1121 rc->trusted_ip = buf;
1109 return GNUNET_YES; 1122 return GNUNET_YES;
1110} 1123}
@@ -1121,67 +1134,67 @@ netint_proc(void *cls, const char *name, int isDefault,
1121 * @param status GNUNET_YES if it is habitable; GNUNET_NO if not 1134 * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
1122 */ 1135 */
1123static void 1136static void
1124host_habitable_cb(void *cls, const struct GNUNET_TESTBED_Host *host, 1137host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host,
1125 int status) 1138 int status)
1126{ 1139{
1127 struct CompatibilityCheckContext *hc = cls; 1140 struct CompatibilityCheckContext *hc = cls;
1128 struct GNUNET_TESTBED_RunHandle *rc; 1141 struct GNUNET_TESTBED_RunHandle *rc;
1129 struct GNUNET_TESTBED_Host **old_hosts; 1142 struct GNUNET_TESTBED_Host **old_hosts;
1130 unsigned int nhost; 1143 unsigned int nhost;
1131 1144
1132 GNUNET_assert(NULL != (rc = hc->rc)); 1145 GNUNET_assert (NULL != (rc = hc->rc));
1133 nhost = hc->index; 1146 nhost = hc->index;
1134 GNUNET_assert(nhost <= rc->num_hosts); 1147 GNUNET_assert (nhost <= rc->num_hosts);
1135 GNUNET_assert(host == rc->hosts[nhost]); 1148 GNUNET_assert (host == rc->hosts[nhost]);
1136 hc->h = NULL; 1149 hc->h = NULL;
1137 if (GNUNET_NO == status) 1150 if (GNUNET_NO == status)
1138 { 1151 {
1139 if ((NULL != host) && (NULL != GNUNET_TESTBED_host_get_hostname(host))) 1152 if ((NULL != host) && (NULL != GNUNET_TESTBED_host_get_hostname (host)))
1140 LOG(GNUNET_ERROR_TYPE_ERROR, _("Host %s cannot start testbed\n"), 1153 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Host %s cannot start testbed\n"),
1141 GNUNET_TESTBED_host_get_hostname(host)); 1154 GNUNET_TESTBED_host_get_hostname (host));
1142 else 1155 else
1143 LOG(GNUNET_ERROR_TYPE_ERROR, 1156 LOG (GNUNET_ERROR_TYPE_ERROR,
1144 _("Testbed cannot be started on localhost\n")); 1157 _ ("Testbed cannot be started on localhost\n"));
1145 GNUNET_SCHEDULER_shutdown(); 1158 GNUNET_SCHEDULER_shutdown ();
1146 return; 1159 return;
1147 } 1160 }
1148 rc->reg_hosts++; 1161 rc->reg_hosts++;
1149 if (rc->reg_hosts < rc->num_hosts) 1162 if (rc->reg_hosts < rc->num_hosts)
1150 return; 1163 return;
1151 GNUNET_free(rc->hclist); 1164 GNUNET_free (rc->hclist);
1152 rc->hclist = NULL; 1165 rc->hclist = NULL;
1153 rc->h = rc->hosts[0]; 1166 rc->h = rc->hosts[0];
1154 rc->num_hosts--; 1167 rc->num_hosts--;
1155 if (0 < rc->num_hosts) 1168 if (0 < rc->num_hosts)
1156 { 1169 {
1157 old_hosts = rc->hosts; 1170 old_hosts = rc->hosts;
1158 rc->hosts = 1171 rc->hosts =
1159 GNUNET_malloc(sizeof(struct GNUNET_TESTBED_Host *) * rc->num_hosts); 1172 GNUNET_malloc (sizeof(struct GNUNET_TESTBED_Host *) * rc->num_hosts);
1160 GNUNET_memcpy(rc->hosts, &old_hosts[1], 1173 GNUNET_memcpy (rc->hosts, &old_hosts[1],
1161 (sizeof(struct GNUNET_TESTBED_Host *) * rc->num_hosts)); 1174 (sizeof(struct GNUNET_TESTBED_Host *) * rc->num_hosts));
1162 GNUNET_free(old_hosts); 1175 GNUNET_free (old_hosts);
1163 } 1176 }
1164 else 1177 else
1165 { 1178 {
1166 GNUNET_free(rc->hosts); 1179 GNUNET_free (rc->hosts);
1167 rc->hosts = NULL; 1180 rc->hosts = NULL;
1168 } 1181 }
1169 GNUNET_TESTBED_host_resolve_(rc->h); 1182 GNUNET_TESTBED_host_resolve_ (rc->h);
1170 for (nhost = 0; nhost < rc->num_hosts; nhost++) 1183 for (nhost = 0; nhost < rc->num_hosts; nhost++)
1171 GNUNET_TESTBED_host_resolve_(rc->hosts[nhost]); 1184 GNUNET_TESTBED_host_resolve_ (rc->hosts[nhost]);
1172 GNUNET_OS_network_interfaces_list(netint_proc, rc); 1185 GNUNET_OS_network_interfaces_list (netint_proc, rc);
1173 if (NULL == rc->trusted_ip) 1186 if (NULL == rc->trusted_ip)
1174 rc->trusted_ip = GNUNET_strdup("127.0.0.1"); 1187 rc->trusted_ip = GNUNET_strdup ("127.0.0.1");
1175 rc->cproc = 1188 rc->cproc =
1176 GNUNET_TESTBED_controller_start(rc->trusted_ip, rc->h, 1189 GNUNET_TESTBED_controller_start (rc->trusted_ip, rc->h,
1177 &controller_status_cb, rc); 1190 &controller_status_cb, rc);
1178 GNUNET_free(rc->trusted_ip); 1191 GNUNET_free (rc->trusted_ip);
1179 rc->trusted_ip = NULL; 1192 rc->trusted_ip = NULL;
1180 if (NULL == rc->cproc) 1193 if (NULL == rc->cproc)
1181 { 1194 {
1182 LOG(GNUNET_ERROR_TYPE_ERROR, _("Cannot start the master controller")); 1195 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Cannot start the master controller"));
1183 GNUNET_SCHEDULER_shutdown(); 1196 GNUNET_SCHEDULER_shutdown ();
1184 } 1197 }
1185} 1198}
1186 1199
1187 1200
@@ -1191,16 +1204,16 @@ host_habitable_cb(void *cls, const struct GNUNET_TESTBED_Host *host,
1191 * @param cls the RunContext 1204 * @param cls the RunContext
1192 */ 1205 */
1193static void 1206static void
1194timeout_task(void *cls) 1207timeout_task (void *cls)
1195{ 1208{
1196 struct GNUNET_TESTBED_RunHandle *rc = cls; 1209 struct GNUNET_TESTBED_RunHandle *rc = cls;
1197 1210
1198 rc->timeout_task = NULL; 1211 rc->timeout_task = NULL;
1199 LOG(GNUNET_ERROR_TYPE_ERROR, 1212 LOG (GNUNET_ERROR_TYPE_ERROR,
1200 _("Shutting down testbed due to timeout while setup.\n")); 1213 _ ("Shutting down testbed due to timeout while setup.\n"));
1201 GNUNET_SCHEDULER_shutdown(); 1214 GNUNET_SCHEDULER_shutdown ();
1202 if (NULL != rc->test_master) 1215 if (NULL != rc->test_master)
1203 rc->test_master(rc->test_master_cls, rc, 0, NULL, 0, 0); 1216 rc->test_master (rc->test_master_cls, rc, 0, NULL, 0, 0);
1204 rc->test_master = NULL; 1217 rc->test_master = NULL;
1205} 1218}
1206 1219
@@ -1233,12 +1246,12 @@ timeout_task(void *cls)
1233 * @param test_master_cls closure for 'test_master'. 1246 * @param test_master_cls closure for 'test_master'.
1234 */ 1247 */
1235void 1248void
1236GNUNET_TESTBED_run(const char *host_filename, 1249GNUNET_TESTBED_run (const char *host_filename,
1237 const struct GNUNET_CONFIGURATION_Handle *cfg, 1250 const struct GNUNET_CONFIGURATION_Handle *cfg,
1238 unsigned int num_peers, uint64_t event_mask, 1251 unsigned int num_peers, uint64_t event_mask,
1239 GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, 1252 GNUNET_TESTBED_ControllerCallback cc, void *cc_cls,
1240 GNUNET_TESTBED_TestMaster test_master, 1253 GNUNET_TESTBED_TestMaster test_master,
1241 void *test_master_cls) 1254 void *test_master_cls)
1242{ 1255{
1243 struct GNUNET_TESTBED_RunHandle *rc; 1256 struct GNUNET_TESTBED_RunHandle *rc;
1244 char *topology; 1257 char *topology;
@@ -1248,33 +1261,33 @@ GNUNET_TESTBED_run(const char *host_filename,
1248 unsigned int hid; 1261 unsigned int hid;
1249 unsigned int nhost; 1262 unsigned int nhost;
1250 1263
1251 GNUNET_assert(num_peers > 0); 1264 GNUNET_assert (num_peers > 0);
1252 rc = GNUNET_new(struct GNUNET_TESTBED_RunHandle); 1265 rc = GNUNET_new (struct GNUNET_TESTBED_RunHandle);
1253 rc->cfg = GNUNET_CONFIGURATION_dup(cfg); 1266 rc->cfg = GNUNET_CONFIGURATION_dup (cfg);
1254#if ENABLE_SUPERMUC 1267#if ENABLE_SUPERMUC
1255 rc->num_hosts = GNUNET_TESTBED_hosts_load_from_loadleveler(rc->cfg, 1268 rc->num_hosts = GNUNET_TESTBED_hosts_load_from_loadleveler (rc->cfg,
1256 &rc->hosts); 1269 &rc->hosts);
1257 if (0 == rc->num_hosts) 1270 if (0 == rc->num_hosts)
1258 { 1271 {
1259 LOG(GNUNET_ERROR_TYPE_WARNING, 1272 LOG (GNUNET_ERROR_TYPE_WARNING,
1260 _("No hosts loaded from LoadLeveler. Need at least one host\n")); 1273 _ ("No hosts loaded from LoadLeveler. Need at least one host\n"));
1261 goto error_cleanup; 1274 goto error_cleanup;
1262 } 1275 }
1263#else 1276#else
1264 if (NULL != host_filename) 1277 if (NULL != host_filename)
1278 {
1279 rc->num_hosts =
1280 GNUNET_TESTBED_hosts_load_from_file (host_filename, rc->cfg,
1281 &rc->hosts);
1282 if (0 == rc->num_hosts)
1265 { 1283 {
1266 rc->num_hosts = 1284 LOG (GNUNET_ERROR_TYPE_WARNING,
1267 GNUNET_TESTBED_hosts_load_from_file(host_filename, rc->cfg, 1285 _ ("No hosts loaded. Need at least one host\n"));
1268 &rc->hosts); 1286 goto error_cleanup;
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 } 1287 }
1288 }
1276 else 1289 else
1277 rc->h = GNUNET_TESTBED_host_create(NULL, NULL, rc->cfg, 0); 1290 rc->h = GNUNET_TESTBED_host_create (NULL, NULL, rc->cfg, 0);
1278#endif 1291#endif
1279 rc->num_peers = num_peers; 1292 rc->num_peers = num_peers;
1280 rc->event_mask = event_mask; 1293 rc->event_mask = event_mask;
@@ -1285,162 +1298,170 @@ GNUNET_TESTBED_run(const char *host_filename,
1285 rc->state = RC_INIT; 1298 rc->state = RC_INIT;
1286 rc->topology = GNUNET_TESTBED_TOPOLOGY_NONE; 1299 rc->topology = GNUNET_TESTBED_TOPOLOGY_NONE;
1287 if (GNUNET_OK == 1300 if (GNUNET_OK ==
1288 GNUNET_CONFIGURATION_get_value_string(rc->cfg, TESTBED_CONFIG_SECTION, 1301 GNUNET_CONFIGURATION_get_value_string (rc->cfg, TESTBED_CONFIG_SECTION,
1289 "OVERLAY_TOPOLOGY", &topology)) 1302 "OVERLAY_TOPOLOGY", &topology))
1303 {
1304 if (GNUNET_NO == GNUNET_TESTBED_topology_get_ (&rc->topology, topology))
1290 { 1305 {
1291 if (GNUNET_NO == GNUNET_TESTBED_topology_get_(&rc->topology, topology)) 1306 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
1292 { 1307 TESTBED_CONFIG_SECTION,
1293 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, 1308 "OVERLAY_TOPLOGY",
1294 "OVERLAY_TOPLOGY", 1309 _
1295 _ 1310 (
1296 ("Specified topology must be supported by testbed")); 1311 "Specified topology must be supported by testbed"));
1297 }
1298 GNUNET_free(topology);
1299 } 1312 }
1313 GNUNET_free (topology);
1314 }
1300 switch (rc->topology) 1315 switch (rc->topology)
1316 {
1317 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
1318 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
1319 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
1320 if (GNUNET_OK !=
1321 GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION,
1322 "OVERLAY_RANDOM_LINKS",
1323 &number))
1301 { 1324 {
1302 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: 1325 /* OVERLAY option RANDOM & SMALL_WORLD_RING requires OVERLAY_RANDOM_LINKS
1303 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: 1326 * option to be set to the number of random links to be established */
1304 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: 1327 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1305 if (GNUNET_OK != 1328 TESTBED_CONFIG_SECTION,
1306 GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, 1329 "OVERLAY_RANDOM_LINKS");
1307 "OVERLAY_RANDOM_LINKS", 1330 goto error_cleanup;
1308 &number)) 1331 }
1309 { 1332 if (number > UINT32_MAX)
1310 /* OVERLAY option RANDOM & SMALL_WORLD_RING requires OVERLAY_RANDOM_LINKS 1333 {
1311 * option to be set to the number of random links to be established */ 1334 GNUNET_break (0); /* Too big number */
1312 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, 1335 goto error_cleanup;
1313 "OVERLAY_RANDOM_LINKS"); 1336 }
1314 goto error_cleanup; 1337 rc->random_links = (unsigned int) number;
1315 } 1338 break;
1316 if (number > UINT32_MAX) 1339
1317 { 1340 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
1318 GNUNET_break(0); /* Too big number */ 1341 if (GNUNET_OK !=
1319 goto error_cleanup; 1342 GNUNET_CONFIGURATION_get_value_filename (rc->cfg,
1320 } 1343 TESTBED_CONFIG_SECTION,
1321 rc->random_links = (unsigned int)number; 1344 "OVERLAY_TOPOLOGY_FILE",
1322 break; 1345 &rc->topo_file))
1323 1346 {
1324 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: 1347 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1325 if (GNUNET_OK != 1348 TESTBED_CONFIG_SECTION,
1326 GNUNET_CONFIGURATION_get_value_filename(rc->cfg, TESTBED_CONFIG_SECTION, 1349 "OVERLAY_TOPOLOGY_FILE");
1327 "OVERLAY_TOPOLOGY_FILE", 1350 goto error_cleanup;
1328 &rc->topo_file)) 1351 }
1329 { 1352 goto warn_ignore;
1330 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION,
1331 "OVERLAY_TOPOLOGY_FILE");
1332 goto error_cleanup;
1333 }
1334 goto warn_ignore;
1335 1353
1336 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: 1354 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
1337 if (GNUNET_OK != 1355 if (GNUNET_OK !=
1338 GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, 1356 GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION,
1339 SCALE_FREE_CAP, &number)) 1357 SCALE_FREE_CAP, &number))
1340 { 1358 {
1341 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, 1359 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1342 SCALE_FREE_CAP); 1360 TESTBED_CONFIG_SECTION,
1343 goto error_cleanup; 1361 SCALE_FREE_CAP);
1344 } 1362 goto error_cleanup;
1345 if (UINT16_MAX < number) 1363 }
1346 { 1364 if (UINT16_MAX < number)
1347 LOG(GNUNET_ERROR_TYPE_ERROR, 1365 {
1348 _("Maximum number of edges a peer can have in a scale free topology" 1366 LOG (GNUNET_ERROR_TYPE_ERROR,
1349 " cannot be more than %u. Given `%s = %llu'"), UINT16_MAX, 1367 _ ("Maximum number of edges a peer can have in a scale free topology"
1350 SCALE_FREE_CAP, number); 1368 " cannot be more than %u. Given `%s = %llu'"), UINT16_MAX,
1351 goto error_cleanup; 1369 SCALE_FREE_CAP, number);
1352 } 1370 goto error_cleanup;
1353 if (GNUNET_OK != 1371 }
1354 GNUNET_CONFIGURATION_get_value_number(rc->cfg, TESTBED_CONFIG_SECTION, 1372 if (GNUNET_OK !=
1355 SCALE_FREE_M, &number)) 1373 GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION,
1356 { 1374 SCALE_FREE_M, &number))
1357 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, TESTBED_CONFIG_SECTION, 1375 {
1358 SCALE_FREE_M); 1376 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1359 goto error_cleanup; 1377 TESTBED_CONFIG_SECTION,
1360 } 1378 SCALE_FREE_M);
1361 if (UINT8_MAX < number) 1379 goto error_cleanup;
1362 { 1380 }
1363 LOG(GNUNET_ERROR_TYPE_ERROR, 1381 if (UINT8_MAX < number)
1364 _("The number of edges that can established when adding a new node" 1382 {
1365 " to scale free topology cannot be more than %u. Given `%s = %llu'"), 1383 LOG (GNUNET_ERROR_TYPE_ERROR,
1366 UINT8_MAX, SCALE_FREE_M, number); 1384 _ ("The number of edges that can established when adding a new node"
1367 goto error_cleanup; 1385 " to scale free topology cannot be more than %u. Given `%s = %llu'"),
1368 } 1386 UINT8_MAX, SCALE_FREE_M, number);
1369 goto warn_ignore; 1387 goto error_cleanup;
1388 }
1389 goto warn_ignore;
1370 1390
1371 case GNUNET_TESTBED_TOPOLOGY_OPTION_END: 1391 case GNUNET_TESTBED_TOPOLOGY_OPTION_END:
1372 /* not allowed! */ 1392 /* not allowed! */
1373 GNUNET_assert(0); 1393 GNUNET_assert (0);
1374 1394
1375 default: 1395 default:
1376warn_ignore: 1396warn_ignore:
1377 /* Warn if OVERLAY_RANDOM_LINKS is present that it will be ignored */ 1397 /* Warn if OVERLAY_RANDOM_LINKS is present that it will be ignored */
1378 if (GNUNET_YES == 1398 if (GNUNET_YES ==
1379 GNUNET_CONFIGURATION_have_value(rc->cfg, TESTBED_CONFIG_SECTION, 1399 GNUNET_CONFIGURATION_have_value (rc->cfg, TESTBED_CONFIG_SECTION,
1380 "OVERLAY_RANDOM_LINKS")) 1400 "OVERLAY_RANDOM_LINKS"))
1381 LOG(GNUNET_ERROR_TYPE_WARNING, 1401 LOG (GNUNET_ERROR_TYPE_WARNING,
1382 "Ignoring value of `OVERLAY_RANDOM_LINKS' in given configuration\n"); 1402 "Ignoring value of `OVERLAY_RANDOM_LINKS' in given configuration\n");
1383 break; 1403 break;
1384 } 1404 }
1385 if (0 != rc->num_hosts) 1405 if (0 != rc->num_hosts)
1406 {
1407 rc->hclist = GNUNET_malloc (sizeof(struct CompatibilityCheckContext)
1408 * rc->num_hosts);
1409 for (nhost = 0; nhost < rc->num_hosts; nhost++)
1386 { 1410 {
1387 rc->hclist = GNUNET_malloc(sizeof(struct CompatibilityCheckContext) 1411 hc = &rc->hclist[nhost];
1388 * rc->num_hosts); 1412 hc->index = nhost;
1389 for (nhost = 0; nhost < rc->num_hosts; nhost++) 1413 hc->rc = rc;
1414 hc->h = GNUNET_TESTBED_is_host_habitable (rc->hosts[nhost], rc->cfg,
1415 &host_habitable_cb, hc);
1416 if (NULL == hc->h)
1417 {
1418 GNUNET_break (0);
1419 for (nhost = 0; nhost < rc->num_hosts; nhost++)
1390 { 1420 {
1391 hc = &rc->hclist[nhost]; 1421 hc = &rc->hclist[nhost];
1392 hc->index = nhost; 1422 if (NULL != hc->h)
1393 hc->rc = rc; 1423 GNUNET_TESTBED_is_host_habitable_cancel (hc->h);
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 }
1409 } 1424 }
1425 GNUNET_free (rc->hclist);
1426 rc->hclist = NULL;
1427 goto error_cleanup;
1428 }
1410 } 1429 }
1430 }
1411 else 1431 else
1412 rc->cproc = 1432 rc->cproc =
1413 GNUNET_TESTBED_controller_start("127.0.0.1", rc->h, 1433 GNUNET_TESTBED_controller_start ("127.0.0.1", rc->h,
1414 &controller_status_cb, rc); 1434 &controller_status_cb, rc);
1415 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(cfg, TESTBED_CONFIG_SECTION, 1435 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg,
1416 "SETUP_TIMEOUT", 1436 TESTBED_CONFIG_SECTION,
1417 &timeout)) 1437 "SETUP_TIMEOUT",
1418 { 1438 &timeout))
1419 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1439 {
1420 DEFAULT_SETUP_TIMEOUT); 1440 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1421 } 1441 DEFAULT_SETUP_TIMEOUT);
1422 rc->rcop_map = GNUNET_CONTAINER_multihashmap32_create(256); 1442 }
1443 rc->rcop_map = GNUNET_CONTAINER_multihashmap32_create (256);
1423 rc->timeout_task = 1444 rc->timeout_task =
1424 GNUNET_SCHEDULER_add_delayed(timeout, &timeout_task, rc); 1445 GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, rc);
1425 GNUNET_assert(NULL == rc->interrupt_task); 1446 GNUNET_assert (NULL == rc->interrupt_task);
1426 rc->interrupt_task = 1447 rc->interrupt_task =
1427 GNUNET_SCHEDULER_add_shutdown(&interrupt, 1448 GNUNET_SCHEDULER_add_shutdown (&interrupt,
1428 rc); 1449 rc);
1429 return; 1450 return;
1430 1451
1431error_cleanup: 1452error_cleanup:
1432 if (NULL != rc->h) 1453 if (NULL != rc->h)
1433 GNUNET_TESTBED_host_destroy(rc->h); 1454 GNUNET_TESTBED_host_destroy (rc->h);
1434 if (NULL != rc->hosts) 1455 if (NULL != rc->hosts)
1435 { 1456 {
1436 for (hid = 0; hid < rc->num_hosts; hid++) 1457 for (hid = 0; hid < rc->num_hosts; hid++)
1437 if (NULL != rc->hosts[hid]) 1458 if (NULL != rc->hosts[hid])
1438 GNUNET_TESTBED_host_destroy(rc->hosts[hid]); 1459 GNUNET_TESTBED_host_destroy (rc->hosts[hid]);
1439 GNUNET_free(rc->hosts); 1460 GNUNET_free (rc->hosts);
1440 } 1461 }
1441 if (NULL != rc->cfg) 1462 if (NULL != rc->cfg)
1442 GNUNET_CONFIGURATION_destroy(rc->cfg); 1463 GNUNET_CONFIGURATION_destroy (rc->cfg);
1443 GNUNET_free(rc); 1464 GNUNET_free (rc);
1444} 1465}
1445 1466
1446 1467
@@ -1452,7 +1473,7 @@ error_cleanup:
1452 * @return handle to the master controller 1473 * @return handle to the master controller
1453 */ 1474 */
1454struct GNUNET_TESTBED_Controller * 1475struct GNUNET_TESTBED_Controller *
1455GNUNET_TESTBED_run_get_controller_handle(struct GNUNET_TESTBED_RunHandle *h) 1476GNUNET_TESTBED_run_get_controller_handle (struct GNUNET_TESTBED_RunHandle *h)
1456{ 1477{
1457 return h->c; 1478 return h->c;
1458} 1479}
diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c
index 58ccf4580..191dbab66 100644
--- a/src/testbed/testbed_api_topology.c
+++ b/src/testbed/testbed_api_topology.c
@@ -34,7 +34,7 @@
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,7 +52,8 @@ struct TopologyContext;
52/** 52/**
53 * Representation of an overlay link 53 * Representation of an overlay link
54 */ 54 */
55struct OverlayLink { 55struct OverlayLink
56{
56 /** 57 /**
57 * An operation corresponding to this link 58 * An operation corresponding to this link
58 */ 59 */
@@ -78,7 +79,8 @@ struct OverlayLink {
78/** 79/**
79 * Representation of an underlay link 80 * Representation of an underlay link
80 */ 81 */
81struct UnderlayLink { 82struct UnderlayLink
83{
82 /** 84 /**
83 * position of peer A's handle in peers array 85 * position of peer A's handle in peers array
84 */ 86 */
@@ -106,7 +108,8 @@ struct UnderlayLink {
106}; 108};
107 109
108 110
109struct RetryListEntry { 111struct RetryListEntry
112{
110 /** 113 /**
111 * the next pointer for the DLL 114 * the next pointer for the DLL
112 */ 115 */
@@ -127,7 +130,8 @@ struct RetryListEntry {
127/** 130/**
128 * Context information for overlay topologies 131 * Context information for overlay topologies
129 */ 132 */
130struct TopologyContextOverlay { 133struct TopologyContextOverlay
134{
131 /** 135 /**
132 * The array of peers 136 * The array of peers
133 */ 137 */
@@ -193,7 +197,8 @@ struct TopologyContextOverlay {
193/** 197/**
194 * Topology context information for underlay topologies 198 * Topology context information for underlay topologies
195 */ 199 */
196struct TopologyContextUnderlay { 200struct TopologyContextUnderlay
201{
197 /** 202 /**
198 * The link array 203 * The link array
199 */ 204 */
@@ -204,11 +209,13 @@ struct TopologyContextUnderlay {
204/** 209/**
205 * Context information for topology operations 210 * Context information for topology operations
206 */ 211 */
207struct TopologyContext { 212struct TopologyContext
213{
208 /** 214 /**
209 * The type of this context 215 * The type of this context
210 */ 216 */
211 enum { 217 enum
218 {
212 /** 219 /**
213 * Type for underlay topology 220 * Type for underlay topology
214 */ 221 */
@@ -220,7 +227,8 @@ struct TopologyContext {
220 TOPOLOGYCONTEXT_TYPE_OVERLAY 227 TOPOLOGYCONTEXT_TYPE_OVERLAY
221 } type; 228 } type;
222 229
223 union { 230 union
231 {
224 /** 232 /**
225 * Topology context information for overlay topology 233 * Topology context information for overlay topology
226 */ 234 */
@@ -333,69 +341,69 @@ static const char *topology_strings[] = {
333 * operation has executed successfully. 341 * operation has executed successfully.
334 */ 342 */
335static void 343static void
336overlay_link_completed(void *cls, 344overlay_link_completed (void *cls,
337 struct GNUNET_TESTBED_Operation *op, 345 struct GNUNET_TESTBED_Operation *op,
338 const char *emsg) 346 const char *emsg)
339{ 347{
340 struct OverlayLink *link = cls; 348 struct OverlayLink *link = cls;
341 struct TopologyContext *tc; 349 struct TopologyContext *tc;
342 struct TopologyContextOverlay *overlay; 350 struct TopologyContextOverlay *overlay;
343 struct RetryListEntry *retry_entry; 351 struct RetryListEntry *retry_entry;
344 352
345 GNUNET_assert(op == link->op); 353 GNUNET_assert (op == link->op);
346 GNUNET_TESTBED_operation_done(op); 354 GNUNET_TESTBED_operation_done (op);
347 link->op = NULL; 355 link->op = NULL;
348 tc = link->tc; 356 tc = link->tc;
349 GNUNET_assert(TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); 357 GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type);
350 overlay = &tc->u.overlay; 358 overlay = &tc->u.overlay;
351 if (NULL != emsg) 359 if (NULL != emsg)
360 {
361 overlay->nfailures++;
362 if (0 != overlay->retry_cnt)
352 { 363 {
353 overlay->nfailures++; 364 LOG (GNUNET_ERROR_TYPE_WARNING,
354 if (0 != overlay->retry_cnt) 365 "Error while establishing a link: %s -- Retrying\n",
355 { 366 emsg);
356 LOG(GNUNET_ERROR_TYPE_WARNING, 367 retry_entry = GNUNET_new (struct RetryListEntry);
357 "Error while establishing a link: %s -- Retrying\n", 368 retry_entry->link = link;
358 emsg); 369 GNUNET_CONTAINER_DLL_insert_tail (overlay->rl_head,
359 retry_entry = GNUNET_new(struct RetryListEntry); 370 overlay->rl_tail,
360 retry_entry->link = link; 371 retry_entry);
361 GNUNET_CONTAINER_DLL_insert_tail(overlay->rl_head,
362 overlay->rl_tail,
363 retry_entry);
364 }
365 } 372 }
373 }
366 else 374 else
367 overlay->nsuccess++; 375 overlay->nsuccess++;
368 overlay->ncompleted++; 376 overlay->ncompleted++;
369 if (overlay->ncompleted < overlay->nlinks) 377 if (overlay->ncompleted < overlay->nlinks)
370 return; 378 return;
371 if ((0 != overlay->retry_cnt) && (NULL != overlay->rl_head)) 379 if ((0 != overlay->retry_cnt) && (NULL != overlay->rl_head))
380 {
381 overlay->retry_cnt--;
382 overlay->ncompleted = 0;
383 overlay->nlinks = 0;
384 while (NULL != (retry_entry = overlay->rl_head))
372 { 385 {
373 overlay->retry_cnt--; 386 link = retry_entry->link;
374 overlay->ncompleted = 0; 387 link->op =
375 overlay->nlinks = 0; 388 GNUNET_TESTBED_overlay_connect (overlay->op_cls,
376 while (NULL != (retry_entry = overlay->rl_head)) 389 &overlay_link_completed,
377 { 390 link,
378 link = retry_entry->link; 391 overlay->peers[link->A],
379 link->op = 392 overlay->peers[link->B]);
380 GNUNET_TESTBED_overlay_connect(overlay->op_cls, 393 overlay->nlinks++;
381 &overlay_link_completed, 394 GNUNET_CONTAINER_DLL_remove (overlay->rl_head,
382 link, 395 overlay->rl_tail,
383 overlay->peers[link->A], 396 retry_entry);
384 overlay->peers[link->B]); 397 GNUNET_free (retry_entry);
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;
392 } 398 }
399 return;
400 }
393 if (NULL != overlay->comp_cb) 401 if (NULL != overlay->comp_cb)
394 { 402 {
395 overlay->comp_cb(overlay->comp_cb_cls, 403 overlay->comp_cb (overlay->comp_cb_cls,
396 overlay->nsuccess, 404 overlay->nsuccess,
397 overlay->nfailures); 405 overlay->nfailures);
398 } 406 }
399} 407}
400 408
401 409
@@ -406,24 +414,24 @@ overlay_link_completed(void *cls,
406 * @param cls the Topology context 414 * @param cls the Topology context
407 */ 415 */
408static void 416static void
409opstart_overlay_configure_topology(void *cls) 417opstart_overlay_configure_topology (void *cls)
410{ 418{
411 struct TopologyContext *tc = cls; 419 struct TopologyContext *tc = cls;
412 struct TopologyContextOverlay *overlay; 420 struct TopologyContextOverlay *overlay;
413 unsigned int p; 421 unsigned int p;
414 422
415 GNUNET_assert(TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); 423 GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type);
416 overlay = &tc->u.overlay; 424 overlay = &tc->u.overlay;
417 overlay->nlinks = tc->link_array_size; 425 overlay->nlinks = tc->link_array_size;
418 for (p = 0; p < tc->link_array_size; p++) 426 for (p = 0; p < tc->link_array_size; p++)
419 { 427 {
420 overlay->link_array[p].op = 428 overlay->link_array[p].op =
421 GNUNET_TESTBED_overlay_connect(overlay->op_cls, 429 GNUNET_TESTBED_overlay_connect (overlay->op_cls,
422 &overlay_link_completed, 430 &overlay_link_completed,
423 &overlay->link_array[p], 431 &overlay->link_array[p],
424 overlay->peers[overlay->link_array[p].A], 432 overlay->peers[overlay->link_array[p].A],
425 overlay->peers[overlay->link_array[p].B]); 433 overlay->peers[overlay->link_array[p].B]);
426 } 434 }
427} 435}
428 436
429 437
@@ -433,28 +441,29 @@ opstart_overlay_configure_topology(void *cls)
433 * @param cls the Topology context 441 * @param cls the Topology context
434 */ 442 */
435static void 443static void
436oprelease_overlay_configure_topology(void *cls) 444oprelease_overlay_configure_topology (void *cls)
437{ 445{
438 struct TopologyContext *tc = cls; 446 struct TopologyContext *tc = cls;
439 struct TopologyContextOverlay *overlay; 447 struct TopologyContextOverlay *overlay;
440 struct RetryListEntry *retry_entry; 448 struct RetryListEntry *retry_entry;
441 unsigned int p; 449 unsigned int p;
442 450
443 GNUNET_assert(TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type); 451 GNUNET_assert (TOPOLOGYCONTEXT_TYPE_OVERLAY == tc->type);
444 overlay = &tc->u.overlay; 452 overlay = &tc->u.overlay;
445 while (NULL != (retry_entry = overlay->rl_head)) 453 while (NULL != (retry_entry = overlay->rl_head))
446 { 454 {
447 GNUNET_CONTAINER_DLL_remove(overlay->rl_head, overlay->rl_tail, retry_entry); 455 GNUNET_CONTAINER_DLL_remove (overlay->rl_head, overlay->rl_tail,
448 GNUNET_free(retry_entry); 456 retry_entry);
449 } 457 GNUNET_free (retry_entry);
458 }
450 if (NULL != overlay->link_array) 459 if (NULL != overlay->link_array)
451 { 460 {
452 for (p = 0; p < tc->link_array_size; p++) 461 for (p = 0; p < tc->link_array_size; p++)
453 if (NULL != overlay->link_array[p].op) 462 if (NULL != overlay->link_array[p].op)
454 GNUNET_TESTBED_operation_done(overlay->link_array[p].op); 463 GNUNET_TESTBED_operation_done (overlay->link_array[p].op);
455 GNUNET_free(overlay->link_array); 464 GNUNET_free (overlay->link_array);
456 } 465 }
457 GNUNET_free(tc); 466 GNUNET_free (tc);
458} 467}
459 468
460 469
@@ -468,23 +477,23 @@ oprelease_overlay_configure_topology(void *cls)
468 * @return 477 * @return
469 */ 478 */
470static void 479static void
471make_link(unsigned int offset, 480make_link (unsigned int offset,
472 uint32_t A, 481 uint32_t A,
473 uint32_t B, 482 uint32_t B,
474 struct TopologyContext *tc) 483 struct TopologyContext *tc)
475{ 484{
476 GNUNET_assert(A != B); 485 GNUNET_assert (A != B);
477 switch (tc->type) 486 switch (tc->type)
478 { 487 {
479 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 488 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
480 { 489 {
481 struct TopologyContextOverlay *overlay; 490 struct TopologyContextOverlay *overlay;
482 struct OverlayLink *olink; 491 struct OverlayLink *olink;
483 492
484 overlay = &tc->u.overlay; 493 overlay = &tc->u.overlay;
485 GNUNET_assert(offset < tc->link_array_size); 494 GNUNET_assert (offset < tc->link_array_size);
486 olink = &overlay->link_array[offset]; 495 olink = &overlay->link_array[offset];
487 LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %u to %u\n", B, A); 496 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer %u to %u\n", B, A);
488 olink->A = A; 497 olink->A = A;
489 olink->B = B; 498 olink->B = B;
490 olink->op = NULL; 499 olink->op = NULL;
@@ -492,19 +501,19 @@ make_link(unsigned int offset,
492 } 501 }
493 break; 502 break;
494 503
495 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 504 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
496 { 505 {
497 struct TopologyContextUnderlay *underlay; 506 struct TopologyContextUnderlay *underlay;
498 struct UnderlayLink *ulink; 507 struct UnderlayLink *ulink;
499 508
500 underlay = &tc->u.underlay; 509 underlay = &tc->u.underlay;
501 GNUNET_assert(offset < tc->link_array_size); 510 GNUNET_assert (offset < tc->link_array_size);
502 ulink = &underlay->link_array[offset]; 511 ulink = &underlay->link_array[offset];
503 ulink->A = A; 512 ulink->A = A;
504 ulink->B = B; 513 ulink->B = B;
505 } 514 }
506 break; 515 break;
507 } 516 }
508} 517}
509 518
510 519
@@ -514,37 +523,37 @@ make_link(unsigned int offset,
514 * @param tc the topology context 523 * @param tc the topology context
515 */ 524 */
516static void 525static void
517gen_topo_line(struct TopologyContext *tc) 526gen_topo_line (struct TopologyContext *tc)
518{ 527{
519 unsigned int cnt; 528 unsigned int cnt;
520 529
521 tc->link_array_size = tc->num_peers - 1; 530 tc->link_array_size = tc->num_peers - 1;
522 switch (tc->type) 531 switch (tc->type)
523 { 532 {
524 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 533 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
525 { 534 {
526 struct TopologyContextOverlay *overlay; 535 struct TopologyContextOverlay *overlay;
527 536
528 overlay = &tc->u.overlay; 537 overlay = &tc->u.overlay;
529 overlay->link_array = 538 overlay->link_array =
530 GNUNET_new_array(tc->link_array_size, 539 GNUNET_new_array (tc->link_array_size,
531 struct OverlayLink); 540 struct OverlayLink);
532 } 541 }
533 break; 542 break;
534 543
535 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 544 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
536 { 545 {
537 struct TopologyContextUnderlay *underlay; 546 struct TopologyContextUnderlay *underlay;
538 547
539 underlay = &tc->u.underlay; 548 underlay = &tc->u.underlay;
540 underlay->link_array = 549 underlay->link_array =
541 GNUNET_new_array(tc->link_array_size, 550 GNUNET_new_array (tc->link_array_size,
542 struct UnderlayLink); 551 struct UnderlayLink);
543 } 552 }
544 break; 553 break;
545 } 554 }
546 for (cnt = 0; cnt < (tc->link_array_size); cnt++) 555 for (cnt = 0; cnt < (tc->link_array_size); cnt++)
547 make_link(cnt, cnt, cnt + 1, tc); 556 make_link (cnt, cnt, cnt + 1, tc);
548} 557}
549 558
550 559
@@ -554,40 +563,40 @@ gen_topo_line(struct TopologyContext *tc)
554 * @param tc the topology context 563 * @param tc the topology context
555 */ 564 */
556static void 565static void
557gen_topo_star(struct TopologyContext *tc) 566gen_topo_star (struct TopologyContext *tc)
558{ 567{
559 unsigned int cnt; 568 unsigned int cnt;
560 569
561 tc->link_array_size = tc->num_peers - 1; 570 tc->link_array_size = tc->num_peers - 1;
562 switch (tc->type) 571 switch (tc->type)
563 { 572 {
564 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 573 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
565 { 574 {
566 struct TopologyContextOverlay *overlay; 575 struct TopologyContextOverlay *overlay;
567 576
568 overlay = &tc->u.overlay; 577 overlay = &tc->u.overlay;
569 overlay->link_array = 578 overlay->link_array =
570 GNUNET_new_array(tc->link_array_size, 579 GNUNET_new_array (tc->link_array_size,
571 struct OverlayLink); 580 struct OverlayLink);
572 } 581 }
573 break; 582 break;
574 583
575 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 584 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
576 { 585 {
577 struct TopologyContextUnderlay *underlay; 586 struct TopologyContextUnderlay *underlay;
578 587
579 underlay = &tc->u.underlay; 588 underlay = &tc->u.underlay;
580 underlay->link_array = 589 underlay->link_array =
581 GNUNET_new_array(tc->link_array_size, 590 GNUNET_new_array (tc->link_array_size,
582 struct UnderlayLink); 591 struct UnderlayLink);
583 } 592 }
584 break; 593 break;
585 } 594 }
586 for (cnt = tc->link_array_size; cnt; cnt--) 595 for (cnt = tc->link_array_size; cnt; cnt--)
587 make_link(cnt - 1, 596 make_link (cnt - 1,
588 0, 597 0,
589 cnt, 598 cnt,
590 tc); 599 tc);
591} 600}
592 601
593 602
@@ -597,35 +606,35 @@ gen_topo_star(struct TopologyContext *tc)
597 * @param tc the topology context 606 * @param tc the topology context
598 */ 607 */
599static void 608static void
600gen_topo_ring(struct TopologyContext *tc) 609gen_topo_ring (struct TopologyContext *tc)
601{ 610{
602 gen_topo_line(tc); 611 gen_topo_line (tc);
603 tc->link_array_size++; 612 tc->link_array_size++;
604 switch (tc->type) 613 switch (tc->type)
605 { 614 {
606 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 615 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
607 { 616 {
608 struct TopologyContextOverlay *overlay; 617 struct TopologyContextOverlay *overlay;
609 618
610 overlay = &tc->u.overlay; 619 overlay = &tc->u.overlay;
611 overlay->link_array = 620 overlay->link_array =
612 GNUNET_realloc(overlay->link_array, sizeof(struct OverlayLink) * 621 GNUNET_realloc (overlay->link_array, sizeof(struct OverlayLink)
613 tc->link_array_size); 622 * tc->link_array_size);
614 } 623 }
615 break; 624 break;
616 625
617 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 626 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
618 { 627 {
619 struct TopologyContextUnderlay *underlay; 628 struct TopologyContextUnderlay *underlay;
620 629
621 underlay = &tc->u.underlay; 630 underlay = &tc->u.underlay;
622 underlay->link_array = 631 underlay->link_array =
623 GNUNET_realloc(underlay->link_array, sizeof(struct UnderlayLink) * 632 GNUNET_realloc (underlay->link_array, sizeof(struct UnderlayLink)
624 tc->link_array_size); 633 * tc->link_array_size);
625 } 634 }
626 break; 635 break;
627 } 636 }
628 make_link(tc->link_array_size - 1, tc->num_peers - 1, 0, tc); 637 make_link (tc->link_array_size - 1, tc->num_peers - 1, 0, tc);
629} 638}
630 639
631 640
@@ -642,8 +651,8 @@ gen_topo_ring(struct TopologyContext *tc)
642 * given number of peers 651 * given number of peers
643 */ 652 */
644unsigned int 653unsigned int
645GNUNET_TESTBED_2dtorus_calc_links(unsigned int num_peers, unsigned int *rows, 654GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, unsigned int *rows,
646 unsigned int **rows_len) 655 unsigned int **rows_len)
647{ 656{
648 double sq; 657 double sq;
649 unsigned int sq_floor; 658 unsigned int sq_floor;
@@ -654,11 +663,11 @@ GNUNET_TESTBED_2dtorus_calc_links(unsigned int num_peers, unsigned int *rows,
654 unsigned int _num_peers; 663 unsigned int _num_peers;
655 unsigned int cnt; 664 unsigned int cnt;
656 665
657 sq = sqrt(num_peers); 666 sq = sqrt (num_peers);
658 sq = floor(sq); 667 sq = floor (sq);
659 sq_floor = (unsigned int)sq; 668 sq_floor = (unsigned int) sq;
660 _rows = (sq_floor + 1); 669 _rows = (sq_floor + 1);
661 _rows_len = GNUNET_malloc(sizeof(unsigned int) * _rows); 670 _rows_len = GNUNET_malloc (sizeof(unsigned int) * _rows);
662 for (y = 0; y < _rows - 1; y++) 671 for (y = 0; y < _rows - 1; y++)
663 _rows_len[y] = sq_floor; 672 _rows_len[y] = sq_floor;
664 _num_peers = sq_floor * sq_floor; 673 _num_peers = sq_floor * sq_floor;
@@ -666,13 +675,13 @@ GNUNET_TESTBED_2dtorus_calc_links(unsigned int num_peers, unsigned int *rows,
666 x = 0; 675 x = 0;
667 y = 0; 676 y = 0;
668 while (_num_peers < num_peers) 677 while (_num_peers < num_peers)
669 { 678 {
670 if (x < y) 679 if (x < y)
671 _rows_len[_rows - 1] = ++x; 680 _rows_len[_rows - 1] = ++x;
672 else 681 else
673 _rows_len[y++]++; 682 _rows_len[y++]++;
674 _num_peers++; 683 _num_peers++;
675 } 684 }
676 cnt += (x < 2) ? x : 2 * x; 685 cnt += (x < 2) ? x : 2 * x;
677 cnt += (y < 2) ? y : 2 * y; 686 cnt += (y < 2) ? y : 2 * y;
678 if (0 == _rows_len[_rows - 1]) 687 if (0 == _rows_len[_rows - 1])
@@ -682,7 +691,7 @@ GNUNET_TESTBED_2dtorus_calc_links(unsigned int num_peers, unsigned int *rows,
682 if (NULL != rows_len) 691 if (NULL != rows_len)
683 *rows_len = _rows_len; 692 *rows_len = _rows_len;
684 else 693 else
685 GNUNET_free(_rows_len); 694 GNUNET_free (_rows_len);
686 return cnt; 695 return cnt;
687} 696}
688 697
@@ -693,7 +702,7 @@ GNUNET_TESTBED_2dtorus_calc_links(unsigned int num_peers, unsigned int *rows,
693 * @param tc the topology context 702 * @param tc the topology context
694 */ 703 */
695static void 704static void
696gen_topo_2dtorus(struct TopologyContext *tc) 705gen_topo_2dtorus (struct TopologyContext *tc)
697{ 706{
698 unsigned int rows; 707 unsigned int rows;
699 unsigned int *rows_len; 708 unsigned int *rows_len;
@@ -703,63 +712,63 @@ gen_topo_2dtorus(struct TopologyContext *tc)
703 unsigned int offset; 712 unsigned int offset;
704 713
705 tc->link_array_size = 714 tc->link_array_size =
706 GNUNET_TESTBED_2dtorus_calc_links(tc->num_peers, &rows, &rows_len); 715 GNUNET_TESTBED_2dtorus_calc_links (tc->num_peers, &rows, &rows_len);
707 switch (tc->type) 716 switch (tc->type)
708 { 717 {
709 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 718 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
710 { 719 {
711 struct TopologyContextOverlay *overlay; 720 struct TopologyContextOverlay *overlay;
712 721
713 overlay = &tc->u.overlay; 722 overlay = &tc->u.overlay;
714 overlay->link_array = 723 overlay->link_array =
715 GNUNET_malloc(sizeof(struct OverlayLink) * tc->link_array_size); 724 GNUNET_malloc (sizeof(struct OverlayLink) * tc->link_array_size);
716 } 725 }
717 break; 726 break;
718 727
719 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 728 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
720 { 729 {
721 struct TopologyContextUnderlay *underlay; 730 struct TopologyContextUnderlay *underlay;
722 731
723 underlay = &tc->u.underlay; 732 underlay = &tc->u.underlay;
724 underlay->link_array = 733 underlay->link_array =
725 GNUNET_malloc(sizeof(struct UnderlayLink) * tc->link_array_size); 734 GNUNET_malloc (sizeof(struct UnderlayLink) * tc->link_array_size);
726 break; 735 break;
727 } 736 }
728 } 737 }
729 cnt = 0; 738 cnt = 0;
730 offset = 0; 739 offset = 0;
731 for (y = 0; y < rows; y++) 740 for (y = 0; y < rows; y++)
741 {
742 for (x = 0; x < rows_len[y] - 1; x++)
732 { 743 {
733 for (x = 0; x < rows_len[y] - 1; x++) 744 make_link (cnt, offset + x, offset + x + 1, tc);
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);
741 cnt++; 745 cnt++;
742 offset += rows_len[y];
743 } 746 }
747 if (0 == x)
748 break;
749 make_link (cnt, offset + x, offset, tc);
750 cnt++;
751 offset += rows_len[y];
752 }
744 for (x = 0; x < rows_len[0]; x++) 753 for (x = 0; x < rows_len[0]; x++)
754 {
755 offset = 0;
756 for (y = 0; y < rows - 1; y++)
745 { 757 {
746 offset = 0; 758 if (x >= rows_len[y + 1])
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)
757 break; 759 break;
758 make_link(cnt, offset + x, x, tc); 760 GNUNET_assert (x < rows_len[y + 1]);
761 make_link (cnt, offset + x, offset + rows_len[y] + x, tc);
762 offset += rows_len[y];
759 cnt++; 763 cnt++;
760 } 764 }
761 GNUNET_assert(cnt == tc->link_array_size); 765 if (0 == offset)
762 GNUNET_free(rows_len); 766 break;
767 make_link (cnt, offset + x, x, tc);
768 cnt++;
769 }
770 GNUNET_assert (cnt == tc->link_array_size);
771 GNUNET_free (rows_len);
763} 772}
764 773
765 774
@@ -772,9 +781,9 @@ gen_topo_2dtorus(struct TopologyContext *tc)
772 * create a new link array 781 * create a new link array
773 */ 782 */
774static void 783static void
775gen_topo_random(struct TopologyContext *tc, 784gen_topo_random (struct TopologyContext *tc,
776 unsigned int links, 785 unsigned int links,
777 int append) 786 int append)
778{ 787{
779 unsigned int cnt; 788 unsigned int cnt;
780 unsigned int index; 789 unsigned int index;
@@ -784,67 +793,69 @@ gen_topo_random(struct TopologyContext *tc,
784 if (1 == tc->num_peers) 793 if (1 == tc->num_peers)
785 return; 794 return;
786 if (GNUNET_YES == append) 795 if (GNUNET_YES == append)
787 { 796 {
788 index = tc->link_array_size; 797 index = tc->link_array_size;
789 tc->link_array_size += links; 798 tc->link_array_size += links;
790 } 799 }
791 else 800 else
792 { 801 {
793 index = 0; 802 index = 0;
794 tc->link_array_size = links; 803 tc->link_array_size = links;
795 } 804 }
796 switch (tc->type) 805 switch (tc->type)
797 { 806 {
798 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 807 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
799 { 808 {
800 struct TopologyContextOverlay *overlay; 809 struct TopologyContextOverlay *overlay;
801 810
802 overlay = &tc->u.overlay; 811 overlay = &tc->u.overlay;
803 if (GNUNET_YES != append) 812 if (GNUNET_YES != append)
804 { 813 {
805 GNUNET_assert(NULL == overlay->link_array); 814 GNUNET_assert (NULL == overlay->link_array);
806 overlay->link_array = 815 overlay->link_array =
807 GNUNET_malloc(sizeof(struct OverlayLink) * tc->link_array_size); 816 GNUNET_malloc (sizeof(struct OverlayLink) * tc->link_array_size);
808 break; 817 break;
809 } 818 }
810 GNUNET_assert((0 < tc->link_array_size) && (NULL != overlay->link_array)); 819 GNUNET_assert ((0 < tc->link_array_size) && (NULL !=
820 overlay->link_array));
811 overlay->link_array = 821 overlay->link_array =
812 GNUNET_realloc(overlay->link_array, 822 GNUNET_realloc (overlay->link_array,
813 sizeof(struct OverlayLink) * tc->link_array_size); 823 sizeof(struct OverlayLink) * tc->link_array_size);
814 break; 824 break;
815 } 825 }
816 826
817 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 827 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
818 { 828 {
819 struct TopologyContextUnderlay *underlay; 829 struct TopologyContextUnderlay *underlay;
820 830
821 underlay = &tc->u.underlay; 831 underlay = &tc->u.underlay;
822 if (GNUNET_YES != append) 832 if (GNUNET_YES != append)
823 { 833 {
824 GNUNET_assert(NULL == underlay->link_array); 834 GNUNET_assert (NULL == underlay->link_array);
825 underlay->link_array = 835 underlay->link_array =
826 GNUNET_malloc(sizeof(struct UnderlayLink) * tc->link_array_size); 836 GNUNET_malloc (sizeof(struct UnderlayLink) * tc->link_array_size);
827 break; 837 break;
828 } 838 }
829 GNUNET_assert((0 < tc->link_array_size) && (NULL != underlay->link_array)); 839 GNUNET_assert ((0 < tc->link_array_size) && (NULL !=
840 underlay->link_array));
830 underlay->link_array = 841 underlay->link_array =
831 GNUNET_realloc(underlay->link_array, 842 GNUNET_realloc (underlay->link_array,
832 sizeof(struct UnderlayLink) * tc->link_array_size); 843 sizeof(struct UnderlayLink) * tc->link_array_size);
833 break; 844 break;
834 } 845 }
835 } 846 }
836 for (cnt = 0; cnt < links; cnt++) 847 for (cnt = 0; cnt < links; cnt++)
848 {
849 do
837 { 850 {
838 do 851 A_rand =
839 { 852 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers);
840 A_rand = 853 B_rand =
841 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, tc->num_peers); 854 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);
847 } 855 }
856 while (A_rand == B_rand);
857 make_link (index + cnt, A_rand, B_rand, tc);
858 }
848} 859}
849 860
850 861
@@ -859,9 +870,9 @@ gen_topo_random(struct TopologyContext *tc,
859 * network 870 * network
860 */ 871 */
861static void 872static void
862gen_topo_scale_free(struct TopologyContext *tc, 873gen_topo_scale_free (struct TopologyContext *tc,
863 uint16_t cap, 874 uint16_t cap,
864 uint8_t m) 875 uint8_t m)
865{ 876{
866 unsigned int *deg; 877 unsigned int *deg;
867 unsigned int *etab; 878 unsigned int *etab;
@@ -878,108 +889,110 @@ gen_topo_scale_free(struct TopologyContext *tc,
878 etaboff = 0; 889 etaboff = 0;
879 tc->link_array_size = tc->num_peers * m; 890 tc->link_array_size = tc->num_peers * m;
880 switch (tc->type) 891 switch (tc->type)
881 { 892 {
882 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 893 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
883 { 894 {
884 struct TopologyContextOverlay *overlay; 895 struct TopologyContextOverlay *overlay;
885 896
886 overlay = &tc->u.overlay; 897 overlay = &tc->u.overlay;
887 overlay->link_array = GNUNET_malloc_large(sizeof(struct OverlayLink) * 898 overlay->link_array = GNUNET_malloc_large (sizeof(struct OverlayLink)
888 tc->link_array_size); 899 * tc->link_array_size);
889 } 900 }
890 break; 901 break;
891 902
892 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 903 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
893 { 904 {
894 struct TopologyContextUnderlay *underlay; 905 struct TopologyContextUnderlay *underlay;
895 906
896 underlay = &tc->u.underlay; 907 underlay = &tc->u.underlay;
897 underlay->link_array = GNUNET_malloc_large(sizeof(struct UnderlayLink) * 908 underlay->link_array = GNUNET_malloc_large (sizeof(struct UnderlayLink)
898 tc->link_array_size); 909 * tc->link_array_size);
899 } 910 }
900 break; 911 break;
901 } 912 }
902 etab = GNUNET_malloc_large(sizeof(unsigned int) * 2 * tc->link_array_size); 913 etab = GNUNET_malloc_large (sizeof(unsigned int) * 2 * tc->link_array_size);
903 deg = GNUNET_malloc(sizeof(unsigned int) * tc->num_peers); 914 deg = GNUNET_malloc (sizeof(unsigned int) * tc->num_peers);
904 used = GNUNET_malloc(sizeof(unsigned int) * m); 915 used = GNUNET_malloc (sizeof(unsigned int) * m);
905 /* start by connecting peer 1 to peer 0 */ 916 /* start by connecting peer 1 to peer 0 */
906 make_link(0, 0, 1, tc); 917 make_link (0, 0, 1, tc);
907 deg[0]++; 918 deg[0]++;
908 deg[1]++; 919 deg[1]++;
909 etab[etaboff++] = 0; 920 etab[etaboff++] = 0;
910 etab[etaboff++] = 1; 921 etab[etaboff++] = 1;
911 links = 1; 922 links = 1;
912 for (peer = 2; peer < tc->num_peers; peer++) 923 for (peer = 2; peer < tc->num_peers; peer++)
924 {
925 if (cap < deg[peer])
926 continue;
927 for (cnt = 0; cnt < GNUNET_MIN (peer, m); cnt++)
913 { 928 {
914 if (cap < deg[peer]) 929 redo_threshold = 0;
915 continue; 930redo:
916 for (cnt = 0; cnt < GNUNET_MIN(peer, m); cnt++) 931 off = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, etaboff);
932 random_peer = etab[off];
933 if (cap < deg[random_peer])
934 {
935 if (++redo_threshold > GNUNET_MAX (1, cap / 2))
917 { 936 {
918 redo_threshold = 0; 937 redo_threshold = 0;
919redo: 938 off = 0;
920 off = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, etaboff); 939 for (cnt2 = 0; cnt2 < etaboff; cnt2++)
921 random_peer = etab[off]; 940 {
922 if (cap < deg[random_peer]) 941 if (random_peer == etab[cnt2])
923 { 942 {
924 if (++redo_threshold > GNUNET_MAX(1, cap / 2)) 943 off++;
925 { 944 continue;
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 } 945 }
941 for (cnt2 = 0; cnt2 < cnt; cnt2++) 946 etab[cnt2 - off] = etab[cnt2];
942 if (random_peer == used[cnt2]) 947 }
943 goto redo; 948 etaboff -= off;
944 make_link(links + cnt, random_peer, peer, tc);
945 deg[random_peer]++;
946 deg[peer]++;
947 used[cnt] = random_peer;
948 }
949 for (cnt = 0; cnt < GNUNET_MIN(peer, m); cnt++)
950 {
951 etab[etaboff++] = used[cnt];
952 etab[etaboff++] = peer;
953 } 949 }
954 links += GNUNET_MIN(peer, m); 950 goto redo;
951 }
952 for (cnt2 = 0; cnt2 < cnt; cnt2++)
953 if (random_peer == used[cnt2])
954 goto redo;
955 make_link (links + cnt, random_peer, peer, tc);
956 deg[random_peer]++;
957 deg[peer]++;
958 used[cnt] = random_peer;
955 } 959 }
956 GNUNET_free(etab); 960 for (cnt = 0; cnt < GNUNET_MIN (peer, m); cnt++)
957 GNUNET_free(used); 961 {
958 GNUNET_free(deg); 962 etab[etaboff++] = used[cnt];
959 GNUNET_assert(links <= tc->link_array_size); 963 etab[etaboff++] = peer;
964 }
965 links += GNUNET_MIN (peer, m);
966 }
967 GNUNET_free (etab);
968 GNUNET_free (used);
969 GNUNET_free (deg);
970 GNUNET_assert (links <= tc->link_array_size);
960 tc->link_array_size = links; 971 tc->link_array_size = links;
961 switch (tc->type) 972 switch (tc->type)
962 { 973 {
963 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 974 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
964 { 975 {
965 struct TopologyContextOverlay *overlay; 976 struct TopologyContextOverlay *overlay;
966 977
967 overlay = &tc->u.overlay; 978 overlay = &tc->u.overlay;
968 overlay->link_array = 979 overlay->link_array =
969 GNUNET_realloc(overlay->link_array, sizeof(struct OverlayLink) * tc->link_array_size); 980 GNUNET_realloc (overlay->link_array, sizeof(struct OverlayLink)
981 * tc->link_array_size);
970 } 982 }
971 break; 983 break;
972 984
973 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 985 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
974 { 986 {
975 struct TopologyContextUnderlay *underlay; 987 struct TopologyContextUnderlay *underlay;
976 988
977 underlay = &tc->u.underlay; 989 underlay = &tc->u.underlay;
978 underlay->link_array = 990 underlay->link_array =
979 GNUNET_realloc(underlay->link_array, sizeof(struct UnderlayLink) * tc->link_array_size); 991 GNUNET_realloc (underlay->link_array, sizeof(struct UnderlayLink)
992 * tc->link_array_size);
980 } 993 }
981 break; 994 break;
982 } 995 }
983} 996}
984 997
985 998
@@ -990,8 +1003,8 @@ redo:
990 * @param filename the filename of the file containing topology data 1003 * @param filename the filename of the file containing topology data
991 */ 1004 */
992static void 1005static void
993gen_topo_from_file(struct TopologyContext *tc, 1006gen_topo_from_file (struct TopologyContext *tc,
994 const char *filename) 1007 const char *filename)
995{ 1008{
996 char *data; 1009 char *data;
997 char *end; 1010 char *end;
@@ -1000,7 +1013,8 @@ gen_topo_from_file(struct TopologyContext *tc,
1000 uint64_t offset; 1013 uint64_t offset;
1001 unsigned long int peer_id; 1014 unsigned long int peer_id;
1002 unsigned long int other_peer_id; 1015 unsigned long int other_peer_id;
1003 enum ParseState { 1016 enum ParseState
1017 {
1004 /** 1018 /**
1005 * We read the peer index 1019 * We read the peer index
1006 */ 1020 */
@@ -1014,177 +1028,178 @@ gen_topo_from_file(struct TopologyContext *tc,
1014 int status; 1028 int status;
1015 1029
1016 status = GNUNET_SYSERR; 1030 status = GNUNET_SYSERR;
1017 if (GNUNET_YES != GNUNET_DISK_file_test(filename)) 1031 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
1018 { 1032 {
1019 LOG(GNUNET_ERROR_TYPE_ERROR, 1033 LOG (GNUNET_ERROR_TYPE_ERROR,
1020 _("Topology file %s not found\n"), 1034 _ ("Topology file %s not found\n"),
1021 filename); 1035 filename);
1022 return; 1036 return;
1023 } 1037 }
1024 if (GNUNET_OK != 1038 if (GNUNET_OK !=
1025 GNUNET_DISK_file_size(filename, &fs, GNUNET_YES, GNUNET_YES)) 1039 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
1026 { 1040 {
1027 LOG(GNUNET_ERROR_TYPE_ERROR, 1041 LOG (GNUNET_ERROR_TYPE_ERROR,
1028 _("Topology file %s has no data\n"), 1042 _ ("Topology file %s has no data\n"),
1029 filename); 1043 filename);
1030 return; 1044 return;
1031 } 1045 }
1032 data = GNUNET_malloc(fs); 1046 data = GNUNET_malloc (fs);
1033 if (fs != GNUNET_DISK_fn_read(filename, data, fs)) 1047 if (fs != GNUNET_DISK_fn_read (filename, data, fs))
1034 { 1048 {
1035 LOG(GNUNET_ERROR_TYPE_ERROR, 1049 LOG (GNUNET_ERROR_TYPE_ERROR,
1036 _("Topology file %s cannot be read\n"), 1050 _ ("Topology file %s cannot be read\n"),
1037 filename); 1051 filename);
1038 goto _exit; 1052 goto _exit;
1039 } 1053 }
1040 1054
1041 offset = 0; 1055 offset = 0;
1042 peer_id = 0; 1056 peer_id = 0;
1043 state = PEER_INDEX; 1057 state = PEER_INDEX;
1044 while (offset < fs) 1058 while (offset < fs)
1059 {
1060 if (0 != isspace ((unsigned char) data[offset]))
1045 { 1061 {
1046 if (0 != isspace((unsigned char)data[offset])) 1062 offset++;
1047 { 1063 continue;
1048 offset++; 1064 }
1049 continue; 1065 switch (state)
1050 } 1066 {
1051 switch (state) 1067 case PEER_INDEX:
1068 buf = strchr (&data[offset], ':');
1069 if (NULL == buf)
1070 {
1071 LOG (GNUNET_ERROR_TYPE_ERROR,
1072 _ ("Failed to read peer index from toology file: %s"), filename);
1073 goto _exit;
1074 }
1075 *buf = '\0';
1076 errno = 0;
1077 peer_id = (unsigned int) strtoul (&data[offset], &end, 10);
1078 if (0 != errno)
1079 {
1080 LOG (GNUNET_ERROR_TYPE_ERROR,
1081 _ ("Value in given topology file: %s out of range\n"), filename);
1082 goto _exit;
1083 }
1084 if (&data[offset] == end)
1085 {
1086 LOG (GNUNET_ERROR_TYPE_ERROR,
1087 _ ("Failed to read peer index from topology file: %s"), filename);
1088 goto _exit;
1089 }
1090 if (tc->num_peers <= peer_id)
1091 {
1092 LOG (GNUNET_ERROR_TYPE_ERROR,
1093 _ ("Topology file needs more peers than given ones\n"), filename);
1094 goto _exit;
1095 }
1096 state = OTHER_PEER_INDEX;
1097 offset += ((unsigned int) (buf - &data[offset])) + 1;
1098 break;
1099
1100 case OTHER_PEER_INDEX:
1101 errno = 0;
1102 other_peer_id = (unsigned int) strtoul (&data[offset], &end, 10);
1103 if (0 != errno)
1104 {
1105 LOG (GNUNET_ERROR_TYPE_ERROR,
1106 _ ("Value in given topology file: %s out of range\n"), filename);
1107 goto _exit;
1108 }
1109 if (&data[offset] == end)
1110 {
1111 LOG (GNUNET_ERROR_TYPE_ERROR,
1112 _ ("Failed to read peer index from topology file: %s"), filename);
1113 goto _exit;
1114 }
1115 if (tc->num_peers <= other_peer_id)
1116 {
1117 LOG (GNUNET_ERROR_TYPE_ERROR,
1118 _ ("Topology file needs more peers than given ones\n"), filename);
1119 goto _exit;
1120 }
1121 if (peer_id != other_peer_id)
1122 {
1123 tc->link_array_size++;
1124 switch (tc->type)
1052 { 1125 {
1053 case PEER_INDEX: 1126 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1054 buf = strchr(&data[offset], ':'); 1127 {
1055 if (NULL == buf) 1128 struct TopologyContextOverlay *overlay;
1056 { 1129
1057 LOG(GNUNET_ERROR_TYPE_ERROR, 1130 overlay = &tc->u.overlay;
1058 _("Failed to read peer index from toology file: %s"), filename); 1131 overlay->link_array =
1059 goto _exit; 1132 GNUNET_realloc (overlay->link_array,
1060 } 1133 sizeof(struct OverlayLink) * tc->link_array_size);
1061 *buf = '\0'; 1134 }
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;
1084 break; 1135 break;
1085 1136
1086 case OTHER_PEER_INDEX: 1137 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1087 errno = 0; 1138 {
1088 other_peer_id = (unsigned int)strtoul(&data[offset], &end, 10); 1139 struct TopologyContextUnderlay *underlay;
1089 if (0 != errno) 1140
1090 { 1141 underlay = &tc->u.underlay;
1091 LOG(GNUNET_ERROR_TYPE_ERROR, 1142 underlay->link_array =
1092 _("Value in given topology file: %s out of range\n"), filename); 1143 GNUNET_realloc (underlay->link_array,
1093 goto _exit; 1144 sizeof(struct UnderlayLink)
1094 } 1145 * tc->link_array_size);
1095 if (&data[offset] == end) 1146 }
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 }
1153 break; 1147 break;
1154 } 1148 }
1149 offset += end - &data[offset];
1150 make_link (tc->link_array_size - 1, peer_id, other_peer_id, tc);
1151 }
1152 else
1153 LOG (GNUNET_ERROR_TYPE_WARNING,
1154 _ ("Ignoring to connect peer %u to peer %u\n"),
1155 peer_id,
1156 other_peer_id);
1157 while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs))
1158 offset++;
1159 if ((offset < fs) &&
1160 ('\n' == data[offset]))
1161 state = PEER_INDEX;
1162 else if ((offset < fs) &&
1163 ('|' == data[offset]))
1164 {
1165 state = OTHER_PEER_INDEX;
1166 offset++;
1167 }
1168 break;
1155 } 1169 }
1170 }
1156 status = GNUNET_OK; 1171 status = GNUNET_OK;
1157 1172
1158_exit: 1173_exit:
1159 GNUNET_free(data); 1174 GNUNET_free (data);
1160 if (GNUNET_OK != status) 1175 if (GNUNET_OK != status)
1176 {
1177 LOG (GNUNET_ERROR_TYPE_WARNING,
1178 "Removing link data read from the file\n");
1179 tc->link_array_size = 0;
1180 switch (tc->type)
1161 { 1181 {
1162 LOG(GNUNET_ERROR_TYPE_WARNING, 1182 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1163 "Removing link data read from the file\n"); 1183 {
1164 tc->link_array_size = 0; 1184 struct TopologyContextOverlay *overlay;
1165 switch (tc->type)
1166 {
1167 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1168 {
1169 struct TopologyContextOverlay *overlay;
1170 1185
1171 overlay = &tc->u.overlay; 1186 overlay = &tc->u.overlay;
1172 GNUNET_free_non_null(overlay->link_array); 1187 GNUNET_free_non_null (overlay->link_array);
1173 overlay->link_array = NULL; 1188 overlay->link_array = NULL;
1174 } 1189 }
1175 break; 1190 break;
1176 1191
1177 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 1192 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1178 { 1193 {
1179 struct TopologyContextUnderlay *underlay; 1194 struct TopologyContextUnderlay *underlay;
1180 1195
1181 underlay = &tc->u.underlay; 1196 underlay = &tc->u.underlay;
1182 GNUNET_free_non_null(underlay->link_array); 1197 GNUNET_free_non_null (underlay->link_array);
1183 underlay->link_array = NULL; 1198 underlay->link_array = NULL;
1184 } 1199 }
1185 break; 1200 break;
1186 }
1187 } 1201 }
1202 }
1188} 1203}
1189 1204
1190 1205
@@ -1194,7 +1209,7 @@ _exit:
1194 * @param tc the topology context 1209 * @param tc the topology context
1195 */ 1210 */
1196static void 1211static void
1197gen_topo_clique(struct TopologyContext *tc) 1212gen_topo_clique (struct TopologyContext *tc)
1198{ 1213{
1199 unsigned int cnt; 1214 unsigned int cnt;
1200 unsigned int offset; 1215 unsigned int offset;
@@ -1202,37 +1217,37 @@ gen_topo_clique(struct TopologyContext *tc)
1202 1217
1203 tc->link_array_size = tc->num_peers * (tc->num_peers - 1); 1218 tc->link_array_size = tc->num_peers * (tc->num_peers - 1);
1204 switch (tc->type) 1219 switch (tc->type)
1205 { 1220 {
1206 case TOPOLOGYCONTEXT_TYPE_OVERLAY: 1221 case TOPOLOGYCONTEXT_TYPE_OVERLAY:
1207 { 1222 {
1208 struct TopologyContextOverlay *overlay; 1223 struct TopologyContextOverlay *overlay;
1209 1224
1210 overlay = &tc->u.overlay; 1225 overlay = &tc->u.overlay;
1211 overlay->link_array = GNUNET_new_array(tc->link_array_size, 1226 overlay->link_array = GNUNET_new_array (tc->link_array_size,
1212 struct OverlayLink); 1227 struct OverlayLink);
1213 } 1228 }
1214 break; 1229 break;
1215 1230
1216 case TOPOLOGYCONTEXT_TYPE_UNDERLAY: 1231 case TOPOLOGYCONTEXT_TYPE_UNDERLAY:
1217 { 1232 {
1218 struct TopologyContextUnderlay *underlay; 1233 struct TopologyContextUnderlay *underlay;
1219 1234
1220 underlay = &tc->u.underlay; 1235 underlay = &tc->u.underlay;
1221 underlay->link_array = GNUNET_new_array(tc->link_array_size, 1236 underlay->link_array = GNUNET_new_array (tc->link_array_size,
1222 struct UnderlayLink); 1237 struct UnderlayLink);
1223 }
1224 } 1238 }
1239 }
1225 offset = 0; 1240 offset = 0;
1226 for (cnt = 0; cnt < tc->num_peers; cnt++) 1241 for (cnt = 0; cnt < tc->num_peers; cnt++)
1242 {
1243 for (neighbour = 0; neighbour < tc->num_peers; neighbour++)
1227 { 1244 {
1228 for (neighbour = 0; neighbour < tc->num_peers; neighbour++) 1245 if (neighbour == cnt)
1229 { 1246 continue;
1230 if (neighbour == cnt) 1247 make_link (offset, cnt, neighbour, tc);
1231 continue; 1248 offset++;
1232 make_link(offset, cnt, neighbour, tc);
1233 offset++;
1234 }
1235 } 1249 }
1250 }
1236} 1251}
1237 1252
1238 1253
@@ -1248,15 +1263,15 @@ gen_topo_clique(struct TopologyContext *tc)
1248 * is not allowed at this time 1263 * is not allowed at this time
1249 */ 1264 */
1250struct GNUNET_TESTBED_Operation * 1265struct GNUNET_TESTBED_Operation *
1251GNUNET_TESTBED_underlay_configure_topology_va(void *op_cls, 1266GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
1252 unsigned int num_peers, 1267 unsigned int num_peers,
1253 struct GNUNET_TESTBED_Peer 1268 struct GNUNET_TESTBED_Peer
1254 **peers, 1269 **peers,
1255 enum 1270 enum
1256 GNUNET_TESTBED_TopologyOption 1271 GNUNET_TESTBED_TopologyOption
1257 topo, va_list ap) 1272 topo, va_list ap)
1258{ 1273{
1259 GNUNET_break(0); 1274 GNUNET_break (0);
1260 return NULL; 1275 return NULL;
1261} 1276}
1262 1277
@@ -1273,13 +1288,13 @@ GNUNET_TESTBED_underlay_configure_topology_va(void *op_cls,
1273 * is not allowed at this time 1288 * is not allowed at this time
1274 */ 1289 */
1275struct GNUNET_TESTBED_Operation * 1290struct GNUNET_TESTBED_Operation *
1276GNUNET_TESTBED_underlay_configure_topology(void *op_cls, 1291GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
1277 unsigned int num_peers, 1292 unsigned int num_peers,
1278 struct GNUNET_TESTBED_Peer **peers, 1293 struct GNUNET_TESTBED_Peer **peers,
1279 enum GNUNET_TESTBED_TopologyOption 1294 enum GNUNET_TESTBED_TopologyOption
1280 topo, ...) 1295 topo, ...)
1281{ 1296{
1282 GNUNET_break(0); 1297 GNUNET_break (0);
1283 return NULL; 1298 return NULL;
1284} 1299}
1285 1300
@@ -1305,15 +1320,16 @@ GNUNET_TESTBED_underlay_configure_topology(void *op_cls,
1305 * not running or underlay disallows) or if num_peers is less than 2 1320 * not running or underlay disallows) or if num_peers is less than 2
1306 */ 1321 */
1307struct GNUNET_TESTBED_Operation * 1322struct GNUNET_TESTBED_Operation *
1308GNUNET_TESTBED_overlay_configure_topology_va(void *op_cls, 1323GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
1309 unsigned int num_peers, 1324 unsigned int num_peers,
1310 struct GNUNET_TESTBED_Peer **peers, 1325 struct GNUNET_TESTBED_Peer **peers,
1311 unsigned int *max_connections, 1326 unsigned int *max_connections,
1312 GNUNET_TESTBED_TopologyCompletionCallback 1327 GNUNET_TESTBED_TopologyCompletionCallback
1313 comp_cb, 1328 comp_cb,
1314 void *comp_cb_cls, 1329 void *comp_cb_cls,
1315 enum GNUNET_TESTBED_TopologyOption topo, 1330 enum GNUNET_TESTBED_TopologyOption
1316 va_list va) 1331 topo,
1332 va_list va)
1317{ 1333{
1318 struct TopologyContext *tc; 1334 struct TopologyContext *tc;
1319 struct TopologyContextOverlay *overlay; 1335 struct TopologyContextOverlay *overlay;
@@ -1324,7 +1340,7 @@ GNUNET_TESTBED_overlay_configure_topology_va(void *op_cls,
1324 if (num_peers < 2) 1340 if (num_peers < 2)
1325 return NULL; 1341 return NULL;
1326 c = peers[0]->controller; 1342 c = peers[0]->controller;
1327 tc = GNUNET_new(struct TopologyContext); 1343 tc = GNUNET_new (struct TopologyContext);
1328 tc->type = TOPOLOGYCONTEXT_TYPE_OVERLAY; 1344 tc->type = TOPOLOGYCONTEXT_TYPE_OVERLAY;
1329 overlay = &tc->u.overlay; 1345 overlay = &tc->u.overlay;
1330 overlay->peers = peers; 1346 overlay->peers = peers;
@@ -1334,100 +1350,100 @@ GNUNET_TESTBED_overlay_configure_topology_va(void *op_cls,
1334 overlay->comp_cb = comp_cb; 1350 overlay->comp_cb = comp_cb;
1335 overlay->comp_cb_cls = comp_cb_cls; 1351 overlay->comp_cb_cls = comp_cb_cls;
1336 switch (topo) 1352 switch (topo)
1337 { 1353 {
1338 case GNUNET_TESTBED_TOPOLOGY_LINE: 1354 case GNUNET_TESTBED_TOPOLOGY_LINE:
1339 gen_topo_line(tc); 1355 gen_topo_line (tc);
1340 break; 1356 break;
1341 1357
1342 case GNUNET_TESTBED_TOPOLOGY_STAR: 1358 case GNUNET_TESTBED_TOPOLOGY_STAR:
1343 gen_topo_star(tc); 1359 gen_topo_star (tc);
1344 break; 1360 break;
1345 1361
1346 case GNUNET_TESTBED_TOPOLOGY_RING: 1362 case GNUNET_TESTBED_TOPOLOGY_RING:
1347 gen_topo_ring(tc); 1363 gen_topo_ring (tc);
1348 break; 1364 break;
1349 1365
1350 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: 1366 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
1351 gen_topo_random(tc, va_arg(va, unsigned int), GNUNET_NO); 1367 gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_NO);
1352 break; 1368 break;
1353 1369
1354 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: 1370 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
1355 gen_topo_ring(tc); 1371 gen_topo_ring (tc);
1356 gen_topo_random(tc, va_arg(va, unsigned int), GNUNET_YES); 1372 gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_YES);
1357 break; 1373 break;
1358 1374
1359 case GNUNET_TESTBED_TOPOLOGY_CLIQUE: 1375 case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
1360 gen_topo_clique(tc); 1376 gen_topo_clique (tc);
1361 break; 1377 break;
1362 1378
1363 case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: 1379 case GNUNET_TESTBED_TOPOLOGY_2D_TORUS:
1364 gen_topo_2dtorus(tc); 1380 gen_topo_2dtorus (tc);
1365 break; 1381 break;
1366 1382
1367 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: 1383 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
1368 gen_topo_2dtorus(tc); 1384 gen_topo_2dtorus (tc);
1369 gen_topo_random(tc, va_arg(va, unsigned int), GNUNET_YES); 1385 gen_topo_random (tc, va_arg (va, unsigned int), GNUNET_YES);
1370 1386
1371 break; 1387 break;
1372 1388
1373 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: 1389 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
1374 { 1390 {
1375 uint16_t cap; 1391 uint16_t cap;
1376 uint8_t m; 1392 uint8_t m;
1377 1393
1378 cap = (uint16_t)va_arg(va, unsigned int); 1394 cap = (uint16_t) va_arg (va, unsigned int);
1379 m = (uint8_t)va_arg(va, unsigned int); 1395 m = (uint8_t) va_arg (va, unsigned int);
1380 gen_topo_scale_free(tc, cap, m); 1396 gen_topo_scale_free (tc, cap, m);
1381 } 1397 }
1382 break; 1398 break;
1383 1399
1384 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: 1400 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
1385 { 1401 {
1386 const char *filename; 1402 const char *filename;
1387 1403
1388 filename = va_arg(va, const char *); 1404 filename = va_arg (va, const char *);
1389 1405
1390 GNUNET_assert(NULL != filename); 1406 GNUNET_assert (NULL != filename);
1391 gen_topo_from_file(tc, filename); 1407 gen_topo_from_file (tc, filename);
1392 } 1408 }
1393 break; 1409 break;
1394 1410
1395 default: 1411 default:
1396 GNUNET_break(0); 1412 GNUNET_break (0);
1397 GNUNET_free(tc); 1413 GNUNET_free (tc);
1398 return NULL; 1414 return NULL;
1399 } 1415 }
1400 do 1416 do
1401 { 1417 {
1402 secondary_option = GNUNET_VA_ARG_ENUM(va, GNUNET_TESTBED_TopologyOption); 1418 secondary_option = GNUNET_VA_ARG_ENUM (va, GNUNET_TESTBED_TopologyOption);
1403 1419
1404 switch (secondary_option) 1420 switch (secondary_option)
1405 { 1421 {
1406 case GNUNET_TESTBED_TOPOLOGY_RETRY_CNT: 1422 case GNUNET_TESTBED_TOPOLOGY_RETRY_CNT:
1407 overlay->retry_cnt = va_arg(va, unsigned int); 1423 overlay->retry_cnt = va_arg (va, unsigned int);
1408 break; 1424 break;
1409 1425
1410 case GNUNET_TESTBED_TOPOLOGY_OPTION_END: 1426 case GNUNET_TESTBED_TOPOLOGY_OPTION_END:
1411 break; 1427 break;
1412 1428
1413 default: 1429 default:
1414 GNUNET_break(0); /* Should not use any other option apart from 1430 GNUNET_break (0); /* Should not use any other option apart from
1415 * the ones handled here */ 1431 * the ones handled here */
1416 GNUNET_free_non_null(overlay->link_array); 1432 GNUNET_free_non_null (overlay->link_array);
1417 GNUNET_free(tc); 1433 GNUNET_free (tc);
1418 return NULL; 1434 return NULL;
1419 }
1420 } 1435 }
1436 }
1421 while (GNUNET_TESTBED_TOPOLOGY_OPTION_END != secondary_option); 1437 while (GNUNET_TESTBED_TOPOLOGY_OPTION_END != secondary_option);
1422 op = GNUNET_TESTBED_operation_create_(tc, 1438 op = GNUNET_TESTBED_operation_create_ (tc,
1423 &opstart_overlay_configure_topology, 1439 &opstart_overlay_configure_topology,
1424 &oprelease_overlay_configure_topology); 1440 &oprelease_overlay_configure_topology);
1425 GNUNET_TESTBED_operation_queue_insert_ 1441 GNUNET_TESTBED_operation_queue_insert_
1426 (c->opq_parallel_topology_config_operations, op); 1442 (c->opq_parallel_topology_config_operations, op);
1427 GNUNET_TESTBED_operation_begin_wait_(op); 1443 GNUNET_TESTBED_operation_begin_wait_ (op);
1428 LOG(GNUNET_ERROR_TYPE_DEBUG, 1444 LOG (GNUNET_ERROR_TYPE_DEBUG,
1429 "Generated %u connections\n", 1445 "Generated %u connections\n",
1430 tc->link_array_size); 1446 tc->link_array_size);
1431 if (NULL != max_connections) 1447 if (NULL != max_connections)
1432 *max_connections = tc->link_array_size; 1448 *max_connections = tc->link_array_size;
1433 return op; 1449 return op;
@@ -1455,27 +1471,28 @@ GNUNET_TESTBED_overlay_configure_topology_va(void *op_cls,
1455 * not running or underlay disallows) or if num_peers is less than 2 1471 * not running or underlay disallows) or if num_peers is less than 2
1456 */ 1472 */
1457struct GNUNET_TESTBED_Operation * 1473struct GNUNET_TESTBED_Operation *
1458GNUNET_TESTBED_overlay_configure_topology(void *op_cls, 1474GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
1459 unsigned int num_peers, 1475 unsigned int num_peers,
1460 struct GNUNET_TESTBED_Peer **peers, 1476 struct GNUNET_TESTBED_Peer **peers,
1461 unsigned int *max_connections, 1477 unsigned int *max_connections,
1462 GNUNET_TESTBED_TopologyCompletionCallback 1478 GNUNET_TESTBED_TopologyCompletionCallback
1463 comp_cb, 1479 comp_cb,
1464 void *comp_cb_cls, 1480 void *comp_cb_cls,
1465 enum GNUNET_TESTBED_TopologyOption topo, 1481 enum GNUNET_TESTBED_TopologyOption
1466 ...) 1482 topo,
1483 ...)
1467{ 1484{
1468 struct GNUNET_TESTBED_Operation *op; 1485 struct GNUNET_TESTBED_Operation *op;
1469 va_list vargs; 1486 va_list vargs;
1470 1487
1471 GNUNET_assert(topo < GNUNET_TESTBED_TOPOLOGY_OPTION_END); 1488 GNUNET_assert (topo < GNUNET_TESTBED_TOPOLOGY_OPTION_END);
1472 va_start(vargs, topo); 1489 va_start (vargs, topo);
1473 op = GNUNET_TESTBED_overlay_configure_topology_va(op_cls, num_peers, peers, 1490 op = GNUNET_TESTBED_overlay_configure_topology_va (op_cls, num_peers, peers,
1474 max_connections, 1491 max_connections,
1475 comp_cb, comp_cb_cls, 1492 comp_cb, comp_cb_cls,
1476 topo, 1493 topo,
1477 vargs); 1494 vargs);
1478 va_end(vargs); 1495 va_end (vargs);
1479 return op; 1496 return op;
1480} 1497}
1481 1498
@@ -1490,21 +1507,22 @@ GNUNET_TESTBED_overlay_configure_topology(void *op_cls,
1490 * known topology, #GNUNET_NO if not 1507 * known topology, #GNUNET_NO if not
1491 */ 1508 */
1492int 1509int
1493GNUNET_TESTBED_topology_get_(enum GNUNET_TESTBED_TopologyOption *topology, 1510GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology,
1494 const char *topology_string) 1511 const char *topology_string)
1495{ 1512{
1496 unsigned int cnt; 1513 unsigned int cnt;
1497 1514
1498 for (cnt = 0; NULL != topology_strings[cnt]; cnt++) 1515 for (cnt = 0; NULL != topology_strings[cnt]; cnt++)
1516 {
1517 if (0 == strcasecmp (topology_string, topology_strings[cnt]))
1499 { 1518 {
1500 if (0 == strcasecmp(topology_string, topology_strings[cnt])) 1519 if (NULL != topology)
1501 { 1520 *topology = (enum GNUNET_TESTBED_TopologyOption) cnt;
1502 if (NULL != topology) 1521 GNUNET_assert (GNUNET_TESTBED_TOPOLOGY_OPTION_END !=
1503 *topology = (enum GNUNET_TESTBED_TopologyOption)cnt; 1522 (enum GNUNET_TESTBED_TopologyOption) cnt);
1504 GNUNET_assert(GNUNET_TESTBED_TOPOLOGY_OPTION_END != (enum GNUNET_TESTBED_TopologyOption)cnt); 1523 return GNUNET_YES;
1505 return GNUNET_YES;
1506 }
1507 } 1524 }
1525 }
1508 return GNUNET_NO; 1526 return GNUNET_NO;
1509} 1527}
1510 1528
@@ -1517,11 +1535,11 @@ GNUNET_TESTBED_topology_get_(enum GNUNET_TESTBED_TopologyOption *topology,
1517 * expressed as a string 1535 * expressed as a string
1518 */ 1536 */
1519char * 1537char *
1520GNUNET_TESTBED_topology_to_str_(enum GNUNET_TESTBED_TopologyOption topology) 1538GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology)
1521{ 1539{
1522 if (GNUNET_TESTBED_TOPOLOGY_OPTION_END <= topology) 1540 if (GNUNET_TESTBED_TOPOLOGY_OPTION_END <= topology)
1523 return NULL; 1541 return NULL;
1524 return GNUNET_strdup(topology_strings[topology]); 1542 return GNUNET_strdup (topology_strings[topology]);
1525} 1543}
1526 1544
1527 1545
@@ -1542,10 +1560,10 @@ GNUNET_TESTBED_topology_to_str_(enum GNUNET_TESTBED_TopologyOption topology)
1542 * underlay link processor returned #GNUNET_SYSERR 1560 * underlay link processor returned #GNUNET_SYSERR
1543 */ 1561 */
1544int 1562int
1545GNUNET_TESTBED_underlay_construct_(int num_peers, 1563GNUNET_TESTBED_underlay_construct_ (int num_peers,
1546 underlay_link_processor proc, 1564 underlay_link_processor proc,
1547 void *cls, 1565 void *cls,
1548 ...) 1566 ...)
1549{ 1567{
1550 struct TopologyContext tc; 1568 struct TopologyContext tc;
1551 struct TopologyContextUnderlay *underlay; 1569 struct TopologyContextUnderlay *underlay;
@@ -1555,88 +1573,88 @@ GNUNET_TESTBED_underlay_construct_(int num_peers,
1555 unsigned int cnt; 1573 unsigned int cnt;
1556 int ret; 1574 int ret;
1557 1575
1558 GNUNET_assert(NULL != proc); 1576 GNUNET_assert (NULL != proc);
1559 ret = GNUNET_OK; 1577 ret = GNUNET_OK;
1560 memset(&tc, 0, sizeof(tc)); 1578 memset (&tc, 0, sizeof(tc));
1561 tc.num_peers = num_peers; 1579 tc.num_peers = num_peers;
1562 tc.type = TOPOLOGYCONTEXT_TYPE_UNDERLAY; 1580 tc.type = TOPOLOGYCONTEXT_TYPE_UNDERLAY;
1563 underlay = &tc.u.underlay; 1581 underlay = &tc.u.underlay;
1564 va_start(vargs, cls); 1582 va_start (vargs, cls);
1565 topology = GNUNET_VA_ARG_ENUM(vargs, GNUNET_TESTBED_TopologyOption); 1583 topology = GNUNET_VA_ARG_ENUM (vargs, GNUNET_TESTBED_TopologyOption);
1566 switch (topology) 1584 switch (topology)
1567 { 1585 {
1568 case GNUNET_TESTBED_TOPOLOGY_LINE: 1586 case GNUNET_TESTBED_TOPOLOGY_LINE:
1569 gen_topo_line(&tc); 1587 gen_topo_line (&tc);
1570 break; 1588 break;
1571 1589
1572 case GNUNET_TESTBED_TOPOLOGY_STAR: 1590 case GNUNET_TESTBED_TOPOLOGY_STAR:
1573 gen_topo_star(&tc); 1591 gen_topo_star (&tc);
1574 break; 1592 break;
1575 1593
1576 case GNUNET_TESTBED_TOPOLOGY_RING: 1594 case GNUNET_TESTBED_TOPOLOGY_RING:
1577 gen_topo_ring(&tc); 1595 gen_topo_ring (&tc);
1578 break; 1596 break;
1579 1597
1580 case GNUNET_TESTBED_TOPOLOGY_CLIQUE: 1598 case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
1581 gen_topo_clique(&tc); 1599 gen_topo_clique (&tc);
1582 break; 1600 break;
1583 1601
1584 case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: 1602 case GNUNET_TESTBED_TOPOLOGY_2D_TORUS:
1585 gen_topo_2dtorus(&tc); 1603 gen_topo_2dtorus (&tc);
1586 break; 1604 break;
1587 1605
1588 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: 1606 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
1589 gen_topo_random(&tc, va_arg(vargs, unsigned int), GNUNET_NO); 1607 gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_NO);
1590 break; 1608 break;
1591 1609
1592 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: 1610 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
1593 gen_topo_ring(&tc); 1611 gen_topo_ring (&tc);
1594 gen_topo_random(&tc, va_arg(vargs, unsigned int), GNUNET_YES); 1612 gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES);
1595 break; 1613 break;
1596 1614
1597 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: 1615 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
1598 gen_topo_2dtorus(&tc); 1616 gen_topo_2dtorus (&tc);
1599 gen_topo_random(&tc, va_arg(vargs, unsigned int), GNUNET_YES); 1617 gen_topo_random (&tc, va_arg (vargs, unsigned int), GNUNET_YES);
1600 break; 1618 break;
1601 1619
1602 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: 1620 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
1603 { 1621 {
1604 const char *filename; 1622 const char *filename;
1605 filename = va_arg(vargs, char *); 1623 filename = va_arg (vargs, char *);
1606 GNUNET_assert(NULL != filename); 1624 GNUNET_assert (NULL != filename);
1607 gen_topo_from_file(&tc, filename); 1625 gen_topo_from_file (&tc, filename);
1608 } 1626 }
1609 break; 1627 break;
1610 1628
1611 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: 1629 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
1612 { 1630 {
1613 uint16_t cap; 1631 uint16_t cap;
1614 uint8_t m; 1632 uint8_t m;
1615 cap = (uint16_t)va_arg(vargs, unsigned int); 1633 cap = (uint16_t) va_arg (vargs, unsigned int);
1616 m = (uint8_t)va_arg(vargs, unsigned int); 1634 m = (uint8_t) va_arg (vargs, unsigned int);
1617 gen_topo_scale_free(&tc, cap, m); 1635 gen_topo_scale_free (&tc, cap, m);
1618 } 1636 }
1619 break; 1637 break;
1620 1638
1621 default: 1639 default:
1622 GNUNET_assert(0); 1640 GNUNET_assert (0);
1623 } 1641 }
1624 va_end(vargs); 1642 va_end (vargs);
1625 for (cnt = 0; cnt < tc.link_array_size; cnt++) 1643 for (cnt = 0; cnt < tc.link_array_size; cnt++)
1644 {
1645 ulink = &underlay->link_array[cnt];
1646 if (GNUNET_SYSERR == proc (cls,
1647 ulink->A,
1648 ulink->B,
1649 ulink->bandwidth,
1650 ulink->latency,
1651 ulink->loss))
1626 { 1652 {
1627 ulink = &underlay->link_array[cnt]; 1653 ret = GNUNET_SYSERR;
1628 if (GNUNET_SYSERR == proc(cls, 1654 break;
1629 ulink->A,
1630 ulink->B,
1631 ulink->bandwidth,
1632 ulink->latency,
1633 ulink->loss))
1634 {
1635 ret = GNUNET_SYSERR;
1636 break;
1637 }
1638 } 1655 }
1639 GNUNET_free_non_null(underlay->link_array); 1656 }
1657 GNUNET_free_non_null (underlay->link_array);
1640 return ret; 1658 return ret;
1641} 1659}
1642 1660
diff --git a/src/testbed/testbed_api_topology.h b/src/testbed/testbed_api_topology.h
index c2b00e094..c303c1412 100644
--- a/src/testbed/testbed_api_topology.h
+++ b/src/testbed/testbed_api_topology.h
@@ -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 */
40unsigned int 40unsigned int
41GNUNET_TESTBED_2dtorus_calc_links(unsigned int num_peers, unsigned int *rows, 41GNUNET_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 */
54int 54int
55GNUNET_TESTBED_topology_get_(enum GNUNET_TESTBED_TopologyOption *topology, 55GNUNET_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 */
66char * 66char *
67GNUNET_TESTBED_topology_to_str_(enum GNUNET_TESTBED_TopologyOption topology); 67GNUNET_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 */
106int 106int
107GNUNET_TESTBED_underlay_construct_(int num_peers, 107GNUNET_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 b0c712ca6..7e509fdfe 100644
--- a/src/testbed/testbed_api_underlay.c
+++ b/src/testbed/testbed_api_underlay.c
@@ -30,7 +30,8 @@
30/** 30/**
31 * An underlay link 31 * An underlay link
32 */ 32 */
33struct LinkProperty { 33struct LinkProperty
34{
34 /** 35 /**
35 * next pointer for list 36 * next pointer for list
36 */ 37 */
@@ -61,7 +62,8 @@ struct LinkProperty {
61/** 62/**
62 * Container for holding a peer in whitelist/blacklist 63 * Container for holding a peer in whitelist/blacklist
63 */ 64 */
64struct ListEntry { 65struct ListEntry
66{
65 /** 67 /**
66 * the next pointer 68 * the next pointer
67 */ 69 */
@@ -78,7 +80,8 @@ struct ListEntry {
78 * Model for configuring underlay links of a peer 80 * Model for configuring underlay links of a peer
79 * @ingroup underlay 81 * @ingroup underlay
80 */ 82 */
81struct GNUNET_TESTBED_UnderlayLinkModel { 83struct GNUNET_TESTBED_UnderlayLinkModel
84{
82 /** 85 /**
83 * The peer associated with this model 86 * The peer associated with this model
84 */ 87 */
@@ -107,15 +110,15 @@ struct GNUNET_TESTBED_UnderlayLinkModel {
107 * @param model the model 110 * @param model the model
108 */ 111 */
109static void 112static void
110free_entries(struct GNUNET_TESTBED_UnderlayLinkModel *model) 113free_entries (struct GNUNET_TESTBED_UnderlayLinkModel *model)
111{ 114{
112 struct ListEntry *e; 115 struct ListEntry *e;
113 116
114 while (NULL != (e = model->entries)) 117 while (NULL != (e = model->entries))
115 { 118 {
116 model->entries = e->next; 119 model->entries = e->next;
117 GNUNET_free(e); 120 GNUNET_free (e);
118 } 121 }
119} 122}
120 123
121 124
@@ -125,15 +128,15 @@ free_entries(struct GNUNET_TESTBED_UnderlayLinkModel *model)
125 * @param model the model 128 * @param model the model
126 */ 129 */
127static void 130static void
128free_link_properties(struct GNUNET_TESTBED_UnderlayLinkModel *model) 131free_link_properties (struct GNUNET_TESTBED_UnderlayLinkModel *model)
129{ 132{
130 struct LinkProperty *p; 133 struct LinkProperty *p;
131 134
132 while (NULL != (p = model->props)) 135 while (NULL != (p = model->props))
133 { 136 {
134 model->props = p->next; 137 model->props = p->next;
135 GNUNET_free(p); 138 GNUNET_free (p);
136 } 139 }
137} 140}
138 141
139 142
@@ -147,13 +150,15 @@ free_link_properties(struct GNUNET_TESTBED_UnderlayLinkModel *model)
147 * @return the model 150 * @return the model
148 */ 151 */
149struct GNUNET_TESTBED_UnderlayLinkModel * 152struct GNUNET_TESTBED_UnderlayLinkModel *
150GNUNET_TESTBED_underlaylinkmodel_create(struct GNUNET_TESTBED_Peer *peer, 153GNUNET_TESTBED_underlaylinkmodel_create (struct GNUNET_TESTBED_Peer *peer,
151 enum GNUNET_TESTBED_UnderlayLinkModelType type) 154 enum
155 GNUNET_TESTBED_UnderlayLinkModelType
156 type)
152{ 157{
153 struct GNUNET_TESTBED_UnderlayLinkModel *m; 158 struct GNUNET_TESTBED_UnderlayLinkModel *m;
154 159
155 GNUNET_assert(0 == peer->underlay_model_exists); 160 GNUNET_assert (0 == peer->underlay_model_exists);
156 m = GNUNET_new(struct GNUNET_TESTBED_UnderlayLinkModel); 161 m = GNUNET_new (struct GNUNET_TESTBED_UnderlayLinkModel);
157 peer->underlay_model_exists = 1; 162 peer->underlay_model_exists = 1;
158 m->type = type; 163 m->type = type;
159 return m; 164 return m;
@@ -170,12 +175,14 @@ GNUNET_TESTBED_underlaylinkmodel_create(struct GNUNET_TESTBED_Peer *peer,
170 * @param peer the peer to add 175 * @param peer the peer to add
171 */ 176 */
172void 177void
173GNUNET_TESTBED_underlaylinkmodel_add_peer(struct GNUNET_TESTBED_UnderlayLinkModel *model, 178GNUNET_TESTBED_underlaylinkmodel_add_peer (struct
174 struct GNUNET_TESTBED_Peer *peer) 179 GNUNET_TESTBED_UnderlayLinkModel *
180 model,
181 struct GNUNET_TESTBED_Peer *peer)
175{ 182{
176 struct ListEntry *entry; 183 struct ListEntry *entry;
177 184
178 entry = GNUNET_new(struct ListEntry); 185 entry = GNUNET_new (struct ListEntry);
179 entry->peer = peer; 186 entry->peer = peer;
180 entry->next = model->entries; 187 entry->next = model->entries;
181 model->entries = entry; 188 model->entries = entry;
@@ -194,15 +201,17 @@ GNUNET_TESTBED_underlaylinkmodel_add_peer(struct GNUNET_TESTBED_UnderlayLinkMode
194 * @param bandwidth bandwidth of the link in kilobytes per second [kB/s] 201 * @param bandwidth bandwidth of the link in kilobytes per second [kB/s]
195 */ 202 */
196void 203void
197GNUNET_TESTBED_underlaylinkmodel_set_link(struct GNUNET_TESTBED_UnderlayLinkModel *model, 204GNUNET_TESTBED_underlaylinkmodel_set_link (struct
198 struct GNUNET_TESTBED_Peer *peer, 205 GNUNET_TESTBED_UnderlayLinkModel *
199 uint32_t latency, 206 model,
200 uint32_t loss, 207 struct GNUNET_TESTBED_Peer *peer,
201 uint32_t bandwidth) 208 uint32_t latency,
209 uint32_t loss,
210 uint32_t bandwidth)
202{ 211{
203 struct LinkProperty *prop; 212 struct LinkProperty *prop;
204 213
205 prop = GNUNET_new(struct LinkProperty); 214 prop = GNUNET_new (struct LinkProperty);
206 prop->peer = peer; 215 prop->peer = peer;
207 prop->latency = latency; 216 prop->latency = latency;
208 prop->loss = loss; 217 prop->loss = loss;
@@ -221,12 +230,13 @@ GNUNET_TESTBED_underlaylinkmodel_set_link(struct GNUNET_TESTBED_UnderlayLinkMode
221 * @param model the model to unallocate 230 * @param model the model to unallocate
222 */ 231 */
223void 232void
224GNUNET_TESTBED_underlaylinkmodel_free(struct GNUNET_TESTBED_UnderlayLinkModel *model) 233GNUNET_TESTBED_underlaylinkmodel_free (struct
234 GNUNET_TESTBED_UnderlayLinkModel *model)
225{ 235{
226 model->peer->underlay_model_exists = 0; 236 model->peer->underlay_model_exists = 0;
227 free_entries(model); 237 free_entries (model);
228 free_link_properties(model); 238 free_link_properties (model);
229 gnunet_free(model); 239 gnunet_free (model);
230} 240}
231 241
232 242
@@ -237,12 +247,13 @@ GNUNET_TESTBED_underlaylinkmodel_free(struct GNUNET_TESTBED_UnderlayLinkModel *m
237 * @param model the model to commit 247 * @param model the model to commit
238 */ 248 */
239void 249void
240GNUNET_TESTBED_underlaylinkmodel_commit(struct GNUNET_TESTBED_UnderlayLinkModel *model) 250GNUNET_TESTBED_underlaylinkmodel_commit (struct
251 GNUNET_TESTBED_UnderlayLinkModel *model)
241{ 252{
242 /* FIXME: Marshal the model into a message */ 253 /* FIXME: Marshal the model into a message */
243 GNUNET_break(0); 254 GNUNET_break (0);
244 /* do not reset the value of model->peer->underlay_model_exists */ 255 /* do not reset the value of model->peer->underlay_model_exists */
245 free_entries(model); 256 free_entries (model);
246 free_link_properties(model); 257 free_link_properties (model);
247 GNUNET_free(model); 258 GNUNET_free (model);
248} 259}
diff --git a/src/testbed/testbed_helper.h b/src/testbed/testbed_helper.h
index 304c4f6b6..817ad559d 100644
--- a/src/testbed/testbed_helper.h
+++ b/src/testbed/testbed_helper.h
@@ -32,7 +32,8 @@ 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 */
35struct GNUNET_TESTBED_HelperInit { 35struct GNUNET_TESTBED_HelperInit
36{
36 /** 37 /**
37 * Type is GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT 38 * Type is GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT
38 */ 39 */
@@ -67,7 +68,8 @@ struct GNUNET_TESTBED_HelperInit {
67/** 68/**
68 * Reply message from helper process 69 * Reply message from helper process
69 */ 70 */
70struct GNUNET_TESTBED_HelperReply { 71struct GNUNET_TESTBED_HelperReply
72{
71 /** 73 /**
72 * Type is GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY 74 * Type is GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY
73 */ 75 */