2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file namestore/gnunet-service-namestore.c
23 * @brief namestore for the GNUnet naming system
24 * @author Matthias Wachs
27 #include "gnunet_getopt_lib.h"
28 #include "gnunet_service_lib.h"
29 #include "gnunet_namestore_service.h"
30 #include "gnunet_namestore_plugin.h"
31 #include "gnunet_signatures.h"
32 #include "namestore.h"
34 #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
37 * A namestore operation.
39 struct GNUNET_NAMESTORE_ZoneIteration
41 struct GNUNET_NAMESTORE_ZoneIteration *next;
42 struct GNUNET_NAMESTORE_ZoneIteration *prev;
44 struct GNUNET_NAMESTORE_Client * client;
48 struct GNUNET_CRYPTO_ShortHashCode zone;
54 * Which flags must be included
56 uint16_t must_have_flags;
59 * Which flags must not be included
61 uint16_t must_not_have_flags;
68 struct GNUNET_NAMESTORE_Client
70 struct GNUNET_NAMESTORE_Client *next;
71 struct GNUNET_NAMESTORE_Client *prev;
73 struct GNUNET_SERVER_Client * client;
75 struct GNUNET_NAMESTORE_ZoneIteration *op_head;
76 struct GNUNET_NAMESTORE_ZoneIteration *op_tail;
79 struct GNUNET_NAMESTORE_CryptoContainer
83 struct GNUNET_CRYPTO_ShortHashCode zone;
84 struct GNUNET_CRYPTO_RsaPrivateKey *privkey;
85 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey;
90 * Configuration handle.
92 const struct GNUNET_CONFIGURATION_Handle *GSN_cfg;
97 struct GNUNET_NAMESTORE_PluginFunctions *GSN_database;
102 static char *zonefile_directory;
104 static char *db_lib_name;
108 * Our notification context.
110 static struct GNUNET_SERVER_NotificationContext *snc;
112 static struct GNUNET_NAMESTORE_Client *client_head;
113 static struct GNUNET_NAMESTORE_Client *client_tail;
115 struct GNUNET_CONTAINER_MultiHashMap *zonekeys;
119 * Write zonefile to disk
120 * @param filename where to write
121 * @param c the crypto container
123 * @return GNUNET_OK on success, GNUNET_SYSERR on fail
127 write_key_to_file (const char *filename, struct GNUNET_NAMESTORE_CryptoContainer *c)
129 struct GNUNET_CRYPTO_RsaPrivateKey *ret = c->privkey;
130 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *enc;
131 struct GNUNET_DISK_FileHandle *fd;
133 if (GNUNET_YES == GNUNET_DISK_file_test (filename))
135 struct GNUNET_CRYPTO_ShortHashCode zone;
136 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey;
137 struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
139 privkey = GNUNET_CRYPTO_rsa_key_create_from_file(filename);
142 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
143 _("File zone `%s' but corrupt content already exists, failed to write! \n"), GNUNET_short_h2s (&zone));
144 return GNUNET_SYSERR;
147 GNUNET_CRYPTO_rsa_key_get_public (privkey, &pubkey);
148 GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone);
149 GNUNET_CRYPTO_rsa_key_free (privkey);
151 if (0 == memcmp (&zone, &c->zone, sizeof(zone)))
153 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
154 _("File zone `%s' containing this key already exists\n"), GNUNET_short_h2s (&zone));
159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
160 _("File zone `%s' but different zone key already exists, failed to write! \n"), GNUNET_short_h2s (&zone));
164 fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_FAILIFEXISTS, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
169 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
171 /* must exist but not be accessible, fail for good! */
172 if (0 != ACCESS (filename, R_OK))
173 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename);
175 GNUNET_break (0); /* what is going on!? */
176 return GNUNET_SYSERR;
179 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
180 return GNUNET_SYSERR;
183 if (GNUNET_YES != GNUNET_DISK_file_lock (fd, 0, sizeof (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded), GNUNET_YES))
185 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
186 return GNUNET_SYSERR;
188 enc = GNUNET_CRYPTO_rsa_encode_key (ret);
189 GNUNET_assert (enc != NULL);
190 GNUNET_assert (ntohs (enc->len) == GNUNET_DISK_file_write (fd, enc, ntohs (enc->len)));
192 GNUNET_DISK_file_sync (fd);
193 if (GNUNET_YES != GNUNET_DISK_file_unlock (fd, 0, sizeof (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded)))
194 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
195 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
198 _("Stored zonekey for zone `%s' in file `%s'\n"), GNUNET_short_h2s(&c->zone), c->filename);
202 int zone_to_disk_it (void *cls,
203 const GNUNET_HashCode *key,
206 struct GNUNET_NAMESTORE_CryptoContainer * c = value;
207 if (c->filename != NULL)
208 write_key_to_file(c->filename, c);
211 GNUNET_asprintf(&c->filename, "%s/%s.zkey", zonefile_directory, GNUNET_short_h2s (&c->zone));
212 write_key_to_file(c->filename, c);
216 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (zonekeys, key, value));
217 GNUNET_CRYPTO_rsa_key_free (c->privkey);
218 GNUNET_free (c->pubkey);
219 GNUNET_free (c->filename);
226 struct GNUNET_TIME_Absolute
227 get_block_expiration_time (unsigned int rd_count, const struct GNUNET_NAMESTORE_RecordData *rd)
230 struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get_forever();
232 return GNUNET_TIME_absolute_get_zero();
233 for (c = 0; c < rd_count; c++)
235 if (rd[c].expiration.abs_value < expire.abs_value)
236 expire = rd[c].expiration;
242 * Task run during shutdown.
248 cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n");
251 struct GNUNET_NAMESTORE_ZoneIteration * no;
252 struct GNUNET_NAMESTORE_ZoneIteration * tmp;
253 struct GNUNET_NAMESTORE_Client * nc;
254 struct GNUNET_NAMESTORE_Client * next;
256 GNUNET_SERVER_notification_context_destroy (snc);
258 GNUNET_CONTAINER_multihashmap_iterate(zonekeys, &zone_to_disk_it, NULL);
259 GNUNET_CONTAINER_multihashmap_destroy(zonekeys);
261 for (nc = client_head; nc != NULL; nc = next)
264 for (no = nc->op_head; no != NULL; no = tmp)
266 GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no);
270 GNUNET_SERVER_client_drop(nc->client);
271 GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc);
275 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database));
276 GNUNET_free (db_lib_name);
277 GNUNET_free_non_null(zonefile_directory);
280 static struct GNUNET_NAMESTORE_Client *
281 client_lookup (struct GNUNET_SERVER_Client *client)
283 struct GNUNET_NAMESTORE_Client * nc;
285 GNUNET_assert (NULL != client);
287 for (nc = client_head; nc != NULL; nc = nc->next)
289 if (client == nc->client)
296 * Called whenever a client is disconnected. Frees our
297 * resources associated with that client.
300 * @param client identification of the client
303 client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
305 struct GNUNET_NAMESTORE_ZoneIteration * no;
306 struct GNUNET_NAMESTORE_Client * nc;
310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected \n", client);
312 nc = client_lookup (client);
314 if ((NULL == client) || (NULL == nc))
320 GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no);
325 GNUNET_SERVER_client_drop(nc->client);
326 GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc);
333 static void handle_start (void *cls,
334 struct GNUNET_SERVER_Client * client,
335 const struct GNUNET_MessageHeader * message)
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client);
339 struct GNUNET_NAMESTORE_Client * nc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Client));
341 GNUNET_SERVER_notification_context_add (snc, client);
342 GNUNET_CONTAINER_DLL_insert(client_head, client_tail, nc);
343 GNUNET_SERVER_client_keep (client);
344 GNUNET_SERVER_receive_done (client, GNUNET_OK);
347 struct LookupNameContext
349 struct GNUNET_NAMESTORE_Client *nc;
351 uint32_t record_type;
352 struct GNUNET_CRYPTO_ShortHashCode *zone;
356 void drop_iterator (void *cls,
357 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
358 struct GNUNET_TIME_Absolute expire,
361 const struct GNUNET_NAMESTORE_RecordData *rd,
362 const struct GNUNET_CRYPTO_RsaSignature *signature)
364 struct GNUNET_CRYPTO_ShortHashCode zone_hash;
366 if (NULL != zone_key)
368 GNUNET_CRYPTO_short_hash(zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone_hash);
369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting zone `%s'\n", GNUNET_short_h2s (&zone_hash));
370 GSN_database->delete_zone (GSN_database->cls, &zone_hash);
374 (*stop) = GNUNET_YES;
380 handle_lookup_name_it (void *cls,
381 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
382 struct GNUNET_TIME_Absolute expire,
384 unsigned int rd_count,
385 const struct GNUNET_NAMESTORE_RecordData *rd,
386 const struct GNUNET_CRYPTO_RsaSignature *signature)
389 struct LookupNameContext *lnc = cls;
390 struct LookupNameResponseMessage *lnr_msg;
391 struct GNUNET_NAMESTORE_RecordData *rd_selected = NULL;
392 struct GNUNET_NAMESTORE_CryptoContainer *cc;
393 struct GNUNET_CRYPTO_RsaSignature *signature_new = NULL;
394 struct GNUNET_TIME_Absolute e;
395 struct GNUNET_CRYPTO_ShortHashCode zone_key_hash;
396 GNUNET_HashCode long_hash;
403 int copied_elements = 0;
404 int contains_signature = GNUNET_NO;
405 int authoritative = GNUNET_NO;
409 name_len = strlen(name) + 1;
411 /* count records to copy */
414 if (lnc->record_type != 0)
416 /* special record type needed */
417 for (c = 0; c < rd_count; c ++)
418 if (rd[c].record_type == lnc->record_type)
419 copied_elements++; /* found matching record */
420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u records with type %u for name `%s' in zone `%s'\n",
421 copied_elements, lnc->record_type, lnc->name, GNUNET_short_h2s(lnc->zone));
422 rd_selected = GNUNET_malloc (copied_elements * sizeof (struct GNUNET_NAMESTORE_RecordData));
424 for (c = 0; c < rd_count; c ++)
426 if (rd[c].record_type == lnc->record_type)
428 /* found matching record */
429 memcpy (&rd_selected[copied_elements], &rd[c], sizeof (struct GNUNET_NAMESTORE_RecordData));
436 copied_elements = rd_count;
437 rd_selected = (struct GNUNET_NAMESTORE_RecordData *) rd;
445 expire = GNUNET_TIME_UNIT_ZERO_ABS;
448 rd_ser_len = GNUNET_NAMESTORE_records_get_size(copied_elements, rd_selected);
449 char rd_ser[rd_ser_len];
450 GNUNET_NAMESTORE_records_serialize(copied_elements, rd_selected, rd_ser_len, rd_ser);
452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u records for name `%s' in zone `%s'\n",
453 copied_elements, lnc->name, GNUNET_short_h2s(lnc->zone));
455 if ((copied_elements == rd_count) && (NULL != signature))
456 contains_signature = GNUNET_YES; /* returning all records, so include signature */
458 contains_signature = GNUNET_NO; /* returning not all records, so do not include signature */
461 if ((NULL != zone_key) && (copied_elements == rd_count))
463 GNUNET_CRYPTO_short_hash(zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone_key_hash);
464 GNUNET_CRYPTO_short_hash_double (&zone_key_hash, &long_hash);
465 if (GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash))
467 cc = GNUNET_CONTAINER_multihashmap_get(zonekeys, &long_hash);
468 e = get_block_expiration_time(rd_count, rd);
469 signature_new = GNUNET_NAMESTORE_create_signature(cc->privkey, e, name, rd, rd_count);
470 GNUNET_assert (signature_new != NULL);
471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating signature for name `%s' with %u records in zone `%s'\n",name, copied_elements, GNUNET_short_h2s(&zone_key_hash));
472 authoritative = GNUNET_YES;
475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am not authoritative for name `%s' in zone `%s'\n",name, GNUNET_short_h2s(&zone_key_hash));
478 r_size = sizeof (struct LookupNameResponseMessage) +
479 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "NAMESTORE_LOOKUP_NAME_RESPONSE");
484 lnr_msg = GNUNET_malloc (r_size);
485 lnr_msg->gns_header.header.type = ntohs (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE);
486 lnr_msg->gns_header.header.size = ntohs (r_size);
487 lnr_msg->gns_header.r_id = htonl (lnc->request_id);
488 lnr_msg->rd_count = htons (copied_elements);
489 lnr_msg->rd_len = htons (rd_ser_len);
490 lnr_msg->name_len = htons (name_len);
491 lnr_msg->expire = GNUNET_TIME_absolute_hton(get_block_expiration_time(copied_elements, rd_selected));
493 if (rd_selected != rd)
494 GNUNET_free (rd_selected);
496 if (zone_key != NULL)
497 lnr_msg->public_key = (*zone_key);
499 memset(&lnr_msg->public_key, '\0', sizeof (lnr_msg->public_key));
501 if (GNUNET_YES == authoritative)
502 { /* use new created signature */
503 lnr_msg->contains_sig = htons (GNUNET_YES);
504 GNUNET_assert (signature_new != NULL);
505 lnr_msg->signature = *signature_new;
506 GNUNET_free (signature_new);
508 else if (GNUNET_YES == contains_signature)
510 /* use existing signature */
511 lnr_msg->contains_sig = htons (GNUNET_YES);
512 GNUNET_assert (signature != NULL);
513 lnr_msg->signature = *signature;
517 /* use no signature */
518 memset (&lnr_msg->signature, '\0', sizeof (lnr_msg->signature));
521 name_tmp = (char *) &lnr_msg[1];
522 rd_tmp = &name_tmp[name_len];
524 memcpy (name_tmp, name, name_len);
525 memcpy (rd_tmp, rd_ser, rd_ser_len);
527 GNUNET_SERVER_notification_context_unicast (snc, lnc->nc->client, (const struct GNUNET_MessageHeader *) lnr_msg, GNUNET_NO);
528 GNUNET_free (lnr_msg);
531 static void handle_lookup_name (void *cls,
532 struct GNUNET_SERVER_Client * client,
533 const struct GNUNET_MessageHeader * message)
535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_LOOKUP_NAME");
536 struct LookupNameContext lnc;
537 struct GNUNET_NAMESTORE_Client *nc;
543 if (ntohs (message->size) < sizeof (struct LookupNameMessage))
546 GNUNET_SERVER_receive_done (client, GNUNET_OK);
550 nc = client_lookup(client);
554 GNUNET_SERVER_receive_done (client, GNUNET_OK);
558 struct LookupNameMessage * ln_msg = (struct LookupNameMessage *) message;
559 rid = ntohl (ln_msg->gns_header.r_id);
560 name_len = ntohl (ln_msg->name_len);
561 type = ntohl (ln_msg->record_type);
563 if ((name_len == 0) || (name_len > 256))
566 GNUNET_SERVER_receive_done (client, GNUNET_OK);
570 name = (char *) &ln_msg[1];
571 if (name[name_len -1] != '\0')
574 GNUNET_SERVER_receive_done (client, GNUNET_OK);
579 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up all records for name `%s' in zone `%s'\n", name, GNUNET_short_h2s(&ln_msg->zone));
581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up records with type %u for name `%s' in zone `%s'\n", type, name, GNUNET_short_h2s(&ln_msg->zone));
583 /* do the actual lookup */
584 lnc.request_id = rid;
586 lnc.record_type = type;
588 lnc.zone = &ln_msg->zone;
589 GSN_database->iterate_records(GSN_database->cls, &ln_msg->zone, name, 0, &handle_lookup_name_it, &lnc);
591 GNUNET_SERVER_receive_done (client, GNUNET_OK);
594 static void handle_record_put (void *cls,
595 struct GNUNET_SERVER_Client * client,
596 const struct GNUNET_MessageHeader * message)
598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_PUT");
599 struct GNUNET_NAMESTORE_Client *nc;
600 struct GNUNET_TIME_Absolute expire;
601 struct GNUNET_CRYPTO_RsaSignature *signature;
602 struct RecordPutResponseMessage rpr_msg;
611 int res = GNUNET_SYSERR;
613 if (ntohs (message->size) < sizeof (struct RecordPutMessage))
616 GNUNET_SERVER_receive_done (client, GNUNET_OK);
620 nc = client_lookup (client);
624 GNUNET_SERVER_receive_done (client, GNUNET_OK);
628 struct RecordPutMessage * rp_msg = (struct RecordPutMessage *) message;
630 rid = ntohl (rp_msg->gns_header.r_id);
631 msg_size = ntohs (rp_msg->gns_header.header.size);
632 name_len = ntohs (rp_msg->name_len);
633 rd_count = ntohs (rp_msg->rd_count);
634 rd_ser_len = ntohs(rp_msg->rd_len);
636 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
639 GNUNET_SERVER_receive_done (client, GNUNET_OK);
643 if ((rd_count < 1) || (rd_ser_len < 1) || (name_len >=256) || (name_len == 0))
646 GNUNET_SERVER_receive_done (client, GNUNET_OK);
650 msg_size_exp = sizeof (struct RecordPutMessage) + name_len + rd_ser_len;
651 if (msg_size != msg_size_exp)
653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size);
655 GNUNET_SERVER_receive_done (client, GNUNET_OK);
658 if ((name_len == 0) || (name_len > 256))
661 GNUNET_SERVER_receive_done (client, GNUNET_OK);
665 name = (char *) &rp_msg[1];
667 if (name[name_len -1] != '\0')
670 GNUNET_SERVER_receive_done (client, GNUNET_OK);
674 expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire);
675 signature = (struct GNUNET_CRYPTO_RsaSignature *) &rp_msg->signature;
677 rd_ser = &name[name_len];
678 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
679 res = GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_ser, rd_count, rd);
680 if (res != GNUNET_OK)
686 struct GNUNET_CRYPTO_ShortHashCode zone_hash;
687 GNUNET_CRYPTO_short_hash (&rp_msg->public_key, sizeof (rp_msg->public_key), &zone_hash);
689 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting %u record for name `%s' in zone `%s'\n", rd_count, name, GNUNET_short_h2s(&zone_hash));
691 /* Database operation */
692 res = GSN_database->put_records(GSN_database->cls,
699 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting record for name `%s': %s\n",
700 name, (res == GNUNET_OK) ? "OK" : "FAIL");
704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_PUT_RESPONSE");
705 rpr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE);
706 rpr_msg.gns_header.header.size = htons (sizeof (struct RecordPutResponseMessage));
707 rpr_msg.gns_header.r_id = htonl (rid);
708 rpr_msg.op_result = htonl (res);
709 GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rpr_msg, GNUNET_NO);
711 GNUNET_SERVER_receive_done (client, GNUNET_OK);
714 struct CreateRecordContext
716 struct GNUNET_NAMESTORE_RecordData *rd;
717 struct GNUNET_CRYPTO_RsaPrivateKey *pkey;
718 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey;
719 struct GNUNET_TIME_Absolute expire;
726 handle_create_record_it (void *cls,
727 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey,
728 struct GNUNET_TIME_Absolute expire,
730 unsigned int rd_count,
731 const struct GNUNET_NAMESTORE_RecordData *rd,
732 const struct GNUNET_CRYPTO_RsaSignature *signature)
734 struct CreateRecordContext * crc = cls;
735 struct GNUNET_NAMESTORE_RecordData *rd_new = NULL;
736 struct GNUNET_CRYPTO_RsaSignature dummy_signature;
737 struct GNUNET_TIME_Absolute block_expiration;
739 int exist = GNUNET_SYSERR;
740 int update = GNUNET_NO;
742 int rd_count_new = 0;
744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u existing records for `%s'\n", rd_count, crc->name);
745 for (c = 0; c < rd_count; c++)
747 if ((crc->rd->record_type == GNUNET_NAMESTORE_TYPE_PKEY) && (rd[c].record_type == GNUNET_NAMESTORE_TYPE_PKEY))
749 /* Update unique PKEY */
754 else if ((crc->rd->record_type == GNUNET_NAMESTORE_TYPE_PSEU) && (rd[c].record_type == GNUNET_NAMESTORE_TYPE_PSEU))
756 /* Update unique PSEU */
761 else if ((crc->rd->record_type == rd[c].record_type) &&
762 (crc->rd->data_size == rd[c].data_size) &&
763 (0 == memcmp (crc->rd->data, rd[c].data, rd[c].data_size)))
765 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found existing records for `%s' to update expiration date!\n", crc->name);
767 if (crc->rd->expiration.abs_value != rd[c].expiration.abs_value)
773 if (exist == GNUNET_SYSERR)
774 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New record does not exist for name `%s'!\n", crc->name);
776 if (exist == GNUNET_SYSERR)
778 rd_new = GNUNET_malloc ((rd_count+1) * sizeof (struct GNUNET_NAMESTORE_RecordData));
779 memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
780 rd_count_new = rd_count + 1;
781 rd_new[rd_count] = *(crc->rd);
783 else if (update == GNUNET_NO)
785 /* Exact same record already exists */
786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No update for %s' record required!\n", crc->name);
790 else if (update == GNUNET_YES)
793 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating existing records for `%s'!\n", crc->name);
794 rd_new = GNUNET_malloc ((rd_count) * sizeof (struct GNUNET_NAMESTORE_RecordData));
795 memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
796 rd_count_new = rd_count;
797 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating expiration from %llu to %llu!\n", rd_new[exist].expiration.abs_value, crc->rd->expiration.abs_value);
798 rd_new[exist] = *(crc->rd);
801 block_expiration = GNUNET_TIME_absolute_max(crc->expire, expire);
802 if (block_expiration.abs_value != expire.abs_value)
803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updated block expiration time\n");
805 memset (&dummy_signature, '\0', sizeof (dummy_signature));
807 /* Database operation */
808 GNUNET_assert ((rd_new != NULL) && (rd_count_new > 0));
809 res = GSN_database->put_records(GSN_database->cls,
810 (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) crc->pubkey,
813 rd_count_new, rd_new,
815 GNUNET_break (GNUNET_OK == res);
816 if (res == GNUNET_OK)
817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully put record for `%s' in database \n", crc->name);
819 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to put record for `%s' in database \n", crc->name);
823 GNUNET_free_non_null (rd_new);
827 /* failed to create the record */
828 crc->res = GNUNET_SYSERR;
831 /* database operations OK */
832 if (GNUNET_YES == update)
834 /* we updated an existing record */
835 crc->res = GNUNET_NO;
839 /* we created a new record */
840 crc->res = GNUNET_YES;
844 /* identical entry existed, so we did nothing */
845 crc->res = GNUNET_NO;
851 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Update result for name `%s' %u\n", crc->name, res);
855 static void handle_record_create (void *cls,
856 struct GNUNET_SERVER_Client * client,
857 const struct GNUNET_MessageHeader * message)
859 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_CREATE");
860 struct GNUNET_NAMESTORE_Client *nc;
861 struct GNUNET_NAMESTORE_CryptoContainer *cc;
862 struct CreateRecordContext crc;
863 struct GNUNET_CRYPTO_RsaPrivateKey *pkey;
864 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
865 struct RecordCreateResponseMessage rcr_msg;
866 struct GNUNET_CRYPTO_ShortHashCode pubkey_hash;
867 GNUNET_HashCode long_hash;
879 int res = GNUNET_SYSERR;
880 crc.res = GNUNET_SYSERR;
882 if (ntohs (message->size) < sizeof (struct RecordCreateMessage))
885 GNUNET_SERVER_receive_done (client, GNUNET_OK);
889 nc = client_lookup(client);
893 GNUNET_SERVER_receive_done (client, GNUNET_OK);
897 struct RecordCreateMessage * rp_msg = (struct RecordCreateMessage *) message;
898 rid = ntohl (rp_msg->gns_header.r_id);
899 name_len = ntohs (rp_msg->name_len);
900 msg_size = ntohs (message->size);
901 rd_count = ntohs (rp_msg->rd_count);
902 rd_ser_len = ntohs (rp_msg->rd_len);
903 key_len = ntohs (rp_msg->pkey_len);
904 msg_size_exp = sizeof (struct RecordCreateMessage) + key_len + name_len + rd_ser_len;
906 if (msg_size != msg_size_exp)
908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size);
910 GNUNET_SERVER_receive_done (client, GNUNET_OK);
914 if ((name_len == 0) || (name_len > 256))
917 GNUNET_SERVER_receive_done (client, GNUNET_OK);
921 pkey_tmp = (char *) &rp_msg[1];
922 name_tmp = &pkey_tmp[key_len];
923 rd_ser = &name_tmp[name_len];
925 if (name_tmp[name_len -1] != '\0')
928 GNUNET_SERVER_receive_done (client, GNUNET_OK);
932 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
934 res = GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_ser, rd_count, rd);
935 if ((res != GNUNET_OK) || (rd_count != 1))
940 /* Extracting and converting private key */
941 pkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len);
942 GNUNET_assert (pkey != NULL);
943 GNUNET_CRYPTO_rsa_key_get_public(pkey, &pub);
944 GNUNET_CRYPTO_short_hash (&pub, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash);
945 GNUNET_CRYPTO_short_hash_double (&pubkey_hash, &long_hash);
947 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash))
949 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received new private key for zone `%s'\n",GNUNET_short_h2s(&pubkey_hash));
951 cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer));
952 cc->privkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len);
953 cc->pubkey = GNUNET_malloc(sizeof (pub));
954 memcpy (cc->pubkey, &pub, sizeof(pub));
955 cc->zone = pubkey_hash;
956 GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, cc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
959 crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire);
960 crc.res = GNUNET_SYSERR;
966 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating record for name `%s' in zone `%s'\n", name_tmp, GNUNET_short_h2s(&pubkey_hash));
968 /* Get existing records for name */
969 res = GSN_database->iterate_records(GSN_database->cls, &pubkey_hash, name_tmp, 0, &handle_create_record_it, &crc);
970 if (res != GNUNET_SYSERR)
972 GNUNET_CRYPTO_rsa_key_free(pkey);
977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_CREATE_RESPONSE");
978 rcr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE);
979 rcr_msg.gns_header.header.size = htons (sizeof (struct RecordCreateResponseMessage));
980 rcr_msg.gns_header.r_id = htonl (rid);
981 if ((GNUNET_OK == res) && (crc.res == GNUNET_YES))
982 rcr_msg.op_result = htonl (GNUNET_YES);
983 else if ((GNUNET_OK == res) && (crc.res == GNUNET_NO))
984 rcr_msg.op_result = htonl (GNUNET_NO);
986 rcr_msg.op_result = htonl (GNUNET_SYSERR);
987 GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rcr_msg, GNUNET_NO);
989 GNUNET_SERVER_receive_done (client, GNUNET_OK);
993 struct RemoveRecordContext
995 struct GNUNET_NAMESTORE_RecordData *rd;
996 struct GNUNET_CRYPTO_RsaPrivateKey *pkey;
1002 handle_record_remove_it (void *cls,
1003 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
1004 struct GNUNET_TIME_Absolute expire,
1006 unsigned int rd_count,
1007 const struct GNUNET_NAMESTORE_RecordData *rd,
1008 const struct GNUNET_CRYPTO_RsaSignature *signature)
1010 struct RemoveRecordContext *rrc = cls;
1014 unsigned int rd_count_new;
1016 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name `%s 'currently has %u records\n", name, rd_count);
1020 /* Could not find record to remove */
1025 /* Find record to remove */
1026 found = GNUNET_SYSERR;
1027 for (c = 0; c < rd_count; c++)
1030 if (rd[c].flags != rrc->rd->flags)
1032 if (rd[c].record_type != rrc->rd->record_type)
1035 if (rd[c].data_size != rrc->rd->data_size)
1038 if (0 != memcmp (rd[c].data, rrc->rd->data, rrc->rd->data_size))
1041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found record to remove!\n", rd_count);
1045 if (GNUNET_SYSERR == found)
1047 /* Could not find record to remove */
1052 if (rd_count-1 == 0)
1054 struct GNUNET_CRYPTO_ShortHashCode pubkey_hash;
1055 GNUNET_CRYPTO_short_hash (zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash);
1056 res = GSN_database->remove_records (GSN_database->cls,
1059 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1060 "No records left for name `%s', removing name\n",
1062 if (GNUNET_OK != res)
1064 /* Could put records into database */
1072 rd_count_new = rd_count -1;
1073 struct GNUNET_NAMESTORE_RecordData rd_new[rd_count_new];
1075 unsigned int c2 = 0;
1076 for (c = 0; c < rd_count; c++)
1080 GNUNET_assert (c2 < rd_count_new);
1086 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name `%s' now has %u records\n", name, rd_count_new);
1088 /* Create dummy signature */
1089 struct GNUNET_CRYPTO_RsaSignature dummy_signature;
1090 memset (&dummy_signature, '\0', sizeof (dummy_signature));
1094 res = GSN_database->put_records(GSN_database->cls,
1098 rd_count_new, rd_new,
1100 if (GNUNET_OK != res)
1102 /* Could put records into database */
1110 static void handle_record_remove (void *cls,
1111 struct GNUNET_SERVER_Client * client,
1112 const struct GNUNET_MessageHeader * message)
1114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_REMOVE");
1115 struct GNUNET_NAMESTORE_Client *nc;
1116 struct RecordRemoveResponseMessage rrr_msg;
1117 struct GNUNET_CRYPTO_RsaPrivateKey *pkey;
1118 struct GNUNET_NAMESTORE_CryptoContainer *cc = NULL;
1119 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
1120 struct GNUNET_CRYPTO_ShortHashCode pubkey_hash;
1121 GNUNET_HashCode long_hash;
1122 char * pkey_tmp = NULL;
1123 char * name_tmp = NULL;
1124 char * rd_ser = NULL;
1126 size_t name_len = 0;
1127 size_t rd_ser_len = 0;
1128 size_t msg_size = 0;
1129 size_t msg_size_exp = 0;
1133 int res = GNUNET_SYSERR;
1135 if (ntohs (message->size) < sizeof (struct RecordRemoveMessage))
1137 GNUNET_break_op (0);
1138 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1142 nc = client_lookup(client);
1145 GNUNET_break_op (0);
1146 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1150 struct RecordRemoveMessage * rr_msg = (struct RecordRemoveMessage *) message;
1151 rid = ntohl (rr_msg->gns_header.r_id);
1152 name_len = ntohs (rr_msg->name_len);
1153 rd_ser_len = ntohs (rr_msg->rd_len);
1154 rd_count = ntohs (rr_msg->rd_count);
1155 key_len = ntohs (rr_msg->pkey_len);
1156 msg_size = ntohs (message->size);
1158 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
1160 GNUNET_break_op (0);
1161 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1165 if ((name_len >=256) || (name_len == 0))
1167 GNUNET_break_op (0);
1168 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1172 msg_size_exp = sizeof (struct RecordRemoveMessage) + key_len + name_len + rd_ser_len;
1173 if (msg_size != msg_size_exp)
1175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size);
1176 GNUNET_break_op (0);
1177 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1181 pkey_tmp = (char *) &rr_msg[1];
1182 name_tmp = &pkey_tmp[key_len];
1183 rd_ser = &name_tmp[name_len];
1186 if ((name_len == 0) || (name_len > 256))
1188 GNUNET_break_op (0);
1189 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1193 if (name_tmp[name_len -1] != '\0')
1195 GNUNET_break_op (0);
1196 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1200 /* Extracting and converting private key */
1201 pkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len);
1202 GNUNET_assert (pkey != NULL);
1203 GNUNET_CRYPTO_rsa_key_get_public(pkey, &pub);
1204 GNUNET_CRYPTO_short_hash (&pub, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash);
1205 GNUNET_CRYPTO_short_hash_double (&pubkey_hash, &long_hash);
1207 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash))
1209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received new private key for zone `%s'\n",GNUNET_short_h2s(&pubkey_hash));
1210 cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer));
1211 cc->privkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len);
1212 cc->pubkey = GNUNET_malloc(sizeof (pub));
1213 memcpy (cc->pubkey, &pub, sizeof(pub));
1214 cc->zone = pubkey_hash;
1216 GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, cc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1220 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
1221 res = GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_ser, rd_count, rd);
1222 if ((res != GNUNET_OK) || (rd_count > 1))
1224 GNUNET_break_op (0);
1230 /* remove the whole name and all records */
1231 /* Database operation */
1232 res = GSN_database->remove_records (GSN_database->cls,
1235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing name `%s': %s\n",
1236 name_tmp, (GNUNET_OK == res) ? "OK" : "FAIL");
1238 if (GNUNET_OK != res)
1239 /* Could not remove entry from database */
1246 /* remove a single record */
1247 struct RemoveRecordContext rrc;
1251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing record for name `%s' in zone `%s'\n", name_tmp, GNUNET_short_h2s(&pubkey_hash));
1253 /* Database operation */
1254 res = GSN_database->iterate_records (GSN_database->cls,
1258 handle_record_remove_it, &rrc);
1260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing record for name `%s': %s\n",
1261 name_tmp, (rrc.op_res == 0) ? "OK" : "FAIL");
1266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_REMOVE_RESPONSE");
1267 rrr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE);
1268 rrr_msg.gns_header.header.size = htons (sizeof (struct RecordRemoveResponseMessage));
1269 rrr_msg.gns_header.r_id = htonl (rid);
1270 rrr_msg.op_result = htonl (res);
1271 GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rrr_msg, GNUNET_NO);
1273 GNUNET_CRYPTO_rsa_key_free (pkey);
1275 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1279 struct ZoneToNameCtx
1281 struct GNUNET_NAMESTORE_Client *nc;
1286 handle_zone_to_name_it (void *cls,
1287 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
1288 struct GNUNET_TIME_Absolute expire,
1290 unsigned int rd_count,
1291 const struct GNUNET_NAMESTORE_RecordData *rd,
1292 const struct GNUNET_CRYPTO_RsaSignature *signature)
1294 struct ZoneToNameCtx * ztn_ctx = cls;
1295 struct ZoneToNameResponseMessage *ztnr_msg;
1296 int16_t res = GNUNET_SYSERR;
1297 uint16_t name_len = 0;
1298 uint16_t rd_ser_len = 0 ;
1299 int32_t contains_sig = 0;
1300 size_t msg_size = 0;
1302 char *rd_ser = NULL;
1307 if ((zone_key != NULL) && (name != NULL))
1310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found results: name is `%s', has %u records\n", name, rd_count);
1312 name_len = strlen (name) +1;
1316 /* no result found */
1317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found no results\n");
1324 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
1325 rd_ser = GNUNET_malloc (rd_ser_len);
1326 GNUNET_NAMESTORE_records_serialize(rd_count, rd, rd_ser_len, rd_ser);
1331 if (signature != NULL)
1332 contains_sig = GNUNET_YES;
1334 contains_sig = GNUNET_NO;
1338 msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len + contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature);
1339 ztnr_msg = GNUNET_malloc (msg_size);
1341 name_tmp = (char *) &ztnr_msg[1];
1342 rd_tmp = &name_tmp[name_len];
1343 sig_tmp = &rd_tmp[rd_ser_len];
1345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "ZONE_TO_NAME_RESPONSE");
1346 ztnr_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE);
1347 ztnr_msg->gns_header.header.size = htons (msg_size);
1348 ztnr_msg->gns_header.r_id = htonl (ztn_ctx->rid);
1349 ztnr_msg->res = htons (res);
1350 ztnr_msg->rd_len = htons (rd_ser_len);
1351 ztnr_msg->rd_count = htons (rd_count);
1352 ztnr_msg->name_len = htons (name_len);
1353 ztnr_msg->expire = GNUNET_TIME_absolute_hton(expire);
1354 if (zone_key != NULL)
1355 ztnr_msg->zone_key = *zone_key;
1357 memset (&ztnr_msg->zone_key, '\0', sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
1359 if ((name_len > 0) && (name != NULL))
1360 memcpy (name_tmp, name, name_len);
1362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name is `%s', has %u records, rd ser len %u msg_size %u\n", name, rd_count, rd_ser_len, msg_size);
1363 if ((rd_ser_len > 0) && (rd_ser != NULL))
1364 memcpy (rd_tmp, rd_ser, rd_ser_len);
1365 if ((GNUNET_YES == contains_sig) && (signature != NULL))
1366 memcpy (sig_tmp, signature, contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature));
1368 GNUNET_SERVER_notification_context_unicast (snc, ztn_ctx->nc->client, (const struct GNUNET_MessageHeader *) ztnr_msg, GNUNET_NO);
1369 GNUNET_free (ztnr_msg);
1370 GNUNET_free_non_null (rd_ser);
1374 static void handle_zone_to_name (void *cls,
1375 struct GNUNET_SERVER_Client * client,
1376 const struct GNUNET_MessageHeader * message)
1378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_TO_NAME");
1379 struct GNUNET_NAMESTORE_Client *nc;
1380 struct ZoneToNameCtx ztn_ctx;
1381 size_t msg_size = 0;
1384 if (ntohs (message->size) != sizeof (struct ZoneToNameMessage))
1386 GNUNET_break_op (0);
1387 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1391 nc = client_lookup(client);
1394 GNUNET_break_op (0);
1395 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1399 struct ZoneToNameMessage *ztn_msg = (struct ZoneToNameMessage *) message;
1401 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
1403 GNUNET_break_op (0);
1404 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1408 rid = ntohl (ztn_msg->gns_header.r_id);
1413 struct GNUNET_CRYPTO_ShortHashAsciiEncoded z_tmp;
1414 GNUNET_CRYPTO_short_hash_to_enc(&ztn_msg->zone, &z_tmp);
1415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up name for zone `%s' in zone `%s'\n",
1417 GNUNET_short_h2s (&ztn_msg->value_zone));
1419 GSN_database->zone_to_name (GSN_database->cls, &ztn_msg->zone, &ztn_msg->value_zone, &handle_zone_to_name_it, &ztn_ctx);
1421 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1426 * Copy record, data has to be free separetely
1429 copy_record (const struct GNUNET_NAMESTORE_RecordData *src, struct GNUNET_NAMESTORE_RecordData *dest)
1432 memcpy (dest, src, sizeof (struct GNUNET_NAMESTORE_RecordData));
1433 dest->data = GNUNET_malloc (src->data_size);
1434 memcpy ((void *) dest->data, src->data, src->data_size);
1437 struct ZoneIterationProcResult
1439 struct GNUNET_NAMESTORE_ZoneIteration *zi;
1441 int res_iteration_finished;
1442 int records_included;
1446 struct GNUNET_CRYPTO_ShortHashCode zone_hash;
1447 struct GNUNET_NAMESTORE_RecordData *rd;
1448 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
1449 struct GNUNET_CRYPTO_RsaSignature signature;
1450 struct GNUNET_TIME_Absolute expire;
1454 void zone_iteraterate_proc (void *cls,
1455 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
1456 struct GNUNET_TIME_Absolute expire,
1458 unsigned int rd_count,
1459 const struct GNUNET_NAMESTORE_RecordData *rd,
1460 const struct GNUNET_CRYPTO_RsaSignature *signature)
1462 struct ZoneIterationProcResult *proc = cls;
1463 struct GNUNET_NAMESTORE_RecordData *rd_filtered;
1464 struct GNUNET_CRYPTO_RsaSignature * new_signature;
1465 struct GNUNET_NAMESTORE_CryptoContainer *cc;
1466 struct GNUNET_CRYPTO_ShortHashCode hash;
1467 GNUNET_HashCode long_hash;
1468 struct GNUNET_TIME_Absolute e;
1469 unsigned int rd_count_filtered = 0;
1473 proc->res_iteration_finished = GNUNET_NO;
1474 proc->records_included = 0;
1476 if ((zone_key == NULL) && (name == NULL))
1478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration done\n");
1479 proc->res_iteration_finished = GNUNET_YES;
1485 rd_filtered = GNUNET_malloc (rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
1486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received result for zone iteration: `%s'\n", name);
1487 for (c = 0; c < rd_count; c++)
1489 include = GNUNET_YES;
1490 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %i has flags: 0x%x must have 0x%x \n",
1491 c, rd[c].flags, proc->zi->must_have_flags);
1492 /* Checking must have flags */
1493 if ((rd[c].flags & proc->zi->must_have_flags) == proc->zi->must_have_flags)
1496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %i has flags: Include \n", c);
1500 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %i has flags: Not include \n", c);
1501 include = GNUNET_NO;
1504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %i has flags: 0x%x must not have 0x%x\n",
1505 c, rd[c].flags, proc->zi->must_not_have_flags);
1506 if ((rd[c].flags & proc->zi->must_not_have_flags) != 0)
1508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %i has flags: Not include \n", c);
1509 include = GNUNET_NO;
1514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %i has flags: Include \n", c);
1516 if (GNUNET_YES == include)
1518 copy_record (&rd[c], &rd_filtered[rd_count_filtered]);
1519 rd_count_filtered++;
1523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Included %i of %i records \n", rd_count_filtered, rd_count);
1525 proc->records_included = rd_count_filtered;
1526 if (0 == rd_count_filtered)
1528 GNUNET_free (rd_filtered);
1531 proc->rd = rd_filtered;
1532 proc->name = strdup(name);
1533 memcpy (&proc->zone_key, zone_key, sizeof (proc->zone_key));
1536 proc->has_signature = GNUNET_NO;
1537 GNUNET_CRYPTO_short_hash (zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &hash);
1538 GNUNET_CRYPTO_short_hash_double(&hash, &long_hash);
1539 proc->zone_hash = hash;
1541 if (GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash))
1543 cc = GNUNET_CONTAINER_multihashmap_get(zonekeys, &long_hash);
1544 e = get_block_expiration_time(rd_count_filtered, rd_filtered);
1546 new_signature = GNUNET_NAMESTORE_create_signature(cc->privkey, e, name, rd_filtered, rd_count_filtered);
1547 GNUNET_assert (signature != NULL);
1548 proc->signature = (*new_signature);
1549 GNUNET_free (new_signature);
1550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating signature for `%s' in zone `%s' with %u records and expiration %llu\n",
1551 name, GNUNET_short_h2s(&hash), rd_count_filtered, e.abs_value);
1552 proc->has_signature = GNUNET_YES;
1554 else if (rd_count_filtered == rd_count)
1556 proc->expire = expire;
1557 if (NULL != signature)
1559 proc->signature = (*signature);
1560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using provided signature for `%s' in zone `%s' with %u records and expiration %llu\n",
1561 name, GNUNET_short_h2s(&hash), rd_count_filtered, expire.abs_value);
1562 proc->has_signature = GNUNET_YES;
1566 memset (&proc->signature, '\0', sizeof (proc->signature));
1567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No signature provided for `%s'\n", name);
1574 void find_next_zone_iteration_result (struct ZoneIterationProcResult *proc)
1577 struct GNUNET_CRYPTO_ShortHashCode *zone;
1579 if (GNUNET_YES == proc->zi->has_zone)
1580 zone = &proc->zi->zone;
1586 GSN_database->iterate_records (GSN_database->cls, zone , NULL, proc->zi->offset, &zone_iteraterate_proc, proc);
1589 while ((proc->records_included == 0) && (GNUNET_NO == proc->res_iteration_finished));
1593 void send_zone_iteration_result (struct ZoneIterationProcResult *proc)
1595 struct GNUNET_NAMESTORE_ZoneIteration *zi = proc->zi;
1597 if (GNUNET_YES == proc->res_iteration_finished)
1599 struct ZoneIterationResponseMessage zir_msg;
1600 if (zi->has_zone == GNUNET_YES)
1601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for zone `%s'\n", GNUNET_short_h2s(&zi->zone));
1603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for all zones\n");
1605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending empty `%s' message\n", "ZONE_ITERATION_RESPONSE");
1606 zir_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE);
1607 zir_msg.gns_header.header.size = htons (sizeof (struct ZoneIterationResponseMessage));
1608 zir_msg.gns_header.r_id = htonl(zi->request_id);
1609 zir_msg.expire = GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_zero());
1610 zir_msg.name_len = htons (0);
1611 zir_msg.reserved = htons (0);
1612 zir_msg.rd_count = htons (0);
1613 zir_msg.rd_len = htons (0);
1614 memset (&zir_msg.public_key, '\0', sizeof (zir_msg.public_key));
1615 memset (&zir_msg.signature, '\0', sizeof (zir_msg.signature));
1616 GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, (const struct GNUNET_MessageHeader *) &zir_msg, GNUNET_NO);
1618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing zone iterator\n");
1619 GNUNET_CONTAINER_DLL_remove (zi->client->op_head, zi->client->op_tail, zi);
1625 GNUNET_assert (proc->records_included > 0);
1627 struct ZoneIterationResponseMessage *zir_msg;
1628 if (zi->has_zone == GNUNET_YES)
1629 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iteration over zone `%s'\n",
1630 proc->name, GNUNET_short_h2s(&zi->zone));
1631 if (zi->has_zone == GNUNET_NO)
1632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iteration over all zones\n",
1640 name_len = strlen (proc->name) +1;
1642 rd_ser_len = GNUNET_NAMESTORE_records_get_size(proc->records_included, proc->rd);
1643 char rd_ser[rd_ser_len];
1644 GNUNET_NAMESTORE_records_serialize(proc->records_included, proc->rd, rd_ser_len, rd_ser);
1645 msg_size = sizeof (struct ZoneIterationResponseMessage) + name_len + rd_ser_len;
1646 zir_msg = GNUNET_malloc(msg_size);
1648 name_tmp = (char *) &zir_msg[1];
1649 rd_tmp = &name_tmp[name_len];
1651 zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE);
1652 zir_msg->gns_header.header.size = htons (msg_size);
1653 zir_msg->gns_header.r_id = htonl(zi->request_id);
1654 zir_msg->expire = GNUNET_TIME_absolute_hton(proc->expire);
1655 zir_msg->reserved = htons (0);
1656 zir_msg->name_len = htons (name_len);
1657 zir_msg->rd_count = htons (proc->records_included);
1658 zir_msg->rd_len = htons (rd_ser_len);
1659 zir_msg->signature = proc->signature;
1660 zir_msg->public_key = proc->zone_key;
1661 memcpy (name_tmp, proc->name, name_len);
1662 memcpy (rd_tmp, rd_ser, rd_ser_len);
1664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with size %u\n", "ZONE_ITERATION_RESPONSE", msg_size);
1665 GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, (const struct GNUNET_MessageHeader *) zir_msg, GNUNET_NO);
1666 GNUNET_free (zir_msg);
1670 void clean_up_zone_iteration_result (struct ZoneIterationProcResult *proc)
1673 GNUNET_free_non_null (proc->name);
1674 for (c = 0; c < proc->records_included; c++)
1676 GNUNET_free ((void *) proc->rd[c].data);
1678 GNUNET_free_non_null (proc->rd);
1683 static void handle_iteration_start (void *cls,
1684 struct GNUNET_SERVER_Client * client,
1685 const struct GNUNET_MessageHeader * message)
1687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_START");
1689 struct ZoneIterationStartMessage * zis_msg = (struct ZoneIterationStartMessage *) message;
1690 struct GNUNET_NAMESTORE_Client *nc;
1691 struct GNUNET_NAMESTORE_ZoneIteration *zi;
1693 nc = client_lookup(client);
1696 GNUNET_break_op (0);
1697 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1701 zi = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_ZoneIteration));
1702 zi->request_id = ntohl (zis_msg->gns_header.r_id);
1705 zi->zone = zis_msg->zone;
1706 zi->must_have_flags = ntohs (zis_msg->must_have_flags);
1707 zi->must_not_have_flags = ntohs (zis_msg->must_not_have_flags);
1709 struct GNUNET_CRYPTO_ShortHashCode dummy;
1710 struct GNUNET_CRYPTO_ShortHashCode *zone_tmp;
1711 memset (&dummy, '\0', sizeof (dummy));
1712 if (0 == memcmp (&dummy, &zis_msg->zone, sizeof (dummy)))
1714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over all zones\n");
1715 zi->has_zone = GNUNET_NO;
1720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over zone `%s'\n", GNUNET_short_h2s (&zis_msg->zone));
1721 zi->has_zone = GNUNET_YES;
1722 zone_tmp = &zis_msg->zone;
1725 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi);
1727 struct ZoneIterationProcResult proc;
1730 find_next_zone_iteration_result (&proc);
1731 if (GNUNET_YES == proc.res_iteration_finished)
1733 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration done\n");
1735 else if (proc.records_included != 0)
1737 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration return %u records\n", proc.records_included);
1739 send_zone_iteration_result (&proc);
1740 clean_up_zone_iteration_result (&proc);
1742 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1745 static void handle_iteration_stop (void *cls,
1746 struct GNUNET_SERVER_Client * client,
1747 const struct GNUNET_MessageHeader * message)
1749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_STOP");
1751 struct GNUNET_NAMESTORE_Client *nc;
1752 struct GNUNET_NAMESTORE_ZoneIteration *zi;
1753 struct ZoneIterationStopMessage * zis_msg = (struct ZoneIterationStopMessage *) message;
1756 nc = client_lookup(client);
1759 GNUNET_break_op (0);
1760 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1764 rid = ntohl (zis_msg->gns_header.r_id);
1765 for (zi = nc->op_head; zi != NULL; zi = zi->next)
1767 if (zi->request_id == rid)
1772 GNUNET_break_op (0);
1773 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1777 GNUNET_CONTAINER_DLL_remove(nc->op_head, nc->op_tail, zi);
1778 if (GNUNET_YES == zi->has_zone)
1779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration for zone `%s'\n", GNUNET_short_h2s (&zi->zone));
1781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration all zones\n");
1784 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1787 static void handle_iteration_next (void *cls,
1788 struct GNUNET_SERVER_Client * client,
1789 const struct GNUNET_MessageHeader * message)
1791 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_NEXT");
1793 struct GNUNET_NAMESTORE_Client *nc;
1794 struct GNUNET_NAMESTORE_ZoneIteration *zi;
1795 struct GNUNET_CRYPTO_ShortHashCode *zone_tmp;
1796 struct ZoneIterationStopMessage * zis_msg = (struct ZoneIterationStopMessage *) message;
1799 nc = client_lookup(client);
1802 GNUNET_break_op (0);
1803 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1807 rid = ntohl (zis_msg->gns_header.r_id);
1808 for (zi = nc->op_head; zi != NULL; zi = zi->next)
1810 if (zi->request_id == rid)
1815 GNUNET_break_op (0);
1816 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1820 if (GNUNET_YES == zi->has_zone)
1821 zone_tmp = &zi->zone;
1826 struct ZoneIterationProcResult proc;
1829 find_next_zone_iteration_result (&proc);
1830 if (GNUNET_YES == proc.res_iteration_finished)
1832 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration done\n");
1834 else if (proc.records_included != 0)
1836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration return %u records\n", proc.records_included);
1838 send_zone_iteration_result (&proc);
1839 clean_up_zone_iteration_result (&proc);
1841 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1844 int zonekey_file_it (void *cls, const char *filename)
1846 GNUNET_HashCode long_hash;
1848 if ((filename != NULL) && (NULL != strstr(filename, ".zkey")))
1850 struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
1851 struct GNUNET_NAMESTORE_CryptoContainer *c;
1852 privkey = GNUNET_CRYPTO_rsa_key_create_from_file(filename);
1853 if (privkey == NULL)
1856 c = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer));
1857 c->pubkey = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
1858 c->privkey = privkey;
1859 GNUNET_CRYPTO_rsa_key_get_public(privkey, c->pubkey);
1860 GNUNET_CRYPTO_short_hash(c->pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &c->zone);
1862 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found zonefile for zone `%s'\n", GNUNET_short_h2s (&c->zone));
1863 GNUNET_CRYPTO_short_hash_double (&c->zone, &long_hash);
1864 GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, c, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1872 * Process template requests.
1874 * @param cls closure
1875 * @param server the initialized server
1876 * @param cfg configuration to use
1879 run (void *cls, struct GNUNET_SERVER_Handle *server,
1880 const struct GNUNET_CONFIGURATION_Handle *cfg)
1884 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n");
1886 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1887 {&handle_start, NULL,
1888 GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)},
1889 {&handle_lookup_name, NULL,
1890 GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, 0},
1891 {&handle_record_put, NULL,
1892 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT, 0},
1893 {&handle_record_create, NULL,
1894 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE, 0},
1895 {&handle_record_remove, NULL,
1896 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE, 0},
1897 {&handle_zone_to_name, NULL,
1898 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, 0},
1899 {&handle_iteration_start, NULL,
1900 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct ZoneIterationStartMessage)},
1901 {&handle_iteration_next, NULL,
1902 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT, 0},
1903 {&handle_iteration_stop, NULL,
1904 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, 0},
1910 /* Load private keys from disk */
1912 GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore", "zonefile_directory",
1913 &zonefile_directory))
1915 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("No directory to load zonefiles specified in configuration\n"));
1916 GNUNET_SCHEDULER_add_now (&cleanup_task, NULL);
1920 if (GNUNET_NO == GNUNET_DISK_file_test (zonefile_directory))
1922 if (GNUNET_SYSERR == GNUNET_DISK_directory_create (zonefile_directory))
1924 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Creating directory `%s' for zone files failed!\n"), zonefile_directory);
1925 GNUNET_SCHEDULER_add_now (&cleanup_task, NULL);
1928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created directory `%s' for zone files\n", zonefile_directory);
1931 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scanning directory `%s' for zone files\n", zonefile_directory);
1932 zonekeys = GNUNET_CONTAINER_multihashmap_create (10);
1933 GNUNET_DISK_directory_scan (zonefile_directory, zonekey_file_it, &counter);
1934 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u zone files\n", counter);
1936 /* Loading database plugin */
1938 GNUNET_CONFIGURATION_get_value_string (cfg, "namestore", "database",
1940 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n");
1942 GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database);
1943 GSN_database = GNUNET_PLUGIN_load (db_lib_name, (void *) GSN_cfg);
1944 GNUNET_free (database);
1945 if (GSN_database == NULL)
1947 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not load database backend `%s'\n",
1949 GNUNET_SCHEDULER_add_now (&cleanup_task, NULL);
1953 /* Configuring server handles */
1954 GNUNET_SERVER_add_handlers (server, handlers);
1955 snc = GNUNET_SERVER_notification_context_create (server, 16);
1956 GNUNET_SERVER_disconnect_notify (server,
1957 &client_disconnect_notification,
1960 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
1967 * The main function for the template service.
1969 * @param argc number of arguments from the command line
1970 * @param argv command line arguments
1971 * @return 0 ok, 1 on error
1974 main (int argc, char *const *argv)
1976 return (GNUNET_OK ==
1977 GNUNET_SERVICE_run (argc, argv, "namestore",
1978 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
1981 /* end of gnunet-service-namestore.c */