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