#include "gnunet_dht_service.h"
/* DEFINES */
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_EXTRA_LOGGING
/* Timeout for entire testcase */
#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
* @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)
{
GNUNET_HashCode original_key; /* Key data was stored data under */
if (put_path != NULL)
{
fprintf (stderr, "PUT Path: ");
- for (i = 0; put_path[i] != NULL; i++)
- fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (put_path[i]));
+ for (i = 0; i<put_path_length; i++)
+ fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&put_path[i]));
fprintf (stderr, "\n");
}
if (get_path != NULL)
{
fprintf (stderr, "GET Path: ");
- for (i = 0; get_path[i] != NULL; i++)
- fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (get_path[i]));
+ for (i = 0; i<get_path_length; i++)
+ fprintf (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&get_path[i]));
fprintf (stderr, "\n");
}
#endif
GNUNET_SCHEDULER_add_now (&finish_testing, NULL);
}
+
/**
- * Start the GET request for the same key/data that was inserted.
+ * Called when the PUT request has been transmitted to the DHT service.
+ * Schedule the GET request for some time in the future.
*/
static void
-do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+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)");
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,
- DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_RECORD_ROUTE,
- NULL, 0, NULL, 0, &get_result_iterator, NULL);
-}
-
-/**
- * Called when the PUT request has been transmitted to the DHT service.
- * Schedule the GET request for some time in the future.
- */
-static void
-put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- 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);
+ 1, GNUNET_DHT_RO_RECORD_ROUTE,
+ NULL, 0, &get_result_iterator, NULL);
}
/**
memset (data, 43, sizeof (data));
/* Insert the data at the first peer */
- GNUNET_DHT_put (peer1dht,
- &key,
- DEFAULT_PUT_REPLICATION,
- GNUNET_DHT_RO_RECORD_ROUTE,
- GNUNET_BLOCK_TYPE_TEST,
- sizeof (data), data,
- GNUNET_TIME_UNIT_FOREVER_ABS,
+ GNUNET_DHT_put (peer1dht, &key, 1,
+ GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_BLOCK_TYPE_TEST,
+ sizeof (data), data, GNUNET_TIME_UNIT_FOREVER_ABS,
GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL);
}
* The emsg variable is NULL on success (peers connected), and non-NULL on
* failure (peers failed to connect).
*/
-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, "from test gets");
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL);
* @param emsg NULL if peer started, non-NULL on error
*/
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 ((pg != NULL)) /* Sanity check */
{
/* Connect peers in a "straight line" topology, return the number of expected connections */
- expected_connections = GNUNET_TESTING_connect_topology (pg,
- GNUNET_TESTING_TOPOLOGY_LINE,
- GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
- 0.0,
- TIMEOUT,
- 2, NULL, NULL);
+ expected_connections =
+ GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_LINE,
+ GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
+ 0.0, TIMEOUT, 2, NULL, NULL);
}
/* Cancel current timeout fail task */
"from connect topology (bad return)");
/* Schedule timeout on failure task */
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &end_badly,
- "from connect topology (timeout)");
+ die_task =
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
+ "from connect topology (timeout)");
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)
{
/* Get path from configuration file */
peers_left = num_peers;
/* 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!!!");
+ die_task =
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
+ "didn't start all daemons in reasonable amount of time!!!");
/* Start num_peers peers, call peers_started_callback on peer start, topology_callback on peer connect */
/* Read the API documentation for other parameters! */
pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */
peers_left, /* Number of outstanding connections */
peers_left, /* Number of parallel ssh connections, or peers being started at once */
- TIMEOUT,
- NULL,
- NULL,
- &peers_started_callback,
- NULL, &topology_callback, NULL, NULL);
+ TIMEOUT, NULL, NULL,
+ &peers_started_callback, NULL,
+ &topology_callback, NULL, NULL);
}
GNUNET_GETOPT_OPTION_END
};
/* Run the run function as a new program */
- ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-dht-twopeer-put-get", "nohelp",
- options, &run, &ok);
+ ret =
+ GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
+ "test-dht-twopeer-put-get", "nohelp", options, &run,
+ &ok);
if (ret != GNUNET_OK)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,