aboutsummaryrefslogtreecommitdiff
path: root/src/ats/ats_api.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-09-05 14:33:46 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-09-05 14:33:46 +0000
commit956bdf4ec0c7941f4abd07f0732a736149237668 (patch)
tree2a2a2312c5d97481d937379ee21be00632b10864 /src/ats/ats_api.c
parentcd8a403c9b658595621a0470dadbbda9b91507ce (diff)
downloadgnunet-956bdf4ec0c7941f4abd07f0732a736149237668.tar.gz
gnunet-956bdf4ec0c7941f4abd07f0732a736149237668.zip
fixing issue with unix domain sockets:
updating sessions with plugins not using sessions failed if (session == NULL) addresses where just overwritten
Diffstat (limited to 'src/ats/ats_api.c')
-rw-r--r--src/ats/ats_api.c60
1 files changed, 56 insertions, 4 deletions
diff --git a/src/ats/ats_api.c b/src/ats/ats_api.c
index 08c5fda1f..7c02d29ff 100644
--- a/src/ats/ats_api.c
+++ b/src/ats/ats_api.c
@@ -288,6 +288,11 @@ suggest_address (void *cls, const GNUNET_HashCode * key, void *value)
288 struct GNUNET_ATS_SuggestionContext *asc = cls; 288 struct GNUNET_ATS_SuggestionContext *asc = cls;
289 struct AllocationRecord *ar = value; 289 struct AllocationRecord *ar = value;
290 290
291#if DEBUG_ATS
292 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-api",
293 "Suggesting address for peer `%s'\n", GNUNET_h2s (key));
294#endif
295
291 /* trivial strategy: pick first available address... */ 296 /* trivial strategy: pick first available address... */
292 asc->cb (asc->cb_cls, &asc->target, ar->plugin_name, ar->plugin_addr, 297 asc->cb (asc->cb_cls, &asc->target, ar->plugin_name, ar->plugin_addr,
293 ar->plugin_addr_len, ar->session, 298 ar->plugin_addr_len, ar->session,
@@ -297,6 +302,13 @@ suggest_address (void *cls, const GNUNET_HashCode * key, void *value)
297 return GNUNET_NO; 302 return GNUNET_NO;
298} 303}
299 304
305int
306map_it (void *cls, const GNUNET_HashCode * key, void *value)
307{
308 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-api", "Found entry for %s\n",
309 GNUNET_h2s (key));
310 return GNUNET_YES;
311}
300 312
301/** 313/**
302 * We would like to establish a new connection with a peer. 314 * We would like to establish a new connection with a peer.
@@ -315,13 +327,29 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_Handle *atc,
315{ 327{
316 struct GNUNET_ATS_SuggestionContext *asc; 328 struct GNUNET_ATS_SuggestionContext *asc;
317 329
330#if DEBUG_ATS
331 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-api",
332 "Looking up suggested address for peer `%s'\n",
333 GNUNET_i2s (peer));
334#endif
335 int count = 0;
336
318 asc = GNUNET_malloc (sizeof (struct GNUNET_ATS_SuggestionContext)); 337 asc = GNUNET_malloc (sizeof (struct GNUNET_ATS_SuggestionContext));
319 asc->cb = cb; 338 asc->cb = cb;
320 asc->cb_cls = cb_cls; 339 asc->cb_cls = cb_cls;
321 asc->atc = atc; 340 asc->atc = atc;
322 asc->target = *peer; 341 asc->target = *peer;
323 GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers, &peer->hashPubKey, 342 count =
324 &suggest_address, asc); 343 GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers, &peer->hashPubKey,
344 &suggest_address, asc);
345
346#if DEBUG_ATS
347 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &map_it, (void *) peer);
348 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-api",
349 "Addresses %u (of %i) processed, \n", count,
350 GNUNET_CONTAINER_multihashmap_size (atc->peers));
351#endif
352
325 if (NULL == asc->cb) 353 if (NULL == asc->cb)
326 { 354 {
327 GNUNET_free (asc); 355 GNUNET_free (asc);
@@ -364,6 +392,9 @@ GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
364{ 392{
365 struct GNUNET_ATS_Handle *atc; 393 struct GNUNET_ATS_Handle *atc;
366 394
395#if DEBUG_ATS
396 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-api", "ATS init\n");
397#endif
367 atc = GNUNET_malloc (sizeof (struct GNUNET_ATS_Handle)); 398 atc = GNUNET_malloc (sizeof (struct GNUNET_ATS_Handle));
368 atc->cfg = cfg; 399 atc->cfg = cfg;
369 atc->alloc_cb = alloc_cb; 400 atc->alloc_cb = alloc_cb;
@@ -404,6 +435,9 @@ destroy_allocation_record (void *cls, const GNUNET_HashCode * key, void *value)
404void 435void
405GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc) 436GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc)
406{ 437{
438#if DEBUG_ATS
439 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-api", "ATS shutdown\n");
440#endif
407 if (GNUNET_SCHEDULER_NO_TASK != atc->ba_task) 441 if (GNUNET_SCHEDULER_NO_TASK != atc->ba_task)
408 { 442 {
409 GNUNET_SCHEDULER_cancel (atc->ba_task); 443 GNUNET_SCHEDULER_cancel (atc->ba_task);
@@ -453,9 +487,16 @@ update_session (void *cls, const GNUNET_HashCode * key, void *value)
453 struct AllocationRecord *arold = value; 487 struct AllocationRecord *arold = value;
454 int change; 488 int change;
455 489
490#if DEBUG_ATS
491 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-api",
492 "Updating session for peer `%s' plugin `%s'\n",
493 GNUNET_h2s (key), arold->plugin_name, arnew->session,
494 arold->session);
495#endif
496
456 if (0 != strcmp (arnew->plugin_name, arold->plugin_name)) 497 if (0 != strcmp (arnew->plugin_name, arold->plugin_name))
457 return GNUNET_YES; 498 return GNUNET_YES;
458 if ((arnew->session == arold->session) || 499 if (((arnew->session == arold->session) && (arnew->session != NULL)) ||
459 ((arold->session == NULL) && 500 ((arold->session == NULL) &&
460 (arold->plugin_addr_len == arnew->plugin_addr_len) && 501 (arold->plugin_addr_len == arnew->plugin_addr_len) &&
461 (0 == 502 (0 ==
@@ -724,6 +765,13 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc,
724 struct AllocationRecord *ar; 765 struct AllocationRecord *ar;
725 struct UpdateSessionContext usc; 766 struct UpdateSessionContext usc;
726 767
768
769#if DEBUG_ATS
770 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-api",
771 "Updating address for peer `%s', plugin `%s'\n",
772 GNUNET_i2s (peer), plugin_name);
773#endif
774
727 ar = create_allocation_record (plugin_name, session, plugin_addr, 775 ar = create_allocation_record (plugin_name, session, plugin_addr,
728 plugin_addr_len, ats, ats_count); 776 plugin_addr_len, ats, ats_count);
729 usc.atc = atc; 777 usc.atc = atc;
@@ -734,7 +782,11 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc,
734 destroy_allocation_record (NULL, &peer->hashPubKey, ar); 782 destroy_allocation_record (NULL, &peer->hashPubKey, ar);
735 return; 783 return;
736 } 784 }
737 785#if DEBUG_ATS
786 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-api",
787 "Adding new address for peer `%s', plugin `%s'\n",
788 GNUNET_i2s (peer), plugin_name);
789#endif
738 GNUNET_assert (GNUNET_OK == 790 GNUNET_assert (GNUNET_OK ==
739 GNUNET_CONTAINER_multihashmap_put (atc->peers, 791 GNUNET_CONTAINER_multihashmap_put (atc->peers,
740 &peer->hashPubKey, ar, 792 &peer->hashPubKey, ar,