From cb8d8079b402d69f1fa92ccdb5242e117493e174 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 21 May 2014 08:02:38 +0000 Subject: performance API indicates disconnect --- src/ats-tests/ats-testing.c | 2 + src/ats-tool/gnunet-ats.c | 96 ++++++++++++++++------ src/ats/ats_api_performance.c | 10 ++- src/ats/perf_ats_solver.c | 2 +- src/ats/test_ats_api_bandwidth_consumption.c | 2 +- src/ats/test_ats_api_performance_monitor.c | 4 + ..._ats_api_performance_monitor_initial_callback.c | 3 + src/ats/test_ats_solver_preferences.c | 3 + src/dv/gnunet-service-dv.c | 6 ++ src/fs/gnunet-service-fs.c | 6 ++ src/include/gnunet_ats_service.h | 10 ++- src/include/gnunet_nat_lib.h | 2 +- src/testbed/gnunet-daemon-latency-logger.c | 6 ++ 13 files changed, 118 insertions(+), 34 deletions(-) diff --git a/src/ats-tests/ats-testing.c b/src/ats-tests/ats-testing.c index 49c3c841b..6fda20311 100644 --- a/src/ats-tests/ats-testing.c +++ b/src/ats-tests/ats-testing.c @@ -556,6 +556,8 @@ ats_performance_info_cb (void *cls, int log; char *peer_id; + + p = find_partner (me, &address->peer); if (NULL == p) { diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c index 56f8a17ac..83b9739ff 100644 --- a/src/ats-tool/gnunet-ats.c +++ b/src/ats-tool/gnunet-ats.c @@ -288,14 +288,33 @@ find_address_it (void *cls, } static void -ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, +ats_perf_mon_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { - struct PendingResolutions * pr; + struct PendingResolutions *pr; + struct PendingResolutions *cur; + struct PendingResolutions *next; - if ((GNUNET_YES == op_monitor) && (GNUNET_NO == verbose)) + if (NULL == address) + { + /* ATS service temporarily disconnected, remove current state */ + next = head; + for (cur = next; NULL != cur; cur = next) + { + next = cur->next; + GNUNET_CONTAINER_DLL_remove (head, tail, cur); + GNUNET_TRANSPORT_address_to_string_cancel (cur->tats_ctx); + GNUNET_HELLO_address_free (cur->address); + GNUNET_free (cur); + } + + GNUNET_CONTAINER_multipeermap_iterate(addresses, &free_addr_it, NULL); + return; + } + + if (GNUNET_NO == verbose) { struct AddressFindCtx actx; @@ -316,7 +335,6 @@ ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, actx.res->bandwidth_out = bandwidth_out; } } - struct ATSAddress *a = GNUNET_new (struct ATSAddress); a->address = GNUNET_HELLO_address_copy(address); a->bandwidth_in = bandwidth_in; @@ -325,27 +343,35 @@ ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); } - if (NULL != address) - { - pr = GNUNET_malloc (sizeof (struct PendingResolutions) + - ats_count * sizeof (struct GNUNET_ATS_Information)); - - pr->ats_count = ats_count; - pr->ats = (struct GNUNET_ATS_Information *) &pr[1]; - if (ats_count > 0) - memcpy (pr->ats, ats, ats_count * sizeof(struct GNUNET_ATS_Information)); - pr->address = GNUNET_HELLO_address_copy (address); - pr->bandwidth_in = bandwidth_in; - pr->bandwidth_out = bandwidth_out; - pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (cfg, address, - resolve_addresses_numeric, - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), - transport_addr_to_str_cb, pr); - GNUNET_CONTAINER_DLL_insert(head, tail, pr); - results++; - pending++; - } - else + pr = GNUNET_malloc (sizeof (struct PendingResolutions) + + ats_count * sizeof (struct GNUNET_ATS_Information)); + + pr->ats_count = ats_count; + pr->ats = (struct GNUNET_ATS_Information *) &pr[1]; + if (ats_count > 0) + memcpy (pr->ats, ats, ats_count * sizeof(struct GNUNET_ATS_Information)); + pr->address = GNUNET_HELLO_address_copy (address); + pr->bandwidth_in = bandwidth_in; + pr->bandwidth_out = bandwidth_out; + pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (cfg, address, + resolve_addresses_numeric, + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), + transport_addr_to_str_cb, pr); + GNUNET_CONTAINER_DLL_insert (head, tail, pr); + results++; + pending++; +} + + +static void +ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) +{ + struct PendingResolutions * pr; + + if (NULL == address) { /* All messages received */ receive_done = GNUNET_YES; @@ -358,6 +384,24 @@ ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, end_task = GNUNET_SCHEDULER_add_now (end, NULL ); } } + + pr = GNUNET_malloc (sizeof (struct PendingResolutions) + + ats_count * sizeof (struct GNUNET_ATS_Information)); + + pr->ats_count = ats_count; + pr->ats = (struct GNUNET_ATS_Information *) &pr[1]; + if (ats_count > 0) + memcpy (pr->ats, ats, ats_count * sizeof(struct GNUNET_ATS_Information)); + pr->address = GNUNET_HELLO_address_copy (address); + pr->bandwidth_in = bandwidth_in; + pr->bandwidth_out = bandwidth_out; + pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (cfg, address, + resolve_addresses_numeric, + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), + transport_addr_to_str_cb, pr); + GNUNET_CONTAINER_DLL_insert(head, tail, pr); + results++; + pending++; } static unsigned int @@ -510,7 +554,7 @@ testservice_ats(void *cls, int result) } else if (op_monitor) { - ph = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL ); + ph = GNUNET_ATS_performance_init (cfg, &ats_perf_mon_cb, NULL ); if (NULL == ph) fprintf (stderr, _("Cannot connect to ATS service, exiting...\n") ); end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c index a1d8dc21a..35dcc558f 100644 --- a/src/ats/ats_api_performance.c +++ b/src/ats/ats_api_performance.c @@ -587,6 +587,7 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg) GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph, GNUNET_TIME_UNIT_FOREVER_REL); return; + reconnect: if (NULL != ph->th) { @@ -595,7 +596,14 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg) } GNUNET_CLIENT_disconnect (ph->client); ph->client = NULL; - /* FIXME: need to signal monitor that we were disconnected! */ + if (NULL != ph->addr_info_cb) + { + /* Indicate reconnect */ + ph->addr_info_cb (ph->addr_info_cb_cls, NULL, GNUNET_NO, + GNUNET_BANDWIDTH_value_init (0), + GNUNET_BANDWIDTH_value_init(0), + NULL, 0); + } ph->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task, ph); } diff --git a/src/ats/perf_ats_solver.c b/src/ats/perf_ats_solver.c index a5307028d..4e1e68c23 100644 --- a/src/ats/perf_ats_solver.c +++ b/src/ats/perf_ats_solver.c @@ -27,7 +27,7 @@ #include "gnunet_util_lib.h" #include "gnunet_statistics_service.h" #include "gnunet-service-ats_addresses.h" - +#include "gnunet-service-ats_normalization.h" #include "gnunet_ats_service.h" #include "gnunet_ats_plugin.h" #include "test_ats_api_common.h" diff --git a/src/ats/test_ats_api_bandwidth_consumption.c b/src/ats/test_ats_api_bandwidth_consumption.c index 493323657..b05a7cf22 100644 --- a/src/ats/test_ats_api_bandwidth_consumption.c +++ b/src/ats/test_ats_api_bandwidth_consumption.c @@ -192,7 +192,7 @@ run (void *cls, p = GNUNET_new (struct PeerContext); addr = GNUNET_new (struct Address); - atp = GNUNET_ATS_performance_init (cfg, &performance_cb, NULL); + atp = GNUNET_ATS_performance_init (cfg, NULL, NULL); if (atp == NULL) { ret = GNUNET_SYSERR; diff --git a/src/ats/test_ats_api_performance_monitor.c b/src/ats/test_ats_api_performance_monitor.c index 6ccac45d1..4b6b08b74 100644 --- a/src/ats/test_ats_api_performance_monitor.c +++ b/src/ats/test_ats_api_performance_monitor.c @@ -106,6 +106,10 @@ ats_perf_cb (void *cls, static int peer0 = GNUNET_NO; static int peer1 = GNUNET_NO; static int done = GNUNET_NO; + + if (NULL == address) + return; + if ((GNUNET_NO == peer0) && (0 == memcmp (address, &p[0].id, sizeof (p[0].id)))) { peer0 = GNUNET_YES; diff --git a/src/ats/test_ats_api_performance_monitor_initial_callback.c b/src/ats/test_ats_api_performance_monitor_initial_callback.c index 6d305d3a5..377686673 100644 --- a/src/ats/test_ats_api_performance_monitor_initial_callback.c +++ b/src/ats/test_ats_api_performance_monitor_initial_callback.c @@ -107,6 +107,9 @@ ats_perf_cb (void *cls, static int peer1 = GNUNET_NO; static int done = GNUNET_NO; + if (NULL == address) + return; + if (0 == memcmp (&address->peer, &p[0].id, sizeof (p[0].id))) { peer0 ++; diff --git a/src/ats/test_ats_solver_preferences.c b/src/ats/test_ats_solver_preferences.c index 117af470b..4de3d9a5b 100644 --- a/src/ats/test_ats_solver_preferences.c +++ b/src/ats/test_ats_solver_preferences.c @@ -145,6 +145,9 @@ perf_info_cb (void *cls, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { + if (NULL == address) + return; + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "ATS performance info: `%s'\n", GNUNET_i2s (&address->peer)); } diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index a3d6e4942..67db7072b 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c @@ -1321,6 +1321,12 @@ handle_ats_update (void *cls, uint32_t distance; enum GNUNET_ATS_Network_Type network = GNUNET_ATS_NET_UNSPECIFIED; + if (NULL == address) + { + /* ATS service temporarily disconnected */ + return; + } + if (GNUNET_NO == active) return; distance = get_atsi_distance (ats, ats_count); diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 59786bae8..fd776e7b8 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -254,6 +254,12 @@ update_latencies (void *cls, unsigned int i; struct GNUNET_TIME_Relative latency; + if (NULL == address) + { + /* ATS service temporarily disconnected */ + return; + } + if (GNUNET_YES != active) return; for (i = 0; i < ats_count; i++) diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index 0268391cd..eeb9eec38 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h @@ -756,9 +756,9 @@ struct GNUNET_ATS_PerformanceHandle; * Signature of a function that is called with QoS information about an address. * * @param cls closure - * @param address the address + * @param address the address, NULL if ATS service was disconnected * @param address_active is this address actively used to maintain a connection - * to a peer + to a peer * @param bandwidth_out assigned outbound bandwidth for the connection * @param bandwidth_in assigned inbound bandwidth for the connection * @param ats performance data for the address (as far as known) @@ -766,10 +766,12 @@ struct GNUNET_ATS_PerformanceHandle; */ typedef void (*GNUNET_ATS_AddressInformationCallback) (void *cls, - const struct GNUNET_HELLO_Address *address, int address_active, + const struct GNUNET_HELLO_Address *address, + int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct GNUNET_ATS_Information *ats, uint32_t ats_count); + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count); /** * Handle for an address listing operation diff --git a/src/include/gnunet_nat_lib.h b/src/include/gnunet_nat_lib.h index f81fe485a..7509bb64d 100644 --- a/src/include/gnunet_nat_lib.h +++ b/src/include/gnunet_nat_lib.h @@ -297,7 +297,7 @@ struct GNUNET_NAT_MiniHandle; * * @param cls closure * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean - * the previous (now invalid) one + * the previous (now invalid) one, #GNUNET_SYSERR indicates an error * @param addr either the previous or the new public IP address * @param addrlen actual length of the @a addr * @param result GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code diff --git a/src/testbed/gnunet-daemon-latency-logger.c b/src/testbed/gnunet-daemon-latency-logger.c index bac89deee..774b5dd4d 100644 --- a/src/testbed/gnunet-daemon-latency-logger.c +++ b/src/testbed/gnunet-daemon-latency-logger.c @@ -190,6 +190,12 @@ addr_info_cb (void *cls, int latency; unsigned int cnt; + if (NULL == address) + { + /* ATS service temporarily disconnected */ + return; + } + GNUNET_assert (NULL != db); if (GNUNET_NO == address_active) return; -- cgit v1.2.3