diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-13 19:33:50 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-13 19:33:50 +0000 |
commit | 2008c8b8f7853f08b13e04d176bc28b1f41098db (patch) | |
tree | d845e9b3d2810df2f9cd28153451d404d62235ff | |
parent | 9d3d595085088e316830652b6673fa6492d373bf (diff) | |
download | gnunet-2008c8b8f7853f08b13e04d176bc28b1f41098db.tar.gz gnunet-2008c8b8f7853f08b13e04d176bc28b1f41098db.zip |
-rw-r--r-- | src/ats/Makefile.am | 16 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats.c | 43 |
2 files changed, 39 insertions, 20 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 0f0a20e55..b5ef6cb0b 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am | |||
@@ -18,14 +18,14 @@ libgnunetats_la_LIBADD = \ | |||
18 | $(top_builddir)/src/util/libgnunetutil.la | 18 | $(top_builddir)/src/util/libgnunetutil.la |
19 | 19 | ||
20 | 20 | ||
21 | #bin_PROGRAMS = \ | 21 | bin_PROGRAMS = \ |
22 | # gnunet-service-ats | 22 | gnunet-service-ats |
23 | 23 | ||
24 | #gnunet_service_ats_SOURCES = \ | 24 | gnunet_service_ats_SOURCES = \ |
25 | # gnunet-service-ats.c | 25 | gnunet-service-ats.c |
26 | #gnunet_service_ats_LDADD = \ | 26 | gnunet_service_ats_LDADD = \ |
27 | # $(top_builddir)/src/util/libgnunetutil.la \ | 27 | $(top_builddir)/src/util/libgnunetutil.la \ |
28 | # $(GN_LIBINTL) | 28 | $(GN_LIBINTL) |
29 | 29 | ||
30 | 30 | ||
31 | #check_PROGRAMS = \ | 31 | #check_PROGRAMS = \ |
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index 03bbf5620..bd87cecaf 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c | |||
@@ -27,10 +27,15 @@ | |||
27 | #include "gnunet_getopt_lib.h" | 27 | #include "gnunet_getopt_lib.h" |
28 | #include "gnunet_service_lib.h" | 28 | #include "gnunet_service_lib.h" |
29 | #include "gnunet_container_lib.h" | 29 | #include "gnunet_container_lib.h" |
30 | #include "gnunet_ats_service.h" | ||
30 | #include "ats.h" | 31 | #include "ats.h" |
31 | 32 | ||
32 | struct ATS_Clients | 33 | struct ATS_Clients |
33 | { | 34 | { |
35 | struct ATS_Clients * next; | ||
36 | |||
37 | struct ATS_Clients * prev; | ||
38 | |||
34 | struct GNUNET_SERVER_Client *client; | 39 | struct GNUNET_SERVER_Client *client; |
35 | 40 | ||
36 | uint32_t flags; | 41 | uint32_t flags; |
@@ -71,7 +76,7 @@ int address_it (void *cls, | |||
71 | { | 76 | { |
72 | struct ATS_Address * aa = cls; | 77 | struct ATS_Address * aa = cls; |
73 | GNUNET_free (aa); | 78 | GNUNET_free (aa); |
74 | GNUNET_OK; | 79 | return GNUNET_OK; |
75 | } | 80 | } |
76 | 81 | ||
77 | /** | 82 | /** |
@@ -89,12 +94,24 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
89 | { | 94 | { |
90 | t = ac_head; | 95 | t = ac_head; |
91 | GNUNET_CONTAINER_DLL_remove(ac_head,ac_tail, t); | 96 | GNUNET_CONTAINER_DLL_remove(ac_head,ac_tail, t); |
92 | GNUNET_free (ac); | 97 | GNUNET_free (t); |
93 | } | 98 | } |
94 | 99 | ||
95 | GNUNET_CONTAINER_multihashmap_iterate(addresses, address_it, NULL); | 100 | GNUNET_CONTAINER_multihashmap_iterate (addresses, address_it, NULL); |
96 | 101 | ||
97 | GNUNET_CONTAINER_multihashmap_create(addresses); | 102 | GNUNET_CONTAINER_multihashmap_destroy (addresses); |
103 | } | ||
104 | |||
105 | static struct ATS_Clients * find_client (struct GNUNET_SERVER_Client *client) | ||
106 | { | ||
107 | struct ATS_Clients * ac = ac_head; | ||
108 | while (ac != NULL) | ||
109 | { | ||
110 | if (ac->client == client) | ||
111 | break; | ||
112 | ac = ac->next; | ||
113 | } | ||
114 | return ac; | ||
98 | } | 115 | } |
99 | 116 | ||
100 | static void | 117 | static void |
@@ -138,32 +155,34 @@ handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, | |||
138 | struct GNUNET_TRANSPORT_ATS_Information *am; | 155 | struct GNUNET_TRANSPORT_ATS_Information *am; |
139 | char *pm; | 156 | char *pm; |
140 | 157 | ||
158 | size_t size = ntohs (msg->header.size); | ||
141 | if (size <= sizeof (struct AddressUpdateMessage)) | 159 | if (size <= sizeof (struct AddressUpdateMessage)) |
142 | GNUNET_break (0); | 160 | GNUNET_break (0); |
143 | 161 | ||
162 | size_t ats_count = ntohs (msg->ats_count); | ||
163 | size_t addr_len = ntohs (msg->address_length); | ||
164 | size_t plugin_len = ntohs (msg->plugin_name_length) + 1 ; | ||
165 | |||
144 | struct ATS_Address * aa = GNUNET_malloc (sizeof (struct ATS_Address) + | 166 | struct ATS_Address * aa = GNUNET_malloc (sizeof (struct ATS_Address) + |
145 | ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) + | 167 | ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) + |
146 | addr_len + | 168 | addr_len + |
147 | plugin_len); | 169 | plugin_len); |
148 | 170 | ||
149 | size_t size = ntohs (msg->header.size); | 171 | |
150 | size_t ats_count = ntohs (msg->ats_count); | ||
151 | size_t addr_len = ntohs (msg->address_length); | ||
152 | size_t plugin_len = ntohs (msg->plugin_name_length) + 1 ; | ||
153 | 172 | ||
154 | memcpy (&aa->peer, &msg->peer, sizeof (struct GNUNET_PeerIdentity)); | 173 | memcpy (&aa->peer, &msg->peer, sizeof (struct GNUNET_PeerIdentity)); |
155 | aa->addr_len = addr_len; | 174 | aa->addr_len = addr_len; |
156 | aa->ats_count = ats_count; | 175 | aa->ats_count = ats_count; |
157 | aa->ats = &aa[1]; | 176 | aa->ats = (struct GNUNET_TRANSPORT_ATS_Information *) &aa[1]; |
158 | 177 | ||
159 | am = (struct GNUNET_TRANSPORT_ATS_Information*) &msg[1]; | 178 | am = (struct GNUNET_TRANSPORT_ATS_Information*) &msg[1]; |
160 | memcpy (&aa->ats, am, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); | 179 | memcpy (&aa->ats, am, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); |
161 | pm = (char *) &am[ats_count]; | 180 | pm = (char *) &am[ats_count]; |
162 | memcpy (aa->addr, pm, addr_len); | 181 | memcpy (aa->addr, pm, addr_len); |
163 | memcpy (aa->plugin, &pm[plugin_addr_len], plugin_len); | 182 | memcpy (aa->plugin, &pm[plugin_len], plugin_len); |
164 | aa->session_id = ntohl(msg->session_id); | 183 | aa->session_id = ntohl(msg->session_id); |
165 | 184 | ||
166 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(addresses, aa->peer.hashPubKey, aa, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 185 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(addresses, &aa->peer.hashPubKey, aa, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
167 | } | 186 | } |
168 | 187 | ||
169 | static void | 188 | static void |
@@ -234,7 +253,7 @@ int | |||
234 | main (int argc, char *const *argv) | 253 | main (int argc, char *const *argv) |
235 | { | 254 | { |
236 | return (GNUNET_OK == | 255 | return (GNUNET_OK == |
237 | GNUNET_SERVICE_run (argc, argv, "gnunet-service-ats", | 256 | GNUNET_SERVICE_run (argc, argv, "ats", |
238 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; | 257 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; |
239 | } | 258 | } |
240 | 259 | ||