struct GNUNET_CONFIGURATION_Handle *cfg;
struct GNUNET_DHT_Handle *dht_handle;
struct GNUNET_PeerIdentity id;
- struct GNUNET_DHT_RouteHandle *get_handle;
- struct GNUNET_DHT_RouteHandle *find_peer_handle;
+ struct GNUNET_DHT_GetHandle *get_handle;
+ struct GNUNET_DHT_FindPeerHandle *find_peer_handle;
#if START_ARM
pid_t arm_pid;
static void
-end (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
/* do work here */
GNUNET_SCHEDULER_cancel (sched, die_task);
die_task = GNUNET_SCHEDULER_NO_TASK;
if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DHT disconnected, returning FAIL!\n");
- ok = 365;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DHT disconnected, returning FAIL!\n");
+ ok = 365;
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DHT disconnected, returning success!\n");
- ok = 0;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DHT disconnected, returning success!\n");
+ ok = 0;
+ }
}
static void
{
/* do work here */
#if VERBOSE
- fprintf(stderr, "Ending on an unhappy note.\n");
+ fprintf (stderr, "Ending on an unhappy note.\n");
#endif
GNUNET_DHT_disconnect (p1.dht_handle);
return;
}
-
/**
* Signature of the main function of a task.
*
* @param cls closure
* @param tc context information (why was this task triggered now)
*/
-void test_put (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+void
+test_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerContext *peer = cls;
- GNUNET_HashCode hash;
- char *data;
- size_t data_size = 42;
- memset(&hash, 42, sizeof(GNUNET_HashCode));
- data = GNUNET_malloc(data_size);
- memset(data, 43, data_size);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_put!\n");
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer_stop!\n");
+ if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
+ GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL);
+
GNUNET_assert (peer->dht_handle != NULL);
- GNUNET_DHT_put(peer->dht_handle, &hash, 0, data_size, data, GNUNET_TIME_relative_to_absolute(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 360)) ,GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 360), &end, NULL);
+ GNUNET_DHT_find_peer_stop (peer->find_peer_handle, &end, &p1);
- //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1);
+ //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &end, &p1);
- //GNUNET_SCHEDULER_add_now(sched, &end, NULL);
}
+
+/**
+ * Iterator called on each result obtained from a find peer
+ * operation
+ *
+ * @param cls closure (NULL)
+ * @param peer the peer we learned about
+ * @param reply response
+ */
+void test_find_peer_processor (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *reply)
+{
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "test_find_peer_processor called (peer `%s'), stopping find peer request!\n", GNUNET_i2s(peer));
+
+ GNUNET_SCHEDULER_add_continuation (sched, &test_find_peer_stop, &p1,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+}
+
+
/**
* Signature of the main function of a task.
*
* @param cls closure
* @param tc context information (why was this task triggered now)
*/
-void test_get_stop (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+void
+test_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerContext *peer = cls;
GNUNET_HashCode hash;
- memset(&hash, 42, sizeof(GNUNET_HashCode));
+ memset (&hash, 42, sizeof (GNUNET_HashCode));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer!\n");
+ GNUNET_assert (peer->dht_handle != NULL);
+
+ peer->find_peer_handle =
+ GNUNET_DHT_find_peer_start (peer->dht_handle, TIMEOUT, 0, NULL, &hash,
+ &test_find_peer_processor, NULL, NULL, NULL);
+
+ if (peer->find_peer_handle == NULL)
+ GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1);
+}
+
+/**
+ * Signature of the main function of a task.
+ *
+ * @param cls closure
+ * @param tc context information (why was this task triggered now)
+ */
+void
+test_get_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct PeerContext *peer = cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get_stop!\n");
if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
- GNUNET_SCHEDULER_add_now(sched, &end_badly, NULL);
+ GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL);
GNUNET_assert (peer->dht_handle != NULL);
- GNUNET_DHT_get_stop(peer->get_handle);
+ GNUNET_DHT_get_stop (peer->get_handle, &test_find_peer, &p1);
//GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1);
- GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1);
}
+void
+test_get_iterator (void *cls,
+ struct GNUNET_TIME_Absolute exp,
+ const GNUNET_HashCode * key,
+ uint32_t type, uint32_t size, const void *data)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "test_get_iterator called (we got a result), stopping get request!\n");
+
+ GNUNET_SCHEDULER_add_continuation (sched, &test_get_stop, &p1,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+}
+
/**
* Signature of the main function of a task.
*
* @param cls closure
* @param tc context information (why was this task triggered now)
*/
-void test_get (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+void
+test_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerContext *peer = cls;
GNUNET_HashCode hash;
- memset(&hash, 42, sizeof(GNUNET_HashCode));
+ memset (&hash, 42, sizeof (GNUNET_HashCode));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get!\n");
- peer->dht_handle = GNUNET_DHT_connect (sched, peer->cfg, 100);
+
GNUNET_assert (peer->dht_handle != NULL);
- peer->get_handle = GNUNET_DHT_get_start(peer->dht_handle, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100), 42, &hash, NULL, NULL, &test_get_stop, &p1);
+ peer->get_handle =
+ GNUNET_DHT_get_start (peer->dht_handle, TIMEOUT, 42, &hash,
+ &test_get_iterator, NULL, NULL, NULL);
if (peer->get_handle == NULL)
- GNUNET_SCHEDULER_add_now(sched, &end_badly, &p1);
+ GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1);
+}
+
+/**
+ * Signature of the main function of a task.
+ *
+ * @param cls closure
+ * @param tc context information (why was this task triggered now)
+ */
+void
+test_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct PeerContext *peer = cls;
+ GNUNET_HashCode hash;
+ char *data;
+ size_t data_size = 42;
+ memset (&hash, 42, sizeof (GNUNET_HashCode));
+ data = GNUNET_malloc (data_size);
+ memset (data, 43, data_size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_put!\n");
+ peer->dht_handle = GNUNET_DHT_connect (sched, peer->cfg, 100);
+
+ GNUNET_assert (peer->dht_handle != NULL);
+
+ GNUNET_DHT_put (peer->dht_handle, &hash, 42, data_size, data,
+ GNUNET_TIME_relative_to_absolute (TIMEOUT), TIMEOUT,
+ &test_get, &p1);
- //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_get_stop, &p1);
}
static void
sched = s;
die_task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1), &end_badly, NULL);
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MINUTES, 1),
+ &end_badly, NULL);
setup_peer (&p1, "test_dht_api_peer1.conf");
- GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_get, &p1);
+ GNUNET_SCHEDULER_add_delayed (sched,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 3), &test_put,
+ &p1);
}
static int
ok = 1;
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-dht-api", "nohelp",
- options, &run, &ok);
+ argv, "test-dht-api", "nohelp", options, &run, &ok);
stop_arm (&p1);
return ok;
}
NULL);
ret = check ();
- //GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-dht-peer-1");
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-dht-peer-1");
return ret;
}