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 for (struct AddressToStringContext *cur = a2s_head;
551 GNUNET_CONTAINER_DLL_remove (clients_head,
563 for (bc = bc_head; NULL != bc; bc = bc->next)
565 if (bc->bl_pos != tc)
567 bc->bl_pos = tc->next;
568 if (NULL == bc->task)
569 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
579 * Function called for each of our connected neighbours. Notify the
580 * client about the existing neighbour.
582 * @param cls the `struct TransportClient *` to notify
583 * @param peer identity of the neighbour
584 * @param address the address
585 * @param state the current state of the peer
586 * @param state_timeout the time out for the state
587 * @param bandwidth_in inbound bandwidth in NBO
588 * @param bandwidth_out outbound bandwidth in NBO
591 notify_client_about_neighbour (void *cls,
592 const struct GNUNET_PeerIdentity *peer,
593 const struct GNUNET_HELLO_Address *address,
594 enum GNUNET_TRANSPORT_PeerState state,
595 struct GNUNET_TIME_Absolute state_timeout,
596 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
597 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
599 struct TransportClient *tc = cls;
600 struct ConnectInfoMessage cim;
602 if (GNUNET_NO == GST_neighbours_test_connected (peer))
604 cim.header.size = htons (sizeof (struct ConnectInfoMessage));
605 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
607 cim.quota_in = bandwidth_in;
608 cim.quota_out = bandwidth_out;
616 * Initialize a normal client. We got a start message from this
617 * client, add him to the list of clients for broadcasting of inbound
620 * @param cls the client
621 * @param start the start message that was sent
624 handle_client_start (void *cls,
625 const struct StartMessage *start)
627 struct TransportClient *tc = cls;
628 const struct GNUNET_MessageHeader *hello;
631 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
632 "Client %p sent START\n",
634 options = ntohl (start->options);
635 if ((0 != (1 & options)) &&
637 memcmp (&start->self,
639 sizeof (struct GNUNET_PeerIdentity))))
641 /* client thinks this is a different peer, reject */
643 GNUNET_SERVICE_client_drop (tc->client);
646 if (CT_NONE != tc->type)
649 GNUNET_SERVICE_client_drop (tc->client);
652 if (0 != (2 & options))
654 hello = GST_hello_get ();
659 GST_neighbours_iterate (¬ify_client_about_neighbour,
661 GNUNET_SERVICE_client_continue (tc->client);
666 * Client sent us a HELLO. Check the request.
668 * @param cls the client
669 * @param message the HELLO message
672 check_client_hello (void *cls,
673 const struct GNUNET_MessageHeader *message)
675 return GNUNET_OK; /* FIXME: check here? */
680 * Client sent us a HELLO. Process the request.
682 * @param cls the client
683 * @param message the HELLO message
686 handle_client_hello (void *cls,
687 const struct GNUNET_MessageHeader *message)
689 struct TransportClient *tc = cls;
691 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
692 "Received HELLO message\n");
693 GST_validation_handle_hello (message);
694 GNUNET_SERVICE_client_continue (tc->client);
699 * Function called after the transmission is done. Notify the client that it is
700 * OK to send the next message.
703 * @param success #GNUNET_OK on success, #GNUNET_NO on failure, #GNUNET_SYSERR if we're not connected
704 * @param bytes_payload bytes payload sent
705 * @param bytes_on_wire bytes sent on wire
708 handle_send_transmit_continuation (void *cls,
710 size_t bytes_payload,
711 size_t bytes_on_wire)
713 struct SendTransmitContinuationContext *stcc = cls;
714 struct SendOkMessage send_ok_msg;
715 struct GNUNET_TIME_Relative delay;
716 const struct GNUNET_HELLO_Address *addr;
718 delay = GNUNET_TIME_absolute_get_duration (stcc->send_time);
719 addr = GST_neighbour_get_current_address (&stcc->target);
720 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
721 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
722 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
723 GNUNET_STRINGS_relative_time_to_string (delay,
725 (unsigned int) bytes_payload,
726 (unsigned int) bytes_on_wire,
727 GNUNET_i2s (&stcc->target),
729 (NULL != addr) ? addr->transport_name : "%");
731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
732 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
733 GNUNET_STRINGS_relative_time_to_string (delay,
735 (unsigned int) bytes_payload,
736 (unsigned int) bytes_on_wire,
737 GNUNET_i2s (&stcc->target),
739 (NULL != addr) ? addr->transport_name : "%");
741 if (GNUNET_NO == stcc->down)
743 /* Only send confirmation if we are still connected */
744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
745 "Sending SEND_OK for transmission request %llu\n",
747 send_ok_msg.header.size = htons (sizeof (send_ok_msg));
748 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
749 send_ok_msg.bytes_msg = htonl (bytes_payload);
750 send_ok_msg.bytes_physical = htonl (bytes_on_wire);
751 send_ok_msg.success = htonl (success);
752 send_ok_msg.peer = stcc->target;
757 GNUNET_assert (GNUNET_OK ==
758 GNUNET_CONTAINER_multipeermap_remove (active_stccs,
766 * Client asked for transmission to a peer. Process the request.
768 * @param cls the client
769 * @param obm the send message that was sent
772 check_client_send (void *cls,
773 const struct OutboundMessage *obm)
776 const struct GNUNET_MessageHeader *obmm;
778 size = ntohs (obm->header.size) - sizeof (struct OutboundMessage);
779 if (size < sizeof (struct GNUNET_MessageHeader))
782 return GNUNET_SYSERR;
784 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
785 if (size != ntohs (obmm->size))
788 return GNUNET_SYSERR;
795 * Client asked for transmission to a peer. Process the request.
797 * @param cls the client
798 * @param obm the send message that was sent
801 handle_client_send (void *cls,
802 const struct OutboundMessage *obm)
804 static unsigned long long uuid_gen;
805 struct TransportClient *tc = cls;
806 const struct GNUNET_MessageHeader *obmm;
807 struct SendTransmitContinuationContext *stcc;
809 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
810 if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer))
812 /* not connected, not allowed to send; can happen due to asynchronous operations */
813 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
814 "Could not send message to peer `%s': not connected\n",
815 GNUNET_i2s (&obm->peer));
816 GNUNET_STATISTICS_update (GST_stats,
818 ("# bytes payload dropped (other peer was not connected)"),
821 GNUNET_SERVICE_client_continue (tc->client);
824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
825 "Received SEND request %llu for `%s' and first message of type %u and total size %u\n",
827 GNUNET_i2s (&obm->peer),
830 GNUNET_SERVICE_client_continue (tc->client);
832 stcc = GNUNET_new (struct SendTransmitContinuationContext);
833 stcc->target = obm->peer;
835 stcc->send_time = GNUNET_TIME_absolute_get ();
836 stcc->uuid = uuid_gen++;
837 (void) GNUNET_CONTAINER_multipeermap_put (active_stccs,
840 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
841 GST_manipulation_send (&obm->peer,
844 GNUNET_TIME_relative_ntoh (obm->timeout),
845 &handle_send_transmit_continuation,
851 * Take the given address and append it to the set of results sent back to
852 * the client. This function may be called serveral times for a single
853 * conversion. The last invocation will be with a @a address of
854 * NULL and a @a res of #GNUNET_OK. Thus, to indicate conversion
855 * errors, the callback might be called first with @a address NULL and
856 * @a res being #GNUNET_SYSERR. In that case, there will still be a
857 * subsequent call later with @a address NULL and @a res #GNUNET_OK.
859 * @param cls the `struct AddressToStringContext`
860 * @param buf text to transmit (contains the human-readable address, or NULL)
861 * @param res #GNUNET_OK if conversion was successful, #GNUNET_SYSERR on error,
865 transmit_address_to_client (void *cls,
869 struct AddressToStringContext *actx = cls;
870 struct GNUNET_MQ_Envelope *env;
871 struct AddressToStringResultMessage *atsm;
874 GNUNET_assert ( (GNUNET_OK == res) ||
875 (GNUNET_SYSERR == res) );
876 if (NULL == actx->tc)
880 env = GNUNET_MQ_msg (atsm,
881 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
882 if (GNUNET_OK == res)
884 /* this was the last call, transmit */
885 atsm->res = htonl (GNUNET_OK);
886 atsm->addr_len = htonl (0);
887 GNUNET_MQ_send (actx->tc->mq,
889 GNUNET_CONTAINER_DLL_remove (a2s_head,
895 if (GNUNET_SYSERR == res)
897 /* address conversion failed, but there will be more callbacks */
898 atsm->res = htonl (GNUNET_SYSERR);
899 atsm->addr_len = htonl (0);
900 GNUNET_MQ_send (actx->tc->mq,
905 GNUNET_assert (GNUNET_OK == res);
906 /* succesful conversion, append*/
907 slen = strlen (buf) + 1;
908 env = GNUNET_MQ_msg_extra (atsm,
910 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
911 atsm->res = htonl (GNUNET_YES);
912 atsm->addr_len = htonl (slen);
913 GNUNET_memcpy (&atsm[1],
916 GNUNET_MQ_send (actx->tc->mq,
922 * Client asked to resolve an address. Check the request.
924 * @param cls the client
925 * @param alum the resolution request
926 * @return #GNUNET_OK if @a alum is well-formed
929 check_client_address_to_string (void *cls,
930 const struct AddressLookupMessage *alum)
932 const char *plugin_name;
934 uint32_t address_len;
937 size = ntohs (alum->header.size);
938 address_len = ntohs (alum->addrlen);
939 if (size <= sizeof (struct AddressLookupMessage) + address_len)
942 return GNUNET_SYSERR;
944 address = (const char *) &alum[1];
945 plugin_name = (const char *) &address[address_len];
946 if ('\0' != plugin_name[size - sizeof (struct AddressLookupMessage) - address_len - 1])
949 return GNUNET_SYSERR;
956 * Client asked to resolve an address. Process the request.
958 * @param cls the client
959 * @param alum the resolution request
962 handle_client_address_to_string (void *cls,
963 const struct AddressLookupMessage *alum)
965 struct TransportClient *tc = cls;
966 struct GNUNET_TRANSPORT_PluginFunctions *papi;
967 const char *plugin_name;
969 uint32_t address_len;
970 struct AddressToStringContext *actx;
971 struct GNUNET_MQ_Envelope *env;
972 struct AddressToStringResultMessage *atsm;
973 struct GNUNET_TIME_Relative rtimeout;
976 address_len = ntohs (alum->addrlen);
977 address = (const char *) &alum[1];
978 plugin_name = (const char *) &address[address_len];
979 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
980 numeric = ntohs (alum->numeric_only);
981 papi = GST_plugins_printer_find (plugin_name);
984 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
985 "Failed to find plugin `%s'\n",
987 env = GNUNET_MQ_msg (atsm,
988 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
989 atsm->res = htonl (GNUNET_SYSERR);
990 atsm->addr_len = htonl (0);
991 GNUNET_MQ_send (tc->mq,
993 env = GNUNET_MQ_msg (atsm,
994 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
995 atsm->res = htonl (GNUNET_OK);
996 atsm->addr_len = htonl (0);
997 GNUNET_MQ_send (tc->mq,
1001 actx = GNUNET_new (struct AddressToStringContext);
1003 GNUNET_CONTAINER_DLL_insert (a2s_head,
1006 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1007 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1008 "Pretty-printing address of %u bytes using plugin `%s'\n",
1011 papi->address_pretty_printer (papi->cls,
1017 &transmit_address_to_client,
1023 * Compose #PeerIterateResponseMessage using the given peer and address.
1025 * @param peer identity of the peer
1026 * @param address the address, NULL on disconnect
1027 * @return composed message
1029 static struct PeerIterateResponseMessage *
1030 compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer,
1031 const struct GNUNET_HELLO_Address *address)
1033 struct PeerIterateResponseMessage *msg;
1039 GNUNET_assert (NULL != peer);
1040 if (NULL != address)
1042 tlen = strlen (address->transport_name) + 1;
1043 alen = address->address_length;
1050 size = (sizeof (struct PeerIterateResponseMessage) + alen + tlen);
1051 msg = GNUNET_malloc (size);
1052 msg->header.size = htons (size);
1054 = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE);
1055 msg->reserved = htonl (0);
1057 msg->addrlen = htonl (alen);
1058 msg->pluginlen = htonl (tlen);
1060 if (NULL != address)
1062 msg->local_address_info = htonl((uint32_t) address->local_info);
1063 addr = (char *) &msg[1];
1064 GNUNET_memcpy (addr,
1067 GNUNET_memcpy (&addr[alen],
1068 address->transport_name,
1076 * Context for #send_validation_information() and
1077 * #send_peer_information().
1079 struct IterationContext
1082 * Context to use for the transmission.
1084 struct TransportClient *tc;
1087 * Which peers do we care about?
1089 struct GNUNET_PeerIdentity id;
1092 * #GNUNET_YES if @e id should be ignored because we want all peers.
1099 * Output information of neighbours to the given client.
1101 * @param cls the `struct PeerIterationContext *`
1102 * @param peer identity of the neighbour
1103 * @param address the address
1104 * @param state current state this peer is in
1105 * @param state_timeout timeout for the current state of the peer
1106 * @param bandwidth_in inbound quota in NBO
1107 * @param bandwidth_out outbound quota in NBO
1110 send_peer_information (void *cls,
1111 const struct GNUNET_PeerIdentity *peer,
1112 const struct GNUNET_HELLO_Address *address,
1113 enum GNUNET_TRANSPORT_PeerState state,
1114 struct GNUNET_TIME_Absolute state_timeout,
1115 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1116 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1118 struct IterationContext *pc = cls;
1119 struct GNUNET_MQ_Envelope *env;
1120 struct PeerIterateResponseMessage *msg;
1122 if ( (GNUNET_YES != pc->all) &&
1127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1128 "Sending information about `%s' using address `%s' in state `%s'\n",
1130 (NULL != address) ? GST_plugins_a2s (address) : "<none>",
1131 GNUNET_TRANSPORT_ps2s (state));
1132 msg = compose_address_iterate_response_message (peer,
1134 msg->state = htonl (state);
1135 msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout);
1136 env = GNUNET_MQ_msg_copy (&msg->header);
1138 GNUNET_MQ_send (pc->tc->mq,
1144 * Client asked to obtain information about a specific or all peers
1145 * Process the request.
1147 * @param cls the client
1148 * @param msg the peer address information request
1151 handle_client_monitor_peers (void *cls,
1152 const struct PeerMonitorMessage *msg)
1154 struct TransportClient *tc = cls;
1155 struct IterationContext pc;
1157 if (CT_NONE != tc->type)
1160 GNUNET_SERVICE_client_drop (tc->client);
1163 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1164 GNUNET_SERVICE_client_mark_monitor (tc->client);
1166 /* Send initial list */
1168 if (0 == memcmp (&msg->peer,
1170 sizeof (struct GNUNET_PeerIdentity)))
1172 /* iterate over all neighbours */
1173 pc.all = GNUNET_YES;
1178 /* just return one neighbour */
1182 GST_neighbours_iterate (&send_peer_information,
1185 if (GNUNET_YES != ntohl (msg->one_shot))
1187 tc->details.monitor_peer = msg->peer;
1188 tc->type = CT_MONITOR;
1189 if (0 != memcmp (&msg->peer,
1191 sizeof (struct GNUNET_PeerIdentity)))
1192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1193 "Client %p started monitoring of the peer `%s'\n",
1195 GNUNET_i2s (&msg->peer));
1197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1198 "Client %p started monitoring all peers\n",
1203 struct GNUNET_MessageHeader *msg;
1204 struct GNUNET_MQ_Envelope *env;
1206 env = GNUNET_MQ_msg (msg,
1207 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END);
1208 GNUNET_MQ_send (tc->mq,
1215 * Function called by the plugin with information about the
1216 * current sessions managed by the plugin (for monitoring).
1218 * @param cls closure
1219 * @param session session handle this information is about,
1220 * NULL to indicate that we are "in sync" (initial
1221 * iteration complete)
1222 * @param info information about the state of the session,
1223 * NULL if @a session is also NULL and we are
1224 * merely signalling that the initial iteration is over
1227 plugin_session_info_cb (void *cls,
1228 struct GNUNET_ATS_Session *session,
1229 const struct GNUNET_TRANSPORT_SessionInfo *info)
1231 struct GNUNET_MQ_Envelope *env;
1232 struct TransportPluginMonitorMessage *msg;
1233 struct GNUNET_MessageHeader *sync;
1240 if (0 == GNUNET_notification_context_get_size (plugin_nc))
1242 GST_plugins_monitor_subscribe (NULL,
1246 if ( (NULL == info) &&
1249 /* end of initial iteration */
1250 if (NULL != sync_client)
1252 env = GNUNET_MQ_msg (sync,
1253 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC);
1254 GNUNET_MQ_send (sync_client->mq,
1260 GNUNET_assert (NULL != info);
1261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1262 "Plugin event for peer %s on transport %s\n",
1263 GNUNET_i2s (&info->address->peer),
1264 info->address->transport_name);
1265 slen = strlen (info->address->transport_name) + 1;
1266 alen = info->address->address_length;
1267 size = sizeof (struct TransportPluginMonitorMessage) + slen + alen;
1268 if (size > UINT16_MAX)
1273 msg = GNUNET_malloc (size);
1274 msg->header.size = htons (size);
1275 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT);
1276 msg->session_state = htons ((uint16_t) info->state);
1277 msg->is_inbound = htons ((int16_t) info->is_inbound);
1278 msg->msgs_pending = htonl (info->num_msg_pending);
1279 msg->bytes_pending = htonl (info->num_bytes_pending);
1280 msg->timeout = GNUNET_TIME_absolute_hton (info->session_timeout);
1281 msg->delay = GNUNET_TIME_absolute_hton (info->receive_delay);
1282 msg->peer = info->address->peer;
1283 msg->session_id = (uint64_t) (intptr_t) session;
1284 msg->plugin_name_len = htons (slen);
1285 msg->plugin_address_len = htons (alen);
1286 name = (char *) &msg[1];
1287 GNUNET_memcpy (name,
1288 info->address->transport_name,
1291 GNUNET_memcpy (addr,
1292 info->address->address,
1294 if (NULL != sync_client)
1296 struct GNUNET_MQ_Envelope *env;
1298 env = GNUNET_MQ_msg_copy (&msg->header);
1299 GNUNET_MQ_send (sync_client->mq,
1304 GNUNET_notification_context_broadcast (plugin_nc,
1313 * Client asked to obtain information about all plugin connections.
1315 * @param cls the client
1316 * @param message the peer address information request
1319 handle_client_monitor_plugins (void *cls,
1320 const struct GNUNET_MessageHeader *message)
1322 struct TransportClient *tc = cls;
1324 GNUNET_SERVICE_client_mark_monitor (tc->client);
1325 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1326 GNUNET_notification_context_add (plugin_nc,
1328 GNUNET_assert (NULL == sync_client);
1330 GST_plugins_monitor_subscribe (&plugin_session_info_cb,
1336 * Broadcast the given message to all of our clients.
1338 * @param msg message to broadcast
1339 * @param may_drop #GNUNET_YES if the message can be dropped / is payload
1342 GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
1345 struct TransportClient *tc;
1348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1349 "Asked to broadcast message of type %u with %u bytes\n",
1350 (unsigned int) ntohs (msg->type),
1351 (unsigned int) ntohs (msg->size));
1353 for (tc = clients_head; NULL != tc; tc = tc->next)
1355 if ( (GNUNET_YES == may_drop) &&
1356 (CT_CORE != tc->type) )
1357 continue; /* skip, this client does not care about payload */
1363 if (GNUNET_NO == done)
1364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1365 "Message of type %u not delivered, is CORE service up?\n",
1371 * Broadcast the new active address to all clients monitoring the peer.
1373 * @param peer peer this update is about (never NULL)
1374 * @param address address, NULL on disconnect
1375 * @param state the current state of the peer
1376 * @param state_timeout the time out for the state
1379 GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer,
1380 const struct GNUNET_HELLO_Address *address,
1381 enum GNUNET_TRANSPORT_PeerState state,
1382 struct GNUNET_TIME_Absolute state_timeout)
1384 struct GNUNET_MQ_Envelope *env;
1385 struct PeerIterateResponseMessage *msg;
1386 struct TransportClient *tc;
1388 msg = compose_address_iterate_response_message (peer,
1390 msg->state = htonl (state);
1391 msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout);
1392 for (tc = clients_head; NULL != tc; tc = tc->next)
1394 if (CT_MONITOR != tc->type)
1396 if ((0 == memcmp (&tc->details.monitor_peer,
1398 sizeof (struct GNUNET_PeerIdentity))) ||
1399 (0 == memcmp (&tc->details.monitor_peer,
1401 sizeof (struct GNUNET_PeerIdentity))))
1403 env = GNUNET_MQ_msg_copy (&msg->header);
1404 GNUNET_MQ_send (tc->mq,
1413 * Mark the peer as down so we don't call the continuation
1414 * context in the future.
1417 * @param peer peer that got disconnected
1418 * @param value a `struct SendTransmitContinuationContext` to mark
1419 * @return #GNUNET_OK (continue to iterate)
1422 mark_peer_down (void *cls,
1423 const struct GNUNET_PeerIdentity *peer,
1426 struct SendTransmitContinuationContext *stcc = value;
1428 stcc->down = GNUNET_YES;
1434 * Notify all clients about a disconnect, and cancel
1435 * pending SEND_OK messages for this peer.
1437 * @param peer peer that disconnected
1440 GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer)
1442 struct DisconnectInfoMessage disconnect_msg;
1444 GNUNET_CONTAINER_multipeermap_get_multiple (active_stccs,
1448 disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage));
1449 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
1450 disconnect_msg.reserved = htonl (0);
1451 disconnect_msg.peer = *peer;
1452 GST_clients_broadcast (&disconnect_msg.header,
1459 * Transmit our HELLO message to the given (connected) neighbour.
1461 * @param cls the 'HELLO' message
1462 * @param peer identity of the peer
1463 * @param address the address
1464 * @param state current state this peer is in
1465 * @param state_timeout timeout for the current state of the peer
1466 * @param bandwidth_in inbound quota in NBO
1467 * @param bandwidth_out outbound quota in NBO
1470 transmit_our_hello (void *cls,
1471 const struct GNUNET_PeerIdentity *peer,
1472 const struct GNUNET_HELLO_Address *address,
1473 enum GNUNET_TRANSPORT_PeerState state,
1474 struct GNUNET_TIME_Absolute state_timeout,
1475 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1476 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1478 const struct GNUNET_MessageHeader *hello = cls;
1483 sizeof (struct GNUNET_PeerIdentity)))
1484 return; /* not to ourselves */
1485 if (GNUNET_NO == GST_neighbours_test_connected (peer))
1488 GST_neighbours_send (peer,
1490 ntohs (hello->size),
1498 * My HELLO has changed. Tell everyone who should know.
1501 * @param hello new HELLO
1504 process_hello_update (void *cls,
1505 const struct GNUNET_MessageHeader *hello)
1507 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1508 "Broadcasting HELLO to clients\n");
1509 GST_clients_broadcast (hello, GNUNET_NO);
1510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1511 "Broadcasting HELLO to neighbours\n");
1512 GST_neighbours_iterate (&transmit_our_hello,
1518 * We received some payload. Prepare to pass it on to our clients.
1520 * @param address address and (claimed) identity of the other peer
1521 * @param session identifier used for this session (NULL for plugins
1522 * that do not offer bi-directional communication to the sender
1523 * using the same "connection")
1524 * @param message the message to process
1525 * @return how long the plugin should wait until receiving more data
1527 static struct GNUNET_TIME_Relative
1528 process_payload (const struct GNUNET_HELLO_Address *address,
1529 struct GNUNET_ATS_Session *session,
1530 const struct GNUNET_MessageHeader *message)
1532 struct GNUNET_TIME_Relative ret;
1534 struct InboundMessage *im;
1535 size_t msg_size = ntohs (message->size);
1536 size_t size = sizeof(struct InboundMessage) + msg_size;
1537 char buf[size] GNUNET_ALIGN;
1539 do_forward = GNUNET_SYSERR;
1540 ret = GST_neighbours_calculate_receive_delay (&address->peer,
1543 if (! GST_neighbours_test_connected (&address->peer))
1545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1546 "Discarded %u bytes type %u payload from peer `%s'\n",
1547 (unsigned int) msg_size,
1548 ntohs (message->type),
1549 GNUNET_i2s (&address->peer));
1550 GNUNET_STATISTICS_update (GST_stats, gettext_noop
1551 ("# bytes payload discarded due to not connected peer"),
1557 if (GNUNET_YES != do_forward)
1559 im = (struct InboundMessage *) buf;
1560 im->header.size = htons (size);
1561 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
1562 im->peer = address->peer;
1563 GNUNET_memcpy (&im[1],
1565 ntohs (message->size));
1566 GST_clients_broadcast (&im->header,
1573 * Task to asynchronously terminate a session.
1575 * @param cls the `struct GNUNET_ATS_SessionKiller` with the information for the kill
1578 kill_session_task (void *cls)
1580 struct GNUNET_ATS_SessionKiller *sk = cls;
1583 GNUNET_CONTAINER_DLL_remove (sk_head,
1586 sk->plugin->disconnect_session (sk->plugin->cls,
1593 * Force plugin to terminate session due to communication
1596 * @param plugin_name name of the plugin
1597 * @param session session to termiante
1600 kill_session (const char *plugin_name,
1601 struct GNUNET_ATS_Session *session)
1603 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
1604 struct GNUNET_ATS_SessionKiller *sk;
1606 for (sk = sk_head; NULL != sk; sk = sk->next)
1607 if (sk->session == session)
1609 plugin = GST_plugins_find (plugin_name);
1615 /* need to issue disconnect asynchronously */
1616 sk = GNUNET_new (struct GNUNET_ATS_SessionKiller);
1617 sk->session = session;
1618 sk->plugin = plugin;
1619 sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task,
1621 GNUNET_CONTAINER_DLL_insert (sk_head,
1628 * Black list check result for try_connect call
1629 * If connection to the peer is allowed request adddress and ???
1631 * @param cls the message
1632 * @param peer the peer
1633 * @param address the address
1634 * @param session the session
1635 * @param result the result
1638 connect_bl_check_cont (void *cls,
1639 const struct GNUNET_PeerIdentity *peer,
1640 const struct GNUNET_HELLO_Address *address,
1641 struct GNUNET_ATS_Session *session,
1644 struct GNUNET_MessageHeader *msg = cls;
1646 if (GNUNET_OK == result)
1648 /* Blacklist allows to speak to this peer, forward SYN to neighbours */
1649 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1650 "Received SYN message from peer `%s' at `%s'\n",
1652 GST_plugins_a2s (address));
1654 GST_neighbours_handle_session_syn (msg,
1657 GST_blacklist_abort_matching (address,
1659 kill_session (address->transport_name,
1666 if (GNUNET_SYSERR == result)
1667 return; /* check was aborted, session destroyed */
1668 /* Blacklist denies to speak to this peer */
1669 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1670 "Discarding SYN message from `%s' due to denied blacklist check\n",
1672 kill_session (address->transport_name,
1678 * Function called by the transport for each received message.
1680 * @param cls closure, const char* with the name of the plugin we received the message from
1681 * @param address address and (claimed) identity of the other peer
1682 * @param message the message, NULL if we only care about
1683 * learning about the delay until we should receive again
1684 * @param session identifier used for this session (NULL for plugins
1685 * that do not offer bi-directional communication to the sender
1686 * using the same "connection")
1687 * @return how long the plugin should wait until receiving more data
1688 * (plugins that do not support this, can ignore the return value)
1690 struct GNUNET_TIME_Relative
1691 GST_receive_callback (void *cls,
1692 const struct GNUNET_HELLO_Address *address,
1693 struct GNUNET_ATS_Session *session,
1694 const struct GNUNET_MessageHeader *message)
1696 const char *plugin_name = cls;
1697 struct GNUNET_TIME_Relative ret;
1700 ret = GNUNET_TIME_UNIT_ZERO;
1701 if (NULL == message)
1703 type = ntohs (message->type);
1704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1705 "Received message with type %u from peer `%s' at %s\n",
1707 GNUNET_i2s (&address->peer),
1708 GST_plugins_a2s (address));
1710 GNUNET_STATISTICS_update (GST_stats,
1711 gettext_noop ("# bytes total received"),
1712 ntohs (message->size),
1714 GST_neighbours_notify_data_recv (address,
1718 case GNUNET_MESSAGE_TYPE_HELLO_LEGACY:
1719 /* Legacy HELLO message, discard */
1721 case GNUNET_MESSAGE_TYPE_HELLO:
1722 if (GNUNET_OK != GST_validation_handle_hello (message))
1724 GNUNET_break_op (0);
1725 GST_blacklist_abort_matching (address,
1729 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
1730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1731 "Processing PING from `%s'\n",
1732 GST_plugins_a2s (address));
1734 GST_validation_handle_ping (&address->peer,
1739 GST_blacklist_abort_matching (address,
1741 kill_session (plugin_name,
1745 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
1746 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1747 "Processing PONG from `%s'\n",
1748 GST_plugins_a2s (address));
1750 GST_validation_handle_pong (&address->peer,
1753 GNUNET_break_op (0);
1754 GST_blacklist_abort_matching (address,
1756 kill_session (plugin_name, session);
1759 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN:
1760 /* Do blacklist check if communication with this peer is allowed */
1761 (void) GST_blacklist_test_allowed (&address->peer,
1763 &connect_bl_check_cont,
1764 GNUNET_copy_message (message),
1768 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK:
1770 GST_neighbours_handle_session_syn_ack (message,
1774 GST_blacklist_abort_matching (address, session);
1775 kill_session (plugin_name, session);
1778 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
1780 GST_neighbours_handle_session_ack (message,
1785 GST_blacklist_abort_matching (address, session);
1786 kill_session (plugin_name, session);
1789 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
1790 GST_neighbours_handle_disconnect_message (&address->peer,
1793 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA:
1794 GST_neighbours_handle_quota_message (&address->peer,
1797 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
1798 GST_neighbours_keepalive (&address->peer,
1801 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE:
1802 GST_neighbours_keepalive_response (&address->peer,
1806 /* should be payload */
1807 GNUNET_STATISTICS_update (GST_stats,
1808 gettext_noop ("# bytes payload received"),
1809 ntohs (message->size),
1811 ret = process_payload (address,
1817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1818 "Allowing receive from peer %s to continue in %s\n",
1819 GNUNET_i2s (&address->peer),
1820 GNUNET_STRINGS_relative_time_to_string (ret,
1827 * Function that will be called for each address the transport
1828 * is aware that it might be reachable under. Update our HELLO.
1830 * @param cls name of the plugin (const char*)
1831 * @param add_remove should the address added (YES) or removed (NO) from the
1832 * set of valid addresses?
1833 * @param address the address to add or remove
1836 plugin_env_address_change_notification (void *cls,
1838 const struct GNUNET_HELLO_Address *address)
1840 static int addresses = 0;
1842 if (GNUNET_YES == add_remove)
1845 GNUNET_STATISTICS_update (GST_stats,
1846 "# transport addresses",
1850 else if (GNUNET_NO == add_remove)
1859 GNUNET_STATISTICS_update (GST_stats,
1860 "# transport addresses",
1865 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1866 "Transport now has %u addresses to communicate\n",
1868 GST_hello_modify_addresses (add_remove,
1874 * Function that will be called whenever the plugin internally
1875 * cleans up a session pointer and hence the service needs to
1876 * discard all of those sessions as well. Plugins that do not
1877 * use sessions can simply omit calling this function and always
1878 * use NULL wherever a session pointer is needed. This function
1879 * should be called BEFORE a potential "TransmitContinuation"
1880 * from the "TransmitFunction".
1882 * @param cls closure
1883 * @param address which address was the session for
1884 * @param session which session is being destoyed
1887 plugin_env_session_end (void *cls,
1888 const struct GNUNET_HELLO_Address *address,
1889 struct GNUNET_ATS_Session *session)
1891 struct GNUNET_ATS_SessionKiller *sk;
1893 if (NULL == address)
1898 if (NULL == session)
1903 GNUNET_assert (strlen (address->transport_name) > 0);
1905 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1906 "Notification from plugin about terminated session %p from peer `%s' address `%s'\n",
1908 GNUNET_i2s (&address->peer),
1909 GST_plugins_a2s (address));
1911 GST_neighbours_session_terminated (&address->peer,
1913 GST_ats_del_session (address,
1915 GST_blacklist_abort_matching (address,
1918 for (sk = sk_head; NULL != sk; sk = sk->next)
1920 if (sk->session == session)
1922 GNUNET_CONTAINER_DLL_remove (sk_head,
1925 GNUNET_SCHEDULER_cancel (sk->task);
1934 * Black list check result from blacklist check triggered when a
1935 * plugin gave us a new session in #plugin_env_session_start(). If
1936 * connection to the peer is disallowed, kill the session.
1939 * @param peer the peer
1940 * @param address address associated with the request
1941 * @param session session associated with the request
1942 * @param result the result
1945 plugin_env_session_start_bl_check_cont (void *cls,
1946 const struct GNUNET_PeerIdentity *peer,
1947 const struct GNUNET_HELLO_Address *address,
1948 struct GNUNET_ATS_Session *session,
1951 if (GNUNET_OK != result)
1953 kill_session (address->transport_name,
1958 GNUNET_HELLO_address_check_option (address,
1959 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1961 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1962 "Informing verifier about inbound session's address `%s'\n",
1963 GST_plugins_a2s (address));
1964 GST_validation_handle_address (address);
1970 * Plugin tells transport service about a new inbound session
1973 * @param address the address
1974 * @param session the new session
1975 * @param scope network scope information
1978 plugin_env_session_start (void *cls,
1979 const struct GNUNET_HELLO_Address *address,
1980 struct GNUNET_ATS_Session *session,
1981 enum GNUNET_ATS_Network_Type scope)
1983 struct GNUNET_ATS_Properties prop;
1985 if (NULL == address)
1990 if (NULL == session)
1995 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1996 "Notification from plugin `%s' about new session from peer `%s' address `%s'\n",
1997 address->transport_name,
1998 GNUNET_i2s (&address->peer),
1999 GST_plugins_a2s (address));
2001 GNUNET_HELLO_address_check_option (address,
2002 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
2004 /* inbound is always new, but outbound MAY already be known, but
2005 for example for UNIX, we have symmetric connections and thus we
2006 may not know the address yet; add if necessary! */
2007 /* FIXME: maybe change API here so we just pass scope? */
2011 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != scope);
2013 GST_ats_add_inbound_address (address,
2017 /* Do blacklist check if communication with this peer is allowed */
2018 (void) GST_blacklist_test_allowed (&address->peer,
2019 address->transport_name,
2020 &plugin_env_session_start_bl_check_cont,
2028 * Function called by ATS to notify the callee that the
2029 * assigned bandwidth or address for a given peer was changed. If the
2030 * callback is called with address/bandwidth assignments of zero, the
2031 * ATS disconnect function will still be called once the disconnect
2032 * actually happened.
2034 * @param cls closure
2035 * @param peer the peer this address is intended for
2036 * @param address address to use (for peer given in address)
2037 * @param session session to use (if available)
2038 * @param bandwidth_out assigned outbound bandwidth for the connection in NBO,
2039 * 0 to disconnect from peer
2040 * @param bandwidth_in assigned inbound bandwidth for the connection in NBO,
2041 * 0 to disconnect from peer
2042 * @param ats ATS information
2043 * @param ats_count number of @a ats elements
2046 ats_request_address_change (void *cls,
2047 const struct GNUNET_PeerIdentity *peer,
2048 const struct GNUNET_HELLO_Address *address,
2049 struct GNUNET_ATS_Session *session,
2050 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
2051 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
2053 uint32_t bw_in = ntohl (bandwidth_in.value__);
2054 uint32_t bw_out = ntohl (bandwidth_out.value__);
2058 /* ATS service died, all suggestions become invalid!
2059 (but we'll keep using the allocations for a little
2060 while, to keep going while ATS restarts) */
2061 /* FIXME: We should drop all
2062 connections now, as ATS won't explicitly tell
2063 us and be unaware of ongoing resource allocations! */
2066 /* ATS tells me to disconnect from peer */
2067 if ((0 == bw_in) && (0 == bw_out))
2069 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2070 "ATS tells me to disconnect from peer `%s'\n",
2072 GST_neighbours_force_disconnect (peer);
2075 GNUNET_assert (NULL != address);
2076 GNUNET_STATISTICS_update (GST_stats,
2077 "# ATS suggestions received",
2080 GST_neighbours_switch_to_address (address,
2088 * Closure for #test_connection_ok().
2090 struct TestConnectionContext
2093 * Is this the first neighbour we're checking?
2098 * Handle to the blacklisting client we need to ask.
2100 struct TransportClient *tc;
2105 * Got the result about an existing connection from a new blacklister.
2106 * Shutdown the neighbour if necessary.
2109 * @param peer the neighbour that was investigated
2110 * @param address address associated with the request
2111 * @param session session associated with the request
2112 * @param allowed #GNUNET_OK if we can keep it,
2113 * #GNUNET_NO if we must shutdown the connection
2116 confirm_or_drop_neighbour (void *cls,
2117 const struct GNUNET_PeerIdentity *peer,
2118 const struct GNUNET_HELLO_Address *address,
2119 struct GNUNET_ATS_Session *session,
2122 if (GNUNET_OK == allowed)
2123 return; /* we're done */
2124 GNUNET_STATISTICS_update (GST_stats,
2125 gettext_noop ("# disconnects due to blacklist"),
2128 GST_neighbours_force_disconnect (peer);
2133 * Test if an existing connection is still acceptable given a new
2134 * blacklisting client.
2136 * @param cls the `struct TestConnectionContext *`
2137 * @param peer identity of the peer
2138 * @param address the address
2139 * @param state current state this peer is in
2140 * @param state_timeout timeout for the current state of the peer
2141 * @param bandwidth_in bandwidth assigned inbound
2142 * @param bandwidth_out bandwidth assigned outbound
2145 test_connection_ok (void *cls,
2146 const struct GNUNET_PeerIdentity *peer,
2147 const struct GNUNET_HELLO_Address *address,
2148 enum GNUNET_TRANSPORT_PeerState state,
2149 struct GNUNET_TIME_Absolute state_timeout,
2150 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
2151 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2153 struct TestConnectionContext *tcc = cls;
2154 struct GST_BlacklistCheck *bc;
2156 bc = GNUNET_new (struct GST_BlacklistCheck);
2157 GNUNET_CONTAINER_DLL_insert (bc_head,
2161 bc->address = GNUNET_HELLO_address_copy (address);
2162 bc->cont = &confirm_or_drop_neighbour;
2163 bc->cont_cls = NULL;
2164 bc->bl_pos = tcc->tc;
2165 if (GNUNET_YES == tcc->first)
2167 /* all would wait for the same client, no need to
2168 * create more than just the first task right now */
2169 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
2171 tcc->first = GNUNET_NO;
2177 * Initialize a blacklisting client. We got a blacklist-init
2178 * message from this client, add him to the list of clients
2179 * to query for blacklisting.
2181 * @param cls the client
2182 * @param message the blacklist-init message that was sent
2185 handle_client_blacklist_init (void *cls,
2186 const struct GNUNET_MessageHeader *message)
2188 struct TransportClient *tc = cls;
2189 struct TestConnectionContext tcc;
2191 if (CT_NONE != tc->type)
2194 GNUNET_SERVICE_client_drop (tc->client);
2197 GNUNET_SERVICE_client_mark_monitor (tc->client);
2198 tc->type = CT_BLACKLIST;
2199 tc->details.blacklist.call_receive_done = GNUNET_YES;
2200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2201 "New blacklist client %p\n",
2203 /* confirm that all existing connections are OK! */
2205 tcc.first = GNUNET_YES;
2206 GST_neighbours_iterate (&test_connection_ok,
2212 * Free the given entry in the blacklist.
2215 * @param key host identity (unused)
2216 * @param value the blacklist entry
2217 * @return #GNUNET_OK (continue to iterate)
2220 free_blacklist_entry (void *cls,
2221 const struct GNUNET_PeerIdentity *key,
2226 GNUNET_free_non_null (be);
2232 * Set traffic metric to manipulate
2234 * @param cls closure
2235 * @param message containing information
2238 handle_client_set_metric (void *cls,
2239 const struct TrafficMetricMessage *tm)
2241 struct TransportClient *tc = cls;
2243 GST_manipulation_set_metric (tm);
2244 GNUNET_SERVICE_client_continue (tc->client);
2249 * Function called when the service shuts down. Unloads our plugins
2250 * and cancels pending validations.
2252 * @param cls closure, unused
2255 shutdown_task (void *cls)
2257 struct AddressToStringContext *cur;
2259 GST_neighbours_stop ();
2260 GST_plugins_unload ();
2261 GST_validation_stop ();
2263 GNUNET_ATS_scheduling_done (GST_ats);
2265 GNUNET_ATS_connectivity_done (GST_ats_connect);
2266 GST_ats_connect = NULL;
2267 GNUNET_ATS_scanner_done (GST_is);
2269 while (NULL != (cur = a2s_head))
2271 GNUNET_CONTAINER_DLL_remove (a2s_head,
2276 if (NULL != plugin_nc)
2278 GNUNET_notification_context_destroy (plugin_nc);
2281 GNUNET_CONTAINER_multipeermap_destroy (active_stccs);
2282 active_stccs = NULL;
2283 if (NULL != blacklist)
2285 GNUNET_CONTAINER_multipeermap_iterate (blacklist,
2286 &free_blacklist_entry,
2288 GNUNET_CONTAINER_multipeermap_destroy (blacklist);
2292 GST_manipulation_stop ();
2294 if (NULL != GST_peerinfo)
2296 GNUNET_PEERINFO_disconnect (GST_peerinfo);
2297 GST_peerinfo = NULL;
2299 if (NULL != GST_stats)
2301 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
2304 if (NULL != GST_my_private_key)
2306 GNUNET_free (GST_my_private_key);
2307 GST_my_private_key = NULL;
2313 * Perform next action in the blacklist check.
2315 * @param cls the `struct GST_BlacklistCheck *`
2318 do_blacklist_check (void *cls)
2320 struct GST_BlacklistCheck *bc = cls;
2321 struct TransportClient *tc;
2322 struct GNUNET_MQ_Envelope *env;
2323 struct BlacklistMessage *bm;
2326 while (NULL != (tc = bc->bl_pos))
2328 if (CT_BLACKLIST == tc->type)
2330 bc->bl_pos = tc->next;
2334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2335 "No other blacklist clients active, will allow neighbour `%s'\n",
2336 GNUNET_i2s (&bc->peer));
2338 bc->cont (bc->cont_cls,
2343 GST_blacklist_test_cancel (bc);
2346 if ( (NULL != tc->details.blacklist.bc) ||
2347 (GNUNET_NO != tc->details.blacklist.waiting_for_reply) )
2348 return; /* someone else busy with this client */
2349 tc->details.blacklist.bc = bc;
2350 env = GNUNET_MQ_msg (bm,
2351 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY);
2352 bm->is_allowed = htonl (0);
2353 bm->peer = bc->peer;
2354 GNUNET_MQ_send (tc->mq,
2356 if (GNUNET_YES == tc->details.blacklist.call_receive_done)
2358 tc->details.blacklist.call_receive_done = GNUNET_NO;
2359 GNUNET_SERVICE_client_continue (tc->client);
2361 tc->details.blacklist.waiting_for_reply = GNUNET_YES;
2366 * A blacklisting client has sent us reply. Process it.
2368 * @param cls the client
2369 * @param msg the blacklist-reply message that was sent
2372 handle_client_blacklist_reply (void *cls,
2373 const struct BlacklistMessage *msg)
2375 struct TransportClient *tc = cls;
2376 struct GST_BlacklistCheck *bc;
2378 if (CT_BLACKLIST != tc->type)
2381 GNUNET_SERVICE_client_drop (tc->client);
2384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2385 "Blacklist client %p sent reply for `%s'\n",
2387 GNUNET_i2s (&msg->peer));
2388 bc = tc->details.blacklist.bc;
2389 tc->details.blacklist.bc = NULL;
2390 tc->details.blacklist.waiting_for_reply = GNUNET_NO;
2391 tc->details.blacklist.call_receive_done = GNUNET_YES;
2394 /* only run this if the blacklist check has not been
2395 * cancelled in the meantime... */
2396 GNUNET_assert (bc->bl_pos == tc);
2397 if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
2399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2400 "Blacklist check failed, peer not allowed\n");
2401 /* For the duration of the continuation, make the ongoing
2402 check invisible (to avoid double-cancellation); then
2403 add it back again so we can re-use GST_blacklist_test_cancel() */
2404 GNUNET_CONTAINER_DLL_remove (bc_head,
2407 bc->cont (bc->cont_cls,
2412 GNUNET_CONTAINER_DLL_insert (bc_head,
2415 GST_blacklist_test_cancel (bc);
2416 tc->details.blacklist.call_receive_done = GNUNET_NO;
2417 GNUNET_SERVICE_client_continue (tc->client);
2422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2423 "Blacklist check succeeded, continuing with checks\n");
2424 tc->details.blacklist.call_receive_done = GNUNET_NO;
2425 GNUNET_SERVICE_client_continue (tc->client);
2426 bc->bl_pos = tc->next;
2427 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
2431 /* check if any other blacklist checks are waiting for this blacklister */
2432 for (bc = bc_head; bc != NULL; bc = bc->next)
2433 if ( (bc->bl_pos == tc) &&
2434 (NULL == bc->task) )
2436 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
2444 * Add the given peer to the blacklist (for the given transport).
2446 * @param peer peer to blacklist
2447 * @param transport_name transport to blacklist for this peer, NULL for all
2450 GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
2451 const char *transport_name)
2453 char *transport = NULL;
2455 if (NULL != transport_name)
2457 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2458 "Adding peer `%s' with plugin `%s' to blacklist\n",
2461 transport = GNUNET_strdup (transport_name);
2464 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2465 "Adding peer `%s' with all plugins to blacklist\n",
2467 if (NULL == blacklist)
2469 GNUNET_CONTAINER_multipeermap_create (TRANSPORT_BLACKLIST_HT_SIZE,
2472 GNUNET_CONTAINER_multipeermap_put (blacklist,
2475 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2480 * Abort blacklist if @a address and @a session match.
2482 * @param address address used to abort matching checks
2483 * @param session session used to abort matching checks
2486 GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
2487 struct GNUNET_ATS_Session *session)
2489 struct GST_BlacklistCheck *bc;
2490 struct GST_BlacklistCheck *n;
2493 while (NULL != (bc = n))
2496 if ( (bc->session == session) &&
2497 (0 == GNUNET_HELLO_address_cmp (bc->address,
2500 bc->cont (bc->cont_cls,
2505 GST_blacklist_test_cancel (bc);
2512 * Test if the given blacklist entry matches. If so,
2513 * abort the iteration.
2515 * @param cls the transport name to match (const char*)
2516 * @param key the key (unused)
2517 * @param value the 'char *' (name of a blacklisted transport)
2518 * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches
2521 test_blacklisted (void *cls,
2522 const struct GNUNET_PeerIdentity *key,
2525 const char *transport_name = cls;
2528 /* Blacklist entry be:
2529 * (NULL == be): peer is blacklisted with all plugins
2530 * (NULL != be): peer is blacklisted for a specific plugin
2532 * If (NULL != transport_name) we look for a transport specific entry:
2533 * if (transport_name == be) forbidden
2537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2538 "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n",
2540 (NULL == transport_name) ? "unspecified" : transport_name,
2541 (NULL == be) ? "all plugins" : be);
2542 /* all plugins for this peer were blacklisted: disallow */
2546 /* blacklist check for specific transport */
2547 if ( (NULL != transport_name) &&
2550 if (0 == strcmp (transport_name,
2552 return GNUNET_NO; /* plugin is blacklisted! */
2559 * Test if a peer/transport combination is blacklisted.
2561 * @param peer the identity of the peer to test
2562 * @param transport_name name of the transport to test, never NULL
2563 * @param cont function to call with result
2564 * @param cont_cls closure for @a cont
2565 * @param address address to pass back to @a cont, can be NULL
2566 * @param session session to pass back to @a cont, can be NULL
2567 * @return handle to the blacklist check, NULL if the decision
2568 * was made instantly and @a cont was already called
2570 struct GST_BlacklistCheck *
2571 GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
2572 const char *transport_name,
2573 GST_BlacklistTestContinuation cont,
2575 const struct GNUNET_HELLO_Address *address,
2576 struct GNUNET_ATS_Session *session)
2578 struct GST_BlacklistCheck *bc;
2579 struct TransportClient *tc;
2581 GNUNET_assert (NULL != peer);
2582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2583 "Blacklist check for peer `%s':%s\n",
2585 (NULL != transport_name) ? transport_name : "unspecified");
2587 /* Check local blacklist by iterating over hashmap
2588 * If iteration is aborted, we found a matching blacklist entry */
2589 if ((NULL != blacklist) &&
2591 GNUNET_CONTAINER_multipeermap_get_multiple (blacklist, peer,
2593 (void *) transport_name)))
2595 /* Disallowed by config, disapprove instantly */
2596 GNUNET_STATISTICS_update (GST_stats,
2597 gettext_noop ("# disconnects due to blacklist"),
2600 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2601 _("Disallowing connection to peer `%s' on transport %s\n"),
2603 (NULL != transport_name) ? transport_name : "unspecified");
2613 for (tc = clients_head; NULL != tc; tc = tc->next)
2614 if (CT_BLACKLIST == tc->type)
2618 /* no blacklist clients, approve instantly */
2625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2626 "Allowing connection to peer `%s' %s\n",
2628 (NULL != transport_name) ? transport_name : "");
2632 /* need to query blacklist clients */
2633 bc = GNUNET_new (struct GST_BlacklistCheck);
2634 GNUNET_CONTAINER_DLL_insert (bc_head,
2638 bc->address = GNUNET_HELLO_address_copy (address);
2639 bc->session = session;
2641 bc->cont_cls = cont_cls;
2643 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
2650 * Cancel a blacklist check.
2652 * @param bc check to cancel
2655 GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc)
2657 GNUNET_CONTAINER_DLL_remove (bc_head,
2660 if (NULL != bc->bl_pos)
2662 if ( (CT_BLACKLIST == bc->bl_pos->type) &&
2663 (bc->bl_pos->details.blacklist.bc == bc) )
2665 /* we're at the head of the queue, remove us! */
2666 bc->bl_pos->details.blacklist.bc = NULL;
2669 if (NULL != bc->task)
2671 GNUNET_SCHEDULER_cancel (bc->task);
2674 GNUNET_free_non_null (bc->address);
2680 * Function to iterate over options in the blacklisting section for a peer.
2682 * @param cls closure
2683 * @param section name of the section
2684 * @param option name of the option
2685 * @param value value of the option
2688 blacklist_cfg_iter (void *cls,
2689 const char *section,
2693 unsigned int *res = cls;
2694 struct GNUNET_PeerIdentity peer;
2699 GNUNET_CRYPTO_eddsa_public_key_from_string (option,
2704 if ((NULL == value) || (0 == strcmp(value, "")))
2706 /* Blacklist whole peer */
2707 GST_blacklist_add_peer (&peer, NULL);
2708 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2709 _("Adding blacklisting entry for peer `%s'\n"),
2710 GNUNET_i2s (&peer));
2714 plugs = GNUNET_strdup (value);
2715 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
2717 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2718 _("Adding blacklisting entry for peer `%s':`%s'\n"),
2719 GNUNET_i2s (&peer), pos);
2720 GST_blacklist_add_peer (&peer, pos);
2722 GNUNET_free (plugs);
2729 * Read blacklist configuration
2731 * @param cfg the configuration handle
2732 * @param my_id my peer identity
2735 read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg,
2736 const struct GNUNET_PeerIdentity *my_id)
2739 unsigned int res = 0;
2741 GNUNET_snprintf (cfg_sect,
2743 "transport-blacklist-%s",
2744 GNUNET_i2s_full (my_id));
2745 GNUNET_CONFIGURATION_iterate_section_values (cfg,
2747 &blacklist_cfg_iter,
2749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2750 "Loaded %u blacklisting entries from configuration\n",
2756 * Initiate transport service.
2758 * @param cls closure
2759 * @param c configuration to use
2760 * @param service the initialized service
2764 const struct GNUNET_CONFIGURATION_Handle *c,
2765 struct GNUNET_SERVICE_Handle *service)
2768 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
2769 long long unsigned int max_fd_cfg;
2777 GNUNET_CONFIGURATION_get_value_filename (c,
2782 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2783 _("Transport service is lacking key configuration settings. Exiting.\n"));
2784 GNUNET_SCHEDULER_shutdown ();
2788 GNUNET_CONFIGURATION_get_value_time (c,
2793 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
2795 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
2796 GNUNET_free (keyfile);
2797 GNUNET_assert (NULL != pk);
2798 GST_my_private_key = pk;
2800 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
2801 GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg);
2802 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key,
2803 &GST_my_identity.public_key);
2804 GNUNET_assert (NULL != GST_my_private_key);
2806 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2807 "My identity is `%s'\n",
2808 GNUNET_i2s_full (&GST_my_identity));
2810 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
2812 if (NULL == GST_peerinfo)
2814 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2815 _("Could not access PEERINFO service. Exiting.\n"));
2816 GNUNET_SCHEDULER_shutdown ();
2823 struct rlimit r_file;
2825 if (0 == getrlimit (RLIMIT_NOFILE,
2828 max_fd_rlimit = r_file.rlim_cur;
2829 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2830 "Maximum number of open files was: %u/%u\n",
2831 (unsigned int) r_file.rlim_cur,
2832 (unsigned int) r_file.rlim_max);
2834 max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */
2838 GNUNET_CONFIGURATION_get_value_number (GST_cfg,
2842 max_fd_cfg = max_fd_rlimit;
2844 if (max_fd_cfg > max_fd_rlimit)
2845 max_fd = max_fd_cfg;
2847 max_fd = max_fd_rlimit;
2848 if (max_fd < DEFAULT_MAX_FDS)
2849 max_fd = DEFAULT_MAX_FDS;
2851 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2852 "Limiting number of sockets to %u: validation %u, neighbors: %u\n",
2857 friend_only = GNUNET_CONFIGURATION_get_value_yesno (GST_cfg,
2860 if (GNUNET_SYSERR == friend_only)
2861 friend_only = GNUNET_NO; /* According to topology defaults */
2862 /* start subsystems */
2863 read_blacklist_configuration (GST_cfg,
2865 GST_is = GNUNET_ATS_scanner_init ();
2866 GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg);
2867 GST_ats = GNUNET_ATS_scheduling_init (GST_cfg,
2868 &ats_request_address_change,
2871 GST_manipulation_init ();
2872 GST_plugins_load (&GST_manipulation_recv,
2873 &plugin_env_address_change_notification,
2874 &plugin_env_session_start,
2875 &plugin_env_session_end);
2876 GST_hello_start (friend_only,
2877 &process_hello_update,
2879 GST_neighbours_start ((max_fd / 3) * 2);
2880 active_stccs = GNUNET_CONTAINER_multipeermap_create (128,
2882 plugin_nc = GNUNET_notification_context_create (0);
2883 GST_validation_start ((max_fd / 3));
2888 * Define "main" method using service macro.
2892 GNUNET_SERVICE_OPTION_NONE,
2895 &client_disconnect_cb,
2897 GNUNET_MQ_hd_fixed_size (client_start,
2898 GNUNET_MESSAGE_TYPE_TRANSPORT_START,
2899 struct StartMessage,
2901 GNUNET_MQ_hd_var_size (client_hello,
2902 GNUNET_MESSAGE_TYPE_HELLO,
2903 struct GNUNET_MessageHeader,
2905 GNUNET_MQ_hd_var_size (client_send,
2906 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
2907 struct OutboundMessage,
2909 GNUNET_MQ_hd_var_size (client_address_to_string,
2910 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING,
2911 struct AddressLookupMessage,
2913 GNUNET_MQ_hd_fixed_size (client_monitor_peers,
2914 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST,
2915 struct PeerMonitorMessage,
2917 GNUNET_MQ_hd_fixed_size (client_blacklist_init,
2918 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
2919 struct GNUNET_MessageHeader,
2921 GNUNET_MQ_hd_fixed_size (client_blacklist_reply,
2922 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
2923 struct BlacklistMessage,
2925 GNUNET_MQ_hd_fixed_size (client_set_metric,
2926 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC,
2927 struct TrafficMetricMessage,
2929 GNUNET_MQ_hd_fixed_size (client_monitor_plugins,
2930 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START,
2931 struct GNUNET_MessageHeader,
2933 GNUNET_MQ_handler_end ());
2936 /* end of file gnunet-service-transport.c */