From: Matthias Wachs Date: Fri, 6 Jul 2012 13:24:20 +0000 (+0000) Subject: - implementation for mantis 0002485 X-Git-Tag: initial-import-from-subversion-38251~12610 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=56389a7d277b05c9c2968b7ebd529a12f8be15eb;p=oweals%2Fgnunet.git - implementation for mantis 0002485 --- diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 6bba8a12d..a0e811886 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -90,12 +90,16 @@ static int connections; * @param ats performance information (unused) * @param ats_count number of records in ats (unused) * @param address the address + * @param bandwidth_in inbound quota in NBO + * @param bandwidth_out outbound quota in NBO */ static void transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target, const struct GNUNET_ATS_Information *ats, uint32_t ats_count, - const struct GNUNET_HELLO_Address *address) + const struct GNUNET_HELLO_Address *address, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) { const struct GNUNET_MessageHeader *hello = cls; @@ -451,7 +455,9 @@ static void neighbours_connect_notification (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + uint32_t ats_count, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) { size_t len = sizeof (struct ConnectInfoMessage) + @@ -469,6 +475,8 @@ neighbours_connect_notification (void *cls, connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); connect_msg->ats_count = htonl (ats_count); connect_msg->id = *peer; + connect_msg->quota_in = bandwidth_in; + connect_msg->quota_out = bandwidth_out; ap = (struct GNUNET_ATS_Information *) &connect_msg[1]; memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); GST_clients_broadcast (&connect_msg->header, GNUNET_NO); diff --git a/src/transport/gnunet-service-transport_blacklist.c b/src/transport/gnunet-service-transport_blacklist.c index c71ecdfd8..8b6e45612 100644 --- a/src/transport/gnunet-service-transport_blacklist.c +++ b/src/transport/gnunet-service-transport_blacklist.c @@ -543,12 +543,16 @@ struct TestConnectionContext * @param ats performance data * @param ats_count number of entries in ats (excluding 0-termination) * @param address the address + * @param bandwidth_in inbound quota in NBO + * @param bandwidth_out outbound quota in NBO */ static void test_connection_ok (void *cls, const struct GNUNET_PeerIdentity *neighbour, const struct GNUNET_ATS_Information *ats, uint32_t ats_count, - const struct GNUNET_HELLO_Address *address) + const struct GNUNET_HELLO_Address *address, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) { struct TestConnectionContext *tcc = cls; struct GST_BlacklistCheck *bc; diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index b2981951d..c530a9da4 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c @@ -437,7 +437,9 @@ notify_client_about_neighbour (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *ats, uint32_t ats_count, - const struct GNUNET_HELLO_Address *address) + const struct GNUNET_HELLO_Address *address, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) { struct TransportClient *tc = cls; struct ConnectInfoMessage *cim; @@ -453,6 +455,8 @@ notify_client_about_neighbour (void *cls, cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); cim->ats_count = htonl (ats_count); cim->id = *peer; + cim->quota_in = bandwidth_in; + cim->quota_out = bandwidth_out; ap = (struct GNUNET_ATS_Information *) &cim[1]; memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); unicast (tc, &cim->header, GNUNET_NO); @@ -832,11 +836,15 @@ compose_address_iterate_response_message (const struct GNUNET_PeerIdentity * @param ats performance data * @param ats_count number of entries in ats (excluding 0-termination) * @param address the address + * @param bandwidth_in inbound quota in NBO + * @param bandwidth_out outbound quota in NBO */ static void output_address (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *ats, uint32_t ats_count, - const struct GNUNET_HELLO_Address *address) + const struct GNUNET_HELLO_Address *address, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) { struct GNUNET_SERVER_TransmitContext *tc = cls; struct AddressIterateResponseMessage *msg; @@ -900,7 +908,9 @@ clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client, /* just return one neighbour */ address = GST_neighbour_get_current_address (&msg->peer); if (address != NULL) - output_address (tc, &msg->peer, NULL, 0, address); + output_address (tc, &msg->peer, NULL, 0, address, + GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, + GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT); } if (GNUNET_YES != ntohl (msg->one_shot)) setup_monitoring_client (client, &msg->peer); diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index cd60ad956..ce407a382 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c @@ -595,7 +595,7 @@ static void *callback_cls; /** * Function to call when we connected to a neighbour. */ -static GNUNET_TRANSPORT_NotifyConnect connect_notify_cb; +static NotifyConnect connect_notify_cb; /** * Function to call when we disconnected from a neighbour. @@ -2170,11 +2170,14 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ATS tells us to switch to address '%s' session %p for peer `%s' in state %s\n", + "ATS tells us to switch to address '%s' session %p for " + "peer `%s' in state %s (quota in/out %u %u )\n", (address->address_length != 0) ? GST_plugins_a2s (address): "", session, GNUNET_i2s (peer), - print_state (n->state)); + print_state (n->state), + ntohl (bandwidth_in.value__), + ntohl (bandwidth_out.value__)); if (NULL == session) { @@ -2634,7 +2637,9 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, gettext_noop ("# peers connected"), ++neighbours_connected, GNUNET_NO); - connect_notify_cb (callback_cls, &n->id, ats, ats_count); + connect_notify_cb (callback_cls, &n->id, ats, ats_count, + n->primary_address.bandwidth_in, + n->primary_address.bandwidth_out); /* Tell ATS that the outbound session we created to send CONNECT was successfull */ GNUNET_ATS_address_add (GST_ats, n->primary_address.address, @@ -2894,7 +2899,9 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message, gettext_noop ("# peers connected"), ++neighbours_connected, GNUNET_NO); - connect_notify_cb (callback_cls, &n->id, ats, ats_count); + connect_notify_cb (callback_cls, &n->id, ats, ats_count, + n->primary_address.bandwidth_in, + n->primary_address.bandwidth_out); GNUNET_ATS_address_add(GST_ats, n->primary_address.address, n->primary_address.session, @@ -3062,7 +3069,25 @@ neighbours_iterate (void *cls, const struct GNUNET_HashCode * key, void *value) struct NeighbourMapEntry *n = value; if (GNUNET_YES == test_connected (n)) - ic->cb (ic->cb_cls, &n->id, NULL, 0, n->primary_address.address); + { + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; + + if (NULL != n->primary_address.address) + { + bandwidth_in = n->primary_address.bandwidth_in; + bandwidth_out = n->primary_address.bandwidth_out; + } + else + { + bandwidth_in = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; + bandwidth_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; + } + + ic->cb (ic->cb_cls, &n->id, NULL, 0, + n->primary_address.address, + bandwidth_in, bandwidth_out); + } return GNUNET_OK; } @@ -3180,7 +3205,7 @@ GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer) */ void GST_neighbours_start (void *cls, - GNUNET_TRANSPORT_NotifyConnect connect_cb, + NotifyConnect connect_cb, GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb, GNUNET_TRANSPORT_PeerIterateCallback peer_address_cb) { diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h index 18afcafc5..d137c311d 100644 --- a/src/transport/gnunet-service-transport_neighbours.h +++ b/src/transport/gnunet-service-transport_neighbours.h @@ -29,6 +29,7 @@ #include "gnunet_statistics_service.h" #include "gnunet_transport_service.h" #include "gnunet_transport_plugin.h" +#include "transport.h" #include "gnunet_util_lib.h" // TODO: @@ -46,7 +47,7 @@ */ void GST_neighbours_start (void *cls, - GNUNET_TRANSPORT_NotifyConnect connect_cb, + NotifyConnect connect_cb, GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb, GNUNET_TRANSPORT_PeerIterateCallback peer_address_cb); @@ -170,6 +171,8 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target); * @param ats performance data * @param ats_count number of entries in ats (including 0-termination) * @param address the address (or NULL) + * @param bandwidth_in inbound quota in NBO + * @param bandwidth_out outbound quota in NBO */ typedef void (*GST_NeighbourIterator) (void *cls, const struct GNUNET_PeerIdentity * @@ -177,7 +180,9 @@ typedef void (*GST_NeighbourIterator) (void *cls, const struct GNUNET_ATS_Information * ats, uint32_t ats_count, const struct GNUNET_HELLO_Address * - address); + address, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out); /** diff --git a/src/transport/transport.h b/src/transport/transport.h index e0b881970..3cca8e268 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -56,6 +56,26 @@ */ #define CONNECTED_LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1) +/** + * Similiar to GNUNET_TRANSPORT_NotifyDisconnect but in and out quotas are + * included here. These values are not required outside transport_api + * + * @param cls closure + * @param peer the peer that connected + * @param ats performance data + * @param ats_count number of entries in ats (excluding 0-termination) + * @param bandwidth_in inbound bandwidth in NBO + * @param bandwidth_out outbound bandwidth in NBO + * + */ + +typedef void (*NotifyConnect) (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out); + GNUNET_NETWORK_STRUCT_BEGIN /** @@ -109,6 +129,16 @@ struct ConnectInfoMessage * Identity of the new neighbour. */ struct GNUNET_PeerIdentity id; + + /** + * Current inbound quota for this peer + */ + struct GNUNET_BANDWIDTH_Value32NBO quota_in; + + /** + * Current outbound quota for this peer + */ + struct GNUNET_BANDWIDTH_Value32NBO quota_out; }; diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index 3a1068cd1..ddad8f196 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c @@ -477,6 +477,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg) break; } n = neighbour_add (h, &cim->id); + GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, cim->quota_out); if (h->nc_cb != NULL) h->nc_cb (h->cls, &n->id, ats, ats_count); break;