aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/namestore_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-23 17:36:21 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-23 17:36:21 +0000
commit375925bc545e8d99cf9290a37e411bfd7eda8c95 (patch)
tree585ac43fdafcd4882fc44ef12ed91a17fb456b79 /src/namestore/namestore_api.c
parenta881ec667a8e9b40398dcc62cdfb97183e5c77ee (diff)
downloadgnunet-375925bc545e8d99cf9290a37e411bfd7eda8c95.tar.gz
gnunet-375925bc545e8d99cf9290a37e411bfd7eda8c95.zip
-fixing compile errors due to ns api change
Diffstat (limited to 'src/namestore/namestore_api.c')
-rw-r--r--src/namestore/namestore_api.c314
1 files changed, 113 insertions, 201 deletions
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index ba0344958..e8547574a 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -172,7 +172,7 @@ process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg)
172 default: 172 default:
173 break; 173 break;
174 } 174 }
175 175 size++; // FIXME: just working around compiler warning here...
176 GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh, 176 GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh,
177 GNUNET_TIME_UNIT_FOREVER_REL); 177 GNUNET_TIME_UNIT_FOREVER_REL);
178 178
@@ -367,184 +367,121 @@ GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *nsh, int drop)
367 nsh = NULL; 367 nsh = NULL;
368} 368}
369 369
370/**
371 * Sign a record. This function is used by the authority of the zone
372 * to add a record.
373 *
374 * @param h handle to the namestore
375 * @param zone_privkey private key of the zone
376 * @param record_hash hash of the record to be signed
377 * @param cont continuation to call when done
378 * @param cont_cls closure for cont
379 * @return handle to abort the request
380 */
381struct GNUNET_NAMESTORE_QueueEntry *
382GNUNET_NAMESTORE_stree_extend (struct GNUNET_NAMESTORE_Handle *h,
383 const struct GNUNET_CRYPTO_RsaPrivateKey *zone_privkey,
384 const GNUNET_HashCode *record_hash,
385 GNUNET_NAMESTORE_ContinuationWithSignature cont,
386 void *cont_cls)
387{
388 struct GNUNET_NAMESTORE_QueueEntry *qe;
389 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
390 return qe;
391}
392 370
393/** 371/**
394 * Rebalance the signature tree of our zone. This function should 372 * Store an item in the namestore. If the item is already present,
395 * be called "rarely" to rebalance the tree. 373 * the expiration time is updated to the max of the existing time and
374 * the new time. This API is used when we cache signatures from other
375 * authorities.
396 * 376 *
397 * @param h handle to the namestore 377 * @param h handle to the namestore
398 * @param zone_privkey private key for the zone to rebalance 378 * @param zone hash of the public key of the zone
379 * @param name name that is being mapped (at most 255 characters long)
380 * @param expire when does the corresponding block in the DHT expire (until
381 * when should we never do a DHT lookup for the same name again)?
382 * @param rd_count number of entries in 'rd' array
383 * @param rd array of records with data to store
384 * @param signature signature for all the records in the zone under the given name
399 * @param cont continuation to call when done 385 * @param cont continuation to call when done
400 * @param cont_cls closure for cont 386 * @param cont_cls closure for cont
401 * @return handle to abort the request 387 * @return handle to abort the request
402 */ 388 */
403struct GNUNET_NAMESTORE_QueueEntry * 389struct GNUNET_NAMESTORE_QueueEntry *
404GNUNET_NAMESTORE_stree_rebalance (struct GNUNET_NAMESTORE_Handle *h, 390GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
405 const struct GNUNET_CRYPTO_RsaPrivateKey *zone_privkey, 391 const GNUNET_HashCode *zone,
406 GNUNET_NAMESTORE_ContinuationWithStatus cont, 392 const char *name,
407 void *cont_cls) 393 struct GNUNET_TIME_Absolute expire,
394 unsigned int rd_count,
395 const struct GNUNET_NAMESTORE_RecordData *rd,
396 const struct GNUNET_CRYPTO_RsaSignature *signature,
397 GNUNET_NAMESTORE_ContinuationWithStatus cont,
398 void *cont_cls)
408{ 399{
409 struct GNUNET_NAMESTORE_QueueEntry *qe; 400 struct GNUNET_NAMESTORE_QueueEntry *qe;
410 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); 401 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
402#if 0
403 struct GNUNET_NAMESTORE_SimpleRecord *sr;
404 sr = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_SimpleRecord));
405 sr->name = name;
406 sr->record_type = record_type;
407 sr->expiration = expiration;
408 sr->flags = flags;
409 sr->data_size = data_size;
410 sr->data = data;
411 GNUNET_CONTAINER_DLL_insert(h->records_head, h->records_tail, sr);
412#endif
411 return qe; 413 return qe;
412} 414}
413 415
414/**
415 * Provide the root of a signature tree. This function is
416 * used by non-authorities as the first operation when
417 * adding a foreign zone.
418 *
419 * @param h handle to the namestore
420 * @param zone_key public key of the zone
421 * @param signature signature of the top-level entry of the zone
422 * @param revision revision number of the zone
423 * @param top_hash top-level hash of the zone
424 * @param cont continuation to call when done
425 * @param cont_cls closure for cont
426 * @return handle to abort the request
427 */
428struct GNUNET_NAMESTORE_QueueEntry *
429GNUNET_NAMESTORE_stree_start (struct GNUNET_NAMESTORE_Handle *h,
430 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
431 const struct GNUNET_CRYPTO_RsaSignature *signature,
432 uint32_t revision,
433 const GNUNET_HashCode *top_hash,
434 GNUNET_NAMESTORE_ContinuationWithSignature cont,
435 void *cont_cls)
436{
437 struct GNUNET_NAMESTORE_QueueEntry *qe;
438 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
439 return qe;
440}
441 416
442/** 417/**
443 * Store part of a signature B-tree in the namestore. This function 418 * Check if a signature is valid. This API is used by the GNS Block
444 * is used by non-authorities to cache parts of a zone's signature tree. 419 * to validate signatures received from the network.
445 * Note that the tree must be build top-down. This function must check
446 * that the nodes being added are valid, and if not refuse the operation.
447 * 420 *
448 * @param h handle to the namestore 421 * @param public_key public key of the zone
449 * @param zone_key public key of the zone 422 * @param name name that is being mapped (at most 255 characters long)
450 * @param loc location in the B-tree 423 * @param rd_count number of entries in 'rd' array
451 * @param ploc parent's location in the B-tree (must have depth = loc.depth - 1) 424 * @param rd array of records with data to store
452 * @param num_entries number of entries at this node in the B-tree 425 * @param signature signature for all the records in the zone under the given name
453 * @param entries the 'num_entries' entries to store (hashes over the 426 * @return GNUNET_OK if the signature is valid
454 * records)
455 * @param cont continuation to call when done
456 * @param cont_cls closure for cont
457 * @return handle to abort the request
458 */ 427 */
459struct GNUNET_NAMESTORE_QueueEntry * 428int
460GNUNET_NAMESTORE_stree_put (struct GNUNET_NAMESTORE_Handle *h, 429GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
461 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, 430 const char *name,
462 const struct GNUNET_NAMESTORE_SignatureLocation *loc, 431 unsigned int rd_count,
463 const struct GNUNET_NAMESTORE_SignatureLocation *ploc, 432 const struct GNUNET_NAMESTORE_RecordData *rd,
464 unsigned int num_entries, 433 const struct GNUNET_CRYPTO_RsaSignature *signature)
465 const GNUNET_HashCode *entries,
466 GNUNET_NAMESTORE_ContinuationWithStatus cont,
467 void *cont_cls)
468{ 434{
469 struct GNUNET_NAMESTORE_QueueEntry *qe; 435 return GNUNET_SYSERR;
470 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
471 return qe;
472} 436}
473 437
474/** 438/**
475 * Store an item in the namestore. If the item is already present, 439 * Store an item in the namestore. If the item is already present,
476 * the expiration time is updated to the max of the existing time and 440 * the expiration time is updated to the max of the existing time and
477 * the new time. The operation must fail if there is no matching 441 * the new time. This API is used by the authority of a zone.
478 * entry in the signature tree.
479 * 442 *
480 * @param h handle to the namestore 443 * @param h handle to the namestore
481 * @param zone hash of the public key of the zone 444 * @param pkey private key of the zone
482 * @param name name that is being mapped (at most 255 characters long) 445 * @param name name that is being mapped (at most 255 characters long)
483 * @param record_type type of the record (A, AAAA, PKEY, etc.) 446 * @param rd record data to store
484 * @param expiration expiration time for the content
485 * @param flags flags for the content
486 * @param sig_loc where is the information about the signature for this record stored?
487 * @param data_size number of bytes in data
488 * @param data value, semantics depend on 'record_type' (see RFCs for DNS and
489 * GNS specification for GNS extensions)
490 * @param cont continuation to call when done 447 * @param cont continuation to call when done
491 * @param cont_cls closure for cont 448 * @param cont_cls closure for cont
492 * @return handle to abort the request 449 * @return handle to abort the request
493 */ 450 */
494struct GNUNET_NAMESTORE_QueueEntry * 451struct GNUNET_NAMESTORE_QueueEntry *
495GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, 452GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
496 const GNUNET_HashCode *zone, 453 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
497 const char *name, 454 const char *name,
498 uint32_t record_type, 455 const struct GNUNET_NAMESTORE_RecordData *rd,
499 struct GNUNET_TIME_Absolute expiration, 456 GNUNET_NAMESTORE_ContinuationWithStatus cont,
500 enum GNUNET_NAMESTORE_RecordFlags flags, 457 void *cont_cls)
501 const struct GNUNET_NAMESTORE_SignatureLocation *sig_loc,
502 size_t data_size,
503 const void *data,
504 GNUNET_NAMESTORE_ContinuationWithStatus cont,
505 void *cont_cls)
506{ 458{
507 struct GNUNET_NAMESTORE_QueueEntry *qe; 459 return NULL;
508 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
509#if 0
510 struct GNUNET_NAMESTORE_SimpleRecord *sr;
511 sr = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_SimpleRecord));
512 sr->name = name;
513 sr->record_type = record_type;
514 sr->expiration = expiration;
515 sr->flags = flags;
516 sr->data_size = data_size;
517 sr->data = data;
518 GNUNET_CONTAINER_DLL_insert(h->records_head, h->records_tail, sr);
519#endif
520 return qe;
521} 460}
522 461
462
523/** 463/**
524 * Explicitly remove some content from the database. The 464 * Explicitly remove some content from the database. The
525 * "cont"inuation will be called with status "GNUNET_OK" if content 465 * "cont"inuation will be called with status "GNUNET_OK" if content
526 * was removed, "GNUNET_NO" if no matching entry was found and 466 * was removed, "GNUNET_NO" if no matching entry was found and
527 * "GNUNET_SYSERR" on all other types of errors. 467 * "GNUNET_SYSERR" on all other types of errors.
468 * This API is used by the authority of a zone.
528 * 469 *
529 * @param h handle to the namestore 470 * @param h handle to the namestore
530 * @param zone hash of the public key of the zone 471 * @param pkey private key of the zone
531 * @param name name that is being mapped (at most 255 characters long) 472 * @param name name that is being mapped (at most 255 characters long)
532 * @param record_type type of the record (A, AAAA, PKEY, etc.) 473 * @param rd record data
533 * @param size number of bytes in data
534 * @param data content stored
535 * @param cont continuation to call when done 474 * @param cont continuation to call when done
536 * @param cont_cls closure for cont 475 * @param cont_cls closure for cont
537 * @return handle to abort the request 476 * @return handle to abort the request
538 */ 477 */
539struct GNUNET_NAMESTORE_QueueEntry * 478struct GNUNET_NAMESTORE_QueueEntry *
540GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h, 479GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
541 const GNUNET_HashCode *zone, 480 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
542 const char *name, 481 const char *name,
543 uint32_t record_type, 482 const struct GNUNET_NAMESTORE_RecordData *rd,
544 size_t size, 483 GNUNET_NAMESTORE_ContinuationWithStatus cont,
545 const void *data, 484 void *cont_cls)
546 GNUNET_NAMESTORE_ContinuationWithStatus cont,
547 void *cont_cls)
548{ 485{
549 struct GNUNET_NAMESTORE_QueueEntry *qe; 486 struct GNUNET_NAMESTORE_QueueEntry *qe;
550 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); 487 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
@@ -565,26 +502,27 @@ GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
565 return qe; 502 return qe;
566} 503}
567 504
505
568/** 506/**
569 * Get a result for a particular key from the namestore. The processor 507 * Get a result for a particular key from the namestore. The processor
570 * will only be called once. 508 * will only be called once.
571 * 509 *
572 * @param h handle to the namestore 510 * @param h handle to the namestore
573 * @param zone zone to look up a record from 511 * @param zone zone to look up a record from
574 * @param name name to look up 512 * @param name name to look up
575 * @param record_type desired record type 513 * @param record_type desired record type, 0 for all
576 * @param proc function to call on each matching value; 514 * @param proc function to call on the matching records, or with
577 * will be called once with a NULL value at the end 515 * NULL (rd_count == 0) if there are no matching records
578 * @param proc_cls closure for proc 516 * @param proc_cls closure for proc
579 * @return a handle that can be used to 517 * @return a handle that can be used to
580 * cancel 518 * cancel
581 */ 519 */
582struct GNUNET_NAMESTORE_QueueEntry * 520struct GNUNET_NAMESTORE_QueueEntry *
583GNUNET_NAMESTORE_lookup_name (struct GNUNET_NAMESTORE_Handle *nsh, 521GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
584 const GNUNET_HashCode *zone, 522 const GNUNET_HashCode *zone,
585 const char *name, 523 const char *name,
586 uint32_t record_type, 524 uint32_t record_type,
587 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls) 525 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls)
588{ 526{
589 struct GNUNET_NAMESTORE_QueueEntry *qe; 527 struct GNUNET_NAMESTORE_QueueEntry *qe;
590 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); 528 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
@@ -603,7 +541,7 @@ GNUNET_NAMESTORE_lookup_name (struct GNUNET_NAMESTORE_Handle *nsh,
603 GNUNET_TIME_absolute_get_forever(), 0, NULL, 0, NULL); /*TERMINATE*/ 541 GNUNET_TIME_absolute_get_forever(), 0, NULL, 0, NULL); /*TERMINATE*/
604#endif 542#endif
605 543
606 GNUNET_assert (NULL != nsh); 544 GNUNET_assert (NULL != h);
607 545
608 struct PendingMessage * p; 546 struct PendingMessage * p;
609 struct LookupNameMessage * msg; 547 struct LookupNameMessage * msg;
@@ -615,93 +553,67 @@ GNUNET_NAMESTORE_lookup_name (struct GNUNET_NAMESTORE_Handle *nsh,
615 msg = (struct LookupNameMessage *) &p[1]; 553 msg = (struct LookupNameMessage *) &p[1];
616 msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME); 554 msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME);
617 msg->header.size = htons (msg_len); 555 msg->header.size = htons (msg_len);
618 GNUNET_CONTAINER_DLL_insert (nsh->pending_head, nsh->pending_tail, p); 556 GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, p);
619 do_transmit (nsh); 557 do_transmit (h);
620 558
621 return qe; 559 return qe;
622} 560}
623 561
624 562
563
625/** 564/**
626 * Get the hash of a record (what will be signed in the Stree for 565 * Starts a new zone iteration (used to periodically PUT all of our
627 * the record). 566 * records into our DHT). This MUST lock the GNUNET_NAMESTORE_Handle
567 * for any other calls than GNUNET_NAMESTORE_zone_iterator_next and
568 * GNUNET_NAMESTORE_zone_iteration_stop. "proc" will be called once
569 * immediately, and then again after
570 * "GNUNET_NAMESTORE_zone_iterator_next" is invoked.
628 * 571 *
629 * @param zone hash of the public key of the zone 572 * @param h handle to the namestore
630 * @param name name that is being mapped (at most 255 characters long) 573 * @param zone zone to access, NULL for all zones
631 * @param record_type type of the record (A, AAAA, PKEY, etc.) 574 * @param must_have_flags flags that must be set for the record to be returned
632 * @param expiration expiration time for the content 575 * @param must_not_have_flags flags that must NOT be set for the record to be returned
633 * @param flags flags for the content 576 * @param proc function to call on each name from the zone; it
634 * @param data_size number of bytes in data 577 * will be called repeatedly with a value (if available)
635 * @param data value, semantics depend on 'record_type' (see RFCs for DNS and. 578 * and always once at the end with a name of NULL.
636 * GNS specification for GNS extensions) 579 * @param proc_cls closure for proc
637 * @param record_hash hash of the record (set) 580 * @return an iterator handle to use for iteration
638 */ 581 */
639void 582struct GNUNET_NAMESTORE_ZoneIterator *
640GNUNET_NAMESTORE_record_hash (struct GNUNET_NAMESTORE_Handle *h, 583GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
641 const GNUNET_HashCode *zone, 584 const GNUNET_HashCode *zone,
642 const char *name, 585 enum GNUNET_NAMESTORE_RecordFlags must_have_flags,
643 uint32_t record_type, 586 enum GNUNET_NAMESTORE_RecordFlags must_not_have_flags,
644 struct GNUNET_TIME_Absolute expiration, 587 GNUNET_NAMESTORE_RecordProcessor proc,
645 enum GNUNET_NAMESTORE_RecordFlags flags, 588 void *proc_cls)
646 size_t data_size,
647 const void *data,
648 GNUNET_HashCode *record_hash)
649{ 589{
650 char* teststring = "namestore-stub"; 590 return NULL;
651 GNUNET_CRYPTO_hash(teststring, strlen(teststring), record_hash);
652} 591}
653 592
593
654/** 594/**
655 * Obtain part of a signature B-tree. The processor 595 * Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start
656 * will only be called once. 596 * for the next record.
657 * 597 *
658 * @param h handle to the namestore 598 * @param it the iterator
659 * @param zone zone to look up a record from
660 * @param sig_loc location to look up
661 * @param proc function to call on each matching value;
662 * will be called once with a NULL value at the end
663 * @param proc_cls closure for proc
664 * @return a handle that can be used to
665 * cancel
666 */ 599 */
667struct GNUNET_NAMESTORE_QueueEntry * 600void
668GNUNET_NAMESTORE_lookup_stree (struct GNUNET_NAMESTORE_Handle *h, 601GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it)
669 const GNUNET_HashCode *zone,
670 const struct GNUNET_NAMESTORE_SignatureLocation *sig_loc,
671 GNUNET_NAMESTORE_StreeProcessor proc, void *proc_cls)
672{ 602{
673 struct GNUNET_NAMESTORE_QueueEntry *qe;
674 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
675 return qe;
676} 603}
677 604
678 605
679/** 606/**
680 * Get all records of a zone. 607 * Stops iteration and releases the namestore handle for further calls.
681 * 608 *
682 * @param h handle to the namestore 609 * @param it the iterator
683 * @param zone zone to access
684 * @param proc function to call on a random value; it
685 * will be called repeatedly with a value (if available)
686 * and always once at the end with a zone and name of NULL.
687 * @param proc_cls closure for proc
688 * @return a handle that can be used to
689 * cancel
690 */ 610 */
691struct GNUNET_NAMESTORE_QueueEntry * 611void
692GNUNET_NAMESTORE_zone_transfer (struct GNUNET_NAMESTORE_Handle *h, 612GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it)
693 const GNUNET_HashCode *zone,
694 GNUNET_NAMESTORE_RecordProcessor proc,
695 void *proc_cls)
696{ 613{
697 struct GNUNET_NAMESTORE_QueueEntry *qe;
698 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
699 return qe;
700} 614}
701 615
702 616
703
704
705/** 617/**
706 * Cancel a namestore operation. The final callback from the 618 * Cancel a namestore operation. The final callback from the
707 * operation must not have been done yet. 619 * operation must not have been done yet.