#include "gnunet_program_lib.h"
#include "gnunet_resolver_service.h"
+#define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+
#define START_ARM GNUNET_YES
#define START_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 1500)
GNUNET_break (result == GNUNET_ARM_RESULT_STOPPING);
GNUNET_break (phase == 6);
phase++;
- FPRINTF (stderr, "Sent 'STOP' request for arm to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
+ LOG ("Sent 'STOP' request for arm to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
}
static void
GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
GNUNET_break (phase == 5);
- FPRINTF (stderr, "Sent 'STOP' request for resolver to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
+ LOG ("Sent 'STOP' request for resolver to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
phase++;
#if START_ARM
GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, arm_stop_cb, NULL);
/* (4), resolver should finish resolving localhost */
GNUNET_break (phase == 4);
phase++;
- FPRINTF (stderr, "%s", "Finished resolving localhost\n");
+ LOG ("Finished resolving localhost\n");
if (ok != 0)
ok = 2;
GNUNET_ARM_request_service_stop (arm, "resolver", TIMEOUT, resolver_stop_cb, NULL);
}
/* (3), resolver should resolve localhost */
GNUNET_break (phase == 3);
- FPRINTF (stderr, "%s", "Resolved localhost\n");
+ LOG ("Resolved localhost\n");
phase++;
GNUNET_break (addr != NULL);
ok = 0;
GNUNET_assert (status == GNUNET_ARM_REQUEST_SENT_OK);
GNUNET_break (phase == 2);
GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
- FPRINTF (stderr, "Sent 'START' request for resolver to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
+ LOG ("Sent 'START' request for resolver to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
phase++;
GNUNET_RESOLVER_ip_get ("localhost", AF_INET, TIMEOUT, &dns_notify, NULL);
}
}
-void
-arm_conn (void *cls, struct GNUNET_ARM_Handle *arm, char connected)
+static void
+arm_conn (void *cls,
+ struct GNUNET_ARM_Handle *arm,
+ int connected)
{
if (GNUNET_SYSERR == connected)
{
if (GNUNET_YES == connected)
{
/* (1), arm connection should be established */
- FPRINTF (stderr, "%s", "Connected to ARM\n");
+ LOG ("Connected to ARM\n");
GNUNET_break (phase == 1);
phase++;
GNUNET_ARM_request_service_start (arm, "resolver", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, resolver_start_cb, NULL);
else
{
/* (7), ARM should stop (we disconnect from it) */
- FPRINTF (stderr, "%s", "Disconnected from ARM\n");
+ LOG ("Disconnected from ARM\n");
GNUNET_break (phase == 7);
if (phase != 7)
ok = 3;
}
}
-void
+
+static void
srv_status (void *cls, const char *service, enum GNUNET_ARM_ServiceStatus status)
{
- FPRINTF (stderr, "Service %s is %u\n", service, status);
+ LOG ("Service %s is %u\n", service, status);
switch (phase)
{
default:
- FPRINTF (stderr, "Unexpectedly got status %u for service %s\n", status,
- service);
+ LOG ("Unexpectedly got status %u for service %s\n", status,
+ service);
GNUNET_break (0);
ok = 2;
#if START_ARM
}
}
+
static void
-arm_start_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result)
+arm_start_cb (void *cls,
+ struct GNUNET_ARM_Handle *h,
+ enum GNUNET_ARM_RequestStatus status,
+ const char *servicename,
+ enum GNUNET_ARM_Result result)
{
/* (0) The request should be "sent" successfully
* ("sent", because it isn't going anywhere, ARM API starts ARM service
*/
GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
GNUNET_break (phase == 0);
- FPRINTF (stderr, "Sent 'START' request for arm to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
+ LOG ("Sent 'START' request for arm to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
phase++;
}
+
static void
task (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
else
GNUNET_free (armconfig);
}
- arm = GNUNET_ARM_connect (cfg, arm_conn, NULL);
+ arm = GNUNET_ARM_connect (cfg, &arm_conn, NULL);
if (NULL == arm)
return;
#if START_ARM
}
-
-static int
-check ()
+int
+main (int argc, char *argvx[])
{
char *const argv[] = {
"test-arm-api",
struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
};
+ GNUNET_log_setup ("test-arm-api",
+ "WARNING",
+ NULL);
GNUNET_assert (GNUNET_OK ==
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "test-arm-api", "nohelp", options,
return ok;
}
-int
-main (int argc, char *argv[])
-{
- int ret;
-
-
- GNUNET_log_setup ("test-arm-api",
- "WARNING",
- NULL);
- ret = check ();
-
- return ret;
-}
-
/* end of test_arm_api.c */
*/
#include "platform.h"
#include "gnunet_arm_service.h"
-#include "gnunet_client_lib.h"
-#include "gnunet_configuration_lib.h"
-#include "gnunet_program_lib.h"
+#include "gnunet_util_lib.h"
#include "gnunet_protocols.h"
+#define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+
#define START_ARM GNUNET_YES
#define LOG_BACKOFF GNUNET_NO
if (size < sizeof (struct GNUNET_MessageHeader))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Failed to transmit shutdown request to client.\n"));
- FPRINTF (stderr, "%s", "Failed to send a shutdown request\n");
+ LOG ("Failed to send a shutdown request\n");
shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
GNUNET_free (shutdown_ctx);
msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_STOP);
msg->size = htons (sizeof (struct GNUNET_MessageHeader));
strcpy ((char *) &msg[1], "do-nothing");
- FPRINTF (stderr, "%s", "Sent a shutdown request\n");
+ LOG ("Sent a shutdown request\n");
return sizeof (struct GNUNET_MessageHeader) + strlen ("do-nothing") + 1;
}
shutdown_ctx);
}
+
static void
kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc);
+
static void
shutdown_cont (void *cls, int reason)
{
if (GNUNET_NO != reason)
{
/* Re-try shutdown */
- FPRINTF (stderr, "%s", "do-nothing didn't die, trying again\n");
+ LOG ("do-nothing didn't die, trying again\n");
GNUNET_SCHEDULER_add_now (kill_task, NULL);
return;
}
startedWaitingAt = GNUNET_TIME_absolute_get ();
- FPRINTF (stderr, "%s", "do-nothing is dead, starting the countdown\n");
+ LOG ("do-nothing is dead, starting the countdown\n");
}
+
static void
kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (NULL != cbData)
{
waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt);
- FPRINTF (stderr, "Waited for: %llu ms\n", waitedFor.rel_value);
-#if LOG_BACKOFF
- FPRINTF (killLogFilePtr, "Waited for: %llu ms\n",
- (unsigned long long) waitedFor.rel_value);
-#endif
+ LOG ("Waited for: %s\n",
+ GNUNET_STRINGS_relative_time_to_string (waitedFor, GNUNET_YES));
}
else
{
TIMEOUT, &shutdown_cont, NULL);
}
+
static void
trigger_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
{
GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
GNUNET_break (result == GNUNET_ARM_RESULT_STOPPING);
- FPRINTF (stderr, "%s", "ARM service stopped\n");
+ LOG ("ARM service stopped\n");
GNUNET_SCHEDULER_add_now (trigger_disconnect, NULL);
}
-void
+
+static void
srv_status (void *cls, struct GNUNET_ARM_MonitorHandle *mon, const char *service, enum GNUNET_ARM_ServiceStatus status)
{
- FPRINTF (stderr, "Service %s is %u, phase %u\n", service, status, phase);
+ LOG ("Service %s is %u, phase %u\n", service, status, phase);
if (status == GNUNET_ARM_SERVICE_MONITORING_STARTED)
{
phase++;
GNUNET_break (status == GNUNET_ARM_SERVICE_STARTING);
GNUNET_break (0 == strcasecmp (service, "do-nothing"));
GNUNET_break (phase == 1);
- FPRINTF (stderr, "%s", "do-nothing is starting\n");
+ LOG ("do-nothing is starting\n");
phase++;
ok = 1;
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &kill_task, NULL);
*/
if (status == GNUNET_ARM_SERVICE_STARTING)
{
- FPRINTF (stderr, "%s", "do-nothing is starting\n");
+ LOG ("do-nothing is starting\n");
GNUNET_SCHEDULER_add_now (kill_task, &ok);
}
else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14))
}
}
+
static void
arm_start_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result)
{
GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
GNUNET_break (phase == 0);
- FPRINTF (stderr, "Sent 'START' request for arm to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
+ LOG ("Sent 'START' request for arm to ARM %s\n",
+ (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully");
}
+
static void
task (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
}
}
+
static int
check ()
{
return ok;
}
+
static int
init ()
{
arm = NULL;
}
+
static void
-arm_stop_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result)
+arm_stop_cb (void *cls,
+ struct GNUNET_ARM_Handle *h,
+ enum GNUNET_ARM_RequestStatus status,
+ const char *servicename,
+ enum GNUNET_ARM_Result result)
{
GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
GNUNET_break (result == GNUNET_ARM_RESULT_STOPPING);
GNUNET_SCHEDULER_add_now (trigger_disconnect, NULL);
}
+
static void
service_list (void *cls, struct GNUNET_ARM_Handle *arm,
- enum GNUNET_ARM_RequestStatus rs,
- unsigned int count, const char *const*list)
+ enum GNUNET_ARM_RequestStatus rs,
+ unsigned int count, const char *const*list)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u services are are currently running\n", count);
- GNUNET_assert (count == 1);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%u services are are currently running\n",
+ count);
+ GNUNET_break (count == 1);
GNUNET_break (0 == strcasecmp (list[0], "resolver (gnunet-service-resolver)"));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got service list, now stopping arm\n");
ret = 0;
GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, arm_stop_cb, NULL);
}
+
static void
hostNameResolveCB (void *cls, const struct sockaddr *addr, socklen_t addrlen)
{
}
}
+
static void
-arm_start_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result)
+arm_start_cb (void *cls,
+ struct GNUNET_ARM_Handle *h,
+ enum GNUNET_ARM_RequestStatus status,
+ const char *servicename,
+ enum GNUNET_ARM_Result result)
{
GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
}
}
+
static void
run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
GNUNET_log_setup ("test-gnunet-service-arm",
"WARNING",
NULL);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-gnunet-service-arm",
- "nohelp", options, &run, NULL));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
+ argv, "test-gnunet-service-arm",
+ "nohelp", options, &run, NULL));
return ret;
}