$(top_builddir)/src/dht/libgnunetdht.la
test_dht_multipeer_DEPENDENCIES = \
libgnunetdht.la
-
-#test_hash_operations_SOURCES = \
-# test_hash_operations.c
-#test_hash_operations_LDADD = \
-# $(top_builddir)/src/util/libgnunetutil.la \
-# $(top_builddir)/src/testing/libgnunettesting.la \
-# $(top_builddir)/src/dht/libgnunetdht.la
test_dht_twopeer_SOURCES = \
test_dht_twopeer.c
test_dht_twopeer_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/testing/libgnunettesting.la \
- $(top_builddir)/src/dht/libgnunetdht.la
+ $(top_builddir)/src/dht/libgnunetdhtnew.la
test_dht_twopeer_DEPENDENCIES = \
libgnunetdht.la
test_dht_twopeer_put_get_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/testing/libgnunettesting.la \
- $(top_builddir)/src/dht/libgnunetdht.la
+ $(top_builddir)/src/dht/libgnunetdhtnew.la
test_dht_twopeer_get_put_SOURCES = \
test_dht_twopeer_get_put.c
#include "gnunet_util_lib.h"
#include "gnunet_transport_service.h"
#include "gnunet_hello_lib.h"
-#include "gnunet_dht_service.h"
+#include "gnunet_dht_service_new.h"
#include "gnunet_statistics_service.h"
#include "gnunet-service-dht.h"
#include "gnunet-service-dht_clients.h"
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
}
GNUNET_STATISTICS_update (GDS_stats,
gettext_noop ("# PUT requests received from clients"), 1,
#include "gnunet_datacache_lib.h"
#include "gnunet_transport_service.h"
#include "gnunet_hello_lib.h"
-#include "gnunet_dht_service.h"
+#include "gnunet_dht_service_new.h"
#include "gnunet_statistics_service.h"
#include "dht.h"
#include "gnunet-service-dht.h"
&peer->id.hashPubKey);
if (matching >= 64)
matching = 63;
- bucket = find_bucket(&peer->id.hashPubKey);
+ bucket = find_bucket (&peer->id.hashPubKey);
if (bucket == GNUNET_SYSERR)
preference = 0;
else
{
struct P2PPendingMessage *pending;
- if (NULL != (pending = peer->head))
+ if (NULL == (pending = peer->head))
return;
if (NULL != peer->th)
return;
+ GNUNET_STATISTICS_update (GDS_stats,
+ gettext_noop ("# Bytes of bandwdith requested from core"),
+ ntohs (pending->msg->size),
+ GNUNET_NO);
peer->th
= GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
pending->importance,
/* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */
target_value = target_value - forward_count;
random_value =
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, UINT32_MAX);
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
if (random_value < (target_value * UINT32_MAX))
forward_count++;
return forward_count;
smallest_distance = dist;
}
}
+ else
+ {
+ GNUNET_STATISTICS_update (GDS_stats,
+ gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1,
+ GNUNET_NO);
+ }
count++;
pos = pos->next;
}
}
+ if (NULL == chosen)
+ GNUNET_STATISTICS_update (GDS_stats,
+ gettext_noop ("# Peer selection failed"), 1,
+ GNUNET_NO);
return chosen;
}
pos = k_buckets[bc].head;
while ((pos != NULL) && (count < bucket_size))
{
- if (GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
+ if ( (bloom != NULL) &&
+ (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) )
{
+ GNUNET_STATISTICS_update (GDS_stats,
+ gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1,
+ GNUNET_NO);
pos = pos->next;
continue; /* Ignore bloomfiltered peers */
}
}
if (count == 0) /* No peers to select from! */
{
+ GNUNET_STATISTICS_update (GDS_stats,
+ gettext_noop ("# Peer selection failed"), 1,
+ GNUNET_NO);
return NULL;
}
/* Now actually choose a peer */
pos = k_buckets[bc].head;
while ((pos != NULL) && (count < bucket_size))
{
- if (GNUNET_YES ==
- GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))
+ if ( (bloom != NULL) &&
+ (GNUNET_YES ==
+ GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)) )
{
pos = pos->next;
continue; /* Ignore bloomfiltered peers */
{
nxt = select_peer (key, bloom, hop_count);
if (nxt == NULL)
- break;
+ break;
rtargets[off++] = nxt;
GNUNET_CONTAINER_bloomfilter_add (bloom, &nxt->id.hashPubKey);
}
ppm->desired_replication_level = htonl (desired_replication_level);
ppm->put_path_length = htonl (put_path_length);
ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_bloomfilter_get_raw_data (bf,
- ppm->bloomfilter,
- DHT_BLOOM_SIZE));
+ if (NULL != bf)
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_bloomfilter_get_raw_data (bf,
+ ppm->bloomfilter,
+ DHT_BLOOM_SIZE));
ppm->key = *key;
pp = (struct GNUNET_PeerIdentity*) &ppm[1];
memcpy (pp, put_path, sizeof (struct GNUNET_PeerIdentity) * put_path_length);
desired_replication_level,
&targets);
if (0 == target_count)
- return;
+ return;
reply_bf_size = GNUNET_CONTAINER_bloomfilter_get_size (reply_bf);
msize = xquery_size + sizeof (struct PeerGetMessage) + reply_bf_size;
if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
pgm->desired_replication_level = htonl (desired_replication_level);
pgm->xquery_size = htonl (xquery_size);
pgm->bf_mutator = reply_bf_mutator;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf,
- pgm->bloomfilter,
- DHT_BLOOM_SIZE));
+ if (NULL != peer_bf)
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf,
+ pgm->bloomfilter,
+ DHT_BLOOM_SIZE));
pgm->key = *key;
xq = (char *) &pgm[1];
memcpy (xq, xquery, xquery_size);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf,
- &xq[xquery_size],
- reply_bf_size));
+ if (NULL != reply_bf)
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_bloomfilter_get_raw_data (reply_bf,
+ &xq[xquery_size],
+ reply_bf_size));
GNUNET_CONTAINER_DLL_insert_tail (target->head,
target->tail,
pending);
}
/* then, also consider sending a random HELLO from the closest bucket */
- bucket_idx = find_bucket (key);
+ if (0 == memcmp (&my_identity.hashPubKey, key, sizeof (GNUNET_HashCode)))
+ bucket_idx = closest_bucket;
+ else
+ bucket_idx = GNUNET_MIN (closest_bucket, find_bucket (key));
if (bucket_idx == GNUNET_SYSERR)
return;
bucket = &k_buckets[bucket_idx];
if (bucket->peers_size == 0)
return;
- choice = GNUNET_CRYPTO_random_u32 (bucket->peers_size,
- GNUNET_CRYPTO_QUALITY_WEAK);
+ choice = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ bucket->peers_size);
peer = bucket->head;
while (choice > 0)
{
if (reply_bf_size > 0)
reply_bf = GNUNET_CONTAINER_bloomfilter_init (&xquery[xquery_size],
reply_bf_size,
- GNUNET_DHT_GET_BLOOMFILTER_K);
+ GNUNET_CONSTANTS_BLOOMFILTER_K);
eval = GNUNET_BLOCK_evaluate (GDS_block_context,
type,
&get->key,
GNUNET_break_op (0);
return GNUNET_YES;
}
+ if (0 == memcmp (&my_identity, &pid, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* got my own HELLO */
+ return GNUNET_YES;
+ }
bucket = find_bucket (&pid.hashPubKey);
if ( (bucket >= 0) &&
(k_buckets[bucket].peers_size < bucket_size) )
AUTOSTART = NO
[dht]
-DEBUG = NO
+DEBUG = YES
STOP_ON_CLOSEST = YES
AUTOSTART = YES
ACCEPT_FROM6 = ::1;
#include "platform.h"
#include "gnunet_testing_lib.h"
#include "gnunet_core_service.h"
-#include "gnunet_dht_service.h"
+#include "gnunet_dht_service_new.h"
/* DEFINES */
#define VERBOSE GNUNET_NO
static void
get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
const GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity *const *get_path,
- const struct GNUNET_PeerIdentity *const *put_path,
+ const struct GNUNET_PeerIdentity *get_path,
+ unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ unsigned int put_path_length,
enum GNUNET_BLOCK_Type type, size_t size, const void *data)
{
struct PeerGetContext *get_context = cls;
(GNUNET_TIME_UNIT_SECONDS, 5),
GNUNET_BLOCK_TYPE_DHT_HELLO,
&get_context->peer->hashPubKey,
- DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL,
- 0, NULL, 0, &get_result_iterator, get_context);
+ 1, GNUNET_DHT_RO_NONE, NULL,
+ 0, &get_result_iterator, get_context);
}
(GNUNET_TIME_UNIT_SECONDS, 5),
GNUNET_BLOCK_TYPE_DHT_HELLO,
&get_context->peer->hashPubKey,
- DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL,
- 0, NULL, 0, &get_result_iterator, get_context);
+ 1, GNUNET_DHT_RO_NONE, NULL,
+ 0, &get_result_iterator, get_context);
}
AUTOSTART = YES
#PREFIX = xterm -T dht -e gdb --args
PORT = 2100
+BINARY = gnunet-service-dht-new
[block]
plugins = test dht dns
#include "platform.h"
#include "gnunet_testing_lib.h"
#include "gnunet_core_service.h"
-#include "gnunet_dht_service.h"
+#include "gnunet_dht_service_new.h"
#include "block_dns.h"
#include "gnunet_signatures.h"
/* DEFINES */
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_YES
/* Timeout for entire testcase */
#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
/* If number of peers not in config file, use this number */
#define DEFAULT_NUM_PEERS 2
-#define DNS GNUNET_NO
-
/* Globals */
/**
static unsigned int failed_connections;
/* Task handle to use to schedule test failure */
-GNUNET_SCHEDULER_TaskIdentifier die_task;
+static GNUNET_SCHEDULER_TaskIdentifier die_task;
/* Global return value (0 for success, anything else for failure) */
static int ok;
-#if DNS
-struct GNUNET_DNS_Record data;
-#endif
-
/**
* Peer identity of the first peer started.
*/
* @param size number of bytes in data
* @param data pointer to the result data
*/
-void
+static void
get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
const GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity *const *get_path,
- const struct GNUNET_PeerIdentity *const *put_path,
+ const struct GNUNET_PeerIdentity *get_path,
+ unsigned int get_path_size,
+ const struct GNUNET_PeerIdentity *put_path,
+ unsigned int put_path_size,
enum GNUNET_BLOCK_Type type, size_t size,
const void *result_data)
{
memset (&original_key, 42, sizeof (GNUNET_HashCode)); /* Set the key to what it was set to previously */
memset (original_data, 43, sizeof (original_data));
-#if DNS
- if ((sizeof (original_data) != size) ||
- (0 != memcmp (&data.service_descriptor, key, sizeof (GNUNET_HashCode))) ||
- (0 != memcmp ((char *) &data, result_data, sizeof (original_data))))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Key or data is not the same as was inserted!\n");
- GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_badly,
- "key or data mismatch in get response!\n");
- return;
- }
-#else
if ((sizeof (original_data) != size) ||
(0 != memcmp (&original_key, key, sizeof (GNUNET_HashCode))) ||
(0 != memcmp (original_data, result_data, sizeof (original_data))))
"key or data mismatch in get response!\n");
return;
}
-#endif
GNUNET_SCHEDULER_cancel (die_task);
GNUNET_DHT_get_stop (global_get_handle);
+ global_get_handle = NULL;
GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
}
-/**
- * Start the GET request for the same key/data that was inserted.
- */
-static void
-do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- GNUNET_HashCode key; /* Key for data lookup */
-
-#if DNS
- memcpy (&key, &data.service_descriptor, sizeof (GNUNET_HashCode));
-#else
- memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */
-#endif
- global_get_handle =
- GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_relative_get_forever (),
-#if DNS
- GNUNET_BLOCK_TYPE_DNS,
-#else
- GNUNET_BLOCK_TYPE_TEST,
-#endif
- &key, DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE,
- NULL, 0, NULL, 0, &get_result_iterator, NULL);
-}
/**
* Called when the PUT request has been transmitted to the DHT service.
static void
put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ GNUNET_HashCode key; /* Key for data lookup */
+
GNUNET_SCHEDULER_cancel (die_task);
die_task =
GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &end_badly,
"waiting for get response (data not found)");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL);
+
+ memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */
+ global_get_handle =
+ GNUNET_DHT_get_start (peer2dht, GNUNET_TIME_relative_get_forever (),
+ GNUNET_BLOCK_TYPE_TEST,
+ &key, 1, GNUNET_DHT_RO_NONE,
+ NULL, 0, &get_result_iterator, NULL);
}
-#if !DNS
/**
* Set up some data, and call API PUT function
*/
memset (data, 43, sizeof (data));
/* Insert the data at the first peer */
- GNUNET_DHT_put (peer1dht, &key, DEFAULT_PUT_REPLICATION, GNUNET_DHT_RO_NONE,
+ GNUNET_DHT_put (peer1dht, &key, 1, GNUNET_DHT_RO_NONE,
GNUNET_BLOCK_TYPE_TEST, sizeof (data), data,
GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL,
&put_finished, NULL);
}
-#else
-
-/**
- * Set up some data, and call API PUT function
- */
-static void
-do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- char *name = "philipptoelke.gnunet.";
- size_t size = sizeof (struct GNUNET_DNS_Record);
-
- memset (&data, 0, size);
-
- data.purpose.size = htonl (size - sizeof (struct GNUNET_CRYPTO_RsaSignature));
- data.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_DNS_RECORD;
- GNUNET_CRYPTO_hash (name, strlen (name) + 1, &data.service_descriptor);
-
- data.service_type = htonl (GNUNET_DNS_SERVICE_TYPE_UDP);
- data.ports = htons (69);
-
- char *keyfile;
-
- GNUNET_asprintf (&keyfile, "/tmp/test_dns_data_key");
- struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key =
- GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
- GNUNET_free (keyfile);
- GNUNET_assert (my_private_key != NULL);
-
- GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &data.peer);
-
- data.expiration_time =
- GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
-
- /* Sign the block */
- if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_sign (my_private_key, &data.purpose, &data.signature))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n");
- return;
- }
- GNUNET_CRYPTO_rsa_key_free (my_private_key);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting with key %08x\n",
- *((unsigned int *) &data.service_descriptor));
-
- GNUNET_DHT_put (peer1dht, &data.service_descriptor, DEFAULT_PUT_REPLICATION,
- GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_DNS, size,
- (char *) &data,
- GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS),
- GNUNET_TIME_UNIT_MINUTES, &put_finished, NULL);
-}
-#endif
/**
* This function is called whenever a connection attempt is finished between two of
* The emsg variable is NULL on success (peers connected), and non-NULL on
* failure (peers failed to connect).
*/
-void
+static void
topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
const struct GNUNET_PeerIdentity *second, uint32_t distance,
const struct GNUNET_CONFIGURATION_Handle *first_cfg,
die_task =
GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, "from test gets");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_put, NULL);
}
else if (total_connections + failed_connections == expected_connections)
{