Added mesh testing code and configuration files
[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
11 static void
12 run (void *cls,
13      char *const *args,
14      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) {
15     struct GNUNET_OS_Process            *arm_pid;
16     struct GNUNET_MESH_Handle           *mesh;
17     struct GNUNET_DHT_Handle            *dht;
18     GNUNET_MESH_ApplicationType         app;
19     char                                buffer[2048];
20
21
22     arm_pid = GNUNET_OS_start_process (NULL, NULL,
23                                        "gnunet-service-arm",
24                                        "gnunet-service-arm",
25                                        "-L", "DEBUG",
26                                        "-c", "test_mesh.conf",
27                                        NULL);
28     dht = GNUNET_DHT_connect(cfg, 100);
29     if(NULL == dht) {
30         GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to dht :(\n");
31     } else {
32         GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO DHT :D\n");
33     }
34
35     app = 0;
36     mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app);
37     if(NULL == mesh) {
38         GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n");
39     } else {
40         GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n");
41     }
42
43     /* do real test work here */
44     if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
45         GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
46     GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
47     GNUNET_OS_process_close (arm_pid);
48
49     return;
50 }
51
52
53
54 int main (int argc, char *argv[]) {
55     int ret;
56     char *const argv2[] = {"test-mesh-api",
57         "-c", "test_mesh.conf",
58         "-L", "DEBUG",
59         NULL
60     };
61     struct GNUNET_GETOPT_CommandLineOption options[] = {
62         GNUNET_GETOPT_OPTION_END
63     };
64       GNUNET_log_setup ("test-dht-api","DEBUG", NULL);
65     ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1,
66                         argv2, "test-mesh-api", "nohelp",
67                         options, &run, NULL);
68     if (ret != GNUNET_OK) {
69         GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "test-mesh-api': Failed with error code %d\n", ret);
70     }
71     return 0;
72 }