change to core pai
[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 {
272   struct GSF_ConnectedPeer *cp;
273
274   cp = GSF_peer_get_ (other);
275   if (NULL == cp)
276   {
277     GNUNET_break (0);
278     return GNUNET_OK;
279   }
280   GSF_cover_content_count++;
281   fprintf (stderr, "FIX ATS DATA!\n");
282   update_latencies (NULL, 0);
283   return GSF_handle_p2p_content_ (cp, message);
284 }
285
286
287 /**
288  * We have a new request, consider forwarding it to the given
289  * peer.
290  *
291  * @param cls the 'struct GSF_PendingRequest'
292  * @param peer identity of the peer
293  * @param cp handle to the connected peer record
294  * @param ppd peer performance data
295  */
296 static void
297 consider_request_for_forwarding (void *cls,
298                                  const struct GNUNET_PeerIdentity *peer,
299                                  struct GSF_ConnectedPeer *cp,
300                                  const struct GSF_PeerPerformanceData *ppd)
301 {
302   struct GSF_PendingRequest *pr = cls;
303
304   if (GNUNET_YES != GSF_pending_request_test_target_ (pr, peer))
305   {
306 #if INSANE_STATISTICS
307     GNUNET_STATISTICS_update (GSF_stats,
308                               gettext_noop ("# Loopback routes suppressed"), 1,
309                               GNUNET_NO);
310 #endif
311     return;
312   }
313   GSF_plan_add_ (cp, pr);
314 }
315
316
317 /**
318  * Function to be called after we're done processing
319  * replies from the local lookup.  If the result status
320  * code indicates that there may be more replies, plan
321  * forwarding the request.
322  *
323  * @param cls closure (NULL)
324  * @param pr the pending request we were processing
325  * @param result final datastore lookup result
326  */
327 static void
328 consider_forwarding (void *cls, struct GSF_PendingRequest *pr,
329                      enum GNUNET_BLOCK_EvaluationResult result)
330 {
331   if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
332     return;                     /* we're done... */
333   GSF_iterate_connected_peers_ (&consider_request_for_forwarding, pr);
334 }
335
336
337 /**
338  * Handle P2P "GET" request.
339  *
340  * @param cls closure, always NULL
341  * @param other the other peer involved (sender or receiver, NULL
342  *        for loopback messages where we are both sender and receiver)
343  * @param message the actual message
344  * @param atsi performance information
345  * @param atsi_count number of records in 'atsi'
346  * @return GNUNET_OK to keep the connection open,
347  *         GNUNET_SYSERR to close it (signal serious error)
348  */
349 static int
350 handle_p2p_get (void *cls, const struct GNUNET_PeerIdentity *other,
351                 const struct GNUNET_MessageHeader *message)
352 {
353   struct GSF_PendingRequest *pr;
354
355   pr = GSF_handle_p2p_query_ (other, message);
356   if (NULL == pr)
357     return GNUNET_SYSERR;
358   GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES;
359   GSF_local_lookup_ (pr, &consider_forwarding, NULL);
360   fprintf (stderr, "FIX ATS DATA!\n");
361   update_latencies (NULL, 0);
362   return GNUNET_OK;
363 }
364
365
366 /**
367  * We're done with the local lookup, now consider
368  * P2P processing (depending on request options and
369  * result status).  Also signal that we can now
370  * receive more request information from the client.
371  *
372  * @param cls the client doing the request ('struct GNUNET_SERVER_Client')
373  * @param pr the pending request we were processing
374  * @param result final datastore lookup result
375  */
376 static void
377 start_p2p_processing (void *cls, struct GSF_PendingRequest *pr,
378                       enum GNUNET_BLOCK_EvaluationResult result)
379 {
380   struct GNUNET_SERVER_Client *client = cls;
381   struct GSF_PendingRequestData *prd;
382
383   prd = GSF_pending_request_get_data_ (pr);
384   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
385               "Finished database lookup for local request `%s' with result %d\n",
386               GNUNET_h2s (&prd->query), result);
387   GNUNET_SERVER_receive_done (client, GNUNET_OK);
388   if (GNUNET_BLOCK_EVALUATION_OK_LAST == result)
389     return;                     /* we're done, 'pr' was already destroyed... */
390   if (0 != (GSF_PRO_LOCAL_ONLY & prd->options))
391   {
392     GSF_pending_request_cancel_ (pr, GNUNET_YES);
393     return;
394   }
395   if (0 == prd->anonymity_level)
396   {
397     switch (prd->type)
398     {
399     case GNUNET_BLOCK_TYPE_FS_DBLOCK:
400     case GNUNET_BLOCK_TYPE_FS_IBLOCK:
401       /* the above block types MAY be available via 'stream' */
402       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
403                   "Considering stream-based download for block\n");
404       GSF_stream_lookup_ (pr);
405       break; 
406     case GNUNET_BLOCK_TYPE_FS_UBLOCK:
407       /* the above block types are in the DHT */
408       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
409                   "Considering DHT-based search for block\n");
410       GSF_dht_lookup_ (pr);
411       break;
412     default:
413       GNUNET_break (0);
414       break;
415     }
416   }
417   consider_forwarding (NULL, pr, result);
418 }
419
420
421 /**
422  * Handle START_SEARCH-message (search request from client).
423  *
424  * @param cls closure
425  * @param client identification of the client
426  * @param message the actual message
427  */
428 static void
429 handle_start_search (void *cls, struct GNUNET_SERVER_Client *client,
430                      const struct GNUNET_MessageHeader *message)
431 {
432   struct GSF_PendingRequest *pr;
433   int ret;
434
435   pr = NULL;
436   ret = GSF_local_client_start_search_handler_ (client, message, &pr);
437   switch (ret)
438   {
439   case GNUNET_SYSERR:
440     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
441     break;
442   case GNUNET_NO:
443     GNUNET_SERVER_receive_done (client, GNUNET_OK);
444     break;
445   case GNUNET_YES:
446     GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES;
447     GSF_local_lookup_ (pr, &start_p2p_processing, client);
448     break;
449   default:
450     GNUNET_assert (0);
451   }
452 }
453
454
455 /**
456  * Task run during shutdown.
457  *
458  * @param cls unused
459  * @param tc unused
460  */
461 static void
462 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
463 {
464   GSF_stream_stop ();
465   if (NULL != GSF_core)
466   {
467     GNUNET_CORE_disconnect (GSF_core);
468     GSF_core = NULL;
469   }
470   GSF_put_done_ ();
471   GSF_push_done_ ();
472   GSF_pending_request_done_ ();
473   GSF_plan_done ();
474   GSF_connected_peer_done_ ();
475   GNUNET_DATASTORE_disconnect (GSF_dsh, GNUNET_NO);
476   GSF_dsh = NULL;
477   GNUNET_DHT_disconnect (GSF_dht);
478   GSF_dht = NULL;
479   GNUNET_BLOCK_context_destroy (GSF_block_ctx);
480   GSF_block_ctx = NULL;
481   GNUNET_CONFIGURATION_destroy (block_cfg);
482   block_cfg = NULL;
483   GNUNET_STATISTICS_destroy (GSF_stats, GNUNET_NO);
484   GSF_stats = NULL;
485   if (GNUNET_SCHEDULER_NO_TASK != cover_age_task)
486   {
487     GNUNET_SCHEDULER_cancel (cover_age_task);
488     cover_age_task = GNUNET_SCHEDULER_NO_TASK;
489   }
490   GNUNET_FS_indexing_done ();
491   GNUNET_LOAD_value_free (datastore_get_load);
492   datastore_get_load = NULL;
493   GNUNET_LOAD_value_free (GSF_rt_entry_lifetime);
494   GSF_rt_entry_lifetime = NULL;
495 }
496
497
498 /**
499  * Function called for each pending request whenever a new
500  * peer connects, giving us a chance to decide about submitting
501  * the existing request to the new peer.
502  *
503  * @param cls the 'struct GSF_ConnectedPeer' of the new peer
504  * @param key query for the request
505  * @param pr handle to the pending request
506  * @return GNUNET_YES to continue to iterate
507  */
508 static int
509 consider_peer_for_forwarding (void *cls, const struct GNUNET_HashCode * key,
510                               struct GSF_PendingRequest *pr)
511 {
512   struct GSF_ConnectedPeer *cp = cls;
513   struct GNUNET_PeerIdentity pid;
514
515   GSF_connected_peer_get_identity_ (cp, &pid);
516   if (GNUNET_YES != GSF_pending_request_test_target_ (pr, &pid))
517   {
518     GNUNET_STATISTICS_update (GSF_stats,
519                               gettext_noop ("# Loopback routes suppressed"), 1,
520                               GNUNET_NO);
521     return GNUNET_YES;
522   }
523   GSF_plan_add_ (cp, pr);
524   return GNUNET_YES;
525 }
526
527
528 /**
529  * Method called whenever a given peer connects.
530  *
531  * @param cls closure, not used
532  * @param peer peer identity this notification is about
533  * @param atsi performance information
534  * @param atsi_count number of records in 'atsi'
535  */
536 static void
537 peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer)
538 {
539   struct GSF_ConnectedPeer *cp;
540
541   if (0 == memcmp (&my_id, peer, sizeof (struct GNUNET_PeerIdentity)))
542     return;
543   fprintf (stderr, "FIX ATS DATA!\n");
544   cp = GSF_peer_connect_handler_ (peer, NULL, 0);
545   if (NULL == cp)
546     return;
547   GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, cp);
548 }
549
550
551 /**
552  * Function called after GNUNET_CORE_connect has succeeded
553  * (or failed for good).  Note that the private key of the
554  * peer is intentionally not exposed here; if you need it,
555  * your process should try to read the private key file
556  * directly (which should work if you are authorized...).
557  *
558  * @param cls closure
559  * @param server handle to the server, NULL if we failed
560  * @param my_identity ID of this peer, NULL if we failed
561  */
562 static void
563 peer_init_handler (void *cls, struct GNUNET_CORE_Handle *server,
564                    const struct GNUNET_PeerIdentity *my_identity)
565 {
566   my_id = *my_identity;
567 }
568
569
570 /**
571  * Process fs requests.
572  *
573  * @param server the initialized server
574  * @param c configuration to use
575  */
576 static int
577 main_init (struct GNUNET_SERVER_Handle *server,
578            const struct GNUNET_CONFIGURATION_Handle *c)
579 {
580   static const struct GNUNET_CORE_MessageHandler no_p2p_handlers[] = {
581     {NULL, 0, 0}
582   };
583   static const struct GNUNET_CORE_MessageHandler p2p_handlers[] = {
584     {&handle_p2p_get,
585      GNUNET_MESSAGE_TYPE_FS_GET, 0},
586     {&handle_p2p_put,
587      GNUNET_MESSAGE_TYPE_FS_PUT, 0},
588     {&GSF_handle_p2p_migration_stop_,
589      GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP,
590      sizeof (struct MigrationStopMessage)},
591     {NULL, 0, 0}
592   };
593   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
594     {&GNUNET_FS_handle_index_start, NULL,
595      GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0},
596     {&GNUNET_FS_handle_index_list_get, NULL,
597      GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET,
598      sizeof (struct GNUNET_MessageHeader)},
599     {&GNUNET_FS_handle_unindex, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX,
600      sizeof (struct UnindexMessage)},
601     {&handle_start_search, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH,
602      0},
603     {NULL, NULL, 0, 0}
604   };
605   int anon_p2p_off;
606
607   /* this option is really only for testcases that need to disable
608      _anonymous_ file-sharing for some reason */
609   anon_p2p_off = (GNUNET_YES ==
610                   GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg,
611                                                         "fs",
612                                                         "DISABLE_ANON_TRANSFER"));  
613   GSF_core =
614       GNUNET_CORE_connect (GSF_cfg, NULL, &peer_init_handler,
615                            &peer_connect_handler, &GSF_peer_disconnect_handler_,
616                            NULL, GNUNET_NO, NULL, GNUNET_NO,
617                            (GNUNET_YES == anon_p2p_off)
618                            ? no_p2p_handlers
619                            : p2p_handlers);
620   if (NULL == GSF_core)
621   {
622     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
623                 _("Failed to connect to `%s' service.\n"), "core");
624     return GNUNET_SYSERR;
625   }
626   GNUNET_SERVER_disconnect_notify (server, &GSF_client_disconnect_handler_,
627                                    NULL);
628   GNUNET_SERVER_add_handlers (server, handlers);
629   cover_age_task =
630       GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
631                                     NULL);
632   datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
633   GSF_stream_start ();
634   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
635                                 NULL);
636   return GNUNET_OK;
637 }
638
639
640 /**
641  * Process fs requests.
642  *
643  * @param cls closure
644  * @param server the initialized server
645  * @param cfg configuration to use
646  */
647 static void
648 run (void *cls, struct GNUNET_SERVER_Handle *server,
649      const struct GNUNET_CONFIGURATION_Handle *cfg)
650 {
651   unsigned long long dqs;
652
653   GSF_cfg = cfg;
654   if (GNUNET_OK !=
655       GNUNET_CONFIGURATION_get_value_size (GSF_cfg, "fs", "DATASTORE_QUEUE_SIZE",
656                                            &dqs))
657   {
658     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_INFO,
659                                "fs", "DATASTORE_QUEUE_SIZE");
660     dqs = 1024;
661   }
662   GSF_datastore_queue_size = (unsigned int) dqs;
663   GSF_enable_randomized_delays =
664       GNUNET_CONFIGURATION_get_value_yesno (cfg, "fs", "DELAY");
665   GSF_dsh = GNUNET_DATASTORE_connect (cfg);
666   if (NULL == GSF_dsh)
667   {
668     GNUNET_SCHEDULER_shutdown ();
669     return;
670   }
671   GSF_rt_entry_lifetime = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_FOREVER_REL);
672   GSF_stats = GNUNET_STATISTICS_create ("fs", cfg);
673   block_cfg = GNUNET_CONFIGURATION_create ();
674   GNUNET_CONFIGURATION_set_value_string (block_cfg, "block", "PLUGINS", "fs");
675   GSF_block_ctx = GNUNET_BLOCK_context_create (block_cfg);
676   GNUNET_assert (NULL != GSF_block_ctx);
677   GSF_dht = GNUNET_DHT_connect (cfg, FS_DHT_HT_SIZE);
678   GSF_plan_init ();
679   GSF_pending_request_init_ ();
680   GSF_connected_peer_init_ ();
681   GSF_push_init_ ();
682   GSF_put_init_ ();
683   if ((GNUNET_OK != GNUNET_FS_indexing_init (cfg, GSF_dsh)) ||
684       (GNUNET_OK != main_init (server, cfg)))
685   {
686     GNUNET_SCHEDULER_shutdown ();
687     shutdown_task (NULL, NULL);
688     return;
689   }
690 }
691
692
693 /**
694  * The main function for the fs service.
695  *
696  * @param argc number of arguments from the command line
697  * @param argv command line arguments
698  * @return 0 ok, 1 on error
699  */
700 int
701 main (int argc, char *const *argv)
702 {
703   return (GNUNET_OK ==
704           GNUNET_SERVICE_run (argc, argv, "fs", GNUNET_SERVICE_OPTION_NONE,
705                               &run, NULL)) ? 0 : 1;
706 }
707
708 /* end of gnunet-service-fs.c */