bacb53bb1fa6feae04c0284aff3d1c8356993bd2
[oweals/gnunet.git] / src / testbed / testbed_api.h
1 /*
2       This file is part of GNUnet
3       (C) 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.h
23  * @brief Interface for functions internally exported from testbed_api.c
24  * @author Sree Harsha Totakura
25  */
26
27 #ifndef TESTBED_API_H
28 #define TESTBED_API_H
29
30
31 /**
32  * Enumeration of operations
33  */
34 enum OperationType
35   {
36     /**
37      * Peer create operation
38      */
39     OP_PEER_CREATE,
40     
41     /**
42      * Peer start operation
43      */
44     OP_PEER_START,
45
46     /**
47      * Peer stop operation
48      */
49     OP_PEER_STOP,
50
51     /**
52      * Peer destroy operation
53      */
54     OP_PEER_DESTROY,
55
56     /**
57      * Get peer information operation
58      */
59     OP_PEER_INFO,
60
61     /**
62      * Overlay connection operation
63      */
64     OP_OVERLAY_CONNECT,
65
66   };
67
68
69 /**
70  * Testbed operation structure
71  */
72 struct GNUNET_TESTBED_Operation
73 {
74   /**
75    * next pointer for DLL
76    */
77   struct GNUNET_TESTBED_Operation *next;
78
79   /**
80    * prev pointer for DLL
81    */
82   struct GNUNET_TESTBED_Operation *prev;
83
84   /**
85    * The controller on which this operation operates
86    */
87   struct GNUNET_TESTBED_Controller *controller;
88
89   /**
90    * The ID for the operation;
91    */
92   uint64_t operation_id;
93
94   /**
95    * The type of operation
96    */
97   enum OperationType type;
98
99   /**
100    * Data specific to OperationType
101    */
102   void *data;
103 };
104
105
106 /**
107  * The message queue for sending messages to the controller service
108  */
109 struct MessageQueue;
110
111 /**
112  * Structure for a controller link
113  */
114 struct ControllerLink;
115
116 /**
117  * Context information for GNUNET_TESTBED_Operation
118  */
119 struct OperationContext
120 {
121   /**
122    * next ptr for DLL
123    */
124   struct OperationContext *next;
125
126   /**
127    * prev ptr for DLL
128    */
129   struct OperationContext *prev;
130
131   /**
132    * The controller to which this operation context belongs to
133    */
134   struct GNUNET_TESTBED_Controller *c;
135
136   /**
137    * The operation
138    */
139   struct GNUNET_TESTBED_Operation *op;
140
141   /**
142    * Data relevant to the operation
143    */
144   void *data;
145
146   /**
147    * The id of the opearation
148    */
149   uint64_t id;
150
151   /**
152    * The type of operation
153    */
154   enum OperationType type;
155
156   /**
157    * Is this operation completed? (has there been a reply from the service)
158    */
159   int completed;
160
161 };
162
163
164 /**
165  * Handle to interact with a GNUnet testbed controller.  Each
166  * controller has at least one master handle which is created when the
167  * controller is created; this master handle interacts with the
168  * controller process, destroying it destroys the controller (by
169  * closing stdin of the controller process).  Additionally,
170  * controllers can interact with each other (in a P2P fashion); those
171  * links are established via TCP/IP on the controller's service port.
172  */
173 struct GNUNET_TESTBED_Controller
174 {
175
176   /**
177    * The host where the controller is running
178    */
179   struct GNUNET_TESTBED_Host *host;
180
181   /**
182    * The controller callback
183    */
184   GNUNET_TESTBED_ControllerCallback cc;
185
186   /**
187    * The closure for controller callback
188    */
189   void *cc_cls;
190
191   /**
192    * The configuration to use while connecting to controller
193    */
194   struct GNUNET_CONFIGURATION_Handle *cfg;
195
196   /**
197    * The client connection handle to the controller service
198    */
199   struct GNUNET_CLIENT_Connection *client;
200   
201   /**
202    * The head of the message queue
203    */
204   struct MessageQueue *mq_head;
205
206   /**
207    * The tail of the message queue
208    */
209   struct MessageQueue *mq_tail;
210
211   /**
212    * The head of the ControllerLink list
213    */
214   struct ControllerLink *cl_head;
215
216   /**
217    * The tail of the ControllerLink list
218    */
219   struct ControllerLink *cl_tail;
220
221   /**
222    * The client transmit handle
223    */
224   struct GNUNET_CLIENT_TransmitHandle *th;
225
226   /**
227    * The host registration handle; NULL if no current registration requests are
228    * present 
229    */
230   struct GNUNET_TESTBED_HostRegistrationHandle *rh;
231
232   /**
233    * The head of the operation queue (FIXME: Remove, use ocq)
234    */
235   struct GNUNET_TESTBED_Operation *op_head;
236   
237   /**
238    * The tail of the operation queue (FIXME: Remove, use ocq)
239    */
240   struct GNUNET_TESTBED_Operation *op_tail;
241
242   /**
243    * The head of the opeartion context queue
244    */
245   struct OperationContext *ocq_head;
246
247   /**
248    * The tail of the operation context queue
249    */
250   struct OperationContext *ocq_tail;
251
252   /**
253    * Operation queue for simultaneous peer creations
254    */
255   struct OperationQueue *opq_peer_create;
256
257   /**
258    * The operation id counter. use current value and increment
259    */
260   uint64_t operation_counter;
261   
262   /**
263    * The controller event mask
264    */
265   uint64_t event_mask;
266
267   /**
268    * Did we start the receive loop yet?
269    */
270   int in_receive;
271
272   /**
273    * Did we create the host for this?
274    */
275   int aux_host;
276 };
277
278
279 /**
280  * Queues a message in send queue for sending to the service
281  *
282  * @param controller the handle to the controller
283  * @param msg the message to queue
284  */
285 void
286 GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
287                                struct GNUNET_MessageHeader *msg);
288
289
290 /**
291  * Compresses given configuration using zlib compress
292  *
293  * @param config the serialized configuration
294  * @param size the size of config
295  * @param xconfig will be set to the compressed configuration (memory is fresly
296  *          allocated) 
297  * @return the size of the xconfig
298  */
299 size_t
300 GNUNET_TESTBED_compress_config_ (const char *config, size_t size,
301                                  char **xconfig);
302
303
304 /**
305  * Adds an operation to the queue of operations
306  *
307  * @param op the operation to add
308  */
309 void
310 GNUNET_TESTBED_operation_add_ (struct GNUNET_TESTBED_Operation *op);
311
312
313 /**
314  * Creates a helper initialization message. Only for testing.
315  *
316  * @param cname the ip address of the controlling host
317  * @param cfg the configuration that has to used to start the testbed service
318  *          thru helper
319  * @return the initialization message
320  */
321 struct GNUNET_TESTBED_HelperInit *
322 GNUNET_TESTBED_create_helper_init_msg_ (const char *cname,
323                                         const struct GNUNET_CONFIGURATION_Handle *cfg);
324
325 #endif