uncrustify as demanded.
[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      SPDX-License-Identifier: AGPL3.0-or-later
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    * State to signify that this peer is invalid
41    */
42   TESTBED_PS_INVALID,
43
44   /**
45    * The peer has been created
46    */
47   TESTBED_PS_CREATED,
48
49   /**
50    * The peer is running
51    */
52   TESTBED_PS_STARTED,
53
54   /**
55    * The peer is stopped
56    */
57   TESTBED_PS_STOPPED,
58 };
59
60
61 /**
62  * A peer controlled by the testing framework.  A peer runs
63  * at a particular host.
64  */
65 struct GNUNET_TESTBED_Peer {
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    * The host where the peer has to be created
110    */
111   struct GNUNET_TESTBED_Host *host;
112
113   /**
114    * The template configuration of the peer
115    */
116   const struct GNUNET_CONFIGURATION_Handle *cfg;
117
118   /**
119    * The call back to call when we receive peer create success message
120    */
121   GNUNET_TESTBED_PeerCreateCallback cb;
122
123   /**
124    * The closure for the above callback
125    */
126   void *cls;
127
128   /**
129    * The peer structure to return when we get success message
130    */
131   struct GNUNET_TESTBED_Peer *peer;
132 };
133
134
135 /**
136  * Data for OperationType OP_PEER_START and OP_PEER_STOP
137  */
138 struct PeerEventData {
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  * Data for the OperationType OP_PEER_DESTROY;
158  */
159 struct PeerDestroyData {
160   /**
161    * The peer structure
162    */
163   struct GNUNET_TESTBED_Peer *peer;
164
165   //PEERDESTROYDATA
166 };
167
168
169 /**
170  * Data for the OperationType OP_PEER_INFO
171  */
172 struct PeerInfoData {
173   /**
174    * The peer whose information has been requested
175    */
176   struct GNUNET_TESTBED_Peer *peer;
177
178   /**
179    * The Peer info callback to call when this operation has completed
180    */
181   GNUNET_TESTBED_PeerInfoCallback cb;
182
183   /**
184    * The closure for peer info callback
185    */
186   void *cb_cls;
187
188   /**
189    * The type of peer information requested
190    */
191   enum GNUNET_TESTBED_PeerInformationType pit;
192 };
193
194
195 /**
196  * Data for the operations of type OP_PEER_RECONFIGURE
197  */
198 struct PeerReconfigureData {
199   /**
200    * The peer whose information has been requested
201    */
202   struct GNUNET_TESTBED_Peer *peer;
203
204   /**
205    * The serialized new configuration template
206    */
207   char *config;
208
209   /**
210    * the size of the serialized configuration
211    */
212   uint16_t cfg_size;
213 };
214
215
216 /**
217  * Data structure for OperationType OP_OVERLAY_CONNECT
218  */
219 struct OverlayConnectData {
220   /**
221    * Peer A to connect to peer B
222    */
223   struct GNUNET_TESTBED_Peer *p1;
224
225   /**
226    * Peer B
227    */
228   struct GNUNET_TESTBED_Peer *p2;
229
230   /**
231    * The operation completion callback to call once this operation is done
232    */
233   GNUNET_TESTBED_OperationCompletionCallback cb;
234
235   /**
236    * The closure for the above callback
237    */
238   void *cb_cls;
239
240   /**
241    * OperationContext for forwarded operations generated when peer1's controller doesn't have the
242    * configuration of peer2's controller for linking laterally to attemp an
243    * overlay connection between peer 1 and peer 2.
244    */
245   struct OperationContext *sub_opc;
246 };
247
248
249 struct ManageServiceData {
250   GNUNET_TESTBED_OperationCompletionCallback cb;
251
252   void *cb_cls;
253
254   struct GNUNET_TESTBED_Peer *peer;
255
256   char *service_name;
257
258   unsigned int start;
259
260   uint16_t msize;
261 };
262
263
264 /**
265  * Generate PeerGetConfigurationMessage
266  *
267  * @param peer_id the id of the peer whose information we have to get
268  * @param operation_id the ip of the operation that should be represented in
269  *          the message
270  * @return the PeerGetConfigurationMessage
271  */
272 struct GNUNET_TESTBED_PeerGetConfigurationMessage *
273 GNUNET_TESTBED_generate_peergetconfig_msg_(uint32_t peer_id,
274                                            uint64_t operation_id);
275
276
277 /**
278  * Adds a peer to the peer list
279  *
280  * @param peer the peer to add to the peer list
281  */
282 void
283 GNUNET_TESTBED_peer_register_(struct GNUNET_TESTBED_Peer *peer);
284
285
286 /**
287  * Removes a peer from the peer list
288  *
289  * @param peer the peer to remove
290  */
291 void
292 GNUNET_TESTBED_peer_deregister_(struct GNUNET_TESTBED_Peer *peer);
293
294
295 /**
296  * Frees all peers
297  */
298 void
299 GNUNET_TESTBED_cleanup_peers_(void);
300
301 #endif
302 /* end of testbed_api_peers.h */