diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-02-25 00:46:09 +0100 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2022-02-25 08:48:59 +0100 |
commit | 5e4cbb92beb575ad5b072334b42d66feb0f0c331 (patch) | |
tree | a1f7e1ae5f77e09e94329ba1cbe6ebb3fc0ba690 /src/dht/gnunet-service-dht_neighbours.c | |
parent | 86e73d58ffc79ea706a5bc83867de3def4eaba48 (diff) | |
download | gnunet-5e4cbb92beb575ad5b072334b42d66feb0f0c331.tar.gz gnunet-5e4cbb92beb575ad5b072334b42d66feb0f0c331.zip |
add GNUNET_B2S() macro; fix dht_line_test: we sign over query_hash, not block key
Diffstat (limited to 'src/dht/gnunet-service-dht_neighbours.c')
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 91 |
1 files changed, 82 insertions, 9 deletions
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)); |