moving out addresses as well
authorChristian Grothoff <christian@grothoff.org>
Thu, 13 Oct 2011 20:54:17 +0000 (20:54 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 13 Oct 2011 20:54:17 +0000 (20:54 +0000)
src/ats/Makefile.am
src/ats/gnunet-service-ats.c
src/ats/gnunet-service-ats_addresses.c [new file with mode: 0644]
src/ats/gnunet-service-ats_addresses.h [new file with mode: 0644]

index 31d9ef4e639929d2b1d91c6a2243d796d7913c0d..2b13fa06a04ea027957f9ac8d23d25e9e3a40ecf 100644 (file)
@@ -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 = \
index aca877d7b9c743172e629cf499bd850cadbcfc3c..dff19abea4c484e0d0852b18deeac4b8f26b76a3 100644 (file)
 #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 (file)
index 0000000..ff83f4f
--- /dev/null
@@ -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 (file)
index 0000000..1bc6b65
--- /dev/null
@@ -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