test case fix, dht bugfix
[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_TrialInfo
72 {
73   /**
74    * Trialuid, possibly set by insert call.
75    */
76   unsigned long long trialuid;
77
78   /**
79    * Outside of database identifier for the trial.
80    */
81   unsigned int other_identifier;
82
83   /** Number of nodes in the trial */
84   unsigned int num_nodes;
85
86   /** Type of initial topology */
87   unsigned int topology;
88
89   /** Topology to blacklist peers to */
90   unsigned int blacklist_topology;
91
92   /** Initially connect peers in this topology */
93   unsigned int connect_topology;
94
95   /** Option to modify connect topology */
96   unsigned int connect_topology_option;
97
98   /** Modifier for the connect option */
99   float connect_topology_option_modifier;
100
101   /** Percentage parameter used for certain topologies */
102   float topology_percentage;
103
104   /** Probability parameter used for certain topologies */
105   float topology_probability;
106
107   /** Number of puts in the trial */
108   unsigned int puts;
109
110   /** Number of gets in the trial */
111   unsigned int gets;
112
113   /** Concurrent puts/gets in the trial (max allowed) */
114   unsigned int concurrent;
115
116   /** How long between initial connection and issuing puts/gets */
117   unsigned int settle_time;
118
119   /** How many times to do put/get loop */
120   unsigned int num_rounds;
121
122   /** Number of malicious getters */
123   unsigned int malicious_getters;
124
125   /** Number of malicious putters */
126   unsigned int malicious_putters;
127
128   /** Number of malicious droppers */
129   unsigned int malicious_droppers;
130
131   /** Frequency of malicious get requests */
132   unsigned int malicious_get_frequency;
133
134   /** Frequency of malicious put requests */
135   unsigned int malicious_put_frequency;
136
137   /** Stop forwarding put/find_peer requests when peer is closer than others */
138   unsigned int stop_closest;
139
140   /** Stop forwarding get requests when data found */
141   unsigned int stop_found;
142
143   /**
144    * Routing behaves as it would in Kademlia (modified to work recursively,
145    * and with our other GNUnet constraints.
146    */
147   unsigned int strict_kademlia;
148
149   /** Number of gets that were reported successful */
150   unsigned int gets_succeeded;
151
152   /** Message for this trial */
153   char *message;
154 };
155
156 struct GNUNET_DHTLOG_Handle
157 {
158
159   /*
160    * Inserts the specified query into the dhttests.queries table
161    *
162    * @param sqlqueruid inserted query uid
163    * @param queryid dht query id
164    * @param type type of the query
165    * @param hops number of hops query traveled
166    * @param succeeded whether or not query was successful
167    * @param node the node the query hit
168    * @param key the key of the query
169    *
170    * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
171    */
172   int (*insert_query) (unsigned long long *sqlqueryuid,
173                        unsigned long long queryid, DHTLOG_MESSAGE_TYPES type,
174                        unsigned int hops,
175                        int succeeded,
176                        const struct GNUNET_PeerIdentity * node,
177                        const GNUNET_HashCode * key);
178
179   /*
180    * Inserts the specified trial into the dhttests.trials table
181    *
182    * @param trial_info general information about this trial
183    *
184    * @return GNUNET_OK on success, GNUNET_SYSERR on failure
185    */
186   int (*insert_trial) (struct GNUNET_DHTLOG_TrialInfo *trial_info);
187
188   /*
189    * Inserts the specified stats into the dhttests.node_statistics table
190    *
191    * @param peer the peer inserting the statistic
192    * @param route_requests route requests seen
193    * @param route_forwards route requests forwarded
194    * @param result_requests route result requests seen
195    * @param client_requests client requests initiated
196    * @param result_forwards route results forwarded
197    * @param gets get requests handled
198    * @param puts put requests handle
199    * @param data_inserts data inserted at this node
200    * @param find_peer_requests find peer requests seen
201    * @param find_peers_started find peer requests initiated at this node
202    * @param gets_started get requests initiated at this node
203    * @param puts_started put requests initiated at this node
204    * @param find_peer_responses_received find peer responses received locally
205    * @param get_responses_received get responses received locally
206    * @param find_peer_responses_sent find peer responses sent from this node
207    * @param get_responses_sent get responses sent from this node
208    *
209    * @return GNUNET_OK on success, GNUNET_SYSERR on failure
210    */
211   int (*insert_stat)
212      (const struct GNUNET_PeerIdentity *peer, unsigned int route_requests,
213       unsigned int route_forwards, unsigned int result_requests,
214       unsigned int client_requests, unsigned int result_forwards,
215       unsigned int gets, unsigned int puts,
216       unsigned int data_inserts, unsigned int find_peer_requests,
217       unsigned int find_peers_started, unsigned int gets_started,
218       unsigned int puts_started, unsigned int find_peer_responses_received,
219       unsigned int get_responses_received, unsigned int find_peer_responses_sent,
220       unsigned int get_responses_sent);
221
222   /*
223    * Update dhttests.trials table with current server time as end time
224    *
225    * @param trialuid trial to update
226    * @param gets_succeeded how many gets did the trial report successful
227    *
228    * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
229    */
230   int (*update_trial) (unsigned long long trialuid,
231                        unsigned int gets_succeeded);
232
233   /*
234    * Update dhttests.nodes table setting the identified
235    * node as a malicious dropper.
236    *
237    * @param peer the peer that was set to be malicious
238    *
239    * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
240    */
241   int (*set_malicious) (struct GNUNET_PeerIdentity *peer);
242
243   /*
244    * Records the current topology (number of connections, time, trial)
245    *
246    * @param num_connections how many connections are in the topology
247    *
248    * @return GNUNET_OK on success, GNUNET_SYSERR on failure
249    */
250   int (*insert_topology) (int num_connections);
251
252   /*
253    * Records a connection between two peers in the current topology
254    *
255    * @param first one side of the connection
256    * @param second other side of the connection
257    *
258    * @return GNUNET_OK on success, GNUNET_SYSERR on failure
259    */
260   int (*insert_extended_topology) (const struct GNUNET_PeerIdentity *first, const struct GNUNET_PeerIdentity *second);
261
262   /*
263    * Inserts the specified stats into the dhttests.generic_stats table
264    *
265    * @param peer the peer inserting the statistic
266    * @param name the name of the statistic
267    * @param section the section of the statistic
268    * @param value the value of the statistic
269    *
270    * @return GNUNET_OK on success, GNUNET_SYSERR on failure
271    */
272   int
273   (*add_generic_stat) (const struct GNUNET_PeerIdentity *peer,
274                        const char *name,
275                        const char *section, uint64_t value);
276
277   /*
278    * Inserts the specified round into the dhttests.rounds table
279    *
280    * @param round_type the type of round that is being started
281    * @param round_count counter for the round (if applicable)
282    *
283    * @return GNUNET_OK on success, GNUNET_SYSERR on failure
284    */
285   int (*insert_round) (unsigned int round_type, unsigned int round_count);
286
287   /*
288    * Update dhttests.trials table with total connections information
289    *
290    * @param trialuid the trialuid to update
291    * @param totalConnections the number of connections
292    *
293    * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
294    */
295   int (*update_connections) (unsigned long long trialuid,
296                              unsigned int totalConnections);
297
298   /*
299    * Update dhttests.trials table with total connections information
300    *
301    * @param connections the number of connections
302    *
303    * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
304    */
305   int (*update_topology) (unsigned int connections);
306
307   /*
308    * Inserts the specified route information into the dhttests.routes table
309    *
310    * @param sqlqueruid inserted query uid
311    * @param queryid dht query id
312    * @param type type of the query
313    * @param hops number of hops query traveled
314    * @param succeeded whether or not query was successful
315    * @param node the node the query hit
316    * @param key the key of the query
317    * @param from_node the node that sent the message to node
318    * @param to_node next node to forward message to
319    *
320    * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
321    */
322   int (*insert_route) (unsigned long long *sqlqueryuid,
323                        unsigned long long queryid,
324                        unsigned int type,
325                        unsigned int hops,
326                        int succeeded,
327                        const struct GNUNET_PeerIdentity * node,
328                        const GNUNET_HashCode * key,
329                        const struct GNUNET_PeerIdentity * from_node,
330                        const struct GNUNET_PeerIdentity * to_node);
331
332   /*
333    * Inserts the specified node into the dhttests.nodes table
334    *
335    * @param nodeuid the inserted node uid
336    * @param node the node to insert
337    *
338    * @return GNUNET_OK on success, GNUNET_SYSERR on failure
339    */
340   int (*insert_node) (unsigned long long *nodeuid,
341                       struct GNUNET_PeerIdentity * node);
342
343   /*
344    * Inserts the specified dhtkey into the dhttests.dhtkeys table,
345    * stores return value of dhttests.dhtkeys.dhtkeyuid into dhtkeyuid
346    *
347    * @param dhtkeyuid return value
348    * @param dhtkey hashcode of key to insert
349    *
350    * @return GNUNET_OK on success, GNUNET_SYSERR on failure
351    */
352   int (*insert_dhtkey) (unsigned long long *dhtkeyuid,
353                         const GNUNET_HashCode * dhtkey);
354
355 };
356
357 struct GNUNET_DHTLOG_Plugin
358 {
359   const struct GNUNET_CONFIGURATION_Handle *cfg;
360
361   struct GNUNET_DHTLOG_Handle *dhtlog_api;
362 };
363
364 /**
365  * Connect to mysql server using the DHT log plugin.
366  *
367  * @param c a configuration to use
368  */
369 struct GNUNET_DHTLOG_Handle *
370 GNUNET_DHTLOG_connect (const struct GNUNET_CONFIGURATION_Handle *c);
371
372 /**
373  * Shutdown the module.
374  */
375 void
376 GNUNET_DHTLOG_disconnect (struct GNUNET_DHTLOG_Handle *api);
377
378
379 #if 0                           /* keep Emacsens' auto-indent happy */
380 {
381 #endif
382 #ifdef __cplusplus
383 }
384 #endif
385
386 /* end of dhtlog.h */
387 #endif