aboutsummaryrefslogtreecommitdiff
path: root/src/core/test_core_api_reliability.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-19 21:29:20 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-19 21:29:20 +0000
commit8b1a351c049deec3226aa40a883b97c76916bea7 (patch)
treed507edb09031a9c9025ad5eb927fc1a9c36452d7 /src/core/test_core_api_reliability.c
parent80c4558f3742ce78f1f511ea13d8941c46b0e88b (diff)
downloadgnunet-8b1a351c049deec3226aa40a883b97c76916bea7.tar.gz
gnunet-8b1a351c049deec3226aa40a883b97c76916bea7.zip
refactoring core API to use new MQ lib
Diffstat (limited to 'src/core/test_core_api_reliability.c')
-rw-r--r--src/core/test_core_api_reliability.c81
1 files changed, 57 insertions, 24 deletions
diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c
index 49affdff3..c7672afdb 100644
--- a/src/core/test_core_api_reliability.c
+++ b/src/core/test_core_api_reliability.c
@@ -138,7 +138,9 @@ terminate_task (void *cls)
138 FPRINTF (stderr, 138 FPRINTF (stderr,
139 "\nThroughput was %llu kb/s\n", 139 "\nThroughput was %llu kb/s\n",
140 total_bytes * 1000000LL / 1024 / delta); 140 total_bytes * 1000000LL / 1024 / delta);
141 GAUGER ("CORE", "Core throughput/s", total_bytes * 1000000LL / 1024 / delta, 141 GAUGER ("CORE",
142 "Core throughput/s",
143 total_bytes * 1000000LL / 1024 / delta,
142 "kb/s"); 144 "kb/s");
143 ok = 0; 145 ok = 0;
144} 146}
@@ -155,7 +157,9 @@ terminate_task_error (void *cls)
155 157
156 158
157static size_t 159static size_t
158transmit_ready (void *cls, size_t size, void *buf) 160transmit_ready (void *cls,
161 size_t size,
162 void *buf)
159{ 163{
160 char *cbuf = buf; 164 char *cbuf = buf;
161 struct TestMessage hdr; 165 struct TestMessage hdr;
@@ -183,7 +187,10 @@ transmit_ready (void *cls, size_t size, void *buf)
183 do 187 do
184 { 188 {
185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
186 "Sending message %u of size %u at offset %u\n", tr_n, s, ret); 190 "Sending message %u of size %u at offset %u\n",
191 tr_n,
192 s,
193 ret);
187 hdr.header.size = htons (s); 194 hdr.header.size = htons (s);
188 hdr.header.type = htons (MTYPE); 195 hdr.header.type = htons (MTYPE);
189 hdr.num = htonl (tr_n); 196 hdr.num = htonl (tr_n);
@@ -202,14 +209,16 @@ transmit_ready (void *cls, size_t size, void *buf)
202 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 209 GNUNET_SCHEDULER_add_delayed (TIMEOUT,
203 &terminate_task_error, NULL); 210 &terminate_task_error, NULL);
204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
205 "Returning total message block of size %u\n", ret); 212 "Returning total message block of size %u\n",
213 ret);
206 total_bytes += ret; 214 total_bytes += ret;
207 return ret; 215 return ret;
208} 216}
209 217
210 218
211static void 219static void
212connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) 220connect_notify (void *cls,
221 const struct GNUNET_PeerIdentity *peer)
213{ 222{
214 struct PeerContext *pc = cls; 223 struct PeerContext *pc = cls;
215 224
@@ -240,30 +249,35 @@ connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
240 249
241 250
242static void 251static void
243disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) 252disconnect_notify (void *cls,
253 const struct GNUNET_PeerIdentity *peer)
244{ 254{
245 struct PeerContext *pc = cls; 255 struct PeerContext *pc = cls;
246 256
247 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) 257 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
248 return; 258 return;
249 pc->connect_status = 0; 259 pc->connect_status = 0;
250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted connection to `%s' cut\n", 260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
261 "Encrypted connection to `%s' cut\n",
251 GNUNET_i2s (peer)); 262 GNUNET_i2s (peer));
252} 263}
253 264
254 265
255static int 266static int
256inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 267inbound_notify (void *cls,
268 const struct GNUNET_PeerIdentity *other,
257 const struct GNUNET_MessageHeader *message) 269 const struct GNUNET_MessageHeader *message)
258{ 270{
259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
260 "Core provides inbound data from `%s'.\n", GNUNET_i2s (other)); 272 "Core provides inbound data from `%s'.\n",
273 GNUNET_i2s (other));
261 return GNUNET_OK; 274 return GNUNET_OK;
262} 275}
263 276
264 277
265static int 278static int
266outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 279outbound_notify (void *cls,
280 const struct GNUNET_PeerIdentity *other,
267 const struct GNUNET_MessageHeader *message) 281 const struct GNUNET_MessageHeader *message)
268{ 282{
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -274,7 +288,9 @@ outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
274 288
275 289
276static size_t 290static size_t
277transmit_ready (void *cls, size_t size, void *buf); 291transmit_ready (void *cls,
292 size_t size,
293 void *buf);
278 294
279 295
280static int 296static int
@@ -294,22 +310,29 @@ process_mtype (void *cls,
294 { 310 {
295 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 311 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
296 "Expected message %u of size %u, got %u bytes of message %u\n", 312 "Expected message %u of size %u, got %u bytes of message %u\n",
297 n, s, ntohs (message->size), ntohl (hdr->num)); 313 n, s,
314 ntohs (message->size),
315 ntohl (hdr->num));
298 GNUNET_SCHEDULER_cancel (err_task); 316 GNUNET_SCHEDULER_cancel (err_task);
299 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL); 317 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error,
318 NULL);
300 return GNUNET_SYSERR; 319 return GNUNET_SYSERR;
301 } 320 }
302 if (ntohl (hdr->num) != n) 321 if (ntohl (hdr->num) != n)
303 { 322 {
304 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 323 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
305 "Expected message %u of size %u, got %u bytes of message %u\n", 324 "Expected message %u of size %u, got %u bytes of message %u\n",
306 n, s, ntohs (message->size), ntohl (hdr->num)); 325 n, s,
326 ntohs (message->size),
327 ntohl (hdr->num));
307 GNUNET_SCHEDULER_cancel (err_task); 328 GNUNET_SCHEDULER_cancel (err_task);
308 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL); 329 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL);
309 return GNUNET_SYSERR; 330 return GNUNET_SYSERR;
310 } 331 }
311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n", 332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
312 ntohl (hdr->num), ntohs (message->size)); 333 "Got message %u of size %u\n",
334 ntohl (hdr->num),
335 ntohs (message->size));
313 n++; 336 n++;
314 if (0 == (n % (TOTAL_MSGS / 100))) 337 if (0 == (n % (TOTAL_MSGS / 100)))
315 FPRINTF (stderr, "%s", "."); 338 FPRINTF (stderr, "%s", ".");
@@ -379,7 +402,8 @@ init_notify (void *cls,
379 402
380 403
381static void 404static void
382process_hello (void *cls, const struct GNUNET_MessageHeader *message) 405process_hello (void *cls,
406 const struct GNUNET_MessageHeader *message)
383{ 407{
384 struct PeerContext *p = cls; 408 struct PeerContext *p = cls;
385 409
@@ -400,7 +424,8 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message)
400 424
401 425
402static void 426static void
403setup_peer (struct PeerContext *p, const char *cfgname) 427setup_peer (struct PeerContext *p,
428 const char *cfgname)
404{ 429{
405 char *binary; 430 char *binary;
406 431
@@ -423,7 +448,9 @@ setup_peer (struct PeerContext *p, const char *cfgname)
423 448
424 449
425static void 450static void
426run (void *cls, char *const *args, const char *cfgfile, 451run (void *cls,
452 char *const *args,
453 const char *cfgfile,
427 const struct GNUNET_CONFIGURATION_Handle *cfg) 454 const struct GNUNET_CONFIGURATION_Handle *cfg)
428{ 455{
429 GNUNET_assert (ok == 1); 456 GNUNET_assert (ok == 1);
@@ -431,7 +458,9 @@ run (void *cls, char *const *args, const char *cfgfile,
431 setup_peer (&p1, "test_core_api_peer1.conf"); 458 setup_peer (&p1, "test_core_api_peer1.conf");
432 setup_peer (&p2, "test_core_api_peer2.conf"); 459 setup_peer (&p2, "test_core_api_peer2.conf");
433 err_task = 460 err_task =
434 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL); 461 GNUNET_SCHEDULER_add_delayed (TIMEOUT,
462 &terminate_task_error,
463 NULL);
435 464
436 GNUNET_assert (NULL != (p1.ch = GNUNET_CORE_connect (p1.cfg, &p1, 465 GNUNET_assert (NULL != (p1.ch = GNUNET_CORE_connect (p1.cfg, &p1,
437 &init_notify, 466 &init_notify,
@@ -447,10 +476,13 @@ static void
447stop_arm (struct PeerContext *p) 476stop_arm (struct PeerContext *p)
448{ 477{
449 if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) 478 if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG))
450 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 479 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
480 "kill");
451 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) 481 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
452 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 482 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", 483 "waitpid");
484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
485 "ARM process %u stopped\n",
454 GNUNET_OS_process_get_pid (p->arm_proc)); 486 GNUNET_OS_process_get_pid (p->arm_proc));
455 GNUNET_OS_process_destroy (p->arm_proc); 487 GNUNET_OS_process_destroy (p->arm_proc);
456 p->arm_proc = NULL; 488 p->arm_proc = NULL;
@@ -461,7 +493,8 @@ stop_arm (struct PeerContext *p)
461int 493int
462main (int argc, char *argv1[]) 494main (int argc, char *argv1[])
463{ 495{
464 char *const argv[] = { "test-core-api-reliability", 496 char *const argv[] = {
497 "test-core-api-reliability",
465 "-c", 498 "-c",
466 "test_core_api_data.conf", 499 "test_core_api_data.conf",
467 NULL 500 NULL