[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r19277 - gnunet/src/ats
From: |
gnunet |
Subject: |
[GNUnet-SVN] r19277 - gnunet/src/ats |
Date: |
Fri, 20 Jan 2012 10:57:39 +0100 |
Author: wachs
Date: 2012-01-20 10:57:39 +0100 (Fri, 20 Jan 2012)
New Revision: 19277
Modified:
gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
gnunet/src/ats/test_ats_mlp.c
Log:
- more code
Modified: gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_mlp.c 2012-01-20 08:35:39 UTC
(rev 19276)
+++ gnunet/src/ats/gnunet-service-ats_addresses_mlp.c 2012-01-20 09:57:39 UTC
(rev 19277)
@@ -148,6 +148,52 @@
}
/**
+ * Translate ATS properties to text
+ * Just intended for debugging
+ *
+ * @param retcode return code
+ * @return string with result
+ */
+const char *
+mlp_ats_to_string (int ats_index)
+{
+ switch (ats_index) {
+ case GNUNET_ATS_ARRAY_TERMINATOR:
+ return "GNUNET_ATS_ARRAY_TERMINATOR";
+ break;
+ case GNUNET_ATS_UTILIZATION_UP:
+ return "GNUNET_ATS_UTILIZATION_UP";
+ break;
+ case GNUNET_ATS_UTILIZATION_DOWN:
+ return "GNUNET_ATS_UTILIZATION_DOWN";
+ break;
+ case GNUNET_ATS_COST_LAN:
+ return "GNUNET_ATS_COST_LAN";
+ break;
+ case GNUNET_ATS_COST_WAN:
+ return "GNUNET_ATS_COST_LAN";
+ break;
+ case GNUNET_ATS_COST_WLAN:
+ return "GNUNET_ATS_COST_WLAN";
+ break;
+ case GNUNET_ATS_NETWORK_TYPE:
+ return "GNUNET_ATS_NETWORK_TYPE";
+ break;
+ case GNUNET_ATS_QUALITY_NET_DELAY:
+ return "GNUNET_ATS_QUALITY_NET_DELAY";
+ break;
+ case GNUNET_ATS_QUALITY_NET_DISTANCE:
+ return "GNUNET_ATS_QUALITY_NET_DISTANCE";
+ break;
+ default:
+ return "unknown";
+ break;
+ }
+ GNUNET_break (0);
+ return "unknown error";
+}
+
+/**
* Find a peer in the DLL
* @param the peer to find
* @return the peer struct
@@ -302,7 +348,35 @@
return GNUNET_OK;
}
+/**
+ * Find the required ATS information for an address
+ *
+ * @param addr the address
+ * @param ats_index the desired ATS index
+ *
+ * @return the index on success, otherwise GNUNET_SYSERR
+ */
+static int
+mlp_lookup_ats (struct ATS_Address *addr, int ats_index)
+{
+ struct GNUNET_ATS_Information * ats = addr->ats;
+ int c;
+ int found = GNUNET_NO;
+ for (c = 0; c < addr->ats_count; c++)
+ {
+ if (ats[c].type == ats_index)
+ {
+ found = GNUNET_YES;
+ break;
+ }
+ }
+ if (found == GNUNET_YES)
+ return c;
+ else
+ return GNUNET_SYSERR;
+}
+
/**
* Adds the problem constraints for all addresses
* Required for problem recreation after address deletion
@@ -519,6 +593,21 @@
while (addr != NULL)
{
+ /* lookup ATS information */
+ int index = mlp_lookup_ats(addr, mlp->q[c]);
+
+ if (index != GNUNET_SYSERR)
+ {
+ value = (double) addr->ats[index].value;
+#if DEBUG_ATS
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Quality %i with ATS property
`%s' has index %i in addresses ats information has value %f\n", c,
mlp_ats_to_string(mlp->q[c]), index, (double) addr->ats[index].value);
+#endif
+ }
+#if DEBUG_ATS
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Quality %i with ATS property
`%s' not existing\n", c, mlp_ats_to_string(mlp->q[c]), index);
+#endif
+
mlpi = addr->mlp_information;
ia[mlp->ci] = mlp->r_q[c];
ja[mlp->ci] = mlpi->c_b;
Modified: gnunet/src/ats/test_ats_mlp.c
===================================================================
--- gnunet/src/ats/test_ats_mlp.c 2012-01-20 08:35:39 UTC (rev 19276)
+++ gnunet/src/ats/test_ats_mlp.c 2012-01-20 09:57:39 UTC (rev 19277)
@@ -27,6 +27,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_statistics_service.h"
+#include "gnunet_ats_service.h"
#include "gnunet-service-ats_addresses_mlp.h"
#define VERBOSE GNUNET_YES
@@ -45,6 +46,24 @@
struct GAS_MLP_Handle *mlp;
static void
+create_address (struct ATS_Address *addr, char * plugin, int ats_count, struct
GNUNET_ATS_Information *ats)
+{
+ addr->mlp_information = NULL;
+ addr->next = NULL;
+ addr->prev = NULL;
+ addr->plugin = 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)
+{
+ ats->type = type;
+ ats->value = value;
+}
+
+static void
check (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
@@ -59,17 +78,20 @@
addresses = GNUNET_CONTAINER_multihashmap_create (10);
+ /* Creating address 1 */
GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK,
&addr[0].peer.hashPubKey);
- addr[0].mlp_information = NULL;
- addr[0].next = NULL;
- addr[0].prev = NULL;
- addr[0].plugin = strdup ("dummy");
+ struct GNUNET_ATS_Information a1_ats[3];
+ set_ats (&a1_ats[0], GNUNET_ATS_QUALITY_NET_DISTANCE, 1);
+ set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 32);
+ set_ats (&a1_ats[2], GNUNET_ATS_ARRAY_TERMINATOR, 0);
+ create_address (&addr[0], "dummy", 3, &a1_ats[0]);
GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK,
&addr[1].peer.hashPubKey);
- addr[1].mlp_information = NULL;
- addr[1].next = NULL;
- addr[1].prev = NULL;
- addr[1].plugin = strdup ("dummy2");
+ struct GNUNET_ATS_Information a2_ats[3];
+ set_ats (&a2_ats[0], GNUNET_ATS_QUALITY_NET_DELAY, 32);
+ set_ats (&a2_ats[1], GNUNET_ATS_QUALITY_NET_DISTANCE, 1);
+ set_ats (&a2_ats[2], GNUNET_ATS_ARRAY_TERMINATOR, 0);
+ create_address (&addr[1], "dummy2", 3, &a2_ats[0]);
GNUNET_CONTAINER_multihashmap_put(addresses, &addr[0].peer.hashPubKey,
&addr[0], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r19277 - gnunet/src/ats,
gnunet <=