aboutsummaryrefslogtreecommitdiff
path: root/src/datastore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-08-26 10:06:53 +0000
committerChristian Grothoff <christian@grothoff.org>2010-08-26 10:06:53 +0000
commitf02fbbebd73bfe88dc3122e9f8eb0b2c55837d16 (patch)
tree74f7e5a1df1f120d27ecb4b8b89011855e4eaa19 /src/datastore
parente743ae65c24457fa19823648c4714c837e49bfdd (diff)
downloadgnunet-f02fbbebd73bfe88dc3122e9f8eb0b2c55837d16.tar.gz
gnunet-f02fbbebd73bfe88dc3122e9f8eb0b2c55837d16.zip
use big endian
Diffstat (limited to 'src/datastore')
-rw-r--r--src/datastore/plugin_datastore_postgres.c191
-rw-r--r--src/datastore/test_datastore_api_data_postgres.conf2
2 files changed, 99 insertions, 94 deletions
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c
index 3b212c98b..332c8a768 100644
--- a/src/datastore/plugin_datastore_postgres.c
+++ b/src/datastore/plugin_datastore_postgres.c
@@ -90,18 +90,18 @@ struct NextRequestClosure
90 const char *paramValues[5]; 90 const char *paramValues[5];
91 const char *pname; 91 const char *pname;
92 int paramLengths[5]; 92 int paramLengths[5];
93 int nparams; // nparams 93 int nparams;
94 struct GNUNET_TIME_Absolute now; 94 uint64_t bnow;
95 GNUNET_HashCode key; 95 GNUNET_HashCode key;
96 GNUNET_HashCode vhash; 96 GNUNET_HashCode vhash;
97 long long count; 97 long long count;
98 long long off; 98 uint64_t off;
99 long long limit_off; 99 uint64_t blimit_off;
100 unsigned long long total; 100 unsigned long long total;
101 unsigned long long last_expire; 101 uint64_t blast_expire;
102 unsigned int last_rowid; // last_rowid 102 uint32_t blast_rowid;
103 unsigned int last_prio; 103 uint32_t blast_prio;
104 enum GNUNET_BLOCK_Type type; 104 uint32_t btype;
105 int end_it; 105 int end_it;
106}; 106};
107 107
@@ -487,22 +487,27 @@ postgres_plugin_put (void *cls,
487 struct Plugin *plugin = cls; 487 struct Plugin *plugin = cls;
488 GNUNET_HashCode vhash; 488 GNUNET_HashCode vhash;
489 PGresult *ret; 489 PGresult *ret;
490 uint32_t bsize = htonl (size);
491 uint32_t btype = htonl (type);
492 uint32_t bprio = htonl (priority);
493 uint32_t banon = htonl (anonymity);
494 uint64_t bexpi = GNUNET_TIME_absolute_hton (expiration).value__;
490 const char *paramValues[] = { 495 const char *paramValues[] = {
491 (const char *) &size, 496 (const char *) &bsize,
492 (const char *) &type, 497 (const char *) &btype,
493 (const char *) &priority, 498 (const char *) &bprio,
494 (const char *) &anonymity, 499 (const char *) &banon,
495 (const char *) &expiration.value, 500 (const char *) &bexpi,
496 (const char *) key, 501 (const char *) key,
497 (const char *) &vhash, 502 (const char *) &vhash,
498 (const char *) data 503 (const char *) data
499 }; 504 };
500 int paramLengths[] = { 505 int paramLengths[] = {
501 sizeof (size), 506 sizeof (bsize),
502 sizeof (type), 507 sizeof (btype),
503 sizeof (priority), 508 sizeof (bprio),
504 sizeof (anonymity), 509 sizeof (banon),
505 sizeof (expiration.value), 510 sizeof (bexpi),
506 sizeof (GNUNET_HashCode), 511 sizeof (GNUNET_HashCode),
507 sizeof (GNUNET_HashCode), 512 sizeof (GNUNET_HashCode),
508 size 513 size
@@ -539,9 +544,9 @@ postgres_next_request_cont (void *next_cls,
539 int iret; 544 int iret;
540 PGresult *res; 545 PGresult *res;
541 enum GNUNET_BLOCK_Type type; 546 enum GNUNET_BLOCK_Type type;
542 unsigned int anonymity; 547 uint32_t anonymity;
543 unsigned int priority; 548 uint32_t priority;
544 unsigned int size; 549 uint32_t size;
545 unsigned int rowid; 550 unsigned int rowid;
546 struct GNUNET_TIME_Absolute expiration_time; 551 struct GNUNET_TIME_Absolute expiration_time;
547 GNUNET_HashCode key; 552 GNUNET_HashCode key;
@@ -559,9 +564,9 @@ postgres_next_request_cont (void *next_cls,
559 564
560 565
561 if (nrc->count == 0) 566 if (nrc->count == 0)
562 nrc->limit_off = nrc->off; 567 nrc->blimit_off = GNUNET_htonll (nrc->off);
563 else 568 else
564 nrc->limit_off = 0; 569 nrc->blimit_off = GNUNET_htonll (0);
565 570
566 res = PQexecPrepared (plugin->dbh, 571 res = PQexecPrepared (plugin->dbh,
567 nrc->pname, 572 nrc->pname,
@@ -595,8 +600,8 @@ postgres_next_request_cont (void *next_cls,
595 } 600 }
596 if ((1 != PQntuples (res)) || 601 if ((1 != PQntuples (res)) ||
597 (8 != PQnfields (res)) || 602 (8 != PQnfields (res)) ||
598 (sizeof (unsigned int) != PQfsize (res, 0)) || 603 (sizeof (uint32_t) != PQfsize (res, 0)) ||
599 (sizeof (unsigned int) != PQfsize (res, 7))) 604 (sizeof (uint32_t) != PQfsize (res, 7)))
600 { 605 {
601 GNUNET_break (0); 606 GNUNET_break (0);
602 nrc->iter (nrc->iter_cls, 607 nrc->iter (nrc->iter_cls,
@@ -606,12 +611,12 @@ postgres_next_request_cont (void *next_cls,
606 GNUNET_free (nrc); 611 GNUNET_free (nrc);
607 return; 612 return;
608 } 613 }
609 rowid = *(unsigned int *) PQgetvalue (res, 0, 7); 614 rowid = ntohl (*(uint32_t *) PQgetvalue (res, 0, 7));
610 size = *(unsigned int *) PQgetvalue (res, 0, 0); 615 size = ntohl (*(uint32_t *) PQgetvalue (res, 0, 0));
611 if ((sizeof (unsigned int) != PQfsize (res, 1)) || 616 if ((sizeof (uint32_t) != PQfsize (res, 1)) ||
612 (sizeof (unsigned int) != PQfsize (res, 2)) || 617 (sizeof (uint32_t) != PQfsize (res, 2)) ||
613 (sizeof (unsigned int) != PQfsize (res, 3)) || 618 (sizeof (uint32_t) != PQfsize (res, 3)) ||
614 (sizeof (unsigned long long) != PQfsize (res, 4)) || 619 (sizeof (uint64_t) != PQfsize (res, 4)) ||
615 (sizeof (GNUNET_HashCode) != PQgetlength (res, 0, 5)) || 620 (sizeof (GNUNET_HashCode) != PQgetlength (res, 0, 5)) ||
616 (size != PQgetlength (res, 0, 6))) 621 (size != PQgetlength (res, 0, 6)))
617 { 622 {
@@ -625,16 +630,16 @@ postgres_next_request_cont (void *next_cls,
625 return; 630 return;
626 } 631 }
627 632
628 type = *(unsigned int *) PQgetvalue (res, 0, 1); 633 type = ntohl (*(uint32_t *) PQgetvalue (res, 0, 1));
629 priority = *(unsigned int *) PQgetvalue (res, 0, 2); 634 priority = ntohl (*(uint32_t *) PQgetvalue (res, 0, 2));
630 anonymity = *(unsigned int *) PQgetvalue (res, 0, 3); 635 anonymity = ntohl ( *(uint32_t *) PQgetvalue (res, 0, 3));
631 expiration_time.value = *(unsigned long long *) PQgetvalue (res, 0, 4); 636 expiration_time.value = GNUNET_ntohll (*(uint64_t *) PQgetvalue (res, 0, 4));
632 size = PQgetlength (res, 0, 6); 637 size = PQgetlength (res, 0, 6);
633 memcpy (&key, PQgetvalue (res, 0, 5), sizeof (GNUNET_HashCode)); 638 memcpy (&key, PQgetvalue (res, 0, 5), sizeof (GNUNET_HashCode));
634 639
635 nrc->last_prio = priority; 640 nrc->blast_prio = htonl (priority);
636 nrc->last_expire = expiration_time.value; 641 nrc->blast_expire = GNUNET_htonll (expiration_time.value);
637 nrc->last_rowid = rowid + 1; 642 nrc->blast_rowid = htonl (rowid + 1);
638 nrc->count++; 643 nrc->count++;
639 iret = nrc->iter (nrc->iter_cls, 644 iret = nrc->iter (nrc->iter_cls,
640 nrc, 645 nrc,
@@ -657,7 +662,6 @@ postgres_next_request_cont (void *next_cls,
657} 662}
658 663
659 664
660
661/** 665/**
662 * Function invoked on behalf of a "PluginIterator" 666 * Function invoked on behalf of a "PluginIterator"
663 * asking the database plugin to call the iterator 667 * asking the database plugin to call the iterator
@@ -715,18 +719,19 @@ postgres_plugin_update (void *cls,
715 char **msg) 719 char **msg)
716{ 720{
717 struct Plugin *plugin = cls; 721 struct Plugin *plugin = cls;
718 unsigned int oid = (unsigned int) uid; /* only 32 bit for postgres */
719 PGresult *ret; 722 PGresult *ret;
720 723 int32_t bdelta = (int32_t) htonl ((uint32_t) delta);
724 uint32_t boid = htonl ( (uint32_t) uid);
725 uint64_t bexpire = GNUNET_TIME_absolute_hton (expire).value__;
721 const char *paramValues[] = { 726 const char *paramValues[] = {
722 (const char *) &delta, 727 (const char *) &bdelta,
723 (const char *) &expire.value, 728 (const char *) &bexpire,
724 (const char *) &oid, 729 (const char *) &boid,
725 }; 730 };
726 int paramLengths[] = { 731 int paramLengths[] = {
727 sizeof (delta), 732 sizeof (bdelta),
728 sizeof (expire.value), 733 sizeof (bexpire),
729 sizeof (oid), 734 sizeof (boid),
730 }; 735 };
731 const int paramFormats[] = { 1, 1, 1 }; 736 const int paramFormats[] = { 1, 1, 1 };
732 737
@@ -768,51 +773,51 @@ postgres_iterate (struct Plugin *plugin,
768 nrc->iter_cls = iter_cls; 773 nrc->iter_cls = iter_cls;
769 if (is_asc) 774 if (is_asc)
770 { 775 {
771 nrc->last_prio = 0; 776 nrc->blast_prio = htonl (0);
772 nrc->last_rowid = 0; 777 nrc->blast_rowid = htonl (0);
773 nrc->last_expire = 0; 778 nrc->blast_expire = htonl (0);
774 } 779 }
775 else 780 else
776 { 781 {
777 nrc->last_prio = 0x7FFFFFFFL; 782 nrc->blast_prio = htonl (0x7FFFFFFFL);
778 nrc->last_rowid = 0xFFFFFFFF; 783 nrc->blast_rowid = htonl (0xFFFFFFFF);
779 nrc->last_expire = 0x7FFFFFFFFFFFFFFFLL; 784 nrc->blast_expire = GNUNET_htonll (0x7FFFFFFFFFFFFFFFLL);
780 } 785 }
781 switch (iter_select) 786 switch (iter_select)
782 { 787 {
783 case 0: 788 case 0:
784 nrc->pname = "select_low_priority"; 789 nrc->pname = "select_low_priority";
785 nrc->nparams = 2; 790 nrc->nparams = 2;
786 nrc->paramValues[0] = (const char *) &nrc->last_prio; 791 nrc->paramValues[0] = (const char *) &nrc->blast_prio;
787 nrc->paramValues[1] = (const char *) &nrc->last_rowid; 792 nrc->paramValues[1] = (const char *) &nrc->blast_rowid;
788 nrc->paramLengths[0] = sizeof (nrc->last_prio); 793 nrc->paramLengths[0] = sizeof (nrc->blast_prio);
789 nrc->paramLengths[1] = sizeof (nrc->last_rowid); 794 nrc->paramLengths[1] = sizeof (nrc->blast_rowid);
790 break; 795 break;
791 case 1: 796 case 1:
792 nrc->pname = "select_non_anonymous"; 797 nrc->pname = "select_non_anonymous";
793 nrc->nparams = 2; 798 nrc->nparams = 2;
794 nrc->paramValues[0] = (const char *) &nrc->last_prio; 799 nrc->paramValues[0] = (const char *) &nrc->blast_prio;
795 nrc->paramValues[1] = (const char *) &nrc->last_rowid; 800 nrc->paramValues[1] = (const char *) &nrc->blast_rowid;
796 nrc->paramLengths[0] = sizeof (nrc->last_prio); 801 nrc->paramLengths[0] = sizeof (nrc->blast_prio);
797 nrc->paramLengths[1] = sizeof (nrc->last_rowid); 802 nrc->paramLengths[1] = sizeof (nrc->blast_rowid);
798 break; 803 break;
799 case 2: 804 case 2:
800 nrc->pname = "select_expiration_time"; 805 nrc->pname = "select_expiration_time";
801 nrc->nparams = 2; 806 nrc->nparams = 2;
802 nrc->paramValues[0] = (const char *) &nrc->last_expire; 807 nrc->paramValues[0] = (const char *) &nrc->blast_expire;
803 nrc->paramValues[1] = (const char *) &nrc->last_rowid; 808 nrc->paramValues[1] = (const char *) &nrc->blast_rowid;
804 nrc->paramLengths[0] = sizeof (nrc->last_expire); 809 nrc->paramLengths[0] = sizeof (nrc->blast_expire);
805 nrc->paramLengths[1] = sizeof (nrc->last_rowid); 810 nrc->paramLengths[1] = sizeof (nrc->blast_rowid);
806 break; 811 break;
807 case 3: 812 case 3:
808 nrc->pname = "select_migration_order"; 813 nrc->pname = "select_migration_order";
809 nrc->nparams = 3; 814 nrc->nparams = 3;
810 nrc->paramValues[0] = (const char *) &nrc->last_expire; 815 nrc->paramValues[0] = (const char *) &nrc->blast_expire;
811 nrc->paramValues[1] = (const char *) &nrc->last_rowid; 816 nrc->paramValues[1] = (const char *) &nrc->blast_rowid;
812 nrc->paramValues[2] = (const char *) &nrc->now; 817 nrc->paramValues[2] = (const char *) &nrc->bnow;
813 nrc->paramLengths[0] = sizeof (nrc->last_expire); 818 nrc->paramLengths[0] = sizeof (nrc->blast_expire);
814 nrc->paramLengths[1] = sizeof (nrc->last_rowid); 819 nrc->paramLengths[1] = sizeof (nrc->blast_rowid);
815 nrc->paramLengths[2] = sizeof (nrc->now); 820 nrc->paramLengths[2] = sizeof (nrc->bnow);
816 break; 821 break;
817 default: 822 default:
818 GNUNET_break (0); 823 GNUNET_break (0);
@@ -821,7 +826,7 @@ postgres_iterate (struct Plugin *plugin,
821 GNUNET_TIME_UNIT_ZERO_ABS, 0); 826 GNUNET_TIME_UNIT_ZERO_ABS, 0);
822 return; 827 return;
823 } 828 }
824 nrc->now = GNUNET_TIME_absolute_get (); 829 nrc->bnow = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()).value__;
825 postgres_plugin_next_request (nrc, 830 postgres_plugin_next_request (nrc,
826 GNUNET_NO); 831 GNUNET_NO);
827} 832}
@@ -899,19 +904,19 @@ postgres_plugin_get (void *cls,
899 nrc->vhash = *vhash; 904 nrc->vhash = *vhash;
900 nrc->paramValues[0] = (const char*) &nrc->key; 905 nrc->paramValues[0] = (const char*) &nrc->key;
901 nrc->paramLengths[0] = sizeof (GNUNET_HashCode); 906 nrc->paramLengths[0] = sizeof (GNUNET_HashCode);
902 nrc->type = type; 907 nrc->btype = htonl (type);
903 if (type != 0) 908 if (type != 0)
904 { 909 {
905 if (vhash != NULL) 910 if (vhash != NULL)
906 { 911 {
907 nrc->paramValues[1] = (const char *) &nrc->vhash; 912 nrc->paramValues[1] = (const char *) &nrc->vhash;
908 nrc->paramLengths[1] = sizeof (nrc->vhash); 913 nrc->paramLengths[1] = sizeof (nrc->vhash);
909 nrc->paramValues[2] = (const char *) &nrc->type; 914 nrc->paramValues[2] = (const char *) &nrc->btype;
910 nrc->paramLengths[2] = sizeof (nrc->type); 915 nrc->paramLengths[2] = sizeof (nrc->btype);
911 nrc->paramValues[3] = (const char *) &nrc->last_rowid; 916 nrc->paramValues[3] = (const char *) &nrc->blast_rowid;
912 nrc->paramLengths[3] = sizeof (nrc->last_rowid); 917 nrc->paramLengths[3] = sizeof (nrc->blast_rowid);
913 nrc->paramValues[4] = (const char *) &nrc->limit_off; 918 nrc->paramValues[4] = (const char *) &nrc->blimit_off;
914 nrc->paramLengths[4] = sizeof (nrc->limit_off); 919 nrc->paramLengths[4] = sizeof (nrc->blimit_off);
915 nrc->nparams = 5; 920 nrc->nparams = 5;
916 nrc->pname = "getvt"; 921 nrc->pname = "getvt";
917 ret = PQexecParams (plugin->dbh, 922 ret = PQexecParams (plugin->dbh,
@@ -924,12 +929,12 @@ postgres_plugin_get (void *cls,
924 } 929 }
925 else 930 else
926 { 931 {
927 nrc->paramValues[1] = (const char *) &nrc->type; 932 nrc->paramValues[1] = (const char *) &nrc->btype;
928 nrc->paramLengths[1] = sizeof (nrc->type); 933 nrc->paramLengths[1] = sizeof (nrc->btype);
929 nrc->paramValues[2] = (const char *) &nrc->last_rowid; 934 nrc->paramValues[2] = (const char *) &nrc->blast_rowid;
930 nrc->paramLengths[2] = sizeof (nrc->last_rowid); 935 nrc->paramLengths[2] = sizeof (nrc->blast_rowid);
931 nrc->paramValues[3] = (const char *) &nrc->limit_off; 936 nrc->paramValues[3] = (const char *) &nrc->blimit_off;
932 nrc->paramLengths[3] = sizeof (nrc->limit_off); 937 nrc->paramLengths[3] = sizeof (nrc->blimit_off);
933 nrc->nparams = 4; 938 nrc->nparams = 4;
934 nrc->pname = "gett"; 939 nrc->pname = "gett";
935 ret = PQexecParams (plugin->dbh, 940 ret = PQexecParams (plugin->dbh,
@@ -947,10 +952,10 @@ postgres_plugin_get (void *cls,
947 { 952 {
948 nrc->paramValues[1] = (const char *) &nrc->vhash; 953 nrc->paramValues[1] = (const char *) &nrc->vhash;
949 nrc->paramLengths[1] = sizeof (nrc->vhash); 954 nrc->paramLengths[1] = sizeof (nrc->vhash);
950 nrc->paramValues[2] = (const char *) &nrc->last_rowid; 955 nrc->paramValues[2] = (const char *) &nrc->blast_rowid;
951 nrc->paramLengths[2] = sizeof (nrc->last_rowid); 956 nrc->paramLengths[2] = sizeof (nrc->blast_rowid);
952 nrc->paramValues[3] = (const char *) &nrc->limit_off; 957 nrc->paramValues[3] = (const char *) &nrc->blimit_off;
953 nrc->paramLengths[3] = sizeof (nrc->limit_off); 958 nrc->paramLengths[3] = sizeof (nrc->blimit_off);
954 nrc->nparams = 4; 959 nrc->nparams = 4;
955 nrc->pname = "getv"; 960 nrc->pname = "getv";
956 ret = PQexecParams (plugin->dbh, 961 ret = PQexecParams (plugin->dbh,
@@ -963,10 +968,10 @@ postgres_plugin_get (void *cls,
963 } 968 }
964 else 969 else
965 { 970 {
966 nrc->paramValues[1] = (const char *) &nrc->last_rowid; 971 nrc->paramValues[1] = (const char *) &nrc->blast_rowid;
967 nrc->paramLengths[1] = sizeof (nrc->last_rowid); 972 nrc->paramLengths[1] = sizeof (nrc->blast_rowid);
968 nrc->paramValues[2] = (const char *) &nrc->limit_off; 973 nrc->paramValues[2] = (const char *) &nrc->blimit_off;
969 nrc->paramLengths[2] = sizeof (nrc->limit_off); 974 nrc->paramLengths[2] = sizeof (nrc->blimit_off);
970 nrc->nparams = 3; 975 nrc->nparams = 3;
971 nrc->pname = "get"; 976 nrc->pname = "get";
972 ret = PQexecParams (plugin->dbh, 977 ret = PQexecParams (plugin->dbh,
diff --git a/src/datastore/test_datastore_api_data_postgres.conf b/src/datastore/test_datastore_api_data_postgres.conf
index 23eb02f97..0bc55852e 100644
--- a/src/datastore/test_datastore_api_data_postgres.conf
+++ b/src/datastore/test_datastore_api_data_postgres.conf
@@ -32,7 +32,7 @@ DISABLE_SOCKET_FORWARDING = YES
32# PREFIX = 32# PREFIX =
33# DEBUG = YES 33# DEBUG = YES
34# PREFIX = xterm -T datastore -e gdb --args 34# PREFIX = xterm -T datastore -e gdb --args
35PREFIX = valgrind --tool=memcheck --leak-check=yes 35# PREFIX = valgrind --tool=memcheck --leak-check=yes
36BINARY = gnunet-service-datastore 36BINARY = gnunet-service-datastore
37 37
38[datastore-postgres] 38[datastore-postgres]