-enabling stream test fully
[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       GSF_stream_lookup_ (pr);
405       break; 
406     case GNUNET_BLOCK_TYPE_FS_KBLOCK:
407     case GNUNET_BLOCK_TYPE_FS_SBLOCK:
408     case GNUNET_BLOCK_TYPE_FS_NBLOCK:
409       /* the above block types are in the DHT */
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                       const struct GNUNET_ATS_Information *atsi,
539                       unsigned int atsi_count)
540 {
541   struct GSF_ConnectedPeer *cp;
542
543   if (0 == memcmp (&my_id, peer, sizeof (struct GNUNET_PeerIdentity)))
544     return;
545   cp = GSF_peer_connect_handler_ (peer, atsi, atsi_count);
546   if (NULL == cp)
547     return;
548   GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, cp);
549 }
550
551
552 /**
553  * Function called after GNUNET_CORE_connect has succeeded
554  * (or failed for good).  Note that the private key of the
555  * peer is intentionally not exposed here; if you need it,
556  * your process should try to read the private key file
557  * directly (which should work if you are authorized...).
558  *
559  * @param cls closure
560  * @param server handle to the server, NULL if we failed
561  * @param my_identity ID of this peer, NULL if we failed
562  */
563 static void
564 peer_init_handler (void *cls, struct GNUNET_CORE_Handle *server,
565                    const struct GNUNET_PeerIdentity *my_identity)
566 {
567   my_id = *my_identity;
568 }
569
570
571 /**
572  * Process fs requests.
573  *
574  * @param server the initialized server
575  * @param c configuration to use
576  */
577 static int
578 main_init (struct GNUNET_SERVER_Handle *server,
579            const struct GNUNET_CONFIGURATION_Handle *c)
580 {
581   static const struct GNUNET_CORE_MessageHandler no_p2p_handlers[] = {
582     {NULL, 0, 0}
583   };
584   static const struct GNUNET_CORE_MessageHandler p2p_handlers[] = {
585     {&handle_p2p_get,
586      GNUNET_MESSAGE_TYPE_FS_GET, 0},
587     {&handle_p2p_put,
588      GNUNET_MESSAGE_TYPE_FS_PUT, 0},
589     {&GSF_handle_p2p_migration_stop_,
590      GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP,
591      sizeof (struct MigrationStopMessage)},
592     {NULL, 0, 0}
593   };
594   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
595     {&GNUNET_FS_handle_index_start, NULL,
596      GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0},
597     {&GNUNET_FS_handle_index_list_get, NULL,
598      GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET,
599      sizeof (struct GNUNET_MessageHeader)},
600     {&GNUNET_FS_handle_unindex, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX,
601      sizeof (struct UnindexMessage)},
602     {&handle_start_search, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH,
603      0},
604     {NULL, NULL, 0, 0}
605   };
606   int anon_p2p_off;
607
608   /* this option is really only for testcases that need to disable
609      _anonymous_ file-sharing for some reason */
610   anon_p2p_off = (GNUNET_YES ==
611                   GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg,
612                                                         "fs",
613                                                         "DISABLE_ANON_TRANSFER"));  
614   GSF_core =
615       GNUNET_CORE_connect (GSF_cfg, NULL, &peer_init_handler,
616                            &peer_connect_handler, &GSF_peer_disconnect_handler_,
617                            NULL, GNUNET_NO, NULL, GNUNET_NO,
618                            (GNUNET_YES == anon_p2p_off)
619                            ? no_p2p_handlers
620                            : p2p_handlers);
621   if (NULL == GSF_core)
622   {
623     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
624                 _("Failed to connect to `%s' service.\n"), "core");
625     return GNUNET_SYSERR;
626   }
627   GNUNET_SERVER_disconnect_notify (server, &GSF_client_disconnect_handler_,
628                                    NULL);
629   GNUNET_SERVER_add_handlers (server, handlers);
630   cover_age_task =
631       GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
632                                     NULL);
633   datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
634   GSF_stream_start ();
635   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
636                                 NULL);
637   return GNUNET_OK;
638 }
639
640
641 /**
642  * Process fs requests.
643  *
644  * @param cls closure
645  * @param server the initialized server
646  * @param cfg configuration to use
647  */
648 static void
649 run (void *cls, struct GNUNET_SERVER_Handle *server,
650      const struct GNUNET_CONFIGURATION_Handle *cfg)
651 {
652   unsigned long long dqs;
653
654   GSF_cfg = cfg;
655   if (GNUNET_OK !=
656       GNUNET_CONFIGURATION_get_value_size (GSF_cfg, "fs", "DATASTORE_QUEUE_SIZE",
657                                            &dqs))
658   {
659     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_INFO,
660                                "fs", "DATASTORE_QUEUE_SIZE");
661     dqs = 1024;
662   }
663   GSF_datastore_queue_size = (unsigned int) dqs;
664   GSF_enable_randomized_delays =
665       GNUNET_CONFIGURATION_get_value_yesno (cfg, "fs", "DELAY");
666   GSF_dsh = GNUNET_DATASTORE_connect (cfg);
667   if (NULL == GSF_dsh)
668   {
669     GNUNET_SCHEDULER_shutdown ();
670     return;
671   }
672   GSF_rt_entry_lifetime = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_FOREVER_REL);
673   GSF_stats = GNUNET_STATISTICS_create ("fs", cfg);
674   block_cfg = GNUNET_CONFIGURATION_create ();
675   GNUNET_CONFIGURATION_set_value_string (block_cfg, "block", "PLUGINS", "fs");
676   GSF_block_ctx = GNUNET_BLOCK_context_create (block_cfg);
677   GNUNET_assert (NULL != GSF_block_ctx);
678   GSF_dht = GNUNET_DHT_connect (cfg, FS_DHT_HT_SIZE);
679   GSF_plan_init ();
680   GSF_pending_request_init_ ();
681   GSF_connected_peer_init_ ();
682   GSF_push_init_ ();
683   GSF_put_init_ ();
684   if ((GNUNET_OK != GNUNET_FS_indexing_init (cfg, GSF_dsh)) ||
685       (GNUNET_OK != main_init (server, cfg)))
686   {
687     GNUNET_SCHEDULER_shutdown ();
688     shutdown_task (NULL, NULL);
689     return;
690   }
691 }
692
693
694 /**
695  * The main function for the fs service.
696  *
697  * @param argc number of arguments from the command line
698  * @param argv command line arguments
699  * @return 0 ok, 1 on error
700  */
701 int
702 main (int argc, char *const *argv)
703 {
704   return (GNUNET_OK ==
705           GNUNET_SERVICE_run (argc, argv, "fs", GNUNET_SERVICE_OPTION_NONE,
706                               &run, NULL)) ? 0 : 1;
707 }
708
709 /* end of gnunet-service-fs.c */