2 This file is part of GNUnet.
3 (C) 2011 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 3, 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.
22 * @file mesh/test_mesh_api.c
23 * @brief test mesh api: dummy test of callbacks
24 * @author Bartlomiej Polot
28 #include "gnunet_util_lib.h"
29 #include "gnunet_dht_service.h"
30 #include "gnunet_mesh_service_new.h"
35 static struct GNUNET_OS_Process *arm_pid;
36 static struct GNUNET_MESH_Handle *mesh;
38 GNUNET_SCHEDULER_TaskIdentifier abort_task;
39 GNUNET_SCHEDULER_TaskIdentifier test_task;
42 * Function is called whenever a message is received.
44 * @param cls closure (set from GNUNET_MESH_connect)
45 * @param tunnel connection to the other end
46 * @param tunnel_ctx place to store local state associated with the tunnel
47 * @param sender who sent the message
48 * @param message the actual message
49 * @param atsi performance data for the connection
50 * @return GNUNET_OK to keep the connection open,
51 * GNUNET_SYSERR to close it (signal serious error)
55 struct GNUNET_MESH_Tunnel *tunnel,
57 const struct GNUNET_PeerIdentity *sender,
58 const struct GNUNET_MessageHeader *message,
59 const struct GNUNET_TRANSPORT_ATS_Information
65 static struct GNUNET_MESH_MessageHandler handlers[] = {{&callback, 1, 0},
70 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
72 if (0 != abort_task) {
73 GNUNET_SCHEDULER_cancel(abort_task);
76 GNUNET_MESH_disconnect (mesh);
78 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) {
79 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
81 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
82 GNUNET_OS_process_close (arm_pid);
86 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
89 GNUNET_SCHEDULER_cancel(test_task);
91 result = GNUNET_SYSERR;
97 test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
99 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
100 GNUNET_MESH_ApplicationType app[3];
102 test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0;
103 app[0] = (GNUNET_MESH_ApplicationType) 1;
104 app[1] = (GNUNET_MESH_ApplicationType) 2;
105 app[2] = (GNUNET_MESH_ApplicationType) 0;
106 mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app);
108 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n");
111 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n");
114 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
115 GNUNET_TIME_UNIT_SECONDS, 1),
124 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
126 arm_pid = GNUNET_OS_start_process (NULL, NULL,
127 "gnunet-service-arm",
128 "gnunet-service-arm",
132 "-c", "test_mesh.conf",
135 abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
136 GNUNET_TIME_UNIT_SECONDS, 20),
139 test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
140 GNUNET_TIME_UNIT_SECONDS, 1),
148 main (int argc, char *argv[])
151 char *const argv2[] = {"test-mesh-api",
152 "-c", "test_mesh.conf",
158 struct GNUNET_GETOPT_CommandLineOption options[] = {
159 GNUNET_GETOPT_OPTION_END
161 GNUNET_log_setup ("test-mesh-api",
168 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1,
169 argv2, "test-mesh-api", "nohelp",
170 options, &run, NULL);
172 if ( GNUNET_OK != ret ) {
173 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
174 "run failed with error code %d\n", ret);
177 if ( GNUNET_SYSERR == result ) {
178 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,