diff options
Diffstat (limited to 'src/dht/dht_api.c')
-rw-r--r-- | src/dht/dht_api.c | 159 |
1 files changed, 119 insertions, 40 deletions
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index d60653dd4..a16db6d4b 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c | |||
@@ -561,9 +561,10 @@ handle_monitor_get (void *cls, | |||
561 | const struct GNUNET_DHT_MonitorGetMessage *msg) | 561 | const struct GNUNET_DHT_MonitorGetMessage *msg) |
562 | { | 562 | { |
563 | struct GNUNET_DHT_Handle *handle = cls; | 563 | struct GNUNET_DHT_Handle *handle = cls; |
564 | struct GNUNET_DHT_MonitorHandle *mh; | ||
565 | 564 | ||
566 | for (mh = handle->monitor_head; NULL != mh; mh = mh->next) | 565 | for (struct GNUNET_DHT_MonitorHandle *mh = handle->monitor_head; |
566 | NULL != mh; | ||
567 | mh = mh->next) | ||
567 | { | 568 | { |
568 | if (NULL == mh->get_cb) | 569 | if (NULL == mh->get_cb) |
569 | continue; | 570 | continue; |
@@ -626,10 +627,12 @@ handle_monitor_get_resp (void *cls, | |||
626 | const struct GNUNET_DHT_PathElement *path; | 627 | const struct GNUNET_DHT_PathElement *path; |
627 | uint32_t getl = ntohl (msg->get_path_length); | 628 | uint32_t getl = ntohl (msg->get_path_length); |
628 | uint32_t putl = ntohl (msg->put_path_length); | 629 | uint32_t putl = ntohl (msg->put_path_length); |
629 | struct GNUNET_DHT_MonitorHandle *mh; | 630 | |
630 | 631 | ||
631 | path = (const struct GNUNET_DHT_PathElement *) &msg[1]; | 632 | path = (const struct GNUNET_DHT_PathElement *) &msg[1]; |
632 | for (mh = handle->monitor_head; NULL != mh; mh = mh->next) | 633 | for (struct GNUNET_DHT_MonitorHandle *mh = handle->monitor_head; |
634 | NULL != mh; | ||
635 | mh = mh->next) | ||
633 | { | 636 | { |
634 | if (NULL == mh->get_resp_cb) | 637 | if (NULL == mh->get_resp_cb) |
635 | continue; | 638 | continue; |
@@ -641,9 +644,9 @@ handle_monitor_get_resp (void *cls, | |||
641 | sizeof(struct GNUNET_HashCode))))) | 644 | sizeof(struct GNUNET_HashCode))))) |
642 | mh->get_resp_cb (mh->cb_cls, | 645 | mh->get_resp_cb (mh->cb_cls, |
643 | (enum GNUNET_BLOCK_Type) ntohl (msg->type), | 646 | (enum GNUNET_BLOCK_Type) ntohl (msg->type), |
644 | path, | 647 | &path[putl], |
645 | getl, | 648 | getl, |
646 | &path[getl], | 649 | path, |
647 | putl, | 650 | putl, |
648 | GNUNET_TIME_absolute_ntoh (msg->expiration_time), | 651 | GNUNET_TIME_absolute_ntoh (msg->expiration_time), |
649 | &msg->key, | 652 | &msg->key, |
@@ -773,12 +776,18 @@ process_client_result (void *cls, | |||
773 | uint16_t type = ntohl (crm->type); | 776 | uint16_t type = ntohl (crm->type); |
774 | uint32_t put_path_length = ntohl (crm->put_path_length); | 777 | uint32_t put_path_length = ntohl (crm->put_path_length); |
775 | uint32_t get_path_length = ntohl (crm->get_path_length); | 778 | uint32_t get_path_length = ntohl (crm->get_path_length); |
776 | const struct GNUNET_DHT_PathElement *put_path; | 779 | const struct GNUNET_DHT_PathElement *put_path |
777 | const struct GNUNET_DHT_PathElement *get_path; | 780 | = (const struct GNUNET_DHT_PathElement *) &crm[1]; |
781 | const struct GNUNET_DHT_PathElement *get_path | ||
782 | = &put_path[put_path_length]; | ||
783 | const void *data | ||
784 | = &get_path[get_path_length]; | ||
785 | size_t meta_length | ||
786 | = sizeof(struct GNUNET_DHT_PathElement) * (get_path_length | ||
787 | + put_path_length); | ||
788 | size_t data_length | ||
789 | = msize - meta_length; | ||
778 | struct GNUNET_HashCode hc; | 790 | struct GNUNET_HashCode hc; |
779 | size_t data_length; | ||
780 | size_t meta_length; | ||
781 | const void *data; | ||
782 | 791 | ||
783 | if (crm->unique_id != get_handle->unique_id) | 792 | if (crm->unique_id != get_handle->unique_id) |
784 | { | 793 | { |
@@ -797,11 +806,7 @@ process_client_result (void *cls, | |||
797 | GNUNET_break (0); | 806 | GNUNET_break (0); |
798 | return GNUNET_YES; | 807 | return GNUNET_YES; |
799 | } | 808 | } |
800 | meta_length = | 809 | |
801 | sizeof(struct GNUNET_DHT_PathElement) * (get_path_length + put_path_length); | ||
802 | data_length = msize - meta_length; | ||
803 | put_path = (const struct GNUNET_DHT_PathElement *) &crm[1]; | ||
804 | get_path = &put_path[put_path_length]; | ||
805 | { | 810 | { |
806 | char *pp; | 811 | char *pp; |
807 | char *gp; | 812 | char *gp; |
@@ -819,7 +824,6 @@ process_client_result (void *cls, | |||
819 | GNUNET_free (gp); | 824 | GNUNET_free (gp); |
820 | GNUNET_free (pp); | 825 | GNUNET_free (pp); |
821 | } | 826 | } |
822 | data = &get_path[get_path_length]; | ||
823 | /* remember that we've seen this result */ | 827 | /* remember that we've seen this result */ |
824 | GNUNET_CRYPTO_hash (data, | 828 | GNUNET_CRYPTO_hash (data, |
825 | data_length, | 829 | data_length, |
@@ -1296,7 +1300,7 @@ GNUNET_DHT_pp2s (const struct GNUNET_DHT_PathElement *path, | |||
1296 | 1300 | ||
1297 | 1301 | ||
1298 | unsigned int | 1302 | unsigned int |
1299 | GNUNET_DHT_verify_path (const struct GNUNET_HashCode *key, | 1303 | GNUNET_DHT_verify_path (const struct GNUNET_HashCode *query_hash, |
1300 | const void *data, | 1304 | const void *data, |
1301 | size_t data_size, | 1305 | size_t data_size, |
1302 | struct GNUNET_TIME_Absolute exp_time, | 1306 | struct GNUNET_TIME_Absolute exp_time, |
@@ -1306,50 +1310,125 @@ GNUNET_DHT_verify_path (const struct GNUNET_HashCode *key, | |||
1306 | unsigned int get_path_len, | 1310 | unsigned int get_path_len, |
1307 | const struct GNUNET_PeerIdentity *me) | 1311 | const struct GNUNET_PeerIdentity *me) |
1308 | { | 1312 | { |
1309 | struct GNUNET_DHT_HopSignature hs = { | 1313 | struct GNUNET_DHT_PutHopSignature phs = { |
1310 | .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DHT_HOP), | 1314 | .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DHT_PUT_HOP), |
1311 | .purpose.size = htonl (sizeof (hs)), | 1315 | .purpose.size = htonl (sizeof (phs)), |
1316 | .expiration_time = GNUNET_TIME_absolute_hton (exp_time) | ||
1317 | }; | ||
1318 | struct GNUNET_DHT_ResultHopSignature ghs = { | ||
1319 | .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DHT_RESULT_HOP), | ||
1320 | .purpose.size = htonl (sizeof (ghs)), | ||
1312 | .expiration_time = GNUNET_TIME_absolute_hton (exp_time), | 1321 | .expiration_time = GNUNET_TIME_absolute_hton (exp_time), |
1313 | .key = *key, | ||
1314 | }; | 1322 | }; |
1323 | const struct GNUNET_PeerIdentity *pred; | ||
1324 | const struct GNUNET_PeerIdentity *succ; | ||
1315 | unsigned int i; | 1325 | unsigned int i; |
1316 | 1326 | ||
1317 | if (0 == get_path_len + put_path_len) | 1327 | if (0 == get_path_len + put_path_len) |
1318 | return 0; | 1328 | return 0; |
1329 | if (0 != get_path_len) | ||
1330 | { | ||
1331 | GNUNET_assert (NULL != query_hash); | ||
1332 | ghs.query_hash = *query_hash; | ||
1333 | } | ||
1319 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1334 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1320 | "%s is verifying signatures for %s with GPL: %u PPL: %u!\n", | 1335 | "%s is verifying signatures for %s with GPL: %u PPL: %u!\n", |
1321 | GNUNET_i2s (me), | 1336 | GNUNET_i2s (me), |
1322 | GNUNET_h2s (key), | 1337 | NULL != query_hash ? GNUNET_h2s (query_hash) : "<null>", |
1323 | get_path_len, | 1338 | get_path_len, |
1324 | put_path_len); | 1339 | put_path_len); |
1340 | for (unsigned int j = 0; j<put_path_len; j++) | ||
1341 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1342 | "PP%u=%s\n", | ||
1343 | j, | ||
1344 | GNUNET_i2s (&put_path[j].pred)); | ||
1345 | for (unsigned int j = 0; j<get_path_len; j++) | ||
1346 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1347 | "GP%u=%s\n", | ||
1348 | j, | ||
1349 | GNUNET_i2s (&get_path[j].pred)); | ||
1350 | |||
1325 | i = put_path_len + get_path_len - 1; | 1351 | i = put_path_len + get_path_len - 1; |
1326 | GNUNET_CRYPTO_hash (data, | 1352 | GNUNET_CRYPTO_hash (data, |
1327 | data_size, | 1353 | data_size, |
1328 | &hs.h_data); | 1354 | &phs.h_data); |
1355 | ghs.h_data = phs.h_data; | ||
1329 | while (i > 0) | 1356 | while (i > 0) |
1330 | { | 1357 | { |
1331 | hs.pred = (i - 1 >= put_path_len) | 1358 | pred = (i - 1 >= put_path_len) |
1332 | ? get_path[i - put_path_len - 1].pred | 1359 | ? &get_path[i - put_path_len - 1].pred |
1333 | : put_path[i - 1].pred; | 1360 | : &put_path[i - 1].pred; |
1334 | if (i + 1 == get_path_len + put_path_len) | 1361 | if (i + 1 == get_path_len + put_path_len) |
1335 | hs.succ = *me; | 1362 | succ = me; |
1336 | else | 1363 | else |
1337 | hs.succ = (i + 1 >= put_path_len) | 1364 | succ = (i + 1 >= put_path_len) |
1338 | ? get_path[i + 1 - put_path_len].pred | 1365 | ? &get_path[i + 1 - put_path_len].pred |
1339 | : put_path[i + 1].pred; | 1366 | : &put_path[i + 1].pred; |
1340 | if (GNUNET_OK != | 1367 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1341 | GNUNET_CRYPTO_eddsa_verify ( | 1368 | "PRED: %s\n", |
1342 | GNUNET_SIGNATURE_PURPOSE_DHT_HOP, | 1369 | GNUNET_i2s (pred)); |
1343 | &hs, | 1370 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1344 | (i - 1 >= put_path_len) | 1371 | "SUCC: %s\n", |
1345 | ? &get_path[i - put_path_len - 1].sig | 1372 | GNUNET_i2s (succ)); |
1373 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1374 | "SIGNER: %s\n", | ||
1375 | GNUNET_i2s ((i >= put_path_len) | ||
1376 | ? &get_path[i - put_path_len].pred | ||
1377 | : &put_path[i].pred)); | ||
1378 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1379 | "SIG: %s\n", | ||
1380 | GNUNET_B2S ((i - 1 >= put_path_len) | ||
1381 | ? &get_path[i - put_path_len - 1].sig | ||
1382 | : &put_path[i - 1].sig)); | ||
1383 | if ( (i + 1 >= put_path_len) && | ||
1384 | (0 != get_path_len) ) | ||
1385 | { | ||
1386 | /* NOTE: the last signature inside the 'PUT' | ||
1387 | path is from the cross-over point and already | ||
1388 | of type RESULT_HOP, but only if we have | ||
1389 | a non-empty 'GET' path! */ | ||
1390 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1391 | "Key: %s offset %u\n", | ||
1392 | GNUNET_h2s (query_hash), | ||
1393 | i); | ||
1394 | ghs.pred = *pred; | ||
1395 | ghs.succ = *succ; | ||
1396 | if (GNUNET_OK != | ||
1397 | GNUNET_CRYPTO_eddsa_verify ( | ||
1398 | GNUNET_SIGNATURE_PURPOSE_DHT_RESULT_HOP, | ||
1399 | &ghs, | ||
1400 | (i - 1 >= put_path_len) | ||
1401 | ? &get_path[i - put_path_len - 1].sig | ||
1346 | : &put_path[i - 1].sig, | 1402 | : &put_path[i - 1].sig, |
1347 | (i >= put_path_len) | 1403 | (i >= put_path_len) |
1348 | ? &get_path[i - put_path_len].pred.public_key | 1404 | ? &get_path[i - put_path_len].pred.public_key |
1349 | : &put_path[i].pred.public_key)) | 1405 | : &put_path[i].pred.public_key)) |
1406 | { | ||
1407 | GNUNET_break_op (0); | ||
1408 | return i; | ||
1409 | } | ||
1410 | } | ||
1411 | else | ||
1350 | { | 1412 | { |
1351 | GNUNET_break_op (0); | 1413 | phs.pred = *pred; |
1352 | return i; | 1414 | phs.succ = *succ; |
1415 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1416 | "offset %u\n", | ||
1417 | i); | ||
1418 | if (GNUNET_OK != | ||
1419 | GNUNET_CRYPTO_eddsa_verify ( | ||
1420 | GNUNET_SIGNATURE_PURPOSE_DHT_PUT_HOP, | ||
1421 | &phs, | ||
1422 | (i - 1 >= put_path_len) | ||
1423 | ? &get_path[i - put_path_len - 1].sig | ||
1424 | : &put_path[i - 1].sig, | ||
1425 | (i >= put_path_len) | ||
1426 | ? &get_path[i - put_path_len].pred.public_key | ||
1427 | : &put_path[i].pred.public_key)) | ||
1428 | { | ||
1429 | GNUNET_break_op (0); | ||
1430 | return i; | ||
1431 | } | ||
1353 | } | 1432 | } |
1354 | i--; | 1433 | i--; |
1355 | } | 1434 | } |