aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/gnunet-dht-get.c22
-rw-r--r--src/dht/gnunet-dht-monitor.c27
-rw-r--r--src/dht/gnunet-service-dht_datacache.c6
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c14
-rw-r--r--src/dht/gnunet-service-dht_neighbours.h22
5 files changed, 64 insertions, 27 deletions
diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c
index 842ec6270e..afcd5422cc 100644
--- a/src/dht/gnunet-dht-get.c
+++ b/src/dht/gnunet-dht-get.c
@@ -154,7 +154,9 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
const void *data)
{
FPRINTF (stdout,
- _("Result %d, type %d:\n%.*s\n"),
+ (GNUNET_BLOCK_TYPE_TEST == type)
+ ? _("Result %d, type %d:\n%.*s\n")
+ : _("Result %d, type %d:\n"),
result_count,
type,
(unsigned int) size,
@@ -196,8 +198,6 @@ run (void *cls, char *const *args, const char *cfgfile,
{
struct GNUNET_HashCode key;
-
-
cfg = c;
if (NULL == query_key)
{
@@ -215,17 +215,22 @@ run (void *cls, char *const *args, const char *cfgfile,
query_type = GNUNET_BLOCK_TYPE_TEST;
GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
if (verbose)
- FPRINTF (stderr, "%s `%s' \n", _("Issueing DHT GET with key"), GNUNET_h2s_full (&key));
+ FPRINTF (stderr, "%s `%s' \n",
+ _("Issueing DHT GET with key"),
+ GNUNET_h2s_full (&key));
GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL);
tt = GNUNET_SCHEDULER_add_delayed (timeout_request,
- &timeout_task, NULL);
+ &timeout_task,
+ NULL);
get_handle =
GNUNET_DHT_get_start (dht_handle, query_type, &key, replication,
(demultixplex_everywhere) ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE : GNUNET_DHT_RO_NONE,
- NULL, 0, &get_result_iterator, NULL);
-
+ NULL, 0,
+ &get_result_iterator,
+ NULL);
}
+
/**
* Entry point for gnunet-dht-get
*
@@ -236,15 +241,12 @@ run (void *cls, char *const *args, const char *cfgfile,
int
main (int argc, char *const *argv)
{
-
struct GNUNET_GETOPT_CommandLineOption options[] = {
-
GNUNET_GETOPT_option_string ('k',
"key",
"KEY",
gettext_noop ("the query key"),
&query_key),
-
GNUNET_GETOPT_option_uint ('r',
"replication",
"LEVEL",
diff --git a/src/dht/gnunet-dht-monitor.c b/src/dht/gnunet-dht-monitor.c
index b7360bbabc..a699b3d175 100644
--- a/src/dht/gnunet-dht-monitor.c
+++ b/src/dht/gnunet-dht-monitor.c
@@ -141,7 +141,8 @@ get_callback (void *cls,
const struct GNUNET_PeerIdentity *path,
const struct GNUNET_HashCode * key)
{
- FPRINTF (stdout, "GET #%u: type %d, key `%s'\n",
+ FPRINTF (stdout,
+ "GET #%u: type %d, key `%s'\n",
result_count,
(int) type,
GNUNET_h2s_full(key));
@@ -176,8 +177,11 @@ get_resp_callback (void *cls,
size_t size)
{
FPRINTF (stdout,
- "RESPONSE #%u: type %d, key `%s', data `%.*s'\n",
+ (GNUNET_BLOCK_TYPE_TEST == type)
+ ? "RESPONSE #%u (%s): type %d, key `%s', data `%.*s'\n"
+ : "RESPONSE #%u (%s): type %d, key `%s'\n",
result_count,
+ GNUNET_STRINGS_absolute_time_to_string (exp),
(int) type,
GNUNET_h2s_full (key),
(unsigned int) size,
@@ -215,8 +219,11 @@ put_callback (void *cls,
size_t size)
{
FPRINTF (stdout,
- "PUT %u: type %d, key `%s', data `%.*s'\n",
+ (GNUNET_BLOCK_TYPE_TEST == type)
+ ? "PUT %u (%s): type %d, key `%s', data `%.*s'\n"
+ : "PUT %u (%s): type %d, key `%s'\n",
result_count,
+ GNUNET_STRINGS_absolute_time_to_string (exp),
(int) type,
GNUNET_h2s_full(key),
(unsigned int) size,
@@ -234,7 +241,9 @@ put_callback (void *cls,
* @param c configuration
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
{
struct GNUNET_HashCode *key;
@@ -291,30 +300,30 @@ int
main (int argc, char *const *argv)
{
struct GNUNET_GETOPT_CommandLineOption options[] = {
-
+
GNUNET_GETOPT_option_string ('k',
"key",
"KEY",
gettext_noop ("the query key"),
&query_key),
-
+
GNUNET_GETOPT_option_uint ('t',
"type",
"TYPE",
gettext_noop ("the type of data to look for"),
&block_type),
-
+
GNUNET_GETOPT_option_relative_time ('T',
"timeout",
"TIMEOUT",
gettext_noop ("how long should the monitor command run"),
&timeout_request),
-
+
GNUNET_GETOPT_option_flag ('V',
"verbose",
gettext_noop ("be verbose (print progress information)"),
&verbose),
-
+
GNUNET_GETOPT_OPTION_END
};
diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c
index 36047d5619..07a666db61 100644
--- a/src/dht/gnunet-service-dht_datacache.c
+++ b/src/dht/gnunet-service-dht_datacache.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_datacache_lib.h"
#include "gnunet-service-dht_datacache.h"
+#include "gnunet-service-dht_neighbours.h"
#include "gnunet-service-dht_routing.h"
#include "gnunet-service-dht.h"
@@ -79,10 +80,13 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
}
/* Put size is actual data size plus struct overhead plus path length (if any) */
GNUNET_STATISTICS_update (GDS_stats,
- gettext_noop ("# ITEMS stored in datacache"), 1,
+ gettext_noop ("# ITEMS stored in datacache"),
+ 1,
GNUNET_NO);
r = GNUNET_DATACACHE_put (datacache,
key,
+ GNUNET_CRYPTO_hash_matching_bits (key,
+ &my_identity_hash),
data_size,
data,
type,
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 0309bea880..94844374de 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -404,7 +404,7 @@ static struct GNUNET_PeerIdentity my_identity;
/**
* Hash of the identity of this peer.
*/
-static struct GNUNET_HashCode my_identity_hash;
+struct GNUNET_HashCode my_identity_hash;
/**
* Handle to CORE.
@@ -421,7 +421,7 @@ static struct GNUNET_ATS_ConnectivityHandle *ats_ch;
* Find the optimal bucket for this key.
*
* @param hc the hashcode to compare our identity to
- * @return the proper bucket index, or GNUNET_SYSERR
+ * @return the proper bucket index, or #GNUNET_SYSERR
* on error (same hashcode)
*/
static int
@@ -941,9 +941,9 @@ get_distance (const struct GNUNET_HashCode *target,
* @return #GNUNET_YES if node location is closest,
* #GNUNET_NO otherwise.
*/
-static int
-am_closest_peer (const struct GNUNET_HashCode *key,
- const struct GNUNET_CONTAINER_BloomFilter *bloom)
+int
+GDS_am_closest_peer (const struct GNUNET_HashCode *key,
+ const struct GNUNET_CONTAINER_BloomFilter *bloom)
{
int bits;
int other_bits;
@@ -1803,7 +1803,7 @@ handle_dht_p2p_put (void *cls,
payload);
/* store locally */
if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
- (am_closest_peer (&put->key, bf)))
+ (GDS_am_closest_peer (&put->key, bf)))
GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time),
&put->key,
putlen,
@@ -2122,7 +2122,7 @@ handle_dht_p2p_get (void *cls,
(unsigned int) ntohl (get->hop_count));
/* local lookup (this may update the reply_bf) */
if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
- (am_closest_peer (&get->key,
+ (GDS_am_closest_peer (&get->key,
peer_bf)))
{
if ((0 != (options & GNUNET_DHT_RO_FIND_PEER)))
diff --git a/src/dht/gnunet-service-dht_neighbours.h b/src/dht/gnunet-service-dht_neighbours.h
index 34b76ee8a2..bf3ed80a23 100644
--- a/src/dht/gnunet-service-dht_neighbours.h
+++ b/src/dht/gnunet-service-dht_neighbours.h
@@ -32,6 +32,12 @@
#include "gnunet_dht_service.h"
/**
+ * Hash of the identity of this peer.
+ */
+extern struct GNUNET_HashCode my_identity_hash;
+
+
+/**
* Perform a PUT operation. Forwards the given request to other
* peers. Does not store the data locally. Does not give the
* data to local clients. May do nothing if this is the only
@@ -123,6 +129,22 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
/**
+ * Check whether my identity is closer than any known peers. If a
+ * non-null bloomfilter is given, check if this is the closest peer
+ * that hasn't already been routed to.
+ *
+ * @param key hash code to check closeness to
+ * @param bloom bloomfilter, exclude these entries from the decision
+ * @return #GNUNET_YES if node location is closest,
+ * #GNUNET_NO otherwise.
+ */
+int
+GDS_am_closest_peer (const struct GNUNET_HashCode *key,
+ const struct GNUNET_CONTAINER_BloomFilter *bloom);
+
+
+
+/**
* Initialize neighbours subsystem.
*
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error