aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-30 23:27:01 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-30 23:27:01 +0000
commitdc07a1e8dfd9fb78756a5277063aeba8b0665e27 (patch)
tree1bb8dd985f90541f2fa602ed551b467b59f509da /src/core
parentb9ea28763dbf7fc8b43c0c78d315838fcf21bec0 (diff)
downloadgnunet-dc07a1e8dfd9fb78756a5277063aeba8b0665e27.tar.gz
gnunet-dc07a1e8dfd9fb78756a5277063aeba8b0665e27.zip
adapting next test to new MQ API
Diffstat (limited to 'src/core')
-rw-r--r--src/core/gnunet-service-core_clients.c6
-rw-r--r--src/core/test_core_api_reliability.c203
2 files changed, 84 insertions, 125 deletions
diff --git a/src/core/gnunet-service-core_clients.c b/src/core/gnunet-service-core_clients.c
index 2f042dfbf..5db33f04b 100644
--- a/src/core/gnunet-service-core_clients.c
+++ b/src/core/gnunet-service-core_clients.c
@@ -469,7 +469,6 @@ handle_client_send (void *cls,
469 struct TokenizerContext tc; 469 struct TokenizerContext tc;
470 uint16_t msize; 470 uint16_t msize;
471 struct GNUNET_TIME_Relative delay; 471 struct GNUNET_TIME_Relative delay;
472 struct GNUNET_TIME_Relative overdue;
473 472
474 msize = ntohs (message->size); 473 msize = ntohs (message->size);
475 if (msize < sizeof (struct SendMessage)) 474 if (msize < sizeof (struct SendMessage))
@@ -509,10 +508,9 @@ handle_client_send (void *cls,
509 return; 508 return;
510 } 509 }
511 delay = GNUNET_TIME_absolute_get_duration (tc.car->received_time); 510 delay = GNUNET_TIME_absolute_get_duration (tc.car->received_time);
512 overdue = GNUNET_TIME_absolute_get_duration (tc.car->deadline);
513 tc.cork = ntohl (sm->cork); 511 tc.cork = ntohl (sm->cork);
514 tc.priority = (enum GNUNET_CORE_Priority) ntohl (sm->priority); 512 tc.priority = (enum GNUNET_CORE_Priority) ntohl (sm->priority);
515 if (overdue.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 513 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
516 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 514 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
517 "Client waited %s for transmission of %u bytes to `%s'%s\n", 515 "Client waited %s for transmission of %u bytes to `%s'%s\n",
518 GNUNET_STRINGS_relative_time_to_string (delay, 516 GNUNET_STRINGS_relative_time_to_string (delay,
@@ -711,7 +709,7 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car)
711 } 709 }
712 delay = GNUNET_TIME_absolute_get_duration (car->received_time); 710 delay = GNUNET_TIME_absolute_get_duration (car->received_time);
713 left = GNUNET_TIME_absolute_get_duration (car->deadline); 711 left = GNUNET_TIME_absolute_get_duration (car->deadline);
714 if (left.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 712 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
715 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 713 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
716 "Client waited %s for permission to transmit to `%s'%s (priority %u)\n", 714 "Client waited %s for permission to transmit to `%s'%s (priority %u)\n",
717 GNUNET_STRINGS_relative_time_to_string (delay, 715 GNUNET_STRINGS_relative_time_to_string (delay,
diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c
index 7a3b53c53..192b5d3d6 100644
--- a/src/core/test_core_api_reliability.c
+++ b/src/core/test_core_api_reliability.c
@@ -62,6 +62,7 @@ struct PeerContext
62{ 62{
63 struct GNUNET_CONFIGURATION_Handle *cfg; 63 struct GNUNET_CONFIGURATION_Handle *cfg;
64 struct GNUNET_CORE_Handle *ch; 64 struct GNUNET_CORE_Handle *ch;
65 struct GNUNET_MQ_Handle *mq;
65 struct GNUNET_PeerIdentity id; 66 struct GNUNET_PeerIdentity id;
66 struct GNUNET_TRANSPORT_OfferHelloHandle *oh; 67 struct GNUNET_TRANSPORT_OfferHelloHandle *oh;
67 struct GNUNET_MessageHeader *hello; 68 struct GNUNET_MessageHeader *hello;
@@ -76,8 +77,6 @@ static struct PeerContext p1;
76 77
77static struct PeerContext p2; 78static struct PeerContext p2;
78 79
79static struct GNUNET_CORE_TransmitHandle *nth;
80
81static int ok; 80static int ok;
82 81
83static int32_t tr_n; 82static int32_t tr_n;
@@ -109,7 +108,7 @@ terminate_peer (struct PeerContext *p)
109{ 108{
110 if (NULL != p->ch) 109 if (NULL != p->ch)
111 { 110 {
112 GNUNET_CORE_disconnect (p->ch); 111 GNUNET_CORE_disconnecT (p->ch);
113 p->ch = NULL; 112 p->ch = NULL;
114 } 113 }
115 if (NULL != p->ghh) 114 if (NULL != p->ghh)
@@ -163,91 +162,58 @@ do_shutdown (void *cls)
163 GNUNET_SCHEDULER_cancel (err_task); 162 GNUNET_SCHEDULER_cancel (err_task);
164 err_task = NULL; 163 err_task = NULL;
165 } 164 }
166 if (NULL != nth)
167 {
168 GNUNET_CORE_notify_transmit_ready_cancel (nth);
169 nth = NULL;
170 }
171 terminate_peer (&p1); 165 terminate_peer (&p1);
172 terminate_peer (&p2); 166 terminate_peer (&p2);
173 167
174} 168}
175 169
176 170
177static size_t 171static void
178transmit_ready (void *cls, 172send_message (struct GNUNET_MQ_Handle *mq,
179 size_t size, 173 int32_t num)
180 void *buf)
181{ 174{
182 char *cbuf = buf; 175 struct GNUNET_MQ_Envelope *env;
183 struct TestMessage hdr; 176 struct TestMessage *hdr;
184 unsigned int s; 177 unsigned int s;
185 unsigned int ret;
186 178
187 nth = NULL; 179 GNUNET_assert (NULL != mq);
188 GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
189 if (NULL == buf)
190 {
191 if (NULL != p1.ch)
192 GNUNET_break (NULL !=
193 (nth = GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO,
194 GNUNET_CORE_PRIO_BEST_EFFORT,
195 FAST_TIMEOUT,
196 &p2.id,
197 get_size (tr_n),
198 &transmit_ready,
199 &p1)));
200 return 0;
201 }
202 GNUNET_assert (tr_n < TOTAL_MSGS); 180 GNUNET_assert (tr_n < TOTAL_MSGS);
203 ret = 0;
204 s = get_size (tr_n); 181 s = get_size (tr_n);
205 GNUNET_assert (size >= s); 182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
206 GNUNET_assert (buf != NULL); 183 "Sending message %u of size %u\n",
207 cbuf = buf; 184 tr_n,
208 do 185 s);
209 { 186 env = GNUNET_MQ_msg_extra (hdr,
210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 187 s - sizeof (struct TestMessage),
211 "Sending message %u of size %u at offset %u\n", 188 MTYPE);
212 tr_n, 189 hdr->num = htonl (tr_n);
213 s, 190 memset (&hdr[1],
214 ret); 191 tr_n,
215 hdr.header.size = htons (s); 192 s - sizeof (struct TestMessage));
216 hdr.header.type = htons (MTYPE); 193 tr_n++;
217 hdr.num = htonl (tr_n);
218 GNUNET_memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
219 ret += sizeof (struct TestMessage);
220 memset (&cbuf[ret], tr_n, s - sizeof (struct TestMessage));
221 ret += s - sizeof (struct TestMessage);
222 tr_n++;
223 s = get_size (tr_n);
224 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
225 break; /* sometimes pack buffer full, sometimes not */
226 }
227 while (size - ret >= s);
228 GNUNET_SCHEDULER_cancel (err_task); 194 GNUNET_SCHEDULER_cancel (err_task);
229 err_task = 195 err_task =
230 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 196 GNUNET_SCHEDULER_add_delayed (TIMEOUT,
231 &terminate_task_error, 197 &terminate_task_error,
232 NULL); 198 NULL);
233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 199 total_bytes += s;
234 "Returning total message block of size %u\n", 200 GNUNET_MQ_send (mq,
235 ret); 201 env);
236 total_bytes += ret;
237 return ret;
238} 202}
239 203
240 204
241static void 205static void *
242connect_notify (void *cls, 206connect_notify (void *cls,
243 const struct GNUNET_PeerIdentity *peer) 207 const struct GNUNET_PeerIdentity *peer,
208 struct GNUNET_MQ_Handle *mq)
244{ 209{
245 struct PeerContext *pc = cls; 210 struct PeerContext *pc = cls;
246 211
247 if (0 == memcmp (&pc->id, 212 if (0 == memcmp (&pc->id,
248 peer, 213 peer,
249 sizeof (struct GNUNET_PeerIdentity))) 214 sizeof (struct GNUNET_PeerIdentity)))
250 return; 215 return (void *) peer;
216 pc->mq = mq;
251 GNUNET_assert (0 == pc->connect_status); 217 GNUNET_assert (0 == pc->connect_status);
252 pc->connect_status = 1; 218 pc->connect_status = 1;
253 if (pc == &p1) 219 if (pc == &p1)
@@ -264,27 +230,25 @@ connect_notify (void *cls,
264 &terminate_task_error, 230 &terminate_task_error,
265 NULL); 231 NULL);
266 start_time = GNUNET_TIME_absolute_get (); 232 start_time = GNUNET_TIME_absolute_get ();
267 GNUNET_break (NULL != 233 send_message (mq,
268 (nth = GNUNET_CORE_notify_transmit_ready (p1.ch, 234 0);
269 GNUNET_NO,
270 GNUNET_CORE_PRIO_BEST_EFFORT,
271 TIMEOUT,
272 &p2.id,
273 get_size (0),
274 &transmit_ready,
275 &p1)));
276 } 235 }
236 return (void *) peer;
277} 237}
278 238
279 239
280static void 240static void
281disconnect_notify (void *cls, 241disconnect_notify (void *cls,
282 const struct GNUNET_PeerIdentity *peer) 242 const struct GNUNET_PeerIdentity *peer,
243 void *internal_cls)
283{ 244{
284 struct PeerContext *pc = cls; 245 struct PeerContext *pc = cls;
285 246
286 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) 247 if (0 == memcmp (&pc->id,
248 peer,
249 sizeof (struct GNUNET_PeerIdentity)))
287 return; 250 return;
251 pc->mq = NULL;
288 pc->connect_status = 0; 252 pc->connect_status = 0;
289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
290 "Encrypted connection to `%s' cut\n", 254 "Encrypted connection to `%s' cut\n",
@@ -292,56 +256,57 @@ disconnect_notify (void *cls,
292} 256}
293 257
294 258
295static size_t 259static int
296transmit_ready (void *cls, 260check_test (void *cls,
297 size_t size, 261 const struct TestMessage *hdr)
298 void *buf); 262{
263 return GNUNET_OK; /* accept all */
264}
299 265
300 266
301static int 267static void
302process_mtype (void *cls, 268handle_test (void *cls,
303 const struct GNUNET_PeerIdentity *peer, 269 const struct TestMessage *hdr)
304 const struct GNUNET_MessageHeader *message)
305{ 270{
306 static int n; 271 static int n;
307 unsigned int s; 272 unsigned int s;
308 const struct TestMessage *hdr;
309 273
310 hdr = (const struct TestMessage *) message;
311 s = get_size (n); 274 s = get_size (n);
312 if (MTYPE != ntohs (message->type)) 275 if (ntohs (hdr->header.size) != s)
313 return GNUNET_SYSERR;
314 if (ntohs (message->size) != s)
315 { 276 {
316 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 277 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
317 "Expected message %u of size %u, got %u bytes of message %u\n", 278 "Expected message %u of size %u, got %u bytes of message %u\n",
318 n, s, 279 n,
319 ntohs (message->size), 280 s,
281 ntohs (hdr->header.size),
320 ntohl (hdr->num)); 282 ntohl (hdr->num));
321 GNUNET_SCHEDULER_cancel (err_task); 283 GNUNET_SCHEDULER_cancel (err_task);
322 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, 284 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error,
323 NULL); 285 NULL);
324 return GNUNET_SYSERR; 286 return;
325 } 287 }
326 if (ntohl (hdr->num) != n) 288 if (ntohl (hdr->num) != n)
327 { 289 {
328 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 290 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
329 "Expected message %u of size %u, got %u bytes of message %u\n", 291 "Expected message %u of size %u, got %u bytes of message %u\n",
330 n, s, 292 n,
331 ntohs (message->size), 293 s,
332 ntohl (hdr->num)); 294 (unsigned int) ntohs (hdr->header.size),
295 (unsigned int) ntohl (hdr->num));
333 GNUNET_SCHEDULER_cancel (err_task); 296 GNUNET_SCHEDULER_cancel (err_task);
334 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, 297 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error,
335 NULL); 298 NULL);
336 return GNUNET_SYSERR; 299 return;
337 } 300 }
338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
339 "Got message %u of size %u\n", 302 "Got message %u of size %u\n",
340 ntohl (hdr->num), 303 (unsigned int) ntohl (hdr->num),
341 ntohs (message->size)); 304 (unsigned int) ntohs (hdr->header.size));
342 n++; 305 n++;
343 if (0 == (n % (TOTAL_MSGS / 100))) 306 if (0 == (n % (TOTAL_MSGS / 100)))
344 FPRINTF (stderr, "%s", "."); 307 FPRINTF (stderr,
308 "%s",
309 ".");
345 if (n == TOTAL_MSGS) 310 if (n == TOTAL_MSGS)
346 { 311 {
347 ok = 0; 312 ok = 0;
@@ -350,30 +315,26 @@ process_mtype (void *cls,
350 else 315 else
351 { 316 {
352 if (n == tr_n) 317 if (n == tr_n)
353 GNUNET_break (NULL != 318 {
354 GNUNET_CORE_notify_transmit_ready (p1.ch, 319 send_message (p1.mq,
355 GNUNET_NO /* no cork */, 320 tr_n);
356 GNUNET_CORE_PRIO_BEST_EFFORT, 321 }
357 FAST_TIMEOUT /* ignored! */,
358 &p2.id,
359 get_size (tr_n),
360 &transmit_ready, &p1));
361 } 322 }
362 return GNUNET_OK;
363} 323}
364 324
365 325
366static struct GNUNET_CORE_MessageHandler handlers[] = {
367 {&process_mtype, MTYPE, 0},
368 {NULL, 0, 0}
369};
370
371
372static void 326static void
373init_notify (void *cls, 327init_notify (void *cls,
374 const struct GNUNET_PeerIdentity *my_identity) 328 const struct GNUNET_PeerIdentity *my_identity)
375{ 329{
330 GNUNET_MQ_hd_var_size (test,
331 MTYPE,
332 struct TestMessage);
376 struct PeerContext *p = cls; 333 struct PeerContext *p = cls;
334 struct GNUNET_MQ_MessageHandler handlers[] = {
335 make_test_handler (NULL),
336 GNUNET_MQ_handler_end ()
337 };
377 338
378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
379 "Connection to CORE service of `%s' established\n", 340 "Connection to CORE service of `%s' established\n",
@@ -385,15 +346,11 @@ init_notify (void *cls,
385 OKPP; 346 OKPP;
386 /* connect p2 */ 347 /* connect p2 */
387 GNUNET_assert (NULL != 348 GNUNET_assert (NULL !=
388 (p2.ch = GNUNET_CORE_connect (p2.cfg, 349 (p2.ch = GNUNET_CORE_connecT (p2.cfg,
389 &p2, 350 &p2,
390 &init_notify, 351 &init_notify,
391 &connect_notify, 352 &connect_notify,
392 &disconnect_notify, 353 &disconnect_notify,
393 NULL,
394 GNUNET_YES,
395 NULL,
396 GNUNET_YES,
397 handlers))); 354 handlers)));
398 } 355 }
399 else 356 else
@@ -490,6 +447,14 @@ run (void *cls,
490 const char *cfgfile, 447 const char *cfgfile,
491 const struct GNUNET_CONFIGURATION_Handle *cfg) 448 const struct GNUNET_CONFIGURATION_Handle *cfg)
492{ 449{
450 GNUNET_MQ_hd_fixed_size (test,
451 MTYPE,
452 struct TestMessage);
453 struct GNUNET_MQ_MessageHandler handlers[] = {
454 make_test_handler (NULL),
455 GNUNET_MQ_handler_end ()
456 };
457
493 GNUNET_assert (ok == 1); 458 GNUNET_assert (ok == 1);
494 OKPP; 459 OKPP;
495 setup_peer (&p1, 460 setup_peer (&p1,
@@ -504,15 +469,11 @@ run (void *cls,
504 NULL); 469 NULL);
505 470
506 GNUNET_assert (NULL != 471 GNUNET_assert (NULL !=
507 (p1.ch = GNUNET_CORE_connect (p1.cfg, 472 (p1.ch = GNUNET_CORE_connecT (p1.cfg,
508 &p1, 473 &p1,
509 &init_notify, 474 &init_notify,
510 &connect_notify, 475 &connect_notify,
511 &disconnect_notify, 476 &disconnect_notify,
512 NULL,
513 GNUNET_YES,
514 NULL,
515 GNUNET_YES,
516 handlers))); 477 handlers)));
517} 478}
518 479