2 This file is part of GNUnet.
3 (C) 2009, 2010, 2011 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.
24 * - Write xquery and block plugin
25 * - Think about mixed dns queries (.gnunet and .org)
26 * - (de-)serialisation of records/signature trees
27 * - The smaller FIXME issues all around
29 * @file gns/gnunet-service-gns.c
30 * @brief GNUnet GNS service
31 * @author Martin Schanzenbach
34 #include "gnunet_util_lib.h"
35 #include "gnunet_transport_service.h"
36 #include "gnunet_dns_service.h"
37 #include "gnunet_dnsparser_lib.h"
38 #include "gnunet_dht_service.h"
39 #include "gnunet_namestore_service.h"
40 #include "gnunet_gns_service.h"
43 /* Ignore for now not used anyway and probably never will */
44 #define GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP 23
45 #define GNUNET_MESSAGE_TYPE_GNS_CLIENT_RESULT 24
47 struct GNUNET_GNS_QueryRecordList
52 struct GNUNET_GNS_QueryRecordList * next;
53 struct GNUNET_GNS_QueryRecordList * prev;
55 struct GNUNET_NAMESTORE_RecordData * record;
59 * A result list for namestore queries
61 struct GNUNET_GNS_PendingQuery
63 /* the answer packet */
64 struct GNUNET_DNSPARSER_Packet *answer;
66 /* records to put into answer packet */
67 struct GNUNET_GNS_QueryRecordList * records_head;
68 struct GNUNET_GNS_QueryRecordList * records_tail;
71 int num_authority_records; //FIXME are all of our replies auth?
77 /* the dns request id */
78 int id; // FIXME can handle->request_id also be used here?
80 /* the request handle to reply to */
81 struct GNUNET_DNS_RequestHandle *request_handle;
83 /* hast this query been answered? */
86 /* the authoritative zone to query */
87 GNUNET_HashCode *authority;
89 /* we have an authority in namestore that
90 * may be able to resolve
97 * Our handle to the DNS handler library
99 struct GNUNET_DNS_Handle *dns_handle;
102 * Our handle to the DHT
104 struct GNUNET_DHT_Handle *dht_handle;
107 * Our zone's private key
109 struct GNUNET_CRYPTO_RsaPrivateKey *zone_key;
112 * Our handle to the namestore service
114 struct GNUNET_NAMESTORE_Handle *namestore_handle;
116 struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
119 * The configuration the GNS service is running with
121 const struct GNUNET_CONFIGURATION_Handle *GNS_cfg;
124 * Our notification context.
126 static struct GNUNET_SERVER_NotificationContext *nc;
131 GNUNET_HashCode zone_hash;
134 * Our tld. Maybe get from config file
136 const char* gnunet_tld = ".gnunet";
139 * Useful for zone update for DHT put
141 static int num_public_records = 3600;
142 struct GNUNET_TIME_Relative dht_update_interval;
145 * Task run during shutdown.
151 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
153 GNUNET_DNS_disconnect(dns_handle);
154 GNUNET_NAMESTORE_disconnect(namestore_handle, 0);
155 GNUNET_DHT_disconnect(dht_handle);
159 * Function called when we get a result from the dht
162 * @param cls the query handle
163 * @param exp lifetime
164 * @param key the key the record was stored under
165 * @param get_path get path
166 * @param get_path_length get path length
167 * @param put_path put path
168 * @param put_path_length put path length
169 * @param type the block type
170 * @param size the size of the record
171 * @param data the record data
174 process_authority_dht_result(void* cls,
175 struct GNUNET_TIME_Absolute exp,
176 const GNUNET_HashCode * key,
177 const struct GNUNET_PeerIdentity *get_path,
178 unsigned int get_path_length,
179 const struct GNUNET_PeerIdentity *put_path,
180 unsigned int put_path_length,
181 enum GNUNET_BLOCK_Type type,
182 size_t size, const void *data)
188 * data is a serialized PKEY record (probably)
189 * parse, put into namestore
190 * namestore zone hash is in query.
191 * Then adjust query->name and call resolve_name
192 * with new zone (the one just received)
194 * query->authority = new_authority
195 * resolve_name(query, new_authority);
200 * Start DHT lookup for a name -> PKEY (compare NS) record in
201 * query->authority's zone
203 * @param query the pending gns query
204 * @param name the name of the PKEY record
207 resolve_authority_dht(struct GNUNET_GNS_PendingQuery *query, const char* name)
209 enum GNUNET_GNS_RecordType rtype = GNUNET_GNS_RECORD_PKEY;
210 struct GNUNET_TIME_Relative timeout;
211 GNUNET_HashCode name_hash;
212 GNUNET_HashCode lookup_key;
214 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
215 GNUNET_CRYPTO_hash_xor(&name_hash, query->authority, &lookup_key);
217 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20);
219 //FIXME how long to wait for results?
220 GNUNET_DHT_get_start(dht_handle, timeout,
221 GNUNET_BLOCK_TYPE_TEST, //FIXME todo
223 5, //Replication level FIXME
225 &rtype, //xquery FIXME this is bad
226 sizeof(GNUNET_GNS_RECORD_PKEY),
227 &process_authority_dht_result,
233 * Function called when we get a result from the dht
236 * @param cls the query handle
237 * @param exp lifetime
238 * @param key the key the record was stored under
239 * @param get_path get path
240 * @param get_path_length get path length
241 * @param put_path put path
242 * @param put_path_length put path length
243 * @param type the block type
244 * @param size the size of the record
245 * @param data the record data
248 process_name_dht_result(void* cls,
249 struct GNUNET_TIME_Absolute exp,
250 const GNUNET_HashCode * key,
251 const struct GNUNET_PeerIdentity *get_path,
252 unsigned int get_path_length,
253 const struct GNUNET_PeerIdentity *put_path,
254 unsigned int put_path_length,
255 enum GNUNET_BLOCK_Type type,
256 size_t size, const void *data)
262 * data is a serialized GNS record of type
263 * query->record_type. Parse and put into namestore
264 * namestore zone hash is in query.
265 * Check if record type and name match in query and reply
271 * Start DHT lookup for a (name -> query->record_type) record in
272 * query->authority's zone
274 * @param query the pending gns query
275 * @param name the name to query record
278 resolve_name_dht(struct GNUNET_GNS_PendingQuery *query, const char* name)
280 struct GNUNET_TIME_Relative timeout;
281 GNUNET_HashCode name_hash;
282 GNUNET_HashCode lookup_key;
284 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
285 GNUNET_CRYPTO_hash_xor(&name_hash, query->authority, &lookup_key);
287 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20);
289 //FIXME how long to wait for results?
290 GNUNET_DHT_get_start(dht_handle, timeout,
291 GNUNET_BLOCK_TYPE_TEST, //FIXME todo
293 5, //Replication level FIXME
295 &query->type, //xquery
297 &process_name_dht_result,
304 resolve_name(struct GNUNET_GNS_PendingQuery *query, GNUNET_HashCode *zone);
307 * This is a callback function that should give us only PKEY
308 * records. Used to query the namestore for the authority (PKEY)
311 * @param cls the pending query
312 * @param zone our zone hash
313 * @param name the name for which we need an authority
314 * @param record_type the type of record (PKEY)
315 * @param expiration expiration date of the record
316 * @param flags namestore record flags
317 * @param sig_loc the location of the record in the signature tree
318 * @param size the size of the record
319 * @param data the record data
322 process_authority_lookup(void* cls,
323 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
324 struct GNUNET_TIME_Absolute expiration,
326 unsigned int rd_count,
327 const struct GNUNET_NAMESTORE_RecordData *rd,
328 const struct GNUNET_CRYPTO_RsaSignature *signature)
330 struct GNUNET_GNS_PendingQuery *query;
331 GNUNET_HashCode zone;
333 query = (struct GNUNET_GNS_PendingQuery *)cls;
334 GNUNET_CRYPTO_hash(key, GNUNET_CRYPTO_RSA_KEY_LENGTH, &zone);
337 * No authority found in namestore.
341 if (query->authority_found)
343 query->authority_found = 0;
344 resolve_name(query, query->authority);
349 * We did not find an authority in the namestore
350 * _IF_ the current authoritative zone is us we cannot resolve
351 * _ELSE_ we can still check the dht
353 if (GNUNET_CRYPTO_hash_cmp(&zone, &zone_hash))
355 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Authority unknown\n");
356 //FIXME return NX answer
360 resolve_authority_dht(query, name);
364 //Note only 1 pkey should have been returned.. anything else would be strange
366 * We found an authority that may be able to help us
370 GNUNET_assert(rd->record_type == GNUNET_GNS_RECORD_PKEY);
371 GNUNET_HashCode *pkey_hash = GNUNET_malloc(sizeof(GNUNET_HashCode));
372 GNUNET_CRYPTO_hash(rd->data, GNUNET_CRYPTO_RSA_KEY_LENGTH, pkey_hash);
373 GNUNET_free_non_null(query->authority);
374 query->authority = pkey_hash;
375 resolve_name(query, query->authority);
381 * Reply to client with the result from our lookup.
383 * @param answer the pending query used in the lookup
386 reply_to_dns(struct GNUNET_GNS_PendingQuery *answer)
388 struct GNUNET_GNS_QueryRecordList *i;
389 struct GNUNET_DNSPARSER_Packet *packet;
390 struct GNUNET_DNSPARSER_Flags dnsflags;
396 packet = GNUNET_malloc(sizeof(struct GNUNET_DNSPARSER_Packet));
398 GNUNET_malloc(sizeof(struct GNUNET_DNSPARSER_Record) * answer->num_records);
400 len = sizeof(struct GNUNET_DNSPARSER_Record*);
402 for (i=answer->records_head; i != NULL; i=i->next)
404 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
405 "Adding type %d to DNS response\n", i->record->record_type);
406 //FIXME build proper dnsparser record! this will fail!
407 //memcpy(&packet->answers[j],
409 // sizeof (struct GNUNET_DNSPARSER_Record));
410 GNUNET_free(i->record);
413 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "after memcpy\n");
414 /* FIXME how to handle auth, additional etc */
415 packet->num_answers = answer->num_records;
416 packet->num_authority_records = answer->num_authority_records;
418 dnsflags.authoritative_answer = 1;
419 dnsflags.opcode = GNUNET_DNSPARSER_OPCODE_QUERY;
420 dnsflags.return_code = GNUNET_DNSPARSER_RETURN_CODE_NO_ERROR; //not sure
421 dnsflags.query_or_response = 1;
422 packet->flags = dnsflags;
424 packet->id = answer->id;
426 //FIXME this is silently discarded
427 ret = GNUNET_DNSPARSER_pack (packet,
428 1024, /* FIXME magic from dns redirector */
431 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
432 "Built DNS response! (ret=%d)\n", ret);
433 if (ret == GNUNET_OK)
435 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
436 "Answering DNS request\n");
437 GNUNET_DNS_request_answer(answer->request_handle,
440 //GNUNET_free(answer);
441 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Answered DNS request\n");
442 //FIXME return code, free datastructures
446 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
447 "Error building DNS response! (ret=%d)", ret);
453 * Namestore calls this function if we have an entry for this name.
454 * (or data=null to indicate the lookup has finished)
456 * @param cls the pending query
457 * @param zone the zone of the lookup
458 * @param name the name looked up
459 * @param record_type the record type
460 * @param expiration lifetime of the record
461 * @param flags record flags
462 * @param sig_loc location of the record in the signature tree
463 * @param size the size of the record
464 * @param data the record data
467 process_authoritative_result(void* cls,
468 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
469 struct GNUNET_TIME_Absolute expiration,
470 const char *name, unsigned int rd_count,
471 const struct GNUNET_NAMESTORE_RecordData *rd,
472 const struct GNUNET_CRYPTO_RsaSignature *signature)
474 struct GNUNET_GNS_PendingQuery *query;
475 struct GNUNET_GNS_QueryRecordList *qrecord;
476 struct GNUNET_NAMESTORE_RecordData *record;
477 GNUNET_HashCode zone;
478 query = (struct GNUNET_GNS_PendingQuery *) cls;
479 GNUNET_CRYPTO_hash(key, GNUNET_CRYPTO_RSA_KEY_LENGTH, &zone);
481 //FIXME Handle results in rd
487 * Lookup terminated and no results
488 * -> DHT Phase unless data is recent
489 * if full_name == next_name and not anwered we cannot resolve
491 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
492 "Namestore lookup terminated. without results\n");
495 * if this is not our zone we cannot rely on the namestore to be
496 * complete. -> Query DHT
498 if (!GNUNET_CRYPTO_hash_cmp(&zone, &zone_hash))
501 resolve_name_dht(query, name);
506 * Our zone and no result? Cannot resolve TT
507 * FIXME modify query to say NX
517 * FIXME Check record expiration and dht expiration
518 * consult dht if necessary
520 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
521 "Processing additional result for %s from namestore\n", name);
523 for (i=0; i<rd_count;i++)
525 // A time will come when this has to be freed
526 qrecord = GNUNET_malloc(sizeof(struct GNUNET_GNS_QueryRecordList));
527 record = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_RecordData));
528 qrecord->record = record;
530 //fixme into gns_util
531 //parse_record(rd[i]->data, rd[i]->data_size, 0, record);
532 GNUNET_CONTAINER_DLL_insert(query->records_head,
535 query->num_records++;
538 //we need to resolve to the original name in the end though...
539 //record->name = (char*)query->original_name;
542 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Found answer to query!\n");
550 * Determine if this name is canonical.
552 * a.b.gnunet = not canonical
555 * @param name the name to test
556 * @return 1 if canonical
559 is_canonical(char* name)
561 uint32_t len = strlen(name);
564 for (i=0; i<len; i++)
566 if (*(name+i) == '.')
573 * Move one level up in the domain hierarchy and return the
574 * passed top level domain.
575 * FIXME this needs a better name
577 * @param name the domain
580 char* pop_tld(char* name)
584 if (is_canonical(name))
587 for (len = strlen(name); len > 0; len--)
589 if (*(name+len) == '.')
596 name[len] = '\0'; //terminate string
603 * The first phase of resolution.
604 * First check if the name is canonical.
605 * If it is then try to resolve directly.
606 * If not then first have to resolve the authoritative entities.
608 * @param query the pending lookup
609 * @param zone the zone we are currently resolving in
612 resolve_name(struct GNUNET_GNS_PendingQuery *query, GNUNET_HashCode *zone)
614 if (is_canonical(query->name))
616 //We only need to check this zone's ns
617 GNUNET_NAMESTORE_lookup_record(namestore_handle,
621 &process_authoritative_result,
626 //We have to resolve the authoritative entity
627 char *new_authority = pop_tld(query->name);
628 GNUNET_NAMESTORE_lookup_record(namestore_handle,
631 GNUNET_GNS_RECORD_PKEY,
632 &process_authority_lookup,
638 * Entry point for name resolution
639 * Lookup local namestore of our zone.
641 * Setup a new query and try to resolve
643 * @param rh the request handle of the DNS request from a client
644 * @param name the name to look up
645 * @param id the id of the dns request (for the reply)
646 * @param type the record type to look for
649 start_resolution(struct GNUNET_DNS_RequestHandle *rh,
650 char* name, uint16_t id, uint16_t type)
652 struct GNUNET_GNS_PendingQuery *query;
654 //FIXME remove .gnunet here from name
655 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "This is .gnunet (%s)!\n", name);
656 query = GNUNET_malloc(sizeof (struct GNUNET_GNS_PendingQuery));
658 query->original_name = name; //Full name of original query
660 //FIXME do not forget to free!!
661 query->name = GNUNET_malloc(strlen(name)-strlen(gnunet_tld) + 1);
662 memset(query->name, 0, strlen(name)-strlen(gnunet_tld) + 1);
663 memcpy(query->name, name, strlen(name)-strlen(gnunet_tld));
666 query->request_handle = rh;
668 //Start resolution in our zone
669 resolve_name(query, &zone_hash);
673 * The DNS request handler
674 * Called for every incoming DNS request.
677 * @param rh request handle to user for reply
678 * @param request_length number of bytes in request
679 * @param request udp payload of the DNS request
682 handle_dns_request(void *cls,
683 struct GNUNET_DNS_RequestHandle *rh,
684 size_t request_length,
687 struct GNUNET_DNSPARSER_Packet *p;
691 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Hijacked a DNS request...processing\n");
692 p = GNUNET_DNSPARSER_parse (request, request_length);
696 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
697 "Received malformed DNS packet, leaving it untouched\n");
698 GNUNET_DNS_request_forward (rh);
703 * Check tld and decide if we or
704 * legacy dns is responsible
706 * FIXME now in theory there could be more than 1 query in the request
707 * but if this is case we get into trouble:
708 * either we query the GNS or the DNS. We cannot do both!
709 * So I suggest to either only allow a single query per request or
710 * only allow GNS or DNS requests.
711 * The way it is implemented here now is buggy and will lead to erratic
712 * behaviour (if multiple queries are present).
714 for (i=0;i<p->num_queries;i++)
716 tldoffset = p->queries[i].name + strlen(p->queries[i].name);
718 while ((*tldoffset) != '.')
721 if (0 == strcmp(tldoffset, gnunet_tld))
723 start_resolution(rh, p->queries[i].name, p->id, p->queries[i].type);
728 * This request does not concern us. Forward to real DNS.
730 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
731 "Request for %s is forwarded to DNS\n", p->queries[i].name);
732 GNUNET_DNS_request_forward (rh);
738 * test function that stores some data in the namestore
741 put_some_records(void)
743 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Populating namestore\n");
744 /* put a few records into namestore */
745 char* ipA = "1.2.3.4";
746 char* ipB = "5.6.7.8";
747 struct in_addr *alice = GNUNET_malloc(sizeof(struct in_addr));
748 struct in_addr *bob = GNUNET_malloc(sizeof(struct in_addr));
749 struct GNUNET_NAMESTORE_RecordData *rda;
750 struct GNUNET_NAMESTORE_RecordData *rdb;
752 rda = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_RecordData));
753 rdb = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_RecordData));
755 GNUNET_assert(1 == inet_pton (AF_INET, ipA, alice));
756 GNUNET_assert(1 == inet_pton (AF_INET, ipB, bob));
758 rda->data_size = sizeof(struct in_addr);
759 rdb->data_size = sizeof(struct in_addr);
762 rda->record_type = GNUNET_GNS_RECORD_TYPE_A;
763 rdb->record_type = GNUNET_GNS_RECORD_TYPE_A;
764 rda->expiration = GNUNET_TIME_absolute_get_forever ();
765 rdb->expiration = GNUNET_TIME_absolute_get_forever ();
767 GNUNET_NAMESTORE_record_create (namestore_handle,
773 GNUNET_NAMESTORE_record_create (namestore_handle,
782 update_zone_dht_next(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
784 GNUNET_NAMESTORE_zone_iterator_next(namestore_iter);
788 * Function used to put all records successively into the DHT.
790 * @param cls the closure (NULL)
791 * @param zone our root zone hash
792 * @param name the name of the record
793 * @param record_type the type of the record
794 * @param expiration lifetime of the record
795 * @param flags flags of the record
796 * @param sig_loc location of record in signature tree
797 * @param size size of the record
798 * @param record_data the record data
801 put_gns_record(void *cls,
802 const const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
803 struct GNUNET_TIME_Absolute expiration,
805 unsigned int rd_count,
806 const struct GNUNET_NAMESTORE_RecordData *rd,
807 const struct GNUNET_CRYPTO_RsaSignature *signature)
809 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Putting records into the DHT\n");
810 struct GNUNET_TIME_Relative timeout;
811 GNUNET_HashCode name_hash;
812 GNUNET_HashCode xor_hash;
814 if (NULL == name) //We're done
816 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
820 * FIXME magic number 20 move to config file
822 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20);
823 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
824 GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash);
825 GNUNET_DHT_put (dht_handle, &xor_hash,
826 5, //replication level
828 GNUNET_BLOCK_TYPE_TEST, //FIXME todo block plugin
833 NULL, //FIXME continuation needed? success check? yes ofc
834 NULL); //cls for cont
837 * Reschedule periodic put
839 GNUNET_SCHEDULER_add_delayed (dht_update_interval,
840 &update_zone_dht_next,
846 * Periodically iterate over our zone and store everything in dht
849 * @param tc task context
852 update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
854 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Update zone!\n");
855 dht_update_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
856 (3600/num_public_records));
857 namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
859 GNUNET_NAMESTORE_RF_AUTHORITY,
860 GNUNET_NAMESTORE_RF_PRIVATE,
866 * Process GNS requests.
869 * @param server the initialized server
870 * @param c configuration to use
873 run (void *cls, struct GNUNET_SERVER_Handle *server,
874 const struct GNUNET_CONFIGURATION_Handle *c)
877 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Init GNS\n");
878 zone_key = GNUNET_CRYPTO_rsa_key_create ();
880 GNUNET_CRYPTO_hash(zone_key, GNUNET_CRYPTO_RSA_KEY_LENGTH,//FIXME is this ok?
882 nc = GNUNET_SERVER_notification_context_create (server, 1);
884 /* FIXME - do some config parsing
885 * - Maybe only hijack dns if option is set (HIJACK_DNS=1)
888 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
891 * Do gnunet dns init here
893 dns_handle = GNUNET_DNS_connect(c,
894 GNUNET_DNS_FLAG_PRE_RESOLUTION,
895 &handle_dns_request, /* rh */
898 if (NULL == dns_handle)
900 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
901 "Failed to connect to the dnsservice!\n");
905 * handle to our local namestore
907 namestore_handle = GNUNET_NAMESTORE_connect(c);
909 if (NULL == namestore_handle)
911 //FIXME do error handling;
912 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
913 "Failed to connect to the namestore!\n");
919 dht_handle = GNUNET_DHT_connect(c, 1); //FIXME get ht_len from cfg
921 if (NULL == dht_handle)
923 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not connect to DHT!\n");
926 put_some_records(); //FIXME for testing
929 * Schedule periodic put
931 * We have roughly an hour for all records;
933 dht_update_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
934 60); //FIXME from cfg
935 GNUNET_SCHEDULER_add_delayed (dht_update_interval,
936 &update_zone_dht_start,
938 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "GNS Init done!\n");
944 * The main function for the GNS service.
946 * @param argc number of arguments from the command line
947 * @param argv command line arguments
948 * @return 0 ok, 1 on error
951 main (int argc, char *const *argv)
957 GNUNET_SERVICE_run (argc, argv, "gns", GNUNET_SERVICE_OPTION_NONE, &run,
962 /* end of gnunet-service-gns.c */