diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-09-25 13:35:22 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-09-25 13:35:22 +0000 |
commit | d3efdf93da7b501244a7f87635dc518ce4b68d26 (patch) | |
tree | bcb7e0bbcdc6d530a2f116cc3713894dfa5b3eda /src/ats/gnunet-service-ats_addresses.c | |
parent | d89d2c881cead94a93f13e39dbd7a72bd4574cd5 (diff) | |
download | gnunet-d3efdf93da7b501244a7f87635dc518ce4b68d26.tar.gz gnunet-d3efdf93da7b501244a7f87635dc518ce4b68d26.zip |
indent
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses.c')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 1258 |
1 files changed, 604 insertions, 654 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 9388a66b4..50a72d80d 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2011 Christian Grothoff (and other contributing authors) | 3 | (C) 2011 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with GNUnet; see the file COPYING. If not, write to the |
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file ats/gnunet-service-ats_addresses.c | 22 | * @file ats/gnunet-service-ats_addresses.c |
@@ -230,7 +230,6 @@ | |||
230 | 230 | ||
231 | */ | 231 | */ |
232 | 232 | ||
233 | |||
234 | /** | 233 | /** |
235 | * Available ressource assignment modes | 234 | * Available ressource assignment modes |
236 | */ | 235 | */ |
@@ -261,7 +260,6 @@ enum ATS_Mode | |||
261 | MODE_RIL | 260 | MODE_RIL |
262 | }; | 261 | }; |
263 | 262 | ||
264 | |||
265 | /** | 263 | /** |
266 | * Pending Address suggestion requests | 264 | * Pending Address suggestion requests |
267 | */ | 265 | */ |
@@ -283,7 +281,6 @@ struct GAS_Addresses_Suggestion_Requests | |||
283 | struct GNUNET_PeerIdentity id; | 281 | struct GNUNET_PeerIdentity id; |
284 | }; | 282 | }; |
285 | 283 | ||
286 | |||
287 | /** | 284 | /** |
288 | * Handle for ATS address component | 285 | * Handle for ATS address component |
289 | */ | 286 | */ |
@@ -346,7 +343,6 @@ struct GAS_Addresses_Handle | |||
346 | */ | 343 | */ |
347 | GAS_solver_address_add s_add; | 344 | GAS_solver_address_add s_add; |
348 | 345 | ||
349 | |||
350 | GAS_solver_address_property_changed s_address_update_property; | 346 | GAS_solver_address_property_changed s_address_update_property; |
351 | 347 | ||
352 | GAS_solver_address_session_changed s_address_update_session; | 348 | GAS_solver_address_session_changed s_address_update_session; |
@@ -396,7 +392,6 @@ struct GAS_Addresses_Handle | |||
396 | GAS_solver_done s_done; | 392 | GAS_solver_done s_done; |
397 | }; | 393 | }; |
398 | 394 | ||
399 | |||
400 | /** | 395 | /** |
401 | * Disassemble ATS information and update performance information in address | 396 | * Disassemble ATS information and update performance information in address |
402 | * | 397 | * |
@@ -412,10 +407,8 @@ struct GAS_Addresses_Handle | |||
412 | */ | 407 | */ |
413 | static unsigned int | 408 | static unsigned int |
414 | disassemble_ats_information (struct ATS_Address *dest, | 409 | disassemble_ats_information (struct ATS_Address *dest, |
415 | const struct GNUNET_ATS_Information *update, | 410 | const struct GNUNET_ATS_Information *update, uint32_t update_count, |
416 | uint32_t update_count, | 411 | struct GNUNET_ATS_Information **delta_dest, uint32_t *delta_count) |
417 | struct GNUNET_ATS_Information **delta_dest, | ||
418 | uint32_t *delta_count) | ||
419 | { | 412 | { |
420 | 413 | ||
421 | int c1; | 414 | int c1; |
@@ -434,19 +427,22 @@ disassemble_ats_information (struct ATS_Address *dest, | |||
434 | delta_atsi_count = 0; | 427 | delta_atsi_count = 0; |
435 | 428 | ||
436 | if (0 == update_count) | 429 | if (0 == update_count) |
437 | return GNUNET_NO; | 430 | return GNUNET_NO; |
438 | 431 | ||
439 | if (NULL == dest->atsi) | 432 | if (NULL == dest->atsi) |
440 | { | 433 | { |
441 | /* Create performance information */ | 434 | /* Create performance information */ |
442 | dest->atsi = GNUNET_malloc (update_count * sizeof (struct GNUNET_ATS_Information)); | 435 | dest->atsi = |
436 | GNUNET_malloc (update_count * sizeof (struct GNUNET_ATS_Information)); | ||
443 | dest->atsi_count = update_count; | 437 | dest->atsi_count = update_count; |
444 | memcpy (dest->atsi, update, update_count * sizeof (struct GNUNET_ATS_Information)); | 438 | memcpy (dest->atsi, update, |
445 | (*delta_dest) = GNUNET_malloc (update_count * sizeof (struct GNUNET_ATS_Information)); | 439 | update_count * sizeof(struct GNUNET_ATS_Information)); |
446 | for (c1 = 0; c1 < update_count; c1 ++) | 440 | (*delta_dest) = |
441 | GNUNET_malloc (update_count * sizeof (struct GNUNET_ATS_Information)); | ||
442 | for (c1 = 0; c1 < update_count; c1++) | ||
447 | { | 443 | { |
448 | (*delta_dest)[c1].type = update[c1].type; | 444 | (*delta_dest)[c1].type = update[c1].type; |
449 | (*delta_dest)[c1].value = htonl(GNUNET_ATS_VALUE_UNDEFINED); | 445 | (*delta_dest)[c1].value = htonl (GNUNET_ATS_VALUE_UNDEFINED); |
450 | } | 446 | } |
451 | (*delta_count) = update_count; | 447 | (*delta_count) = update_count; |
452 | return GNUNET_YES; | 448 | return GNUNET_YES; |
@@ -464,7 +460,7 @@ disassemble_ats_information (struct ATS_Address *dest, | |||
464 | { | 460 | { |
465 | /* Save previous value in delta */ | 461 | /* Save previous value in delta */ |
466 | delta_atsi[delta_atsi_count] = dest->atsi[c2]; | 462 | delta_atsi[delta_atsi_count] = dest->atsi[c2]; |
467 | delta_atsi_count ++; | 463 | delta_atsi_count++; |
468 | /* Set new value */ | 464 | /* Set new value */ |
469 | dest->atsi[c2].value = update[c1].value; | 465 | dest->atsi[c2].value = update[c1].value; |
470 | change = GNUNET_YES; | 466 | change = GNUNET_YES; |
@@ -476,10 +472,10 @@ disassemble_ats_information (struct ATS_Address *dest, | |||
476 | if (GNUNET_NO == found) | 472 | if (GNUNET_NO == found) |
477 | { | 473 | { |
478 | add_atsi[add_atsi_count] = update[c1]; | 474 | add_atsi[add_atsi_count] = update[c1]; |
479 | add_atsi_count ++; | 475 | add_atsi_count++; |
480 | delta_atsi[delta_atsi_count].type = update[c1].type; | 476 | delta_atsi[delta_atsi_count].type = update[c1].type; |
481 | delta_atsi[delta_atsi_count].value = htonl (GNUNET_ATS_VALUE_UNDEFINED); | 477 | delta_atsi[delta_atsi_count].value = htonl (GNUNET_ATS_VALUE_UNDEFINED); |
482 | delta_atsi_count ++; | 478 | delta_atsi_count++; |
483 | } | 479 | } |
484 | } | 480 | } |
485 | 481 | ||
@@ -488,10 +484,12 @@ disassemble_ats_information (struct ATS_Address *dest, | |||
488 | /* Extend ats performance information */ | 484 | /* Extend ats performance information */ |
489 | 485 | ||
490 | tmp_atsi = GNUNET_malloc ((dest->atsi_count + add_atsi_count) * | 486 | tmp_atsi = GNUNET_malloc ((dest->atsi_count + add_atsi_count) * |
491 | (sizeof (struct GNUNET_ATS_Information))); | 487 | (sizeof (struct GNUNET_ATS_Information))); |
492 | memcpy (tmp_atsi, dest->atsi, dest->atsi_count * sizeof (struct GNUNET_ATS_Information)); | 488 | memcpy (tmp_atsi, dest->atsi, |
493 | memcpy (&tmp_atsi[dest->atsi_count], add_atsi, add_atsi_count * sizeof (struct GNUNET_ATS_Information)); | 489 | dest->atsi_count * sizeof(struct GNUNET_ATS_Information)); |
494 | GNUNET_free (dest->atsi); | 490 | memcpy (&tmp_atsi[dest->atsi_count], add_atsi, |
491 | add_atsi_count * sizeof(struct GNUNET_ATS_Information)); | ||
492 | GNUNET_free(dest->atsi); | ||
495 | dest->atsi = tmp_atsi; | 493 | dest->atsi = tmp_atsi; |
496 | dest->atsi_count = dest->atsi_count + add_atsi_count; | 494 | dest->atsi_count = dest->atsi_count + add_atsi_count; |
497 | change = GNUNET_YES; | 495 | change = GNUNET_YES; |
@@ -500,8 +498,10 @@ disassemble_ats_information (struct ATS_Address *dest, | |||
500 | if (delta_atsi_count > 0) | 498 | if (delta_atsi_count > 0) |
501 | { | 499 | { |
502 | /* Copy delta */ | 500 | /* Copy delta */ |
503 | (*delta_dest) = GNUNET_malloc (delta_atsi_count * sizeof (struct GNUNET_ATS_Information)); | 501 | (*delta_dest) = |
504 | memcpy ((*delta_dest), delta_atsi, delta_atsi_count * sizeof (struct GNUNET_ATS_Information)); | 502 | GNUNET_malloc (delta_atsi_count * sizeof (struct GNUNET_ATS_Information)); |
503 | memcpy ((*delta_dest), delta_atsi, | ||
504 | delta_atsi_count * sizeof(struct GNUNET_ATS_Information)); | ||
505 | (*delta_count) = delta_atsi_count; | 505 | (*delta_count) = delta_atsi_count; |
506 | } | 506 | } |
507 | 507 | ||
@@ -516,9 +516,9 @@ disassemble_ats_information (struct ATS_Address *dest, | |||
516 | static void | 516 | static void |
517 | free_address (struct ATS_Address *addr) | 517 | free_address (struct ATS_Address *addr) |
518 | { | 518 | { |
519 | GNUNET_free (addr->plugin); | 519 | GNUNET_free(addr->plugin); |
520 | GNUNET_free_non_null (addr->atsi); | 520 | GNUNET_free_non_null(addr->atsi); |
521 | GNUNET_free (addr); | 521 | GNUNET_free(addr); |
522 | } | 522 | } |
523 | 523 | ||
524 | /** | 524 | /** |
@@ -532,10 +532,8 @@ free_address (struct ATS_Address *addr) | |||
532 | * @return the ATS_Address | 532 | * @return the ATS_Address |
533 | */ | 533 | */ |
534 | static struct ATS_Address * | 534 | static struct ATS_Address * |
535 | create_address (const struct GNUNET_PeerIdentity *peer, | 535 | create_address (const struct GNUNET_PeerIdentity *peer, const char *plugin_name, |
536 | const char *plugin_name, | 536 | const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id) |
537 | const void *plugin_addr, size_t plugin_addr_len, | ||
538 | uint32_t session_id) | ||
539 | { | 537 | { |
540 | struct ATS_Address *aa = NULL; | 538 | struct ATS_Address *aa = NULL; |
541 | int c1; | 539 | int c1; |
@@ -553,20 +551,19 @@ create_address (const struct GNUNET_PeerIdentity *peer, | |||
553 | aa->solver_information = NULL; | 551 | aa->solver_information = NULL; |
554 | aa->atsi = NULL; | 552 | aa->atsi = NULL; |
555 | aa->atsi_count = 0; | 553 | aa->atsi_count = 0; |
556 | aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0); | 554 | aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init (0); |
557 | aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0); | 555 | aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init (0); |
558 | 556 | ||
559 | for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1 ++) | 557 | for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++) |
560 | { | 558 | { |
561 | aa->atsin[c1].avg_queue_index = 0; | 559 | aa->atsin[c1].avg_queue_index = 0; |
562 | for (c2 = 0; c2 < GAS_normalization_queue_length; c2++) | 560 | for (c2 = 0; c2 < GAS_normalization_queue_length; c2++) |
563 | aa->atsin[c1].atsi_abs[c2] = GNUNET_ATS_VALUE_UNDEFINED; | 561 | aa->atsin[c1].atsi_abs[c2] = GNUNET_ATS_VALUE_UNDEFINED; |
564 | } | 562 | } |
565 | 563 | ||
566 | return aa; | 564 | return aa; |
567 | } | 565 | } |
568 | 566 | ||
569 | |||
570 | struct CompareAddressContext | 567 | struct CompareAddressContext |
571 | { | 568 | { |
572 | const struct ATS_Address *search; | 569 | const struct ATS_Address *search; |
@@ -602,10 +599,12 @@ compare_address_it (void *cls, const struct GNUNET_HashCode * key, void *value) | |||
602 | * | 599 | * |
603 | * return as exact address | 600 | * return as exact address |
604 | */ | 601 | */ |
605 | if ((aa->addr_len == cac->search->addr_len) && (0 == strcmp (aa->plugin, cac->search->plugin))) | 602 | if ((aa->addr_len == cac->search->addr_len) |
603 | && (0 == strcmp (aa->plugin, cac->search->plugin))) | ||
606 | { | 604 | { |
607 | if ((0 == memcmp (aa->addr, cac->search->addr, aa->addr_len)) && (aa->session_id == cac->search->session_id)) | 605 | if ((0 == memcmp (aa->addr, cac->search->addr, aa->addr_len)) |
608 | cac->exact_address = aa; | 606 | && (aa->session_id == cac->search->session_id)) |
607 | cac->exact_address = aa; | ||
609 | } | 608 | } |
610 | 609 | ||
611 | /* Find an matching base address: | 610 | /* Find an matching base address: |
@@ -621,10 +620,12 @@ compare_address_it (void *cls, const struct GNUNET_HashCode * key, void *value) | |||
621 | * | 620 | * |
622 | * return as base address | 621 | * return as base address |
623 | */ | 622 | */ |
624 | if ((aa->addr_len == cac->search->addr_len) && (0 == strcmp (aa->plugin, cac->search->plugin))) | 623 | if ((aa->addr_len == cac->search->addr_len) |
624 | && (0 == strcmp (aa->plugin, cac->search->plugin))) | ||
625 | { | 625 | { |
626 | if ((0 == memcmp (aa->addr, cac->search->addr, aa->addr_len)) && (aa->session_id == 0)) | 626 | if ((0 == memcmp (aa->addr, cac->search->addr, aa->addr_len)) |
627 | cac->base_address = aa; | 627 | && (aa->session_id == 0)) |
628 | cac->base_address = aa; | ||
628 | } | 629 | } |
629 | 630 | ||
630 | /* Find an matching exact address based on session: | 631 | /* Find an matching exact address based on session: |
@@ -641,17 +642,17 @@ compare_address_it (void *cls, const struct GNUNET_HashCode * key, void *value) | |||
641 | */ | 642 | */ |
642 | if (0 == cac->search->addr_len) | 643 | if (0 == cac->search->addr_len) |
643 | { | 644 | { |
644 | if ((0 == strcmp (aa->plugin, cac->search->plugin)) && (aa->session_id == cac->search->session_id)) | 645 | if ((0 == strcmp (aa->plugin, cac->search->plugin)) |
645 | cac->exact_address = aa; | 646 | && (aa->session_id == cac->search->session_id)) |
647 | cac->exact_address = aa; | ||
646 | } | 648 | } |
647 | 649 | ||
648 | if (cac->exact_address == NULL) | 650 | if (cac->exact_address == NULL ) |
649 | return GNUNET_YES; /* Continue iteration to find exact address */ | 651 | return GNUNET_YES; /* Continue iteration to find exact address */ |
650 | else | 652 | else |
651 | return GNUNET_NO; /* Stop iteration since we have an exact address */ | 653 | return GNUNET_NO; /* Stop iteration since we have an exact address */ |
652 | } | 654 | } |
653 | 655 | ||
654 | |||
655 | /** | 656 | /** |
656 | * Find an existing equivalent address record. | 657 | * Find an existing equivalent address record. |
657 | * Compares by peer identity and network address OR by session ID | 658 | * Compares by peer identity and network address OR by session ID |
@@ -664,23 +665,21 @@ compare_address_it (void *cls, const struct GNUNET_HashCode * key, void *value) | |||
664 | */ | 665 | */ |
665 | struct ATS_Address * | 666 | struct ATS_Address * |
666 | find_equivalent_address (struct GAS_Addresses_Handle *handle, | 667 | find_equivalent_address (struct GAS_Addresses_Handle *handle, |
667 | const struct GNUNET_PeerIdentity *peer, | 668 | const struct GNUNET_PeerIdentity *peer, const struct ATS_Address *addr) |
668 | const struct ATS_Address *addr) | ||
669 | { | 669 | { |
670 | struct CompareAddressContext cac; | 670 | struct CompareAddressContext cac; |
671 | 671 | ||
672 | cac.exact_address = NULL; | 672 | cac.exact_address = NULL; |
673 | cac.base_address = NULL; | 673 | cac.base_address = NULL; |
674 | cac.search = addr; | 674 | cac.search = addr; |
675 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey, | 675 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, |
676 | &compare_address_it, &cac); | 676 | &peer->hashPubKey, &compare_address_it, &cac); |
677 | 677 | ||
678 | if (cac.exact_address == NULL) | 678 | if (cac.exact_address == NULL ) |
679 | return cac.base_address; | 679 | return cac.base_address; |
680 | return cac.exact_address; | 680 | return cac.exact_address; |
681 | } | 681 | } |
682 | 682 | ||
683 | |||
684 | /** | 683 | /** |
685 | * Find the exact address | 684 | * Find the exact address |
686 | * | 685 | * |
@@ -695,31 +694,25 @@ find_equivalent_address (struct GAS_Addresses_Handle *handle, | |||
695 | 694 | ||
696 | static struct ATS_Address * | 695 | static struct ATS_Address * |
697 | find_exact_address (struct GAS_Addresses_Handle *handle, | 696 | find_exact_address (struct GAS_Addresses_Handle *handle, |
698 | const struct GNUNET_PeerIdentity *peer, | 697 | const struct GNUNET_PeerIdentity *peer, const char *plugin_name, |
699 | const char *plugin_name, | 698 | const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id) |
700 | const void *plugin_addr, | ||
701 | size_t plugin_addr_len, | ||
702 | uint32_t session_id) | ||
703 | { | 699 | { |
704 | struct ATS_Address *aa; | 700 | struct ATS_Address *aa; |
705 | struct ATS_Address *ea; | 701 | struct ATS_Address *ea; |
706 | 702 | ||
707 | aa = create_address (peer, | 703 | aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, |
708 | plugin_name, | 704 | session_id); |
709 | plugin_addr, plugin_addr_len, | ||
710 | session_id); | ||
711 | 705 | ||
712 | /* Get existing address or address with session == 0 */ | 706 | /* Get existing address or address with session == 0 */ |
713 | ea = find_equivalent_address (handle, peer, aa); | 707 | ea = find_equivalent_address (handle, peer, aa); |
714 | free_address (aa); | 708 | free_address (aa); |
715 | if (ea == NULL) | 709 | if (ea == NULL ) |
716 | return NULL; | 710 | return NULL ; |
717 | else if (ea->session_id != session_id) | 711 | else if (ea->session_id != session_id) |
718 | return NULL; | 712 | return NULL ; |
719 | return ea; | 713 | return ea; |
720 | } | 714 | } |
721 | 715 | ||
722 | |||
723 | /** | 716 | /** |
724 | * Extract an ATS performance info from an address | 717 | * Extract an ATS performance info from an address |
725 | * | 718 | * |
@@ -730,20 +723,19 @@ find_exact_address (struct GAS_Addresses_Handle *handle, | |||
730 | static int | 723 | static int |
731 | get_performance_info (struct ATS_Address *address, uint32_t type) | 724 | get_performance_info (struct ATS_Address *address, uint32_t type) |
732 | { | 725 | { |
733 | int c1; | 726 | int c1; |
734 | GNUNET_assert (NULL != address); | 727 | GNUNET_assert(NULL != address); |
735 | 728 | ||
736 | if ((NULL == address->atsi) || (0 == address->atsi_count)) | 729 | if ((NULL == address->atsi) || (0 == address->atsi_count)) |
737 | return GNUNET_ATS_VALUE_UNDEFINED; | 730 | return GNUNET_ATS_VALUE_UNDEFINED; |
738 | |||
739 | for (c1 = 0; c1 < address->atsi_count; c1++) | ||
740 | { | ||
741 | if (ntohl(address->atsi[c1].type) == type) | ||
742 | return ntohl(address->atsi[c1].value); | ||
743 | } | ||
744 | return GNUNET_ATS_VALUE_UNDEFINED; | ||
745 | } | ||
746 | 731 | ||
732 | for (c1 = 0; c1 < address->atsi_count; c1++) | ||
733 | { | ||
734 | if (ntohl (address->atsi[c1].type) == type) | ||
735 | return ntohl (address->atsi[c1].value); | ||
736 | } | ||
737 | return GNUNET_ATS_VALUE_UNDEFINED; | ||
738 | } | ||
747 | 739 | ||
748 | /** | 740 | /** |
749 | * Add a new address for a peer. | 741 | * Add a new address for a peer. |
@@ -759,13 +751,9 @@ get_performance_info (struct ATS_Address *address, uint32_t type) | |||
759 | */ | 751 | */ |
760 | void | 752 | void |
761 | GAS_addresses_add (struct GAS_Addresses_Handle *handle, | 753 | GAS_addresses_add (struct GAS_Addresses_Handle *handle, |
762 | const struct GNUNET_PeerIdentity *peer, | 754 | const struct GNUNET_PeerIdentity *peer, const char *plugin_name, |
763 | const char *plugin_name, | 755 | const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id, |
764 | const void *plugin_addr, | 756 | const struct GNUNET_ATS_Information *atsi, uint32_t atsi_count) |
765 | size_t plugin_addr_len, | ||
766 | uint32_t session_id, | ||
767 | const struct GNUNET_ATS_Information *atsi, | ||
768 | uint32_t atsi_count) | ||
769 | { | 757 | { |
770 | struct ATS_Address *new_address; | 758 | struct ATS_Address *new_address; |
771 | struct ATS_Address *existing_address; | 759 | struct ATS_Address *existing_address; |
@@ -775,134 +763,131 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
775 | uint32_t previous_session; | 763 | uint32_t previous_session; |
776 | int c1; | 764 | int c1; |
777 | 765 | ||
778 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 766 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received `%s' for peer `%s'\n", |
779 | "Received `%s' for peer `%s'\n", | 767 | "ADDRESS ADD", GNUNET_i2s (peer)); |
780 | "ADDRESS ADD", | ||
781 | GNUNET_i2s (peer)); | ||
782 | 768 | ||
783 | if (GNUNET_NO == handle->running) | 769 | if (GNUNET_NO == handle->running) |
784 | return; | 770 | return; |
785 | 771 | ||
786 | GNUNET_assert (NULL != handle->addresses); | 772 | GNUNET_assert(NULL != handle->addresses); |
787 | 773 | ||
788 | new_address = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, | 774 | new_address = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, |
789 | session_id); | 775 | session_id); |
790 | atsi_delta = NULL; | 776 | atsi_delta = NULL; |
791 | disassemble_ats_information (new_address, atsi, atsi_count, &atsi_delta, &atsi_delta_count); | 777 | disassemble_ats_information (new_address, atsi, atsi_count, &atsi_delta, |
792 | GNUNET_free_non_null (atsi_delta); | 778 | &atsi_delta_count); |
779 | GNUNET_free_non_null(atsi_delta); | ||
793 | addr_net = get_performance_info (new_address, GNUNET_ATS_NETWORK_TYPE); | 780 | addr_net = get_performance_info (new_address, GNUNET_ATS_NETWORK_TYPE); |
794 | if (GNUNET_ATS_VALUE_UNDEFINED == addr_net) | 781 | if (GNUNET_ATS_VALUE_UNDEFINED == addr_net) |
795 | addr_net = GNUNET_ATS_NET_UNSPECIFIED; | 782 | addr_net = GNUNET_ATS_NET_UNSPECIFIED; |
796 | 783 | ||
797 | /* Get existing address or address with session == 0 */ | 784 | /* Get existing address or address with session == 0 */ |
798 | existing_address = find_equivalent_address (handle, peer, new_address); | 785 | existing_address = find_equivalent_address (handle, peer, new_address); |
799 | if (existing_address == NULL) | 786 | if (existing_address == NULL ) |
800 | { | 787 | { |
801 | /* Add a new address */ | 788 | /* Add a new address */ |
802 | GNUNET_assert (GNUNET_OK == | 789 | GNUNET_assert( |
803 | GNUNET_CONTAINER_multihashmap_put (handle->addresses, | 790 | GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (handle->addresses, &peer->hashPubKey, new_address, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
804 | &peer->hashPubKey, new_address, | ||
805 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
806 | 791 | ||
807 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding new address %p for peer `%s', length %u, session id %u, %s\n", | 792 | GNUNET_STATISTICS_set (handle->stat, "# addresses", |
808 | new_address, GNUNET_i2s (peer), plugin_addr_len, session_id, GNUNET_ATS_print_network_type(addr_net)); | 793 | GNUNET_CONTAINER_multihashmap_size (handle->addresses), GNUNET_NO); |
794 | |||
795 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
796 | "Adding new address %p for peer `%s', length %u, session id %u, %s\n", | ||
797 | new_address, GNUNET_i2s (peer), plugin_addr_len, session_id, | ||
798 | GNUNET_ATS_print_network_type (addr_net)); | ||
809 | 799 | ||
810 | /* Tell solver about new address */ | 800 | /* Tell solver about new address */ |
811 | handle->s_add (handle->solver, new_address, addr_net); | 801 | handle->s_add (handle->solver, new_address, addr_net); |
812 | 802 | ||
813 | handle->s_bulk_start (handle->solver); | 803 | handle->s_bulk_start (handle->solver); |
814 | GAS_normalization_normalize_property (handle->addresses, new_address, atsi, atsi_count); | 804 | GAS_normalization_normalize_property (handle->addresses, new_address, atsi, |
805 | atsi_count); | ||
815 | handle->s_bulk_stop (handle->solver); | 806 | handle->s_bulk_stop (handle->solver); |
816 | 807 | ||
817 | /* Notify performance clients about new address */ | 808 | /* Notify performance clients about new address */ |
818 | GAS_performance_notify_all_clients (&new_address->peer, | 809 | GAS_performance_notify_all_clients (&new_address->peer, new_address->plugin, |
819 | new_address->plugin, | 810 | new_address->addr, new_address->addr_len, new_address->session_id, |
820 | new_address->addr, new_address->addr_len, | ||
821 | new_address->session_id, | ||
822 | new_address->atsi, new_address->atsi_count, | 811 | new_address->atsi, new_address->atsi_count, |
823 | new_address->assigned_bw_out, | 812 | new_address->assigned_bw_out, new_address->assigned_bw_in); |
824 | new_address->assigned_bw_in); | ||
825 | return; | 813 | return; |
826 | } | 814 | } |
827 | 815 | ||
828 | /* We have an existing address we can use, clean up new */ | 816 | /* We have an existing address we can use, clean up new */ |
829 | GNUNET_free (new_address->plugin); | 817 | GNUNET_free(new_address->plugin); |
830 | GNUNET_free_non_null (new_address->atsi); | 818 | GNUNET_free_non_null(new_address->atsi); |
831 | GNUNET_free (new_address); | 819 | GNUNET_free(new_address); |
832 | new_address = NULL; | 820 | new_address = NULL; |
833 | 821 | ||
834 | if (0 != existing_address->session_id) | 822 | if (0 != existing_address->session_id) |
835 | { | 823 | { |
836 | /* Should not happen */ | 824 | /* Should not happen */ |
837 | GNUNET_break (0); | 825 | GNUNET_break(0); |
838 | return; | 826 | return; |
839 | } | 827 | } |
840 | 828 | ||
841 | addr_net = get_performance_info (existing_address, GNUNET_ATS_NETWORK_TYPE); | 829 | addr_net = get_performance_info (existing_address, GNUNET_ATS_NETWORK_TYPE); |
842 | if (GNUNET_ATS_VALUE_UNDEFINED == addr_net) | 830 | if (GNUNET_ATS_VALUE_UNDEFINED == addr_net) |
843 | addr_net = GNUNET_ATS_NET_UNSPECIFIED; | 831 | addr_net = GNUNET_ATS_NET_UNSPECIFIED; |
844 | 832 | ||
845 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 833 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
846 | "Found existing address for peer `%s' %p with new session %u in network %s\n", | 834 | "Found existing address for peer `%s' %p with new session %u in network %s\n", |
847 | GNUNET_i2s (peer), | 835 | GNUNET_i2s (peer), existing_address, session_id, |
848 | existing_address, | 836 | GNUNET_ATS_print_network_type (addr_net)); |
849 | session_id, | ||
850 | GNUNET_ATS_print_network_type (addr_net)); | ||
851 | /* We have an address without an session, update this address */ | 837 | /* We have an address without an session, update this address */ |
852 | atsi_delta = NULL; | 838 | atsi_delta = NULL; |
853 | atsi_delta_count = 0; | 839 | atsi_delta_count = 0; |
854 | if (GNUNET_YES == disassemble_ats_information (existing_address, atsi, atsi_count, &atsi_delta, &atsi_delta_count)) | 840 | if (GNUNET_YES |
841 | == disassemble_ats_information (existing_address, atsi, atsi_count, | ||
842 | &atsi_delta, &atsi_delta_count)) | ||
855 | { | 843 | { |
856 | /* Notify performance clients about properties */ | 844 | /* Notify performance clients about properties */ |
857 | GAS_performance_notify_all_clients (&existing_address->peer, | 845 | GAS_performance_notify_all_clients (&existing_address->peer, |
858 | existing_address->plugin, | 846 | existing_address->plugin, existing_address->addr, |
859 | existing_address->addr, existing_address->addr_len, | 847 | existing_address->addr_len, existing_address->session_id, |
860 | existing_address->session_id, | 848 | existing_address->atsi, existing_address->atsi_count, |
861 | existing_address->atsi, existing_address->atsi_count, | 849 | existing_address->assigned_bw_out, existing_address->assigned_bw_in); |
862 | existing_address->assigned_bw_out, | ||
863 | existing_address->assigned_bw_in); | ||
864 | 850 | ||
865 | for (c1 = 0; c1 < atsi_delta_count; c1++) | 851 | for (c1 = 0; c1 < atsi_delta_count; c1++) |
866 | { | 852 | { |
867 | if ((GNUNET_ATS_NETWORK_TYPE == ntohl (atsi_delta[c1].type)) && | 853 | if ((GNUNET_ATS_NETWORK_TYPE == ntohl (atsi_delta[c1].type)) |
868 | (addr_net != ntohl (atsi_delta[c1].value))) | 854 | && (addr_net != ntohl (atsi_delta[c1].value))) |
869 | { | 855 | { |
870 | /* Network type changed */ | 856 | /* Network type changed */ |
871 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Address for peer `%s' %p changed from network %s to %s\n", | 857 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
872 | GNUNET_i2s (peer), existing_address, | 858 | "Address for peer `%s' %p changed from network %s to %s\n", |
873 | GNUNET_ATS_print_network_type (addr_net), | 859 | GNUNET_i2s (peer), existing_address, |
874 | GNUNET_ATS_print_network_type (ntohl (atsi_delta[c1].value))); | 860 | GNUNET_ATS_print_network_type (addr_net), |
875 | handle->s_address_update_network (handle->solver, existing_address, | 861 | GNUNET_ATS_print_network_type (ntohl (atsi_delta[c1].value))); |
876 | ntohl (atsi_delta[c1].value), | 862 | handle->s_address_update_network (handle->solver, existing_address, |
877 | get_performance_info (existing_address, GNUNET_ATS_NETWORK_TYPE)); | 863 | ntohl (atsi_delta[c1].value), |
878 | addr_net = get_performance_info (existing_address, GNUNET_ATS_NETWORK_TYPE); | 864 | get_performance_info (existing_address, GNUNET_ATS_NETWORK_TYPE)); |
865 | addr_net = get_performance_info (existing_address, | ||
866 | GNUNET_ATS_NETWORK_TYPE); | ||
879 | } | 867 | } |
880 | } | 868 | } |
881 | /* Notify solver about update with atsi information and session */ | 869 | /* Notify solver about update with atsi information and session */ |
882 | handle->s_bulk_start (handle->solver); | 870 | handle->s_bulk_start (handle->solver); |
883 | GAS_normalization_normalize_property (handle->addresses, existing_address, atsi, atsi_count); | 871 | GAS_normalization_normalize_property (handle->addresses, existing_address, |
872 | atsi, atsi_count); | ||
884 | handle->s_bulk_stop (handle->solver); | 873 | handle->s_bulk_stop (handle->solver); |
885 | } | 874 | } |
886 | GNUNET_free_non_null (atsi_delta); | 875 | GNUNET_free_non_null(atsi_delta); |
887 | 876 | ||
888 | /* Notify solver about new session */ | 877 | /* Notify solver about new session */ |
889 | if (existing_address->session_id == session_id) | 878 | if (existing_address->session_id == session_id) |
890 | return; /* possible, can both be 0 since address is revalidated */ | 879 | return; /* possible, can both be 0 since address is revalidated */ |
891 | 880 | ||
892 | previous_session = existing_address->session_id; | 881 | previous_session = existing_address->session_id; |
893 | existing_address->session_id = session_id; | 882 | existing_address->session_id = session_id; |
894 | handle->s_address_update_session (handle->solver, existing_address, | 883 | handle->s_address_update_session (handle->solver, existing_address, |
895 | previous_session, session_id); | 884 | previous_session, session_id); |
896 | |||
897 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
898 | "Updated existing address for peer `%s' %p length %u with new session %u in network %s\n", | ||
899 | GNUNET_i2s (peer), | ||
900 | existing_address, | ||
901 | existing_address->addr_len, | ||
902 | session_id, | ||
903 | GNUNET_ATS_print_network_type(addr_net)); | ||
904 | } | ||
905 | 885 | ||
886 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
887 | "Updated existing address for peer `%s' %p length %u with new session %u in network %s\n", | ||
888 | GNUNET_i2s (peer), existing_address, existing_address->addr_len, | ||
889 | session_id, GNUNET_ATS_print_network_type (addr_net)); | ||
890 | } | ||
906 | 891 | ||
907 | /** | 892 | /** |
908 | * Update an address with a session or performance information for a peer. | 893 | * Update an address with a session or performance information for a peer. |
@@ -921,11 +906,9 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
921 | */ | 906 | */ |
922 | void | 907 | void |
923 | GAS_addresses_update (struct GAS_Addresses_Handle *handle, | 908 | GAS_addresses_update (struct GAS_Addresses_Handle *handle, |
924 | const struct GNUNET_PeerIdentity *peer, | 909 | const struct GNUNET_PeerIdentity *peer, const char *plugin_name, |
925 | const char *plugin_name, const void *plugin_addr, | 910 | const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id, |
926 | size_t plugin_addr_len, uint32_t session_id, | 911 | const struct GNUNET_ATS_Information *atsi, uint32_t atsi_count) |
927 | const struct GNUNET_ATS_Information *atsi, | ||
928 | uint32_t atsi_count) | ||
929 | { | 912 | { |
930 | struct ATS_Address *aa; | 913 | struct ATS_Address *aa; |
931 | struct GNUNET_ATS_Information *atsi_delta; | 914 | struct GNUNET_ATS_Information *atsi_delta; |
@@ -936,12 +919,12 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
936 | if (GNUNET_NO == handle->running) | 919 | if (GNUNET_NO == handle->running) |
937 | return; | 920 | return; |
938 | 921 | ||
939 | GNUNET_assert (NULL != handle->addresses); | 922 | GNUNET_assert(NULL != handle->addresses); |
940 | 923 | ||
941 | /* Get existing address */ | 924 | /* Get existing address */ |
942 | aa = find_exact_address (handle, peer, plugin_name, | 925 | aa = find_exact_address (handle, peer, plugin_name, plugin_addr, |
943 | plugin_addr, plugin_addr_len, session_id); | 926 | plugin_addr_len, session_id); |
944 | if (aa == NULL) | 927 | if (aa == NULL ) |
945 | { | 928 | { |
946 | /* GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Tried to update unknown address for peer `%s' `%s' session id %u\n", */ | 929 | /* GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Tried to update unknown address for peer `%s' `%s' session id %u\n", */ |
947 | /* GNUNET_i2s (peer), plugin_name, session_id); */ | 930 | /* GNUNET_i2s (peer), plugin_name, session_id); */ |
@@ -951,58 +934,56 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
951 | 934 | ||
952 | if (NULL == aa->solver_information) | 935 | if (NULL == aa->solver_information) |
953 | { | 936 | { |
954 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Tried to update unknown address for peer `%s' `%s' session id %u\n", | 937 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
955 | GNUNET_i2s (peer), plugin_name, session_id); | 938 | "Tried to update unknown address for peer `%s' `%s' session id %u\n", |
939 | GNUNET_i2s (peer), plugin_name, session_id); | ||
956 | return; | 940 | return; |
957 | } | 941 | } |
958 | 942 | ||
959 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 943 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received `%s' for peer `%s' address \n", |
960 | "Received `%s' for peer `%s' address \n", | 944 | "ADDRESS UPDATE", GNUNET_i2s (peer), aa); |
961 | "ADDRESS UPDATE", | ||
962 | GNUNET_i2s (peer), aa); | ||
963 | 945 | ||
964 | /* Update address */ | 946 | /* Update address */ |
965 | if (session_id != aa->session_id) | 947 | if (session_id != aa->session_id) |
966 | { | 948 | { |
967 | /* Session changed */ | 949 | /* Session changed */ |
968 | prev_session = aa->session_id; | 950 | prev_session = aa->session_id; |
969 | aa->session_id = session_id; | 951 | aa->session_id = session_id; |
970 | handle->s_address_update_session (handle->solver, aa, prev_session, aa->session_id); | 952 | handle->s_address_update_session (handle->solver, aa, prev_session, |
953 | aa->session_id); | ||
971 | } | 954 | } |
972 | 955 | ||
973 | atsi_delta = NULL; | 956 | atsi_delta = NULL; |
974 | atsi_delta_count = 0; | 957 | atsi_delta_count = 0; |
975 | if (GNUNET_YES == disassemble_ats_information (aa, atsi, atsi_count, &atsi_delta, &atsi_delta_count)) | 958 | if (GNUNET_YES |
959 | == disassemble_ats_information (aa, atsi, atsi_count, &atsi_delta, | ||
960 | &atsi_delta_count)) | ||
976 | { | 961 | { |
977 | /* ATS properties changed */ | 962 | /* ATS properties changed */ |
978 | for (c1 = 0; c1 < atsi_delta_count; c1++) | 963 | for (c1 = 0; c1 < atsi_delta_count; c1++) |
979 | { | 964 | { |
980 | if (GNUNET_ATS_NETWORK_TYPE == ntohl (atsi_delta[c1].type)) | 965 | if (GNUNET_ATS_NETWORK_TYPE == ntohl (atsi_delta[c1].type)) |
981 | { | 966 | { |
982 | /* Network type changed */ | 967 | /* Network type changed */ |
983 | handle->s_address_update_network (handle->solver, aa, | 968 | handle->s_address_update_network (handle->solver, aa, |
984 | ntohl (atsi_delta[c1].value), | 969 | ntohl (atsi_delta[c1].value), |
985 | get_performance_info (aa, GNUNET_ATS_NETWORK_TYPE)); | 970 | get_performance_info (aa, GNUNET_ATS_NETWORK_TYPE)); |
986 | } | 971 | } |
987 | } | 972 | } |
988 | 973 | ||
989 | /* Notify performance clients about updated address */ | 974 | /* Notify performance clients about updated address */ |
990 | GAS_performance_notify_all_clients (&aa->peer, | 975 | GAS_performance_notify_all_clients (&aa->peer, aa->plugin, aa->addr, |
991 | aa->plugin, | 976 | aa->addr_len, aa->session_id, aa->atsi, aa->atsi_count, |
992 | aa->addr, aa->addr_len, | 977 | aa->assigned_bw_out, aa->assigned_bw_in); |
993 | aa->session_id, | ||
994 | aa->atsi, aa->atsi_count, | ||
995 | aa->assigned_bw_out, | ||
996 | aa->assigned_bw_in); | ||
997 | 978 | ||
998 | handle->s_bulk_start (handle->solver); | 979 | handle->s_bulk_start (handle->solver); |
999 | GAS_normalization_normalize_property (handle->addresses, aa, atsi, atsi_count); | 980 | GAS_normalization_normalize_property (handle->addresses, aa, atsi, |
981 | atsi_count); | ||
1000 | handle->s_bulk_stop (handle->solver); | 982 | handle->s_bulk_stop (handle->solver); |
1001 | } | 983 | } |
1002 | GNUNET_free_non_null (atsi_delta); | 984 | GNUNET_free_non_null(atsi_delta); |
1003 | } | 985 | } |
1004 | 986 | ||
1005 | |||
1006 | struct DestroyContext | 987 | struct DestroyContext |
1007 | { | 988 | { |
1008 | struct ATS_Address *aa; | 989 | struct ATS_Address *aa; |
@@ -1016,7 +997,6 @@ struct DestroyContext | |||
1016 | int result; | 997 | int result; |
1017 | }; | 998 | }; |
1018 | 999 | ||
1019 | |||
1020 | /** | 1000 | /** |
1021 | * Delete an address | 1001 | * Delete an address |
1022 | * | 1002 | * |
@@ -1030,33 +1010,32 @@ struct DestroyContext | |||
1030 | * @return GNUNET_OK (continue to iterate) | 1010 | * @return GNUNET_OK (continue to iterate) |
1031 | */ | 1011 | */ |
1032 | static int | 1012 | static int |
1033 | destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, void *value) | 1013 | destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, |
1014 | void *value) | ||
1034 | { | 1015 | { |
1035 | struct DestroyContext *dc = cls; | 1016 | struct DestroyContext *dc = cls; |
1036 | struct GAS_Addresses_Handle *handle = dc->handle; | 1017 | struct GAS_Addresses_Handle *handle = dc->handle; |
1037 | const struct ATS_Address *des = dc->aa; | 1018 | const struct ATS_Address *des = dc->aa; |
1038 | struct ATS_Address *aa = value; | 1019 | struct ATS_Address *aa = value; |
1039 | 1020 | ||
1040 | GNUNET_assert (0 == memcmp (&aa->peer, &des->peer, | 1021 | GNUNET_assert( |
1041 | sizeof (struct GNUNET_PeerIdentity))); | 1022 | 0 == memcmp (&aa->peer, &des->peer, sizeof(struct GNUNET_PeerIdentity))); |
1042 | |||
1043 | 1023 | ||
1044 | if (des->session_id == 0) | 1024 | if (des->session_id == 0) |
1045 | { | 1025 | { |
1046 | /* Session == 0, remove full address */ | 1026 | /* Session == 0, remove full address */ |
1047 | if ((0 == strcmp (des->plugin, aa->plugin)) && | 1027 | if ((0 == strcmp (des->plugin, aa->plugin)) |
1048 | (aa->addr_len == des->addr_len) && | 1028 | && (aa->addr_len == des->addr_len) |
1049 | (0 == memcmp (des->addr, aa->addr, aa->addr_len))) | 1029 | && (0 == memcmp (des->addr, aa->addr, aa->addr_len))) |
1050 | { | 1030 | { |
1051 | 1031 | ||
1052 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1032 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1053 | "Deleting full address for peer `%s' session %u %p\n", | 1033 | "Deleting full address for peer `%s' session %u %p\n", |
1054 | GNUNET_i2s (&aa->peer), aa->session_id, aa); | 1034 | GNUNET_i2s (&aa->peer), aa->session_id, aa); |
1055 | 1035 | ||
1056 | /* Notify solver about deletion */ | 1036 | /* Notify solver about deletion */ |
1057 | GNUNET_assert (GNUNET_YES == | 1037 | GNUNET_assert( |
1058 | GNUNET_CONTAINER_multihashmap_remove (handle->addresses, | 1038 | GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->addresses, &aa->peer.hashPubKey, aa)); |
1059 | &aa->peer.hashPubKey, aa)); | ||
1060 | handle->s_del (handle->solver, aa, GNUNET_NO); | 1039 | handle->s_del (handle->solver, aa, GNUNET_NO); |
1061 | free_address (aa); | 1040 | free_address (aa); |
1062 | dc->result = GNUNET_NO; | 1041 | dc->result = GNUNET_NO; |
@@ -1069,49 +1048,46 @@ destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, void *valu | |||
1069 | if (aa->session_id != des->session_id) | 1048 | if (aa->session_id != des->session_id) |
1070 | return GNUNET_OK; /* irrelevant */ | 1049 | return GNUNET_OK; /* irrelevant */ |
1071 | 1050 | ||
1072 | if ((aa->session_id != 0) && | 1051 | if ((aa->session_id != 0) && (0 != strcmp (des->plugin, aa->plugin))) |
1073 | (0 != strcmp (des->plugin, aa->plugin))) | ||
1074 | { | 1052 | { |
1075 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1053 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1076 | "Different plugins during removal: `%s' vs `%s' \n", | 1054 | "Different plugins during removal: `%s' vs `%s' \n", des->plugin, |
1077 | des->plugin, aa->plugin); | 1055 | aa->plugin); |
1078 | GNUNET_break (0); | 1056 | GNUNET_break(0); |
1079 | return GNUNET_OK; | 1057 | return GNUNET_OK; |
1080 | } | 1058 | } |
1081 | 1059 | ||
1082 | if (aa->addr_len == 0) | 1060 | if (aa->addr_len == 0) |
1083 | { | 1061 | { |
1084 | /* Inbound connection died, delete full address */ | 1062 | /* Inbound connection died, delete full address */ |
1085 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1063 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1086 | "Deleting inbound address for peer `%s': `%s' session %u\n", | 1064 | "Deleting inbound address for peer `%s': `%s' session %u\n", |
1087 | GNUNET_i2s (&aa->peer), aa->plugin, aa->session_id); | 1065 | GNUNET_i2s (&aa->peer), aa->plugin, aa->session_id); |
1088 | 1066 | ||
1089 | /* Notify solver about deletion */ | 1067 | /* Notify solver about deletion */ |
1090 | GNUNET_assert (GNUNET_YES == | 1068 | GNUNET_assert( |
1091 | GNUNET_CONTAINER_multihashmap_remove (handle->addresses, | 1069 | GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->addresses, &aa->peer.hashPubKey, aa)); |
1092 | &aa->peer.hashPubKey, aa)); | 1070 | handle->s_del (handle->solver, aa, GNUNET_NO); |
1093 | handle->s_del (handle->solver, aa, GNUNET_NO); | 1071 | free_address (aa); |
1094 | free_address (aa); | 1072 | dc->result = GNUNET_NO; |
1095 | dc->result = GNUNET_NO; | 1073 | return GNUNET_OK; /* Continue iteration */ |
1096 | return GNUNET_OK; /* Continue iteration */ | ||
1097 | } | 1074 | } |
1098 | else | 1075 | else |
1099 | { | 1076 | { |
1100 | /* Session died */ | 1077 | /* Session died */ |
1101 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1078 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1102 | "Deleting session for peer `%s': `%s' %u\n", | 1079 | "Deleting session for peer `%s': `%s' %u\n", GNUNET_i2s (&aa->peer), |
1103 | GNUNET_i2s (&aa->peer), aa->plugin, aa->session_id); | 1080 | aa->plugin, aa->session_id); |
1104 | /* Notify solver to delete session */ | 1081 | /* Notify solver to delete session */ |
1105 | handle->s_del (handle->solver, aa, GNUNET_YES); | 1082 | handle->s_del (handle->solver, aa, GNUNET_YES); |
1106 | aa->session_id = 0; | 1083 | aa->session_id = 0; |
1107 | aa->active = GNUNET_NO; | 1084 | aa->active = GNUNET_NO; |
1108 | return GNUNET_OK; | 1085 | return GNUNET_OK; |
1109 | } | 1086 | } |
1110 | } | 1087 | } |
1111 | return GNUNET_OK; | 1088 | return GNUNET_OK; |
1112 | } | 1089 | } |
1113 | 1090 | ||
1114 | |||
1115 | /** | 1091 | /** |
1116 | * Remove an address or just a session for a peer. | 1092 | * Remove an address or just a session for a peer. |
1117 | * | 1093 | * |
@@ -1124,11 +1100,8 @@ destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, void *valu | |||
1124 | */ | 1100 | */ |
1125 | void | 1101 | void |
1126 | GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, | 1102 | GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, |
1127 | const struct GNUNET_PeerIdentity *peer, | 1103 | const struct GNUNET_PeerIdentity *peer, const char *plugin_name, |
1128 | const char *plugin_name, | 1104 | const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id) |
1129 | const void *plugin_addr, | ||
1130 | size_t plugin_addr_len, | ||
1131 | uint32_t session_id) | ||
1132 | { | 1105 | { |
1133 | struct ATS_Address *ea; | 1106 | struct ATS_Address *ea; |
1134 | struct DestroyContext dc; | 1107 | struct DestroyContext dc; |
@@ -1137,29 +1110,31 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, | |||
1137 | 1110 | ||
1138 | /* Get existing address */ | 1111 | /* Get existing address */ |
1139 | ea = find_exact_address (handle, peer, plugin_name, plugin_addr, | 1112 | ea = find_exact_address (handle, peer, plugin_name, plugin_addr, |
1140 | plugin_addr_len, session_id); | 1113 | plugin_addr_len, session_id); |
1141 | if (ea == NULL) | 1114 | if (ea == NULL ) |
1142 | { | 1115 | { |
1143 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Tried to destroy unknown address for peer `%s' `%s' session id %u\n", | 1116 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1144 | GNUNET_i2s (peer), plugin_name, session_id); | 1117 | "Tried to destroy unknown address for peer `%s' `%s' session id %u\n", |
1118 | GNUNET_i2s (peer), plugin_name, session_id); | ||
1145 | return; | 1119 | return; |
1146 | } | 1120 | } |
1147 | 1121 | ||
1148 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1122 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1149 | "Received `%s' for peer `%s' address %p session %u\n", | 1123 | "Received `%s' for peer `%s' address %p session %u\n", "ADDRESS DESTROY", |
1150 | "ADDRESS DESTROY", | 1124 | GNUNET_i2s (peer), ea, session_id); |
1151 | GNUNET_i2s (peer), ea, session_id); | ||
1152 | 1125 | ||
1153 | GNUNET_break (0 < strlen (plugin_name)); | 1126 | GNUNET_break(0 < strlen (plugin_name)); |
1154 | dc.handle = handle; | 1127 | dc.handle = handle; |
1155 | dc.aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, session_id); | 1128 | dc.aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, |
1129 | session_id); | ||
1156 | 1130 | ||
1157 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey, | 1131 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, |
1158 | &destroy_by_session_id, &dc); | 1132 | &peer->hashPubKey, &destroy_by_session_id, &dc); |
1133 | GNUNET_STATISTICS_set (handle->stat, "# addresses", | ||
1134 | GNUNET_CONTAINER_multihashmap_size (handle->addresses), GNUNET_NO); | ||
1159 | free_address (dc.aa); | 1135 | free_address (dc.aa); |
1160 | } | 1136 | } |
1161 | 1137 | ||
1162 | |||
1163 | /** | 1138 | /** |
1164 | * Notification about active use of an address. | 1139 | * Notification about active use of an address. |
1165 | * in_use == GNUNET_YES: | 1140 | * in_use == GNUNET_YES: |
@@ -1181,42 +1156,35 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, | |||
1181 | */ | 1156 | */ |
1182 | int | 1157 | int |
1183 | GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, | 1158 | GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, |
1184 | const struct GNUNET_PeerIdentity *peer, | 1159 | const struct GNUNET_PeerIdentity *peer, const char *plugin_name, |
1185 | const char *plugin_name, | 1160 | const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id, |
1186 | const void *plugin_addr, | 1161 | int in_use) |
1187 | size_t plugin_addr_len, | ||
1188 | uint32_t session_id, | ||
1189 | int in_use) | ||
1190 | { | 1162 | { |
1191 | struct ATS_Address *ea; | 1163 | struct ATS_Address *ea; |
1192 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1164 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received `%s' for peer `%s'\n", |
1193 | "Received `%s' for peer `%s'\n", | 1165 | "ADDRESS IN USE", GNUNET_i2s (peer)); |
1194 | "ADDRESS IN USE", | ||
1195 | GNUNET_i2s (peer)); | ||
1196 | 1166 | ||
1197 | if (GNUNET_NO == handle->running) | 1167 | if (GNUNET_NO == handle->running) |
1198 | return GNUNET_SYSERR; | 1168 | return GNUNET_SYSERR; |
1199 | 1169 | ||
1200 | ea = find_exact_address (handle, peer, plugin_name, | 1170 | ea = find_exact_address (handle, peer, plugin_name, plugin_addr, |
1201 | plugin_addr, plugin_addr_len, session_id); | 1171 | plugin_addr_len, session_id); |
1202 | if (NULL == ea) | 1172 | if (NULL == ea) |
1203 | { | 1173 | { |
1204 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1174 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1205 | "Trying to set unknown address `%s' `%s' `%u' to %s \n", | 1175 | "Trying to set unknown address `%s' `%s' `%u' to %s \n", |
1206 | GNUNET_i2s (peer), | 1176 | GNUNET_i2s (peer), plugin_name, session_id, |
1207 | plugin_name, session_id, | 1177 | (GNUNET_NO == in_use) ? "NO" : "YES"); |
1208 | (GNUNET_NO == in_use) ? "NO" : "YES"); | 1178 | GNUNET_break(0); |
1209 | GNUNET_break (0); | ||
1210 | return GNUNET_SYSERR; | 1179 | return GNUNET_SYSERR; |
1211 | } | 1180 | } |
1212 | if (ea->used == in_use) | 1181 | if (ea->used == in_use) |
1213 | { | 1182 | { |
1214 | GNUNET_break (0); | 1183 | GNUNET_break(0); |
1215 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1184 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1216 | "Address in use called multiple times for peer `%s': %s -> %s \n", | 1185 | "Address in use called multiple times for peer `%s': %s -> %s \n", |
1217 | GNUNET_i2s (peer), | 1186 | GNUNET_i2s (peer), (GNUNET_NO == ea->used) ? "NO" : "YES", |
1218 | (GNUNET_NO == ea->used) ? "NO" : "YES", | 1187 | (GNUNET_NO == in_use) ? "NO" : "YES"); |
1219 | (GNUNET_NO == in_use) ? "NO" : "YES"); | ||
1220 | return GNUNET_SYSERR; | 1188 | return GNUNET_SYSERR; |
1221 | } | 1189 | } |
1222 | 1190 | ||
@@ -1226,7 +1194,6 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, | |||
1226 | return GNUNET_OK; | 1194 | return GNUNET_OK; |
1227 | } | 1195 | } |
1228 | 1196 | ||
1229 | |||
1230 | /** | 1197 | /** |
1231 | * Cancel address suggestions for a peer | 1198 | * Cancel address suggestions for a peer |
1232 | * | 1199 | * |
@@ -1235,51 +1202,52 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, | |||
1235 | */ | 1202 | */ |
1236 | void | 1203 | void |
1237 | GAS_addresses_request_address_cancel (struct GAS_Addresses_Handle *handle, | 1204 | GAS_addresses_request_address_cancel (struct GAS_Addresses_Handle *handle, |
1238 | const struct GNUNET_PeerIdentity *peer) | 1205 | const struct GNUNET_PeerIdentity *peer) |
1239 | { | 1206 | { |
1240 | struct GAS_Addresses_Suggestion_Requests *cur = handle->r_head; | 1207 | struct GAS_Addresses_Suggestion_Requests *cur = handle->r_head; |
1241 | 1208 | ||
1242 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1209 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received request: `%s' for peer %s\n", |
1243 | "Received request: `%s' for peer %s\n", "request_address_cancel", GNUNET_i2s (peer)); | 1210 | "request_address_cancel", GNUNET_i2s (peer)); |
1244 | 1211 | ||
1245 | while (NULL != cur) | 1212 | while (NULL != cur) |
1246 | { | 1213 | { |
1247 | if (0 == memcmp (peer, &cur->id, sizeof (cur->id))) | 1214 | if (0 == memcmp (peer, &cur->id, sizeof(cur->id))) |
1248 | break; /* found */ | 1215 | break; /* found */ |
1249 | cur = cur->next; | 1216 | cur = cur->next; |
1250 | } | 1217 | } |
1251 | 1218 | ||
1252 | if (NULL == cur) | 1219 | if (NULL == cur) |
1253 | { | 1220 | { |
1254 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1221 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1255 | "No address requests pending for peer `%s', cannot remove!\n", GNUNET_i2s (peer)); | 1222 | "No address requests pending for peer `%s', cannot remove!\n", |
1256 | return; | 1223 | GNUNET_i2s (peer)); |
1224 | return; | ||
1257 | } | 1225 | } |
1258 | handle->s_get_stop (handle->solver, peer); | 1226 | handle->s_get_stop (handle->solver, peer); |
1259 | GAS_addresses_handle_backoff_reset (handle, peer); | 1227 | GAS_addresses_handle_backoff_reset (handle, peer); |
1260 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1228 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Removed request pending for peer `%s\n", |
1261 | "Removed request pending for peer `%s\n", GNUNET_i2s (peer)); | 1229 | GNUNET_i2s (peer)); |
1262 | GNUNET_CONTAINER_DLL_remove (handle->r_head, handle->r_tail, cur); | 1230 | GNUNET_CONTAINER_DLL_remove(handle->r_head, handle->r_tail, cur); |
1263 | GNUNET_free (cur); | 1231 | GNUNET_free(cur); |
1264 | } | 1232 | } |
1265 | 1233 | ||
1266 | /* | 1234 | /* |
1267 | static int | 1235 | static int |
1268 | addrinfo_it (void *cls, const struct GNUNET_HashCode *key, void *value) | 1236 | addrinfo_it (void *cls, const struct GNUNET_HashCode *key, void *value) |
1269 | { | 1237 | { |
1270 | static int count = 0; | 1238 | static int count = 0; |
1271 | struct GNUNET_PeerIdentity *id = cls; | 1239 | struct GNUNET_PeerIdentity *id = cls; |
1272 | struct ATS_Address *aa = value; | 1240 | struct ATS_Address *aa = value; |
1273 | 1241 | ||
1274 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1242 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1275 | "[%u] Peer `%s' %s length %u session %u active %s\n", | 1243 | "[%u] Peer `%s' %s length %u session %u active %s\n", |
1276 | count, GNUNET_i2s (id), aa->plugin, aa->addr_len, aa->session_id, | 1244 | count, GNUNET_i2s (id), aa->plugin, aa->addr_len, aa->session_id, |
1277 | (GNUNET_YES == aa->active) ? "active" : "inactive"); | 1245 | (GNUNET_YES == aa->active) ? "active" : "inactive"); |
1278 | 1246 | ||
1279 | count ++; | 1247 | count ++; |
1280 | return GNUNET_OK; | 1248 | return GNUNET_OK; |
1281 | } | 1249 | } |
1282 | */ | 1250 | */ |
1283 | 1251 | ||
1284 | /** | 1252 | /** |
1285 | * Request address suggestions for a peer | 1253 | * Request address suggestions for a peer |
@@ -1289,29 +1257,27 @@ addrinfo_it (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
1289 | */ | 1257 | */ |
1290 | void | 1258 | void |
1291 | GAS_addresses_request_address (struct GAS_Addresses_Handle *handle, | 1259 | GAS_addresses_request_address (struct GAS_Addresses_Handle *handle, |
1292 | const struct GNUNET_PeerIdentity *peer) | 1260 | const struct GNUNET_PeerIdentity *peer) |
1293 | { | 1261 | { |
1294 | struct GAS_Addresses_Suggestion_Requests *cur = handle->r_head; | 1262 | struct GAS_Addresses_Suggestion_Requests *cur = handle->r_head; |
1295 | struct ATS_Address *aa; | 1263 | struct ATS_Address *aa; |
1296 | 1264 | ||
1297 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1265 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received `%s' for peer `%s'\n", |
1298 | "Received `%s' for peer `%s'\n", | 1266 | "REQUEST ADDRESS", GNUNET_i2s (peer)); |
1299 | "REQUEST ADDRESS", | ||
1300 | GNUNET_i2s (peer)); | ||
1301 | 1267 | ||
1302 | if (GNUNET_NO == handle->running) | 1268 | if (GNUNET_NO == handle->running) |
1303 | return; | 1269 | return; |
1304 | while (NULL != cur) | 1270 | while (NULL != cur) |
1305 | { | 1271 | { |
1306 | if (0 == memcmp (peer, &cur->id, sizeof (cur->id))) | 1272 | if (0 == memcmp (peer, &cur->id, sizeof(cur->id))) |
1307 | break; /* already suggesting */ | 1273 | break; /* already suggesting */ |
1308 | cur = cur->next; | 1274 | cur = cur->next; |
1309 | } | 1275 | } |
1310 | if (NULL == cur) | 1276 | if (NULL == cur) |
1311 | { | 1277 | { |
1312 | cur = GNUNET_malloc (sizeof (struct GAS_Addresses_Suggestion_Requests)); | 1278 | cur = GNUNET_malloc (sizeof (struct GAS_Addresses_Suggestion_Requests)); |
1313 | cur->id = (*peer); | 1279 | cur->id = (*peer); |
1314 | GNUNET_CONTAINER_DLL_insert (handle->r_head, handle->r_tail, cur); | 1280 | GNUNET_CONTAINER_DLL_insert(handle->r_head, handle->r_tail, cur); |
1315 | } | 1281 | } |
1316 | 1282 | ||
1317 | /* | 1283 | /* |
@@ -1325,31 +1291,28 @@ GAS_addresses_request_address (struct GAS_Addresses_Handle *handle, | |||
1325 | aa = (struct ATS_Address *) handle->s_get (handle->solver, peer); | 1291 | aa = (struct ATS_Address *) handle->s_get (handle->solver, peer); |
1326 | if (NULL == aa) | 1292 | if (NULL == aa) |
1327 | { | 1293 | { |
1328 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1294 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Cannot suggest address for peer `%s'\n", |
1329 | "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer)); | 1295 | GNUNET_i2s (peer)); |
1330 | return; | 1296 | return; |
1331 | } | 1297 | } |
1332 | 1298 | ||
1333 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1299 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Suggesting address %p for peer `%s'\n", |
1334 | "Suggesting address %p for peer `%s'\n", aa, GNUNET_i2s (peer)); | 1300 | aa, GNUNET_i2s (peer)); |
1335 | 1301 | ||
1336 | GAS_scheduling_transmit_address_suggestion (peer, | 1302 | GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, aa->addr, |
1337 | aa->plugin, | 1303 | aa->addr_len, aa->session_id, aa->atsi, aa->atsi_count, |
1338 | aa->addr, aa->addr_len, | 1304 | aa->assigned_bw_out, aa->assigned_bw_in); |
1339 | aa->session_id, | ||
1340 | aa->atsi, aa->atsi_count, | ||
1341 | aa->assigned_bw_out, | ||
1342 | aa->assigned_bw_in); | ||
1343 | 1305 | ||
1344 | aa->block_interval = GNUNET_TIME_relative_add (aa->block_interval, ATS_BLOCKING_DELTA); | 1306 | aa->block_interval = GNUNET_TIME_relative_add (aa->block_interval, |
1345 | aa->blocked_until = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), aa->block_interval); | 1307 | ATS_BLOCKING_DELTA); |
1308 | aa->blocked_until = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), | ||
1309 | aa->block_interval); | ||
1346 | 1310 | ||
1347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1311 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1348 | "Address %p ready for suggestion, block interval now %llu \n", | 1312 | "Address %p ready for suggestion, block interval now %llu \n", aa, |
1349 | aa, aa->block_interval); | 1313 | aa->block_interval); |
1350 | } | 1314 | } |
1351 | 1315 | ||
1352 | |||
1353 | /** | 1316 | /** |
1354 | * Iterator to reset address blocking | 1317 | * Iterator to reset address blocking |
1355 | * | 1318 | * |
@@ -1363,16 +1326,15 @@ reset_address_it (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
1363 | { | 1326 | { |
1364 | struct ATS_Address *aa = value; | 1327 | struct ATS_Address *aa = value; |
1365 | 1328 | ||
1366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1329 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1367 | "Resetting interval for peer `%s' address %p from %llu to 0\n", | 1330 | "Resetting interval for peer `%s' address %p from %llu to 0\n", |
1368 | GNUNET_i2s (&aa->peer), aa, aa->block_interval); | 1331 | GNUNET_i2s (&aa->peer), aa, aa->block_interval); |
1369 | 1332 | ||
1370 | aa->blocked_until = GNUNET_TIME_UNIT_ZERO_ABS; | 1333 | aa->blocked_until = GNUNET_TIME_UNIT_ZERO_ABS; |
1371 | aa->block_interval = GNUNET_TIME_UNIT_ZERO; | 1334 | aa->block_interval = GNUNET_TIME_UNIT_ZERO; |
1372 | return GNUNET_OK; | 1335 | return GNUNET_OK; |
1373 | } | 1336 | } |
1374 | 1337 | ||
1375 | |||
1376 | /** | 1338 | /** |
1377 | * Reset suggestion backoff for a peer | 1339 | * Reset suggestion backoff for a peer |
1378 | * | 1340 | * |
@@ -1384,19 +1346,14 @@ reset_address_it (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
1384 | */ | 1346 | */ |
1385 | void | 1347 | void |
1386 | GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle, | 1348 | GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle, |
1387 | const struct GNUNET_PeerIdentity *peer) | 1349 | const struct GNUNET_PeerIdentity *peer) |
1388 | { | 1350 | { |
1389 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1351 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received `%s' for peer `%s'\n", |
1390 | "Received `%s' for peer `%s'\n", | 1352 | "RESET BACKOFF", GNUNET_i2s (peer)); |
1391 | "RESET BACKOFF", | ||
1392 | GNUNET_i2s (peer)); | ||
1393 | |||
1394 | GNUNET_break (GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, | ||
1395 | &peer->hashPubKey, | ||
1396 | &reset_address_it, | ||
1397 | NULL)); | ||
1398 | } | ||
1399 | 1353 | ||
1354 | GNUNET_break( | ||
1355 | GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey, &reset_address_it, NULL)); | ||
1356 | } | ||
1400 | 1357 | ||
1401 | /** | 1358 | /** |
1402 | * The preference changed for a peer | 1359 | * The preference changed for a peer |
@@ -1408,18 +1365,16 @@ GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle, | |||
1408 | */ | 1365 | */ |
1409 | static void | 1366 | static void |
1410 | normalized_preference_changed_cb (void *cls, | 1367 | normalized_preference_changed_cb (void *cls, |
1411 | const struct GNUNET_PeerIdentity *peer, | 1368 | const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind, |
1412 | enum GNUNET_ATS_PreferenceKind kind, | 1369 | double pref_rel) |
1413 | double pref_rel) | ||
1414 | { | 1370 | { |
1415 | GNUNET_assert (NULL != cls); | 1371 | GNUNET_assert(NULL != cls); |
1416 | struct GAS_Addresses_Handle *handle = cls; | 1372 | struct GAS_Addresses_Handle *handle = cls; |
1417 | 1373 | ||
1418 | /* Tell solver about update */ | 1374 | /* Tell solver about update */ |
1419 | handle->s_pref (handle->solver, peer, kind, pref_rel); | 1375 | handle->s_pref (handle->solver, peer, kind, pref_rel); |
1420 | } | 1376 | } |
1421 | 1377 | ||
1422 | |||
1423 | /** | 1378 | /** |
1424 | * The relative value for a property changed | 1379 | * The relative value for a property changed |
1425 | * | 1380 | * |
@@ -1429,24 +1384,20 @@ normalized_preference_changed_cb (void *cls, | |||
1429 | * @param prop_rel the new relative preference value | 1384 | * @param prop_rel the new relative preference value |
1430 | */ | 1385 | */ |
1431 | static void | 1386 | static void |
1432 | normalized_property_changed_cb (void *cls, | 1387 | normalized_property_changed_cb (void *cls, struct ATS_Address *address, |
1433 | struct ATS_Address *address, | 1388 | uint32_t type, double prop_rel) |
1434 | uint32_t type, | ||
1435 | double prop_rel) | ||
1436 | { | 1389 | { |
1437 | struct GAS_Addresses_Handle *ah = (struct GAS_Addresses_Handle *) cls; | 1390 | struct GAS_Addresses_Handle *ah = (struct GAS_Addresses_Handle *) cls; |
1438 | GNUNET_assert (NULL != ah); | 1391 | GNUNET_assert(NULL != ah); |
1439 | 1392 | ||
1440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1393 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1441 | "Normalized property %s for peer `%s' changed to %.3f \n", | 1394 | "Normalized property %s for peer `%s' changed to %.3f \n", |
1442 | GNUNET_ATS_print_property_type (type), | 1395 | GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer), |
1443 | GNUNET_i2s (&address->peer), | 1396 | prop_rel); |
1444 | prop_rel); | ||
1445 | 1397 | ||
1446 | ah->s_address_update_property (ah->solver, address, type, 0, prop_rel); | 1398 | ah->s_address_update_property (ah->solver, address, type, 0, prop_rel); |
1447 | } | 1399 | } |
1448 | 1400 | ||
1449 | |||
1450 | /** | 1401 | /** |
1451 | * Function allowing the solver to obtain normalized preference | 1402 | * Function allowing the solver to obtain normalized preference |
1452 | * values from solver | 1403 | * values from solver |
@@ -1458,7 +1409,7 @@ normalized_property_changed_cb (void *cls, | |||
1458 | const double * | 1409 | const double * |
1459 | get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) | 1410 | get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) |
1460 | { | 1411 | { |
1461 | return GAS_normalization_get_preferences (id); | 1412 | return GAS_normalization_get_preferences (id); |
1462 | } | 1413 | } |
1463 | 1414 | ||
1464 | /** | 1415 | /** |
@@ -1472,7 +1423,7 @@ get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) | |||
1472 | const double * | 1423 | const double * |
1473 | get_property_cb (void *cls, const struct ATS_Address *address) | 1424 | get_property_cb (void *cls, const struct ATS_Address *address) |
1474 | { | 1425 | { |
1475 | return GAS_normalization_get_properties ((struct ATS_Address *) address); | 1426 | return GAS_normalization_get_properties ((struct ATS_Address *) address); |
1476 | } | 1427 | } |
1477 | 1428 | ||
1478 | /** | 1429 | /** |
@@ -1486,27 +1437,24 @@ get_property_cb (void *cls, const struct ATS_Address *address) | |||
1486 | */ | 1437 | */ |
1487 | void | 1438 | void |
1488 | GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle, | 1439 | GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle, |
1489 | void *client, | 1440 | void *client, const struct GNUNET_PeerIdentity *peer, |
1490 | const struct GNUNET_PeerIdentity *peer, | 1441 | enum GNUNET_ATS_PreferenceKind kind, float score_abs) |
1491 | enum GNUNET_ATS_PreferenceKind kind, | ||
1492 | float score_abs) | ||
1493 | { | 1442 | { |
1494 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1443 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1495 | "Received `%s' for peer `%s' for client %p\n", | 1444 | "Received `%s' for peer `%s' for client %p\n", "CHANGE PREFERENCE", |
1496 | "CHANGE PREFERENCE", | 1445 | GNUNET_i2s (peer), client); |
1497 | GNUNET_i2s (peer), client); | ||
1498 | 1446 | ||
1499 | if (GNUNET_NO == handle->running) | 1447 | if (GNUNET_NO == handle->running) |
1500 | return; | 1448 | return; |
1501 | 1449 | ||
1502 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->addresses, | 1450 | if (GNUNET_NO |
1503 | &peer->hashPubKey)) | 1451 | == GNUNET_CONTAINER_multihashmap_contains (handle->addresses, |
1452 | &peer->hashPubKey)) | ||
1504 | { | 1453 | { |
1505 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1454 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1506 | "Received `%s' for unknown peer `%s' from client %p\n", | 1455 | "Received `%s' for unknown peer `%s' from client %p\n", |
1507 | "CHANGE PREFERENCE", | 1456 | "CHANGE PREFERENCE", GNUNET_i2s (peer), client); |
1508 | GNUNET_i2s (peer), client); | 1457 | return; |
1509 | return; | ||
1510 | } | 1458 | } |
1511 | 1459 | ||
1512 | handle->s_bulk_start (handle->solver); | 1460 | handle->s_bulk_start (handle->solver); |
@@ -1515,7 +1463,6 @@ GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle, | |||
1515 | handle->s_bulk_stop (handle->solver); | 1463 | handle->s_bulk_stop (handle->solver); |
1516 | } | 1464 | } |
1517 | 1465 | ||
1518 | |||
1519 | /** | 1466 | /** |
1520 | * Change the preference for a peer | 1467 | * Change the preference for a peer |
1521 | * | 1468 | * |
@@ -1528,34 +1475,31 @@ GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle, | |||
1528 | */ | 1475 | */ |
1529 | void | 1476 | void |
1530 | GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle, | 1477 | GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle, |
1531 | void *application, | 1478 | void *application, const struct GNUNET_PeerIdentity *peer, |
1532 | const struct GNUNET_PeerIdentity *peer, | 1479 | const struct GNUNET_TIME_Relative scope, |
1533 | const struct GNUNET_TIME_Relative scope, | 1480 | enum GNUNET_ATS_PreferenceKind kind, float score_abs) |
1534 | enum GNUNET_ATS_PreferenceKind kind, | ||
1535 | float score_abs) | ||
1536 | { | 1481 | { |
1537 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1482 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1538 | "Received `%s' for peer `%s' for client %p\n", | 1483 | "Received `%s' for peer `%s' for client %p\n", "PREFERENCE FEEDBACK", |
1539 | "PREFERENCE FEEDBACK", | 1484 | GNUNET_i2s (peer), application); |
1540 | GNUNET_i2s (peer), application); | ||
1541 | 1485 | ||
1542 | if (GNUNET_NO == handle->running) | 1486 | if (GNUNET_NO == handle->running) |
1543 | return; | 1487 | return; |
1544 | 1488 | ||
1545 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->addresses, | 1489 | if (GNUNET_NO |
1546 | &peer->hashPubKey)) | 1490 | == GNUNET_CONTAINER_multihashmap_contains (handle->addresses, |
1491 | &peer->hashPubKey)) | ||
1547 | { | 1492 | { |
1548 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1493 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1549 | "Received `%s' for unknown peer `%s' from client %p\n", | 1494 | "Received `%s' for unknown peer `%s' from client %p\n", |
1550 | "PREFERENCE FEEDBACK", | 1495 | "PREFERENCE FEEDBACK", GNUNET_i2s (peer), application); |
1551 | GNUNET_i2s (peer), application); | ||
1552 | return; | 1496 | return; |
1553 | } | 1497 | } |
1554 | 1498 | ||
1555 | handle->s_feedback (handle->solver, application, peer, scope, kind, score_abs); | 1499 | handle->s_feedback (handle->solver, application, peer, scope, kind, |
1500 | score_abs); | ||
1556 | } | 1501 | } |
1557 | 1502 | ||
1558 | |||
1559 | /** | 1503 | /** |
1560 | * Load quotas for networks from configuration | 1504 | * Load quotas for networks from configuration |
1561 | * | 1505 | * |
@@ -1567,9 +1511,7 @@ GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle, | |||
1567 | */ | 1511 | */ |
1568 | static unsigned int | 1512 | static unsigned int |
1569 | load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, | 1513 | load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1570 | unsigned long long *out_dest, | 1514 | unsigned long long *out_dest, unsigned long long *in_dest, int dest_length) |
1571 | unsigned long long *in_dest, | ||
1572 | int dest_length) | ||
1573 | { | 1515 | { |
1574 | char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString; | 1516 | char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString; |
1575 | char * entry_in = NULL; | 1517 | char * entry_in = NULL; |
@@ -1587,80 +1529,102 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1587 | GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]); | 1529 | GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]); |
1588 | 1530 | ||
1589 | /* quota out */ | 1531 | /* quota out */ |
1590 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str)) | 1532 | if (GNUNET_OK |
1533 | == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", entry_out, | ||
1534 | "a_out_str)) | ||
1591 | { | 1535 | { |
1592 | res = GNUNET_NO; | 1536 | res = GNUNET_NO; |
1593 | if (0 == strcmp(quota_out_str, GNUNET_ATS_MaxBandwidthString)) | 1537 | if (0 == strcmp (quota_out_str, GNUNET_ATS_MaxBandwidthString)) |
1594 | { | 1538 | { |
1595 | out_dest[c] = GNUNET_ATS_MaxBandwidth; | 1539 | out_dest[c] = GNUNET_ATS_MaxBandwidth; |
1596 | res = GNUNET_YES; | 1540 | res = GNUNET_YES; |
1597 | } | 1541 | } |
1598 | if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c]))) | 1542 | if ((GNUNET_NO == res) |
1543 | && (GNUNET_OK | ||
1544 | == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, | ||
1545 | &out_dest[c]))) | ||
1546 | res = GNUNET_YES; | ||
1547 | if ((GNUNET_NO == res) | ||
1548 | && (GNUNET_OK | ||
1549 | == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, | ||
1550 | &out_dest[c]))) | ||
1599 | res = GNUNET_YES; | 1551 | res = GNUNET_YES; |
1600 | if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c]))) | ||
1601 | res = GNUNET_YES; | ||
1602 | 1552 | ||
1603 | if (GNUNET_NO == res) | 1553 | if (GNUNET_NO == res) |
1604 | { | 1554 | { |
1605 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), | 1555 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1606 | network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth); | 1556 | _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), |
1607 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; | 1557 | network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth); |
1558 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; | ||
1608 | } | 1559 | } |
1609 | else | 1560 | else |
1610 | { | 1561 | { |
1611 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Outbound quota configure for network `%s' is %llu\n"), | 1562 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1612 | network_str[c], out_dest[c]); | 1563 | _("Outbound quota configure for network `%s' is %llu\n"), |
1564 | network_str[c], out_dest[c]); | ||
1613 | } | 1565 | } |
1614 | GNUNET_free (quota_out_str); | 1566 | GNUNET_free(quota_out_str); |
1615 | } | 1567 | } |
1616 | else | 1568 | else |
1617 | { | 1569 | { |
1618 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"), | 1570 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1571 | _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"), | ||
1619 | network_str[c], GNUNET_ATS_DefaultBandwidth); | 1572 | network_str[c], GNUNET_ATS_DefaultBandwidth); |
1620 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; | 1573 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; |
1621 | } | 1574 | } |
1622 | 1575 | ||
1623 | /* quota in */ | 1576 | /* quota in */ |
1624 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str)) | 1577 | if (GNUNET_OK |
1578 | == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", entry_in, | ||
1579 | "a_in_str)) | ||
1625 | { | 1580 | { |
1626 | res = GNUNET_NO; | 1581 | res = GNUNET_NO; |
1627 | if (0 == strcmp(quota_in_str, GNUNET_ATS_MaxBandwidthString)) | 1582 | if (0 == strcmp (quota_in_str, GNUNET_ATS_MaxBandwidthString)) |
1628 | { | 1583 | { |
1629 | in_dest[c] = GNUNET_ATS_MaxBandwidth; | 1584 | in_dest[c] = GNUNET_ATS_MaxBandwidth; |
1630 | res = GNUNET_YES; | 1585 | res = GNUNET_YES; |
1631 | } | 1586 | } |
1632 | if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c]))) | 1587 | if ((GNUNET_NO == res) |
1588 | && (GNUNET_OK | ||
1589 | == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c]))) | ||
1590 | res = GNUNET_YES; | ||
1591 | if ((GNUNET_NO == res) | ||
1592 | && (GNUNET_OK | ||
1593 | == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, | ||
1594 | &in_dest[c]))) | ||
1633 | res = GNUNET_YES; | 1595 | res = GNUNET_YES; |
1634 | if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c]))) | ||
1635 | res = GNUNET_YES; | ||
1636 | 1596 | ||
1637 | if (GNUNET_NO == res) | 1597 | if (GNUNET_NO == res) |
1638 | { | 1598 | { |
1639 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), | 1599 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1640 | network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth); | 1600 | _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), |
1641 | in_dest[c] = GNUNET_ATS_DefaultBandwidth; | 1601 | network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth); |
1602 | in_dest[c] = GNUNET_ATS_DefaultBandwidth; | ||
1642 | } | 1603 | } |
1643 | else | 1604 | else |
1644 | { | 1605 | { |
1645 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Inbound quota configured for network `%s' is %llu\n"), | 1606 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1646 | network_str[c], in_dest[c]); | 1607 | _("Inbound quota configured for network `%s' is %llu\n"), |
1608 | network_str[c], in_dest[c]); | ||
1647 | } | 1609 | } |
1648 | GNUNET_free (quota_in_str); | 1610 | GNUNET_free(quota_in_str); |
1649 | } | 1611 | } |
1650 | else | 1612 | else |
1651 | { | 1613 | { |
1652 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"), | 1614 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1615 | _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"), | ||
1653 | network_str[c], GNUNET_ATS_DefaultBandwidth); | 1616 | network_str[c], GNUNET_ATS_DefaultBandwidth); |
1654 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; | 1617 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; |
1655 | } | 1618 | } |
1656 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded quota for network `%s' (in/out): %llu %llu\n", network_str[c], in_dest[c], out_dest[c]); | 1619 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1657 | GNUNET_free (entry_out); | 1620 | "Loaded quota for network `%s' (in/out): %llu %llu\n", network_str[c], |
1658 | GNUNET_free (entry_in); | 1621 | in_dest[c], out_dest[c]); |
1622 | GNUNET_free(entry_out); | ||
1623 | GNUNET_free(entry_in); | ||
1659 | } | 1624 | } |
1660 | return GNUNET_ATS_NetworkTypeCount; | 1625 | return GNUNET_ATS_NetworkTypeCount; |
1661 | } | 1626 | } |
1662 | 1627 | ||
1663 | |||
1664 | /** | 1628 | /** |
1665 | * Callback for solver to notify about assignment changes | 1629 | * Callback for solver to notify about assignment changes |
1666 | * | 1630 | * |
@@ -1673,61 +1637,52 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address) | |||
1673 | struct GAS_Addresses_Handle *handle = cls; | 1637 | struct GAS_Addresses_Handle *handle = cls; |
1674 | struct GAS_Addresses_Suggestion_Requests *cur; | 1638 | struct GAS_Addresses_Suggestion_Requests *cur; |
1675 | 1639 | ||
1676 | GNUNET_assert (handle != NULL); | 1640 | GNUNET_assert(handle != NULL); |
1677 | GNUNET_assert (address != NULL); | 1641 | GNUNET_assert(address != NULL); |
1678 | 1642 | ||
1679 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bandwidth assignment changed for peer %s \n", | 1643 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1680 | GNUNET_i2s(&address->peer)); | 1644 | "Bandwidth assignment changed for peer %s \n", |
1645 | GNUNET_i2s (&address->peer)); | ||
1681 | 1646 | ||
1682 | /* Notify performance clients about changes to address */ | 1647 | /* Notify performance clients about changes to address */ |
1683 | GAS_performance_notify_all_clients (&address->peer, | 1648 | GAS_performance_notify_all_clients (&address->peer, address->plugin, |
1684 | address->plugin, | 1649 | address->addr, address->addr_len, address->session_id, address->atsi, |
1685 | address->addr, address->addr_len, | 1650 | address->atsi_count, address->assigned_bw_out, address->assigned_bw_in); |
1686 | address->session_id, | ||
1687 | address->atsi, address->atsi_count, | ||
1688 | address->assigned_bw_out, | ||
1689 | address->assigned_bw_in); | ||
1690 | cur = handle->r_head; | 1651 | cur = handle->r_head; |
1691 | while (NULL != cur) | 1652 | while (NULL != cur) |
1692 | { | 1653 | { |
1693 | if (0 == memcmp (&address->peer, &cur->id, sizeof (cur->id))) | 1654 | if (0 == memcmp (&address->peer, &cur->id, sizeof(cur->id))) |
1694 | break; /* we have an address request pending*/ | 1655 | break; /* we have an address request pending*/ |
1695 | cur = cur->next; | 1656 | cur = cur->next; |
1696 | } | 1657 | } |
1697 | if (NULL == cur) | 1658 | if (NULL == cur) |
1698 | { | 1659 | { |
1699 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1660 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Nobody is interested in peer `%s' :(\n", |
1700 | "Nobody is interested in peer `%s' :(\n",GNUNET_i2s (&address->peer)); | 1661 | GNUNET_i2s (&address->peer)); |
1701 | return; | 1662 | return; |
1702 | } | 1663 | } |
1703 | 1664 | ||
1704 | if ((0 == ntohl (address->assigned_bw_in.value__)) && | 1665 | if ((0 == ntohl (address->assigned_bw_in.value__)) |
1705 | (0 == ntohl (address->assigned_bw_out.value__))) | 1666 | && (0 == ntohl (address->assigned_bw_out.value__))) |
1706 | { | 1667 | { |
1707 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1668 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1708 | "Telling transport to disconnect peer `%s'\n", | 1669 | "Telling transport to disconnect peer `%s'\n", |
1709 | GNUNET_i2s (&address->peer)); | 1670 | GNUNET_i2s (&address->peer)); |
1710 | } | 1671 | } |
1711 | else | 1672 | else |
1712 | { | 1673 | { |
1713 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1674 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1714 | "Sending bandwidth update for peer `%s': %llu %llu\n", | 1675 | "Sending bandwidth update for peer `%s': %llu %llu\n", |
1715 | GNUNET_i2s (&address->peer), | 1676 | GNUNET_i2s (&address->peer), address->assigned_bw_out, |
1716 | address->assigned_bw_out, | 1677 | address->assigned_bw_out); |
1717 | address->assigned_bw_out); | ||
1718 | } | 1678 | } |
1719 | 1679 | ||
1720 | /* *Notify scheduling clients about suggestion */ | 1680 | /* *Notify scheduling clients about suggestion */ |
1721 | GAS_scheduling_transmit_address_suggestion (&address->peer, | 1681 | GAS_scheduling_transmit_address_suggestion (&address->peer, address->plugin, |
1722 | address->plugin, | 1682 | address->addr, address->addr_len, address->session_id, address->atsi, |
1723 | address->addr, address->addr_len, | 1683 | address->atsi_count, address->assigned_bw_out, address->assigned_bw_in); |
1724 | address->session_id, | ||
1725 | address->atsi, address->atsi_count, | ||
1726 | address->assigned_bw_out, | ||
1727 | address->assigned_bw_in); | ||
1728 | } | 1684 | } |
1729 | 1685 | ||
1730 | |||
1731 | /** | 1686 | /** |
1732 | * Initialize address subsystem. The addresses subsystem manages the addresses | 1687 | * Initialize address subsystem. The addresses subsystem manages the addresses |
1733 | * known and current performance information. It has a solver component | 1688 | * known and current performance information. It has a solver component |
@@ -1740,12 +1695,12 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address) | |||
1740 | */ | 1695 | */ |
1741 | struct GAS_Addresses_Handle * | 1696 | struct GAS_Addresses_Handle * |
1742 | GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | 1697 | GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1743 | const struct GNUNET_STATISTICS_Handle *stats) | 1698 | const struct GNUNET_STATISTICS_Handle *stats) |
1744 | { | 1699 | { |
1745 | struct GAS_Addresses_Handle *ah; | 1700 | struct GAS_Addresses_Handle *ah; |
1746 | int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; | 1701 | int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; |
1747 | unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount]; | 1702 | unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount]; |
1748 | unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount]; | 1703 | unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount]; |
1749 | int quota_count; | 1704 | int quota_count; |
1750 | char *mode_str; | 1705 | char *mode_str; |
1751 | int c; | 1706 | int c; |
@@ -1756,144 +1711,152 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1756 | ah->stat = (struct GNUNET_STATISTICS_Handle *) stats; | 1711 | ah->stat = (struct GNUNET_STATISTICS_Handle *) stats; |
1757 | /* Initialize the addresses database */ | 1712 | /* Initialize the addresses database */ |
1758 | ah->addresses = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); | 1713 | ah->addresses = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); |
1759 | GNUNET_assert (NULL != ah->addresses); | 1714 | GNUNET_assert(NULL != ah->addresses); |
1760 | 1715 | ||
1761 | /* Figure out configured solution method */ | 1716 | /* Figure out configured solution method */ |
1762 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "MODE", &mode_str)) | 1717 | if (GNUNET_SYSERR |
1718 | == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "MODE", &mode_str)) | ||
1763 | { | 1719 | { |
1764 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "No resource assignment method configured, using proportional approach\n"); | 1720 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1765 | ah->ats_mode = MODE_PROPORTIONAL; | 1721 | "No resource assignment method configured, using proportional approach\n"); |
1722 | ah->ats_mode = MODE_PROPORTIONAL; | ||
1766 | } | 1723 | } |
1767 | else | 1724 | else |
1768 | { | 1725 | { |
1769 | for (c = 0; c < strlen (mode_str); c++) | 1726 | for (c = 0; c < strlen (mode_str); c++) |
1770 | mode_str[c] = toupper (mode_str[c]); | 1727 | mode_str[c] = toupper (mode_str[c]); |
1771 | if (0 == strcmp (mode_str, "PROPORTIONAL")) | 1728 | if (0 == strcmp (mode_str, "PROPORTIONAL")) |
1772 | { | 1729 | { |
1773 | ah->ats_mode = MODE_PROPORTIONAL; | 1730 | ah->ats_mode = MODE_PROPORTIONAL; |
1774 | } | 1731 | } |
1775 | else if (0 == strcmp (mode_str, "MLP")) | 1732 | else if (0 == strcmp (mode_str, "MLP")) |
1776 | { | 1733 | { |
1777 | ah->ats_mode = MODE_MLP; | 1734 | ah->ats_mode = MODE_MLP; |
1778 | #if !HAVE_LIBGLPK | 1735 | #if !HAVE_LIBGLPK |
1779 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Assignment method `%s' configured, but GLPK is not available, please install \n", mode_str); | 1736 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1780 | ah->ats_mode = MODE_PROPORTIONAL; | 1737 | "Assignment method `%s' configured, but GLPK is not available, please install \n", |
1738 | mode_str); | ||
1739 | ah->ats_mode = MODE_PROPORTIONAL; | ||
1781 | #endif | 1740 | #endif |
1782 | } | 1741 | } |
1783 | else if (0 == strcmp (mode_str, "RIL")) | 1742 | else if (0 == strcmp (mode_str, "RIL")) |
1784 | { | 1743 | { |
1785 | ah->ats_mode = MODE_RIL; | 1744 | ah->ats_mode = MODE_RIL; |
1786 | } | 1745 | } |
1787 | else | 1746 | else |
1788 | { | 1747 | { |
1789 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid resource assignment method `%s' configured, using proportional approach\n", mode_str); | 1748 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1790 | ah->ats_mode = MODE_PROPORTIONAL; | 1749 | "Invalid resource assignment method `%s' configured, using proportional approach\n", |
1791 | } | 1750 | mode_str); |
1792 | GNUNET_free (mode_str); | 1751 | ah->ats_mode = MODE_PROPORTIONAL; |
1752 | } | ||
1753 | GNUNET_free(mode_str); | ||
1793 | } | 1754 | } |
1794 | /* Start configured solution method */ | 1755 | /* Start configured solution method */ |
1795 | switch (ah->ats_mode) | 1756 | switch (ah->ats_mode) |
1796 | { | 1757 | { |
1797 | case MODE_MLP: | 1758 | case MODE_MLP: |
1798 | /* Init the MLP solver with default values */ | 1759 | /* Init the MLP solver with default values */ |
1799 | #if HAVE_LIBGLPK | 1760 | #if HAVE_LIBGLPK |
1800 | ah->s_init = &GAS_mlp_init; | 1761 | ah->s_init = &GAS_mlp_init; |
1801 | ah->s_add = &GAS_mlp_address_add; | 1762 | ah->s_add = &GAS_mlp_address_add; |
1802 | ah->s_address_update_property = &GAS_mlp_address_property_changed; | 1763 | ah->s_address_update_property = &GAS_mlp_address_property_changed; |
1803 | ah->s_address_update_session = &GAS_mlp_address_session_changed; | 1764 | ah->s_address_update_session = &GAS_mlp_address_session_changed; |
1804 | ah->s_address_update_inuse = &GAS_mlp_address_inuse_changed; | 1765 | ah->s_address_update_inuse = &GAS_mlp_address_inuse_changed; |
1805 | ah->s_address_update_network = &GAS_mlp_address_change_network; | 1766 | ah->s_address_update_network = &GAS_mlp_address_change_network; |
1806 | ah->s_get = &GAS_mlp_get_preferred_address; | 1767 | ah->s_get = &GAS_mlp_get_preferred_address; |
1807 | ah->s_get_stop = &GAS_mlp_stop_get_preferred_address; | 1768 | ah->s_get_stop = &GAS_mlp_stop_get_preferred_address; |
1808 | ah->s_pref = &GAS_mlp_address_change_preference; | 1769 | ah->s_pref = &GAS_mlp_address_change_preference; |
1809 | ah->s_feedback = &GAS_mlp_address_preference_feedback; | 1770 | ah->s_feedback = &GAS_mlp_address_preference_feedback; |
1810 | ah->s_del = &GAS_mlp_address_delete; | 1771 | ah->s_del = &GAS_mlp_address_delete; |
1811 | ah->s_bulk_start = &GAS_mlp_bulk_start; | 1772 | ah->s_bulk_start = &GAS_mlp_bulk_start; |
1812 | ah->s_bulk_stop = &GAS_mlp_bulk_stop; | 1773 | ah->s_bulk_stop = &GAS_mlp_bulk_stop; |
1813 | ah->s_done = &GAS_mlp_done; | 1774 | ah->s_done = &GAS_mlp_done; |
1814 | #else | 1775 | #else |
1815 | GNUNET_free (ah); | 1776 | GNUNET_free(ah); |
1816 | return NULL; | 1777 | return NULL ; |
1817 | #endif | 1778 | #endif |
1818 | break; | 1779 | break; |
1819 | case MODE_PROPORTIONAL: | 1780 | case MODE_PROPORTIONAL: |
1820 | /* Init the proportional solver with default values */ | 1781 | /* Init the proportional solver with default values */ |
1821 | ah->s_init = &GAS_proportional_init; | 1782 | ah->s_init = &GAS_proportional_init; |
1822 | ah->s_add = &GAS_proportional_address_add; | 1783 | ah->s_add = &GAS_proportional_address_add; |
1823 | ah->s_address_update_property = &GAS_proportional_address_property_changed; | 1784 | ah->s_address_update_property = &GAS_proportional_address_property_changed; |
1824 | ah->s_address_update_session = &GAS_proportional_address_session_changed; | 1785 | ah->s_address_update_session = &GAS_proportional_address_session_changed; |
1825 | ah->s_address_update_inuse = &GAS_proportional_address_inuse_changed; | 1786 | ah->s_address_update_inuse = &GAS_proportional_address_inuse_changed; |
1826 | ah->s_address_update_network = &GAS_proportional_address_change_network; | 1787 | ah->s_address_update_network = &GAS_proportional_address_change_network; |
1827 | ah->s_get = &GAS_proportional_get_preferred_address; | 1788 | ah->s_get = &GAS_proportional_get_preferred_address; |
1828 | ah->s_get_stop = &GAS_proportional_stop_get_preferred_address; | 1789 | ah->s_get_stop = &GAS_proportional_stop_get_preferred_address; |
1829 | ah->s_pref = &GAS_proportional_address_change_preference; | 1790 | ah->s_pref = &GAS_proportional_address_change_preference; |
1830 | ah->s_feedback = &GAS_proportional_address_preference_feedback; | 1791 | ah->s_feedback = &GAS_proportional_address_preference_feedback; |
1831 | ah->s_del = &GAS_proportional_address_delete; | 1792 | ah->s_del = &GAS_proportional_address_delete; |
1832 | ah->s_bulk_start = &GAS_proportional_bulk_start; | 1793 | ah->s_bulk_start = &GAS_proportional_bulk_start; |
1833 | ah->s_bulk_stop = &GAS_proportional_bulk_stop; | 1794 | ah->s_bulk_stop = &GAS_proportional_bulk_stop; |
1834 | ah->s_done = &GAS_proportional_done; | 1795 | ah->s_done = &GAS_proportional_done; |
1835 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS started in %s mode\n", "PROPORTIONAL"); | 1796 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "ATS started in %s mode\n", |
1836 | break; | 1797 | "PROPORTIONAL"); |
1837 | case MODE_RIL: | 1798 | break; |
1838 | /* Init the ril solver with default values */ | 1799 | case MODE_RIL: |
1839 | ah->s_init = &GAS_ril_init; | 1800 | /* Init the ril solver with default values */ |
1840 | ah->s_add = &GAS_ril_address_add; | 1801 | ah->s_init = &GAS_ril_init; |
1841 | ah->s_address_update_property = &GAS_ril_address_property_changed; | 1802 | ah->s_add = &GAS_ril_address_add; |
1842 | ah->s_address_update_session = &GAS_ril_address_session_changed; | 1803 | ah->s_address_update_property = &GAS_ril_address_property_changed; |
1843 | ah->s_address_update_inuse = &GAS_ril_address_inuse_changed; | 1804 | ah->s_address_update_session = &GAS_ril_address_session_changed; |
1844 | ah->s_address_update_network = &GAS_ril_address_change_network; | 1805 | ah->s_address_update_inuse = &GAS_ril_address_inuse_changed; |
1845 | ah->s_get = &GAS_ril_get_preferred_address; | 1806 | ah->s_address_update_network = &GAS_ril_address_change_network; |
1846 | ah->s_get_stop = &GAS_ril_stop_get_preferred_address; | 1807 | ah->s_get = &GAS_ril_get_preferred_address; |
1847 | ah->s_pref = &GAS_ril_address_change_preference; | 1808 | ah->s_get_stop = &GAS_ril_stop_get_preferred_address; |
1848 | ah->s_feedback = &GAS_ril_address_preference_feedback; | 1809 | ah->s_pref = &GAS_ril_address_change_preference; |
1849 | ah->s_del = &GAS_ril_address_delete; | 1810 | ah->s_feedback = &GAS_ril_address_preference_feedback; |
1850 | ah->s_bulk_start = &GAS_ril_bulk_start; | 1811 | ah->s_del = &GAS_ril_address_delete; |
1851 | ah->s_bulk_stop = &GAS_ril_bulk_stop; | 1812 | ah->s_bulk_start = &GAS_ril_bulk_start; |
1852 | ah->s_done = &GAS_ril_done; | 1813 | ah->s_bulk_stop = &GAS_ril_bulk_stop; |
1853 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS started in %s mode\n", "RIL"); | 1814 | ah->s_done = &GAS_ril_done; |
1854 | break; | 1815 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "ATS started in %s mode\n", "RIL"); |
1855 | default: | 1816 | break; |
1856 | return NULL; | 1817 | default: |
1857 | break; | 1818 | return NULL ; |
1819 | break; | ||
1858 | } | 1820 | } |
1859 | 1821 | ||
1860 | GNUNET_assert (NULL != ah->s_init); | 1822 | GNUNET_assert(NULL != ah->s_init); |
1861 | GNUNET_assert (NULL != ah->s_add); | 1823 | GNUNET_assert(NULL != ah->s_add); |
1862 | GNUNET_assert (NULL != ah->s_address_update_inuse); | 1824 | GNUNET_assert(NULL != ah->s_address_update_inuse); |
1863 | GNUNET_assert (NULL != ah->s_address_update_property); | 1825 | GNUNET_assert(NULL != ah->s_address_update_property); |
1864 | GNUNET_assert (NULL != ah->s_address_update_session); | 1826 | GNUNET_assert(NULL != ah->s_address_update_session); |
1865 | GNUNET_assert (NULL != ah->s_address_update_network); | 1827 | GNUNET_assert(NULL != ah->s_address_update_network); |
1866 | GNUNET_assert (NULL != ah->s_get); | 1828 | GNUNET_assert(NULL != ah->s_get); |
1867 | GNUNET_assert (NULL != ah->s_get_stop); | 1829 | GNUNET_assert(NULL != ah->s_get_stop); |
1868 | GNUNET_assert (NULL != ah->s_pref); | 1830 | GNUNET_assert(NULL != ah->s_pref); |
1869 | GNUNET_assert (NULL != ah->s_feedback); | 1831 | GNUNET_assert(NULL != ah->s_feedback); |
1870 | GNUNET_assert (NULL != ah->s_del); | 1832 | GNUNET_assert(NULL != ah->s_del); |
1871 | GNUNET_assert (NULL != ah->s_done); | 1833 | GNUNET_assert(NULL != ah->s_done); |
1872 | GNUNET_assert (NULL != ah->s_bulk_start); | 1834 | GNUNET_assert(NULL != ah->s_bulk_start); |
1873 | GNUNET_assert (NULL != ah->s_bulk_stop); | 1835 | GNUNET_assert(NULL != ah->s_bulk_stop); |
1874 | 1836 | ||
1875 | GAS_normalization_start (&normalized_preference_changed_cb, ah, | 1837 | GAS_normalization_start (&normalized_preference_changed_cb, ah, |
1876 | &normalized_property_changed_cb, ah); | 1838 | &normalized_property_changed_cb, ah); |
1877 | quota_count = load_quotas(cfg, quotas_in, quotas_out, GNUNET_ATS_NetworkTypeCount); | 1839 | quota_count = load_quotas (cfg, quotas_in, quotas_out, |
1878 | 1840 | GNUNET_ATS_NetworkTypeCount); | |
1879 | ah->solver = ah->s_init (cfg, stats, ah->addresses, | 1841 | |
1880 | quotas, quotas_in, quotas_out, quota_count, | 1842 | ah->solver = ah->s_init (cfg, stats, ah->addresses, quotas, quotas_in, |
1881 | &bandwidth_changed_cb, ah, | 1843 | quotas_out, quota_count, &bandwidth_changed_cb, ah, &get_preferences_cb, |
1882 | &get_preferences_cb, NULL, | 1844 | NULL, &get_property_cb, NULL ); |
1883 | &get_property_cb, NULL); | ||
1884 | if (NULL == ah->solver) | 1845 | if (NULL == ah->solver) |
1885 | { | 1846 | { |
1886 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver!\n")); | 1847 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver!\n")); |
1887 | GNUNET_free (ah); | 1848 | GNUNET_free(ah); |
1888 | return NULL; | 1849 | return NULL ; |
1889 | } | 1850 | } |
1890 | |||
1891 | /* up and running */ | 1851 | /* up and running */ |
1892 | ah->running = GNUNET_YES; | 1852 | ah->running = GNUNET_YES; |
1853 | |||
1854 | GNUNET_STATISTICS_set (ah->stat, "# addresses", | ||
1855 | GNUNET_CONTAINER_multihashmap_size (ah->addresses), GNUNET_NO); | ||
1856 | |||
1893 | return ah; | 1857 | return ah; |
1894 | } | 1858 | } |
1895 | 1859 | ||
1896 | |||
1897 | /** | 1860 | /** |
1898 | * Destroy all addresses iterator | 1861 | * Destroy all addresses iterator |
1899 | * | 1862 | * |
@@ -1903,13 +1866,15 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1903 | * @return GNUNET_OK (continue to iterate) | 1866 | * @return GNUNET_OK (continue to iterate) |
1904 | */ | 1867 | */ |
1905 | static int | 1868 | static int |
1906 | destroy_all_address_it (void *cls, const struct GNUNET_HashCode * key, void *value) | 1869 | destroy_all_address_it (void *cls, const struct GNUNET_HashCode * key, |
1870 | void *value) | ||
1907 | { | 1871 | { |
1908 | struct GAS_Addresses_Handle *handle = cls; | 1872 | struct GAS_Addresses_Handle *handle = cls; |
1909 | struct ATS_Address *aa = value; | 1873 | struct ATS_Address *aa = value; |
1910 | 1874 | ||
1911 | /* Remove */ | 1875 | /* Remove */ |
1912 | GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->addresses, key, value)); | 1876 | GNUNET_assert( |
1877 | GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->addresses, key, value)); | ||
1913 | /* Notify */ | 1878 | /* Notify */ |
1914 | handle->s_del (handle->solver, aa, GNUNET_NO); | 1879 | handle->s_del (handle->solver, aa, GNUNET_NO); |
1915 | /* Destroy */ | 1880 | /* Destroy */ |
@@ -1918,7 +1883,6 @@ destroy_all_address_it (void *cls, const struct GNUNET_HashCode * key, void *val | |||
1918 | return GNUNET_OK; | 1883 | return GNUNET_OK; |
1919 | } | 1884 | } |
1920 | 1885 | ||
1921 | |||
1922 | /** | 1886 | /** |
1923 | * Remove all addresses | 1887 | * Remove all addresses |
1924 | * | 1888 | * |
@@ -1930,15 +1894,14 @@ GAS_addresses_destroy_all (struct GAS_Addresses_Handle *handle) | |||
1930 | if (GNUNET_NO == handle->running) | 1894 | if (GNUNET_NO == handle->running) |
1931 | return; | 1895 | return; |
1932 | 1896 | ||
1933 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1897 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Destroying all addresses\n"); |
1934 | "Destroying all addresses\n"); | ||
1935 | handle->s_bulk_start (handle->solver); | 1898 | handle->s_bulk_start (handle->solver); |
1936 | if (handle->addresses != NULL) | 1899 | if (handle->addresses != NULL ) |
1937 | GNUNET_CONTAINER_multihashmap_iterate (handle->addresses, &destroy_all_address_it, handle); | 1900 | GNUNET_CONTAINER_multihashmap_iterate (handle->addresses, |
1901 | &destroy_all_address_it, handle); | ||
1938 | handle->s_bulk_start (handle->solver); | 1902 | handle->s_bulk_start (handle->solver); |
1939 | } | 1903 | } |
1940 | 1904 | ||
1941 | |||
1942 | /** | 1905 | /** |
1943 | * Shutdown address subsystem. | 1906 | * Shutdown address subsystem. |
1944 | * | 1907 | * |
@@ -1949,25 +1912,23 @@ GAS_addresses_done (struct GAS_Addresses_Handle *handle) | |||
1949 | { | 1912 | { |
1950 | struct GAS_Addresses_Suggestion_Requests *cur; | 1913 | struct GAS_Addresses_Suggestion_Requests *cur; |
1951 | 1914 | ||
1952 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1915 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Shutting down addresses\n"); |
1953 | "Shutting down addresses\n"); | 1916 | GNUNET_assert(NULL != handle); |
1954 | GNUNET_assert (NULL != handle); | ||
1955 | GAS_addresses_destroy_all (handle); | 1917 | GAS_addresses_destroy_all (handle); |
1956 | handle->running = GNUNET_NO; | 1918 | handle->running = GNUNET_NO; |
1957 | GNUNET_CONTAINER_multihashmap_destroy (handle->addresses); | 1919 | GNUNET_CONTAINER_multihashmap_destroy (handle->addresses); |
1958 | handle->addresses = NULL; | 1920 | handle->addresses = NULL; |
1959 | while (NULL != (cur = handle->r_head)) | 1921 | while (NULL != (cur = handle->r_head)) |
1960 | { | 1922 | { |
1961 | GNUNET_CONTAINER_DLL_remove (handle->r_head, handle->r_tail, cur); | 1923 | GNUNET_CONTAINER_DLL_remove(handle->r_head, handle->r_tail, cur); |
1962 | GNUNET_free (cur); | 1924 | GNUNET_free(cur); |
1963 | } | 1925 | } |
1964 | handle->s_done (handle->solver); | 1926 | handle->s_done (handle->solver); |
1965 | GNUNET_free (handle); | 1927 | GNUNET_free(handle); |
1966 | /* Stop configured solution method */ | 1928 | /* Stop configured solution method */ |
1967 | GAS_normalization_stop (); | 1929 | GAS_normalization_stop (); |
1968 | } | 1930 | } |
1969 | 1931 | ||
1970 | |||
1971 | struct PeerIteratorContext | 1932 | struct PeerIteratorContext |
1972 | { | 1933 | { |
1973 | GNUNET_ATS_Peer_Iterator it; | 1934 | GNUNET_ATS_Peer_Iterator it; |
@@ -1975,7 +1936,6 @@ struct PeerIteratorContext | |||
1975 | struct GNUNET_CONTAINER_MultiHashMap *peers_returned; | 1936 | struct GNUNET_CONTAINER_MultiHashMap *peers_returned; |
1976 | }; | 1937 | }; |
1977 | 1938 | ||
1978 | |||
1979 | /** | 1939 | /** |
1980 | * Iterator to iterate over all peers | 1940 | * Iterator to iterate over all peers |
1981 | * | 1941 | * |
@@ -1985,24 +1945,23 @@ struct PeerIteratorContext | |||
1985 | * @return GNUNET_OK to continue | 1945 | * @return GNUNET_OK to continue |
1986 | */ | 1946 | */ |
1987 | static int | 1947 | static int |
1988 | peer_it (void *cls, | 1948 | peer_it (void *cls, const struct GNUNET_HashCode * key, void *value) |
1989 | const struct GNUNET_HashCode * key, | ||
1990 | void *value) | ||
1991 | { | 1949 | { |
1992 | struct PeerIteratorContext *ip_ctx = cls; | 1950 | struct PeerIteratorContext *ip_ctx = cls; |
1993 | struct GNUNET_PeerIdentity tmp; | 1951 | struct GNUNET_PeerIdentity tmp; |
1994 | 1952 | ||
1995 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(ip_ctx->peers_returned, key)) | 1953 | if (GNUNET_NO |
1954 | == GNUNET_CONTAINER_multihashmap_contains (ip_ctx->peers_returned, key)) | ||
1996 | { | 1955 | { |
1997 | GNUNET_CONTAINER_multihashmap_put(ip_ctx->peers_returned, key, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 1956 | GNUNET_CONTAINER_multihashmap_put (ip_ctx->peers_returned, key, NULL, |
1998 | tmp.hashPubKey = (*key); | 1957 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
1999 | ip_ctx->it (ip_ctx->it_cls, &tmp); | 1958 | tmp.hashPubKey = (*key); |
1959 | ip_ctx->it (ip_ctx->it_cls, &tmp); | ||
2000 | } | 1960 | } |
2001 | 1961 | ||
2002 | return GNUNET_OK; | 1962 | return GNUNET_OK; |
2003 | } | 1963 | } |
2004 | 1964 | ||
2005 | |||
2006 | /** | 1965 | /** |
2007 | * Return information all peers currently known to ATS | 1966 | * Return information all peers currently known to ATS |
2008 | * | 1967 | * |
@@ -2012,36 +1971,35 @@ peer_it (void *cls, | |||
2012 | */ | 1971 | */ |
2013 | void | 1972 | void |
2014 | GAS_addresses_iterate_peers (struct GAS_Addresses_Handle *handle, | 1973 | GAS_addresses_iterate_peers (struct GAS_Addresses_Handle *handle, |
2015 | GNUNET_ATS_Peer_Iterator p_it, | 1974 | GNUNET_ATS_Peer_Iterator p_it, void *p_it_cls) |
2016 | void *p_it_cls) | ||
2017 | { | 1975 | { |
2018 | struct PeerIteratorContext ip_ctx; | 1976 | struct PeerIteratorContext ip_ctx; |
2019 | unsigned int size; | 1977 | unsigned int size; |
2020 | 1978 | ||
2021 | if (NULL == p_it) | 1979 | if (NULL == p_it) |
2022 | return; | 1980 | return; |
2023 | GNUNET_assert (NULL != handle->addresses); | 1981 | GNUNET_assert(NULL != handle->addresses); |
2024 | 1982 | ||
2025 | size = GNUNET_CONTAINER_multihashmap_size(handle->addresses); | 1983 | size = GNUNET_CONTAINER_multihashmap_size (handle->addresses); |
2026 | if (0 != size) | 1984 | if (0 != size) |
2027 | { | 1985 | { |
2028 | ip_ctx.it = p_it; | 1986 | ip_ctx.it = p_it; |
2029 | ip_ctx.it_cls = p_it_cls; | 1987 | ip_ctx.it_cls = p_it_cls; |
2030 | ip_ctx.peers_returned = GNUNET_CONTAINER_multihashmap_create (size, GNUNET_NO); | 1988 | ip_ctx.peers_returned = GNUNET_CONTAINER_multihashmap_create (size, |
2031 | GNUNET_CONTAINER_multihashmap_iterate (handle->addresses, &peer_it, &ip_ctx); | 1989 | GNUNET_NO); |
1990 | GNUNET_CONTAINER_multihashmap_iterate (handle->addresses, &peer_it, | ||
1991 | &ip_ctx); | ||
2032 | GNUNET_CONTAINER_multihashmap_destroy (ip_ctx.peers_returned); | 1992 | GNUNET_CONTAINER_multihashmap_destroy (ip_ctx.peers_returned); |
2033 | } | 1993 | } |
2034 | p_it (p_it_cls, NULL); | 1994 | p_it (p_it_cls, NULL ); |
2035 | } | 1995 | } |
2036 | 1996 | ||
2037 | |||
2038 | struct PeerInfoIteratorContext | 1997 | struct PeerInfoIteratorContext |
2039 | { | 1998 | { |
2040 | GNUNET_ATS_PeerInfo_Iterator it; | 1999 | GNUNET_ATS_PeerInfo_Iterator it; |
2041 | void *it_cls; | 2000 | void *it_cls; |
2042 | }; | 2001 | }; |
2043 | 2002 | ||
2044 | |||
2045 | /** | 2003 | /** |
2046 | * Iterator to iterate over a peer's addresses | 2004 | * Iterator to iterate over a peer's addresses |
2047 | * | 2005 | * |
@@ -2050,29 +2008,21 @@ struct PeerInfoIteratorContext | |||
2050 | * @param value the ATS_address | 2008 | * @param value the ATS_address |
2051 | * @return GNUNET_OK to continue | 2009 | * @return GNUNET_OK to continue |
2052 | */ | 2010 | */ |
2053 | static int | 2011 | static int |
2054 | peerinfo_it (void *cls, | 2012 | peerinfo_it (void *cls, const struct GNUNET_HashCode * key, void *value) |
2055 | const struct GNUNET_HashCode * key, | ||
2056 | void *value) | ||
2057 | { | 2013 | { |
2058 | struct PeerInfoIteratorContext *pi_ctx = cls; | 2014 | struct PeerInfoIteratorContext *pi_ctx = cls; |
2059 | struct ATS_Address *addr = (struct ATS_Address *) value; | 2015 | struct ATS_Address *addr = (struct ATS_Address *) value; |
2060 | 2016 | ||
2061 | if (NULL != pi_ctx->it) | 2017 | if (NULL != pi_ctx->it) |
2062 | { | 2018 | { |
2063 | pi_ctx->it (pi_ctx->it_cls, | 2019 | pi_ctx->it (pi_ctx->it_cls, &addr->peer, addr->plugin, addr->addr, |
2064 | &addr->peer, | 2020 | addr->addr_len, addr->active, addr->atsi, addr->atsi_count, |
2065 | addr->plugin, | 2021 | addr->assigned_bw_out, addr->assigned_bw_in); |
2066 | addr->addr, addr->addr_len, | ||
2067 | addr->active, | ||
2068 | addr->atsi, addr->atsi_count, | ||
2069 | addr->assigned_bw_out, | ||
2070 | addr->assigned_bw_in); | ||
2071 | } | 2022 | } |
2072 | return GNUNET_YES; | 2023 | return GNUNET_YES; |
2073 | } | 2024 | } |
2074 | 2025 | ||
2075 | |||
2076 | /** | 2026 | /** |
2077 | * Return information all peers currently known to ATS | 2027 | * Return information all peers currently known to ATS |
2078 | * | 2028 | * |
@@ -2083,14 +2033,13 @@ peerinfo_it (void *cls, | |||
2083 | */ | 2033 | */ |
2084 | void | 2034 | void |
2085 | GAS_addresses_get_peer_info (struct GAS_Addresses_Handle *handle, | 2035 | GAS_addresses_get_peer_info (struct GAS_Addresses_Handle *handle, |
2086 | const struct GNUNET_PeerIdentity *peer, | 2036 | const struct GNUNET_PeerIdentity *peer, GNUNET_ATS_PeerInfo_Iterator pi_it, |
2087 | GNUNET_ATS_PeerInfo_Iterator pi_it, | 2037 | void *pi_it_cls) |
2088 | void *pi_it_cls) | ||
2089 | { | 2038 | { |
2090 | struct PeerInfoIteratorContext pi_ctx; | 2039 | struct PeerInfoIteratorContext pi_ctx; |
2091 | struct GNUNET_BANDWIDTH_Value32NBO zero_bw; | 2040 | struct GNUNET_BANDWIDTH_Value32NBO zero_bw; |
2092 | GNUNET_assert (NULL != peer); | 2041 | GNUNET_assert(NULL != peer); |
2093 | GNUNET_assert (NULL != handle->addresses); | 2042 | GNUNET_assert(NULL != handle->addresses); |
2094 | if (NULL == pi_it) | 2043 | if (NULL == pi_it) |
2095 | return; /* does not make sense without callback */ | 2044 | return; /* does not make sense without callback */ |
2096 | 2045 | ||
@@ -2098,12 +2047,13 @@ GAS_addresses_get_peer_info (struct GAS_Addresses_Handle *handle, | |||
2098 | pi_ctx.it = pi_it; | 2047 | pi_ctx.it = pi_it; |
2099 | pi_ctx.it_cls = pi_it_cls; | 2048 | pi_ctx.it_cls = pi_it_cls; |
2100 | 2049 | ||
2101 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey, &peerinfo_it, &pi_ctx); | 2050 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, |
2051 | &peer->hashPubKey, &peerinfo_it, &pi_ctx); | ||
2102 | 2052 | ||
2103 | if (NULL != pi_it) | 2053 | if (NULL != pi_it) |
2104 | pi_it (pi_it_cls, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, zero_bw, zero_bw); | 2054 | pi_it (pi_it_cls, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, zero_bw, |
2055 | zero_bw); | ||
2105 | 2056 | ||
2106 | } | 2057 | } |
2107 | 2058 | ||
2108 | |||
2109 | /* end of gnunet-service-ats_addresses.c */ | 2059 | /* end of gnunet-service-ats_addresses.c */ |