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