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 dv/gnunet-service-dv.c
23 * @brief the distance vector service, primarily handles gossip of nearby
24 * peers and sending/receiving DV messages from core and decapsulating
27 * @author Christian Grothoff
28 * @author Nathan Evans
30 * TODO: The gossip rates need to be worked out. Probably many other things
35 #include "gnunet_client_lib.h"
36 #include "gnunet_getopt_lib.h"
37 #include "gnunet_os_lib.h"
38 #include "gnunet_protocols.h"
39 #include "gnunet_service_lib.h"
40 #include "gnunet_core_service.h"
41 #include "gnunet_signal_lib.h"
42 #include "gnunet_util_lib.h"
43 #include "gnunet_hello_lib.h"
44 #include "gnunet_peerinfo_service.h"
45 #include "gnunet_crypto_lib.h"
49 * For testing mostly, remember only the
50 * shortest path to a distant neighbor.
52 #define AT_MOST_ONE GNUNET_NO
54 #define USE_PEER_ID GNUNET_YES
57 * How often do we check about sending out more peer information (if
58 * we are connected to no peers previously).
60 #define GNUNET_DV_DEFAULT_SEND_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500000)
63 * How long do we wait at most between sending out information?
65 #define GNUNET_DV_MAX_SEND_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500000)
68 * How long can we have not heard from a peer and
69 * still have it in our tables?
71 #define GNUNET_DV_PEER_EXPIRATION_TIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1000))
74 * Priority for gossip.
76 #define GNUNET_DV_DHT_GOSSIP_PRIORITY (GNUNET_EXTREME_PRIORITY / 10)
79 * How often should we check if expiration time has elapsed for
82 #define GNUNET_DV_MAINTAIN_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5))
85 * How long to allow a message to be delayed?
87 #define DV_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5))
90 * Priority to use for DV data messages.
95 * The cost to a direct neighbor. We used to use 0, but 1 makes more sense.
97 #define DIRECT_NEIGHBOR_COST 1
100 * The default number of direct connections to store in DV (max)
102 #define DEFAULT_DIRECT_CONNECTIONS 50
105 * The default size of direct + extended peers in DV (max)
107 #define DEFAULT_DV_SIZE 100
110 * The default fisheye depth, from how many hops away will
113 #define DEFAULT_FISHEYE_DEPTH 4
116 * Linked list of messages to send to clients.
118 struct PendingMessage
121 * Pointer to next item in the list
123 struct PendingMessage *next;
126 * Pointer to previous item in the list
128 struct PendingMessage *prev;
131 * The PeerIdentity to send to
133 struct GNUNET_PeerIdentity recipient;
136 * The result of message sending.
138 struct GNUNET_DV_SendResultMessage *send_result;
141 * Message importance level.
143 unsigned int importance;
148 unsigned int msg_size;
151 * How long to wait before sending message.
153 struct GNUNET_TIME_Relative timeout;
156 * Actual message to be sent; // avoid allocation
158 const struct GNUNET_MessageHeader *msg; // msg = (cast) &pm[1]; // memcpy (&pm[1], data, len);
162 struct FastGossipNeighborList
165 * Next element of DLL
167 struct FastGossipNeighborList *next;
170 * Prev element of DLL
172 struct FastGossipNeighborList *prev;
175 * The neighbor to gossip about
177 struct DistantNeighbor *about;
181 * Context created whenever a direct peer connects to us,
182 * used to gossip other peers to it.
184 struct NeighborSendContext
187 * The peer we will gossip to.
189 struct DirectNeighbor *toNeighbor;
192 * The task associated with this context.
194 GNUNET_SCHEDULER_TaskIdentifier task;
197 * Head of DLL of peers to gossip about
198 * as fast as possible to this peer, for initial
201 struct FastGossipNeighborList *fast_gossip_list_head;
204 * Tail of DLL of peers to gossip about
205 * as fast as possible to this peer, for initial
208 struct FastGossipNeighborList *fast_gossip_list_tail;
214 * Struct to hold information for updating existing neighbors
216 struct NeighborUpdateInfo
224 * The existing neighbor
226 struct DistantNeighbor *neighbor;
229 * The referrer of the possibly existing peer
231 struct DirectNeighbor *referrer;
234 * The time we heard about this peer
236 struct GNUNET_TIME_Absolute now;
239 * Peer id this peer uses to refer to neighbor.
241 unsigned int referrer_peer_id;
246 * Struct where actual neighbor information is stored,
247 * referenced by min_heap and max_heap. Freeing dealt
248 * with when items removed from hashmap.
250 struct DirectNeighbor
253 * Identity of neighbor.
255 struct GNUNET_PeerIdentity identity;
258 * PublicKey of neighbor.
260 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
263 * Head of DLL of nodes that this direct neighbor referred to us.
265 struct DistantNeighbor *referee_head;
268 * Tail of DLL of nodes that this direct neighbor referred to us.
270 struct DistantNeighbor *referee_tail;
273 * The sending context for gossiping peers to this neighbor.
275 struct NeighborSendContext *send_context;
278 * Is this one of the direct neighbors that we are "hiding"
286 * Struct where actual neighbor information is stored,
287 * referenced by min_heap and max_heap. Freeing dealt
288 * with when items removed from hashmap.
290 struct DistantNeighbor
293 * We keep distant neighbor's of the same referrer in a DLL.
295 struct DistantNeighbor *next;
298 * We keep distant neighbor's of the same referrer in a DLL.
300 struct DistantNeighbor *prev;
305 struct GNUNET_CONTAINER_HeapNode *min_loc;
310 struct GNUNET_CONTAINER_HeapNode *max_loc;
313 * Identity of referrer (next hop towards 'neighbor').
315 struct DirectNeighbor *referrer;
318 * Identity of neighbor.
320 struct GNUNET_PeerIdentity identity;
323 * PublicKey of neighbor.
325 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey;
328 * Last time we received routing information from this peer
330 struct GNUNET_TIME_Absolute last_activity;
333 * Cost to neighbor, used for actual distance vector computations
338 * Random identifier *we* use for this peer, to be used as shortcut
339 * instead of sending full peer id for each message
344 * Random identifier the *referrer* uses for this peer.
346 unsigned int referrer_id;
349 * Is this one of the direct neighbors that we are "hiding"
356 struct PeerIteratorContext
359 * The actual context, to be freed later.
361 struct GNUNET_PEERINFO_IteratorContext *ic;
364 * The neighbor about which we are concerned.
366 struct DirectNeighbor *neighbor;
369 * The distant neighbor entry for this direct neighbor.
371 struct DistantNeighbor *distant;
376 * Context used for creating hello messages when
377 * gossips are received.
382 * Identity of distant neighbor.
384 struct GNUNET_PeerIdentity distant_peer;
387 * Identity of direct neighbor, via which we send this message.
389 const struct GNUNET_PeerIdentity *direct_peer;
392 * How many addresses do we need to add (always starts at 1, then set to 0)
394 int addresses_to_add;
398 struct DV_SendContext
401 * The distant peer (should always match)
403 struct GNUNET_PeerIdentity *distant_peer;
406 * The direct peer, we need to verify the referrer of.
408 struct GNUNET_PeerIdentity *direct_peer;
411 * The message to be sent
413 struct GNUNET_MessageHeader *message;
416 * The pre-built send result message. Simply needs to be queued
417 * and freed once send has been called!
419 struct GNUNET_DV_SendResultMessage *send_result;
422 * The size of the message being sent, may be larger
423 * than message->header.size because it's multiple
424 * messages packed into one!
429 * How important is this message?
431 unsigned int importance;
434 * Timeout for this message
436 struct GNUNET_TIME_Relative timeout;
439 * Unique ID for DV message
444 struct FindDestinationContext
447 struct DistantNeighbor *dest;
453 struct GNUNET_PeerIdentity *dest;
454 const struct GNUNET_PeerIdentity *via;
457 struct DisconnectContext
460 * Distant neighbor to get pid from.
462 struct DistantNeighbor *distant;
465 * Direct neighbor that disconnected.
467 struct DirectNeighbor *direct;
470 struct TokenizedMessageContext
473 * Immediate sender of this message
475 const struct GNUNET_PeerIdentity *peer;
478 * Distant sender of the message
480 struct DistantNeighbor *distant;
483 * Uid for this set of messages
489 * Context for finding the least cost peer to send to.
490 * Transport selection can only go so far.
492 struct FindLeastCostContext
494 struct DistantNeighbor *target;
495 unsigned int least_cost;
499 * Handle to the core service api.
501 static struct GNUNET_CORE_Handle *coreAPI;
504 * Stream tokenizer to handle messages coming in from core.
506 static struct GNUNET_SERVER_MessageStreamTokenizer *coreMST;
509 * The identity of our peer.
511 static struct GNUNET_PeerIdentity my_identity;
514 * The configuration for this service.
516 static const struct GNUNET_CONFIGURATION_Handle *cfg;
519 * The scheduler for this service.
521 static struct GNUNET_SCHEDULER_Handle *sched;
524 * The client, the DV plugin connected to us. Hopefully
525 * this client will never change, although if the plugin dies
526 * and returns for some reason it may happen.
528 static struct GNUNET_SERVER_Client * client_handle;
531 * Task to run when we shut down, cleaning up all our trash
533 static GNUNET_SCHEDULER_TaskIdentifier cleanup_task;
535 static size_t default_dv_priority = 0;
537 static char *my_short_id;
540 * Transmit handle to the plugin.
542 static struct GNUNET_CONNECTION_TransmitHandle * plugin_transmit_handle;
545 * Head of DLL for client messages
547 static struct PendingMessage *plugin_pending_head;
550 * Tail of DLL for client messages
552 static struct PendingMessage *plugin_pending_tail;
555 * Handle to the peerinfo service
557 static struct GNUNET_PEERINFO_Handle *peerinfo_handle;
560 * Transmit handle to core service.
562 static struct GNUNET_CORE_TransmitHandle * core_transmit_handle;
565 * Head of DLL for core messages
567 static struct PendingMessage *core_pending_head;
570 * Tail of DLL for core messages
572 static struct PendingMessage *core_pending_tail;
575 * Map of PeerIdentifiers to 'struct GNUNET_dv_neighbor*'s for all
576 * directly connected peers.
578 static struct GNUNET_CONTAINER_MultiHashMap *direct_neighbors;
581 * Map of PeerIdentifiers to 'struct GNUNET_dv_neighbor*'s for
582 * peers connected via DV (extended neighborhood). Does ALSO
583 * include any peers that are in 'direct_neighbors'; for those
584 * peers, the cost will be zero and the referrer all zeros.
586 static struct GNUNET_CONTAINER_MultiHashMap *extended_neighbors;
589 * We use the min heap (min refers to cost) to prefer
590 * gossipping about peers with small costs.
592 static struct GNUNET_CONTAINER_Heap *neighbor_min_heap;
595 * We use the max heap (max refers to cost) for general
596 * iterations over all peers and to remove the most costly
597 * connection if we have too many.
599 static struct GNUNET_CONTAINER_Heap *neighbor_max_heap;
602 * How far out to keep peers we learn about.
604 static unsigned long long fisheye_depth;
607 * How many peers to store at most.
609 static unsigned long long max_table_size;
612 * We've been given a target ID based on the random numbers that
613 * we assigned to our DV-neighborhood. Find the entry for the
614 * respective neighbor.
617 find_destination (void *cls,
618 struct GNUNET_CONTAINER_HeapNode *node,
619 void *element, GNUNET_CONTAINER_HeapCostType cost)
621 struct FindDestinationContext *fdc = cls;
622 struct DistantNeighbor *dn = element;
624 if (fdc->tid != dn->our_id)
632 * We've been given a target ID based on the random numbers that
633 * we assigned to our DV-neighborhood. Find the entry for the
634 * respective neighbor.
637 find_specific_id (void *cls,
638 const GNUNET_HashCode *key,
641 struct FindIDContext *fdc = cls;
642 struct DistantNeighbor *dn = value;
644 if (memcmp(&dn->referrer->identity, fdc->via, sizeof(struct GNUNET_PeerIdentity)) == 0)
646 fdc->tid = dn->referrer_id;
653 * Find a distant peer whose referrer_id matches what we're
654 * looking for. For looking up a peer we've gossipped about
655 * but is now disconnected. Need to do this because we don't
656 * want to remove those that may be accessible via a different
659 static int find_distant_peer (void *cls,
660 const GNUNET_HashCode * key,
663 struct FindDestinationContext *fdc = cls;
664 struct DistantNeighbor *distant = value;
666 if (fdc->tid == distant->referrer_id)
675 * Function called to notify a client about the socket
676 * begin ready to queue more data. "buf" will be
677 * NULL and "size" zero if the socket was closed for
678 * writing in the meantime.
681 * @param size number of bytes available in buf
682 * @param buf where the callee should write the message
683 * @return number of bytes written to buf
685 size_t transmit_to_plugin (void *cls,
686 size_t size, void *buf)
689 struct PendingMessage *reply;
695 /* client disconnected */
696 #if DEBUG_DV_MESSAGES
697 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s: %s buffer was NULL (client disconnect?)\n", my_short_id, "transmit_to_plugin");
701 plugin_transmit_handle = NULL;
703 while ( (NULL != (reply = plugin_pending_head)) &&
704 (size >= off + (msize = ntohs (reply->msg->size))))
706 GNUNET_CONTAINER_DLL_remove (plugin_pending_head,
709 memcpy (&cbuf[off], reply->msg, msize);
714 if (plugin_pending_head != NULL)
715 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle,
716 ntohs(plugin_pending_head->msg->size),
717 GNUNET_TIME_UNIT_FOREVER_REL,
718 &transmit_to_plugin, NULL);
724 * Send a message to the dv plugin.
726 * @param sender the direct sender of the message
727 * @param message the message to send to the plugin
728 * (may be an encapsulated type)
729 * @param message_size the size of the message to be sent
730 * @param distant_neighbor the original sender of the message
731 * @param cost the cost to the original sender of the message
733 void send_to_plugin(const struct GNUNET_PeerIdentity * sender,
734 const struct GNUNET_MessageHeader *message,
736 struct GNUNET_PeerIdentity *distant_neighbor,
739 struct GNUNET_DV_MessageReceived *received_msg;
740 struct PendingMessage *pending_message;
741 char *sender_address;
742 size_t sender_address_len;
743 char *packed_msg_start;
747 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send_to_plugin called with peer %s as sender\n", GNUNET_i2s(distant_neighbor));
750 if (memcmp(sender, distant_neighbor, sizeof(struct GNUNET_PeerIdentity)) != 0)
752 sender_address_len = sizeof(struct GNUNET_PeerIdentity) * 2;
753 sender_address = GNUNET_malloc(sender_address_len);
754 memcpy(sender_address, distant_neighbor, sizeof(struct GNUNET_PeerIdentity));
755 memcpy(&sender_address[sizeof(struct GNUNET_PeerIdentity)], sender, sizeof(struct GNUNET_PeerIdentity));
759 sender_address_len = sizeof(struct GNUNET_PeerIdentity);
760 sender_address = GNUNET_malloc(sender_address_len);
761 memcpy(sender_address, sender, sizeof(struct GNUNET_PeerIdentity));
764 size = sizeof(struct GNUNET_DV_MessageReceived) + sender_address_len + message_size;
765 received_msg = GNUNET_malloc(size);
766 received_msg->header.size = htons(size);
767 received_msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE);
768 received_msg->sender_address_len = htonl(sender_address_len);
769 received_msg->distance = htonl(cost);
770 received_msg->msg_len = htonl(message_size);
771 /* Set the sender in this message to be the original sender! */
772 memcpy(&received_msg->sender, distant_neighbor, sizeof(struct GNUNET_PeerIdentity));
773 /* Copy the intermediate sender to the end of the message, this is how the transport identifies this peer */
774 memcpy(&received_msg[1], sender_address, sender_address_len);
775 GNUNET_free(sender_address);
776 /* Copy the actual message after the sender */
777 packed_msg_start = (char *)&received_msg[1];
778 packed_msg_start = &packed_msg_start[sender_address_len];
779 memcpy(packed_msg_start, message, message_size);
780 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + size);
781 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1];
782 memcpy(&pending_message[1], received_msg, size);
783 GNUNET_free(received_msg);
785 GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head, plugin_pending_tail, plugin_pending_tail, pending_message);
787 if (client_handle != NULL)
789 if (plugin_transmit_handle == NULL)
791 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle,
792 size, GNUNET_TIME_UNIT_FOREVER_REL,
793 &transmit_to_plugin, NULL);
798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue message for plugin, client_handle not yet set (how?)!\n");
804 * Function called to notify a client about the socket
805 * being ready to queue more data. "buf" will be
806 * NULL and "size" zero if the socket was closed for
807 * writing in the meantime.
810 * @param size number of bytes available in buf
811 * @param buf where the callee should write the message
812 * @return number of bytes written to buf
814 size_t core_transmit_notify (void *cls,
815 size_t size, void *buf)
818 struct PendingMessage *reply;
819 struct PendingMessage *client_reply;
825 /* client disconnected */
827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s': buffer was NULL\n", "DHT");
832 core_transmit_handle = NULL;
834 reply = core_pending_head;
835 if ( (reply != NULL) &&
836 (size >= (msize = ntohs (reply->msg->size))))
839 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "`%s' : transmit_notify (core) called with size %d\n", "dv service", msize);
841 GNUNET_CONTAINER_DLL_remove (core_pending_head,
844 if (reply->send_result != NULL) /* Will only be non-null if a real client asked for this send */
846 client_reply = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(struct GNUNET_DV_SendResultMessage));
847 client_reply->msg = (struct GNUNET_MessageHeader *)&client_reply[1];
848 memcpy(&client_reply[1], reply->send_result, sizeof(struct GNUNET_DV_SendResultMessage));
849 GNUNET_free(reply->send_result);
851 GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head, plugin_pending_tail, plugin_pending_tail, client_reply);
852 if (client_handle != NULL)
854 if (plugin_transmit_handle == NULL)
856 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle,
857 sizeof(struct GNUNET_DV_SendResultMessage),
858 GNUNET_TIME_UNIT_FOREVER_REL,
859 &transmit_to_plugin, NULL);
863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue message for plugin, must be one in progress already!!\n");
867 memcpy (&cbuf[off], reply->msg, msize);
871 reply = core_pending_head;
873 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, reply->importance, reply->timeout, &reply->recipient, reply->msg_size, &core_transmit_notify, NULL);
880 * Send a DV data message via DV.
882 * @param sender the original sender of the message
883 * @param recipient the next hop recipient, may be our direct peer, maybe not
884 * @param send_context the send context
887 send_message_via (const struct GNUNET_PeerIdentity *sender,
888 const struct GNUNET_PeerIdentity *recipient,
889 struct DV_SendContext *send_context)
891 p2p_dv_MESSAGE_Data *toSend;
892 unsigned int msg_size;
893 unsigned int recipient_id;
894 unsigned int sender_id;
895 struct DistantNeighbor *source;
896 struct PendingMessage *pending_message;
897 struct FindIDContext find_context;
902 msg_size = send_context->message_size + sizeof (p2p_dv_MESSAGE_Data);
904 find_context.dest = send_context->distant_peer;
905 find_context.via = recipient;
906 find_context.tid = 0;
907 GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors, &send_context->distant_peer->hashPubKey,
908 &find_specific_id, &find_context);
910 if (find_context.tid == 0)
912 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: find_specific_id failed to find peer!\n", my_short_id);
913 /* target unknown to us, drop! */
914 return GNUNET_SYSERR;
916 recipient_id = find_context.tid;
918 if (0 == (memcmp (&my_identity,
919 sender, sizeof (struct GNUNET_PeerIdentity))))
922 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
923 &sender->hashPubKey);
925 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: send_message_via found %s, myself in extended peer list???\n", my_short_id, GNUNET_i2s(&source->identity));
929 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
930 &sender->hashPubKey);
933 /* sender unknown to us, drop! */
934 return GNUNET_SYSERR;
936 sender_id = source->our_id;
939 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + msg_size);
940 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1];
941 pending_message->send_result = send_context->send_result;
942 memcpy(&pending_message->recipient, recipient, sizeof(struct GNUNET_PeerIdentity));
943 pending_message->msg_size = msg_size;
944 pending_message->importance = send_context->importance;
945 pending_message->timeout = send_context->timeout;
946 toSend = (p2p_dv_MESSAGE_Data *)pending_message->msg;
947 toSend->header.size = htons (msg_size);
948 toSend->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DATA);
949 toSend->sender = htonl (sender_id);
950 toSend->recipient = htonl (recipient_id);
951 #if DEBUG_DV_MESSAGES
952 toSend->uid = send_context->uid; /* Still sent around in network byte order */
954 toSend->uid = htonl(0);
957 memcpy (&toSend[1], send_context->message, send_context->message_size);
960 memcpy(&shortname, GNUNET_i2s(send_context->distant_peer), 4);
962 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Notifying core of send to destination `%s' via `%s' size %u\n", "DV", &shortname, GNUNET_i2s(recipient), msg_size);
965 GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
970 if (core_transmit_handle == NULL)
971 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, send_context->importance, send_context->timeout, recipient, msg_size, &core_transmit_notify, NULL);
975 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "`%s': Failed to schedule pending transmission (must be one in progress!)\n", "dv service");
982 * Given a FindLeastCostContext, and a set
983 * of peers that match the target, return the cheapest.
985 * @param cls closure, a struct FindLeastCostContext
986 * @param key the key identifying the target peer
987 * @param value the target peer
989 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop
992 find_least_cost_peer (void *cls,
993 const GNUNET_HashCode *key,
996 struct FindLeastCostContext *find_context = cls;
997 struct DistantNeighbor *dn = value;
999 if (dn->cost < find_context->least_cost)
1001 find_context->target = dn;
1003 if (dn->cost == DIRECT_NEIGHBOR_COST)
1009 * Send a DV data message via DV.
1011 * @param recipient the ultimate recipient of this message
1012 * @param sender the original sender of the message
1013 * @param specific_neighbor the specific neighbor to send this message via
1014 * @param message the packed message
1015 * @param message_size size of the message
1016 * @param importance what priority to send this message with
1017 * @param timeout how long to possibly delay sending this message
1020 send_message (const struct GNUNET_PeerIdentity * recipient,
1021 const struct GNUNET_PeerIdentity * sender,
1022 const struct DistantNeighbor * specific_neighbor,
1023 const struct GNUNET_MessageHeader * message,
1024 size_t message_size,
1025 unsigned int importance,
1027 struct GNUNET_TIME_Relative timeout)
1029 p2p_dv_MESSAGE_Data *toSend;
1030 unsigned int msg_size;
1032 unsigned int recipient_id;
1033 unsigned int sender_id;
1034 struct DistantNeighbor *target;
1035 struct DistantNeighbor *source;
1036 struct PendingMessage *pending_message;
1037 struct FindLeastCostContext find_least_ctx;
1038 #if DEBUG_DV_PEER_NUMBERS
1039 struct GNUNET_CRYPTO_HashAsciiEncoded encPeerFrom;
1040 struct GNUNET_CRYPTO_HashAsciiEncoded encPeerTo;
1041 struct GNUNET_CRYPTO_HashAsciiEncoded encPeerVia;
1043 msg_size = message_size + sizeof (p2p_dv_MESSAGE_Data);
1045 find_least_ctx.least_cost = -1;
1046 find_least_ctx.target = NULL;
1048 * Need to find the least cost peer, lest the transport selection keep
1049 * picking the same DV route for the same destination which results
1050 * in messages looping forever. Relatively cheap, we don't iterate
1051 * over all known peers, just those that apply.
1053 GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors,
1054 &recipient->hashPubKey, &find_least_cost_peer, &find_least_ctx);
1055 target = find_least_ctx.target;
1059 /* target unknown to us, drop! */
1060 return GNUNET_SYSERR;
1062 recipient_id = target->referrer_id;
1064 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
1065 &sender->hashPubKey);
1068 if (0 != (memcmp (&my_identity,
1069 sender, sizeof (struct GNUNET_PeerIdentity))))
1071 /* sender unknown to us, drop! */
1072 return GNUNET_SYSERR;
1074 sender_id = 0; /* 0 == us */
1078 /* find out the number that we use when we gossip about
1080 sender_id = source->our_id;
1083 #if DEBUG_DV_PEER_NUMBERS
1084 GNUNET_CRYPTO_hash_to_enc (&source->identity.hashPubKey, &encPeerFrom);
1085 GNUNET_CRYPTO_hash_to_enc (&target->referrer->identity.hashPubKey, &encPeerVia);
1086 encPeerFrom.encoding[4] = '\0';
1087 encPeerVia.encoding[4] = '\0';
1089 if ((sender_id != 0) && (0 == memcmp(&source->identity, &target->referrer->identity, sizeof(struct GNUNET_PeerIdentity))))
1094 cost = target->cost;
1095 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + msg_size);
1096 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1];
1097 pending_message->send_result = NULL;
1098 pending_message->importance = importance;
1099 pending_message->timeout = timeout;
1100 memcpy(&pending_message->recipient, &target->referrer->identity, sizeof(struct GNUNET_PeerIdentity));
1101 pending_message->msg_size = msg_size;
1102 toSend = (p2p_dv_MESSAGE_Data *)pending_message->msg;
1103 toSend->header.size = htons (msg_size);
1104 toSend->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DATA);
1105 toSend->sender = htonl (sender_id);
1106 toSend->recipient = htonl (recipient_id);
1107 #if DEBUG_DV_MESSAGES
1108 toSend->uid = htonl(uid);
1110 toSend->uid = htonl(0);
1113 #if DEBUG_DV_PEER_NUMBERS
1114 GNUNET_CRYPTO_hash_to_enc (&target->identity.hashPubKey, &encPeerTo);
1115 encPeerTo.encoding[4] = '\0';
1116 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Sending DATA message. Sender id %u, source %s, destination %s, via %s\n", GNUNET_i2s(&my_identity), sender_id, &encPeerFrom, &encPeerTo, &encPeerVia);
1118 memcpy (&toSend[1], message, message_size);
1119 if (source->pkey == NULL) /* Test our hypothesis about message failures! */
1121 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: Sending message, but anticipate recipient will not know sender!!!\n\n\n");
1123 GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
1128 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Notifying core of send size %d to destination `%s'\n", "DV SEND MESSAGE", msg_size, GNUNET_i2s(recipient));
1130 if (core_transmit_handle == NULL)
1131 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, importance, timeout, &target->referrer->identity, msg_size, &core_transmit_notify, NULL);
1133 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: CORE ALREADY SENDING\n", "DV SEND MESSAGE", msg_size);
1138 struct CheckPeerContext
1143 struct DistantNeighbor *peer;
1146 * Sender id to search for
1148 unsigned int sender_id;
1152 * Iterator over hash map entries.
1154 * @param cls closure
1155 * @param key current key code
1156 * @param value value in the hash map
1157 * @return GNUNET_YES if we should continue to
1161 int checkPeerID (void *cls,
1162 const GNUNET_HashCode * key,
1165 struct CheckPeerContext *ctx = cls;
1166 struct DistantNeighbor *distant = value;
1168 if (memcmp(key, &ctx->sender_id, sizeof(unsigned int)) == 0)
1170 ctx->peer = distant;
1180 * Handler for messages parsed out by the tokenizer from
1181 * DV DATA received for this peer.
1184 * @param client the TokenizedMessageContext which contains message information
1185 * @param message the actual message
1187 void tokenized_message_handler (void *cls,
1189 const struct GNUNET_MessageHeader *message)
1191 struct TokenizedMessageContext *ctx = client;
1192 GNUNET_break_op (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP);
1193 GNUNET_break_op (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_DATA);
1194 if ( (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP) &&
1195 (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_DATA) )
1197 #if DEBUG_DV_MESSAGES
1198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1199 "%s: Receives %s message for me, uid %u, size %d, type %d cost %u from %s!\n", my_short_id, "DV DATA", ctx->uid, ntohs(message->size), ntohs(message->type), ctx->distant->cost, GNUNET_i2s(&ctx->distant->identity));
1201 GNUNET_assert(memcmp(ctx->peer, &ctx->distant->identity, sizeof(struct GNUNET_PeerIdentity)) != 0);
1202 send_to_plugin(ctx->peer, message, ntohs(message->size), &ctx->distant->identity, ctx->distant->cost);
1207 * Core handler for dv data messages. Whatever this message
1208 * contains all we really have to do is rip it out of its
1209 * DV layering and give it to our pal the DV plugin to report
1212 * @param cls closure
1213 * @param peer peer which sent the message (immediate sender)
1214 * @param message the message
1215 * @param latency the latency of the connection we received the message from
1216 * @param distance the distance to the immediate peer
1218 static int handle_dv_data_message (void *cls,
1219 const struct GNUNET_PeerIdentity * peer,
1220 const struct GNUNET_MessageHeader * message,
1221 struct GNUNET_TIME_Relative latency,
1224 const p2p_dv_MESSAGE_Data *incoming = (const p2p_dv_MESSAGE_Data *) message;
1225 const struct GNUNET_MessageHeader *packed_message;
1226 struct DirectNeighbor *dn;
1227 struct DistantNeighbor *pos;
1228 unsigned int sid; /* Sender id */
1229 unsigned int tid; /* Target id */
1230 struct GNUNET_PeerIdentity original_sender;
1231 struct GNUNET_PeerIdentity destination;
1232 struct FindDestinationContext fdc;
1233 struct TokenizedMessageContext tkm_ctx;
1235 struct CheckPeerContext checkPeerCtx;
1240 size_t packed_message_size;
1245 packed_message_size = ntohs(incoming->header.size) - sizeof(p2p_dv_MESSAGE_Data);
1249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1250 "%s: Receives DATA message from %s size %d, packed size %d!\n", my_short_id, GNUNET_i2s(peer) , ntohs(incoming->header.size), packed_message_size);
1253 if (ntohs (incoming->header.size) < sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader))
1257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1258 "`%s': Message sizes don't add up, total size %u, expected at least %u!\n", "dv service", ntohs(incoming->header.size), sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader));
1260 return GNUNET_SYSERR;
1263 dn = GNUNET_CONTAINER_multihashmap_get (direct_neighbors,
1268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1269 "%s: dn NULL!\n", "dv");
1273 sid = ntohl (incoming->sender);
1277 checkPeerCtx.sender_id = sid;
1278 checkPeerCtx.peer = NULL;
1279 GNUNET_CONTAINER_multihashmap_iterate(extended_neighbors, &checkPeerID, &checkPeerCtx);
1280 pos = checkPeerCtx.peer;
1284 pos = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
1288 pos = dn->referee_head;
1289 while ((NULL != pos) && (pos->referrer_id != sid))
1295 direct_id = GNUNET_strdup(GNUNET_i2s(&dn->identity));
1296 #if DEBUG_DV_MESSAGES
1297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1298 "%s: unknown sender (%u), Message uid %llu from %s!\n", GNUNET_i2s(&my_identity), ntohl(incoming->sender), ntohl(incoming->uid), direct_id);
1300 GNUNET_free(direct_id);
1301 pos = dn->referee_head;
1302 while ((NULL != pos) && (pos->referrer_id != sid))
1304 sender_id = strdup(GNUNET_i2s(&pos->identity));
1305 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "I know sender %u %s\n", pos->referrer_id, sender_id);
1306 GNUNET_free(sender_id);
1310 #if DEBUG_MESSAGE_DROP
1311 direct_id = GNUNET_strdup(GNUNET_i2s(&dn->identity));
1312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1313 "%s: DROPPING MESSAGE type %d, unknown sender! Message immediately from %s!\n", GNUNET_i2s(&my_identity), ntohs(((struct GNUNET_MessageHeader *)&incoming[1])->type), direct_id);
1314 GNUNET_free(direct_id);
1316 /* unknown sender */
1319 original_sender = pos->identity;
1320 tid = ntohl (incoming->recipient);
1324 cbuf = (char *)&incoming[1];
1326 tkm_ctx.peer = peer;
1327 tkm_ctx.distant = pos;
1328 tkm_ctx.uid = ntohl(incoming->uid);
1329 if (GNUNET_OK != GNUNET_SERVER_mst_receive (coreMST,
1332 packed_message_size,
1337 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: %s Received corrupt data, discarding!", my_short_id, "DV SERVICE");
1341 while(offset < packed_message_size)
1343 packed_message = (struct GNUNET_MessageHeader *)&cbuf[offset];
1345 GNUNET_break_op (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP);
1346 GNUNET_break_op (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_DATA);
1347 if ( (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP) &&
1348 (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_DATA) )
1350 #if DEBUG_DV_MESSAGES
1351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1352 "%s: Receives %s message(s) for me, uid %u, total size %d cost %u from %s!\n", my_short_id, "DV DATA", ntohl(incoming->uid), ntohs(packed_message->size), pos->cost, GNUNET_i2s(&pos->identity));
1354 GNUNET_assert(memcmp(peer, &pos->identity, sizeof(struct GNUNET_PeerIdentity)) != 0);
1355 send_to_plugin(peer, packed_message, ntohs(packed_message->size), &pos->identity, pos->cost);
1357 offset += ntohs(packed_message->size);
1364 packed_message = (struct GNUNET_MessageHeader *)&incoming[1];
1367 /* FIXME: this is the *only* per-request operation we have in DV
1368 that is O(n) in relation to the number of connected peers; a
1369 hash-table lookup could easily solve this (minor performance
1373 GNUNET_CONTAINER_heap_iterate (neighbor_max_heap,
1374 &find_destination, &fdc);
1377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1378 "%s: Receives %s message for someone else!\n", "dv", "DV DATA");
1381 if (fdc.dest == NULL)
1383 #if DEBUG_DV_MESSAGES
1384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1385 "%s: Receives %s message uid %u for someone we don't know (id %u)!\n", my_short_id, "DV DATA", ntohl(incoming->uid), tid);
1389 destination = fdc.dest->identity;
1391 if (0 == memcmp (&destination, peer, sizeof (struct GNUNET_PeerIdentity)))
1393 /* FIXME: create stat: routing loop-discard! */
1394 #if DEBUG_DV_PEER_NUMBERS
1395 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\n\n\nLoopy loo message\n\n\n");
1398 #if DEBUG_DV_MESSAGES
1399 direct_id = GNUNET_strdup(GNUNET_i2s(&dn->identity));
1400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1401 "%s: DROPPING MESSAGE uid %u type %d, routing loop! Message immediately from %s!\n", my_short_id, ntohl(incoming->uid), ntohs(packed_message->type), direct_id);
1406 /* At this point we have a message, and we need to forward it on to the
1409 /* FIXME: Can't send message on, we have to behave.
1410 * We have to tell core we have a message for the next peer, and let
1411 * transport do transport selection on how to get this message to 'em */
1412 /*ret = send_message (&destination,
1414 packed_message, DV_PRIORITY, DV_DELAY);*/
1416 #if DEBUG_DV_MESSAGES
1417 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1418 "%s: FORWARD %s message for %s, uid %u, size %d type %d, cost %u!\n", my_short_id, "DV DATA", GNUNET_i2s(&destination), ntohl(incoming->uid), ntohs(packed_message->size), ntohs(packed_message->type), pos->cost);
1421 ret = send_message(&destination,
1425 packed_message_size,
1426 default_dv_priority,
1427 ntohl(incoming->uid),
1428 GNUNET_TIME_relative_get_forever());
1430 if (ret != GNUNET_SYSERR)
1434 #if DEBUG_MESSAGE_DROP
1435 direct_id = GNUNET_strdup(GNUNET_i2s(&dn->identity));
1436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1437 "%s: DROPPING MESSAGE type %d, forwarding failed! Message immediately from %s!\n", GNUNET_i2s(&my_identity), ntohs(((struct GNUNET_MessageHeader *)&incoming[1])->type), direct_id);
1439 return GNUNET_SYSERR;
1445 * Iterator over hash map entries.
1447 * @param cls closure (NULL)
1448 * @param key current key code
1449 * @param value value in the hash map (DistantNeighbor)
1450 * @return GNUNET_YES if we should continue to
1454 int print_neighbors (void *cls,
1455 const GNUNET_HashCode * key,
1458 struct DistantNeighbor *distant_neighbor = value;
1459 char my_shortname[5];
1460 char referrer_shortname[5];
1461 memcpy(&my_shortname, GNUNET_i2s(&my_identity), 4);
1462 my_shortname[4] = '\0';
1463 memcpy(&referrer_shortname, GNUNET_i2s(&distant_neighbor->referrer->identity), 4);
1464 referrer_shortname[4] = '\0';
1466 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`%s' %s: Peer `%s', distance %d, referrer `%s' pkey: %s\n", &my_shortname, "DV", GNUNET_i2s(&distant_neighbor->identity), distant_neighbor->cost, &referrer_shortname, distant_neighbor->pkey == NULL ? "no" : "yes");
1472 * Scheduled task which gossips about known direct peers to other connected
1473 * peers. Will run until called with reason shutdown.
1476 neighbor_send_task (void *cls,
1477 const struct GNUNET_SCHEDULER_TaskContext *tc)
1479 struct NeighborSendContext *send_context = cls;
1480 #if DEBUG_DV_GOSSIP_SEND
1481 char * encPeerAbout;
1484 struct DistantNeighbor *about;
1485 struct DirectNeighbor *to;
1486 struct FastGossipNeighborList *about_list;
1488 p2p_dv_MESSAGE_NeighborInfo *message;
1489 struct PendingMessage *pending_message;
1491 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
1494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1495 "%s: Called with reason shutdown, shutting down!\n",
1496 GNUNET_i2s(&my_identity));
1501 if (send_context->fast_gossip_list_head != NULL)
1503 about_list = send_context->fast_gossip_list_head;
1504 about = about_list->about;
1505 GNUNET_CONTAINER_DLL_remove(send_context->fast_gossip_list_head,
1506 send_context->fast_gossip_list_tail,
1508 GNUNET_free(about_list);
1512 /* FIXME: this may become a problem, because the heap walk has only one internal "walker". This means
1513 * that if two neighbor_send_tasks are operating in lockstep (which is quite possible, given default
1514 * values for all connected peers) there may be a serious bias as to which peers get gossiped about!
1515 * Probably the *best* way to fix would be to have an opaque pointer to the walk position passed as
1516 * part of the walk_get_next call. Then the heap would have to keep a list of walks, or reset the walk
1517 * whenever a modification has been detected. Yuck either way. Perhaps we could iterate over the heap
1518 * once to get a list of peers to gossip about and gossip them over time... But then if one goes away
1519 * in the mean time that becomes nasty. For now we'll just assume that the walking is done
1520 * asynchronously enough to avoid major problems (-;
1522 * NOTE: probably fixed once we decided send rate based on allowed bandwidth.
1524 about = GNUNET_CONTAINER_heap_walk_get_next (neighbor_min_heap);
1526 to = send_context->toNeighbor;
1528 if ((about != NULL) && (to != about->referrer /* split horizon */ ) &&
1530 (about->hidden == GNUNET_NO) &&
1533 (0 != memcmp (&about->identity,
1534 &to->identity, sizeof (struct GNUNET_PeerIdentity))) &&
1535 (about->pkey != NULL))
1537 #if DEBUG_DV_GOSSIP_SEND
1538 encPeerAbout = GNUNET_strdup(GNUNET_i2s(&about->identity));
1539 encPeerTo = GNUNET_strdup(GNUNET_i2s(&to->identity));
1540 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1541 "%s: Sending info about peer %s id %u to directly connected peer %s\n",
1542 GNUNET_i2s(&my_identity),
1543 encPeerAbout, about->our_id, encPeerTo);
1544 GNUNET_free(encPeerAbout);
1545 GNUNET_free(encPeerTo);
1547 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(p2p_dv_MESSAGE_NeighborInfo));
1548 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1];
1549 pending_message->importance = default_dv_priority;
1550 pending_message->timeout = GNUNET_TIME_relative_get_forever();
1551 memcpy(&pending_message->recipient, &to->identity, sizeof(struct GNUNET_PeerIdentity));
1552 pending_message->msg_size = sizeof(p2p_dv_MESSAGE_NeighborInfo);
1553 message = (p2p_dv_MESSAGE_NeighborInfo *)pending_message->msg;
1554 message->header.size = htons (sizeof (p2p_dv_MESSAGE_NeighborInfo));
1555 message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_GOSSIP);
1556 message->cost = htonl (about->cost);
1557 message->neighbor_id = htonl (about->our_id);
1559 memcpy (&message->pkey, about->pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
1560 memcpy (&message->neighbor,
1561 &about->identity, sizeof (struct GNUNET_PeerIdentity));
1563 GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
1568 if (core_transmit_handle == NULL)
1569 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, default_dv_priority, GNUNET_TIME_relative_get_forever(), &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, NULL);
1573 if (send_context->fast_gossip_list_head != NULL) /* If there are other peers in the fast list, schedule right away */
1575 #if DEBUG_DV_PEER_NUMBERS
1576 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DV SERVICE: still in fast send mode\n");
1578 send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, send_context);
1582 #if DEBUG_DV_PEER_NUMBERS
1583 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DV SERVICE: entering slow send mode\n");
1585 send_context->task = GNUNET_SCHEDULER_add_delayed(sched, GNUNET_DV_DEFAULT_SEND_INTERVAL, &neighbor_send_task, send_context);
1593 * Handle START-message. This is the first message sent to us
1594 * by the client (can only be one!).
1596 * @param cls closure (always NULL)
1597 * @param client identification of the client
1598 * @param message the actual message
1601 handle_start (void *cls,
1602 struct GNUNET_SERVER_Client *client,
1603 const struct GNUNET_MessageHeader *message)
1607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1608 "Received `%s' request from client\n", "START");
1611 client_handle = client;
1613 GNUNET_SERVER_client_keep(client_handle);
1614 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1619 * Iterate over hash map entries for a distant neighbor,
1620 * if direct neighbor matches context call send message
1622 * @param cls closure, a DV_SendContext
1623 * @param key current key code
1624 * @param value value in the hash map
1625 * @return GNUNET_YES if we should continue to
1629 int send_iterator (void *cls,
1630 const GNUNET_HashCode * key,
1633 struct DV_SendContext *send_context = cls;
1634 struct DistantNeighbor *distant_neighbor = value;
1636 if (memcmp(distant_neighbor->referrer, send_context->direct_peer, sizeof(struct GNUNET_PeerIdentity)) == 0) /* They match, send and free */
1638 send_message_via(&my_identity, distant_neighbor, send_context);
1646 * Service server's handler for message send requests (which come
1647 * bubbling up to us through the DV plugin).
1649 * @param cls closure
1650 * @param client identification of the client
1651 * @param message the actual message
1653 void handle_dv_send_message (void *cls,
1654 struct GNUNET_SERVER_Client * client,
1655 const struct GNUNET_MessageHeader * message)
1657 struct GNUNET_DV_SendMessage *send_msg;
1658 struct GNUNET_DV_SendResultMessage *send_result_msg;
1659 struct PendingMessage *pending_message;
1661 size_t message_size;
1662 struct GNUNET_PeerIdentity *destination;
1663 struct GNUNET_PeerIdentity *direct;
1664 struct GNUNET_MessageHeader *message_buf;
1667 static struct GNUNET_CRYPTO_HashAsciiEncoded dest_hash;
1668 struct DV_SendContext *send_context;
1669 #if DEBUG_DV_MESSAGES
1671 struct GNUNET_MessageHeader *packed_message;
1674 if (client_handle == NULL)
1676 client_handle = client;
1677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1678 "%s: Setting initial client handle, never received `%s' message?\n", "dv", "START");
1680 else if (client_handle != client)
1682 client_handle = client;
1683 /* What should we do in this case, assert fail or just log the warning? */
1685 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1686 "%s: Setting client handle (was a different client!)!\n", "dv");
1690 GNUNET_assert(ntohs(message->size) > sizeof(struct GNUNET_DV_SendMessage));
1691 send_msg = (struct GNUNET_DV_SendMessage *)message;
1693 address_len = ntohl(send_msg->addrlen);
1694 GNUNET_assert(address_len == sizeof(struct GNUNET_PeerIdentity) * 2);
1695 message_size = ntohs(message->size) - sizeof(struct GNUNET_DV_SendMessage) - address_len;
1696 destination = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
1697 direct = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
1698 message_buf = GNUNET_malloc(message_size);
1700 temp_pos = (char *)&send_msg[1]; /* Set pointer to end of message */
1701 offset = 0; /* Offset starts at zero */
1703 memcpy(destination, &temp_pos[offset], sizeof(struct GNUNET_PeerIdentity));
1704 offset += sizeof(struct GNUNET_PeerIdentity);
1706 memcpy(direct, &temp_pos[offset], sizeof(struct GNUNET_PeerIdentity));
1707 offset += sizeof(struct GNUNET_PeerIdentity);
1710 memcpy(message_buf, &temp_pos[offset], message_size);
1711 if (memcmp(&send_msg->target, destination, sizeof(struct GNUNET_PeerIdentity)) != 0)
1713 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
1714 dest_hash.encoding[4] = '\0';
1715 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: asked to send message to `%s', but address is for `%s'!", "DV SERVICE", GNUNET_i2s(&send_msg->target), (const char *)&dest_hash.encoding);
1718 #if DEBUG_DV_MESSAGES
1719 cbuf = (char *)message_buf;
1721 while(offset < message_size)
1723 packed_message = (struct GNUNET_MessageHeader *)&cbuf[offset];
1724 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: DV PLUGIN SEND uid %u type %d to %s\n", my_short_id, ntohl(send_msg->uid), ntohs(packed_message->type), GNUNET_i2s(destination));
1725 offset += ntohs(packed_message->size);
1727 /*GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: DV PLUGIN SEND uid %u type %d to %s\n", my_short_id, ntohl(send_msg->uid), ntohs(message_buf->type), GNUNET_i2s(destination));*/
1729 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
1730 dest_hash.encoding[4] = '\0';
1731 send_context = GNUNET_malloc(sizeof(struct DV_SendContext));
1733 send_result_msg = GNUNET_malloc(sizeof(struct GNUNET_DV_SendResultMessage));
1734 send_result_msg->header.size = htons(sizeof(struct GNUNET_DV_SendResultMessage));
1735 send_result_msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT);
1736 send_result_msg->uid = send_msg->uid; /* No need to ntohl->htonl this */
1738 send_context->importance = ntohl(send_msg->priority);
1739 send_context->timeout = send_msg->timeout;
1740 send_context->direct_peer = direct;
1741 send_context->distant_peer = destination;
1742 send_context->message = message_buf;
1743 send_context->message_size = message_size;
1744 send_context->send_result = send_result_msg;
1745 #if DEBUG_DV_MESSAGES
1746 send_context->uid = send_msg->uid;
1749 if (send_message_via(&my_identity, direct, send_context) != GNUNET_YES)
1751 send_result_msg->result = htons(1);
1752 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(struct GNUNET_DV_SendResultMessage));
1753 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1];
1754 memcpy(&pending_message[1], send_result_msg, sizeof(struct GNUNET_DV_SendResultMessage));
1755 GNUNET_free(send_result_msg);
1757 GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head, plugin_pending_tail, plugin_pending_tail, pending_message);
1759 if (client_handle != NULL)
1761 if (plugin_transmit_handle == NULL)
1763 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle,
1764 sizeof(struct GNUNET_DV_SendResultMessage),
1765 GNUNET_TIME_UNIT_FOREVER_REL,
1766 &transmit_to_plugin, NULL);
1770 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue message for plugin, must be one in progress already!!\n");
1773 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
1774 dest_hash.encoding[4] = '\0';
1775 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s DV SEND failed to send message to destination `%s' via `%s'\n", my_short_id, (const char *)&dest_hash.encoding, GNUNET_i2s(direct));
1778 /* In bizarro world GNUNET_SYSERR indicates that we succeeded */
1780 if (GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_get_multiple(extended_neighbors, &destination->hashPubKey, &send_iterator, send_context))
1782 send_result_msg->result = htons(1);
1783 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(struct GNUNET_DV_SendResultMessage));
1784 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1];
1785 memcpy(&pending_message[1], send_result_msg, sizeof(struct GNUNET_DV_SendResultMessage));
1786 GNUNET_free(send_result_msg);
1788 GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head, plugin_pending_tail, plugin_pending_tail, pending_message);
1790 if (client_handle != NULL)
1792 if (plugin_transmit_handle == NULL)
1794 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle,
1795 sizeof(struct GNUNET_DV_SendResultMessage),
1796 GNUNET_TIME_UNIT_FOREVER_REL,
1797 &transmit_to_plugin, NULL);
1801 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue message for plugin, must be one in progress already!!\n");
1804 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
1805 dest_hash.encoding[4] = '\0';
1806 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s DV SEND failed to send message to destination `%s' via `%s'\n", my_short_id, (const char *)&dest_hash.encoding, GNUNET_i2s(direct));
1809 GNUNET_free(message_buf);
1810 GNUNET_free(send_context);
1811 GNUNET_free(direct);
1812 GNUNET_free(destination);
1814 GNUNET_SERVER_receive_done(client, GNUNET_OK);
1817 /** Forward declarations **/
1818 static int handle_dv_gossip_message (void *cls,
1819 const struct GNUNET_PeerIdentity *peer,
1820 const struct GNUNET_MessageHeader *message,
1821 struct GNUNET_TIME_Relative latency,
1824 static int handle_dv_disconnect_message (void *cls,
1825 const struct GNUNET_PeerIdentity *peer,
1826 const struct GNUNET_MessageHeader *message,
1827 struct GNUNET_TIME_Relative latency,
1829 /** End forward declarations **/
1833 * List of handlers for the messages understood by this
1836 * Hmm... will we need to register some handlers with core and
1837 * some handlers with our server here? Because core should be
1838 * getting the incoming DV messages (from whichever lower level
1839 * transport) and then our server should be getting messages
1840 * from the dv_plugin, right?
1842 static struct GNUNET_CORE_MessageHandler core_handlers[] = {
1843 {&handle_dv_data_message, GNUNET_MESSAGE_TYPE_DV_DATA, 0},
1844 {&handle_dv_gossip_message, GNUNET_MESSAGE_TYPE_DV_GOSSIP, 0},
1845 {&handle_dv_disconnect_message, GNUNET_MESSAGE_TYPE_DV_DISCONNECT, 0},
1849 static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = {
1850 {&handle_dv_send_message, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND, 0},
1851 {&handle_start, NULL, GNUNET_MESSAGE_TYPE_DV_START, 0},
1856 * Free a DistantNeighbor node, including removing it
1857 * from the referer's list.
1860 distant_neighbor_free (struct DistantNeighbor *referee)
1862 struct DirectNeighbor *referrer;
1864 referrer = referee->referrer;
1865 if (referrer != NULL)
1867 GNUNET_CONTAINER_DLL_remove (referrer->referee_head,
1868 referrer->referee_tail, referee);
1870 GNUNET_CONTAINER_heap_remove_node (neighbor_max_heap, referee->max_loc);
1871 GNUNET_CONTAINER_heap_remove_node (neighbor_min_heap, referee->min_loc);
1872 GNUNET_CONTAINER_multihashmap_remove_all (extended_neighbors,
1873 &referee->identity.hashPubKey);
1874 GNUNET_free_non_null (referee->pkey);
1875 GNUNET_free (referee);
1879 * Free a DirectNeighbor node, including removing it
1880 * from the referer's list.
1883 direct_neighbor_free (struct DirectNeighbor *direct)
1885 struct NeighborSendContext *send_context;
1886 struct FastGossipNeighborList *about_list;
1887 struct FastGossipNeighborList *prev_about;
1889 send_context = direct->send_context;
1891 if (send_context->task != GNUNET_SCHEDULER_NO_TASK)
1892 GNUNET_SCHEDULER_cancel(sched, send_context->task);
1894 about_list = send_context->fast_gossip_list_head;
1895 while (about_list != NULL)
1897 GNUNET_CONTAINER_DLL_remove(send_context->fast_gossip_list_head, send_context->fast_gossip_list_tail, about_list);
1898 prev_about = about_list;
1899 about_list = about_list->next;
1900 GNUNET_free(prev_about);
1902 GNUNET_free(send_context);
1903 GNUNET_free(direct);
1907 * Multihashmap iterator for sending out disconnect messages
1910 * @param cls the peer that was disconnected
1911 * @param key key value stored under
1912 * @param value the direct neighbor to send disconnect to
1914 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop
1916 static int schedule_disconnect_messages (void *cls,
1917 const GNUNET_HashCode * key,
1920 struct DisconnectContext *disconnect_context = cls;
1921 struct DirectNeighbor *disconnected = disconnect_context->direct;
1922 struct DirectNeighbor *notify = value;
1923 struct PendingMessage *pending_message;
1924 p2p_dv_MESSAGE_Disconnect *disconnect_message;
1926 if (memcmp(¬ify->identity, &disconnected->identity, sizeof(struct GNUNET_PeerIdentity)) == 0)
1927 return GNUNET_YES; /* Don't send disconnect message to peer that disconnected! */
1929 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(p2p_dv_MESSAGE_Disconnect));
1930 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1];
1931 pending_message->importance = default_dv_priority;
1932 pending_message->timeout = GNUNET_TIME_relative_get_forever();
1933 memcpy(&pending_message->recipient, ¬ify->identity, sizeof(struct GNUNET_PeerIdentity));
1934 pending_message->msg_size = sizeof(p2p_dv_MESSAGE_Disconnect);
1935 disconnect_message = (p2p_dv_MESSAGE_Disconnect *)pending_message->msg;
1936 disconnect_message->header.size = htons (sizeof (p2p_dv_MESSAGE_Disconnect));
1937 disconnect_message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DISCONNECT);
1938 disconnect_message->peer_id = htonl(disconnect_context->distant->our_id);
1940 GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
1945 if (core_transmit_handle == NULL)
1946 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, default_dv_priority, GNUNET_TIME_relative_get_forever(), ¬ify->identity, sizeof(p2p_dv_MESSAGE_Disconnect), &core_transmit_notify, NULL);
1952 * Multihashmap iterator for freeing extended neighbors.
1955 * @param key key value stored under
1956 * @param value the distant neighbor to be freed
1958 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop
1960 static int free_extended_neighbors (void *cls,
1961 const GNUNET_HashCode * key,
1964 struct DistantNeighbor *distant = value;
1965 distant_neighbor_free(distant);
1970 * Multihashmap iterator for freeing direct neighbors.
1973 * @param key key value stored under
1974 * @param value the direct neighbor to be freed
1976 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop
1978 static int free_direct_neighbors (void *cls,
1979 const GNUNET_HashCode * key,
1982 struct DirectNeighbor *direct = value;
1983 direct_neighbor_free(direct);
1989 * Task run during shutdown.
1995 shutdown_task (void *cls,
1996 const struct GNUNET_SCHEDULER_TaskContext *tc)
1999 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "calling CORE_DISCONNECT\n");
2000 GNUNET_CONTAINER_multihashmap_iterate(extended_neighbors, &print_neighbors, NULL);
2002 GNUNET_CONTAINER_multihashmap_iterate(extended_neighbors, &free_extended_neighbors, NULL);
2003 GNUNET_CONTAINER_multihashmap_destroy(extended_neighbors);
2004 GNUNET_CONTAINER_multihashmap_iterate(direct_neighbors, &free_direct_neighbors, NULL);
2005 GNUNET_CONTAINER_multihashmap_destroy(direct_neighbors);
2007 GNUNET_CONTAINER_heap_destroy(neighbor_max_heap);
2008 GNUNET_CONTAINER_heap_destroy(neighbor_min_heap);
2010 GNUNET_CORE_disconnect (coreAPI);
2011 GNUNET_PEERINFO_disconnect(peerinfo_handle);
2012 GNUNET_SERVER_mst_destroy(coreMST);
2013 GNUNET_free_non_null(my_short_id);
2015 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "CORE_DISCONNECT completed\n");
2020 * To be called on core init/fail.
2022 void core_init (void *cls,
2023 struct GNUNET_CORE_Handle * server,
2024 const struct GNUNET_PeerIdentity *identity,
2025 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * publicKey)
2030 GNUNET_SCHEDULER_cancel(sched, cleanup_task);
2031 GNUNET_SCHEDULER_add_now(sched, &shutdown_task, NULL);
2035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2036 "%s: Core connection initialized, I am peer: %s\n", "dv", GNUNET_i2s(identity));
2038 memcpy(&my_identity, identity, sizeof(struct GNUNET_PeerIdentity));
2039 my_short_id = GNUNET_strdup(GNUNET_i2s(&my_identity));
2044 #if PKEY_NO_NEIGHBOR_ON_ADD
2046 * Iterator over hash map entries.
2048 * @param cls closure
2049 * @param key current key code
2050 * @param value value in the hash map
2051 * @return GNUNET_YES if we should continue to
2055 static int add_pkey_to_extended (void *cls,
2056 const GNUNET_HashCode * key,
2059 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey = cls;
2060 struct DistantNeighbor *distant_neighbor = value;
2062 if (distant_neighbor->pkey == NULL)
2064 distant_neighbor->pkey = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
2065 memcpy(distant_neighbor->pkey, pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
2073 * Iterator over hash map entries.
2075 * @param cls closure
2076 * @param key current key code
2077 * @param value value in the hash map
2078 * @return GNUNET_YES if we should continue to
2082 static int update_matching_neighbors (void *cls,
2083 const GNUNET_HashCode * key,
2086 struct NeighborUpdateInfo * update_info = cls;
2087 struct DistantNeighbor *distant_neighbor = value;
2089 if (update_info->referrer == distant_neighbor->referrer) /* Direct neighbor matches, update it's info and return GNUNET_NO */
2091 /* same referrer, cost change! */
2092 GNUNET_CONTAINER_heap_update_cost (neighbor_max_heap,
2093 update_info->neighbor->max_loc, update_info->cost);
2094 GNUNET_CONTAINER_heap_update_cost (neighbor_min_heap,
2095 update_info->neighbor->min_loc, update_info->cost);
2096 update_info->neighbor->last_activity = update_info->now;
2097 update_info->neighbor->cost = update_info->cost;
2098 update_info->neighbor->referrer_id = update_info->referrer_peer_id;
2107 * Iterate over all current direct peers, add DISTANT newly connected
2108 * peer to the fast gossip list for that peer so we get DV routing
2109 * information out as fast as possible!
2111 * @param cls the newly connected neighbor we will gossip about
2112 * @param key the hashcode of the peer
2113 * @param value the direct neighbor we should gossip to
2115 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise
2117 static int add_distant_all_direct_neighbors (void *cls,
2118 const GNUNET_HashCode * key,
2121 struct DirectNeighbor *direct = (struct DirectNeighbor *)value;
2122 struct DistantNeighbor *distant = (struct DistantNeighbor *)cls;
2123 struct NeighborSendContext *send_context = direct->send_context;
2124 struct FastGossipNeighborList *gossip_entry;
2130 if (distant == NULL)
2135 if (memcmp(&direct->identity, &distant->identity, sizeof(struct GNUNET_PeerIdentity)) == 0)
2137 return GNUNET_YES; /* Don't gossip to a peer about itself! */
2141 if (distant->hidden == GNUNET_YES)
2142 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */
2144 gossip_entry = GNUNET_malloc(sizeof(struct FastGossipNeighborList));
2145 gossip_entry->about = distant;
2147 GNUNET_CONTAINER_DLL_insert_after(send_context->fast_gossip_list_head,
2148 send_context->fast_gossip_list_tail,
2149 send_context->fast_gossip_list_tail,
2152 encPeerAbout = GNUNET_strdup(GNUNET_i2s(&distant->identity));
2153 encPeerTo = GNUNET_strdup(GNUNET_i2s(&direct->identity));
2155 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Fast send info about peer %s id %u for directly connected peer %s\n",
2156 GNUNET_i2s(&my_identity),
2157 encPeerAbout, distant->our_id, encPeerTo);
2158 GNUNET_free(encPeerAbout);
2159 GNUNET_free(encPeerTo);
2161 /*if (send_context->task != GNUNET_SCHEDULER_NO_TASK)
2162 GNUNET_SCHEDULER_cancel(sched, send_context->task);*/
2164 send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, send_context);
2169 * Callback for hello address creation.
2171 * @param cls closure, a struct HelloContext
2172 * @param max maximum number of bytes that can be written to buf
2173 * @param buf where to write the address information
2175 * @return number of bytes written, 0 to signal the
2176 * end of the iteration.
2179 generate_hello_address (void *cls, size_t max, void *buf)
2181 struct HelloContext *hello_context = cls;
2187 if (hello_context->addresses_to_add == 0)
2190 /* Hello "address" will be concatenation of distant peer and direct peer identities */
2191 size = 2 * sizeof(struct GNUNET_PeerIdentity);
2192 GNUNET_assert(max >= size);
2194 addr_buffer = GNUNET_malloc(size);
2196 /* Copy the distant peer identity to buffer */
2197 memcpy(addr_buffer, &hello_context->distant_peer, sizeof(struct GNUNET_PeerIdentity));
2198 offset += sizeof(struct GNUNET_PeerIdentity);
2199 /* Copy the direct peer identity to buffer */
2200 memcpy(&addr_buffer[offset], hello_context->direct_peer, sizeof(struct GNUNET_PeerIdentity));
2201 ret = GNUNET_HELLO_add_address ("dv",
2202 GNUNET_TIME_relative_to_absolute
2203 (GNUNET_TIME_UNIT_HOURS), addr_buffer, size,
2206 hello_context->addresses_to_add--;
2208 GNUNET_free(addr_buffer);
2214 * Handles when a peer is either added due to being newly connected
2215 * or having been gossiped about, also called when the cost for a neighbor
2216 * needs to be updated.
2218 * @param peer identity of the peer whose info is being added/updated
2219 * @param pkey public key of the peer whose info is being added/updated
2220 * @param referrer_peer_id id to use when sending to 'peer'
2221 * @param referrer if this is a gossiped peer, who did we hear it from?
2222 * @param cost the cost of communicating with this peer via 'referrer'
2224 * @return the added neighbor, the updated neighbor or NULL (neighbor
2227 static struct DistantNeighbor *
2228 addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey,
2229 unsigned int referrer_peer_id,
2230 struct DirectNeighbor *referrer, unsigned int cost)
2232 struct DistantNeighbor *neighbor;
2233 struct DistantNeighbor *max;
2234 struct GNUNET_TIME_Absolute now;
2235 struct NeighborUpdateInfo *neighbor_update;
2236 struct HelloContext *hello_context;
2237 struct GNUNET_HELLO_Message *hello_msg;
2238 unsigned int our_id;
2242 #if DEBUG_DV_PEER_NUMBERS
2244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2245 "%s Received sender id (%u)!\n", "DV SERVICE", referrer_peer_id);
2248 now = GNUNET_TIME_absolute_get ();
2249 neighbor = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
2251 neighbor_update = GNUNET_malloc(sizeof(struct NeighborUpdateInfo));
2252 neighbor_update->neighbor = neighbor;
2253 neighbor_update->cost = cost;
2254 neighbor_update->now = now;
2255 neighbor_update->referrer = referrer;
2256 neighbor_update->referrer_peer_id = referrer_peer_id;
2258 if (neighbor != NULL)
2261 memcpy(&our_id, &neighbor->identity, sizeof(unsigned int));
2263 our_id = neighbor->our_id;
2269 memcpy(&our_id, peer, sizeof(unsigned int));
2271 our_id = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, RAND_MAX - 1) + 1;
2275 /* Either we do not know this peer, or we already do but via a different immediate peer */
2276 if ((neighbor == NULL) ||
2277 (GNUNET_CONTAINER_multihashmap_get_multiple(extended_neighbors,
2279 &update_matching_neighbors,
2280 neighbor_update) != GNUNET_SYSERR))
2284 if ((neighbor != NULL) && (cost < neighbor->cost)) /* New cost is less than old, remove old */
2286 distant_neighbor_free(neighbor);
2288 else if (neighbor != NULL) /* Only allow one DV connection to each peer */
2294 if (cost > fisheye_depth)
2297 GNUNET_free(neighbor_update);
2301 #if DEBUG_DV_PEER_NUMBERS
2302 encAbout = GNUNET_strdup(GNUNET_i2s(peer));
2303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2304 "%s: %s Chose NEW id (%u) for peer %s!\n", GNUNET_i2s(&my_identity), "DV SERVICE", our_id, encAbout);
2305 GNUNET_free(encAbout);
2308 if (max_table_size <=
2309 GNUNET_CONTAINER_multihashmap_size (extended_neighbors))
2311 /* remove most expensive entry */
2312 max = GNUNET_CONTAINER_heap_peek (neighbor_max_heap);
2313 GNUNET_assert(max != NULL);
2314 if (cost > max->cost)
2316 /* new entry most expensive, don't create */
2317 GNUNET_free(neighbor_update);
2322 /* only free if this is not a direct connection;
2323 we could theoretically have more direct
2324 connections than DV entries allowed total! */
2325 distant_neighbor_free (max);
2329 neighbor = GNUNET_malloc (sizeof (struct DistantNeighbor));
2330 GNUNET_CONTAINER_DLL_insert (referrer->referee_head,
2331 referrer->referee_tail, neighbor);
2332 neighbor->max_loc = GNUNET_CONTAINER_heap_insert (neighbor_max_heap,
2334 neighbor->min_loc = GNUNET_CONTAINER_heap_insert (neighbor_min_heap,
2336 neighbor->referrer = referrer;
2337 memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity));
2338 if (pkey != NULL) /* pkey will be null on direct neighbor addition */
2340 neighbor->pkey = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
2341 memcpy (neighbor->pkey, pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
2344 neighbor->pkey = pkey;
2346 neighbor->last_activity = now;
2347 neighbor->cost = cost;
2348 neighbor->referrer_id = referrer_peer_id;
2349 neighbor->our_id = our_id;
2351 (cost == DIRECT_NEIGHBOR_COST) ? (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 4) ==
2354 GNUNET_CONTAINER_multihashmap_put (extended_neighbors, &peer->hashPubKey,
2356 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2358 if (cost != DIRECT_NEIGHBOR_COST)
2360 /* Added neighbor, now send HELLO to transport */
2361 hello_context = GNUNET_malloc(sizeof(struct HelloContext));
2362 hello_context->direct_peer = &referrer->identity;
2363 memcpy(&hello_context->distant_peer, peer, sizeof(struct GNUNET_PeerIdentity));
2364 hello_context->addresses_to_add = 1;
2365 hello_msg = GNUNET_HELLO_create(pkey, &generate_hello_address, hello_context);
2366 GNUNET_assert(memcmp(hello_context->direct_peer, &hello_context->distant_peer, sizeof(struct GNUNET_PeerIdentity)) != 0);
2367 addr1 = GNUNET_strdup(GNUNET_i2s(hello_context->direct_peer));
2368 addr2 = GNUNET_strdup(GNUNET_i2s(&hello_context->distant_peer));
2369 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: GIVING HELLO size %d for %s via %s to TRANSPORT\n", my_short_id, GNUNET_HELLO_size(hello_msg), addr2, addr1);
2372 send_to_plugin(hello_context->direct_peer, GNUNET_HELLO_get_header(hello_msg), GNUNET_HELLO_size(hello_msg), &hello_context->distant_peer, cost);
2373 GNUNET_free(hello_context);
2374 GNUNET_free(hello_msg);
2381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2382 "%s: Already know peer %s distance %d, referrer id %d!\n", "dv", GNUNET_i2s(peer), cost, referrer_peer_id);
2386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2387 "%s: Size of extended_neighbors is %d\n", "dv", GNUNET_CONTAINER_multihashmap_size(extended_neighbors));
2390 GNUNET_free(neighbor_update);
2396 * Core handler for dv disconnect messages. These will be used
2397 * by us to tell transport via the dv plugin that a peer can
2398 * no longer be contacted by us via a certain address. We should
2399 * then propagate these messages on, given that the distance to
2400 * the peer indicates we would have gossiped about it to others.
2402 * @param cls closure
2403 * @param peer peer which sent the message (immediate sender)
2404 * @param message the message
2405 * @param latency the latency of the connection we received the message from
2406 * @param distance the distance to the immediate peer
2408 static int handle_dv_disconnect_message (void *cls,
2409 const struct GNUNET_PeerIdentity *peer,
2410 const struct GNUNET_MessageHeader *message,
2411 struct GNUNET_TIME_Relative latency,
2414 struct DirectNeighbor *referrer;
2415 struct DistantNeighbor *distant;
2416 p2p_dv_MESSAGE_Disconnect *enc_message = (p2p_dv_MESSAGE_Disconnect *)message;
2418 if (ntohs (message->size) < sizeof (p2p_dv_MESSAGE_Disconnect))
2420 return GNUNET_SYSERR; /* invalid message */
2423 referrer = GNUNET_CONTAINER_multihashmap_get (direct_neighbors,
2425 if (referrer == NULL)
2428 distant = referrer->referee_head;
2429 while (distant != NULL)
2431 if (distant->referrer_id == ntohl(enc_message->peer_id))
2433 distant_neighbor_free(distant);
2435 distant = referrer->referee_head;
2443 * Core handler for dv gossip messages. These will be used
2444 * by us to create a HELLO message for the newly peer containing
2445 * which direct peer we can connect through, and what the cost
2446 * is. This HELLO will then be scheduled for validation by the
2447 * transport service so that it can be used by all others.
2449 * @param cls closure
2450 * @param peer peer which sent the message (immediate sender)
2451 * @param message the message
2452 * @param latency the latency of the connection we received the message from
2453 * @param distance the distance to the immediate peer
2455 static int handle_dv_gossip_message (void *cls,
2456 const struct GNUNET_PeerIdentity *peer,
2457 const struct GNUNET_MessageHeader *message,
2458 struct GNUNET_TIME_Relative latency,
2461 struct DirectNeighbor *referrer;
2462 p2p_dv_MESSAGE_NeighborInfo *enc_message = (p2p_dv_MESSAGE_NeighborInfo *)message;
2464 if (ntohs (message->size) < sizeof (p2p_dv_MESSAGE_NeighborInfo))
2466 return GNUNET_SYSERR; /* invalid message */
2469 #if DEBUG_DV_GOSSIP_RECEIPT
2470 char * encPeerAbout;
2473 encPeerAbout = GNUNET_strdup(GNUNET_i2s(&enc_message->neighbor));
2474 encPeerFrom = GNUNET_strdup(GNUNET_i2s(peer));
2475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2476 "%s: Received %s message from peer %s about peer %s id %u distance %d!\n", GNUNET_i2s(&my_identity), "DV GOSSIP", encPeerFrom, encPeerAbout, ntohl(enc_message->neighbor_id), ntohl (enc_message->cost) + 1);
2477 GNUNET_free(encPeerAbout);
2478 GNUNET_free(encPeerFrom);
2481 referrer = GNUNET_CONTAINER_multihashmap_get (direct_neighbors,
2483 if (referrer == NULL)
2486 addUpdateNeighbor (&enc_message->neighbor, &enc_message->pkey,
2487 ntohl (enc_message->neighbor_id),
2488 referrer, ntohl (enc_message->cost) + 1);
2495 * Iterate over all currently known peers, add them to the
2496 * fast gossip list for this peer so we get DV routing information
2497 * out as fast as possible!
2499 * @param cls the direct neighbor we will gossip to
2500 * @param key the hashcode of the peer
2501 * @param value the distant neighbor we should add to the list
2503 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise
2505 static int add_all_extended_peers (void *cls,
2506 const GNUNET_HashCode * key,
2509 struct NeighborSendContext *send_context = (struct NeighborSendContext *)cls;
2510 struct DistantNeighbor *distant = (struct DistantNeighbor *)value;
2511 struct FastGossipNeighborList *gossip_entry;
2513 if (memcmp(&send_context->toNeighbor->identity, &distant->identity, sizeof(struct GNUNET_PeerIdentity)) == 0)
2514 return GNUNET_YES; /* Don't gossip to a peer about itself! */
2517 if (distant->hidden == GNUNET_YES)
2518 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */
2520 gossip_entry = GNUNET_malloc(sizeof(struct FastGossipNeighborList));
2521 gossip_entry->about = distant;
2523 GNUNET_CONTAINER_DLL_insert_after(send_context->fast_gossip_list_head,
2524 send_context->fast_gossip_list_tail,
2525 send_context->fast_gossip_list_tail,
2533 * Iterator over hash map entries.
2535 * @param cls closure
2536 * @param key current key code
2537 * @param value value in the hash map
2538 * @return GNUNET_YES if we should continue to
2542 static int gossip_all_to_all_iterator (void *cls,
2543 const GNUNET_HashCode * key,
2546 struct DirectNeighbor *direct = value;
2548 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &add_all_extended_peers, direct->send_context);
2550 if (direct->send_context->task != GNUNET_SCHEDULER_NO_TASK)
2551 GNUNET_SCHEDULER_cancel(sched, direct->send_context->task);
2553 direct->send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, direct->send_context);
2558 * Task run during shutdown.
2564 gossip_all_to_all (void *cls,
2565 const struct GNUNET_SCHEDULER_TaskContext *tc)
2567 GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors, &gossip_all_to_all_iterator, NULL);
2569 GNUNET_SCHEDULER_add_delayed (sched,
2570 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
2577 * Iterate over all current direct peers, add newly connected peer
2578 * to the fast gossip list for that peer so we get DV routing
2579 * information out as fast as possible!
2581 * @param cls the newly connected neighbor we will gossip about
2582 * @param key the hashcode of the peer
2583 * @param value the direct neighbor we should gossip to
2585 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise
2587 static int add_all_direct_neighbors (void *cls,
2588 const GNUNET_HashCode * key,
2591 struct DirectNeighbor *direct = (struct DirectNeighbor *)value;
2592 struct DirectNeighbor *to = (struct DirectNeighbor *)cls;
2593 struct DistantNeighbor *distant;
2594 struct NeighborSendContext *send_context = direct->send_context;
2595 struct FastGossipNeighborList *gossip_entry;
2599 distant = GNUNET_CONTAINER_multihashmap_get(extended_neighbors, &to->identity.hashPubKey);
2600 if (distant == NULL)
2605 if (memcmp(&direct->identity, &to->identity, sizeof(struct GNUNET_PeerIdentity)) == 0)
2607 return GNUNET_YES; /* Don't gossip to a peer about itself! */
2611 if (distant->hidden == GNUNET_YES)
2612 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */
2614 direct_id = GNUNET_strdup(GNUNET_i2s(&direct->identity));
2616 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: adding peer %s to fast send list for %s\n", my_short_id, GNUNET_i2s(&distant->identity), direct_id);
2618 GNUNET_free(direct_id);
2619 gossip_entry = GNUNET_malloc(sizeof(struct FastGossipNeighborList));
2620 gossip_entry->about = distant;
2622 GNUNET_CONTAINER_DLL_insert_after(send_context->fast_gossip_list_head,
2623 send_context->fast_gossip_list_tail,
2624 send_context->fast_gossip_list_tail,
2626 if (send_context->task != GNUNET_SCHEDULER_NO_TASK)
2627 GNUNET_SCHEDULER_cancel(sched, send_context->task);
2629 send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, send_context);
2630 //tc.reason = GNUNET_SCHEDULER_REASON_TIMEOUT;
2631 //neighbor_send_task(send_context, &tc);
2636 * Type of an iterator over the hosts. Note that each
2637 * host will be called with each available protocol.
2639 * @param cls closure
2640 * @param peer id of the peer, NULL for last call
2641 * @param hello hello message for the peer (can be NULL)
2642 * @param trust amount of trust we have in the peer
2645 process_peerinfo (void *cls,
2646 const struct GNUNET_PeerIdentity *peer,
2647 const struct GNUNET_HELLO_Message *hello, uint32_t trust)
2649 struct PeerIteratorContext *peerinfo_iterator = cls;
2650 struct DirectNeighbor *neighbor = peerinfo_iterator->neighbor;
2651 struct DistantNeighbor *distant = peerinfo_iterator->distant;
2652 #if DEBUG_DV_PEER_NUMBERS
2659 if (distant->pkey == NULL)
2662 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to get peerinfo information for this peer, retrying!\n");
2664 peerinfo_iterator->ic = GNUNET_PEERINFO_iterate(peerinfo_handle,
2665 &peerinfo_iterator->neighbor->identity,
2667 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3),
2673 GNUNET_free(peerinfo_iterator);
2678 if (memcmp(&neighbor->identity, peer, sizeof(struct GNUNET_PeerIdentity) != 0))
2681 if ((hello != NULL) && (GNUNET_HELLO_get_key (hello, &neighbor->pkey) == GNUNET_OK))
2683 if (distant->pkey == NULL)
2685 distant->pkey = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
2686 memcpy(distant->pkey, &neighbor->pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
2689 sent = GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &add_all_extended_peers, neighbor->send_context);
2691 #if DEBUG_DV_PEER_NUMBERS
2692 neighbor_pid = GNUNET_strdup(GNUNET_i2s(&neighbor->identity));
2693 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Gossipped %d extended peers to %s\n", GNUNET_i2s(&my_identity), sent, neighbor_pid);
2695 sent = GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors, &add_all_direct_neighbors, neighbor);
2696 #if DEBUG_DV_PEER_NUMBERS
2697 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Gossipped about %s to %d direct peers\n", GNUNET_i2s(&my_identity), neighbor_pid, sent);
2698 GNUNET_free(neighbor_pid);
2700 neighbor->send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, neighbor->send_context);
2706 * Method called whenever a peer connects.
2708 * @param cls closure
2709 * @param peer peer identity this notification is about
2710 * @param latency reported latency of the connection with peer
2711 * @param distance reported distance (DV) to peer
2713 void handle_core_connect (void *cls,
2714 const struct GNUNET_PeerIdentity * peer,
2715 struct GNUNET_TIME_Relative latency,
2718 struct DirectNeighbor *neighbor;
2719 struct DistantNeighbor *about;
2720 struct PeerIteratorContext *peerinfo_iterator;
2723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2724 "%s: Receives core connect message for peer %s distance %d!\n", "dv", GNUNET_i2s(peer), distance);
2727 if ((distance == DIRECT_NEIGHBOR_COST) && (GNUNET_CONTAINER_multihashmap_get(direct_neighbors, &peer->hashPubKey) == NULL))
2729 peerinfo_iterator = GNUNET_malloc(sizeof(struct PeerIteratorContext));
2730 neighbor = GNUNET_malloc (sizeof (struct DirectNeighbor));
2731 neighbor->send_context = GNUNET_malloc(sizeof(struct NeighborSendContext));
2732 neighbor->send_context->toNeighbor = neighbor;
2733 memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity));
2735 GNUNET_assert(GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_put (direct_neighbors,
2737 neighbor, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2738 about = addUpdateNeighbor (peer, NULL, 0, neighbor, DIRECT_NEIGHBOR_COST);
2739 peerinfo_iterator->distant = about;
2740 peerinfo_iterator->neighbor = neighbor;
2741 peerinfo_iterator->ic = GNUNET_PEERINFO_iterate (peerinfo_handle,
2744 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3),
2748 if ((about != NULL) && (about->pkey == NULL))
2751 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Newly added peer %s has NULL pkey!\n", GNUNET_i2s(peer));
2754 else if (about != NULL)
2756 GNUNET_free(peerinfo_iterator);
2761 about = GNUNET_CONTAINER_multihashmap_get(extended_neighbors, &peer->hashPubKey);
2762 if ((GNUNET_CONTAINER_multihashmap_get(direct_neighbors, &peer->hashPubKey) == NULL) && (about != NULL))
2763 sent = GNUNET_CONTAINER_multihashmap_iterate(direct_neighbors, &add_distant_all_direct_neighbors, about);
2765 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2766 "%s: Distance (%d) greater than %d or already know about peer (%s), not re-adding!\n", "dv", distance, DIRECT_NEIGHBOR_COST, GNUNET_i2s(peer));
2773 * Method called whenever a given peer disconnects.
2775 * @param cls closure
2776 * @param peer peer identity this notification is about
2778 void handle_core_disconnect (void *cls,
2779 const struct GNUNET_PeerIdentity * peer)
2781 struct DirectNeighbor *neighbor;
2782 struct DistantNeighbor *referee;
2783 struct FindDestinationContext fdc;
2784 struct DisconnectContext disconnect_context;
2787 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2788 "%s: Receives core peer disconnect message!\n", "dv");
2792 GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey);
2793 if (neighbor == NULL)
2797 while (NULL != (referee = neighbor->referee_head))
2798 distant_neighbor_free (referee);
2803 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &find_distant_peer, &fdc);
2805 if (fdc.dest != NULL)
2807 disconnect_context.direct = neighbor;
2808 disconnect_context.distant = fdc.dest;
2809 GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors, &schedule_disconnect_messages, &disconnect_context);
2812 GNUNET_assert (neighbor->referee_tail == NULL);
2813 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (direct_neighbors,
2814 &peer->hashPubKey, neighbor))
2818 if ((neighbor->send_context != NULL) && (neighbor->send_context->task != GNUNET_SCHEDULER_NO_TASK))
2819 GNUNET_SCHEDULER_cancel(sched, neighbor->send_context->task);
2820 GNUNET_free (neighbor);
2825 * Process dv requests.
2827 * @param cls closure
2828 * @param scheduler scheduler to use
2829 * @param server the initialized server
2830 * @param c configuration to use
2834 struct GNUNET_SCHEDULER_Handle *scheduler,
2835 struct GNUNET_SERVER_Handle *server,
2836 const struct GNUNET_CONFIGURATION_Handle *c)
2838 unsigned long long max_hosts;
2842 /* FIXME: Read from config, or calculate, or something other than this! */
2843 max_hosts = DEFAULT_DIRECT_CONNECTIONS;
2844 max_table_size = DEFAULT_DV_SIZE;
2845 fisheye_depth = DEFAULT_FISHEYE_DEPTH;
2847 if (GNUNET_CONFIGURATION_have_value(cfg, "dv", "max_direct_connections"))
2848 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "dv", "max_direct_connections", &max_hosts));
2850 if (GNUNET_CONFIGURATION_have_value(cfg, "dv", "max_total_connections"))
2851 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "dv", "max_total_connections", &max_table_size));
2854 if (GNUNET_CONFIGURATION_have_value(cfg, "dv", "fisheye_depth"))
2855 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "dv", "fisheye_depth", &fisheye_depth));
2858 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
2860 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
2862 direct_neighbors = GNUNET_CONTAINER_multihashmap_create (max_hosts);
2863 extended_neighbors =
2864 GNUNET_CONTAINER_multihashmap_create (max_table_size * 3);
2866 GNUNET_SERVER_add_handlers (server, plugin_handlers);
2868 GNUNET_CORE_connect (sched,
2870 GNUNET_TIME_relative_get_forever(),
2871 NULL, /* FIXME: anything we want to pass around? */
2873 &handle_core_connect,
2874 &handle_core_disconnect,
2881 if (coreAPI == NULL)
2884 coreMST = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE,
2885 &tokenized_message_handler,
2888 peerinfo_handle = GNUNET_PEERINFO_connect(sched, cfg);
2890 if (peerinfo_handle == NULL)
2892 GNUNET_CORE_disconnect(coreAPI);
2896 /* Scheduled the task to clean up when shutdown is called */
2897 cleanup_task = GNUNET_SCHEDULER_add_delayed (sched,
2898 GNUNET_TIME_UNIT_FOREVER_REL,
2902 GNUNET_SCHEDULER_add_delayed (sched,
2903 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
2911 * The main function for the dv service.
2913 * @param argc number of arguments from the command line
2914 * @param argv command line arguments
2915 * @return 0 ok, 1 on error
2918 main (int argc, char *const *argv)
2920 return (GNUNET_OK ==
2921 GNUNET_SERVICE_run (argc,
2924 GNUNET_SERVICE_OPTION_NONE,
2925 &run, NULL)) ? 0 : 1;