2 This file is part of GNUnet.
3 Copyright (C) 2012, 2017 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
16 * @file gnunet-gns-helper-service-w32.c
17 * @brief an intermediary service to access distributed GNS
18 * @author Christian Grothoff
22 #include <gnunet_util_lib.h>
23 #include <gnunet_identity_service.h>
24 #include <gnunet_dnsparser_lib.h>
25 #include <gnunet_namestore_service.h>
26 #include <gnunet_gns_service.h>
28 #include "gnunet_w32nsp_lib.h"
29 #include "w32resolver.h"
33 #define DEFINE_DNS_GUID(a,x) DEFINE_GUID(a, 0x00090035, 0x0000, x, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46)
34 DEFINE_DNS_GUID(SVCID_DNS_TYPE_A, 0x0001);
35 DEFINE_DNS_GUID(SVCID_DNS_TYPE_NS, 0x0002);
36 DEFINE_DNS_GUID(SVCID_DNS_TYPE_CNAME, 0x0005);
37 DEFINE_DNS_GUID(SVCID_DNS_TYPE_SOA, 0x0006);
38 DEFINE_DNS_GUID(SVCID_DNS_TYPE_PTR, 0x000c);
39 DEFINE_DNS_GUID(SVCID_DNS_TYPE_MX, 0x000f);
40 DEFINE_DNS_GUID(SVCID_DNS_TYPE_TEXT, 0x0010);
41 DEFINE_DNS_GUID(SVCID_DNS_TYPE_AAAA, 0x001c);
42 DEFINE_DNS_GUID(SVCID_DNS_TYPE_SRV, 0x0021);
43 DEFINE_GUID(SVCID_HOSTNAME, 0x0002a800, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
44 DEFINE_GUID(SVCID_INET_HOSTADDRBYNAME, 0x0002a803, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
50 * We keep these in a doubly-linked list (for cleanup).
55 * We keep these in a doubly-linked list (for cleanup).
60 * Client that issued the request
62 struct GNUNET_SERVICE_Client *client;
72 struct GNUNET_GNS_LookupRequest *lookup_request;
77 * Head of the doubly-linked list (for cleanup).
79 static struct request *rq_head;
82 * Tail of the doubly-linked list (for cleanup).
84 static struct request *rq_tail;
87 * Handle to GNS service.
89 static struct GNUNET_GNS_Handle *gns;
92 * Active operation on identity service.
94 static struct GNUNET_IDENTITY_Operation *id_op;
97 * Handle for identity service.
99 static struct GNUNET_IDENTITY_Handle *identity;
102 * Public key of the gns-master ego
104 static struct GNUNET_CRYPTO_EcdsaPublicKey gns_master_pubkey;
107 * Set to 1 once egos are obtained.
113 * Task run on shutdown. Cleans up everything.
118 do_shutdown (void *cls)
124 GNUNET_IDENTITY_cancel (id_op);
127 if (NULL != identity)
129 GNUNET_IDENTITY_disconnect (identity);
132 while (NULL != (rq = rq_head))
134 if (NULL != rq->lookup_request)
135 GNUNET_GNS_lookup_cancel (rq->lookup_request);
136 GNUNET_CONTAINER_DLL_remove (rq_head,
139 GNUNET_free_non_null (rq->name);
146 GNUNET_GNS_disconnect (gns);
152 #define MarshallPtr(ptr, base, type) \
154 ptr = (type *) ((char *) ptr - (char *) base)
158 MarshallWSAQUERYSETW (WSAQUERYSETW *qs, GUID *sc)
160 MarshallPtr (qs->lpszServiceInstanceName, qs, wchar_t);
161 MarshallPtr (qs->lpServiceClassId, qs, GUID);
162 MarshallPtr (qs->lpVersion, qs, WSAVERSION);
163 MarshallPtr (qs->lpNSProviderId, qs, GUID);
164 MarshallPtr (qs->lpszContext, qs, wchar_t);
165 MarshallPtr (qs->lpafpProtocols, qs, AFPROTOCOLS);
166 MarshallPtr (qs->lpszQueryString, qs, wchar_t);
167 for (int i = 0; i < qs->dwNumberOfCsAddrs; i++)
169 MarshallPtr (qs->lpcsaBuffer[i].LocalAddr.lpSockaddr, qs, SOCKADDR);
170 MarshallPtr (qs->lpcsaBuffer[i].RemoteAddr.lpSockaddr, qs, SOCKADDR);
172 MarshallPtr (qs->lpcsaBuffer, qs, CSADDR_INFO);
173 if (IsEqualGUID (&SVCID_INET_HOSTADDRBYNAME, sc) && qs->lpBlob != NULL && qs->lpBlob->pBlobData != NULL)
177 he = (struct hostent *) qs->lpBlob->pBlobData;
178 for (int i = 0; he->h_aliases[i] != NULL; i++)
179 MarshallPtr (he->h_aliases[i], he, char);
180 MarshallPtr (he->h_aliases, he, char *);
181 MarshallPtr (he->h_name, he, char);
182 for (int i = 0; he->h_addr_list[i] != NULL; i++)
183 MarshallPtr (he->h_addr_list[i], he, void);
184 MarshallPtr (he->h_addr_list, he, char *);
185 MarshallPtr (qs->lpBlob->pBlobData, qs, void);
187 MarshallPtr (qs->lpBlob, qs, BLOB);
192 process_lookup_result (void *cls,
194 const struct GNUNET_GNSRECORD_Data *rd)
196 struct request *rq = cls;
198 struct GNUNET_W32RESOLVER_GetMessage *msg;
199 struct GNUNET_MQ_Envelope *msg_env;
200 struct GNUNET_MessageHeader *msgend;
201 struct GNUNET_MQ_Envelope *msgend_env;
207 size_t blobaddrcount = 0;
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
210 "Got lookup result with count %u for rq %p with client %p\n",
214 rq->lookup_request = NULL;
218 msgend_env = GNUNET_MQ_msg (msgend, GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
219 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (rq->client),
221 GNUNET_CONTAINER_DLL_remove (rq_head,
224 GNUNET_free_non_null (rq->name);
231 size = sizeof (struct GNUNET_W32RESOLVER_GetMessage) + sizeof (WSAQUERYSETW);
232 size += (wcslen (rq->name) + 1) * sizeof (wchar_t);
233 size += sizeof (GUID);
234 /* lpszComment ? a TXT record? */
235 size += sizeof (GUID);
236 /* lpszContext ? Not sure what it is */
238 for (i = 0; i < rd_count; i++)
240 switch (rd[i].record_type)
242 case GNUNET_DNSPARSER_TYPE_A:
243 if (rd[i].data_size != sizeof (struct in_addr))
245 size += sizeof (CSADDR_INFO) + sizeof (struct sockaddr_in) * 2;
248 case GNUNET_DNSPARSER_TYPE_AAAA:
249 if (rd[i].data_size != sizeof (struct in6_addr))
251 size += sizeof (CSADDR_INFO) + sizeof (struct sockaddr_in6) * 2;
256 if (IsEqualGUID (&SVCID_INET_HOSTADDRBYNAME, &rq->sc))
258 size += sizeof (BLOB);
259 blobsize += sizeof (struct hostent);
260 blobsize += strlen (rq->u8name) + 1;
261 blobsize += sizeof (void *); /* For aliases */
262 blobsize += sizeof (void *); /* For addresses */
263 for (i = 0; i < rd_count; i++)
265 if ((rq->af == AF_INET || rq->af == AF_UNSPEC) && rd[i].record_type == GNUNET_DNSPARSER_TYPE_A)
267 blobsize += sizeof (void *);
268 blobsize += sizeof (struct in_addr);
271 else if (rq->af == AF_INET6 && rd[i].record_type == GNUNET_DNSPARSER_TYPE_AAAA)
273 blobsize += sizeof (void *);
274 blobsize += sizeof (struct in6_addr);
280 size_recalc = sizeof (struct GNUNET_W32RESOLVER_GetMessage) + sizeof (WSAQUERYSETW);
281 msg_env = GNUNET_MQ_msg_extra (msg,
282 size - sizeof (struct GNUNET_MessageHeader),
283 GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
284 msg->af = htonl (rq->af);
285 msg->sc_data1 = htonl (rq->sc.Data1);
286 msg->sc_data2 = htons (rq->sc.Data2);
287 msg->sc_data3 = htons (rq->sc.Data3);
288 for (i = 0; i < 8; i++)
289 msg->sc_data4[i] = rq->sc.Data4[i];
290 qs = (WSAQUERYSETW *) &msg[1];
291 ptr = (char *) &qs[1];
292 GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg));
293 qs->dwSize = sizeof (WSAQUERYSETW);
294 qs->lpszServiceInstanceName = (wchar_t *) ptr;
295 ptr += (wcslen (rq->name) + 1) * sizeof (wchar_t);
296 size_recalc += (wcslen (rq->name) + 1) * sizeof (wchar_t);
297 GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg));
298 wcscpy (qs->lpszServiceInstanceName, rq->name);
299 qs->lpServiceClassId = (GUID *) ptr;
300 ptr += sizeof (GUID);
301 size_recalc += sizeof (GUID);
302 GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg));
303 GNUNET_memcpy (qs->lpServiceClassId, &rq->sc, sizeof (GUID));
304 qs->lpVersion = NULL;
305 qs->dwNameSpace = NS_DNS;
306 qs->lpNSProviderId = (GUID *) ptr;
307 ptr += sizeof (GUID);
308 size_recalc += sizeof (GUID);
309 GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg));
310 GNUNET_memcpy (qs->lpNSProviderId, &GNUNET_NAMESPACE_PROVIDER_DNS, sizeof (GUID));
311 qs->lpszContext = NULL;
312 qs->dwNumberOfProtocols = 0;
313 qs->lpafpProtocols = NULL;
314 /* Don't bother with this... */
315 qs->lpszQueryString = NULL;
316 qs->dwNumberOfCsAddrs = rd_count;
317 qs->lpcsaBuffer = (CSADDR_INFO *) ptr;
318 ptr += sizeof (CSADDR_INFO) * csanum;
320 for (i = 0; i < rd_count; i++)
322 switch (rd[i].record_type)
324 case GNUNET_DNSPARSER_TYPE_A:
325 if (rd[i].data_size != sizeof (struct in_addr))
327 qs->lpcsaBuffer[j].iSocketType = SOCK_STREAM;
328 qs->lpcsaBuffer[j].iProtocol = IPPROTO_TCP;
330 qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength = sizeof (struct sockaddr_in);
331 qs->lpcsaBuffer[j].LocalAddr.lpSockaddr = (SOCKADDR *) ptr;
332 ptr += qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength;
333 memset (qs->lpcsaBuffer[j].LocalAddr.lpSockaddr, 0, qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength);
334 ((struct sockaddr_in *)qs->lpcsaBuffer[j].LocalAddr.lpSockaddr)->sin_family = AF_INET;
336 qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength = sizeof (struct sockaddr_in);
337 qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr = (SOCKADDR *) ptr;
338 ptr += qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength;
339 memset (qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr, 0, qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength);
340 ((struct sockaddr_in *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin_family = AF_INET;
341 ((struct sockaddr_in *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin_port = htonl (53); /* Don't ask why it's 53 */
342 ((struct sockaddr_in *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin_addr = *(struct in_addr *) rd[i].data;
343 size_recalc += sizeof (CSADDR_INFO) + sizeof (struct sockaddr_in) * 2;
346 case GNUNET_DNSPARSER_TYPE_AAAA:
347 if (rd[i].data_size != sizeof (struct in6_addr))
349 qs->lpcsaBuffer[j].iSocketType = SOCK_STREAM;
350 qs->lpcsaBuffer[j].iProtocol = IPPROTO_TCP;
352 qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength = sizeof (struct sockaddr_in6);
353 qs->lpcsaBuffer[j].LocalAddr.lpSockaddr = (SOCKADDR *) ptr;
354 ptr += qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength;
355 memset (qs->lpcsaBuffer[j].LocalAddr.lpSockaddr, 0, qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength);
356 ((struct sockaddr_in6 *)qs->lpcsaBuffer[j].LocalAddr.lpSockaddr)->sin6_family = AF_INET6;
358 qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength = sizeof (struct sockaddr_in6);
359 qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr = (SOCKADDR *) ptr;
360 ptr += qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength;
361 memset (qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr, 0, qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength);
362 ((struct sockaddr_in6 *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin6_family = AF_INET6;
363 ((struct sockaddr_in6 *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin6_port = htonl (53); /* Don't ask why it's 53 */
364 ((struct sockaddr_in6 *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin6_addr = *(struct in6_addr *) rd[i].data;
365 size_recalc += sizeof (CSADDR_INFO) + sizeof (struct sockaddr_in6) * 2;
372 GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg));
373 qs->dwOutputFlags = 0;
374 if (IsEqualGUID (&SVCID_INET_HOSTADDRBYNAME, &rq->sc))
377 qs->lpBlob = (BLOB *) ptr;
378 ptr += sizeof (BLOB);
380 size_recalc += sizeof (BLOB);
381 GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg));
383 qs->lpBlob->cbSize = blobsize;
384 qs->lpBlob->pBlobData = (BYTE *) ptr;
385 ptr += sizeof (struct hostent);
387 size_recalc += sizeof (struct hostent);
388 GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg));
390 he = (struct hostent *) qs->lpBlob->pBlobData;
391 he->h_name = (char *) ptr;
392 ptr += strlen (rq->u8name) + 1;
394 size_recalc += strlen (rq->u8name) + 1;
395 GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg));
397 strcpy (he->h_name, rq->u8name);
398 he->h_aliases = (char **) ptr;
399 ptr += sizeof (void *);
401 size_recalc += sizeof (void *); /* For aliases */
402 GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg));
404 he->h_aliases[0] = NULL;
405 he->h_addrtype = rq->af;
406 he->h_length = rq->af == AF_INET || rq->af == AF_UNSPEC ? sizeof (struct in_addr) : sizeof (struct in6_addr);
407 he->h_addr_list = (char **) ptr;
408 ptr += sizeof (void *) * (blobaddrcount + 1);
410 size_recalc += sizeof (void *) * (blobaddrcount + 1); /* For addresses */
411 GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg));
414 for (i = 0; i < rd_count; i++)
416 if ((rq->af == AF_INET || rq->af == AF_UNSPEC) &&
417 rd[i].record_type == GNUNET_DNSPARSER_TYPE_A)
419 he->h_addr_list[j] = (char *) ptr;
420 ptr += sizeof (struct in_addr);
422 size_recalc += sizeof (struct in_addr);
423 GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg));
425 GNUNET_memcpy (he->h_addr_list[j], rd[i].data, sizeof (struct in_addr));
428 else if (rq->af == AF_INET6 && rd[i].record_type == GNUNET_DNSPARSER_TYPE_AAAA)
430 he->h_addr_list[j] = (char *) ptr;
431 ptr += sizeof (struct in6_addr);
433 size_recalc += sizeof (struct in6_addr);
434 GNUNET_break (size_recalc == (size_t) ((char *) ptr - (char *) msg));
436 GNUNET_memcpy (he->h_addr_list[j], rd[i].data, sizeof (struct in6_addr));
440 he->h_addr_list[j] = NULL;
442 msgend_env = GNUNET_MQ_msg (msgend, GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
444 if ((char *) ptr - (char *) msg != size || size_recalc != size || size_recalc != ((char *) ptr - (char *) msg))
446 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
447 "Error in WSAQUERYSETW size calc: expected %u, got %lu (recalc %u)\n",
449 (unsigned long) ((char *) ptr - (char *) msg),
452 MarshallWSAQUERYSETW (qs, &rq->sc);
453 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (rq->client),
455 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (rq->client),
457 GNUNET_CONTAINER_DLL_remove (rq_head,
460 GNUNET_free_non_null (rq->name);
468 get_ip_from_hostname (struct GNUNET_SERVICE_Client *client,
479 if (IsEqualGUID (&SVCID_DNS_TYPE_A, &sc))
480 rtype = GNUNET_DNSPARSER_TYPE_A;
481 else if (IsEqualGUID (&SVCID_DNS_TYPE_NS, &sc))
482 rtype = GNUNET_DNSPARSER_TYPE_NS;
483 else if (IsEqualGUID (&SVCID_DNS_TYPE_CNAME, &sc))
484 rtype = GNUNET_DNSPARSER_TYPE_CNAME;
485 else if (IsEqualGUID (&SVCID_DNS_TYPE_SOA, &sc))
486 rtype = GNUNET_DNSPARSER_TYPE_SOA;
487 else if (IsEqualGUID (&SVCID_DNS_TYPE_PTR, &sc))
488 rtype = GNUNET_DNSPARSER_TYPE_PTR;
489 else if (IsEqualGUID (&SVCID_DNS_TYPE_MX, &sc))
490 rtype = GNUNET_DNSPARSER_TYPE_MX;
491 else if (IsEqualGUID (&SVCID_DNS_TYPE_TEXT, &sc))
492 rtype = GNUNET_DNSPARSER_TYPE_TXT;
493 else if (IsEqualGUID (&SVCID_DNS_TYPE_AAAA, &sc))
494 rtype = GNUNET_DNSPARSER_TYPE_AAAA;
495 else if (IsEqualGUID (&SVCID_DNS_TYPE_SRV, &sc))
496 rtype = GNUNET_DNSPARSER_TYPE_SRV;
497 else if (IsEqualGUID (&SVCID_INET_HOSTADDRBYNAME, &sc))
498 rtype = GNUNET_DNSPARSER_TYPE_A;
501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
502 "Unknown GUID: %08lX-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
514 GNUNET_SERVICE_client_drop (client);
519 namelen = wcslen (name);
523 hostname = (char *) u16_to_u8 (name, namelen + 1, NULL, &strl);
527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
528 "W32 DNS resolver asked to look up %s for `%s'.\n",
529 af == AF_INET ? "IPv4" : af == AF_INET6 ? "IPv6" : "anything",
532 rq = GNUNET_new (struct request);
536 if (rq->af != AF_INET && rq->af != AF_INET6)
540 rq->name = GNUNET_malloc ((namelen + 1) * sizeof (wchar_t));
541 GNUNET_memcpy (rq->name,
543 (namelen + 1) * sizeof (wchar_t));
544 rq->u8name = hostname;
547 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
548 "Launching a lookup for client %p with rq %p\n",
551 rq->lookup_request = GNUNET_GNS_lookup (gns,
555 GNUNET_NO /* Use DHT */,
556 &process_lookup_result,
558 if (NULL != rq->lookup_request)
560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
561 "Lookup launched, waiting for a reply\n");
562 GNUNET_SERVICE_client_continue (client);
563 GNUNET_CONTAINER_DLL_insert (rq_head,
569 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
570 "Lookup was not launched, disconnecting the client\n");
571 GNUNET_free_non_null (rq->name);
575 GNUNET_SERVICE_client_drop (client);
583 * @param cls identification of the client
584 * @param msg the actual message
585 * @return #GNUNET_OK if @a msg is well-formed
588 check_get (void *cls,
589 const struct GNUNET_W32RESOLVER_GetMessage *msg)
592 const wchar_t *hostname;
596 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
597 _("Not ready to process requests, lacking ego data\n"));
598 return GNUNET_SYSERR;
600 size = ntohs (msg->header.size) - sizeof (struct GNUNET_W32RESOLVER_GetMessage);
601 hostname = (const wchar_t *) &msg[1];
602 if (hostname[size / 2 - 1] != L'\0')
605 return GNUNET_SYSERR;
612 * Handle GET-message.
614 * @param cls identification of the client
615 * @param msg the actual message
618 handle_get (void *cls,
619 const struct GNUNET_W32RESOLVER_GetMessage *msg)
621 struct GNUNET_SERVICE_Client *client = cls;
624 const wchar_t *hostname;
627 size = ntohs (msg->header.size) - sizeof (struct GNUNET_W32RESOLVER_GetMessage);
628 af = ntohl (msg->af);
629 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
630 "Got NBO GUID: %08X-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
642 sc.Data1 = ntohl (msg->sc_data1);
643 sc.Data2 = ntohs (msg->sc_data2);
644 sc.Data3 = ntohs (msg->sc_data3);
645 for (int i = 0; i < 8; i++)
646 sc.Data4[i] = msg->sc_data4[i];
647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
648 "Got GUID: %08lX-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
660 hostname = (const wchar_t *) &msg[1];
661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
662 "Name of %u bytes (last word is 0x%0X): %*S\n",
664 hostname[size / 2 - 2],
667 get_ip_from_hostname (client,
675 * Method called to with the ego we are to use for the lookup,
676 * when the ego is the one for the default master zone.
678 * @param cls closure (NULL, unused)
679 * @param ego ego handle, NULL if not found
680 * @param ctx context for application to store data for this ego
681 * (during the lifetime of this process, initially NULL)
682 * @param name name assigned by the user for this ego,
683 * NULL if the user just deleted the ego and it
684 * must thus no longer be used
687 identity_master_cb (void *cls,
688 struct GNUNET_IDENTITY_Ego *ego,
695 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
696 _("Ego for `gns-master' not found, cannot perform lookup. Did you run gnunet-gns-import.sh?\n"));
697 GNUNET_SCHEDULER_shutdown ();
700 GNUNET_IDENTITY_ego_get_public_key (ego,
707 * Start up gns-helper-w32 service.
710 * @param cfg configuration to use
711 * @param service the initialized service
715 const struct GNUNET_CONFIGURATION_Handle *cfg,
716 struct GNUNET_SERVICE_Handle *service)
718 gns = GNUNET_GNS_connect (cfg);
722 _("Failed to connect to GNS\n"));
723 GNUNET_SCHEDULER_shutdown ();
726 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
728 identity = GNUNET_IDENTITY_connect (cfg,
731 if (NULL == identity)
734 _("Failed to connect to identity service\n"));
735 GNUNET_SCHEDULER_shutdown ();
738 id_op = GNUNET_IDENTITY_get (identity,
742 GNUNET_assert (NULL != id_op);
747 * Handle client connecting to the service.
750 * @param client the new client
751 * @param mq the message queue of @a client
755 client_connect_cb (void *cls,
756 struct GNUNET_SERVICE_Client *client,
757 struct GNUNET_MQ_Handle *mq)
764 * Callback called when a client disconnected from the service
766 * @param cls closure for the service
767 * @param c the client that disconnected
768 * @param internal_cls should be equal to @a c
771 client_disconnect_cb (void *cls,
772 struct GNUNET_SERVICE_Client *client,
775 GNUNET_assert (internal_cls == client);
780 * Define "main" method using service macro.
783 ("gns-helper-service-w32",
784 GNUNET_SERVICE_OPTION_NONE,
787 &client_disconnect_cb,
789 GNUNET_MQ_hd_var_size (get,
790 GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST,
791 struct GNUNET_W32RESOLVER_GetMessage,
793 GNUNET_MQ_handler_end());
796 /* end of gnunet-gns-helper-service-w32.c */