aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-02 23:16:13 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-02 23:16:13 +0000
commit8727c5c69097aeb474ce6039bf31650400b6286a (patch)
tree7159a82133c6d5d411a02a513aa247df7031a263 /src/transport/gnunet-service-transport.c
parentfee260b50973a0e26eaa10a5736a3e16ee6201ae (diff)
downloadgnunet-8727c5c69097aeb474ce6039bf31650400b6286a.tar.gz
gnunet-8727c5c69097aeb474ce6039bf31650400b6286a.zip
reduce callback insanity for callbacks that are always bound to only one value
Diffstat (limited to 'src/transport/gnunet-service-transport.c')
-rw-r--r--src/transport/gnunet-service-transport.c109
1 files changed, 2 insertions, 107 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index ca0f6b813..cd6bd9dff 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors) 3 (C) 2010-2015 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -132,11 +132,6 @@ struct GNUNET_ATS_SchedulingHandle *GST_ats;
132struct GNUNET_TIME_Relative hello_expiration; 132struct GNUNET_TIME_Relative hello_expiration;
133 133
134/** 134/**
135 * DEBUGGING connection counter
136 */
137static int connections;
138
139/**
140 * Head of DLL of asynchronous tasks to kill sessions. 135 * Head of DLL of asynchronous tasks to kill sessions.
141 */ 136 */
142static struct SessionKiller *sk_head; 137static struct SessionKiller *sk_head;
@@ -845,102 +840,6 @@ ats_request_address_change (void *cls,
845 840
846 841
847/** 842/**
848 * Function called to notify transport users that another
849 * peer connected to us.
850 *
851 * @param cls closure
852 * @param peer the peer that connected
853 * @param bandwidth_in inbound bandwidth in NBO
854 * @param bandwidth_out outbound bandwidth in NBO
855 */
856static void
857neighbours_connect_notification (void *cls,
858 const struct GNUNET_PeerIdentity *peer,
859 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
860 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
861{
862 size_t len = sizeof(struct ConnectInfoMessage);
863 char buf[len] GNUNET_ALIGN;
864 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf;
865
866 connections++;
867 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
868 "We are now connected to peer `%s' and %u peers in total\n",
869 GNUNET_i2s (peer),
870 connections);
871 connect_msg->header.size = htons (sizeof(buf));
872 connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
873 connect_msg->id = *peer;
874 connect_msg->quota_in = bandwidth_in;
875 connect_msg->quota_out = bandwidth_out;
876 GST_clients_broadcast (&connect_msg->header, GNUNET_NO);
877}
878
879
880/**
881 * Function called to notify transport users that another
882 * peer disconnected from us.
883 *
884 * @param cls closure
885 * @param peer the peer that disconnected
886 */
887static void
888neighbours_disconnect_notification (void *cls,
889 const struct GNUNET_PeerIdentity *peer)
890{
891 struct DisconnectInfoMessage disconnect_msg;
892
893 connections--;
894 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
895 "Peer `%s' disconnected and we are connected to %u peers\n",
896 GNUNET_i2s (peer),
897 connections);
898
899 GST_manipulation_peer_disconnect (peer);
900 disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage));
901 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
902 disconnect_msg.reserved = htonl (0);
903 disconnect_msg.peer = *peer;
904 GST_clients_broadcast (&disconnect_msg.header, GNUNET_NO);
905}
906
907
908/**
909 * Function called to notify transport users that a neighbour peer changed its
910 * active address.
911 *
912 * @param cls closure
913 * @param peer identity of the peer
914 * @param address address possibly NULL if peer is not connected
915 * @param state current state this peer is in
916 * @param state_timeout timeout for the current state of the peer
917 * @param bandwidth_in bandwidth assigned inbound, 0 on disconnect
918 * @param bandwidth_out bandwidth assigned outbound, 0 on disconnect
919 */
920static void
921neighbours_changed_notification (void *cls,
922 const struct GNUNET_PeerIdentity *peer,
923 const struct GNUNET_HELLO_Address *address,
924 enum GNUNET_TRANSPORT_PeerState state,
925 struct GNUNET_TIME_Absolute state_timeout,
926 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
927 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
928{
929 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
930 "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n",
931 GNUNET_i2s (peer),
932 GST_plugins_a2s (address),
933 GNUNET_TRANSPORT_ps2s (state),
934 GNUNET_STRINGS_absolute_time_to_string (state_timeout));
935 /* FIXME: include bandwidth in notification! */
936 GST_clients_broadcast_peer_notification (peer,
937 address,
938 state,
939 state_timeout);
940}
941
942
943/**
944 * Function called when the service shuts down. Unloads our plugins 843 * Function called when the service shuts down. Unloads our plugins
945 * and cancels pending validations. 844 * and cancels pending validations.
946 * 845 *
@@ -1097,11 +996,7 @@ run (void *cls,
1097 &plugin_env_session_end, 996 &plugin_env_session_end,
1098 &plugin_env_address_to_type, 997 &plugin_env_address_to_type,
1099 &plugin_env_update_metrics); 998 &plugin_env_update_metrics);
1100 GST_neighbours_start (NULL, 999 GST_neighbours_start ((max_fd / 3) * 2);
1101 &neighbours_connect_notification,
1102 &neighbours_disconnect_notification,
1103 &neighbours_changed_notification,
1104 (max_fd / 3) * 2);
1105 GST_clients_start (GST_server); 1000 GST_clients_start (GST_server);
1106 GST_validation_start ((max_fd / 3)); 1001 GST_validation_start ((max_fd / 3));
1107} 1002}