diff options
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses.c')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 193 |
1 files changed, 112 insertions, 81 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 4db70dbae..8e3692b8e 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -294,7 +294,7 @@ struct GAS_Addresses_Handle | |||
294 | /** | 294 | /** |
295 | * A multihashmap to store all addresses | 295 | * A multihashmap to store all addresses |
296 | */ | 296 | */ |
297 | struct GNUNET_CONTAINER_MultiHashMap *addresses; | 297 | struct GNUNET_CONTAINER_MultiPeerMap *addresses; |
298 | 298 | ||
299 | /** | 299 | /** |
300 | * Configure WAN quota in | 300 | * Configure WAN quota in |
@@ -574,17 +574,19 @@ struct CompareAddressContext | |||
574 | struct ATS_Address *base_address; | 574 | struct ATS_Address *base_address; |
575 | }; | 575 | }; |
576 | 576 | ||
577 | |||
577 | /** | 578 | /** |
578 | * Comapre addresses | 579 | * Comapre addresses |
579 | * | 580 | * |
580 | * @param cls a CompareAddressContext containin the source address | 581 | * @param cls a CompareAddressContext containin the source address |
581 | * @param key peer id | 582 | * @param key peer id |
582 | * @param value the address to compare with | 583 | * @param value the address to compare with |
583 | * @return GNUNET_YES to continue, GNUNET_NO if address is founce | 584 | * @return #GNUNET_YES to continue, #GNUNET_NO if address is founce |
584 | */ | 585 | */ |
585 | |||
586 | static int | 586 | static int |
587 | compare_address_it (void *cls, const struct GNUNET_HashCode * key, void *value) | 587 | compare_address_it (void *cls, |
588 | const struct GNUNET_PeerIdentity *key, | ||
589 | void *value) | ||
588 | { | 590 | { |
589 | struct CompareAddressContext *cac = cls; | 591 | struct CompareAddressContext *cac = cls; |
590 | struct ATS_Address *aa = value; | 592 | struct ATS_Address *aa = value; |
@@ -672,14 +674,16 @@ find_equivalent_address (struct GAS_Addresses_Handle *handle, | |||
672 | cac.exact_address = NULL; | 674 | cac.exact_address = NULL; |
673 | cac.base_address = NULL; | 675 | cac.base_address = NULL; |
674 | cac.search = addr; | 676 | cac.search = addr; |
675 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, | 677 | GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses, |
676 | &peer->hashPubKey, &compare_address_it, &cac); | 678 | peer, |
679 | &compare_address_it, &cac); | ||
677 | 680 | ||
678 | if (cac.exact_address == NULL ) | 681 | if (cac.exact_address == NULL) |
679 | return cac.base_address; | 682 | return cac.base_address; |
680 | return cac.exact_address; | 683 | return cac.exact_address; |
681 | } | 684 | } |
682 | 685 | ||
686 | |||
683 | /** | 687 | /** |
684 | * Find the exact address | 688 | * Find the exact address |
685 | * | 689 | * |
@@ -787,13 +791,13 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
787 | { | 791 | { |
788 | /* Add a new address */ | 792 | /* Add a new address */ |
789 | GNUNET_assert( | 793 | GNUNET_assert( |
790 | GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (handle->addresses, | 794 | GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (handle->addresses, |
791 | &peer->hashPubKey, | 795 | peer, |
792 | new_address, | 796 | new_address, |
793 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 797 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
794 | 798 | ||
795 | GNUNET_STATISTICS_set (handle->stat, "# addresses", | 799 | GNUNET_STATISTICS_set (handle->stat, "# addresses", |
796 | GNUNET_CONTAINER_multihashmap_size (handle->addresses), GNUNET_NO); | 800 | GNUNET_CONTAINER_multipeermap_size (handle->addresses), GNUNET_NO); |
797 | 801 | ||
798 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 802 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
799 | "Adding new address %p for peer `%s', length %u, session id %u, %s\n", | 803 | "Adding new address %p for peer `%s', length %u, session id %u, %s\n", |
@@ -1013,8 +1017,9 @@ struct DestroyContext | |||
1013 | * @return GNUNET_OK (continue to iterate) | 1017 | * @return GNUNET_OK (continue to iterate) |
1014 | */ | 1018 | */ |
1015 | static int | 1019 | static int |
1016 | destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, | 1020 | destroy_by_session_id (void *cls, |
1017 | void *value) | 1021 | const struct GNUNET_PeerIdentity *key, |
1022 | void *value) | ||
1018 | { | 1023 | { |
1019 | struct DestroyContext *dc = cls; | 1024 | struct DestroyContext *dc = cls; |
1020 | struct GAS_Addresses_Handle *handle = dc->handle; | 1025 | struct GAS_Addresses_Handle *handle = dc->handle; |
@@ -1038,7 +1043,9 @@ destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, | |||
1038 | 1043 | ||
1039 | /* Notify solver about deletion */ | 1044 | /* Notify solver about deletion */ |
1040 | GNUNET_assert( | 1045 | GNUNET_assert( |
1041 | GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->addresses, &aa->peer.hashPubKey, aa)); | 1046 | GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (handle->addresses, |
1047 | &aa->peer, | ||
1048 | aa)); | ||
1042 | handle->s_del (handle->solver, aa, GNUNET_NO); | 1049 | handle->s_del (handle->solver, aa, GNUNET_NO); |
1043 | free_address (aa); | 1050 | free_address (aa); |
1044 | dc->result = GNUNET_NO; | 1051 | dc->result = GNUNET_NO; |
@@ -1069,7 +1076,8 @@ destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, | |||
1069 | 1076 | ||
1070 | /* Notify solver about deletion */ | 1077 | /* Notify solver about deletion */ |
1071 | GNUNET_assert( | 1078 | GNUNET_assert( |
1072 | GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->addresses, &aa->peer.hashPubKey, aa)); | 1079 | GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (handle->addresses, |
1080 | &aa->peer, aa)); | ||
1073 | handle->s_del (handle->solver, aa, GNUNET_NO); | 1081 | handle->s_del (handle->solver, aa, GNUNET_NO); |
1074 | free_address (aa); | 1082 | free_address (aa); |
1075 | dc->result = GNUNET_NO; | 1083 | dc->result = GNUNET_NO; |
@@ -1091,6 +1099,7 @@ destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, | |||
1091 | return GNUNET_OK; | 1099 | return GNUNET_OK; |
1092 | } | 1100 | } |
1093 | 1101 | ||
1102 | |||
1094 | /** | 1103 | /** |
1095 | * Remove an address or just a session for a peer. | 1104 | * Remove an address or just a session for a peer. |
1096 | * | 1105 | * |
@@ -1131,10 +1140,11 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, | |||
1131 | dc.aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, | 1140 | dc.aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, |
1132 | session_id); | 1141 | session_id); |
1133 | 1142 | ||
1134 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, | 1143 | GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses, |
1135 | &peer->hashPubKey, &destroy_by_session_id, &dc); | 1144 | peer, |
1145 | &destroy_by_session_id, &dc); | ||
1136 | GNUNET_STATISTICS_set (handle->stat, "# addresses", | 1146 | GNUNET_STATISTICS_set (handle->stat, "# addresses", |
1137 | GNUNET_CONTAINER_multihashmap_size (handle->addresses), GNUNET_NO); | 1147 | GNUNET_CONTAINER_multipeermap_size (handle->addresses), GNUNET_NO); |
1138 | free_address (dc.aa); | 1148 | free_address (dc.aa); |
1139 | } | 1149 | } |
1140 | 1150 | ||
@@ -1308,22 +1318,26 @@ GAS_addresses_request_address (struct GAS_Addresses_Handle *handle, | |||
1308 | * @param cls not used | 1318 | * @param cls not used |
1309 | * @param key the peer | 1319 | * @param key the peer |
1310 | * @param value the address to reset | 1320 | * @param value the address to reset |
1311 | * @return GNUNET_OK to continue | 1321 | * @return #GNUNET_OK to continue |
1312 | */ | 1322 | */ |
1313 | static int | 1323 | static int |
1314 | reset_address_it (void *cls, const struct GNUNET_HashCode *key, void *value) | 1324 | reset_address_it (void *cls, |
1325 | const struct GNUNET_PeerIdentity *key, | ||
1326 | void *value) | ||
1315 | { | 1327 | { |
1316 | struct ATS_Address *aa = value; | 1328 | struct ATS_Address *aa = value; |
1317 | 1329 | ||
1318 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1330 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1319 | "Resetting interval for peer `%s' address %p from %llu to 0\n", | 1331 | "Resetting interval for peer `%s' address %p from %llu to 0\n", |
1320 | GNUNET_i2s (&aa->peer), aa, aa->block_interval); | 1332 | GNUNET_i2s (&aa->peer), |
1321 | 1333 | aa, | |
1334 | aa->block_interval); | ||
1322 | aa->blocked_until = GNUNET_TIME_UNIT_ZERO_ABS; | 1335 | aa->blocked_until = GNUNET_TIME_UNIT_ZERO_ABS; |
1323 | aa->block_interval = GNUNET_TIME_UNIT_ZERO; | 1336 | aa->block_interval = GNUNET_TIME_UNIT_ZERO; |
1324 | return GNUNET_OK; | 1337 | return GNUNET_OK; |
1325 | } | 1338 | } |
1326 | 1339 | ||
1340 | |||
1327 | /** | 1341 | /** |
1328 | * Reset suggestion backoff for a peer | 1342 | * Reset suggestion backoff for a peer |
1329 | * | 1343 | * |
@@ -1341,9 +1355,12 @@ GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle, | |||
1341 | "RESET BACKOFF", GNUNET_i2s (peer)); | 1355 | "RESET BACKOFF", GNUNET_i2s (peer)); |
1342 | 1356 | ||
1343 | GNUNET_break( | 1357 | GNUNET_break( |
1344 | GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey, &reset_address_it, NULL)); | 1358 | GNUNET_SYSERR != GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses, |
1359 | peer, | ||
1360 | &reset_address_it, NULL)); | ||
1345 | } | 1361 | } |
1346 | 1362 | ||
1363 | |||
1347 | /** | 1364 | /** |
1348 | * The preference changed for a peer | 1365 | * The preference changed for a peer |
1349 | * | 1366 | * |
@@ -1436,9 +1453,9 @@ GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle, | |||
1436 | if (GNUNET_NO == handle->running) | 1453 | if (GNUNET_NO == handle->running) |
1437 | return; | 1454 | return; |
1438 | 1455 | ||
1439 | if (GNUNET_NO | 1456 | if (GNUNET_NO == |
1440 | == GNUNET_CONTAINER_multihashmap_contains (handle->addresses, | 1457 | GNUNET_CONTAINER_multipeermap_contains (handle->addresses, |
1441 | &peer->hashPubKey)) | 1458 | peer)) |
1442 | { | 1459 | { |
1443 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1460 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1444 | "Received `%s' for unknown peer `%s' from client %p\n", | 1461 | "Received `%s' for unknown peer `%s' from client %p\n", |
@@ -1475,9 +1492,9 @@ GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle, | |||
1475 | if (GNUNET_NO == handle->running) | 1492 | if (GNUNET_NO == handle->running) |
1476 | return; | 1493 | return; |
1477 | 1494 | ||
1478 | if (GNUNET_NO | 1495 | if (GNUNET_NO == |
1479 | == GNUNET_CONTAINER_multihashmap_contains (handle->addresses, | 1496 | GNUNET_CONTAINER_multipeermap_contains (handle->addresses, |
1480 | &peer->hashPubKey)) | 1497 | peer)) |
1481 | { | 1498 | { |
1482 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1499 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1483 | "Received `%s' for unknown peer `%s' from client %p\n", | 1500 | "Received `%s' for unknown peer `%s' from client %p\n", |
@@ -1699,7 +1716,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1699 | 1716 | ||
1700 | ah->stat = (struct GNUNET_STATISTICS_Handle *) stats; | 1717 | ah->stat = (struct GNUNET_STATISTICS_Handle *) stats; |
1701 | /* Initialize the addresses database */ | 1718 | /* Initialize the addresses database */ |
1702 | ah->addresses = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); | 1719 | ah->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); |
1703 | GNUNET_assert(NULL != ah->addresses); | 1720 | GNUNET_assert(NULL != ah->addresses); |
1704 | 1721 | ||
1705 | /* Figure out configured solution method */ | 1722 | /* Figure out configured solution method */ |
@@ -1808,29 +1825,30 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1808 | break; | 1825 | break; |
1809 | } | 1826 | } |
1810 | 1827 | ||
1811 | GNUNET_assert(NULL != ah->s_init); | 1828 | GNUNET_assert (NULL != ah->s_init); |
1812 | GNUNET_assert(NULL != ah->s_add); | 1829 | GNUNET_assert (NULL != ah->s_add); |
1813 | GNUNET_assert(NULL != ah->s_address_update_inuse); | 1830 | GNUNET_assert (NULL != ah->s_address_update_inuse); |
1814 | GNUNET_assert(NULL != ah->s_address_update_property); | 1831 | GNUNET_assert (NULL != ah->s_address_update_property); |
1815 | GNUNET_assert(NULL != ah->s_address_update_session); | 1832 | GNUNET_assert (NULL != ah->s_address_update_session); |
1816 | GNUNET_assert(NULL != ah->s_address_update_network); | 1833 | GNUNET_assert (NULL != ah->s_address_update_network); |
1817 | GNUNET_assert(NULL != ah->s_get); | 1834 | GNUNET_assert (NULL != ah->s_get); |
1818 | GNUNET_assert(NULL != ah->s_get_stop); | 1835 | GNUNET_assert (NULL != ah->s_get_stop); |
1819 | GNUNET_assert(NULL != ah->s_pref); | 1836 | GNUNET_assert (NULL != ah->s_pref); |
1820 | GNUNET_assert(NULL != ah->s_feedback); | 1837 | GNUNET_assert (NULL != ah->s_feedback); |
1821 | GNUNET_assert(NULL != ah->s_del); | 1838 | GNUNET_assert (NULL != ah->s_del); |
1822 | GNUNET_assert(NULL != ah->s_done); | 1839 | GNUNET_assert (NULL != ah->s_done); |
1823 | GNUNET_assert(NULL != ah->s_bulk_start); | 1840 | GNUNET_assert (NULL != ah->s_bulk_start); |
1824 | GNUNET_assert(NULL != ah->s_bulk_stop); | 1841 | GNUNET_assert (NULL != ah->s_bulk_stop); |
1825 | 1842 | ||
1826 | GAS_normalization_start (&normalized_preference_changed_cb, ah, | 1843 | GAS_normalization_start (&normalized_preference_changed_cb, ah, |
1827 | &normalized_property_changed_cb, ah); | 1844 | &normalized_property_changed_cb, ah); |
1828 | quota_count = load_quotas (cfg, quotas_in, quotas_out, | 1845 | quota_count = load_quotas (cfg, quotas_in, quotas_out, |
1829 | GNUNET_ATS_NetworkTypeCount); | 1846 | GNUNET_ATS_NetworkTypeCount); |
1830 | 1847 | ||
1831 | ah->solver = ah->s_init (cfg, stats, ah->addresses, quotas, quotas_in, | 1848 | ah->solver = ah->s_init (cfg, stats, ah->addresses, quotas, quotas_in, |
1832 | quotas_out, quota_count, &bandwidth_changed_cb, ah, &get_preferences_cb, | 1849 | quotas_out, quota_count, |
1833 | NULL, &get_property_cb, NULL ); | 1850 | &bandwidth_changed_cb, ah, &get_preferences_cb, |
1851 | NULL, &get_property_cb, NULL ); | ||
1834 | if (NULL == ah->solver) | 1852 | if (NULL == ah->solver) |
1835 | { | 1853 | { |
1836 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver!\n")); | 1854 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver!\n")); |
@@ -1841,7 +1859,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1841 | ah->running = GNUNET_YES; | 1859 | ah->running = GNUNET_YES; |
1842 | 1860 | ||
1843 | GNUNET_STATISTICS_set (ah->stat, "# addresses", | 1861 | GNUNET_STATISTICS_set (ah->stat, "# addresses", |
1844 | GNUNET_CONTAINER_multihashmap_size (ah->addresses), GNUNET_NO); | 1862 | GNUNET_CONTAINER_multipeermap_size (ah->addresses), GNUNET_NO); |
1845 | 1863 | ||
1846 | return ah; | 1864 | return ah; |
1847 | } | 1865 | } |
@@ -1852,18 +1870,19 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1852 | * @param cls NULL | 1870 | * @param cls NULL |
1853 | * @param key peer identity (unused) | 1871 | * @param key peer identity (unused) |
1854 | * @param value the 'struct ATS_Address' to free | 1872 | * @param value the 'struct ATS_Address' to free |
1855 | * @return GNUNET_OK (continue to iterate) | 1873 | * @return #GNUNET_OK (continue to iterate) |
1856 | */ | 1874 | */ |
1857 | static int | 1875 | static int |
1858 | destroy_all_address_it (void *cls, const struct GNUNET_HashCode * key, | 1876 | destroy_all_address_it (void *cls, |
1859 | void *value) | 1877 | const struct GNUNET_PeerIdentity *key, |
1878 | void *value) | ||
1860 | { | 1879 | { |
1861 | struct GAS_Addresses_Handle *handle = cls; | 1880 | struct GAS_Addresses_Handle *handle = cls; |
1862 | struct ATS_Address *aa = value; | 1881 | struct ATS_Address *aa = value; |
1863 | 1882 | ||
1864 | /* Remove */ | 1883 | /* Remove */ |
1865 | GNUNET_assert( | 1884 | GNUNET_assert(GNUNET_YES == |
1866 | GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->addresses, key, value)); | 1885 | GNUNET_CONTAINER_multipeermap_remove (handle->addresses, key, value)); |
1867 | /* Notify */ | 1886 | /* Notify */ |
1868 | handle->s_del (handle->solver, aa, GNUNET_NO); | 1887 | handle->s_del (handle->solver, aa, GNUNET_NO); |
1869 | /* Destroy */ | 1888 | /* Destroy */ |
@@ -1872,6 +1891,7 @@ destroy_all_address_it (void *cls, const struct GNUNET_HashCode * key, | |||
1872 | return GNUNET_OK; | 1891 | return GNUNET_OK; |
1873 | } | 1892 | } |
1874 | 1893 | ||
1894 | |||
1875 | /** | 1895 | /** |
1876 | * Remove all addresses | 1896 | * Remove all addresses |
1877 | * | 1897 | * |
@@ -1886,11 +1906,13 @@ GAS_addresses_destroy_all (struct GAS_Addresses_Handle *handle) | |||
1886 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Destroying all addresses\n"); | 1906 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Destroying all addresses\n"); |
1887 | handle->s_bulk_start (handle->solver); | 1907 | handle->s_bulk_start (handle->solver); |
1888 | if (handle->addresses != NULL ) | 1908 | if (handle->addresses != NULL ) |
1889 | GNUNET_CONTAINER_multihashmap_iterate (handle->addresses, | 1909 | GNUNET_CONTAINER_multipeermap_iterate (handle->addresses, |
1890 | &destroy_all_address_it, handle); | 1910 | &destroy_all_address_it, |
1911 | handle); | ||
1891 | handle->s_bulk_start (handle->solver); | 1912 | handle->s_bulk_start (handle->solver); |
1892 | } | 1913 | } |
1893 | 1914 | ||
1915 | |||
1894 | /** | 1916 | /** |
1895 | * Shutdown address subsystem. | 1917 | * Shutdown address subsystem. |
1896 | * | 1918 | * |
@@ -1905,7 +1927,7 @@ GAS_addresses_done (struct GAS_Addresses_Handle *handle) | |||
1905 | GNUNET_assert(NULL != handle); | 1927 | GNUNET_assert(NULL != handle); |
1906 | GAS_addresses_destroy_all (handle); | 1928 | GAS_addresses_destroy_all (handle); |
1907 | handle->running = GNUNET_NO; | 1929 | handle->running = GNUNET_NO; |
1908 | GNUNET_CONTAINER_multihashmap_destroy (handle->addresses); | 1930 | GNUNET_CONTAINER_multipeermap_destroy (handle->addresses); |
1909 | handle->addresses = NULL; | 1931 | handle->addresses = NULL; |
1910 | while (NULL != (cur = handle->r_head)) | 1932 | while (NULL != (cur = handle->r_head)) |
1911 | { | 1933 | { |
@@ -1918,34 +1940,36 @@ GAS_addresses_done (struct GAS_Addresses_Handle *handle) | |||
1918 | GAS_normalization_stop (); | 1940 | GAS_normalization_stop (); |
1919 | } | 1941 | } |
1920 | 1942 | ||
1943 | |||
1921 | struct PeerIteratorContext | 1944 | struct PeerIteratorContext |
1922 | { | 1945 | { |
1923 | GNUNET_ATS_Peer_Iterator it; | 1946 | GNUNET_ATS_Peer_Iterator it; |
1924 | void *it_cls; | 1947 | void *it_cls; |
1925 | struct GNUNET_CONTAINER_MultiHashMap *peers_returned; | 1948 | struct GNUNET_CONTAINER_MultiPeerMap *peers_returned; |
1926 | }; | 1949 | }; |
1927 | 1950 | ||
1951 | |||
1928 | /** | 1952 | /** |
1929 | * Iterator to iterate over all peers | 1953 | * Iterator to iterate over all peers |
1930 | * | 1954 | * |
1931 | * @param cls a PeerIteratorContext | 1955 | * @param cls a PeerIteratorContext |
1932 | * @param key the peer id | 1956 | * @param key the peer id |
1933 | * @param value the ATS_address | 1957 | * @param value the ATS_address |
1934 | * @return GNUNET_OK to continue | 1958 | * @return #GNUNET_OK to continue |
1935 | */ | 1959 | */ |
1936 | static int | 1960 | static int |
1937 | peer_it (void *cls, const struct GNUNET_HashCode * key, void *value) | 1961 | peer_it (void *cls, |
1962 | const struct GNUNET_PeerIdentity *key, | ||
1963 | void *value) | ||
1938 | { | 1964 | { |
1939 | struct PeerIteratorContext *ip_ctx = cls; | 1965 | struct PeerIteratorContext *ip_ctx = cls; |
1940 | struct GNUNET_PeerIdentity tmp; | ||
1941 | 1966 | ||
1942 | if (GNUNET_NO | 1967 | if (GNUNET_NO == |
1943 | == GNUNET_CONTAINER_multihashmap_contains (ip_ctx->peers_returned, key)) | 1968 | GNUNET_CONTAINER_multipeermap_contains (ip_ctx->peers_returned, key)) |
1944 | { | 1969 | { |
1945 | GNUNET_CONTAINER_multihashmap_put (ip_ctx->peers_returned, key, NULL, | 1970 | GNUNET_CONTAINER_multipeermap_put (ip_ctx->peers_returned, key, NULL, |
1946 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 1971 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
1947 | tmp.hashPubKey = (*key); | 1972 | ip_ctx->it (ip_ctx->it_cls, key); |
1948 | ip_ctx->it (ip_ctx->it_cls, &tmp); | ||
1949 | } | 1973 | } |
1950 | 1974 | ||
1951 | return GNUNET_OK; | 1975 | return GNUNET_OK; |
@@ -1969,16 +1993,17 @@ GAS_addresses_iterate_peers (struct GAS_Addresses_Handle *handle, | |||
1969 | return; | 1993 | return; |
1970 | GNUNET_assert(NULL != handle->addresses); | 1994 | GNUNET_assert(NULL != handle->addresses); |
1971 | 1995 | ||
1972 | size = GNUNET_CONTAINER_multihashmap_size (handle->addresses); | 1996 | size = GNUNET_CONTAINER_multipeermap_size (handle->addresses); |
1973 | if (0 != size) | 1997 | if (0 != size) |
1974 | { | 1998 | { |
1975 | ip_ctx.it = p_it; | 1999 | ip_ctx.it = p_it; |
1976 | ip_ctx.it_cls = p_it_cls; | 2000 | ip_ctx.it_cls = p_it_cls; |
1977 | ip_ctx.peers_returned = GNUNET_CONTAINER_multihashmap_create (size, | 2001 | ip_ctx.peers_returned = GNUNET_CONTAINER_multipeermap_create (size, |
1978 | GNUNET_NO); | 2002 | GNUNET_NO); |
1979 | GNUNET_CONTAINER_multihashmap_iterate (handle->addresses, &peer_it, | 2003 | GNUNET_CONTAINER_multipeermap_iterate (handle->addresses, |
1980 | &ip_ctx); | 2004 | &peer_it, |
1981 | GNUNET_CONTAINER_multihashmap_destroy (ip_ctx.peers_returned); | 2005 | &ip_ctx); |
2006 | GNUNET_CONTAINER_multipeermap_destroy (ip_ctx.peers_returned); | ||
1982 | } | 2007 | } |
1983 | p_it (p_it_cls, NULL ); | 2008 | p_it (p_it_cls, NULL ); |
1984 | } | 2009 | } |
@@ -1989,19 +2014,22 @@ struct PeerInfoIteratorContext | |||
1989 | void *it_cls; | 2014 | void *it_cls; |
1990 | }; | 2015 | }; |
1991 | 2016 | ||
2017 | |||
1992 | /** | 2018 | /** |
1993 | * Iterator to iterate over a peer's addresses | 2019 | * Iterator to iterate over a peer's addresses |
1994 | * | 2020 | * |
1995 | * @param cls a PeerInfoIteratorContext | 2021 | * @param cls a `struct PeerInfoIteratorContext` |
1996 | * @param key the peer id | 2022 | * @param key the peer id |
1997 | * @param value the ATS_address | 2023 | * @param value the `struct ATS_address` |
1998 | * @return GNUNET_OK to continue | 2024 | * @return #GNUNET_OK to continue |
1999 | */ | 2025 | */ |
2000 | static int | 2026 | static int |
2001 | peerinfo_it (void *cls, const struct GNUNET_HashCode * key, void *value) | 2027 | peerinfo_it (void *cls, |
2028 | const struct GNUNET_PeerIdentity *key, | ||
2029 | void *value) | ||
2002 | { | 2030 | { |
2003 | struct PeerInfoIteratorContext *pi_ctx = cls; | 2031 | struct PeerInfoIteratorContext *pi_ctx = cls; |
2004 | struct ATS_Address *addr = (struct ATS_Address *) value; | 2032 | struct ATS_Address *addr = value; |
2005 | 2033 | ||
2006 | if (NULL != pi_ctx->it) | 2034 | if (NULL != pi_ctx->it) |
2007 | { | 2035 | { |
@@ -2012,6 +2040,7 @@ peerinfo_it (void *cls, const struct GNUNET_HashCode * key, void *value) | |||
2012 | return GNUNET_YES; | 2040 | return GNUNET_YES; |
2013 | } | 2041 | } |
2014 | 2042 | ||
2043 | |||
2015 | /** | 2044 | /** |
2016 | * Return information all peers currently known to ATS | 2045 | * Return information all peers currently known to ATS |
2017 | * | 2046 | * |
@@ -2027,6 +2056,7 @@ GAS_addresses_get_peer_info (struct GAS_Addresses_Handle *handle, | |||
2027 | { | 2056 | { |
2028 | struct PeerInfoIteratorContext pi_ctx; | 2057 | struct PeerInfoIteratorContext pi_ctx; |
2029 | struct GNUNET_BANDWIDTH_Value32NBO zero_bw; | 2058 | struct GNUNET_BANDWIDTH_Value32NBO zero_bw; |
2059 | |||
2030 | GNUNET_assert(NULL != peer); | 2060 | GNUNET_assert(NULL != peer); |
2031 | GNUNET_assert(NULL != handle->addresses); | 2061 | GNUNET_assert(NULL != handle->addresses); |
2032 | if (NULL == pi_it) | 2062 | if (NULL == pi_it) |
@@ -2036,8 +2066,9 @@ GAS_addresses_get_peer_info (struct GAS_Addresses_Handle *handle, | |||
2036 | pi_ctx.it = pi_it; | 2066 | pi_ctx.it = pi_it; |
2037 | pi_ctx.it_cls = pi_it_cls; | 2067 | pi_ctx.it_cls = pi_it_cls; |
2038 | 2068 | ||
2039 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, | 2069 | GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses, |
2040 | &peer->hashPubKey, &peerinfo_it, &pi_ctx); | 2070 | peer, |
2071 | &peerinfo_it, &pi_ctx); | ||
2041 | 2072 | ||
2042 | if (NULL != pi_it) | 2073 | if (NULL != pi_it) |
2043 | pi_it (pi_it_cls, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, zero_bw, | 2074 | pi_it (pi_it_cls, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, zero_bw, |