aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_plugin_namestore.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-23 14:03:07 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-23 14:03:07 +0000
commit297b8ea479db3fd5513e16093d517dee30a51c24 (patch)
tree607ba8267bf2363e3f190c24f90432f94df9efbc /src/namestore/test_plugin_namestore.c
parentb8ca2af15579933b2acca79908a19e08535abe26 (diff)
downloadgnunet-297b8ea479db3fd5513e16093d517dee30a51c24.tar.gz
gnunet-297b8ea479db3fd5513e16093d517dee30a51c24.zip
-moving towards new plugin API
Diffstat (limited to 'src/namestore/test_plugin_namestore.c')
-rw-r--r--src/namestore/test_plugin_namestore.c275
1 files changed, 13 insertions, 262 deletions
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c
index d3d94684d..b95e9f0c9 100644
--- a/src/namestore/test_plugin_namestore.c
+++ b/src/namestore/test_plugin_namestore.c
@@ -84,284 +84,39 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
84 * Function called by for each matching record. 84 * Function called by for each matching record.
85 * 85 *
86 * @param cls closure 86 * @param cls closure
87 * @param zone hash of the public key of the zone 87 * @param zone_key public key of the zone
88 * @param loc location of the signature for this record 88 * @param expire when does the corresponding block in the DHT expire (until
89 * when should we never do a DHT lookup for the same name again)?
89 * @param name name that is being mapped (at most 255 characters long) 90 * @param name name that is being mapped (at most 255 characters long)
90 * @param record_type type of the record (A, AAAA, PKEY, etc.) 91 * @param rd_count number of entries in 'rd' array
91 * @param expiration expiration time for the content 92 * @param rd array of records with data to store
92 * @param flags flags for the content 93 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
93 * @param data_size number of bytes in data 94 * because the user queried for a particular record type only)
94 * @param data value, semantics depend on 'record_type' (see RFCs for DNS and
95 * GNS specification for GNS extensions)
96 */ 95 */
97static void 96static void
98test_record (void *cls, 97test_record (void *cls,
99 const GNUNET_HashCode *zone, 98 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
100 const struct GNUNET_NAMESTORE_SignatureLocation *loc, 99 struct GNUNET_TIME_Absolute expire,
101 const char *name, 100 const char *name,
102 uint32_t record_type, 101 unsigned int rd_count,
103 struct GNUNET_TIME_Absolute expiration, 102 const struct GNUNET_NAMESTORE_RecordData *rd,
104 enum GNUNET_NAMESTORE_RecordFlags flags, 103 const struct GNUNET_CRYPTO_RsaSignature *signature)
105 size_t data_size,
106 const void *data)
107{ 104{
108 int *idp = cls;
109 int id = *idp;
110 size_t tdata_size = id * 17;
111 char tdata[tdata_size];
112 GNUNET_HashCode tzone;
113 char tname[32];
114 uint32_t trecord_type;
115 struct GNUNET_NAMESTORE_SignatureLocation tloc;
116 enum GNUNET_NAMESTORE_RecordFlags tflags;
117
118 memset (&tzone, 42, sizeof (tzone));
119 memset (tdata, id % 255, sizeof (tdata));
120 GNUNET_snprintf (tname, sizeof (tname),
121 "aa%u", (unsigned int) id);
122 trecord_type = id % 4;
123 tloc.depth = (id % 10);
124 tloc.offset = (id % 3);
125 tloc.revision = id % 1024;
126 tflags = GNUNET_NAMESTORE_RF_AUTHORITY;
127
128 GNUNET_assert (0 == memcmp (&tzone, zone, sizeof (GNUNET_HashCode)));
129 GNUNET_assert (trecord_type == record_type);
130 GNUNET_assert (0 == strcmp (tname, name));
131 GNUNET_assert (tdata_size == data_size);
132 GNUNET_assert (0 == memcmp (data, tdata, data_size));
133 GNUNET_assert (flags == tflags);
134 GNUNET_assert (0 == memcmp (loc, &tloc, sizeof (struct GNUNET_NAMESTORE_SignatureLocation)));
135} 105}
136 106
137 107
138static void 108static void
139get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) 109get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
140{ 110{
141 GNUNET_HashCode zone;
142 GNUNET_HashCode nh;
143 char name[32];
144
145 memset (&zone, 42, sizeof (zone));
146 GNUNET_snprintf (name, sizeof (name),
147 "aa%u", (unsigned int) id);
148 GNUNET_CRYPTO_hash (name, strlen (name), &nh);
149 GNUNET_assert (1 == nsp->iterate_records (nsp->cls, 111 GNUNET_assert (1 == nsp->iterate_records (nsp->cls,
150 &zone, 112 NULL, NULL, 0,
151 &nh,
152 &test_record, &id)); 113 &test_record, &id));
153} 114}
154 115
155 116
156/**
157 * Function called with the matching node.
158 *
159 * @param cls closure
160 * @param zone hash of public key of the zone
161 * @param loc location in the B-tree
162 * @param ploc parent's location in the B-tree (must have depth = loc.depth - 1), NULL for root
163 * @param num_entries number of entries at this node in the B-tree
164 * @param entries the 'num_entries' entries to store (hashes over the
165 * records)
166 */
167static void
168test_node (void *cls,
169 const GNUNET_HashCode *zone,
170 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
171 const struct GNUNET_NAMESTORE_SignatureLocation *ploc,
172 unsigned int num_entries,
173 const GNUNET_HashCode *entries)
174{
175 int *idp = cls;
176 int id = *idp;
177 struct GNUNET_NAMESTORE_SignatureLocation tloc;
178 struct GNUNET_NAMESTORE_SignatureLocation tploc;
179 unsigned int tnum_entries = 1 + (id % 15);
180 GNUNET_HashCode tentries[num_entries];
181 unsigned int i;
182
183 tloc.depth = (id % 10);
184 tloc.offset = (id % 3);
185 tloc.revision = id % 1024;
186 tploc.depth = tloc.depth + 1;
187 tploc.offset = (id % 5);
188 tploc.revision = tloc.revision;
189 for (i=0;i<tnum_entries;i++)
190 memset (&tentries[i], (id+i) % 255, sizeof (GNUNET_HashCode));
191 GNUNET_assert (0 == memcmp (&tloc, loc,
192 sizeof (const struct GNUNET_NAMESTORE_SignatureLocation)));
193 GNUNET_assert (0 == memcmp (&tploc, ploc,
194 sizeof (const struct GNUNET_NAMESTORE_SignatureLocation)));
195 GNUNET_assert (num_entries == tnum_entries);
196 GNUNET_assert (0 == memcmp (entries, tentries, sizeof (tentries)));
197}
198
199
200static void
201get_node (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
202{
203 GNUNET_HashCode zone;
204 struct GNUNET_NAMESTORE_SignatureLocation loc;
205
206 memset (&zone, 42, sizeof (zone));
207 loc.depth = (id % 10);
208 loc.offset = (id % 3);
209 loc.revision = id % 1024;
210 GNUNET_assert (GNUNET_OK ==
211 nsp->get_node (nsp->cls,
212 &zone,
213 &loc,
214 &test_node,
215 &id));
216}
217
218
219/**
220 * Function called with the matching signature.
221 *
222 * @param cls closure
223 * @param zone public key of the zone
224 * @param loc location of the root in the B-tree (depth, revision)
225 * @param top_sig signature signing the zone
226 * @param zone_time time the signature was created
227 * @param root_hash top level hash that is being signed
228 */
229static void
230test_signature (void *cls,
231 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
232 const struct GNUNET_NAMESTORE_SignatureLocation *loc,
233 const struct GNUNET_CRYPTO_RsaSignature *top_sig,
234 struct GNUNET_TIME_Absolute zone_time,
235 const GNUNET_HashCode *root_hash)
236{
237 int *idp = cls;
238 int id = *idp;
239 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded tzone_key;
240 struct GNUNET_NAMESTORE_SignatureLocation tloc;
241 struct GNUNET_CRYPTO_RsaSignature ttop_sig;
242 GNUNET_HashCode troot_hash;
243
244 memset (&tzone_key, 13, sizeof (tzone_key));
245 tloc.depth = (id % 10);
246 tloc.offset = 0;
247 tloc.revision = id % 1024;
248 memset (&ttop_sig, 24, sizeof (ttop_sig));
249 memset (&troot_hash, 42, sizeof (troot_hash));
250
251 GNUNET_assert (0 == memcmp (&tzone_key, zone_key, sizeof (GNUNET_HashCode)));
252 GNUNET_assert (0 == memcmp (&tloc, loc, sizeof (struct GNUNET_NAMESTORE_SignatureLocation)));
253 GNUNET_assert (0 == memcmp (&ttop_sig, top_sig, sizeof (struct GNUNET_CRYPTO_RsaSignature)));
254 GNUNET_assert (0 == memcmp (&troot_hash, root_hash, sizeof (GNUNET_HashCode)));
255}
256
257
258static void
259get_signature (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
260{
261 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
262 GNUNET_HashCode zone;
263
264 memset (&zone_key, 13, sizeof (zone_key));
265 GNUNET_CRYPTO_hash (&zone_key, sizeof (zone_key), &zone);
266 GNUNET_assert (GNUNET_OK ==
267 nsp->get_signature (nsp->cls,
268 &zone,
269 test_signature,
270 &id));
271}
272
273
274static void 117static void
275put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) 118put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
276{ 119{
277 size_t data_size = id * 17;
278 char data[data_size];
279 GNUNET_HashCode zone;
280 char name[32];
281 uint32_t record_type;
282 struct GNUNET_NAMESTORE_SignatureLocation loc;
283 struct GNUNET_TIME_Absolute expiration;
284 enum GNUNET_NAMESTORE_RecordFlags flags;
285
286 memset (&zone, 42, sizeof (zone));
287 memset (data, id % 255, sizeof (data));
288 GNUNET_snprintf (name, sizeof (name),
289 "aa%u", (unsigned int) id);
290 record_type = id % 4;
291 loc.depth = (id % 10);
292 loc.offset = (id % 3);
293 loc.revision = id % 1024;
294 expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
295 flags = GNUNET_NAMESTORE_RF_AUTHORITY;
296
297 GNUNET_assert (GNUNET_OK ==
298 nsp->put_record (nsp->cls,
299 &zone,
300 name,
301 record_type,
302 &loc,
303 expiration,
304 flags,
305 data_size,
306 data));
307}
308
309
310static void
311put_node (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
312 int id)
313{
314 GNUNET_HashCode zone;
315 struct GNUNET_NAMESTORE_SignatureLocation loc;
316 struct GNUNET_NAMESTORE_SignatureLocation ploc;
317 unsigned int num_entries = 1 + (id % 15);
318 GNUNET_HashCode entries[num_entries];
319 unsigned int i;
320
321 memset (&zone, 42, sizeof (zone));
322 loc.depth = (id % 10);
323 loc.offset = (id % 3);
324 loc.revision = id % 1024;
325 ploc.depth = loc.depth + 1;
326 ploc.offset = (id % 5);
327 ploc.revision = loc.revision;
328 for (i=0;i<num_entries;i++)
329 memset (&entries[i], (id+i) % 255, sizeof (GNUNET_HashCode));
330 GNUNET_assert (GNUNET_OK ==
331 nsp->put_node (nsp->cls,
332 &zone,
333 &loc,
334 &ploc,
335 num_entries,
336 entries));
337}
338
339
340static void
341put_signature (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
342 int id)
343{
344 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
345 struct GNUNET_NAMESTORE_SignatureLocation loc;
346 struct GNUNET_CRYPTO_RsaSignature top_sig;
347 GNUNET_HashCode root_hash;
348 struct GNUNET_TIME_Absolute zone_time;
349
350 memset (&zone_key, 13, sizeof (zone_key));
351 loc.depth = (id % 10);
352 loc.offset = 0;
353 loc.revision = id % 1024;
354 memset (&top_sig, 24, sizeof (top_sig));
355 memset (&root_hash, 42, sizeof (root_hash));
356 zone_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
357
358 GNUNET_assert (GNUNET_OK ==
359 nsp->put_signature (nsp->cls,
360 &zone_key,
361 &loc,
362 &top_sig,
363 &root_hash,
364 zone_time));
365} 120}
366 121
367 122
@@ -383,10 +138,6 @@ run (void *cls, char *const *args, const char *cfgfile,
383 } 138 }
384 put_record (nsp, 1); 139 put_record (nsp, 1);
385 get_record (nsp, 1); 140 get_record (nsp, 1);
386 put_node (nsp, 1);
387 get_node (nsp, 1);
388 put_signature (nsp, 1);
389 get_signature (nsp, 1);
390 141
391 memset (&zone, 42, sizeof (zone)); 142 memset (&zone, 42, sizeof (zone));
392 nsp->delete_zone (nsp->cls, &zone); 143 nsp->delete_zone (nsp->cls, &zone);