-check return values, fix leak
[oweals/gnunet.git] / src / fs / gnunet-service-fs.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2010 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 3, 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 fs/gnunet-service-fs.h
23  * @brief shared data structures of gnunet-service-fs.c
24  * @author Christian Grothoff
25  */
26 #ifndef GNUNET_SERVICE_FS_H
27 #define GNUNET_SERVICE_FS_H
28
29 #include "gnunet_util_lib.h"
30 #include "gnunet_statistics_service.h"
31 #include "gnunet_transport_service.h"
32 #include "gnunet_core_service.h"
33 #include "gnunet_block_lib.h"
34 #include "fs.h"
35
36
37 /**
38  * By which amount do we decrement the TTL for simple forwarding /
39  * indirection of the query; in milli-seconds.  Set somewhat in
40  * accordance to your network latency (above the time it'll take you
41  * to send a packet and get a reply).
42  */
43 #define TTL_DECREMENT 5000
44
45 /**
46  * At what frequency should our datastore load decrease
47  * automatically (since if we don't use it, clearly the
48  * load must be going down).
49  */
50 #define DATASTORE_LOAD_AUTODECLINE GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
51
52 /**
53  * Only the (mandatory) query is included.
54  */
55 #define GET_MESSAGE_BIT_QUERY_ONLY 0
56
57 /**
58  * The peer identity of a peer waiting for the
59  * reply is included (used if the response
60  * should be transmitted to someone other than
61  * the sender of the GET).
62  */
63 #define GET_MESSAGE_BIT_RETURN_TO 1
64
65 /**
66  * The hash of the public key of the target
67  * namespace is included (for SKS queries).
68  */
69 #define GET_MESSAGE_BIT_SKS_NAMESPACE 2
70
71 /**
72  * The peer identity of a peer that had claimed to have the content
73  * previously is included (can be used if responder-anonymity is not
74  * desired; note that the precursor presumably lacked a direct
75  * connection to the specified peer; still, the receiver is in no way
76  * required to limit forwarding only to the specified peer, it should
77  * only prefer it somewhat if possible).
78  */
79 #define GET_MESSAGE_BIT_TRANSMIT_TO 4
80
81
82 GNUNET_NETWORK_STRUCT_BEGIN
83
84 /**
85  * Message sent between peers asking for FS-content.
86  */
87 struct GetMessage
88 {
89
90   /**
91    * Message type will be GNUNET_MESSAGE_TYPE_FS_GET.
92    */
93   struct GNUNET_MessageHeader header;
94
95   /**
96    * Type of the query (block type).
97    */
98   uint32_t type GNUNET_PACKED;
99
100   /**
101    * How important is this request (network byte order)
102    */
103   uint32_t priority GNUNET_PACKED;
104
105   /**
106    * Relative time to live in MILLISECONDS (network byte order)
107    */
108   int32_t ttl GNUNET_PACKED;
109
110   /**
111    * The content hash should be mutated using this value
112    * before checking against the bloomfilter (used to
113    * get many different filters for the same hash codes).
114    * The number should be in big-endian format when used
115    * for mingling.
116    */
117   uint32_t filter_mutator GNUNET_PACKED;
118
119   /**
120    * Which of the optional hash codes are present at the end of the
121    * message?  See GET_MESSAGE_BIT_xx constants.  For each bit that is
122    * set, an additional GNUNET_HashCode with the respective content
123    * (in order of the bits) will be appended to the end of the GET
124    * message.
125    */
126   uint32_t hash_bitmap GNUNET_PACKED;
127
128   /**
129    * Hashcodes of the file(s) we're looking for.
130    * Details depend on the query type.
131    */
132   GNUNET_HashCode query GNUNET_PACKED;
133
134   /* this is followed by hash codes as specified in the "hash_bitmap";
135    * after that, an optional bloomfilter (with bits set for replies
136    * that should be suppressed) can be present */
137 };
138
139
140 /**
141  * Message send by a peer that wants to be excluded
142  * from migration for a while.
143  */
144 struct MigrationStopMessage
145 {
146   /**
147    * Message type will be
148    * GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP.
149    */
150   struct GNUNET_MessageHeader header;
151
152   /**
153    * Always zero.
154    */
155   uint32_t reserved GNUNET_PACKED;
156
157   /**
158    * How long should the block last?
159    */
160   struct GNUNET_TIME_RelativeNBO duration;
161
162 };
163 GNUNET_NETWORK_STRUCT_END
164
165 /**
166  * A connected peer.
167  */
168 struct GSF_ConnectedPeer;
169
170 /**
171  * An active request.
172  */
173 struct GSF_PendingRequest;
174
175 /**
176  * A local client.
177  */
178 struct GSF_LocalClient;
179
180 /**
181  * Information kept per plan per request ('pe' module).
182  */
183 struct GSF_RequestPlan;
184
185 /**
186  * DLL of request plans a particular pending request is
187  * involved with.
188  */
189 struct GSF_RequestPlanReference;
190
191 /**
192  * Our connection to the datastore.
193  */
194 extern struct GNUNET_DATASTORE_Handle *GSF_dsh;
195
196 /**
197  * Our configuration.
198  */
199 extern const struct GNUNET_CONFIGURATION_Handle *GSF_cfg;
200
201 /**
202  * Handle for reporting statistics.
203  */
204 extern struct GNUNET_STATISTICS_Handle *GSF_stats;
205
206 /**
207  * Pointer to handle to the core service (points to NULL until we've
208  * connected to it).
209  */
210 extern struct GNUNET_CORE_Handle *GSF_core;
211
212 /**
213  * Handle for DHT operations.
214  */
215 extern struct GNUNET_DHT_Handle *GSF_dht;
216
217 /**
218  * How long do requests typically stay in the routing table?
219  */
220 extern struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime;
221
222 /**
223  * Running average of the observed latency to other peers (round trip).
224  */
225 extern struct GNUNET_TIME_Relative GSF_avg_latency;
226
227 /**
228  * Typical priorities we're seeing from other peers right now.  Since
229  * most priorities will be zero, this value is the weighted average of
230  * non-zero priorities seen "recently".  In order to ensure that new
231  * values do not dramatically change the ratio, values are first
232  * "capped" to a reasonable range (+N of the current value) and then
233  * averaged into the existing value by a ratio of 1:N.  Hence
234  * receiving the largest possible priority can still only raise our
235  * "current_priorities" by at most 1.
236  */
237 extern double GSF_current_priorities;
238
239 /**
240  * How many query messages have we received 'recently' that
241  * have not yet been claimed as cover traffic?
242  */
243 extern unsigned int GSF_cover_query_count;
244
245 /**
246  * How many content messages have we received 'recently' that
247  * have not yet been claimed as cover traffic?
248  */
249 extern unsigned int GSF_cover_content_count;
250
251 /**
252  * Our block context.
253  */
254 extern struct GNUNET_BLOCK_Context *GSF_block_ctx;
255
256 /**
257  * Are we introducing randomized delays for better anonymity?
258  */
259 extern int GSF_enable_randomized_delays;
260
261 /**
262  * Test if the DATABASE (GET) load on this peer is too high
263  * to even consider processing the query at
264  * all.
265  *
266  * @return GNUNET_YES if the load is too high to do anything (load high)
267  *         GNUNET_NO to process normally (load normal)
268  *         GNUNET_SYSERR to process for free (load low)
269  */
270 int
271 GSF_test_get_load_too_high_ (uint32_t priority);
272
273
274 /**
275  * We've just now completed a datastore request.  Update our
276  * datastore load calculations.
277  *
278  * @param start time when the datastore request was issued
279  */
280 void
281 GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start);
282
283
284
285 #endif
286 /* end of gnunet-service-fs.h */