diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-09-08 16:02:02 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-09-08 16:02:02 +0000 |
commit | fb9f26178c5dfdba919b089ccdab9f1e8f3a2101 (patch) | |
tree | 9a2aeb330ecf010ed3b3b655776568e586945e22 | |
parent | 7967fed20086cb4d46292890b15ab8942fa959f0 (diff) | |
download | gnunet-fb9f26178c5dfdba919b089ccdab9f1e8f3a2101.tar.gz gnunet-fb9f26178c5dfdba919b089ccdab9f1e8f3a2101.zip |
merging ats arrays
is working but needs an additional testcase
-rw-r--r-- | src/ats/ats_api.c | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/src/ats/ats_api.c b/src/ats/ats_api.c index ba80360e4..e6013a84c 100644 --- a/src/ats/ats_api.c +++ b/src/ats/ats_api.c | |||
@@ -486,6 +486,10 @@ update_session (void *cls, const GNUNET_HashCode * key, void *value) | |||
486 | struct AllocationRecord *arnew = usc->arnew; | 486 | struct AllocationRecord *arnew = usc->arnew; |
487 | struct AllocationRecord *arold = value; | 487 | struct AllocationRecord *arold = value; |
488 | int change; | 488 | int change; |
489 | int c_old; | ||
490 | int c_new; | ||
491 | int found; | ||
492 | |||
489 | 493 | ||
490 | #if DEBUG_ATS | 494 | #if DEBUG_ATS |
491 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-api", | 495 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-api", |
@@ -514,7 +518,52 @@ update_session (void *cls, const GNUNET_HashCode * key, void *value) | |||
514 | arold->connected = GNUNET_YES; | 518 | arold->connected = GNUNET_YES; |
515 | change = GNUNET_YES; | 519 | change = GNUNET_YES; |
516 | } | 520 | } |
517 | // FIXME: merge ats arrays of (arold, arnew); | 521 | |
522 | /* Update existing value */ | ||
523 | c_new = 0; | ||
524 | while (c_new < arnew->ats_count) | ||
525 | { | ||
526 | c_old = 0; | ||
527 | found = GNUNET_NO; | ||
528 | while (c_old < arold->ats_count) | ||
529 | { | ||
530 | if (arold->ats[c_old].type == arnew->ats[c_new].type) | ||
531 | { | ||
532 | #if DEBUG_ATS | ||
533 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
534 | "Found type %u, old value=%u new value=%u\n", | ||
535 | ntohl (arold->ats[c_old].type), | ||
536 | ntohl (arold->ats[c_old].value), | ||
537 | ntohl (arnew->ats[c_new].value)); | ||
538 | #endif | ||
539 | arold->ats[c_old].value = arnew->ats[c_new].value; | ||
540 | found = GNUNET_YES; | ||
541 | } | ||
542 | c_old++; | ||
543 | } | ||
544 | /* Add new value */ | ||
545 | if (found == GNUNET_NO) | ||
546 | { | ||
547 | #if DEBUG_ATS | ||
548 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
549 | "Added new value type %u, old value=%u new value=%u\n", | ||
550 | ntohl (arnew->ats[c_new].type), | ||
551 | ntohl (arnew->ats[c_new].value)); | ||
552 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Old array size: %u\n", | ||
553 | arold->ats_count); | ||
554 | #endif | ||
555 | GNUNET_array_grow (arold->ats, arold->ats_count, arold->ats_count + 1); | ||
556 | arold->ats[arold->ats_count - 1].type = arnew->ats[c_new].type; | ||
557 | arold->ats[arold->ats_count - 1].value = arnew->ats[c_new].value; | ||
558 | arold->ats[arold->ats_count].type = htonl (0); | ||
559 | arold->ats[arold->ats_count].value = htonl (0); | ||
560 | #if DEBUG_ATS | ||
561 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New array size: %i\n", | ||
562 | arold->ats_count); | ||
563 | #endif | ||
564 | } | ||
565 | c_new++; | ||
566 | } | ||
518 | 567 | ||
519 | if (GNUNET_YES == change) | 568 | if (GNUNET_YES == change) |
520 | update_bandwidth_assignment (usc->atc, arold); | 569 | update_bandwidth_assignment (usc->atc, arold); |