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