2 This file is part of GNUnet.
3 (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;
218 if (GNUNET_NO == GST_neighbours_test_connected (peer))
221 GST_neighbours_send (peer,
230 * My HELLO has changed. Tell everyone who should know.
233 * @param hello new HELLO
236 process_hello_update (void *cls,
237 const struct GNUNET_MessageHeader *hello)
239 GST_clients_broadcast (hello, GNUNET_NO);
240 GST_neighbours_iterate (&transmit_our_hello, (void *) hello);
245 * We received some payload. Prepare to pass it on to our clients.
247 * @param address address and (claimed) identity of the other peer
248 * @param session identifier used for this session (NULL for plugins
249 * that do not offer bi-directional communication to the sender
250 * using the same "connection")
251 * @param message the message to process
252 * @return how long the plugin should wait until receiving more data
254 static struct GNUNET_TIME_Relative
255 process_payload (const struct GNUNET_HELLO_Address *address,
256 struct Session *session,
257 const struct GNUNET_MessageHeader *message)
259 struct GNUNET_TIME_Relative ret;
261 struct InboundMessage *im;
262 size_t msg_size = ntohs (message->size);
263 size_t size = sizeof(struct InboundMessage) + msg_size;
264 char buf[size] GNUNET_ALIGN;
266 do_forward = GNUNET_SYSERR;
267 ret = GST_neighbours_calculate_receive_delay (&address->peer,
270 if (! GST_neighbours_test_connected (&address->peer))
272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
273 "Discarded %u bytes type %u payload from peer `%s'\n",
275 ntohs (message->type),
276 GNUNET_i2s (&address->peer));
277 GNUNET_STATISTICS_update (GST_stats, gettext_noop
278 ("# bytes payload discarded due to not connected peer"),
284 if (GNUNET_YES != do_forward)
286 im = (struct InboundMessage *) buf;
287 im->header.size = htons (size);
288 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
289 im->peer = address->peer;
290 memcpy (&im[1], message, ntohs (message->size));
291 GST_clients_broadcast (&im->header, GNUNET_YES);
297 * Task to asynchronously terminate a session.
299 * @param cls the `struct SessionKiller` with the information for the kill
300 * @param tc scheduler context
303 kill_session_task (void *cls,
304 const struct GNUNET_SCHEDULER_TaskContext *tc)
306 struct SessionKiller *sk = cls;
309 GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk);
310 sk->plugin->disconnect_session (sk->plugin->cls, sk->session);
316 * Cancel all blacklist checks that are pending for the given address and session.
317 * NOTE: Consider moving the "bc_*" logic into blacklist.h?
319 * @param address address to remove from check
320 * @param sesssion session that must match to remove for check
323 cancel_pending_blacklist_checks (const struct GNUNET_HELLO_Address *address,
324 struct Session *session)
326 struct BlacklistCheckContext *blctx;
327 struct BlacklistCheckContext *next;
330 for (blctx = next; NULL != blctx; blctx = next)
333 if ( (NULL != blctx->address) &&
334 (0 == GNUNET_HELLO_address_cmp(blctx->address, address)) &&
335 (blctx->session == session))
337 GNUNET_CONTAINER_DLL_remove (bc_head,
340 if (NULL != blctx->blc)
342 GST_blacklist_test_cancel (blctx->blc);
345 GNUNET_HELLO_address_free (blctx->address);
346 GNUNET_free_non_null (blctx->msg);
354 * Force plugin to terminate session due to communication
357 * @param plugin_name name of the plugin
358 * @param session session to termiante
361 kill_session (const char *plugin_name,
362 struct Session *session)
364 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
365 struct SessionKiller *sk;
367 for (sk = sk_head; NULL != sk; sk = sk->next)
368 if (sk->session == session)
370 plugin = GST_plugins_find (plugin_name);
376 /* need to issue disconnect asynchronously */
377 sk = GNUNET_new (struct SessionKiller);
378 sk->session = session;
380 sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task, sk);
381 GNUNET_CONTAINER_DLL_insert (sk_head,
388 * Black list check result for try_connect call
389 * If connection to the peer is allowed request adddress and ???
391 * @param cls blc_ctx bl context
392 * @param peer the peer
393 * @param result the result
396 connect_bl_check_cont (void *cls,
397 const struct GNUNET_PeerIdentity *peer,
400 struct BlacklistCheckContext *blctx = cls;
402 GNUNET_CONTAINER_DLL_remove (bc_head,
406 if (GNUNET_OK == result)
408 /* Blacklist allows to speak to this peer, forward SYN to neighbours */
409 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
410 "Received SYN message from peer `%s' at `%s'\n",
412 GST_plugins_a2s (blctx->address));
414 GST_neighbours_handle_session_syn (blctx->msg,
415 &blctx->address->peer))
417 cancel_pending_blacklist_checks (blctx->address,
419 kill_session (blctx->address->transport_name,
425 /* Blacklist denies to speak to this peer */
426 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
427 "Discarding SYN message from `%s' due to denied blacklist check\n",
429 cancel_pending_blacklist_checks (blctx->address,
431 kill_session (blctx->address->transport_name,
435 if (NULL != blctx->address)
436 GNUNET_HELLO_address_free (blctx->address);
437 GNUNET_free (blctx->msg);
443 * Function called by the transport for each received message.
445 * @param cls closure, const char* with the name of the plugin we received the message from
446 * @param address address and (claimed) identity of the other peer
447 * @param message the message, NULL if we only care about
448 * learning about the delay until we should receive again
449 * @param session identifier used for this session (NULL for plugins
450 * that do not offer bi-directional communication to the sender
451 * using the same "connection")
452 * @return how long the plugin should wait until receiving more data
453 * (plugins that do not support this, can ignore the return value)
455 struct GNUNET_TIME_Relative
456 GST_receive_callback (void *cls,
457 const struct GNUNET_HELLO_Address *address,
458 struct Session *session,
459 const struct GNUNET_MessageHeader *message)
461 const char *plugin_name = cls;
462 struct GNUNET_TIME_Relative ret;
463 struct BlacklistCheckContext *blctx;
464 struct GST_BlacklistCheck *blc;
467 ret = GNUNET_TIME_UNIT_ZERO;
470 type = ntohs (message->type);
471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
472 "Received message with type %u from peer `%s'\n",
474 GNUNET_i2s (&address->peer));
476 GNUNET_STATISTICS_update (GST_stats,
477 gettext_noop ("# bytes total received"),
478 ntohs (message->size),
480 GST_neighbours_notify_data_recv (address,
484 case GNUNET_MESSAGE_TYPE_HELLO_LEGACY:
485 /* Legacy HELLO message, discard */
487 case GNUNET_MESSAGE_TYPE_HELLO:
488 if (GNUNET_OK != GST_validation_handle_hello (message))
491 cancel_pending_blacklist_checks (address,
495 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
497 "Processing `%s' from `%s'\n", "PING",
498 GST_plugins_a2s (address));
500 GST_validation_handle_ping (&address->peer,
505 cancel_pending_blacklist_checks (address,
507 kill_session (plugin_name,
511 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
512 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
513 "Processing `%s' from `%s'\n", "PONG",
514 GST_plugins_a2s (address));
515 if (GNUNET_OK != GST_validation_handle_pong (&address->peer, message))
518 cancel_pending_blacklist_checks (address, session);
519 kill_session (plugin_name, session);
522 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN:
523 /* Do blacklist check if communication with this peer is allowed */
524 blctx = GNUNET_new (struct BlacklistCheckContext);
525 blctx->address = GNUNET_HELLO_address_copy (address);
526 blctx->session = session;
527 blctx->msg = GNUNET_malloc (ntohs(message->size));
530 ntohs (message->size));
531 GNUNET_CONTAINER_DLL_insert (bc_head,
535 (blc = GST_blacklist_test_allowed (&address->peer,
537 &connect_bl_check_cont,
543 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK:
545 GST_neighbours_handle_session_syn_ack (message,
549 cancel_pending_blacklist_checks (address, session);
550 kill_session (plugin_name, session);
553 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
555 GST_neighbours_handle_session_ack (message,
560 cancel_pending_blacklist_checks (address, session);
561 kill_session (plugin_name, session);
564 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
565 GST_neighbours_handle_disconnect_message (&address->peer, message);
567 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
568 GST_neighbours_keepalive (&address->peer, message);
570 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE:
571 GST_neighbours_keepalive_response (&address->peer, message);
574 /* should be payload */
575 GNUNET_STATISTICS_update (GST_stats,
576 gettext_noop ("# bytes payload received"),
577 ntohs (message->size),
579 GST_neighbours_notify_payload_recv (address,
581 ret = process_payload (address,
587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
588 "Allowing receive from peer %s to continue in %s\n",
589 GNUNET_i2s (&address->peer),
590 GNUNET_STRINGS_relative_time_to_string (ret,
597 * Function that will be called for each address the transport
598 * is aware that it might be reachable under. Update our HELLO.
600 * @param cls name of the plugin (const char*)
601 * @param add_remove should the address added (YES) or removed (NO) from the
602 * set of valid addresses?
603 * @param address the address to add or remove
606 plugin_env_address_change_notification (void *cls,
608 const struct GNUNET_HELLO_Address *address)
610 static int addresses = 0;
611 struct GNUNET_STATISTICS_Handle *cfg = GST_stats;
613 if (GNUNET_YES == add_remove)
616 GNUNET_STATISTICS_update (cfg, "# transport addresses", 1, GNUNET_NO);
618 else if (GNUNET_NO == add_remove)
625 GNUNET_STATISTICS_update (cfg, "# transport addresses", -1, GNUNET_NO);
629 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
630 "Transport now has %u addresses to communicate\n",
632 GST_hello_modify_addresses (add_remove, address);
637 * Function that will be called whenever the plugin internally
638 * cleans up a session pointer and hence the service needs to
639 * discard all of those sessions as well. Plugins that do not
640 * use sessions can simply omit calling this function and always
641 * use NULL wherever a session pointer is needed. This function
642 * should be called BEFORE a potential "TransmitContinuation"
643 * from the "TransmitFunction".
646 * @param address which address was the session for
647 * @param session which session is being destoyed
650 plugin_env_session_end (void *cls,
651 const struct GNUNET_HELLO_Address *address,
652 struct Session *session)
654 struct SessionKiller *sk;
666 GNUNET_assert (strlen (address->transport_name) > 0);
668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
669 "Notification from plugin about terminated session %p from peer `%s' address `%s'\n",
671 GNUNET_i2s (&address->peer),
672 GST_plugins_a2s (address));
674 GST_neighbours_session_terminated (&address->peer, session);
675 GST_ats_del_session (address, session);
676 cancel_pending_blacklist_checks (address, session);
678 for (sk = sk_head; NULL != sk; sk = sk->next)
680 if (sk->session == session)
682 GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk);
683 GNUNET_SCHEDULER_cancel (sk->task);
692 * Function that will be called to figure if an address is an loopback,
693 * LAN, WAN etc. address
696 * @param addr binary address
697 * @param addrlen length of the @a addr
698 * @return type of the network @a addr belongs to
700 static enum GNUNET_ATS_Network_Type
701 plugin_env_address_to_type (void *cls,
702 const struct sockaddr *addr,
708 return GNUNET_ATS_NET_UNSPECIFIED;
710 return GNUNET_ATS_scanner_address_get_type (is,
717 * Function that will be called to update metrics for an address
720 * @param address address to update metrics for
721 * @param session the session
722 * @param ats the ats information to update
723 * @param ats_count the number of @a ats elements
726 plugin_env_update_metrics (void *cls,
727 const struct GNUNET_HELLO_Address *address,
728 struct Session *session,
729 const struct GNUNET_ATS_Information *ats,
732 GST_ats_update_metrics (address,
739 * Black list check result from blacklist check triggered when a
740 * plugin gave us a new session in #plugin_env_session_start(). If
741 * connection to the peer is disallowed, kill the session.
743 * @param cls blc_ctx bl context
744 * @param peer the peer
745 * @param result the result
748 plugin_env_session_start_bl_check_cont (void *cls,
749 const struct GNUNET_PeerIdentity *peer,
752 struct BlacklistCheckContext *blctx = cls;
754 GNUNET_CONTAINER_DLL_remove (bc_head,
758 if (GNUNET_OK != result)
760 cancel_pending_blacklist_checks (blctx->address,
762 kill_session (blctx->address->transport_name,
765 else if (GNUNET_YES !=
766 GNUNET_HELLO_address_check_option (blctx->address,
767 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
769 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
770 "Informing verifier about inbound session's address `%s'\n",
771 GST_plugins_a2s (blctx->address));
772 GST_validation_handle_address (blctx->address);
774 GNUNET_HELLO_address_free (blctx->address);
780 * Plugin tells transport service about a new inbound session
783 * @param address the address
784 * @param session the new session
785 * @param ats ats information
786 * @param ats_count number of @a ats information
789 plugin_env_session_start (void *cls,
790 const struct GNUNET_HELLO_Address *address,
791 struct Session *session,
792 const struct GNUNET_ATS_Information *ats,
795 struct BlacklistCheckContext *blctx;
796 struct GST_BlacklistCheck *blc;
808 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
809 "Notification from plugin `%s' about new session %p from peer `%s' address `%s'\n",
810 address->transport_name,
812 GNUNET_i2s (&address->peer),
813 GST_plugins_a2s (address));
815 GNUNET_HELLO_address_check_option (address,
816 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
818 /* inbound is always new, but outbound MAY already be known, but
819 for example for UNIX, we have symmetric connections and thus we
820 may not know the address yet; add if necessary! */
821 GST_ats_add_inbound_address (address,
829 GST_ats_is_known (address,
832 GST_ats_update_metrics (address,
838 /* Do blacklist check if communication with this peer is allowed */
839 blctx = GNUNET_new (struct BlacklistCheckContext);
840 blctx->address = GNUNET_HELLO_address_copy (address);
841 blctx->session = session;
842 GNUNET_CONTAINER_DLL_insert (bc_head,
846 (blc = GST_blacklist_test_allowed (&address->peer,
847 address->transport_name,
848 &plugin_env_session_start_bl_check_cont,
857 * Function called by ATS to notify the callee that the
858 * assigned bandwidth or address for a given peer was changed. If the
859 * callback is called with address/bandwidth assignments of zero, the
860 * ATS disconnect function will still be called once the disconnect
864 * @param peer the peer this address is intended for
865 * @param address address to use (for peer given in address)
866 * @param session session to use (if available)
867 * @param bandwidth_out assigned outbound bandwidth for the connection in NBO,
868 * 0 to disconnect from peer
869 * @param bandwidth_in assigned inbound bandwidth for the connection in NBO,
870 * 0 to disconnect from peer
871 * @param ats ATS information
872 * @param ats_count number of @a ats elements
875 ats_request_address_change (void *cls,
876 const struct GNUNET_PeerIdentity *peer,
877 const struct GNUNET_HELLO_Address *address,
878 struct Session *session,
879 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
880 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
882 uint32_t bw_in = ntohl (bandwidth_in.value__);
883 uint32_t bw_out = ntohl (bandwidth_out.value__);
887 /* ATS service died, all suggestions become invalid!
888 (but we'll keep using the allocations for a little
889 while, to keep going while ATS restarts) */
890 // FIXME: do something?
893 /* ATS tells me to disconnect from peer */
894 if ((0 == bw_in) && (0 == bw_out))
896 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
897 "ATS tells me to disconnect from peer `%s'\n",
899 GST_neighbours_force_disconnect (peer);
902 GNUNET_assert (NULL != address);
903 GNUNET_STATISTICS_update (GST_stats,
904 "# ATS suggestions received",
907 GST_neighbours_switch_to_address (address,
915 * Function called when the service shuts down. Unloads our plugins
916 * and cancels pending validations.
918 * @param cls closure, unused
919 * @param tc task context (unused)
922 shutdown_task (void *cls,
923 const struct GNUNET_SCHEDULER_TaskContext *tc)
925 GST_neighbours_stop ();
926 GST_plugins_unload ();
927 GST_validation_stop ();
929 GNUNET_ATS_scheduling_done (GST_ats);
931 GNUNET_ATS_connectivity_done (GST_ats_connect);
932 GST_ats_connect = NULL;
933 GNUNET_ATS_scanner_done (is);
936 GST_blacklist_stop ();
938 GST_manipulation_stop ();
940 if (NULL != GST_peerinfo)
942 GNUNET_PEERINFO_disconnect (GST_peerinfo);
945 if (NULL != GST_stats)
947 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
950 if (NULL != GST_my_private_key)
952 GNUNET_free(GST_my_private_key);
953 GST_my_private_key = NULL;
960 * Initiate transport service.
963 * @param server the initialized server
964 * @param c configuration to use
968 struct GNUNET_SERVER_Handle *server,
969 const struct GNUNET_CONFIGURATION_Handle *c)
972 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
973 long long unsigned int max_fd_cfg;
981 GNUNET_CONFIGURATION_get_value_filename (c,
986 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
987 _("Transport service is lacking key configuration settings. Exiting.\n"));
988 GNUNET_SCHEDULER_shutdown ();
992 GNUNET_CONFIGURATION_get_value_time (c,
997 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
1000 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
1001 GNUNET_free (keyfile);
1002 GNUNET_assert (NULL != pk);
1003 GST_my_private_key = pk;
1005 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
1006 GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg);
1007 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key,
1008 &GST_my_identity.public_key);
1009 GNUNET_assert(NULL != GST_my_private_key);
1011 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1012 "My identity is `%4s'\n",
1013 GNUNET_i2s_full (&GST_my_identity));
1015 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1018 if (NULL == GST_peerinfo)
1020 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1021 _("Could not access PEERINFO service. Exiting.\n"));
1022 GNUNET_SCHEDULER_shutdown ();
1029 struct rlimit r_file;
1030 if (0 == getrlimit (RLIMIT_NOFILE, &r_file))
1032 max_fd_rlimit = r_file.rlim_cur;
1033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1034 "Maximum number of open files was: %u/%u\n",
1038 max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */
1040 GNUNET_CONFIGURATION_get_value_number (GST_cfg,
1045 if (max_fd_cfg > max_fd_rlimit)
1046 max_fd = max_fd_cfg;
1048 max_fd = max_fd_rlimit;
1049 if (max_fd < DEFAULT_MAX_FDS)
1050 max_fd = DEFAULT_MAX_FDS;
1052 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1053 "Limiting number of sockets to %u: validation %u, neighbors: %u\n",
1054 max_fd, (max_fd / 3), (max_fd / 3) * 2);
1056 friend_only = GNUNET_CONFIGURATION_get_value_yesno (GST_cfg, "topology",
1058 if (GNUNET_SYSERR == friend_only)
1059 friend_only = GNUNET_NO; /* According to topology defaults */
1060 /* start subsystems */
1061 GST_hello_start (friend_only, &process_hello_update, NULL );
1062 GNUNET_assert(NULL != GST_hello_get());
1063 GST_blacklist_start (GST_server, GST_cfg, &GST_my_identity);
1064 is = GNUNET_ATS_scanner_init ();
1065 GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg);
1066 GST_ats = GNUNET_ATS_scheduling_init (GST_cfg,
1067 &ats_request_address_change,
1070 GST_manipulation_init (GST_cfg);
1071 GST_plugins_load (&GST_manipulation_recv,
1072 &plugin_env_address_change_notification,
1073 &plugin_env_session_start,
1074 &plugin_env_session_end,
1075 &plugin_env_address_to_type,
1076 &plugin_env_update_metrics);
1077 GST_neighbours_start ((max_fd / 3) * 2);
1078 GST_clients_start (GST_server);
1079 GST_validation_start ((max_fd / 3));
1084 * The main function for the transport service.
1086 * @param argc number of arguments from the command line
1087 * @param argv command line arguments
1088 * @return 0 ok, 1 on error
1091 main (int argc, char * const *argv)
1095 == GNUNET_SERVICE_run (argc, argv, "transport",
1096 GNUNET_SERVICE_OPTION_NONE, &run, NULL )) ? 0 : 1;
1099 /* end of file gnunet-service-transport.c */