#include "gnunet_dht_service.h"
/* DEFINES */
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_EXTRA_LOGGING
#define MAX_GET_ATTEMPTS 10
static unsigned int failed_connections;
-GNUNET_SCHEDULER_TaskIdentifier die_task;
+static GNUNET_SCHEDULER_TaskIdentifier die_task;
static int ok;
/**
* Check whether peers successfully shut down.
*/
-void
+static void
shutdown_callback (void *cls, const char *emsg)
{
if (emsg != NULL)
GNUNET_DHT_disconnect (peer1dht);
GNUNET_DHT_disconnect (peer2dht);
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ pg = NULL;
ok = 0;
}
GNUNET_DHT_disconnect (peer2dht);
if (pg != NULL)
+ {
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ pg = NULL;
+ }
if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK)
+ {
GNUNET_SCHEDULER_cancel (curr_get_ctx.retry_task);
+ curr_get_ctx.retry_task = GNUNET_SCHEDULER_NO_TASK;
+ }
}
+
static void
end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ const char *emsg = cls;
+
+ fprintf (stderr,
+ "Error: %s\n",
+ emsg);
if (curr_get_ctx.retry_task != GNUNET_SCHEDULER_NO_TASK)
+ {
GNUNET_SCHEDULER_cancel (curr_get_ctx.retry_task);
-
+ curr_get_ctx.retry_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (curr_get_ctx.get_handle != NULL)
{
GNUNET_DHT_get_stop (curr_get_ctx.get_handle);
ok = 1;
}
+
/* Forward declaration */
-static void do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+static void
+do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
* Iterator called on each result obtained for a DHT
* @param size number of bytes in data
* @param data pointer to the result data
*/
-void
-get_result_iterator (void *cls,
- struct GNUNET_TIME_Absolute exp,
+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;
if (0 !=
memcmp (&get_context->peer->hashPubKey, key, sizeof (GNUNET_HashCode)))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ fprintf (stderr, "??\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Key returned is not the same key as was searched for!\n");
GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_badly, "key mismatch in get response!\n");
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "key mismatch in get response!\n");
return;
}
-
+ fprintf (stderr, "!\n");
if (get_context->retry_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (get_context->retry_task);
"Received second correct GET request response!\n");
GNUNET_SCHEDULER_cancel (die_task);
GNUNET_DHT_get_stop (get_context->get_handle);
- GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
+ die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
}
}
static void
stop_retry_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+
static void
get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
get_context->get_attempts);
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ fprintf (stderr, "?\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Too many attempts failed, ending test!\n",
get_context->get_attempts);
GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_badly, "key mismatch in get response!\n");
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly,
+ "GET attempt failed, ending test!\n");
return;
}
+ fprintf (stderr, ".");
get_context->get_attempts++;
get_context->retry_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(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);
}
+
static void
stop_retry_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_SCHEDULER_add_now (&get_stop_finished, get_context);
}
+
static void
do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 10),
&stop_retry_get, get_context);
-
- get_context->get_handle = GNUNET_DHT_get_start (get_context->dht_handle,
- GNUNET_TIME_relative_multiply
- (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);
+ get_context->get_handle =
+ GNUNET_DHT_get_start (get_context->dht_handle,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 5),
+ GNUNET_BLOCK_TYPE_DHT_HELLO,
+ &get_context->peer->hashPubKey,
+ 1, GNUNET_DHT_RO_FIND_PEER, NULL,
+ 0, &get_result_iterator, get_context);
}
-void
-topology_callback (void *cls,
- const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second,
- uint32_t distance,
+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,
const struct GNUNET_CONFIGURATION_Handle *second_cfg,
struct GNUNET_TESTING_Daemon *first_daemon,
total_connections);
#endif
GNUNET_SCHEDULER_cancel (die_task);
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly, "from test gets");
+ die_task =
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly, "Timeout trying to GET");
curr_get_ctx.dht_handle = peer1dht;
curr_get_ctx.peer = &peer2id;
}
}
+
static void
connect_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
expected_connections = -1;
if ((pg != NULL) && (peers_left == 0))
- expected_connections = GNUNET_TESTING_connect_topology (pg,
- GNUNET_TESTING_TOPOLOGY_CLIQUE,
- GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
- 0.0,
- TIMEOUT, 12, NULL,
- NULL);
+ expected_connections =
+ GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE,
+ GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
+ 0.0, TIMEOUT, 12, NULL, NULL);
GNUNET_SCHEDULER_cancel (die_task);
if (expected_connections == GNUNET_SYSERR)
die_task =
GNUNET_SCHEDULER_add_now (&end_badly,
"from connect topology (bad return)");
-
-
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly,
- "from connect topology (timeout)");
+ else
+ die_task =
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
+ "from connect topology (timeout)");
}
+
static void
-peers_started_callback (void *cls,
- const struct GNUNET_PeerIdentity *id,
+peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Daemon *d, const char *emsg)
{
if (emsg != NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to start daemon with error: `%s'\n", emsg);
+ fprintf (stderr,
+ "Failed to start daemon: `%s'\n",
+ emsg);
return;
}
GNUNET_assert (id != NULL);
if (peer1dht == NULL)
{
GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
}
}
else
if (peer2dht == NULL)
{
GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
+ die_task =
+ GNUNET_SCHEDULER_add_now (&end_badly, "Failed to get dht handle!\n");
}
}
GNUNET_SCHEDULER_cancel (die_task);
/* Set up task in case topology creation doesn't finish
* within a reasonable amount of time */
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly,
- "from peers_started_callback");
+ die_task =
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
+ "from peers_started_callback");
GNUNET_SCHEDULER_add_now (&connect_topology, NULL);
ok = 0;
}
}
+
static void
-run (void *cls,
- char *const *args,
- const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
+run (void *cls, char *const *args, const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
if (GNUNET_YES !=
total_gets = num_peers;
gets_succeeded = 0;
/* Set up a task to end testing if peer start fails */
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly,
- "didn't start all daemons in reasonable amount of time!!!");
-
- pg = GNUNET_TESTING_daemons_start (cfg,
- num_peers,
- 10,
- num_peers,
- TIMEOUT,
- NULL, NULL,
- &peers_started_callback,
- NULL, &topology_callback, NULL, NULL);
+ die_task =
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
+ "didn't start all daemons in reasonable amount of time!!!");
+
+ pg = GNUNET_TESTING_daemons_start (cfg, num_peers, 10, num_peers, TIMEOUT,
+ NULL, NULL, &peers_started_callback, NULL,
+ &topology_callback, NULL, NULL);
}
struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
};
- ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-dht-twopeer", "nohelp",
- options, &run, &ok);
+ ret =
+ GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
+ "test-dht-twopeer", "nohelp", options, &run, &ok);
if (ret != GNUNET_OK)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,