From f4af5b0b23a2efe6b5f25dbd87f79f788bfd5aba Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Thu, 14 Feb 2013 13:28:13 +0000 Subject: [PATCH] mod --- src/ats/test_ats_api_common.c | 33 ++++++++ src/ats/test_ats_api_common.h | 7 ++ src/ats/test_ats_mlp.c | 139 +++++++++------------------------- 3 files changed, 75 insertions(+), 104 deletions(-) diff --git a/src/ats/test_ats_api_common.c b/src/ats/test_ats_api_common.c index dcd043e71..f8d106a7f 100644 --- a/src/ats/test_ats_api_common.c +++ b/src/ats/test_ats_api_common.c @@ -242,4 +242,37 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, return GNUNET_ATS_NetworkTypeCount; } +/** + * Create a ATS_address with the given information + * @param peer peer + * @param plugin_name plugin + * @param plugin_addr address + * @param plugin_addr_len address length + * @param session_id session + * @return the ATS_Address + */ +struct ATS_Address * +create_address (const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, + const void *plugin_addr, size_t plugin_addr_len, + uint32_t session_id) +{ + struct ATS_Address *aa = NULL; + + aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1); + aa->peer = *peer; + aa->addr_len = plugin_addr_len; + aa->addr = &aa[1]; + aa->plugin = (char *) &aa[1] + plugin_addr_len; + memcpy (&aa[1], plugin_addr, plugin_addr_len); + memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1); + aa->session_id = session_id; + aa->active = GNUNET_NO; + aa->used = GNUNET_NO; + aa->solver_information = NULL; + aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0); + aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0); + return aa; +} + /* end of file test_ats_api_common.c */ diff --git a/src/ats/test_ats_api_common.h b/src/ats/test_ats_api_common.h index 3fbd0691b..1f9bd10c1 100644 --- a/src/ats/test_ats_api_common.h +++ b/src/ats/test_ats_api_common.h @@ -27,6 +27,7 @@ #include "platform.h" #include "gnunet_common.h" #include "gnunet_ats_service.h" +#include "gnunet-service-ats_addresses.h" #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) @@ -72,6 +73,12 @@ int compare_ats (const struct GNUNET_ATS_Information *ats_is, uint32_t ats_count_is, const struct GNUNET_ATS_Information *ats_should, uint32_t ats_count_should); +struct ATS_Address * +create_address (const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, + const void *plugin_addr, size_t plugin_addr_len, + uint32_t session_id); + /** * Load quotas for networks from configuration * diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c index 594957a25..7945ab3a9 100644 --- a/src/ats/test_ats_mlp.c +++ b/src/ats/test_ats_mlp.c @@ -52,32 +52,21 @@ struct GNUNET_STATISTICS_Handle * stats; */ struct GNUNET_CONTAINER_MultiHashMap * addresses; +/** + * Peer + */ +struct GNUNET_PeerIdentity p; + +/** + * ATS Address + */ +struct ATS_Address *address; + #if 0 #define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) #define MLP_MAX_ITERATIONS INT_MAX - - - - - - - - - - -static void -create_address (struct ATS_Address *addr, char * plugin, int ats_count, struct GNUNET_ATS_Information *ats) -{ - addr->solver_information = NULL; - addr->next = NULL; - addr->prev = NULL; - addr->plugin = GNUNET_strdup (plugin); - addr->ats_count = ats_count; - addr->ats = ats; -} - static void set_ats (struct GNUNET_ATS_Information *ats, uint32_t type, uint32_t value) { @@ -85,87 +74,6 @@ set_ats (struct GNUNET_ATS_Information *ats, uint32_t type, uint32_t value) ats->value = value; } - -unsigned int -load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long *out_dest, unsigned long long *in_dest, int dest_length) -{ - int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; - char * entry_in = NULL; - char * entry_out = NULL; - char * quota_out_str; - char * quota_in_str; - int c; - - for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++) - { - in_dest[c] = 0; - out_dest[c] = 0; - switch (quotas[c]) { - case GNUNET_ATS_NET_UNSPECIFIED: - entry_out = "UNSPECIFIED_QUOTA_OUT"; - entry_in = "UNSPECIFIED_QUOTA_IN"; - break; - case GNUNET_ATS_NET_LOOPBACK: - entry_out = "LOOPBACK_QUOTA_OUT"; - entry_in = "LOOPBACK_QUOTA_IN"; - break; - case GNUNET_ATS_NET_LAN: - entry_out = "LAN_QUOTA_OUT"; - entry_in = "LAN_QUOTA_IN"; - break; - case GNUNET_ATS_NET_WAN: - entry_out = "WAN_QUOTA_OUT"; - entry_in = "WAN_QUOTA_IN"; - break; - case GNUNET_ATS_NET_WLAN: - entry_out = "WLAN_QUOTA_OUT"; - entry_in = "WLAN_QUOTA_IN"; - break; - default: - break; - } - - if ((entry_in == NULL) || (entry_out == NULL)) - continue; - - /* quota out */ - if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str)) - { - if (0 == strcmp(quota_out_str, BIG_M_STRING) || - (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c]))) - out_dest[c] = UINT32_MAX; - - GNUNET_free (quota_out_str); - quota_out_str = NULL; - } - else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c]) - out_dest[c] = UINT32_MAX; - else - out_dest[c] = UINT32_MAX; - - /* quota in */ - if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str)) - { - if (0 == strcmp(quota_in_str, BIG_M_STRING) || - (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c]))) - in_dest[c] = UINT32_MAX; - - GNUNET_free (quota_in_str); - quota_in_str = NULL; - } - else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c]) - { - in_dest[c] = UINT32_MAX; - } - else - { - in_dest[c] = UINT32_MAX; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded quota: %s %u, %s %u\n", entry_in, in_dest[c], entry_out, out_dest[c]); - - } - return GNUNET_ATS_NetworkTypeCount; -} #endif int addr_it (void *cls, @@ -196,7 +104,11 @@ end_now (int res) GNUNET_CONTAINER_multihashmap_destroy (addresses); addresses = NULL ; } - + if (NULL != address) + { + GNUNET_free (address); + address = NULL; + } ret = res; } @@ -238,7 +150,6 @@ check (void *cls, char *const *args, const char *cfgfile, } addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); - mlp = GAS_mlp_init (cfg, stats, quotas, quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount, &bandwidth_changed_cb, NULL); if (NULL == mlp) @@ -248,6 +159,26 @@ check (void *cls, char *const *args, const char *cfgfile, return; } + /* Create peer */ + if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p.hashPubKey)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); + end_now (1); + return; + } + + /* Create address */ + address = create_address (&p, "test_plugin", "test_addr", strlen("test_addr")+1, 0); + if (NULL == address) + { + GNUNET_break (0); + end_now (1); + return; + } + GNUNET_CONTAINER_multihashmap_put (addresses, &p.hashPubKey, address, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + + GAS_mlp_address_add (mlp, addresses, address); end_now (0); -- 2.25.1