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
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file transport/gnunet-service-transport.c
22 * @brief main for gnunet-service-transport
23 * @author Christian Grothoff
26 #include "gnunet_util_lib.h"
27 #include "gnunet_hello_lib.h"
28 #include "gnunet_statistics_service.h"
29 #include "gnunet_transport_service.h"
30 #include "gnunet_peerinfo_service.h"
31 #include "gnunet_ats_service.h"
32 #include "gnunet-service-transport.h"
33 #include "gnunet-service-transport_ats.h"
34 #include "gnunet-service-transport_hello.h"
35 #include "gnunet-service-transport_neighbours.h"
36 #include "gnunet-service-transport_plugins.h"
37 #include "gnunet-service-transport_validation.h"
38 #include "gnunet-service-transport_manipulation.h"
39 #include "transport.h"
42 * Size of the blacklist hash map.
44 #define TRANSPORT_BLACKLIST_HT_SIZE 64
47 * How many messages can we have pending for a given client process
48 * before we start to drop incoming messages? We typically should
49 * have only one client and so this would be the primary buffer for
50 * messages, so the number should be chosen rather generously.
52 * The expectation here is that most of the time the queue is large
53 * enough so that a drop is virtually never required. Note that
54 * this value must be about as large as 'TOTAL_MSGS' in the
55 * 'test_transport_api_reliability.c', otherwise that testcase may
58 #define MAX_PENDING (128 * 1024)
62 * Information we need for an asynchronous session kill.
64 struct GNUNET_ATS_SessionKiller
69 struct GNUNET_ATS_SessionKiller *next;
74 struct GNUNET_ATS_SessionKiller *prev;
79 struct GNUNET_ATS_Session *session;
82 * Plugin for the session.
84 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
89 struct GNUNET_SCHEDULER_Task *task;
94 * What type of client is the `struct TransportClient` about?
99 * We do not know yet (client is fresh).
104 * Is the CORE service, we need to forward traffic to it.
109 * It is a monitor, forward monitor data.
114 * It is a blacklist, query about allowed connections.
121 * Context we use when performing a blacklist check.
123 struct GST_BlacklistCheck;
126 * Client connected to the transport service.
128 struct TransportClient
132 * This is a doubly-linked list.
134 struct TransportClient *next;
137 * This is a doubly-linked list.
139 struct TransportClient *prev;
142 * Handle to the client.
144 struct GNUNET_SERVICE_Client *client;
147 * Message queue to the client.
149 struct GNUNET_MQ_Handle *mq;
152 * What type of client is this?
154 enum ClientType type;
159 * Peer identity to monitor the addresses of.
160 * Zero to monitor all neighbours. Valid if
161 * @e type is CT_MONITOR.
163 struct GNUNET_PeerIdentity monitor_peer;
166 * Additional details if @e type is CT_BLACKLIST.
171 * Blacklist check that we're currently performing (or NULL
172 * if we're performing one that has been cancelled).
174 struct GST_BlacklistCheck *bc;
177 * Set to #GNUNET_YES if we're currently waiting for a reply.
179 int waiting_for_reply;
182 * #GNUNET_YES if we have to call receive_done for this client
184 int call_receive_done;
195 * Context we use when performing a blacklist check.
197 struct GST_BlacklistCheck
201 * This is a linked list.
203 struct GST_BlacklistCheck *next;
206 * This is a linked list.
208 struct GST_BlacklistCheck *prev;
211 * Peer being checked.
213 struct GNUNET_PeerIdentity peer;
216 * Continuation to call with the result.
218 GST_BlacklistTestContinuation cont;
221 * Closure for @e cont.
226 * Address for #GST_blacklist_abort_matching(), can be NULL.
228 struct GNUNET_HELLO_Address *address;
231 * Session for #GST_blacklist_abort_matching(), can be NULL.
233 struct GNUNET_ATS_Session *session;
236 * Our current position in the blacklisters list.
238 struct TransportClient *bl_pos;
241 * Current task performing the check.
243 struct GNUNET_SCHEDULER_Task *task;
249 * Context for address to string operations
251 struct AddressToStringContext
254 * This is a doubly-linked list.
256 struct AddressToStringContext *next;
259 * This is a doubly-linked list.
261 struct AddressToStringContext *prev;
264 * Client that made the request.
266 struct TransportClient* tc;
271 * Closure for #handle_send_transmit_continuation()
273 struct SendTransmitContinuationContext
277 * Client that made the request.
279 struct TransportClient *tc;
282 * Peer that was the target.
284 struct GNUNET_PeerIdentity target;
287 * At what time did we receive the message?
289 struct GNUNET_TIME_Absolute send_time;
292 * Unique ID, for logging.
294 unsigned long long uuid;
297 * Set to #GNUNET_YES if the connection for @e target goes
298 * down and we thus must no longer send the
299 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK message.
306 * Head of linked list of all clients to this service.
308 static struct TransportClient *clients_head;
311 * Tail of linked list of all clients to this service.
313 static struct TransportClient *clients_tail;
316 * Map of peer identities to active send transmit continuation
317 * contexts. Used to flag contexts as 'dead' when a connection goes
318 * down. Values are of type `struct SendTransmitContinuationContext
321 static struct GNUNET_CONTAINER_MultiPeerMap *active_stccs;
324 * Head of linked list of all pending address iterations
326 static struct AddressToStringContext *a2s_head;
329 * Tail of linked list of all pending address iterations
331 static struct AddressToStringContext *a2s_tail;
334 * Head of DLL of active blacklisting queries.
336 static struct GST_BlacklistCheck *bc_head;
339 * Tail of DLL of active blacklisting queries.
341 static struct GST_BlacklistCheck *bc_tail;
344 * Hashmap of blacklisted peers. Values are of type 'char *' (transport names),
345 * can be NULL if we have no static blacklist.
347 static struct GNUNET_CONTAINER_MultiPeerMap *blacklist;
350 * Notification context, to send updates on changes to active plugin
353 static struct GNUNET_NotificationContext *plugin_nc;
356 * Plugin monitoring client we are currently syncing, NULL if all
357 * monitoring clients are in sync.
359 static struct TransportClient *sync_client;
362 * Peer identity that is all zeros, used as a way to indicate
363 * "all peers". Used for comparissons.
365 static struct GNUNET_PeerIdentity all_zeros;
370 struct GNUNET_STATISTICS_Handle *GST_stats;
373 * Configuration handle.
375 const struct GNUNET_CONFIGURATION_Handle *GST_cfg;
378 * Configuration handle.
380 struct GNUNET_PeerIdentity GST_my_identity;
383 * Handle to peerinfo service.
385 struct GNUNET_PEERINFO_Handle *GST_peerinfo;
390 struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key;
393 * ATS scheduling handle.
395 struct GNUNET_ATS_SchedulingHandle *GST_ats;
398 * ATS connectivity handle.
400 struct GNUNET_ATS_ConnectivityHandle *GST_ats_connect;
403 * Hello address expiration
405 struct GNUNET_TIME_Relative hello_expiration;
408 * Head of DLL of asynchronous tasks to kill sessions.
410 static struct GNUNET_ATS_SessionKiller *sk_head;
413 * Tail of DLL of asynchronous tasks to kill sessions.
415 static struct GNUNET_ATS_SessionKiller *sk_tail;
418 * Interface scanner determines our LAN address range(s).
420 struct GNUNET_ATS_InterfaceScanner *GST_is;
424 * Queue the given message for transmission to the given client
426 * @param tc target of the message
427 * @param msg message to transmit
428 * @param may_drop #GNUNET_YES if the message can be dropped
431 unicast (struct TransportClient *tc,
432 const struct GNUNET_MessageHeader *msg,
435 struct GNUNET_MQ_Envelope *env;
437 if ( (GNUNET_MQ_get_length (tc->mq) >= MAX_PENDING) &&
438 (GNUNET_YES == may_drop) )
440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
441 "Dropping message of type %u and size %u, have %u/%u messages pending\n",
444 GNUNET_MQ_get_length (tc->mq),
446 GNUNET_STATISTICS_update (GST_stats,
448 ("# messages dropped due to slow client"), 1,
452 env = GNUNET_MQ_msg_copy (msg);
453 GNUNET_MQ_send (tc->mq,
459 * Called whenever a client connects. Allocates our
460 * data structures associated with that client.
462 * @param cls closure, NULL
463 * @param client identification of the client
464 * @param mq message queue for the client
465 * @return our `struct TransportClient`
468 client_connect_cb (void *cls,
469 struct GNUNET_SERVICE_Client *client,
470 struct GNUNET_MQ_Handle *mq)
472 struct TransportClient *tc;
474 tc = GNUNET_new (struct TransportClient);
477 GNUNET_CONTAINER_DLL_insert (clients_head,
480 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
481 "Client %p connected\n",
488 * Perform next action in the blacklist check.
490 * @param cls the `struct BlacklistCheck*`
493 do_blacklist_check (void *cls);
497 * Mark the peer as down so we don't call the continuation
498 * context in the future.
500 * @param cls a `struct TransportClient`
501 * @param peer a peer we are sending to
502 * @param value a `struct SendTransmitContinuationContext` to mark
503 * @return #GNUNET_OK (continue to iterate)
506 mark_match_down (void *cls,
507 const struct GNUNET_PeerIdentity *peer,
510 struct TransportClient *tc = cls;
511 struct SendTransmitContinuationContext *stcc = value;
515 stcc->down = GNUNET_YES;
523 * Called whenever a client is disconnected. Frees our
524 * resources associated with that client.
526 * @param cls closure, NULL
527 * @param client identification of the client
528 * @param app_ctx our `struct TransportClient`
531 client_disconnect_cb (void *cls,
532 struct GNUNET_SERVICE_Client *client,
535 struct TransportClient *tc = app_ctx;
536 struct GST_BlacklistCheck *bc;
538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
539 "Client %p disconnected, cleaning up.\n",
541 GNUNET_CONTAINER_multipeermap_iterate (active_stccs,
544 GNUNET_CONTAINER_DLL_remove (clients_head,
556 for (bc = bc_head; NULL != bc; bc = bc->next)
558 if (bc->bl_pos != tc)
560 bc->bl_pos = tc->next;
561 if (NULL == bc->task)
562 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
572 * Function called for each of our connected neighbours. Notify the
573 * client about the existing neighbour.
575 * @param cls the `struct TransportClient *` to notify
576 * @param peer identity of the neighbour
577 * @param address the address
578 * @param state the current state of the peer
579 * @param state_timeout the time out for the state
580 * @param bandwidth_in inbound bandwidth in NBO
581 * @param bandwidth_out outbound bandwidth in NBO
584 notify_client_about_neighbour (void *cls,
585 const struct GNUNET_PeerIdentity *peer,
586 const struct GNUNET_HELLO_Address *address,
587 enum GNUNET_TRANSPORT_PeerState state,
588 struct GNUNET_TIME_Absolute state_timeout,
589 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
590 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
592 struct TransportClient *tc = cls;
593 struct ConnectInfoMessage cim;
595 if (GNUNET_NO == GST_neighbours_test_connected (peer))
597 cim.header.size = htons (sizeof (struct ConnectInfoMessage));
598 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
600 cim.quota_in = bandwidth_in;
601 cim.quota_out = bandwidth_out;
609 * Initialize a normal client. We got a start message from this
610 * client, add him to the list of clients for broadcasting of inbound
613 * @param cls the client
614 * @param start the start message that was sent
617 handle_client_start (void *cls,
618 const struct StartMessage *start)
620 struct TransportClient *tc = cls;
621 const struct GNUNET_MessageHeader *hello;
624 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
625 "Client %p sent START\n",
627 options = ntohl (start->options);
628 if ((0 != (1 & options)) &&
630 memcmp (&start->self,
632 sizeof (struct GNUNET_PeerIdentity))))
634 /* client thinks this is a different peer, reject */
636 GNUNET_SERVICE_client_drop (tc->client);
639 if (CT_NONE != tc->type)
642 GNUNET_SERVICE_client_drop (tc->client);
645 if (0 != (2 & options))
647 hello = GST_hello_get ();
652 GST_neighbours_iterate (¬ify_client_about_neighbour,
654 GNUNET_SERVICE_client_continue (tc->client);
659 * Client sent us a HELLO. Check the request.
661 * @param cls the client
662 * @param message the HELLO message
665 check_client_hello (void *cls,
666 const struct GNUNET_MessageHeader *message)
668 return GNUNET_OK; /* FIXME: check here? */
673 * Client sent us a HELLO. Process the request.
675 * @param cls the client
676 * @param message the HELLO message
679 handle_client_hello (void *cls,
680 const struct GNUNET_MessageHeader *message)
682 struct TransportClient *tc = cls;
684 GST_validation_handle_hello (message);
685 GNUNET_SERVICE_client_continue (tc->client);
690 * Function called after the transmission is done. Notify the client that it is
691 * OK to send the next message.
694 * @param success #GNUNET_OK on success, #GNUNET_NO on failure, #GNUNET_SYSERR if we're not connected
695 * @param bytes_payload bytes payload sent
696 * @param bytes_on_wire bytes sent on wire
699 handle_send_transmit_continuation (void *cls,
701 size_t bytes_payload,
702 size_t bytes_on_wire)
704 struct SendTransmitContinuationContext *stcc = cls;
705 struct SendOkMessage send_ok_msg;
706 struct GNUNET_TIME_Relative delay;
707 const struct GNUNET_HELLO_Address *addr;
709 delay = GNUNET_TIME_absolute_get_duration (stcc->send_time);
710 addr = GST_neighbour_get_current_address (&stcc->target);
711 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
712 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
713 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
714 GNUNET_STRINGS_relative_time_to_string (delay,
716 (unsigned int) bytes_payload,
717 (unsigned int) bytes_on_wire,
718 GNUNET_i2s (&stcc->target),
720 (NULL != addr) ? addr->transport_name : "%");
722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
723 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
724 GNUNET_STRINGS_relative_time_to_string (delay,
726 (unsigned int) bytes_payload,
727 (unsigned int) bytes_on_wire,
728 GNUNET_i2s (&stcc->target),
730 (NULL != addr) ? addr->transport_name : "%");
732 if (GNUNET_NO == stcc->down)
734 /* Only send confirmation if we are still connected */
735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
736 "Sending SEND_OK for transmission request %llu\n",
738 send_ok_msg.header.size = htons (sizeof (send_ok_msg));
739 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
740 send_ok_msg.bytes_msg = htonl (bytes_payload);
741 send_ok_msg.bytes_physical = htonl (bytes_on_wire);
742 send_ok_msg.success = htonl (success);
743 send_ok_msg.peer = stcc->target;
748 GNUNET_assert (GNUNET_OK ==
749 GNUNET_CONTAINER_multipeermap_remove (active_stccs,
757 * Client asked for transmission to a peer. Process the request.
759 * @param cls the client
760 * @param obm the send message that was sent
763 check_client_send (void *cls,
764 const struct OutboundMessage *obm)
767 const struct GNUNET_MessageHeader *obmm;
769 size = ntohs (obm->header.size) - sizeof (struct OutboundMessage);
770 if (size < sizeof (struct GNUNET_MessageHeader))
773 return GNUNET_SYSERR;
775 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
776 if (size != ntohs (obmm->size))
779 return GNUNET_SYSERR;
786 * Client asked for transmission to a peer. Process the request.
788 * @param cls the client
789 * @param obm the send message that was sent
792 handle_client_send (void *cls,
793 const struct OutboundMessage *obm)
795 static unsigned long long uuid_gen;
796 struct TransportClient *tc = cls;
797 const struct GNUNET_MessageHeader *obmm;
798 struct SendTransmitContinuationContext *stcc;
800 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
801 if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer))
803 /* not connected, not allowed to send; can happen due to asynchronous operations */
804 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
805 "Could not send message to peer `%s': not connected\n",
806 GNUNET_i2s (&obm->peer));
807 GNUNET_STATISTICS_update (GST_stats,
809 ("# bytes payload dropped (other peer was not connected)"),
812 GNUNET_SERVICE_client_continue (tc->client);
815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
816 "Received SEND request %llu for `%s' and first message of type %u and total size %u\n",
818 GNUNET_i2s (&obm->peer),
821 GNUNET_SERVICE_client_continue (tc->client);
823 stcc = GNUNET_new (struct SendTransmitContinuationContext);
824 stcc->target = obm->peer;
826 stcc->send_time = GNUNET_TIME_absolute_get ();
827 stcc->uuid = uuid_gen++;
828 (void) GNUNET_CONTAINER_multipeermap_put (active_stccs,
831 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
832 GST_manipulation_send (&obm->peer,
835 GNUNET_TIME_relative_ntoh (obm->timeout),
836 &handle_send_transmit_continuation,
842 * Take the given address and append it to the set of results sent back to
843 * the client. This function may be called serveral times for a single
844 * conversion. The last invocation will be with a @a address of
845 * NULL and a @a res of #GNUNET_OK. Thus, to indicate conversion
846 * errors, the callback might be called first with @a address NULL and
847 * @a res being #GNUNET_SYSERR. In that case, there will still be a
848 * subsequent call later with @a address NULL and @a res #GNUNET_OK.
850 * @param cls the `struct AddressToStringContext`
851 * @param buf text to transmit (contains the human-readable address, or NULL)
852 * @param res #GNUNET_OK if conversion was successful, #GNUNET_SYSERR on error,
856 transmit_address_to_client (void *cls,
860 struct AddressToStringContext *actx = cls;
861 struct GNUNET_MQ_Envelope *env;
862 struct AddressToStringResultMessage *atsm;
865 GNUNET_assert ( (GNUNET_OK == res) ||
866 (GNUNET_SYSERR == res) );
869 env = GNUNET_MQ_msg (atsm,
870 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
871 if (GNUNET_OK == res)
873 /* this was the last call, transmit */
874 atsm->res = htonl (GNUNET_OK);
875 atsm->addr_len = htonl (0);
876 GNUNET_MQ_send (actx->tc->mq,
878 GNUNET_CONTAINER_DLL_remove (a2s_head,
883 if (GNUNET_SYSERR == res)
885 /* address conversion failed, but there will be more callbacks */
886 atsm->res = htonl (GNUNET_SYSERR);
887 atsm->addr_len = htonl (0);
888 GNUNET_MQ_send (actx->tc->mq,
893 GNUNET_assert (GNUNET_OK == res);
894 /* succesful conversion, append*/
895 slen = strlen (buf) + 1;
896 env = GNUNET_MQ_msg_extra (atsm,
898 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
899 atsm->res = htonl (GNUNET_YES);
900 atsm->addr_len = htonl (slen);
901 GNUNET_memcpy (&atsm[1],
904 GNUNET_MQ_send (actx->tc->mq,
910 * Client asked to resolve an address. Check the request.
912 * @param cls the client
913 * @param alum the resolution request
914 * @return #GNUNET_OK if @a alum is well-formed
917 check_client_address_to_string (void *cls,
918 const struct AddressLookupMessage *alum)
920 const char *plugin_name;
922 uint32_t address_len;
925 size = ntohs (alum->header.size);
926 address_len = ntohs (alum->addrlen);
927 if (size <= sizeof (struct AddressLookupMessage) + address_len)
930 return GNUNET_SYSERR;
932 address = (const char *) &alum[1];
933 plugin_name = (const char *) &address[address_len];
934 if ('\0' != plugin_name[size - sizeof (struct AddressLookupMessage) - address_len - 1])
937 return GNUNET_SYSERR;
944 * Client asked to resolve an address. Process the request.
946 * @param cls the client
947 * @param alum the resolution request
950 handle_client_address_to_string (void *cls,
951 const struct AddressLookupMessage *alum)
953 struct TransportClient *tc = cls;
954 struct GNUNET_TRANSPORT_PluginFunctions *papi;
955 const char *plugin_name;
957 uint32_t address_len;
958 struct AddressToStringContext *actx;
959 struct GNUNET_MQ_Envelope *env;
960 struct AddressToStringResultMessage *atsm;
961 struct GNUNET_TIME_Relative rtimeout;
964 address_len = ntohs (alum->addrlen);
965 address = (const char *) &alum[1];
966 plugin_name = (const char *) &address[address_len];
967 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
968 numeric = ntohs (alum->numeric_only);
969 papi = GST_plugins_printer_find (plugin_name);
972 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
973 "Failed to find plugin `%s'\n",
975 env = GNUNET_MQ_msg (atsm,
976 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
977 atsm->res = htonl (GNUNET_SYSERR);
978 atsm->addr_len = htonl (0);
979 GNUNET_MQ_send (tc->mq,
981 env = GNUNET_MQ_msg (atsm,
982 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
983 atsm->res = htonl (GNUNET_OK);
984 atsm->addr_len = htonl (0);
985 GNUNET_MQ_send (tc->mq,
989 actx = GNUNET_new (struct AddressToStringContext);
991 GNUNET_CONTAINER_DLL_insert (a2s_head,
994 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
995 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
996 "Pretty-printing address of %u bytes using plugin `%s'\n",
999 papi->address_pretty_printer (papi->cls,
1005 &transmit_address_to_client,
1011 * Compose #PeerIterateResponseMessage using the given peer and address.
1013 * @param peer identity of the peer
1014 * @param address the address, NULL on disconnect
1015 * @return composed message
1017 static struct PeerIterateResponseMessage *
1018 compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer,
1019 const struct GNUNET_HELLO_Address *address)
1021 struct PeerIterateResponseMessage *msg;
1027 GNUNET_assert (NULL != peer);
1028 if (NULL != address)
1030 tlen = strlen (address->transport_name) + 1;
1031 alen = address->address_length;
1038 size = (sizeof (struct PeerIterateResponseMessage) + alen + tlen);
1039 msg = GNUNET_malloc (size);
1040 msg->header.size = htons (size);
1042 = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE);
1043 msg->reserved = htonl (0);
1045 msg->addrlen = htonl (alen);
1046 msg->pluginlen = htonl (tlen);
1048 if (NULL != address)
1050 msg->local_address_info = htonl((uint32_t) address->local_info);
1051 addr = (char *) &msg[1];
1052 GNUNET_memcpy (addr,
1055 GNUNET_memcpy (&addr[alen],
1056 address->transport_name,
1064 * Context for #send_validation_information() and
1065 * #send_peer_information().
1067 struct IterationContext
1070 * Context to use for the transmission.
1072 struct TransportClient *tc;
1075 * Which peers do we care about?
1077 struct GNUNET_PeerIdentity id;
1080 * #GNUNET_YES if @e id should be ignored because we want all peers.
1087 * Output information of neighbours to the given client.
1089 * @param cls the `struct PeerIterationContext *`
1090 * @param peer identity of the neighbour
1091 * @param address the address
1092 * @param state current state this peer is in
1093 * @param state_timeout timeout for the current state of the peer
1094 * @param bandwidth_in inbound quota in NBO
1095 * @param bandwidth_out outbound quota in NBO
1098 send_peer_information (void *cls,
1099 const struct GNUNET_PeerIdentity *peer,
1100 const struct GNUNET_HELLO_Address *address,
1101 enum GNUNET_TRANSPORT_PeerState state,
1102 struct GNUNET_TIME_Absolute state_timeout,
1103 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1104 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1106 struct IterationContext *pc = cls;
1107 struct GNUNET_MQ_Envelope *env;
1108 struct PeerIterateResponseMessage *msg;
1110 if ( (GNUNET_YES != pc->all) &&
1115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1116 "Sending information about `%s' using address `%s' in state `%s'\n",
1118 (NULL != address) ? GST_plugins_a2s (address) : "<none>",
1119 GNUNET_TRANSPORT_ps2s (state));
1120 msg = compose_address_iterate_response_message (peer,
1122 msg->state = htonl (state);
1123 msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout);
1124 env = GNUNET_MQ_msg_copy (&msg->header);
1126 GNUNET_MQ_send (pc->tc->mq,
1132 * Client asked to obtain information about a specific or all peers
1133 * Process the request.
1135 * @param cls the client
1136 * @param msg the peer address information request
1139 handle_client_monitor_peers (void *cls,
1140 const struct PeerMonitorMessage *msg)
1142 struct TransportClient *tc = cls;
1143 struct IterationContext pc;
1145 if (CT_NONE != tc->type)
1148 GNUNET_SERVICE_client_drop (tc->client);
1151 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1152 GNUNET_SERVICE_client_mark_monitor (tc->client);
1154 /* Send initial list */
1156 if (0 == memcmp (&msg->peer,
1158 sizeof (struct GNUNET_PeerIdentity)))
1160 /* iterate over all neighbours */
1161 pc.all = GNUNET_YES;
1166 /* just return one neighbour */
1170 GST_neighbours_iterate (&send_peer_information,
1173 if (GNUNET_YES != ntohl (msg->one_shot))
1175 tc->details.monitor_peer = msg->peer;
1176 tc->type = CT_MONITOR;
1177 if (0 != memcmp (&msg->peer,
1179 sizeof (struct GNUNET_PeerIdentity)))
1180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1181 "Client %p started monitoring of the peer `%s'\n",
1183 GNUNET_i2s (&msg->peer));
1185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1186 "Client %p started monitoring all peers\n",
1191 struct GNUNET_MessageHeader *msg;
1192 struct GNUNET_MQ_Envelope *env;
1194 env = GNUNET_MQ_msg (msg,
1195 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END);
1196 GNUNET_MQ_send (tc->mq,
1203 * Function called by the plugin with information about the
1204 * current sessions managed by the plugin (for monitoring).
1206 * @param cls closure
1207 * @param session session handle this information is about,
1208 * NULL to indicate that we are "in sync" (initial
1209 * iteration complete)
1210 * @param info information about the state of the session,
1211 * NULL if @a session is also NULL and we are
1212 * merely signalling that the initial iteration is over
1215 plugin_session_info_cb (void *cls,
1216 struct GNUNET_ATS_Session *session,
1217 const struct GNUNET_TRANSPORT_SessionInfo *info)
1219 struct GNUNET_MQ_Envelope *env;
1220 struct TransportPluginMonitorMessage *msg;
1221 struct GNUNET_MessageHeader *sync;
1228 if (0 == GNUNET_notification_context_get_size (plugin_nc))
1230 GST_plugins_monitor_subscribe (NULL,
1234 if ( (NULL == info) &&
1237 /* end of initial iteration */
1238 if (NULL != sync_client)
1240 env = GNUNET_MQ_msg (sync,
1241 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC);
1242 GNUNET_MQ_send (sync_client->mq,
1248 GNUNET_assert (NULL != info);
1249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1250 "Plugin event for peer %s on transport %s\n",
1251 GNUNET_i2s (&info->address->peer),
1252 info->address->transport_name);
1253 slen = strlen (info->address->transport_name) + 1;
1254 alen = info->address->address_length;
1255 size = sizeof (struct TransportPluginMonitorMessage) + slen + alen;
1256 if (size > UINT16_MAX)
1261 msg = GNUNET_malloc (size);
1262 msg->header.size = htons (size);
1263 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT);
1264 msg->session_state = htons ((uint16_t) info->state);
1265 msg->is_inbound = htons ((int16_t) info->is_inbound);
1266 msg->msgs_pending = htonl (info->num_msg_pending);
1267 msg->bytes_pending = htonl (info->num_bytes_pending);
1268 msg->timeout = GNUNET_TIME_absolute_hton (info->session_timeout);
1269 msg->delay = GNUNET_TIME_absolute_hton (info->receive_delay);
1270 msg->peer = info->address->peer;
1271 msg->session_id = (uint64_t) (intptr_t) session;
1272 msg->plugin_name_len = htons (slen);
1273 msg->plugin_address_len = htons (alen);
1274 name = (char *) &msg[1];
1275 GNUNET_memcpy (name,
1276 info->address->transport_name,
1279 GNUNET_memcpy (addr,
1280 info->address->address,
1282 if (NULL != sync_client)
1284 struct GNUNET_MQ_Envelope *env;
1286 env = GNUNET_MQ_msg_copy (&msg->header);
1287 GNUNET_MQ_send (sync_client->mq,
1292 GNUNET_notification_context_broadcast (plugin_nc,
1301 * Client asked to obtain information about all plugin connections.
1303 * @param cls the client
1304 * @param message the peer address information request
1307 handle_client_monitor_plugins (void *cls,
1308 const struct GNUNET_MessageHeader *message)
1310 struct TransportClient *tc = cls;
1312 GNUNET_SERVICE_client_mark_monitor (tc->client);
1313 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1314 GNUNET_notification_context_add (plugin_nc,
1316 GNUNET_assert (NULL == sync_client);
1318 GST_plugins_monitor_subscribe (&plugin_session_info_cb,
1324 * Broadcast the given message to all of our clients.
1326 * @param msg message to broadcast
1327 * @param may_drop #GNUNET_YES if the message can be dropped / is payload
1330 GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
1333 struct TransportClient *tc;
1336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1337 "Asked to broadcast message of type %u with %u bytes\n",
1338 (unsigned int) ntohs (msg->type),
1339 (unsigned int) ntohs (msg->size));
1341 for (tc = clients_head; NULL != tc; tc = tc->next)
1343 if ( (GNUNET_YES == may_drop) &&
1344 (CT_CORE != tc->type) )
1345 continue; /* skip, this client does not care about payload */
1351 if (GNUNET_NO == done)
1352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1353 "Message of type %u not delivered, is CORE service up?\n",
1359 * Broadcast the new active address to all clients monitoring the peer.
1361 * @param peer peer this update is about (never NULL)
1362 * @param address address, NULL on disconnect
1363 * @param state the current state of the peer
1364 * @param state_timeout the time out for the state
1367 GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer,
1368 const struct GNUNET_HELLO_Address *address,
1369 enum GNUNET_TRANSPORT_PeerState state,
1370 struct GNUNET_TIME_Absolute state_timeout)
1372 struct GNUNET_MQ_Envelope *env;
1373 struct PeerIterateResponseMessage *msg;
1374 struct TransportClient *tc;
1376 msg = compose_address_iterate_response_message (peer,
1378 msg->state = htonl (state);
1379 msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout);
1380 for (tc = clients_head; NULL != tc; tc = tc->next)
1382 if (CT_MONITOR != tc->type)
1384 if ((0 == memcmp (&tc->details.monitor_peer,
1386 sizeof (struct GNUNET_PeerIdentity))) ||
1387 (0 == memcmp (&tc->details.monitor_peer,
1389 sizeof (struct GNUNET_PeerIdentity))))
1391 env = GNUNET_MQ_msg_copy (&msg->header);
1392 GNUNET_MQ_send (tc->mq,
1401 * Mark the peer as down so we don't call the continuation
1402 * context in the future.
1405 * @param peer peer that got disconnected
1406 * @param value a `struct SendTransmitContinuationContext` to mark
1407 * @return #GNUNET_OK (continue to iterate)
1410 mark_peer_down (void *cls,
1411 const struct GNUNET_PeerIdentity *peer,
1414 struct SendTransmitContinuationContext *stcc = value;
1416 stcc->down = GNUNET_YES;
1422 * Notify all clients about a disconnect, and cancel
1423 * pending SEND_OK messages for this peer.
1425 * @param peer peer that disconnected
1428 GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer)
1430 struct DisconnectInfoMessage disconnect_msg;
1432 GNUNET_CONTAINER_multipeermap_get_multiple (active_stccs,
1436 disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage));
1437 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
1438 disconnect_msg.reserved = htonl (0);
1439 disconnect_msg.peer = *peer;
1440 GST_clients_broadcast (&disconnect_msg.header,
1447 * Transmit our HELLO message to the given (connected) neighbour.
1449 * @param cls the 'HELLO' message
1450 * @param peer identity of the peer
1451 * @param address the address
1452 * @param state current state this peer is in
1453 * @param state_timeout timeout for the current state of the peer
1454 * @param bandwidth_in inbound quota in NBO
1455 * @param bandwidth_out outbound quota in NBO
1458 transmit_our_hello (void *cls,
1459 const struct GNUNET_PeerIdentity *peer,
1460 const struct GNUNET_HELLO_Address *address,
1461 enum GNUNET_TRANSPORT_PeerState state,
1462 struct GNUNET_TIME_Absolute state_timeout,
1463 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1464 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1466 const struct GNUNET_MessageHeader *hello = cls;
1471 sizeof (struct GNUNET_PeerIdentity)))
1472 return; /* not to ourselves */
1473 if (GNUNET_NO == GST_neighbours_test_connected (peer))
1476 GST_neighbours_send (peer,
1478 ntohs (hello->size),
1486 * My HELLO has changed. Tell everyone who should know.
1489 * @param hello new HELLO
1492 process_hello_update (void *cls,
1493 const struct GNUNET_MessageHeader *hello)
1495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1496 "Broadcasting HELLO to clients\n");
1497 GST_clients_broadcast (hello, GNUNET_NO);
1498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1499 "Broadcasting HELLO to neighbours\n");
1500 GST_neighbours_iterate (&transmit_our_hello,
1506 * We received some payload. Prepare to pass it on to our clients.
1508 * @param address address and (claimed) identity of the other peer
1509 * @param session identifier used for this session (NULL for plugins
1510 * that do not offer bi-directional communication to the sender
1511 * using the same "connection")
1512 * @param message the message to process
1513 * @return how long the plugin should wait until receiving more data
1515 static struct GNUNET_TIME_Relative
1516 process_payload (const struct GNUNET_HELLO_Address *address,
1517 struct GNUNET_ATS_Session *session,
1518 const struct GNUNET_MessageHeader *message)
1520 struct GNUNET_TIME_Relative ret;
1522 struct InboundMessage *im;
1523 size_t msg_size = ntohs (message->size);
1524 size_t size = sizeof(struct InboundMessage) + msg_size;
1525 char buf[size] GNUNET_ALIGN;
1527 do_forward = GNUNET_SYSERR;
1528 ret = GST_neighbours_calculate_receive_delay (&address->peer,
1531 if (! GST_neighbours_test_connected (&address->peer))
1533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1534 "Discarded %u bytes type %u payload from peer `%s'\n",
1535 (unsigned int) msg_size,
1536 ntohs (message->type),
1537 GNUNET_i2s (&address->peer));
1538 GNUNET_STATISTICS_update (GST_stats, gettext_noop
1539 ("# bytes payload discarded due to not connected peer"),
1545 if (GNUNET_YES != do_forward)
1547 im = (struct InboundMessage *) buf;
1548 im->header.size = htons (size);
1549 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
1550 im->peer = address->peer;
1551 GNUNET_memcpy (&im[1],
1553 ntohs (message->size));
1554 GST_clients_broadcast (&im->header,
1561 * Task to asynchronously terminate a session.
1563 * @param cls the `struct GNUNET_ATS_SessionKiller` with the information for the kill
1566 kill_session_task (void *cls)
1568 struct GNUNET_ATS_SessionKiller *sk = cls;
1571 GNUNET_CONTAINER_DLL_remove (sk_head,
1574 sk->plugin->disconnect_session (sk->plugin->cls,
1581 * Force plugin to terminate session due to communication
1584 * @param plugin_name name of the plugin
1585 * @param session session to termiante
1588 kill_session (const char *plugin_name,
1589 struct GNUNET_ATS_Session *session)
1591 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
1592 struct GNUNET_ATS_SessionKiller *sk;
1594 for (sk = sk_head; NULL != sk; sk = sk->next)
1595 if (sk->session == session)
1597 plugin = GST_plugins_find (plugin_name);
1603 /* need to issue disconnect asynchronously */
1604 sk = GNUNET_new (struct GNUNET_ATS_SessionKiller);
1605 sk->session = session;
1606 sk->plugin = plugin;
1607 sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task,
1609 GNUNET_CONTAINER_DLL_insert (sk_head,
1616 * Black list check result for try_connect call
1617 * If connection to the peer is allowed request adddress and ???
1619 * @param cls the message
1620 * @param peer the peer
1621 * @param address the address
1622 * @param session the session
1623 * @param result the result
1626 connect_bl_check_cont (void *cls,
1627 const struct GNUNET_PeerIdentity *peer,
1628 const struct GNUNET_HELLO_Address *address,
1629 struct GNUNET_ATS_Session *session,
1632 struct GNUNET_MessageHeader *msg = cls;
1634 if (GNUNET_OK == result)
1636 /* Blacklist allows to speak to this peer, forward SYN to neighbours */
1637 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1638 "Received SYN message from peer `%s' at `%s'\n",
1640 GST_plugins_a2s (address));
1642 GST_neighbours_handle_session_syn (msg,
1645 GST_blacklist_abort_matching (address,
1647 kill_session (address->transport_name,
1654 if (GNUNET_SYSERR == result)
1655 return; /* check was aborted, session destroyed */
1656 /* Blacklist denies to speak to this peer */
1657 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1658 "Discarding SYN message from `%s' due to denied blacklist check\n",
1660 kill_session (address->transport_name,
1666 * Function called by the transport for each received message.
1668 * @param cls closure, const char* with the name of the plugin we received the message from
1669 * @param address address and (claimed) identity of the other peer
1670 * @param message the message, NULL if we only care about
1671 * learning about the delay until we should receive again
1672 * @param session identifier used for this session (NULL for plugins
1673 * that do not offer bi-directional communication to the sender
1674 * using the same "connection")
1675 * @return how long the plugin should wait until receiving more data
1676 * (plugins that do not support this, can ignore the return value)
1678 struct GNUNET_TIME_Relative
1679 GST_receive_callback (void *cls,
1680 const struct GNUNET_HELLO_Address *address,
1681 struct GNUNET_ATS_Session *session,
1682 const struct GNUNET_MessageHeader *message)
1684 const char *plugin_name = cls;
1685 struct GNUNET_TIME_Relative ret;
1688 ret = GNUNET_TIME_UNIT_ZERO;
1689 if (NULL == message)
1691 type = ntohs (message->type);
1692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1693 "Received message with type %u from peer `%s' at %s\n",
1695 GNUNET_i2s (&address->peer),
1696 GST_plugins_a2s (address));
1698 GNUNET_STATISTICS_update (GST_stats,
1699 gettext_noop ("# bytes total received"),
1700 ntohs (message->size),
1702 GST_neighbours_notify_data_recv (address,
1706 case GNUNET_MESSAGE_TYPE_HELLO_LEGACY:
1707 /* Legacy HELLO message, discard */
1709 case GNUNET_MESSAGE_TYPE_HELLO:
1710 if (GNUNET_OK != GST_validation_handle_hello (message))
1712 GNUNET_break_op (0);
1713 GST_blacklist_abort_matching (address,
1717 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
1718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1719 "Processing PING from `%s'\n",
1720 GST_plugins_a2s (address));
1722 GST_validation_handle_ping (&address->peer,
1727 GST_blacklist_abort_matching (address,
1729 kill_session (plugin_name,
1733 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
1734 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1735 "Processing PONG from `%s'\n",
1736 GST_plugins_a2s (address));
1738 GST_validation_handle_pong (&address->peer,
1741 GNUNET_break_op (0);
1742 GST_blacklist_abort_matching (address,
1744 kill_session (plugin_name, session);
1747 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN:
1748 /* Do blacklist check if communication with this peer is allowed */
1749 (void) GST_blacklist_test_allowed (&address->peer,
1751 &connect_bl_check_cont,
1752 GNUNET_copy_message (message),
1756 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK:
1758 GST_neighbours_handle_session_syn_ack (message,
1762 GST_blacklist_abort_matching (address, session);
1763 kill_session (plugin_name, session);
1766 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
1768 GST_neighbours_handle_session_ack (message,
1773 GST_blacklist_abort_matching (address, session);
1774 kill_session (plugin_name, session);
1777 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
1778 GST_neighbours_handle_disconnect_message (&address->peer,
1781 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA:
1782 GST_neighbours_handle_quota_message (&address->peer,
1785 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
1786 GST_neighbours_keepalive (&address->peer,
1789 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE:
1790 GST_neighbours_keepalive_response (&address->peer,
1794 /* should be payload */
1795 GNUNET_STATISTICS_update (GST_stats,
1796 gettext_noop ("# bytes payload received"),
1797 ntohs (message->size),
1799 ret = process_payload (address,
1805 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1806 "Allowing receive from peer %s to continue in %s\n",
1807 GNUNET_i2s (&address->peer),
1808 GNUNET_STRINGS_relative_time_to_string (ret,
1815 * Function that will be called for each address the transport
1816 * is aware that it might be reachable under. Update our HELLO.
1818 * @param cls name of the plugin (const char*)
1819 * @param add_remove should the address added (YES) or removed (NO) from the
1820 * set of valid addresses?
1821 * @param address the address to add or remove
1824 plugin_env_address_change_notification (void *cls,
1826 const struct GNUNET_HELLO_Address *address)
1828 static int addresses = 0;
1830 if (GNUNET_YES == add_remove)
1833 GNUNET_STATISTICS_update (GST_stats,
1834 "# transport addresses",
1838 else if (GNUNET_NO == add_remove)
1847 GNUNET_STATISTICS_update (GST_stats,
1848 "# transport addresses",
1853 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1854 "Transport now has %u addresses to communicate\n",
1856 GST_hello_modify_addresses (add_remove,
1862 * Function that will be called whenever the plugin internally
1863 * cleans up a session pointer and hence the service needs to
1864 * discard all of those sessions as well. Plugins that do not
1865 * use sessions can simply omit calling this function and always
1866 * use NULL wherever a session pointer is needed. This function
1867 * should be called BEFORE a potential "TransmitContinuation"
1868 * from the "TransmitFunction".
1870 * @param cls closure
1871 * @param address which address was the session for
1872 * @param session which session is being destoyed
1875 plugin_env_session_end (void *cls,
1876 const struct GNUNET_HELLO_Address *address,
1877 struct GNUNET_ATS_Session *session)
1879 struct GNUNET_ATS_SessionKiller *sk;
1881 if (NULL == address)
1886 if (NULL == session)
1891 GNUNET_assert (strlen (address->transport_name) > 0);
1893 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1894 "Notification from plugin about terminated session %p from peer `%s' address `%s'\n",
1896 GNUNET_i2s (&address->peer),
1897 GST_plugins_a2s (address));
1899 GST_neighbours_session_terminated (&address->peer,
1901 GST_ats_del_session (address,
1903 GST_blacklist_abort_matching (address,
1906 for (sk = sk_head; NULL != sk; sk = sk->next)
1908 if (sk->session == session)
1910 GNUNET_CONTAINER_DLL_remove (sk_head,
1913 GNUNET_SCHEDULER_cancel (sk->task);
1922 * Black list check result from blacklist check triggered when a
1923 * plugin gave us a new session in #plugin_env_session_start(). If
1924 * connection to the peer is disallowed, kill the session.
1927 * @param peer the peer
1928 * @param address address associated with the request
1929 * @param session session associated with the request
1930 * @param result the result
1933 plugin_env_session_start_bl_check_cont (void *cls,
1934 const struct GNUNET_PeerIdentity *peer,
1935 const struct GNUNET_HELLO_Address *address,
1936 struct GNUNET_ATS_Session *session,
1939 if (GNUNET_OK != result)
1941 kill_session (address->transport_name,
1946 GNUNET_HELLO_address_check_option (address,
1947 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1949 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1950 "Informing verifier about inbound session's address `%s'\n",
1951 GST_plugins_a2s (address));
1952 GST_validation_handle_address (address);
1958 * Plugin tells transport service about a new inbound session
1961 * @param address the address
1962 * @param session the new session
1963 * @param scope network scope information
1966 plugin_env_session_start (void *cls,
1967 const struct GNUNET_HELLO_Address *address,
1968 struct GNUNET_ATS_Session *session,
1969 enum GNUNET_ATS_Network_Type scope)
1971 struct GNUNET_ATS_Properties prop;
1973 if (NULL == address)
1978 if (NULL == session)
1983 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1984 "Notification from plugin `%s' about new session from peer `%s' address `%s'\n",
1985 address->transport_name,
1986 GNUNET_i2s (&address->peer),
1987 GST_plugins_a2s (address));
1989 GNUNET_HELLO_address_check_option (address,
1990 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1992 /* inbound is always new, but outbound MAY already be known, but
1993 for example for UNIX, we have symmetric connections and thus we
1994 may not know the address yet; add if necessary! */
1995 /* FIXME: maybe change API here so we just pass scope? */
1999 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != scope);
2001 GST_ats_add_inbound_address (address,
2005 /* Do blacklist check if communication with this peer is allowed */
2006 (void) GST_blacklist_test_allowed (&address->peer,
2007 address->transport_name,
2008 &plugin_env_session_start_bl_check_cont,
2016 * Function called by ATS to notify the callee that the
2017 * assigned bandwidth or address for a given peer was changed. If the
2018 * callback is called with address/bandwidth assignments of zero, the
2019 * ATS disconnect function will still be called once the disconnect
2020 * actually happened.
2022 * @param cls closure
2023 * @param peer the peer this address is intended for
2024 * @param address address to use (for peer given in address)
2025 * @param session session to use (if available)
2026 * @param bandwidth_out assigned outbound bandwidth for the connection in NBO,
2027 * 0 to disconnect from peer
2028 * @param bandwidth_in assigned inbound bandwidth for the connection in NBO,
2029 * 0 to disconnect from peer
2030 * @param ats ATS information
2031 * @param ats_count number of @a ats elements
2034 ats_request_address_change (void *cls,
2035 const struct GNUNET_PeerIdentity *peer,
2036 const struct GNUNET_HELLO_Address *address,
2037 struct GNUNET_ATS_Session *session,
2038 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
2039 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
2041 uint32_t bw_in = ntohl (bandwidth_in.value__);
2042 uint32_t bw_out = ntohl (bandwidth_out.value__);
2046 /* ATS service died, all suggestions become invalid!
2047 (but we'll keep using the allocations for a little
2048 while, to keep going while ATS restarts) */
2049 /* FIXME: We should drop all
2050 connections now, as ATS won't explicitly tell
2051 us and be unaware of ongoing resource allocations! */
2054 /* ATS tells me to disconnect from peer */
2055 if ((0 == bw_in) && (0 == bw_out))
2057 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2058 "ATS tells me to disconnect from peer `%s'\n",
2060 GST_neighbours_force_disconnect (peer);
2063 GNUNET_assert (NULL != address);
2064 GNUNET_STATISTICS_update (GST_stats,
2065 "# ATS suggestions received",
2068 GST_neighbours_switch_to_address (address,
2076 * Closure for #test_connection_ok().
2078 struct TestConnectionContext
2081 * Is this the first neighbour we're checking?
2086 * Handle to the blacklisting client we need to ask.
2088 struct TransportClient *tc;
2093 * Got the result about an existing connection from a new blacklister.
2094 * Shutdown the neighbour if necessary.
2097 * @param peer the neighbour that was investigated
2098 * @param address address associated with the request
2099 * @param session session associated with the request
2100 * @param allowed #GNUNET_OK if we can keep it,
2101 * #GNUNET_NO if we must shutdown the connection
2104 confirm_or_drop_neighbour (void *cls,
2105 const struct GNUNET_PeerIdentity *peer,
2106 const struct GNUNET_HELLO_Address *address,
2107 struct GNUNET_ATS_Session *session,
2110 if (GNUNET_OK == allowed)
2111 return; /* we're done */
2112 GNUNET_STATISTICS_update (GST_stats,
2113 gettext_noop ("# disconnects due to blacklist"),
2116 GST_neighbours_force_disconnect (peer);
2121 * Test if an existing connection is still acceptable given a new
2122 * blacklisting client.
2124 * @param cls the `struct TestConnectionContext *`
2125 * @param peer identity of the peer
2126 * @param address the address
2127 * @param state current state this peer is in
2128 * @param state_timeout timeout for the current state of the peer
2129 * @param bandwidth_in bandwidth assigned inbound
2130 * @param bandwidth_out bandwidth assigned outbound
2133 test_connection_ok (void *cls,
2134 const struct GNUNET_PeerIdentity *peer,
2135 const struct GNUNET_HELLO_Address *address,
2136 enum GNUNET_TRANSPORT_PeerState state,
2137 struct GNUNET_TIME_Absolute state_timeout,
2138 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
2139 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2141 struct TestConnectionContext *tcc = cls;
2142 struct GST_BlacklistCheck *bc;
2144 bc = GNUNET_new (struct GST_BlacklistCheck);
2145 GNUNET_CONTAINER_DLL_insert (bc_head,
2149 bc->address = GNUNET_HELLO_address_copy (address);
2150 bc->cont = &confirm_or_drop_neighbour;
2151 bc->cont_cls = NULL;
2152 bc->bl_pos = tcc->tc;
2153 if (GNUNET_YES == tcc->first)
2155 /* all would wait for the same client, no need to
2156 * create more than just the first task right now */
2157 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
2159 tcc->first = GNUNET_NO;
2165 * Initialize a blacklisting client. We got a blacklist-init
2166 * message from this client, add him to the list of clients
2167 * to query for blacklisting.
2169 * @param cls the client
2170 * @param message the blacklist-init message that was sent
2173 handle_client_blacklist_init (void *cls,
2174 const struct GNUNET_MessageHeader *message)
2176 struct TransportClient *tc = cls;
2177 struct TestConnectionContext tcc;
2179 if (CT_NONE != tc->type)
2182 GNUNET_SERVICE_client_drop (tc->client);
2185 GNUNET_SERVICE_client_mark_monitor (tc->client);
2186 tc->type = CT_BLACKLIST;
2187 tc->details.blacklist.call_receive_done = GNUNET_YES;
2188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2189 "New blacklist client %p\n",
2191 /* confirm that all existing connections are OK! */
2193 tcc.first = GNUNET_YES;
2194 GST_neighbours_iterate (&test_connection_ok,
2200 * Free the given entry in the blacklist.
2203 * @param key host identity (unused)
2204 * @param value the blacklist entry
2205 * @return #GNUNET_OK (continue to iterate)
2208 free_blacklist_entry (void *cls,
2209 const struct GNUNET_PeerIdentity *key,
2214 GNUNET_free_non_null (be);
2220 * Set traffic metric to manipulate
2222 * @param cls closure
2223 * @param message containing information
2226 handle_client_set_metric (void *cls,
2227 const struct TrafficMetricMessage *tm)
2229 struct TransportClient *tc = cls;
2231 GST_manipulation_set_metric (tm);
2232 GNUNET_SERVICE_client_continue (tc->client);
2237 * Function called when the service shuts down. Unloads our plugins
2238 * and cancels pending validations.
2240 * @param cls closure, unused
2243 shutdown_task (void *cls)
2245 struct AddressToStringContext *cur;
2247 GST_neighbours_stop ();
2248 GST_plugins_unload ();
2249 GST_validation_stop ();
2251 GNUNET_ATS_scheduling_done (GST_ats);
2253 GNUNET_ATS_connectivity_done (GST_ats_connect);
2254 GST_ats_connect = NULL;
2255 GNUNET_ATS_scanner_done (GST_is);
2257 while (NULL != (cur = a2s_head))
2259 GNUNET_CONTAINER_DLL_remove (a2s_head,
2264 if (NULL != plugin_nc)
2266 GNUNET_notification_context_destroy (plugin_nc);
2269 GNUNET_CONTAINER_multipeermap_destroy (active_stccs);
2270 active_stccs = NULL;
2271 if (NULL != blacklist)
2273 GNUNET_CONTAINER_multipeermap_iterate (blacklist,
2274 &free_blacklist_entry,
2276 GNUNET_CONTAINER_multipeermap_destroy (blacklist);
2280 GST_manipulation_stop ();
2282 if (NULL != GST_peerinfo)
2284 GNUNET_PEERINFO_disconnect (GST_peerinfo);
2285 GST_peerinfo = NULL;
2287 if (NULL != GST_stats)
2289 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
2292 if (NULL != GST_my_private_key)
2294 GNUNET_free (GST_my_private_key);
2295 GST_my_private_key = NULL;
2301 * Perform next action in the blacklist check.
2303 * @param cls the `struct GST_BlacklistCheck *`
2306 do_blacklist_check (void *cls)
2308 struct GST_BlacklistCheck *bc = cls;
2309 struct TransportClient *tc;
2310 struct GNUNET_MQ_Envelope *env;
2311 struct BlacklistMessage *bm;
2314 while (NULL != (tc = bc->bl_pos))
2316 if (CT_BLACKLIST == tc->type)
2318 bc->bl_pos = tc->next;
2322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2323 "No other blacklist clients active, will allow neighbour `%s'\n",
2324 GNUNET_i2s (&bc->peer));
2326 bc->cont (bc->cont_cls,
2331 GST_blacklist_test_cancel (bc);
2334 if ( (NULL != tc->details.blacklist.bc) ||
2335 (GNUNET_NO != tc->details.blacklist.waiting_for_reply) )
2336 return; /* someone else busy with this client */
2337 tc->details.blacklist.bc = bc;
2338 env = GNUNET_MQ_msg (bm,
2339 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY);
2340 bm->is_allowed = htonl (0);
2341 bm->peer = bc->peer;
2342 GNUNET_MQ_send (tc->mq,
2344 if (GNUNET_YES == tc->details.blacklist.call_receive_done)
2346 tc->details.blacklist.call_receive_done = GNUNET_NO;
2347 GNUNET_SERVICE_client_continue (tc->client);
2349 tc->details.blacklist.waiting_for_reply = GNUNET_YES;
2354 * A blacklisting client has sent us reply. Process it.
2356 * @param cls the client
2357 * @param msg the blacklist-reply message that was sent
2360 handle_client_blacklist_reply (void *cls,
2361 const struct BlacklistMessage *msg)
2363 struct TransportClient *tc = cls;
2364 struct GST_BlacklistCheck *bc;
2366 if (CT_BLACKLIST != tc->type)
2369 GNUNET_SERVICE_client_drop (tc->client);
2372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2373 "Blacklist client %p sent reply for `%s'\n",
2375 GNUNET_i2s (&msg->peer));
2376 bc = tc->details.blacklist.bc;
2377 tc->details.blacklist.bc = NULL;
2378 tc->details.blacklist.waiting_for_reply = GNUNET_NO;
2379 tc->details.blacklist.call_receive_done = GNUNET_YES;
2382 /* only run this if the blacklist check has not been
2383 * cancelled in the meantime... */
2384 GNUNET_assert (bc->bl_pos == tc);
2385 if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
2387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2388 "Blacklist check failed, peer not allowed\n");
2389 /* For the duration of the continuation, make the ongoing
2390 check invisible (to avoid double-cancellation); then
2391 add it back again so we can re-use GST_blacklist_test_cancel() */
2392 GNUNET_CONTAINER_DLL_remove (bc_head,
2395 bc->cont (bc->cont_cls,
2400 GNUNET_CONTAINER_DLL_insert (bc_head,
2403 GST_blacklist_test_cancel (bc);
2404 tc->details.blacklist.call_receive_done = GNUNET_NO;
2405 GNUNET_SERVICE_client_continue (tc->client);
2410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2411 "Blacklist check succeeded, continuing with checks\n");
2412 tc->details.blacklist.call_receive_done = GNUNET_NO;
2413 GNUNET_SERVICE_client_continue (tc->client);
2414 bc->bl_pos = tc->next;
2415 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
2419 /* check if any other blacklist checks are waiting for this blacklister */
2420 for (bc = bc_head; bc != NULL; bc = bc->next)
2421 if ( (bc->bl_pos == tc) &&
2422 (NULL == bc->task) )
2424 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
2432 * Add the given peer to the blacklist (for the given transport).
2434 * @param peer peer to blacklist
2435 * @param transport_name transport to blacklist for this peer, NULL for all
2438 GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
2439 const char *transport_name)
2441 char *transport = NULL;
2443 if (NULL != transport_name)
2445 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2446 "Adding peer `%s' with plugin `%s' to blacklist\n",
2449 transport = GNUNET_strdup (transport_name);
2452 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2453 "Adding peer `%s' with all plugins to blacklist\n",
2455 if (NULL == blacklist)
2457 GNUNET_CONTAINER_multipeermap_create (TRANSPORT_BLACKLIST_HT_SIZE,
2460 GNUNET_CONTAINER_multipeermap_put (blacklist,
2463 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2468 * Abort blacklist if @a address and @a session match.
2470 * @param address address used to abort matching checks
2471 * @param session session used to abort matching checks
2474 GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
2475 struct GNUNET_ATS_Session *session)
2477 struct GST_BlacklistCheck *bc;
2478 struct GST_BlacklistCheck *n;
2481 while (NULL != (bc = n))
2484 if ( (bc->session == session) &&
2485 (0 == GNUNET_HELLO_address_cmp (bc->address,
2488 bc->cont (bc->cont_cls,
2493 GST_blacklist_test_cancel (bc);
2500 * Test if the given blacklist entry matches. If so,
2501 * abort the iteration.
2503 * @param cls the transport name to match (const char*)
2504 * @param key the key (unused)
2505 * @param value the 'char *' (name of a blacklisted transport)
2506 * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches
2509 test_blacklisted (void *cls,
2510 const struct GNUNET_PeerIdentity *key,
2513 const char *transport_name = cls;
2516 /* Blacklist entry be:
2517 * (NULL == be): peer is blacklisted with all plugins
2518 * (NULL != be): peer is blacklisted for a specific plugin
2520 * If (NULL != transport_name) we look for a transport specific entry:
2521 * if (transport_name == be) forbidden
2525 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2526 "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n",
2528 (NULL == transport_name) ? "unspecified" : transport_name,
2529 (NULL == be) ? "all plugins" : be);
2530 /* all plugins for this peer were blacklisted: disallow */
2534 /* blacklist check for specific transport */
2535 if ( (NULL != transport_name) &&
2538 if (0 == strcmp (transport_name,
2540 return GNUNET_NO; /* plugin is blacklisted! */
2547 * Test if a peer/transport combination is blacklisted.
2549 * @param peer the identity of the peer to test
2550 * @param transport_name name of the transport to test, never NULL
2551 * @param cont function to call with result
2552 * @param cont_cls closure for @a cont
2553 * @param address address to pass back to @a cont, can be NULL
2554 * @param session session to pass back to @a cont, can be NULL
2555 * @return handle to the blacklist check, NULL if the decision
2556 * was made instantly and @a cont was already called
2558 struct GST_BlacklistCheck *
2559 GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
2560 const char *transport_name,
2561 GST_BlacklistTestContinuation cont,
2563 const struct GNUNET_HELLO_Address *address,
2564 struct GNUNET_ATS_Session *session)
2566 struct GST_BlacklistCheck *bc;
2567 struct TransportClient *tc;
2569 GNUNET_assert (NULL != peer);
2570 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2571 "Blacklist check for peer `%s':%s\n",
2573 (NULL != transport_name) ? transport_name : "unspecified");
2575 /* Check local blacklist by iterating over hashmap
2576 * If iteration is aborted, we found a matching blacklist entry */
2577 if ((NULL != blacklist) &&
2579 GNUNET_CONTAINER_multipeermap_get_multiple (blacklist, peer,
2581 (void *) transport_name)))
2583 /* Disallowed by config, disapprove instantly */
2584 GNUNET_STATISTICS_update (GST_stats,
2585 gettext_noop ("# disconnects due to blacklist"),
2588 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2589 _("Disallowing connection to peer `%s' on transport %s\n"),
2591 (NULL != transport_name) ? transport_name : "unspecified");
2601 for (tc = clients_head; NULL != tc; tc = tc->next)
2602 if (CT_BLACKLIST == tc->type)
2606 /* no blacklist clients, approve instantly */
2613 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2614 "Allowing connection to peer `%s' %s\n",
2616 (NULL != transport_name) ? transport_name : "");
2620 /* need to query blacklist clients */
2621 bc = GNUNET_new (struct GST_BlacklistCheck);
2622 GNUNET_CONTAINER_DLL_insert (bc_head,
2626 bc->address = GNUNET_HELLO_address_copy (address);
2627 bc->session = session;
2629 bc->cont_cls = cont_cls;
2631 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
2638 * Cancel a blacklist check.
2640 * @param bc check to cancel
2643 GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc)
2645 GNUNET_CONTAINER_DLL_remove (bc_head,
2648 if (NULL != bc->bl_pos)
2650 if ( (CT_BLACKLIST == bc->bl_pos->type) &&
2651 (bc->bl_pos->details.blacklist.bc == bc) )
2653 /* we're at the head of the queue, remove us! */
2654 bc->bl_pos->details.blacklist.bc = NULL;
2657 if (NULL != bc->task)
2659 GNUNET_SCHEDULER_cancel (bc->task);
2662 GNUNET_free_non_null (bc->address);
2668 * Function to iterate over options in the blacklisting section for a peer.
2670 * @param cls closure
2671 * @param section name of the section
2672 * @param option name of the option
2673 * @param value value of the option
2676 blacklist_cfg_iter (void *cls,
2677 const char *section,
2681 unsigned int *res = cls;
2682 struct GNUNET_PeerIdentity peer;
2687 GNUNET_CRYPTO_eddsa_public_key_from_string (option,
2692 if ((NULL == value) || (0 == strcmp(value, "")))
2694 /* Blacklist whole peer */
2695 GST_blacklist_add_peer (&peer, NULL);
2696 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2697 _("Adding blacklisting entry for peer `%s'\n"),
2698 GNUNET_i2s (&peer));
2702 plugs = GNUNET_strdup (value);
2703 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
2705 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2706 _("Adding blacklisting entry for peer `%s':`%s'\n"),
2707 GNUNET_i2s (&peer), pos);
2708 GST_blacklist_add_peer (&peer, pos);
2710 GNUNET_free (plugs);
2717 * Read blacklist configuration
2719 * @param cfg the configuration handle
2720 * @param my_id my peer identity
2723 read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg,
2724 const struct GNUNET_PeerIdentity *my_id)
2727 unsigned int res = 0;
2729 GNUNET_snprintf (cfg_sect,
2731 "transport-blacklist-%s",
2732 GNUNET_i2s_full (my_id));
2733 GNUNET_CONFIGURATION_iterate_section_values (cfg,
2735 &blacklist_cfg_iter,
2737 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2738 "Loaded %u blacklisting entries from configuration\n",
2744 * Initiate transport service.
2746 * @param cls closure
2747 * @param c configuration to use
2748 * @param service the initialized service
2752 const struct GNUNET_CONFIGURATION_Handle *c,
2753 struct GNUNET_SERVICE_Handle *service)
2756 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
2757 long long unsigned int max_fd_cfg;
2765 GNUNET_CONFIGURATION_get_value_filename (c,
2770 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2771 _("Transport service is lacking key configuration settings. Exiting.\n"));
2772 GNUNET_SCHEDULER_shutdown ();
2776 GNUNET_CONFIGURATION_get_value_time (c,
2781 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
2783 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
2784 GNUNET_free (keyfile);
2785 GNUNET_assert (NULL != pk);
2786 GST_my_private_key = pk;
2788 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
2789 GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg);
2790 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key,
2791 &GST_my_identity.public_key);
2792 GNUNET_assert (NULL != GST_my_private_key);
2794 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2795 "My identity is `%4s'\n",
2796 GNUNET_i2s_full (&GST_my_identity));
2798 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
2800 if (NULL == GST_peerinfo)
2802 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2803 _("Could not access PEERINFO service. Exiting.\n"));
2804 GNUNET_SCHEDULER_shutdown ();
2811 struct rlimit r_file;
2813 if (0 == getrlimit (RLIMIT_NOFILE,
2816 max_fd_rlimit = r_file.rlim_cur;
2817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2818 "Maximum number of open files was: %u/%u\n",
2819 (unsigned int) r_file.rlim_cur,
2820 (unsigned int) r_file.rlim_max);
2822 max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */
2826 GNUNET_CONFIGURATION_get_value_number (GST_cfg,
2830 max_fd_cfg = max_fd_rlimit;
2832 if (max_fd_cfg > max_fd_rlimit)
2833 max_fd = max_fd_cfg;
2835 max_fd = max_fd_rlimit;
2836 if (max_fd < DEFAULT_MAX_FDS)
2837 max_fd = DEFAULT_MAX_FDS;
2839 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2840 "Limiting number of sockets to %u: validation %u, neighbors: %u\n",
2845 friend_only = GNUNET_CONFIGURATION_get_value_yesno (GST_cfg,
2848 if (GNUNET_SYSERR == friend_only)
2849 friend_only = GNUNET_NO; /* According to topology defaults */
2850 /* start subsystems */
2851 read_blacklist_configuration (GST_cfg,
2853 GST_is = GNUNET_ATS_scanner_init ();
2854 GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg);
2855 GST_ats = GNUNET_ATS_scheduling_init (GST_cfg,
2856 &ats_request_address_change,
2859 GST_manipulation_init ();
2860 GST_plugins_load (&GST_manipulation_recv,
2861 &plugin_env_address_change_notification,
2862 &plugin_env_session_start,
2863 &plugin_env_session_end);
2864 GST_hello_start (friend_only,
2865 &process_hello_update,
2867 GST_neighbours_start ((max_fd / 3) * 2);
2868 active_stccs = GNUNET_CONTAINER_multipeermap_create (128,
2870 plugin_nc = GNUNET_notification_context_create (0);
2871 GST_validation_start ((max_fd / 3));
2876 * Define "main" method using service macro.
2880 GNUNET_SERVICE_OPTION_NONE,
2883 &client_disconnect_cb,
2885 GNUNET_MQ_hd_fixed_size (client_start,
2886 GNUNET_MESSAGE_TYPE_TRANSPORT_START,
2887 struct StartMessage,
2889 GNUNET_MQ_hd_var_size (client_hello,
2890 GNUNET_MESSAGE_TYPE_HELLO,
2891 struct GNUNET_MessageHeader,
2893 GNUNET_MQ_hd_var_size (client_send,
2894 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
2895 struct OutboundMessage,
2897 GNUNET_MQ_hd_var_size (client_address_to_string,
2898 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING,
2899 struct AddressLookupMessage,
2901 GNUNET_MQ_hd_fixed_size (client_monitor_peers,
2902 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST,
2903 struct PeerMonitorMessage,
2905 GNUNET_MQ_hd_fixed_size (client_blacklist_init,
2906 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
2907 struct GNUNET_MessageHeader,
2909 GNUNET_MQ_hd_fixed_size (client_blacklist_reply,
2910 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
2911 struct BlacklistMessage,
2913 GNUNET_MQ_hd_fixed_size (client_set_metric,
2914 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC,
2915 struct TrafficMetricMessage,
2917 GNUNET_MQ_hd_fixed_size (client_monitor_plugins,
2918 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START,
2919 struct GNUNET_MessageHeader,
2921 GNUNET_MQ_handler_end ());
2924 /* end of file gnunet-service-transport.c */