aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht_neighbours.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-05-31 23:43:05 +0200
committerChristian Grothoff <christian@grothoff.org>2022-05-31 23:43:05 +0200
commitedddc9384e9bc4331d57291de7318bbe401e49b0 (patch)
treebe9387df3a4fa4e8cb71590501fb3740920c5bb6 /src/dht/gnunet-service-dht_neighbours.c
parent02a2c3560aa08c3c7f389706b0e24007e2010bc5 (diff)
downloadgnunet-edddc9384e9bc4331d57291de7318bbe401e49b0.tar.gz
gnunet-edddc9384e9bc4331d57291de7318bbe401e49b0.zip
protocol change: swap xquery and result filter, integrate mutator with result filter
Diffstat (limited to 'src/dht/gnunet-service-dht_neighbours.c')
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c96
1 files changed, 42 insertions, 54 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 2f9cbab84..9a3abc376 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -39,15 +39,15 @@
39 __VA_ARGS__) 39 __VA_ARGS__)
40 40
41/** 41/**
42 * Enable slow sanity checks to debug issues. 42 * Enable slow sanity checks to debug issues.
43 * 43 *
44 * TODO: might want to eventually implement probabilistic 44 * TODO: might want to eventually implement probabilistic
45 * load-based path verification, but for now it is all or nothing 45 * load-based path verification, but for now it is all or nothing
46 * based on this define. 46 * based on this define.
47 * 47 *
48 * 0: do not check -- if signatures become performance critical 48 * 0: do not check -- if signatures become performance critical
49 * 1: check all external inputs -- normal production for now 49 * 1: check all external inputs -- normal production for now
50 * 2: check internal computations as well -- for debugging 50 * 2: check internal computations as well -- for debugging
51 */ 51 */
52#define SANITY_CHECKS 2 52#define SANITY_CHECKS 2
53 53
@@ -235,9 +235,9 @@ struct PeerGetMessage
235 uint16_t desired_replication_level GNUNET_PACKED; 235 uint16_t desired_replication_level GNUNET_PACKED;
236 236
237 /** 237 /**
238 * Size of the extended query. 238 * Size of the result filter.
239 */ 239 */
240 uint16_t xquery_size; 240 uint16_t result_filter_size GNUNET_PACKED;
241 241
242 /** 242 /**
243 * Bloomfilter (for peer identities) to stop circular routes 243 * Bloomfilter (for peer identities) to stop circular routes
@@ -249,14 +249,10 @@ struct PeerGetMessage
249 */ 249 */
250 struct GNUNET_HashCode key; 250 struct GNUNET_HashCode key;
251 251
252 /** 252 /* result bloomfilter */
253 * Bloomfilter mutator.
254 */
255 uint32_t bf_mutator;
256 253
257 /* xquery */ 254 /* xquery */
258 255
259 /* result bloomfilter */
260}; 256};
261GNUNET_NETWORK_STRUCT_END 257GNUNET_NETWORK_STRUCT_END
262 258
@@ -654,9 +650,6 @@ send_find_peer_message (void *cls)
654 650
655 bg = GNUNET_BLOCK_group_create (GDS_block_context, 651 bg = GNUNET_BLOCK_group_create (GDS_block_context,
656 GNUNET_BLOCK_TYPE_DHT_URL_HELLO, 652 GNUNET_BLOCK_TYPE_DHT_URL_HELLO,
657 GNUNET_CRYPTO_random_u32 (
658 GNUNET_CRYPTO_QUALITY_WEAK,
659 UINT32_MAX),
660 NULL, 653 NULL,
661 0, 654 0,
662 "filter-size", 655 "filter-size",
@@ -1287,9 +1280,9 @@ get_target_peers (const struct GNUNET_HashCode *key,
1287 1280
1288 1281
1289/** 1282/**
1290 * If we got a HELLO, consider it for our own routing table 1283 * If we got a HELLO, consider it for our own routing table
1291 * 1284 *
1292 * @param bd block data we got 1285 * @param bd block data we got
1293 */ 1286 */
1294static void 1287static void
1295hello_check (const struct GDS_DATACACHE_BlockData *bd) 1288hello_check (const struct GDS_DATACACHE_BlockData *bd)
@@ -1345,7 +1338,7 @@ GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd,
1345 GNUNET_h2s (&bd->key), 1338 GNUNET_h2s (&bd->key),
1346 (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE) ? "x" : "-", 1339 (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE) ? "x" : "-",
1347 (options & GNUNET_DHT_RO_RECORD_ROUTE) ? "R" : "-"); 1340 (options & GNUNET_DHT_RO_RECORD_ROUTE) ? "R" : "-");
1348 1341
1349 /* if we got a HELLO, consider it for our own routing table */ 1342 /* if we got a HELLO, consider it for our own routing table */
1350 hello_check (bd); 1343 hello_check (bd);
1351 GNUNET_CONTAINER_bloomfilter_add (bf, 1344 GNUNET_CONTAINER_bloomfilter_add (bf,
@@ -1464,10 +1457,9 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1464 unsigned int target_count; 1457 unsigned int target_count;
1465 struct PeerInfo **targets; 1458 struct PeerInfo **targets;
1466 size_t msize; 1459 size_t msize;
1467 size_t reply_bf_size; 1460 size_t result_filter_size;
1468 void *reply_bf; 1461 void *result_filter;
1469 unsigned int skip_count; 1462 unsigned int skip_count;
1470 uint32_t bf_nonce;
1471 1463
1472 GNUNET_assert (NULL != peer_bf); 1464 GNUNET_assert (NULL != peer_bf);
1473 GNUNET_STATISTICS_update (GDS_stats, 1465 GNUNET_STATISTICS_update (GDS_stats,
@@ -1499,20 +1491,17 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1499 } 1491 }
1500 if (GNUNET_OK != 1492 if (GNUNET_OK !=
1501 GNUNET_BLOCK_group_serialize (bg, 1493 GNUNET_BLOCK_group_serialize (bg,
1502 &bf_nonce, 1494 &result_filter,
1503 &reply_bf, 1495 &result_filter_size))
1504 &reply_bf_size))
1505 { 1496 {
1506 reply_bf = NULL; 1497 result_filter = NULL;
1507 reply_bf_size = 0; 1498 result_filter_size = 0;
1508 bf_nonce = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1509 UINT32_MAX);
1510 } 1499 }
1511 msize = xquery_size + reply_bf_size; 1500 msize = xquery_size + result_filter_size;
1512 if (msize + sizeof(struct PeerGetMessage) >= GNUNET_MAX_MESSAGE_SIZE) 1501 if (msize + sizeof(struct PeerGetMessage) >= GNUNET_MAX_MESSAGE_SIZE)
1513 { 1502 {
1514 GNUNET_break (0); 1503 GNUNET_break (0);
1515 GNUNET_free (reply_bf); 1504 GNUNET_free (result_filter);
1516 GNUNET_free (targets); 1505 GNUNET_free (targets);
1517 return GNUNET_NO; 1506 return GNUNET_NO;
1518 } 1507 }
@@ -1523,7 +1512,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1523 struct PeerInfo *target = targets[i]; 1512 struct PeerInfo *target = targets[i];
1524 struct PeerGetMessage *pgm; 1513 struct PeerGetMessage *pgm;
1525 char buf[sizeof (*pgm) + msize] GNUNET_ALIGN; 1514 char buf[sizeof (*pgm) + msize] GNUNET_ALIGN;
1526 char *xq; 1515 char *rf;
1527 1516
1528 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1529 "Routing GET for %s after %u hops to %s\n", 1518 "Routing GET for %s after %u hops to %s\n",
@@ -1537,8 +1526,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1537 pgm->options = htons (options); 1526 pgm->options = htons (options);
1538 pgm->hop_count = htons (hop_count + 1); 1527 pgm->hop_count = htons (hop_count + 1);
1539 pgm->desired_replication_level = htons (desired_replication_level); 1528 pgm->desired_replication_level = htons (desired_replication_level);
1540 pgm->xquery_size = htonl (xquery_size); 1529 pgm->result_filter_size = htonl (result_filter_size);
1541 pgm->bf_mutator = bf_nonce;
1542 GNUNET_break (GNUNET_YES == 1530 GNUNET_break (GNUNET_YES ==
1543 GNUNET_CONTAINER_bloomfilter_test (peer_bf, 1531 GNUNET_CONTAINER_bloomfilter_test (peer_bf,
1544 &target->phash)); 1532 &target->phash));
@@ -1547,13 +1535,13 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1547 pgm->bloomfilter, 1535 pgm->bloomfilter,
1548 DHT_BLOOM_SIZE)); 1536 DHT_BLOOM_SIZE));
1549 pgm->key = *key; 1537 pgm->key = *key;
1550 xq = (char *) &pgm[1]; 1538 rf = (char *) &pgm[1];
1551 GNUNET_memcpy (xq, 1539 GNUNET_memcpy (rf,
1540 result_filter,
1541 result_filter_size);
1542 GNUNET_memcpy (&rf[result_filter_size],
1552 xquery, 1543 xquery,
1553 xquery_size); 1544 xquery_size);
1554 GNUNET_memcpy (&xq[xquery_size],
1555 reply_bf,
1556 reply_bf_size);
1557 do_send (target, 1545 do_send (target,
1558 &pgm->header); 1546 &pgm->header);
1559 } 1547 }
@@ -1562,7 +1550,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1562 target_count - skip_count, 1550 target_count - skip_count,
1563 GNUNET_NO); 1551 GNUNET_NO);
1564 GNUNET_free (targets); 1552 GNUNET_free (targets);
1565 GNUNET_free (reply_bf); 1553 GNUNET_free (result_filter);
1566 return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; 1554 return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
1567} 1555}
1568 1556
@@ -1852,7 +1840,7 @@ handle_dht_p2p_put (void *cls,
1852 if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) 1840 if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE))
1853 { 1841 {
1854 unsigned int failure_offset; 1842 unsigned int failure_offset;
1855 1843
1856 GNUNET_memcpy (pp, 1844 GNUNET_memcpy (pp,
1857 put_path, 1845 put_path,
1858 putlen * sizeof(struct GNUNET_DHT_PathElement)); 1846 putlen * sizeof(struct GNUNET_DHT_PathElement));
@@ -1861,10 +1849,10 @@ handle_dht_p2p_put (void *cls,
1861 memset (&pp[putlen].sig, 1849 memset (&pp[putlen].sig,
1862 0, 1850 0,
1863 sizeof (pp[putlen].sig)); 1851 sizeof (pp[putlen].sig));
1864#if SANITY_CHECKS 1852#if SANITY_CHECKS
1865 /* TODO: might want to eventually implement probabilistic 1853 /* TODO: might want to eventually implement probabilistic
1866 load-based path verification, but for now it is all or nothing */ 1854 load-based path verification, but for now it is all or nothing */
1867 failure_offset 1855 failure_offset
1868 = GNUNET_DHT_verify_path (bd.data, 1856 = GNUNET_DHT_verify_path (bd.data,
1869 bd.data_size, 1857 bd.data_size,
1870 bd.expiration_time, 1858 bd.expiration_time,
@@ -1883,7 +1871,7 @@ handle_dht_p2p_put (void *cls,
1883 GNUNET_assert (failure_offset <= putlen); 1871 GNUNET_assert (failure_offset <= putlen);
1884 bd.put_path = &pp[failure_offset]; 1872 bd.put_path = &pp[failure_offset];
1885 bd.put_path_length = putlen - failure_offset; 1873 bd.put_path_length = putlen - failure_offset;
1886 } 1874 }
1887 } 1875 }
1888 else 1876 else
1889 { 1877 {
@@ -2073,10 +2061,10 @@ check_dht_p2p_get (void *cls,
2073 const struct PeerGetMessage *get) 2061 const struct PeerGetMessage *get)
2074{ 2062{
2075 uint16_t msize = ntohs (get->header.size); 2063 uint16_t msize = ntohs (get->header.size);
2076 uint32_t xquery_size = ntohl (get->xquery_size); 2064 uint32_t result_filter_size = ntohl (get->result_filter_size);
2077 2065
2078 (void) cls; 2066 (void) cls;
2079 if (msize < sizeof(*get) + xquery_size) 2067 if (msize < sizeof(*get) + result_filter_size)
2080 { 2068 {
2081 GNUNET_break_op (0); 2069 GNUNET_break_op (0);
2082 return GNUNET_SYSERR; 2070 return GNUNET_SYSERR;
@@ -2098,14 +2086,15 @@ handle_dht_p2p_get (void *cls,
2098 struct Target *t = cls; 2086 struct Target *t = cls;
2099 struct PeerInfo *peer = t->pi; 2087 struct PeerInfo *peer = t->pi;
2100 uint16_t msize = ntohs (get->header.size); 2088 uint16_t msize = ntohs (get->header.size);
2101 uint32_t xquery_size = ntohl (get->xquery_size); 2089 uint32_t result_filter_size = ntohl (get->result_filter_size);
2102 uint32_t hop_count = ntohs (get->hop_count); 2090 uint32_t hop_count = ntohs (get->hop_count);
2103 size_t reply_bf_size = msize - (sizeof(*get) + xquery_size);
2104 enum GNUNET_BLOCK_Type type = (enum GNUNET_BLOCK_Type) ntohl (get->type); 2091 enum GNUNET_BLOCK_Type type = (enum GNUNET_BLOCK_Type) ntohl (get->type);
2105 enum GNUNET_DHT_RouteOption options = (enum GNUNET_DHT_RouteOption) ntohs ( 2092 enum GNUNET_DHT_RouteOption options = (enum GNUNET_DHT_RouteOption) ntohs (
2106 get->options); 2093 get->options);
2107 enum GNUNET_BLOCK_ReplyEvaluationResult eval = GNUNET_BLOCK_REPLY_OK_MORE; 2094 enum GNUNET_BLOCK_ReplyEvaluationResult eval = GNUNET_BLOCK_REPLY_OK_MORE;
2108 const void *xquery = (const void *) &get[1]; 2095 const void *result_filter = (const void *) &get[1];
2096 const void *xquery = result_filter + result_filter_size;
2097 size_t xquery_size = msize - sizeof (*get) - result_filter_size;
2109 2098
2110 /* parse and validate message */ 2099 /* parse and validate message */
2111 GNUNET_STATISTICS_update (GDS_stats, 2100 GNUNET_STATISTICS_update (GDS_stats,
@@ -2140,11 +2129,10 @@ handle_dht_p2p_get (void *cls,
2140 &peer->phash)); 2129 &peer->phash));
2141 bg = GNUNET_BLOCK_group_create (GDS_block_context, 2130 bg = GNUNET_BLOCK_group_create (GDS_block_context,
2142 type, 2131 type,
2143 get->bf_mutator, 2132 result_filter,
2144 xquery + xquery_size, 2133 result_filter_size,
2145 reply_bf_size,
2146 "filter-size", 2134 "filter-size",
2147 reply_bf_size, 2135 result_filter_size,
2148 NULL); 2136 NULL);
2149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2150 "GET for %s at %s after %u hops\n", 2138 "GET for %s at %s after %u hops\n",
@@ -2353,7 +2341,7 @@ handle_dht_p2p_result (void *cls,
2353 }; 2341 };
2354 const struct GNUNET_DHT_PathElement *get_path 2342 const struct GNUNET_DHT_PathElement *get_path
2355 = &bd.put_path[bd.put_path_length]; 2343 = &bd.put_path[bd.put_path_length];
2356 2344
2357 /* parse and validate message */ 2345 /* parse and validate message */
2358 if (GNUNET_TIME_absolute_is_past (bd.expiration_time)) 2346 if (GNUNET_TIME_absolute_is_past (bd.expiration_time))
2359 { 2347 {
@@ -2416,7 +2404,7 @@ handle_dht_p2p_result (void *cls,
2416#if SANITY_CHECKS 2404#if SANITY_CHECKS
2417 /* TODO: might want to eventually implement probabilistic 2405 /* TODO: might want to eventually implement probabilistic
2418 load-based path verification, but for now it is all or nothing */ 2406 load-based path verification, but for now it is all or nothing */
2419 failure_offset 2407 failure_offset
2420 = GNUNET_DHT_verify_path (bd.data, 2408 = GNUNET_DHT_verify_path (bd.data,
2421 bd.data_size, 2409 bd.data_size,
2422 bd.expiration_time, 2410 bd.expiration_time,