aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/test_mesh_api.c
blob: 00212eb4976afa7e1888bf6149171bfc86a236fd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_dht_service.h"
#include "gnunet_mesh_service_new.h"

static struct GNUNET_MESH_MessageHandler handlers[] = {
    {NULL, 0, 0}
};


static void
run (void *cls,
     char *const *args,
     const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) {
    struct GNUNET_OS_Process            *arm_pid;
    struct GNUNET_MESH_Handle           *mesh;
    struct GNUNET_DHT_Handle            *dht;
    GNUNET_MESH_ApplicationType         app;
    char                                buffer[2048];


    arm_pid = GNUNET_OS_start_process (NULL, NULL,
                                       "gnunet-service-arm",
                                       "gnunet-service-arm",
                                       "-L", "DEBUG",
                                       "-c", "test_mesh.conf",
                                       NULL);
    dht = GNUNET_DHT_connect(cfg, 100);
    if(NULL == dht) {
        GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to dht :(\n");
    } else {
        GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO DHT :D\n");
    }

    app = 0;
    mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app);
    if(NULL == mesh) {
        GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n");
    } else {
        GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n");
    }

    /* do real test work here */
    if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
        GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
    GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
    GNUNET_OS_process_close (arm_pid);

    return;
}



int main (int argc, char *argv[]) {
    int ret;
    char *const argv2[] = {"test-mesh-api",
        "-c", "test_mesh.conf",
        "-L", "DEBUG",
        NULL
    };
    struct GNUNET_GETOPT_CommandLineOption options[] = {
        GNUNET_GETOPT_OPTION_END
    };
      GNUNET_log_setup ("test-dht-api","DEBUG", NULL);
    ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1,
                        argv2, "test-mesh-api", "nohelp",
                        options, &run, NULL);
    if (ret != GNUNET_OK) {
        GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "test-mesh-api': Failed with error code %d\n", ret);
    }
    return 0;
}