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;
196 handle_lookup_name_it (void *cls,
197 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
198 struct GNUNET_TIME_Absolute expire,
200 unsigned int rd_count,
201 const struct GNUNET_NAMESTORE_RecordData *rd,
202 const struct GNUNET_CRYPTO_RsaSignature *signature)
205 struct LookupNameContext *lnc = cls;
206 struct LookupNameResponseMessage *lnr_msg;
208 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key_tmp;
209 struct GNUNET_NAMESTORE_RecordData * rd_tmp;
211 struct GNUNET_CRYPTO_RsaSignature *signature_tmp;
213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "NAMESTORE_LOOKUP_NAME_RESPONSE");
219 name_len = strlen(name) + 1;
221 int copied_elements = 0;
222 int contains_signature = 0;
225 /* count records to copy */
228 if (lnc->record_type != 0)
230 /* special record type needed */
231 for (c = 0; c < rd_count; c ++)
232 if (rd[c].record_type == lnc->record_type)
233 copied_elements++; /* found matching record */
236 copied_elements = rd_count;
239 if ((copied_elements == rd_count) && (signature != NULL))
240 contains_signature = GNUNET_YES;
242 r_size = sizeof (struct LookupNameResponseMessage) +
243 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
245 copied_elements * sizeof (struct GNUNET_NAMESTORE_RecordData) +
246 contains_signature * sizeof (struct GNUNET_CRYPTO_RsaSignature);
248 lnr_msg = GNUNET_malloc (r_size);
250 lnr_msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE);
251 lnr_msg->header.size = ntohs (r_size);
252 lnr_msg->op_id = htonl (lnc->id);
253 lnr_msg->rc_count = htonl (copied_elements);
254 lnr_msg->name_len = htons (name_len);
255 lnr_msg->expire = GNUNET_TIME_absolute_hton(expire);
256 lnr_msg->contains_sig = htons (contains_signature);
259 zone_key_tmp = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &lnr_msg[1];
260 name_tmp = (char *) &zone_key_tmp[1];
261 rd_tmp = (struct GNUNET_NAMESTORE_RecordData *) &name_tmp[name_len];
262 signature_tmp = (struct GNUNET_CRYPTO_RsaSignature *) &rd_tmp[copied_elements];
264 if (zone_key != NULL)
265 memcpy (zone_key_tmp, zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
268 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded dummy;
269 memset (&dummy, '0', sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
270 memcpy (zone_key_tmp, &dummy, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
272 memcpy (name_tmp, name, name_len);
277 if (lnc->record_type != 0)
279 /* special record type needed */
280 for (c = 0; c < rd_count; c ++)
281 if (rd[c].record_type == lnc->record_type)
283 /* found matching record */
284 memcpy (&rd_tmp[copied_elements], &rd[c], rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
289 memcpy (rd_tmp, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
292 if (GNUNET_YES == contains_signature)
293 memcpy (signature_tmp, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature));
294 GNUNET_SERVER_notification_context_unicast (snc, lnc->nc->client, (const struct GNUNET_MessageHeader *) lnr_msg, GNUNET_NO);
296 GNUNET_free (lnr_msg);
299 static void handle_lookup_name (void *cls,
300 struct GNUNET_SERVER_Client * client,
301 const struct GNUNET_MessageHeader * message)
303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_LOOKUP_NAME");
304 struct LookupNameContext lnc;
305 struct GNUNET_NAMESTORE_Client *nc;
306 GNUNET_HashCode name_hash;
313 if (ntohs (message->size) < sizeof (struct LookupNameMessage))
316 GNUNET_SERVER_receive_done (client, GNUNET_OK);
320 nc = client_lookup(client);
324 GNUNET_SERVER_receive_done (client, GNUNET_OK);
328 struct LookupNameMessage * ln_msg = (struct LookupNameMessage *) message;
329 id = ntohl (ln_msg->op_id);
330 name_len = ntohl (ln_msg->name_len);
331 type = ntohl (ln_msg->record_type);
333 if ((name_len == 0) || (name_len > 256))
336 GNUNET_SERVER_receive_done (client, GNUNET_OK);
340 name = GNUNET_malloc (name_len);
341 memcpy (name, &ln_msg[1], name_len);
342 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up record for name `%s'\n", name);
343 GNUNET_CRYPTO_hash(name, name_len-1, &name_hash);
346 /* do the actual lookup */
349 lnc.record_type = type;
350 GSN_database->iterate_records(GSN_database->cls, &ln_msg->zone, &ln_msg->zone, 0, &handle_lookup_name_it, &lnc);
352 GNUNET_SERVER_receive_done (client, GNUNET_OK);
355 static void handle_record_put (void *cls,
356 struct GNUNET_SERVER_Client * client,
357 const struct GNUNET_MessageHeader * message)
359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_PUT");
360 struct GNUNET_NAMESTORE_Client *nc;
361 struct GNUNET_TIME_Absolute expire;
362 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key;
363 struct GNUNET_NAMESTORE_RecordData *rd;
364 struct GNUNET_CRYPTO_RsaSignature *signature;
365 struct RecordPutResponseMessage rpr_msg;
372 int res = GNUNET_SYSERR;
374 if (ntohs (message->size) < sizeof (struct RecordPutMessage))
377 GNUNET_SERVER_receive_done (client, GNUNET_OK);
381 nc = client_lookup (client);
385 GNUNET_SERVER_receive_done (client, GNUNET_OK);
389 struct RecordPutMessage * rp_msg = (struct RecordPutMessage *) message;
390 id = ntohl (rp_msg->op_id);
391 name_len = ntohs (rp_msg->name_len);
392 rd_count = ntohl(rp_msg->rd_count);
393 msg_size = ntohs (message->size);
394 msg_size_exp = sizeof (struct RecordPutMessage) + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + name_len + rd_count * (sizeof (struct GNUNET_NAMESTORE_RecordData));
396 if (msg_size != msg_size_exp)
398 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size);
400 GNUNET_SERVER_receive_done (client, GNUNET_OK);
405 if ((name_len == 0) || (name_len > 256))
408 GNUNET_SERVER_receive_done (client, GNUNET_OK);
412 zone_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &rp_msg[1];
413 name = (char *) &zone_key[1];
414 expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire);
415 signature = (struct GNUNET_CRYPTO_RsaSignature *) &rp_msg->signature;
416 rd = (struct GNUNET_NAMESTORE_RecordData *) &name[name_len];
418 /* Database operation */
419 res = GSN_database->put_records(GSN_database->cls,
426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting record for name `%s': %s\n",
427 name, (res == GNUNET_OK) ? "OK" : "FAIL");
431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_PUT_RESPONSE");
432 rpr_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE);
433 rpr_msg.op_id = rp_msg->op_id;
434 rpr_msg.header.size = htons (sizeof (struct RecordPutResponseMessage));
435 if (GNUNET_OK == res)
436 rpr_msg.op_result = htons (GNUNET_OK);
438 rpr_msg.op_result = htons (GNUNET_NO);
439 GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rpr_msg, GNUNET_NO);
441 GNUNET_SERVER_receive_done (client, GNUNET_OK);
445 static void handle_record_create (void *cls,
446 struct GNUNET_SERVER_Client * client,
447 const struct GNUNET_MessageHeader * message)
449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_CREATE");
450 struct GNUNET_NAMESTORE_Client *nc;
451 struct RecordCreateResponseMessage rcr_msg;
457 int res = GNUNET_SYSERR;
459 if (ntohs (message->size) < sizeof (struct RecordCreateMessage))
462 GNUNET_SERVER_receive_done (client, GNUNET_OK);
466 nc = client_lookup(client);
470 GNUNET_SERVER_receive_done (client, GNUNET_OK);
474 struct RecordCreateMessage * rp_msg = (struct RecordCreateMessage *) message;
475 id = ntohl (rp_msg->op_id);
476 name_len = ntohs (rp_msg->name_len);
477 msg_size = ntohs (message->size);
478 msg_size_exp = sizeof (struct RecordCreateMessage) + name_len + sizeof (struct GNUNET_NAMESTORE_RecordData);
480 if (msg_size != msg_size_exp)
482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size);
484 GNUNET_SERVER_receive_done (client, GNUNET_OK);
489 if ((name_len == 0) || (name_len > 256))
492 GNUNET_SERVER_receive_done (client, GNUNET_OK);
500 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_CREATE_RESPONSE");
501 rcr_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE);
502 rcr_msg.op_id = rp_msg->op_id;
503 rcr_msg.header.size = htons (sizeof (struct RecordCreateResponseMessage));
504 if (GNUNET_OK == res)
505 rcr_msg.op_result = htons (GNUNET_OK);
507 rcr_msg.op_result = htons (GNUNET_NO);
508 GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rcr_msg, GNUNET_NO);
510 GNUNET_SERVER_receive_done (client, GNUNET_OK);
513 static void handle_record_remove (void *cls,
514 struct GNUNET_SERVER_Client * client,
515 const struct GNUNET_MessageHeader * message)
517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_REMOVE");
518 struct GNUNET_NAMESTORE_Client *nc;
519 struct RecordRemoveResponseMessage rrr_msg;
525 int res = GNUNET_SYSERR;
527 if (ntohs (message->size) < sizeof (struct RecordRemoveMessage))
530 GNUNET_SERVER_receive_done (client, GNUNET_OK);
534 nc = client_lookup(client);
538 GNUNET_SERVER_receive_done (client, GNUNET_OK);
542 struct RecordRemoveMessage * rp_msg = (struct RecordRemoveMessage *) message;
543 id = ntohl (rp_msg->op_id);
544 name_len = ntohs (rp_msg->name_len);
545 msg_size = ntohs (message->size);
546 msg_size_exp = sizeof (struct RecordRemoveMessage) + name_len + sizeof (struct GNUNET_NAMESTORE_RecordData);
548 if (msg_size != msg_size_exp)
550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size);
552 GNUNET_SERVER_receive_done (client, GNUNET_OK);
557 if ((name_len == 0) || (name_len > 256))
560 GNUNET_SERVER_receive_done (client, GNUNET_OK);
568 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_REMOVE_RESPONSE");
569 rrr_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE);
570 rrr_msg.op_id = rp_msg->op_id;
571 rrr_msg.header.size = htons (sizeof (struct RecordRemoveResponseMessage));
572 if (GNUNET_OK == res)
573 rrr_msg.op_result = htons (GNUNET_OK);
575 rrr_msg.op_result = htons (GNUNET_NO);
576 GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rrr_msg, GNUNET_NO);
578 GNUNET_SERVER_receive_done (client, GNUNET_OK);
582 void zone_iteration_proc (void *cls,
583 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
584 struct GNUNET_TIME_Absolute expire,
586 unsigned int rd_count,
587 const struct GNUNET_NAMESTORE_RecordData *rd,
588 const struct GNUNET_CRYPTO_RsaSignature *signature)
590 struct ZoneIterationResponseMessage zir_msg;
591 struct GNUNET_NAMESTORE_ZoneIteration * zi = cls;
593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "ZONE_ITERATION_RESPONSE");
594 zir_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE);
595 zir_msg.op_id = htonl(zi->op_id);
596 zir_msg.header.size = htons (sizeof (struct ZoneIterationResponseMessage));
598 GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, (const struct GNUNET_MessageHeader *) &zir_msg, GNUNET_NO);
601 static void handle_iteration_start (void *cls,
602 struct GNUNET_SERVER_Client * client,
603 const struct GNUNET_MessageHeader * message)
605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_START");
607 struct ZoneIterationStartMessage * zis_msg = (struct ZoneIterationStartMessage *) message;
608 struct GNUNET_NAMESTORE_Client *nc;
609 struct GNUNET_NAMESTORE_ZoneIteration *zi;
612 nc = client_lookup(client);
616 GNUNET_SERVER_receive_done (client, GNUNET_OK);
620 zi = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_ZoneIteration));
621 zi->op_id = ntohl (zis_msg->op_id);
624 zi->zone = zis_msg->zone;
626 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi);
628 res = GSN_database->iterate_records (GSN_database->cls, &zis_msg->zone, NULL, zi->offset , &zone_iteration_proc, zi);
629 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "iterate_records: %i\n", res);
630 GNUNET_SERVER_receive_done (client, GNUNET_OK);
633 static void handle_iteration_stop (void *cls,
634 struct GNUNET_SERVER_Client * client,
635 const struct GNUNET_MessageHeader * message)
637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_STOP");
639 struct GNUNET_NAMESTORE_Client *nc;
640 struct GNUNET_NAMESTORE_ZoneIteration *zi;
641 struct ZoneIterationStopMessage * zis_msg = (struct ZoneIterationStopMessage *) message;
644 nc = client_lookup(client);
648 GNUNET_SERVER_receive_done (client, GNUNET_OK);
652 id = ntohl (zis_msg->op_id);
653 for (zi = nc->op_head; zi != NULL; zi = zi->next)
661 GNUNET_SERVER_receive_done (client, GNUNET_OK);
665 GNUNET_CONTAINER_DLL_remove(nc->op_head, nc->op_tail, zi);
666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration for zone `%s'\n", GNUNET_h2s (&zi->zone));
669 GNUNET_SERVER_receive_done (client, GNUNET_OK);
672 static void handle_iteration_next (void *cls,
673 struct GNUNET_SERVER_Client * client,
674 const struct GNUNET_MessageHeader * message)
676 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_NEXT");
682 * Process template requests.
685 * @param server the initialized server
686 * @param cfg configuration to use
689 run (void *cls, struct GNUNET_SERVER_Handle *server,
690 const struct GNUNET_CONFIGURATION_Handle *cfg)
694 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n");
696 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
697 {&handle_start, NULL,
698 GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)},
699 {&handle_lookup_name, NULL,
700 GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, 0},
701 {&handle_record_put, NULL,
702 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT, 0},
703 {&handle_record_create, NULL,
704 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE, 0},
705 {&handle_record_remove, NULL,
706 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE, 0},
707 {&handle_iteration_start, NULL,
708 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct ZoneIterationStartMessage)},
709 {&handle_iteration_stop, NULL,
710 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, sizeof (struct ZoneIterationStopMessage)},
711 {&handle_iteration_next, NULL,
712 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT, 0},
718 /* Loading database plugin */
720 GNUNET_CONFIGURATION_get_value_string (cfg, "namestore", "database",
722 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n");
724 GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database);
725 GSN_database = GNUNET_PLUGIN_load (db_lib_name, (void *) GSN_cfg);
726 if (GSN_database == NULL)
727 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not load database backend `%s'\n",
729 GNUNET_free (database);
731 /* Configuring server handles */
732 GNUNET_SERVER_add_handlers (server, handlers);
733 snc = GNUNET_SERVER_notification_context_create (server, 16);
734 GNUNET_SERVER_disconnect_notify (server,
735 &client_disconnect_notification,
738 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
745 * The main function for the template service.
747 * @param argc number of arguments from the command line
748 * @param argv command line arguments
749 * @return 0 ok, 1 on error
752 main (int argc, char *const *argv)
755 GNUNET_SERVICE_run (argc, argv, "namestore",
756 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
759 /* end of gnunet-service-namestore.c */