aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-02-25 00:46:09 +0100
committerMartin Schanzenbach <mschanzenbach@posteo.de>2022-02-25 08:48:59 +0100
commit5e4cbb92beb575ad5b072334b42d66feb0f0c331 (patch)
treea1f7e1ae5f77e09e94329ba1cbe6ebb3fc0ba690
parent86e73d58ffc79ea706a5bc83867de3def4eaba48 (diff)
downloadgnunet-5e4cbb92beb575ad5b072334b42d66feb0f0c331.tar.gz
gnunet-5e4cbb92beb575ad5b072334b42d66feb0f0c331.zip
add GNUNET_B2S() macro; fix dht_line_test: we sign over query_hash, not block key
-rw-r--r--src/dht/dht_api.c7
-rw-r--r--src/dht/gnunet-service-dht_clients.c31
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c91
-rw-r--r--src/dht/gnunet-service-dht_routing.c3
-rw-r--r--src/dht/test_dht_topo.c1
-rw-r--r--src/include/gnunet_common.h27
-rw-r--r--src/util/common_logging.c25
7 files changed, 168 insertions, 17 deletions
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index cae8de726..d60653dd4 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -1317,7 +1317,9 @@ GNUNET_DHT_verify_path (const struct GNUNET_HashCode *key,
1317 if (0 == get_path_len + put_path_len) 1317 if (0 == get_path_len + put_path_len)
1318 return 0; 1318 return 0;
1319 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1319 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1320 "Verifying signatures with GPL: %u PPL: %u!\n", 1320 "%s is verifying signatures for %s with GPL: %u PPL: %u!\n",
1321 GNUNET_i2s (me),
1322 GNUNET_h2s (key),
1321 get_path_len, 1323 get_path_len,
1322 put_path_len); 1324 put_path_len);
1323 i = put_path_len + get_path_len - 1; 1325 i = put_path_len + get_path_len - 1;
@@ -1345,7 +1347,10 @@ GNUNET_DHT_verify_path (const struct GNUNET_HashCode *key,
1345 (i >= put_path_len) 1347 (i >= put_path_len)
1346 ? &get_path[i - put_path_len].pred.public_key 1348 ? &get_path[i - put_path_len].pred.public_key
1347 : &put_path[i].pred.public_key)) 1349 : &put_path[i].pred.public_key))
1350 {
1351 GNUNET_break_op (0);
1348 return i; 1352 return i;
1353 }
1349 i--; 1354 i--;
1350 } 1355 }
1351 return i; 1356 return i;
diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c
index db075509f..049e3d1f1 100644
--- a/src/dht/gnunet-service-dht_clients.c
+++ b/src/dht/gnunet-service-dht_clients.c
@@ -24,7 +24,6 @@
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 * @author Nathan Evans 25 * @author Nathan Evans
26 */ 26 */
27
28#include "platform.h" 27#include "platform.h"
29#include "gnunet_constants.h" 28#include "gnunet_constants.h"
30#include "gnunet_protocols.h" 29#include "gnunet_protocols.h"
@@ -36,6 +35,11 @@
36 35
37 36
38/** 37/**
38 * Enable slow sanity checks to debug issues.
39 */
40#define SANITY_CHECKS 1
41
42/**
39 * Should routing details be logged to stderr (for debugging)? 43 * Should routing details be logged to stderr (for debugging)?
40 */ 44 */
41#define LOG_TRAFFIC(kind, ...) GNUNET_log_from (kind, "dht-traffic", \ 45#define LOG_TRAFFIC(kind, ...) GNUNET_log_from (kind, "dht-traffic", \
@@ -1006,7 +1010,8 @@ forward_reply (void *cls,
1006 * frc->bd->put_path_length); 1010 * frc->bd->put_path_length);
1007 GNUNET_memcpy (&paths[frc->bd->put_path_length], 1011 GNUNET_memcpy (&paths[frc->bd->put_path_length],
1008 frc->get_path, 1012 frc->get_path,
1009 sizeof(struct GNUNET_DHT_PathElement) * frc->get_path_length); 1013 sizeof(struct GNUNET_DHT_PathElement)
1014 * frc->get_path_length);
1010 GNUNET_memcpy (&paths[frc->get_path_length + frc->bd->put_path_length], 1015 GNUNET_memcpy (&paths[frc->get_path_length + frc->bd->put_path_length],
1011 frc->bd->data, 1016 frc->bd->data,
1012 frc->bd->data_size); 1017 frc->bd->data_size);
@@ -1039,12 +1044,30 @@ GDS_CLIENTS_handle_reply (const struct GDS_DATACACHE_BlockData *bd,
1039 GNUNET_break (0); 1044 GNUNET_break (0);
1040 return; 1045 return;
1041 } 1046 }
1047#if SANITY_CHECKS
1048 if (0 !=
1049 GNUNET_DHT_verify_path (&bd->key,
1050 bd->data,
1051 bd->data_size,
1052 bd->expiration_time,
1053 get_path,
1054 get_path_length,
1055 bd->put_path,
1056 bd->put_path_length,
1057 &GDS_my_identity))
1058 {
1059 GNUNET_break_op (0);
1060 return;
1061 }
1062#endif
1042 frc.bd = bd; 1063 frc.bd = bd;
1043 frc.get_path = get_path; 1064 frc.get_path = get_path;
1044 frc.get_path_length = get_path_length; 1065 frc.get_path_length = get_path_length;
1045 LOG (GNUNET_ERROR_TYPE_DEBUG, 1066 LOG (GNUNET_ERROR_TYPE_DEBUG,
1046 "Forwarding reply for query hash %s to client\n", 1067 "Forwarding reply for query hash %s with GPL %u and PPL %u to client\n",
1047 GNUNET_h2s (query_hash)); 1068 GNUNET_h2s (query_hash),
1069 get_path_length,
1070 bd->put_path_length);
1048 if (0 == 1071 if (0 ==
1049 GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, 1072 GNUNET_CONTAINER_multihashmap_get_multiple (forward_map,
1050 query_hash, 1073 query_hash,
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 2e25b4d1e..284380647 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -1400,6 +1400,10 @@ GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd,
1400 &pp[put_path_length - 1].pred, 1400 &pp[put_path_length - 1].pred,
1401 &target->id, 1401 &target->id,
1402 &pp[put_path_length - 1].sig); 1402 &pp[put_path_length - 1].sig);
1403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1404 "Signing PUT PATH %u => %s\n",
1405 put_path_length,
1406 GNUNET_B2S (&pp[put_path_length - 1].sig));
1403 } 1407 }
1404 1408
1405 GNUNET_memcpy (&pp[put_path_length], 1409 GNUNET_memcpy (&pp[put_path_length],
@@ -1594,7 +1598,7 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi,
1594 GNUNET_break (0); 1598 GNUNET_break (0);
1595 return; 1599 return;
1596 } 1600 }
1597 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1601 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1598 "Forwarding reply for key %s to peer %s\n", 1602 "Forwarding reply for key %s to peer %s\n",
1599 GNUNET_h2s (query_hash), 1603 GNUNET_h2s (query_hash),
1600 GNUNET_i2s (&pi->id)); 1604 GNUNET_i2s (&pi->id));
@@ -1636,22 +1640,55 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi,
1636 { 1640 {
1637 GNUNET_assert (0 == get_path_length); 1641 GNUNET_assert (0 == get_path_length);
1638 } 1642 }
1639 /* 0 == get_path_length means path is not being tracked */ 1643 /* 0 == get_path_length+ppl means path is not being tracked */
1640 if (0 != get_path_length) 1644 if (0 != (get_path_length + ppl))
1641 { 1645 {
1642 /* Note that the signature in 'get_path' was not initialized before, 1646 /* Note that the last signature in 'paths' was not initialized before,
1643 so this is crucial to avoid sending garbage. */ 1647 so this is crucial to avoid sending garbage. */
1644 sign_path (&bd->key, 1648 sign_path (query_hash,
1645 bd->data, 1649 bd->data,
1646 bd->data_size, 1650 bd->data_size,
1647 bd->expiration_time, 1651 bd->expiration_time,
1648 &paths[ppl + get_path_length - 1].pred, 1652 &paths[ppl + get_path_length - 1].pred,
1649 &pi->id, 1653 &pi->id,
1650 &paths[ppl + get_path_length - 1].sig); 1654 &paths[ppl + get_path_length - 1].sig);
1655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1656 "Signing GET PATH %u/%u of %s => %s\n",
1657 ppl,
1658 get_path_length,
1659 GNUNET_h2s (query_hash),
1660 GNUNET_B2S (&paths[ppl + get_path_length - 1].sig));
1651 } 1661 }
1652 GNUNET_memcpy (&paths[ppl + get_path_length], 1662 GNUNET_memcpy (&paths[ppl + get_path_length],
1653 bd->data, 1663 bd->data,
1654 bd->data_size); 1664 bd->data_size);
1665
1666#if SANITY_CHECKS
1667 {
1668 struct GNUNET_DHT_PathElement xpaths[get_path_length + 1];
1669
1670 memcpy (xpaths,
1671 &paths[ppl],
1672 get_path_length * sizeof (struct GNUNET_DHT_PathElement));
1673 xpaths[get_path_length].pred = GDS_my_identity;
1674 if (0 !=
1675 GNUNET_DHT_verify_path (&prm->key,
1676 bd->data,
1677 bd->data_size,
1678 bd->expiration_time,
1679 paths,
1680 ppl,
1681 xpaths,
1682 get_path_length + 1,
1683 &pi->id))
1684 {
1685 GNUNET_break (0);
1686 return;
1687 }
1688 }
1689#endif
1690
1691
1655 do_send (pi, 1692 do_send (pi,
1656 &prm->header); 1693 &prm->header);
1657 } 1694 }
@@ -2201,6 +2238,8 @@ process_reply_with_path (const struct GDS_DATACACHE_BlockData *bd,
2201 const struct GNUNET_DHT_PathElement *get_path) 2238 const struct GNUNET_DHT_PathElement *get_path)
2202{ 2239{
2203 /* forward to local clients */ 2240 /* forward to local clients */
2241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2242 "Forwarding reply to local clients\n");
2204 GDS_CLIENTS_handle_reply (bd, 2243 GDS_CLIENTS_handle_reply (bd,
2205 query_hash, 2244 query_hash,
2206 get_path_length, 2245 get_path_length,
@@ -2246,6 +2285,10 @@ check_dht_p2p_result (void *cls,
2246 uint16_t get_path_length = ntohs (prm->get_path_length); 2285 uint16_t get_path_length = ntohs (prm->get_path_length);
2247 uint16_t put_path_length = ntohs (prm->put_path_length); 2286 uint16_t put_path_length = ntohs (prm->put_path_length);
2248 uint16_t msize = ntohs (prm->header.size); 2287 uint16_t msize = ntohs (prm->header.size);
2288 const struct GNUNET_DHT_PathElement *pp
2289 = (const struct GNUNET_DHT_PathElement *) &prm[1];
2290 const struct GNUNET_DHT_PathElement *gp
2291 = &pp[put_path_length];
2249 2292
2250 (void) cls; 2293 (void) cls;
2251 if ( (msize < 2294 if ( (msize <
@@ -2260,6 +2303,26 @@ check_dht_p2p_result (void *cls,
2260 GNUNET_break_op (0); 2303 GNUNET_break_op (0);
2261 return GNUNET_SYSERR; 2304 return GNUNET_SYSERR;
2262 } 2305 }
2306
2307#if SANITY_CHECKS
2308 if (0 !=
2309 GNUNET_DHT_verify_path (&prm->key,
2310 &gp[get_path_length],
2311 msize - (sizeof(struct PeerResultMessage)
2312 + (get_path_length + put_path_length)
2313 * sizeof(struct GNUNET_DHT_PathElement)),
2314 GNUNET_TIME_absolute_ntoh (prm->expiration_time),
2315 pp,
2316 put_path_length,
2317 gp,
2318 get_path_length,
2319 &GDS_my_identity))
2320 {
2321 GNUNET_break_op (0);
2322 return GNUNET_SYSERR;
2323 }
2324#endif
2325
2263 return GNUNET_OK; 2326 return GNUNET_OK;
2264} 2327}
2265 2328
@@ -2412,13 +2475,18 @@ handle_dht_p2p_result (void *cls,
2412 2475
2413 /* First, check if 'peer' is already on the path, and if 2476 /* First, check if 'peer' is already on the path, and if
2414 so, truncate it instead of expanding. */ 2477 so, truncate it instead of expanding. */
2415 for (unsigned int i = 0; i <= get_path_length; i++) 2478 for (unsigned int i = 0; i < get_path_length; i++)
2416 if (0 == GNUNET_memcmp (&get_path[i].pred, 2479 if (0 == GNUNET_memcmp (&get_path[i].pred,
2417 &peer->id)) 2480 &peer->id))
2418 { 2481 {
2482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2483 "Truncating path at %u/%u\n",
2484 i,
2485 get_path_length);
2419 process_reply_with_path (&bd, 2486 process_reply_with_path (&bd,
2420 &prm->key, 2487 &prm->key,
2421 i, get_path); 2488 i,
2489 get_path);
2422 return; 2490 return;
2423 } 2491 }
2424 2492
@@ -2433,9 +2501,14 @@ handle_dht_p2p_result (void *cls,
2433 memset (&xget_path[get_path_length].sig, 2501 memset (&xget_path[get_path_length].sig,
2434 0, 2502 0,
2435 sizeof (xget_path[get_path_length].sig)); 2503 sizeof (xget_path[get_path_length].sig));
2504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2505 "Extending GET path of length %u with %s\n",
2506 get_path_length,
2507 GNUNET_i2s (&peer->id));
2436 process_reply_with_path (&bd, 2508 process_reply_with_path (&bd,
2437 &prm->key, 2509 &prm->key,
2438 get_path_length + 1, xget_path); 2510 get_path_length + 1,
2511 xget_path);
2439 } 2512 }
2440} 2513}
2441 2514
@@ -2540,7 +2613,7 @@ GDS_u_receive (void *cls,
2540 GNUNET_break_op (0); 2613 GNUNET_break_op (0);
2541 return; 2614 return;
2542 } 2615 }
2543 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2616 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2544 "Handling message of type %u from peer %s\n", 2617 "Handling message of type %u from peer %s\n",
2545 ntohs (mh->type), 2618 ntohs (mh->type),
2546 GNUNET_i2s (&t->pi->id)); 2619 GNUNET_i2s (&t->pi->id));
diff --git a/src/dht/gnunet-service-dht_routing.c b/src/dht/gnunet-service-dht_routing.c
index ec3f5b46f..c07b06c5e 100644
--- a/src/dht/gnunet-service-dht_routing.c
+++ b/src/dht/gnunet-service-dht_routing.c
@@ -198,7 +198,8 @@ process (void *cls,
198 GDS_NEIGHBOURS_handle_reply (pi, 198 GDS_NEIGHBOURS_handle_reply (pi,
199 &bdx, 199 &bdx,
200 query_hash, 200 query_hash,
201 get_path_length, pc->get_path); 201 get_path_length,
202 pc->get_path);
202 } 203 }
203 break; 204 break;
204 case GNUNET_BLOCK_REPLY_OK_DUPLICATE: 205 case GNUNET_BLOCK_REPLY_OK_DUPLICATE:
diff --git a/src/dht/test_dht_topo.c b/src/dht/test_dht_topo.c
index eb7e80d3b..30e7749ca 100644
--- a/src/dht/test_dht_topo.c
+++ b/src/dht/test_dht_topo.c
@@ -380,6 +380,7 @@ dht_get_handler (void *cls,
380 put_path_length, 380 put_path_length,
381 &get_op->me)) 381 &get_op->me))
382 { 382 {
383 GNUNET_break (0);
383 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 384 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
384 "Path signature verification failed!\n"); 385 "Path signature verification failed!\n");
385 } 386 }
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 4472d3ee8..9bcd99c7b 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -623,6 +623,31 @@ GNUNET_abort_ (void) GNUNET_NORETURN;
623 623
624 624
625/** 625/**
626 * Convert a buffer to an 8-character string
627 * representative of the contents. This is used
628 * for logging binary data when debugging.
629 *
630 * @param buf buffer to log
631 * @param buf_size number of bytes in @a buf
632 * @return text representation of buf, valid until next
633 * call to this function
634 */
635const char *
636GNUNET_b2s (const void *buf,
637 size_t buf_size);
638
639
640/**
641 * Convert a fixed-sized object to a string using
642 * #GNUNET_b2s().
643 *
644 * @param obj address of object to convert
645 * @return string representing the binary obj buffer
646 */
647#define GNUNET_B2S(obj) GNUNET_b2s ((obj), sizeof (*(obj)))
648
649
650/**
626 * @ingroup logging 651 * @ingroup logging
627 * Ignore the next @a n calls to the log function. 652 * Ignore the next @a n calls to the log function.
628 * 653 *
@@ -1240,7 +1265,7 @@ GNUNET_is_zero_ (const void *a,
1240 * @return GNUNET_YES if a is zero, GNUNET_NO otherwise 1265 * @return GNUNET_YES if a is zero, GNUNET_NO otherwise
1241 */ 1266 */
1242#define GNUNET_is_zero(a) \ 1267#define GNUNET_is_zero(a) \
1243 GNUNET_is_zero_ (a, sizeof (*a)) 1268 GNUNET_is_zero_ ((a), sizeof (*(a)))
1244 1269
1245 1270
1246/** 1271/**
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index cba37cd2f..b07f3fc0b 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -321,6 +321,28 @@ log_rotate (const char *new_name)
321} 321}
322 322
323 323
324const char *
325GNUNET_b2s (const void *buf,
326 size_t buf_size)
327{
328 static GNUNET_THREAD_LOCAL char ret[9];
329 struct GNUNET_HashCode hc;
330 char *tmp;
331
332 GNUNET_CRYPTO_hash (buf,
333 buf_size,
334 &hc);
335 tmp = GNUNET_STRINGS_data_to_string_alloc (&hc,
336 sizeof (hc));
337 memcpy (ret,
338 tmp,
339 8);
340 GNUNET_free (tmp);
341 ret[8] = '\0';
342 return ret;
343}
344
345
324/** 346/**
325 * Setup the log file. 347 * Setup the log file.
326 * 348 *
@@ -1015,7 +1037,8 @@ mylog (enum GNUNET_ErrorType kind,
1015 else 1037 else
1016 { 1038 {
1017 /* RFC 3339 timestamp, with snprintf placeholder for microseconds */ 1039 /* RFC 3339 timestamp, with snprintf placeholder for microseconds */
1018 if (0 == strftime (date2, DATE_STR_SIZE, "%Y-%m-%dT%H:%M:%S.%%06u%z", tmptr)) 1040 if (0 == strftime (date2, DATE_STR_SIZE, "%Y-%m-%dT%H:%M:%S.%%06u%z",
1041 tmptr))
1019 abort (); 1042 abort ();
1020 /* Fill in microseconds */ 1043 /* Fill in microseconds */
1021 if (0 > snprintf (date, sizeof(date), date2, timeofday.tv_usec)) 1044 if (0 > snprintf (date, sizeof(date), date2, timeofday.tv_usec))