aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorLRN <lrn1986@gmail.com>2013-12-09 17:53:20 +0000
committerLRN <lrn1986@gmail.com>2013-12-09 17:53:20 +0000
commit2d828dcdcd023b9361b11491254d08f122c142b1 (patch)
treefdf837d651c71372c630ce53175547a687e323ab /src/gns
parenteec3e29ff08f7cf71b97f39e0ca54848eb88683c (diff)
downloadgnunet-2d828dcdcd023b9361b11491254d08f122c142b1.tar.gz
gnunet-2d828dcdcd023b9361b11491254d08f122c142b1.zip
Update W32 GNS helper and NSP
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/Makefile.am2
-rw-r--r--src/gns/gnunet-gns-helper-service-w32.c218
-rw-r--r--src/gns/w32nsp.c4
3 files changed, 155 insertions, 69 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index a24f5f63d..73210f6cf 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -153,10 +153,12 @@ gnunet_gns_helper_service_w32_SOURCES = \
153 gnunet-gns-helper-service-w32.c 153 gnunet-gns-helper-service-w32.c
154gnunet_gns_helper_service_w32_LDADD = \ 154gnunet_gns_helper_service_w32_LDADD = \
155 $(top_builddir)/src/gns/libgnunetgns.la \ 155 $(top_builddir)/src/gns/libgnunetgns.la \
156 $(top_builddir)/src/identity/libgnunetidentity.la \
156 $(top_builddir)/src/util/libgnunetutil.la \ 157 $(top_builddir)/src/util/libgnunetutil.la \
157 $(GN_LIBINTL) 158 $(GN_LIBINTL)
158gnunet_gns_helper_service_w32_DEPENDENCIES = \ 159gnunet_gns_helper_service_w32_DEPENDENCIES = \
159 $(top_builddir)/src/util/libgnunetutil.la \ 160 $(top_builddir)/src/util/libgnunetutil.la \
161 $(top_builddir)/src/identity/libgnunetidentity.la \
160 libgnunetgns.la 162 libgnunetgns.la
161 163
162w32nsp_install_SOURCES = \ 164w32nsp_install_SOURCES = \
diff --git a/src/gns/gnunet-gns-helper-service-w32.c b/src/gns/gnunet-gns-helper-service-w32.c
index 02afa7ac2..48bbd5723 100644
--- a/src/gns/gnunet-gns-helper-service-w32.c
+++ b/src/gns/gnunet-gns-helper-service-w32.c
@@ -26,6 +26,7 @@
26#define INITGUID 26#define INITGUID
27#include "platform.h" 27#include "platform.h"
28#include <gnunet_util_lib.h> 28#include <gnunet_util_lib.h>
29#include <gnunet_identity_service.h>
29#include <gnunet_dnsparser_lib.h> 30#include <gnunet_dnsparser_lib.h>
30#include <gnunet_namestore_service.h> 31#include <gnunet_namestore_service.h>
31#include <gnunet_gns_service.h> 32#include <gnunet_gns_service.h>
@@ -54,6 +55,7 @@ struct request
54 int af; 55 int af;
55 wchar_t *name; 56 wchar_t *name;
56 char *u8name; 57 char *u8name;
58 struct GNUNET_GNS_LookupRequest *lookup_request;
57}; 59};
58 60
59/** 61/**
@@ -61,10 +63,30 @@ struct request
61 */ 63 */
62static struct GNUNET_GNS_Handle *gns; 64static struct GNUNET_GNS_Handle *gns;
63 65
64static struct GNUNET_CRYPTO_EcdsaPublicKey *zone = NULL; 66/**
65static struct GNUNET_HashCode user_zone; 67 * Active operation on identity service.
66struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_key = NULL; 68 */
69static struct GNUNET_IDENTITY_Operation *id_op;
70
71/**
72 * Handle for identity service.
73 */
74static struct GNUNET_IDENTITY_Handle *identity;
75
76/**
77 * Public key of the gns-master ego
78 */
79static struct GNUNET_CRYPTO_EcdsaPublicKey gns_master_pubkey;
80
81/**
82 * Private key of the gns-short ego
83 */
84static struct GNUNET_CRYPTO_EcdsaPrivateKey gns_short_privkey;
67 85
86/**
87 * Set to 1 once egos are obtained.
88 */
89static int got_egos = 0;
68 90
69/** 91/**
70 * Task run on shutdown. Cleans up everything. 92 * Task run on shutdown. Cleans up everything.
@@ -76,6 +98,16 @@ static void
76do_shutdown (void *cls, 98do_shutdown (void *cls,
77 const struct GNUNET_SCHEDULER_TaskContext *tc) 99 const struct GNUNET_SCHEDULER_TaskContext *tc)
78{ 100{
101 if (NULL != id_op)
102 {
103 GNUNET_IDENTITY_cancel (id_op);
104 id_op = NULL;
105 }
106 if (NULL != identity)
107 {
108 GNUNET_IDENTITY_disconnect (identity);
109 identity = NULL;
110 }
79 if (NULL != gns) 111 if (NULL != gns)
80 { 112 {
81 GNUNET_GNS_disconnect (gns); 113 GNUNET_GNS_disconnect (gns);
@@ -131,7 +163,7 @@ static int cleaning_done;
131 163
132/** 164/**
133 * Function called to notify a client about the socket 165 * Function called to notify a client about the socket
134 * begin ready to queue more data. "buf" will be 166 * being ready to queue more data. "buf" will be
135 * NULL and "size" zero if the socket was closed for 167 * NULL and "size" zero if the socket was closed for
136 * writing in the meantime. 168 * writing in the meantime.
137 * 169 *
@@ -242,9 +274,8 @@ MarshallWSAQUERYSETW (WSAQUERYSETW *qs, GUID *sc)
242 274
243 275
244static void 276static void
245process_ip_lookup_result (void* cls, 277process_lookup_result (void* cls, uint32_t rd_count,
246 uint32_t rd_count, 278 const struct GNUNET_GNSRECORD_Data *rd)
247 const struct GNUNET_GNSRECORD_Data *rd)
248{ 279{
249 int i, j, csanum; 280 int i, j, csanum;
250 struct request *rq = (struct request *) cls; 281 struct request *rq = (struct request *) cls;
@@ -258,8 +289,8 @@ process_ip_lookup_result (void* cls,
258 size_t blobaddrcount = 0; 289 size_t blobaddrcount = 0;
259 290
260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
261 "Got lookup result with count %u for rq %p with client %p\n", 292 "Got lookup result with count %u for rq %p with client %p\n",
262 rd_count, rq, rq->client); 293 rd_count, rq, rq->client);
263 294
264 if (rd_count == 0) 295 if (rd_count == 0)
265 { 296 {
@@ -268,6 +299,10 @@ process_ip_lookup_result (void* cls,
268 msg->header.size = htons (size); 299 msg->header.size = htons (size);
269 msg->header.type = htons (GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE); 300 msg->header.type = htons (GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
270 transmit (rq->client, &msg->header); 301 transmit (rq->client, &msg->header);
302 GNUNET_free_non_null (rq->name);
303 if (rq->u8name)
304 free (rq->u8name);
305 GNUNET_free (rq);
271 return; 306 return;
272 } 307 }
273 308
@@ -498,6 +533,10 @@ process_ip_lookup_result (void* cls,
498 } 533 }
499 MarshallWSAQUERYSETW (qs, &rq->sc); 534 MarshallWSAQUERYSETW (qs, &rq->sc);
500 transmit (rq->client, &msg->header); 535 transmit (rq->client, &msg->header);
536 GNUNET_free_non_null (rq->name);
537 if (rq->u8name)
538 free (rq->u8name);
539 GNUNET_free (rq);
501} 540}
502 541
503 542
@@ -547,11 +586,14 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
547 namelen = 0; 586 namelen = 0;
548 if (namelen > 0) 587 if (namelen > 0)
549 hostname = (char *) u16_to_u8 (name, namelen + 1, NULL, &strl); 588 hostname = (char *) u16_to_u8 (name, namelen + 1, NULL, &strl);
589 else
590 hostname = NULL;
550 591
551 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
552 "W32 DNS resolver asked to look up %s for `%s'.\n", 593 "W32 DNS resolver asked to look up %s for `%s'.\n",
553 af == AF_INET ? "IPv4" : af == AF_INET6 ? "IPv6" : "anything", 594 af == AF_INET ? "IPv4" : af == AF_INET6 ? "IPv6" : "anything",
554 hostname); 595 hostname);
596
555 rq = GNUNET_malloc (sizeof (struct request)); 597 rq = GNUNET_malloc (sizeof (struct request));
556 rq->sc = sc; 598 rq->sc = sc;
557 rq->client = client; 599 rq->client = client;
@@ -569,8 +611,11 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
569 "Launching a lookup for client %p with rq %p\n", 611 "Launching a lookup for client %p with rq %p\n",
570 client, rq); 612 client, rq);
571 613
572 if (NULL != GNUNET_GNS_lookup (gns, hostname, zone, rtype, 614 rq->lookup_request = GNUNET_GNS_lookup (gns, hostname, &gns_master_pubkey,
573 GNUNET_YES, shorten_key, &process_ip_lookup_result, rq)) 615 rtype, GNUNET_NO /* Use DHT */, &gns_short_privkey, &process_lookup_result,
616 rq);
617
618 if (NULL != rq->lookup_request)
574 { 619 {
575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 620 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
576 "Lookup launched, waiting for a reply\n"); 621 "Lookup launched, waiting for a reply\n");
@@ -579,12 +624,10 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
579 else 624 else
580 { 625 {
581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
582 "Lookup was not, disconnecting the client\n"); 627 "Lookup was not launched, disconnecting the client\n");
583 if (namelen) 628 GNUNET_free_non_null (rq->name);
584 { 629 if (rq->u8name)
585 GNUNET_free (rq->name);
586 free (rq->u8name); 630 free (rq->u8name);
587 }
588 GNUNET_free (rq); 631 GNUNET_free (rq);
589 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 632 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
590 } 633 }
@@ -611,6 +654,16 @@ handle_get (void *cls, struct GNUNET_SERVER_Client *client,
611 const wchar_t *hostname; 654 const wchar_t *hostname;
612 int af; 655 int af;
613 656
657 if (!got_egos)
658 {
659 /*
660 * FIXME: be done with GNUNET_OK, put the get request into a queue?
661 * or postpone GNUNET_SERVER_add_handlers() until egos are obtained?
662 */
663 GNUNET_SERVER_receive_done (client, GNUNET_NO);
664 return;
665 }
666
614 msize = ntohs (message->size); 667 msize = ntohs (message->size);
615 if (msize < sizeof (struct GNUNET_W32RESOLVER_GetMessage)) 668 if (msize < sizeof (struct GNUNET_W32RESOLVER_GetMessage))
616 { 669 {
@@ -646,6 +699,69 @@ handle_get (void *cls, struct GNUNET_SERVER_Client *client,
646 699
647 700
648/** 701/**
702 * Method called to with the ego we are to use for shortening
703 * during the lookup.
704 *
705 * @param cls closure (NULL, unused)
706 * @param ego ego handle, NULL if not found
707 * @param ctx context for application to store data for this ego
708 * (during the lifetime of this process, initially NULL)
709 * @param name name assigned by the user for this ego,
710 * NULL if the user just deleted the ego and it
711 * must thus no longer be used
712 */
713static void
714identity_shorten_cb (void *cls,
715 struct GNUNET_IDENTITY_Ego *ego,
716 void **ctx,
717 const char *name)
718{
719 id_op = NULL;
720 if (NULL == ego)
721 {
722 fprintf (stderr,
723 _("Ego for `gns-short' not found. This is not really fatal, but i'll pretend that it is and refuse to perform a lookup. Did you run gnunet-gns-import.sh?\n"));
724 GNUNET_SCHEDULER_shutdown ();
725 return;
726 }
727 gns_short_privkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
728 got_egos = 1;
729}
730
731/**
732 * Method called to with the ego we are to use for the lookup,
733 * when the ego is the one for the default master zone.
734 *
735 * @param cls closure (NULL, unused)
736 * @param ego ego handle, NULL if not found
737 * @param ctx context for application to store data for this ego
738 * (during the lifetime of this process, initially NULL)
739 * @param name name assigned by the user for this ego,
740 * NULL if the user just deleted the ego and it
741 * must thus no longer be used
742 */
743static void
744identity_master_cb (void *cls,
745 struct GNUNET_IDENTITY_Ego *ego,
746 void **ctx,
747 const char *name)
748{
749 id_op = NULL;
750 if (NULL == ego)
751 {
752 fprintf (stderr,
753 _("Ego for `gns-master' not found, cannot perform lookup. Did you run gnunet-gns-import.sh?\n"));
754 GNUNET_SCHEDULER_shutdown ();
755 return;
756 }
757 GNUNET_IDENTITY_ego_get_public_key (ego, &gns_master_pubkey);
758 id_op = GNUNET_IDENTITY_get (identity, "gns-short", &identity_shorten_cb,
759 NULL);
760 GNUNET_assert (NULL != id_op);
761}
762
763
764/**
649 * Start up gns-helper-w32 service. 765 * Start up gns-helper-w32 service.
650 * 766 *
651 * @param cls closure 767 * @param cls closure
@@ -654,65 +770,36 @@ handle_get (void *cls, struct GNUNET_SERVER_Client *client,
654 */ 770 */
655static void 771static void
656run (void *cls, struct GNUNET_SERVER_Handle *server, 772run (void *cls, struct GNUNET_SERVER_Handle *server,
657 const struct GNUNET_CONFIGURATION_Handle *cfg) 773 const struct GNUNET_CONFIGURATION_Handle *cfg)
658{ 774{
659 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 775 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
660 {&handle_get, NULL, GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST, 0}, 776 {&handle_get, NULL, GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST, 0},
661 {NULL, NULL, 0, 0} 777 {NULL, NULL, 0, 0}
662 }; 778 };
663 779
664 char* keyfile; 780 gns = GNUNET_GNS_connect (cfg);
665 struct GNUNET_CRYPTO_EcdsaPrivateKey *key = NULL; 781 if (NULL == gns)
666 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
667 struct GNUNET_CRYPTO_HashAsciiEncoded zonename;
668
669 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
670 "ZONEKEY", &keyfile))
671 {
672 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
673 "No private key for root zone found, using default!\n");
674 zone = NULL;
675 }
676 else
677 { 782 {
678 if (GNUNET_YES == GNUNET_DISK_file_test (keyfile)) 783 fprintf (stderr, _("Failed to connect to GNS\n"));
679 { 784 GNUNET_SCHEDULER_shutdown ();
680 key = GNUNET_CRYPTO_ecdsa_key_create_from_file (keyfile); 785 return;
681 GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey);
682 GNUNET_CRYPTO_hash (&pkey, sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey),
683 &user_zone);
684 GNUNET_CRYPTO_hash_to_enc (&user_zone, &zonename);
685 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
686 "Using zone: %s!\n", &zonename);
687 GNUNET_free(key);
688 }
689 GNUNET_free(keyfile);
690 } 786 }
787 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
788 NULL);
691 789
692 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", 790 identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
693 "SHORTEN_ZONEKEY", &keyfile)) 791 if (NULL == identity)
694 {
695 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
696 "No shorten key found!\n");
697 shorten_key = NULL;
698 }
699 else
700 { 792 {
701 if (GNUNET_YES == GNUNET_DISK_file_test (keyfile)) 793 fprintf (stderr, _("Failed to connect to identity service\n"));
702 { 794 GNUNET_SCHEDULER_shutdown ();
703 shorten_key = GNUNET_CRYPTO_ecdsa_key_create_from_file (keyfile); 795 return;
704 }
705 GNUNET_free(keyfile);
706 } 796 }
707 797
708 gns = GNUNET_GNS_connect (cfg); 798 id_op = GNUNET_IDENTITY_get (identity, "gns-master", &identity_master_cb,
709 if (gns == NULL) 799 NULL);
710 return; 800 GNUNET_assert (NULL != id_op);
711 801
712 GNUNET_SERVER_add_handlers (server, handlers); 802 GNUNET_SERVER_add_handlers (server, handlers);
713 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
714 NULL);
715
716} 803}
717 804
718 805
@@ -728,12 +815,9 @@ main (int argc, char *const *argv)
728{ 815{
729 int ret; 816 int ret;
730 817
731 ret = 818 ret = GNUNET_SERVICE_run (argc, argv, "gns-helper-service-w32",
732 (GNUNET_OK == 819 GNUNET_SERVICE_OPTION_NONE, &run, NULL);
733 GNUNET_SERVICE_run (argc, argv, "gns-helper-service-w32", GNUNET_SERVICE_OPTION_NONE, 820 return (GNUNET_OK == ret) ? 0 : 1;
734 &run, NULL)) ? 0 : 1;
735
736 return ret;
737} 821}
738 822
739/* end of gnunet-gns-helper-service-w32.c */ 823/* end of gnunet-gns-helper-service-w32.c */
diff --git a/src/gns/w32nsp.c b/src/gns/w32nsp.c
index 79609eb5a..d6a589d4f 100644
--- a/src/gns/w32nsp.c
+++ b/src/gns/w32nsp.c
@@ -337,10 +337,10 @@ GNUNET_W32NSP_LookupServiceBegin (LPGUID lpProviderId, LPWSAQUERYSETW lpqsRestri
337 { 337 {
338 wchar_t *s = lpqsRestrictions->lpszServiceInstanceName; 338 wchar_t *s = lpqsRestrictions->lpszServiceInstanceName;
339 size_t len = wcslen (s); 339 size_t len = wcslen (s);
340 if (len >= 4 && wcscmp (&s[len - 4], L"zkey") == 0) 340 if (len >= 5 && wcscmp (&s[len - 5], L".zkey") == 0)
341 { 341 {
342 } 342 }
343 else if (len >= 4 && wcscmp (&s[len - 4], L"gnu") == 0) 343 else if (len >= 4 && wcscmp (&s[len - 4], L".gnu") == 0)
344 { 344 {
345 } 345 }
346 else 346 else