aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-10-14 13:05:32 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-10-14 13:05:32 +0000
commitdde8ff327461c6eb62df698c1f059552f1a57505 (patch)
tree45a51e20de52dd92d1ab64f83622ff3823c601a7
parent02219049255a8612969794f661f3cd576014dc9b (diff)
-rw-r--r--src/ats/gnunet-service-ats_addresses.c34
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c2
-rw-r--r--src/ats/test_ats_api.conf1
-rw-r--r--src/ats/test_ats_api_scheduling.c52
4 files changed, 57 insertions, 32 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index 8a79889f3f..213b431245 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -77,8 +77,11 @@ compare_address_it (void *cls,
if (0 == strcmp(aa->plugin, cac->search->plugin))
{
- if ((aa->addr_len == cac->search->addr_len) &&
- (0 == memcmp (aa->addr, cac->search->addr, aa->addr_len)))
+ if (aa->addr_len != cac->search->addr_len)
+ return GNUNET_YES;
+ if (aa->addr_len == 0)
+ return GNUNET_YES;
+ if (0 == memcmp (aa->addr, cac->search->addr, aa->addr_len))
cac->result = aa;
return GNUNET_NO;
}
@@ -104,13 +107,17 @@ find_address (const struct GNUNET_PeerIdentity *peer,
static void
merge_ats (struct ATS_Address * dest, struct ATS_Address * source)
{
- /*
int c_src = 0;
int c_dest = 0;
struct GNUNET_TRANSPORT_ATS_Information * a_src = source->ats;
struct GNUNET_TRANSPORT_ATS_Information * a_dest = dest->ats;
+ struct ATS_Address * bigger = NULL;
- int new_entries = dest->ats_count;
+ bigger = (dest->ats_count > source->ats_count) ? dest : source;
+ int new_entries = bigger->ats_count;
+
+ if (new_entries == 0)
+ return;
for (c_dest = 0; c_dest < dest->ats_count; c_dest ++)
{
@@ -122,9 +129,8 @@ merge_ats (struct ATS_Address * dest, struct ATS_Address * source)
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Have %u new entries\n",
+ "Have %u entries to update and %u new entries\n",bigger->ats_count,
new_entries);
-*/
}
void
@@ -139,8 +145,7 @@ GAS_address_update (const struct GNUNET_PeerIdentity *peer,
struct ATS_Address * aa;
struct ATS_Address * old;
- aa = GNUNET_malloc (sizeof (struct ATS_Address) +
- plugin_addr_len);
+ aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len);
aa->ats = GNUNET_malloc(atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
aa->peer = *peer;
@@ -148,7 +153,7 @@ GAS_address_update (const struct GNUNET_PeerIdentity *peer,
aa->ats_count = atsi_count;
memcpy (aa->ats, atsi, atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
aa->addr = &aa[1];
- memcpy (&aa->addr, plugin_addr, plugin_addr_len);
+ memcpy (aa->addr, plugin_addr, plugin_addr_len);
aa->plugin = GNUNET_strdup (plugin_name);
aa->session_client = session_client;
aa->session_id = session_id;
@@ -172,6 +177,7 @@ GAS_address_update (const struct GNUNET_PeerIdentity *peer,
"Updated existing address for peer `%s' %X \n",
GNUNET_i2s (peer), old);
GNUNET_free (aa->ats);
+ GNUNET_free (aa->plugin);
GNUNET_free (aa);
}
@@ -201,9 +207,13 @@ GAS_address_destroyed (const struct GNUNET_PeerIdentity *peer,
aa->session_id = session_id;
res = find_address (peer, aa);
+ GNUNET_assert (res != 0);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Deleting address for peer `%s'\n",
+ GNUNET_i2s (peer));
- GNUNET_break (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove(addresses, &peer->hashPubKey, res));
+ GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(addresses, &peer->hashPubKey, res));
GNUNET_free (res->plugin);
GNUNET_free_non_null (res->ats);
GNUNET_free (res);
@@ -248,6 +258,8 @@ free_address_it (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Freeing address for peer `%s' %X\n",
GNUNET_i2s (&aa->peer), aa);
+ GNUNET_free (aa->plugin);
+ GNUNET_free_non_null (aa->ats);
GNUNET_free (aa);
return GNUNET_OK;
}
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index 76c192107f..066096bc23 100644
--- a/src/ats/gnunet-service-ats_scheduling.c
+++ b/src/ats/gnunet-service-ats_scheduling.c
@@ -317,7 +317,7 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
plugin_name = &address[address_length];
if ( (address_length +
plugin_name_length +
- sizeof (struct AddressSuggestionMessage) != ntohs (message->size)) ||
+ sizeof (struct AddressDestroyedMessage) != ntohs (message->size)) ||
(plugin_name[plugin_name_length - 1] != '\0') )
{
GNUNET_break (0);
diff --git a/src/ats/test_ats_api.conf b/src/ats/test_ats_api.conf
index c2bb1942d2..79e92af496 100644
--- a/src/ats/test_ats_api.conf
+++ b/src/ats/test_ats_api.conf
@@ -8,6 +8,7 @@ UNIXPATH = /tmp/test-ats-scheduling-arm.sock
[ats]
DEBUG = YES
+#PREFIX = valgrind --leak-check=full
AUTOSTART = YES
PORT = 12002
HOSTNAME = localhost
diff --git a/src/ats/test_ats_api_scheduling.c b/src/ats/test_ats_api_scheduling.c
index 4ed68ba879..efc2523805 100644
--- a/src/ats/test_ats_api_scheduling.c
+++ b/src/ats/test_ats_api_scheduling.c
@@ -46,9 +46,7 @@ static struct GNUNET_ATS_SchedulingHandle *ats;
struct GNUNET_OS_Process * arm_proc;
-struct Address addr;
-struct PeerContext p;
-struct GNUNET_TRANSPORT_ATS_Information atsi[2];
+
static int ret;
@@ -73,6 +71,9 @@ struct PeerContext
struct Address * addr;
};
+struct Address addr[2];
+struct PeerContext p[2];
+struct GNUNET_TRANSPORT_ATS_Information atsi[2];
static void
stop_arm ()
@@ -139,11 +140,11 @@ address_suggest_cb (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address `%s'\n", GNUNET_i2s (peer));
- GNUNET_assert (0 == memcmp (peer, &p.id, sizeof (struct GNUNET_PeerIdentity)));
- GNUNET_assert (0 == strcmp (plugin_name, addr.plugin));
- GNUNET_assert (plugin_addr_len == addr.addr_len);
- GNUNET_assert (0 == memcmp (plugin_addr, addr.plugin, plugin_addr_len));
- GNUNET_assert (addr.session == session);
+ GNUNET_assert (0 == memcmp (peer, &p[0].id, sizeof (struct GNUNET_PeerIdentity)));
+ GNUNET_assert (0 == strcmp (plugin_name, addr[0].plugin));
+ GNUNET_assert (plugin_addr_len == addr[0].addr_len);
+ GNUNET_assert (0 == memcmp (plugin_addr, addr[0].plugin, plugin_addr_len));
+ GNUNET_assert (addr[0].session == session);
/* TODO ats merge
@@ -189,22 +190,29 @@ check (void *cls, char *const *args, const char *cfgfile,
}
/* set up peer */
- GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p.id.hashPubKey);
+ GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[0].id.hashPubKey);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p[0].id));
+
+ GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[1].id.hashPubKey);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p[1].id));
+ addr[0].plugin = "test";
+ addr[0].session = NULL;
+ addr[0].addr = strdup("test");
+ addr[0].addr_len = 4;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p.id));
- p.addr = &addr;
- addr.plugin = "test";
- addr.session = NULL;
- addr.addr = NULL;
- addr.addr_len = 0;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing address creation\n");
- GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, NULL, 0);
+ GNUNET_ATS_address_update(ats, &p[0].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, NULL, 0);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info creation\n");
atsi[0].type = htons (1);
atsi[0].type = htons (1);
- GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, atsi, 1);
+ GNUNET_ATS_address_update(ats, &p[0].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, atsi, 1);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info merging\n");
atsi[0].type = htons (1);
atsi[0].type = htons (2);
@@ -212,10 +220,14 @@ check (void *cls, char *const *args, const char *cfgfile,
atsi[1].type = htons (2);
atsi[1].type = htons (2);
- GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, atsi, 2);
+ GNUNET_ATS_address_update(ats, &p[0].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, atsi, 2);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing manual address deletion \n");
+ GNUNET_ATS_address_update(ats, &p[1].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session, NULL, 0);
+ GNUNET_ATS_address_destroyed (ats, &p[1].id, addr[0].plugin, addr[0].addr, addr[0].addr_len, addr[0].session );
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n", GNUNET_i2s (&p.id));
- GNUNET_ATS_suggest_address(ats, &p.id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n", GNUNET_i2s (&p[0].id));
+ GNUNET_ATS_suggest_address(ats, &p[0].id);
}
int