aboutsummaryrefslogtreecommitdiff
path: root/src/consensus/gnunet-consensus-ibf.c
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2013-02-07 10:51:17 +0000
committerFlorian Dold <florian.dold@gmail.com>2013-02-07 10:51:17 +0000
commit4dc3faf5e88b8ca602602aa28a6ff76c02d34848 (patch)
treed50989d9fe71816bba1fdcef690684daa4f7873b /src/consensus/gnunet-consensus-ibf.c
parent5ceb669384bd36b3213f7f1e7dbaf31b913e06a0 (diff)
downloadgnunet-4dc3faf5e88b8ca602602aa28a6ff76c02d34848.tar.gz
gnunet-4dc3faf5e88b8ca602602aa28a6ff76c02d34848.zip
- improved ibf decoding algorithm
- strata estimator now fits in one message - work on consensus, not quite working yet
Diffstat (limited to 'src/consensus/gnunet-consensus-ibf.c')
-rw-r--r--src/consensus/gnunet-consensus-ibf.c65
1 files changed, 53 insertions, 12 deletions
diff --git a/src/consensus/gnunet-consensus-ibf.c b/src/consensus/gnunet-consensus-ibf.c
index c9bcc1ab0..a16ca3247 100644
--- a/src/consensus/gnunet-consensus-ibf.c
+++ b/src/consensus/gnunet-consensus-ibf.c
@@ -38,16 +38,39 @@ static unsigned int csize = 10;
38static unsigned int hash_num = 3; 38static unsigned int hash_num = 3;
39static unsigned int ibf_size = 80; 39static unsigned int ibf_size = 80;
40 40
41/* FIXME: add parameter for this */
42static enum GNUNET_CRYPTO_Quality random_quality = GNUNET_CRYPTO_QUALITY_WEAK;
41 43
42static struct GNUNET_CONTAINER_MultiHashMap *set_a; 44static struct GNUNET_CONTAINER_MultiHashMap *set_a;
43static struct GNUNET_CONTAINER_MultiHashMap *set_b; 45static struct GNUNET_CONTAINER_MultiHashMap *set_b;
44/* common elements in a and b */ 46/* common elements in a and b */
45static struct GNUNET_CONTAINER_MultiHashMap *set_c; 47static struct GNUNET_CONTAINER_MultiHashMap *set_c;
46 48
49static struct GNUNET_CONTAINER_MultiHashMap *key_to_hashcode;
50
47static struct InvertibleBloomFilter *ibf_a; 51static struct InvertibleBloomFilter *ibf_a;
48static struct InvertibleBloomFilter *ibf_b; 52static struct InvertibleBloomFilter *ibf_b;
49 53
50 54
55static void
56register_hashcode (struct GNUNET_HashCode *hash)
57{
58 struct GNUNET_HashCode replicated;
59 uint64_t key;
60 key = ibf_key_from_hashcode (hash);
61 ibf_hashcode_from_key (key, &replicated);
62 GNUNET_CONTAINER_multihashmap_put (key_to_hashcode, &replicated, GNUNET_memdup (hash, sizeof *hash),
63 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
64}
65
66static void
67iter_hashcodes (uint64_t key, GNUNET_CONTAINER_HashMapIterator iter, void *cls)
68{
69 struct GNUNET_HashCode replicated;
70 ibf_hashcode_from_key (key, &replicated);
71 GNUNET_CONTAINER_multihashmap_get_multiple (key_to_hashcode, &replicated, iter, cls);
72}
73
51 74
52static int 75static int
53insert_iterator (void *cls, 76insert_iterator (void *cls,
@@ -55,7 +78,19 @@ insert_iterator (void *cls,
55 void *value) 78 void *value)
56{ 79{
57 struct InvertibleBloomFilter *ibf = (struct InvertibleBloomFilter *) cls; 80 struct InvertibleBloomFilter *ibf = (struct InvertibleBloomFilter *) cls;
58 ibf_insert (ibf, key); 81 ibf_insert (ibf, ibf_key_from_hashcode (key));
82 return GNUNET_YES;
83}
84
85
86static int
87remove_iterator (void *cls,
88 const struct GNUNET_HashCode *key,
89 void *value)
90{
91 struct GNUNET_CONTAINER_MultiHashMap *hashmap = cls;
92 /* if remove fails, there just was a collision with another key */
93 (void) GNUNET_CONTAINER_multihashmap_remove (hashmap, value, NULL);
59 return GNUNET_YES; 94 return GNUNET_YES;
60} 95}
61 96
@@ -65,6 +100,7 @@ run (void *cls, char *const *args, const char *cfgfile,
65 const struct GNUNET_CONFIGURATION_Handle *cfg) 100 const struct GNUNET_CONFIGURATION_Handle *cfg)
66{ 101{
67 struct GNUNET_HashCode id; 102 struct GNUNET_HashCode id;
103 uint64_t ibf_key;
68 int i; 104 int i;
69 int side; 105 int side;
70 int res; 106 int res;
@@ -78,47 +114,57 @@ run (void *cls, char *const *args, const char *cfgfile,
78 set_c = GNUNET_CONTAINER_multihashmap_create (((csize == 0) ? 1 : csize), 114 set_c = GNUNET_CONTAINER_multihashmap_create (((csize == 0) ? 1 : csize),
79 GNUNET_NO); 115 GNUNET_NO);
80 116
117 key_to_hashcode = GNUNET_CONTAINER_multihashmap_create (((asize+bsize+csize == 0) ? 1 : (asize+bsize+csize)),
118 GNUNET_NO);
119
81 printf ("hash-num=%u, size=%u, #(A-B)=%u, #(B-A)=%u, #(A&B)=%u\n", 120 printf ("hash-num=%u, size=%u, #(A-B)=%u, #(B-A)=%u, #(A&B)=%u\n",
82 hash_num, ibf_size, asize, bsize, csize); 121 hash_num, ibf_size, asize, bsize, csize);
83 122
84 i = 0; 123 i = 0;
85 while (i < asize) 124 while (i < asize)
86 { 125 {
87 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id); 126 GNUNET_CRYPTO_hash_create_random (random_quality, &id);
88 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id)) 127 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id))
89 continue; 128 continue;
90 GNUNET_CONTAINER_multihashmap_put ( 129 GNUNET_CONTAINER_multihashmap_put (
91 set_a, &id, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 130 set_a, &id, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
131 register_hashcode (&id);
92 i++; 132 i++;
93 } 133 }
94 i = 0; 134 i = 0;
95 while (i < bsize) 135 while (i < bsize)
96 { 136 {
97 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id); 137 GNUNET_CRYPTO_hash_create_random (random_quality, &id);
98 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id)) 138 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id))
99 continue; 139 continue;
100 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_b, &id)) 140 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_b, &id))
101 continue; 141 continue;
102 GNUNET_CONTAINER_multihashmap_put ( 142 GNUNET_CONTAINER_multihashmap_put (
103 set_b, &id, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 143 set_b, &id, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
144 register_hashcode (&id);
104 i++; 145 i++;
105 } 146 }
106 i = 0; 147 i = 0;
107 while (i < csize) 148 while (i < csize)
108 { 149 {
109 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id); 150 GNUNET_CRYPTO_hash_create_random (random_quality, &id);
110 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id)) 151 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_a, &id))
111 continue; 152 continue;
112 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_b, &id)) 153 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_b, &id))
113 continue; 154 continue;
155 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (set_c, &id))
156 continue;
114 GNUNET_CONTAINER_multihashmap_put ( 157 GNUNET_CONTAINER_multihashmap_put (
115 set_c, &id, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 158 set_c, &id, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
159 register_hashcode (&id);
116 i++; 160 i++;
117 } 161 }
118 162
119 ibf_a = ibf_create (ibf_size, hash_num, 0); 163 ibf_a = ibf_create (ibf_size, hash_num, 0);
120 ibf_b = ibf_create (ibf_size, hash_num, 0); 164 ibf_b = ibf_create (ibf_size, hash_num, 0);
121 165
166 printf ("generated sets\n");
167
122 start_time = GNUNET_TIME_absolute_get (); 168 start_time = GNUNET_TIME_absolute_get ();
123 169
124 GNUNET_CONTAINER_multihashmap_iterate (set_a, &insert_iterator, ibf_a); 170 GNUNET_CONTAINER_multihashmap_iterate (set_a, &insert_iterator, ibf_a);
@@ -137,7 +183,7 @@ run (void *cls, char *const *args, const char *cfgfile,
137 183
138 for (;;) 184 for (;;)
139 { 185 {
140 res = ibf_decode (ibf_a, &side, &id); 186 res = ibf_decode (ibf_a, &side, &ibf_key);
141 if (GNUNET_SYSERR == res) 187 if (GNUNET_SYSERR == res)
142 { 188 {
143 printf ("decode failed\n"); 189 printf ("decode failed\n");
@@ -157,14 +203,9 @@ run (void *cls, char *const *args, const char *cfgfile,
157 } 203 }
158 204
159 if (side == 1) 205 if (side == 1)
160 res = GNUNET_CONTAINER_multihashmap_remove (set_a, &id, NULL); 206 iter_hashcodes (ibf_key, remove_iterator, set_a);
161 if (side == -1) 207 if (side == -1)
162 res = GNUNET_CONTAINER_multihashmap_remove (set_b, &id, NULL); 208 iter_hashcodes (ibf_key, remove_iterator, set_b);
163 if (GNUNET_YES != res)
164 {
165 printf ("decoded wrong element\n");
166 return;
167 }
168 } 209 }
169} 210}
170 211