aboutsummaryrefslogtreecommitdiff
path: root/src/core
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
parentc4f4203aaff577fdbe60a7a0976e913dbb77f03e (diff)
downloadgnunet-b9ea28763dbf7fc8b43c0c78d315838fcf21bec0.tar.gz
gnunet-b9ea28763dbf7fc8b43c0c78d315838fcf21bec0.zip
starting to convert core tests to new MQ API
Diffstat (limited to 'src/core')
-rw-r--r--src/core/test_core_api.c151
-rw-r--r--src/core/test_core_api_reliability.c33
-rw-r--r--src/core/test_core_api_start_only.c68
3 files changed, 96 insertions, 156 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;
diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c
index c5ee12478..7a3b53c53 100644
--- a/src/core/test_core_api_reliability.c
+++ b/src/core/test_core_api_reliability.c
@@ -20,6 +20,7 @@
20/** 20/**
21 * @file core/test_core_api_reliability.c 21 * @file core/test_core_api_reliability.c
22 * @brief testcase for core_api.c focusing on reliable transmission (with TCP) 22 * @brief testcase for core_api.c focusing on reliable transmission (with TCP)
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"
@@ -291,30 +292,6 @@ disconnect_notify (void *cls,
291} 292}
292 293
293 294
294static int
295inbound_notify (void *cls,
296 const struct GNUNET_PeerIdentity *other,
297 const struct GNUNET_MessageHeader *message)
298{
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
300 "Core provides inbound data from `%s'.\n",
301 GNUNET_i2s (other));
302 return GNUNET_OK;
303}
304
305
306static int
307outbound_notify (void *cls,
308 const struct GNUNET_PeerIdentity *other,
309 const struct GNUNET_MessageHeader *message)
310{
311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
312 "Core notifies about outbound data for `%s'.\n",
313 GNUNET_i2s (other));
314 return GNUNET_OK;
315}
316
317
318static size_t 295static size_t
319transmit_ready (void *cls, 296transmit_ready (void *cls,
320 size_t size, 297 size_t size,
@@ -413,9 +390,9 @@ init_notify (void *cls,
413 &init_notify, 390 &init_notify,
414 &connect_notify, 391 &connect_notify,
415 &disconnect_notify, 392 &disconnect_notify,
416 &inbound_notify, 393 NULL,
417 GNUNET_YES, 394 GNUNET_YES,
418 &outbound_notify, 395 NULL,
419 GNUNET_YES, 396 GNUNET_YES,
420 handlers))); 397 handlers)));
421 } 398 }
@@ -532,9 +509,9 @@ run (void *cls,
532 &init_notify, 509 &init_notify,
533 &connect_notify, 510 &connect_notify,
534 &disconnect_notify, 511 &disconnect_notify,
535 &inbound_notify, 512 NULL,
536 GNUNET_YES, 513 GNUNET_YES,
537 &outbound_notify, 514 NULL,
538 GNUNET_YES, 515 GNUNET_YES,
539 handlers))); 516 handlers)));
540} 517}
diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c
index 07a402189..6abc3cc89 100644
--- a/src/core/test_core_api_start_only.c
+++ b/src/core/test_core_api_start_only.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009, 2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -21,6 +21,7 @@
21 * @file transport/test_core_api_start_only.c 21 * @file transport/test_core_api_start_only.c
22 * @brief testcase for core_api.c that only starts two peers, 22 * @brief testcase for core_api.c that only starts two peers,
23 * connects to the core service and shuts down again 23 * connects to the core service and shuts down again
24 * @author Christian Grothoff
24 */ 25 */
25#include "platform.h" 26#include "platform.h"
26#include "gnunet_arm_service.h" 27#include "gnunet_arm_service.h"
@@ -48,49 +49,34 @@ static struct GNUNET_SCHEDULER_Task *timeout_task_id;
48static int ok; 49static int ok;
49 50
50 51
51static void 52static void *
52connect_notify (void *cls, 53connect_notify (void *cls,
53 const struct GNUNET_PeerIdentity *peer) 54 const struct GNUNET_PeerIdentity *peer,
55 struct GNUNET_MQ_Handle *mq)
54{ 56{
57 return NULL;
55} 58}
56 59
57 60
58static void 61static void
59disconnect_notify (void *cls, 62disconnect_notify (void *cls,
60 const struct GNUNET_PeerIdentity *peer) 63 const struct GNUNET_PeerIdentity *peer,
61{ 64 void *internal_cls)
62}
63
64
65static int
66inbound_notify (void *cls,
67 const struct GNUNET_PeerIdentity *other,
68 const struct GNUNET_MessageHeader *message)
69{
70 return GNUNET_OK;
71}
72
73
74static int
75outbound_notify (void *cls,
76 const struct GNUNET_PeerIdentity *other,
77 const struct GNUNET_MessageHeader *message)
78{ 65{
79 return GNUNET_OK;
80} 66}
81 67
82 68
83static struct GNUNET_CORE_MessageHandler handlers[] = { 69static struct GNUNET_MQ_MessageHandler handlers[] = {
84 {NULL, 0, 0} 70 GNUNET_MQ_handler_end ()
85}; 71};
86 72
87 73
88static void 74static void
89shutdown_task (void *cls) 75shutdown_task (void *cls)
90{ 76{
91 GNUNET_CORE_disconnect (p1.ch); 77 GNUNET_CORE_disconnecT (p1.ch);
92 p1.ch = NULL; 78 p1.ch = NULL;
93 GNUNET_CORE_disconnect (p2.ch); 79 GNUNET_CORE_disconnecT (p2.ch);
94 p2.ch = NULL; 80 p2.ch = NULL;
95 ok = 0; 81 ok = 0;
96} 82}
@@ -105,15 +91,12 @@ init_notify (void *cls,
105 if (p == &p1) 91 if (p == &p1)
106 { 92 {
107 /* connect p2 */ 93 /* connect p2 */
108 p2.ch = 94 p2.ch = GNUNET_CORE_connecT (p2.cfg,
109 GNUNET_CORE_connect (p2.cfg, 95 &p2,
110 &p2, 96 &init_notify,
111 &init_notify, 97 &connect_notify,
112 &connect_notify, 98 &disconnect_notify,
113 &disconnect_notify, 99 handlers);
114 &inbound_notify, GNUNET_YES,
115 &outbound_notify, GNUNET_YES,
116 handlers);
117 } 100 }
118 else 101 else
119 { 102 {
@@ -152,15 +135,17 @@ setup_peer (struct PeerContext *p,
152static void 135static void
153timeout_task (void *cls) 136timeout_task (void *cls)
154{ 137{
155 FPRINTF (stderr, "%s", "Timeout.\n"); 138 FPRINTF (stderr,
139 "%s",
140 "Timeout.\n");
156 if (NULL != p1.ch) 141 if (NULL != p1.ch)
157 { 142 {
158 GNUNET_CORE_disconnect (p1.ch); 143 GNUNET_CORE_disconnecT (p1.ch);
159 p1.ch = NULL; 144 p1.ch = NULL;
160 } 145 }
161 if (NULL != p2.ch) 146 if (NULL != p2.ch)
162 { 147 {
163 GNUNET_CORE_disconnect (p2.ch); 148 GNUNET_CORE_disconnecT (p2.ch);
164 p2.ch = NULL; 149 p2.ch = NULL;
165 } 150 }
166 ok = 42; 151 ok = 42;
@@ -181,14 +166,13 @@ run (void *cls,
181 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 166 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
182 (GNUNET_TIME_UNIT_MINUTES, 167 (GNUNET_TIME_UNIT_MINUTES,
183 TIMEOUT), 168 TIMEOUT),
184 &timeout_task, NULL); 169 &timeout_task,
185 p1.ch = GNUNET_CORE_connect (p1.cfg, 170 NULL);
171 p1.ch = GNUNET_CORE_connecT (p1.cfg,
186 &p1, 172 &p1,
187 &init_notify, 173 &init_notify,
188 &connect_notify, 174 &connect_notify,
189 &disconnect_notify, 175 &disconnect_notify,
190 &inbound_notify, GNUNET_YES,
191 &outbound_notify, GNUNET_YES,
192 handlers); 176 handlers);
193} 177}
194 178