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