diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/ats_api.c | 76 |
1 files changed, 47 insertions, 29 deletions
diff --git a/src/ats/ats_api.c b/src/ats/ats_api.c index 50d7d4dd4..b5467cdb3 100644 --- a/src/ats/ats_api.c +++ b/src/ats/ats_api.c | |||
@@ -136,7 +136,9 @@ set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value) | |||
136 | struct SetBandwidthContext *sbc = cls; | 136 | struct SetBandwidthContext *sbc = cls; |
137 | struct AllocationRecord *ar = value; | 137 | struct AllocationRecord *ar = value; |
138 | 138 | ||
139 | if (GNUNET_YES == ar->connected) | 139 | GNUNET_assert (GNUNET_SYSERR != ar->connected); |
140 | /* FIXME: ||1 because we currently NEVER get 'connected' events... */ | ||
141 | if ( (GNUNET_YES == ar->connected) || 1) | ||
140 | { | 142 | { |
141 | ar->bandwidth_in = sbc->bw_in; | 143 | ar->bandwidth_in = sbc->bw_in; |
142 | ar->bandwidth_out = sbc->bw_out; | 144 | ar->bandwidth_out = sbc->bw_out; |
@@ -165,6 +167,13 @@ set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value) | |||
165 | ar->plugin_addr_len, ar->bandwidth_out, | 167 | ar->plugin_addr_len, ar->bandwidth_out, |
166 | ar->bandwidth_in); | 168 | ar->bandwidth_in); |
167 | } | 169 | } |
170 | else | ||
171 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
172 | "Not communicating bandwidth assigned to peer %s: not connected and bw is: i:%u/o:%u bytes/s\n", | ||
173 | GNUNET_i2s ((const struct GNUNET_PeerIdentity *) key), | ||
174 | ntohl (ar->bandwidth_in.value__), | ||
175 | ntohl (ar->bandwidth_out.value__)); | ||
176 | |||
168 | return GNUNET_YES; | 177 | return GNUNET_YES; |
169 | } | 178 | } |
170 | 179 | ||
@@ -191,7 +200,11 @@ update_bandwidth_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
191 | GNUNET_assert (ac > 0); | 200 | GNUNET_assert (ac > 0); |
192 | bwc.bw_in = GNUNET_BANDWIDTH_value_init (atc->total_bps_in / ac); | 201 | bwc.bw_in = GNUNET_BANDWIDTH_value_init (atc->total_bps_in / ac); |
193 | bwc.bw_out = GNUNET_BANDWIDTH_value_init (atc->total_bps_out / ac); | 202 | bwc.bw_out = GNUNET_BANDWIDTH_value_init (atc->total_bps_out / ac); |
194 | GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc); | 203 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
204 | "Trivial implementation: bandwidth assigned to each peer is i:%u/o:%u bytes/s\n", | ||
205 | ntohl (bwc.bw_in.value__), | ||
206 | ntohl (bwc.bw_out.value__)); | ||
207 | GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc); | ||
195 | } | 208 | } |
196 | 209 | ||
197 | 210 | ||
@@ -418,43 +431,38 @@ update_session (void *cls, const GNUNET_HashCode * key, void *value) | |||
418 | struct UpdateSessionContext *usc = cls; | 431 | struct UpdateSessionContext *usc = cls; |
419 | struct AllocationRecord *arnew = usc->arnew; | 432 | struct AllocationRecord *arnew = usc->arnew; |
420 | struct AllocationRecord *arold = value; | 433 | struct AllocationRecord *arold = value; |
421 | int change; | ||
422 | int c_old; | 434 | int c_old; |
423 | int c_new; | 435 | int c_new; |
424 | int found; | 436 | int found; |
425 | 437 | ||
426 | 438 | ||
439 | if (0 != strcmp (arnew->plugin_name, arold->plugin_name)) | ||
440 | return GNUNET_YES; | ||
441 | if (! (((arnew->session == arold->session) && (arnew->session != NULL)) || | ||
442 | ((arold->session == NULL) && | ||
443 | (arold->plugin_addr_len == arnew->plugin_addr_len) && | ||
444 | (0 == | ||
445 | memcmp (arold->plugin_addr, arnew->plugin_addr, | ||
446 | arnew->plugin_addr_len))))) | ||
447 | return GNUNET_YES; /* no match */ | ||
448 | /* records match */ | ||
427 | #if DEBUG_ATS | 449 | #if DEBUG_ATS |
428 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 450 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
429 | "Updating session for peer `%s' plugin `%s'\n", GNUNET_h2s (key), | 451 | "Updating session for peer `%s' plugin `%s'\n", GNUNET_h2s (key), |
430 | arold->plugin_name); | 452 | arold->plugin_name); |
431 | #endif | 453 | #endif |
432 | 454 | if (arnew->session != arold->session) | |
433 | if (0 != strcmp (arnew->plugin_name, arold->plugin_name)) | ||
434 | return GNUNET_YES; | ||
435 | if (((arnew->session == arold->session) && (arnew->session != NULL)) || | ||
436 | ((arold->session == NULL) && | ||
437 | (arold->plugin_addr_len == arnew->plugin_addr_len) && | ||
438 | (0 == | ||
439 | memcmp (arold->plugin_addr, arnew->plugin_addr, | ||
440 | arnew->plugin_addr_len)))) | ||
441 | { | ||
442 | change = GNUNET_NO; | ||
443 | /* records match */ | ||
444 | if (arnew->session != arold->session) | ||
445 | { | 455 | { |
446 | arold->session = arnew->session; | 456 | arold->session = arnew->session; |
447 | change = GNUNET_YES; | ||
448 | } | 457 | } |
449 | if ((arnew->connected == GNUNET_YES) && (arold->connected == GNUNET_NO)) | 458 | if ((arnew->connected == GNUNET_YES) && (arold->connected == GNUNET_NO)) |
450 | { | 459 | { |
451 | arold->connected = GNUNET_YES; | 460 | arold->connected = GNUNET_YES; |
452 | change = GNUNET_YES; | ||
453 | } | 461 | } |
454 | 462 | ||
455 | /* Update existing value */ | 463 | /* Update existing value */ |
456 | c_new = 0; | 464 | c_new = 0; |
457 | while (c_new < arnew->ats_count) | 465 | while (c_new < arnew->ats_count) |
458 | { | 466 | { |
459 | c_old = 0; | 467 | c_old = 0; |
460 | found = GNUNET_NO; | 468 | found = GNUNET_NO; |
@@ -493,12 +501,9 @@ update_session (void *cls, const GNUNET_HashCode * key, void *value) | |||
493 | } | 501 | } |
494 | c_new++; | 502 | c_new++; |
495 | } | 503 | } |
496 | 504 | ||
497 | if (GNUNET_YES == change) | 505 | update_bandwidth_assignment (usc->atc, arold); |
498 | update_bandwidth_assignment (usc->atc, arold); | 506 | return GNUNET_NO; |
499 | return GNUNET_NO; | ||
500 | } | ||
501 | return GNUNET_YES; | ||
502 | } | 507 | } |
503 | 508 | ||
504 | 509 | ||
@@ -532,6 +537,7 @@ create_allocation_record (const char *plugin_name, struct Session *session, | |||
532 | GNUNET_array_grow (ar->ats, ar->ats_count, ats_count); | 537 | GNUNET_array_grow (ar->ats, ar->ats_count, ats_count); |
533 | memcpy (ar->ats, ats, | 538 | memcpy (ar->ats, ats, |
534 | ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); | 539 | ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); |
540 | ar->connected = GNUNET_SYSERR; /* aka: not known / no change */ | ||
535 | return ar; | 541 | return ar; |
536 | } | 542 | } |
537 | 543 | ||
@@ -584,6 +590,12 @@ GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc, | |||
584 | struct AllocationRecord *ar; | 590 | struct AllocationRecord *ar; |
585 | struct UpdateSessionContext usc; | 591 | struct UpdateSessionContext usc; |
586 | 592 | ||
593 | #if DEBUG_ATS | ||
594 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
595 | "Connected to peer %s\n", | ||
596 | GNUNET_i2s (peer)); | ||
597 | #endif | ||
598 | |||
587 | (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &disconnect_peer, | 599 | (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &disconnect_peer, |
588 | atc); | 600 | atc); |
589 | ar = create_allocation_record (plugin_name, session, plugin_addr, | 601 | ar = create_allocation_record (plugin_name, session, plugin_addr, |
@@ -616,6 +628,11 @@ void | |||
616 | GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_Handle *atc, | 628 | GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_Handle *atc, |
617 | const struct GNUNET_PeerIdentity *peer) | 629 | const struct GNUNET_PeerIdentity *peer) |
618 | { | 630 | { |
631 | #if DEBUG_ATS | ||
632 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
633 | "Disconnected from peer %s\n", | ||
634 | GNUNET_i2s (peer)); | ||
635 | #endif | ||
619 | (void) GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers, | 636 | (void) GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers, |
620 | &peer->hashPubKey, | 637 | &peer->hashPubKey, |
621 | &disconnect_peer, atc); | 638 | &disconnect_peer, atc); |
@@ -767,6 +784,7 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc, | |||
767 | "Adding new address for peer `%s', plugin `%s'\n", GNUNET_i2s (peer), | 784 | "Adding new address for peer `%s', plugin `%s'\n", GNUNET_i2s (peer), |
768 | plugin_name); | 785 | plugin_name); |
769 | #endif | 786 | #endif |
787 | ar->connected = GNUNET_NO; | ||
770 | GNUNET_assert (GNUNET_OK == | 788 | GNUNET_assert (GNUNET_OK == |
771 | GNUNET_CONTAINER_multihashmap_put (atc->peers, | 789 | GNUNET_CONTAINER_multihashmap_put (atc->peers, |
772 | &peer->hashPubKey, ar, | 790 | &peer->hashPubKey, ar, |