gnunet-daemon-experimentation.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2009 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file experimentation/gnunet-daemon-experimentation.h
  19. * @brief experimentation daemon
  20. * @author Christian Grothoff
  21. * @author Matthias Wachs
  22. */
  23. #ifndef GNUNET_DAEMON_EXPERIMENTATION_H
  24. #define GNUNET_DAEMON_EXPERIMENTATION_H
  25. #include "platform.h"
  26. #include "gnunet_getopt_lib.h"
  27. #include "gnunet_util_lib.h"
  28. #include "gnunet_core_service.h"
  29. #include "gnunet_statistics_service.h"
  30. /**
  31. * Timeout between request and expected response
  32. */
  33. #define EXP_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
  34. /**
  35. * Default experiment frequency
  36. */
  37. #define EXP_DEFAULT_EXP_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 6)
  38. /**
  39. * Default experiment duration
  40. */
  41. #define EXP_DEFAULT_EXP_DUR GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
  42. /**
  43. * Statistics handle shared between components
  44. */
  45. extern struct GNUNET_STATISTICS_Handle *GED_stats;
  46. /**
  47. * Configuration handle shared between components
  48. */
  49. extern struct GNUNET_CONFIGURATION_Handle *GED_cfg;
  50. /**
  51. * Capability value shared between components
  52. */
  53. extern uint32_t GSE_node_capabilities;
  54. /**
  55. * Capabilities a node has or an experiment requires
  56. */
  57. enum GNUNET_EXPERIMENTATION_capabilities
  58. {
  59. NONE = 0,
  60. PLUGIN_TCP = 1,
  61. PLUGIN_UDP = 2,
  62. PLUGIN_UNIX = 4,
  63. PLUGIN_HTTP_CLIENT = 8,
  64. PLUGIN_HTTP_SERVER = 16,
  65. PLUGIN_HTTPS_CLIENT = 32,
  66. PLUGIN_HTTPS_SERVER = 64,
  67. PLUGIN_WLAN = 128,
  68. HAVE_IPV6 = 256,
  69. BEHIND_NAT = 512
  70. };
  71. /**
  72. * Struct to store information about a specific experiment
  73. */
  74. struct Experiment
  75. {
  76. /* Header */
  77. /* ----------------- */
  78. char *name;
  79. /**
  80. * Experiment issuer
  81. */
  82. struct GNUNET_CRYPTO_EddsaPublicKey issuer;
  83. /**
  84. * Experiment version as timestamp of creation
  85. */
  86. struct GNUNET_TIME_Absolute version;
  87. /**
  88. * Description
  89. */
  90. char *description;
  91. /**
  92. * Required capabilities
  93. */
  94. uint32_t required_capabilities;
  95. /* Experiment timing */
  96. /* ----------------- */
  97. /**
  98. * When to start experiment
  99. */
  100. struct GNUNET_TIME_Absolute start;
  101. /**
  102. * When to end experiment
  103. */
  104. struct GNUNET_TIME_Absolute stop;
  105. /**
  106. * How often to run experiment
  107. */
  108. struct GNUNET_TIME_Relative frequency;
  109. /**
  110. * How long to run each execution
  111. */
  112. struct GNUNET_TIME_Relative duration;
  113. /* Experiment itself */
  114. /* ----------------- */
  115. /* TBD */
  116. };
  117. /**
  118. * A experimentation node
  119. */
  120. struct Node
  121. {
  122. /**
  123. * Peer id
  124. */
  125. struct GNUNET_PeerIdentity id;
  126. /**
  127. * Task for response timeout
  128. */
  129. GNUNET_SCHEDULER_TaskIdentifier timeout_task;
  130. /**
  131. * Core transmission handle
  132. */
  133. struct GNUNET_CORE_TransmitHandle *cth;
  134. /**
  135. * Node capabilities
  136. */
  137. uint32_t capabilities;
  138. /**
  139. * Experiment version as timestamp of creation
  140. */
  141. struct GNUNET_TIME_Absolute version;
  142. struct NodeComCtx *e_req_head;
  143. struct NodeComCtx *e_req_tail;
  144. /**
  145. * Array of issuers accepted by this neighbor.
  146. */
  147. struct GNUNET_CRYPTO_EddsaPublicKey *issuer_id;
  148. unsigned int issuer_count;
  149. };
  150. GNUNET_NETWORK_STRUCT_BEGIN
  151. /**
  152. * Experimentation request message
  153. * Used to detect experimentation capability
  154. *
  155. * This struct is followed by issuer identities:
  156. * (issuer_count * struct GNUNET_CRYPTO_EddsaPublicKey)
  157. *
  158. */
  159. struct Experimentation_Request
  160. {
  161. struct GNUNET_MessageHeader msg;
  162. uint32_t capabilities GNUNET_PACKED;
  163. uint32_t issuer_count GNUNET_PACKED;
  164. };
  165. /**
  166. * Experimentation response message
  167. * Sent if peer is running the daemon
  168. *
  169. * This struct is followed by issuer identities:
  170. * (issuer_count * struct GNUNET_CRYPTO_EddsaPublicKey)
  171. */
  172. struct Experimentation_Response
  173. {
  174. struct GNUNET_MessageHeader msg;
  175. uint32_t capabilities GNUNET_PACKED;
  176. uint32_t issuer_count GNUNET_PACKED;
  177. };
  178. /**
  179. * Struct to store information about an experiment issuer
  180. */
  181. struct Issuer
  182. {
  183. struct GNUNET_CRYPTO_EddsaPublicKey pubkey;
  184. };
  185. /**
  186. * Hashmap containing valid experiment issuers
  187. * (the key is the hash of the respective public key,
  188. * the values are of type `struct Issuer').
  189. */
  190. struct GNUNET_CONTAINER_MultiHashMap *valid_issuers;
  191. /**
  192. * Experiment start message
  193. *
  194. * struct is followed by string with length len_name
  195. */
  196. struct GED_start_message
  197. {
  198. struct GNUNET_MessageHeader header;
  199. /**
  200. * String length of experiment name following the struct
  201. */
  202. uint32_t len_name GNUNET_PACKED;
  203. /**
  204. * Experiment issuer
  205. */
  206. struct GNUNET_CRYPTO_EddsaPublicKey issuer;
  207. /**
  208. * Experiment version as timestamp of creation
  209. */
  210. struct GNUNET_TIME_AbsoluteNBO version_nbo;
  211. };
  212. struct GED_start_ack_message
  213. {
  214. struct GNUNET_MessageHeader header;
  215. /**
  216. * String length of experiment name following the struct
  217. */
  218. uint32_t len_name GNUNET_PACKED;
  219. /**
  220. * Experiment issuer
  221. */
  222. struct GNUNET_CRYPTO_EddsaPublicKey issuer;
  223. /**
  224. * Experiment version as timestamp of creation
  225. */
  226. struct GNUNET_TIME_AbsoluteNBO version_nbo;
  227. };
  228. struct GED_stop_message
  229. {
  230. struct GNUNET_MessageHeader header;
  231. /**
  232. * String length of experiment name following the struct
  233. */
  234. uint32_t len_name GNUNET_PACKED;
  235. /**
  236. * Experiment issuer
  237. */
  238. struct GNUNET_CRYPTO_EddsaPublicKey issuer;
  239. /**
  240. * Experiment version as timestamp of creation
  241. */
  242. struct GNUNET_TIME_AbsoluteNBO version_nbo;
  243. };
  244. GNUNET_NETWORK_STRUCT_END
  245. int
  246. GED_nodes_rts (struct Node *n);
  247. int
  248. GED_nodes_send_start (struct Node *n, struct Experiment *e);
  249. /**
  250. * Confirm a experiment START with a node
  251. *
  252. * @return #GNUNET_NO if core was busy with sending, #GNUNET_OK otherwise
  253. */
  254. int
  255. GED_nodes_send_start_ack (struct Node *n, struct Experiment *e);
  256. /**
  257. * Start the nodes management
  258. */
  259. void
  260. GED_nodes_start (void);
  261. /**
  262. * Stop the nodes management
  263. */
  264. void
  265. GED_nodes_stop (void);
  266. /**
  267. * Print a single capability value
  268. *
  269. * @param cap capability value
  270. * @return the string to print
  271. */
  272. const char *
  273. GED_capability_to_str (uint32_t cap);
  274. /**
  275. * Are the capabilities provided?
  276. *
  277. * @param have bitstring containing the provided capabilities
  278. * @param desired bitstring containing the desired capabilities\
  279. * @return #GNUNET_YES or #GNUNET_NO
  280. */
  281. int
  282. GED_capabilities_have (uint32_t have, uint32_t desired);
  283. /**
  284. * Start the detecting capabilities
  285. */
  286. void
  287. GED_capabilities_start (void);
  288. /**
  289. * Stop the detecting capabilities
  290. */
  291. void
  292. GED_capabilities_stop (void);
  293. /**
  294. * Start experiments management
  295. *
  296. * @return #GNUNET_YES or #GNUNET_NO
  297. */
  298. int
  299. GED_experiments_issuer_accepted (const struct GNUNET_CRYPTO_EddsaPublicKey *issuer_ID);
  300. /*
  301. * Find an experiment based on issuer name and version
  302. *
  303. * @param issuer the issuer
  304. * @param name experiment name
  305. * @param version experiment version
  306. * @return the experiment or NULL if not found
  307. */
  308. struct Experiment *
  309. GED_experiments_find (const struct GNUNET_CRYPTO_EddsaPublicKey *issuer,
  310. const char *name,
  311. const struct GNUNET_TIME_Absolute version);
  312. typedef void (*GNUNET_EXPERIMENTATION_experiments_get_cb) (struct Node *n,
  313. struct Experiment *e);
  314. void
  315. GED_experiments_get (struct Node *n,
  316. struct GNUNET_CRYPTO_EddsaPublicKey *issuer,
  317. GNUNET_EXPERIMENTATION_experiments_get_cb get_cb);
  318. /**
  319. * Start experiments management
  320. *
  321. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  322. */
  323. int
  324. GED_experiments_start (void);
  325. /**
  326. * Stop experiments management
  327. */
  328. void
  329. GED_experiments_stop (void);
  330. /**
  331. * Handle a START message from a remote node
  332. *
  333. * @param n the node
  334. * @param e the experiment
  335. */
  336. void
  337. GED_scheduler_handle_start (struct Node *n, struct Experiment *e);
  338. /**
  339. * Handle a START_ACL message from a remote node
  340. *
  341. * @param n the node
  342. * @param e the experiment
  343. */
  344. void
  345. GED_scheduler_handle_start_ack (struct Node *n, struct Experiment *e);
  346. /**
  347. * Handle a STOP message from a remote node
  348. *
  349. * @param n the node
  350. * @param e the experiment
  351. */
  352. void
  353. GED_scheduler_handle_stop (struct Node *n, struct Experiment *e);
  354. /**
  355. * Add a new experiment for a node
  356. *
  357. * @param n the node
  358. * @param e the experiment
  359. * @param outbound are we initiator (#GNUNET_YES) or client (#GNUNET_NO)?
  360. */
  361. void
  362. GED_scheduler_add (struct Node *n,
  363. struct Experiment *e,
  364. int outbound);
  365. /**
  366. * Start the scheduler component
  367. */
  368. void
  369. GED_scheduler_start (void);
  370. /**
  371. * Stop the scheduler component
  372. */
  373. void
  374. GED_scheduler_stop (void);
  375. /**
  376. * Start the storage component
  377. */
  378. void
  379. GED_storage_start (void);
  380. /**
  381. * Stop the storage component
  382. */
  383. void
  384. GED_storage_stop (void);
  385. #endif /* #ifndef GNUNET_DAEMON_EXPERIMENTATION_H */
  386. /* end of gnunet-daemon-experimentation.h */