fixes
[oweals/gnunet.git] / src / mesh / test_mesh_api.c
1 #include "platform.h"
2 #include "gnunet_util_lib.h"
3 #include "gnunet_dht_service.h"
4 #include "gnunet_mesh_service_new.h"
5
6 static struct GNUNET_MESH_MessageHandler handlers[] = {
7     {NULL, 0, 0}
8 };
9
10 static struct GNUNET_OS_Process            *arm_pid;
11
12 static struct GNUNET_MESH_Handle           *mesh;
13
14 static struct GNUNET_DHT_Handle            *dht;
15
16 static void
17   do_shutdown (void *cls,
18                const struct GNUNET_SCHEDULER_TaskContext *tc)
19 {
20   if (NULL != mesh)
21     GNUNET_MESH_disconnect (mesh);
22     if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
23         GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
24     GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
25     GNUNET_OS_process_close (arm_pid);
26 }
27
28
29 static void
30 run (void *cls,
31      char *const *args,
32      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) {
33     GNUNET_MESH_ApplicationType         app;
34     // char                                buffer[2048];
35
36
37     arm_pid = GNUNET_OS_start_process (NULL, NULL,
38                                        "gnunet-service-arm",
39                                        "gnunet-service-arm",
40                                        "-L", "DEBUG",
41                                        "-c", "test_mesh.conf",
42                                        NULL);
43     dht = GNUNET_DHT_connect(cfg, 100);
44     if(NULL == dht) {
45         GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to dht :(\n");
46     } else {
47         GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO DHT :D\n");
48     }
49
50     app = 0;
51     mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app);
52     if(NULL == mesh) {
53         GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n");
54     } else {
55         GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n");
56     }
57
58     /* do real test work here */
59     GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
60                                   &do_shutdown,
61                                   NULL);
62 }
63
64
65
66
67
68 int main (int argc, char *argv[]) {
69     int ret;
70     char *const argv2[] = {"test-mesh-api",
71         "-c", "test_mesh.conf",
72         "-L", "DEBUG",
73         NULL
74     };
75     struct GNUNET_GETOPT_CommandLineOption options[] = {
76         GNUNET_GETOPT_OPTION_END
77     };
78       GNUNET_log_setup ("test-dht-api","DEBUG", NULL);
79     ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1,
80                         argv2, "test-mesh-api", "nohelp",
81                         options, &run, NULL);
82     if (ret != GNUNET_OK) {
83         GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "test-mesh-api': Failed with error code %d\n", ret);
84     }
85     return 0;
86 }