- relaxed to accommodate overlay linking timeouts
[oweals/gnunet.git] / src / testbed / testbed_api_peers.c
1 /*
2       This file is part of GNUnet
3       (C) 2008--2012 Christian Grothoff (and other contributing authors)
4
5       GNUnet is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 3, or (at your
8       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       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18       Boston, MA 02111-1307, USA.
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  * Function to call to start a peer_create type operation once all
38  * queues the operation is part of declare that the
39  * operation can be activated.
40  *
41  * @param cls the closure from GNUNET_TESTBED_operation_create_()
42  */
43 static void
44 opstart_peer_create (void *cls)
45 {
46   struct OperationContext *opc = cls;
47   struct PeerCreateData *data;
48   struct GNUNET_TESTBED_PeerCreateMessage *msg;
49   char *config;
50   char *xconfig;
51   size_t c_size;
52   size_t xc_size;
53   uint16_t msize;
54
55   GNUNET_assert (OP_PEER_CREATE == opc->type);
56   data = opc->data;
57   GNUNET_assert (NULL != data);
58   GNUNET_assert (NULL != data->peer);
59   opc->state = OPC_STATE_STARTED;
60   config = GNUNET_CONFIGURATION_serialize (data->cfg, &c_size);
61   xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
62   GNUNET_free (config);
63   msize = xc_size + sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
64   msg = GNUNET_realloc (xconfig, msize);
65   memmove (&msg[1], msg, xc_size);
66   msg->header.size = htons (msize);
67   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER);
68   msg->operation_id = GNUNET_htonll (opc->id);
69   msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->peer->host));
70   msg->peer_id = htonl (data->peer->unique_id);
71   msg->config_size = htonl (c_size);
72   GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
73   GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
74 }
75
76
77 /**
78  * Callback which will be called when peer_create type operation is released
79  *
80  * @param cls the closure from GNUNET_TESTBED_operation_create_()
81  */
82 static void
83 oprelease_peer_create (void *cls)
84 {
85   struct OperationContext *opc = cls;
86
87   if (OPC_STATE_FINISHED != opc->state)
88   {
89     GNUNET_free (((struct PeerCreateData *) opc->data)->peer);
90     GNUNET_free (opc->data);
91     GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
92   }
93   GNUNET_free (opc);
94 }
95
96
97 /**
98  * Function called when a peer destroy operation is ready
99  *
100  * @param cls the closure from GNUNET_TESTBED_operation_create_()
101  */
102 static void
103 opstart_peer_destroy (void *cls)
104 {
105   struct OperationContext *opc = cls;
106   struct GNUNET_TESTBED_Peer *peer;
107   struct GNUNET_TESTBED_PeerDestroyMessage *msg;
108
109   GNUNET_assert (OP_PEER_DESTROY == opc->type);
110   peer = opc->data;
111   GNUNET_assert (NULL != peer);
112   opc->state = OPC_STATE_STARTED;
113   msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
114   msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
115   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER);
116   msg->peer_id = htonl (peer->unique_id);
117   msg->operation_id = GNUNET_htonll (opc->id);
118   GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
119   GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
120 }
121
122
123 /**
124  * Callback which will be called when peer_create type operation is released
125  *
126  * @param cls the closure from GNUNET_TESTBED_operation_create_()
127  */
128 static void
129 oprelease_peer_destroy (void *cls)
130 {
131   struct OperationContext *opc = cls;
132
133   if (OPC_STATE_FINISHED != opc->state)
134     GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
135   GNUNET_free (opc);
136 }
137
138
139 /**
140  * Function called when a peer start operation is ready
141  *
142  * @param cls the closure from GNUNET_TESTBED_operation_create_()
143  */
144 static void
145 opstart_peer_start (void *cls)
146 {
147   struct OperationContext *opc = cls;
148   struct GNUNET_TESTBED_PeerStartMessage *msg;
149   struct PeerEventData *data;
150   struct GNUNET_TESTBED_Peer *peer;
151
152   GNUNET_assert (OP_PEER_START == opc->type);
153   GNUNET_assert (NULL != opc->data);
154   data = opc->data;
155   GNUNET_assert (NULL != data->peer);
156   peer = data->peer;
157   GNUNET_assert ((PS_CREATED == peer->state) || (PS_STOPPED == peer->state));
158   opc->state = OPC_STATE_STARTED;
159   msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStartMessage));
160   msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStartMessage));
161   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER);
162   msg->peer_id = htonl (peer->unique_id);
163   msg->operation_id = GNUNET_htonll (opc->id);
164   GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
165   GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
166 }
167
168
169 /**
170  * Callback which will be called when peer start type operation is released
171  *
172  * @param cls the closure from GNUNET_TESTBED_operation_create_()
173  */
174 static void
175 oprelease_peer_start (void *cls)
176 {
177   struct OperationContext *opc = cls;
178
179   if (OPC_STATE_FINISHED != opc->state)
180   {
181     GNUNET_free (opc->data);
182     GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
183   }
184   GNUNET_free (opc);
185 }
186
187
188 /**
189  * Function called when a peer stop operation is ready
190  *
191  * @param cls the closure from GNUNET_TESTBED_operation_create_()
192  */
193 static void
194 opstart_peer_stop (void *cls)
195 {
196   struct OperationContext *opc = cls;
197   struct GNUNET_TESTBED_PeerStopMessage *msg;
198   struct PeerEventData *data;
199   struct GNUNET_TESTBED_Peer *peer;
200
201   GNUNET_assert (NULL != opc->data);
202   data = opc->data;
203   GNUNET_assert (NULL != data->peer);
204   peer = data->peer;
205   GNUNET_assert (PS_STARTED == peer->state);
206   opc->state = OPC_STATE_STARTED;
207   msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
208   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER);
209   msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
210   msg->peer_id = htonl (peer->unique_id);
211   msg->operation_id = GNUNET_htonll (opc->id);
212   GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
213   GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
214 }
215
216
217 /**
218  * Callback which will be called when peer stop type operation is released
219  *
220  * @param cls the closure from GNUNET_TESTBED_operation_create_()
221  */
222 static void
223 oprelease_peer_stop (void *cls)
224 {
225   struct OperationContext *opc = cls;
226
227   if (OPC_STATE_FINISHED != opc->state)
228   {
229     GNUNET_free (opc->data);
230     GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
231   }
232   GNUNET_free (opc);
233 }
234
235
236 /**
237  * Generate PeerGetConfigurationMessage
238  *
239  * @param peer_id the id of the peer whose information we have to get
240  * @param operation_id the ip of the operation that should be represented in the
241  *          message
242  * @return the PeerGetConfigurationMessage
243  */
244 struct GNUNET_TESTBED_PeerGetConfigurationMessage *
245 GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id,
246                                             uint64_t operation_id)
247 {
248   struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
249
250   msg =
251       GNUNET_malloc (sizeof
252                      (struct GNUNET_TESTBED_PeerGetConfigurationMessage));
253   msg->header.size =
254       htons (sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage));
255   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG);
256   msg->peer_id = htonl (peer_id);
257   msg->operation_id = GNUNET_htonll (operation_id);
258   return msg;
259 }
260
261
262 /**
263  * Function called when a peer get information operation is ready
264  *
265  * @param cls the closure from GNUNET_TESTBED_operation_create_()
266  */
267 static void
268 opstart_peer_getinfo (void *cls)
269 {
270   struct OperationContext *opc = cls;
271   struct PeerInfoData *data;
272   struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
273
274   data = opc->data;
275   GNUNET_assert (NULL != data);
276   opc->state = OPC_STATE_STARTED;
277   msg =
278       GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id,
279                                                   opc->id);
280   GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
281   GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
282 }
283
284
285 /**
286  * Callback which will be called when peer stop type operation is released
287  *
288  * @param cls the closure from GNUNET_TESTBED_operation_create_()
289  */
290 static void
291 oprelease_peer_getinfo (void *cls)
292 {
293   struct OperationContext *opc = cls;
294   struct GNUNET_TESTBED_PeerInformation *data;
295
296   if (OPC_STATE_FINISHED != opc->state)
297   {
298     GNUNET_free_non_null (opc->data);
299     GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
300   }
301   else
302   {
303     data = opc->data;
304     GNUNET_assert (NULL != data);
305     switch (data->pit)
306     {
307     case GNUNET_TESTBED_PIT_CONFIGURATION:
308       GNUNET_CONFIGURATION_destroy (data->result.cfg);
309       break;
310     case GNUNET_TESTBED_PIT_IDENTITY:
311       GNUNET_free (data->result.id);
312       break;
313     default:
314       GNUNET_assert (0);        /* We should never reach here */
315     }
316     GNUNET_free (data);
317   }
318   GNUNET_free (opc);
319 }
320
321
322 /**
323  * Function called when a overlay connect operation is ready
324  *
325  * @param cls the closure from GNUNET_TESTBED_operation_create_()
326  */
327 static void
328 opstart_overlay_connect (void *cls)
329 {
330   struct OperationContext *opc = cls;
331   struct GNUNET_TESTBED_OverlayConnectMessage *msg;
332   struct OverlayConnectData *data;
333
334   opc->state = OPC_STATE_STARTED;
335   data = opc->data;
336   GNUNET_assert (NULL != data);
337   msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_OverlayConnectMessage));
338   msg->header.size =
339       htons (sizeof (struct GNUNET_TESTBED_OverlayConnectMessage));
340   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT);
341   msg->peer1 = htonl (data->p1->unique_id);
342   msg->peer2 = htonl (data->p2->unique_id);
343   msg->operation_id = GNUNET_htonll (opc->id);
344   msg->peer2_host_id = htonl (GNUNET_TESTBED_host_get_id_ (data->p2->host));
345   GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
346   GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
347 }
348
349
350 /**
351  * Callback which will be called when overlay connect operation is released
352  *
353  * @param cls the closure from GNUNET_TESTBED_operation_create_()
354  */
355 static void
356 oprelease_overlay_connect (void *cls)
357 {
358   struct OperationContext *opc = cls;
359
360   if (OPC_STATE_STARTED == opc->state)
361   {
362     GNUNET_free (opc->data);
363     GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
364   }
365   GNUNET_free (opc);
366 }
367
368
369 /**
370  * Lookup a peer by ID.
371  *
372  * @param id global peer ID assigned to the peer
373  * @return handle to the host, NULL on error
374  */
375 struct GNUNET_TESTBED_Peer *
376 GNUNET_TESTBED_peer_lookup_by_id_ (uint32_t id)
377 {
378   GNUNET_break (0);
379   return NULL;
380 }
381
382
383 /**
384  * Create the given peer at the specified host using the given
385  * controller.  If the given controller is not running on the target
386  * host, it should find or create a controller at the target host and
387  * delegate creating the peer.  Explicit delegation paths can be setup
388  * using 'GNUNET_TESTBED_controller_link'.  If no explicit delegation
389  * path exists, a direct link with a subordinate controller is setup
390  * for the first delegated peer to a particular host; the subordinate
391  * controller is then destroyed once the last peer that was delegated
392  * to the remote host is stopped.  This function is used in particular
393  * if some other controller has already assigned a unique ID to the
394  * peer.
395  *
396  * Creating the peer only creates the handle to manipulate and further
397  * configure the peer; use "GNUNET_TESTBED_peer_start" and
398  * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
399  * processes.
400  *
401  * Note that the given configuration will be adjusted by the
402  * controller to avoid port/path conflicts with other peers.
403  * The "final" configuration can be obtained using
404  * 'GNUNET_TESTBED_peer_get_information'.
405  *
406  * @param unique_id unique ID for this peer
407  * @param controller controller process to use
408  * @param host host to run the peer on
409  * @param cfg Template configuration to use for the peer. Should exist until
410  *          operation is cancelled or GNUNET_TESTBED_operation_done() is called
411  * @param cb the callback to call when the peer has been created
412  * @param cls the closure to the above callback
413  * @return the operation handle
414  */
415 struct GNUNET_TESTBED_Operation *
416 GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
417                                      struct GNUNET_TESTBED_Controller
418                                      *controller,
419                                      struct GNUNET_TESTBED_Host *host,
420                                      const struct GNUNET_CONFIGURATION_Handle
421                                      *cfg, GNUNET_TESTBED_PeerCreateCallback cb,
422                                      void *cls)
423 {
424   struct GNUNET_TESTBED_Peer *peer;
425   struct PeerCreateData *data;
426   struct OperationContext *opc;
427
428   peer = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer));
429   peer->controller = controller;
430   peer->host = host;
431   peer->unique_id = unique_id;
432   peer->state = PS_INVALID;
433   data = GNUNET_malloc (sizeof (struct PeerCreateData));
434   data->host = host;
435   data->cfg = cfg;
436   data->cb = cb;
437   data->cls = cls;
438   data->peer = peer;
439   opc = GNUNET_malloc (sizeof (struct OperationContext));
440   opc->c = controller;
441   opc->data = data;
442   opc->id = GNUNET_TESTBED_get_next_op_id (controller);
443   opc->type = OP_PEER_CREATE;
444   opc->op =
445       GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_create,
446                                         &oprelease_peer_create);
447   GNUNET_TESTBED_operation_queue_insert_ (controller->opq_parallel_operations,
448                                           opc->op);
449   return opc->op;
450 }
451
452
453 /**
454  * Create the given peer at the specified host using the given
455  * controller.  If the given controller is not running on the target
456  * host, it should find or create a controller at the target host and
457  * delegate creating the peer.  Explicit delegation paths can be setup
458  * using 'GNUNET_TESTBED_controller_link'.  If no explicit delegation
459  * path exists, a direct link with a subordinate controller is setup
460  * for the first delegated peer to a particular host; the subordinate
461  * controller is then destroyed once the last peer that was delegated
462  * to the remote host is stopped.
463  *
464  * Creating the peer only creates the handle to manipulate and further
465  * configure the peer; use "GNUNET_TESTBED_peer_start" and
466  * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
467  * processes.
468  *
469  * Note that the given configuration will be adjusted by the
470  * controller to avoid port/path conflicts with other peers.
471  * The "final" configuration can be obtained using
472  * 'GNUNET_TESTBED_peer_get_information'.
473  *
474  * @param controller controller process to use
475  * @param host host to run the peer on
476  * @param cfg Template configuration to use for the peer. Should exist until
477  *          operation is cancelled or GNUNET_TESTBED_operation_done() is called
478  * @param cb the callback to call when the peer has been created
479  * @param cls the closure to the above callback
480  * @return the operation handle
481  */
482 struct GNUNET_TESTBED_Operation *
483 GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
484                             struct GNUNET_TESTBED_Host *host,
485                             const struct GNUNET_CONFIGURATION_Handle *cfg,
486                             GNUNET_TESTBED_PeerCreateCallback cb, void *cls)
487 {
488   static uint32_t id_gen;
489
490   return GNUNET_TESTBED_peer_create_with_id_ (id_gen++, controller, host, cfg,
491                                               cb, cls);
492 }
493
494
495 /**
496  * Start the given peer.
497  *
498  * @param op_cls the closure for this operation; will be set in
499  *          event->details.operation_finished.op_cls when this operation fails.
500  * @param peer peer to start
501  * @param pcc function to call upon completion
502  * @param pcc_cls closure for 'pcc'
503  * @return handle to the operation
504  */
505 struct GNUNET_TESTBED_Operation *
506 GNUNET_TESTBED_peer_start (void *op_cls,
507                            struct GNUNET_TESTBED_Peer *peer,
508                            GNUNET_TESTBED_PeerChurnCallback pcc,
509                            void *pcc_cls)
510 {
511   struct OperationContext *opc;
512   struct PeerEventData *data;
513   
514   data = GNUNET_malloc (sizeof (struct PeerEventData));
515   data->peer = peer;
516   data->pcc = pcc;
517   data->pcc_cls = pcc_cls;
518   opc = GNUNET_malloc (sizeof (struct OperationContext));
519   opc->c = peer->controller;
520   opc->data = data;
521   opc->op_cls = op_cls;
522   opc->id = GNUNET_TESTBED_get_next_op_id (opc->c);
523   opc->type = OP_PEER_START;
524   opc->op =
525       GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_start,
526                                         &oprelease_peer_start);
527   GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
528                                           opc->op);
529   return opc->op;
530 }
531
532
533 /**
534  * Stop the given peer.  The handle remains valid (use
535  * "GNUNET_TESTBED_peer_destroy" to fully clean up the
536  * state of the peer).
537  *
538  * @param peer peer to stop
539  * @param pcc function to call upon completion
540  * @param pcc_cls closure for 'pcc'
541  * @return handle to the operation
542  */
543 struct GNUNET_TESTBED_Operation *
544 GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer,
545                           GNUNET_TESTBED_PeerChurnCallback pcc,
546                           void *pcc_cls)
547 {
548   struct OperationContext *opc;
549   struct PeerEventData *data;
550  
551   data = GNUNET_malloc (sizeof (struct PeerEventData));
552   data->peer = peer;
553   data->pcc = pcc;
554   data->pcc_cls = pcc_cls;
555   opc = GNUNET_malloc (sizeof (struct OperationContext));
556   opc->c = peer->controller;
557   opc->data = data;
558   opc->id = GNUNET_TESTBED_get_next_op_id (opc->c);
559   opc->type = OP_PEER_STOP;
560   opc->op =
561       GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_stop,
562                                         &oprelease_peer_stop);
563   GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
564                                           opc->op);
565   return opc->op;
566 }
567
568
569 /**
570  * Request information about a peer. The controller callback will not be called
571  * with event type GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this
572  * operation is available. Instead, the GNUNET_TESTBED_PeerInfoCallback() will
573  * be called.
574  *
575  * @param peer peer to request information about
576  * @param pit desired information
577  * @param cb the convenience callback to be called when results for this
578  *          operation are available
579  * @param cb_cls the closure for the above callback
580  * @return handle to the operation
581  */
582 struct GNUNET_TESTBED_Operation *
583 GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
584                                      enum GNUNET_TESTBED_PeerInformationType
585                                      pit,
586                                      GNUNET_TESTBED_PeerInfoCallback cb,
587                                      void *cb_cls)
588 {
589   struct OperationContext *opc;
590   struct PeerInfoData *data;
591
592   GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC != pit);
593   data = GNUNET_malloc (sizeof (struct PeerInfoData));
594   data->peer = peer;
595   data->pit = pit;
596   data->cb = cb;
597   data->cb_cls = cb_cls;
598   opc = GNUNET_malloc (sizeof (struct OperationContext));
599   opc->c = peer->controller;
600   opc->data = data;
601   opc->type = OP_PEER_INFO;
602   opc->id = GNUNET_TESTBED_get_next_op_id (opc->c);
603   opc->op =
604       GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_getinfo,
605                                         &oprelease_peer_getinfo);
606   GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
607                                           opc->op);
608   return opc->op;
609 }
610
611
612 /**
613  * Change peer configuration.  Must only be called while the
614  * peer is stopped.  Ports and paths cannot be changed this
615  * way.
616  *
617  * @param peer peer to change configuration for
618  * @param cfg new configuration (differences to existing
619  *            configuration only)
620  * @return handle to the operation
621  */
622 struct GNUNET_TESTBED_Operation *
623 GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
624                                           const struct
625                                           GNUNET_CONFIGURATION_Handle *cfg)
626 {
627   // FIXME: handle locally or delegate...
628   GNUNET_break (0);
629   return NULL;
630 }
631
632
633 /**
634  * Destroy the given peer; the peer should have been
635  * stopped first (if it was started).
636  *
637  * @param peer peer to stop
638  * @return handle to the operation
639  */
640 struct GNUNET_TESTBED_Operation *
641 GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer)
642 {
643   struct OperationContext *opc;
644
645   opc = GNUNET_malloc (sizeof (struct OperationContext));
646   opc->data = peer;
647   opc->c = peer->controller;
648   opc->id = GNUNET_TESTBED_get_next_op_id (peer->controller);
649   opc->type = OP_PEER_DESTROY;
650   opc->op =
651       GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_destroy,
652                                         &oprelease_peer_destroy);
653   GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations,
654                                           opc->op);
655   return opc->op;
656 }
657
658
659 /**
660  * Manipulate the P2P underlay topology by configuring a link
661  * between two peers.
662  *
663  * @param op_cls closure argument to give with the operation event
664  * @param p1 first peer
665  * @param p2 second peer
666  * @param co option to change
667  * @param ... option-specific values
668  * @return handle to the operation, NULL if configuring the link at this
669  *         time is not allowed
670  */
671 struct GNUNET_TESTBED_Operation *
672 GNUNET_TESTBED_underlay_configure_link (void *op_cls,
673                                         struct GNUNET_TESTBED_Peer *p1,
674                                         struct GNUNET_TESTBED_Peer *p2,
675                                         enum GNUNET_TESTBED_ConnectOption co,
676                                         ...)
677 {
678   GNUNET_break (0);
679   return NULL;
680 }
681
682
683 /**
684  * Both peers must have been started before calling this function.
685  * This function then obtains a HELLO from 'p1', gives it to 'p2'
686  * and asks 'p2' to connect to 'p1'.
687  *
688  * @param op_cls closure argument to give with the operation event
689  * @param cb the callback to call when this operation has finished
690  * @param cb_cls the closure for the above callback
691  * @param p1 first peer
692  * @param p2 second peer
693  * @return handle to the operation, NULL if connecting these two
694  *         peers is fundamentally not possible at this time (peers
695  *         not running or underlay disallows)
696  */
697 struct GNUNET_TESTBED_Operation *
698 GNUNET_TESTBED_overlay_connect (void *op_cls,
699                                 GNUNET_TESTBED_OperationCompletionCallback cb,
700                                 void *cb_cls,
701                                 struct GNUNET_TESTBED_Peer *p1,
702                                 struct GNUNET_TESTBED_Peer *p2)
703 {
704   struct OperationContext *opc;
705   struct OverlayConnectData *data;
706
707   GNUNET_assert ((PS_STARTED == p1->state) && (PS_STARTED == p2->state));
708   data = GNUNET_malloc (sizeof (struct OverlayConnectData));
709   data->p1 = p1;
710   data->p2 = p2;
711   data->cb = cb;
712   data->cb_cls = cb_cls;
713   data->state = OCD_INIT;
714   opc = GNUNET_malloc (sizeof (struct OperationContext));
715   opc->data = data;
716   opc->c = p1->controller;
717   opc->id = GNUNET_TESTBED_get_next_op_id (opc->c);
718   opc->type = OP_OVERLAY_CONNECT;
719   opc->op_cls = op_cls;
720   opc->op =
721       GNUNET_TESTBED_operation_create_ (opc, &opstart_overlay_connect,
722                                         &oprelease_overlay_connect);
723   /* GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, */
724   /*                                         opc->op); */
725   GNUNET_TESTBED_operation_queue_insert_
726       (opc->c->opq_parallel_overlay_connect_operations, opc->op);
727   return opc->op;
728 }
729
730
731
732 /* end of testbed_api_peers.c */