diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-06-04 11:57:59 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-06-04 11:57:59 +0200 |
commit | 58002acac13b2eef407a20ee3ddc5f458cd5e483 (patch) | |
tree | 8285fc1b32a8c9ac55f970667e7d29b791b6758e /src | |
parent | 9ce956ea4c93f038995a21c6c1c0133eee6bff75 (diff) | |
download | gnunet-58002acac13b2eef407a20ee3ddc5f458cd5e483.tar.gz gnunet-58002acac13b2eef407a20ee3ddc5f458cd5e483.zip |
nicer loop structure
Diffstat (limited to 'src')
-rw-r--r-- | src/namestore/gnunet-zoneimport.c | 844 | ||||
-rw-r--r-- | src/peerstore/gnunet-service-peerstore.c | 264 | ||||
-rw-r--r-- | src/peerstore/peerstore_api.c | 247 | ||||
-rw-r--r-- | src/regex/regex_internal.c | 717 | ||||
-rw-r--r-- | src/statistics/gnunet-statistics.c | 387 |
5 files changed, 1073 insertions, 1386 deletions
diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c index f36106332..4c5205ab3 100644 --- a/src/namestore/gnunet-zoneimport.c +++ b/src/namestore/gnunet-zoneimport.c | |||
@@ -56,7 +56,8 @@ | |||
56 | /** | 56 | /** |
57 | * How long do we wait at least between series of requests? | 57 | * How long do we wait at least between series of requests? |
58 | */ | 58 | */ |
59 | #define SERIES_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10) | 59 | #define SERIES_DELAY \ |
60 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10) | ||
60 | 61 | ||
61 | /** | 62 | /** |
62 | * How long do DNS records have to last at least after being imported? | 63 | * How long do DNS records have to last at least after being imported? |
@@ -97,7 +98,6 @@ struct Zone | |||
97 | * Private key of the zone. | 98 | * Private key of the zone. |
98 | */ | 99 | */ |
99 | struct GNUNET_CRYPTO_EcdsaPrivateKey key; | 100 | struct GNUNET_CRYPTO_EcdsaPrivateKey key; |
100 | |||
101 | }; | 101 | }; |
102 | 102 | ||
103 | 103 | ||
@@ -120,7 +120,6 @@ struct Record | |||
120 | * GNS record. | 120 | * GNS record. |
121 | */ | 121 | */ |
122 | struct GNUNET_GNSRECORD_Data grd; | 122 | struct GNUNET_GNSRECORD_Data grd; |
123 | |||
124 | }; | 123 | }; |
125 | 124 | ||
126 | 125 | ||
@@ -367,9 +366,8 @@ static struct GNUNET_TIME_Relative idle_time; | |||
367 | * @param cls closure | 366 | * @param cls closure |
368 | * @param rec a DNS record | 367 | * @param rec a DNS record |
369 | */ | 368 | */ |
370 | typedef void | 369 | typedef void (*RecordProcessor) (void *cls, |
371 | (*RecordProcessor) (void *cls, | 370 | const struct GNUNET_DNSPARSER_Record *rec); |
372 | const struct GNUNET_DNSPARSER_Record *rec); | ||
373 | 371 | ||
374 | 372 | ||
375 | /** | 373 | /** |
@@ -382,29 +380,26 @@ typedef void | |||
382 | */ | 380 | */ |
383 | static void | 381 | static void |
384 | for_all_records (const struct GNUNET_DNSPARSER_Packet *p, | 382 | for_all_records (const struct GNUNET_DNSPARSER_Packet *p, |
385 | RecordProcessor rp, | 383 | RecordProcessor rp, |
386 | void *rp_cls) | 384 | void *rp_cls) |
387 | { | 385 | { |
388 | for (unsigned int i=0;i<p->num_answers;i++) | 386 | for (unsigned int i = 0; i < p->num_answers; i++) |
389 | { | 387 | { |
390 | struct GNUNET_DNSPARSER_Record *rs = &p->answers[i]; | 388 | struct GNUNET_DNSPARSER_Record *rs = &p->answers[i]; |
391 | 389 | ||
392 | rp (rp_cls, | 390 | rp (rp_cls, rs); |
393 | rs); | ||
394 | } | 391 | } |
395 | for (unsigned int i=0;i<p->num_authority_records;i++) | 392 | for (unsigned int i = 0; i < p->num_authority_records; i++) |
396 | { | 393 | { |
397 | struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i]; | 394 | struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i]; |
398 | 395 | ||
399 | rp (rp_cls, | 396 | rp (rp_cls, rs); |
400 | rs); | ||
401 | } | 397 | } |
402 | for (unsigned int i=0;i<p->num_additional_records;i++) | 398 | for (unsigned int i = 0; i < p->num_additional_records; i++) |
403 | { | 399 | { |
404 | struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i]; | 400 | struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i]; |
405 | 401 | ||
406 | rp (rp_cls, | 402 | rp (rp_cls, rs); |
407 | rs); | ||
408 | } | 403 | } |
409 | } | 404 | } |
410 | 405 | ||
@@ -422,8 +417,7 @@ get_label (struct Request *req) | |||
422 | static char label[64]; | 417 | static char label[64]; |
423 | const char *dot; | 418 | const char *dot; |
424 | 419 | ||
425 | dot = strchr (req->hostname, | 420 | dot = strchr (req->hostname, (unsigned char) '.'); |
426 | (unsigned char) '.'); | ||
427 | if (NULL == dot) | 421 | if (NULL == dot) |
428 | { | 422 | { |
429 | GNUNET_break (0); | 423 | GNUNET_break (0); |
@@ -434,9 +428,7 @@ get_label (struct Request *req) | |||
434 | GNUNET_break (0); | 428 | GNUNET_break (0); |
435 | return NULL; | 429 | return NULL; |
436 | } | 430 | } |
437 | GNUNET_memcpy (label, | 431 | GNUNET_memcpy (label, req->hostname, dot - req->hostname); |
438 | req->hostname, | ||
439 | dot - req->hostname); | ||
440 | label[dot - req->hostname] = '\0'; | 432 | label[dot - req->hostname] = '\0'; |
441 | return label; | 433 | return label; |
442 | } | 434 | } |
@@ -451,8 +443,7 @@ get_label (struct Request *req) | |||
451 | * allocated query buffer | 443 | * allocated query buffer |
452 | */ | 444 | */ |
453 | static void * | 445 | static void * |
454 | build_dns_query (struct Request *req, | 446 | build_dns_query (struct Request *req, size_t *raw_size) |
455 | size_t *raw_size) | ||
456 | { | 447 | { |
457 | static char raw[512]; | 448 | static char raw[512]; |
458 | char *rawp; | 449 | char *rawp; |
@@ -464,16 +455,11 @@ build_dns_query (struct Request *req, | |||
464 | q.type = GNUNET_DNSPARSER_TYPE_NS; | 455 | q.type = GNUNET_DNSPARSER_TYPE_NS; |
465 | q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; | 456 | q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; |
466 | 457 | ||
467 | memset (&p, | 458 | memset (&p, 0, sizeof (p)); |
468 | 0, | ||
469 | sizeof (p)); | ||
470 | p.num_queries = 1; | 459 | p.num_queries = 1; |
471 | p.queries = &q; | 460 | p.queries = &q; |
472 | p.id = req->id; | 461 | p.id = req->id; |
473 | ret = GNUNET_DNSPARSER_pack (&p, | 462 | ret = GNUNET_DNSPARSER_pack (&p, UINT16_MAX, &rawp, raw_size); |
474 | UINT16_MAX, | ||
475 | &rawp, | ||
476 | raw_size); | ||
477 | if (GNUNET_OK != ret) | 463 | if (GNUNET_OK != ret) |
478 | { | 464 | { |
479 | if (GNUNET_NO == ret) | 465 | if (GNUNET_NO == ret) |
@@ -494,15 +480,12 @@ build_dns_query (struct Request *req, | |||
494 | GNUNET_free (rawp); | 480 | GNUNET_free (rawp); |
495 | return NULL; | 481 | return NULL; |
496 | } | 482 | } |
497 | GNUNET_memcpy (raw, | 483 | GNUNET_memcpy (raw, rawp, *raw_size); |
498 | rawp, | ||
499 | *raw_size); | ||
500 | GNUNET_free (rawp); | 484 | GNUNET_free (rawp); |
501 | return raw; | 485 | return raw; |
502 | } | 486 | } |
503 | 487 | ||
504 | 488 | ||
505 | |||
506 | /** | 489 | /** |
507 | * Free records associated with @a req. | 490 | * Free records associated with @a req. |
508 | * | 491 | * |
@@ -516,9 +499,7 @@ free_records (struct Request *req) | |||
516 | /* Free records */ | 499 | /* Free records */ |
517 | while (NULL != (rec = req->rec_head)) | 500 | while (NULL != (rec = req->rec_head)) |
518 | { | 501 | { |
519 | GNUNET_CONTAINER_DLL_remove (req->rec_head, | 502 | GNUNET_CONTAINER_DLL_remove (req->rec_head, req->rec_tail, rec); |
520 | req->rec_tail, | ||
521 | rec); | ||
522 | GNUNET_free (rec); | 503 | GNUNET_free (rec); |
523 | } | 504 | } |
524 | } | 505 | } |
@@ -554,17 +535,14 @@ process_queue (void *cls); | |||
554 | static void | 535 | static void |
555 | insert_sorted (struct Request *req) | 536 | insert_sorted (struct Request *req) |
556 | { | 537 | { |
557 | req->hn = GNUNET_CONTAINER_heap_insert (req_heap, | 538 | req->hn = |
558 | req, | 539 | GNUNET_CONTAINER_heap_insert (req_heap, req, req->expires.abs_value_us); |
559 | req->expires.abs_value_us); | ||
560 | if (req == GNUNET_CONTAINER_heap_peek (req_heap)) | 540 | if (req == GNUNET_CONTAINER_heap_peek (req_heap)) |
561 | { | 541 | { |
562 | if (NULL != t) | 542 | if (NULL != t) |
563 | GNUNET_SCHEDULER_cancel (t); | 543 | GNUNET_SCHEDULER_cancel (t); |
564 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); | 544 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); |
565 | t = GNUNET_SCHEDULER_add_at (req->expires, | 545 | t = GNUNET_SCHEDULER_add_at (req->expires, &process_queue, NULL); |
566 | &process_queue, | ||
567 | NULL); | ||
568 | } | 546 | } |
569 | } | 547 | } |
570 | 548 | ||
@@ -580,10 +558,10 @@ insert_sorted (struct Request *req) | |||
580 | */ | 558 | */ |
581 | static void | 559 | static void |
582 | add_record (struct Request *req, | 560 | add_record (struct Request *req, |
583 | uint32_t type, | 561 | uint32_t type, |
584 | struct GNUNET_TIME_Absolute expiration_time, | 562 | struct GNUNET_TIME_Absolute expiration_time, |
585 | const void *data, | 563 | const void *data, |
586 | size_t data_len) | 564 | size_t data_len) |
587 | { | 565 | { |
588 | struct Record *rec; | 566 | struct Record *rec; |
589 | 567 | ||
@@ -593,12 +571,8 @@ add_record (struct Request *req, | |||
593 | rec->grd.data_size = data_len; | 571 | rec->grd.data_size = data_len; |
594 | rec->grd.record_type = type; | 572 | rec->grd.record_type = type; |
595 | rec->grd.flags = GNUNET_GNSRECORD_RF_NONE; | 573 | rec->grd.flags = GNUNET_GNSRECORD_RF_NONE; |
596 | GNUNET_memcpy (&rec[1], | 574 | GNUNET_memcpy (&rec[1], data, data_len); |
597 | data, | 575 | GNUNET_CONTAINER_DLL_insert (req->rec_head, req->rec_tail, rec); |
598 | data_len); | ||
599 | GNUNET_CONTAINER_DLL_insert (req->rec_head, | ||
600 | req->rec_tail, | ||
601 | rec); | ||
602 | } | 576 | } |
603 | 577 | ||
604 | 578 | ||
@@ -631,20 +605,18 @@ struct GlueClosure | |||
631 | * @param rec record that may contain glue information | 605 | * @param rec record that may contain glue information |
632 | */ | 606 | */ |
633 | static void | 607 | static void |
634 | check_for_glue (void *cls, | 608 | check_for_glue (void *cls, const struct GNUNET_DNSPARSER_Record *rec) |
635 | const struct GNUNET_DNSPARSER_Record *rec) | ||
636 | { | 609 | { |
637 | struct GlueClosure *gc = cls; | 610 | struct GlueClosure *gc = cls; |
638 | char dst[65536]; | 611 | char dst[65536]; |
639 | size_t dst_len; | 612 | size_t dst_len; |
640 | size_t off; | 613 | size_t off; |
641 | char ip[INET6_ADDRSTRLEN+1]; | 614 | char ip[INET6_ADDRSTRLEN + 1]; |
642 | socklen_t ip_size = (socklen_t) sizeof (ip); | 615 | socklen_t ip_size = (socklen_t) sizeof (ip); |
643 | struct GNUNET_TIME_Absolute expiration_time; | 616 | struct GNUNET_TIME_Absolute expiration_time; |
644 | struct GNUNET_TIME_Relative left; | 617 | struct GNUNET_TIME_Relative left; |
645 | 618 | ||
646 | if (0 != strcasecmp (rec->name, | 619 | if (0 != strcasecmp (rec->name, gc->ns)) |
647 | gc->ns)) | ||
648 | return; | 620 | return; |
649 | expiration_time = rec->expiration_time; | 621 | expiration_time = rec->expiration_time; |
650 | left = GNUNET_TIME_absolute_get_remaining (expiration_time); | 622 | left = GNUNET_TIME_absolute_get_remaining (expiration_time); |
@@ -652,7 +624,8 @@ check_for_glue (void *cls, | |||
652 | return; /* ignore expired glue records */ | 624 | return; /* ignore expired glue records */ |
653 | /* if expiration window is too short, bump it to configured minimum */ | 625 | /* if expiration window is too short, bump it to configured minimum */ |
654 | if (left.rel_value_us < minimum_expiration_time.rel_value_us) | 626 | if (left.rel_value_us < minimum_expiration_time.rel_value_us) |
655 | expiration_time = GNUNET_TIME_relative_to_absolute (minimum_expiration_time); | 627 | expiration_time = |
628 | GNUNET_TIME_relative_to_absolute (minimum_expiration_time); | ||
656 | dst_len = sizeof (dst); | 629 | dst_len = sizeof (dst); |
657 | off = 0; | 630 | off = 0; |
658 | switch (rec->type) | 631 | switch (rec->type) |
@@ -663,31 +636,23 @@ check_for_glue (void *cls, | |||
663 | GNUNET_break (0); | 636 | GNUNET_break (0); |
664 | return; | 637 | return; |
665 | } | 638 | } |
666 | if (NULL == | 639 | if (NULL == inet_ntop (AF_INET, rec->data.raw.data, ip, ip_size)) |
667 | inet_ntop (AF_INET, | ||
668 | rec->data.raw.data, | ||
669 | ip, | ||
670 | ip_size)) | ||
671 | { | 640 | { |
672 | GNUNET_break (0); | 641 | GNUNET_break (0); |
673 | return; | 642 | return; |
674 | } | 643 | } |
675 | if ( (GNUNET_OK == | 644 | if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, |
676 | GNUNET_DNSPARSER_builder_add_name (dst, | 645 | dst_len, |
677 | dst_len, | 646 | &off, |
678 | &off, | 647 | gc->req->hostname)) && |
679 | gc->req->hostname)) && | 648 | (GNUNET_OK == |
680 | (GNUNET_OK == | 649 | GNUNET_DNSPARSER_builder_add_name (dst, dst_len, &off, ip))) |
681 | GNUNET_DNSPARSER_builder_add_name (dst, | ||
682 | dst_len, | ||
683 | &off, | ||
684 | ip)) ) | ||
685 | { | 650 | { |
686 | add_record (gc->req, | 651 | add_record (gc->req, |
687 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | 652 | GNUNET_GNSRECORD_TYPE_GNS2DNS, |
688 | expiration_time, | 653 | expiration_time, |
689 | dst, | 654 | dst, |
690 | off); | 655 | off); |
691 | gc->found = GNUNET_YES; | 656 | gc->found = GNUNET_YES; |
692 | } | 657 | } |
693 | break; | 658 | break; |
@@ -697,51 +662,41 @@ check_for_glue (void *cls, | |||
697 | GNUNET_break (0); | 662 | GNUNET_break (0); |
698 | return; | 663 | return; |
699 | } | 664 | } |
700 | if (NULL == | 665 | if (NULL == inet_ntop (AF_INET6, rec->data.raw.data, ip, ip_size)) |
701 | inet_ntop (AF_INET6, | ||
702 | rec->data.raw.data, | ||
703 | ip, | ||
704 | ip_size)) | ||
705 | { | 666 | { |
706 | GNUNET_break (0); | 667 | GNUNET_break (0); |
707 | return; | 668 | return; |
708 | } | 669 | } |
709 | if ( (GNUNET_OK == | 670 | if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, |
710 | GNUNET_DNSPARSER_builder_add_name (dst, | 671 | dst_len, |
711 | dst_len, | 672 | &off, |
712 | &off, | 673 | gc->req->hostname)) && |
713 | gc->req->hostname)) && | 674 | (GNUNET_OK == |
714 | (GNUNET_OK == | 675 | GNUNET_DNSPARSER_builder_add_name (dst, dst_len, &off, ip))) |
715 | GNUNET_DNSPARSER_builder_add_name (dst, | ||
716 | dst_len, | ||
717 | &off, | ||
718 | ip)) ) | ||
719 | { | 676 | { |
720 | add_record (gc->req, | 677 | add_record (gc->req, |
721 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | 678 | GNUNET_GNSRECORD_TYPE_GNS2DNS, |
722 | expiration_time, | 679 | expiration_time, |
723 | dst, | 680 | dst, |
724 | off); | 681 | off); |
725 | gc->found = GNUNET_YES; | 682 | gc->found = GNUNET_YES; |
726 | } | 683 | } |
727 | break; | 684 | break; |
728 | case GNUNET_DNSPARSER_TYPE_CNAME: | 685 | case GNUNET_DNSPARSER_TYPE_CNAME: |
729 | if ( (GNUNET_OK == | 686 | if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, |
730 | GNUNET_DNSPARSER_builder_add_name (dst, | 687 | dst_len, |
731 | dst_len, | 688 | &off, |
732 | &off, | 689 | gc->req->hostname)) && |
733 | gc->req->hostname)) && | 690 | (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, |
734 | (GNUNET_OK == | 691 | dst_len, |
735 | GNUNET_DNSPARSER_builder_add_name (dst, | 692 | &off, |
736 | dst_len, | 693 | rec->data.hostname))) |
737 | &off, | ||
738 | rec->data.hostname)) ) | ||
739 | { | 694 | { |
740 | add_record (gc->req, | 695 | add_record (gc->req, |
741 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | 696 | GNUNET_GNSRECORD_TYPE_GNS2DNS, |
742 | expiration_time, | 697 | expiration_time, |
743 | dst, | 698 | dst, |
744 | off); | 699 | off); |
745 | gc->found = GNUNET_YES; | 700 | gc->found = GNUNET_YES; |
746 | } | 701 | } |
747 | break; | 702 | break; |
@@ -777,8 +732,7 @@ struct ProcessRecordContext | |||
777 | * @param rec response | 732 | * @param rec response |
778 | */ | 733 | */ |
779 | static void | 734 | static void |
780 | process_record (void *cls, | 735 | process_record (void *cls, const struct GNUNET_DNSPARSER_Record *rec) |
781 | const struct GNUNET_DNSPARSER_Record *rec) | ||
782 | { | 736 | { |
783 | struct ProcessRecordContext *prc = cls; | 737 | struct ProcessRecordContext *prc = cls; |
784 | struct Request *req = prc->req; | 738 | struct Request *req = prc->req; |
@@ -791,14 +745,14 @@ process_record (void *cls, | |||
791 | dst_len = sizeof (dst); | 745 | dst_len = sizeof (dst); |
792 | off = 0; | 746 | off = 0; |
793 | records++; | 747 | records++; |
794 | if (0 != strcasecmp (rec->name, | 748 | if (0 != strcasecmp (rec->name, req->hostname)) |
795 | req->hostname)) | ||
796 | { | 749 | { |
797 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 750 | GNUNET_log ( |
798 | "DNS returned record from zone `%s' of type %u while resolving `%s'\n", | 751 | GNUNET_ERROR_TYPE_DEBUG, |
799 | rec->name, | 752 | "DNS returned record from zone `%s' of type %u while resolving `%s'\n", |
800 | (unsigned int) rec->type, | 753 | rec->name, |
801 | req->hostname); | 754 | (unsigned int) rec->type, |
755 | req->hostname); | ||
802 | return; /* does not match hostname, might be glue, but | 756 | return; /* does not match hostname, might be glue, but |
803 | not useful for this pass! */ | 757 | not useful for this pass! */ |
804 | } | 758 | } |
@@ -807,8 +761,8 @@ process_record (void *cls, | |||
807 | if (0 == left.rel_value_us) | 761 | if (0 == left.rel_value_us) |
808 | { | 762 | { |
809 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 763 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
810 | "DNS returned expired record for `%s'\n", | 764 | "DNS returned expired record for `%s'\n", |
811 | req->hostname); | 765 | req->hostname); |
812 | GNUNET_STATISTICS_update (stats, | 766 | GNUNET_STATISTICS_update (stats, |
813 | "# expired records obtained from DNS", | 767 | "# expired records obtained from DNS", |
814 | 1, | 768 | 1, |
@@ -822,68 +776,59 @@ process_record (void *cls, | |||
822 | req->hostname); | 776 | req->hostname); |
823 | /* if expiration window is too short, bump it to configured minimum */ | 777 | /* if expiration window is too short, bump it to configured minimum */ |
824 | if (left.rel_value_us < minimum_expiration_time.rel_value_us) | 778 | if (left.rel_value_us < minimum_expiration_time.rel_value_us) |
825 | expiration_time = GNUNET_TIME_relative_to_absolute (minimum_expiration_time); | 779 | expiration_time = |
780 | GNUNET_TIME_relative_to_absolute (minimum_expiration_time); | ||
826 | switch (rec->type) | 781 | switch (rec->type) |
827 | { | 782 | { |
828 | case GNUNET_DNSPARSER_TYPE_NS: | 783 | case GNUNET_DNSPARSER_TYPE_NS: { |
784 | struct GlueClosure gc; | ||
785 | |||
786 | /* check for glue */ | ||
787 | gc.req = req; | ||
788 | gc.ns = rec->data.hostname; | ||
789 | gc.found = GNUNET_NO; | ||
790 | for_all_records (prc->p, &check_for_glue, &gc); | ||
791 | if ((GNUNET_NO == gc.found) && | ||
792 | (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, | ||
793 | dst_len, | ||
794 | &off, | ||
795 | req->hostname)) && | ||
796 | (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, | ||
797 | dst_len, | ||
798 | &off, | ||
799 | rec->data.hostname))) | ||
829 | { | 800 | { |
830 | struct GlueClosure gc; | 801 | /* FIXME: actually check if this is out-of-bailiwick, |
831 | |||
832 | /* check for glue */ | ||
833 | gc.req = req; | ||
834 | gc.ns = rec->data.hostname; | ||
835 | gc.found = GNUNET_NO; | ||
836 | for_all_records (prc->p, | ||
837 | &check_for_glue, | ||
838 | &gc); | ||
839 | if ( (GNUNET_NO == gc.found) && | ||
840 | (GNUNET_OK == | ||
841 | GNUNET_DNSPARSER_builder_add_name (dst, | ||
842 | dst_len, | ||
843 | &off, | ||
844 | req->hostname)) && | ||
845 | (GNUNET_OK == | ||
846 | GNUNET_DNSPARSER_builder_add_name (dst, | ||
847 | dst_len, | ||
848 | &off, | ||
849 | rec->data.hostname)) ) | ||
850 | { | ||
851 | /* FIXME: actually check if this is out-of-bailiwick, | ||
852 | and if not request explicit resolution... */ | 802 | and if not request explicit resolution... */ |
853 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 803 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
854 | "Converted OOB (`%s') NS record for `%s'\n", | 804 | "Converted OOB (`%s') NS record for `%s'\n", |
855 | rec->data.hostname, | 805 | rec->data.hostname, |
856 | rec->name); | 806 | rec->name); |
857 | add_record (req, | 807 | add_record (req, |
858 | GNUNET_GNSRECORD_TYPE_GNS2DNS, | 808 | GNUNET_GNSRECORD_TYPE_GNS2DNS, |
859 | expiration_time, | 809 | expiration_time, |
860 | dst, | 810 | dst, |
861 | off); | 811 | off); |
862 | } | 812 | } |
863 | else | 813 | else |
864 | { | 814 | { |
865 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 815 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
866 | "Converted NS record for `%s' using glue\n", | 816 | "Converted NS record for `%s' using glue\n", |
867 | rec->name); | 817 | rec->name); |
868 | } | ||
869 | break; | ||
870 | } | 818 | } |
819 | break; | ||
820 | } | ||
871 | case GNUNET_DNSPARSER_TYPE_CNAME: | 821 | case GNUNET_DNSPARSER_TYPE_CNAME: |
872 | if (GNUNET_OK == | 822 | if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, |
873 | GNUNET_DNSPARSER_builder_add_name (dst, | 823 | dst_len, |
874 | dst_len, | 824 | &off, |
875 | &off, | 825 | rec->data.hostname)) |
876 | rec->data.hostname)) | ||
877 | { | 826 | { |
878 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 827 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
879 | "Converting CNAME (`%s') record for `%s'\n", | 828 | "Converting CNAME (`%s') record for `%s'\n", |
880 | rec->data.hostname, | 829 | rec->data.hostname, |
881 | rec->name); | 830 | rec->name); |
882 | add_record (req, | 831 | add_record (req, rec->type, expiration_time, dst, off); |
883 | rec->type, | ||
884 | expiration_time, | ||
885 | dst, | ||
886 | off); | ||
887 | } | 832 | } |
888 | break; | 833 | break; |
889 | case GNUNET_DNSPARSER_TYPE_DNAME: | 834 | case GNUNET_DNSPARSER_TYPE_DNAME: |
@@ -895,90 +840,57 @@ process_record (void *cls, | |||
895 | break; | 840 | break; |
896 | case GNUNET_DNSPARSER_TYPE_MX: | 841 | case GNUNET_DNSPARSER_TYPE_MX: |
897 | if (GNUNET_OK == | 842 | if (GNUNET_OK == |
898 | GNUNET_DNSPARSER_builder_add_mx (dst, | 843 | GNUNET_DNSPARSER_builder_add_mx (dst, dst_len, &off, rec->data.mx)) |
899 | dst_len, | ||
900 | &off, | ||
901 | rec->data.mx)) | ||
902 | { | 844 | { |
903 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 845 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
904 | "Converting MX (`%s') record for `%s'\n", | 846 | "Converting MX (`%s') record for `%s'\n", |
905 | rec->data.mx->mxhost, | 847 | rec->data.mx->mxhost, |
906 | rec->name); | 848 | rec->name); |
907 | add_record (req, | 849 | add_record (req, rec->type, expiration_time, dst, off); |
908 | rec->type, | ||
909 | expiration_time, | ||
910 | dst, | ||
911 | off); | ||
912 | } | 850 | } |
913 | break; | 851 | break; |
914 | case GNUNET_DNSPARSER_TYPE_SOA: | 852 | case GNUNET_DNSPARSER_TYPE_SOA: |
915 | if (GNUNET_OK == | 853 | if (GNUNET_OK == |
916 | GNUNET_DNSPARSER_builder_add_soa (dst, | 854 | GNUNET_DNSPARSER_builder_add_soa (dst, dst_len, &off, rec->data.soa)) |
917 | dst_len, | ||
918 | &off, | ||
919 | rec->data.soa)) | ||
920 | { | 855 | { |
921 | /* NOTE: GNS does not really use SOAs */ | 856 | /* NOTE: GNS does not really use SOAs */ |
922 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 857 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
923 | "Converting SOA record for `%s'\n", | 858 | "Converting SOA record for `%s'\n", |
924 | rec->name); | 859 | rec->name); |
925 | add_record (req, | 860 | add_record (req, rec->type, expiration_time, dst, off); |
926 | rec->type, | ||
927 | expiration_time, | ||
928 | dst, | ||
929 | off); | ||
930 | } | 861 | } |
931 | break; | 862 | break; |
932 | case GNUNET_DNSPARSER_TYPE_SRV: | 863 | case GNUNET_DNSPARSER_TYPE_SRV: |
933 | if (GNUNET_OK == | 864 | if (GNUNET_OK == |
934 | GNUNET_DNSPARSER_builder_add_srv (dst, | 865 | GNUNET_DNSPARSER_builder_add_srv (dst, dst_len, &off, rec->data.srv)) |
935 | dst_len, | ||
936 | &off, | ||
937 | rec->data.srv)) | ||
938 | { | 866 | { |
939 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 867 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
940 | "Converting SRV record for `%s'\n", | 868 | "Converting SRV record for `%s'\n", |
941 | rec->name); | 869 | rec->name); |
942 | add_record (req, | 870 | add_record (req, rec->type, expiration_time, dst, off); |
943 | rec->type, | ||
944 | expiration_time, | ||
945 | dst, | ||
946 | off); | ||
947 | } | 871 | } |
948 | break; | 872 | break; |
949 | case GNUNET_DNSPARSER_TYPE_PTR: | 873 | case GNUNET_DNSPARSER_TYPE_PTR: |
950 | if (GNUNET_OK == | 874 | if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst, |
951 | GNUNET_DNSPARSER_builder_add_name (dst, | 875 | dst_len, |
952 | dst_len, | 876 | &off, |
953 | &off, | 877 | rec->data.hostname)) |
954 | rec->data.hostname)) | ||
955 | { | 878 | { |
956 | /* !?: what does a PTR record do in a regular TLD??? */ | 879 | /* !?: what does a PTR record do in a regular TLD??? */ |
957 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 880 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
958 | "Converting PTR record for `%s' (weird)\n", | 881 | "Converting PTR record for `%s' (weird)\n", |
959 | rec->name); | 882 | rec->name); |
960 | add_record (req, | 883 | add_record (req, rec->type, expiration_time, dst, off); |
961 | rec->type, | ||
962 | expiration_time, | ||
963 | dst, | ||
964 | off); | ||
965 | } | 884 | } |
966 | break; | 885 | break; |
967 | case GNUNET_DNSPARSER_TYPE_CERT: | 886 | case GNUNET_DNSPARSER_TYPE_CERT: |
968 | if (GNUNET_OK == | 887 | if (GNUNET_OK == |
969 | GNUNET_DNSPARSER_builder_add_cert (dst, | 888 | GNUNET_DNSPARSER_builder_add_cert (dst, dst_len, &off, rec->data.cert)) |
970 | dst_len, | ||
971 | &off, | ||
972 | rec->data.cert)) | ||
973 | { | 889 | { |
974 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 890 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
975 | "Converting CERT record for `%s'\n", | 891 | "Converting CERT record for `%s'\n", |
976 | rec->name); | 892 | rec->name); |
977 | add_record (req, | 893 | add_record (req, rec->type, expiration_time, dst, off); |
978 | rec->type, | ||
979 | expiration_time, | ||
980 | dst, | ||
981 | off); | ||
982 | } | 894 | } |
983 | break; | 895 | break; |
984 | /* Rest is 'raw' encoded and just needs to be copied IF | 896 | /* Rest is 'raw' encoded and just needs to be copied IF |
@@ -989,14 +901,14 @@ process_record (void *cls, | |||
989 | case GNUNET_DNSPARSER_TYPE_TXT: | 901 | case GNUNET_DNSPARSER_TYPE_TXT: |
990 | default: | 902 | default: |
991 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 903 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
992 | "Converting record of type %u for `%s'\n", | 904 | "Converting record of type %u for `%s'\n", |
993 | (unsigned int) rec->type, | 905 | (unsigned int) rec->type, |
994 | rec->name); | 906 | rec->name); |
995 | add_record (req, | 907 | add_record (req, |
996 | rec->type, | 908 | rec->type, |
997 | expiration_time, | 909 | expiration_time, |
998 | rec->data.raw.data, | 910 | rec->data.raw.data, |
999 | rec->data.raw.data_len); | 911 | rec->data.raw.data_len); |
1000 | break; | 912 | break; |
1001 | } | 913 | } |
1002 | } | 914 | } |
@@ -1013,9 +925,7 @@ process_record (void *cls, | |||
1013 | * @param emsg NULL on success, otherwise an error message | 925 | * @param emsg NULL on success, otherwise an error message |
1014 | */ | 926 | */ |
1015 | static void | 927 | static void |
1016 | store_completed_cb (void *cls, | 928 | store_completed_cb (void *cls, int32_t success, const char *emsg) |
1017 | int32_t success, | ||
1018 | const char *emsg) | ||
1019 | { | 929 | { |
1020 | static struct GNUNET_TIME_Absolute last; | 930 | static struct GNUNET_TIME_Absolute last; |
1021 | struct Request *req = cls; | 931 | struct Request *req = cls; |
@@ -1024,15 +934,15 @@ store_completed_cb (void *cls, | |||
1024 | if (GNUNET_SYSERR == success) | 934 | if (GNUNET_SYSERR == success) |
1025 | { | 935 | { |
1026 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 936 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1027 | "Failed to store zone data for `%s': %s\n", | 937 | "Failed to store zone data for `%s': %s\n", |
1028 | req->hostname, | 938 | req->hostname, |
1029 | emsg); | 939 | emsg); |
1030 | } | 940 | } |
1031 | else | 941 | else |
1032 | { | 942 | { |
1033 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 943 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1034 | "Stored records under `%s' (%d)\n", | 944 | "Stored records under `%s' (%d)\n", |
1035 | req->hostname, | 945 | req->hostname, |
1036 | success); | 946 | success); |
1037 | } | 947 | } |
1038 | total_reg_proc_dns_ns++; /* finished regular processing */ | 948 | total_reg_proc_dns_ns++; /* finished regular processing */ |
@@ -1045,8 +955,7 @@ store_completed_cb (void *cls, | |||
1045 | struct GNUNET_TIME_Relative ns_latency; | 955 | struct GNUNET_TIME_Relative ns_latency; |
1046 | 956 | ||
1047 | ns_latency = GNUNET_TIME_absolute_get_duration (req->op_start_time); | 957 | ns_latency = GNUNET_TIME_absolute_get_duration (req->op_start_time); |
1048 | total_ns_latency = GNUNET_TIME_relative_add (total_ns_latency, | 958 | total_ns_latency = GNUNET_TIME_relative_add (total_ns_latency, ns_latency); |
1049 | ns_latency); | ||
1050 | if (0 == total_ns_latency_cnt) | 959 | if (0 == total_ns_latency_cnt) |
1051 | last = GNUNET_TIME_absolute_get (); | 960 | last = GNUNET_TIME_absolute_get (); |
1052 | total_ns_latency_cnt++; | 961 | total_ns_latency_cnt++; |
@@ -1057,25 +966,25 @@ store_completed_cb (void *cls, | |||
1057 | delta = GNUNET_TIME_absolute_get_duration (last); | 966 | delta = GNUNET_TIME_absolute_get_duration (last); |
1058 | last = GNUNET_TIME_absolute_get (); | 967 | last = GNUNET_TIME_absolute_get (); |
1059 | fprintf (stderr, | 968 | fprintf (stderr, |
1060 | "Processed 1000 records in %s\n", | 969 | "Processed 1000 records in %s\n", |
1061 | GNUNET_STRINGS_relative_time_to_string (delta, | 970 | GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES)); |
1062 | GNUNET_YES)); | ||
1063 | GNUNET_STATISTICS_set (stats, | 971 | GNUNET_STATISTICS_set (stats, |
1064 | "# average NAMESTORE PUT latency (μs)", | 972 | "# average NAMESTORE PUT latency (μs)", |
1065 | total_ns_latency.rel_value_us / total_ns_latency_cnt, | 973 | total_ns_latency.rel_value_us / |
974 | total_ns_latency_cnt, | ||
1066 | GNUNET_NO); | 975 | GNUNET_NO); |
1067 | } | 976 | } |
1068 | } | 977 | } |
1069 | /* compute and publish overall velocity */ | 978 | /* compute and publish overall velocity */ |
1070 | if (0 == (total_reg_proc_dns_ns % 100) ) | 979 | if (0 == (total_reg_proc_dns_ns % 100)) |
1071 | { | 980 | { |
1072 | struct GNUNET_TIME_Relative runtime; | 981 | struct GNUNET_TIME_Relative runtime; |
1073 | 982 | ||
1074 | runtime = GNUNET_TIME_absolute_get_duration (start_time_reg_proc); | 983 | runtime = GNUNET_TIME_absolute_get_duration (start_time_reg_proc); |
1075 | runtime = GNUNET_TIME_relative_subtract (runtime, | 984 | runtime = GNUNET_TIME_relative_subtract (runtime, idle_time); |
1076 | idle_time); | 985 | runtime = |
1077 | runtime = GNUNET_TIME_relative_divide (runtime, | 986 | GNUNET_TIME_relative_divide (runtime, |
1078 | total_reg_proc_dns + total_reg_proc_dns_ns); | 987 | total_reg_proc_dns + total_reg_proc_dns_ns); |
1079 | GNUNET_STATISTICS_set (stats, | 988 | GNUNET_STATISTICS_set (stats, |
1080 | "# Regular processing completed without NAMESTORE", | 989 | "# Regular processing completed without NAMESTORE", |
1081 | total_reg_proc_dns, | 990 | total_reg_proc_dns, |
@@ -1097,8 +1006,7 @@ store_completed_cb (void *cls, | |||
1097 | if (NULL == t) | 1006 | if (NULL == t) |
1098 | { | 1007 | { |
1099 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); | 1008 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); |
1100 | t = GNUNET_SCHEDULER_add_now (&process_queue, | 1009 | t = GNUNET_SCHEDULER_add_now (&process_queue, NULL); |
1101 | NULL); | ||
1102 | } | 1010 | } |
1103 | } | 1011 | } |
1104 | 1012 | ||
@@ -1124,31 +1032,22 @@ process_result (void *cls, | |||
1124 | if (NULL == dns) | 1032 | if (NULL == dns) |
1125 | { | 1033 | { |
1126 | /* stub gave up */ | 1034 | /* stub gave up */ |
1127 | GNUNET_CONTAINER_DLL_remove (req_head, | 1035 | GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req); |
1128 | req_tail, | ||
1129 | req); | ||
1130 | pending--; | 1036 | pending--; |
1131 | if (NULL == t) | 1037 | if (NULL == t) |
1132 | { | 1038 | { |
1133 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); | 1039 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); |
1134 | t = GNUNET_SCHEDULER_add_now (&process_queue, | 1040 | t = GNUNET_SCHEDULER_add_now (&process_queue, NULL); |
1135 | NULL); | ||
1136 | } | 1041 | } |
1137 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1042 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1138 | "Stub gave up on DNS reply for `%s'\n", | 1043 | "Stub gave up on DNS reply for `%s'\n", |
1139 | req->hostname); | 1044 | req->hostname); |
1140 | GNUNET_STATISTICS_update (stats, | 1045 | GNUNET_STATISTICS_update (stats, "# DNS lookups timed out", 1, GNUNET_NO); |
1141 | "# DNS lookups timed out", | ||
1142 | 1, | ||
1143 | GNUNET_NO); | ||
1144 | if (req->issue_num > MAX_RETRIES) | 1046 | if (req->issue_num > MAX_RETRIES) |
1145 | { | 1047 | { |
1146 | failures++; | 1048 | failures++; |
1147 | free_request (req); | 1049 | free_request (req); |
1148 | GNUNET_STATISTICS_update (stats, | 1050 | GNUNET_STATISTICS_update (stats, "# requests given up on", 1, GNUNET_NO); |
1149 | "# requests given up on", | ||
1150 | 1, | ||
1151 | GNUNET_NO); | ||
1152 | return; | 1051 | return; |
1153 | } | 1052 | } |
1154 | total_reg_proc_dns++; | 1053 | total_reg_proc_dns++; |
@@ -1160,43 +1059,30 @@ process_result (void *cls, | |||
1160 | { | 1059 | { |
1161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1060 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1162 | "DNS ID did not match request, ignoring reply\n"); | 1061 | "DNS ID did not match request, ignoring reply\n"); |
1163 | GNUNET_STATISTICS_update (stats, | 1062 | GNUNET_STATISTICS_update (stats, "# DNS ID mismatches", 1, GNUNET_NO); |
1164 | "# DNS ID mismatches", | ||
1165 | 1, | ||
1166 | GNUNET_NO); | ||
1167 | return; | 1063 | return; |
1168 | } | 1064 | } |
1169 | GNUNET_CONTAINER_DLL_remove (req_head, | 1065 | GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req); |
1170 | req_tail, | ||
1171 | req); | ||
1172 | GNUNET_DNSSTUB_resolve_cancel (req->rs); | 1066 | GNUNET_DNSSTUB_resolve_cancel (req->rs); |
1173 | req->rs = NULL; | 1067 | req->rs = NULL; |
1174 | pending--; | 1068 | pending--; |
1175 | p = GNUNET_DNSPARSER_parse ((const char *) dns, | 1069 | p = GNUNET_DNSPARSER_parse ((const char *) dns, dns_len); |
1176 | dns_len); | ||
1177 | if (NULL == p) | 1070 | if (NULL == p) |
1178 | { | 1071 | { |
1179 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1072 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1180 | "Failed to parse DNS reply for `%s'\n", | 1073 | "Failed to parse DNS reply for `%s'\n", |
1181 | req->hostname); | 1074 | req->hostname); |
1182 | GNUNET_STATISTICS_update (stats, | 1075 | GNUNET_STATISTICS_update (stats, "# DNS parser errors", 1, GNUNET_NO); |
1183 | "# DNS parser errors", | ||
1184 | 1, | ||
1185 | GNUNET_NO); | ||
1186 | if (NULL == t) | 1076 | if (NULL == t) |
1187 | { | 1077 | { |
1188 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); | 1078 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); |
1189 | t = GNUNET_SCHEDULER_add_now (&process_queue, | 1079 | t = GNUNET_SCHEDULER_add_now (&process_queue, NULL); |
1190 | NULL); | ||
1191 | } | 1080 | } |
1192 | if (req->issue_num > MAX_RETRIES) | 1081 | if (req->issue_num > MAX_RETRIES) |
1193 | { | 1082 | { |
1194 | failures++; | 1083 | failures++; |
1195 | free_request (req); | 1084 | free_request (req); |
1196 | GNUNET_STATISTICS_update (stats, | 1085 | GNUNET_STATISTICS_update (stats, "# requests given up on", 1, GNUNET_NO); |
1197 | "# requests given up on", | ||
1198 | 1, | ||
1199 | GNUNET_NO); | ||
1200 | return; | 1086 | return; |
1201 | } | 1087 | } |
1202 | insert_sorted (req); | 1088 | insert_sorted (req); |
@@ -1205,14 +1091,9 @@ process_result (void *cls, | |||
1205 | /* import new records */ | 1091 | /* import new records */ |
1206 | req->issue_num = 0; /* success, reset counter! */ | 1092 | req->issue_num = 0; /* success, reset counter! */ |
1207 | { | 1093 | { |
1208 | struct ProcessRecordContext prc = { | 1094 | struct ProcessRecordContext prc = {.req = req, .p = p}; |
1209 | .req = req, | 1095 | |
1210 | .p = p | 1096 | for_all_records (p, &process_record, &prc); |
1211 | }; | ||
1212 | |||
1213 | for_all_records (p, | ||
1214 | &process_record, | ||
1215 | &prc); | ||
1216 | } | 1097 | } |
1217 | GNUNET_DNSPARSER_free_packet (p); | 1098 | GNUNET_DNSPARSER_free_packet (p); |
1218 | /* count records found, determine minimum expiration time */ | 1099 | /* count records found, determine minimum expiration time */ |
@@ -1221,14 +1102,15 @@ process_result (void *cls, | |||
1221 | struct GNUNET_TIME_Relative dns_latency; | 1102 | struct GNUNET_TIME_Relative dns_latency; |
1222 | 1103 | ||
1223 | dns_latency = GNUNET_TIME_absolute_get_duration (req->op_start_time); | 1104 | dns_latency = GNUNET_TIME_absolute_get_duration (req->op_start_time); |
1224 | total_dns_latency = GNUNET_TIME_relative_add (total_dns_latency, | 1105 | total_dns_latency = |
1225 | dns_latency); | 1106 | GNUNET_TIME_relative_add (total_dns_latency, dns_latency); |
1226 | total_dns_latency_cnt++; | 1107 | total_dns_latency_cnt++; |
1227 | if (0 == (total_dns_latency_cnt % 1000)) | 1108 | if (0 == (total_dns_latency_cnt % 1000)) |
1228 | { | 1109 | { |
1229 | GNUNET_STATISTICS_set (stats, | 1110 | GNUNET_STATISTICS_set (stats, |
1230 | "# average DNS lookup latency (μs)", | 1111 | "# average DNS lookup latency (μs)", |
1231 | total_dns_latency.rel_value_us / total_dns_latency_cnt, | 1112 | total_dns_latency.rel_value_us / |
1113 | total_dns_latency_cnt, | ||
1232 | GNUNET_NO); | 1114 | GNUNET_NO); |
1233 | } | 1115 | } |
1234 | } | 1116 | } |
@@ -1238,20 +1120,18 @@ process_result (void *cls, | |||
1238 | struct GNUNET_TIME_Absolute at; | 1120 | struct GNUNET_TIME_Absolute at; |
1239 | 1121 | ||
1240 | at.abs_value_us = rec->grd.expiration_time; | 1122 | at.abs_value_us = rec->grd.expiration_time; |
1241 | req->expires = GNUNET_TIME_absolute_min (req->expires, | 1123 | req->expires = GNUNET_TIME_absolute_min (req->expires, at); |
1242 | at); | ||
1243 | rd_count++; | 1124 | rd_count++; |
1244 | } | 1125 | } |
1245 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1126 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1246 | "Obtained %u records for `%s'\n", | 1127 | "Obtained %u records for `%s'\n", |
1247 | rd_count, | 1128 | rd_count, |
1248 | req->hostname); | 1129 | req->hostname); |
1249 | /* Instead of going for SOA, simplified for now to look each | 1130 | /* Instead of going for SOA, simplified for now to look each |
1250 | day in case we got an empty response */ | 1131 | day in case we got an empty response */ |
1251 | if (0 == rd_count) | 1132 | if (0 == rd_count) |
1252 | { | 1133 | { |
1253 | req->expires | 1134 | req->expires = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS); |
1254 | = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS); | ||
1255 | GNUNET_STATISTICS_update (stats, | 1135 | GNUNET_STATISTICS_update (stats, |
1256 | "# empty DNS replies (usually NXDOMAIN)", | 1136 | "# empty DNS replies (usually NXDOMAIN)", |
1257 | 1, | 1137 | 1, |
@@ -1263,21 +1143,21 @@ process_result (void *cls, | |||
1263 | } | 1143 | } |
1264 | /* convert records to namestore import format */ | 1144 | /* convert records to namestore import format */ |
1265 | { | 1145 | { |
1266 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)]; | 1146 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)]; |
1267 | unsigned int off = 0; | 1147 | unsigned int off = 0; |
1268 | 1148 | ||
1269 | /* convert linked list into array */ | 1149 | /* convert linked list into array */ |
1270 | for (rec = req->rec_head; NULL != rec; rec =rec->next) | 1150 | for (rec = req->rec_head; NULL != rec; rec = rec->next) |
1271 | rd[off++] = rec->grd; | 1151 | rd[off++] = rec->grd; |
1272 | pending_rs++; | 1152 | pending_rs++; |
1273 | req->op_start_time = GNUNET_TIME_absolute_get (); | 1153 | req->op_start_time = GNUNET_TIME_absolute_get (); |
1274 | req->qe = GNUNET_NAMESTORE_records_store (ns, | 1154 | req->qe = GNUNET_NAMESTORE_records_store (ns, |
1275 | &req->zone->key, | 1155 | &req->zone->key, |
1276 | get_label (req), | 1156 | get_label (req), |
1277 | rd_count, | 1157 | rd_count, |
1278 | rd, | 1158 | rd, |
1279 | &store_completed_cb, | 1159 | &store_completed_cb, |
1280 | req); | 1160 | req); |
1281 | GNUNET_assert (NULL != req->qe); | 1161 | GNUNET_assert (NULL != req->qe); |
1282 | } | 1162 | } |
1283 | insert_sorted (req); | 1163 | insert_sorted (req); |
@@ -1300,8 +1180,7 @@ process_queue (void *cls) | |||
1300 | 1180 | ||
1301 | (void) cls; | 1181 | (void) cls; |
1302 | delay = GNUNET_TIME_absolute_get_duration (sleep_time_reg_proc); | 1182 | delay = GNUNET_TIME_absolute_get_duration (sleep_time_reg_proc); |
1303 | idle_time = GNUNET_TIME_relative_add (idle_time, | 1183 | idle_time = GNUNET_TIME_relative_add (idle_time, delay); |
1304 | delay); | ||
1305 | series = 0; | 1184 | series = 0; |
1306 | t = NULL; | 1185 | t = NULL; |
1307 | while (pending + pending_rs < THRESH) | 1186 | while (pending + pending_rs < THRESH) |
@@ -1318,18 +1197,14 @@ process_queue (void *cls) | |||
1318 | } | 1197 | } |
1319 | if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0) | 1198 | if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0) |
1320 | break; | 1199 | break; |
1321 | GNUNET_assert (req == | 1200 | GNUNET_assert (req == GNUNET_CONTAINER_heap_remove_root (req_heap)); |
1322 | GNUNET_CONTAINER_heap_remove_root (req_heap)); | ||
1323 | req->hn = NULL; | 1201 | req->hn = NULL; |
1324 | GNUNET_CONTAINER_DLL_insert (req_head, | 1202 | GNUNET_CONTAINER_DLL_insert (req_head, req_tail, req); |
1325 | req_tail, | ||
1326 | req); | ||
1327 | GNUNET_assert (NULL == req->rs); | 1203 | GNUNET_assert (NULL == req->rs); |
1328 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1204 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1329 | "Requesting resolution for `%s'\n", | 1205 | "Requesting resolution for `%s'\n", |
1330 | req->hostname); | 1206 | req->hostname); |
1331 | raw = build_dns_query (req, | 1207 | raw = build_dns_query (req, &raw_size); |
1332 | &raw_size); | ||
1333 | if (NULL == raw) | 1208 | if (NULL == raw) |
1334 | { | 1209 | { |
1335 | GNUNET_break (0); | 1210 | GNUNET_break (0); |
@@ -1337,11 +1212,7 @@ process_queue (void *cls) | |||
1337 | continue; | 1212 | continue; |
1338 | } | 1213 | } |
1339 | req->op_start_time = GNUNET_TIME_absolute_get (); | 1214 | req->op_start_time = GNUNET_TIME_absolute_get (); |
1340 | req->rs = GNUNET_DNSSTUB_resolve (ctx, | 1215 | req->rs = GNUNET_DNSSTUB_resolve (ctx, raw, raw_size, &process_result, req); |
1341 | raw, | ||
1342 | raw_size, | ||
1343 | &process_result, | ||
1344 | req); | ||
1345 | GNUNET_assert (NULL != req->rs); | 1216 | GNUNET_assert (NULL != req->rs); |
1346 | req->issue_num++; | 1217 | req->issue_num++; |
1347 | lookups++; | 1218 | lookups++; |
@@ -1353,41 +1224,36 @@ process_queue (void *cls) | |||
1353 | if (pending + pending_rs >= THRESH) | 1224 | if (pending + pending_rs >= THRESH) |
1354 | { | 1225 | { |
1355 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1356 | "Stopped processing queue (%u+%u/%u)]\n", | 1227 | "Stopped processing queue (%u+%u/%u)]\n", |
1357 | pending, | 1228 | pending, |
1358 | pending_rs, | 1229 | pending_rs, |
1359 | THRESH); | 1230 | THRESH); |
1360 | return; /* wait for replies */ | 1231 | return; /* wait for replies */ |
1361 | } | 1232 | } |
1362 | req = GNUNET_CONTAINER_heap_peek (req_heap); | 1233 | req = GNUNET_CONTAINER_heap_peek (req_heap); |
1363 | if (NULL == req) | 1234 | if (NULL == req) |
1364 | { | 1235 | { |
1365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1236 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1366 | "Stopped processing queue: empty queue\n"); | 1237 | "Stopped processing queue: empty queue\n"); |
1367 | return; | 1238 | return; |
1368 | } | 1239 | } |
1369 | if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0) | 1240 | if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0) |
1370 | { | 1241 | { |
1371 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1242 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1372 | "Waiting until %s for next record (`%s') to expire\n", | 1243 | "Waiting until %s for next record (`%s') to expire\n", |
1373 | GNUNET_STRINGS_absolute_time_to_string (req->expires), | 1244 | GNUNET_STRINGS_absolute_time_to_string (req->expires), |
1374 | req->hostname); | 1245 | req->hostname); |
1375 | if (NULL != t) | 1246 | if (NULL != t) |
1376 | GNUNET_SCHEDULER_cancel (t); | 1247 | GNUNET_SCHEDULER_cancel (t); |
1377 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); | 1248 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); |
1378 | t = GNUNET_SCHEDULER_add_at (req->expires, | 1249 | t = GNUNET_SCHEDULER_add_at (req->expires, &process_queue, NULL); |
1379 | &process_queue, | ||
1380 | NULL); | ||
1381 | return; | 1250 | return; |
1382 | } | 1251 | } |
1383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Throttling\n"); |
1384 | "Throttling\n"); | ||
1385 | if (NULL != t) | 1253 | if (NULL != t) |
1386 | GNUNET_SCHEDULER_cancel (t); | 1254 | GNUNET_SCHEDULER_cancel (t); |
1387 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); | 1255 | sleep_time_reg_proc = GNUNET_TIME_absolute_get (); |
1388 | t = GNUNET_SCHEDULER_add_delayed (SERIES_DELAY, | 1256 | t = GNUNET_SCHEDULER_add_delayed (SERIES_DELAY, &process_queue, NULL); |
1389 | &process_queue, | ||
1390 | NULL); | ||
1391 | } | 1257 | } |
1392 | 1258 | ||
1393 | 1259 | ||
@@ -1401,9 +1267,7 @@ process_queue (void *cls) | |||
1401 | * @return #GNUNET_OK | 1267 | * @return #GNUNET_OK |
1402 | */ | 1268 | */ |
1403 | static int | 1269 | static int |
1404 | free_request_it (void *cls, | 1270 | free_request_it (void *cls, const struct GNUNET_HashCode *key, void *value) |
1405 | const struct GNUNET_HashCode *key, | ||
1406 | void *value) | ||
1407 | { | 1271 | { |
1408 | struct Request *req = value; | 1272 | struct Request *req = value; |
1409 | 1273 | ||
@@ -1438,9 +1302,7 @@ do_shutdown (void *cls) | |||
1438 | } | 1302 | } |
1439 | while (NULL != (req = req_head)) | 1303 | while (NULL != (req = req_head)) |
1440 | { | 1304 | { |
1441 | GNUNET_CONTAINER_DLL_remove (req_head, | 1305 | GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req); |
1442 | req_tail, | ||
1443 | req); | ||
1444 | if (NULL != req->qe) | 1306 | if (NULL != req->qe) |
1445 | GNUNET_NAMESTORE_cancel (req->qe); | 1307 | GNUNET_NAMESTORE_cancel (req->qe); |
1446 | free_request (req); | 1308 | free_request (req); |
@@ -1474,17 +1336,13 @@ do_shutdown (void *cls) | |||
1474 | } | 1336 | } |
1475 | if (NULL != ns_pending) | 1337 | if (NULL != ns_pending) |
1476 | { | 1338 | { |
1477 | GNUNET_CONTAINER_multihashmap_iterate (ns_pending, | 1339 | GNUNET_CONTAINER_multihashmap_iterate (ns_pending, &free_request_it, NULL); |
1478 | &free_request_it, | ||
1479 | NULL); | ||
1480 | GNUNET_CONTAINER_multihashmap_destroy (ns_pending); | 1340 | GNUNET_CONTAINER_multihashmap_destroy (ns_pending); |
1481 | ns_pending = NULL; | 1341 | ns_pending = NULL; |
1482 | } | 1342 | } |
1483 | while (NULL != (zone = zone_head)) | 1343 | while (NULL != (zone = zone_head)) |
1484 | { | 1344 | { |
1485 | GNUNET_CONTAINER_DLL_remove (zone_head, | 1345 | GNUNET_CONTAINER_DLL_remove (zone_head, zone_tail, zone); |
1486 | zone_tail, | ||
1487 | zone); | ||
1488 | GNUNET_free (zone->domain); | 1346 | GNUNET_free (zone->domain); |
1489 | GNUNET_free (zone); | 1347 | GNUNET_free (zone); |
1490 | } | 1348 | } |
@@ -1518,8 +1376,8 @@ ns_lookup_error_cb (void *cls) | |||
1518 | struct Zone *zone = cls; | 1376 | struct Zone *zone = cls; |
1519 | 1377 | ||
1520 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1378 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1521 | "Failed to load data from namestore for zone `%s'\n", | 1379 | "Failed to load data from namestore for zone `%s'\n", |
1522 | zone->domain); | 1380 | zone->domain); |
1523 | zone_it = NULL; | 1381 | zone_it = NULL; |
1524 | ns_iterator_trigger_next = 0; | 1382 | ns_iterator_trigger_next = 0; |
1525 | iterate_zones (NULL); | 1383 | iterate_zones (NULL); |
@@ -1537,10 +1395,10 @@ ns_lookup_error_cb (void *cls) | |||
1537 | */ | 1395 | */ |
1538 | static void | 1396 | static void |
1539 | ns_lookup_result_cb (void *cls, | 1397 | ns_lookup_result_cb (void *cls, |
1540 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 1398 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, |
1541 | const char *label, | 1399 | const char *label, |
1542 | unsigned int rd_count, | 1400 | unsigned int rd_count, |
1543 | const struct GNUNET_GNSRECORD_Data *rd) | 1401 | const struct GNUNET_GNSRECORD_Data *rd) |
1544 | { | 1402 | { |
1545 | struct Zone *zone = cls; | 1403 | struct Zone *zone = cls; |
1546 | struct Request *req; | 1404 | struct Request *req; |
@@ -1549,8 +1407,8 @@ ns_lookup_result_cb (void *cls, | |||
1549 | 1407 | ||
1550 | ns_iterator_trigger_next--; | 1408 | ns_iterator_trigger_next--; |
1551 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1552 | "Obtained NAMESTORE reply, %llu left in round\n", | 1410 | "Obtained NAMESTORE reply, %llu left in round\n", |
1553 | (unsigned long long) ns_iterator_trigger_next); | 1411 | (unsigned long long) ns_iterator_trigger_next); |
1554 | if (0 == ns_iterator_trigger_next) | 1412 | if (0 == ns_iterator_trigger_next) |
1555 | { | 1413 | { |
1556 | ns_iterator_trigger_next = NS_BATCH_SIZE; | 1414 | ns_iterator_trigger_next = NS_BATCH_SIZE; |
@@ -1558,19 +1416,12 @@ ns_lookup_result_cb (void *cls, | |||
1558 | "# NAMESTORE records requested from cache", | 1416 | "# NAMESTORE records requested from cache", |
1559 | ns_iterator_trigger_next, | 1417 | ns_iterator_trigger_next, |
1560 | GNUNET_NO); | 1418 | GNUNET_NO); |
1561 | GNUNET_NAMESTORE_zone_iterator_next (zone_it, | 1419 | GNUNET_NAMESTORE_zone_iterator_next (zone_it, ns_iterator_trigger_next); |
1562 | ns_iterator_trigger_next); | ||
1563 | } | 1420 | } |
1564 | GNUNET_asprintf (&fqdn, | 1421 | GNUNET_asprintf (&fqdn, "%s.%s", label, zone->domain); |
1565 | "%s.%s", | 1422 | GNUNET_CRYPTO_hash (fqdn, strlen (fqdn) + 1, &hc); |
1566 | label, | ||
1567 | zone->domain); | ||
1568 | GNUNET_CRYPTO_hash (fqdn, | ||
1569 | strlen (fqdn) + 1, | ||
1570 | &hc); | ||
1571 | GNUNET_free (fqdn); | 1423 | GNUNET_free (fqdn); |
1572 | req = GNUNET_CONTAINER_multihashmap_get (ns_pending, | 1424 | req = GNUNET_CONTAINER_multihashmap_get (ns_pending, &hc); |
1573 | &hc); | ||
1574 | if (NULL == req) | 1425 | if (NULL == req) |
1575 | { | 1426 | { |
1576 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1427 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -1580,14 +1431,10 @@ ns_lookup_result_cb (void *cls, | |||
1580 | return; | 1431 | return; |
1581 | } | 1432 | } |
1582 | GNUNET_assert (GNUNET_OK == | 1433 | GNUNET_assert (GNUNET_OK == |
1583 | GNUNET_CONTAINER_multihashmap_remove (ns_pending, | 1434 | GNUNET_CONTAINER_multihashmap_remove (ns_pending, &hc, req)); |
1584 | &hc, | 1435 | GNUNET_break (0 == GNUNET_memcmp (key, &req->zone->key)); |
1585 | req)); | 1436 | GNUNET_break (0 == strcasecmp (label, get_label (req))); |
1586 | GNUNET_break (0 == GNUNET_memcmp (key, | 1437 | for (unsigned int i = 0; i < rd_count; i++) |
1587 | &req->zone->key)); | ||
1588 | GNUNET_break (0 == strcasecmp (label, | ||
1589 | get_label (req))); | ||
1590 | for (unsigned int i=0;i<rd_count;i++) | ||
1591 | { | 1438 | { |
1592 | struct GNUNET_TIME_Absolute at; | 1439 | struct GNUNET_TIME_Absolute at; |
1593 | 1440 | ||
@@ -1602,17 +1449,13 @@ ns_lookup_result_cb (void *cls, | |||
1602 | { | 1449 | { |
1603 | at.abs_value_us = rd->expiration_time; | 1450 | at.abs_value_us = rd->expiration_time; |
1604 | } | 1451 | } |
1605 | add_record (req, | 1452 | add_record (req, rd->record_type, at, rd->data, rd->data_size); |
1606 | rd->record_type, | ||
1607 | at, | ||
1608 | rd->data, | ||
1609 | rd->data_size); | ||
1610 | } | 1453 | } |
1611 | if (0 == rd_count) | 1454 | if (0 == rd_count) |
1612 | { | 1455 | { |
1613 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1456 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1614 | "Empty record set in namestore for `%s'\n", | 1457 | "Empty record set in namestore for `%s'\n", |
1615 | req->hostname); | 1458 | req->hostname); |
1616 | } | 1459 | } |
1617 | else | 1460 | else |
1618 | { | 1461 | { |
@@ -1620,30 +1463,27 @@ ns_lookup_result_cb (void *cls, | |||
1620 | 1463 | ||
1621 | cached++; | 1464 | cached++; |
1622 | req->expires = GNUNET_TIME_UNIT_FOREVER_ABS; | 1465 | req->expires = GNUNET_TIME_UNIT_FOREVER_ABS; |
1623 | for (struct Record *rec = req->rec_head; | 1466 | for (struct Record *rec = req->rec_head; NULL != rec; rec = rec->next) |
1624 | NULL != rec; | ||
1625 | rec = rec->next) | ||
1626 | { | 1467 | { |
1627 | struct GNUNET_TIME_Absolute at; | 1468 | struct GNUNET_TIME_Absolute at; |
1628 | 1469 | ||
1629 | at.abs_value_us = rec->grd.expiration_time; | 1470 | at.abs_value_us = rec->grd.expiration_time; |
1630 | req->expires = GNUNET_TIME_absolute_min (req->expires, | 1471 | req->expires = GNUNET_TIME_absolute_min (req->expires, at); |
1631 | at); | ||
1632 | pos++; | 1472 | pos++; |
1633 | } | 1473 | } |
1634 | if (0 == pos) | 1474 | if (0 == pos) |
1635 | req->expires = GNUNET_TIME_UNIT_ZERO_ABS; | 1475 | req->expires = GNUNET_TIME_UNIT_ZERO_ABS; |
1636 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1476 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1637 | "Hot-start with %u existing records for `%s'\n", | 1477 | "Hot-start with %u existing records for `%s'\n", |
1638 | pos, | 1478 | pos, |
1639 | req->hostname); | 1479 | req->hostname); |
1640 | } | 1480 | } |
1641 | free_records (req); | 1481 | free_records (req); |
1642 | 1482 | ||
1643 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1483 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1644 | "Adding `%s' to worklist to start at %s\n", | 1484 | "Adding `%s' to worklist to start at %s\n", |
1645 | req->hostname, | 1485 | req->hostname, |
1646 | GNUNET_STRINGS_absolute_time_to_string (req->expires)); | 1486 | GNUNET_STRINGS_absolute_time_to_string (req->expires)); |
1647 | insert_sorted (req); | 1487 | insert_sorted (req); |
1648 | } | 1488 | } |
1649 | 1489 | ||
@@ -1662,8 +1502,7 @@ queue (const char *hostname) | |||
1662 | size_t hlen; | 1502 | size_t hlen; |
1663 | struct GNUNET_HashCode hc; | 1503 | struct GNUNET_HashCode hc; |
1664 | 1504 | ||
1665 | if (GNUNET_OK != | 1505 | if (GNUNET_OK != GNUNET_DNSPARSER_check_name (hostname)) |
1666 | GNUNET_DNSPARSER_check_name (hostname)) | ||
1667 | { | 1506 | { |
1668 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1507 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1669 | "Refusing invalid hostname `%s'\n", | 1508 | "Refusing invalid hostname `%s'\n", |
@@ -1671,8 +1510,7 @@ queue (const char *hostname) | |||
1671 | rejects++; | 1510 | rejects++; |
1672 | return; | 1511 | return; |
1673 | } | 1512 | } |
1674 | dot = strchr (hostname, | 1513 | dot = strchr (hostname, (unsigned char) '.'); |
1675 | (unsigned char) '.'); | ||
1676 | if (NULL == dot) | 1514 | if (NULL == dot) |
1677 | { | 1515 | { |
1678 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1516 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -1682,8 +1520,7 @@ queue (const char *hostname) | |||
1682 | return; | 1520 | return; |
1683 | } | 1521 | } |
1684 | for (zone = zone_head; NULL != zone; zone = zone->next) | 1522 | for (zone = zone_head; NULL != zone; zone = zone->next) |
1685 | if (0 == strcmp (zone->domain, | 1523 | if (0 == strcmp (zone->domain, dot + 1)) |
1686 | dot + 1)) | ||
1687 | break; | 1524 | break; |
1688 | if (NULL == zone) | 1525 | if (NULL == zone) |
1689 | { | 1526 | { |
@@ -1698,19 +1535,15 @@ queue (const char *hostname) | |||
1698 | req = GNUNET_malloc (sizeof (struct Request) + hlen); | 1535 | req = GNUNET_malloc (sizeof (struct Request) + hlen); |
1699 | req->zone = zone; | 1536 | req->zone = zone; |
1700 | req->hostname = (char *) &req[1]; | 1537 | req->hostname = (char *) &req[1]; |
1701 | GNUNET_memcpy (req->hostname, | 1538 | GNUNET_memcpy (req->hostname, hostname, hlen); |
1702 | hostname, | ||
1703 | hlen); | ||
1704 | req->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 1539 | req->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
1705 | UINT16_MAX); | 1540 | UINT16_MAX); |
1706 | GNUNET_CRYPTO_hash (req->hostname, | 1541 | GNUNET_CRYPTO_hash (req->hostname, hlen, &hc); |
1707 | hlen, | 1542 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put ( |
1708 | &hc); | 1543 | ns_pending, |
1709 | if (GNUNET_OK != | 1544 | &hc, |
1710 | GNUNET_CONTAINER_multihashmap_put (ns_pending, | 1545 | req, |
1711 | &hc, | 1546 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
1712 | req, | ||
1713 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1714 | { | 1547 | { |
1715 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1548 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1716 | "Duplicate hostname `%s' ignored\n", | 1549 | "Duplicate hostname `%s' ignored\n", |
@@ -1733,9 +1566,7 @@ queue (const char *hostname) | |||
1733 | * @return #GNUNET_OK (continue to iterate) | 1566 | * @return #GNUNET_OK (continue to iterate) |
1734 | */ | 1567 | */ |
1735 | static int | 1568 | static int |
1736 | move_to_queue (void *cls, | 1569 | move_to_queue (void *cls, const struct GNUNET_HashCode *key, void *value) |
1737 | const struct GNUNET_HashCode *key, | ||
1738 | void *value) | ||
1739 | { | 1570 | { |
1740 | struct Request *req = value; | 1571 | struct Request *req = value; |
1741 | 1572 | ||
@@ -1766,9 +1597,9 @@ iterate_zones (void *cls) | |||
1766 | last->domain); | 1597 | last->domain); |
1767 | /* subtract left-overs from previous iteration */ | 1598 | /* subtract left-overs from previous iteration */ |
1768 | GNUNET_STATISTICS_update (stats, | 1599 | GNUNET_STATISTICS_update (stats, |
1769 | "# NAMESTORE records requested from cache", | 1600 | "# NAMESTORE records requested from cache", |
1770 | (long long) (- ns_iterator_trigger_next), | 1601 | (long long) (-ns_iterator_trigger_next), |
1771 | GNUNET_NO); | 1602 | GNUNET_NO); |
1772 | ns_iterator_trigger_next = 0; | 1603 | ns_iterator_trigger_next = 0; |
1773 | } | 1604 | } |
1774 | GNUNET_assert (NULL != zone_tail); | 1605 | GNUNET_assert (NULL != zone_tail); |
@@ -1777,14 +1608,12 @@ iterate_zones (void *cls) | |||
1777 | /* Done iterating over relevant zones in NAMESTORE, move | 1608 | /* Done iterating over relevant zones in NAMESTORE, move |
1778 | rest of hash map to work queue as well. */ | 1609 | rest of hash map to work queue as well. */ |
1779 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1610 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1780 | "Finished all NAMESTORE iterations!\n"); | 1611 | "Finished all NAMESTORE iterations!\n"); |
1781 | GNUNET_STATISTICS_set (stats, | 1612 | GNUNET_STATISTICS_set (stats, |
1782 | "# Domain names without cached reply", | 1613 | "# Domain names without cached reply", |
1783 | GNUNET_CONTAINER_multihashmap_size (ns_pending), | 1614 | GNUNET_CONTAINER_multihashmap_size (ns_pending), |
1784 | GNUNET_NO); | 1615 | GNUNET_NO); |
1785 | GNUNET_CONTAINER_multihashmap_iterate (ns_pending, | 1616 | GNUNET_CONTAINER_multihashmap_iterate (ns_pending, &move_to_queue, NULL); |
1786 | &move_to_queue, | ||
1787 | NULL); | ||
1788 | GNUNET_CONTAINER_multihashmap_destroy (ns_pending); | 1617 | GNUNET_CONTAINER_multihashmap_destroy (ns_pending); |
1789 | ns_pending = NULL; | 1618 | ns_pending = NULL; |
1790 | start_time_reg_proc = GNUNET_TIME_absolute_get (); | 1619 | start_time_reg_proc = GNUNET_TIME_absolute_get (); |
@@ -1801,14 +1630,11 @@ iterate_zones (void *cls) | |||
1801 | last->domain); | 1630 | last->domain); |
1802 | /* subtract left-overs from previous iteration */ | 1631 | /* subtract left-overs from previous iteration */ |
1803 | GNUNET_STATISTICS_update (stats, | 1632 | GNUNET_STATISTICS_update (stats, |
1804 | "# NAMESTORE records requested from cache", | 1633 | "# NAMESTORE records requested from cache", |
1805 | 1, | 1634 | 1, |
1806 | GNUNET_NO); | 1635 | GNUNET_NO); |
1807 | ns_iterator_trigger_next = 1; | 1636 | ns_iterator_trigger_next = 1; |
1808 | GNUNET_STATISTICS_update (stats, | 1637 | GNUNET_STATISTICS_update (stats, "# zones iterated", 1, GNUNET_NO); |
1809 | "# zones iterated", | ||
1810 | 1, | ||
1811 | GNUNET_NO); | ||
1812 | zone_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | 1638 | zone_it = GNUNET_NAMESTORE_zone_iteration_start (ns, |
1813 | &last->key, | 1639 | &last->key, |
1814 | &ns_lookup_error_cb, | 1640 | &ns_lookup_error_cb, |
@@ -1817,7 +1643,6 @@ iterate_zones (void *cls) | |||
1817 | last, | 1643 | last, |
1818 | &iterate_zones, | 1644 | &iterate_zones, |
1819 | NULL); | 1645 | NULL); |
1820 | |||
1821 | } | 1646 | } |
1822 | 1647 | ||
1823 | 1648 | ||
@@ -1840,13 +1665,10 @@ process_stdin (void *cls) | |||
1840 | GNUNET_IDENTITY_disconnect (id); | 1665 | GNUNET_IDENTITY_disconnect (id); |
1841 | id = NULL; | 1666 | id = NULL; |
1842 | } | 1667 | } |
1843 | while (NULL != | 1668 | while (NULL != fgets (hn, sizeof (hn), stdin)) |
1844 | fgets (hn, | ||
1845 | sizeof (hn), | ||
1846 | stdin)) | ||
1847 | { | 1669 | { |
1848 | if (strlen(hn) > 0) | 1670 | if (strlen (hn) > 0) |
1849 | hn[strlen(hn)-1] = '\0'; /* eat newline */ | 1671 | hn[strlen (hn) - 1] = '\0'; /* eat newline */ |
1850 | if (0 == idot) | 1672 | if (0 == idot) |
1851 | last = GNUNET_TIME_absolute_get (); | 1673 | last = GNUNET_TIME_absolute_get (); |
1852 | idot++; | 1674 | idot++; |
@@ -1857,23 +1679,16 @@ process_stdin (void *cls) | |||
1857 | delta = GNUNET_TIME_absolute_get_duration (last); | 1679 | delta = GNUNET_TIME_absolute_get_duration (last); |
1858 | last = GNUNET_TIME_absolute_get (); | 1680 | last = GNUNET_TIME_absolute_get (); |
1859 | fprintf (stderr, | 1681 | fprintf (stderr, |
1860 | "Read 100000 domain names in %s\n", | 1682 | "Read 100000 domain names in %s\n", |
1861 | GNUNET_STRINGS_relative_time_to_string (delta, | 1683 | GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES)); |
1862 | GNUNET_YES)); | 1684 | GNUNET_STATISTICS_set (stats, "# domain names provided", idot, GNUNET_NO); |
1863 | GNUNET_STATISTICS_set (stats, | ||
1864 | "# domain names provided", | ||
1865 | idot, | ||
1866 | GNUNET_NO); | ||
1867 | } | 1685 | } |
1868 | queue (hn); | 1686 | queue (hn); |
1869 | } | 1687 | } |
1870 | fprintf (stderr, | 1688 | fprintf (stderr, |
1871 | "Done reading %llu domain names\n", | 1689 | "Done reading %llu domain names\n", |
1872 | (unsigned long long) idot); | 1690 | (unsigned long long) idot); |
1873 | GNUNET_STATISTICS_set (stats, | 1691 | GNUNET_STATISTICS_set (stats, "# domain names provided", idot, GNUNET_NO); |
1874 | "# domain names provided", | ||
1875 | idot, | ||
1876 | GNUNET_NO); | ||
1877 | iterate_zones (NULL); | 1692 | iterate_zones (NULL); |
1878 | } | 1693 | } |
1879 | 1694 | ||
@@ -1905,7 +1720,7 @@ process_stdin (void *cls) | |||
1905 | * cleaned up). | 1720 | * cleaned up). |
1906 | * | 1721 | * |
1907 | * @param cls closure | 1722 | * @param cls closure |
1908 | * @param ego ego handle | 1723 | * @param ego ego handle, NULL for end of list |
1909 | * @param ctx context for application to store data for this ego | 1724 | * @param ctx context for application to store data for this ego |
1910 | * (during the lifetime of this process, initially NULL) | 1725 | * (during the lifetime of this process, initially NULL) |
1911 | * @param name name assigned by the user for this ego, | 1726 | * @param name name assigned by the user for this ego, |
@@ -1914,26 +1729,25 @@ process_stdin (void *cls) | |||
1914 | */ | 1729 | */ |
1915 | static void | 1730 | static void |
1916 | identity_cb (void *cls, | 1731 | identity_cb (void *cls, |
1917 | struct GNUNET_IDENTITY_Ego *ego, | 1732 | struct GNUNET_IDENTITY_Ego *ego, |
1918 | void **ctx, | 1733 | void **ctx, |
1919 | const char *name) | 1734 | const char *name) |
1920 | { | 1735 | { |
1921 | (void) cls; | 1736 | (void) cls; |
1922 | (void) ctx; | 1737 | (void) ctx; |
1738 | |||
1923 | if (NULL == ego) | 1739 | if (NULL == ego) |
1924 | { | 1740 | { |
1925 | if (NULL != zone_head) | 1741 | /* end of iteration */ |
1742 | if (NULL == zone_head) | ||
1926 | { | 1743 | { |
1927 | t = GNUNET_SCHEDULER_add_now (&process_stdin, | 1744 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No zone found\n"); |
1928 | NULL); | ||
1929 | } | ||
1930 | else | ||
1931 | { | ||
1932 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1933 | "No zone found\n"); | ||
1934 | GNUNET_SCHEDULER_shutdown (); | 1745 | GNUNET_SCHEDULER_shutdown (); |
1935 | return; | 1746 | return; |
1936 | } | 1747 | } |
1748 | /* zone_head non-null, process hostnames from stdin */ | ||
1749 | t = GNUNET_SCHEDULER_add_now (&process_stdin, NULL); | ||
1750 | return; | ||
1937 | } | 1751 | } |
1938 | if (NULL != name) | 1752 | if (NULL != name) |
1939 | { | 1753 | { |
@@ -1942,9 +1756,7 @@ identity_cb (void *cls, | |||
1942 | zone = GNUNET_new (struct Zone); | 1756 | zone = GNUNET_new (struct Zone); |
1943 | zone->key = *GNUNET_IDENTITY_ego_get_private_key (ego); | 1757 | zone->key = *GNUNET_IDENTITY_ego_get_private_key (ego); |
1944 | zone->domain = GNUNET_strdup (name); | 1758 | zone->domain = GNUNET_strdup (name); |
1945 | GNUNET_CONTAINER_DLL_insert (zone_head, | 1759 | GNUNET_CONTAINER_DLL_insert (zone_head, zone_tail, zone); |
1946 | zone_tail, | ||
1947 | zone); | ||
1948 | } | 1760 | } |
1949 | } | 1761 | } |
1950 | 1762 | ||
@@ -1967,22 +1779,18 @@ run (void *cls, | |||
1967 | (void) cls; | 1779 | (void) cls; |
1968 | (void) args; | 1780 | (void) args; |
1969 | (void) cfgfile; | 1781 | (void) cfgfile; |
1970 | stats = GNUNET_STATISTICS_create ("zoneimport", | 1782 | stats = GNUNET_STATISTICS_create ("zoneimport", cfg); |
1971 | cfg); | ||
1972 | req_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 1783 | req_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
1973 | ns_pending = GNUNET_CONTAINER_multihashmap_create (map_size, | 1784 | ns_pending = GNUNET_CONTAINER_multihashmap_create (map_size, GNUNET_NO); |
1974 | GNUNET_NO); | ||
1975 | if (NULL == ns_pending) | 1785 | if (NULL == ns_pending) |
1976 | { | 1786 | { |
1977 | fprintf (stderr, | 1787 | fprintf (stderr, "Failed to allocate memory for main hash map\n"); |
1978 | "Failed to allocate memory for main hash map\n"); | ||
1979 | return; | 1788 | return; |
1980 | } | 1789 | } |
1981 | ctx = GNUNET_DNSSTUB_start (256); | 1790 | ctx = GNUNET_DNSSTUB_start (256); |
1982 | if (NULL == ctx) | 1791 | if (NULL == ctx) |
1983 | { | 1792 | { |
1984 | fprintf (stderr, | 1793 | fprintf (stderr, "Failed to initialize GNUnet DNS STUB\n"); |
1985 | "Failed to initialize GNUnet DNS STUB\n"); | ||
1986 | return; | 1794 | return; |
1987 | } | 1795 | } |
1988 | if (NULL == args[0]) | 1796 | if (NULL == args[0]) |
@@ -1991,31 +1799,24 @@ run (void *cls, | |||
1991 | "You must provide a list of DNS resolvers on the command line\n"); | 1799 | "You must provide a list of DNS resolvers on the command line\n"); |
1992 | return; | 1800 | return; |
1993 | } | 1801 | } |
1994 | for (unsigned int i=0;NULL != args[i];i++) | 1802 | for (unsigned int i = 0; NULL != args[i]; i++) |
1995 | { | 1803 | { |
1996 | if (GNUNET_OK != | 1804 | if (GNUNET_OK != GNUNET_DNSSTUB_add_dns_ip (ctx, args[i])) |
1997 | GNUNET_DNSSTUB_add_dns_ip (ctx, | ||
1998 | args[i])) | ||
1999 | { | 1805 | { |
2000 | fprintf (stderr, | 1806 | fprintf (stderr, "Failed to use `%s' for DNS resolver\n", args[i]); |
2001 | "Failed to use `%s' for DNS resolver\n", | ||
2002 | args[i]); | ||
2003 | return; | 1807 | return; |
2004 | } | 1808 | } |
2005 | } | 1809 | } |
2006 | 1810 | ||
2007 | 1811 | ||
2008 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 1812 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
2009 | NULL); | ||
2010 | ns = GNUNET_NAMESTORE_connect (cfg); | 1813 | ns = GNUNET_NAMESTORE_connect (cfg); |
2011 | if (NULL == ns) | 1814 | if (NULL == ns) |
2012 | { | 1815 | { |
2013 | GNUNET_SCHEDULER_shutdown (); | 1816 | GNUNET_SCHEDULER_shutdown (); |
2014 | return; | 1817 | return; |
2015 | } | 1818 | } |
2016 | id = GNUNET_IDENTITY_connect (cfg, | 1819 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); |
2017 | &identity_cb, | ||
2018 | NULL); | ||
2019 | } | 1820 | } |
2020 | 1821 | ||
2021 | 1822 | ||
@@ -2027,38 +1828,35 @@ run (void *cls, | |||
2027 | * @return 0 on success | 1828 | * @return 0 on success |
2028 | */ | 1829 | */ |
2029 | int | 1830 | int |
2030 | main (int argc, | 1831 | main (int argc, char *const *argv) |
2031 | char *const*argv) | ||
2032 | { | 1832 | { |
2033 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 1833 | struct GNUNET_GETOPT_CommandLineOption options[] = |
2034 | GNUNET_GETOPT_option_uint ('s', | 1834 | {GNUNET_GETOPT_option_uint ('s', |
2035 | "size", | 1835 | "size", |
2036 | "MAPSIZE", | 1836 | "MAPSIZE", |
2037 | gettext_noop ("size to use for the main hash map"), | 1837 | gettext_noop ( |
2038 | &map_size), | 1838 | "size to use for the main hash map"), |
2039 | GNUNET_GETOPT_option_relative_time ('m', | 1839 | &map_size), |
2040 | "minimum-expiration", | 1840 | GNUNET_GETOPT_option_relative_time ( |
2041 | "RELATIVETIME", | 1841 | 'm', |
2042 | gettext_noop ("minimum expiration time we assume for imported records"), | 1842 | "minimum-expiration", |
2043 | &minimum_expiration_time), | 1843 | "RELATIVETIME", |
2044 | GNUNET_GETOPT_OPTION_END | 1844 | gettext_noop ("minimum expiration time we assume for imported records"), |
2045 | }; | 1845 | &minimum_expiration_time), |
1846 | GNUNET_GETOPT_OPTION_END}; | ||
2046 | int ret; | 1847 | int ret; |
2047 | 1848 | ||
2048 | if (GNUNET_OK != | 1849 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
2049 | GNUNET_STRINGS_get_utf8_args (argc, argv, | ||
2050 | &argc, &argv)) | ||
2051 | return 2; | 1850 | return 2; |
2052 | if (GNUNET_OK != | 1851 | if (GNUNET_OK != (ret = GNUNET_PROGRAM_run (argc, |
2053 | (ret = GNUNET_PROGRAM_run (argc, | 1852 | argv, |
2054 | argv, | 1853 | "gnunet-zoneimport", |
2055 | "gnunet-zoneimport", | 1854 | "import DNS zone into namestore", |
2056 | "import DNS zone into namestore", | 1855 | options, |
2057 | options, | 1856 | &run, |
2058 | &run, | 1857 | NULL))) |
2059 | NULL))) | ||
2060 | return ret; | 1858 | return ret; |
2061 | GNUNET_free ((void*) argv); | 1859 | GNUNET_free ((void *) argv); |
2062 | fprintf (stderr, | 1860 | fprintf (stderr, |
2063 | "Rejected %u names, had %u cached, did %u lookups, stored %u record sets\n" | 1861 | "Rejected %u names, had %u cached, did %u lookups, stored %u record sets\n" |
2064 | "Found %u records, %u lookups failed, %u/%u pending on shutdown\n", | 1862 | "Found %u records, %u lookups failed, %u/%u pending on shutdown\n", |
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c index 9bce542b9..ed1c35535 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -33,7 +33,7 @@ | |||
33 | /** | 33 | /** |
34 | * Interval for expired records cleanup (in seconds) | 34 | * Interval for expired records cleanup (in seconds) |
35 | */ | 35 | */ |
36 | #define EXPIRED_RECORDS_CLEANUP_INTERVAL 300 /* 5mins */ | 36 | #define EXPIRED_RECORDS_CLEANUP_INTERVAL 300 /* 5mins */ |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Our configuration. | 39 | * Our configuration. |
@@ -79,9 +79,7 @@ do_shutdown () | |||
79 | { | 79 | { |
80 | if (NULL != db_lib_name) | 80 | if (NULL != db_lib_name) |
81 | { | 81 | { |
82 | GNUNET_break (NULL == | 82 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db)); |
83 | GNUNET_PLUGIN_unload (db_lib_name, | ||
84 | db)); | ||
85 | GNUNET_free (db_lib_name); | 83 | GNUNET_free (db_lib_name); |
86 | db_lib_name = NULL; | 84 | db_lib_name = NULL; |
87 | } | 85 | } |
@@ -108,15 +106,14 @@ static void | |||
108 | shutdown_task (void *cls) | 106 | shutdown_task (void *cls) |
109 | { | 107 | { |
110 | in_shutdown = GNUNET_YES; | 108 | in_shutdown = GNUNET_YES; |
111 | if (0 == num_clients) /* Only when no connected clients. */ | 109 | if (0 == num_clients) /* Only when no connected clients. */ |
112 | do_shutdown (); | 110 | do_shutdown (); |
113 | } | 111 | } |
114 | 112 | ||
115 | 113 | ||
116 | /* Forward declaration */ | 114 | /* Forward declaration */ |
117 | static void | 115 | static void |
118 | expire_records_continuation (void *cls, | 116 | expire_records_continuation (void *cls, int success); |
119 | int success); | ||
120 | 117 | ||
121 | 118 | ||
122 | /** | 119 | /** |
@@ -131,16 +128,16 @@ cleanup_expired_records (void *cls) | |||
131 | GNUNET_assert (NULL != db); | 128 | GNUNET_assert (NULL != db); |
132 | ret = db->expire_records (db->cls, | 129 | ret = db->expire_records (db->cls, |
133 | GNUNET_TIME_absolute_get (), | 130 | GNUNET_TIME_absolute_get (), |
134 | &expire_records_continuation, | 131 | &expire_records_continuation, |
135 | NULL); | 132 | NULL); |
136 | if (GNUNET_OK != ret) | 133 | if (GNUNET_OK != ret) |
137 | { | 134 | { |
138 | GNUNET_assert (NULL == expire_task); | 135 | GNUNET_assert (NULL == expire_task); |
139 | expire_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 136 | expire_task = GNUNET_SCHEDULER_add_delayed ( |
140 | (GNUNET_TIME_UNIT_SECONDS, | 137 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
141 | EXPIRED_RECORDS_CLEANUP_INTERVAL), | 138 | EXPIRED_RECORDS_CLEANUP_INTERVAL), |
142 | &cleanup_expired_records, | 139 | &cleanup_expired_records, |
143 | NULL); | 140 | NULL); |
144 | } | 141 | } |
145 | } | 142 | } |
146 | 143 | ||
@@ -152,19 +149,16 @@ cleanup_expired_records (void *cls) | |||
152 | * @param success count of records deleted or #GNUNET_SYSERR | 149 | * @param success count of records deleted or #GNUNET_SYSERR |
153 | */ | 150 | */ |
154 | static void | 151 | static void |
155 | expire_records_continuation (void *cls, | 152 | expire_records_continuation (void *cls, int success) |
156 | int success) | ||
157 | { | 153 | { |
158 | if (success > 0) | 154 | if (success > 0) |
159 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 155 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", success); |
160 | "%d records expired.\n", | ||
161 | success); | ||
162 | GNUNET_assert (NULL == expire_task); | 156 | GNUNET_assert (NULL == expire_task); |
163 | expire_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 157 | expire_task = GNUNET_SCHEDULER_add_delayed ( |
164 | (GNUNET_TIME_UNIT_SECONDS, | 158 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
165 | EXPIRED_RECORDS_CLEANUP_INTERVAL), | 159 | EXPIRED_RECORDS_CLEANUP_INTERVAL), |
166 | &cleanup_expired_records, | 160 | &cleanup_expired_records, |
167 | NULL); | 161 | NULL); |
168 | } | 162 | } |
169 | 163 | ||
170 | 164 | ||
@@ -195,15 +189,12 @@ client_connect_cb (void *cls, | |||
195 | * @return #GNUNET_OK to continue iterating | 189 | * @return #GNUNET_OK to continue iterating |
196 | */ | 190 | */ |
197 | static int | 191 | static int |
198 | client_disconnect_it (void *cls, | 192 | client_disconnect_it (void *cls, const struct GNUNET_HashCode *key, void *value) |
199 | const struct GNUNET_HashCode *key, | ||
200 | void *value) | ||
201 | { | 193 | { |
202 | if (value == cls) | 194 | if (value == cls) |
203 | { | 195 | { |
204 | GNUNET_CONTAINER_multihashmap_remove (watchers, | 196 | GNUNET_assert (GNUNET_YES == |
205 | key, | 197 | GNUNET_CONTAINER_multihashmap_remove (watchers, key, value)); |
206 | value); | ||
207 | num_clients++; | 198 | num_clients++; |
208 | } | 199 | } |
209 | return GNUNET_OK; | 200 | return GNUNET_OK; |
@@ -221,15 +212,13 @@ client_disconnect_cb (void *cls, | |||
221 | struct GNUNET_SERVICE_Client *client, | 212 | struct GNUNET_SERVICE_Client *client, |
222 | void *app_cls) | 213 | void *app_cls) |
223 | { | 214 | { |
224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 215 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "A client disconnected, cleaning up.\n"); |
225 | "A client disconnected, cleaning up.\n"); | ||
226 | if (NULL != watchers) | 216 | if (NULL != watchers) |
227 | GNUNET_CONTAINER_multihashmap_iterate (watchers, | 217 | GNUNET_CONTAINER_multihashmap_iterate (watchers, |
228 | &client_disconnect_it, | 218 | &client_disconnect_it, |
229 | client); | 219 | client); |
230 | num_clients--; | 220 | num_clients--; |
231 | if ( (0 == num_clients) && | 221 | if ((0 == num_clients) && in_shutdown) |
232 | in_shutdown) | ||
233 | do_shutdown (); | 222 | do_shutdown (); |
234 | } | 223 | } |
235 | 224 | ||
@@ -255,10 +244,8 @@ record_iterator (void *cls, | |||
255 | /* No more records */ | 244 | /* No more records */ |
256 | struct GNUNET_MessageHeader *endmsg; | 245 | struct GNUNET_MessageHeader *endmsg; |
257 | 246 | ||
258 | env = GNUNET_MQ_msg (endmsg, | 247 | env = GNUNET_MQ_msg (endmsg, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); |
259 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); | 248 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), env); |
260 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), | ||
261 | env); | ||
262 | if (NULL == emsg) | 249 | if (NULL == emsg) |
263 | { | 250 | { |
264 | GNUNET_SERVICE_client_continue (cls_record->client); | 251 | GNUNET_SERVICE_client_continue (cls_record->client); |
@@ -266,25 +253,23 @@ record_iterator (void *cls, | |||
266 | else | 253 | else |
267 | { | 254 | { |
268 | GNUNET_break (0); | 255 | GNUNET_break (0); |
269 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 256 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to iterate: %s\n", emsg); |
270 | "Failed to iterate: %s\n", | ||
271 | emsg); | ||
272 | GNUNET_SERVICE_client_drop (cls_record->client); | 257 | GNUNET_SERVICE_client_drop (cls_record->client); |
273 | } | 258 | } |
274 | PEERSTORE_destroy_record (cls_record); | 259 | PEERSTORE_destroy_record (cls_record); |
275 | return; | 260 | return; |
276 | } | 261 | } |
277 | 262 | ||
278 | env = PEERSTORE_create_record_mq_envelope (record->sub_system, | 263 | env = PEERSTORE_create_record_mq_envelope ( |
279 | &record->peer, | 264 | record->sub_system, |
280 | record->key, | 265 | &record->peer, |
281 | record->value, | 266 | record->key, |
282 | record->value_size, | 267 | record->value, |
283 | record->expiry, | 268 | record->value_size, |
284 | 0, | 269 | record->expiry, |
285 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); | 270 | 0, |
286 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), | 271 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); |
287 | env); | 272 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), env); |
288 | } | 273 | } |
289 | 274 | ||
290 | 275 | ||
@@ -298,26 +283,23 @@ record_iterator (void *cls, | |||
298 | * @return #GNUNET_YES to continue iterating | 283 | * @return #GNUNET_YES to continue iterating |
299 | */ | 284 | */ |
300 | static int | 285 | static int |
301 | watch_notifier_it (void *cls, | 286 | watch_notifier_it (void *cls, const struct GNUNET_HashCode *key, void *value) |
302 | const struct GNUNET_HashCode *key, | ||
303 | void *value) | ||
304 | { | 287 | { |
305 | struct GNUNET_PEERSTORE_Record *record = cls; | 288 | struct GNUNET_PEERSTORE_Record *record = cls; |
306 | struct GNUNET_SERVICE_Client *client = value; | 289 | struct GNUNET_SERVICE_Client *client = value; |
307 | struct GNUNET_MQ_Envelope *env; | 290 | struct GNUNET_MQ_Envelope *env; |
308 | 291 | ||
309 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n"); |
310 | "Found a watcher to update.\n"); | 293 | env = PEERSTORE_create_record_mq_envelope ( |
311 | env = PEERSTORE_create_record_mq_envelope (record->sub_system, | 294 | record->sub_system, |
312 | &record->peer, | 295 | &record->peer, |
313 | record->key, | 296 | record->key, |
314 | record->value, | 297 | record->value, |
315 | record->value_size, | 298 | record->value_size, |
316 | record->expiry, | 299 | record->expiry, |
317 | 0, | 300 | 0, |
318 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD); | 301 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD); |
319 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 302 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); |
320 | env); | ||
321 | return GNUNET_YES; | 303 | return GNUNET_YES; |
322 | } | 304 | } |
323 | 305 | ||
@@ -332,10 +314,7 @@ watch_notifier (struct GNUNET_PEERSTORE_Record *record) | |||
332 | { | 314 | { |
333 | struct GNUNET_HashCode keyhash; | 315 | struct GNUNET_HashCode keyhash; |
334 | 316 | ||
335 | PEERSTORE_hash_key (record->sub_system, | 317 | PEERSTORE_hash_key (record->sub_system, &record->peer, record->key, &keyhash); |
336 | &record->peer, | ||
337 | record->key, | ||
338 | &keyhash); | ||
339 | GNUNET_CONTAINER_multihashmap_get_multiple (watchers, | 318 | GNUNET_CONTAINER_multihashmap_get_multiple (watchers, |
340 | &keyhash, | 319 | &keyhash, |
341 | &watch_notifier_it, | 320 | &watch_notifier_it, |
@@ -350,17 +329,13 @@ watch_notifier (struct GNUNET_PEERSTORE_Record *record) | |||
350 | * @param hm the actual message | 329 | * @param hm the actual message |
351 | */ | 330 | */ |
352 | static void | 331 | static void |
353 | handle_watch_cancel (void *cls, | 332 | handle_watch_cancel (void *cls, const struct StoreKeyHashMessage *hm) |
354 | const struct StoreKeyHashMessage *hm) | ||
355 | { | 333 | { |
356 | struct GNUNET_SERVICE_Client *client = cls; | 334 | struct GNUNET_SERVICE_Client *client = cls; |
357 | 335 | ||
358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch cancel request.\n"); |
359 | "Received a watch cancel request.\n"); | ||
360 | if (GNUNET_OK != | 337 | if (GNUNET_OK != |
361 | GNUNET_CONTAINER_multihashmap_remove (watchers, | 338 | GNUNET_CONTAINER_multihashmap_remove (watchers, &hm->keyhash, client)) |
362 | &hm->keyhash, | ||
363 | client)) | ||
364 | { | 339 | { |
365 | GNUNET_break (0); | 340 | GNUNET_break (0); |
366 | GNUNET_SERVICE_client_drop (client); | 341 | GNUNET_SERVICE_client_drop (client); |
@@ -378,13 +353,11 @@ handle_watch_cancel (void *cls, | |||
378 | * @param hm the actual message | 353 | * @param hm the actual message |
379 | */ | 354 | */ |
380 | static void | 355 | static void |
381 | handle_watch (void *cls, | 356 | handle_watch (void *cls, const struct StoreKeyHashMessage *hm) |
382 | const struct StoreKeyHashMessage *hm) | ||
383 | { | 357 | { |
384 | struct GNUNET_SERVICE_Client *client = cls; | 358 | struct GNUNET_SERVICE_Client *client = cls; |
385 | 359 | ||
386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch request.\n"); |
387 | "Received a watch request.\n"); | ||
388 | num_clients--; /* do not count watchers */ | 361 | num_clients--; /* do not count watchers */ |
389 | GNUNET_SERVICE_client_mark_monitor (client); | 362 | GNUNET_SERVICE_client_mark_monitor (client); |
390 | GNUNET_CONTAINER_multihashmap_put (watchers, | 363 | GNUNET_CONTAINER_multihashmap_put (watchers, |
@@ -403,8 +376,7 @@ handle_watch (void *cls, | |||
403 | * @return #GNUNET_OK if @a srm is well-formed | 376 | * @return #GNUNET_OK if @a srm is well-formed |
404 | */ | 377 | */ |
405 | static int | 378 | static int |
406 | check_iterate (void *cls, | 379 | check_iterate (void *cls, const struct StoreRecordMessage *srm) |
407 | const struct StoreRecordMessage *srm) | ||
408 | { | 380 | { |
409 | struct GNUNET_PEERSTORE_Record *record; | 381 | struct GNUNET_PEERSTORE_Record *record; |
410 | 382 | ||
@@ -432,8 +404,7 @@ check_iterate (void *cls, | |||
432 | * @param srm the actual message | 404 | * @param srm the actual message |
433 | */ | 405 | */ |
434 | static void | 406 | static void |
435 | handle_iterate (void *cls, | 407 | handle_iterate (void *cls, const struct StoreRecordMessage *srm) |
436 | const struct StoreRecordMessage *srm) | ||
437 | { | 408 | { |
438 | struct GNUNET_SERVICE_Client *client = cls; | 409 | struct GNUNET_SERVICE_Client *client = cls; |
439 | struct GNUNET_PEERSTORE_Record *record; | 410 | struct GNUNET_PEERSTORE_Record *record; |
@@ -467,8 +438,7 @@ handle_iterate (void *cls, | |||
467 | * @param success result | 438 | * @param success result |
468 | */ | 439 | */ |
469 | static void | 440 | static void |
470 | store_record_continuation (void *cls, | 441 | store_record_continuation (void *cls, int success) |
471 | int success) | ||
472 | { | 442 | { |
473 | struct GNUNET_PEERSTORE_Record *record = cls; | 443 | struct GNUNET_PEERSTORE_Record *record = cls; |
474 | 444 | ||
@@ -494,8 +464,7 @@ store_record_continuation (void *cls, | |||
494 | * @return #GNUNET_OK if @a srm is well-formed | 464 | * @return #GNUNET_OK if @a srm is well-formed |
495 | */ | 465 | */ |
496 | static int | 466 | static int |
497 | check_store (void *cls, | 467 | check_store (void *cls, const struct StoreRecordMessage *srm) |
498 | const struct StoreRecordMessage *srm) | ||
499 | { | 468 | { |
500 | struct GNUNET_PEERSTORE_Record *record; | 469 | struct GNUNET_PEERSTORE_Record *record; |
501 | 470 | ||
@@ -505,8 +474,7 @@ check_store (void *cls, | |||
505 | GNUNET_break (0); | 474 | GNUNET_break (0); |
506 | return GNUNET_SYSERR; | 475 | return GNUNET_SYSERR; |
507 | } | 476 | } |
508 | if ( (NULL == record->sub_system) || | 477 | if ((NULL == record->sub_system) || (NULL == record->key)) |
509 | (NULL == record->key) ) | ||
510 | { | 478 | { |
511 | GNUNET_break (0); | 479 | GNUNET_break (0); |
512 | PEERSTORE_destroy_record (record); | 480 | PEERSTORE_destroy_record (record); |
@@ -524,31 +492,30 @@ check_store (void *cls, | |||
524 | * @param srm the actual message | 492 | * @param srm the actual message |
525 | */ | 493 | */ |
526 | static void | 494 | static void |
527 | handle_store (void *cls, | 495 | handle_store (void *cls, const struct StoreRecordMessage *srm) |
528 | const struct StoreRecordMessage *srm) | ||
529 | { | 496 | { |
530 | struct GNUNET_SERVICE_Client *client = cls; | 497 | struct GNUNET_SERVICE_Client *client = cls; |
531 | struct GNUNET_PEERSTORE_Record *record; | 498 | struct GNUNET_PEERSTORE_Record *record; |
532 | 499 | ||
533 | record = PEERSTORE_parse_record_message (srm); | 500 | record = PEERSTORE_parse_record_message (srm); |
534 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 501 | GNUNET_log ( |
535 | "Received a store request. Sub system `%s' Peer `%s Key `%s' Options: %u.\n", | 502 | GNUNET_ERROR_TYPE_INFO, |
536 | record->sub_system, | 503 | "Received a store request. Sub system `%s' Peer `%s Key `%s' Options: %u.\n", |
537 | GNUNET_i2s (&record->peer), | 504 | record->sub_system, |
538 | record->key, | 505 | GNUNET_i2s (&record->peer), |
539 | (uint32_t) ntohl (srm->options)); | 506 | record->key, |
507 | (uint32_t) ntohl (srm->options)); | ||
540 | record->client = client; | 508 | record->client = client; |
541 | if (GNUNET_OK != | 509 | if (GNUNET_OK != db->store_record (db->cls, |
542 | db->store_record (db->cls, | 510 | record->sub_system, |
543 | record->sub_system, | 511 | &record->peer, |
544 | &record->peer, | 512 | record->key, |
545 | record->key, | 513 | record->value, |
546 | record->value, | 514 | record->value_size, |
547 | record->value_size, | 515 | record->expiry, |
548 | record->expiry, | 516 | ntohl (srm->options), |
549 | ntohl (srm->options), | 517 | &store_record_continuation, |
550 | &store_record_continuation, | 518 | record)) |
551 | record)) | ||
552 | { | 519 | { |
553 | GNUNET_break (0); | 520 | GNUNET_break (0); |
554 | PEERSTORE_destroy_record (record); | 521 | PEERSTORE_destroy_record (record); |
@@ -574,11 +541,10 @@ run (void *cls, | |||
574 | 541 | ||
575 | in_shutdown = GNUNET_NO; | 542 | in_shutdown = GNUNET_NO; |
576 | cfg = c; | 543 | cfg = c; |
577 | if (GNUNET_OK != | 544 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, |
578 | GNUNET_CONFIGURATION_get_value_string (cfg, | 545 | "peerstore", |
579 | "peerstore", | 546 | "DATABASE", |
580 | "DATABASE", | 547 | &database)) |
581 | &database)) | ||
582 | { | 548 | { |
583 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 549 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
584 | "peerstore", | 550 | "peerstore", |
@@ -586,56 +552,50 @@ run (void *cls, | |||
586 | GNUNET_SCHEDULER_shutdown (); | 552 | GNUNET_SCHEDULER_shutdown (); |
587 | return; | 553 | return; |
588 | } | 554 | } |
589 | GNUNET_asprintf (&db_lib_name, | 555 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_peerstore_%s", database); |
590 | "libgnunet_plugin_peerstore_%s", | 556 | db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); |
591 | database); | ||
592 | db = GNUNET_PLUGIN_load (db_lib_name, | ||
593 | (void *) cfg); | ||
594 | GNUNET_free (database); | 557 | GNUNET_free (database); |
595 | if (NULL == db) | 558 | if (NULL == db) |
596 | { | 559 | { |
597 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 560 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
598 | _("Could not load database backend `%s'\n"), | 561 | _ ("Could not load database backend `%s'\n"), |
599 | db_lib_name); | 562 | db_lib_name); |
600 | GNUNET_SCHEDULER_shutdown (); | 563 | GNUNET_SCHEDULER_shutdown (); |
601 | return; | 564 | return; |
602 | } | 565 | } |
603 | watchers = GNUNET_CONTAINER_multihashmap_create (10, | 566 | watchers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); |
604 | GNUNET_NO); | 567 | expire_task = GNUNET_SCHEDULER_add_now (&cleanup_expired_records, NULL); |
605 | expire_task = GNUNET_SCHEDULER_add_now (&cleanup_expired_records, | 568 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
606 | NULL); | ||
607 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
608 | NULL); | ||
609 | } | 569 | } |
610 | 570 | ||
611 | 571 | ||
612 | /** | 572 | /** |
613 | * Define "main" method using service macro. | 573 | * Define "main" method using service macro. |
614 | */ | 574 | */ |
615 | GNUNET_SERVICE_MAIN | 575 | GNUNET_SERVICE_MAIN ( |
616 | ("peerstore", | 576 | "peerstore", |
617 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, | 577 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, |
618 | &run, | 578 | &run, |
619 | &client_connect_cb, | 579 | &client_connect_cb, |
620 | &client_disconnect_cb, | 580 | &client_disconnect_cb, |
621 | NULL, | 581 | NULL, |
622 | GNUNET_MQ_hd_var_size (store, | 582 | GNUNET_MQ_hd_var_size (store, |
623 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, | 583 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, |
624 | struct StoreRecordMessage, | 584 | struct StoreRecordMessage, |
625 | NULL), | 585 | NULL), |
626 | GNUNET_MQ_hd_var_size (iterate, | 586 | GNUNET_MQ_hd_var_size (iterate, |
627 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, | 587 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, |
628 | struct StoreRecordMessage, | 588 | struct StoreRecordMessage, |
629 | NULL), | 589 | NULL), |
630 | GNUNET_MQ_hd_fixed_size (watch, | 590 | GNUNET_MQ_hd_fixed_size (watch, |
631 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, | 591 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, |
632 | struct StoreKeyHashMessage, | 592 | struct StoreKeyHashMessage, |
633 | NULL), | 593 | NULL), |
634 | GNUNET_MQ_hd_fixed_size (watch_cancel, | 594 | GNUNET_MQ_hd_fixed_size (watch_cancel, |
635 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL, | 595 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL, |
636 | struct StoreKeyHashMessage, | 596 | struct StoreKeyHashMessage, |
637 | NULL), | 597 | NULL), |
638 | GNUNET_MQ_handler_end ()); | 598 | GNUNET_MQ_handler_end ()); |
639 | 599 | ||
640 | 600 | ||
641 | /* end of gnunet-service-peerstore.c */ | 601 | /* end of gnunet-service-peerstore.c */ |
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c index 02f3e287a..64bc3ae72 100644 --- a/src/peerstore/peerstore_api.c +++ b/src/peerstore/peerstore_api.c | |||
@@ -28,7 +28,7 @@ | |||
28 | #include "peerstore.h" | 28 | #include "peerstore.h" |
29 | #include "peerstore_common.h" | 29 | #include "peerstore_common.h" |
30 | 30 | ||
31 | #define LOG(kind,...) GNUNET_log_from (kind, "peerstore-api",__VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from (kind, "peerstore-api", __VA_ARGS__) |
32 | 32 | ||
33 | /******************************************************************************/ | 33 | /******************************************************************************/ |
34 | /************************ DATA STRUCTURES ****************************/ | 34 | /************************ DATA STRUCTURES ****************************/ |
@@ -89,7 +89,6 @@ struct GNUNET_PEERSTORE_Handle | |||
89 | * Are we in the process of disconnecting but need to sync first? | 89 | * Are we in the process of disconnecting but need to sync first? |
90 | */ | 90 | */ |
91 | int disconnecting; | 91 | int disconnecting; |
92 | |||
93 | }; | 92 | }; |
94 | 93 | ||
95 | /** | 94 | /** |
@@ -156,7 +155,6 @@ struct GNUNET_PEERSTORE_StoreContext | |||
156 | * Options for the store operation. | 155 | * Options for the store operation. |
157 | */ | 156 | */ |
158 | enum GNUNET_PEERSTORE_StoreOption options; | 157 | enum GNUNET_PEERSTORE_StoreOption options; |
159 | |||
160 | }; | 158 | }; |
161 | 159 | ||
162 | /** | 160 | /** |
@@ -208,7 +206,6 @@ struct GNUNET_PEERSTORE_IterateContext | |||
208 | * #GNUNET_YES if we are currently processing records. | 206 | * #GNUNET_YES if we are currently processing records. |
209 | */ | 207 | */ |
210 | int iterating; | 208 | int iterating; |
211 | |||
212 | }; | 209 | }; |
213 | 210 | ||
214 | /** | 211 | /** |
@@ -245,7 +242,6 @@ struct GNUNET_PEERSTORE_WatchContext | |||
245 | * Hash of the combined key | 242 | * Hash of the combined key |
246 | */ | 243 | */ |
247 | struct GNUNET_HashCode keyhash; | 244 | struct GNUNET_HashCode keyhash; |
248 | |||
249 | }; | 245 | }; |
250 | 246 | ||
251 | /******************************************************************************/ | 247 | /******************************************************************************/ |
@@ -271,8 +267,7 @@ disconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
271 | { | 267 | { |
272 | struct GNUNET_PEERSTORE_IterateContext *next; | 268 | struct GNUNET_PEERSTORE_IterateContext *next; |
273 | 269 | ||
274 | for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; | 270 | for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL != ic; |
275 | NULL != ic; | ||
276 | ic = next) | 271 | ic = next) |
277 | { | 272 | { |
278 | next = ic->next; | 273 | next = ic->next; |
@@ -285,9 +280,7 @@ disconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
285 | icb_cls = ic->callback_cls; | 280 | icb_cls = ic->callback_cls; |
286 | GNUNET_PEERSTORE_iterate_cancel (ic); | 281 | GNUNET_PEERSTORE_iterate_cancel (ic); |
287 | if (NULL != icb) | 282 | if (NULL != icb) |
288 | icb (icb_cls, | 283 | icb (icb_cls, NULL, "Iteration canceled due to reconnection"); |
289 | NULL, | ||
290 | "Iteration canceled due to reconnection"); | ||
291 | } | 284 | } |
292 | } | 285 | } |
293 | 286 | ||
@@ -312,17 +305,13 @@ disconnect_and_schedule_reconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
312 | disconnect (h); | 305 | disconnect (h); |
313 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 306 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
314 | "Scheduling task to reconnect to PEERSTORE service in %s.\n", | 307 | "Scheduling task to reconnect to PEERSTORE service in %s.\n", |
315 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, | 308 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); |
316 | GNUNET_YES)); | ||
317 | h->reconnect_task = | 309 | h->reconnect_task = |
318 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, | 310 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); |
319 | &reconnect, | ||
320 | h); | ||
321 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); | 311 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); |
322 | } | 312 | } |
323 | 313 | ||
324 | 314 | ||
325 | |||
326 | /** | 315 | /** |
327 | * Callback after MQ envelope is sent | 316 | * Callback after MQ envelope is sent |
328 | * | 317 | * |
@@ -352,8 +341,7 @@ store_request_sent (void *cls) | |||
352 | * Function called when we had trouble talking to the service. | 341 | * Function called when we had trouble talking to the service. |
353 | */ | 342 | */ |
354 | static void | 343 | static void |
355 | handle_client_error (void *cls, | 344 | handle_client_error (void *cls, enum GNUNET_MQ_Error error) |
356 | enum GNUNET_MQ_Error error) | ||
357 | { | 345 | { |
358 | struct GNUNET_PEERSTORE_Handle *h = cls; | 346 | struct GNUNET_PEERSTORE_Handle *h = cls; |
359 | 347 | ||
@@ -373,9 +361,7 @@ handle_client_error (void *cls, | |||
373 | * @return #GNUNET_YES (continue to iterate) | 361 | * @return #GNUNET_YES (continue to iterate) |
374 | */ | 362 | */ |
375 | static int | 363 | static int |
376 | rewatch_it (void *cls, | 364 | rewatch_it (void *cls, const struct GNUNET_HashCode *key, void *value) |
377 | const struct GNUNET_HashCode *key, | ||
378 | void *value) | ||
379 | { | 365 | { |
380 | struct GNUNET_PEERSTORE_Handle *h = cls; | 366 | struct GNUNET_PEERSTORE_Handle *h = cls; |
381 | struct GNUNET_PEERSTORE_WatchContext *wc = value; | 367 | struct GNUNET_PEERSTORE_WatchContext *wc = value; |
@@ -398,9 +384,7 @@ rewatch_it (void *cls, | |||
398 | * @return #GNUNET_YES to continue iteration | 384 | * @return #GNUNET_YES to continue iteration |
399 | */ | 385 | */ |
400 | static int | 386 | static int |
401 | destroy_watch (void *cls, | 387 | destroy_watch (void *cls, const struct GNUNET_HashCode *key, void *value) |
402 | const struct GNUNET_HashCode *key, | ||
403 | void *value) | ||
404 | { | 388 | { |
405 | struct GNUNET_PEERSTORE_WatchContext *wc = value; | 389 | struct GNUNET_PEERSTORE_WatchContext *wc = value; |
406 | 390 | ||
@@ -461,8 +445,7 @@ GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
461 | * @param sync_first send any pending STORE requests before disconnecting | 445 | * @param sync_first send any pending STORE requests before disconnecting |
462 | */ | 446 | */ |
463 | void | 447 | void |
464 | GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, | 448 | GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first) |
465 | int sync_first) | ||
466 | { | 449 | { |
467 | struct GNUNET_PEERSTORE_IterateContext *ic; | 450 | struct GNUNET_PEERSTORE_IterateContext *ic; |
468 | struct GNUNET_PEERSTORE_StoreContext *sc; | 451 | struct GNUNET_PEERSTORE_StoreContext *sc; |
@@ -515,8 +498,7 @@ GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) | |||
515 | GNUNET_free (sc->value); | 498 | GNUNET_free (sc->value); |
516 | GNUNET_free (sc->key); | 499 | GNUNET_free (sc->key); |
517 | GNUNET_free (sc); | 500 | GNUNET_free (sc); |
518 | if ( (GNUNET_YES == h->disconnecting) && | 501 | if ((GNUNET_YES == h->disconnecting) && (NULL == h->store_head)) |
519 | (NULL == h->store_head) ) | ||
520 | final_disconnect (h); | 502 | final_disconnect (h); |
521 | } | 503 | } |
522 | 504 | ||
@@ -542,7 +524,8 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | |||
542 | const char *sub_system, | 524 | const char *sub_system, |
543 | const struct GNUNET_PeerIdentity *peer, | 525 | const struct GNUNET_PeerIdentity *peer, |
544 | const char *key, | 526 | const char *key, |
545 | const void *value, size_t size, | 527 | const void *value, |
528 | size_t size, | ||
546 | struct GNUNET_TIME_Absolute expiry, | 529 | struct GNUNET_TIME_Absolute expiry, |
547 | enum GNUNET_PEERSTORE_StoreOption options, | 530 | enum GNUNET_PEERSTORE_StoreOption options, |
548 | GNUNET_PEERSTORE_Continuation cont, | 531 | GNUNET_PEERSTORE_Continuation cont, |
@@ -553,10 +536,19 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | |||
553 | 536 | ||
554 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 537 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
555 | "Storing value (size: %lu) for subsytem `%s', peer `%s', key `%s'\n", | 538 | "Storing value (size: %lu) for subsytem `%s', peer `%s', key `%s'\n", |
556 | size, sub_system, GNUNET_i2s (peer), key); | 539 | size, |
557 | ev = PEERSTORE_create_record_mq_envelope (sub_system, peer, key, value, size, | 540 | sub_system, |
558 | expiry, options, | 541 | GNUNET_i2s (peer), |
559 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); | 542 | key); |
543 | ev = | ||
544 | PEERSTORE_create_record_mq_envelope (sub_system, | ||
545 | peer, | ||
546 | key, | ||
547 | value, | ||
548 | size, | ||
549 | expiry, | ||
550 | options, | ||
551 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); | ||
560 | sc = GNUNET_new (struct GNUNET_PEERSTORE_StoreContext); | 552 | sc = GNUNET_new (struct GNUNET_PEERSTORE_StoreContext); |
561 | 553 | ||
562 | sc->sub_system = GNUNET_strdup (sub_system); | 554 | sc->sub_system = GNUNET_strdup (sub_system); |
@@ -574,7 +566,6 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | |||
574 | GNUNET_MQ_notify_sent (ev, &store_request_sent, sc); | 566 | GNUNET_MQ_notify_sent (ev, &store_request_sent, sc); |
575 | GNUNET_MQ_send (h->mq, ev); | 567 | GNUNET_MQ_send (h->mq, ev); |
576 | return sc; | 568 | return sc; |
577 | |||
578 | } | 569 | } |
579 | 570 | ||
580 | 571 | ||
@@ -590,8 +581,7 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | |||
590 | * @param msg message received | 581 | * @param msg message received |
591 | */ | 582 | */ |
592 | static void | 583 | static void |
593 | handle_iterate_end (void *cls, | 584 | handle_iterate_end (void *cls, const struct GNUNET_MessageHeader *msg) |
594 | const struct GNUNET_MessageHeader *msg) | ||
595 | { | 585 | { |
596 | struct GNUNET_PEERSTORE_Handle *h = cls; | 586 | struct GNUNET_PEERSTORE_Handle *h = cls; |
597 | struct GNUNET_PEERSTORE_IterateContext *ic; | 587 | struct GNUNET_PEERSTORE_IterateContext *ic; |
@@ -602,7 +592,7 @@ handle_iterate_end (void *cls, | |||
602 | if (NULL == ic) | 592 | if (NULL == ic) |
603 | { | 593 | { |
604 | LOG (GNUNET_ERROR_TYPE_ERROR, | 594 | LOG (GNUNET_ERROR_TYPE_ERROR, |
605 | _("Unexpected iteration response, this should not happen.\n")); | 595 | _ ("Unexpected iteration response, this should not happen.\n")); |
606 | disconnect_and_schedule_reconnect (h); | 596 | disconnect_and_schedule_reconnect (h); |
607 | return; | 597 | return; |
608 | } | 598 | } |
@@ -611,9 +601,7 @@ handle_iterate_end (void *cls, | |||
611 | ic->iterating = GNUNET_NO; | 601 | ic->iterating = GNUNET_NO; |
612 | GNUNET_PEERSTORE_iterate_cancel (ic); | 602 | GNUNET_PEERSTORE_iterate_cancel (ic); |
613 | if (NULL != callback) | 603 | if (NULL != callback) |
614 | callback (callback_cls, | 604 | callback (callback_cls, NULL, NULL); |
615 | NULL, | ||
616 | NULL); | ||
617 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 605 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
618 | } | 606 | } |
619 | 607 | ||
@@ -626,8 +614,7 @@ handle_iterate_end (void *cls, | |||
626 | * @param msg message received | 614 | * @param msg message received |
627 | */ | 615 | */ |
628 | static int | 616 | static int |
629 | check_iterate_result (void *cls, | 617 | check_iterate_result (void *cls, const struct StoreRecordMessage *msg) |
630 | const struct StoreRecordMessage *msg) | ||
631 | { | 618 | { |
632 | /* we defer validation to #handle_iterate_result */ | 619 | /* we defer validation to #handle_iterate_result */ |
633 | return GNUNET_OK; | 620 | return GNUNET_OK; |
@@ -641,8 +628,7 @@ check_iterate_result (void *cls, | |||
641 | * @param msg message received | 628 | * @param msg message received |
642 | */ | 629 | */ |
643 | static void | 630 | static void |
644 | handle_iterate_result (void *cls, | 631 | handle_iterate_result (void *cls, const struct StoreRecordMessage *msg) |
645 | const struct StoreRecordMessage *msg) | ||
646 | { | 632 | { |
647 | struct GNUNET_PEERSTORE_Handle *h = cls; | 633 | struct GNUNET_PEERSTORE_Handle *h = cls; |
648 | struct GNUNET_PEERSTORE_IterateContext *ic; | 634 | struct GNUNET_PEERSTORE_IterateContext *ic; |
@@ -654,7 +640,7 @@ handle_iterate_result (void *cls, | |||
654 | if (NULL == ic) | 640 | if (NULL == ic) |
655 | { | 641 | { |
656 | LOG (GNUNET_ERROR_TYPE_ERROR, | 642 | LOG (GNUNET_ERROR_TYPE_ERROR, |
657 | _("Unexpected iteration response, this should not happen.\n")); | 643 | _ ("Unexpected iteration response, this should not happen.\n")); |
658 | disconnect_and_schedule_reconnect (h); | 644 | disconnect_and_schedule_reconnect (h); |
659 | return; | 645 | return; |
660 | } | 646 | } |
@@ -668,13 +654,11 @@ handle_iterate_result (void *cls, | |||
668 | { | 654 | { |
669 | callback (callback_cls, | 655 | callback (callback_cls, |
670 | NULL, | 656 | NULL, |
671 | _("Received a malformed response from service.")); | 657 | _ ("Received a malformed response from service.")); |
672 | } | 658 | } |
673 | else | 659 | else |
674 | { | 660 | { |
675 | callback (callback_cls, | 661 | callback (callback_cls, record, NULL); |
676 | record, | ||
677 | NULL); | ||
678 | PEERSTORE_destroy_record (record); | 662 | PEERSTORE_destroy_record (record); |
679 | } | 663 | } |
680 | } | 664 | } |
@@ -691,9 +675,7 @@ GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic) | |||
691 | { | 675 | { |
692 | if (GNUNET_NO == ic->iterating) | 676 | if (GNUNET_NO == ic->iterating) |
693 | { | 677 | { |
694 | GNUNET_CONTAINER_DLL_remove (ic->h->iterate_head, | 678 | GNUNET_CONTAINER_DLL_remove (ic->h->iterate_head, ic->h->iterate_tail, ic); |
695 | ic->h->iterate_tail, | ||
696 | ic); | ||
697 | GNUNET_free (ic->sub_system); | 679 | GNUNET_free (ic->sub_system); |
698 | GNUNET_free_non_null (ic->key); | 680 | GNUNET_free_non_null (ic->key); |
699 | GNUNET_free (ic); | 681 | GNUNET_free (ic); |
@@ -725,13 +707,15 @@ GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, | |||
725 | struct GNUNET_MQ_Envelope *ev; | 707 | struct GNUNET_MQ_Envelope *ev; |
726 | struct GNUNET_PEERSTORE_IterateContext *ic; | 708 | struct GNUNET_PEERSTORE_IterateContext *ic; |
727 | 709 | ||
728 | ev = PEERSTORE_create_record_mq_envelope (sub_system, | 710 | ev = |
729 | peer, | 711 | PEERSTORE_create_record_mq_envelope (sub_system, |
730 | key, | 712 | peer, |
731 | NULL, 0, | 713 | key, |
732 | GNUNET_TIME_UNIT_FOREVER_ABS, | 714 | NULL, |
733 | 0, | 715 | 0, |
734 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); | 716 | GNUNET_TIME_UNIT_FOREVER_ABS, |
717 | 0, | ||
718 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); | ||
735 | ic = GNUNET_new (struct GNUNET_PEERSTORE_IterateContext); | 719 | ic = GNUNET_new (struct GNUNET_PEERSTORE_IterateContext); |
736 | ic->callback = callback; | 720 | ic->callback = callback; |
737 | ic->callback_cls = callback_cls; | 721 | ic->callback_cls = callback_cls; |
@@ -741,9 +725,7 @@ GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, | |||
741 | ic->peer = *peer; | 725 | ic->peer = *peer; |
742 | if (NULL != key) | 726 | if (NULL != key) |
743 | ic->key = GNUNET_strdup (key); | 727 | ic->key = GNUNET_strdup (key); |
744 | GNUNET_CONTAINER_DLL_insert_tail (h->iterate_head, | 728 | GNUNET_CONTAINER_DLL_insert_tail (h->iterate_head, h->iterate_tail, ic); |
745 | h->iterate_tail, | ||
746 | ic); | ||
747 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 729 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
748 | "Sending an iterate request for sub system `%s'\n", | 730 | "Sending an iterate request for sub system `%s'\n", |
749 | sub_system); | 731 | sub_system); |
@@ -763,8 +745,7 @@ GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, | |||
763 | * @param msg message received | 745 | * @param msg message received |
764 | */ | 746 | */ |
765 | static int | 747 | static int |
766 | check_watch_record (void *cls, | 748 | check_watch_record (void *cls, const struct StoreRecordMessage *msg) |
767 | const struct StoreRecordMessage *msg) | ||
768 | { | 749 | { |
769 | /* we defer validation to #handle_watch_result */ | 750 | /* we defer validation to #handle_watch_result */ |
770 | return GNUNET_OK; | 751 | return GNUNET_OK; |
@@ -778,41 +759,33 @@ check_watch_record (void *cls, | |||
778 | * @param msg message received | 759 | * @param msg message received |
779 | */ | 760 | */ |
780 | static void | 761 | static void |
781 | handle_watch_record (void *cls, | 762 | handle_watch_record (void *cls, const struct StoreRecordMessage *msg) |
782 | const struct StoreRecordMessage *msg) | ||
783 | { | 763 | { |
784 | struct GNUNET_PEERSTORE_Handle *h = cls; | 764 | struct GNUNET_PEERSTORE_Handle *h = cls; |
785 | struct GNUNET_PEERSTORE_Record *record; | 765 | struct GNUNET_PEERSTORE_Record *record; |
786 | struct GNUNET_HashCode keyhash; | 766 | struct GNUNET_HashCode keyhash; |
787 | struct GNUNET_PEERSTORE_WatchContext *wc; | 767 | struct GNUNET_PEERSTORE_WatchContext *wc; |
788 | 768 | ||
789 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 769 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a watch record from service.\n"); |
790 | "Received a watch record from service.\n"); | ||
791 | record = PEERSTORE_parse_record_message (msg); | 770 | record = PEERSTORE_parse_record_message (msg); |
792 | if (NULL == record) | 771 | if (NULL == record) |
793 | { | 772 | { |
794 | disconnect_and_schedule_reconnect (h); | 773 | disconnect_and_schedule_reconnect (h); |
795 | return; | 774 | return; |
796 | } | 775 | } |
797 | PEERSTORE_hash_key (record->sub_system, | 776 | PEERSTORE_hash_key (record->sub_system, &record->peer, record->key, &keyhash); |
798 | &record->peer, | ||
799 | record->key, | ||
800 | &keyhash); | ||
801 | // FIXME: what if there are multiple watches for the same key? | 777 | // FIXME: what if there are multiple watches for the same key? |
802 | wc = GNUNET_CONTAINER_multihashmap_get (h->watches, | 778 | wc = GNUNET_CONTAINER_multihashmap_get (h->watches, &keyhash); |
803 | &keyhash); | ||
804 | if (NULL == wc) | 779 | if (NULL == wc) |
805 | { | 780 | { |
806 | LOG (GNUNET_ERROR_TYPE_ERROR, | 781 | LOG (GNUNET_ERROR_TYPE_ERROR, |
807 | _("Received a watch result for a non existing watch.\n")); | 782 | _ ("Received a watch result for a non existing watch.\n")); |
808 | PEERSTORE_destroy_record (record); | 783 | PEERSTORE_destroy_record (record); |
809 | disconnect_and_schedule_reconnect (h); | 784 | disconnect_and_schedule_reconnect (h); |
810 | return; | 785 | return; |
811 | } | 786 | } |
812 | if (NULL != wc->callback) | 787 | if (NULL != wc->callback) |
813 | wc->callback (wc->callback_cls, | 788 | wc->callback (wc->callback_cls, record, NULL); |
814 | record, | ||
815 | NULL); | ||
816 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 789 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
817 | PEERSTORE_destroy_record (record); | 790 | PEERSTORE_destroy_record (record); |
818 | } | 791 | } |
@@ -827,26 +800,24 @@ static void | |||
827 | reconnect (void *cls) | 800 | reconnect (void *cls) |
828 | { | 801 | { |
829 | struct GNUNET_PEERSTORE_Handle *h = cls; | 802 | struct GNUNET_PEERSTORE_Handle *h = cls; |
830 | struct GNUNET_MQ_MessageHandler mq_handlers[] = { | 803 | struct GNUNET_MQ_MessageHandler mq_handlers[] = |
831 | GNUNET_MQ_hd_fixed_size (iterate_end, | 804 | {GNUNET_MQ_hd_fixed_size (iterate_end, |
832 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, | 805 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, |
833 | struct GNUNET_MessageHeader, | 806 | struct GNUNET_MessageHeader, |
834 | h), | 807 | h), |
835 | GNUNET_MQ_hd_var_size (iterate_result, | 808 | GNUNET_MQ_hd_var_size (iterate_result, |
836 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, | 809 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, |
837 | struct StoreRecordMessage, | 810 | struct StoreRecordMessage, |
838 | h), | 811 | h), |
839 | GNUNET_MQ_hd_var_size (watch_record, | 812 | GNUNET_MQ_hd_var_size (watch_record, |
840 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, | 813 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, |
841 | struct StoreRecordMessage, | 814 | struct StoreRecordMessage, |
842 | h), | 815 | h), |
843 | GNUNET_MQ_handler_end () | 816 | GNUNET_MQ_handler_end ()}; |
844 | }; | ||
845 | struct GNUNET_MQ_Envelope *ev; | 817 | struct GNUNET_MQ_Envelope *ev; |
846 | 818 | ||
847 | h->reconnect_task = NULL; | 819 | h->reconnect_task = NULL; |
848 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 820 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n"); |
849 | "Reconnecting...\n"); | ||
850 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 821 | h->mq = GNUNET_CLIENT_connect (h->cfg, |
851 | "peerstore", | 822 | "peerstore", |
852 | mq_handlers, | 823 | mq_handlers, |
@@ -857,39 +828,35 @@ reconnect (void *cls) | |||
857 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 828 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
858 | "Resending pending requests after reconnect.\n"); | 829 | "Resending pending requests after reconnect.\n"); |
859 | if (NULL != h->watches) | 830 | if (NULL != h->watches) |
860 | GNUNET_CONTAINER_multihashmap_iterate (h->watches, | 831 | GNUNET_CONTAINER_multihashmap_iterate (h->watches, &rewatch_it, h); |
861 | &rewatch_it, | 832 | for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL != ic; |
862 | h); | ||
863 | for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; | ||
864 | NULL != ic; | ||
865 | ic = ic->next) | 833 | ic = ic->next) |
866 | { | 834 | { |
867 | ev = PEERSTORE_create_record_mq_envelope (ic->sub_system, | 835 | ev = |
868 | &ic->peer, | 836 | PEERSTORE_create_record_mq_envelope (ic->sub_system, |
869 | ic->key, | 837 | &ic->peer, |
870 | NULL, 0, | 838 | ic->key, |
871 | GNUNET_TIME_UNIT_FOREVER_ABS, | 839 | NULL, |
872 | 0, | 840 | 0, |
873 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); | 841 | GNUNET_TIME_UNIT_FOREVER_ABS, |
842 | 0, | ||
843 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); | ||
874 | GNUNET_MQ_send (h->mq, ev); | 844 | GNUNET_MQ_send (h->mq, ev); |
875 | } | 845 | } |
876 | for (struct GNUNET_PEERSTORE_StoreContext *sc = h->store_head; | 846 | for (struct GNUNET_PEERSTORE_StoreContext *sc = h->store_head; NULL != sc; |
877 | NULL != sc; | ||
878 | sc = sc->next) | 847 | sc = sc->next) |
879 | { | 848 | { |
880 | ev = PEERSTORE_create_record_mq_envelope (sc->sub_system, | 849 | ev = |
881 | &sc->peer, | 850 | PEERSTORE_create_record_mq_envelope (sc->sub_system, |
882 | sc->key, | 851 | &sc->peer, |
883 | sc->value, | 852 | sc->key, |
884 | sc->size, | 853 | sc->value, |
885 | sc->expiry, | 854 | sc->size, |
886 | sc->options, | 855 | sc->expiry, |
887 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); | 856 | sc->options, |
888 | GNUNET_MQ_notify_sent (ev, | 857 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); |
889 | &store_request_sent, | 858 | GNUNET_MQ_notify_sent (ev, &store_request_sent, sc); |
890 | sc); | 859 | GNUNET_MQ_send (h->mq, ev); |
891 | GNUNET_MQ_send (h->mq, | ||
892 | ev); | ||
893 | } | 860 | } |
894 | } | 861 | } |
895 | 862 | ||
@@ -906,15 +873,13 @@ GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc) | |||
906 | struct GNUNET_MQ_Envelope *ev; | 873 | struct GNUNET_MQ_Envelope *ev; |
907 | struct StoreKeyHashMessage *hm; | 874 | struct StoreKeyHashMessage *hm; |
908 | 875 | ||
909 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 876 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Canceling watch.\n"); |
910 | "Canceling watch.\n"); | 877 | ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL); |
911 | ev = GNUNET_MQ_msg (hm, | ||
912 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL); | ||
913 | hm->keyhash = wc->keyhash; | 878 | hm->keyhash = wc->keyhash; |
914 | GNUNET_MQ_send (h->mq, ev); | 879 | GNUNET_MQ_send (h->mq, ev); |
915 | GNUNET_CONTAINER_multihashmap_remove (h->watches, | 880 | GNUNET_assert ( |
916 | &wc->keyhash, | 881 | GNUNET_YES == |
917 | wc); | 882 | GNUNET_CONTAINER_multihashmap_remove (h->watches, &wc->keyhash, wc)); |
918 | GNUNET_free (wc); | 883 | GNUNET_free (wc); |
919 | } | 884 | } |
920 | 885 | ||
@@ -943,32 +908,26 @@ GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h, | |||
943 | struct StoreKeyHashMessage *hm; | 908 | struct StoreKeyHashMessage *hm; |
944 | struct GNUNET_PEERSTORE_WatchContext *wc; | 909 | struct GNUNET_PEERSTORE_WatchContext *wc; |
945 | 910 | ||
946 | ev = GNUNET_MQ_msg (hm, | 911 | ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); |
947 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH); | 912 | PEERSTORE_hash_key (sub_system, peer, key, &hm->keyhash); |
948 | PEERSTORE_hash_key (sub_system, | ||
949 | peer, | ||
950 | key, | ||
951 | &hm->keyhash); | ||
952 | wc = GNUNET_new (struct GNUNET_PEERSTORE_WatchContext); | 913 | wc = GNUNET_new (struct GNUNET_PEERSTORE_WatchContext); |
953 | wc->callback = callback; | 914 | wc->callback = callback; |
954 | wc->callback_cls = callback_cls; | 915 | wc->callback_cls = callback_cls; |
955 | wc->h = h; | 916 | wc->h = h; |
956 | wc->keyhash = hm->keyhash; | 917 | wc->keyhash = hm->keyhash; |
957 | if (NULL == h->watches) | 918 | if (NULL == h->watches) |
958 | h->watches = GNUNET_CONTAINER_multihashmap_create (5, | 919 | h->watches = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO); |
959 | GNUNET_NO); | 920 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put ( |
960 | GNUNET_assert (GNUNET_OK == | 921 | h->watches, |
961 | GNUNET_CONTAINER_multihashmap_put (h->watches, | 922 | &wc->keyhash, |
962 | &wc->keyhash, | 923 | wc, |
963 | wc, | 924 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
964 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
965 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 925 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
966 | "Sending a watch request for subsystem `%s', peer `%s', key `%s'.\n", | 926 | "Sending a watch request for subsystem `%s', peer `%s', key `%s'.\n", |
967 | sub_system, | 927 | sub_system, |
968 | GNUNET_i2s (peer), | 928 | GNUNET_i2s (peer), |
969 | key); | 929 | key); |
970 | GNUNET_MQ_send (h->mq, | 930 | GNUNET_MQ_send (h->mq, ev); |
971 | ev); | ||
972 | return wc; | 931 | return wc; |
973 | } | 932 | } |
974 | 933 | ||
diff --git a/src/regex/regex_internal.c b/src/regex/regex_internal.c index 3f667a11f..55d16129f 100644 --- a/src/regex/regex_internal.c +++ b/src/regex/regex_internal.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -66,7 +66,7 @@ struct REGEX_INTERNAL_StateSet_MDLL | |||
66 | */ | 66 | */ |
67 | static void | 67 | static void |
68 | state_set_append (struct REGEX_INTERNAL_StateSet *set, | 68 | state_set_append (struct REGEX_INTERNAL_StateSet *set, |
69 | struct REGEX_INTERNAL_State *state) | 69 | struct REGEX_INTERNAL_State *state) |
70 | { | 70 | { |
71 | if (set->off == set->size) | 71 | if (set->off == set->size) |
72 | GNUNET_array_grow (set->states, set->size, set->size * 2 + 4); | 72 | GNUNET_array_grow (set->states, set->size, set->size * 2 + 4); |
@@ -114,8 +114,7 @@ state_add_transition (struct REGEX_INTERNAL_Context *ctx, | |||
114 | 114 | ||
115 | if (NULL == from_state) | 115 | if (NULL == from_state) |
116 | { | 116 | { |
117 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 117 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create Transition.\n"); |
118 | "Could not create Transition.\n"); | ||
119 | return; | 118 | return; |
120 | } | 119 | } |
121 | 120 | ||
@@ -147,7 +146,9 @@ state_add_transition (struct REGEX_INTERNAL_Context *ctx, | |||
147 | /* Add outgoing transition to 'from_state' */ | 146 | /* Add outgoing transition to 'from_state' */ |
148 | from_state->transition_count++; | 147 | from_state->transition_count++; |
149 | GNUNET_CONTAINER_DLL_insert_before (from_state->transitions_head, | 148 | GNUNET_CONTAINER_DLL_insert_before (from_state->transitions_head, |
150 | from_state->transitions_tail, oth, t); | 149 | from_state->transitions_tail, |
150 | oth, | ||
151 | t); | ||
151 | } | 152 | } |
152 | 153 | ||
153 | 154 | ||
@@ -170,7 +171,8 @@ state_remove_transition (struct REGEX_INTERNAL_State *state, | |||
170 | GNUNET_free_non_null (transition->label); | 171 | GNUNET_free_non_null (transition->label); |
171 | 172 | ||
172 | state->transition_count--; | 173 | state->transition_count--; |
173 | GNUNET_CONTAINER_DLL_remove (state->transitions_head, state->transitions_tail, | 174 | GNUNET_CONTAINER_DLL_remove (state->transitions_head, |
175 | state->transitions_tail, | ||
174 | transition); | 176 | transition); |
175 | 177 | ||
176 | GNUNET_free (transition); | 178 | GNUNET_free (transition); |
@@ -207,8 +209,7 @@ state_compare (const void *a, const void *b) | |||
207 | * @return number of edges. | 209 | * @return number of edges. |
208 | */ | 210 | */ |
209 | static unsigned int | 211 | static unsigned int |
210 | state_get_edges (struct REGEX_INTERNAL_State *s, | 212 | state_get_edges (struct REGEX_INTERNAL_State *s, struct REGEX_BLOCK_Edge *edges) |
211 | struct REGEX_BLOCK_Edge *edges) | ||
212 | { | 213 | { |
213 | struct REGEX_INTERNAL_Transition *t; | 214 | struct REGEX_INTERNAL_Transition *t; |
214 | unsigned int count; | 215 | unsigned int count; |
@@ -463,10 +464,13 @@ automaton_add_state (struct REGEX_INTERNAL_Automaton *a, | |||
463 | * @param action_cls closure for action. | 464 | * @param action_cls closure for action. |
464 | */ | 465 | */ |
465 | static void | 466 | static void |
466 | automaton_state_traverse (struct REGEX_INTERNAL_State *s, int *marks, | 467 | automaton_state_traverse (struct REGEX_INTERNAL_State *s, |
468 | int *marks, | ||
467 | unsigned int *count, | 469 | unsigned int *count, |
468 | REGEX_INTERNAL_traverse_check check, void *check_cls, | 470 | REGEX_INTERNAL_traverse_check check, |
469 | REGEX_INTERNAL_traverse_action action, void *action_cls) | 471 | void *check_cls, |
472 | REGEX_INTERNAL_traverse_action action, | ||
473 | void *action_cls) | ||
470 | { | 474 | { |
471 | struct REGEX_INTERNAL_Transition *t; | 475 | struct REGEX_INTERNAL_Transition *t; |
472 | 476 | ||
@@ -485,8 +489,13 @@ automaton_state_traverse (struct REGEX_INTERNAL_State *s, int *marks, | |||
485 | if (NULL == check || | 489 | if (NULL == check || |
486 | (NULL != check && GNUNET_YES == check (check_cls, s, t))) | 490 | (NULL != check && GNUNET_YES == check (check_cls, s, t))) |
487 | { | 491 | { |
488 | automaton_state_traverse (t->to_state, marks, count, check, check_cls, | 492 | automaton_state_traverse (t->to_state, |
489 | action, action_cls); | 493 | marks, |
494 | count, | ||
495 | check, | ||
496 | check_cls, | ||
497 | action, | ||
498 | action_cls); | ||
490 | } | 499 | } |
491 | } | 500 | } |
492 | } | 501 | } |
@@ -535,9 +544,13 @@ REGEX_INTERNAL_automaton_traverse (const struct REGEX_INTERNAL_Automaton *a, | |||
535 | else | 544 | else |
536 | s = start; | 545 | s = start; |
537 | 546 | ||
538 | automaton_state_traverse (s, marks, &count, | 547 | automaton_state_traverse (s, |
539 | check, check_cls, | 548 | marks, |
540 | action, action_cls); | 549 | &count, |
550 | check, | ||
551 | check_cls, | ||
552 | action, | ||
553 | action_cls); | ||
541 | } | 554 | } |
542 | 555 | ||
543 | 556 | ||
@@ -582,7 +595,6 @@ struct StringBuffer | |||
582 | * most likely due to increased cache misses. | 595 | * most likely due to increased cache misses. |
583 | */ | 596 | */ |
584 | int16_t synced; | 597 | int16_t synced; |
585 | |||
586 | }; | 598 | }; |
587 | 599 | ||
588 | 600 | ||
@@ -595,14 +607,11 @@ struct StringBuffer | |||
595 | * @return 0 if the strings are the same or both NULL, 1 or -1 if not. | 607 | * @return 0 if the strings are the same or both NULL, 1 or -1 if not. |
596 | */ | 608 | */ |
597 | static int | 609 | static int |
598 | sb_nullstrcmp (const struct StringBuffer *s1, | 610 | sb_nullstrcmp (const struct StringBuffer *s1, const struct StringBuffer *s2) |
599 | const struct StringBuffer *s2) | ||
600 | { | 611 | { |
601 | if ( (GNUNET_YES == s1->null_flag) && | 612 | if ((GNUNET_YES == s1->null_flag) && (GNUNET_YES == s2->null_flag)) |
602 | (GNUNET_YES == s2->null_flag) ) | ||
603 | return 0; | 613 | return 0; |
604 | if ( (GNUNET_YES == s1->null_flag) || | 614 | if ((GNUNET_YES == s1->null_flag) || (GNUNET_YES == s2->null_flag)) |
605 | (GNUNET_YES == s2->null_flag) ) | ||
606 | return -1; | 615 | return -1; |
607 | if (s1->slen != s2->slen) | 616 | if (s1->slen != s2->slen) |
608 | return -1; | 617 | return -1; |
@@ -621,8 +630,7 @@ sb_nullstrcmp (const struct StringBuffer *s1, | |||
621 | * @return 0 if the strings are the same, 1 or -1 if not. | 630 | * @return 0 if the strings are the same, 1 or -1 if not. |
622 | */ | 631 | */ |
623 | static int | 632 | static int |
624 | sb_strcmp (const struct StringBuffer *s1, | 633 | sb_strcmp (const struct StringBuffer *s1, const struct StringBuffer *s2) |
625 | const struct StringBuffer *s2) | ||
626 | { | 634 | { |
627 | if (s1->slen != s2->slen) | 635 | if (s1->slen != s2->slen) |
628 | return -1; | 636 | return -1; |
@@ -640,8 +648,7 @@ sb_strcmp (const struct StringBuffer *s1, | |||
640 | * @param nlen target length for the buffer, must be at least ret->slen | 648 | * @param nlen target length for the buffer, must be at least ret->slen |
641 | */ | 649 | */ |
642 | static void | 650 | static void |
643 | sb_realloc (struct StringBuffer *ret, | 651 | sb_realloc (struct StringBuffer *ret, size_t nlen) |
644 | size_t nlen) | ||
645 | { | 652 | { |
646 | char *old; | 653 | char *old; |
647 | 654 | ||
@@ -649,9 +656,7 @@ sb_realloc (struct StringBuffer *ret, | |||
649 | old = ret->abuf; | 656 | old = ret->abuf; |
650 | ret->abuf = GNUNET_malloc (nlen); | 657 | ret->abuf = GNUNET_malloc (nlen); |
651 | ret->blen = nlen; | 658 | ret->blen = nlen; |
652 | GNUNET_memcpy (ret->abuf, | 659 | GNUNET_memcpy (ret->abuf, ret->sbuf, ret->slen); |
653 | ret->sbuf, | ||
654 | ret->slen); | ||
655 | ret->sbuf = ret->abuf; | 660 | ret->sbuf = ret->abuf; |
656 | GNUNET_free_non_null (old); | 661 | GNUNET_free_non_null (old); |
657 | } | 662 | } |
@@ -664,17 +669,14 @@ sb_realloc (struct StringBuffer *ret, | |||
664 | * @param sarg string to append | 669 | * @param sarg string to append |
665 | */ | 670 | */ |
666 | static void | 671 | static void |
667 | sb_append (struct StringBuffer *ret, | 672 | sb_append (struct StringBuffer *ret, const struct StringBuffer *sarg) |
668 | const struct StringBuffer *sarg) | ||
669 | { | 673 | { |
670 | if (GNUNET_YES == ret->null_flag) | 674 | if (GNUNET_YES == ret->null_flag) |
671 | ret->slen = 0; | 675 | ret->slen = 0; |
672 | ret->null_flag = GNUNET_NO; | 676 | ret->null_flag = GNUNET_NO; |
673 | if (ret->blen < sarg->slen + ret->slen) | 677 | if (ret->blen < sarg->slen + ret->slen) |
674 | sb_realloc (ret, ret->blen + sarg->slen + 128); | 678 | sb_realloc (ret, ret->blen + sarg->slen + 128); |
675 | GNUNET_memcpy (&ret->sbuf[ret->slen], | 679 | GNUNET_memcpy (&ret->sbuf[ret->slen], sarg->sbuf, sarg->slen); |
676 | sarg->sbuf, | ||
677 | sarg->slen); | ||
678 | ret->slen += sarg->slen; | 680 | ret->slen += sarg->slen; |
679 | } | 681 | } |
680 | 682 | ||
@@ -686,8 +688,7 @@ sb_append (struct StringBuffer *ret, | |||
686 | * @param cstr string to append | 688 | * @param cstr string to append |
687 | */ | 689 | */ |
688 | static void | 690 | static void |
689 | sb_append_cstr (struct StringBuffer *ret, | 691 | sb_append_cstr (struct StringBuffer *ret, const char *cstr) |
690 | const char *cstr) | ||
691 | { | 692 | { |
692 | size_t cstr_len = strlen (cstr); | 693 | size_t cstr_len = strlen (cstr); |
693 | 694 | ||
@@ -696,9 +697,7 @@ sb_append_cstr (struct StringBuffer *ret, | |||
696 | ret->null_flag = GNUNET_NO; | 697 | ret->null_flag = GNUNET_NO; |
697 | if (ret->blen < cstr_len + ret->slen) | 698 | if (ret->blen < cstr_len + ret->slen) |
698 | sb_realloc (ret, ret->blen + cstr_len + 128); | 699 | sb_realloc (ret, ret->blen + cstr_len + 128); |
699 | GNUNET_memcpy (&ret->sbuf[ret->slen], | 700 | GNUNET_memcpy (&ret->sbuf[ret->slen], cstr, cstr_len); |
700 | cstr, | ||
701 | cstr_len); | ||
702 | ret->slen += cstr_len; | 701 | ret->slen += cstr_len; |
703 | } | 702 | } |
704 | 703 | ||
@@ -714,9 +713,7 @@ sb_append_cstr (struct StringBuffer *ret, | |||
714 | * @param extra_chars how long will the result be, in addition to 'sarg' length | 713 | * @param extra_chars how long will the result be, in addition to 'sarg' length |
715 | */ | 714 | */ |
716 | static void | 715 | static void |
717 | sb_wrap (struct StringBuffer *ret, | 716 | sb_wrap (struct StringBuffer *ret, const char *format, size_t extra_chars) |
718 | const char *format, | ||
719 | size_t extra_chars) | ||
720 | { | 717 | { |
721 | char *temp; | 718 | char *temp; |
722 | 719 | ||
@@ -725,10 +722,10 @@ sb_wrap (struct StringBuffer *ret, | |||
725 | ret->null_flag = GNUNET_NO; | 722 | ret->null_flag = GNUNET_NO; |
726 | temp = GNUNET_malloc (ret->slen + extra_chars + 1); | 723 | temp = GNUNET_malloc (ret->slen + extra_chars + 1); |
727 | GNUNET_snprintf (temp, | 724 | GNUNET_snprintf (temp, |
728 | ret->slen + extra_chars + 1, | 725 | ret->slen + extra_chars + 1, |
729 | format, | 726 | format, |
730 | (int) ret->slen, | 727 | (int) ret->slen, |
731 | ret->sbuf); | 728 | ret->sbuf); |
732 | GNUNET_free_non_null (ret->abuf); | 729 | GNUNET_free_non_null (ret->abuf); |
733 | ret->abuf = temp; | 730 | ret->abuf = temp; |
734 | ret->sbuf = temp; | 731 | ret->sbuf = temp; |
@@ -748,21 +745,16 @@ sb_wrap (struct StringBuffer *ret, | |||
748 | */ | 745 | */ |
749 | static void | 746 | static void |
750 | sb_printf1 (struct StringBuffer *ret, | 747 | sb_printf1 (struct StringBuffer *ret, |
751 | const char *format, | 748 | const char *format, |
752 | size_t extra_chars, | 749 | size_t extra_chars, |
753 | const struct StringBuffer *sarg) | 750 | const struct StringBuffer *sarg) |
754 | { | 751 | { |
755 | if (ret->blen < sarg->slen + extra_chars + 1) | 752 | if (ret->blen < sarg->slen + extra_chars + 1) |
756 | sb_realloc (ret, | 753 | sb_realloc (ret, sarg->slen + extra_chars + 1); |
757 | sarg->slen + extra_chars + 1); | ||
758 | ret->null_flag = GNUNET_NO; | 754 | ret->null_flag = GNUNET_NO; |
759 | ret->sbuf = ret->abuf; | 755 | ret->sbuf = ret->abuf; |
760 | ret->slen = sarg->slen + extra_chars; | 756 | ret->slen = sarg->slen + extra_chars; |
761 | GNUNET_snprintf (ret->sbuf, | 757 | GNUNET_snprintf (ret->sbuf, ret->blen, format, (int) sarg->slen, sarg->sbuf); |
762 | ret->blen, | ||
763 | format, | ||
764 | (int) sarg->slen, | ||
765 | sarg->sbuf); | ||
766 | } | 758 | } |
767 | 759 | ||
768 | 760 | ||
@@ -777,24 +769,23 @@ sb_printf1 (struct StringBuffer *ret, | |||
777 | */ | 769 | */ |
778 | static void | 770 | static void |
779 | sb_printf2 (struct StringBuffer *ret, | 771 | sb_printf2 (struct StringBuffer *ret, |
780 | const char *format, | 772 | const char *format, |
781 | size_t extra_chars, | 773 | size_t extra_chars, |
782 | const struct StringBuffer *sarg1, | 774 | const struct StringBuffer *sarg1, |
783 | const struct StringBuffer *sarg2) | 775 | const struct StringBuffer *sarg2) |
784 | { | 776 | { |
785 | if (ret->blen < sarg1->slen + sarg2->slen + extra_chars + 1) | 777 | if (ret->blen < sarg1->slen + sarg2->slen + extra_chars + 1) |
786 | sb_realloc (ret, | 778 | sb_realloc (ret, sarg1->slen + sarg2->slen + extra_chars + 1); |
787 | sarg1->slen + sarg2->slen + extra_chars + 1); | ||
788 | ret->null_flag = GNUNET_NO; | 779 | ret->null_flag = GNUNET_NO; |
789 | ret->slen = sarg1->slen + sarg2->slen + extra_chars; | 780 | ret->slen = sarg1->slen + sarg2->slen + extra_chars; |
790 | ret->sbuf = ret->abuf; | 781 | ret->sbuf = ret->abuf; |
791 | GNUNET_snprintf (ret->sbuf, | 782 | GNUNET_snprintf (ret->sbuf, |
792 | ret->blen, | 783 | ret->blen, |
793 | format, | 784 | format, |
794 | (int) sarg1->slen, | 785 | (int) sarg1->slen, |
795 | sarg1->sbuf, | 786 | sarg1->sbuf, |
796 | (int) sarg2->slen, | 787 | (int) sarg2->slen, |
797 | sarg2->sbuf); | 788 | sarg2->sbuf); |
798 | } | 789 | } |
799 | 790 | ||
800 | 791 | ||
@@ -811,27 +802,26 @@ sb_printf2 (struct StringBuffer *ret, | |||
811 | */ | 802 | */ |
812 | static void | 803 | static void |
813 | sb_printf3 (struct StringBuffer *ret, | 804 | sb_printf3 (struct StringBuffer *ret, |
814 | const char *format, | 805 | const char *format, |
815 | size_t extra_chars, | 806 | size_t extra_chars, |
816 | const struct StringBuffer *sarg1, | 807 | const struct StringBuffer *sarg1, |
817 | const struct StringBuffer *sarg2, | 808 | const struct StringBuffer *sarg2, |
818 | const struct StringBuffer *sarg3) | 809 | const struct StringBuffer *sarg3) |
819 | { | 810 | { |
820 | if (ret->blen < sarg1->slen + sarg2->slen + sarg3->slen + extra_chars + 1) | 811 | if (ret->blen < sarg1->slen + sarg2->slen + sarg3->slen + extra_chars + 1) |
821 | sb_realloc (ret, | 812 | sb_realloc (ret, sarg1->slen + sarg2->slen + sarg3->slen + extra_chars + 1); |
822 | sarg1->slen + sarg2->slen + sarg3->slen + extra_chars + 1); | ||
823 | ret->null_flag = GNUNET_NO; | 813 | ret->null_flag = GNUNET_NO; |
824 | ret->slen = sarg1->slen + sarg2->slen + sarg3->slen + extra_chars; | 814 | ret->slen = sarg1->slen + sarg2->slen + sarg3->slen + extra_chars; |
825 | ret->sbuf = ret->abuf; | 815 | ret->sbuf = ret->abuf; |
826 | GNUNET_snprintf (ret->sbuf, | 816 | GNUNET_snprintf (ret->sbuf, |
827 | ret->blen, | 817 | ret->blen, |
828 | format, | 818 | format, |
829 | (int) sarg1->slen, | 819 | (int) sarg1->slen, |
830 | sarg1->sbuf, | 820 | sarg1->sbuf, |
831 | (int) sarg2->slen, | 821 | (int) sarg2->slen, |
832 | sarg2->sbuf, | 822 | sarg2->sbuf, |
833 | (int) sarg3->slen, | 823 | (int) sarg3->slen, |
834 | sarg3->sbuf); | 824 | sarg3->sbuf); |
835 | } | 825 | } |
836 | 826 | ||
837 | 827 | ||
@@ -844,12 +834,10 @@ sb_printf3 (struct StringBuffer *ret, | |||
844 | static void | 834 | static void |
845 | sb_free (struct StringBuffer *sb) | 835 | sb_free (struct StringBuffer *sb) |
846 | { | 836 | { |
847 | GNUNET_array_grow (sb->abuf, | 837 | GNUNET_array_grow (sb->abuf, sb->blen, 0); |
848 | sb->blen, | ||
849 | 0); | ||
850 | sb->slen = 0; | 838 | sb->slen = 0; |
851 | sb->sbuf = NULL; | 839 | sb->sbuf = NULL; |
852 | sb->null_flag= GNUNET_YES; | 840 | sb->null_flag = GNUNET_YES; |
853 | } | 841 | } |
854 | 842 | ||
855 | 843 | ||
@@ -860,8 +848,7 @@ sb_free (struct StringBuffer *sb) | |||
860 | * @param out output string | 848 | * @param out output string |
861 | */ | 849 | */ |
862 | static void | 850 | static void |
863 | sb_strdup (struct StringBuffer *out, | 851 | sb_strdup (struct StringBuffer *out, const struct StringBuffer *in) |
864 | const struct StringBuffer *in) | ||
865 | 852 | ||
866 | { | 853 | { |
867 | out->null_flag = in->null_flag; | 854 | out->null_flag = in->null_flag; |
@@ -869,9 +856,7 @@ sb_strdup (struct StringBuffer *out, | |||
869 | return; | 856 | return; |
870 | if (out->blen < in->slen) | 857 | if (out->blen < in->slen) |
871 | { | 858 | { |
872 | GNUNET_array_grow (out->abuf, | 859 | GNUNET_array_grow (out->abuf, out->blen, in->slen); |
873 | out->blen, | ||
874 | in->slen); | ||
875 | } | 860 | } |
876 | out->sbuf = out->abuf; | 861 | out->sbuf = out->abuf; |
877 | out->slen = in->slen; | 862 | out->slen = in->slen; |
@@ -886,8 +871,7 @@ sb_strdup (struct StringBuffer *out, | |||
886 | * @param out output string | 871 | * @param out output string |
887 | */ | 872 | */ |
888 | static void | 873 | static void |
889 | sb_strdup_cstr (struct StringBuffer *out, | 874 | sb_strdup_cstr (struct StringBuffer *out, const char *cstr) |
890 | const char *cstr) | ||
891 | { | 875 | { |
892 | if (NULL == cstr) | 876 | if (NULL == cstr) |
893 | { | 877 | { |
@@ -898,9 +882,7 @@ sb_strdup_cstr (struct StringBuffer *out, | |||
898 | out->slen = strlen (cstr); | 882 | out->slen = strlen (cstr); |
899 | if (out->blen < out->slen) | 883 | if (out->blen < out->slen) |
900 | { | 884 | { |
901 | GNUNET_array_grow (out->abuf, | 885 | GNUNET_array_grow (out->abuf, out->blen, out->slen); |
902 | out->blen, | ||
903 | out->slen); | ||
904 | } | 886 | } |
905 | out->sbuf = out->abuf; | 887 | out->sbuf = out->abuf; |
906 | GNUNET_memcpy (out->sbuf, cstr, out->slen); | 888 | GNUNET_memcpy (out->sbuf, cstr, out->slen); |
@@ -942,8 +924,7 @@ needs_parentheses (const struct StringBuffer *str) | |||
942 | return GNUNET_YES; | 924 | return GNUNET_YES; |
943 | } | 925 | } |
944 | /* while '(' before ')', count opening parens */ | 926 | /* while '(' before ')', count opening parens */ |
945 | while ( (NULL != (op = memchr (pos, '(', end - pos))) && | 927 | while ((NULL != (op = memchr (pos, '(', end - pos))) && (op < cl)) |
946 | (op < cl) ) | ||
947 | { | 928 | { |
948 | cnt++; | 929 | cnt++; |
949 | pos = op + 1; | 930 | pos = op + 1; |
@@ -979,10 +960,8 @@ remove_parentheses (struct StringBuffer *str) | |||
979 | if (0) | 960 | if (0) |
980 | return; | 961 | return; |
981 | sbuf = str->sbuf; | 962 | sbuf = str->sbuf; |
982 | if ( (GNUNET_YES == str->null_flag) || | 963 | if ((GNUNET_YES == str->null_flag) || (1 >= (slen = str->slen)) || |
983 | (1 >= (slen = str->slen)) || | 964 | ('(' != str->sbuf[0]) || (')' != str->sbuf[slen - 1])) |
984 | ('(' != str->sbuf[0]) || | ||
985 | (')' != str->sbuf[slen - 1]) ) | ||
986 | return; | 965 | return; |
987 | cnt = 0; | 966 | cnt = 0; |
988 | pos = &sbuf[1]; | 967 | pos = &sbuf[1]; |
@@ -991,19 +970,16 @@ remove_parentheses (struct StringBuffer *str) | |||
991 | cp = memchr (pos, ')', end - pos); | 970 | cp = memchr (pos, ')', end - pos); |
992 | while (NULL != cp) | 971 | while (NULL != cp) |
993 | { | 972 | { |
994 | while ( (NULL != op) && | 973 | while ((NULL != op) && (op < cp)) |
995 | (op < cp) ) | ||
996 | { | 974 | { |
997 | cnt++; | 975 | cnt++; |
998 | pos = op + 1; | 976 | pos = op + 1; |
999 | op = memchr (pos, '(', end - pos); | 977 | op = memchr (pos, '(', end - pos); |
1000 | } | 978 | } |
1001 | while ( (NULL != cp) && | 979 | while ((NULL != cp) && ((NULL == op) || (cp < op))) |
1002 | ( (NULL == op) || | ||
1003 | (cp < op) ) ) | ||
1004 | { | 980 | { |
1005 | if (0 == cnt) | 981 | if (0 == cnt) |
1006 | return; /* can't strip parens */ | 982 | return; /* can't strip parens */ |
1007 | cnt--; | 983 | cnt--; |
1008 | pos = cp + 1; | 984 | pos = cp + 1; |
1009 | cp = memchr (pos, ')', end - pos); | 985 | cp = memchr (pos, ')', end - pos); |
@@ -1030,12 +1006,9 @@ remove_parentheses (struct StringBuffer *str) | |||
1030 | static int | 1006 | static int |
1031 | has_epsilon (const struct StringBuffer *str) | 1007 | has_epsilon (const struct StringBuffer *str) |
1032 | { | 1008 | { |
1033 | return | 1009 | return (GNUNET_YES != str->null_flag) && (0 < str->slen) && |
1034 | (GNUNET_YES != str->null_flag) && | 1010 | ('(' == str->sbuf[0]) && ('|' == str->sbuf[1]) && |
1035 | (0 < str->slen) && | 1011 | (')' == str->sbuf[str->slen - 1]); |
1036 | ('(' == str->sbuf[0]) && | ||
1037 | ('|' == str->sbuf[1]) && | ||
1038 | (')' == str->sbuf[str->slen - 1]); | ||
1039 | } | 1012 | } |
1040 | 1013 | ||
1041 | 1014 | ||
@@ -1049,25 +1022,20 @@ has_epsilon (const struct StringBuffer *str) | |||
1049 | * epsilon could be found, NULL if 'str' was NULL | 1022 | * epsilon could be found, NULL if 'str' was NULL |
1050 | */ | 1023 | */ |
1051 | static void | 1024 | static void |
1052 | remove_epsilon (const struct StringBuffer *str, | 1025 | remove_epsilon (const struct StringBuffer *str, struct StringBuffer *ret) |
1053 | struct StringBuffer *ret) | ||
1054 | { | 1026 | { |
1055 | if (GNUNET_YES == str->null_flag) | 1027 | if (GNUNET_YES == str->null_flag) |
1056 | { | 1028 | { |
1057 | ret->null_flag = GNUNET_YES; | 1029 | ret->null_flag = GNUNET_YES; |
1058 | return; | 1030 | return; |
1059 | } | 1031 | } |
1060 | if ( (str->slen > 1) && | 1032 | if ((str->slen > 1) && ('(' == str->sbuf[0]) && ('|' == str->sbuf[1]) && |
1061 | ('(' == str->sbuf[0]) && | 1033 | (')' == str->sbuf[str->slen - 1])) |
1062 | ('|' == str->sbuf[1]) && | ||
1063 | (')' == str->sbuf[str->slen - 1]) ) | ||
1064 | { | 1034 | { |
1065 | /* remove epsilon */ | 1035 | /* remove epsilon */ |
1066 | if (ret->blen < str->slen - 3) | 1036 | if (ret->blen < str->slen - 3) |
1067 | { | 1037 | { |
1068 | GNUNET_array_grow (ret->abuf, | 1038 | GNUNET_array_grow (ret->abuf, ret->blen, str->slen - 3); |
1069 | ret->blen, | ||
1070 | str->slen - 3); | ||
1071 | } | 1039 | } |
1072 | ret->sbuf = ret->abuf; | 1040 | ret->sbuf = ret->abuf; |
1073 | ret->slen = str->slen - 3; | 1041 | ret->slen = str->slen - 3; |
@@ -1089,13 +1057,12 @@ remove_epsilon (const struct StringBuffer *str, | |||
1089 | */ | 1057 | */ |
1090 | static int | 1058 | static int |
1091 | sb_strncmp (const struct StringBuffer *str1, | 1059 | sb_strncmp (const struct StringBuffer *str1, |
1092 | const struct StringBuffer *str2, size_t n) | 1060 | const struct StringBuffer *str2, |
1061 | size_t n) | ||
1093 | { | 1062 | { |
1094 | size_t max; | 1063 | size_t max; |
1095 | 1064 | ||
1096 | if ( (str1->slen != str2->slen) && | 1065 | if ((str1->slen != str2->slen) && ((str1->slen < n) || (str2->slen < n))) |
1097 | ( (str1->slen < n) || | ||
1098 | (str2->slen < n) ) ) | ||
1099 | return -1; | 1066 | return -1; |
1100 | max = GNUNET_MAX (str1->slen, str2->slen); | 1067 | max = GNUNET_MAX (str1->slen, str2->slen); |
1101 | if (max > n) | 1068 | if (max > n) |
@@ -1114,8 +1081,7 @@ sb_strncmp (const struct StringBuffer *str1, | |||
1114 | * @return -1 if any of the strings is NULL, 0 if equal, non 0 otherwise | 1081 | * @return -1 if any of the strings is NULL, 0 if equal, non 0 otherwise |
1115 | */ | 1082 | */ |
1116 | static int | 1083 | static int |
1117 | sb_strncmp_cstr (const struct StringBuffer *str1, | 1084 | sb_strncmp_cstr (const struct StringBuffer *str1, const char *str2, size_t n) |
1118 | const char *str2, size_t n) | ||
1119 | { | 1085 | { |
1120 | if (str1->slen < n) | 1086 | if (str1->slen < n) |
1121 | return -1; | 1087 | return -1; |
@@ -1131,8 +1097,7 @@ sb_strncmp_cstr (const struct StringBuffer *str1, | |||
1131 | * @param n desired target length | 1097 | * @param n desired target length |
1132 | */ | 1098 | */ |
1133 | static void | 1099 | static void |
1134 | sb_init (struct StringBuffer *sb, | 1100 | sb_init (struct StringBuffer *sb, size_t n) |
1135 | size_t n) | ||
1136 | { | 1101 | { |
1137 | sb->null_flag = GNUNET_NO; | 1102 | sb->null_flag = GNUNET_NO; |
1138 | sb->abuf = sb->sbuf = (0 == n) ? NULL : GNUNET_malloc (n); | 1103 | sb->abuf = sb->sbuf = (0 == n) ? NULL : GNUNET_malloc (n); |
@@ -1152,12 +1117,11 @@ sb_init (struct StringBuffer *sb, | |||
1152 | */ | 1117 | */ |
1153 | static int | 1118 | static int |
1154 | sb_strkcmp (const struct StringBuffer *str1, | 1119 | sb_strkcmp (const struct StringBuffer *str1, |
1155 | const struct StringBuffer *str2, size_t k) | 1120 | const struct StringBuffer *str2, |
1121 | size_t k) | ||
1156 | { | 1122 | { |
1157 | if ( (GNUNET_YES == str1->null_flag) || | 1123 | if ((GNUNET_YES == str1->null_flag) || (GNUNET_YES == str2->null_flag) || |
1158 | (GNUNET_YES == str2->null_flag) || | 1124 | (k > str1->slen) || (str1->slen - k != str2->slen)) |
1159 | (k > str1->slen) || | ||
1160 | (str1->slen - k != str2->slen) ) | ||
1161 | return -1; | 1125 | return -1; |
1162 | return memcmp (&str1->sbuf[k], str2->sbuf, str2->slen); | 1126 | return memcmp (&str1->sbuf[k], str2->sbuf, str2->slen); |
1163 | } | 1127 | } |
@@ -1172,7 +1136,8 @@ sb_strkcmp (const struct StringBuffer *str1, | |||
1172 | * @param s current state. | 1136 | * @param s current state. |
1173 | */ | 1137 | */ |
1174 | static void | 1138 | static void |
1175 | number_states (void *cls, const unsigned int count, | 1139 | number_states (void *cls, |
1140 | const unsigned int count, | ||
1176 | struct REGEX_INTERNAL_State *s) | 1141 | struct REGEX_INTERNAL_State *s) |
1177 | { | 1142 | { |
1178 | struct REGEX_INTERNAL_State **states = cls; | 1143 | struct REGEX_INTERNAL_State **states = cls; |
@@ -1183,10 +1148,9 @@ number_states (void *cls, const unsigned int count, | |||
1183 | } | 1148 | } |
1184 | 1149 | ||
1185 | 1150 | ||
1186 | 1151 | #define PRIS(a) \ | |
1187 | #define PRIS(a) \ | ||
1188 | ((GNUNET_YES == a.null_flag) ? 6 : (int) a.slen), \ | 1152 | ((GNUNET_YES == a.null_flag) ? 6 : (int) a.slen), \ |
1189 | ((GNUNET_YES == a.null_flag) ? "(null)" : a.sbuf) | 1153 | ((GNUNET_YES == a.null_flag) ? "(null)" : a.sbuf) |
1190 | 1154 | ||
1191 | 1155 | ||
1192 | /** | 1156 | /** |
@@ -1205,12 +1169,12 @@ number_states (void *cls, const unsigned int count, | |||
1205 | */ | 1169 | */ |
1206 | static void | 1170 | static void |
1207 | automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | 1171 | automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, |
1208 | const struct StringBuffer *R_last_ik, | 1172 | const struct StringBuffer *R_last_ik, |
1209 | const struct StringBuffer *R_last_kk, | 1173 | const struct StringBuffer *R_last_kk, |
1210 | const struct StringBuffer *R_last_kj, | 1174 | const struct StringBuffer *R_last_kj, |
1211 | struct StringBuffer *R_cur_ij, | 1175 | struct StringBuffer *R_cur_ij, |
1212 | struct StringBuffer *R_cur_l, | 1176 | struct StringBuffer *R_cur_l, |
1213 | struct StringBuffer *R_cur_r) | 1177 | struct StringBuffer *R_cur_r) |
1214 | { | 1178 | { |
1215 | struct StringBuffer R_temp_ij; | 1179 | struct StringBuffer R_temp_ij; |
1216 | struct StringBuffer R_temp_ik; | 1180 | struct StringBuffer R_temp_ik; |
@@ -1235,9 +1199,9 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1235 | * R_cur_r == R^{(k-1)}_{ik} ( R^{(k-1)}_{kk} )^* R^{(k-1)}_{kj} | 1199 | * R_cur_r == R^{(k-1)}_{ik} ( R^{(k-1)}_{kk} )^* R^{(k-1)}_{kj} |
1236 | */ | 1200 | */ |
1237 | 1201 | ||
1238 | if ( (GNUNET_YES == R_last_ij->null_flag) && | 1202 | if ((GNUNET_YES == R_last_ij->null_flag) && |
1239 | ( (GNUNET_YES == R_last_ik->null_flag) || | 1203 | ((GNUNET_YES == R_last_ik->null_flag) || |
1240 | (GNUNET_YES == R_last_kj->null_flag))) | 1204 | (GNUNET_YES == R_last_kj->null_flag))) |
1241 | { | 1205 | { |
1242 | /* R^{(k)}_{ij} = N | N */ | 1206 | /* R^{(k)}_{ij} = N | N */ |
1243 | R_cur_ij->null_flag = GNUNET_YES; | 1207 | R_cur_ij->null_flag = GNUNET_YES; |
@@ -1245,8 +1209,8 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1245 | return; | 1209 | return; |
1246 | } | 1210 | } |
1247 | 1211 | ||
1248 | if ( (GNUNET_YES == R_last_ik->null_flag) || | 1212 | if ((GNUNET_YES == R_last_ik->null_flag) || |
1249 | (GNUNET_YES == R_last_kj->null_flag) ) | 1213 | (GNUNET_YES == R_last_kj->null_flag)) |
1250 | { | 1214 | { |
1251 | /* R^{(k)}_{ij} = R^{(k-1)}_{ij} | N */ | 1215 | /* R^{(k)}_{ij} = R^{(k-1)}_{ij} | N */ |
1252 | if (GNUNET_YES == R_last_ij->synced) | 1216 | if (GNUNET_YES == R_last_ij->synced) |
@@ -1299,9 +1263,9 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1299 | remove_epsilon (R_last_ij, &R_temp_ij); | 1263 | remove_epsilon (R_last_ij, &R_temp_ij); |
1300 | remove_parentheses (&R_temp_ij); | 1264 | remove_parentheses (&R_temp_ij); |
1301 | 1265 | ||
1302 | if ( (0 == sb_strcmp (&R_temp_ij, &R_temp_ik)) && | 1266 | if ((0 == sb_strcmp (&R_temp_ij, &R_temp_ik)) && |
1303 | (0 == sb_strcmp (&R_temp_ik, &R_temp_kk)) && | 1267 | (0 == sb_strcmp (&R_temp_ik, &R_temp_kk)) && |
1304 | (0 == sb_strcmp (&R_temp_kk, &R_temp_kj)) ) | 1268 | (0 == sb_strcmp (&R_temp_kk, &R_temp_kj))) |
1305 | { | 1269 | { |
1306 | if (0 == R_temp_ij.slen) | 1270 | if (0 == R_temp_ij.slen) |
1307 | { | 1271 | { |
@@ -1340,7 +1304,8 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1340 | sb_printf1 (R_cur_r, "%.*s+", 1, &R_temp_ij); | 1304 | sb_printf1 (R_cur_r, "%.*s+", 1, &R_temp_ij); |
1341 | } | 1305 | } |
1342 | } | 1306 | } |
1343 | else if ( (0 == ij_ik_cmp) && (0 == clean_kk_kj_cmp) && (0 != clean_ik_kk_cmp) ) | 1307 | else if ((0 == ij_ik_cmp) && (0 == clean_kk_kj_cmp) && |
1308 | (0 != clean_ik_kk_cmp)) | ||
1344 | { | 1309 | { |
1345 | /* a|ab*b = ab* */ | 1310 | /* a|ab*b = ab* */ |
1346 | if (0 == R_last_kk->slen) | 1311 | if (0 == R_last_kk->slen) |
@@ -1351,7 +1316,8 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1351 | sb_printf2 (R_cur_r, "%.*s%.*s*", 1, R_last_ij, R_last_kk); | 1316 | sb_printf2 (R_cur_r, "%.*s%.*s*", 1, R_last_ij, R_last_kk); |
1352 | R_cur_l->null_flag = GNUNET_YES; | 1317 | R_cur_l->null_flag = GNUNET_YES; |
1353 | } | 1318 | } |
1354 | else if ( (0 == ij_kj_cmp) && (0 == clean_ik_kk_cmp) && (0 != clean_kk_kj_cmp)) | 1319 | else if ((0 == ij_kj_cmp) && (0 == clean_ik_kk_cmp) && |
1320 | (0 != clean_kk_kj_cmp)) | ||
1355 | { | 1321 | { |
1356 | /* a|bb*a = b*a */ | 1322 | /* a|bb*a = b*a */ |
1357 | if (R_last_kk->slen < 1) | 1323 | if (R_last_kk->slen < 1) |
@@ -1365,8 +1331,8 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1365 | 1331 | ||
1366 | R_cur_l->null_flag = GNUNET_YES; | 1332 | R_cur_l->null_flag = GNUNET_YES; |
1367 | } | 1333 | } |
1368 | else if ( (0 == ij_ik_cmp) && (0 == kk_kj_cmp) && (! has_epsilon (R_last_ij)) && | 1334 | else if ((0 == ij_ik_cmp) && (0 == kk_kj_cmp) && |
1369 | has_epsilon (R_last_kk)) | 1335 | (! has_epsilon (R_last_ij)) && has_epsilon (R_last_kk)) |
1370 | { | 1336 | { |
1371 | /* a|a(e|b)*(e|b) = a|ab* = a|a|ab|abb|abbb|... = ab* */ | 1337 | /* a|a(e|b)*(e|b) = a|ab* = a|a|ab|abb|abbb|... = ab* */ |
1372 | if (needs_parentheses (&R_temp_kk)) | 1338 | if (needs_parentheses (&R_temp_kk)) |
@@ -1375,8 +1341,8 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1375 | sb_printf2 (R_cur_r, "%.*s%.*s*", 1, R_last_ij, &R_temp_kk); | 1341 | sb_printf2 (R_cur_r, "%.*s%.*s*", 1, R_last_ij, &R_temp_kk); |
1376 | R_cur_l->null_flag = GNUNET_YES; | 1342 | R_cur_l->null_flag = GNUNET_YES; |
1377 | } | 1343 | } |
1378 | else if ( (0 == ij_kj_cmp) && (0 == ik_kk_cmp) && (! has_epsilon (R_last_ij)) && | 1344 | else if ((0 == ij_kj_cmp) && (0 == ik_kk_cmp) && |
1379 | has_epsilon (R_last_kk)) | 1345 | (! has_epsilon (R_last_ij)) && has_epsilon (R_last_kk)) |
1380 | { | 1346 | { |
1381 | /* a|(e|b)(e|b)*a = a|b*a = a|a|ba|bba|bbba|... = b*a */ | 1347 | /* a|(e|b)(e|b)*a = a|b*a = a|a|ba|bba|bbba|... = b*a */ |
1382 | if (needs_parentheses (&R_temp_kk)) | 1348 | if (needs_parentheses (&R_temp_kk)) |
@@ -1403,15 +1369,12 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1403 | length = R_temp_kk.slen - R_last_ik->slen; | 1369 | length = R_temp_kk.slen - R_last_ik->slen; |
1404 | 1370 | ||
1405 | /* a(ba)*bx = (ab)+x */ | 1371 | /* a(ba)*bx = (ab)+x */ |
1406 | if ( (length > 0) && | 1372 | if ((length > 0) && (GNUNET_YES != R_last_kk->null_flag) && |
1407 | (GNUNET_YES != R_last_kk->null_flag) && | 1373 | (0 < R_last_kk->slen) && (GNUNET_YES != R_last_kj->null_flag) && |
1408 | (0 < R_last_kk->slen) && | 1374 | (0 < R_last_kj->slen) && (GNUNET_YES != R_last_ik->null_flag) && |
1409 | (GNUNET_YES != R_last_kj->null_flag) && | 1375 | (0 < R_last_ik->slen) && |
1410 | (0 < R_last_kj->slen) && | 1376 | (0 == sb_strkcmp (&R_temp_kk, R_last_ik, length)) && |
1411 | (GNUNET_YES != R_last_ik->null_flag) && | 1377 | (0 == sb_strncmp (&R_temp_kk, R_last_kj, length))) |
1412 | (0 < R_last_ik->slen) && | ||
1413 | (0 == sb_strkcmp (&R_temp_kk, R_last_ik, length)) && | ||
1414 | (0 == sb_strncmp (&R_temp_kk, R_last_kj, length)) ) | ||
1415 | { | 1378 | { |
1416 | struct StringBuffer temp_a; | 1379 | struct StringBuffer temp_a; |
1417 | struct StringBuffer temp_b; | 1380 | struct StringBuffer temp_b; |
@@ -1430,9 +1393,8 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1430 | temp_b.slen = length_r; | 1393 | temp_b.slen = length_r; |
1431 | 1394 | ||
1432 | /* e|(ab)+ = (ab)* */ | 1395 | /* e|(ab)+ = (ab)* */ |
1433 | if ( (GNUNET_YES != R_cur_l->null_flag) && | 1396 | if ((GNUNET_YES != R_cur_l->null_flag) && (0 == R_cur_l->slen) && |
1434 | (0 == R_cur_l->slen) && | 1397 | (0 == temp_b.slen)) |
1435 | (0 == temp_b.slen) ) | ||
1436 | { | 1398 | { |
1437 | sb_printf2 (R_cur_r, "(%.*s%.*s)*", 3, R_last_ik, &temp_a); | 1399 | sb_printf2 (R_cur_r, "(%.*s%.*s)*", 3, R_last_ik, &temp_a); |
1438 | sb_free (R_cur_l); | 1400 | sb_free (R_cur_l); |
@@ -1460,9 +1422,8 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1460 | sb_printf1 (R_cur_r, "%.*s*", 1, &R_temp_kk); | 1422 | sb_printf1 (R_cur_r, "%.*s*", 1, &R_temp_kk); |
1461 | } | 1423 | } |
1462 | /* aa*a = a+a */ | 1424 | /* aa*a = a+a */ |
1463 | else if ( (0 == clean_ik_kk_cmp) && | 1425 | else if ((0 == clean_ik_kk_cmp) && (0 == clean_kk_kj_cmp) && |
1464 | (0 == clean_kk_kj_cmp) && | 1426 | (! has_epsilon (R_last_ik))) |
1465 | (! has_epsilon (R_last_ik)) ) | ||
1466 | { | 1427 | { |
1467 | if (needs_parentheses (&R_temp_kk)) | 1428 | if (needs_parentheses (&R_temp_kk)) |
1468 | sb_printf2 (R_cur_r, "(%.*s)+%.*s", 3, &R_temp_kk, &R_temp_kk); | 1429 | sb_printf2 (R_cur_r, "(%.*s)+%.*s", 3, &R_temp_kk, &R_temp_kk); |
@@ -1477,9 +1438,8 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1477 | */ | 1438 | */ |
1478 | else | 1439 | else |
1479 | { | 1440 | { |
1480 | eps_check = | 1441 | eps_check = (has_epsilon (R_last_ik) + has_epsilon (R_last_kk) + |
1481 | (has_epsilon (R_last_ik) + has_epsilon (R_last_kk) + | 1442 | has_epsilon (R_last_kj)); |
1482 | has_epsilon (R_last_kj)); | ||
1483 | 1443 | ||
1484 | if (1 == eps_check) | 1444 | if (1 == eps_check) |
1485 | { | 1445 | { |
@@ -1538,18 +1498,26 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1538 | { | 1498 | { |
1539 | if (needs_parentheses (&R_temp_kk)) | 1499 | if (needs_parentheses (&R_temp_kk)) |
1540 | { | 1500 | { |
1541 | sb_printf3 (R_cur_r, "%.*s(%.*s)*%.*s", 3, R_last_ik, &R_temp_kk, | 1501 | sb_printf3 (R_cur_r, |
1542 | R_last_kj); | 1502 | "%.*s(%.*s)*%.*s", |
1503 | 3, | ||
1504 | R_last_ik, | ||
1505 | &R_temp_kk, | ||
1506 | R_last_kj); | ||
1543 | } | 1507 | } |
1544 | else | 1508 | else |
1545 | { | 1509 | { |
1546 | sb_printf3 (R_cur_r, "%.*s%.*s*%.*s", 1, R_last_ik, &R_temp_kk, | 1510 | sb_printf3 (R_cur_r, |
1547 | R_last_kj); | 1511 | "%.*s%.*s*%.*s", |
1512 | 1, | ||
1513 | R_last_ik, | ||
1514 | &R_temp_kk, | ||
1515 | R_last_kj); | ||
1548 | } | 1516 | } |
1549 | } | 1517 | } |
1550 | else | 1518 | else |
1551 | { | 1519 | { |
1552 | sb_printf2 (R_cur_r, "%.*s%.*s", 0, R_last_ik, R_last_kj); | 1520 | sb_printf2 (R_cur_r, "%.*s%.*s", 0, R_last_ik, R_last_kj); |
1553 | } | 1521 | } |
1554 | } | 1522 | } |
1555 | } | 1523 | } |
@@ -1558,15 +1526,13 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1558 | sb_free (&R_temp_kk); | 1526 | sb_free (&R_temp_kk); |
1559 | sb_free (&R_temp_kj); | 1527 | sb_free (&R_temp_kj); |
1560 | 1528 | ||
1561 | if ( (GNUNET_YES == R_cur_l->null_flag) && | 1529 | if ((GNUNET_YES == R_cur_l->null_flag) && (GNUNET_YES == R_cur_r->null_flag)) |
1562 | (GNUNET_YES == R_cur_r->null_flag) ) | ||
1563 | { | 1530 | { |
1564 | R_cur_ij->null_flag = GNUNET_YES; | 1531 | R_cur_ij->null_flag = GNUNET_YES; |
1565 | return; | 1532 | return; |
1566 | } | 1533 | } |
1567 | 1534 | ||
1568 | if ( (GNUNET_YES != R_cur_l->null_flag) && | 1535 | if ((GNUNET_YES != R_cur_l->null_flag) && (GNUNET_YES == R_cur_r->null_flag)) |
1569 | (GNUNET_YES == R_cur_r->null_flag) ) | ||
1570 | { | 1536 | { |
1571 | struct StringBuffer tmp; | 1537 | struct StringBuffer tmp; |
1572 | 1538 | ||
@@ -1576,8 +1542,7 @@ automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij, | |||
1576 | return; | 1542 | return; |
1577 | } | 1543 | } |
1578 | 1544 | ||
1579 | if ( (GNUNET_YES == R_cur_l->null_flag) && | 1545 | if ((GNUNET_YES == R_cur_l->null_flag) && (GNUNET_YES != R_cur_r->null_flag)) |
1580 | (GNUNET_YES != R_cur_r->null_flag) ) | ||
1581 | { | 1546 | { |
1582 | struct StringBuffer tmp; | 1547 | struct StringBuffer tmp; |
1583 | 1548 | ||
@@ -1629,8 +1594,7 @@ automaton_create_proofs (struct REGEX_INTERNAL_Automaton *a) | |||
1629 | 1594 | ||
1630 | R_last = GNUNET_malloc_large (sizeof (struct StringBuffer) * n * n); | 1595 | R_last = GNUNET_malloc_large (sizeof (struct StringBuffer) * n * n); |
1631 | R_cur = GNUNET_malloc_large (sizeof (struct StringBuffer) * n * n); | 1596 | R_cur = GNUNET_malloc_large (sizeof (struct StringBuffer) * n * n); |
1632 | if ( (NULL == R_last) || | 1597 | if ((NULL == R_last) || (NULL == R_cur)) |
1633 | (NULL == R_cur) ) | ||
1634 | { | 1598 | { |
1635 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc"); | 1599 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc"); |
1636 | GNUNET_free_non_null (R_cur); | 1600 | GNUNET_free_non_null (R_cur); |
@@ -1639,14 +1603,18 @@ automaton_create_proofs (struct REGEX_INTERNAL_Automaton *a) | |||
1639 | } | 1603 | } |
1640 | 1604 | ||
1641 | /* create depth-first numbering of the states, initializes 'state' */ | 1605 | /* create depth-first numbering of the states, initializes 'state' */ |
1642 | REGEX_INTERNAL_automaton_traverse (a, a->start, NULL, NULL, &number_states, | 1606 | REGEX_INTERNAL_automaton_traverse (a, |
1643 | states); | 1607 | a->start, |
1608 | NULL, | ||
1609 | NULL, | ||
1610 | &number_states, | ||
1611 | states); | ||
1644 | 1612 | ||
1645 | for (i = 0; i < n; i++) | 1613 | for (i = 0; i < n; i++) |
1646 | GNUNET_assert (NULL != states[i]); | 1614 | GNUNET_assert (NULL != states[i]); |
1647 | for (i = 0; i < n; i++) | 1615 | for (i = 0; i < n; i++) |
1648 | for (j = 0; j < n; j++) | 1616 | for (j = 0; j < n; j++) |
1649 | R_last[i *n + j].null_flag = GNUNET_YES; | 1617 | R_last[i * n + j].null_flag = GNUNET_YES; |
1650 | 1618 | ||
1651 | /* Compute regular expressions of length "1" between each pair of states */ | 1619 | /* Compute regular expressions of length "1" between each pair of states */ |
1652 | for (i = 0; i < n; i++) | 1620 | for (i = 0; i < n; i++) |
@@ -1660,8 +1628,8 @@ automaton_create_proofs (struct REGEX_INTERNAL_Automaton *a) | |||
1660 | } | 1628 | } |
1661 | else | 1629 | else |
1662 | { | 1630 | { |
1663 | sb_append_cstr (&R_last[i * n + j], "|"); | 1631 | sb_append_cstr (&R_last[i * n + j], "|"); |
1664 | sb_append_cstr (&R_last[i * n + j], t->label); | 1632 | sb_append_cstr (&R_last[i * n + j], t->label); |
1665 | } | 1633 | } |
1666 | } | 1634 | } |
1667 | /* add self-loop: i is reachable from i via epsilon-transition */ | 1635 | /* add self-loop: i is reachable from i via epsilon-transition */ |
@@ -1695,10 +1663,13 @@ automaton_create_proofs (struct REGEX_INTERNAL_Automaton *a) | |||
1695 | */ | 1663 | */ |
1696 | 1664 | ||
1697 | /* Create R_cur[i][j] and simplify the expression */ | 1665 | /* Create R_cur[i][j] and simplify the expression */ |
1698 | automaton_create_proofs_simplify (&R_last[i * n + j], &R_last[i * n + k], | 1666 | automaton_create_proofs_simplify (&R_last[i * n + j], |
1699 | &R_last[k * n + k], &R_last[k * n + j], | 1667 | &R_last[i * n + k], |
1668 | &R_last[k * n + k], | ||
1669 | &R_last[k * n + j], | ||
1700 | &R_cur[i * n + j], | 1670 | &R_cur[i * n + j], |
1701 | &R_cur_l, &R_cur_r); | 1671 | &R_cur_l, |
1672 | &R_cur_r); | ||
1702 | } | 1673 | } |
1703 | } | 1674 | } |
1704 | /* set R_last = R_cur */ | 1675 | /* set R_last = R_cur */ |
@@ -1718,8 +1689,9 @@ automaton_create_proofs (struct REGEX_INTERNAL_Automaton *a) | |||
1718 | if (GNUNET_YES != R_last[a->start->dfs_id * n + i].null_flag) | 1689 | if (GNUNET_YES != R_last[a->start->dfs_id * n + i].null_flag) |
1719 | { | 1690 | { |
1720 | states[i]->proof = GNUNET_strndup (R_last[a->start->dfs_id * n + i].sbuf, | 1691 | states[i]->proof = GNUNET_strndup (R_last[a->start->dfs_id * n + i].sbuf, |
1721 | R_last[a->start->dfs_id * n + i].slen); | 1692 | R_last[a->start->dfs_id * n + i].slen); |
1722 | GNUNET_CRYPTO_hash (states[i]->proof, strlen (states[i]->proof), | 1693 | GNUNET_CRYPTO_hash (states[i]->proof, |
1694 | strlen (states[i]->proof), | ||
1723 | &states[i]->hash); | 1695 | &states[i]->hash); |
1724 | } | 1696 | } |
1725 | } | 1697 | } |
@@ -1731,22 +1703,21 @@ automaton_create_proofs (struct REGEX_INTERNAL_Automaton *a) | |||
1731 | { | 1703 | { |
1732 | if (states[i]->accepting) | 1704 | if (states[i]->accepting) |
1733 | { | 1705 | { |
1734 | if ( (0 == complete_regex.slen) && | 1706 | if ((0 == complete_regex.slen) && |
1735 | (0 < R_last[a->start->dfs_id * n + i].slen) ) | 1707 | (0 < R_last[a->start->dfs_id * n + i].slen)) |
1736 | { | 1708 | { |
1737 | sb_append (&complete_regex, | 1709 | sb_append (&complete_regex, &R_last[a->start->dfs_id * n + i]); |
1738 | &R_last[a->start->dfs_id * n + i]); | ||
1739 | } | 1710 | } |
1740 | else if ( (GNUNET_YES != R_last[a->start->dfs_id * n + i].null_flag) && | 1711 | else if ((GNUNET_YES != R_last[a->start->dfs_id * n + i].null_flag) && |
1741 | (0 < R_last[a->start->dfs_id * n + i].slen) ) | 1712 | (0 < R_last[a->start->dfs_id * n + i].slen)) |
1742 | { | 1713 | { |
1743 | sb_append_cstr (&complete_regex, "|"); | 1714 | sb_append_cstr (&complete_regex, "|"); |
1744 | sb_append (&complete_regex, | 1715 | sb_append (&complete_regex, &R_last[a->start->dfs_id * n + i]); |
1745 | &R_last[a->start->dfs_id * n + i]); | ||
1746 | } | 1716 | } |
1747 | } | 1717 | } |
1748 | } | 1718 | } |
1749 | a->canonical_regex = GNUNET_strndup (complete_regex.sbuf, complete_regex.slen); | 1719 | a->canonical_regex = |
1720 | GNUNET_strndup (complete_regex.sbuf, complete_regex.slen); | ||
1750 | 1721 | ||
1751 | /* cleanup */ | 1722 | /* cleanup */ |
1752 | sb_free (&complete_regex); | 1723 | sb_free (&complete_regex); |
@@ -1807,10 +1778,7 @@ dfa_state_create (struct REGEX_INTERNAL_Context *ctx, | |||
1807 | for (i = 0; i < nfa_states->off; i++) | 1778 | for (i = 0; i < nfa_states->off; i++) |
1808 | { | 1779 | { |
1809 | cstate = nfa_states->states[i]; | 1780 | cstate = nfa_states->states[i]; |
1810 | GNUNET_snprintf (pos, | 1781 | GNUNET_snprintf (pos, pos - s->name + len, "%i,", cstate->id); |
1811 | pos - s->name + len, | ||
1812 | "%i,", | ||
1813 | cstate->id); | ||
1814 | pos += strlen (pos); | 1782 | pos += strlen (pos); |
1815 | 1783 | ||
1816 | /* Add a transition for each distinct label to NULL state */ | 1784 | /* Add a transition for each distinct label to NULL state */ |
@@ -1911,7 +1879,12 @@ dfa_remove_unreachable_states (struct REGEX_INTERNAL_Automaton *a) | |||
1911 | s->marked = GNUNET_NO; | 1879 | s->marked = GNUNET_NO; |
1912 | 1880 | ||
1913 | /* 2. traverse dfa from start state and mark all visited states */ | 1881 | /* 2. traverse dfa from start state and mark all visited states */ |
1914 | REGEX_INTERNAL_automaton_traverse (a, a->start, NULL, NULL, &mark_states, NULL); | 1882 | REGEX_INTERNAL_automaton_traverse (a, |
1883 | a->start, | ||
1884 | NULL, | ||
1885 | NULL, | ||
1886 | &mark_states, | ||
1887 | NULL); | ||
1915 | 1888 | ||
1916 | /* 3. delete all states that were not visited */ | 1889 | /* 3. delete all states that were not visited */ |
1917 | for (s = a->states_head; NULL != s; s = s_next) | 1890 | for (s = a->states_head; NULL != s; s = s_next) |
@@ -1990,7 +1963,7 @@ dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx, | |||
1990 | unsigned long long idx; | 1963 | unsigned long long idx; |
1991 | unsigned long long idx1; | 1964 | unsigned long long idx1; |
1992 | 1965 | ||
1993 | if ( (NULL == a) || (0 == a->state_count) ) | 1966 | if ((NULL == a) || (0 == a->state_count)) |
1994 | { | 1967 | { |
1995 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1968 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1996 | "Could not merge nondistinguishable states, automaton was NULL.\n"); | 1969 | "Could not merge nondistinguishable states, automaton was NULL.\n"); |
@@ -1998,7 +1971,8 @@ dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx, | |||
1998 | } | 1971 | } |
1999 | 1972 | ||
2000 | state_cnt = a->state_count; | 1973 | state_cnt = a->state_count; |
2001 | table = GNUNET_malloc_large ((sizeof (uint32_t) * state_cnt * state_cnt / 32) + sizeof (uint32_t)); | 1974 | table = GNUNET_malloc_large ( |
1975 | (sizeof (uint32_t) * state_cnt * state_cnt / 32) + sizeof (uint32_t)); | ||
2002 | if (NULL == table) | 1976 | if (NULL == table) |
2003 | { | 1977 | { |
2004 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc"); | 1978 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc"); |
@@ -2011,10 +1985,10 @@ dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx, | |||
2011 | /* Mark all pairs of accepting/!accepting states */ | 1985 | /* Mark all pairs of accepting/!accepting states */ |
2012 | for (s1 = a->states_head; NULL != s1; s1 = s1->next) | 1986 | for (s1 = a->states_head; NULL != s1; s1 = s1->next) |
2013 | for (s2 = a->states_head; NULL != s2; s2 = s2->next) | 1987 | for (s2 = a->states_head; NULL != s2; s2 = s2->next) |
2014 | if ( (s1->accepting && !s2->accepting) || | 1988 | if ((s1->accepting && ! s2->accepting) || |
2015 | (!s1->accepting && s2->accepting) ) | 1989 | (! s1->accepting && s2->accepting)) |
2016 | { | 1990 | { |
2017 | idx = (unsigned long long) s1->marked * state_cnt + s2->marked; | 1991 | idx = (unsigned long long) s1->marked * state_cnt + s2->marked; |
2018 | table[idx / 32] |= (1U << (idx % 32)); | 1992 | table[idx / 32] |= (1U << (idx % 32)); |
2019 | } | 1993 | } |
2020 | 1994 | ||
@@ -2027,7 +2001,7 @@ dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx, | |||
2027 | { | 2001 | { |
2028 | for (s2 = a->states_head; NULL != s2 && s1 != s2; s2 = s2->next) | 2002 | for (s2 = a->states_head; NULL != s2 && s1 != s2; s2 = s2->next) |
2029 | { | 2003 | { |
2030 | idx = (unsigned long long) s1->marked * state_cnt + s2->marked; | 2004 | idx = (unsigned long long) s1->marked * state_cnt + s2->marked; |
2031 | if (0 != (table[idx / 32] & (1U << (idx % 32)))) | 2005 | if (0 != (table[idx / 32] & (1U << (idx % 32)))) |
2032 | continue; | 2006 | continue; |
2033 | num_equal_edges = 0; | 2007 | num_equal_edges = 0; |
@@ -2036,28 +2010,30 @@ dfa_merge_nondistinguishable_states (struct REGEX_INTERNAL_Context *ctx, | |||
2036 | for (t2 = s2->transitions_head; NULL != t2; t2 = t2->next) | 2010 | for (t2 = s2->transitions_head; NULL != t2; t2 = t2->next) |
2037 | { | 2011 | { |
2038 | if (0 == strcmp (t1->label, t2->label)) | 2012 | if (0 == strcmp (t1->label, t2->label)) |
2039 | { | 2013 | { |
2040 | num_equal_edges++; | 2014 | num_equal_edges++; |
2041 | /* same edge, but targets definitively different, so we're different | 2015 | /* same edge, but targets definitively different, so we're different |
2042 | as well */ | 2016 | as well */ |
2043 | if (t1->to_state->marked > t2->to_state->marked) | 2017 | if (t1->to_state->marked > t2->to_state->marked) |
2044 | idx1 = (unsigned long long) t1->to_state->marked * state_cnt + t2->to_state->marked; | 2018 | idx1 = (unsigned long long) t1->to_state->marked * state_cnt + |
2045 | else | 2019 | t2->to_state->marked; |
2046 | idx1 = (unsigned long long) t2->to_state->marked * state_cnt + t1->to_state->marked; | 2020 | else |
2047 | if (0 != (table[idx1 / 32] & (1U << (idx1 % 32)))) | 2021 | idx1 = (unsigned long long) t2->to_state->marked * state_cnt + |
2048 | { | 2022 | t1->to_state->marked; |
2049 | table[idx / 32] |= (1U << (idx % 32)); | 2023 | if (0 != (table[idx1 / 32] & (1U << (idx1 % 32)))) |
2050 | change = 1; /* changed a marker, need to run again */ | 2024 | { |
2051 | } | 2025 | table[idx / 32] |= (1U << (idx % 32)); |
2052 | } | 2026 | change = 1; /* changed a marker, need to run again */ |
2053 | } | 2027 | } |
2028 | } | ||
2029 | } | ||
2054 | } | 2030 | } |
2055 | if ( (num_equal_edges != s1->transition_count) || | 2031 | if ((num_equal_edges != s1->transition_count) || |
2056 | (num_equal_edges != s2->transition_count) ) | 2032 | (num_equal_edges != s2->transition_count)) |
2057 | { | 2033 | { |
2058 | /* Make sure ALL edges of possible equal states are the same */ | 2034 | /* Make sure ALL edges of possible equal states are the same */ |
2059 | table[idx / 32] |= (1U << (idx % 32)); | 2035 | table[idx / 32] |= (1U << (idx % 32)); |
2060 | change = 1; /* changed a marker, need to run again */ | 2036 | change = 1; /* changed a marker, need to run again */ |
2061 | } | 2037 | } |
2062 | } | 2038 | } |
2063 | } | 2039 | } |
@@ -2145,7 +2121,9 @@ struct REGEX_INTERNAL_Strided_Context | |||
2145 | * @param s current state in the depth-first traversal | 2121 | * @param s current state in the depth-first traversal |
2146 | */ | 2122 | */ |
2147 | static void | 2123 | static void |
2148 | dfa_add_multi_strides_helper (void *cls, const unsigned int depth, char *label, | 2124 | dfa_add_multi_strides_helper (void *cls, |
2125 | const unsigned int depth, | ||
2126 | char *label, | ||
2149 | struct REGEX_INTERNAL_State *start, | 2127 | struct REGEX_INTERNAL_State *start, |
2150 | struct REGEX_INTERNAL_State *s) | 2128 | struct REGEX_INTERNAL_State *s) |
2151 | { | 2129 | { |
@@ -2159,7 +2137,8 @@ dfa_add_multi_strides_helper (void *cls, const unsigned int depth, char *label, | |||
2159 | t->label = GNUNET_strdup (label); | 2137 | t->label = GNUNET_strdup (label); |
2160 | t->to_state = s; | 2138 | t->to_state = s; |
2161 | t->from_state = start; | 2139 | t->from_state = start; |
2162 | GNUNET_CONTAINER_DLL_insert (ctx->transitions_head, ctx->transitions_tail, | 2140 | GNUNET_CONTAINER_DLL_insert (ctx->transitions_head, |
2141 | ctx->transitions_tail, | ||
2163 | t); | 2142 | t); |
2164 | } | 2143 | } |
2165 | else | 2144 | else |
@@ -2178,7 +2157,10 @@ dfa_add_multi_strides_helper (void *cls, const unsigned int depth, char *label, | |||
2178 | else | 2157 | else |
2179 | new_label = GNUNET_strdup (t->label); | 2158 | new_label = GNUNET_strdup (t->label); |
2180 | 2159 | ||
2181 | dfa_add_multi_strides_helper (cls, (depth + 1), new_label, start, | 2160 | dfa_add_multi_strides_helper (cls, |
2161 | (depth + 1), | ||
2162 | new_label, | ||
2163 | start, | ||
2182 | t->to_state); | 2164 | t->to_state); |
2183 | } | 2165 | } |
2184 | } | 2166 | } |
@@ -2195,7 +2177,8 @@ dfa_add_multi_strides_helper (void *cls, const unsigned int depth, char *label, | |||
2195 | * @param s current state. | 2177 | * @param s current state. |
2196 | */ | 2178 | */ |
2197 | static void | 2179 | static void |
2198 | dfa_add_multi_strides (void *cls, const unsigned int count, | 2180 | dfa_add_multi_strides (void *cls, |
2181 | const unsigned int count, | ||
2199 | struct REGEX_INTERNAL_State *s) | 2182 | struct REGEX_INTERNAL_State *s) |
2200 | { | 2183 | { |
2201 | dfa_add_multi_strides_helper (cls, 0, NULL, s, s); | 2184 | dfa_add_multi_strides_helper (cls, 0, NULL, s, s); |
@@ -2211,10 +2194,10 @@ dfa_add_multi_strides (void *cls, const unsigned int count, | |||
2211 | */ | 2194 | */ |
2212 | void | 2195 | void |
2213 | REGEX_INTERNAL_dfa_add_multi_strides (struct REGEX_INTERNAL_Context *regex_ctx, | 2196 | REGEX_INTERNAL_dfa_add_multi_strides (struct REGEX_INTERNAL_Context *regex_ctx, |
2214 | struct REGEX_INTERNAL_Automaton *dfa, | 2197 | struct REGEX_INTERNAL_Automaton *dfa, |
2215 | const unsigned int stride_len) | 2198 | const unsigned int stride_len) |
2216 | { | 2199 | { |
2217 | struct REGEX_INTERNAL_Strided_Context ctx = { stride_len, NULL, NULL }; | 2200 | struct REGEX_INTERNAL_Strided_Context ctx = {stride_len, NULL, NULL}; |
2218 | struct REGEX_INTERNAL_Transition *t; | 2201 | struct REGEX_INTERNAL_Transition *t; |
2219 | struct REGEX_INTERNAL_Transition *t_next; | 2202 | struct REGEX_INTERNAL_Transition *t_next; |
2220 | 2203 | ||
@@ -2222,8 +2205,12 @@ REGEX_INTERNAL_dfa_add_multi_strides (struct REGEX_INTERNAL_Context *regex_ctx, | |||
2222 | return; | 2205 | return; |
2223 | 2206 | ||
2224 | /* Compute the new transitions of given stride_len */ | 2207 | /* Compute the new transitions of given stride_len */ |
2225 | REGEX_INTERNAL_automaton_traverse (dfa, dfa->start, NULL, NULL, | 2208 | REGEX_INTERNAL_automaton_traverse (dfa, |
2226 | &dfa_add_multi_strides, &ctx); | 2209 | dfa->start, |
2210 | NULL, | ||
2211 | NULL, | ||
2212 | &dfa_add_multi_strides, | ||
2213 | &ctx); | ||
2227 | 2214 | ||
2228 | /* Add all the new transitions to the automaton. */ | 2215 | /* Add all the new transitions to the automaton. */ |
2229 | for (t = ctx.transitions_head; NULL != t; t = t_next) | 2216 | for (t = ctx.transitions_head; NULL != t; t = t_next) |
@@ -2255,7 +2242,8 @@ REGEX_INTERNAL_dfa_add_multi_strides (struct REGEX_INTERNAL_Context *regex_ctx, | |||
2255 | void | 2242 | void |
2256 | dfa_compress_paths_helper (struct REGEX_INTERNAL_Automaton *dfa, | 2243 | dfa_compress_paths_helper (struct REGEX_INTERNAL_Automaton *dfa, |
2257 | struct REGEX_INTERNAL_State *start, | 2244 | struct REGEX_INTERNAL_State *start, |
2258 | struct REGEX_INTERNAL_State *cur, char *label, | 2245 | struct REGEX_INTERNAL_State *cur, |
2246 | char *label, | ||
2259 | unsigned int max_len, | 2247 | unsigned int max_len, |
2260 | struct REGEX_INTERNAL_Transition **transitions_head, | 2248 | struct REGEX_INTERNAL_Transition **transitions_head, |
2261 | struct REGEX_INTERNAL_Transition **transitions_tail) | 2249 | struct REGEX_INTERNAL_Transition **transitions_tail) |
@@ -2266,8 +2254,8 @@ dfa_compress_paths_helper (struct REGEX_INTERNAL_Automaton *dfa, | |||
2266 | 2254 | ||
2267 | if (NULL != label && | 2255 | if (NULL != label && |
2268 | ((cur->incoming_transition_count > 1 || GNUNET_YES == cur->accepting || | 2256 | ((cur->incoming_transition_count > 1 || GNUNET_YES == cur->accepting || |
2269 | GNUNET_YES == cur->marked) || (start != dfa->start && max_len > 0 && | 2257 | GNUNET_YES == cur->marked) || |
2270 | max_len == strlen (label)) || | 2258 | (start != dfa->start && max_len > 0 && max_len == strlen (label)) || |
2271 | (start == dfa->start && GNUNET_REGEX_INITIAL_BYTES == strlen (label)))) | 2259 | (start == dfa->start && GNUNET_REGEX_INITIAL_BYTES == strlen (label)))) |
2272 | { | 2260 | { |
2273 | t = GNUNET_new (struct REGEX_INTERNAL_Transition); | 2261 | t = GNUNET_new (struct REGEX_INTERNAL_Transition); |
@@ -2278,7 +2266,12 @@ dfa_compress_paths_helper (struct REGEX_INTERNAL_Automaton *dfa, | |||
2278 | 2266 | ||
2279 | if (GNUNET_NO == cur->marked) | 2267 | if (GNUNET_NO == cur->marked) |
2280 | { | 2268 | { |
2281 | dfa_compress_paths_helper (dfa, cur, cur, NULL, max_len, transitions_head, | 2269 | dfa_compress_paths_helper (dfa, |
2270 | cur, | ||
2271 | cur, | ||
2272 | NULL, | ||
2273 | max_len, | ||
2274 | transitions_head, | ||
2282 | transitions_tail); | 2275 | transitions_tail); |
2283 | } | 2276 | } |
2284 | return; | 2277 | return; |
@@ -2301,8 +2294,13 @@ dfa_compress_paths_helper (struct REGEX_INTERNAL_Automaton *dfa, | |||
2301 | 2294 | ||
2302 | if (t->to_state != cur) | 2295 | if (t->to_state != cur) |
2303 | { | 2296 | { |
2304 | dfa_compress_paths_helper (dfa, start, t->to_state, new_label, max_len, | 2297 | dfa_compress_paths_helper (dfa, |
2305 | transitions_head, transitions_tail); | 2298 | start, |
2299 | t->to_state, | ||
2300 | new_label, | ||
2301 | max_len, | ||
2302 | transitions_head, | ||
2303 | transitions_tail); | ||
2306 | } | 2304 | } |
2307 | GNUNET_free (new_label); | 2305 | GNUNET_free (new_label); |
2308 | } | 2306 | } |
@@ -2319,7 +2317,8 @@ dfa_compress_paths_helper (struct REGEX_INTERNAL_Automaton *dfa, | |||
2319 | */ | 2317 | */ |
2320 | static void | 2318 | static void |
2321 | dfa_compress_paths (struct REGEX_INTERNAL_Context *regex_ctx, | 2319 | dfa_compress_paths (struct REGEX_INTERNAL_Context *regex_ctx, |
2322 | struct REGEX_INTERNAL_Automaton *dfa, unsigned int max_len) | 2320 | struct REGEX_INTERNAL_Automaton *dfa, |
2321 | unsigned int max_len) | ||
2323 | { | 2322 | { |
2324 | struct REGEX_INTERNAL_State *s; | 2323 | struct REGEX_INTERNAL_State *s; |
2325 | struct REGEX_INTERNAL_State *s_next; | 2324 | struct REGEX_INTERNAL_State *s_next; |
@@ -2349,8 +2348,13 @@ dfa_compress_paths (struct REGEX_INTERNAL_Context *regex_ctx, | |||
2349 | } | 2348 | } |
2350 | 2349 | ||
2351 | /* Add strides and mark states that can be deleted. */ | 2350 | /* Add strides and mark states that can be deleted. */ |
2352 | dfa_compress_paths_helper (dfa, dfa->start, dfa->start, NULL, max_len, | 2351 | dfa_compress_paths_helper (dfa, |
2353 | &transitions_head, &transitions_tail); | 2352 | dfa->start, |
2353 | dfa->start, | ||
2354 | NULL, | ||
2355 | max_len, | ||
2356 | &transitions_head, | ||
2357 | &transitions_tail); | ||
2354 | 2358 | ||
2355 | /* Add all the new transitions to the automaton. */ | 2359 | /* Add all the new transitions to the automaton. */ |
2356 | for (t = transitions_head; NULL != t; t = t_next) | 2360 | for (t = transitions_head; NULL != t; t = t_next) |
@@ -2486,8 +2490,9 @@ nfa_state_create (struct REGEX_INTERNAL_Context *ctx, int accepting) | |||
2486 | */ | 2490 | */ |
2487 | static void | 2491 | static void |
2488 | nfa_closure_set_create (struct REGEX_INTERNAL_StateSet *ret, | 2492 | nfa_closure_set_create (struct REGEX_INTERNAL_StateSet *ret, |
2489 | struct REGEX_INTERNAL_Automaton *nfa, | 2493 | struct REGEX_INTERNAL_Automaton *nfa, |
2490 | struct REGEX_INTERNAL_StateSet *states, const char *label) | 2494 | struct REGEX_INTERNAL_StateSet *states, |
2495 | const char *label) | ||
2491 | { | 2496 | { |
2492 | struct REGEX_INTERNAL_State *s; | 2497 | struct REGEX_INTERNAL_State *s; |
2493 | unsigned int i; | 2498 | unsigned int i; |
@@ -2516,23 +2521,27 @@ nfa_closure_set_create (struct REGEX_INTERNAL_StateSet *ret, | |||
2516 | 2521 | ||
2517 | while (NULL != (currentstate = cls_stack.tail)) | 2522 | while (NULL != (currentstate = cls_stack.tail)) |
2518 | { | 2523 | { |
2519 | GNUNET_CONTAINER_MDLL_remove (ST, cls_stack.head, cls_stack.tail, | 2524 | GNUNET_CONTAINER_MDLL_remove (ST, |
2520 | currentstate); | 2525 | cls_stack.head, |
2526 | cls_stack.tail, | ||
2527 | currentstate); | ||
2521 | cls_stack.len--; | 2528 | cls_stack.len--; |
2522 | for (ctran = currentstate->transitions_head; NULL != ctran; | 2529 | for (ctran = currentstate->transitions_head; NULL != ctran; |
2523 | ctran = ctran->next) | 2530 | ctran = ctran->next) |
2524 | { | 2531 | { |
2525 | if (NULL == (clsstate = ctran->to_state)) | 2532 | if (NULL == (clsstate = ctran->to_state)) |
2526 | continue; | 2533 | continue; |
2527 | if (0 != clsstate->contained) | 2534 | if (0 != clsstate->contained) |
2528 | continue; | 2535 | continue; |
2529 | if (0 != nullstrcmp (label, ctran->label)) | 2536 | if (0 != nullstrcmp (label, ctran->label)) |
2530 | continue; | 2537 | continue; |
2531 | state_set_append (ret, clsstate); | 2538 | state_set_append (ret, clsstate); |
2532 | GNUNET_CONTAINER_MDLL_insert_tail (ST, cls_stack.head, cls_stack.tail, | 2539 | GNUNET_CONTAINER_MDLL_insert_tail (ST, |
2533 | clsstate); | 2540 | cls_stack.head, |
2534 | cls_stack.len++; | 2541 | cls_stack.tail, |
2535 | clsstate->contained = 1; | 2542 | clsstate); |
2543 | cls_stack.len++; | ||
2544 | clsstate->contained = 1; | ||
2536 | } | 2545 | } |
2537 | } | 2546 | } |
2538 | } | 2547 | } |
@@ -2540,7 +2549,9 @@ nfa_closure_set_create (struct REGEX_INTERNAL_StateSet *ret, | |||
2540 | ret->states[i]->contained = 0; | 2549 | ret->states[i]->contained = 0; |
2541 | 2550 | ||
2542 | if (ret->off > 1) | 2551 | if (ret->off > 1) |
2543 | qsort (ret->states, ret->off, sizeof (struct REGEX_INTERNAL_State *), | 2552 | qsort (ret->states, |
2553 | ret->off, | ||
2554 | sizeof (struct REGEX_INTERNAL_State *), | ||
2544 | &state_compare); | 2555 | &state_compare); |
2545 | } | 2556 | } |
2546 | 2557 | ||
@@ -2598,8 +2609,9 @@ nfa_add_star_op (struct REGEX_INTERNAL_Context *ctx) | |||
2598 | 2609 | ||
2599 | if (NULL == a) | 2610 | if (NULL == a) |
2600 | { | 2611 | { |
2601 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2612 | GNUNET_log ( |
2602 | "nfa_add_star_op failed, because there was no element on the stack"); | 2613 | GNUNET_ERROR_TYPE_ERROR, |
2614 | "nfa_add_star_op failed, because there was no element on the stack"); | ||
2603 | return; | 2615 | return; |
2604 | } | 2616 | } |
2605 | 2617 | ||
@@ -2638,8 +2650,9 @@ nfa_add_plus_op (struct REGEX_INTERNAL_Context *ctx) | |||
2638 | 2650 | ||
2639 | if (NULL == a) | 2651 | if (NULL == a) |
2640 | { | 2652 | { |
2641 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2653 | GNUNET_log ( |
2642 | "nfa_add_plus_op failed, because there was no element on the stack"); | 2654 | GNUNET_ERROR_TYPE_ERROR, |
2655 | "nfa_add_plus_op failed, because there was no element on the stack"); | ||
2643 | return; | 2656 | return; |
2644 | } | 2657 | } |
2645 | 2658 | ||
@@ -2667,8 +2680,9 @@ nfa_add_question_op (struct REGEX_INTERNAL_Context *ctx) | |||
2667 | a = ctx->stack_tail; | 2680 | a = ctx->stack_tail; |
2668 | if (NULL == a) | 2681 | if (NULL == a) |
2669 | { | 2682 | { |
2670 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2683 | GNUNET_log ( |
2671 | "nfa_add_question_op failed, because there was no element on the stack"); | 2684 | GNUNET_ERROR_TYPE_ERROR, |
2685 | "nfa_add_question_op failed, because there was no element on the stack"); | ||
2672 | return; | 2686 | return; |
2673 | } | 2687 | } |
2674 | 2688 | ||
@@ -2803,7 +2817,7 @@ REGEX_INTERNAL_construct_nfa (const char *regex, const size_t len) | |||
2803 | { | 2817 | { |
2804 | int altcount; | 2818 | int altcount; |
2805 | int atomcount; | 2819 | int atomcount; |
2806 | } *p; | 2820 | } * p; |
2807 | 2821 | ||
2808 | if (NULL == regex || 0 == strlen (regex) || 0 == len) | 2822 | if (NULL == regex || 0 == strlen (regex) || 0 == len) |
2809 | { | 2823 | { |
@@ -2935,7 +2949,12 @@ REGEX_INTERNAL_construct_nfa (const char *regex, const size_t len) | |||
2935 | nfa->regex = GNUNET_strdup (regex); | 2949 | nfa->regex = GNUNET_strdup (regex); |
2936 | 2950 | ||
2937 | /* create depth-first numbering of the states for pretty printing */ | 2951 | /* create depth-first numbering of the states for pretty printing */ |
2938 | REGEX_INTERNAL_automaton_traverse (nfa, NULL, NULL, NULL, &number_states, NULL); | 2952 | REGEX_INTERNAL_automaton_traverse (nfa, |
2953 | NULL, | ||
2954 | NULL, | ||
2955 | NULL, | ||
2956 | &number_states, | ||
2957 | NULL); | ||
2939 | 2958 | ||
2940 | /* No multistriding added so far */ | 2959 | /* No multistriding added so far */ |
2941 | nfa->is_multistrided = GNUNET_NO; | 2960 | nfa->is_multistrided = GNUNET_NO; |
@@ -2997,7 +3016,7 @@ construct_dfa_states (struct REGEX_INTERNAL_Context *ctx, | |||
2997 | if (0 == state_set_compare (&state_iter->nfa_set, &nfa_set)) | 3016 | if (0 == state_set_compare (&state_iter->nfa_set, &nfa_set)) |
2998 | { | 3017 | { |
2999 | state_contains = state_iter; | 3018 | state_contains = state_iter; |
3000 | break; | 3019 | break; |
3001 | } | 3020 | } |
3002 | } | 3021 | } |
3003 | if (NULL == state_contains) | 3022 | if (NULL == state_contains) |
@@ -3034,7 +3053,8 @@ construct_dfa_states (struct REGEX_INTERNAL_Context *ctx, | |||
3034 | * @return DFA, needs to be freed using REGEX_INTERNAL_automaton_destroy. | 3053 | * @return DFA, needs to be freed using REGEX_INTERNAL_automaton_destroy. |
3035 | */ | 3054 | */ |
3036 | struct REGEX_INTERNAL_Automaton * | 3055 | struct REGEX_INTERNAL_Automaton * |
3037 | REGEX_INTERNAL_construct_dfa (const char *regex, const size_t len, | 3056 | REGEX_INTERNAL_construct_dfa (const char *regex, |
3057 | const size_t len, | ||
3038 | unsigned int max_path_len) | 3058 | unsigned int max_path_len) |
3039 | { | 3059 | { |
3040 | struct REGEX_INTERNAL_Context ctx; | 3060 | struct REGEX_INTERNAL_Context ctx; |
@@ -3130,8 +3150,7 @@ REGEX_INTERNAL_automaton_destroy (struct REGEX_INTERNAL_Automaton *a) | |||
3130 | * @return 0 if string matches, non-0 otherwise | 3150 | * @return 0 if string matches, non-0 otherwise |
3131 | */ | 3151 | */ |
3132 | static int | 3152 | static int |
3133 | evaluate_dfa (struct REGEX_INTERNAL_Automaton *a, | 3153 | evaluate_dfa (struct REGEX_INTERNAL_Automaton *a, const char *string) |
3134 | const char *string) | ||
3135 | { | 3154 | { |
3136 | const char *strp; | 3155 | const char *strp; |
3137 | struct REGEX_INTERNAL_State *s; | 3156 | struct REGEX_INTERNAL_State *s; |
@@ -3173,8 +3192,7 @@ evaluate_dfa (struct REGEX_INTERNAL_Automaton *a, | |||
3173 | * @return 0 if string matches, non-0 otherwise | 3192 | * @return 0 if string matches, non-0 otherwise |
3174 | */ | 3193 | */ |
3175 | static int | 3194 | static int |
3176 | evaluate_nfa (struct REGEX_INTERNAL_Automaton *a, | 3195 | evaluate_nfa (struct REGEX_INTERNAL_Automaton *a, const char *string) |
3177 | const char *string) | ||
3178 | { | 3196 | { |
3179 | const char *strp; | 3197 | const char *strp; |
3180 | char str[2]; | 3198 | char str[2]; |
@@ -3215,7 +3233,7 @@ evaluate_nfa (struct REGEX_INTERNAL_Automaton *a, | |||
3215 | for (i = 0; i < sset.off; i++) | 3233 | for (i = 0; i < sset.off; i++) |
3216 | { | 3234 | { |
3217 | s = sset.states[i]; | 3235 | s = sset.states[i]; |
3218 | if ( (NULL != s) && (s->accepting) ) | 3236 | if ((NULL != s) && (s->accepting)) |
3219 | { | 3237 | { |
3220 | result = 0; | 3238 | result = 0; |
3221 | break; | 3239 | break; |
@@ -3235,8 +3253,7 @@ evaluate_nfa (struct REGEX_INTERNAL_Automaton *a, | |||
3235 | * @return 0 if string matches, non-0 otherwise | 3253 | * @return 0 if string matches, non-0 otherwise |
3236 | */ | 3254 | */ |
3237 | int | 3255 | int |
3238 | REGEX_INTERNAL_eval (struct REGEX_INTERNAL_Automaton *a, | 3256 | REGEX_INTERNAL_eval (struct REGEX_INTERNAL_Automaton *a, const char *string) |
3239 | const char *string) | ||
3240 | { | 3257 | { |
3241 | int result; | 3258 | int result; |
3242 | 3259 | ||
@@ -3321,12 +3338,11 @@ REGEX_INTERNAL_get_first_key (const char *input_string, | |||
3321 | { | 3338 | { |
3322 | size_t size; | 3339 | size_t size; |
3323 | 3340 | ||
3324 | size = string_len < GNUNET_REGEX_INITIAL_BYTES ? string_len : | 3341 | size = string_len < GNUNET_REGEX_INITIAL_BYTES ? string_len |
3325 | GNUNET_REGEX_INITIAL_BYTES; | 3342 | : GNUNET_REGEX_INITIAL_BYTES; |
3326 | if (NULL == input_string) | 3343 | if (NULL == input_string) |
3327 | { | 3344 | { |
3328 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3345 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Given input string was NULL!\n"); |
3329 | "Given input string was NULL!\n"); | ||
3330 | return 0; | 3346 | return 0; |
3331 | } | 3347 | } |
3332 | GNUNET_CRYPTO_hash (input_string, size, key); | 3348 | GNUNET_CRYPTO_hash (input_string, size, key); |
@@ -3367,21 +3383,16 @@ iterate_initial_edge (unsigned int min_len, | |||
3367 | else | 3383 | else |
3368 | cur_len = 0; | 3384 | cur_len = 0; |
3369 | 3385 | ||
3370 | if ( ( (cur_len >= min_len) || | 3386 | if (((cur_len >= min_len) || (GNUNET_YES == state->accepting)) && |
3371 | (GNUNET_YES == state->accepting) ) && | 3387 | (cur_len > 0) && (NULL != consumed_string)) |
3372 | (cur_len > 0) && | ||
3373 | (NULL != consumed_string) ) | ||
3374 | { | 3388 | { |
3375 | if (cur_len <= max_len) | 3389 | if (cur_len <= max_len) |
3376 | { | 3390 | { |
3377 | if ( (NULL != state->proof) && | 3391 | if ((NULL != state->proof) && |
3378 | (0 != strcmp (consumed_string, | 3392 | (0 != strcmp (consumed_string, state->proof))) |
3379 | state->proof)) ) | ||
3380 | { | 3393 | { |
3381 | (void) state_get_edges (state, edges); | 3394 | (void) state_get_edges (state, edges); |
3382 | GNUNET_CRYPTO_hash (consumed_string, | 3395 | GNUNET_CRYPTO_hash (consumed_string, strlen (consumed_string), &hash); |
3383 | strlen (consumed_string), | ||
3384 | &hash); | ||
3385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3396 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3386 | "Start state for string `%s' is %s\n", | 3397 | "Start state for string `%s' is %s\n", |
3387 | consumed_string, | 3398 | consumed_string, |
@@ -3390,13 +3401,12 @@ iterate_initial_edge (unsigned int min_len, | |||
3390 | &hash, | 3401 | &hash, |
3391 | consumed_string, | 3402 | consumed_string, |
3392 | state->accepting, | 3403 | state->accepting, |
3393 | num_edges, edges); | 3404 | num_edges, |
3405 | edges); | ||
3394 | } | 3406 | } |
3395 | 3407 | ||
3396 | if ( (GNUNET_YES == state->accepting) && | 3408 | if ((GNUNET_YES == state->accepting) && (cur_len > 1) && |
3397 | (cur_len > 1) && | 3409 | (state->transition_count < 1) && (cur_len < max_len)) |
3398 | (state->transition_count < 1) && | ||
3399 | (cur_len < max_len) ) | ||
3400 | { | 3410 | { |
3401 | /* Special case for regex consisting of just a string that is shorter than | 3411 | /* Special case for regex consisting of just a string that is shorter than |
3402 | * max_len */ | 3412 | * max_len */ |
@@ -3404,18 +3414,12 @@ iterate_initial_edge (unsigned int min_len, | |||
3404 | edge[0].destination = state->hash; | 3414 | edge[0].destination = state->hash; |
3405 | temp = GNUNET_strdup (consumed_string); | 3415 | temp = GNUNET_strdup (consumed_string); |
3406 | temp[cur_len - 1] = '\0'; | 3416 | temp[cur_len - 1] = '\0'; |
3407 | GNUNET_CRYPTO_hash (temp, | 3417 | GNUNET_CRYPTO_hash (temp, cur_len - 1, &hash_new); |
3408 | cur_len - 1, | ||
3409 | &hash_new); | ||
3410 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3418 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3411 | "Start state for short string `%s' is %s\n", | 3419 | "Start state for short string `%s' is %s\n", |
3412 | temp, | 3420 | temp, |
3413 | GNUNET_h2s (&hash_new)); | 3421 | GNUNET_h2s (&hash_new)); |
3414 | iterator (iterator_cls, | 3422 | iterator (iterator_cls, &hash_new, temp, GNUNET_NO, 1, edge); |
3415 | &hash_new, | ||
3416 | temp, | ||
3417 | GNUNET_NO, 1, | ||
3418 | edge); | ||
3419 | GNUNET_free (temp); | 3423 | GNUNET_free (temp); |
3420 | } | 3424 | } |
3421 | } | 3425 | } |
@@ -3432,12 +3436,7 @@ iterate_initial_edge (unsigned int min_len, | |||
3432 | temp, | 3436 | temp, |
3433 | edge[0].label, | 3437 | edge[0].label, |
3434 | GNUNET_h2s (&hash_new)); | 3438 | GNUNET_h2s (&hash_new)); |
3435 | iterator (iterator_cls, | 3439 | iterator (iterator_cls, &hash, temp, GNUNET_NO, 1, edge); |
3436 | &hash, | ||
3437 | temp, | ||
3438 | GNUNET_NO, | ||
3439 | 1, | ||
3440 | edge); | ||
3441 | GNUNET_free (temp); | 3440 | GNUNET_free (temp); |
3442 | } | 3441 | } |
3443 | } | 3442 | } |
@@ -3446,22 +3445,16 @@ iterate_initial_edge (unsigned int min_len, | |||
3446 | { | 3445 | { |
3447 | for (t = state->transitions_head; NULL != t; t = t->next) | 3446 | for (t = state->transitions_head; NULL != t; t = t->next) |
3448 | { | 3447 | { |
3449 | if (NULL != strchr (t->label, | 3448 | if (NULL != strchr (t->label, (int) '.')) |
3450 | (int) '.')) | ||
3451 | { | 3449 | { |
3452 | /* Wildcards not allowed during starting states */ | 3450 | /* Wildcards not allowed during starting states */ |
3453 | GNUNET_break (0); | 3451 | GNUNET_break (0); |
3454 | continue; | 3452 | continue; |
3455 | } | 3453 | } |
3456 | if (NULL != consumed_string) | 3454 | if (NULL != consumed_string) |
3457 | GNUNET_asprintf (&temp, | 3455 | GNUNET_asprintf (&temp, "%s%s", consumed_string, t->label); |
3458 | "%s%s", | ||
3459 | consumed_string, | ||
3460 | t->label); | ||
3461 | else | 3456 | else |
3462 | GNUNET_asprintf (&temp, | 3457 | GNUNET_asprintf (&temp, "%s", t->label); |
3463 | "%s", | ||
3464 | t->label); | ||
3465 | iterate_initial_edge (min_len, | 3458 | iterate_initial_edge (min_len, |
3466 | max_len, | 3459 | max_len, |
3467 | temp, | 3460 | temp, |
@@ -3489,30 +3482,32 @@ REGEX_INTERNAL_iterate_all_edges (struct REGEX_INTERNAL_Automaton *a, | |||
3489 | { | 3482 | { |
3490 | struct REGEX_INTERNAL_State *s; | 3483 | struct REGEX_INTERNAL_State *s; |
3491 | 3484 | ||
3492 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3485 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating over starting edges\n"); |
3493 | "Iterating over starting edges\n"); | ||
3494 | iterate_initial_edge (GNUNET_REGEX_INITIAL_BYTES, | 3486 | iterate_initial_edge (GNUNET_REGEX_INITIAL_BYTES, |
3495 | GNUNET_REGEX_INITIAL_BYTES, | 3487 | GNUNET_REGEX_INITIAL_BYTES, |
3496 | NULL, a->start, | 3488 | NULL, |
3497 | iterator, iterator_cls); | 3489 | a->start, |
3498 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3490 | iterator, |
3499 | "Iterating over DFA edges\n"); | 3491 | iterator_cls); |
3492 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating over DFA edges\n"); | ||
3500 | for (s = a->states_head; NULL != s; s = s->next) | 3493 | for (s = a->states_head; NULL != s; s = s->next) |
3501 | { | 3494 | { |
3502 | struct REGEX_BLOCK_Edge edges[s->transition_count]; | 3495 | struct REGEX_BLOCK_Edge edges[s->transition_count]; |
3503 | unsigned int num_edges; | 3496 | unsigned int num_edges; |
3504 | 3497 | ||
3505 | num_edges = state_get_edges (s, edges); | 3498 | num_edges = state_get_edges (s, edges); |
3506 | if ( ( (NULL != s->proof) && | 3499 | if (((NULL != s->proof) && (0 < strlen (s->proof))) || s->accepting) |
3507 | (0 < strlen (s->proof)) ) || s->accepting) | ||
3508 | { | 3500 | { |
3509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3501 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3510 | "Creating DFA edges at `%s' under key %s\n", | 3502 | "Creating DFA edges at `%s' under key %s\n", |
3511 | s->proof, | 3503 | s->proof, |
3512 | GNUNET_h2s (&s->hash)); | 3504 | GNUNET_h2s (&s->hash)); |
3513 | iterator (iterator_cls, &s->hash, s->proof, | 3505 | iterator (iterator_cls, |
3506 | &s->hash, | ||
3507 | s->proof, | ||
3514 | s->accepting, | 3508 | s->accepting, |
3515 | num_edges, edges); | 3509 | num_edges, |
3510 | edges); | ||
3516 | } | 3511 | } |
3517 | s->marked = GNUNET_NO; | 3512 | s->marked = GNUNET_NO; |
3518 | } | 3513 | } |
@@ -3525,7 +3520,8 @@ REGEX_INTERNAL_iterate_all_edges (struct REGEX_INTERNAL_Automaton *a, | |||
3525 | * Contains the same info as the Regex Iterator parametes except the key, | 3520 | * Contains the same info as the Regex Iterator parametes except the key, |
3526 | * which comes directly from the HashMap iterator. | 3521 | * which comes directly from the HashMap iterator. |
3527 | */ | 3522 | */ |
3528 | struct temporal_state_store { | 3523 | struct temporal_state_store |
3524 | { | ||
3529 | int reachable; | 3525 | int reachable; |
3530 | char *proof; | 3526 | char *proof; |
3531 | int accepting; | 3527 | int accepting; |
@@ -3537,7 +3533,8 @@ struct temporal_state_store { | |||
3537 | /** | 3533 | /** |
3538 | * Store regex iterator and cls in one place to pass to the hashmap iterator. | 3534 | * Store regex iterator and cls in one place to pass to the hashmap iterator. |
3539 | */ | 3535 | */ |
3540 | struct client_iterator { | 3536 | struct client_iterator |
3537 | { | ||
3541 | REGEX_INTERNAL_KeyIterator iterator; | 3538 | REGEX_INTERNAL_KeyIterator iterator; |
3542 | void *iterator_cls; | 3539 | void *iterator_cls; |
3543 | }; | 3540 | }; |
@@ -3573,9 +3570,13 @@ store_all_states (void *cls, | |||
3573 | tmp->num_edges = num_edges; | 3570 | tmp->num_edges = num_edges; |
3574 | edges_size = sizeof (struct REGEX_BLOCK_Edge) * num_edges; | 3571 | edges_size = sizeof (struct REGEX_BLOCK_Edge) * num_edges; |
3575 | tmp->edges = GNUNET_malloc (edges_size); | 3572 | tmp->edges = GNUNET_malloc (edges_size); |
3576 | GNUNET_memcpy(tmp->edges, edges, edges_size); | 3573 | GNUNET_memcpy (tmp->edges, edges, edges_size); |
3577 | GNUNET_CONTAINER_multihashmap_put (hm, key, tmp, | 3574 | GNUNET_assert (GNUNET_YES == |
3578 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 3575 | GNUNET_CONTAINER_multihashmap_put ( |
3576 | hm, | ||
3577 | key, | ||
3578 | tmp, | ||
3579 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | ||
3579 | } | 3580 | } |
3580 | 3581 | ||
3581 | 3582 | ||
@@ -3601,8 +3602,8 @@ mark_as_reachable (struct temporal_state_store *state, | |||
3601 | state->reachable = GNUNET_YES; | 3602 | state->reachable = GNUNET_YES; |
3602 | for (i = 0; i < state->num_edges; i++) | 3603 | for (i = 0; i < state->num_edges; i++) |
3603 | { | 3604 | { |
3604 | child = GNUNET_CONTAINER_multihashmap_get (hm, | 3605 | child = |
3605 | &state->edges[i].destination); | 3606 | GNUNET_CONTAINER_multihashmap_get (hm, &state->edges[i].destination); |
3606 | if (NULL == child) | 3607 | if (NULL == child) |
3607 | { | 3608 | { |
3608 | GNUNET_break (0); | 3609 | GNUNET_break (0); |
@@ -3655,24 +3656,24 @@ reachability_iterator (void *cls, | |||
3655 | * #GNUNET_NO if not. | 3656 | * #GNUNET_NO if not. |
3656 | */ | 3657 | */ |
3657 | static int | 3658 | static int |
3658 | iterate_reachables (void *cls, | 3659 | iterate_reachables (void *cls, const struct GNUNET_HashCode *key, void *value) |
3659 | const struct GNUNET_HashCode *key, | ||
3660 | void *value) | ||
3661 | { | 3660 | { |
3662 | struct client_iterator *ci = cls; | 3661 | struct client_iterator *ci = cls; |
3663 | struct temporal_state_store *state = value; | 3662 | struct temporal_state_store *state = value; |
3664 | 3663 | ||
3665 | if (GNUNET_YES == state->reachable) | 3664 | if (GNUNET_YES == state->reachable) |
3666 | { | 3665 | { |
3667 | ci->iterator (ci->iterator_cls, key, | 3666 | ci->iterator (ci->iterator_cls, |
3668 | state->proof, state->accepting, | 3667 | key, |
3669 | state->num_edges, state->edges); | 3668 | state->proof, |
3669 | state->accepting, | ||
3670 | state->num_edges, | ||
3671 | state->edges); | ||
3670 | } | 3672 | } |
3671 | GNUNET_free (state->edges); | 3673 | GNUNET_free (state->edges); |
3672 | GNUNET_free (state->proof); | 3674 | GNUNET_free (state->proof); |
3673 | GNUNET_free (state); | 3675 | GNUNET_free (state); |
3674 | return GNUNET_YES; | 3676 | return GNUNET_YES; |
3675 | |||
3676 | } | 3677 | } |
3677 | 3678 | ||
3678 | /** | 3679 | /** |
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c index bf111ade2..bc30670e9 100644 --- a/src/statistics/gnunet-statistics.c +++ b/src/statistics/gnunet-statistics.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -93,7 +93,8 @@ static int set_value; | |||
93 | /** | 93 | /** |
94 | * @brief Representation of all (testbed) nodes. | 94 | * @brief Representation of all (testbed) nodes. |
95 | */ | 95 | */ |
96 | static struct Node { | 96 | static struct Node |
97 | { | ||
97 | /** | 98 | /** |
98 | * @brief Index of the node in this array. | 99 | * @brief Index of the node in this array. |
99 | */ | 100 | */ |
@@ -117,7 +118,7 @@ static struct Node { | |||
117 | * @brief Identifier for shutdown task for this node. | 118 | * @brief Identifier for shutdown task for this node. |
118 | */ | 119 | */ |
119 | struct GNUNET_SCHEDULER_Task *shutdown_task; | 120 | struct GNUNET_SCHEDULER_Task *shutdown_task; |
120 | } *nodes; | 121 | } * nodes; |
121 | 122 | ||
122 | /** | 123 | /** |
123 | * @brief Number of configurations of all (testbed) nodes. | 124 | * @brief Number of configurations of all (testbed) nodes. |
@@ -204,11 +205,9 @@ new_value_set (const char *subsystem, | |||
204 | * @return GNUNET_YES - continue iteration. | 205 | * @return GNUNET_YES - continue iteration. |
205 | */ | 206 | */ |
206 | static int | 207 | static int |
207 | printer (void *cls, | 208 | printer (void *cls, const struct GNUNET_HashCode *key, void *value) |
208 | const struct GNUNET_HashCode *key, | ||
209 | void *value) | ||
210 | { | 209 | { |
211 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); | 210 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
212 | const char *now_str; | 211 | const char *now_str; |
213 | struct ValueSet *value_set = value; | 212 | struct ValueSet *value_set = value; |
214 | 213 | ||
@@ -218,38 +217,38 @@ printer (void *cls, | |||
218 | { | 217 | { |
219 | now_str = GNUNET_STRINGS_absolute_time_to_string (now); | 218 | now_str = GNUNET_STRINGS_absolute_time_to_string (now); |
220 | FPRINTF (stdout, | 219 | FPRINTF (stdout, |
221 | "%24s%s %s%s%12s%s %s%50s%s%s ", | 220 | "%24s%s %s%s%12s%s %s%50s%s%s ", |
222 | now_str, | 221 | now_str, |
223 | csv_separator, | 222 | csv_separator, |
224 | value_set->is_persistent ? "!" : " ", | 223 | value_set->is_persistent ? "!" : " ", |
225 | csv_separator, | 224 | csv_separator, |
226 | value_set->subsystem, | 225 | value_set->subsystem, |
227 | csv_separator, | 226 | csv_separator, |
228 | (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */ | 227 | (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */ |
229 | _(value_set->name), | 228 | _ (value_set->name), |
230 | (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */ | 229 | (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */ |
231 | (0 == strlen (csv_separator) ? ":": csv_separator)); | 230 | (0 == strlen (csv_separator) ? ":" : csv_separator)); |
232 | } | 231 | } |
233 | else | 232 | else |
234 | { | 233 | { |
235 | FPRINTF (stdout, | 234 | FPRINTF (stdout, |
236 | "%s%s%12s%s %s%50s%s%s ", | 235 | "%s%s%12s%s %s%50s%s%s ", |
237 | value_set->is_persistent ? "!" : " ", | 236 | value_set->is_persistent ? "!" : " ", |
238 | csv_separator, | 237 | csv_separator, |
239 | value_set->subsystem, | 238 | value_set->subsystem, |
240 | csv_separator, | 239 | csv_separator, |
241 | (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */ | 240 | (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */ |
242 | _(value_set->name), | 241 | _ (value_set->name), |
243 | (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */ | 242 | (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */ |
244 | (0 == strlen (csv_separator) ? ":": csv_separator)); | 243 | (0 == strlen (csv_separator) ? ":" : csv_separator)); |
245 | } | 244 | } |
246 | } | 245 | } |
247 | for (unsigned i = 0; i < num_nodes; i++) | 246 | for (unsigned i = 0; i < num_nodes; i++) |
248 | { | 247 | { |
249 | FPRINTF (stdout, | 248 | FPRINTF (stdout, |
250 | "%16llu%s", | 249 | "%16llu%s", |
251 | (unsigned long long) value_set->values[i], | 250 | (unsigned long long) value_set->values[i], |
252 | csv_separator); | 251 | csv_separator); |
253 | } | 252 | } |
254 | FPRINTF (stdout, "\n"); | 253 | FPRINTF (stdout, "\n"); |
255 | GNUNET_free (value_set->subsystem); | 254 | GNUNET_free (value_set->subsystem); |
@@ -276,7 +275,7 @@ printer_watch (void *cls, | |||
276 | uint64_t value, | 275 | uint64_t value, |
277 | int is_persistent) | 276 | int is_persistent) |
278 | { | 277 | { |
279 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); | 278 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
280 | const char *now_str; | 279 | const char *now_str; |
281 | 280 | ||
282 | if (quiet == GNUNET_NO) | 281 | if (quiet == GNUNET_NO) |
@@ -292,10 +291,10 @@ printer_watch (void *cls, | |||
292 | csv_separator, | 291 | csv_separator, |
293 | subsystem, | 292 | subsystem, |
294 | csv_separator, | 293 | csv_separator, |
295 | (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */ | 294 | (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */ |
296 | _(name), | 295 | _ (name), |
297 | (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */ | 296 | (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */ |
298 | (0 == strlen (csv_separator) ? ":": csv_separator), | 297 | (0 == strlen (csv_separator) ? ":" : csv_separator), |
299 | (unsigned long long) value); | 298 | (unsigned long long) value); |
300 | } | 299 | } |
301 | else | 300 | else |
@@ -306,17 +305,15 @@ printer_watch (void *cls, | |||
306 | csv_separator, | 305 | csv_separator, |
307 | subsystem, | 306 | subsystem, |
308 | csv_separator, | 307 | csv_separator, |
309 | (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */ | 308 | (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */ |
310 | _(name), | 309 | _ (name), |
311 | (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */ | 310 | (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */ |
312 | (0 == strlen (csv_separator) ? ":": csv_separator), | 311 | (0 == strlen (csv_separator) ? ":" : csv_separator), |
313 | (unsigned long long) value); | 312 | (unsigned long long) value); |
314 | } | 313 | } |
315 | } | 314 | } |
316 | else | 315 | else |
317 | FPRINTF (stdout, | 316 | FPRINTF (stdout, "%llu\n", (unsigned long long) value); |
318 | "%llu\n", | ||
319 | (unsigned long long) value); | ||
320 | 317 | ||
321 | return GNUNET_OK; | 318 | return GNUNET_OK; |
322 | } | 319 | } |
@@ -335,8 +332,8 @@ clean_node (void *cls) | |||
335 | struct GNUNET_STATISTICS_Handle *h; | 332 | struct GNUNET_STATISTICS_Handle *h; |
336 | struct GNUNET_STATISTICS_GetHandle *gh; | 333 | struct GNUNET_STATISTICS_GetHandle *gh; |
337 | 334 | ||
338 | if ( (NULL != path_testbed) && /* were issued with -t <testbed-path> option */ | 335 | if ((NULL != path_testbed) && /* were issued with -t <testbed-path> option */ |
339 | (NULL != nodes[index_node].conf) ) | 336 | (NULL != nodes[index_node].conf)) |
340 | { | 337 | { |
341 | GNUNET_CONFIGURATION_destroy (nodes[index_node].conf); | 338 | GNUNET_CONFIGURATION_destroy (nodes[index_node].conf); |
342 | nodes[index_node].conf = NULL; | 339 | nodes[index_node].conf = NULL; |
@@ -352,7 +349,8 @@ clean_node (void *cls) | |||
352 | } | 349 | } |
353 | if (GNUNET_YES == watch) | 350 | if (GNUNET_YES == watch) |
354 | { | 351 | { |
355 | GNUNET_assert (GNUNET_OK == | 352 | GNUNET_assert ( |
353 | GNUNET_OK == | ||
356 | GNUNET_STATISTICS_watch_cancel (h, | 354 | GNUNET_STATISTICS_watch_cancel (h, |
357 | subsystem, | 355 | subsystem, |
358 | name, | 356 | name, |
@@ -383,7 +381,7 @@ static void | |||
383 | print_finish (void *cls) | 381 | print_finish (void *cls) |
384 | { | 382 | { |
385 | GNUNET_CONTAINER_multihashmap_iterate (values, printer, NULL); | 383 | GNUNET_CONTAINER_multihashmap_iterate (values, printer, NULL); |
386 | GNUNET_SCHEDULER_shutdown(); | 384 | GNUNET_SCHEDULER_shutdown (); |
387 | } | 385 | } |
388 | 386 | ||
389 | /** | 387 | /** |
@@ -395,8 +393,7 @@ print_finish (void *cls) | |||
395 | * @param succes Whether statistics were obtained successfully. | 393 | * @param succes Whether statistics were obtained successfully. |
396 | */ | 394 | */ |
397 | static void | 395 | static void |
398 | continuation_print (void *cls, | 396 | continuation_print (void *cls, int success) |
399 | int success) | ||
400 | { | 397 | { |
401 | const unsigned index_node = *(unsigned *) cls; | 398 | const unsigned index_node = *(unsigned *) cls; |
402 | 399 | ||
@@ -404,12 +401,10 @@ continuation_print (void *cls, | |||
404 | if (GNUNET_OK != success) | 401 | if (GNUNET_OK != success) |
405 | { | 402 | { |
406 | if (NULL == remote_host) | 403 | if (NULL == remote_host) |
407 | FPRINTF (stderr, | 404 | FPRINTF (stderr, "%s", _ ("Failed to obtain statistics.\n")); |
408 | "%s", | ||
409 | _("Failed to obtain statistics.\n")); | ||
410 | else | 405 | else |
411 | FPRINTF (stderr, | 406 | FPRINTF (stderr, |
412 | _("Failed to obtain statistics from host `%s:%llu'\n"), | 407 | _ ("Failed to obtain statistics from host `%s:%llu'\n"), |
413 | remote_host, | 408 | remote_host, |
414 | remote_port); | 409 | remote_port); |
415 | ret = 1; | 410 | ret = 1; |
@@ -435,8 +430,7 @@ continuation_print (void *cls, | |||
435 | * successfully obtained, #GNUNET_SYSERR if not. | 430 | * successfully obtained, #GNUNET_SYSERR if not. |
436 | */ | 431 | */ |
437 | static void | 432 | static void |
438 | cleanup (void *cls, | 433 | cleanup (void *cls, int success) |
439 | int success) | ||
440 | { | 434 | { |
441 | for (unsigned i = 0; i < num_nodes; i++) | 435 | for (unsigned i = 0; i < num_nodes; i++) |
442 | { | 436 | { |
@@ -445,12 +439,10 @@ cleanup (void *cls, | |||
445 | if (GNUNET_OK != success) | 439 | if (GNUNET_OK != success) |
446 | { | 440 | { |
447 | if (NULL == remote_host) | 441 | if (NULL == remote_host) |
448 | FPRINTF (stderr, | 442 | FPRINTF (stderr, "%s", _ ("Failed to obtain statistics.\n")); |
449 | "%s", | ||
450 | _("Failed to obtain statistics.\n")); | ||
451 | else | 443 | else |
452 | FPRINTF (stderr, | 444 | FPRINTF (stderr, |
453 | _("Failed to obtain statistics from host `%s:%llu'\n"), | 445 | _ ("Failed to obtain statistics from host `%s:%llu'\n"), |
454 | remote_host, | 446 | remote_host, |
455 | remote_port); | 447 | remote_port); |
456 | ret = 1; | 448 | ret = 1; |
@@ -492,19 +484,19 @@ collector (void *cls, | |||
492 | GNUNET_free (subsys_name); | 484 | GNUNET_free (subsys_name); |
493 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (values, key)) | 485 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (values, key)) |
494 | { | 486 | { |
495 | // get | ||
496 | value_set = GNUNET_CONTAINER_multihashmap_get (values, key); | 487 | value_set = GNUNET_CONTAINER_multihashmap_get (values, key); |
497 | } | 488 | } |
498 | else | 489 | else |
499 | { | 490 | { |
500 | // new | ||
501 | value_set = new_value_set (subsystem, name, num_nodes, is_persistent); | 491 | value_set = new_value_set (subsystem, name, num_nodes, is_persistent); |
502 | } | 492 | } |
503 | // write | ||
504 | value_set->values[index_node] = value; | 493 | value_set->values[index_node] = value; |
505 | // put | 494 | GNUNET_assert (GNUNET_YES == |
506 | GNUNET_CONTAINER_multihashmap_put (values, key, value_set, | 495 | GNUNET_CONTAINER_multihashmap_put ( |
507 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 496 | values, |
497 | key, | ||
498 | value_set, | ||
499 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
508 | return GNUNET_OK; | 500 | return GNUNET_OK; |
509 | } | 501 | } |
510 | 502 | ||
@@ -523,22 +515,17 @@ main_task (void *cls) | |||
523 | { | 515 | { |
524 | if (NULL == subsystem) | 516 | if (NULL == subsystem) |
525 | { | 517 | { |
526 | FPRINTF (stderr, | 518 | FPRINTF (stderr, "%s", _ ("Missing argument: subsystem \n")); |
527 | "%s", | ||
528 | _("Missing argument: subsystem \n")); | ||
529 | ret = 1; | 519 | ret = 1; |
530 | return; | 520 | return; |
531 | } | 521 | } |
532 | if (NULL == name) | 522 | if (NULL == name) |
533 | { | 523 | { |
534 | FPRINTF (stderr, | 524 | FPRINTF (stderr, "%s", _ ("Missing argument: name\n")); |
535 | "%s", | ||
536 | _("Missing argument: name\n")); | ||
537 | ret = 1; | 525 | ret = 1; |
538 | return; | 526 | return; |
539 | } | 527 | } |
540 | nodes[index_node].handle = GNUNET_STATISTICS_create (subsystem, | 528 | nodes[index_node].handle = GNUNET_STATISTICS_create (subsystem, cfg); |
541 | cfg); | ||
542 | if (NULL == nodes[index_node].handle) | 529 | if (NULL == nodes[index_node].handle) |
543 | { | 530 | { |
544 | ret = 1; | 531 | ret = 1; |
@@ -548,59 +535,51 @@ main_task (void *cls) | |||
548 | name, | 535 | name, |
549 | (uint64_t) set_val, | 536 | (uint64_t) set_val, |
550 | persistent); | 537 | persistent); |
551 | GNUNET_STATISTICS_destroy (nodes[index_node].handle, | 538 | GNUNET_STATISTICS_destroy (nodes[index_node].handle, GNUNET_YES); |
552 | GNUNET_YES); | ||
553 | nodes[index_node].handle = NULL; | 539 | nodes[index_node].handle = NULL; |
554 | return; | 540 | return; |
555 | } | 541 | } |
556 | if (NULL == (nodes[index_node].handle = GNUNET_STATISTICS_create ("gnunet-statistics", | 542 | if (NULL == (nodes[index_node].handle = |
557 | cfg))) | 543 | GNUNET_STATISTICS_create ("gnunet-statistics", cfg))) |
558 | { | 544 | { |
559 | ret = 1; | 545 | ret = 1; |
560 | return; | 546 | return; |
561 | } | 547 | } |
562 | if (GNUNET_NO == watch) | 548 | if (GNUNET_NO == watch) |
563 | { | 549 | { |
564 | if (NULL == | 550 | if (NULL == (nodes[index_node].gh = |
565 | (nodes[index_node].gh = GNUNET_STATISTICS_get (nodes[index_node].handle, | 551 | GNUNET_STATISTICS_get (nodes[index_node].handle, |
566 | subsystem, | 552 | subsystem, |
567 | name, | 553 | name, |
568 | &continuation_print, | 554 | &continuation_print, |
569 | &collector, | 555 | &collector, |
570 | &nodes[index_node].index_node)) ) | 556 | &nodes[index_node].index_node))) |
571 | cleanup (nodes[index_node].handle, | 557 | cleanup (nodes[index_node].handle, GNUNET_SYSERR); |
572 | GNUNET_SYSERR); | ||
573 | } | 558 | } |
574 | else | 559 | else |
575 | { | 560 | { |
576 | if ( (NULL == subsystem) || | 561 | if ((NULL == subsystem) || (NULL == name)) |
577 | (NULL == name) ) | ||
578 | { | 562 | { |
579 | printf (_("No subsystem or name given\n")); | 563 | printf (_ ("No subsystem or name given\n")); |
580 | GNUNET_STATISTICS_destroy (nodes[index_node].handle, | 564 | GNUNET_STATISTICS_destroy (nodes[index_node].handle, GNUNET_NO); |
581 | GNUNET_NO); | ||
582 | nodes[index_node].handle = NULL; | 565 | nodes[index_node].handle = NULL; |
583 | ret = 1; | 566 | ret = 1; |
584 | return; | 567 | return; |
585 | } | 568 | } |
586 | if (GNUNET_OK != | 569 | if (GNUNET_OK != GNUNET_STATISTICS_watch (nodes[index_node].handle, |
587 | GNUNET_STATISTICS_watch (nodes[index_node].handle, | 570 | subsystem, |
588 | subsystem, | 571 | name, |
589 | name, | 572 | &printer_watch, |
590 | &printer_watch, | 573 | &nodes[index_node].index_node)) |
591 | &nodes[index_node].index_node)) | ||
592 | { | 574 | { |
593 | fprintf (stderr, | 575 | fprintf (stderr, _ ("Failed to initialize watch routine\n")); |
594 | _("Failed to initialize watch routine\n")); | ||
595 | nodes[index_node].shutdown_task = | 576 | nodes[index_node].shutdown_task = |
596 | GNUNET_SCHEDULER_add_now (&clean_node, | 577 | GNUNET_SCHEDULER_add_now (&clean_node, &nodes[index_node].index_node); |
597 | &nodes[index_node].index_node); | ||
598 | return; | 578 | return; |
599 | } | 579 | } |
600 | } | 580 | } |
601 | nodes[index_node].shutdown_task = | 581 | nodes[index_node].shutdown_task = |
602 | GNUNET_SCHEDULER_add_shutdown (&clean_node, | 582 | GNUNET_SCHEDULER_add_shutdown (&clean_node, &nodes[index_node].index_node); |
603 | &nodes[index_node].index_node); | ||
604 | } | 583 | } |
605 | 584 | ||
606 | /** | 585 | /** |
@@ -615,16 +594,16 @@ main_task (void *cls) | |||
615 | * @return to continue iteration or not to | 594 | * @return to continue iteration or not to |
616 | */ | 595 | */ |
617 | static int | 596 | static int |
618 | iter_check_config (void *cls, | 597 | iter_check_config (void *cls, const char *filename) |
619 | const char *filename) | ||
620 | { | 598 | { |
621 | if (0 == strncmp (GNUNET_STRINGS_get_short_name (filename), "config", 6)) | 599 | if (0 == strncmp (GNUNET_STRINGS_get_short_name (filename), "config", 6)) |
622 | { | 600 | { |
623 | /* Found the config - stop iteration successfully */ | 601 | /* Found the config - stop iteration successfully */ |
624 | GNUNET_array_grow (nodes, num_nodes, num_nodes+1); | 602 | GNUNET_array_grow (nodes, num_nodes, num_nodes + 1); |
625 | nodes[num_nodes-1].conf = GNUNET_CONFIGURATION_create(); | 603 | nodes[num_nodes - 1].conf = GNUNET_CONFIGURATION_create (); |
626 | nodes[num_nodes-1].index_node = num_nodes-1; | 604 | nodes[num_nodes - 1].index_node = num_nodes - 1; |
627 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (nodes[num_nodes-1].conf, filename)) | 605 | if (GNUNET_OK != |
606 | GNUNET_CONFIGURATION_load (nodes[num_nodes - 1].conf, filename)) | ||
628 | { | 607 | { |
629 | FPRINTF (stderr, "Failed loading config `%s'\n", filename); | 608 | FPRINTF (stderr, "Failed loading config `%s'\n", filename); |
630 | return GNUNET_SYSERR; | 609 | return GNUNET_SYSERR; |
@@ -652,19 +631,14 @@ iter_check_config (void *cls, | |||
652 | * @return status whether to continue iteration | 631 | * @return status whether to continue iteration |
653 | */ | 632 | */ |
654 | static int | 633 | static int |
655 | iter_testbed_path (void *cls, | 634 | iter_testbed_path (void *cls, const char *filename) |
656 | const char *filename) | ||
657 | { | 635 | { |
658 | unsigned index_node; | 636 | unsigned index_node; |
659 | 637 | ||
660 | GNUNET_assert (NULL != filename); | 638 | GNUNET_assert (NULL != filename); |
661 | if (1 == SSCANF (GNUNET_STRINGS_get_short_name (filename), | 639 | if (1 == SSCANF (GNUNET_STRINGS_get_short_name (filename), "%u", &index_node)) |
662 | "%u", | ||
663 | &index_node)) | ||
664 | { | 640 | { |
665 | if (-1 == GNUNET_DISK_directory_scan (filename, | 641 | if (-1 == GNUNET_DISK_directory_scan (filename, iter_check_config, NULL)) |
666 | iter_check_config, | ||
667 | NULL)) | ||
668 | { | 642 | { |
669 | /* This is probably no directory for a testbed node | 643 | /* This is probably no directory for a testbed node |
670 | * Go on with iteration */ | 644 | * Go on with iteration */ |
@@ -687,14 +661,11 @@ discover_testbed_nodes (const char *path_testbed) | |||
687 | { | 661 | { |
688 | int num_dir_entries; | 662 | int num_dir_entries; |
689 | 663 | ||
690 | num_dir_entries = GNUNET_DISK_directory_scan (path_testbed, | 664 | num_dir_entries = |
691 | iter_testbed_path, | 665 | GNUNET_DISK_directory_scan (path_testbed, iter_testbed_path, NULL); |
692 | NULL); | ||
693 | if (-1 == num_dir_entries) | 666 | if (-1 == num_dir_entries) |
694 | { | 667 | { |
695 | FPRINTF (stderr, | 668 | FPRINTF (stderr, "Failure during scanning directory `%s'\n", path_testbed); |
696 | "Failure during scanning directory `%s'\n", | ||
697 | path_testbed); | ||
698 | return -1; | 669 | return -1; |
699 | } | 670 | } |
700 | return 0; | 671 | return 0; |
@@ -718,16 +689,13 @@ run (void *cls, | |||
718 | 689 | ||
719 | c = (struct GNUNET_CONFIGURATION_Handle *) cfg; | 690 | c = (struct GNUNET_CONFIGURATION_Handle *) cfg; |
720 | set_value = GNUNET_NO; | 691 | set_value = GNUNET_NO; |
721 | if (NULL == csv_separator) csv_separator = ""; | 692 | if (NULL == csv_separator) |
693 | csv_separator = ""; | ||
722 | if (NULL != args[0]) | 694 | if (NULL != args[0]) |
723 | { | 695 | { |
724 | if (1 != SSCANF (args[0], | 696 | if (1 != SSCANF (args[0], "%llu", &set_val)) |
725 | "%llu", | ||
726 | &set_val)) | ||
727 | { | 697 | { |
728 | FPRINTF (stderr, | 698 | FPRINTF (stderr, _ ("Invalid argument `%s'\n"), args[0]); |
729 | _("Invalid argument `%s'\n"), | ||
730 | args[0]); | ||
731 | ret = 1; | 699 | ret = 1; |
732 | return; | 700 | return; |
733 | } | 701 | } |
@@ -737,39 +705,36 @@ run (void *cls, | |||
737 | { | 705 | { |
738 | if (0 == remote_port) | 706 | if (0 == remote_port) |
739 | { | 707 | { |
740 | if (GNUNET_SYSERR == | 708 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, |
741 | GNUNET_CONFIGURATION_get_value_number (cfg, | 709 | "statistics", |
742 | "statistics", | 710 | "PORT", |
743 | "PORT", | 711 | &remote_port)) |
744 | &remote_port)) | ||
745 | { | 712 | { |
746 | FPRINTF (stderr, | 713 | FPRINTF (stderr, |
747 | _("A port is required to connect to host `%s'\n"), | 714 | _ ("A port is required to connect to host `%s'\n"), |
748 | remote_host); | 715 | remote_host); |
749 | return; | 716 | return; |
750 | } | 717 | } |
751 | } | 718 | } |
752 | else if (65535 <= remote_port) | 719 | else if (65535 <= remote_port) |
753 | { | 720 | { |
754 | FPRINTF (stderr, | 721 | FPRINTF (stderr, |
755 | _("A port has to be between 1 and 65535 to connect to host `%s'\n"), | 722 | _ ( |
756 | remote_host); | 723 | "A port has to be between 1 and 65535 to connect to host `%s'\n"), |
724 | remote_host); | ||
757 | return; | 725 | return; |
758 | } | 726 | } |
759 | 727 | ||
760 | /* Manipulate configuration */ | 728 | /* Manipulate configuration */ |
729 | GNUNET_CONFIGURATION_set_value_string (c, "statistics", "UNIXPATH", ""); | ||
761 | GNUNET_CONFIGURATION_set_value_string (c, | 730 | GNUNET_CONFIGURATION_set_value_string (c, |
762 | "statistics", | 731 | "statistics", |
763 | "UNIXPATH", | 732 | "HOSTNAME", |
764 | ""); | 733 | remote_host); |
765 | GNUNET_CONFIGURATION_set_value_string (c, | ||
766 | "statistics", | ||
767 | "HOSTNAME", | ||
768 | remote_host); | ||
769 | GNUNET_CONFIGURATION_set_value_number (c, | 734 | GNUNET_CONFIGURATION_set_value_number (c, |
770 | "statistics", | 735 | "statistics", |
771 | "PORT", | 736 | "PORT", |
772 | remote_port); | 737 | remote_port); |
773 | } | 738 | } |
774 | if (NULL == path_testbed) | 739 | if (NULL == path_testbed) |
775 | { | 740 | { |
@@ -783,7 +748,8 @@ run (void *cls, | |||
783 | { | 748 | { |
784 | if (GNUNET_YES == watch) | 749 | if (GNUNET_YES == watch) |
785 | { | 750 | { |
786 | printf (_("Not able to watch testbed nodes (yet - feel free to implement)\n")); | 751 | printf ( |
752 | _ ("Not able to watch testbed nodes (yet - feel free to implement)\n")); | ||
787 | ret = 1; | 753 | ret = 1; |
788 | return; | 754 | return; |
789 | } | 755 | } |
@@ -795,8 +761,7 @@ run (void *cls, | |||
795 | /* For each config/node collect statistics */ | 761 | /* For each config/node collect statistics */ |
796 | for (unsigned i = 0; i < num_nodes; i++) | 762 | for (unsigned i = 0; i < num_nodes; i++) |
797 | { | 763 | { |
798 | GNUNET_SCHEDULER_add_now (&main_task, | 764 | GNUNET_SCHEDULER_add_now (&main_task, &nodes[i].index_node); |
799 | &nodes[i].index_node); | ||
800 | } | 765 | } |
801 | } | 766 | } |
802 | } | 767 | } |
@@ -812,78 +777,82 @@ run (void *cls, | |||
812 | int | 777 | int |
813 | main (int argc, char *const *argv) | 778 | main (int argc, char *const *argv) |
814 | { | 779 | { |
815 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 780 | struct GNUNET_GETOPT_CommandLineOption options[] = |
816 | GNUNET_GETOPT_option_string ('n', | 781 | {GNUNET_GETOPT_option_string ( |
817 | "name", | 782 | 'n', |
818 | "NAME", | 783 | "name", |
819 | gettext_noop ("limit output to statistics for the given NAME"), | 784 | "NAME", |
820 | &name), | 785 | gettext_noop ("limit output to statistics for the given NAME"), |
821 | 786 | &name), | |
822 | GNUNET_GETOPT_option_flag ('p', | 787 | |
823 | "persistent", | 788 | GNUNET_GETOPT_option_flag ('p', |
824 | gettext_noop ("make the value being set persistent"), | 789 | "persistent", |
825 | &persistent), | 790 | gettext_noop ( |
826 | 791 | "make the value being set persistent"), | |
827 | GNUNET_GETOPT_option_string ('s', | 792 | &persistent), |
828 | "subsystem", | 793 | |
829 | "SUBSYSTEM", | 794 | GNUNET_GETOPT_option_string ('s', |
830 | gettext_noop ("limit output to the given SUBSYSTEM"), | 795 | "subsystem", |
831 | &subsystem), | 796 | "SUBSYSTEM", |
832 | 797 | gettext_noop ( | |
833 | GNUNET_GETOPT_option_string ('S', | 798 | "limit output to the given SUBSYSTEM"), |
834 | "csv-separator", | 799 | &subsystem), |
835 | "CSV_SEPARATOR", | 800 | |
836 | gettext_noop ("use as csv separator"), | 801 | GNUNET_GETOPT_option_string ('S', |
837 | &csv_separator), | 802 | "csv-separator", |
838 | 803 | "CSV_SEPARATOR", | |
839 | GNUNET_GETOPT_option_filename ('t', | 804 | gettext_noop ("use as csv separator"), |
840 | "testbed", | 805 | &csv_separator), |
841 | "TESTBED", | 806 | |
842 | gettext_noop ("path to the folder containing the testbed data"), | 807 | GNUNET_GETOPT_option_filename ( |
843 | &path_testbed), | 808 | 't', |
844 | 809 | "testbed", | |
845 | GNUNET_GETOPT_option_flag ('q', | 810 | "TESTBED", |
846 | "quiet", | 811 | gettext_noop ("path to the folder containing the testbed data"), |
847 | gettext_noop ("just print the statistics value"), | 812 | &path_testbed), |
848 | &quiet), | 813 | |
849 | 814 | GNUNET_GETOPT_option_flag ('q', | |
850 | GNUNET_GETOPT_option_flag ('w', | 815 | "quiet", |
851 | "watch", | 816 | gettext_noop ( |
852 | gettext_noop ("watch value continuously"), | 817 | "just print the statistics value"), |
853 | &watch), | 818 | &quiet), |
854 | 819 | ||
855 | GNUNET_GETOPT_option_string ('r', | 820 | GNUNET_GETOPT_option_flag ('w', |
856 | "remote", | 821 | "watch", |
857 | "REMOTE", | 822 | gettext_noop ("watch value continuously"), |
858 | gettext_noop ("connect to remote host"), | 823 | &watch), |
859 | &remote_host), | 824 | |
860 | 825 | GNUNET_GETOPT_option_string ('r', | |
861 | GNUNET_GETOPT_option_ulong ('o', | 826 | "remote", |
862 | "port", | 827 | "REMOTE", |
863 | "PORT", | 828 | gettext_noop ("connect to remote host"), |
864 | gettext_noop ("port for remote host"), | 829 | &remote_host), |
865 | &remote_port), | 830 | |
866 | 831 | GNUNET_GETOPT_option_ulong ('o', | |
867 | GNUNET_GETOPT_OPTION_END | 832 | "port", |
868 | }; | 833 | "PORT", |
834 | gettext_noop ("port for remote host"), | ||
835 | &remote_port), | ||
836 | |||
837 | GNUNET_GETOPT_OPTION_END}; | ||
869 | remote_port = 0; | 838 | remote_port = 0; |
870 | remote_host = NULL; | 839 | remote_host = NULL; |
871 | if (GNUNET_OK != | 840 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
872 | GNUNET_STRINGS_get_utf8_args (argc, argv, | ||
873 | &argc, &argv)) | ||
874 | return 2; | 841 | return 2; |
875 | 842 | ||
876 | ret = (GNUNET_OK == | 843 | ret = (GNUNET_OK == |
877 | GNUNET_PROGRAM_run (argc, | 844 | GNUNET_PROGRAM_run (argc, |
878 | argv, | 845 | argv, |
879 | "gnunet-statistics [options [value]]", | 846 | "gnunet-statistics [options [value]]", |
880 | gettext_noop | 847 | gettext_noop ( |
881 | ("Print statistics about GNUnet operations."), | 848 | "Print statistics about GNUnet operations."), |
882 | options, | 849 | options, |
883 | &run, | 850 | &run, |
884 | NULL)) ? ret : 1; | 851 | NULL)) |
852 | ? ret | ||
853 | : 1; | ||
885 | GNUNET_free_non_null (remote_host); | 854 | GNUNET_free_non_null (remote_host); |
886 | GNUNET_free ((void*) argv); | 855 | GNUNET_free ((void *) argv); |
887 | return ret; | 856 | return ret; |
888 | } | 857 | } |
889 | 858 | ||