aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-02 23:31:25 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-02 23:31:25 +0000
commitf2d1198d45bc3786d0164a5b6df928768022d1b7 (patch)
treebcce1d8e39bbcddda171c3637bf418f4fbd41824
parent8727c5c69097aeb474ce6039bf31650400b6286a (diff)
downloadgnunet-f2d1198d45bc3786d0164a5b6df928768022d1b7.tar.gz
gnunet-f2d1198d45bc3786d0164a5b6df928768022d1b7.zip
dramatically simplify quota notification: avoid registration, simply always notify plugin
-rw-r--r--src/include/gnunet_transport_plugin.h42
-rw-r--r--src/transport/gnunet-service-transport.c2
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c199
-rw-r--r--src/transport/gnunet-service-transport_neighbours.h21
-rw-r--r--src/transport/gnunet-service-transport_plugins.c8
-rw-r--r--src/transport/gnunet-service-transport_plugins.h2
-rw-r--r--src/transport/plugin_transport_tcp.c8
-rw-r--r--src/transport/test_transport_api_monitor_peers.c2
8 files changed, 28 insertions, 256 deletions
diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h
index 8ebb3a92b..0e75cb454 100644
--- a/src/include/gnunet_transport_plugin.h
+++ b/src/include/gnunet_transport_plugin.h
@@ -193,38 +193,6 @@ typedef struct GNUNET_TIME_Relative
193 193
194 194
195/** 195/**
196 * Function to be called by the plugin to be notified about changes to the quota
197 * for a specific peer, plugin and session
198 *
199 * @param cls closure
200 * @param peer the peer to be notified about
201 * @param plugin the plugin to be notified about
202 * @param session the session for include in the notification
203 *
204 */
205typedef void
206(*GNUNET_TRANSPORT_RegisterQuotaNotification) (void *cls,
207 const struct GNUNET_PeerIdentity *peer,
208 const char *plugin,
209 struct Session *session);
210
211
212/**
213 * Function to be called by the plugin to stop notification about changes to the quota
214 * for a specific peer, plugin and session
215 *
216 * @param cls closure
217 * @param peer the peer to be notified about
218 * @param plugin the plugin to be notified about
219 * @param session the session for include in the notification
220 */
221typedef void
222(*GNUNET_TRANSPORT_UnregisterQuotaNotification) (void *cls,
223 const struct GNUNET_PeerIdentity *peer,
224 const char *plugin,
225 struct Session *session);
226
227/**
228 * Function that returns a HELLO message. 196 * Function that returns a HELLO message.
229 * 197 *
230 * @return HELLO message (FIXME with what?) 198 * @return HELLO message (FIXME with what?)
@@ -307,16 +275,6 @@ struct GNUNET_TRANSPORT_PluginEnvironment
307 GNUNET_TRANSPORT_UpdateAddressMetrics update_address_metrics; 275 GNUNET_TRANSPORT_UpdateAddressMetrics update_address_metrics;
308 276
309 /** 277 /**
310 * FIXME: document!
311 */
312 GNUNET_TRANSPORT_RegisterQuotaNotification register_quota_notification;
313
314 /**
315 * FIXME: document!
316 */
317 GNUNET_TRANSPORT_UnregisterQuotaNotification unregister_quota_notification;
318
319 /**
320 * What is the maximum number of connections that this transport 278 * What is the maximum number of connections that this transport
321 * should allow? Transports that do not have sessions (such as 279 * should allow? Transports that do not have sessions (such as
322 * UDP) can ignore this value. 280 * UDP) can ignore this value.
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index cd6bd9dff..8f6767c97 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -989,8 +989,6 @@ run (void *cls,
989 GST_ats_init (); 989 GST_ats_init ();
990 GST_manipulation_init (GST_cfg); 990 GST_manipulation_init (GST_cfg);
991 GST_plugins_load (&GST_manipulation_recv, 991 GST_plugins_load (&GST_manipulation_recv,
992 &GST_neighbours_register_quota_notification,
993 &GST_neighbours_unregister_quota_notification,
994 &plugin_env_address_change_notification, 992 &plugin_env_address_change_notification,
995 &plugin_env_session_start, 993 &plugin_env_session_start,
996 &plugin_env_session_end, 994 &plugin_env_session_end,
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index f1095095a..b400ac7fb 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -522,11 +522,6 @@ static unsigned long long bytes_in_send_queue;
522 */ 522 */
523static struct GNUNET_SCHEDULER_Task * util_transmission_tk; 523static struct GNUNET_SCHEDULER_Task * util_transmission_tk;
524 524
525/**
526 * FIXME
527 */
528static struct GNUNET_CONTAINER_MultiPeerMap *registered_quota_notifications;
529
530 525
531/** 526/**
532 * FIXME 527 * FIXME
@@ -2027,173 +2022,32 @@ send_connect_ack_message (const struct GNUNET_HELLO_Address *address,
2027 2022
2028} 2023}
2029 2024
2030struct QuotaNotificationRequest
2031{
2032 struct GNUNET_PeerIdentity peer;
2033 struct Session *session;
2034 char *plugin;
2035};
2036
2037struct QNR_LookContext
2038{
2039 struct GNUNET_PeerIdentity peer;
2040 struct Session *session;
2041 const char *plugin;
2042
2043 struct QuotaNotificationRequest *res;
2044};
2045
2046static int
2047find_notification_request (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
2048{
2049 struct QNR_LookContext *qnr_ctx = cls;
2050 struct QuotaNotificationRequest *qnr = value;
2051
2052 if ((qnr->session == qnr_ctx->session) &&
2053 (0 == memcmp (&qnr->peer,
2054 &qnr_ctx->peer,
2055 sizeof (struct GNUNET_PeerIdentity))) &&
2056 (0 == strcmp(qnr_ctx->plugin, qnr->plugin)))
2057 {
2058 qnr_ctx->res = value;
2059 return GNUNET_NO;
2060 }
2061 return GNUNET_YES;
2062}
2063
2064
2065void
2066GST_neighbours_register_quota_notification (void *cls,
2067 const struct GNUNET_PeerIdentity *peer,
2068 const char *plugin,
2069 struct Session *session)
2070{
2071 struct QuotaNotificationRequest *qnr;
2072 struct QNR_LookContext qnr_ctx;
2073
2074 if (NULL == registered_quota_notifications)
2075 {
2076 return; /* init or shutdown */
2077 }
2078
2079 qnr_ctx.peer = (*peer);
2080 qnr_ctx.plugin = plugin;
2081 qnr_ctx.session = session;
2082 qnr_ctx.res = NULL;
2083
2084 GNUNET_CONTAINER_multipeermap_get_multiple (registered_quota_notifications,
2085 peer, &find_notification_request, &qnr_ctx);
2086 if (NULL != qnr_ctx.res)
2087 {
2088 GNUNET_break(0);
2089 return;
2090 }
2091
2092 qnr = GNUNET_new (struct QuotaNotificationRequest);
2093 qnr->peer = (*peer);
2094 qnr->plugin = GNUNET_strdup (plugin);
2095 qnr->session = session;
2096
2097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2098 "Adding notification for peer `%s' plugin `%s' session %p \n",
2099 GNUNET_i2s (peer), plugin, session);
2100
2101 GNUNET_CONTAINER_multipeermap_put (registered_quota_notifications, peer,
2102 qnr, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2103}
2104
2105
2106void
2107GST_neighbours_unregister_quota_notification(void *cls,
2108 const struct GNUNET_PeerIdentity *peer,
2109 const char *plugin,
2110 struct Session *session)
2111{
2112 struct QNR_LookContext qnr_ctx;
2113
2114 if (NULL == registered_quota_notifications)
2115 {
2116 return; /* init or shutdown */
2117 }
2118 2025
2119 qnr_ctx.peer = (*peer); 2026static void
2120 qnr_ctx.plugin = plugin; 2027inbound_bw_tracker_update (void *cls)
2121 qnr_ctx.session = session;
2122 qnr_ctx.res = NULL;
2123
2124 GNUNET_CONTAINER_multipeermap_iterate (registered_quota_notifications,
2125 &find_notification_request, &qnr_ctx);
2126 if (NULL == qnr_ctx.res)
2127 {
2128 GNUNET_break(0);
2129 return;
2130 }
2131
2132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2133 "Removing notification for peer `%s' plugin `%s' session %p \n",
2134 GNUNET_i2s (peer), plugin, session);
2135
2136 GNUNET_CONTAINER_multipeermap_remove (registered_quota_notifications, peer,
2137 qnr_ctx.res);
2138 GNUNET_free (qnr_ctx.res->plugin);
2139 GNUNET_free (qnr_ctx.res);
2140}
2141
2142
2143static int
2144notification_cb (void *cls,
2145 const struct GNUNET_PeerIdentity *key,
2146 void *value)
2147{ 2028{
2148 /* struct NeighbourMapEntry *n = cls; */ 2029 struct NeighbourMapEntry *n = cls;
2149 struct QuotaNotificationRequest *qnr = value;
2150 struct GNUNET_TRANSPORT_PluginFunctions *papi; 2030 struct GNUNET_TRANSPORT_PluginFunctions *papi;
2151 struct GNUNET_TIME_Relative delay; 2031 struct GNUNET_TIME_Relative delay;
2152 int do_forward; 2032 int do_forward;
2153 2033
2154 papi = GST_plugins_find(qnr->plugin); 2034 if (NULL == n->primary_address.address)
2155 if (NULL == papi) 2035 return; /* not active, ignore */
2156 { 2036 papi = GST_plugins_find (n->primary_address.address->transport_name);
2157 GNUNET_break (0); 2037 GNUNET_assert (NULL != papi);
2158 return GNUNET_OK; 2038 if (NULL == papi->update_inbound_delay)
2159 } 2039 return;
2160 2040 delay = GST_neighbours_calculate_receive_delay (&n->id,
2161 delay = GST_neighbours_calculate_receive_delay (key, 0, &do_forward); 2041 0,
2042 &do_forward);
2162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2043 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2163 "New inbound delay for peer `%s' is %llu ms\n", GNUNET_i2s (key), 2044 "New inbound delay for peer `%s' is %llu ms\n",
2164 delay.rel_value_us / 1000); 2045 GNUNET_i2s (&n->id),
2165 2046 delay.rel_value_us / 1000);
2166 if (NULL != papi->update_inbound_delay) 2047 papi->update_inbound_delay (papi->cls,
2167 papi->update_inbound_delay (papi->cls, key, qnr->session, delay); 2048 &n->id,
2168 return GNUNET_OK; 2049 n->primary_address.session,
2169} 2050 delay);
2170
2171
2172static int
2173free_notification_cb (void *cls,
2174 const struct GNUNET_PeerIdentity *key,
2175 void *value)
2176{
2177 /* struct NeighbourMapEntry *n = cls; */
2178 struct QuotaNotificationRequest *qnr = value;
2179
2180 GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (registered_quota_notifications, key,
2181 qnr));
2182 GNUNET_free(qnr->plugin);
2183 GNUNET_free(qnr);
2184
2185 return GNUNET_OK;
2186}
2187
2188
2189static void
2190inbound_bw_tracker_update (void *cls)
2191{
2192 struct NeighbourMapEntry *n = cls;
2193
2194 /* Quota was updated, tell plugins to update the time to receive next */
2195 GNUNET_CONTAINER_multipeermap_get_multiple (registered_quota_notifications,
2196 &n->id, &notification_cb, n);
2197} 2051}
2198 2052
2199 2053
@@ -2220,11 +2074,15 @@ setup_neighbour (const struct GNUNET_PeerIdentity *peer)
2220 n->util_payload_bytes_sent = 0; 2074 n->util_payload_bytes_sent = 0;
2221 n->util_total_bytes_recv = 0; 2075 n->util_total_bytes_recv = 0;
2222 n->util_total_bytes_sent = 0; 2076 n->util_total_bytes_sent = 0;
2223 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, &inbound_bw_tracker_update, n, 2077 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
2078 &inbound_bw_tracker_update,
2079 n,
2224 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 2080 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
2225 MAX_BANDWIDTH_CARRY_S); 2081 MAX_BANDWIDTH_CARRY_S);
2226 n->task = GNUNET_SCHEDULER_add_now (&master_task, n); 2082 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
2227 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TIME_UNIT_FOREVER_ABS); 2083 set_state_and_timeout (n,
2084 GNUNET_TRANSPORT_PS_NOT_CONNECTED,
2085 GNUNET_TIME_UNIT_FOREVER_ABS);
2228 GNUNET_assert (GNUNET_OK == 2086 GNUNET_assert (GNUNET_OK ==
2229 GNUNET_CONTAINER_multipeermap_put (neighbours, 2087 GNUNET_CONTAINER_multipeermap_put (neighbours,
2230 &n->id, n, 2088 &n->id, n,
@@ -3900,7 +3758,6 @@ void
3900GST_neighbours_start (unsigned int max_fds) 3758GST_neighbours_start (unsigned int max_fds)
3901{ 3759{
3902 neighbours = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE, GNUNET_NO); 3760 neighbours = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE, GNUNET_NO);
3903 registered_quota_notifications = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE, GNUNET_NO);
3904 util_transmission_tk = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL, 3761 util_transmission_tk = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL,
3905 utilization_transmission, NULL); 3762 utilization_transmission, NULL);
3906} 3763}
@@ -3967,12 +3824,6 @@ GST_neighbours_stop ()
3967 GNUNET_HELLO_address_free (cur->address); 3824 GNUNET_HELLO_address_free (cur->address);
3968 GNUNET_free (cur); 3825 GNUNET_free (cur);
3969 } 3826 }
3970
3971 GNUNET_CONTAINER_multipeermap_iterate (registered_quota_notifications,
3972 &free_notification_cb, NULL);
3973 GNUNET_CONTAINER_multipeermap_destroy (registered_quota_notifications);
3974 registered_quota_notifications = NULL;
3975
3976 neighbours = NULL; 3827 neighbours = NULL;
3977} 3828}
3978 3829
diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h
index 093bd06e1..710439b10 100644
--- a/src/transport/gnunet-service-transport_neighbours.h
+++ b/src/transport/gnunet-service-transport_neighbours.h
@@ -102,27 +102,6 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
102 GST_NeighbourSendContinuation cont, void *cont_cls); 102 GST_NeighbourSendContinuation cont, void *cont_cls);
103 103
104 104
105
106/**
107 * FIXME
108 */
109void
110GST_neighbours_register_quota_notification (void *cls,
111 const struct GNUNET_PeerIdentity *peer,
112 const char *plugin,
113 struct Session *session);
114
115
116/**
117 * FIXME
118 */
119void
120GST_neighbours_unregister_quota_notification (void *cls,
121 const struct GNUNET_PeerIdentity *peer,
122 const char *plugin,
123 struct Session *session);
124
125
126/** 105/**
127 * We have received a message from the given sender. 106 * We have received a message from the given sender.
128 * How long should we delay before receiving more? 107 * How long should we delay before receiving more?
diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c
index e8b795f9d..db018a566 100644
--- a/src/transport/gnunet-service-transport_plugins.c
+++ b/src/transport/gnunet-service-transport_plugins.c
@@ -85,8 +85,6 @@ static struct TransportPlugin *plugins_tail;
85 * plugin that caused the call. 85 * plugin that caused the call.
86 * 86 *
87 * @param recv_cb function to call when data is received 87 * @param recv_cb function to call when data is received
88 * @param register_quota_cb function to call to register a quota callback
89 * @param unregister_quota_cb function to call to unregister a quota callback
90 * @param address_cb function to call when our public addresses changed 88 * @param address_cb function to call when our public addresses changed
91 * @param session_start_cb function to call when a session was created 89 * @param session_start_cb function to call when a session was created
92 * @param session_end_cb function to call when a session was terminated 90 * @param session_end_cb function to call when a session was terminated
@@ -95,8 +93,6 @@ static struct TransportPlugin *plugins_tail;
95 */ 93 */
96void 94void
97GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, 95GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
98 GNUNET_TRANSPORT_RegisterQuotaNotification register_quota_cb,
99 GNUNET_TRANSPORT_UnregisterQuotaNotification unregister_quota_cb,
100 GNUNET_TRANSPORT_AddressNotification address_cb, 96 GNUNET_TRANSPORT_AddressNotification address_cb,
101 GNUNET_TRANSPORT_SessionStart session_start_cb, 97 GNUNET_TRANSPORT_SessionStart session_start_cb,
102 GNUNET_TRANSPORT_SessionEnd session_end_cb, 98 GNUNET_TRANSPORT_SessionEnd session_end_cb,
@@ -145,15 +141,13 @@ GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
145 plug->env.session_end = session_end_cb; 141 plug->env.session_end = session_end_cb;
146 plug->env.get_address_type = address_type_cb; 142 plug->env.get_address_type = address_type_cb;
147 plug->env.update_address_metrics = metric_update_cb; 143 plug->env.update_address_metrics = metric_update_cb;
148 plug->env.register_quota_notification = register_quota_cb;
149 plug->env.unregister_quota_notification = unregister_quota_cb;
150 plug->env.max_connections = tneigh; 144 plug->env.max_connections = tneigh;
151 plug->env.stats = GST_stats; 145 plug->env.stats = GST_stats;
152 GNUNET_CONTAINER_DLL_insert (plugins_head, plugins_tail, plug); 146 GNUNET_CONTAINER_DLL_insert (plugins_head, plugins_tail, plug);
153 } 147 }
154 GNUNET_free (plugs); 148 GNUNET_free (plugs);
155 next = plugins_head; 149 next = plugins_head;
156 while (next != NULL) 150 while (NULL != next)
157 { 151 {
158 plug = next; 152 plug = next;
159 next = plug->next; 153 next = plug->next;
diff --git a/src/transport/gnunet-service-transport_plugins.h b/src/transport/gnunet-service-transport_plugins.h
index 766ebaa66..31161a3d6 100644
--- a/src/transport/gnunet-service-transport_plugins.h
+++ b/src/transport/gnunet-service-transport_plugins.h
@@ -50,8 +50,6 @@
50 */ 50 */
51void 51void
52GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, 52GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
53 GNUNET_TRANSPORT_RegisterQuotaNotification register_quota_cb,
54 GNUNET_TRANSPORT_UnregisterQuotaNotification unregister_quota_cb,
55 GNUNET_TRANSPORT_AddressNotification address_cb, 53 GNUNET_TRANSPORT_AddressNotification address_cb,
56 GNUNET_TRANSPORT_SessionStart session_start_cb, 54 GNUNET_TRANSPORT_SessionStart session_start_cb,
57 GNUNET_TRANSPORT_SessionEnd session_end_cb, 55 GNUNET_TRANSPORT_SessionEnd session_end_cb,
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index d59850f51..a070fdfc0 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -845,10 +845,6 @@ tcp_plugin_disconnect_session (void *cls,
845 GNUNET_SERVER_notify_transmit_ready_cancel (session->transmit_handle); 845 GNUNET_SERVER_notify_transmit_ready_cancel (session->transmit_handle);
846 session->transmit_handle = NULL; 846 session->transmit_handle = NULL;
847 } 847 }
848 plugin->env->unregister_quota_notification (plugin->env->cls,
849 &session->target,
850 PLUGIN_NAME,
851 session);
852 session->plugin->env->session_end (session->plugin->env->cls, 848 session->plugin->env->session_end (session->plugin->env->cls,
853 session->address, 849 session->address,
854 session); 850 session);
@@ -1054,10 +1050,6 @@ create_session (struct Plugin *plugin,
1054 session, 1050 session,
1055 GNUNET_TRANSPORT_SS_HANDSHAKE); 1051 GNUNET_TRANSPORT_SS_HANDSHAKE);
1056 } 1052 }
1057 plugin->env->register_quota_notification (plugin->env->cls,
1058 &address->peer,
1059 PLUGIN_NAME,
1060 session);
1061 return session; 1053 return session;
1062} 1054}
1063 1055
diff --git a/src/transport/test_transport_api_monitor_peers.c b/src/transport/test_transport_api_monitor_peers.c
index 536507c47..0cf58a0d1 100644
--- a/src/transport/test_transport_api_monitor_peers.c
+++ b/src/transport/test_transport_api_monitor_peers.c
@@ -386,6 +386,7 @@ start_cb (struct PeerContext *p, void *cls)
386 386
387static void 387static void
388monitor1_cb (void *cls, 388monitor1_cb (void *cls,
389 const struct GNUNET_PeerIdentity *peer,
389 const struct GNUNET_HELLO_Address *address, 390 const struct GNUNET_HELLO_Address *address,
390 enum GNUNET_TRANSPORT_PeerState state, 391 enum GNUNET_TRANSPORT_PeerState state,
391 struct GNUNET_TIME_Absolute state_timeout) 392 struct GNUNET_TIME_Absolute state_timeout)
@@ -411,6 +412,7 @@ monitor1_cb (void *cls,
411 412
412static void 413static void
413monitor2_cb (void *cls, 414monitor2_cb (void *cls,
415 const struct GNUNET_PeerIdentity *peer,
414 const struct GNUNET_HELLO_Address *address, 416 const struct GNUNET_HELLO_Address *address,
415 enum GNUNET_TRANSPORT_PeerState state, 417 enum GNUNET_TRANSPORT_PeerState state,
416 struct GNUNET_TIME_Absolute state_timeout) 418 struct GNUNET_TIME_Absolute state_timeout)