diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-09-23 10:50:28 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-09-23 10:50:28 +0000 |
commit | 7bcb01815e30bab21204f1d974f727130b2a7884 (patch) | |
tree | 20baa8c7ab8f6d7e216200ca50730e558adc62aa | |
parent | e730bd4b9d68a38b3d4277f6222369de61da8225 (diff) | |
download | gnunet-7bcb01815e30bab21204f1d974f727130b2a7884.tar.gz gnunet-7bcb01815e30bab21204f1d974f727130b2a7884.zip |
add option to cache blocks from result messages as well
-rw-r--r-- | src/dht/dht.conf.in | 2 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_clients.c | 29 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 52 |
3 files changed, 60 insertions, 23 deletions
diff --git a/src/dht/dht.conf.in b/src/dht/dht.conf.in index 2802111df..59c5bc1b7 100644 --- a/src/dht/dht.conf.in +++ b/src/dht/dht.conf.in | |||
@@ -21,6 +21,8 @@ UNIX_MATCH_GID = YES | |||
21 | # REJECT_FROM6 = | 21 | # REJECT_FROM6 = |
22 | # PREFIX = | 22 | # PREFIX = |
23 | 23 | ||
24 | # Should the DHT cache results that we are routing in the DATACACHE as well? | ||
25 | CACHE_RESULTS = YES | ||
24 | 26 | ||
25 | # Special option to disable DHT calling 'try_connect' (for testing) | 27 | # Special option to disable DHT calling 'try_connect' (for testing) |
26 | DISABLE_TRY_CONNECT = NO | 28 | DISABLE_TRY_CONNECT = NO |
diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c index 70b1500cc..20fbba789 100644 --- a/src/dht/gnunet-service-dht_clients.c +++ b/src/dht/gnunet-service-dht_clients.c | |||
@@ -312,7 +312,7 @@ find_active_client (struct GNUNET_SERVER_Client *client) | |||
312 | return pos; | 312 | return pos; |
313 | pos = pos->next; | 313 | pos = pos->next; |
314 | } | 314 | } |
315 | ret = GNUNET_malloc (sizeof (struct ClientList)); | 315 | ret = GNUNET_new (struct ClientList); |
316 | ret->client_handle = client; | 316 | ret->client_handle = client; |
317 | GNUNET_CONTAINER_DLL_insert (client_head, client_tail, ret); | 317 | GNUNET_CONTAINER_DLL_insert (client_head, client_tail, ret); |
318 | return ret; | 318 | return ret; |
@@ -326,7 +326,7 @@ find_active_client (struct GNUNET_SERVER_Client *client) | |||
326 | * @param cls client to search for in source routes | 326 | * @param cls client to search for in source routes |
327 | * @param key current key code (ignored) | 327 | * @param key current key code (ignored) |
328 | * @param value value in the hash map, a ClientQueryRecord | 328 | * @param value value in the hash map, a ClientQueryRecord |
329 | * @return GNUNET_YES (we should continue to iterate) | 329 | * @return #GNUNET_YES (we should continue to iterate) |
330 | */ | 330 | */ |
331 | static int | 331 | static int |
332 | remove_client_records (void *cls, const struct GNUNET_HashCode * key, void *value) | 332 | remove_client_records (void *cls, const struct GNUNET_HashCode * key, void *value) |
@@ -359,13 +359,16 @@ remove_client_records (void *cls, const struct GNUNET_HashCode * key, void *valu | |||
359 | * for the last call when the server is destroyed | 359 | * for the last call when the server is destroyed |
360 | */ | 360 | */ |
361 | static void | 361 | static void |
362 | handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | 362 | handle_client_disconnect (void *cls, |
363 | struct GNUNET_SERVER_Client *client) | ||
363 | { | 364 | { |
364 | struct ClientList *pos; | 365 | struct ClientList *pos; |
365 | struct PendingMessage *reply; | 366 | struct PendingMessage *reply; |
366 | struct ClientMonitorRecord *monitor; | 367 | struct ClientMonitorRecord *monitor; |
367 | 368 | ||
368 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Local client %p disconnects\n", client); | 369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
370 | "Local client %p disconnects\n", | ||
371 | client); | ||
369 | pos = find_active_client (client); | 372 | pos = find_active_client (client); |
370 | GNUNET_CONTAINER_DLL_remove (client_head, client_tail, pos); | 373 | GNUNET_CONTAINER_DLL_remove (client_head, client_tail, pos); |
371 | if (pos->transmit_handle != NULL) | 374 | if (pos->transmit_handle != NULL) |
@@ -1021,8 +1024,9 @@ forward_reply (void *cls, const struct GNUNET_HashCode * key, void *value) | |||
1021 | struct GNUNET_HashCode ch; | 1024 | struct GNUNET_HashCode ch; |
1022 | unsigned int i; | 1025 | unsigned int i; |
1023 | 1026 | ||
1024 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, "XDHT CLIENT-RESULT %s @ %u\n", | 1027 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, |
1025 | GNUNET_h2s (key), getpid ()); | 1028 | "XDHT CLIENT-RESULT %s\n", |
1029 | GNUNET_h2s (key)); | ||
1026 | if ((record->type != GNUNET_BLOCK_TYPE_ANY) && (record->type != frc->type)) | 1030 | if ((record->type != GNUNET_BLOCK_TYPE_ANY) && (record->type != frc->type)) |
1027 | { | 1031 | { |
1028 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1032 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1108,7 +1112,8 @@ forward_reply (void *cls, const struct GNUNET_HashCode * key, void *value) | |||
1108 | reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1]; | 1112 | reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1]; |
1109 | reply->unique_id = record->unique_id; | 1113 | reply->unique_id = record->unique_id; |
1110 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1114 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1111 | "Queueing reply to query %s for client %p\n", GNUNET_h2s (key), | 1115 | "Queueing reply to query %s for client %p\n", |
1116 | GNUNET_h2s (key), | ||
1112 | record->client->client_handle); | 1117 | record->client->client_handle); |
1113 | add_pending_message (record->client, pm); | 1118 | add_pending_message (record->client, pm); |
1114 | if (GNUNET_YES == do_free) | 1119 | if (GNUNET_YES == do_free) |
@@ -1124,12 +1129,12 @@ forward_reply (void *cls, const struct GNUNET_HashCode * key, void *value) | |||
1124 | * | 1129 | * |
1125 | * @param expiration when will the reply expire | 1130 | * @param expiration when will the reply expire |
1126 | * @param key the query this reply is for | 1131 | * @param key the query this reply is for |
1127 | * @param get_path_length number of peers in 'get_path' | 1132 | * @param get_path_length number of peers in @a get_path |
1128 | * @param get_path path the reply took on get | 1133 | * @param get_path path the reply took on get |
1129 | * @param put_path_length number of peers in 'put_path' | 1134 | * @param put_path_length number of peers in @a put_path |
1130 | * @param put_path path the reply took on put | 1135 | * @param put_path path the reply took on put |
1131 | * @param type type of the reply | 1136 | * @param type type of the reply |
1132 | * @param data_size number of bytes in 'data' | 1137 | * @param data_size number of bytes in @a data |
1133 | * @param data application payload data | 1138 | * @param data application payload data |
1134 | */ | 1139 | */ |
1135 | void | 1140 | void |
@@ -1148,7 +1153,9 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, | |||
1148 | struct GNUNET_PeerIdentity *paths; | 1153 | struct GNUNET_PeerIdentity *paths; |
1149 | size_t msize; | 1154 | size_t msize; |
1150 | 1155 | ||
1151 | LOG (GNUNET_ERROR_TYPE_DEBUG, "reply for key %s\n", GNUNET_h2s (key)); | 1156 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1157 | "reply for key %s\n", | ||
1158 | GNUNET_h2s (key)); | ||
1152 | 1159 | ||
1153 | if (NULL == GNUNET_CONTAINER_multihashmap_get (forward_map, key)) | 1160 | if (NULL == GNUNET_CONTAINER_multihashmap_get (forward_map, key)) |
1154 | { | 1161 | { |
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 | */ | ||
385 | static 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 | */ |
446 | static int | 452 | static int |
447 | find_bucket (const struct GNUNET_HashCode * hc) | 453 | find_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 | */ |
468 | static void | 474 | static 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 | */ |
540 | static int | 546 | static int |
541 | add_known_to_bloom (void *cls, const struct GNUNET_HashCode * key, void *value) | 547 | add_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 | */ |
680 | static void | 688 | static void |
681 | handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 689 | handle_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 | */ |
896 | static unsigned int | 907 | static unsigned int |
897 | get_distance (const struct GNUNET_HashCode * target, const struct GNUNET_HashCode * have) | 908 | get_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 | */ |
1794 | static int | 1806 | static int |
1795 | handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, | 1807 | handle_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 | */ |
1935 | static int | 1947 | static int |
1936 | handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer, | 1948 | handle_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 () | |||
2104 | void | 2132 | void |
2105 | GDS_NEIGHBOURS_done () | 2133 | GDS_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; |