2 This file is part of GNUnet.
3 Copyright (C) 2010-2015 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file transport/gnunet-service-transport.c
22 * @brief main for gnunet-service-transport
23 * @author Christian Grothoff
26 #include "gnunet_util_lib.h"
27 #include "gnunet_hello_lib.h"
28 #include "gnunet_statistics_service.h"
29 #include "gnunet_transport_service.h"
30 #include "gnunet_peerinfo_service.h"
31 #include "gnunet_ats_service.h"
32 #include "gnunet-service-transport.h"
33 #include "gnunet-service-transport_ats.h"
34 #include "gnunet-service-transport_blacklist.h"
35 #include "gnunet-service-transport_clients.h"
36 #include "gnunet-service-transport_hello.h"
37 #include "gnunet-service-transport_neighbours.h"
38 #include "gnunet-service-transport_plugins.h"
39 #include "gnunet-service-transport_validation.h"
40 #include "gnunet-service-transport_manipulation.h"
41 #include "transport.h"
45 * Information we need for an asynchronous session kill.
52 struct SessionKiller *next;
57 struct SessionKiller *prev;
62 struct Session *session;
65 * Plugin for the session.
67 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
72 struct GNUNET_SCHEDULER_Task * task;
77 * We track active blacklist checks in a DLL so we can cancel them if
78 * necessary. We typically check against the blacklist a few times
79 * during connection setup, as the check is asynchronous and the
80 * blacklist may change its mind before the connection goes fully up.
81 * Similarly, the session may die during the asynchronous check, so
82 * we use this list to then cancel ongoing checks.
84 struct BlacklistCheckContext
87 * We keep these in a DLL.
89 struct BlacklistCheckContext *prev;
92 * We keep these in a DLL.
94 struct BlacklistCheckContext *next;
97 * Handle with the blacklist subsystem.
99 struct GST_BlacklistCheck *blc;
102 * The address we are checking.
104 struct GNUNET_HELLO_Address *address;
107 * Session associated with the address (or NULL).
109 struct Session *session;
112 * Message to process in the continuation if the
113 * blacklist check is ok, can be NULL.
115 struct GNUNET_MessageHeader *msg;
124 struct GNUNET_STATISTICS_Handle *GST_stats;
127 * Configuration handle.
129 const struct GNUNET_CONFIGURATION_Handle *GST_cfg;
132 * Configuration handle.
134 struct GNUNET_PeerIdentity GST_my_identity;
137 * Handle to peerinfo service.
139 struct GNUNET_PEERINFO_Handle *GST_peerinfo;
142 * Handle to our service's server.
144 static struct GNUNET_SERVER_Handle *GST_server;
149 struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key;
152 * ATS scheduling handle.
154 struct GNUNET_ATS_SchedulingHandle *GST_ats;
157 * ATS connectivity handle.
159 struct GNUNET_ATS_ConnectivityHandle *GST_ats_connect;
162 * Hello address expiration
164 struct GNUNET_TIME_Relative hello_expiration;
167 * Head of DLL of asynchronous tasks to kill sessions.
169 static struct SessionKiller *sk_head;
172 * Tail of DLL of asynchronous tasks to kill sessions.
174 static struct SessionKiller *sk_tail;
177 * Interface scanner determines our LAN address range(s).
179 static struct GNUNET_ATS_InterfaceScanner *is;
182 * Head of DLL of blacklist checks we have pending for
183 * incoming sessions and/or SYN requests. We may
184 * want to move this into the blacklist-logic at some
187 struct BlacklistCheckContext *bc_head;
190 * Tail of DLL of blacklist checks we have pending for
191 * incoming sessions and/or SYN requests.
193 struct BlacklistCheckContext *bc_tail;
197 * Transmit our HELLO message to the given (connected) neighbour.
199 * @param cls the 'HELLO' message
200 * @param peer identity of the peer
201 * @param address the address
202 * @param state current state this peer is in
203 * @param state_timeout timeout for the current state of the peer
204 * @param bandwidth_in inbound quota in NBO
205 * @param bandwidth_out outbound quota in NBO
208 transmit_our_hello (void *cls,
209 const struct GNUNET_PeerIdentity *peer,
210 const struct GNUNET_HELLO_Address *address,
211 enum GNUNET_TRANSPORT_PeerState state,
212 struct GNUNET_TIME_Absolute state_timeout,
213 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
214 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
216 const struct GNUNET_MessageHeader *hello = cls;
221 sizeof (struct GNUNET_PeerIdentity)))
222 return; /* not to ourselves */
223 if (GNUNET_NO == GST_neighbours_test_connected (peer))
226 GST_neighbours_send (peer,
235 * My HELLO has changed. Tell everyone who should know.
238 * @param hello new HELLO
241 process_hello_update (void *cls,
242 const struct GNUNET_MessageHeader *hello)
244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
245 "Broadcasting HELLO to clients\n");
246 GST_clients_broadcast (hello, GNUNET_NO);
247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
248 "Broadcasting HELLO to neighbours\n");
249 GST_neighbours_iterate (&transmit_our_hello,
255 * We received some payload. Prepare to pass it on to our clients.
257 * @param address address and (claimed) identity of the other peer
258 * @param session identifier used for this session (NULL for plugins
259 * that do not offer bi-directional communication to the sender
260 * using the same "connection")
261 * @param message the message to process
262 * @return how long the plugin should wait until receiving more data
264 static struct GNUNET_TIME_Relative
265 process_payload (const struct GNUNET_HELLO_Address *address,
266 struct Session *session,
267 const struct GNUNET_MessageHeader *message)
269 struct GNUNET_TIME_Relative ret;
271 struct InboundMessage *im;
272 size_t msg_size = ntohs (message->size);
273 size_t size = sizeof(struct InboundMessage) + msg_size;
274 char buf[size] GNUNET_ALIGN;
276 do_forward = GNUNET_SYSERR;
277 ret = GST_neighbours_calculate_receive_delay (&address->peer,
280 if (! GST_neighbours_test_connected (&address->peer))
282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
283 "Discarded %u bytes type %u payload from peer `%s'\n",
285 ntohs (message->type),
286 GNUNET_i2s (&address->peer));
287 GNUNET_STATISTICS_update (GST_stats, gettext_noop
288 ("# bytes payload discarded due to not connected peer"),
294 if (GNUNET_YES != do_forward)
296 im = (struct InboundMessage *) buf;
297 im->header.size = htons (size);
298 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
299 im->peer = address->peer;
300 memcpy (&im[1], message, ntohs (message->size));
301 GST_clients_broadcast (&im->header, GNUNET_YES);
307 * Task to asynchronously terminate a session.
309 * @param cls the `struct SessionKiller` with the information for the kill
310 * @param tc scheduler context
313 kill_session_task (void *cls,
314 const struct GNUNET_SCHEDULER_TaskContext *tc)
316 struct SessionKiller *sk = cls;
319 GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk);
320 sk->plugin->disconnect_session (sk->plugin->cls, sk->session);
326 * Cancel all blacklist checks that are pending for the given address and session.
327 * NOTE: Consider moving the "bc_*" logic into blacklist.h?
329 * @param address address to remove from check
330 * @param sesssion session that must match to remove for check
333 cancel_pending_blacklist_checks (const struct GNUNET_HELLO_Address *address,
334 struct Session *session)
336 struct BlacklistCheckContext *blctx;
337 struct BlacklistCheckContext *next;
340 for (blctx = next; NULL != blctx; blctx = next)
343 if ( (NULL != blctx->address) &&
344 (0 == GNUNET_HELLO_address_cmp(blctx->address, address)) &&
345 (blctx->session == session))
347 GNUNET_CONTAINER_DLL_remove (bc_head,
350 if (NULL != blctx->blc)
352 GST_blacklist_test_cancel (blctx->blc);
355 GNUNET_HELLO_address_free (blctx->address);
356 GNUNET_free_non_null (blctx->msg);
364 * Force plugin to terminate session due to communication
367 * @param plugin_name name of the plugin
368 * @param session session to termiante
371 kill_session (const char *plugin_name,
372 struct Session *session)
374 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
375 struct SessionKiller *sk;
377 for (sk = sk_head; NULL != sk; sk = sk->next)
378 if (sk->session == session)
380 plugin = GST_plugins_find (plugin_name);
386 /* need to issue disconnect asynchronously */
387 sk = GNUNET_new (struct SessionKiller);
388 sk->session = session;
390 sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task, sk);
391 GNUNET_CONTAINER_DLL_insert (sk_head,
398 * Black list check result for try_connect call
399 * If connection to the peer is allowed request adddress and ???
401 * @param cls blc_ctx bl context
402 * @param peer the peer
403 * @param result the result
406 connect_bl_check_cont (void *cls,
407 const struct GNUNET_PeerIdentity *peer,
410 struct BlacklistCheckContext *blctx = cls;
412 GNUNET_CONTAINER_DLL_remove (bc_head,
416 if (GNUNET_OK == result)
418 /* Blacklist allows to speak to this peer, forward SYN to neighbours */
419 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
420 "Received SYN message from peer `%s' at `%s'\n",
422 GST_plugins_a2s (blctx->address));
424 GST_neighbours_handle_session_syn (blctx->msg,
425 &blctx->address->peer))
427 cancel_pending_blacklist_checks (blctx->address,
429 kill_session (blctx->address->transport_name,
435 /* Blacklist denies to speak to this peer */
436 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
437 "Discarding SYN message from `%s' due to denied blacklist check\n",
439 cancel_pending_blacklist_checks (blctx->address,
441 kill_session (blctx->address->transport_name,
445 if (NULL != blctx->address)
446 GNUNET_HELLO_address_free (blctx->address);
447 GNUNET_free (blctx->msg);
453 * Function called by the transport for each received message.
455 * @param cls closure, const char* with the name of the plugin we received the message from
456 * @param address address and (claimed) identity of the other peer
457 * @param message the message, NULL if we only care about
458 * learning about the delay until we should receive again
459 * @param session identifier used for this session (NULL for plugins
460 * that do not offer bi-directional communication to the sender
461 * using the same "connection")
462 * @return how long the plugin should wait until receiving more data
463 * (plugins that do not support this, can ignore the return value)
465 struct GNUNET_TIME_Relative
466 GST_receive_callback (void *cls,
467 const struct GNUNET_HELLO_Address *address,
468 struct Session *session,
469 const struct GNUNET_MessageHeader *message)
471 const char *plugin_name = cls;
472 struct GNUNET_TIME_Relative ret;
473 struct BlacklistCheckContext *blctx;
474 struct GST_BlacklistCheck *blc;
477 ret = GNUNET_TIME_UNIT_ZERO;
480 type = ntohs (message->type);
481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
482 "Received message with type %u from peer `%s'\n",
484 GNUNET_i2s (&address->peer));
486 GNUNET_STATISTICS_update (GST_stats,
487 gettext_noop ("# bytes total received"),
488 ntohs (message->size),
490 GST_neighbours_notify_data_recv (address,
494 case GNUNET_MESSAGE_TYPE_HELLO_LEGACY:
495 /* Legacy HELLO message, discard */
497 case GNUNET_MESSAGE_TYPE_HELLO:
498 if (GNUNET_OK != GST_validation_handle_hello (message))
501 cancel_pending_blacklist_checks (address,
505 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
507 "Processing `%s' from `%s'\n", "PING",
508 GST_plugins_a2s (address));
510 GST_validation_handle_ping (&address->peer,
515 cancel_pending_blacklist_checks (address,
517 kill_session (plugin_name,
521 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
522 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
523 "Processing `%s' from `%s'\n", "PONG",
524 GST_plugins_a2s (address));
525 if (GNUNET_OK != GST_validation_handle_pong (&address->peer, message))
528 cancel_pending_blacklist_checks (address, session);
529 kill_session (plugin_name, session);
532 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN:
533 /* Do blacklist check if communication with this peer is allowed */
534 blctx = GNUNET_new (struct BlacklistCheckContext);
535 blctx->address = GNUNET_HELLO_address_copy (address);
536 blctx->session = session;
537 blctx->msg = GNUNET_malloc (ntohs(message->size));
540 ntohs (message->size));
541 GNUNET_CONTAINER_DLL_insert (bc_head,
545 (blc = GST_blacklist_test_allowed (&address->peer,
547 &connect_bl_check_cont,
553 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK:
555 GST_neighbours_handle_session_syn_ack (message,
559 cancel_pending_blacklist_checks (address, session);
560 kill_session (plugin_name, session);
563 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
565 GST_neighbours_handle_session_ack (message,
570 cancel_pending_blacklist_checks (address, session);
571 kill_session (plugin_name, session);
574 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
575 GST_neighbours_handle_disconnect_message (&address->peer, message);
577 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
578 GST_neighbours_keepalive (&address->peer, message);
580 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE:
581 GST_neighbours_keepalive_response (&address->peer, message);
584 /* should be payload */
585 GNUNET_STATISTICS_update (GST_stats,
586 gettext_noop ("# bytes payload received"),
587 ntohs (message->size),
589 ret = process_payload (address,
595 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
596 "Allowing receive from peer %s to continue in %s\n",
597 GNUNET_i2s (&address->peer),
598 GNUNET_STRINGS_relative_time_to_string (ret,
605 * Function that will be called for each address the transport
606 * is aware that it might be reachable under. Update our HELLO.
608 * @param cls name of the plugin (const char*)
609 * @param add_remove should the address added (YES) or removed (NO) from the
610 * set of valid addresses?
611 * @param address the address to add or remove
614 plugin_env_address_change_notification (void *cls,
616 const struct GNUNET_HELLO_Address *address)
618 static int addresses = 0;
619 struct GNUNET_STATISTICS_Handle *cfg = GST_stats;
621 if (GNUNET_YES == add_remove)
624 GNUNET_STATISTICS_update (cfg, "# transport addresses", 1, GNUNET_NO);
626 else if (GNUNET_NO == add_remove)
633 GNUNET_STATISTICS_update (cfg, "# transport addresses", -1, GNUNET_NO);
637 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
638 "Transport now has %u addresses to communicate\n",
640 GST_hello_modify_addresses (add_remove, address);
645 * Function that will be called whenever the plugin internally
646 * cleans up a session pointer and hence the service needs to
647 * discard all of those sessions as well. Plugins that do not
648 * use sessions can simply omit calling this function and always
649 * use NULL wherever a session pointer is needed. This function
650 * should be called BEFORE a potential "TransmitContinuation"
651 * from the "TransmitFunction".
654 * @param address which address was the session for
655 * @param session which session is being destoyed
658 plugin_env_session_end (void *cls,
659 const struct GNUNET_HELLO_Address *address,
660 struct Session *session)
662 struct SessionKiller *sk;
674 GNUNET_assert (strlen (address->transport_name) > 0);
676 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
677 "Notification from plugin about terminated session %p from peer `%s' address `%s'\n",
679 GNUNET_i2s (&address->peer),
680 GST_plugins_a2s (address));
682 GST_neighbours_session_terminated (&address->peer, session);
683 GST_ats_del_session (address, session);
684 cancel_pending_blacklist_checks (address, session);
686 for (sk = sk_head; NULL != sk; sk = sk->next)
688 if (sk->session == session)
690 GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk);
691 GNUNET_SCHEDULER_cancel (sk->task);
700 * Function that will be called to figure if an address is an loopback,
701 * LAN, WAN etc. address
704 * @param addr binary address
705 * @param addrlen length of the @a addr
706 * @return type of the network @a addr belongs to
708 static enum GNUNET_ATS_Network_Type
709 plugin_env_address_to_type (void *cls,
710 const struct sockaddr *addr,
716 return GNUNET_ATS_NET_UNSPECIFIED;
718 return GNUNET_ATS_scanner_address_get_type (is,
725 * Function that will be called to update metrics for an address
728 * @param address address to update metrics for
729 * @param session the session
730 * @param ats the ats information to update
731 * @param ats_count the number of @a ats elements
734 plugin_env_update_metrics (void *cls,
735 const struct GNUNET_HELLO_Address *address,
736 struct Session *session,
737 const struct GNUNET_ATS_Information *ats,
740 GST_ats_update_metrics (address,
747 * Black list check result from blacklist check triggered when a
748 * plugin gave us a new session in #plugin_env_session_start(). If
749 * connection to the peer is disallowed, kill the session.
751 * @param cls blc_ctx bl context
752 * @param peer the peer
753 * @param result the result
756 plugin_env_session_start_bl_check_cont (void *cls,
757 const struct GNUNET_PeerIdentity *peer,
760 struct BlacklistCheckContext *blctx = cls;
762 GNUNET_CONTAINER_DLL_remove (bc_head,
766 if (GNUNET_OK != result)
768 cancel_pending_blacklist_checks (blctx->address,
770 kill_session (blctx->address->transport_name,
773 else if (GNUNET_YES !=
774 GNUNET_HELLO_address_check_option (blctx->address,
775 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
778 "Informing verifier about inbound session's address `%s'\n",
779 GST_plugins_a2s (blctx->address));
780 GST_validation_handle_address (blctx->address);
782 GNUNET_HELLO_address_free (blctx->address);
788 * Plugin tells transport service about a new inbound session
791 * @param address the address
792 * @param session the new session
793 * @param ats ats information
794 * @param ats_count number of @a ats information
797 plugin_env_session_start (void *cls,
798 const struct GNUNET_HELLO_Address *address,
799 struct Session *session,
800 const struct GNUNET_ATS_Information *ats,
803 struct BlacklistCheckContext *blctx;
804 struct GST_BlacklistCheck *blc;
816 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
817 "Notification from plugin `%s' about new session %p from peer `%s' address `%s'\n",
818 address->transport_name,
820 GNUNET_i2s (&address->peer),
821 GST_plugins_a2s (address));
823 GNUNET_HELLO_address_check_option (address,
824 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
826 /* inbound is always new, but outbound MAY already be known, but
827 for example for UNIX, we have symmetric connections and thus we
828 may not know the address yet; add if necessary! */
829 GST_ats_add_inbound_address (address,
837 GST_ats_is_known (address,
840 GST_ats_update_metrics (address,
846 /* Do blacklist check if communication with this peer is allowed */
847 blctx = GNUNET_new (struct BlacklistCheckContext);
848 blctx->address = GNUNET_HELLO_address_copy (address);
849 blctx->session = session;
850 GNUNET_CONTAINER_DLL_insert (bc_head,
854 (blc = GST_blacklist_test_allowed (&address->peer,
855 address->transport_name,
856 &plugin_env_session_start_bl_check_cont,
865 * Function called by ATS to notify the callee that the
866 * assigned bandwidth or address for a given peer was changed. If the
867 * callback is called with address/bandwidth assignments of zero, the
868 * ATS disconnect function will still be called once the disconnect
872 * @param peer the peer this address is intended for
873 * @param address address to use (for peer given in address)
874 * @param session session to use (if available)
875 * @param bandwidth_out assigned outbound bandwidth for the connection in NBO,
876 * 0 to disconnect from peer
877 * @param bandwidth_in assigned inbound bandwidth for the connection in NBO,
878 * 0 to disconnect from peer
879 * @param ats ATS information
880 * @param ats_count number of @a ats elements
883 ats_request_address_change (void *cls,
884 const struct GNUNET_PeerIdentity *peer,
885 const struct GNUNET_HELLO_Address *address,
886 struct Session *session,
887 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
888 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
890 uint32_t bw_in = ntohl (bandwidth_in.value__);
891 uint32_t bw_out = ntohl (bandwidth_out.value__);
895 /* ATS service died, all suggestions become invalid!
896 (but we'll keep using the allocations for a little
897 while, to keep going while ATS restarts) */
898 /* FIXME: We should drop all
899 connections now, as ATS won't explicitly tell
900 us and be unaware of ongoing resource allocations! */
903 /* ATS tells me to disconnect from peer */
904 if ((0 == bw_in) && (0 == bw_out))
906 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
907 "ATS tells me to disconnect from peer `%s'\n",
909 GST_neighbours_force_disconnect (peer);
912 GNUNET_assert (NULL != address);
913 GNUNET_STATISTICS_update (GST_stats,
914 "# ATS suggestions received",
917 GST_neighbours_switch_to_address (address,
925 * Function called when the service shuts down. Unloads our plugins
926 * and cancels pending validations.
928 * @param cls closure, unused
929 * @param tc task context (unused)
932 shutdown_task (void *cls,
933 const struct GNUNET_SCHEDULER_TaskContext *tc)
935 GST_neighbours_stop ();
936 GST_plugins_unload ();
937 GST_validation_stop ();
939 GNUNET_ATS_scheduling_done (GST_ats);
941 GNUNET_ATS_connectivity_done (GST_ats_connect);
942 GST_ats_connect = NULL;
943 GNUNET_ATS_scanner_done (is);
946 GST_blacklist_stop ();
948 GST_manipulation_stop ();
950 if (NULL != GST_peerinfo)
952 GNUNET_PEERINFO_disconnect (GST_peerinfo);
955 if (NULL != GST_stats)
957 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
960 if (NULL != GST_my_private_key)
962 GNUNET_free(GST_my_private_key);
963 GST_my_private_key = NULL;
970 * Initiate transport service.
973 * @param server the initialized server
974 * @param c configuration to use
978 struct GNUNET_SERVER_Handle *server,
979 const struct GNUNET_CONFIGURATION_Handle *c)
982 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
983 long long unsigned int max_fd_cfg;
991 GNUNET_CONFIGURATION_get_value_filename (c,
996 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
997 _("Transport service is lacking key configuration settings. Exiting.\n"));
998 GNUNET_SCHEDULER_shutdown ();
1002 GNUNET_CONFIGURATION_get_value_time (c,
1007 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
1009 GST_server = server;
1010 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
1011 GNUNET_free (keyfile);
1012 GNUNET_assert (NULL != pk);
1013 GST_my_private_key = pk;
1015 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
1016 GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg);
1017 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key,
1018 &GST_my_identity.public_key);
1019 GNUNET_assert(NULL != GST_my_private_key);
1021 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1022 "My identity is `%4s'\n",
1023 GNUNET_i2s_full (&GST_my_identity));
1025 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1028 if (NULL == GST_peerinfo)
1030 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1031 _("Could not access PEERINFO service. Exiting.\n"));
1032 GNUNET_SCHEDULER_shutdown ();
1039 struct rlimit r_file;
1040 if (0 == getrlimit (RLIMIT_NOFILE, &r_file))
1042 max_fd_rlimit = r_file.rlim_cur;
1043 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1044 "Maximum number of open files was: %u/%u\n",
1048 max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */
1050 GNUNET_CONFIGURATION_get_value_number (GST_cfg,
1055 if (max_fd_cfg > max_fd_rlimit)
1056 max_fd = max_fd_cfg;
1058 max_fd = max_fd_rlimit;
1059 if (max_fd < DEFAULT_MAX_FDS)
1060 max_fd = DEFAULT_MAX_FDS;
1062 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1063 "Limiting number of sockets to %u: validation %u, neighbors: %u\n",
1064 max_fd, (max_fd / 3), (max_fd / 3) * 2);
1066 friend_only = GNUNET_CONFIGURATION_get_value_yesno (GST_cfg,
1069 if (GNUNET_SYSERR == friend_only)
1070 friend_only = GNUNET_NO; /* According to topology defaults */
1071 /* start subsystems */
1072 GST_hello_start (friend_only,
1073 &process_hello_update,
1075 GST_blacklist_start (GST_server,
1078 is = GNUNET_ATS_scanner_init ();
1079 GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg);
1080 GST_ats = GNUNET_ATS_scheduling_init (GST_cfg,
1081 &ats_request_address_change,
1084 GST_manipulation_init (GST_cfg);
1085 GST_plugins_load (&GST_manipulation_recv,
1086 &plugin_env_address_change_notification,
1087 &plugin_env_session_start,
1088 &plugin_env_session_end,
1089 &plugin_env_address_to_type,
1090 &plugin_env_update_metrics);
1091 GST_neighbours_start ((max_fd / 3) * 2);
1092 GST_clients_start (GST_server);
1093 GST_validation_start ((max_fd / 3));
1098 * The main function for the transport service.
1100 * @param argc number of arguments from the command line
1101 * @param argv command line arguments
1102 * @return 0 ok, 1 on error
1105 main (int argc, char * const *argv)
1109 == GNUNET_SERVICE_run (argc, argv, "transport",
1110 GNUNET_SERVICE_OPTION_NONE, &run, NULL )) ? 0 : 1;
1113 /* end of file gnunet-service-transport.c */