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