GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 2, or (at your
+ by the Free Software Foundation; either version 3, or (at your
option) any later version.
GNUnet is distributed in the hope that it will be useful, but
*/
static struct GNUNET_DHT_Handle *dht_handle;
-/**
- * Global handle of the scheduler
- */
-static struct GNUNET_SCHEDULER_Handle *sched;
/**
* Global handle of the configuration
static int ret;
static void
-shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
-
if (dht_handle != NULL)
- GNUNET_DHT_disconnect (dht_handle);
-
- dht_handle = NULL;
+ {
+ GNUNET_DHT_disconnect (dht_handle);
+ dht_handle = NULL;
+ }
+ fprintf (stderr,
+ _("Found %u peers\n"),
+ result_count);
}
+
static void
-cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+cleanup_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (find_peer_handle != NULL)
- GNUNET_DHT_find_peer_stop (find_peer_handle, &shutdown_task, NULL);
- else
- GNUNET_SCHEDULER_add_now (sched, &shutdown_task, NULL);
+ {
+ GNUNET_DHT_find_peer_stop (find_peer_handle);
+ find_peer_handle = NULL;
+ }
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
/**
* operation
*
* @param cls closure (NULL)
- * @param peer the peer we learned about
- * @param reply the response message, should be a HELLO
+ * @param hello the response message, a HELLO
*/
-void find_peer_processor (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *reply)
+static void
+find_peer_processor (void *cls,
+ const struct GNUNET_HELLO_Message *hello)
{
- result_count++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "test_find_peer_processor called (peer `%s'), total results %d!\n", GNUNET_i2s(peer), result_count);
-
-}
+ struct GNUNET_PeerIdentity peer;
-
-/**
- * Signature of the main function of a task.
- *
- * @param cls closure
- * @param tc context information (why was this task triggered now)
- */
-void
-message_sent_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
- {
- if (verbose)
- fprintf (stderr,
- "Failed to send FIND PEER request to service, quitting.\n");
- ret = 1;
- GNUNET_SCHEDULER_add_now (sched, &shutdown_task, NULL);
- }
- else
+ if (GNUNET_OK == GNUNET_HELLO_get_id(hello, &peer))
{
+ result_count++;
if (verbose)
- fprintf (stderr, "FIND PEER request sent, awaiting results!\n");
- GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_TIME_absolute_get_remaining
- (absolute_timeout), &cleanup_task, NULL);
+ fprintf (stderr,
+ _("Found peer `%s'\n"),
+ GNUNET_i2s (&peer));
}
}
+
/**
* Main function that will be run by the scheduler.
*
* @param cls closure
- * @param s the scheduler to use
* @param args remaining command-line arguments
* @param cfgfile name of the configuration file used (for saving, can be NULL!)
* @param c configuration
*/
static void
run (void *cls,
- struct GNUNET_SCHEDULER_Handle *s,
char *const *args,
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
struct GNUNET_TIME_Relative timeout;
GNUNET_HashCode key;
- sched = s;
cfg = c;
if (query_key == NULL)
return;
}
- dht_handle = GNUNET_DHT_connect (sched, cfg, 1);
+ dht_handle = GNUNET_DHT_connect (cfg, 1);
if (dht_handle == NULL)
{
if (verbose)
fprintf (stderr, "Issuing FIND PEER request for %s!\n", query_key);
- find_peer_handle = GNUNET_DHT_find_peer_start (dht_handle, timeout, 0, NULL, &key,
- &find_peer_processor, NULL, &message_sent_cont, NULL);
-
+ find_peer_handle = GNUNET_DHT_find_peer_start (dht_handle,
+ timeout,
+ &key,
+ GNUNET_DHT_RO_NONE,
+ &find_peer_processor,
+ NULL);
+ if (NULL == find_peer_handle)
+ {
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ return;
+ }
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (absolute_timeout),
+ &cleanup_task, NULL);
}
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc,
argv,
- "gnunet-dht-get",
+ "gnunet-dht-get-peer",
gettext_noop
- ("Issue a GET request to the GNUnet DHT, prints results."),
+ ("Issue a GET PEER request to the GNUnet DHT, print results."),
options, &run, NULL)) ? ret : 1;
}
+
+/* end of gnunet-dht-get-peer */