2 This file is part of GNUnet.
3 Copyright (C) 2010-2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @file transport/gnunet-service-transport.c
20 * @brief main for gnunet-service-transport
21 * @author Christian Grothoff
24 #include "gnunet_util_lib.h"
25 #include "gnunet_hello_lib.h"
26 #include "gnunet_statistics_service.h"
27 #include "gnunet_transport_service.h"
28 #include "gnunet_peerinfo_service.h"
29 #include "gnunet_ats_service.h"
30 #include "gnunet-service-transport.h"
31 #include "gnunet-service-transport_ats.h"
32 #include "gnunet-service-transport_hello.h"
33 #include "gnunet-service-transport_neighbours.h"
34 #include "gnunet-service-transport_plugins.h"
35 #include "gnunet-service-transport_validation.h"
36 #include "gnunet-service-transport_manipulation.h"
37 #include "transport.h"
40 * Size of the blacklist hash map.
42 #define TRANSPORT_BLACKLIST_HT_SIZE 64
45 * How many messages can we have pending for a given client process
46 * before we start to drop incoming messages? We typically should
47 * have only one client and so this would be the primary buffer for
48 * messages, so the number should be chosen rather generously.
50 * The expectation here is that most of the time the queue is large
51 * enough so that a drop is virtually never required. Note that
52 * this value must be about as large as 'TOTAL_MSGS' in the
53 * 'test_transport_api_reliability.c', otherwise that testcase may
56 #define MAX_PENDING (128 * 1024)
60 * Information we need for an asynchronous session kill.
62 struct GNUNET_ATS_SessionKiller
67 struct GNUNET_ATS_SessionKiller *next;
72 struct GNUNET_ATS_SessionKiller *prev;
77 struct GNUNET_ATS_Session *session;
80 * Plugin for the session.
82 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
87 struct GNUNET_SCHEDULER_Task *task;
92 * What type of client is the `struct TransportClient` about?
97 * We do not know yet (client is fresh).
102 * Is the CORE service, we need to forward traffic to it.
107 * It is a monitor, forward monitor data.
112 * It is a blacklist, query about allowed connections.
119 * Context we use when performing a blacklist check.
121 struct GST_BlacklistCheck;
124 * Client connected to the transport service.
126 struct TransportClient
130 * This is a doubly-linked list.
132 struct TransportClient *next;
135 * This is a doubly-linked list.
137 struct TransportClient *prev;
140 * Handle to the client.
142 struct GNUNET_SERVICE_Client *client;
145 * Message queue to the client.
147 struct GNUNET_MQ_Handle *mq;
150 * What type of client is this?
152 enum ClientType type;
157 * Peer identity to monitor the addresses of.
158 * Zero to monitor all neighbours. Valid if
159 * @e type is CT_MONITOR.
161 struct GNUNET_PeerIdentity monitor_peer;
164 * Additional details if @e type is CT_BLACKLIST.
169 * Blacklist check that we're currently performing (or NULL
170 * if we're performing one that has been cancelled).
172 struct GST_BlacklistCheck *bc;
175 * Set to #GNUNET_YES if we're currently waiting for a reply.
177 int waiting_for_reply;
180 * #GNUNET_YES if we have to call receive_done for this client
182 int call_receive_done;
193 * Context we use when performing a blacklist check.
195 struct GST_BlacklistCheck
199 * This is a linked list.
201 struct GST_BlacklistCheck *next;
204 * This is a linked list.
206 struct GST_BlacklistCheck *prev;
209 * Peer being checked.
211 struct GNUNET_PeerIdentity peer;
214 * Continuation to call with the result.
216 GST_BlacklistTestContinuation cont;
219 * Closure for @e cont.
224 * Address for #GST_blacklist_abort_matching(), can be NULL.
226 struct GNUNET_HELLO_Address *address;
229 * Session for #GST_blacklist_abort_matching(), can be NULL.
231 struct GNUNET_ATS_Session *session;
234 * Our current position in the blacklisters list.
236 struct TransportClient *bl_pos;
239 * Current task performing the check.
241 struct GNUNET_SCHEDULER_Task *task;
247 * Context for address to string operations
249 struct AddressToStringContext
252 * This is a doubly-linked list.
254 struct AddressToStringContext *next;
257 * This is a doubly-linked list.
259 struct AddressToStringContext *prev;
262 * Client that made the request.
264 struct TransportClient* tc;
269 * Closure for #handle_send_transmit_continuation()
271 struct SendTransmitContinuationContext
275 * Client that made the request.
277 struct TransportClient *tc;
280 * Peer that was the target.
282 struct GNUNET_PeerIdentity target;
285 * At what time did we receive the message?
287 struct GNUNET_TIME_Absolute send_time;
290 * Unique ID, for logging.
292 unsigned long long uuid;
295 * Set to #GNUNET_YES if the connection for @e target goes
296 * down and we thus must no longer send the
297 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK message.
304 * Head of linked list of all clients to this service.
306 static struct TransportClient *clients_head;
309 * Tail of linked list of all clients to this service.
311 static struct TransportClient *clients_tail;
314 * Map of peer identities to active send transmit continuation
315 * contexts. Used to flag contexts as 'dead' when a connection goes
316 * down. Values are of type `struct SendTransmitContinuationContext
319 static struct GNUNET_CONTAINER_MultiPeerMap *active_stccs;
322 * Head of linked list of all pending address iterations
324 static struct AddressToStringContext *a2s_head;
327 * Tail of linked list of all pending address iterations
329 static struct AddressToStringContext *a2s_tail;
332 * Head of DLL of active blacklisting queries.
334 static struct GST_BlacklistCheck *bc_head;
337 * Tail of DLL of active blacklisting queries.
339 static struct GST_BlacklistCheck *bc_tail;
342 * Hashmap of blacklisted peers. Values are of type 'char *' (transport names),
343 * can be NULL if we have no static blacklist.
345 static struct GNUNET_CONTAINER_MultiPeerMap *blacklist;
348 * Notification context, to send updates on changes to active plugin
351 static struct GNUNET_NotificationContext *plugin_nc;
354 * Plugin monitoring client we are currently syncing, NULL if all
355 * monitoring clients are in sync.
357 static struct TransportClient *sync_client;
360 * Peer identity that is all zeros, used as a way to indicate
361 * "all peers". Used for comparissons.
363 static struct GNUNET_PeerIdentity all_zeros;
368 struct GNUNET_STATISTICS_Handle *GST_stats;
371 * Configuration handle.
373 const struct GNUNET_CONFIGURATION_Handle *GST_cfg;
376 * Configuration handle.
378 struct GNUNET_PeerIdentity GST_my_identity;
381 * Handle to peerinfo service.
383 struct GNUNET_PEERINFO_Handle *GST_peerinfo;
388 struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key;
391 * ATS scheduling handle.
393 struct GNUNET_ATS_SchedulingHandle *GST_ats;
396 * ATS connectivity handle.
398 struct GNUNET_ATS_ConnectivityHandle *GST_ats_connect;
401 * Hello address expiration
403 struct GNUNET_TIME_Relative hello_expiration;
406 * Head of DLL of asynchronous tasks to kill sessions.
408 static struct GNUNET_ATS_SessionKiller *sk_head;
411 * Tail of DLL of asynchronous tasks to kill sessions.
413 static struct GNUNET_ATS_SessionKiller *sk_tail;
416 * Interface scanner determines our LAN address range(s).
418 struct GNUNET_NT_InterfaceScanner *GST_is;
422 * Queue the given message for transmission to the given client
424 * @param tc target of the message
425 * @param msg message to transmit
426 * @param may_drop #GNUNET_YES if the message can be dropped
429 unicast (struct TransportClient *tc,
430 const struct GNUNET_MessageHeader *msg,
433 struct GNUNET_MQ_Envelope *env;
435 if ( (GNUNET_MQ_get_length (tc->mq) >= MAX_PENDING) &&
436 (GNUNET_YES == may_drop) )
438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
439 "Dropping message of type %u and size %u, have %u/%u messages pending\n",
442 GNUNET_MQ_get_length (tc->mq),
444 GNUNET_STATISTICS_update (GST_stats,
446 ("# messages dropped due to slow client"), 1,
450 env = GNUNET_MQ_msg_copy (msg);
451 GNUNET_MQ_send (tc->mq,
457 * Called whenever a client connects. Allocates our
458 * data structures associated with that client.
460 * @param cls closure, NULL
461 * @param client identification of the client
462 * @param mq message queue for the client
463 * @return our `struct TransportClient`
466 client_connect_cb (void *cls,
467 struct GNUNET_SERVICE_Client *client,
468 struct GNUNET_MQ_Handle *mq)
470 struct TransportClient *tc;
472 tc = GNUNET_new (struct TransportClient);
475 GNUNET_CONTAINER_DLL_insert (clients_head,
478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
479 "Client %p connected\n",
486 * Perform next action in the blacklist check.
488 * @param cls the `struct BlacklistCheck*`
491 do_blacklist_check (void *cls);
495 * Mark the peer as down so we don't call the continuation
496 * context in the future.
498 * @param cls a `struct TransportClient`
499 * @param peer a peer we are sending to
500 * @param value a `struct SendTransmitContinuationContext` to mark
501 * @return #GNUNET_OK (continue to iterate)
504 mark_match_down (void *cls,
505 const struct GNUNET_PeerIdentity *peer,
508 struct TransportClient *tc = cls;
509 struct SendTransmitContinuationContext *stcc = value;
513 stcc->down = GNUNET_YES;
521 * Called whenever a client is disconnected. Frees our
522 * resources associated with that client.
524 * @param cls closure, NULL
525 * @param client identification of the client
526 * @param app_ctx our `struct TransportClient`
529 client_disconnect_cb (void *cls,
530 struct GNUNET_SERVICE_Client *client,
533 struct TransportClient *tc = app_ctx;
534 struct GST_BlacklistCheck *bc;
536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
537 "Client %p disconnected, cleaning up.\n",
539 GNUNET_CONTAINER_multipeermap_iterate (active_stccs,
542 for (struct AddressToStringContext *cur = a2s_head;
549 GNUNET_CONTAINER_DLL_remove (clients_head,
561 for (bc = bc_head; NULL != bc; bc = bc->next)
563 if (bc->bl_pos != tc)
565 bc->bl_pos = tc->next;
566 if (NULL == bc->task)
567 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
577 * Function called for each of our connected neighbours. Notify the
578 * client about the existing neighbour.
580 * @param cls the `struct TransportClient *` to notify
581 * @param peer identity of the neighbour
582 * @param address the address
583 * @param state the current state of the peer
584 * @param state_timeout the time out for the state
585 * @param bandwidth_in inbound bandwidth in NBO
586 * @param bandwidth_out outbound bandwidth in NBO
589 notify_client_about_neighbour (void *cls,
590 const struct GNUNET_PeerIdentity *peer,
591 const struct GNUNET_HELLO_Address *address,
592 enum GNUNET_TRANSPORT_PeerState state,
593 struct GNUNET_TIME_Absolute state_timeout,
594 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
595 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
597 struct TransportClient *tc = cls;
598 struct ConnectInfoMessage cim;
600 if (GNUNET_NO == GST_neighbours_test_connected (peer))
602 cim.header.size = htons (sizeof (struct ConnectInfoMessage));
603 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
605 cim.quota_out = bandwidth_out;
613 * Initialize a normal client. We got a start message from this
614 * client, add it to the list of clients for broadcasting of inbound
617 * @param cls the client
618 * @param start the start message that was sent
621 handle_client_start (void *cls,
622 const struct StartMessage *start)
624 struct TransportClient *tc = cls;
625 const struct GNUNET_MessageHeader *hello;
628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
629 "Client %p sent START\n",
631 options = ntohl (start->options);
632 if ((0 != (1 & options)) &&
634 memcmp (&start->self,
636 sizeof (struct GNUNET_PeerIdentity))))
638 /* client thinks this is a different peer, reject */
640 GNUNET_SERVICE_client_drop (tc->client);
643 if (CT_NONE != tc->type)
646 GNUNET_SERVICE_client_drop (tc->client);
649 if (0 != (2 & options))
651 hello = GST_hello_get ();
656 GST_neighbours_iterate (¬ify_client_about_neighbour,
658 GNUNET_SERVICE_client_continue (tc->client);
663 * Client sent us a HELLO. Check the request.
665 * @param cls the client
666 * @param message the HELLO message
669 check_client_hello (void *cls,
670 const struct GNUNET_MessageHeader *message)
672 return GNUNET_OK; /* FIXME: check here? */
677 * Client sent us a HELLO. Process the request.
679 * @param cls the client
680 * @param message the HELLO message
683 handle_client_hello (void *cls,
684 const struct GNUNET_MessageHeader *message)
686 struct TransportClient *tc = cls;
688 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
689 "Received HELLO message\n");
690 GST_validation_handle_hello (message);
691 GNUNET_SERVICE_client_continue (tc->client);
696 * Function called after the transmission is done. Notify the client that it is
697 * OK to send the next message.
700 * @param success #GNUNET_OK on success, #GNUNET_NO on failure, #GNUNET_SYSERR if we're not connected
701 * @param bytes_payload bytes payload sent
702 * @param bytes_on_wire bytes sent on wire
705 handle_send_transmit_continuation (void *cls,
707 size_t bytes_payload,
708 size_t bytes_on_wire)
710 struct SendTransmitContinuationContext *stcc = cls;
711 struct SendOkMessage send_ok_msg;
712 struct GNUNET_TIME_Relative delay;
713 const struct GNUNET_HELLO_Address *addr;
715 delay = GNUNET_TIME_absolute_get_duration (stcc->send_time);
716 addr = GST_neighbour_get_current_address (&stcc->target);
717 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
718 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
719 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
720 GNUNET_STRINGS_relative_time_to_string (delay,
722 (unsigned int) bytes_payload,
723 (unsigned int) bytes_on_wire,
724 GNUNET_i2s (&stcc->target),
726 (NULL != addr) ? addr->transport_name : "%");
728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
729 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
730 GNUNET_STRINGS_relative_time_to_string (delay,
732 (unsigned int) bytes_payload,
733 (unsigned int) bytes_on_wire,
734 GNUNET_i2s (&stcc->target),
736 (NULL != addr) ? addr->transport_name : "%");
738 if (GNUNET_NO == stcc->down)
740 /* Only send confirmation if we are still connected */
741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
742 "Sending SEND_OK for transmission request %llu\n",
744 send_ok_msg.header.size = htons (sizeof (send_ok_msg));
745 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
746 send_ok_msg.bytes_msg = htonl (bytes_payload);
747 send_ok_msg.bytes_physical = htonl (bytes_on_wire);
748 send_ok_msg.success = htonl (success);
749 send_ok_msg.peer = stcc->target;
754 GNUNET_assert (GNUNET_OK ==
755 GNUNET_CONTAINER_multipeermap_remove (active_stccs,
763 * Client asked for transmission to a peer. Process the request.
765 * @param cls the client
766 * @param obm the send message that was sent
769 check_client_send (void *cls,
770 const struct OutboundMessage *obm)
773 const struct GNUNET_MessageHeader *obmm;
775 size = ntohs (obm->header.size) - sizeof (struct OutboundMessage);
776 if (size < sizeof (struct GNUNET_MessageHeader))
779 return GNUNET_SYSERR;
781 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
782 if (size != ntohs (obmm->size))
785 return GNUNET_SYSERR;
792 * Client asked for transmission to a peer. Process the request.
794 * @param cls the client
795 * @param obm the send message that was sent
798 handle_client_send (void *cls,
799 const struct OutboundMessage *obm)
801 static unsigned long long uuid_gen;
802 struct TransportClient *tc = cls;
803 const struct GNUNET_MessageHeader *obmm;
804 struct SendTransmitContinuationContext *stcc;
806 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
807 if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer))
809 /* not connected, not allowed to send; can happen due to asynchronous operations */
810 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
811 "Could not send message to peer `%s': not connected\n",
812 GNUNET_i2s (&obm->peer));
813 GNUNET_STATISTICS_update (GST_stats,
815 ("# bytes payload dropped (other peer was not connected)"),
818 GNUNET_SERVICE_client_continue (tc->client);
821 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
822 "Received SEND request %llu for `%s' and first message of type %u and total size %u\n",
824 GNUNET_i2s (&obm->peer),
827 GNUNET_SERVICE_client_continue (tc->client);
829 stcc = GNUNET_new (struct SendTransmitContinuationContext);
830 stcc->target = obm->peer;
832 stcc->send_time = GNUNET_TIME_absolute_get ();
833 stcc->uuid = uuid_gen++;
834 (void) GNUNET_CONTAINER_multipeermap_put (active_stccs,
837 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
838 GST_manipulation_send (&obm->peer,
841 GNUNET_TIME_relative_ntoh (obm->timeout),
842 &handle_send_transmit_continuation,
848 * Take the given address and append it to the set of results sent back to
849 * the client. This function may be called serveral times for a single
850 * conversion. The last invocation will be with a @a address of
851 * NULL and a @a res of #GNUNET_OK. Thus, to indicate conversion
852 * errors, the callback might be called first with @a address NULL and
853 * @a res being #GNUNET_SYSERR. In that case, there will still be a
854 * subsequent call later with @a address NULL and @a res #GNUNET_OK.
856 * @param cls the `struct AddressToStringContext`
857 * @param buf text to transmit (contains the human-readable address, or NULL)
858 * @param res #GNUNET_OK if conversion was successful, #GNUNET_SYSERR on error,
862 transmit_address_to_client (void *cls,
866 struct AddressToStringContext *actx = cls;
867 struct GNUNET_MQ_Envelope *env;
868 struct AddressToStringResultMessage *atsm;
871 GNUNET_assert ( (GNUNET_OK == res) ||
872 (GNUNET_SYSERR == res) );
873 if (NULL == actx->tc)
877 env = GNUNET_MQ_msg (atsm,
878 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
879 if (GNUNET_OK == res)
881 /* this was the last call, transmit */
882 atsm->res = htonl (GNUNET_OK);
883 atsm->addr_len = htonl (0);
884 GNUNET_MQ_send (actx->tc->mq,
886 GNUNET_CONTAINER_DLL_remove (a2s_head,
892 if (GNUNET_SYSERR == res)
894 /* address conversion failed, but there will be more callbacks */
895 atsm->res = htonl (GNUNET_SYSERR);
896 atsm->addr_len = htonl (0);
897 GNUNET_MQ_send (actx->tc->mq,
902 GNUNET_assert (GNUNET_OK == res);
903 /* succesful conversion, append*/
904 slen = strlen (buf) + 1;
905 env = GNUNET_MQ_msg_extra (atsm,
907 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
908 atsm->res = htonl (GNUNET_YES);
909 atsm->addr_len = htonl (slen);
910 GNUNET_memcpy (&atsm[1],
913 GNUNET_MQ_send (actx->tc->mq,
919 * Client asked to resolve an address. Check the request.
921 * @param cls the client
922 * @param alum the resolution request
923 * @return #GNUNET_OK if @a alum is well-formed
926 check_client_address_to_string (void *cls,
927 const struct AddressLookupMessage *alum)
929 const char *plugin_name;
931 uint32_t address_len;
934 size = ntohs (alum->header.size);
935 address_len = ntohs (alum->addrlen);
936 if (size <= sizeof (struct AddressLookupMessage) + address_len)
939 return GNUNET_SYSERR;
941 address = (const char *) &alum[1];
942 plugin_name = (const char *) &address[address_len];
943 if ('\0' != plugin_name[size - sizeof (struct AddressLookupMessage) - address_len - 1])
946 return GNUNET_SYSERR;
953 * Client asked to resolve an address. Process the request.
955 * @param cls the client
956 * @param alum the resolution request
959 handle_client_address_to_string (void *cls,
960 const struct AddressLookupMessage *alum)
962 struct TransportClient *tc = cls;
963 struct GNUNET_TRANSPORT_PluginFunctions *papi;
964 const char *plugin_name;
966 uint32_t address_len;
967 struct AddressToStringContext *actx;
968 struct GNUNET_MQ_Envelope *env;
969 struct AddressToStringResultMessage *atsm;
970 struct GNUNET_TIME_Relative rtimeout;
973 address_len = ntohs (alum->addrlen);
974 address = (const char *) &alum[1];
975 plugin_name = (const char *) &address[address_len];
976 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
977 numeric = ntohs (alum->numeric_only);
978 papi = GST_plugins_printer_find (plugin_name);
981 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
982 "Failed to find plugin `%s'\n",
984 env = GNUNET_MQ_msg (atsm,
985 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
986 atsm->res = htonl (GNUNET_SYSERR);
987 atsm->addr_len = htonl (0);
988 GNUNET_MQ_send (tc->mq,
990 env = GNUNET_MQ_msg (atsm,
991 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
992 atsm->res = htonl (GNUNET_OK);
993 atsm->addr_len = htonl (0);
994 GNUNET_MQ_send (tc->mq,
998 actx = GNUNET_new (struct AddressToStringContext);
1000 GNUNET_CONTAINER_DLL_insert (a2s_head,
1003 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1004 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1005 "Pretty-printing address of %u bytes using plugin `%s'\n",
1008 papi->address_pretty_printer (papi->cls,
1014 &transmit_address_to_client,
1020 * Compose #PeerIterateResponseMessage using the given peer and address.
1022 * @param peer identity of the peer
1023 * @param address the address, NULL on disconnect
1024 * @return composed message
1026 static struct PeerIterateResponseMessage *
1027 compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer,
1028 const struct GNUNET_HELLO_Address *address)
1030 struct PeerIterateResponseMessage *msg;
1036 GNUNET_assert (NULL != peer);
1037 if (NULL != address)
1039 tlen = strlen (address->transport_name) + 1;
1040 alen = address->address_length;
1047 size = (sizeof (struct PeerIterateResponseMessage) + alen + tlen);
1048 msg = GNUNET_malloc (size);
1049 msg->header.size = htons (size);
1051 = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE);
1052 msg->reserved = htonl (0);
1054 msg->addrlen = htonl (alen);
1055 msg->pluginlen = htonl (tlen);
1057 if (NULL != address)
1059 msg->local_address_info = htonl((uint32_t) address->local_info);
1060 addr = (char *) &msg[1];
1061 GNUNET_memcpy (addr,
1064 GNUNET_memcpy (&addr[alen],
1065 address->transport_name,
1073 * Context for #send_validation_information() and
1074 * #send_peer_information().
1076 struct IterationContext
1079 * Context to use for the transmission.
1081 struct TransportClient *tc;
1084 * Which peers do we care about?
1086 struct GNUNET_PeerIdentity id;
1089 * #GNUNET_YES if @e id should be ignored because we want all peers.
1096 * Output information of neighbours to the given client.
1098 * @param cls the `struct PeerIterationContext *`
1099 * @param peer identity of the neighbour
1100 * @param address the address
1101 * @param state current state this peer is in
1102 * @param state_timeout timeout for the current state of the peer
1103 * @param bandwidth_in inbound quota in NBO
1104 * @param bandwidth_out outbound quota in NBO
1107 send_peer_information (void *cls,
1108 const struct GNUNET_PeerIdentity *peer,
1109 const struct GNUNET_HELLO_Address *address,
1110 enum GNUNET_TRANSPORT_PeerState state,
1111 struct GNUNET_TIME_Absolute state_timeout,
1112 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1113 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1115 struct IterationContext *pc = cls;
1116 struct GNUNET_MQ_Envelope *env;
1117 struct PeerIterateResponseMessage *msg;
1119 if ( (GNUNET_YES != pc->all) &&
1124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1125 "Sending information about `%s' using address `%s' in state `%s'\n",
1127 (NULL != address) ? GST_plugins_a2s (address) : "<none>",
1128 GNUNET_TRANSPORT_ps2s (state));
1129 msg = compose_address_iterate_response_message (peer,
1131 msg->state = htonl (state);
1132 msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout);
1133 env = GNUNET_MQ_msg_copy (&msg->header);
1135 GNUNET_MQ_send (pc->tc->mq,
1141 * Client asked to obtain information about a specific or all peers
1142 * Process the request.
1144 * @param cls the client
1145 * @param msg the peer address information request
1148 handle_client_monitor_peers (void *cls,
1149 const struct PeerMonitorMessage *msg)
1151 struct TransportClient *tc = cls;
1152 struct IterationContext pc;
1154 if (CT_NONE != tc->type)
1157 GNUNET_SERVICE_client_drop (tc->client);
1160 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1161 GNUNET_SERVICE_client_mark_monitor (tc->client);
1163 /* Send initial list */
1165 if (0 == memcmp (&msg->peer,
1167 sizeof (struct GNUNET_PeerIdentity)))
1169 /* iterate over all neighbours */
1170 pc.all = GNUNET_YES;
1175 /* just return one neighbour */
1179 GST_neighbours_iterate (&send_peer_information,
1182 if (GNUNET_YES != ntohl (msg->one_shot))
1184 tc->details.monitor_peer = msg->peer;
1185 tc->type = CT_MONITOR;
1186 if (0 != memcmp (&msg->peer,
1188 sizeof (struct GNUNET_PeerIdentity)))
1189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1190 "Client %p started monitoring of the peer `%s'\n",
1192 GNUNET_i2s (&msg->peer));
1194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1195 "Client %p started monitoring all peers\n",
1200 struct GNUNET_MessageHeader *msg;
1201 struct GNUNET_MQ_Envelope *env;
1203 env = GNUNET_MQ_msg (msg,
1204 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END);
1205 GNUNET_MQ_send (tc->mq,
1212 * Function called by the plugin with information about the
1213 * current sessions managed by the plugin (for monitoring).
1215 * @param cls closure
1216 * @param session session handle this information is about,
1217 * NULL to indicate that we are "in sync" (initial
1218 * iteration complete)
1219 * @param info information about the state of the session,
1220 * NULL if @a session is also NULL and we are
1221 * merely signalling that the initial iteration is over
1224 plugin_session_info_cb (void *cls,
1225 struct GNUNET_ATS_Session *session,
1226 const struct GNUNET_TRANSPORT_SessionInfo *info)
1228 struct GNUNET_MQ_Envelope *env;
1229 struct TransportPluginMonitorMessage *msg;
1230 struct GNUNET_MessageHeader *sync;
1237 if (0 == GNUNET_notification_context_get_size (plugin_nc))
1239 GST_plugins_monitor_subscribe (NULL,
1243 if ( (NULL == info) &&
1246 /* end of initial iteration */
1247 if (NULL != sync_client)
1249 env = GNUNET_MQ_msg (sync,
1250 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC);
1251 GNUNET_MQ_send (sync_client->mq,
1257 GNUNET_assert (NULL != info);
1258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1259 "Plugin event for peer %s on transport %s\n",
1260 GNUNET_i2s (&info->address->peer),
1261 info->address->transport_name);
1262 slen = strlen (info->address->transport_name) + 1;
1263 alen = info->address->address_length;
1264 size = sizeof (struct TransportPluginMonitorMessage) + slen + alen;
1265 if (size > UINT16_MAX)
1270 msg = GNUNET_malloc (size);
1271 msg->header.size = htons (size);
1272 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT);
1273 msg->session_state = htons ((uint16_t) info->state);
1274 msg->is_inbound = htons ((int16_t) info->is_inbound);
1275 msg->msgs_pending = htonl (info->num_msg_pending);
1276 msg->bytes_pending = htonl (info->num_bytes_pending);
1277 msg->timeout = GNUNET_TIME_absolute_hton (info->session_timeout);
1278 msg->delay = GNUNET_TIME_absolute_hton (info->receive_delay);
1279 msg->peer = info->address->peer;
1280 msg->session_id = (uint64_t) (intptr_t) session;
1281 msg->plugin_name_len = htons (slen);
1282 msg->plugin_address_len = htons (alen);
1283 name = (char *) &msg[1];
1284 GNUNET_memcpy (name,
1285 info->address->transport_name,
1288 GNUNET_memcpy (addr,
1289 info->address->address,
1291 if (NULL != sync_client)
1293 struct GNUNET_MQ_Envelope *env;
1295 env = GNUNET_MQ_msg_copy (&msg->header);
1296 GNUNET_MQ_send (sync_client->mq,
1301 GNUNET_notification_context_broadcast (plugin_nc,
1310 * Client asked to obtain information about all plugin connections.
1312 * @param cls the client
1313 * @param message the peer address information request
1316 handle_client_monitor_plugins (void *cls,
1317 const struct GNUNET_MessageHeader *message)
1319 struct TransportClient *tc = cls;
1321 GNUNET_SERVICE_client_mark_monitor (tc->client);
1322 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1323 GNUNET_notification_context_add (plugin_nc,
1325 GNUNET_assert (NULL == sync_client);
1327 GST_plugins_monitor_subscribe (&plugin_session_info_cb,
1333 * Broadcast the given message to all of our clients.
1335 * @param msg message to broadcast
1336 * @param may_drop #GNUNET_YES if the message can be dropped / is payload
1339 GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
1342 struct TransportClient *tc;
1345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1346 "Asked to broadcast message of type %u with %u bytes\n",
1347 (unsigned int) ntohs (msg->type),
1348 (unsigned int) ntohs (msg->size));
1350 for (tc = clients_head; NULL != tc; tc = tc->next)
1352 if ( (GNUNET_YES == may_drop) &&
1353 (CT_CORE != tc->type) )
1354 continue; /* skip, this client does not care about payload */
1360 if (GNUNET_NO == done)
1361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1362 "Message of type %u not delivered, is CORE service up?\n",
1368 * Broadcast the new active address to all clients monitoring the peer.
1370 * @param peer peer this update is about (never NULL)
1371 * @param address address, NULL on disconnect
1372 * @param state the current state of the peer
1373 * @param state_timeout the time out for the state
1376 GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer,
1377 const struct GNUNET_HELLO_Address *address,
1378 enum GNUNET_TRANSPORT_PeerState state,
1379 struct GNUNET_TIME_Absolute state_timeout)
1381 struct GNUNET_MQ_Envelope *env;
1382 struct PeerIterateResponseMessage *msg;
1383 struct TransportClient *tc;
1385 msg = compose_address_iterate_response_message (peer,
1387 msg->state = htonl (state);
1388 msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout);
1389 for (tc = clients_head; NULL != tc; tc = tc->next)
1391 if (CT_MONITOR != tc->type)
1393 if ((0 == memcmp (&tc->details.monitor_peer,
1395 sizeof (struct GNUNET_PeerIdentity))) ||
1396 (0 == memcmp (&tc->details.monitor_peer,
1398 sizeof (struct GNUNET_PeerIdentity))))
1400 env = GNUNET_MQ_msg_copy (&msg->header);
1401 GNUNET_MQ_send (tc->mq,
1410 * Mark the peer as down so we don't call the continuation
1411 * context in the future.
1414 * @param peer peer that got disconnected
1415 * @param value a `struct SendTransmitContinuationContext` to mark
1416 * @return #GNUNET_OK (continue to iterate)
1419 mark_peer_down (void *cls,
1420 const struct GNUNET_PeerIdentity *peer,
1423 struct SendTransmitContinuationContext *stcc = value;
1425 stcc->down = GNUNET_YES;
1431 * Notify all clients about a disconnect, and cancel
1432 * pending SEND_OK messages for this peer.
1434 * @param peer peer that disconnected
1437 GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer)
1439 struct DisconnectInfoMessage disconnect_msg;
1441 GNUNET_CONTAINER_multipeermap_get_multiple (active_stccs,
1445 disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage));
1446 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
1447 disconnect_msg.reserved = htonl (0);
1448 disconnect_msg.peer = *peer;
1449 GST_clients_broadcast (&disconnect_msg.header,
1456 * Transmit our HELLO message to the given (connected) neighbour.
1458 * @param cls the 'HELLO' message
1459 * @param peer identity of the peer
1460 * @param address the address
1461 * @param state current state this peer is in
1462 * @param state_timeout timeout for the current state of the peer
1463 * @param bandwidth_in inbound quota in NBO
1464 * @param bandwidth_out outbound quota in NBO
1467 transmit_our_hello (void *cls,
1468 const struct GNUNET_PeerIdentity *peer,
1469 const struct GNUNET_HELLO_Address *address,
1470 enum GNUNET_TRANSPORT_PeerState state,
1471 struct GNUNET_TIME_Absolute state_timeout,
1472 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1473 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1475 const struct GNUNET_MessageHeader *hello = cls;
1480 sizeof (struct GNUNET_PeerIdentity)))
1481 return; /* not to ourselves */
1482 if (GNUNET_NO == GST_neighbours_test_connected (peer))
1485 GST_neighbours_send (peer,
1487 ntohs (hello->size),
1495 * My HELLO has changed. Tell everyone who should know.
1498 * @param hello new HELLO
1501 process_hello_update (void *cls,
1502 const struct GNUNET_MessageHeader *hello)
1504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1505 "Broadcasting HELLO to clients\n");
1506 GST_clients_broadcast (hello, GNUNET_NO);
1507 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1508 "Broadcasting HELLO to neighbours\n");
1509 GST_neighbours_iterate (&transmit_our_hello,
1515 * We received some payload. Prepare to pass it on to our clients.
1517 * @param address address and (claimed) identity of the other peer
1518 * @param session identifier used for this session (NULL for plugins
1519 * that do not offer bi-directional communication to the sender
1520 * using the same "connection")
1521 * @param message the message to process
1522 * @return how long the plugin should wait until receiving more data
1524 static struct GNUNET_TIME_Relative
1525 process_payload (const struct GNUNET_HELLO_Address *address,
1526 struct GNUNET_ATS_Session *session,
1527 const struct GNUNET_MessageHeader *message)
1529 struct GNUNET_TIME_Relative ret;
1531 struct InboundMessage *im;
1532 size_t msg_size = ntohs (message->size);
1533 size_t size = sizeof(struct InboundMessage) + msg_size;
1534 char buf[size] GNUNET_ALIGN;
1536 do_forward = GNUNET_SYSERR;
1537 ret = GST_neighbours_calculate_receive_delay (&address->peer,
1540 if (! GST_neighbours_test_connected (&address->peer))
1542 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1543 "Discarded %u bytes type %u payload from peer `%s'\n",
1544 (unsigned int) msg_size,
1545 ntohs (message->type),
1546 GNUNET_i2s (&address->peer));
1547 GNUNET_STATISTICS_update (GST_stats, gettext_noop
1548 ("# bytes payload discarded due to not connected peer"),
1554 if (GNUNET_YES != do_forward)
1556 im = (struct InboundMessage *) buf;
1557 im->header.size = htons (size);
1558 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
1559 im->peer = address->peer;
1560 GNUNET_memcpy (&im[1],
1562 ntohs (message->size));
1563 GST_clients_broadcast (&im->header,
1570 * Task to asynchronously terminate a session.
1572 * @param cls the `struct GNUNET_ATS_SessionKiller` with the information for the kill
1575 kill_session_task (void *cls)
1577 struct GNUNET_ATS_SessionKiller *sk = cls;
1580 GNUNET_CONTAINER_DLL_remove (sk_head,
1583 sk->plugin->disconnect_session (sk->plugin->cls,
1590 * Force plugin to terminate session due to communication
1593 * @param plugin_name name of the plugin
1594 * @param session session to termiante
1597 kill_session (const char *plugin_name,
1598 struct GNUNET_ATS_Session *session)
1600 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
1601 struct GNUNET_ATS_SessionKiller *sk;
1603 for (sk = sk_head; NULL != sk; sk = sk->next)
1604 if (sk->session == session)
1606 plugin = GST_plugins_find (plugin_name);
1612 /* need to issue disconnect asynchronously */
1613 sk = GNUNET_new (struct GNUNET_ATS_SessionKiller);
1614 sk->session = session;
1615 sk->plugin = plugin;
1616 sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task,
1618 GNUNET_CONTAINER_DLL_insert (sk_head,
1625 * Black list check result for try_connect call
1626 * If connection to the peer is allowed request adddress and ???
1628 * @param cls the message
1629 * @param peer the peer
1630 * @param address the address
1631 * @param session the session
1632 * @param result the result
1635 connect_bl_check_cont (void *cls,
1636 const struct GNUNET_PeerIdentity *peer,
1637 const struct GNUNET_HELLO_Address *address,
1638 struct GNUNET_ATS_Session *session,
1641 struct GNUNET_MessageHeader *msg = cls;
1643 if (GNUNET_OK == result)
1645 /* Blacklist allows to speak to this peer, forward SYN to neighbours */
1646 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1647 "Received SYN message from peer `%s' at `%s'\n",
1649 GST_plugins_a2s (address));
1651 GST_neighbours_handle_session_syn (msg,
1654 GST_blacklist_abort_matching (address,
1656 kill_session (address->transport_name,
1663 if (GNUNET_SYSERR == result)
1664 return; /* check was aborted, session destroyed */
1665 /* Blacklist denies to speak to this peer */
1666 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1667 "Discarding SYN message from `%s' due to denied blacklist check\n",
1669 kill_session (address->transport_name,
1675 * Function called by the transport for each received message.
1677 * @param cls closure, const char* with the name of the plugin we received the message from
1678 * @param address address and (claimed) identity of the other peer
1679 * @param message the message, NULL if we only care about
1680 * learning about the delay until we should receive again
1681 * @param session identifier used for this session (NULL for plugins
1682 * that do not offer bi-directional communication to the sender
1683 * using the same "connection")
1684 * @return how long the plugin should wait until receiving more data
1685 * (plugins that do not support this, can ignore the return value)
1687 struct GNUNET_TIME_Relative
1688 GST_receive_callback (void *cls,
1689 const struct GNUNET_HELLO_Address *address,
1690 struct GNUNET_ATS_Session *session,
1691 const struct GNUNET_MessageHeader *message)
1693 const char *plugin_name = cls;
1694 struct GNUNET_TIME_Relative ret;
1697 ret = GNUNET_TIME_UNIT_ZERO;
1698 if (NULL == message)
1700 type = ntohs (message->type);
1701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1702 "Received message with type %u from peer `%s' at %s\n",
1704 GNUNET_i2s (&address->peer),
1705 GST_plugins_a2s (address));
1707 GNUNET_STATISTICS_update (GST_stats,
1708 gettext_noop ("# bytes total received"),
1709 ntohs (message->size),
1711 GST_neighbours_notify_data_recv (address,
1715 case GNUNET_MESSAGE_TYPE_HELLO_LEGACY:
1716 /* Legacy HELLO message, discard */
1718 case GNUNET_MESSAGE_TYPE_HELLO:
1719 if (GNUNET_OK != GST_validation_handle_hello (message))
1721 GNUNET_break_op (0);
1722 GST_blacklist_abort_matching (address,
1726 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
1727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1728 "Processing PING from `%s'\n",
1729 GST_plugins_a2s (address));
1731 GST_validation_handle_ping (&address->peer,
1736 GST_blacklist_abort_matching (address,
1738 kill_session (plugin_name,
1742 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
1743 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1744 "Processing PONG from `%s'\n",
1745 GST_plugins_a2s (address));
1747 GST_validation_handle_pong (&address->peer,
1750 GNUNET_break_op (0);
1751 GST_blacklist_abort_matching (address,
1753 kill_session (plugin_name, session);
1756 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN:
1757 /* Do blacklist check if communication with this peer is allowed */
1758 (void) GST_blacklist_test_allowed (&address->peer,
1760 &connect_bl_check_cont,
1761 GNUNET_copy_message (message),
1765 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK:
1767 GST_neighbours_handle_session_syn_ack (message,
1771 GST_blacklist_abort_matching (address, session);
1772 kill_session (plugin_name, session);
1775 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
1777 GST_neighbours_handle_session_ack (message,
1782 GST_blacklist_abort_matching (address, session);
1783 kill_session (plugin_name, session);
1786 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
1787 GST_neighbours_handle_disconnect_message (&address->peer,
1790 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA:
1791 GST_neighbours_handle_quota_message (&address->peer,
1794 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
1795 GST_neighbours_keepalive (&address->peer,
1798 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE:
1799 GST_neighbours_keepalive_response (&address->peer,
1803 /* should be payload */
1804 GNUNET_STATISTICS_update (GST_stats,
1805 gettext_noop ("# bytes payload received"),
1806 ntohs (message->size),
1808 ret = process_payload (address,
1814 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1815 "Allowing receive from peer %s to continue in %s\n",
1816 GNUNET_i2s (&address->peer),
1817 GNUNET_STRINGS_relative_time_to_string (ret,
1824 * Function that will be called for each address the transport
1825 * is aware that it might be reachable under. Update our HELLO.
1827 * @param cls name of the plugin (const char*)
1828 * @param add_remove should the address added (YES) or removed (NO) from the
1829 * set of valid addresses?
1830 * @param address the address to add or remove
1833 plugin_env_address_change_notification (void *cls,
1835 const struct GNUNET_HELLO_Address *address)
1837 static int addresses = 0;
1839 if (GNUNET_YES == add_remove)
1842 GNUNET_STATISTICS_update (GST_stats,
1843 "# transport addresses",
1847 else if (GNUNET_NO == add_remove)
1856 GNUNET_STATISTICS_update (GST_stats,
1857 "# transport addresses",
1862 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1863 "Transport now has %u addresses to communicate\n",
1865 GST_hello_modify_addresses (add_remove,
1871 * Function that will be called whenever the plugin internally
1872 * cleans up a session pointer and hence the service needs to
1873 * discard all of those sessions as well. Plugins that do not
1874 * use sessions can simply omit calling this function and always
1875 * use NULL wherever a session pointer is needed. This function
1876 * should be called BEFORE a potential "TransmitContinuation"
1877 * from the "TransmitFunction".
1879 * @param cls closure
1880 * @param address which address was the session for
1881 * @param session which session is being destoyed
1884 plugin_env_session_end (void *cls,
1885 const struct GNUNET_HELLO_Address *address,
1886 struct GNUNET_ATS_Session *session)
1888 struct GNUNET_ATS_SessionKiller *sk;
1890 if (NULL == address)
1895 if (NULL == session)
1900 GNUNET_assert (strlen (address->transport_name) > 0);
1902 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1903 "Notification from plugin about terminated session %p from peer `%s' address `%s'\n",
1905 GNUNET_i2s (&address->peer),
1906 GST_plugins_a2s (address));
1908 GST_neighbours_session_terminated (&address->peer,
1910 GST_ats_del_session (address,
1912 GST_blacklist_abort_matching (address,
1915 for (sk = sk_head; NULL != sk; sk = sk->next)
1917 if (sk->session == session)
1919 GNUNET_CONTAINER_DLL_remove (sk_head,
1922 GNUNET_SCHEDULER_cancel (sk->task);
1931 * Black list check result from blacklist check triggered when a
1932 * plugin gave us a new session in #plugin_env_session_start(). If
1933 * connection to the peer is disallowed, kill the session.
1936 * @param peer the peer
1937 * @param address address associated with the request
1938 * @param session session associated with the request
1939 * @param result the result
1942 plugin_env_session_start_bl_check_cont (void *cls,
1943 const struct GNUNET_PeerIdentity *peer,
1944 const struct GNUNET_HELLO_Address *address,
1945 struct GNUNET_ATS_Session *session,
1948 if (GNUNET_OK != result)
1950 kill_session (address->transport_name,
1955 GNUNET_HELLO_address_check_option (address,
1956 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1958 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1959 "Informing verifier about inbound session's address `%s'\n",
1960 GST_plugins_a2s (address));
1961 GST_validation_handle_address (address);
1967 * Plugin tells transport service about a new inbound session
1970 * @param address the address
1971 * @param session the new session
1972 * @param scope network scope information
1975 plugin_env_session_start (void *cls,
1976 const struct GNUNET_HELLO_Address *address,
1977 struct GNUNET_ATS_Session *session,
1978 enum GNUNET_NetworkType scope)
1980 struct GNUNET_ATS_Properties prop;
1982 if (NULL == address)
1987 if (NULL == session)
1992 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1993 "Notification from plugin `%s' about new session from peer `%s' address `%s'\n",
1994 address->transport_name,
1995 GNUNET_i2s (&address->peer),
1996 GST_plugins_a2s (address));
1998 GNUNET_HELLO_address_check_option (address,
1999 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
2001 /* inbound is always new, but outbound MAY already be known, but
2002 for example for UNIX, we have symmetric connections and thus we
2003 may not know the address yet; add if necessary! */
2004 /* FIXME: maybe change API here so we just pass scope? */
2008 GNUNET_break (GNUNET_NT_UNSPECIFIED != scope);
2010 GST_ats_add_inbound_address (address,
2014 /* Do blacklist check if communication with this peer is allowed */
2015 (void) GST_blacklist_test_allowed (&address->peer,
2016 address->transport_name,
2017 &plugin_env_session_start_bl_check_cont,
2025 * Function called by ATS to notify the callee that the
2026 * assigned bandwidth or address for a given peer was changed. If the
2027 * callback is called with address/bandwidth assignments of zero, the
2028 * ATS disconnect function will still be called once the disconnect
2029 * actually happened.
2031 * @param cls closure
2032 * @param peer the peer this address is intended for
2033 * @param address address to use (for peer given in address)
2034 * @param session session to use (if available)
2035 * @param bandwidth_out assigned outbound bandwidth for the connection in NBO,
2036 * 0 to disconnect from peer
2037 * @param bandwidth_in assigned inbound bandwidth for the connection in NBO,
2038 * 0 to disconnect from peer
2039 * @param ats ATS information
2040 * @param ats_count number of @a ats elements
2043 ats_request_address_change (void *cls,
2044 const struct GNUNET_PeerIdentity *peer,
2045 const struct GNUNET_HELLO_Address *address,
2046 struct GNUNET_ATS_Session *session,
2047 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
2048 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
2050 uint32_t bw_in = ntohl (bandwidth_in.value__);
2051 uint32_t bw_out = ntohl (bandwidth_out.value__);
2055 /* ATS service died, all suggestions become invalid!
2056 (but we'll keep using the allocations for a little
2057 while, to keep going while ATS restarts) */
2058 /* FIXME: We should drop all
2059 connections now, as ATS won't explicitly tell
2060 us and be unaware of ongoing resource allocations! */
2063 /* ATS tells me to disconnect from peer */
2064 if ((0 == bw_in) && (0 == bw_out))
2066 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2067 "ATS tells me to disconnect from peer `%s'\n",
2069 GST_neighbours_force_disconnect (peer);
2072 GNUNET_assert (NULL != address);
2073 GNUNET_STATISTICS_update (GST_stats,
2074 "# ATS suggestions received",
2077 GST_neighbours_switch_to_address (address,
2085 * Closure for #test_connection_ok().
2087 struct TestConnectionContext
2090 * Is this the first neighbour we're checking?
2095 * Handle to the blacklisting client we need to ask.
2097 struct TransportClient *tc;
2102 * Got the result about an existing connection from a new blacklister.
2103 * Shutdown the neighbour if necessary.
2106 * @param peer the neighbour that was investigated
2107 * @param address address associated with the request
2108 * @param session session associated with the request
2109 * @param allowed #GNUNET_OK if we can keep it,
2110 * #GNUNET_NO if we must shutdown the connection
2113 confirm_or_drop_neighbour (void *cls,
2114 const struct GNUNET_PeerIdentity *peer,
2115 const struct GNUNET_HELLO_Address *address,
2116 struct GNUNET_ATS_Session *session,
2119 if (GNUNET_OK == allowed)
2120 return; /* we're done */
2121 GNUNET_STATISTICS_update (GST_stats,
2122 gettext_noop ("# disconnects due to blacklist"),
2125 GST_neighbours_force_disconnect (peer);
2130 * Test if an existing connection is still acceptable given a new
2131 * blacklisting client.
2133 * @param cls the `struct TestConnectionContext *`
2134 * @param peer identity of the peer
2135 * @param address the address
2136 * @param state current state this peer is in
2137 * @param state_timeout timeout for the current state of the peer
2138 * @param bandwidth_in bandwidth assigned inbound
2139 * @param bandwidth_out bandwidth assigned outbound
2142 test_connection_ok (void *cls,
2143 const struct GNUNET_PeerIdentity *peer,
2144 const struct GNUNET_HELLO_Address *address,
2145 enum GNUNET_TRANSPORT_PeerState state,
2146 struct GNUNET_TIME_Absolute state_timeout,
2147 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
2148 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2150 struct TestConnectionContext *tcc = cls;
2151 struct GST_BlacklistCheck *bc;
2153 bc = GNUNET_new (struct GST_BlacklistCheck);
2154 GNUNET_CONTAINER_DLL_insert (bc_head,
2158 bc->address = GNUNET_HELLO_address_copy (address);
2159 bc->cont = &confirm_or_drop_neighbour;
2160 bc->cont_cls = NULL;
2161 bc->bl_pos = tcc->tc;
2162 if (GNUNET_YES == tcc->first)
2164 /* all would wait for the same client, no need to
2165 * create more than just the first task right now */
2166 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
2168 tcc->first = GNUNET_NO;
2174 * Initialize a blacklisting client. We got a blacklist-init
2175 * message from this client, add it to the list of clients
2176 * to query for blacklisting.
2178 * @param cls the client
2179 * @param message the blacklist-init message that was sent
2182 handle_client_blacklist_init (void *cls,
2183 const struct GNUNET_MessageHeader *message)
2185 struct TransportClient *tc = cls;
2186 struct TestConnectionContext tcc;
2188 if (CT_NONE != tc->type)
2191 GNUNET_SERVICE_client_drop (tc->client);
2194 GNUNET_SERVICE_client_mark_monitor (tc->client);
2195 tc->type = CT_BLACKLIST;
2196 tc->details.blacklist.call_receive_done = GNUNET_YES;
2197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2198 "New blacklist client %p\n",
2200 /* confirm that all existing connections are OK! */
2202 tcc.first = GNUNET_YES;
2203 GST_neighbours_iterate (&test_connection_ok,
2209 * Free the given entry in the blacklist.
2212 * @param key host identity (unused)
2213 * @param value the blacklist entry
2214 * @return #GNUNET_OK (continue to iterate)
2217 free_blacklist_entry (void *cls,
2218 const struct GNUNET_PeerIdentity *key,
2223 GNUNET_free_non_null (be);
2229 * Set traffic metric to manipulate
2231 * @param cls closure
2232 * @param message containing information
2235 handle_client_set_metric (void *cls,
2236 const struct TrafficMetricMessage *tm)
2238 struct TransportClient *tc = cls;
2240 GST_manipulation_set_metric (tm);
2241 GNUNET_SERVICE_client_continue (tc->client);
2246 * Function called when the service shuts down. Unloads our plugins
2247 * and cancels pending validations.
2249 * @param cls closure, unused
2252 shutdown_task (void *cls)
2254 struct AddressToStringContext *cur;
2256 GST_neighbours_stop ();
2257 GST_plugins_unload ();
2258 GST_validation_stop ();
2260 GNUNET_ATS_scheduling_done (GST_ats);
2262 GNUNET_ATS_connectivity_done (GST_ats_connect);
2263 GST_ats_connect = NULL;
2264 GNUNET_NT_scanner_done (GST_is);
2266 while (NULL != (cur = a2s_head))
2268 GNUNET_CONTAINER_DLL_remove (a2s_head,
2273 if (NULL != plugin_nc)
2275 GNUNET_notification_context_destroy (plugin_nc);
2278 GNUNET_CONTAINER_multipeermap_destroy (active_stccs);
2279 active_stccs = NULL;
2280 if (NULL != blacklist)
2282 GNUNET_CONTAINER_multipeermap_iterate (blacklist,
2283 &free_blacklist_entry,
2285 GNUNET_CONTAINER_multipeermap_destroy (blacklist);
2289 GST_manipulation_stop ();
2291 if (NULL != GST_peerinfo)
2293 GNUNET_PEERINFO_disconnect (GST_peerinfo);
2294 GST_peerinfo = NULL;
2296 if (NULL != GST_stats)
2298 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
2301 if (NULL != GST_my_private_key)
2303 GNUNET_free (GST_my_private_key);
2304 GST_my_private_key = NULL;
2310 * Perform next action in the blacklist check.
2312 * @param cls the `struct GST_BlacklistCheck *`
2315 do_blacklist_check (void *cls)
2317 struct GST_BlacklistCheck *bc = cls;
2318 struct TransportClient *tc;
2319 struct GNUNET_MQ_Envelope *env;
2320 struct BlacklistMessage *bm;
2323 while (NULL != (tc = bc->bl_pos))
2325 if (CT_BLACKLIST == tc->type)
2327 bc->bl_pos = tc->next;
2331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2332 "No other blacklist clients active, will allow neighbour `%s'\n",
2333 GNUNET_i2s (&bc->peer));
2335 bc->cont (bc->cont_cls,
2340 GST_blacklist_test_cancel (bc);
2343 if ( (NULL != tc->details.blacklist.bc) ||
2344 (GNUNET_NO != tc->details.blacklist.waiting_for_reply) )
2345 return; /* someone else busy with this client */
2346 tc->details.blacklist.bc = bc;
2347 env = GNUNET_MQ_msg (bm,
2348 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY);
2349 bm->is_allowed = htonl (0);
2350 bm->peer = bc->peer;
2351 GNUNET_MQ_send (tc->mq,
2353 if (GNUNET_YES == tc->details.blacklist.call_receive_done)
2355 tc->details.blacklist.call_receive_done = GNUNET_NO;
2356 GNUNET_SERVICE_client_continue (tc->client);
2358 tc->details.blacklist.waiting_for_reply = GNUNET_YES;
2363 * A blacklisting client has sent us reply. Process it.
2365 * @param cls the client
2366 * @param msg the blacklist-reply message that was sent
2369 handle_client_blacklist_reply (void *cls,
2370 const struct BlacklistMessage *msg)
2372 struct TransportClient *tc = cls;
2373 struct GST_BlacklistCheck *bc;
2375 if (CT_BLACKLIST != tc->type)
2378 GNUNET_SERVICE_client_drop (tc->client);
2381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2382 "Blacklist client %p sent reply for `%s'\n",
2384 GNUNET_i2s (&msg->peer));
2385 bc = tc->details.blacklist.bc;
2386 tc->details.blacklist.bc = NULL;
2387 tc->details.blacklist.waiting_for_reply = GNUNET_NO;
2388 tc->details.blacklist.call_receive_done = GNUNET_YES;
2391 /* only run this if the blacklist check has not been
2392 * cancelled in the meantime... */
2393 GNUNET_assert (bc->bl_pos == tc);
2394 if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
2396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2397 "Blacklist check failed, peer not allowed\n");
2398 /* For the duration of the continuation, make the ongoing
2399 check invisible (to avoid double-cancellation); then
2400 add it back again so we can re-use GST_blacklist_test_cancel() */
2401 GNUNET_CONTAINER_DLL_remove (bc_head,
2404 bc->cont (bc->cont_cls,
2409 GNUNET_CONTAINER_DLL_insert (bc_head,
2412 GST_blacklist_test_cancel (bc);
2413 tc->details.blacklist.call_receive_done = GNUNET_NO;
2414 GNUNET_SERVICE_client_continue (tc->client);
2419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2420 "Blacklist check succeeded, continuing with checks\n");
2421 tc->details.blacklist.call_receive_done = GNUNET_NO;
2422 GNUNET_SERVICE_client_continue (tc->client);
2423 bc->bl_pos = tc->next;
2424 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
2428 /* check if any other blacklist checks are waiting for this blacklister */
2429 for (bc = bc_head; bc != NULL; bc = bc->next)
2430 if ( (bc->bl_pos == tc) &&
2431 (NULL == bc->task) )
2433 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
2441 * Add the given peer to the blacklist (for the given transport).
2443 * @param peer peer to blacklist
2444 * @param transport_name transport to blacklist for this peer, NULL for all
2447 GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
2448 const char *transport_name)
2450 char *transport = NULL;
2452 if (NULL != transport_name)
2454 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2455 "Adding peer `%s' with plugin `%s' to blacklist\n",
2458 transport = GNUNET_strdup (transport_name);
2461 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2462 "Adding peer `%s' with all plugins to blacklist\n",
2464 if (NULL == blacklist)
2466 GNUNET_CONTAINER_multipeermap_create (TRANSPORT_BLACKLIST_HT_SIZE,
2469 GNUNET_CONTAINER_multipeermap_put (blacklist,
2472 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2477 * Abort blacklist if @a address and @a session match.
2479 * @param address address used to abort matching checks
2480 * @param session session used to abort matching checks
2483 GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
2484 struct GNUNET_ATS_Session *session)
2486 struct GST_BlacklistCheck *bc;
2487 struct GST_BlacklistCheck *n;
2490 while (NULL != (bc = n))
2493 if ( (bc->session == session) &&
2494 (0 == GNUNET_HELLO_address_cmp (bc->address,
2497 bc->cont (bc->cont_cls,
2502 GST_blacklist_test_cancel (bc);
2509 * Test if the given blacklist entry matches. If so,
2510 * abort the iteration.
2512 * @param cls the transport name to match (const char*)
2513 * @param key the key (unused)
2514 * @param value the 'char *' (name of a blacklisted transport)
2515 * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches
2518 test_blacklisted (void *cls,
2519 const struct GNUNET_PeerIdentity *key,
2522 const char *transport_name = cls;
2525 /* Blacklist entry be:
2526 * (NULL == be): peer is blacklisted with all plugins
2527 * (NULL != be): peer is blacklisted for a specific plugin
2529 * If (NULL != transport_name) we look for a transport specific entry:
2530 * if (transport_name == be) forbidden
2534 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2535 "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n",
2537 (NULL == transport_name) ? "unspecified" : transport_name,
2538 (NULL == be) ? "all plugins" : be);
2539 /* all plugins for this peer were blacklisted: disallow */
2543 /* blacklist check for specific transport */
2544 if ( (NULL != transport_name) &&
2547 if (0 == strcmp (transport_name,
2549 return GNUNET_NO; /* plugin is blacklisted! */
2556 * Test if a peer/transport combination is blacklisted.
2558 * @param peer the identity of the peer to test
2559 * @param transport_name name of the transport to test, never NULL
2560 * @param cont function to call with result
2561 * @param cont_cls closure for @a cont
2562 * @param address address to pass back to @a cont, can be NULL
2563 * @param session session to pass back to @a cont, can be NULL
2564 * @return handle to the blacklist check, NULL if the decision
2565 * was made instantly and @a cont was already called
2567 struct GST_BlacklistCheck *
2568 GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
2569 const char *transport_name,
2570 GST_BlacklistTestContinuation cont,
2572 const struct GNUNET_HELLO_Address *address,
2573 struct GNUNET_ATS_Session *session)
2575 struct GST_BlacklistCheck *bc;
2576 struct TransportClient *tc;
2578 GNUNET_assert (NULL != peer);
2579 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2580 "Blacklist check for peer `%s':%s\n",
2582 (NULL != transport_name) ? transport_name : "unspecified");
2584 /* Check local blacklist by iterating over hashmap
2585 * If iteration is aborted, we found a matching blacklist entry */
2586 if ((NULL != blacklist) &&
2588 GNUNET_CONTAINER_multipeermap_get_multiple (blacklist, peer,
2590 (void *) transport_name)))
2592 /* Disallowed by config, disapprove instantly */
2593 GNUNET_STATISTICS_update (GST_stats,
2594 gettext_noop ("# disconnects due to blacklist"),
2597 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2598 _("Disallowing connection to peer `%s' on transport %s\n"),
2600 (NULL != transport_name) ? transport_name : "unspecified");
2610 for (tc = clients_head; NULL != tc; tc = tc->next)
2611 if (CT_BLACKLIST == tc->type)
2615 /* no blacklist clients, approve instantly */
2622 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2623 "Allowing connection to peer `%s' %s\n",
2625 (NULL != transport_name) ? transport_name : "");
2629 /* need to query blacklist clients */
2630 bc = GNUNET_new (struct GST_BlacklistCheck);
2631 GNUNET_CONTAINER_DLL_insert (bc_head,
2635 bc->address = GNUNET_HELLO_address_copy (address);
2636 bc->session = session;
2638 bc->cont_cls = cont_cls;
2640 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
2647 * Cancel a blacklist check.
2649 * @param bc check to cancel
2652 GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc)
2654 GNUNET_CONTAINER_DLL_remove (bc_head,
2657 if (NULL != bc->bl_pos)
2659 if ( (CT_BLACKLIST == bc->bl_pos->type) &&
2660 (bc->bl_pos->details.blacklist.bc == bc) )
2662 /* we're at the head of the queue, remove us! */
2663 bc->bl_pos->details.blacklist.bc = NULL;
2666 if (NULL != bc->task)
2668 GNUNET_SCHEDULER_cancel (bc->task);
2671 GNUNET_free_non_null (bc->address);
2677 * Function to iterate over options in the blacklisting section for a peer.
2679 * @param cls closure
2680 * @param section name of the section
2681 * @param option name of the option
2682 * @param value value of the option
2685 blacklist_cfg_iter (void *cls,
2686 const char *section,
2690 unsigned int *res = cls;
2691 struct GNUNET_PeerIdentity peer;
2696 GNUNET_CRYPTO_eddsa_public_key_from_string (option,
2701 if ((NULL == value) || (0 == strcmp(value, "")))
2703 /* Blacklist whole peer */
2704 GST_blacklist_add_peer (&peer, NULL);
2705 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2706 _("Adding blacklisting entry for peer `%s'\n"),
2707 GNUNET_i2s (&peer));
2711 plugs = GNUNET_strdup (value);
2712 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
2714 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2715 _("Adding blacklisting entry for peer `%s':`%s'\n"),
2716 GNUNET_i2s (&peer), pos);
2717 GST_blacklist_add_peer (&peer, pos);
2719 GNUNET_free (plugs);
2726 * Read blacklist configuration
2728 * @param cfg the configuration handle
2729 * @param my_id my peer identity
2732 read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg,
2733 const struct GNUNET_PeerIdentity *my_id)
2736 unsigned int res = 0;
2738 GNUNET_snprintf (cfg_sect,
2740 "transport-blacklist-%s",
2741 GNUNET_i2s_full (my_id));
2742 GNUNET_CONFIGURATION_iterate_section_values (cfg,
2744 &blacklist_cfg_iter,
2746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2747 "Loaded %u blacklisting entries from configuration\n",
2753 * Initiate transport service.
2755 * @param cls closure
2756 * @param c configuration to use
2757 * @param service the initialized service
2761 const struct GNUNET_CONFIGURATION_Handle *c,
2762 struct GNUNET_SERVICE_Handle *service)
2765 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
2766 long long unsigned int max_fd_cfg;
2774 GNUNET_CONFIGURATION_get_value_filename (c,
2779 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2780 _("Transport service is lacking key configuration settings. Exiting.\n"));
2781 GNUNET_SCHEDULER_shutdown ();
2785 GNUNET_CONFIGURATION_get_value_time (c,
2790 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
2792 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
2793 GNUNET_free (keyfile);
2794 GNUNET_assert (NULL != pk);
2795 GST_my_private_key = pk;
2797 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
2798 GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg);
2799 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key,
2800 &GST_my_identity.public_key);
2801 GNUNET_assert (NULL != GST_my_private_key);
2803 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2804 "My identity is `%s'\n",
2805 GNUNET_i2s_full (&GST_my_identity));
2807 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
2809 if (NULL == GST_peerinfo)
2811 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2812 _("Could not access PEERINFO service. Exiting.\n"));
2813 GNUNET_SCHEDULER_shutdown ();
2820 struct rlimit r_file;
2822 if (0 == getrlimit (RLIMIT_NOFILE,
2825 max_fd_rlimit = r_file.rlim_cur;
2826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2827 "Maximum number of open files was: %u/%u\n",
2828 (unsigned int) r_file.rlim_cur,
2829 (unsigned int) r_file.rlim_max);
2831 max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */
2835 GNUNET_CONFIGURATION_get_value_number (GST_cfg,
2839 max_fd_cfg = max_fd_rlimit;
2841 if (max_fd_cfg > max_fd_rlimit)
2842 max_fd = max_fd_cfg;
2844 max_fd = max_fd_rlimit;
2845 if (max_fd < DEFAULT_MAX_FDS)
2846 max_fd = DEFAULT_MAX_FDS;
2848 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2849 "Limiting number of sockets to %u: validation %u, neighbors: %u\n",
2854 friend_only = GNUNET_CONFIGURATION_get_value_yesno (GST_cfg,
2857 if (GNUNET_SYSERR == friend_only)
2858 friend_only = GNUNET_NO; /* According to topology defaults */
2859 /* start subsystems */
2860 read_blacklist_configuration (GST_cfg,
2862 GST_is = GNUNET_NT_scanner_init ();
2863 GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg);
2864 GST_ats = GNUNET_ATS_scheduling_init (GST_cfg,
2865 &ats_request_address_change,
2868 GST_manipulation_init ();
2869 GST_plugins_load (&GST_manipulation_recv,
2870 &plugin_env_address_change_notification,
2871 &plugin_env_session_start,
2872 &plugin_env_session_end);
2873 GST_hello_start (friend_only,
2874 &process_hello_update,
2876 GST_neighbours_start ((max_fd / 3) * 2);
2877 active_stccs = GNUNET_CONTAINER_multipeermap_create (128,
2879 plugin_nc = GNUNET_notification_context_create (0);
2880 GST_validation_start ((max_fd / 3));
2885 * Define "main" method using service macro.
2889 GNUNET_SERVICE_OPTION_NONE,
2892 &client_disconnect_cb,
2894 GNUNET_MQ_hd_fixed_size (client_start,
2895 GNUNET_MESSAGE_TYPE_TRANSPORT_START,
2896 struct StartMessage,
2898 GNUNET_MQ_hd_var_size (client_hello,
2899 GNUNET_MESSAGE_TYPE_HELLO,
2900 struct GNUNET_MessageHeader,
2902 GNUNET_MQ_hd_var_size (client_send,
2903 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
2904 struct OutboundMessage,
2906 GNUNET_MQ_hd_var_size (client_address_to_string,
2907 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING,
2908 struct AddressLookupMessage,
2910 GNUNET_MQ_hd_fixed_size (client_monitor_peers,
2911 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST,
2912 struct PeerMonitorMessage,
2914 GNUNET_MQ_hd_fixed_size (client_blacklist_init,
2915 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
2916 struct GNUNET_MessageHeader,
2918 GNUNET_MQ_hd_fixed_size (client_blacklist_reply,
2919 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
2920 struct BlacklistMessage,
2922 GNUNET_MQ_hd_fixed_size (client_set_metric,
2923 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC,
2924 struct TrafficMetricMessage,
2926 GNUNET_MQ_hd_fixed_size (client_monitor_plugins,
2927 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START,
2928 struct GNUNET_MessageHeader,
2930 GNUNET_MQ_handler_end ());
2933 /* end of file gnunet-service-transport.c */