2 This file is part of GNUnet.
3 Copyright (C) 2010-2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @file transport/gnunet-service-transport.c
20 * @brief main for gnunet-service-transport
21 * @author Christian Grothoff
24 #include "gnunet_util_lib.h"
25 #include "gnunet_hello_lib.h"
26 #include "gnunet_statistics_service.h"
27 #include "gnunet_transport_service.h"
28 #include "gnunet_peerinfo_service.h"
29 #include "gnunet_ats_service.h"
30 #include "gnunet-service-transport.h"
31 #include "gnunet-service-transport_ats.h"
32 #include "gnunet-service-transport_hello.h"
33 #include "gnunet-service-transport_neighbours.h"
34 #include "gnunet-service-transport_plugins.h"
35 #include "gnunet-service-transport_validation.h"
36 #include "gnunet-service-transport_manipulation.h"
37 #include "transport.h"
40 * Size of the blacklist hash map.
42 #define TRANSPORT_BLACKLIST_HT_SIZE 64
45 * How many messages can we have pending for a given client process
46 * before we start to drop incoming messages? We typically should
47 * have only one client and so this would be the primary buffer for
48 * messages, so the number should be chosen rather generously.
50 * The expectation here is that most of the time the queue is large
51 * enough so that a drop is virtually never required. Note that
52 * this value must be about as large as 'TOTAL_MSGS' in the
53 * 'test_transport_api_reliability.c', otherwise that testcase may
56 #define MAX_PENDING (128 * 1024)
60 * Information we need for an asynchronous session kill.
62 struct GNUNET_ATS_SessionKiller
67 struct GNUNET_ATS_SessionKiller *next;
72 struct GNUNET_ATS_SessionKiller *prev;
77 struct GNUNET_ATS_Session *session;
80 * Plugin for the session.
82 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
87 struct GNUNET_SCHEDULER_Task *task;
92 * What type of client is the `struct TransportClient` about?
97 * We do not know yet (client is fresh).
102 * Is the CORE service, we need to forward traffic to it.
107 * It is a monitor, forward monitor data.
112 * It is a blacklist, query about allowed connections.
119 * Context we use when performing a blacklist check.
121 struct GST_BlacklistCheck;
124 * Client connected to the transport service.
126 struct TransportClient
130 * This is a doubly-linked list.
132 struct TransportClient *next;
135 * This is a doubly-linked list.
137 struct TransportClient *prev;
140 * Handle to the client.
142 struct GNUNET_SERVICE_Client *client;
145 * Message queue to the client.
147 struct GNUNET_MQ_Handle *mq;
150 * What type of client is this?
152 enum ClientType type;
157 * Peer identity to monitor the addresses of.
158 * Zero to monitor all neighbours. Valid if
159 * @e type is CT_MONITOR.
161 struct GNUNET_PeerIdentity monitor_peer;
164 * Additional details if @e type is CT_BLACKLIST.
169 * Blacklist check that we're currently performing (or NULL
170 * if we're performing one that has been cancelled).
172 struct GST_BlacklistCheck *bc;
175 * Set to #GNUNET_YES if we're currently waiting for a reply.
177 int waiting_for_reply;
180 * #GNUNET_YES if we have to call receive_done for this client
182 int call_receive_done;
193 * Context we use when performing a blacklist check.
195 struct GST_BlacklistCheck
199 * This is a linked list.
201 struct GST_BlacklistCheck *next;
204 * This is a linked list.
206 struct GST_BlacklistCheck *prev;
209 * Peer being checked.
211 struct GNUNET_PeerIdentity peer;
214 * Continuation to call with the result.
216 GST_BlacklistTestContinuation cont;
219 * Closure for @e cont.
224 * Address for #GST_blacklist_abort_matching(), can be NULL.
226 struct GNUNET_HELLO_Address *address;
229 * Session for #GST_blacklist_abort_matching(), can be NULL.
231 struct GNUNET_ATS_Session *session;
234 * Our current position in the blacklisters list.
236 struct TransportClient *bl_pos;
239 * Current task performing the check.
241 struct GNUNET_SCHEDULER_Task *task;
247 * Context for address to string operations
249 struct AddressToStringContext
252 * This is a doubly-linked list.
254 struct AddressToStringContext *next;
257 * This is a doubly-linked list.
259 struct AddressToStringContext *prev;
262 * Client that made the request.
264 struct TransportClient* tc;
269 * Closure for #handle_send_transmit_continuation()
271 struct SendTransmitContinuationContext
275 * Client that made the request.
277 struct TransportClient *tc;
280 * Peer that was the target.
282 struct GNUNET_PeerIdentity target;
285 * At what time did we receive the message?
287 struct GNUNET_TIME_Absolute send_time;
290 * Unique ID, for logging.
292 unsigned long long uuid;
295 * Set to #GNUNET_YES if the connection for @e target goes
296 * down and we thus must no longer send the
297 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK message.
304 * Head of linked list of all clients to this service.
306 static struct TransportClient *clients_head;
309 * Tail of linked list of all clients to this service.
311 static struct TransportClient *clients_tail;
314 * Map of peer identities to active send transmit continuation
315 * contexts. Used to flag contexts as 'dead' when a connection goes
316 * down. Values are of type `struct SendTransmitContinuationContext
319 static struct GNUNET_CONTAINER_MultiPeerMap *active_stccs;
322 * Head of linked list of all pending address iterations
324 static struct AddressToStringContext *a2s_head;
327 * Tail of linked list of all pending address iterations
329 static struct AddressToStringContext *a2s_tail;
332 * Head of DLL of active blacklisting queries.
334 static struct GST_BlacklistCheck *bc_head;
337 * Tail of DLL of active blacklisting queries.
339 static struct GST_BlacklistCheck *bc_tail;
342 * Hashmap of blacklisted peers. Values are of type 'char *' (transport names),
343 * can be NULL if we have no static blacklist.
345 static struct GNUNET_CONTAINER_MultiPeerMap *blacklist;
348 * Notification context, to send updates on changes to active plugin
351 static struct GNUNET_NotificationContext *plugin_nc;
354 * Plugin monitoring client we are currently syncing, NULL if all
355 * monitoring clients are in sync.
357 static struct TransportClient *sync_client;
360 * Peer identity that is all zeros, used as a way to indicate
361 * "all peers". Used for comparissons.
363 static struct GNUNET_PeerIdentity all_zeros;
368 struct GNUNET_STATISTICS_Handle *GST_stats;
371 * Configuration handle.
373 const struct GNUNET_CONFIGURATION_Handle *GST_cfg;
376 * Configuration handle.
378 struct GNUNET_PeerIdentity GST_my_identity;
381 * Handle to peerinfo service.
383 struct GNUNET_PEERINFO_Handle *GST_peerinfo;
388 struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key;
391 * ATS scheduling handle.
393 struct GNUNET_ATS_SchedulingHandle *GST_ats;
396 * ATS connectivity handle.
398 struct GNUNET_ATS_ConnectivityHandle *GST_ats_connect;
401 * Hello address expiration
403 struct GNUNET_TIME_Relative hello_expiration;
406 * Head of DLL of asynchronous tasks to kill sessions.
408 static struct GNUNET_ATS_SessionKiller *sk_head;
411 * Tail of DLL of asynchronous tasks to kill sessions.
413 static struct GNUNET_ATS_SessionKiller *sk_tail;
416 * Interface scanner determines our LAN address range(s).
418 struct GNUNET_ATS_InterfaceScanner *GST_is;
422 * Queue the given message for transmission to the given client
424 * @param tc target of the message
425 * @param msg message to transmit
426 * @param may_drop #GNUNET_YES if the message can be dropped
429 unicast (struct TransportClient *tc,
430 const struct GNUNET_MessageHeader *msg,
433 struct GNUNET_MQ_Envelope *env;
435 if ( (GNUNET_MQ_get_length (tc->mq) >= MAX_PENDING) &&
436 (GNUNET_YES == may_drop) )
438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
439 "Dropping message of type %u and size %u, have %u/%u messages pending\n",
442 GNUNET_MQ_get_length (tc->mq),
444 GNUNET_STATISTICS_update (GST_stats,
446 ("# messages dropped due to slow client"), 1,
450 env = GNUNET_MQ_msg_copy (msg);
451 GNUNET_MQ_send (tc->mq,
457 * Called whenever a client connects. Allocates our
458 * data structures associated with that client.
460 * @param cls closure, NULL
461 * @param client identification of the client
462 * @param mq message queue for the client
463 * @return our `struct TransportClient`
466 client_connect_cb (void *cls,
467 struct GNUNET_SERVICE_Client *client,
468 struct GNUNET_MQ_Handle *mq)
470 struct TransportClient *tc;
472 tc = GNUNET_new (struct TransportClient);
475 GNUNET_CONTAINER_DLL_insert (clients_head,
478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
479 "Client %p connected\n",
486 * Perform next action in the blacklist check.
488 * @param cls the `struct BlacklistCheck*`
491 do_blacklist_check (void *cls);
495 * Mark the peer as down so we don't call the continuation
496 * context in the future.
498 * @param cls a `struct TransportClient`
499 * @param peer a peer we are sending to
500 * @param value a `struct SendTransmitContinuationContext` to mark
501 * @return #GNUNET_OK (continue to iterate)
504 mark_match_down (void *cls,
505 const struct GNUNET_PeerIdentity *peer,
508 struct TransportClient *tc = cls;
509 struct SendTransmitContinuationContext *stcc = value;
513 stcc->down = GNUNET_YES;
521 * Called whenever a client is disconnected. Frees our
522 * resources associated with that client.
524 * @param cls closure, NULL
525 * @param client identification of the client
526 * @param app_ctx our `struct TransportClient`
529 client_disconnect_cb (void *cls,
530 struct GNUNET_SERVICE_Client *client,
533 struct TransportClient *tc = app_ctx;
534 struct GST_BlacklistCheck *bc;
536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
537 "Client %p disconnected, cleaning up.\n",
539 GNUNET_CONTAINER_multipeermap_iterate (active_stccs,
542 for (struct AddressToStringContext *cur = a2s_head;
549 GNUNET_CONTAINER_DLL_remove (clients_head,
561 for (bc = bc_head; NULL != bc; bc = bc->next)
563 if (bc->bl_pos != tc)
565 bc->bl_pos = tc->next;
566 if (NULL == bc->task)
567 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
577 * Function called for each of our connected neighbours. Notify the
578 * client about the existing neighbour.
580 * @param cls the `struct TransportClient *` to notify
581 * @param peer identity of the neighbour
582 * @param address the address
583 * @param state the current state of the peer
584 * @param state_timeout the time out for the state
585 * @param bandwidth_in inbound bandwidth in NBO
586 * @param bandwidth_out outbound bandwidth in NBO
589 notify_client_about_neighbour (void *cls,
590 const struct GNUNET_PeerIdentity *peer,
591 const struct GNUNET_HELLO_Address *address,
592 enum GNUNET_TRANSPORT_PeerState state,
593 struct GNUNET_TIME_Absolute state_timeout,
594 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
595 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
597 struct TransportClient *tc = cls;
598 struct ConnectInfoMessage cim;
600 if (GNUNET_NO == GST_neighbours_test_connected (peer))
602 cim.header.size = htons (sizeof (struct ConnectInfoMessage));
603 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
605 cim.quota_in = bandwidth_in;
606 cim.quota_out = bandwidth_out;
614 * Initialize a normal client. We got a start message from this
615 * client, add it to the list of clients for broadcasting of inbound
618 * @param cls the client
619 * @param start the start message that was sent
622 handle_client_start (void *cls,
623 const struct StartMessage *start)
625 struct TransportClient *tc = cls;
626 const struct GNUNET_MessageHeader *hello;
629 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
630 "Client %p sent START\n",
632 options = ntohl (start->options);
633 if ((0 != (1 & options)) &&
635 memcmp (&start->self,
637 sizeof (struct GNUNET_PeerIdentity))))
639 /* client thinks this is a different peer, reject */
641 GNUNET_SERVICE_client_drop (tc->client);
644 if (CT_NONE != tc->type)
647 GNUNET_SERVICE_client_drop (tc->client);
650 if (0 != (2 & options))
652 hello = GST_hello_get ();
657 GST_neighbours_iterate (¬ify_client_about_neighbour,
659 GNUNET_SERVICE_client_continue (tc->client);
664 * Client sent us a HELLO. Check the request.
666 * @param cls the client
667 * @param message the HELLO message
670 check_client_hello (void *cls,
671 const struct GNUNET_MessageHeader *message)
673 return GNUNET_OK; /* FIXME: check here? */
678 * Client sent us a HELLO. Process the request.
680 * @param cls the client
681 * @param message the HELLO message
684 handle_client_hello (void *cls,
685 const struct GNUNET_MessageHeader *message)
687 struct TransportClient *tc = cls;
689 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
690 "Received HELLO message\n");
691 GST_validation_handle_hello (message);
692 GNUNET_SERVICE_client_continue (tc->client);
697 * Function called after the transmission is done. Notify the client that it is
698 * OK to send the next message.
701 * @param success #GNUNET_OK on success, #GNUNET_NO on failure, #GNUNET_SYSERR if we're not connected
702 * @param bytes_payload bytes payload sent
703 * @param bytes_on_wire bytes sent on wire
706 handle_send_transmit_continuation (void *cls,
708 size_t bytes_payload,
709 size_t bytes_on_wire)
711 struct SendTransmitContinuationContext *stcc = cls;
712 struct SendOkMessage send_ok_msg;
713 struct GNUNET_TIME_Relative delay;
714 const struct GNUNET_HELLO_Address *addr;
716 delay = GNUNET_TIME_absolute_get_duration (stcc->send_time);
717 addr = GST_neighbour_get_current_address (&stcc->target);
718 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
719 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
720 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
721 GNUNET_STRINGS_relative_time_to_string (delay,
723 (unsigned int) bytes_payload,
724 (unsigned int) bytes_on_wire,
725 GNUNET_i2s (&stcc->target),
727 (NULL != addr) ? addr->transport_name : "%");
729 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
730 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
731 GNUNET_STRINGS_relative_time_to_string (delay,
733 (unsigned int) bytes_payload,
734 (unsigned int) bytes_on_wire,
735 GNUNET_i2s (&stcc->target),
737 (NULL != addr) ? addr->transport_name : "%");
739 if (GNUNET_NO == stcc->down)
741 /* Only send confirmation if we are still connected */
742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
743 "Sending SEND_OK for transmission request %llu\n",
745 send_ok_msg.header.size = htons (sizeof (send_ok_msg));
746 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
747 send_ok_msg.bytes_msg = htonl (bytes_payload);
748 send_ok_msg.bytes_physical = htonl (bytes_on_wire);
749 send_ok_msg.success = htonl (success);
750 send_ok_msg.peer = stcc->target;
755 GNUNET_assert (GNUNET_OK ==
756 GNUNET_CONTAINER_multipeermap_remove (active_stccs,
764 * Client asked for transmission to a peer. Process the request.
766 * @param cls the client
767 * @param obm the send message that was sent
770 check_client_send (void *cls,
771 const struct OutboundMessage *obm)
774 const struct GNUNET_MessageHeader *obmm;
776 size = ntohs (obm->header.size) - sizeof (struct OutboundMessage);
777 if (size < sizeof (struct GNUNET_MessageHeader))
780 return GNUNET_SYSERR;
782 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
783 if (size != ntohs (obmm->size))
786 return GNUNET_SYSERR;
793 * Client asked for transmission to a peer. Process the request.
795 * @param cls the client
796 * @param obm the send message that was sent
799 handle_client_send (void *cls,
800 const struct OutboundMessage *obm)
802 static unsigned long long uuid_gen;
803 struct TransportClient *tc = cls;
804 const struct GNUNET_MessageHeader *obmm;
805 struct SendTransmitContinuationContext *stcc;
807 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
808 if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer))
810 /* not connected, not allowed to send; can happen due to asynchronous operations */
811 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
812 "Could not send message to peer `%s': not connected\n",
813 GNUNET_i2s (&obm->peer));
814 GNUNET_STATISTICS_update (GST_stats,
816 ("# bytes payload dropped (other peer was not connected)"),
819 GNUNET_SERVICE_client_continue (tc->client);
822 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
823 "Received SEND request %llu for `%s' and first message of type %u and total size %u\n",
825 GNUNET_i2s (&obm->peer),
828 GNUNET_SERVICE_client_continue (tc->client);
830 stcc = GNUNET_new (struct SendTransmitContinuationContext);
831 stcc->target = obm->peer;
833 stcc->send_time = GNUNET_TIME_absolute_get ();
834 stcc->uuid = uuid_gen++;
835 (void) GNUNET_CONTAINER_multipeermap_put (active_stccs,
838 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
839 GST_manipulation_send (&obm->peer,
842 GNUNET_TIME_relative_ntoh (obm->timeout),
843 &handle_send_transmit_continuation,
849 * Take the given address and append it to the set of results sent back to
850 * the client. This function may be called serveral times for a single
851 * conversion. The last invocation will be with a @a address of
852 * NULL and a @a res of #GNUNET_OK. Thus, to indicate conversion
853 * errors, the callback might be called first with @a address NULL and
854 * @a res being #GNUNET_SYSERR. In that case, there will still be a
855 * subsequent call later with @a address NULL and @a res #GNUNET_OK.
857 * @param cls the `struct AddressToStringContext`
858 * @param buf text to transmit (contains the human-readable address, or NULL)
859 * @param res #GNUNET_OK if conversion was successful, #GNUNET_SYSERR on error,
863 transmit_address_to_client (void *cls,
867 struct AddressToStringContext *actx = cls;
868 struct GNUNET_MQ_Envelope *env;
869 struct AddressToStringResultMessage *atsm;
872 GNUNET_assert ( (GNUNET_OK == res) ||
873 (GNUNET_SYSERR == res) );
874 if (NULL == actx->tc)
878 env = GNUNET_MQ_msg (atsm,
879 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
880 if (GNUNET_OK == res)
882 /* this was the last call, transmit */
883 atsm->res = htonl (GNUNET_OK);
884 atsm->addr_len = htonl (0);
885 GNUNET_MQ_send (actx->tc->mq,
887 GNUNET_CONTAINER_DLL_remove (a2s_head,
893 if (GNUNET_SYSERR == res)
895 /* address conversion failed, but there will be more callbacks */
896 atsm->res = htonl (GNUNET_SYSERR);
897 atsm->addr_len = htonl (0);
898 GNUNET_MQ_send (actx->tc->mq,
903 GNUNET_assert (GNUNET_OK == res);
904 /* succesful conversion, append*/
905 slen = strlen (buf) + 1;
906 env = GNUNET_MQ_msg_extra (atsm,
908 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
909 atsm->res = htonl (GNUNET_YES);
910 atsm->addr_len = htonl (slen);
911 GNUNET_memcpy (&atsm[1],
914 GNUNET_MQ_send (actx->tc->mq,
920 * Client asked to resolve an address. Check the request.
922 * @param cls the client
923 * @param alum the resolution request
924 * @return #GNUNET_OK if @a alum is well-formed
927 check_client_address_to_string (void *cls,
928 const struct AddressLookupMessage *alum)
930 const char *plugin_name;
932 uint32_t address_len;
935 size = ntohs (alum->header.size);
936 address_len = ntohs (alum->addrlen);
937 if (size <= sizeof (struct AddressLookupMessage) + address_len)
940 return GNUNET_SYSERR;
942 address = (const char *) &alum[1];
943 plugin_name = (const char *) &address[address_len];
944 if ('\0' != plugin_name[size - sizeof (struct AddressLookupMessage) - address_len - 1])
947 return GNUNET_SYSERR;
954 * Client asked to resolve an address. Process the request.
956 * @param cls the client
957 * @param alum the resolution request
960 handle_client_address_to_string (void *cls,
961 const struct AddressLookupMessage *alum)
963 struct TransportClient *tc = cls;
964 struct GNUNET_TRANSPORT_PluginFunctions *papi;
965 const char *plugin_name;
967 uint32_t address_len;
968 struct AddressToStringContext *actx;
969 struct GNUNET_MQ_Envelope *env;
970 struct AddressToStringResultMessage *atsm;
971 struct GNUNET_TIME_Relative rtimeout;
974 address_len = ntohs (alum->addrlen);
975 address = (const char *) &alum[1];
976 plugin_name = (const char *) &address[address_len];
977 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
978 numeric = ntohs (alum->numeric_only);
979 papi = GST_plugins_printer_find (plugin_name);
982 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
983 "Failed to find plugin `%s'\n",
985 env = GNUNET_MQ_msg (atsm,
986 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
987 atsm->res = htonl (GNUNET_SYSERR);
988 atsm->addr_len = htonl (0);
989 GNUNET_MQ_send (tc->mq,
991 env = GNUNET_MQ_msg (atsm,
992 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
993 atsm->res = htonl (GNUNET_OK);
994 atsm->addr_len = htonl (0);
995 GNUNET_MQ_send (tc->mq,
999 actx = GNUNET_new (struct AddressToStringContext);
1001 GNUNET_CONTAINER_DLL_insert (a2s_head,
1004 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1005 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1006 "Pretty-printing address of %u bytes using plugin `%s'\n",
1009 papi->address_pretty_printer (papi->cls,
1015 &transmit_address_to_client,
1021 * Compose #PeerIterateResponseMessage using the given peer and address.
1023 * @param peer identity of the peer
1024 * @param address the address, NULL on disconnect
1025 * @return composed message
1027 static struct PeerIterateResponseMessage *
1028 compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer,
1029 const struct GNUNET_HELLO_Address *address)
1031 struct PeerIterateResponseMessage *msg;
1037 GNUNET_assert (NULL != peer);
1038 if (NULL != address)
1040 tlen = strlen (address->transport_name) + 1;
1041 alen = address->address_length;
1048 size = (sizeof (struct PeerIterateResponseMessage) + alen + tlen);
1049 msg = GNUNET_malloc (size);
1050 msg->header.size = htons (size);
1052 = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE);
1053 msg->reserved = htonl (0);
1055 msg->addrlen = htonl (alen);
1056 msg->pluginlen = htonl (tlen);
1058 if (NULL != address)
1060 msg->local_address_info = htonl((uint32_t) address->local_info);
1061 addr = (char *) &msg[1];
1062 GNUNET_memcpy (addr,
1065 GNUNET_memcpy (&addr[alen],
1066 address->transport_name,
1074 * Context for #send_validation_information() and
1075 * #send_peer_information().
1077 struct IterationContext
1080 * Context to use for the transmission.
1082 struct TransportClient *tc;
1085 * Which peers do we care about?
1087 struct GNUNET_PeerIdentity id;
1090 * #GNUNET_YES if @e id should be ignored because we want all peers.
1097 * Output information of neighbours to the given client.
1099 * @param cls the `struct PeerIterationContext *`
1100 * @param peer identity of the neighbour
1101 * @param address the address
1102 * @param state current state this peer is in
1103 * @param state_timeout timeout for the current state of the peer
1104 * @param bandwidth_in inbound quota in NBO
1105 * @param bandwidth_out outbound quota in NBO
1108 send_peer_information (void *cls,
1109 const struct GNUNET_PeerIdentity *peer,
1110 const struct GNUNET_HELLO_Address *address,
1111 enum GNUNET_TRANSPORT_PeerState state,
1112 struct GNUNET_TIME_Absolute state_timeout,
1113 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1114 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1116 struct IterationContext *pc = cls;
1117 struct GNUNET_MQ_Envelope *env;
1118 struct PeerIterateResponseMessage *msg;
1120 if ( (GNUNET_YES != pc->all) &&
1125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1126 "Sending information about `%s' using address `%s' in state `%s'\n",
1128 (NULL != address) ? GST_plugins_a2s (address) : "<none>",
1129 GNUNET_TRANSPORT_ps2s (state));
1130 msg = compose_address_iterate_response_message (peer,
1132 msg->state = htonl (state);
1133 msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout);
1134 env = GNUNET_MQ_msg_copy (&msg->header);
1136 GNUNET_MQ_send (pc->tc->mq,
1142 * Client asked to obtain information about a specific or all peers
1143 * Process the request.
1145 * @param cls the client
1146 * @param msg the peer address information request
1149 handle_client_monitor_peers (void *cls,
1150 const struct PeerMonitorMessage *msg)
1152 struct TransportClient *tc = cls;
1153 struct IterationContext pc;
1155 if (CT_NONE != tc->type)
1158 GNUNET_SERVICE_client_drop (tc->client);
1161 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1162 GNUNET_SERVICE_client_mark_monitor (tc->client);
1164 /* Send initial list */
1166 if (0 == memcmp (&msg->peer,
1168 sizeof (struct GNUNET_PeerIdentity)))
1170 /* iterate over all neighbours */
1171 pc.all = GNUNET_YES;
1176 /* just return one neighbour */
1180 GST_neighbours_iterate (&send_peer_information,
1183 if (GNUNET_YES != ntohl (msg->one_shot))
1185 tc->details.monitor_peer = msg->peer;
1186 tc->type = CT_MONITOR;
1187 if (0 != memcmp (&msg->peer,
1189 sizeof (struct GNUNET_PeerIdentity)))
1190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1191 "Client %p started monitoring of the peer `%s'\n",
1193 GNUNET_i2s (&msg->peer));
1195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1196 "Client %p started monitoring all peers\n",
1201 struct GNUNET_MessageHeader *msg;
1202 struct GNUNET_MQ_Envelope *env;
1204 env = GNUNET_MQ_msg (msg,
1205 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END);
1206 GNUNET_MQ_send (tc->mq,
1213 * Function called by the plugin with information about the
1214 * current sessions managed by the plugin (for monitoring).
1216 * @param cls closure
1217 * @param session session handle this information is about,
1218 * NULL to indicate that we are "in sync" (initial
1219 * iteration complete)
1220 * @param info information about the state of the session,
1221 * NULL if @a session is also NULL and we are
1222 * merely signalling that the initial iteration is over
1225 plugin_session_info_cb (void *cls,
1226 struct GNUNET_ATS_Session *session,
1227 const struct GNUNET_TRANSPORT_SessionInfo *info)
1229 struct GNUNET_MQ_Envelope *env;
1230 struct TransportPluginMonitorMessage *msg;
1231 struct GNUNET_MessageHeader *sync;
1238 if (0 == GNUNET_notification_context_get_size (plugin_nc))
1240 GST_plugins_monitor_subscribe (NULL,
1244 if ( (NULL == info) &&
1247 /* end of initial iteration */
1248 if (NULL != sync_client)
1250 env = GNUNET_MQ_msg (sync,
1251 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC);
1252 GNUNET_MQ_send (sync_client->mq,
1258 GNUNET_assert (NULL != info);
1259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1260 "Plugin event for peer %s on transport %s\n",
1261 GNUNET_i2s (&info->address->peer),
1262 info->address->transport_name);
1263 slen = strlen (info->address->transport_name) + 1;
1264 alen = info->address->address_length;
1265 size = sizeof (struct TransportPluginMonitorMessage) + slen + alen;
1266 if (size > UINT16_MAX)
1271 msg = GNUNET_malloc (size);
1272 msg->header.size = htons (size);
1273 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT);
1274 msg->session_state = htons ((uint16_t) info->state);
1275 msg->is_inbound = htons ((int16_t) info->is_inbound);
1276 msg->msgs_pending = htonl (info->num_msg_pending);
1277 msg->bytes_pending = htonl (info->num_bytes_pending);
1278 msg->timeout = GNUNET_TIME_absolute_hton (info->session_timeout);
1279 msg->delay = GNUNET_TIME_absolute_hton (info->receive_delay);
1280 msg->peer = info->address->peer;
1281 msg->session_id = (uint64_t) (intptr_t) session;
1282 msg->plugin_name_len = htons (slen);
1283 msg->plugin_address_len = htons (alen);
1284 name = (char *) &msg[1];
1285 GNUNET_memcpy (name,
1286 info->address->transport_name,
1289 GNUNET_memcpy (addr,
1290 info->address->address,
1292 if (NULL != sync_client)
1294 struct GNUNET_MQ_Envelope *env;
1296 env = GNUNET_MQ_msg_copy (&msg->header);
1297 GNUNET_MQ_send (sync_client->mq,
1302 GNUNET_notification_context_broadcast (plugin_nc,
1311 * Client asked to obtain information about all plugin connections.
1313 * @param cls the client
1314 * @param message the peer address information request
1317 handle_client_monitor_plugins (void *cls,
1318 const struct GNUNET_MessageHeader *message)
1320 struct TransportClient *tc = cls;
1322 GNUNET_SERVICE_client_mark_monitor (tc->client);
1323 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1324 GNUNET_notification_context_add (plugin_nc,
1326 GNUNET_assert (NULL == sync_client);
1328 GST_plugins_monitor_subscribe (&plugin_session_info_cb,
1334 * Broadcast the given message to all of our clients.
1336 * @param msg message to broadcast
1337 * @param may_drop #GNUNET_YES if the message can be dropped / is payload
1340 GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
1343 struct TransportClient *tc;
1346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1347 "Asked to broadcast message of type %u with %u bytes\n",
1348 (unsigned int) ntohs (msg->type),
1349 (unsigned int) ntohs (msg->size));
1351 for (tc = clients_head; NULL != tc; tc = tc->next)
1353 if ( (GNUNET_YES == may_drop) &&
1354 (CT_CORE != tc->type) )
1355 continue; /* skip, this client does not care about payload */
1361 if (GNUNET_NO == done)
1362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1363 "Message of type %u not delivered, is CORE service up?\n",
1369 * Broadcast the new active address to all clients monitoring the peer.
1371 * @param peer peer this update is about (never NULL)
1372 * @param address address, NULL on disconnect
1373 * @param state the current state of the peer
1374 * @param state_timeout the time out for the state
1377 GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer,
1378 const struct GNUNET_HELLO_Address *address,
1379 enum GNUNET_TRANSPORT_PeerState state,
1380 struct GNUNET_TIME_Absolute state_timeout)
1382 struct GNUNET_MQ_Envelope *env;
1383 struct PeerIterateResponseMessage *msg;
1384 struct TransportClient *tc;
1386 msg = compose_address_iterate_response_message (peer,
1388 msg->state = htonl (state);
1389 msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout);
1390 for (tc = clients_head; NULL != tc; tc = tc->next)
1392 if (CT_MONITOR != tc->type)
1394 if ((0 == memcmp (&tc->details.monitor_peer,
1396 sizeof (struct GNUNET_PeerIdentity))) ||
1397 (0 == memcmp (&tc->details.monitor_peer,
1399 sizeof (struct GNUNET_PeerIdentity))))
1401 env = GNUNET_MQ_msg_copy (&msg->header);
1402 GNUNET_MQ_send (tc->mq,
1411 * Mark the peer as down so we don't call the continuation
1412 * context in the future.
1415 * @param peer peer that got disconnected
1416 * @param value a `struct SendTransmitContinuationContext` to mark
1417 * @return #GNUNET_OK (continue to iterate)
1420 mark_peer_down (void *cls,
1421 const struct GNUNET_PeerIdentity *peer,
1424 struct SendTransmitContinuationContext *stcc = value;
1426 stcc->down = GNUNET_YES;
1432 * Notify all clients about a disconnect, and cancel
1433 * pending SEND_OK messages for this peer.
1435 * @param peer peer that disconnected
1438 GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer)
1440 struct DisconnectInfoMessage disconnect_msg;
1442 GNUNET_CONTAINER_multipeermap_get_multiple (active_stccs,
1446 disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage));
1447 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
1448 disconnect_msg.reserved = htonl (0);
1449 disconnect_msg.peer = *peer;
1450 GST_clients_broadcast (&disconnect_msg.header,
1457 * Transmit our HELLO message to the given (connected) neighbour.
1459 * @param cls the 'HELLO' message
1460 * @param peer identity of the peer
1461 * @param address the address
1462 * @param state current state this peer is in
1463 * @param state_timeout timeout for the current state of the peer
1464 * @param bandwidth_in inbound quota in NBO
1465 * @param bandwidth_out outbound quota in NBO
1468 transmit_our_hello (void *cls,
1469 const struct GNUNET_PeerIdentity *peer,
1470 const struct GNUNET_HELLO_Address *address,
1471 enum GNUNET_TRANSPORT_PeerState state,
1472 struct GNUNET_TIME_Absolute state_timeout,
1473 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1474 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1476 const struct GNUNET_MessageHeader *hello = cls;
1481 sizeof (struct GNUNET_PeerIdentity)))
1482 return; /* not to ourselves */
1483 if (GNUNET_NO == GST_neighbours_test_connected (peer))
1486 GST_neighbours_send (peer,
1488 ntohs (hello->size),
1496 * My HELLO has changed. Tell everyone who should know.
1499 * @param hello new HELLO
1502 process_hello_update (void *cls,
1503 const struct GNUNET_MessageHeader *hello)
1505 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1506 "Broadcasting HELLO to clients\n");
1507 GST_clients_broadcast (hello, GNUNET_NO);
1508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1509 "Broadcasting HELLO to neighbours\n");
1510 GST_neighbours_iterate (&transmit_our_hello,
1516 * We received some payload. Prepare to pass it on to our clients.
1518 * @param address address and (claimed) identity of the other peer
1519 * @param session identifier used for this session (NULL for plugins
1520 * that do not offer bi-directional communication to the sender
1521 * using the same "connection")
1522 * @param message the message to process
1523 * @return how long the plugin should wait until receiving more data
1525 static struct GNUNET_TIME_Relative
1526 process_payload (const struct GNUNET_HELLO_Address *address,
1527 struct GNUNET_ATS_Session *session,
1528 const struct GNUNET_MessageHeader *message)
1530 struct GNUNET_TIME_Relative ret;
1532 struct InboundMessage *im;
1533 size_t msg_size = ntohs (message->size);
1534 size_t size = sizeof(struct InboundMessage) + msg_size;
1535 char buf[size] GNUNET_ALIGN;
1537 do_forward = GNUNET_SYSERR;
1538 ret = GST_neighbours_calculate_receive_delay (&address->peer,
1541 if (! GST_neighbours_test_connected (&address->peer))
1543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1544 "Discarded %u bytes type %u payload from peer `%s'\n",
1545 (unsigned int) msg_size,
1546 ntohs (message->type),
1547 GNUNET_i2s (&address->peer));
1548 GNUNET_STATISTICS_update (GST_stats, gettext_noop
1549 ("# bytes payload discarded due to not connected peer"),
1555 if (GNUNET_YES != do_forward)
1557 im = (struct InboundMessage *) buf;
1558 im->header.size = htons (size);
1559 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
1560 im->peer = address->peer;
1561 GNUNET_memcpy (&im[1],
1563 ntohs (message->size));
1564 GST_clients_broadcast (&im->header,
1571 * Task to asynchronously terminate a session.
1573 * @param cls the `struct GNUNET_ATS_SessionKiller` with the information for the kill
1576 kill_session_task (void *cls)
1578 struct GNUNET_ATS_SessionKiller *sk = cls;
1581 GNUNET_CONTAINER_DLL_remove (sk_head,
1584 sk->plugin->disconnect_session (sk->plugin->cls,
1591 * Force plugin to terminate session due to communication
1594 * @param plugin_name name of the plugin
1595 * @param session session to termiante
1598 kill_session (const char *plugin_name,
1599 struct GNUNET_ATS_Session *session)
1601 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
1602 struct GNUNET_ATS_SessionKiller *sk;
1604 for (sk = sk_head; NULL != sk; sk = sk->next)
1605 if (sk->session == session)
1607 plugin = GST_plugins_find (plugin_name);
1613 /* need to issue disconnect asynchronously */
1614 sk = GNUNET_new (struct GNUNET_ATS_SessionKiller);
1615 sk->session = session;
1616 sk->plugin = plugin;
1617 sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task,
1619 GNUNET_CONTAINER_DLL_insert (sk_head,
1626 * Black list check result for try_connect call
1627 * If connection to the peer is allowed request adddress and ???
1629 * @param cls the message
1630 * @param peer the peer
1631 * @param address the address
1632 * @param session the session
1633 * @param result the result
1636 connect_bl_check_cont (void *cls,
1637 const struct GNUNET_PeerIdentity *peer,
1638 const struct GNUNET_HELLO_Address *address,
1639 struct GNUNET_ATS_Session *session,
1642 struct GNUNET_MessageHeader *msg = cls;
1644 if (GNUNET_OK == result)
1646 /* Blacklist allows to speak to this peer, forward SYN to neighbours */
1647 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1648 "Received SYN message from peer `%s' at `%s'\n",
1650 GST_plugins_a2s (address));
1652 GST_neighbours_handle_session_syn (msg,
1655 GST_blacklist_abort_matching (address,
1657 kill_session (address->transport_name,
1664 if (GNUNET_SYSERR == result)
1665 return; /* check was aborted, session destroyed */
1666 /* Blacklist denies to speak to this peer */
1667 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1668 "Discarding SYN message from `%s' due to denied blacklist check\n",
1670 kill_session (address->transport_name,
1676 * Function called by the transport for each received message.
1678 * @param cls closure, const char* with the name of the plugin we received the message from
1679 * @param address address and (claimed) identity of the other peer
1680 * @param message the message, NULL if we only care about
1681 * learning about the delay until we should receive again
1682 * @param session identifier used for this session (NULL for plugins
1683 * that do not offer bi-directional communication to the sender
1684 * using the same "connection")
1685 * @return how long the plugin should wait until receiving more data
1686 * (plugins that do not support this, can ignore the return value)
1688 struct GNUNET_TIME_Relative
1689 GST_receive_callback (void *cls,
1690 const struct GNUNET_HELLO_Address *address,
1691 struct GNUNET_ATS_Session *session,
1692 const struct GNUNET_MessageHeader *message)
1694 const char *plugin_name = cls;
1695 struct GNUNET_TIME_Relative ret;
1698 ret = GNUNET_TIME_UNIT_ZERO;
1699 if (NULL == message)
1701 type = ntohs (message->type);
1702 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1703 "Received message with type %u from peer `%s' at %s\n",
1705 GNUNET_i2s (&address->peer),
1706 GST_plugins_a2s (address));
1708 GNUNET_STATISTICS_update (GST_stats,
1709 gettext_noop ("# bytes total received"),
1710 ntohs (message->size),
1712 GST_neighbours_notify_data_recv (address,
1716 case GNUNET_MESSAGE_TYPE_HELLO_LEGACY:
1717 /* Legacy HELLO message, discard */
1719 case GNUNET_MESSAGE_TYPE_HELLO:
1720 if (GNUNET_OK != GST_validation_handle_hello (message))
1722 GNUNET_break_op (0);
1723 GST_blacklist_abort_matching (address,
1727 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
1728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1729 "Processing PING from `%s'\n",
1730 GST_plugins_a2s (address));
1732 GST_validation_handle_ping (&address->peer,
1737 GST_blacklist_abort_matching (address,
1739 kill_session (plugin_name,
1743 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
1744 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1745 "Processing PONG from `%s'\n",
1746 GST_plugins_a2s (address));
1748 GST_validation_handle_pong (&address->peer,
1751 GNUNET_break_op (0);
1752 GST_blacklist_abort_matching (address,
1754 kill_session (plugin_name, session);
1757 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN:
1758 /* Do blacklist check if communication with this peer is allowed */
1759 (void) GST_blacklist_test_allowed (&address->peer,
1761 &connect_bl_check_cont,
1762 GNUNET_copy_message (message),
1766 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK:
1768 GST_neighbours_handle_session_syn_ack (message,
1772 GST_blacklist_abort_matching (address, session);
1773 kill_session (plugin_name, session);
1776 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
1778 GST_neighbours_handle_session_ack (message,
1783 GST_blacklist_abort_matching (address, session);
1784 kill_session (plugin_name, session);
1787 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
1788 GST_neighbours_handle_disconnect_message (&address->peer,
1791 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA:
1792 GST_neighbours_handle_quota_message (&address->peer,
1795 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
1796 GST_neighbours_keepalive (&address->peer,
1799 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE:
1800 GST_neighbours_keepalive_response (&address->peer,
1804 /* should be payload */
1805 GNUNET_STATISTICS_update (GST_stats,
1806 gettext_noop ("# bytes payload received"),
1807 ntohs (message->size),
1809 ret = process_payload (address,
1815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1816 "Allowing receive from peer %s to continue in %s\n",
1817 GNUNET_i2s (&address->peer),
1818 GNUNET_STRINGS_relative_time_to_string (ret,
1825 * Function that will be called for each address the transport
1826 * is aware that it might be reachable under. Update our HELLO.
1828 * @param cls name of the plugin (const char*)
1829 * @param add_remove should the address added (YES) or removed (NO) from the
1830 * set of valid addresses?
1831 * @param address the address to add or remove
1834 plugin_env_address_change_notification (void *cls,
1836 const struct GNUNET_HELLO_Address *address)
1838 static int addresses = 0;
1840 if (GNUNET_YES == add_remove)
1843 GNUNET_STATISTICS_update (GST_stats,
1844 "# transport addresses",
1848 else if (GNUNET_NO == add_remove)
1857 GNUNET_STATISTICS_update (GST_stats,
1858 "# transport addresses",
1863 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1864 "Transport now has %u addresses to communicate\n",
1866 GST_hello_modify_addresses (add_remove,
1872 * Function that will be called whenever the plugin internally
1873 * cleans up a session pointer and hence the service needs to
1874 * discard all of those sessions as well. Plugins that do not
1875 * use sessions can simply omit calling this function and always
1876 * use NULL wherever a session pointer is needed. This function
1877 * should be called BEFORE a potential "TransmitContinuation"
1878 * from the "TransmitFunction".
1880 * @param cls closure
1881 * @param address which address was the session for
1882 * @param session which session is being destoyed
1885 plugin_env_session_end (void *cls,
1886 const struct GNUNET_HELLO_Address *address,
1887 struct GNUNET_ATS_Session *session)
1889 struct GNUNET_ATS_SessionKiller *sk;
1891 if (NULL == address)
1896 if (NULL == session)
1901 GNUNET_assert (strlen (address->transport_name) > 0);
1903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1904 "Notification from plugin about terminated session %p from peer `%s' address `%s'\n",
1906 GNUNET_i2s (&address->peer),
1907 GST_plugins_a2s (address));
1909 GST_neighbours_session_terminated (&address->peer,
1911 GST_ats_del_session (address,
1913 GST_blacklist_abort_matching (address,
1916 for (sk = sk_head; NULL != sk; sk = sk->next)
1918 if (sk->session == session)
1920 GNUNET_CONTAINER_DLL_remove (sk_head,
1923 GNUNET_SCHEDULER_cancel (sk->task);
1932 * Black list check result from blacklist check triggered when a
1933 * plugin gave us a new session in #plugin_env_session_start(). If
1934 * connection to the peer is disallowed, kill the session.
1937 * @param peer the peer
1938 * @param address address associated with the request
1939 * @param session session associated with the request
1940 * @param result the result
1943 plugin_env_session_start_bl_check_cont (void *cls,
1944 const struct GNUNET_PeerIdentity *peer,
1945 const struct GNUNET_HELLO_Address *address,
1946 struct GNUNET_ATS_Session *session,
1949 if (GNUNET_OK != result)
1951 kill_session (address->transport_name,
1956 GNUNET_HELLO_address_check_option (address,
1957 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1959 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1960 "Informing verifier about inbound session's address `%s'\n",
1961 GST_plugins_a2s (address));
1962 GST_validation_handle_address (address);
1968 * Plugin tells transport service about a new inbound session
1971 * @param address the address
1972 * @param session the new session
1973 * @param scope network scope information
1976 plugin_env_session_start (void *cls,
1977 const struct GNUNET_HELLO_Address *address,
1978 struct GNUNET_ATS_Session *session,
1979 enum GNUNET_ATS_Network_Type scope)
1981 struct GNUNET_ATS_Properties prop;
1983 if (NULL == address)
1988 if (NULL == session)
1993 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1994 "Notification from plugin `%s' about new session from peer `%s' address `%s'\n",
1995 address->transport_name,
1996 GNUNET_i2s (&address->peer),
1997 GST_plugins_a2s (address));
1999 GNUNET_HELLO_address_check_option (address,
2000 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
2002 /* inbound is always new, but outbound MAY already be known, but
2003 for example for UNIX, we have symmetric connections and thus we
2004 may not know the address yet; add if necessary! */
2005 /* FIXME: maybe change API here so we just pass scope? */
2009 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != scope);
2011 GST_ats_add_inbound_address (address,
2015 /* Do blacklist check if communication with this peer is allowed */
2016 (void) GST_blacklist_test_allowed (&address->peer,
2017 address->transport_name,
2018 &plugin_env_session_start_bl_check_cont,
2026 * Function called by ATS to notify the callee that the
2027 * assigned bandwidth or address for a given peer was changed. If the
2028 * callback is called with address/bandwidth assignments of zero, the
2029 * ATS disconnect function will still be called once the disconnect
2030 * actually happened.
2032 * @param cls closure
2033 * @param peer the peer this address is intended for
2034 * @param address address to use (for peer given in address)
2035 * @param session session to use (if available)
2036 * @param bandwidth_out assigned outbound bandwidth for the connection in NBO,
2037 * 0 to disconnect from peer
2038 * @param bandwidth_in assigned inbound bandwidth for the connection in NBO,
2039 * 0 to disconnect from peer
2040 * @param ats ATS information
2041 * @param ats_count number of @a ats elements
2044 ats_request_address_change (void *cls,
2045 const struct GNUNET_PeerIdentity *peer,
2046 const struct GNUNET_HELLO_Address *address,
2047 struct GNUNET_ATS_Session *session,
2048 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
2049 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
2051 uint32_t bw_in = ntohl (bandwidth_in.value__);
2052 uint32_t bw_out = ntohl (bandwidth_out.value__);
2056 /* ATS service died, all suggestions become invalid!
2057 (but we'll keep using the allocations for a little
2058 while, to keep going while ATS restarts) */
2059 /* FIXME: We should drop all
2060 connections now, as ATS won't explicitly tell
2061 us and be unaware of ongoing resource allocations! */
2064 /* ATS tells me to disconnect from peer */
2065 if ((0 == bw_in) && (0 == bw_out))
2067 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2068 "ATS tells me to disconnect from peer `%s'\n",
2070 GST_neighbours_force_disconnect (peer);
2073 GNUNET_assert (NULL != address);
2074 GNUNET_STATISTICS_update (GST_stats,
2075 "# ATS suggestions received",
2078 GST_neighbours_switch_to_address (address,
2086 * Closure for #test_connection_ok().
2088 struct TestConnectionContext
2091 * Is this the first neighbour we're checking?
2096 * Handle to the blacklisting client we need to ask.
2098 struct TransportClient *tc;
2103 * Got the result about an existing connection from a new blacklister.
2104 * Shutdown the neighbour if necessary.
2107 * @param peer the neighbour that was investigated
2108 * @param address address associated with the request
2109 * @param session session associated with the request
2110 * @param allowed #GNUNET_OK if we can keep it,
2111 * #GNUNET_NO if we must shutdown the connection
2114 confirm_or_drop_neighbour (void *cls,
2115 const struct GNUNET_PeerIdentity *peer,
2116 const struct GNUNET_HELLO_Address *address,
2117 struct GNUNET_ATS_Session *session,
2120 if (GNUNET_OK == allowed)
2121 return; /* we're done */
2122 GNUNET_STATISTICS_update (GST_stats,
2123 gettext_noop ("# disconnects due to blacklist"),
2126 GST_neighbours_force_disconnect (peer);
2131 * Test if an existing connection is still acceptable given a new
2132 * blacklisting client.
2134 * @param cls the `struct TestConnectionContext *`
2135 * @param peer identity of the peer
2136 * @param address the address
2137 * @param state current state this peer is in
2138 * @param state_timeout timeout for the current state of the peer
2139 * @param bandwidth_in bandwidth assigned inbound
2140 * @param bandwidth_out bandwidth assigned outbound
2143 test_connection_ok (void *cls,
2144 const struct GNUNET_PeerIdentity *peer,
2145 const struct GNUNET_HELLO_Address *address,
2146 enum GNUNET_TRANSPORT_PeerState state,
2147 struct GNUNET_TIME_Absolute state_timeout,
2148 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
2149 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2151 struct TestConnectionContext *tcc = cls;
2152 struct GST_BlacklistCheck *bc;
2154 bc = GNUNET_new (struct GST_BlacklistCheck);
2155 GNUNET_CONTAINER_DLL_insert (bc_head,
2159 bc->address = GNUNET_HELLO_address_copy (address);
2160 bc->cont = &confirm_or_drop_neighbour;
2161 bc->cont_cls = NULL;
2162 bc->bl_pos = tcc->tc;
2163 if (GNUNET_YES == tcc->first)
2165 /* all would wait for the same client, no need to
2166 * create more than just the first task right now */
2167 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
2169 tcc->first = GNUNET_NO;
2175 * Initialize a blacklisting client. We got a blacklist-init
2176 * message from this client, add it to the list of clients
2177 * to query for blacklisting.
2179 * @param cls the client
2180 * @param message the blacklist-init message that was sent
2183 handle_client_blacklist_init (void *cls,
2184 const struct GNUNET_MessageHeader *message)
2186 struct TransportClient *tc = cls;
2187 struct TestConnectionContext tcc;
2189 if (CT_NONE != tc->type)
2192 GNUNET_SERVICE_client_drop (tc->client);
2195 GNUNET_SERVICE_client_mark_monitor (tc->client);
2196 tc->type = CT_BLACKLIST;
2197 tc->details.blacklist.call_receive_done = GNUNET_YES;
2198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2199 "New blacklist client %p\n",
2201 /* confirm that all existing connections are OK! */
2203 tcc.first = GNUNET_YES;
2204 GST_neighbours_iterate (&test_connection_ok,
2210 * Free the given entry in the blacklist.
2213 * @param key host identity (unused)
2214 * @param value the blacklist entry
2215 * @return #GNUNET_OK (continue to iterate)
2218 free_blacklist_entry (void *cls,
2219 const struct GNUNET_PeerIdentity *key,
2224 GNUNET_free_non_null (be);
2230 * Set traffic metric to manipulate
2232 * @param cls closure
2233 * @param message containing information
2236 handle_client_set_metric (void *cls,
2237 const struct TrafficMetricMessage *tm)
2239 struct TransportClient *tc = cls;
2241 GST_manipulation_set_metric (tm);
2242 GNUNET_SERVICE_client_continue (tc->client);
2247 * Function called when the service shuts down. Unloads our plugins
2248 * and cancels pending validations.
2250 * @param cls closure, unused
2253 shutdown_task (void *cls)
2255 struct AddressToStringContext *cur;
2257 GST_neighbours_stop ();
2258 GST_plugins_unload ();
2259 GST_validation_stop ();
2261 GNUNET_ATS_scheduling_done (GST_ats);
2263 GNUNET_ATS_connectivity_done (GST_ats_connect);
2264 GST_ats_connect = NULL;
2265 GNUNET_ATS_scanner_done (GST_is);
2267 while (NULL != (cur = a2s_head))
2269 GNUNET_CONTAINER_DLL_remove (a2s_head,
2274 if (NULL != plugin_nc)
2276 GNUNET_notification_context_destroy (plugin_nc);
2279 GNUNET_CONTAINER_multipeermap_destroy (active_stccs);
2280 active_stccs = NULL;
2281 if (NULL != blacklist)
2283 GNUNET_CONTAINER_multipeermap_iterate (blacklist,
2284 &free_blacklist_entry,
2286 GNUNET_CONTAINER_multipeermap_destroy (blacklist);
2290 GST_manipulation_stop ();
2292 if (NULL != GST_peerinfo)
2294 GNUNET_PEERINFO_disconnect (GST_peerinfo);
2295 GST_peerinfo = NULL;
2297 if (NULL != GST_stats)
2299 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
2302 if (NULL != GST_my_private_key)
2304 GNUNET_free (GST_my_private_key);
2305 GST_my_private_key = NULL;
2311 * Perform next action in the blacklist check.
2313 * @param cls the `struct GST_BlacklistCheck *`
2316 do_blacklist_check (void *cls)
2318 struct GST_BlacklistCheck *bc = cls;
2319 struct TransportClient *tc;
2320 struct GNUNET_MQ_Envelope *env;
2321 struct BlacklistMessage *bm;
2324 while (NULL != (tc = bc->bl_pos))
2326 if (CT_BLACKLIST == tc->type)
2328 bc->bl_pos = tc->next;
2332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2333 "No other blacklist clients active, will allow neighbour `%s'\n",
2334 GNUNET_i2s (&bc->peer));
2336 bc->cont (bc->cont_cls,
2341 GST_blacklist_test_cancel (bc);
2344 if ( (NULL != tc->details.blacklist.bc) ||
2345 (GNUNET_NO != tc->details.blacklist.waiting_for_reply) )
2346 return; /* someone else busy with this client */
2347 tc->details.blacklist.bc = bc;
2348 env = GNUNET_MQ_msg (bm,
2349 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY);
2350 bm->is_allowed = htonl (0);
2351 bm->peer = bc->peer;
2352 GNUNET_MQ_send (tc->mq,
2354 if (GNUNET_YES == tc->details.blacklist.call_receive_done)
2356 tc->details.blacklist.call_receive_done = GNUNET_NO;
2357 GNUNET_SERVICE_client_continue (tc->client);
2359 tc->details.blacklist.waiting_for_reply = GNUNET_YES;
2364 * A blacklisting client has sent us reply. Process it.
2366 * @param cls the client
2367 * @param msg the blacklist-reply message that was sent
2370 handle_client_blacklist_reply (void *cls,
2371 const struct BlacklistMessage *msg)
2373 struct TransportClient *tc = cls;
2374 struct GST_BlacklistCheck *bc;
2376 if (CT_BLACKLIST != tc->type)
2379 GNUNET_SERVICE_client_drop (tc->client);
2382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2383 "Blacklist client %p sent reply for `%s'\n",
2385 GNUNET_i2s (&msg->peer));
2386 bc = tc->details.blacklist.bc;
2387 tc->details.blacklist.bc = NULL;
2388 tc->details.blacklist.waiting_for_reply = GNUNET_NO;
2389 tc->details.blacklist.call_receive_done = GNUNET_YES;
2392 /* only run this if the blacklist check has not been
2393 * cancelled in the meantime... */
2394 GNUNET_assert (bc->bl_pos == tc);
2395 if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
2397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2398 "Blacklist check failed, peer not allowed\n");
2399 /* For the duration of the continuation, make the ongoing
2400 check invisible (to avoid double-cancellation); then
2401 add it back again so we can re-use GST_blacklist_test_cancel() */
2402 GNUNET_CONTAINER_DLL_remove (bc_head,
2405 bc->cont (bc->cont_cls,
2410 GNUNET_CONTAINER_DLL_insert (bc_head,
2413 GST_blacklist_test_cancel (bc);
2414 tc->details.blacklist.call_receive_done = GNUNET_NO;
2415 GNUNET_SERVICE_client_continue (tc->client);
2420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2421 "Blacklist check succeeded, continuing with checks\n");
2422 tc->details.blacklist.call_receive_done = GNUNET_NO;
2423 GNUNET_SERVICE_client_continue (tc->client);
2424 bc->bl_pos = tc->next;
2425 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
2429 /* check if any other blacklist checks are waiting for this blacklister */
2430 for (bc = bc_head; bc != NULL; bc = bc->next)
2431 if ( (bc->bl_pos == tc) &&
2432 (NULL == bc->task) )
2434 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
2442 * Add the given peer to the blacklist (for the given transport).
2444 * @param peer peer to blacklist
2445 * @param transport_name transport to blacklist for this peer, NULL for all
2448 GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
2449 const char *transport_name)
2451 char *transport = NULL;
2453 if (NULL != transport_name)
2455 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2456 "Adding peer `%s' with plugin `%s' to blacklist\n",
2459 transport = GNUNET_strdup (transport_name);
2462 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2463 "Adding peer `%s' with all plugins to blacklist\n",
2465 if (NULL == blacklist)
2467 GNUNET_CONTAINER_multipeermap_create (TRANSPORT_BLACKLIST_HT_SIZE,
2470 GNUNET_CONTAINER_multipeermap_put (blacklist,
2473 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2478 * Abort blacklist if @a address and @a session match.
2480 * @param address address used to abort matching checks
2481 * @param session session used to abort matching checks
2484 GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
2485 struct GNUNET_ATS_Session *session)
2487 struct GST_BlacklistCheck *bc;
2488 struct GST_BlacklistCheck *n;
2491 while (NULL != (bc = n))
2494 if ( (bc->session == session) &&
2495 (0 == GNUNET_HELLO_address_cmp (bc->address,
2498 bc->cont (bc->cont_cls,
2503 GST_blacklist_test_cancel (bc);
2510 * Test if the given blacklist entry matches. If so,
2511 * abort the iteration.
2513 * @param cls the transport name to match (const char*)
2514 * @param key the key (unused)
2515 * @param value the 'char *' (name of a blacklisted transport)
2516 * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches
2519 test_blacklisted (void *cls,
2520 const struct GNUNET_PeerIdentity *key,
2523 const char *transport_name = cls;
2526 /* Blacklist entry be:
2527 * (NULL == be): peer is blacklisted with all plugins
2528 * (NULL != be): peer is blacklisted for a specific plugin
2530 * If (NULL != transport_name) we look for a transport specific entry:
2531 * if (transport_name == be) forbidden
2535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2536 "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n",
2538 (NULL == transport_name) ? "unspecified" : transport_name,
2539 (NULL == be) ? "all plugins" : be);
2540 /* all plugins for this peer were blacklisted: disallow */
2544 /* blacklist check for specific transport */
2545 if ( (NULL != transport_name) &&
2548 if (0 == strcmp (transport_name,
2550 return GNUNET_NO; /* plugin is blacklisted! */
2557 * Test if a peer/transport combination is blacklisted.
2559 * @param peer the identity of the peer to test
2560 * @param transport_name name of the transport to test, never NULL
2561 * @param cont function to call with result
2562 * @param cont_cls closure for @a cont
2563 * @param address address to pass back to @a cont, can be NULL
2564 * @param session session to pass back to @a cont, can be NULL
2565 * @return handle to the blacklist check, NULL if the decision
2566 * was made instantly and @a cont was already called
2568 struct GST_BlacklistCheck *
2569 GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
2570 const char *transport_name,
2571 GST_BlacklistTestContinuation cont,
2573 const struct GNUNET_HELLO_Address *address,
2574 struct GNUNET_ATS_Session *session)
2576 struct GST_BlacklistCheck *bc;
2577 struct TransportClient *tc;
2579 GNUNET_assert (NULL != peer);
2580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2581 "Blacklist check for peer `%s':%s\n",
2583 (NULL != transport_name) ? transport_name : "unspecified");
2585 /* Check local blacklist by iterating over hashmap
2586 * If iteration is aborted, we found a matching blacklist entry */
2587 if ((NULL != blacklist) &&
2589 GNUNET_CONTAINER_multipeermap_get_multiple (blacklist, peer,
2591 (void *) transport_name)))
2593 /* Disallowed by config, disapprove instantly */
2594 GNUNET_STATISTICS_update (GST_stats,
2595 gettext_noop ("# disconnects due to blacklist"),
2598 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2599 _("Disallowing connection to peer `%s' on transport %s\n"),
2601 (NULL != transport_name) ? transport_name : "unspecified");
2611 for (tc = clients_head; NULL != tc; tc = tc->next)
2612 if (CT_BLACKLIST == tc->type)
2616 /* no blacklist clients, approve instantly */
2623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2624 "Allowing connection to peer `%s' %s\n",
2626 (NULL != transport_name) ? transport_name : "");
2630 /* need to query blacklist clients */
2631 bc = GNUNET_new (struct GST_BlacklistCheck);
2632 GNUNET_CONTAINER_DLL_insert (bc_head,
2636 bc->address = GNUNET_HELLO_address_copy (address);
2637 bc->session = session;
2639 bc->cont_cls = cont_cls;
2641 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
2648 * Cancel a blacklist check.
2650 * @param bc check to cancel
2653 GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc)
2655 GNUNET_CONTAINER_DLL_remove (bc_head,
2658 if (NULL != bc->bl_pos)
2660 if ( (CT_BLACKLIST == bc->bl_pos->type) &&
2661 (bc->bl_pos->details.blacklist.bc == bc) )
2663 /* we're at the head of the queue, remove us! */
2664 bc->bl_pos->details.blacklist.bc = NULL;
2667 if (NULL != bc->task)
2669 GNUNET_SCHEDULER_cancel (bc->task);
2672 GNUNET_free_non_null (bc->address);
2678 * Function to iterate over options in the blacklisting section for a peer.
2680 * @param cls closure
2681 * @param section name of the section
2682 * @param option name of the option
2683 * @param value value of the option
2686 blacklist_cfg_iter (void *cls,
2687 const char *section,
2691 unsigned int *res = cls;
2692 struct GNUNET_PeerIdentity peer;
2697 GNUNET_CRYPTO_eddsa_public_key_from_string (option,
2702 if ((NULL == value) || (0 == strcmp(value, "")))
2704 /* Blacklist whole peer */
2705 GST_blacklist_add_peer (&peer, NULL);
2706 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2707 _("Adding blacklisting entry for peer `%s'\n"),
2708 GNUNET_i2s (&peer));
2712 plugs = GNUNET_strdup (value);
2713 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
2715 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2716 _("Adding blacklisting entry for peer `%s':`%s'\n"),
2717 GNUNET_i2s (&peer), pos);
2718 GST_blacklist_add_peer (&peer, pos);
2720 GNUNET_free (plugs);
2727 * Read blacklist configuration
2729 * @param cfg the configuration handle
2730 * @param my_id my peer identity
2733 read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg,
2734 const struct GNUNET_PeerIdentity *my_id)
2737 unsigned int res = 0;
2739 GNUNET_snprintf (cfg_sect,
2741 "transport-blacklist-%s",
2742 GNUNET_i2s_full (my_id));
2743 GNUNET_CONFIGURATION_iterate_section_values (cfg,
2745 &blacklist_cfg_iter,
2747 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2748 "Loaded %u blacklisting entries from configuration\n",
2754 * Initiate transport service.
2756 * @param cls closure
2757 * @param c configuration to use
2758 * @param service the initialized service
2762 const struct GNUNET_CONFIGURATION_Handle *c,
2763 struct GNUNET_SERVICE_Handle *service)
2766 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
2767 long long unsigned int max_fd_cfg;
2775 GNUNET_CONFIGURATION_get_value_filename (c,
2780 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2781 _("Transport service is lacking key configuration settings. Exiting.\n"));
2782 GNUNET_SCHEDULER_shutdown ();
2786 GNUNET_CONFIGURATION_get_value_time (c,
2791 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
2793 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
2794 GNUNET_free (keyfile);
2795 GNUNET_assert (NULL != pk);
2796 GST_my_private_key = pk;
2798 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
2799 GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg);
2800 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key,
2801 &GST_my_identity.public_key);
2802 GNUNET_assert (NULL != GST_my_private_key);
2804 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2805 "My identity is `%s'\n",
2806 GNUNET_i2s_full (&GST_my_identity));
2808 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
2810 if (NULL == GST_peerinfo)
2812 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2813 _("Could not access PEERINFO service. Exiting.\n"));
2814 GNUNET_SCHEDULER_shutdown ();
2821 struct rlimit r_file;
2823 if (0 == getrlimit (RLIMIT_NOFILE,
2826 max_fd_rlimit = r_file.rlim_cur;
2827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2828 "Maximum number of open files was: %u/%u\n",
2829 (unsigned int) r_file.rlim_cur,
2830 (unsigned int) r_file.rlim_max);
2832 max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */
2836 GNUNET_CONFIGURATION_get_value_number (GST_cfg,
2840 max_fd_cfg = max_fd_rlimit;
2842 if (max_fd_cfg > max_fd_rlimit)
2843 max_fd = max_fd_cfg;
2845 max_fd = max_fd_rlimit;
2846 if (max_fd < DEFAULT_MAX_FDS)
2847 max_fd = DEFAULT_MAX_FDS;
2849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2850 "Limiting number of sockets to %u: validation %u, neighbors: %u\n",
2855 friend_only = GNUNET_CONFIGURATION_get_value_yesno (GST_cfg,
2858 if (GNUNET_SYSERR == friend_only)
2859 friend_only = GNUNET_NO; /* According to topology defaults */
2860 /* start subsystems */
2861 read_blacklist_configuration (GST_cfg,
2863 GST_is = GNUNET_ATS_scanner_init ();
2864 GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg);
2865 GST_ats = GNUNET_ATS_scheduling_init (GST_cfg,
2866 &ats_request_address_change,
2869 GST_manipulation_init ();
2870 GST_plugins_load (&GST_manipulation_recv,
2871 &plugin_env_address_change_notification,
2872 &plugin_env_session_start,
2873 &plugin_env_session_end);
2874 GST_hello_start (friend_only,
2875 &process_hello_update,
2877 GST_neighbours_start ((max_fd / 3) * 2);
2878 active_stccs = GNUNET_CONTAINER_multipeermap_create (128,
2880 plugin_nc = GNUNET_notification_context_create (0);
2881 GST_validation_start ((max_fd / 3));
2886 * Define "main" method using service macro.
2890 GNUNET_SERVICE_OPTION_NONE,
2893 &client_disconnect_cb,
2895 GNUNET_MQ_hd_fixed_size (client_start,
2896 GNUNET_MESSAGE_TYPE_TRANSPORT_START,
2897 struct StartMessage,
2899 GNUNET_MQ_hd_var_size (client_hello,
2900 GNUNET_MESSAGE_TYPE_HELLO,
2901 struct GNUNET_MessageHeader,
2903 GNUNET_MQ_hd_var_size (client_send,
2904 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
2905 struct OutboundMessage,
2907 GNUNET_MQ_hd_var_size (client_address_to_string,
2908 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING,
2909 struct AddressLookupMessage,
2911 GNUNET_MQ_hd_fixed_size (client_monitor_peers,
2912 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST,
2913 struct PeerMonitorMessage,
2915 GNUNET_MQ_hd_fixed_size (client_blacklist_init,
2916 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
2917 struct GNUNET_MessageHeader,
2919 GNUNET_MQ_hd_fixed_size (client_blacklist_reply,
2920 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
2921 struct BlacklistMessage,
2923 GNUNET_MQ_hd_fixed_size (client_set_metric,
2924 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC,
2925 struct TrafficMetricMessage,
2927 GNUNET_MQ_hd_fixed_size (client_monitor_plugins,
2928 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START,
2929 struct GNUNET_MessageHeader,
2931 GNUNET_MQ_handler_end ());
2934 /* end of file gnunet-service-transport.c */