diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-05-12 22:21:16 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-05-12 22:21:16 +0000 |
commit | bb0f1a9c37476ebe08b2de7b6fb7f8b2ed0514b5 (patch) | |
tree | 091423fbd715fc8c8ed0bd8107ae6b9cde4bf8c9 /src/mesh/test_mesh_api.c | |
parent | 33b69c82ed1aed813b58aa076fbbed72a8e834b4 (diff) | |
download | gnunet-bb0f1a9c37476ebe08b2de7b6fb7f8b2ed0514b5.tar.gz gnunet-bb0f1a9c37476ebe08b2de7b6fb7f8b2ed0514b5.zip |
WiP
Diffstat (limited to 'src/mesh/test_mesh_api.c')
-rw-r--r-- | src/mesh/test_mesh_api.c | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/src/mesh/test_mesh_api.c b/src/mesh/test_mesh_api.c index 5f988f555..6c3bd60a9 100644 --- a/src/mesh/test_mesh_api.c +++ b/src/mesh/test_mesh_api.c | |||
@@ -11,28 +11,40 @@ static struct GNUNET_OS_Process *arm_pid; | |||
11 | 11 | ||
12 | static struct GNUNET_MESH_Handle *mesh; | 12 | static struct GNUNET_MESH_Handle *mesh; |
13 | 13 | ||
14 | static struct GNUNET_DHT_Handle *dht; | ||
15 | |||
16 | static void | 14 | static void |
17 | do_shutdown (void *cls, | 15 | do_shutdown (void *cls, |
18 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 16 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
19 | { | 17 | { |
20 | if (NULL != mesh) | 18 | if (NULL != mesh) { |
21 | GNUNET_MESH_disconnect (mesh); | 19 | GNUNET_MESH_disconnect (mesh); |
22 | if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) | 20 | } |
21 | if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) { | ||
23 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 22 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
23 | } | ||
24 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid)); | 24 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid)); |
25 | GNUNET_OS_process_close (arm_pid); | 25 | GNUNET_OS_process_close (arm_pid); |
26 | } | 26 | } |
27 | 27 | ||
28 | 28 | ||
29 | static void | 29 | static void |
30 | error_shutdown (void *cls, | ||
31 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
32 | { | ||
33 | if (NULL != mesh) { | ||
34 | GNUNET_MESH_disconnect (mesh); | ||
35 | } | ||
36 | if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) { | ||
37 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
38 | } | ||
39 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid)); | ||
40 | GNUNET_OS_process_close (arm_pid); | ||
41 | } | ||
42 | |||
43 | static void | ||
30 | run (void *cls, | 44 | run (void *cls, |
31 | char *const *args, | 45 | char *const *args, |
32 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { | 46 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { |
33 | GNUNET_MESH_ApplicationType app; | 47 | GNUNET_MESH_ApplicationType app; |
34 | // char buffer[2048]; | ||
35 | |||
36 | 48 | ||
37 | arm_pid = GNUNET_OS_start_process (NULL, NULL, | 49 | arm_pid = GNUNET_OS_start_process (NULL, NULL, |
38 | "gnunet-service-arm", | 50 | "gnunet-service-arm", |
@@ -40,13 +52,6 @@ run (void *cls, | |||
40 | "-L", "DEBUG", | 52 | "-L", "DEBUG", |
41 | "-c", "test_mesh.conf", | 53 | "-c", "test_mesh.conf", |
42 | NULL); | 54 | 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; | 55 | app = 0; |
51 | mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app); | 56 | mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app); |
52 | if(NULL == mesh) { | 57 | if(NULL == mesh) { |
@@ -56,15 +61,13 @@ run (void *cls, | |||
56 | } | 61 | } |
57 | 62 | ||
58 | /* do real test work here */ | 63 | /* do real test work here */ |
59 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 64 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( |
60 | &do_shutdown, | 65 | GNUNET_TIME_UNIT_SECONDS, 5), |
61 | NULL); | 66 | &do_shutdown, |
67 | NULL); | ||
62 | } | 68 | } |
63 | 69 | ||
64 | 70 | ||
65 | |||
66 | |||
67 | |||
68 | int main (int argc, char *argv[]) { | 71 | int main (int argc, char *argv[]) { |
69 | int ret; | 72 | int ret; |
70 | char *const argv2[] = {"test-mesh-api", | 73 | char *const argv2[] = {"test-mesh-api", |
@@ -80,7 +83,9 @@ int main (int argc, char *argv[]) { | |||
80 | argv2, "test-mesh-api", "nohelp", | 83 | argv2, "test-mesh-api", "nohelp", |
81 | options, &run, NULL); | 84 | options, &run, NULL); |
82 | if (ret != GNUNET_OK) { | 85 | if (ret != GNUNET_OK) { |
83 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "test-mesh-api': Failed with error code %d\n", ret); | 86 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
87 | "test-mesh-api': Failed with error code %d\n", ret); | ||
88 | return 1; | ||
84 | } | 89 | } |
85 | return 0; | 90 | return 0; |
86 | } | 91 | } |