notify performance monitors about destroyed addresses (for #3406)
[oweals/gnunet.git] / src / fs / gnunet-service-fs.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2010, 2011 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.c
23  * @brief gnunet anonymity protocol implementation
24  * @author Christian Grothoff
25  */
26 #include "platform.h"
27 #include <float.h>
28 #include "gnunet_constants.h"
29 #include "gnunet_core_service.h"
30 #include "gnunet_dht_service.h"
31 #include "gnunet_datastore_service.h"
32 #include "gnunet_load_lib.h"
33 #include "gnunet_peer_lib.h"
34 #include "gnunet_protocols.h"
35 #include "gnunet_signatures.h"
36 #include "gnunet_statistics_service.h"
37 #include "gnunet_transport_service.h"
38 #include "gnunet_util_lib.h"
39 #include "gnunet-service-fs_cp.h"
40 #include "gnunet-service-fs_indexing.h"
41 #include "gnunet-service-fs_lc.h"
42 #include "gnunet-service-fs_pe.h"
43 #include "gnunet-service-fs_pr.h"
44 #include "gnunet-service-fs_push.h"
45 #include "gnunet-service-fs_put.h"
46 #include "gnunet-service-fs_cadet.h"
47 #include "fs.h"
48
49 /**
50  * Size for the hash map for DHT requests from the FS
51  * service.  Should be about the number of concurrent
52  * DHT requests we plan to make.
53  */
54 #define FS_DHT_HT_SIZE 1024
55
56
57 /**
58  * How quickly do we age cover traffic?  At the given
59  * time interval, remaining cover traffic counters are
60  * decremented by 1/16th.
61  */
62 #define COVER_AGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
63
64 /**
65  * Collect an instane number of statistics?  May cause excessive IPC.
66  */
67 #define INSANE_STATISTICS GNUNET_NO
68
69
70 /* ****************************** globals ****************************** */
71
72 /**
73  * Our connection to the datastore.
74  */
75 struct GNUNET_DATASTORE_Handle *GSF_dsh;
76
77 /**
78  * Our configuration.
79  */
80 const struct GNUNET_CONFIGURATION_Handle *GSF_cfg;
81
82 /**
83  * Handle for reporting statistics.
84  */
85 struct GNUNET_STATISTICS_Handle *GSF_stats;
86
87 /**
88  * Handle for DHT operations.
89  */
90 struct GNUNET_DHT_Handle *GSF_dht;
91
92 /**
93  * How long do requests typically stay in the routing table?
94  */
95 struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime;
96
97 /**
98  * Running average of the observed latency to other peers (round trip).
99  * Initialized to 5s as the initial default.
100  */
101 struct GNUNET_TIME_Relative GSF_avg_latency = { 500 };
102
103 /**
104  * Handle to ATS service.
105  */
106 struct GNUNET_ATS_PerformanceHandle *GSF_ats;
107
108
109 /**
110  * Typical priorities we're seeing from other peers right now.  Since
111  * most priorities will be zero, this value is the weighted average of
112  * non-zero priorities seen "recently".  In order to ensure that new
113  * values do not dramatically change the ratio, values are first
114  * "capped" to a reasonable range (+N of the current value) and then
115  * averaged into the existing value by a ratio of 1:N.  Hence
116  * receiving the largest possible priority can still only raise our
117  * "current_priorities" by at most 1.
118  */
119 double GSF_current_priorities;
120
121 /**
122  * Size of the datastore queue we assume for common requests.
123  */
124 unsigned int GSF_datastore_queue_size;
125
126 /**
127  * How many query messages have we received 'recently' that
128  * have not yet been claimed as cover traffic?
129  */
130 unsigned int GSF_cover_query_count;
131
132 /**
133  * How many content messages have we received 'recently' that
134  * have not yet been claimed as cover traffic?
135  */
136 unsigned int GSF_cover_content_count;
137
138 /**
139  * Our block context.
140  */
141 struct GNUNET_BLOCK_Context *GSF_block_ctx;
142
143 /**
144  * Pointer to handle to the core service (points to NULL until we've
145  * connected to it).
146  */
147 struct GNUNET_CORE_Handle *GSF_core;
148
149 /**
150  * Are we introducing randomized delays for better anonymity?
151  */
152 int GSF_enable_randomized_delays;
153
154 /* ***************************** locals ******************************* */
155
156 /**
157  * Configuration for block library.
158  */
159 static struct GNUNET_CONFIGURATION_Handle *block_cfg;
160
161 /**
162  * ID of our task that we use to age the cover counters.
163  */
164 static GNUNET_SCHEDULER_TaskIdentifier cover_age_task;
165
166 /**
167  * Datastore 'GET' load tracking.
168  */
169 static struct GNUNET_LOAD_Value *datastore_get_load;
170
171 /**
172  * Identity of this peer.
173  */
174 static struct GNUNET_PeerIdentity my_id;
175
176 /**
177  * Task that periodically ages our cover traffic statistics.
178  *
179  * @param cls unused closure
180  * @param tc task context
181  */
182 static void
183 age_cover_counters (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
184 {
185   GSF_cover_content_count = (GSF_cover_content_count * 15) / 16;
186   GSF_cover_query_count = (GSF_cover_query_count * 15) / 16;
187   cover_age_task =
188       GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
189                                     NULL);
190 }
191
192
193 /**
194  * We've just now completed a datastore request.  Update our
195  * datastore load calculations.
196  *
197  * @param start time when the datastore request was issued
198  */
199 void
200 GSF_update_datastore_delay_ (struct GNUNET_TIME_Absolute start)
201 {
202   struct GNUNET_TIME_Relative delay;
203
204   delay = GNUNET_TIME_absolute_get_duration (start);
205   GNUNET_LOAD_update (datastore_get_load, delay.rel_value_us);
206 }
207
208
209 /**
210  * Test if the DATABASE (GET) load on this peer is too high
211  * to even consider processing the query at
212  * all.
213  *
214  * @param priority priority of the request (used as a reference point to compare with the load)
215  * @return GNUNET_YES if the load is too high to do anything (load high)
216  *         GNUNET_NO to process normally (load normal)
217  *         GNUNET_SYSERR to process for free (load low)
218  */
219 int
220 GSF_test_get_load_too_high_ (uint32_t priority)
221 {
222   double ld;
223
224   ld = GNUNET_LOAD_get_load (datastore_get_load);
225   if (ld < 1)
226     return GNUNET_SYSERR;
227   if (ld <= priority)
228     return GNUNET_NO;
229   return GNUNET_YES;
230 }
231
232
233 /**
234  * We've received peer performance information. Update
235  * our running average for the P2P latency.
236 *
237  * @param cls closure
238  * @param address the address
239  * @param active is this address in active use
240  * @param bandwidth_out assigned outbound bandwidth for the connection
241  * @param bandwidth_in assigned inbound bandwidth for the connection
242  * @param ats performance data for the address (as far as known)
243  * @param ats_count number of performance records in 'ats'
244  */
245 static void
246 update_latencies (void *cls,
247                   const struct GNUNET_HELLO_Address *address,
248                   int active,
249                   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
250                   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
251                   const struct GNUNET_ATS_Information *ats,
252                   uint32_t ats_count)
253 {
254   unsigned int i;
255   struct GNUNET_TIME_Relative latency;
256
257   if (NULL == address)
258   {
259     /* ATS service temporarily disconnected */
260     return;
261   }
262
263   if (GNUNET_YES != active)
264     return;
265   for (i = 0; i < ats_count; i++)
266   {
267     if (GNUNET_ATS_QUALITY_NET_DELAY != ntohl (ats[i].type))
268       continue;
269     latency.rel_value_us = ntohl (ats[i].value);
270     GSF_update_peer_latency_ (&address->peer,
271                               latency);
272     GSF_avg_latency.rel_value_us =
273       (GSF_avg_latency.rel_value_us * 31 +
274        GNUNET_MIN (5000, ntohl (ats[i].value))) / 32;
275     GNUNET_STATISTICS_set (GSF_stats,
276                            gettext_noop
277                            ("# running average P2P latency (ms)"),
278                            GSF_avg_latency.rel_value_us / 1000LL, GNUNET_NO);
279     break;
280   }
281 }
282
283
284 /**
285  * Handle P2P "PUT" message.
286  *
287  * @param cls closure, always NULL
288  * @param other the other peer involved (sender or receiver, NULL
289  *        for loopback messages where we are both sender and receiver)
290  * @param message the actual message
291  * @return GNUNET_OK to keep the connection open,
292  *         GNUNET_SYSERR to close it (signal serious error)
293  */
294 static int
295 handle_p2p_put (void *cls, const struct GNUNET_PeerIdentity *other,
296                 const struct GNUNET_MessageHeader *message)
297 {
298   struct GSF_ConnectedPeer *cp;
299
300   cp = GSF_peer_get_ (other);
301   if (NULL == cp)
302   {
303     GNUNET_break (0);
304     return GNUNET_OK;
305   }
306   GSF_cover_content_count++;
307   return GSF_handle_p2p_content_ (cp, message);
308 }
309
310
311 /**
312  * We have a new request, consider forwarding it to the given
313  * peer.
314  *
315  * @param cls the 'struct GSF_PendingRequest'
316  * @param peer identity of the peer
317  * @param cp handle to the connected peer record
318  * @param ppd peer performance data
319  */
320 static void
321 consider_request_for_forwarding (void *cls,
322                                  const struct GNUNET_PeerIdentity *peer,
323                                  struct GSF_ConnectedPeer *cp,
324                                  const struct GSF_PeerPerformanceData *ppd)
325 {
326   struct GSF_PendingRequest *pr = cls;
327
328   if (GNUNET_YES != GSF_pending_request_test_target_ (pr, peer))
329   {
330 #if INSANE_STATISTICS
331     GNUNET_STATISTICS_update (GSF_stats,
332                               gettext_noop ("# Loopback routes suppressed"), 1,
333                               GNUNET_NO);
334 #endif
335     return;
336   }
337   GSF_plan_add_ (cp, pr);
338 }
339
340
341 /**
342  * Function to be called after we're done processing
343  * replies from the local lookup.  If the result status
344  * code indicates that there may be more replies, plan
345  * forwarding the request.
346  *
347  * @param cls closure (NULL)
348  * @param pr the pending request we were processing
349  * @param result final datastore lookup result
350  */
351 static void
352 consider_forwarding (void *cls, struct GSF_PendingRequest *pr,
353                      enum GNUNET_BLOCK_EvaluationResult result)
354 {
355   if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
356     return;                     /* we're done... */
357   GSF_iterate_connected_peers_ (&consider_request_for_forwarding, pr);
358 }
359
360
361 /**
362  * Handle P2P "GET" request.
363  *
364  * @param cls closure, always NULL
365  * @param other the other peer involved (sender or receiver, NULL
366  *        for loopback messages where we are both sender and receiver)
367  * @param message the actual message
368  * @return GNUNET_OK to keep the connection open,
369  *         GNUNET_SYSERR to close it (signal serious error)
370  */
371 static int
372 handle_p2p_get (void *cls, const struct GNUNET_PeerIdentity *other,
373                 const struct GNUNET_MessageHeader *message)
374 {
375   struct GSF_PendingRequest *pr;
376
377   pr = GSF_handle_p2p_query_ (other, message);
378   if (NULL == pr)
379     return GNUNET_SYSERR;
380   GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES;
381   GSF_local_lookup_ (pr, &consider_forwarding, NULL);
382   return GNUNET_OK;
383 }
384
385
386 /**
387  * We're done with the local lookup, now consider
388  * P2P processing (depending on request options and
389  * result status).  Also signal that we can now
390  * receive more request information from the client.
391  *
392  * @param cls the client doing the request ('struct GNUNET_SERVER_Client')
393  * @param pr the pending request we were processing
394  * @param result final datastore lookup result
395  */
396 static void
397 start_p2p_processing (void *cls, struct GSF_PendingRequest *pr,
398                       enum GNUNET_BLOCK_EvaluationResult result)
399 {
400   struct GNUNET_SERVER_Client *client = cls;
401   struct GSF_PendingRequestData *prd;
402
403   prd = GSF_pending_request_get_data_ (pr);
404   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
405               "Finished database lookup for local request `%s' with result %d\n",
406               GNUNET_h2s (&prd->query), result);
407   GNUNET_SERVER_receive_done (client, GNUNET_OK);
408   if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
409     return;                     /* we're done, 'pr' was already destroyed... */
410   if (0 != (GSF_PRO_LOCAL_ONLY & prd->options))
411   {
412     GSF_pending_request_cancel_ (pr, GNUNET_YES);
413     return;
414   }
415   if (0 == prd->anonymity_level)
416   {
417     switch (prd->type)
418     {
419     case GNUNET_BLOCK_TYPE_FS_DBLOCK:
420     case GNUNET_BLOCK_TYPE_FS_IBLOCK:
421       /* the above block types MAY be available via 'cadet' */
422       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
423                   "Considering cadet-based download for block\n");
424       GSF_cadet_lookup_ (pr);
425       break;
426     case GNUNET_BLOCK_TYPE_FS_UBLOCK:
427       /* the above block types are in the DHT */
428       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
429                   "Considering DHT-based search for block\n");
430       GSF_dht_lookup_ (pr);
431       break;
432     default:
433       GNUNET_break (0);
434       break;
435     }
436   }
437   consider_forwarding (NULL, pr, result);
438 }
439
440
441 /**
442  * Handle START_SEARCH-message (search request from client).
443  *
444  * @param cls closure
445  * @param client identification of the client
446  * @param message the actual message
447  */
448 static void
449 handle_start_search (void *cls, struct GNUNET_SERVER_Client *client,
450                      const struct GNUNET_MessageHeader *message)
451 {
452   struct GSF_PendingRequest *pr;
453   int ret;
454
455   pr = NULL;
456   ret = GSF_local_client_start_search_handler_ (client, message, &pr);
457   switch (ret)
458   {
459   case GNUNET_SYSERR:
460     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
461     break;
462   case GNUNET_NO:
463     GNUNET_SERVER_receive_done (client, GNUNET_OK);
464     break;
465   case GNUNET_YES:
466     GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES;
467     GSF_local_lookup_ (pr, &start_p2p_processing, client);
468     break;
469   default:
470     GNUNET_assert (0);
471   }
472 }
473
474
475 /**
476  * Task run during shutdown.
477  *
478  * @param cls unused
479  * @param tc unused
480  */
481 static void
482 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
483 {
484   GSF_cadet_stop_client ();
485   GSF_cadet_stop_server ();
486   if (NULL != GSF_core)
487   {
488     GNUNET_CORE_disconnect (GSF_core);
489     GSF_core = NULL;
490   }
491   if (NULL != GSF_ats)
492   {
493     GNUNET_ATS_performance_done (GSF_ats);
494     GSF_ats = NULL;
495   }
496   GSF_put_done_ ();
497   GSF_push_done_ ();
498   GSF_pending_request_done_ ();
499   GSF_plan_done ();
500   GSF_connected_peer_done_ ();
501   GNUNET_DATASTORE_disconnect (GSF_dsh, GNUNET_NO);
502   GSF_dsh = NULL;
503   GNUNET_DHT_disconnect (GSF_dht);
504   GSF_dht = NULL;
505   GNUNET_BLOCK_context_destroy (GSF_block_ctx);
506   GSF_block_ctx = NULL;
507   GNUNET_CONFIGURATION_destroy (block_cfg);
508   block_cfg = NULL;
509   GNUNET_STATISTICS_destroy (GSF_stats, GNUNET_NO);
510   GSF_stats = NULL;
511   if (GNUNET_SCHEDULER_NO_TASK != cover_age_task)
512   {
513     GNUNET_SCHEDULER_cancel (cover_age_task);
514     cover_age_task = GNUNET_SCHEDULER_NO_TASK;
515   }
516   GNUNET_FS_indexing_done ();
517   GNUNET_LOAD_value_free (datastore_get_load);
518   datastore_get_load = NULL;
519   GNUNET_LOAD_value_free (GSF_rt_entry_lifetime);
520   GSF_rt_entry_lifetime = NULL;
521 }
522
523
524 /**
525  * Function called for each pending request whenever a new
526  * peer connects, giving us a chance to decide about submitting
527  * the existing request to the new peer.
528  *
529  * @param cls the 'struct GSF_ConnectedPeer' of the new peer
530  * @param key query for the request
531  * @param pr handle to the pending request
532  * @return GNUNET_YES to continue to iterate
533  */
534 static int
535 consider_peer_for_forwarding (void *cls, const struct GNUNET_HashCode * key,
536                               struct GSF_PendingRequest *pr)
537 {
538   struct GSF_ConnectedPeer *cp = cls;
539   struct GNUNET_PeerIdentity pid;
540
541   GSF_connected_peer_get_identity_ (cp, &pid);
542   if (GNUNET_YES != GSF_pending_request_test_target_ (pr, &pid))
543   {
544     GNUNET_STATISTICS_update (GSF_stats,
545                               gettext_noop ("# Loopback routes suppressed"), 1,
546                               GNUNET_NO);
547     return GNUNET_YES;
548   }
549   GSF_plan_add_ (cp, pr);
550   return GNUNET_YES;
551 }
552
553
554 /**
555  * Method called whenever a given peer connects.
556  *
557  * @param cls closure, not used
558  * @param peer peer identity this notification is about
559  */
560 static void
561 peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer)
562 {
563   struct GSF_ConnectedPeer *cp;
564
565   if (0 == memcmp (&my_id, peer, sizeof (struct GNUNET_PeerIdentity)))
566     return;
567   cp = GSF_peer_connect_handler_ (peer);
568   if (NULL == cp)
569     return;
570   GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, cp);
571 }
572
573
574 /**
575  * Function called after GNUNET_CORE_connect has succeeded
576  * (or failed for good).  Note that the private key of the
577  * peer is intentionally not exposed here; if you need it,
578  * your process should try to read the private key file
579  * directly (which should work if you are authorized...).
580  *
581  * @param cls closure
582  * @param my_identity ID of this peer, NULL if we failed
583  */
584 static void
585 peer_init_handler (void *cls,
586                    const struct GNUNET_PeerIdentity *my_identity)
587 {
588   my_id = *my_identity;
589 }
590
591
592 /**
593  * Process fs requests.
594  *
595  * @param server the initialized server
596  * @param c configuration to use
597  */
598 static int
599 main_init (struct GNUNET_SERVER_Handle *server,
600            const struct GNUNET_CONFIGURATION_Handle *c)
601 {
602   static const struct GNUNET_CORE_MessageHandler no_p2p_handlers[] = {
603     {NULL, 0, 0}
604   };
605   static const struct GNUNET_CORE_MessageHandler p2p_handlers[] = {
606     {&handle_p2p_get,
607      GNUNET_MESSAGE_TYPE_FS_GET, 0},
608     {&handle_p2p_put,
609      GNUNET_MESSAGE_TYPE_FS_PUT, 0},
610     {&GSF_handle_p2p_migration_stop_,
611      GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP,
612      sizeof (struct MigrationStopMessage)},
613     {NULL, 0, 0}
614   };
615   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
616     {&GNUNET_FS_handle_index_start, NULL,
617      GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0},
618     {&GNUNET_FS_handle_index_list_get, NULL,
619      GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET,
620      sizeof (struct GNUNET_MessageHeader)},
621     {&GNUNET_FS_handle_unindex, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX,
622      sizeof (struct UnindexMessage)},
623     {&handle_start_search, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH,
624      0},
625     {NULL, NULL, 0, 0}
626   };
627   int anon_p2p_off;
628
629   /* this option is really only for testcases that need to disable
630      _anonymous_ file-sharing for some reason */
631   anon_p2p_off = (GNUNET_YES ==
632                   GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg,
633                                                         "fs",
634                                                         "DISABLE_ANON_TRANSFER"));
635   GSF_core =
636       GNUNET_CORE_connect (GSF_cfg, NULL, &peer_init_handler,
637                            &peer_connect_handler, &GSF_peer_disconnect_handler_,
638                            NULL, GNUNET_NO, NULL, GNUNET_NO,
639                            (GNUNET_YES == anon_p2p_off)
640                            ? no_p2p_handlers
641                            : p2p_handlers);
642   if (NULL == GSF_core)
643   {
644     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
645                 _("Failed to connect to `%s' service.\n"), "core");
646     return GNUNET_SYSERR;
647   }
648   GNUNET_SERVER_disconnect_notify (server, &GSF_client_disconnect_handler_,
649                                    NULL);
650   GNUNET_SERVER_add_handlers (server, handlers);
651   cover_age_task =
652       GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
653                                     NULL);
654   datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
655   GSF_cadet_start_server ();
656   GSF_cadet_start_client ();
657   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
658                                 NULL);
659   return GNUNET_OK;
660 }
661
662
663 /**
664  * Process fs requests.
665  *
666  * @param cls closure
667  * @param server the initialized server
668  * @param cfg configuration to use
669  */
670 static void
671 run (void *cls, struct GNUNET_SERVER_Handle *server,
672      const struct GNUNET_CONFIGURATION_Handle *cfg)
673 {
674   unsigned long long dqs;
675
676   GSF_cfg = cfg;
677   if (GNUNET_OK !=
678       GNUNET_CONFIGURATION_get_value_size (GSF_cfg, "fs", "DATASTORE_QUEUE_SIZE",
679                                            &dqs))
680   {
681     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_INFO,
682                                "fs", "DATASTORE_QUEUE_SIZE");
683     dqs = 1024;
684   }
685   GSF_datastore_queue_size = (unsigned int) dqs;
686   GSF_enable_randomized_delays =
687       GNUNET_CONFIGURATION_get_value_yesno (cfg, "fs", "DELAY");
688   GSF_dsh = GNUNET_DATASTORE_connect (cfg);
689   if (NULL == GSF_dsh)
690   {
691     GNUNET_SCHEDULER_shutdown ();
692     return;
693   }
694   GSF_rt_entry_lifetime = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_FOREVER_REL);
695   GSF_stats = GNUNET_STATISTICS_create ("fs", cfg);
696   block_cfg = GNUNET_CONFIGURATION_create ();
697   GSF_block_ctx = GNUNET_BLOCK_context_create (block_cfg);
698   GNUNET_assert (NULL != GSF_block_ctx);
699   GSF_dht = GNUNET_DHT_connect (cfg, FS_DHT_HT_SIZE);
700   GSF_plan_init ();
701   GSF_pending_request_init_ ();
702   GSF_connected_peer_init_ ();
703   GSF_ats = GNUNET_ATS_performance_init (GSF_cfg, &update_latencies, NULL);
704   GSF_push_init_ ();
705   GSF_put_init_ ();
706   if ((GNUNET_OK != GNUNET_FS_indexing_init (cfg, GSF_dsh)) ||
707       (GNUNET_OK != main_init (server, cfg)))
708   {
709     GNUNET_SCHEDULER_shutdown ();
710     shutdown_task (NULL, NULL);
711     return;
712   }
713 }
714
715
716 /**
717  * The main function for the fs service.
718  *
719  * @param argc number of arguments from the command line
720  * @param argv command line arguments
721  * @return 0 ok, 1 on error
722  */
723 int
724 main (int argc, char *const *argv)
725 {
726   return (GNUNET_OK ==
727           GNUNET_SERVICE_run (argc, argv, "fs", GNUNET_SERVICE_OPTION_NONE,
728                               &run, NULL)) ? 0 : 1;
729 }
730
731 /* end of gnunet-service-fs.c */