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