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 * - tracking of PendingRequests (and defining that struct...)
28 * - setup P2P search on CS request
29 * - setup P2P search on P2P GET
30 * - forward replies based on tracked requests
31 * - validation of KBLOCKS (almost done)
32 * - validation of SBLOCKS
33 * - validation of KSBLOCKS
34 * - content migration (put in local DS)
35 * - possible major issue: we may
36 * queue "gazillions" of (K|S)Blocks for the
37 * core to transmit to another peer; need
38 * to make sure this is bounded overall...
39 * - various load-based actions (can wait)
40 * - remove on-demand blocks if they keep failing (can wait)
43 #include "gnunet_core_service.h"
44 #include "gnunet_datastore_service.h"
45 #include "gnunet_protocols.h"
46 #include "gnunet_signatures.h"
47 #include "gnunet_util_lib.h"
52 * In-memory information about indexed files (also available
59 * This is a linked list.
61 struct IndexInfo *next;
64 * Name of the indexed file. Memory allocated
65 * at the end of this struct (do not free).
70 * Context for transmitting confirmation to client,
71 * NULL if we've done this already.
73 struct GNUNET_SERVER_TransmitContext *tc;
76 * Hash of the contents of the file.
78 GNUNET_HashCode file_id;
84 * Signature of a function that is called whenever a datastore
85 * request can be processed (or an entry put on the queue times out).
88 * @param ok GNUNET_OK if DS is ready, GNUNET_SYSERR on timeout
90 typedef void (*RequestFunction)(void *cls,
95 * Doubly-linked list of our requests for the datastore.
97 struct DatastoreRequestQueue
101 * This is a doubly-linked list.
103 struct DatastoreRequestQueue *next;
106 * This is a doubly-linked list.
108 struct DatastoreRequestQueue *prev;
111 * Function to call (will issue the request).
121 * When should this request time-out because we don't care anymore?
123 struct GNUNET_TIME_Absolute timeout;
126 * ID of task used for signaling timeout.
128 GNUNET_SCHEDULER_TaskIdentifier task;
134 * Closure for processing START_SEARCH messages from a client.
136 struct LocalGetContext
140 * This is a doubly-linked list.
142 struct LocalGetContext *next;
145 * This is a doubly-linked list.
147 struct LocalGetContext *prev;
150 * Client that initiated the search.
152 struct GNUNET_SERVER_Client *client;
155 * Array of results that we've already received
158 GNUNET_HashCode *results;
161 * Bloomfilter over all results (for fast query construction);
162 * NULL if we don't have any results.
164 struct GNUNET_CONTAINER_BloomFilter *results_bf;
167 * DS request associated with this operation.
169 struct DatastoreRequestQueue *req;
172 * Current result message to transmit to client (or NULL).
174 struct ContentMessage *result;
177 * Type of the content that we're looking for.
183 * Desired anonymity level.
185 uint32_t anonymity_level;
188 * Number of results actually stored in the results array.
190 unsigned int results_used;
193 * Size of the results array in memory.
195 unsigned int results_size;
198 * If the request is for a DBLOCK or IBLOCK, this is the identity of
199 * the peer that is known to have a response. Set to all-zeros if
200 * such a target is not known (note that even if OUR anonymity
201 * level is >0 we may happen to know the responder's identity;
202 * nevertheless, we should probably not use it for a DHT-lookup
203 * or similar blunt actions in order to avoid exposing ourselves).
205 * If the request is for an SBLOCK, this is the identity of the
206 * pseudonym to which the SBLOCK belongs.
208 * If the request is for a KBLOCK, "target" must be all zeros.
210 GNUNET_HashCode target;
213 * Hash of the keyword (aka query) for KBLOCKs; Hash of
214 * the CHK-encoded block for DBLOCKS and IBLOCKS (aka query)
215 * and hash of the identifier XORed with the target for
216 * SBLOCKS (aka query).
218 GNUNET_HashCode query;
224 * Possible routing policies for an FS-GET request.
229 * Simply drop the request.
231 ROUTING_POLICY_NONE = 0,
234 * Answer it if we can from local datastore.
236 ROUTING_POLICY_ANSWER = 1,
239 * Forward the request to other peers (if possible).
241 ROUTING_POLICY_FORWARD = 2,
244 * Forward to other peers, and ask them to route
245 * the response via ourselves.
247 ROUTING_POLICY_INDIRECT = 6,
250 * Do everything we could possibly do (that would
253 ROUTING_POLICY_ALL = 7
258 * Internal context we use for our initial processing
261 struct ProcessGetContext
264 * The search query (used for datastore lookup).
266 GNUNET_HashCode query;
269 * Which peer we should forward the response to.
271 struct GNUNET_PeerIdentity reply_to;
274 * Namespace for the result (only set for SKS requests)
276 GNUNET_HashCode namespace;
279 * Peer that we should forward the query to if possible
280 * (since that peer likely has the content).
282 struct GNUNET_PeerIdentity prime_target;
285 * When did we receive this request?
287 struct GNUNET_TIME_Absolute start_time;
290 * Our entry in the DRQ (non-NULL while we wait for our
291 * turn to interact with the local database).
293 struct DatastoreRequestQueue *drq;
296 * Filter used to eliminate duplicate
297 * results. Can be NULL if we are
298 * not yet filtering any results.
300 struct GNUNET_CONTAINER_BloomFilter *bf;
303 * Bitmap describing which of the optional
304 * hash codes / peer identities were given to us.
309 * Desired block type.
314 * Priority of the request.
319 * In what ways are we going to process
322 enum RoutingPolicy policy;
325 * Time-to-live for the request (value
331 * Number to mingle hashes for bloom-filter
337 * Number of results that were found so far.
339 unsigned int results_found;
344 * Information we keep for each pending
347 struct PendingRequest
354 * Closure for "process_reply" function.
356 struct ProcessReplyClosure
359 * The data for the reply.
364 * When the reply expires.
366 struct GNUNET_TIME_Absolute expiration;
379 * How much was this reply worth to us?
386 * Map from queries to pending requests ("struct PendingRequest") for
389 static struct GNUNET_CONTAINER_MultiHashMap *request_map;
392 * Our connection to the datastore.
394 static struct GNUNET_DATASTORE_Handle *dsh;
399 static struct GNUNET_SCHEDULER_Handle *sched;
404 const struct GNUNET_CONFIGURATION_Handle *cfg;
407 * Handle to the core service (NULL until we've
410 struct GNUNET_CORE_Handle *core;
413 * Head of doubly-linked LGC list.
415 static struct LocalGetContext *lgc_head;
418 * Tail of doubly-linked LGC list.
420 static struct LocalGetContext *lgc_tail;
423 * Head of request queue for the datastore, sorted by timeout.
425 static struct DatastoreRequestQueue *drq_head;
428 * Tail of request queue for the datastore.
430 static struct DatastoreRequestQueue *drq_tail;
433 * Linked list of indexed files.
435 static struct IndexInfo *indexed_files;
438 * Maps hash over content of indexed files
439 * to the respective filename. The filenames
440 * are pointers into the indexed_files linked
441 * list and do not need to be freed.
443 static struct GNUNET_CONTAINER_MultiHashMap *ifm;
447 * Write the current index information list to disk.
452 struct GNUNET_BIO_WriteHandle *wh;
454 struct IndexInfo *pos;
457 GNUNET_CONFIGURATION_get_value_filename (cfg,
462 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
463 _("Configuration option `%s' in section `%s' missing.\n"),
468 wh = GNUNET_BIO_write_open (fn);
471 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
472 _("Could not open `%s'.\n"),
481 GNUNET_BIO_write (wh,
483 sizeof (GNUNET_HashCode))) ||
485 GNUNET_BIO_write_string (wh,
491 GNUNET_BIO_write_close (wh))
493 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
494 _("Error writing `%s'.\n"),
504 * Read index information from disk.
509 struct GNUNET_BIO_ReadHandle *rh;
511 struct IndexInfo *pos;
518 GNUNET_CONFIGURATION_get_value_filename (cfg,
523 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
524 _("Configuration option `%s' in section `%s' missing.\n"),
529 rh = GNUNET_BIO_read_open (fn);
532 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
533 _("Could not open `%s'.\n"),
539 while ( (GNUNET_OK ==
541 "Hash of indexed file",
543 sizeof (GNUNET_HashCode))) &&
545 GNUNET_BIO_read_string (rh,
546 "Name of indexed file",
550 slen = strlen (fname) + 1;
551 pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
553 pos->filename = (const char *) &pos[1];
554 memcpy (&pos[1], fname, slen);
556 GNUNET_CONTAINER_multihashmap_put (ifm,
558 (void*) pos->filename,
559 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
565 pos->next = indexed_files;
570 GNUNET_BIO_read_close (rh, &emsg))
577 * We've validated the hash of the file we're about to
578 * index. Signal success to the client and update
579 * our internal data structures.
581 * @param ii the index info entry for the request
584 signal_index_ok (struct IndexInfo *ii)
587 GNUNET_CONTAINER_multihashmap_put (ifm,
589 (void*) ii->filename,
590 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
592 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
593 _("Index request received for file `%s' is indexed as `%s'. Permitting anyway.\n"),
595 (const char*) GNUNET_CONTAINER_multihashmap_get (ifm,
597 GNUNET_SERVER_transmit_context_append (ii->tc,
599 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
600 GNUNET_SERVER_transmit_context_run (ii->tc,
601 GNUNET_TIME_UNIT_MINUTES);
605 ii->next = indexed_files;
608 GNUNET_SERVER_transmit_context_append (ii->tc,
610 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
611 GNUNET_SERVER_transmit_context_run (ii->tc,
612 GNUNET_TIME_UNIT_MINUTES);
618 * Function called once the hash computation over an
619 * indexed file has completed.
621 * @param cls closure, our publishing context
622 * @param res resulting hash, NULL on error
625 hash_for_index_val (void *cls,
626 const GNUNET_HashCode *
629 struct IndexInfo *ii = cls;
631 if ( (res == NULL) ||
634 sizeof(GNUNET_HashCode))) )
636 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
637 _("Hash mismatch trying to index file `%s'\n"),
639 GNUNET_SERVER_transmit_context_append (ii->tc,
641 GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED);
642 GNUNET_SERVER_transmit_context_run (ii->tc,
643 GNUNET_TIME_UNIT_MINUTES);
647 signal_index_ok (ii);
652 * Handle INDEX_START-message.
655 * @param client identification of the client
656 * @param message the actual message
659 handle_index_start (void *cls,
660 struct GNUNET_SERVER_Client *client,
661 const struct GNUNET_MessageHeader *message)
663 const struct IndexStartMessage *ism;
666 struct IndexInfo *ii;
673 msize = ntohs(message->size);
674 if ( (msize <= sizeof (struct IndexStartMessage)) ||
675 ( ((const char *)message)[msize-1] != '\0') )
678 GNUNET_SERVER_receive_done (client,
682 ism = (const struct IndexStartMessage*) message;
683 fn = (const char*) &ism[1];
684 dev = ntohl (ism->device);
685 ino = GNUNET_ntohll (ism->inode);
686 ism = (const struct IndexStartMessage*) message;
687 slen = strlen (fn) + 1;
688 ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
689 ii->filename = (const char*) &ii[1];
690 memcpy (&ii[1], fn, slen);
691 ii->file_id = ism->file_id;
692 ii->tc = GNUNET_SERVER_transmit_context_create (client);
695 (GNUNET_OK == GNUNET_DISK_file_get_identifiers (fn,
701 /* fast validation OK! */
702 signal_index_ok (ii);
705 /* slow validation, need to hash full file (again) */
706 GNUNET_CRYPTO_hash_file (sched,
707 GNUNET_SCHEDULER_PRIORITY_IDLE,
717 * Handle INDEX_LIST_GET-message.
720 * @param client identification of the client
721 * @param message the actual message
724 handle_index_list_get (void *cls,
725 struct GNUNET_SERVER_Client *client,
726 const struct GNUNET_MessageHeader *message)
728 struct GNUNET_SERVER_TransmitContext *tc;
729 struct IndexInfoMessage *iim;
730 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
733 struct GNUNET_MessageHeader *msg;
734 struct IndexInfo *pos;
736 tc = GNUNET_SERVER_transmit_context_create (client);
737 iim = (struct IndexInfoMessage*) buf;
743 iim->file_id = pos->file_id;
745 slen = strlen (fn) + 1;
746 if (slen + sizeof (struct IndexInfoMessage) >
747 GNUNET_SERVER_MAX_MESSAGE_SIZE)
752 memcpy (&iim[1], fn, slen);
753 GNUNET_SERVER_transmit_context_append
756 sizeof (struct IndexInfoMessage)
757 - sizeof (struct GNUNET_MessageHeader) + slen,
758 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
761 GNUNET_SERVER_transmit_context_append (tc,
763 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
764 GNUNET_SERVER_transmit_context_run (tc,
765 GNUNET_TIME_UNIT_MINUTES);
770 * Handle UNINDEX-message.
773 * @param client identification of the client
774 * @param message the actual message
777 handle_unindex (void *cls,
778 struct GNUNET_SERVER_Client *client,
779 const struct GNUNET_MessageHeader *message)
781 const struct UnindexMessage *um;
782 struct IndexInfo *pos;
783 struct IndexInfo *prev;
784 struct IndexInfo *next;
785 struct GNUNET_SERVER_TransmitContext *tc;
788 um = (const struct UnindexMessage*) message;
795 if (0 == memcmp (&pos->file_id,
797 sizeof (GNUNET_HashCode)))
800 indexed_files = pos->next;
802 prev->next = pos->next;
812 if (GNUNET_YES == found)
814 tc = GNUNET_SERVER_transmit_context_create (client);
815 GNUNET_SERVER_transmit_context_append (tc,
817 GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK);
818 GNUNET_SERVER_transmit_context_run (tc,
819 GNUNET_TIME_UNIT_MINUTES);
824 * Run the next DS request in our
825 * queue, we're done with the current one.
830 struct DatastoreRequestQueue *e;
832 while (NULL != (e = drq_head))
834 if (0 != GNUNET_TIME_absolute_get_remaining (e->timeout).value)
836 if (e->task != GNUNET_SCHEDULER_NO_TASK)
837 GNUNET_SCHEDULER_cancel (sched, e->task);
838 GNUNET_CONTAINER_DLL_remove (drq_head, drq_tail, e);
839 e->req (e->req_cls, GNUNET_NO);
844 if (e->task != GNUNET_SCHEDULER_NO_TASK)
845 GNUNET_SCHEDULER_cancel (sched, e->task);
846 e->task = GNUNET_SCHEDULER_NO_TASK;
847 e->req (e->req_cls, GNUNET_YES);
848 GNUNET_CONTAINER_DLL_remove (drq_head, drq_tail, e);
854 * A datastore request had to be timed out.
856 * @param cls closure (of type "struct DatastoreRequestQueue*")
857 * @param tc task context, unused
860 timeout_ds_request (void *cls,
861 const struct GNUNET_SCHEDULER_TaskContext *tc)
863 struct DatastoreRequestQueue *e = cls;
865 e->task = GNUNET_SCHEDULER_NO_TASK;
866 GNUNET_CONTAINER_DLL_remove (drq_head, drq_tail, e);
867 e->req (e->req_cls, GNUNET_NO);
873 * Queue a request for the datastore.
875 * @param deadline by when the request should run
876 * @param fun function to call once the request can be run
877 * @param fun_cls closure for fun
879 static struct DatastoreRequestQueue *
880 queue_ds_request (struct GNUNET_TIME_Relative deadline,
884 struct DatastoreRequestQueue *e;
885 struct DatastoreRequestQueue *bef;
887 if (drq_head == NULL)
889 /* no other requests pending, run immediately */
890 fun (fun_cls, GNUNET_OK);
893 e = GNUNET_malloc (sizeof (struct DatastoreRequestQueue));
894 e->timeout = GNUNET_TIME_relative_to_absolute (deadline);
896 e->req_cls = fun_cls;
897 if (deadline.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
899 /* local request, highest prio, put at head of queue
900 regardless of deadline */
906 while ( (NULL != bef) &&
907 (e->timeout.value < bef->timeout.value) )
910 GNUNET_CONTAINER_DLL_insert_after (drq_head, drq_tail, bef, e);
911 if (deadline.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
913 e->task = GNUNET_SCHEDULER_add_delayed (sched,
915 GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
916 GNUNET_SCHEDULER_NO_TASK,
925 * Free the state associated with a local get context.
927 * @param lgc the lgc to free
930 local_get_context_free (struct LocalGetContext *lgc)
932 GNUNET_CONTAINER_DLL_remove (lgc_head, lgc_tail, lgc);
933 GNUNET_SERVER_client_drop (lgc->client);
934 GNUNET_free_non_null (lgc->results);
935 if (lgc->results_bf != NULL)
936 GNUNET_CONTAINER_bloomfilter_free (lgc->results_bf);
937 if (lgc->req != NULL)
939 if (lgc->req->task != GNUNET_SCHEDULER_NO_TASK)
940 GNUNET_SCHEDULER_cancel (sched, lgc->req->task);
941 GNUNET_CONTAINER_DLL_remove (lgc_head, lgc_tail, lgc);
942 GNUNET_free (lgc->req);
949 * We're able to transmit the next (local) result to the client.
950 * Do it and ask the datastore for more. Or, on error, tell
951 * the datastore to stop giving us more.
953 * @param cls our closure (struct LocalGetContext)
954 * @param max maximum number of bytes we can transmit
955 * @param buf where to copy our message
956 * @return number of bytes copied to buf
959 transmit_local_result (void *cls,
963 struct LocalGetContext *lgc = cls;
969 GNUNET_free (lgc->result);
971 GNUNET_DATASTORE_get_next (dsh, GNUNET_NO);
974 msize = ntohs (lgc->result->header.size);
975 GNUNET_assert (max >= msize);
976 memcpy (buf, lgc->result, msize);
977 GNUNET_free (lgc->result);
979 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
985 * Continuation called from datastore's remove
989 * @param success did the deletion work?
990 * @param msg error message
993 remove_cont (void *cls,
997 if (GNUNET_OK != success)
998 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
999 _("Failed to delete bogus block: %s\n"),
1001 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
1006 * Mingle hash with the mingle_number to
1007 * produce different bits.
1010 mingle_hash (const GNUNET_HashCode * in,
1011 int32_t mingle_number,
1012 GNUNET_HashCode * hc)
1016 GNUNET_CRYPTO_hash (&mingle_number,
1019 GNUNET_CRYPTO_hash_xor (&m, in, hc);
1024 * We've received an on-demand encoded block
1025 * from the datastore. Attempt to do on-demand
1026 * encoding and (if successful), call the
1027 * continuation with the resulting block. On
1028 * error, clean up and ask the datastore for
1031 * @param key key for the content
1032 * @param size number of bytes in data
1033 * @param data content stored
1034 * @param type type of the content
1035 * @param priority priority of the content
1036 * @param anonymity anonymity-level for the content
1037 * @param expiration expiration time for the content
1038 * @param uid unique identifier for the datum;
1039 * maybe 0 if no unique identifier is available
1040 * @param cont function to call with the actual block
1041 * @param cont_cls closure for cont
1044 handle_on_demand_block (const GNUNET_HashCode * key,
1050 struct GNUNET_TIME_Absolute
1051 expiration, uint64_t uid,
1052 GNUNET_DATASTORE_Iterator cont,
1055 const struct OnDemandBlock *odb;
1056 GNUNET_HashCode nkey;
1057 struct GNUNET_CRYPTO_AesSessionKey skey;
1058 struct GNUNET_CRYPTO_AesInitializationVector iv;
1059 GNUNET_HashCode query;
1061 char ndata[DBLOCK_SIZE];
1062 char edata[DBLOCK_SIZE];
1064 struct GNUNET_DISK_FileHandle *fh;
1067 if (size != sizeof (struct OnDemandBlock))
1070 GNUNET_DATASTORE_remove (dsh,
1076 GNUNET_TIME_UNIT_FOREVER_REL);
1079 odb = (const struct OnDemandBlock*) data;
1080 off = GNUNET_ntohll (odb->offset);
1081 fn = (const char*) GNUNET_CONTAINER_multihashmap_get (ifm,
1083 if ( (NULL == fn) ||
1084 (NULL == (fh = GNUNET_DISK_file_open (fn,
1085 GNUNET_DISK_OPEN_READ))) ||
1087 GNUNET_DISK_file_seek (fh,
1089 GNUNET_DISK_SEEK_SET)) ||
1091 (nsize = GNUNET_DISK_file_read (fh,
1095 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1096 _("Could not access indexed file `%s' at offset %llu: %s\n"),
1097 GNUNET_h2s (&odb->file_id),
1098 (unsigned long long) off,
1101 GNUNET_DISK_file_close (fh);
1102 /* FIXME: if this happens often, we need
1103 to remove the OnDemand block from the DS! */
1104 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
1107 GNUNET_DISK_file_close (fh);
1108 GNUNET_CRYPTO_hash (ndata,
1111 GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv);
1112 GNUNET_CRYPTO_aes_encrypt (ndata,
1117 GNUNET_CRYPTO_hash (edata,
1120 if (0 != memcmp (&query,
1122 sizeof (GNUNET_HashCode)))
1124 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1125 _("Indexed file `%s' changed at offset %llu\n"),
1127 (unsigned long long) off);
1128 /* FIXME: if this happens often, we need
1129 to remove the OnDemand block from the DS! */
1130 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
1137 GNUNET_DATASTORE_BLOCKTYPE_DBLOCK,
1146 * We're processing (local) results for a search request
1147 * from a (local) client. Pass applicable results to the
1148 * client and if we are done either clean up (operation
1149 * complete) or switch to P2P search (more results possible).
1151 * @param cls our closure (struct LocalGetContext)
1152 * @param key key for the content
1153 * @param size number of bytes in data
1154 * @param data content stored
1155 * @param type type of the content
1156 * @param priority priority of the content
1157 * @param anonymity anonymity-level for the content
1158 * @param expiration expiration time for the content
1159 * @param uid unique identifier for the datum;
1160 * maybe 0 if no unique identifier is available
1163 process_local_get_result (void *cls,
1164 const GNUNET_HashCode * key,
1170 struct GNUNET_TIME_Absolute
1174 struct LocalGetContext *lgc = cls;
1180 /* no further results from datastore; continue
1181 processing further requests from the client and
1182 allow the next task to use the datastore; also,
1183 switch to P2P requests or clean up our state. */
1185 GNUNET_SERVER_receive_done (lgc->client,
1187 if ( (lgc->results_used == 0) ||
1188 (lgc->type == GNUNET_DATASTORE_BLOCKTYPE_KBLOCK) ||
1189 (lgc->type == GNUNET_DATASTORE_BLOCKTYPE_SBLOCK) ||
1190 (lgc->type == GNUNET_DATASTORE_BLOCKTYPE_SKBLOCK) )
1192 // FIXME: initiate P2P search
1195 /* got all possible results, clean up! */
1196 local_get_context_free (lgc);
1199 if (type == GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND)
1201 handle_on_demand_block (key, size, data, type, priority,
1202 anonymity, expiration, uid,
1203 &process_local_get_result,
1207 if (type != lgc->type)
1209 /* this should be virtually impossible to reach (DBLOCK
1210 query hash being identical to KBLOCK/SBLOCK query hash);
1211 nevertheless, if it happens, the correct thing is to
1212 simply skip the result. */
1213 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
1216 /* check if this is a result we've alredy
1218 for (i=0;i<lgc->results_used;i++)
1219 if (0 == memcmp (key,
1221 sizeof (GNUNET_HashCode)))
1223 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
1226 if (lgc->results_used == lgc->results_size)
1227 GNUNET_array_grow (lgc->results,
1229 lgc->results_size * 2 + 2);
1230 GNUNET_CRYPTO_hash (data,
1232 &lgc->results[lgc->results_used++]);
1233 msize = size + sizeof (struct ContentMessage);
1234 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
1235 lgc->result = GNUNET_malloc (msize);
1236 lgc->result->header.size = htons (msize);
1237 lgc->result->header.type = htons (GNUNET_MESSAGE_TYPE_FS_CONTENT);
1238 lgc->result->type = htonl (type);
1239 lgc->result->expiration = GNUNET_TIME_absolute_hton (expiration);
1240 memcpy (&lgc->result[1],
1243 GNUNET_SERVER_notify_transmit_ready (lgc->client,
1245 GNUNET_TIME_UNIT_FOREVER_REL,
1246 &transmit_local_result,
1252 * We're processing a search request from a local
1253 * client. Now it is our turn to query the datastore.
1255 * @param cls our closure (struct LocalGetContext)
1259 transmit_local_get (void *cls,
1260 const struct GNUNET_SCHEDULER_TaskContext *tc)
1262 struct LocalGetContext *lgc = cls;
1266 if (type == GNUNET_DATASTORE_BLOCKTYPE_DBLOCK)
1267 type = GNUNET_DATASTORE_BLOCKTYPE_ANY; /* to get on-demand as well */
1268 GNUNET_DATASTORE_get (dsh,
1271 &process_local_get_result,
1273 GNUNET_TIME_UNIT_FOREVER_REL);
1278 * We're processing a search request from a local
1279 * client. Now it is our turn to query the datastore.
1281 * @param cls our closure (struct LocalGetContext)
1282 * @param ok did we succeed to queue for datastore access, should always be GNUNET_OK
1285 transmit_local_get_ready (void *cls,
1288 struct LocalGetContext *lgc = cls;
1290 GNUNET_assert (GNUNET_OK == ok);
1291 GNUNET_SCHEDULER_add_continuation (sched,
1293 &transmit_local_get,
1295 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1300 * Handle START_SEARCH-message (search request from client).
1302 * @param cls closure
1303 * @param client identification of the client
1304 * @param message the actual message
1307 handle_start_search (void *cls,
1308 struct GNUNET_SERVER_Client *client,
1309 const struct GNUNET_MessageHeader *message)
1311 const struct SearchMessage *sm;
1312 struct LocalGetContext *lgc;
1316 msize = ntohs (message->size);
1317 if ( (msize < sizeof (struct SearchMessage)) ||
1318 (0 != (msize - sizeof (struct SearchMessage)) % sizeof (GNUNET_HashCode)) )
1321 GNUNET_SERVER_receive_done (client,
1325 sc = (msize - sizeof (struct SearchMessage)) / sizeof (GNUNET_HashCode);
1326 sm = (const struct SearchMessage*) message;
1327 GNUNET_SERVER_client_keep (client);
1328 lgc = GNUNET_malloc (sizeof (struct LocalGetContext));
1331 lgc->results_used = sc;
1332 GNUNET_array_grow (lgc->results,
1335 memcpy (lgc->results,
1337 sc * sizeof (GNUNET_HashCode));
1339 lgc->client = client;
1340 lgc->type = ntohl (sm->type);
1341 lgc->anonymity_level = ntohl (sm->anonymity_level);
1342 lgc->target = sm->target;
1343 lgc->query = sm->query;
1344 GNUNET_CONTAINER_DLL_insert (lgc_head, lgc_tail, lgc);
1345 lgc->req = queue_ds_request (GNUNET_TIME_UNIT_FOREVER_REL,
1346 &transmit_local_get_ready,
1352 * List of handlers for the messages understood by this
1355 static struct GNUNET_SERVER_MessageHandler handlers[] = {
1356 {&handle_index_start, NULL,
1357 GNUNET_MESSAGE_TYPE_FS_INDEX_START, 0},
1358 {&handle_index_list_get, NULL,
1359 GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET, sizeof(struct GNUNET_MessageHeader) },
1360 {&handle_unindex, NULL, GNUNET_MESSAGE_TYPE_FS_UNINDEX,
1361 sizeof (struct UnindexMessage) },
1362 {&handle_start_search, NULL, GNUNET_MESSAGE_TYPE_FS_START_SEARCH,
1369 * A client disconnected. Remove all of its pending queries.
1371 * @param cls closure, NULL
1372 * @param client identification of the client
1375 handle_client_disconnect (void *cls,
1376 struct GNUNET_SERVER_Client
1379 struct LocalGetContext *lgc;
1382 while ( (NULL != lgc) &&
1383 (lgc->client != client) )
1386 return; /* not one of our clients */
1387 local_get_context_free (lgc);
1392 * Task run during shutdown.
1398 shutdown_task (void *cls,
1399 const struct GNUNET_SCHEDULER_TaskContext *tc)
1401 struct IndexInfo *pos;
1404 GNUNET_CORE_disconnect (core);
1405 GNUNET_DATASTORE_disconnect (dsh,
1408 // FIXME: iterate over 'request_map' to free entries!
1409 GNUNET_CONTAINER_multihashmap_destroy (request_map);
1411 GNUNET_CONTAINER_multihashmap_destroy (ifm);
1413 while (NULL != (pos = indexed_files))
1415 indexed_files = pos->next;
1422 * Method called whenever a peer disconnects.
1424 * @param cls closure, not used
1425 * @param peer peer identity this notification is about
1428 peer_disconnect_handler (void *cls,
1430 GNUNET_PeerIdentity * peer)
1432 // FIXME: remove all pending requests from this
1433 // peer from our memory
1434 // (iterate over request_map)
1439 * We're processing a GET request from
1440 * another peer and have decided to forward
1441 * it to other peers.
1443 * @param cls our "struct ProcessGetContext *"
1447 forward_get_request (void *cls,
1448 const struct GNUNET_SCHEDULER_TaskContext *tc)
1450 struct ProcessGetContext *pgc = cls;
1452 // FIXME: install entry in
1453 // 'request_map' and do actual
1455 if (pgc->bf != NULL)
1456 GNUNET_CONTAINER_bloomfilter_free (pgc->bf);
1462 * Transmit the given message by copying it to
1463 * the target buffer "buf". "buf" will be
1464 * NULL and "size" zero if the socket was closed for
1465 * writing in the meantime. In that case, only
1468 * @param cls closure, pointer to the message
1469 * @param size number of bytes available in buf
1470 * @param buf where the callee should write the message
1471 * @return number of bytes written to buf
1474 transmit_message (void *cls,
1475 size_t size, void *buf)
1477 struct GNUNET_MessageHeader *msg = cls;
1483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1484 "Dropping reply, core too busy.\n");
1489 msize = ntohs (msg->size);
1490 GNUNET_assert (size >= msize);
1491 memcpy (buf, msg, msize);
1498 * Test if the load on this peer is too high
1499 * to even consider processing the query at
1502 * @return GNUNET_YES if the load is too high, GNUNET_NO otherwise
1505 test_load_too_high ()
1507 return GNUNET_NO; // FIXME
1512 * We're processing (local) results for a search request
1513 * from another peer. Pass applicable results to the
1514 * peer and if we are done either clean up (operation
1515 * complete) or forward to other peers (more results possible).
1517 * @param cls our closure (struct LocalGetContext)
1518 * @param key key for the content
1519 * @param size number of bytes in data
1520 * @param data content stored
1521 * @param type type of the content
1522 * @param priority priority of the content
1523 * @param anonymity anonymity-level for the content
1524 * @param expiration expiration time for the content
1525 * @param uid unique identifier for the datum;
1526 * maybe 0 if no unique identifier is available
1529 process_p2p_get_result (void *cls,
1530 const GNUNET_HashCode * key,
1536 struct GNUNET_TIME_Absolute
1540 struct ProcessGetContext *pgc = cls;
1541 GNUNET_HashCode dhash;
1542 GNUNET_HashCode mhash;
1543 struct PutMessage *reply;
1547 /* no more results */
1548 if ( ( (pgc->policy & ROUTING_POLICY_FORWARD) == ROUTING_POLICY_FORWARD) &&
1549 ( (0 == pgc->results_found) ||
1550 (pgc->type == GNUNET_DATASTORE_BLOCKTYPE_KBLOCK) ||
1551 (pgc->type == GNUNET_DATASTORE_BLOCKTYPE_SBLOCK) ||
1552 (pgc->type == GNUNET_DATASTORE_BLOCKTYPE_SKBLOCK) ) )
1554 GNUNET_SCHEDULER_add_continuation (sched,
1556 &forward_get_request,
1558 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1562 if (pgc->bf != NULL)
1563 GNUNET_CONTAINER_bloomfilter_free (pgc->bf);
1569 if (type == GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND)
1571 handle_on_demand_block (key, size, data, type, priority,
1572 anonymity, expiration, uid,
1573 &process_p2p_get_result,
1577 /* check for duplicates */
1578 GNUNET_CRYPTO_hash (data, size, &dhash);
1579 mingle_hash (&dhash,
1582 if ( (pgc->bf != NULL) &&
1584 GNUNET_CONTAINER_bloomfilter_test (pgc->bf,
1588 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1589 "Result from datastore filtered by bloomfilter.\n");
1591 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
1594 pgc->results_found++;
1595 if ( (pgc->type == GNUNET_DATASTORE_BLOCKTYPE_KBLOCK) ||
1596 (pgc->type == GNUNET_DATASTORE_BLOCKTYPE_SBLOCK) ||
1597 (pgc->type == GNUNET_DATASTORE_BLOCKTYPE_SKBLOCK) )
1599 if (pgc->bf == NULL)
1600 pgc->bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
1603 GNUNET_CONTAINER_bloomfilter_add (pgc->bf,
1607 reply = GNUNET_malloc (sizeof (struct PutMessage) + size);
1608 reply->header.size = htons (sizeof (struct PutMessage) + size);
1609 reply->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT);
1610 reply->type = htonl (type);
1611 reply->expiration = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining (expiration));
1612 memcpy (&reply[1], data, size);
1613 GNUNET_CORE_notify_transmit_ready (core,
1615 ACCEPTABLE_REPLY_DELAY,
1617 sizeof (struct PutMessage) + size,
1620 if ( (GNUNET_YES == test_load_too_high()) ||
1621 (pgc->results_found > 5 + 2 * pgc->priority) )
1623 GNUNET_DATASTORE_get_next (dsh, GNUNET_NO);
1624 pgc->policy &= ~ ROUTING_POLICY_FORWARD;
1627 GNUNET_DATASTORE_get_next (dsh, GNUNET_YES);
1632 * We're processing a GET request from
1633 * another peer. Give it to our local
1636 * @param cls our "struct ProcessGetContext"
1637 * @param ok did we get a datastore slice or not?
1640 ds_get_request (void *cls,
1643 struct ProcessGetContext *pgc = cls;
1645 struct GNUNET_TIME_Relative timeout;
1647 if (GNUNET_OK != ok)
1649 /* no point in doing P2P stuff if we can't even do local */
1654 if (type == GNUNET_DATASTORE_BLOCKTYPE_DBLOCK)
1655 type = GNUNET_DATASTORE_BLOCKTYPE_ANY; /* to get on-demand as well */
1656 timeout = GNUNET_TIME_relative_multiply (BASIC_DATASTORE_REQUEST_DELAY,
1657 (pgc->priority + 1));
1658 GNUNET_DATASTORE_get (dsh,
1661 &process_p2p_get_result,
1668 * The priority level imposes a bound on the maximum
1669 * value for the ttl that can be requested.
1671 * @param ttl_in requested ttl
1672 * @param priority given priority
1673 * @return ttl_in if ttl_in is below the limit,
1674 * otherwise the ttl-limit for the given priority
1677 bound_ttl (int32_t ttl_in, uint32_t prio)
1679 unsigned long long allowed;
1683 allowed = ((unsigned long long) prio) * TTL_DECREMENT / 1000;
1684 if (ttl_in > allowed)
1686 if (allowed >= (1 << 30))
1695 * We've received a request with the specified
1696 * priority. Bound it according to how much
1697 * we trust the given peer.
1699 * @param prio_in requested priority
1700 * @param peer the peer making the request
1701 * @return effective priority
1704 bound_priority (uint32_t prio_in,
1705 const struct GNUNET_PeerIdentity *peer)
1712 * Handle P2P "GET" request.
1714 * @param cls closure, always NULL
1715 * @param peer the other peer involved (sender or receiver, NULL
1716 * for loopback messages where we are both sender and receiver)
1717 * @param message the actual message
1718 * @return GNUNET_OK to keep the connection open,
1719 * GNUNET_SYSERR to close it (signal serious error)
1722 handle_p2p_get (void *cls,
1723 const struct GNUNET_PeerIdentity *other,
1724 const struct GNUNET_MessageHeader *message)
1727 const struct GetMessage *gm;
1729 const GNUNET_HashCode *opt;
1730 struct ProcessGetContext *pgc;
1733 uint32_t ttl_decrement;
1738 msize = ntohs(message->size);
1739 if (msize < sizeof (struct GetMessage))
1741 GNUNET_break_op (0);
1742 return GNUNET_SYSERR;
1744 gm = (const struct GetMessage*) message;
1745 bm = ntohl (gm->hash_bitmap);
1753 if (msize < sizeof (struct GetMessage) + bits * sizeof (GNUNET_HashCode))
1755 GNUNET_break_op (0);
1756 return GNUNET_SYSERR;
1758 opt = (const GNUNET_HashCode*) &gm[1];
1759 bfsize = msize - sizeof (struct GetMessage) + bits * sizeof (GNUNET_HashCode);
1760 pgc = GNUNET_malloc (sizeof (struct ProcessGetContext));
1762 pgc->bf = GNUNET_CONTAINER_bloomfilter_init ((const char*) &pgc[1],
1765 pgc->type = ntohl (gm->type);
1766 pgc->bm = ntohl (gm->hash_bitmap);
1767 pgc->mingle = gm->filter_mutator;
1769 if (0 != (pgc->bm & GET_MESSAGE_BIT_RETURN_TO))
1770 pgc->reply_to.hashPubKey = opt[bits++];
1772 pgc->reply_to = *other;
1773 if (0 != (pgc->bm & GET_MESSAGE_BIT_SKS_NAMESPACE))
1774 pgc->namespace = opt[bits++];
1775 else if (pgc->type == GNUNET_DATASTORE_BLOCKTYPE_SBLOCK)
1777 GNUNET_break_op (0);
1779 return GNUNET_SYSERR;
1781 if (0 != (pgc->bm & GET_MESSAGE_BIT_TRANSMIT_TO))
1782 pgc->prime_target.hashPubKey = opt[bits++];
1783 /* note that we can really only check load here since otherwise
1784 peers could find out that we are overloaded by being disconnected
1785 after sending us a malformed query... */
1786 if (GNUNET_YES == test_load_too_high ())
1788 if (NULL != pgc->bf)
1789 GNUNET_CONTAINER_bloomfilter_free (pgc->bf);
1792 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1793 "Dropping query from `%s', this peer is too busy.\n",
1794 GNUNET_h2s (other));
1798 net_load_up = 50; // FIXME
1799 net_load_down = 50; // FIXME
1800 pgc->policy = ROUTING_POLICY_NONE;
1801 if ( (net_load_up < IDLE_LOAD_THRESHOLD) &&
1802 (net_load_down < IDLE_LOAD_THRESHOLD) )
1804 pgc->policy |= ROUTING_POLICY_ALL;
1805 pgc->priority = 0; /* no charge */
1809 pgc->priority = bound_priority (ntohl (gm->priority), other);
1811 IDLE_LOAD_THRESHOLD + pgc->priority * pgc->priority) &&
1813 IDLE_LOAD_THRESHOLD + pgc->priority * pgc->priority) )
1815 pgc->policy |= ROUTING_POLICY_ALL;
1819 // FIXME: is this sound?
1820 if (net_load_up < 90 + 10 * pgc->priority)
1821 pgc->policy |= ROUTING_POLICY_FORWARD;
1822 if (net_load_down < 90 + 10 * pgc->priority)
1823 pgc->policy |= ROUTING_POLICY_ANSWER;
1826 if (pgc->policy == ROUTING_POLICY_NONE)
1829 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1830 "Dropping query from `%s', network saturated.\n",
1831 GNUNET_h2s (other));
1833 if (NULL != pgc->bf)
1834 GNUNET_CONTAINER_bloomfilter_free (pgc->bf);
1836 return GNUNET_OK; /* drop */
1838 if ((pgc->policy & ROUTING_POLICY_INDIRECT) != ROUTING_POLICY_INDIRECT)
1839 pgc->priority = 0; /* kill the priority (we cannot benefit) */
1840 pgc->ttl = bound_ttl (ntohl (gm->ttl), pgc->priority);
1841 /* decrement ttl (always) */
1842 ttl_decrement = 2 * TTL_DECREMENT +
1843 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1845 if ( (pgc->ttl < 0) &&
1846 (pgc->ttl - ttl_decrement > 0) )
1849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1850 "Dropping query from `%s' due to TTL underflow.\n",
1851 GNUNET_h2s (other));
1853 /* integer underflow => drop (should be very rare)! */
1854 if (NULL != pgc->bf)
1855 GNUNET_CONTAINER_bloomfilter_free (pgc->bf);
1859 pgc->ttl -= ttl_decrement;
1860 pgc->start_time = GNUNET_TIME_absolute_get ();
1861 preference = (double) pgc->priority;
1862 if (preference < QUERY_BANDWIDTH_VALUE)
1863 preference = QUERY_BANDWIDTH_VALUE;
1864 // FIXME: also reserve bandwidth for reply?
1865 GNUNET_CORE_peer_configure (core,
1867 GNUNET_TIME_UNIT_FOREVER_REL,
1868 0, 0, preference, NULL, NULL);
1869 if (0 != (pgc->policy & ROUTING_POLICY_ANSWER))
1870 pgc->drq = queue_ds_request (BASIC_DATASTORE_REQUEST_DELAY,
1874 GNUNET_SCHEDULER_add_continuation (sched,
1876 &forward_get_request,
1878 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1884 * Iterator over pending requests.
1886 * @param cls response (struct ProcessReplyClosure)
1887 * @param key our query
1888 * @param value value in the hash map (meta-info about the query)
1889 * @return GNUNET_YES (we should continue to iterate)
1892 process_reply (void *cls,
1893 const GNUNET_HashCode * key,
1896 struct ProcessReplyClosure *prq = cls;
1897 struct PendingRequest *pr = value;
1899 fprintf (stderr, "FIXME %p %p\n", prq, pr);
1900 // FIXME: forward reply to client
1901 // or other peers (depending on pr...)
1907 * Handle P2P "PUT" request.
1909 * @param cls closure, always NULL
1910 * @param peer the other peer involved (sender or receiver, NULL
1911 * for loopback messages where we are both sender and receiver)
1912 * @param message the actual message
1913 * @return GNUNET_OK to keep the connection open,
1914 * GNUNET_SYSERR to close it (signal serious error)
1917 handle_p2p_put (void *cls,
1918 const struct GNUNET_PeerIdentity *other,
1919 const struct GNUNET_MessageHeader *message)
1921 const struct PutMessage *put;
1925 struct GNUNET_TIME_Absolute expiration;
1926 GNUNET_HashCode query;
1927 const struct KBlock *kb;
1928 struct ProcessReplyClosure prq;
1930 msize = ntohs (message->size);
1931 if (msize < sizeof (struct PutMessage))
1934 return GNUNET_SYSERR;
1936 put = (const struct PutMessage*) message;
1937 dsize = msize - sizeof (struct PutMessage);
1938 type = ntohl (put->type);
1939 expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_ntoh (put->expiration));
1941 /* first, validate! */
1944 case GNUNET_DATASTORE_BLOCKTYPE_DBLOCK:
1945 case GNUNET_DATASTORE_BLOCKTYPE_IBLOCK:
1946 GNUNET_CRYPTO_hash (&put[1], dsize, &query);
1948 case GNUNET_DATASTORE_BLOCKTYPE_KBLOCK:
1949 if (dsize < sizeof (struct KBlock))
1951 GNUNET_break_op (0);
1952 return GNUNET_SYSERR;
1954 kb = (const struct KBlock*) &put[1];
1955 // FIXME -- validation code below broken...
1956 if ( (dsize != ntohs (kb->purpose.size) + 42) ||
1958 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK,
1963 GNUNET_break_op (0);
1964 return GNUNET_SYSERR;
1966 GNUNET_CRYPTO_hash (&kb->keyspace,
1967 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1970 case GNUNET_DATASTORE_BLOCKTYPE_SBLOCK:
1971 // FIXME -- validate SBLOCK!
1974 case GNUNET_DATASTORE_BLOCKTYPE_SKBLOCK:
1975 // FIXME -- validate SKBLOCK!
1979 /* unknown block type */
1980 GNUNET_break_op (0);
1981 return GNUNET_SYSERR;
1984 /* now, lookup 'query' */
1985 prq.data = (const void*) &put[1];
1988 prq.expiration = expiration;
1990 GNUNET_CONTAINER_multihashmap_get_multiple (request_map,
1994 // FIXME: if migration is on and load is low,
1995 // queue to store data in datastore;
1996 // use "prq.priority" for that!
2002 * List of handlers for P2P messages
2003 * that we care about.
2005 static struct GNUNET_CORE_MessageHandler p2p_handlers[] =
2008 GNUNET_MESSAGE_TYPE_FS_GET, 0 },
2010 GNUNET_MESSAGE_TYPE_FS_PUT, 0 },
2016 * Task that will try to initiate a connection with the
2023 core_connect_task (void *cls,
2024 const struct GNUNET_SCHEDULER_TaskContext *tc);
2028 * Function called by the core after we've
2032 core_start_cb (void *cls,
2033 struct GNUNET_CORE_Handle * server,
2034 const struct GNUNET_PeerIdentity *
2037 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
2042 GNUNET_SCHEDULER_add_delayed (sched,
2044 GNUNET_SCHEDULER_PRIORITY_HIGH,
2045 GNUNET_SCHEDULER_NO_TASK,
2046 GNUNET_TIME_UNIT_SECONDS,
2056 * Task that will try to initiate a connection with the
2063 core_connect_task (void *cls,
2064 const struct GNUNET_SCHEDULER_TaskContext *tc)
2066 GNUNET_CORE_connect (sched,
2068 GNUNET_TIME_UNIT_FOREVER_REL,
2072 &peer_disconnect_handler,
2081 * Process fs requests.
2083 * @param cls closure
2084 * @param sched scheduler to use
2085 * @param server the initialized server
2086 * @param cfg configuration to use
2090 struct GNUNET_SCHEDULER_Handle *s,
2091 struct GNUNET_SERVER_Handle *server,
2092 const struct GNUNET_CONFIGURATION_Handle *c)
2097 ifm = GNUNET_CONTAINER_multihashmap_create (128);
2098 request_map = GNUNET_CONTAINER_multihashmap_create (128); // FIXME: get size from config
2100 dsh = GNUNET_DATASTORE_connect (cfg,
2104 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2105 _("Failed to connect to datastore service.\n"));
2108 GNUNET_SERVER_disconnect_notify (server,
2109 &handle_client_disconnect,
2111 GNUNET_SERVER_add_handlers (server, handlers);
2112 core_connect_task (NULL, NULL);
2113 GNUNET_SCHEDULER_add_delayed (sched,
2115 GNUNET_SCHEDULER_PRIORITY_IDLE,
2116 GNUNET_SCHEDULER_NO_TASK,
2117 GNUNET_TIME_UNIT_FOREVER_REL,
2124 * The main function for the fs service.
2126 * @param argc number of arguments from the command line
2127 * @param argv command line arguments
2128 * @return 0 ok, 1 on error
2131 main (int argc, char *const *argv)
2133 return (GNUNET_OK ==
2134 GNUNET_SERVICE_run (argc,
2136 "fs", &run, NULL, NULL, NULL)) ? 0 : 1;
2139 /* end of gnunet-service-fs.c */