2 This file is part of GNUnet
3 (C) 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file hostlist/test_gnunet_daemon_hostlist.c
22 * @brief test for gnunet_daemon_hostslist.c
23 * @author Christian Grothoff
26 #include "gnunet_util_lib.h"
27 #include "gnunet_arm_service.h"
28 #include "gnunet_transport_service.h"
30 #define VERBOSE GNUNET_YES
32 #define START_ARM GNUNET_YES
36 * How long until we give up on transmitting the message?
38 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
42 static struct GNUNET_SCHEDULER_Handle *sched;
46 struct GNUNET_CONFIGURATION_Handle *cfg;
47 struct GNUNET_TRANSPORT_Handle *th;
48 struct GNUNET_MessageHeader *hello;
54 static struct PeerContext p1;
56 static struct PeerContext p2;
61 process_hello (void *cls,
62 struct GNUNET_TIME_Relative latency,
63 const struct GNUNET_PeerIdentity *peer,
64 const struct GNUNET_MessageHeader *message)
66 struct PeerContext *p = cls;
68 GNUNET_assert (peer != NULL);
69 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
70 "Received (my) `%s' from transport service of `%4s'\n",
71 "HELLO", GNUNET_i2s (peer));
72 GNUNET_assert (message != NULL);
73 p->hello = GNUNET_malloc (ntohs (message->size));
74 memcpy (p->hello, message, ntohs (message->size));
75 if ((p == &p1) && (p2.th != NULL))
76 GNUNET_TRANSPORT_offer_hello (p2.th, message);
77 if ((p == &p2) && (p1.th != NULL))
78 GNUNET_TRANSPORT_offer_hello (p1.th, message);
80 if ((p == &p1) && (p2.hello != NULL))
81 GNUNET_TRANSPORT_offer_hello (p1.th, p2.hello);
82 if ((p == &p2) && (p1.hello != NULL))
83 GNUNET_TRANSPORT_offer_hello (p2.th, p1.hello);
88 setup_peer (struct PeerContext *p, const char *cfgname)
90 p->cfg = GNUNET_CONFIGURATION_create ();
92 p->arm_pid = GNUNET_OS_start_process ("gnunet-service-arm",
99 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
100 GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
101 p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, p, NULL, NULL, NULL);
102 GNUNET_assert (p->th != NULL);
103 GNUNET_TRANSPORT_get_hello (p->th, TIMEOUT, &process_hello, p);
109 struct GNUNET_SCHEDULER_Handle *s,
112 const struct GNUNET_CONFIGURATION_Handle *cfg)
114 GNUNET_assert (ok == 1);
117 setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf");
118 setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf");
123 stop_arm (struct PeerContext *p)
125 GNUNET_ARM_stop_services (p->cfg, sched, "core", NULL);
127 if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
128 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
129 if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
130 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
132 "ARM process %u stopped\n", p->arm_pid);
134 GNUNET_CONFIGURATION_destroy (p->cfg);
141 char *const argv[] = { "test-gnunet-daemon-hostlist",
142 "-c", "test_gnunet_daemon_hostlist_data.conf",
148 struct GNUNET_GETOPT_CommandLineOption options[] = {
149 GNUNET_GETOPT_OPTION_END
152 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
153 argv, "test-gnunet-daemon-hostlist",
154 "nohelp", options, &run, &ok);
162 main (int argc, char *argv[])
167 GNUNET_log_setup ("test-gnunet-daemon-hostlist",
178 /* end of test_gnunet_daemon_hostlist.c */