2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013, 2014, 2018 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file namestore/gnunet-service-namestore.c
23 * @brief namestore for the GNUnet naming system
24 * @author Matthias Wachs
25 * @author Christian Grothoff
28 * - run testcases, make sure everything works!
31 #include "gnunet_util_lib.h"
32 #include "gnunet_dnsparser_lib.h"
33 #include "gnunet_gns_service.h"
34 #include "gnunet_namecache_service.h"
35 #include "gnunet_namestore_service.h"
36 #include "gnunet_namestore_plugin.h"
37 #include "gnunet_statistics_service.h"
38 #include "gnunet_signatures.h"
39 #include "namestore.h"
41 #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
47 struct NamestoreClient;
51 * A namestore iteration operation.
56 * Next element in the DLL
58 struct ZoneIteration *next;
61 * Previous element in the DLL
63 struct ZoneIteration *prev;
66 * Namestore client which intiated this zone iteration
68 struct NamestoreClient *nc;
71 * The nick to add to the records
73 struct GNUNET_GNSRECORD_Data *nick;
76 * Key of the zone we are iterating over.
78 struct GNUNET_CRYPTO_EcdsaPrivateKey zone;
81 * Last sequence number in the zone iteration used to address next
82 * result of the zone iteration in the store
85 * Updated in #zone_iterate_proc()
90 * The operation id fot the zone iteration in the response for the client
95 * Offset of the zone iteration used to address next result of the zone
96 * iteration in the store
98 * Initialy set to 0 in #handle_iteration_start
99 * Incremented with by every call to #handle_iteration_next
109 struct NamestoreClient
115 struct GNUNET_SERVICE_Client *client;
118 * Message queue for transmission to @e client
120 struct GNUNET_MQ_Handle *mq;
124 * Zone iteration operations in progress initiated by this client
126 struct ZoneIteration *op_head;
130 * Zone iteration operations in progress initiated by this client
132 struct ZoneIteration *op_tail;
137 * A namestore monitor.
142 * Next element in the DLL
144 struct ZoneMonitor *next;
147 * Previous element in the DLL
149 struct ZoneMonitor *prev;
152 * Namestore client which intiated this zone monitor
154 struct NamestoreClient *nc;
157 * Private key of the zone.
159 struct GNUNET_CRYPTO_EcdsaPrivateKey zone;
162 * Task active during initial iteration.
164 struct GNUNET_SCHEDULER_Task *task;
167 * Last sequence number in the zone iteration used to address next
168 * result of the zone iteration in the store
171 * Updated in #monitor_iterate_cb()
176 * Current limit of how many more messages we are allowed
177 * to queue to this monitor.
182 * How many more requests may we receive from the iterator
183 * before it is at the limit we gave it? Will be below or
184 * equal to @e limit. The effective limit for monitor
185 * events is thus @e iteration_cnt - @e limit!
187 uint64_t iteration_cnt;
190 * Are we (still) in the initial iteration pass?
192 int in_first_iteration;
195 * Is there a store activity waiting for this monitor? We only raise the
196 * flag when it happens and search the DLL for the store activity when we
197 * had a limit increase. If we cannot find any waiting store activity at
198 * that time, we clear the flag again.
206 * Pending operation on the namecache.
208 struct CacheOperation
214 struct CacheOperation *prev;
219 struct CacheOperation *next;
222 * Handle to namecache queue.
224 struct GNUNET_NAMECACHE_QueueEntry *qe;
227 * Client to notify about the result.
229 struct NamestoreClient *nc;
232 * Client's request ID.
239 * Information for an ongoing #handle_record_store() operation.
240 * Needed as we may wait for monitors to be ready for the notification.
247 struct StoreActivity *next;
252 struct StoreActivity *prev;
255 * Which client triggered the store activity?
257 struct NamestoreClient *nc;
260 * Copy of the original store message (as data fields in @e rd will
263 const struct RecordStoreMessage *rsm;
266 * Array of record data to store (without NICK unless this is about
267 * #GNUNET_GNS_EMPTY_LABEL_AT). Length is in @e rd_count.
269 struct GNUNET_GNSRECORD_Data *rd;
272 * Next zone monitor that still needs to be notified about this PUT.
274 struct ZoneMonitor *zm_pos;
277 * Label nicely canonicalized (lower case).
282 * How many records do we try to store?
284 unsigned int rd_count;
290 * Public key of all zeros.
292 static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero;
295 * Configuration handle.
297 static const struct GNUNET_CONFIGURATION_Handle *GSN_cfg;
300 * Handle to the statistics service
302 static struct GNUNET_STATISTICS_Handle *statistics;
307 static struct GNUNET_NAMECACHE_Handle *namecache;
312 static struct GNUNET_NAMESTORE_PluginFunctions *GSN_database;
315 * Name of the database plugin
317 static char *db_lib_name;
322 static struct CacheOperation *cop_head;
327 static struct CacheOperation *cop_tail;
330 * First active zone monitor.
332 static struct ZoneMonitor *monitor_head;
335 * Last active zone monitor.
337 static struct ZoneMonitor *monitor_tail;
340 * Head of DLL of monitor-blocked store activities.
342 static struct StoreActivity *sa_head;
345 * Tail of DLL of monitor-blocked store activities.
347 static struct StoreActivity *sa_tail;
350 * Notification context shared by all monitors.
352 static struct GNUNET_NotificationContext *monitor_nc;
355 * Optimize block insertion by caching map of private keys to
356 * public keys in memory?
358 static int cache_keys;
361 * Use the namecache? Doing so creates additional cryptographic
362 * operations whenever we touch a record.
364 static int disable_namecache;
368 * Task run during shutdown.
373 cleanup_task (void *cls)
375 struct CacheOperation *cop;
378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
379 "Stopping namestore service\n");
380 while (NULL != (cop = cop_head))
382 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
383 "Aborting incomplete namecache operation\n");
384 GNUNET_NAMECACHE_cancel (cop->qe);
385 GNUNET_CONTAINER_DLL_remove (cop_head,
390 if (NULL != namecache)
392 GNUNET_NAMECACHE_disconnect (namecache);
395 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name,
397 GNUNET_free (db_lib_name);
399 if (NULL != monitor_nc)
401 GNUNET_notification_context_destroy (monitor_nc);
404 if (NULL != statistics)
406 GNUNET_STATISTICS_destroy (statistics,
414 * Release memory used by @a sa.
416 * @param sa activity to free
419 free_store_activity (struct StoreActivity *sa)
421 GNUNET_CONTAINER_DLL_remove (sa_head,
424 GNUNET_array_grow (sa->rd,
427 GNUNET_free (sa->conv_name);
433 * Function called with the records for the #GNUNET_GNS_EMPTY_LABEL_AT
434 * label in the zone. Used to locate the #GNUNET_GNSRECORD_TYPE_NICK
435 * record, which (if found) is then copied to @a cls for future use.
437 * @param cls a `struct GNUNET_GNSRECORD_Data **` for storing the nick (if found)
438 * @param seq sequence number of the record
439 * @param private_key the private key of the zone (unused)
440 * @param label should be #GNUNET_GNS_EMPTY_LABEL_AT
441 * @param rd_count number of records in @a rd
442 * @param rd records stored under @a label in the zone
445 lookup_nick_it (void *cls,
447 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
449 unsigned int rd_count,
450 const struct GNUNET_GNSRECORD_Data *rd)
452 struct GNUNET_GNSRECORD_Data **res = cls;
456 if (0 != strcmp (label, GNUNET_GNS_EMPTY_LABEL_AT))
461 for (unsigned int c = 0; c < rd_count; c++)
463 if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type)
465 (*res) = GNUNET_malloc (rd[c].data_size + sizeof (struct GNUNET_GNSRECORD_Data));
466 (*res)->data = &(*res)[1];
467 GNUNET_memcpy ((void *) (*res)->data,
470 (*res)->data_size = rd[c].data_size;
471 (*res)->expiration_time = rd[c].expiration_time;
472 (*res)->flags = rd[c].flags;
473 (*res)->record_type = GNUNET_GNSRECORD_TYPE_NICK;
482 * Return the NICK record for the zone (if it exists).
484 * @param zone private key for the zone to look for nick
485 * @return NULL if no NICK record was found
487 static struct GNUNET_GNSRECORD_Data *
488 get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone)
490 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
491 struct GNUNET_GNSRECORD_Data *nick;
495 res = GSN_database->lookup_records (GSN_database->cls,
497 GNUNET_GNS_EMPTY_LABEL_AT,
500 if ( (GNUNET_OK != res) ||
503 GNUNET_CRYPTO_ecdsa_key_get_public (zone, &pub);
504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
505 "No nick name set for zone `%s'\n",
506 GNUNET_GNSRECORD_z2s (&pub));
514 * Merge the nick record @a nick_rd with the rest of the
515 * record set given in @a rd2. Store the result in @a rdc_res
516 * and @a rd_res. The @a nick_rd's expiration time is set to
517 * the maximum expiration time of all of the records in @a rd2.
519 * @param nick_rd the nick record to integrate
520 * @param rd2_length length of the @a rd2 array
521 * @param rd2 array of records
522 * @param rdc_res[out] length of the resulting @a rd_res array
523 * @param rd_res[out] set to an array of records,
524 * including @a nick_rd and @a rd2;
525 * all of the variable-size 'data' fields in @a rd2 are
526 * allocated in the same chunk of memory!
529 merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd,
530 unsigned int rd2_length,
531 const struct GNUNET_GNSRECORD_Data *rd2,
532 unsigned int *rdc_res,
533 struct GNUNET_GNSRECORD_Data **rd_res)
535 uint64_t latest_expiration;
541 (*rdc_res) = 1 + rd2_length;
542 if (0 == 1 + rd2_length)
548 for (unsigned int c=0; c< 1; c++)
549 req += sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd[c].data_size;
550 for (unsigned int c=0; c< rd2_length; c++)
551 req += sizeof (struct GNUNET_GNSRECORD_Data) + rd2[c].data_size;
552 (*rd_res) = GNUNET_malloc (req);
553 data = (char *) &(*rd_res)[1 + rd2_length];
555 latest_expiration = 0;
556 for (unsigned int c=0; c< rd2_length; c++)
558 if (0 != (rd2[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
560 if ((GNUNET_TIME_absolute_get().abs_value_us + rd2[c].expiration_time) >
562 latest_expiration = rd2[c].expiration_time;
564 else if (rd2[c].expiration_time > latest_expiration)
565 latest_expiration = rd2[c].expiration_time;
566 (*rd_res)[c] = rd2[c];
567 (*rd_res)[c].data = (void *) &data[data_offset];
568 GNUNET_memcpy ((void *) (*rd_res)[c].data,
571 data_offset += (*rd_res)[c].data_size;
574 record_offset = rd2_length;
575 (*rd_res)[record_offset] = *nick_rd;
576 (*rd_res)[record_offset].expiration_time = latest_expiration;
577 (*rd_res)[record_offset].data = (void *) &data[data_offset];
578 GNUNET_memcpy ((void *) (*rd_res)[record_offset].data,
581 data_offset += (*rd_res)[record_offset].data_size;
582 GNUNET_assert (req == (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset);
587 * Generate a `struct LookupNameResponseMessage` and send it to the
588 * given client using the given notification context.
590 * @param nc client to unicast to
591 * @param request_id request ID to use
592 * @param zone_key zone key of the zone
594 * @param rd_count number of records in @a rd
595 * @param rd array of records
598 send_lookup_response (struct NamestoreClient *nc,
600 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
602 unsigned int rd_count,
603 const struct GNUNET_GNSRECORD_Data *rd)
605 struct GNUNET_MQ_Envelope *env;
606 struct RecordResultMessage *zir_msg;
607 struct GNUNET_GNSRECORD_Data *nick;
608 struct GNUNET_GNSRECORD_Data *res;
609 unsigned int res_count;
615 nick = get_nick_record (zone_key);
616 if ( (NULL != nick) &&
618 GNUNET_GNS_EMPTY_LABEL_AT)))
620 nick->flags = (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE;
621 merge_with_nick_records (nick,
630 res_count = rd_count;
631 res = (struct GNUNET_GNSRECORD_Data *) rd;
634 name_len = strlen (name) + 1;
635 rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res);
636 env = GNUNET_MQ_msg_extra (zir_msg,
637 name_len + rd_ser_len,
638 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT);
639 zir_msg->gns_header.r_id = htonl (request_id);
640 zir_msg->name_len = htons (name_len);
641 zir_msg->rd_count = htons (res_count);
642 zir_msg->rd_len = htons (rd_ser_len);
643 zir_msg->private_key = *zone_key;
644 name_tmp = (char *) &zir_msg[1];
645 GNUNET_memcpy (name_tmp,
648 rd_ser = &name_tmp[name_len];
649 GNUNET_GNSRECORD_records_serialize (res_count,
653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
654 "Sending RECORD_RESULT message with %u records\n",
656 GNUNET_STATISTICS_update (statistics,
657 "Record sets sent to clients",
660 GNUNET_MQ_send (nc->mq,
668 * Send response to the store request to the client.
670 * @param client client to talk to
671 * @param res status of the operation
672 * @param rid client's request ID
675 send_store_response (struct NamestoreClient *nc,
679 struct GNUNET_MQ_Envelope *env;
680 struct RecordStoreResponseMessage *rcr_msg;
682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
683 "Sending RECORD_STORE_RESPONSE message\n");
684 GNUNET_STATISTICS_update (statistics,
685 "Store requests completed",
688 env = GNUNET_MQ_msg (rcr_msg,
689 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE);
690 rcr_msg->gns_header.r_id = htonl (rid);
691 rcr_msg->op_result = htonl (res);
692 GNUNET_MQ_send (nc->mq,
698 * Cache operation complete, clean up.
700 * @param cls the `struct CacheOperation`
701 * @param success success
702 * @param emsg error messages
705 finish_cache_operation (void *cls,
709 struct CacheOperation *cop = cls;
712 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
713 _("Failed to replicate block in namecache: %s\n"),
716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
717 "CACHE operation completed\n");
718 GNUNET_CONTAINER_DLL_remove (cop_head,
722 send_store_response (cop->nc,
730 * We just touched the plaintext information about a name in our zone;
731 * refresh the corresponding (encrypted) block in the namecache.
733 * @param nc client responsible for the request, can be NULL
734 * @param rid request ID of the client
735 * @param zone_key private key of the zone
736 * @param name label for the records
737 * @param rd_count number of records
738 * @param rd records stored under the given @a name
741 refresh_block (struct NamestoreClient *nc,
743 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
745 unsigned int rd_count,
746 const struct GNUNET_GNSRECORD_Data *rd)
748 struct GNUNET_GNSRECORD_Block *block;
749 struct CacheOperation *cop;
750 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
751 struct GNUNET_GNSRECORD_Data *nick;
752 struct GNUNET_GNSRECORD_Data *res;
753 unsigned int res_count;
754 struct GNUNET_TIME_Absolute exp_time;
756 nick = get_nick_record (zone_key);
757 res_count = rd_count;
758 res = (struct GNUNET_GNSRECORD_Data *) rd; /* fixme: a bit unclean... */
761 nick->flags = (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE;
762 merge_with_nick_records (nick,
770 send_store_response (nc,
773 return; /* no data, no need to update cache */
775 if (GNUNET_YES == disable_namecache)
777 GNUNET_STATISTICS_update (statistics,
778 "Namecache updates skipped (NC disabled)",
781 send_store_response (nc,
786 exp_time = GNUNET_GNSRECORD_record_get_expiration_time (res_count,
789 block = GNUNET_GNSRECORD_block_create2 (zone_key,
795 block = GNUNET_GNSRECORD_block_create (zone_key,
800 GNUNET_assert (NULL != block);
801 GNUNET_CRYPTO_ecdsa_key_get_public (zone_key,
803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
804 "Caching block for label `%s' with %u records and expiration %s in zone `%s' in namecache\n",
807 GNUNET_STRINGS_absolute_time_to_string (exp_time),
808 GNUNET_GNSRECORD_z2s (&pkey));
809 GNUNET_STATISTICS_update (statistics,
810 "Namecache updates pushed",
813 cop = GNUNET_new (struct CacheOperation);
816 GNUNET_CONTAINER_DLL_insert (cop_head,
819 cop->qe = GNUNET_NAMECACHE_block_cache (namecache,
821 &finish_cache_operation,
828 * Continue processing the @a sa.
830 * @param sa store activity to process
833 continue_store_activity (struct StoreActivity *sa)
835 const struct RecordStoreMessage *rp_msg = sa->rsm;
837 for (struct ZoneMonitor *zm = sa->zm_pos;
841 if ( (0 != memcmp (&rp_msg->private_key,
843 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) &&
844 (0 != memcmp (&zm->zone,
846 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
847 sa->zm_pos = zm->next; /* not interesting to this monitor */
848 if (zm->limit == zm->iteration_cnt)
850 zm->sa_waiting = GNUNET_YES;
851 return; /* blocked on zone monitor */
853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
854 "Notifying monitor about changes under label `%s'\n",
857 send_lookup_response (zm->nc,
859 &rp_msg->private_key,
863 sa->zm_pos = zm->next;
865 /* great, done with the monitors, unpack (again) for refresh_block operation */
870 const char *name_tmp;
872 unsigned int rd_count;
874 rid = ntohl (rp_msg->gns_header.r_id);
875 name_len = ntohs (rp_msg->name_len);
876 rd_count = ntohs (rp_msg->rd_count);
877 rd_ser_len = ntohs (rp_msg->rd_len);
878 name_tmp = (const char *) &rp_msg[1];
879 rd_ser = &name_tmp[name_len];
881 struct GNUNET_GNSRECORD_Data rd[rd_count];
883 /* We did this before, must succeed again */
884 GNUNET_assert (GNUNET_OK ==
885 GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
889 refresh_block (sa->nc,
891 &rp_msg->private_key,
897 GNUNET_SERVICE_client_continue (sa->nc->client);
898 free_store_activity (sa);
903 * Called whenever a client is disconnected.
904 * Frees our resources associated with that client.
907 * @param client identification of the client
908 * @param app_ctx the `struct NamestoreClient` of @a client
911 client_disconnect_cb (void *cls,
912 struct GNUNET_SERVICE_Client *client,
915 struct NamestoreClient *nc = app_ctx;
916 struct ZoneIteration *no;
917 struct CacheOperation *cop;
920 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
921 "Client %p disconnected\n",
923 for (struct ZoneMonitor *zm = monitor_head; NULL != zm; zm = zm->next)
925 struct StoreActivity *san;
929 GNUNET_CONTAINER_DLL_remove (monitor_head,
932 if (NULL != zm->task)
934 GNUNET_SCHEDULER_cancel (zm->task);
937 for (struct StoreActivity *sa = sa_head; NULL != sa; sa = san)
940 if (zm == sa->zm_pos)
942 sa->zm_pos = zm->next;
943 /* this may free sa */
944 continue_store_activity (sa);
950 for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next)
954 /* this may free sa */
955 free_store_activity (sa);
956 break; /* there can only be one per nc */
959 while (NULL != (no = nc->op_head))
961 GNUNET_CONTAINER_DLL_remove (nc->op_head,
966 for (cop = cop_head; NULL != cop; cop = cop->next)
974 * Add a client to our list of active clients.
977 * @param client client to add
978 * @param mq message queue for @a client
979 * @return internal namestore client structure for this client
982 client_connect_cb (void *cls,
983 struct GNUNET_SERVICE_Client *client,
984 struct GNUNET_MQ_Handle *mq)
986 struct NamestoreClient *nc;
989 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
990 "Client %p connected\n",
992 nc = GNUNET_new (struct NamestoreClient);
1000 * Closure for #lookup_it().
1002 struct RecordLookupContext
1018 struct GNUNET_GNSRECORD_Data *nick;
1028 unsigned int res_rd_count;
1039 * @param seq sequence number of the record
1042 lookup_it (void *cls,
1044 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
1046 unsigned int rd_count,
1047 const struct GNUNET_GNSRECORD_Data *rd)
1049 struct RecordLookupContext *rlc = cls;
1050 struct GNUNET_GNSRECORD_Data *rd_res;
1051 unsigned int rdc_res;
1055 if (0 == strcmp (label,
1058 rlc->found = GNUNET_YES;
1061 if ( (NULL != rlc->nick) &&
1062 (0 != strcmp (label,
1063 GNUNET_GNS_EMPTY_LABEL_AT)) )
1068 rlc->nick->flags = (rlc->nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE;
1069 merge_with_nick_records (rlc->nick,
1074 rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res,
1076 rlc->res_rd_count = rdc_res;
1077 rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len);
1078 GNUNET_GNSRECORD_records_serialize (rdc_res,
1083 GNUNET_free (rd_res);
1084 GNUNET_free (rlc->nick);
1089 rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count,
1091 rlc->res_rd_count = rd_count;
1092 rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len);
1093 GNUNET_GNSRECORD_records_serialize (rd_count,
1101 rlc->rd_ser_len = 0;
1102 rlc->res_rd_count = 0;
1110 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message
1112 * @param cls client sending the message
1113 * @param ll_msg message of type `struct LabelLookupMessage`
1114 * @return #GNUNET_OK if @a ll_msg is well-formed
1117 check_record_lookup (void *cls,
1118 const struct LabelLookupMessage *ll_msg)
1122 const char *name_tmp;
1125 name_len = ntohl (ll_msg->label_len);
1126 src_size = ntohs (ll_msg->gns_header.header.size);
1127 if (name_len != src_size - sizeof (struct LabelLookupMessage))
1130 return GNUNET_SYSERR;
1133 name_tmp = (const char *) &ll_msg[1];
1134 if ('\0' != name_tmp[name_len -1])
1137 return GNUNET_SYSERR;
1144 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message
1146 * @param cls client sending the message
1147 * @param ll_msg message of type `struct LabelLookupMessage`
1150 handle_record_lookup (void *cls,
1151 const struct LabelLookupMessage *ll_msg)
1153 struct NamestoreClient *nc = cls;
1154 struct GNUNET_MQ_Envelope *env;
1155 struct LabelLookupResponseMessage *llr_msg;
1156 struct RecordLookupContext rlc;
1157 const char *name_tmp;
1163 name_len = ntohl (ll_msg->label_len);
1164 name_tmp = (const char *) &ll_msg[1];
1165 GNUNET_SERVICE_client_continue (nc->client);
1166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1167 "Received NAMESTORE_RECORD_LOOKUP message for name `%s'\n",
1170 conv_name = GNUNET_GNSRECORD_string_to_lowercase (name_tmp);
1171 if (NULL == conv_name)
1173 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1174 "Error converting name `%s'\n",
1176 GNUNET_SERVICE_client_drop (nc->client);
1179 rlc.label = conv_name;
1180 rlc.found = GNUNET_NO;
1181 rlc.res_rd_count = 0;
1184 rlc.nick = get_nick_record (&ll_msg->zone);
1185 res = GSN_database->lookup_records (GSN_database->cls,
1190 GNUNET_free (conv_name);
1191 env = GNUNET_MQ_msg_extra (llr_msg,
1192 name_len + rlc.rd_ser_len,
1193 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE);
1194 llr_msg->gns_header.r_id = ll_msg->gns_header.r_id;
1195 llr_msg->private_key = ll_msg->zone;
1196 llr_msg->name_len = htons (name_len);
1197 llr_msg->rd_count = htons (rlc.res_rd_count);
1198 llr_msg->rd_len = htons (rlc.rd_ser_len);
1199 res_name = (char *) &llr_msg[1];
1200 if ((GNUNET_YES == rlc.found) && (GNUNET_OK == res))
1201 llr_msg->found = ntohs (GNUNET_YES);
1203 llr_msg->found = ntohs (GNUNET_NO);
1204 GNUNET_memcpy (&llr_msg[1],
1207 GNUNET_memcpy (&res_name[name_len],
1210 GNUNET_MQ_send (nc->mq,
1212 GNUNET_free_non_null (rlc.res_rd);
1217 * Checks a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message
1219 * @param cls client sending the message
1220 * @param rp_msg message of type `struct RecordStoreMessage`
1221 * @return #GNUNET_OK if @a rp_msg is well-formed
1224 check_record_store (void *cls,
1225 const struct RecordStoreMessage *rp_msg)
1229 size_t msg_size_exp;
1231 const char *name_tmp;
1234 name_len = ntohs (rp_msg->name_len);
1235 msg_size = ntohs (rp_msg->gns_header.header.size);
1236 rd_ser_len = ntohs (rp_msg->rd_len);
1237 msg_size_exp = sizeof (struct RecordStoreMessage) + name_len + rd_ser_len;
1238 if (msg_size != msg_size_exp)
1241 return GNUNET_SYSERR;
1243 if ( (0 == name_len) ||
1244 (name_len > MAX_NAME_LEN) )
1247 return GNUNET_SYSERR;
1249 name_tmp = (const char *) &rp_msg[1];
1250 if ('\0' != name_tmp[name_len -1])
1253 return GNUNET_SYSERR;
1260 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message
1262 * @param cls client sending the message
1263 * @param rp_msg message of type `struct RecordStoreMessage`
1266 handle_record_store (void *cls,
1267 const struct RecordStoreMessage *rp_msg)
1269 struct NamestoreClient *nc = cls;
1273 const char *name_tmp;
1276 unsigned int rd_count;
1278 struct StoreActivity *sa;
1280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1281 "Received NAMESTORE_RECORD_STORE message\n");
1282 rid = ntohl (rp_msg->gns_header.r_id);
1283 name_len = ntohs (rp_msg->name_len);
1284 rd_count = ntohs (rp_msg->rd_count);
1285 rd_ser_len = ntohs (rp_msg->rd_len);
1286 GNUNET_break (0 == ntohs (rp_msg->reserved));
1287 name_tmp = (const char *) &rp_msg[1];
1288 rd_ser = &name_tmp[name_len];
1290 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
1291 struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)];
1292 unsigned int rd_clean_off;
1295 GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
1301 GNUNET_SERVICE_client_drop (nc->client);
1305 /* Extracting and converting private key */
1306 conv_name = GNUNET_GNSRECORD_string_to_lowercase (name_tmp);
1307 if (NULL == conv_name)
1309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1310 "Error converting name `%s'\n",
1312 GNUNET_SERVICE_client_drop (nc->client);
1315 GNUNET_STATISTICS_update (statistics,
1316 "Well-formed store requests received",
1319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1320 "Creating %u records for name `%s'\n",
1321 (unsigned int) rd_count,
1323 if ( (0 == rd_count) &&
1325 GSN_database->lookup_records (GSN_database->cls,
1326 &rp_msg->private_key,
1331 /* This name does not exist, so cannot be removed */
1332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1333 "Name `%s' does not exist, no deletion required\n",
1339 /* remove "NICK" records, unless this is for the
1340 #GNUNET_GNS_EMPTY_LABEL_AT label */
1342 for (unsigned int i=0;i<rd_count;i++)
1344 rd_clean[rd_clean_off] = rd[i];
1345 if ( (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT,
1347 (GNUNET_GNSRECORD_TYPE_NICK != rd[i].record_type) )
1350 res = GSN_database->store_records (GSN_database->cls,
1351 &rp_msg->private_key,
1357 if (GNUNET_OK != res)
1359 /* store not successful, not need to tell monitors */
1360 send_store_response (nc,
1363 GNUNET_SERVICE_client_continue (nc->client);
1364 GNUNET_free (conv_name);
1368 sa = GNUNET_malloc (sizeof (struct StoreActivity) +
1369 ntohs (rp_msg->gns_header.header.size));
1370 GNUNET_CONTAINER_DLL_insert (sa_head,
1374 sa->rsm = (const struct RecordStoreMessage *) &sa[1];
1377 ntohs (rp_msg->gns_header.header.size));
1378 sa->zm_pos = monitor_head;
1379 sa->conv_name = conv_name;
1380 GNUNET_array_grow (sa->rd,
1385 sizeof (struct GNUNET_GNSRECORD_Data) * rd_clean_off);
1386 continue_store_activity (sa);
1392 * Context for record remove operations passed from #handle_zone_to_name to
1393 * #handle_zone_to_name_it as closure
1395 struct ZoneToNameCtx
1400 struct NamestoreClient *nc;
1403 * Request id (to be used in the response to the client).
1408 * Set to #GNUNET_OK on success, #GNUNET_SYSERR on error. Note that
1409 * not finding a name for the zone still counts as a 'success' here,
1410 * as this field is about the success of executing the IPC protocol.
1417 * Zone to name iterator
1419 * @param cls struct ZoneToNameCtx *
1420 * @param seq sequence number of the record
1421 * @param zone_key the zone key
1423 * @param rd_count number of records in @a rd
1424 * @param rd record data
1427 handle_zone_to_name_it (void *cls,
1429 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
1431 unsigned int rd_count,
1432 const struct GNUNET_GNSRECORD_Data *rd)
1434 struct ZoneToNameCtx *ztn_ctx = cls;
1435 struct GNUNET_MQ_Envelope *env;
1436 struct ZoneToNameResponseMessage *ztnr_msg;
1445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1446 "Found result for zone-to-name lookup: `%s'\n",
1449 name_len = (NULL == name) ? 0 : strlen (name) + 1;
1450 rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd);
1451 msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len;
1452 if (msg_size >= GNUNET_MAX_MESSAGE_SIZE)
1455 ztn_ctx->success = GNUNET_SYSERR;
1458 env = GNUNET_MQ_msg_extra (ztnr_msg,
1459 name_len + rd_ser_len,
1460 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE);
1461 ztnr_msg->gns_header.header.size = htons (msg_size);
1462 ztnr_msg->gns_header.r_id = htonl (ztn_ctx->rid);
1463 ztnr_msg->res = htons (res);
1464 ztnr_msg->rd_len = htons (rd_ser_len);
1465 ztnr_msg->rd_count = htons (rd_count);
1466 ztnr_msg->name_len = htons (name_len);
1467 ztnr_msg->zone = *zone_key;
1468 name_tmp = (char *) &ztnr_msg[1];
1469 GNUNET_memcpy (name_tmp,
1472 rd_tmp = &name_tmp[name_len];
1473 GNUNET_GNSRECORD_records_serialize (rd_count,
1477 ztn_ctx->success = GNUNET_OK;
1478 GNUNET_MQ_send (ztn_ctx->nc->mq,
1484 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME message
1486 * @param cls client client sending the message
1487 * @param ztn_msg message of type 'struct ZoneToNameMessage'
1490 handle_zone_to_name (void *cls,
1491 const struct ZoneToNameMessage *ztn_msg)
1493 struct NamestoreClient *nc = cls;
1494 struct ZoneToNameCtx ztn_ctx;
1495 struct GNUNET_MQ_Envelope *env;
1496 struct ZoneToNameResponseMessage *ztnr_msg;
1498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1499 "Received ZONE_TO_NAME message\n");
1500 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id);
1502 ztn_ctx.success = GNUNET_NO;
1503 if (GNUNET_SYSERR ==
1504 GSN_database->zone_to_name (GSN_database->cls,
1506 &ztn_msg->value_zone,
1507 &handle_zone_to_name_it, &ztn_ctx))
1509 /* internal error, hang up instead of signalling something
1510 that might be wrong */
1512 GNUNET_SERVICE_client_drop (nc->client);
1515 if (GNUNET_NO == ztn_ctx.success)
1517 /* no result found, send empty response */
1518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1519 "Found no result for zone-to-name lookup.\n");
1520 env = GNUNET_MQ_msg (ztnr_msg,
1521 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE);
1522 ztnr_msg->gns_header.r_id = ztn_msg->gns_header.r_id;
1523 ztnr_msg->res = htons (GNUNET_NO);
1524 GNUNET_MQ_send (nc->mq,
1527 GNUNET_SERVICE_client_continue (nc->client);
1532 * Context for record remove operations passed from
1533 * #run_zone_iteration_round to #zone_iterate_proc as closure
1535 struct ZoneIterationProcResult
1538 * The zone iteration handle
1540 struct ZoneIteration *zi;
1543 * Number of results left to be returned in this iteration.
1551 * Process results for zone iteration from database
1553 * @param cls struct ZoneIterationProcResult
1554 * @param seq sequence number of the record
1555 * @param zone_key the zone key
1557 * @param rd_count number of records for this name
1558 * @param rd record data
1561 zone_iterate_proc (void *cls,
1563 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
1565 unsigned int rd_count,
1566 const struct GNUNET_GNSRECORD_Data *rd)
1568 struct ZoneIterationProcResult *proc = cls;
1569 int do_refresh_block;
1571 if ( (NULL == zone_key) &&
1574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1575 "Iteration done\n");
1578 if ( (NULL == zone_key) ||
1581 /* what is this!? should never happen */
1585 if (0 == proc->limit)
1587 /* what is this!? should never happen */
1592 proc->zi->seq = seq;
1593 send_lookup_response (proc->zi->nc,
1594 proc->zi->request_id,
1599 do_refresh_block = GNUNET_NO;
1600 for (unsigned int i=0;i<rd_count;i++)
1601 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
1603 do_refresh_block = GNUNET_YES;
1606 if (GNUNET_YES == do_refresh_block)
1607 refresh_block (NULL,
1617 * Perform the next round of the zone iteration.
1619 * @param zi zone iterator to process
1620 * @param limit number of results to return in one pass
1623 run_zone_iteration_round (struct ZoneIteration *zi,
1626 struct ZoneIterationProcResult proc;
1627 struct GNUNET_MQ_Envelope *env;
1628 struct RecordResultMessage *rrm;
1629 struct GNUNET_TIME_Absolute start;
1630 struct GNUNET_TIME_Relative duration;
1635 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1636 "Asked to return up to %llu records at position %llu\n",
1637 (unsigned long long) limit,
1638 (unsigned long long) zi->seq);
1641 start = GNUNET_TIME_absolute_get ();
1642 GNUNET_break (GNUNET_SYSERR !=
1643 GSN_database->iterate_records (GSN_database->cls,
1644 (0 == memcmp (&zi->zone,
1653 duration = GNUNET_TIME_absolute_get_duration (start);
1654 duration = GNUNET_TIME_relative_divide (duration,
1655 limit - proc.limit);
1656 GNUNET_STATISTICS_set (statistics,
1657 "NAMESTORE iteration delay (μs/record)",
1658 duration.rel_value_us,
1660 if (0 == proc.limit)
1662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1663 "Returned %llu results, more results available\n",
1664 (unsigned long long) limit);
1665 return; /* more results later after we get the
1666 #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT message */
1668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1669 "Completed iteration after %llu/%llu results\n",
1670 (unsigned long long) (limit - proc.limit),
1671 (unsigned long long) limit);
1672 /* send empty response to indicate end of list */
1673 env = GNUNET_MQ_msg (rrm,
1674 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT);
1675 rrm->gns_header.r_id = htonl (zi->request_id);
1676 GNUNET_MQ_send (zi->nc->mq,
1678 GNUNET_CONTAINER_DLL_remove (zi->nc->op_head,
1686 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START message
1688 * @param cls the client sending the message
1689 * @param zis_msg message from the client
1692 handle_iteration_start (void *cls,
1693 const struct ZoneIterationStartMessage *zis_msg)
1695 struct NamestoreClient *nc = cls;
1696 struct ZoneIteration *zi;
1698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1699 "Received ZONE_ITERATION_START message\n");
1700 zi = GNUNET_new (struct ZoneIteration);
1701 zi->request_id = ntohl (zis_msg->gns_header.r_id);
1704 zi->zone = zis_msg->zone;
1706 GNUNET_CONTAINER_DLL_insert (nc->op_head,
1709 run_zone_iteration_round (zi,
1711 GNUNET_SERVICE_client_continue (nc->client);
1716 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP message
1718 * @param cls the client sending the message
1719 * @param zis_msg message from the client
1722 handle_iteration_stop (void *cls,
1723 const struct ZoneIterationStopMessage *zis_msg)
1725 struct NamestoreClient *nc = cls;
1726 struct ZoneIteration *zi;
1729 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1730 "Received ZONE_ITERATION_STOP message\n");
1731 rid = ntohl (zis_msg->gns_header.r_id);
1732 for (zi = nc->op_head; NULL != zi; zi = zi->next)
1733 if (zi->request_id == rid)
1738 GNUNET_SERVICE_client_drop (nc->client);
1741 GNUNET_CONTAINER_DLL_remove (nc->op_head,
1745 GNUNET_SERVICE_client_continue (nc->client);
1750 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT message
1752 * @param cls the client sending the message
1753 * @param message message from the client
1756 handle_iteration_next (void *cls,
1757 const struct ZoneIterationNextMessage *zis_msg)
1759 struct NamestoreClient *nc = cls;
1760 struct ZoneIteration *zi;
1764 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1765 "Received ZONE_ITERATION_NEXT message\n");
1766 GNUNET_STATISTICS_update (statistics,
1767 "Iteration NEXT messages received",
1770 rid = ntohl (zis_msg->gns_header.r_id);
1771 limit = GNUNET_ntohll (zis_msg->limit);
1772 for (zi = nc->op_head; NULL != zi; zi = zi->next)
1773 if (zi->request_id == rid)
1778 GNUNET_SERVICE_client_drop (nc->client);
1781 run_zone_iteration_round (zi,
1783 GNUNET_SERVICE_client_continue (nc->client);
1788 * Function called when the monitor is ready for more data, and we
1789 * should thus unblock PUT operations that were blocked on the
1790 * monitor not being ready.
1793 monitor_unblock (struct ZoneMonitor *zm)
1795 struct StoreActivity *sa = sa_head;
1797 while ( (NULL != sa) &&
1798 (zm->limit > zm->iteration_cnt) )
1800 struct StoreActivity *sn = sa->next;
1802 if (sa->zm_pos == zm)
1803 continue_store_activity (sa);
1806 if (zm->limit > zm->iteration_cnt)
1807 zm->sa_waiting = GNUNET_NO;
1812 * Send 'sync' message to zone monitor, we're now in sync.
1814 * @param zm monitor that is now in sync
1817 monitor_sync (struct ZoneMonitor *zm)
1819 struct GNUNET_MQ_Envelope *env;
1820 struct GNUNET_MessageHeader *sync;
1822 env = GNUNET_MQ_msg (sync,
1823 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC);
1824 GNUNET_MQ_send (zm->nc->mq,
1826 /* mark iteration done */
1827 zm->in_first_iteration = GNUNET_NO;
1828 zm->iteration_cnt = 0;
1829 if ( (zm->limit > 0) &&
1831 monitor_unblock (zm);
1836 * Obtain the next datum during the zone monitor's zone initial iteration.
1838 * @param cls zone monitor that does its initial iteration
1841 monitor_iteration_next (void *cls);
1845 * A #GNUNET_NAMESTORE_RecordIterator for monitors.
1847 * @param cls a 'struct ZoneMonitor *' with information about the monitor
1848 * @param seq sequence number of the record
1849 * @param zone_key zone key of the zone
1851 * @param rd_count number of records in @a rd
1852 * @param rd array of records
1855 monitor_iterate_cb (void *cls,
1857 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
1859 unsigned int rd_count,
1860 const struct GNUNET_GNSRECORD_Data *rd)
1862 struct ZoneMonitor *zm = cls;
1867 /* finished with iteration */
1871 GNUNET_STATISTICS_update (statistics,
1872 "Monitor notifications sent",
1876 zm->iteration_cnt--;
1877 send_lookup_response (zm->nc,
1883 if ( (0 == zm->iteration_cnt) &&
1886 /* We are done with the current iteration batch, AND the
1887 client would right now accept more, so go again! */
1888 GNUNET_assert (NULL == zm->task);
1889 zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
1896 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START message
1898 * @param cls the client sending the message
1899 * @param zis_msg message from the client
1902 handle_monitor_start (void *cls,
1903 const struct ZoneMonitorStartMessage *zis_msg)
1905 struct NamestoreClient *nc = cls;
1906 struct ZoneMonitor *zm;
1908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1909 "Received ZONE_MONITOR_START message\n");
1910 zm = GNUNET_new (struct ZoneMonitor);
1912 zm->zone = zis_msg->zone;
1914 zm->in_first_iteration = (GNUNET_YES == ntohl (zis_msg->iterate_first));
1915 GNUNET_CONTAINER_DLL_insert (monitor_head,
1918 GNUNET_SERVICE_client_mark_monitor (nc->client);
1919 GNUNET_SERVICE_client_continue (nc->client);
1920 GNUNET_notification_context_add (monitor_nc,
1922 if (zm->in_first_iteration)
1923 zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
1931 * Obtain the next datum during the zone monitor's zone initial iteration.
1933 * @param cls zone monitor that does its initial iteration
1936 monitor_iteration_next (void *cls)
1938 struct ZoneMonitor *zm = cls;
1942 GNUNET_assert (0 == zm->iteration_cnt);
1944 zm->iteration_cnt = zm->limit / 2; /* leave half for monitor events */
1946 zm->iteration_cnt = zm->limit; /* use it all */
1947 ret = GSN_database->iterate_records (GSN_database->cls,
1948 (0 == memcmp (&zm->zone,
1955 &monitor_iterate_cb,
1957 if (GNUNET_SYSERR == ret)
1959 GNUNET_SERVICE_client_drop (zm->nc->client);
1962 if (GNUNET_NO == ret)
1972 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT message
1974 * @param cls the client sending the message
1975 * @param nm message from the client
1978 handle_monitor_next (void *cls,
1979 const struct ZoneMonitorNextMessage *nm)
1981 struct NamestoreClient *nc = cls;
1982 struct ZoneMonitor *zm;
1985 inc = GNUNET_ntohll (nm->limit);
1986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1987 "Received ZONE_MONITOR_NEXT message with limit %llu\n",
1988 (unsigned long long) inc);
1989 for (zm = monitor_head; NULL != zm; zm = zm->next)
1995 GNUNET_SERVICE_client_drop (nc->client);
1998 GNUNET_SERVICE_client_continue (nc->client);
1999 if (zm->limit + inc < zm->limit)
2002 GNUNET_SERVICE_client_drop (nc->client);
2006 if ( (zm->in_first_iteration) &&
2007 (zm->limit == inc) )
2009 /* We are still iterating, and the previous iteration must
2010 have stopped due to the client's limit, so continue it! */
2011 GNUNET_assert (NULL == zm->task);
2012 zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
2015 GNUNET_assert (zm->iteration_cnt <= zm->limit);
2016 if ( (zm->limit > zm->iteration_cnt) &&
2018 monitor_unblock (zm);
2023 * Process namestore requests.
2025 * @param cls closure
2026 * @param cfg configuration to use
2027 * @param service the initialized service
2031 const struct GNUNET_CONFIGURATION_Handle *cfg,
2032 struct GNUNET_SERVICE_Handle *service)
2038 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2039 "Starting namestore service\n");
2040 cache_keys = GNUNET_CONFIGURATION_get_value_yesno (cfg,
2043 disable_namecache = GNUNET_CONFIGURATION_get_value_yesno (cfg,
2047 monitor_nc = GNUNET_notification_context_create (1);
2048 if (GNUNET_YES != disable_namecache)
2050 namecache = GNUNET_NAMECACHE_connect (cfg);
2051 GNUNET_assert (NULL != namecache);
2053 /* Loading database plugin */
2055 GNUNET_CONFIGURATION_get_value_string (cfg,
2059 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2060 "No database backend configured\n");
2062 GNUNET_asprintf (&db_lib_name,
2063 "libgnunet_plugin_namestore_%s",
2065 GSN_database = GNUNET_PLUGIN_load (db_lib_name,
2067 GNUNET_free (database);
2068 statistics = GNUNET_STATISTICS_create ("namestore",
2070 GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
2072 if (NULL == GSN_database)
2074 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2075 "Could not load database backend `%s'\n",
2077 GNUNET_SCHEDULER_shutdown ();
2084 * Define "main" method using service macro.
2088 GNUNET_SERVICE_OPTION_NONE,
2091 &client_disconnect_cb,
2093 GNUNET_MQ_hd_var_size (record_store,
2094 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE,
2095 struct RecordStoreMessage,
2097 GNUNET_MQ_hd_var_size (record_lookup,
2098 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP,
2099 struct LabelLookupMessage,
2101 GNUNET_MQ_hd_fixed_size (zone_to_name,
2102 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME,
2103 struct ZoneToNameMessage,
2105 GNUNET_MQ_hd_fixed_size (iteration_start,
2106 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START,
2107 struct ZoneIterationStartMessage,
2109 GNUNET_MQ_hd_fixed_size (iteration_next,
2110 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT,
2111 struct ZoneIterationNextMessage,
2113 GNUNET_MQ_hd_fixed_size (iteration_stop,
2114 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP,
2115 struct ZoneIterationStopMessage,
2117 GNUNET_MQ_hd_fixed_size (monitor_start,
2118 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START,
2119 struct ZoneMonitorStartMessage,
2121 GNUNET_MQ_hd_fixed_size (monitor_next,
2122 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT,
2123 struct ZoneMonitorNextMessage,
2125 GNUNET_MQ_handler_end ());
2128 /* end of gnunet-service-namestore.c */