2 This file is part of GNUnet.
3 (C) 2009, 2010 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 dht/gnunet-service-dht.c
23 * @brief main DHT service shell, building block for DHT implementations
24 * @author Christian Grothoff
25 * @author Nathan Evans
29 #include "gnunet_client_lib.h"
30 #include "gnunet_getopt_lib.h"
31 #include "gnunet_os_lib.h"
32 #include "gnunet_protocols.h"
33 #include "gnunet_service_lib.h"
34 #include "gnunet_core_service.h"
35 #include "gnunet_signal_lib.h"
36 #include "gnunet_util_lib.h"
37 #include "gnunet_datacache_lib.h"
38 #include "gnunet_transport_service.h"
39 #include "gnunet_hello_lib.h"
43 * Handle to the datacache service (for inserting/retrieving data)
45 struct GNUNET_DATACACHE_Handle *datacache;
48 * The main scheduler to use for the DHT service
50 static struct GNUNET_SCHEDULER_Handle *sched;
53 * The configuration the DHT service is running with
55 static const struct GNUNET_CONFIGURATION_Handle *cfg;
58 * Timeout for transmissions to clients
60 static struct GNUNET_TIME_Relative client_transmit_timeout;
63 * Handle to the core service
65 static struct GNUNET_CORE_Handle *coreAPI;
68 * Handle to the transport service, for getting our hello
70 static struct GNUNET_TRANSPORT_Handle *transport_handle;
73 * The identity of our peer.
75 static struct GNUNET_PeerIdentity my_identity;
80 static struct GNUNET_MessageHeader *my_hello;
83 * Task to run when we shut down, cleaning up all our trash
85 static GNUNET_SCHEDULER_TaskIdentifier cleanup_task;
89 * Linked list of messages to send to clients.
94 * Pointer to next item in the list
96 struct PendingMessage *next;
99 * Actual message to be sent
101 struct GNUNET_MessageHeader *msg;
106 * Struct containing information about a client,
107 * handle to connect to it, and any pending messages
108 * that need to be sent to it.
113 * Linked list of active clients
115 struct ClientList *next;
118 * The handle to this client
120 struct GNUNET_SERVER_Client *client_handle;
123 * Handle to the current transmission request, NULL
126 struct GNUNET_CONNECTION_TransmitHandle *transmit_handle;
129 * Linked list of pending messages for this client
131 struct PendingMessage *pending_head;
136 * Context for handling results from a get request.
138 struct DatacacheGetContext
141 * The client to send the result to.
143 struct ClientList *client;
146 * The unique id of this request
148 unsigned long long unique_id;
152 * Context containing information about a DHT message received.
154 struct DHT_MessageContext
157 * The client this request was received from.
159 struct ClientList *client;
162 * The key this request was about
164 GNUNET_HashCode *key;
167 * The unique identifier of this request
169 unsigned long long unique_id;
172 * Desired replication level
177 * Any message options for this request
183 * List of active clients.
185 static struct ClientList *client_list;
189 * Server handlers for handling locally received dht requests
192 handle_dht_start_message (void *cls, struct GNUNET_SERVER_Client *client,
193 const struct GNUNET_MessageHeader *message);
196 handle_dht_stop_message (void *cls, struct GNUNET_SERVER_Client *client,
197 const struct GNUNET_MessageHeader *message);
199 static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = {
200 {&handle_dht_start_message, NULL, GNUNET_MESSAGE_TYPE_DHT, 0},
201 {&handle_dht_stop_message, NULL, GNUNET_MESSAGE_TYPE_DHT_STOP, 0},
207 * Core handler for p2p dht get requests.
209 static int handle_dht_p2p_get (void *cls,
210 const struct GNUNET_PeerIdentity *peer,
211 const struct GNUNET_MessageHeader *message,
212 struct GNUNET_TIME_Relative latency,
216 * Core handler for p2p dht put requests.
218 static int handle_dht_p2p_put (void *cls,
219 const struct GNUNET_PeerIdentity *peer,
220 const struct GNUNET_MessageHeader *message,
221 struct GNUNET_TIME_Relative latency,
225 * Core handler for p2p dht find peer requests.
227 static int handle_dht_p2p_find_peer (void *cls,
228 const struct GNUNET_PeerIdentity *peer,
229 const struct GNUNET_MessageHeader
231 struct GNUNET_TIME_Relative latency,
234 static struct GNUNET_CORE_MessageHandler core_handlers[] = {
235 {&handle_dht_p2p_get, GNUNET_MESSAGE_TYPE_DHT_GET, 0},
236 {&handle_dht_p2p_put, GNUNET_MESSAGE_TYPE_DHT_PUT, 0},
237 {&handle_dht_p2p_find_peer, GNUNET_MESSAGE_TYPE_DHT_FIND_PEER, 0},
242 * Forward declaration.
244 static size_t send_generic_reply (void *cls, size_t size, void *buf);
247 * Task run to check for messages that need to be sent to a client.
249 * @param cls a ClientList, containing the client and any messages to be sent to it
250 * @param tc reason this was called
253 process_pending_messages (void *cls,
254 const struct GNUNET_SCHEDULER_TaskContext *tc)
256 struct ClientList *client = cls;
258 if (client->pending_head == NULL) /* No messages queued */
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
262 "`%s': Have no pending messages for client.\n", "DHT");
267 if (client->transmit_handle == NULL) /* No current pending messages, we can try to send! */
268 client->transmit_handle =
269 GNUNET_SERVER_notify_transmit_ready (client->client_handle,
270 ntohs (client->pending_head->msg->
272 GNUNET_TIME_relative_multiply
273 (GNUNET_TIME_UNIT_SECONDS, 5),
274 &send_generic_reply, client);
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
279 "`%s': Transmit handle is non-null.\n", "DHT");
285 * Callback called as a result of issuing a GNUNET_SERVER_notify_transmit_ready
286 * request. A ClientList is passed as closure, take the head of the list
287 * and copy it into buf, which has the result of sending the message to the
290 * @param cls closure to this call
291 * @param size maximum number of bytes available to send
292 * @param buf where to copy the actual message to
294 * @return the number of bytes actually copied, 0 indicates failure
297 send_generic_reply (void *cls, size_t size, void *buf)
299 struct ClientList *client = cls;
300 struct PendingMessage *reply = client->pending_head;
303 client->transmit_handle = NULL;
304 if (buf == NULL) /* Message timed out, that's crappy... */
307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s': buffer was NULL\n", "DHT");
309 client->pending_head = reply->next;
310 GNUNET_free (reply->msg);
315 if (size >= ntohs (reply->msg->size))
318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
319 "`%s': Copying reply to buffer, REALLY SENT\n", "DHT");
321 memcpy (buf, reply->msg, ntohs (reply->msg->size));
323 ret = ntohs (reply->msg->size);
328 client->pending_head = reply->next;
329 GNUNET_free (reply->msg);
332 GNUNET_SCHEDULER_add_now (sched, &process_pending_messages, client);
337 * Add a PendingMessage to the clients list of messages to be sent
339 * @param client the active client to send the message to
340 * @param pending_message the actual message to send
343 add_pending_message (struct ClientList *client,
344 struct PendingMessage *pending_message)
346 struct PendingMessage *pos;
347 struct PendingMessage *prev;
349 pos = client->pending_head;
352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
353 "`%s': Adding pending message for client.\n", "DHT");
358 client->pending_head = pending_message;
360 else /* This means another request is already queued, rely on send_reply to process all pending messages */
362 while (pos != NULL) /* Find end of list */
368 GNUNET_assert (prev != NULL);
369 prev->next = pending_message;
372 GNUNET_SCHEDULER_add_now (sched, &process_pending_messages, client);
377 * Called when a reply needs to be sent to a client, either as
378 * a result it found to a GET or FIND PEER request.
380 * @param client the client to send the reply to
381 * @param message the encapsulated message to send
382 * @param uid the unique identifier of this request
385 send_reply_to_client (struct ClientList *client,
386 struct GNUNET_MessageHeader *message,
387 unsigned long long uid)
389 struct GNUNET_DHT_Message *reply;
390 struct PendingMessage *pending_message;
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
396 "`%s': Sending reply to client.\n", "DHT");
398 msize = ntohs (message->size);
399 tsize = sizeof (struct GNUNET_DHT_Message) + msize;
400 reply = GNUNET_malloc (tsize);
401 reply->header.type = htons (GNUNET_MESSAGE_TYPE_DHT);
402 reply->header.size = htons (tsize);
404 reply->unique = htons (GNUNET_YES);
405 reply->unique_id = GNUNET_htonll (uid);
406 memcpy (&reply[1], message, msize);
408 pending_message = GNUNET_malloc (sizeof (struct PendingMessage));
409 pending_message->msg = &reply->header;
411 add_pending_message (client, pending_message);
416 * Iterator for local get request results,
418 * @param cls closure for iterator, a DatacacheGetContext
419 * @param exp when does this value expire?
420 * @param key the key this data is stored under
421 * @param size the size of the data identified by key
422 * @param data the actual data
423 * @param type the type of the data
425 * @return GNUNET_OK to continue iteration, anything else
429 datacache_get_iterator (void *cls,
430 struct GNUNET_TIME_Absolute exp,
431 const GNUNET_HashCode * key,
432 uint32_t size, const char *data, uint32_t type)
434 struct DatacacheGetContext *datacache_get_ctx = cls;
435 struct GNUNET_DHT_GetResultMessage *get_result;
437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
438 "`%s': Received `%s' response from datacache\n", "DHT", "GET");
441 GNUNET_malloc (sizeof (struct GNUNET_DHT_GetResultMessage) + size);
442 get_result->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_GET_RESULT);
443 get_result->header.size =
444 htons (sizeof (struct GNUNET_DHT_GetResultMessage) + size);
445 get_result->data_size = htons (size);
446 get_result->expiration = exp;
447 memcpy (&get_result->key, key, sizeof (GNUNET_HashCode));
448 get_result->type = htons (type);
449 memcpy (&get_result[1], data, size);
451 send_reply_to_client (datacache_get_ctx->client, &get_result->header,
452 datacache_get_ctx->unique_id);
454 GNUNET_free (get_result);
459 * Server handler for initiating local dht get requests
461 * @param cls closure for service
462 * @param get_msg the actual get message
463 * @param message_context struct containing pertinent information about the get request
467 handle_dht_get (void *cls, struct GNUNET_DHT_GetMessage *get_msg,
468 struct DHT_MessageContext *message_context)
471 GNUNET_HashCode get_key;
474 unsigned int results;
475 struct DatacacheGetContext *datacache_get_context;
477 GNUNET_assert (ntohs (get_msg->header.size) >=
478 sizeof (struct GNUNET_DHT_GetMessage));
479 get_type = ntohs (get_msg->type);
482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
483 "`%s': Received `%s' request from client, message type %d, key %s, uid %llu\n",
484 "DHT", "GET", get_type, GNUNET_h2s (&get_key),
485 message_context->unique_id);
488 datacache_get_context = GNUNET_malloc (sizeof (struct DatacacheGetContext));
489 datacache_get_context->client = message_context->client;
490 datacache_get_context->unique_id = message_context->unique_id;
493 if (datacache != NULL)
495 GNUNET_DATACACHE_get (datacache, message_context->key, get_type,
496 &datacache_get_iterator, datacache_get_context);
499 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
500 "`%s': Found %d results for local `%s' request\n", "DHT",
503 GNUNET_free (datacache_get_context);
504 /* FIXME: Implement get functionality here */
509 * Server handler for initiating local dht find peer requests
511 * @param cls closure for service
512 * @param find_msg the actual find peer message
513 * @param message_context struct containing pertinent information about the request
517 handle_dht_find_peer (void *cls, struct GNUNET_DHT_FindPeerMessage *find_msg,
518 struct DHT_MessageContext *message_context)
520 struct GNUNET_DHT_FindPeerResultMessage *find_peer_result;
524 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
525 "`%s': Received `%s' request from client, key %s (msg size %d, we expected %d)\n",
526 "DHT", "FIND PEER", GNUNET_h2s (message_context->key),
527 ntohs (find_msg->header.size),
528 sizeof (struct GNUNET_DHT_FindPeerMessage));
531 GNUNET_assert (ntohs (find_msg->header.size) >=
532 sizeof (struct GNUNET_DHT_FindPeerMessage));
534 if (my_hello == NULL)
537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
538 "`%s': Our HELLO is null, can't return.\n",
545 /* Simplistic find_peer functionality, always return our hello */
546 hello_size = ntohs(my_hello->size);
547 tsize = hello_size + sizeof (struct GNUNET_DHT_FindPeerResultMessage);
548 find_peer_result = GNUNET_malloc (tsize);
549 find_peer_result->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT);
550 find_peer_result->header.size = htons (tsize);
551 find_peer_result->data_size = htons (hello_size);
552 memcpy(&find_peer_result->peer, &my_identity, sizeof(struct GNUNET_PeerIdentity));
553 memcpy (&find_peer_result[1], &my_hello, hello_size);
555 send_reply_to_client(message_context->client, &find_peer_result->header, message_context->unique_id);
557 /* FIXME: Implement find peer functionality here */
562 * Server handler for initiating local dht put requests
564 * @param cls closure for service
565 * @param put_msg the actual put message
566 * @param message_context struct containing pertinent information about the request
569 handle_dht_put (void *cls, struct GNUNET_DHT_PutMessage *put_msg,
570 struct DHT_MessageContext *message_context)
575 GNUNET_assert (ntohs (put_msg->header.size) >=
576 sizeof (struct GNUNET_DHT_PutMessage));
578 put_type = ntohs (put_msg->type);
579 data_size = ntohs (put_msg->data_size);
581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
582 "`%s': %s msg total size is %d, data size %d, struct size %d\n",
583 "DHT", "PUT", ntohs (put_msg->header.size), data_size,
584 sizeof (struct GNUNET_DHT_PutMessage));
586 GNUNET_assert (ntohs (put_msg->header.size) ==
587 sizeof (struct GNUNET_DHT_PutMessage) + data_size);
590 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
591 "`%s': Received `%s' request from client, message type %d, key %s\n",
592 "DHT", "PUT", put_type, GNUNET_h2s (message_context->key));
596 * Simplest DHT functionality, store any message we receive a put request for.
598 if (datacache != NULL)
599 GNUNET_DATACACHE_put (datacache, message_context->key, data_size,
600 (char *) &put_msg[1], put_type,
601 put_msg->expiration);
603 * FIXME: Implement dht put request functionality here!
610 * Find a client if it exists, add it otherwise.
612 * @param client the server handle to the client
614 * @return the client if found, a new client otherwise
616 static struct ClientList *
617 find_active_client (struct GNUNET_SERVER_Client *client)
619 struct ClientList *pos = client_list;
620 struct ClientList *ret;
624 if (pos->client_handle == client)
629 ret = GNUNET_malloc (sizeof (struct ClientList));
630 ret->client_handle = client;
631 ret->next = client_list;
633 ret->pending_head = NULL;
639 * Construct a message receipt confirmation for a particular uid.
640 * Receipt confirmations are used for any requests that don't expect
641 * a reply otherwise (i.e. put requests, stop requests).
643 * @param client the handle for the client
644 * @param uid the unique identifier of this message
647 send_client_receipt_confirmation (struct GNUNET_SERVER_Client *client,
650 struct GNUNET_DHT_StopMessage *confirm_message;
651 struct ClientList *active_client;
652 struct PendingMessage *pending_message;
655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
656 "`%s': Sending receipt confirmation for uid %llu\n", "DHT",
659 confirm_message = GNUNET_malloc (sizeof (struct GNUNET_DHT_StopMessage));
660 confirm_message->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_STOP);
661 confirm_message->header.size =
662 htons (sizeof (struct GNUNET_DHT_StopMessage));
663 confirm_message->unique_id = GNUNET_htonll (uid);
665 active_client = find_active_client (client);
666 pending_message = GNUNET_malloc (sizeof (struct PendingMessage));
667 pending_message->msg = &confirm_message->header;
669 add_pending_message (active_client, pending_message);
674 * Handler for any generic DHT messages, calls the appropriate handler
675 * depending on message type, sends confirmation if responses aren't otherwise
678 * @param cls closure for the service
679 * @param client the client we received this message from
680 * @param message the actual message received
683 handle_dht_start_message (void *cls, struct GNUNET_SERVER_Client *client,
684 const struct GNUNET_MessageHeader *message)
686 struct GNUNET_DHT_Message *dht_msg = (struct GNUNET_DHT_Message *) message;
687 struct GNUNET_MessageHeader *enc_msg;
688 struct DHT_MessageContext *message_context;
692 enc_msg = (struct GNUNET_MessageHeader *) &dht_msg[1];
693 enc_type = ntohs (enc_msg->type);
697 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
698 "`%s': Received `%s' request from client, message type %d, key %s, uid %llu\n",
699 "DHT", "GENERIC", enc_type, GNUNET_h2s (&dht_msg->key),
700 GNUNET_ntohll (dht_msg->unique_id));
703 message_context = GNUNET_malloc (sizeof (struct DHT_MessageContext));
704 message_context->client = find_active_client (client);
705 message_context->key = &dht_msg->key;
706 message_context->unique_id = GNUNET_ntohll (dht_msg->unique_id);
707 message_context->replication = ntohs (dht_msg->desired_replication_level);
708 message_context->msg_options = ntohs (dht_msg->options);
712 case GNUNET_MESSAGE_TYPE_DHT_GET:
713 handle_dht_get (cls, (struct GNUNET_DHT_GetMessage *) enc_msg,
716 case GNUNET_MESSAGE_TYPE_DHT_PUT:
717 handle_dht_put (cls, (struct GNUNET_DHT_PutMessage *) enc_msg,
719 send_client_receipt_confirmation (client,
720 GNUNET_ntohll (dht_msg->unique_id));
722 case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER:
723 handle_dht_find_peer (cls,
724 (struct GNUNET_DHT_FindPeerMessage *) enc_msg,
728 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
729 "`%s': Message type (%d) not handled\n", "DHT", enc_type);
732 GNUNET_free (message_context);
733 GNUNET_SERVER_receive_done (client, GNUNET_OK);
738 * Handler for any generic DHT stop messages, calls the appropriate handler
739 * depending on message type, sends confirmation by default (stop messages
740 * do not otherwise expect replies)
742 * @param cls closure for the service
743 * @param client the client we received this message from
744 * @param message the actual message received
746 * TODO: add demultiplexing for stop message types.
749 handle_dht_stop_message (void *cls, struct GNUNET_SERVER_Client *client,
750 const struct GNUNET_MessageHeader *message)
752 struct GNUNET_DHT_StopMessage *dht_stop_msg =
753 (struct GNUNET_DHT_StopMessage *) message;
756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
757 "`%s': Received `%s' request from client, uid %llu\n", "DHT",
758 "GENERIC STOP", GNUNET_ntohll (dht_stop_msg->unique_id));
761 /* TODO: Put in demultiplexing here */
763 send_client_receipt_confirmation (client,
764 GNUNET_ntohll (dht_stop_msg->unique_id));
765 GNUNET_SERVER_receive_done (client, GNUNET_OK);
770 * Core handler for p2p dht get requests.
773 handle_dht_p2p_get (void *cls,
774 const struct GNUNET_PeerIdentity *peer,
775 const struct GNUNET_MessageHeader *message,
776 struct GNUNET_TIME_Relative latency, uint32_t distance)
779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
780 "`%s': Received `%s' request from another peer\n", "DHT",
788 * Core handler for p2p dht put requests.
791 handle_dht_p2p_put (void *cls,
792 const struct GNUNET_PeerIdentity *peer,
793 const struct GNUNET_MessageHeader *message,
794 struct GNUNET_TIME_Relative latency, uint32_t distance)
797 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
798 "`%s': Received `%s' request from another peer\n", "DHT",
806 * Core handler for p2p dht find peer requests.
809 handle_dht_p2p_find_peer (void *cls,
810 const struct GNUNET_PeerIdentity *peer,
811 const struct GNUNET_MessageHeader *message,
812 struct GNUNET_TIME_Relative latency,
816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
817 "`%s': Received `%s' request from another peer\n", "DHT",
826 * Receive the HELLO from transport service,
827 * free current and replace if necessary.
830 * @param message HELLO message of peer
833 process_hello (void *cls, const struct GNUNET_MessageHeader *message)
836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
837 "Received our `%s' from transport service\n",
841 GNUNET_assert (message != NULL);
842 GNUNET_free_non_null(my_hello);
843 my_hello = GNUNET_malloc(ntohs(message->size));
844 memcpy(my_hello, message, ntohs(message->size));
848 * Task run during shutdown.
854 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
856 if (transport_handle != NULL)
858 GNUNET_free_non_null(my_hello);
859 GNUNET_TRANSPORT_get_hello_cancel(transport_handle, &process_hello, NULL);
860 GNUNET_TRANSPORT_disconnect(transport_handle);
862 GNUNET_CORE_disconnect (coreAPI);
867 * To be called on core init/fail.
869 * @param cls service closure
870 * @param server handle to the server for this service
871 * @param identity the public identity of this peer
872 * @param publicKey the public key of this peer
875 core_init (void *cls,
876 struct GNUNET_CORE_Handle *server,
877 const struct GNUNET_PeerIdentity *identity,
878 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
883 GNUNET_SCHEDULER_cancel (sched, cleanup_task);
884 GNUNET_SCHEDULER_add_now (sched, &shutdown_task, NULL);
888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
889 "%s: Core connection initialized, I am peer: %s\n", "dht",
890 GNUNET_i2s (identity));
892 /* Copy our identity so we can use it */
893 memcpy (&my_identity, identity, sizeof (struct GNUNET_PeerIdentity));
894 /* Set the server to local variable */
900 * Process dht requests.
903 * @param scheduler scheduler to use
904 * @param server the initialized server
905 * @param c configuration to use
909 struct GNUNET_SCHEDULER_Handle *scheduler,
910 struct GNUNET_SERVER_Handle *server,
911 const struct GNUNET_CONFIGURATION_Handle *c)
916 datacache = GNUNET_DATACACHE_create (sched, cfg, "dhtcache");
918 client_transmit_timeout =
919 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5);
920 GNUNET_SERVER_add_handlers (server, plugin_handlers);
922 coreAPI = GNUNET_CORE_connect (sched, /* Main scheduler */
923 cfg, /* Main configuration */
924 client_transmit_timeout, /* Delay for connecting */
925 NULL, /* FIXME: anything we want to pass around? */
926 &core_init, /* Call core_init once connected */
927 NULL, /* Don't care about pre-connects */
928 NULL, /* Don't care about connects */
929 NULL, /* Don't care about disconnects */
930 NULL, /* Don't want notified about all incoming messages */
931 GNUNET_NO, /* For header only inbound notification */
932 NULL, /* Don't want notified about all outbound messages */
933 GNUNET_NO, /* For header only outbound notification */
934 core_handlers); /* Register these handlers */
936 transport_handle = GNUNET_TRANSPORT_connect(sched, cfg, NULL, NULL, NULL, NULL);
938 if (transport_handle != NULL)
939 GNUNET_TRANSPORT_get_hello (transport_handle, &process_hello, NULL);
941 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to connect to transport service!\n");
947 /* Scheduled the task to clean up when shutdown is called */
948 cleanup_task = GNUNET_SCHEDULER_add_delayed (sched,
949 GNUNET_TIME_UNIT_FOREVER_REL,
950 &shutdown_task, NULL);
955 * The main function for the dht service.
957 * @param argc number of arguments from the command line
958 * @param argv command line arguments
959 * @return 0 ok, 1 on error
962 main (int argc, char *const *argv)
965 GNUNET_SERVICE_run (argc,
968 GNUNET_SERVICE_OPTION_NONE,
969 &run, NULL)) ? 0 : 1;