aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-02-25 04:05:28 +0100
committerChristian Grothoff <christian@grothoff.org>2017-02-25 04:05:28 +0100
commitf27515316a9374e88c689b7e039b3902bd56b5a1 (patch)
tree8d8068a98193bf09f4ed0ea7a978eb5e022750d0 /src/gns
parent27f28018356c87db9b5710c3f66f01349a46b489 (diff)
downloadgnunet-f27515316a9374e88c689b7e039b3902bd56b5a1.tar.gz
gnunet-f27515316a9374e88c689b7e039b3902bd56b5a1.zip
updating gnunet-gns-helper-service-w32 to current APIs
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/gnunet-gns-helper-service-w32.c452
1 files changed, 229 insertions, 223 deletions
diff --git a/src/gns/gnunet-gns-helper-service-w32.c b/src/gns/gnunet-gns-helper-service-w32.c
index bfee2b498..c0482d931 100644
--- a/src/gns/gnunet-gns-helper-service-w32.c
+++ b/src/gns/gnunet-gns-helper-service-w32.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V. 3 Copyright (C) 2012, 2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -48,6 +48,7 @@ DEFINE_DNS_GUID(SVCID_DNS_TYPE_SRV, 0x0021);
48DEFINE_GUID(SVCID_HOSTNAME, 0x0002a800, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); 48DEFINE_GUID(SVCID_HOSTNAME, 0x0002a800, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
49DEFINE_GUID(SVCID_INET_HOSTADDRBYNAME, 0x0002a803, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); 49DEFINE_GUID(SVCID_INET_HOSTADDRBYNAME, 0x0002a803, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
50 50
51
51struct request 52struct request
52{ 53{
53 /** 54 /**
@@ -60,14 +61,23 @@ struct request
60 */ 61 */
61 struct request *prev; 62 struct request *prev;
62 63
63 struct GNUNET_SERVER_Client *client; 64 /**
65 * Client that issued the request
66 */
67 struct GNUNET_SERVICE_Client *client;
68
64 GUID sc; 69 GUID sc;
70
65 int af; 71 int af;
72
66 wchar_t *name; 73 wchar_t *name;
74
67 char *u8name; 75 char *u8name;
76
68 struct GNUNET_GNS_LookupRequest *lookup_request; 77 struct GNUNET_GNS_LookupRequest *lookup_request;
69}; 78};
70 79
80
71/** 81/**
72 * Head of the doubly-linked list (for cleanup). 82 * Head of the doubly-linked list (for cleanup).
73 */ 83 */
@@ -99,14 +109,10 @@ static struct GNUNET_IDENTITY_Handle *identity;
99static struct GNUNET_CRYPTO_EcdsaPublicKey gns_master_pubkey; 109static struct GNUNET_CRYPTO_EcdsaPublicKey gns_master_pubkey;
100 110
101/** 111/**
102 * Private key of the gns-short ego
103 */
104static struct GNUNET_CRYPTO_EcdsaPrivateKey gns_short_privkey;
105
106/**
107 * Set to 1 once egos are obtained. 112 * Set to 1 once egos are obtained.
108 */ 113 */
109static int got_egos = 0; 114static int got_egos;
115
110 116
111/** 117/**
112 * Task run on shutdown. Cleans up everything. 118 * Task run on shutdown. Cleans up everything.
@@ -117,6 +123,7 @@ static void
117do_shutdown (void *cls) 123do_shutdown (void *cls)
118{ 124{
119 struct request *rq; 125 struct request *rq;
126
120 if (NULL != id_op) 127 if (NULL != id_op)
121 { 128 {
122 GNUNET_IDENTITY_cancel (id_op); 129 GNUNET_IDENTITY_cancel (id_op);
@@ -130,8 +137,10 @@ do_shutdown (void *cls)
130 while (NULL != (rq = rq_head)) 137 while (NULL != (rq = rq_head))
131 { 138 {
132 if (NULL != rq->lookup_request) 139 if (NULL != rq->lookup_request)
133 GNUNET_GNS_lookup_cancel(rq->lookup_request); 140 GNUNET_GNS_lookup_cancel (rq->lookup_request);
134 GNUNET_CONTAINER_DLL_remove (rq_head, rq_tail, rq); 141 GNUNET_CONTAINER_DLL_remove (rq_head,
142 rq_tail,
143 rq);
135 GNUNET_free_non_null (rq->name); 144 GNUNET_free_non_null (rq->name);
136 if (rq->u8name) 145 if (rq->u8name)
137 free (rq->u8name); 146 free (rq->u8name);
@@ -144,56 +153,6 @@ do_shutdown (void *cls)
144 } 153 }
145} 154}
146 155
147/**
148 * Context for transmitting replies to clients.
149 */
150struct TransmitCallbackContext
151{
152
153 /**
154 * We keep these in a doubly-linked list (for cleanup).
155 */
156 struct TransmitCallbackContext *next;
157
158 /**
159 * We keep these in a doubly-linked list (for cleanup).
160 */
161 struct TransmitCallbackContext *prev;
162
163 /**
164 * The message that we're asked to transmit.
165 */
166 struct GNUNET_MessageHeader *msg;
167
168 /**
169 * Handle for the transmission request.
170 */
171 struct GNUNET_SERVER_TransmitHandle *th;
172
173
174 /**
175 * Handle for the client to which to send
176 */
177 struct GNUNET_SERVER_Client *client;
178};
179
180
181/**
182 * Head of the doubly-linked list (for cleanup).
183 */
184static struct TransmitCallbackContext *tcc_head;
185
186/**
187 * Tail of the doubly-linked list (for cleanup).
188 */
189static struct TransmitCallbackContext *tcc_tail;
190
191/**
192 * Have we already cleaned up the TCCs and are hence no longer
193 * willing (or able) to transmit anything to anyone?
194 */
195static int cleaning_done;
196
197 156
198/** 157/**
199 * Function called to notify a client about the socket 158 * Function called to notify a client about the socket
@@ -249,26 +208,17 @@ transmit_callback (void *cls, size_t size, void *buf)
249 * @param msg message to transmit, will be freed! 208 * @param msg message to transmit, will be freed!
250 */ 209 */
251static void 210static void
252transmit (struct GNUNET_SERVER_Client *client, 211transmit (struct GNUNET_SERVICE_Client *client,
253 struct GNUNET_MessageHeader *msg) 212 struct GNUNET_MessageHeader *msg)
254{ 213{
255 struct TransmitCallbackContext *tcc; 214 struct GNUNET_MQ_Handle *mq = GNUNET_SERVICE_client_get_mq (client);
256 215 struct GNUNET_MQ_Envelope *env;
257 if (GNUNET_YES == cleaning_done) 216
258 { 217 /* NOTE: small hack here, should have constructed and
259 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 218 passed an 'env' in the first place... */
260 _("Shutdown in progress, aborting transmission.\n")); 219 env = GNUNET_MQ_msg_copy (msg);
261 GNUNET_free (msg); 220 GNUNET_MQ_send (mq,
262 return; 221 env);
263 }
264 tcc = GNUNET_new (struct TransmitCallbackContext);
265 tcc->msg = msg;
266 tcc->client = client;
267 tcc->th = GNUNET_SERVER_notify_transmit_ready (client,
268 ntohs (msg->size),
269 GNUNET_TIME_UNIT_FOREVER_REL,
270 &transmit_callback, tcc);
271 GNUNET_CONTAINER_DLL_insert (tcc_head, tcc_tail, tcc);
272} 222}
273 223
274 224
@@ -280,7 +230,6 @@ transmit (struct GNUNET_SERVER_Client *client,
280void 230void
281MarshallWSAQUERYSETW (WSAQUERYSETW *qs, GUID *sc) 231MarshallWSAQUERYSETW (WSAQUERYSETW *qs, GUID *sc)
282{ 232{
283 int i;
284 MarshallPtr (qs->lpszServiceInstanceName, qs, wchar_t); 233 MarshallPtr (qs->lpszServiceInstanceName, qs, wchar_t);
285 MarshallPtr (qs->lpServiceClassId, qs, GUID); 234 MarshallPtr (qs->lpServiceClassId, qs, GUID);
286 MarshallPtr (qs->lpVersion, qs, WSAVERSION); 235 MarshallPtr (qs->lpVersion, qs, WSAVERSION);
@@ -288,7 +237,7 @@ MarshallWSAQUERYSETW (WSAQUERYSETW *qs, GUID *sc)
288 MarshallPtr (qs->lpszContext, qs, wchar_t); 237 MarshallPtr (qs->lpszContext, qs, wchar_t);
289 MarshallPtr (qs->lpafpProtocols, qs, AFPROTOCOLS); 238 MarshallPtr (qs->lpafpProtocols, qs, AFPROTOCOLS);
290 MarshallPtr (qs->lpszQueryString, qs, wchar_t); 239 MarshallPtr (qs->lpszQueryString, qs, wchar_t);
291 for (i = 0; i < qs->dwNumberOfCsAddrs; i++) 240 for (int i = 0; i < qs->dwNumberOfCsAddrs; i++)
292 { 241 {
293 MarshallPtr (qs->lpcsaBuffer[i].LocalAddr.lpSockaddr, qs, SOCKADDR); 242 MarshallPtr (qs->lpcsaBuffer[i].LocalAddr.lpSockaddr, qs, SOCKADDR);
294 MarshallPtr (qs->lpcsaBuffer[i].RemoteAddr.lpSockaddr, qs, SOCKADDR); 243 MarshallPtr (qs->lpcsaBuffer[i].RemoteAddr.lpSockaddr, qs, SOCKADDR);
@@ -297,12 +246,13 @@ MarshallWSAQUERYSETW (WSAQUERYSETW *qs, GUID *sc)
297 if (IsEqualGUID (&SVCID_INET_HOSTADDRBYNAME, sc) && qs->lpBlob != NULL && qs->lpBlob->pBlobData != NULL) 246 if (IsEqualGUID (&SVCID_INET_HOSTADDRBYNAME, sc) && qs->lpBlob != NULL && qs->lpBlob->pBlobData != NULL)
298 { 247 {
299 struct hostent *he; 248 struct hostent *he;
249
300 he = (struct hostent *) qs->lpBlob->pBlobData; 250 he = (struct hostent *) qs->lpBlob->pBlobData;
301 for (i = 0; he->h_aliases[i] != NULL; i++) 251 for (int i = 0; he->h_aliases[i] != NULL; i++)
302 MarshallPtr (he->h_aliases[i], he, char); 252 MarshallPtr (he->h_aliases[i], he, char);
303 MarshallPtr (he->h_aliases, he, char *); 253 MarshallPtr (he->h_aliases, he, char *);
304 MarshallPtr (he->h_name, he, char); 254 MarshallPtr (he->h_name, he, char);
305 for (i = 0; he->h_addr_list[i] != NULL; i++) 255 for (int i = 0; he->h_addr_list[i] != NULL; i++)
306 MarshallPtr (he->h_addr_list[i], he, void); 256 MarshallPtr (he->h_addr_list[i], he, void);
307 MarshallPtr (he->h_addr_list, he, char *); 257 MarshallPtr (he->h_addr_list, he, char *);
308 MarshallPtr (qs->lpBlob->pBlobData, qs, void); 258 MarshallPtr (qs->lpBlob->pBlobData, qs, void);
@@ -312,11 +262,12 @@ MarshallWSAQUERYSETW (WSAQUERYSETW *qs, GUID *sc)
312 262
313 263
314static void 264static void
315process_lookup_result (void* cls, uint32_t rd_count, 265process_lookup_result (void *cls,
316 const struct GNUNET_GNSRECORD_Data *rd) 266 uint32_t rd_count,
267 const struct GNUNET_GNSRECORD_Data *rd)
317{ 268{
269 struct request *rq = cls;
318 int i, j, csanum; 270 int i, j, csanum;
319 struct request *rq = (struct request *) cls;
320 struct GNUNET_W32RESOLVER_GetMessage *msg; 271 struct GNUNET_W32RESOLVER_GetMessage *msg;
321 struct GNUNET_MessageHeader *msgend; 272 struct GNUNET_MessageHeader *msgend;
322 WSAQUERYSETW *qs; 273 WSAQUERYSETW *qs;
@@ -327,18 +278,22 @@ process_lookup_result (void* cls, uint32_t rd_count,
327 size_t blobaddrcount = 0; 278 size_t blobaddrcount = 0;
328 279
329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
330 "Got lookup result with count %u for rq %p with client %p\n", 281 "Got lookup result with count %u for rq %p with client %p\n",
331 rd_count, rq, rq->client); 282 rd_count,
283 rq,
284 rq->client);
332 rq->lookup_request = NULL; 285 rq->lookup_request = NULL;
333 286
334 if (rd_count == 0) 287 if (0 == rd_count)
335 { 288 {
336 size = sizeof (struct GNUNET_MessageHeader); 289 msg = GNUNET_new (struct GNUNET_MessageHeader);
337 msg = GNUNET_malloc (size); 290 msg->header.size = htons (sizeof (struct GNUNET_MessageHeader));
338 msg->header.size = htons (size);
339 msg->header.type = htons (GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE); 291 msg->header.type = htons (GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
340 transmit (rq->client, &msg->header); 292 transmit (rq->client,
341 GNUNET_CONTAINER_DLL_remove (rq_head, rq_tail, rq); 293 &msg->header);
294 GNUNET_CONTAINER_DLL_remove (rq_head,
295 rq_tail,
296 rq);
342 GNUNET_free_non_null (rq->name); 297 GNUNET_free_non_null (rq->name);
343 if (rq->u8name) 298 if (rq->u8name)
344 free (rq->u8name); 299 free (rq->u8name);
@@ -564,12 +519,20 @@ process_lookup_result (void* cls, uint32_t rd_count,
564 519
565 if ((char *) ptr - (char *) msg != size || size_recalc != size || size_recalc != ((char *) ptr - (char *) msg)) 520 if ((char *) ptr - (char *) msg != size || size_recalc != size || size_recalc != ((char *) ptr - (char *) msg))
566 { 521 {
567 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error in WSAQUERYSETW size calc: expected %lu, got %lu (recalc %lu)\n", size, (unsigned long) ((char *) ptr - (char *) msg), size_recalc); 522 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
523 "Error in WSAQUERYSETW size calc: expected %lu, got %lu (recalc %lu)\n",
524 size,
525 (unsigned long) ((char *) ptr - (char *) msg),
526 size_recalc);
568 } 527 }
569 MarshallWSAQUERYSETW (qs, &rq->sc); 528 MarshallWSAQUERYSETW (qs, &rq->sc);
570 transmit (rq->client, &msg->header); 529 transmit (rq->client,
571 transmit (rq->client, msgend); 530 &msg->header);
572 GNUNET_CONTAINER_DLL_remove (rq_head, rq_tail, rq); 531 transmit (rq->client,
532 msgend);
533 GNUNET_CONTAINER_DLL_remove (rq_head,
534 rq_tail,
535 rq);
573 GNUNET_free_non_null (rq->name); 536 GNUNET_free_non_null (rq->name);
574 if (rq->u8name) 537 if (rq->u8name)
575 free (rq->u8name); 538 free (rq->u8name);
@@ -578,8 +541,10 @@ process_lookup_result (void* cls, uint32_t rd_count,
578 541
579 542
580static void 543static void
581get_ip_from_hostname (struct GNUNET_SERVER_Client *client, 544get_ip_from_hostname (struct GNUNET_SERVICE_Client *client,
582 const wchar_t *name, int af, GUID sc) 545 const wchar_t *name,
546 int af,
547 GUID sc)
583{ 548{
584 struct request *rq; 549 struct request *rq;
585 char *hostname; 550 char *hostname;
@@ -611,9 +576,18 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
611 { 576 {
612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
613 "Unknown GUID: %08X-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n", 578 "Unknown GUID: %08X-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
614 sc.Data1, sc.Data2, sc.Data3, sc.Data4[0], sc.Data4[1], sc.Data4[2], 579 sc.Data1,
615 sc.Data4[3], sc.Data4[4], sc.Data4[5], sc.Data4[6], sc.Data4[7]); 580 sc.Data2,
616 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 581 sc.Data3,
582 sc.Data4[0],
583 sc.Data4[1],
584 sc.Data4[2],
585 sc.Data4[3],
586 sc.Data4[4],
587 sc.Data4[5],
588 sc.Data4[6],
589 sc.Data4[7]);
590 GNUNET_SERVICE_client_drop (client);
617 return; 591 return;
618 } 592 }
619 593
@@ -640,24 +614,31 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
640 if (namelen) 614 if (namelen)
641 { 615 {
642 rq->name = GNUNET_malloc ((namelen + 1) * sizeof (wchar_t)); 616 rq->name = GNUNET_malloc ((namelen + 1) * sizeof (wchar_t));
643 GNUNET_memcpy (rq->name, name, (namelen + 1) * sizeof (wchar_t)); 617 GNUNET_memcpy (rq->name,
618 name,
619 (namelen + 1) * sizeof (wchar_t));
644 rq->u8name = hostname; 620 rq->u8name = hostname;
645 } 621 }
646 622
647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
648 "Launching a lookup for client %p with rq %p\n", 624 "Launching a lookup for client %p with rq %p\n",
649 client, rq); 625 client,
650 626 rq);
651 rq->lookup_request = GNUNET_GNS_lookup (gns, hostname, &gns_master_pubkey, 627 rq->lookup_request = GNUNET_GNS_lookup (gns,
652 rtype, GNUNET_NO /* Use DHT */, &gns_short_privkey, &process_lookup_result, 628 hostname,
653 rq); 629 &gns_master_pubkey,
654 630 rtype,
631 GNUNET_NO /* Use DHT */,
632 &process_lookup_result,
633 rq);
655 if (NULL != rq->lookup_request) 634 if (NULL != rq->lookup_request)
656 { 635 {
657 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 636 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
658 "Lookup launched, waiting for a reply\n"); 637 "Lookup launched, waiting for a reply\n");
659 GNUNET_SERVER_receive_done (client, GNUNET_OK); 638 GNUNET_SERVICE_client_continue (client);
660 GNUNET_CONTAINER_DLL_insert (rq_head, rq_tail, rq); 639 GNUNET_CONTAINER_DLL_insert (rq_head,
640 rq_tail,
641 rq);
661 } 642 }
662 else 643 else
663 { 644 {
@@ -667,110 +648,105 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
667 if (rq->u8name) 648 if (rq->u8name)
668 free (rq->u8name); 649 free (rq->u8name);
669 GNUNET_free (rq); 650 GNUNET_free (rq);
670 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 651 GNUNET_SERVICE_client_drop (client);
671 } 652 }
672} 653}
673 654
674 655
675/** 656/**
676 * Handle GET-message. 657 * Check GET-message.
677 * 658 *
678 * @param cls closure 659 * @param cls identification of the client
679 * @param client identification of the client 660 * @param msg the actual message
680 * @param message the actual message 661 * @return #GNUNET_OK if @a msg is well-formed
681 */ 662 */
682static void 663static int
683handle_get (void *cls, struct GNUNET_SERVER_Client *client, 664check_get (void *cls,
684 const struct GNUNET_MessageHeader *message) 665 const struct GNUNET_W32RESOLVER_GetMessage *msg)
685{ 666{
686 uint16_t msize;
687 const struct GNUNET_W32RESOLVER_GetMessage *msg;
688 GUID sc;
689 uint16_t size; 667 uint16_t size;
690 int i;
691 const wchar_t *hostname; 668 const wchar_t *hostname;
692 int af;
693 669
694 if (!got_egos) 670 if (! got_egos)
695 { 671 {
696 /* 672 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
697 * FIXME: be done with GNUNET_OK, put the get request into a queue? 673 _("Not ready to process requests, lacking ego data\n"));
698 * or postpone GNUNET_SERVER_add_handlers() until egos are obtained? 674 return GNUNET_SYSERR;
699 */
700 GNUNET_SERVER_receive_done (client, GNUNET_NO);
701 return;
702 } 675 }
703 676 size = ntohs (msg->header.size) - sizeof (struct GNUNET_W32RESOLVER_GetMessage);
704 msize = ntohs (message->size);
705 if (msize <= sizeof (struct GNUNET_W32RESOLVER_GetMessage))
706 {
707 GNUNET_break (0);
708 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
709 return;
710 }
711 msg = (const struct GNUNET_W32RESOLVER_GetMessage *) message;
712 size = msize - sizeof (struct GNUNET_W32RESOLVER_GetMessage);
713 af = ntohl (msg->af);
714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
715 "Got NBO GUID: %08X-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
716 msg->sc_data1, msg->sc_data2, msg->sc_data3, msg->sc_data4[0], msg->sc_data4[1],
717 msg->sc_data4[2], msg->sc_data4[3], msg->sc_data4[4], msg->sc_data4[5],
718 msg->sc_data4[6], msg->sc_data4[7]);
719 sc.Data1 = ntohl (msg->sc_data1);
720 sc.Data2 = ntohs (msg->sc_data2);
721 sc.Data3 = ntohs (msg->sc_data3);
722 for (i = 0; i < 8; i++)
723 sc.Data4[i] = msg->sc_data4[i];
724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
725 "Got GUID: %08X-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
726 sc.Data1, sc.Data2, sc.Data3, sc.Data4[0], sc.Data4[1], sc.Data4[2],
727 sc.Data4[3], sc.Data4[4], sc.Data4[5], sc.Data4[6], sc.Data4[7]);
728
729 hostname = (const wchar_t *) &msg[1]; 677 hostname = (const wchar_t *) &msg[1];
730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "name of %u bytes (last word is 0x%0X): %*S\n",
731 size, hostname[size / 2 - 2], size / 2, hostname);
732 if (hostname[size / 2 - 1] != L'\0') 678 if (hostname[size / 2 - 1] != L'\0')
733 { 679 {
734 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "name of length %u, not 0-terminated (%d-th word is 0x%0X): %*S\n",
735 size, size / 2 - 1, hostname[size / 2 - 1], size, hostname);
736 GNUNET_break (0); 680 GNUNET_break (0);
737 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 681 return GNUNET_SYSERR;
738 return;
739 } 682 }
740 get_ip_from_hostname (client, hostname, af, sc); 683 return GNUNET_OK;
741} 684}
742 685
743 686
744/** 687/**
745 * Method called to with the ego we are to use for shortening 688 * Handle GET-message.
746 * during the lookup.
747 * 689 *
748 * @param cls closure (NULL, unused) 690 * @param cls identification of the client
749 * @param ego ego handle, NULL if not found 691 * @param msg the actual message
750 * @param ctx context for application to store data for this ego
751 * (during the lifetime of this process, initially NULL)
752 * @param name name assigned by the user for this ego,
753 * NULL if the user just deleted the ego and it
754 * must thus no longer be used
755 */ 692 */
756static void 693static void
757identity_shorten_cb (void *cls, 694handle_get (void *cls,
758 struct GNUNET_IDENTITY_Ego *ego, 695 const struct GNUNET_W32RESOLVER_GetMessage *msg)
759 void **ctx,
760 const char *name)
761{ 696{
762 id_op = NULL; 697 struct GNUNET_SERVICE_Client *client = cls;
763 if (NULL == ego) 698 GUID sc;
764 { 699 uint16_t size;
765 fprintf (stderr, 700 const wchar_t *hostname;
766 _("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")); 701 int af;
767 GNUNET_SCHEDULER_shutdown (); 702
768 return; 703 size = ntohs (msg->header.size) - sizeof (struct GNUNET_W32RESOLVER_GetMessage);
769 } 704 af = ntohl (msg->af);
770 gns_short_privkey = *GNUNET_IDENTITY_ego_get_private_key (ego); 705 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
771 got_egos = 1; 706 "Got NBO GUID: %08X-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
707 msg->sc_data1,
708 msg->sc_data2,
709 msg->sc_data3,
710 msg->sc_data4[0],
711 msg->sc_data4[1],
712 msg->sc_data4[2],
713 msg->sc_data4[3],
714 msg->sc_data4[4],
715 msg->sc_data4[5],
716 msg->sc_data4[6],
717 msg->sc_data4[7]);
718 sc.Data1 = ntohl (msg->sc_data1);
719 sc.Data2 = ntohs (msg->sc_data2);
720 sc.Data3 = ntohs (msg->sc_data3);
721 for (int i = 0; i < 8; i++)
722 sc.Data4[i] = msg->sc_data4[i];
723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
724 "Got GUID: %08X-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
725 sc.Data1,
726 sc.Data2,
727 sc.Data3,
728 sc.Data4[0],
729 sc.Data4[1],
730 sc.Data4[2],
731 sc.Data4[3],
732 sc.Data4[4],
733 sc.Data4[5],
734 sc.Data4[6],
735 sc.Data4[7]);
736 hostname = (const wchar_t *) &msg[1];
737 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
738 "Name of %u bytes (last word is 0x%0X): %*S\n",
739 size,
740 hostname[size / 2 - 2],
741 size / 2,
742 hostname);
743 get_ip_from_hostname (client,
744 hostname,
745 af,
746 sc);
772} 747}
773 748
749
774/** 750/**
775 * Method called to with the ego we are to use for the lookup, 751 * Method called to with the ego we are to use for the lookup,
776 * when the ego is the one for the default master zone. 752 * when the ego is the one for the default master zone.
@@ -785,22 +761,21 @@ identity_shorten_cb (void *cls,
785 */ 761 */
786static void 762static void
787identity_master_cb (void *cls, 763identity_master_cb (void *cls,
788 struct GNUNET_IDENTITY_Ego *ego, 764 struct GNUNET_IDENTITY_Ego *ego,
789 void **ctx, 765 void **ctx,
790 const char *name) 766 const char *name)
791{ 767{
792 id_op = NULL; 768 id_op = NULL;
793 if (NULL == ego) 769 if (NULL == ego)
794 { 770 {
795 fprintf (stderr, 771 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
796 _("Ego for `gns-master' not found, cannot perform lookup. Did you run gnunet-gns-import.sh?\n")); 772 _("Ego for `gns-master' not found, cannot perform lookup. Did you run gnunet-gns-import.sh?\n"));
797 GNUNET_SCHEDULER_shutdown (); 773 GNUNET_SCHEDULER_shutdown ();
798 return; 774 return;
799 } 775 }
800 GNUNET_IDENTITY_ego_get_public_key (ego, &gns_master_pubkey); 776 GNUNET_IDENTITY_ego_get_public_key (ego,
801 id_op = GNUNET_IDENTITY_get (identity, "gns-short", &identity_shorten_cb, 777 &gns_master_pubkey);
802 NULL); 778 got_egos = 1;
803 GNUNET_assert (NULL != id_op);
804} 779}
805 780
806 781
@@ -808,59 +783,90 @@ identity_master_cb (void *cls,
808 * Start up gns-helper-w32 service. 783 * Start up gns-helper-w32 service.
809 * 784 *
810 * @param cls closure 785 * @param cls closure
811 * @param server the initialized server
812 * @param cfg configuration to use 786 * @param cfg configuration to use
787 * @param service the initialized service
813 */ 788 */
814static void 789static void
815run (void *cls, struct GNUNET_SERVER_Handle *server, 790run (void *cls,
816 const struct GNUNET_CONFIGURATION_Handle *cfg) 791 const struct GNUNET_CONFIGURATION_Handle *cfg,
792 struct GNUNET_SERVICE_Handle *service)
817{ 793{
818 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
819 {&handle_get, NULL, GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST, 0},
820 {NULL, NULL, 0, 0}
821 };
822
823 gns = GNUNET_GNS_connect (cfg); 794 gns = GNUNET_GNS_connect (cfg);
824 if (NULL == gns) 795 if (NULL == gns)
825 { 796 {
826 fprintf (stderr, _("Failed to connect to GNS\n")); 797 fprintf (stderr,
798 _("Failed to connect to GNS\n"));
827 GNUNET_SCHEDULER_shutdown (); 799 GNUNET_SCHEDULER_shutdown ();
828 return; 800 return;
829 } 801 }
830 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 802 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
831 NULL); 803 NULL);
832 804 identity = GNUNET_IDENTITY_connect (cfg,
833 identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL); 805 NULL,
806 NULL);
834 if (NULL == identity) 807 if (NULL == identity)
835 { 808 {
836 fprintf (stderr, _("Failed to connect to identity service\n")); 809 fprintf (stderr,
810 _("Failed to connect to identity service\n"));
837 GNUNET_SCHEDULER_shutdown (); 811 GNUNET_SCHEDULER_shutdown ();
838 return; 812 return;
839 } 813 }
840 814 id_op = GNUNET_IDENTITY_get (identity,
841 id_op = GNUNET_IDENTITY_get (identity, "gns-master", &identity_master_cb, 815 "gns-master",
842 NULL); 816 &identity_master_cb,
817 NULL);
843 GNUNET_assert (NULL != id_op); 818 GNUNET_assert (NULL != id_op);
844
845 GNUNET_SERVER_add_handlers (server, handlers);
846} 819}
847 820
848 821
849/** 822/**
850 * The main function for gns-helper-w32. 823 * Handle client connecting to the service.
851 * 824 *
852 * @param argc number of arguments from the command line 825 * @param cls NULL
853 * @param argv command line arguments 826 * @param client the new client
854 * @return 0 ok, 1 on error 827 * @param mq the message queue of @a client
828 * @return @a client
855 */ 829 */
856int 830static void *
857main (int argc, char *const *argv) 831client_connect_cb (void *cls,
832 struct GNUNET_SERVICE_Client *client,
833 struct GNUNET_MQ_Handle *mq)
858{ 834{
859 int ret; 835 return client;
836}
837
860 838
861 ret = GNUNET_SERVICE_run (argc, argv, "gns-helper-service-w32", 839/**
862 GNUNET_SERVICE_OPTION_NONE, &run, NULL); 840 * Callback called when a client disconnected from the service
863 return (GNUNET_OK == ret) ? 0 : 1; 841 *
842 * @param cls closure for the service
843 * @param c the client that disconnected
844 * @param internal_cls should be equal to @a c
845 */
846static void
847client_disconnect_cb (void *cls,
848 struct GNUNET_SERVICE_Client *client,
849 void *internal_cls)
850{
851 GNUNET_assert (internal_cls == client);
864} 852}
865 853
854
855/**
856 * Define "main" method using service macro.
857 */
858GNUNET_SERVICE_MAIN
859("gns-helper-service-w32",
860 GNUNET_SERVICE_OPTION_NONE,
861 &run,
862 &client_connect_cb,
863 &client_disconnect_cb,
864 NULL,
865 GNUNET_MQ_hd_var_size (get,
866 GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST,
867 struct GNUNET_W32RESOLVER_GetMessage,
868 NULL),
869 GNUNET_MQ_handler_end());
870
871
866/* end of gnunet-gns-helper-service-w32.c */ 872/* end of gnunet-gns-helper-service-w32.c */