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 3, 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 transport/gnunet-service-transport.c
23 * @brief low-level P2P messaging
24 * @author Christian Grothoff
28 #include "gnunet_client_lib.h"
29 #include "gnunet_container_lib.h"
30 #include "gnunet_constants.h"
31 #include "gnunet_getopt_lib.h"
32 #include "gnunet_hello_lib.h"
33 #include "gnunet_os_lib.h"
34 #include "gnunet_peerinfo_service.h"
35 #include "gnunet_plugin_lib.h"
36 #include "gnunet_protocols.h"
37 #include "gnunet_service_lib.h"
38 #include "gnunet_signatures.h"
39 #include "plugin_transport.h"
40 #include "transport.h"
42 #define DEBUG_BLACKLIST GNUNET_NO
44 #define DEBUG_PING_PONG GNUNET_NO
46 #define DEBUG_TRANSPORT_HELLO GNUNET_NO
49 * Should we do some additional checks (to validate behavior
52 #define EXTRA_CHECKS GNUNET_YES
55 * How many messages can we have pending for a given client process
56 * before we start to drop incoming messages? We typically should
57 * have only one client and so this would be the primary buffer for
58 * messages, so the number should be chosen rather generously.
60 * The expectation here is that most of the time the queue is large
61 * enough so that a drop is virtually never required. Note that
62 * this value must be about as large as 'TOTAL_MSGS' in the
63 * 'test_transport_api_reliability.c', otherwise that testcase may
66 #define MAX_PENDING (128 * 1024)
69 * Size of the per-transport blacklist hash maps.
71 #define TRANSPORT_BLACKLIST_HT_SIZE 16
74 * How often should we try to reconnect to a peer using a particular
75 * transport plugin before giving up? Note that the plugin may be
76 * added back to the list after PLUGIN_RETRY_FREQUENCY expires.
78 #define MAX_CONNECT_RETRY 3
81 * Limit on the number of ready-to-run tasks when validating
82 * HELLOs. If more tasks are ready to run, we will drop
83 * HELLOs instead of validating them.
85 #define MAX_HELLO_LOAD 4
88 * How often must a peer violate bandwidth quotas before we start
89 * to simply drop its messages?
91 #define QUOTA_VIOLATION_DROP_THRESHOLD 10
94 * How long until a HELLO verification attempt should time out?
95 * Must be rather small, otherwise a partially successful HELLO
96 * validation (some addresses working) might not be available
97 * before a client's request for a connection fails for good.
98 * Besides, if a single request to an address takes a long time,
99 * then the peer is unlikely worthwhile anyway.
101 #define HELLO_VERIFICATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
104 * How long is a PONG signature valid? We'll recycle a signature until
105 * 1/4 of this time is remaining. PONGs should expire so that if our
106 * external addresses change an adversary cannot replay them indefinitely.
107 * OTOH, we don't want to spend too much time generating PONG signatures,
108 * so they must have some lifetime to reduce our CPU usage.
110 #define PONG_SIGNATURE_LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
113 * Priority to use for PONG messages.
115 #define TRANSPORT_PONG_PRIORITY 4
118 * How often do we re-add (cheaper) plugins to our list of plugins
119 * to try for a given connected peer?
121 #define PLUGIN_RETRY_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
124 * After how long do we expire an address in a HELLO that we just
125 * validated? This value is also used for our own addresses when we
128 #define HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12)
132 * How long before an existing address expires should we again try to
133 * validate it? Must be (significantly) smaller than
134 * HELLO_ADDRESS_EXPIRATION.
136 #define HELLO_REVALIDATION_START_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
139 * Maximum frequency for re-evaluating latencies for all transport addresses.
141 #define LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
144 * Maximum frequency for re-evaluating latencies for connected addresses.
146 #define CONNECTED_LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
150 * List of addresses of other peers
152 struct ForeignAddressList
155 * This is a linked list.
157 struct ForeignAddressList *next;
160 * Which ready list does this entry belong to.
162 struct ReadyList *ready_list;
165 * How long until we auto-expire this address (unless it is
166 * re-confirmed by the transport)?
168 struct GNUNET_TIME_Absolute expires;
171 * Task used to re-validate addresses, updates latencies and
174 GNUNET_SCHEDULER_TaskIdentifier revalidate_task;
182 * Session (or NULL if no valid session currently exists or if the
183 * plugin does not use sessions).
185 struct Session *session;
188 * What was the last latency observed for this address, plugin and peer?
190 struct GNUNET_TIME_Relative latency;
193 * If we did not successfully transmit a message to the given peer
194 * via this connection during the specified time, we should consider
195 * the connection to be dead. This is used in the case that a TCP
196 * transport simply stalls writing to the stream but does not
197 * formerly get a signal that the other peer died.
199 struct GNUNET_TIME_Absolute timeout;
202 * How often have we tried to connect using this plugin? Used to
203 * discriminate against addresses that do not work well.
204 * FIXME: not yet used, but should be!
206 unsigned int connect_attempts;
209 * DV distance to this peer (1 if no DV is used).
210 * FIXME: need to set this from transport plugins!
220 * Have we ever estimated the latency of this address? Used to
221 * ensure that the first time we add an address, we immediately
227 * Are we currently connected via this address? The first time we
228 * successfully transmit or receive data to a peer via a particular
229 * address, we set this to GNUNET_YES. If we later get an error
230 * (disconnect notification, transmission failure, timeout), we set
231 * it back to GNUNET_NO.
236 * Is this plugin currently busy transmitting to the specific target?
237 * GNUNET_NO if not (initial, default state is GNUNET_NO). Internal
238 * messages do not count as 'in transmit'.
243 * Has this address been validated yet?
251 * Entry in linked list of network addresses for ourselves. Also
252 * includes a cached signature for 'struct TransportPongMessage's.
254 struct OwnAddressList
257 * This is a linked list.
259 struct OwnAddressList *next;
262 * How long until we actually auto-expire this address (unless it is
263 * re-confirmed by the transport)?
265 struct GNUNET_TIME_Absolute expires;
268 * How long until the current signature expires? (ZERO if the
269 * signature was never created).
271 struct GNUNET_TIME_Absolute pong_sig_expires;
274 * Signature for a 'struct TransportPongMessage' for this address.
276 struct GNUNET_CRYPTO_RsaSignature pong_signature;
287 * Entry in linked list of all of our plugins.
289 struct TransportPlugin
293 * This is a linked list.
295 struct TransportPlugin *next;
298 * API of the transport as returned by the plugin's
299 * initialization function.
301 struct GNUNET_TRANSPORT_PluginFunctions *api;
304 * Short name for the plugin (i.e. "tcp").
309 * Name of the library (i.e. "gnunet_plugin_transport_tcp").
314 * List of our known addresses for this transport.
316 struct OwnAddressList *addresses;
319 * Environment this transport service is using
322 struct GNUNET_TRANSPORT_PluginEnvironment env;
325 * ID of task that is used to clean up expired addresses.
327 GNUNET_SCHEDULER_TaskIdentifier address_update_task;
330 * Set to GNUNET_YES if we need to scrap the existing list of
331 * "addresses" and start fresh when we receive the next address
332 * update from a transport. Set to GNUNET_NO if we should just add
333 * the new address to the list and wait for the commit call.
338 * Hashmap of blacklisted peers for this particular transport.
340 struct GNUNET_CONTAINER_MultiHashMap *blacklist;
343 struct NeighbourList;
346 * For each neighbour we keep a list of messages
347 * that we still want to transmit to the neighbour.
353 * This is a doubly linked list.
355 struct MessageQueue *next;
358 * This is a doubly linked list.
360 struct MessageQueue *prev;
363 * The message(s) we want to transmit, GNUNET_MessageHeader(s)
364 * stuck together in memory. Allocated at the end of this struct.
366 const char *message_buf;
369 * Size of the message buf
371 size_t message_buf_size;
374 * Client responsible for queueing the message;
375 * used to check that a client has no two messages
376 * pending for the same target. Can be NULL.
378 struct TransportClient *client;
381 * Using which specific address should we send this message?
383 struct ForeignAddressList *specific_address;
386 * Peer ID of the Neighbour this entry belongs to.
388 struct GNUNET_PeerIdentity neighbour_id;
391 * Plugin that we used for the transmission.
392 * NULL until we scheduled a transmission.
394 struct TransportPlugin *plugin;
397 * At what time should we fail?
399 struct GNUNET_TIME_Absolute timeout;
402 * Internal message of the transport system that should not be
403 * included in the usual SEND-SEND_OK transmission confirmation
404 * traffic management scheme. Typically, "internal_msg" will
405 * be set whenever "client" is NULL (but it is not strictly
411 * How important is the message?
413 unsigned int priority;
419 * For a given Neighbour, which plugins are available
420 * to talk to this peer and what are their costs?
425 * This is a linked list.
427 struct ReadyList *next;
430 * Which of our transport plugins does this entry
433 struct TransportPlugin *plugin;
436 * Transport addresses, latency, and readiness for
437 * this particular plugin.
439 struct ForeignAddressList *addresses;
442 * To which neighbour does this ready list belong to?
444 struct NeighbourList *neighbour;
450 * Entry in linked list of all of our current neighbours.
456 * This is a linked list.
458 struct NeighbourList *next;
461 * Which of our transports is connected to this peer
462 * and what is their status?
464 struct ReadyList *plugins;
467 * Head of list of messages we would like to send to this peer;
468 * must contain at most one message per client.
470 struct MessageQueue *messages_head;
473 * Tail of list of messages we would like to send to this peer; must
474 * contain at most one message per client.
476 struct MessageQueue *messages_tail;
479 * Buffer for at most one payload message used when we receive
480 * payload data before our PING-PONG has succeeded. We then
481 * store such messages in this intermediary buffer until the
482 * connection is fully up.
484 struct GNUNET_MessageHeader *pre_connect_message_buffer;
487 * Context for peerinfo iteration.
488 * NULL after we are done processing peerinfo's information.
490 struct GNUNET_PEERINFO_IteratorContext *piter;
493 * Public key for this peer. Valid only if the respective flag is set below.
495 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded publicKey;
498 * Identity of this neighbour.
500 struct GNUNET_PeerIdentity id;
503 * ID of task scheduled to run when this peer is about to
504 * time out (will free resources associated with the peer).
506 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
509 * ID of task scheduled to run when we should retry transmitting
510 * the head of the message queue. Actually triggered when the
511 * transmission is timing out (we trigger instantly when we have
512 * a chance of success).
514 GNUNET_SCHEDULER_TaskIdentifier retry_task;
517 * How long until we should consider this peer dead
518 * (if we don't receive another message in the
521 struct GNUNET_TIME_Absolute peer_timeout;
524 * Tracker for inbound bandwidth.
526 struct GNUNET_BANDWIDTH_Tracker in_tracker;
529 * The latency we have seen for this particular address for
530 * this particular peer. This latency may have been calculated
531 * over multiple transports. This value reflects how long it took
532 * us to receive a response when SENDING via this particular
533 * transport/neighbour/address combination!
535 * FIXME: we need to periodically send PINGs to update this
536 * latency (at least more often than the current "huge" (11h?)
539 struct GNUNET_TIME_Relative latency;
542 * How often has the other peer (recently) violated the
543 * inbound traffic limit? Incremented by 10 per violation,
544 * decremented by 1 per non-violation (for each
547 unsigned int quota_violation_count;
550 * DV distance to this peer (1 if no DV is used).
555 * Have we seen an PONG from this neighbour in the past (and
556 * not had a disconnect since)?
561 * Do we have a valid public key for this neighbour?
563 int public_key_valid;
568 * Message used to ask a peer to validate receipt (to check an address
569 * from a HELLO). Followed by the address we are trying to validate,
570 * or an empty address if we are just sending a PING to confirm that a
571 * connection which the receiver (of the PING) initiated is still valid.
573 struct TransportPingMessage
577 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_PING
579 struct GNUNET_MessageHeader header;
582 * Challenge code (to ensure fresh reply).
584 uint32_t challenge GNUNET_PACKED;
587 * Who is the intended recipient?
589 struct GNUNET_PeerIdentity target;
595 * Message used to validate a HELLO. The challenge is included in the
596 * confirmation to make matching of replies to requests possible. The
597 * signature signs our public key, an expiration time and our address.<p>
599 * This message is followed by our transport address that the PING tried
600 * to confirm (if we liked it). The address can be empty (zero bytes)
601 * if the PING had not address either (and we received the request via
602 * a connection that we initiated).
604 struct TransportPongMessage
608 * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_PONG
610 struct GNUNET_MessageHeader header;
613 * Challenge code from PING (showing freshness). Not part of what
614 * is signed so that we can re-use signatures.
616 uint32_t challenge GNUNET_PACKED;
621 struct GNUNET_CRYPTO_RsaSignature signature;
624 * What are we signing and why? Two possible reason codes can be here:
625 * GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN to confirm that this is a
626 * plausible address for this peer (pid is set to identity of signer); or
627 * GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING to confirm that this is
628 * an address we used to connect to the peer with the given pid.
630 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
633 * When does this signature expire?
635 struct GNUNET_TIME_AbsoluteNBO expiration;
638 * Either the identity of the peer Who signed this message, or the
639 * identity of the peer that we're connected to using the given
640 * address (depending on purpose.type).
642 struct GNUNET_PeerIdentity pid;
645 * Size of address appended to this message (part of what is
646 * being signed, hence not redundant).
654 * Linked list of messages to be transmitted to the client. Each
655 * entry is followed by the actual message.
657 struct ClientMessageQueueEntry
660 * This is a doubly-linked list.
662 struct ClientMessageQueueEntry *next;
665 * This is a doubly-linked list.
667 struct ClientMessageQueueEntry *prev;
672 * Client connected to the transport service.
674 struct TransportClient
678 * This is a linked list.
680 struct TransportClient *next;
683 * Handle to the client.
685 struct GNUNET_SERVER_Client *client;
688 * Linked list of messages yet to be transmitted to
691 struct ClientMessageQueueEntry *message_queue_head;
694 * Tail of linked list of messages yet to be transmitted to the
697 struct ClientMessageQueueEntry *message_queue_tail;
700 * Current transmit request handle.
702 struct GNUNET_CONNECTION_TransmitHandle *th;
705 * Is a call to "transmit_send_continuation" pending? If so, we
706 * must not free this struct (even if the corresponding client
707 * disconnects) and instead only remove it from the linked list and
708 * set the "client" field to NULL.
713 * Length of the list of messages pending for this client.
715 unsigned int message_count;
721 * Context of currently active requests to peerinfo
722 * for validation of HELLOs.
724 struct CheckHelloValidatedContext;
728 * Entry in map of all HELLOs awaiting validation.
730 struct ValidationEntry
734 * NULL if this entry is not part of a larger HELLO validation.
736 struct CheckHelloValidatedContext *chvc;
739 * The address, actually a pointer to the end
740 * of this struct. Do not free!
745 * Name of the transport.
747 char *transport_name;
750 * The public key of the peer.
752 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded publicKey;
755 * ID of task that will clean up this entry if we don't succeed
756 * with the validation first.
758 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
761 * At what time did we send this validation?
763 struct GNUNET_TIME_Absolute send_time;
766 * Session being validated (or NULL for none).
768 struct Session *session;
771 * Challenge number we used.
784 * Context of currently active requests to peerinfo
785 * for validation of HELLOs.
787 struct CheckHelloValidatedContext
791 * This is a doubly-linked list.
793 struct CheckHelloValidatedContext *next;
796 * This is a doubly-linked list.
798 struct CheckHelloValidatedContext *prev;
801 * Hello that we are validating.
803 const struct GNUNET_HELLO_Message *hello;
806 * Context for peerinfo iteration.
807 * NULL after we are done processing peerinfo's information.
809 struct GNUNET_PEERINFO_IteratorContext *piter;
812 * Was a HELLO known for this peer to peerinfo?
817 * Number of validation entries currently referring to this
820 unsigned int ve_count;
828 static struct GNUNET_HELLO_Message *our_hello;
833 static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
838 static struct GNUNET_PeerIdentity my_identity;
843 static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
848 struct GNUNET_SCHEDULER_Handle *sched;
853 const struct GNUNET_CONFIGURATION_Handle *cfg;
856 * Linked list of all clients to this service.
858 static struct TransportClient *clients;
861 * All loaded plugins.
863 static struct TransportPlugin *plugins;
866 * Handle to peerinfo service.
868 static struct GNUNET_PEERINFO_Handle *peerinfo;
871 * All known neighbours and their HELLOs.
873 static struct NeighbourList *neighbours;
876 * Number of neighbours we'd like to have.
878 static uint32_t max_connect_per_transport;
881 * Head of linked list.
883 static struct CheckHelloValidatedContext *chvc_head;
886 * Tail of linked list.
888 static struct CheckHelloValidatedContext *chvc_tail;
891 * Map of PeerIdentities to 'struct ValidationEntry*'s (addresses
892 * of the given peer that we are currently validating).
894 static struct GNUNET_CONTAINER_MultiHashMap *validation_map;
897 * Handle for reporting statistics.
899 static struct GNUNET_STATISTICS_Handle *stats;
902 * The peer specified by the given neighbour has timed-out or a plugin
903 * has disconnected. We may either need to do nothing (other plugins
904 * still up), or trigger a full disconnect and clean up. This
905 * function updates our state and do the necessary notifications.
906 * Also notifies our clients that the neighbour is now officially
909 * @param n the neighbour list entry for the peer
910 * @param check should we just check if all plugins
911 * disconnected or must we ask all plugins to
914 static void disconnect_neighbour (struct NeighbourList *n, int check);
917 * Check the ready list for the given neighbour and if a plugin is
918 * ready for transmission (and if we have a message), do so!
920 * @param neighbour target peer for which to transmit
922 static void try_transmission_to_peer (struct NeighbourList *neighbour);
926 * Find an entry in the neighbour list for a particular peer.
928 * @return NULL if not found.
930 static struct NeighbourList *
931 find_neighbour (const struct GNUNET_PeerIdentity *key)
933 struct NeighbourList *head = neighbours;
935 while ((head != NULL) &&
936 (0 != memcmp (key, &head->id, sizeof (struct GNUNET_PeerIdentity))))
943 * Find an entry in the transport list for a particular transport.
945 * @return NULL if not found.
947 static struct TransportPlugin *
948 find_transport (const char *short_name)
950 struct TransportPlugin *head = plugins;
951 while ((head != NULL) && (0 != strcmp (short_name, head->short_name)))
957 * Is a particular peer blacklisted for a particular transport?
959 * @param peer the peer to check for
960 * @param plugin the plugin used to connect to the peer
962 * @return GNUNET_YES if the peer is blacklisted, GNUNET_NO if not
965 is_blacklisted (const struct GNUNET_PeerIdentity *peer, struct TransportPlugin *plugin)
968 if (plugin->blacklist != NULL)
970 if (GNUNET_CONTAINER_multihashmap_contains(plugin->blacklist, &peer->hashPubKey) == GNUNET_YES)
973 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
974 _("Peer `%s:%s' is blacklisted!\n"),
975 plugin->short_name, GNUNET_i2s (peer));
986 add_peer_to_blacklist (struct GNUNET_PeerIdentity *peer, char *transport_name)
988 struct TransportPlugin *plugin;
990 plugin = find_transport(transport_name);
991 if (plugin == NULL) /* Nothing to do */
993 if (plugin->blacklist == NULL)
994 plugin->blacklist = GNUNET_CONTAINER_multihashmap_create(TRANSPORT_BLACKLIST_HT_SIZE);
995 GNUNET_assert(plugin->blacklist != NULL);
996 GNUNET_CONTAINER_multihashmap_put(plugin->blacklist, &peer->hashPubKey,
998 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
1003 * Read the blacklist file, containing transport:peer entries.
1004 * Provided the transport is loaded, set up hashmap with these
1005 * entries to blacklist peers by transport.
1009 read_blacklist_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
1016 struct GNUNET_PeerIdentity pid;
1018 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
1019 unsigned int entries_found;
1020 char *transport_name;
1023 GNUNET_CONFIGURATION_get_value_filename (cfg,
1029 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1030 _("Option `%s' in section `%s' not specified!\n"),
1036 if (GNUNET_OK != GNUNET_DISK_file_test (fn))
1037 GNUNET_DISK_fn_write (fn, NULL, 0, GNUNET_DISK_PERM_USER_READ
1038 | GNUNET_DISK_PERM_USER_WRITE);
1039 if (0 != STAT (fn, &frstat))
1041 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1042 _("Could not read blacklist file `%s'\n"), fn);
1046 if (frstat.st_size == 0)
1049 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1050 _("Blacklist file `%s' is empty.\n"),
1056 /* FIXME: use mmap */
1057 data = GNUNET_malloc_large (frstat.st_size);
1058 GNUNET_assert(data != NULL);
1059 if (frstat.st_size !=
1060 GNUNET_DISK_fn_read (fn, data, frstat.st_size))
1062 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1063 _("Failed to read blacklist from `%s'\n"), fn);
1070 while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
1072 while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) &&
1073 (pos <= frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)))
1076 while ((colon_pos < frstat.st_size) && (data[colon_pos] != ':') && !isspace ( (unsigned char) data[colon_pos]))
1079 if (colon_pos >= frstat.st_size)
1081 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1082 _("Syntax error in blacklist file at offset %llu, giving up!\n"),
1083 (unsigned long long) colon_pos);
1089 if (isspace( (unsigned char) data[colon_pos]))
1091 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1092 _("Syntax error in blacklist file at offset %llu, skipping bytes.\n"),
1093 (unsigned long long) colon_pos);
1095 while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
1099 tsize = colon_pos - pos;
1100 if ((pos >= frstat.st_size) || (pos + tsize >= frstat.st_size) || (tsize == 0))
1102 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1103 _("Syntax error in blacklist file at offset %llu, giving up!\n"),
1104 (unsigned long long) colon_pos);
1113 transport_name = GNUNET_malloc(tsize + 1);
1114 memcpy(transport_name, &data[pos], tsize);
1115 pos = colon_pos + 1;
1117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1118 _("Read transport name %s in blacklist file.\n"),
1121 memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
1122 if (!isspace ( (unsigned char) enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1]))
1124 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1125 _("Syntax error in blacklist file at offset %llu, skipping bytes.\n"),
1126 (unsigned long long) pos);
1128 while ((pos < frstat.st_size) && (!isspace ( (unsigned char) data[pos])))
1130 GNUNET_free_non_null(transport_name);
1133 enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
1134 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char *) &enc, &pid.hashPubKey))
1136 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1137 _("Syntax error in blacklist file at offset %llu, skipping bytes `%s'.\n"),
1138 (unsigned long long) pos,
1143 if (0 != memcmp (&pid,
1145 sizeof (struct GNUNET_PeerIdentity)))
1148 add_peer_to_blacklist (&pid,
1153 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1154 _("Found myself `%s' in blacklist (useless, ignored)\n"),
1158 pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded);
1159 GNUNET_free_non_null(transport_name);
1160 while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
1169 * Function called to notify a client about the socket being ready to
1170 * queue more data. "buf" will be NULL and "size" zero if the socket
1171 * was closed for writing in the meantime.
1173 * @param cls closure
1174 * @param size number of bytes available in buf
1175 * @param buf where the callee should write the message
1176 * @return number of bytes written to buf
1179 transmit_to_client_callback (void *cls, size_t size, void *buf)
1181 struct TransportClient *client = cls;
1182 struct ClientMessageQueueEntry *q;
1185 const struct GNUNET_MessageHeader *msg;
1191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1192 "Transmission to client failed, closing connection.\n");
1193 /* fatal error with client, free message queue! */
1194 while (NULL != (q = client->message_queue_head))
1196 GNUNET_STATISTICS_update (stats,
1197 gettext_noop ("# bytes discarded (could not transmit to client)"),
1198 ntohs (((const struct GNUNET_MessageHeader*)&q[1])->size),
1200 GNUNET_CONTAINER_DLL_remove (client->message_queue_head,
1201 client->message_queue_tail,
1205 client->message_count = 0;
1210 while (NULL != (q = client->message_queue_head))
1212 msg = (const struct GNUNET_MessageHeader *) &q[1];
1213 msize = ntohs (msg->size);
1214 if (msize + tsize > size)
1217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1218 "Transmitting message of type %u to client.\n",
1221 GNUNET_CONTAINER_DLL_remove (client->message_queue_head,
1222 client->message_queue_tail,
1224 memcpy (&cbuf[tsize], msg, msize);
1227 client->message_count--;
1231 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
1232 client->th = GNUNET_SERVER_notify_transmit_ready (client->client,
1234 GNUNET_TIME_UNIT_FOREVER_REL,
1235 &transmit_to_client_callback,
1237 GNUNET_assert (client->th != NULL);
1244 * Convert an address to a string.
1246 * @param plugin name of the plugin responsible for the address
1247 * @param addr binary address
1248 * @param addr_len number of bytes in addr
1249 * @return NULL on error, otherwise address string
1252 a2s (const char *plugin,
1256 struct TransportPlugin *p;
1260 p = find_transport (plugin);
1263 return p->api->address_to_string (p->api->cls,
1270 * Mark the given FAL entry as 'connected' (and hence preferred for
1271 * sending); also mark all others for the same peer as 'not connected'
1272 * (since only one can be preferred).
1274 * @param fal address to set to 'connected'
1277 mark_address_connected (struct ForeignAddressList *fal)
1279 struct ForeignAddressList *pos;
1282 GNUNET_assert (GNUNET_YES == fal->validated);
1283 if (fal->connected == GNUNET_YES)
1284 return; /* nothing to do */
1286 pos = fal->ready_list->addresses;
1289 if (GNUNET_YES == pos->connected)
1292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1293 "Marking address `%s' as no longer connected (due to connect on other address)\n",
1294 a2s (pos->ready_list->plugin->short_name,
1298 GNUNET_break (cnt == GNUNET_YES);
1300 pos->connected = GNUNET_NO;
1301 GNUNET_STATISTICS_update (stats,
1302 gettext_noop ("# connected addresses"),
1308 fal->connected = GNUNET_YES;
1309 if (GNUNET_YES == cnt)
1311 GNUNET_STATISTICS_update (stats,
1312 gettext_noop ("# connected addresses"),
1320 * Send the specified message to the specified client. Since multiple
1321 * messages may be pending for the same client at a time, this code
1322 * makes sure that no message is lost.
1324 * @param client client to transmit the message to
1325 * @param msg the message to send
1326 * @param may_drop can this message be dropped if the
1327 * message queue for this client is getting far too large?
1330 transmit_to_client (struct TransportClient *client,
1331 const struct GNUNET_MessageHeader *msg, int may_drop)
1333 struct ClientMessageQueueEntry *q;
1336 if ((client->message_count >= MAX_PENDING) && (GNUNET_YES == may_drop))
1338 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1340 ("Dropping message of type %u and size %u, have %u messages pending (%u is the soft limit)\n"),
1343 client->message_count,
1345 GNUNET_STATISTICS_update (stats,
1346 gettext_noop ("# messages dropped due to slow client"),
1351 msize = ntohs (msg->size);
1352 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
1353 q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize);
1354 memcpy (&q[1], msg, msize);
1355 GNUNET_CONTAINER_DLL_insert_after (client->message_queue_head,
1356 client->message_queue_tail,
1357 client->message_queue_tail,
1359 client->message_count++;
1360 if (client->th == NULL)
1362 client->th = GNUNET_SERVER_notify_transmit_ready (client->client,
1364 GNUNET_TIME_UNIT_FOREVER_REL,
1365 &transmit_to_client_callback,
1367 GNUNET_assert (client->th != NULL);
1373 * Transmit a 'SEND_OK' notification to the given client for the
1376 * @param client who to notify
1377 * @param n neighbour to notify about
1378 * @param result status code for the transmission request
1381 transmit_send_ok (struct TransportClient *client,
1382 struct NeighbourList *n,
1385 struct SendOkMessage send_ok_msg;
1387 send_ok_msg.header.size = htons (sizeof (send_ok_msg));
1388 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
1389 send_ok_msg.success = htonl (result);
1390 send_ok_msg.latency = GNUNET_TIME_relative_hton (n->latency);
1391 send_ok_msg.peer = n->id;
1392 transmit_to_client (client, &send_ok_msg.header, GNUNET_NO);
1397 * Function called by the GNUNET_TRANSPORT_TransmitFunction
1398 * upon "completion" of a send request. This tells the API
1399 * that it is now legal to send another message to the given
1402 * @param cls closure, identifies the entry on the
1403 * message queue that was transmitted and the
1404 * client responsible for queueing the message
1405 * @param target the peer receiving the message
1406 * @param result GNUNET_OK on success, if the transmission
1407 * failed, we should not tell the client to transmit
1411 transmit_send_continuation (void *cls,
1412 const struct GNUNET_PeerIdentity *target,
1415 struct MessageQueue *mq = cls;
1416 struct NeighbourList *n;
1418 GNUNET_STATISTICS_update (stats,
1419 gettext_noop ("# bytes pending with plugins"),
1420 - (int64_t) mq->message_buf_size,
1422 if (result == GNUNET_OK)
1424 GNUNET_STATISTICS_update (stats,
1425 gettext_noop ("# bytes successfully transmitted by plugins"),
1426 mq->message_buf_size,
1431 GNUNET_STATISTICS_update (stats,
1432 gettext_noop ("# bytes with transmission failure by plugins"),
1433 mq->message_buf_size,
1436 n = find_neighbour(&mq->neighbour_id);
1437 GNUNET_assert (n != NULL);
1438 if (mq->specific_address != NULL)
1440 if (result == GNUNET_OK)
1442 mq->specific_address->timeout =
1443 GNUNET_TIME_relative_to_absolute
1444 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1445 if (mq->specific_address->validated == GNUNET_YES)
1446 mark_address_connected (mq->specific_address);
1450 if (mq->specific_address->connected != GNUNET_NO)
1453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1454 "Marking address `%s' as no longer connected (due to transmission problem)\n",
1455 a2s (mq->specific_address->ready_list->plugin->short_name,
1456 mq->specific_address->addr,
1457 mq->specific_address->addrlen));
1459 GNUNET_STATISTICS_update (stats,
1460 gettext_noop ("# connected addresses"),
1463 mq->specific_address->connected = GNUNET_NO;
1466 if (! mq->internal_msg)
1467 mq->specific_address->in_transmit = GNUNET_NO;
1469 if (mq->client != NULL)
1470 transmit_send_ok (mq->client, n, result);
1472 try_transmission_to_peer (n);
1477 * Find an address in any of the available transports for
1478 * the given neighbour that would be good for message
1479 * transmission. This is essentially the transport selection
1482 * @param neighbour for whom to select an address
1483 * @return selected address, NULL if we have none
1485 struct ForeignAddressList *
1486 find_ready_address(struct NeighbourList *neighbour)
1488 struct ReadyList *head = neighbour->plugins;
1489 struct ForeignAddressList *addresses;
1490 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
1491 struct ForeignAddressList *best_address;
1493 best_address = NULL;
1494 while (head != NULL)
1496 addresses = head->addresses;
1497 while (addresses != NULL)
1499 if ( (addresses->timeout.value < now.value) &&
1500 (addresses->connected == GNUNET_YES) )
1503 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1504 "Marking long-time inactive connection to `%4s' as down.\n",
1505 GNUNET_i2s (&neighbour->id));
1507 GNUNET_STATISTICS_update (stats,
1508 gettext_noop ("# connected addresses"),
1511 addresses->connected = GNUNET_NO;
1513 addresses = addresses->next;
1516 addresses = head->addresses;
1517 while (addresses != NULL)
1519 #if DEBUG_TRANSPORT > 1
1520 if (addresses->addr != NULL)
1521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1522 "Have address `%s' for peer `%4s' (status: %d, %d, %d, %u, %llums, %u)\n",
1523 a2s (head->plugin->short_name,
1525 addresses->addrlen),
1526 GNUNET_i2s (&neighbour->id),
1527 addresses->connected,
1528 addresses->in_transmit,
1529 addresses->validated,
1530 addresses->connect_attempts,
1531 (unsigned long long) addresses->timeout.value,
1532 (unsigned int) addresses->distance);
1534 if ( ( (best_address == NULL) ||
1535 (addresses->connected == GNUNET_YES) ||
1536 (best_address->connected == GNUNET_NO) ) &&
1537 (addresses->in_transmit == GNUNET_NO) &&
1538 ( (best_address == NULL) ||
1539 (addresses->latency.value < best_address->latency.value)) )
1540 best_address = addresses;
1541 /* FIXME: also give lower-latency addresses that are not
1542 connected a chance some times... */
1543 addresses = addresses->next;
1547 if (best_address != NULL)
1550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1551 "Best address found (`%s') has latency of %llu ms.\n",
1552 (best_address->addrlen > 0)
1553 ? a2s (best_address->ready_list->plugin->short_name,
1555 best_address->addrlen)
1557 best_address->latency.value);
1562 GNUNET_STATISTICS_update (stats,
1563 gettext_noop ("# transmission attempts failed (no address)"),
1567 return best_address;
1573 * We should re-try transmitting to the given peer,
1574 * hopefully we've learned something in the meantime.
1577 retry_transmission_task (void *cls,
1578 const struct GNUNET_SCHEDULER_TaskContext *tc)
1580 struct NeighbourList *n = cls;
1582 n->retry_task = GNUNET_SCHEDULER_NO_TASK;
1583 try_transmission_to_peer (n);
1588 * Check the ready list for the given neighbour and if a plugin is
1589 * ready for transmission (and if we have a message), do so!
1591 * @param neighbour target peer for which to transmit
1594 try_transmission_to_peer (struct NeighbourList *neighbour)
1596 struct ReadyList *rl;
1597 struct MessageQueue *mq;
1598 struct GNUNET_TIME_Relative timeout;
1602 if (neighbour->messages_head == NULL)
1605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1606 "Transmission queue for `%4s' is empty\n",
1607 GNUNET_i2s (&neighbour->id));
1609 return; /* nothing to do */
1612 mq = neighbour->messages_head;
1613 force_address = GNUNET_YES;
1614 if (mq->specific_address == NULL)
1616 mq->specific_address = find_ready_address(neighbour);
1617 GNUNET_STATISTICS_update (stats,
1618 gettext_noop ("# transport selected peer address freely"),
1621 force_address = GNUNET_NO;
1623 if (mq->specific_address == NULL)
1625 GNUNET_STATISTICS_update (stats,
1626 gettext_noop ("# transport failed to selected peer address"),
1629 timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout);
1630 if (timeout.value == 0)
1633 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1634 "No destination address available to transmit message of size %u to peer `%4s'\n",
1635 mq->message_buf_size,
1636 GNUNET_i2s (&mq->neighbour_id));
1638 GNUNET_STATISTICS_update (stats,
1639 gettext_noop ("# bytes in message queue for other peers"),
1640 - (int64_t) mq->message_buf_size,
1642 GNUNET_STATISTICS_update (stats,
1643 gettext_noop ("# bytes discarded (no destination address available)"),
1644 mq->message_buf_size,
1646 if (mq->client != NULL)
1647 transmit_send_ok (mq->client, neighbour, GNUNET_NO);
1648 GNUNET_CONTAINER_DLL_remove (neighbour->messages_head,
1649 neighbour->messages_tail,
1652 return; /* nobody ready */
1654 GNUNET_STATISTICS_update (stats,
1655 gettext_noop ("# message delivery deferred (no address)"),
1658 if (neighbour->retry_task != GNUNET_SCHEDULER_NO_TASK)
1659 GNUNET_SCHEDULER_cancel (sched,
1660 neighbour->retry_task);
1661 neighbour->retry_task = GNUNET_SCHEDULER_add_delayed (sched,
1663 &retry_transmission_task,
1666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1667 "No validated destination address available to transmit message of size %u to peer `%4s', will wait %llums to find an address.\n",
1668 mq->message_buf_size,
1669 GNUNET_i2s (&mq->neighbour_id),
1672 /* FIXME: might want to trigger peerinfo lookup here
1673 (unless that's already pending...) */
1676 GNUNET_CONTAINER_DLL_remove (neighbour->messages_head,
1677 neighbour->messages_tail,
1679 if (mq->specific_address->connected == GNUNET_NO)
1680 mq->specific_address->connect_attempts++;
1681 rl = mq->specific_address->ready_list;
1682 mq->plugin = rl->plugin;
1683 if (!mq->internal_msg)
1684 mq->specific_address->in_transmit = GNUNET_YES;
1686 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1687 "Sending message of size %u for `%4s' to `%s' via plugin `%s'\n",
1688 mq->message_buf_size,
1689 GNUNET_i2s (&neighbour->id),
1690 (mq->specific_address->addr != NULL)
1691 ? a2s (mq->plugin->short_name,
1692 mq->specific_address->addr,
1693 mq->specific_address->addrlen)
1695 rl->plugin->short_name);
1697 GNUNET_STATISTICS_update (stats,
1698 gettext_noop ("# bytes in message queue for other peers"),
1699 - (int64_t) mq->message_buf_size,
1701 GNUNET_STATISTICS_update (stats,
1702 gettext_noop ("# bytes pending with plugins"),
1703 mq->message_buf_size,
1705 ret = rl->plugin->api->send (rl->plugin->api->cls,
1708 mq->message_buf_size,
1710 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1711 mq->specific_address->session,
1712 mq->specific_address->addr,
1713 mq->specific_address->addrlen,
1715 &transmit_send_continuation, mq);
1718 /* failure, but 'send' would not call continuation in this case,
1719 so we need to do it here! */
1720 transmit_send_continuation (mq,
1728 * Send the specified message to the specified peer.
1730 * @param client source of the transmission request (can be NULL)
1731 * @param peer_address ForeignAddressList where we should send this message
1732 * @param priority how important is the message
1733 * @param timeout how long do we have to transmit?
1734 * @param message_buf message(s) to send GNUNET_MessageHeader(s)
1735 * @param message_buf_size total size of all messages in message_buf
1736 * @param is_internal is this an internal message; these are pre-pended and
1737 * also do not count for plugins being "ready" to transmit
1738 * @param neighbour handle to the neighbour for transmission
1741 transmit_to_peer (struct TransportClient *client,
1742 struct ForeignAddressList *peer_address,
1743 unsigned int priority,
1744 struct GNUNET_TIME_Relative timeout,
1745 const char *message_buf,
1746 size_t message_buf_size,
1747 int is_internal, struct NeighbourList *neighbour)
1749 struct MessageQueue *mq;
1754 /* check for duplicate submission */
1755 mq = neighbour->messages_head;
1758 if (mq->client == client)
1760 /* client transmitted to same peer twice
1761 before getting SEND_OK! */
1769 GNUNET_STATISTICS_update (stats,
1770 gettext_noop ("# bytes in message queue for other peers"),
1773 mq = GNUNET_malloc (sizeof (struct MessageQueue) + message_buf_size);
1774 mq->specific_address = peer_address;
1775 mq->client = client;
1776 /* FIXME: this memcpy can be up to 7% of our total runtime! */
1777 memcpy (&mq[1], message_buf, message_buf_size);
1778 mq->message_buf = (const char*) &mq[1];
1779 mq->message_buf_size = message_buf_size;
1780 memcpy(&mq->neighbour_id, &neighbour->id, sizeof(struct GNUNET_PeerIdentity));
1781 mq->internal_msg = is_internal;
1782 mq->priority = priority;
1783 mq->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1785 GNUNET_CONTAINER_DLL_insert (neighbour->messages_head,
1786 neighbour->messages_tail,
1789 GNUNET_CONTAINER_DLL_insert_after (neighbour->messages_head,
1790 neighbour->messages_tail,
1791 neighbour->messages_tail,
1793 try_transmission_to_peer (neighbour);
1800 struct GeneratorContext
1802 struct TransportPlugin *plug_pos;
1803 struct OwnAddressList *addr_pos;
1804 struct GNUNET_TIME_Absolute expiration;
1812 address_generator (void *cls, size_t max, void *buf)
1814 struct GeneratorContext *gc = cls;
1817 while ((gc->addr_pos == NULL) && (gc->plug_pos != NULL))
1819 gc->plug_pos = gc->plug_pos->next;
1820 gc->addr_pos = (gc->plug_pos != NULL) ? gc->plug_pos->addresses : NULL;
1822 if (NULL == gc->plug_pos)
1827 ret = GNUNET_HELLO_add_address (gc->plug_pos->short_name,
1830 gc->addr_pos->addrlen, buf, max);
1831 gc->addr_pos = gc->addr_pos->next;
1837 * Construct our HELLO message from all of the addresses of
1838 * all of the transports.
1843 struct GNUNET_HELLO_Message *hello;
1844 struct TransportClient *cpos;
1845 struct NeighbourList *npos;
1846 struct GeneratorContext gc;
1848 gc.plug_pos = plugins;
1849 gc.addr_pos = plugins != NULL ? plugins->addresses : NULL;
1850 gc.expiration = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
1851 hello = GNUNET_HELLO_create (&my_public_key, &address_generator, &gc);
1853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
1854 "Refreshed my `%s', new size is %d\n", "HELLO", GNUNET_HELLO_size(hello));
1856 GNUNET_STATISTICS_update (stats,
1857 gettext_noop ("# refreshed my HELLO"),
1861 while (cpos != NULL)
1863 transmit_to_client (cpos,
1864 (const struct GNUNET_MessageHeader *) hello,
1869 GNUNET_free_non_null (our_hello);
1871 GNUNET_PEERINFO_add_peer (peerinfo, our_hello);
1873 while (npos != NULL)
1876 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
1877 "Transmitting updated `%s' to neighbour `%4s'\n",
1878 "HELLO", GNUNET_i2s (&npos->id));
1880 GNUNET_STATISTICS_update (stats,
1881 gettext_noop ("# transmitted my HELLO to other peers"),
1884 transmit_to_peer (NULL, NULL, 0,
1885 HELLO_ADDRESS_EXPIRATION,
1886 (const char *) our_hello,
1887 GNUNET_HELLO_size(our_hello),
1895 * Task used to clean up expired addresses for a plugin.
1897 * @param cls closure
1901 expire_address_task (void *cls,
1902 const struct GNUNET_SCHEDULER_TaskContext *tc);
1906 * Update the list of addresses for this plugin,
1907 * expiring those that are past their expiration date.
1909 * @param plugin addresses of which plugin should be recomputed?
1910 * @param fresh set to GNUNET_YES if a new address was added
1911 * and we need to regenerate the HELLO even if nobody
1915 update_addresses (struct TransportPlugin *plugin, int fresh)
1917 static struct GNUNET_TIME_Absolute last_update;
1918 struct GNUNET_TIME_Relative min_remaining;
1919 struct GNUNET_TIME_Relative remaining;
1920 struct GNUNET_TIME_Absolute now;
1921 struct OwnAddressList *pos;
1922 struct OwnAddressList *prev;
1923 struct OwnAddressList *next;
1926 if (plugin->address_update_task != GNUNET_SCHEDULER_NO_TASK)
1927 GNUNET_SCHEDULER_cancel (plugin->env.sched, plugin->address_update_task);
1928 plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK;
1929 now = GNUNET_TIME_absolute_get ();
1930 min_remaining = GNUNET_TIME_UNIT_FOREVER_REL;
1931 expired = (GNUNET_TIME_absolute_get_duration (last_update).value > (HELLO_ADDRESS_EXPIRATION.value / 4));
1933 pos = plugin->addresses;
1937 if (pos->expires.value < now.value)
1939 expired = GNUNET_YES;
1941 plugin->addresses = pos->next;
1943 prev->next = pos->next;
1948 remaining = GNUNET_TIME_absolute_get_remaining (pos->expires);
1949 if (remaining.value < min_remaining.value)
1950 min_remaining = remaining;
1956 if (expired || fresh)
1961 min_remaining = GNUNET_TIME_relative_min (min_remaining,
1962 GNUNET_TIME_relative_divide (HELLO_ADDRESS_EXPIRATION,
1964 plugin->address_update_task
1965 = GNUNET_SCHEDULER_add_delayed (plugin->env.sched,
1967 &expire_address_task, plugin);
1972 * Task used to clean up expired addresses for a plugin.
1974 * @param cls closure
1978 expire_address_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1980 struct TransportPlugin *plugin = cls;
1982 plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK;
1983 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1984 update_addresses (plugin, GNUNET_NO);
1989 * Iterator over hash map entries that NULLs the session of validation
1990 * entries that match the given session.
1992 * @param cls closure (the 'struct Session*' to match against)
1993 * @param key current key code (peer ID, not used)
1994 * @param value value in the hash map ('struct ValidationEntry*')
1995 * @return GNUNET_YES (we should continue to iterate)
1998 remove_session_validations (void *cls,
1999 const GNUNET_HashCode * key,
2002 struct Session *session = cls;
2003 struct ValidationEntry *ve = value;
2005 if (session == ve->session)
2012 * We've been disconnected from the other peer (for some
2013 * connection-oriented transport). Either quickly
2014 * re-establish the connection or signal the disconnect
2017 * @param p overall plugin context
2018 * @param nl neighbour that was disconnected
2021 try_fast_reconnect (struct TransportPlugin *p,
2022 struct NeighbourList *nl)
2024 /* FIXME-MW: fast reconnect / transport switching not implemented... */
2025 /* Note: the idea here is to hide problems with transports (or
2026 switching between plugins) from the core to eliminate the need to
2027 re-negotiate session keys and the like; OTOH, we should tell core
2028 quickly (much faster than timeout) `if a connection was lost and
2029 could not be re-established (i.e. other peer went down or is
2030 unable / refuses to communicate);
2032 So we should consider:
2033 1) ideally: our own willingness / need to connect
2034 2) prior failures to connect to this peer (by plugin)
2035 3) ideally: reaons why other peer terminated (as far as knowable)
2037 Most importantly, it must be POSSIBLE for another peer to terminate
2038 a connection for a while (without us instantly re-establishing it).
2039 Similarly, if another peer is gone we should quickly notify CORE.
2040 OTOH, if there was a minor glitch (i.e. crash of gnunet-service-transport
2041 on the other end), we should reconnect in such a way that BOTH CORE
2042 services never even notice.
2043 Furthermore, the same mechanism (or small variation) could be used
2044 to switch to a better-performing plugin (ATS).
2046 Finally, this needs to be tested throughly... */
2048 /* No reconnect, signal disconnect instead! */
2049 disconnect_neighbour (nl, GNUNET_NO);
2054 * Function that will be called whenever the plugin internally
2055 * cleans up a session pointer and hence the service needs to
2056 * discard all of those sessions as well. Plugins that do not
2057 * use sessions can simply omit calling this function and always
2058 * use NULL wherever a session pointer is needed.
2060 * @param cls closure
2061 * @param peer which peer was the session for
2062 * @param session which session is being destoyed
2065 plugin_env_session_end (void *cls,
2066 const struct GNUNET_PeerIdentity *peer,
2067 struct Session *session)
2069 struct TransportPlugin *p = cls;
2070 struct NeighbourList *nl;
2071 struct ReadyList *rl;
2072 struct ForeignAddressList *pos;
2073 struct ForeignAddressList *prev;
2075 GNUNET_CONTAINER_multihashmap_iterate (validation_map,
2076 &remove_session_validations,
2078 nl = find_neighbour (peer);
2080 return; /* was never marked as connected */
2084 if (rl->plugin == p)
2089 return; /* was never marked as connected */
2091 pos = rl->addresses;
2092 while ( (pos != NULL) &&
2093 (pos->session != session) )
2099 return; /* was never marked as connected */
2100 pos->session = NULL;
2101 if (pos->addrlen != 0)
2103 if (nl->received_pong != GNUNET_NO)
2104 try_fast_reconnect (p, nl);
2107 /* was inbound connection, free 'pos' */
2109 rl->addresses = pos->next;
2111 prev->next = pos->next;
2112 if (GNUNET_SCHEDULER_NO_TASK != pos->revalidate_task)
2114 GNUNET_SCHEDULER_cancel (sched,
2115 pos->revalidate_task);
2116 pos->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
2119 if (nl->received_pong == GNUNET_NO)
2120 return; /* nothing to do, never connected... */
2121 /* check if we have any validated addresses left */
2122 pos = rl->addresses;
2127 try_fast_reconnect (p, nl);
2132 /* no valid addresses left, signal disconnect! */
2133 disconnect_neighbour (nl, GNUNET_NO);
2138 * Function that must be called by each plugin to notify the
2139 * transport service about the addresses under which the transport
2140 * provided by the plugin can be reached.
2142 * @param cls closure
2143 * @param name name of the transport that generated the address
2144 * @param addr one of the addresses of the host, NULL for the last address
2145 * the specific address format depends on the transport
2146 * @param addrlen length of the address
2147 * @param expires when should this address automatically expire?
2150 plugin_env_notify_address (void *cls,
2154 struct GNUNET_TIME_Relative expires)
2156 struct TransportPlugin *p = cls;
2157 struct OwnAddressList *al;
2158 struct GNUNET_TIME_Absolute abex;
2160 GNUNET_assert (addr != NULL);
2161 abex = GNUNET_TIME_relative_to_absolute (expires);
2162 GNUNET_assert (p == find_transport (name));
2166 if ((addrlen == al->addrlen) && (0 == memcmp (addr, &al[1], addrlen)))
2168 if (al->expires.value < abex.value)
2175 al = GNUNET_malloc (sizeof (struct OwnAddressList) + addrlen);
2176 al->next = p->addresses;
2179 al->addrlen = addrlen;
2180 memcpy (&al[1], addr, addrlen);
2181 update_addresses (p, GNUNET_YES);
2186 * Notify all of our clients about a peer connecting.
2189 notify_clients_connect (const struct GNUNET_PeerIdentity *peer,
2190 struct GNUNET_TIME_Relative latency,
2193 struct ConnectInfoMessage cim;
2194 struct TransportClient *cpos;
2197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2198 "Notifying clients about connection from `%s'\n",
2201 GNUNET_STATISTICS_update (stats,
2202 gettext_noop ("# peers connected"),
2205 cim.header.size = htons (sizeof (struct ConnectInfoMessage));
2206 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
2207 cim.distance = htonl (distance);
2208 cim.latency = GNUNET_TIME_relative_hton (latency);
2209 memcpy (&cim.id, peer, sizeof (struct GNUNET_PeerIdentity));
2211 while (cpos != NULL)
2213 transmit_to_client (cpos, &cim.header, GNUNET_NO);
2220 * Notify all of our clients about a peer disconnecting.
2223 notify_clients_disconnect (const struct GNUNET_PeerIdentity *peer)
2225 struct DisconnectInfoMessage dim;
2226 struct TransportClient *cpos;
2229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2230 "Notifying clients about lost connection to `%s'\n",
2233 GNUNET_STATISTICS_update (stats,
2234 gettext_noop ("# peers connected"),
2237 dim.header.size = htons (sizeof (struct DisconnectInfoMessage));
2238 dim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
2239 dim.reserved = htonl (0);
2240 memcpy (&dim.peer, peer, sizeof (struct GNUNET_PeerIdentity));
2242 while (cpos != NULL)
2244 transmit_to_client (cpos, &dim.header, GNUNET_NO);
2251 * Find a ForeignAddressList entry for the given neighbour
2252 * that matches the given address and transport.
2254 * @param neighbour which peer we care about
2255 * @param tname name of the transport plugin
2256 * @param session session to look for, NULL for 'any'; otherwise
2257 * can be used for the service to "learn" this session ID
2259 * @param addr binary address
2260 * @param addrlen length of addr
2261 * @return NULL if no such entry exists
2263 static struct ForeignAddressList *
2264 find_peer_address(struct NeighbourList *neighbour,
2266 struct Session *session,
2270 struct ReadyList *head;
2271 struct ForeignAddressList *pos;
2273 head = neighbour->plugins;
2274 while (head != NULL)
2276 if (0 == strcmp (tname, head->plugin->short_name))
2282 pos = head->addresses;
2283 while ( (pos != NULL) &&
2284 ( (pos->addrlen != addrlen) ||
2285 (memcmp(pos->addr, addr, addrlen) != 0) ) )
2287 if ( (session != NULL) &&
2288 (pos->session == session) )
2292 if ( (session != NULL) && (pos != NULL) )
2293 pos->session = session; /* learn it! */
2299 * Get the peer address struct for the given neighbour and
2300 * address. If it doesn't yet exist, create it.
2302 * @param neighbour which peer we care about
2303 * @param tname name of the transport plugin
2304 * @param session session of the plugin, or NULL for none
2305 * @param addr binary address
2306 * @param addrlen length of addr
2307 * @return NULL if we do not have a transport plugin for 'tname'
2309 static struct ForeignAddressList *
2310 add_peer_address (struct NeighbourList *neighbour,
2312 struct Session *session,
2316 struct ReadyList *head;
2317 struct ForeignAddressList *ret;
2319 ret = find_peer_address (neighbour, tname, session, addr, addrlen);
2322 head = neighbour->plugins;
2324 while (head != NULL)
2326 if (0 == strcmp (tname, head->plugin->short_name))
2332 ret = GNUNET_malloc(sizeof(struct ForeignAddressList) + addrlen);
2333 ret->session = session;
2336 ret->addr = (const char*) &ret[1];
2337 memcpy (&ret[1], addr, addrlen);
2343 ret->addrlen = addrlen;
2344 ret->expires = GNUNET_TIME_relative_to_absolute
2345 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2346 ret->latency = GNUNET_TIME_relative_get_forever();
2348 ret->timeout = GNUNET_TIME_relative_to_absolute
2349 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2350 ret->ready_list = head;
2351 ret->next = head->addresses;
2352 head->addresses = ret;
2358 * Closure for 'add_validated_address'.
2360 struct AddValidatedAddressContext
2363 * Entry that has been validated.
2365 const struct ValidationEntry *ve;
2368 * Flag set after we have added the address so
2369 * that we terminate the iteration next time.
2376 * Callback function used to fill a buffer of max bytes with a list of
2377 * addresses in the format used by HELLOs. Should use
2378 * "GNUNET_HELLO_add_address" as a helper function.
2380 * @param cls the 'struct AddValidatedAddressContext' with the validated address
2381 * @param max maximum number of bytes that can be written to buf
2382 * @param buf where to write the address information
2383 * @return number of bytes written, 0 to signal the
2384 * end of the iteration.
2387 add_validated_address (void *cls,
2388 size_t max, void *buf)
2390 struct AddValidatedAddressContext *avac = cls;
2391 const struct ValidationEntry *ve = avac->ve;
2393 if (GNUNET_YES == avac->done)
2395 avac->done = GNUNET_YES;
2396 return GNUNET_HELLO_add_address (ve->transport_name,
2397 GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION),
2407 * Closure for 'check_address_exists'.
2409 struct CheckAddressExistsClosure
2412 * Address to check for.
2417 * Name of the transport.
2424 struct Session *session;
2427 * Set to GNUNET_YES if the address exists.
2440 * Iterator over hash map entries. Checks if the given
2441 * validation entry is for the same address as what is given
2444 * @param cls the 'struct CheckAddressExistsClosure*'
2445 * @param key current key code (ignored)
2446 * @param value value in the hash map ('struct ValidationEntry')
2447 * @return GNUNET_YES if we should continue to
2448 * iterate (mismatch), GNUNET_NO if not (entry matched)
2451 check_address_exists (void *cls,
2452 const GNUNET_HashCode * key,
2455 struct CheckAddressExistsClosure *caec = cls;
2456 struct ValidationEntry *ve = value;
2458 if ( (0 == strcmp (caec->tname,
2459 ve->transport_name)) &&
2460 (caec->addrlen == ve->addrlen) &&
2461 (0 == memcmp (caec->addr,
2465 caec->exists = GNUNET_YES;
2468 if ( (ve->session != NULL) &&
2469 (caec->session == ve->session) )
2471 caec->exists = GNUNET_YES;
2480 * Iterator to free entries in the validation_map.
2482 * @param cls closure (unused)
2483 * @param key current key code
2484 * @param value value in the hash map (validation to abort)
2485 * @return GNUNET_YES (always)
2488 abort_validation (void *cls,
2489 const GNUNET_HashCode * key,
2492 struct ValidationEntry *va = value;
2494 if (GNUNET_SCHEDULER_NO_TASK != va->timeout_task)
2495 GNUNET_SCHEDULER_cancel (sched, va->timeout_task);
2496 GNUNET_free (va->transport_name);
2497 if (va->chvc != NULL)
2499 va->chvc->ve_count--;
2500 if (va->chvc->ve_count == 0)
2502 GNUNET_CONTAINER_DLL_remove (chvc_head,
2505 GNUNET_free (va->chvc);
2515 * HELLO validation cleanup task (validation failed).
2517 * @param cls the 'struct ValidationEntry' that failed
2518 * @param tc scheduler context (unused)
2521 timeout_hello_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2523 struct ValidationEntry *va = cls;
2524 struct GNUNET_PeerIdentity pid;
2526 va->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2527 GNUNET_STATISTICS_update (stats,
2528 gettext_noop ("# address validation timeouts"),
2531 GNUNET_CRYPTO_hash (&va->publicKey,
2533 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
2535 GNUNET_break (GNUNET_OK ==
2536 GNUNET_CONTAINER_multihashmap_remove (validation_map,
2539 abort_validation (NULL, NULL, va);
2544 neighbour_timeout_task (void *cls,
2545 const struct GNUNET_SCHEDULER_TaskContext *tc)
2547 struct NeighbourList *n = cls;
2550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2551 "Neighbour `%4s' has timed out!\n", GNUNET_i2s (&n->id));
2553 GNUNET_STATISTICS_update (stats,
2554 gettext_noop ("# disconnects due to timeout"),
2557 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2558 disconnect_neighbour (n, GNUNET_NO);
2563 * Schedule the job that will cause us to send a PING to the
2564 * foreign address to evaluate its validity and latency.
2566 * @param fal address to PING
2569 schedule_next_ping (struct ForeignAddressList *fal);
2573 * Add the given address to the list of foreign addresses
2574 * available for the given peer (check for duplicates).
2576 * @param cls the respective 'struct NeighbourList' to update
2577 * @param tname name of the transport
2578 * @param expiration expiration time
2579 * @param addr the address
2580 * @param addrlen length of the address
2581 * @return GNUNET_OK (always)
2584 add_to_foreign_address_list (void *cls,
2586 struct GNUNET_TIME_Absolute expiration,
2590 struct NeighbourList *n = cls;
2591 struct ForeignAddressList *fal;
2594 GNUNET_STATISTICS_update (stats,
2595 gettext_noop ("# valid peer addresses returned by PEERINFO"),
2599 fal = find_peer_address (n, tname, NULL, addr, addrlen);
2603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2604 "Adding address `%s' (%s) for peer `%4s' due to PEERINFO data for %llums.\n",
2605 a2s (tname, addr, addrlen),
2607 GNUNET_i2s (&n->id),
2610 fal = add_peer_address (n, tname, NULL, addr, addrlen);
2613 GNUNET_STATISTICS_update (stats,
2614 gettext_noop ("# previously validated addresses lacking transport"),
2620 fal->expires = GNUNET_TIME_absolute_max (expiration,
2622 schedule_next_ping (fal);
2628 fal->expires = GNUNET_TIME_absolute_max (expiration,
2633 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2634 "Failed to add new address for `%4s'\n",
2635 GNUNET_i2s (&n->id));
2638 if (fal->validated == GNUNET_NO)
2640 fal->validated = GNUNET_YES;
2641 GNUNET_STATISTICS_update (stats,
2642 gettext_noop ("# peer addresses considered valid"),
2646 if (try == GNUNET_YES)
2648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2649 "Have new addresses, will try to trigger transmissions.\n");
2650 try_transmission_to_peer (n);
2657 * Add addresses in validated HELLO "h" to the set of addresses
2658 * we have for this peer.
2660 * @param cls closure ('struct NeighbourList*')
2661 * @param peer id of the peer, NULL for last call
2662 * @param h hello message for the peer (can be NULL)
2665 add_hello_for_peer (void *cls,
2666 const struct GNUNET_PeerIdentity *peer,
2667 const struct GNUNET_HELLO_Message *h)
2669 struct NeighbourList *n = cls;
2677 return; /* no HELLO available */
2679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2680 "Peerinfo had `%s' message for peer `%4s', adding existing addresses.\n",
2684 if (GNUNET_YES != n->public_key_valid)
2686 GNUNET_HELLO_get_key (h, &n->publicKey);
2687 n->public_key_valid = GNUNET_YES;
2689 GNUNET_HELLO_iterate_addresses (h,
2691 &add_to_foreign_address_list,
2697 * Create a fresh entry in our neighbour list for the given peer.
2698 * Will try to transmit our current HELLO to the new neighbour.
2699 * Do not call this function directly, use 'setup_peer_check_blacklist.
2701 * @param peer the peer for which we create the entry
2702 * @param do_hello should we schedule transmitting a HELLO
2703 * @return the new neighbour list entry
2705 static struct NeighbourList *
2706 setup_new_neighbour (const struct GNUNET_PeerIdentity *peer,
2709 struct NeighbourList *n;
2710 struct TransportPlugin *tp;
2711 struct ReadyList *rl;
2714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2715 "Setting up state for neighbour `%4s'\n",
2718 GNUNET_assert (our_hello != NULL);
2719 GNUNET_STATISTICS_update (stats,
2720 gettext_noop ("# active neighbours"),
2723 n = GNUNET_malloc (sizeof (struct NeighbourList));
2724 n->next = neighbours;
2728 GNUNET_TIME_relative_to_absolute
2729 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2730 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
2731 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
2732 MAX_BANDWIDTH_CARRY_S);
2736 if ((tp->api->send != NULL) && (!is_blacklisted(peer, tp)))
2738 rl = GNUNET_malloc (sizeof (struct ReadyList));
2740 rl->next = n->plugins;
2743 rl->addresses = NULL;
2747 n->latency = GNUNET_TIME_UNIT_FOREVER_REL;
2749 n->timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
2750 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
2751 &neighbour_timeout_task, n);
2754 n->piter = GNUNET_PEERINFO_iterate (peerinfo, peer,
2755 GNUNET_TIME_UNIT_FOREVER_REL,
2756 &add_hello_for_peer, n);
2757 transmit_to_peer (NULL, NULL, 0,
2758 HELLO_ADDRESS_EXPIRATION,
2759 (const char *) our_hello, GNUNET_HELLO_size(our_hello),
2767 * Function called after we have checked if communicating
2768 * with a given peer is acceptable.
2770 * @param cls closure
2771 * @param n NULL if communication is not acceptable
2773 typedef void (*SetupContinuation)(void *cls,
2774 struct NeighbourList *n);
2778 * Information kept for each client registered to perform
2784 * This is a linked list.
2786 struct Blacklisters *next;
2789 * This is a linked list.
2791 struct Blacklisters *prev;
2794 * Client responsible for this entry.
2796 struct GNUNET_SERVER_Client *client;
2799 * Blacklist check that we're currently performing.
2801 struct BlacklistCheck *bc;
2807 * Head of DLL of blacklisting clients.
2809 static struct Blacklisters *bl_head;
2812 * Tail of DLL of blacklisting clients.
2814 static struct Blacklisters *bl_tail;
2818 * Context we use when performing a blacklist check.
2820 struct BlacklistCheck
2824 * This is a linked list.
2826 struct BlacklistCheck *next;
2829 * This is a linked list.
2831 struct BlacklistCheck *prev;
2834 * Peer being checked.
2836 struct GNUNET_PeerIdentity peer;
2839 * Option for setup neighbour afterwards.
2844 * Continuation to call with the result.
2846 SetupContinuation cont;
2854 * Current transmission request handle for this client, or NULL if no
2855 * request is pending.
2857 struct GNUNET_CONNECTION_TransmitHandle *th;
2860 * Our current position in the blacklisters list.
2862 struct Blacklisters *bl_pos;
2865 * Current task performing the check.
2867 GNUNET_SCHEDULER_TaskIdentifier task;
2872 * Head of DLL of active blacklisting queries.
2874 static struct BlacklistCheck *bc_head;
2877 * Tail of DLL of active blacklisting queries.
2879 static struct BlacklistCheck *bc_tail;
2883 * Perform next action in the blacklist check.
2885 * @param cls the 'struct BlacklistCheck*'
2889 do_blacklist_check (void *cls,
2890 const struct GNUNET_SCHEDULER_TaskContext *tc);
2894 * Transmit blacklist query to the client.
2896 * @param cls the 'struct BlacklistCheck'
2897 * @param size number of bytes allowed
2898 * @param buf where to copy the message
2899 * @return number of bytes copied to buf
2902 transmit_blacklist_message (void *cls,
2906 struct BlacklistCheck *bc = cls;
2907 struct Blacklisters *bl;
2908 struct BlacklistMessage bm;
2913 GNUNET_assert (bc->task == GNUNET_SCHEDULER_NO_TASK);
2914 bc->task = GNUNET_SCHEDULER_add_now (sched,
2915 &do_blacklist_check,
2920 bm.header.size = htons (sizeof (struct BlacklistMessage));
2921 bm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY);
2922 bm.is_allowed = htonl (0);
2924 memcpy (buf, &bm, sizeof (bm));
2925 GNUNET_SERVER_receive_done (bl->client, GNUNET_OK);
2931 * Perform next action in the blacklist check.
2933 * @param cls the 'struct BlacklistCheck*'
2937 do_blacklist_check (void *cls,
2938 const struct GNUNET_SCHEDULER_TaskContext *tc)
2940 struct BlacklistCheck *bc = cls;
2941 struct Blacklisters *bl;
2943 bc->task = GNUNET_SCHEDULER_NO_TASK;
2947 bc->cont (bc->cont_cls,
2948 setup_new_neighbour (&bc->peer, bc->do_hello));
2955 bc->th = GNUNET_SERVER_notify_transmit_ready (bl->client,
2956 sizeof (struct BlacklistMessage),
2957 GNUNET_TIME_UNIT_FOREVER_REL,
2958 &transmit_blacklist_message,
2965 * Obtain a 'struct NeighbourList' for the given peer. If such an entry
2966 * does not yet exist, check the blacklist. If the blacklist says creating
2967 * one is acceptable, create one and call the continuation; otherwise
2968 * call the continuation with NULL.
2970 * @param peer peer to setup or look up a struct NeighbourList for
2971 * @param do_hello should we also schedule sending our HELLO to the peer
2972 * if this is a new record
2973 * @param cont function to call with the 'struct NeigbhbourList*'
2974 * @param cont_cls closure for cont
2977 setup_peer_check_blacklist (const struct GNUNET_PeerIdentity *peer,
2979 SetupContinuation cont,
2982 struct NeighbourList *n;
2983 struct BlacklistCheck *bc;
2985 n = find_neighbour(peer);
2991 if (bl_head == NULL)
2994 setup_new_neighbour (peer, do_hello));
2997 bc = GNUNET_malloc (sizeof (struct BlacklistCheck));
2998 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
3000 bc->do_hello = do_hello;
3002 bc->cont_cls = cont_cls;
3003 bc->bl_pos = bl_head;
3004 bc->task = GNUNET_SCHEDULER_add_now (sched,
3005 &do_blacklist_check,
3011 * Function called with the result of querying a new blacklister about
3012 * it being allowed (or not) to continue to talk to an existing neighbour.
3014 * @param cls the original 'struct NeighbourList'
3015 * @param n NULL if we need to disconnect
3018 confirm_or_drop_neighbour (void *cls,
3019 struct NeighbourList *n)
3021 struct NeighbourList * orig = cls;
3024 disconnect_neighbour (orig, GNUNET_NO);
3029 * Handle a request to start a blacklist.
3031 * @param cls closure (always NULL)
3032 * @param client identification of the client
3033 * @param message the actual message
3036 handle_blacklist_init (void *cls,
3037 struct GNUNET_SERVER_Client *client,
3038 const struct GNUNET_MessageHeader *message)
3040 struct Blacklisters *bl;
3041 struct BlacklistCheck *bc;
3042 struct NeighbourList *n;
3047 if (bl->client == client)
3050 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3055 bl = GNUNET_malloc (sizeof (struct Blacklisters));
3056 bl->client = client;
3057 GNUNET_SERVER_client_keep (client);
3058 GNUNET_CONTAINER_DLL_insert_after (bl_head, bl_tail, bl_tail, bl);
3059 /* confirm that all existing connections are OK! */
3063 bc = GNUNET_malloc (sizeof (struct BlacklistCheck));
3064 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
3066 bc->do_hello = GNUNET_NO;
3067 bc->cont = &confirm_or_drop_neighbour;
3070 if (n == neighbours) /* all would wait for the same client, no need to
3071 create more than just the first task right now */
3072 bc->task = GNUNET_SCHEDULER_add_now (sched,
3073 &do_blacklist_check,
3081 * Handle a request to blacklist a peer.
3083 * @param cls closure (always NULL)
3084 * @param client identification of the client
3085 * @param message the actual message
3088 handle_blacklist_reply (void *cls,
3089 struct GNUNET_SERVER_Client *client,
3090 const struct GNUNET_MessageHeader *message)
3092 const struct BlacklistMessage *msg = (const struct BlacklistMessage*) message;
3093 struct Blacklisters *bl;
3094 struct BlacklistCheck *bc;
3097 while ( (bl != NULL) &&
3098 (bl->client != client) )
3102 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3107 if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
3109 bc->cont (bc->cont_cls, NULL);
3110 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
3115 bc->bl_pos = bc->bl_pos->next;
3116 bc->task = GNUNET_SCHEDULER_add_now (sched,
3117 &do_blacklist_check,
3120 /* check if any other bc's are waiting for this blacklister */
3124 if ( (bc->bl_pos == bl) &&
3125 (GNUNET_SCHEDULER_NO_TASK == bc->task) )
3126 bc->task = GNUNET_SCHEDULER_add_now (sched,
3127 &do_blacklist_check,
3135 * Send periodic PING messages to a given foreign address.
3137 * @param cls our 'struct PeriodicValidationContext*'
3138 * @param tc task context
3141 send_periodic_ping (void *cls,
3142 const struct GNUNET_SCHEDULER_TaskContext *tc)
3144 struct ForeignAddressList *peer_address = cls;
3145 struct TransportPlugin *tp;
3146 struct ValidationEntry *va;
3147 struct NeighbourList *neighbour;
3148 struct TransportPingMessage ping;
3149 struct CheckAddressExistsClosure caec;
3151 uint16_t hello_size;
3155 peer_address->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
3156 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
3158 tp = peer_address->ready_list->plugin;
3159 neighbour = peer_address->ready_list->neighbour;
3160 if (GNUNET_YES != neighbour->public_key_valid)
3162 /* no public key yet, try again later */
3163 schedule_next_ping (peer_address);
3166 caec.addr = peer_address->addr;
3167 caec.addrlen = peer_address->addrlen;
3168 caec.tname = tp->short_name;
3169 caec.session = peer_address->session;
3170 caec.exists = GNUNET_NO;
3171 GNUNET_CONTAINER_multihashmap_iterate (validation_map,
3172 &check_address_exists,
3174 if (caec.exists == GNUNET_YES)
3176 /* During validation attempts we will likely trigger the other
3177 peer trying to validate our address which in turn will cause
3178 it to send us its HELLO, so we expect to hit this case rather
3179 frequently. Only print something if we are very verbose. */
3180 #if DEBUG_TRANSPORT > 1
3181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3182 "Some validation of address `%s' via `%s' for peer `%4s' already in progress.\n",
3183 (peer_address->addr != NULL)
3184 ? a2s (tp->short_name,
3186 peer_address->addrlen)
3189 GNUNET_i2s (&neighbour->id));
3191 schedule_next_ping (peer_address);
3194 va = GNUNET_malloc (sizeof (struct ValidationEntry) + peer_address->addrlen);
3195 va->transport_name = GNUNET_strdup (tp->short_name);
3196 va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
3198 va->send_time = GNUNET_TIME_absolute_get();
3199 va->session = peer_address->session;
3200 if (peer_address->addr != NULL)
3202 va->addr = (const void*) &va[1];
3203 memcpy (&va[1], peer_address->addr, peer_address->addrlen);
3204 va->addrlen = peer_address->addrlen;
3206 memcpy(&va->publicKey,
3207 &neighbour->publicKey,
3208 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
3210 va->timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
3211 HELLO_VERIFICATION_TIMEOUT,
3212 &timeout_hello_validation,
3214 GNUNET_CONTAINER_multihashmap_put (validation_map,
3215 &neighbour->id.hashPubKey,
3217 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
3218 hello_size = GNUNET_HELLO_size(our_hello);
3219 tsize = sizeof(struct TransportPingMessage) + hello_size;
3220 if (peer_address->addr != NULL)
3222 slen = strlen (tp->short_name) + 1;
3223 tsize += slen + peer_address->addrlen;
3227 slen = 0; /* make gcc happy */
3229 message_buf = GNUNET_malloc(tsize);
3230 ping.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
3231 ping.challenge = htonl(va->challenge);
3232 memcpy(&ping.target, &neighbour->id, sizeof(struct GNUNET_PeerIdentity));
3233 memcpy(message_buf, our_hello, hello_size);
3234 if (peer_address->addr != NULL)
3236 ping.header.size = htons(sizeof(struct TransportPingMessage) +
3237 peer_address->addrlen +
3239 memcpy(&message_buf[hello_size + sizeof (struct TransportPingMessage)],
3242 memcpy(&message_buf[hello_size + sizeof (struct TransportPingMessage) + slen],
3244 peer_address->addrlen);
3248 ping.header.size = htons(sizeof(struct TransportPingMessage));
3250 memcpy(&message_buf[hello_size],
3252 sizeof(struct TransportPingMessage));
3254 #if DEBUG_TRANSPORT_REVALIDATION
3255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3256 "Performing re-validation of address `%s' via `%s' for peer `%4s' sending `%s' (%u bytes) and `%s'\n",
3257 (peer_address->addr != NULL)
3258 ? a2s (peer_address->plugin->short_name,
3260 peer_address->addrlen)
3263 GNUNET_i2s (&neighbour->id),
3264 "HELLO", hello_size,
3267 GNUNET_STATISTICS_update (stats,
3268 gettext_noop ("# PING messages sent for re-validation"),
3271 transmit_to_peer (NULL, peer_address,
3272 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
3273 HELLO_VERIFICATION_TIMEOUT,
3275 GNUNET_YES, neighbour);
3276 GNUNET_free(message_buf);
3277 schedule_next_ping (peer_address);
3282 * Schedule the job that will cause us to send a PING to the
3283 * foreign address to evaluate its validity and latency.
3285 * @param fal address to PING
3288 schedule_next_ping (struct ForeignAddressList *fal)
3290 struct GNUNET_TIME_Relative delay;
3292 if (fal->revalidate_task != GNUNET_SCHEDULER_NO_TASK)
3294 delay = GNUNET_TIME_absolute_get_remaining (fal->expires);
3295 delay.value /= 2; /* do before expiration */
3296 delay = GNUNET_TIME_relative_min (delay,
3297 LATENCY_EVALUATION_MAX_DELAY);
3298 if (GNUNET_YES != fal->estimated)
3300 delay = GNUNET_TIME_UNIT_ZERO;
3301 fal->estimated = GNUNET_YES;
3303 if (GNUNET_YES == fal->connected)
3305 delay = GNUNET_TIME_relative_min (delay,
3306 CONNECTED_LATENCY_EVALUATION_MAX_DELAY);
3308 /* FIXME: also adjust delay based on how close the last
3309 observed latency is to the latency of the best alternative */
3310 /* bound how fast we can go */
3311 delay = GNUNET_TIME_relative_max (delay,
3312 GNUNET_TIME_UNIT_SECONDS);
3313 /* randomize a bit (to avoid doing all at the same time) */
3314 delay.value += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000);
3315 fal->revalidate_task = GNUNET_SCHEDULER_add_delayed(sched,
3317 &send_periodic_ping,
3325 * Function that will be called if we receive some payload
3326 * from another peer.
3328 * @param message the payload
3329 * @param n peer who claimed to be the sender
3332 handle_payload_message (const struct GNUNET_MessageHeader *message,
3333 struct NeighbourList *n)
3335 struct InboundMessage *im;
3336 struct TransportClient *cpos;
3339 msize = ntohs (message->size);
3340 if (n->received_pong == GNUNET_NO)
3342 GNUNET_free_non_null (n->pre_connect_message_buffer);
3343 n->pre_connect_message_buffer = GNUNET_malloc (msize);
3344 memcpy (n->pre_connect_message_buffer, message, msize);
3348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3349 "Received message of type %u and size %u from `%4s', sending to all clients.\n",
3350 ntohs (message->type),
3351 ntohs (message->size),
3352 GNUNET_i2s (&n->id));
3354 if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker,
3357 n->quota_violation_count++;
3359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3360 "Bandwidth quota (%u b/s) violation detected (total of %u).\n",
3361 n->in_tracker.available_bytes_per_s__,
3362 n->quota_violation_count);
3364 /* Discount 32k per violation */
3365 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker,
3370 if (n->quota_violation_count > 0)
3372 /* try to add 32k back */
3373 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker,
3375 n->quota_violation_count--;
3378 GNUNET_STATISTICS_update (stats,
3379 gettext_noop ("# payload received from other peers"),
3382 /* transmit message to all clients */
3383 im = GNUNET_malloc (sizeof (struct InboundMessage) + msize);
3384 im->header.size = htons (sizeof (struct InboundMessage) + msize);
3385 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
3386 im->latency = GNUNET_TIME_relative_hton (n->latency);
3388 im->distance = ntohl(n->distance);
3389 memcpy (&im[1], message, msize);
3391 while (cpos != NULL)
3393 transmit_to_client (cpos, &im->header, GNUNET_YES);
3401 * Iterator over hash map entries. Checks if the given validation
3402 * entry is for the same challenge as what is given in the PONG.
3404 * @param cls the 'struct TransportPongMessage*'
3405 * @param key peer identity
3406 * @param value value in the hash map ('struct ValidationEntry')
3407 * @return GNUNET_YES if we should continue to
3408 * iterate (mismatch), GNUNET_NO if not (entry matched)
3411 check_pending_validation (void *cls,
3412 const GNUNET_HashCode * key,
3415 const struct TransportPongMessage *pong = cls;
3416 struct ValidationEntry *ve = value;
3417 struct AddValidatedAddressContext avac;
3418 unsigned int challenge = ntohl(pong->challenge);
3419 struct GNUNET_HELLO_Message *hello;
3420 struct GNUNET_PeerIdentity target;
3421 struct NeighbourList *n;
3422 struct ForeignAddressList *fal;
3423 struct OwnAddressList *oal;
3424 struct TransportPlugin *tp;
3425 struct GNUNET_MessageHeader *prem;
3431 ps = ntohs (pong->header.size);
3432 if (ps < sizeof (struct TransportPongMessage))
3434 GNUNET_break_op (0);
3437 addr = (const char*) &pong[1];
3438 slen = strlen (ve->transport_name) + 1;
3439 if ( (ps - sizeof (struct TransportPongMessage) != ve->addrlen + slen) ||
3440 (ve->challenge != challenge) ||
3441 (addr[slen-1] != '\0') ||
3442 (0 != strcmp (addr, ve->transport_name)) ||
3443 (ntohl (pong->purpose.size)
3444 != sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
3446 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
3447 sizeof (struct GNUNET_PeerIdentity) + ve->addrlen + slen) )
3449 alen = ps - sizeof (struct TransportPongMessage) - slen;
3450 switch (ntohl (pong->purpose.purpose))
3452 case GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN:
3453 if ( (ve->addrlen + slen != ntohl (pong->addrlen)) ||
3454 (0 != memcmp (&addr[slen],
3457 return GNUNET_YES; /* different entry, keep trying! */
3458 if (0 != memcmp (&pong->pid,
3460 sizeof (struct GNUNET_PeerIdentity)))
3462 GNUNET_break_op (0);
3466 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
3471 GNUNET_break_op (0);
3475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3476 "Confirmed validity of address, peer `%4s' has address `%s' (%s).\n",
3478 a2s (ve->transport_name,
3479 (const struct sockaddr *) ve->addr,
3481 ve->transport_name);
3484 case GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING:
3485 if (ve->addrlen != 0)
3486 return GNUNET_YES; /* different entry, keep trying */
3487 if ( (0 != memcmp (&pong->pid,
3489 sizeof (struct GNUNET_PeerIdentity))) ||
3490 (ve->addrlen != 0) )
3492 GNUNET_break_op (0);
3495 tp = find_transport (ve->transport_name);
3501 oal = tp->addresses;
3504 if ( (oal->addrlen == alen) &&
3505 (0 == memcmp (&oal[1],
3513 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3514 _("Not accepting PONG with address `%s' since I cannot confirm having this address.\n"),
3515 a2s (ve->transport_name,
3521 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING,
3526 GNUNET_break_op (0);
3530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3531 "Confirmed that peer `%4s' is talking to us using address `%s' (%s) for us.\n",
3533 a2s (ve->transport_name,
3536 ve->transport_name);
3540 GNUNET_break_op (0);
3543 if (GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (pong->expiration)).value == 0)
3545 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3546 _("Received expired signature. Check system time.\n"));
3549 GNUNET_STATISTICS_update (stats,
3550 gettext_noop ("# address validation successes"),
3553 /* create the updated HELLO */
3554 GNUNET_CRYPTO_hash (&ve->publicKey,
3555 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
3556 &target.hashPubKey);
3557 if (ve->addr != NULL)
3559 avac.done = GNUNET_NO;
3561 hello = GNUNET_HELLO_create (&ve->publicKey,
3562 &add_validated_address,
3564 GNUNET_PEERINFO_add_peer (peerinfo,
3566 GNUNET_free (hello);
3568 n = find_neighbour (&target);
3571 n->publicKey = ve->publicKey;
3572 n->public_key_valid = GNUNET_YES;
3573 fal = add_peer_address (n,
3578 GNUNET_assert (fal != NULL);
3579 fal->expires = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
3580 fal->validated = GNUNET_YES;
3581 mark_address_connected (fal);
3582 GNUNET_STATISTICS_update (stats,
3583 gettext_noop ("# peer addresses considered valid"),
3586 fal->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
3587 schedule_next_ping (fal);
3588 if (n->latency.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
3589 n->latency = fal->latency;
3591 n->latency.value = (fal->latency.value + n->latency.value) / 2;
3593 n->distance = fal->distance;
3594 if (GNUNET_NO == n->received_pong)
3596 n->received_pong = GNUNET_YES;
3597 notify_clients_connect (&target, n->latency, n->distance);
3598 if (NULL != (prem = n->pre_connect_message_buffer))
3600 n->pre_connect_message_buffer = NULL;
3601 handle_payload_message (prem, n);
3605 if (n->retry_task != GNUNET_SCHEDULER_NO_TASK)
3607 GNUNET_SCHEDULER_cancel (sched,
3609 n->retry_task = GNUNET_SCHEDULER_NO_TASK;
3610 try_transmission_to_peer (n);
3614 /* clean up validation entry */
3615 GNUNET_assert (GNUNET_YES ==
3616 GNUNET_CONTAINER_multihashmap_remove (validation_map,
3619 abort_validation (NULL, NULL, ve);
3625 * Function that will be called if we receive a validation
3626 * of an address challenge that we transmitted to another
3627 * peer. Note that the validation should only be considered
3628 * acceptable if the challenge matches AND if the sender
3629 * address is at least a plausible address for this peer
3630 * (otherwise we may be seeing a MiM attack).
3632 * @param cls closure
3633 * @param message the pong message
3634 * @param peer who responded to our challenge
3635 * @param sender_address string describing our sender address (as observed
3636 * by the other peer in binary format)
3637 * @param sender_address_len number of bytes in 'sender_address'
3640 handle_pong (void *cls, const struct GNUNET_MessageHeader *message,
3641 const struct GNUNET_PeerIdentity *peer,
3642 const char *sender_address,
3643 size_t sender_address_len)
3645 #if DEBUG_TRANSPORT > 1
3646 /* we get tons of these that just get discarded, only log
3647 if we are quite verbose */
3648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3649 "Receiving `%s' message from `%4s'.\n", "PONG",
3652 GNUNET_STATISTICS_update (stats,
3653 gettext_noop ("# PONG messages received"),
3656 if (GNUNET_SYSERR !=
3657 GNUNET_CONTAINER_multihashmap_get_multiple (validation_map,
3659 &check_pending_validation,
3662 /* This is *expected* to happen a lot since we send
3663 PONGs to *all* known addresses of the sender of
3664 the PING, so most likely we get multiple PONGs
3665 per PING, and all but the first PONG will end up
3666 here. So really we should not print anything here
3667 unless we want to be very, very verbose... */
3668 #if DEBUG_TRANSPORT > 2
3669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3670 "Received `%s' message from `%4s' but have no record of a matching `%s' message. Ignoring.\n",
3682 * Try to validate a neighbour's address by sending him our HELLO and a PING.
3684 * @param cls the 'struct ValidationEntry*'
3685 * @param neighbour neighbour to validate, NULL if validation failed
3688 transmit_hello_and_ping (void *cls,
3689 struct NeighbourList *neighbour)
3691 struct ValidationEntry *va = cls;
3692 struct ForeignAddressList *peer_address;
3693 struct TransportPingMessage ping;
3694 uint16_t hello_size;
3697 struct GNUNET_PeerIdentity id;
3700 GNUNET_CRYPTO_hash (&va->publicKey,
3701 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
3703 if (neighbour == NULL)
3705 /* FIXME: stats... */
3706 GNUNET_break (GNUNET_OK ==
3707 GNUNET_CONTAINER_multihashmap_remove (validation_map,
3710 abort_validation (NULL, NULL, va);
3713 neighbour->publicKey = va->publicKey;
3714 neighbour->public_key_valid = GNUNET_YES;
3715 peer_address = add_peer_address (neighbour,
3716 va->transport_name, NULL,
3717 (const void*) &va[1],
3719 if (peer_address == NULL)
3721 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3722 "Failed to add peer `%4s' for plugin `%s'\n",
3723 GNUNET_i2s (&neighbour->id),
3724 va->transport_name);
3725 GNUNET_break (GNUNET_OK ==
3726 GNUNET_CONTAINER_multihashmap_remove (validation_map,
3729 abort_validation (NULL, NULL, va);
3732 hello_size = GNUNET_HELLO_size(our_hello);
3733 slen = strlen(va->transport_name) + 1;
3734 tsize = sizeof(struct TransportPingMessage) + hello_size + va->addrlen + slen;
3735 message_buf = GNUNET_malloc(tsize);
3736 ping.challenge = htonl(va->challenge);
3737 ping.header.size = htons(sizeof(struct TransportPingMessage) + slen + va->addrlen);
3738 ping.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
3739 memcpy(&ping.target, &neighbour->id, sizeof(struct GNUNET_PeerIdentity));
3740 memcpy(message_buf, our_hello, hello_size);
3741 memcpy(&message_buf[hello_size],
3743 sizeof(struct TransportPingMessage));
3744 memcpy(&message_buf[hello_size + sizeof (struct TransportPingMessage)],
3747 memcpy(&message_buf[hello_size + sizeof (struct TransportPingMessage) + slen],
3751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3752 "Performing validation of address `%s' via `%s' for peer `%4s' sending `%s' (%u bytes) and `%s' (%u bytes)\n",
3755 : a2s (va->transport_name,
3756 (const void*) &va[1], va->addrlen),
3758 GNUNET_i2s (&neighbour->id),
3759 "HELLO", hello_size,
3760 "PING", sizeof (struct TransportPingMessage) + va->addrlen + slen);
3763 GNUNET_STATISTICS_update (stats,
3764 gettext_noop ("# PING messages sent for initial validation"),
3767 transmit_to_peer (NULL, peer_address,
3768 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
3769 HELLO_VERIFICATION_TIMEOUT,
3771 GNUNET_YES, neighbour);
3772 GNUNET_free(message_buf);
3777 * Check if the given address is already being validated; if not,
3778 * append the given address to the list of entries that are being be
3779 * validated and initiate validation.
3781 * @param cls closure ('struct CheckHelloValidatedContext *')
3782 * @param tname name of the transport
3783 * @param expiration expiration time
3784 * @param addr the address
3785 * @param addrlen length of the address
3786 * @return GNUNET_OK (always)
3789 run_validation (void *cls,
3791 struct GNUNET_TIME_Absolute expiration,
3795 struct CheckHelloValidatedContext *chvc = cls;
3796 struct GNUNET_PeerIdentity id;
3797 struct TransportPlugin *tp;
3798 struct ValidationEntry *va;
3799 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk;
3800 struct CheckAddressExistsClosure caec;
3801 struct OwnAddressList *oal;
3803 GNUNET_assert (addr != NULL);
3805 GNUNET_STATISTICS_update (stats,
3806 gettext_noop ("# peer addresses scheduled for validation"),
3809 tp = find_transport (tname);
3812 GNUNET_log (GNUNET_ERROR_TYPE_INFO |
3813 GNUNET_ERROR_TYPE_BULK,
3815 ("Transport `%s' not loaded, will not try to validate peer address using this transport.\n"),
3817 GNUNET_STATISTICS_update (stats,
3818 gettext_noop ("# peer addresses not validated (plugin not available)"),
3823 /* check if this is one of our own addresses */
3824 oal = tp->addresses;
3827 if ( (oal->addrlen == addrlen) &&
3828 (0 == memcmp (&oal[1],
3832 /* not plausible, this address is equivalent to our own address! */
3833 GNUNET_STATISTICS_update (stats,
3834 gettext_noop ("# peer addresses not validated (loopback)"),
3841 GNUNET_HELLO_get_key (chvc->hello, &pk);
3842 GNUNET_CRYPTO_hash (&pk,
3844 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
3847 if (is_blacklisted(&id, tp))
3850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3851 "Attempted to validate blacklisted peer `%s' using `%s'!\n",
3859 caec.addrlen = addrlen;
3860 caec.session = NULL;
3862 caec.exists = GNUNET_NO;
3863 GNUNET_CONTAINER_multihashmap_iterate (validation_map,
3864 &check_address_exists,
3866 if (caec.exists == GNUNET_YES)
3868 /* During validation attempts we will likely trigger the other
3869 peer trying to validate our address which in turn will cause
3870 it to send us its HELLO, so we expect to hit this case rather
3871 frequently. Only print something if we are very verbose. */
3872 #if DEBUG_TRANSPORT > 1
3873 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3874 "Validation of address `%s' via `%s' for peer `%4s' already in progress.\n",
3875 a2s (tname, addr, addrlen),
3879 GNUNET_STATISTICS_update (stats,
3880 gettext_noop ("# peer addresses not validated (in progress)"),
3885 va = GNUNET_malloc (sizeof (struct ValidationEntry) + addrlen);
3888 va->transport_name = GNUNET_strdup (tname);
3889 va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
3891 va->send_time = GNUNET_TIME_absolute_get();
3892 va->addr = (const void*) &va[1];
3893 memcpy (&va[1], addr, addrlen);
3894 va->addrlen = addrlen;
3895 GNUNET_HELLO_get_key (chvc->hello,
3897 va->timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
3898 HELLO_VERIFICATION_TIMEOUT,
3899 &timeout_hello_validation,
3901 GNUNET_CONTAINER_multihashmap_put (validation_map,
3904 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
3905 setup_peer_check_blacklist (&id, GNUNET_NO,
3906 &transmit_hello_and_ping,
3913 * Check if addresses in validated hello "h" overlap with
3914 * those in "chvc->hello" and validate the rest.
3916 * @param cls closure
3917 * @param peer id of the peer, NULL for last call
3918 * @param h hello message for the peer (can be NULL)
3921 check_hello_validated (void *cls,
3922 const struct GNUNET_PeerIdentity *peer,
3923 const struct GNUNET_HELLO_Message *h)
3925 struct CheckHelloValidatedContext *chvc = cls;
3926 struct GNUNET_HELLO_Message *plain_hello;
3927 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk;
3928 struct GNUNET_PeerIdentity target;
3929 struct NeighbourList *n;
3934 if (GNUNET_NO == chvc->hello_known)
3936 /* notify PEERINFO about the peer now, so that we at least
3937 have the public key if some other component needs it */
3938 GNUNET_HELLO_get_key (chvc->hello, &pk);
3939 GNUNET_CRYPTO_hash (&pk,
3940 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
3941 &target.hashPubKey);
3942 plain_hello = GNUNET_HELLO_create (&pk,
3945 GNUNET_PEERINFO_add_peer (peerinfo, plain_hello);
3946 GNUNET_free (plain_hello);
3948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3949 "PEERINFO had no `%s' message for peer `%4s', full validation needed.\n",
3951 GNUNET_i2s (&target));
3953 GNUNET_STATISTICS_update (stats,
3954 gettext_noop ("# new HELLOs requiring full validation"),
3957 GNUNET_HELLO_iterate_addresses (chvc->hello,
3964 GNUNET_STATISTICS_update (stats,
3965 gettext_noop ("# duplicate HELLO (peer known)"),
3970 if (chvc->ve_count == 0)
3972 GNUNET_CONTAINER_DLL_remove (chvc_head,
3982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3983 "PEERINFO had `%s' message for peer `%4s', validating only new addresses.\n",
3987 chvc->hello_known = GNUNET_YES;
3988 n = find_neighbour (peer);
3991 GNUNET_HELLO_iterate_addresses (h,
3993 &add_to_foreign_address_list,
3995 try_transmission_to_peer (n);
3999 GNUNET_STATISTICS_update (stats,
4000 gettext_noop ("# no existing neighbour record (validating HELLO)"),
4004 GNUNET_STATISTICS_update (stats,
4005 gettext_noop ("# HELLO validations (update case)"),
4008 GNUNET_HELLO_iterate_new_addresses (chvc->hello,
4010 GNUNET_TIME_relative_to_absolute (HELLO_REVALIDATION_START_TIME),
4017 * Process HELLO-message.
4019 * @param plugin transport involved, may be NULL
4020 * @param message the actual message
4021 * @return GNUNET_OK if the HELLO was well-formed, GNUNET_SYSERR otherwise
4024 process_hello (struct TransportPlugin *plugin,
4025 const struct GNUNET_MessageHeader *message)
4028 struct GNUNET_PeerIdentity target;
4029 const struct GNUNET_HELLO_Message *hello;
4030 struct CheckHelloValidatedContext *chvc;
4031 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded publicKey;
4032 #if DEBUG_TRANSPORT_HELLO
4035 hsize = ntohs (message->size);
4036 if ((ntohs (message->type) != GNUNET_MESSAGE_TYPE_HELLO) ||
4037 (hsize < sizeof (struct GNUNET_MessageHeader)))
4040 return GNUNET_SYSERR;
4042 GNUNET_STATISTICS_update (stats,
4043 gettext_noop ("# HELLOs received for validation"),
4047 /* first, check if load is too high */
4048 if (GNUNET_SCHEDULER_get_load (sched,
4049 GNUNET_SCHEDULER_PRIORITY_BACKGROUND) > MAX_HELLO_LOAD)
4051 GNUNET_STATISTICS_update (stats,
4052 gettext_noop ("# HELLOs ignored due to high load"),
4055 #if DEBUG_TRANSPORT_HELLO
4056 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4057 "Ignoring `%s' for `%4s', load too high.\n",
4059 GNUNET_i2s (&target));
4063 hello = (const struct GNUNET_HELLO_Message *) message;
4064 if (GNUNET_OK != GNUNET_HELLO_get_key (hello, &publicKey))
4066 #if DEBUG_TRANSPORT_HELLO
4067 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4068 "Unable to get public key from `%s' for `%4s'!\n",
4070 GNUNET_i2s (&target));
4072 GNUNET_break_op (0);
4073 return GNUNET_SYSERR;
4076 GNUNET_CRYPTO_hash (&publicKey,
4077 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
4078 &target.hashPubKey);
4080 if (0 == memcmp (&my_identity,
4082 sizeof (struct GNUNET_PeerIdentity)))
4084 GNUNET_STATISTICS_update (stats,
4085 gettext_noop ("# HELLOs ignored for validation (is my own HELLO)"),
4091 while (NULL != chvc)
4093 if (GNUNET_HELLO_equals (hello,
4095 GNUNET_TIME_absolute_get ()).value > 0)
4097 #if DEBUG_TRANSPORT_HELLO
4098 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4099 "Received duplicate `%s' message for `%4s'; ignored\n",
4101 GNUNET_i2s (&target));
4103 return GNUNET_OK; /* validation already pending */
4105 if (GNUNET_HELLO_size(hello) == GNUNET_HELLO_size (chvc->hello))
4106 GNUNET_break (0 != memcmp (hello, chvc->hello,
4107 GNUNET_HELLO_size(hello)));
4110 #if DEBUG_TRANSPORT_HELLO
4113 my_id = GNUNET_strdup(GNUNET_i2s(plugin->env.my_identity));
4114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4115 "%s: Starting validation of `%s' message for `%4s' via '%s' of size %u\n",
4118 GNUNET_i2s (&target),
4120 GNUNET_HELLO_size(hello));
4124 chvc = GNUNET_malloc (sizeof (struct CheckHelloValidatedContext) + hsize);
4126 chvc->hello = (const struct GNUNET_HELLO_Message *) &chvc[1];
4127 memcpy (&chvc[1], hello, hsize);
4128 GNUNET_CONTAINER_DLL_insert (chvc_head,
4131 /* finally, check if HELLO was previously validated
4132 (continuation will then schedule actual validation) */
4133 chvc->piter = GNUNET_PEERINFO_iterate (peerinfo,
4135 HELLO_VERIFICATION_TIMEOUT,
4136 &check_hello_validated, chvc);
4142 * The peer specified by the given neighbour has timed-out or a plugin
4143 * has disconnected. We may either need to do nothing (other plugins
4144 * still up), or trigger a full disconnect and clean up. This
4145 * function updates our state and does the necessary notifications.
4146 * Also notifies our clients that the neighbour is now officially
4149 * @param n the neighbour list entry for the peer
4150 * @param check should we just check if all plugins
4151 * disconnected or must we ask all plugins to
4155 disconnect_neighbour (struct NeighbourList *n, int check)
4157 struct ReadyList *rpos;
4158 struct NeighbourList *npos;
4159 struct NeighbourList *nprev;
4160 struct MessageQueue *mq;
4161 struct ForeignAddressList *peer_addresses;
4162 struct ForeignAddressList *peer_pos;
4164 if (GNUNET_YES == check)
4167 while (NULL != rpos)
4169 peer_addresses = rpos->addresses;
4170 while (peer_addresses != NULL)
4172 if (GNUNET_YES == peer_addresses->connected)
4173 return; /* still connected */
4174 peer_addresses = peer_addresses->next;
4180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
4181 "Disconnecting from `%4s'\n",
4182 GNUNET_i2s (&n->id));
4184 /* remove n from neighbours list */
4187 while ((npos != NULL) && (npos != n))
4192 GNUNET_assert (npos != NULL);
4194 neighbours = n->next;
4196 nprev->next = n->next;
4198 /* notify all clients about disconnect */
4199 if (GNUNET_YES == n->received_pong)
4200 notify_clients_disconnect (&n->id);
4202 /* clean up all plugins, cancel connections and pending transmissions */
4203 while (NULL != (rpos = n->plugins))
4205 n->plugins = rpos->next;
4206 rpos->plugin->api->disconnect (rpos->plugin->api->cls, &n->id);
4207 while (rpos->addresses != NULL)
4209 peer_pos = rpos->addresses;
4210 rpos->addresses = peer_pos->next;
4211 if (peer_pos->connected == GNUNET_YES)
4212 GNUNET_STATISTICS_update (stats,
4213 gettext_noop ("# connected addresses"),
4216 if (GNUNET_YES == peer_pos->validated)
4217 GNUNET_STATISTICS_update (stats,
4218 gettext_noop ("# peer addresses considered valid"),
4221 if (GNUNET_SCHEDULER_NO_TASK != peer_pos->revalidate_task)
4223 GNUNET_SCHEDULER_cancel (sched,
4224 peer_pos->revalidate_task);
4225 peer_pos->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
4227 GNUNET_free(peer_pos);
4232 /* free all messages on the queue */
4233 while (NULL != (mq = n->messages_head))
4235 GNUNET_STATISTICS_update (stats,
4236 gettext_noop ("# bytes in message queue for other peers"),
4237 - (int64_t) mq->message_buf_size,
4239 GNUNET_STATISTICS_update (stats,
4240 gettext_noop ("# bytes discarded due to disconnect"),
4241 mq->message_buf_size,
4243 GNUNET_CONTAINER_DLL_remove (n->messages_head,
4246 GNUNET_assert (0 == memcmp(&mq->neighbour_id,
4248 sizeof(struct GNUNET_PeerIdentity)));
4251 if (n->timeout_task != GNUNET_SCHEDULER_NO_TASK)
4253 GNUNET_SCHEDULER_cancel (sched, n->timeout_task);
4254 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
4256 if (n->retry_task != GNUNET_SCHEDULER_NO_TASK)
4258 GNUNET_SCHEDULER_cancel (sched, n->retry_task);
4259 n->retry_task = GNUNET_SCHEDULER_NO_TASK;
4261 if (n->piter != NULL)
4263 GNUNET_PEERINFO_iterate_cancel (n->piter);
4266 /* finally, free n itself */
4267 GNUNET_STATISTICS_update (stats,
4268 gettext_noop ("# active neighbours"),
4271 GNUNET_free_non_null (n->pre_connect_message_buffer);
4277 * We have received a PING message from someone. Need to send a PONG message
4278 * in response to the peer by any means necessary.
4281 handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
4282 const struct GNUNET_PeerIdentity *peer,
4283 struct Session *session,
4284 const char *sender_address,
4285 uint16_t sender_address_len)
4287 struct TransportPlugin *plugin = cls;
4288 struct SessionHeader *session_header = (struct SessionHeader*) session;
4289 struct TransportPingMessage *ping;
4290 struct TransportPongMessage *pong;
4291 struct NeighbourList *n;
4292 struct ReadyList *rl;
4293 struct ForeignAddressList *fal;
4294 struct OwnAddressList *oal;
4299 if (ntohs (message->size) < sizeof (struct TransportPingMessage))
4301 GNUNET_break_op (0);
4302 return GNUNET_SYSERR;
4305 ping = (struct TransportPingMessage *) message;
4306 if (0 != memcmp (&ping->target,
4307 plugin->env.my_identity,
4308 sizeof (struct GNUNET_PeerIdentity)))
4310 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
4311 _("Received `%s' message not destined for me!\n"),
4313 return GNUNET_SYSERR;
4316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
4317 "Processing `%s' from `%s'\n",
4319 (sender_address != NULL)
4320 ? a2s (plugin->short_name,
4321 (const struct sockaddr *)sender_address,
4325 GNUNET_STATISTICS_update (stats,
4326 gettext_noop ("# PING messages received"),
4329 addr = (const char*) &ping[1];
4330 alen = ntohs (message->size) - sizeof (struct TransportPingMessage);
4331 slen = strlen (plugin->short_name) + 1;
4334 /* peer wants to confirm that we have an outbound connection to him */
4335 if (session == NULL)
4337 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
4338 _("Refusing to create PONG since I do not have a session with `%s'.\n"),
4340 return GNUNET_SYSERR;
4342 pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + sender_address_len + slen);
4343 pong->header.size = htons (sizeof (struct TransportPongMessage) + sender_address_len + slen);
4344 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
4345 pong->purpose.size =
4346 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
4348 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
4349 sizeof (struct GNUNET_PeerIdentity) + sender_address_len + slen);
4350 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING);
4351 pong->challenge = ping->challenge;
4352 pong->addrlen = htonl(sender_address_len + slen);
4355 sizeof(struct GNUNET_PeerIdentity));
4359 memcpy (&((char*)&pong[1])[slen],
4361 sender_address_len);
4362 if (GNUNET_TIME_absolute_get_remaining (session_header->pong_sig_expires).value < PONG_SIGNATURE_LIFETIME.value / 4)
4364 /* create / update cached sig */
4366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4367 "Creating PONG signature to indicate active connection.\n");
4369 session_header->pong_sig_expires = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME);
4370 pong->expiration = GNUNET_TIME_absolute_hton (session_header->pong_sig_expires);
4371 GNUNET_assert (GNUNET_OK ==
4372 GNUNET_CRYPTO_rsa_sign (my_private_key,
4374 &session_header->pong_signature));
4378 pong->expiration = GNUNET_TIME_absolute_hton (session_header->pong_sig_expires);
4380 memcpy (&pong->signature,
4381 &session_header->pong_signature,
4382 sizeof (struct GNUNET_CRYPTO_RsaSignature));
4388 /* peer wants to confirm that this is one of our addresses */
4392 plugin->api->check_address (plugin->api->cls,
4396 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
4397 _("Not confirming PING with address `%s' since I cannot confirm having this address.\n"),
4398 a2s (plugin->short_name,
4403 oal = plugin->addresses;
4406 if ( (oal->addrlen == alen) &&
4413 pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + alen + slen);
4414 pong->header.size = htons (sizeof (struct TransportPongMessage) + alen + slen);
4415 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
4416 pong->purpose.size =
4417 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
4419 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
4420 sizeof (struct GNUNET_PeerIdentity) + alen + slen);
4421 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
4422 pong->challenge = ping->challenge;
4423 pong->addrlen = htonl(alen + slen);
4426 sizeof(struct GNUNET_PeerIdentity));
4427 memcpy (&pong[1], plugin->short_name, slen);
4428 memcpy (&((char*)&pong[1])[slen], addr, alen);
4429 if ( (oal != NULL) &&
4430 (GNUNET_TIME_absolute_get_remaining (oal->pong_sig_expires).value < PONG_SIGNATURE_LIFETIME.value / 4) )
4432 /* create / update cached sig */
4434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4435 "Creating PONG signature to indicate ownership.\n");
4437 oal->pong_sig_expires = GNUNET_TIME_absolute_min (oal->expires,
4438 GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME));
4439 pong->expiration = GNUNET_TIME_absolute_hton (oal->pong_sig_expires);
4440 GNUNET_assert (GNUNET_OK ==
4441 GNUNET_CRYPTO_rsa_sign (my_private_key,
4443 &oal->pong_signature));
4444 memcpy (&pong->signature,
4445 &oal->pong_signature,
4446 sizeof (struct GNUNET_CRYPTO_RsaSignature));
4448 else if (oal == NULL)
4450 /* not using cache (typically DV-only) */
4451 pong->expiration = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME));
4452 GNUNET_assert (GNUNET_OK ==
4453 GNUNET_CRYPTO_rsa_sign (my_private_key,
4459 /* can used cached version */
4460 pong->expiration = GNUNET_TIME_absolute_hton (oal->pong_sig_expires);
4461 memcpy (&pong->signature,
4462 &oal->pong_signature,
4463 sizeof (struct GNUNET_CRYPTO_RsaSignature));
4466 n = find_neighbour(peer);
4467 GNUNET_assert (n != NULL);
4468 /* first try reliable response transmission */
4472 fal = rl->addresses;
4475 if (-1 != rl->plugin->api->send (rl->plugin->api->cls,
4478 ntohs (pong->header.size),
4479 TRANSPORT_PONG_PRIORITY,
4480 HELLO_VERIFICATION_TIMEOUT,
4488 GNUNET_STATISTICS_update (stats,
4489 gettext_noop ("# PONGs unicast via reliable transport"),
4499 /* no reliable method found, do multicast */
4500 GNUNET_STATISTICS_update (stats,
4501 gettext_noop ("# PONGs multicast to all available addresses"),
4507 fal = rl->addresses;
4510 transmit_to_peer(NULL, fal,
4511 TRANSPORT_PONG_PRIORITY,
4512 HELLO_VERIFICATION_TIMEOUT,
4514 ntohs(pong->header.size),
4527 * Function called by the plugin for each received message.
4528 * Update data volumes, possibly notify plugins about
4529 * reducing the rate at which they read from the socket
4530 * and generally forward to our receive callback.
4532 * @param cls the "struct TransportPlugin *" we gave to the plugin
4533 * @param peer (claimed) identity of the other peer
4534 * @param message the message, NULL if we only care about
4535 * learning about the delay until we should receive again
4536 * @param distance in overlay hops; use 1 unless DV (or 0 if message == NULL)
4537 * @param session identifier used for this session (can be NULL)
4538 * @param sender_address binary address of the sender (if observed)
4539 * @param sender_address_len number of bytes in sender_address
4540 * @return how long the plugin should wait until receiving more data
4541 * (plugins that do not support this, can ignore the return value)
4543 static struct GNUNET_TIME_Relative
4544 plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
4545 const struct GNUNET_MessageHeader *message,
4547 struct Session *session,
4548 const char *sender_address,
4549 uint16_t sender_address_len)
4551 struct TransportPlugin *plugin = cls;
4552 struct ReadyList *service_context;
4553 struct ForeignAddressList *peer_address;
4555 struct NeighbourList *n;
4556 struct GNUNET_TIME_Relative ret;
4558 if (is_blacklisted (peer, plugin))
4559 return GNUNET_TIME_UNIT_FOREVER_REL;
4561 n = find_neighbour (peer);
4563 n = setup_new_neighbour (peer, GNUNET_YES);
4564 service_context = n->plugins;
4565 while ((service_context != NULL) && (plugin != service_context->plugin))
4566 service_context = service_context->next;
4567 GNUNET_assert ((plugin->api->send == NULL) || (service_context != NULL));
4568 peer_address = NULL;
4569 if (message != NULL)
4571 if ( (session != NULL) ||
4572 (sender_address != NULL) )
4573 peer_address = add_peer_address (n,
4577 sender_address_len);
4578 if (peer_address != NULL)
4580 peer_address->distance = distance;
4581 if (GNUNET_YES == peer_address->validated)
4582 mark_address_connected (peer_address);
4583 peer_address->timeout
4585 GNUNET_TIME_relative_to_absolute
4586 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
4587 schedule_next_ping (peer_address);
4589 /* update traffic received amount ... */
4590 msize = ntohs (message->size);
4591 GNUNET_STATISTICS_update (stats,
4592 gettext_noop ("# bytes received from other peers"),
4595 n->distance = distance;
4597 GNUNET_TIME_relative_to_absolute
4598 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
4599 GNUNET_SCHEDULER_cancel (sched,
4602 GNUNET_SCHEDULER_add_delayed (sched,
4603 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
4604 &neighbour_timeout_task, n);
4605 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
4607 /* dropping message due to frequent inbound volume violations! */
4608 GNUNET_log (GNUNET_ERROR_TYPE_WARNING |
4609 GNUNET_ERROR_TYPE_BULK,
4611 ("Dropping incoming message due to repeated bandwidth quota (%u b/s) violations (total of %u).\n"),
4612 n->in_tracker.available_bytes_per_s__,
4613 n->quota_violation_count);
4614 GNUNET_STATISTICS_update (stats,
4615 gettext_noop ("# bandwidth quota violations by other peers"),
4618 return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT;
4621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4622 "Received message of type %u and size %u from `%4s', sending to all clients.\n",
4623 ntohs (message->type),
4624 ntohs (message->size),
4627 switch (ntohs (message->type))
4629 case GNUNET_MESSAGE_TYPE_HELLO:
4630 GNUNET_STATISTICS_update (stats,
4631 gettext_noop ("# HELLO messages received from other peers"),
4634 process_hello (plugin, message);
4636 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
4637 handle_ping (plugin, message, peer, session, sender_address, sender_address_len);
4639 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
4640 handle_pong (plugin, message, peer, sender_address, sender_address_len);
4643 handle_payload_message (message, n);
4647 ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 0);
4650 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
4651 "Throttling read (%llu bytes excess at %u b/s), waiting %llums before reading more.\n",
4652 (unsigned long long) n->in_tracker.consumption_since_last_update__,
4653 (unsigned int) n->in_tracker.available_bytes_per_s__,
4654 (unsigned long long) ret.value);
4655 GNUNET_STATISTICS_update (stats,
4656 gettext_noop ("# ms throttling suggested"),
4657 (int64_t) ret.value,
4664 * Handle START-message. This is the first message sent to us
4665 * by any client which causes us to add it to our list.
4667 * @param cls closure (always NULL)
4668 * @param client identification of the client
4669 * @param message the actual message
4672 handle_start (void *cls,
4673 struct GNUNET_SERVER_Client *client,
4674 const struct GNUNET_MessageHeader *message)
4676 const struct StartMessage *start;
4677 struct TransportClient *c;
4678 struct ConnectInfoMessage cim;
4679 struct NeighbourList *n;
4681 start = (const struct StartMessage*) message;
4683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4684 "Received `%s' request from client\n", "START");
4689 if (c->client == client)
4691 /* client already on our list! */
4693 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
4698 if ( (GNUNET_NO != ntohl (start->do_check)) &&
4699 (0 != memcmp (&start->self,
4701 sizeof (struct GNUNET_PeerIdentity))) )
4703 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
4704 _("Rejecting control connection from peer `%s', which is not me!\n"),
4705 GNUNET_i2s (&start->self));
4706 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
4709 c = GNUNET_malloc (sizeof (struct TransportClient));
4713 if (our_hello != NULL)
4716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4717 "Sending our own `%s' to new client\n", "HELLO");
4719 transmit_to_client (c,
4720 (const struct GNUNET_MessageHeader *) our_hello,
4722 /* tell new client about all existing connections */
4723 cim.header.size = htons (sizeof (struct ConnectInfoMessage));
4724 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
4728 if (GNUNET_YES == n->received_pong)
4731 cim.latency = GNUNET_TIME_relative_hton (n->latency);
4732 cim.distance = htonl (n->distance);
4733 transmit_to_client (c, &cim.header, GNUNET_NO);
4738 GNUNET_SERVER_receive_done (client, GNUNET_OK);
4743 * Handle HELLO-message.
4745 * @param cls closure (always NULL)
4746 * @param client identification of the client
4747 * @param message the actual message
4750 handle_hello (void *cls,
4751 struct GNUNET_SERVER_Client *client,
4752 const struct GNUNET_MessageHeader *message)
4756 GNUNET_STATISTICS_update (stats,
4757 gettext_noop ("# HELLOs received from clients"),
4760 ret = process_hello (NULL, message);
4761 GNUNET_SERVER_receive_done (client, ret);
4766 * Closure for 'transmit_client_message'; followed by
4767 * 'msize' bytes of the actual message.
4769 struct TransmitClientMessageContext
4772 * Client on whom's behalf we are sending.
4774 struct GNUNET_SERVER_Client *client;
4777 * Timeout for the transmission.
4779 struct GNUNET_TIME_Absolute timeout;
4787 * Size of the message in bytes.
4794 * Schedule transmission of a message we got from a client to a peer.
4796 * @param cls the 'struct TransmitClientMessageContext*'
4797 * @param n destination, or NULL on error (in that case, drop the message)
4800 transmit_client_message (void *cls,
4801 struct NeighbourList *n)
4803 struct TransmitClientMessageContext *tcmc = cls;
4804 struct TransportClient *tc;
4807 while ((tc != NULL) && (tc->client != tcmc->client))
4812 transmit_to_peer (tc, NULL, tcmc->priority,
4813 GNUNET_TIME_absolute_get_remaining (tcmc->timeout),
4815 tcmc->msize, GNUNET_NO, n);
4817 GNUNET_SERVER_receive_done (tcmc->client, GNUNET_OK);
4818 GNUNET_SERVER_client_drop (tcmc->client);
4824 * Handle SEND-message.
4826 * @param cls closure (always NULL)
4827 * @param client identification of the client
4828 * @param message the actual message
4831 handle_send (void *cls,
4832 struct GNUNET_SERVER_Client *client,
4833 const struct GNUNET_MessageHeader *message)
4835 const struct OutboundMessage *obm;
4836 const struct GNUNET_MessageHeader *obmm;
4837 struct TransmitClientMessageContext *tcmc;
4841 size = ntohs (message->size);
4843 sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader))
4846 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
4849 GNUNET_STATISTICS_update (stats,
4850 gettext_noop ("# payload received for other peers"),
4853 obm = (const struct OutboundMessage *) message;
4854 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
4855 msize = size - sizeof (struct OutboundMessage);
4857 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4858 "Received `%s' request from client with target `%4s' and message of type %u and size %u\n",
4859 "SEND", GNUNET_i2s (&obm->peer),
4863 tcmc = GNUNET_malloc (sizeof (struct TransmitClientMessageContext) + msize);
4864 tcmc->client = client;
4865 tcmc->priority = ntohl (obm->priority);
4866 tcmc->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_ntoh (obm->timeout));
4867 tcmc->msize = msize;
4868 /* FIXME: this memcpy can be up to 7% of our total runtime */
4869 memcpy (&tcmc[1], obmm, msize);
4870 GNUNET_SERVER_client_keep (client);
4871 setup_peer_check_blacklist (&obm->peer, GNUNET_YES,
4872 &transmit_client_message,
4878 * Handle SET_QUOTA-message.
4880 * @param cls closure (always NULL)
4881 * @param client identification of the client
4882 * @param message the actual message
4885 handle_set_quota (void *cls,
4886 struct GNUNET_SERVER_Client *client,
4887 const struct GNUNET_MessageHeader *message)
4889 const struct QuotaSetMessage *qsm =
4890 (const struct QuotaSetMessage *) message;
4891 struct NeighbourList *n;
4893 GNUNET_STATISTICS_update (stats,
4894 gettext_noop ("# SET QUOTA messages received"),
4897 n = find_neighbour (&qsm->peer);
4900 GNUNET_SERVER_receive_done (client, GNUNET_OK);
4901 GNUNET_STATISTICS_update (stats,
4902 gettext_noop ("# SET QUOTA messages ignored (no such peer)"),
4908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4909 "Received `%s' request (new quota %u, old quota %u) from client for peer `%4s'\n",
4911 (unsigned int) ntohl (qsm->quota.value__),
4912 (unsigned int) n->in_tracker.available_bytes_per_s__,
4913 GNUNET_i2s (&qsm->peer));
4915 GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker,
4917 if (0 == ntohl (qsm->quota.value__))
4918 disconnect_neighbour (n, GNUNET_NO);
4919 GNUNET_SERVER_receive_done (client, GNUNET_OK);
4924 * Take the given address and append it to the set of results sent back to
4927 * @param cls the transmission context used ('struct GNUNET_SERVER_TransmitContext*')
4928 * @param address the resolved name, NULL to indicate the last response
4931 transmit_address_to_client (void *cls, const char *address)
4933 struct GNUNET_SERVER_TransmitContext *tc = cls;
4936 if (NULL == address)
4939 slen = strlen (address) + 1;
4941 GNUNET_SERVER_transmit_context_append_data (tc, address, slen,
4942 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
4943 if (NULL == address)
4944 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
4949 * Handle AddressLookup-message.
4951 * @param cls closure (always NULL)
4952 * @param client identification of the client
4953 * @param message the actual message
4956 handle_address_lookup (void *cls,
4957 struct GNUNET_SERVER_Client *client,
4958 const struct GNUNET_MessageHeader *message)
4960 const struct AddressLookupMessage *alum;
4961 struct TransportPlugin *lsPlugin;
4962 const char *nameTransport;
4963 const char *address;
4965 struct GNUNET_SERVER_TransmitContext *tc;
4966 struct GNUNET_TIME_Absolute timeout;
4967 struct GNUNET_TIME_Relative rtimeout;
4970 size = ntohs (message->size);
4971 if (size < sizeof (struct AddressLookupMessage))
4973 GNUNET_break_op (0);
4974 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
4977 alum = (const struct AddressLookupMessage *) message;
4978 uint32_t addressLen = ntohl (alum->addrlen);
4979 if (size <= sizeof (struct AddressLookupMessage) + addressLen)
4981 GNUNET_break_op (0);
4982 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
4985 address = (const char *) &alum[1];
4986 nameTransport = (const char *) &address[addressLen];
4988 [size - sizeof (struct AddressLookupMessage) - addressLen - 1] != '\0')
4990 GNUNET_break_op (0);
4991 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
4994 timeout = GNUNET_TIME_absolute_ntoh (alum->timeout);
4995 rtimeout = GNUNET_TIME_absolute_get_remaining (timeout);
4996 numeric = ntohl (alum->numeric_only);
4997 lsPlugin = find_transport (nameTransport);
4998 if (NULL == lsPlugin)
5000 tc = GNUNET_SERVER_transmit_context_create (client);
5001 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
5002 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
5003 GNUNET_SERVER_transmit_context_run (tc, rtimeout);
5006 tc = GNUNET_SERVER_transmit_context_create (client);
5007 lsPlugin->api->address_pretty_printer (lsPlugin->api->cls,
5009 address, addressLen,
5012 &transmit_address_to_client, tc);
5017 * Setup the environment for this plugin.
5020 create_environment (struct TransportPlugin *plug)
5022 plug->env.cfg = cfg;
5023 plug->env.sched = sched;
5024 plug->env.my_identity = &my_identity;
5025 plug->env.cls = plug;
5026 plug->env.receive = &plugin_env_receive;
5027 plug->env.notify_address = &plugin_env_notify_address;
5028 plug->env.session_end = &plugin_env_session_end;
5029 plug->env.max_connections = max_connect_per_transport;
5030 plug->env.stats = stats;
5035 * Start the specified transport (load the plugin).
5038 start_transport (struct GNUNET_SERVER_Handle *server,
5041 struct TransportPlugin *plug;
5044 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
5045 _("Loading `%s' transport plugin\n"), name);
5046 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", name);
5047 plug = GNUNET_malloc (sizeof (struct TransportPlugin));
5048 create_environment (plug);
5049 plug->short_name = GNUNET_strdup (name);
5050 plug->lib_name = libname;
5051 plug->next = plugins;
5053 plug->api = GNUNET_PLUGIN_load (libname, &plug->env);
5054 if (plug->api == NULL)
5056 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
5057 _("Failed to load transport plugin for `%s'\n"), name);
5058 GNUNET_free (plug->short_name);
5059 plugins = plug->next;
5060 GNUNET_free (libname);
5067 * Called whenever a client is disconnected. Frees our
5068 * resources associated with that client.
5070 * @param cls closure
5071 * @param client identification of the client
5074 client_disconnect_notification (void *cls,
5075 struct GNUNET_SERVER_Client *client)
5077 struct TransportClient *pos;
5078 struct TransportClient *prev;
5079 struct ClientMessageQueueEntry *mqe;
5080 struct Blacklisters *bl;
5081 struct BlacklistCheck *bc;
5086 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
5087 "Client disconnected, cleaning up.\n");
5089 /* clean up blacklister */
5093 if (bl->client == client)
5098 if (bc->bl_pos == bl)
5100 bc->bl_pos = bl->next;
5103 GNUNET_CONNECTION_notify_transmit_ready_cancel (bc->th);
5106 if (bc->task == GNUNET_SCHEDULER_NO_TASK)
5107 bc->task = GNUNET_SCHEDULER_add_now (sched,
5108 &do_blacklist_check,
5114 GNUNET_CONTAINER_DLL_remove (bl_head,
5117 GNUNET_SERVER_client_drop (bl->client);
5123 /* clean up 'normal' clients */
5126 while ((pos != NULL) && (pos->client != client))
5133 while (NULL != (mqe = pos->message_queue_head))
5135 GNUNET_CONTAINER_DLL_remove (pos->message_queue_head,
5136 pos->message_queue_tail,
5138 pos->message_count--;
5142 clients = pos->next;
5144 prev->next = pos->next;
5145 if (GNUNET_YES == pos->tcs_pending)
5150 if (pos->th != NULL)
5152 GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th);
5155 GNUNET_break (0 == pos->message_count);
5161 * Function called when the service shuts down. Unloads our plugins
5162 * and cancels pending validations.
5164 * @param cls closure, unused
5165 * @param tc task context (unused)
5168 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5170 struct TransportPlugin *plug;
5171 struct OwnAddressList *al;
5172 struct CheckHelloValidatedContext *chvc;
5174 while (neighbours != NULL)
5175 disconnect_neighbour (neighbours, GNUNET_NO);
5177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5178 "Transport service is unloading plugins...\n");
5180 while (NULL != (plug = plugins))
5182 plugins = plug->next;
5183 if (plug->address_update_task != GNUNET_SCHEDULER_NO_TASK)
5185 GNUNET_SCHEDULER_cancel (plug->env.sched,
5186 plug->address_update_task);
5187 plug->address_update_task = GNUNET_SCHEDULER_NO_TASK;
5189 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
5190 GNUNET_free (plug->lib_name);
5191 GNUNET_free (plug->short_name);
5192 while (NULL != (al = plug->addresses))
5194 plug->addresses = al->next;
5199 if (my_private_key != NULL)
5200 GNUNET_CRYPTO_rsa_key_free (my_private_key);
5201 GNUNET_free_non_null (our_hello);
5203 GNUNET_CONTAINER_multihashmap_iterate (validation_map,
5206 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
5207 validation_map = NULL;
5209 /* free 'chvc' data structure */
5210 while (NULL != (chvc = chvc_head))
5212 chvc_head = chvc->next;
5213 if (chvc->piter != NULL)
5214 GNUNET_PEERINFO_iterate_cancel (chvc->piter);
5217 GNUNET_assert (chvc->ve_count == 0);
5224 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
5227 if (peerinfo != NULL)
5229 GNUNET_PEERINFO_disconnect (peerinfo);
5232 /* Can we assume those are gone by now, or do we need to clean up
5234 GNUNET_break (bl_head == NULL);
5235 GNUNET_break (bc_head == NULL);
5240 * Initiate transport service.
5242 * @param cls closure
5243 * @param s scheduler to use
5244 * @param server the initialized server
5245 * @param c configuration to use
5249 struct GNUNET_SCHEDULER_Handle *s,
5250 struct GNUNET_SERVER_Handle *server,
5251 const struct GNUNET_CONFIGURATION_Handle *c)
5253 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
5254 {&handle_start, NULL,
5255 GNUNET_MESSAGE_TYPE_TRANSPORT_START, sizeof (struct StartMessage)},
5256 {&handle_hello, NULL,
5257 GNUNET_MESSAGE_TYPE_HELLO, 0},
5258 {&handle_send, NULL,
5259 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0},
5260 {&handle_set_quota, NULL,
5261 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)},
5262 {&handle_address_lookup, NULL,
5263 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP,
5265 {&handle_blacklist_init, NULL,
5266 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, sizeof (struct GNUNET_MessageHeader)},
5267 {&handle_blacklist_reply, NULL,
5268 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY, sizeof (struct BlacklistMessage)},
5274 unsigned long long tneigh;
5279 stats = GNUNET_STATISTICS_create (sched, "transport", cfg);
5280 validation_map = GNUNET_CONTAINER_multihashmap_create (64);
5281 /* parse configuration */
5283 GNUNET_CONFIGURATION_get_value_number (c,
5288 GNUNET_CONFIGURATION_get_value_filename (c,
5290 "HOSTKEY", &keyfile)))
5292 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
5294 ("Transport service is lacking key configuration settings. Exiting.\n"));
5295 GNUNET_SCHEDULER_shutdown (s);
5298 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
5301 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
5302 validation_map = NULL;
5305 max_connect_per_transport = (uint32_t) tneigh;
5306 peerinfo = GNUNET_PEERINFO_connect (sched, cfg);
5307 if (peerinfo == NULL)
5309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
5310 _("Could not access PEERINFO service. Exiting.\n"));
5311 GNUNET_SCHEDULER_shutdown (s);
5314 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
5317 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
5318 validation_map = NULL;
5319 GNUNET_free (keyfile);
5322 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
5323 GNUNET_free (keyfile);
5324 if (my_private_key == NULL)
5326 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
5328 ("Transport service could not access hostkey. Exiting.\n"));
5329 GNUNET_SCHEDULER_shutdown (s);
5332 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
5335 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
5336 validation_map = NULL;
5339 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
5340 GNUNET_CRYPTO_hash (&my_public_key,
5341 sizeof (my_public_key), &my_identity.hashPubKey);
5342 /* setup notification */
5343 GNUNET_SERVER_disconnect_notify (server,
5344 &client_disconnect_notification, NULL);
5345 /* load plugins... */
5348 GNUNET_CONFIGURATION_get_value_string (c,
5349 "TRANSPORT", "PLUGINS", &plugs))
5351 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
5352 _("Starting transport plugins `%s'\n"), plugs);
5353 pos = strtok (plugs, " ");
5356 start_transport (server, pos);
5358 pos = strtok (NULL, " ");
5360 GNUNET_free (plugs);
5362 GNUNET_SCHEDULER_add_delayed (sched,
5363 GNUNET_TIME_UNIT_FOREVER_REL,
5364 &shutdown_task, NULL);
5369 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport service ready.\n"));
5371 /* If we have a blacklist file, read from it */
5372 read_blacklist_file(cfg);
5373 /* process client requests */
5374 GNUNET_SERVER_add_handlers (server, handlers);
5379 * The main function for the transport service.
5381 * @param argc number of arguments from the command line
5382 * @param argv command line arguments
5383 * @return 0 ok, 1 on error
5386 main (int argc, char *const *argv)
5388 a2s (NULL, NULL, 0); /* make compiler happy */
5389 return (GNUNET_OK ==
5390 GNUNET_SERVICE_run (argc,
5393 GNUNET_SERVICE_OPTION_NONE,
5394 &run, NULL)) ? 0 : 1;
5397 /* end of gnunet-service-transport.c */