testbed api peer start
[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 start operation
38      */
39     OP_PEER_START,
40
41     /**
42      * Peer destroy operation
43      */
44     OP_PEER_DESTROY
45   };
46
47
48 /**
49  * Testbed operation structure
50  */
51 struct GNUNET_TESTBED_Operation
52 {
53   /**
54    * next pointer for DLL
55    */
56   struct GNUNET_TESTBED_Operation *next;
57
58   /**
59    * prev pointer for DLL
60    */
61   struct GNUNET_TESTBED_Operation *prev;
62
63   /**
64    * The ID for the operation;
65    */
66   uint64_t operation_id;
67
68   /**
69    * The type of operation
70    */
71   enum OperationType type;
72
73   /**
74    * Data specific to OperationType
75    */
76   void *data;
77 };
78
79
80 /**
81  * The message queue for sending messages to the controller service
82  */
83 struct MessageQueue;
84
85
86 /**
87  * Structure for a controller link
88  */
89 struct ControllerLink;
90
91
92 /**
93  * Handle to interact with a GNUnet testbed controller.  Each
94  * controller has at least one master handle which is created when the
95  * controller is created; this master handle interacts with the
96  * controller process, destroying it destroys the controller (by
97  * closing stdin of the controller process).  Additionally,
98  * controllers can interact with each other (in a P2P fashion); those
99  * links are established via TCP/IP on the controller's service port.
100  */
101 struct GNUNET_TESTBED_Controller
102 {
103
104   /**
105    * The host where the controller is running
106    */
107   struct GNUNET_TESTBED_Host *host;
108
109   /**
110    * The controller callback
111    */
112   GNUNET_TESTBED_ControllerCallback cc;
113
114   /**
115    * The closure for controller callback
116    */
117   void *cc_cls;
118
119   /**
120    * The configuration to use while connecting to controller
121    */
122   struct GNUNET_CONFIGURATION_Handle *cfg;
123
124   /**
125    * The client connection handle to the controller service
126    */
127   struct GNUNET_CLIENT_Connection *client;
128   
129   /**
130    * The head of the message queue
131    */
132   struct MessageQueue *mq_head;
133
134   /**
135    * The tail of the message queue
136    */
137   struct MessageQueue *mq_tail;
138
139   /**
140    * The head of the ControllerLink list
141    */
142   struct ControllerLink *cl_head;
143
144   /**
145    * The tail of the ControllerLink list
146    */
147   struct ControllerLink *cl_tail;
148
149   /**
150    * The client transmit handle
151    */
152   struct GNUNET_CLIENT_TransmitHandle *th;
153
154   /**
155    * The host registration handle; NULL if no current registration requests are
156    * present 
157    */
158   struct GNUNET_TESTBED_HostRegistrationHandle *rh;
159
160   /**
161    * The head of the operation queue
162    */
163   struct GNUNET_TESTBED_Operation *op_head;
164   
165   /**
166    * The tail of the operation queue
167    */
168   struct GNUNET_TESTBED_Operation *op_tail;
169
170   /**
171    * The operation id counter. use current value and increment
172    */
173   uint64_t operation_counter;
174   
175   /**
176    * The controller event mask
177    */
178   uint64_t event_mask;
179
180   /**
181    * Did we start the receive loop yet?
182    */
183   int in_receive;
184
185   /**
186    * Did we create the host for this?
187    */
188   int aux_host;
189 };
190
191
192 /**
193  * Queues a message in send queue for sending to the service
194  *
195  * @param controller the handle to the controller
196  * @param msg the message to queue
197  */
198 void
199 GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
200                                struct GNUNET_MessageHeader *msg);
201
202
203 /**
204  * Compresses given configuration using zlib compress
205  *
206  * @param config the serialized configuration
207  * @param size the size of config
208  * @param xconfig will be set to the compressed configuration (memory is fresly
209  *          allocated) 
210  * @return the size of the xconfig
211  */
212 size_t
213 GNUNET_TESTBED_compress_config_ (const char *config, size_t size,
214                                  char **xconfig);
215
216
217 /**
218  * Adds an operation to the queue of operations
219  *
220  * @param op the operation to add
221  */
222 void
223 GNUNET_TESTBED_operation_add_ (struct GNUNET_TESTBED_Operation *op);
224
225
226 /**
227  * Creates a helper initialization message. Only for testing.
228  *
229  * @param cname the ip address of the controlling host
230  * @param cfg the configuration that has to used to start the testbed service
231  *          thru helper
232  * @return the initialization message
233  */
234 struct GNUNET_TESTBED_HelperInit *
235 GNUNET_TESTBED_create_helper_init_msg_ (const char *cname,
236                                         const struct GNUNET_CONFIGURATION_Handle *cfg);
237
238 #endif