diff options
Diffstat (limited to 'src/dht/gnunet-service-dht_neighbours.c')
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 360 |
1 files changed, 223 insertions, 137 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 1bbc95a06..15071edca 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -27,7 +27,6 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_block_lib.h" | 29 | #include "gnunet_block_lib.h" |
30 | #include "gnunet_block_group_lib.h" | ||
31 | #include "gnunet_hello_lib.h" | 30 | #include "gnunet_hello_lib.h" |
32 | #include "gnunet_constants.h" | 31 | #include "gnunet_constants.h" |
33 | #include "gnunet_protocols.h" | 32 | #include "gnunet_protocols.h" |
@@ -622,8 +621,9 @@ add_known_to_bloom (void *cls, | |||
622 | GNUNET_CRYPTO_hash (key, | 621 | GNUNET_CRYPTO_hash (key, |
623 | sizeof (struct GNUNET_PeerIdentity), | 622 | sizeof (struct GNUNET_PeerIdentity), |
624 | &key_hash); | 623 | &key_hash); |
625 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | 624 | GNUNET_BLOCK_group_set_seen (bg, |
626 | &key_hash); | 625 | &key_hash, |
626 | 1); | ||
627 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 627 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
628 | "Adding known peer (%s) to bloomfilter for FIND PEER\n", | 628 | "Adding known peer (%s) to bloomfilter for FIND PEER\n", |
629 | GNUNET_i2s (key)); | 629 | GNUNET_i2s (key)); |
@@ -656,14 +656,15 @@ send_find_peer_message (void *cls) | |||
656 | newly_found_peers = 0; | 656 | newly_found_peers = 0; |
657 | return; | 657 | return; |
658 | } | 658 | } |
659 | bg = GNUNET_BLOCK_GROUP_bf_create (NULL, | 659 | bg = GNUNET_BLOCK_group_create (GDS_block_context, |
660 | DHT_BLOOM_SIZE, | 660 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
661 | GNUNET_CONSTANTS_BLOOMFILTER_K, | 661 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
662 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 662 | UINT32_MAX), |
663 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 663 | NULL, |
664 | UINT32_MAX), | 664 | 0, |
665 | NULL, | 665 | "filter-size", |
666 | 0); | 666 | DHT_BLOOM_SIZE, |
667 | NULL); | ||
667 | GNUNET_CONTAINER_multipeermap_iterate (all_connected_peers, | 668 | GNUNET_CONTAINER_multipeermap_iterate (all_connected_peers, |
668 | &add_known_to_bloom, | 669 | &add_known_to_bloom, |
669 | bg); | 670 | bg); |
@@ -677,7 +678,7 @@ send_find_peer_message (void *cls) | |||
677 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 678 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
678 | // FIXME: pass priority!? | 679 | // FIXME: pass priority!? |
679 | GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO, | 680 | GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO, |
680 | GNUNET_DHT_RO_FIND_PEER, | 681 | GNUNET_DHT_RO_FIND_PEER | GNUNET_DHT_RO_RECORD_ROUTE, |
681 | FIND_PEER_REPLICATION_LEVEL, | 682 | FIND_PEER_REPLICATION_LEVEL, |
682 | 0, | 683 | 0, |
683 | &my_identity_hash, | 684 | &my_identity_hash, |
@@ -1022,10 +1023,10 @@ select_peer (const struct GNUNET_HashCode *key, | |||
1022 | count = 0; | 1023 | count = 0; |
1023 | while ((pos != NULL) && (count < bucket_size)) | 1024 | while ((pos != NULL) && (count < bucket_size)) |
1024 | { | 1025 | { |
1025 | if ((bloom == NULL) || | 1026 | if ( (NULL == bloom) || |
1026 | (GNUNET_NO == | 1027 | (GNUNET_NO == |
1027 | GNUNET_CONTAINER_bloomfilter_test (bloom, | 1028 | GNUNET_CONTAINER_bloomfilter_test (bloom, |
1028 | &pos->phash))) | 1029 | &pos->phash))) |
1029 | { | 1030 | { |
1030 | dist = get_distance (key, | 1031 | dist = get_distance (key, |
1031 | &pos->phash); | 1032 | &pos->phash); |
@@ -1059,8 +1060,14 @@ select_peer (const struct GNUNET_HashCode *key, | |||
1059 | } | 1060 | } |
1060 | if (NULL == chosen) | 1061 | if (NULL == chosen) |
1061 | GNUNET_STATISTICS_update (GDS_stats, | 1062 | GNUNET_STATISTICS_update (GDS_stats, |
1062 | gettext_noop ("# Peer selection failed"), 1, | 1063 | gettext_noop ("# Peer selection failed"), |
1064 | 1, | ||
1063 | GNUNET_NO); | 1065 | GNUNET_NO); |
1066 | else | ||
1067 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1068 | "Selected peer `%s' in greedy routing for %s\n", | ||
1069 | GNUNET_i2s (chosen->id), | ||
1070 | GNUNET_h2s (key)); | ||
1064 | return chosen; | 1071 | return chosen; |
1065 | } | 1072 | } |
1066 | 1073 | ||
@@ -1070,12 +1077,12 @@ select_peer (const struct GNUNET_HashCode *key, | |||
1070 | for (bc = 0; bc <= closest_bucket; bc++) | 1077 | for (bc = 0; bc <= closest_bucket; bc++) |
1071 | { | 1078 | { |
1072 | pos = k_buckets[bc].head; | 1079 | pos = k_buckets[bc].head; |
1073 | while ((pos != NULL) && (count < bucket_size)) | 1080 | while ( (NULL != pos) && (count < bucket_size) ) |
1074 | { | 1081 | { |
1075 | if ((bloom != NULL) && | 1082 | if ( (NULL != bloom) && |
1076 | (GNUNET_YES == | 1083 | (GNUNET_YES == |
1077 | GNUNET_CONTAINER_bloomfilter_test (bloom, | 1084 | GNUNET_CONTAINER_bloomfilter_test (bloom, |
1078 | &pos->phash))) | 1085 | &pos->phash)) ) |
1079 | { | 1086 | { |
1080 | GNUNET_STATISTICS_update (GDS_stats, | 1087 | GNUNET_STATISTICS_update (GDS_stats, |
1081 | gettext_noop | 1088 | gettext_noop |
@@ -1115,7 +1122,13 @@ select_peer (const struct GNUNET_HashCode *key, | |||
1115 | continue; /* Ignore bloomfiltered peers */ | 1122 | continue; /* Ignore bloomfiltered peers */ |
1116 | } | 1123 | } |
1117 | if (0 == selected--) | 1124 | if (0 == selected--) |
1125 | { | ||
1126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1127 | "Selected peer `%s' in random routing for %s\n", | ||
1128 | GNUNET_i2s (pos->id), | ||
1129 | GNUNET_h2s (key)); | ||
1118 | return pos; | 1130 | return pos; |
1131 | } | ||
1119 | } | 1132 | } |
1120 | } | 1133 | } |
1121 | GNUNET_break (0); | 1134 | GNUNET_break (0); |
@@ -1160,7 +1173,9 @@ get_target_peers (const struct GNUNET_HashCode *key, | |||
1160 | struct PeerInfo *); | 1173 | struct PeerInfo *); |
1161 | for (off = 0; off < ret; off++) | 1174 | for (off = 0; off < ret; off++) |
1162 | { | 1175 | { |
1163 | nxt = select_peer (key, bloom, hop_count); | 1176 | nxt = select_peer (key, |
1177 | bloom, | ||
1178 | hop_count); | ||
1164 | if (NULL == nxt) | 1179 | if (NULL == nxt) |
1165 | break; | 1180 | break; |
1166 | rtargets[off] = nxt; | 1181 | rtargets[off] = nxt; |
@@ -1241,7 +1256,8 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, | |||
1241 | "Adding myself (%s) to PUT bloomfilter for %s\n", | 1256 | "Adding myself (%s) to PUT bloomfilter for %s\n", |
1242 | GNUNET_i2s (&my_identity), | 1257 | GNUNET_i2s (&my_identity), |
1243 | GNUNET_h2s (key)); | 1258 | GNUNET_h2s (key)); |
1244 | GNUNET_CONTAINER_bloomfilter_add (bf, &my_identity_hash); | 1259 | GNUNET_CONTAINER_bloomfilter_add (bf, |
1260 | &my_identity_hash); | ||
1245 | GNUNET_STATISTICS_update (GDS_stats, | 1261 | GNUNET_STATISTICS_update (GDS_stats, |
1246 | gettext_noop ("# PUT requests routed"), | 1262 | gettext_noop ("# PUT requests routed"), |
1247 | 1, | 1263 | 1, |
@@ -1664,10 +1680,13 @@ handle_dht_p2p_put (void *cls, | |||
1664 | if (GNUNET_YES == log_route_details_stderr) | 1680 | if (GNUNET_YES == log_route_details_stderr) |
1665 | { | 1681 | { |
1666 | char *tmp; | 1682 | char *tmp; |
1683 | char *pp; | ||
1667 | 1684 | ||
1685 | pp = GNUNET_STRINGS_pp2s (put_path, | ||
1686 | putlen); | ||
1668 | tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); | 1687 | tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); |
1669 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, | 1688 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, |
1670 | "R5N PUT %s: %s->%s (%u, %u=>%u)\n", | 1689 | "R5N PUT %s: %s->%s (%u, %u=>%u, PP: %s)\n", |
1671 | GNUNET_h2s (&put->key), | 1690 | GNUNET_h2s (&put->key), |
1672 | GNUNET_i2s (peer->id), | 1691 | GNUNET_i2s (peer->id), |
1673 | tmp, | 1692 | tmp, |
@@ -1675,8 +1694,9 @@ handle_dht_p2p_put (void *cls, | |||
1675 | GNUNET_CRYPTO_hash_matching_bits (&peer->phash, | 1694 | GNUNET_CRYPTO_hash_matching_bits (&peer->phash, |
1676 | &put->key), | 1695 | &put->key), |
1677 | GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, | 1696 | GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, |
1678 | &put->key) | 1697 | &put->key), |
1679 | ); | 1698 | pp); |
1699 | GNUNET_free (pp); | ||
1680 | GNUNET_free (tmp); | 1700 | GNUNET_free (tmp); |
1681 | } | 1701 | } |
1682 | switch (GNUNET_BLOCK_get_key | 1702 | switch (GNUNET_BLOCK_get_key |
@@ -1839,22 +1859,26 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1839 | struct PeerInfo *peer; | 1859 | struct PeerInfo *peer; |
1840 | unsigned int choice; | 1860 | unsigned int choice; |
1841 | const struct GNUNET_HELLO_Message *hello; | 1861 | const struct GNUNET_HELLO_Message *hello; |
1862 | size_t hello_size; | ||
1842 | 1863 | ||
1843 | /* first, check about our own HELLO */ | 1864 | /* first, check about our own HELLO */ |
1844 | if (NULL != GDS_my_hello) | 1865 | if (NULL != GDS_my_hello) |
1845 | { | 1866 | { |
1846 | if (GNUNET_YES != | 1867 | hello_size = GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) GDS_my_hello); |
1847 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | 1868 | GNUNET_break (hello_size >= sizeof (struct GNUNET_MessageHeader)); |
1848 | &my_identity_hash)) | 1869 | if (GNUNET_BLOCK_EVALUATION_OK_MORE == |
1870 | GNUNET_BLOCK_evaluate (GDS_block_context, | ||
1871 | GNUNET_BLOCK_TYPE_DHT_HELLO, | ||
1872 | bg, | ||
1873 | GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, | ||
1874 | &my_identity_hash, | ||
1875 | NULL, 0, | ||
1876 | GDS_my_hello, | ||
1877 | hello_size)) | ||
1849 | { | 1878 | { |
1850 | size_t hello_size; | ||
1851 | |||
1852 | hello_size = GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) GDS_my_hello); | ||
1853 | GNUNET_break (hello_size >= sizeof (struct GNUNET_MessageHeader)); | ||
1854 | GDS_NEIGHBOURS_handle_reply (sender, | 1879 | GDS_NEIGHBOURS_handle_reply (sender, |
1855 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 1880 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
1856 | GNUNET_TIME_relative_to_absolute | 1881 | GNUNET_TIME_relative_to_absolute (hello_expiration), |
1857 | (hello_expiration), | ||
1858 | key, | 1882 | key, |
1859 | 0, | 1883 | 0, |
1860 | NULL, | 1884 | NULL, |
@@ -1911,9 +1935,15 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1911 | peer = bucket->head; | 1935 | peer = bucket->head; |
1912 | hello = GDS_HELLO_get (peer->id); | 1936 | hello = GDS_HELLO_get (peer->id); |
1913 | } while ( (NULL == hello) || | 1937 | } while ( (NULL == hello) || |
1914 | (GNUNET_YES == | 1938 | (GNUNET_BLOCK_EVALUATION_OK_MORE != |
1915 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, | 1939 | GNUNET_BLOCK_evaluate (GDS_block_context, |
1916 | &peer->phash)) ); | 1940 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
1941 | bg, | ||
1942 | GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, | ||
1943 | &peer->phash, | ||
1944 | NULL, 0, | ||
1945 | hello, | ||
1946 | (hello_size = GNUNET_HELLO_size (hello)))) ); | ||
1917 | GDS_NEIGHBOURS_handle_reply (sender, | 1947 | GDS_NEIGHBOURS_handle_reply (sender, |
1918 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 1948 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
1919 | GNUNET_TIME_relative_to_absolute | 1949 | GNUNET_TIME_relative_to_absolute |
@@ -1924,14 +1954,14 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1924 | 0, | 1954 | 0, |
1925 | NULL, | 1955 | NULL, |
1926 | hello, | 1956 | hello, |
1927 | GNUNET_HELLO_size (hello)); | 1957 | hello_size); |
1928 | } | 1958 | } |
1929 | 1959 | ||
1930 | 1960 | ||
1931 | /** | 1961 | /** |
1932 | * Handle a result from local datacache for a GET operation. | 1962 | * Handle a result from local datacache for a GET operation. |
1933 | * | 1963 | * |
1934 | * @param cls the `struct ClientHandle` of the client doing the query | 1964 | * @param cls the `struct PeerInfo` for which this is a reply |
1935 | * @param type type of the block | 1965 | * @param type type of the block |
1936 | * @param expiration_time when does the content expire | 1966 | * @param expiration_time when does the content expire |
1937 | * @param key key for the content | 1967 | * @param key key for the content |
@@ -1954,15 +1984,23 @@ handle_local_result (void *cls, | |||
1954 | const void *data, | 1984 | const void *data, |
1955 | size_t data_size) | 1985 | size_t data_size) |
1956 | { | 1986 | { |
1957 | // FIXME: we can probably do better here by | 1987 | struct PeerInfo *peer = cls; |
1958 | // passing the peer that did the query in the closure... | 1988 | char *pp; |
1959 | GDS_ROUTING_process (NULL, | 1989 | |
1960 | type, | 1990 | pp = GNUNET_STRINGS_pp2s (put_path, |
1961 | expiration_time, | 1991 | put_path_length); |
1962 | key, | 1992 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1963 | put_path_length, put_path, | 1993 | "Found local result for %s (PP: %s)\n", |
1964 | 0, NULL, | 1994 | GNUNET_h2s (key), |
1965 | data, data_size); | 1995 | pp); |
1996 | GNUNET_free (pp); | ||
1997 | GDS_NEIGHBOURS_handle_reply (peer->id, | ||
1998 | type, | ||
1999 | expiration_time, | ||
2000 | key, | ||
2001 | put_path_length, put_path, | ||
2002 | get_path_length, get_path, | ||
2003 | data, data_size); | ||
1966 | } | 2004 | } |
1967 | 2005 | ||
1968 | 2006 | ||
@@ -2013,11 +2051,6 @@ handle_dht_p2p_get (void *cls, | |||
2013 | const char *xquery; | 2051 | const char *xquery; |
2014 | int forwarded; | 2052 | int forwarded; |
2015 | 2053 | ||
2016 | if (NULL == peer) | ||
2017 | { | ||
2018 | GNUNET_break (0); | ||
2019 | return; | ||
2020 | } | ||
2021 | /* parse and validate message */ | 2054 | /* parse and validate message */ |
2022 | msize = ntohs (get->header.size); | 2055 | msize = ntohs (get->header.size); |
2023 | xquery_size = ntohl (get->xquery_size); | 2056 | xquery_size = ntohl (get->xquery_size); |
@@ -2052,15 +2085,10 @@ handle_dht_p2p_get (void *cls, | |||
2052 | xquery); | 2085 | xquery); |
2053 | GNUNET_free (tmp); | 2086 | GNUNET_free (tmp); |
2054 | } | 2087 | } |
2055 | bg = GNUNET_BLOCK_group_create (GDS_block_context, | ||
2056 | type, | ||
2057 | get->bf_mutator, | ||
2058 | &xquery[xquery_size], | ||
2059 | reply_bf_size); | ||
2060 | eval | 2088 | eval |
2061 | = GNUNET_BLOCK_evaluate (GDS_block_context, | 2089 | = GNUNET_BLOCK_evaluate (GDS_block_context, |
2062 | type, | 2090 | type, |
2063 | bg, | 2091 | NULL, |
2064 | GNUNET_BLOCK_EO_NONE, | 2092 | GNUNET_BLOCK_EO_NONE, |
2065 | &get->key, | 2093 | &get->key, |
2066 | xquery, | 2094 | xquery, |
@@ -2071,7 +2099,6 @@ handle_dht_p2p_get (void *cls, | |||
2071 | { | 2099 | { |
2072 | /* request invalid or block type not supported */ | 2100 | /* request invalid or block type not supported */ |
2073 | GNUNET_break_op (eval == GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED); | 2101 | GNUNET_break_op (eval == GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED); |
2074 | GNUNET_BLOCK_group_destroy (bg); | ||
2075 | return; | 2102 | return; |
2076 | } | 2103 | } |
2077 | peer_bf = GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, | 2104 | peer_bf = GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, |
@@ -2080,14 +2107,14 @@ handle_dht_p2p_get (void *cls, | |||
2080 | GNUNET_break_op (GNUNET_YES == | 2107 | GNUNET_break_op (GNUNET_YES == |
2081 | GNUNET_CONTAINER_bloomfilter_test (peer_bf, | 2108 | GNUNET_CONTAINER_bloomfilter_test (peer_bf, |
2082 | &peer->phash)); | 2109 | &peer->phash)); |
2083 | /* remember request for routing replies */ | 2110 | bg = GNUNET_BLOCK_group_create (GDS_block_context, |
2084 | GDS_ROUTING_add (peer->id, | 2111 | type, |
2085 | type, | 2112 | get->bf_mutator, |
2086 | bg, /* bg now owned by routing, but valid at least until end of this function! */ | 2113 | &xquery[xquery_size], |
2087 | options, | 2114 | reply_bf_size, |
2088 | &get->key, | 2115 | "filter-size", |
2089 | xquery, | 2116 | reply_bf_size, |
2090 | xquery_size); | 2117 | NULL); |
2091 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2118 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2092 | "GET for %s at %s after %u hops\n", | 2119 | "GET for %s at %s after %u hops\n", |
2093 | GNUNET_h2s (&get->key), | 2120 | GNUNET_h2s (&get->key), |
@@ -2116,7 +2143,7 @@ handle_dht_p2p_get (void *cls, | |||
2116 | xquery_size, | 2143 | xquery_size, |
2117 | bg, | 2144 | bg, |
2118 | &handle_local_result, | 2145 | &handle_local_result, |
2119 | NULL); | 2146 | peer); |
2120 | } | 2147 | } |
2121 | } | 2148 | } |
2122 | else | 2149 | else |
@@ -2127,6 +2154,15 @@ handle_dht_p2p_get (void *cls, | |||
2127 | GNUNET_NO); | 2154 | GNUNET_NO); |
2128 | } | 2155 | } |
2129 | 2156 | ||
2157 | /* remember request for routing replies */ | ||
2158 | GDS_ROUTING_add (peer->id, | ||
2159 | type, | ||
2160 | bg, /* bg now owned by routing, but valid at least until end of this function! */ | ||
2161 | options, | ||
2162 | &get->key, | ||
2163 | xquery, | ||
2164 | xquery_size); | ||
2165 | |||
2130 | /* P2P forwarding */ | 2166 | /* P2P forwarding */ |
2131 | forwarded = GNUNET_NO; | 2167 | forwarded = GNUNET_NO; |
2132 | if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) | 2168 | if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) |
@@ -2189,6 +2225,81 @@ check_dht_p2p_result (void *cls, | |||
2189 | 2225 | ||
2190 | 2226 | ||
2191 | /** | 2227 | /** |
2228 | * Process a reply, after the @a get_path has been updated. | ||
2229 | * | ||
2230 | * @param expiration_time when does the reply expire | ||
2231 | * @param key key matching the query | ||
2232 | * @param get_path_length number of entries in @a get_path | ||
2233 | * @param get_path path the reply has taken | ||
2234 | * @param put_path_length number of entries in @a put_path | ||
2235 | * @param put_path path the PUT has taken | ||
2236 | * @param type type of the block | ||
2237 | * @param data_size number of bytes in @a data | ||
2238 | * @param data payload of the reply | ||
2239 | */ | ||
2240 | static void | ||
2241 | process_reply_with_path (struct GNUNET_TIME_Absolute expiration_time, | ||
2242 | const struct GNUNET_HashCode *key, | ||
2243 | unsigned int get_path_length, | ||
2244 | const struct GNUNET_PeerIdentity *get_path, | ||
2245 | unsigned int put_path_length, | ||
2246 | const struct GNUNET_PeerIdentity *put_path, | ||
2247 | enum GNUNET_BLOCK_Type type, | ||
2248 | size_t data_size, | ||
2249 | const void *data) | ||
2250 | { | ||
2251 | /* forward to local clients */ | ||
2252 | GDS_CLIENTS_handle_reply (expiration_time, | ||
2253 | key, | ||
2254 | get_path_length, | ||
2255 | get_path, | ||
2256 | put_path_length, | ||
2257 | put_path, | ||
2258 | type, | ||
2259 | data_size, | ||
2260 | data); | ||
2261 | GDS_CLIENTS_process_get_resp (type, | ||
2262 | get_path, | ||
2263 | get_path_length, | ||
2264 | put_path, | ||
2265 | put_path_length, | ||
2266 | expiration_time, | ||
2267 | key, | ||
2268 | data, | ||
2269 | data_size); | ||
2270 | if (GNUNET_YES == cache_results) | ||
2271 | { | ||
2272 | struct GNUNET_PeerIdentity xput_path[get_path_length + 1 + put_path_length]; | ||
2273 | |||
2274 | GNUNET_memcpy (xput_path, | ||
2275 | put_path, | ||
2276 | put_path_length * sizeof (struct GNUNET_PeerIdentity)); | ||
2277 | GNUNET_memcpy (&xput_path[put_path_length], | ||
2278 | get_path, | ||
2279 | get_path_length * sizeof (struct GNUNET_PeerIdentity)); | ||
2280 | |||
2281 | GDS_DATACACHE_handle_put (expiration_time, | ||
2282 | key, | ||
2283 | get_path_length + put_path_length, | ||
2284 | xput_path, | ||
2285 | type, | ||
2286 | data_size, | ||
2287 | data); | ||
2288 | } | ||
2289 | /* forward to other peers */ | ||
2290 | GDS_ROUTING_process (type, | ||
2291 | expiration_time, | ||
2292 | key, | ||
2293 | put_path_length, | ||
2294 | put_path, | ||
2295 | get_path_length, | ||
2296 | get_path, | ||
2297 | data, | ||
2298 | data_size); | ||
2299 | } | ||
2300 | |||
2301 | |||
2302 | /** | ||
2192 | * Core handler for p2p result messages. | 2303 | * Core handler for p2p result messages. |
2193 | * | 2304 | * |
2194 | * @param cls closure | 2305 | * @param cls closure |
@@ -2230,14 +2341,23 @@ handle_dht_p2p_result (void *cls, | |||
2230 | if (GNUNET_YES == log_route_details_stderr) | 2341 | if (GNUNET_YES == log_route_details_stderr) |
2231 | { | 2342 | { |
2232 | char *tmp; | 2343 | char *tmp; |
2344 | char *pp; | ||
2345 | char *gp; | ||
2233 | 2346 | ||
2347 | gp = GNUNET_STRINGS_pp2s (get_path, | ||
2348 | get_path_length); | ||
2349 | pp = GNUNET_STRINGS_pp2s (put_path, | ||
2350 | put_path_length); | ||
2234 | tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); | 2351 | tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); |
2235 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, | 2352 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, |
2236 | "R5N RESULT %s: %s->%s (%u)\n", | 2353 | "R5N RESULT %s: %s->%s (GP: %s, PP: %s)\n", |
2237 | GNUNET_h2s (&prm->key), | 2354 | GNUNET_h2s (&prm->key), |
2238 | GNUNET_i2s (peer->id), | 2355 | GNUNET_i2s (peer->id), |
2239 | tmp, | 2356 | tmp, |
2240 | get_path_length + 1); | 2357 | gp, |
2358 | pp); | ||
2359 | GNUNET_free (gp); | ||
2360 | GNUNET_free (pp); | ||
2241 | GNUNET_free (tmp); | 2361 | GNUNET_free (tmp); |
2242 | } | 2362 | } |
2243 | /* if we got a HELLO, consider it for our own routing table */ | 2363 | /* if we got a HELLO, consider it for our own routing table */ |
@@ -2273,78 +2393,44 @@ handle_dht_p2p_result (void *cls, | |||
2273 | h); | 2393 | h); |
2274 | } | 2394 | } |
2275 | 2395 | ||
2276 | /* append 'peer' to 'get_path' */ | ||
2277 | { | ||
2278 | struct GNUNET_PeerIdentity xget_path[get_path_length + 1]; | ||
2279 | 2396 | ||
2280 | #if SANITY_CHECKS | 2397 | /* First, check if 'peer' is already on the path, and if |
2281 | for (unsigned int i=0;i<=get_path_length;i++) | 2398 | so, truncate it instead of expanding. */ |
2399 | for (unsigned int i=0;i<=get_path_length;i++) | ||
2400 | if (0 == memcmp (&get_path[i], | ||
2401 | peer->id, | ||
2402 | sizeof (struct GNUNET_PeerIdentity))) | ||
2282 | { | 2403 | { |
2283 | for (unsigned int j=0;j<i;j++) | 2404 | process_reply_with_path (GNUNET_TIME_absolute_ntoh (prm->expiration_time), |
2284 | { | 2405 | &prm->key, |
2285 | GNUNET_break (0 != memcmp (&get_path[i], | 2406 | i, |
2286 | &get_path[j], | 2407 | get_path, |
2287 | sizeof (struct GNUNET_PeerIdentity))); | 2408 | put_path_length, |
2288 | } | 2409 | put_path, |
2289 | GNUNET_break (0 != memcmp (&get_path[i], | 2410 | type, |
2290 | peer->id, | 2411 | data_size, |
2291 | sizeof (struct GNUNET_PeerIdentity))); | 2412 | data); |
2413 | return; | ||
2292 | } | 2414 | } |
2293 | #endif | 2415 | |
2416 | /* Need to append 'peer' to 'get_path' (normal case) */ | ||
2417 | { | ||
2418 | struct GNUNET_PeerIdentity xget_path[get_path_length + 1]; | ||
2419 | |||
2294 | GNUNET_memcpy (xget_path, | 2420 | GNUNET_memcpy (xget_path, |
2295 | get_path, | 2421 | get_path, |
2296 | get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 2422 | get_path_length * sizeof (struct GNUNET_PeerIdentity)); |
2297 | xget_path[get_path_length] = *peer->id; | 2423 | xget_path[get_path_length] = *peer->id; |
2298 | get_path_length++; | ||
2299 | |||
2300 | /* forward to local clients */ | ||
2301 | GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (prm->expiration_time), | ||
2302 | &prm->key, | ||
2303 | get_path_length, | ||
2304 | xget_path, | ||
2305 | put_path_length, | ||
2306 | put_path, | ||
2307 | type, | ||
2308 | data_size, | ||
2309 | data); | ||
2310 | GDS_CLIENTS_process_get_resp (type, | ||
2311 | xget_path, | ||
2312 | get_path_length, | ||
2313 | put_path, put_path_length, | ||
2314 | GNUNET_TIME_absolute_ntoh (prm->expiration_time), | ||
2315 | &prm->key, | ||
2316 | data, | ||
2317 | data_size); | ||
2318 | if (GNUNET_YES == cache_results) | ||
2319 | { | ||
2320 | struct GNUNET_PeerIdentity xput_path[get_path_length + 1 + put_path_length]; | ||
2321 | 2424 | ||
2322 | GNUNET_memcpy (xput_path, | 2425 | process_reply_with_path (GNUNET_TIME_absolute_ntoh (prm->expiration_time), |
2323 | put_path, | 2426 | &prm->key, |
2324 | put_path_length * sizeof (struct GNUNET_PeerIdentity)); | 2427 | get_path_length + 1, |
2325 | GNUNET_memcpy (&xput_path[put_path_length], | 2428 | xget_path, |
2326 | xget_path, | 2429 | put_path_length, |
2327 | get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 2430 | put_path, |
2328 | 2431 | type, | |
2329 | GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (prm->expiration_time), | 2432 | data_size, |
2330 | &prm->key, | 2433 | data); |
2331 | get_path_length + put_path_length, | ||
2332 | xput_path, | ||
2333 | type, | ||
2334 | data_size, | ||
2335 | data); | ||
2336 | } | ||
2337 | /* forward to other peers */ | ||
2338 | GDS_ROUTING_process (NULL, | ||
2339 | type, | ||
2340 | GNUNET_TIME_absolute_ntoh (prm->expiration_time), | ||
2341 | &prm->key, | ||
2342 | put_path_length, | ||
2343 | put_path, | ||
2344 | get_path_length, | ||
2345 | xget_path, | ||
2346 | data, | ||
2347 | data_size); | ||
2348 | } | 2434 | } |
2349 | } | 2435 | } |
2350 | 2436 | ||