2 This file is part of GNUnet.
3 (C) 2010,2011 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_neighbours.h"
29 #include "gnunet-service-transport_plugins.h"
30 #include "gnunet-service-transport_validation.h"
31 #include "gnunet-service-transport.h"
32 #include "gnunet_peerinfo_service.h"
33 #include "gnunet_constants.h"
34 #include "transport.h"
38 * Size of the neighbour hash map.
40 #define NEIGHBOUR_TABLE_SIZE 256
43 * How often must a peer violate bandwidth quotas before we start
44 * to simply drop its messages?
46 #define QUOTA_VIOLATION_DROP_THRESHOLD 10
50 * Entry in neighbours.
52 struct NeighbourMapEntry;
56 * For each neighbour we keep a list of messages
57 * that we still want to transmit to the neighbour.
63 * This is a doubly linked list.
65 struct MessageQueue *next;
68 * This is a doubly linked list.
70 struct MessageQueue *prev;
73 * Once this message is actively being transmitted, which
74 * neighbour is it associated with?
76 struct NeighbourMapEntry *n;
79 * Function to call once we're done.
81 GST_NeighbourSendContinuation cont;
89 * The message(s) we want to transmit, GNUNET_MessageHeader(s)
90 * stuck together in memory. Allocated at the end of this struct.
92 const char *message_buf;
95 * Size of the message buf
97 size_t message_buf_size;
100 * At what time should we fail?
102 struct GNUNET_TIME_Absolute timeout;
108 * Entry in neighbours.
110 struct NeighbourMapEntry
114 * Head of list of messages we would like to send to this peer;
115 * must contain at most one message per client.
117 struct MessageQueue *messages_head;
120 * Tail of list of messages we would like to send to this peer; must
121 * contain at most one message per client.
123 struct MessageQueue *messages_tail;
126 * Context for address suggestion.
127 * NULL after we are connected.
129 struct GNUNET_ATS_SuggestionContext *asc;
132 * Performance data for the peer.
134 struct GNUNET_TRANSPORT_ATS_Information *ats;
137 * Are we currently trying to send a message? If so, which one?
139 struct MessageQueue *is_active;
142 * Active session for communicating with the peer.
144 struct Session *session;
147 * Name of the plugin we currently use.
152 * Address used for communicating with the peer, NULL for inbound connections.
157 * Number of bytes in 'addr'.
162 * Identity of this neighbour.
164 struct GNUNET_PeerIdentity id;
167 * ID of task scheduled to run when this peer is about to
168 * time out (will free resources associated with the peer).
170 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
173 * ID of task scheduled to run when we should try transmitting
174 * the head of the message queue.
176 GNUNET_SCHEDULER_TaskIdentifier transmission_task;
179 * Tracker for inbound bandwidth.
181 struct GNUNET_BANDWIDTH_Tracker in_tracker;
184 * How often has the other peer (recently) violated the inbound
185 * traffic limit? Incremented by 10 per violation, decremented by 1
186 * per non-violation (for each time interval).
188 unsigned int quota_violation_count;
191 * Number of values in 'ats' array.
193 unsigned int ats_count;
196 * Are we already in the process of disconnecting this neighbour?
201 * Do we currently consider this neighbour connected? (as far as
202 * the connect/disconnect callbacks are concerned)?
210 * All known neighbours and their HELLOs.
212 static struct GNUNET_CONTAINER_MultiHashMap *neighbours;
215 * Closure for connect_notify_cb and disconnect_notify_cb
217 static void *callback_cls;
220 * Function to call when we connected to a neighbour.
222 static GNUNET_TRANSPORT_NotifyConnect connect_notify_cb;
225 * Function to call when we disconnected from a neighbour.
227 static GNUNET_TRANSPORT_NotifyDisconnect disconnect_notify_cb;
231 * Lookup a neighbour entry in the neighbours hash map.
233 * @param pid identity of the peer to look up
234 * @return the entry, NULL if there is no existing record
236 static struct NeighbourMapEntry *
237 lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
239 return GNUNET_CONTAINER_multihashmap_get (neighbours, &pid->hashPubKey);
244 * Task invoked to start a transmission to another peer.
246 * @param cls the 'struct NeighbourMapEntry'
247 * @param tc scheduler context
250 transmission_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
254 * We're done with our transmission attempt, continue processing.
256 * @param cls the 'struct MessageQueue' of the message
257 * @param receiver intended receiver
258 * @param success whether it worked or not
261 transmit_send_continuation (void *cls,
262 const struct GNUNET_PeerIdentity *receiver,
265 struct MessageQueue *mq;
266 struct NeighbourMapEntry *n;
272 GNUNET_assert (n->is_active == mq);
274 GNUNET_assert (n->transmission_task == GNUNET_SCHEDULER_NO_TASK);
275 n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task, n);
277 if (NULL != mq->cont)
278 mq->cont (mq->cont_cls, success);
284 * Check the ready list for the given neighbour and if a plugin is
285 * ready for transmission (and if we have a message), do so!
287 * @param neighbour target peer for which to transmit
290 try_transmission_to_peer (struct NeighbourMapEntry *n)
292 struct MessageQueue *mq;
293 struct GNUNET_TIME_Relative timeout;
295 struct GNUNET_TRANSPORT_PluginFunctions *papi;
297 if (n->is_active != NULL)
298 return; /* transmission already pending */
299 if (n->transmission_task != GNUNET_SCHEDULER_NO_TASK)
300 return; /* currently waiting for bandwidth */
301 mq = n->messages_head;
302 while (NULL != (mq = n->messages_head))
304 timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout);
305 if (timeout.rel_value > 0)
307 transmit_send_continuation (mq, &n->id, GNUNET_SYSERR); /* timeout */
310 return; /* no more messages */
312 papi = GST_plugins_find (n->plugin_name);
318 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
324 papi->send (papi->cls, &n->id, mq->message_buf, mq->message_buf_size,
325 0 /* priority -- remove from plugin API? */ ,
326 timeout, n->session, n->addr, n->addrlen, GNUNET_YES,
327 &transmit_send_continuation, mq);
330 /* failure, but 'send' would not call continuation in this case,
331 * so we need to do it here! */
332 transmit_send_continuation (mq, &n->id, GNUNET_SYSERR);
333 n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task, n);
339 * Task invoked to start a transmission to another peer.
341 * @param cls the 'struct NeighbourMapEntry'
342 * @param tc scheduler context
345 transmission_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
347 struct NeighbourMapEntry *n = cls;
349 n->transmission_task = GNUNET_SCHEDULER_NO_TASK;
350 try_transmission_to_peer (n);
355 * Initialize the neighbours subsystem.
357 * @param cls closure for callbacks
358 * @param connect_cb function to call if we connect to a peer
359 * @param disconnect_cb function to call if we disconnect from a peer
362 GST_neighbours_start (void *cls, GNUNET_TRANSPORT_NotifyConnect connect_cb,
363 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb)
366 connect_notify_cb = connect_cb;
367 disconnect_notify_cb = disconnect_cb;
368 neighbours = GNUNET_CONTAINER_multihashmap_create (NEIGHBOUR_TABLE_SIZE);
373 * Disconnect from the given neighbour, clean up the record.
375 * @param n neighbour to disconnect from
378 disconnect_neighbour (struct NeighbourMapEntry *n)
380 struct MessageQueue *mq;
382 if (GNUNET_YES == n->in_disconnect)
384 n->in_disconnect = GNUNET_YES;
385 while (NULL != (mq = n->messages_head))
387 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
388 mq->cont (mq->cont_cls, GNUNET_SYSERR);
391 if (NULL != n->is_active)
393 n->is_active->n = NULL;
396 if (GNUNET_YES == n->is_connected)
398 n->is_connected = GNUNET_NO;
399 disconnect_notify_cb (callback_cls, &n->id);
401 GNUNET_assert (GNUNET_YES ==
402 GNUNET_CONTAINER_multihashmap_remove (neighbours,
403 &n->id.hashPubKey, n));
404 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
406 GNUNET_SCHEDULER_cancel (n->timeout_task);
407 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
409 if (GNUNET_SCHEDULER_NO_TASK != n->transmission_task)
411 GNUNET_SCHEDULER_cancel (n->timeout_task);
412 n->transmission_task = GNUNET_SCHEDULER_NO_TASK;
416 GNUNET_ATS_suggest_address_cancel (n->asc);
419 GNUNET_array_grow (n->ats, n->ats_count, 0);
420 if (NULL != n->plugin_name)
422 GNUNET_free (n->plugin_name);
423 n->plugin_name = NULL;
427 GNUNET_free (n->addr);
437 * Peer has been idle for too long. Disconnect.
439 * @param cls the 'struct NeighbourMapEntry' of the neighbour that went idle
440 * @param tc scheduler context
443 neighbour_timeout_task (void *cls,
444 const struct GNUNET_SCHEDULER_TaskContext *tc)
446 struct NeighbourMapEntry *n = cls;
448 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
449 disconnect_neighbour (n);
454 * Disconnect from the given neighbour.
457 * @param key hash of neighbour's public key (not used)
458 * @param value the 'struct NeighbourMapEntry' of the neighbour
461 disconnect_all_neighbours (void *cls, const GNUNET_HashCode * key, void *value)
463 struct NeighbourMapEntry *n = value;
466 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n",
467 GNUNET_i2s (&n->id), "SHUTDOWN_TASK");
469 disconnect_neighbour (n);
475 * Cleanup the neighbours subsystem.
478 GST_neighbours_stop ()
480 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &disconnect_all_neighbours,
482 GNUNET_CONTAINER_multihashmap_destroy (neighbours);
485 connect_notify_cb = NULL;
486 disconnect_notify_cb = NULL;
491 * For an existing neighbour record, set the active connection to
494 * @param peer identity of the peer to switch the address for
495 * @param plugin_name name of transport that delivered the PONG
496 * @param address address of the other peer, NULL if other peer
498 * @param address_len number of bytes in address
499 * @param session session to use (or NULL)
500 * @param ats performance data
501 * @param ats_count number of entries in ats (excluding 0-termination)
504 GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
505 const char *plugin_name, const void *address,
506 size_t address_len, struct Session *session,
507 const struct GNUNET_TRANSPORT_ATS_Information
508 *ats, uint32_t ats_count)
510 struct NeighbourMapEntry *n;
511 struct GNUNET_MessageHeader connect_msg;
513 n = lookup_neighbour (peer);
521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
522 "SWITCH! Peer `%4s' switches to plugin `%s' address '%s' session %X\n",
523 GNUNET_i2s (peer), plugin_name,
524 (address_len == 0) ? "<inbound>" : GST_plugins_a2s (plugin_name,
530 GNUNET_free_non_null (n->addr);
531 n->addr = GNUNET_malloc (address_len);
532 memcpy (n->addr, address, address_len);
533 n->addrlen = address_len;
534 n->session = session;
535 GNUNET_array_grow (n->ats, n->ats_count, ats_count);
537 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
538 GNUNET_free_non_null (n->plugin_name);
539 n->plugin_name = GNUNET_strdup (plugin_name);
540 GNUNET_SCHEDULER_cancel (n->timeout_task);
542 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
543 &neighbour_timeout_task, n);
544 connect_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
545 connect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT);
546 GST_neighbours_send (peer, &connect_msg, sizeof (connect_msg),
547 GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL);
552 * Try to connect to the target peer using the given address
554 * @param cls the 'struct NeighbourMapEntry' of the target
555 * @param target identity of the target peer
556 * @param plugin_name name of the plugin
557 * @param plugin_address binary address
558 * @param plugin_address_len length of address
559 * @param bandwidth available bandwidth
560 * @param ats performance data for the address (as far as known)
561 * @param ats_count number of performance records in 'ats'
564 try_connect_using_address (void *cls, const struct GNUNET_PeerIdentity *target,
565 const char *plugin_name, const void *plugin_address,
566 size_t plugin_address_len, struct Session *session,
567 struct GNUNET_BANDWIDTH_Value32NBO bandwidth,
568 const struct GNUNET_TRANSPORT_ATS_Information *ats,
571 struct NeighbourMapEntry *n = cls;
575 was_connected = n->is_connected;
576 n->is_connected = GNUNET_YES;
577 GST_neighbours_switch_to_address (target, plugin_name, plugin_address,
578 plugin_address_len, session, ats,
580 if (GNUNET_YES == was_connected)
582 connect_notify_cb (callback_cls, target, n->ats, n->ats_count);
587 * Try to create a connection to the given target (eventually).
589 * @param target peer to try to connect to
592 GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
594 struct NeighbourMapEntry *n;
597 memcmp (target, &GST_my_identity,
598 sizeof (struct GNUNET_PeerIdentity)));
599 n = lookup_neighbour (target);
600 if ((NULL != n) && (GNUNET_YES == n->is_connected))
601 return; /* already connected */
604 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry));
606 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
607 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
608 MAX_BANDWIDTH_CARRY_S);
610 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
611 &neighbour_timeout_task, n);
612 GNUNET_assert (GNUNET_OK ==
613 GNUNET_CONTAINER_multihashmap_put (neighbours,
614 &n->id.hashPubKey, n,
615 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
618 return; /* already trying */
620 GNUNET_ATS_suggest_address (GST_ats, target, &try_connect_using_address,
626 * Test if we're connected to the given peer.
628 * @param target peer to test
629 * @return GNUNET_YES if we are connected, GNUNET_NO if not
632 GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target)
634 struct NeighbourMapEntry *n;
636 n = lookup_neighbour (target);
637 if ((NULL == n) || (n->is_connected != GNUNET_YES))
638 return GNUNET_NO; /* not connected */
644 * A session was terminated. Take note.
646 * @param peer identity of the peer where the session died
647 * @param session session that is gone
650 GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
651 struct Session *session)
653 struct NeighbourMapEntry *n;
655 n = lookup_neighbour (peer);
658 if (session != n->session)
659 return; /* doesn't affect us */
661 if (GNUNET_YES != n->is_connected)
662 return; /* not connected anymore anyway, shouldn't matter */
664 GNUNET_SCHEDULER_cancel (n->timeout_task);
666 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
667 &neighbour_timeout_task, n);
668 /* try QUICKLY to re-establish a connection, reduce timeout! */
671 /* how can this be!? */
676 GNUNET_ATS_suggest_address (GST_ats, peer, &try_connect_using_address, n);
681 * Transmit a message to the given target using the active connection.
683 * @param target destination
684 * @param msg message to send
685 * @param msg_size number of bytes in msg
686 * @param timeout when to fail with timeout
687 * @param cont function to call when done
688 * @param cont_cls closure for 'cont'
691 GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
692 size_t msg_size, struct GNUNET_TIME_Relative timeout,
693 GST_NeighbourSendContinuation cont, void *cont_cls)
695 struct NeighbourMapEntry *n;
696 struct MessageQueue *mq;
698 n = lookup_neighbour (target);
699 if ((n == NULL) || (GNUNET_YES != n->is_connected))
701 GNUNET_STATISTICS_update (GST_stats,
703 ("# messages not sent (no such peer or not connected)"),
707 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
708 "Could not send message to peer `%s': unknown neighbor",
709 GNUNET_i2s (target));
710 if (GNUNET_YES != n->is_connected)
711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
712 "Could not send message to peer `%s': not connected\n",
713 GNUNET_i2s (target));
716 cont (cont_cls, GNUNET_SYSERR);
719 GNUNET_assert (msg_size >= sizeof (struct GNUNET_MessageHeader));
720 GNUNET_STATISTICS_update (GST_stats,
722 ("# bytes in message queue for other peers"),
723 msg_size, GNUNET_NO);
724 mq = GNUNET_malloc (sizeof (struct MessageQueue) + msg_size);
726 mq->cont_cls = cont_cls;
727 /* FIXME: this memcpy can be up to 7% of our total runtime! */
728 memcpy (&mq[1], msg, msg_size);
729 mq->message_buf = (const char *) &mq[1];
730 mq->message_buf_size = msg_size;
731 mq->timeout = GNUNET_TIME_relative_to_absolute (timeout);
732 GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, n->messages_tail, mq);
733 if ((GNUNET_SCHEDULER_NO_TASK == n->transmission_task) &&
734 (NULL == n->is_active))
735 n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task, n);
740 * We have received a message from the given sender. How long should
741 * we delay before receiving more? (Also used to keep the peer marked
744 * @param sender sender of the message
745 * @param size size of the message
746 * @param do_forward set to GNUNET_YES if the message should be forwarded to clients
747 * GNUNET_NO if the neighbour is not connected or violates the quota
748 * @return how long to wait before reading more from this sender
750 struct GNUNET_TIME_Relative
751 GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity
752 *sender, ssize_t size, int *do_forward)
754 struct NeighbourMapEntry *n;
755 struct GNUNET_TIME_Relative ret;
757 n = lookup_neighbour (sender);
760 *do_forward = GNUNET_NO;
761 return GNUNET_TIME_UNIT_ZERO;
763 if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, size))
765 n->quota_violation_count++;
767 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
768 "Bandwidth quota (%u b/s) violation detected (total of %u).\n",
769 n->in_tracker.available_bytes_per_s__,
770 n->quota_violation_count);
772 /* Discount 32k per violation */
773 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, -32 * 1024);
777 if (n->quota_violation_count > 0)
779 /* try to add 32k back */
780 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, 32 * 1024);
781 n->quota_violation_count--;
784 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
786 GNUNET_STATISTICS_update (GST_stats,
788 ("# bandwidth quota violations by other peers"),
790 *do_forward = GNUNET_NO;
791 return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT;
793 *do_forward = GNUNET_YES;
794 ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 0);
795 if (ret.rel_value > 0)
798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
799 "Throttling read (%llu bytes excess at %u b/s), waiting %llu ms before reading more.\n",
800 (unsigned long long) n->in_tracker.
801 consumption_since_last_update__,
802 (unsigned int) n->in_tracker.available_bytes_per_s__,
803 (unsigned long long) ret.rel_value);
805 GNUNET_STATISTICS_update (GST_stats,
806 gettext_noop ("# ms throttling suggested"),
807 (int64_t) ret.rel_value, GNUNET_NO);
814 * Keep the connection to the given neighbour alive longer,
815 * we received a KEEPALIVE (or equivalent).
817 * @param neighbour neighbour to keep alive
820 GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour)
822 struct NeighbourMapEntry *n;
824 n = lookup_neighbour (neighbour);
827 GNUNET_STATISTICS_update (GST_stats,
829 ("# KEEPALIVE messages discarded (not connected)"),
833 GNUNET_SCHEDULER_cancel (n->timeout_task);
835 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
836 &neighbour_timeout_task, n);
841 * Change the incoming quota for the given peer.
843 * @param neighbour identity of peer to change qutoa for
844 * @param quota new quota
847 GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
848 struct GNUNET_BANDWIDTH_Value32NBO quota)
850 struct NeighbourMapEntry *n;
852 n = lookup_neighbour (neighbour);
855 GNUNET_STATISTICS_update (GST_stats,
857 ("# SET QUOTA messages ignored (no such peer)"),
861 GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker, quota);
862 if (0 != ntohl (quota.value__))
865 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s' due to `%s'\n",
866 GNUNET_i2s (&n->id), "SET_QUOTA");
868 GNUNET_STATISTICS_update (GST_stats,
869 gettext_noop ("# disconnects due to quota of 0"), 1,
871 disconnect_neighbour (n);
876 * Closure for the neighbours_iterate function.
878 struct IteratorContext
881 * Function to call on each connected neighbour.
883 GST_NeighbourIterator cb;
893 * Call the callback from the closure for each connected neighbour.
895 * @param cls the 'struct IteratorContext'
896 * @param key the hash of the public key of the neighbour
897 * @param value the 'struct NeighbourMapEntry'
898 * @return GNUNET_OK (continue to iterate)
901 neighbours_iterate (void *cls, const GNUNET_HashCode * key, void *value)
903 struct IteratorContext *ic = cls;
904 struct NeighbourMapEntry *n = value;
906 if (GNUNET_YES != n->is_connected)
908 GNUNET_assert (n->ats_count > 0);
909 ic->cb (ic->cb_cls, &n->id, n->ats, n->ats_count - 1);
915 * Iterate over all connected neighbours.
917 * @param cb function to call
918 * @param cb_cls closure for cb
921 GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls)
923 struct IteratorContext ic;
927 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &neighbours_iterate, &ic);
932 * If we have an active connection to the given target, it must be shutdown.
934 * @param target peer to disconnect from
937 GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
939 struct NeighbourMapEntry *n;
940 struct GNUNET_TRANSPORT_PluginFunctions *papi;
941 struct GNUNET_MessageHeader disconnect_msg;
943 n = lookup_neighbour (target);
945 return; /* not active */
946 if (GNUNET_YES == n->is_connected)
948 /* we're actually connected, send DISCONNECT message */
949 disconnect_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
950 disconnect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
951 papi = GST_plugins_find (n->plugin_name);
953 papi->send (papi->cls, target, (const void *) &disconnect_msg,
954 sizeof (struct GNUNET_MessageHeader),
955 UINT32_MAX /* priority */ ,
956 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->addr, n->addrlen,
957 GNUNET_YES, NULL, NULL);
959 disconnect_neighbour (n);
963 /* end of file gnunet-service-transport_neighbours.c */