/*
This file is part of GNUnet
- (C) 2009 Christian Grothoff (and other contributing authors)
+ (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
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
#include "gnunet_resolver_service.h"
#include "gnunet_statistics_service.h"
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_NO
#define START_ARM GNUNET_YES
+
#define MAX_URL_LEN 1000
/**
* How long until wait until testcases fails
*/
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
-#define CHECK_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
-
-static int timeout;
-static int adv_sent;
-static int adv_arrived;
-
-static int learned_hostlist_saved;
-static int learned_hostlist_downloaded;
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 180)
-static char * current_adv_uri;
+#define CHECK_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
-static struct GNUNET_CONFIGURATION_Handle *cfg;
-static struct GNUNET_SCHEDULER_Handle *sched;
-static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
-static GNUNET_SCHEDULER_TaskIdentifier check_task;
-
struct PeerContext
{
struct GNUNET_CONFIGURATION_Handle *cfg;
struct GNUNET_CORE_Handle *core;
struct GNUNET_STATISTICS_Handle *stats;
#if START_ARM
- pid_t arm_pid;
+ struct GNUNET_OS_Process *arm_proc;
#endif
};
+static int timeout;
+
+static int adv_sent;
+
+static int adv_arrived;
+
+static int learned_hostlist_saved;
+
+static int learned_hostlist_downloaded;
+
+static char *current_adv_uri;
+
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
+
+static GNUNET_SCHEDULER_TaskIdentifier check_task;
+
static struct PeerContext adv_peer;
static struct PeerContext learn_peer;
-static struct GNUNET_STATISTICS_GetHandle * download_stats;
-static struct GNUNET_STATISTICS_GetHandle * urisrecv_stat;
-static struct GNUNET_STATISTICS_GetHandle * advsent_stat;
+static struct GNUNET_STATISTICS_GetHandle *download_stats;
+static struct GNUNET_STATISTICS_GetHandle *urisrecv_stat;
-static void
-waitpid_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct PeerContext *p = cls;
-
-#if START_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Killing ARM process.\n");
- if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", p->arm_pid);
-#endif
- GNUNET_CONFIGURATION_destroy (p->cfg);
-}
+static struct GNUNET_STATISTICS_GetHandle *advsent_stat;
-static void shutdown_testcase()
+static void
+shutdown_testcase ()
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown testcase....\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping Timeout Task.\n");
if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel (sched, timeout_task);
+ GNUNET_SCHEDULER_cancel (timeout_task);
timeout_task = GNUNET_SCHEDULER_NO_TASK;
}
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping Statistics Check Task.\n");
- if (check_task != GNUNET_SCHEDULER_NO_TASK)
+ if (NULL != download_stats)
{
- GNUNET_SCHEDULER_cancel (sched, check_task);
- check_task = GNUNET_SCHEDULER_NO_TASK;
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping Statistics Task.\n");
-
- if ((NULL != learn_peer.stats) && (NULL != download_stats))
GNUNET_STATISTICS_get_cancel (download_stats);
- if ((NULL != learn_peer.stats) && (NULL != urisrecv_stat))
+ download_stats = NULL;
+ }
+ if (NULL != urisrecv_stat)
+ {
GNUNET_STATISTICS_get_cancel (urisrecv_stat);
- if ((NULL != adv_peer.stats) && (NULL != advsent_stat))
+ urisrecv_stat = NULL;
+ }
+ if (NULL != advsent_stat)
+ {
GNUNET_STATISTICS_get_cancel (advsent_stat);
-
- if ( NULL != current_adv_uri ) GNUNET_free (current_adv_uri);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from Transport.\n");
+ advsent_stat = NULL;
+ }
+ if (check_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (check_task);
+ check_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (NULL != current_adv_uri)
+ {
+ GNUNET_free (current_adv_uri);
+ current_adv_uri = NULL;
+ }
if (adv_peer.th != NULL)
{
GNUNET_TRANSPORT_disconnect (adv_peer.th);
GNUNET_TRANSPORT_disconnect (learn_peer.th);
learn_peer.th = NULL;
}
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from Core.\n");
if (adv_peer.core != NULL)
{
GNUNET_CORE_disconnect (adv_peer.core);
GNUNET_CORE_disconnect (learn_peer.core);
learn_peer.core = NULL;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking ARM to stop core services\n");
-
-
#if START_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Killing hostlist server ARM process.\n");
- if (0 != PLIBC_KILL (adv_peer.arm_pid, SIGTERM))
+ if (0 != GNUNET_OS_process_kill (adv_peer.arm_proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(adv_peer.arm_pid) != GNUNET_OK)
+ if (GNUNET_OS_process_wait (adv_peer.arm_proc) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostlist server ARM process %u stopped\n", adv_peer.arm_pid);
-#endif
-
-
-#if START_ARM
+ GNUNET_OS_process_close (adv_peer.arm_proc);
+ adv_peer.arm_proc = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Killing hostlist client ARM process.\n");
- if (0 != PLIBC_KILL (learn_peer.arm_pid, SIGTERM))
+ if (0 != GNUNET_OS_process_kill (learn_peer.arm_proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(learn_peer.arm_pid) != GNUNET_OK)
+ if (GNUNET_OS_process_wait (learn_peer.arm_proc) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostlist client ARM process %u stopped\n", learn_peer.arm_pid);
+ GNUNET_OS_process_close (learn_peer.arm_proc);
+ learn_peer.arm_proc = NULL;
#endif
-
- if (NULL != learn_peer.cfg)
- GNUNET_CONFIGURATION_destroy (learn_peer.cfg);
- if (NULL != adv_peer.cfg)
- GNUNET_CONFIGURATION_destroy (adv_peer.cfg);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down scheduler\n");
- GNUNET_SCHEDULER_shutdown (sched);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown complete....\n");
-
}
/**
timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
timeout_task = GNUNET_SCHEDULER_NO_TASK;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Timeout while executing testcase, test failed.\n");
timeout = GNUNET_YES;
- shutdown_testcase();
+ shutdown_testcase ();
}
-static int
-process_downloads (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+
+static void
+process_downloads_done (void *cls, int success)
{
download_stats = NULL;
- if ( ((struct PeerContext *) cls == &learn_peer) && (value == 2) && (learned_hostlist_downloaded == GNUNET_NO) )
+}
+
+
+static int
+process_downloads (void *cls, const char *subsystem, const char *name,
+ uint64_t value, int is_persistent)
+{
+ if ((value >= 2) && (learned_hostlist_downloaded == GNUNET_NO))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Peer has successfully downloaded advertised URI \n"));
+ "Peer has successfully downloaded advertised URI\n");
learned_hostlist_downloaded = GNUNET_YES;
+ if ((learned_hostlist_saved == GNUNET_YES) && (adv_sent == GNUNET_YES))
+ shutdown_testcase ();
}
- if (GNUNET_NO != learned_hostlist_downloaded)
- shutdown_testcase();
return GNUNET_OK;
}
-static int
-process_uris_recv (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+
+static void
+process_uris_recv_done (void *cls, int success)
{
urisrecv_stat = NULL;
- if ( ((struct PeerContext *) cls == &learn_peer) && (value == 1) && (learned_hostlist_saved == GNUNET_NO))
+}
+
+
+static int
+process_uris_recv (void *cls, const char *subsystem, const char *name,
+ uint64_t value, int is_persistent)
+{
+ if (((struct PeerContext *) cls == &learn_peer) && (value == 1) &&
+ (learned_hostlist_saved == GNUNET_NO))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Peer has successfully saved advertised URI \n"));
+ "Peer has successfully saved advertised URI\n");
learned_hostlist_saved = GNUNET_YES;
+ if ((learned_hostlist_downloaded == GNUNET_YES) && (adv_sent == GNUNET_YES))
+ shutdown_testcase ();
}
return GNUNET_OK;
}
-static int
-process_adv_sent (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+
+static void
+process_adv_sent_done (void *cls, int success)
{
advsent_stat = NULL;
- if ( (value >= 1) && (adv_sent == GNUNET_NO))
+}
+
+
+static int
+process_adv_sent (void *cls, const char *subsystem, const char *name,
+ uint64_t value, int is_persistent)
+{
+ if ((value >= 1) && (adv_sent == GNUNET_NO))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Server has successfully sent advertisement\n"));
+ "Server has successfully sent advertisement\n");
adv_sent = GNUNET_YES;
+ if ((learned_hostlist_downloaded == GNUNET_YES) &&
+ (learned_hostlist_saved == GNUNET_YES))
+ shutdown_testcase ();
}
return GNUNET_OK;
}
char *stat;
check_task = GNUNET_SCHEDULER_NO_TASK;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
- GNUNET_asprintf (&stat,
- gettext_noop("# advertised URI `%s' downloaded"),
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
+ GNUNET_asprintf (&stat, gettext_noop ("# advertised URI `%s' downloaded"),
current_adv_uri);
-
-
- if ( NULL != learn_peer.stats)
+ if (NULL != learn_peer.stats)
{
- download_stats = GNUNET_STATISTICS_get (learn_peer.stats,
- "hostlist",
- stat,
- GNUNET_TIME_UNIT_MINUTES,
- NULL,
- &process_downloads,
- &learn_peer);
- GNUNET_free (stat);
- urisrecv_stat = GNUNET_STATISTICS_get (learn_peer.stats,
- "hostlist",
- gettext_noop("# advertised hostlist URIs"),
- GNUNET_TIME_UNIT_MINUTES,
- NULL,
- &process_uris_recv,
- &learn_peer);
+ if (NULL != download_stats)
+ GNUNET_STATISTICS_get_cancel (download_stats);
+ download_stats =
+ GNUNET_STATISTICS_get (learn_peer.stats, "hostlist", stat,
+ GNUNET_TIME_UNIT_MINUTES,
+ &process_downloads_done, &process_downloads,
+ &learn_peer);
+ if (NULL != urisrecv_stat)
+ GNUNET_STATISTICS_get_cancel (urisrecv_stat);
+ urisrecv_stat =
+ GNUNET_STATISTICS_get (learn_peer.stats, "hostlist",
+ gettext_noop ("# advertised hostlist URIs"),
+ GNUNET_TIME_UNIT_MINUTES,
+ &process_uris_recv_done, &process_uris_recv,
+ &learn_peer);
}
- if ( NULL != adv_peer.stats)
+ GNUNET_free (stat);
+ if (NULL != adv_peer.stats)
{
- advsent_stat = GNUNET_STATISTICS_get (adv_peer.stats,
- "hostlist",
- gettext_noop("# hostlist advertisements send"),
- GNUNET_TIME_UNIT_MINUTES,
- NULL,
- &process_adv_sent,
- NULL);
+ if (NULL != advsent_stat)
+ GNUNET_STATISTICS_get_cancel (advsent_stat);
+ advsent_stat =
+ GNUNET_STATISTICS_get (adv_peer.stats, "hostlist",
+ gettext_noop ("# hostlist advertisements send"),
+ GNUNET_TIME_UNIT_MINUTES, &process_adv_sent_done,
+ &process_adv_sent, NULL);
}
- check_task = GNUNET_SCHEDULER_add_delayed (sched,
- CHECK_INTERVALL,
- &check_statistics,
- NULL);
+ check_task =
+ GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, &check_statistics, NULL);
}
+
/**
* Core handler for p2p hostlist advertisements
*/
-static int ad_arrive_handler (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- const struct GNUNET_MessageHeader * message,
- struct GNUNET_TIME_Relative latency,
- uint32_t distance)
+static int
+ad_arrive_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
char *hostname;
- char *expected_uri = GNUNET_malloc (MAX_URL_LEN);
-
+ char *expected_uri;
unsigned long long port;
- size_t size;
- const struct GNUNET_MessageHeader * incoming;
+ const struct GNUNET_MessageHeader *incoming;
+ const char *end;
- if (-1 == GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg,
- "HOSTLIST",
- "HTTPPORT",
- &port))
- {
+ if (-1 ==
+ GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg, "HOSTLIST",
+ "HTTPPORT", &port))
+ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not read advertising server's configuration\n" );
- if ( NULL != expected_uri ) GNUNET_free ( expected_uri );
+ "Could not read advertising server's configuration\n");
return GNUNET_SYSERR;
- }
+ }
- if ( GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg,
- "HOSTLIST",
- "EXTERNAL_DNS_NAME",
- &hostname))
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg, "HOSTLIST",
+ "EXTERNAL_DNS_NAME", &hostname))
hostname = GNUNET_RESOLVER_local_fqdn_get ();
-
- if (NULL != hostname)
- {
- size = strlen (hostname);
- if (size + 15 > MAX_URL_LEN)
- {
- GNUNET_break (0);
- }
- else
- {
- GNUNET_asprintf (&expected_uri,
- "http://%s:%u/",
- hostname,
- (unsigned int) port);
- }
- }
-
+ GNUNET_asprintf (&expected_uri, "http://%s:%u/",
+ hostname != NULL ? hostname : "localhost",
+ (unsigned int) port);
incoming = (const struct GNUNET_MessageHeader *) message;
- current_adv_uri = strdup ((char*) &incoming[1]);
- if ( 0 == strcmp( expected_uri, current_adv_uri ) )
+ end = (const char *) &incoming[1];
+ if ('\0' !=
+ end[ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - 1])
+ {
+ GNUNET_break (0);
+ GNUNET_free (expected_uri);
+ GNUNET_free_non_null (hostname);
+ return GNUNET_SYSERR;
+ }
+ current_adv_uri = GNUNET_strdup (end);
+ if (0 == strcmp (expected_uri, current_adv_uri))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Recieved hostlist advertisement with URI `%s' as expected\n", current_adv_uri);
+ "Received hostlist advertisement with URI `%s' as expected\n",
+ current_adv_uri);
adv_arrived = GNUNET_YES;
+ adv_sent = GNUNET_YES;
}
else
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected URI `%s' and recieved URI `%s' differ\n", expected_uri, current_adv_uri);
- GNUNET_free_non_null (expected_uri);
+ "Expected URI `%s' and recieved URI `%s' differ\n",
+ expected_uri, current_adv_uri);
+ GNUNET_free (expected_uri);
GNUNET_free_non_null (hostname);
return GNUNET_OK;
}
+
/**
* List of handlers if we are learning.
*/
static struct GNUNET_CORE_MessageHandler learn_handlers[] = {
- { &ad_arrive_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0},
- { NULL, 0, 0 }
+ {&ad_arrive_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0},
+ {NULL, 0, 0}
};
+
static void
setup_learn_peer (struct PeerContext *p, const char *cfgname)
{
- char * filename;
+ char *filename;
unsigned int result;
+
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
- p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ p->arm_proc =
+ GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (p->cfg,
- "HOSTLIST",
- "HOSTLISTFILE",
- &filename))
+ if (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (p->cfg, "HOSTLIST", "HOSTLISTFILE",
+ &filename))
{
- if ( GNUNET_YES == GNUNET_DISK_file_test (filename) )
+ if (GNUNET_YES == GNUNET_DISK_file_test (filename))
{
- result = remove (filename);
+ result = UNLINK (filename);
if (result == 0)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Hostlist file `%s' was removed\n"),filename);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Hostlist file `%s' was removed\n"), filename);
}
+ GNUNET_free (filename);
}
- if ( NULL != filename) GNUNET_free ( filename );
-
- p->core = GNUNET_CORE_connect (sched, p->cfg,
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL,
- NULL,
- NULL, NULL,
- NULL, GNUNET_NO,
- NULL, GNUNET_NO,
- learn_handlers );
- GNUNET_assert ( NULL != p->core );
- p->stats = GNUNET_STATISTICS_create (sched, "hostlist", p->cfg);
- GNUNET_assert ( NULL != p->stats );
+ p->core =
+ GNUNET_CORE_connect (p->cfg, 1, NULL, NULL, NULL, NULL, NULL, GNUNET_NO,
+ NULL, GNUNET_NO, learn_handlers);
+ GNUNET_assert (NULL != p->core);
+ p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg);
+ GNUNET_assert (NULL != p->stats);
}
static void
setup_adv_peer (struct PeerContext *p, const char *cfgname)
{
-
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
- p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ p->arm_proc =
+ GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
- p->stats = GNUNET_STATISTICS_create (sched, "hostlist", p->cfg);
- GNUNET_assert ( NULL != p->stats );
-
+ p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg);
+ GNUNET_assert (NULL != p->stats);
}
+
static void
-run (void *cls,
- struct GNUNET_SCHEDULER_Handle *s,
- char *const *args,
- const char *cfgfile,
+run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
{
timeout = GNUNET_NO;
- adv_sent =GNUNET_NO;
+ adv_sent = GNUNET_NO;
adv_arrived = 0;
learned_hostlist_saved = GNUNET_NO;
learned_hostlist_downloaded = GNUNET_NO;
cfg = c;
- sched = s;
-
- check_task = GNUNET_SCHEDULER_add_delayed (sched,
- CHECK_INTERVALL,
- &check_statistics,
- NULL);
setup_adv_peer (&adv_peer, "test_learning_adv_peer.conf");
setup_learn_peer (&learn_peer, "test_learning_learn_peer.conf");
- timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
- TIMEOUT,
- &timeout_error,
- NULL);
+ timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL);
+
+ check_task =
+ GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, &check_statistics, NULL);
}
+
static int
check ()
{
unsigned int failed;
- char *const argv[] = { "test-gnunet-daemon-hostlist-learning",
+
+ char *const argv[] = {
+ "test-gnunet-daemon-hostlist-learning",
"-c", "learning_data.conf",
#if VERBOSE
"-L", "DEBUG",
GNUNET_GETOPT_OPTION_END
};
- GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-gnunet-daemon-hostlist-learning",
- "nohelp", options, &run, NULL);
-
+ GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
+ "test-gnunet-daemon-hostlist-learning", "nohelp", options,
+ &run, NULL);
failed = GNUNET_NO;
-
if (timeout == GNUNET_YES)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Testcase could not set up two communicating peers, timeout\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase timeout\n");
failed = GNUNET_YES;
}
if (adv_arrived != GNUNET_YES)
"Learning peer did not receive advertisement from server\n");
failed = GNUNET_YES;
}
- if ( learned_hostlist_saved == GNUNET_NO )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Peer1: Advertised hostlist was not saved in datastore\n");
- failed = GNUNET_YES;
- }
+ if (learned_hostlist_saved == GNUNET_NO)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Advertised hostlist was not saved in datastore\n");
+ failed = GNUNET_YES;
+ }
if (learned_hostlist_downloaded == GNUNET_NO)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Peer1: Advertised hostlist could not be downloaded from server\n");
+ "Advertised hostlist could not be downloaded from server\n");
failed = GNUNET_YES;
}
if (adv_sent == GNUNET_NO)
"Advertised was not sent from server to client\n");
failed = GNUNET_YES;
}
- if ( GNUNET_YES == failed )
+ if (GNUNET_YES == failed)
return GNUNET_YES;
- else
- return GNUNET_NO;
+ return GNUNET_NO;
}
+
int
main (int argc, char *argv[])
{
-
int ret;
- GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-hostlist-peer-1");
- GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-hostlist-peer-2");
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
GNUNET_log_setup ("test-gnunet-daemon-hostlist",
#if VERBOSE
"DEBUG",
"WARNING",
#endif
NULL);
+#if !WINDOWS
+ system ("gnunet-peerinfo -s -c test_learning_adv_peer.conf > /dev/null");
+ system ("gnunet-peerinfo -s -c test_learning_learn_peer.conf > /dev/null");
+#else
+ system ("gnunet-peerinfo -s -c test_learning_adv_peer.conf > NUL");
+ system ("gnunet-peerinfo -s -c test_learning_learn_peer.conf > NUL");
+#endif
ret = check ();
- GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-hostlist-peer-1");
- GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-hostlist-peer-2");
- if ( GNUNET_YES == GNUNET_DISK_file_test ("hostlists_learn_peer.file") )
- {
- if ( remove ("hostlists_learn_peer.file") == 0)
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
+ GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
+ if (GNUNET_YES == GNUNET_DISK_file_test ("hostlists_learn_peer.file"))
+ {
+ if (0 == UNLINK ("hostlists_learn_peer.file"))
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Hostlist file hostlists_learn_peer.file was removed\n"));
- }
- return ret;
+ "Hostlist file hostlists_learn_peer.file was removed\n");
+ }
+ return ret;
}
/* end of test_gnunet_daemon_hostlist.c */