From 375cb861fb99d7fd9237cfdcf83c58fb9eb05141 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Fri, 7 Dec 2012 15:32:46 +0000 Subject: [PATCH] mod --- src/ats/gnunet-service-ats_addresses.c | 53 ------------------- src/ats/gnunet-service-ats_addresses.h | 25 ++++++++- .../gnunet-service-ats_addresses_simplistic.c | 53 ++++++++++++++++--- .../gnunet-service-ats_addresses_simplistic.h | 22 ++++++-- 4 files changed, 87 insertions(+), 66 deletions(-) diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 70869192e..ddaa8a367 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -314,11 +314,6 @@ compare_address_it (void *cls, const struct GNUNET_HashCode * key, void *value) struct CompareAddressContext *cac = cls; struct ATS_Address *aa = value; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing peer %4s: address length %u session %u <-> address length %u session %u\n", - GNUNET_h2s (key), - aa->addr_len, aa->session_id, - cac->search->addr_len, cac->search->session_id); - /* Find an matching exact address: * * Compare by: @@ -400,12 +395,6 @@ find_address (const struct GNUNET_PeerIdentity *peer, GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey, &compare_address_it, &cac); -#if 0 - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Found exact address: %s base address: %s\n", - (cac.exact_address != NULL) ? "YES" : "NO", - (cac.base_address != NULL) ? "YES" : "NO"); -#endif if (cac.exact_address == NULL) return cac.base_address; return cac.exact_address; @@ -444,48 +433,6 @@ lookup_address (const struct GNUNET_PeerIdentity *peer, } -#if 0 -static int -compare_address_session_it (void *cls, const struct GNUNET_HashCode * key, void *value) -{ - struct CompareAddressContext *cac = cls; - struct ATS_Address *aa = value; - - if ((aa->addr_len == cac->search->addr_len) && (0 == strcmp (aa->plugin, cac->search->plugin))) - { - if ((0 == memcmp (aa->addr, cac->search->addr, aa->addr_len)) && (aa->session_id == cac->search->session_id)) - { - cac->exact_address = aa; - return GNUNET_NO; - } - } - return GNUNET_YES; -} - - -/** - * Find an existing equivalent address record. - * Compares by peer identity and network address AND by session ID - * (one of the two must match). - * - * @param peer peer to lookup addresses for - * @param addr existing address record - * @return existing address record, NULL for none - */ -static struct ATS_Address * -find_exact_address (const struct GNUNET_PeerIdentity *peer, - const struct ATS_Address *addr) -{ - struct CompareAddressContext cac; - - cac.exact_address = NULL; - cac.search = addr; - GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey, - &compare_address_session_it, &cac); - return cac.exact_address; -} -#endif - void GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, const char *plugin_name, const void *plugin_addr, diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index 80c89afba..5600d48e2 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h @@ -147,12 +147,33 @@ struct ATS_Address }; +/** + * Init the simplistic problem solving component + * + * Quotas: + * network[i] contains the network type as type GNUNET_ATS_NetworkType[i] + * out_quota[i] contains outbound quota for network type i + * in_quota[i] contains inbound quota for network type i + * + * Example + * network = {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN} + * network[2] == GNUNET_ATS_NET_LAN + * out_quota[2] == 65353 + * in_quota[2] == 65353 + * + * @param cfg configuration handle + * @param stats the GNUNET_STATISTICS handle + * @param network array of GNUNET_ATS_NetworkType with length dest_length + * @param out_quota array of outbound quotas + * param in_quota array of outbound quota + * @return handle for the solver on success, NULL on fail + */ typedef void * (*GAS_solver_init) (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_STATISTICS_Handle *stats, int *network, - unsigned long long *out_dest, - unsigned long long *in_dest, + unsigned long long *out_quota, + unsigned long long *in_quota, int dest_length); typedef void diff --git a/src/ats/gnunet-service-ats_addresses_simplistic.c b/src/ats/gnunet-service-ats_addresses_simplistic.c index baab09e90..1e7b468d5 100644 --- a/src/ats/gnunet-service-ats_addresses_simplistic.c +++ b/src/ats/gnunet-service-ats_addresses_simplistic.c @@ -36,26 +36,62 @@ */ struct GAS_SIMPLISTIC_Handle { + unsigned int active_addresses; + + /** + * Network type array + * + * quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; + * + */ int *quota_net; + + /** + * Array of inbound quotas + * + */ unsigned long long *quota_in; + + /** + * Array of outbound quotas + * + */ unsigned long long *quota_out; -}; + /** + * Active addresses per network type + */ + unsigned int *active_addresses_per_net; +}; /** * Init the simplistic problem solving component * + * Quotas: + * network[i] contains the network type as type GNUNET_ATS_NetworkType[i] + * out_quota[i] contains outbound quota for network type i + * in_quota[i] contains inbound quota for network type i + * + * Example + * network = {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN} + * network[2] == GNUNET_ATS_NET_LAN + * out_quota[2] == 65353 + * in_quota[2] == 65353 + * * @param cfg configuration handle * @param stats the GNUNET_STATISTICS handle + * @param network array of GNUNET_ATS_NetworkType with length dest_length + * @param out_quota array of outbound quotas + * param in_quota array of outbound quota * @return handle for the solver on success, NULL on fail */ void * GAS_simplistic_init (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_STATISTICS_Handle *stats, int *network, - unsigned long long *out_dest, - unsigned long long *in_dest, + unsigned long long *out_quota, + unsigned long long *in_quota, int dest_length) { struct GAS_SIMPLISTIC_Handle *solver = GNUNET_malloc (sizeof (struct GAS_SIMPLISTIC_Handle)); @@ -64,10 +100,12 @@ GAS_simplistic_init (const struct GNUNET_CONFIGURATION_Handle *cfg, memcpy (solver->quota_net, network, dest_length * sizeof (int)); solver->quota_in = GNUNET_malloc (dest_length * sizeof (unsigned long long)); - memcpy (solver->quota_in, out_dest, dest_length * sizeof (int)); + memcpy (solver->quota_in, in_quota, dest_length * sizeof (int)); solver->quota_out = GNUNET_malloc (dest_length * sizeof (unsigned long long)); - memcpy (solver->quota_out, out_dest, dest_length * sizeof (unsigned long long)); + memcpy (solver->quota_out, out_quota, dest_length * sizeof (unsigned long long)); + + solver->active_addresses_per_net = GNUNET_malloc (dest_length * sizeof (unsigned int)); return solver; } @@ -86,6 +124,7 @@ GAS_simplistic_done (void *solver) GNUNET_free (s->quota_net); GNUNET_free (s->quota_in); GNUNET_free (s->quota_out); + GNUNET_free (s->active_addresses_per_net); GNUNET_free (s); } @@ -212,8 +251,6 @@ update_bw_simple_it (void *cls, const struct GNUNET_HashCode * key, void *value) aa->assigned_bw_in.value__ = htonl (UINT32_MAX / s->active_addresses); aa->assigned_bw_out.value__ = htonl (UINT32_MAX / s->active_addresses); - //send_bw_notification (aa); - return GNUNET_OK; } @@ -284,7 +321,7 @@ GAS_simplistic_address_change_preference (void *solver, enum GNUNET_ATS_PreferenceKind kind, float score) { - + /* FIXME : implement this */ } /* end of gnunet-service-ats_addresses_simplistic.c */ diff --git a/src/ats/gnunet-service-ats_addresses_simplistic.h b/src/ats/gnunet-service-ats_addresses_simplistic.h index 6f45f819b..7c99b74ca 100644 --- a/src/ats/gnunet-service-ats_addresses_simplistic.h +++ b/src/ats/gnunet-service-ats_addresses_simplistic.h @@ -33,15 +33,31 @@ /** * Init the simplistic problem solving component * + * Quotas: + * network[i] contains the network type as type GNUNET_ATS_NetworkType[i] + * out_quota[i] contains outbound quota for network type i + * in_quota[i] contains inbound quota for network type i + * + * Example + * network = {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN} + * network[2] == GNUNET_ATS_NET_LAN + * out_quota[2] == 65353 + * in_quota[2] == 65353 + * * @param cfg configuration handle * @param stats the GNUNET_STATISTICS handle + * @param network array of GNUNET_ATS_NetworkType with length dest_length + * @param out_quota array of outbound quotas + * param in_quota array of outbound quota * @return handle for the solver on success, NULL on fail */ void * GAS_simplistic_init (const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_STATISTICS_Handle *stats, - int *network, - unsigned long long *out_dest, unsigned long long *in_dest, int dest_length); + const struct GNUNET_STATISTICS_Handle *stats, + int *network, + unsigned long long *out_quota, + unsigned long long *in_quota, + int dest_length); /** * Shutdown the simplistic problem solving component -- 2.25.1