- send START first
[oweals/gnunet.git] / src / namestore / gnunet-service-namestore.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @file namestore/gnunet-service-namestore.c
23  * @brief namestore for the GNUnet naming system
24  * @author Matthias Wachs
25  */
26 #include "platform.h"
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"
32
33
34
35 /**
36  * A namestore operation.
37  */
38 struct GNUNET_NAMESTORE_Operation
39 {
40   struct GNUNET_NAMESTORE_Operation *next;
41   struct GNUNET_NAMESTORE_Operation *prev;
42
43   uint64_t op_id;
44
45   char *data; /*stub data pointer*/
46 };
47
48
49 /**
50  * A namestore client
51  */
52 struct GNUNET_NAMESTORE_Client
53 {
54   struct GNUNET_NAMESTORE_Client *next;
55   struct GNUNET_NAMESTORE_Client *prev;
56
57   struct GNUNET_SERVER_Client * client;
58
59   struct GNUNET_NAMESTORE_Operation *op_head;
60   struct GNUNET_NAMESTORE_Operation *op_tail;
61 };
62
63
64
65 /**
66  * Configuration handle.
67  */
68 const struct GNUNET_CONFIGURATION_Handle *GSN_cfg;
69
70 static struct GNUNET_NAMESTORE_PluginFunctions *GSN_database;
71
72 /**
73  * Our notification context.
74  */
75 static struct GNUNET_SERVER_NotificationContext *snc;
76
77 static char *db_lib_name;
78
79 static struct GNUNET_NAMESTORE_Client *client_head;
80 static struct GNUNET_NAMESTORE_Client *client_tail;
81
82
83 /**
84  * Task run during shutdown.
85  *
86  * @param cls unused
87  * @param tc unused
88  */
89 static void
90 cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
91 {
92   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n");
93
94   struct GNUNET_NAMESTORE_Operation * no;
95   struct GNUNET_NAMESTORE_Operation * tmp;
96   struct GNUNET_NAMESTORE_Client * nc;
97   struct GNUNET_NAMESTORE_Client * next;
98
99   for (nc = client_head; nc != NULL; nc = next)
100   {
101     next = nc->next;
102     for (no = nc->op_head; no != NULL; no = tmp)
103     {
104       GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no);
105       tmp = no->next;
106       GNUNET_free (no);
107     }
108
109     GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc);
110     GNUNET_free (nc);
111
112   }
113
114   GNUNET_SERVER_notification_context_destroy (snc);
115   snc = NULL;
116
117   GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database));
118   GNUNET_free (db_lib_name);
119 }
120
121 static struct GNUNET_NAMESTORE_Client *
122 client_lookup (struct GNUNET_SERVER_Client *client)
123 {
124   struct GNUNET_NAMESTORE_Client * nc;
125
126   GNUNET_assert (NULL != client);
127
128   for (nc = client_head; nc != NULL; nc = nc->next)
129   {
130     if (client == nc->client)
131       break;
132   }
133   return nc;
134 }
135
136
137 /**
138  * Called whenever a client is disconnected.  Frees our
139  * resources associated with that client.
140  *
141  * @param cls closure
142  * @param client identification of the client
143  */
144 static void
145 client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
146 {
147   struct GNUNET_NAMESTORE_Operation * no;
148   struct GNUNET_NAMESTORE_Client * nc;
149   if (NULL == client)
150     return;
151
152   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected \n", client);
153
154   nc = client_lookup (client);
155
156   if ((NULL == client) || (NULL == nc))
157     return;
158
159   for (no = nc->op_head; no != NULL; no = no->next)
160   {
161     GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no);
162     GNUNET_free (no);
163   }
164
165   GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc);
166   GNUNET_free (nc);
167 }
168
169 static void handle_start (void *cls,
170                           struct GNUNET_SERVER_Client * client,
171                           const struct GNUNET_MessageHeader * message)
172 {
173   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client);
174
175   struct GNUNET_NAMESTORE_Client * nc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Client));
176   nc->client = client;
177   GNUNET_SERVER_notification_context_add (snc, client);
178   GNUNET_CONTAINER_DLL_insert(client_head, client_tail, nc);
179
180   GNUNET_SERVER_receive_done (client, GNUNET_OK);
181 }
182
183 struct LookupNameContext
184 {
185   struct GNUNET_NAMESTORE_Client *nc;
186   uint32_t id;
187   uint32_t record_type;
188 };
189
190
191 static void
192 handle_lookup_name_it (void *cls,
193     const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
194     struct GNUNET_TIME_Absolute expire,
195     const char *name,
196     unsigned int rd_count,
197     const struct GNUNET_NAMESTORE_RecordData *rd,
198     const struct GNUNET_CRYPTO_RsaSignature *signature)
199 {
200   /* send response */
201   struct LookupNameContext *lnc = cls;
202   struct LookupNameResponseMessage *lnr_msg;
203
204   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key_tmp;
205   struct GNUNET_NAMESTORE_RecordData * rd_tmp;
206   char *name_tmp;
207   struct GNUNET_CRYPTO_RsaSignature *signature_tmp;
208
209   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "NAMESTORE_LOOKUP_NAME_RESPONSE");
210
211   size_t r_size = 0;
212
213   size_t name_len = 0;
214   if (NULL != name)
215     name_len = strlen(name) + 1;
216
217   int copied_elements = 0;
218   int contains_signature = 0;
219   int c;
220
221   /* count records to copy */
222   if (rd_count != 0)
223   {
224     if (lnc->record_type != 0)
225     {
226       /* special record type needed */
227       for (c = 0; c < rd_count; c ++)
228         if (rd[c].record_type == lnc->record_type)
229           copied_elements++; /* found matching record */
230     }
231     else
232       copied_elements = rd_count;
233   }
234
235   if ((copied_elements == rd_count) && (signature != NULL))
236       contains_signature = GNUNET_YES;
237
238   r_size = sizeof (struct LookupNameResponseMessage) +
239            sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
240            name_len +
241            copied_elements * sizeof (struct GNUNET_NAMESTORE_RecordData) +
242            contains_signature * sizeof (struct GNUNET_CRYPTO_RsaSignature);
243
244   lnr_msg = GNUNET_malloc (r_size);
245
246   lnr_msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE);
247   lnr_msg->header.size = ntohs (r_size);
248   lnr_msg->op_id = htonl (lnc->id);
249   lnr_msg->rc_count = htonl (copied_elements);
250   lnr_msg->name_len = htons (name_len);
251   lnr_msg->expire = GNUNET_TIME_absolute_hton(expire);
252   lnr_msg->contains_sig = htons (contains_signature);
253
254
255   zone_key_tmp =  (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &lnr_msg[1];
256   name_tmp = (char *) &zone_key_tmp[1];
257   rd_tmp = (struct GNUNET_NAMESTORE_RecordData *) &name_tmp[name_len];
258   signature_tmp = (struct GNUNET_CRYPTO_RsaSignature *) &rd_tmp[copied_elements];
259
260   if (zone_key != NULL)
261     memcpy (zone_key_tmp, zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
262   else
263   {
264     struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded dummy;
265     memset (&dummy, '0', sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
266     memcpy (zone_key_tmp, &dummy, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
267   }
268   memcpy (name_tmp, name, name_len);
269   /* copy records */
270   copied_elements = 0;
271   if (rd_count != 0)
272   {
273     if (lnc->record_type != 0)
274     {
275       /* special record type needed */
276       for (c = 0; c < rd_count; c ++)
277         if (rd[c].record_type == lnc->record_type)
278         {
279           /* found matching record */
280           memcpy (&rd_tmp[copied_elements], &rd[c], rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
281           copied_elements++;
282         }
283     }
284     else
285       memcpy (rd_tmp, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
286   }
287
288   if (GNUNET_YES == contains_signature)
289     memcpy (signature_tmp, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature));
290   GNUNET_SERVER_notification_context_unicast (snc, lnc->nc->client, (const struct GNUNET_MessageHeader *) lnr_msg, GNUNET_NO);
291
292   GNUNET_free (lnr_msg);
293 }
294
295 static void handle_lookup_name (void *cls,
296                           struct GNUNET_SERVER_Client * client,
297                           const struct GNUNET_MessageHeader * message)
298 {
299   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_LOOKUP_NAME");
300   struct LookupNameContext lnc;
301   struct GNUNET_NAMESTORE_Client *nc;
302   GNUNET_HashCode name_hash;
303   size_t name_len;
304   char * name;
305   uint32_t id = 0;
306   uint32_t type = 0;
307
308
309   if (ntohs (message->size) < sizeof (struct LookupNameMessage))
310   {
311     GNUNET_break_op (0);
312     GNUNET_SERVER_receive_done (client, GNUNET_OK);
313     return;
314   }
315
316   nc = client_lookup(client);
317   if (nc == NULL)
318   {
319     GNUNET_break_op (0);
320     GNUNET_SERVER_receive_done (client, GNUNET_OK);
321     return;
322   }
323
324   struct LookupNameMessage * ln_msg = (struct LookupNameMessage *) message;
325   id = ntohl (ln_msg->op_id);
326   name_len = ntohl (ln_msg->name_len);
327   type = ntohl (ln_msg->record_type);
328
329   if ((name_len == 0) || (name_len > 256))
330   {
331     GNUNET_break_op (0);
332     GNUNET_SERVER_receive_done (client, GNUNET_OK);
333     return;
334   }
335
336   name = GNUNET_malloc (name_len);
337   memcpy (name, &ln_msg[1], name_len);
338   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up record for name `%s'\n", name);
339   GNUNET_CRYPTO_hash(name, name_len-1, &name_hash);
340   GNUNET_free (name);
341
342   /* do the actual lookup */
343   lnc.id = id;
344   lnc.nc = nc;
345   lnc.record_type = type;
346   GSN_database->iterate_records(GSN_database->cls, &ln_msg->zone, &ln_msg->zone, 0, &handle_lookup_name_it, &lnc);
347
348   GNUNET_SERVER_receive_done (client, GNUNET_OK);
349 }
350
351 static void handle_record_put (void *cls,
352                           struct GNUNET_SERVER_Client * client,
353                           const struct GNUNET_MessageHeader * message)
354 {
355   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_PUT");
356   struct GNUNET_NAMESTORE_Client *nc;
357   struct GNUNET_TIME_Absolute expire;
358   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key;
359   struct GNUNET_NAMESTORE_RecordData *rd;
360   struct GNUNET_CRYPTO_RsaSignature *signature;
361   struct RecordPutResponseMessage rpr_msg;
362   size_t name_len;
363   size_t msg_size;
364   size_t msg_size_exp;
365   char * name;
366   uint32_t id = 0;
367   uint32_t rd_count;
368   int res = GNUNET_SYSERR;
369
370   if (ntohs (message->size) < sizeof (struct RecordPutMessage))
371   {
372     GNUNET_break_op (0);
373     GNUNET_SERVER_receive_done (client, GNUNET_OK);
374     return;
375   }
376
377   nc = client_lookup(client);
378   if (nc == NULL)
379   {
380     GNUNET_break_op (0);
381     GNUNET_SERVER_receive_done (client, GNUNET_OK);
382     return;
383   }
384
385   struct RecordPutMessage * rp_msg = (struct RecordPutMessage *) message;
386   id = ntohl (rp_msg->op_id);
387   name_len = ntohs (rp_msg->name_len);
388   rd_count = ntohl(rp_msg->rd_count);
389   msg_size = ntohs (message->size);
390   msg_size_exp = sizeof (struct RecordPutMessage) + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + name_len  + rd_count * (sizeof (struct GNUNET_NAMESTORE_RecordData));
391
392   if (msg_size != msg_size_exp)
393   {
394     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size);
395     GNUNET_break_op (0);
396     GNUNET_SERVER_receive_done (client, GNUNET_OK);
397     return;
398   }
399
400
401   if ((name_len == 0) || (name_len > 256))
402   {
403     GNUNET_break_op (0);
404     GNUNET_SERVER_receive_done (client, GNUNET_OK);
405     return;
406   }
407
408   zone_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &rp_msg[1];
409   name = (char *) &zone_key[1];
410   expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire);
411   signature = (struct GNUNET_CRYPTO_RsaSignature *) &rp_msg->signature;
412   rd = (struct GNUNET_NAMESTORE_RecordData *) &name[name_len];
413
414   /* Database operation */
415   res = GSN_database->put_records(GSN_database->cls,
416                                 zone_key,
417                                 expire,
418                                 name,
419                                 rd_count, rd,
420                                 signature);
421
422   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting record for name `%s': %s\n",
423       name, (res == GNUNET_OK) ? "OK" : "FAIL");
424
425   /* Send response */
426
427   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_PUT_RESPONSE");
428   rpr_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE);
429   rpr_msg.op_id = rp_msg->op_id;
430   rpr_msg.header.size = htons (sizeof (struct RecordPutResponseMessage));
431   if (GNUNET_OK == res)
432     rpr_msg.op_result = htons (GNUNET_OK);
433   else
434     rpr_msg.op_result = htons (GNUNET_NO);
435   GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rpr_msg, GNUNET_NO);
436
437   GNUNET_SERVER_receive_done (client, GNUNET_OK);
438 }
439
440
441 static void handle_record_create (void *cls,
442                           struct GNUNET_SERVER_Client * client,
443                           const struct GNUNET_MessageHeader * message)
444 {
445   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_CREATE");
446   struct GNUNET_NAMESTORE_Client *nc;
447   struct RecordCreateResponseMessage rcr_msg;
448   size_t name_len;
449   size_t msg_size;
450   size_t msg_size_exp;
451   uint32_t id = 0;
452
453   int res = GNUNET_SYSERR;
454
455   if (ntohs (message->size) < sizeof (struct RecordCreateMessage))
456   {
457     GNUNET_break_op (0);
458     GNUNET_SERVER_receive_done (client, GNUNET_OK);
459     return;
460   }
461
462   nc = client_lookup(client);
463   if (nc == NULL)
464   {
465     GNUNET_break_op (0);
466     GNUNET_SERVER_receive_done (client, GNUNET_OK);
467     return;
468   }
469
470   struct RecordCreateMessage * rp_msg = (struct RecordCreateMessage *) message;
471   id = ntohl (rp_msg->op_id);
472   name_len = ntohs (rp_msg->name_len);
473   msg_size = ntohs (message->size);
474   msg_size_exp = sizeof (struct RecordCreateMessage) + name_len + sizeof (struct GNUNET_NAMESTORE_RecordData);
475
476   if (msg_size != msg_size_exp)
477   {
478     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size);
479     GNUNET_break_op (0);
480     GNUNET_SERVER_receive_done (client, GNUNET_OK);
481     return;
482   }
483
484
485   if ((name_len == 0) || (name_len > 256))
486   {
487     GNUNET_break_op (0);
488     GNUNET_SERVER_receive_done (client, GNUNET_OK);
489     return;
490   }
491
492   /* DO WORK HERE */
493
494   /* Send response */
495
496   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_CREATE_RESPONSE");
497   rcr_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE);
498   rcr_msg.op_id = rp_msg->op_id;
499   rcr_msg.header.size = htons (sizeof (struct RecordCreateResponseMessage));
500   if (GNUNET_OK == res)
501     rcr_msg.op_result = htons (GNUNET_OK);
502   else
503     rcr_msg.op_result = htons (GNUNET_NO);
504   GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rcr_msg, GNUNET_NO);
505
506   GNUNET_SERVER_receive_done (client, GNUNET_OK);
507 }
508
509 static void handle_record_remove (void *cls,
510                           struct GNUNET_SERVER_Client * client,
511                           const struct GNUNET_MessageHeader * message)
512 {
513   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_REMOVE");
514   struct GNUNET_NAMESTORE_Client *nc;
515   struct RecordRemoveResponseMessage rrr_msg;
516   size_t name_len;
517   size_t msg_size;
518   size_t msg_size_exp;
519   uint32_t id = 0;
520
521   int res = GNUNET_SYSERR;
522
523   if (ntohs (message->size) < sizeof (struct RecordRemoveMessage))
524   {
525     GNUNET_break_op (0);
526     GNUNET_SERVER_receive_done (client, GNUNET_OK);
527     return;
528   }
529
530   nc = client_lookup(client);
531   if (nc == NULL)
532   {
533     GNUNET_break_op (0);
534     GNUNET_SERVER_receive_done (client, GNUNET_OK);
535     return;
536   }
537
538   struct RecordRemoveMessage * rp_msg = (struct RecordRemoveMessage *) message;
539   id = ntohl (rp_msg->op_id);
540   name_len = ntohs (rp_msg->name_len);
541   msg_size = ntohs (message->size);
542   msg_size_exp = sizeof (struct RecordRemoveMessage) + name_len + sizeof (struct GNUNET_NAMESTORE_RecordData);
543
544   if (msg_size != msg_size_exp)
545   {
546     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size);
547     GNUNET_break_op (0);
548     GNUNET_SERVER_receive_done (client, GNUNET_OK);
549     return;
550   }
551
552
553   if ((name_len == 0) || (name_len > 256))
554   {
555     GNUNET_break_op (0);
556     GNUNET_SERVER_receive_done (client, GNUNET_OK);
557     return;
558   }
559
560   /* DO WORK HERE */
561
562   /* Send response */
563
564   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_REMOVE_RESPONSE");
565   rrr_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE);
566   rrr_msg.op_id = rp_msg->op_id;
567   rrr_msg.header.size = htons (sizeof (struct RecordRemoveResponseMessage));
568   if (GNUNET_OK == res)
569     rrr_msg.op_result = htons (GNUNET_OK);
570   else
571     rrr_msg.op_result = htons (GNUNET_NO);
572   GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rrr_msg, GNUNET_NO);
573
574   GNUNET_SERVER_receive_done (client, GNUNET_OK);
575 }
576
577
578
579 /**
580  * Process template requests.
581  *
582  * @param cls closure
583  * @param server the initialized server
584  * @param cfg configuration to use
585  */
586 static void
587 run (void *cls, struct GNUNET_SERVER_Handle *server,
588      const struct GNUNET_CONFIGURATION_Handle *cfg)
589 {
590   char * database;
591
592   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n");
593
594   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
595     {&handle_start, NULL,
596      GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)},
597     {&handle_lookup_name, NULL,
598      GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, 0},
599     {&handle_record_put, NULL,
600     GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT, 0},
601     {&handle_record_create, NULL,
602      GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE, 0},
603     {&handle_record_remove, NULL,
604      GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE, 0},
605     {NULL, NULL, 0, 0}
606   };
607
608   GSN_cfg = cfg;
609
610   /* Loading database plugin */
611   if (GNUNET_OK !=
612       GNUNET_CONFIGURATION_get_value_string (cfg, "namestore", "database",
613                                              &database))
614     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n");
615
616   GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database);
617   GSN_database = GNUNET_PLUGIN_load (db_lib_name, (void *) GSN_cfg);
618   if (GSN_database == NULL)
619     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not load database backend `%s'\n",
620         db_lib_name);
621   GNUNET_free (database);
622
623   /* Configuring server handles */
624   GNUNET_SERVER_add_handlers (server, handlers);
625   snc = GNUNET_SERVER_notification_context_create (server, 16);
626   GNUNET_SERVER_disconnect_notify (server,
627                                    &client_disconnect_notification,
628                                    NULL);
629
630   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
631                                 NULL);
632
633 }
634
635
636 /**
637  * The main function for the template service.
638  *
639  * @param argc number of arguments from the command line
640  * @param argv command line arguments
641  * @return 0 ok, 1 on error
642  */
643 int
644 main (int argc, char *const *argv)
645 {
646   return (GNUNET_OK ==
647           GNUNET_SERVICE_run (argc, argv, "namestore",
648                               GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
649 }
650
651 /* end of gnunet-service-namestore.c */