diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-02-23 10:35:45 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-02-23 10:35:45 +0000 |
commit | 3d8f372adbd1f765b2c4e0fadb4d7152e9301588 (patch) | |
tree | 9a2776f70ec7a6cdd304cb6f754d32a488de048a /src/include/gnunet_namestore_service.h | |
parent | 6f82910681a10defdfd2c98fdb7b721cc7677109 (diff) | |
download | gnunet-3d8f372adbd1f765b2c4e0fadb4d7152e9301588.tar.gz gnunet-3d8f372adbd1f765b2c4e0fadb4d7152e9301588.zip |
-new api
Diffstat (limited to 'src/include/gnunet_namestore_service.h')
-rw-r--r-- | src/include/gnunet_namestore_service.h | 322 |
1 files changed, 84 insertions, 238 deletions
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index 9bda0f6f0..894397543 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h | |||
@@ -54,6 +54,11 @@ struct GNUNET_NAMESTORE_QueueEntry; | |||
54 | struct GNUNET_NAMESTORE_Handle; | 54 | struct GNUNET_NAMESTORE_Handle; |
55 | 55 | ||
56 | /** | 56 | /** |
57 | * Handle to the namestore zone iterator. | ||
58 | */ | ||
59 | struct GNUNET_NAMESTORE_ZoneIterator; | ||
60 | |||
61 | /** | ||
57 | * Maximum size of a value that can be stored in the namestore. | 62 | * Maximum size of a value that can be stored in the namestore. |
58 | */ | 63 | */ |
59 | #define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024) | 64 | #define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024) |
@@ -122,45 +127,7 @@ enum GNUNET_NAMESTORE_RecordFlags | |||
122 | 127 | ||
123 | 128 | ||
124 | /** | 129 | /** |
125 | * We formally store records in a B-tree for signing. This struct | 130 | * Get the hash of a record |
126 | * identifies the location of a record in the B-tree. | ||
127 | */ | ||
128 | struct GNUNET_NAMESTORE_SignatureLocation | ||
129 | { | ||
130 | /** | ||
131 | * Offset in the B-tree. | ||
132 | */ | ||
133 | uint64_t offset; | ||
134 | |||
135 | /** | ||
136 | * Depth in the B-tree. | ||
137 | */ | ||
138 | uint32_t depth; | ||
139 | |||
140 | /** | ||
141 | * Revision of the B-tree. | ||
142 | */ | ||
143 | uint32_t revision; | ||
144 | }; | ||
145 | |||
146 | |||
147 | /** | ||
148 | * Continuation called to notify client about result of the | ||
149 | * signing operation. | ||
150 | * | ||
151 | * @param cls closure | ||
152 | * @param sig where the signature is now located in the S-tree | ||
153 | */ | ||
154 | typedef void (*GNUNET_NAMESTORE_ContinuationWithSignature) (void *cls, | ||
155 | const struct GNUNET_NAMESTORE_SignatureLocation *sig); | ||
156 | |||
157 | |||
158 | |||
159 | |||
160 | |||
161 | /** | ||
162 | * Get the hash of a record (what will be signed in the Stree for | ||
163 | * the record). | ||
164 | * | 131 | * |
165 | * @param zone hash of the public key of the zone | 132 | * @param zone hash of the public key of the zone |
166 | * @param name name that is being mapped (at most 255 characters long) | 133 | * @param name name that is being mapped (at most 255 characters long) |
@@ -185,125 +152,9 @@ GNUNET_NAMESTORE_record_hash (struct GNUNET_NAMESTORE_Handle *h, | |||
185 | 152 | ||
186 | 153 | ||
187 | /** | 154 | /** |
188 | * Sign a record. This function is used by the authority of the zone | ||
189 | * to add a record. | ||
190 | * | ||
191 | * @param h handle to the namestore | ||
192 | * @param zone_privkey private key of the zone | ||
193 | * @param record_hash hash of the record to be signed | ||
194 | * @param cont continuation to call when done | ||
195 | * @param cont_cls closure for cont | ||
196 | * @return handle to abort the request | ||
197 | */ | ||
198 | struct GNUNET_NAMESTORE_QueueEntry * | ||
199 | GNUNET_NAMESTORE_stree_extend (struct GNUNET_NAMESTORE_Handle *h, | ||
200 | const struct GNUNET_CRYPTO_RsaPrivateKey *zone_privkey, | ||
201 | const GNUNET_HashCode *record_hash, | ||
202 | GNUNET_NAMESTORE_ContinuationWithSignature cont, | ||
203 | void *cont_cls); | ||
204 | |||
205 | |||
206 | /** | ||
207 | * Rebalance the signature tree of our zone. This function should | ||
208 | * be called "rarely" to rebalance the tree. | ||
209 | * | ||
210 | * @param h handle to the namestore | ||
211 | * @param zone_privkey private key for the zone to rebalance | ||
212 | * @param cont continuation to call when done | ||
213 | * @param cont_cls closure for cont | ||
214 | * @return handle to abort the request | ||
215 | */ | ||
216 | struct GNUNET_NAMESTORE_QueueEntry * | ||
217 | GNUNET_NAMESTORE_stree_rebalance (struct GNUNET_NAMESTORE_Handle *h, | ||
218 | const struct GNUNET_CRYPTO_RsaPrivateKey *zone_privkey, | ||
219 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | ||
220 | void *cont_cls); | ||
221 | |||
222 | |||
223 | /** | ||
224 | * Provide the root of a signature tree. This function is | ||
225 | * used by non-authorities as the first operation when | ||
226 | * adding a foreign zone. | ||
227 | * | ||
228 | * @param h handle to the namestore | ||
229 | * @param zone_key public key of the zone | ||
230 | * @param signature signature of the top-level entry of the zone | ||
231 | * @param revision revision number of the zone | ||
232 | * @param top_hash top-level hash of the zone | ||
233 | * @param cont continuation to call when done | ||
234 | * @param cont_cls closure for cont | ||
235 | * @return handle to abort the request | ||
236 | */ | ||
237 | struct GNUNET_NAMESTORE_QueueEntry * | ||
238 | GNUNET_NAMESTORE_stree_start (struct GNUNET_NAMESTORE_Handle *h, | ||
239 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | ||
240 | const struct GNUNET_CRYPTO_RsaSignature *signature, | ||
241 | uint32_t revision, | ||
242 | const GNUNET_HashCode *top_hash, | ||
243 | GNUNET_NAMESTORE_ContinuationWithSignature cont, | ||
244 | void *cont_cls); | ||
245 | |||
246 | |||
247 | /** | ||
248 | * Store part of a signature B-tree in the namestore. This function | ||
249 | * is used by non-authorities to cache parts of a zone's signature tree. | ||
250 | * Note that the tree must be build top-down. This function must check | ||
251 | * that the nodes being added are valid, and if not refuse the operation. | ||
252 | * | ||
253 | * @param h handle to the namestore | ||
254 | * @param zone_key public key of the zone | ||
255 | * @param loc location in the B-tree | ||
256 | * @param ploc parent's location in the B-tree (must have depth = loc.depth - 1) | ||
257 | * @param num_entries number of entries at this node in the B-tree | ||
258 | * @param entries the 'num_entries' entries to store (hashes over the | ||
259 | * records) | ||
260 | * @param cont continuation to call when done | ||
261 | * @param cont_cls closure for cont | ||
262 | * @return handle to abort the request | ||
263 | */ | ||
264 | struct GNUNET_NAMESTORE_QueueEntry * | ||
265 | GNUNET_NAMESTORE_stree_put (struct GNUNET_NAMESTORE_Handle *h, | ||
266 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | ||
267 | const struct GNUNET_NAMESTORE_SignatureLocation *loc, | ||
268 | const struct GNUNET_NAMESTORE_SignatureLocation *ploc, | ||
269 | unsigned int num_entries, | ||
270 | const GNUNET_HashCode *entries, | ||
271 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | ||
272 | void *cont_cls); | ||
273 | |||
274 | |||
275 | /** | ||
276 | * Store current zone signature in the namestore. This function | ||
277 | * is used by non-authorities to cache the top of a zone's signature tree. | ||
278 | * Note that the tree must be build top-down, so this function is called | ||
279 | * first for a given zone and revision. | ||
280 | * | ||
281 | * @param h handle to the namestore | ||
282 | * @param zone_key public key of the zone | ||
283 | * @param loc identifies the top of the B-tree (depth and revision) | ||
284 | * @param time time of the signature creation | ||
285 | * @param top_sig signature at the top | ||
286 | * @param root_hash top level hash code in the Merkle-tree / stree | ||
287 | * @param cont continuation to call when done | ||
288 | * @param cont_cls closure for cont | ||
289 | * @return handle to abort the request | ||
290 | */ | ||
291 | struct GNUNET_NAMESTORE_QueueEntry * | ||
292 | GNUNET_NAMESTORE_signature_put (struct GNUNET_NAMESTORE_Handle *h, | ||
293 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | ||
294 | const struct GNUNET_NAMESTORE_SignatureLocation *loc, | ||
295 | struct GNUNET_TIME_Absolute time, | ||
296 | const struct GNUNET_CRYPTO_RsaSignature *top_sig, | ||
297 | const GNUNET_HashCode *root_hash, | ||
298 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | ||
299 | void *cont_cls); | ||
300 | |||
301 | |||
302 | /** | ||
303 | * Store an item in the namestore. If the item is already present, | 155 | * Store an item in the namestore. If the item is already present, |
304 | * the expiration time is updated to the max of the existing time and | 156 | * the expiration time is updated to the max of the existing time and |
305 | * the new time. The operation must fail if there is no matching | 157 | * the new time. |
306 | * entry in the signature tree. | ||
307 | * | 158 | * |
308 | * @param h handle to the namestore | 159 | * @param h handle to the namestore |
309 | * @param zone hash of the public key of the zone | 160 | * @param zone hash of the public key of the zone |
@@ -311,7 +162,6 @@ GNUNET_NAMESTORE_signature_put (struct GNUNET_NAMESTORE_Handle *h, | |||
311 | * @param record_type type of the record (A, AAAA, PKEY, etc.) | 162 | * @param record_type type of the record (A, AAAA, PKEY, etc.) |
312 | * @param expiration expiration time for the content | 163 | * @param expiration expiration time for the content |
313 | * @param flags flags for the content | 164 | * @param flags flags for the content |
314 | * @param sig_loc where is the information about the signature for this record stored? | ||
315 | * @param data_size number of bytes in data | 165 | * @param data_size number of bytes in data |
316 | * @param data value, semantics depend on 'record_type' (see RFCs for DNS and | 166 | * @param data value, semantics depend on 'record_type' (see RFCs for DNS and |
317 | * GNS specification for GNS extensions) | 167 | * GNS specification for GNS extensions) |
@@ -326,12 +176,31 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, | |||
326 | uint32_t record_type, | 176 | uint32_t record_type, |
327 | struct GNUNET_TIME_Absolute expiration, | 177 | struct GNUNET_TIME_Absolute expiration, |
328 | enum GNUNET_NAMESTORE_RecordFlags flags, | 178 | enum GNUNET_NAMESTORE_RecordFlags flags, |
329 | const struct GNUNET_NAMESTORE_SignatureLocation *sig_loc, | ||
330 | size_t data_size, | 179 | size_t data_size, |
331 | const void *data, | 180 | const void *data, |
332 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | 181 | GNUNET_NAMESTORE_ContinuationWithStatus cont, |
333 | void *cont_cls); | 182 | void *cont_cls); |
334 | 183 | ||
184 | /** | ||
185 | * Store a signature for 'name' in the namestore. | ||
186 | * Used by non-authorities to store signatures for cached name records. | ||
187 | * | ||
188 | * @param h handle to the namestore | ||
189 | * @param zone hash of the public key of the zone | ||
190 | * @param name name that is being mapped (at most 255 characters long) | ||
191 | * @param sig the signature | ||
192 | * @param cont continuation to call when done | ||
193 | * @param cont_cls closure for cont | ||
194 | * @return handle to abort the request | ||
195 | */ | ||
196 | struct GNUNET_NAMESTORE_QueueEntry * | ||
197 | GNUNET_NAMESTORE_signature_put (struct GNUNET_NAMESTORE_Handle *h, | ||
198 | const GNUNET_HashCode *zone, | ||
199 | const char *name, | ||
200 | struct GNUNET_CRYPTO_RsaSignature sig, | ||
201 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | ||
202 | void *cont_cls); | ||
203 | |||
335 | 204 | ||
336 | /** | 205 | /** |
337 | * Explicitly remove some content from the database. The | 206 | * Explicitly remove some content from the database. The |
@@ -369,7 +238,6 @@ GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h, | |||
369 | * @param record_type type of the record (A, AAAA, PKEY, etc.) | 238 | * @param record_type type of the record (A, AAAA, PKEY, etc.) |
370 | * @param expiration expiration time for the content | 239 | * @param expiration expiration time for the content |
371 | * @param flags flags for the content | 240 | * @param flags flags for the content |
372 | * @param sig_loc where is the information about the signature for this record stored? | ||
373 | * @param size number of bytes in data | 241 | * @param size number of bytes in data |
374 | * @param data content stored | 242 | * @param data content stored |
375 | */ | 243 | */ |
@@ -379,9 +247,22 @@ typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls, | |||
379 | uint32_t record_type, | 247 | uint32_t record_type, |
380 | struct GNUNET_TIME_Absolute expiration, | 248 | struct GNUNET_TIME_Absolute expiration, |
381 | enum GNUNET_NAMESTORE_RecordFlags flags, | 249 | enum GNUNET_NAMESTORE_RecordFlags flags, |
382 | const struct GNUNET_NAMESTORE_SignatureLocation *sig_loc, | ||
383 | size_t size, const void *data); | 250 | size_t size, const void *data); |
384 | 251 | ||
252 | /** | ||
253 | * Process a signature for a given name | ||
254 | * | ||
255 | * @param cls closure | ||
256 | * @param zone hash of the public key of the zone | ||
257 | * @param name name of the records that were signed | ||
258 | * @param sig the signature | ||
259 | */ | ||
260 | typedef void (*GNUNET_NAMESTORE_SignatureProcessor) (void *cls, | ||
261 | const GNUNET_HashCode *zone, | ||
262 | const char *name, | ||
263 | struct GNUNET_CRYPTO_RsaSignature sig); | ||
264 | |||
265 | |||
385 | 266 | ||
386 | /** | 267 | /** |
387 | * Get a result for a particular key from the namestore. The processor | 268 | * Get a result for a particular key from the namestore. The processor |
@@ -398,94 +279,20 @@ typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls, | |||
398 | * cancel | 279 | * cancel |
399 | */ | 280 | */ |
400 | struct GNUNET_NAMESTORE_QueueEntry * | 281 | struct GNUNET_NAMESTORE_QueueEntry * |
401 | GNUNET_NAMESTORE_lookup_name (struct GNUNET_NAMESTORE_Handle *h, | 282 | GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, |
402 | const GNUNET_HashCode *zone, | 283 | const GNUNET_HashCode *zone, |
403 | const char *name, | 284 | const char *name, |
404 | uint32_t record_type, | 285 | uint32_t record_type, |
405 | GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls); | 286 | GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls); |
406 | 287 | ||
407 | 288 | ||
408 | |||
409 | /** | ||
410 | * Get the hash of a subtree in the STree (what will be signed in the parent | ||
411 | * location). FIXME naming conflict! | ||
412 | * | ||
413 | * @param zone hash of the public key of the zone | ||
414 | * @param loc where we are in the signature tree | ||
415 | * @param num_entries number of entries being stored here | ||
416 | * @param entries the entries themselves | ||
417 | * @param st_hash hash of the stree node (set) | ||
418 | */ | ||
419 | void | ||
420 | GNUNET_NAMESTORE_record_hash_dup (struct GNUNET_NAMESTORE_Handle *h, | ||
421 | const GNUNET_HashCode *zone, | ||
422 | const struct GNUNET_NAMESTORE_SignatureLocation *loc, | ||
423 | unsigned int num_entries, | ||
424 | const GNUNET_HashCode *entries, | ||
425 | GNUNET_HashCode *st_hash); | ||
426 | |||
427 | |||
428 | /** | ||
429 | * Process a Stree node that was stored in the namestore. | ||
430 | * | ||
431 | * @param cls closure | ||
432 | * @param zone hash of the public key of the zone | ||
433 | * @param loc where we are in the signature tree | ||
434 | * @param ploc location of our parent in the signature tree | ||
435 | * @param num_entries number of entries being stored here | ||
436 | * @param entries the entries themselves | ||
437 | */ | ||
438 | typedef void (*GNUNET_NAMESTORE_StreeProcessor) (void *cls, | ||
439 | const GNUNET_HashCode *zone, | ||
440 | const struct GNUNET_NAMESTORE_SignatureLocation *loc, | ||
441 | const struct GNUNET_NAMESTORE_SignatureLocation *ploc, | ||
442 | unsigned int num_entries, | ||
443 | const GNUNET_HashCode *entries); | ||
444 | |||
445 | |||
446 | /** | ||
447 | * Obtain part of a signature B-tree. The processor | ||
448 | * will only be called once. | ||
449 | * | ||
450 | * @param h handle to the namestore | ||
451 | * @param zone zone to look up a record from | ||
452 | * @param sig_loc location to look up | ||
453 | * @param proc function to call on each matching value; | ||
454 | * will be called once with a NULL value at the end | ||
455 | * @param proc_cls closure for proc | ||
456 | * @return a handle that can be used to | ||
457 | * cancel | ||
458 | */ | ||
459 | struct GNUNET_NAMESTORE_QueueEntry * | ||
460 | GNUNET_NAMESTORE_lookup_stree (struct GNUNET_NAMESTORE_Handle *h, | ||
461 | const GNUNET_HashCode *zone, | ||
462 | const struct GNUNET_NAMESTORE_SignatureLocation *sig_loc, | ||
463 | GNUNET_NAMESTORE_StreeProcessor proc, void *proc_cls); | ||
464 | |||
465 | /** | ||
466 | * Process zone signature information that was stored in the namestore. | ||
467 | * | ||
468 | * @param cls closure | ||
469 | * @param zone hash of the public key of the zone | ||
470 | * @param loc where we are in the signature tree (identifies top) | ||
471 | * @param top_sig signature at the root | ||
472 | * @param time timestamp of the signature | ||
473 | * @param top_hash hash at the top of the tree | ||
474 | */ | ||
475 | typedef void (*GNUNET_NAMESTORE_SignatureProcessor) (void *cls, | ||
476 | const GNUNET_HashCode *zone, | ||
477 | const struct GNUNET_NAMESTORE_SignatureLocation *loc, | ||
478 | const struct GNUNET_CRYPTO_RsaSignature *top_sig, | ||
479 | struct GNUNET_TIME_Absolute time, | ||
480 | const GNUNET_HashCode *top_hash); | ||
481 | |||
482 | |||
483 | /** | 289 | /** |
484 | * Obtain latest/current signature of a zone. The processor | 290 | * Obtain latest/current signature of a zone's name. The processor |
485 | * will only be called once. | 291 | * will only be called once. |
486 | * | 292 | * |
487 | * @param h handle to the namestore | 293 | * @param h handle to the namestore |
488 | * @param zone zone to look up a record from | 294 | * @param zone zone to look up a signature from |
295 | * @param the common name of the records the signature is for | ||
489 | * @param proc function to call on each matching value; | 296 | * @param proc function to call on each matching value; |
490 | * will be called once with a NULL value at the end | 297 | * will be called once with a NULL value at the end |
491 | * @param proc_cls closure for proc | 298 | * @param proc_cls closure for proc |
@@ -495,6 +302,7 @@ typedef void (*GNUNET_NAMESTORE_SignatureProcessor) (void *cls, | |||
495 | struct GNUNET_NAMESTORE_QueueEntry * | 302 | struct GNUNET_NAMESTORE_QueueEntry * |
496 | GNUNET_NAMESTORE_lookup_signature (struct GNUNET_NAMESTORE_Handle *h, | 303 | GNUNET_NAMESTORE_lookup_signature (struct GNUNET_NAMESTORE_Handle *h, |
497 | const GNUNET_HashCode *zone, | 304 | const GNUNET_HashCode *zone, |
305 | const char* name, | ||
498 | GNUNET_NAMESTORE_SignatureProcessor proc, void *proc_cls); | 306 | GNUNET_NAMESTORE_SignatureProcessor proc, void *proc_cls); |
499 | 307 | ||
500 | 308 | ||
@@ -517,6 +325,44 @@ GNUNET_NAMESTORE_zone_transfer (struct GNUNET_NAMESTORE_Handle *h, | |||
517 | void *proc_cls); | 325 | void *proc_cls); |
518 | 326 | ||
519 | 327 | ||
328 | /** | ||
329 | * Starts a new zone iteration. This MUST lock the GNUNET_NAMESTORE_Handle | ||
330 | * for any other calls than | ||
331 | * GNUNET_NAMESTORE_zone_iterator_next | ||
332 | * and | ||
333 | * GNUNET_NAMESTORE_zone_iteration_stop | ||
334 | * | ||
335 | * @param h handle to the namestore | ||
336 | * @param zone zone to access | ||
337 | * @param proc function to call on a random value; it | ||
338 | * will be called repeatedly with a value (if available) | ||
339 | * and always once at the end with a zone and name of NULL. | ||
340 | * @param proc_cls closure for proc | ||
341 | * @return an iterator handle to use for iteration | ||
342 | */ | ||
343 | struct GNUNET_NAMESTORE_ZoneIterator * | ||
344 | GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, | ||
345 | const GNUNET_HashCode *zone, | ||
346 | GNUNET_NAMESTORE_RecordProcessor proc, | ||
347 | void *proc_cls); | ||
348 | |||
349 | /** | ||
350 | * Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start | ||
351 | * for the next record. | ||
352 | * | ||
353 | * @param it the iterator | ||
354 | * @return 0 if no more records are available to iterate | ||
355 | */ | ||
356 | int | ||
357 | GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it); | ||
358 | |||
359 | /** | ||
360 | * Stops iteration and releases the namestore handle for further calls. | ||
361 | * | ||
362 | * @param it the iterator | ||
363 | */ | ||
364 | void | ||
365 | GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it); | ||
520 | 366 | ||
521 | 367 | ||
522 | /** | 368 | /** |