-messing up experimentation some more, towards using egos instead of peer identities
[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_EccPublicSignKey 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
180 GNUNET_NETWORK_STRUCT_BEGIN
181
182 /**
183  * Experimentation request message
184  * Used to detect experimentation capability
185  *
186  * This struct is followed by issuer identities:
187  * (issuer_count * struct GNUNET_CRYPTO_EccPublicSignKey)
188  *
189  */
190 struct Experimentation_Request
191 {
192   struct GNUNET_MessageHeader msg;
193   
194   uint32_t capabilities GNUNET_PACKED;
195   
196   uint32_t issuer_count GNUNET_PACKED;
197 };
198
199
200 /**
201  * Experimentation response message
202  * Sent if peer is running the daemon
203  *
204  * This struct is followed by issuer identities:
205  * (issuer_count * struct GNUNET_CRYPTO_EccPublicSignKey)
206  */
207 struct Experimentation_Response
208 {
209   struct GNUNET_MessageHeader msg;
210   
211   uint32_t capabilities GNUNET_PACKED;
212   
213   uint32_t issuer_count GNUNET_PACKED;
214 };
215
216
217 /**
218  * Struct to store information about an experiment issuer
219  */
220 struct Issuer
221 {
222   struct GNUNET_CRYPTO_EccPublicSignKey pubkey;
223 };
224
225
226 /**
227  * Hashmap containing valid experiment issuers
228  * (the key is the hash of the respective public key, 
229  * the values are of type `struct Issuer').
230  */
231 struct GNUNET_CONTAINER_MultiHashMap *valid_issuers;
232
233 /**
234  * Experiment start message
235  *
236  * struct is followed by string with length len_name
237  */
238 struct GED_start_message
239 {
240   struct GNUNET_MessageHeader header;
241   
242   /**
243    * String length of experiment name following the struct
244    */
245   uint32_t len_name GNUNET_PACKED;
246   
247   /**
248    * Experiment issuer 
249    */
250   struct GNUNET_CRYPTO_EccPublicSignKey issuer;
251   
252   /**
253    * Experiment version as timestamp of creation 
254    */
255   struct GNUNET_TIME_AbsoluteNBO version_nbo;
256 };
257
258
259 struct GED_start_ack_message
260 {
261   struct GNUNET_MessageHeader header;
262   
263   /**
264    * String length of experiment name following the struct
265    */
266   uint32_t len_name GNUNET_PACKED;
267   
268   /**
269    * Experiment issuer 
270    */
271   struct GNUNET_CRYPTO_EccPublicSignKey issuer;
272
273   /**
274    * Experiment version as timestamp of creation 
275    */
276   struct GNUNET_TIME_AbsoluteNBO version_nbo;
277 };
278
279
280 struct GED_stop_message
281 {
282   struct GNUNET_MessageHeader header;
283   
284   /**
285    * String length of experiment name following the struct
286    */
287   uint32_t len_name GNUNET_PACKED;
288   
289   /**
290    * Experiment issuer 
291    */
292   struct GNUNET_CRYPTO_EccPublicSignKey issuer;
293   
294   /**
295    * Experiment version as timestamp of creation 
296    */
297   struct GNUNET_TIME_AbsoluteNBO version_nbo;
298 };
299
300 GNUNET_NETWORK_STRUCT_END
301
302
303 int
304 GED_nodes_rts (struct Node *n);
305
306
307 int
308 GED_nodes_send_start (struct Node *n, struct Experiment *e);
309
310
311 /**
312  * Confirm a experiment START with a node
313  *
314  * @return #GNUNET_NO if core was busy with sending, #GNUNET_OK otherwise
315  */
316 int
317 GED_nodes_send_start_ack (struct Node *n, struct Experiment *e);
318
319 /**
320  * Start the nodes management
321  */
322 void
323 GED_nodes_start (void);
324
325
326 /**
327  * Stop the nodes management
328  */
329 void
330 GED_nodes_stop (void);
331
332
333 /**
334  * Print a single capability value
335  *
336  * @param cap capability value
337  * @return the string to print
338  */
339 const char *
340 GED_capability_to_str (uint32_t cap);
341
342
343 /**
344  * Are the capabilities provided?
345  *
346  * @param have bitstring containing the provided capabilities
347  * @param desired bitstring containing the desired capabilities\
348  * @return #GNUNET_YES or #GNUNET_NO
349  */
350 int
351 GED_capabilities_have (uint32_t have, uint32_t desired);
352
353
354 /**
355  * Start the detecting capabilities
356  */
357 void
358 GED_capabilities_start (void);
359
360
361 /**
362  * Stop the detecting capabilities
363  */
364 void
365 GED_capabilities_stop (void);
366
367
368 /**
369  * Start experiments management
370  *
371  * @return #GNUNET_YES or #GNUNET_NO
372  */
373 int
374 GED_experiments_issuer_accepted (const struct GNUNET_CRYPTO_EccPublicSignKey *issuer_ID);
375
376
377 /*
378  * Find an experiment based on issuer name and version
379  *
380  * @param issuer the issuer
381  * @param name experiment name
382  * @param version experiment version
383  * @return the experiment or NULL if not found
384  */
385 struct Experiment *
386 GED_experiments_find (const struct GNUNET_CRYPTO_EccPublicSignKey *issuer,
387                       const char *name,
388                       const struct GNUNET_TIME_Absolute version);
389
390
391 typedef void (*GNUNET_EXPERIMENTATION_experiments_get_cb) (struct Node *n, 
392                                                            struct Experiment *e);
393
394
395 void
396 GED_experiments_get (struct Node *n,
397                      struct GNUNET_CRYPTO_EccPublicSignKey *issuer,
398                      GNUNET_EXPERIMENTATION_experiments_get_cb get_cb);
399
400
401 /**
402  * Start experiments management
403  *
404  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
405  */
406 int
407 GED_experiments_start (void);
408
409
410 /**
411  * Stop experiments management
412  */
413 void
414 GED_experiments_stop (void);
415
416
417 /**
418  * Handle a START message from a remote node
419  *
420  * @param n the node
421  * @param e the experiment
422  */
423 void
424 GED_scheduler_handle_start (struct Node *n, struct Experiment *e);
425
426
427 /**
428  * Handle a START_ACL message from a remote node
429  *
430  * @param n the node
431  * @param e the experiment
432  */
433 void
434 GED_scheduler_handle_start_ack (struct Node *n, struct Experiment *e);
435
436
437 /**
438  * Handle a STOP message from a remote node
439  *
440  * @param n the node
441  * @param e the experiment
442  */
443 void
444 GED_scheduler_handle_stop (struct Node *n, struct Experiment *e);
445
446
447 /**
448  * Add a new experiment for a node
449  *
450  * @param n the node
451  * @param e the experiment
452  * @param outbound are we initiator (#GNUNET_YES) or client (#GNUNET_NO)?
453  */
454 void
455 GED_scheduler_add (struct Node *n,
456                    struct Experiment *e, 
457                    int outbound);
458
459
460 /**
461  * Start the scheduler component
462  */
463 void
464 GED_scheduler_start (void);
465
466
467 /**
468  * Stop the scheduler component
469  */
470 void
471 GED_scheduler_stop (void);
472
473
474 /**
475  * Start the storage component
476  */
477 void
478 GED_storage_start (void);
479
480
481 /**
482  * Stop the storage component
483  */
484 void
485 GED_storage_stop (void);
486
487
488 /* end of gnunet-daemon-experimentation.h */