paragraph for gnunet devs that don't know how to use the web
[oweals/gnunet.git] / src / testbed / testbed_api_peers.h
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
19 /**
20  * @file testbed/testbed_api_peers.h
21  * @brief internal API to access the 'peers' subsystem
22  * @author Christian Grothoff
23  * @author Sree Harsha Totakura
24  */
25
26 #ifndef NEW_TESTING_API_PEERS_H
27 #define NEW_TESTING_API_PEERS_H
28
29 #include "gnunet_testbed_service.h"
30 #include "gnunet_helper_lib.h"
31
32
33 /**
34  * Enumeration of possible states a peer could be in
35  */
36 enum PeerState
37 {
38     /**
39      * State to signify that this peer is invalid
40      */
41   TESTBED_PS_INVALID,
42
43     /**
44      * The peer has been created
45      */
46   TESTBED_PS_CREATED,
47
48     /**
49      * The peer is running
50      */
51   TESTBED_PS_STARTED,
52
53     /**
54      * The peer is stopped
55      */
56   TESTBED_PS_STOPPED,
57 };
58
59
60 /**
61  * A peer controlled by the testing framework.  A peer runs
62  * at a particular host.
63  */
64 struct GNUNET_TESTBED_Peer
65 {
66   /**
67    * peer list DLL
68    */
69   struct GNUNET_TESTBED_Peer *next;
70
71   /**
72    * peer list DLL
73    */
74   struct GNUNET_TESTBED_Peer *prev;
75
76   /**
77    * Our controller context (not necessarily the controller
78    * that is responsible for starting/running the peer!).
79    */
80   struct GNUNET_TESTBED_Controller *controller;
81
82   /**
83    * Which host does this peer run on?
84    */
85   struct GNUNET_TESTBED_Host *host;
86
87   /**
88    * Globally unique ID of the peer.
89    */
90   uint32_t unique_id;
91
92   /**
93    * Peer's state
94    */
95   enum PeerState state;
96
97   /**
98    * Has an underlay model already set for this peer?
99    */
100   uint8_t underlay_model_exists;
101 };
102
103
104 /**
105  * Data for the OperationType OP_PEER_CREATE
106  */
107 struct PeerCreateData
108 {
109   /**
110    * The host where the peer has to be created
111    */
112   struct GNUNET_TESTBED_Host *host;
113
114   /**
115    * The template configuration of the peer
116    */
117   const struct GNUNET_CONFIGURATION_Handle *cfg;
118
119   /**
120    * The call back to call when we receive peer create success message
121    */
122   GNUNET_TESTBED_PeerCreateCallback cb;
123
124   /**
125    * The closure for the above callback
126    */
127   void *cls;
128
129   /**
130    * The peer structure to return when we get success message
131    */
132   struct GNUNET_TESTBED_Peer *peer;
133
134 };
135
136
137 /**
138  * Data for OperationType OP_PEER_START and OP_PEER_STOP
139  */
140 struct PeerEventData
141 {
142   /**
143    * The handle of the peer to start
144    */
145   struct GNUNET_TESTBED_Peer *peer;
146
147   /**
148    * The Peer churn callback to call when this operation is completed
149    */
150   GNUNET_TESTBED_PeerChurnCallback pcc;
151
152   /**
153    * Closure for the above callback
154    */
155   void *pcc_cls;
156
157 };
158
159
160 /**
161  * Data for the OperationType OP_PEER_DESTROY;
162  */
163 struct PeerDestroyData
164 {
165   /**
166    * The peer structure
167    */
168   struct GNUNET_TESTBED_Peer *peer;
169
170   //PEERDESTROYDATA
171 };
172
173
174 /**
175  * Data for the OperationType OP_PEER_INFO
176  */
177 struct PeerInfoData
178 {
179   /**
180    * The peer whose information has been requested
181    */
182   struct GNUNET_TESTBED_Peer *peer;
183
184   /**
185    * The Peer info callback to call when this operation has completed
186    */
187   GNUNET_TESTBED_PeerInfoCallback cb;
188
189   /**
190    * The closure for peer info callback
191    */
192   void *cb_cls;
193
194   /**
195    * The type of peer information requested
196    */
197   enum GNUNET_TESTBED_PeerInformationType pit;
198 };
199
200
201 /**
202  * Data for the operations of type OP_PEER_RECONFIGURE
203  */
204 struct PeerReconfigureData
205 {
206   /**
207    * The peer whose information has been requested
208    */
209   struct GNUNET_TESTBED_Peer *peer;
210
211   /**
212    * The serialized new configuration template
213    */
214   char *config;
215
216   /**
217    * the size of the serialized configuration
218    */
219   uint16_t cfg_size;
220 };
221
222
223 /**
224  * Data structure for OperationType OP_OVERLAY_CONNECT
225  */
226 struct OverlayConnectData
227 {
228
229   /**
230    * Peer A to connect to peer B
231    */
232   struct GNUNET_TESTBED_Peer *p1;
233
234   /**
235    * Peer B
236    */
237   struct GNUNET_TESTBED_Peer *p2;
238
239   /**
240    * The operation completion callback to call once this operation is done
241    */
242   GNUNET_TESTBED_OperationCompletionCallback cb;
243
244   /**
245    * The closure for the above callback
246    */
247   void *cb_cls;
248
249   /**
250    * OperationContext for forwarded operations generated when peer1's controller doesn't have the
251    * configuration of peer2's controller for linking laterally to attemp an
252    * overlay connection between peer 1 and peer 2.
253    */
254   struct OperationContext *sub_opc;
255
256 };
257
258
259 struct ManageServiceData {
260   GNUNET_TESTBED_OperationCompletionCallback cb;
261
262   void *cb_cls;
263
264   struct GNUNET_TESTBED_Peer *peer;
265
266   char *service_name;
267
268   unsigned int start;
269
270   uint16_t msize;
271
272 };
273
274
275 /**
276  * Generate PeerGetConfigurationMessage
277  *
278  * @param peer_id the id of the peer whose information we have to get
279  * @param operation_id the ip of the operation that should be represented in
280  *          the message
281  * @return the PeerGetConfigurationMessage
282  */
283 struct GNUNET_TESTBED_PeerGetConfigurationMessage *
284 GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id,
285                                             uint64_t operation_id);
286
287
288 /**
289  * Adds a peer to the peer list
290  *
291  * @param peer the peer to add to the peer list
292  */
293 void
294 GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer);
295
296
297 /**
298  * Removes a peer from the peer list
299  *
300  * @param peer the peer to remove
301  */
302 void
303 GNUNET_TESTBED_peer_deregister_ (struct GNUNET_TESTBED_Peer *peer);
304
305
306 /**
307  * Frees all peers
308  */
309 void
310 GNUNET_TESTBED_cleanup_peers_ (void);
311
312 #endif
313 /* end of testbed_api_peers.h */