aboutsummaryrefslogtreecommitdiff
path: root/src/core/test_core_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-30 23:07:34 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-30 23:07:34 +0000
commitb9ea28763dbf7fc8b43c0c78d315838fcf21bec0 (patch)
tree53f7deb49511a8fa675504ad2034796f28995096 /src/core/test_core_api.c
parentc4f4203aaff577fdbe60a7a0976e913dbb77f03e (diff)
downloadgnunet-b9ea28763dbf7fc8b43c0c78d315838fcf21bec0.tar.gz
gnunet-b9ea28763dbf7fc8b43c0c78d315838fcf21bec0.zip
starting to convert core tests to new MQ API
Diffstat (limited to 'src/core/test_core_api.c')
-rw-r--r--src/core/test_core_api.c151
1 files changed, 65 insertions, 86 deletions
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c
index 3f0b77bd1..772ded991 100644
--- a/src/core/test_core_api.c
+++ b/src/core/test_core_api.c
@@ -20,6 +20,7 @@
20/** 20/**
21 * @file core/test_core_api.c 21 * @file core/test_core_api.c
22 * @brief testcase for core_api.c 22 * @brief testcase for core_api.c
23 * @author Christian Grothoff
23 */ 24 */
24#include "platform.h" 25#include "platform.h"
25#include "gnunet_arm_service.h" 26#include "gnunet_arm_service.h"
@@ -91,7 +92,7 @@ terminate_peer (struct PeerContext *p)
91{ 92{
92 if (NULL != p->ch) 93 if (NULL != p->ch)
93 { 94 {
94 GNUNET_CORE_disconnect (p->ch); 95 GNUNET_CORE_disconnecT (p->ch);
95 p->ch = NULL; 96 p->ch = NULL;
96 } 97 }
97 if (NULL != p->ghh) 98 if (NULL != p->ghh)
@@ -140,35 +141,19 @@ terminate_task_error (void *cls)
140} 141}
141 142
142 143
143static size_t 144static void *
144transmit_ready (void *cls,
145 size_t size,
146 void *buf)
147{
148 struct PeerContext *p = cls;
149 struct GNUNET_MessageHeader *m;
150
151 GNUNET_assert (ok == 4);
152 OKPP;
153 GNUNET_assert (p == &p1);
154 GNUNET_assert (NULL != buf);
155 m = (struct GNUNET_MessageHeader *) buf;
156 m->type = htons (MTYPE);
157 m->size = htons (sizeof (struct GNUNET_MessageHeader));
158 return sizeof (struct GNUNET_MessageHeader);
159}
160
161
162static void
163connect_notify (void *cls, 145connect_notify (void *cls,
164 const struct GNUNET_PeerIdentity *peer) 146 const struct GNUNET_PeerIdentity *peer,
147 struct GNUNET_MQ_Handle *mq)
165{ 148{
166 struct PeerContext *pc = cls; 149 struct PeerContext *pc = cls;
150 struct GNUNET_MQ_Envelope *env;
151 struct GNUNET_MessageHeader *msg;
167 152
168 if (0 == memcmp (&pc->id, 153 if (0 == memcmp (&pc->id,
169 peer, 154 peer,
170 sizeof (struct GNUNET_PeerIdentity))) 155 sizeof (struct GNUNET_PeerIdentity)))
171 return; 156 return (void *) peer;
172 GNUNET_assert (pc->connect_status == 0); 157 GNUNET_assert (pc->connect_status == 0);
173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
174 "Encrypted connection established to peer `%s'\n", 159 "Encrypted connection established to peer `%s'\n",
@@ -176,30 +161,35 @@ connect_notify (void *cls,
176 pc->connect_status = 1; 161 pc->connect_status = 1;
177 if (pc == &p1) 162 if (pc == &p1)
178 { 163 {
164 uint64_t flags;
165 const void *extra;
166
179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
180 "Asking core (1) for transmission to peer `%s'\n", 168 "Asking core (1) for transmission to peer `%s'\n",
181 GNUNET_i2s (&p2.id)); 169 GNUNET_i2s (&p2.id));
182 if (NULL == 170 env = GNUNET_MQ_msg (msg,
183 GNUNET_CORE_notify_transmit_ready (p1.ch, 171 MTYPE);
184 GNUNET_YES, 172 /* enable corking for this test */
185 GNUNET_CORE_PRIO_BEST_EFFORT, 173 extra = GNUNET_CORE_get_mq_options (GNUNET_YES,
186 GNUNET_TIME_relative_multiply 174 GNUNET_CORE_PRIO_BEST_EFFORT,
187 (GNUNET_TIME_UNIT_SECONDS, 145), 175 &flags);
188 &p2.id, 176 GNUNET_MQ_env_set_options (env,
189 sizeof (struct GNUNET_MessageHeader), 177 flags,
190 &transmit_ready, &p1)) 178 extra);
191 { 179 /* now actually transmit message */
192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 180 GNUNET_assert (ok == 4);
193 "RECEIVED NULL when asking core (1) for transmission to peer `%s'\n", 181 OKPP;
194 GNUNET_i2s (&p2.id)); 182 GNUNET_MQ_send (mq,
195 } 183 env);
196 } 184 }
185 return (void *) peer;
197} 186}
198 187
199 188
200static void 189static void
201disconnect_notify (void *cls, 190disconnect_notify (void *cls,
202 const struct GNUNET_PeerIdentity *peer) 191 const struct GNUNET_PeerIdentity *peer,
192 void *internal_cls)
203{ 193{
204 struct PeerContext *pc = cls; 194 struct PeerContext *pc = cls;
205 195
@@ -214,35 +204,12 @@ disconnect_notify (void *cls,
214} 204}
215 205
216 206
217static int 207static void
218inbound_notify (void *cls, 208handle_test (void *cls,
219 const struct GNUNET_PeerIdentity *other, 209 const struct GNUNET_MessageHeader *message)
220 const struct GNUNET_MessageHeader *message)
221{
222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
223 "Core provides inbound data from `%s'.\n",
224 GNUNET_i2s (other));
225 return GNUNET_OK;
226}
227
228
229static int
230outbound_notify (void *cls,
231 const struct GNUNET_PeerIdentity *other,
232 const struct GNUNET_MessageHeader *message)
233{
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
235 "Core notifies about outbound data for `%s'.\n",
236 GNUNET_i2s (other));
237 return GNUNET_OK;
238}
239
240
241static int
242process_mtype (void *cls,
243 const struct GNUNET_PeerIdentity *peer,
244 const struct GNUNET_MessageHeader *message)
245{ 210{
211 const struct GNUNET_PeerIdentity *peer = cls;
212
246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
247 "Receiving message from `%s'.\n", 214 "Receiving message from `%s'.\n",
248 GNUNET_i2s (peer)); 215 GNUNET_i2s (peer));
@@ -251,21 +218,21 @@ process_mtype (void *cls,
251 GNUNET_SCHEDULER_cancel (err_task); 218 GNUNET_SCHEDULER_cancel (err_task);
252 err_task = GNUNET_SCHEDULER_add_now (&terminate_task, 219 err_task = GNUNET_SCHEDULER_add_now (&terminate_task,
253 NULL); 220 NULL);
254 return GNUNET_OK;
255} 221}
256 222
257 223
258static struct GNUNET_CORE_MessageHandler handlers[] = {
259 {&process_mtype, MTYPE, sizeof (struct GNUNET_MessageHeader)},
260 {NULL, 0, 0}
261};
262
263
264static void 224static void
265init_notify (void *cls, 225init_notify (void *cls,
266 const struct GNUNET_PeerIdentity *my_identity) 226 const struct GNUNET_PeerIdentity *my_identity)
267{ 227{
228 GNUNET_MQ_hd_fixed_size (test,
229 MTYPE,
230 struct GNUNET_MessageHeader);
268 struct PeerContext *p = cls; 231 struct PeerContext *p = cls;
232 struct GNUNET_MQ_MessageHandler handlers[] = {
233 make_test_handler (NULL),
234 GNUNET_MQ_handler_end ()
235 };
269 236
270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
271 "Core connection to `%s' established\n", 238 "Core connection to `%s' established\n",
@@ -276,13 +243,11 @@ init_notify (void *cls,
276 GNUNET_assert (ok == 2); 243 GNUNET_assert (ok == 2);
277 OKPP; 244 OKPP;
278 /* connect p2 */ 245 /* connect p2 */
279 p2.ch = GNUNET_CORE_connect (p2.cfg, 246 p2.ch = GNUNET_CORE_connecT (p2.cfg,
280 &p2, 247 &p2,
281 &init_notify, 248 &init_notify,
282 &connect_notify, 249 &connect_notify,
283 &disconnect_notify, 250 &disconnect_notify,
284 &inbound_notify, GNUNET_YES,
285 &outbound_notify, GNUNET_YES,
286 handlers); 251 handlers);
287 } 252 }
288 else 253 else
@@ -333,21 +298,30 @@ run (void *cls,
333 const char *cfgfile, 298 const char *cfgfile,
334 const struct GNUNET_CONFIGURATION_Handle *cfg) 299 const struct GNUNET_CONFIGURATION_Handle *cfg)
335{ 300{
301 GNUNET_MQ_hd_fixed_size (test,
302 MTYPE,
303 struct GNUNET_MessageHeader);
304 struct GNUNET_MQ_MessageHandler handlers[] = {
305 make_test_handler (NULL),
306 GNUNET_MQ_handler_end ()
307 };
308
336 GNUNET_assert (ok == 1); 309 GNUNET_assert (ok == 1);
337 OKPP; 310 OKPP;
338 setup_peer (&p1, "test_core_api_peer1.conf"); 311 setup_peer (&p1,
339 setup_peer (&p2, "test_core_api_peer2.conf"); 312 "test_core_api_peer1.conf");
313 setup_peer (&p2,
314 "test_core_api_peer2.conf");
340 err_task = 315 err_task =
341 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 316 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
342 (GNUNET_TIME_UNIT_SECONDS, 300), 317 (GNUNET_TIME_UNIT_SECONDS, 300),
343 &terminate_task_error, NULL); 318 &terminate_task_error, NULL);
344 p1.ch = 319 p1.ch =
345 GNUNET_CORE_connect (p1.cfg, &p1, 320 GNUNET_CORE_connecT (p1.cfg,
321 &p1,
346 &init_notify, 322 &init_notify,
347 &connect_notify, 323 &connect_notify,
348 &disconnect_notify, 324 &disconnect_notify,
349 &inbound_notify, GNUNET_YES,
350 &outbound_notify, GNUNET_YES,
351 handlers); 325 handlers);
352} 326}
353 327
@@ -355,11 +329,16 @@ run (void *cls,
355static void 329static void
356stop_arm (struct PeerContext *p) 330stop_arm (struct PeerContext *p)
357{ 331{
358 if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) 332 if (0 != GNUNET_OS_process_kill (p->arm_proc,
359 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 333 GNUNET_TERM_SIG))
360 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 334 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
361 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 335 "kill");
362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", 336 if (GNUNET_OK !=
337 GNUNET_OS_process_wait (p->arm_proc))
338 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
339 "waitpid");
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
341 "ARM process %u stopped\n",
363 GNUNET_OS_process_get_pid (p->arm_proc)); 342 GNUNET_OS_process_get_pid (p->arm_proc));
364 GNUNET_OS_process_destroy (p->arm_proc); 343 GNUNET_OS_process_destroy (p->arm_proc);
365 p->arm_proc = NULL; 344 p->arm_proc = NULL;