diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-14 16:31:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-14 16:31:04 +0000 |
commit | abaa53b4052431835f1303ebc40c069f6da5cecd (patch) | |
tree | 57d848754f8ef9eea739e744cbc6332af381fff3 /src/ats | |
parent | 4dc6c16a353cce59fac581fcbab5d5f22ee5ad6b (diff) | |
download | gnunet-abaa53b4052431835f1303ebc40c069f6da5cecd.tar.gz gnunet-abaa53b4052431835f1303ebc40c069f6da5cecd.zip |
cleaner destroy by session ID
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 85 |
1 files changed, 56 insertions, 29 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index d5c0b0915..9884104f1 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -206,7 +206,7 @@ find_address (const struct GNUNET_PeerIdentity *peer, | |||
206 | cac.result = NULL; | 206 | cac.result = NULL; |
207 | cac.search = addr; | 207 | cac.search = addr; |
208 | GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, | 208 | GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, |
209 | compare_address_it, &cac); | 209 | &compare_address_it, &cac); |
210 | return cac.result; | 210 | return cac.result; |
211 | } | 211 | } |
212 | 212 | ||
@@ -290,46 +290,73 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | |||
290 | } | 290 | } |
291 | 291 | ||
292 | 292 | ||
293 | /** | ||
294 | * Update a bandwidth assignment for a peer. This trivial method currently | ||
295 | * simply assigns the same share to all active connections. | ||
296 | * | ||
297 | * @param cls unused | ||
298 | * @param key unused | ||
299 | * @param value the 'struct ATS_Address' | ||
300 | * @return GNUNET_OK (continue to iterate) | ||
301 | */ | ||
302 | static int | ||
303 | destroy_by_session_id (void *cls, const GNUNET_HashCode * key, void *value) | ||
304 | { | ||
305 | const struct ATS_Address *info = cls; | ||
306 | struct ATS_Address *aa = value; | ||
307 | |||
308 | GNUNET_assert (0 == memcmp (&aa->peer, | ||
309 | &info->peer, | ||
310 | sizeof (struct GNUNET_PeerIdentity))); | ||
311 | if ( (info->session_id == 0) && | ||
312 | (0 == strcmp (info->plugin, | ||
313 | aa->plugin)) && | ||
314 | (aa->addr_len == info->addr_len) && | ||
315 | (0 == memcmp (info->addr, | ||
316 | aa->addr, | ||
317 | aa->addr_len)) ) | ||
318 | { | ||
319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
320 | "Deleting address for peer `%s': `%s'\n", | ||
321 | GNUNET_i2s (&aa->peer), aa->plugin); | ||
322 | if (GNUNET_YES == destroy_address (aa)) | ||
323 | recalculate_assigned_bw (); | ||
324 | return GNUNET_OK; | ||
325 | } | ||
326 | if (aa->session_id != info->session_id) | ||
327 | return GNUNET_OK; /* irrelevant */ | ||
328 | GNUNET_assert (0 == strcmp (info->plugin, | ||
329 | aa->plugin)); | ||
330 | /* session died */ | ||
331 | aa->session_id = 0; | ||
332 | if (GNUNET_YES == aa->active) | ||
333 | { | ||
334 | aa->active = GNUNET_NO; | ||
335 | active_addr_count--; | ||
336 | if (aa->addr_len == 0) | ||
337 | (void) destroy_address (aa); | ||
338 | recalculate_assigned_bw (); | ||
339 | } | ||
340 | return GNUNET_OK; | ||
341 | } | ||
342 | |||
343 | |||
293 | void | 344 | void |
294 | GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, | 345 | GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, |
295 | const char *plugin_name, const void *plugin_addr, | 346 | const char *plugin_name, const void *plugin_addr, |
296 | size_t plugin_addr_len, uint32_t session_id) | 347 | size_t plugin_addr_len, uint32_t session_id) |
297 | { | 348 | { |
298 | struct ATS_Address aa; | 349 | struct ATS_Address aa; |
299 | struct ATS_Address *res; | ||
300 | 350 | ||
301 | aa.peer = *peer; | 351 | aa.peer = *peer; |
302 | aa.addr_len = plugin_addr_len; | 352 | aa.addr_len = plugin_addr_len; |
303 | aa.addr = plugin_addr; | 353 | aa.addr = plugin_addr; |
304 | aa.plugin = (char *) plugin_name; | 354 | aa.plugin = (char *) plugin_name; |
305 | aa.session_id = session_id; | 355 | aa.session_id = session_id; |
306 | res = find_address (peer, &aa); | 356 | GNUNET_CONTAINER_multihashmap_get_multiple (addresses, |
307 | if (res == NULL) | 357 | &peer->hashPubKey, |
308 | { | 358 | &destroy_by_session_id, |
309 | /* we don't even know this one, can this happen? */ | 359 | &aa); |
310 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
311 | "Asked to delete unknown address for peer `%s'\n", | ||
312 | GNUNET_i2s (peer)); | ||
313 | return; | ||
314 | } | ||
315 | if ((aa.session_id == session_id) && (session_id != 0) && (res->addr_len > 0)) | ||
316 | { | ||
317 | /* just session died */ | ||
318 | res->session_id = 0; | ||
319 | if (GNUNET_YES == res->active) | ||
320 | { | ||
321 | res->active = GNUNET_NO; | ||
322 | active_addr_count--; | ||
323 | recalculate_assigned_bw (); | ||
324 | } | ||
325 | return; | ||
326 | } | ||
327 | /* destroy address entirely (either was only session or was | ||
328 | * not even with a session) */ | ||
329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting address for peer `%s': `%s'\n", | ||
330 | GNUNET_i2s (peer), plugin_name); | ||
331 | if (GNUNET_YES == destroy_address (res)) | ||
332 | recalculate_assigned_bw (); | ||
333 | } | 360 | } |
334 | 361 | ||
335 | 362 | ||