aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/test_mesh_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesh/test_mesh_api.c')
-rw-r--r--src/mesh/test_mesh_api.c188
1 files changed, 97 insertions, 91 deletions
diff --git a/src/mesh/test_mesh_api.c b/src/mesh/test_mesh_api.c
index c85f2e738..9828ee8d9 100644
--- a/src/mesh/test_mesh_api.c
+++ b/src/mesh/test_mesh_api.c
@@ -32,11 +32,11 @@
32#define VERBOSE 1 32#define VERBOSE 1
33#define VERBOSE_ARM 0 33#define VERBOSE_ARM 0
34 34
35static struct GNUNET_OS_Process *arm_pid; 35static struct GNUNET_OS_Process *arm_pid;
36static struct GNUNET_MESH_Handle *mesh; 36static struct GNUNET_MESH_Handle *mesh;
37static int result; 37static int result;
38GNUNET_SCHEDULER_TaskIdentifier abort_task; 38GNUNET_SCHEDULER_TaskIdentifier abort_task;
39GNUNET_SCHEDULER_TaskIdentifier test_task; 39GNUNET_SCHEDULER_TaskIdentifier test_task;
40 40
41/** 41/**
42 * Function is called whenever a message is received. 42 * Function is called whenever a message is received.
@@ -51,70 +51,76 @@ GNUNET_SCHEDULER_TaskIdentifier test_task;
51 * GNUNET_SYSERR to close it (signal serious error) 51 * GNUNET_SYSERR to close it (signal serious error)
52 */ 52 */
53static int 53static int
54callback(void *cls, 54callback (void *cls,
55 struct GNUNET_MESH_Tunnel *tunnel, 55 struct GNUNET_MESH_Tunnel *tunnel,
56 void **tunnel_ctx, 56 void **tunnel_ctx,
57 const struct GNUNET_PeerIdentity *sender, 57 const struct GNUNET_PeerIdentity *sender,
58 const struct GNUNET_MessageHeader *message, 58 const struct GNUNET_MessageHeader *message,
59 const struct GNUNET_TRANSPORT_ATS_Information 59 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
60 *atsi)
61{ 60{
62 return 0; 61 return 0;
63} 62}
64 63
65static struct GNUNET_MESH_MessageHandler handlers[] = {{&callback, 1, 0}, 64static struct GNUNET_MESH_MessageHandler handlers[] = { {&callback, 1, 0},
66 {NULL, 0, 0}}; 65{NULL, 0, 0}
66};
67 67
68 68
69static void 69static void
70do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 70do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
71{ 71{
72 if (0 != abort_task) { 72 if (0 != abort_task)
73 GNUNET_SCHEDULER_cancel(abort_task); 73 {
74 } 74 GNUNET_SCHEDULER_cancel (abort_task);
75 if (NULL != mesh) { 75 }
76 GNUNET_MESH_disconnect (mesh); 76 if (NULL != mesh)
77 } 77 {
78 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) { 78 GNUNET_MESH_disconnect (mesh);
79 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 79 }
80 } 80 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
81 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid)); 81 {
82 GNUNET_OS_process_close (arm_pid); 82 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
83 }
84 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
85 GNUNET_OS_process_close (arm_pid);
83} 86}
84 87
85static void 88static void
86do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 89do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
87{ 90{
88 if (0 != test_task) { 91 if (0 != test_task)
89 GNUNET_SCHEDULER_cancel(test_task); 92 {
90 } 93 GNUNET_SCHEDULER_cancel (test_task);
91 result = GNUNET_SYSERR; 94 }
92 abort_task = 0; 95 result = GNUNET_SYSERR;
93 do_shutdown(cls, tc); 96 abort_task = 0;
97 do_shutdown (cls, tc);
94} 98}
95 99
96static void 100static void
97test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 101test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
98{ 102{
99 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 103 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
100 GNUNET_MESH_ApplicationType app[3]; 104 GNUNET_MESH_ApplicationType app[3];
101 105
102 test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0; 106 test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0;
103 app[0] = (GNUNET_MESH_ApplicationType) 1; 107 app[0] = (GNUNET_MESH_ApplicationType) 1;
104 app[1] = (GNUNET_MESH_ApplicationType) 2; 108 app[1] = (GNUNET_MESH_ApplicationType) 2;
105 app[2] = (GNUNET_MESH_ApplicationType) 0; 109 app[2] = (GNUNET_MESH_ApplicationType) 0;
106 mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app); 110 mesh = GNUNET_MESH_connect (cfg, NULL, NULL, handlers, &app);
107 if(NULL == mesh) { 111 if (NULL == mesh)
108 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n"); 112 {
109 return; 113 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n");
110 } else { 114 return;
111 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n"); 115 }
112 } 116 else
113 117 {
114 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( 118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n");
115 GNUNET_TIME_UNIT_SECONDS, 1), 119 }
116 &do_shutdown, 120
117 NULL); 121 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
122 (GNUNET_TIME_UNIT_SECONDS, 1), &do_shutdown,
123 NULL);
118} 124}
119 125
120 126
@@ -123,23 +129,21 @@ run (void *cls,
123 char *const *args, 129 char *const *args,
124 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 130 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
125{ 131{
126 arm_pid = GNUNET_OS_start_process (NULL, NULL, 132 arm_pid = GNUNET_OS_start_process (NULL, NULL,
127 "gnunet-service-arm", 133 "gnunet-service-arm", "gnunet-service-arm",
128 "gnunet-service-arm",
129#if VERBOSE_ARM 134#if VERBOSE_ARM
130 "-L", "DEBUG", 135 "-L", "DEBUG",
131#endif 136#endif
132 "-c", "test_mesh.conf", 137 "-c", "test_mesh.conf", NULL);
133 NULL); 138
134 139 abort_task =
135 abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( 140 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
136 GNUNET_TIME_UNIT_SECONDS, 20), 141 (GNUNET_TIME_UNIT_SECONDS, 20), &do_abort,
137 &do_abort, 142 NULL);
138 NULL); 143 test_task =
139 test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( 144 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
140 GNUNET_TIME_UNIT_SECONDS, 1), 145 (GNUNET_TIME_UNIT_SECONDS, 1), &test,
141 &test, 146 (void *) cfg);
142 (void *)cfg);
143 147
144} 148}
145 149
@@ -147,37 +151,39 @@ run (void *cls,
147int 151int
148main (int argc, char *argv[]) 152main (int argc, char *argv[])
149{ 153{
150 int ret; 154 int ret;
151 char *const argv2[] = {"test-mesh-api", 155
152 "-c", "test_mesh.conf", 156 char *const argv2[] = { "test-mesh-api",
157 "-c", "test_mesh.conf",
153#if VERBOSE 158#if VERBOSE
154 "-L", "DEBUG", 159 "-L", "DEBUG",
155#endif 160#endif
156 NULL 161 NULL
157 }; 162 };
158 struct GNUNET_GETOPT_CommandLineOption options[] = { 163 struct GNUNET_GETOPT_CommandLineOption options[] = {
159 GNUNET_GETOPT_OPTION_END 164 GNUNET_GETOPT_OPTION_END
160 }; 165 };
161 GNUNET_log_setup ("test-mesh-api", 166 GNUNET_log_setup ("test-mesh-api",
162#if VERBOSE 167#if VERBOSE
163 "DEBUG", 168 "DEBUG",
164#else 169#else
165 "WARNING", 170 "WARNING",
166#endif 171#endif
167 NULL); 172 NULL);
168 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, 173 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1,
169 argv2, "test-mesh-api", "nohelp", 174 argv2, "test-mesh-api", "nohelp",
170 options, &run, NULL); 175 options, &run, NULL);
171 176
172 if ( GNUNET_OK != ret ) { 177 if (GNUNET_OK != ret)
173 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 178 {
174 "run failed with error code %d\n", ret); 179 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
175 return 1; 180 "run failed with error code %d\n", ret);
176 } 181 return 1;
177 if ( GNUNET_SYSERR == result ) { 182 }
178 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 183 if (GNUNET_SYSERR == result)
179 "test failed\n"); 184 {
180 return 1; 185 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test failed\n");
181 } 186 return 1;
182 return 0; 187 }
188 return 0;
183} 189}