*/
#include "test_ats_api_common.h"
+#define BIG_M_STRING "unlimited"
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
-
-#define PEERID0 "2AK99KD8RM9UA9LC3QKA0IQ5UBFC0FBB50EBGCFQT8448DGGACNAC4CJQDD1CPFS494O41U88DJD1FLIG8VA5CQR9IN4L96GP104MVO"
-#define PEERID1 "5ED7I0AR3MSTAL7FQN04S22E0EQ3CR9RLASCDLVMM1BNFPUPTCT46DLKNJ4DACASJ6U0DR5J8S3R2UJL49682JS7MOVRAB8P8A4PJH0"
void
create_test_address (struct Test_Address *dest, char * plugin, void *session, void *addr, size_t addrlen)
void
free_test_address (struct Test_Address *dest)
{
- GNUNET_free (dest->plugin);
- if (NULL != dest->addr)
- GNUNET_free (dest->addr);
+ GNUNET_free_non_null (dest->plugin);
+ dest->plugin = NULL;
+ GNUNET_free_non_null (dest->addr);
+ dest->addr = NULL;
}
int
}
if (address1->address_length != address2->address_length)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address length'\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address length\n");
return GNUNET_SYSERR;
}
else if (0 != memcmp (address1->address, address2->address, address2->address_length))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address'\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address\n");
return GNUNET_SYSERR;
}
if (session1 != session2)
}
+/**
+ * Load quotas for networks from configuration
+ *
+ * @param cfg configuration handle
+ * @param out_dest where to write outbound quotas
+ * @param in_dest where to write inbound quotas
+ * @param dest_length length of inbound and outbound arrays
+ * @return number of networks loaded
+ */
+unsigned int
+load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ unsigned long long *out_dest,
+ unsigned long long *in_dest,
+ int dest_length)
+{
+ char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
+ char * entry_in = NULL;
+ char * entry_out = NULL;
+ char * quota_out_str;
+ char * quota_in_str;
+ int c;
+ int res;
+
+ for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
+ {
+ in_dest[c] = 0;
+ out_dest[c] = 0;
+ GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]);
+ GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]);
+
+ /* quota out */
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
+ {
+ res = GNUNET_NO;
+ if (0 == strcmp(quota_out_str, BIG_M_STRING))
+ {
+ out_dest[c] = GNUNET_ATS_MaxBandwidth;
+ res = GNUNET_YES;
+ }
+ if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
+ res = GNUNET_YES;
+ if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
+ res = GNUNET_YES;
+
+ if (GNUNET_NO == res)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
+ network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth);
+ out_dest[c] = GNUNET_ATS_DefaultBandwidth;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Outbound quota configure for network `%s' is %llu\n"),
+ network_str[c], out_dest[c]);
+ }
+ GNUNET_free (quota_out_str);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
+ network_str[c], GNUNET_ATS_DefaultBandwidth);
+ out_dest[c] = GNUNET_ATS_DefaultBandwidth;
+ }
+
+ /* quota in */
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
+ {
+ res = GNUNET_NO;
+ if (0 == strcmp(quota_in_str, BIG_M_STRING))
+ {
+ in_dest[c] = GNUNET_ATS_MaxBandwidth;
+ res = GNUNET_YES;
+ }
+ if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
+ res = GNUNET_YES;
+ if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
+ res = GNUNET_YES;
+
+ if (GNUNET_NO == res)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
+ network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth);
+ in_dest[c] = GNUNET_ATS_DefaultBandwidth;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Inbound quota configured for network `%s' is %llu\n"),
+ network_str[c], in_dest[c]);
+ }
+ GNUNET_free (quota_in_str);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
+ network_str[c], GNUNET_ATS_DefaultBandwidth);
+ out_dest[c] = GNUNET_ATS_DefaultBandwidth;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded quota for network `%s' (in/out): %llu %llu\n", network_str[c], in_dest[c], out_dest[c]);
+ GNUNET_free (entry_out);
+ GNUNET_free (entry_in);
+ }
+ 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 */