diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-02 23:31:25 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-02 23:31:25 +0000 |
commit | f2d1198d45bc3786d0164a5b6df928768022d1b7 (patch) | |
tree | bcce1d8e39bbcddda171c3637bf418f4fbd41824 /src/transport/gnunet-service-transport_neighbours.c | |
parent | 8727c5c69097aeb474ce6039bf31650400b6286a (diff) | |
download | gnunet-f2d1198d45bc3786d0164a5b6df928768022d1b7.tar.gz gnunet-f2d1198d45bc3786d0164a5b6df928768022d1b7.zip |
dramatically simplify quota notification: avoid registration, simply always notify plugin
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.c | 199 |
1 files changed, 25 insertions, 174 deletions
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 | */ |
523 | static struct GNUNET_SCHEDULER_Task * util_transmission_tk; | 523 | static struct GNUNET_SCHEDULER_Task * util_transmission_tk; |
524 | 524 | ||
525 | /** | ||
526 | * FIXME | ||
527 | */ | ||
528 | static 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 | ||
2030 | struct QuotaNotificationRequest | ||
2031 | { | ||
2032 | struct GNUNET_PeerIdentity peer; | ||
2033 | struct Session *session; | ||
2034 | char *plugin; | ||
2035 | }; | ||
2036 | |||
2037 | struct QNR_LookContext | ||
2038 | { | ||
2039 | struct GNUNET_PeerIdentity peer; | ||
2040 | struct Session *session; | ||
2041 | const char *plugin; | ||
2042 | |||
2043 | struct QuotaNotificationRequest *res; | ||
2044 | }; | ||
2045 | |||
2046 | static int | ||
2047 | find_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 | |||
2065 | void | ||
2066 | GST_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 | |||
2106 | void | ||
2107 | GST_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); | 2026 | static void |
2120 | qnr_ctx.plugin = plugin; | 2027 | inbound_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 | |||
2143 | static int | ||
2144 | notification_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 | |||
2172 | static int | ||
2173 | free_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 | |||
2189 | static void | ||
2190 | inbound_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, ¬ification_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 | |||
3900 | GST_neighbours_start (unsigned int max_fds) | 3758 | GST_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 | ||