From: Christian Grothoff Date: Thu, 13 Oct 2011 20:54:17 +0000 (+0000) Subject: moving out addresses as well X-Git-Tag: initial-import-from-subversion-38251~16541 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=42f0a310ce2d0c9c2cd4b62e8da617d8bc9b8290;p=oweals%2Fgnunet.git moving out addresses as well --- diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 31d9ef4e6..2b13fa06a 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am @@ -23,6 +23,7 @@ bin_PROGRAMS = \ gnunet_service_ats_SOURCES = \ gnunet-service-ats.c \ + gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h gnunet_service_ats_LDADD = \ diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index aca877d7b..dff19abea 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c @@ -28,29 +28,9 @@ #include "gnunet_ats_service.h" #include "gnunet-service-ats_performance.h" #include "gnunet-service-ats_scheduling.h" -// #include "gnunet-service-ats_performance.h" +#include "gnunet-service-ats_addresses.h" #include "ats.h" -struct ATS_Address -{ - struct GNUNET_PeerIdentity peer; - - size_t addr_len; - - uint32_t session_id; - - uint32_t ats_count; - - void * addr; - - char * plugin; - - struct GNUNET_TRANSPORT_ATS_Information * ats; -}; - -static struct GNUNET_CONTAINER_MultiHashMap * addresses; - - static void handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client, @@ -80,42 +60,6 @@ handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client, } -struct CompareAddressContext -{ - struct ATS_Address * search; - struct ATS_Address * result; -}; - -int compare_address_it (void *cls, - const GNUNET_HashCode * key, - void *value) -{ - struct CompareAddressContext * cac = cls; - struct ATS_Address * aa = (struct ATS_Address *) value; - 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))) - cac->result = aa; - return GNUNET_NO; - } - return GNUNET_YES; -} - - -static int -free_address_it (void *cls, - const GNUNET_HashCode * key, - void *value) -{ - struct ATS_Address * aa = cls; - GNUNET_free (aa); - return GNUNET_OK; -} - - - - /** * Task run during shutdown. @@ -126,8 +70,7 @@ free_address_it (void *cls, static void cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - GNUNET_CONTAINER_multihashmap_iterate (addresses, &free_address_it, NULL); - GNUNET_CONTAINER_multihashmap_destroy (addresses); + GAS_addresses_done (); } @@ -157,7 +100,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0}, {NULL, NULL, 0, 0} }; - addresses = GNUNET_CONTAINER_multihashmap_create(128); + GAS_addresses_init (); GNUNET_SERVER_add_handlers (server, handlers); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, NULL); diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c new file mode 100644 index 000000000..ff83f4fd8 --- /dev/null +++ b/src/ats/gnunet-service-ats_addresses.c @@ -0,0 +1,102 @@ +/* + This file is part of GNUnet. + (C) 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/gnunet-service-ats_addresses.c + * @brief ats service address management + * @author Matthias Wachs + */ +#include "platform.h" +#include "gnunet-service-ats_addresses.h" + + +struct ATS_Address +{ + struct GNUNET_PeerIdentity peer; + + size_t addr_len; + + uint32_t session_id; + + uint32_t ats_count; + + void * addr; + + char * plugin; + + struct GNUNET_TRANSPORT_ATS_Information * ats; +}; + +static struct GNUNET_CONTAINER_MultiHashMap * addresses; + + +struct CompareAddressContext +{ + struct ATS_Address * search; + struct ATS_Address * result; +}; + +int compare_address_it (void *cls, + const GNUNET_HashCode * key, + void *value) +{ + struct CompareAddressContext * cac = cls; + struct ATS_Address * aa = (struct ATS_Address *) value; + 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))) + cac->result = aa; + return GNUNET_NO; + } + return GNUNET_YES; +} + + +static int +free_address_it (void *cls, + const GNUNET_HashCode * key, + void *value) +{ + struct ATS_Address * aa = cls; + GNUNET_free (aa); + return GNUNET_OK; +} + + +/** + */ +void +GAS_addresses_done () +{ + GNUNET_CONTAINER_multihashmap_iterate (addresses, &free_address_it, NULL); + GNUNET_CONTAINER_multihashmap_destroy (addresses); +} + + +/** + */ +void +GAS_addresses_init () +{ + addresses = GNUNET_CONTAINER_multihashmap_create(128); +} + +/* end of gnunet-service-ats_addresses.c */ diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h new file mode 100644 index 000000000..1bc6b65c2 --- /dev/null +++ b/src/ats/gnunet-service-ats_addresses.h @@ -0,0 +1,44 @@ +/* + This file is part of GNUnet. + (C) 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/gnunet-service-ats_addresses.c + * @brief ats service address management + * @author Matthias Wachs + */ +#ifndef GNUNET_SERVICE_ATS_ADDRESSES_H +#define GNUNET_SERVICE_ATS_ADDRESSES_H + +#include "gnunet_util_lib.h" + + +/** + */ +void +GAS_addresses_init (void); + + +/** + */ +void +GAS_addresses_done (void); + + +#endif