*/
static unsigned int failed_connections;
-/* Task handle to use to schedule test failure */
+/**
+ * Task handle to use to schedule test failure
+ */
GNUNET_SCHEDULER_TaskIdentifier die_task;
-/* Global return value (0 for success, anything else for failure) */
+/**
+ * Global return value (0 for success, anything else for failure)
+ */
static int ok;
/**
* @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,
- const GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity *const *get_path,
- const struct GNUNET_PeerIdentity *const *put_path,
- enum GNUNET_BLOCK_Type type, size_t size, const void *data)
+static void
+get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
+ const struct GNUNET_HashCode * key,
+ 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 */
+ struct GNUNET_HashCode original_key; /* Key data was stored data under */
char original_data[4]; /* Made up data that was stored */
- memset (&original_key, 42, sizeof (GNUNET_HashCode)); /* Set the key to what it was set to previously */
+ memset (&original_key, 42, sizeof (struct GNUNET_HashCode)); /* Set the key to what it was set to previously */
memset (original_data, 43, sizeof (original_data));
#if VERBOSE
unsigned int i;
#endif
- if ((0 != memcmp (&original_key, key, sizeof (GNUNET_HashCode))) ||
+ if ((0 != memcmp (&original_key, key, sizeof (struct GNUNET_HashCode))) ||
(0 != memcmp (original_data, data, sizeof (original_data))))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
#if VERBOSE
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]));
- fprintf (stderr, "\n");
+ FPRINTF (stderr, "%s", "PUT Path: ");
+ for (i = 0; i < put_path_length; i++)
+ FPRINTF (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&put_path[i]));
+ FPRINTF (stderr, "%s", "\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]));
- fprintf (stderr, "\n");
+ FPRINTF (stderr, "%s", "GET Path: ");
+ for (i = 0; i < get_path_length; i++)
+ FPRINTF (stderr, "%s%s", i == 0 ? "" : "->", GNUNET_i2s (&get_path[i]));
+ FPRINTF (stderr, "%s", "\n");
}
#endif
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 */
-
- 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)
+put_finished (void *cls, int success)
{
+ struct 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);
+ die_task =
+ GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &end_badly,
+ "waiting for get response (data not found)");
+ memset (&key, 42, sizeof (struct GNUNET_HashCode)); /* Set the key to the same thing as when data was inserted */
+ global_get_handle =
+ GNUNET_DHT_get_start (peer2dht,
+ GNUNET_BLOCK_TYPE_TEST, &key, 1,
+ GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0,
+ &get_result_iterator, NULL);
}
/**
static void
do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- GNUNET_HashCode key; /* Made up key to store data under */
+ struct GNUNET_HashCode key; /* Made up key to store data under */
char data[4]; /* Made up data to store */
- memset (&key, 42, sizeof (GNUNET_HashCode)); /* Set the key to something simple so we can issue GET request */
+ memset (&key, 42, sizeof (struct GNUNET_HashCode)); /* Set the key to something simple so we can issue GET request */
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_TIME_UNIT_FOREVER_REL, &put_finished, NULL);
+ 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 */
/* Get number of peers to start from configuration (should be two) */
if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
+ GNUNET_CONFIGURATION_get_value_number (cfg, "testing_old", "num_peers",
&num_peers))
num_peers = DEFAULT_NUM_PEERS;
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,