diff options
Diffstat (limited to 'src/dht/gnunet-service-dht_neighbours.c')
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 253 |
1 files changed, 122 insertions, 131 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index fb061d5b1..75bdaed53 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -424,7 +424,7 @@ static struct GNUNET_ATS_ConnectivityHandle *ats_ch; | |||
424 | * Find the optimal bucket for this key. | 424 | * Find the optimal bucket for this key. |
425 | * | 425 | * |
426 | * @param hc the hashcode to compare our identity to | 426 | * @param hc the hashcode to compare our identity to |
427 | * @return the proper bucket index, or #GNUNET_SYSERR | 427 | * @return the proper bucket index, or -1 |
428 | * on error (same hashcode) | 428 | * on error (same hashcode) |
429 | */ | 429 | */ |
430 | static int | 430 | static int |
@@ -437,7 +437,7 @@ find_bucket (const struct GNUNET_HashCode *hc) | |||
437 | { | 437 | { |
438 | /* How can all bits match? Got my own ID? */ | 438 | /* How can all bits match? Got my own ID? */ |
439 | GNUNET_break (0); | 439 | GNUNET_break (0); |
440 | return GNUNET_SYSERR; | 440 | return -1; |
441 | } | 441 | } |
442 | return MAX_BUCKETS - bits - 1; | 442 | return MAX_BUCKETS - bits - 1; |
443 | } | 443 | } |
@@ -466,7 +466,7 @@ offer_hello_done (void *cls) | |||
466 | * @param value the value to remove | 466 | * @param value the value to remove |
467 | * @return #GNUNET_YES | 467 | * @return #GNUNET_YES |
468 | */ | 468 | */ |
469 | static int | 469 | static enum GNUNET_GenericReturnValue |
470 | free_connect_info (void *cls, | 470 | free_connect_info (void *cls, |
471 | const struct GNUNET_PeerIdentity *peer, | 471 | const struct GNUNET_PeerIdentity *peer, |
472 | void *value) | 472 | void *value) |
@@ -580,7 +580,7 @@ try_connect (const struct GNUNET_PeerIdentity *pid, | |||
580 | * @param value unused | 580 | * @param value unused |
581 | * @return #GNUNET_YES (continue to iterate) | 581 | * @return #GNUNET_YES (continue to iterate) |
582 | */ | 582 | */ |
583 | static int | 583 | static enum GNUNET_GenericReturnValue |
584 | update_desire_strength (void *cls, | 584 | update_desire_strength (void *cls, |
585 | const struct GNUNET_PeerIdentity *pid, | 585 | const struct GNUNET_PeerIdentity *pid, |
586 | void *value) | 586 | void *value) |
@@ -600,7 +600,7 @@ update_desire_strength (void *cls, | |||
600 | * @param tc scheduler context. | 600 | * @param tc scheduler context. |
601 | */ | 601 | */ |
602 | static void | 602 | static void |
603 | update_connect_preferences () | 603 | update_connect_preferences (void) |
604 | { | 604 | { |
605 | GNUNET_CONTAINER_multipeermap_iterate (all_desired_peers, | 605 | GNUNET_CONTAINER_multipeermap_iterate (all_desired_peers, |
606 | &update_desire_strength, | 606 | &update_desire_strength, |
@@ -617,7 +617,7 @@ update_connect_preferences () | |||
617 | * @param value value the peer information (unused) | 617 | * @param value value the peer information (unused) |
618 | * @return #GNUNET_YES (we should continue to iterate) | 618 | * @return #GNUNET_YES (we should continue to iterate) |
619 | */ | 619 | */ |
620 | static int | 620 | static enum GNUNET_GenericReturnValue |
621 | add_known_to_bloom (void *cls, | 621 | add_known_to_bloom (void *cls, |
622 | const struct GNUNET_PeerIdentity *key, | 622 | const struct GNUNET_PeerIdentity *key, |
623 | void *value) | 623 | void *value) |
@@ -680,7 +680,7 @@ send_find_peer_message (void *cls) | |||
680 | &add_known_to_bloom, | 680 | &add_known_to_bloom, |
681 | bg); | 681 | bg); |
682 | GNUNET_STATISTICS_update (GDS_stats, | 682 | GNUNET_STATISTICS_update (GDS_stats, |
683 | gettext_noop ("# FIND PEER messages initiated"), | 683 | "# FIND PEER messages initiated", |
684 | 1, | 684 | 1, |
685 | GNUNET_NO); | 685 | GNUNET_NO); |
686 | peer_bf | 686 | peer_bf |
@@ -932,7 +932,7 @@ get_distance (const struct GNUNET_HashCode *target, | |||
932 | * @return #GNUNET_YES if node location is closest, | 932 | * @return #GNUNET_YES if node location is closest, |
933 | * #GNUNET_NO otherwise. | 933 | * #GNUNET_NO otherwise. |
934 | */ | 934 | */ |
935 | int | 935 | enum GNUNET_GenericReturnValue |
936 | GDS_am_closest_peer (const struct GNUNET_HashCode *key, | 936 | GDS_am_closest_peer (const struct GNUNET_HashCode *key, |
937 | const struct GNUNET_CONTAINER_BloomFilter *bloom) | 937 | const struct GNUNET_CONTAINER_BloomFilter *bloom) |
938 | { | 938 | { |
@@ -1222,7 +1222,7 @@ get_target_peers (const struct GNUNET_HashCode *key, | |||
1222 | * @param data_size number of bytes in @a data | 1222 | * @param data_size number of bytes in @a data |
1223 | * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not | 1223 | * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not |
1224 | */ | 1224 | */ |
1225 | int | 1225 | enum GNUNET_GenericReturnValue |
1226 | GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, | 1226 | GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, |
1227 | enum GNUNET_DHT_RouteOption options, | 1227 | enum GNUNET_DHT_RouteOption options, |
1228 | uint32_t desired_replication_level, | 1228 | uint32_t desired_replication_level, |
@@ -1359,7 +1359,7 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, | |||
1359 | * @param peer_bf filter for peers not to select (again) | 1359 | * @param peer_bf filter for peers not to select (again) |
1360 | * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not | 1360 | * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not |
1361 | */ | 1361 | */ |
1362 | int | 1362 | enum GNUNET_GenericReturnValue |
1363 | GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | 1363 | GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, |
1364 | enum GNUNET_DHT_RouteOption options, | 1364 | enum GNUNET_DHT_RouteOption options, |
1365 | uint32_t desired_replication_level, | 1365 | uint32_t desired_replication_level, |
@@ -1614,7 +1614,7 @@ core_init (void *cls, | |||
1614 | * @param message message | 1614 | * @param message message |
1615 | * @return #GNUNET_OK if the message is valid | 1615 | * @return #GNUNET_OK if the message is valid |
1616 | */ | 1616 | */ |
1617 | static int | 1617 | static enum GNUNET_GenericReturnValue |
1618 | check_dht_p2p_put (void *cls, | 1618 | check_dht_p2p_put (void *cls, |
1619 | const struct PeerPutMessage *put) | 1619 | const struct PeerPutMessage *put) |
1620 | { | 1620 | { |
@@ -1655,12 +1655,11 @@ handle_dht_p2p_put (void *cls, | |||
1655 | size_t payload_size; | 1655 | size_t payload_size; |
1656 | enum GNUNET_DHT_RouteOption options; | 1656 | enum GNUNET_DHT_RouteOption options; |
1657 | struct GNUNET_CONTAINER_BloomFilter *bf; | 1657 | struct GNUNET_CONTAINER_BloomFilter *bf; |
1658 | struct GNUNET_HashCode test_key; | ||
1659 | int forwarded; | 1658 | int forwarded; |
1660 | struct GNUNET_TIME_Absolute exp_time; | 1659 | struct GNUNET_TIME_Absolute exp_time; |
1661 | 1660 | ||
1662 | exp_time = GNUNET_TIME_absolute_ntoh (put->expiration_time); | 1661 | exp_time = GNUNET_TIME_absolute_ntoh (put->expiration_time); |
1663 | if (0 == GNUNET_TIME_absolute_get_remaining (exp_time).rel_value_us) | 1662 | if (GNUNET_TIME_absolute_is_past (exp_time)) |
1664 | { | 1663 | { |
1665 | GNUNET_STATISTICS_update (GDS_stats, | 1664 | GNUNET_STATISTICS_update (GDS_stats, |
1666 | gettext_noop ("# Expired PUTs discarded"), | 1665 | gettext_noop ("# Expired PUTs discarded"), |
@@ -1710,63 +1709,44 @@ handle_dht_p2p_put (void *cls, | |||
1710 | GNUNET_free (pp); | 1709 | GNUNET_free (pp); |
1711 | GNUNET_free (tmp); | 1710 | GNUNET_free (tmp); |
1712 | } | 1711 | } |
1713 | switch (GNUNET_BLOCK_get_key | 1712 | |
1714 | (GDS_block_context, | ||
1715 | ntohl (put->type), | ||
1716 | payload, | ||
1717 | payload_size, | ||
1718 | &test_key)) | ||
1719 | { | 1713 | { |
1720 | case GNUNET_YES: | 1714 | struct GNUNET_HashCode test_key; |
1721 | if (0 != memcmp (&test_key, | 1715 | enum GNUNET_GenericReturnValue ret; |
1722 | &put->key, | ||
1723 | sizeof(struct GNUNET_HashCode))) | ||
1724 | { | ||
1725 | char *put_s = GNUNET_strdup (GNUNET_h2s_full (&put->key)); | ||
1726 | 1716 | ||
1717 | ret = GNUNET_BLOCK_get_key (GDS_block_context, | ||
1718 | ntohl (put->type), | ||
1719 | payload, | ||
1720 | payload_size, | ||
1721 | &test_key); | ||
1722 | switch (ret) | ||
1723 | { | ||
1724 | case GNUNET_YES: | ||
1725 | if (0 != GNUNET_memcmp (&test_key, | ||
1726 | &put->key)) | ||
1727 | { | ||
1728 | GNUNET_break_op (0); | ||
1729 | return; | ||
1730 | } | ||
1731 | break; | ||
1732 | case GNUNET_NO: | ||
1727 | GNUNET_break_op (0); | 1733 | GNUNET_break_op (0); |
1728 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1729 | "PUT with key `%s' for block with key %s\n", | ||
1730 | put_s, | ||
1731 | GNUNET_h2s_full (&test_key)); | ||
1732 | GNUNET_free (put_s); | ||
1733 | return; | 1734 | return; |
1735 | case GNUNET_SYSERR: | ||
1736 | /* cannot verify, good luck */ | ||
1737 | break; | ||
1734 | } | 1738 | } |
1735 | break; | 1739 | } |
1736 | 1740 | ||
1737 | case GNUNET_NO: | 1741 | if (GNUNET_NO == |
1742 | GNUNET_BLOCK_check_block (GDS_block_context, | ||
1743 | ntohl (put->type), | ||
1744 | &put->key, | ||
1745 | payload, | ||
1746 | payload_size)) | ||
1747 | { | ||
1738 | GNUNET_break_op (0); | 1748 | GNUNET_break_op (0); |
1739 | return; | 1749 | return; |
1740 | |||
1741 | case GNUNET_SYSERR: | ||
1742 | /* cannot verify, good luck */ | ||
1743 | break; | ||
1744 | } | ||
1745 | if (ntohl (put->type) == GNUNET_BLOCK_TYPE_REGEX) /* FIXME: do for all tpyes */ | ||
1746 | { | ||
1747 | switch (GNUNET_BLOCK_evaluate (GDS_block_context, | ||
1748 | ntohl (put->type), | ||
1749 | NULL, /* query group */ | ||
1750 | GNUNET_BLOCK_EO_NONE, | ||
1751 | NULL, /* query */ | ||
1752 | NULL, 0, /* xquery */ | ||
1753 | payload, | ||
1754 | payload_size)) | ||
1755 | { | ||
1756 | case GNUNET_BLOCK_EVALUATION_OK_MORE: | ||
1757 | case GNUNET_BLOCK_EVALUATION_OK_LAST: | ||
1758 | break; | ||
1759 | |||
1760 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: | ||
1761 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: | ||
1762 | case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: | ||
1763 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: | ||
1764 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: | ||
1765 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: | ||
1766 | default: | ||
1767 | GNUNET_break_op (0); | ||
1768 | return; | ||
1769 | } | ||
1770 | } | 1750 | } |
1771 | 1751 | ||
1772 | bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, | 1752 | bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, |
@@ -1807,6 +1787,7 @@ handle_dht_p2p_put (void *cls, | |||
1807 | /* give to local clients */ | 1787 | /* give to local clients */ |
1808 | GDS_CLIENTS_handle_reply (exp_time, | 1788 | GDS_CLIENTS_handle_reply (exp_time, |
1809 | &put->key, | 1789 | &put->key, |
1790 | &put->key, | ||
1810 | 0, | 1791 | 0, |
1811 | NULL, | 1792 | NULL, |
1812 | putlen, | 1793 | putlen, |
@@ -1906,8 +1887,7 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1906 | else | 1887 | else |
1907 | { | 1888 | { |
1908 | GNUNET_STATISTICS_update (GDS_stats, | 1889 | GNUNET_STATISTICS_update (GDS_stats, |
1909 | gettext_noop ( | 1890 | "# FIND PEER requests ignored due to Bloomfilter", |
1910 | "# FIND PEER requests ignored due to Bloomfilter"), | ||
1911 | 1, | 1891 | 1, |
1912 | GNUNET_NO); | 1892 | GNUNET_NO); |
1913 | } | 1893 | } |
@@ -1915,17 +1895,16 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender, | |||
1915 | else | 1895 | else |
1916 | { | 1896 | { |
1917 | GNUNET_STATISTICS_update (GDS_stats, | 1897 | GNUNET_STATISTICS_update (GDS_stats, |
1918 | gettext_noop ( | 1898 | "# FIND PEER requests ignored due to lack of HELLO", |
1919 | "# FIND PEER requests ignored due to lack of HELLO"), | ||
1920 | 1, | 1899 | 1, |
1921 | GNUNET_NO); | 1900 | GNUNET_NO); |
1922 | } | 1901 | } |
1923 | 1902 | ||
1924 | /* then, also consider sending a random HELLO from the closest bucket */ | 1903 | /* then, also consider sending a random HELLO from the closest bucket */ |
1925 | /* FIXME: How can this be true? Shouldnt we just do find_bucket() ? */ | 1904 | /* FIXME: How can this be true? Shouldnt we just do find_bucket() ? */ |
1926 | if (0 == memcmp (&my_identity_hash, | 1905 | if (0 == |
1927 | key, | 1906 | GNUNET_memcmp (&my_identity_hash, |
1928 | sizeof(struct GNUNET_HashCode))) | 1907 | key)) |
1929 | bucket_idx = closest_bucket; | 1908 | bucket_idx = closest_bucket; |
1930 | else | 1909 | else |
1931 | bucket_idx = GNUNET_MIN ((int) closest_bucket, | 1910 | bucket_idx = GNUNET_MIN ((int) closest_bucket, |
@@ -2005,15 +1984,17 @@ handle_local_result (void *cls, | |||
2005 | size_t data_size) | 1984 | size_t data_size) |
2006 | { | 1985 | { |
2007 | struct PeerInfo *peer = cls; | 1986 | struct PeerInfo *peer = cls; |
2008 | char *pp; | 1987 | { |
1988 | char *pp; | ||
2009 | 1989 | ||
2010 | pp = GNUNET_STRINGS_pp2s (put_path, | 1990 | pp = GNUNET_STRINGS_pp2s (put_path, |
2011 | put_path_length); | 1991 | put_path_length); |
2012 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1992 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2013 | "Found local result for %s (PP: %s)\n", | 1993 | "Found local result for %s (PP: %s)\n", |
2014 | GNUNET_h2s (key), | 1994 | GNUNET_h2s (key), |
2015 | pp); | 1995 | pp); |
2016 | GNUNET_free (pp); | 1996 | GNUNET_free (pp); |
1997 | } | ||
2017 | GDS_NEIGHBOURS_handle_reply (peer->id, | 1998 | GDS_NEIGHBOURS_handle_reply (peer->id, |
2018 | type, | 1999 | type, |
2019 | expiration_time, | 2000 | expiration_time, |
@@ -2031,7 +2012,7 @@ handle_local_result (void *cls, | |||
2031 | * @param get the message | 2012 | * @param get the message |
2032 | * @return #GNUNET_OK if the message is well-formed | 2013 | * @return #GNUNET_OK if the message is well-formed |
2033 | */ | 2014 | */ |
2034 | static int | 2015 | static enum GNUNET_GenericReturnValue |
2035 | check_dht_p2p_get (void *cls, | 2016 | check_dht_p2p_get (void *cls, |
2036 | const struct PeerGetMessage *get) | 2017 | const struct PeerGetMessage *get) |
2037 | { | 2018 | { |
@@ -2066,11 +2047,11 @@ handle_dht_p2p_get (void *cls, | |||
2066 | uint16_t msize; | 2047 | uint16_t msize; |
2067 | enum GNUNET_BLOCK_Type type; | 2048 | enum GNUNET_BLOCK_Type type; |
2068 | enum GNUNET_DHT_RouteOption options; | 2049 | enum GNUNET_DHT_RouteOption options; |
2069 | enum GNUNET_BLOCK_EvaluationResult eval; | 2050 | enum GNUNET_BLOCK_ReplyEvaluationResult eval = GNUNET_BLOCK_REPLY_OK_MORE; |
2070 | struct GNUNET_BLOCK_Group *bg; | 2051 | struct GNUNET_BLOCK_Group *bg; |
2071 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; | 2052 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; |
2072 | const char *xquery; | 2053 | const void *xquery; |
2073 | int forwarded; | 2054 | enum GNUNET_GenericReturnValue forwarded; |
2074 | 2055 | ||
2075 | /* parse and validate message */ | 2056 | /* parse and validate message */ |
2076 | msize = ntohs (get->header.size); | 2057 | msize = ntohs (get->header.size); |
@@ -2078,7 +2059,7 @@ handle_dht_p2p_get (void *cls, | |||
2078 | reply_bf_size = msize - (sizeof(struct PeerGetMessage) + xquery_size); | 2059 | reply_bf_size = msize - (sizeof(struct PeerGetMessage) + xquery_size); |
2079 | type = ntohl (get->type); | 2060 | type = ntohl (get->type); |
2080 | options = ntohl (get->options); | 2061 | options = ntohl (get->options); |
2081 | xquery = (const char *) &get[1]; | 2062 | xquery = (const void *) &get[1]; |
2082 | GNUNET_STATISTICS_update (GDS_stats, | 2063 | GNUNET_STATISTICS_update (GDS_stats, |
2083 | gettext_noop ("# P2P GET requests received"), | 2064 | gettext_noop ("# P2P GET requests received"), |
2084 | 1, | 2065 | 1, |
@@ -2103,23 +2084,18 @@ handle_dht_p2p_get (void *cls, | |||
2103 | GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, | 2084 | GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, |
2104 | &get->key), | 2085 | &get->key), |
2105 | ntohl (get->xquery_size), | 2086 | ntohl (get->xquery_size), |
2106 | xquery); | 2087 | (const char *) xquery); |
2107 | GNUNET_free (tmp); | 2088 | GNUNET_free (tmp); |
2108 | } | 2089 | } |
2109 | eval | 2090 | if (GNUNET_NO == |
2110 | = GNUNET_BLOCK_evaluate (GDS_block_context, | 2091 | GNUNET_BLOCK_check_query (GDS_block_context, |
2111 | type, | 2092 | type, |
2112 | NULL, | 2093 | &get->key, |
2113 | GNUNET_BLOCK_EO_NONE, | 2094 | xquery, |
2114 | &get->key, | 2095 | xquery_size)) |
2115 | xquery, | ||
2116 | xquery_size, | ||
2117 | NULL, | ||
2118 | 0); | ||
2119 | if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID) | ||
2120 | { | 2096 | { |
2121 | /* request invalid or block type not supported */ | 2097 | /* request invalid */ |
2122 | GNUNET_break_op (eval == GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED); | 2098 | GNUNET_break_op (0); |
2123 | return; | 2099 | return; |
2124 | } | 2100 | } |
2125 | peer_bf = GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, | 2101 | peer_bf = GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, |
@@ -2131,7 +2107,7 @@ handle_dht_p2p_get (void *cls, | |||
2131 | bg = GNUNET_BLOCK_group_create (GDS_block_context, | 2107 | bg = GNUNET_BLOCK_group_create (GDS_block_context, |
2132 | type, | 2108 | type, |
2133 | get->bf_mutator, | 2109 | get->bf_mutator, |
2134 | &xquery[xquery_size], | 2110 | xquery + xquery_size, |
2135 | reply_bf_size, | 2111 | reply_bf_size, |
2136 | "filter-size", | 2112 | "filter-size", |
2137 | reply_bf_size, | 2113 | reply_bf_size, |
@@ -2142,15 +2118,14 @@ handle_dht_p2p_get (void *cls, | |||
2142 | GNUNET_i2s (&my_identity), | 2118 | GNUNET_i2s (&my_identity), |
2143 | (unsigned int) ntohl (get->hop_count)); | 2119 | (unsigned int) ntohl (get->hop_count)); |
2144 | /* local lookup (this may update the reply_bf) */ | 2120 | /* local lookup (this may update the reply_bf) */ |
2145 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || | 2121 | if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || |
2146 | (GDS_am_closest_peer (&get->key, | 2122 | (GDS_am_closest_peer (&get->key, |
2147 | peer_bf))) | 2123 | peer_bf)) ) |
2148 | { | 2124 | { |
2149 | if ((0 != (options & GNUNET_DHT_RO_FIND_PEER))) | 2125 | if ((0 != (options & GNUNET_DHT_RO_FIND_PEER))) |
2150 | { | 2126 | { |
2151 | GNUNET_STATISTICS_update (GDS_stats, | 2127 | GNUNET_STATISTICS_update (GDS_stats, |
2152 | gettext_noop ( | 2128 | "# P2P FIND PEER requests processed", |
2153 | "# P2P FIND PEER requests processed"), | ||
2154 | 1, | 2129 | 1, |
2155 | GNUNET_NO); | 2130 | GNUNET_NO); |
2156 | handle_find_peer (peer->id, | 2131 | handle_find_peer (peer->id, |
@@ -2171,7 +2146,7 @@ handle_dht_p2p_get (void *cls, | |||
2171 | else | 2146 | else |
2172 | { | 2147 | { |
2173 | GNUNET_STATISTICS_update (GDS_stats, | 2148 | GNUNET_STATISTICS_update (GDS_stats, |
2174 | gettext_noop ("# P2P GET requests ONLY routed"), | 2149 | "# P2P GET requests ONLY routed", |
2175 | 1, | 2150 | 1, |
2176 | GNUNET_NO); | 2151 | GNUNET_NO); |
2177 | } | 2152 | } |
@@ -2187,7 +2162,7 @@ handle_dht_p2p_get (void *cls, | |||
2187 | 2162 | ||
2188 | /* P2P forwarding */ | 2163 | /* P2P forwarding */ |
2189 | forwarded = GNUNET_NO; | 2164 | forwarded = GNUNET_NO; |
2190 | if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) | 2165 | if (eval != GNUNET_BLOCK_REPLY_OK_LAST) |
2191 | forwarded = GDS_NEIGHBOURS_handle_get (type, | 2166 | forwarded = GDS_NEIGHBOURS_handle_get (type, |
2192 | options, | 2167 | options, |
2193 | ntohl ( | 2168 | ntohl ( |
@@ -2220,7 +2195,7 @@ handle_dht_p2p_get (void *cls, | |||
2220 | * @param message message | 2195 | * @param message message |
2221 | * @return #GNUNET_YES if the message is well-formed | 2196 | * @return #GNUNET_YES if the message is well-formed |
2222 | */ | 2197 | */ |
2223 | static int | 2198 | static enum GNUNET_GenericReturnValue |
2224 | check_dht_p2p_result (void *cls, | 2199 | check_dht_p2p_result (void *cls, |
2225 | const struct PeerResultMessage *prm) | 2200 | const struct PeerResultMessage *prm) |
2226 | { | 2201 | { |
@@ -2252,7 +2227,8 @@ check_dht_p2p_result (void *cls, | |||
2252 | * Process a reply, after the @a get_path has been updated. | 2227 | * Process a reply, after the @a get_path has been updated. |
2253 | * | 2228 | * |
2254 | * @param expiration_time when does the reply expire | 2229 | * @param expiration_time when does the reply expire |
2255 | * @param key key matching the query | 2230 | * @param key key of the original inquiry |
2231 | * @param query_hash key matching the block | ||
2256 | * @param get_path_length number of entries in @a get_path | 2232 | * @param get_path_length number of entries in @a get_path |
2257 | * @param get_path path the reply has taken | 2233 | * @param get_path path the reply has taken |
2258 | * @param put_path_length number of entries in @a put_path | 2234 | * @param put_path_length number of entries in @a put_path |
@@ -2264,6 +2240,7 @@ check_dht_p2p_result (void *cls, | |||
2264 | static void | 2240 | static void |
2265 | process_reply_with_path (struct GNUNET_TIME_Absolute expiration_time, | 2241 | process_reply_with_path (struct GNUNET_TIME_Absolute expiration_time, |
2266 | const struct GNUNET_HashCode *key, | 2242 | const struct GNUNET_HashCode *key, |
2243 | const struct GNUNET_HashCode *query_hash, | ||
2267 | unsigned int get_path_length, | 2244 | unsigned int get_path_length, |
2268 | const struct GNUNET_PeerIdentity *get_path, | 2245 | const struct GNUNET_PeerIdentity *get_path, |
2269 | unsigned int put_path_length, | 2246 | unsigned int put_path_length, |
@@ -2275,6 +2252,7 @@ process_reply_with_path (struct GNUNET_TIME_Absolute expiration_time, | |||
2275 | /* forward to local clients */ | 2252 | /* forward to local clients */ |
2276 | GDS_CLIENTS_handle_reply (expiration_time, | 2253 | GDS_CLIENTS_handle_reply (expiration_time, |
2277 | key, | 2254 | key, |
2255 | query_hash, | ||
2278 | get_path_length, | 2256 | get_path_length, |
2279 | get_path, | 2257 | get_path, |
2280 | put_path_length, | 2258 | put_path_length, |
@@ -2288,7 +2266,7 @@ process_reply_with_path (struct GNUNET_TIME_Absolute expiration_time, | |||
2288 | put_path, | 2266 | put_path, |
2289 | put_path_length, | 2267 | put_path_length, |
2290 | expiration_time, | 2268 | expiration_time, |
2291 | key, | 2269 | query_hash, |
2292 | data, | 2270 | data, |
2293 | data_size); | 2271 | data_size); |
2294 | if (GNUNET_YES == cache_results) | 2272 | if (GNUNET_YES == cache_results) |
@@ -2303,7 +2281,7 @@ process_reply_with_path (struct GNUNET_TIME_Absolute expiration_time, | |||
2303 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); | 2281 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); |
2304 | 2282 | ||
2305 | GDS_DATACACHE_handle_put (expiration_time, | 2283 | GDS_DATACACHE_handle_put (expiration_time, |
2306 | key, | 2284 | query_hash, |
2307 | get_path_length + put_path_length, | 2285 | get_path_length + put_path_length, |
2308 | xput_path, | 2286 | xput_path, |
2309 | type, | 2287 | type, |
@@ -2343,6 +2321,8 @@ handle_dht_p2p_result (void *cls, | |||
2343 | size_t data_size; | 2321 | size_t data_size; |
2344 | enum GNUNET_BLOCK_Type type; | 2322 | enum GNUNET_BLOCK_Type type; |
2345 | struct GNUNET_TIME_Absolute exp_time; | 2323 | struct GNUNET_TIME_Absolute exp_time; |
2324 | const struct GNUNET_HashCode *pquery; | ||
2325 | struct GNUNET_HashCode dquery; | ||
2346 | 2326 | ||
2347 | /* parse and validate message */ | 2327 | /* parse and validate message */ |
2348 | exp_time = GNUNET_TIME_absolute_ntoh (prm->expiration_time); | 2328 | exp_time = GNUNET_TIME_absolute_ntoh (prm->expiration_time); |
@@ -2363,8 +2343,8 @@ handle_dht_p2p_result (void *cls, | |||
2363 | data = (const void *) &get_path[get_path_length]; | 2343 | data = (const void *) &get_path[get_path_length]; |
2364 | data_size = msize - (sizeof(struct PeerResultMessage) | 2344 | data_size = msize - (sizeof(struct PeerResultMessage) |
2365 | + (get_path_length | 2345 | + (get_path_length |
2366 | + put_path_length) * sizeof(struct | 2346 | + put_path_length) |
2367 | GNUNET_PeerIdentity)); | 2347 | * sizeof(struct GNUNET_PeerIdentity)); |
2368 | GNUNET_STATISTICS_update (GDS_stats, | 2348 | GNUNET_STATISTICS_update (GDS_stats, |
2369 | gettext_noop ("# P2P RESULTS received"), | 2349 | gettext_noop ("# P2P RESULTS received"), |
2370 | 1, | 2350 | 1, |
@@ -2373,6 +2353,31 @@ handle_dht_p2p_result (void *cls, | |||
2373 | gettext_noop ("# P2P RESULT bytes received"), | 2353 | gettext_noop ("# P2P RESULT bytes received"), |
2374 | msize, | 2354 | msize, |
2375 | GNUNET_NO); | 2355 | GNUNET_NO); |
2356 | { | ||
2357 | enum GNUNET_GenericReturnValue ret; | ||
2358 | |||
2359 | ret = GNUNET_BLOCK_get_key (GDS_block_context, | ||
2360 | type, | ||
2361 | data, | ||
2362 | data_size, | ||
2363 | &dquery); | ||
2364 | if (GNUNET_NO == ret) | ||
2365 | { | ||
2366 | GNUNET_break_op (0); | ||
2367 | return; | ||
2368 | } | ||
2369 | pquery = (GNUNET_OK == ret) ? &dquery : &prm->key; | ||
2370 | if (GNUNET_OK != | ||
2371 | GNUNET_BLOCK_check_block (GDS_block_context, | ||
2372 | type, | ||
2373 | pquery, | ||
2374 | data, | ||
2375 | data_size)) | ||
2376 | { | ||
2377 | GNUNET_break_op (0); | ||
2378 | return; | ||
2379 | } | ||
2380 | } | ||
2376 | if (GNUNET_YES == log_route_details_stderr) | 2381 | if (GNUNET_YES == log_route_details_stderr) |
2377 | { | 2382 | { |
2378 | char *tmp; | 2383 | char *tmp; |
@@ -2421,9 +2426,8 @@ handle_dht_p2p_result (void *cls, | |||
2421 | return; | 2426 | return; |
2422 | } | 2427 | } |
2423 | if ((GNUNET_YES != disable_try_connect) && | 2428 | if ((GNUNET_YES != disable_try_connect) && |
2424 | (0 != memcmp (&my_identity, | 2429 | (0 != GNUNET_memcmp (&my_identity, |
2425 | &pid, | 2430 | &pid))) |
2426 | sizeof(struct GNUNET_PeerIdentity)))) | ||
2427 | try_connect (&pid, | 2431 | try_connect (&pid, |
2428 | h); | 2432 | h); |
2429 | } | 2433 | } |
@@ -2431,12 +2435,12 @@ handle_dht_p2p_result (void *cls, | |||
2431 | /* First, check if 'peer' is already on the path, and if | 2435 | /* First, check if 'peer' is already on the path, and if |
2432 | so, truncate it instead of expanding. */ | 2436 | so, truncate it instead of expanding. */ |
2433 | for (unsigned int i = 0; i <= get_path_length; i++) | 2437 | for (unsigned int i = 0; i <= get_path_length; i++) |
2434 | if (0 == memcmp (&get_path[i], | 2438 | if (0 == GNUNET_memcmp (&get_path[i], |
2435 | peer->id, | 2439 | peer->id)) |
2436 | sizeof(struct GNUNET_PeerIdentity))) | ||
2437 | { | 2440 | { |
2438 | process_reply_with_path (exp_time, | 2441 | process_reply_with_path (exp_time, |
2439 | &prm->key, | 2442 | &prm->key, |
2443 | pquery, | ||
2440 | i, | 2444 | i, |
2441 | get_path, | 2445 | get_path, |
2442 | put_path_length, | 2446 | put_path_length, |
@@ -2455,9 +2459,9 @@ handle_dht_p2p_result (void *cls, | |||
2455 | get_path, | 2459 | get_path, |
2456 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); | 2460 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); |
2457 | xget_path[get_path_length] = *peer->id; | 2461 | xget_path[get_path_length] = *peer->id; |
2458 | |||
2459 | process_reply_with_path (exp_time, | 2462 | process_reply_with_path (exp_time, |
2460 | &prm->key, | 2463 | &prm->key, |
2464 | pquery, | ||
2461 | get_path_length + 1, | 2465 | get_path_length + 1, |
2462 | xget_path, | 2466 | xget_path, |
2463 | put_path_length, | 2467 | put_path_length, |
@@ -2469,12 +2473,7 @@ handle_dht_p2p_result (void *cls, | |||
2469 | } | 2473 | } |
2470 | 2474 | ||
2471 | 2475 | ||
2472 | /** | 2476 | enum GNUNET_GenericReturnValue |
2473 | * Initialize neighbours subsystem. | ||
2474 | * | ||
2475 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
2476 | */ | ||
2477 | int | ||
2478 | GDS_NEIGHBOURS_init () | 2477 | GDS_NEIGHBOURS_init () |
2479 | { | 2478 | { |
2480 | struct GNUNET_MQ_MessageHandler core_handlers[] = { | 2479 | struct GNUNET_MQ_MessageHandler core_handlers[] = { |
@@ -2528,9 +2527,6 @@ GDS_NEIGHBOURS_init () | |||
2528 | } | 2527 | } |
2529 | 2528 | ||
2530 | 2529 | ||
2531 | /** | ||
2532 | * Shutdown neighbours subsystem. | ||
2533 | */ | ||
2534 | void | 2530 | void |
2535 | GDS_NEIGHBOURS_done () | 2531 | GDS_NEIGHBOURS_done () |
2536 | { | 2532 | { |
@@ -2553,11 +2549,6 @@ GDS_NEIGHBOURS_done () | |||
2553 | } | 2549 | } |
2554 | 2550 | ||
2555 | 2551 | ||
2556 | /** | ||
2557 | * Get the ID of the local node. | ||
2558 | * | ||
2559 | * @return identity of the local node | ||
2560 | */ | ||
2561 | struct GNUNET_PeerIdentity * | 2552 | struct GNUNET_PeerIdentity * |
2562 | GDS_NEIGHBOURS_get_id () | 2553 | GDS_NEIGHBOURS_get_id () |
2563 | { | 2554 | { |