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 "namestore.h"
36 * A namestore operation.
38 struct GNUNET_NAMESTORE_ZoneIteration
40 struct GNUNET_NAMESTORE_ZoneIteration *next;
41 struct GNUNET_NAMESTORE_ZoneIteration *prev;
43 struct GNUNET_NAMESTORE_Client * client;
56 struct GNUNET_NAMESTORE_Client
58 struct GNUNET_NAMESTORE_Client *next;
59 struct GNUNET_NAMESTORE_Client *prev;
61 struct GNUNET_SERVER_Client * client;
63 struct GNUNET_NAMESTORE_ZoneIteration *op_head;
64 struct GNUNET_NAMESTORE_ZoneIteration *op_tail;
70 * Configuration handle.
72 const struct GNUNET_CONFIGURATION_Handle *GSN_cfg;
74 static struct GNUNET_NAMESTORE_PluginFunctions *GSN_database;
77 * Our notification context.
79 static struct GNUNET_SERVER_NotificationContext *snc;
81 static char *db_lib_name;
83 static struct GNUNET_NAMESTORE_Client *client_head;
84 static struct GNUNET_NAMESTORE_Client *client_tail;
88 * Task run during shutdown.
94 cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
96 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n");
98 struct GNUNET_NAMESTORE_ZoneIteration * no;
99 struct GNUNET_NAMESTORE_ZoneIteration * tmp;
100 struct GNUNET_NAMESTORE_Client * nc;
101 struct GNUNET_NAMESTORE_Client * next;
103 for (nc = client_head; nc != NULL; nc = next)
106 for (no = nc->op_head; no != NULL; no = tmp)
108 GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no);
113 GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc);
118 GNUNET_SERVER_notification_context_destroy (snc);
121 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database));
122 GNUNET_free (db_lib_name);
125 static struct GNUNET_NAMESTORE_Client *
126 client_lookup (struct GNUNET_SERVER_Client *client)
128 struct GNUNET_NAMESTORE_Client * nc;
130 GNUNET_assert (NULL != client);
132 for (nc = client_head; nc != NULL; nc = nc->next)
134 if (client == nc->client)
142 * Called whenever a client is disconnected. Frees our
143 * resources associated with that client.
146 * @param client identification of the client
149 client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
151 struct GNUNET_NAMESTORE_ZoneIteration * no;
152 struct GNUNET_NAMESTORE_Client * nc;
156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected \n", client);
158 nc = client_lookup (client);
160 if ((NULL == client) || (NULL == nc))
163 for (no = nc->op_head; no != NULL; no = no->next)
165 GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no);
169 GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc);
173 static void handle_start (void *cls,
174 struct GNUNET_SERVER_Client * client,
175 const struct GNUNET_MessageHeader * message)
177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client);
179 struct GNUNET_NAMESTORE_Client * nc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Client));
181 GNUNET_SERVER_notification_context_add (snc, client);
182 GNUNET_CONTAINER_DLL_insert(client_head, client_tail, nc);
184 GNUNET_SERVER_receive_done (client, GNUNET_OK);
187 struct LookupNameContext
189 struct GNUNET_NAMESTORE_Client *nc;
191 uint32_t record_type;
198 handle_lookup_name_it (void *cls,
199 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
200 struct GNUNET_TIME_Absolute expire,
202 unsigned int rd_count,
203 const struct GNUNET_NAMESTORE_RecordData *rd,
204 const struct GNUNET_CRYPTO_RsaSignature *signature)
207 struct LookupNameContext *lnc = cls;
208 struct LookupNameResponseMessage *lnr_msg;
210 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key_tmp;
211 struct GNUNET_NAMESTORE_RecordData * rd_tmp;
213 struct GNUNET_CRYPTO_RsaSignature *signature_tmp;
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "NAMESTORE_LOOKUP_NAME_RESPONSE");
221 name_len = strlen(name) + 1;
223 int copied_elements = 0;
224 int contains_signature = 0;
227 /* count records to copy */
230 if (lnc->record_type != 0)
232 /* special record type needed */
233 for (c = 0; c < rd_count; c ++)
234 if (rd[c].record_type == lnc->record_type)
235 copied_elements++; /* found matching record */
238 copied_elements = rd_count;
241 if ((copied_elements == rd_count) && (signature != NULL))
242 contains_signature = GNUNET_YES;
244 r_size = sizeof (struct LookupNameResponseMessage) +
245 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
247 copied_elements * sizeof (struct GNUNET_NAMESTORE_RecordData) +
248 contains_signature * sizeof (struct GNUNET_CRYPTO_RsaSignature);
250 lnr_msg = GNUNET_malloc (r_size);
252 lnr_msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE);
253 lnr_msg->header.size = ntohs (r_size);
254 lnr_msg->op_id = htonl (lnc->id);
255 lnr_msg->rc_count = htonl (copied_elements);
256 lnr_msg->name_len = htons (name_len);
257 lnr_msg->expire = GNUNET_TIME_absolute_hton(expire);
258 lnr_msg->contains_sig = htons (contains_signature);
261 zone_key_tmp = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &lnr_msg[1];
262 name_tmp = (char *) &zone_key_tmp[1];
263 rd_tmp = (struct GNUNET_NAMESTORE_RecordData *) &name_tmp[name_len];
264 signature_tmp = (struct GNUNET_CRYPTO_RsaSignature *) &rd_tmp[copied_elements];
266 if (zone_key != NULL)
267 memcpy (zone_key_tmp, zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
270 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded dummy;
271 memset (&dummy, '0', sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
272 memcpy (zone_key_tmp, &dummy, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
274 memcpy (name_tmp, name, name_len);
279 if (lnc->record_type != 0)
281 /* special record type needed */
282 for (c = 0; c < rd_count; c ++)
283 if (rd[c].record_type == lnc->record_type)
285 /* found matching record */
286 memcpy (&rd_tmp[copied_elements], &rd[c], rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
291 memcpy (rd_tmp, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
294 if (GNUNET_YES == contains_signature)
295 memcpy (signature_tmp, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature));
296 GNUNET_SERVER_notification_context_unicast (snc, lnc->nc->client, (const struct GNUNET_MessageHeader *) lnr_msg, GNUNET_NO);
298 GNUNET_free (lnr_msg);
301 static void handle_lookup_name (void *cls,
302 struct GNUNET_SERVER_Client * client,
303 const struct GNUNET_MessageHeader * message)
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_LOOKUP_NAME");
306 struct LookupNameContext lnc;
307 struct GNUNET_NAMESTORE_Client *nc;
308 GNUNET_HashCode name_hash;
315 if (ntohs (message->size) < sizeof (struct LookupNameMessage))
318 GNUNET_SERVER_receive_done (client, GNUNET_OK);
322 nc = client_lookup(client);
326 GNUNET_SERVER_receive_done (client, GNUNET_OK);
330 struct LookupNameMessage * ln_msg = (struct LookupNameMessage *) message;
331 id = ntohl (ln_msg->op_id);
332 name_len = ntohl (ln_msg->name_len);
333 type = ntohl (ln_msg->record_type);
335 if ((name_len == 0) || (name_len > 256))
338 GNUNET_SERVER_receive_done (client, GNUNET_OK);
342 name = GNUNET_malloc (name_len);
343 memcpy (name, &ln_msg[1], name_len);
344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up record for name `%s'\n", name);
345 GNUNET_CRYPTO_hash(name, name_len-1, &name_hash);
348 /* do the actual lookup */
351 lnc.record_type = type;
352 GSN_database->iterate_records(GSN_database->cls, &ln_msg->zone, &ln_msg->zone, 0, &handle_lookup_name_it, &lnc);
354 GNUNET_SERVER_receive_done (client, GNUNET_OK);
357 static void handle_record_put (void *cls,
358 struct GNUNET_SERVER_Client * client,
359 const struct GNUNET_MessageHeader * message)
361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_PUT");
362 struct GNUNET_NAMESTORE_Client *nc;
363 struct GNUNET_TIME_Absolute expire;
364 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key;
365 struct GNUNET_NAMESTORE_RecordData *rd;
366 struct GNUNET_CRYPTO_RsaSignature *signature;
367 struct RecordPutResponseMessage rpr_msg;
376 int res = GNUNET_SYSERR;
378 if (ntohs (message->size) < sizeof (struct RecordPutMessage))
381 GNUNET_SERVER_receive_done (client, GNUNET_OK);
385 nc = client_lookup (client);
389 GNUNET_SERVER_receive_done (client, GNUNET_OK);
393 struct RecordPutMessage * rp_msg = (struct RecordPutMessage *) message;
394 id = ntohl (rp_msg->op_id);
395 name_len = ntohs (rp_msg->name_len);
396 rd_ser_len = ntohs(rp_msg->rd_len);
397 msg_size = ntohs (message->size);
398 msg_size_exp = sizeof (struct RecordPutMessage) + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + name_len + rd_ser_len;
400 if (msg_size != msg_size_exp)
402 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size);
404 GNUNET_SERVER_receive_done (client, GNUNET_OK);
409 if ((name_len == 0) || (name_len > 256))
412 GNUNET_SERVER_receive_done (client, GNUNET_OK);
416 zone_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &rp_msg[1];
417 name = (char *) &zone_key[1];
418 expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire);
419 signature = (struct GNUNET_CRYPTO_RsaSignature *) &rp_msg->signature;
420 rd_ser = &name[name_len];
421 rd_count = GNUNET_NAMESTORE_records_deserialize(&rd, rd_ser, rd_ser_len);
423 /* Database operation */
424 res = GSN_database->put_records(GSN_database->cls,
431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting record for name `%s': %s\n",
432 name, (res == GNUNET_OK) ? "OK" : "FAIL");
436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_PUT_RESPONSE");
437 rpr_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE);
438 rpr_msg.op_id = rp_msg->op_id;
439 rpr_msg.header.size = htons (sizeof (struct RecordPutResponseMessage));
440 if (GNUNET_OK == res)
441 rpr_msg.op_result = htons (GNUNET_OK);
443 rpr_msg.op_result = htons (GNUNET_NO);
444 GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rpr_msg, GNUNET_NO);
446 GNUNET_SERVER_receive_done (client, GNUNET_OK);
450 static void handle_record_create (void *cls,
451 struct GNUNET_SERVER_Client * client,
452 const struct GNUNET_MessageHeader * message)
454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_CREATE");
455 struct GNUNET_NAMESTORE_Client *nc;
456 struct RecordCreateResponseMessage rcr_msg;
462 int res = GNUNET_SYSERR;
464 if (ntohs (message->size) < sizeof (struct RecordCreateMessage))
467 GNUNET_SERVER_receive_done (client, GNUNET_OK);
471 nc = client_lookup(client);
475 GNUNET_SERVER_receive_done (client, GNUNET_OK);
479 struct RecordCreateMessage * rp_msg = (struct RecordCreateMessage *) message;
480 id = ntohl (rp_msg->op_id);
481 name_len = ntohs (rp_msg->name_len);
482 msg_size = ntohs (message->size);
483 msg_size_exp = sizeof (struct RecordCreateMessage) + name_len + sizeof (struct GNUNET_NAMESTORE_RecordData);
485 if (msg_size != msg_size_exp)
487 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size);
489 GNUNET_SERVER_receive_done (client, GNUNET_OK);
494 if ((name_len == 0) || (name_len > 256))
497 GNUNET_SERVER_receive_done (client, GNUNET_OK);
505 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_CREATE_RESPONSE");
506 rcr_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE);
507 rcr_msg.op_id = rp_msg->op_id;
508 rcr_msg.header.size = htons (sizeof (struct RecordCreateResponseMessage));
509 if (GNUNET_OK == res)
510 rcr_msg.op_result = htons (GNUNET_OK);
512 rcr_msg.op_result = htons (GNUNET_NO);
513 GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rcr_msg, GNUNET_NO);
515 GNUNET_SERVER_receive_done (client, GNUNET_OK);
518 static void handle_record_remove (void *cls,
519 struct GNUNET_SERVER_Client * client,
520 const struct GNUNET_MessageHeader * message)
522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_REMOVE");
523 struct GNUNET_NAMESTORE_Client *nc;
524 struct RecordRemoveResponseMessage rrr_msg;
530 int res = GNUNET_SYSERR;
532 if (ntohs (message->size) < sizeof (struct RecordRemoveMessage))
535 GNUNET_SERVER_receive_done (client, GNUNET_OK);
539 nc = client_lookup(client);
543 GNUNET_SERVER_receive_done (client, GNUNET_OK);
547 struct RecordRemoveMessage * rp_msg = (struct RecordRemoveMessage *) message;
548 id = ntohl (rp_msg->op_id);
549 name_len = ntohs (rp_msg->name_len);
550 msg_size = ntohs (message->size);
551 msg_size_exp = sizeof (struct RecordRemoveMessage) + name_len + sizeof (struct GNUNET_NAMESTORE_RecordData);
553 if (msg_size != msg_size_exp)
555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size);
557 GNUNET_SERVER_receive_done (client, GNUNET_OK);
562 if ((name_len == 0) || (name_len > 256))
565 GNUNET_SERVER_receive_done (client, GNUNET_OK);
573 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_REMOVE_RESPONSE");
574 rrr_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE);
575 rrr_msg.op_id = rp_msg->op_id;
576 rrr_msg.header.size = htons (sizeof (struct RecordRemoveResponseMessage));
577 if (GNUNET_OK == res)
578 rrr_msg.op_result = htons (GNUNET_OK);
580 rrr_msg.op_result = htons (GNUNET_NO);
581 GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rrr_msg, GNUNET_NO);
583 GNUNET_SERVER_receive_done (client, GNUNET_OK);
586 struct ZoneIterationProcResult
589 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key;
592 struct GNUNET_CRYPTO_RsaSignature signature;
593 struct GNUNET_TIME_Absolute expire;
598 unsigned int rd_count;
603 void zone_iteration_proc (void *cls,
604 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
605 struct GNUNET_TIME_Absolute expire,
607 unsigned int rd_count,
608 const struct GNUNET_NAMESTORE_RecordData *rd,
609 const struct GNUNET_CRYPTO_RsaSignature *signature)
611 struct ZoneIterationProcResult *zipr = cls;
613 if (zone_key != NULL)
615 zipr->zone_key = *zone_key;
616 zipr->have_zone_key = GNUNET_YES;
619 zipr->have_zone_key = GNUNET_NO;
621 zipr->expire = expire;
625 memcpy (zipr->name, name, strlen(name) + 1);
626 zipr->have_name = GNUNET_YES;
629 zipr->have_name = GNUNET_NO;
631 zipr->rd_count = rd_count;
633 if (signature != NULL)
635 zipr->signature = *signature;
636 zipr->have_signature = GNUNET_YES;
639 zipr->have_signature = GNUNET_NO;
641 if ((rd_count > 0) && (rd != NULL))
643 len = GNUNET_NAMESTORE_records_serialize (&zipr->rd_ser, rd_count, rd);
647 static void handle_iteration_start (void *cls,
648 struct GNUNET_SERVER_Client * client,
649 const struct GNUNET_MessageHeader * message)
651 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_START");
653 struct ZoneIterationStartMessage * zis_msg = (struct ZoneIterationStartMessage *) message;
654 struct GNUNET_NAMESTORE_Client *nc;
655 struct GNUNET_NAMESTORE_ZoneIteration *zi;
656 struct ZoneIterationResponseMessage zir_msg;
657 struct ZoneIterationProcResult zipr;
660 nc = client_lookup(client);
664 GNUNET_SERVER_receive_done (client, GNUNET_OK);
668 zi = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_ZoneIteration));
669 zi->op_id = ntohl (zis_msg->op_id);
672 zi->zone = zis_msg->zone;
674 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi);
676 res = GSN_database->iterate_records (GSN_database->cls, &zis_msg->zone, NULL, zi->offset , &zone_iteration_proc, &zipr);
678 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "ZONE_ITERATION_RESPONSE");
679 zir_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE);
680 zir_msg.op_id = htonl(zi->op_id);
681 zir_msg.header.size = htons (sizeof (struct ZoneIterationResponseMessage));
683 GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, (const struct GNUNET_MessageHeader *) &zir_msg, GNUNET_NO);
686 GNUNET_SERVER_receive_done (client, GNUNET_OK);
689 static void handle_iteration_stop (void *cls,
690 struct GNUNET_SERVER_Client * client,
691 const struct GNUNET_MessageHeader * message)
693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_STOP");
695 struct GNUNET_NAMESTORE_Client *nc;
696 struct GNUNET_NAMESTORE_ZoneIteration *zi;
697 struct ZoneIterationStopMessage * zis_msg = (struct ZoneIterationStopMessage *) message;
700 nc = client_lookup(client);
704 GNUNET_SERVER_receive_done (client, GNUNET_OK);
708 id = ntohl (zis_msg->op_id);
709 for (zi = nc->op_head; zi != NULL; zi = zi->next)
717 GNUNET_SERVER_receive_done (client, GNUNET_OK);
721 GNUNET_CONTAINER_DLL_remove(nc->op_head, nc->op_tail, zi);
722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration for zone `%s'\n", GNUNET_h2s (&zi->zone));
725 GNUNET_SERVER_receive_done (client, GNUNET_OK);
728 static void handle_iteration_next (void *cls,
729 struct GNUNET_SERVER_Client * client,
730 const struct GNUNET_MessageHeader * message)
732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_NEXT");
734 struct GNUNET_NAMESTORE_Client *nc;
735 struct GNUNET_NAMESTORE_ZoneIteration *zi;
736 struct ZoneIterationStopMessage * zis_msg = (struct ZoneIterationStopMessage *) message;
740 nc = client_lookup(client);
744 GNUNET_SERVER_receive_done (client, GNUNET_OK);
748 id = ntohl (zis_msg->op_id);
749 for (zi = nc->op_head; zi != NULL; zi = zi->next)
757 GNUNET_SERVER_receive_done (client, GNUNET_OK);
762 res = GSN_database->iterate_records (GSN_database->cls, &zi->zone, NULL, zi->offset , &zone_iteration_proc, zi);
768 * Process template requests.
771 * @param server the initialized server
772 * @param cfg configuration to use
775 run (void *cls, struct GNUNET_SERVER_Handle *server,
776 const struct GNUNET_CONFIGURATION_Handle *cfg)
780 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n");
782 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
783 {&handle_start, NULL,
784 GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)},
785 {&handle_lookup_name, NULL,
786 GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, 0},
787 {&handle_record_put, NULL,
788 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT, 0},
789 {&handle_record_create, NULL,
790 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE, 0},
791 {&handle_record_remove, NULL,
792 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE, 0},
793 {&handle_iteration_start, NULL,
794 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct ZoneIterationStartMessage)},
795 {&handle_iteration_stop, NULL,
796 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, sizeof (struct ZoneIterationStopMessage)},
797 {&handle_iteration_next, NULL,
798 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT, 0},
804 /* Loading database plugin */
806 GNUNET_CONFIGURATION_get_value_string (cfg, "namestore", "database",
808 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n");
810 GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database);
811 GSN_database = GNUNET_PLUGIN_load (db_lib_name, (void *) GSN_cfg);
812 if (GSN_database == NULL)
813 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not load database backend `%s'\n",
815 GNUNET_free (database);
817 /* Configuring server handles */
818 GNUNET_SERVER_add_handlers (server, handlers);
819 snc = GNUNET_SERVER_notification_context_create (server, 16);
820 GNUNET_SERVER_disconnect_notify (server,
821 &client_disconnect_notification,
824 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
831 * The main function for the template service.
833 * @param argc number of arguments from the command line
834 * @param argv command line arguments
835 * @return 0 ok, 1 on error
838 main (int argc, char *const *argv)
841 GNUNET_SERVICE_run (argc, argv, "namestore",
842 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
845 /* end of gnunet-service-namestore.c */