diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-13 18:19:48 +0200 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-13 18:19:48 +0200 |
commit | 21c4b14e7e9a5f113b2c190b0223ca95074125b1 (patch) | |
tree | cb3105228f1ba52bea81c74caa642b26bc6c297e /src/testbed/testbed_api_peers.c | |
parent | f5c99c11e752667d6c07d16568ae16a782b48e4c (diff) | |
download | gnunet-21c4b14e7e9a5f113b2c190b0223ca95074125b1.tar.gz gnunet-21c4b14e7e9a5f113b2c190b0223ca95074125b1.zip |
Delete more subsystems not required after tng
Diffstat (limited to 'src/testbed/testbed_api_peers.c')
-rw-r--r-- | src/testbed/testbed_api_peers.c | 961 |
1 files changed, 0 insertions, 961 deletions
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c deleted file mode 100644 index b8e428441..000000000 --- a/src/testbed/testbed_api_peers.c +++ /dev/null | |||
@@ -1,961 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2008--2013 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testbed/testbed_api_peers.c | ||
23 | * @brief management of the knowledge about peers in this library | ||
24 | * (we know the peer ID, its host, pending operations, etc.) | ||
25 | * @author Christian Grothoff | ||
26 | * @author Sree Harsha Totakura | ||
27 | */ | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "testbed_api_peers.h" | ||
31 | #include "testbed_api.h" | ||
32 | #include "testbed.h" | ||
33 | #include "testbed_api_hosts.h" | ||
34 | #include "testbed_api_operations.h" | ||
35 | |||
36 | |||
37 | /** | ||
38 | * Peer list DLL head | ||
39 | */ | ||
40 | static struct GNUNET_TESTBED_Peer *peer_list_head; | ||
41 | |||
42 | /** | ||
43 | * Peer list DLL tail | ||
44 | */ | ||
45 | static struct GNUNET_TESTBED_Peer *peer_list_tail; | ||
46 | |||
47 | |||
48 | /** | ||
49 | * Adds a peer to the peer list | ||
50 | * | ||
51 | * @param peer the peer to add to the peer list | ||
52 | */ | ||
53 | void | ||
54 | GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer) | ||
55 | { | ||
56 | GNUNET_CONTAINER_DLL_insert_tail (peer_list_head, peer_list_tail, peer); | ||
57 | } | ||
58 | |||
59 | |||
60 | /** | ||
61 | * Removes a peer from the peer list | ||
62 | * | ||
63 | * @param peer the peer to remove | ||
64 | */ | ||
65 | void | ||
66 | GNUNET_TESTBED_peer_deregister_ (struct GNUNET_TESTBED_Peer *peer) | ||
67 | { | ||
68 | GNUNET_CONTAINER_DLL_remove (peer_list_head, peer_list_tail, peer); | ||
69 | } | ||
70 | |||
71 | |||
72 | /** | ||
73 | * Frees all peers | ||
74 | */ | ||
75 | void | ||
76 | GNUNET_TESTBED_cleanup_peers_ (void) | ||
77 | { | ||
78 | struct GNUNET_TESTBED_Peer *peer; | ||
79 | |||
80 | while (NULL != (peer = peer_list_head)) | ||
81 | { | ||
82 | GNUNET_TESTBED_peer_deregister_ (peer); | ||
83 | GNUNET_free (peer); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | |||
88 | /** | ||
89 | * Function to call to start a peer_create type operation once all | ||
90 | * queues the operation is part of declare that the | ||
91 | * operation can be activated. | ||
92 | * | ||
93 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
94 | */ | ||
95 | static void | ||
96 | opstart_peer_create (void *cls) | ||
97 | { | ||
98 | struct OperationContext *opc = cls; | ||
99 | struct PeerCreateData *data = opc->data; | ||
100 | struct GNUNET_TESTBED_PeerCreateMessage *msg; | ||
101 | struct GNUNET_MQ_Envelope *env; | ||
102 | char *config; | ||
103 | char *xconfig; | ||
104 | size_t c_size; | ||
105 | size_t xc_size; | ||
106 | |||
107 | GNUNET_assert (OP_PEER_CREATE == opc->type); | ||
108 | GNUNET_assert (NULL != data); | ||
109 | GNUNET_assert (NULL != data->peer); | ||
110 | opc->state = OPC_STATE_STARTED; | ||
111 | config = GNUNET_CONFIGURATION_serialize (data->cfg, | ||
112 | &c_size); | ||
113 | xc_size = GNUNET_TESTBED_compress_config_ (config, | ||
114 | c_size, | ||
115 | &xconfig); | ||
116 | GNUNET_free (config); | ||
117 | env = GNUNET_MQ_msg_extra (msg, | ||
118 | xc_size, | ||
119 | GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER); | ||
120 | msg->operation_id = GNUNET_htonll (opc->id); | ||
121 | msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->peer->host)); | ||
122 | msg->peer_id = htonl (data->peer->unique_id); | ||
123 | msg->config_size = htons ((uint16_t) c_size); | ||
124 | GNUNET_memcpy (&msg[1], | ||
125 | xconfig, | ||
126 | xc_size); | ||
127 | GNUNET_MQ_send (opc->c->mq, | ||
128 | env); | ||
129 | GNUNET_free (xconfig); | ||
130 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | ||
131 | } | ||
132 | |||
133 | |||
134 | /** | ||
135 | * Callback which will be called when peer_create type operation is released | ||
136 | * | ||
137 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
138 | */ | ||
139 | static void | ||
140 | oprelease_peer_create (void *cls) | ||
141 | { | ||
142 | struct OperationContext *opc = cls; | ||
143 | |||
144 | switch (opc->state) | ||
145 | { | ||
146 | case OPC_STATE_STARTED: | ||
147 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | ||
148 | |||
149 | /* No break we continue flow */ | ||
150 | case OPC_STATE_INIT: | ||
151 | GNUNET_free (((struct PeerCreateData *) opc->data)->peer); | ||
152 | GNUNET_free (opc->data); | ||
153 | break; | ||
154 | |||
155 | case OPC_STATE_FINISHED: | ||
156 | break; | ||
157 | } | ||
158 | GNUNET_free (opc); | ||
159 | } | ||
160 | |||
161 | |||
162 | /** | ||
163 | * Function called when a peer destroy operation is ready | ||
164 | * | ||
165 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
166 | */ | ||
167 | static void | ||
168 | opstart_peer_destroy (void *cls) | ||
169 | { | ||
170 | struct OperationContext *opc = cls; | ||
171 | struct GNUNET_TESTBED_Peer *peer = opc->data; | ||
172 | struct GNUNET_TESTBED_PeerDestroyMessage *msg; | ||
173 | struct GNUNET_MQ_Envelope *env; | ||
174 | |||
175 | GNUNET_assert (OP_PEER_DESTROY == opc->type); | ||
176 | GNUNET_assert (NULL != peer); | ||
177 | opc->state = OPC_STATE_STARTED; | ||
178 | env = GNUNET_MQ_msg (msg, | ||
179 | GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER); | ||
180 | msg->peer_id = htonl (peer->unique_id); | ||
181 | msg->operation_id = GNUNET_htonll (opc->id); | ||
182 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | ||
183 | GNUNET_MQ_send (peer->controller->mq, | ||
184 | env); | ||
185 | } | ||
186 | |||
187 | |||
188 | /** | ||
189 | * Callback which will be called when peer_create type operation is released | ||
190 | * | ||
191 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
192 | */ | ||
193 | static void | ||
194 | oprelease_peer_destroy (void *cls) | ||
195 | { | ||
196 | struct OperationContext *opc = cls; | ||
197 | |||
198 | switch (opc->state) | ||
199 | { | ||
200 | case OPC_STATE_STARTED: | ||
201 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | ||
202 | |||
203 | /* no break; continue */ | ||
204 | case OPC_STATE_INIT: | ||
205 | break; | ||
206 | |||
207 | case OPC_STATE_FINISHED: | ||
208 | break; | ||
209 | } | ||
210 | GNUNET_free (opc); | ||
211 | } | ||
212 | |||
213 | |||
214 | /** | ||
215 | * Function called when a peer start operation is ready | ||
216 | * | ||
217 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
218 | */ | ||
219 | static void | ||
220 | opstart_peer_start (void *cls) | ||
221 | { | ||
222 | struct OperationContext *opc = cls; | ||
223 | struct GNUNET_TESTBED_PeerStartMessage *msg; | ||
224 | struct GNUNET_MQ_Envelope *env; | ||
225 | struct PeerEventData *data; | ||
226 | struct GNUNET_TESTBED_Peer *peer; | ||
227 | |||
228 | GNUNET_assert (OP_PEER_START == opc->type); | ||
229 | GNUNET_assert (NULL != (data = opc->data)); | ||
230 | GNUNET_assert (NULL != (peer = data->peer)); | ||
231 | GNUNET_assert ((TESTBED_PS_CREATED == peer->state) || (TESTBED_PS_STOPPED == | ||
232 | peer->state)); | ||
233 | opc->state = OPC_STATE_STARTED; | ||
234 | env = GNUNET_MQ_msg (msg, | ||
235 | GNUNET_MESSAGE_TYPE_TESTBED_START_PEER); | ||
236 | msg->peer_id = htonl (peer->unique_id); | ||
237 | msg->operation_id = GNUNET_htonll (opc->id); | ||
238 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | ||
239 | GNUNET_MQ_send (peer->controller->mq, | ||
240 | env); | ||
241 | } | ||
242 | |||
243 | |||
244 | /** | ||
245 | * Callback which will be called when peer start type operation is released | ||
246 | * | ||
247 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
248 | */ | ||
249 | static void | ||
250 | oprelease_peer_start (void *cls) | ||
251 | { | ||
252 | struct OperationContext *opc = cls; | ||
253 | |||
254 | switch (opc->state) | ||
255 | { | ||
256 | case OPC_STATE_STARTED: | ||
257 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | ||
258 | |||
259 | /* no break; continue */ | ||
260 | case OPC_STATE_INIT: | ||
261 | GNUNET_free (opc->data); | ||
262 | break; | ||
263 | |||
264 | case OPC_STATE_FINISHED: | ||
265 | break; | ||
266 | } | ||
267 | GNUNET_free (opc); | ||
268 | } | ||
269 | |||
270 | |||
271 | /** | ||
272 | * Function called when a peer stop operation is ready | ||
273 | * | ||
274 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
275 | */ | ||
276 | static void | ||
277 | opstart_peer_stop (void *cls) | ||
278 | { | ||
279 | struct OperationContext *opc = cls; | ||
280 | struct GNUNET_TESTBED_PeerStopMessage *msg; | ||
281 | struct PeerEventData *data; | ||
282 | struct GNUNET_TESTBED_Peer *peer; | ||
283 | struct GNUNET_MQ_Envelope *env; | ||
284 | |||
285 | GNUNET_assert (NULL != (data = opc->data)); | ||
286 | GNUNET_assert (NULL != (peer = data->peer)); | ||
287 | GNUNET_assert (TESTBED_PS_STARTED == peer->state); | ||
288 | opc->state = OPC_STATE_STARTED; | ||
289 | env = GNUNET_MQ_msg (msg, | ||
290 | GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER); | ||
291 | msg->peer_id = htonl (peer->unique_id); | ||
292 | msg->operation_id = GNUNET_htonll (opc->id); | ||
293 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | ||
294 | GNUNET_MQ_send (peer->controller->mq, | ||
295 | env); | ||
296 | } | ||
297 | |||
298 | |||
299 | /** | ||
300 | * Callback which will be called when peer stop type operation is released | ||
301 | * | ||
302 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
303 | */ | ||
304 | static void | ||
305 | oprelease_peer_stop (void *cls) | ||
306 | { | ||
307 | struct OperationContext *opc = cls; | ||
308 | |||
309 | switch (opc->state) | ||
310 | { | ||
311 | case OPC_STATE_STARTED: | ||
312 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | ||
313 | |||
314 | /* no break; continue */ | ||
315 | case OPC_STATE_INIT: | ||
316 | GNUNET_free (opc->data); | ||
317 | break; | ||
318 | |||
319 | case OPC_STATE_FINISHED: | ||
320 | break; | ||
321 | } | ||
322 | GNUNET_free (opc); | ||
323 | } | ||
324 | |||
325 | |||
326 | /** | ||
327 | * Generate PeerGetConfigurationMessage | ||
328 | * | ||
329 | * @param peer_id the id of the peer whose information we have to get | ||
330 | * @param operation_id the ip of the operation that should be represented in the | ||
331 | * message | ||
332 | * @return the PeerGetConfigurationMessage | ||
333 | */ | ||
334 | struct GNUNET_TESTBED_PeerGetConfigurationMessage * | ||
335 | GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id, | ||
336 | uint64_t operation_id) | ||
337 | { | ||
338 | struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; | ||
339 | |||
340 | msg = | ||
341 | GNUNET_malloc (sizeof | ||
342 | (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); | ||
343 | msg->header.size = | ||
344 | htons (sizeof(struct GNUNET_TESTBED_PeerGetConfigurationMessage)); | ||
345 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION); | ||
346 | msg->peer_id = htonl (peer_id); | ||
347 | msg->operation_id = GNUNET_htonll (operation_id); | ||
348 | return msg; | ||
349 | } | ||
350 | |||
351 | |||
352 | /** | ||
353 | * Function called when a peer get information operation is ready | ||
354 | * | ||
355 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
356 | */ | ||
357 | static void | ||
358 | opstart_peer_getinfo (void *cls) | ||
359 | { | ||
360 | struct OperationContext *opc = cls; | ||
361 | struct PeerInfoData *data = opc->data; | ||
362 | struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; | ||
363 | |||
364 | GNUNET_assert (NULL != data); | ||
365 | opc->state = OPC_STATE_STARTED; | ||
366 | msg = | ||
367 | GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id, | ||
368 | opc->id); | ||
369 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | ||
370 | GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); | ||
371 | } | ||
372 | |||
373 | |||
374 | /** | ||
375 | * Callback which will be called when peer stop type operation is released | ||
376 | * | ||
377 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
378 | */ | ||
379 | static void | ||
380 | oprelease_peer_getinfo (void *cls) | ||
381 | { | ||
382 | struct OperationContext *opc = cls; | ||
383 | struct GNUNET_TESTBED_PeerInformation *data; | ||
384 | |||
385 | switch (opc->state) | ||
386 | { | ||
387 | case OPC_STATE_STARTED: | ||
388 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | ||
389 | |||
390 | /* no break; continue */ | ||
391 | case OPC_STATE_INIT: | ||
392 | GNUNET_free (opc->data); | ||
393 | break; | ||
394 | |||
395 | case OPC_STATE_FINISHED: | ||
396 | data = opc->data; | ||
397 | GNUNET_assert (NULL != data); | ||
398 | switch (data->pit) | ||
399 | { | ||
400 | case GNUNET_TESTBED_PIT_CONFIGURATION: | ||
401 | if (NULL != data->result.cfg) | ||
402 | GNUNET_CONFIGURATION_destroy (data->result.cfg); | ||
403 | break; | ||
404 | |||
405 | case GNUNET_TESTBED_PIT_IDENTITY: | ||
406 | GNUNET_free (data->result.id); | ||
407 | break; | ||
408 | |||
409 | default: | ||
410 | GNUNET_assert (0); /* We should never reach here */ | ||
411 | } | ||
412 | GNUNET_free (data); | ||
413 | break; | ||
414 | } | ||
415 | GNUNET_free (opc); | ||
416 | } | ||
417 | |||
418 | |||
419 | /** | ||
420 | * Function called when a overlay connect operation is ready | ||
421 | * | ||
422 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
423 | */ | ||
424 | static void | ||
425 | opstart_overlay_connect (void *cls) | ||
426 | { | ||
427 | struct OperationContext *opc = cls; | ||
428 | struct GNUNET_MQ_Envelope *env; | ||
429 | struct GNUNET_TESTBED_OverlayConnectMessage *msg; | ||
430 | struct OverlayConnectData *data; | ||
431 | |||
432 | opc->state = OPC_STATE_STARTED; | ||
433 | data = opc->data; | ||
434 | GNUNET_assert (NULL != data); | ||
435 | env = GNUNET_MQ_msg (msg, | ||
436 | GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT); | ||
437 | msg->peer1 = htonl (data->p1->unique_id); | ||
438 | msg->peer2 = htonl (data->p2->unique_id); | ||
439 | msg->operation_id = GNUNET_htonll (opc->id); | ||
440 | msg->peer2_host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->p2->host)); | ||
441 | GNUNET_TESTBED_insert_opc_ (opc->c, | ||
442 | opc); | ||
443 | GNUNET_MQ_send (opc->c->mq, | ||
444 | env); | ||
445 | } | ||
446 | |||
447 | |||
448 | /** | ||
449 | * Callback which will be called when overlay connect operation is released | ||
450 | * | ||
451 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
452 | */ | ||
453 | static void | ||
454 | oprelease_overlay_connect (void *cls) | ||
455 | { | ||
456 | struct OperationContext *opc = cls; | ||
457 | struct OverlayConnectData *data; | ||
458 | |||
459 | data = opc->data; | ||
460 | switch (opc->state) | ||
461 | { | ||
462 | case OPC_STATE_INIT: | ||
463 | break; | ||
464 | |||
465 | case OPC_STATE_STARTED: | ||
466 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | ||
467 | break; | ||
468 | |||
469 | case OPC_STATE_FINISHED: | ||
470 | break; | ||
471 | } | ||
472 | GNUNET_free (data); | ||
473 | GNUNET_free (opc); | ||
474 | } | ||
475 | |||
476 | |||
477 | /** | ||
478 | * Function called when a peer reconfigure operation is ready | ||
479 | * | ||
480 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
481 | */ | ||
482 | static void | ||
483 | opstart_peer_reconfigure (void *cls) | ||
484 | { | ||
485 | struct OperationContext *opc = cls; | ||
486 | struct PeerReconfigureData *data = opc->data; | ||
487 | struct GNUNET_MQ_Envelope *env; | ||
488 | struct GNUNET_TESTBED_PeerReconfigureMessage *msg; | ||
489 | char *xconfig; | ||
490 | size_t xc_size; | ||
491 | |||
492 | opc->state = OPC_STATE_STARTED; | ||
493 | GNUNET_assert (NULL != data); | ||
494 | xc_size = GNUNET_TESTBED_compress_config_ (data->config, | ||
495 | data->cfg_size, | ||
496 | &xconfig); | ||
497 | GNUNET_free (data->config); | ||
498 | data->config = NULL; | ||
499 | GNUNET_assert (xc_size < UINT16_MAX - sizeof(*msg)); | ||
500 | env = GNUNET_MQ_msg_extra (msg, | ||
501 | xc_size, | ||
502 | GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER); | ||
503 | msg->peer_id = htonl (data->peer->unique_id); | ||
504 | msg->operation_id = GNUNET_htonll (opc->id); | ||
505 | msg->config_size = htons (data->cfg_size); | ||
506 | GNUNET_memcpy (&msg[1], | ||
507 | xconfig, | ||
508 | xc_size); | ||
509 | GNUNET_free (xconfig); | ||
510 | GNUNET_free (data); | ||
511 | opc->data = NULL; | ||
512 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | ||
513 | GNUNET_MQ_send (opc->c->mq, | ||
514 | env); | ||
515 | } | ||
516 | |||
517 | |||
518 | /** | ||
519 | * Callback which will be called when a peer reconfigure operation is released | ||
520 | * | ||
521 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
522 | */ | ||
523 | static void | ||
524 | oprelease_peer_reconfigure (void *cls) | ||
525 | { | ||
526 | struct OperationContext *opc = cls; | ||
527 | struct PeerReconfigureData *data = opc->data; | ||
528 | |||
529 | switch (opc->state) | ||
530 | { | ||
531 | case OPC_STATE_INIT: | ||
532 | GNUNET_free (data->config); | ||
533 | GNUNET_free (data); | ||
534 | break; | ||
535 | |||
536 | case OPC_STATE_STARTED: | ||
537 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | ||
538 | break; | ||
539 | |||
540 | case OPC_STATE_FINISHED: | ||
541 | break; | ||
542 | } | ||
543 | GNUNET_free (opc); | ||
544 | } | ||
545 | |||
546 | |||
547 | /** | ||
548 | * Lookup a peer by ID. | ||
549 | * | ||
550 | * @param id global peer ID assigned to the peer | ||
551 | * @return handle to the host, NULL on error | ||
552 | */ | ||
553 | struct GNUNET_TESTBED_Peer * | ||
554 | GNUNET_TESTBED_peer_lookup_by_id_ (uint32_t id) | ||
555 | { | ||
556 | GNUNET_break (0); | ||
557 | return NULL; | ||
558 | } | ||
559 | |||
560 | |||
561 | /** | ||
562 | * Create the given peer at the specified host using the given | ||
563 | * controller. If the given controller is not running on the target | ||
564 | * host, it should find or create a controller at the target host and | ||
565 | * delegate creating the peer. Explicit delegation paths can be setup | ||
566 | * using 'GNUNET_TESTBED_controller_link'. If no explicit delegation | ||
567 | * path exists, a direct link with a subordinate controller is setup | ||
568 | * for the first delegated peer to a particular host; the subordinate | ||
569 | * controller is then destroyed once the last peer that was delegated | ||
570 | * to the remote host is stopped. | ||
571 | * | ||
572 | * Creating the peer only creates the handle to manipulate and further | ||
573 | * configure the peer; use "GNUNET_TESTBED_peer_start" and | ||
574 | * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's | ||
575 | * processes. | ||
576 | * | ||
577 | * Note that the given configuration will be adjusted by the | ||
578 | * controller to avoid port/path conflicts with other peers. | ||
579 | * The "final" configuration can be obtained using | ||
580 | * 'GNUNET_TESTBED_peer_get_information'. | ||
581 | * | ||
582 | * @param controller controller process to use | ||
583 | * @param host host to run the peer on; cannot be NULL | ||
584 | * @param cfg Template configuration to use for the peer. Should exist until | ||
585 | * operation is cancelled or GNUNET_TESTBED_operation_done() is called | ||
586 | * @param cb the callback to call when the peer has been created | ||
587 | * @param cls the closure to the above callback | ||
588 | * @return the operation handle | ||
589 | */ | ||
590 | struct GNUNET_TESTBED_Operation * | ||
591 | GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller, | ||
592 | struct GNUNET_TESTBED_Host *host, | ||
593 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
594 | GNUNET_TESTBED_PeerCreateCallback cb, void *cls) | ||
595 | { | ||
596 | struct GNUNET_TESTBED_Peer *peer; | ||
597 | struct PeerCreateData *data; | ||
598 | struct OperationContext *opc; | ||
599 | static uint32_t id_gen; | ||
600 | |||
601 | peer = GNUNET_new (struct GNUNET_TESTBED_Peer); | ||
602 | peer->controller = controller; | ||
603 | peer->host = host; | ||
604 | peer->unique_id = id_gen++; | ||
605 | peer->state = TESTBED_PS_INVALID; | ||
606 | data = GNUNET_new (struct PeerCreateData); | ||
607 | data->host = host; | ||
608 | data->cfg = cfg; | ||
609 | data->cb = cb; | ||
610 | data->cls = cls; | ||
611 | data->peer = peer; | ||
612 | opc = GNUNET_new (struct OperationContext); | ||
613 | opc->c = controller; | ||
614 | opc->data = data; | ||
615 | opc->id = GNUNET_TESTBED_get_next_op_id (controller); | ||
616 | opc->type = OP_PEER_CREATE; | ||
617 | opc->op = | ||
618 | GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_create, | ||
619 | &oprelease_peer_create); | ||
620 | GNUNET_TESTBED_operation_queue_insert_ (controller->opq_parallel_operations, | ||
621 | opc->op); | ||
622 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | ||
623 | return opc->op; | ||
624 | } | ||
625 | |||
626 | |||
627 | /** | ||
628 | * Start the given peer. | ||
629 | * | ||
630 | * @param op_cls the closure for this operation; will be set in | ||
631 | * event->details.operation_finished.op_cls when this operation fails. | ||
632 | * @param peer peer to start | ||
633 | * @param pcc function to call upon completion | ||
634 | * @param pcc_cls closure for 'pcc' | ||
635 | * @return handle to the operation | ||
636 | */ | ||
637 | struct GNUNET_TESTBED_Operation * | ||
638 | GNUNET_TESTBED_peer_start (void *op_cls, struct GNUNET_TESTBED_Peer *peer, | ||
639 | GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls) | ||
640 | { | ||
641 | struct OperationContext *opc; | ||
642 | struct PeerEventData *data; | ||
643 | |||
644 | data = GNUNET_new (struct PeerEventData); | ||
645 | data->peer = peer; | ||
646 | data->pcc = pcc; | ||
647 | data->pcc_cls = pcc_cls; | ||
648 | opc = GNUNET_new (struct OperationContext); | ||
649 | opc->c = peer->controller; | ||
650 | opc->data = data; | ||
651 | opc->op_cls = op_cls; | ||
652 | opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); | ||
653 | opc->type = OP_PEER_START; | ||
654 | opc->op = | ||
655 | GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_start, | ||
656 | &oprelease_peer_start); | ||
657 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, | ||
658 | opc->op); | ||
659 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | ||
660 | return opc->op; | ||
661 | } | ||
662 | |||
663 | |||
664 | struct GNUNET_TESTBED_Operation * | ||
665 | GNUNET_TESTBED_peer_stop (void *op_cls, | ||
666 | struct GNUNET_TESTBED_Peer *peer, | ||
667 | GNUNET_TESTBED_PeerChurnCallback pcc, void *pcc_cls) | ||
668 | { | ||
669 | struct OperationContext *opc; | ||
670 | struct PeerEventData *data; | ||
671 | |||
672 | data = GNUNET_new (struct PeerEventData); | ||
673 | data->peer = peer; | ||
674 | data->pcc = pcc; | ||
675 | data->pcc_cls = pcc_cls; | ||
676 | opc = GNUNET_new (struct OperationContext); | ||
677 | opc->c = peer->controller; | ||
678 | opc->data = data; | ||
679 | opc->op_cls = op_cls; | ||
680 | opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); | ||
681 | opc->type = OP_PEER_STOP; | ||
682 | opc->op = | ||
683 | GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_stop, | ||
684 | &oprelease_peer_stop); | ||
685 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, | ||
686 | opc->op); | ||
687 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | ||
688 | return opc->op; | ||
689 | } | ||
690 | |||
691 | |||
692 | struct GNUNET_TESTBED_Operation * | ||
693 | GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, | ||
694 | enum GNUNET_TESTBED_PeerInformationType | ||
695 | pit, GNUNET_TESTBED_PeerInfoCallback cb, | ||
696 | void *cb_cls) | ||
697 | { | ||
698 | struct OperationContext *opc; | ||
699 | struct PeerInfoData *data; | ||
700 | |||
701 | GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC != pit); | ||
702 | GNUNET_assert (NULL != cb); | ||
703 | data = GNUNET_new (struct PeerInfoData); | ||
704 | data->peer = peer; | ||
705 | data->pit = pit; | ||
706 | data->cb = cb; | ||
707 | data->cb_cls = cb_cls; | ||
708 | opc = GNUNET_new (struct OperationContext); | ||
709 | opc->c = peer->controller; | ||
710 | opc->data = data; | ||
711 | opc->type = OP_PEER_INFO; | ||
712 | opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); | ||
713 | opc->op = | ||
714 | GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_getinfo, | ||
715 | &oprelease_peer_getinfo); | ||
716 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, | ||
717 | opc->op); | ||
718 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | ||
719 | return opc->op; | ||
720 | } | ||
721 | |||
722 | |||
723 | /** | ||
724 | * Change peer configuration. Must only be called while the | ||
725 | * peer is stopped. Ports and paths cannot be changed this | ||
726 | * way. | ||
727 | * | ||
728 | * @param peer peer to change configuration for | ||
729 | * @param cfg new configuration (differences to existing | ||
730 | * configuration only) | ||
731 | * @return handle to the operation | ||
732 | */ | ||
733 | struct GNUNET_TESTBED_Operation * | ||
734 | GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer, | ||
735 | const struct | ||
736 | GNUNET_CONFIGURATION_Handle *cfg) | ||
737 | { | ||
738 | struct OperationContext *opc; | ||
739 | struct PeerReconfigureData *data; | ||
740 | size_t csize; | ||
741 | |||
742 | data = GNUNET_new (struct PeerReconfigureData); | ||
743 | data->peer = peer; | ||
744 | data->config = GNUNET_CONFIGURATION_serialize (cfg, &csize); | ||
745 | if (NULL == data->config) | ||
746 | { | ||
747 | GNUNET_free (data); | ||
748 | return NULL; | ||
749 | } | ||
750 | if (csize > UINT16_MAX) | ||
751 | { | ||
752 | GNUNET_break (0); | ||
753 | GNUNET_free (data->config); | ||
754 | GNUNET_free (data); | ||
755 | return NULL; | ||
756 | } | ||
757 | data->cfg_size = (uint16_t) csize; | ||
758 | opc = GNUNET_new (struct OperationContext); | ||
759 | opc->c = peer->controller; | ||
760 | opc->data = data; | ||
761 | opc->type = OP_PEER_RECONFIGURE; | ||
762 | opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); | ||
763 | opc->op = | ||
764 | GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_reconfigure, | ||
765 | &oprelease_peer_reconfigure); | ||
766 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, | ||
767 | opc->op); | ||
768 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | ||
769 | return opc->op; | ||
770 | } | ||
771 | |||
772 | |||
773 | /** | ||
774 | * Destroy the given peer; the peer should have been | ||
775 | * stopped first (if it was started). | ||
776 | * | ||
777 | * @param peer peer to stop | ||
778 | * @return handle to the operation | ||
779 | */ | ||
780 | struct GNUNET_TESTBED_Operation * | ||
781 | GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer) | ||
782 | { | ||
783 | struct OperationContext *opc; | ||
784 | |||
785 | opc = GNUNET_new (struct OperationContext); | ||
786 | opc->data = peer; | ||
787 | opc->c = peer->controller; | ||
788 | opc->id = GNUNET_TESTBED_get_next_op_id (peer->controller); | ||
789 | opc->type = OP_PEER_DESTROY; | ||
790 | opc->op = | ||
791 | GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_destroy, | ||
792 | &oprelease_peer_destroy); | ||
793 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, | ||
794 | opc->op); | ||
795 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | ||
796 | return opc->op; | ||
797 | } | ||
798 | |||
799 | |||
800 | /** | ||
801 | * Manipulate the P2P underlay topology by configuring a link | ||
802 | * between two peers. | ||
803 | * | ||
804 | * @param op_cls closure argument to give with the operation event | ||
805 | * @param p1 first peer | ||
806 | * @param p2 second peer | ||
807 | * @param co option to change | ||
808 | * @param ... option-specific values | ||
809 | * @return handle to the operation, NULL if configuring the link at this | ||
810 | * time is not allowed | ||
811 | */ | ||
812 | struct GNUNET_TESTBED_Operation * | ||
813 | GNUNET_TESTBED_underlay_configure_link (void *op_cls, | ||
814 | struct GNUNET_TESTBED_Peer *p1, | ||
815 | struct GNUNET_TESTBED_Peer *p2, | ||
816 | enum GNUNET_TESTBED_ConnectOption co, | ||
817 | ...) | ||
818 | { | ||
819 | GNUNET_break (0); | ||
820 | return NULL; | ||
821 | } | ||
822 | |||
823 | |||
824 | struct GNUNET_TESTBED_Operation * | ||
825 | GNUNET_TESTBED_overlay_connect (void *op_cls, | ||
826 | GNUNET_TESTBED_OperationCompletionCallback cb, | ||
827 | void *cb_cls, struct GNUNET_TESTBED_Peer *p1, | ||
828 | struct GNUNET_TESTBED_Peer *p2) | ||
829 | { | ||
830 | struct OperationContext *opc; | ||
831 | struct OverlayConnectData *data; | ||
832 | |||
833 | GNUNET_assert ((TESTBED_PS_STARTED == p1->state) && (TESTBED_PS_STARTED == | ||
834 | p2->state)); | ||
835 | data = GNUNET_new (struct OverlayConnectData); | ||
836 | data->p1 = p1; | ||
837 | data->p2 = p2; | ||
838 | data->cb = cb; | ||
839 | data->cb_cls = cb_cls; | ||
840 | opc = GNUNET_new (struct OperationContext); | ||
841 | opc->data = data; | ||
842 | opc->c = p1->controller; | ||
843 | opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); | ||
844 | opc->type = OP_OVERLAY_CONNECT; | ||
845 | opc->op_cls = op_cls; | ||
846 | opc->op = | ||
847 | GNUNET_TESTBED_operation_create_ (opc, &opstart_overlay_connect, | ||
848 | &oprelease_overlay_connect); | ||
849 | GNUNET_TESTBED_host_queue_oc_ (p1->host, opc->op); | ||
850 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | ||
851 | return opc->op; | ||
852 | } | ||
853 | |||
854 | |||
855 | /** | ||
856 | * Function called when a peer manage service operation is ready | ||
857 | * | ||
858 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
859 | */ | ||
860 | static void | ||
861 | opstart_manage_service (void *cls) | ||
862 | { | ||
863 | struct OperationContext *opc = cls; | ||
864 | struct ManageServiceData *data = opc->data; | ||
865 | struct GNUNET_MQ_Envelope *env; | ||
866 | struct GNUNET_TESTBED_ManagePeerServiceMessage *msg; | ||
867 | size_t xlen; | ||
868 | |||
869 | GNUNET_assert (NULL != data); | ||
870 | xlen = data->msize - sizeof(struct GNUNET_TESTBED_ManagePeerServiceMessage); | ||
871 | env = GNUNET_MQ_msg_extra (msg, | ||
872 | xlen, | ||
873 | GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE); | ||
874 | msg->peer_id = htonl (data->peer->unique_id); | ||
875 | msg->operation_id = GNUNET_htonll (opc->id); | ||
876 | msg->start = (uint8_t) data->start; | ||
877 | GNUNET_memcpy (&msg[1], | ||
878 | data->service_name, | ||
879 | xlen); | ||
880 | GNUNET_free (data->service_name); | ||
881 | data->service_name = NULL; | ||
882 | opc->state = OPC_STATE_STARTED; | ||
883 | GNUNET_TESTBED_insert_opc_ (opc->c, opc); | ||
884 | GNUNET_MQ_send (opc->c->mq, | ||
885 | env); | ||
886 | } | ||
887 | |||
888 | |||
889 | /** | ||
890 | * Callback which will be called when peer manage server operation is released | ||
891 | * | ||
892 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
893 | */ | ||
894 | static void | ||
895 | oprelease_manage_service (void *cls) | ||
896 | { | ||
897 | struct OperationContext *opc = cls; | ||
898 | struct ManageServiceData *data; | ||
899 | |||
900 | data = opc->data; | ||
901 | switch (opc->state) | ||
902 | { | ||
903 | case OPC_STATE_STARTED: | ||
904 | GNUNET_TESTBED_remove_opc_ (opc->c, opc); | ||
905 | break; | ||
906 | |||
907 | case OPC_STATE_INIT: | ||
908 | GNUNET_assert (NULL != data); | ||
909 | GNUNET_free (data->service_name); | ||
910 | break; | ||
911 | |||
912 | case OPC_STATE_FINISHED: | ||
913 | break; | ||
914 | } | ||
915 | GNUNET_free (data); | ||
916 | GNUNET_free (opc); | ||
917 | } | ||
918 | |||
919 | |||
920 | struct GNUNET_TESTBED_Operation * | ||
921 | GNUNET_TESTBED_peer_manage_service (void *op_cls, | ||
922 | struct GNUNET_TESTBED_Peer *peer, | ||
923 | const char *service_name, | ||
924 | GNUNET_TESTBED_OperationCompletionCallback | ||
925 | cb, | ||
926 | void *cb_cls, | ||
927 | unsigned int start) | ||
928 | { | ||
929 | struct ManageServiceData *data; | ||
930 | struct OperationContext *opc; | ||
931 | size_t msize; | ||
932 | |||
933 | GNUNET_assert (TESTBED_PS_STARTED == peer->state); /* peer is not running? */ | ||
934 | msize = strlen (service_name) + 1; | ||
935 | msize += sizeof(struct GNUNET_TESTBED_ManagePeerServiceMessage); | ||
936 | if (GNUNET_MAX_MESSAGE_SIZE < msize) | ||
937 | return NULL; | ||
938 | data = GNUNET_new (struct ManageServiceData); | ||
939 | data->cb = cb; | ||
940 | data->cb_cls = cb_cls; | ||
941 | data->peer = peer; | ||
942 | data->service_name = GNUNET_strdup (service_name); | ||
943 | data->start = start; | ||
944 | data->msize = (uint16_t) msize; | ||
945 | opc = GNUNET_new (struct OperationContext); | ||
946 | opc->data = data; | ||
947 | opc->c = peer->controller; | ||
948 | opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); | ||
949 | opc->type = OP_MANAGE_SERVICE; | ||
950 | opc->op_cls = op_cls; | ||
951 | opc->op = | ||
952 | GNUNET_TESTBED_operation_create_ (opc, &opstart_manage_service, | ||
953 | &oprelease_manage_service); | ||
954 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, | ||
955 | opc->op); | ||
956 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | ||
957 | return opc->op; | ||
958 | } | ||
959 | |||
960 | |||
961 | /* end of testbed_api_peers.c */ | ||