diff options
author | Maximilian Szengel <gnunet@maxsz.de> | 2012-10-18 18:00:10 +0000 |
---|---|---|
committer | Maximilian Szengel <gnunet@maxsz.de> | 2012-10-18 18:00:10 +0000 |
commit | beba336144a95917321fe706d871cf27fc00db87 (patch) | |
tree | e891f21255ba6d76bfcbfa9a0955826843dbfd94 /src | |
parent | 44f92861e676181ca60892c76654bb5e69651637 (diff) | |
download | gnunet-beba336144a95917321fe706d871cf27fc00db87.tar.gz gnunet-beba336144a95917321fe706d871cf27fc00db87.zip |
regex profiler
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-regex-profiler.c | 927 | ||||
-rw-r--r-- | src/mesh/regex_profiler_test.conf | 36 |
2 files changed, 540 insertions, 423 deletions
diff --git a/src/mesh/gnunet-regex-profiler.c b/src/mesh/gnunet-regex-profiler.c index 2dc369841..b2634c2b8 100644 --- a/src/mesh/gnunet-regex-profiler.c +++ b/src/mesh/gnunet-regex-profiler.c | |||
@@ -34,223 +34,260 @@ | |||
34 | #include "gnunet_stream_lib.h" | 34 | #include "gnunet_stream_lib.h" |
35 | #include "gnunet_testbed_service.h" | 35 | #include "gnunet_testbed_service.h" |
36 | 36 | ||
37 | |||
38 | /** | 37 | /** |
39 | * Total number of hosts. | 38 | * DLL of operations |
40 | */ | 39 | */ |
41 | #define NUM_HOSTS 2 | 40 | struct DLLOperation |
41 | { | ||
42 | /** | ||
43 | * The testbed operation handle | ||
44 | */ | ||
45 | struct GNUNET_TESTBED_Operation *op; | ||
42 | 46 | ||
43 | /** | 47 | /** |
44 | * Number of peers per host. | 48 | * Closure |
45 | */ | 49 | */ |
46 | #define PEER_PER_HOST 1 | 50 | void *cls; |
47 | 51 | ||
48 | /** | 52 | /** |
49 | * Total number of peers. | 53 | * The next pointer for DLL |
50 | */ | 54 | */ |
51 | #define TOTAL_PEERS (NUM_HOSTS * PEER_PER_HOST) | 55 | struct DLLOperation *next; |
56 | |||
57 | /** | ||
58 | * The prev pointer for DLL | ||
59 | */ | ||
60 | struct DLLOperation *prev; | ||
61 | }; | ||
52 | 62 | ||
53 | 63 | ||
54 | /** | 64 | /** |
55 | * Different states in test setup | 65 | * Available states during profiling |
56 | */ | 66 | */ |
57 | enum SetupState | 67 | enum State |
58 | { | 68 | { |
59 | /** | 69 | /** |
60 | * The initial state | 70 | * Initial state |
61 | */ | 71 | */ |
62 | INIT, | 72 | STATE_INIT = 0, |
63 | 73 | ||
64 | /** | 74 | /** |
65 | * Connecting to slave controller | 75 | * Starting slaves |
66 | */ | 76 | */ |
67 | LINKING, | 77 | STATE_SLAVES_STARTING, |
68 | 78 | ||
69 | LINKING_SLAVES, | 79 | /** |
70 | 80 | * Creating peers | |
71 | LINKING_SLAVES_SUCCESS, | 81 | */ |
82 | STATE_PEERS_CREATING, | ||
72 | 83 | ||
73 | CONNECTING_PEERS, | 84 | /** |
85 | * Starting peers | ||
86 | */ | ||
87 | STATE_PEERS_STARTING, | ||
74 | 88 | ||
75 | CREATING_PEER, | 89 | /** |
90 | * Linking peers | ||
91 | */ | ||
92 | STATE_PEERS_LINKING, | ||
76 | 93 | ||
77 | STARTING_PEER | 94 | /** |
95 | * Destroying peers; we can do this as the controller takes care of stopping a | ||
96 | * peer if it is running | ||
97 | */ | ||
98 | STATE_PEERS_DESTROYING | ||
78 | }; | 99 | }; |
79 | 100 | ||
80 | 101 | ||
81 | /** | 102 | /** |
82 | * Event Mask for operation callbacks | 103 | * An array of hosts loaded from the hostkeys file |
83 | */ | 104 | */ |
84 | uint64_t event_mask; | 105 | static struct GNUNET_TESTBED_Host **hosts; |
85 | 106 | ||
86 | /** | 107 | /** |
87 | * Testbed operation handle | 108 | * Peer handles. |
88 | */ | 109 | */ |
89 | static struct GNUNET_TESTBED_Operation *op[NUM_HOSTS]; | 110 | struct Peer |
111 | { | ||
112 | /** | ||
113 | * The actual testbed peer handle. | ||
114 | */ | ||
115 | struct GNUNET_TESTBED_Peer *peer_handle; | ||
116 | |||
117 | /** | ||
118 | * Peer's mesh handle. | ||
119 | */ | ||
120 | struct GNUNET_MESH_Handle *mesh_handle; | ||
121 | |||
122 | /** | ||
123 | * Host on which the peer is running. | ||
124 | */ | ||
125 | struct GNUNET_TESTBED_Host *host_handle; | ||
126 | |||
127 | /** | ||
128 | * Testbed operation handle. | ||
129 | */ | ||
130 | struct GNUNET_TESTBED_Operation *op_handle; | ||
131 | }; | ||
90 | 132 | ||
91 | /** | 133 | /** |
92 | * Setup state. | 134 | * Array of peer handles used to pass to |
135 | * GNUNET_TESTBED_overlay_configure_topology | ||
93 | */ | 136 | */ |
94 | static enum SetupState state[NUM_HOSTS]; | 137 | struct GNUNET_TESTBED_Peer **peer_handles; |
95 | 138 | ||
96 | /** | 139 | /** |
97 | * Abort task. | 140 | * The array of peers; we fill this as the peers are given to us by the testbed |
98 | */ | 141 | */ |
99 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; | 142 | static struct Peer *peers; |
100 | 143 | ||
101 | /** | 144 | /** |
102 | * Global test result | 145 | * Host registration handle |
103 | */ | 146 | */ |
104 | static int result; | 147 | static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle; |
105 | 148 | ||
106 | /** | 149 | /** |
107 | * Hosts successfully registered | 150 | * Handle to the master controller process |
108 | */ | 151 | */ |
109 | static unsigned int host_registered; | 152 | struct GNUNET_TESTBED_ControllerProc *mc_proc; |
110 | 153 | ||
111 | /** | 154 | /** |
112 | * Peers successfully started | 155 | * Handle to the master controller |
113 | */ | 156 | */ |
114 | static unsigned int peers_started; | 157 | struct GNUNET_TESTBED_Controller *mc; |
115 | 158 | ||
116 | /** | 159 | /** |
117 | * The master controller host | 160 | * Handle to global configuration |
118 | */ | 161 | */ |
119 | struct GNUNET_TESTBED_Host *master_host; | 162 | struct GNUNET_CONFIGURATION_Handle *cfg; |
120 | 163 | ||
121 | /** | 164 | /** |
122 | * The master controller process | 165 | * Head of the operations list |
123 | */ | 166 | */ |
124 | static struct GNUNET_TESTBED_ControllerProc *master_proc; | 167 | struct DLLOperation *dll_op_head; |
125 | 168 | ||
126 | /** | 169 | /** |
127 | * Handle to master controller | 170 | * Tail of the operations list |
128 | */ | 171 | */ |
129 | static struct GNUNET_TESTBED_Controller *master_ctrl; | 172 | struct DLLOperation *dll_op_tail; |
130 | |||
131 | 173 | ||
132 | /** | 174 | /** |
133 | * Slave host registration handles | 175 | * Peer linking - topology operation |
134 | */ | 176 | */ |
135 | static struct GNUNET_TESTBED_HostRegistrationHandle *rh; | 177 | struct GNUNET_TESTBED_Operation *topology_op; |
136 | |||
137 | 178 | ||
138 | /** | 179 | /** |
139 | * Handle to global configuration | 180 | * Abort task identifier |
140 | */ | 181 | */ |
141 | static struct GNUNET_CONFIGURATION_Handle *cfg; | 182 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; |
142 | 183 | ||
143 | /** | 184 | /** |
144 | * Structure for storing host handles | 185 | * Host registration task identifier |
145 | */ | 186 | */ |
146 | struct Host | 187 | static GNUNET_SCHEDULER_TaskIdentifier register_hosts_task; |
147 | { | ||
148 | /** | ||
149 | * IP address of this host. | ||
150 | */ | ||
151 | char *ip; | ||
152 | 188 | ||
153 | /** | 189 | /** |
154 | * Host handle. | 190 | * Global event mask for all testbed events |
155 | */ | 191 | */ |
156 | struct GNUNET_TESTBED_Host *host; | 192 | uint64_t event_mask; |
157 | |||
158 | /** | ||
159 | * Registration state of this host. | ||
160 | */ | ||
161 | int host_registered; | ||
162 | |||
163 | /** | ||
164 | * Operation handle. | ||
165 | */ | ||
166 | struct GNUNET_TESTBED_Operation *op; | ||
167 | |||
168 | /** | ||
169 | * Host state. | ||
170 | */ | ||
171 | enum SetupState state; | ||
172 | }; | ||
173 | 193 | ||
174 | /** | 194 | /** |
175 | * List of slaves. | 195 | * The starting time of a profiling step |
176 | */ | 196 | */ |
177 | static struct Host slaves[NUM_HOSTS] = { {"192.168.1.33", NULL, 0, NULL, INIT}, | 197 | struct GNUNET_TIME_Absolute prof_start_time; |
178 | {"192.168.1.34", NULL, 0, NULL, INIT} | ||
179 | }; | ||
180 | 198 | ||
181 | /** | 199 | /** |
182 | * Structure for holding peer's handles. | 200 | * Duration profiling step has taken |
183 | */ | 201 | */ |
184 | struct PeerData | 202 | struct GNUNET_TIME_Relative prof_time; |
185 | { | ||
186 | /** | ||
187 | * Handle to testbed peer. | ||
188 | */ | ||
189 | struct GNUNET_TESTBED_Peer *peer; | ||
190 | 203 | ||
191 | /** | 204 | /** |
192 | * Peer's mesh handle. | 205 | * Current peer id |
193 | */ | 206 | */ |
194 | struct GNUNET_MESH_Handle *mesh_handle; | 207 | unsigned int peer_id; |
195 | 208 | ||
196 | /** | 209 | /** |
197 | * The service connect operation to stream | 210 | * Number of peers to be started by the profiler |
198 | */ | 211 | */ |
199 | struct GNUNET_TESTBED_Operation *op; | 212 | static unsigned int num_peers; |
200 | 213 | ||
201 | /** | 214 | /** |
202 | * Peer setup state. | 215 | * Number of hosts in the hosts array |
203 | */ | 216 | */ |
204 | enum SetupState state; | 217 | static unsigned int num_hosts; |
205 | 218 | ||
206 | /** | 219 | /** |
207 | * Our Peer id | 220 | * Number of random links to be established between peers |
208 | */ | 221 | */ |
209 | struct GNUNET_PeerIdentity our_id; | 222 | static unsigned int num_links; |
210 | }; | ||
211 | 223 | ||
212 | /** | 224 | /** |
213 | * The peers | 225 | * Global testing status |
214 | */ | 226 | */ |
215 | struct PeerData peers[TOTAL_PEERS]; | 227 | static int result; |
216 | 228 | ||
229 | /** | ||
230 | * current state of profiling | ||
231 | */ | ||
232 | enum State state; | ||
217 | 233 | ||
218 | 234 | ||
219 | /** | 235 | /** |
220 | * Close sockets and stop testing deamons nicely | 236 | * Shutdown nicely |
237 | * | ||
238 | * @param cls NULL | ||
239 | * @param tc the task context | ||
221 | */ | 240 | */ |
222 | void | 241 | static void |
223 | do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 242 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
224 | { | 243 | { |
225 | unsigned int i; | 244 | struct DLLOperation *dll_op; |
245 | unsigned int nhost; | ||
226 | 246 | ||
227 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | 247 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) |
228 | GNUNET_SCHEDULER_cancel (abort_task); | 248 | GNUNET_SCHEDULER_cancel (abort_task); |
229 | 249 | if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task) | |
230 | for (i = 0; i < TOTAL_PEERS; i++) | 250 | GNUNET_SCHEDULER_cancel (register_hosts_task); |
251 | if (NULL != reg_handle) | ||
252 | GNUNET_TESTBED_cancel_registration (reg_handle); | ||
253 | if (NULL != topology_op) | ||
254 | GNUNET_TESTBED_operation_cancel (topology_op); | ||
255 | for (nhost = 0; nhost < num_hosts; nhost++) | ||
256 | if (NULL != hosts[nhost]) | ||
257 | GNUNET_TESTBED_host_destroy (hosts[nhost]); | ||
258 | GNUNET_free_non_null (hosts); | ||
259 | while (NULL != (dll_op = dll_op_head)) | ||
231 | { | 260 | { |
232 | if (NULL != peers[i].mesh_handle) | 261 | GNUNET_TESTBED_operation_cancel (dll_op->op); |
233 | GNUNET_MESH_disconnect (peers[i].mesh_handle); | 262 | GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); |
234 | if (NULL != peers[i].op) | 263 | GNUNET_free (dll_op); |
235 | GNUNET_TESTBED_operation_done (peers[i].op); | ||
236 | } | 264 | } |
265 | if (NULL != mc) | ||
266 | GNUNET_TESTBED_controller_disconnect (mc); | ||
267 | if (NULL != mc_proc) | ||
268 | GNUNET_TESTBED_controller_stop (mc_proc); | ||
269 | if (NULL != cfg) | ||
270 | GNUNET_CONFIGURATION_destroy (cfg); | ||
271 | |||
272 | //FIXME GNUNET_MESH_disconnect (peers[i].mesh_handle); | ||
237 | 273 | ||
238 | GNUNET_SCHEDULER_shutdown (); /* For shutting down testbed */ | 274 | GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */ |
239 | } | 275 | } |
240 | 276 | ||
241 | 277 | ||
242 | /** | 278 | /** |
243 | * Something went wrong and timed out. Kill everything and set error flag. | 279 | * abort task to run on test timed out |
244 | * | 280 | * |
245 | * @param cls close. | 281 | * @param cls NULL |
246 | * @param tc task context. | 282 | * @param tc the task context |
247 | */ | 283 | */ |
248 | static void | 284 | static void |
249 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 285 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
250 | { | 286 | { |
251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: ABORT\n"); | 287 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n"); |
288 | abort_task = GNUNET_SCHEDULER_NO_TASK; | ||
252 | result = GNUNET_SYSERR; | 289 | result = GNUNET_SYSERR; |
253 | abort_task = 0; | 290 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
254 | } | 291 | } |
255 | 292 | ||
256 | 293 | ||
@@ -310,7 +347,7 @@ void | |||
310 | mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | 347 | mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, |
311 | void *ca_result, const char *emsg) | 348 | void *ca_result, const char *emsg) |
312 | { | 349 | { |
313 | long i = (long) cls; | 350 | struct Peer *peer = (struct Peer *) cls; |
314 | 351 | ||
315 | if (NULL != emsg) | 352 | if (NULL != emsg) |
316 | { | 353 | { |
@@ -318,8 +355,14 @@ mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
318 | GNUNET_assert (0); | 355 | GNUNET_assert (0); |
319 | } | 356 | } |
320 | 357 | ||
321 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh connect callback for peer %i\n", | 358 | GNUNET_assert (peer->op_handle == op); |
322 | i); | 359 | GNUNET_assert (peer->mesh_handle == ca_result); |
360 | |||
361 | GNUNET_TESTBED_operation_done (op); | ||
362 | |||
363 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh connect callback for peer\n"); | ||
364 | |||
365 | //GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
323 | } | 366 | } |
324 | 367 | ||
325 | 368 | ||
@@ -334,7 +377,8 @@ mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
334 | void * | 377 | void * |
335 | mesh_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 378 | mesh_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
336 | { | 379 | { |
337 | struct PeerData *peer = (struct PeerData *) cls; | 380 | |
381 | struct Peer *peer = (struct Peer *) cls; | ||
338 | 382 | ||
339 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh connect adapter\n"); | 383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh connect adapter\n"); |
340 | 384 | ||
@@ -350,7 +394,7 @@ mesh_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
350 | GNUNET_MESH_connect (cfg, cls, &mesh_inbound_tunnel_handler, | 394 | GNUNET_MESH_connect (cfg, cls, &mesh_inbound_tunnel_handler, |
351 | &mesh_tunnel_end_handler, handlers, apptypes); | 395 | &mesh_tunnel_end_handler, handlers, apptypes); |
352 | 396 | ||
353 | return NULL; | 397 | return peer->mesh_handle; |
354 | } | 398 | } |
355 | 399 | ||
356 | 400 | ||
@@ -364,6 +408,10 @@ mesh_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
364 | void | 408 | void |
365 | mesh_da (void *cls, void *op_result) | 409 | mesh_da (void *cls, void *op_result) |
366 | { | 410 | { |
411 | struct Peer *peer = (struct Peer *) cls; | ||
412 | |||
413 | GNUNET_assert (peer->mesh_handle == op_result); | ||
414 | |||
367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh disconnect adapter\n"); | 415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh disconnect adapter\n"); |
368 | } | 416 | } |
369 | 417 | ||
@@ -376,27 +424,54 @@ mesh_da (void *cls, void *op_result) | |||
376 | * @param emsg NULL on success; otherwise an error description | 424 | * @param emsg NULL on success; otherwise an error description |
377 | */ | 425 | */ |
378 | static void | 426 | static void |
379 | peer_start_cb (void *cls, const char *emsg) | 427 | peer_churn_cb (void *cls, const char *emsg) |
380 | { | 428 | { |
381 | unsigned int cnt; | 429 | struct DLLOperation *dll_op = cls; |
382 | long i = (long) cls; | 430 | struct GNUNET_TESTBED_Operation *op; |
383 | 431 | static unsigned int started_peers; | |
384 | GNUNET_TESTBED_operation_done (op[i]); | 432 | unsigned int peer_cnt; |
385 | peers_started++; | ||
386 | // FIXME create and start rest of PEERS_PER_HOST | ||
387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u peer(s) started\n", peers_started); | ||
388 | 433 | ||
389 | if (TOTAL_PEERS == peers_started) | 434 | op = dll_op->op; |
435 | GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); | ||
436 | GNUNET_free (dll_op); | ||
437 | if (NULL != emsg) | ||
438 | { | ||
439 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
440 | _("An operation has failed while starting peers\n")); | ||
441 | GNUNET_TESTBED_operation_done (op); | ||
442 | GNUNET_SCHEDULER_cancel (abort_task); | ||
443 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); | ||
444 | return; | ||
445 | } | ||
446 | GNUNET_TESTBED_operation_done (op); | ||
447 | if (++started_peers == num_peers) | ||
390 | { | 448 | { |
391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers started.\n"); | 449 | prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time); |
392 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Linking slave controllers\n"); | 450 | printf ("All peers started successfully in %.2f seconds\n", |
451 | ((double) prof_time.rel_value) / 1000.00); | ||
452 | result = GNUNET_OK; | ||
453 | if (0 == num_links) | ||
454 | { | ||
455 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
456 | return; | ||
457 | } | ||
393 | 458 | ||
394 | for (cnt = 0; cnt < NUM_HOSTS - 1; cnt++) | 459 | peer_handles = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer *) * num_peers); |
460 | for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) | ||
461 | peer_handles[peer_cnt] = peers[peer_cnt].peer_handle; | ||
462 | |||
463 | state = STATE_PEERS_LINKING; | ||
464 | /* Do overlay connect */ | ||
465 | prof_start_time = GNUNET_TIME_absolute_get (); | ||
466 | topology_op = | ||
467 | GNUNET_TESTBED_overlay_configure_topology (NULL, num_peers, peer_handles, | ||
468 | GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, | ||
469 | num_links); | ||
470 | if (NULL == topology_op) | ||
395 | { | 471 | { |
396 | state[cnt] = LINKING_SLAVES; | 472 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
397 | op[cnt] = | 473 | "Cannot create topology, op handle was NULL\n"); |
398 | GNUNET_TESTBED_get_slave_config ((void *) (long) cnt, master_ctrl, | 474 | GNUNET_assert (0); |
399 | slaves[cnt + 1].host); | ||
400 | } | 475 | } |
401 | } | 476 | } |
402 | } | 477 | } |
@@ -414,348 +489,398 @@ peer_start_cb (void *cls, const char *emsg) | |||
414 | static void | 489 | static void |
415 | peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | 490 | peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) |
416 | { | 491 | { |
417 | long i = (long) cls; | 492 | struct DLLOperation *dll_op = cls; |
418 | long peer_id; | 493 | struct Peer *peer_ptr; |
419 | 494 | static unsigned int created_peers; | |
420 | // GNUNET_TESTBED_operation_done(op[i]); | 495 | unsigned int peer_cnt; |
421 | peer_id = i; // FIXME A * i + B | 496 | |
422 | peers[peer_id].peer = peer; | 497 | if (NULL != emsg) |
423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Peer %i created\n", peer_id); | 498 | { |
424 | op[i] = GNUNET_TESTBED_peer_start (NULL, peer, peer_start_cb, (void *) i); | 499 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
500 | _("Creating a peer failed. Error: %s\n"), emsg); | ||
501 | GNUNET_TESTBED_operation_done (dll_op->op); | ||
502 | GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); | ||
503 | GNUNET_free (dll_op); | ||
504 | GNUNET_SCHEDULER_cancel (abort_task); | ||
505 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); | ||
506 | return; | ||
507 | } | ||
508 | |||
509 | peer_ptr = dll_op->cls; | ||
510 | GNUNET_assert (NULL == peer_ptr->peer_handle); | ||
511 | peer_ptr->peer_handle = peer; | ||
512 | GNUNET_TESTBED_operation_done (dll_op->op); | ||
513 | GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); | ||
514 | GNUNET_free (dll_op); | ||
515 | |||
516 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %i created on host %s\n", | ||
517 | created_peers, | ||
518 | GNUNET_TESTBED_host_get_hostname (peer_ptr->host_handle)); | ||
519 | |||
520 | if (++created_peers == num_peers) | ||
521 | { | ||
522 | prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time); | ||
523 | printf ("All peers created successfully in %.2f seconds\n", | ||
524 | ((double) prof_time.rel_value) / 1000.00); | ||
525 | /* Now peers are to be started */ | ||
526 | state = STATE_PEERS_STARTING; | ||
527 | prof_start_time = GNUNET_TIME_absolute_get (); | ||
528 | for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) | ||
529 | { | ||
530 | dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); | ||
531 | dll_op->op = GNUNET_TESTBED_peer_start (dll_op, peers[peer_cnt].peer_handle, | ||
532 | &peer_churn_cb, dll_op); | ||
533 | GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op); | ||
534 | } | ||
535 | } | ||
425 | } | 536 | } |
426 | 537 | ||
427 | 538 | ||
428 | /** | 539 | /** |
429 | * Signature of the event handler function called by the | 540 | * Controller event callback |
430 | * respective event controller. | ||
431 | * | 541 | * |
432 | * @param cls closure | 542 | * @param cls NULL |
433 | * @param event information about the event | 543 | * @param event the controller event |
434 | */ | 544 | */ |
435 | static void | 545 | static void |
436 | controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | 546 | controller_event_cb (void *cls, |
547 | const struct GNUNET_TESTBED_EventInformation *event) | ||
437 | { | 548 | { |
438 | long i; | 549 | struct DLLOperation *dll_op; |
550 | struct GNUNET_TESTBED_Operation *op; | ||
439 | 551 | ||
440 | switch (event->type) | 552 | switch (state) |
441 | { | 553 | { |
442 | case GNUNET_TESTBED_ET_PEER_START: | 554 | case STATE_SLAVES_STARTING: |
443 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Peer started\n"); | 555 | switch (event->type) |
444 | /* event->details.peer_start.peer; */ | ||
445 | /* event->details.peer_start.host; */ | ||
446 | |||
447 | break; | ||
448 | case GNUNET_TESTBED_ET_PEER_STOP: | ||
449 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer stopped\n"); | ||
450 | break; | ||
451 | case GNUNET_TESTBED_ET_CONNECT: | ||
452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Overlay Connected\n"); | ||
453 | for (i = 0; i < TOTAL_PEERS; i++) | ||
454 | { | ||
455 | GNUNET_TESTBED_service_connect (NULL, peers[i].peer, "mesh", | ||
456 | &mesh_connect_cb, (void *) i, &mesh_ca, | ||
457 | &mesh_da, NULL); | ||
458 | } | ||
459 | break; | ||
460 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
461 | if (NULL != event->details.operation_finished.emsg) | ||
462 | { | ||
463 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testbed error: %s\n", | ||
464 | event->details.operation_finished.emsg); | ||
465 | GNUNET_assert (0); | ||
466 | } | ||
467 | |||
468 | i = (long) event->details.operation_finished.op_cls; | ||
469 | switch (state[i]) | ||
470 | { | 556 | { |
471 | case INIT: | 557 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: |
472 | { | 558 | { |
473 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Init: %u\n", i); | 559 | static unsigned int slaves_started; |
474 | GNUNET_TESTBED_operation_done (event->details. | 560 | unsigned int peer_cnt; |
475 | operation_finished.operation); | 561 | |
476 | op[i] = NULL; | 562 | dll_op = event->details.operation_finished.op_cls; |
477 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Operation %u finished\n", i); | 563 | GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); |
478 | break; | 564 | GNUNET_free (dll_op); |
479 | } | 565 | op = event->details.operation_finished.operation; |
480 | case LINKING: | 566 | if (NULL != event->details.operation_finished.emsg) |
481 | { | 567 | { |
482 | GNUNET_assert (NULL != slaves[i].op); | 568 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
483 | 569 | _("An operation has failed while starting slaves\n")); | |
484 | GNUNET_TESTBED_operation_done (slaves[i].op); | 570 | GNUNET_TESTBED_operation_done (op); |
485 | slaves[i].op = NULL; | 571 | GNUNET_SCHEDULER_cancel (abort_task); |
486 | 572 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); | |
487 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Operation %u finished\n", i); | 573 | return; |
488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Linked host %i\n", i); | 574 | } |
489 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating peer...\n"); | 575 | GNUNET_TESTBED_operation_done (op); |
490 | 576 | /* Proceed to start peers */ | |
491 | state[i] = CREATING_PEER; | 577 | if (++slaves_started == num_hosts - 1) |
492 | op[i] = | 578 | { |
493 | GNUNET_TESTBED_peer_create (master_ctrl, slaves[i].host, cfg, | 579 | printf ("All slaves started successfully\n"); |
494 | peer_create_cb, (void *) i); | 580 | state = STATE_PEERS_CREATING; |
495 | break; | 581 | prof_start_time = GNUNET_TIME_absolute_get (); |
496 | } | 582 | peers = GNUNET_malloc (sizeof (struct Peer) * num_peers); |
497 | case CREATING_PEER: | 583 | for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) |
498 | { | 584 | { |
499 | GNUNET_TESTBED_operation_done (event->details. | 585 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating peer %i on host %s\n", |
500 | operation_finished.operation); | 586 | peer_cnt, |
501 | op[i] = NULL; | 587 | GNUNET_TESTBED_host_get_hostname (hosts[peer_cnt % num_hosts])); |
502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Operation %u finished\n", i); | 588 | |
503 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Peer create\n"); | 589 | peers[peer_cnt].host_handle = hosts[peer_cnt % num_hosts]; |
590 | |||
591 | dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); | ||
592 | dll_op->cls = &peers[peer_cnt]; | ||
593 | dll_op->op = GNUNET_TESTBED_peer_create (mc, | ||
594 | hosts[peer_cnt % num_hosts], | ||
595 | cfg, | ||
596 | &peer_create_cb, | ||
597 | dll_op); | ||
598 | GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op); | ||
599 | } | ||
600 | } | ||
601 | } | ||
504 | break; | 602 | break; |
603 | default: | ||
604 | GNUNET_assert (0); | ||
505 | } | 605 | } |
506 | case LINKING_SLAVES: | 606 | break; |
607 | case STATE_PEERS_STARTING: | ||
608 | switch (event->type) | ||
507 | { | 609 | { |
508 | struct GNUNET_CONFIGURATION_Handle *slave_cfg; | 610 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: |
509 | 611 | /* Control reaches here when peer start fails */ | |
510 | GNUNET_assert (NULL != event->details.operation_finished.generic); | 612 | case GNUNET_TESTBED_ET_PEER_START: |
511 | slave_cfg = | 613 | /* we handle peer starts in peer_churn_cb */ |
512 | GNUNET_CONFIGURATION_dup ((struct GNUNET_CONFIGURATION_Handle *) | ||
513 | event->details.operation_finished.generic); | ||
514 | GNUNET_TESTBED_operation_done (event->details. | ||
515 | operation_finished.operation); | ||
516 | op[i] = NULL; | ||
517 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Operation %u finished\n", i); | ||
518 | state[i] = LINKING_SLAVES_SUCCESS; | ||
519 | op[i] = | ||
520 | GNUNET_TESTBED_controller_link ((void *) (long) i, master_ctrl, | ||
521 | slaves[i + 1].host, slaves[i].host, | ||
522 | slave_cfg, GNUNET_NO); | ||
523 | GNUNET_CONFIGURATION_destroy (slave_cfg); | ||
524 | break; | 614 | break; |
615 | default: | ||
616 | GNUNET_assert (0); | ||
525 | } | 617 | } |
526 | case LINKING_SLAVES_SUCCESS: | 618 | break; |
619 | case STATE_PEERS_LINKING: | ||
620 | switch (event->type) | ||
527 | { | 621 | { |
528 | unsigned int peer_cnt; | 622 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: |
529 | struct GNUNET_TESTBED_Peer *peer_handles[TOTAL_PEERS]; | 623 | /* Control reaches here when a peer linking operation fails */ |
530 | 624 | if (NULL != event->details.operation_finished.emsg) | |
531 | GNUNET_TESTBED_operation_done (event->details. | ||
532 | operation_finished.operation); | ||
533 | op[i] = NULL; | ||
534 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Operation %u finished\n", i); | ||
535 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Linking slave %i succeeded\n", i); | ||
536 | state[0] = CONNECTING_PEERS; | ||
537 | |||
538 | for (peer_cnt = 0; peer_cnt < TOTAL_PEERS; peer_cnt++) | ||
539 | { | 625 | { |
540 | peer_handles[peer_cnt] = peers[peer_cnt].peer; | 626 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
627 | _("An operation has failed while linking\n")); | ||
628 | GNUNET_SCHEDULER_cancel (abort_task); | ||
629 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); | ||
541 | } | 630 | } |
542 | op[0] = | ||
543 | GNUNET_TESTBED_overlay_configure_topology (NULL, TOTAL_PEERS, | ||
544 | peer_handles, | ||
545 | GNUNET_TESTBED_TOPOLOGY_LINE); | ||
546 | GNUNET_assert (NULL != op[0]); | ||
547 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peers...\n"); | ||
548 | break; | 631 | break; |
549 | } | 632 | case GNUNET_TESTBED_ET_CONNECT: |
550 | case CONNECTING_PEERS: | 633 | { |
551 | { | 634 | static unsigned int established_links; |
552 | GNUNET_TESTBED_operation_done (event->details. | 635 | unsigned int peer_cnt; |
553 | operation_finished.operation); | 636 | |
554 | op[i] = NULL; | 637 | if (0 == established_links) |
555 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Operation %u finished\n", i); | 638 | printf ("Establishing links\n ."); |
556 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n"); | 639 | else |
640 | { | ||
641 | printf ("."); | ||
642 | fflush (stdout); | ||
643 | } | ||
644 | if (++established_links == num_links) | ||
645 | { | ||
646 | prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time); | ||
647 | printf ("\n%u links established in %.2f seconds\n", | ||
648 | num_links, ((double) prof_time.rel_value) / 1000.00); | ||
649 | result = GNUNET_OK; | ||
650 | GNUNET_free (peer_handles); | ||
651 | printf ("\nConnecting to mesh service...\n"); | ||
652 | for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) | ||
653 | { | ||
654 | peers[peer_cnt].op_handle = GNUNET_TESTBED_service_connect (NULL, | ||
655 | peers[peer_cnt].peer_handle, | ||
656 | "mesh", | ||
657 | &mesh_connect_cb, | ||
658 | &peers[peer_cnt], | ||
659 | &mesh_ca, | ||
660 | &mesh_da, | ||
661 | &peers[peer_cnt]); | ||
662 | } | ||
663 | } | ||
664 | } | ||
557 | break; | 665 | break; |
558 | } | ||
559 | default: | 666 | default: |
560 | GNUNET_break (0); | 667 | GNUNET_assert (0); |
561 | } | 668 | } |
562 | break; | 669 | break; |
563 | default: | 670 | default: |
564 | GNUNET_break (0); | 671 | GNUNET_assert (0); |
565 | } | 672 | } |
566 | } | 673 | } |
567 | 674 | ||
568 | 675 | ||
569 | /** | 676 | /** |
570 | * Callback which will be called to after a host registration succeeded or | 677 | * Task to register all hosts available in the global host list |
571 | * failed. Registration of all slave hosts is continued and linking of the hosts | ||
572 | * is started. | ||
573 | * | 678 | * |
574 | * @param cls not used. | 679 | * @param cls NULL |
575 | * @param emsg the error message; NULL if host registration is successful. | 680 | * @param tc the scheduler task context |
576 | */ | 681 | */ |
577 | static void | 682 | static void |
578 | registration_cont (void *cls, const char *emsg) | 683 | register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
579 | { | ||
580 | struct Host *slave = (struct Host *) cls; | ||
581 | 684 | ||
582 | if (NULL != emsg || NULL == slave) | 685 | |
686 | /** | ||
687 | * Callback which will be called to after a host registration succeeded or failed | ||
688 | * | ||
689 | * @param cls the closure | ||
690 | * @param emsg the error message; NULL if host registration is successful | ||
691 | */ | ||
692 | static void | ||
693 | host_registration_completion (void *cls, const char *emsg) | ||
694 | { | ||
695 | reg_handle = NULL; | ||
696 | if (NULL != emsg) | ||
583 | { | 697 | { |
584 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); | 698 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
585 | GNUNET_assert (0); | 699 | _("Host registration failed for a host. Error: %s\n"), emsg); |
700 | GNUNET_SCHEDULER_cancel (abort_task); | ||
701 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); | ||
702 | return; | ||
586 | } | 703 | } |
704 | register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL); | ||
705 | } | ||
587 | 706 | ||
588 | state[host_registered] = LINKING; | ||
589 | slave->state = LINKING; | ||
590 | 707 | ||
591 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Linking host %u\n", host_registered); | 708 | /** |
592 | slave->op = | 709 | * Task to register all hosts available in the global host list |
593 | GNUNET_TESTBED_controller_link ((void *) (long) host_registered, | 710 | * |
594 | master_ctrl, slave->host, NULL, cfg, | 711 | * @param cls NULL |
595 | GNUNET_YES); | 712 | * @param tc the scheduler task context |
596 | host_registered++; | 713 | */ |
597 | if (NUM_HOSTS != host_registered) | 714 | static void |
715 | register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
716 | { | ||
717 | struct DLLOperation *dll_op; | ||
718 | static unsigned int reg_host; | ||
719 | unsigned int slave; | ||
720 | |||
721 | register_hosts_task = GNUNET_SCHEDULER_NO_TASK; | ||
722 | if (reg_host == num_hosts - 1) | ||
598 | { | 723 | { |
599 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Registering host %u with ip %s\n", | 724 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
600 | host_registered, slaves[host_registered].ip); | 725 | "All hosts successfully registered\n"); |
601 | rh = GNUNET_TESTBED_register_host (master_ctrl, | 726 | /* Start slaves */ |
602 | slaves[host_registered].host, | 727 | state = STATE_SLAVES_STARTING; |
603 | ®istration_cont, | 728 | for (slave = 1; slave < num_hosts; slave++) |
604 | &slaves[host_registered]); | 729 | { |
730 | dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); | ||
731 | dll_op->op = GNUNET_TESTBED_controller_link (dll_op, | ||
732 | mc, | ||
733 | hosts[slave], | ||
734 | hosts[0], | ||
735 | cfg, | ||
736 | GNUNET_YES); | ||
737 | GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op); | ||
738 | } | ||
605 | return; | 739 | return; |
606 | } | 740 | } |
741 | reg_handle = GNUNET_TESTBED_register_host (mc, hosts[++reg_host], | ||
742 | host_registration_completion, | ||
743 | NULL); | ||
607 | } | 744 | } |
608 | 745 | ||
609 | 746 | ||
610 | /** | 747 | /** |
611 | * Callback to signal successfull startup of the controller process. If the | 748 | * Callback to signal successfull startup of the controller process |
612 | * startup was successfull the master controller and all slave hosts are | ||
613 | * created. Registering the slave hosts is started and continued in | ||
614 | * registration_cont. | ||
615 | * | 749 | * |
616 | * @param cls not used. | 750 | * @param cls the closure from GNUNET_TESTBED_controller_start() |
617 | * @param config the configuration with which the controller has been started; | 751 | * @param cfg the configuration with which the controller has been started; |
618 | * NULL if status is not GNUNET_OK | 752 | * NULL if status is not GNUNET_OK |
619 | * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not, | 753 | * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not, |
620 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case | 754 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case |
621 | */ | 755 | */ |
622 | static void | 756 | static void |
623 | status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, | 757 | status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status) |
624 | int status) | ||
625 | { | 758 | { |
626 | unsigned int i; | 759 | GNUNET_SCHEDULER_cancel (abort_task); |
627 | 760 | if (GNUNET_OK != status) | |
628 | if (NULL == config || GNUNET_OK != status) | 761 | { |
762 | mc_proc = NULL; | ||
763 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); | ||
629 | return; | 764 | return; |
630 | 765 | } | |
631 | event_mask = 0; | 766 | event_mask = 0; |
632 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); | 767 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); |
633 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); | 768 | event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); |
634 | event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); | 769 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); |
635 | event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 770 | event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT); |
636 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to master controller\n"); | 771 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
637 | master_ctrl = | 772 | mc = GNUNET_TESTBED_controller_connect (config, hosts[0], event_mask, |
638 | GNUNET_TESTBED_controller_connect (config, master_host, event_mask, | 773 | &controller_event_cb, NULL); |
639 | &controller_cb, NULL); | 774 | if (NULL == mc) |
640 | GNUNET_assert (NULL != master_ctrl); | ||
641 | |||
642 | for (i = 0; i < NUM_HOSTS; i++) | ||
643 | { | 775 | { |
644 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating host %u with ip %s\n", i, | 776 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
645 | slaves[i].ip); | 777 | _("Unable to connect to master controller -- Check config\n")); |
646 | slaves[i].host = GNUNET_TESTBED_host_create (slaves[i].ip, NULL, 0); | 778 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); |
647 | GNUNET_assert (NULL != slaves[i].host); | 779 | return; |
648 | } | 780 | } |
649 | host_registered = 0; | 781 | register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL); |
650 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Registering host %u with ip %s\n", | 782 | abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
651 | host_registered, slaves[0].ip); | 783 | &do_abort, NULL); |
652 | rh = GNUNET_TESTBED_register_host (master_ctrl, slaves[0].host, | ||
653 | ®istration_cont, &slaves[0]); | ||
654 | GNUNET_assert (NULL != rh); | ||
655 | } | 784 | } |
656 | 785 | ||
657 | 786 | ||
658 | /** | 787 | /** |
659 | * Main run function. | 788 | * Main function that will be run by the scheduler. |
660 | * | 789 | * |
661 | * @param cls not used. | 790 | * @param cls closure |
662 | * @param args arguments passed to GNUNET_PROGRAM_run | 791 | * @param args remaining command-line arguments |
663 | * @param cfgfile the path to configuration file | 792 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) |
664 | * @param config the configuration file handle | 793 | * @param config configuration |
665 | */ | 794 | */ |
666 | static void | 795 | static void |
667 | run (void *cls, char *const *args, const char *cfgfile, | 796 | run (void *cls, char *const *args, const char *cfgfile, |
668 | const struct GNUNET_CONFIGURATION_Handle *config) | 797 | const struct GNUNET_CONFIGURATION_Handle *config) |
669 | { | 798 | { |
670 | master_host = GNUNET_TESTBED_host_create ("192.168.1.33", NULL, 0); | 799 | unsigned int nhost; |
671 | GNUNET_assert (NULL != master_host); | 800 | |
801 | if (NULL == args[0]) | ||
802 | { | ||
803 | fprintf (stderr, _("No hosts-file specified on command line\n")); | ||
804 | return; | ||
805 | } | ||
806 | if (0 == num_peers) | ||
807 | { | ||
808 | result = GNUNET_OK; | ||
809 | return; | ||
810 | } | ||
811 | num_hosts = GNUNET_TESTBED_hosts_load_from_file (args[0], &hosts); | ||
812 | if (0 == num_hosts) | ||
813 | { | ||
814 | fprintf (stderr, _("No hosts loaded. Need at least one host\n")); | ||
815 | return; | ||
816 | } | ||
817 | for (nhost = 0; nhost < num_hosts; nhost++) | ||
818 | { | ||
819 | if (GNUNET_YES != GNUNET_TESTBED_is_host_habitable (hosts[nhost])) | ||
820 | { | ||
821 | fprintf (stderr, _("Host %s cannot start testbed\n"), | ||
822 | GNUNET_TESTBED_host_get_hostname (hosts[nhost])); | ||
823 | break; | ||
824 | } | ||
825 | } | ||
826 | if (num_hosts != nhost) | ||
827 | { | ||
828 | fprintf (stderr, _("Exiting\n")); | ||
829 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
830 | return; | ||
831 | } | ||
832 | if (NULL == config) | ||
833 | { | ||
834 | fprintf (stderr, _("No configuration file given. Exiting\n")); | ||
835 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
836 | return; | ||
837 | } | ||
838 | |||
672 | cfg = GNUNET_CONFIGURATION_dup (config); | 839 | cfg = GNUNET_CONFIGURATION_dup (config); |
673 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting master controller\n"); | 840 | mc_proc = |
674 | master_proc = | 841 | GNUNET_TESTBED_controller_start (GNUNET_TESTBED_host_get_hostname |
675 | GNUNET_TESTBED_controller_start ("192.168.1.33", master_host, cfg, | 842 | (hosts[0]), |
676 | status_cb, NULL); | 843 | hosts[0], |
844 | cfg, | ||
845 | status_cb, | ||
846 | NULL); | ||
677 | abort_task = | 847 | abort_task = |
678 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 848 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
679 | (GNUNET_TIME_UNIT_MINUTES, 60), &do_abort, | 849 | (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort, |
680 | NULL); | 850 | NULL); |
681 | } | 851 | } |
682 | 852 | ||
683 | 853 | ||
684 | /** | 854 | /** |
685 | * Main function for profiling the regex/mesh implementation. Checks if all ssh | 855 | * Main function. |
686 | * connections to each of the hosts in 'slave_ips' is possible before setting up | ||
687 | * the testbed. | ||
688 | * | 856 | * |
689 | * @param argc argument count. | 857 | * @return 0 on success |
690 | * @param argv argument values. | ||
691 | * | ||
692 | * @return 0 on success. | ||
693 | */ | 858 | */ |
694 | int | 859 | int |
695 | main (int argc, char **argv) | 860 | main (int argc, char *const *argv) |
696 | { | 861 | { |
697 | int ret; | 862 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
698 | int test_hosts; | 863 | { 'p', "num-peers", "COUNT", |
699 | unsigned int i; | 864 | gettext_noop ("create COUNT number of peers"), |
700 | 865 | GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_peers }, | |
701 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 866 | { 'n', "num-links", "COUNT", |
867 | gettext_noop ("create COUNT number of random links"), | ||
868 | GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_links }, | ||
702 | GNUNET_GETOPT_OPTION_END | 869 | GNUNET_GETOPT_OPTION_END |
703 | }; | 870 | }; |
704 | char *const argv2[] = { "gnunet-regex-profiler", | 871 | int ret; |
705 | "-c", "regex_profiler_test.conf", | ||
706 | NULL | ||
707 | }; | ||
708 | 872 | ||
709 | test_hosts = GNUNET_OK; | 873 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
710 | for (i = 0; i < NUM_HOSTS; i++) | 874 | return 2; |
711 | { | ||
712 | char *const remote_args[] = { | ||
713 | "ssh", "-o", "BatchMode=yes", slaves[i].ip, | ||
714 | "gnunet-helper-testbed --help > /dev/null", NULL | ||
715 | }; | ||
716 | struct GNUNET_OS_Process *auxp; | ||
717 | enum GNUNET_OS_ProcessStatusType type; | ||
718 | unsigned long code; | ||
719 | |||
720 | fprintf (stderr, "Testing host %i\n", i); | ||
721 | auxp = | ||
722 | GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, | ||
723 | NULL, "ssh", remote_args); | ||
724 | GNUNET_assert (NULL != auxp); | ||
725 | do | ||
726 | { | ||
727 | ret = GNUNET_OS_process_status (auxp, &type, &code); | ||
728 | GNUNET_assert (GNUNET_SYSERR != ret); | ||
729 | (void) usleep (300); | ||
730 | } | ||
731 | while (GNUNET_NO == ret); | ||
732 | (void) GNUNET_OS_process_wait (auxp); | ||
733 | GNUNET_OS_process_destroy (auxp); | ||
734 | if (0 != code) | ||
735 | { | ||
736 | fprintf (stderr, | ||
737 | "Unable to run the test as this system is not configured " | ||
738 | "to use password less SSH logins to host %s.\n", slaves[i].ip); | ||
739 | test_hosts = GNUNET_SYSERR; | ||
740 | } | ||
741 | } | ||
742 | if (test_hosts != GNUNET_OK) | ||
743 | { | ||
744 | fprintf (stderr, "Some hosts have failed the ssh check. Exiting.\n"); | ||
745 | return 1; | ||
746 | } | ||
747 | fprintf (stderr, "START.\n"); | ||
748 | 875 | ||
749 | result = GNUNET_SYSERR; | 876 | result = GNUNET_SYSERR; |
750 | |||
751 | ret = | 877 | ret = |
752 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | 878 | GNUNET_PROGRAM_run (argc, argv, "gnunet-regex-profiler [OPTIONS] hosts-file", |
753 | "gnunet-regex-profiler", "nohelp", options, &run, | 879 | _("Profiler for regex/mesh"), |
754 | NULL); | 880 | options, &run, NULL); |
755 | 881 | if (GNUNET_OK != ret) | |
756 | fprintf (stderr, "END.\n"); | 882 | return ret; |
757 | 883 | if (GNUNET_OK != result) | |
758 | if (GNUNET_SYSERR == result || GNUNET_OK != ret) | ||
759 | return 1; | 884 | return 1; |
760 | return 0; | 885 | return 0; |
761 | } | 886 | } |
diff --git a/src/mesh/regex_profiler_test.conf b/src/mesh/regex_profiler_test.conf index f21a2ba57..0f3dbcc47 100644 --- a/src/mesh/regex_profiler_test.conf +++ b/src/mesh/regex_profiler_test.conf | |||
@@ -1,8 +1,11 @@ | |||
1 | [lockmanager] | 1 | [testbed] |
2 | AUTOSTART = NO | 2 | AUTOSTART = NO |
3 | ACCEPT_FROM = 127.0.0.1; | 3 | PORT = 12113 |
4 | ACCEPT_FROM = 127.0.0.1; 192.168.1.0/24; | ||
4 | HOSTNAME = localhost | 5 | HOSTNAME = localhost |
5 | PORT = 12101 | 6 | MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS = 5 |
7 | MAX_PARALLEL_OVERLAY_CONNECT_OPERATIONS = 5 | ||
8 | #PREFIX = xterm -geometry 100x85 -T peer1 -e libtool --mode=execute gdb --args | ||
6 | 9 | ||
7 | [fs] | 10 | [fs] |
8 | AUTOSTART = NO | 11 | AUTOSTART = NO |
@@ -12,19 +15,9 @@ AUTOSTART = NO | |||
12 | 15 | ||
13 | [mesh] | 16 | [mesh] |
14 | AUTOSTART = YES | 17 | AUTOSTART = YES |
15 | ACCEPT_FROM = 127.0.0.1; | ||
16 | HOSTNAME = localhost | ||
17 | PORT = 10700 | ||
18 | # PREFIX = valgrind --leak-check=full | ||
19 | # PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args | ||
20 | 18 | ||
21 | [dht] | 19 | [dht] |
22 | DEBUG = NO | 20 | AUTOSTART = NO |
23 | AUTOSTART = YES | ||
24 | ACCEPT_FROM6 = ::1; | ||
25 | ACCEPT_FROM = 127.0.0.1; | ||
26 | HOSTNAME = localhost | ||
27 | PORT = 12100 | ||
28 | 21 | ||
29 | [block] | 22 | [block] |
30 | plugins = dht test | 23 | plugins = dht test |
@@ -47,9 +40,10 @@ WAN_QUOTA_IN = 3932160 | |||
47 | 40 | ||
48 | [core] | 41 | [core] |
49 | PORT = 12092 | 42 | PORT = 12092 |
43 | AUTOSTART = YES | ||
50 | 44 | ||
51 | [arm] | 45 | [arm] |
52 | DEFAULTSERVICES = core lockmanager statistics | 46 | DEFAULTSERVICES = core |
53 | PORT = 12366 | 47 | PORT = 12366 |
54 | DEBUG = NO | 48 | DEBUG = NO |
55 | 49 | ||
@@ -58,12 +52,10 @@ TIMEOUT = 300 s | |||
58 | PORT = 12368 | 52 | PORT = 12368 |
59 | 53 | ||
60 | [TESTING] | 54 | [TESTING] |
61 | WEAKRANDOM = YES | ||
62 | |||
63 | [testing_old] | ||
64 | NUM_PEERS = 5 | 55 | NUM_PEERS = 5 |
56 | WEAKRANDOM = YES | ||
65 | DEBUG = YES | 57 | DEBUG = YES |
66 | HOSTKEYSFILE = ${DATADIR}/testing_hostkeys.dat | 58 | HOSTKEYSFILE = ../../contrib/testing_hostkeys.dat |
67 | MAX_CONCURRENT_SSH = 10 | 59 | MAX_CONCURRENT_SSH = 10 |
68 | USE_PROGRESSBARS = YES | 60 | USE_PROGRESSBARS = YES |
69 | PEERGROUP_TIMEOUT = 2400 s | 61 | PEERGROUP_TIMEOUT = 2400 s |
@@ -72,7 +64,7 @@ PEERGROUP_TIMEOUT = 2400 s | |||
72 | HOSTKEY = $SERVICEHOME/.hostkey | 64 | HOSTKEY = $SERVICEHOME/.hostkey |
73 | 65 | ||
74 | [PATHS] | 66 | [PATHS] |
75 | SERVICEHOME = /tmp/test-stream/ | 67 | SERVICEHOME = /tmp/test-testbed/ |
76 | 68 | ||
77 | [dns] | 69 | [dns] |
78 | AUTOSTART = NO | 70 | AUTOSTART = NO |
@@ -83,5 +75,5 @@ AUTOSTART = NO | |||
83 | [vpn] | 75 | [vpn] |
84 | AUTOSTART = NO | 76 | AUTOSTART = NO |
85 | 77 | ||
86 | [testbed] | 78 | [nat] |
87 | PORT = 12099 | 79 | RETURN_LOCAL_ADDRESSES = YES |