commit f2d1198d45bc3786d0164a5b6df928768022d1b7
parent 8727c5c69097aeb474ce6039bf31650400b6286a
Author: Christian Grothoff <christian@grothoff.org>
Date: Mon, 2 Feb 2015 23:31:25 +0000
dramatically simplify quota notification: avoid registration, simply always notify plugin
Diffstat:
8 files changed, 28 insertions(+), 256 deletions(-)
diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h
@@ -193,38 +193,6 @@ typedef struct GNUNET_TIME_Relative
/**
- * Function to be called by the plugin to be notified about changes to the quota
- * for a specific peer, plugin and session
- *
- * @param cls closure
- * @param peer the peer to be notified about
- * @param plugin the plugin to be notified about
- * @param session the session for include in the notification
- *
- */
-typedef void
-(*GNUNET_TRANSPORT_RegisterQuotaNotification) (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin,
- struct Session *session);
-
-
-/**
- * Function to be called by the plugin to stop notification about changes to the quota
- * for a specific peer, plugin and session
- *
- * @param cls closure
- * @param peer the peer to be notified about
- * @param plugin the plugin to be notified about
- * @param session the session for include in the notification
- */
-typedef void
-(*GNUNET_TRANSPORT_UnregisterQuotaNotification) (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin,
- struct Session *session);
-
-/**
* Function that returns a HELLO message.
*
* @return HELLO message (FIXME with what?)
@@ -307,16 +275,6 @@ struct GNUNET_TRANSPORT_PluginEnvironment
GNUNET_TRANSPORT_UpdateAddressMetrics update_address_metrics;
/**
- * FIXME: document!
- */
- GNUNET_TRANSPORT_RegisterQuotaNotification register_quota_notification;
-
- /**
- * FIXME: document!
- */
- GNUNET_TRANSPORT_UnregisterQuotaNotification unregister_quota_notification;
-
- /**
* What is the maximum number of connections that this transport
* should allow? Transports that do not have sessions (such as
* UDP) can ignore this value.
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
@@ -989,8 +989,6 @@ run (void *cls,
GST_ats_init ();
GST_manipulation_init (GST_cfg);
GST_plugins_load (&GST_manipulation_recv,
- &GST_neighbours_register_quota_notification,
- &GST_neighbours_unregister_quota_notification,
&plugin_env_address_change_notification,
&plugin_env_session_start,
&plugin_env_session_end,
diff --git 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;
*/
static struct GNUNET_SCHEDULER_Task * util_transmission_tk;
-/**
- * FIXME
- */
-static struct GNUNET_CONTAINER_MultiPeerMap *registered_quota_notifications;
-
/**
* FIXME
@@ -2027,173 +2022,32 @@ send_connect_ack_message (const struct GNUNET_HELLO_Address *address,
}
-struct QuotaNotificationRequest
-{
- struct GNUNET_PeerIdentity peer;
- struct Session *session;
- char *plugin;
-};
-
-struct QNR_LookContext
-{
- struct GNUNET_PeerIdentity peer;
- struct Session *session;
- const char *plugin;
-
- struct QuotaNotificationRequest *res;
-};
-
-static int
-find_notification_request (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
-{
- struct QNR_LookContext *qnr_ctx = cls;
- struct QuotaNotificationRequest *qnr = value;
-
- if ((qnr->session == qnr_ctx->session) &&
- (0 == memcmp (&qnr->peer,
- &qnr_ctx->peer,
- sizeof (struct GNUNET_PeerIdentity))) &&
- (0 == strcmp(qnr_ctx->plugin, qnr->plugin)))
- {
- qnr_ctx->res = value;
- return GNUNET_NO;
- }
- return GNUNET_YES;
-}
-
-
-void
-GST_neighbours_register_quota_notification (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin,
- struct Session *session)
-{
- struct QuotaNotificationRequest *qnr;
- struct QNR_LookContext qnr_ctx;
-
- if (NULL == registered_quota_notifications)
- {
- return; /* init or shutdown */
- }
-
- qnr_ctx.peer = (*peer);
- qnr_ctx.plugin = plugin;
- qnr_ctx.session = session;
- qnr_ctx.res = NULL;
-
- GNUNET_CONTAINER_multipeermap_get_multiple (registered_quota_notifications,
- peer, &find_notification_request, &qnr_ctx);
- if (NULL != qnr_ctx.res)
- {
- GNUNET_break(0);
- return;
- }
-
- qnr = GNUNET_new (struct QuotaNotificationRequest);
- qnr->peer = (*peer);
- qnr->plugin = GNUNET_strdup (plugin);
- qnr->session = session;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding notification for peer `%s' plugin `%s' session %p \n",
- GNUNET_i2s (peer), plugin, session);
-
- GNUNET_CONTAINER_multipeermap_put (registered_quota_notifications, peer,
- qnr, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
-}
-
-
-void
-GST_neighbours_unregister_quota_notification(void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin,
- struct Session *session)
-{
- struct QNR_LookContext qnr_ctx;
-
- if (NULL == registered_quota_notifications)
- {
- return; /* init or shutdown */
- }
- qnr_ctx.peer = (*peer);
- qnr_ctx.plugin = plugin;
- qnr_ctx.session = session;
- qnr_ctx.res = NULL;
-
- GNUNET_CONTAINER_multipeermap_iterate (registered_quota_notifications,
- &find_notification_request, &qnr_ctx);
- if (NULL == qnr_ctx.res)
- {
- GNUNET_break(0);
- return;
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Removing notification for peer `%s' plugin `%s' session %p \n",
- GNUNET_i2s (peer), plugin, session);
-
- GNUNET_CONTAINER_multipeermap_remove (registered_quota_notifications, peer,
- qnr_ctx.res);
- GNUNET_free (qnr_ctx.res->plugin);
- GNUNET_free (qnr_ctx.res);
-}
-
-
-static int
-notification_cb (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
+static void
+inbound_bw_tracker_update (void *cls)
{
- /* struct NeighbourMapEntry *n = cls; */
- struct QuotaNotificationRequest *qnr = value;
+ struct NeighbourMapEntry *n = cls;
struct GNUNET_TRANSPORT_PluginFunctions *papi;
struct GNUNET_TIME_Relative delay;
int do_forward;
- papi = GST_plugins_find(qnr->plugin);
- if (NULL == papi)
- {
- GNUNET_break (0);
- return GNUNET_OK;
- }
-
- delay = GST_neighbours_calculate_receive_delay (key, 0, &do_forward);
+ if (NULL == n->primary_address.address)
+ return; /* not active, ignore */
+ papi = GST_plugins_find (n->primary_address.address->transport_name);
+ GNUNET_assert (NULL != papi);
+ if (NULL == papi->update_inbound_delay)
+ return;
+ delay = GST_neighbours_calculate_receive_delay (&n->id,
+ 0,
+ &do_forward);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "New inbound delay for peer `%s' is %llu ms\n", GNUNET_i2s (key),
- delay.rel_value_us / 1000);
-
- if (NULL != papi->update_inbound_delay)
- papi->update_inbound_delay (papi->cls, key, qnr->session, delay);
- return GNUNET_OK;
-}
-
-
-static int
-free_notification_cb (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
-{
- /* struct NeighbourMapEntry *n = cls; */
- struct QuotaNotificationRequest *qnr = value;
-
- GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (registered_quota_notifications, key,
- qnr));
- GNUNET_free(qnr->plugin);
- GNUNET_free(qnr);
-
- return GNUNET_OK;
-}
-
-
-static void
-inbound_bw_tracker_update (void *cls)
-{
- struct NeighbourMapEntry *n = cls;
-
- /* Quota was updated, tell plugins to update the time to receive next */
- GNUNET_CONTAINER_multipeermap_get_multiple (registered_quota_notifications,
- &n->id, ¬ification_cb, n);
+ "New inbound delay for peer `%s' is %llu ms\n",
+ GNUNET_i2s (&n->id),
+ delay.rel_value_us / 1000);
+ papi->update_inbound_delay (papi->cls,
+ &n->id,
+ n->primary_address.session,
+ delay);
}
@@ -2220,11 +2074,15 @@ setup_neighbour (const struct GNUNET_PeerIdentity *peer)
n->util_payload_bytes_sent = 0;
n->util_total_bytes_recv = 0;
n->util_total_bytes_sent = 0;
- GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, &inbound_bw_tracker_update, n,
+ GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
+ &inbound_bw_tracker_update,
+ n,
GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
MAX_BANDWIDTH_CARRY_S);
n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
- set_state_and_timeout (n, GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TIME_UNIT_FOREVER_ABS);
+ set_state_and_timeout (n,
+ GNUNET_TRANSPORT_PS_NOT_CONNECTED,
+ GNUNET_TIME_UNIT_FOREVER_ABS);
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multipeermap_put (neighbours,
&n->id, n,
@@ -3900,7 +3758,6 @@ void
GST_neighbours_start (unsigned int max_fds)
{
neighbours = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE, GNUNET_NO);
- registered_quota_notifications = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE, GNUNET_NO);
util_transmission_tk = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL,
utilization_transmission, NULL);
}
@@ -3967,12 +3824,6 @@ GST_neighbours_stop ()
GNUNET_HELLO_address_free (cur->address);
GNUNET_free (cur);
}
-
- GNUNET_CONTAINER_multipeermap_iterate (registered_quota_notifications,
- &free_notification_cb, NULL);
- GNUNET_CONTAINER_multipeermap_destroy (registered_quota_notifications);
- registered_quota_notifications = NULL;
-
neighbours = NULL;
}
diff --git 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,
GST_NeighbourSendContinuation cont, void *cont_cls);
-
-/**
- * FIXME
- */
-void
-GST_neighbours_register_quota_notification (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin,
- struct Session *session);
-
-
-/**
- * FIXME
- */
-void
-GST_neighbours_unregister_quota_notification (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin,
- struct Session *session);
-
-
/**
* We have received a message from the given sender.
* 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
@@ -85,8 +85,6 @@ static struct TransportPlugin *plugins_tail;
* plugin that caused the call.
*
* @param recv_cb function to call when data is received
- * @param register_quota_cb function to call to register a quota callback
- * @param unregister_quota_cb function to call to unregister a quota callback
* @param address_cb function to call when our public addresses changed
* @param session_start_cb function to call when a session was created
* @param session_end_cb function to call when a session was terminated
@@ -95,8 +93,6 @@ static struct TransportPlugin *plugins_tail;
*/
void
GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
- GNUNET_TRANSPORT_RegisterQuotaNotification register_quota_cb,
- GNUNET_TRANSPORT_UnregisterQuotaNotification unregister_quota_cb,
GNUNET_TRANSPORT_AddressNotification address_cb,
GNUNET_TRANSPORT_SessionStart session_start_cb,
GNUNET_TRANSPORT_SessionEnd session_end_cb,
@@ -145,15 +141,13 @@ GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
plug->env.session_end = session_end_cb;
plug->env.get_address_type = address_type_cb;
plug->env.update_address_metrics = metric_update_cb;
- plug->env.register_quota_notification = register_quota_cb;
- plug->env.unregister_quota_notification = unregister_quota_cb;
plug->env.max_connections = tneigh;
plug->env.stats = GST_stats;
GNUNET_CONTAINER_DLL_insert (plugins_head, plugins_tail, plug);
}
GNUNET_free (plugs);
next = plugins_head;
- while (next != NULL)
+ while (NULL != next)
{
plug = next;
next = plug->next;
diff --git a/src/transport/gnunet-service-transport_plugins.h b/src/transport/gnunet-service-transport_plugins.h
@@ -50,8 +50,6 @@
*/
void
GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
- GNUNET_TRANSPORT_RegisterQuotaNotification register_quota_cb,
- GNUNET_TRANSPORT_UnregisterQuotaNotification unregister_quota_cb,
GNUNET_TRANSPORT_AddressNotification address_cb,
GNUNET_TRANSPORT_SessionStart session_start_cb,
GNUNET_TRANSPORT_SessionEnd session_end_cb,
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
@@ -845,10 +845,6 @@ tcp_plugin_disconnect_session (void *cls,
GNUNET_SERVER_notify_transmit_ready_cancel (session->transmit_handle);
session->transmit_handle = NULL;
}
- plugin->env->unregister_quota_notification (plugin->env->cls,
- &session->target,
- PLUGIN_NAME,
- session);
session->plugin->env->session_end (session->plugin->env->cls,
session->address,
session);
@@ -1054,10 +1050,6 @@ create_session (struct Plugin *plugin,
session,
GNUNET_TRANSPORT_SS_HANDSHAKE);
}
- plugin->env->register_quota_notification (plugin->env->cls,
- &address->peer,
- PLUGIN_NAME,
- session);
return session;
}
diff --git 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)
static void
monitor1_cb (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_HELLO_Address *address,
enum GNUNET_TRANSPORT_PeerState state,
struct GNUNET_TIME_Absolute state_timeout)
@@ -411,6 +412,7 @@ monitor1_cb (void *cls,
static void
monitor2_cb (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_HELLO_Address *address,
enum GNUNET_TRANSPORT_PeerState state,
struct GNUNET_TIME_Absolute state_timeout)