2 This file is part of GNUnet.
3 Copyright (C) 2010-2015 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_neighbours.c
23 * @brief neighbour management
24 * @author Christian Grothoff
27 #include "gnunet_ats_service.h"
28 #include "gnunet-service-transport_ats.h"
29 #include "gnunet-service-transport_blacklist.h"
30 #include "gnunet-service-transport_clients.h"
31 #include "gnunet-service-transport_neighbours.h"
32 #include "gnunet-service-transport_manipulation.h"
33 #include "gnunet-service-transport_plugins.h"
34 #include "gnunet-service-transport_validation.h"
35 #include "gnunet-service-transport.h"
36 #include "gnunet_peerinfo_service.h"
37 #include "gnunet_constants.h"
38 #include "transport.h"
42 * Size of the neighbour hash map.
44 #define NEIGHBOUR_TABLE_SIZE 256
47 * Time we give plugin to transmit DISCONNECT message before the
48 * neighbour entry self-destructs.
50 #define DISCONNECT_SENT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
53 * How often must a peer violate bandwidth quotas before we start
54 * to simply drop its messages?
56 #define QUOTA_VIOLATION_DROP_THRESHOLD 10
59 * How long are we willing to wait for a response from ATS before timing out?
61 #define ATS_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
64 * How long are we willing to wait for an ACK from the other peer before
65 * giving up on our connect operation?
67 #define SETUP_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
70 * How long are we willing to wait for a successful reconnect if
71 * an existing connection went down? Much shorter than the
72 * usual SETUP_CONNECTION_TIMEOUT as we do not inform the
73 * higher layers about the disconnect during this period.
75 #define FAST_RECONNECT_TIMEOUT GNUNET_TIME_UNIT_SECONDS
78 * Interval to send utilization data
80 #define UTIL_TRANSMISSION_INTERVAL GNUNET_TIME_UNIT_SECONDS
83 * State describing which kind a reply this neighbour should send
88 * We did not receive a SYN message for this neighbour
93 * The neighbour received a SYN message and has to send a SYN_ACK
99 * The neighbour sent a SYN_ACK message and has to send a ACK
106 GNUNET_NETWORK_STRUCT_BEGIN
109 * Message a peer sends to another to indicate that it intends to
110 * setup a connection/session for data exchange. A 'SESSION_SYN'
111 * should be answered with a 'SESSION_SYN_ACK' with the same body
112 * to confirm. A 'SESSION_SYN_ACK' should then be followed with
113 * a 'ACK'. Once the 'ACK' is received, both peers
114 * should be connected.
116 struct TransportSynMessage
119 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN
120 * or #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK
122 struct GNUNET_MessageHeader header;
127 uint32_t reserved GNUNET_PACKED;
130 * Absolute time at the sender. Only the most recent connect
131 * message implies which session is preferred by the sender.
133 struct GNUNET_TIME_AbsoluteNBO timestamp;
139 * Message a peer sends to another when connected to indicate that a
140 * session is in use and the peer is still alive or to respond to a keep alive.
141 * A peer sends a message with type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE
142 * to request a message with #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE.
143 * When the keep alive response with type is received, transport service
144 * will call the respective plugin to update the session timeout
146 struct SessionKeepAliveMessage
149 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE or
150 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE.
152 struct GNUNET_MessageHeader header;
155 * A nonce to identify the session the keep alive is used for
157 uint32_t nonce GNUNET_PACKED;
161 * Message we send to the other peer to notify him that we intentionally
162 * are disconnecting (to reduce timeouts). This is just a friendly
163 * notification, peers must not rely on always receiving disconnect
166 struct SessionDisconnectMessage
169 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT
171 struct GNUNET_MessageHeader header;
176 uint32_t reserved GNUNET_PACKED;
179 * Purpose of the signature. Extends over the timestamp.
180 * Purpose should be #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DISCONNECT.
182 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
185 * Absolute time at the sender. Only the most recent connect
186 * message implies which session is preferred by the sender.
188 struct GNUNET_TIME_AbsoluteNBO timestamp;
191 * Public key of the sender.
193 struct GNUNET_CRYPTO_EddsaPublicKey public_key;
196 * Signature of the peer that sends us the disconnect. Only
197 * valid if the timestamp is AFTER the timestamp from the
198 * corresponding 'SYN' message.
200 struct GNUNET_CRYPTO_EddsaSignature signature;
204 GNUNET_NETWORK_STRUCT_END
208 * For each neighbour we keep a list of messages
209 * that we still want to transmit to the neighbour.
215 * This is a doubly linked list.
217 struct MessageQueue *next;
220 * This is a doubly linked list.
222 struct MessageQueue *prev;
225 * Function to call once we're done.
227 GST_NeighbourSendContinuation cont;
230 * Closure for @e cont
235 * The message(s) we want to transmit, GNUNET_MessageHeader(s)
236 * stuck together in memory. Allocated at the end of this struct.
238 const char *message_buf;
241 * Size of the message buf
243 size_t message_buf_size;
246 * At what time should we fail?
248 struct GNUNET_TIME_Absolute timeout;
254 * A possible address we could use to communicate with a neighbour.
256 struct NeighbourAddress
260 * Active session for this address.
262 struct Session *session;
265 * Network-level address information.
267 struct GNUNET_HELLO_Address *address;
270 * Timestamp of the 'SESSION_CONNECT' message we sent to the other
271 * peer for this address. Use to check that the ACK is in response
272 * to our most recent 'SYN'.
274 struct GNUNET_TIME_Absolute connect_timestamp;
277 * Inbound bandwidth from ATS for this address.
279 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
282 * Outbound bandwidth from ATS for this address.
284 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
287 * Did we tell ATS that this is our 'active' address?
292 * The current nonce sent in the last keep alive messages
294 uint32_t keep_alive_nonce;
299 * Entry in neighbours.
301 struct NeighbourMapEntry
305 * Head of list of messages we would like to send to this peer;
306 * must contain at most one message per client.
308 struct MessageQueue *messages_head;
311 * Tail of list of messages we would like to send to this peer; must
312 * contain at most one message per client.
314 struct MessageQueue *messages_tail;
317 * Are we currently trying to send a message? If so, which one?
319 struct MessageQueue *is_active;
322 * Primary address we currently use to communicate with the neighbour.
324 struct NeighbourAddress primary_address;
327 * Alternative address currently under consideration for communicating
328 * with the neighbour.
330 struct NeighbourAddress alternative_address;
333 * Identity of this neighbour.
335 struct GNUNET_PeerIdentity id;
338 * Main task that drives this peer (timeouts, keepalives, etc.).
339 * Always runs the 'master_task'.
341 struct GNUNET_SCHEDULER_Task *task;
344 * Task to disconnect neighbour after we received a DISCONNECT message
346 struct GNUNET_SCHEDULER_Task *delayed_disconnect_task;
349 * At what time should we sent the next keep-alive message?
351 struct GNUNET_TIME_Absolute keep_alive_time;
354 * At what time did we sent the last keep-alive message? Used
355 * to calculate round-trip time ("latency").
357 struct GNUNET_TIME_Absolute last_keep_alive_time;
360 * Timestamp we should include in our next SYN_ACK message.
361 * (only valid if 'send_connect_ack' is #GNUNET_YES). Used to build
362 * our SYN_ACK message.
364 struct GNUNET_TIME_Absolute connect_ack_timestamp;
367 * ATS address suggest handle
369 struct GNUNET_ATS_ConnectivitySuggestHandle *suggest_handle;
372 * Time where we should cut the connection (timeout) if we don't
373 * make progress in the state machine (or get a KEEPALIVE_RESPONSE
374 * if we are in #S_CONNECTED).
376 struct GNUNET_TIME_Absolute timeout;
379 * Tracker for inbound bandwidth.
381 struct GNUNET_BANDWIDTH_Tracker in_tracker;
384 * How often has the other peer (recently) violated the inbound
385 * traffic limit? Incremented by 10 per violation, decremented by 1
386 * per non-violation (for each time interval).
388 unsigned int quota_violation_count;
391 * The current state of the peer.
393 enum GNUNET_TRANSPORT_PeerState state;
396 * Did we sent an KEEP_ALIVE message and are we expecting a response?
398 int expect_latency_response;
401 * When a peer wants to connect we have to reply to the 1st SYN message
402 * with a SYN_ACK message. But sometime we cannot send this message
403 * immediately since we do not have an address and then we have to remember
404 * to send this message as soon as we have an address.
406 * Flag to set if we still need to send a SYN_ACK message to the other peer
407 * (once we have an address to use and the peer has been allowed by our
408 * blacklist). Initially set to #ACK_UNDEFINED. Set to #ACK_SEND_SYN_ACK
409 * if we need to send a SYN_ACK. Set to #ACK_SEND_ACK if we did
410 * send a SYN_ACK and should go to #S_CONNECTED upon receiving a
411 * 'ACK' (regardless of what our own state machine might say).
413 enum GST_ACK_State ack_state;
416 * Tracking utilization of outbound bandwidth
418 uint32_t util_total_bytes_sent;
421 * Tracking utilization of inbound bandwidth
423 uint32_t util_total_bytes_recv;
426 * Date of last utilization transmission
428 struct GNUNET_TIME_Absolute last_util_transmission;
433 * Context for blacklist checks and the #try_connect_bl_check_cont()
434 * function. Stores information about ongoing blacklist checks.
436 struct BlackListCheckContext
440 * We keep blacklist checks in a DLL.
442 struct BlackListCheckContext *next;
445 * We keep blacklist checks in a DLL.
447 struct BlackListCheckContext *prev;
450 * Address that is being checked.
452 struct NeighbourAddress na;
455 * Handle to the ongoing blacklist check.
457 struct GST_BlacklistCheck *bc;
462 * Hash map from peer identities to the respective `struct NeighbourMapEntry`.
464 static struct GNUNET_CONTAINER_MultiPeerMap *neighbours;
467 * We keep blacklist checks in a DLL so that we can find
468 * the 'sessions' in their 'struct NeighbourAddress' if
469 * a session goes down.
471 static struct BlackListCheckContext *bc_head;
474 * We keep blacklist checks in a DLL.
476 static struct BlackListCheckContext *bc_tail;
479 * List of pending blacklist checks: head
481 static struct BlacklistCheckSwitchContext *pending_bc_head;
484 * List of pending blacklist checks: tail
486 static struct BlacklistCheckSwitchContext *pending_bc_tail;
489 * counter for connected neighbours
491 static unsigned int neighbours_connected;
494 * Number of bytes we have currently queued for transmission.
496 static unsigned long long bytes_in_send_queue;
499 * Task transmitting utilization data
501 static struct GNUNET_SCHEDULER_Task *util_transmission_tk;
505 * Convert the given ACK state to a string.
508 * @return corresponding human-readable string
511 print_ack_state (enum GST_ACK_State s)
516 case ACK_SEND_SYN_ACK:
517 return "SEND_SYN_ACK";
528 * Notify our clients that another peer connected to us.
530 * @param peer the peer that connected
531 * @param bandwidth_in inbound bandwidth in NBO
532 * @param bandwidth_out outbound bandwidth in NBO
535 neighbours_connect_notification (const struct GNUNET_PeerIdentity *peer,
536 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
537 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
539 size_t len = sizeof(struct ConnectInfoMessage);
540 char buf[len] GNUNET_ALIGN;
541 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf;
543 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
544 "We are now connected to peer `%s'\n",
546 connect_msg->header.size = htons (sizeof(buf));
547 connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
548 connect_msg->id = *peer;
549 connect_msg->quota_in = bandwidth_in;
550 connect_msg->quota_out = bandwidth_out;
551 GST_clients_broadcast (&connect_msg->header, GNUNET_NO);
556 * Notify our clients (and manipulation) that a peer disconnected from
559 * @param peer the peer that disconnected
562 neighbours_disconnect_notification (const struct GNUNET_PeerIdentity *peer)
564 struct DisconnectInfoMessage disconnect_msg;
566 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
567 "Peer `%s' disconnected\n",
569 GST_manipulation_peer_disconnect (peer);
570 disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage));
571 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
572 disconnect_msg.reserved = htonl (0);
573 disconnect_msg.peer = *peer;
574 GST_clients_broadcast (&disconnect_msg.header,
580 * Notify transport clients that a neighbour peer changed its active
583 * @param peer identity of the peer
584 * @param address address possibly NULL if peer is not connected
585 * @param state current state this peer is in
586 * @param state_timeout timeout for the current state of the peer
587 * @param bandwidth_in bandwidth assigned inbound, 0 on disconnect
588 * @param bandwidth_out bandwidth assigned outbound, 0 on disconnect
591 neighbours_changed_notification (const struct GNUNET_PeerIdentity *peer,
592 const struct GNUNET_HELLO_Address *address,
593 enum GNUNET_TRANSPORT_PeerState state,
594 struct GNUNET_TIME_Absolute state_timeout,
595 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
596 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
599 "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n",
601 GST_plugins_a2s (address),
602 GNUNET_TRANSPORT_ps2s (state),
603 GNUNET_STRINGS_absolute_time_to_string (state_timeout));
604 /* FIXME: include bandwidth in notification! */
605 GST_clients_broadcast_peer_notification (peer,
613 * Lookup a neighbour entry in the neighbours hash map.
615 * @param pid identity of the peer to look up
616 * @return the entry, NULL if there is no existing record
618 static struct NeighbourMapEntry *
619 lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
621 if (NULL == neighbours)
623 return GNUNET_CONTAINER_multipeermap_get (neighbours, pid);
628 * Test if we're connected to the given peer.
630 * @param n neighbour entry of peer to test
631 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not
634 test_connected (struct NeighbourMapEntry *n)
638 return GNUNET_TRANSPORT_is_connected (n->state);
643 * Send information about a new outbound quota to our clients.
645 * @param target affected peer
646 * @param quota new quota
649 send_outbound_quota (const struct GNUNET_PeerIdentity *target,
650 struct GNUNET_BANDWIDTH_Value32NBO quota)
652 struct QuotaSetMessage q_msg;
654 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
655 "Sending outbound quota of %u Bps for peer `%s' to all clients\n",
656 ntohl (quota.value__),
657 GNUNET_i2s (target));
658 q_msg.header.size = htons (sizeof (struct QuotaSetMessage));
659 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
661 q_msg.peer = (*target);
662 GST_clients_broadcast (&q_msg.header, GNUNET_NO);
667 * We don't need a given neighbour address any more.
668 * Release its resources and give appropriate notifications
669 * to ATS and other subsystems.
671 * @param na address we are done with; @a na itself must NOT be 'free'd, only the contents!
674 free_address (struct NeighbourAddress *na)
676 if (GNUNET_YES == na->ats_active)
677 GST_validation_set_address_use (na->address,
679 if (NULL != na->address)
681 GST_ats_block_address (na->address,
683 GNUNET_HELLO_address_free (na->address);
686 na->bandwidth_in = GNUNET_BANDWIDTH_value_init (0);
687 na->bandwidth_out = GNUNET_BANDWIDTH_value_init (0);
688 na->ats_active = GNUNET_NO;
689 na->keep_alive_nonce = 0;
695 * Master task run for every neighbour. Performs all of the time-related
696 * activities (keep alive, send next message, disconnect if idle, finish
697 * clean up after disconnect).
699 * @param cls the `struct NeighbourMapEntry` for which we are running
700 * @param tc scheduler context (unused)
703 master_task (void *cls,
704 const struct GNUNET_SCHEDULER_TaskContext *tc);
708 * Set net state and state timeout for this neighbour and notify monitoring
710 * @param n the respective neighbour
711 * @param s the new state
712 * @param timeout the new timeout
715 set_state_and_timeout (struct NeighbourMapEntry *n,
716 enum GNUNET_TRANSPORT_PeerState s,
717 struct GNUNET_TIME_Absolute timeout)
719 if (GNUNET_TRANSPORT_is_connected (s) &&
720 ! GNUNET_TRANSPORT_is_connected (n->state) )
722 neighbours_connect_notification (&n->id,
723 n->primary_address.bandwidth_in,
724 n->primary_address.bandwidth_out);
725 GNUNET_STATISTICS_set (GST_stats,
726 gettext_noop ("# peers connected"),
727 ++neighbours_connected,
730 if (! GNUNET_TRANSPORT_is_connected (s) &&
731 GNUNET_TRANSPORT_is_connected (n->state) )
733 GNUNET_STATISTICS_set (GST_stats,
734 gettext_noop ("# peers connected"),
735 --neighbours_connected,
737 neighbours_disconnect_notification (&n->id);
740 if ( (timeout.abs_value_us < n->timeout.abs_value_us) &&
743 /* new timeout is earlier, reschedule master task */
744 GNUNET_SCHEDULER_cancel (n->task);
745 n->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (timeout),
749 n->timeout = timeout;
750 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
751 "Neighbour `%s' changed state to %s with timeout %s\n",
753 GNUNET_TRANSPORT_ps2s(s),
754 GNUNET_STRINGS_absolute_time_to_string (timeout));
755 neighbours_changed_notification (&n->id,
756 n->primary_address.address,
759 n->primary_address.bandwidth_in,
760 n->primary_address.bandwidth_out);
765 * Initialize the alternative address of a neighbour
767 * @param n the neighbour
768 * @param address address of the other peer, NULL if other peer
770 * @param session session to use (or NULL, in which case an
771 * address must be setup)
772 * @param bandwidth_in inbound quota to be used when connection is up
773 * @param bandwidth_out outbound quota to be used when connection is up
776 set_alternative_address (struct NeighbourMapEntry *n,
777 const struct GNUNET_HELLO_Address *address,
778 struct Session *session,
779 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
780 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
782 struct GNUNET_TRANSPORT_PluginFunctions *papi;
784 if (NULL == (papi = GST_plugins_find (address->transport_name)))
789 if (session == n->alternative_address.session)
791 n->alternative_address.bandwidth_in = bandwidth_in;
792 n->alternative_address.bandwidth_out = bandwidth_out;
795 if (NULL != n->alternative_address.address)
797 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
798 "Replacing existing alternative address with another one\n");
799 free_address (&n->alternative_address);
802 session = papi->get_session (papi->cls,
806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
807 "Failed to obtain new session for peer `%s' and address '%s'\n",
808 GNUNET_i2s (&address->peer),
809 GST_plugins_a2s (address));
810 GNUNET_STATISTICS_update (GST_stats,
811 gettext_noop ("# session creation failed"),
816 GST_ats_new_session (address,
818 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
819 "Neighbour `%s' configured alternative address %s\n",
821 GST_plugins_a2s(address));
823 n->alternative_address.address = GNUNET_HELLO_address_copy (address);
824 n->alternative_address.bandwidth_in = bandwidth_in;
825 n->alternative_address.bandwidth_out = bandwidth_out;
826 n->alternative_address.session = session;
827 n->alternative_address.ats_active = GNUNET_NO;
828 n->alternative_address.keep_alive_nonce = 0;
829 GNUNET_assert (GNUNET_YES ==
830 GST_ats_is_known (n->alternative_address.address,
831 n->alternative_address.session));
836 * Initialize the primary address of a neighbour
838 * @param n the neighbour
839 * @param address address of the other peer, NULL if other peer
841 * @param session session to use (or NULL, in which case an
842 * address must be setup)
843 * @param bandwidth_in inbound quota to be used when connection is up
844 * @param bandwidth_out outbound quota to be used when connection is up
847 set_primary_address (struct NeighbourMapEntry *n,
848 const struct GNUNET_HELLO_Address *address,
849 struct Session *session,
850 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
851 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
853 if (session == n->primary_address.session)
855 GST_validation_set_address_use (n->primary_address.address,
857 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__)
859 n->primary_address.bandwidth_in = bandwidth_in;
860 GST_neighbours_set_incoming_quota (&address->peer,
863 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__)
865 n->primary_address.bandwidth_out = bandwidth_out;
866 send_outbound_quota (&address->peer,
871 if ( (NULL != n->primary_address.address) &&
872 (0 == GNUNET_HELLO_address_cmp (address,
873 n->primary_address.address)) )
881 GST_ats_block_address (address,
885 if (NULL != n->primary_address.address)
887 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
888 "Replacing existing primary address with another one\n");
889 free_address (&n->primary_address);
891 n->primary_address.address = GNUNET_HELLO_address_copy (address);
892 n->primary_address.bandwidth_in = bandwidth_in;
893 n->primary_address.bandwidth_out = bandwidth_out;
894 n->primary_address.session = session;
895 n->primary_address.keep_alive_nonce = 0;
896 GNUNET_assert (GNUNET_YES ==
897 GST_ats_is_known (n->primary_address.address,
898 n->primary_address.session));
899 /* subsystems about address use */
900 GST_validation_set_address_use (n->primary_address.address,
902 GST_neighbours_set_incoming_quota (&address->peer,
904 send_outbound_quota (&address->peer,
906 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
907 "Neighbour `%s' switched to address `%s'\n",
909 GST_plugins_a2s(address));
911 neighbours_changed_notification (&n->id,
912 n->primary_address.address,
915 n->primary_address.bandwidth_in,
916 n->primary_address.bandwidth_out);
921 * Clear the primary address of a neighbour since this address is not
922 * valid anymore and notify monitoring about it
924 * @param n the neighbour
927 unset_primary_address (struct NeighbourMapEntry *n)
929 /* Notify monitoring about change */
930 if (NULL == n->primary_address.address)
932 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
933 "Disabling primary address\n");
934 neighbours_changed_notification (&n->id,
935 n->primary_address.address,
938 GNUNET_BANDWIDTH_value_init (0),
939 GNUNET_BANDWIDTH_value_init (0));
940 free_address (&n->primary_address);
945 * Free a neighbour map entry.
947 * @param n entry to free
950 free_neighbour (struct NeighbourMapEntry *n)
952 struct MessageQueue *mq;
954 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
955 "Freeing neighbour state of peer `%s'\n",
956 GNUNET_i2s (&n->id));
957 n->is_active = NULL; /* always free'd by its own continuation! */
959 /* fail messages currently in the queue */
960 while (NULL != (mq = n->messages_head))
962 GNUNET_CONTAINER_DLL_remove (n->messages_head,
965 if (NULL != mq->cont)
966 mq->cont (mq->cont_cls,
968 mq->message_buf_size,
972 /* Mark peer as disconnected */
973 set_state_and_timeout (n,
974 GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED,
975 GNUNET_TIME_UNIT_FOREVER_ABS);
976 /* free addresses and mark as unused */
977 unset_primary_address (n);
979 if (NULL != n->alternative_address.address)
981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
982 "Cleaning up alternative address\n");
983 free_address (&n->alternative_address);
985 GNUNET_assert (GNUNET_YES ==
986 GNUNET_CONTAINER_multipeermap_remove (neighbours,
989 /* Cancel address requests for this peer */
990 if (NULL != n->suggest_handle)
992 GNUNET_ATS_connectivity_suggest_cancel (n->suggest_handle);
993 n->suggest_handle = NULL;
996 /* Cancel the disconnect task */
997 if (NULL != n->delayed_disconnect_task)
999 GNUNET_SCHEDULER_cancel (n->delayed_disconnect_task);
1000 n->delayed_disconnect_task = NULL;
1003 /* Cancel the master task */
1004 if (NULL != n->task)
1006 GNUNET_SCHEDULER_cancel (n->task);
1009 /* free rest of memory */
1015 * Transmit a message using the current session of the given
1018 * @param n entry for the recipient
1019 * @param msgbuf buffer to transmit
1020 * @param msgbuf_size number of bytes in @a msgbuf buffer
1021 * @param priority transmission priority
1022 * @param timeout transmission timeout
1023 * @param use_keepalive_timeout #GNUNET_YES to use plugin-specific keep-alive
1024 * timeout (@a timeout is ignored in that case), #GNUNET_NO otherwise
1025 * @param cont continuation to call when finished (can be NULL)
1026 * @param cont_cls closure for @a cont
1027 * @return timeout (copy of @a timeout or a calculated one if
1028 * @a use_keepalive_timeout is #GNUNET_YES.
1030 static struct GNUNET_TIME_Relative
1031 send_with_session (struct NeighbourMapEntry *n,
1035 struct GNUNET_TIME_Relative timeout,
1036 unsigned int use_keepalive_timeout,
1037 GNUNET_TRANSPORT_TransmitContinuation cont,
1040 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1041 struct GNUNET_TIME_Relative result = GNUNET_TIME_UNIT_FOREVER_REL;
1043 GNUNET_assert (NULL != n->primary_address.session);
1044 if ( ((NULL == (papi = GST_plugins_find (n->primary_address.address->transport_name)) ||
1045 (-1 == papi->send (papi->cls,
1046 n->primary_address.session,
1050 (result = (GNUNET_NO == use_keepalive_timeout) ? timeout :
1051 GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1052 papi->query_keepalive_factor (papi->cls))),
1061 GST_neighbours_notify_data_sent (n->primary_address.address,
1062 n->primary_address.session,
1064 GNUNET_break (NULL != papi);
1070 * Function called when the 'DISCONNECT' message has been sent by the
1071 * plugin. Frees the neighbour --- if the entry still exists.
1074 * @param target identity of the neighbour that was disconnected
1075 * @param result #GNUNET_OK if the disconnect got out successfully
1076 * @param payload bytes payload
1077 * @param physical bytes on wire
1080 send_disconnect_cont (void *cls,
1081 const struct GNUNET_PeerIdentity *target,
1086 struct NeighbourMapEntry *n;
1088 n = lookup_neighbour (target);
1090 return; /* already gone */
1091 if (GNUNET_TRANSPORT_PS_DISCONNECT != n->state)
1092 return; /* have created a fresh entry since */
1093 if (NULL != n->task)
1094 GNUNET_SCHEDULER_cancel (n->task);
1095 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
1100 * Transmit a DISCONNECT message to the other peer.
1102 * @param n neighbour to send DISCONNECT message.
1105 send_disconnect (struct NeighbourMapEntry *n)
1107 struct SessionDisconnectMessage disconnect_msg;
1109 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1110 "Sending DISCONNECT message to peer `%4s'\n",
1111 GNUNET_i2s (&n->id));
1112 disconnect_msg.header.size = htons (sizeof (struct SessionDisconnectMessage));
1113 disconnect_msg.header.type =
1114 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
1115 disconnect_msg.reserved = htonl (0);
1116 disconnect_msg.purpose.size =
1117 htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
1118 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) +
1119 sizeof (struct GNUNET_TIME_AbsoluteNBO));
1120 disconnect_msg.purpose.purpose =
1121 htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
1122 disconnect_msg.timestamp =
1123 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1124 disconnect_msg.public_key = GST_my_identity.public_key;
1125 GNUNET_assert (GNUNET_OK ==
1126 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
1127 &disconnect_msg.purpose,
1128 &disconnect_msg.signature));
1130 (void) send_with_session (n,
1132 sizeof (disconnect_msg),
1134 GNUNET_TIME_UNIT_FOREVER_REL,
1136 &send_disconnect_cont,
1138 GNUNET_STATISTICS_update (GST_stats,
1139 gettext_noop ("# DISCONNECT messages sent"),
1146 * Disconnect from the given neighbour, clean up the record.
1148 * @param n neighbour to disconnect from
1151 disconnect_neighbour (struct NeighbourMapEntry *n)
1153 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1154 "Disconnecting from peer %s in state %s\n",
1155 GNUNET_i2s (&n->id),
1156 GNUNET_TRANSPORT_ps2s (n->state));
1157 /* depending on state, notify neighbour and/or upper layers of this peer
1161 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
1162 case GNUNET_TRANSPORT_PS_INIT_ATS:
1163 /* other peer is completely unaware of us, no need to send DISCONNECT */
1166 case GNUNET_TRANSPORT_PS_SYN_SENT:
1167 send_disconnect (n);
1168 set_state_and_timeout (n,
1169 GNUNET_TRANSPORT_PS_DISCONNECT,
1170 GNUNET_TIME_UNIT_FOREVER_ABS);
1172 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
1173 /* we never ACK'ed the other peer's request, no need to send DISCONNECT */
1176 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
1177 /* we DID ACK the other peer's request, must send DISCONNECT */
1178 send_disconnect (n);
1179 set_state_and_timeout (n,
1180 GNUNET_TRANSPORT_PS_DISCONNECT,
1181 GNUNET_TIME_UNIT_FOREVER_ABS);
1183 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1184 case GNUNET_TRANSPORT_PS_CONNECTED:
1185 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1186 /* we are currently connected, need to send disconnect and do
1187 internal notifications and update statistics */
1188 send_disconnect (n);
1189 set_state_and_timeout (n,
1190 GNUNET_TRANSPORT_PS_DISCONNECT,
1191 GNUNET_TIME_UNIT_FOREVER_ABS);
1193 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
1194 /* Disconnecting while waiting for an ATS address to reconnect,
1195 * cannot send DISCONNECT */
1198 case GNUNET_TRANSPORT_PS_DISCONNECT:
1199 /* already disconnected, ignore */
1201 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
1202 /* already cleaned up, how did we get here!? */
1206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1207 "Unhandled state `%s'\n",
1208 GNUNET_TRANSPORT_ps2s (n->state));
1212 /* schedule timeout to clean up */
1213 if (NULL != n->task)
1214 GNUNET_SCHEDULER_cancel (n->task);
1215 n->task = GNUNET_SCHEDULER_add_delayed (DISCONNECT_SENT_TIMEOUT,
1222 * We're done with our transmission attempt, continue processing.
1224 * @param cls the `struct MessageQueue` of the message
1225 * @param receiver intended receiver
1226 * @param success whether it worked or not
1227 * @param size_payload bytes payload sent
1228 * @param physical bytes sent on wire
1231 transmit_send_continuation (void *cls,
1232 const struct GNUNET_PeerIdentity *receiver,
1234 size_t size_payload,
1237 struct MessageQueue *mq = cls;
1238 struct NeighbourMapEntry *n;
1240 if (NULL == (n = lookup_neighbour (receiver)))
1242 if (NULL != mq->cont)
1243 mq->cont (mq->cont_cls,
1244 GNUNET_SYSERR /* not connected */,
1248 return; /* disconnect or other error while transmitting, can happen */
1250 if (n->is_active == mq)
1252 /* this is still "our" neighbour, remove us from its queue
1253 and allow it to send the next message now */
1254 n->is_active = NULL;
1255 if (NULL != n->task)
1256 GNUNET_SCHEDULER_cancel (n->task);
1257 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
1259 if (bytes_in_send_queue < mq->message_buf_size)
1261 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1262 "Bytes_in_send_queue `%u', Message_size %u, result: %s, payload %u, on wire %u\n",
1263 bytes_in_send_queue,
1264 mq->message_buf_size,
1265 (GNUNET_OK == success) ? "OK" : "FAIL",
1271 GNUNET_break (size_payload == mq->message_buf_size);
1272 bytes_in_send_queue -= mq->message_buf_size;
1273 GNUNET_STATISTICS_set (GST_stats,
1275 ("# bytes in message queue for other peers"),
1276 bytes_in_send_queue, GNUNET_NO);
1277 if (GNUNET_OK == success)
1278 GNUNET_STATISTICS_update (GST_stats,
1280 ("# messages transmitted to other peers"),
1283 GNUNET_STATISTICS_update (GST_stats,
1285 ("# transmission failures for messages to other peers"),
1287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1288 "Sending message to `%s' of type %u with %u bytes was a %s\n",
1289 GNUNET_i2s (receiver),
1290 ntohs (((struct GNUNET_MessageHeader *) mq->message_buf)->type),
1291 mq->message_buf_size,
1292 (success == GNUNET_OK) ? "success" : "FAILURE");
1293 if (NULL != mq->cont)
1294 mq->cont (mq->cont_cls, success, size_payload, physical);
1300 * Check the message list for the given neighbour and if we can
1301 * send a message, do so. This function should only be called
1302 * if the connection is at least generally ready for transmission.
1303 * While we will only send one message at a time, no bandwidth
1304 * quota management is performed here. If a message was given to
1305 * the plugin, the continuation will automatically re-schedule
1306 * the 'master' task once the next message might be transmitted.
1308 * @param n target peer for which to transmit
1311 try_transmission_to_peer (struct NeighbourMapEntry *n)
1313 struct MessageQueue *mq;
1314 struct GNUNET_TIME_Relative timeout;
1316 if (NULL == n->primary_address.address)
1318 /* no address, why are we here? */
1322 if ((0 == n->primary_address.address->address_length) &&
1323 (NULL == n->primary_address.session))
1325 /* no address, why are we here? */
1329 if (NULL != n->is_active)
1331 /* transmission already pending */
1335 /* timeout messages from the queue that are past their due date */
1336 while (NULL != (mq = n->messages_head))
1338 timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout);
1339 if (timeout.rel_value_us > 0)
1341 GNUNET_STATISTICS_update (GST_stats,
1342 gettext_noop ("# messages timed out while in transport queue"),
1345 GNUNET_CONTAINER_DLL_remove (n->messages_head,
1349 transmit_send_continuation (mq,
1352 mq->message_buf_size,
1356 return; /* no more messages */
1357 GNUNET_CONTAINER_DLL_remove (n->messages_head,
1362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1363 "Giving message with %u bytes to plugin session %p\n",
1364 mq->message_buf_size,
1365 n->primary_address.session);
1366 (void) send_with_session (n,
1368 mq->message_buf_size,
1372 &transmit_send_continuation,
1378 * Send keepalive message to the neighbour. Must only be called
1379 * if we are on 'connected' state or while trying to switch addresses.
1380 * Will internally determine if a keepalive is truly needed (so can
1381 * always be called).
1383 * @param n neighbour that went idle and needs a keepalive
1386 send_keepalive (struct NeighbourMapEntry *n)
1388 struct SessionKeepAliveMessage m;
1389 struct GNUNET_TIME_Relative timeout;
1392 GNUNET_assert ((GNUNET_TRANSPORT_PS_CONNECTED == n->state) ||
1393 (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state));
1394 if (GNUNET_TIME_absolute_get_remaining (n->keep_alive_time).rel_value_us > 0)
1395 return; /* no keepalive needed at this time */
1397 nonce = 0; /* 0 indicates 'not set' */
1399 nonce = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
1402 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1403 "Sending KEEPALIVE to peer `%s' with nonce %u\n",
1404 GNUNET_i2s (&n->id),
1406 m.header.size = htons (sizeof (struct SessionKeepAliveMessage));
1407 m.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE);
1408 m.nonce = htonl (nonce);
1410 timeout = send_with_session (n,
1413 UINT32_MAX /* priority */,
1414 GNUNET_TIME_UNIT_FOREVER_REL,
1417 GNUNET_STATISTICS_update (GST_stats,
1418 gettext_noop ("# KEEPALIVES sent"),
1421 n->primary_address.keep_alive_nonce = nonce;
1422 n->expect_latency_response = GNUNET_YES;
1423 n->last_keep_alive_time = GNUNET_TIME_absolute_get ();
1424 n->keep_alive_time = GNUNET_TIME_relative_to_absolute (timeout);
1429 * Keep the connection to the given neighbour alive longer,
1430 * we received a KEEPALIVE (or equivalent); send a response.
1432 * @param neighbour neighbour to keep alive (by sending keep alive response)
1433 * @param m the keep alive message containing the nonce to respond to
1436 GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour,
1437 const struct GNUNET_MessageHeader *m)
1439 struct NeighbourMapEntry *n;
1440 const struct SessionKeepAliveMessage *msg_in;
1441 struct SessionKeepAliveMessage msg;
1443 if (sizeof (struct SessionKeepAliveMessage) != ntohs (m->size))
1445 GNUNET_break_op (0);
1449 msg_in = (const struct SessionKeepAliveMessage *) m;
1450 if (NULL == (n = lookup_neighbour (neighbour)))
1452 GNUNET_STATISTICS_update (GST_stats,
1454 ("# KEEPALIVE messages discarded (peer unknown)"),
1458 if (NULL == n->primary_address.session)
1460 GNUNET_STATISTICS_update (GST_stats,
1462 ("# KEEPALIVE messages discarded (no session)"),
1467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1468 "Received KEEPALIVE request from peer `%s' with nonce %u\n",
1469 GNUNET_i2s (&n->id),
1470 ntohl (msg_in->nonce));
1471 GNUNET_STATISTICS_update (GST_stats,
1472 gettext_noop ("# KEEPALIVES received in good order"),
1476 /* send reply to allow neighbour to measure latency */
1477 msg.header.size = htons (sizeof (struct SessionKeepAliveMessage));
1478 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE);
1479 msg.nonce = msg_in->nonce;
1480 (void) send_with_session (n,
1482 sizeof (struct SessionKeepAliveMessage),
1483 UINT32_MAX /* priority */,
1484 GNUNET_TIME_UNIT_FOREVER_REL,
1491 * We received a KEEP_ALIVE_RESPONSE message and use this to calculate
1492 * latency to this peer. Pass the updated information (existing ats
1493 * plus calculated latency) to ATS.
1495 * @param neighbour neighbour to keep alive
1496 * @param m the message containing the keep alive response
1499 GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
1500 const struct GNUNET_MessageHeader *m)
1502 struct NeighbourMapEntry *n;
1503 const struct SessionKeepAliveMessage *msg;
1504 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1505 struct GNUNET_TIME_Relative latency;
1507 if (sizeof (struct SessionKeepAliveMessage) != ntohs (m->size))
1509 GNUNET_break_op (0);
1513 msg = (const struct SessionKeepAliveMessage *) m;
1514 if (NULL == (n = lookup_neighbour (neighbour)))
1516 GNUNET_STATISTICS_update (GST_stats,
1517 gettext_noop ("# KEEPALIVE_RESPONSEs discarded (not connected)"),
1522 if ( (GNUNET_TRANSPORT_PS_CONNECTED != n->state) ||
1523 (GNUNET_YES != n->expect_latency_response) )
1525 GNUNET_STATISTICS_update (GST_stats,
1526 gettext_noop ("# KEEPALIVE_RESPONSEs discarded (not expected)"),
1531 if (NULL == n->primary_address.address)
1533 GNUNET_STATISTICS_update (GST_stats,
1534 gettext_noop ("# KEEPALIVE_RESPONSEs discarded (address changed)"),
1539 if (n->primary_address.keep_alive_nonce != ntohl (msg->nonce))
1541 if (0 == n->primary_address.keep_alive_nonce)
1542 GNUNET_STATISTICS_update (GST_stats,
1543 gettext_noop ("# KEEPALIVE_RESPONSEs discarded (no nonce)"),
1547 GNUNET_STATISTICS_update (GST_stats,
1548 gettext_noop ("# KEEPALIVE_RESPONSEs discarded (bad nonce)"),
1553 GNUNET_STATISTICS_update (GST_stats,
1554 gettext_noop ("# KEEPALIVE_RESPONSEs received (OK)"),
1559 /* Update session timeout here */
1560 if (NULL != (papi = GST_plugins_find (n->primary_address.address->transport_name)))
1562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1563 "Updating session for peer `%s' for session %p\n",
1564 GNUNET_i2s (&n->id),
1565 n->primary_address.session);
1566 papi->update_session_timeout (papi->cls,
1568 n->primary_address.session);
1575 n->primary_address.keep_alive_nonce = 0;
1576 n->expect_latency_response = GNUNET_NO;
1577 set_state_and_timeout (n,
1579 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
1581 latency = GNUNET_TIME_absolute_get_duration (n->last_keep_alive_time);
1582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1583 "Received KEEPALIVE_RESPONSE from peer `%s', latency is %s\n",
1584 GNUNET_i2s (&n->id),
1585 GNUNET_STRINGS_relative_time_to_string (latency,
1587 GST_ats_update_delay (n->primary_address.address,
1588 GNUNET_TIME_relative_divide (latency,
1594 * We have received a message from the given sender. How long should
1595 * we delay before receiving more? (Also used to keep the peer marked
1598 * @param sender sender of the message
1599 * @param size size of the message
1600 * @param do_forward set to #GNUNET_YES if the message should be forwarded to clients
1601 * #GNUNET_NO if the neighbour is not connected or violates the quota,
1602 * #GNUNET_SYSERR if the connection is not fully up yet
1603 * @return how long to wait before reading more from this sender
1605 struct GNUNET_TIME_Relative
1606 GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender,
1610 struct NeighbourMapEntry *n;
1611 struct GNUNET_TIME_Relative ret;
1613 if (NULL == neighbours)
1615 *do_forward = GNUNET_NO;
1616 return GNUNET_TIME_UNIT_FOREVER_REL; /* This can happen during shutdown */
1618 if (NULL == (n = lookup_neighbour (sender)))
1620 GST_neighbours_try_connect (sender);
1621 if (NULL == (n = lookup_neighbour (sender)))
1623 GNUNET_STATISTICS_update (GST_stats,
1625 ("# messages discarded due to lack of neighbour record"),
1627 *do_forward = GNUNET_NO;
1628 return GNUNET_TIME_UNIT_ZERO;
1631 if (! test_connected (n))
1633 *do_forward = GNUNET_SYSERR;
1634 return GNUNET_TIME_UNIT_ZERO;
1636 if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, size))
1638 n->quota_violation_count++;
1639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1640 "Bandwidth quota (%u b/s) violation detected (total of %u).\n",
1641 n->in_tracker.available_bytes_per_s__,
1642 n->quota_violation_count);
1643 /* Discount 32k per violation */
1644 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, -32 * 1024);
1648 if (n->quota_violation_count > 0)
1650 /* try to add 32k back */
1651 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, 32 * 1024);
1652 n->quota_violation_count--;
1655 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
1657 GNUNET_STATISTICS_update (GST_stats,
1659 ("# bandwidth quota violations by other peers"),
1661 *do_forward = GNUNET_NO;
1662 return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT;
1664 *do_forward = GNUNET_YES;
1665 ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 32 * 1024);
1666 if (ret.rel_value_us > 0)
1668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1669 "Throttling read (%lld bytes excess at %u b/s), waiting %s before reading more.\n",
1670 (long long) n->in_tracker.consumption_since_last_update__,
1671 (unsigned int) n->in_tracker.available_bytes_per_s__,
1672 GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
1673 GNUNET_STATISTICS_update (GST_stats,
1674 gettext_noop ("# ms throttling suggested"),
1675 (int64_t) ret.rel_value_us / 1000LL,
1683 * Transmit a message to the given target using the active connection.
1685 * @param target destination
1686 * @param msg message to send
1687 * @param msg_size number of bytes in msg
1688 * @param timeout when to fail with timeout
1689 * @param cont function to call when done
1690 * @param cont_cls closure for @a cont
1693 GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
1696 struct GNUNET_TIME_Relative timeout,
1697 GST_NeighbourSendContinuation cont,
1700 struct NeighbourMapEntry *n;
1701 struct MessageQueue *mq;
1703 /* All ove these cases should never happen; they are all API violations.
1704 But we check anyway, just to be sure. */
1705 if (NULL == (n = lookup_neighbour (target)))
1715 if (GNUNET_YES != test_connected (n))
1725 bytes_in_send_queue += msg_size;
1726 GNUNET_STATISTICS_set (GST_stats,
1728 ("# bytes in message queue for other peers"),
1729 bytes_in_send_queue, GNUNET_NO);
1730 mq = GNUNET_malloc (sizeof (struct MessageQueue) + msg_size);
1732 mq->cont_cls = cont_cls;
1733 memcpy (&mq[1], msg, msg_size);
1734 mq->message_buf = (const char *) &mq[1];
1735 mq->message_buf_size = msg_size;
1736 mq->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1739 "Enqueueing %u bytes to send to peer %s\n",
1741 GNUNET_i2s (target));
1742 GNUNET_CONTAINER_DLL_insert_tail (n->messages_head,
1745 if (NULL != n->task)
1746 GNUNET_SCHEDULER_cancel (n->task);
1747 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
1752 * Continuation called from our attempt to transmitted our
1753 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN to the specified @a
1754 * target. Continue processing based on the @a result. Specifically,
1755 * if we failed to transmit, discard the address we used.
1758 * @param target which peer received the transmission
1759 * @param result #GNUNET_OK if sending worked
1760 * @param size_payload how many bytes of payload were sent (ignored)
1761 * @param size_on_wire how much bandwidth was consumed on the wire (ignored)
1764 send_session_syn_cont (void *cls,
1765 const struct GNUNET_PeerIdentity *target,
1767 size_t size_payload,
1768 size_t size_on_wire)
1770 struct NeighbourMapEntry *n;
1772 n = lookup_neighbour (target);
1775 /* SYN continuation was called after neighbor was freed,
1776 * for example due to a time out for the state or the session
1777 * used was already terminated: nothing to do here... */
1781 if ( (GNUNET_TRANSPORT_PS_SYN_SENT != n->state) &&
1782 (GNUNET_TRANSPORT_PS_RECONNECT_SENT != n->state) &&
1783 (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT != n->state))
1785 /* SYN continuation was called after neighbor changed state,
1786 * for example due to a time out for the state or the session
1787 * used was already terminated: nothing to do here... */
1790 if (GNUNET_OK == result)
1793 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1794 _("Failed to send SYN message to peer `%s'\n"),
1795 GNUNET_i2s (target));
1797 case GNUNET_TRANSPORT_PS_SYN_SENT:
1798 /* Remove address and request an additional one */
1799 unset_primary_address (n);
1800 set_state_and_timeout (n,
1801 GNUNET_TRANSPORT_PS_INIT_ATS,
1802 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
1804 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1805 /* Remove address and request an additional one */
1806 unset_primary_address (n);
1807 set_state_and_timeout (n,
1808 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
1809 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1811 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1812 /* Remove address and request and go back to primary address */
1813 GNUNET_STATISTICS_update (GST_stats,
1814 gettext_noop ("# Failed attempts to switch addresses (failed to send SYN CONT)"),
1817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1818 "Switch failed, cleaning up alternative address\n");
1819 free_address (&n->alternative_address);
1820 set_state_and_timeout (n,
1821 GNUNET_TRANSPORT_PS_CONNECTED,
1822 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1825 disconnect_neighbour (n);
1832 * Send a SYN message via the given address.
1834 * @param na address to use
1837 send_syn (struct NeighbourAddress *na)
1839 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1840 struct TransportSynMessage connect_msg;
1841 struct NeighbourMapEntry *n;
1843 GNUNET_assert (NULL != na->session);
1844 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1845 "Sending SYN message to peer `%s' at %s\n",
1846 GNUNET_i2s (&na->address->peer),
1847 GST_plugins_a2s (na->address));
1849 papi = GST_plugins_find (na->address->transport_name);
1850 GNUNET_assert (NULL != papi);
1851 GNUNET_STATISTICS_update (GST_stats,
1853 ("# SYN messages sent"),
1855 na->connect_timestamp = GNUNET_TIME_absolute_get ();
1856 connect_msg.header.size = htons (sizeof (struct TransportSynMessage));
1857 connect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN);
1858 connect_msg.reserved = htonl (0);
1859 connect_msg.timestamp = GNUNET_TIME_absolute_hton (na->connect_timestamp);
1861 papi->send (papi->cls,
1863 (const char *) &connect_msg,
1864 sizeof (struct TransportSynMessage),
1866 SETUP_CONNECTION_TIMEOUT,
1867 &send_session_syn_cont, NULL))
1869 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1870 _("Failed to transmit SYN message to %s\n"),
1871 GST_plugins_a2s (na->address));
1872 n = lookup_neighbour (&na->address->peer);
1879 case GNUNET_TRANSPORT_PS_SYN_SENT:
1880 /* Remove address and request and additional one */
1881 GNUNET_assert (na == &n->primary_address);
1882 unset_primary_address (n);
1883 set_state_and_timeout (n,
1884 GNUNET_TRANSPORT_PS_INIT_ATS,
1885 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
1886 /* Hard failure to send the SYN message with this address:
1887 Destroy address and session */
1889 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1890 /* Remove address and request an additional one */
1891 GNUNET_assert (na == &n->primary_address);
1892 unset_primary_address (n);
1893 set_state_and_timeout (n,
1894 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
1895 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1897 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1898 GNUNET_assert (na == &n->alternative_address);
1899 GNUNET_STATISTICS_update (GST_stats,
1900 gettext_noop ("# Failed attempts to switch addresses (failed to send SYN)"),
1903 /* Remove address and request an additional one */
1904 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1905 "Switch failed, cleaning up alternative address\n");
1906 free_address (&n->alternative_address);
1907 set_state_and_timeout (n,
1908 GNUNET_TRANSPORT_PS_CONNECTED,
1909 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1913 disconnect_neighbour (n);
1918 GST_neighbours_notify_data_sent (na->address,
1920 sizeof (struct TransportSynMessage));
1925 * Continuation called from our attempt to transmitted our
1926 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK to the specified @a
1927 * target. Continue processing based on the @a result. Specifically,
1928 * if we failed to transmit, discard the address we used.
1931 * @param target which peer received the transmission
1932 * @param result #GNUNET_OK if sending worked
1933 * @param size_payload how many bytes of payload were sent (ignored)
1934 * @param size_on_wire how much bandwidth was consumed on the wire (ignored)
1937 send_session_syn_ack_cont (void *cls,
1938 const struct GNUNET_PeerIdentity *target,
1940 size_t size_payload,
1941 size_t size_on_wire)
1943 struct NeighbourMapEntry *n;
1945 n = lookup_neighbour (target);
1948 /* SYN_ACK continuation was called after neighbor was freed,
1949 * for example due to a time out for the state or the session
1950 * used was already terminated: nothing to do here... */
1954 if (GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state)
1956 /* SYN_ACK continuation was called after neighbor changed state,
1957 * for example due to a time out for the state or the session
1958 * used was already terminated: nothing to do here... */
1961 if (GNUNET_OK == result)
1964 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1965 _("Failed to send SYN_ACK message to peer `%s' using address `%s'\n"),
1966 GNUNET_i2s (target),
1967 GST_plugins_a2s (n->primary_address.address));
1969 /* Remove address and request and additional one */
1970 /* FIXME: what if the neighbour's primary address
1971 changed in the meantime? Might want to instead
1972 pass "something" around in closure to be sure. */
1973 unset_primary_address (n);
1974 n->ack_state = ACK_SEND_SYN_ACK;
1975 set_state_and_timeout (n,
1976 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
1977 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1982 * Send a SYN_ACK message via the given address.
1984 * @param na address and session to use
1985 * @param timestamp timestamp to use for the ACK message
1986 * @return #GNUNET_SYSERR if sending immediately failed, #GNUNET_OK otherwise
1989 send_syn_ack_message (struct NeighbourAddress *na,
1990 struct GNUNET_TIME_Absolute timestamp)
1992 const struct GNUNET_HELLO_Address *address = na->address;
1993 struct Session *session = na->session;
1994 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1995 struct TransportSynMessage connect_msg;
1996 struct NeighbourMapEntry *n;
1998 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1999 "Sending SYN_ACK to peer `%s'\n",
2000 GNUNET_i2s (&address->peer));
2002 if (NULL == (papi = GST_plugins_find (address->transport_name)))
2007 if (NULL == session)
2008 session = papi->get_session (papi->cls,
2010 if (NULL == session)
2015 GST_ats_new_session (address,
2017 GNUNET_STATISTICS_update (GST_stats,
2019 ("# SYN_ACK messages sent"),
2021 connect_msg.header.size = htons (sizeof (struct TransportSynMessage));
2022 connect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK);
2023 connect_msg.reserved = htonl (0);
2024 connect_msg.timestamp = GNUNET_TIME_absolute_hton (timestamp);
2026 if (GNUNET_SYSERR ==
2027 papi->send (papi->cls,
2029 (const char *) &connect_msg,
2030 sizeof (struct TransportSynMessage),
2032 GNUNET_TIME_UNIT_FOREVER_REL,
2033 &send_session_syn_ack_cont, NULL))
2035 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2036 _("Failed to transmit SYN_ACK message to %s\n"),
2037 GST_plugins_a2s (address));
2039 n = lookup_neighbour (&address->peer);
2045 /* Remove address and request and additional one */
2046 unset_primary_address (n);
2047 n->ack_state = ACK_SEND_SYN_ACK;
2048 set_state_and_timeout (n,
2049 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2050 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
2057 * Function called by the bandwidth tracker for a peer whenever
2058 * the tracker's state changed such that we need to recalculate
2059 * the delay for flow control. We calculate the latest delay
2060 * and inform the plugin (if applicable).
2062 * @param cls the `struct NeighbourMapEntry` to update calculations for
2065 inbound_bw_tracker_update (void *cls)
2067 struct NeighbourMapEntry *n = cls;
2068 struct GNUNET_TRANSPORT_PluginFunctions *papi;
2069 struct GNUNET_TIME_Relative delay;
2072 if (NULL == n->primary_address.address)
2073 return; /* not active, ignore */
2074 papi = GST_plugins_find (n->primary_address.address->transport_name);
2075 GNUNET_assert (NULL != papi);
2076 if (NULL == papi->update_inbound_delay)
2078 delay = GST_neighbours_calculate_receive_delay (&n->id,
2081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2082 "New inbound delay for peer `%s' is %llu ms\n",
2083 GNUNET_i2s (&n->id),
2084 delay.rel_value_us / 1000);
2085 papi->update_inbound_delay (papi->cls,
2087 n->primary_address.session,
2093 * Create a fresh entry in the neighbour map for the given peer
2095 * @param peer peer to create an entry for
2096 * @return new neighbour map entry
2098 static struct NeighbourMapEntry *
2099 setup_neighbour (const struct GNUNET_PeerIdentity *peer)
2101 struct NeighbourMapEntry *n;
2103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2104 "Creating new neighbour entry for `%s'\n",
2106 n = GNUNET_new (struct NeighbourMapEntry);
2108 n->ack_state = ACK_UNDEFINED;
2109 n->last_util_transmission = GNUNET_TIME_absolute_get();
2110 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
2111 &inbound_bw_tracker_update,
2113 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
2114 MAX_BANDWIDTH_CARRY_S);
2115 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
2116 set_state_and_timeout (n,
2117 GNUNET_TRANSPORT_PS_NOT_CONNECTED,
2118 GNUNET_TIME_UNIT_FOREVER_ABS);
2119 GNUNET_assert (GNUNET_OK ==
2120 GNUNET_CONTAINER_multipeermap_put (neighbours,
2122 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2123 n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect,
2131 * Entry in a DLL we use to keep track of pending blacklist checks.
2133 struct BlacklistCheckSwitchContext
2138 struct BlacklistCheckSwitchContext *prev;
2143 struct BlacklistCheckSwitchContext *next;
2146 * Handle to the blacklist check we are performing.
2148 struct GST_BlacklistCheck *blc;
2151 * Inbound bandwidth that was assigned to @e address.
2153 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
2156 * Outbound bandwidth that was assigned to @e address.
2158 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
2163 * Black list check result for try_connect call
2164 * If connection to the peer is allowed request adddress and
2166 * @param cls blc_ctx bl context
2167 * @param peer the peer
2168 * @param address address associated with the request
2169 * @param session session associated with the request
2170 * @param result #GNUNET_OK if the connection is allowed,
2171 * #GNUNET_NO if not,
2172 * #GNUNET_SYSERR if operation was aborted
2175 try_connect_bl_check_cont (void *cls,
2176 const struct GNUNET_PeerIdentity *peer,
2177 const struct GNUNET_HELLO_Address *address,
2178 struct Session *session,
2181 struct BlacklistCheckSwitchContext *blc_ctx = cls;
2182 struct NeighbourMapEntry *n;
2184 GNUNET_CONTAINER_DLL_remove (pending_bc_head,
2187 GNUNET_free (blc_ctx);
2188 if (GNUNET_OK != result)
2190 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2191 _("Blacklisting disapproved to connect to peer `%s'\n"),
2196 /* Setup a new neighbour */
2197 if (NULL != lookup_neighbour(peer))
2198 return; /* The neighbor was created in the meantime while waited for BL clients */
2200 n = setup_neighbour (peer);
2202 /* Request address suggestions for this peer */
2203 set_state_and_timeout (n,
2204 GNUNET_TRANSPORT_PS_INIT_ATS,
2205 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
2210 * Try to create a connection to the given target (eventually).
2212 * @param target peer to try to connect to
2215 GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
2217 struct NeighbourMapEntry *n;
2218 struct GST_BlacklistCheck *blc;
2219 struct BlacklistCheckSwitchContext *blc_ctx;
2221 if (NULL == neighbours)
2223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2224 "Asked to connect to peer `%s' during shutdown\n",
2225 GNUNET_i2s (target));
2226 return; /* during shutdown, do nothing */
2228 n = lookup_neighbour (target);
2229 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2230 "Asked to connect to peer `%s' (state: %s)\n",
2231 GNUNET_i2s (target),
2232 (NULL != n) ? GNUNET_TRANSPORT_ps2s(n->state) : "NEW PEER");
2237 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2238 /* this should not be possible */
2242 case GNUNET_TRANSPORT_PS_INIT_ATS:
2243 case GNUNET_TRANSPORT_PS_SYN_SENT:
2244 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
2245 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
2246 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2247 "Ignoring request to try to connect to `%s', already trying!\n",
2248 GNUNET_i2s (target));
2249 return; /* already trying */
2250 case GNUNET_TRANSPORT_PS_CONNECTED:
2251 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
2252 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
2253 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
2254 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2255 "Ignoring request to try to connect, already connected to `%s'!\n",
2256 GNUNET_i2s (target));
2257 return; /* already connected */
2258 case GNUNET_TRANSPORT_PS_DISCONNECT:
2259 /* get rid of remains, ready to re-try immediately */
2262 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
2263 /* should not be possible */
2267 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2268 "Unhandled state `%s'\n",
2269 GNUNET_TRANSPORT_ps2s (n->state));
2276 /* Do blacklist check if connecting to this peer is allowed */
2277 blc_ctx = GNUNET_new (struct BlacklistCheckSwitchContext);
2278 GNUNET_CONTAINER_DLL_insert (pending_bc_head,
2283 (blc = GST_blacklist_test_allowed (target,
2285 &try_connect_bl_check_cont,
2296 * We received a 'SYN' message from the other peer.
2297 * Consider switching to it.
2299 * @param message possibly a 'struct TransportSynMessage' (check format)
2300 * @param peer identity of the peer to switch the address for
2301 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
2304 GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message,
2305 const struct GNUNET_PeerIdentity *peer)
2307 const struct TransportSynMessage *scm;
2308 struct NeighbourMapEntry *n;
2309 struct GNUNET_TIME_Absolute ts;
2311 if (ntohs (message->size) != sizeof (struct TransportSynMessage))
2313 GNUNET_break_op (0);
2314 return GNUNET_SYSERR;
2316 GNUNET_STATISTICS_update (GST_stats,
2318 ("# SYN messages received"),
2320 if (NULL == neighbours)
2322 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2323 _("SYN request from peer `%s' ignored due impending shutdown\n"),
2325 return GNUNET_OK; /* we're shutting down */
2327 scm = (const struct TransportSynMessage *) message;
2328 GNUNET_break_op (0 == ntohl (scm->reserved));
2329 ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
2330 n = lookup_neighbour (peer);
2333 /* This is a new neighbour and set to not connected */
2334 n = setup_neighbour (peer);
2337 /* Remember this SYN message in neighbour */
2338 n->ack_state = ACK_SEND_SYN_ACK;
2339 n->connect_ack_timestamp = ts;
2341 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2342 "Received SYN for peer `%s' in state %s/%s\n",
2344 GNUNET_TRANSPORT_ps2s (n->state),
2345 print_ack_state (n->ack_state));
2349 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2350 /* Request an address from ATS to send SYN_ACK to this peer */
2351 set_state_and_timeout (n,
2352 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2353 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
2355 case GNUNET_TRANSPORT_PS_INIT_ATS:
2356 /* SYN message takes priority over us asking ATS for address:
2357 * Wait for ATS to suggest an address and send SYN_ACK */
2358 set_state_and_timeout (n,
2359 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2360 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
2362 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
2363 /* We already wait for an address to send an SYN_ACK */
2365 case GNUNET_TRANSPORT_PS_SYN_SENT:
2366 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
2367 /* Send ACK immediately */
2368 n->ack_state = ACK_SEND_ACK;
2369 send_syn_ack_message (&n->primary_address,
2372 case GNUNET_TRANSPORT_PS_CONNECTED:
2373 /* we are already connected and can thus send the ACK immediately */
2374 GNUNET_assert (NULL != n->primary_address.address);
2375 GNUNET_assert (NULL != n->primary_address.session);
2376 n->ack_state = ACK_SEND_ACK;
2377 send_syn_ack_message (&n->primary_address,
2380 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
2381 /* We wait for ATS address suggestion */
2383 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
2384 /* We received a SYN message while waiting for a SYN_ACK in fast
2385 * reconnect. Send SYN_ACK immediately */
2386 n->ack_state = ACK_SEND_ACK;
2387 send_syn_ack_message (&n->primary_address,
2388 n->connect_ack_timestamp);
2390 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
2391 /* We are already connected and can thus send the ACK immediately;
2392 still, it can never hurt to have an alternative address, so also
2393 tell ATS about it */
2394 GNUNET_assert (NULL != n->primary_address.address);
2395 GNUNET_assert (NULL != n->primary_address.session);
2396 n->ack_state = ACK_SEND_ACK;
2397 send_syn_ack_message (&n->primary_address,
2400 case GNUNET_TRANSPORT_PS_DISCONNECT:
2401 /* Get rid of remains and re-try */
2403 n = setup_neighbour (peer);
2404 /* Remember the SYN time stamp for ACK message */
2405 n->ack_state = ACK_SEND_SYN_ACK;
2406 n->connect_ack_timestamp = ts;
2407 /* Request an address for the peer */
2408 set_state_and_timeout (n,
2409 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2410 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
2412 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
2413 /* should not be possible */
2417 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2418 "Unhandled state `%s'\n",
2419 GNUNET_TRANSPORT_ps2s (n->state));
2421 return GNUNET_SYSERR;
2428 * Check if the given @a address is the same that we are already
2429 * using for the respective neighbour. If so, update the bandwidth
2430 * assignment and possibly the session and return #GNUNET_OK.
2431 * If the new address is different from what the neighbour is
2432 * using right now, return #GNUNET_NO.
2434 * @param address address of the other peer,
2435 * @param session session to use or NULL if transport should initiate a session
2436 * @param bandwidth_in inbound quota to be used when connection is up,
2437 * 0 to disconnect from peer
2438 * @param bandwidth_out outbound quota to be used when connection is up,
2439 * 0 to disconnect from peer
2440 * @return #GNUNET_OK if we were able to just update the bandwidth and session,
2441 * #GNUNET_NO if more extensive changes are required (address changed)
2444 try_run_fast_ats_update (const struct GNUNET_HELLO_Address *address,
2445 struct Session *session,
2446 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
2447 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2449 struct NeighbourMapEntry *n;
2451 n = lookup_neighbour (&address->peer);
2453 (NULL == n->primary_address.address) ||
2454 (0 != GNUNET_HELLO_address_cmp (address,
2455 n->primary_address.address)) )
2457 /* We are not really switching addresses, but merely adjusting
2458 session and/or bandwidth, can do fast ATS update! */
2459 if (session != n->primary_address.session)
2461 /* switch to a different session, but keeping same address; could
2462 happen if there is a 2nd inbound connection */
2463 n->primary_address.session = session;
2464 GNUNET_assert (GNUNET_YES ==
2465 GST_ats_is_known (n->primary_address.address,
2466 n->primary_address.session));
2468 n->primary_address.bandwidth_in = bandwidth_in;
2469 n->primary_address.bandwidth_out = bandwidth_out;
2470 GST_neighbours_set_incoming_quota (&address->peer,
2472 send_outbound_quota (&address->peer,
2479 * We've been asked to switch addresses, and just now got the result
2480 * from the blacklist check to see if this is allowed.
2482 * @param cls the `struct BlacklistCheckSwitchContext` with
2483 * the information about the future address
2484 * @param peer the peer we may switch addresses on
2485 * @param address address associated with the request
2486 * @param session session associated with the request
2487 * @param result #GNUNET_OK if the connection is allowed,
2488 * #GNUNET_NO if not,
2489 * #GNUNET_SYSERR if operation was aborted
2492 switch_address_bl_check_cont (void *cls,
2493 const struct GNUNET_PeerIdentity *peer,
2494 const struct GNUNET_HELLO_Address *address,
2495 struct Session *session,
2498 struct BlacklistCheckSwitchContext *blc_ctx = cls;
2499 struct GNUNET_TRANSPORT_PluginFunctions *papi;
2500 struct NeighbourMapEntry *n;
2502 if (GNUNET_SYSERR == result)
2505 papi = GST_plugins_find (address->transport_name);
2506 GNUNET_assert (NULL != papi);
2508 if (GNUNET_NO == result)
2510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2511 "Blacklist denied to switch to suggested address `%s' session %p for peer `%s'\n",
2512 GST_plugins_a2s (address),
2515 GNUNET_STATISTICS_update (GST_stats,
2516 "# ATS suggestions ignored (blacklist denied)",
2519 papi->disconnect_session (papi->cls,
2522 GNUNET_HELLO_address_check_option (address,
2523 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
2524 GST_ats_block_address (address,
2530 if (NULL == session)
2532 /* need to create a session, ATS only gave us an address */
2533 session = papi->get_session (papi->cls,
2535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2536 "Obtained new session for peer `%s' and address '%s': %p\n",
2537 GNUNET_i2s (&address->peer),
2538 GST_plugins_a2s (address),
2540 if (NULL != session)
2541 GST_ats_new_session (address,
2544 if (NULL == session)
2546 /* session creation failed, bad!, fail! */
2547 GNUNET_STATISTICS_update (GST_stats,
2548 "# ATS suggestions ignored (failed to create session)",
2551 /* No session could be obtained, remove blacklist check and clean up */
2552 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2553 "Failed to obtain new session for peer `%s' and address '%s'\n",
2554 GNUNET_i2s (&address->peer),
2555 GST_plugins_a2s (address));
2556 GST_ats_block_address (address,
2561 /* We did this check already before going into blacklist, but
2562 it is theoretically possible that the situation changed in
2563 the meantime, hence we check again here */
2565 try_run_fast_ats_update (address,
2567 blc_ctx->bandwidth_in,
2568 blc_ctx->bandwidth_out))
2569 goto cleanup; /* was just a minor update, we're done */
2571 /* check if we also need to setup the neighbour entry */
2572 if (NULL == (n = lookup_neighbour (peer)))
2574 n = setup_neighbour (peer);
2575 n->state = GNUNET_TRANSPORT_PS_INIT_ATS;
2578 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2579 "Peer `%s' switches to address `%s'\n",
2580 GNUNET_i2s (&address->peer),
2581 GST_plugins_a2s (address));
2585 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2587 GST_ats_block_address (address,
2591 case GNUNET_TRANSPORT_PS_INIT_ATS:
2592 /* We requested an address and ATS suggests one:
2593 * set primary address and send SYN message*/
2594 set_primary_address (n,
2597 blc_ctx->bandwidth_in,
2598 blc_ctx->bandwidth_out);
2599 if (ACK_SEND_SYN_ACK == n->ack_state)
2601 /* Send pending SYN_ACK message */
2602 n->ack_state = ACK_SEND_ACK;
2603 send_syn_ack_message (&n->primary_address,
2604 n->connect_ack_timestamp);
2606 set_state_and_timeout (n,
2607 GNUNET_TRANSPORT_PS_SYN_SENT,
2608 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
2609 send_syn (&n->primary_address);
2611 case GNUNET_TRANSPORT_PS_SYN_SENT:
2612 /* ATS suggested a new address while waiting for an SYN_ACK:
2613 * Switch and send new SYN */
2614 /* ATS suggests a different address, switch again */
2615 set_primary_address (n,
2618 blc_ctx->bandwidth_in,
2619 blc_ctx->bandwidth_out);
2620 if (ACK_SEND_SYN_ACK == n->ack_state)
2622 /* Send pending SYN_ACK message */
2623 n->ack_state = ACK_SEND_ACK;
2624 send_syn_ack_message (&n->primary_address,
2625 n->connect_ack_timestamp);
2627 set_state_and_timeout (n,
2628 GNUNET_TRANSPORT_PS_SYN_SENT,
2629 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
2630 send_syn (&n->primary_address);
2632 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
2633 /* We requested an address and ATS suggests one:
2634 * set primary address and send SYN_ACK message*/
2635 set_primary_address (n,
2638 blc_ctx->bandwidth_in,
2639 blc_ctx->bandwidth_out);
2640 /* Send an ACK message as a response to the SYN msg */
2641 set_state_and_timeout (n,
2642 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
2643 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
2644 send_syn_ack_message (&n->primary_address,
2645 n->connect_ack_timestamp);
2646 if ( (ACK_SEND_SYN_ACK == n->ack_state) ||
2647 (ACK_UNDEFINED == n->ack_state) )
2648 n->ack_state = ACK_SEND_ACK;
2650 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
2651 /* ATS asks us to switch while we were trying to connect; switch to new
2652 address and check blacklist again */
2653 if ( (ACK_SEND_SYN_ACK == n->ack_state) )
2655 n->ack_state = ACK_SEND_ACK;
2656 send_syn_ack_message (&n->primary_address,
2657 n->connect_ack_timestamp);
2659 set_primary_address (n,
2662 blc_ctx->bandwidth_in,
2663 blc_ctx->bandwidth_out);
2664 set_state_and_timeout (n,
2665 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
2666 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
2668 case GNUNET_TRANSPORT_PS_CONNECTED:
2669 GNUNET_assert (NULL != n->primary_address.address);
2670 GNUNET_assert (NULL != n->primary_address.session);
2671 GNUNET_break (n->primary_address.session != session);
2672 /* ATS asks us to switch a life connection; see if we can get
2673 a SYN_ACK on it before we actually do this! */
2674 set_alternative_address (n,
2677 blc_ctx->bandwidth_in,
2678 blc_ctx->bandwidth_out);
2679 set_state_and_timeout (n,
2680 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
2681 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
2682 GNUNET_STATISTICS_update (GST_stats,
2683 gettext_noop ("# Attempts to switch addresses"),
2686 send_syn (&n->alternative_address);
2688 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
2689 set_primary_address (n,
2692 blc_ctx->bandwidth_in,
2693 blc_ctx->bandwidth_out);
2694 if (ACK_SEND_SYN_ACK == n->ack_state)
2696 /* Send pending SYN_ACK message */
2697 n->ack_state = ACK_SEND_ACK;
2698 send_syn_ack_message (&n->primary_address,
2699 n->connect_ack_timestamp);
2701 set_state_and_timeout (n,
2702 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
2703 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
2704 send_syn (&n->primary_address);
2706 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
2707 /* ATS asks us to switch while we were trying to reconnect; switch to new
2708 address and send SYN again */
2709 set_primary_address (n,
2712 blc_ctx->bandwidth_in,
2713 blc_ctx->bandwidth_out);
2714 set_state_and_timeout (n,
2715 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
2716 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
2717 send_syn (&n->primary_address);
2719 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
2720 if ( (0 == GNUNET_HELLO_address_cmp (n->primary_address.address,
2722 (n->primary_address.session == session) )
2724 /* ATS switches back to still-active session */
2725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2726 "ATS double-switched, cleaning up alternative address\n");
2727 free_address (&n->alternative_address);
2728 set_state_and_timeout (n,
2729 GNUNET_TRANSPORT_PS_CONNECTED,
2733 /* ATS asks us to switch a life connection, send */
2734 set_alternative_address (n,
2737 blc_ctx->bandwidth_in,
2738 blc_ctx->bandwidth_out);
2739 set_state_and_timeout (n,
2740 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
2741 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
2742 send_syn (&n->alternative_address);
2744 case GNUNET_TRANSPORT_PS_DISCONNECT:
2745 /* not going to switch addresses while disconnecting */
2746 GNUNET_STATISTICS_update (GST_stats,
2747 "# ATS suggestion ignored (disconnecting)",
2751 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
2755 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2756 "Unhandled state `%s'\n",
2757 GNUNET_TRANSPORT_ps2s (n->state));
2762 GNUNET_CONTAINER_DLL_remove (pending_bc_head,
2765 GNUNET_free (blc_ctx);
2770 * For the given peer, switch to this address.
2772 * Before accepting this addresses and actively using it, a blacklist check
2775 * If any check fails or the suggestion can somehow not be followed, we
2776 * MUST call #GST_ats_block_address() to tell ATS that the suggestion
2777 * could not be satisfied and force ATS to do something else.
2779 * @param address address of the other peer,
2780 * @param session session to use or NULL if transport should initiate a session
2781 * @param bandwidth_in inbound quota to be used when connection is up,
2782 * 0 to disconnect from peer
2783 * @param bandwidth_out outbound quota to be used when connection is up,
2784 * 0 to disconnect from peer
2787 GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address,
2788 struct Session *session,
2789 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
2790 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2792 struct GST_BlacklistCheck *blc;
2793 struct BlacklistCheckSwitchContext *blc_ctx;
2795 GNUNET_assert (NULL != address->transport_name);
2797 try_run_fast_ats_update (address,
2803 /* Check if plugin is available */
2804 if (NULL == (GST_plugins_find (address->transport_name)))
2806 /* we don't have the plugin for this address */
2808 GST_ats_block_address (address,
2812 if ((NULL == session) &&
2813 (GNUNET_HELLO_address_check_option (address,
2814 GNUNET_HELLO_ADDRESS_INFO_INBOUND)))
2816 /* This is a inbound address and we do not have a session to use! */
2818 GST_ats_block_address (address,
2823 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2824 "ATS suggests address '%s' for peer `%s' at %u/%u speed\n",
2825 GST_plugins_a2s (address),
2826 GNUNET_i2s (&address->peer),
2827 (unsigned int) ntohl (bandwidth_in.value__),
2828 (unsigned int) ntohl (bandwidth_out.value__));
2830 /* Perform blacklist check */
2831 blc_ctx = GNUNET_new (struct BlacklistCheckSwitchContext);
2832 blc_ctx->bandwidth_in = bandwidth_in;
2833 blc_ctx->bandwidth_out = bandwidth_out;
2834 GNUNET_CONTAINER_DLL_insert (pending_bc_head,
2837 if (NULL != (blc = GST_blacklist_test_allowed (&address->peer,
2838 address->transport_name,
2839 &switch_address_bl_check_cont,
2850 * Function called to send network utilization data to ATS for
2851 * each active connection.
2854 * @param key peer we send utilization data for
2855 * @param value the `struct NeighbourMapEntry *` with data to send
2856 * @return #GNUNET_OK (continue to iterate)
2859 send_utilization_data (void *cls,
2860 const struct GNUNET_PeerIdentity *key,
2863 struct NeighbourMapEntry *n = value;
2866 struct GNUNET_TIME_Relative delta;
2868 if ( (GNUNET_YES != test_connected (n)) ||
2869 (NULL == n->primary_address.address) )
2871 delta = GNUNET_TIME_absolute_get_difference (n->last_util_transmission,
2872 GNUNET_TIME_absolute_get ());
2874 if ((0 != n->util_total_bytes_recv) && (0 != delta.rel_value_us))
2875 bps_in = (1000LL * 1000LL * n->util_total_bytes_recv) / (delta.rel_value_us);
2877 if ((0 != n->util_total_bytes_sent) && (0 != delta.rel_value_us))
2878 bps_out = (1000LL * 1000LL * n->util_total_bytes_sent) / delta.rel_value_us;
2880 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2881 "`%s' total: received %u Bytes/s, sent %u Bytes/s\n",
2885 GST_ats_update_utilization (n->primary_address.address,
2888 n->util_total_bytes_recv = 0;
2889 n->util_total_bytes_sent = 0;
2890 n->last_util_transmission = GNUNET_TIME_absolute_get ();
2896 * Task transmitting utilization in a regular interval
2898 * @param cls the 'struct NeighbourMapEntry' for which we are running
2899 * @param tc scheduler context (unused)
2902 utilization_transmission (void *cls,
2903 const struct GNUNET_SCHEDULER_TaskContext *tc)
2905 util_transmission_tk = NULL;
2906 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
2907 &send_utilization_data,
2909 util_transmission_tk
2910 = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL,
2911 &utilization_transmission,
2917 * Track information about data we received from the
2918 * given address (used to notify ATS about our utilization
2919 * of allocated resources).
2921 * @param address the address we got data from
2922 * @param message the message we received (really only the size is used)
2925 GST_neighbours_notify_data_recv (const struct GNUNET_HELLO_Address *address,
2926 const struct GNUNET_MessageHeader *message)
2928 struct NeighbourMapEntry *n;
2930 n = lookup_neighbour (&address->peer);
2933 n->util_total_bytes_recv += ntohs (message->size);
2938 * Track information about data we transmitted using the given @a
2939 * address and @a session (used to notify ATS about our utilization of
2940 * allocated resources).
2942 * @param address the address we transmitted data to
2943 * @param session session we used to transmit data
2944 * @param message the message we sent (really only the size is used)
2947 GST_neighbours_notify_data_sent (const struct GNUNET_HELLO_Address *address,
2948 struct Session *session,
2951 struct NeighbourMapEntry *n;
2953 n = lookup_neighbour (&address->peer);
2956 if (n->primary_address.session != session)
2958 n->util_total_bytes_sent += size;
2963 * Master task run for every neighbour. Performs all of the time-related
2964 * activities (keep alive, send next message, disconnect if idle, finish
2965 * clean up after disconnect).
2967 * @param cls the 'struct NeighbourMapEntry' for which we are running
2968 * @param tc scheduler context (unused)
2971 master_task (void *cls,
2972 const struct GNUNET_SCHEDULER_TaskContext *tc)
2974 struct NeighbourMapEntry *n = cls;
2975 struct GNUNET_TIME_Relative delay;
2978 delay = GNUNET_TIME_absolute_get_remaining (n->timeout);
2979 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2980 "Master task runs for neighbour `%s' in state %s with timeout in %s\n",
2981 GNUNET_i2s (&n->id),
2982 GNUNET_TRANSPORT_ps2s(n->state),
2983 GNUNET_STRINGS_relative_time_to_string (delay,
2987 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2988 /* invalid state for master task, clean up */
2992 case GNUNET_TRANSPORT_PS_INIT_ATS:
2993 if (0 == delay.rel_value_us)
2995 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2996 "Connection to `%s' timed out waiting for ATS to provide address\n",
2997 GNUNET_i2s (&n->id));
3002 case GNUNET_TRANSPORT_PS_SYN_SENT:
3003 if (0 == delay.rel_value_us)
3005 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3006 "Connection to `%s' timed out waiting for other peer to send SYN_ACK\n",
3007 GNUNET_i2s (&n->id));
3008 /* Remove address and request and additional one */
3009 unset_primary_address (n);
3010 set_state_and_timeout (n,
3011 GNUNET_TRANSPORT_PS_INIT_ATS,
3012 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
3016 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3017 if (0 == delay.rel_value_us)
3019 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3020 "Connection to `%s' timed out waiting ATS to provide address to use for SYN_ACK\n",
3021 GNUNET_i2s (&n->id));
3026 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3027 if (0 == delay.rel_value_us)
3029 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3030 "Connection to `%s' timed out waiting for other peer to send ACK\n",
3031 GNUNET_i2s (&n->id));
3032 disconnect_neighbour (n);
3036 case GNUNET_TRANSPORT_PS_CONNECTED:
3037 if (0 == delay.rel_value_us)
3039 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3040 "Connection to `%s' timed out, missing KEEPALIVE_RESPONSEs\n",
3041 GNUNET_i2s (&n->id));
3042 disconnect_neighbour (n);
3045 try_transmission_to_peer (n);
3048 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
3049 if (0 == delay.rel_value_us)
3051 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3052 "Connection to `%s' timed out, waiting for ATS replacement address\n",
3053 GNUNET_i2s (&n->id));
3054 disconnect_neighbour (n);
3058 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
3059 if (0 == delay.rel_value_us)
3061 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3062 "Connection to `%s' timed out, waiting for other peer to SYN_ACK replacement address\n",
3063 GNUNET_i2s (&n->id));
3064 disconnect_neighbour (n);
3068 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3069 if (0 == delay.rel_value_us)
3071 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3072 "Switch failed, cleaning up alternative address\n");
3073 free_address (&n->alternative_address);
3074 set_state_and_timeout (n,
3075 GNUNET_TRANSPORT_PS_CONNECTED,
3076 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
3078 try_transmission_to_peer (n);
3081 case GNUNET_TRANSPORT_PS_DISCONNECT:
3082 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3083 "Cleaning up connection to `%s' after sending DISCONNECT\n",
3084 GNUNET_i2s (&n->id));
3087 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
3088 /* how did we get here!? */
3092 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3093 "Unhandled state `%s'\n",
3094 GNUNET_TRANSPORT_ps2s (n->state));
3098 delay = GNUNET_TIME_absolute_get_remaining (n->timeout);
3099 if ( (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) ||
3100 (GNUNET_TRANSPORT_PS_CONNECTED == n->state) )
3102 /* if we are *now* in one of the two states, we're sending
3103 keep alive messages, so we need to consider the keepalive
3104 delay, not just the connection timeout */
3105 delay = GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining (n->keep_alive_time),
3108 if (NULL == n->task)
3109 n->task = GNUNET_SCHEDULER_add_delayed (delay,
3116 * Send a ACK message to the neighbour to confirm that we
3119 * @param n neighbour to send the ACK to
3122 send_session_ack_message (struct NeighbourMapEntry *n)
3124 struct GNUNET_MessageHeader msg;
3126 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3127 "Sending ACK message to peer `%s'\n",
3128 GNUNET_i2s (&n->id));
3130 msg.size = htons (sizeof (struct GNUNET_MessageHeader));
3131 msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK);
3132 (void) send_with_session (n,
3134 sizeof (struct GNUNET_MessageHeader),
3136 GNUNET_TIME_UNIT_FOREVER_REL,
3143 * We received a 'SESSION_SYN_ACK' message from the other peer.
3144 * Consider switching to it.
3146 * @param message possibly a `struct SessionConnectMessage` (check format)
3147 * @param peer identity of the peer to switch the address for
3148 * @param address address of the other peer, NULL if other peer
3150 * @param session session to use (or NULL)
3151 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
3154 GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *message,
3155 const struct GNUNET_HELLO_Address *address,
3156 struct Session *session)
3158 const struct TransportSynMessage *scm;
3159 struct GNUNET_TIME_Absolute ts;
3160 struct NeighbourMapEntry *n;
3162 if (ntohs (message->size) != sizeof (struct TransportSynMessage))
3164 GNUNET_break_op (0);
3165 return GNUNET_SYSERR;
3167 GNUNET_STATISTICS_update (GST_stats,
3169 ("# SYN_ACK messages received"),
3171 scm = (const struct TransportSynMessage *) message;
3172 GNUNET_break_op (ntohl (scm->reserved) == 0);
3173 if (NULL == (n = lookup_neighbour (&address->peer)))
3175 GNUNET_STATISTICS_update (GST_stats,
3177 ("# unexpected SYN_ACK messages (no peer)"),
3179 return GNUNET_SYSERR;
3181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3182 "Received SYN_ACK message from peer `%s' in state %s/%s\n",
3183 GNUNET_i2s (&address->peer),
3184 GNUNET_TRANSPORT_ps2s (n->state),
3185 print_ack_state (n->ack_state));
3186 ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
3189 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
3192 return GNUNET_SYSERR;
3193 case GNUNET_TRANSPORT_PS_INIT_ATS:
3194 GNUNET_STATISTICS_update (GST_stats,
3195 gettext_noop ("# unexpected SYN_ACK messages (not ready)"),
3199 case GNUNET_TRANSPORT_PS_SYN_SENT:
3200 if (ts.abs_value_us != n->primary_address.connect_timestamp.abs_value_us)
3202 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3203 "SYN_ACK ignored as the timestamp does not match our SYN request\n");
3206 set_state_and_timeout (n,
3207 GNUNET_TRANSPORT_PS_CONNECTED,
3208 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3209 set_primary_address (n,
3210 n->primary_address.address,
3211 n->primary_address.session,
3212 n->primary_address.bandwidth_in,
3213 n->primary_address.bandwidth_out);
3214 send_session_ack_message (n);
3216 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3217 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3218 GNUNET_STATISTICS_update (GST_stats,
3219 gettext_noop ("# unexpected SYN_ACK messages (not ready)"),
3223 case GNUNET_TRANSPORT_PS_CONNECTED:
3224 /* duplicate SYN_ACK, let's answer by duplicate ACK just in case */
3225 send_session_ack_message (n);
3227 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
3228 /* we didn't expect any SYN_ACK, as we are waiting for ATS
3229 to give us a new address... */
3230 GNUNET_STATISTICS_update (GST_stats,
3231 gettext_noop ("# unexpected SYN_ACK messages (waiting on ATS)"),
3235 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
3236 /* Reconnecting with new address address worked; go back to connected! */
3237 set_state_and_timeout (n,
3238 GNUNET_TRANSPORT_PS_CONNECTED,
3239 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3240 send_session_ack_message (n);
3242 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3243 /* new address worked; adopt it and go back to connected! */
3244 set_state_and_timeout (n,
3245 GNUNET_TRANSPORT_PS_CONNECTED,
3246 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3247 GNUNET_break (GNUNET_NO == n->alternative_address.ats_active);
3249 /* Set primary addresses */
3250 set_primary_address (n,
3251 n->alternative_address.address,
3252 n->alternative_address.session,
3253 n->alternative_address.bandwidth_in,
3254 n->alternative_address.bandwidth_out);
3255 GNUNET_STATISTICS_update (GST_stats,
3256 gettext_noop ("# Successful attempts to switch addresses"),
3260 GNUNET_HELLO_address_free (n->alternative_address.address);
3261 memset (&n->alternative_address,
3263 sizeof (n->alternative_address));
3264 send_session_ack_message (n);
3266 case GNUNET_TRANSPORT_PS_DISCONNECT:
3267 GNUNET_STATISTICS_update (GST_stats,
3269 ("# unexpected SYN_ACK messages (disconnecting)"),
3271 return GNUNET_SYSERR;
3272 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
3276 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3277 "Unhandled state `%s'\n",
3278 GNUNET_TRANSPORT_ps2s (n->state));
3280 return GNUNET_SYSERR;
3287 * A session was terminated. Take note; if needed, try to get
3288 * an alternative address from ATS.
3290 * @param peer identity of the peer where the session died
3291 * @param session session that is gone
3292 * @return #GNUNET_YES if this was a session used, #GNUNET_NO if
3293 * this session was not in use
3296 GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
3297 struct Session *session)
3299 struct NeighbourMapEntry *n;
3300 struct BlackListCheckContext *bcc;
3301 struct BlackListCheckContext *bcc_next;
3303 /* make sure to cancel all ongoing blacklist checks involving 'session' */
3305 while (NULL != (bcc = bcc_next))
3307 bcc_next = bcc->next;
3308 if (bcc->na.session == session)
3310 if (NULL != bcc->bc)
3311 GST_blacklist_test_cancel (bcc->bc);
3312 GNUNET_HELLO_address_free (bcc->na.address);
3313 GNUNET_CONTAINER_DLL_remove (bc_head,
3319 if (NULL == (n = lookup_neighbour (peer)))
3320 return GNUNET_NO; /* can't affect us */
3321 if (session != n->primary_address.session)
3323 /* Free alternative address */
3324 if (session == n->alternative_address.session)
3326 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state)
3327 set_state_and_timeout (n,
3328 GNUNET_TRANSPORT_PS_CONNECTED,
3330 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3331 "Session died, cleaning up alternative address\n");
3332 free_address (&n->alternative_address);
3334 return GNUNET_NO; /* doesn't affect us further */
3337 n->expect_latency_response = GNUNET_NO;
3338 /* The session for neighbour's primary address died */
3341 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
3345 case GNUNET_TRANSPORT_PS_INIT_ATS:
3349 case GNUNET_TRANSPORT_PS_SYN_SENT:
3350 /* The session used to send the SYN terminated:
3351 * this implies a connect error*/
3352 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3353 "Failed to send SYN in %s with `%s' %p: session terminated\n",
3355 GST_plugins_a2s (n->primary_address.address),
3356 n->primary_address.session,
3359 /* Destroy the address since it cannot be used */
3360 unset_primary_address (n);
3361 set_state_and_timeout (n,
3362 GNUNET_TRANSPORT_PS_INIT_ATS,
3363 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
3365 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3366 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3367 /* error on inbound session; free neighbour entirely */
3370 case GNUNET_TRANSPORT_PS_CONNECTED:
3371 /* Our primary connection died, try a fast reconnect */
3372 unset_primary_address (n);
3373 set_state_and_timeout (n,
3374 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
3375 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
3377 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
3378 /* we don't have an address, how can it go down? */
3381 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
3382 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3383 "Failed to send SYN in %s with `%s' %p: session terminated\n",
3385 GST_plugins_a2s (n->primary_address.address),
3386 n->primary_address.session,
3388 /* Destroy the address since it cannot be used */
3389 unset_primary_address (n);
3390 set_state_and_timeout (n,
3391 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
3392 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
3394 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3395 /* primary went down while we were waiting for SYN_ACK on secondary;
3396 secondary as primary */
3398 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3399 "Connection `%s' %p to peer `%s' was terminated while switching, "
3400 "switching to alternative address `%s' %p\n",
3401 GST_plugins_a2s (n->primary_address.address),
3402 n->primary_address.session,
3404 GST_plugins_a2s (n->alternative_address.address),
3405 n->alternative_address.session);
3407 /* Destroy the inbound address since it cannot be used */
3408 free_address (&n->primary_address);
3409 n->primary_address = n->alternative_address;
3410 GNUNET_assert (GNUNET_YES ==
3411 GST_ats_is_known (n->primary_address.address,
3412 n->primary_address.session));
3413 memset (&n->alternative_address,
3415 sizeof (struct NeighbourAddress));
3416 set_state_and_timeout (n,
3417 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
3418 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
3420 case GNUNET_TRANSPORT_PS_DISCONNECT:
3421 unset_primary_address (n);
3423 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
3424 /* neighbour was freed and plugins told to terminate session */
3427 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3428 "Unhandled state `%s'\n",
3429 GNUNET_TRANSPORT_ps2s (n->state));
3433 if (NULL != n->task)
3434 GNUNET_SCHEDULER_cancel (n->task);
3435 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
3441 * We received a 'ACK' message from the other peer.
3442 * If we sent a 'SYN_ACK' last, this means we are now
3443 * connected. Otherwise, do nothing.
3445 * @param message possibly a 'struct SessionConnectMessage' (check format)
3446 * @param address address of the other peer
3447 * @param session session to use (or NULL)
3448 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
3451 GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3452 const struct GNUNET_HELLO_Address *address,
3453 struct Session *session)
3455 struct NeighbourMapEntry *n;
3457 if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader))
3459 GNUNET_break_op (0);
3460 return GNUNET_SYSERR;
3462 GNUNET_STATISTICS_update (GST_stats,
3463 gettext_noop ("# ACK messages received"),
3466 if (NULL == (n = lookup_neighbour (&address->peer)))
3468 GNUNET_break_op (0);
3469 return GNUNET_SYSERR;
3471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3472 "Received ACK for peer `%s' in state %s/%s\n",
3473 GNUNET_i2s (&address->peer),
3474 GNUNET_TRANSPORT_ps2s (n->state),
3475 print_ack_state (n->ack_state));
3477 /* Check if we are in a plausible state for having sent
3478 a SYN_ACK. If not, return, otherwise break.
3480 The remote peers sends a ACK as a response for a SYN_ACK
3484 - If a remote peer has sent a SYN, we responded with a SYN_ACK and
3485 now wait for the ACK to finally be connected
3486 - If we sent a SYN_ACK to this peer before */
3488 if ( (GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state) &&
3489 (ACK_SEND_ACK != n->ack_state))
3491 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3492 "Received unexpected ACK message from peer `%s' in state %s/%s\n",
3493 GNUNET_i2s (&address->peer),
3494 GNUNET_TRANSPORT_ps2s (n->state),
3495 print_ack_state (n->ack_state));
3497 GNUNET_STATISTICS_update (GST_stats,
3498 gettext_noop ("# unexpected ACK messages"),
3503 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state)
3505 /* We tried to switch addresses while being connect. We explicitly wait
3506 * for a SYN_ACK before going to GNUNET_TRANSPORT_PS_CONNECTED,
3507 * so we do not want to set the address as in use! */
3510 set_state_and_timeout (n,
3511 GNUNET_TRANSPORT_PS_CONNECTED,
3512 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3514 /* Reset backoff for primary address */
3515 GST_ats_block_reset (n->primary_address.address,
3516 n->primary_address.session);
3522 * Test if we're connected to the given peer.
3524 * @param target peer to test
3525 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not
3528 GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target)
3530 return test_connected (lookup_neighbour (target));
3535 * Change the incoming quota for the given peer.
3537 * @param neighbour identity of peer to change qutoa for
3538 * @param quota new quota
3541 GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
3542 struct GNUNET_BANDWIDTH_Value32NBO quota)
3544 struct NeighbourMapEntry *n;
3546 if (NULL == (n = lookup_neighbour (neighbour)))
3548 GNUNET_STATISTICS_update (GST_stats,
3550 ("# SET QUOTA messages ignored (no such peer)"),
3554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3555 "Setting inbound quota of %u Bps for peer `%s' to all clients\n",
3556 ntohl (quota.value__), GNUNET_i2s (&n->id));
3557 GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker, quota);
3558 if (0 != ntohl (quota.value__))
3560 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3561 "Disconnecting peer `%4s' due to SET_QUOTA\n",
3562 GNUNET_i2s (&n->id));
3563 if (GNUNET_YES == test_connected (n))
3564 GNUNET_STATISTICS_update (GST_stats,
3565 gettext_noop ("# disconnects due to quota of 0"),
3567 disconnect_neighbour (n);
3572 * Task to asynchronously run #free_neighbour().
3574 * @param cls the `struct NeighbourMapEntry` to free
3578 delayed_disconnect (void *cls,
3579 const struct GNUNET_SCHEDULER_TaskContext* tc)
3581 struct NeighbourMapEntry *n = cls;
3583 n->delayed_disconnect_task = NULL;
3584 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3585 "Disconnecting by request from peer %s\n",
3586 GNUNET_i2s (&n->id));
3592 * We received a disconnect message from the given peer,
3593 * validate and process.
3595 * @param peer sender of the message
3596 * @param msg the disconnect message
3599 GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer,
3600 const struct GNUNET_MessageHeader *msg)
3602 struct NeighbourMapEntry *n;
3603 const struct SessionDisconnectMessage *sdm;
3605 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3606 "Received DISCONNECT message from peer `%s'\n",
3608 if (ntohs (msg->size) != sizeof (struct SessionDisconnectMessage))
3610 GNUNET_break_op (0);
3611 GNUNET_STATISTICS_update (GST_stats,
3613 ("# disconnect messages ignored (malformed)"), 1,
3617 GNUNET_STATISTICS_update (GST_stats,
3619 ("# DISCONNECT messages received"),
3621 sdm = (const struct SessionDisconnectMessage *) msg;
3622 if (NULL == (n = lookup_neighbour (peer)))
3627 if (GNUNET_TIME_absolute_ntoh (sdm->timestamp).abs_value_us <= n->connect_ack_timestamp.abs_value_us)
3629 GNUNET_STATISTICS_update (GST_stats,
3630 gettext_noop ("# disconnect messages ignored (timestamp)"),
3635 if (0 != memcmp (peer,
3637 sizeof (struct GNUNET_PeerIdentity)))
3639 GNUNET_break_op (0);
3642 if (ntohl (sdm->purpose.size) !=
3643 sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
3644 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) +
3645 sizeof (struct GNUNET_TIME_AbsoluteNBO))
3647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3648 "DISCONNECT message from peer `%s' has invalid size\n",
3650 GNUNET_break_op (0);
3654 GNUNET_CRYPTO_eddsa_verify (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT,
3659 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3660 "DISCONNECT message from peer `%s' cannot be verified \n",
3662 GNUNET_break_op (0);
3665 n->delayed_disconnect_task = GNUNET_SCHEDULER_add_now (&delayed_disconnect, n);
3670 * Closure for the #neighbours_iterate() function.
3672 struct IteratorContext
3675 * Function to call on each connected neighbour.
3677 GST_NeighbourIterator cb;
3680 * Closure for @e cb.
3687 * Call the callback from the closure for each neighbour.
3689 * @param cls the `struct IteratorContext`
3690 * @param key the hash of the public key of the neighbour
3691 * @param value the `struct NeighbourMapEntry`
3692 * @return #GNUNET_OK (continue to iterate)
3695 neighbours_iterate (void *cls,
3696 const struct GNUNET_PeerIdentity *key,
3699 struct IteratorContext *ic = cls;
3700 struct NeighbourMapEntry *n = value;
3701 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
3702 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
3704 if (NULL != n->primary_address.address)
3706 bandwidth_in = n->primary_address.bandwidth_in;
3707 bandwidth_out = n->primary_address.bandwidth_out;
3711 bandwidth_in = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
3712 bandwidth_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
3716 n->primary_address.address,
3719 bandwidth_in, bandwidth_out);
3725 * Iterate over all connected neighbours.
3727 * @param cb function to call
3728 * @param cb_cls closure for cb
3731 GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls)
3733 struct IteratorContext ic;
3735 if (NULL == neighbours)
3736 return; /* can happen during shutdown */
3739 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
3740 &neighbours_iterate,
3746 * If we have an active connection to the given target, it must be shutdown.
3748 * @param target peer to disconnect from
3751 GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
3753 struct NeighbourMapEntry *n;
3755 if (NULL == (n = lookup_neighbour (target)))
3756 return; /* not active */
3757 if (GNUNET_YES == test_connected (n))
3758 GNUNET_STATISTICS_update (GST_stats,
3759 gettext_noop ("# disconnected from peer upon explicit request"),
3762 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3763 "Forced disconnect from peer %s\n",
3764 GNUNET_i2s (target));
3765 disconnect_neighbour (n);
3770 * Obtain current address information for the given neighbour.
3773 * @return address currently used
3775 struct GNUNET_HELLO_Address *
3776 GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer)
3778 struct NeighbourMapEntry *n;
3780 n = lookup_neighbour (peer);
3783 return n->primary_address.address;
3788 * Initialize the neighbours subsystem.
3790 * @param max_fds maximum number of fds to use
3793 GST_neighbours_start (unsigned int max_fds)
3795 neighbours = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE,
3797 util_transmission_tk = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL,
3798 &utilization_transmission,
3804 * Disconnect from the given neighbour.
3807 * @param key hash of neighbour's public key (not used)
3808 * @param value the 'struct NeighbourMapEntry' of the neighbour
3809 * @return #GNUNET_OK (continue to iterate)
3812 disconnect_all_neighbours (void *cls,
3813 const struct GNUNET_PeerIdentity *key,
3816 struct NeighbourMapEntry *n = value;
3818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3819 "Disconnecting peer `%4s' during shutdown\n",
3820 GNUNET_i2s (&n->id));
3827 * Cleanup the neighbours subsystem.
3830 GST_neighbours_stop ()
3832 struct BlacklistCheckSwitchContext *cur;
3833 struct BlacklistCheckSwitchContext *next;
3835 if (NULL == neighbours)
3837 if (NULL != util_transmission_tk)
3839 GNUNET_SCHEDULER_cancel (util_transmission_tk);
3840 util_transmission_tk = NULL;
3842 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
3843 &disconnect_all_neighbours,
3845 GNUNET_CONTAINER_multipeermap_destroy (neighbours);
3847 next = pending_bc_head;
3848 for (cur = next; NULL != cur; cur = next)
3851 GNUNET_CONTAINER_DLL_remove (pending_bc_head,
3855 if (NULL != cur->blc)
3857 GST_blacklist_test_cancel (cur->blc);
3865 /* end of file gnunet-service-transport_neighbours.c */