diff options
Diffstat (limited to 'src/dht/gnunet-service-dht_neighbours.c')
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 2602 |
1 files changed, 1315 insertions, 1287 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 90ef5429f..fe9dd3e9c 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -46,7 +46,8 @@ | |||
46 | #include "gnunet-service-dht_routing.h" | 46 | #include "gnunet-service-dht_routing.h" |
47 | #include "dht.h" | 47 | #include "dht.h" |
48 | 48 | ||
49 | #define LOG_TRAFFIC(kind, ...) GNUNET_log_from(kind, "dht-traffic", __VA_ARGS__) | 49 | #define LOG_TRAFFIC(kind, ...) GNUNET_log_from (kind, "dht-traffic", \ |
50 | __VA_ARGS__) | ||
50 | 51 | ||
51 | /** | 52 | /** |
52 | * Enable slow sanity checks to debug issues. | 53 | * Enable slow sanity checks to debug issues. |
@@ -81,17 +82,19 @@ | |||
81 | /** | 82 | /** |
82 | * How long at least to wait before sending another find peer request. | 83 | * How long at least to wait before sending another find peer request. |
83 | */ | 84 | */ |
84 | #define DHT_MINIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) | 85 | #define DHT_MINIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply ( \ |
86 | GNUNET_TIME_UNIT_SECONDS, 30) | ||
85 | 87 | ||
86 | /** | 88 | /** |
87 | * How long at most to wait before sending another find peer request. | 89 | * How long at most to wait before sending another find peer request. |
88 | */ | 90 | */ |
89 | #define DHT_MAXIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 10) | 91 | #define DHT_MAXIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply ( \ |
92 | GNUNET_TIME_UNIT_MINUTES, 10) | ||
90 | 93 | ||
91 | /** | 94 | /** |
92 | * How long at most to wait for transmission of a GET request to another peer? | 95 | * How long at most to wait for transmission of a GET request to another peer? |
93 | */ | 96 | */ |
94 | #define GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) | 97 | #define GET_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) |
95 | 98 | ||
96 | /** | 99 | /** |
97 | * Hello address expiration | 100 | * Hello address expiration |
@@ -104,7 +107,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
104 | /** | 107 | /** |
105 | * P2P PUT message | 108 | * P2P PUT message |
106 | */ | 109 | */ |
107 | struct PeerPutMessage { | 110 | struct PeerPutMessage |
111 | { | ||
108 | /** | 112 | /** |
109 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_PUT | 113 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_PUT |
110 | */ | 114 | */ |
@@ -159,7 +163,8 @@ struct PeerPutMessage { | |||
159 | /** | 163 | /** |
160 | * P2P Result message | 164 | * P2P Result message |
161 | */ | 165 | */ |
162 | struct PeerResultMessage { | 166 | struct PeerResultMessage |
167 | { | ||
163 | /** | 168 | /** |
164 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT | 169 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT |
165 | */ | 170 | */ |
@@ -201,7 +206,8 @@ struct PeerResultMessage { | |||
201 | /** | 206 | /** |
202 | * P2P GET message | 207 | * P2P GET message |
203 | */ | 208 | */ |
204 | struct PeerGetMessage { | 209 | struct PeerGetMessage |
210 | { | ||
205 | /** | 211 | /** |
206 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_GET | 212 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_GET |
207 | */ | 213 | */ |
@@ -257,7 +263,8 @@ GNUNET_NETWORK_STRUCT_END | |||
257 | /** | 263 | /** |
258 | * Entry for a peer in a bucket. | 264 | * Entry for a peer in a bucket. |
259 | */ | 265 | */ |
260 | struct PeerInfo { | 266 | struct PeerInfo |
267 | { | ||
261 | /** | 268 | /** |
262 | * Next peer entry (DLL) | 269 | * Next peer entry (DLL) |
263 | */ | 270 | */ |
@@ -293,7 +300,8 @@ struct PeerInfo { | |||
293 | /** | 300 | /** |
294 | * Peers are grouped into buckets. | 301 | * Peers are grouped into buckets. |
295 | */ | 302 | */ |
296 | struct PeerBucket { | 303 | struct PeerBucket |
304 | { | ||
297 | /** | 305 | /** |
298 | * Head of DLL | 306 | * Head of DLL |
299 | */ | 307 | */ |
@@ -314,7 +322,8 @@ struct PeerBucket { | |||
314 | /** | 322 | /** |
315 | * Information about a peer that we would like to connect to. | 323 | * Information about a peer that we would like to connect to. |
316 | */ | 324 | */ |
317 | struct ConnectInfo { | 325 | struct ConnectInfo |
326 | { | ||
318 | /** | 327 | /** |
319 | * Handle to active HELLO offer operation, or NULL. | 328 | * Handle to active HELLO offer operation, or NULL. |
320 | */ | 329 | */ |
@@ -414,17 +423,17 @@ static struct GNUNET_ATS_ConnectivityHandle *ats_ch; | |||
414 | * on error (same hashcode) | 423 | * on error (same hashcode) |
415 | */ | 424 | */ |
416 | static int | 425 | static int |
417 | find_bucket(const struct GNUNET_HashCode *hc) | 426 | find_bucket (const struct GNUNET_HashCode *hc) |
418 | { | 427 | { |
419 | unsigned int bits; | 428 | unsigned int bits; |
420 | 429 | ||
421 | bits = GNUNET_CRYPTO_hash_matching_bits(&my_identity_hash, hc); | 430 | bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, hc); |
422 | if (bits == MAX_BUCKETS) | 431 | if (bits == MAX_BUCKETS) |
423 | { | 432 | { |
424 | /* How can all bits match? Got my own ID? */ | 433 | /* How can all bits match? Got my own ID? */ |
425 | GNUNET_break(0); | 434 | GNUNET_break (0); |
426 | return GNUNET_SYSERR; | 435 | return GNUNET_SYSERR; |
427 | } | 436 | } |
428 | return MAX_BUCKETS - bits - 1; | 437 | return MAX_BUCKETS - bits - 1; |
429 | } | 438 | } |
430 | 439 | ||
@@ -436,7 +445,7 @@ find_bucket(const struct GNUNET_HashCode *hc) | |||
436 | * @param cls a `struct ConnectInfo` | 445 | * @param cls a `struct ConnectInfo` |
437 | */ | 446 | */ |
438 | static void | 447 | static void |
439 | offer_hello_done(void *cls) | 448 | offer_hello_done (void *cls) |
440 | { | 449 | { |
441 | struct ConnectInfo *ci = cls; | 450 | struct ConnectInfo *ci = cls; |
442 | 451 | ||
@@ -453,28 +462,28 @@ offer_hello_done(void *cls) | |||
453 | * @return #GNUNET_YES | 462 | * @return #GNUNET_YES |
454 | */ | 463 | */ |
455 | static int | 464 | static int |
456 | free_connect_info(void *cls, | 465 | free_connect_info (void *cls, |
457 | const struct GNUNET_PeerIdentity *peer, | 466 | const struct GNUNET_PeerIdentity *peer, |
458 | void *value) | 467 | void *value) |
459 | { | 468 | { |
460 | struct ConnectInfo *ci = value; | 469 | struct ConnectInfo *ci = value; |
461 | 470 | ||
462 | (void)cls; | 471 | (void) cls; |
463 | GNUNET_assert(GNUNET_YES == | 472 | GNUNET_assert (GNUNET_YES == |
464 | GNUNET_CONTAINER_multipeermap_remove(all_desired_peers, | 473 | GNUNET_CONTAINER_multipeermap_remove (all_desired_peers, |
465 | peer, | 474 | peer, |
466 | ci)); | 475 | ci)); |
467 | if (NULL != ci->sh) | 476 | if (NULL != ci->sh) |
468 | { | 477 | { |
469 | GNUNET_ATS_connectivity_suggest_cancel(ci->sh); | 478 | GNUNET_ATS_connectivity_suggest_cancel (ci->sh); |
470 | ci->sh = NULL; | 479 | ci->sh = NULL; |
471 | } | 480 | } |
472 | if (NULL != ci->oh) | 481 | if (NULL != ci->oh) |
473 | { | 482 | { |
474 | GNUNET_TRANSPORT_offer_hello_cancel(ci->oh); | 483 | GNUNET_TRANSPORT_offer_hello_cancel (ci->oh); |
475 | ci->oh = NULL; | 484 | ci->oh = NULL; |
476 | } | 485 | } |
477 | GNUNET_free(ci); | 486 | GNUNET_free (ci); |
478 | return GNUNET_YES; | 487 | return GNUNET_YES; |
479 | } | 488 | } |
480 | 489 | ||
@@ -488,68 +497,68 @@ free_connect_info(void *cls, | |||
488 | * @param h a HELLO message, or NULL | 497 | * @param h a HELLO message, or NULL |
489 | */ | 498 | */ |
490 | static void | 499 | static void |
491 | try_connect(const struct GNUNET_PeerIdentity *pid, | 500 | try_connect (const struct GNUNET_PeerIdentity *pid, |
492 | const struct GNUNET_MessageHeader *h) | 501 | const struct GNUNET_MessageHeader *h) |
493 | { | 502 | { |
494 | int bucket; | 503 | int bucket; |
495 | struct GNUNET_HashCode pid_hash; | 504 | struct GNUNET_HashCode pid_hash; |
496 | struct ConnectInfo *ci; | 505 | struct ConnectInfo *ci; |
497 | uint32_t strength; | 506 | uint32_t strength; |
498 | 507 | ||
499 | GNUNET_CRYPTO_hash(pid, | 508 | GNUNET_CRYPTO_hash (pid, |
500 | sizeof(struct GNUNET_PeerIdentity), | 509 | sizeof(struct GNUNET_PeerIdentity), |
501 | &pid_hash); | 510 | &pid_hash); |
502 | bucket = find_bucket(&pid_hash); | 511 | bucket = find_bucket (&pid_hash); |
503 | if (bucket < 0) | 512 | if (bucket < 0) |
504 | return; /* self? */ | 513 | return; /* self? */ |
505 | ci = GNUNET_CONTAINER_multipeermap_get(all_desired_peers, | 514 | ci = GNUNET_CONTAINER_multipeermap_get (all_desired_peers, |
506 | pid); | 515 | pid); |
507 | 516 | ||
508 | if (k_buckets[bucket].peers_size < bucket_size) | 517 | if (k_buckets[bucket].peers_size < bucket_size) |
509 | strength = (bucket_size - k_buckets[bucket].peers_size) * bucket; | 518 | strength = (bucket_size - k_buckets[bucket].peers_size) * bucket; |
510 | else | 519 | else |
511 | strength = bucket; /* minimum value of connectivity */ | 520 | strength = bucket; /* minimum value of connectivity */ |
512 | if (GNUNET_YES == | 521 | if (GNUNET_YES == |
513 | GNUNET_CONTAINER_multipeermap_contains(all_connected_peers, | 522 | GNUNET_CONTAINER_multipeermap_contains (all_connected_peers, |
514 | pid)) | 523 | pid)) |
515 | strength *= 2; /* double for connected peers */ | 524 | strength *= 2; /* double for connected peers */ |
516 | else if (k_buckets[bucket].peers_size > bucket_size) | 525 | else if (k_buckets[bucket].peers_size > bucket_size) |
517 | strength = 0; /* bucket full, we really do not care about more */ | 526 | strength = 0; /* bucket full, we really do not care about more */ |
518 | 527 | ||
519 | if ((0 == strength) && | 528 | if ((0 == strength) && |
520 | (NULL != ci)) | 529 | (NULL != ci)) |
521 | { | 530 | { |
522 | /* release request */ | 531 | /* release request */ |
523 | GNUNET_assert(GNUNET_YES == | 532 | GNUNET_assert (GNUNET_YES == |
524 | free_connect_info(NULL, | 533 | free_connect_info (NULL, |
525 | pid, | 534 | pid, |
526 | ci)); | 535 | ci)); |
527 | return; | 536 | return; |
528 | } | 537 | } |
529 | if (NULL == ci) | 538 | if (NULL == ci) |
530 | { | 539 | { |
531 | ci = GNUNET_new(struct ConnectInfo); | 540 | ci = GNUNET_new (struct ConnectInfo); |
532 | GNUNET_assert(GNUNET_OK == | 541 | GNUNET_assert (GNUNET_OK == |
533 | GNUNET_CONTAINER_multipeermap_put(all_desired_peers, | 542 | GNUNET_CONTAINER_multipeermap_put (all_desired_peers, |
534 | pid, | 543 | pid, |
535 | ci, | 544 | ci, |
536 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 545 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
537 | } | 546 | } |
538 | if ((NULL != ci->oh) && | 547 | if ((NULL != ci->oh) && |
539 | (NULL != h)) | 548 | (NULL != h)) |
540 | GNUNET_TRANSPORT_offer_hello_cancel(ci->oh); | 549 | GNUNET_TRANSPORT_offer_hello_cancel (ci->oh); |
541 | if (NULL != h) | 550 | if (NULL != h) |
542 | ci->oh = GNUNET_TRANSPORT_offer_hello(GDS_cfg, | 551 | ci->oh = GNUNET_TRANSPORT_offer_hello (GDS_cfg, |
543 | h, | 552 | h, |
544 | &offer_hello_done, | 553 | &offer_hello_done, |
545 | ci); | 554 | ci); |
546 | if ((NULL != ci->sh) && | 555 | if ((NULL != ci->sh) && |
547 | (ci->strength != strength)) | 556 | (ci->strength != strength)) |
548 | GNUNET_ATS_connectivity_suggest_cancel(ci->sh); | 557 | GNUNET_ATS_connectivity_suggest_cancel (ci->sh); |
549 | if (ci->strength != strength) | 558 | if (ci->strength != strength) |
550 | ci->sh = GNUNET_ATS_connectivity_suggest(ats_ch, | 559 | ci->sh = GNUNET_ATS_connectivity_suggest (ats_ch, |
551 | pid, | 560 | pid, |
552 | strength); | 561 | strength); |
553 | ci->strength = strength; | 562 | ci->strength = strength; |
554 | } | 563 | } |
555 | 564 | ||
@@ -567,14 +576,14 @@ try_connect(const struct GNUNET_PeerIdentity *pid, | |||
567 | * @return #GNUNET_YES (continue to iterate) | 576 | * @return #GNUNET_YES (continue to iterate) |
568 | */ | 577 | */ |
569 | static int | 578 | static int |
570 | update_desire_strength(void *cls, | 579 | update_desire_strength (void *cls, |
571 | const struct GNUNET_PeerIdentity *pid, | 580 | const struct GNUNET_PeerIdentity *pid, |
572 | void *value) | 581 | void *value) |
573 | { | 582 | { |
574 | (void)cls; | 583 | (void) cls; |
575 | (void)value; | 584 | (void) value; |
576 | try_connect(pid, | 585 | try_connect (pid, |
577 | NULL); | 586 | NULL); |
578 | return GNUNET_YES; | 587 | return GNUNET_YES; |
579 | } | 588 | } |
580 | 589 | ||
@@ -586,11 +595,11 @@ update_desire_strength(void *cls, | |||
586 | * @param tc scheduler context. | 595 | * @param tc scheduler context. |
587 | */ | 596 | */ |
588 | static void | 597 | static void |
589 | update_connect_preferences() | 598 | update_connect_preferences () |
590 | { | 599 | { |
591 | GNUNET_CONTAINER_multipeermap_iterate(all_desired_peers, | 600 | GNUNET_CONTAINER_multipeermap_iterate (all_desired_peers, |
592 | &update_desire_strength, | 601 | &update_desire_strength, |
593 | NULL); | 602 | NULL); |
594 | } | 603 | } |
595 | 604 | ||
596 | 605 | ||
@@ -604,24 +613,24 @@ update_connect_preferences() | |||
604 | * @return #GNUNET_YES (we should continue to iterate) | 613 | * @return #GNUNET_YES (we should continue to iterate) |
605 | */ | 614 | */ |
606 | static int | 615 | static int |
607 | add_known_to_bloom(void *cls, | 616 | add_known_to_bloom (void *cls, |
608 | const struct GNUNET_PeerIdentity *key, | 617 | const struct GNUNET_PeerIdentity *key, |
609 | void *value) | 618 | void *value) |
610 | { | 619 | { |
611 | struct GNUNET_BLOCK_Group *bg = cls; | 620 | struct GNUNET_BLOCK_Group *bg = cls; |
612 | struct GNUNET_HashCode key_hash; | 621 | struct GNUNET_HashCode key_hash; |
613 | 622 | ||
614 | (void)cls; | 623 | (void) cls; |
615 | (void)value; | 624 | (void) value; |
616 | GNUNET_CRYPTO_hash(key, | 625 | GNUNET_CRYPTO_hash (key, |
617 | sizeof(struct GNUNET_PeerIdentity), | 626 | sizeof(struct GNUNET_PeerIdentity), |
618 | &key_hash); | 627 | &key_hash); |
619 | GNUNET_BLOCK_group_set_seen(bg, | 628 | GNUNET_BLOCK_group_set_seen (bg, |
620 | &key_hash, | 629 | &key_hash, |
621 | 1); | 630 | 1); |
622 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 631 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
623 | "Adding known peer (%s) to bloomfilter for FIND PEER\n", | 632 | "Adding known peer (%s) to bloomfilter for FIND PEER\n", |
624 | GNUNET_i2s(key)); | 633 | GNUNET_i2s (key)); |
625 | return GNUNET_YES; | 634 | return GNUNET_YES; |
626 | } | 635 | } |
627 | 636 | ||
@@ -634,68 +643,70 @@ add_known_to_bloom(void *cls, | |||
634 | * @param cls closure for this task | 643 | * @param cls closure for this task |
635 | */ | 644 | */ |
636 | static void | 645 | static void |
637 | send_find_peer_message(void *cls) | 646 | send_find_peer_message (void *cls) |
638 | { | 647 | { |
639 | struct GNUNET_TIME_Relative next_send_time; | 648 | struct GNUNET_TIME_Relative next_send_time; |
640 | struct GNUNET_BLOCK_Group *bg; | 649 | struct GNUNET_BLOCK_Group *bg; |
641 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; | 650 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; |
642 | 651 | ||
643 | (void)cls; | 652 | (void) cls; |
644 | find_peer_task = NULL; | 653 | find_peer_task = NULL; |
645 | if (newly_found_peers > bucket_size) | 654 | if (newly_found_peers > bucket_size) |
646 | { | 655 | { |
647 | /* If we are finding many peers already, no need to send out our request right now! */ | 656 | /* If we are finding many peers already, no need to send out our request right now! */ |
648 | find_peer_task = | 657 | find_peer_task = |
649 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, | 658 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
650 | &send_find_peer_message, | 659 | &send_find_peer_message, |
651 | NULL); | 660 | NULL); |
652 | newly_found_peers = 0; | 661 | newly_found_peers = 0; |
653 | return; | 662 | return; |
654 | } | 663 | } |
655 | bg = GNUNET_BLOCK_group_create(GDS_block_context, | 664 | bg = GNUNET_BLOCK_group_create (GDS_block_context, |
656 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 665 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
657 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 666 | GNUNET_CRYPTO_random_u32 ( |
658 | UINT32_MAX), | 667 | GNUNET_CRYPTO_QUALITY_WEAK, |
659 | NULL, | 668 | UINT32_MAX), |
660 | 0, | 669 | NULL, |
661 | "filter-size", | 670 | 0, |
662 | DHT_BLOOM_SIZE, | 671 | "filter-size", |
663 | NULL); | 672 | DHT_BLOOM_SIZE, |
664 | GNUNET_CONTAINER_multipeermap_iterate(all_connected_peers, | 673 | NULL); |
665 | &add_known_to_bloom, | 674 | GNUNET_CONTAINER_multipeermap_iterate (all_connected_peers, |
666 | bg); | 675 | &add_known_to_bloom, |
667 | GNUNET_STATISTICS_update(GDS_stats, | 676 | bg); |
668 | gettext_noop("# FIND PEER messages initiated"), | 677 | GNUNET_STATISTICS_update (GDS_stats, |
669 | 1, | 678 | gettext_noop ("# FIND PEER messages initiated"), |
670 | GNUNET_NO); | 679 | 1, |
680 | GNUNET_NO); | ||
671 | peer_bf | 681 | peer_bf |
672 | = GNUNET_CONTAINER_bloomfilter_init(NULL, | 682 | = GNUNET_CONTAINER_bloomfilter_init (NULL, |
673 | DHT_BLOOM_SIZE, | 683 | DHT_BLOOM_SIZE, |
674 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 684 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
675 | // FIXME: pass priority!? | 685 | // FIXME: pass priority!? |
676 | GDS_NEIGHBOURS_handle_get(GNUNET_BLOCK_TYPE_DHT_HELLO, | 686 | GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO, |
677 | GNUNET_DHT_RO_FIND_PEER | GNUNET_DHT_RO_RECORD_ROUTE, | 687 | GNUNET_DHT_RO_FIND_PEER |
678 | FIND_PEER_REPLICATION_LEVEL, | 688 | | GNUNET_DHT_RO_RECORD_ROUTE, |
679 | 0, | 689 | FIND_PEER_REPLICATION_LEVEL, |
680 | &my_identity_hash, | 690 | 0, |
681 | NULL, | 691 | &my_identity_hash, |
682 | 0, | 692 | NULL, |
683 | bg, | 693 | 0, |
684 | peer_bf); | 694 | bg, |
685 | GNUNET_CONTAINER_bloomfilter_free(peer_bf); | 695 | peer_bf); |
686 | GNUNET_BLOCK_group_destroy(bg); | 696 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); |
697 | GNUNET_BLOCK_group_destroy (bg); | ||
687 | /* schedule next round */ | 698 | /* schedule next round */ |
688 | next_send_time.rel_value_us = | 699 | next_send_time.rel_value_us = |
689 | DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value_us + | 700 | DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value_us |
690 | GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | 701 | + GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
691 | DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value_us / | 702 | DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value_us |
692 | (newly_found_peers + 1)); | 703 | / (newly_found_peers + 1)); |
693 | newly_found_peers = 0; | 704 | newly_found_peers = 0; |
694 | GNUNET_assert(NULL == find_peer_task); | 705 | GNUNET_assert (NULL == find_peer_task); |
695 | find_peer_task = | 706 | find_peer_task = |
696 | GNUNET_SCHEDULER_add_delayed(next_send_time, | 707 | GNUNET_SCHEDULER_add_delayed (next_send_time, |
697 | &send_find_peer_message, | 708 | &send_find_peer_message, |
698 | NULL); | 709 | NULL); |
699 | } | 710 | } |
700 | 711 | ||
701 | 712 | ||
@@ -708,61 +719,61 @@ send_find_peer_message(void *cls) | |||
708 | * @return our `struct PeerInfo` for @a peer | 719 | * @return our `struct PeerInfo` for @a peer |
709 | */ | 720 | */ |
710 | static void * | 721 | static void * |
711 | handle_core_connect(void *cls, | 722 | handle_core_connect (void *cls, |
712 | const struct GNUNET_PeerIdentity *peer, | 723 | const struct GNUNET_PeerIdentity *peer, |
713 | struct GNUNET_MQ_Handle *mq) | 724 | struct GNUNET_MQ_Handle *mq) |
714 | { | 725 | { |
715 | struct PeerInfo *pi; | 726 | struct PeerInfo *pi; |
716 | 727 | ||
717 | (void)cls; | 728 | (void) cls; |
718 | /* Check for connect to self message */ | 729 | /* Check for connect to self message */ |
719 | if (0 == GNUNET_memcmp(&my_identity, | 730 | if (0 == GNUNET_memcmp (&my_identity, |
720 | peer)) | 731 | peer)) |
721 | return NULL; | 732 | return NULL; |
722 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 733 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
723 | "Connected to %s\n", | 734 | "Connected to %s\n", |
724 | GNUNET_i2s(peer)); | 735 | GNUNET_i2s (peer)); |
725 | GNUNET_assert(GNUNET_NO == | 736 | GNUNET_assert (GNUNET_NO == |
726 | GNUNET_CONTAINER_multipeermap_get(all_connected_peers, | 737 | GNUNET_CONTAINER_multipeermap_get (all_connected_peers, |
727 | peer)); | 738 | peer)); |
728 | GNUNET_STATISTICS_update(GDS_stats, | 739 | GNUNET_STATISTICS_update (GDS_stats, |
729 | gettext_noop("# peers connected"), | 740 | gettext_noop ("# peers connected"), |
730 | 1, | 741 | 1, |
731 | GNUNET_NO); | 742 | GNUNET_NO); |
732 | pi = GNUNET_new(struct PeerInfo); | 743 | pi = GNUNET_new (struct PeerInfo); |
733 | pi->id = peer; | 744 | pi->id = peer; |
734 | pi->mq = mq; | 745 | pi->mq = mq; |
735 | GNUNET_CRYPTO_hash(peer, | 746 | GNUNET_CRYPTO_hash (peer, |
736 | sizeof(struct GNUNET_PeerIdentity), | 747 | sizeof(struct GNUNET_PeerIdentity), |
737 | &pi->phash); | 748 | &pi->phash); |
738 | pi->peer_bucket = find_bucket(&pi->phash); | 749 | pi->peer_bucket = find_bucket (&pi->phash); |
739 | GNUNET_assert((pi->peer_bucket >= 0) && | 750 | GNUNET_assert ((pi->peer_bucket >= 0) && |
740 | ((unsigned int)pi->peer_bucket < MAX_BUCKETS)); | 751 | ((unsigned int) pi->peer_bucket < MAX_BUCKETS)); |
741 | GNUNET_CONTAINER_DLL_insert_tail(k_buckets[pi->peer_bucket].head, | 752 | GNUNET_CONTAINER_DLL_insert_tail (k_buckets[pi->peer_bucket].head, |
742 | k_buckets[pi->peer_bucket].tail, | 753 | k_buckets[pi->peer_bucket].tail, |
743 | pi); | 754 | pi); |
744 | k_buckets[pi->peer_bucket].peers_size++; | 755 | k_buckets[pi->peer_bucket].peers_size++; |
745 | closest_bucket = GNUNET_MAX(closest_bucket, | 756 | closest_bucket = GNUNET_MAX (closest_bucket, |
746 | (unsigned int)pi->peer_bucket); | 757 | (unsigned int) pi->peer_bucket); |
747 | GNUNET_assert(GNUNET_OK == | 758 | GNUNET_assert (GNUNET_OK == |
748 | GNUNET_CONTAINER_multipeermap_put(all_connected_peers, | 759 | GNUNET_CONTAINER_multipeermap_put (all_connected_peers, |
749 | pi->id, | 760 | pi->id, |
750 | pi, | 761 | pi, |
751 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 762 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
752 | if ((pi->peer_bucket > 0) && | 763 | if ((pi->peer_bucket > 0) && |
753 | (k_buckets[pi->peer_bucket].peers_size <= bucket_size)) | 764 | (k_buckets[pi->peer_bucket].peers_size <= bucket_size)) |
754 | { | 765 | { |
755 | update_connect_preferences(); | 766 | update_connect_preferences (); |
756 | newly_found_peers++; | 767 | newly_found_peers++; |
757 | } | 768 | } |
758 | if ((1 == GNUNET_CONTAINER_multipeermap_size(all_connected_peers)) && | 769 | if ((1 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers)) && |
759 | (GNUNET_YES != disable_try_connect)) | 770 | (GNUNET_YES != disable_try_connect)) |
760 | { | 771 | { |
761 | /* got a first connection, good time to start with FIND PEER requests... */ | 772 | /* got a first connection, good time to start with FIND PEER requests... */ |
762 | GNUNET_assert(NULL == find_peer_task); | 773 | GNUNET_assert (NULL == find_peer_task); |
763 | find_peer_task = GNUNET_SCHEDULER_add_now(&send_find_peer_message, | 774 | find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, |
764 | NULL); | 775 | NULL); |
765 | } | 776 | } |
766 | return pi; | 777 | return pi; |
767 | } | 778 | } |
768 | 779 | ||
@@ -775,45 +786,45 @@ handle_core_connect(void *cls, | |||
775 | * @param internal_cls our `struct PeerInfo` for @a peer | 786 | * @param internal_cls our `struct PeerInfo` for @a peer |
776 | */ | 787 | */ |
777 | static void | 788 | static void |
778 | handle_core_disconnect(void *cls, | 789 | handle_core_disconnect (void *cls, |
779 | const struct GNUNET_PeerIdentity *peer, | 790 | const struct GNUNET_PeerIdentity *peer, |
780 | void *internal_cls) | 791 | void *internal_cls) |
781 | { | 792 | { |
782 | struct PeerInfo *to_remove = internal_cls; | 793 | struct PeerInfo *to_remove = internal_cls; |
783 | 794 | ||
784 | (void)cls; | 795 | (void) cls; |
785 | /* Check for disconnect from self message */ | 796 | /* Check for disconnect from self message */ |
786 | if (NULL == to_remove) | 797 | if (NULL == to_remove) |
787 | return; | 798 | return; |
788 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 799 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
789 | "Disconnected %s\n", | 800 | "Disconnected %s\n", |
790 | GNUNET_i2s(peer)); | 801 | GNUNET_i2s (peer)); |
791 | GNUNET_STATISTICS_update(GDS_stats, | 802 | GNUNET_STATISTICS_update (GDS_stats, |
792 | gettext_noop("# peers connected"), | 803 | gettext_noop ("# peers connected"), |
793 | -1, | 804 | -1, |
794 | GNUNET_NO); | 805 | GNUNET_NO); |
795 | GNUNET_assert(GNUNET_YES == | 806 | GNUNET_assert (GNUNET_YES == |
796 | GNUNET_CONTAINER_multipeermap_remove(all_connected_peers, | 807 | GNUNET_CONTAINER_multipeermap_remove (all_connected_peers, |
797 | peer, | 808 | peer, |
798 | to_remove)); | 809 | to_remove)); |
799 | if ((0 == GNUNET_CONTAINER_multipeermap_size(all_connected_peers)) && | 810 | if ((0 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers)) && |
800 | (GNUNET_YES != disable_try_connect)) | 811 | (GNUNET_YES != disable_try_connect)) |
801 | { | 812 | { |
802 | GNUNET_SCHEDULER_cancel(find_peer_task); | 813 | GNUNET_SCHEDULER_cancel (find_peer_task); |
803 | find_peer_task = NULL; | 814 | find_peer_task = NULL; |
804 | } | 815 | } |
805 | GNUNET_assert(to_remove->peer_bucket >= 0); | 816 | GNUNET_assert (to_remove->peer_bucket >= 0); |
806 | GNUNET_CONTAINER_DLL_remove(k_buckets[to_remove->peer_bucket].head, | 817 | GNUNET_CONTAINER_DLL_remove (k_buckets[to_remove->peer_bucket].head, |
807 | k_buckets[to_remove->peer_bucket].tail, | 818 | k_buckets[to_remove->peer_bucket].tail, |
808 | to_remove); | 819 | to_remove); |
809 | GNUNET_assert(k_buckets[to_remove->peer_bucket].peers_size > 0); | 820 | GNUNET_assert (k_buckets[to_remove->peer_bucket].peers_size > 0); |
810 | k_buckets[to_remove->peer_bucket].peers_size--; | 821 | k_buckets[to_remove->peer_bucket].peers_size--; |
811 | while ((closest_bucket > 0) && | 822 | while ((closest_bucket > 0) && |
812 | (0 == k_buckets[to_remove->peer_bucket].peers_size)) | 823 | (0 == k_buckets[to_remove->peer_bucket].peers_size)) |
813 | closest_bucket--; | 824 | closest_bucket--; |
814 | if (k_buckets[to_remove->peer_bucket].peers_size < bucket_size) | 825 | if (k_buckets[to_remove->peer_bucket].peers_size < bucket_size) |
815 | update_connect_preferences(); | 826 | update_connect_preferences (); |
816 | GNUNET_free(to_remove); | 827 | GNUNET_free (to_remove); |
817 | } | 828 | } |
818 | 829 | ||
819 | 830 | ||
@@ -826,39 +837,39 @@ handle_core_disconnect(void *cls, | |||
826 | * @return Some number of peers to forward the message to | 837 | * @return Some number of peers to forward the message to |
827 | */ | 838 | */ |
828 | static unsigned int | 839 | static unsigned int |
829 | get_forward_count(uint32_t hop_count, | 840 | get_forward_count (uint32_t hop_count, |
830 | uint32_t target_replication) | 841 | uint32_t target_replication) |
831 | { | 842 | { |
832 | uint32_t random_value; | 843 | uint32_t random_value; |
833 | uint32_t forward_count; | 844 | uint32_t forward_count; |
834 | float target_value; | 845 | float target_value; |
835 | 846 | ||
836 | if (hop_count > GDS_NSE_get() * 4.0) | 847 | if (hop_count > GDS_NSE_get () * 4.0) |
837 | { | 848 | { |
838 | /* forcefully terminate */ | 849 | /* forcefully terminate */ |
839 | GNUNET_STATISTICS_update(GDS_stats, | 850 | GNUNET_STATISTICS_update (GDS_stats, |
840 | gettext_noop("# requests TTL-dropped"), | 851 | gettext_noop ("# requests TTL-dropped"), |
841 | 1, GNUNET_NO); | 852 | 1, GNUNET_NO); |
842 | return 0; | 853 | return 0; |
843 | } | 854 | } |
844 | if (hop_count > GDS_NSE_get() * 2.0) | 855 | if (hop_count > GDS_NSE_get () * 2.0) |
845 | { | 856 | { |
846 | /* Once we have reached our ideal number of hops, only forward to 1 peer */ | 857 | /* Once we have reached our ideal number of hops, only forward to 1 peer */ |
847 | return 1; | 858 | return 1; |
848 | } | 859 | } |
849 | /* bound by system-wide maximum */ | 860 | /* bound by system-wide maximum */ |
850 | target_replication = | 861 | target_replication = |
851 | GNUNET_MIN(MAXIMUM_REPLICATION_LEVEL, target_replication); | 862 | GNUNET_MIN (MAXIMUM_REPLICATION_LEVEL, target_replication); |
852 | target_value = | 863 | target_value = |
853 | 1 + (target_replication - 1.0) / (GDS_NSE_get() + | 864 | 1 + (target_replication - 1.0) / (GDS_NSE_get () |
854 | ((float)(target_replication - 1.0) * | 865 | + ((float) (target_replication - 1.0) |
855 | hop_count)); | 866 | * hop_count)); |
856 | /* Set forward count to floor of target_value */ | 867 | /* Set forward count to floor of target_value */ |
857 | forward_count = (uint32_t)target_value; | 868 | forward_count = (uint32_t) target_value; |
858 | /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ | 869 | /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ |
859 | target_value = target_value - forward_count; | 870 | target_value = target_value - forward_count; |
860 | random_value = | 871 | random_value = |
861 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); | 872 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); |
862 | if (random_value < (target_value * UINT32_MAX)) | 873 | if (random_value < (target_value * UINT32_MAX)) |
863 | forward_count++; | 874 | forward_count++; |
864 | return forward_count; | 875 | return forward_count; |
@@ -877,8 +888,8 @@ get_forward_count(uint32_t hop_count, | |||
877 | * the two hash codes increases | 888 | * the two hash codes increases |
878 | */ | 889 | */ |
879 | static unsigned int | 890 | static unsigned int |
880 | get_distance(const struct GNUNET_HashCode *target, | 891 | get_distance (const struct GNUNET_HashCode *target, |
881 | const struct GNUNET_HashCode *have) | 892 | const struct GNUNET_HashCode *have) |
882 | { | 893 | { |
883 | unsigned int bucket; | 894 | unsigned int bucket; |
884 | unsigned int msb; | 895 | unsigned int msb; |
@@ -900,13 +911,13 @@ get_distance(const struct GNUNET_HashCode *target, | |||
900 | 911 | ||
901 | /* first, calculate the most significant 9 bits of our | 912 | /* first, calculate the most significant 9 bits of our |
902 | * result, aka the number of LSBs */ | 913 | * result, aka the number of LSBs */ |
903 | bucket = GNUNET_CRYPTO_hash_matching_bits(target, | 914 | bucket = GNUNET_CRYPTO_hash_matching_bits (target, |
904 | have); | 915 | have); |
905 | /* bucket is now a value between 0 and 512 */ | 916 | /* bucket is now a value between 0 and 512 */ |
906 | if (bucket == 512) | 917 | if (bucket == 512) |
907 | return 0; /* perfect match */ | 918 | return 0; /* perfect match */ |
908 | if (bucket == 0) | 919 | if (bucket == 0) |
909 | return (unsigned int)-1; /* LSB differs; use max (if we did the bit-shifting | 920 | return (unsigned int) -1; /* LSB differs; use max (if we did the bit-shifting |
910 | * below, we'd end up with max+1 (overflow)) */ | 921 | * below, we'd end up with max+1 (overflow)) */ |
911 | 922 | ||
912 | /* calculate the most significant bits of the final result */ | 923 | /* calculate the most significant bits of the final result */ |
@@ -916,14 +927,15 @@ get_distance(const struct GNUNET_HashCode *target, | |||
916 | * mismatching bit at 'bucket' */ | 927 | * mismatching bit at 'bucket' */ |
917 | lsb = 0; | 928 | lsb = 0; |
918 | for (i = bucket + 1; | 929 | for (i = bucket + 1; |
919 | (i < sizeof(struct GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9); i++) | 930 | (i < sizeof(struct GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9); |
920 | { | 931 | i++) |
921 | if (GNUNET_CRYPTO_hash_get_bit(target, i) != | 932 | { |
922 | GNUNET_CRYPTO_hash_get_bit(have, i)) | 933 | if (GNUNET_CRYPTO_hash_get_bit (target, i) != |
923 | lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10, | 934 | GNUNET_CRYPTO_hash_get_bit (have, i)) |
935 | lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10, | ||
924 | * last bit set will be 31 -- if | 936 | * last bit set will be 31 -- if |
925 | * i does not reach 512 first... */ | 937 | * i does not reach 512 first... */ |
926 | } | 938 | } |
927 | return msb | lsb; | 939 | return msb | lsb; |
928 | } | 940 | } |
929 | 941 | ||
@@ -939,40 +951,40 @@ get_distance(const struct GNUNET_HashCode *target, | |||
939 | * #GNUNET_NO otherwise. | 951 | * #GNUNET_NO otherwise. |
940 | */ | 952 | */ |
941 | int | 953 | int |
942 | GDS_am_closest_peer(const struct GNUNET_HashCode *key, | 954 | GDS_am_closest_peer (const struct GNUNET_HashCode *key, |
943 | const struct GNUNET_CONTAINER_BloomFilter *bloom) | 955 | const struct GNUNET_CONTAINER_BloomFilter *bloom) |
944 | { | 956 | { |
945 | int bits; | 957 | int bits; |
946 | int other_bits; | 958 | int other_bits; |
947 | int bucket_num; | 959 | int bucket_num; |
948 | struct PeerInfo *pos; | 960 | struct PeerInfo *pos; |
949 | 961 | ||
950 | if (0 == GNUNET_memcmp(&my_identity_hash, | 962 | if (0 == GNUNET_memcmp (&my_identity_hash, |
951 | key)) | 963 | key)) |
952 | return GNUNET_YES; | 964 | return GNUNET_YES; |
953 | bucket_num = find_bucket(key); | 965 | bucket_num = find_bucket (key); |
954 | GNUNET_assert(bucket_num >= 0); | 966 | GNUNET_assert (bucket_num >= 0); |
955 | bits = GNUNET_CRYPTO_hash_matching_bits(&my_identity_hash, | 967 | bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, |
956 | key); | 968 | key); |
957 | pos = k_buckets[bucket_num].head; | 969 | pos = k_buckets[bucket_num].head; |
958 | while (NULL != pos) | 970 | while (NULL != pos) |
971 | { | ||
972 | if ((NULL != bloom) && | ||
973 | (GNUNET_YES == | ||
974 | GNUNET_CONTAINER_bloomfilter_test (bloom, | ||
975 | &pos->phash))) | ||
959 | { | 976 | { |
960 | if ((NULL != bloom) && | ||
961 | (GNUNET_YES == | ||
962 | GNUNET_CONTAINER_bloomfilter_test(bloom, | ||
963 | &pos->phash))) | ||
964 | { | ||
965 | pos = pos->next; | ||
966 | continue; /* Skip already checked entries */ | ||
967 | } | ||
968 | other_bits = GNUNET_CRYPTO_hash_matching_bits(&pos->phash, | ||
969 | key); | ||
970 | if (other_bits > bits) | ||
971 | return GNUNET_NO; | ||
972 | if (other_bits == bits) /* We match the same number of bits */ | ||
973 | return GNUNET_YES; | ||
974 | pos = pos->next; | 977 | pos = pos->next; |
978 | continue; /* Skip already checked entries */ | ||
975 | } | 979 | } |
980 | other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->phash, | ||
981 | key); | ||
982 | if (other_bits > bits) | ||
983 | return GNUNET_NO; | ||
984 | if (other_bits == bits) /* We match the same number of bits */ | ||
985 | return GNUNET_YES; | ||
986 | pos = pos->next; | ||
987 | } | ||
976 | /* No peers closer, we are the closest! */ | 988 | /* No peers closer, we are the closest! */ |
977 | return GNUNET_YES; | 989 | return GNUNET_YES; |
978 | } | 990 | } |
@@ -996,9 +1008,9 @@ GDS_am_closest_peer(const struct GNUNET_HashCode *key, | |||
996 | * @return Peer to route to, or NULL on error | 1008 | * @return Peer to route to, or NULL on error |
997 | */ | 1009 | */ |
998 | static struct PeerInfo * | 1010 | static struct PeerInfo * |
999 | select_peer(const struct GNUNET_HashCode *key, | 1011 | select_peer (const struct GNUNET_HashCode *key, |
1000 | const struct GNUNET_CONTAINER_BloomFilter *bloom, | 1012 | const struct GNUNET_CONTAINER_BloomFilter *bloom, |
1001 | uint32_t hops) | 1013 | uint32_t hops) |
1002 | { | 1014 | { |
1003 | unsigned int bc; | 1015 | unsigned int bc; |
1004 | unsigned int count; | 1016 | unsigned int count; |
@@ -1008,126 +1020,129 @@ select_peer(const struct GNUNET_HashCode *key, | |||
1008 | unsigned int smallest_distance; | 1020 | unsigned int smallest_distance; |
1009 | struct PeerInfo *chosen; | 1021 | struct PeerInfo *chosen; |
1010 | 1022 | ||
1011 | if (hops >= GDS_NSE_get()) | 1023 | if (hops >= GDS_NSE_get ()) |
1024 | { | ||
1025 | /* greedy selection (closest peer that is not in bloomfilter) */ | ||
1026 | smallest_distance = UINT_MAX; | ||
1027 | chosen = NULL; | ||
1028 | for (bc = 0; bc <= closest_bucket; bc++) | ||
1012 | { | 1029 | { |
1013 | /* greedy selection (closest peer that is not in bloomfilter) */ | 1030 | pos = k_buckets[bc].head; |
1014 | smallest_distance = UINT_MAX; | 1031 | count = 0; |
1015 | chosen = NULL; | 1032 | while ((pos != NULL) && (count < bucket_size)) |
1016 | for (bc = 0; bc <= closest_bucket; bc++) | 1033 | { |
1034 | if ((NULL == bloom) || | ||
1035 | (GNUNET_NO == | ||
1036 | GNUNET_CONTAINER_bloomfilter_test (bloom, | ||
1037 | &pos->phash))) | ||
1038 | { | ||
1039 | dist = get_distance (key, | ||
1040 | &pos->phash); | ||
1041 | if (dist < smallest_distance) | ||
1042 | { | ||
1043 | chosen = pos; | ||
1044 | smallest_distance = dist; | ||
1045 | } | ||
1046 | } | ||
1047 | else | ||
1017 | { | 1048 | { |
1018 | pos = k_buckets[bc].head; | 1049 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1019 | count = 0; | 1050 | "Excluded peer `%s' due to BF match in greedy routing for %s\n", |
1020 | while ((pos != NULL) && (count < bucket_size)) | 1051 | GNUNET_i2s (pos->id), |
1021 | { | 1052 | GNUNET_h2s (key)); |
1022 | if ((NULL == bloom) || | 1053 | GNUNET_STATISTICS_update (GDS_stats, |
1023 | (GNUNET_NO == | 1054 | gettext_noop ( |
1024 | GNUNET_CONTAINER_bloomfilter_test(bloom, | 1055 | "# Peers excluded from routing due to Bloomfilter"), |
1025 | &pos->phash))) | 1056 | 1, |
1026 | { | 1057 | GNUNET_NO); |
1027 | dist = get_distance(key, | 1058 | dist = get_distance (key, |
1028 | &pos->phash); | 1059 | &pos->phash); |
1029 | if (dist < smallest_distance) | 1060 | if (dist < smallest_distance) |
1030 | { | 1061 | { |
1031 | chosen = pos; | 1062 | chosen = NULL; |
1032 | smallest_distance = dist; | 1063 | smallest_distance = dist; |
1033 | } | 1064 | } |
1034 | } | ||
1035 | else | ||
1036 | { | ||
1037 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1038 | "Excluded peer `%s' due to BF match in greedy routing for %s\n", | ||
1039 | GNUNET_i2s(pos->id), | ||
1040 | GNUNET_h2s(key)); | ||
1041 | GNUNET_STATISTICS_update(GDS_stats, | ||
1042 | gettext_noop("# Peers excluded from routing due to Bloomfilter"), | ||
1043 | 1, | ||
1044 | GNUNET_NO); | ||
1045 | dist = get_distance(key, | ||
1046 | &pos->phash); | ||
1047 | if (dist < smallest_distance) | ||
1048 | { | ||
1049 | chosen = NULL; | ||
1050 | smallest_distance = dist; | ||
1051 | } | ||
1052 | } | ||
1053 | count++; | ||
1054 | pos = pos->next; | ||
1055 | } | ||
1056 | } | 1065 | } |
1057 | if (NULL == chosen) | 1066 | count++; |
1058 | GNUNET_STATISTICS_update(GDS_stats, | 1067 | pos = pos->next; |
1059 | gettext_noop("# Peer selection failed"), | 1068 | } |
1060 | 1, | ||
1061 | GNUNET_NO); | ||
1062 | else | ||
1063 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1064 | "Selected peer `%s' in greedy routing for %s\n", | ||
1065 | GNUNET_i2s(chosen->id), | ||
1066 | GNUNET_h2s(key)); | ||
1067 | return chosen; | ||
1068 | } | 1069 | } |
1070 | if (NULL == chosen) | ||
1071 | GNUNET_STATISTICS_update (GDS_stats, | ||
1072 | gettext_noop ("# Peer selection failed"), | ||
1073 | 1, | ||
1074 | GNUNET_NO); | ||
1075 | else | ||
1076 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1077 | "Selected peer `%s' in greedy routing for %s\n", | ||
1078 | GNUNET_i2s (chosen->id), | ||
1079 | GNUNET_h2s (key)); | ||
1080 | return chosen; | ||
1081 | } | ||
1069 | 1082 | ||
1070 | /* select "random" peer */ | 1083 | /* select "random" peer */ |
1071 | /* count number of peers that are available and not filtered */ | 1084 | /* count number of peers that are available and not filtered */ |
1072 | count = 0; | 1085 | count = 0; |
1073 | for (bc = 0; bc <= closest_bucket; bc++) | 1086 | for (bc = 0; bc <= closest_bucket; bc++) |
1087 | { | ||
1088 | pos = k_buckets[bc].head; | ||
1089 | while ((NULL != pos) && (count < bucket_size)) | ||
1074 | { | 1090 | { |
1075 | pos = k_buckets[bc].head; | 1091 | if ((NULL != bloom) && |
1076 | while ((NULL != pos) && (count < bucket_size)) | 1092 | (GNUNET_YES == |
1077 | { | 1093 | GNUNET_CONTAINER_bloomfilter_test (bloom, |
1078 | if ((NULL != bloom) && | 1094 | &pos->phash))) |
1079 | (GNUNET_YES == | 1095 | { |
1080 | GNUNET_CONTAINER_bloomfilter_test(bloom, | 1096 | GNUNET_STATISTICS_update (GDS_stats, |
1081 | &pos->phash))) | 1097 | gettext_noop |
1082 | { | 1098 | ( |
1083 | GNUNET_STATISTICS_update(GDS_stats, | 1099 | "# Peers excluded from routing due to Bloomfilter"), |
1084 | gettext_noop | 1100 | 1, GNUNET_NO); |
1085 | ("# Peers excluded from routing due to Bloomfilter"), | 1101 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1086 | 1, GNUNET_NO); | 1102 | "Excluded peer `%s' due to BF match in random routing for %s\n", |
1087 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1103 | GNUNET_i2s (pos->id), |
1088 | "Excluded peer `%s' due to BF match in random routing for %s\n", | 1104 | GNUNET_h2s (key)); |
1089 | GNUNET_i2s(pos->id), | 1105 | pos = pos->next; |
1090 | GNUNET_h2s(key)); | 1106 | continue; /* Ignore bloomfiltered peers */ |
1091 | pos = pos->next; | 1107 | } |
1092 | continue; /* Ignore bloomfiltered peers */ | 1108 | count++; |
1093 | } | 1109 | pos = pos->next; |
1094 | count++; | ||
1095 | pos = pos->next; | ||
1096 | } | ||
1097 | } | 1110 | } |
1111 | } | ||
1098 | if (0 == count) /* No peers to select from! */ | 1112 | if (0 == count) /* No peers to select from! */ |
1099 | { | 1113 | { |
1100 | GNUNET_STATISTICS_update(GDS_stats, | 1114 | GNUNET_STATISTICS_update (GDS_stats, |
1101 | gettext_noop("# Peer selection failed"), 1, | 1115 | gettext_noop ("# Peer selection failed"), 1, |
1102 | GNUNET_NO); | 1116 | GNUNET_NO); |
1103 | return NULL; | 1117 | return NULL; |
1104 | } | 1118 | } |
1105 | /* Now actually choose a peer */ | 1119 | /* Now actually choose a peer */ |
1106 | selected = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 1120 | selected = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1107 | count); | 1121 | count); |
1108 | count = 0; | 1122 | count = 0; |
1109 | for (bc = 0; bc <= closest_bucket; bc++) | 1123 | for (bc = 0; bc <= closest_bucket; bc++) |
1124 | { | ||
1125 | for (pos = k_buckets[bc].head; ((pos != NULL) && (count < bucket_size)); | ||
1126 | pos = pos->next) | ||
1110 | { | 1127 | { |
1111 | for (pos = k_buckets[bc].head; ((pos != NULL) && (count < bucket_size)); pos = pos->next) | 1128 | if ((bloom != NULL) && |
1112 | { | 1129 | (GNUNET_YES == |
1113 | if ((bloom != NULL) && | 1130 | GNUNET_CONTAINER_bloomfilter_test (bloom, |
1114 | (GNUNET_YES == | 1131 | &pos->phash))) |
1115 | GNUNET_CONTAINER_bloomfilter_test(bloom, | 1132 | { |
1116 | &pos->phash))) | 1133 | continue; /* Ignore bloomfiltered peers */ |
1117 | { | 1134 | } |
1118 | continue; /* Ignore bloomfiltered peers */ | 1135 | if (0 == selected--) |
1119 | } | 1136 | { |
1120 | if (0 == selected--) | 1137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1121 | { | 1138 | "Selected peer `%s' in random routing for %s\n", |
1122 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1139 | GNUNET_i2s (pos->id), |
1123 | "Selected peer `%s' in random routing for %s\n", | 1140 | GNUNET_h2s (key)); |
1124 | GNUNET_i2s(pos->id), | 1141 | return pos; |
1125 | GNUNET_h2s(key)); | 1142 | } |
1126 | return pos; | ||
1127 | } | ||
1128 | } | ||
1129 | } | 1143 | } |
1130 | GNUNET_break(0); | 1144 | } |
1145 | GNUNET_break (0); | ||
1131 | return NULL; | 1146 | return NULL; |
1132 | } | 1147 | } |
1133 | 1148 | ||
@@ -1146,60 +1161,60 @@ select_peer(const struct GNUNET_HashCode *key, | |||
1146 | * @return number of peers returned in 'targets'. | 1161 | * @return number of peers returned in 'targets'. |
1147 | */ | 1162 | */ |
1148 | static unsigned int | 1163 | static unsigned int |
1149 | get_target_peers(const struct GNUNET_HashCode *key, | 1164 | get_target_peers (const struct GNUNET_HashCode *key, |
1150 | struct GNUNET_CONTAINER_BloomFilter *bloom, | 1165 | struct GNUNET_CONTAINER_BloomFilter *bloom, |
1151 | uint32_t hop_count, | 1166 | uint32_t hop_count, |
1152 | uint32_t target_replication, | 1167 | uint32_t target_replication, |
1153 | struct PeerInfo ***targets) | 1168 | struct PeerInfo ***targets) |
1154 | { | 1169 | { |
1155 | unsigned int ret; | 1170 | unsigned int ret; |
1156 | unsigned int off; | 1171 | unsigned int off; |
1157 | struct PeerInfo **rtargets; | 1172 | struct PeerInfo **rtargets; |
1158 | struct PeerInfo *nxt; | 1173 | struct PeerInfo *nxt; |
1159 | 1174 | ||
1160 | GNUNET_assert(NULL != bloom); | 1175 | GNUNET_assert (NULL != bloom); |
1161 | ret = get_forward_count(hop_count, | 1176 | ret = get_forward_count (hop_count, |
1162 | target_replication); | 1177 | target_replication); |
1163 | if (0 == ret) | 1178 | if (0 == ret) |
1164 | { | 1179 | { |
1165 | *targets = NULL; | 1180 | *targets = NULL; |
1166 | return 0; | 1181 | return 0; |
1167 | } | 1182 | } |
1168 | rtargets = GNUNET_new_array(ret, | 1183 | rtargets = GNUNET_new_array (ret, |
1169 | struct PeerInfo *); | 1184 | struct PeerInfo *); |
1170 | for (off = 0; off < ret; off++) | 1185 | for (off = 0; off < ret; off++) |
1171 | { | 1186 | { |
1172 | nxt = select_peer(key, | 1187 | nxt = select_peer (key, |
1173 | bloom, | 1188 | bloom, |
1174 | hop_count); | 1189 | hop_count); |
1175 | if (NULL == nxt) | 1190 | if (NULL == nxt) |
1176 | break; | 1191 | break; |
1177 | rtargets[off] = nxt; | 1192 | rtargets[off] = nxt; |
1178 | GNUNET_break(GNUNET_NO == | 1193 | GNUNET_break (GNUNET_NO == |
1179 | GNUNET_CONTAINER_bloomfilter_test(bloom, | 1194 | GNUNET_CONTAINER_bloomfilter_test (bloom, |
1180 | &nxt->phash)); | 1195 | &nxt->phash)); |
1181 | GNUNET_CONTAINER_bloomfilter_add(bloom, | 1196 | GNUNET_CONTAINER_bloomfilter_add (bloom, |
1182 | &nxt->phash); | 1197 | &nxt->phash); |
1183 | } | 1198 | } |
1184 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1185 | "Selected %u/%u peers at hop %u for %s (target was %u)\n", | 1200 | "Selected %u/%u peers at hop %u for %s (target was %u)\n", |
1186 | off, | 1201 | off, |
1187 | GNUNET_CONTAINER_multipeermap_size(all_connected_peers), | 1202 | GNUNET_CONTAINER_multipeermap_size (all_connected_peers), |
1188 | (unsigned int)hop_count, | 1203 | (unsigned int) hop_count, |
1189 | GNUNET_h2s(key), | 1204 | GNUNET_h2s (key), |
1190 | ret); | 1205 | ret); |
1191 | if (0 == off) | 1206 | if (0 == off) |
1192 | { | 1207 | { |
1193 | GNUNET_free(rtargets); | 1208 | GNUNET_free (rtargets); |
1194 | *targets = NULL; | 1209 | *targets = NULL; |
1195 | return 0; | 1210 | return 0; |
1196 | } | 1211 | } |
1197 | *targets = rtargets; | 1212 | *targets = rtargets; |
1198 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1199 | "Forwarding query `%s' to %u peers (goal was %u peers)\n", | 1214 | "Forwarding query `%s' to %u peers (goal was %u peers)\n", |
1200 | GNUNET_h2s(key), | 1215 | GNUNET_h2s (key), |
1201 | off, | 1216 | off, |
1202 | ret); | 1217 | ret); |
1203 | return off; | 1218 | return off; |
1204 | } | 1219 | } |
1205 | 1220 | ||
@@ -1225,17 +1240,17 @@ get_target_peers(const struct GNUNET_HashCode *key, | |||
1225 | * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not | 1240 | * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not |
1226 | */ | 1241 | */ |
1227 | int | 1242 | int |
1228 | GDS_NEIGHBOURS_handle_put(enum GNUNET_BLOCK_Type type, | 1243 | GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, |
1229 | enum GNUNET_DHT_RouteOption options, | 1244 | enum GNUNET_DHT_RouteOption options, |
1230 | uint32_t desired_replication_level, | 1245 | uint32_t desired_replication_level, |
1231 | struct GNUNET_TIME_Absolute expiration_time, | 1246 | struct GNUNET_TIME_Absolute expiration_time, |
1232 | uint32_t hop_count, | 1247 | uint32_t hop_count, |
1233 | struct GNUNET_CONTAINER_BloomFilter *bf, | 1248 | struct GNUNET_CONTAINER_BloomFilter *bf, |
1234 | const struct GNUNET_HashCode *key, | 1249 | const struct GNUNET_HashCode *key, |
1235 | unsigned int put_path_length, | 1250 | unsigned int put_path_length, |
1236 | struct GNUNET_PeerIdentity *put_path, | 1251 | struct GNUNET_PeerIdentity *put_path, |
1237 | const void *data, | 1252 | const void *data, |
1238 | size_t data_size) | 1253 | size_t data_size) |
1239 | { | 1254 | { |
1240 | unsigned int target_count; | 1255 | unsigned int target_count; |
1241 | unsigned int i; | 1256 | unsigned int i; |
@@ -1247,97 +1262,99 @@ GDS_NEIGHBOURS_handle_put(enum GNUNET_BLOCK_Type type, | |||
1247 | struct GNUNET_PeerIdentity *pp; | 1262 | struct GNUNET_PeerIdentity *pp; |
1248 | unsigned int skip_count; | 1263 | unsigned int skip_count; |
1249 | 1264 | ||
1250 | GNUNET_assert(NULL != bf); | 1265 | GNUNET_assert (NULL != bf); |
1251 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1252 | "Adding myself (%s) to PUT bloomfilter for %s\n", | 1267 | "Adding myself (%s) to PUT bloomfilter for %s\n", |
1253 | GNUNET_i2s(&my_identity), | 1268 | GNUNET_i2s (&my_identity), |
1254 | GNUNET_h2s(key)); | 1269 | GNUNET_h2s (key)); |
1255 | GNUNET_CONTAINER_bloomfilter_add(bf, | 1270 | GNUNET_CONTAINER_bloomfilter_add (bf, |
1256 | &my_identity_hash); | 1271 | &my_identity_hash); |
1257 | GNUNET_STATISTICS_update(GDS_stats, | 1272 | GNUNET_STATISTICS_update (GDS_stats, |
1258 | gettext_noop("# PUT requests routed"), | 1273 | gettext_noop ("# PUT requests routed"), |
1259 | 1, | 1274 | 1, |
1260 | GNUNET_NO); | 1275 | GNUNET_NO); |
1261 | target_count | 1276 | target_count |
1262 | = get_target_peers(key, | 1277 | = get_target_peers (key, |
1263 | bf, | 1278 | bf, |
1264 | hop_count, | 1279 | hop_count, |
1265 | desired_replication_level, | 1280 | desired_replication_level, |
1266 | &targets); | 1281 | &targets); |
1267 | if (0 == target_count) | 1282 | if (0 == target_count) |
1268 | { | 1283 | { |
1269 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1270 | "Routing PUT for %s terminates after %u hops at %s\n", | 1285 | "Routing PUT for %s terminates after %u hops at %s\n", |
1271 | GNUNET_h2s(key), | 1286 | GNUNET_h2s (key), |
1272 | (unsigned int)hop_count, | 1287 | (unsigned int) hop_count, |
1273 | GNUNET_i2s(&my_identity)); | 1288 | GNUNET_i2s (&my_identity)); |
1274 | return GNUNET_NO; | 1289 | return GNUNET_NO; |
1275 | } | 1290 | } |
1276 | msize = put_path_length * sizeof(struct GNUNET_PeerIdentity) + data_size; | 1291 | msize = put_path_length * sizeof(struct GNUNET_PeerIdentity) + data_size; |
1277 | if (msize + sizeof(struct PeerPutMessage) | 1292 | if (msize + sizeof(struct PeerPutMessage) |
1278 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | 1293 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) |
1279 | { | 1294 | { |
1280 | put_path_length = 0; | 1295 | put_path_length = 0; |
1281 | msize = data_size; | 1296 | msize = data_size; |
1282 | } | 1297 | } |
1283 | if (msize + sizeof(struct PeerPutMessage) | 1298 | if (msize + sizeof(struct PeerPutMessage) |
1284 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | 1299 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) |
1285 | { | 1300 | { |
1286 | GNUNET_break(0); | 1301 | GNUNET_break (0); |
1287 | GNUNET_free(targets); | 1302 | GNUNET_free (targets); |
1288 | return GNUNET_NO; | 1303 | return GNUNET_NO; |
1289 | } | 1304 | } |
1290 | GNUNET_STATISTICS_update(GDS_stats, | 1305 | GNUNET_STATISTICS_update (GDS_stats, |
1291 | gettext_noop("# PUT messages queued for transmission"), | 1306 | gettext_noop ( |
1292 | target_count, | 1307 | "# PUT messages queued for transmission"), |
1293 | GNUNET_NO); | 1308 | target_count, |
1309 | GNUNET_NO); | ||
1294 | skip_count = 0; | 1310 | skip_count = 0; |
1295 | for (i = 0; i < target_count; i++) | 1311 | for (i = 0; i < target_count; i++) |
1312 | { | ||
1313 | target = targets[i]; | ||
1314 | if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER) | ||
1296 | { | 1315 | { |
1297 | target = targets[i]; | 1316 | /* skip */ |
1298 | if (GNUNET_MQ_get_length(target->mq) >= MAXIMUM_PENDING_PER_PEER) | 1317 | GNUNET_STATISTICS_update (GDS_stats, |
1299 | { | 1318 | gettext_noop ( |
1300 | /* skip */ | 1319 | "# P2P messages dropped due to full queue"), |
1301 | GNUNET_STATISTICS_update(GDS_stats, | 1320 | 1, |
1302 | gettext_noop("# P2P messages dropped due to full queue"), | 1321 | GNUNET_NO); |
1303 | 1, | 1322 | skip_count++; |
1304 | GNUNET_NO); | 1323 | continue; |
1305 | skip_count++; | 1324 | } |
1306 | continue; | 1325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1307 | } | 1326 | "Routing PUT for %s after %u hops to %s\n", |
1308 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1327 | GNUNET_h2s (key), |
1309 | "Routing PUT for %s after %u hops to %s\n", | 1328 | (unsigned int) hop_count, |
1310 | GNUNET_h2s(key), | 1329 | GNUNET_i2s (target->id)); |
1311 | (unsigned int)hop_count, | 1330 | env = GNUNET_MQ_msg_extra (ppm, |
1312 | GNUNET_i2s(target->id)); | 1331 | msize, |
1313 | env = GNUNET_MQ_msg_extra(ppm, | 1332 | GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); |
1314 | msize, | 1333 | ppm->options = htonl (options); |
1315 | GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); | 1334 | ppm->type = htonl (type); |
1316 | ppm->options = htonl(options); | 1335 | ppm->hop_count = htonl (hop_count + 1); |
1317 | ppm->type = htonl(type); | 1336 | ppm->desired_replication_level = htonl (desired_replication_level); |
1318 | ppm->hop_count = htonl(hop_count + 1); | 1337 | ppm->put_path_length = htonl (put_path_length); |
1319 | ppm->desired_replication_level = htonl(desired_replication_level); | 1338 | ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); |
1320 | ppm->put_path_length = htonl(put_path_length); | 1339 | GNUNET_break (GNUNET_YES == |
1321 | ppm->expiration_time = GNUNET_TIME_absolute_hton(expiration_time); | 1340 | GNUNET_CONTAINER_bloomfilter_test (bf, |
1322 | GNUNET_break(GNUNET_YES == | ||
1323 | GNUNET_CONTAINER_bloomfilter_test(bf, | ||
1324 | &target->phash)); | 1341 | &target->phash)); |
1325 | GNUNET_assert(GNUNET_OK == | 1342 | GNUNET_assert (GNUNET_OK == |
1326 | GNUNET_CONTAINER_bloomfilter_get_raw_data(bf, | 1343 | GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, |
1327 | ppm->bloomfilter, | 1344 | ppm->bloomfilter, |
1328 | DHT_BLOOM_SIZE)); | 1345 | DHT_BLOOM_SIZE)); |
1329 | ppm->key = *key; | 1346 | ppm->key = *key; |
1330 | pp = (struct GNUNET_PeerIdentity *)&ppm[1]; | 1347 | pp = (struct GNUNET_PeerIdentity *) &ppm[1]; |
1331 | GNUNET_memcpy(pp, | 1348 | GNUNET_memcpy (pp, |
1332 | put_path, | 1349 | put_path, |
1333 | sizeof(struct GNUNET_PeerIdentity) * put_path_length); | 1350 | sizeof(struct GNUNET_PeerIdentity) * put_path_length); |
1334 | GNUNET_memcpy(&pp[put_path_length], | 1351 | GNUNET_memcpy (&pp[put_path_length], |
1335 | data, | 1352 | data, |
1336 | data_size); | 1353 | data_size); |
1337 | GNUNET_MQ_send(target->mq, | 1354 | GNUNET_MQ_send (target->mq, |
1338 | env); | 1355 | env); |
1339 | } | 1356 | } |
1340 | GNUNET_free(targets); | 1357 | GNUNET_free (targets); |
1341 | return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; | 1358 | return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; |
1342 | } | 1359 | } |
1343 | 1360 | ||
@@ -1360,15 +1377,15 @@ GDS_NEIGHBOURS_handle_put(enum GNUNET_BLOCK_Type type, | |||
1360 | * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not | 1377 | * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not |
1361 | */ | 1378 | */ |
1362 | int | 1379 | int |
1363 | GDS_NEIGHBOURS_handle_get(enum GNUNET_BLOCK_Type type, | 1380 | GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, |
1364 | enum GNUNET_DHT_RouteOption options, | 1381 | enum GNUNET_DHT_RouteOption options, |
1365 | uint32_t desired_replication_level, | 1382 | uint32_t desired_replication_level, |
1366 | uint32_t hop_count, | 1383 | uint32_t hop_count, |
1367 | const struct GNUNET_HashCode *key, | 1384 | const struct GNUNET_HashCode *key, |
1368 | const void *xquery, | 1385 | const void *xquery, |
1369 | size_t xquery_size, | 1386 | size_t xquery_size, |
1370 | struct GNUNET_BLOCK_Group *bg, | 1387 | struct GNUNET_BLOCK_Group *bg, |
1371 | struct GNUNET_CONTAINER_BloomFilter *peer_bf) | 1388 | struct GNUNET_CONTAINER_BloomFilter *peer_bf) |
1372 | { | 1389 | { |
1373 | unsigned int target_count; | 1390 | unsigned int target_count; |
1374 | struct PeerInfo **targets; | 1391 | struct PeerInfo **targets; |
@@ -1382,102 +1399,104 @@ GDS_NEIGHBOURS_handle_get(enum GNUNET_BLOCK_Type type, | |||
1382 | unsigned int skip_count; | 1399 | unsigned int skip_count; |
1383 | uint32_t bf_nonce; | 1400 | uint32_t bf_nonce; |
1384 | 1401 | ||
1385 | GNUNET_assert(NULL != peer_bf); | 1402 | GNUNET_assert (NULL != peer_bf); |
1386 | GNUNET_STATISTICS_update(GDS_stats, | 1403 | GNUNET_STATISTICS_update (GDS_stats, |
1387 | gettext_noop("# GET requests routed"), | 1404 | gettext_noop ("# GET requests routed"), |
1388 | 1, | 1405 | 1, |
1389 | GNUNET_NO); | 1406 | GNUNET_NO); |
1390 | target_count = get_target_peers(key, | 1407 | target_count = get_target_peers (key, |
1391 | peer_bf, | 1408 | peer_bf, |
1392 | hop_count, | 1409 | hop_count, |
1393 | desired_replication_level, | 1410 | desired_replication_level, |
1394 | &targets); | 1411 | &targets); |
1395 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1396 | "Adding myself (%s) to GET bloomfilter for %s\n", | 1413 | "Adding myself (%s) to GET bloomfilter for %s\n", |
1397 | GNUNET_i2s(&my_identity), | 1414 | GNUNET_i2s (&my_identity), |
1398 | GNUNET_h2s(key)); | 1415 | GNUNET_h2s (key)); |
1399 | GNUNET_CONTAINER_bloomfilter_add(peer_bf, | 1416 | GNUNET_CONTAINER_bloomfilter_add (peer_bf, |
1400 | &my_identity_hash); | 1417 | &my_identity_hash); |
1401 | if (0 == target_count) | 1418 | if (0 == target_count) |
1402 | { | 1419 | { |
1403 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1404 | "Routing GET for %s terminates after %u hops at %s\n", | 1421 | "Routing GET for %s terminates after %u hops at %s\n", |
1405 | GNUNET_h2s(key), | 1422 | GNUNET_h2s (key), |
1406 | (unsigned int)hop_count, | 1423 | (unsigned int) hop_count, |
1407 | GNUNET_i2s(&my_identity)); | 1424 | GNUNET_i2s (&my_identity)); |
1408 | return GNUNET_NO; | 1425 | return GNUNET_NO; |
1409 | } | 1426 | } |
1410 | if (GNUNET_OK != | 1427 | if (GNUNET_OK != |
1411 | GNUNET_BLOCK_group_serialize(bg, | 1428 | GNUNET_BLOCK_group_serialize (bg, |
1412 | &bf_nonce, | 1429 | &bf_nonce, |
1413 | &reply_bf, | 1430 | &reply_bf, |
1414 | &reply_bf_size)) | 1431 | &reply_bf_size)) |
1415 | { | 1432 | { |
1416 | reply_bf = NULL; | 1433 | reply_bf = NULL; |
1417 | reply_bf_size = 0; | 1434 | reply_bf_size = 0; |
1418 | bf_nonce = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 1435 | bf_nonce = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1419 | UINT32_MAX); | 1436 | UINT32_MAX); |
1420 | } | 1437 | } |
1421 | msize = xquery_size + reply_bf_size; | 1438 | msize = xquery_size + reply_bf_size; |
1422 | if (msize + sizeof(struct PeerGetMessage) >= GNUNET_MAX_MESSAGE_SIZE) | 1439 | if (msize + sizeof(struct PeerGetMessage) >= GNUNET_MAX_MESSAGE_SIZE) |
1423 | { | 1440 | { |
1424 | GNUNET_break(0); | 1441 | GNUNET_break (0); |
1425 | GNUNET_free_non_null(reply_bf); | 1442 | GNUNET_free_non_null (reply_bf); |
1426 | GNUNET_free(targets); | 1443 | GNUNET_free (targets); |
1427 | return GNUNET_NO; | 1444 | return GNUNET_NO; |
1428 | } | 1445 | } |
1429 | GNUNET_STATISTICS_update(GDS_stats, | 1446 | GNUNET_STATISTICS_update (GDS_stats, |
1430 | gettext_noop("# GET messages queued for transmission"), | 1447 | gettext_noop ( |
1431 | target_count, | 1448 | "# GET messages queued for transmission"), |
1432 | GNUNET_NO); | 1449 | target_count, |
1450 | GNUNET_NO); | ||
1433 | /* forward request */ | 1451 | /* forward request */ |
1434 | skip_count = 0; | 1452 | skip_count = 0; |
1435 | for (unsigned int i = 0; i < target_count; i++) | 1453 | for (unsigned int i = 0; i < target_count; i++) |
1454 | { | ||
1455 | target = targets[i]; | ||
1456 | if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER) | ||
1436 | { | 1457 | { |
1437 | target = targets[i]; | 1458 | /* skip */ |
1438 | if (GNUNET_MQ_get_length(target->mq) >= MAXIMUM_PENDING_PER_PEER) | 1459 | GNUNET_STATISTICS_update (GDS_stats, |
1439 | { | 1460 | gettext_noop ( |
1440 | /* skip */ | 1461 | "# P2P messages dropped due to full queue"), |
1441 | GNUNET_STATISTICS_update(GDS_stats, | 1462 | 1, GNUNET_NO); |
1442 | gettext_noop("# P2P messages dropped due to full queue"), | 1463 | skip_count++; |
1443 | 1, GNUNET_NO); | 1464 | continue; |
1444 | skip_count++; | 1465 | } |
1445 | continue; | 1466 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1446 | } | 1467 | "Routing GET for %s after %u hops to %s\n", |
1447 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1468 | GNUNET_h2s (key), |
1448 | "Routing GET for %s after %u hops to %s\n", | 1469 | (unsigned int) hop_count, |
1449 | GNUNET_h2s(key), | 1470 | GNUNET_i2s (target->id)); |
1450 | (unsigned int)hop_count, | 1471 | env = GNUNET_MQ_msg_extra (pgm, |
1451 | GNUNET_i2s(target->id)); | 1472 | msize, |
1452 | env = GNUNET_MQ_msg_extra(pgm, | 1473 | GNUNET_MESSAGE_TYPE_DHT_P2P_GET); |
1453 | msize, | 1474 | pgm->options = htonl (options); |
1454 | GNUNET_MESSAGE_TYPE_DHT_P2P_GET); | 1475 | pgm->type = htonl (type); |
1455 | pgm->options = htonl(options); | 1476 | pgm->hop_count = htonl (hop_count + 1); |
1456 | pgm->type = htonl(type); | 1477 | pgm->desired_replication_level = htonl (desired_replication_level); |
1457 | pgm->hop_count = htonl(hop_count + 1); | 1478 | pgm->xquery_size = htonl (xquery_size); |
1458 | pgm->desired_replication_level = htonl(desired_replication_level); | 1479 | pgm->bf_mutator = bf_nonce; |
1459 | pgm->xquery_size = htonl(xquery_size); | 1480 | GNUNET_break (GNUNET_YES == |
1460 | pgm->bf_mutator = bf_nonce; | 1481 | GNUNET_CONTAINER_bloomfilter_test (peer_bf, |
1461 | GNUNET_break(GNUNET_YES == | ||
1462 | GNUNET_CONTAINER_bloomfilter_test(peer_bf, | ||
1463 | &target->phash)); | 1482 | &target->phash)); |
1464 | GNUNET_assert(GNUNET_OK == | 1483 | GNUNET_assert (GNUNET_OK == |
1465 | GNUNET_CONTAINER_bloomfilter_get_raw_data(peer_bf, | 1484 | GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf, |
1466 | pgm->bloomfilter, | 1485 | pgm->bloomfilter, |
1467 | DHT_BLOOM_SIZE)); | 1486 | DHT_BLOOM_SIZE)); |
1468 | pgm->key = *key; | 1487 | pgm->key = *key; |
1469 | xq = (char *)&pgm[1]; | 1488 | xq = (char *) &pgm[1]; |
1470 | GNUNET_memcpy(xq, | 1489 | GNUNET_memcpy (xq, |
1471 | xquery, | 1490 | xquery, |
1472 | xquery_size); | 1491 | xquery_size); |
1473 | GNUNET_memcpy(&xq[xquery_size], | 1492 | GNUNET_memcpy (&xq[xquery_size], |
1474 | reply_bf, | 1493 | reply_bf, |
1475 | reply_bf_size); | 1494 | reply_bf_size); |
1476 | GNUNET_MQ_send(target->mq, | 1495 | GNUNET_MQ_send (target->mq, |
1477 | env); | 1496 | env); |
1478 | } | 1497 | } |
1479 | GNUNET_free(targets); | 1498 | GNUNET_free (targets); |
1480 | GNUNET_free_non_null(reply_bf); | 1499 | GNUNET_free_non_null (reply_bf); |
1481 | return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; | 1500 | return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; |
1482 | } | 1501 | } |
1483 | 1502 | ||
@@ -1499,16 +1518,16 @@ GDS_NEIGHBOURS_handle_get(enum GNUNET_BLOCK_Type type, | |||
1499 | * @param data_size number of bytes in @a data | 1518 | * @param data_size number of bytes in @a data |
1500 | */ | 1519 | */ |
1501 | void | 1520 | void |
1502 | GDS_NEIGHBOURS_handle_reply(const struct GNUNET_PeerIdentity *target, | 1521 | GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, |
1503 | enum GNUNET_BLOCK_Type type, | 1522 | enum GNUNET_BLOCK_Type type, |
1504 | struct GNUNET_TIME_Absolute expiration_time, | 1523 | struct GNUNET_TIME_Absolute expiration_time, |
1505 | const struct GNUNET_HashCode *key, | 1524 | const struct GNUNET_HashCode *key, |
1506 | unsigned int put_path_length, | 1525 | unsigned int put_path_length, |
1507 | const struct GNUNET_PeerIdentity *put_path, | 1526 | const struct GNUNET_PeerIdentity *put_path, |
1508 | unsigned int get_path_length, | 1527 | unsigned int get_path_length, |
1509 | const struct GNUNET_PeerIdentity *get_path, | 1528 | const struct GNUNET_PeerIdentity *get_path, |
1510 | const void *data, | 1529 | const void *data, |
1511 | size_t data_size) | 1530 | size_t data_size) |
1512 | { | 1531 | { |
1513 | struct PeerInfo *pi; | 1532 | struct PeerInfo *pi; |
1514 | struct GNUNET_MQ_Envelope *env; | 1533 | struct GNUNET_MQ_Envelope *env; |
@@ -1516,69 +1535,70 @@ GDS_NEIGHBOURS_handle_reply(const struct GNUNET_PeerIdentity *target, | |||
1516 | struct PeerResultMessage *prm; | 1535 | struct PeerResultMessage *prm; |
1517 | struct GNUNET_PeerIdentity *paths; | 1536 | struct GNUNET_PeerIdentity *paths; |
1518 | 1537 | ||
1519 | msize = data_size + (get_path_length + put_path_length) * | 1538 | msize = data_size + (get_path_length + put_path_length) |
1520 | sizeof(struct GNUNET_PeerIdentity); | 1539 | * sizeof(struct GNUNET_PeerIdentity); |
1521 | if ((msize + sizeof(struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) || | 1540 | if ((msize + sizeof(struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) || |
1522 | (get_path_length > | 1541 | (get_path_length > |
1523 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || | 1542 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || |
1524 | (put_path_length > | 1543 | (put_path_length > |
1525 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || | 1544 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || |
1526 | (data_size > GNUNET_MAX_MESSAGE_SIZE)) | 1545 | (data_size > GNUNET_MAX_MESSAGE_SIZE)) |
1527 | { | 1546 | { |
1528 | GNUNET_break(0); | 1547 | GNUNET_break (0); |
1529 | return; | 1548 | return; |
1530 | } | 1549 | } |
1531 | pi = GNUNET_CONTAINER_multipeermap_get(all_connected_peers, | 1550 | pi = GNUNET_CONTAINER_multipeermap_get (all_connected_peers, |
1532 | target); | 1551 | target); |
1533 | if (NULL == pi) | 1552 | if (NULL == pi) |
1534 | { | 1553 | { |
1535 | /* peer disconnected in the meantime, drop reply */ | 1554 | /* peer disconnected in the meantime, drop reply */ |
1536 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1555 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1537 | "No matching peer for reply for key %s\n", | 1556 | "No matching peer for reply for key %s\n", |
1538 | GNUNET_h2s(key)); | 1557 | GNUNET_h2s (key)); |
1539 | return; | 1558 | return; |
1540 | } | 1559 | } |
1541 | if (GNUNET_MQ_get_length(pi->mq) >= MAXIMUM_PENDING_PER_PEER) | 1560 | if (GNUNET_MQ_get_length (pi->mq) >= MAXIMUM_PENDING_PER_PEER) |
1542 | { | 1561 | { |
1543 | /* skip */ | 1562 | /* skip */ |
1544 | GNUNET_STATISTICS_update(GDS_stats, | 1563 | GNUNET_STATISTICS_update (GDS_stats, |
1545 | gettext_noop("# P2P messages dropped due to full queue"), | 1564 | gettext_noop ( |
1546 | 1, | 1565 | "# P2P messages dropped due to full queue"), |
1547 | GNUNET_NO); | 1566 | 1, |
1548 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1567 | GNUNET_NO); |
1549 | "Peer queue full, ignoring reply for key %s\n", | 1568 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1550 | GNUNET_h2s(key)); | 1569 | "Peer queue full, ignoring reply for key %s\n", |
1551 | return; | 1570 | GNUNET_h2s (key)); |
1552 | } | 1571 | return; |
1572 | } | ||
1553 | 1573 | ||
1554 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1574 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1555 | "Forwarding reply for key %s to peer %s\n", | 1575 | "Forwarding reply for key %s to peer %s\n", |
1556 | GNUNET_h2s(key), | 1576 | GNUNET_h2s (key), |
1557 | GNUNET_i2s(target)); | 1577 | GNUNET_i2s (target)); |
1558 | GNUNET_STATISTICS_update(GDS_stats, | 1578 | GNUNET_STATISTICS_update (GDS_stats, |
1559 | gettext_noop | 1579 | gettext_noop |
1560 | ("# RESULT messages queued for transmission"), 1, | 1580 | ("# RESULT messages queued for transmission"), 1, |
1561 | GNUNET_NO); | 1581 | GNUNET_NO); |
1562 | env = GNUNET_MQ_msg_extra(prm, | 1582 | env = GNUNET_MQ_msg_extra (prm, |
1563 | msize, | 1583 | msize, |
1564 | GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT); | 1584 | GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT); |
1565 | prm->type = htonl(type); | 1585 | prm->type = htonl (type); |
1566 | prm->put_path_length = htonl(put_path_length); | 1586 | prm->put_path_length = htonl (put_path_length); |
1567 | prm->get_path_length = htonl(get_path_length); | 1587 | prm->get_path_length = htonl (get_path_length); |
1568 | prm->expiration_time = GNUNET_TIME_absolute_hton(expiration_time); | 1588 | prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); |
1569 | prm->key = *key; | 1589 | prm->key = *key; |
1570 | paths = (struct GNUNET_PeerIdentity *)&prm[1]; | 1590 | paths = (struct GNUNET_PeerIdentity *) &prm[1]; |
1571 | GNUNET_memcpy(paths, | 1591 | GNUNET_memcpy (paths, |
1572 | put_path, | 1592 | put_path, |
1573 | put_path_length * sizeof(struct GNUNET_PeerIdentity)); | 1593 | put_path_length * sizeof(struct GNUNET_PeerIdentity)); |
1574 | GNUNET_memcpy(&paths[put_path_length], | 1594 | GNUNET_memcpy (&paths[put_path_length], |
1575 | get_path, | 1595 | get_path, |
1576 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); | 1596 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); |
1577 | GNUNET_memcpy(&paths[put_path_length + get_path_length], | 1597 | GNUNET_memcpy (&paths[put_path_length + get_path_length], |
1578 | data, | 1598 | data, |
1579 | data_size); | 1599 | data_size); |
1580 | GNUNET_MQ_send(pi->mq, | 1600 | GNUNET_MQ_send (pi->mq, |
1581 | env); | 1601 | env); |
1582 | } | 1602 | } |
1583 | 1603 | ||
1584 | 1604 | ||
@@ -1589,18 +1609,18 @@ GDS_NEIGHBOURS_handle_reply(const struct GNUNET_PeerIdentity *target, | |||
1589 | * @param identity the public identity of this peer | 1609 | * @param identity the public identity of this peer |
1590 | */ | 1610 | */ |
1591 | static void | 1611 | static void |
1592 | core_init(void *cls, | 1612 | core_init (void *cls, |
1593 | const struct GNUNET_PeerIdentity *identity) | 1613 | const struct GNUNET_PeerIdentity *identity) |
1594 | { | 1614 | { |
1595 | (void)cls; | 1615 | (void) cls; |
1596 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1616 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1597 | "CORE called, I am %s\n", | 1617 | "CORE called, I am %s\n", |
1598 | GNUNET_i2s(identity)); | 1618 | GNUNET_i2s (identity)); |
1599 | my_identity = *identity; | 1619 | my_identity = *identity; |
1600 | GNUNET_CRYPTO_hash(identity, | 1620 | GNUNET_CRYPTO_hash (identity, |
1601 | sizeof(struct GNUNET_PeerIdentity), | 1621 | sizeof(struct GNUNET_PeerIdentity), |
1602 | &my_identity_hash); | 1622 | &my_identity_hash); |
1603 | GNUNET_SERVICE_resume(GDS_service); | 1623 | GNUNET_SERVICE_resume (GDS_service); |
1604 | } | 1624 | } |
1605 | 1625 | ||
1606 | 1626 | ||
@@ -1612,24 +1632,24 @@ core_init(void *cls, | |||
1612 | * @return #GNUNET_OK if the message is valid | 1632 | * @return #GNUNET_OK if the message is valid |
1613 | */ | 1633 | */ |
1614 | static int | 1634 | static int |
1615 | check_dht_p2p_put(void *cls, | 1635 | check_dht_p2p_put (void *cls, |
1616 | const struct PeerPutMessage *put) | 1636 | const struct PeerPutMessage *put) |
1617 | { | 1637 | { |
1618 | uint32_t putlen; | 1638 | uint32_t putlen; |
1619 | uint16_t msize; | 1639 | uint16_t msize; |
1620 | 1640 | ||
1621 | (void)cls; | 1641 | (void) cls; |
1622 | msize = ntohs(put->header.size); | 1642 | msize = ntohs (put->header.size); |
1623 | putlen = ntohl(put->put_path_length); | 1643 | putlen = ntohl (put->put_path_length); |
1624 | if ((msize < | 1644 | if ((msize < |
1625 | sizeof(struct PeerPutMessage) + | 1645 | sizeof(struct PeerPutMessage) |
1626 | putlen * sizeof(struct GNUNET_PeerIdentity)) || | 1646 | + putlen * sizeof(struct GNUNET_PeerIdentity)) || |
1627 | (putlen > | 1647 | (putlen > |
1628 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity))) | 1648 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity))) |
1629 | { | 1649 | { |
1630 | GNUNET_break_op(0); | 1650 | GNUNET_break_op (0); |
1631 | return GNUNET_SYSERR; | 1651 | return GNUNET_SYSERR; |
1632 | } | 1652 | } |
1633 | return GNUNET_OK; | 1653 | return GNUNET_OK; |
1634 | } | 1654 | } |
1635 | 1655 | ||
@@ -1641,8 +1661,8 @@ check_dht_p2p_put(void *cls, | |||
1641 | * @param message message | 1661 | * @param message message |
1642 | */ | 1662 | */ |
1643 | static void | 1663 | static void |
1644 | handle_dht_p2p_put(void *cls, | 1664 | handle_dht_p2p_put (void *cls, |
1645 | const struct PeerPutMessage *put) | 1665 | const struct PeerPutMessage *put) |
1646 | { | 1666 | { |
1647 | struct PeerInfo *peer = cls; | 1667 | struct PeerInfo *peer = cls; |
1648 | const struct GNUNET_PeerIdentity *put_path; | 1668 | const struct GNUNET_PeerIdentity *put_path; |
@@ -1656,198 +1676,199 @@ handle_dht_p2p_put(void *cls, | |||
1656 | int forwarded; | 1676 | int forwarded; |
1657 | struct GNUNET_TIME_Absolute exp_time; | 1677 | struct GNUNET_TIME_Absolute exp_time; |
1658 | 1678 | ||
1659 | exp_time = GNUNET_TIME_absolute_ntoh(put->expiration_time); | 1679 | exp_time = GNUNET_TIME_absolute_ntoh (put->expiration_time); |
1660 | if (0 == GNUNET_TIME_absolute_get_remaining(exp_time).rel_value_us) | 1680 | if (0 == GNUNET_TIME_absolute_get_remaining (exp_time).rel_value_us) |
1661 | { | 1681 | { |
1662 | GNUNET_STATISTICS_update(GDS_stats, | 1682 | GNUNET_STATISTICS_update (GDS_stats, |
1663 | gettext_noop("# Expired PUTs discarded"), | 1683 | gettext_noop ("# Expired PUTs discarded"), |
1664 | 1, | 1684 | 1, |
1665 | GNUNET_NO); | 1685 | GNUNET_NO); |
1666 | return; | 1686 | return; |
1667 | } | 1687 | } |
1668 | msize = ntohs(put->header.size); | 1688 | msize = ntohs (put->header.size); |
1669 | putlen = ntohl(put->put_path_length); | 1689 | putlen = ntohl (put->put_path_length); |
1670 | GNUNET_STATISTICS_update(GDS_stats, | 1690 | GNUNET_STATISTICS_update (GDS_stats, |
1671 | gettext_noop("# P2P PUT requests received"), | 1691 | gettext_noop ("# P2P PUT requests received"), |
1672 | 1, | 1692 | 1, |
1673 | GNUNET_NO); | 1693 | GNUNET_NO); |
1674 | GNUNET_STATISTICS_update(GDS_stats, | 1694 | GNUNET_STATISTICS_update (GDS_stats, |
1675 | gettext_noop("# P2P PUT bytes received"), | 1695 | gettext_noop ("# P2P PUT bytes received"), |
1676 | msize, | 1696 | msize, |
1677 | GNUNET_NO); | 1697 | GNUNET_NO); |
1678 | put_path = (const struct GNUNET_PeerIdentity *)&put[1]; | 1698 | put_path = (const struct GNUNET_PeerIdentity *) &put[1]; |
1679 | payload = &put_path[putlen]; | 1699 | payload = &put_path[putlen]; |
1680 | options = ntohl(put->options); | 1700 | options = ntohl (put->options); |
1681 | payload_size = msize - (sizeof(struct PeerPutMessage) + | 1701 | payload_size = msize - (sizeof(struct PeerPutMessage) |
1682 | putlen * sizeof(struct GNUNET_PeerIdentity)); | 1702 | + putlen * sizeof(struct GNUNET_PeerIdentity)); |
1683 | 1703 | ||
1684 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1704 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1685 | "PUT for `%s' from %s\n", | 1705 | "PUT for `%s' from %s\n", |
1686 | GNUNET_h2s(&put->key), | 1706 | GNUNET_h2s (&put->key), |
1687 | GNUNET_i2s(peer->id)); | 1707 | GNUNET_i2s (peer->id)); |
1688 | if (GNUNET_YES == log_route_details_stderr) | 1708 | if (GNUNET_YES == log_route_details_stderr) |
1689 | { | 1709 | { |
1690 | char *tmp; | 1710 | char *tmp; |
1691 | char *pp; | 1711 | char *pp; |
1692 | 1712 | ||
1693 | pp = GNUNET_STRINGS_pp2s(put_path, | 1713 | pp = GNUNET_STRINGS_pp2s (put_path, |
1694 | putlen); | 1714 | putlen); |
1695 | tmp = GNUNET_strdup(GNUNET_i2s(&my_identity)); | 1715 | tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); |
1696 | LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG, | 1716 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, |
1697 | "R5N PUT %s: %s->%s (%u, %u=>%u, PP: %s)\n", | 1717 | "R5N PUT %s: %s->%s (%u, %u=>%u, PP: %s)\n", |
1698 | GNUNET_h2s(&put->key), | 1718 | GNUNET_h2s (&put->key), |
1699 | GNUNET_i2s(peer->id), | 1719 | GNUNET_i2s (peer->id), |
1700 | tmp, | 1720 | tmp, |
1701 | ntohl(put->hop_count), | 1721 | ntohl (put->hop_count), |
1702 | GNUNET_CRYPTO_hash_matching_bits(&peer->phash, | 1722 | GNUNET_CRYPTO_hash_matching_bits (&peer->phash, |
1703 | &put->key), | 1723 | &put->key), |
1704 | GNUNET_CRYPTO_hash_matching_bits(&my_identity_hash, | 1724 | GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, |
1705 | &put->key), | 1725 | &put->key), |
1706 | pp); | 1726 | pp); |
1707 | GNUNET_free(pp); | 1727 | GNUNET_free (pp); |
1708 | GNUNET_free(tmp); | 1728 | GNUNET_free (tmp); |
1709 | } | 1729 | } |
1710 | switch (GNUNET_BLOCK_get_key | 1730 | switch (GNUNET_BLOCK_get_key |
1711 | (GDS_block_context, | 1731 | (GDS_block_context, |
1712 | ntohl(put->type), | 1732 | ntohl (put->type), |
1713 | payload, | 1733 | payload, |
1714 | payload_size, | 1734 | payload_size, |
1715 | &test_key)) | 1735 | &test_key)) |
1736 | { | ||
1737 | case GNUNET_YES: | ||
1738 | if (0 != memcmp (&test_key, | ||
1739 | &put->key, | ||
1740 | sizeof(struct GNUNET_HashCode))) | ||
1716 | { | 1741 | { |
1717 | case GNUNET_YES: | 1742 | char *put_s = GNUNET_strdup (GNUNET_h2s_full (&put->key)); |
1718 | if (0 != memcmp(&test_key, | 1743 | |
1719 | &put->key, | 1744 | GNUNET_break_op (0); |
1720 | sizeof(struct GNUNET_HashCode))) | 1745 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1721 | { | 1746 | "PUT with key `%s' for block with key %s\n", |
1722 | char *put_s = GNUNET_strdup(GNUNET_h2s_full(&put->key)); | 1747 | put_s, |
1723 | 1748 | GNUNET_h2s_full (&test_key)); | |
1724 | GNUNET_break_op(0); | 1749 | GNUNET_free (put_s); |
1725 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
1726 | "PUT with key `%s' for block with key %s\n", | ||
1727 | put_s, | ||
1728 | GNUNET_h2s_full(&test_key)); | ||
1729 | GNUNET_free(put_s); | ||
1730 | return; | ||
1731 | } | ||
1732 | break; | ||
1733 | |||
1734 | case GNUNET_NO: | ||
1735 | GNUNET_break_op(0); | ||
1736 | return; | 1750 | return; |
1737 | |||
1738 | case GNUNET_SYSERR: | ||
1739 | /* cannot verify, good luck */ | ||
1740 | break; | ||
1741 | } | 1751 | } |
1742 | if (ntohl(put->type) == GNUNET_BLOCK_TYPE_REGEX) /* FIXME: do for all tpyes */ | 1752 | break; |
1753 | |||
1754 | case GNUNET_NO: | ||
1755 | GNUNET_break_op (0); | ||
1756 | return; | ||
1757 | |||
1758 | case GNUNET_SYSERR: | ||
1759 | /* cannot verify, good luck */ | ||
1760 | break; | ||
1761 | } | ||
1762 | if (ntohl (put->type) == GNUNET_BLOCK_TYPE_REGEX) /* FIXME: do for all tpyes */ | ||
1763 | { | ||
1764 | switch (GNUNET_BLOCK_evaluate (GDS_block_context, | ||
1765 | ntohl (put->type), | ||
1766 | NULL, /* query group */ | ||
1767 | GNUNET_BLOCK_EO_NONE, | ||
1768 | NULL, /* query */ | ||
1769 | NULL, 0, /* xquery */ | ||
1770 | payload, | ||
1771 | payload_size)) | ||
1743 | { | 1772 | { |
1744 | switch (GNUNET_BLOCK_evaluate(GDS_block_context, | 1773 | case GNUNET_BLOCK_EVALUATION_OK_MORE: |
1745 | ntohl(put->type), | 1774 | case GNUNET_BLOCK_EVALUATION_OK_LAST: |
1746 | NULL, /* query group */ | 1775 | break; |
1747 | GNUNET_BLOCK_EO_NONE, | 1776 | |
1748 | NULL, /* query */ | 1777 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: |
1749 | NULL, 0, /* xquery */ | 1778 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: |
1750 | payload, | 1779 | case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: |
1751 | payload_size)) | 1780 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: |
1752 | { | 1781 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: |
1753 | case GNUNET_BLOCK_EVALUATION_OK_MORE: | 1782 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: |
1754 | case GNUNET_BLOCK_EVALUATION_OK_LAST: | 1783 | default: |
1755 | break; | 1784 | GNUNET_break_op (0); |
1756 | 1785 | return; | |
1757 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: | ||
1758 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: | ||
1759 | case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: | ||
1760 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: | ||
1761 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: | ||
1762 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: | ||
1763 | default: | ||
1764 | GNUNET_break_op(0); | ||
1765 | return; | ||
1766 | } | ||
1767 | } | 1786 | } |
1787 | } | ||
1768 | 1788 | ||
1769 | bf = GNUNET_CONTAINER_bloomfilter_init(put->bloomfilter, | 1789 | bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, |
1770 | DHT_BLOOM_SIZE, | 1790 | DHT_BLOOM_SIZE, |
1771 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 1791 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
1772 | GNUNET_break_op(GNUNET_YES == | 1792 | GNUNET_break_op (GNUNET_YES == |
1773 | GNUNET_CONTAINER_bloomfilter_test(bf, | 1793 | GNUNET_CONTAINER_bloomfilter_test (bf, |
1774 | &peer->phash)); | 1794 | &peer->phash)); |
1775 | { | 1795 | { |
1776 | struct GNUNET_PeerIdentity pp[putlen + 1]; | 1796 | struct GNUNET_PeerIdentity pp[putlen + 1]; |
1777 | 1797 | ||
1778 | /* extend 'put path' by sender */ | 1798 | /* extend 'put path' by sender */ |
1779 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) | 1799 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) |
1780 | { | 1800 | { |
1781 | #if SANITY_CHECKS | 1801 | #if SANITY_CHECKS |
1782 | for (unsigned int i = 0; i <= putlen; i++) | 1802 | for (unsigned int i = 0; i <= putlen; i++) |
1783 | { | 1803 | { |
1784 | for (unsigned int j = 0; j < i; j++) | 1804 | for (unsigned int j = 0; j < i; j++) |
1785 | { | 1805 | { |
1786 | GNUNET_break(0 != memcmp(&pp[i], | 1806 | GNUNET_break (0 != memcmp (&pp[i], |
1787 | &pp[j], | 1807 | &pp[j], |
1788 | sizeof(struct GNUNET_PeerIdentity))); | ||
1789 | } | ||
1790 | GNUNET_break(0 != memcmp(&pp[i], | ||
1791 | peer->id, | ||
1792 | sizeof(struct GNUNET_PeerIdentity))); | 1808 | sizeof(struct GNUNET_PeerIdentity))); |
1793 | } | 1809 | } |
1794 | #endif | 1810 | GNUNET_break (0 != memcmp (&pp[i], |
1795 | GNUNET_memcpy(pp, | 1811 | peer->id, |
1796 | put_path, | 1812 | sizeof(struct GNUNET_PeerIdentity))); |
1797 | putlen * sizeof(struct GNUNET_PeerIdentity)); | ||
1798 | pp[putlen] = *peer->id; | ||
1799 | putlen++; | ||
1800 | } | 1813 | } |
1814 | #endif | ||
1815 | GNUNET_memcpy (pp, | ||
1816 | put_path, | ||
1817 | putlen * sizeof(struct GNUNET_PeerIdentity)); | ||
1818 | pp[putlen] = *peer->id; | ||
1819 | putlen++; | ||
1820 | } | ||
1801 | else | 1821 | else |
1802 | putlen = 0; | 1822 | putlen = 0; |
1803 | 1823 | ||
1804 | /* give to local clients */ | 1824 | /* give to local clients */ |
1805 | GDS_CLIENTS_handle_reply(exp_time, | 1825 | GDS_CLIENTS_handle_reply (exp_time, |
1806 | &put->key, | 1826 | &put->key, |
1807 | 0, | 1827 | 0, |
1808 | NULL, | 1828 | NULL, |
1809 | putlen, | 1829 | putlen, |
1810 | pp, | 1830 | pp, |
1811 | ntohl(put->type), | 1831 | ntohl (put->type), |
1812 | payload_size, | 1832 | payload_size, |
1813 | payload); | 1833 | payload); |
1814 | /* store locally */ | 1834 | /* store locally */ |
1815 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || | 1835 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || |
1816 | (GDS_am_closest_peer(&put->key, bf))) | 1836 | (GDS_am_closest_peer (&put->key, bf))) |
1817 | GDS_DATACACHE_handle_put(exp_time, | 1837 | GDS_DATACACHE_handle_put (exp_time, |
1818 | &put->key, | 1838 | &put->key, |
1819 | putlen, | 1839 | putlen, |
1820 | pp, | 1840 | pp, |
1821 | ntohl(put->type), | 1841 | ntohl (put->type), |
1822 | payload_size, | 1842 | payload_size, |
1823 | payload); | 1843 | payload); |
1824 | /* route to other peers */ | 1844 | /* route to other peers */ |
1825 | forwarded = GDS_NEIGHBOURS_handle_put(ntohl(put->type), | 1845 | forwarded = GDS_NEIGHBOURS_handle_put (ntohl (put->type), |
1826 | options, | 1846 | options, |
1827 | ntohl(put->desired_replication_level), | 1847 | ntohl ( |
1828 | exp_time, | 1848 | put->desired_replication_level), |
1829 | ntohl(put->hop_count), | 1849 | exp_time, |
1830 | bf, | 1850 | ntohl (put->hop_count), |
1831 | &put->key, | 1851 | bf, |
1832 | putlen, | 1852 | &put->key, |
1833 | pp, | 1853 | putlen, |
1834 | payload, | 1854 | pp, |
1835 | payload_size); | 1855 | payload, |
1856 | payload_size); | ||
1836 | /* notify monitoring clients */ | 1857 | /* notify monitoring clients */ |
1837 | GDS_CLIENTS_process_put(options | 1858 | GDS_CLIENTS_process_put (options |
1838 | | ((GNUNET_OK == forwarded) | 1859 | | ((GNUNET_OK == forwarded) |
1839 | ? GNUNET_DHT_RO_LAST_HOP | 1860 | ? GNUNET_DHT_RO_LAST_HOP |
1840 | : 0), | 1861 | : 0), |
1841 | ntohl(put->type), | 1862 | ntohl (put->type), |
1842 | ntohl(put->hop_count), | 1863 | ntohl (put->hop_count), |
1843 | ntohl(put->desired_replication_level), | 1864 | ntohl (put->desired_replication_level), |
1844 | putlen, pp, | 1865 | putlen, pp, |
1845 | exp_time, | 1866 | exp_time, |
1846 | &put->key, | 1867 | &put->key, |
1847 | payload, | 1868 | payload, |
1848 | payload_size); | 1869 | payload_size); |
1849 | } | 1870 | } |
1850 | GNUNET_CONTAINER_bloomfilter_free(bf); | 1871 | GNUNET_CONTAINER_bloomfilter_free (bf); |
1851 | } | 1872 | } |
1852 | 1873 | ||
1853 | 1874 | ||
@@ -1860,9 +1881,9 @@ handle_dht_p2p_put(void *cls, | |||
1860 | * @param bg group for filtering peers | 1881 | * @param bg group for filtering peers |
1861 | */ | 1882 | */ |
1862 | static void | 1883 | static void |
1863 | handle_find_peer(const struct GNUNET_PeerIdentity *sender, | 1884 | handle_find_peer (const struct GNUNET_PeerIdentity *sender, |
1864 | const struct GNUNET_HashCode *key, | 1885 | const struct GNUNET_HashCode *key, |
1865 | struct GNUNET_BLOCK_Group *bg) | 1886 | struct GNUNET_BLOCK_Group *bg) |
1866 | { | 1887 | { |
1867 | int bucket_idx; | 1888 | int bucket_idx; |
1868 | struct PeerBucket *bucket; | 1889 | struct PeerBucket *bucket; |
@@ -1873,99 +1894,103 @@ handle_find_peer(const struct GNUNET_PeerIdentity *sender, | |||
1873 | 1894 | ||
1874 | /* first, check about our own HELLO */ | 1895 | /* first, check about our own HELLO */ |
1875 | if (NULL != GDS_my_hello) | 1896 | if (NULL != GDS_my_hello) |
1897 | { | ||
1898 | hello_size = GNUNET_HELLO_size ((const struct | ||
1899 | GNUNET_HELLO_Message *) GDS_my_hello); | ||
1900 | GNUNET_break (hello_size >= sizeof(struct GNUNET_MessageHeader)); | ||
1901 | if (GNUNET_BLOCK_EVALUATION_OK_MORE == | ||
1902 | GNUNET_BLOCK_evaluate (GDS_block_context, | ||
1903 | GNUNET_BLOCK_TYPE_DHT_HELLO, | ||
1904 | bg, | ||
1905 | GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, | ||
1906 | &my_identity_hash, | ||
1907 | NULL, 0, | ||
1908 | GDS_my_hello, | ||
1909 | hello_size)) | ||
1876 | { | 1910 | { |
1877 | hello_size = GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)GDS_my_hello); | 1911 | GDS_NEIGHBOURS_handle_reply (sender, |
1878 | GNUNET_break(hello_size >= sizeof(struct GNUNET_MessageHeader)); | 1912 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
1879 | if (GNUNET_BLOCK_EVALUATION_OK_MORE == | 1913 | GNUNET_TIME_relative_to_absolute ( |
1880 | GNUNET_BLOCK_evaluate(GDS_block_context, | 1914 | hello_expiration), |
1881 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 1915 | key, |
1882 | bg, | 1916 | 0, |
1883 | GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, | 1917 | NULL, |
1884 | &my_identity_hash, | 1918 | 0, |
1885 | NULL, 0, | 1919 | NULL, |
1886 | GDS_my_hello, | 1920 | GDS_my_hello, |
1887 | hello_size)) | 1921 | hello_size); |
1888 | { | ||
1889 | GDS_NEIGHBOURS_handle_reply(sender, | ||
1890 | GNUNET_BLOCK_TYPE_DHT_HELLO, | ||
1891 | GNUNET_TIME_relative_to_absolute(hello_expiration), | ||
1892 | key, | ||
1893 | 0, | ||
1894 | NULL, | ||
1895 | 0, | ||
1896 | NULL, | ||
1897 | GDS_my_hello, | ||
1898 | hello_size); | ||
1899 | } | ||
1900 | else | ||
1901 | { | ||
1902 | GNUNET_STATISTICS_update(GDS_stats, | ||
1903 | gettext_noop("# FIND PEER requests ignored due to Bloomfilter"), | ||
1904 | 1, | ||
1905 | GNUNET_NO); | ||
1906 | } | ||
1907 | } | 1922 | } |
1908 | else | 1923 | else |
1909 | { | 1924 | { |
1910 | GNUNET_STATISTICS_update(GDS_stats, | 1925 | GNUNET_STATISTICS_update (GDS_stats, |
1911 | gettext_noop("# FIND PEER requests ignored due to lack of HELLO"), | 1926 | gettext_noop ( |
1912 | 1, | 1927 | "# FIND PEER requests ignored due to Bloomfilter"), |
1913 | GNUNET_NO); | 1928 | 1, |
1929 | GNUNET_NO); | ||
1914 | } | 1930 | } |
1931 | } | ||
1932 | else | ||
1933 | { | ||
1934 | GNUNET_STATISTICS_update (GDS_stats, | ||
1935 | gettext_noop ( | ||
1936 | "# FIND PEER requests ignored due to lack of HELLO"), | ||
1937 | 1, | ||
1938 | GNUNET_NO); | ||
1939 | } | ||
1915 | 1940 | ||
1916 | /* then, also consider sending a random HELLO from the closest bucket */ | 1941 | /* then, also consider sending a random HELLO from the closest bucket */ |
1917 | if (0 == memcmp(&my_identity_hash, | 1942 | if (0 == memcmp (&my_identity_hash, |
1918 | key, | 1943 | key, |
1919 | sizeof(struct GNUNET_HashCode))) | 1944 | sizeof(struct GNUNET_HashCode))) |
1920 | bucket_idx = closest_bucket; | 1945 | bucket_idx = closest_bucket; |
1921 | else | 1946 | else |
1922 | bucket_idx = GNUNET_MIN((int)closest_bucket, | 1947 | bucket_idx = GNUNET_MIN ((int) closest_bucket, |
1923 | find_bucket(key)); | 1948 | find_bucket (key)); |
1924 | if (bucket_idx < 0) | 1949 | if (bucket_idx < 0) |
1925 | return; | 1950 | return; |
1926 | bucket = &k_buckets[bucket_idx]; | 1951 | bucket = &k_buckets[bucket_idx]; |
1927 | if (bucket->peers_size == 0) | 1952 | if (bucket->peers_size == 0) |
1928 | return; | 1953 | return; |
1929 | choice = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 1954 | choice = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1930 | bucket->peers_size); | 1955 | bucket->peers_size); |
1931 | peer = bucket->head; | 1956 | peer = bucket->head; |
1932 | while (choice > 0) | 1957 | while (choice > 0) |
1933 | { | 1958 | { |
1934 | GNUNET_assert(NULL != peer); | 1959 | GNUNET_assert (NULL != peer); |
1935 | peer = peer->next; | 1960 | peer = peer->next; |
1936 | choice--; | 1961 | choice--; |
1937 | } | 1962 | } |
1938 | choice = bucket->peers_size; | 1963 | choice = bucket->peers_size; |
1939 | do | 1964 | do |
1940 | { | 1965 | { |
1941 | peer = peer->next; | 1966 | peer = peer->next; |
1942 | if (0 == choice--) | 1967 | if (0 == choice--) |
1943 | return; /* no non-masked peer available */ | 1968 | return; /* no non-masked peer available */ |
1944 | if (NULL == peer) | 1969 | if (NULL == peer) |
1945 | peer = bucket->head; | 1970 | peer = bucket->head; |
1946 | hello = GDS_HELLO_get(peer->id); | 1971 | hello = GDS_HELLO_get (peer->id); |
1947 | } | 1972 | } |
1948 | while ((NULL == hello) || | 1973 | while ((NULL == hello) || |
1949 | (GNUNET_BLOCK_EVALUATION_OK_MORE != | 1974 | (GNUNET_BLOCK_EVALUATION_OK_MORE != |
1950 | GNUNET_BLOCK_evaluate(GDS_block_context, | 1975 | GNUNET_BLOCK_evaluate (GDS_block_context, |
1951 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 1976 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
1952 | bg, | 1977 | bg, |
1953 | GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, | 1978 | GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, |
1954 | &peer->phash, | 1979 | &peer->phash, |
1955 | NULL, 0, | 1980 | NULL, 0, |
1956 | hello, | 1981 | hello, |
1957 | (hello_size = GNUNET_HELLO_size(hello))))); | 1982 | (hello_size = GNUNET_HELLO_size (hello))))); |
1958 | GDS_NEIGHBOURS_handle_reply(sender, | 1983 | GDS_NEIGHBOURS_handle_reply (sender, |
1959 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 1984 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
1960 | GNUNET_TIME_relative_to_absolute | 1985 | GNUNET_TIME_relative_to_absolute |
1961 | (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), | 1986 | (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), |
1962 | key, | 1987 | key, |
1963 | 0, | 1988 | 0, |
1964 | NULL, | 1989 | NULL, |
1965 | 0, | 1990 | 0, |
1966 | NULL, | 1991 | NULL, |
1967 | hello, | 1992 | hello, |
1968 | hello_size); | 1993 | hello_size); |
1969 | } | 1994 | } |
1970 | 1995 | ||
1971 | 1996 | ||
@@ -1984,34 +2009,34 @@ handle_find_peer(const struct GNUNET_PeerIdentity *sender, | |||
1984 | * @param data_size number of bytes in @a data | 2009 | * @param data_size number of bytes in @a data |
1985 | */ | 2010 | */ |
1986 | static void | 2011 | static void |
1987 | handle_local_result(void *cls, | 2012 | handle_local_result (void *cls, |
1988 | enum GNUNET_BLOCK_Type type, | 2013 | enum GNUNET_BLOCK_Type type, |
1989 | struct GNUNET_TIME_Absolute expiration_time, | 2014 | struct GNUNET_TIME_Absolute expiration_time, |
1990 | const struct GNUNET_HashCode *key, | 2015 | const struct GNUNET_HashCode *key, |
1991 | unsigned int put_path_length, | 2016 | unsigned int put_path_length, |
1992 | const struct GNUNET_PeerIdentity *put_path, | 2017 | const struct GNUNET_PeerIdentity *put_path, |
1993 | unsigned int get_path_length, | 2018 | unsigned int get_path_length, |
1994 | const struct GNUNET_PeerIdentity *get_path, | 2019 | const struct GNUNET_PeerIdentity *get_path, |
1995 | const void *data, | 2020 | const void *data, |
1996 | size_t data_size) | 2021 | size_t data_size) |
1997 | { | 2022 | { |
1998 | struct PeerInfo *peer = cls; | 2023 | struct PeerInfo *peer = cls; |
1999 | char *pp; | 2024 | char *pp; |
2000 | 2025 | ||
2001 | pp = GNUNET_STRINGS_pp2s(put_path, | 2026 | pp = GNUNET_STRINGS_pp2s (put_path, |
2002 | put_path_length); | 2027 | put_path_length); |
2003 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2028 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2004 | "Found local result for %s (PP: %s)\n", | 2029 | "Found local result for %s (PP: %s)\n", |
2005 | GNUNET_h2s(key), | 2030 | GNUNET_h2s (key), |
2006 | pp); | 2031 | pp); |
2007 | GNUNET_free(pp); | 2032 | GNUNET_free (pp); |
2008 | GDS_NEIGHBOURS_handle_reply(peer->id, | 2033 | GDS_NEIGHBOURS_handle_reply (peer->id, |
2009 | type, | 2034 | type, |
2010 | expiration_time, | 2035 | expiration_time, |
2011 | key, | 2036 | key, |
2012 | put_path_length, put_path, | 2037 | put_path_length, put_path, |
2013 | get_path_length, get_path, | 2038 | get_path_length, get_path, |
2014 | data, data_size); | 2039 | data, data_size); |
2015 | } | 2040 | } |
2016 | 2041 | ||
2017 | 2042 | ||
@@ -2023,20 +2048,20 @@ handle_local_result(void *cls, | |||
2023 | * @return #GNUNET_OK if the message is well-formed | 2048 | * @return #GNUNET_OK if the message is well-formed |
2024 | */ | 2049 | */ |
2025 | static int | 2050 | static int |
2026 | check_dht_p2p_get(void *cls, | 2051 | check_dht_p2p_get (void *cls, |
2027 | const struct PeerGetMessage *get) | 2052 | const struct PeerGetMessage *get) |
2028 | { | 2053 | { |
2029 | uint32_t xquery_size; | 2054 | uint32_t xquery_size; |
2030 | uint16_t msize; | 2055 | uint16_t msize; |
2031 | 2056 | ||
2032 | (void)cls; | 2057 | (void) cls; |
2033 | msize = ntohs(get->header.size); | 2058 | msize = ntohs (get->header.size); |
2034 | xquery_size = ntohl(get->xquery_size); | 2059 | xquery_size = ntohl (get->xquery_size); |
2035 | if (msize < sizeof(struct PeerGetMessage) + xquery_size) | 2060 | if (msize < sizeof(struct PeerGetMessage) + xquery_size) |
2036 | { | 2061 | { |
2037 | GNUNET_break_op(0); | 2062 | GNUNET_break_op (0); |
2038 | return GNUNET_SYSERR; | 2063 | return GNUNET_SYSERR; |
2039 | } | 2064 | } |
2040 | return GNUNET_OK; | 2065 | return GNUNET_OK; |
2041 | } | 2066 | } |
2042 | 2067 | ||
@@ -2048,8 +2073,8 @@ check_dht_p2p_get(void *cls, | |||
2048 | * @param get the message | 2073 | * @param get the message |
2049 | */ | 2074 | */ |
2050 | static void | 2075 | static void |
2051 | handle_dht_p2p_get(void *cls, | 2076 | handle_dht_p2p_get (void *cls, |
2052 | const struct PeerGetMessage *get) | 2077 | const struct PeerGetMessage *get) |
2053 | { | 2078 | { |
2054 | struct PeerInfo *peer = cls; | 2079 | struct PeerInfo *peer = cls; |
2055 | uint32_t xquery_size; | 2080 | uint32_t xquery_size; |
@@ -2064,141 +2089,143 @@ handle_dht_p2p_get(void *cls, | |||
2064 | int forwarded; | 2089 | int forwarded; |
2065 | 2090 | ||
2066 | /* parse and validate message */ | 2091 | /* parse and validate message */ |
2067 | msize = ntohs(get->header.size); | 2092 | msize = ntohs (get->header.size); |
2068 | xquery_size = ntohl(get->xquery_size); | 2093 | xquery_size = ntohl (get->xquery_size); |
2069 | reply_bf_size = msize - (sizeof(struct PeerGetMessage) + xquery_size); | 2094 | reply_bf_size = msize - (sizeof(struct PeerGetMessage) + xquery_size); |
2070 | type = ntohl(get->type); | 2095 | type = ntohl (get->type); |
2071 | options = ntohl(get->options); | 2096 | options = ntohl (get->options); |
2072 | xquery = (const char *)&get[1]; | 2097 | xquery = (const char *) &get[1]; |
2073 | GNUNET_STATISTICS_update(GDS_stats, | 2098 | GNUNET_STATISTICS_update (GDS_stats, |
2074 | gettext_noop("# P2P GET requests received"), | 2099 | gettext_noop ("# P2P GET requests received"), |
2075 | 1, | 2100 | 1, |
2076 | GNUNET_NO); | 2101 | GNUNET_NO); |
2077 | GNUNET_STATISTICS_update(GDS_stats, | 2102 | GNUNET_STATISTICS_update (GDS_stats, |
2078 | gettext_noop("# P2P GET bytes received"), | 2103 | gettext_noop ("# P2P GET bytes received"), |
2079 | msize, | 2104 | msize, |
2080 | GNUNET_NO); | 2105 | GNUNET_NO); |
2081 | if (GNUNET_YES == log_route_details_stderr) | 2106 | if (GNUNET_YES == log_route_details_stderr) |
2082 | { | 2107 | { |
2083 | char *tmp; | 2108 | char *tmp; |
2084 | 2109 | ||
2085 | tmp = GNUNET_strdup(GNUNET_i2s(&my_identity)); | 2110 | tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); |
2086 | LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG, | 2111 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, |
2087 | "R5N GET %s: %s->%s (%u, %u=>%u) xq: %.*s\n", | 2112 | "R5N GET %s: %s->%s (%u, %u=>%u) xq: %.*s\n", |
2088 | GNUNET_h2s(&get->key), | 2113 | GNUNET_h2s (&get->key), |
2089 | GNUNET_i2s(peer->id), | 2114 | GNUNET_i2s (peer->id), |
2090 | tmp, | 2115 | tmp, |
2091 | ntohl(get->hop_count), | 2116 | ntohl (get->hop_count), |
2092 | GNUNET_CRYPTO_hash_matching_bits(&peer->phash, | 2117 | GNUNET_CRYPTO_hash_matching_bits (&peer->phash, |
2093 | &get->key), | 2118 | &get->key), |
2094 | GNUNET_CRYPTO_hash_matching_bits(&my_identity_hash, | 2119 | GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, |
2095 | &get->key), | 2120 | &get->key), |
2096 | ntohl(get->xquery_size), | 2121 | ntohl (get->xquery_size), |
2097 | xquery); | 2122 | xquery); |
2098 | GNUNET_free(tmp); | 2123 | GNUNET_free (tmp); |
2099 | } | 2124 | } |
2100 | eval | 2125 | eval |
2101 | = GNUNET_BLOCK_evaluate(GDS_block_context, | 2126 | = GNUNET_BLOCK_evaluate (GDS_block_context, |
2102 | type, | 2127 | type, |
2103 | NULL, | 2128 | NULL, |
2104 | GNUNET_BLOCK_EO_NONE, | 2129 | GNUNET_BLOCK_EO_NONE, |
2105 | &get->key, | 2130 | &get->key, |
2106 | xquery, | 2131 | xquery, |
2107 | xquery_size, | 2132 | xquery_size, |
2108 | NULL, | 2133 | NULL, |
2109 | 0); | 2134 | 0); |
2110 | if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID) | 2135 | if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID) |
2111 | { | 2136 | { |
2112 | /* request invalid or block type not supported */ | 2137 | /* request invalid or block type not supported */ |
2113 | GNUNET_break_op(eval == GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED); | 2138 | GNUNET_break_op (eval == GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED); |
2114 | return; | 2139 | return; |
2115 | } | 2140 | } |
2116 | peer_bf = GNUNET_CONTAINER_bloomfilter_init(get->bloomfilter, | 2141 | peer_bf = GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, |
2117 | DHT_BLOOM_SIZE, | 2142 | DHT_BLOOM_SIZE, |
2118 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 2143 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
2119 | GNUNET_break_op(GNUNET_YES == | 2144 | GNUNET_break_op (GNUNET_YES == |
2120 | GNUNET_CONTAINER_bloomfilter_test(peer_bf, | 2145 | GNUNET_CONTAINER_bloomfilter_test (peer_bf, |
2121 | &peer->phash)); | 2146 | &peer->phash)); |
2122 | bg = GNUNET_BLOCK_group_create(GDS_block_context, | 2147 | bg = GNUNET_BLOCK_group_create (GDS_block_context, |
2123 | type, | 2148 | type, |
2124 | get->bf_mutator, | 2149 | get->bf_mutator, |
2125 | &xquery[xquery_size], | 2150 | &xquery[xquery_size], |
2126 | reply_bf_size, | 2151 | reply_bf_size, |
2127 | "filter-size", | 2152 | "filter-size", |
2128 | reply_bf_size, | 2153 | reply_bf_size, |
2129 | NULL); | 2154 | NULL); |
2130 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2155 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2131 | "GET for %s at %s after %u hops\n", | 2156 | "GET for %s at %s after %u hops\n", |
2132 | GNUNET_h2s(&get->key), | 2157 | GNUNET_h2s (&get->key), |
2133 | GNUNET_i2s(&my_identity), | 2158 | GNUNET_i2s (&my_identity), |
2134 | (unsigned int)ntohl(get->hop_count)); | 2159 | (unsigned int) ntohl (get->hop_count)); |
2135 | /* local lookup (this may update the reply_bf) */ | 2160 | /* local lookup (this may update the reply_bf) */ |
2136 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || | 2161 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || |
2137 | (GDS_am_closest_peer(&get->key, | 2162 | (GDS_am_closest_peer (&get->key, |
2138 | peer_bf))) | 2163 | peer_bf))) |
2164 | { | ||
2165 | if ((0 != (options & GNUNET_DHT_RO_FIND_PEER))) | ||
2139 | { | 2166 | { |
2140 | if ((0 != (options & GNUNET_DHT_RO_FIND_PEER))) | 2167 | GNUNET_STATISTICS_update (GDS_stats, |
2141 | { | 2168 | gettext_noop ( |
2142 | GNUNET_STATISTICS_update(GDS_stats, | 2169 | "# P2P FIND PEER requests processed"), |
2143 | gettext_noop("# P2P FIND PEER requests processed"), | 2170 | 1, |
2144 | 1, | 2171 | GNUNET_NO); |
2145 | GNUNET_NO); | 2172 | handle_find_peer (peer->id, |
2146 | handle_find_peer(peer->id, | 2173 | &get->key, |
2147 | &get->key, | 2174 | bg); |
2148 | bg); | ||
2149 | } | ||
2150 | else | ||
2151 | { | ||
2152 | eval = GDS_DATACACHE_handle_get(&get->key, | ||
2153 | type, | ||
2154 | xquery, | ||
2155 | xquery_size, | ||
2156 | bg, | ||
2157 | &handle_local_result, | ||
2158 | peer); | ||
2159 | } | ||
2160 | } | 2175 | } |
2161 | else | 2176 | else |
2162 | { | 2177 | { |
2163 | GNUNET_STATISTICS_update(GDS_stats, | 2178 | eval = GDS_DATACACHE_handle_get (&get->key, |
2164 | gettext_noop("# P2P GET requests ONLY routed"), | 2179 | type, |
2165 | 1, | 2180 | xquery, |
2166 | GNUNET_NO); | 2181 | xquery_size, |
2182 | bg, | ||
2183 | &handle_local_result, | ||
2184 | peer); | ||
2167 | } | 2185 | } |
2186 | } | ||
2187 | else | ||
2188 | { | ||
2189 | GNUNET_STATISTICS_update (GDS_stats, | ||
2190 | gettext_noop ("# P2P GET requests ONLY routed"), | ||
2191 | 1, | ||
2192 | GNUNET_NO); | ||
2193 | } | ||
2168 | 2194 | ||
2169 | /* remember request for routing replies */ | 2195 | /* remember request for routing replies */ |
2170 | GDS_ROUTING_add(peer->id, | 2196 | GDS_ROUTING_add (peer->id, |
2171 | type, | 2197 | type, |
2172 | bg, /* bg now owned by routing, but valid at least until end of this function! */ | 2198 | bg, /* bg now owned by routing, but valid at least until end of this function! */ |
2173 | options, | 2199 | options, |
2174 | &get->key, | 2200 | &get->key, |
2175 | xquery, | 2201 | xquery, |
2176 | xquery_size); | 2202 | xquery_size); |
2177 | 2203 | ||
2178 | /* P2P forwarding */ | 2204 | /* P2P forwarding */ |
2179 | forwarded = GNUNET_NO; | 2205 | forwarded = GNUNET_NO; |
2180 | if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) | 2206 | if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) |
2181 | forwarded = GDS_NEIGHBOURS_handle_get(type, | 2207 | forwarded = GDS_NEIGHBOURS_handle_get (type, |
2182 | options, | 2208 | options, |
2183 | ntohl(get->desired_replication_level), | 2209 | ntohl ( |
2184 | ntohl(get->hop_count), | 2210 | get->desired_replication_level), |
2185 | &get->key, | 2211 | ntohl (get->hop_count), |
2186 | xquery, | 2212 | &get->key, |
2187 | xquery_size, | 2213 | xquery, |
2188 | bg, | 2214 | xquery_size, |
2189 | peer_bf); | 2215 | bg, |
2190 | GDS_CLIENTS_process_get(options | 2216 | peer_bf); |
2191 | | (GNUNET_OK == forwarded) | 2217 | GDS_CLIENTS_process_get (options |
2192 | ? GNUNET_DHT_RO_LAST_HOP : 0, | 2218 | | (GNUNET_OK == forwarded) |
2193 | type, | 2219 | ? GNUNET_DHT_RO_LAST_HOP : 0, |
2194 | ntohl(get->hop_count), | 2220 | type, |
2195 | ntohl(get->desired_replication_level), | 2221 | ntohl (get->hop_count), |
2196 | 0, | 2222 | ntohl (get->desired_replication_level), |
2197 | NULL, | 2223 | 0, |
2198 | &get->key); | 2224 | NULL, |
2225 | &get->key); | ||
2199 | 2226 | ||
2200 | /* clean up; note that 'bg' is owned by routing now! */ | 2227 | /* clean up; note that 'bg' is owned by routing now! */ |
2201 | GNUNET_CONTAINER_bloomfilter_free(peer_bf); | 2228 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); |
2202 | } | 2229 | } |
2203 | 2230 | ||
2204 | 2231 | ||
@@ -2210,29 +2237,29 @@ handle_dht_p2p_get(void *cls, | |||
2210 | * @return #GNUNET_YES if the message is well-formed | 2237 | * @return #GNUNET_YES if the message is well-formed |
2211 | */ | 2238 | */ |
2212 | static int | 2239 | static int |
2213 | check_dht_p2p_result(void *cls, | 2240 | check_dht_p2p_result (void *cls, |
2214 | const struct PeerResultMessage *prm) | 2241 | const struct PeerResultMessage *prm) |
2215 | { | 2242 | { |
2216 | uint32_t get_path_length; | 2243 | uint32_t get_path_length; |
2217 | uint32_t put_path_length; | 2244 | uint32_t put_path_length; |
2218 | uint16_t msize; | 2245 | uint16_t msize; |
2219 | 2246 | ||
2220 | (void)cls; | 2247 | (void) cls; |
2221 | msize = ntohs(prm->header.size); | 2248 | msize = ntohs (prm->header.size); |
2222 | put_path_length = ntohl(prm->put_path_length); | 2249 | put_path_length = ntohl (prm->put_path_length); |
2223 | get_path_length = ntohl(prm->get_path_length); | 2250 | get_path_length = ntohl (prm->get_path_length); |
2224 | if ((msize < | 2251 | if ((msize < |
2225 | sizeof(struct PeerResultMessage) + (get_path_length + | 2252 | sizeof(struct PeerResultMessage) + (get_path_length |
2226 | put_path_length) * | 2253 | + put_path_length) |
2227 | sizeof(struct GNUNET_PeerIdentity)) || | 2254 | * sizeof(struct GNUNET_PeerIdentity)) || |
2228 | (get_path_length > | 2255 | (get_path_length > |
2229 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || | 2256 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || |
2230 | (put_path_length > | 2257 | (put_path_length > |
2231 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity))) | 2258 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity))) |
2232 | { | 2259 | { |
2233 | GNUNET_break_op(0); | 2260 | GNUNET_break_op (0); |
2234 | return GNUNET_SYSERR; | 2261 | return GNUNET_SYSERR; |
2235 | } | 2262 | } |
2236 | return GNUNET_OK; | 2263 | return GNUNET_OK; |
2237 | } | 2264 | } |
2238 | 2265 | ||
@@ -2251,64 +2278,64 @@ check_dht_p2p_result(void *cls, | |||
2251 | * @param data payload of the reply | 2278 | * @param data payload of the reply |
2252 | */ | 2279 | */ |
2253 | static void | 2280 | static void |
2254 | process_reply_with_path(struct GNUNET_TIME_Absolute expiration_time, | 2281 | process_reply_with_path (struct GNUNET_TIME_Absolute expiration_time, |
2255 | const struct GNUNET_HashCode *key, | 2282 | const struct GNUNET_HashCode *key, |
2256 | unsigned int get_path_length, | 2283 | unsigned int get_path_length, |
2257 | const struct GNUNET_PeerIdentity *get_path, | 2284 | const struct GNUNET_PeerIdentity *get_path, |
2258 | unsigned int put_path_length, | 2285 | unsigned int put_path_length, |
2259 | const struct GNUNET_PeerIdentity *put_path, | 2286 | const struct GNUNET_PeerIdentity *put_path, |
2260 | enum GNUNET_BLOCK_Type type, | 2287 | enum GNUNET_BLOCK_Type type, |
2261 | size_t data_size, | 2288 | size_t data_size, |
2262 | const void *data) | 2289 | const void *data) |
2263 | { | 2290 | { |
2264 | /* forward to local clients */ | 2291 | /* forward to local clients */ |
2265 | GDS_CLIENTS_handle_reply(expiration_time, | 2292 | GDS_CLIENTS_handle_reply (expiration_time, |
2266 | key, | 2293 | key, |
2267 | get_path_length, | 2294 | get_path_length, |
2268 | get_path, | 2295 | get_path, |
2269 | put_path_length, | 2296 | put_path_length, |
2270 | put_path, | 2297 | put_path, |
2271 | type, | 2298 | type, |
2272 | data_size, | 2299 | data_size, |
2273 | data); | 2300 | data); |
2274 | GDS_CLIENTS_process_get_resp(type, | 2301 | GDS_CLIENTS_process_get_resp (type, |
2275 | get_path, | 2302 | get_path, |
2276 | get_path_length, | 2303 | get_path_length, |
2277 | put_path, | 2304 | put_path, |
2278 | put_path_length, | 2305 | put_path_length, |
2279 | expiration_time, | 2306 | expiration_time, |
2280 | key, | 2307 | key, |
2281 | data, | 2308 | data, |
2282 | data_size); | 2309 | data_size); |
2283 | if (GNUNET_YES == cache_results) | 2310 | if (GNUNET_YES == cache_results) |
2284 | { | 2311 | { |
2285 | struct GNUNET_PeerIdentity xput_path[get_path_length + 1 + put_path_length]; | 2312 | struct GNUNET_PeerIdentity xput_path[get_path_length + 1 + put_path_length]; |
2286 | 2313 | ||
2287 | GNUNET_memcpy(xput_path, | 2314 | GNUNET_memcpy (xput_path, |
2288 | put_path, | 2315 | put_path, |
2289 | put_path_length * sizeof(struct GNUNET_PeerIdentity)); | 2316 | put_path_length * sizeof(struct GNUNET_PeerIdentity)); |
2290 | GNUNET_memcpy(&xput_path[put_path_length], | 2317 | GNUNET_memcpy (&xput_path[put_path_length], |
2291 | get_path, | 2318 | get_path, |
2292 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); | 2319 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); |
2293 | 2320 | ||
2294 | GDS_DATACACHE_handle_put(expiration_time, | 2321 | GDS_DATACACHE_handle_put (expiration_time, |
2295 | key, | 2322 | key, |
2296 | get_path_length + put_path_length, | 2323 | get_path_length + put_path_length, |
2297 | xput_path, | 2324 | xput_path, |
2298 | type, | 2325 | type, |
2299 | data_size, | 2326 | data_size, |
2300 | data); | 2327 | data); |
2301 | } | 2328 | } |
2302 | /* forward to other peers */ | 2329 | /* forward to other peers */ |
2303 | GDS_ROUTING_process(type, | 2330 | GDS_ROUTING_process (type, |
2304 | expiration_time, | 2331 | expiration_time, |
2305 | key, | 2332 | key, |
2306 | put_path_length, | 2333 | put_path_length, |
2307 | put_path, | 2334 | put_path, |
2308 | get_path_length, | 2335 | get_path_length, |
2309 | get_path, | 2336 | get_path, |
2310 | data, | 2337 | data, |
2311 | data_size); | 2338 | data_size); |
2312 | } | 2339 | } |
2313 | 2340 | ||
2314 | 2341 | ||
@@ -2319,8 +2346,8 @@ process_reply_with_path(struct GNUNET_TIME_Absolute expiration_time, | |||
2319 | * @param message message | 2346 | * @param message message |
2320 | */ | 2347 | */ |
2321 | static void | 2348 | static void |
2322 | handle_dht_p2p_result(void *cls, | 2349 | handle_dht_p2p_result (void *cls, |
2323 | const struct PeerResultMessage *prm) | 2350 | const struct PeerResultMessage *prm) |
2324 | { | 2351 | { |
2325 | struct PeerInfo *peer = cls; | 2352 | struct PeerInfo *peer = cls; |
2326 | const struct GNUNET_PeerIdentity *put_path; | 2353 | const struct GNUNET_PeerIdentity *put_path; |
@@ -2334,125 +2361,126 @@ handle_dht_p2p_result(void *cls, | |||
2334 | struct GNUNET_TIME_Absolute exp_time; | 2361 | struct GNUNET_TIME_Absolute exp_time; |
2335 | 2362 | ||
2336 | /* parse and validate message */ | 2363 | /* parse and validate message */ |
2337 | exp_time = GNUNET_TIME_absolute_ntoh(prm->expiration_time); | 2364 | exp_time = GNUNET_TIME_absolute_ntoh (prm->expiration_time); |
2338 | if (0 == GNUNET_TIME_absolute_get_remaining(exp_time).rel_value_us) | 2365 | if (0 == GNUNET_TIME_absolute_get_remaining (exp_time).rel_value_us) |
2366 | { | ||
2367 | GNUNET_STATISTICS_update (GDS_stats, | ||
2368 | gettext_noop ("# Expired results discarded"), | ||
2369 | 1, | ||
2370 | GNUNET_NO); | ||
2371 | return; | ||
2372 | } | ||
2373 | msize = ntohs (prm->header.size); | ||
2374 | put_path_length = ntohl (prm->put_path_length); | ||
2375 | get_path_length = ntohl (prm->get_path_length); | ||
2376 | put_path = (const struct GNUNET_PeerIdentity *) &prm[1]; | ||
2377 | get_path = &put_path[put_path_length]; | ||
2378 | type = ntohl (prm->type); | ||
2379 | data = (const void *) &get_path[get_path_length]; | ||
2380 | data_size = msize - (sizeof(struct PeerResultMessage) | ||
2381 | + (get_path_length | ||
2382 | + put_path_length) * sizeof(struct | ||
2383 | GNUNET_PeerIdentity)); | ||
2384 | GNUNET_STATISTICS_update (GDS_stats, | ||
2385 | gettext_noop ("# P2P RESULTS received"), | ||
2386 | 1, | ||
2387 | GNUNET_NO); | ||
2388 | GNUNET_STATISTICS_update (GDS_stats, | ||
2389 | gettext_noop ("# P2P RESULT bytes received"), | ||
2390 | msize, | ||
2391 | GNUNET_NO); | ||
2392 | if (GNUNET_YES == log_route_details_stderr) | ||
2393 | { | ||
2394 | char *tmp; | ||
2395 | char *pp; | ||
2396 | char *gp; | ||
2397 | |||
2398 | gp = GNUNET_STRINGS_pp2s (get_path, | ||
2399 | get_path_length); | ||
2400 | pp = GNUNET_STRINGS_pp2s (put_path, | ||
2401 | put_path_length); | ||
2402 | tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); | ||
2403 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, | ||
2404 | "R5N RESULT %s: %s->%s (GP: %s, PP: %s)\n", | ||
2405 | GNUNET_h2s (&prm->key), | ||
2406 | GNUNET_i2s (peer->id), | ||
2407 | tmp, | ||
2408 | gp, | ||
2409 | pp); | ||
2410 | GNUNET_free (gp); | ||
2411 | GNUNET_free (pp); | ||
2412 | GNUNET_free (tmp); | ||
2413 | } | ||
2414 | /* if we got a HELLO, consider it for our own routing table */ | ||
2415 | if (GNUNET_BLOCK_TYPE_DHT_HELLO == type) | ||
2416 | { | ||
2417 | const struct GNUNET_MessageHeader *h; | ||
2418 | struct GNUNET_PeerIdentity pid; | ||
2419 | |||
2420 | /* Should be a HELLO, validate and consider using it! */ | ||
2421 | if (data_size < sizeof(struct GNUNET_HELLO_Message)) | ||
2339 | { | 2422 | { |
2340 | GNUNET_STATISTICS_update(GDS_stats, | 2423 | GNUNET_break_op (0); |
2341 | gettext_noop("# Expired results discarded"), | ||
2342 | 1, | ||
2343 | GNUNET_NO); | ||
2344 | return; | 2424 | return; |
2345 | } | 2425 | } |
2346 | msize = ntohs(prm->header.size); | 2426 | h = data; |
2347 | put_path_length = ntohl(prm->put_path_length); | 2427 | if (data_size != ntohs (h->size)) |
2348 | get_path_length = ntohl(prm->get_path_length); | ||
2349 | put_path = (const struct GNUNET_PeerIdentity *)&prm[1]; | ||
2350 | get_path = &put_path[put_path_length]; | ||
2351 | type = ntohl(prm->type); | ||
2352 | data = (const void *)&get_path[get_path_length]; | ||
2353 | data_size = msize - (sizeof(struct PeerResultMessage) + | ||
2354 | (get_path_length + | ||
2355 | put_path_length) * sizeof(struct GNUNET_PeerIdentity)); | ||
2356 | GNUNET_STATISTICS_update(GDS_stats, | ||
2357 | gettext_noop("# P2P RESULTS received"), | ||
2358 | 1, | ||
2359 | GNUNET_NO); | ||
2360 | GNUNET_STATISTICS_update(GDS_stats, | ||
2361 | gettext_noop("# P2P RESULT bytes received"), | ||
2362 | msize, | ||
2363 | GNUNET_NO); | ||
2364 | if (GNUNET_YES == log_route_details_stderr) | ||
2365 | { | 2428 | { |
2366 | char *tmp; | 2429 | GNUNET_break_op (0); |
2367 | char *pp; | 2430 | return; |
2368 | char *gp; | ||
2369 | |||
2370 | gp = GNUNET_STRINGS_pp2s(get_path, | ||
2371 | get_path_length); | ||
2372 | pp = GNUNET_STRINGS_pp2s(put_path, | ||
2373 | put_path_length); | ||
2374 | tmp = GNUNET_strdup(GNUNET_i2s(&my_identity)); | ||
2375 | LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG, | ||
2376 | "R5N RESULT %s: %s->%s (GP: %s, PP: %s)\n", | ||
2377 | GNUNET_h2s(&prm->key), | ||
2378 | GNUNET_i2s(peer->id), | ||
2379 | tmp, | ||
2380 | gp, | ||
2381 | pp); | ||
2382 | GNUNET_free(gp); | ||
2383 | GNUNET_free(pp); | ||
2384 | GNUNET_free(tmp); | ||
2385 | } | 2431 | } |
2386 | /* if we got a HELLO, consider it for our own routing table */ | 2432 | if (GNUNET_OK != |
2387 | if (GNUNET_BLOCK_TYPE_DHT_HELLO == type) | 2433 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) h, |
2434 | &pid)) | ||
2388 | { | 2435 | { |
2389 | const struct GNUNET_MessageHeader *h; | 2436 | GNUNET_break_op (0); |
2390 | struct GNUNET_PeerIdentity pid; | 2437 | return; |
2391 | |||
2392 | /* Should be a HELLO, validate and consider using it! */ | ||
2393 | if (data_size < sizeof(struct GNUNET_HELLO_Message)) | ||
2394 | { | ||
2395 | GNUNET_break_op(0); | ||
2396 | return; | ||
2397 | } | ||
2398 | h = data; | ||
2399 | if (data_size != ntohs(h->size)) | ||
2400 | { | ||
2401 | GNUNET_break_op(0); | ||
2402 | return; | ||
2403 | } | ||
2404 | if (GNUNET_OK != | ||
2405 | GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)h, | ||
2406 | &pid)) | ||
2407 | { | ||
2408 | GNUNET_break_op(0); | ||
2409 | return; | ||
2410 | } | ||
2411 | if ((GNUNET_YES != disable_try_connect) && | ||
2412 | (0 != memcmp(&my_identity, | ||
2413 | &pid, | ||
2414 | sizeof(struct GNUNET_PeerIdentity)))) | ||
2415 | try_connect(&pid, | ||
2416 | h); | ||
2417 | } | 2438 | } |
2439 | if ((GNUNET_YES != disable_try_connect) && | ||
2440 | (0 != memcmp (&my_identity, | ||
2441 | &pid, | ||
2442 | sizeof(struct GNUNET_PeerIdentity)))) | ||
2443 | try_connect (&pid, | ||
2444 | h); | ||
2445 | } | ||
2418 | 2446 | ||
2419 | /* First, check if 'peer' is already on the path, and if | 2447 | /* First, check if 'peer' is already on the path, and if |
2420 | so, truncate it instead of expanding. */ | 2448 | so, truncate it instead of expanding. */ |
2421 | for (unsigned int i = 0; i <= get_path_length; i++) | 2449 | for (unsigned int i = 0; i <= get_path_length; i++) |
2422 | if (0 == memcmp(&get_path[i], | 2450 | if (0 == memcmp (&get_path[i], |
2423 | peer->id, | 2451 | peer->id, |
2424 | sizeof(struct GNUNET_PeerIdentity))) | 2452 | sizeof(struct GNUNET_PeerIdentity))) |
2425 | { | 2453 | { |
2426 | process_reply_with_path(exp_time, | 2454 | process_reply_with_path (exp_time, |
2427 | &prm->key, | 2455 | &prm->key, |
2428 | i, | 2456 | i, |
2429 | get_path, | 2457 | get_path, |
2430 | put_path_length, | 2458 | put_path_length, |
2431 | put_path, | 2459 | put_path, |
2432 | type, | 2460 | type, |
2433 | data_size, | 2461 | data_size, |
2434 | data); | 2462 | data); |
2435 | return; | 2463 | return; |
2436 | } | 2464 | } |
2437 | 2465 | ||
2438 | /* Need to append 'peer' to 'get_path' (normal case) */ | 2466 | /* Need to append 'peer' to 'get_path' (normal case) */ |
2439 | { | 2467 | { |
2440 | struct GNUNET_PeerIdentity xget_path[get_path_length + 1]; | 2468 | struct GNUNET_PeerIdentity xget_path[get_path_length + 1]; |
2441 | 2469 | ||
2442 | GNUNET_memcpy(xget_path, | 2470 | GNUNET_memcpy (xget_path, |
2443 | get_path, | 2471 | get_path, |
2444 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); | 2472 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); |
2445 | xget_path[get_path_length] = *peer->id; | 2473 | xget_path[get_path_length] = *peer->id; |
2446 | 2474 | ||
2447 | process_reply_with_path(exp_time, | 2475 | process_reply_with_path (exp_time, |
2448 | &prm->key, | 2476 | &prm->key, |
2449 | get_path_length + 1, | 2477 | get_path_length + 1, |
2450 | xget_path, | 2478 | xget_path, |
2451 | put_path_length, | 2479 | put_path_length, |
2452 | put_path, | 2480 | put_path, |
2453 | type, | 2481 | type, |
2454 | data_size, | 2482 | data_size, |
2455 | data); | 2483 | data); |
2456 | } | 2484 | } |
2457 | } | 2485 | } |
2458 | 2486 | ||
@@ -2463,55 +2491,55 @@ handle_dht_p2p_result(void *cls, | |||
2463 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 2491 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
2464 | */ | 2492 | */ |
2465 | int | 2493 | int |
2466 | GDS_NEIGHBOURS_init() | 2494 | GDS_NEIGHBOURS_init () |
2467 | { | 2495 | { |
2468 | struct GNUNET_MQ_MessageHandler core_handlers[] = { | 2496 | struct GNUNET_MQ_MessageHandler core_handlers[] = { |
2469 | GNUNET_MQ_hd_var_size(dht_p2p_get, | 2497 | GNUNET_MQ_hd_var_size (dht_p2p_get, |
2470 | GNUNET_MESSAGE_TYPE_DHT_P2P_GET, | 2498 | GNUNET_MESSAGE_TYPE_DHT_P2P_GET, |
2471 | struct PeerGetMessage, | 2499 | struct PeerGetMessage, |
2472 | NULL), | 2500 | NULL), |
2473 | GNUNET_MQ_hd_var_size(dht_p2p_put, | 2501 | GNUNET_MQ_hd_var_size (dht_p2p_put, |
2474 | GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, | 2502 | GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, |
2475 | struct PeerPutMessage, | 2503 | struct PeerPutMessage, |
2476 | NULL), | 2504 | NULL), |
2477 | GNUNET_MQ_hd_var_size(dht_p2p_result, | 2505 | GNUNET_MQ_hd_var_size (dht_p2p_result, |
2478 | GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, | 2506 | GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, |
2479 | struct PeerResultMessage, | 2507 | struct PeerResultMessage, |
2480 | NULL), | 2508 | NULL), |
2481 | GNUNET_MQ_handler_end() | 2509 | GNUNET_MQ_handler_end () |
2482 | }; | 2510 | }; |
2483 | unsigned long long temp_config_num; | 2511 | unsigned long long temp_config_num; |
2484 | 2512 | ||
2485 | disable_try_connect | 2513 | disable_try_connect |
2486 | = GNUNET_CONFIGURATION_get_value_yesno(GDS_cfg, | 2514 | = GNUNET_CONFIGURATION_get_value_yesno (GDS_cfg, |
2487 | "DHT", | ||
2488 | "DISABLE_TRY_CONNECT"); | ||
2489 | if (GNUNET_OK == | ||
2490 | GNUNET_CONFIGURATION_get_value_number(GDS_cfg, | ||
2491 | "DHT", | 2515 | "DHT", |
2492 | "bucket_size", | 2516 | "DISABLE_TRY_CONNECT"); |
2493 | &temp_config_num)) | 2517 | if (GNUNET_OK == |
2494 | bucket_size = (unsigned int)temp_config_num; | 2518 | GNUNET_CONFIGURATION_get_value_number (GDS_cfg, |
2519 | "DHT", | ||
2520 | "bucket_size", | ||
2521 | &temp_config_num)) | ||
2522 | bucket_size = (unsigned int) temp_config_num; | ||
2495 | cache_results | 2523 | cache_results |
2496 | = GNUNET_CONFIGURATION_get_value_yesno(GDS_cfg, | 2524 | = GNUNET_CONFIGURATION_get_value_yesno (GDS_cfg, |
2497 | "DHT", | 2525 | "DHT", |
2498 | "CACHE_RESULTS"); | 2526 | "CACHE_RESULTS"); |
2499 | 2527 | ||
2500 | log_route_details_stderr = | 2528 | log_route_details_stderr = |
2501 | (NULL != getenv("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO; | 2529 | (NULL != getenv ("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO; |
2502 | ats_ch = GNUNET_ATS_connectivity_init(GDS_cfg); | 2530 | ats_ch = GNUNET_ATS_connectivity_init (GDS_cfg); |
2503 | core_api = GNUNET_CORE_connect(GDS_cfg, | 2531 | core_api = GNUNET_CORE_connect (GDS_cfg, |
2504 | NULL, | 2532 | NULL, |
2505 | &core_init, | 2533 | &core_init, |
2506 | &handle_core_connect, | 2534 | &handle_core_connect, |
2507 | &handle_core_disconnect, | 2535 | &handle_core_disconnect, |
2508 | core_handlers); | 2536 | core_handlers); |
2509 | if (NULL == core_api) | 2537 | if (NULL == core_api) |
2510 | return GNUNET_SYSERR; | 2538 | return GNUNET_SYSERR; |
2511 | all_connected_peers = GNUNET_CONTAINER_multipeermap_create(256, | 2539 | all_connected_peers = GNUNET_CONTAINER_multipeermap_create (256, |
2512 | GNUNET_YES); | 2540 | GNUNET_YES); |
2513 | all_desired_peers = GNUNET_CONTAINER_multipeermap_create(256, | 2541 | all_desired_peers = GNUNET_CONTAINER_multipeermap_create (256, |
2514 | GNUNET_NO); | 2542 | GNUNET_NO); |
2515 | return GNUNET_OK; | 2543 | return GNUNET_OK; |
2516 | } | 2544 | } |
2517 | 2545 | ||
@@ -2520,24 +2548,24 @@ GDS_NEIGHBOURS_init() | |||
2520 | * Shutdown neighbours subsystem. | 2548 | * Shutdown neighbours subsystem. |
2521 | */ | 2549 | */ |
2522 | void | 2550 | void |
2523 | GDS_NEIGHBOURS_done() | 2551 | GDS_NEIGHBOURS_done () |
2524 | { | 2552 | { |
2525 | if (NULL == core_api) | 2553 | if (NULL == core_api) |
2526 | return; | 2554 | return; |
2527 | GNUNET_CORE_disconnect(core_api); | 2555 | GNUNET_CORE_disconnect (core_api); |
2528 | core_api = NULL; | 2556 | core_api = NULL; |
2529 | GNUNET_assert(0 == | 2557 | GNUNET_assert (0 == |
2530 | GNUNET_CONTAINER_multipeermap_size(all_connected_peers)); | 2558 | GNUNET_CONTAINER_multipeermap_size (all_connected_peers)); |
2531 | GNUNET_CONTAINER_multipeermap_destroy(all_connected_peers); | 2559 | GNUNET_CONTAINER_multipeermap_destroy (all_connected_peers); |
2532 | all_connected_peers = NULL; | 2560 | all_connected_peers = NULL; |
2533 | GNUNET_CONTAINER_multipeermap_iterate(all_desired_peers, | 2561 | GNUNET_CONTAINER_multipeermap_iterate (all_desired_peers, |
2534 | &free_connect_info, | 2562 | &free_connect_info, |
2535 | NULL); | 2563 | NULL); |
2536 | GNUNET_CONTAINER_multipeermap_destroy(all_desired_peers); | 2564 | GNUNET_CONTAINER_multipeermap_destroy (all_desired_peers); |
2537 | all_desired_peers = NULL; | 2565 | all_desired_peers = NULL; |
2538 | GNUNET_ATS_connectivity_done(ats_ch); | 2566 | GNUNET_ATS_connectivity_done (ats_ch); |
2539 | ats_ch = NULL; | 2567 | ats_ch = NULL; |
2540 | GNUNET_assert(NULL == find_peer_task); | 2568 | GNUNET_assert (NULL == find_peer_task); |
2541 | } | 2569 | } |
2542 | 2570 | ||
2543 | 2571 | ||
@@ -2547,7 +2575,7 @@ GDS_NEIGHBOURS_done() | |||
2547 | * @return identity of the local node | 2575 | * @return identity of the local node |
2548 | */ | 2576 | */ |
2549 | struct GNUNET_PeerIdentity * | 2577 | struct GNUNET_PeerIdentity * |
2550 | GDS_NEIGHBOURS_get_id() | 2578 | GDS_NEIGHBOURS_get_id () |
2551 | { | 2579 | { |
2552 | return &my_identity; | 2580 | return &my_identity; |
2553 | } | 2581 | } |