2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
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 2, or (at your
8 option) any later version.
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.
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.
22 * @file fs/gnunet-service-fs.c
23 * @brief program that provides the file-sharing service
24 * @author Christian Grothoff
27 * - fix gazillion of minor FIXME's
28 * - possible major issue: we may queue "gazillions" of (K|S)Blocks for the
29 * core to transmit to another peer; need to make sure this is bounded overall...
30 * - randomly delay processing for improved anonymity (can wait)
31 * - content migration (put in local DS) (can wait)
32 * - handle some special cases when forwarding replies based on tracked requests (can wait)
33 * - tracking of success correlations for hot-path routing (can wait)
34 * - various load-based actions (can wait)
35 * - validation of KSBLOCKS (can wait)
36 * - remove on-demand blocks if they keep failing (can wait)
37 * - check that we decrement PIDs always where necessary (can wait)
38 * - find out how to use core-pulling instead of pushing (at least for some cases)
42 #include "gnunet_core_service.h"
43 #include "gnunet_datastore_service.h"
44 #include "gnunet_peer_lib.h"
45 #include "gnunet_protocols.h"
46 #include "gnunet_signatures.h"
47 #include "gnunet_util_lib.h"
48 #include "gnunet-service-fs_indexing.h"
51 #define DEBUG_FS GNUNET_NO
54 * Signature of a function that is called whenever a datastore
55 * request can be processed (or an entry put on the queue times out).
58 * @param ok GNUNET_OK if DS is ready, GNUNET_SYSERR on timeout
60 typedef void (*RequestFunction)(void *cls,
65 * Doubly-linked list of our requests for the datastore.
67 struct DatastoreRequestQueue
71 * This is a doubly-linked list.
73 struct DatastoreRequestQueue *next;
76 * This is a doubly-linked list.
78 struct DatastoreRequestQueue *prev;
81 * Function to call (will issue the request).
91 * When should this request time-out because we don't care anymore?
93 struct GNUNET_TIME_Absolute timeout;
96 * ID of task used for signaling timeout.
98 GNUNET_SCHEDULER_TaskIdentifier task;
104 * Closure for processing START_SEARCH messages from a client.
106 struct LocalGetContext
110 * This is a doubly-linked list.
112 struct LocalGetContext *next;
115 * This is a doubly-linked list.
117 struct LocalGetContext *prev;
120 * Client that initiated the search.
122 struct GNUNET_SERVER_Client *client;
125 * Array of results that we've already received
128 GNUNET_HashCode *results;
131 * Bloomfilter over all results (for fast query construction);
132 * NULL if we don't have any results.
134 * FIXME: this member is not used, is that OK? If so, it should
137 struct GNUNET_CONTAINER_BloomFilter *results_bf;
140 * DS request associated with this operation.
142 struct DatastoreRequestQueue *req;
145 * Current result message to transmit to client (or NULL).
147 struct ContentMessage *result;
150 * Type of the content that we're looking for.
156 * Desired anonymity level.
158 uint32_t anonymity_level;
161 * Number of results actually stored in the results array.
163 unsigned int results_used;
166 * Size of the results array in memory.
168 unsigned int results_size;
171 * Size (in bytes) of the 'results_bf' bloomfilter.
173 * FIXME: this member is not used, is that OK? If so, it should
176 size_t results_bf_size;
179 * If the request is for a DBLOCK or IBLOCK, this is the identity of
180 * the peer that is known to have a response. Set to all-zeros if
181 * such a target is not known (note that even if OUR anonymity
182 * level is >0 we may happen to know the responder's identity;
183 * nevertheless, we should probably not use it for a DHT-lookup
184 * or similar blunt actions in order to avoid exposing ourselves).
186 struct GNUNET_PeerIdentity target;
189 * If the request is for an SBLOCK, this is the identity of the
190 * pseudonym to which the SBLOCK belongs.
192 GNUNET_HashCode namespace;
195 * Hash of the keyword (aka query) for KBLOCKs; Hash of
196 * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
197 * and hash of the identifier XORed with the target for
198 * SBLOCKS (aka query).
200 GNUNET_HashCode query;
206 * Possible routing policies for an FS-GET request.
211 * Simply drop the request.
213 ROUTING_POLICY_NONE = 0,
216 * Answer it if we can from local datastore.
218 ROUTING_POLICY_ANSWER = 1,
221 * Forward the request to other peers (if possible).
223 ROUTING_POLICY_FORWARD = 2,
226 * Forward to other peers, and ask them to route
227 * the response via ourselves.
229 ROUTING_POLICY_INDIRECT = 6,
232 * Do everything we could possibly do (that would
235 ROUTING_POLICY_ALL = 7
240 * Internal context we use for our initial processing
243 struct ProcessGetContext
246 * The search query (used for datastore lookup).
248 GNUNET_HashCode query;
251 * Which peer we should forward the response to.
253 struct GNUNET_PeerIdentity reply_to;
256 * Namespace for the result (only set for SKS requests)
258 GNUNET_HashCode namespace;
261 * Peer that we should forward the query to if possible
262 * (since that peer likely has the content).
264 struct GNUNET_PeerIdentity prime_target;
267 * When did we receive this request?
269 struct GNUNET_TIME_Absolute start_time;
272 * Our entry in the DRQ (non-NULL while we wait for our
273 * turn to interact with the local database).
275 struct DatastoreRequestQueue *drq;
278 * Filter used to eliminate duplicate results. Can be NULL if we
279 * are not yet filtering any results.
281 struct GNUNET_CONTAINER_BloomFilter *bf;
284 * Bitmap describing which of the optional
285 * hash codes / peer identities were given to us.
290 * Desired block type.
295 * Priority of the request.
300 * Size of the 'bf' (in bytes).
305 * In what ways are we going to process
308 enum RoutingPolicy policy;
311 * Time-to-live for the request (value
317 * Number to mingle hashes for bloom-filter
323 * Number of results that were found so far.
325 unsigned int results_found;
330 * Information we keep for each pending reply. The
331 * actual message follows at the end of this struct.
333 struct PendingMessage
336 * This is a linked list.
338 struct PendingMessage *next;
341 * Size of the reply; actual reply message follows
342 * at the end of this struct.
347 * How important is this message for us?
355 * All requests from a client are kept in a doubly-linked list.
357 struct ClientRequestList;
361 * Information we keep for each pending request. We should try to
362 * keep this struct as small as possible since its memory consumption
363 * is key to how many requests we can have pending at once.
365 struct PendingRequest
369 * ID of a client making a request, NULL if this entry is for a
372 struct GNUNET_SERVER_Client *client;
375 * If this request was made by a client,
376 * this is our entry in the client request
377 * list; otherwise NULL.
379 struct ClientRequestList *crl_entry;
382 * If this is a namespace query, pointer to the hash of the public
383 * key of the namespace; otherwise NULL.
385 GNUNET_HashCode *namespace;
388 * Bloomfilter we use to filter out replies that we don't care about
389 * (anymore). NULL as long as we are interested in all replies.
391 struct GNUNET_CONTAINER_BloomFilter *bf;
394 * Context of our GNUNET_CORE_peer_change_preference call.
396 struct GNUNET_CORE_InformationRequestContext *irc;
399 * Handle for an active request for transmission to this peer, or
400 * NULL. Only used for replies that we are trying to send to a peer
401 * that we are not yet connected to.
403 struct GNUNET_CORE_TransmitHandle *cth;
406 * Replies that we have received but were unable to forward yet
407 * (typically non-null only if we have a pending transmission
408 * request with the client or the respective peer).
410 struct PendingMessage *replies_pending;
413 * Pending transmission request for the target client (for processing of
414 * 'replies_pending').
416 struct GNUNET_CONNECTION_TransmitHandle *th;
419 * Hash code of all replies that we have seen so far (only valid
420 * if client is not NULL since we only track replies like this for
423 GNUNET_HashCode *replies_seen;
426 * Node in the heap representing this entry.
428 struct GNUNET_CONTAINER_HeapNode *hnode;
431 * When did we first see this request (form this peer), or, if our
432 * client is initiating, when did we last initiate a search?
434 struct GNUNET_TIME_Absolute start_time;
437 * The query that this request is for.
439 GNUNET_HashCode query;
442 * The task responsible for transmitting queries
445 GNUNET_SCHEDULER_TaskIdentifier task;
448 * (Interned) Peer identifier (only valid if "client" is NULL)
449 * that identifies a peer that gave us this request.
451 GNUNET_PEER_Id source_pid;
454 * (Interned) Peer identifier that identifies a preferred target
457 GNUNET_PEER_Id target_pid;
460 * (Interned) Peer identifiers of peers that have already
461 * received our query for this content.
463 GNUNET_PEER_Id *used_pids;
466 * Size of the 'bf' (in bytes).
471 * Desired anonymity level; only valid for requests from a local client.
473 uint32_t anonymity_level;
476 * How many entries in "used_pids" are actually valid?
478 unsigned int used_pids_off;
481 * How long is the "used_pids" array?
483 unsigned int used_pids_size;
486 * How many entries in "replies_seen" are actually valid?
488 unsigned int replies_seen_off;
491 * How long is the "replies_seen" array?
493 unsigned int replies_seen_size;
496 * Priority with which this request was made. If one of our clients
497 * made the request, then this is the current priority that we are
498 * using when initiating the request. This value is used when
499 * we decide to reward other peers with trust for providing a reply.
504 * Priority points left for us to spend when forwarding this request
507 uint32_t remaining_priority;
510 * Number to mingle hashes for bloom-filter
516 * TTL with which we saw this request (or, if we initiated, TTL that
517 * we used for the request).
522 * Type of the content that this request is for.
530 * All requests from a client are kept in a doubly-linked list.
532 struct ClientRequestList
535 * This is a doubly-linked list.
537 struct ClientRequestList *next;
540 * This is a doubly-linked list.
542 struct ClientRequestList *prev;
545 * A request from this client.
547 struct PendingRequest *req;
550 * Client list with the head and tail of this DLL.
552 struct ClientList *cl;
557 * Linked list of all clients that we are currently processing
564 * This is a linked list.
566 struct ClientList *next;
569 * What client is this entry for?
571 struct GNUNET_SERVER_Client* client;
574 * Head of the DLL of requests from this client.
576 struct ClientRequestList *head;
579 * Tail of the DLL of requests from this client.
581 struct ClientRequestList *tail;
587 * Closure for "process_reply" function.
589 struct ProcessReplyClosure
592 * The data for the reply.
597 * When the reply expires.
599 struct GNUNET_TIME_Absolute expiration;
607 * Namespace that this reply belongs to
608 * (if it is of type SBLOCK).
610 GNUNET_HashCode namespace;
618 * How much was this reply worth to us?
625 * Information about a peer that we are connected to.
626 * We track data that is useful for determining which
627 * peers should receive our requests.
633 * List of the last clients for which this peer
634 * successfully answered a query.
636 struct GNUNET_SERVER_Client *last_client_replies[CS2P_SUCCESS_LIST_SIZE];
639 * List of the last PIDs for which
640 * this peer successfully answered a query;
641 * We use 0 to indicate no successful reply.
643 GNUNET_PEER_Id last_p2p_replies[P2P_SUCCESS_LIST_SIZE];
646 * Average delay between sending the peer a request and
647 * getting a reply (only calculated over the requests for
648 * which we actually got a reply). Calculated
649 * as a moving average: new_delay = ((n-1)*last_delay+curr_delay) / n
651 struct GNUNET_TIME_Relative avg_delay;
654 * Handle for an active request for transmission to this
657 struct GNUNET_CORE_TransmitHandle *cth;
660 * Messages (replies, queries, content migration) we would like to
661 * send to this peer in the near future. Sorted by priority.
663 struct PendingMessage *pending_messages;
666 * Average priority of successful replies. Calculated
667 * as a moving average: new_avg = ((n-1)*last_avg+curr_prio) / n
672 * The peer's identity.
677 * Number of requests we have currently pending with this peer (that
678 * is, requests that were transmitted so recently that we would not
679 * retransmit them right now).
681 unsigned int pending_requests;
684 * Which offset in "last_p2p_replies" will be updated next?
685 * (we go round-robin).
687 unsigned int last_p2p_replies_woff;
690 * Which offset in "last_client_replies" will be updated next?
691 * (we go round-robin).
693 unsigned int last_client_replies_woff;
699 * Our connection to the datastore.
701 static struct GNUNET_DATASTORE_Handle *dsh;
706 static struct GNUNET_SCHEDULER_Handle *sched;
711 const struct GNUNET_CONFIGURATION_Handle *cfg;
714 * Handle to the core service (NULL until we've connected to it).
716 struct GNUNET_CORE_Handle *core;
719 * Head of doubly-linked LGC list.
721 static struct LocalGetContext *lgc_head;
724 * Tail of doubly-linked LGC list.
726 static struct LocalGetContext *lgc_tail;
729 * Head of request queue for the datastore, sorted by timeout.
731 static struct DatastoreRequestQueue *drq_head;
734 * Tail of request queue for the datastore.
736 static struct DatastoreRequestQueue *drq_tail;
739 * Map of query hash codes to requests.
741 static struct GNUNET_CONTAINER_MultiHashMap *requests_by_query;
744 * Map of peer IDs to requests (for those requests coming
747 static struct GNUNET_CONTAINER_MultiHashMap *requests_by_peer;
750 * Linked list of all of our clients and their requests.
752 static struct ClientList *clients;
755 * Heap with the request that will expire next at the top. Contains
756 * pointers of type "struct PendingRequest*"; these will *also* be
757 * aliased from the "requests_by_peer" data structures and the
758 * "requests_by_query" table. Note that requests from our clients
759 * don't expire and are thus NOT in the "requests_by_expiration"
760 * (or the "requests_by_peer" tables).
762 static struct GNUNET_CONTAINER_Heap *requests_by_expiration;
765 * Map of peer identifiers to "struct ConnectedPeer" (for that peer).
767 static struct GNUNET_CONTAINER_MultiHashMap *connected_peers;
770 * Maximum number of requests (from other peers) that we're
771 * willing to have pending at any given point in time.
772 * FIXME: set from configuration (and 32 is a tiny value for testing only).
774 static uint64_t max_pending_requests = 32;
779 * Run the next DS request in our
780 * queue, we're done with the current one.
785 struct DatastoreRequestQueue *e;
787 while (NULL != (e = drq_head))
789 if (0 != GNUNET_TIME_absolute_get_remaining (e->timeout).value)
791 if (e->task != GNUNET_SCHEDULER_NO_TASK)
792 GNUNET_SCHEDULER_cancel (sched, e->task);
793 GNUNET_CONTAINER_DLL_remove (drq_head, drq_tail, e);
794 e->req (e->req_cls, GNUNET_NO);
799 if (e->task != GNUNET_SCHEDULER_NO_TASK)
800 GNUNET_SCHEDULER_cancel (sched, e->task);
801 e->task = GNUNET_SCHEDULER_NO_TASK;
802 e->req (e->req_cls, GNUNET_YES);
803 GNUNET_CONTAINER_DLL_remove (drq_head, drq_tail, e);
809 * A datastore request had to be timed out.
811 * @param cls closure (of type "struct DatastoreRequestQueue*")
812 * @param tc task context, unused
815 timeout_ds_request (void *cls,
816 const struct GNUNET_SCHEDULER_TaskContext *tc)
818 struct DatastoreRequestQueue *e = cls;
820 e->task = GNUNET_SCHEDULER_NO_TASK;
821 GNUNET_CONTAINER_DLL_remove (drq_head, drq_tail, e);
822 e->req (e->req_cls, GNUNET_NO);
828 * Queue a request for the datastore.
830 * @param deadline by when the request should run
831 * @param fun function to call once the request can be run
832 * @param fun_cls closure for fun
834 static struct DatastoreRequestQueue *
835 queue_ds_request (struct GNUNET_TIME_Relative deadline,
839 struct DatastoreRequestQueue *e;
840 struct DatastoreRequestQueue *bef;
842 if (drq_head == NULL)
844 /* no other requests pending, run immediately */
845 fun (fun_cls, GNUNET_OK);
848 e = GNUNET_malloc (sizeof (struct DatastoreRequestQueue));
849 e->timeout = GNUNET_TIME_relative_to_absolute (deadline);
851 e->req_cls = fun_cls;
852 if (deadline.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
854 /* local request, highest prio, put at head of queue
855 regardless of deadline */
861 while ( (NULL != bef) &&
862 (e->timeout.value < bef->timeout.value) )
865 GNUNET_CONTAINER_DLL_insert_after (drq_head, drq_tail, bef, e);
866 if (deadline.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
868 e->task = GNUNET_SCHEDULER_add_delayed (sched,
877 * Free the state associated with a local get context.
879 * @param lgc the lgc to free
882 local_get_context_free (struct LocalGetContext *lgc)
884 GNUNET_CONTAINER_DLL_remove (lgc_head, lgc_tail, lgc);
885 GNUNET_SERVER_client_drop (lgc->client);
886 GNUNET_free_non_null (lgc->results);
887 if (lgc->results_bf != NULL)
888 GNUNET_CONTAINER_bloomfilter_free (lgc->results_bf);
889 if (lgc->req != NULL)
891 if (lgc->req->task != GNUNET_SCHEDULER_NO_TASK)
892 GNUNET_SCHEDULER_cancel (sched, lgc->req->task);
893 GNUNET_CONTAINER_DLL_remove (lgc_head, lgc_tail, lgc);
894 GNUNET_free (lgc->req);
901 * We're able to transmit the next (local) result to the client.
902 * Do it and ask the datastore for more. Or, on error, tell
903 * the datastore to stop giving us more.
905 * @param cls our closure (struct LocalGetContext)
906 * @param max maximum number of bytes we can transmit
907 * @param buf where to copy our message
908 * @return number of bytes copied to buf
911 transmit_local_result (void *cls,
915 struct LocalGetContext *lgc = cls;
921 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
922 "Failed to transmit result to local client, aborting datastore iteration.\n");
925 GNUNET_free (lgc->result);
927 GNUNET_DATASTORE_get_next (dsh, GNUNET_NO);
930 msize = ntohs (lgc->result->header.size);
932 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
933 "Transmitting %u bytes of result to local client.\n",
936 GNUNET_assert (max >= msize);
937 memcpy (buf, lgc->result, msize);
938 GNUNET_free (lgc->result);
940 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
946 * Mingle hash with the mingle_number to produce different bits.
949 mingle_hash (const GNUNET_HashCode * in,
950 int32_t mingle_number,
951 GNUNET_HashCode * hc)
955 GNUNET_CRYPTO_hash (&mingle_number,
958 GNUNET_CRYPTO_hash_xor (&m, in, hc);
963 * How many bytes should a bloomfilter be if we have already seen
964 * entry_count responses? Note that BLOOMFILTER_K gives us the number
965 * of bits set per entry. Furthermore, we should not re-size the
966 * filter too often (to keep it cheap).
968 * Since other peers will also add entries but not resize the filter,
969 * we should generally pick a slightly larger size than what the
970 * strict math would suggest.
972 * @return must be a power of two and smaller or equal to 2^15.
975 compute_bloomfilter_size (unsigned int entry_count)
978 unsigned int ideal = (entry_count * BLOOMFILTER_K) / 4;
979 uint16_t max = 1 << 15;
981 if (entry_count > max)
984 while ((size < max) && (size < ideal))
993 * Recalculate our bloom filter for filtering replies.
995 * @param count number of entries we are filtering right now
996 * @param mingle set to our new mingling value
997 * @param bf_size set to the size of the bloomfilter
998 * @param entries the entries to filter
999 * @return updated bloomfilter, NULL for none
1001 static struct GNUNET_CONTAINER_BloomFilter *
1002 refresh_bloomfilter (unsigned int count,
1005 const GNUNET_HashCode *entries)
1007 struct GNUNET_CONTAINER_BloomFilter *bf;
1010 GNUNET_HashCode mhash;
1014 nsize = compute_bloomfilter_size (count);
1015 *mingle = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, -1);
1017 bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
1020 for (i=0;i<count;i++)
1022 mingle_hash (&entries[i], *mingle, &mhash);
1023 GNUNET_CONTAINER_bloomfilter_add (bf, &mhash);
1030 * Closure used for "target_peer_select_cb".
1032 struct PeerSelectionContext
1035 * The request for which we are selecting
1038 struct PendingRequest *pr;
1041 * Current "prime" target.
1043 struct GNUNET_PeerIdentity target;
1046 * How much do we like this target?
1048 double target_score;
1054 * Function called for each connected peer to determine
1055 * which one(s) would make good targets for forwarding.
1057 * @param cls closure (struct PeerSelectionContext)
1058 * @param key current key code (peer identity)
1059 * @param value value in the hash map (struct ConnectedPeer)
1060 * @return GNUNET_YES if we should continue to
1065 target_peer_select_cb (void *cls,
1066 const GNUNET_HashCode * key,
1069 struct PeerSelectionContext *psc = cls;
1070 struct ConnectedPeer *cp = value;
1071 struct PendingRequest *pr = psc->pr;
1075 /* 1) check if we have already (recently) forwarded to this peer */
1076 for (i=0;i<pr->used_pids_off;i++)
1077 if (pr->used_pids[i] == cp->pid)
1078 return GNUNET_YES; /* skip */
1079 // 2) calculate how much we'd like to forward to this peer
1080 score = 0; // FIXME!
1082 /* store best-fit in closure */
1083 if (score > psc->target_score)
1085 psc->target_score = score;
1086 psc->target.hashPubKey = *key;
1093 * We use a random delay to make the timing of requests
1094 * less predictable. This function returns such a random
1097 * @return random delay to use for some request, between 0 and TTL_DECREMENT ms
1099 static struct GNUNET_TIME_Relative
1100 get_processing_delay ()
1102 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1103 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1109 * Task that is run for each request with the goal of forwarding the
1110 * associated query to other peers. The task should re-schedule
1111 * itself to be re-run once the TTL has expired. (or at a later time
1112 * if more peers should be queried earlier).
1114 * @param cls the requests "struct PendingRequest*"
1115 * @param tc task context (unused)
1118 forward_request_task (void *cls,
1119 const struct GNUNET_SCHEDULER_TaskContext *tc);
1123 * We've selected a peer for forwarding of a query. Construct the
1124 * message and then re-schedule the task to forward again to (other)
1127 * @param cls closure
1128 * @param size number of bytes available in buf
1129 * @param buf where the callee should write the message
1130 * @return number of bytes written to buf
1133 transmit_request_cb (void *cls,
1137 struct ConnectedPeer *cp = cls;
1139 struct GNUNET_PeerIdentity target;
1140 struct PendingMessage *pr;
1145 while ( (NULL != (pr = cp->pending_messages)) &&
1146 (pr->msize < size - tot) )
1152 cp->pending_messages = pr->next;
1157 GNUNET_PEER_resolve (cp->pid,
1159 cp->cth = GNUNET_CORE_notify_transmit_ready (core,
1161 GNUNET_TIME_UNIT_FOREVER_REL,
1164 &transmit_request_cb,
1172 * Function called after we've tried to reserve a certain amount of
1173 * bandwidth for a reply. Check if we succeeded and if so send our
1176 * @param cls the requests "struct PendingRequest*"
1177 * @param peer identifies the peer
1178 * @param bpm_in set to the current bandwidth limit (receiving) for this peer
1179 * @param bpm_out set to the current bandwidth limit (sending) for this peer
1180 * @param amount set to the amount that was actually reserved or unreserved
1181 * @param preference current traffic preference for the given peer
1184 target_reservation_cb (void *cls,
1186 GNUNET_PeerIdentity * peer,
1187 unsigned int bpm_in,
1188 unsigned int bpm_out,
1190 uint64_t preference)
1192 struct PendingRequest *pr = cls;
1193 struct ConnectedPeer *cp;
1194 struct PendingMessage *pm;
1195 struct PendingMessage *pos;
1196 struct PendingMessage *prev;
1197 struct GetMessage *gm;
1198 GNUNET_HashCode *ext;
1203 pr->task = GNUNET_SCHEDULER_add_delayed (sched,
1204 get_processing_delay (), // FIXME: longer?
1205 &forward_request_task,
1208 GNUNET_assert (peer != NULL);
1209 if (amount != DBLOCK_SIZE)
1211 /* FIXME: call stats... */
1212 return; /* this target round failed */
1214 // (2) transmit, update ttl/priority
1215 cp = GNUNET_CONTAINER_multihashmap_get (connected_peers,
1219 /* Peer must have just left; try again immediately */
1220 pr->task = GNUNET_SCHEDULER_add_now (sched,
1221 &forward_request_task,
1225 /* build message and insert message into priority queue */
1226 k = 0; // FIXME: count hash codes!
1227 msize = sizeof (struct GetMessage) + pr->bf_size + k * sizeof(GNUNET_HashCode);
1228 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
1229 pm = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
1231 pm->priority = 0; // FIXME: calculate priority properly!
1232 gm = (struct GetMessage*) &pm[1];
1233 gm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_GET);
1234 gm->header.size = htons (msize);
1235 gm->type = htonl (pr->type);
1236 pr->remaining_priority /= 2;
1237 gm->priority = htonl (pr->remaining_priority);
1238 gm->ttl = htonl (pr->ttl);
1239 gm->filter_mutator = htonl(pr->mingle);
1240 gm->hash_bitmap = htonl (42);
1241 gm->query = pr->query;
1242 ext = (GNUNET_HashCode*) &gm[1];
1244 // FIXME: setup "ext[0]..[k-1]"
1245 bfdata = (char *) &ext[k];
1247 GNUNET_CONTAINER_bloomfilter_get_raw_data (pr->bf,
1253 pos = cp->pending_messages;
1254 while ( (pos != NULL) &&
1255 (pm->priority < pos->priority) )
1261 cp->pending_messages = pm;
1265 if (cp->cth == NULL)
1266 cp->cth = GNUNET_CORE_notify_transmit_ready (core,
1267 cp->pending_messages->priority,
1268 GNUNET_TIME_UNIT_FOREVER_REL,
1271 &transmit_request_cb,
1273 if (cp->cth == NULL)
1275 /* technically, this should not be a 'break'; but
1276 we don't handle this (rare) case yet, so let's warn
1285 * Task that is run for each request with the goal of forwarding the
1286 * associated query to other peers. The task should re-schedule
1287 * itself to be re-run once the TTL has expired. (or at a later time
1288 * if more peers should be queried earlier).
1290 * @param cls the requests "struct PendingRequest*"
1291 * @param tc task context (unused)
1294 forward_request_task (void *cls,
1295 const struct GNUNET_SCHEDULER_TaskContext *tc)
1297 struct PendingRequest *pr = cls;
1298 struct PeerSelectionContext psc;
1300 pr->task = GNUNET_SCHEDULER_NO_TASK;
1301 /* (1) select target */
1303 psc.target_score = DBL_MIN;
1304 GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
1305 &target_peer_select_cb,
1307 if (psc.target_score == DBL_MIN)
1309 /* no possible target found, wait some time */
1310 pr->task = GNUNET_SCHEDULER_add_delayed (sched,
1311 get_processing_delay (), // FIXME: exponential back-off? or at least wait longer...
1312 &forward_request_task,
1316 /* (2) reserve reply bandwidth */
1317 GNUNET_assert (NULL == pr->irc);
1318 pr->irc = GNUNET_CORE_peer_change_preference (sched, cfg,
1320 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1322 DBLOCK_SIZE, // FIXME: make dependent on type?
1324 &target_reservation_cb,
1330 * We're processing (local) results for a search request
1331 * from a (local) client. Pass applicable results to the
1332 * client and if we are done either clean up (operation
1333 * complete) or switch to P2P search (more results possible).
1335 * @param cls our closure (struct LocalGetContext)
1336 * @param key key for the content
1337 * @param size number of bytes in data
1338 * @param data content stored
1339 * @param type type of the content
1340 * @param priority priority of the content
1341 * @param anonymity anonymity-level for the content
1342 * @param expiration expiration time for the content
1343 * @param uid unique identifier for the datum;
1344 * maybe 0 if no unique identifier is available
1347 process_local_get_result (void *cls,
1348 const GNUNET_HashCode * key,
1354 struct GNUNET_TIME_Absolute
1358 struct LocalGetContext *lgc = cls;
1359 struct PendingRequest *pr;
1360 struct ClientRequestList *crl;
1361 struct ClientList *cl;
1368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1369 "Received last result for `%s' from local datastore, deciding what to do next.\n",
1370 GNUNET_h2s (&lgc->query));
1372 /* no further results from datastore; continue
1373 processing further requests from the client and
1374 allow the next task to use the datastore; also,
1375 switch to P2P requests or clean up our state. */
1377 GNUNET_SERVER_receive_done (lgc->client,
1379 if ( (lgc->results_used == 0) ||
1380 (lgc->type == GNUNET_DATASTORE_BLOCKTYPE_KBLOCK) ||
1381 (lgc->type == GNUNET_DATASTORE_BLOCKTYPE_SBLOCK) ||
1382 (lgc->type == GNUNET_DATASTORE_BLOCKTYPE_SKBLOCK) )
1385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1386 "Forwarding query for `%s' to network.\n",
1387 GNUNET_h2s (&lgc->query));
1390 while ( (NULL != cl) &&
1391 (cl->client != lgc->client) )
1395 cl = GNUNET_malloc (sizeof (struct ClientList));
1396 cl->client = lgc->client;
1400 crl = GNUNET_malloc (sizeof (struct ClientRequestList));
1402 GNUNET_CONTAINER_DLL_insert (cl->head, cl->tail, crl);
1403 pr = GNUNET_malloc (sizeof (struct PendingRequest));
1404 pr->client = lgc->client;
1405 GNUNET_SERVER_client_keep (pr->client);
1406 pr->crl_entry = crl;
1408 if (lgc->type == GNUNET_DATASTORE_BLOCKTYPE_SBLOCK)
1410 pr->namespace = GNUNET_malloc (sizeof (GNUNET_HashCode));
1411 *pr->namespace = lgc->namespace;
1413 pr->replies_seen = lgc->results;
1414 lgc->results = NULL;
1415 pr->start_time = GNUNET_TIME_absolute_get ();
1416 pr->query = lgc->query;
1417 pr->target_pid = GNUNET_PEER_intern (&lgc->target);
1418 pr->replies_seen_off = lgc->results_used;
1419 pr->replies_seen_size = lgc->results_size;
1420 lgc->results_size = 0;
1421 pr->type = lgc->type;
1422 pr->anonymity_level = lgc->anonymity_level;
1423 pr->bf = refresh_bloomfilter (pr->replies_seen_off,
1427 GNUNET_CONTAINER_multihashmap_put (requests_by_query,
1430 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1431 pr->task = GNUNET_SCHEDULER_add_delayed (sched,
1432 get_processing_delay (),
1433 &forward_request_task,
1435 local_get_context_free (lgc);
1438 /* got all possible results, clean up! */
1440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1441 "Found all possible results for query for `%s', done!\n",
1442 GNUNET_h2s (&lgc->query));
1444 local_get_context_free (lgc);
1447 if (type == GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND)
1450 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1451 "Received on-demand block for `%s' from local datastore, fetching data.\n",
1452 GNUNET_h2s (&lgc->query));
1454 GNUNET_FS_handle_on_demand_block (key, size, data, type, priority,
1455 anonymity, expiration, uid,
1457 &process_local_get_result,
1461 if ( (type != lgc->type) &&
1462 (lgc->type != GNUNET_DATASTORE_BLOCKTYPE_ANY) )
1464 /* this should be virtually impossible to reach (DBLOCK
1465 query hash being identical to KBLOCK/SBLOCK query hash);
1466 nevertheless, if it happens, the correct thing is to
1467 simply skip the result. */
1469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1470 "Received block of unexpected type (%u, want %u) for `%s' from local datastore, ignoring.\n",
1473 GNUNET_h2s (&lgc->query));
1475 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
1478 /* check if this is a result we've alredy
1480 for (i=0;i<lgc->results_used;i++)
1481 if (0 == memcmp (key,
1483 sizeof (GNUNET_HashCode)))
1486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1487 "Received duplicate result for `%s' from local datastore, ignoring.\n",
1488 GNUNET_h2s (&lgc->query));
1490 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
1493 if (lgc->results_used == lgc->results_size)
1494 GNUNET_array_grow (lgc->results,
1496 lgc->results_size * 2 + 2);
1497 GNUNET_CRYPTO_hash (data,
1499 &lgc->results[lgc->results_used++]);
1500 msize = size + sizeof (struct ContentMessage);
1501 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
1502 lgc->result = GNUNET_malloc (msize);
1503 lgc->result->header.size = htons (msize);
1504 lgc->result->header.type = htons (GNUNET_MESSAGE_TYPE_FS_CONTENT);
1505 lgc->result->type = htonl (type);
1506 lgc->result->expiration = GNUNET_TIME_absolute_hton (expiration);
1507 memcpy (&lgc->result[1],
1511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1512 "Received new result for `%s' from local datastore, passing to client.\n",
1513 GNUNET_h2s (&lgc->query));
1515 GNUNET_SERVER_notify_transmit_ready (lgc->client,
1517 GNUNET_TIME_UNIT_FOREVER_REL,
1518 &transmit_local_result,
1524 * We're processing a search request from a local
1525 * client. Now it is our turn to query the datastore.
1527 * @param cls our closure (struct LocalGetContext)
1531 transmit_local_get (void *cls,
1532 const struct GNUNET_SCHEDULER_TaskContext *tc)
1534 struct LocalGetContext *lgc = cls;
1538 if (type == GNUNET_DATASTORE_BLOCKTYPE_DBLOCK)
1539 type = GNUNET_DATASTORE_BLOCKTYPE_ANY; /* to get on-demand as well */
1540 GNUNET_DATASTORE_get (dsh,
1543 &process_local_get_result,
1545 GNUNET_TIME_UNIT_FOREVER_REL);
1550 * We're processing a search request from a local
1551 * client. Now it is our turn to query the datastore.
1553 * @param cls our closure (struct LocalGetContext)
1554 * @param ok did we succeed to queue for datastore access, should always be GNUNET_OK
1557 transmit_local_get_ready (void *cls,
1560 struct LocalGetContext *lgc = cls;
1562 GNUNET_assert (GNUNET_OK == ok);
1563 GNUNET_SCHEDULER_add_continuation (sched,
1564 &transmit_local_get,
1566 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1571 * Handle START_SEARCH-message (search request from client).
1573 * @param cls closure
1574 * @param client identification of the client
1575 * @param message the actual message
1578 handle_start_search (void *cls,
1579 struct GNUNET_SERVER_Client *client,
1580 const struct GNUNET_MessageHeader *message)
1582 const struct SearchMessage *sm;
1583 struct LocalGetContext *lgc;
1587 msize = ntohs (message->size);
1588 if ( (msize < sizeof (struct SearchMessage)) ||
1589 (0 != (msize - sizeof (struct SearchMessage)) % sizeof (GNUNET_HashCode)) )
1592 GNUNET_SERVER_receive_done (client,
1596 sc = (msize - sizeof (struct SearchMessage)) / sizeof (GNUNET_HashCode);
1597 sm = (const struct SearchMessage*) message;
1598 GNUNET_SERVER_client_keep (client);
1599 lgc = GNUNET_malloc (sizeof (struct LocalGetContext));
1602 lgc->results_used = sc;
1603 GNUNET_array_grow (lgc->results,
1606 memcpy (lgc->results,
1608 sc * sizeof (GNUNET_HashCode));
1610 lgc->client = client;
1611 lgc->type = ntohl (sm->type);
1612 lgc->anonymity_level = ntohl (sm->anonymity_level);
1615 case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK:
1616 case GNUNET_DATASTORE_BLOCKTYPE_IBLOCK:
1617 lgc->target.hashPubKey = sm->target;
1619 case GNUNET_DATASTORE_BLOCKTYPE_SBLOCK:
1620 lgc->namespace = sm->target;
1625 lgc->query = sm->query;
1626 GNUNET_CONTAINER_DLL_insert (lgc_head, lgc_tail, lgc);
1627 lgc->req = queue_ds_request (GNUNET_TIME_UNIT_FOREVER_REL,
1628 &transmit_local_get_ready,
1634 * List of handlers for the messages understood by this
1637 static struct GNUNET_SERVER_MessageHandler handlers[] = {
1638 {&GNUNET_FS_handle_index_start, NULL,
1639 GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0},
1640 {&GNUNET_FS_handle_index_list_get, NULL,
1641 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, sizeof(struct GNUNET_MessageHeader) },
1642 {&GNUNET_FS_handle_unindex, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX,
1643 sizeof (struct UnindexMessage) },
1644 {&handle_start_search, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH,
1651 * Clean up the memory used by the PendingRequest structure (except
1652 * for the client or peer list that the request may be part of).
1654 * @param pr request to clean up
1657 destroy_pending_request (struct PendingRequest *pr)
1659 struct PendingMessage *reply;
1660 struct ClientList *cl;
1662 GNUNET_CONTAINER_multihashmap_remove (requests_by_query,
1665 // FIXME: not sure how this can work (efficiently)
1666 // also, what does the return value mean?
1667 if (pr->irc != NULL)
1669 GNUNET_CORE_peer_change_preference_cancel (pr->irc);
1672 if (pr->client == NULL)
1674 GNUNET_CONTAINER_heap_remove_node (requests_by_expiration,
1679 cl = pr->crl_entry->cl;
1680 GNUNET_CONTAINER_DLL_remove (cl->head,
1684 if (GNUNET_SCHEDULER_NO_TASK != pr->task)
1685 GNUNET_SCHEDULER_cancel (sched, pr->task);
1687 GNUNET_CONTAINER_bloomfilter_free (pr->bf);
1689 GNUNET_CONNECTION_notify_transmit_ready_cancel (pr->th);
1690 while (NULL != (reply = pr->replies_pending))
1692 pr->replies_pending = reply->next;
1693 GNUNET_free (reply);
1695 if (NULL != pr->cth)
1696 GNUNET_CORE_notify_transmit_ready_cancel (pr->cth);
1697 GNUNET_PEER_change_rc (pr->source_pid, -1);
1698 GNUNET_PEER_change_rc (pr->target_pid, -1);
1699 GNUNET_PEER_decrement_rcs (pr->used_pids, pr->used_pids_off);
1700 GNUNET_free_non_null (pr->used_pids);
1701 GNUNET_free_non_null (pr->replies_seen);
1702 GNUNET_free_non_null (pr->namespace);
1708 * A client disconnected. Remove all of its pending queries.
1710 * @param cls closure, NULL
1711 * @param client identification of the client
1714 handle_client_disconnect (void *cls,
1715 struct GNUNET_SERVER_Client
1718 struct LocalGetContext *lgc;
1719 struct ClientList *cpos;
1720 struct ClientList *cprev;
1721 struct ClientRequestList *rl;
1726 while ( (NULL != lgc) &&
1727 (lgc->client != client) )
1730 local_get_context_free (lgc);
1733 while ( (NULL != cpos) &&
1734 (clients->client != client) )
1742 clients = cpos->next;
1744 cprev->next = cpos->next;
1745 while (NULL != (rl = cpos->head))
1747 cpos->head = rl->next;
1748 destroy_pending_request (rl->req);
1757 * Iterator over entries in the "requests_by_query" map
1758 * that frees all the entries.
1760 * @param cls closure, NULL
1761 * @param key current key code (the query, unused)
1762 * @param value value in the hash map, of type "struct PendingRequest*"
1763 * @return GNUNET_YES (we should continue to iterate)
1766 destroy_pending_request_cb (void *cls,
1767 const GNUNET_HashCode * key,
1770 struct PendingRequest *pr = value;
1772 destroy_pending_request (pr);
1778 * Task run during shutdown.
1784 shutdown_task (void *cls,
1785 const struct GNUNET_SCHEDULER_TaskContext *tc)
1789 GNUNET_CORE_disconnect (core);
1794 GNUNET_DATASTORE_disconnect (dsh,
1798 GNUNET_CONTAINER_multihashmap_iterate (requests_by_query,
1799 &destroy_pending_request_cb,
1801 while (clients != NULL)
1802 handle_client_disconnect (NULL,
1804 GNUNET_CONTAINER_multihashmap_destroy (requests_by_query);
1805 requests_by_query = NULL;
1806 GNUNET_CONTAINER_multihashmap_destroy (requests_by_peer);
1807 requests_by_peer = NULL;
1808 GNUNET_CONTAINER_heap_destroy (requests_by_expiration);
1809 requests_by_expiration = NULL;
1810 // FIXME: iterate over entries and free individually?
1811 // (or do we get disconnect notifications?)
1812 GNUNET_CONTAINER_multihashmap_destroy (connected_peers);
1813 connected_peers = NULL;
1818 * Free (each) request made by the peer.
1820 * @param cls closure, points to peer that the request belongs to
1821 * @param key current key code
1822 * @param value value in the hash map
1823 * @return GNUNET_YES (we should continue to iterate)
1826 destroy_request (void *cls,
1827 const GNUNET_HashCode * key,
1830 const struct GNUNET_PeerIdentity * peer = cls;
1831 struct PendingRequest *pr = value;
1833 GNUNET_CONTAINER_multihashmap_remove (requests_by_peer,
1836 destroy_pending_request (pr);
1843 * Method called whenever a given peer connects.
1845 * @param cls closure, not used
1846 * @param peer peer identity this notification is about
1847 * @param latency reported latency of the connection with 'other'
1848 * @param distance reported distance (DV) to 'other'
1851 peer_connect_handler (void *cls,
1853 GNUNET_PeerIdentity * peer,
1854 struct GNUNET_TIME_Relative latency,
1857 struct ConnectedPeer *cp;
1859 cp = GNUNET_malloc (sizeof (struct ConnectedPeer));
1860 cp->pid = GNUNET_PEER_intern (peer);
1861 GNUNET_CONTAINER_multihashmap_put (connected_peers,
1864 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1869 * Method called whenever a peer disconnects.
1871 * @param cls closure, not used
1872 * @param peer peer identity this notification is about
1875 peer_disconnect_handler (void *cls,
1877 GNUNET_PeerIdentity * peer)
1879 struct ConnectedPeer *cp;
1880 struct PendingMessage *pm;
1882 cp = GNUNET_CONTAINER_multihashmap_get (connected_peers,
1886 GNUNET_PEER_change_rc (cp->pid, -1);
1887 GNUNET_PEER_decrement_rcs (cp->last_p2p_replies, P2P_SUCCESS_LIST_SIZE);
1888 if (NULL != cp->cth)
1889 GNUNET_CORE_notify_transmit_ready_cancel (cp->cth);
1890 while (NULL != (pm = cp->pending_messages))
1892 cp->pending_messages = pm->next;
1897 GNUNET_CONTAINER_multihashmap_get_multiple (requests_by_peer,
1905 * We're processing a GET request from another peer and have decided
1906 * to forward it to other peers.
1908 * @param cls our "struct ProcessGetContext *"
1912 forward_get_request (void *cls,
1913 const struct GNUNET_SCHEDULER_TaskContext *tc)
1915 struct ProcessGetContext *pgc = cls;
1916 struct PendingRequest *pr;
1917 struct PendingRequest *eer;
1918 struct GNUNET_PeerIdentity target;
1920 pr = GNUNET_malloc (sizeof (struct PendingRequest));
1921 if (GET_MESSAGE_BIT_SKS_NAMESPACE == (GET_MESSAGE_BIT_SKS_NAMESPACE & pgc->bm))
1923 pr->namespace = GNUNET_malloc (sizeof(GNUNET_HashCode));
1924 *pr->namespace = pgc->namespace;
1927 pr->bf_size = pgc->bf_size;
1929 pr->start_time = pgc->start_time;
1930 pr->query = pgc->query;
1931 pr->source_pid = GNUNET_PEER_intern (&pgc->reply_to);
1932 if (GET_MESSAGE_BIT_TRANSMIT_TO == (GET_MESSAGE_BIT_TRANSMIT_TO & pgc->bm))
1933 pr->target_pid = GNUNET_PEER_intern (&pgc->prime_target);
1934 pr->anonymity_level = 1; /* default */
1935 pr->priority = pgc->priority;
1936 pr->remaining_priority = pr->priority;
1937 pr->mingle = pgc->mingle;
1939 pr->type = pgc->type;
1940 GNUNET_CONTAINER_multihashmap_put (requests_by_query,
1943 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1944 GNUNET_CONTAINER_multihashmap_put (requests_by_peer,
1945 &pgc->reply_to.hashPubKey,
1947 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1948 pr->hnode = GNUNET_CONTAINER_heap_insert (requests_by_expiration,
1950 pr->start_time.value + pr->ttl);
1951 if (GNUNET_CONTAINER_heap_get_size (requests_by_expiration) > max_pending_requests)
1953 /* expire oldest request! */
1954 eer = GNUNET_CONTAINER_heap_peek (requests_by_expiration);
1955 GNUNET_PEER_resolve (eer->source_pid,
1957 GNUNET_CONTAINER_multihashmap_remove (requests_by_peer,
1960 destroy_pending_request (eer);
1962 pr->task = GNUNET_SCHEDULER_add_delayed (sched,
1963 get_processing_delay (),
1964 &forward_request_task,
1969 * Transmit the given message by copying it to
1970 * the target buffer "buf". "buf" will be
1971 * NULL and "size" zero if the socket was closed for
1972 * writing in the meantime. In that case, only
1976 * @param cls closure, pointer to the message
1977 * @param size number of bytes available in buf
1978 * @param buf where the callee should write the message
1979 * @return number of bytes written to buf
1982 transmit_message (void *cls,
1983 size_t size, void *buf)
1985 struct GNUNET_MessageHeader *msg = cls;
1991 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1992 "Dropping reply, core too busy.\n");
1997 msize = ntohs (msg->size);
1998 GNUNET_assert (size >= msize);
1999 memcpy (buf, msg, msize);
2006 * Test if the load on this peer is too high
2007 * to even consider processing the query at
2010 * @return GNUNET_YES if the load is too high, GNUNET_NO otherwise
2013 test_load_too_high ()
2015 return GNUNET_NO; // FIXME
2020 * We're processing (local) results for a search request
2021 * from another peer. Pass applicable results to the
2022 * peer and if we are done either clean up (operation
2023 * complete) or forward to other peers (more results possible).
2025 * @param cls our closure (struct LocalGetContext)
2026 * @param key key for the content
2027 * @param size number of bytes in data
2028 * @param data content stored
2029 * @param type type of the content
2030 * @param priority priority of the content
2031 * @param anonymity anonymity-level for the content
2032 * @param expiration expiration time for the content
2033 * @param uid unique identifier for the datum;
2034 * maybe 0 if no unique identifier is available
2037 process_p2p_get_result (void *cls,
2038 const GNUNET_HashCode * key,
2044 struct GNUNET_TIME_Absolute
2048 struct ProcessGetContext *pgc = cls;
2049 GNUNET_HashCode dhash;
2050 GNUNET_HashCode mhash;
2051 struct PutMessage *reply;
2055 /* no more results */
2056 if ( ( (pgc->policy & ROUTING_POLICY_FORWARD) == ROUTING_POLICY_FORWARD) &&
2057 ( (0 == pgc->results_found) ||
2058 (pgc->type == GNUNET_DATASTORE_BLOCKTYPE_KBLOCK) ||
2059 (pgc->type == GNUNET_DATASTORE_BLOCKTYPE_SBLOCK) ||
2060 (pgc->type == GNUNET_DATASTORE_BLOCKTYPE_SKBLOCK) ) )
2062 GNUNET_SCHEDULER_add_continuation (sched,
2063 &forward_get_request,
2065 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
2069 if (pgc->bf != NULL)
2070 GNUNET_CONTAINER_bloomfilter_free (pgc->bf);
2076 if (type == GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND)
2078 GNUNET_FS_handle_on_demand_block (key, size, data, type, priority,
2079 anonymity, expiration, uid, dsh,
2080 &process_p2p_get_result,
2084 /* check for duplicates */
2085 GNUNET_CRYPTO_hash (data, size, &dhash);
2086 mingle_hash (&dhash,
2089 if ( (pgc->bf != NULL) &&
2091 GNUNET_CONTAINER_bloomfilter_test (pgc->bf,
2095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2096 "Result from datastore filtered by bloomfilter.\n");
2098 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
2101 pgc->results_found++;
2102 if ( (pgc->type == GNUNET_DATASTORE_BLOCKTYPE_KBLOCK) ||
2103 (pgc->type == GNUNET_DATASTORE_BLOCKTYPE_SBLOCK) ||
2104 (pgc->type == GNUNET_DATASTORE_BLOCKTYPE_SKBLOCK) )
2106 if (pgc->bf == NULL)
2109 pgc->bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
2113 GNUNET_CONTAINER_bloomfilter_add (pgc->bf,
2117 reply = GNUNET_malloc (sizeof (struct PutMessage) + size);
2118 reply->header.size = htons (sizeof (struct PutMessage) + size);
2119 reply->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT);
2120 reply->type = htonl (type);
2121 reply->expiration = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining (expiration));
2122 memcpy (&reply[1], data, size);
2123 GNUNET_CORE_notify_transmit_ready (core,
2125 ACCEPTABLE_REPLY_DELAY,
2127 sizeof (struct PutMessage) + size,
2130 if ( (GNUNET_YES == test_load_too_high()) ||
2131 (pgc->results_found > 5 + 2 * pgc->priority) )
2133 GNUNET_DATASTORE_get_next (dsh, GNUNET_NO);
2134 pgc->policy &= ~ ROUTING_POLICY_FORWARD;
2137 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
2142 * We're processing a GET request from another peer. Give it to our
2145 * @param cls our "struct ProcessGetContext"
2146 * @param ok did we get a datastore slice or not?
2149 ds_get_request (void *cls,
2152 struct ProcessGetContext *pgc = cls;
2154 struct GNUNET_TIME_Relative timeout;
2156 if (GNUNET_OK != ok)
2158 /* no point in doing P2P stuff if we can't even do local */
2163 if (type == GNUNET_DATASTORE_BLOCKTYPE_DBLOCK)
2164 type = GNUNET_DATASTORE_BLOCKTYPE_ANY; /* to get on-demand as well */
2165 timeout = GNUNET_TIME_relative_multiply (BASIC_DATASTORE_REQUEST_DELAY,
2166 (pgc->priority + 1));
2167 GNUNET_DATASTORE_get (dsh,
2170 &process_p2p_get_result,
2177 * The priority level imposes a bound on the maximum
2178 * value for the ttl that can be requested.
2180 * @param ttl_in requested ttl
2181 * @param prio given priority
2182 * @return ttl_in if ttl_in is below the limit,
2183 * otherwise the ttl-limit for the given priority
2186 bound_ttl (int32_t ttl_in, uint32_t prio)
2188 unsigned long long allowed;
2192 allowed = ((unsigned long long) prio) * TTL_DECREMENT / 1000;
2193 if (ttl_in > allowed)
2195 if (allowed >= (1 << 30))
2204 * We've received a request with the specified
2205 * priority. Bound it according to how much
2206 * we trust the given peer.
2208 * @param prio_in requested priority
2209 * @param peer the peer making the request
2210 * @return effective priority
2213 bound_priority (uint32_t prio_in,
2214 const struct GNUNET_PeerIdentity *peer)
2221 * Handle P2P "GET" request.
2223 * @param cls closure, always NULL
2224 * @param other the other peer involved (sender or receiver, NULL
2225 * for loopback messages where we are both sender and receiver)
2226 * @param message the actual message
2227 * @param latency reported latency of the connection with 'other'
2228 * @param distance reported distance (DV) to 'other'
2229 * @return GNUNET_OK to keep the connection open,
2230 * GNUNET_SYSERR to close it (signal serious error)
2233 handle_p2p_get (void *cls,
2234 const struct GNUNET_PeerIdentity *other,
2235 const struct GNUNET_MessageHeader *message,
2236 struct GNUNET_TIME_Relative latency,
2240 const struct GetMessage *gm;
2242 const GNUNET_HashCode *opt;
2243 struct ProcessGetContext *pgc;
2246 uint32_t ttl_decrement;
2251 msize = ntohs(message->size);
2252 if (msize < sizeof (struct GetMessage))
2254 GNUNET_break_op (0);
2255 return GNUNET_SYSERR;
2257 gm = (const struct GetMessage*) message;
2258 bm = ntohl (gm->hash_bitmap);
2266 if (msize < sizeof (struct GetMessage) + bits * sizeof (GNUNET_HashCode))
2268 GNUNET_break_op (0);
2269 return GNUNET_SYSERR;
2271 opt = (const GNUNET_HashCode*) &gm[1];
2272 bfsize = msize - sizeof (struct GetMessage) + bits * sizeof (GNUNET_HashCode);
2273 pgc = GNUNET_malloc (sizeof (struct ProcessGetContext));
2276 pgc->bf = GNUNET_CONTAINER_bloomfilter_init ((const char*) &pgc[1],
2279 pgc->bf_size = bfsize;
2281 pgc->type = ntohl (gm->type);
2282 pgc->bm = ntohl (gm->hash_bitmap);
2283 pgc->mingle = gm->filter_mutator;
2285 if (0 != (pgc->bm & GET_MESSAGE_BIT_RETURN_TO))
2286 pgc->reply_to.hashPubKey = opt[bits++];
2288 pgc->reply_to = *other;
2289 if (0 != (pgc->bm & GET_MESSAGE_BIT_SKS_NAMESPACE))
2290 pgc->namespace = opt[bits++];
2291 else if (pgc->type == GNUNET_DATASTORE_BLOCKTYPE_SBLOCK)
2293 GNUNET_break_op (0);
2295 return GNUNET_SYSERR;
2297 if (0 != (pgc->bm & GET_MESSAGE_BIT_TRANSMIT_TO))
2298 pgc->prime_target.hashPubKey = opt[bits++];
2299 /* note that we can really only check load here since otherwise
2300 peers could find out that we are overloaded by being disconnected
2301 after sending us a malformed query... */
2302 if (GNUNET_YES == test_load_too_high ())
2304 if (NULL != pgc->bf)
2305 GNUNET_CONTAINER_bloomfilter_free (pgc->bf);
2308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2309 "Dropping query from `%s', this peer is too busy.\n",
2310 GNUNET_i2s (other));
2314 net_load_up = 50; // FIXME
2315 net_load_down = 50; // FIXME
2316 pgc->policy = ROUTING_POLICY_NONE;
2317 if ( (net_load_up < IDLE_LOAD_THRESHOLD) &&
2318 (net_load_down < IDLE_LOAD_THRESHOLD) )
2320 pgc->policy |= ROUTING_POLICY_ALL;
2321 pgc->priority = 0; /* no charge */
2325 pgc->priority = bound_priority (ntohl (gm->priority), other);
2327 IDLE_LOAD_THRESHOLD + pgc->priority * pgc->priority) &&
2329 IDLE_LOAD_THRESHOLD + pgc->priority * pgc->priority) )
2331 pgc->policy |= ROUTING_POLICY_ALL;
2335 // FIXME: is this sound?
2336 if (net_load_up < 90 + 10 * pgc->priority)
2337 pgc->policy |= ROUTING_POLICY_FORWARD;
2338 if (net_load_down < 90 + 10 * pgc->priority)
2339 pgc->policy |= ROUTING_POLICY_ANSWER;
2342 if (pgc->policy == ROUTING_POLICY_NONE)
2345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2346 "Dropping query from `%s', network saturated.\n",
2347 GNUNET_i2s (other));
2349 if (NULL != pgc->bf)
2350 GNUNET_CONTAINER_bloomfilter_free (pgc->bf);
2352 return GNUNET_OK; /* drop */
2354 if ((pgc->policy & ROUTING_POLICY_INDIRECT) != ROUTING_POLICY_INDIRECT)
2355 pgc->priority = 0; /* kill the priority (we cannot benefit) */
2356 pgc->ttl = bound_ttl (ntohl (gm->ttl), pgc->priority);
2357 /* decrement ttl (always) */
2358 ttl_decrement = 2 * TTL_DECREMENT +
2359 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2361 if ( (pgc->ttl < 0) &&
2362 (pgc->ttl - ttl_decrement > 0) )
2365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2366 "Dropping query from `%s' due to TTL underflow.\n",
2367 GNUNET_i2s (other));
2369 /* integer underflow => drop (should be very rare)! */
2370 if (NULL != pgc->bf)
2371 GNUNET_CONTAINER_bloomfilter_free (pgc->bf);
2375 pgc->ttl -= ttl_decrement;
2376 pgc->start_time = GNUNET_TIME_absolute_get ();
2377 preference = (double) pgc->priority;
2378 if (preference < QUERY_BANDWIDTH_VALUE)
2379 preference = QUERY_BANDWIDTH_VALUE;
2380 // FIXME: also reserve bandwidth for reply?
2381 (void) GNUNET_CORE_peer_change_preference (sched, cfg,
2383 GNUNET_TIME_UNIT_FOREVER_REL,
2384 0, 0, preference, NULL, NULL);
2385 if (0 != (pgc->policy & ROUTING_POLICY_ANSWER))
2386 pgc->drq = queue_ds_request (BASIC_DATASTORE_REQUEST_DELAY,
2390 GNUNET_SCHEDULER_add_continuation (sched,
2391 &forward_get_request,
2393 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
2399 * Function called to notify us that we can now transmit a reply to a
2400 * client or peer. "buf" will be NULL and "size" zero if the socket was
2401 * closed for writing in the meantime.
2403 * @param cls closure, points to a "struct PendingRequest*" with
2404 * one or more pending replies
2405 * @param size number of bytes available in buf
2406 * @param buf where the callee should write the message
2407 * @return number of bytes written to buf
2410 transmit_result (void *cls,
2414 struct PendingRequest *pr = cls;
2416 struct PendingMessage *reply;
2420 while (NULL != (reply = pr->replies_pending))
2422 if ( (reply->msize + ret < ret) ||
2423 (reply->msize + ret > size) )
2425 pr->replies_pending = reply->next;
2426 memcpy (&cbuf[ret], &reply[1], reply->msize);
2427 ret += reply->msize;
2428 GNUNET_free (reply);
2435 * We have received a reply; handle it!
2437 * @param cls response (struct ProcessReplyClosure)
2438 * @param key our query
2439 * @param value value in the hash map (meta-info about the query)
2440 * @return GNUNET_YES (we should continue to iterate)
2443 process_reply (void *cls,
2444 const GNUNET_HashCode * key,
2447 struct ProcessReplyClosure *prq = cls;
2448 struct PendingRequest *pr = value;
2449 struct PendingRequest *eer;
2450 struct PendingMessage *reply;
2451 struct PutMessage *pm;
2452 struct ContentMessage *cm;
2453 struct ConnectedPeer *cp;
2454 GNUNET_HashCode chash;
2455 GNUNET_HashCode mhash;
2456 struct GNUNET_PeerIdentity target;
2459 struct GNUNET_TIME_Relative max_delay;
2461 GNUNET_CRYPTO_hash (prq->data,
2466 case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK:
2467 case GNUNET_DATASTORE_BLOCKTYPE_IBLOCK:
2469 case GNUNET_DATASTORE_BLOCKTYPE_SBLOCK:
2470 /* FIXME: does prq->namespace match our expectations? */
2471 /* then: fall-through??? */
2472 case GNUNET_DATASTORE_BLOCKTYPE_KBLOCK:
2475 mingle_hash (&chash, pr->mingle, &mhash);
2476 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (pr->bf,
2478 return GNUNET_YES; /* duplicate */
2479 GNUNET_CONTAINER_bloomfilter_add (pr->bf,
2483 case GNUNET_DATASTORE_BLOCKTYPE_SKBLOCK:
2484 // FIXME: any checks against duplicates for SKBlocks?
2487 prio = pr->priority;
2488 prq->priority += pr->remaining_priority;
2489 pr->remaining_priority = 0;
2490 if (pr->client != NULL)
2492 if (pr->replies_seen_size == pr->replies_seen_off)
2493 GNUNET_array_grow (pr->replies_seen,
2494 pr->replies_seen_size,
2495 pr->replies_seen_size * 2 + 4);
2496 pr->replies_seen[pr->replies_seen_off++] = chash;
2497 // FIXME: possibly recalculate BF!
2499 if (pr->client == NULL)
2501 GNUNET_PEER_resolve (pr->source_pid,
2503 cp = GNUNET_CONTAINER_multihashmap_get (connected_peers,
2504 &target.hashPubKey);
2505 msize = sizeof (struct ContentMessage) + prq->size;
2506 reply = GNUNET_malloc (msize + sizeof (struct PendingMessage));
2507 reply->msize = msize;
2508 reply->priority = (uint32_t) -1; /* send replies first! */
2509 cm = (struct ContentMessage*) &reply[1];
2510 cm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_CONTENT);
2511 cm->header.size = htons (msize);
2512 cm->type = htonl (prq->type);
2513 cm->expiration = GNUNET_TIME_absolute_hton (prq->expiration);
2514 memcpy (&reply[1], prq->data, prq->size);
2515 max_delay = GNUNET_TIME_UNIT_FOREVER_REL;
2516 if (GNUNET_CONTAINER_heap_get_size (requests_by_expiration) >= max_pending_requests)
2518 /* estimate expiration time from time difference between
2519 first request that will be discarded and this request */
2520 eer = GNUNET_CONTAINER_heap_peek (requests_by_expiration);
2521 max_delay = GNUNET_TIME_absolute_get_difference (pr->start_time,
2527 /* FIXME: bound queue size! */
2528 reply->next = pr->replies_pending;
2529 pr->replies_pending = reply;
2530 if (pr->cth == NULL)
2532 /* implicitly tries to connect */
2533 pr->cth = GNUNET_CORE_notify_transmit_ready (core,
2544 /* insert replies always at the head */
2545 reply->next = cp->pending_messages;
2546 cp->pending_messages = reply;
2547 if (cp->cth == NULL)
2548 cp->cth = GNUNET_CORE_notify_transmit_ready (core,
2550 GNUNET_TIME_UNIT_FOREVER_REL,
2553 &transmit_request_cb,
2559 msize = sizeof (struct PutMessage) + prq->size;
2560 reply = GNUNET_malloc (msize + sizeof (struct PendingMessage));
2561 reply->msize = msize;
2562 reply->next = pr->replies_pending;
2563 pm = (struct PutMessage*) &reply[1];
2564 pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT);
2565 pm->header.size = htons (msize);
2566 pm->type = htonl (prq->type);
2567 pm->expiration = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining (prq->expiration));
2568 pr->replies_pending = reply;
2569 memcpy (&reply[1], prq->data, prq->size);
2572 pr->th = GNUNET_SERVER_notify_transmit_ready (pr->client,
2574 GNUNET_TIME_UNIT_FOREVER_REL,
2579 // FIXME: need to try again later (not much
2580 // to do here specifically, but we need to
2581 // check somewhere else to handle this case!)
2584 // FIXME: implement hot-path routing statistics keeping!
2590 * Check if the given KBlock is well-formed.
2592 * @param kb the kblock data (or at least "dsize" bytes claiming to be one)
2593 * @param dsize size of "kb" in bytes; check for < sizeof(struct KBlock)!
2594 * @param query where to store the query that this block answers
2595 * @return GNUNET_OK if this is actually a well-formed KBlock
2598 check_kblock (const struct KBlock *kb,
2600 GNUNET_HashCode *query)
2602 if (dsize < sizeof (struct KBlock))
2604 GNUNET_break_op (0);
2605 return GNUNET_SYSERR;
2607 if (dsize - sizeof (struct KBlock) !=
2608 ntohs (kb->purpose.size)
2609 - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
2610 - sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) )
2612 GNUNET_break_op (0);
2613 return GNUNET_SYSERR;
2616 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK,
2621 GNUNET_break_op (0);
2622 return GNUNET_SYSERR;
2625 GNUNET_CRYPTO_hash (&kb->keyspace,
2626 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
2633 * Check if the given SBlock is well-formed.
2635 * @param sb the sblock data (or at least "dsize" bytes claiming to be one)
2636 * @param dsize size of "kb" in bytes; check for < sizeof(struct SBlock)!
2637 * @param query where to store the query that this block answers
2638 * @param namespace where to store the namespace that this block belongs to
2639 * @return GNUNET_OK if this is actually a well-formed SBlock
2642 check_sblock (const struct SBlock *sb,
2644 GNUNET_HashCode *query,
2645 GNUNET_HashCode *namespace)
2647 if (dsize < sizeof (struct SBlock))
2649 GNUNET_break_op (0);
2650 return GNUNET_SYSERR;
2653 ntohs (sb->purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature))
2655 GNUNET_break_op (0);
2656 return GNUNET_SYSERR;
2659 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK,
2664 GNUNET_break_op (0);
2665 return GNUNET_SYSERR;
2668 *query = sb->identifier;
2669 if (namespace != NULL)
2670 GNUNET_CRYPTO_hash (&sb->subspace,
2671 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
2678 * Handle P2P "PUT" request.
2680 * @param cls closure, always NULL
2681 * @param other the other peer involved (sender or receiver, NULL
2682 * for loopback messages where we are both sender and receiver)
2683 * @param message the actual message
2684 * @param latency reported latency of the connection with 'other'
2685 * @param distance reported distance (DV) to 'other'
2686 * @return GNUNET_OK to keep the connection open,
2687 * GNUNET_SYSERR to close it (signal serious error)
2690 handle_p2p_put (void *cls,
2691 const struct GNUNET_PeerIdentity *other,
2692 const struct GNUNET_MessageHeader *message,
2693 struct GNUNET_TIME_Relative latency,
2696 const struct PutMessage *put;
2700 struct GNUNET_TIME_Absolute expiration;
2701 GNUNET_HashCode query;
2702 struct ProcessReplyClosure prq;
2704 msize = ntohs (message->size);
2705 if (msize < sizeof (struct PutMessage))
2708 return GNUNET_SYSERR;
2710 put = (const struct PutMessage*) message;
2711 dsize = msize - sizeof (struct PutMessage);
2712 type = ntohl (put->type);
2713 expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_ntoh (put->expiration));
2715 /* first, validate! */
2718 case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK:
2719 case GNUNET_DATASTORE_BLOCKTYPE_IBLOCK:
2720 GNUNET_CRYPTO_hash (&put[1], dsize, &query);
2722 case GNUNET_DATASTORE_BLOCKTYPE_KBLOCK:
2724 check_kblock ((const struct KBlock*) &put[1],
2727 return GNUNET_SYSERR;
2729 case GNUNET_DATASTORE_BLOCKTYPE_SBLOCK:
2731 check_sblock ((const struct SBlock*) &put[1],
2735 return GNUNET_SYSERR;
2737 case GNUNET_DATASTORE_BLOCKTYPE_SKBLOCK:
2738 // FIXME -- validate SKBLOCK!
2742 /* unknown block type */
2743 GNUNET_break_op (0);
2744 return GNUNET_SYSERR;
2747 /* now, lookup 'query' */
2748 prq.data = (const void*) &put[1];
2751 prq.expiration = expiration;
2753 GNUNET_CONTAINER_multihashmap_get_multiple (requests_by_query,
2757 // FIXME: if migration is on and load is low,
2758 // queue to store data in datastore;
2759 // use "prq.priority" for that!
2765 * List of handlers for P2P messages
2766 * that we care about.
2768 static struct GNUNET_CORE_MessageHandler p2p_handlers[] =
2771 GNUNET_MESSAGE_TYPE_FS_GET, 0 },
2773 GNUNET_MESSAGE_TYPE_FS_PUT, 0 },
2779 * Process fs requests.
2781 * @param cls closure
2782 * @param s scheduler to use
2783 * @param server the initialized server
2784 * @param c configuration to use
2788 struct GNUNET_SCHEDULER_Handle *s,
2789 struct GNUNET_SERVER_Handle *server,
2790 const struct GNUNET_CONFIGURATION_Handle *c)
2795 requests_by_query = GNUNET_CONTAINER_multihashmap_create (128); // FIXME: get size from config
2796 requests_by_peer = GNUNET_CONTAINER_multihashmap_create (128); // FIXME: get size from config
2797 connected_peers = GNUNET_CONTAINER_multihashmap_create (64);
2798 requests_by_expiration = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
2799 GNUNET_FS_init_indexing (sched, cfg);
2800 dsh = GNUNET_DATASTORE_connect (cfg,
2802 core = GNUNET_CORE_connect (sched,
2804 GNUNET_TIME_UNIT_FOREVER_REL,
2808 &peer_connect_handler,
2809 &peer_disconnect_handler,
2814 GNUNET_SERVER_disconnect_notify (server,
2815 &handle_client_disconnect,
2817 GNUNET_SERVER_add_handlers (server, handlers);
2818 GNUNET_SCHEDULER_add_delayed (sched,
2819 GNUNET_TIME_UNIT_FOREVER_REL,
2824 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2825 _("Failed to connect to `%s' service.\n"),
2827 GNUNET_SCHEDULER_shutdown (sched);
2832 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2833 _("Failed to connect to `%s' service.\n"),
2835 GNUNET_SCHEDULER_shutdown (sched);
2842 * The main function for the fs service.
2844 * @param argc number of arguments from the command line
2845 * @param argv command line arguments
2846 * @return 0 ok, 1 on error
2849 main (int argc, char *const *argv)
2851 return (GNUNET_OK ==
2852 GNUNET_SERVICE_run (argc,
2855 GNUNET_SERVICE_OPTION_NONE,
2856 &run, NULL)) ? 0 : 1;
2859 /* end of gnunet-service-fs.c */