refined overlay connect and extended test case
[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,
73                                     opc->c->ocq_tail, opc);
74   GNUNET_TESTBED_queue_message_ (opc->c,
75                                  (struct GNUNET_MessageHeader *) msg);
76 };
77
78
79 /**
80  * Callback which will be called when peer_create type operation is released
81  *
82  * @param cls the closure from GNUNET_TESTBED_operation_create_()
83  */
84 static void 
85 oprelease_peer_create (void *cls)
86 {
87   struct OperationContext *opc = cls;  
88
89   if (OPC_STATE_FINISHED != opc->state)
90   {
91     GNUNET_free (((struct PeerCreateData *) opc->data)->peer);
92     GNUNET_free (opc->data);
93     GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
94   }
95   GNUNET_free (opc);
96 }
97
98
99 /**
100  * Function called when a peer destroy operation is ready
101  *
102  * @param cls the closure from GNUNET_TESTBED_operation_create_()
103  */
104 static void 
105 opstart_peer_destroy (void *cls)
106 {
107   struct OperationContext *opc = cls;
108   struct GNUNET_TESTBED_Peer *peer;
109   struct GNUNET_TESTBED_PeerDestroyMessage *msg;
110
111   GNUNET_assert (OP_PEER_DESTROY == opc->type);
112   peer = opc->data;
113   GNUNET_assert (NULL != peer);
114   opc->state = OPC_STATE_STARTED;
115   msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
116   msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
117   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER);
118   msg->peer_id = htonl (peer->unique_id);
119   msg->operation_id = GNUNET_htonll (opc->id);
120   GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head,
121                                     opc->c->ocq_tail, opc);
122   GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
123 }
124
125
126 /**
127  * Callback which will be called when peer_create type operation is released
128  *
129  * @param cls the closure from GNUNET_TESTBED_operation_create_()
130  */
131 static void 
132 oprelease_peer_destroy (void *cls)
133 {
134   struct OperationContext *opc = cls;
135   
136   if (OPC_STATE_FINISHED != opc->state)
137     GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
138   GNUNET_free (opc);
139 }
140
141
142 /**
143  * Function called when a peer start operation is ready
144  *
145  * @param cls the closure from GNUNET_TESTBED_operation_create_()
146  */
147 static void 
148 opstart_peer_start (void *cls)
149 {
150   struct OperationContext *opc = cls;
151   struct GNUNET_TESTBED_PeerStartMessage *msg;
152   struct GNUNET_TESTBED_Peer *peer;
153
154   GNUNET_assert (OP_PEER_START == opc->type);
155   GNUNET_assert (NULL != opc->data);
156   peer = opc->data;
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     GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
181   GNUNET_free (opc);
182 }
183
184
185 /**
186  * Function called when a peer stop operation is ready
187  *
188  * @param cls the closure from GNUNET_TESTBED_operation_create_()
189  */
190 static void 
191 opstart_peer_stop (void *cls)
192 {
193   struct OperationContext *opc = cls;
194   struct GNUNET_TESTBED_PeerStopMessage *msg;
195   struct GNUNET_TESTBED_Peer *peer;
196
197   GNUNET_assert (NULL != opc->data);
198   peer = opc->data;
199   GNUNET_assert (PS_STARTED == peer->state); 
200   opc->state = OPC_STATE_STARTED;  
201   msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
202   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER);
203   msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
204   msg->peer_id = htonl (peer->unique_id);
205   msg->operation_id = GNUNET_htonll (opc->id);
206   GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
207   GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
208 }
209
210
211 /**
212  * Callback which will be called when peer stop type operation is released
213  *
214  * @param cls the closure from GNUNET_TESTBED_operation_create_()
215  */
216 static void 
217 oprelease_peer_stop (void *cls)
218 {
219   struct OperationContext *opc = cls;
220   
221   if (OPC_STATE_FINISHED != opc->state)
222     GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
223   GNUNET_free (opc);
224 }
225
226
227 /**
228  * Function called when a peer get information operation is ready
229  *
230  * @param cls the closure from GNUNET_TESTBED_operation_create_()
231  */
232 static void 
233 opstart_peer_getinfo (void *cls)
234 {
235   struct OperationContext *opc = cls;
236   struct PeerInfoData *data;  
237   struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
238
239   data = opc->data;
240   GNUNET_assert (NULL != data);
241   opc->state = OPC_STATE_STARTED;
242   msg = GNUNET_malloc (sizeof (struct
243                                GNUNET_TESTBED_PeerGetConfigurationMessage));
244   msg->header.size = htons
245     (sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage));
246   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG);
247   msg->peer_id = htonl (data->peer->unique_id);
248   msg->operation_id = GNUNET_htonll (opc->id);
249   GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
250   GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
251 }
252
253
254 /**
255  * Callback which will be called when peer stop type operation is released
256  *
257  * @param cls the closure from GNUNET_TESTBED_operation_create_()
258  */
259 static void 
260 oprelease_peer_getinfo (void *cls)
261 {
262   struct OperationContext *opc = cls;
263   struct PeerInfoData2 *data;
264   
265   if (OPC_STATE_FINISHED != opc->state)
266   {
267     GNUNET_free_non_null (opc->data);
268     GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);  
269   }
270   else
271   {
272     data = opc->data;
273     GNUNET_assert (NULL != data);
274     switch (data->pit)
275     {
276     case GNUNET_TESTBED_PIT_CONFIGURATION:
277       GNUNET_CONFIGURATION_destroy (data->details.cfg);
278       break;
279     case GNUNET_TESTBED_PIT_IDENTITY:
280       GNUNET_free (data->details.peer_identity);
281       break;
282     default:
283       GNUNET_assert (0);        /* We should never reach here */
284     }
285     GNUNET_free (data);
286   }
287   GNUNET_free (opc);
288 }
289
290
291 /**
292  * Function called when a overlay connect operation is ready
293  *
294  * @param cls the closure from GNUNET_TESTBED_operation_create_()
295  */
296 static void 
297 opstart_overlay_connect (void *cls)
298 {
299   struct OperationContext *opc = cls;
300   struct GNUNET_TESTBED_OverlayConnectMessage *msg;
301   struct OverlayConnectData *data;
302     
303   opc->state = OPC_STATE_STARTED;
304   data = opc->data;
305   GNUNET_assert (NULL != data);
306   msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_OverlayConnectMessage));
307   msg->header.size = htons (sizeof 
308                             (struct GNUNET_TESTBED_OverlayConnectMessage));
309   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT);
310   msg->peer1 = htonl (data->p1->unique_id);
311   msg->peer2 = htonl (data->p2->unique_id);
312   msg->operation_id = GNUNET_htonll (opc->id);
313   GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
314   GNUNET_TESTBED_queue_message_ (opc->c, &msg->header);
315 }
316
317
318 /**
319  * Callback which will be called when overlay connect operation is released
320  *
321  * @param cls the closure from GNUNET_TESTBED_operation_create_()
322  */
323 static void 
324 oprelease_overlay_connect (void *cls)
325 {
326   struct OperationContext *opc = cls;
327   
328   if (OPC_STATE_FINISHED != opc->state)
329   {
330     GNUNET_free (opc->data);
331     GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
332   }
333   GNUNET_free (opc);  
334 }
335
336
337 /**
338  * Lookup a peer by ID.
339  * 
340  * @param id global peer ID assigned to the peer
341  * @return handle to the host, NULL on error
342  */
343 struct GNUNET_TESTBED_Peer *
344 GNUNET_TESTBED_peer_lookup_by_id_ (uint32_t id)
345 {
346   GNUNET_break (0);
347   return NULL;
348 }
349
350
351 /**
352  * Create the given peer at the specified host using the given
353  * controller.  If the given controller is not running on the target
354  * host, it should find or create a controller at the target host and
355  * delegate creating the peer.  Explicit delegation paths can be setup
356  * using 'GNUNET_TESTBED_controller_link'.  If no explicit delegation
357  * path exists, a direct link with a subordinate controller is setup
358  * for the first delegated peer to a particular host; the subordinate
359  * controller is then destroyed once the last peer that was delegated
360  * to the remote host is stopped.  This function is used in particular
361  * if some other controller has already assigned a unique ID to the
362  * peer.
363  *
364  * Creating the peer only creates the handle to manipulate and further
365  * configure the peer; use "GNUNET_TESTBED_peer_start" and
366  * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
367  * processes.
368  *
369  * Note that the given configuration will be adjusted by the
370  * controller to avoid port/path conflicts with other peers.
371  * The "final" configuration can be obtained using
372  * 'GNUNET_TESTBED_peer_get_information'.
373  *
374  * @param unique_id unique ID for this peer
375  * @param controller controller process to use
376  * @param host host to run the peer on
377  * @param cfg Template configuration to use for the peer. Should exist until
378  *          operation is cancelled or GNUNET_TESTBED_operation_done() is called
379  * @param cb the callback to call when the peer has been created
380  * @param cls the closure to the above callback
381  * @return the operation handle
382  */
383 struct GNUNET_TESTBED_Operation *
384 GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
385                                      struct GNUNET_TESTBED_Controller *controller,
386                                      struct GNUNET_TESTBED_Host *host,
387                                      const struct GNUNET_CONFIGURATION_Handle *cfg,
388                                      GNUNET_TESTBED_PeerCreateCallback cb,
389                                      void *cls)
390 {
391   struct GNUNET_TESTBED_Peer *peer;
392   struct PeerCreateData *data;
393   struct OperationContext *opc;
394
395   peer = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer));
396   peer->controller = controller;
397   peer->host = host;
398   peer->unique_id = unique_id;
399   peer->state = PS_INVALID;
400   data = GNUNET_malloc (sizeof (struct PeerCreateData));
401   data->host = host;
402   data->cfg = cfg;
403   data->cb = cb;
404   data->cls = cls;
405   data->peer = peer;
406   opc = GNUNET_malloc (sizeof (struct OperationContext));
407   opc->c = controller;
408   opc->data = data;
409   opc->id = controller->operation_counter++;
410   opc->type = OP_PEER_CREATE;
411   opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_create,
412                                               &oprelease_peer_create);
413   GNUNET_TESTBED_operation_queue_insert_ (controller->opq_peer_create, opc->op);
414   return opc->op;
415 }
416
417
418 /**
419  * Create the given peer at the specified host using the given
420  * controller.  If the given controller is not running on the target
421  * host, it should find or create a controller at the target host and
422  * delegate creating the peer.  Explicit delegation paths can be setup
423  * using 'GNUNET_TESTBED_controller_link'.  If no explicit delegation
424  * path exists, a direct link with a subordinate controller is setup
425  * for the first delegated peer to a particular host; the subordinate
426  * controller is then destroyed once the last peer that was delegated
427  * to the remote host is stopped.
428  *
429  * Creating the peer only creates the handle to manipulate and further
430  * configure the peer; use "GNUNET_TESTBED_peer_start" and
431  * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
432  * processes.
433  *
434  * Note that the given configuration will be adjusted by the
435  * controller to avoid port/path conflicts with other peers.
436  * The "final" configuration can be obtained using
437  * 'GNUNET_TESTBED_peer_get_information'.
438  *
439  * @param controller controller process to use
440  * @param host host to run the peer on
441  * @param cfg Template configuration to use for the peer. Should exist until
442  *          operation is cancelled or GNUNET_TESTBED_operation_done() is called
443  * @param cb the callback to call when the peer has been created
444  * @param cls the closure to the above callback
445  * @return the operation handle
446  */
447 struct GNUNET_TESTBED_Operation *
448 GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
449                             struct GNUNET_TESTBED_Host *host,
450                             const struct GNUNET_CONFIGURATION_Handle *cfg,
451                             GNUNET_TESTBED_PeerCreateCallback cb,
452                             void *cls)
453 {
454   static uint32_t id_gen;
455
456   return GNUNET_TESTBED_peer_create_with_id_ (++id_gen,
457                                               controller,
458                                               host,
459                                               cfg,
460                                               cb, cls);
461 }
462
463
464 /**
465  * Start the given peer.
466  *
467  * @param peer peer to start
468  * @return handle to the operation
469  */
470 struct GNUNET_TESTBED_Operation *
471 GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer)
472 {
473   struct OperationContext *opc;
474
475   opc = GNUNET_malloc (sizeof (struct OperationContext));
476   opc->c = peer->controller;
477   opc->data = peer;
478   opc->id = opc->c->operation_counter++;
479   opc->type = OP_PEER_START;
480   opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_start,
481                                              &oprelease_peer_start);
482   GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create, opc->op);
483   return opc->op;  
484 }
485
486
487 /**
488  * Stop the given peer.  The handle remains valid (use
489  * "GNUNET_TESTBED_peer_destroy" to fully clean up the 
490  * state of the peer).
491  *
492  * @param peer peer to stop
493  * @return handle to the operation
494  */
495 struct GNUNET_TESTBED_Operation *
496 GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer)
497 {
498   struct OperationContext *opc;
499
500   opc = GNUNET_malloc (sizeof (struct OperationContext));
501   opc->c = peer->controller;
502   opc->data = peer;
503   opc->id = opc->c->operation_counter++;
504   opc->type = OP_PEER_STOP;
505   opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_stop,
506                                               &oprelease_peer_stop);
507   GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create, opc->op);
508   return opc->op;
509 }
510
511
512 /**
513  * Request information about a peer.
514  *
515  * @param peer peer to request information about
516  * @param pit desired information
517  * @return handle to the operation
518  */
519 struct GNUNET_TESTBED_Operation *
520 GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
521                                      enum GNUNET_TESTBED_PeerInformationType pit)
522 {
523   struct OperationContext *opc;
524   struct PeerInfoData *data;
525
526   GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC != pit);
527   data = GNUNET_malloc (sizeof (struct PeerInfoData));
528   data->peer = peer;
529   data->pit = pit;
530   opc = GNUNET_malloc (sizeof (struct OperationContext));
531   opc->c = peer->controller;
532   opc->data = data;
533   opc->type = OP_PEER_INFO;
534   opc->id = opc->c->operation_counter++;
535   opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_getinfo,
536                                              &oprelease_peer_getinfo);
537   GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create, opc->op);
538   return opc->op;
539 }
540
541
542 /**
543  * Change peer configuration.  Must only be called while the
544  * peer is stopped.  Ports and paths cannot be changed this
545  * way.
546  *
547  * @param peer peer to change configuration for
548  * @param cfg new configuration (differences to existing
549  *            configuration only)
550  * @return handle to the operation
551  */
552 struct GNUNET_TESTBED_Operation *
553 GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
554                                           const struct GNUNET_CONFIGURATION_Handle *cfg)
555 {
556   // FIXME: handle locally or delegate...
557   GNUNET_break (0);
558   return NULL;
559 }
560
561
562 /**
563  * Destroy the given peer; the peer should have been
564  * stopped first (if it was started).
565  *
566  * @param peer peer to stop
567  * @return handle to the operation
568  */
569 struct GNUNET_TESTBED_Operation *
570 GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer)
571 {
572   struct OperationContext *opc;
573
574   opc = GNUNET_malloc (sizeof (struct OperationContext));
575   opc->data = peer;
576   opc->c = peer->controller;
577   opc->id = peer->controller->operation_counter++;
578   opc->type = OP_PEER_DESTROY;
579   opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_destroy,
580                                               &oprelease_peer_destroy);
581   GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create,
582                                           opc->op);
583   return opc->op;
584 }
585
586
587 /**
588  * Manipulate the P2P underlay topology by configuring a link
589  * between two peers.  
590  *
591  * @param op_cls closure argument to give with the operation event
592  * @param p1 first peer
593  * @param p2 second peer
594  * @param co option to change
595  * @param ... option-specific values
596  * @return handle to the operation, NULL if configuring the link at this
597  *         time is not allowed
598  */
599 struct GNUNET_TESTBED_Operation *
600 GNUNET_TESTBED_underlay_configure_link (void *op_cls,
601                                         struct GNUNET_TESTBED_Peer *p1,
602                                         struct GNUNET_TESTBED_Peer *p2,
603                                         enum GNUNET_TESTBED_ConnectOption co, ...)
604 {
605   GNUNET_break (0);
606   return NULL;
607 }
608
609
610
611 /**
612  * Both peers must have been started before calling this function.
613  * This function then obtains a HELLO from 'p1', gives it to 'p2'
614  * and asks 'p2' to connect to 'p1'.
615  *
616  * @param op_cls closure argument to give with the operation event
617  * @param p1 first peer
618  * @param p2 second peer
619  * @return handle to the operation, NULL if connecting these two
620  *         peers is fundamentally not possible at this time (peers
621  *         not running or underlay disallows)
622  */
623 struct GNUNET_TESTBED_Operation *
624 GNUNET_TESTBED_overlay_connect (void *op_cls,
625                                 struct GNUNET_TESTBED_Peer *p1,
626                                 struct GNUNET_TESTBED_Peer *p2)
627 {
628   struct OperationContext *opc;
629   struct OverlayConnectData *data;
630
631   GNUNET_assert ((PS_STARTED == p1->state) && (PS_STARTED == p2->state));
632   GNUNET_assert (p1->controller == p2->controller);
633   data = GNUNET_malloc (sizeof (struct OverlayConnectData));
634   data->p1 = p1;
635   data->p2 = p2;
636   opc = GNUNET_malloc (sizeof (struct OperationContext));
637   opc->data = data;
638   opc->c = p1->controller;
639   opc->id = opc->c->operation_counter++;
640   opc->type = OP_OVERLAY_CONNECT;
641   opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_overlay_connect,
642                                               &oprelease_overlay_connect);
643   GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create,
644                                           opc->op);
645   return opc->op;
646 }
647
648
649
650 /* end of testbed_api_peers.c */