2 This file is part of GNUnet.
3 (C) 2010,2011 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.
22 * @file transport/gnunet-service-transport.c
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_hello_lib.h"
29 #include "gnunet_statistics_service.h"
30 #include "gnunet_transport_service.h"
31 #include "gnunet_peerinfo_service.h"
32 #include "gnunet_ats_service.h"
33 #include "gnunet-service-transport.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"
48 struct GNUNET_STATISTICS_Handle *GST_stats;
51 * Configuration handle.
53 const struct GNUNET_CONFIGURATION_Handle *GST_cfg;
56 * Configuration handle.
58 struct GNUNET_PeerIdentity GST_my_identity;
61 * Handle to peerinfo service.
63 struct GNUNET_PEERINFO_Handle *GST_peerinfo;
66 * Handle to our service's server.
68 static struct GNUNET_SERVER_Handle *GST_server;
73 struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key;
78 struct GNUNET_ATS_SchedulingHandle *GST_ats;
81 * DEBUGGING connection counter
83 static int connections;
86 * Hello address expiration
88 struct GNUNET_TIME_Relative hello_expiration;
92 * Transmit our HELLO message to the given (connected) neighbour.
94 * @param cls the 'HELLO' message
95 * @param target a connected neighbour
96 * @param address the address
97 * @param bandwidth_in inbound quota in NBO
98 * @param bandwidth_out outbound quota in NBO
101 transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target,
102 const struct GNUNET_HELLO_Address *address,
103 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
104 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
106 const struct GNUNET_MessageHeader *hello = cls;
108 GST_neighbours_send (target, (const char *) hello, ntohs (hello->size),
109 hello_expiration, NULL, NULL);
114 * My HELLO has changed. Tell everyone who should know.
117 * @param hello new HELLO
120 process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello)
122 GST_clients_broadcast (hello, GNUNET_NO);
123 GST_neighbours_iterate (&transmit_our_hello, (void *) hello);
128 * We received some payload. Prepare to pass it on to our clients.
130 * @param peer (claimed) identity of the other peer
131 * @param address the address
132 * @param session session used
133 * @param message the message to process
134 * @return how long the plugin should wait until receiving more data
136 static struct GNUNET_TIME_Relative
137 process_payload (const struct GNUNET_PeerIdentity *peer,
138 const struct GNUNET_HELLO_Address *address,
139 struct Session *session,
140 const struct GNUNET_MessageHeader *message)
142 struct GNUNET_TIME_Relative ret;
144 struct InboundMessage *im;
145 size_t msg_size = ntohs (message->size);
147 sizeof (struct InboundMessage) + msg_size;
148 char buf[size] GNUNET_ALIGN;
150 do_forward = GNUNET_SYSERR;
151 ret = GST_neighbours_calculate_receive_delay (peer, msg_size, &do_forward);
152 if (! GST_neighbours_test_connected (peer))
154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
155 "Discarded %u bytes type %u payload from peer `%s'\n",
157 ntohs (message->type), GNUNET_i2s (peer));
158 GNUNET_STATISTICS_update (GST_stats,
160 ("# bytes payload discarded due to not connected peer"),
161 msg_size, GNUNET_NO);
165 GST_ats_add_address ((struct GNUNET_HELLO_Address *) address, session);
167 if (GNUNET_YES != do_forward)
169 im = (struct InboundMessage *) buf;
170 im->header.size = htons (size);
171 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
173 memcpy (&im[1], message, ntohs (message->size));
174 GST_clients_broadcast (&im->header, GNUNET_YES);
180 * Force plugin to terminate session due to communication
183 * @param plugin_name name of the plugin
184 * @param session session to termiante
187 kill_session (const char *plugin_name,
188 struct Session *session)
190 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
192 plugin = GST_plugins_find (plugin_name);
198 plugin->disconnect_session (plugin->cls,
204 * Function called by the transport for each received message.
206 * @param cls closure, const char* with the name of the plugin we received the message from
207 * @param peer (claimed) identity of the other peer
208 * @param message the message, NULL if we only care about
209 * learning about the delay until we should receive again
210 * @param session identifier used for this session (NULL for plugins
211 * that do not offer bi-directional communication to the sender
212 * using the same "connection")
213 * @param sender_address binary address of the sender (if we established the
214 * connection or are otherwise sure of it; should be NULL
215 * for inbound TCP/UDP connections since it it not clear
216 * that we could establish ourselves a connection to that
217 * IP address and get the same system)
218 * @param sender_address_len number of bytes in @a sender_address
219 * @return how long the plugin should wait until receiving more data
220 * (plugins that do not support this, can ignore the return value)
222 struct GNUNET_TIME_Relative
223 GST_receive_callback (void *cls,
224 const struct GNUNET_PeerIdentity *peer,
225 const struct GNUNET_MessageHeader *message,
226 struct Session *session,
227 const char *sender_address,
228 uint16_t sender_address_len)
230 const char *plugin_name = cls;
231 struct GNUNET_TIME_Relative ret;
232 struct GNUNET_HELLO_Address address;
235 address.peer = *peer;
236 address.address = sender_address;
237 address.address_length = sender_address_len;
238 address.transport_name = plugin_name;
239 ret = GNUNET_TIME_UNIT_ZERO;
242 type = ntohs (message->type);
243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
244 "Received Message with type %u from peer `%s'\n",
248 GNUNET_STATISTICS_update (GST_stats,
250 ("# bytes total received"),
251 ntohs (message->size), GNUNET_NO);
252 GST_neighbours_notify_data_recv (peer, &address, session, message);
256 case GNUNET_MESSAGE_TYPE_HELLO_LEGACY:
257 /* Legacy HELLO message, discard */
259 case GNUNET_MESSAGE_TYPE_HELLO:
261 GST_validation_handle_hello (message))
264 kill_session (plugin_name, session);
267 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
269 "Processing `%s' from `%s'\n", "PING",
271 NULL) ? GST_plugins_a2s (&address) : TRANSPORT_SESSION_INBOUND_STRING);
273 GST_validation_handle_ping (peer, message, &address, session))
274 kill_session (plugin_name, session);
276 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
278 "Processing `%s' from `%s'\n", "PONG",
280 NULL) ? GST_plugins_a2s (&address) : TRANSPORT_SESSION_INBOUND_STRING);
282 GST_validation_handle_pong (peer, message))
285 kill_session (plugin_name, session);
288 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT:
290 GST_neighbours_handle_connect (message, peer, &address, session))
293 kill_session (plugin_name, session);
296 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK:
298 GST_neighbours_handle_connect_ack (message, peer, &address, session))
301 kill_session (plugin_name, session);
304 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
306 GST_neighbours_handle_session_ack (message, peer, &address, session))
309 kill_session (plugin_name, session);
312 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
313 GST_neighbours_handle_disconnect_message (peer, message);
315 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
316 GST_neighbours_keepalive (peer);
318 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE:
319 GST_neighbours_keepalive_response (peer);
322 /* should be payload */
323 GNUNET_STATISTICS_update (GST_stats,
325 ("# bytes payload received"),
326 ntohs (message->size), GNUNET_NO);
327 GST_neighbours_notify_payload_recv (peer, &address, session, message);
328 ret = process_payload (peer, &address, session, message);
332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
333 "Allowing receive from peer %s to continue in %s\n",
335 GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
341 * Function that will be called for each address the transport
342 * is aware that it might be reachable under. Update our HELLO.
344 * @param cls name of the plugin (const char*)
345 * @param add_remove should the address added (YES) or removed (NO) from the
346 * set of valid addresses?
347 * @param addr one of the addresses of the host
348 * the specific address format depends on the transport
349 * @param addrlen length of the @a addr
350 * @param dest_plugin destination plugin to use this address with
353 plugin_env_address_change_notification (void *cls, int add_remove,
354 const void *addr, size_t addrlen,
355 const char *dest_plugin)
357 struct GNUNET_HELLO_Address address;
359 address.peer = GST_my_identity;
360 address.transport_name = dest_plugin;
361 address.address = addr;
362 address.address_length = addrlen;
363 GST_hello_modify_addresses (add_remove, &address);
368 * Function that will be called whenever the plugin internally
369 * cleans up a session pointer and hence the service needs to
370 * discard all of those sessions as well. Plugins that do not
371 * use sessions can simply omit calling this function and always
372 * use NULL wherever a session pointer is needed. This function
373 * should be called BEFORE a potential "TransmitContinuation"
374 * from the "TransmitFunction".
377 * @param peer which peer was the session for
378 * @param session which session is being destoyed
381 plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
382 struct Session *session)
384 const char *transport_name = cls;
385 struct GNUNET_HELLO_Address address;
387 GNUNET_assert (strlen (transport_name) > 0);
388 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %p to peer `%s' ended \n",
389 session, GNUNET_i2s (peer));
391 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
393 "Telling ATS to destroy session %p from peer %s\n",
394 session, GNUNET_i2s (peer));
395 address.peer = *peer;
396 address.address = NULL;
397 address.address_length = 0;
398 address.transport_name = transport_name;
399 GST_neighbours_session_terminated (peer, session);
401 /* Tell ATS that session has ended */
402 GNUNET_ATS_address_destroyed (GST_ats, &address, session);
407 * Function that will be called to figure if an address is an loopback,
408 * LAN, WAN etc. address
411 * @param addr binary address
412 * @param addrlen length of the address
413 * @return ATS Information containing the network type
415 static struct GNUNET_ATS_Information
416 plugin_env_address_to_type (void *cls,
417 const struct sockaddr *addr,
420 struct GNUNET_ATS_Information ats;
422 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
423 ats.value = htonl (GNUNET_ATS_NET_UNSPECIFIED);
429 if (((addr->sa_family != AF_INET) && (addrlen != sizeof (struct sockaddr_in))) &&
430 ((addr->sa_family != AF_INET6) && (addrlen != sizeof (struct sockaddr_in6))) &&
431 (addr->sa_family != AF_UNIX))
433 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
434 "Malformed address with length %u `%s'\n",
436 GNUNET_a2s (addr, addrlen));
440 return GNUNET_ATS_address_get_type (GST_ats, addr, addrlen);
445 * Notify ATS about the new address including the network this address is
448 * @param address the address
449 * @param session the session
452 GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
453 struct Session *session)
455 struct GNUNET_TRANSPORT_PluginFunctions *papi;
456 struct GNUNET_ATS_Information ats;
459 /* valid new address, let ATS know! */
460 if (NULL == address->transport_name)
465 if (NULL == (papi = GST_plugins_find (address->transport_name)))
467 /* we don't have the plugin for this address */
472 if (GNUNET_YES == GNUNET_ATS_session_known (GST_ats, address, session))
475 net = papi->get_network (NULL, (void *) session);
476 if (GNUNET_ATS_NET_UNSPECIFIED != net)
478 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
479 _("Could not obtain a valid network for `%s' %s (%s)\n"),
480 GNUNET_i2s (&address->peer),
481 GST_plugins_a2s (address),
482 address->transport_name);
485 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
486 ats.value = htonl(net);
487 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
488 "Notifying ATS about peer `%s''s new address `%s' session %p in network %s\n",
489 GNUNET_i2s (&address->peer),
490 (0 == address->address_length) ? "<inbound>" : GST_plugins_a2s (address),
492 GNUNET_ATS_print_network_type(net));
493 GNUNET_ATS_address_add (GST_ats,
494 address, session, &ats, 1);
499 * Notify ATS about property changes to an address
501 * @param peer the peer
502 * @param address the address
503 * @param session the session
504 * @param ats performance information
505 * @param ats_count number of elements in @a ats
508 GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer,
509 const struct GNUNET_HELLO_Address *address,
510 struct Session *session,
511 const struct GNUNET_ATS_Information *ats,
514 struct GNUNET_ATS_Information *ats_new;
516 if (GNUNET_NO == GNUNET_ATS_session_known (GST_ats, address, session))
519 /* Call to manipulation to manipulate ATS information */
520 ats_new = GST_manipulation_manipulate_metrics (peer, address, session, ats,
527 if (GNUNET_NO == GNUNET_ATS_address_update (GST_ats,
528 address, session, ats_new, ats_count))
530 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
531 _("Address or session unknown: failed to update properties for peer `%s' plugin `%s' address `%s' session %p\n"),
533 address->transport_name,
534 GST_plugins_a2s (address),
537 GNUNET_free (ats_new);
542 * Function that will be called to figure if an address is an loopback,
543 * LAN, WAN etc. address
546 * @param peer the peer
547 * @param address binary address
548 * @param address_len length of the @a address
549 * @param session the session
550 * @param ats the ats information to update
551 * @param ats_count the number of @a ats elements
554 plugin_env_update_metrics (void *cls,
555 const struct GNUNET_PeerIdentity *peer,
557 uint16_t address_len,
558 struct Session *session,
559 const struct GNUNET_ATS_Information *ats,
562 const char *plugin_name = cls;
563 struct GNUNET_HELLO_Address haddress;
565 if ((NULL == ats) || (0 == ats_count))
567 GNUNET_assert (NULL != GST_ats);
569 haddress.peer = *peer;
570 haddress.address = address;
571 haddress.address_length = address_len;
572 haddress.transport_name = plugin_name;
574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
575 "Updating metrics for peer `%s' address %s session %p\n",
577 GST_plugins_a2s (&haddress),
579 GST_ats_update_metrics (peer, &haddress, session, ats, ats_count);
584 * Plugin tells transport service about a new (inbound) session
587 * @param peer the peer
588 * @param plugin plugin name
589 * @param address address
590 * @param address_len @a address length
591 * @param session the new session
592 * @param ats ats information
593 * @param ats_count number of @a ats information
596 plugin_env_session_start (void *cls,
597 const struct GNUNET_PeerIdentity *peer,
599 const void *address, uint16_t address_len,
600 struct Session *session,
601 const struct GNUNET_ATS_Information *ats,
604 struct GNUNET_HELLO_Address *addr;
622 addr = GNUNET_HELLO_address_allocate (peer, plugin, address, address_len);
623 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
624 "Notification from plugin `%s' about new session %p from peer `%s' address `%s'\n",
628 GST_plugins_a2s (addr));
629 GST_ats_add_address (addr, session);
632 GST_ats_update_metrics (peer, addr, session, ats, ats_count);
638 * Function called by ATS to notify the callee that the
639 * assigned bandwidth or address for a given peer was changed. If the
640 * callback is called with address/bandwidth assignments of zero, the
641 * ATS disconnect function will still be called once the disconnect
645 * @param address address to use (for peer given in address)
646 * @param session session to use (if available)
647 * @param bandwidth_out assigned outbound bandwidth for the connection in NBO,
648 * 0 to disconnect from peer
649 * @param bandwidth_in assigned inbound bandwidth for the connection in NBO,
650 * 0 to disconnect from peer
651 * @param ats ATS information
652 * @param ats_count number of @a ats elements
655 ats_request_address_change (void *cls,
656 const struct GNUNET_HELLO_Address *address,
657 struct Session *session,
658 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
659 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
660 const struct GNUNET_ATS_Information *ats,
663 uint32_t bw_in = ntohl (bandwidth_in.value__);
664 uint32_t bw_out = ntohl (bandwidth_out.value__);
666 /* ATS tells me to disconnect from peer */
667 if ((bw_in == 0) && (bw_out == 0))
669 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
670 "ATS tells me to disconnect from peer `%s'\n",
671 GNUNET_i2s (&address->peer));
672 GST_neighbours_force_disconnect (&address->peer);
675 GST_neighbours_switch_to_address (&address->peer, address, session, ats,
676 ats_count, bandwidth_in,
682 * Function called to notify transport users that another
683 * peer connected to us.
686 * @param peer the peer that connected
687 * @param bandwidth_in inbound bandwidth in NBO
688 * @param bandwidth_out outbound bandwidth in NBO
691 neighbours_connect_notification (void *cls,
692 const struct GNUNET_PeerIdentity *peer,
693 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
694 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
696 size_t len = sizeof (struct ConnectInfoMessage);
697 char buf[len] GNUNET_ALIGN;
698 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf;
701 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
702 "We are now connected to peer `%s' and %u peers in total\n",
703 GNUNET_i2s (peer), connections);
704 connect_msg->header.size = htons (sizeof (buf));
705 connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
706 connect_msg->id = *peer;
707 connect_msg->quota_in = bandwidth_in;
708 connect_msg->quota_out = bandwidth_out;
709 GST_clients_broadcast (&connect_msg->header, GNUNET_NO);
714 * Function called to notify transport users that another
715 * peer disconnected from us.
718 * @param peer the peer that disconnected
721 neighbours_disconnect_notification (void *cls,
722 const struct GNUNET_PeerIdentity *peer)
724 struct DisconnectInfoMessage disconnect_msg;
727 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
728 "Peer `%s' disconnected and we are connected to %u peers\n",
729 GNUNET_i2s (peer), connections);
731 GST_manipulation_peer_disconnect (peer);
732 disconnect_msg.header.size = htons (sizeof (struct DisconnectInfoMessage));
733 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
734 disconnect_msg.reserved = htonl (0);
735 disconnect_msg.peer = *peer;
736 GST_clients_broadcast (&disconnect_msg.header, GNUNET_NO);
741 * Function called to notify transport users that a neighbour peer changed its
745 * @param peer peer this update is about (never NULL)
746 * @param address address, NULL on disconnect
749 neighbours_address_notification (void *cls,
750 const struct GNUNET_PeerIdentity *peer,
751 const struct GNUNET_HELLO_Address *address)
753 GST_clients_broadcast_address_notification (peer, address);
758 * Function called when the service shuts down. Unloads our plugins
759 * and cancels pending validations.
761 * @param cls closure, unused
762 * @param tc task context (unused)
765 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
767 GST_neighbours_stop ();
768 GST_validation_stop ();
769 GST_plugins_unload ();
771 GNUNET_ATS_scheduling_done (GST_ats);
774 GST_blacklist_stop ();
776 GST_manipulation_stop ();
778 if (NULL != GST_peerinfo)
780 GNUNET_PEERINFO_disconnect (GST_peerinfo);
783 if (NULL != GST_stats)
785 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
788 if (NULL != GST_my_private_key)
790 GNUNET_free (GST_my_private_key);
791 GST_my_private_key = NULL;
798 * Initiate transport service.
801 * @param server the initialized server
802 * @param c configuration to use
805 run (void *cls, struct GNUNET_SERVER_Handle *server,
806 const struct GNUNET_CONFIGURATION_Handle *c)
809 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
810 long long unsigned int max_fd_cfg;
818 GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY",
821 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
822 _("Transport service is lacking key configuration settings. Exiting.\n"));
823 GNUNET_SCHEDULER_shutdown ();
827 GNUNET_CONFIGURATION_get_value_time (c, "transport", "HELLO_EXPIRATION",
830 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
833 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
834 GNUNET_free (keyfile);
835 GNUNET_assert (NULL != pk);
836 GST_my_private_key = pk;
838 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
839 GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg);
840 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key,
841 &GST_my_identity.public_key);
842 GNUNET_assert (NULL != GST_my_private_key);
844 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
845 "My identity is `%4s'\n", GNUNET_i2s (&GST_my_identity));
847 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
849 if (NULL == GST_peerinfo)
851 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
852 _("Could not access PEERINFO service. Exiting.\n"));
853 GNUNET_SCHEDULER_shutdown ();
860 struct rlimit r_file;
861 if (0 == getrlimit (RLIMIT_NOFILE, &r_file))
863 max_fd_rlimit = r_file.rlim_cur;
864 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
865 "Maximum number of open files was: %u/%u\n",
869 max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */
871 GNUNET_CONFIGURATION_get_value_number (GST_cfg, "transport", "MAX_FD", &max_fd_cfg);
873 if (max_fd_cfg > max_fd_rlimit)
876 max_fd = max_fd_rlimit;
877 if (max_fd < DEFAULT_MAX_FDS)
878 max_fd = DEFAULT_MAX_FDS;
880 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
881 "Limiting number of sockets to %u: validation %u, neighbors: %u\n",
882 max_fd, (max_fd / 3) , (max_fd / 3) * 2);
884 friend_only = GNUNET_CONFIGURATION_get_value_yesno(GST_cfg, "topology","FRIENDS-ONLY");
885 if (GNUNET_SYSERR == friend_only)
886 friend_only = GNUNET_NO; /* According to topology defaults */
887 /* start subsystems */
888 GST_hello_start (friend_only, &process_hello_update, NULL);
889 GNUNET_assert (NULL != GST_hello_get());
890 GST_blacklist_start (GST_server, GST_cfg, &GST_my_identity);
892 GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL);
893 GST_manipulation_init (GST_cfg);
894 GST_plugins_load (&GST_manipulation_recv,
895 &plugin_env_address_change_notification,
896 &plugin_env_session_start,
897 &plugin_env_session_end,
898 &plugin_env_address_to_type,
899 &plugin_env_update_metrics);
900 GST_neighbours_start (NULL,
901 &neighbours_connect_notification,
902 &neighbours_disconnect_notification,
903 &neighbours_address_notification,
905 GST_clients_start (GST_server);
906 GST_validation_start ((max_fd / 3));
911 * The main function for the transport service.
913 * @param argc number of arguments from the command line
914 * @param argv command line arguments
915 * @return 0 ok, 1 on error
918 main (int argc, char *const *argv)
921 GNUNET_SERVICE_run (argc, argv, "transport",
922 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
925 /* end of file gnunet-service-transport.c */