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