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