aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-13 20:54:17 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-13 20:54:17 +0000
commit42f0a310ce2d0c9c2cd4b62e8da617d8bc9b8290 (patch)
treece839c1c56d5a4b14b756ccbcf5654009460ed9b
parent8a8968521fba2e248c37c7b817fa970c5c5097e2 (diff)
downloadgnunet-42f0a310ce2d0c9c2cd4b62e8da617d8bc9b8290.tar.gz
gnunet-42f0a310ce2d0c9c2cd4b62e8da617d8bc9b8290.zip
moving out addresses as well
-rw-r--r--src/ats/Makefile.am1
-rw-r--r--src/ats/gnunet-service-ats.c63
-rw-r--r--src/ats/gnunet-service-ats_addresses.c102
-rw-r--r--src/ats/gnunet-service-ats_addresses.h44
4 files changed, 150 insertions, 60 deletions
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 = \
23 23
24gnunet_service_ats_SOURCES = \ 24gnunet_service_ats_SOURCES = \
25 gnunet-service-ats.c \ 25 gnunet-service-ats.c \
26 gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \
26 gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ 27 gnunet-service-ats_performance.c gnunet-service-ats_performance.h \
27 gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h 28 gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h
28gnunet_service_ats_LDADD = \ 29gnunet_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 @@
28#include "gnunet_ats_service.h" 28#include "gnunet_ats_service.h"
29#include "gnunet-service-ats_performance.h" 29#include "gnunet-service-ats_performance.h"
30#include "gnunet-service-ats_scheduling.h" 30#include "gnunet-service-ats_scheduling.h"
31// #include "gnunet-service-ats_performance.h" 31#include "gnunet-service-ats_addresses.h"
32#include "ats.h" 32#include "ats.h"
33 33
34struct ATS_Address
35{
36 struct GNUNET_PeerIdentity peer;
37
38 size_t addr_len;
39
40 uint32_t session_id;
41
42 uint32_t ats_count;
43
44 void * addr;
45
46 char * plugin;
47
48 struct GNUNET_TRANSPORT_ATS_Information * ats;
49};
50
51static struct GNUNET_CONTAINER_MultiHashMap * addresses;
52
53
54 34
55static void 35static void
56handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client, 36handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client,
@@ -80,42 +60,6 @@ handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client,
80} 60}
81 61
82 62
83struct CompareAddressContext
84{
85 struct ATS_Address * search;
86 struct ATS_Address * result;
87};
88
89int compare_address_it (void *cls,
90 const GNUNET_HashCode * key,
91 void *value)
92{
93 struct CompareAddressContext * cac = cls;
94 struct ATS_Address * aa = (struct ATS_Address *) value;
95 if (0 == strcmp(aa->plugin, cac->search->plugin))
96 {
97 if ((aa->addr_len == cac->search->addr_len) &&
98 (0 == memcmp (aa->addr, cac->search->addr, aa->addr_len)))
99 cac->result = aa;
100 return GNUNET_NO;
101 }
102 return GNUNET_YES;
103}
104
105
106static int
107free_address_it (void *cls,
108 const GNUNET_HashCode * key,
109 void *value)
110{
111 struct ATS_Address * aa = cls;
112 GNUNET_free (aa);
113 return GNUNET_OK;
114}
115
116
117
118
119 63
120/** 64/**
121 * Task run during shutdown. 65 * Task run during shutdown.
@@ -126,8 +70,7 @@ free_address_it (void *cls,
126static void 70static void
127cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 71cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
128{ 72{
129 GNUNET_CONTAINER_multihashmap_iterate (addresses, &free_address_it, NULL); 73 GAS_addresses_done ();
130 GNUNET_CONTAINER_multihashmap_destroy (addresses);
131} 74}
132 75
133 76
@@ -157,7 +100,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
157 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0}, 100 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0},
158 {NULL, NULL, 0, 0} 101 {NULL, NULL, 0, 0}
159 }; 102 };
160 addresses = GNUNET_CONTAINER_multihashmap_create(128); 103 GAS_addresses_init ();
161 GNUNET_SERVER_add_handlers (server, handlers); 104 GNUNET_SERVER_add_handlers (server, handlers);
162 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, 105 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
163 NULL); 106 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 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file ats/gnunet-service-ats_addresses.c
23 * @brief ats service address management
24 * @author Matthias Wachs
25 */
26#include "platform.h"
27#include "gnunet-service-ats_addresses.h"
28
29
30struct ATS_Address
31{
32 struct GNUNET_PeerIdentity peer;
33
34 size_t addr_len;
35
36 uint32_t session_id;
37
38 uint32_t ats_count;
39
40 void * addr;
41
42 char * plugin;
43
44 struct GNUNET_TRANSPORT_ATS_Information * ats;
45};
46
47static struct GNUNET_CONTAINER_MultiHashMap * addresses;
48
49
50struct CompareAddressContext
51{
52 struct ATS_Address * search;
53 struct ATS_Address * result;
54};
55
56int compare_address_it (void *cls,
57 const GNUNET_HashCode * key,
58 void *value)
59{
60 struct CompareAddressContext * cac = cls;
61 struct ATS_Address * aa = (struct ATS_Address *) value;
62 if (0 == strcmp(aa->plugin, cac->search->plugin))
63 {
64 if ((aa->addr_len == cac->search->addr_len) &&
65 (0 == memcmp (aa->addr, cac->search->addr, aa->addr_len)))
66 cac->result = aa;
67 return GNUNET_NO;
68 }
69 return GNUNET_YES;
70}
71
72
73static int
74free_address_it (void *cls,
75 const GNUNET_HashCode * key,
76 void *value)
77{
78 struct ATS_Address * aa = cls;
79 GNUNET_free (aa);
80 return GNUNET_OK;
81}
82
83
84/**
85 */
86void
87GAS_addresses_done ()
88{
89 GNUNET_CONTAINER_multihashmap_iterate (addresses, &free_address_it, NULL);
90 GNUNET_CONTAINER_multihashmap_destroy (addresses);
91}
92
93
94/**
95 */
96void
97GAS_addresses_init ()
98{
99 addresses = GNUNET_CONTAINER_multihashmap_create(128);
100}
101
102/* 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 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file ats/gnunet-service-ats_addresses.c
23 * @brief ats service address management
24 * @author Matthias Wachs
25 */
26#ifndef GNUNET_SERVICE_ATS_ADDRESSES_H
27#define GNUNET_SERVICE_ATS_ADDRESSES_H
28
29#include "gnunet_util_lib.h"
30
31
32/**
33 */
34void
35GAS_addresses_init (void);
36
37
38/**
39 */
40void
41GAS_addresses_done (void);
42
43
44#endif