- replace deprecated INCLUDES with AM_CPPFLAGS
[oweals/gnunet.git] / src / experimentation / gnunet-daemon-experimentation.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009 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 experimentation/gnunet-daemon-experimentation.h
23  * @brief experimentation daemon
24  * @author Christian Grothoff
25  * @author Matthias Wachs
26  */
27 #include "platform.h"
28 #include "gnunet_getopt_lib.h"
29 #include "gnunet_util_lib.h"
30 #include "gnunet_core_service.h"
31 #include "gnunet_statistics_service.h"
32
33
34 /**
35  * Timeout between request and expected response
36  */
37 #define EXP_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
38
39 /**
40  * Default experiment frequency
41  */
42 #define EXP_DEFAULT_EXP_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 6)
43
44 /**
45  * Default experiment duration
46  */
47 #define EXP_DEFAULT_EXP_DUR GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
48
49 /**
50  * Statistics handle shared between components
51  */
52 extern struct GNUNET_STATISTICS_Handle *GED_stats;
53
54
55 /**
56  * Configuration handle shared between components
57  */
58 extern struct GNUNET_CONFIGURATION_Handle *GED_cfg;
59
60
61 /**
62  * Capability value shared between components
63  */
64 extern uint32_t GSE_node_capabilities;
65
66
67 extern uint32_t GSE_my_issuer_count;
68
69 extern struct Experimentation_Issuer *GSE_my_issuer;
70
71 /**
72  * Capabilities a node has or an experiment requires
73  */
74 enum GNUNET_EXPERIMENTATION_capabilities
75 {
76         NONE = 0,
77         PLUGIN_TCP = 1,
78         PLUGIN_UDP = 2,
79         PLUGIN_UNIX = 4,
80         PLUGIN_HTTP_CLIENT = 8,
81         PLUGIN_HTTP_SERVER = 16,
82         PLUGIN_HTTPS_CLIENT = 32,
83         PLUGIN_HTTPS_SERVER = 64,
84         PLUGIN_WLAN = 128,
85         HAVE_IPV6 = 256,
86         BEHIND_NAT = 512
87 };
88
89
90 /**
91  * Struct to store information about a specific experiment
92  */
93 struct Experiment
94 {
95         /* Header */
96         /* ----------------- */
97         char *name;
98
99         /* Experiment issuer */
100         struct GNUNET_PeerIdentity issuer;
101
102         /* Experiment version as timestamp of creation */
103         struct GNUNET_TIME_Absolute version;
104
105         /* Description */
106         char *description;
107
108         /* Required capabilities  */
109         uint32_t required_capabilities;
110
111         /* Experiment timing */
112         /* ----------------- */
113
114         /* When to start experiment */
115         struct GNUNET_TIME_Absolute start;
116
117         /* When to end experiment */
118         struct GNUNET_TIME_Absolute stop;
119
120         /* How often to run experiment */
121         struct GNUNET_TIME_Relative frequency;
122
123         /* How long to run each execution  */
124         struct GNUNET_TIME_Relative duration;
125
126
127         /* Experiment itself */
128         /* ----------------- */
129
130         /* TBD */
131 };
132
133
134 /**
135  * A experimentation node
136  */
137 struct Node
138 {
139         /**
140          * Peer id
141          */
142         struct GNUNET_PeerIdentity id;
143
144         /**
145          * Task for response timeout
146          */
147         GNUNET_SCHEDULER_TaskIdentifier timeout_task;
148
149         /**
150          * Core transmission handle
151          */
152         struct GNUNET_CORE_TransmitHandle *cth;
153
154         /**
155          * Node capabilities
156          */
157         uint32_t capabilities;
158
159         /* Experiment version as timestamp of creation */
160         struct GNUNET_TIME_Absolute version;
161
162         uint32_t issuer_count;
163
164         /**
165          * Array of fssuer ids
166          */
167         struct GNUNET_PeerIdentity *issuer_id;
168
169         struct NodeComCtx *e_req_head;
170         struct NodeComCtx *e_req_tail;
171 };
172
173 struct Experimentation_Issuer
174 {
175         struct GNUNET_PeerIdentity issuer_id;
176 };
177
178 GNUNET_NETWORK_STRUCT_BEGIN
179
180 /**
181  * Experimentation request message
182  * Used to detect experimentation capability
183  *
184  * This struct is followed by issuer identities:
185  * (issuer_count * struct Experimentation_Request_Issuer)
186  *
187  */
188 struct Experimentation_Request
189 {
190         struct GNUNET_MessageHeader msg;
191
192         uint32_t capabilities;
193
194         uint32_t issuer_count;
195 };
196
197 /**
198  * Experimentation response message
199  * Sent if peer is running the daemon
200  *
201  * This struct is followed by issuer identities:
202  * (issuer_count * struct Experimentation_Request_Issuer)
203  */
204 struct Experimentation_Response
205 {
206         struct GNUNET_MessageHeader msg;
207
208         uint32_t capabilities;
209
210         uint32_t issuer_count;
211 };
212
213
214 /**
215  * Experiment start message
216  *
217  * struct is followed by string with length len_name
218  */
219 struct GED_start_message
220 {
221         struct GNUNET_MessageHeader header;
222
223         /**
224          * String length of experiment name following the struct
225          */
226         uint32_t len_name;
227
228         /* Experiment issuer */
229         struct GNUNET_PeerIdentity issuer;
230
231         /* Experiment version as timestamp of creation */
232         struct GNUNET_TIME_AbsoluteNBO version_nbo;
233 };
234
235 struct GED_start_ack_message
236 {
237         struct GNUNET_MessageHeader header;
238
239         /**
240          * String length of experiment name following the struct
241          */
242         uint32_t len_name;
243
244         /* Experiment issuer */
245         struct GNUNET_PeerIdentity issuer;
246
247         /* Experiment version as timestamp of creation */
248         struct GNUNET_TIME_AbsoluteNBO version_nbo;
249 };
250
251 struct GED_stop_message
252 {
253         struct GNUNET_MessageHeader header;
254
255         /**
256          * String length of experiment name following the struct
257          */
258         uint32_t len_name;
259
260         /* Experiment issuer */
261         struct GNUNET_PeerIdentity issuer;
262
263         /* Experiment version as timestamp of creation */
264         struct GNUNET_TIME_AbsoluteNBO version_nbo;
265 };
266
267 GNUNET_NETWORK_STRUCT_END
268
269
270 int
271 GED_nodes_rts (struct Node *n);
272
273 int
274 GED_nodes_send_start (struct Node *n, struct Experiment *e);
275
276 /**
277  * Confirm a experiment START with a node
278  *
279  * @return GNUNET_NO if core was busy with sending, GNUNET_OK otherwise
280  */
281 int
282 GED_nodes_send_start_ack (struct Node *n, struct Experiment *e);
283
284 /**
285  * Start the nodes management
286  */
287 void
288 GED_nodes_start ();
289
290
291 /**
292  * Stop the nodes management
293  */
294 void
295 GED_nodes_stop ();
296
297
298 /**
299  * Print a single capability value
300  *
301  * @param cap capability value
302  * @return the string to print
303  */
304 const char *
305 GED_capability_to_str (uint32_t cap);
306
307
308 /**
309  * Are the capabilities provided?
310  *
311  * @param have bitstring containing the provided capabilities
312  * @param desired bitstring containing the desired capabilities\
313  * @return GNUNET_YES or GNUNET_NO
314  */
315 int
316 GED_capabilities_have (uint32_t have, uint32_t desired);
317
318
319 /**
320  * Start the detecting capabilities
321  */
322 void
323 GED_capabilities_start ();
324
325
326 /**
327  * Stop the detecting capabilities
328  */
329 void
330 GED_capabilities_stop ();
331
332
333 /**
334  * Start experiments management
335  *
336  * @return GNUNET_YES or GNUNET_NO
337  */
338 int
339 GED_experiments_issuer_accepted (struct GNUNET_PeerIdentity *issuer_ID);
340
341
342 /*
343  * Find an experiment based on issuer name and version
344  *
345  * @param issuer the issuer
346  * @param name experiment name
347  * @param version experiment version
348  * @return the experiment or NULL if not found
349  */
350 struct Experiment *
351 GED_experiments_find (const struct GNUNET_PeerIdentity *issuer,
352                                                                                         const char *name,
353                                                                                         const struct GNUNET_TIME_Absolute version);
354
355
356 typedef void (*GNUNET_EXPERIMENTATION_experiments_get_cb) (struct Node *n, struct Experiment *e);
357
358
359 void
360 GED_experiments_get (struct Node *n,
361                                                                                                                                                                 struct GNUNET_PeerIdentity *issuer,
362                                                                                                                                                                 GNUNET_EXPERIMENTATION_experiments_get_cb get_cb);
363
364 /**
365  * Start experiments management
366  *
367  * @return GNUNET_OK on success, GNUNET_SYSERR on error
368  */
369 int
370 GED_experiments_start ();
371
372
373 /**
374  * Stop experiments management
375  */
376 void
377 GED_experiments_stop ();
378
379 /**
380  * Handle a START message from a remote node
381  *
382  * @param n the node
383  * @param e the experiment
384  */
385 void
386 GED_scheduler_handle_start (struct Node *n, struct Experiment *e);
387
388
389 /**
390  * Handle a START_ACL message from a remote node
391  *
392  * @param n the node
393  * @param e the experiment
394  */
395 void
396 GED_scheduler_handle_start_ack (struct Node *n, struct Experiment *e);
397
398 /**
399  * Handle a STOP message from a remote node
400  *
401  * @param n the node
402  * @param e the experiment
403  */
404 void
405 GED_scheduler_handle_stop (struct Node *n, struct Experiment *e);
406
407
408 /**
409  * Add a new experiment for a node
410  *
411  * @param n the node
412  * @param e the experiment
413  * @param outbound are we initiator (GNUNET_YES) or client (GNUNET_NO)?
414  */
415 void
416 GED_scheduler_add (struct Node *n, struct Experiment *e, int outbound);
417
418 /**
419  * Start the scheduler component
420  */
421 void
422 GED_scheduler_start ();
423
424
425 /**
426  * Stop the scheduler component
427  */
428 void
429 GED_scheduler_stop ();
430
431
432 /**
433  * Start the storage component
434  */
435 void
436 GED_storage_start ();
437
438
439
440 /**
441  * Stop the storage component
442  */
443 void
444 GED_storage_stop ();
445
446
447 /* end of gnunet-daemon-experimentation.h */