diff options
author | wachs <wachs@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-05-22 09:57:18 +0000 |
---|---|---|
committer | wachs <wachs@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-05-22 09:57:18 +0000 |
commit | 35889794d0b2be3eda04f4d6f7fb6002bfbab5f7 (patch) | |
tree | 0b1accdbb672fe5c36af033f59a955c910e41a86 | |
parent | baad221b508bc8490075367da7187f18873b3dcb (diff) |
- suggest backoff reset
git-svn-id: https://gnunet.org/svn/gnunet@21558 140774ce-b5e7-0310-ab8b-a85725594a96
-rw-r--r-- | src/ats/Makefile.am | 7 | ||||
-rw-r--r-- | src/ats/ats.h | 9 | ||||
-rw-r--r-- | src/ats/ats_api_scheduling.c | 26 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats.c | 3 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 24 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.h | 3 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_scheduling.c | 24 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_scheduling.h | 13 | ||||
-rw-r--r-- | src/ats/test_ats_api_reset_backoff.c | 316 | ||||
-rw-r--r-- | src/include/gnunet_ats_service.h | 11 | ||||
-rw-r--r-- | src/include/gnunet_protocols.h | 6 |
11 files changed, 441 insertions, 1 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index d8c7e86884..91d25a2746 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am @@ -54,6 +54,7 @@ gnunet_service_ats_LDADD = \ check_PROGRAMS = \ test_ats_api_scheduling \ + test_ats_api_reset_backoff \ $(GN_MLP_TEST) \ $(GN_MLP_TEST_AVG) \ $(GN_MLP_PERF) @@ -96,6 +97,12 @@ test_ats_api_scheduling_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/ats/libgnunetats.la +test_ats_api_reset_backoff_SOURCES = \ + test_ats_api_reset_backoff.c +test_ats_api_reset_backoff_LDADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/ats/libgnunetats.la + #test_ats_api_scheduling_get_type_SOURCES = \ # test_ats_api_scheduling_get_type.c #test_ats_api_scheduling_get_type_LDADD = \ diff --git a/src/ats/ats.h b/src/ats/ats.h index 30ca295804..f4c3d9fbac 100644 --- a/src/ats/ats.h +++ b/src/ats/ats.h @@ -61,6 +61,15 @@ struct RequestAddressMessage struct GNUNET_PeerIdentity peer; }; +struct ResetBackoffMessage +{ + struct GNUNET_MessageHeader header; + + uint32_t reserved GNUNET_PACKED; + + struct GNUNET_PeerIdentity peer; +}; + struct AddressUpdateMessage { diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index 3c98b238ce..583ada8f7e 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c @@ -918,6 +918,32 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh) sh = NULL; } +/** + * We would like to reset the address suggestion block time for this + * peer + * + * @param sh handle + * @param peer identity of the peer we want to reset + */ +void +GNUNET_ATS_reset_backoff (struct GNUNET_ATS_SchedulingHandle *sh, + const struct GNUNET_PeerIdentity *peer) +{ + struct PendingMessage *p; + struct ResetBackoffMessage *m; + + p = GNUNET_malloc (sizeof (struct PendingMessage) + + sizeof (struct ResetBackoffMessage)); + p->size = sizeof (struct ResetBackoffMessage); + p->is_init = GNUNET_NO; + m = (struct ResetBackoffMessage *) &p[1]; + m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESET_BACKOFF); + m->header.size = htons (sizeof (struct ResetBackoffMessage)); + m->reserved = htonl (0); + m->peer = *peer; + GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p); + do_transmit (sh); +} /** * We would like to establish a new connection with a peer. ATS diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index 2f1dc95e86..aef72f171f 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c @@ -153,6 +153,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, sizeof (struct ReservationRequestMessage)}, {&GAS_handle_preference_change, NULL, GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0}, + {&GAS_handle_reset_backoff, NULL, + GNUNET_MESSAGE_TYPE_ATS_RESET_BACKOFF, + sizeof (struct ResetBackoffMessage)}, {NULL, NULL, 0, 0} }; GSA_server = server; diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 096a983149..7f96edcac7 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -743,6 +743,30 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) } +static int +reset_address_it (void *cls, const GNUNET_HashCode * key, void *value) +{ + struct ATS_Address *aa = value; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Resetting interval for peer `%s' address %p from %llu to 0\n", GNUNET_i2s (&aa->peer), aa, aa->block_interval); + + aa->blocked_until = GNUNET_TIME_absolute_get_zero(); + aa->block_interval = GNUNET_TIME_relative_get_zero(); + return GNUNET_OK; +} + +void +GAS_addresses_handle_backoff_reset (const struct GNUNET_PeerIdentity *peer) +{ + GNUNET_break (GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_get_multiple (addresses, + &peer->hashPubKey, + &reset_address_it, + NULL)); +} + + + // FIXME: this function should likely end up in the LP-subsystem and // not with 'addresses' in the future... void diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index fbe1fc994f..fe07563ac7 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h @@ -112,6 +112,9 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, void GAS_addresses_done (void); +void +GAS_addresses_handle_backoff_reset (const struct GNUNET_PeerIdentity *peer); + /** * This address is now used or not used anymore */ diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c index 5d03ff0075..0b66ac5668 100644 --- a/src/ats/gnunet-service-ats_scheduling.c +++ b/src/ats/gnunet-service-ats_scheduling.c @@ -198,6 +198,30 @@ GAS_handle_request_address_cancel (void *cls, GNUNET_SERVER_receive_done (client, GNUNET_OK); } +/** + * Handle 'reset backoff' messages from clients. + * + * @param cls unused, NULL + * @param client client that sent the request + * @param message the request message + */ +void +GAS_handle_reset_backoff (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + const struct ResetBackoffMessage *msg = + (const struct ResetBackoffMessage *) message; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", + "RESET_BACKOFF"); + GNUNET_STATISTICS_update (GSA_stats, "# backoff reset requests received", 1, + GNUNET_NO); + GNUNET_break (0 == ntohl (msg->reserved)); + GAS_addresses_handle_backoff_reset (&msg->peer); + GNUNET_SERVER_receive_done (client, GNUNET_OK); +} + /** * Handle 'address update' messages from clients. diff --git a/src/ats/gnunet-service-ats_scheduling.h b/src/ats/gnunet-service-ats_scheduling.h index 45fca2f3d9..08a7f1b330 100644 --- a/src/ats/gnunet-service-ats_scheduling.h +++ b/src/ats/gnunet-service-ats_scheduling.h @@ -51,6 +51,19 @@ GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client); /** + * Handle 'reset backoff' messages from clients. + * + * @param cls unused, NULL + * @param client client that sent the request + * @param message the request message + */ +void +GAS_handle_reset_backoff (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message); + + +/** * Transmit the given address suggestion and bandwidth update to all scheduling * clients. * diff --git a/src/ats/test_ats_api_reset_backoff.c b/src/ats/test_ats_api_reset_backoff.c new file mode 100644 index 0000000000..90d9e7f837 --- /dev/null +++ b/src/ats/test_ats_api_reset_backoff.c @@ -0,0 +1,316 @@ +/* + This file is part of GNUnet. + (C) 2010,2011 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file ats/test_ats_api_reset_backoff.c + * @brief test case for block reset api + * @author Christian Grothoff + * @author Matthias Wachs + */ +#include "platform.h" +#include "gnunet_ats_service.h" +#include "ats.h" + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) +#define ATS_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) + +static GNUNET_SCHEDULER_TaskIdentifier die_task; + +static GNUNET_SCHEDULER_TaskIdentifier suggest_timeout_task; + +static struct GNUNET_ATS_SchedulingHandle *ats; + +struct GNUNET_OS_Process *arm_proc; + +static int ret; + +struct Address +{ + char *plugin; + size_t plugin_len; + + void *addr; + size_t addr_len; + + struct GNUNET_ATS_Information *ats; + int ats_count; + + void *session; +}; + +struct PeerContext +{ + struct GNUNET_PeerIdentity id; + + struct Address *addr; +}; + +struct GNUNET_HELLO_Address hello_addr; +struct Address address; +struct PeerContext peer; +struct GNUNET_ATS_Information atsi[2]; + +static void +stop_arm () +{ + if (0 != GNUNET_OS_process_kill (arm_proc, SIGTERM)) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); + GNUNET_OS_process_wait (arm_proc); + GNUNET_OS_process_destroy (arm_proc); + arm_proc = NULL; +} + + +static void +end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + die_task = GNUNET_SCHEDULER_NO_TASK; + + if (suggest_timeout_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (suggest_timeout_task); + suggest_timeout_task = GNUNET_SCHEDULER_NO_TASK; + } + + if (ats != NULL) + { + GNUNET_ATS_scheduling_done (ats); + ats = NULL; + } + + ret = GNUNET_SYSERR; + + stop_arm (); +} + + +static void +end () +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); + if (die_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (die_task); + die_task = GNUNET_SCHEDULER_NO_TASK; + } + + if (suggest_timeout_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (suggest_timeout_task); + suggest_timeout_task = GNUNET_SCHEDULER_NO_TASK; + } + + GNUNET_ATS_scheduling_done (ats); + + ret = 0; + + stop_arm (); +} + + +static void +suggest_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + suggest_timeout_task = GNUNET_SCHEDULER_NO_TASK; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting address for peer timed out\n"); +} + +static void request_address () +{ + + if (suggest_timeout_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (suggest_timeout_task); + suggest_timeout_task = GNUNET_SCHEDULER_NO_TASK; + } + + suggest_timeout_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, &suggest_timeout, NULL); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting address for peer `%s'\n", + GNUNET_i2s (&peer.id)); + GNUNET_ATS_suggest_address (ats, &peer.id); +} + + +static void +address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *a, + struct Session *session, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + const struct GNUNET_ATS_Information *atsi, + uint32_t ats_count) +{ + static int suggestions; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address `%s'\n", + GNUNET_i2s (&a->peer)); + + if (0 != memcmp (&a->peer, &peer.id, + sizeof (struct GNUNET_PeerIdentity))) + { + GNUNET_break (0); + if (die_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (die_task); + die_task = GNUNET_SCHEDULER_NO_TASK; + } + GNUNET_SCHEDULER_add_now (&end_badly, NULL); + return; + } + + if (0 != strcmp (a->transport_name, address.plugin)) + { + GNUNET_break (0); + if (die_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (die_task); + die_task = GNUNET_SCHEDULER_NO_TASK; + } + GNUNET_SCHEDULER_add_now (&end_badly, NULL); + return; + } + + if (a->address_length != address.addr_len) + { + GNUNET_break (0); + if (die_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (die_task); + die_task = GNUNET_SCHEDULER_NO_TASK; + } + GNUNET_SCHEDULER_add_now (&end_badly, NULL); + return; + } + + if (0 != memcmp (a->address, address.addr, + a->address_length)) + { + GNUNET_break (0); + if (die_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (die_task); + die_task = GNUNET_SCHEDULER_NO_TASK; + } + GNUNET_SCHEDULER_add_now (&end_badly, NULL); + return; + } + + if (session != address.session) + { + GNUNET_break (0); + if (die_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (die_task); + die_task = GNUNET_SCHEDULER_NO_TASK; + } + GNUNET_SCHEDULER_add_now (&end_badly, NULL); + return; + } + + suggestions ++; + + if (2 == suggestions) + { + GNUNET_SCHEDULER_add_now(&end, NULL); + return; + } + + if (suggest_timeout_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (suggest_timeout_task); + suggest_timeout_task = GNUNET_SCHEDULER_NO_TASK; + } + + GNUNET_ATS_reset_backoff(ats, &a->peer); + request_address (); +} + + + + +void +start_arm (const char *cfgname) +{ + arm_proc = + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", + "gnunet-service-arm", + "-c", cfgname, NULL); +} + +static void +check (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + ret = GNUNET_SYSERR; + + die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); + start_arm (cfgfile); + + ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); + + if (ats == NULL) + { + ret = GNUNET_SYSERR; + end (); + return; + } + + /* set up peer */ + GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, + &peer.id.hashPubKey); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&peer.id)); + + address.plugin = "test"; + address.session = NULL; + address.addr = GNUNET_strdup ("test"); + address.addr_len = 4; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding address\n"); + + hello_addr.peer = peer.id; + hello_addr.transport_name = address.plugin; + hello_addr.address = address.addr; + hello_addr.address_length = address.addr_len; + GNUNET_ATS_address_update (ats, &hello_addr, address.session, NULL, 0); + + request_address (); +} + +int +main (int argc, char *argv[]) +{ + static char *const argv2[] = { "test_ats_api_scheduling", + "-c", + "test_ats_api.conf", + "-L", "WARNING", + NULL + }; + + static struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_OPTION_END + }; + + GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, + "test_ats_api_scheduling", "nohelp", options, &check, + NULL); + + + return ret; +} +/* end of file test_ats_api_reset_backoff.c */ diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index 0ee3d55350..a5f1bdc23c 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h @@ -523,6 +523,17 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh); /** + * We would like to reset the address suggestion block time for this + * peer + * + * @param sh handle + * @param peer identity of the peer we want to reset + */ +void +GNUNET_ATS_reset_backoff (struct GNUNET_ATS_SchedulingHandle *sh, + const struct GNUNET_PeerIdentity *peer); + +/** * We would like to establish a new connection with a peer. ATS * should suggest a good address to begin with. * diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 2ec2baea65..b655f08969 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -1028,7 +1028,11 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE 351 - +/** + * Type of the 'struct AddressUseMessage' sent by ATS to client + * to confirm that an address is used or not used anymore + */ +#define GNUNET_MESSAGE_TYPE_ATS_RESET_BACKOFF 352 /******************************************************************************* |