-add adv port
[oweals/gnunet.git] / src / testbed / testbed_api_peers.h
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.h
23  * @brief internal API to access the 'peers' subsystem
24  * @author Christian Grothoff
25  * @author Sree Harsha Totakura
26  */
27
28 #ifndef NEW_TESTING_API_PEERS_H
29 #define NEW_TESTING_API_PEERS_H
30
31 #include "gnunet_testbed_service.h"
32 #include "gnunet_helper_lib.h"
33
34
35 /**
36  * Enumeration of possible states a peer could be in
37  */
38 enum PeerState
39 {
40     /**
41      * State to signify that this peer is invalid
42      */
43   PS_INVALID,
44
45     /**
46      * The peer has been created
47      */
48   PS_CREATED,
49
50     /**
51      * The peer is running
52      */
53   PS_STARTED,
54
55     /**
56      * The peer is stopped
57      */
58   PS_STOPPED,
59 };
60
61
62 /**
63  * A peer controlled by the testing framework.  A peer runs
64  * at a particular host.
65  */
66 struct GNUNET_TESTBED_Peer
67 {
68   /**
69    * Our controller context (not necessarily the controller
70    * that is responsible for starting/running the peer!).
71    */
72   struct GNUNET_TESTBED_Controller *controller;
73
74   /**
75    * Which host does this peer run on?
76    */
77   struct GNUNET_TESTBED_Host *host;
78
79   /**
80    * Globally unique ID of the peer.
81    */
82   uint32_t unique_id;
83
84   /**
85    * Peer's state
86    */
87   enum PeerState state;
88 };
89
90
91 /**
92  * Data for the OperationType OP_PEER_CREATE
93  */
94 struct PeerCreateData
95 {
96   /**
97    * The host where the peer has to be created
98    */
99   struct GNUNET_TESTBED_Host *host;
100
101   /**
102    * The template configuration of the peer
103    */
104   const struct GNUNET_CONFIGURATION_Handle *cfg;
105
106   /**
107    * The call back to call when we receive peer create success message
108    */
109   GNUNET_TESTBED_PeerCreateCallback cb;
110
111   /**
112    * The closure for the above callback
113    */
114   void *cls;
115
116   /**
117    * The peer structure to return when we get success message
118    */
119   struct GNUNET_TESTBED_Peer *peer;
120
121 };
122
123
124 /**
125  * Data for OperationType OP_PEER_START and OP_PEER_STOP
126  */
127 struct PeerEventData
128 {
129   /**
130    * The handle of the peer to start
131    */
132   struct GNUNET_TESTBED_Peer *peer;
133   
134   /**
135    * The Peer churn callback to call when this operation is completed
136    */
137   GNUNET_TESTBED_PeerChurnCallback pcc;
138    
139   /**
140    * Closure for the above callback
141    */
142   void *pcc_cls;
143     
144 };
145
146
147 /**
148  * Data for the OperationType OP_PEER_DESTROY;
149  */
150 struct PeerDestroyData
151 {
152   /**
153    * The peer structure
154    */
155   struct GNUNET_TESTBED_Peer *peer;
156
157   //PEERDESTROYDATA
158 };
159
160
161 /**
162  * Data for the OperationType OP_PEER_INFO
163  */
164 struct PeerInfoData
165 {
166   /**
167    * The peer whose information has been requested
168    */
169   struct GNUNET_TESTBED_Peer *peer;
170
171   /**
172    * The Peer info callback to call when this operation has completed
173    */
174   GNUNET_TESTBED_PeerInfoCallback cb;
175     
176   /**
177    * The closure for peer info callback
178    */
179   void *cb_cls;
180
181   /**
182    * The type of peer information requested
183    */
184   enum GNUNET_TESTBED_PeerInformationType pit;
185 };
186
187
188 /**
189  * Data structure for OperationType OP_OVERLAY_CONNECT
190  */
191 struct OverlayConnectData
192 {
193
194   /**
195    * Peer A to connect to peer B
196    */
197   struct GNUNET_TESTBED_Peer *p1;
198
199   /**
200    * Peer B
201    */
202   struct GNUNET_TESTBED_Peer *p2;
203
204   /**
205    * The operation completion callback to call once this operation is done
206    */
207   GNUNET_TESTBED_OperationCompletionCallback cb;
208   
209   /**
210    * The closure for the above callback
211    */
212   void *cb_cls;
213
214   /**
215    * OperationContext for forwarded operations generated when peer1's controller doesn't have the
216    * configuration of peer2's controller for linking laterally to attemp an
217    * overlay connection between peer 1 and peer 2.
218    */
219   struct OperationContext *sub_opc;
220
221   /**
222    * State information for this context data
223    */
224   enum OCDState {
225     
226     /**
227      * The initial state
228      */
229     OCD_INIT,
230
231     /**
232      * State where we attempt to acquire peer2's controller's configuration
233      */
234     OCD_CFG_ACQUIRE,
235
236     /**
237      * State where we link peer1's controller to peer2's controller
238      */
239     OCD_LINK_CONTROLLERS,
240     
241     /**
242      * State where we re-ask controller of peer1 to attempt an overlay connect
243      * between peer1 and peer2
244      */
245     OCD_REATTEMPT_OVERLAY_CONNECT
246   } state;
247
248 };
249
250
251
252 /**
253  * Create the given peer at the specified host using the given
254  * controller.  If the given controller is not running on the target
255  * host, it should find or create a controller at the target host and
256  * delegate creating the peer.  Explicit delegation paths can be setup
257  * using 'GNUNET_TESTBED_controller_link'.  If no explicit delegation
258  * path exists, a direct link with a subordinate controller is setup
259  * for the first delegated peer to a particular host; the subordinate
260  * controller is then destroyed once the last peer that was delegated
261  * to the remote host is stopped.  This function is used in particular
262  * if some other controller has already assigned a unique ID to the
263  * peer.
264  *
265  * Creating the peer only creates the handle to manipulate and further
266  * configure the peer; use "GNUNET_TESTBED_peer_start" and
267  * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
268  * processes.
269  *
270  * Note that the given configuration will be adjusted by the
271  * controller to avoid port/path conflicts with other peers.
272  * The "final" configuration can be obtained using
273  * 'GNUNET_TESTBED_peer_get_information'.
274  *
275  * @param unique_id unique ID for this peer
276  * @param controller controller process to use
277  * @param host host to run the peer on
278  * @param cfg configuration to use for the peer
279  * @param cb the callback to call when the peer has been created
280  * @param cls the closure to the above callback
281  * @return the operation handle
282  */
283 struct GNUNET_TESTBED_Operation *
284 GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
285                                      struct GNUNET_TESTBED_Controller
286                                      *controller,
287                                      struct GNUNET_TESTBED_Host *host,
288                                      const struct GNUNET_CONFIGURATION_Handle
289                                      *cfg, GNUNET_TESTBED_PeerCreateCallback cb,
290                                      void *cls);
291
292
293 /**
294  * Generate PeerGetConfigurationMessage
295  *
296  * @param peer_id the id of the peer whose information we have to get
297  * @param operation_id the ip of the operation that should be represented in
298  *          the message
299  * @return the PeerGetConfigurationMessage
300  */
301 struct GNUNET_TESTBED_PeerGetConfigurationMessage *
302 GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id,
303                                             uint64_t operation_id);
304
305 #endif
306 /* end of testbed_api_peers.h */