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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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.
119 * CORE client without any handlers.
121 CT_CORE_NO_HANDLERS = 4
126 * Context we use when performing a blacklist check.
128 struct GST_BlacklistCheck;
131 * Client connected to the transport service.
133 struct TransportClient
136 * This is a doubly-linked list.
138 struct TransportClient *next;
141 * This is a doubly-linked list.
143 struct TransportClient *prev;
146 * Handle to the client.
148 struct GNUNET_SERVICE_Client *client;
151 * Message queue to the client.
153 struct GNUNET_MQ_Handle *mq;
156 * What type of client is this?
158 enum ClientType type;
163 * Peer identity to monitor the addresses of.
164 * Zero to monitor all neighbours. Valid if
165 * @e type is CT_MONITOR.
167 struct GNUNET_PeerIdentity monitor_peer;
170 * Additional details if @e type is CT_BLACKLIST.
175 * Blacklist check that we're currently performing (or NULL
176 * if we're performing one that has been cancelled).
178 struct GST_BlacklistCheck *bc;
181 * Set to #GNUNET_YES if we're currently waiting for a reply.
183 int waiting_for_reply;
186 * #GNUNET_YES if we have to call receive_done for this client
188 int call_receive_done;
195 * Context we use when performing a blacklist check.
197 struct GST_BlacklistCheck
200 * This is a linked list.
202 struct GST_BlacklistCheck *next;
205 * This is a linked list.
207 struct GST_BlacklistCheck *prev;
210 * Peer being checked.
212 struct GNUNET_PeerIdentity peer;
215 * Continuation to call with the result.
217 GST_BlacklistTestContinuation cont;
220 * Closure for @e cont.
225 * Address for #GST_blacklist_abort_matching(), can be NULL.
227 struct GNUNET_HELLO_Address *address;
230 * Session for #GST_blacklist_abort_matching(), can be NULL.
232 struct GNUNET_ATS_Session *session;
235 * Our current position in the blacklisters list.
237 struct TransportClient *bl_pos;
240 * Current task performing the check.
242 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
274 * Client that made the request.
276 struct TransportClient *tc;
279 * Peer that was the target.
281 struct GNUNET_PeerIdentity target;
284 * At what time did we receive the message?
286 struct GNUNET_TIME_Absolute send_time;
289 * Unique ID, for logging.
291 unsigned long long uuid;
294 * Set to #GNUNET_YES if the connection for @e target goes
295 * down and we thus must no longer send the
296 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK message.
303 * Head of linked list of all clients to this service.
305 static struct TransportClient *clients_head;
308 * Tail of linked list of all clients to this service.
310 static struct TransportClient *clients_tail;
313 * Map of peer identities to active send transmit continuation
314 * contexts. Used to flag contexts as 'dead' when a connection goes
315 * down. Values are of type `struct SendTransmitContinuationContext
318 static struct GNUNET_CONTAINER_MultiPeerMap *active_stccs;
321 * Head of linked list of all pending address iterations
323 static struct AddressToStringContext *a2s_head;
326 * Tail of linked list of all pending address iterations
328 static struct AddressToStringContext *a2s_tail;
331 * Head of DLL of active blacklisting queries.
333 static struct GST_BlacklistCheck *bc_head;
336 * Tail of DLL of active blacklisting queries.
338 static struct GST_BlacklistCheck *bc_tail;
341 * Hashmap of blacklisted peers. Values are of type 'char *' (transport names),
342 * can be NULL if we have no static blacklist.
344 static struct GNUNET_CONTAINER_MultiPeerMap *blacklist;
347 * Notification context, to send updates on changes to active plugin
350 static struct GNUNET_NotificationContext *plugin_nc;
353 * Plugin monitoring client we are currently syncing, NULL if all
354 * monitoring clients are in sync.
356 static struct TransportClient *sync_client;
359 * Peer identity that is all zeros, used as a way to indicate
360 * "all peers". Used for comparissons.
362 static struct GNUNET_PeerIdentity all_zeros;
367 struct GNUNET_STATISTICS_Handle *GST_stats;
370 * Configuration handle.
372 const struct GNUNET_CONFIGURATION_Handle *GST_cfg;
375 * Configuration handle.
377 struct GNUNET_PeerIdentity GST_my_identity;
380 * Handle to peerinfo service.
382 struct GNUNET_PEERINFO_Handle *GST_peerinfo;
387 struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key;
390 * ATS scheduling handle.
392 struct GNUNET_ATS_SchedulingHandle *GST_ats;
395 * ATS connectivity handle.
397 struct GNUNET_ATS_ConnectivityHandle *GST_ats_connect;
400 * Hello address expiration
402 struct GNUNET_TIME_Relative hello_expiration;
405 * Head of DLL of asynchronous tasks to kill sessions.
407 static struct GNUNET_ATS_SessionKiller *sk_head;
410 * Tail of DLL of asynchronous tasks to kill sessions.
412 static struct GNUNET_ATS_SessionKiller *sk_tail;
415 * Interface scanner determines our LAN address range(s).
417 struct GNUNET_NT_InterfaceScanner *GST_is;
420 * Queue the given message for transmission to the given client
422 * @param tc target of the message
423 * @param msg message to transmit
424 * @param may_drop #GNUNET_YES if the message can be dropped
427 unicast (struct TransportClient *tc,
428 const struct GNUNET_MessageHeader *msg,
431 struct GNUNET_MQ_Envelope *env;
433 if ((GNUNET_MQ_get_length (tc->mq) >= MAX_PENDING) &&
434 (GNUNET_YES == may_drop))
437 GNUNET_ERROR_TYPE_DEBUG,
438 "Dropping message of type %u and size %u, have %u/%u messages pending\n",
441 GNUNET_MQ_get_length (tc->mq),
443 GNUNET_STATISTICS_update (GST_stats,
445 "# messages dropped due to slow client"),
450 env = GNUNET_MQ_msg_copy (msg);
451 GNUNET_MQ_send (tc->mq, env);
456 * Called whenever a client connects. Allocates our
457 * data structures associated with that client.
459 * @param cls closure, NULL
460 * @param client identification of the client
461 * @param mq message queue for the client
462 * @return our `struct TransportClient`
465 client_connect_cb (void *cls,
466 struct GNUNET_SERVICE_Client *client,
467 struct GNUNET_MQ_Handle *mq)
469 struct TransportClient *tc;
471 tc = GNUNET_new (struct TransportClient);
474 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc);
475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc);
481 * Perform next action in the blacklist check.
483 * @param cls the `struct BlacklistCheck*`
486 do_blacklist_check (void *cls);
490 * Mark the peer as down so we don't call the continuation
491 * context in the future.
493 * @param cls a `struct TransportClient`
494 * @param peer a peer we are sending to
495 * @param value a `struct SendTransmitContinuationContext` to mark
496 * @return #GNUNET_OK (continue to iterate)
499 mark_match_down (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
501 struct TransportClient *tc = cls;
502 struct SendTransmitContinuationContext *stcc = value;
506 stcc->down = GNUNET_YES;
514 * Called whenever a client is disconnected. Frees our
515 * resources associated with that client.
517 * @param cls closure, NULL
518 * @param client identification of the client
519 * @param app_ctx our `struct TransportClient`
522 client_disconnect_cb (void *cls,
523 struct GNUNET_SERVICE_Client *client,
526 struct TransportClient *tc = app_ctx;
527 struct GST_BlacklistCheck *bc;
529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
530 "Client %p disconnected, cleaning up.\n",
532 GNUNET_CONTAINER_multipeermap_iterate (active_stccs, &mark_match_down, tc);
533 for (struct AddressToStringContext *cur = a2s_head; NULL != cur;
539 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc);
552 for (bc = bc_head; NULL != bc; bc = bc->next)
554 if (bc->bl_pos != tc)
556 bc->bl_pos = tc->next;
557 if (NULL == bc->task)
558 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
562 case CT_CORE_NO_HANDLERS:
570 * Function called for each of our connected neighbours. Notify the
571 * client about the existing neighbour.
573 * @param cls the `struct TransportClient *` to notify
574 * @param peer identity of the neighbour
575 * @param address the address
576 * @param state the current state of the peer
577 * @param state_timeout the time out for the state
578 * @param bandwidth_in inbound bandwidth in NBO
579 * @param bandwidth_out outbound bandwidth in NBO
582 notify_client_about_neighbour (void *cls,
583 const struct GNUNET_PeerIdentity *peer,
584 const struct GNUNET_HELLO_Address *address,
585 enum GNUNET_TRANSPORT_PeerState state,
586 struct GNUNET_TIME_Absolute state_timeout,
587 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
588 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
590 struct TransportClient *tc = cls;
591 struct ConnectInfoMessage cim;
593 if (GNUNET_NO == GST_neighbours_test_connected (peer))
595 cim.header.size = htons (sizeof(struct ConnectInfoMessage));
596 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
598 cim.quota_out = bandwidth_out;
599 unicast (tc, &cim.header, GNUNET_NO);
604 * Initialize a normal client. We got a start message from this
605 * client, add it to the list of clients for broadcasting of inbound
608 * @param cls the client
609 * @param start the start message that was sent
612 handle_client_start (void *cls, const struct StartMessage *start)
614 struct TransportClient *tc = cls;
615 const struct GNUNET_MessageHeader *hello;
618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p sent START\n", tc);
619 options = ntohl (start->options);
620 if ((0 != (1 & options)) &&
621 (0 != memcmp (&start->self,
623 sizeof(struct GNUNET_PeerIdentity))))
625 /* client thinks this is a different peer, reject */
627 GNUNET_SERVICE_client_drop (tc->client);
630 if (CT_NONE != tc->type)
633 GNUNET_SERVICE_client_drop (tc->client);
636 if (0 != (2 & options))
639 tc->type = CT_CORE_NO_HANDLERS;
640 hello = GST_hello_get ();
642 unicast (tc, hello, GNUNET_NO);
643 GST_neighbours_iterate (¬ify_client_about_neighbour, tc);
644 GNUNET_SERVICE_client_continue (tc->client);
649 * Client sent us a HELLO. Check the request.
651 * @param cls the client
652 * @param message the HELLO message
655 check_client_hello (void *cls, const struct GNUNET_MessageHeader *message)
657 return GNUNET_OK; /* FIXME: check here? */
662 * Client sent us a HELLO. Process the request.
664 * @param cls the client
665 * @param message the HELLO message
668 handle_client_hello (void *cls, const struct GNUNET_MessageHeader *message)
670 struct TransportClient *tc = cls;
672 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received HELLO message\n");
673 GST_validation_handle_hello (message);
674 GNUNET_SERVICE_client_continue (tc->client);
679 * Function called after the transmission is done. Notify the client that it is
680 * OK to send the next message.
683 * @param success #GNUNET_OK on success, #GNUNET_NO on failure, #GNUNET_SYSERR if we're not connected
684 * @param bytes_payload bytes payload sent
685 * @param bytes_on_wire bytes sent on wire
688 handle_send_transmit_continuation (void *cls,
690 size_t bytes_payload,
691 size_t bytes_on_wire)
693 struct SendTransmitContinuationContext *stcc = cls;
694 struct SendOkMessage send_ok_msg;
695 struct GNUNET_TIME_Relative delay;
696 const struct GNUNET_HELLO_Address *addr;
698 delay = GNUNET_TIME_absolute_get_duration (stcc->send_time);
699 addr = GST_neighbour_get_current_address (&stcc->target);
700 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
701 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
702 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
703 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
704 (unsigned int) bytes_payload,
705 (unsigned int) bytes_on_wire,
706 GNUNET_i2s (&stcc->target),
708 (NULL != addr) ? addr->transport_name : "%");
710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
711 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
712 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
713 (unsigned int) bytes_payload,
714 (unsigned int) bytes_on_wire,
715 GNUNET_i2s (&stcc->target),
717 (NULL != addr) ? addr->transport_name : "%");
719 if (GNUNET_NO == stcc->down)
721 /* Only send confirmation if we are still connected */
722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
723 "Sending SEND_OK for transmission request %llu\n",
725 send_ok_msg.header.size = htons (sizeof(send_ok_msg));
726 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
727 send_ok_msg.bytes_msg = htonl (bytes_payload);
728 send_ok_msg.bytes_physical = htonl (bytes_on_wire);
729 send_ok_msg.success = htonl (success);
730 send_ok_msg.peer = stcc->target;
731 unicast (stcc->tc, &send_ok_msg.header, GNUNET_NO);
735 GNUNET_CONTAINER_multipeermap_remove (active_stccs, &stcc->target, stcc));
741 * Client asked for transmission to a peer. Process the request.
743 * @param cls the client
744 * @param obm the send message that was sent
747 check_client_send (void *cls, const struct OutboundMessage *obm)
750 const struct GNUNET_MessageHeader *obmm;
752 size = ntohs (obm->header.size) - sizeof(struct OutboundMessage);
753 if (size < sizeof(struct GNUNET_MessageHeader))
756 return GNUNET_SYSERR;
758 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
759 if (size != ntohs (obmm->size))
762 return GNUNET_SYSERR;
769 * Client asked for transmission to a peer. Process the request.
771 * @param cls the client
772 * @param obm the send message that was sent
775 handle_client_send (void *cls, const struct OutboundMessage *obm)
777 static unsigned long long uuid_gen;
778 struct TransportClient *tc = cls;
779 const struct GNUNET_MessageHeader *obmm;
780 struct SendTransmitContinuationContext *stcc;
782 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
783 if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer))
785 /* not connected, not allowed to send; can happen due to asynchronous operations */
786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
787 "Could not send message to peer `%s': not connected\n",
788 GNUNET_i2s (&obm->peer));
789 GNUNET_STATISTICS_update (
791 gettext_noop ("# bytes payload dropped (other peer was not connected)"),
794 GNUNET_SERVICE_client_continue (tc->client);
798 GNUNET_ERROR_TYPE_DEBUG,
799 "Received SEND request %llu for `%s' and first message of type %u and total size %u\n",
801 GNUNET_i2s (&obm->peer),
804 GNUNET_SERVICE_client_continue (tc->client);
806 stcc = GNUNET_new (struct SendTransmitContinuationContext);
807 stcc->target = obm->peer;
809 stcc->send_time = GNUNET_TIME_absolute_get ();
810 stcc->uuid = uuid_gen++;
811 (void) GNUNET_CONTAINER_multipeermap_put (
815 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
816 GST_manipulation_send (&obm->peer,
819 GNUNET_TIME_relative_ntoh (obm->timeout),
820 &handle_send_transmit_continuation,
826 * Take the given address and append it to the set of results sent back to
827 * the client. This function may be called serveral times for a single
828 * conversion. The last invocation will be with a @a address of
829 * NULL and a @a res of #GNUNET_OK. Thus, to indicate conversion
830 * errors, the callback might be called first with @a address NULL and
831 * @a res being #GNUNET_SYSERR. In that case, there will still be a
832 * subsequent call later with @a address NULL and @a res #GNUNET_OK.
834 * @param cls the `struct AddressToStringContext`
835 * @param buf text to transmit (contains the human-readable address, or NULL)
836 * @param res #GNUNET_OK if conversion was successful, #GNUNET_SYSERR on error,
840 transmit_address_to_client (void *cls, const char *buf, int res)
842 struct AddressToStringContext *actx = cls;
843 struct GNUNET_MQ_Envelope *env;
844 struct AddressToStringResultMessage *atsm;
847 GNUNET_assert ((GNUNET_OK == res) || (GNUNET_SYSERR == res));
848 if (NULL == actx->tc)
852 env = GNUNET_MQ_msg (atsm,
853 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
854 if (GNUNET_OK == res)
856 /* this was the last call, transmit */
857 atsm->res = htonl (GNUNET_OK);
858 atsm->addr_len = htonl (0);
859 GNUNET_MQ_send (actx->tc->mq, env);
860 GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx);
864 if (GNUNET_SYSERR == res)
866 /* address conversion failed, but there will be more callbacks */
867 atsm->res = htonl (GNUNET_SYSERR);
868 atsm->addr_len = htonl (0);
869 GNUNET_MQ_send (actx->tc->mq, env);
873 GNUNET_assert (GNUNET_OK == res);
874 /* succesful conversion, append*/
875 slen = strlen (buf) + 1;
877 GNUNET_MQ_msg_extra (atsm,
879 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
880 atsm->res = htonl (GNUNET_YES);
881 atsm->addr_len = htonl (slen);
882 GNUNET_memcpy (&atsm[1], buf, slen);
883 GNUNET_MQ_send (actx->tc->mq, env);
888 * Client asked to resolve an address. Check the request.
890 * @param cls the client
891 * @param alum the resolution request
892 * @return #GNUNET_OK if @a alum is well-formed
895 check_client_address_to_string (void *cls,
896 const struct AddressLookupMessage *alum)
898 const char *plugin_name;
900 uint32_t address_len;
903 size = ntohs (alum->header.size);
904 address_len = ntohs (alum->addrlen);
905 if (size <= sizeof(struct AddressLookupMessage) + address_len)
908 return GNUNET_SYSERR;
910 address = (const char *) &alum[1];
911 plugin_name = (const char *) &address[address_len];
912 if ('\0' != plugin_name[size - sizeof(struct AddressLookupMessage)
916 return GNUNET_SYSERR;
923 * Client asked to resolve an address. Process the request.
925 * @param cls the client
926 * @param alum the resolution request
929 handle_client_address_to_string (void *cls,
930 const struct AddressLookupMessage *alum)
932 struct TransportClient *tc = cls;
933 struct GNUNET_TRANSPORT_PluginFunctions *papi;
934 const char *plugin_name;
936 uint32_t address_len;
937 struct AddressToStringContext *actx;
938 struct GNUNET_MQ_Envelope *env;
939 struct AddressToStringResultMessage *atsm;
940 struct GNUNET_TIME_Relative rtimeout;
943 address_len = ntohs (alum->addrlen);
944 address = (const char *) &alum[1];
945 plugin_name = (const char *) &address[address_len];
946 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
947 numeric = ntohs (alum->numeric_only);
948 papi = GST_plugins_printer_find (plugin_name);
951 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
952 "Failed to find plugin `%s'\n",
954 env = GNUNET_MQ_msg (atsm,
955 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
956 atsm->res = htonl (GNUNET_SYSERR);
957 atsm->addr_len = htonl (0);
958 GNUNET_MQ_send (tc->mq, env);
959 env = GNUNET_MQ_msg (atsm,
960 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
961 atsm->res = htonl (GNUNET_OK);
962 atsm->addr_len = htonl (0);
963 GNUNET_MQ_send (tc->mq, env);
966 actx = GNUNET_new (struct AddressToStringContext);
968 GNUNET_CONTAINER_DLL_insert (a2s_head, a2s_tail, actx);
969 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
970 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
971 "Pretty-printing address of %u bytes using plugin `%s'\n",
974 papi->address_pretty_printer (papi->cls,
980 &transmit_address_to_client,
986 * Compose #PeerIterateResponseMessage using the given peer and address.
988 * @param peer identity of the peer
989 * @param address the address, NULL on disconnect
990 * @return composed message
992 static struct PeerIterateResponseMessage *
993 compose_address_iterate_response_message (
994 const struct GNUNET_PeerIdentity *peer,
995 const struct GNUNET_HELLO_Address *address)
997 struct PeerIterateResponseMessage *msg;
1003 GNUNET_assert (NULL != peer);
1004 if (NULL != address)
1006 tlen = strlen (address->transport_name) + 1;
1007 alen = address->address_length;
1014 size = (sizeof(struct PeerIterateResponseMessage) + alen + tlen);
1015 msg = GNUNET_malloc (size);
1016 msg->header.size = htons (size);
1018 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE);
1019 msg->reserved = htonl (0);
1021 msg->addrlen = htonl (alen);
1022 msg->pluginlen = htonl (tlen);
1024 if (NULL != address)
1026 msg->local_address_info = htonl ((uint32_t) address->local_info);
1027 addr = (char *) &msg[1];
1028 GNUNET_memcpy (addr, address->address, alen);
1029 GNUNET_memcpy (&addr[alen], address->transport_name, tlen);
1036 * Context for #send_validation_information() and
1037 * #send_peer_information().
1039 struct IterationContext
1042 * Context to use for the transmission.
1044 struct TransportClient *tc;
1047 * Which peers do we care about?
1049 struct GNUNET_PeerIdentity id;
1052 * #GNUNET_YES if @e id should be ignored because we want all peers.
1059 * Output information of neighbours to the given client.
1061 * @param cls the `struct PeerIterationContext *`
1062 * @param peer identity of the neighbour
1063 * @param address the address
1064 * @param state current state this peer is in
1065 * @param state_timeout timeout for the current state of the peer
1066 * @param bandwidth_in inbound quota in NBO
1067 * @param bandwidth_out outbound quota in NBO
1070 send_peer_information (void *cls,
1071 const struct GNUNET_PeerIdentity *peer,
1072 const struct GNUNET_HELLO_Address *address,
1073 enum GNUNET_TRANSPORT_PeerState state,
1074 struct GNUNET_TIME_Absolute state_timeout,
1075 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1076 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1078 struct IterationContext *pc = cls;
1079 struct GNUNET_MQ_Envelope *env;
1080 struct PeerIterateResponseMessage *msg;
1082 if ((GNUNET_YES != pc->all) && (0 != memcmp (peer, &pc->id, sizeof(pc->id))))
1084 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1085 "Sending information about `%s' using address `%s' in state `%s'\n",
1087 (NULL != address) ? GST_plugins_a2s (address) : "<none>",
1088 GNUNET_TRANSPORT_ps2s (state));
1089 msg = compose_address_iterate_response_message (peer, address);
1090 msg->state = htonl (state);
1091 msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout);
1092 env = GNUNET_MQ_msg_copy (&msg->header);
1094 GNUNET_MQ_send (pc->tc->mq, env);
1099 * Client asked to obtain information about a specific or all peers
1100 * Process the request.
1102 * @param cls the client
1103 * @param msg the peer address information request
1106 handle_client_monitor_peers (void *cls, const struct PeerMonitorMessage *msg)
1108 struct TransportClient *tc = cls;
1109 struct IterationContext pc;
1111 if (CT_NONE != tc->type)
1114 GNUNET_SERVICE_client_drop (tc->client);
1117 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1118 GNUNET_SERVICE_client_mark_monitor (tc->client);
1120 /* Send initial list */
1122 if (0 == memcmp (&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity)))
1124 /* iterate over all neighbours */
1125 pc.all = GNUNET_YES;
1130 /* just return one neighbour */
1134 GST_neighbours_iterate (&send_peer_information, &pc);
1136 if (GNUNET_YES != ntohl (msg->one_shot))
1138 tc->details.monitor_peer = msg->peer;
1139 tc->type = CT_MONITOR;
1141 memcmp (&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity)))
1142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1143 "Client %p started monitoring of the peer `%s'\n",
1145 GNUNET_i2s (&msg->peer));
1147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1148 "Client %p started monitoring all peers\n",
1153 struct GNUNET_MessageHeader *msg;
1154 struct GNUNET_MQ_Envelope *env;
1158 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END);
1159 GNUNET_MQ_send (tc->mq, env);
1165 * Function called by the plugin with information about the
1166 * current sessions managed by the plugin (for monitoring).
1168 * @param cls closure
1169 * @param session session handle this information is about,
1170 * NULL to indicate that we are "in sync" (initial
1171 * iteration complete)
1172 * @param info information about the state of the session,
1173 * NULL if @a session is also NULL and we are
1174 * merely signalling that the initial iteration is over
1177 plugin_session_info_cb (void *cls,
1178 struct GNUNET_ATS_Session *session,
1179 const struct GNUNET_TRANSPORT_SessionInfo *info)
1181 struct GNUNET_MQ_Envelope *env;
1182 struct TransportPluginMonitorMessage *msg;
1183 struct GNUNET_MessageHeader *sync;
1190 if (0 == GNUNET_notification_context_get_size (plugin_nc))
1192 GST_plugins_monitor_subscribe (NULL, NULL);
1195 if ((NULL == info) && (NULL == session))
1197 /* end of initial iteration */
1198 if (NULL != sync_client)
1201 GNUNET_MQ_msg (sync, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC);
1202 GNUNET_MQ_send (sync_client->mq, env);
1207 GNUNET_assert (NULL != info);
1208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1209 "Plugin event for peer %s on transport %s\n",
1210 GNUNET_i2s (&info->address->peer),
1211 info->address->transport_name);
1212 slen = strlen (info->address->transport_name) + 1;
1213 alen = info->address->address_length;
1214 size = sizeof(struct TransportPluginMonitorMessage) + slen + alen;
1215 if (size > UINT16_MAX)
1220 msg = GNUNET_malloc (size);
1221 msg->header.size = htons (size);
1222 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT);
1223 msg->session_state = htons ((uint16_t) info->state);
1224 msg->is_inbound = htons ((int16_t) info->is_inbound);
1225 msg->msgs_pending = htonl (info->num_msg_pending);
1226 msg->bytes_pending = htonl (info->num_bytes_pending);
1227 msg->timeout = GNUNET_TIME_absolute_hton (info->session_timeout);
1228 msg->delay = GNUNET_TIME_absolute_hton (info->receive_delay);
1229 msg->peer = info->address->peer;
1230 msg->session_id = (uint64_t) (intptr_t) session;
1231 msg->plugin_name_len = htons (slen);
1232 msg->plugin_address_len = htons (alen);
1233 name = (char *) &msg[1];
1234 GNUNET_memcpy (name, info->address->transport_name, slen);
1236 GNUNET_memcpy (addr, info->address->address, alen);
1237 if (NULL != sync_client)
1239 struct GNUNET_MQ_Envelope *env;
1241 env = GNUNET_MQ_msg_copy (&msg->header);
1242 GNUNET_MQ_send (sync_client->mq, env);
1246 GNUNET_notification_context_broadcast (plugin_nc, &msg->header, GNUNET_NO);
1253 * Client asked to obtain information about all plugin connections.
1255 * @param cls the client
1256 * @param message the peer address information request
1259 handle_client_monitor_plugins (void *cls,
1260 const struct GNUNET_MessageHeader *message)
1262 struct TransportClient *tc = cls;
1264 GNUNET_SERVICE_client_mark_monitor (tc->client);
1265 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1266 GNUNET_notification_context_add (plugin_nc, tc->mq);
1267 GNUNET_assert (NULL == sync_client);
1269 GST_plugins_monitor_subscribe (&plugin_session_info_cb, NULL);
1274 * Broadcast the given message to all of our clients.
1276 * @param msg message to broadcast
1277 * @param may_drop #GNUNET_YES if the message can be dropped / is payload
1280 GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop)
1284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1285 "Asked to broadcast message of type %u with %u bytes\n",
1286 (unsigned int) ntohs (msg->type),
1287 (unsigned int) ntohs (msg->size));
1289 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
1291 if (CT_NONE == tc->type)
1292 continue; /* client not yet ready */
1293 if ((GNUNET_YES == may_drop) && (CT_CORE != tc->type))
1294 continue; /* skip, this client does not care about payload */
1295 unicast (tc, msg, may_drop);
1298 if (GNUNET_NO == done)
1299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1300 "Message of type %u not delivered, is CORE service up?\n",
1306 * Broadcast the new active address to all clients monitoring the peer.
1308 * @param peer peer this update is about (never NULL)
1309 * @param address address, NULL on disconnect
1310 * @param state the current state of the peer
1311 * @param state_timeout the time out for the state
1314 GST_clients_broadcast_peer_notification (
1315 const struct GNUNET_PeerIdentity *peer,
1316 const struct GNUNET_HELLO_Address *address,
1317 enum GNUNET_TRANSPORT_PeerState state,
1318 struct GNUNET_TIME_Absolute state_timeout)
1320 struct GNUNET_MQ_Envelope *env;
1321 struct PeerIterateResponseMessage *msg;
1323 msg = compose_address_iterate_response_message (peer, address);
1324 msg->state = htonl (state);
1325 msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout);
1326 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
1328 if (CT_MONITOR != tc->type)
1330 if ((0 == memcmp (&tc->details.monitor_peer,
1332 sizeof(struct GNUNET_PeerIdentity))) ||
1333 (0 == memcmp (&tc->details.monitor_peer,
1335 sizeof(struct GNUNET_PeerIdentity))))
1337 env = GNUNET_MQ_msg_copy (&msg->header);
1338 GNUNET_MQ_send (tc->mq, env);
1346 * Mark the peer as down so we don't call the continuation
1347 * context in the future.
1350 * @param peer peer that got disconnected
1351 * @param value a `struct SendTransmitContinuationContext` to mark
1352 * @return #GNUNET_OK (continue to iterate)
1355 mark_peer_down (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
1357 struct SendTransmitContinuationContext *stcc = value;
1359 stcc->down = GNUNET_YES;
1365 * Notify all clients about a disconnect, and cancel
1366 * pending SEND_OK messages for this peer.
1368 * @param peer peer that disconnected
1371 GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer)
1373 struct DisconnectInfoMessage disconnect_msg;
1375 GNUNET_CONTAINER_multipeermap_get_multiple (active_stccs,
1379 disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage));
1380 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
1381 disconnect_msg.reserved = htonl (0);
1382 disconnect_msg.peer = *peer;
1383 GST_clients_broadcast (&disconnect_msg.header, GNUNET_NO);
1388 * Transmit our HELLO message to the given (connected) neighbour.
1390 * @param cls the 'HELLO' message
1391 * @param peer identity of the peer
1392 * @param address the address
1393 * @param state current state this peer is in
1394 * @param state_timeout timeout for the current state of the peer
1395 * @param bandwidth_in inbound quota in NBO
1396 * @param bandwidth_out outbound quota in NBO
1399 transmit_our_hello (void *cls,
1400 const struct GNUNET_PeerIdentity *peer,
1401 const struct GNUNET_HELLO_Address *address,
1402 enum GNUNET_TRANSPORT_PeerState state,
1403 struct GNUNET_TIME_Absolute state_timeout,
1404 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1405 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1407 const struct GNUNET_MessageHeader *hello = cls;
1409 if (0 == memcmp (peer, &GST_my_identity, sizeof(struct GNUNET_PeerIdentity)))
1410 return; /* not to ourselves */
1411 if (GNUNET_NO == GST_neighbours_test_connected (peer))
1414 GST_neighbours_send (peer,
1416 ntohs (hello->size),
1424 * My HELLO has changed. Tell everyone who should know.
1427 * @param hello new HELLO
1430 process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello)
1432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to clients\n");
1433 GST_clients_broadcast (hello, GNUNET_NO);
1434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to neighbours\n");
1435 GST_neighbours_iterate (&transmit_our_hello, (void *) hello);
1440 * We received some payload. Prepare to pass it on to our clients.
1442 * @param address address and (claimed) identity of the other peer
1443 * @param session identifier used for this session (NULL for plugins
1444 * that do not offer bi-directional communication to the sender
1445 * using the same "connection")
1446 * @param message the message to process
1447 * @return how long the plugin should wait until receiving more data
1449 static struct GNUNET_TIME_Relative
1450 process_payload (const struct GNUNET_HELLO_Address *address,
1451 struct GNUNET_ATS_Session *session,
1452 const struct GNUNET_MessageHeader *message)
1454 struct GNUNET_TIME_Relative ret;
1456 struct InboundMessage *im;
1457 size_t msg_size = ntohs (message->size);
1458 size_t size = sizeof(struct InboundMessage) + msg_size;
1459 char buf[size] GNUNET_ALIGN;
1461 do_forward = GNUNET_SYSERR;
1462 ret = GST_neighbours_calculate_receive_delay (&address->peer,
1465 if (! GST_neighbours_test_connected (&address->peer))
1467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1468 "Discarded %u bytes type %u payload from peer `%s'\n",
1469 (unsigned int) msg_size,
1470 ntohs (message->type),
1471 GNUNET_i2s (&address->peer));
1472 GNUNET_STATISTICS_update (
1474 gettext_noop ("# bytes payload discarded due to not connected peer"),
1480 if (GNUNET_YES != do_forward)
1482 im = (struct InboundMessage *) buf;
1483 im->header.size = htons (size);
1484 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
1485 im->peer = address->peer;
1486 GNUNET_memcpy (&im[1], message, ntohs (message->size));
1487 GST_clients_broadcast (&im->header, GNUNET_YES);
1493 * Task to asynchronously terminate a session.
1495 * @param cls the `struct GNUNET_ATS_SessionKiller` with the information for the kill
1498 kill_session_task (void *cls)
1500 struct GNUNET_ATS_SessionKiller *sk = cls;
1503 GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk);
1504 sk->plugin->disconnect_session (sk->plugin->cls, sk->session);
1510 * Force plugin to terminate session due to communication
1513 * @param plugin_name name of the plugin
1514 * @param session session to termiante
1517 kill_session (const char *plugin_name, struct GNUNET_ATS_Session *session)
1519 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
1520 struct GNUNET_ATS_SessionKiller *sk;
1522 for (sk = sk_head; NULL != sk; sk = sk->next)
1523 if (sk->session == session)
1525 plugin = GST_plugins_find (plugin_name);
1531 /* need to issue disconnect asynchronously */
1532 sk = GNUNET_new (struct GNUNET_ATS_SessionKiller);
1533 sk->session = session;
1534 sk->plugin = plugin;
1535 sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task, sk);
1536 GNUNET_CONTAINER_DLL_insert (sk_head, sk_tail, sk);
1541 * Black list check result for try_connect call
1542 * If connection to the peer is allowed request adddress and ???
1544 * @param cls the message
1545 * @param peer the peer
1546 * @param address the address
1547 * @param session the session
1548 * @param result the result
1551 connect_bl_check_cont (void *cls,
1552 const struct GNUNET_PeerIdentity *peer,
1553 const struct GNUNET_HELLO_Address *address,
1554 struct GNUNET_ATS_Session *session,
1557 struct GNUNET_MessageHeader *msg = cls;
1559 if (GNUNET_OK == result)
1561 /* Blacklist allows to speak to this peer, forward SYN to neighbours */
1562 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1563 "Received SYN message from peer `%s' at `%s'\n",
1565 GST_plugins_a2s (address));
1566 if (GNUNET_OK != GST_neighbours_handle_session_syn (msg, peer))
1568 GST_blacklist_abort_matching (address, session);
1569 kill_session (address->transport_name, session);
1575 if (GNUNET_SYSERR == result)
1576 return; /* check was aborted, session destroyed */
1577 /* Blacklist denies to speak to this peer */
1578 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1579 "Discarding SYN message from `%s' due to denied blacklist check\n",
1581 kill_session (address->transport_name, session);
1586 * Function called by the transport for each received message.
1588 * @param cls closure, const char* with the name of the plugin we received the message from
1589 * @param address address and (claimed) identity of the other peer
1590 * @param message the message, NULL if we only care about
1591 * learning about the delay until we should receive again
1592 * @param session identifier used for this session (NULL for plugins
1593 * that do not offer bi-directional communication to the sender
1594 * using the same "connection")
1595 * @return how long the plugin should wait until receiving more data
1596 * (plugins that do not support this, can ignore the return value)
1598 struct GNUNET_TIME_Relative
1599 GST_receive_callback (void *cls,
1600 const struct GNUNET_HELLO_Address *address,
1601 struct GNUNET_ATS_Session *session,
1602 const struct GNUNET_MessageHeader *message)
1604 const char *plugin_name = cls;
1605 struct GNUNET_TIME_Relative ret;
1608 ret = GNUNET_TIME_UNIT_ZERO;
1609 if (NULL == message)
1611 type = ntohs (message->type);
1612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1613 "Received message with type %u from peer `%s' at %s\n",
1615 GNUNET_i2s (&address->peer),
1616 GST_plugins_a2s (address));
1618 GNUNET_STATISTICS_update (GST_stats,
1619 gettext_noop ("# bytes total received"),
1620 ntohs (message->size),
1622 GST_neighbours_notify_data_recv (address, message);
1625 case GNUNET_MESSAGE_TYPE_HELLO_LEGACY:
1626 /* Legacy HELLO message, discard */
1629 case GNUNET_MESSAGE_TYPE_HELLO:
1630 if (GNUNET_OK != GST_validation_handle_hello (message))
1632 GNUNET_break_op (0);
1633 GST_blacklist_abort_matching (address, session);
1637 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
1638 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1639 "Processing PING from `%s'\n",
1640 GST_plugins_a2s (address));
1642 GST_validation_handle_ping (&address->peer, message, address, session))
1644 GST_blacklist_abort_matching (address, session);
1645 kill_session (plugin_name, session);
1649 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
1650 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1651 "Processing PONG from `%s'\n",
1652 GST_plugins_a2s (address));
1653 if (GNUNET_OK != GST_validation_handle_pong (&address->peer, message))
1655 GNUNET_break_op (0);
1656 GST_blacklist_abort_matching (address, session);
1657 kill_session (plugin_name, session);
1661 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN:
1662 /* Do blacklist check if communication with this peer is allowed */
1663 (void) GST_blacklist_test_allowed (&address->peer,
1665 &connect_bl_check_cont,
1666 GNUNET_copy_message (message),
1671 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK:
1673 GST_neighbours_handle_session_syn_ack (message, address, session))
1675 GST_blacklist_abort_matching (address, session);
1676 kill_session (plugin_name, session);
1680 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
1682 GST_neighbours_handle_session_ack (message, address, session))
1684 GNUNET_break_op (0);
1685 GST_blacklist_abort_matching (address, session);
1686 kill_session (plugin_name, session);
1690 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
1691 GST_neighbours_handle_disconnect_message (&address->peer, message);
1694 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA:
1695 GST_neighbours_handle_quota_message (&address->peer, message);
1698 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
1699 GST_neighbours_keepalive (&address->peer, message);
1702 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE:
1703 GST_neighbours_keepalive_response (&address->peer, message);
1707 /* should be payload */
1708 GNUNET_STATISTICS_update (GST_stats,
1709 gettext_noop ("# bytes payload received"),
1710 ntohs (message->size),
1712 ret = process_payload (address, session, message);
1716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1717 "Allowing receive from peer %s to continue in %s\n",
1718 GNUNET_i2s (&address->peer),
1719 GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
1725 * Function that will be called for each address the transport
1726 * is aware that it might be reachable under. Update our HELLO.
1728 * @param cls name of the plugin (const char*)
1729 * @param add_remove should the address added (YES) or removed (NO) from the
1730 * set of valid addresses?
1731 * @param address the address to add or remove
1734 plugin_env_address_change_notification (
1737 const struct GNUNET_HELLO_Address *address)
1739 static int addresses = 0;
1741 if (GNUNET_YES == add_remove)
1744 GNUNET_STATISTICS_update (GST_stats, "# transport addresses", 1, GNUNET_NO);
1746 else if (GNUNET_NO == add_remove)
1755 GNUNET_STATISTICS_update (GST_stats,
1756 "# transport addresses",
1761 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1762 "Transport now has %u addresses to communicate\n",
1764 GST_hello_modify_addresses (add_remove, address);
1769 * Function that will be called whenever the plugin internally
1770 * cleans up a session pointer and hence the service needs to
1771 * discard all of those sessions as well. Plugins that do not
1772 * use sessions can simply omit calling this function and always
1773 * use NULL wherever a session pointer is needed. This function
1774 * should be called BEFORE a potential "TransmitContinuation"
1775 * from the "TransmitFunction".
1777 * @param cls closure
1778 * @param address which address was the session for
1779 * @param session which session is being destoyed
1782 plugin_env_session_end (void *cls,
1783 const struct GNUNET_HELLO_Address *address,
1784 struct GNUNET_ATS_Session *session)
1786 struct GNUNET_ATS_SessionKiller *sk;
1788 if (NULL == address)
1793 if (NULL == session)
1798 GNUNET_assert (strlen (address->transport_name) > 0);
1801 GNUNET_ERROR_TYPE_DEBUG,
1802 "Notification from plugin about terminated session %p from peer `%s' address `%s'\n",
1804 GNUNET_i2s (&address->peer),
1805 GST_plugins_a2s (address));
1807 GST_neighbours_session_terminated (&address->peer, session);
1808 GST_ats_del_session (address, session);
1809 GST_blacklist_abort_matching (address, session);
1811 for (sk = sk_head; NULL != sk; sk = sk->next)
1813 if (sk->session == session)
1815 GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk);
1816 GNUNET_SCHEDULER_cancel (sk->task);
1825 * Black list check result from blacklist check triggered when a
1826 * plugin gave us a new session in #plugin_env_session_start(). If
1827 * connection to the peer is disallowed, kill the session.
1830 * @param peer the peer
1831 * @param address address associated with the request
1832 * @param session session associated with the request
1833 * @param result the result
1836 plugin_env_session_start_bl_check_cont (
1838 const struct GNUNET_PeerIdentity *peer,
1839 const struct GNUNET_HELLO_Address *address,
1840 struct GNUNET_ATS_Session *session,
1843 if (GNUNET_OK != result)
1845 kill_session (address->transport_name, session);
1849 GNUNET_HELLO_address_check_option (address,
1850 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1853 "Informing verifier about inbound session's address `%s'\n",
1854 GST_plugins_a2s (address));
1855 GST_validation_handle_address (address);
1861 * Plugin tells transport service about a new inbound session
1864 * @param address the address
1865 * @param session the new session
1866 * @param scope network scope information
1869 plugin_env_session_start (void *cls,
1870 const struct GNUNET_HELLO_Address *address,
1871 struct GNUNET_ATS_Session *session,
1872 enum GNUNET_NetworkType scope)
1874 struct GNUNET_ATS_Properties prop;
1876 if (NULL == address)
1881 if (NULL == session)
1887 GNUNET_ERROR_TYPE_INFO,
1888 "Notification from plugin `%s' about new session from peer `%s' address `%s'\n",
1889 address->transport_name,
1890 GNUNET_i2s (&address->peer),
1891 GST_plugins_a2s (address));
1893 GNUNET_HELLO_address_check_option (address,
1894 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1896 /* inbound is always new, but outbound MAY already be known, but
1897 for example for UNIX, we have symmetric connections and thus we
1898 may not know the address yet; add if necessary! */
1899 /* FIXME: maybe change API here so we just pass scope? */
1900 memset (&prop, 0, sizeof(prop));
1901 GNUNET_break (GNUNET_NT_UNSPECIFIED != scope);
1903 GST_ats_add_inbound_address (address, session, &prop);
1905 /* Do blacklist check if communication with this peer is allowed */
1906 (void) GST_blacklist_test_allowed (&address->peer,
1907 address->transport_name,
1908 &plugin_env_session_start_bl_check_cont,
1916 * Function called by ATS to notify the callee that the
1917 * assigned bandwidth or address for a given peer was changed. If the
1918 * callback is called with address/bandwidth assignments of zero, the
1919 * ATS disconnect function will still be called once the disconnect
1920 * actually happened.
1922 * @param cls closure
1923 * @param peer the peer this address is intended for
1924 * @param address address to use (for peer given in address)
1925 * @param session session to use (if available)
1926 * @param bandwidth_out assigned outbound bandwidth for the connection in NBO,
1927 * 0 to disconnect from peer
1928 * @param bandwidth_in assigned inbound bandwidth for the connection in NBO,
1929 * 0 to disconnect from peer
1930 * @param ats ATS information
1931 * @param ats_count number of @a ats elements
1934 ats_request_address_change (void *cls,
1935 const struct GNUNET_PeerIdentity *peer,
1936 const struct GNUNET_HELLO_Address *address,
1937 struct GNUNET_ATS_Session *session,
1938 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
1939 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
1941 uint32_t bw_in = ntohl (bandwidth_in.value__);
1942 uint32_t bw_out = ntohl (bandwidth_out.value__);
1946 /* ATS service died, all suggestions become invalid!
1947 (but we'll keep using the allocations for a little
1948 while, to keep going while ATS restarts) */
1949 /* FIXME: We should drop all
1950 connections now, as ATS won't explicitly tell
1951 us and be unaware of ongoing resource allocations! */
1954 /* ATS tells me to disconnect from peer */
1955 if ((0 == bw_in) && (0 == bw_out))
1957 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1958 "ATS tells me to disconnect from peer `%s'\n",
1960 GST_neighbours_force_disconnect (peer);
1963 GNUNET_assert (NULL != address);
1964 GNUNET_STATISTICS_update (GST_stats,
1965 "# ATS suggestions received",
1968 GST_neighbours_switch_to_address (address,
1976 * Closure for #test_connection_ok().
1978 struct TestConnectionContext
1981 * Is this the first neighbour we're checking?
1986 * Handle to the blacklisting client we need to ask.
1988 struct TransportClient *tc;
1993 * Got the result about an existing connection from a new blacklister.
1994 * Shutdown the neighbour if necessary.
1997 * @param peer the neighbour that was investigated
1998 * @param address address associated with the request
1999 * @param session session associated with the request
2000 * @param allowed #GNUNET_OK if we can keep it,
2001 * #GNUNET_NO if we must shutdown the connection
2004 confirm_or_drop_neighbour (void *cls,
2005 const struct GNUNET_PeerIdentity *peer,
2006 const struct GNUNET_HELLO_Address *address,
2007 struct GNUNET_ATS_Session *session,
2010 if (GNUNET_OK == allowed)
2011 return; /* we're done */
2012 GNUNET_STATISTICS_update (GST_stats,
2013 gettext_noop ("# disconnects due to blacklist"),
2016 GST_neighbours_force_disconnect (peer);
2021 * Test if an existing connection is still acceptable given a new
2022 * blacklisting client.
2024 * @param cls the `struct TestConnectionContext *`
2025 * @param peer identity of the peer
2026 * @param address the address
2027 * @param state current state this peer is in
2028 * @param state_timeout timeout for the current state of the peer
2029 * @param bandwidth_in bandwidth assigned inbound
2030 * @param bandwidth_out bandwidth assigned outbound
2033 test_connection_ok (void *cls,
2034 const struct GNUNET_PeerIdentity *peer,
2035 const struct GNUNET_HELLO_Address *address,
2036 enum GNUNET_TRANSPORT_PeerState state,
2037 struct GNUNET_TIME_Absolute state_timeout,
2038 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
2039 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2041 struct TestConnectionContext *tcc = cls;
2042 struct GST_BlacklistCheck *bc;
2044 bc = GNUNET_new (struct GST_BlacklistCheck);
2045 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
2047 bc->address = GNUNET_HELLO_address_copy (address);
2048 bc->cont = &confirm_or_drop_neighbour;
2049 bc->cont_cls = NULL;
2050 bc->bl_pos = tcc->tc;
2051 if (GNUNET_YES == tcc->first)
2053 /* all would wait for the same client, no need to
2054 * create more than just the first task right now */
2055 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
2056 tcc->first = GNUNET_NO;
2062 * Initialize a blacklisting client. We got a blacklist-init
2063 * message from this client, add it to the list of clients
2064 * to query for blacklisting.
2066 * @param cls the client
2067 * @param message the blacklist-init message that was sent
2070 handle_client_blacklist_init (void *cls,
2071 const struct GNUNET_MessageHeader *message)
2073 struct TransportClient *tc = cls;
2074 struct TestConnectionContext tcc;
2076 if (CT_NONE != tc->type)
2079 GNUNET_SERVICE_client_drop (tc->client);
2082 GNUNET_SERVICE_client_mark_monitor (tc->client);
2083 tc->type = CT_BLACKLIST;
2084 tc->details.blacklist.call_receive_done = GNUNET_YES;
2085 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New blacklist client %p\n", tc);
2086 /* confirm that all existing connections are OK! */
2088 tcc.first = GNUNET_YES;
2089 GST_neighbours_iterate (&test_connection_ok, &tcc);
2094 * Free the given entry in the blacklist.
2097 * @param key host identity (unused)
2098 * @param value the blacklist entry
2099 * @return #GNUNET_OK (continue to iterate)
2102 free_blacklist_entry (void *cls,
2103 const struct GNUNET_PeerIdentity *key,
2108 GNUNET_free_non_null (be);
2114 * Set traffic metric to manipulate
2116 * @param cls closure
2117 * @param message containing information
2120 handle_client_set_metric (void *cls, const struct TrafficMetricMessage *tm)
2122 struct TransportClient *tc = cls;
2124 GST_manipulation_set_metric (tm);
2125 GNUNET_SERVICE_client_continue (tc->client);
2130 * Function called when the service shuts down. Unloads our plugins
2131 * and cancels pending validations.
2133 * @param cls closure, unused
2136 shutdown_task (void *cls)
2138 struct AddressToStringContext *cur;
2140 GST_neighbours_stop ();
2141 GST_plugins_unload ();
2142 GST_validation_stop ();
2144 GNUNET_ATS_scheduling_done (GST_ats);
2146 GNUNET_ATS_connectivity_done (GST_ats_connect);
2147 GST_ats_connect = NULL;
2148 GNUNET_NT_scanner_done (GST_is);
2150 while (NULL != (cur = a2s_head))
2152 GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, cur);
2155 if (NULL != plugin_nc)
2157 GNUNET_notification_context_destroy (plugin_nc);
2160 GNUNET_CONTAINER_multipeermap_destroy (active_stccs);
2161 active_stccs = NULL;
2162 if (NULL != blacklist)
2164 GNUNET_CONTAINER_multipeermap_iterate (blacklist,
2165 &free_blacklist_entry,
2167 GNUNET_CONTAINER_multipeermap_destroy (blacklist);
2171 GST_manipulation_stop ();
2173 if (NULL != GST_peerinfo)
2175 GNUNET_PEERINFO_disconnect (GST_peerinfo);
2176 GST_peerinfo = NULL;
2178 if (NULL != GST_stats)
2180 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
2183 if (NULL != GST_my_private_key)
2185 GNUNET_free (GST_my_private_key);
2186 GST_my_private_key = NULL;
2192 * Perform next action in the blacklist check.
2194 * @param cls the `struct GST_BlacklistCheck *`
2197 do_blacklist_check (void *cls)
2199 struct GST_BlacklistCheck *bc = cls;
2200 struct TransportClient *tc;
2201 struct GNUNET_MQ_Envelope *env;
2202 struct BlacklistMessage *bm;
2205 while (NULL != (tc = bc->bl_pos))
2207 if (CT_BLACKLIST == tc->type)
2209 bc->bl_pos = tc->next;
2213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2214 "No other blacklist clients active, will allow neighbour `%s'\n",
2215 GNUNET_i2s (&bc->peer));
2217 bc->cont (bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_OK);
2218 GST_blacklist_test_cancel (bc);
2221 if ((NULL != tc->details.blacklist.bc) ||
2222 (GNUNET_NO != tc->details.blacklist.waiting_for_reply))
2223 return; /* someone else busy with this client */
2224 tc->details.blacklist.bc = bc;
2225 env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY);
2226 bm->is_allowed = htonl (0);
2227 bm->peer = bc->peer;
2228 GNUNET_MQ_send (tc->mq, env);
2229 if (GNUNET_YES == tc->details.blacklist.call_receive_done)
2231 tc->details.blacklist.call_receive_done = GNUNET_NO;
2232 GNUNET_SERVICE_client_continue (tc->client);
2234 tc->details.blacklist.waiting_for_reply = GNUNET_YES;
2239 * A blacklisting client has sent us reply. Process it.
2241 * @param cls the client
2242 * @param msg the blacklist-reply message that was sent
2245 handle_client_blacklist_reply (void *cls, const struct BlacklistMessage *msg)
2247 struct TransportClient *tc = cls;
2248 struct GST_BlacklistCheck *bc;
2250 if (CT_BLACKLIST != tc->type)
2253 GNUNET_SERVICE_client_drop (tc->client);
2256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2257 "Blacklist client %p sent reply for `%s'\n",
2259 GNUNET_i2s (&msg->peer));
2260 bc = tc->details.blacklist.bc;
2261 tc->details.blacklist.bc = NULL;
2262 tc->details.blacklist.waiting_for_reply = GNUNET_NO;
2263 tc->details.blacklist.call_receive_done = GNUNET_YES;
2266 /* only run this if the blacklist check has not been
2267 * cancelled in the meantime... */
2268 GNUNET_assert (bc->bl_pos == tc);
2269 if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
2271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2272 "Blacklist check failed, peer not allowed\n");
2273 /* For the duration of the continuation, make the ongoing
2274 check invisible (to avoid double-cancellation); then
2275 add it back again so we can re-use GST_blacklist_test_cancel() */
2276 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
2277 bc->cont (bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_NO);
2278 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
2279 GST_blacklist_test_cancel (bc);
2280 tc->details.blacklist.call_receive_done = GNUNET_NO;
2281 GNUNET_SERVICE_client_continue (tc->client);
2286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2287 "Blacklist check succeeded, continuing with checks\n");
2288 tc->details.blacklist.call_receive_done = GNUNET_NO;
2289 GNUNET_SERVICE_client_continue (tc->client);
2290 bc->bl_pos = tc->next;
2291 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
2294 /* check if any other blacklist checks are waiting for this blacklister */
2295 for (bc = bc_head; bc != NULL; bc = bc->next)
2296 if ((bc->bl_pos == tc) && (NULL == bc->task))
2298 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
2305 * Add the given peer to the blacklist (for the given transport).
2307 * @param peer peer to blacklist
2308 * @param transport_name transport to blacklist for this peer, NULL for all
2311 GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
2312 const char *transport_name)
2314 char *transport = NULL;
2316 if (NULL != transport_name)
2318 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2319 "Adding peer `%s' with plugin `%s' to blacklist\n",
2322 transport = GNUNET_strdup (transport_name);
2325 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2326 "Adding peer `%s' with all plugins to blacklist\n",
2328 if (NULL == blacklist)
2330 GNUNET_CONTAINER_multipeermap_create (TRANSPORT_BLACKLIST_HT_SIZE,
2333 GNUNET_CONTAINER_multipeermap_put (blacklist,
2336 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2341 * Abort blacklist if @a address and @a session match.
2343 * @param address address used to abort matching checks
2344 * @param session session used to abort matching checks
2347 GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
2348 struct GNUNET_ATS_Session *session)
2350 struct GST_BlacklistCheck *bc;
2351 struct GST_BlacklistCheck *n;
2354 while (NULL != (bc = n))
2357 if ((bc->session == session) &&
2358 (0 == GNUNET_HELLO_address_cmp (bc->address, address)))
2360 bc->cont (bc->cont_cls,
2365 GST_blacklist_test_cancel (bc);
2372 * Test if the given blacklist entry matches. If so,
2373 * abort the iteration.
2375 * @param cls the transport name to match (const char*)
2376 * @param key the key (unused)
2377 * @param value the 'char *' (name of a blacklisted transport)
2378 * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches
2381 test_blacklisted (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
2383 const char *transport_name = cls;
2386 /* Blacklist entry be:
2387 * (NULL == be): peer is blacklisted with all plugins
2388 * (NULL != be): peer is blacklisted for a specific plugin
2390 * If (NULL != transport_name) we look for a transport specific entry:
2391 * if (transport_name == be) forbidden
2393 */GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2394 "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n",
2396 (NULL == transport_name) ? "unspecified" : transport_name,
2397 (NULL == be) ? "all plugins" : be);
2398 /* all plugins for this peer were blacklisted: disallow */
2402 /* blacklist check for specific transport */
2403 if ((NULL != transport_name) && (NULL != value))
2405 if (0 == strcmp (transport_name, be))
2406 return GNUNET_NO; /* plugin is blacklisted! */
2413 * Test if a peer/transport combination is blacklisted.
2415 * @param peer the identity of the peer to test
2416 * @param transport_name name of the transport to test, never NULL
2417 * @param cont function to call with result
2418 * @param cont_cls closure for @a cont
2419 * @param address address to pass back to @a cont, can be NULL
2420 * @param session session to pass back to @a cont, can be NULL
2421 * @return handle to the blacklist check, NULL if the decision
2422 * was made instantly and @a cont was already called
2424 struct GST_BlacklistCheck *
2425 GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
2426 const char *transport_name,
2427 GST_BlacklistTestContinuation cont,
2429 const struct GNUNET_HELLO_Address *address,
2430 struct GNUNET_ATS_Session *session)
2432 struct GST_BlacklistCheck *bc;
2433 struct TransportClient *tc;
2435 GNUNET_assert (NULL != peer);
2436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2437 "Blacklist check for peer `%s':%s\n",
2439 (NULL != transport_name) ? transport_name : "unspecified");
2441 /* Check local blacklist by iterating over hashmap
2442 * If iteration is aborted, we found a matching blacklist entry */
2443 if ((NULL != blacklist) &&
2445 GNUNET_CONTAINER_multipeermap_get_multiple (blacklist,
2448 (void *) transport_name)))
2450 /* Disallowed by config, disapprove instantly */
2451 GNUNET_STATISTICS_update (GST_stats,
2452 gettext_noop ("# disconnects due to blacklist"),
2455 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2456 _ ("Disallowing connection to peer `%s' on transport %s\n"),
2458 (NULL != transport_name) ? transport_name : "unspecified");
2460 cont (cont_cls, peer, address, session, GNUNET_NO);
2464 for (tc = clients_head; NULL != tc; tc = tc->next)
2465 if (CT_BLACKLIST == tc->type)
2469 /* no blacklist clients, approve instantly */
2471 cont (cont_cls, peer, address, session, GNUNET_OK);
2472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2473 "Allowing connection to peer `%s' %s\n",
2475 (NULL != transport_name) ? transport_name : "");
2479 /* need to query blacklist clients */
2480 bc = GNUNET_new (struct GST_BlacklistCheck);
2481 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
2483 bc->address = GNUNET_HELLO_address_copy (address);
2484 bc->session = session;
2486 bc->cont_cls = cont_cls;
2488 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
2494 * Cancel a blacklist check.
2496 * @param bc check to cancel
2499 GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc)
2501 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
2502 if (NULL != bc->bl_pos)
2504 if ((CT_BLACKLIST == bc->bl_pos->type) &&
2505 (bc->bl_pos->details.blacklist.bc == bc))
2507 /* we're at the head of the queue, remove us! */
2508 bc->bl_pos->details.blacklist.bc = NULL;
2511 if (NULL != bc->task)
2513 GNUNET_SCHEDULER_cancel (bc->task);
2516 GNUNET_free_non_null (bc->address);
2522 * Function to iterate over options in the blacklisting section for a peer.
2524 * @param cls closure
2525 * @param section name of the section
2526 * @param option name of the option
2527 * @param value value of the option
2530 blacklist_cfg_iter (void *cls,
2531 const char *section,
2535 unsigned int *res = cls;
2536 struct GNUNET_PeerIdentity peer;
2541 GNUNET_CRYPTO_eddsa_public_key_from_string (option,
2546 if ((NULL == value) || (0 == strcmp (value, "")))
2548 /* Blacklist whole peer */
2549 GST_blacklist_add_peer (&peer, NULL);
2550 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2551 _ ("Adding blacklisting entry for peer `%s'\n"),
2552 GNUNET_i2s (&peer));
2556 plugs = GNUNET_strdup (value);
2557 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
2559 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2560 _ ("Adding blacklisting entry for peer `%s':`%s'\n"),
2563 GST_blacklist_add_peer (&peer, pos);
2565 GNUNET_free (plugs);
2572 * Read blacklist configuration
2574 * @param cfg the configuration handle
2575 * @param my_id my peer identity
2578 read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg,
2579 const struct GNUNET_PeerIdentity *my_id)
2582 unsigned int res = 0;
2584 GNUNET_snprintf (cfg_sect,
2586 "transport-blacklist-%s",
2587 GNUNET_i2s_full (my_id));
2588 GNUNET_CONFIGURATION_iterate_section_values (cfg,
2590 &blacklist_cfg_iter,
2592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2593 "Loaded %u blacklisting entries from configuration\n",
2599 * Initiate transport service.
2601 * @param cls closure
2602 * @param c configuration to use
2603 * @param service the initialized service
2607 const struct GNUNET_CONFIGURATION_Handle *c,
2608 struct GNUNET_SERVICE_Handle *service)
2611 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
2612 long long unsigned int max_fd_cfg;
2619 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c,
2625 GNUNET_ERROR_TYPE_ERROR,
2627 "Transport service is lacking key configuration settings. Exiting.\n"));
2628 GNUNET_SCHEDULER_shutdown ();
2631 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (c,
2636 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
2638 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
2639 GNUNET_free (keyfile);
2640 GNUNET_assert (NULL != pk);
2641 GST_my_private_key = pk;
2643 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
2644 GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg);
2645 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key,
2646 &GST_my_identity.public_key);
2647 GNUNET_assert (NULL != GST_my_private_key);
2649 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2650 "My identity is `%s'\n",
2651 GNUNET_i2s_full (&GST_my_identity));
2653 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
2654 if (NULL == GST_peerinfo)
2656 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2657 _ ("Could not access PEERINFO service. Exiting.\n"));
2658 GNUNET_SCHEDULER_shutdown ();
2665 struct rlimit r_file;
2667 if (0 == getrlimit (RLIMIT_NOFILE, &r_file))
2669 max_fd_rlimit = r_file.rlim_cur;
2670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2671 "Maximum number of open files was: %u/%u\n",
2672 (unsigned int) r_file.rlim_cur,
2673 (unsigned int) r_file.rlim_max);
2676 (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */
2679 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (GST_cfg,
2683 max_fd_cfg = max_fd_rlimit;
2685 if (max_fd_cfg > max_fd_rlimit)
2686 max_fd = max_fd_cfg;
2688 max_fd = max_fd_rlimit;
2689 if (max_fd < DEFAULT_MAX_FDS)
2690 max_fd = DEFAULT_MAX_FDS;
2692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2693 "Limiting number of sockets to %u: validation %u, neighbors: %u\n",
2699 GNUNET_CONFIGURATION_get_value_yesno (GST_cfg, "topology", "FRIENDS-ONLY");
2700 if (GNUNET_SYSERR == friend_only)
2701 friend_only = GNUNET_NO; /* According to topology defaults */
2702 /* start subsystems */
2703 /* Disable DSTJ peer */
2705 struct GNUNET_PeerIdentity dstj;
2706 const char *ds = "DSTJBRRKZ8TBW3FGK6B0M5QXWT9WYNZ45H5MCV4HY7ST64Q8T9F0";
2710 GNUNET_CRYPTO_eddsa_public_key_from_string (ds,
2713 GST_blacklist_add_peer (&dstj, NULL);
2715 read_blacklist_configuration (GST_cfg, &GST_my_identity);
2716 GST_is = GNUNET_NT_scanner_init ();
2717 GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg);
2719 GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL);
2721 GST_manipulation_init ();
2722 GST_plugins_load (&GST_manipulation_recv,
2723 &plugin_env_address_change_notification,
2724 &plugin_env_session_start,
2725 &plugin_env_session_end);
2726 GST_hello_start (friend_only, &process_hello_update, NULL);
2727 GST_neighbours_start ((max_fd / 3) * 2);
2728 active_stccs = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES);
2729 plugin_nc = GNUNET_notification_context_create (0);
2730 GST_validation_start ((max_fd / 3));
2735 * Define "main" method using service macro.
2737 GNUNET_SERVICE_MAIN (
2739 GNUNET_SERVICE_OPTION_NONE,
2742 &client_disconnect_cb,
2744 GNUNET_MQ_hd_fixed_size (client_start,
2745 GNUNET_MESSAGE_TYPE_TRANSPORT_START,
2746 struct StartMessage,
2748 GNUNET_MQ_hd_var_size (client_hello,
2749 GNUNET_MESSAGE_TYPE_HELLO,
2750 struct GNUNET_MessageHeader,
2752 GNUNET_MQ_hd_var_size (client_send,
2753 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
2754 struct OutboundMessage,
2756 GNUNET_MQ_hd_var_size (client_address_to_string,
2757 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING,
2758 struct AddressLookupMessage,
2760 GNUNET_MQ_hd_fixed_size (client_monitor_peers,
2761 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST,
2762 struct PeerMonitorMessage,
2764 GNUNET_MQ_hd_fixed_size (client_blacklist_init,
2765 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
2766 struct GNUNET_MessageHeader,
2768 GNUNET_MQ_hd_fixed_size (client_blacklist_reply,
2769 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
2770 struct BlacklistMessage,
2772 GNUNET_MQ_hd_fixed_size (client_set_metric,
2773 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC,
2774 struct TrafficMetricMessage,
2776 GNUNET_MQ_hd_fixed_size (client_monitor_plugins,
2777 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START,
2778 struct GNUNET_MessageHeader,
2780 GNUNET_MQ_handler_end ());
2783 /* end of file gnunet-service-transport.c */