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