aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-13 13:25:05 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-13 13:25:05 +0000
commit35927ed463d637b46ec7f819578dbdf46b44d1f4 (patch)
tree39d22465902f9653c0c1bb348c9d17ee0019d67c
parent700adc7f3dd9aa84f52517e091d27a271f3f7e07 (diff)
downloadgnunet-35927ed463d637b46ec7f819578dbdf46b44d1f4.tar.gz
gnunet-35927ed463d637b46ec7f819578dbdf46b44d1f4.zip
-namestore service builds again
-rw-r--r--src/namestore/gnunet-service-namestore.c1097
-rw-r--r--src/namestore/namestore.h34
-rw-r--r--src/namestore/namestore_api.c4
-rw-r--r--src/namestore/plugin_namestore_sqlite.c31
4 files changed, 253 insertions, 913 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 4b1345be7..f6caf6ba7 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -69,7 +69,7 @@ struct ZoneIteration
69 /** 69 /**
70 * The operation id fot the zone iteration in the response for the client 70 * The operation id fot the zone iteration in the response for the client
71 */ 71 */
72 uint64_t request_id; 72 uint32_t request_id;
73 73
74 /** 74 /**
75 * Offset of the zone iteration used to address next result of the zone 75 * Offset of the zone iteration used to address next result of the zone
@@ -135,7 +135,7 @@ struct ZoneMonitor
135 /** 135 /**
136 * Namestore client which intiated this zone monitor 136 * Namestore client which intiated this zone monitor
137 */ 137 */
138 struct GNUNET_SERVER_Client *client; 138 struct NamestoreClient *nc;
139 139
140 /** 140 /**
141 * Private key of the zone. 141 * Private key of the zone.
@@ -145,7 +145,7 @@ struct ZoneMonitor
145 /** 145 /**
146 * The operation id fot the zone iteration in the response for the client 146 * The operation id fot the zone iteration in the response for the client
147 */ 147 */
148 uint64_t request_id; 148 uint32_t request_id;
149 149
150 /** 150 /**
151 * Task active during initial iteration. 151 * Task active during initial iteration.
@@ -223,7 +223,8 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
223 struct ZoneIteration *no; 223 struct ZoneIteration *no;
224 struct NamestoreClient *nc; 224 struct NamestoreClient *nc;
225 225
226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n"); 226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
227 "Stopping namestore service\n");
227 if (NULL != snc) 228 if (NULL != snc)
228 { 229 {
229 GNUNET_SERVER_notification_context_destroy (snc); 230 GNUNET_SERVER_notification_context_destroy (snc);
@@ -251,26 +252,6 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
251 252
252 253
253/** 254/**
254 * Lookup our internal data structure for a given client.
255 *
256 * @param client server client handle to use for the lookup
257 * @return our internal structure for the client, NULL if
258 * we do not have any yet
259 */
260static struct NamestoreClient *
261client_lookup (struct GNUNET_SERVER_Client *client)
262{
263 struct NamestoreClient *nc;
264
265 GNUNET_assert (NULL != client);
266 for (nc = client_head; NULL != nc; nc = nc->next)
267 if (client == nc->client)
268 return nc;
269 return NULL;
270}
271
272
273/**
274 * Called whenever a client is disconnected. 255 * Called whenever a client is disconnected.
275 * Frees our resources associated with that client. 256 * Frees our resources associated with that client.
276 * 257 *
@@ -290,7 +271,7 @@ client_disconnect_notification (void *cls,
290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
291 "Client %p disconnected\n", 272 "Client %p disconnected\n",
292 client); 273 client);
293 if (NULL == (nc = client_lookup (client))) 274 if (NULL == (nc = GNUNET_SERVER_client_get_user_context (client, struct NamestoreClient)))
294 return; 275 return;
295 while (NULL != (no = nc->op_head)) 276 while (NULL != (no = nc->op_head))
296 { 277 {
@@ -301,7 +282,7 @@ client_disconnect_notification (void *cls,
301 GNUNET_free (nc); 282 GNUNET_free (nc);
302 for (zm = monitor_head; NULL != zm; zm = zm->next) 283 for (zm = monitor_head; NULL != zm; zm = zm->next)
303 { 284 {
304 if (client == zm->client) 285 if (client == zm->nc->client)
305 { 286 {
306 GNUNET_CONTAINER_DLL_remove (monitor_head, 287 GNUNET_CONTAINER_DLL_remove (monitor_head,
307 monitor_tail, 288 monitor_tail,
@@ -319,32 +300,29 @@ client_disconnect_notification (void *cls,
319 300
320 301
321/** 302/**
322 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_START' message 303 * Add a client to our list of active clients, if it is not yet
304 * in there.
323 * 305 *
324 * @param cls unused 306 * @param client client to add
325 * @param client GNUNET_SERVER_Client sending the message 307 * @return internal namestore client structure for this client
326 * @param message unused
327 */ 308 */
328static void 309static struct NamestoreClient *
329handle_start (void *cls, 310client_lookup (struct GNUNET_SERVER_Client *client)
330 struct GNUNET_SERVER_Client *client,
331 const struct GNUNET_MessageHeader *message)
332{ 311{
333 struct NamestoreClient *nc; 312 struct NamestoreClient *nc;
334 313
314 nc = GNUNET_SERVER_client_get_user_context (client, struct NamestoreClient);
315 if (NULL != nc)
316 return nc;
335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
336 "Client %p connected\n", client); 318 "Client %p connected\n",
337 if (NULL != client_lookup (client)) 319 client);
338 { 320 nc = GNUNET_new (struct NamestoreClient);
339 GNUNET_break (0);
340 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
341 return;
342 }
343 nc = GNUNET_malloc (sizeof (struct NamestoreClient));
344 nc->client = client; 321 nc->client = client;
345 GNUNET_SERVER_notification_context_add (snc, client); 322 GNUNET_SERVER_notification_context_add (snc, client);
346 GNUNET_CONTAINER_DLL_insert (client_head, client_tail, nc); 323 GNUNET_CONTAINER_DLL_insert (client_head, client_tail, nc);
347 GNUNET_SERVER_receive_done (client, GNUNET_OK); 324 GNUNET_SERVER_client_set_user_context (client, nc);
325 return nc;
348} 326}
349 327
350 328
@@ -360,366 +338,155 @@ struct LookupNameContext
360 struct NamestoreClient *nc; 338 struct NamestoreClient *nc;
361 339
362 /** 340 /**
363 * Requested zone
364 */
365 const struct GNUNET_CRYPTO_ShortHashCode *zone;
366
367 /**
368 * Requested name
369 */
370 const char *name;
371
372 /**
373 * Operation id for the name lookup 341 * Operation id for the name lookup
374 */ 342 */
375 uint32_t request_id; 343 uint32_t request_id;
376 344
377 /**
378 * Requested specific record type
379 */
380 uint32_t record_type;
381}; 345};
382 346
383 347
384/** 348/**
385 * A 'GNUNET_NAMESTORE_RecordIterator' for name lookups in handle_lookup_name 349 * A #GNUNET_NAMESTORE_BlockCallback for name lookups in #handle_lookup_name
386 * 350 *
387 * @param cls a 'struct LookupNameContext *' with information about the request 351 * @param cls a 'struct LookupNameContext *' with information about the request
388 * @param zone_key zone key of the zone 352 * @param block the block
389 * @param expire expiration time
390 * @param name name
391 * @param rd_count number of records
392 * @param rd array of records
393 * @param signature signature
394 */ 353 */
395static void 354static void
396handle_lookup_name_it (void *cls, 355handle_lookup_block_it (void *cls,
397 const struct GNUNET_CRYPTO_EccPublicKey *zone_key, 356 const struct GNUNET_NAMESTORE_Block *block)
398 struct GNUNET_TIME_Absolute expire,
399 const char *name,
400 unsigned int rd_count,
401 const struct GNUNET_NAMESTORE_RecordData *rd,
402 const struct GNUNET_CRYPTO_EccSignature *signature)
403{ 357{
404 struct LookupNameContext *lnc = cls; 358 struct LookupNameContext *lnc = cls;
405 struct LookupNameResponseMessage *lnr_msg; 359 struct LookupBlockResponseMessage *r;
406 struct GNUNET_NAMESTORE_RecordData *rd_selected; 360 size_t esize;
407 struct GNUNET_NAMESTORE_CryptoContainer *cc; 361
408 struct GNUNET_CRYPTO_EccSignature *signature_new; 362 esize = ntohl (block->purpose.size)
409 struct GNUNET_TIME_Absolute e; 363 - sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)
410 struct GNUNET_TIME_Relative re; 364 - sizeof (struct GNUNET_TIME_AbsoluteNBO);
411 struct GNUNET_CRYPTO_ShortHashCode zone_key_hash; 365 r = GNUNET_malloc (sizeof (struct LookupBlockResponseMessage) + esize);
412 struct GNUNET_HashCode long_hash; 366 r->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK_RESPONSE);
413 char *rd_tmp; 367 r->gns_header.header.size = htons (sizeof (struct LookupBlockResponseMessage) + esize);
414 char *name_tmp; 368 r->gns_header.r_id = htonl (lnc->request_id);
415 size_t rd_ser_len; 369 r->expire = block->expiration_time;
416 size_t r_size; 370 r->signature = block->signature;
417 size_t name_len; 371 r->derived_key = block->derived_key;
418 int copied_elements; 372 memcpy (&r[1], &block[1], esize);
419 int contains_signature;
420 int authoritative;
421 int rd_modified;
422 unsigned int c;
423
424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
425 "Found %u records under name `%s'\n",
426 rd_count,
427 name);
428 authoritative = GNUNET_NO;
429 signature_new = NULL;
430 cc = NULL;
431 if (NULL != zone_key)
432 {
433 GNUNET_CRYPTO_short_hash (zone_key,
434 sizeof (struct GNUNET_CRYPTO_EccPublicKey),
435 &zone_key_hash);
436 GNUNET_CRYPTO_short_hash_double (&zone_key_hash, &long_hash);
437 if (NULL != (cc = GNUNET_CONTAINER_multihashmap_get (zonekeys, &long_hash)))
438 {
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "Am authoritative for zone `%s'\n",
441 GNUNET_NAMESTORE_short_h2s (&zone_key_hash));
442 authoritative = GNUNET_YES;
443 }
444 }
445
446 copied_elements = 0;
447 rd_modified = GNUNET_NO;
448 rd_selected = NULL;
449 /* count records to copy */
450 for (c = 0; c < rd_count; c++)
451 {
452 if ( (GNUNET_YES == authoritative) &&
453 (GNUNET_YES ==
454 GNUNET_NAMESTORE_is_expired (&rd[c]) ) )
455 {
456 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
457 "Skipping expired record\n");
458 continue;
459 }
460 if ( (GNUNET_NAMESTORE_TYPE_ANY == lnc->record_type) ||
461 (rd[c].record_type == lnc->record_type) )
462 copied_elements++; /* found matching record */
463 else
464 {
465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
466 "Skipping non-mtaching record\n");
467 rd_modified = GNUNET_YES;
468 }
469 }
470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
471 "Found %u records with type %u for name `%s' in zone `%s'\n",
472 copied_elements,
473 lnc->record_type,
474 lnc->name,
475 GNUNET_NAMESTORE_short_h2s(lnc->zone));
476 if (copied_elements > 0)
477 {
478 rd_selected = GNUNET_malloc (copied_elements * sizeof (struct GNUNET_NAMESTORE_RecordData));
479 copied_elements = 0;
480 for (c = 0; c < rd_count; c++)
481 {
482 if ( (GNUNET_YES == authoritative) &&
483 (GNUNET_YES ==
484 GNUNET_NAMESTORE_is_expired (&rd[c])) )
485 continue;
486 if ( (GNUNET_NAMESTORE_TYPE_ANY == lnc->record_type) ||
487 (rd[c].record_type == lnc->record_type) )
488 {
489 if (0 != (rd[c].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION))
490 {
491 GNUNET_break (GNUNET_YES == authoritative);
492 rd_modified = GNUNET_YES;
493 re.rel_value_us = rd[c].expiration_time;
494 e = GNUNET_TIME_relative_to_absolute (re);
495 }
496 else
497 {
498 e.abs_value_us = rd[c].expiration_time;
499 }
500 /* found matching record, copy and convert flags to public format */
501 rd_selected[copied_elements] = rd[c]; /* shallow copy! */
502 rd_selected[copied_elements].expiration_time = e.abs_value_us;
503 if (0 != (rd_selected[copied_elements].flags &
504 (GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION | GNUNET_NAMESTORE_RF_AUTHORITY)))
505 {
506 rd_selected[copied_elements].flags &= ~ (GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION |
507 GNUNET_NAMESTORE_RF_AUTHORITY);
508 rd_modified = GNUNET_YES;
509 }
510 copied_elements++;
511 }
512 else
513 {
514 rd_modified = GNUNET_YES;
515 }
516 }
517 }
518 else
519 rd_selected = NULL;
520
521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
522 "Found %u matching records for name `%s' in zone `%s'\n",
523 copied_elements,
524 lnc->name,
525 GNUNET_NAMESTORE_short_h2s (lnc->zone));
526 contains_signature = GNUNET_NO;
527 if (copied_elements > 0)
528 {
529 if (GNUNET_YES == authoritative)
530 {
531 GNUNET_assert (NULL != cc);
532 e = get_block_expiration_time (rd_count, rd);
533 signature_new = GNUNET_NAMESTORE_create_signature (cc->privkey, e, name, rd_selected, copied_elements);
534 GNUNET_assert (NULL != signature_new);
535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
536 "Creating signature for name `%s' with %u records in zone `%s'\n",
537 name,
538 copied_elements,
539 GNUNET_NAMESTORE_short_h2s(&zone_key_hash));
540 }
541 else
542 {
543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
544 "Not authoritative, records modified is %d, have sig is %d\n",
545 rd_modified,
546 NULL != signature);
547 if ((GNUNET_NO == rd_modified) && (NULL != signature))
548 contains_signature = GNUNET_YES; /* returning all records, so include signature */
549 }
550 }
551
552 rd_ser_len = GNUNET_NAMESTORE_records_get_size (copied_elements, rd_selected);
553 name_len = (NULL == name) ? 0 : strlen(name) + 1;
554 r_size = sizeof (struct LookupNameResponseMessage) +
555 name_len +
556 rd_ser_len;
557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
558 "Sending `%s' message\n", 374 "Sending `%s' message\n",
559 "NAMESTORE_LOOKUP_NAME_RESPONSE"); 375 "NAMESTORE_LOOKUP_NAME_RESPONSE");
560 lnr_msg = GNUNET_malloc (r_size); 376 GNUNET_SERVER_notification_context_unicast (snc,
561 lnr_msg->gns_header.header.type = ntohs (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE); 377 lnc->nc->client,
562 lnr_msg->gns_header.header.size = ntohs (r_size); 378 &r->gns_header.header,
563 lnr_msg->gns_header.r_id = htonl (lnc->request_id);
564 lnr_msg->rd_count = htons (copied_elements);
565 lnr_msg->rd_len = htons (rd_ser_len);
566 lnr_msg->name_len = htons (name_len);
567 lnr_msg->expire = GNUNET_TIME_absolute_hton (get_block_expiration_time (copied_elements,
568 rd_selected));
569 name_tmp = (char *) &lnr_msg[1];
570 memcpy (name_tmp, name, name_len);
571 rd_tmp = &name_tmp[name_len];
572 GNUNET_NAMESTORE_records_serialize (copied_elements, rd_selected, rd_ser_len, rd_tmp);
573 if (rd_selected != rd)
574 GNUNET_free_non_null (rd_selected);
575 if (NULL != zone_key)
576 lnr_msg->public_key = *zone_key;
577 if ( (GNUNET_YES == authoritative) &&
578 (copied_elements > 0) )
579 {
580 /* use new created signature */
581 lnr_msg->contains_sig = htons (GNUNET_YES);
582 GNUNET_assert (NULL != signature_new);
583 lnr_msg->signature = *signature_new;
584 GNUNET_free (signature_new);
585 }
586 else if (GNUNET_YES == contains_signature)
587 {
588 /* use existing signature */
589 lnr_msg->contains_sig = htons (GNUNET_YES);
590 GNUNET_assert (NULL != signature);
591 lnr_msg->signature = *signature;
592 }
593 GNUNET_SERVER_notification_context_unicast (snc, lnc->nc->client,
594 &lnr_msg->gns_header.header,
595 GNUNET_NO); 379 GNUNET_NO);
596 GNUNET_free (lnr_msg); 380 GNUNET_free (r);
597} 381}
598 382
599 383
600/** 384/**
601 * Send an empty name response to indicate the end of the 385 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK message
602 * set of results to the client.
603 *
604 * @param nc notification context to use for sending
605 * @param client destination of the empty response
606 * @param request_id identification for the request
607 */
608static void
609send_empty_response (struct GNUNET_SERVER_NotificationContext *nc,
610 struct GNUNET_SERVER_Client *client,
611 uint32_t request_id)
612{
613 struct LookupNameResponseMessage zir_end;
614
615 memset (&zir_end, 0, sizeof (zir_end));
616 zir_end.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE);
617 zir_end.gns_header.header.size = htons (sizeof (struct LookupNameResponseMessage));
618 zir_end.gns_header.r_id = htonl(request_id);
619 GNUNET_SERVER_notification_context_unicast (nc,
620 client,
621 &zir_end.gns_header.header, GNUNET_NO);
622}
623
624
625/**
626 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME' message
627 * 386 *
628 * @param cls unused 387 * @param cls unused
629 * @param client GNUNET_SERVER_Client sending the message 388 * @param client client sending the message
630 * @param message message of type 'struct LookupNameMessage' 389 * @param message message of type 'struct LookupNameMessage'
631 */ 390 */
632static void 391static void
633handle_lookup_name (void *cls, 392handle_lookup_block (void *cls,
634 struct GNUNET_SERVER_Client *client, 393 struct GNUNET_SERVER_Client *client,
635 const struct GNUNET_MessageHeader *message) 394 const struct GNUNET_MessageHeader *message)
636{ 395{
637 const struct LookupNameMessage *ln_msg; 396 const struct LookupBlockMessage *ln_msg;
638 struct LookupNameContext lnc; 397 struct LookupNameContext lnc;
639 struct NamestoreClient *nc; 398 struct NamestoreClient *nc;
640 size_t name_len; 399 struct LookupBlockResponseMessage zir_end;
641 const char *name;
642 uint32_t rid;
643 uint32_t type;
644 char *conv_name;
645 int ret; 400 int ret;
646 401
647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 402 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
648 "Received `%s' message\n", 403 "Received `%s' message\n",
649 "NAMESTORE_LOOKUP_NAME"); 404 "NAMESTORE_LOOKUP_NAME");
650 if (ntohs (message->size) < sizeof (struct LookupNameMessage)) 405 nc = client_lookup(client);
651 { 406 ln_msg = (const struct LookupBlockMessage *) message;
652 GNUNET_break (0); 407 lnc.request_id = ntohl (ln_msg->gns_header.r_id);
653 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
654 return;
655 }
656 if (NULL == (nc = client_lookup(client)))
657 {
658 GNUNET_break (0);
659 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
660 return;
661 }
662 ln_msg = (const struct LookupNameMessage *) message;
663 rid = ntohl (ln_msg->gns_header.r_id);
664 name_len = ntohl (ln_msg->name_len);
665 type = ntohl (ln_msg->record_type);
666 if ((0 == name_len) || (name_len > MAX_NAME_LEN))
667 {
668 GNUNET_break (0);
669 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
670 return;
671 }
672 name = (const char *) &ln_msg[1];
673 if ('\0' != name[name_len - 1])
674 {
675 GNUNET_break (0);
676 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
677 return;
678 }
679 if (GNUNET_NAMESTORE_TYPE_ANY == type)
680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
681 "Looking up all records for name `%s' in zone `%s'\n",
682 name,
683 GNUNET_NAMESTORE_short_h2s(&ln_msg->zone));
684 else
685 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
686 "Looking up records with type %u for name `%s' in zone `%s'\n",
687 type, name,
688 GNUNET_NAMESTORE_short_h2s(&ln_msg->zone));
689
690 conv_name = GNUNET_NAMESTORE_normalize_string (name);
691 if (NULL == conv_name)
692 {
693 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
694 "Error converting name `%s'\n", name);
695 return;
696 }
697
698 /* do the actual lookup */
699 lnc.request_id = rid;
700 lnc.nc = nc; 408 lnc.nc = nc;
701 lnc.record_type = type;
702 lnc.name = conv_name;
703 lnc.zone = &ln_msg->zone;
704 if (GNUNET_SYSERR == 409 if (GNUNET_SYSERR ==
705 (ret = GSN_database->iterate_records (GSN_database->cls, 410 (ret = GSN_database->lookup_block (GSN_database->cls,
706 &ln_msg->zone, conv_name, 0 /* offset */, 411 &ln_msg->query,
707 &handle_lookup_name_it, &lnc))) 412 &handle_lookup_block_it, &lnc)))
708 { 413 {
709 /* internal error (in database plugin); might be best to just hang up on 414 /* internal error (in database plugin); might be best to just hang up on
710 plugin rather than to signal that there are 'no' results, which 415 plugin rather than to signal that there are 'no' results, which
711 might also be false... */ 416 might also be false... */
712 GNUNET_break (0); 417 GNUNET_break (0);
713 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 418 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
714 GNUNET_free (conv_name);
715 return; 419 return;
716 } 420 }
717 GNUNET_free (conv_name);
718 if (0 == ret) 421 if (0 == ret)
719 { 422 {
720 /* no records match at all, generate empty response */ 423 /* no records match at all, generate empty response */
721 send_empty_response (snc, nc->client, rid); 424 memset (&zir_end, 0, sizeof (zir_end));
425 zir_end.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK_RESPONSE);
426 zir_end.gns_header.header.size = htons (sizeof (struct LookupBlockResponseMessage));
427 zir_end.gns_header.r_id = ln_msg->gns_header.r_id;
428 GNUNET_SERVER_notification_context_unicast (snc,
429 client,
430 &zir_end.gns_header.header,
431 GNUNET_NO);
432
433 }
434 GNUNET_SERVER_receive_done (client, GNUNET_OK);
435}
436
437
438/**
439 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE' message
440 *
441 * @param cls unused
442 * @param client GNUNET_SERVER_Client sending the message
443 * @param message message of type 'struct BlockCacheMessage'
444 */
445static void
446handle_block_cache (void *cls,
447 struct GNUNET_SERVER_Client *client,
448 const struct GNUNET_MessageHeader *message)
449{
450 struct NamestoreClient *nc;
451 const struct BlockCacheMessage *rp_msg;
452 struct BlockCacheResponseMessage rpr_msg;
453 struct GNUNET_NAMESTORE_Block *block;
454 size_t esize;
455 int res;
456
457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
458 "Received `%s' message\n",
459 "NAMESTORE_BLOCK_CACHE");
460 nc = client_lookup (client);
461 if (ntohs (message->size) < sizeof (struct BlockCacheMessage))
462 {
463 GNUNET_break (0);
464 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
465 return;
722 } 466 }
467 rp_msg = (const struct BlockCacheMessage *) message;
468 esize = ntohs (rp_msg->gns_header.header.size) - sizeof (struct BlockCacheMessage);
469
470 block = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Block) + esize);
471 block->signature = rp_msg->signature;
472 block->derived_key = rp_msg->derived_key;
473 block->purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
474 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
475 esize);
476 block->expiration_time = rp_msg->expire;
477 memcpy (&block[1], &rp_msg[1], esize);
478 res = GSN_database->cache_block (GSN_database->cls,
479 block);
480 GNUNET_free (block);
481
482 rpr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE_RESPONSE);
483 rpr_msg.gns_header.header.size = htons (sizeof (struct BlockCacheResponseMessage));
484 rpr_msg.gns_header.r_id = rp_msg->gns_header.r_id;
485 rpr_msg.op_result = htonl (res);
486 GNUNET_SERVER_notification_context_unicast (snc,
487 nc->client,
488 &rpr_msg.gns_header.header,
489 GNUNET_NO);
723 GNUNET_SERVER_receive_done (client, GNUNET_OK); 490 GNUNET_SERVER_receive_done (client, GNUNET_OK);
724} 491}
725 492
@@ -732,24 +499,20 @@ handle_lookup_name (void *cls,
732 * @param client client to unicast to 499 * @param client client to unicast to
733 * @param request_id request ID to use 500 * @param request_id request ID to use
734 * @param zone_key zone key of the zone 501 * @param zone_key zone key of the zone
735 * @param expire expiration time
736 * @param name name 502 * @param name name
737 * @param rd_count number of records 503 * @param rd_count number of records
738 * @param rd array of records 504 * @param rd array of records
739 * @param signature signature
740 */ 505 */
741static void 506static void
742send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc, 507send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc,
743 struct GNUNET_SERVER_Client *client, 508 struct GNUNET_SERVER_Client *client,
744 uint32_t request_id, 509 uint32_t request_id,
745 const struct GNUNET_CRYPTO_EccPublicKey *zone_key, 510 const struct GNUNET_CRYPTO_EccPrivateKey *zone_key,
746 struct GNUNET_TIME_Absolute expire,
747 const char *name, 511 const char *name,
748 unsigned int rd_count, 512 unsigned int rd_count,
749 const struct GNUNET_NAMESTORE_RecordData *rd, 513 const struct GNUNET_NAMESTORE_RecordData *rd)
750 const struct GNUNET_CRYPTO_EccSignature *signature)
751{ 514{
752 struct LookupNameResponseMessage *zir_msg; 515 struct RecordResultMessage *zir_msg;
753 size_t name_len; 516 size_t name_len;
754 size_t rd_ser_len; 517 size_t rd_ser_len;
755 size_t msg_size; 518 size_t msg_size;
@@ -758,27 +521,23 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc,
758 521
759 name_len = strlen (name) + 1; 522 name_len = strlen (name) + 1;
760 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd); 523 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
761 msg_size = sizeof (struct LookupNameResponseMessage) + name_len + rd_ser_len; 524 msg_size = sizeof (struct RecordResultMessage) + name_len + rd_ser_len;
762 525
763 zir_msg = GNUNET_malloc (msg_size); 526 zir_msg = GNUNET_malloc (msg_size);
764 zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE); 527 zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT);
765 zir_msg->gns_header.header.size = htons (msg_size); 528 zir_msg->gns_header.header.size = htons (msg_size);
766 zir_msg->gns_header.r_id = htonl (request_id); 529 zir_msg->gns_header.r_id = htonl (request_id);
767 zir_msg->expire = GNUNET_TIME_absolute_hton (expire);
768 zir_msg->contains_sig = htons ((NULL == signature) ? GNUNET_NO : GNUNET_YES);
769 zir_msg->name_len = htons (name_len); 530 zir_msg->name_len = htons (name_len);
770 zir_msg->rd_count = htons (rd_count); 531 zir_msg->rd_count = htons (rd_count);
771 zir_msg->rd_len = htons (rd_ser_len); 532 zir_msg->rd_len = htons (rd_ser_len);
772 if (NULL != signature) 533 zir_msg->private_key = *zone_key;
773 zir_msg->signature = *signature;
774 zir_msg->public_key = *zone_key;
775 name_tmp = (char *) &zir_msg[1]; 534 name_tmp = (char *) &zir_msg[1];
776 memcpy (name_tmp, name, name_len); 535 memcpy (name_tmp, name, name_len);
777 rd_ser = &name_tmp[name_len]; 536 rd_ser = &name_tmp[name_len];
778 GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser); 537 GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser);
779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
780 "Sending `%s' message with size %u\n", 539 "Sending `%s' message with size %u\n",
781 "ZONE_ITERATION_RESPONSE", 540 "RECORD_RESULT",
782 msg_size); 541 msg_size);
783 GNUNET_SERVER_notification_context_unicast (nc, 542 GNUNET_SERVER_notification_context_unicast (nc,
784 client, 543 client,
@@ -789,162 +548,20 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc,
789 548
790 549
791/** 550/**
792 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT' message 551 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE' message
793 * 552 *
794 * @param cls unused 553 * @param cls unused
795 * @param client GNUNET_SERVER_Client sending the message 554 * @param client client sending the message
796 * @param message message of type 'struct RecordPutMessage'
797 */
798static void
799handle_record_put (void *cls,
800 struct GNUNET_SERVER_Client *client,
801 const struct GNUNET_MessageHeader *message)
802{
803 struct NamestoreClient *nc;
804 const struct RecordPutMessage *rp_msg;
805 struct GNUNET_TIME_Absolute expire;
806 const struct GNUNET_CRYPTO_EccSignature *signature;
807 struct RecordPutResponseMessage rpr_msg;
808 struct GNUNET_CRYPTO_ShortHashCode zone_hash;
809 size_t name_len;
810 size_t msg_size;
811 size_t msg_size_exp;
812 const char *name;
813 const char *rd_ser;
814 char * conv_name;
815 uint32_t rid;
816 uint32_t rd_ser_len;
817 uint32_t rd_count;
818 int res;
819
820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
821 "Received `%s' message\n",
822 "NAMESTORE_RECORD_PUT");
823 if (ntohs (message->size) < sizeof (struct RecordPutMessage))
824 {
825 GNUNET_break (0);
826 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
827 return;
828 }
829 if (NULL == (nc = client_lookup (client)))
830 {
831 GNUNET_break (0);
832 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
833 return;
834 }
835 rp_msg = (const struct RecordPutMessage *) message;
836 rid = ntohl (rp_msg->gns_header.r_id);
837 msg_size = ntohs (rp_msg->gns_header.header.size);
838 name_len = ntohs (rp_msg->name_len);
839 rd_count = ntohs (rp_msg->rd_count);
840 rd_ser_len = ntohs (rp_msg->rd_len);
841 if ((rd_count < 1) || (rd_ser_len < 1) || (name_len >= MAX_NAME_LEN) || (0 == name_len))
842 {
843 GNUNET_break (0);
844 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
845 return;
846 }
847 msg_size_exp = sizeof (struct RecordPutMessage) + name_len + rd_ser_len;
848 if (msg_size != msg_size_exp)
849 {
850 GNUNET_break (0);
851 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
852 return;
853 }
854 name = (const char *) &rp_msg[1];
855 if ('\0' != name[name_len -1])
856 {
857 GNUNET_break (0);
858 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
859 return;
860 }
861 expire = GNUNET_TIME_absolute_ntoh (rp_msg->expire);
862 signature = &rp_msg->signature;
863 rd_ser = &name[name_len];
864 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
865
866 if (GNUNET_OK !=
867 GNUNET_NAMESTORE_records_deserialize (rd_ser_len, rd_ser, rd_count, rd))
868 {
869 GNUNET_break (0);
870 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
871 return;
872 }
873 GNUNET_CRYPTO_short_hash (&rp_msg->public_key,
874 sizeof (rp_msg->public_key),
875 &zone_hash);
876
877 conv_name = GNUNET_NAMESTORE_normalize_string (name);
878 if (NULL == conv_name)
879 {
880 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
881 "Error converting name `%s'\n", name);
882 return;
883 }
884
885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
886 "Putting %u records under name `%s' in zone `%s'\n",
887 rd_count, conv_name,
888 GNUNET_NAMESTORE_short_h2s (&zone_hash));
889 res = GSN_database->put_records (GSN_database->cls,
890 &rp_msg->public_key,
891 expire,
892 conv_name,
893 rd_count, rd,
894 signature);
895 if (GNUNET_OK == res)
896 {
897 struct ZoneMonitor *zm;
898
899 for (zm = monitor_head; NULL != zm; zm = zm->next)
900 if ( (GNUNET_NO == zm->has_zone) ||
901 (0 == memcmp (&zone_hash, &zm->zone, sizeof (struct GNUNET_CRYPTO_ShortHashCode))) )
902 send_lookup_response (monitor_nc,
903 zm->client,
904 zm->request_id,
905 &rp_msg->public_key,
906 expire,
907 conv_name,
908 rd_count, rd,
909 signature);
910 }
911 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
912 "Putting record for name `%s': %s\n",
913 conv_name,
914 (GNUNET_OK == res) ? "OK" : "FAILED");
915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
916 "Sending `%s' message\n",
917 "RECORD_PUT_RESPONSE");
918 GNUNET_free (conv_name);
919 rpr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE);
920 rpr_msg.gns_header.header.size = htons (sizeof (struct RecordPutResponseMessage));
921 rpr_msg.gns_header.r_id = htonl (rid);
922 rpr_msg.op_result = htonl (res);
923 GNUNET_SERVER_notification_context_unicast (snc,
924 nc->client,
925 &rpr_msg.gns_header.header,
926 GNUNET_NO);
927 GNUNET_SERVER_receive_done (client, GNUNET_OK);
928}
929
930
931/**
932 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE' message
933 *
934 * @param cls unused
935 * @param client GNUNET_SERVER_Client sending the message
936 * @param message message of type 'struct RecordCreateMessage' 555 * @param message message of type 'struct RecordCreateMessage'
937 */ 556 */
938static void 557static void
939handle_record_create (void *cls, 558handle_record_store (void *cls,
940 struct GNUNET_SERVER_Client *client, 559 struct GNUNET_SERVER_Client *client,
941 const struct GNUNET_MessageHeader *message) 560 const struct GNUNET_MessageHeader *message)
942{ 561{
943 static struct GNUNET_CRYPTO_EccSignature dummy_signature;
944 struct NamestoreClient *nc; 562 struct NamestoreClient *nc;
945 const struct RecordCreateMessage *rp_msg; 563 const struct RecordStoreMessage *rp_msg;
946 struct GNUNET_CRYPTO_EccPrivateKey *pkey; 564 struct RecordStoreResponseMessage rcr_msg;
947 struct RecordCreateResponseMessage rcr_msg;
948 size_t name_len; 565 size_t name_len;
949 size_t msg_size; 566 size_t msg_size;
950 size_t msg_size_exp; 567 size_t msg_size_exp;
@@ -955,31 +572,26 @@ handle_record_create (void *cls,
955 const char *rd_ser; 572 const char *rd_ser;
956 unsigned int rd_count; 573 unsigned int rd_count;
957 int res; 574 int res;
958 struct GNUNET_CRYPTO_ShortHashCode pubkey_hash;
959 struct GNUNET_CRYPTO_EccPublicKey pubkey; 575 struct GNUNET_CRYPTO_EccPublicKey pubkey;
960 576
961 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
962 "Received `%s' message\n", "NAMESTORE_RECORD_CREATE"); 578 "Received `%s' message\n",
963 if (ntohs (message->size) < sizeof (struct RecordCreateMessage)) 579 "NAMESTORE_RECORD_STORE");
964 { 580 if (ntohs (message->size) < sizeof (struct RecordStoreMessage))
965 GNUNET_break (0);
966 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
967 return;
968 }
969 if (NULL == (nc = client_lookup (client)))
970 { 581 {
971 GNUNET_break (0); 582 GNUNET_break (0);
972 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 583 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
973 return; 584 return;
974 } 585 }
975 rp_msg = (const struct RecordCreateMessage *) message; 586 nc = client_lookup (client);
587 rp_msg = (const struct RecordStoreMessage *) message;
976 rid = ntohl (rp_msg->gns_header.r_id); 588 rid = ntohl (rp_msg->gns_header.r_id);
977 name_len = ntohs (rp_msg->name_len); 589 name_len = ntohs (rp_msg->name_len);
978 msg_size = ntohs (message->size); 590 msg_size = ntohs (message->size);
979 rd_count = ntohs (rp_msg->rd_count); 591 rd_count = ntohs (rp_msg->rd_count);
980 rd_ser_len = ntohs (rp_msg->rd_len); 592 rd_ser_len = ntohs (rp_msg->rd_len);
981 GNUNET_break (0 == ntohs (rp_msg->reserved)); 593 GNUNET_break (0 == ntohs (rp_msg->reserved));
982 msg_size_exp = sizeof (struct RecordCreateMessage) + name_len + rd_ser_len; 594 msg_size_exp = sizeof (struct RecordStoreMessage) + name_len + rd_ser_len;
983 if (msg_size != msg_size_exp) 595 if (msg_size != msg_size_exp)
984 { 596 {
985 GNUNET_break (0); 597 GNUNET_break (0);
@@ -1000,8 +612,6 @@ handle_record_create (void *cls,
1000 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 612 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1001 return; 613 return;
1002 } 614 }
1003 pkey = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
1004 memcpy (pkey, &rp_msg->private_key, sizeof (struct GNUNET_CRYPTO_EccPrivateKey));
1005 { 615 {
1006 struct GNUNET_NAMESTORE_RecordData rd[rd_count]; 616 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
1007 617
@@ -1009,23 +619,18 @@ handle_record_create (void *cls,
1009 GNUNET_NAMESTORE_records_deserialize (rd_ser_len, rd_ser, rd_count, rd)) 619 GNUNET_NAMESTORE_records_deserialize (rd_ser_len, rd_ser, rd_count, rd))
1010 { 620 {
1011 GNUNET_break (0); 621 GNUNET_break (0);
1012 GNUNET_CRYPTO_ecc_key_free (pkey);
1013 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 622 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1014 return; 623 return;
1015 } 624 }
1016 625
1017 /* Extracting and converting private key */ 626 /* Extracting and converting private key */
1018 GNUNET_CRYPTO_ecc_key_get_public (pkey, &pubkey); 627 GNUNET_CRYPTO_ecc_key_get_public (&rp_msg->private_key,
1019 GNUNET_CRYPTO_short_hash (&pubkey, 628 &pubkey);
1020 sizeof (struct GNUNET_CRYPTO_EccPublicKey),
1021 &pubkey_hash);
1022 learn_private_key (pkey);
1023 conv_name = GNUNET_NAMESTORE_normalize_string (name_tmp); 629 conv_name = GNUNET_NAMESTORE_normalize_string (name_tmp);
1024 if (NULL == conv_name) 630 if (NULL == conv_name)
1025 { 631 {
1026 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 632 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1027 "Error converting name `%s'\n", name_tmp); 633 "Error converting name `%s'\n", name_tmp);
1028 GNUNET_CRYPTO_ecc_key_free (pkey);
1029 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 634 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1030 return; 635 return;
1031 } 636 }
@@ -1033,42 +638,35 @@ handle_record_create (void *cls,
1033 "Creating %u records for name `%s' in zone `%s'\n", 638 "Creating %u records for name `%s' in zone `%s'\n",
1034 (unsigned int) rd_count, 639 (unsigned int) rd_count,
1035 conv_name, 640 conv_name,
1036 GNUNET_NAMESTORE_short_h2s (&pubkey_hash)); 641 GNUNET_NAMESTORE_z2s (&pubkey));
1037 if (0 == rd_count) 642 res = GSN_database->store_records (GSN_database->cls,
1038 res = GSN_database->remove_records (GSN_database->cls, 643 &rp_msg->private_key,
1039 &pubkey_hash, 644 conv_name,
1040 conv_name); 645 rd_count, rd);
1041 else
1042 res = GSN_database->put_records (GSN_database->cls,
1043 &pubkey,
1044 GNUNET_TIME_absolute_ntoh (rp_msg->expire),
1045 conv_name,
1046 rd_count, rd,
1047 &dummy_signature);
1048 if (GNUNET_OK == res) 646 if (GNUNET_OK == res)
1049 { 647 {
1050 struct ZoneMonitor *zm; 648 struct ZoneMonitor *zm;
1051 649
1052 for (zm = monitor_head; NULL != zm; zm = zm->next) 650 for (zm = monitor_head; NULL != zm; zm = zm->next)
1053 if ( (GNUNET_NO == zm->has_zone) || 651 if (0 == memcmp (&rp_msg->private_key,
1054 (0 == memcmp (&pubkey_hash, &zm->zone, sizeof (struct GNUNET_CRYPTO_ShortHashCode))) ) 652 &zm->zone,
653 sizeof (struct GNUNET_CRYPTO_EccPrivateKey)))
1055 send_lookup_response (monitor_nc, 654 send_lookup_response (monitor_nc,
1056 zm->client, 655 zm->nc->client,
1057 zm->request_id, 656 zm->request_id,
1058 &pubkey, 657 &rp_msg->private_key,
1059 GNUNET_TIME_absolute_ntoh (rp_msg->expire),
1060 conv_name, 658 conv_name,
1061 rd_count, rd, 659 rd_count, rd);
1062 &dummy_signature);
1063 } 660 }
1064 GNUNET_free (conv_name); 661 GNUNET_free (conv_name);
1065 } 662 }
1066 663
1067 /* Send response */ 664 /* Send response */
1068 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 665 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1069 "Sending `%s' message\n", "RECORD_CREATE_RESPONSE"); 666 "Sending `%s' message\n",
1070 rcr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE); 667 "RECORD_STORE_RESPONSE");
1071 rcr_msg.gns_header.header.size = htons (sizeof (struct RecordCreateResponseMessage)); 668 rcr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE);
669 rcr_msg.gns_header.header.size = htons (sizeof (struct RecordStoreResponseMessage));
1072 rcr_msg.gns_header.r_id = htonl (rid); 670 rcr_msg.gns_header.r_id = htonl (rid);
1073 rcr_msg.op_result = htonl (res); 671 rcr_msg.op_result = htonl (res);
1074 GNUNET_SERVER_notification_context_unicast (snc, nc->client, 672 GNUNET_SERVER_notification_context_unicast (snc, nc->client,
@@ -1108,20 +706,16 @@ struct ZoneToNameCtx
1108 * 706 *
1109 * @param cls struct ZoneToNameCtx * 707 * @param cls struct ZoneToNameCtx *
1110 * @param zone_key the zone key 708 * @param zone_key the zone key
1111 * @param expire expiration date
1112 * @param name name 709 * @param name name
1113 * @param rd_count number of records 710 * @param rd_count number of records
1114 * @param rd record data 711 * @param rd record data
1115 * @param signature signature
1116 */ 712 */
1117static void 713static void
1118handle_zone_to_name_it (void *cls, 714handle_zone_to_name_it (void *cls,
1119 const struct GNUNET_CRYPTO_EccPublicKey *zone_key, 715 const struct GNUNET_CRYPTO_EccPrivateKey *zone_key,
1120 struct GNUNET_TIME_Absolute expire,
1121 const char *name, 716 const char *name,
1122 unsigned int rd_count, 717 unsigned int rd_count,
1123 const struct GNUNET_NAMESTORE_RecordData *rd, 718 const struct GNUNET_NAMESTORE_RecordData *rd)
1124 const struct GNUNET_CRYPTO_EccSignature *signature)
1125{ 719{
1126 struct ZoneToNameCtx *ztn_ctx = cls; 720 struct ZoneToNameCtx *ztn_ctx = cls;
1127 struct ZoneToNameResponseMessage *ztnr_msg; 721 struct ZoneToNameResponseMessage *ztnr_msg;
@@ -1131,32 +725,14 @@ handle_zone_to_name_it (void *cls,
1131 size_t msg_size; 725 size_t msg_size;
1132 char *name_tmp; 726 char *name_tmp;
1133 char *rd_tmp; 727 char *rd_tmp;
1134 char *sig_tmp;
1135 728
1136 if ((NULL != zone_key) && (NULL != name))
1137 {
1138 /* found result */
1139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1140 "Found result: name `%s' has %u records\n",
1141 name, rd_count);
1142 res = GNUNET_YES;
1143 name_len = strlen (name) + 1;
1144 }
1145 else
1146 {
1147 /* no result found */
1148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1149 "Found no results\n");
1150 res = GNUNET_NO;
1151 name_len = 0;
1152 }
1153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 729 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1154 "Sending `%s' message\n", 730 "Found result for zone-to-name lookup: `%s'\n",
1155 "ZONE_TO_NAME_RESPONSE"); 731 name);
732 res = GNUNET_YES;
733 name_len = strlen (name) + 1;
1156 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd); 734 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
1157 msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len; 735 msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len;
1158 if (NULL != signature)
1159 msg_size += sizeof (struct GNUNET_CRYPTO_EccSignature);
1160 if (msg_size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 736 if (msg_size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1161 { 737 {
1162 GNUNET_break (0); 738 GNUNET_break (0);
@@ -1171,17 +747,12 @@ handle_zone_to_name_it (void *cls,
1171 ztnr_msg->rd_len = htons (rd_ser_len); 747 ztnr_msg->rd_len = htons (rd_ser_len);
1172 ztnr_msg->rd_count = htons (rd_count); 748 ztnr_msg->rd_count = htons (rd_count);
1173 ztnr_msg->name_len = htons (name_len); 749 ztnr_msg->name_len = htons (name_len);
1174 ztnr_msg->expire = GNUNET_TIME_absolute_hton (expire); 750 ztnr_msg->zone = *zone_key;
1175 if (NULL != zone_key)
1176 ztnr_msg->zone_key = *zone_key;
1177 name_tmp = (char *) &ztnr_msg[1]; 751 name_tmp = (char *) &ztnr_msg[1];
1178 if (NULL != name) 752 if (NULL != name)
1179 memcpy (name_tmp, name, name_len); 753 memcpy (name_tmp, name, name_len);
1180 rd_tmp = &name_tmp[name_len]; 754 rd_tmp = &name_tmp[name_len];
1181 GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_tmp); 755 GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_tmp);
1182 sig_tmp = &rd_tmp[rd_ser_len];
1183 if (NULL != signature)
1184 memcpy (sig_tmp, signature, sizeof (struct GNUNET_CRYPTO_EccSignature));
1185 ztn_ctx->success = GNUNET_OK; 756 ztn_ctx->success = GNUNET_OK;
1186 GNUNET_SERVER_notification_context_unicast (snc, ztn_ctx->nc->client, 757 GNUNET_SERVER_notification_context_unicast (snc, ztn_ctx->nc->client,
1187 &ztnr_msg->gns_header.header, 758 &ztnr_msg->gns_header.header,
@@ -1205,20 +776,16 @@ handle_zone_to_name (void *cls,
1205 struct NamestoreClient *nc; 776 struct NamestoreClient *nc;
1206 const struct ZoneToNameMessage *ztn_msg; 777 const struct ZoneToNameMessage *ztn_msg;
1207 struct ZoneToNameCtx ztn_ctx; 778 struct ZoneToNameCtx ztn_ctx;
779 struct ZoneToNameResponseMessage ztnr_msg;
1208 780
1209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1210 "Received `%s' message\n", 782 "Received `%s' message\n",
1211 "ZONE_TO_NAME"); 783 "ZONE_TO_NAME");
1212 ztn_msg = (const struct ZoneToNameMessage *) message; 784 ztn_msg = (const struct ZoneToNameMessage *) message;
1213 if (NULL == (nc = client_lookup(client))) 785 nc = client_lookup (client);
1214 {
1215 GNUNET_break (0);
1216 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1217 return;
1218 }
1219 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id); 786 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id);
1220 ztn_ctx.nc = nc; 787 ztn_ctx.nc = nc;
1221 ztn_ctx.success = GNUNET_SYSERR; 788 ztn_ctx.success = GNUNET_NO;
1222 if (GNUNET_SYSERR == 789 if (GNUNET_SYSERR ==
1223 GSN_database->zone_to_name (GSN_database->cls, 790 GSN_database->zone_to_name (GSN_database->cls,
1224 &ztn_msg->zone, 791 &ztn_msg->zone,
@@ -1231,6 +798,19 @@ handle_zone_to_name (void *cls,
1231 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 798 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1232 return; 799 return;
1233 } 800 }
801 if (GNUNET_NO == ztn_ctx.success)
802 {
803 /* no result found, send empty response */
804 memset (&ztnr_msg, 0, sizeof (ztnr_msg));
805 ztnr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE);
806 ztnr_msg.gns_header.header.size = htons (sizeof (ztnr_msg));
807 ztnr_msg.gns_header.r_id = ztn_msg->gns_header.r_id;
808 ztnr_msg.res = htons (GNUNET_NO);
809 GNUNET_SERVER_notification_context_unicast (snc,
810 client,
811 &ztnr_msg.gns_header.header,
812 GNUNET_NO);
813 }
1234 GNUNET_SERVER_receive_done (client, ztn_ctx.success); 814 GNUNET_SERVER_receive_done (client, ztn_ctx.success);
1235} 815}
1236 816
@@ -1241,21 +821,20 @@ handle_zone_to_name (void *cls,
1241enum ZoneIterationResult 821enum ZoneIterationResult
1242{ 822{
1243 /** 823 /**
1244 * Found records, but all records were filtered 824 * Iteration start.
1245 * Continue to iterate
1246 */ 825 */
1247 IT_ALL_RECORDS_FILTERED = -1, 826 IT_START = 0,
1248 827
1249 /** 828 /**
1250 * Found records, 829 * Found records,
1251 * Continue to iterate with next iteration_next call 830 * Continue to iterate with next iteration_next call
1252 */ 831 */
1253 IT_SUCCESS_MORE_AVAILABLE = 0, 832 IT_SUCCESS_MORE_AVAILABLE = 1,
1254 833
1255 /** 834 /**
1256 * Iteration complete 835 * Iteration complete
1257 */ 836 */
1258 IT_SUCCESS_NOT_MORE_RESULTS_AVAILABLE = 1 837 IT_SUCCESS_NOT_MORE_RESULTS_AVAILABLE = 2
1259}; 838};
1260 839
1261 840
@@ -1295,24 +874,13 @@ struct ZoneIterationProcResult
1295 */ 874 */
1296static void 875static void
1297zone_iteraterate_proc (void *cls, 876zone_iteraterate_proc (void *cls,
1298 const struct GNUNET_CRYPTO_EccPublicKey *zone_key, 877 const struct GNUNET_CRYPTO_EccPrivateKey *zone_key,
1299 struct GNUNET_TIME_Absolute expire,
1300 const char *name, 878 const char *name,
1301 unsigned int rd_count, 879 unsigned int rd_count,
1302 const struct GNUNET_NAMESTORE_RecordData *rd, 880 const struct GNUNET_NAMESTORE_RecordData *rd)
1303 const struct GNUNET_CRYPTO_EccSignature *signature)
1304{ 881{
1305 struct ZoneIterationProcResult *proc = cls; 882 struct ZoneIterationProcResult *proc = cls;
1306 struct GNUNET_NAMESTORE_RecordData rd_filtered[rd_count];
1307 struct GNUNET_CRYPTO_EccSignature *new_signature = NULL;
1308 struct GNUNET_NAMESTORE_CryptoContainer *cc;
1309 struct GNUNET_HashCode long_hash;
1310 struct GNUNET_CRYPTO_ShortHashCode zone_hash;
1311 struct GNUNET_TIME_Relative rt;
1312 unsigned int rd_count_filtered;
1313 unsigned int c;
1314 883
1315 proc->res_iteration_finished = IT_SUCCESS_MORE_AVAILABLE;
1316 if ((NULL == zone_key) && (NULL == name)) 884 if ((NULL == zone_key) && (NULL == name))
1317 { 885 {
1318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 886 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1323,136 +891,18 @@ zone_iteraterate_proc (void *cls,
1323 if ((NULL == zone_key) || (NULL == name)) 891 if ((NULL == zone_key) || (NULL == name))
1324 { 892 {
1325 /* what is this!? should never happen */ 893 /* what is this!? should never happen */
894 proc->res_iteration_finished = IT_START;
1326 GNUNET_break (0); 895 GNUNET_break (0);
1327 return; 896 return;
1328 } 897 }
1329 rd_count_filtered = 0; 898 proc->res_iteration_finished = IT_SUCCESS_MORE_AVAILABLE;
1330 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1331 "Received result for zone iteration: `%s'\n",
1332 name);
1333 for (c = 0; c < rd_count; c++)
1334 {
1335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1336 "Record %u has flags: %x must have flags are %x, must not have flags are %x\n",
1337 c, rd[c].flags,
1338 proc->zi->must_have_flags,
1339 proc->zi->must_not_have_flags);
1340 /* Checking must have flags, except 'relative-expiration' which is a special flag */
1341 if ((rd[c].flags & proc->zi->must_have_flags & (~GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION))
1342 != (proc->zi->must_have_flags & (~ GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)))
1343 {
1344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %u lacks 'must-have' flags: Not included\n", c);
1345 continue;
1346 }
1347 /* Checking must-not-have flags */
1348 if (0 != (rd[c].flags & proc->zi->must_not_have_flags))
1349 {
1350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1351 "Record %u has 'must-not-have' flags: Not included\n", c);
1352 continue;
1353 }
1354 rd_filtered[rd_count_filtered] = rd[c];
1355 /* convert relative to absolute expiration time unless explicitly requested otherwise */
1356 if ( (0 == (proc->zi->must_have_flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)) &&
1357 (0 != (rd[c].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)) )
1358 {
1359 /* should convert relative-to-absolute expiration time */
1360 rt.rel_value_us = rd[c].expiration_time;
1361 rd_filtered[c].expiration_time = GNUNET_TIME_relative_to_absolute (rt).abs_value_us;
1362 rd_filtered[c].flags &= ~ GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
1363 }
1364 /* we NEVER keep the 'authority' flag */
1365 rd_filtered[c].flags &= ~ GNUNET_NAMESTORE_RF_AUTHORITY;
1366 rd_count_filtered++;
1367 }
1368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1369 "Included %u of %u records\n",
1370 rd_count_filtered, rd_count);
1371
1372 signature = NULL;
1373 if ( (rd_count_filtered > 0) &&
1374 (0 == (proc->zi->must_have_flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)) )
1375 {
1376 /* compute / obtain signature, but only if we (a) have records and (b) expiration times were
1377 converted to absolute expiration times */
1378 GNUNET_CRYPTO_short_hash (zone_key,
1379 sizeof (struct GNUNET_CRYPTO_EccPublicKey),
1380 &zone_hash);
1381 GNUNET_CRYPTO_short_hash_double (&zone_hash, &long_hash);
1382 if (NULL != (cc = GNUNET_CONTAINER_multihashmap_get (zonekeys, &long_hash)))
1383 {
1384 expire = get_block_expiration_time (rd_count_filtered, rd_filtered);
1385
1386
1387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1388 "Creating signature for `%s' in zone `%s' with %u records and expiration %s\n",
1389 name, GNUNET_NAMESTORE_short_h2s(&zone_hash),
1390 rd_count_filtered,
1391 GNUNET_STRINGS_absolute_time_to_string (expire));
1392 /* TODO 1) AB: New publishing
1393 * - Create HDKF(Q,i)
1394 * - Encrypt record block R with HKDF: HDKF(Q,i) == E(R)
1395 * - Create block |e,E(R)|
1396 * - Create d: h * x mod n == hash (name, zone) * c->privkey mod n
1397 * - Create ECC signature S_d (e, E_HKDF(Q,i))
1398 *
1399 * Return: zone_key , expire, name, rd_count_filtered, new signature S_d
1400 *
1401 * Q: zone's public key
1402 * x: zone's private key
1403 * i: name
1404 * d: derived secret
1405 *
1406 * - how do I get n:
1407 * Extract from private key s_expression
1408 * Question
1409 * - how do I multiply h * x?
1410 */
1411
1412 new_signature = GNUNET_NAMESTORE_create_signature (cc->privkey, expire, name,
1413 rd_filtered, rd_count_filtered);
1414 GNUNET_assert (NULL != new_signature);
1415 signature = new_signature;
1416 }
1417 else if (rd_count_filtered == rd_count)
1418 {
1419 if (NULL != signature)
1420 {
1421 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1422 "Using provided signature for `%s' in zone `%s' with %u records and expiration %s\n",
1423 name, GNUNET_NAMESTORE_short_h2s (&zone_hash), rd_count_filtered,
1424 GNUNET_STRINGS_absolute_time_to_string (expire));
1425 return;
1426 }
1427 }
1428 }
1429 if (0 == rd_count_filtered)
1430 {
1431 /* After filtering records there are no records left to return */
1432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No records to transmit\n");
1433 proc->res_iteration_finished = IT_ALL_RECORDS_FILTERED;
1434 return;
1435 }
1436
1437 if (GNUNET_YES == proc->zi->has_zone)
1438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1439 "Sending name `%s' for iteration over zone `%s'\n",
1440 name, GNUNET_NAMESTORE_short_h2s(&proc->zi->zone));
1441 else
1442 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1443 "Sending name `%s' for iteration over all zones\n",
1444 name);
1445 send_lookup_response (snc, 899 send_lookup_response (snc,
1446 proc->zi->client->client, 900 proc->zi->client->client,
1447 proc->zi->request_id, 901 proc->zi->request_id,
1448 zone_key, 902 zone_key,
1449 expire,
1450 name, 903 name,
1451 rd_count_filtered, 904 rd_count,
1452 rd_filtered, 905 rd);
1453 signature);
1454 proc->res_iteration_finished = IT_SUCCESS_MORE_AVAILABLE;
1455 GNUNET_free_non_null (new_signature);
1456} 906}
1457 907
1458 908
@@ -1465,20 +915,17 @@ static void
1465run_zone_iteration_round (struct ZoneIteration *zi) 915run_zone_iteration_round (struct ZoneIteration *zi)
1466{ 916{
1467 struct ZoneIterationProcResult proc; 917 struct ZoneIterationProcResult proc;
1468 struct GNUNET_CRYPTO_ShortHashCode *zone; 918 struct RecordResultMessage rrm;
1469 int ret; 919 int ret;
1470 920
1471 memset (&proc, 0, sizeof (proc)); 921 memset (&proc, 0, sizeof (proc));
1472 proc.zi = zi; 922 proc.zi = zi;
1473 if (GNUNET_YES == zi->has_zone) 923 proc.res_iteration_finished = IT_START;
1474 zone = &zi->zone; 924 while (IT_START == proc.res_iteration_finished)
1475 else
1476 zone = NULL;
1477 proc.res_iteration_finished = IT_ALL_RECORDS_FILTERED;
1478 while (IT_ALL_RECORDS_FILTERED == proc.res_iteration_finished)
1479 { 925 {
1480 if (GNUNET_SYSERR == 926 if (GNUNET_SYSERR ==
1481 (ret = GSN_database->iterate_records (GSN_database->cls, zone, NULL, 927 (ret = GSN_database->iterate_records (GSN_database->cls,
928 &zi->zone,
1482 zi->offset, 929 zi->offset,
1483 &zone_iteraterate_proc, &proc))) 930 &zone_iteraterate_proc, &proc)))
1484 { 931 {
@@ -1495,16 +942,15 @@ run_zone_iteration_round (struct ZoneIteration *zi)
1495 "More results available\n"); 942 "More results available\n");
1496 return; /* more results later */ 943 return; /* more results later */
1497 } 944 }
1498 if (GNUNET_YES == zi->has_zone) 945 /* send empty response to indicate end of list */
1499 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 946 memset (&rrm, 0, sizeof (rrm));
1500 "No more results for zone `%s'\n", 947 rrm.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT);
1501 GNUNET_NAMESTORE_short_h2s(&zi->zone)); 948 rrm.gns_header.header.size = htons (sizeof (rrm));
1502 else 949 rrm.gns_header.r_id = htonl (zi->request_id);
1503 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 950 GNUNET_SERVER_notification_context_unicast (snc,
1504 "No more results for all zones\n"); 951 zi->client->client,
1505 send_empty_response (snc, zi->client->client, zi->request_id); 952 &rrm.gns_header.header,
1506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 953 GNUNET_NO);
1507 "Removing zone iterator\n");
1508 GNUNET_CONTAINER_DLL_remove (zi->client->op_head, 954 GNUNET_CONTAINER_DLL_remove (zi->client->op_head,
1509 zi->client->op_tail, 955 zi->client->op_tail,
1510 zi); 956 zi);
@@ -1524,7 +970,6 @@ handle_iteration_start (void *cls,
1524 struct GNUNET_SERVER_Client *client, 970 struct GNUNET_SERVER_Client *client,
1525 const struct GNUNET_MessageHeader *message) 971 const struct GNUNET_MessageHeader *message)
1526{ 972{
1527 static struct GNUNET_CRYPTO_ShortHashCode zeros;
1528 const struct ZoneIterationStartMessage *zis_msg; 973 const struct ZoneIterationStartMessage *zis_msg;
1529 struct NamestoreClient *nc; 974 struct NamestoreClient *nc;
1530 struct ZoneIteration *zi; 975 struct ZoneIteration *zi;
@@ -1541,21 +986,7 @@ handle_iteration_start (void *cls,
1541 zi->request_id = ntohl (zis_msg->gns_header.r_id); 986 zi->request_id = ntohl (zis_msg->gns_header.r_id);
1542 zi->offset = 0; 987 zi->offset = 0;
1543 zi->client = nc; 988 zi->client = nc;
1544 zi->must_have_flags = ntohs (zis_msg->must_have_flags); 989 zi->zone = zis_msg->zone;
1545 zi->must_not_have_flags = ntohs (zis_msg->must_not_have_flags);
1546 if (0 == memcmp (&zeros, &zis_msg->zone, sizeof (zeros)))
1547 {
1548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over all zones\n");
1549 zi->zone = zis_msg->zone;
1550 zi->has_zone = GNUNET_NO;
1551 }
1552 else
1553 {
1554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1555 "Starting to iterate over zone `%s'\n", GNUNET_NAMESTORE_short_h2s (&zis_msg->zone));
1556 zi->zone = zis_msg->zone;
1557 zi->has_zone = GNUNET_YES;
1558 }
1559 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); 990 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi);
1560 run_zone_iteration_round (zi); 991 run_zone_iteration_round (zi);
1561 GNUNET_SERVER_receive_done (client, GNUNET_OK); 992 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -1600,13 +1031,6 @@ handle_iteration_stop (void *cls,
1600 return; 1031 return;
1601 } 1032 }
1602 GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, zi); 1033 GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, zi);
1603 if (GNUNET_YES == zi->has_zone)
1604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1605 "Stopped zone iteration for zone `%s'\n",
1606 GNUNET_NAMESTORE_short_h2s (&zi->zone));
1607 else
1608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1609 "Stopped zone iteration over all zones\n");
1610 GNUNET_free (zi); 1034 GNUNET_free (zi);
1611 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1035 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1612} 1036}
@@ -1653,30 +1077,6 @@ handle_iteration_next (void *cls,
1653 1077
1654 1078
1655/** 1079/**
1656 * Load zone keys from directory by reading all .zkey files in this directory
1657 *
1658 * @param cls int * 'counter' to store the number of files found
1659 * @param filename directory to scan
1660 * @return GNUNET_OK to continue
1661 */
1662static int
1663zonekey_file_it (void *cls, const char *filename)
1664{
1665 unsigned int *counter = cls;
1666 struct GNUNET_CRYPTO_EccPrivateKey *pk;
1667
1668
1669 if ((NULL == filename) ||
1670 (NULL == strstr (filename, ".zkey")))
1671 return GNUNET_OK;
1672 pk = GNUNET_CRYPTO_ecc_key_create_from_file (filename);
1673 learn_private_key (pk);
1674 (*counter)++;
1675 return GNUNET_OK;
1676}
1677
1678
1679/**
1680 * Send 'sync' message to zone monitor, we're now in sync. 1080 * Send 'sync' message to zone monitor, we're now in sync.
1681 * 1081 *
1682 * @param zm monitor that is now in sync 1082 * @param zm monitor that is now in sync
@@ -1689,7 +1089,7 @@ monitor_sync (struct ZoneMonitor *zm)
1689 sync.size = htons (sizeof (struct GNUNET_MessageHeader)); 1089 sync.size = htons (sizeof (struct GNUNET_MessageHeader));
1690 sync.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC); 1090 sync.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC);
1691 GNUNET_SERVER_notification_context_unicast (monitor_nc, 1091 GNUNET_SERVER_notification_context_unicast (monitor_nc,
1692 zm->client, 1092 zm->nc->client,
1693 &sync, 1093 &sync,
1694 GNUNET_NO); 1094 GNUNET_NO);
1695} 1095}
@@ -1719,12 +1119,10 @@ monitor_next (void *cls,
1719 */ 1119 */
1720static void 1120static void
1721monitor_iterate_cb (void *cls, 1121monitor_iterate_cb (void *cls,
1722 const struct GNUNET_CRYPTO_EccPublicKey *zone_key, 1122 const struct GNUNET_CRYPTO_EccPrivateKey *zone_key,
1723 struct GNUNET_TIME_Absolute expire,
1724 const char *name, 1123 const char *name,
1725 unsigned int rd_count, 1124 unsigned int rd_count,
1726 const struct GNUNET_NAMESTORE_RecordData *rd, 1125 const struct GNUNET_NAMESTORE_RecordData *rd)
1727 const struct GNUNET_CRYPTO_EccSignature *signature)
1728{ 1126{
1729 struct ZoneMonitor *zm = cls; 1127 struct ZoneMonitor *zm = cls;
1730 1128
@@ -1735,14 +1133,12 @@ monitor_iterate_cb (void *cls,
1735 return; 1133 return;
1736 } 1134 }
1737 send_lookup_response (monitor_nc, 1135 send_lookup_response (monitor_nc,
1738 zm->client, 1136 zm->nc->client,
1739 zm->request_id, 1137 zm->request_id,
1740 zone_key, 1138 zone_key,
1741 expire,
1742 name, 1139 name,
1743 rd_count, 1140 rd_count,
1744 rd, 1141 rd);
1745 signature);
1746 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, zm); 1142 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, zm);
1747} 1143}
1748 1144
@@ -1759,10 +1155,9 @@ handle_monitor_start (void *cls,
1759 struct GNUNET_SERVER_Client *client, 1155 struct GNUNET_SERVER_Client *client,
1760 const struct GNUNET_MessageHeader *message) 1156 const struct GNUNET_MessageHeader *message)
1761{ 1157{
1762 static struct GNUNET_CRYPTO_ShortHashCode zeros;
1763 const struct ZoneMonitorStartMessage *zis_msg; 1158 const struct ZoneMonitorStartMessage *zis_msg;
1764 struct ZoneMonitor *zm; 1159 struct ZoneMonitor *zm;
1765 1160
1766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1767 "Received `%s' message\n", 1162 "Received `%s' message\n",
1768 "ZONE_MONITOR_START"); 1163 "ZONE_MONITOR_START");
@@ -1770,22 +1165,8 @@ handle_monitor_start (void *cls,
1770 zm = GNUNET_new (struct ZoneMonitor); 1165 zm = GNUNET_new (struct ZoneMonitor);
1771 zm->request_id = ntohl (zis_msg->gns_header.r_id); 1166 zm->request_id = ntohl (zis_msg->gns_header.r_id);
1772 zm->offset = 0; 1167 zm->offset = 0;
1773 zm->client = client; // FIXME: notify handler for disconnects, check monitors! 1168 zm->nc = client_lookup (client);
1774 if (0 == memcmp (&zeros, &zis_msg->zone, sizeof (zeros))) 1169 zm->zone = zis_msg->zone;
1775 {
1776 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1777 "Starting to monitor all zones\n");
1778 zm->zone = zis_msg->zone;
1779 zm->has_zone = GNUNET_NO;
1780 }
1781 else
1782 {
1783 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1784 "Starting to monitor zone `%s'\n",
1785 GNUNET_NAMESTORE_short_h2s (&zis_msg->zone));
1786 zm->zone = zis_msg->zone;
1787 zm->has_zone = GNUNET_YES;
1788 }
1789 GNUNET_CONTAINER_DLL_insert (monitor_head, monitor_tail, zm); 1170 GNUNET_CONTAINER_DLL_insert (monitor_head, monitor_tail, zm);
1790 GNUNET_SERVER_client_mark_monitor (client); 1171 GNUNET_SERVER_client_mark_monitor (client);
1791 GNUNET_SERVER_disable_receive_done_warning (client); 1172 GNUNET_SERVER_disable_receive_done_warning (client);
@@ -1810,12 +1191,12 @@ monitor_next (void *cls,
1810 1191
1811 zm->task = GNUNET_SCHEDULER_NO_TASK; 1192 zm->task = GNUNET_SCHEDULER_NO_TASK;
1812 ret = GSN_database->iterate_records (GSN_database->cls, 1193 ret = GSN_database->iterate_records (GSN_database->cls,
1813 (GNUNET_YES == zm->has_zone) ? &zm->zone : NULL, 1194 &zm->zone,
1814 NULL, zm->offset++, 1195 zm->offset++,
1815 &monitor_iterate_cb, zm); 1196 &monitor_iterate_cb, zm);
1816 if (GNUNET_SYSERR == ret) 1197 if (GNUNET_SYSERR == ret)
1817 { 1198 {
1818 GNUNET_SERVER_client_disconnect (zm->client); 1199 GNUNET_SERVER_client_disconnect (zm->nc->client);
1819 return; 1200 return;
1820 } 1201 }
1821 if (GNUNET_NO == ret) 1202 if (GNUNET_NO == ret)
@@ -1839,14 +1220,12 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1839 const struct GNUNET_CONFIGURATION_Handle *cfg) 1220 const struct GNUNET_CONFIGURATION_Handle *cfg)
1840{ 1221{
1841 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 1222 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1842 {&handle_start, NULL, 1223 {&handle_lookup_block, NULL,
1843 GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)}, 1224 GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK, sizeof (struct LookupBlockMessage)},
1844 {&handle_lookup_name, NULL, 1225 {&handle_block_cache, NULL,
1845 GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, 0}, 1226 GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE, 0},
1846 {&handle_record_put, NULL, 1227 {&handle_record_store, NULL,
1847 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT, 0}, 1228 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE, 0},
1848 {&handle_record_create, NULL,
1849 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE, 0},
1850 {&handle_zone_to_name, NULL, 1229 {&handle_zone_to_name, NULL,
1851 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, sizeof (struct ZoneToNameMessage) }, 1230 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, sizeof (struct ZoneToNameMessage) },
1852 {&handle_iteration_start, NULL, 1231 {&handle_iteration_start, NULL,
@@ -1860,48 +1239,10 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1860 {NULL, NULL, 0, 0} 1239 {NULL, NULL, 0, 0}
1861 }; 1240 };
1862 char *database; 1241 char *database;
1863 unsigned int counter;
1864 1242
1865 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n"); 1243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n");
1866 GSN_cfg = cfg; 1244 GSN_cfg = cfg;
1867 monitor_nc = GNUNET_SERVER_notification_context_create (server, 1); 1245 monitor_nc = GNUNET_SERVER_notification_context_create (server, 1);
1868 /* Load private keys from disk */
1869 if (GNUNET_OK !=
1870 GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore",
1871 "zonefile_directory",
1872 &zonefile_directory))
1873 {
1874 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1875 _("No directory to load zonefiles specified in configuration\n"));
1876 GNUNET_SCHEDULER_add_now (&cleanup_task, NULL);
1877 return;
1878 }
1879
1880 if (GNUNET_NO == GNUNET_DISK_file_test (zonefile_directory))
1881 {
1882 if (GNUNET_SYSERR == GNUNET_DISK_directory_create (zonefile_directory))
1883 {
1884 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1885 _("Creating directory `%s' for zone files failed!\n"),
1886 zonefile_directory);
1887 GNUNET_SCHEDULER_add_now (&cleanup_task, NULL);
1888 return;
1889 }
1890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1891 "Created directory `%s' for zone files\n",
1892 zonefile_directory);
1893 }
1894
1895 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1896 "Scanning directory `%s' for zone files\n",
1897 zonefile_directory);
1898 zonekeys = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO);
1899 counter = 0;
1900 GNUNET_DISK_directory_scan (zonefile_directory,
1901 &zonekey_file_it, &counter);
1902 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1903 "Found %u zone files\n",
1904 counter);
1905 1246
1906 /* Loading database plugin */ 1247 /* Loading database plugin */
1907 if (GNUNET_OK != 1248 if (GNUNET_OK !=
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h
index ca712e136..edfb8dcdd 100644
--- a/src/namestore/namestore.h
+++ b/src/namestore/namestore.h
@@ -58,7 +58,7 @@ struct GNUNET_NAMESTORE_Header
58struct LookupBlockMessage 58struct LookupBlockMessage
59{ 59{
60 /** 60 /**
61 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK 61 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK
62 */ 62 */
63 struct GNUNET_NAMESTORE_Header gns_header; 63 struct GNUNET_NAMESTORE_Header gns_header;
64 64
@@ -105,7 +105,7 @@ struct LookupBlockResponseMessage
105struct BlockCacheMessage 105struct BlockCacheMessage
106{ 106{
107 /** 107 /**
108 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE 108 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE
109 */ 109 */
110 struct GNUNET_NAMESTORE_Header gns_header; 110 struct GNUNET_NAMESTORE_Header gns_header;
111 111
@@ -134,12 +134,12 @@ struct BlockCacheMessage
134struct BlockCacheResponseMessage 134struct BlockCacheResponseMessage
135{ 135{
136 /** 136 /**
137 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE_RESPONSE 137 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE_RESPONSE
138 */ 138 */
139 struct GNUNET_NAMESTORE_Header gns_header; 139 struct GNUNET_NAMESTORE_Header gns_header;
140 140
141 /** 141 /**
142 * name length: GNUNET_NO already exists, GNUNET_YES on success, GNUNET_SYSERR error 142 * #GNUNET_OK on success, #GNUNET_SYSERR error
143 */ 143 */
144 int32_t op_result; 144 int32_t op_result;
145}; 145};
@@ -151,7 +151,7 @@ struct BlockCacheResponseMessage
151struct RecordStoreMessage 151struct RecordStoreMessage
152{ 152{
153 /** 153 /**
154 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_RECORD_STORE 154 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_RECORD_STORE
155 */ 155 */
156 struct GNUNET_NAMESTORE_Header gns_header; 156 struct GNUNET_NAMESTORE_Header gns_header;
157 157
@@ -198,14 +198,12 @@ struct RecordStoreMessage
198struct RecordStoreResponseMessage 198struct RecordStoreResponseMessage
199{ 199{
200 /** 200 /**
201 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE 201 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE
202 */ 202 */
203 struct GNUNET_NAMESTORE_Header gns_header; 203 struct GNUNET_NAMESTORE_Header gns_header;
204 204
205 /** 205 /**
206 * result: 206 * #GNUNET_SYSERR on failure, #GNUNET_OK on success
207 * GNUNET_SYSERR on failure
208 * GNUNET_OK on success
209 */ 207 */
210 int32_t op_result; 208 int32_t op_result;
211}; 209};
@@ -218,7 +216,7 @@ struct RecordStoreResponseMessage
218struct ZoneToNameMessage 216struct ZoneToNameMessage
219{ 217{
220 /** 218 /**
221 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME 219 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME
222 */ 220 */
223 struct GNUNET_NAMESTORE_Header gns_header; 221 struct GNUNET_NAMESTORE_Header gns_header;
224 222
@@ -240,7 +238,7 @@ struct ZoneToNameMessage
240struct ZoneToNameResponseMessage 238struct ZoneToNameResponseMessage
241{ 239{
242 /** 240 /**
243 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE 241 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE
244 */ 242 */
245 struct GNUNET_NAMESTORE_Header gns_header; 243 struct GNUNET_NAMESTORE_Header gns_header;
246 244
@@ -260,8 +258,8 @@ struct ZoneToNameResponseMessage
260 uint16_t rd_count; 258 uint16_t rd_count;
261 259
262 /** 260 /**
263 * result in NBO: GNUNET_OK on success, GNUNET_NO if there were no 261 * result in NBO: #GNUNET_OK on success, #GNUNET_NO if there were no
264 * results, GNUNET_SYSERR on error 262 * results, #GNUNET_SYSERR on error
265 */ 263 */
266 int16_t res; 264 int16_t res;
267 265
@@ -284,7 +282,7 @@ struct ZoneToNameResponseMessage
284struct RecordResultMessage 282struct RecordResultMessage
285{ 283{
286 /** 284 /**
287 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT 285 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT
288 */ 286 */
289 struct GNUNET_NAMESTORE_Header gns_header; 287 struct GNUNET_NAMESTORE_Header gns_header;
290 288
@@ -326,7 +324,7 @@ struct RecordResultMessage
326struct ZoneMonitorStartMessage 324struct ZoneMonitorStartMessage
327{ 325{
328 /** 326 /**
329 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START 327 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START
330 */ 328 */
331 struct GNUNET_NAMESTORE_Header gns_header; 329 struct GNUNET_NAMESTORE_Header gns_header;
332 330
@@ -344,7 +342,7 @@ struct ZoneMonitorStartMessage
344struct ZoneIterationStartMessage 342struct ZoneIterationStartMessage
345{ 343{
346 /** 344 /**
347 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START 345 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START
348 */ 346 */
349 struct GNUNET_NAMESTORE_Header gns_header; 347 struct GNUNET_NAMESTORE_Header gns_header;
350 348
@@ -362,7 +360,7 @@ struct ZoneIterationStartMessage
362struct ZoneIterationNextMessage 360struct ZoneIterationNextMessage
363{ 361{
364 /** 362 /**
365 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT 363 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
366 */ 364 */
367 struct GNUNET_NAMESTORE_Header gns_header; 365 struct GNUNET_NAMESTORE_Header gns_header;
368}; 366};
@@ -374,7 +372,7 @@ struct ZoneIterationNextMessage
374struct ZoneIterationStopMessage 372struct ZoneIterationStopMessage
375{ 373{
376 /** 374 /**
377 * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP 375 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP
378 */ 376 */
379 struct GNUNET_NAMESTORE_Header gns_header; 377 struct GNUNET_NAMESTORE_Header gns_header;
380}; 378};
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index acc9b4e37..98148ba1e 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -275,7 +275,9 @@ handle_lookup_block_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
275 block->signature = msg->signature; 275 block->signature = msg->signature;
276 block->derived_key = msg->derived_key; 276 block->derived_key = msg->derived_key;
277 block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); 277 block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN);
278 block->purpose.size = htonl (size - sizeof (struct LookupBlockResponseMessage) + sizeof (struct GNUNET_TIME_AbsoluteNBO)); 278 block->purpose.size = htonl (size - sizeof (struct LookupBlockResponseMessage) +
279 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
280 sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
279 block->expiration_time = msg->expire; 281 block->expiration_time = msg->expire;
280 memcpy (&block[1], 282 memcpy (&block[1],
281 &msg[1], 283 &msg[1],
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c
index 3559dc7ce..7e8ee12a6 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -493,8 +493,7 @@ namestore_sqlite_cache_block (void *cls,
493 * @param query hash of public key derived from the zone and the label 493 * @param query hash of public key derived from the zone and the label
494 * @param iter function to call with the result 494 * @param iter function to call with the result
495 * @param iter_cls closure for iter 495 * @param iter_cls closure for iter
496 * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error 496 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
497 * 'iter' will have been called unless the return value is 'GNUNET_SYSERR'
498 */ 497 */
499static int 498static int
500namestore_sqlite_lookup_block (void *cls, 499namestore_sqlite_lookup_block (void *cls,
@@ -523,7 +522,6 @@ namestore_sqlite_lookup_block (void *cls,
523 ret = GNUNET_NO; 522 ret = GNUNET_NO;
524 if (SQLITE_ROW == (sret = sqlite3_step (plugin->lookup_block))) 523 if (SQLITE_ROW == (sret = sqlite3_step (plugin->lookup_block)))
525 { 524 {
526 ret = GNUNET_YES;
527 block = sqlite3_column_blob (plugin->lookup_block, 0); 525 block = sqlite3_column_blob (plugin->lookup_block, 0);
528 block_size = sqlite3_column_bytes (plugin->lookup_block, 0); 526 block_size = sqlite3_column_bytes (plugin->lookup_block, 0);
529 if ( (block_size < sizeof (struct GNUNET_NAMESTORE_Block)) || 527 if ( (block_size < sizeof (struct GNUNET_NAMESTORE_Block)) ||
@@ -537,13 +535,16 @@ namestore_sqlite_lookup_block (void *cls,
537 else 535 else
538 { 536 {
539 iter (iter_cls, block); 537 iter (iter_cls, block);
538 ret = GNUNET_YES;
540 } 539 }
541 } 540 }
542 else 541 else
543 { 542 {
544 if (SQLITE_DONE != sret) 543 if (SQLITE_DONE != sret)
545 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step"); 544 {
546 iter (iter_cls, NULL); 545 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step");
546 ret = GNUNET_SYSERR;
547 }
547 } 548 }
548 if (SQLITE_OK != sqlite3_reset (plugin->lookup_block)) 549 if (SQLITE_OK != sqlite3_reset (plugin->lookup_block))
549 LOG_SQLITE (plugin, 550 LOG_SQLITE (plugin,
@@ -562,7 +563,7 @@ namestore_sqlite_lookup_block (void *cls,
562 * @param label name that is being mapped (at most 255 characters long) 563 * @param label name that is being mapped (at most 255 characters long)
563 * @param rd_count number of entries in 'rd' array 564 * @param rd_count number of entries in 'rd' array
564 * @param rd array of records with data to store 565 * @param rd array of records with data to store
565 * @return GNUNET_OK on success, else GNUNET_SYSERR 566 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
566 */ 567 */
567static int 568static int
568namestore_sqlite_store_records (void *cls, 569namestore_sqlite_store_records (void *cls,
@@ -677,8 +678,8 @@ namestore_sqlite_store_records (void *cls,
677 * @param stmt to run (and then clean up) 678 * @param stmt to run (and then clean up)
678 * @param zone_key private key of the zone 679 * @param zone_key private key of the zone
679 * @param iter iterator to call with the result 680 * @param iter iterator to call with the result
680 * @param iter_cls closure for 'iter' 681 * @param iter_cls closure for @a iter
681 * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error 682 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
682 */ 683 */
683static int 684static int
684get_record_and_call_iterator (struct Plugin *plugin, 685get_record_and_call_iterator (struct Plugin *plugin,
@@ -724,6 +725,7 @@ get_record_and_call_iterator (struct Plugin *plugin,
724 { 725 {
725 iter (iter_cls, zone_key, label, 726 iter (iter_cls, zone_key, label,
726 record_count, rd); 727 record_count, rd);
728 ret = GNUNET_YES;
727 } 729 }
728 } 730 }
729 } 731 }
@@ -731,7 +733,6 @@ get_record_and_call_iterator (struct Plugin *plugin,
731 { 733 {
732 if (SQLITE_DONE != sret) 734 if (SQLITE_DONE != sret)
733 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step"); 735 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step");
734 iter (iter_cls, NULL, NULL, 0, NULL);
735 } 736 }
736 if (SQLITE_OK != sqlite3_reset (stmt)) 737 if (SQLITE_OK != sqlite3_reset (stmt))
737 LOG_SQLITE (plugin, 738 LOG_SQLITE (plugin,
@@ -749,8 +750,8 @@ get_record_and_call_iterator (struct Plugin *plugin,
749 * @param zone hash of public key of the zone, NULL to iterate over all zones 750 * @param zone hash of public key of the zone, NULL to iterate over all zones
750 * @param offset offset in the list of all matching records 751 * @param offset offset in the list of all matching records
751 * @param iter function to call with the result 752 * @param iter function to call with the result
752 * @param iter_cls closure for iter 753 * @param iter_cls closure for @a iter
753 * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error 754 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
754 */ 755 */
755static int 756static int
756namestore_sqlite_iterate_records (void *cls, 757namestore_sqlite_iterate_records (void *cls,
@@ -789,8 +790,8 @@ namestore_sqlite_iterate_records (void *cls,
789 * @param zone private key of the zone to look up in, never NULL 790 * @param zone private key of the zone to look up in, never NULL
790 * @param value_zone public key of the target zone (value), never NULL 791 * @param value_zone public key of the target zone (value), never NULL
791 * @param iter function to call with the result 792 * @param iter function to call with the result
792 * @param iter_cls closure for iter 793 * @param iter_cls closure for @a iter
793 * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error 794 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
794 */ 795 */
795static int 796static int
796namestore_sqlite_zone_to_name (void *cls, 797namestore_sqlite_zone_to_name (void *cls,
@@ -825,7 +826,7 @@ namestore_sqlite_zone_to_name (void *cls,
825 * Entry point for the plugin. 826 * Entry point for the plugin.
826 * 827 *
827 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*" 828 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
828 * @return NULL on error, othrewise the plugin context 829 * @return NULL on error, otherwise the plugin context
829 */ 830 */
830void * 831void *
831libgnunet_plugin_namestore_sqlite_init (void *cls) 832libgnunet_plugin_namestore_sqlite_init (void *cls)
@@ -868,8 +869,6 @@ libgnunet_plugin_namestore_sqlite_done (void *cls)
868 struct GNUNET_NAMESTORE_PluginFunctions *api = cls; 869 struct GNUNET_NAMESTORE_PluginFunctions *api = cls;
869 struct Plugin *plugin = api->cls; 870 struct Plugin *plugin = api->cls;
870 871
871 LOG (GNUNET_ERROR_TYPE_DEBUG,
872 "sqlite plugin is done\n");
873 database_shutdown (plugin); 872 database_shutdown (plugin);
874 plugin->cfg = NULL; 873 plugin->cfg = NULL;
875 GNUNET_free (api); 874 GNUNET_free (api);