*/
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
#define RESOLUTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+#define OP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
/**
* Which peer should we connect to?
*/
static GNUNET_SCHEDULER_TaskIdentifier end;
+/**
+ * Task for operation timeout
+ */
+static GNUNET_SCHEDULER_TaskIdentifier op_timeout;
+
+
static struct GNUNET_CONTAINER_MultiHashMap *peers;
/**
shutdown_task (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
+ {
+ GNUNET_SCHEDULER_cancel (op_timeout);
+ op_timeout = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL != pic)
{
GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pic);
}
}
+
+
+static void
+operation_timeout (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ op_timeout = GNUNET_SCHEDULER_NO_TASK;
+ if (try_connect)
+ {
+ FPRINTF (stdout, _("Failed to connect to `%s'\n"), GNUNET_h2s_full (&pid.hashPubKey));
+ if (GNUNET_SCHEDULER_NO_TASK != end)
+ GNUNET_SCHEDULER_cancel (end);
+ end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ ret = 1;
+ return;
+ }
+}
+
+
+
/**
* Display the result of the test.
*
if (try_connect)
{
/* all done, terminate instantly */
- if (verbosity > 0)
- FPRINTF (stdout, _("Successfully connected to %s\n"), GNUNET_i2s (peer));
- GNUNET_SCHEDULER_cancel (end);
+ FPRINTF (stdout, _("Successfully connected to %s\n"), GNUNET_h2s_full (&peer->hashPubKey));
+ ret = 0;
+
+ if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
+ GNUNET_SCHEDULER_cancel (op_timeout);
+
+ if (GNUNET_SCHEDULER_NO_TASK != end)
+ GNUNET_SCHEDULER_cancel (end);
end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL);
+ return;
}
- else if (benchmark_send)
+ if (benchmark_send)
{
start_time = GNUNET_TIME_absolute_get ();
if (NULL == th)
th = GNUNET_TRANSPORT_notify_transmit_ready (handle, peer, 32 * 1024, 0,
GNUNET_TIME_UNIT_FOREVER_REL,
&transmit_data, NULL);
- }
- else
- {
- /* all done, terminate instantly */
- GNUNET_SCHEDULER_cancel (end);
- end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL);
+ return;
}
}
{
if (GNUNET_SCHEDULER_NO_TASK != end)
GNUNET_SCHEDULER_cancel (end);
+ ret = 0;
end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
}
{
struct GNUNET_CONFIGURATION_Handle *cfg = cls;
int counter = 0;
- int try_connect = 0;
-
+ ret = 1;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
{
if (NULL == handle)
{
FPRINTF (stderr, _("Failed to connect to transport service\n"));
+ ret = 1;
return;
}
-
GNUNET_TRANSPORT_try_connect (handle, &pid);
+ op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
+ &operation_timeout, NULL);
}
else if (benchmark_send) /* Benchmark sending */
{
FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
"-s", "-p");
+ ret = 1;
return;
}
- ret = 1;
handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL,
¬ify_receive,
¬ify_connect,
if (NULL == handle)
{
FPRINTF (stderr, _("Failed to connect to transport service\n"));
+ ret = 1;
return;
}
GNUNET_TRANSPORT_try_connect (handle, &pid);
- /*
- end = GNUNET_SCHEDULER_add_delayed (benchmark_send ?
- GNUNET_TIME_UNIT_FOREVER_REL :
- GNUNET_TIME_UNIT_SECONDS,
- &do_disconnect,
- NULL);*/
+
+ op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
+ &operation_timeout,
+ NULL);
}
else if (benchmark_receive) /* Benchmark receiving */
{
if (NULL == handle)
{
FPRINTF (stderr, _("Failed to connect to transport service\n"));
+ ret = 1;
return;
}
GNUNET_TRANSPORT_try_connect (handle, &pid);
if (NULL == handle)
{
FPRINTF (stderr, _("Failed to connect to transport service\n"));
+ ret = 1;
return;
}
+ ret = 0;
}
else
{