- cleanup peers after shutdown operation
[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    * 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
101 /**
102  * Data for the OperationType OP_PEER_CREATE
103  */
104 struct PeerCreateData
105 {
106   /**
107    * The host where the peer has to be created
108    */
109   struct GNUNET_TESTBED_Host *host;
110
111   /**
112    * The template configuration of the peer
113    */
114   const struct GNUNET_CONFIGURATION_Handle *cfg;
115
116   /**
117    * The call back to call when we receive peer create success message
118    */
119   GNUNET_TESTBED_PeerCreateCallback cb;
120
121   /**
122    * The closure for the above callback
123    */
124   void *cls;
125
126   /**
127    * The peer structure to return when we get success message
128    */
129   struct GNUNET_TESTBED_Peer *peer;
130
131 };
132
133
134 /**
135  * Data for OperationType OP_PEER_START and OP_PEER_STOP
136  */
137 struct PeerEventData
138 {
139   /**
140    * The handle of the peer to start
141    */
142   struct GNUNET_TESTBED_Peer *peer;
143
144   /**
145    * The Peer churn callback to call when this operation is completed
146    */
147   GNUNET_TESTBED_PeerChurnCallback pcc;
148
149   /**
150    * Closure for the above callback
151    */
152   void *pcc_cls;
153
154 };
155
156
157 /**
158  * Data for the OperationType OP_PEER_DESTROY;
159  */
160 struct PeerDestroyData
161 {
162   /**
163    * The peer structure
164    */
165   struct GNUNET_TESTBED_Peer *peer;
166
167   //PEERDESTROYDATA
168 };
169
170
171 /**
172  * Data for the OperationType OP_PEER_INFO
173  */
174 struct PeerInfoData
175 {
176   /**
177    * The peer whose information has been requested
178    */
179   struct GNUNET_TESTBED_Peer *peer;
180
181   /**
182    * The Peer info callback to call when this operation has completed
183    */
184   GNUNET_TESTBED_PeerInfoCallback cb;
185
186   /**
187    * The closure for peer info callback
188    */
189   void *cb_cls;
190
191   /**
192    * The type of peer information requested
193    */
194   enum GNUNET_TESTBED_PeerInformationType pit;
195 };
196
197
198 /**
199  * Data structure for OperationType OP_OVERLAY_CONNECT
200  */
201 struct OverlayConnectData
202 {
203
204   /**
205    * Peer A to connect to peer B
206    */
207   struct GNUNET_TESTBED_Peer *p1;
208
209   /**
210    * Peer B
211    */
212   struct GNUNET_TESTBED_Peer *p2;
213
214   /**
215    * The operation completion callback to call once this operation is done
216    */
217   GNUNET_TESTBED_OperationCompletionCallback cb;
218
219   /**
220    * The closure for the above callback
221    */
222   void *cb_cls;
223
224   /**
225    * OperationContext for forwarded operations generated when peer1's controller doesn't have the
226    * configuration of peer2's controller for linking laterally to attemp an
227    * overlay connection between peer 1 and peer 2.
228    */
229   struct OperationContext *sub_opc;
230
231   /**
232    * The starting time of this operation
233    */
234   struct GNUNET_TIME_Absolute tstart;
235
236   /**
237    * Has this operation failed
238    */
239   int failed;
240
241   /**
242    * The timing slot index for this operation
243    */
244   unsigned int tslot_index;
245
246 };
247
248
249 /**
250  * Generate PeerGetConfigurationMessage
251  *
252  * @param peer_id the id of the peer whose information we have to get
253  * @param operation_id the ip of the operation that should be represented in
254  *          the message
255  * @return the PeerGetConfigurationMessage
256  */
257 struct GNUNET_TESTBED_PeerGetConfigurationMessage *
258 GNUNET_TESTBED_generate_peergetconfig_msg_ (uint32_t peer_id,
259                                             uint64_t operation_id);
260
261
262 /**
263  * Adds a peer to the peer list
264  *
265  * @param peer the peer to add to the peer list
266  */
267 void
268 GNUNET_TESTBED_peer_register_ (struct GNUNET_TESTBED_Peer *peer);
269
270
271 /**
272  * Removes a peer from the peer list
273  *
274  * @param peer the peer to remove
275  */
276 void
277 GNUNET_TESTBED_peer_deregister_ (struct GNUNET_TESTBED_Peer *peer);
278
279
280 /**
281  * Frees all peers
282  */
283 void
284 GNUNET_TESTBED_cleanup_peers_ (void);
285
286 #endif
287 /* end of testbed_api_peers.h */