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