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