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 transport/test_core_api_start_only.c
22 * @brief testcase for core_api.c that only starts two peers,
23 * connects to the core service and shuts down again
26 #include "gnunet_common.h"
27 #include "gnunet_arm_service.h"
28 #include "gnunet_core_service.h"
29 #include "gnunet_getopt_lib.h"
30 #include "gnunet_os_lib.h"
31 #include "gnunet_program_lib.h"
32 #include "gnunet_scheduler_lib.h"
34 #define VERBOSE GNUNET_NO
36 #define START_ARM GNUNET_YES
40 * How long until we give up on transmitting the message?
42 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
48 struct GNUNET_CONFIGURATION_Handle *cfg;
49 struct GNUNET_CORE_Handle *ch;
50 struct GNUNET_PeerIdentity id;
56 static struct PeerContext p1;
58 static struct PeerContext p2;
60 static struct GNUNET_SCHEDULER_Handle *sched;
65 #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
67 #define OKPP do { ok++; } while (0)
73 connect_notify (void *cls,
74 const struct GNUNET_PeerIdentity *peer)
80 disconnect_notify (void *cls,
81 const struct GNUNET_PeerIdentity *peer)
87 bfc_callback (void *cls,
88 const struct GNUNET_PeerIdentity *receiver,
97 inbound_notify (void *cls,
98 const struct GNUNET_PeerIdentity *other,
99 const struct GNUNET_MessageHeader *message)
106 outbound_notify (void *cls,
107 const struct GNUNET_PeerIdentity *other,
108 const struct GNUNET_MessageHeader *message)
114 static struct GNUNET_CORE_MessageHandler handlers[] = {
121 init_notify (void *cls,
122 struct GNUNET_CORE_Handle *server,
123 const struct GNUNET_PeerIdentity *my_identity,
124 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
126 struct PeerContext *p = cls;
128 GNUNET_assert (server != NULL);
133 GNUNET_CORE_connect (sched,
143 &outbound_notify, GNUNET_YES, handlers);
147 GNUNET_assert (cls == &p2);
148 GNUNET_CORE_disconnect (p1.ch);
149 GNUNET_CORE_disconnect (p2.ch);
150 GNUNET_ARM_stop_services (p1.cfg, sched, "core", NULL);
151 GNUNET_ARM_stop_services (p2.cfg, sched, "core", NULL);
159 setup_peer (struct PeerContext *p, const char *cfgname)
161 p->cfg = GNUNET_CONFIGURATION_create ();
163 p->arm_pid = GNUNET_OS_start_process ("gnunet-service-arm",
164 "gnunet-service-arm",
168 "-c", cfgname, NULL);
170 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
171 GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
177 struct GNUNET_SCHEDULER_Handle *s,
180 const struct GNUNET_CONFIGURATION_Handle *cfg)
182 GNUNET_assert (ok == 1);
185 setup_peer (&p1, "test_core_api_peer1.conf");
186 setup_peer (&p2, "test_core_api_peer2.conf");
187 GNUNET_CORE_connect (sched,
196 GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
201 stop_arm (struct PeerContext *p)
204 if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
205 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
206 if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
207 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
209 "ARM process %u stopped\n", p->arm_pid);
211 GNUNET_CONFIGURATION_destroy (p->cfg);
218 char *const argv[] = { "test-core-api",
220 "test_core_api_data.conf",
226 struct GNUNET_GETOPT_CommandLineOption options[] = {
227 GNUNET_GETOPT_OPTION_END
231 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
232 argv, "test-core-api", "nohelp", options, &run, &ok);
239 main (int argc, char *argv[])
243 GNUNET_log_setup ("test-core-api",
255 /* end of test_core_api_start_only.c */