dhtlog.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /*
  2. This file is part of GNUnet
  3. (C) 2006 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 2, 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 src/dht/dhtlog.h
  19. *
  20. * @brief dhtlog is a service that implements logging of dht operations
  21. * for testing
  22. * @author Nathan Evans
  23. */
  24. #ifndef GNUNET_DHTLOG_SERVICE_H
  25. #define GNUNET_DHTLOG_SERVICE_H
  26. #include "gnunet_util_lib.h"
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #if 0 /* keep Emacsens' auto-indent happy */
  31. }
  32. #endif
  33. #endif
  34. typedef enum
  35. {
  36. /**
  37. * Type for a DHT GET message
  38. */
  39. DHTLOG_GET = 1,
  40. /**
  41. * Type for a DHT PUT message
  42. */
  43. DHTLOG_PUT = 2,
  44. /**
  45. * Type for a DHT FIND PEER message
  46. */
  47. DHTLOG_FIND_PEER = 3,
  48. /**
  49. * Type for a DHT RESULT message
  50. */
  51. DHTLOG_RESULT = 4,
  52. /**
  53. * Generic DHT ROUTE message
  54. */
  55. DHTLOG_ROUTE = 5,
  56. } DHTLOG_MESSAGE_TYPES;
  57. struct GNUNET_DHTLOG_TrialInfo
  58. {
  59. /**
  60. * Outside of database identifier for the trial.
  61. */
  62. unsigned int other_identifier;
  63. /** Number of nodes in the trial */
  64. unsigned int num_nodes;
  65. /** Type of initial topology */
  66. unsigned int topology;
  67. /** Topology to blacklist peers to */
  68. unsigned int blacklist_topology;
  69. /** Initially connect peers in this topology */
  70. unsigned int connect_topology;
  71. /** Option to modify connect topology */
  72. unsigned int connect_topology_option;
  73. /** Modifier for the connect option */
  74. float connect_topology_option_modifier;
  75. /** Percentage parameter used for certain topologies */
  76. float topology_percentage;
  77. /** Probability parameter used for certain topologies */
  78. float topology_probability;
  79. /** Number of puts in the trial */
  80. unsigned int puts;
  81. /** Number of gets in the trial */
  82. unsigned int gets;
  83. /** Concurrent puts/gets in the trial (max allowed) */
  84. unsigned int concurrent;
  85. /** How long between initial connection and issuing puts/gets */
  86. unsigned int settle_time;
  87. /** How many times to do put/get loop */
  88. unsigned int num_rounds;
  89. /** Number of malicious getters */
  90. unsigned int malicious_getters;
  91. /** Number of malicious putters */
  92. unsigned int malicious_putters;
  93. /** Number of malicious droppers */
  94. unsigned int malicious_droppers;
  95. /** Frequency of malicious get requests */
  96. unsigned int malicious_get_frequency;
  97. /** Frequency of malicious put requests */
  98. unsigned int malicious_put_frequency;
  99. /** Stop forwarding put/find_peer requests when peer is closer than others */
  100. unsigned int stop_closest;
  101. /** Stop forwarding get requests when data found */
  102. unsigned int stop_found;
  103. /**
  104. * Routing behaves as it would in Kademlia (modified to work recursively,
  105. * and with our other GNUnet constraints).
  106. */
  107. unsigned int strict_kademlia;
  108. /** Number of gets that were reported successful */
  109. unsigned int gets_succeeded;
  110. /** Message for this trial */
  111. char *message;
  112. };
  113. struct GNUNET_DHTLOG_Handle
  114. {
  115. /*
  116. * Inserts the specified query into the dhttests.queries table
  117. *
  118. * @param sqlqueruid inserted query uid
  119. * @param queryid dht query id
  120. * @param type type of the query
  121. * @param hops number of hops query traveled
  122. * @param succeeded whether or not query was successful
  123. * @param node the node the query hit
  124. * @param key the key of the query
  125. *
  126. * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
  127. */
  128. int (*insert_query) (unsigned long long *sqlqueryuid,
  129. unsigned long long queryid, DHTLOG_MESSAGE_TYPES type,
  130. unsigned int hops, int succeeded,
  131. const struct GNUNET_PeerIdentity * node,
  132. const GNUNET_HashCode * key);
  133. /*
  134. * Inserts the specified trial into the dhttests.trials table
  135. *
  136. * @param trial_info general information about this trial
  137. *
  138. * @return GNUNET_OK on success, GNUNET_SYSERR on failure
  139. */
  140. int (*insert_trial) (struct GNUNET_DHTLOG_TrialInfo * trial_info);
  141. /*
  142. * Inserts the specified stats into the dhttests.node_statistics table
  143. *
  144. * @param peer the peer inserting the statistic
  145. * @param route_requests route requests seen
  146. * @param route_forwards route requests forwarded
  147. * @param result_requests route result requests seen
  148. * @param client_requests client requests initiated
  149. * @param result_forwards route results forwarded
  150. * @param gets get requests handled
  151. * @param puts put requests handle
  152. * @param data_inserts data inserted at this node
  153. * @param find_peer_requests find peer requests seen
  154. * @param find_peers_started find peer requests initiated at this node
  155. * @param gets_started get requests initiated at this node
  156. * @param puts_started put requests initiated at this node
  157. * @param find_peer_responses_received find peer responses received locally
  158. * @param get_responses_received get responses received locally
  159. * @param find_peer_responses_sent find peer responses sent from this node
  160. * @param get_responses_sent get responses sent from this node
  161. *
  162. * @return GNUNET_OK on success, GNUNET_SYSERR on failure
  163. */
  164. int (*insert_stat) (const struct GNUNET_PeerIdentity * peer,
  165. unsigned int route_requests, unsigned int route_forwards,
  166. unsigned int result_requests,
  167. unsigned int client_requests,
  168. unsigned int result_forwards, unsigned int gets,
  169. unsigned int puts, unsigned int data_inserts,
  170. unsigned int find_peer_requests,
  171. unsigned int find_peers_started,
  172. unsigned int gets_started, unsigned int puts_started,
  173. unsigned int find_peer_responses_received,
  174. unsigned int get_responses_received,
  175. unsigned int find_peer_responses_sent,
  176. unsigned int get_responses_sent);
  177. /*
  178. * Update dhttests.trials table with current server time as end time
  179. *
  180. * @param gets_succeeded how many gets did the trial report successful
  181. *
  182. * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
  183. */
  184. int (*update_trial) (unsigned int gets_succeeded);
  185. /*
  186. * Update dhttests.nodes table setting the identified
  187. * node as a malicious dropper.
  188. *
  189. * @param peer the peer that was set to be malicious
  190. *
  191. * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
  192. */
  193. int (*set_malicious) (struct GNUNET_PeerIdentity * peer);
  194. /*
  195. * Records the current topology (number of connections, time, trial)
  196. *
  197. * @param num_connections how many connections are in the topology
  198. *
  199. * @return GNUNET_OK on success, GNUNET_SYSERR on failure
  200. */
  201. int (*insert_topology) (int num_connections);
  202. /*
  203. * Records a connection between two peers in the current topology
  204. *
  205. * @param first one side of the connection
  206. * @param second other side of the connection
  207. *
  208. * @return GNUNET_OK on success, GNUNET_SYSERR on failure
  209. */
  210. int (*insert_extended_topology) (const struct GNUNET_PeerIdentity * first,
  211. const struct GNUNET_PeerIdentity * second);
  212. /*
  213. * Inserts the specified stats into the dhttests.generic_stats table
  214. *
  215. * @param peer the peer inserting the statistic
  216. * @param name the name of the statistic
  217. * @param section the section of the statistic
  218. * @param value the value of the statistic
  219. *
  220. * @return GNUNET_OK on success, GNUNET_SYSERR on failure
  221. */
  222. int (*add_generic_stat) (const struct GNUNET_PeerIdentity * peer,
  223. const char *name, const char *section,
  224. uint64_t value);
  225. /*
  226. * Inserts the specified round into the dhttests.rounds table
  227. *
  228. * @param round_type the type of round that is being started
  229. * @param round_count counter for the round (if applicable)
  230. *
  231. * @return GNUNET_OK on success, GNUNET_SYSERR on failure
  232. */
  233. int (*insert_round) (unsigned int round_type, unsigned int round_count);
  234. /*
  235. * Inserts the specified round results into the
  236. * dhttests.processed_round_details table
  237. *
  238. * @param round_type the type of round that is being started
  239. * @param round_count counter for the round (if applicable)
  240. * @param num_messages the total number of messages initiated
  241. * @param num_messages_succeeded the number of messages that succeeded
  242. *
  243. * @return GNUNET_OK on success, GNUNET_SYSERR on failure
  244. */
  245. int (*insert_round_details) (unsigned int round_type,
  246. unsigned int round_count,
  247. unsigned int num_messages,
  248. unsigned int num_messages_succeeded);
  249. /*
  250. * Update dhttests.trials table with total connections information
  251. *
  252. * @param totalConnections the number of connections
  253. *
  254. * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
  255. */
  256. int (*update_connections) (unsigned int totalConnections);
  257. /*
  258. * Update dhttests.trials table with total connections information
  259. *
  260. * @param connections the number of connections
  261. *
  262. * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
  263. */
  264. int (*update_topology) (unsigned int connections);
  265. /*
  266. * Inserts the specified route information into the dhttests.routes table
  267. *
  268. * @param sqlqueruid inserted query uid
  269. * @param queryid dht query id
  270. * @param type type of the query
  271. * @param hops number of hops query traveled
  272. * @param succeeded whether or not query was successful
  273. * @param node the node the query hit
  274. * @param key the key of the query
  275. * @param from_node the node that sent the message to node
  276. * @param to_node next node to forward message to
  277. *
  278. * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
  279. */
  280. int (*insert_route) (unsigned long long *sqlqueryuid,
  281. unsigned long long queryid, unsigned int type,
  282. unsigned int hops, int succeeded,
  283. const struct GNUNET_PeerIdentity * node,
  284. const GNUNET_HashCode * key,
  285. const struct GNUNET_PeerIdentity * from_node,
  286. const struct GNUNET_PeerIdentity * to_node);
  287. /*
  288. * Inserts the specified node into the dhttests.nodes table
  289. *
  290. * @param nodeuid the inserted node uid
  291. * @param node the node to insert
  292. *
  293. * @return GNUNET_OK on success, GNUNET_SYSERR on failure
  294. */
  295. int (*insert_node) (unsigned long long *nodeuid,
  296. struct GNUNET_PeerIdentity * node);
  297. /*
  298. * Inserts the specified dhtkey into the dhttests.dhtkeys table,
  299. * stores return value of dhttests.dhtkeys.dhtkeyuid into dhtkeyuid
  300. *
  301. * @param dhtkeyuid return value
  302. * @param dhtkey hashcode of key to insert
  303. *
  304. * @return GNUNET_OK on success, GNUNET_SYSERR on failure
  305. */
  306. int (*insert_dhtkey) (unsigned long long *dhtkeyuid,
  307. const GNUNET_HashCode * dhtkey);
  308. };
  309. struct GNUNET_DHTLOG_Plugin
  310. {
  311. const struct GNUNET_CONFIGURATION_Handle *cfg;
  312. struct GNUNET_DHTLOG_Handle *dhtlog_api;
  313. };
  314. /**
  315. * Connect to mysql server using the DHT log plugin.
  316. *
  317. * @param c a configuration to use
  318. */
  319. struct GNUNET_DHTLOG_Handle *
  320. GNUNET_DHTLOG_connect (const struct GNUNET_CONFIGURATION_Handle *c);
  321. /**
  322. * Shutdown the module.
  323. */
  324. void
  325. GNUNET_DHTLOG_disconnect (struct GNUNET_DHTLOG_Handle *api);
  326. #if 0 /* keep Emacsens' auto-indent happy */
  327. {
  328. #endif
  329. #ifdef __cplusplus
  330. }
  331. #endif
  332. /* end of dhtlog.h */
  333. #endif