aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-10-14 13:57:31 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-10-14 13:57:31 +0000
commit692f77eb5db9f2be29079deb2cffa5925682acc8 (patch)
tree27129a9d23ce2a8ac1ef46ecde79f121ae9b2c33
parentdde8ff327461c6eb62df698c1f059552f1a57505 (diff)
downloadgnunet-692f77eb5db9f2be29079deb2cffa5925682acc8.tar.gz
gnunet-692f77eb5db9f2be29079deb2cffa5925682acc8.zip
remove addresses on client disconnect
-rw-r--r--src/ats/gnunet-service-ats_addresses.c50
-rw-r--r--src/ats/gnunet-service-ats_addresses.h2
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c2
-rw-r--r--src/ats/test_ats_api.conf2
4 files changed, 45 insertions, 11 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index 213b43124..e874ca7c4 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -61,6 +61,13 @@ struct CompareAddressContext
61 struct ATS_Address * result; 61 struct ATS_Address * result;
62}; 62};
63 63
64static void
65destroy_address (struct ATS_Address * addr)
66{
67 GNUNET_free_non_null (addr->ats);
68 GNUNET_free (addr->plugin);
69 GNUNET_free (addr);
70}
64 71
65static int 72static int
66compare_address_it (void *cls, 73compare_address_it (void *cls,
@@ -107,6 +114,7 @@ find_address (const struct GNUNET_PeerIdentity *peer,
107static void 114static void
108merge_ats (struct ATS_Address * dest, struct ATS_Address * source) 115merge_ats (struct ATS_Address * dest, struct ATS_Address * source)
109{ 116{
117 /*
110 int c_src = 0; 118 int c_src = 0;
111 int c_dest = 0; 119 int c_dest = 0;
112 struct GNUNET_TRANSPORT_ATS_Information * a_src = source->ats; 120 struct GNUNET_TRANSPORT_ATS_Information * a_src = source->ats;
@@ -131,6 +139,7 @@ merge_ats (struct ATS_Address * dest, struct ATS_Address * source)
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
132 "Have %u entries to update and %u new entries\n",bigger->ats_count, 140 "Have %u entries to update and %u new entries\n",bigger->ats_count,
133 new_entries); 141 new_entries);
142 */
134} 143}
135 144
136void 145void
@@ -176,13 +185,36 @@ GAS_address_update (const struct GNUNET_PeerIdentity *peer,
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
177 "Updated existing address for peer `%s' %X \n", 186 "Updated existing address for peer `%s' %X \n",
178 GNUNET_i2s (peer), old); 187 GNUNET_i2s (peer), old);
179 GNUNET_free (aa->ats); 188 destroy_address (aa);
180 GNUNET_free (aa->plugin);
181 GNUNET_free (aa);
182 } 189 }
183 190
184} 191}
185 192
193static int
194remove_client (void *cls,
195 const GNUNET_HashCode * key,
196 void *value)
197{
198 struct GNUNET_SERVER_Client *client = cls;
199 struct ATS_Address * aa = (struct ATS_Address * ) value;
200
201 if (aa->session_client == client)
202 {
203 GNUNET_CONTAINER_multihashmap_remove(addresses, key, value);
204 destroy_address (aa);
205 }
206 return GNUNET_OK;
207}
208
209
210
211void
212GAS_address_client_disconnected (struct GNUNET_SERVER_Client *client)
213{
214 if (addresses != NULL)
215 GNUNET_CONTAINER_multihashmap_iterate(addresses, &remove_client, client);
216}
217
186 218
187void 219void
188GAS_address_destroyed (const struct GNUNET_PeerIdentity *peer, 220GAS_address_destroyed (const struct GNUNET_PeerIdentity *peer,
@@ -214,10 +246,8 @@ GAS_address_destroyed (const struct GNUNET_PeerIdentity *peer,
214 GNUNET_i2s (peer)); 246 GNUNET_i2s (peer));
215 247
216 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(addresses, &peer->hashPubKey, res)); 248 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(addresses, &peer->hashPubKey, res));
217 GNUNET_free (res->plugin); 249 destroy_address (aa);
218 GNUNET_free_non_null (res->ats); 250 destroy_address (res);
219 GNUNET_free (res);
220
221} 251}
222 252
223 253
@@ -258,9 +288,8 @@ free_address_it (void *cls,
258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
259 "Freeing address for peer `%s' %X\n", 289 "Freeing address for peer `%s' %X\n",
260 GNUNET_i2s (&aa->peer), aa); 290 GNUNET_i2s (&aa->peer), aa);
261 GNUNET_free (aa->plugin); 291 GNUNET_CONTAINER_multihashmap_remove (addresses, key, value);
262 GNUNET_free_non_null (aa->ats); 292 destroy_address (aa);
263 GNUNET_free (aa);
264 return GNUNET_OK; 293 return GNUNET_OK;
265} 294}
266 295
@@ -274,6 +303,7 @@ GAS_addresses_done ()
274{ 303{
275 GNUNET_CONTAINER_multihashmap_iterate (addresses, &free_address_it, NULL); 304 GNUNET_CONTAINER_multihashmap_iterate (addresses, &free_address_it, NULL);
276 GNUNET_CONTAINER_multihashmap_destroy (addresses); 305 GNUNET_CONTAINER_multihashmap_destroy (addresses);
306 addresses = NULL;
277} 307}
278 308
279 309
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h
index 2aed9f84e..dc70bf553 100644
--- a/src/ats/gnunet-service-ats_addresses.h
+++ b/src/ats/gnunet-service-ats_addresses.h
@@ -61,6 +61,8 @@ GAS_address_destroyed (const struct GNUNET_PeerIdentity *peer,
61 struct GNUNET_SERVER_Client *session_client, 61 struct GNUNET_SERVER_Client *session_client,
62 uint32_t session_id); 62 uint32_t session_id);
63 63
64void
65GAS_address_client_disconnected (struct GNUNET_SERVER_Client *session_client);
64 66
65// FIXME: this function should likely end up in the LP-subsystem and 67// FIXME: this function should likely end up in the LP-subsystem and
66// not with 'addresses' in the future... 68// not with 'addresses' in the future...
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index 066096bc2..2491529db 100644
--- a/src/ats/gnunet-service-ats_scheduling.c
+++ b/src/ats/gnunet-service-ats_scheduling.c
@@ -112,6 +112,7 @@ GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client)
112} 112}
113 113
114 114
115
115/** 116/**
116 * Unregister a client (which may have been a scheduling client, 117 * Unregister a client (which may have been a scheduling client,
117 * but this is not assured). 118 * but this is not assured).
@@ -127,6 +128,7 @@ GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client)
127 if (NULL == sc) 128 if (NULL == sc)
128 return; 129 return;
129 GNUNET_CONTAINER_DLL_remove (sc_head, sc_tail, sc); 130 GNUNET_CONTAINER_DLL_remove (sc_head, sc_tail, sc);
131 GAS_address_client_disconnected (client);
130 GNUNET_SERVER_client_drop (client); 132 GNUNET_SERVER_client_drop (client);
131 GNUNET_free (sc); 133 GNUNET_free (sc);
132} 134}
diff --git a/src/ats/test_ats_api.conf b/src/ats/test_ats_api.conf
index 79e92af49..de539981b 100644
--- a/src/ats/test_ats_api.conf
+++ b/src/ats/test_ats_api.conf
@@ -8,7 +8,7 @@ UNIXPATH = /tmp/test-ats-scheduling-arm.sock
8 8
9[ats] 9[ats]
10DEBUG = YES 10DEBUG = YES
11#PREFIX = valgrind --leak-check=full 11PREFIX = valgrind --leak-check=full
12AUTOSTART = YES 12AUTOSTART = YES
13PORT = 12002 13PORT = 12002
14HOSTNAME = localhost 14HOSTNAME = localhost