aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht_neighbours.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-23 10:50:28 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-23 10:50:28 +0000
commit7bcb01815e30bab21204f1d974f727130b2a7884 (patch)
tree20baa8c7ab8f6d7e216200ca50730e558adc62aa /src/dht/gnunet-service-dht_neighbours.c
parente730bd4b9d68a38b3d4277f6222369de61da8225 (diff)
downloadgnunet-7bcb01815e30bab21204f1d974f727130b2a7884.tar.gz
gnunet-7bcb01815e30bab21204f1d974f727130b2a7884.zip
add option to cache blocks from result messages as well
Diffstat (limited to 'src/dht/gnunet-service-dht_neighbours.c')
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c52
1 files changed, 40 insertions, 12 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 6d3ec6d8c..87581f036 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -378,6 +378,12 @@ struct PeerBucket
378 unsigned int peers_size; 378 unsigned int peers_size;
379}; 379};
380 380
381
382/**
383 * Do we cache all results that we are routing in the local datacache?
384 */
385static int cache_results;
386
381/** 387/**
382 * Should routing details be logged to stderr (for debugging)? 388 * Should routing details be logged to stderr (for debugging)?
383 */ 389 */
@@ -444,7 +450,7 @@ static struct GNUNET_ATS_PerformanceHandle *atsAPI;
444 * on error (same hashcode) 450 * on error (same hashcode)
445 */ 451 */
446static int 452static int
447find_bucket (const struct GNUNET_HashCode * hc) 453find_bucket (const struct GNUNET_HashCode *hc)
448{ 454{
449 unsigned int bits; 455 unsigned int bits;
450 456
@@ -462,7 +468,7 @@ find_bucket (const struct GNUNET_HashCode * hc)
462/** 468/**
463 * Let GNUnet core know that we like the given peer. 469 * Let GNUnet core know that we like the given peer.
464 * 470 *
465 * @param cls the 'struct PeerInfo' of the peer 471 * @param cls the `struct PeerInfo` of the peer
466 * @param tc scheduler context. 472 * @param tc scheduler context.
467 */ 473 */
468static void 474static void
@@ -535,10 +541,12 @@ struct BloomConstructorContext
535 * @param cls the 'struct BloomConstructorContext'. 541 * @param cls the 'struct BloomConstructorContext'.
536 * @param key peer identity to add to the bloom filter 542 * @param key peer identity to add to the bloom filter
537 * @param value value the peer information (unused) 543 * @param value value the peer information (unused)
538 * @return GNUNET_YES (we should continue to iterate) 544 * @return #GNUNET_YES (we should continue to iterate)
539 */ 545 */
540static int 546static int
541add_known_to_bloom (void *cls, const struct GNUNET_HashCode * key, void *value) 547add_known_to_bloom (void *cls,
548 const struct GNUNET_HashCode *key,
549 void *value)
542{ 550{
543 struct BloomConstructorContext *ctx = cls; 551 struct BloomConstructorContext *ctx = cls;
544 struct GNUNET_HashCode mh; 552 struct GNUNET_HashCode mh;
@@ -678,7 +686,8 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
678 * @param peer peer identity this notification is about 686 * @param peer peer identity this notification is about
679 */ 687 */
680static void 688static void
681handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 689handle_core_disconnect (void *cls,
690 const struct GNUNET_PeerIdentity *peer)
682{ 691{
683 struct PeerInfo *to_remove; 692 struct PeerInfo *to_remove;
684 int current_bucket; 693 int current_bucket;
@@ -889,12 +898,15 @@ get_forward_count (uint32_t hop_count, uint32_t target_replication)
889 * Differences in the lower bits must count stronger than differences 898 * Differences in the lower bits must count stronger than differences
890 * in the higher bits. 899 * in the higher bits.
891 * 900 *
901 * @param target
902 * @param have
892 * @return 0 if have==target, otherwise a number 903 * @return 0 if have==target, otherwise a number
893 * that is larger as the distance between 904 * that is larger as the distance between
894 * the two hash codes increases 905 * the two hash codes increases
895 */ 906 */
896static unsigned int 907static unsigned int
897get_distance (const struct GNUNET_HashCode * target, const struct GNUNET_HashCode * have) 908get_distance (const struct GNUNET_HashCode *target,
909 const struct GNUNET_HashCode *have)
898{ 910{
899 unsigned int bucket; 911 unsigned int bucket;
900 unsigned int msb; 912 unsigned int msb;
@@ -1757,7 +1769,7 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1757 peer = bucket->head; 1769 peer = bucket->head;
1758 while (choice > 0) 1770 while (choice > 0)
1759 { 1771 {
1760 GNUNET_assert (peer != NULL); 1772 GNUNET_assert (NULL != peer);
1761 peer = peer->next; 1773 peer = peer->next;
1762 choice--; 1774 choice--;
1763 } 1775 }
@@ -1788,8 +1800,8 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1788 * @param cls closure 1800 * @param cls closure
1789 * @param peer sender of the request 1801 * @param peer sender of the request
1790 * @param message message 1802 * @param message message
1791 * @return GNUNET_OK to keep the connection open, 1803 * @return #GNUNET_OK to keep the connection open,
1792 * GNUNET_SYSERR to close it (signal serious error) 1804 * #GNUNET_SYSERR to close it (signal serious error)
1793 */ 1805 */
1794static int 1806static int
1795handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, 1807handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
@@ -1930,7 +1942,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
1930 * @param cls closure 1942 * @param cls closure
1931 * @param message message 1943 * @param message message
1932 * @param peer peer identity this notification is about 1944 * @param peer peer identity this notification is about
1933 * @return GNUNET_YES (do not cut p2p connection) 1945 * @return #GNUNET_YES (do not cut p2p connection)
1934 */ 1946 */
1935static int 1947static int
1936handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, 1948handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
@@ -2051,7 +2063,20 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
2051 &prm->key, 2063 &prm->key,
2052 data, 2064 data,
2053 data_size); 2065 data_size);
2054 2066 if (GNUNET_YES == cache_results)
2067 {
2068 struct GNUNET_PeerIdentity xput_path[get_path_length + 1 + put_path_length];
2069
2070 memcpy (xput_path, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity));
2071 memcpy (&xput_path[put_path_length],
2072 xget_path,
2073 get_path_length * sizeof (struct GNUNET_PeerIdentity));
2074
2075 GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (prm->expiration_time),
2076 &prm->key,
2077 get_path_length + put_path_length, xput_path,
2078 type, data_size, data);
2079 }
2055 /* forward to other peers */ 2080 /* forward to other peers */
2056 GDS_ROUTING_process (type, GNUNET_TIME_absolute_ntoh (prm->expiration_time), 2081 GDS_ROUTING_process (type, GNUNET_TIME_absolute_ntoh (prm->expiration_time),
2057 &prm->key, put_path_length, put_path, get_path_length, 2082 &prm->key, put_path_length, put_path, get_path_length,
@@ -2084,6 +2109,9 @@ GDS_NEIGHBOURS_init ()
2084 GNUNET_CONFIGURATION_get_value_number (GDS_cfg, "DHT", "bucket_size", 2109 GNUNET_CONFIGURATION_get_value_number (GDS_cfg, "DHT", "bucket_size",
2085 &temp_config_num)) 2110 &temp_config_num))
2086 bucket_size = (unsigned int) temp_config_num; 2111 bucket_size = (unsigned int) temp_config_num;
2112 cache_results
2113 = GNUNET_CONFIGURATION_get_value_yesno (GDS_cfg, "DHT", "CACHE_RESULTS");
2114
2087 log_route_details_stderr = 2115 log_route_details_stderr =
2088 (NULL != getenv("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO; 2116 (NULL != getenv("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO;
2089 atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL); 2117 atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL);
@@ -2104,7 +2132,7 @@ GDS_NEIGHBOURS_init ()
2104void 2132void
2105GDS_NEIGHBOURS_done () 2133GDS_NEIGHBOURS_done ()
2106{ 2134{
2107 if (coreAPI == NULL) 2135 if (NULL == coreAPI)
2108 return; 2136 return;
2109 GNUNET_CORE_disconnect (coreAPI); 2137 GNUNET_CORE_disconnect (coreAPI);
2110 coreAPI = NULL; 2138 coreAPI = NULL;