diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-07-07 13:42:52 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-07-07 13:42:52 +0200 |
commit | 2906241b6a21d6009a0d195199f3a08e8f4d4e2a (patch) | |
tree | c9946fd81f343008877b41fc8471d13d0051f48a /src/dht/gnunet-service-dht_neighbours.c | |
parent | 374e3cf6de48f26f67cf93091a2bfbdab019a6eb (diff) | |
download | gnunet-2906241b6a21d6009a0d195199f3a08e8f4d4e2a.tar.gz gnunet-2906241b6a21d6009a0d195199f3a08e8f4d4e2a.zip |
major modification to datacache to store route options (and clean up the API)
Diffstat (limited to 'src/dht/gnunet-service-dht_neighbours.c')
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index fde25936f..2a54f715a 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -1285,7 +1285,7 @@ get_target_peers (const struct GNUNET_HashCode *key, | |||
1285 | * @param bd block data we got | 1285 | * @param bd block data we got |
1286 | */ | 1286 | */ |
1287 | static void | 1287 | static void |
1288 | hello_check (const struct GDS_DATACACHE_BlockData *bd) | 1288 | hello_check (const struct GNUNET_DATACACHE_Block *bd) |
1289 | { | 1289 | { |
1290 | struct GNUNET_PeerIdentity pid; | 1290 | struct GNUNET_PeerIdentity pid; |
1291 | struct GNUNET_HELLO_Builder *b; | 1291 | struct GNUNET_HELLO_Builder *b; |
@@ -1305,8 +1305,7 @@ hello_check (const struct GDS_DATACACHE_BlockData *bd) | |||
1305 | 1305 | ||
1306 | 1306 | ||
1307 | enum GNUNET_GenericReturnValue | 1307 | enum GNUNET_GenericReturnValue |
1308 | GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd, | 1308 | GDS_NEIGHBOURS_handle_put (const struct GNUNET_DATACACHE_Block *bd, |
1309 | enum GNUNET_DHT_RouteOption options, | ||
1310 | uint16_t desired_replication_level, | 1309 | uint16_t desired_replication_level, |
1311 | uint16_t hop_count, | 1310 | uint16_t hop_count, |
1312 | struct GNUNET_CONTAINER_BloomFilter *bf) | 1311 | struct GNUNET_CONTAINER_BloomFilter *bf) |
@@ -1336,8 +1335,8 @@ GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd, | |||
1336 | "Adding myself (%s) to PUT bloomfilter for %s with RO(%s/%s)\n", | 1335 | "Adding myself (%s) to PUT bloomfilter for %s with RO(%s/%s)\n", |
1337 | GNUNET_i2s (&GDS_my_identity), | 1336 | GNUNET_i2s (&GDS_my_identity), |
1338 | GNUNET_h2s (&bd->key), | 1337 | GNUNET_h2s (&bd->key), |
1339 | (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE) ? "x" : "-", | 1338 | (bd->ro & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE) ? "x" : "-", |
1340 | (options & GNUNET_DHT_RO_RECORD_ROUTE) ? "R" : "-"); | 1339 | (bd->ro & GNUNET_DHT_RO_RECORD_ROUTE) ? "R" : "-"); |
1341 | 1340 | ||
1342 | /* if we got a HELLO, consider it for our own routing table */ | 1341 | /* if we got a HELLO, consider it for our own routing table */ |
1343 | hello_check (bd); | 1342 | hello_check (bd); |
@@ -1394,7 +1393,7 @@ GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd, | |||
1394 | ppm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); | 1393 | ppm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); |
1395 | ppm->header.size = htons (sizeof (buf)); | 1394 | ppm->header.size = htons (sizeof (buf)); |
1396 | ppm->type = htonl (bd->type); | 1395 | ppm->type = htonl (bd->type); |
1397 | ppm->options = htons (options); | 1396 | ppm->options = htons (bd->ro); |
1398 | ppm->hop_count = htons (hop_count + 1); | 1397 | ppm->hop_count = htons (hop_count + 1); |
1399 | ppm->desired_replication_level = htons (desired_replication_level); | 1398 | ppm->desired_replication_level = htons (desired_replication_level); |
1400 | ppm->put_path_length = htons (put_path_length); | 1399 | ppm->put_path_length = htons (put_path_length); |
@@ -1565,7 +1564,7 @@ GDS_NEIGHBOURS_lookup_peer (const struct GNUNET_PeerIdentity *target) | |||
1565 | 1564 | ||
1566 | bool | 1565 | bool |
1567 | GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi, | 1566 | GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi, |
1568 | const struct GDS_DATACACHE_BlockData *bd, | 1567 | const struct GNUNET_DATACACHE_Block *bd, |
1569 | const struct GNUNET_HashCode *query_hash, | 1568 | const struct GNUNET_HashCode *query_hash, |
1570 | unsigned int get_path_length, | 1569 | unsigned int get_path_length, |
1571 | const struct GNUNET_DHT_PathElement *get_path) | 1570 | const struct GNUNET_DHT_PathElement *get_path) |
@@ -1748,16 +1747,15 @@ handle_dht_p2p_put (void *cls, | |||
1748 | struct Target *t = cls; | 1747 | struct Target *t = cls; |
1749 | struct PeerInfo *peer = t->pi; | 1748 | struct PeerInfo *peer = t->pi; |
1750 | uint16_t msize = ntohs (put->header.size); | 1749 | uint16_t msize = ntohs (put->header.size); |
1751 | enum GNUNET_DHT_RouteOption options | ||
1752 | = (enum GNUNET_DHT_RouteOption) ntohs (put->options); | ||
1753 | const struct GNUNET_DHT_PathElement *put_path | 1750 | const struct GNUNET_DHT_PathElement *put_path |
1754 | = (const struct GNUNET_DHT_PathElement *) &put[1]; | 1751 | = (const struct GNUNET_DHT_PathElement *) &put[1]; |
1755 | uint16_t putlen | 1752 | uint16_t putlen |
1756 | = ntohs (put->put_path_length); | 1753 | = ntohs (put->put_path_length); |
1757 | struct GDS_DATACACHE_BlockData bd = { | 1754 | struct GNUNET_DATACACHE_Block bd = { |
1758 | .key = put->key, | 1755 | .key = put->key, |
1759 | .expiration_time = GNUNET_TIME_absolute_ntoh (put->expiration_time), | 1756 | .expiration_time = GNUNET_TIME_absolute_ntoh (put->expiration_time), |
1760 | .type = ntohl (put->type), | 1757 | .type = ntohl (put->type), |
1758 | .ro = (enum GNUNET_DHT_RouteOption) ntohs (put->options), | ||
1761 | .data_size = msize - (sizeof(*put) | 1759 | .data_size = msize - (sizeof(*put) |
1762 | + putlen * sizeof(struct GNUNET_DHT_PathElement)), | 1760 | + putlen * sizeof(struct GNUNET_DHT_PathElement)), |
1763 | .data = &put_path[putlen] | 1761 | .data = &put_path[putlen] |
@@ -1767,8 +1765,8 @@ handle_dht_p2p_put (void *cls, | |||
1767 | "PUT for `%s' from %s with RO (%s/%s)\n", | 1765 | "PUT for `%s' from %s with RO (%s/%s)\n", |
1768 | GNUNET_h2s (&put->key), | 1766 | GNUNET_h2s (&put->key), |
1769 | GNUNET_i2s (&peer->id), | 1767 | GNUNET_i2s (&peer->id), |
1770 | (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE) ? "x" : "-", | 1768 | (bd.ro & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE) ? "x" : "-", |
1771 | (options & GNUNET_DHT_RO_RECORD_ROUTE) ? "R" : "-"); | 1769 | (bd.ro & GNUNET_DHT_RO_RECORD_ROUTE) ? "R" : "-"); |
1772 | if (GNUNET_TIME_absolute_is_past (bd.expiration_time)) | 1770 | if (GNUNET_TIME_absolute_is_past (bd.expiration_time)) |
1773 | { | 1771 | { |
1774 | GNUNET_STATISTICS_update (GDS_stats, | 1772 | GNUNET_STATISTICS_update (GDS_stats, |
@@ -1786,7 +1784,7 @@ handle_dht_p2p_put (void *cls, | |||
1786 | GNUNET_break_op (0); | 1784 | GNUNET_break_op (0); |
1787 | return; | 1785 | return; |
1788 | } | 1786 | } |
1789 | if (0 == (options & GNUNET_DHT_RO_RECORD_ROUTE)) | 1787 | if (0 == (bd.ro & GNUNET_DHT_RO_RECORD_ROUTE)) |
1790 | putlen = 0; | 1788 | putlen = 0; |
1791 | GNUNET_STATISTICS_update (GDS_stats, | 1789 | GNUNET_STATISTICS_update (GDS_stats, |
1792 | "# P2P PUT requests received", | 1790 | "# P2P PUT requests received", |
@@ -1837,7 +1835,7 @@ handle_dht_p2p_put (void *cls, | |||
1837 | /* extend 'put path' by sender */ | 1835 | /* extend 'put path' by sender */ |
1838 | bd.put_path = (const struct GNUNET_DHT_PathElement *) pp; | 1836 | bd.put_path = (const struct GNUNET_DHT_PathElement *) pp; |
1839 | bd.put_path_length = putlen + 1; | 1837 | bd.put_path_length = putlen + 1; |
1840 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) | 1838 | if (0 != (bd.ro & GNUNET_DHT_RO_RECORD_ROUTE)) |
1841 | { | 1839 | { |
1842 | unsigned int failure_offset; | 1840 | unsigned int failure_offset; |
1843 | 1841 | ||
@@ -1884,7 +1882,7 @@ handle_dht_p2p_put (void *cls, | |||
1884 | 0, NULL /* get path */)); | 1882 | 0, NULL /* get path */)); |
1885 | 1883 | ||
1886 | /* store locally */ | 1884 | /* store locally */ |
1887 | if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || | 1885 | if ( (0 != (bd.ro & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || |
1888 | (GDS_am_closest_peer (&put->key, | 1886 | (GDS_am_closest_peer (&put->key, |
1889 | bf)) ) | 1887 | bf)) ) |
1890 | GDS_DATACACHE_handle_put (&bd); | 1888 | GDS_DATACACHE_handle_put (&bd); |
@@ -1894,16 +1892,14 @@ handle_dht_p2p_put (void *cls, | |||
1894 | /* route to other peers */ | 1892 | /* route to other peers */ |
1895 | forwarded | 1893 | forwarded |
1896 | = GDS_NEIGHBOURS_handle_put (&bd, | 1894 | = GDS_NEIGHBOURS_handle_put (&bd, |
1897 | options, | ||
1898 | ntohs (put->desired_replication_level), | 1895 | ntohs (put->desired_replication_level), |
1899 | ntohs (put->hop_count), | 1896 | ntohs (put->hop_count), |
1900 | bf); | 1897 | bf); |
1901 | /* notify monitoring clients */ | 1898 | /* notify monitoring clients */ |
1902 | GDS_CLIENTS_process_put (options | 1899 | bd.ro |= ((GNUNET_OK == forwarded) |
1903 | | ((GNUNET_OK == forwarded) | 1900 | ? GNUNET_DHT_RO_LAST_HOP |
1904 | ? GNUNET_DHT_RO_LAST_HOP | 1901 | : 0); |
1905 | : 0), | 1902 | GDS_CLIENTS_process_put (&bd, |
1906 | &bd, | ||
1907 | ntohs (put->hop_count), | 1903 | ntohs (put->hop_count), |
1908 | ntohs (put->desired_replication_level)); | 1904 | ntohs (put->desired_replication_level)); |
1909 | } | 1905 | } |
@@ -1957,7 +1953,7 @@ handle_find_my_hello (struct PeerInfo *pi, | |||
1957 | block, | 1953 | block, |
1958 | block_size)) | 1954 | block_size)) |
1959 | { | 1955 | { |
1960 | struct GDS_DATACACHE_BlockData bd = { | 1956 | struct GNUNET_DATACACHE_Block bd = { |
1961 | .type = GNUNET_BLOCK_TYPE_DHT_URL_HELLO, | 1957 | .type = GNUNET_BLOCK_TYPE_DHT_URL_HELLO, |
1962 | .expiration_time | 1958 | .expiration_time |
1963 | = GNUNET_TIME_relative_to_absolute ( | 1959 | = GNUNET_TIME_relative_to_absolute ( |
@@ -2014,7 +2010,7 @@ handle_find_local_hello (struct PeerInfo *pi, | |||
2014 | peer->hello, | 2010 | peer->hello, |
2015 | peer->hello_size)) ) | 2011 | peer->hello_size)) ) |
2016 | { | 2012 | { |
2017 | struct GDS_DATACACHE_BlockData bd = { | 2013 | struct GNUNET_DATACACHE_Block bd = { |
2018 | .type = GNUNET_BLOCK_TYPE_DHT_URL_HELLO, | 2014 | .type = GNUNET_BLOCK_TYPE_DHT_URL_HELLO, |
2019 | .expiration_time = peer->hello_expiration, | 2015 | .expiration_time = peer->hello_expiration, |
2020 | .key = peer->phash, | 2016 | .key = peer->phash, |
@@ -2038,7 +2034,7 @@ handle_find_local_hello (struct PeerInfo *pi, | |||
2038 | */ | 2034 | */ |
2039 | static void | 2035 | static void |
2040 | handle_local_result (void *cls, | 2036 | handle_local_result (void *cls, |
2041 | const struct GDS_DATACACHE_BlockData *bd) | 2037 | const struct GNUNET_DATACACHE_Block *bd) |
2042 | { | 2038 | { |
2043 | struct PeerInfo *peer = cls; | 2039 | struct PeerInfo *peer = cls; |
2044 | 2040 | ||
@@ -2242,7 +2238,7 @@ handle_dht_p2p_get (void *cls, | |||
2242 | * @return true on success | 2238 | * @return true on success |
2243 | */ | 2239 | */ |
2244 | static bool | 2240 | static bool |
2245 | process_reply_with_path (const struct GDS_DATACACHE_BlockData *bd, | 2241 | process_reply_with_path (const struct GNUNET_DATACACHE_Block *bd, |
2246 | const struct GNUNET_HashCode *query_hash, | 2242 | const struct GNUNET_HashCode *query_hash, |
2247 | unsigned int get_path_length, | 2243 | unsigned int get_path_length, |
2248 | const struct GNUNET_DHT_PathElement *get_path) | 2244 | const struct GNUNET_DHT_PathElement *get_path) |
@@ -2265,7 +2261,7 @@ process_reply_with_path (const struct GDS_DATACACHE_BlockData *bd, | |||
2265 | { | 2261 | { |
2266 | struct GNUNET_DHT_PathElement xput_path[GNUNET_NZL (get_path_length | 2262 | struct GNUNET_DHT_PathElement xput_path[GNUNET_NZL (get_path_length |
2267 | + bd->put_path_length)]; | 2263 | + bd->put_path_length)]; |
2268 | struct GDS_DATACACHE_BlockData bdx = *bd; | 2264 | struct GNUNET_DATACACHE_Block bdx = *bd; |
2269 | 2265 | ||
2270 | GNUNET_memcpy (xput_path, | 2266 | GNUNET_memcpy (xput_path, |
2271 | bd->put_path, | 2267 | bd->put_path, |
@@ -2332,7 +2328,7 @@ handle_dht_p2p_result (void *cls, | |||
2332 | struct PeerInfo *peer = t->pi; | 2328 | struct PeerInfo *peer = t->pi; |
2333 | uint16_t msize = ntohs (prm->header.size); | 2329 | uint16_t msize = ntohs (prm->header.size); |
2334 | uint16_t get_path_length = ntohs (prm->get_path_length); | 2330 | uint16_t get_path_length = ntohs (prm->get_path_length); |
2335 | struct GDS_DATACACHE_BlockData bd = { | 2331 | struct GNUNET_DATACACHE_Block bd = { |
2336 | .expiration_time = GNUNET_TIME_absolute_ntoh (prm->expiration_time), | 2332 | .expiration_time = GNUNET_TIME_absolute_ntoh (prm->expiration_time), |
2337 | .put_path = (const struct GNUNET_DHT_PathElement *) &prm[1], | 2333 | .put_path = (const struct GNUNET_DHT_PathElement *) &prm[1], |
2338 | .put_path_length = ntohs (prm->put_path_length), | 2334 | .put_path_length = ntohs (prm->put_path_length), |