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