aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2017-03-29 14:26:33 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2017-03-29 14:26:33 +0200
commitab281595eeb270120f89ec954a572f4fcf78fc53 (patch)
tree335a2caf503596adc400c5ebb9fb742f097bc5a3 /src/gns
parent59d393a1124cfd1aaffdf994bf6f8a9baaac8361 (diff)
parent2b87f173e360aaf4a3bac3fbc6e5b4dc44cf58cd (diff)
downloadgnunet-ab281595eeb270120f89ec954a572f4fcf78fc53.tar.gz
gnunet-ab281595eeb270120f89ec954a572f4fcf78fc53.zip
- merge with master
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/Makefile.am23
-rw-r--r--src/gns/gns.h53
-rw-r--r--src/gns/gns_api.c196
-rw-r--r--src/gns/gnunet-bcd.c12
-rw-r--r--src/gns/gnunet-dns2gns.c67
-rw-r--r--src/gns/gnunet-gns-helper-service-w32.c517
-rw-r--r--src/gns/gnunet-gns-import.c71
-rw-r--r--src/gns/gnunet-gns-proxy.c129
-rw-r--r--src/gns/gnunet-gns.c218
-rw-r--r--src/gns/gnunet-service-gns.c199
-rw-r--r--src/gns/gnunet-service-gns_interceptor.c1
-rw-r--r--src/gns/gnunet-service-gns_resolver.c36
-rw-r--r--src/gns/gnunet-service-gns_resolver.h11
-rw-r--r--src/gns/gnunet-service-gns_reverser.c601
-rw-r--r--src/gns/gnunet-service-gns_reverser.h91
-rw-r--r--src/gns/gnunet-service-gns_shorten.c466
-rw-r--r--src/gns/gnunet-service-gns_shorten.h70
-rw-r--r--src/gns/plugin_block_gns.c97
-rw-r--r--src/gns/plugin_gnsrecord_gns.c18
-rw-r--r--src/gns/plugin_rest_gns.c55
-rwxr-xr-xsrc/gns/test_gns_nick_shorten.sh124
-rwxr-xr-xsrc/gns/test_gns_reverse_lookup.sh50
-rw-r--r--src/gns/w32nsp-resolve.c3
23 files changed, 554 insertions, 2554 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 0b65a3d17..464bbbca1 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -12,7 +12,6 @@ SUBDIRS = . $(NSS_SUBDIR)
12EXTRA_DIST = \ 12EXTRA_DIST = \
13 test_gns_defaults.conf \ 13 test_gns_defaults.conf \
14 test_gns_lookup.conf \ 14 test_gns_lookup.conf \
15 test_gns_nick_shorten.conf \
16 test_gns_proxy.conf \ 15 test_gns_proxy.conf \
17 test_gns_simple_lookup.conf \ 16 test_gns_simple_lookup.conf \
18 gns-helper-service-w32.conf \ 17 gns-helper-service-w32.conf \
@@ -70,8 +69,8 @@ endif
70 69
71libexec_PROGRAMS = \ 70libexec_PROGRAMS = \
72 gnunet-service-gns \ 71 gnunet-service-gns \
73 $(DO_W32_HELPER) \
74 gnunet-dns2gns \ 72 gnunet-dns2gns \
73 $(DO_W32_HELPER) \
75 $(DO_PROXY) 74 $(DO_PROXY)
76 75
77bin_PROGRAMS = \ 76bin_PROGRAMS = \
@@ -114,7 +113,6 @@ gnunet_gns_SOURCES = \
114gnunet_gns_LDADD = \ 113gnunet_gns_LDADD = \
115 libgnunetgns.la \ 114 libgnunetgns.la \
116 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 115 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
117 $(top_builddir)/src/namestore/libgnunetnamestore.la \
118 $(top_builddir)/src/identity/libgnunetidentity.la \ 116 $(top_builddir)/src/identity/libgnunetidentity.la \
119 $(top_builddir)/src/util/libgnunetutil.la \ 117 $(top_builddir)/src/util/libgnunetutil.la \
120 $(GN_LIBINTL) 118 $(GN_LIBINTL)
@@ -134,11 +132,18 @@ gnunet_dns2gns_LDADD = \
134 libgnunetgns.la \ 132 libgnunetgns.la \
135 $(top_builddir)/src/util/libgnunetutil.la \ 133 $(top_builddir)/src/util/libgnunetutil.la \
136 $(top_builddir)/src/identity/libgnunetidentity.la \ 134 $(top_builddir)/src/identity/libgnunetidentity.la \
137 $(top_builddir)/src/namestore/libgnunetnamestore.la \
138 $(top_builddir)/src/dns/libgnunetdnsparser.la \ 135 $(top_builddir)/src/dns/libgnunetdnsparser.la \
139 $(top_builddir)/src/dns/libgnunetdnsstub.la \ 136 $(top_builddir)/src/dns/libgnunetdnsstub.la \
140 $(GN_LIBINTL) 137 $(GN_LIBINTL)
141 138
139if LINUX
140HIJACKBIN = gnunet-dns2gns
141install-exec-hook:
142 $(SUDO_BINARY) setcap 'cap_net_bind_service=+ep' $(DESTDIR)$(libexecdir)/gnunet-dns2gns || true
143else
144install-exec-hook:
145endif
146
142gnunet_gns_proxy_SOURCES = \ 147gnunet_gns_proxy_SOURCES = \
143 gnunet-gns-proxy.c 148 gnunet-gns-proxy.c
144gnunet_gns_proxy_CPPFLAGS = $(AM_CPPFLAGS) $(CPP_GNURL) 149gnunet_gns_proxy_CPPFLAGS = $(AM_CPPFLAGS) $(CPP_GNURL)
@@ -184,8 +189,6 @@ w32nsp_resolve_LDADD = -lws2_32
184gnunet_service_gns_SOURCES = \ 189gnunet_service_gns_SOURCES = \
185 gnunet-service-gns.c \ 190 gnunet-service-gns.c \
186 gnunet-service-gns_resolver.c gnunet-service-gns_resolver.h \ 191 gnunet-service-gns_resolver.c gnunet-service-gns_resolver.h \
187 gnunet-service-gns_reverser.c gnunet-service-gns_reverser.h \
188 gnunet-service-gns_shorten.c gnunet-service-gns_shorten.h \
189 gnunet-service-gns_interceptor.c gnunet-service-gns_interceptor.h 192 gnunet-service-gns_interceptor.c gnunet-service-gns_interceptor.h
190gnunet_service_gns_LDADD = \ 193gnunet_service_gns_LDADD = \
191 -lm \ 194 -lm \
@@ -200,7 +203,6 @@ gnunet_service_gns_LDADD = \
200 $(top_builddir)/src/dht/libgnunetdht.la \ 203 $(top_builddir)/src/dht/libgnunetdht.la \
201 $(top_builddir)/src/tun/libgnunettun.la \ 204 $(top_builddir)/src/tun/libgnunettun.la \
202 $(top_builddir)/src/namecache/libgnunetnamecache.la \ 205 $(top_builddir)/src/namecache/libgnunetnamecache.la \
203 $(top_builddir)/src/namestore/libgnunetnamestore.la \
204 $(USE_VPN) \ 206 $(USE_VPN) \
205 $(GN_LIBINTL) 207 $(GN_LIBINTL)
206 208
@@ -227,6 +229,7 @@ libgnunet_plugin_block_gns_la_SOURCES = \
227libgnunet_plugin_block_gns_la_LIBADD = \ 229libgnunet_plugin_block_gns_la_LIBADD = \
228 $(top_builddir)/src/util/libgnunetutil.la \ 230 $(top_builddir)/src/util/libgnunetutil.la \
229 $(top_builddir)/src/block/libgnunetblock.la \ 231 $(top_builddir)/src/block/libgnunetblock.la \
232 $(top_builddir)/src/block/libgnunetblockgroup.la \
230 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la 233 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la
231libgnunet_plugin_block_gns_la_LDFLAGS = \ 234libgnunet_plugin_block_gns_la_LDFLAGS = \
232 $(GN_PLUGIN_LDFLAGS) 235 $(GN_PLUGIN_LDFLAGS)
@@ -253,18 +256,16 @@ check_SCRIPTS = \
253 test_gns_gns2dns_lookup.sh \ 256 test_gns_gns2dns_lookup.sh \
254 test_gns_dht_lookup.sh\ 257 test_gns_dht_lookup.sh\
255 test_gns_delegated_lookup.sh \ 258 test_gns_delegated_lookup.sh \
256 test_gns_nick_shorten.sh\
257 test_gns_plus_lookup.sh\ 259 test_gns_plus_lookup.sh\
258 test_gns_zkey_lookup.sh\ 260 test_gns_zkey_lookup.sh\
259 test_gns_rel_expiration.sh\ 261 test_gns_rel_expiration.sh\
260 test_gns_soa_lookup.sh\ 262 test_gns_soa_lookup.sh\
261 test_gns_revocation.sh\ 263 test_gns_revocation.sh\
262 test_gns_cname_lookup.sh \ 264 test_gns_cname_lookup.sh
263 test_gns_reverse_lookup.sh
264 265
265if ENABLE_TEST_RUN 266if ENABLE_TEST_RUN
266if HAVE_SQLITE 267if HAVE_SQLITE
267 AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; 268 AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
268 TESTS = $(check_SCRIPTS) 269 TESTS = $(check_SCRIPTS)
269endif 270endif
270endif 271endif
diff --git a/src/gns/gns.h b/src/gns/gns.h
index ca5525f80..d77bf53c6 100644
--- a/src/gns/gns.h
+++ b/src/gns/gns.h
@@ -72,51 +72,20 @@ struct LookupMessage
72 int16_t options GNUNET_PACKED; 72 int16_t options GNUNET_PACKED;
73 73
74 /** 74 /**
75 * Is a shorten key attached? 75 * Always 0.
76 */ 76 */
77 int16_t have_key GNUNET_PACKED; 77 int16_t reserved GNUNET_PACKED;
78 78
79 /** 79 /**
80 * the type of record to look up 80 * the type of record to look up
81 */ 81 */
82 int32_t type GNUNET_PACKED; 82 int32_t type GNUNET_PACKED;
83 83
84 /**
85 * The key for shorten, if @e have_key is set
86 */
87 struct GNUNET_CRYPTO_EcdsaPrivateKey shorten_key;
88
89 /* Followed by the zero-terminated name to look up */ 84 /* Followed by the zero-terminated name to look up */
90}; 85};
91 86
92 87
93/** 88/**
94 * Message from client to GNS service to lookup records.
95 */
96struct ReverseLookupMessage
97{
98 /**
99 * Header of type #GNUNET_MESSAGE_TYPE_GNS_REVERSE_LOOKUP
100 */
101 struct GNUNET_MessageHeader header;
102
103 /**
104 * Unique identifier for this request (for key collisions).
105 */
106 uint32_t id GNUNET_PACKED;
107
108 /**
109 * Zone that is target for reverse lookup
110 */
111 struct GNUNET_CRYPTO_EcdsaPublicKey zone_pkey;
112
113 /**
114 * Root zone
115 */
116 struct GNUNET_CRYPTO_EcdsaPublicKey root_pkey;
117};
118
119/**
120 * Message from GNS service to client: new results. 89 * Message from GNS service to client: new results.
121 */ 90 */
122struct LookupResultMessage 91struct LookupResultMessage
@@ -140,24 +109,6 @@ struct LookupResultMessage
140 109
141}; 110};
142 111
143/**
144 * Message from GNS service to client: new results.
145 */
146struct ReverseLookupResultMessage
147{
148 /**
149 * Header of type #GNUNET_MESSAGE_TYPE_GNS_REVERSE_LOOKUP_RESULT
150 */
151 struct GNUNET_MessageHeader header;
152
153 /**
154 * Unique identifier for this request (for key collisions).
155 */
156 uint32_t id GNUNET_PACKED;
157
158 /* followed by the resulting name of the reverse lookup */
159};
160
161 112
162GNUNET_NETWORK_STRUCT_END 113GNUNET_NETWORK_STRUCT_END
163 114
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index f6f9889ac..84c4ae189 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -79,49 +79,6 @@ struct GNUNET_GNS_LookupRequest
79 79
80}; 80};
81 81
82/**
83 * Handle to a lookup request
84 */
85struct GNUNET_GNS_ReverseLookupRequest
86{
87
88 /**
89 * DLL
90 */
91 struct GNUNET_GNS_ReverseLookupRequest *next;
92
93 /**
94 * DLL
95 */
96 struct GNUNET_GNS_ReverseLookupRequest *prev;
97
98 /**
99 * handle to gns
100 */
101 struct GNUNET_GNS_Handle *gns_handle;
102
103 /**
104 * processor to call on lookup result
105 */
106 GNUNET_GNS_ReverseLookupResultProcessor lookup_proc;
107
108 /**
109 * @e lookup_proc closure
110 */
111 void *proc_cls;
112
113 /**
114 * Envelope with the message for this queue entry.
115 */
116 struct GNUNET_MQ_Envelope *env;
117
118 /**
119 * request id
120 */
121 uint32_t r_id;
122
123};
124
125 82
126/** 83/**
127 * Connection to the GNS service. 84 * Connection to the GNS service.
@@ -150,15 +107,6 @@ struct GNUNET_GNS_Handle
150 struct GNUNET_GNS_LookupRequest *lookup_tail; 107 struct GNUNET_GNS_LookupRequest *lookup_tail;
151 108
152 /** 109 /**
153 * Head of linked list of active reverse lookup requests.
154 */
155 struct GNUNET_GNS_ReverseLookupRequest *rev_lookup_head;
156
157 /**
158 * Tail of linked list of active reverse lookup requests.
159 */
160 struct GNUNET_GNS_ReverseLookupRequest *rev_lookup_tail;
161 /**
162 * Reconnect task 110 * Reconnect task
163 */ 111 */
164 struct GNUNET_SCHEDULER_Task *reconnect_task; 112 struct GNUNET_SCHEDULER_Task *reconnect_task;
@@ -232,71 +180,13 @@ mq_error_handler (void *cls,
232 enum GNUNET_MQ_Error error) 180 enum GNUNET_MQ_Error error)
233{ 181{
234 struct GNUNET_GNS_Handle *handle = cls; 182 struct GNUNET_GNS_Handle *handle = cls;
235 LOG (GNUNET_ERROR_TYPE_WARNING, "Problem with message queue. error: %i\n", 183
184 LOG (GNUNET_ERROR_TYPE_WARNING,
185 "Problem with message queue. error: %i\n",
236 error); 186 error);
237 force_reconnect (handle); 187 force_reconnect (handle);
238} 188}
239 189
240/**
241 * Check validity of message received from the GNS service
242 *
243 * @param cls the `struct GNUNET_GNS_Handle *`
244 * @param loookup_msg the incoming message
245 */
246static int
247check_rev_result (void *cls,
248 const struct ReverseLookupResultMessage *lookup_msg)
249{
250 size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg);
251 char *name;
252
253 name = (char*) &lookup_msg[1];
254 if ('\0' != name[mlen-1])
255 {
256 GNUNET_break (0);
257 return GNUNET_SYSERR;
258 }
259 return GNUNET_OK;
260}
261
262
263/**
264 * Handler for messages received from the GNS service
265 *
266 * @param cls the `struct GNUNET_GNS_Handle *`
267 * @param loookup_msg the incoming message
268 */
269static void
270handle_rev_result (void *cls,
271 const struct ReverseLookupResultMessage *lookup_msg)
272{
273 struct GNUNET_GNS_Handle *handle = cls;
274 char *name;
275 uint32_t r_id = ntohl (lookup_msg->id);
276 struct GNUNET_GNS_ReverseLookupRequest *rlr;
277 GNUNET_GNS_ReverseLookupResultProcessor proc;
278 void *proc_cls;
279
280 name = (char*)&lookup_msg[1];
281 LOG (GNUNET_ERROR_TYPE_DEBUG,
282 "Received reverse lookup reply from GNS service (%s)\n",
283 name);
284 for (rlr = handle->rev_lookup_head; NULL != rlr; rlr = rlr->next)
285 if (rlr->r_id == r_id)
286 break;
287 if (NULL == rlr)
288 return;
289 proc = rlr->lookup_proc;
290 proc_cls = rlr->proc_cls;
291 GNUNET_CONTAINER_DLL_remove (handle->rev_lookup_head,
292 handle->rev_lookup_tail,
293 rlr);
294 GNUNET_free (rlr);
295 proc (proc_cls,
296 name);
297}
298
299
300 190
301/** 191/**
302 * Check validity of message received from the GNS service 192 * Check validity of message received from the GNS service
@@ -385,14 +275,9 @@ reconnect (struct GNUNET_GNS_Handle *handle)
385 GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT, 275 GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT,
386 struct LookupResultMessage, 276 struct LookupResultMessage,
387 handle), 277 handle),
388 GNUNET_MQ_hd_var_size (rev_result,
389 GNUNET_MESSAGE_TYPE_GNS_REVERSE_LOOKUP_RESULT,
390 struct ReverseLookupResultMessage,
391 handle),
392 GNUNET_MQ_handler_end () 278 GNUNET_MQ_handler_end ()
393 }; 279 };
394 struct GNUNET_GNS_LookupRequest *lh; 280 struct GNUNET_GNS_LookupRequest *lh;
395 struct GNUNET_GNS_ReverseLookupRequest *rlh;
396 281
397 GNUNET_assert (NULL == handle->mq); 282 GNUNET_assert (NULL == handle->mq);
398 LOG (GNUNET_ERROR_TYPE_DEBUG, 283 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -407,9 +292,6 @@ reconnect (struct GNUNET_GNS_Handle *handle)
407 for (lh = handle->lookup_head; NULL != lh; lh = lh->next) 292 for (lh = handle->lookup_head; NULL != lh; lh = lh->next)
408 GNUNET_MQ_send_copy (handle->mq, 293 GNUNET_MQ_send_copy (handle->mq,
409 lh->env); 294 lh->env);
410 for (rlh = handle->rev_lookup_head; NULL != rlh; rlh = rlh->next)
411 GNUNET_MQ_send_copy (handle->mq,
412 rlh->env);
413} 295}
414 296
415 297
@@ -455,7 +337,6 @@ GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle)
455 handle->reconnect_task = NULL; 337 handle->reconnect_task = NULL;
456 } 338 }
457 GNUNET_assert (NULL == handle->lookup_head); 339 GNUNET_assert (NULL == handle->lookup_head);
458 GNUNET_assert (NULL == handle->rev_lookup_head);
459 GNUNET_free (handle); 340 GNUNET_free (handle);
460} 341}
461 342
@@ -477,22 +358,6 @@ GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr)
477 GNUNET_free (lr); 358 GNUNET_free (lr);
478} 359}
479 360
480/**
481 * Cancel pending reverse lookup request
482 *
483 * @param lr the lookup request to cancel
484 */
485void
486GNUNET_GNS_reverse_lookup_cancel (struct GNUNET_GNS_ReverseLookupRequest *lr)
487{
488 struct GNUNET_GNS_Handle *handle = lr->gns_handle;
489
490 GNUNET_CONTAINER_DLL_remove (handle->rev_lookup_head,
491 handle->rev_lookup_tail,
492 lr);
493 GNUNET_MQ_discard (lr->env);
494 GNUNET_free (lr);
495}
496 361
497/** 362/**
498 * Perform an asynchronous lookup operation on the GNS. 363 * Perform an asynchronous lookup operation on the GNS.
@@ -502,7 +367,6 @@ GNUNET_GNS_reverse_lookup_cancel (struct GNUNET_GNS_ReverseLookupRequest *lr)
502 * @param zone the zone to start the resolution in 367 * @param zone the zone to start the resolution in
503 * @param type the record type to look up 368 * @param type the record type to look up
504 * @param options local options for the lookup 369 * @param options local options for the lookup
505 * @param shorten_zone_key the private key of the shorten zone (can be NULL)
506 * @param proc processor to call on result 370 * @param proc processor to call on result
507 * @param proc_cls closure for @a proc 371 * @param proc_cls closure for @a proc
508 * @return handle to the get request 372 * @return handle to the get request
@@ -513,7 +377,6 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
513 const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, 377 const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
514 uint32_t type, 378 uint32_t type,
515 enum GNUNET_GNS_LocalOptions options, 379 enum GNUNET_GNS_LocalOptions options,
516 const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone_key,
517 GNUNET_GNS_LookupResultProcessor proc, 380 GNUNET_GNS_LookupResultProcessor proc,
518 void *proc_cls) 381 void *proc_cls)
519{ 382{
@@ -531,7 +394,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
531 "Trying to lookup `%s' in GNS\n", 394 "Trying to lookup `%s' in GNS\n",
532 name); 395 name);
533 nlen = strlen (name) + 1; 396 nlen = strlen (name) + 1;
534 if (nlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*lr)) 397 if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*lr))
535 { 398 {
536 GNUNET_break (0); 399 GNUNET_break (0);
537 return NULL; 400 return NULL;
@@ -548,11 +411,6 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
548 lookup_msg->options = htons ((uint16_t) options); 411 lookup_msg->options = htons ((uint16_t) options);
549 lookup_msg->zone = *zone; 412 lookup_msg->zone = *zone;
550 lookup_msg->type = htonl (type); 413 lookup_msg->type = htonl (type);
551 if (NULL != shorten_zone_key)
552 {
553 lookup_msg->have_key = htons (GNUNET_YES);
554 lookup_msg->shorten_key = *shorten_zone_key;
555 }
556 GNUNET_memcpy (&lookup_msg[1], 414 GNUNET_memcpy (&lookup_msg[1],
557 name, 415 name,
558 nlen); 416 nlen);
@@ -565,50 +423,4 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
565 return lr; 423 return lr;
566} 424}
567 425
568/**
569 * Perform an asynchronous reverse lookup operation on the GNS.
570 *
571 * @param handle handle to the GNS service
572 * @param zone_key zone to find a name for
573 * @param root_key our zone
574 * @param proc processor to call on result
575 * @param proc_cls closure for @a proc
576 * @return handle to the request
577 */
578struct GNUNET_GNS_ReverseLookupRequest*
579GNUNET_GNS_reverse_lookup (struct GNUNET_GNS_Handle *handle,
580 const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key,
581 const struct GNUNET_CRYPTO_EcdsaPublicKey *root_key,
582 GNUNET_GNS_ReverseLookupResultProcessor proc,
583 void *proc_cls)
584{
585 /* IPC to shorten gns names, return shorten_handle */
586 struct ReverseLookupMessage *rev_lookup_msg;
587 struct GNUNET_GNS_ReverseLookupRequest *lr;
588
589 if ((NULL == zone_key) || (NULL == root_key))
590 {
591 GNUNET_break (0);
592 return NULL;
593 }
594 LOG (GNUNET_ERROR_TYPE_DEBUG,
595 "Trying to reverse lookup in GNS\n");
596 lr = GNUNET_new (struct GNUNET_GNS_ReverseLookupRequest);
597 lr->gns_handle = handle;
598 lr->lookup_proc = proc;
599 lr->proc_cls = proc_cls;
600 lr->r_id = handle->r_id_gen++;
601 lr->env = GNUNET_MQ_msg (rev_lookup_msg,
602 GNUNET_MESSAGE_TYPE_GNS_REVERSE_LOOKUP);
603 rev_lookup_msg->id = htonl (lr->r_id);
604 rev_lookup_msg->zone_pkey = *zone_key;
605 rev_lookup_msg->root_pkey = *root_key;
606 GNUNET_CONTAINER_DLL_insert (handle->rev_lookup_head,
607 handle->rev_lookup_tail,
608 lr);
609 if (NULL != handle->mq)
610 GNUNET_MQ_send_copy (handle->mq,
611 lr->env);
612 return lr;
613}
614/* end of gns_api.c */ 426/* end of gns_api.c */
diff --git a/src/gns/gnunet-bcd.c b/src/gns/gnunet-bcd.c
index 21471350d..0746d5c57 100644
--- a/src/gns/gnunet-bcd.c
+++ b/src/gns/gnunet-bcd.c
@@ -514,10 +514,14 @@ run (void *cls,
514int 514int
515main (int argc, char *const *argv) 515main (int argc, char *const *argv)
516{ 516{
517 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 517 struct GNUNET_GETOPT_CommandLineOption options[] = {
518 {'p', "port", "PORT", 518
519 gettext_noop ("Run HTTP serve on port PORT (default is 8888)"), 1, 519 GNUNET_GETOPT_option_uint ('p',
520 &GNUNET_GETOPT_set_uint, &port}, 520 "port",
521 "PORT",
522 gettext_noop ("Run HTTP serve on port PORT (default is 8888)"),
523 &port),
524
521 GNUNET_GETOPT_OPTION_END 525 GNUNET_GETOPT_OPTION_END
522 }; 526 };
523 int ret; 527 int ret;
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c
index f58303789..424677d14 100644
--- a/src/gns/gnunet-dns2gns.c
+++ b/src/gns/gnunet-dns2gns.c
@@ -138,7 +138,7 @@ static char *dns_ip;
138/** 138/**
139 * UDP Port we listen on for inbound DNS requests. 139 * UDP Port we listen on for inbound DNS requests.
140 */ 140 */
141static unsigned int listen_port = 2853; 141static unsigned int listen_port = 53;
142 142
143/** 143/**
144 * Which GNS zone do we translate incoming DNS requests to? 144 * Which GNS zone do we translate incoming DNS requests to?
@@ -483,7 +483,6 @@ handle_request (struct GNUNET_NETWORK_Handle *lsock,
483 &my_zone, 483 &my_zone,
484 type, 484 type,
485 GNUNET_NO, 485 GNUNET_NO,
486 NULL /* no shorten */,
487 &result_processor, 486 &result_processor,
488 request); 487 request);
489 } 488 }
@@ -618,7 +617,7 @@ run_dnsd ()
618 if (NULL != listen_socket4) 617 if (NULL != listen_socket4)
619 { 618 {
620 struct sockaddr_in v4; 619 struct sockaddr_in v4;
621 620
622 memset (&v4, 0, sizeof (v4)); 621 memset (&v4, 0, sizeof (v4));
623 v4.sin_family = AF_INET; 622 v4.sin_family = AF_INET;
624#if HAVE_SOCKADDR_IN_SIN_LEN 623#if HAVE_SOCKADDR_IN_SIN_LEN
@@ -641,7 +640,7 @@ run_dnsd ()
641 if (NULL != listen_socket6) 640 if (NULL != listen_socket6)
642 { 641 {
643 struct sockaddr_in6 v6; 642 struct sockaddr_in6 v6;
644 643
645 memset (&v6, 0, sizeof (v6)); 644 memset (&v6, 0, sizeof (v6));
646 v6.sin6_family = AF_INET6; 645 v6.sin6_family = AF_INET6;
647#if HAVE_SOCKADDR_IN_SIN_LEN 646#if HAVE_SOCKADDR_IN_SIN_LEN
@@ -777,33 +776,53 @@ int
777main (int argc, 776main (int argc,
778 char *const *argv) 777 char *const *argv)
779{ 778{
780 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 779 struct GNUNET_GETOPT_CommandLineOption options[] = {
781 {'d', "dns", "IP", 780
782 gettext_noop ("IP of recursive DNS resolver to use (required)"), 1, 781 GNUNET_GETOPT_option_string ('d',
783 &GNUNET_GETOPT_set_string, &dns_ip}, 782 "dns",
784 {'f', "fcfs", "NAME", 783 "IP",
785 gettext_noop ("Authoritative FCFS suffix to use (optional); default: fcfs.zkey.eu"), 1, 784 gettext_noop ("IP of recursive DNS resolver to use (required)"),
786 &GNUNET_GETOPT_set_string, &fcfs_suffix}, 785 &dns_ip),
787 {'s', "suffix", "SUFFIX", 786
788 gettext_noop ("Authoritative DNS suffix to use (optional); default: zkey.eu"), 1, 787 GNUNET_GETOPT_option_string ('f',
789 &GNUNET_GETOPT_set_string, &dns_suffix}, 788 "fcfs",
790 {'p', "port", "UDPPORT", 789 "NAME",
791 gettext_noop ("UDP port to listen on for inbound DNS requests; default: 2853"), 1, 790 gettext_noop ("Authoritative FCFS suffix to use (optional); default: fcfs.zkey.eu"),
792 &GNUNET_GETOPT_set_uint, &listen_port}, 791 &fcfs_suffix),
793 {'z', "zone", "PUBLICKEY", 792
794 gettext_noop ("Public key of the GNS zone to use (overrides default)"), 1, 793 GNUNET_GETOPT_option_string ('s',
795 &GNUNET_GETOPT_set_string, &gns_zone_str}, 794 "suffix",
795 "SUFFIX",
796 gettext_noop ("Authoritative DNS suffix to use (optional); default: zkey.eu"),
797 &dns_suffix),
798
799 GNUNET_GETOPT_option_uint ('p',
800 "port",
801 "UDPPORT",
802 gettext_noop ("UDP port to listen on for inbound DNS requests; default: 2853"),
803 &listen_port),
804
805 GNUNET_GETOPT_option_string ('z',
806 "zone",
807 "PUBLICKEY",
808 gettext_noop ("Public key of the GNS zone to use (overrides default)"),
809 &gns_zone_str),
810
796 GNUNET_GETOPT_OPTION_END 811 GNUNET_GETOPT_OPTION_END
797 }; 812 };
798 int ret; 813 int ret;
799 814
800 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, 815 if (GNUNET_OK !=
801 &argc, &argv)) 816 GNUNET_STRINGS_get_utf8_args (argc, argv,
817 &argc, &argv))
802 return 2; 818 return 2;
803 GNUNET_log_setup ("gnunet-dns2gns", "WARNING", NULL); 819 GNUNET_log_setup ("gnunet-dns2gns",
820 "WARNING",
821 NULL);
804 ret = 822 ret =
805 (GNUNET_OK == 823 (GNUNET_OK ==
806 GNUNET_PROGRAM_run (argc, argv, "gnunet-dns2gns", 824 GNUNET_PROGRAM_run (argc, argv,
825 "gnunet-dns2gns",
807 _("GNUnet DNS-to-GNS proxy (a DNS server)"), 826 _("GNUnet DNS-to-GNS proxy (a DNS server)"),
808 options, 827 options,
809 &run, NULL)) ? 0 : 1; 828 &run, NULL)) ? 0 : 1;
diff --git a/src/gns/gnunet-gns-helper-service-w32.c b/src/gns/gnunet-gns-helper-service-w32.c
index bfee2b498..a59cc5981 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,133 +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
198/**
199 * Function called to notify a client about the socket
200 * being ready to queue more data. "buf" will be
201 * NULL and "size" zero if the socket was closed for
202 * writing in the meantime.
203 *
204 * @param cls closure
205 * @param size number of bytes available in buf
206 * @param buf where the callee should write the message
207 * @return number of bytes written to buf
208 */
209static size_t
210transmit_callback (void *cls, size_t size, void *buf)
211{
212 struct TransmitCallbackContext *tcc = cls;
213 size_t msize;
214
215 tcc->th = NULL;
216 GNUNET_CONTAINER_DLL_remove (tcc_head, tcc_tail, tcc);
217 msize = ntohs (tcc->msg->size);
218 if (size == 0)
219 {
220 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
221 _("Transmission to client failed!\n"));
222 GNUNET_free (tcc->msg);
223 GNUNET_free (tcc);
224 return 0;
225 }
226 GNUNET_assert (size >= msize);
227 GNUNET_memcpy (buf, tcc->msg, msize);
228 GNUNET_free (tcc->msg);
229 GNUNET_free (tcc);
230 for (tcc = tcc_head; tcc; tcc = tcc->next)
231 {
232 if (NULL == tcc->th)
233 {
234 tcc->th = GNUNET_SERVER_notify_transmit_ready (tcc->client,
235 ntohs (tcc->msg->size),
236 GNUNET_TIME_UNIT_FOREVER_REL,
237 &transmit_callback, tcc);
238 break;
239 }
240 }
241 return msize;
242}
243
244
245/**
246 * Transmit the given message to the client.
247 *
248 * @param client target of the message
249 * @param msg message to transmit, will be freed!
250 */
251static void
252transmit (struct GNUNET_SERVER_Client *client,
253 struct GNUNET_MessageHeader *msg)
254{
255 struct TransmitCallbackContext *tcc;
256
257 if (GNUNET_YES == cleaning_done)
258 {
259 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
260 _("Shutdown in progress, aborting transmission.\n"));
261 GNUNET_free (msg);
262 return;
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}
273
274 156
275#define MarshallPtr(ptr, base, type) \ 157#define MarshallPtr(ptr, base, type) \
276 if (ptr) \ 158 if (ptr) \
@@ -280,7 +162,6 @@ transmit (struct GNUNET_SERVER_Client *client,
280void 162void
281MarshallWSAQUERYSETW (WSAQUERYSETW *qs, GUID *sc) 163MarshallWSAQUERYSETW (WSAQUERYSETW *qs, GUID *sc)
282{ 164{
283 int i;
284 MarshallPtr (qs->lpszServiceInstanceName, qs, wchar_t); 165 MarshallPtr (qs->lpszServiceInstanceName, qs, wchar_t);
285 MarshallPtr (qs->lpServiceClassId, qs, GUID); 166 MarshallPtr (qs->lpServiceClassId, qs, GUID);
286 MarshallPtr (qs->lpVersion, qs, WSAVERSION); 167 MarshallPtr (qs->lpVersion, qs, WSAVERSION);
@@ -288,7 +169,7 @@ MarshallWSAQUERYSETW (WSAQUERYSETW *qs, GUID *sc)
288 MarshallPtr (qs->lpszContext, qs, wchar_t); 169 MarshallPtr (qs->lpszContext, qs, wchar_t);
289 MarshallPtr (qs->lpafpProtocols, qs, AFPROTOCOLS); 170 MarshallPtr (qs->lpafpProtocols, qs, AFPROTOCOLS);
290 MarshallPtr (qs->lpszQueryString, qs, wchar_t); 171 MarshallPtr (qs->lpszQueryString, qs, wchar_t);
291 for (i = 0; i < qs->dwNumberOfCsAddrs; i++) 172 for (int i = 0; i < qs->dwNumberOfCsAddrs; i++)
292 { 173 {
293 MarshallPtr (qs->lpcsaBuffer[i].LocalAddr.lpSockaddr, qs, SOCKADDR); 174 MarshallPtr (qs->lpcsaBuffer[i].LocalAddr.lpSockaddr, qs, SOCKADDR);
294 MarshallPtr (qs->lpcsaBuffer[i].RemoteAddr.lpSockaddr, qs, SOCKADDR); 175 MarshallPtr (qs->lpcsaBuffer[i].RemoteAddr.lpSockaddr, qs, SOCKADDR);
@@ -297,12 +178,13 @@ MarshallWSAQUERYSETW (WSAQUERYSETW *qs, GUID *sc)
297 if (IsEqualGUID (&SVCID_INET_HOSTADDRBYNAME, sc) && qs->lpBlob != NULL && qs->lpBlob->pBlobData != NULL) 178 if (IsEqualGUID (&SVCID_INET_HOSTADDRBYNAME, sc) && qs->lpBlob != NULL && qs->lpBlob->pBlobData != NULL)
298 { 179 {
299 struct hostent *he; 180 struct hostent *he;
181
300 he = (struct hostent *) qs->lpBlob->pBlobData; 182 he = (struct hostent *) qs->lpBlob->pBlobData;
301 for (i = 0; he->h_aliases[i] != NULL; i++) 183 for (int i = 0; he->h_aliases[i] != NULL; i++)
302 MarshallPtr (he->h_aliases[i], he, char); 184 MarshallPtr (he->h_aliases[i], he, char);
303 MarshallPtr (he->h_aliases, he, char *); 185 MarshallPtr (he->h_aliases, he, char *);
304 MarshallPtr (he->h_name, he, char); 186 MarshallPtr (he->h_name, he, char);
305 for (i = 0; he->h_addr_list[i] != NULL; i++) 187 for (int i = 0; he->h_addr_list[i] != NULL; i++)
306 MarshallPtr (he->h_addr_list[i], he, void); 188 MarshallPtr (he->h_addr_list[i], he, void);
307 MarshallPtr (he->h_addr_list, he, char *); 189 MarshallPtr (he->h_addr_list, he, char *);
308 MarshallPtr (qs->lpBlob->pBlobData, qs, void); 190 MarshallPtr (qs->lpBlob->pBlobData, qs, void);
@@ -312,13 +194,16 @@ MarshallWSAQUERYSETW (WSAQUERYSETW *qs, GUID *sc)
312 194
313 195
314static void 196static void
315process_lookup_result (void* cls, uint32_t rd_count, 197process_lookup_result (void *cls,
316 const struct GNUNET_GNSRECORD_Data *rd) 198 uint32_t rd_count,
199 const struct GNUNET_GNSRECORD_Data *rd)
317{ 200{
201 struct request *rq = cls;
318 int i, j, csanum; 202 int i, j, csanum;
319 struct request *rq = (struct request *) cls;
320 struct GNUNET_W32RESOLVER_GetMessage *msg; 203 struct GNUNET_W32RESOLVER_GetMessage *msg;
204 struct GNUNET_MQ_Envelope *msg_env;
321 struct GNUNET_MessageHeader *msgend; 205 struct GNUNET_MessageHeader *msgend;
206 struct GNUNET_MQ_Envelope *msgend_env;
322 WSAQUERYSETW *qs; 207 WSAQUERYSETW *qs;
323 size_t size; 208 size_t size;
324 size_t size_recalc; 209 size_t size_recalc;
@@ -327,18 +212,20 @@ process_lookup_result (void* cls, uint32_t rd_count,
327 size_t blobaddrcount = 0; 212 size_t blobaddrcount = 0;
328 213
329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
330 "Got lookup result with count %u for rq %p with client %p\n", 215 "Got lookup result with count %u for rq %p with client %p\n",
331 rd_count, rq, rq->client); 216 rd_count,
217 rq,
218 rq->client);
332 rq->lookup_request = NULL; 219 rq->lookup_request = NULL;
333 220
334 if (rd_count == 0) 221 if (0 == rd_count)
335 { 222 {
336 size = sizeof (struct GNUNET_MessageHeader); 223 msgend_env = GNUNET_MQ_msg (msgend, GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
337 msg = GNUNET_malloc (size); 224 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (rq->client),
338 msg->header.size = htons (size); 225 msgend_env);
339 msg->header.type = htons (GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE); 226 GNUNET_CONTAINER_DLL_remove (rq_head,
340 transmit (rq->client, &msg->header); 227 rq_tail,
341 GNUNET_CONTAINER_DLL_remove (rq_head, rq_tail, rq); 228 rq);
342 GNUNET_free_non_null (rq->name); 229 GNUNET_free_non_null (rq->name);
343 if (rq->u8name) 230 if (rq->u8name)
344 free (rq->u8name); 231 free (rq->u8name);
@@ -396,9 +283,9 @@ process_lookup_result (void* cls, uint32_t rd_count,
396 size += blobsize; 283 size += blobsize;
397 } 284 }
398 size_recalc = sizeof (struct GNUNET_W32RESOLVER_GetMessage) + sizeof (WSAQUERYSETW); 285 size_recalc = sizeof (struct GNUNET_W32RESOLVER_GetMessage) + sizeof (WSAQUERYSETW);
399 msg = GNUNET_malloc (size); 286 msg_env = GNUNET_MQ_msg_extra (msg,
400 msg->header.size = htons (size - sizeof (struct GNUNET_MessageHeader)); 287 size - sizeof (struct GNUNET_MessageHeader),
401 msg->header.type = htons (GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE); 288 GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
402 msg->af = htonl (rq->af); 289 msg->af = htonl (rq->af);
403 msg->sc_data1 = htonl (rq->sc.Data1); 290 msg->sc_data1 = htonl (rq->sc.Data1);
404 msg->sc_data2 = htons (rq->sc.Data2); 291 msg->sc_data2 = htons (rq->sc.Data2);
@@ -557,19 +444,24 @@ process_lookup_result (void* cls, uint32_t rd_count,
557 } 444 }
558 he->h_addr_list[j] = NULL; 445 he->h_addr_list[j] = NULL;
559 } 446 }
560 msgend = GNUNET_new (struct GNUNET_MessageHeader); 447 msgend_env = GNUNET_MQ_msg (msgend, GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
561
562 msgend->type = htons (GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
563 msgend->size = htons (sizeof (struct GNUNET_MessageHeader));
564 448
565 if ((char *) ptr - (char *) msg != size || size_recalc != size || size_recalc != ((char *) ptr - (char *) msg)) 449 if ((char *) ptr - (char *) msg != size || size_recalc != size || size_recalc != ((char *) ptr - (char *) msg))
566 { 450 {
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); 451 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
452 "Error in WSAQUERYSETW size calc: expected %u, got %lu (recalc %u)\n",
453 size,
454 (unsigned long) ((char *) ptr - (char *) msg),
455 size_recalc);
568 } 456 }
569 MarshallWSAQUERYSETW (qs, &rq->sc); 457 MarshallWSAQUERYSETW (qs, &rq->sc);
570 transmit (rq->client, &msg->header); 458 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (rq->client),
571 transmit (rq->client, msgend); 459 msg_env);
572 GNUNET_CONTAINER_DLL_remove (rq_head, rq_tail, rq); 460 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (rq->client),
461 msgend_env);
462 GNUNET_CONTAINER_DLL_remove (rq_head,
463 rq_tail,
464 rq);
573 GNUNET_free_non_null (rq->name); 465 GNUNET_free_non_null (rq->name);
574 if (rq->u8name) 466 if (rq->u8name)
575 free (rq->u8name); 467 free (rq->u8name);
@@ -578,8 +470,10 @@ process_lookup_result (void* cls, uint32_t rd_count,
578 470
579 471
580static void 472static void
581get_ip_from_hostname (struct GNUNET_SERVER_Client *client, 473get_ip_from_hostname (struct GNUNET_SERVICE_Client *client,
582 const wchar_t *name, int af, GUID sc) 474 const wchar_t *name,
475 int af,
476 GUID sc)
583{ 477{
584 struct request *rq; 478 struct request *rq;
585 char *hostname; 479 char *hostname;
@@ -610,10 +504,19 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
610 else 504 else
611 { 505 {
612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
613 "Unknown GUID: %08X-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n", 507 "Unknown GUID: %08lX-%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], 508 sc.Data1,
615 sc.Data4[3], sc.Data4[4], sc.Data4[5], sc.Data4[6], sc.Data4[7]); 509 sc.Data2,
616 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 510 sc.Data3,
511 sc.Data4[0],
512 sc.Data4[1],
513 sc.Data4[2],
514 sc.Data4[3],
515 sc.Data4[4],
516 sc.Data4[5],
517 sc.Data4[6],
518 sc.Data4[7]);
519 GNUNET_SERVICE_client_drop (client);
617 return; 520 return;
618 } 521 }
619 522
@@ -640,24 +543,31 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
640 if (namelen) 543 if (namelen)
641 { 544 {
642 rq->name = GNUNET_malloc ((namelen + 1) * sizeof (wchar_t)); 545 rq->name = GNUNET_malloc ((namelen + 1) * sizeof (wchar_t));
643 GNUNET_memcpy (rq->name, name, (namelen + 1) * sizeof (wchar_t)); 546 GNUNET_memcpy (rq->name,
547 name,
548 (namelen + 1) * sizeof (wchar_t));
644 rq->u8name = hostname; 549 rq->u8name = hostname;
645 } 550 }
646 551
647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 552 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
648 "Launching a lookup for client %p with rq %p\n", 553 "Launching a lookup for client %p with rq %p\n",
649 client, rq); 554 client,
650 555 rq);
651 rq->lookup_request = GNUNET_GNS_lookup (gns, hostname, &gns_master_pubkey, 556 rq->lookup_request = GNUNET_GNS_lookup (gns,
652 rtype, GNUNET_NO /* Use DHT */, &gns_short_privkey, &process_lookup_result, 557 hostname,
653 rq); 558 &gns_master_pubkey,
654 559 rtype,
560 GNUNET_NO /* Use DHT */,
561 &process_lookup_result,
562 rq);
655 if (NULL != rq->lookup_request) 563 if (NULL != rq->lookup_request)
656 { 564 {
657 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 565 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
658 "Lookup launched, waiting for a reply\n"); 566 "Lookup launched, waiting for a reply\n");
659 GNUNET_SERVER_receive_done (client, GNUNET_OK); 567 GNUNET_SERVICE_client_continue (client);
660 GNUNET_CONTAINER_DLL_insert (rq_head, rq_tail, rq); 568 GNUNET_CONTAINER_DLL_insert (rq_head,
569 rq_tail,
570 rq);
661 } 571 }
662 else 572 else
663 { 573 {
@@ -667,110 +577,105 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
667 if (rq->u8name) 577 if (rq->u8name)
668 free (rq->u8name); 578 free (rq->u8name);
669 GNUNET_free (rq); 579 GNUNET_free (rq);
670 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 580 GNUNET_SERVICE_client_drop (client);
671 } 581 }
672} 582}
673 583
674 584
675/** 585/**
676 * Handle GET-message. 586 * Check GET-message.
677 * 587 *
678 * @param cls closure 588 * @param cls identification of the client
679 * @param client identification of the client 589 * @param msg the actual message
680 * @param message the actual message 590 * @return #GNUNET_OK if @a msg is well-formed
681 */ 591 */
682static void 592static int
683handle_get (void *cls, struct GNUNET_SERVER_Client *client, 593check_get (void *cls,
684 const struct GNUNET_MessageHeader *message) 594 const struct GNUNET_W32RESOLVER_GetMessage *msg)
685{ 595{
686 uint16_t msize;
687 const struct GNUNET_W32RESOLVER_GetMessage *msg;
688 GUID sc;
689 uint16_t size; 596 uint16_t size;
690 int i;
691 const wchar_t *hostname; 597 const wchar_t *hostname;
692 int af;
693
694 if (!got_egos)
695 {
696 /*
697 * FIXME: be done with GNUNET_OK, put the get request into a queue?
698 * or postpone GNUNET_SERVER_add_handlers() until egos are obtained?
699 */
700 GNUNET_SERVER_receive_done (client, GNUNET_NO);
701 return;
702 }
703 598
704 msize = ntohs (message->size); 599 if (! got_egos)
705 if (msize <= sizeof (struct GNUNET_W32RESOLVER_GetMessage))
706 { 600 {
707 GNUNET_break (0); 601 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
708 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 602 _("Not ready to process requests, lacking ego data\n"));
709 return; 603 return GNUNET_SYSERR;
710 } 604 }
711 msg = (const struct GNUNET_W32RESOLVER_GetMessage *) message; 605 size = ntohs (msg->header.size) - sizeof (struct GNUNET_W32RESOLVER_GetMessage);
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]; 606 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') 607 if (hostname[size / 2 - 1] != L'\0')
733 { 608 {
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); 609 GNUNET_break (0);
737 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 610 return GNUNET_SYSERR;
738 return;
739 } 611 }
740 get_ip_from_hostname (client, hostname, af, sc); 612 return GNUNET_OK;
741} 613}
742 614
743 615
744/** 616/**
745 * Method called to with the ego we are to use for shortening 617 * Handle GET-message.
746 * during the lookup.
747 * 618 *
748 * @param cls closure (NULL, unused) 619 * @param cls identification of the client
749 * @param ego ego handle, NULL if not found 620 * @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 */ 621 */
756static void 622static void
757identity_shorten_cb (void *cls, 623handle_get (void *cls,
758 struct GNUNET_IDENTITY_Ego *ego, 624 const struct GNUNET_W32RESOLVER_GetMessage *msg)
759 void **ctx,
760 const char *name)
761{ 625{
762 id_op = NULL; 626 struct GNUNET_SERVICE_Client *client = cls;
763 if (NULL == ego) 627 GUID sc;
764 { 628 uint16_t size;
765 fprintf (stderr, 629 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")); 630 int af;
767 GNUNET_SCHEDULER_shutdown (); 631
768 return; 632 size = ntohs (msg->header.size) - sizeof (struct GNUNET_W32RESOLVER_GetMessage);
769 } 633 af = ntohl (msg->af);
770 gns_short_privkey = *GNUNET_IDENTITY_ego_get_private_key (ego); 634 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
771 got_egos = 1; 635 "Got NBO GUID: %08X-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
636 msg->sc_data1,
637 msg->sc_data2,
638 msg->sc_data3,
639 msg->sc_data4[0],
640 msg->sc_data4[1],
641 msg->sc_data4[2],
642 msg->sc_data4[3],
643 msg->sc_data4[4],
644 msg->sc_data4[5],
645 msg->sc_data4[6],
646 msg->sc_data4[7]);
647 sc.Data1 = ntohl (msg->sc_data1);
648 sc.Data2 = ntohs (msg->sc_data2);
649 sc.Data3 = ntohs (msg->sc_data3);
650 for (int i = 0; i < 8; i++)
651 sc.Data4[i] = msg->sc_data4[i];
652 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
653 "Got GUID: %08lX-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
654 sc.Data1,
655 sc.Data2,
656 sc.Data3,
657 sc.Data4[0],
658 sc.Data4[1],
659 sc.Data4[2],
660 sc.Data4[3],
661 sc.Data4[4],
662 sc.Data4[5],
663 sc.Data4[6],
664 sc.Data4[7]);
665 hostname = (const wchar_t *) &msg[1];
666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
667 "Name of %u bytes (last word is 0x%0X): %*S\n",
668 size,
669 hostname[size / 2 - 2],
670 size / 2,
671 hostname);
672 get_ip_from_hostname (client,
673 hostname,
674 af,
675 sc);
772} 676}
773 677
678
774/** 679/**
775 * Method called to with the ego we are to use for the lookup, 680 * 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. 681 * when the ego is the one for the default master zone.
@@ -785,22 +690,21 @@ identity_shorten_cb (void *cls,
785 */ 690 */
786static void 691static void
787identity_master_cb (void *cls, 692identity_master_cb (void *cls,
788 struct GNUNET_IDENTITY_Ego *ego, 693 struct GNUNET_IDENTITY_Ego *ego,
789 void **ctx, 694 void **ctx,
790 const char *name) 695 const char *name)
791{ 696{
792 id_op = NULL; 697 id_op = NULL;
793 if (NULL == ego) 698 if (NULL == ego)
794 { 699 {
795 fprintf (stderr, 700 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
796 _("Ego for `gns-master' not found, cannot perform lookup. Did you run gnunet-gns-import.sh?\n")); 701 _("Ego for `gns-master' not found, cannot perform lookup. Did you run gnunet-gns-import.sh?\n"));
797 GNUNET_SCHEDULER_shutdown (); 702 GNUNET_SCHEDULER_shutdown ();
798 return; 703 return;
799 } 704 }
800 GNUNET_IDENTITY_ego_get_public_key (ego, &gns_master_pubkey); 705 GNUNET_IDENTITY_ego_get_public_key (ego,
801 id_op = GNUNET_IDENTITY_get (identity, "gns-short", &identity_shorten_cb, 706 &gns_master_pubkey);
802 NULL); 707 got_egos = 1;
803 GNUNET_assert (NULL != id_op);
804} 708}
805 709
806 710
@@ -808,59 +712,90 @@ identity_master_cb (void *cls,
808 * Start up gns-helper-w32 service. 712 * Start up gns-helper-w32 service.
809 * 713 *
810 * @param cls closure 714 * @param cls closure
811 * @param server the initialized server
812 * @param cfg configuration to use 715 * @param cfg configuration to use
716 * @param service the initialized service
813 */ 717 */
814static void 718static void
815run (void *cls, struct GNUNET_SERVER_Handle *server, 719run (void *cls,
816 const struct GNUNET_CONFIGURATION_Handle *cfg) 720 const struct GNUNET_CONFIGURATION_Handle *cfg,
721 struct GNUNET_SERVICE_Handle *service)
817{ 722{
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); 723 gns = GNUNET_GNS_connect (cfg);
824 if (NULL == gns) 724 if (NULL == gns)
825 { 725 {
826 fprintf (stderr, _("Failed to connect to GNS\n")); 726 fprintf (stderr,
727 _("Failed to connect to GNS\n"));
827 GNUNET_SCHEDULER_shutdown (); 728 GNUNET_SCHEDULER_shutdown ();
828 return; 729 return;
829 } 730 }
830 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 731 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
831 NULL); 732 NULL);
832 733 identity = GNUNET_IDENTITY_connect (cfg,
833 identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL); 734 NULL,
735 NULL);
834 if (NULL == identity) 736 if (NULL == identity)
835 { 737 {
836 fprintf (stderr, _("Failed to connect to identity service\n")); 738 fprintf (stderr,
739 _("Failed to connect to identity service\n"));
837 GNUNET_SCHEDULER_shutdown (); 740 GNUNET_SCHEDULER_shutdown ();
838 return; 741 return;
839 } 742 }
840 743 id_op = GNUNET_IDENTITY_get (identity,
841 id_op = GNUNET_IDENTITY_get (identity, "gns-master", &identity_master_cb, 744 "gns-master",
842 NULL); 745 &identity_master_cb,
746 NULL);
843 GNUNET_assert (NULL != id_op); 747 GNUNET_assert (NULL != id_op);
844
845 GNUNET_SERVER_add_handlers (server, handlers);
846} 748}
847 749
848 750
849/** 751/**
850 * The main function for gns-helper-w32. 752 * Handle client connecting to the service.
851 * 753 *
852 * @param argc number of arguments from the command line 754 * @param cls NULL
853 * @param argv command line arguments 755 * @param client the new client
854 * @return 0 ok, 1 on error 756 * @param mq the message queue of @a client
757 * @return @a client
855 */ 758 */
856int 759static void *
857main (int argc, char *const *argv) 760client_connect_cb (void *cls,
761 struct GNUNET_SERVICE_Client *client,
762 struct GNUNET_MQ_Handle *mq)
858{ 763{
859 int ret; 764 return client;
765}
860 766
861 ret = GNUNET_SERVICE_run (argc, argv, "gns-helper-service-w32", 767
862 GNUNET_SERVICE_OPTION_NONE, &run, NULL); 768/**
863 return (GNUNET_OK == ret) ? 0 : 1; 769 * Callback called when a client disconnected from the service
770 *
771 * @param cls closure for the service
772 * @param c the client that disconnected
773 * @param internal_cls should be equal to @a c
774 */
775static void
776client_disconnect_cb (void *cls,
777 struct GNUNET_SERVICE_Client *client,
778 void *internal_cls)
779{
780 GNUNET_assert (internal_cls == client);
864} 781}
865 782
783
784/**
785 * Define "main" method using service macro.
786 */
787GNUNET_SERVICE_MAIN
788("gns-helper-service-w32",
789 GNUNET_SERVICE_OPTION_NONE,
790 &run,
791 &client_connect_cb,
792 &client_disconnect_cb,
793 NULL,
794 GNUNET_MQ_hd_var_size (get,
795 GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST,
796 struct GNUNET_W32RESOLVER_GetMessage,
797 NULL),
798 GNUNET_MQ_handler_end());
799
800
866/* end of gnunet-gns-helper-service-w32.c */ 801/* end of gnunet-gns-helper-service-w32.c */
diff --git a/src/gns/gnunet-gns-import.c b/src/gns/gnunet-gns-import.c
index e98babfa8..49f6e495f 100644
--- a/src/gns/gnunet-gns-import.c
+++ b/src/gns/gnunet-gns-import.c
@@ -224,45 +224,52 @@ zone_iterator (void *cls,
224 else if (0 == strcmp (rname, "pin")) 224 else if (0 == strcmp (rname, "pin"))
225 check_pkey (rd_len, rd, pin_zone_pkey, &found_pin_rec); 225 check_pkey (rd_len, rd, pin_zone_pkey, &found_pin_rec);
226 } 226 }
227 if (NULL == rname && 0 == rd_len && NULL == rd) 227 GNUNET_NAMESTORE_zone_iterator_next (list_it);
228}
229
230static void
231zone_iteration_error (void *cls)
232{
233 enum GNUNET_OS_ProcessStatusType st;
234 unsigned long code;
235 if (!found_private_rec)
228 { 236 {
229 enum GNUNET_OS_ProcessStatusType st; 237 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code,
230 unsigned long code; 238 "gnunet-namestore",
231 if (!found_private_rec) 239 "gnunet-namestore", "-z", "master-zone", "-a", "-e", "never", "-n", "private", "-p", "-t", "PKEY", "-V", private_zone_pkey, NULL))
232 { 240 {
233 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, 241 ret = 8;
234 "gnunet-namestore", 242 return;
235 "gnunet-namestore", "-z", "master-zone", "-a", "-e", "never", "-n", "private", "-p", "-t", "PKEY", "-V", private_zone_pkey, NULL))
236 {
237 ret = 8;
238 return;
239 }
240 } 243 }
241 if (!found_short_rec) 244 }
245 if (!found_short_rec)
246 {
247 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code,
248 "gnunet-namestore",
249 "gnunet-namestore", "-z", "master-zone", "-a", "-e", "never", "-n", "short", "-p", "-t", "PKEY", "-V", short_zone_pkey, NULL))
242 { 250 {
243 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, 251 ret = 9;
244 "gnunet-namestore", 252 return;
245 "gnunet-namestore", "-z", "master-zone", "-a", "-e", "never", "-n", "short", "-p", "-t", "PKEY", "-V", short_zone_pkey, NULL))
246 {
247 ret = 9;
248 return;
249 }
250 } 253 }
251 if (!found_pin_rec) 254 }
255 if (!found_pin_rec)
256 {
257 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code,
258 "gnunet-namestore",
259 "gnunet-namestore", "-z", "master-zone", "-a", "-e", "never", "-n", "pin", "-p", "-t", "PKEY", "-V", pin_zone_pkey, NULL))
252 { 260 {
253 if (0 != run_process_and_wait (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, &st, &code, 261 ret = 10;
254 "gnunet-namestore", 262 return;
255 "gnunet-namestore", "-z", "master-zone", "-a", "-e", "never", "-n", "pin", "-p", "-t", "PKEY", "-V", pin_zone_pkey, NULL))
256 {
257 ret = 10;
258 return;
259 }
260 } 263 }
261 list_it = NULL;
262 GNUNET_SCHEDULER_shutdown ();
263 return;
264 } 264 }
265 GNUNET_NAMESTORE_zone_iterator_next (list_it); 265 list_it = NULL;
266 GNUNET_SCHEDULER_shutdown ();
267}
268
269
270static void
271zone_iteration_finished (void *cls)
272{
266} 273}
267 274
268 275
@@ -317,7 +324,7 @@ get_ego (void *cls,
317 return; 324 return;
318 } 325 }
319 list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, 326 list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
320 &master_pk, &zone_iterator, NULL); 327 &master_pk, &zone_iteration_error, NULL, &zone_iterator, NULL, &zone_iteration_finished, NULL);
321 if (NULL == list_it) 328 if (NULL == list_it)
322 { 329 {
323 ret = 12; 330 ret = 12;
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 3a38970a8..2a6de1c30 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -606,7 +606,7 @@ struct Socks5Request
606 * Headers from response 606 * Headers from response
607 */ 607 */
608 struct HttpResponseHeader *header_tail; 608 struct HttpResponseHeader *header_tail;
609 609
610 /** 610 /**
611 * SSL Certificate status 611 * SSL Certificate status
612 */ 612 */
@@ -621,7 +621,7 @@ struct Socks5Request
621/** 621/**
622 * The port the proxy is running on (default 7777) 622 * The port the proxy is running on (default 7777)
623 */ 623 */
624static unsigned long port = GNUNET_GNS_PROXY_PORT; 624static unsigned long long port = GNUNET_GNS_PROXY_PORT;
625 625
626/** 626/**
627 * The CA file (pem) to use for the proxy CA 627 * The CA file (pem) to use for the proxy CA
@@ -695,16 +695,6 @@ static struct Socks5Request *s5r_tail;
695static struct GNUNET_CRYPTO_EcdsaPublicKey local_gns_zone; 695static struct GNUNET_CRYPTO_EcdsaPublicKey local_gns_zone;
696 696
697/** 697/**
698 * The users local shorten zone
699 */
700static struct GNUNET_CRYPTO_EcdsaPrivateKey local_shorten_zone;
701
702/**
703 * Is shortening enabled?
704 */
705static int do_shorten;
706
707/**
708 * The CA for SSL certificate generation 698 * The CA for SSL certificate generation
709 */ 699 */
710static struct ProxyCA proxy_ca; 700static struct ProxyCA proxy_ca;
@@ -873,9 +863,10 @@ check_ssl_certificate (struct Socks5Request *s5r)
873 gnutls_x509_crt_t x509_cert; 863 gnutls_x509_crt_t x509_cert;
874 int rc; 864 int rc;
875 const char *name; 865 const char *name;
876 866
877 s5r->ssl_checked = GNUNET_YES; 867 s5r->ssl_checked = GNUNET_YES;
878 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "XXXXXX\n"); 868 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
869 "Checking SSL certificate\n");
879 if (CURLE_OK != 870 if (CURLE_OK !=
880 curl_easy_getinfo (s5r->curl, 871 curl_easy_getinfo (s5r->curl,
881 CURLINFO_TLS_SESSION, 872 CURLINFO_TLS_SESSION,
@@ -1039,7 +1030,7 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls)
1039 size_t delta_cdomain; 1030 size_t delta_cdomain;
1040 int domain_matched; 1031 int domain_matched;
1041 char *tok; 1032 char *tok;
1042 1033
1043 /* first, check SSL certificate */ 1034 /* first, check SSL certificate */
1044 if ((GNUNET_YES != s5r->ssl_checked) && 1035 if ((GNUNET_YES != s5r->ssl_checked) &&
1045 (HTTPS_PORT == s5r->port)) 1036 (HTTPS_PORT == s5r->port))
@@ -1047,7 +1038,7 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls)
1047 if (GNUNET_OK != check_ssl_certificate (s5r)) 1038 if (GNUNET_OK != check_ssl_certificate (s5r))
1048 return 0; 1039 return 0;
1049 } 1040 }
1050 1041
1051 ndup = GNUNET_strndup (buffer, bytes); 1042 ndup = GNUNET_strndup (buffer, bytes);
1052 hdr_type = strtok (ndup, ":"); 1043 hdr_type = strtok (ndup, ":");
1053 if (NULL == hdr_type) 1044 if (NULL == hdr_type)
@@ -1287,7 +1278,7 @@ curl_upload_cb (void *buf, size_t size, size_t nmemb, void *cls)
1287 struct Socks5Request *s5r = cls; 1278 struct Socks5Request *s5r = cls;
1288 size_t len = size * nmemb; 1279 size_t len = size * nmemb;
1289 size_t to_copy; 1280 size_t to_copy;
1290 1281
1291 if ( (0 == s5r->io_len) && 1282 if ( (0 == s5r->io_len) &&
1292 (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state) ) 1283 (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state) )
1293 { 1284 {
@@ -1763,7 +1754,7 @@ create_response (void *cls,
1763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1754 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1764 "Processing %u bytes UPLOAD\n", 1755 "Processing %u bytes UPLOAD\n",
1765 (unsigned int) *upload_data_size); 1756 (unsigned int) *upload_data_size);
1766 1757
1767 /* FIXME: This must be set or a header with Transfer-Encoding: chunked. Else 1758 /* FIXME: This must be set or a header with Transfer-Encoding: chunked. Else
1768 * upload callback is not called! 1759 * upload callback is not called!
1769 */ 1760 */
@@ -1892,19 +1883,22 @@ mhd_connection_cb (void *cls,
1892 { 1883 {
1893 if (GNUNET_NETWORK_get_fd (s5r->sock) == sock) 1884 if (GNUNET_NETWORK_get_fd (s5r->sock) == sock)
1894 { 1885 {
1895 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Context set...\n"); 1886 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1887 "Context set...\n");
1888 s5r->ssl_checked = GNUNET_NO;
1896 *con_cls = s5r; 1889 *con_cls = s5r;
1897 break; 1890 break;
1898 } 1891 }
1899 } 1892 }
1900 s5r->ssl_checked = GNUNET_NO;
1901 break; 1893 break;
1902 case MHD_CONNECTION_NOTIFY_CLOSED: 1894 case MHD_CONNECTION_NOTIFY_CLOSED:
1903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection closed... cleaning up\n"); 1895 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1896 "Connection closed... cleaning up\n");
1904 s5r = *con_cls; 1897 s5r = *con_cls;
1905 if (NULL == s5r) 1898 if (NULL == s5r)
1906 { 1899 {
1907 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection stale!\n"); 1900 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1901 "Connection stale!\n");
1908 return; 1902 return;
1909 } 1903 }
1910 cleanup_s5r (s5r); 1904 cleanup_s5r (s5r);
@@ -2827,7 +2821,6 @@ do_s5r_read (void *cls)
2827 &local_gns_zone, 2821 &local_gns_zone,
2828 GNUNET_DNSPARSER_TYPE_A, 2822 GNUNET_DNSPARSER_TYPE_A,
2829 GNUNET_NO /* only cached */, 2823 GNUNET_NO /* only cached */,
2830 (GNUNET_YES == do_shorten) ? &local_shorten_zone : NULL,
2831 &handle_gns_result, 2824 &handle_gns_result,
2832 s5r); 2825 s5r);
2833 break; 2826 break;
@@ -3115,7 +3108,7 @@ run_cont ()
3115 return; 3108 return;
3116 } 3109 }
3117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3118 "Proxy listens on port %lu\n", 3111 "Proxy listens on port %llu\n",
3119 port); 3112 port);
3120 3113
3121 /* start MHD daemon for HTTP */ 3114 /* start MHD daemon for HTTP */
@@ -3141,46 +3134,6 @@ run_cont ()
3141 3134
3142 3135
3143/** 3136/**
3144 * Method called to inform about the egos of the shorten zone of this peer.
3145 *
3146 * When used with #GNUNET_IDENTITY_create or #GNUNET_IDENTITY_get,
3147 * this function is only called ONCE, and 'NULL' being passed in
3148 * @a ego does indicate an error (i.e. name is taken or no default
3149 * value is known). If @a ego is non-NULL and if '*ctx'
3150 * is set in those callbacks, the value WILL be passed to a subsequent
3151 * call to the identity callback of #GNUNET_IDENTITY_connect (if
3152 * that one was not NULL).
3153 *
3154 * @param cls closure, NULL
3155 * @param ego ego handle
3156 * @param ctx context for application to store data for this ego
3157 * (during the lifetime of this process, initially NULL)
3158 * @param name name assigned by the user for this ego,
3159 * NULL if the user just deleted the ego and it
3160 * must thus no longer be used
3161 */
3162static void
3163identity_shorten_cb (void *cls,
3164 struct GNUNET_IDENTITY_Ego *ego,
3165 void **ctx,
3166 const char *name)
3167{
3168 id_op = NULL;
3169 if (NULL == ego)
3170 {
3171 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3172 _("No ego configured for `shorten-zone`\n"));
3173 }
3174 else
3175 {
3176 local_shorten_zone = *GNUNET_IDENTITY_ego_get_private_key (ego);
3177 do_shorten = GNUNET_YES;
3178 }
3179 run_cont ();
3180}
3181
3182
3183/**
3184 * Method called to inform about the egos of the master zone of this peer. 3137 * Method called to inform about the egos of the master zone of this peer.
3185 * 3138 *
3186 * When used with #GNUNET_IDENTITY_create or #GNUNET_IDENTITY_get, 3139 * When used with #GNUNET_IDENTITY_create or #GNUNET_IDENTITY_get,
@@ -3216,10 +3169,7 @@ identity_master_cb (void *cls,
3216 } 3169 }
3217 GNUNET_IDENTITY_ego_get_public_key (ego, 3170 GNUNET_IDENTITY_ego_get_public_key (ego,
3218 &local_gns_zone); 3171 &local_gns_zone);
3219 id_op = GNUNET_IDENTITY_get (identity, 3172 run_cont ();
3220 "gns-short",
3221 &identity_shorten_cb,
3222 NULL);
3223} 3173}
3224 3174
3225 3175
@@ -3232,7 +3182,9 @@ identity_master_cb (void *cls,
3232 * @param c configuration 3182 * @param c configuration
3233 */ 3183 */
3234static void 3184static void
3235run (void *cls, char *const *args, const char *cfgfile, 3185run (void *cls,
3186 char *const *args,
3187 const char *cfgfile,
3236 const struct GNUNET_CONFIGURATION_Handle *c) 3188 const struct GNUNET_CONFIGURATION_Handle *c)
3237{ 3189{
3238 char* cafile_cfg = NULL; 3190 char* cafile_cfg = NULL;
@@ -3309,13 +3261,20 @@ run (void *cls, char *const *args, const char *cfgfile,
3309int 3261int
3310main (int argc, char *const *argv) 3262main (int argc, char *const *argv)
3311{ 3263{
3312 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 3264 struct GNUNET_GETOPT_CommandLineOption options[] = {
3313 {'p', "port", NULL, 3265
3314 gettext_noop ("listen on specified port (default: 7777)"), 1, 3266 GNUNET_GETOPT_option_ulong ('p',
3315 &GNUNET_GETOPT_set_ulong, &port}, 3267 "port",
3316 {'a', "authority", NULL, 3268 NULL,
3317 gettext_noop ("pem file to use as CA"), 1, 3269 gettext_noop ("listen on specified port (default: 7777)"),
3318 &GNUNET_GETOPT_set_string, &cafile_opt}, 3270 &port),
3271
3272 GNUNET_GETOPT_option_string ('a',
3273 "authority",
3274 NULL,
3275 gettext_noop ("pem file to use as CA"),
3276 &cafile_opt),
3277
3319 GNUNET_GETOPT_OPTION_END 3278 GNUNET_GETOPT_OPTION_END
3320 }; 3279 };
3321 static const char* page = 3280 static const char* page =
@@ -3323,22 +3282,26 @@ main (int argc, char *const *argv)
3323 "</head><body>cURL fail</body></html>"; 3282 "</head><body>cURL fail</body></html>";
3324 int ret; 3283 int ret;
3325 3284
3326 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 3285 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv,
3286 &argc, &argv))
3327 return 2; 3287 return 2;
3328 GNUNET_log_setup ("gnunet-gns-proxy", "WARNING", NULL); 3288 GNUNET_log_setup ("gnunet-gns-proxy",
3329 curl_failure_response = MHD_create_response_from_buffer (strlen (page), 3289 "WARNING",
3330 (void*)page, 3290 NULL);
3331 MHD_RESPMEM_PERSISTENT); 3291 curl_failure_response
3292 = MHD_create_response_from_buffer (strlen (page),
3293 (void *) page,
3294 MHD_RESPMEM_PERSISTENT);
3332 3295
3333 ret = 3296 ret =
3334 (GNUNET_OK == 3297 (GNUNET_OK ==
3335 GNUNET_PROGRAM_run (argc, argv, "gnunet-gns-proxy", 3298 GNUNET_PROGRAM_run (argc, argv,
3299 "gnunet-gns-proxy",
3336 _("GNUnet GNS proxy"), 3300 _("GNUnet GNS proxy"),
3337 options, 3301 options,
3338 &run, NULL)) ? 0 : 1; 3302 &run, NULL)) ? 0 : 1;
3339 MHD_destroy_response (curl_failure_response); 3303 MHD_destroy_response (curl_failure_response);
3340 GNUNET_free_non_null ((char *) argv); 3304 GNUNET_free_non_null ((char *) argv);
3341 GNUNET_CRYPTO_ecdsa_key_clear (&local_shorten_zone);
3342 return ret; 3305 return ret;
3343} 3306}
3344 3307
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
index 17fe4cbda..c0de0f30c 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.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-2013 GNUnet e.V. 3 Copyright (C) 2012-2013, 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
@@ -66,16 +66,6 @@ static char *zone_ego_name;
66static char *public_key; 66static char *public_key;
67 67
68/** 68/**
69 * Reverse key
70 */
71static char *reverse_key;
72
73/**
74 * Reverse key
75 */
76static struct GNUNET_CRYPTO_EcdsaPublicKey rkey;
77
78/**
79 * Set to GNUNET_GNS_LO_LOCAL_MASTER if we are looking up in the master zone. 69 * Set to GNUNET_GNS_LO_LOCAL_MASTER if we are looking up in the master zone.
80 */ 70 */
81static enum GNUNET_GNS_LocalOptions local_options; 71static enum GNUNET_GNS_LocalOptions local_options;
@@ -96,11 +86,6 @@ static int rtype;
96static struct GNUNET_GNS_LookupRequest *lookup_request; 86static struct GNUNET_GNS_LookupRequest *lookup_request;
97 87
98/** 88/**
99 * Handle to reverse lookup request
100 */
101static struct GNUNET_GNS_ReverseLookupRequest *rev_lookup_request;
102
103/**
104 * Lookup an ego with the identity service. 89 * Lookup an ego with the identity service.
105 */ 90 */
106static struct GNUNET_IDENTITY_EgoLookup *el; 91static struct GNUNET_IDENTITY_EgoLookup *el;
@@ -174,24 +159,6 @@ do_timeout (void *cls)
174 GNUNET_SCHEDULER_shutdown (); 159 GNUNET_SCHEDULER_shutdown ();
175} 160}
176 161
177static void
178process_reverse_result (void *cls,
179 const char *name)
180{
181 rev_lookup_request = NULL;
182 if (NULL == name)
183 {
184 printf ("No name found.\n");
185 return;
186 }
187 if (raw)
188 printf ("%s\n", name);
189 else
190 printf ("%s is known as %s\n",
191 reverse_key,
192 name);
193 GNUNET_SCHEDULER_shutdown ();
194}
195 162
196/** 163/**
197 * Function called with the result of a GNS lookup. 164 * Function called with the result of a GNS lookup.
@@ -201,7 +168,8 @@ process_reverse_result (void *cls,
201 * @param rd array of @a rd_count records with the results 168 * @param rd array of @a rd_count records with the results
202 */ 169 */
203static void 170static void
204process_lookup_result (void *cls, uint32_t rd_count, 171process_lookup_result (void *cls,
172 uint32_t rd_count,
205 const struct GNUNET_GNSRECORD_Data *rd) 173 const struct GNUNET_GNSRECORD_Data *rd)
206{ 174{
207 const char *name = cls; 175 const char *name = cls;
@@ -253,11 +221,9 @@ process_lookup_result (void *cls, uint32_t rd_count,
253 * identified by the given public key and the shorten zone. 221 * identified by the given public key and the shorten zone.
254 * 222 *
255 * @param pkey public key to use for the zone, can be NULL 223 * @param pkey public key to use for the zone, can be NULL
256 * @param shorten_key private key used for shortening, can be NULL
257 */ 224 */
258static void 225static void
259lookup_with_keys (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, 226lookup_with_public_key (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
260 const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_key)
261{ 227{
262 if (NULL != lookup_type) 228 if (NULL != lookup_type)
263 rtype = GNUNET_GNSRECORD_typename_to_number (lookup_type); 229 rtype = GNUNET_GNSRECORD_typename_to_number (lookup_type);
@@ -277,18 +243,9 @@ lookup_with_keys (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey,
277 pkey, 243 pkey,
278 rtype, 244 rtype,
279 local_options, 245 local_options,
280 shorten_key,
281 &process_lookup_result, 246 &process_lookup_result,
282 lookup_name); 247 lookup_name);
283 } 248 }
284 else if (NULL != reverse_key)
285 {
286 rev_lookup_request = GNUNET_GNS_reverse_lookup (gns,
287 &rkey,
288 pkey,
289 &process_reverse_result,
290 NULL);
291 }
292 else 249 else
293 { 250 {
294 fprintf (stderr, 251 fprintf (stderr,
@@ -300,63 +257,6 @@ lookup_with_keys (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey,
300 257
301 258
302/** 259/**
303 * Method called to with the ego we are to use for shortening
304 * during the lookup.
305 *
306 * @param cls closure contains the public key to use
307 * @param ego ego handle, NULL if not found
308 * @param ctx context for application to store data for this ego
309 * (during the lifetime of this process, initially NULL)
310 * @param name name assigned by the user for this ego,
311 * NULL if the user just deleted the ego and it
312 * must thus no longer be used
313 */
314static void
315identity_shorten_cb (void *cls,
316 struct GNUNET_IDENTITY_Ego *ego,
317 void **ctx,
318 const char *name)
319{
320 struct GNUNET_CRYPTO_EcdsaPublicKey *pkeym = cls;
321
322 id_op = NULL;
323 if (NULL == ego)
324 lookup_with_keys (pkeym, NULL);
325 else
326 lookup_with_keys (pkeym,
327 GNUNET_IDENTITY_ego_get_private_key (ego));
328 GNUNET_free (pkeym);
329}
330
331
332/**
333 * Perform the actual resolution, starting with the zone
334 * identified by the given public key.
335 *
336 * @param pkey public key to use for the zone
337 */
338static void
339lookup_with_public_key (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
340{
341 struct GNUNET_CRYPTO_EcdsaPublicKey *pkeym;
342
343 GNUNET_assert (NULL != pkey);
344 pkeym = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
345 *pkeym = *pkey;
346 GNUNET_break (NULL == id_op);
347 id_op = GNUNET_IDENTITY_get (identity,
348 "gns-short",
349 &identity_shorten_cb,
350 pkeym);
351 if (NULL == id_op)
352 {
353 GNUNET_break (0);
354 lookup_with_keys (pkey, NULL);
355 }
356}
357
358
359/**
360 * Method called to with the ego we are to use for the lookup, 260 * Method called to with the ego we are to use for the lookup,
361 * when the ego is determined by a name. 261 * when the ego is determined by a name.
362 * 262 *
@@ -449,7 +349,6 @@ run (void *cls,
449 349
450 cfg = c; 350 cfg = c;
451 gns = GNUNET_GNS_connect (cfg); 351 gns = GNUNET_GNS_connect (cfg);
452 identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
453 if (NULL == gns) 352 if (NULL == gns)
454 { 353 {
455 fprintf (stderr, 354 fprintf (stderr,
@@ -457,22 +356,13 @@ run (void *cls,
457 return; 356 return;
458 } 357 }
459 tt = GNUNET_SCHEDULER_add_delayed (timeout, 358 tt = GNUNET_SCHEDULER_add_delayed (timeout,
460 &do_timeout, NULL); 359 &do_timeout,
461 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 360 NULL);
462 if (NULL != reverse_key) 361 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
463 { 362 NULL);
464 if (GNUNET_OK != 363 identity = GNUNET_IDENTITY_connect (cfg,
465 GNUNET_CRYPTO_ecdsa_public_key_from_string (reverse_key, 364 NULL,
466 strlen (reverse_key), 365 NULL);
467 &rkey))
468 {
469 fprintf (stderr,
470 _("Reverse key `%s' is not well-formed\n"),
471 reverse_key);
472 GNUNET_SCHEDULER_shutdown ();
473 return;
474 }
475 }
476 if (NULL != public_key) 366 if (NULL != public_key)
477 { 367 {
478 if (GNUNET_OK != 368 if (GNUNET_OK !=
@@ -489,20 +379,6 @@ run (void *cls,
489 lookup_with_public_key (&pkey); 379 lookup_with_public_key (&pkey);
490 return; 380 return;
491 } 381 }
492 if (NULL != reverse_key)
493 {
494 if (GNUNET_OK !=
495 GNUNET_CRYPTO_ecdsa_public_key_from_string (reverse_key,
496 strlen (reverse_key),
497 &rkey))
498 {
499 fprintf (stderr,
500 _("Reverse key `%s' is not well-formed\n"),
501 reverse_key);
502 GNUNET_SCHEDULER_shutdown ();
503 return;
504 }
505 }
506 if (NULL != zone_ego_name) 382 if (NULL != zone_ego_name)
507 { 383 {
508 el = GNUNET_IDENTITY_ego_lookup (cfg, 384 el = GNUNET_IDENTITY_ego_lookup (cfg,
@@ -541,42 +417,62 @@ run (void *cls,
541 * @return 0 ok, 1 on error 417 * @return 0 ok, 1 on error
542 */ 418 */
543int 419int
544main (int argc, char *const *argv) 420main (int argc,
421 char *const *argv)
545{ 422{
546 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 423 struct GNUNET_GETOPT_CommandLineOption options[] = {
547 {'u', "lookup", "NAME", 424
548 gettext_noop ("Lookup a record for the given name"), 1, 425 GNUNET_GETOPT_option_string ('u',
549 &GNUNET_GETOPT_set_string, &lookup_name}, 426 "lookup",
550 {'t', "type", "TYPE", 427 "NAME",
551 gettext_noop ("Specify the type of the record to lookup"), 1, 428 gettext_noop ("Lookup a record for the given name"),
552 &GNUNET_GETOPT_set_string, &lookup_type}, 429 &lookup_name),
553 { 'T', "timeout", "DELAY", 430
554 gettext_noop ("Specify timeout for the lookup"), 1, 431 GNUNET_GETOPT_option_string ('t',
555 &GNUNET_GETOPT_set_relative_time, &timeout }, 432 "type",
556 {'r', "raw", NULL, 433 "TYPE",
557 gettext_noop ("No unneeded output"), 0, 434 gettext_noop ("Specify the type of the record to lookup"),
558 &GNUNET_GETOPT_set_one, &raw}, 435 &lookup_type),
559 {'p', "public-key", "PKEY", 436
560 gettext_noop ("Specify the public key of the zone to lookup the record in"), 1, 437 GNUNET_GETOPT_option_relative_time ('T',
561 &GNUNET_GETOPT_set_string, &public_key}, 438 "timeout",
562 {'z', "zone", "NAME", 439 "DELAY",
563 gettext_noop ("Specify the name of the ego of the zone to lookup the record in"), 1, 440 gettext_noop ("Specify timeout for the lookup"),
564 &GNUNET_GETOPT_set_string, &zone_ego_name}, 441 &timeout),
565 {'R', "reverse", "PKEY", 442
566 gettext_noop ("Specify the public key of the zone to reverse lookup a name for"), 1, 443 GNUNET_GETOPT_option_flag ('r',
567 &GNUNET_GETOPT_set_string, &reverse_key}, 444 "raw",
445 gettext_noop ("No unneeded output"),
446 &raw),
447
448 GNUNET_GETOPT_option_string ('p',
449 "public-key",
450 "PKEY",
451 gettext_noop ("Specify the public key of the zone to lookup the record in"),
452 &public_key),
453
454 GNUNET_GETOPT_option_string ('z',
455 "zone",
456 "NAME",
457 gettext_noop ("Specify the name of the ego of the zone to lookup the record in"),
458 &zone_ego_name),
459
568 GNUNET_GETOPT_OPTION_END 460 GNUNET_GETOPT_OPTION_END
569 }; 461 };
570 int ret; 462 int ret;
571 463
572 timeout = GNUNET_TIME_UNIT_FOREVER_REL; 464 timeout = GNUNET_TIME_UNIT_FOREVER_REL;
573 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 465 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv,
466 &argc, &argv))
574 return 2; 467 return 2;
575 468
576 GNUNET_log_setup ("gnunet-gns", "WARNING", NULL); 469 GNUNET_log_setup ("gnunet-gns",
470 "WARNING",
471 NULL);
577 ret = 472 ret =
578 (GNUNET_OK == 473 (GNUNET_OK ==
579 GNUNET_PROGRAM_run (argc, argv, "gnunet-gns", 474 GNUNET_PROGRAM_run (argc, argv,
475 "gnunet-gns",
580 _("GNUnet GNS resolver tool"), 476 _("GNUnet GNS resolver tool"),
581 options, 477 options,
582 &run, NULL)) ? 0 : 1; 478 &run, NULL)) ? 0 : 1;
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index cec31ff48..0ca25ac19 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -29,14 +29,11 @@
29#include "gnunet_dnsparser_lib.h" 29#include "gnunet_dnsparser_lib.h"
30#include "gnunet_dht_service.h" 30#include "gnunet_dht_service.h"
31#include "gnunet_namecache_service.h" 31#include "gnunet_namecache_service.h"
32#include "gnunet_namestore_service.h"
33#include "gnunet_identity_service.h" 32#include "gnunet_identity_service.h"
34#include "gnunet_gns_service.h" 33#include "gnunet_gns_service.h"
35#include "gnunet_statistics_service.h" 34#include "gnunet_statistics_service.h"
36#include "gns.h" 35#include "gns.h"
37#include "gnunet-service-gns_resolver.h" 36#include "gnunet-service-gns_resolver.h"
38#include "gnunet-service-gns_reverser.h"
39#include "gnunet-service-gns_shorten.h"
40#include "gnunet-service-gns_interceptor.h" 37#include "gnunet-service-gns_interceptor.h"
41#include "gnunet_protocols.h" 38#include "gnunet_protocols.h"
42 39
@@ -61,7 +58,7 @@ struct ClientLookupHandle
61 * We keep these in a DLL. 58 * We keep these in a DLL.
62 */ 59 */
63 struct ClientLookupHandle *prev; 60 struct ClientLookupHandle *prev;
64 61
65 /** 62 /**
66 * Client handle 63 * Client handle
67 */ 64 */
@@ -73,11 +70,6 @@ struct ClientLookupHandle
73 struct GNS_ResolverHandle *lookup; 70 struct GNS_ResolverHandle *lookup;
74 71
75 /** 72 /**
76 * Active handle for a reverse lookup
77 */
78 struct GNS_ReverserHandle *rev_lookup;
79
80 /**
81 * request id 73 * request id
82 */ 74 */
83 uint32_t request_id; 75 uint32_t request_id;
@@ -119,11 +111,6 @@ static struct GNUNET_DHT_Handle *dht_handle;
119static struct GNUNET_NAMECACHE_Handle *namecache_handle; 111static struct GNUNET_NAMECACHE_Handle *namecache_handle;
120 112
121/** 113/**
122 * Our handle to the namestore service
123 */
124static struct GNUNET_NAMESTORE_Handle *namestore_handle;
125
126/**
127 * Our handle to the identity service 114 * Our handle to the identity service
128 */ 115 */
129static struct GNUNET_IDENTITY_Handle *identity_handle; 116static struct GNUNET_IDENTITY_Handle *identity_handle;
@@ -173,19 +160,12 @@ shutdown_task (void *cls)
173 identity_handle = NULL; 160 identity_handle = NULL;
174 } 161 }
175 GNS_resolver_done (); 162 GNS_resolver_done ();
176 GNS_reverse_done ();
177 GNS_shorten_done ();
178 if (NULL != statistics) 163 if (NULL != statistics)
179 { 164 {
180 GNUNET_STATISTICS_destroy (statistics, 165 GNUNET_STATISTICS_destroy (statistics,
181 GNUNET_NO); 166 GNUNET_NO);
182 statistics = NULL; 167 statistics = NULL;
183 } 168 }
184 if (NULL != namestore_handle)
185 {
186 GNUNET_NAMESTORE_disconnect (namestore_handle);
187 namestore_handle = NULL;
188 }
189 if (NULL != namecache_handle) 169 if (NULL != namecache_handle)
190 { 170 {
191 GNUNET_NAMECACHE_disconnect (namecache_handle); 171 GNUNET_NAMECACHE_disconnect (namecache_handle);
@@ -221,15 +201,13 @@ client_disconnect_cb (void *cls,
221 { 201 {
222 if (NULL != clh->lookup) 202 if (NULL != clh->lookup)
223 GNS_resolver_lookup_cancel (clh->lookup); 203 GNS_resolver_lookup_cancel (clh->lookup);
224 if (NULL != clh->rev_lookup)
225 GNS_reverse_lookup_cancel (clh->rev_lookup);
226 GNUNET_CONTAINER_DLL_remove (gc->clh_head, 204 GNUNET_CONTAINER_DLL_remove (gc->clh_head,
227 gc->clh_tail, 205 gc->clh_tail,
228 clh); 206 clh);
229 GNUNET_free (clh); 207 GNUNET_free (clh);
230 } 208 }
231 209
232 GNUNET_free (gc); 210 GNUNET_free (gc);
233} 211}
234 212
235 213
@@ -288,7 +266,9 @@ send_lookup_response (void* cls,
288 (char*) &rmsg[1]); 266 (char*) &rmsg[1]);
289 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(clh->gc->client), 267 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(clh->gc->client),
290 env); 268 env);
291 GNUNET_CONTAINER_DLL_remove (clh->gc->clh_head, clh->gc->clh_tail, clh); 269 GNUNET_CONTAINER_DLL_remove (clh->gc->clh_head,
270 clh->gc->clh_tail,
271 clh);
292 GNUNET_free (clh); 272 GNUNET_free (clh);
293 GNUNET_STATISTICS_update (statistics, 273 GNUNET_STATISTICS_update (statistics,
294 "Completed lookups", 1, 274 "Completed lookups", 1,
@@ -299,47 +279,6 @@ send_lookup_response (void* cls,
299 GNUNET_NO); 279 GNUNET_NO);
300} 280}
301 281
302/**
303 * Reply to client with the result from our reverse lookup.
304 *
305 * @param cls the closure (our client lookup handle)
306 * @param rd_count the number of records in @a rd
307 * @param rd the record data
308 */
309static void
310send_reverse_lookup_response (void* cls,
311 const char *name)
312{
313 struct ClientLookupHandle *clh = cls;
314 struct GNUNET_MQ_Envelope *env;
315 struct ReverseLookupResultMessage *rmsg;
316 size_t len;
317
318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
319 "Sending LOOKUP_RESULT message with %s\n",
320 name);
321
322 if (NULL == name)
323 len = 1;
324 else
325 len = strlen (name) + 1;
326 env = GNUNET_MQ_msg_extra (rmsg,
327 len,
328 GNUNET_MESSAGE_TYPE_GNS_REVERSE_LOOKUP_RESULT);
329 rmsg->id = clh->request_id;
330 if (1 < len)
331 GNUNET_memcpy ((char*) &rmsg[1],
332 name,
333 strlen (name));
334 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(clh->gc->client),
335 env);
336 GNUNET_CONTAINER_DLL_remove (clh->gc->clh_head, clh->gc->clh_tail, clh);
337 GNUNET_free (clh);
338 GNUNET_STATISTICS_update (statistics,
339 "Completed reverse lookups", 1,
340 GNUNET_NO);
341}
342
343 282
344/** 283/**
345 * Checks a #GNUNET_MESSAGE_TYPE_GNS_LOOKUP message 284 * Checks a #GNUNET_MESSAGE_TYPE_GNS_LOOKUP message
@@ -371,6 +310,7 @@ check_lookup (void *cls,
371 return GNUNET_OK; 310 return GNUNET_OK;
372} 311}
373 312
313
374/** 314/**
375 * Handle lookup requests from client 315 * Handle lookup requests from client
376 * 316 *
@@ -387,20 +327,18 @@ handle_lookup (void *cls,
387 struct ClientLookupHandle *clh; 327 struct ClientLookupHandle *clh;
388 char *nameptr = name; 328 char *nameptr = name;
389 const char *utf_in; 329 const char *utf_in;
390 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key;
391 330
392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
393 "Received LOOKUP message\n");
394 GNUNET_SERVICE_client_continue (gc->client); 331 GNUNET_SERVICE_client_continue (gc->client);
395 if (GNUNET_YES == ntohs (sh_msg->have_key))
396 key = &sh_msg->shorten_key;
397 else
398 key = NULL;
399 utf_in = (const char *) &sh_msg[1]; 332 utf_in = (const char *) &sh_msg[1];
400 GNUNET_STRINGS_utf8_tolower (utf_in, nameptr); 333 GNUNET_STRINGS_utf8_tolower (utf_in, nameptr);
334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
335 "Received LOOKUP `%s' message\n",
336 name);
401 337
402 clh = GNUNET_new (struct ClientLookupHandle); 338 clh = GNUNET_new (struct ClientLookupHandle);
403 GNUNET_CONTAINER_DLL_insert (gc->clh_head, gc->clh_tail, clh); 339 GNUNET_CONTAINER_DLL_insert (gc->clh_head,
340 gc->clh_tail,
341 clh);
404 clh->gc = gc; 342 clh->gc = gc;
405 clh->request_id = sh_msg->id; 343 clh->request_id = sh_msg->id;
406 if ( (GNUNET_DNSPARSER_TYPE_A == ntohl (sh_msg->type)) && 344 if ( (GNUNET_DNSPARSER_TYPE_A == ntohl (sh_msg->type)) &&
@@ -422,7 +360,6 @@ handle_lookup (void *cls,
422 clh->lookup = GNS_resolver_lookup (&sh_msg->zone, 360 clh->lookup = GNS_resolver_lookup (&sh_msg->zone,
423 ntohl (sh_msg->type), 361 ntohl (sh_msg->type),
424 name, 362 name,
425 key,
426 (enum GNUNET_GNS_LocalOptions) ntohs (sh_msg->options), 363 (enum GNUNET_GNS_LocalOptions) ntohs (sh_msg->options),
427 &send_lookup_response, clh); 364 &send_lookup_response, clh);
428 GNUNET_STATISTICS_update (statistics, 365 GNUNET_STATISTICS_update (statistics,
@@ -430,82 +367,6 @@ handle_lookup (void *cls,
430 1, GNUNET_NO); 367 1, GNUNET_NO);
431} 368}
432 369
433/**
434 * Handle reverse lookup requests from client
435 *
436 * @param cls the closure
437 * @param client the client
438 * @param message the message
439 */
440static void
441handle_rev_lookup (void *cls,
442 const struct ReverseLookupMessage *sh_msg)
443{
444 struct GnsClient *gc = cls;
445 struct ClientLookupHandle *clh;
446
447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
448 "Received REVERSE_LOOKUP message\n");
449 GNUNET_SERVICE_client_continue (gc->client);
450
451 clh = GNUNET_new (struct ClientLookupHandle);
452 GNUNET_CONTAINER_DLL_insert (gc->clh_head, gc->clh_tail, clh);
453 clh->gc = gc;
454 clh->request_id = sh_msg->id;
455 clh->rev_lookup = GNS_reverse_lookup (&sh_msg->zone_pkey,
456 &sh_msg->root_pkey,
457 &send_reverse_lookup_response,
458 clh);
459 GNUNET_STATISTICS_update (statistics,
460 "Reverse lookup attempts",
461 1, GNUNET_NO);
462}
463
464
465/**
466 * Method called to inform about the ego to be used for the master zone
467 * for DNS interceptions.
468 *
469 * This function is only called ONCE, and 'NULL' being passed in
470 * @a ego does indicate that interception is not configured.
471 * If @a ego is non-NULL, we should start to intercept DNS queries
472 * and resolve ".gnu" queries using the given ego as the master zone.
473 *
474 * @param cls closure, our `const struct GNUNET_CONFIGURATION_Handle *c`
475 * @param ego ego handle
476 * @param ctx context for application to store data for this ego
477 * (during the lifetime of this process, initially NULL)
478 * @param name name assigned by the user for this ego,
479 * NULL if the user just deleted the ego and it
480 * must thus no longer be used
481 */
482static void
483identity_reverse_cb (void *cls,
484 struct GNUNET_IDENTITY_Ego *ego,
485 void **ctx,
486 const char *name)
487{
488 identity_op = NULL;
489
490 if (NULL == ego)
491 {
492 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
493 _("No ego configured for `%s`\n"),
494 "gns-master");
495
496 return;
497 }
498 if (GNUNET_SYSERR ==
499 GNS_reverse_init (namestore_handle,
500 GNUNET_IDENTITY_ego_get_private_key (ego),
501 name))
502 {
503 GNUNET_break (0);
504 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
505 return;
506 }
507}
508
509 370
510/** 371/**
511 * Method called to inform about the ego to be used for the master zone 372 * Method called to inform about the ego to be used for the master zone
@@ -532,16 +393,10 @@ identity_intercept_cb (void *cls,
532{ 393{
533 const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 394 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
534 struct GNUNET_CRYPTO_EcdsaPublicKey dns_root; 395 struct GNUNET_CRYPTO_EcdsaPublicKey dns_root;
535 identity_op = NULL;
536 396
397 identity_op = NULL;
537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 398 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
538 "Looking for gns-intercept ego\n"); 399 "Looking for gns-intercept ego\n");
539 identity_op = GNUNET_IDENTITY_get (identity_handle,
540 "gns-reverse",
541 &identity_reverse_cb,
542 (void*)cfg);
543
544
545 if (NULL == ego) 400 if (NULL == ego)
546 { 401 {
547 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 402 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -553,10 +408,12 @@ identity_intercept_cb (void *cls,
553 GNUNET_IDENTITY_ego_get_public_key (ego, 408 GNUNET_IDENTITY_ego_get_public_key (ego,
554 &dns_root); 409 &dns_root);
555 if (GNUNET_SYSERR == 410 if (GNUNET_SYSERR ==
556 GNS_interceptor_init (&dns_root, cfg)) 411 GNS_interceptor_init (&dns_root,
412 cfg))
557 { 413 {
558 GNUNET_break (0); 414 GNUNET_break (0);
559 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 415 GNUNET_SCHEDULER_add_now (&shutdown_task,
416 NULL);
560 return; 417 return;
561 } 418 }
562} 419}
@@ -577,16 +434,8 @@ run (void *cls,
577 unsigned long long max_parallel_bg_queries = 16; 434 unsigned long long max_parallel_bg_queries = 16;
578 435
579 v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6); 436 v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6);
580 v4_enabled = GNUNET_NETWORK_test_pf (PF_INET); 437 v4_enabled = GNUNET_NETWORK_test_pf (PF_INET);
581 namestore_handle = GNUNET_NAMESTORE_connect (c); 438 namecache_handle = GNUNET_NAMECACHE_connect (c);
582 if (NULL == namestore_handle)
583 {
584 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
585 _("Failed to connect to the namestore!\n"));
586 GNUNET_SCHEDULER_shutdown ();
587 return;
588 }
589 namecache_handle = GNUNET_NAMECACHE_connect (c);
590 if (NULL == namecache_handle) 439 if (NULL == namecache_handle)
591 { 440 {
592 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 441 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -635,11 +484,9 @@ run (void *cls,
635 dht_handle, 484 dht_handle,
636 c, 485 c,
637 max_parallel_bg_queries); 486 max_parallel_bg_queries);
638 GNS_shorten_init (namestore_handle,
639 namecache_handle,
640 dht_handle);
641 statistics = GNUNET_STATISTICS_create ("gns", c); 487 statistics = GNUNET_STATISTICS_create ("gns", c);
642 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 488 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
489 NULL);
643} 490}
644 491
645 492
@@ -657,10 +504,6 @@ GNUNET_SERVICE_MAIN
657 GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 504 GNUNET_MESSAGE_TYPE_GNS_LOOKUP,
658 struct LookupMessage, 505 struct LookupMessage,
659 NULL), 506 NULL),
660 GNUNET_MQ_hd_fixed_size (rev_lookup,
661 GNUNET_MESSAGE_TYPE_GNS_REVERSE_LOOKUP,
662 struct ReverseLookupMessage,
663 NULL),
664 GNUNET_MQ_handler_end()); 507 GNUNET_MQ_handler_end());
665 508
666 509
diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c
index 7a3cfc0dd..a9e207891 100644
--- a/src/gns/gnunet-service-gns_interceptor.c
+++ b/src/gns/gnunet-service-gns_interceptor.c
@@ -333,7 +333,6 @@ handle_dns_request (void *cls,
333 ilh->lookup = GNS_resolver_lookup (&zone, 333 ilh->lookup = GNS_resolver_lookup (&zone,
334 p->queries[0].type, 334 p->queries[0].type,
335 p->queries[0].name, 335 p->queries[0].name,
336 NULL /* FIXME: enable shorten for DNS intercepts? */,
337 GNUNET_NO, 336 GNUNET_NO,
338 &reply_to_dns, ilh); 337 &reply_to_dns, ilh);
339 return; 338 return;
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 5e957871e..c58190599 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -30,7 +30,6 @@
30#include "gnunet_dht_service.h" 30#include "gnunet_dht_service.h"
31#include "gnunet_gnsrecord_lib.h" 31#include "gnunet_gnsrecord_lib.h"
32#include "gnunet_namecache_service.h" 32#include "gnunet_namecache_service.h"
33#include "gnunet_namestore_service.h"
34#include "gnunet_dns_service.h" 33#include "gnunet_dns_service.h"
35#include "gnunet_resolver_service.h" 34#include "gnunet_resolver_service.h"
36#include "gnunet_revocation_service.h" 35#include "gnunet_revocation_service.h"
@@ -39,7 +38,6 @@
39#include "gnunet_gns_service.h" 38#include "gnunet_gns_service.h"
40#include "gns.h" 39#include "gns.h"
41#include "gnunet-service-gns_resolver.h" 40#include "gnunet-service-gns_resolver.h"
42#include "gnunet-service-gns_shorten.h"
43#include "gnunet_vpn_service.h" 41#include "gnunet_vpn_service.h"
44 42
45 43
@@ -327,11 +325,6 @@ struct GNS_ResolverHandle
327 struct AuthorityChain *ac_tail; 325 struct AuthorityChain *ac_tail;
328 326
329 /** 327 /**
330 * Private key of the shorten zone, NULL to not shorten.
331 */
332 struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_key;
333
334 /**
335 * ID of a task associated with the resolution process. 328 * ID of a task associated with the resolution process.
336 */ 329 */
337 struct GNUNET_SCHEDULER_Task * task_id; 330 struct GNUNET_SCHEDULER_Task * task_id;
@@ -1750,23 +1743,6 @@ handle_gns_resolution_result (void *cls,
1750 } /* end: switch */ 1743 } /* end: switch */
1751 } /* end: for rd_count */ 1744 } /* end: for rd_count */
1752 1745
1753 /* trigger shortening */
1754 if ((NULL != rh->shorten_key) &&
1755 (NULL != shorten_ac) &&
1756 (GNUNET_NO == shorten_ac->shortening_started) &&
1757 (NULL != shorten_ac->suggested_shortening_label))
1758 {
1759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1760 "Start shortening for label `%s' based on nick `%s'\n",
1761 shorten_ac->label,
1762 shorten_ac->suggested_shortening_label);
1763 shorten_ac->shortening_started = GNUNET_YES;
1764 GNS_shorten_start (shorten_ac->label,
1765 shorten_ac->suggested_shortening_label,
1766 &shorten_ac->authority_info.gns_authority,
1767 rh->shorten_key);
1768 }
1769
1770 /* yes, we are done, return result */ 1746 /* yes, we are done, return result */
1771 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1747 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1772 "Returning GNS response for `%s' with %u answers\n", 1748 "Returning GNS response for `%s' with %u answers\n",
@@ -2374,7 +2350,6 @@ start_resolver_lookup (struct GNS_ResolverHandle *rh)
2374 * @param zone the zone to perform the lookup in 2350 * @param zone the zone to perform the lookup in
2375 * @param record_type the record type to look up 2351 * @param record_type the record type to look up
2376 * @param name the name to look up 2352 * @param name the name to look up
2377 * @param shorten_key a private key for use with PSEU import (can be NULL)
2378 * @param options local options to control local lookup 2353 * @param options local options to control local lookup
2379 * @param proc the processor to call on result 2354 * @param proc the processor to call on result
2380 * @param proc_cls the closure to pass to @a proc 2355 * @param proc_cls the closure to pass to @a proc
@@ -2384,16 +2359,13 @@ struct GNS_ResolverHandle *
2384GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, 2359GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
2385 uint32_t record_type, 2360 uint32_t record_type,
2386 const char *name, 2361 const char *name,
2387 const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_key,
2388 enum GNUNET_GNS_LocalOptions options, 2362 enum GNUNET_GNS_LocalOptions options,
2389 GNS_ResultProcessor proc, void *proc_cls) 2363 GNS_ResultProcessor proc, void *proc_cls)
2390{ 2364{
2391 struct GNS_ResolverHandle *rh; 2365 struct GNS_ResolverHandle *rh;
2392 2366
2393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2394 (NULL == shorten_key) 2368 "Starting lookup for `%s'\n",
2395 ? "Starting lookup for `%s' with shortening disabled\n"
2396 : "Starting lookup for `%s' with shortening enabled\n",
2397 name); 2369 name);
2398 rh = GNUNET_new (struct GNS_ResolverHandle); 2370 rh = GNUNET_new (struct GNS_ResolverHandle);
2399 GNUNET_CONTAINER_DLL_insert (rlh_head, 2371 GNUNET_CONTAINER_DLL_insert (rlh_head,
@@ -2406,11 +2378,6 @@ GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
2406 rh->record_type = record_type; 2378 rh->record_type = record_type;
2407 rh->name = GNUNET_strdup (name); 2379 rh->name = GNUNET_strdup (name);
2408 rh->name_resolution_pos = strlen (name); 2380 rh->name_resolution_pos = strlen (name);
2409 if (NULL != shorten_key)
2410 {
2411 rh->shorten_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey);
2412 *rh->shorten_key = *shorten_key;
2413 }
2414 start_resolver_lookup (rh); 2381 start_resolver_lookup (rh);
2415 return rh; 2382 return rh;
2416} 2383}
@@ -2507,7 +2474,6 @@ GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh)
2507 dr); 2474 dr);
2508 GNUNET_free (dr); 2475 GNUNET_free (dr);
2509 } 2476 }
2510 GNUNET_free_non_null (rh->shorten_key);
2511 GNUNET_free (rh->name); 2477 GNUNET_free (rh->name);
2512 GNUNET_free (rh); 2478 GNUNET_free (rh);
2513} 2479}
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h
index 863398093..c71d3983d 100644
--- a/src/gns/gnunet-service-gns_resolver.h
+++ b/src/gns/gnunet-service-gns_resolver.h
@@ -65,9 +65,10 @@ struct GNS_ResolverHandle;
65 * @param rd_count number of records in @a rd 65 * @param rd_count number of records in @a rd
66 * @param rd records returned for the lookup 66 * @param rd records returned for the lookup
67 */ 67 */
68typedef void (*GNS_ResultProcessor)(void *cls, 68typedef void
69 uint32_t rd_count, 69(*GNS_ResultProcessor)(void *cls,
70 const struct GNUNET_GNSRECORD_Data *rd); 70 uint32_t rd_count,
71 const struct GNUNET_GNSRECORD_Data *rd);
71 72
72 73
73/** 74/**
@@ -77,7 +78,6 @@ typedef void (*GNS_ResultProcessor)(void *cls,
77 * @param zone the zone to perform the lookup in 78 * @param zone the zone to perform the lookup in
78 * @param record_type the record type to look up 79 * @param record_type the record type to look up
79 * @param name the name to look up 80 * @param name the name to look up
80 * @param shorten_key optional private key for authority caching, can be NULL
81 * @param options options set to control local lookup 81 * @param options options set to control local lookup
82 * @param proc the processor to call 82 * @param proc the processor to call
83 * @param proc_cls the closure to pass to @a proc 83 * @param proc_cls the closure to pass to @a proc
@@ -87,7 +87,6 @@ struct GNS_ResolverHandle *
87GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, 87GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
88 uint32_t record_type, 88 uint32_t record_type,
89 const char *name, 89 const char *name,
90 const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_key,
91 enum GNUNET_GNS_LocalOptions options, 90 enum GNUNET_GNS_LocalOptions options,
92 GNS_ResultProcessor proc, 91 GNS_ResultProcessor proc,
93 void *proc_cls); 92 void *proc_cls);
@@ -102,8 +101,6 @@ void
102GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh); 101GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh);
103 102
104 103
105
106
107/** 104/**
108 * Generic function to check for TLDs. Checks if "name" ends in ".tld" 105 * Generic function to check for TLDs. Checks if "name" ends in ".tld"
109 * 106 *
diff --git a/src/gns/gnunet-service-gns_reverser.c b/src/gns/gnunet-service-gns_reverser.c
deleted file mode 100644
index b5b8b31b7..000000000
--- a/src/gns/gnunet-service-gns_reverser.c
+++ /dev/null
@@ -1,601 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2013 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20/**
21 * @file gns/gnunet-service-gns_reverser.c
22 * @brief GNUnet GNS service
23 * @author Martin Schanzenbach
24 */
25
26
27#include "platform.h"
28#include "gnunet_gns_service.h"
29#include "gnunet-service-gns_resolver.h"
30#include "gnunet-service-gns_reverser.h"
31
32struct ReverseRecordEntry
33{
34 /**
35 * DLL
36 */
37 struct ReverseRecordEntry *next;
38
39 /**
40 * DLL
41 */
42 struct ReverseRecordEntry *prev;
43
44 /**
45 * ReverseRecord
46 */
47 struct GNUNET_GNSRECORD_ReverseRecord *record;
48
49 /**
50 * Record length
51 */
52 size_t record_len;
53
54};
55
56struct IteratorHandle
57{
58 /**
59 * Records found
60 */
61 struct ReverseRecordEntry *records_head;
62
63 /**
64 * Records found
65 */
66 struct ReverseRecordEntry *records_tail;
67
68 /**
69 * Record count
70 */
71 uint64_t record_count;
72
73 /**
74 * Current delegation to expect
75 */
76 struct GNUNET_CRYPTO_EcdsaPublicKey target;
77
78 /**
79 * Queue entry
80 */
81 struct GNUNET_NAMESTORE_QueueEntry *ns_qe;
82
83};
84
85struct ReverseTreeNode
86{
87 /**
88 * DLL
89 */
90 struct ReverseTreeNode *next;
91
92 /**
93 * DLL
94 */
95 struct ReverseTreeNode *prev;
96
97 /**
98 * Resolved name until now
99 */
100 char *name;
101
102 /**
103 * Depth of the resolution at this node
104 */
105 uint8_t depth;
106
107 /**
108 * The pkey of the namespace
109 */
110 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
111
112};
113
114
115struct GNS_ReverserHandle
116{
117 /**
118 * GNS resolver handle
119 */
120 struct GNS_ResolverHandle *rh;
121
122 /**
123 * The authority to look for
124 */
125 struct GNUNET_CRYPTO_EcdsaPublicKey authority;
126
127 /**
128 * Resolution candidate queue
129 */
130 struct ReverseTreeNode *node_queue_head;
131
132 /**
133 * Resolution candidate queue
134 */
135 struct ReverseTreeNode *node_queue_tail;
136
137 /**
138 * Max depth for the resolution
139 */
140 uint8_t max_depth;
141
142 /**
143 * Result callback
144 */
145 GNS_ReverseResultProcessor proc;
146
147 /**
148 * Callback closure
149 */
150 void *proc_cls;
151};
152
153/**
154 * Reverse record collection task
155 */
156static struct GNUNET_SCHEDULER_Task *reverse_record_check_task;
157
158/**
159 * NS iterator task
160 */
161static struct GNUNET_SCHEDULER_Task *it_task;
162
163/**
164 * GNS lookup handle
165 */
166static struct GNS_ResolverHandle *gns_lookup_reverse;
167
168/**
169 * NS handle
170 */
171static struct GNUNET_NAMESTORE_Handle *ns;
172
173/**
174 * NS Iterator
175 */
176static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
177
178/**
179 * The zone target for reverse record resolution
180 */
181static struct GNUNET_CRYPTO_EcdsaPublicKey myzone;
182
183/**
184 * The zone target for reverse record resolution
185 */
186static struct GNUNET_CRYPTO_EcdsaPrivateKey pzone;
187
188/**
189 * The nick of our zone
190 */
191static char *mynick;
192
193
194static void
195cleanup_handle (struct GNS_ReverserHandle *rh)
196{
197 struct ReverseTreeNode *rtn;
198
199 for (rtn = rh->node_queue_head; NULL != rtn; rtn = rh->node_queue_head)
200 {
201 if (NULL != rtn->name)
202 GNUNET_free (rtn->name);
203 GNUNET_CONTAINER_DLL_remove (rh->node_queue_head,
204 rh->node_queue_tail,
205 rtn);
206 GNUNET_free (rtn);
207 }
208 GNUNET_free (rh);
209}
210
211static void
212handle_gns_result (void *cls,
213 uint32_t rd_count,
214 const struct GNUNET_GNSRECORD_Data *rd)
215{
216 struct GNS_ReverserHandle *rh = cls;
217 const struct GNUNET_GNSRECORD_ReverseRecord *rr;
218 struct ReverseTreeNode *rtn;
219 char *result;
220 const char *name;
221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
222 "Got result (%d)\n", rd_count);
223
224 for (int i = 0; i < rd_count; i++)
225 {
226 /**
227 * Check if we are in the delegation set
228 */
229 if (GNUNET_GNSRECORD_TYPE_REVERSE != rd[i].record_type)
230 continue;
231 rr = rd[i].data;
232 name = (const char*) &rr[1];
233 if (0 == memcmp (&rh->authority,
234 &rr->pkey,
235 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
236 {
237 //Found!
238 GNUNET_asprintf (&result,
239 "%s.%s.gnu",
240 rh->node_queue_head->name,
241 name);
242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
243 "Found path from %s\n", result);
244
245 rh->proc (rh->proc_cls, result);
246 cleanup_handle (rh);
247 GNUNET_free (result);
248 return;
249 } else {
250 if (rh->node_queue_head->depth >= rh->max_depth)
251 break;
252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
253 "Found REVERSE from %s\n", name);
254
255 rtn = GNUNET_new (struct ReverseTreeNode);
256 if (NULL == rh->node_queue_head->name)
257 rtn->name = GNUNET_strdup (name);
258 else
259 GNUNET_asprintf (&rtn->name,
260 "%s.%s",
261 rh->node_queue_head->name,
262 name);
263 rtn->depth = rh->node_queue_head->depth + 1;
264 rtn->pkey = rr->pkey;
265 GNUNET_CONTAINER_DLL_insert_tail (rh->node_queue_head,
266 rh->node_queue_tail,
267 rtn);
268 }
269 }
270
271 /**
272 * Done here remove node from queue
273 */
274 rtn = rh->node_queue_head;
275 if (NULL != rtn)
276 GNUNET_CONTAINER_DLL_remove (rh->node_queue_head,
277 rh->node_queue_tail,
278 rtn);
279 if (NULL == rh->node_queue_head)
280 {
281 //No luck
282 rh->proc (rh->proc_cls, NULL);
283 cleanup_handle (rh);
284 return;
285 }
286 rh->rh = GNS_resolver_lookup (&rh->node_queue_head->pkey,
287 GNUNET_GNSRECORD_TYPE_REVERSE,
288 "+.gnu",
289 NULL,
290 GNUNET_GNS_LO_DEFAULT,
291 &handle_gns_result,
292 rh);
293}
294
295/**
296 * Reverse lookup of a specific zone
297 * calls RecordLookupProcessor on result or timeout
298 *
299 * @param target the zone to perform the lookup in
300 * @param authority the authority
301 * @param proc the processor to call
302 * @param proc_cls the closure to pass to @a proc
303 * @return handle to cancel operation
304 */
305struct GNS_ReverserHandle *
306GNS_reverse_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *target,
307 const struct GNUNET_CRYPTO_EcdsaPublicKey *authority,
308 GNS_ReverseResultProcessor proc,
309 void *proc_cls)
310{
311 struct GNS_ReverserHandle *rh;
312 struct ReverseTreeNode *rtn;
313
314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
315 "Starting reverse resolution\n");
316 rh = GNUNET_new (struct GNS_ReverserHandle);
317 rh->proc = proc;
318 rh->proc_cls = proc_cls;
319 rtn = GNUNET_new (struct ReverseTreeNode);
320 rtn->name = NULL;
321 rtn->pkey = *target;
322 rtn->depth = 0;
323 GNUNET_CONTAINER_DLL_insert (rh->node_queue_head,
324 rh->node_queue_tail,
325 rtn);
326 rh->authority = *authority;
327 rh->max_depth = 3; //TODO make argument
328 rh->rh = GNS_resolver_lookup (target,
329 GNUNET_GNSRECORD_TYPE_REVERSE,
330 "+.gnu",
331 NULL,
332 GNUNET_GNS_LO_DEFAULT,
333 &handle_gns_result,
334 rh);
335 return rh;
336}
337
338/**
339 * Cancel active resolution (i.e. client disconnected).
340 *
341 * @param rh resolution to abort
342 */
343void
344GNS_reverse_lookup_cancel (struct GNS_ReverserHandle *rh)
345{
346 cleanup_handle (rh);
347 return;
348}
349
350/********************************************
351 * Reverse iterator
352 * ******************************************/
353
354
355static void
356next_it (void *cls);
357
358static void
359handle_gns_result_iter (void *cls,
360 uint32_t rd_count,
361 const struct GNUNET_GNSRECORD_Data *rd)
362{
363 struct IteratorHandle *ith = cls;
364 struct ReverseRecordEntry *rr;
365 gns_lookup_reverse = NULL;
366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
367 "GNS for REVERSE (%s)\n", mynick);
368
369
370 if ((rd_count != 1) ||
371 (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type))
372 {
373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
374 "GNS invalid REVERSE (%s)\n", mynick);
375 gns_lookup_reverse = NULL;
376 it_task = GNUNET_SCHEDULER_add_now (&next_it, ith);
377 return;
378 }
379
380
381 rr = GNUNET_new (struct ReverseRecordEntry);
382 rr->record_len = sizeof (struct GNUNET_GNSRECORD_ReverseRecord)
383 + strlen (mynick) + 1;
384 rr->record = GNUNET_malloc (rr->record_len);
385 rr->record->pkey = ith->target;
386 rr->record->expiration.abs_value_us = rd->expiration_time;
387 GNUNET_memcpy ((char*)&rr->record[1],
388 mynick,
389 strlen (mynick));
390 GNUNET_CONTAINER_DLL_insert (ith->records_head,
391 ith->records_tail,
392 rr);
393 ith->record_count++;
394 it_task = GNUNET_SCHEDULER_add_now (&next_it, ith);
395}
396
397
398static void
399next_it (void *cls)
400{
401 it_task = NULL;
402 GNUNET_assert (NULL != namestore_iter);
403 GNUNET_NAMESTORE_zone_iterator_next (namestore_iter);
404}
405
406
407static void
408iterator_cb (void *cls,
409 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
410 const char *label,
411 unsigned int rd_count,
412 const struct GNUNET_GNSRECORD_Data *rd)
413{
414 struct IteratorHandle *ith = cls;
415 struct GNUNET_CRYPTO_EcdsaPublicKey zone;
416 char *name;
417
418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
419 "iterating for REVERSE (%s / %s)\n",
420 label,
421 mynick);
422
423
424 if ((rd_count != 1) ||
425 (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type))
426 {
427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
428 "wrong format (%s)\n", mynick);
429
430
431 it_task = GNUNET_SCHEDULER_add_now (&next_it, ith);
432 return;
433 }
434 GNUNET_CRYPTO_ecdsa_key_get_public (key,
435 &zone);
436 if (0 != memcmp (&zone, &myzone,
437 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
438 {
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "wrong zone (%s)\n", mynick);
441
442
443 it_task = GNUNET_SCHEDULER_add_now (&next_it, ith);
444 return;
445 }
446 ith->target = *((struct GNUNET_CRYPTO_EcdsaPublicKey *) rd->data);
447 GNUNET_asprintf (&name,
448 "%s.gnu",
449 mynick);
450 gns_lookup_reverse = GNS_resolver_lookup (&ith->target,
451 GNUNET_GNSRECORD_TYPE_PKEY,
452 name,
453 NULL,
454 GNUNET_GNS_LO_DEFAULT,
455 &handle_gns_result_iter,
456 ith);
457 GNUNET_free (name);
458}
459
460static void check_reverse_records (void *cls);
461
462static void
463store_reverse (void *cls,
464 int32_t success,
465 const char *emsg)
466{
467 struct IteratorHandle *ith = cls;
468 struct ReverseRecordEntry *rr;
469
470 if (GNUNET_SYSERR == success)
471 {
472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
473 "%s\n",
474 emsg);
475 }
476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stored records (%s)\n", mynick);
477
478 for (rr = ith->records_head; NULL != rr; rr = ith->records_head)
479 {
480 GNUNET_CONTAINER_DLL_remove (ith->records_head,
481 ith->records_tail,
482 rr);
483 GNUNET_free (rr->record);
484 GNUNET_free (rr);
485 }
486 reverse_record_check_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_DAYS,
487 &check_reverse_records,
488 NULL);
489 GNUNET_free (ith);
490}
491
492
493static void
494finished_cb (void *cls)
495{
496 struct IteratorHandle *ith = cls;
497 struct ReverseRecordEntry *rr;
498 struct GNUNET_GNSRECORD_Data rd[ith->record_count];
499
500 memset (rd, 0, sizeof (struct GNUNET_GNSRECORD_Data) * ith->record_count);
501
502 rr = ith->records_head;
503 for (int i = 0; i < ith->record_count; i++)
504 {
505 rd[i].data_size = rr->record_len;
506 rd[i].data = GNUNET_malloc (rr->record_len);
507 rd[i].record_type = GNUNET_GNSRECORD_TYPE_REVERSE;
508 rd[i].expiration_time = rr->record->expiration.abs_value_us;
509 GNUNET_memcpy ((char*) rd[i].data,
510 rr->record,
511 rr->record_len);
512 rr = rr->next;
513 }
514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
515 "Finished iterating for REVERSE\n");
516
517 ith->ns_qe = GNUNET_NAMESTORE_records_store (ns,
518 &pzone,
519 "+",
520 ith->record_count,
521 rd,
522 &store_reverse,
523 ith);
524 namestore_iter = NULL;
525
526}
527
528
529static void
530it_error (void *cls)
531{
532 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
533 "Error iterating for REVERSE\n");
534}
535
536
537static void
538check_reverse_records (void *cls)
539{
540 struct IteratorHandle *ith;
541 ith = GNUNET_new (struct IteratorHandle);
542 ith->record_count = 0;
543 reverse_record_check_task = NULL;
544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
545 "Start iterating for REVERSE (%s)\n", mynick);
546 namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (ns,
547 NULL,
548 &it_error,
549 ith,
550 &iterator_cb,
551 ith,
552 &finished_cb,
553 ith);
554}
555
556
557/**
558 * Initialize reverser
559 *
560 * @param nh handle to a namestore
561 * @param key the private key of the gns-reverse zone
562 * @param name the name of the gns-reverse zone
563 * @return GNUNET_OK
564 */
565int
566GNS_reverse_init (struct GNUNET_NAMESTORE_Handle *nh,
567 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
568 const char *nick)
569{
570 GNUNET_asprintf (&mynick,
571 "%s",
572 nick);
573 GNUNET_CRYPTO_ecdsa_key_get_public (zone,
574 &myzone);
575 GNUNET_memcpy (&pzone,
576 zone,
577 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
578 ns = nh;
579 reverse_record_check_task = GNUNET_SCHEDULER_add_now (&check_reverse_records,
580 NULL);
581 return GNUNET_OK;
582}
583
584/**
585 * Cleanup reverser
586 */
587void
588GNS_reverse_done ()
589{
590 if (NULL != mynick)
591 GNUNET_free (mynick);
592 if (NULL != it_task)
593 GNUNET_SCHEDULER_cancel (it_task);
594 if (NULL != reverse_record_check_task)
595 GNUNET_SCHEDULER_cancel (reverse_record_check_task);
596 if (NULL != gns_lookup_reverse)
597 GNS_resolver_lookup_cancel (gns_lookup_reverse);
598 if (NULL != namestore_iter)
599 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
600}
601
diff --git a/src/gns/gnunet-service-gns_reverser.h b/src/gns/gnunet-service-gns_reverser.h
deleted file mode 100644
index fc9680a29..000000000
--- a/src/gns/gnunet-service-gns_reverser.h
+++ /dev/null
@@ -1,91 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2013 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20/**
21 * @file gns/gnunet-service-gns_reverser.h
22 * @brief GNUnet GNS service
23 * @author Martin Schanzenbach
24 */
25#ifndef GNS_REVERSER_H
26#define GNS_REVERSER_H
27#include "gns.h"
28#include "gnunet_gns_service.h"
29
30/**
31 * Handle for an active request.
32 */
33struct GNS_ReverserHandle;
34
35
36/**
37 * Function called with results for a GNS resolution.
38 *
39 * @param cls closure
40 * @param rd_count number of records in @a rd
41 * @param rd records returned for the lookup
42 */
43typedef void (*GNS_ReverseResultProcessor)(void *cls,
44 const char *name);
45
46
47/**
48 * Reverse lookup of a specific zone
49 * calls RecordLookupProcessor on result or timeout
50 *
51 * @param target the zone to perform the lookup in
52 * @param authority the authority
53 * @param proc the processor to call
54 * @param proc_cls the closure to pass to @a proc
55 * @return handle to cancel operation
56 */
57struct GNS_ReverserHandle *
58GNS_reverse_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *target,
59 const struct GNUNET_CRYPTO_EcdsaPublicKey *authority,
60 GNS_ReverseResultProcessor proc,
61 void *proc_cls);
62
63
64/**
65 * Cancel active resolution (i.e. client disconnected).
66 *
67 * @param rh resolution to abort
68 */
69void
70GNS_reverse_lookup_cancel (struct GNS_ReverserHandle *rh);
71
72/**
73 * Initialize reverser
74 *
75 * @param nh handle to a namestore
76 * @param key the private key of the gns-reverse zone
77 * @param name the name of the gns-reverse zone
78 * @return GNUNET_OK
79 */
80int
81GNS_reverse_init (struct GNUNET_NAMESTORE_Handle *nh,
82 const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
83 const char *name);
84
85/**
86 * Cleanup reverser
87 */
88void
89GNS_reverse_done ();
90
91#endif
diff --git a/src/gns/gnunet-service-gns_shorten.c b/src/gns/gnunet-service-gns_shorten.c
deleted file mode 100644
index 9aa0419aa..000000000
--- a/src/gns/gnunet-service-gns_shorten.c
+++ /dev/null
@@ -1,466 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2011-2013 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @file gns/gnunet-service-gns_shorten.c
23 * @brief GNUnet GNS shortening logic
24 * @author Martin Schanzenbach
25 * @author Christian Grothoff
26 */
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_dht_service.h"
30#include "gnunet_gnsrecord_lib.h"
31#include "gnunet_namestore_service.h"
32#include "gnunet_resolver_service.h"
33#include "gnunet_gns_service.h"
34#include "gns.h"
35#include "gnunet-service-gns_shorten.h"
36#include "gnunet_vpn_service.h"
37
38
39/**
40 * Default DHT timeout for lookups.
41 */
42#define DHT_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
43
44/**
45 * DHT replication level
46 */
47#define DHT_GNS_REPLICATION_LEVEL 5
48
49
50/**
51 * Handle for a PSEU lookup used to shorten names.
52 */
53struct GetPseuAuthorityHandle
54{
55 /**
56 * DLL
57 */
58 struct GetPseuAuthorityHandle *next;
59
60 /**
61 * DLL
62 */
63 struct GetPseuAuthorityHandle *prev;
64
65 /**
66 * Private key of the (shorten) zone to store the resulting
67 * pseudonym in.
68 */
69 struct GNUNET_CRYPTO_EcdsaPrivateKey shorten_zone_key;
70
71 /**
72 * Original label (used if no PSEU record is found).
73 */
74 char label[GNUNET_DNSPARSER_MAX_LABEL_LENGTH + 1];
75
76 /**
77 * Suggested label based on NICK record
78 */
79 char * suggested_label;
80
81 /**
82 * Label we are currently trying out
83 */
84 char *current_label;
85
86 /**
87 * The zone for which we are trying to find the PSEU record.
88 */
89 struct GNUNET_CRYPTO_EcdsaPublicKey target_zone;
90
91 /**
92 * Handle for DHT lookups. Should be NULL if no lookups are in progress
93 */
94 struct GNUNET_DHT_GetHandle *get_handle;
95
96 /**
97 * Handle to namestore request
98 */
99 struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
100
101 /**
102 * Handle to namecache request
103 */
104 struct GNUNET_NAMECACHE_QueueEntry *namecache_task;
105
106 /**
107 * Task to abort DHT lookup operation.
108 */
109 struct GNUNET_SCHEDULER_Task * timeout_task;
110
111};
112
113
114/**
115 * Head of PSEU/shorten operations list.
116 */
117static struct GetPseuAuthorityHandle *gph_head;
118
119/**
120 * Tail of PSEU/shorten operations list.
121 */
122static struct GetPseuAuthorityHandle *gph_tail;
123
124/**
125 * Our handle to the namestore service
126 */
127static struct GNUNET_NAMESTORE_Handle *namestore_handle;
128
129/**
130 * Our handle to the namecache service
131 */
132static struct GNUNET_NAMECACHE_Handle *namecache_handle;
133
134/**
135 * Resolver handle to the dht
136 */
137static struct GNUNET_DHT_Handle *dht_handle;
138
139/**
140 * Cleanup a 'struct GetPseuAuthorityHandle', terminating all
141 * pending activities.
142 *
143 * @param gph handle to terminate
144 */
145static void
146free_get_pseu_authority_handle (struct GetPseuAuthorityHandle *gph)
147{
148 if (NULL != gph->get_handle)
149 {
150 GNUNET_DHT_get_stop (gph->get_handle);
151 gph->get_handle = NULL;
152 }
153 if (NULL != gph->namestore_task)
154 {
155 GNUNET_NAMESTORE_cancel (gph->namestore_task);
156 gph->namestore_task = NULL;
157 }
158 if (NULL != gph->namecache_task)
159 {
160 GNUNET_NAMECACHE_cancel (gph->namecache_task);
161 gph->namecache_task = NULL;
162 }
163 if (NULL != gph->timeout_task)
164 {
165 GNUNET_SCHEDULER_cancel (gph->timeout_task);
166 gph->timeout_task = NULL;
167 }
168 GNUNET_CONTAINER_DLL_remove (gph_head, gph_tail, gph);
169 GNUNET_free_non_null (gph->current_label);
170 GNUNET_free (gph);
171}
172
173
174/**
175 * Continuation for pkey record creation (shorten)
176 *
177 * @param cls a GetPseuAuthorityHandle
178 * @param success unused
179 * @param emsg unused
180 */
181static void
182create_pkey_cont (void* cls,
183 int32_t success,
184 const char *emsg)
185{
186 struct GetPseuAuthorityHandle* gph = cls;
187
188 gph->namestore_task = NULL;
189 free_get_pseu_authority_handle (gph);
190}
191
192
193/**
194 * Namestore calls this function if we have record for this name.
195 * (or with rd_count=0 to indicate no matches).
196 *
197 * @param cls the pending query
198 * @param rd_count the number of records with 'name'
199 * @param rd the record data
200 */
201static void
202process_pseu_lookup_ns (void *cls,
203 unsigned int rd_count,
204 const struct GNUNET_GNSRECORD_Data *rd);
205
206
207/**
208 * We obtained a result for our query to the shorten zone from
209 * the namestore. Try to decrypt.
210 *
211 * @param cls the handle to our shorten operation
212 * @param block resulting encrypted block
213 */
214static void
215process_pseu_block_ns (void *cls,
216 const struct GNUNET_GNSRECORD_Block *block)
217{
218 struct GetPseuAuthorityHandle *gph = cls;
219 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
220
221 gph->namecache_task = NULL;
222 if (NULL == block)
223 {
224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
225 "Namecache did not return information for label `%s' \n",
226 gph->current_label);
227 process_pseu_lookup_ns (gph, 0, NULL);
228 return;
229 }
230 GNUNET_CRYPTO_ecdsa_key_get_public (&gph->shorten_zone_key,
231 &pub);
232 if (GNUNET_OK !=
233 GNUNET_GNSRECORD_block_decrypt (block,
234 &pub,
235 gph->current_label,
236 &process_pseu_lookup_ns,
237 gph))
238 {
239 GNUNET_break (0);
240 free_get_pseu_authority_handle (gph);
241 return;
242 }
243}
244
245
246/**
247 * Lookup in the namecache for the shorten zone the given label.
248 *
249 * @param gph the handle to our shorten operation
250 * @param label the label to lookup
251 */
252static void
253perform_nick_lookup (struct GetPseuAuthorityHandle *gph,
254 const char *label)
255{
256 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
257 struct GNUNET_HashCode query;
258
259 GNUNET_CRYPTO_ecdsa_key_get_public (&gph->shorten_zone_key,
260 &pub);
261 GNUNET_free_non_null (gph->current_label);
262 gph->current_label = GNUNET_strdup (label);
263 GNUNET_GNSRECORD_query_from_public_key (&pub,
264 label,
265 &query);
266 gph->namecache_task = GNUNET_NAMECACHE_lookup_block (namecache_handle,
267 &query,
268 &process_pseu_block_ns,
269 gph);
270}
271
272
273/**
274 * Namestore calls this function if we have record for this name.
275 * (or with rd_count=0 to indicate no matches).
276 *
277 * @param cls the pending query
278 * @param rd_count the number of records with 'name'
279 * @param rd the record data
280 */
281static void
282process_pseu_lookup_ns (void *cls,
283 unsigned int rd_count,
284 const struct GNUNET_GNSRECORD_Data *rd)
285{
286 struct GetPseuAuthorityHandle *gph = cls;
287 struct GNUNET_GNSRECORD_Data new_pkey;
288
289 gph->namestore_task = NULL;
290 if (rd_count > 0)
291 {
292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
293 "Name `%s' already taken, cannot shorten.\n",
294 gph->current_label);
295 /* if this was not yet the original label, try one more
296 time, this time not using PSEU but the original label */
297 if (0 == strcmp (gph->current_label,
298 gph->label))
299 {
300 free_get_pseu_authority_handle (gph);
301 }
302 else
303 {
304 perform_nick_lookup (gph, gph->label);
305 }
306 return;
307 }
308 /* name is available */
309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
310 "Shortening `%s' to `%s'\n",
311 GNUNET_GNSRECORD_z2s (&gph->target_zone),
312 gph->current_label);
313 new_pkey.expiration_time = UINT64_MAX;
314 new_pkey.data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
315 new_pkey.data = &gph->target_zone;
316 new_pkey.record_type = GNUNET_GNSRECORD_TYPE_PKEY;
317 new_pkey.flags = GNUNET_GNSRECORD_RF_NONE
318 | GNUNET_GNSRECORD_RF_PRIVATE;
319 gph->namestore_task
320 = GNUNET_NAMESTORE_records_store (namestore_handle,
321 &gph->shorten_zone_key,
322 gph->current_label,
323 1, &new_pkey,
324 &create_pkey_cont, gph);
325}
326
327
328/**
329 * Encountered an error in zone-to-name lookup, give up on shortening.
330 */
331static void
332zone_to_name_error_cb (void *cls)
333{
334 struct GetPseuAuthorityHandle* gph = cls;
335
336 gph->namestore_task = NULL;
337 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
338 "Shortening aborted, internal error talking to namestore\n");
339 free_get_pseu_authority_handle (gph);
340}
341
342
343/**
344 * Callback called by namestore for a zone to name result. We're
345 * trying to see if a short name for a given zone already exists.
346 *
347 * @param cls the closure
348 * @param zone_key the zone we queried
349 * @param name the name found or NULL
350 * @param rd_len number of records for the name
351 * @param rd the record data (PKEY) for the name
352 */
353static void
354process_zone_to_name_discover (void *cls,
355 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
356 const char *name,
357 unsigned int rd_len,
358 const struct GNUNET_GNSRECORD_Data *rd)
359{
360 struct GetPseuAuthorityHandle* gph = cls;
361
362 gph->namestore_task = NULL;
363 if (0 != rd_len)
364 {
365 /* we found a match in our own zone */
366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
367 "Shortening aborted, name `%s' already reserved for the zone\n",
368 name);
369 free_get_pseu_authority_handle (gph);
370 return;
371 }
372 else
373 {
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
375 "Shortening continuing, no name not reserved in shorten zone\n");
376 }
377 /* record does not yet exist, check if suggested label is available */
378 perform_nick_lookup (gph, gph->suggested_label);
379}
380
381
382/**
383 * Start shortening algorithm, try to allocate a nice short
384 * canonical name for @a pub in @a shorten_zone, using
385 * @a original_label as one possible suggestion.
386 *
387 * @param original_label original label for the zone
388 * @param suggested_label suggested label for the zone
389 * @param pub public key of the zone to shorten
390 * @param shorten_zone private key of the target zone for the new record
391 */
392void
393GNS_shorten_start (const char *original_label,
394 const char *suggested_label,
395 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub,
396 const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone)
397{
398 struct GetPseuAuthorityHandle *gph;
399 struct GNUNET_CRYPTO_EcdsaPublicKey shorten_pub;
400
401 if (strlen (original_label) > GNUNET_DNSPARSER_MAX_LABEL_LENGTH)
402 {
403 GNUNET_break (0);
404 return;
405 }
406 GNUNET_CRYPTO_ecdsa_key_get_public (shorten_zone, &shorten_pub);
407 if (0 == memcmp (&shorten_pub, pub, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
408 {
409 /* Do not shorten the shorten zone */
410 return;
411 }
412
413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
414 "Starting shortening process for `%s' with old label `%s' and suggested nickname `%s'\n",
415 GNUNET_GNSRECORD_z2s (pub),
416 original_label, suggested_label);
417 gph = GNUNET_new (struct GetPseuAuthorityHandle);
418 gph->shorten_zone_key = *shorten_zone;
419 gph->target_zone = *pub;
420 gph->suggested_label = GNUNET_strdup (suggested_label);
421 strcpy (gph->label, original_label);
422 GNUNET_CONTAINER_DLL_insert (gph_head, gph_tail, gph);
423 /* first, check if we *already* have a record for this zone */
424 gph->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
425 shorten_zone,
426 pub,
427 &zone_to_name_error_cb,
428 gph,
429 &process_zone_to_name_discover,
430 gph);
431}
432
433
434/**
435 * Initialize the shortening subsystem
436 *
437 * @param nh the namestore handle
438 * @param nc the namecache handle
439 * @param dht the dht handle
440 */
441void
442GNS_shorten_init (struct GNUNET_NAMESTORE_Handle *nh,
443 struct GNUNET_NAMECACHE_Handle *nc,
444 struct GNUNET_DHT_Handle *dht)
445{
446 namestore_handle = nh;
447 namecache_handle = nc;
448 dht_handle = dht;
449}
450
451
452/**
453 * Shutdown shortening.
454 */
455void
456GNS_shorten_done ()
457{
458 /* abort active shorten operations */
459 while (NULL != gph_head)
460 free_get_pseu_authority_handle (gph_head);
461 dht_handle = NULL;
462 namestore_handle = NULL;
463 namecache_handle = NULL;
464}
465
466/* end of gnunet-service-gns_shorten.c */
diff --git a/src/gns/gnunet-service-gns_shorten.h b/src/gns/gnunet-service-gns_shorten.h
deleted file mode 100644
index d82bb52f7..000000000
--- a/src/gns/gnunet-service-gns_shorten.h
+++ /dev/null
@@ -1,70 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2013 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20/**
21 * @file gns/gnunet-service-gns_shorten.h
22 * @brief GNUnet GNS shortening API
23 * @author Martin Schanzenbach
24 */
25#ifndef GNS_SHORTEN_H
26#define GNS_SHORTEN_H
27#include "gns.h"
28#include "gnunet_dht_service.h"
29#include "gnunet_namecache_service.h"
30#include "gnunet_namestore_service.h"
31
32
33/**
34 * Initialize the shorten subsystem.
35 * MUST be called before #GNS_shorten_start.
36 *
37 * @param nh handle to the namestore
38 * @param nc the namecache handle
39 * @param dht handle to the dht
40 */
41void
42GNS_shorten_init (struct GNUNET_NAMESTORE_Handle *nh,
43 struct GNUNET_NAMECACHE_Handle *nc,
44 struct GNUNET_DHT_Handle *dht);
45
46
47/**
48 * Cleanup shorten: Terminate pending lookups
49 */
50void
51GNS_shorten_done (void);
52
53
54/**
55 * Start shortening algorithm, try to allocate a nice short
56 * canonical name for @a pub in @a shorten_zone, using
57 * @a original_label as one possible suggestion.
58 *
59 * @param original_label original label for the zone
60 * @param pub public key of the zone to shorten
61 * @param shorten_zone private key of the target zone for the new record
62 */
63void
64GNS_shorten_start (const char *original_label,
65 const char *suggested_label,
66 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub,
67 const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone);
68
69
70#endif
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c
index f0e34a04b..a42fef953 100644
--- a/src/gns/plugin_block_gns.c
+++ b/src/gns/plugin_block_gns.c
@@ -22,9 +22,11 @@
22 * @file gns/plugin_block_gns.c 22 * @file gns/plugin_block_gns.c
23 * @brief blocks used for GNS records 23 * @brief blocks used for GNS records
24 * @author Martin Schanzenbach 24 * @author Martin Schanzenbach
25 * @author Christian Grothoff
25 */ 26 */
26 27
27#include "platform.h" 28#include "platform.h"
29#include "gnunet_block_group_lib.h"
28#include "gnunet_block_plugin.h" 30#include "gnunet_block_plugin.h"
29#include "gnunet_namestore_service.h" 31#include "gnunet_namestore_service.h"
30#include "gnunet_signatures.h" 32#include "gnunet_signatures.h"
@@ -36,6 +38,59 @@
36#define BLOOMFILTER_K 16 38#define BLOOMFILTER_K 16
37 39
38/** 40/**
41 * How big is the BF we use for GNS blocks?
42 */
43#define GNS_BF_SIZE 8
44
45
46/**
47 * Create a new block group.
48 *
49 * @param ctx block context in which the block group is created
50 * @param type type of the block for which we are creating the group
51 * @param nonce random value used to seed the group creation
52 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh
53 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
54 * @param va variable arguments specific to @a type
55 * @return block group handle, NULL if block groups are not supported
56 * by this @a type of block (this is not an error)
57 */
58static struct GNUNET_BLOCK_Group *
59block_plugin_gns_create_group (void *cls,
60 enum GNUNET_BLOCK_Type type,
61 uint32_t nonce,
62 const void *raw_data,
63 size_t raw_data_size,
64 va_list va)
65{
66 unsigned int bf_size;
67 const char *guard;
68
69 guard = va_arg (va, const char *);
70 if (0 == strcmp (guard,
71 "seen-set-size"))
72 bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int),
73 BLOOMFILTER_K);
74 else if (0 == strcmp (guard,
75 "filter-size"))
76 bf_size = va_arg (va, unsigned int);
77 else
78 {
79 GNUNET_break (0);
80 bf_size = GNS_BF_SIZE;
81 }
82 GNUNET_break (NULL == va_arg (va, const char *));
83 return GNUNET_BLOCK_GROUP_bf_create (cls,
84 bf_size,
85 BLOOMFILTER_K,
86 type,
87 nonce,
88 raw_data,
89 raw_data_size);
90}
91
92
93/**
39 * Function called to validate a reply or a request. For 94 * Function called to validate a reply or a request. For
40 * request evaluation, simply pass "NULL" for the reply_block. 95 * request evaluation, simply pass "NULL" for the reply_block.
41 * Note that it is assumed that the reply has already been 96 * Note that it is assumed that the reply has already been
@@ -43,11 +98,11 @@
43 * be done with the "get_key" function. 98 * be done with the "get_key" function.
44 * 99 *
45 * @param cls closure 100 * @param cls closure
101 * @param ctx block context
46 * @param type block type 102 * @param type block type
103 * @param bg block group to use for evaluation
47 * @param eo control flags 104 * @param eo control flags
48 * @param query original query (hash) 105 * @param query original query (hash)
49 * @param bf pointer to bloom filter associated with @a query; possibly updated (!)
50 * @param bf_mutator mutation value for @a bf
51 * @param xquery extrended query data (can be NULL, depending on @a type) 106 * @param xquery extrended query data (can be NULL, depending on @a type)
52 * @param xquery_size number of bytes in @a xquery 107 * @param xquery_size number of bytes in @a xquery
53 * @param reply_block response to validate 108 * @param reply_block response to validate
@@ -56,11 +111,11 @@
56 */ 111 */
57static enum GNUNET_BLOCK_EvaluationResult 112static enum GNUNET_BLOCK_EvaluationResult
58block_plugin_gns_evaluate (void *cls, 113block_plugin_gns_evaluate (void *cls,
114 struct GNUNET_BLOCK_Context *ctx,
59 enum GNUNET_BLOCK_Type type, 115 enum GNUNET_BLOCK_Type type,
116 struct GNUNET_BLOCK_Group *bg,
60 enum GNUNET_BLOCK_EvaluationOptions eo, 117 enum GNUNET_BLOCK_EvaluationOptions eo,
61 const struct GNUNET_HashCode *query, 118 const struct GNUNET_HashCode *query,
62 struct GNUNET_CONTAINER_BloomFilter **bf,
63 int32_t bf_mutator,
64 const void *xquery, 119 const void *xquery,
65 size_t xquery_size, 120 size_t xquery_size,
66 const void *reply_block, 121 const void *reply_block,
@@ -69,7 +124,6 @@ block_plugin_gns_evaluate (void *cls,
69 const struct GNUNET_GNSRECORD_Block *block; 124 const struct GNUNET_GNSRECORD_Block *block;
70 struct GNUNET_HashCode h; 125 struct GNUNET_HashCode h;
71 struct GNUNET_HashCode chash; 126 struct GNUNET_HashCode chash;
72 struct GNUNET_HashCode mhash;
73 127
74 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) 128 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD)
75 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 129 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
@@ -110,21 +164,13 @@ block_plugin_gns_evaluate (void *cls,
110 GNUNET_break_op (0); 164 GNUNET_break_op (0);
111 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 165 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
112 } 166 }
113 if (NULL != bf) 167 GNUNET_CRYPTO_hash (reply_block,
114 { 168 reply_block_size,
115 GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash); 169 &chash);
116 GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash); 170 if (GNUNET_YES ==
117 if (NULL != *bf) 171 GNUNET_BLOCK_GROUP_bf_test_and_set (bg,
118 { 172 &chash))
119 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test(*bf, &mhash)) 173 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
120 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
121 }
122 else
123 {
124 *bf = GNUNET_CONTAINER_bloomfilter_init(NULL, 8, BLOOMFILTER_K);
125 }
126 GNUNET_CONTAINER_bloomfilter_add(*bf, &mhash);
127 }
128 return GNUNET_BLOCK_EVALUATION_OK_MORE; 174 return GNUNET_BLOCK_EVALUATION_OK_MORE;
129} 175}
130 176
@@ -141,9 +187,11 @@ block_plugin_gns_evaluate (void *cls,
141 * (or if extracting a key from a block of this type does not work) 187 * (or if extracting a key from a block of this type does not work)
142 */ 188 */
143static int 189static int
144block_plugin_gns_get_key (void *cls, enum GNUNET_BLOCK_Type type, 190block_plugin_gns_get_key (void *cls,
145 const void *reply_block, size_t reply_block_size, 191 enum GNUNET_BLOCK_Type type,
146 struct GNUNET_HashCode *key) 192 const void *reply_block,
193 size_t reply_block_size,
194 struct GNUNET_HashCode *key)
147{ 195{
148 const struct GNUNET_GNSRECORD_Block *block; 196 const struct GNUNET_GNSRECORD_Block *block;
149 197
@@ -178,6 +226,7 @@ libgnunet_plugin_block_gns_init (void *cls)
178 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 226 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
179 api->evaluate = &block_plugin_gns_evaluate; 227 api->evaluate = &block_plugin_gns_evaluate;
180 api->get_key = &block_plugin_gns_get_key; 228 api->get_key = &block_plugin_gns_get_key;
229 api->create_group = &block_plugin_gns_create_group;
181 api->types = types; 230 api->types = types;
182 return api; 231 return api;
183} 232}
@@ -189,7 +238,7 @@ libgnunet_plugin_block_gns_init (void *cls)
189void * 238void *
190libgnunet_plugin_block_gns_done (void *cls) 239libgnunet_plugin_block_gns_done (void *cls)
191{ 240{
192 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 241 struct GNUNET_BLOCK_PluginFunctions *api = cls;
193 242
194 GNUNET_free (api); 243 GNUNET_free (api);
195 return NULL; 244 return NULL;
diff --git a/src/gns/plugin_gnsrecord_gns.c b/src/gns/plugin_gnsrecord_gns.c
index 5faca4578..5d611e19e 100644
--- a/src/gns/plugin_gnsrecord_gns.c
+++ b/src/gns/plugin_gnsrecord_gns.c
@@ -279,9 +279,10 @@ gns_string_to_value (void *cls,
279 } 279 }
280 *data_size = sizeof (struct GNUNET_TUN_GnsVpnRecord) + strlen (s_serv) + 1; 280 *data_size = sizeof (struct GNUNET_TUN_GnsVpnRecord) + strlen (s_serv) + 1;
281 *data = vpn = GNUNET_malloc (*data_size); 281 *data = vpn = GNUNET_malloc (*data_size);
282 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string ((char*) s_peer, 282 if (GNUNET_OK !=
283 strlen (s_peer), 283 GNUNET_CRYPTO_eddsa_public_key_from_string ((char*) s_peer,
284 &vpn->peer.public_key)) 284 strlen (s_peer),
285 &vpn->peer.public_key))
285 { 286 {
286 GNUNET_free (vpn); 287 GNUNET_free (vpn);
287 *data_size = 0; 288 *data_size = 0;
@@ -362,9 +363,14 @@ gns_string_to_value (void *cls,
362 } 363 }
363 *data_size = sizeof (struct GNUNET_GNSRECORD_ReverseRecord) + strlen (known_by) + 1; 364 *data_size = sizeof (struct GNUNET_GNSRECORD_ReverseRecord) + strlen (known_by) + 1;
364 *data = rev = GNUNET_malloc (*data_size); 365 *data = rev = GNUNET_malloc (*data_size);
365 GNUNET_CRYPTO_ecdsa_public_key_from_string (pkey_str, 366 if (GNUNET_OK !=
366 strlen (pkey_str), 367 GNUNET_CRYPTO_ecdsa_public_key_from_string (pkey_str,
367 &rev->pkey); 368 strlen (pkey_str),
369 &rev->pkey))
370 {
371 GNUNET_free (rev);
372 return GNUNET_SYSERR;
373 }
368 rev->expiration = expiration; 374 rev->expiration = expiration;
369 GNUNET_memcpy (&rev[1], 375 GNUNET_memcpy (&rev[1],
370 known_by, 376 known_by,
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c
index 3cddbc246..b7775e4ea 100644
--- a/src/gns/plugin_rest_gns.c
+++ b/src/gns/plugin_rest_gns.c
@@ -336,10 +336,9 @@ process_lookup_result (void *cls, uint32_t rd_count,
336 * identified by the given public key and the shorten zone. 336 * identified by the given public key and the shorten zone.
337 * 337 *
338 * @param pkey public key to use for the zone, can be NULL 338 * @param pkey public key to use for the zone, can be NULL
339 * @param shorten_key private key used for shortening, can be NULL
340 */ 339 */
341static void 340static void
342lookup_with_keys (struct LookupHandle *handle, const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_key) 341lookup_with_public_key (struct LookupHandle *handle)
343{ 342{
344 if (UINT32_MAX == handle->type) 343 if (UINT32_MAX == handle->type)
345 { 344 {
@@ -354,7 +353,6 @@ lookup_with_keys (struct LookupHandle *handle, const struct GNUNET_CRYPTO_EcdsaP
354 &handle->pkey, 353 &handle->pkey,
355 handle->type, 354 handle->type,
356 handle->options, 355 handle->options,
357 shorten_key,
358 &process_lookup_result, 356 &process_lookup_result,
359 handle); 357 handle);
360 } 358 }
@@ -365,55 +363,6 @@ lookup_with_keys (struct LookupHandle *handle, const struct GNUNET_CRYPTO_EcdsaP
365 } 363 }
366} 364}
367 365
368/**
369 * Method called to with the ego we are to use for shortening
370 * during the lookup.
371 *
372 * @param cls closure contains the public key to use
373 * @param ego ego handle, NULL if not found
374 * @param ctx context for application to store data for this ego
375 * (during the lifetime of this process, initially NULL)
376 * @param name name assigned by the user for this ego,
377 * NULL if the user just deleted the ego and it
378 * must thus no longer be used
379 */
380static void
381identity_shorten_cb (void *cls,
382 struct GNUNET_IDENTITY_Ego *ego,
383 void **ctx,
384 const char *name)
385{
386 struct LookupHandle *handle = cls;
387
388 handle->id_op = NULL;
389 if (NULL == ego)
390 lookup_with_keys (handle, NULL);
391 else
392 lookup_with_keys (handle,
393 GNUNET_IDENTITY_ego_get_private_key (ego));
394}
395
396/**
397 * Perform the actual resolution, starting with the zone
398 * identified by the given public key.
399 *
400 * @param pkey public key to use for the zone
401 */
402static void
403lookup_with_public_key (struct LookupHandle *handle)
404{
405 handle->pkeym = handle->pkey;
406 GNUNET_break (NULL == handle->id_op);
407 handle->id_op = GNUNET_IDENTITY_get (handle->identity,
408 "gns-short",
409 &identity_shorten_cb,
410 handle);
411 if (NULL == handle->id_op)
412 {
413 GNUNET_break (0);
414 lookup_with_keys (handle, NULL);
415 }
416}
417 366
418/** 367/**
419 * Method called to with the ego we are to use for the lookup, 368 * Method called to with the ego we are to use for the lookup,
@@ -444,6 +393,7 @@ identity_zone_cb (void *cls,
444 json_decref(handle->json_root); 393 json_decref(handle->json_root);
445} 394}
446 395
396
447/** 397/**
448 * Method called to with the ego we are to use for the lookup, 398 * Method called to with the ego we are to use for the lookup,
449 * when the ego is the one for the default master zone. 399 * when the ego is the one for the default master zone.
@@ -579,6 +529,7 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
579 { 529 {
580 handle->pkey_str = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, 530 handle->pkey_str = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
581 &key); 531 &key);
532 GNUNET_assert (NULL != handle->pkey_str);
582 if (GNUNET_OK != 533 if (GNUNET_OK !=
583 GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->pkey_str, 534 GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->pkey_str,
584 strlen(handle->pkey_str), 535 strlen(handle->pkey_str),
diff --git a/src/gns/test_gns_nick_shorten.sh b/src/gns/test_gns_nick_shorten.sh
deleted file mode 100755
index df69bbba9..000000000
--- a/src/gns/test_gns_nick_shorten.sh
+++ /dev/null
@@ -1,124 +0,0 @@
1#!/bin/bash
2trap "gnunet-arm -e -c test_gns_nick_shorten.conf" SIGINT
3which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
4
5# This test tests shortening functionality based on NICK records:
6#
7# zone "delegatedego": Alice's zone
8# zone "testego": Local zone with delegation to alice
9
10LOCATION=$(which gnunet-config)
11if [ -z $LOCATION ]
12then
13 LOCATION="gnunet-config"
14fi
15$LOCATION --version 1> /dev/null
16if test $? != 0
17then
18 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
19 exit 77
20fi
21
22# Deleting home directory from previous runs
23TEST_CONFIG="test_gns_nick_shorten.conf "
24rm -rf /tmp/test-gnunet-gns-peer-1/
25TEST_IP="127.0.0.1"
26TEST_IP="127.0.0.2"
27TEST_NICK_EGO="ego"
28TEST_NICK_DELEGATED="alice"
29TEST_NAME="www.mybestfriendalice.gnu"
30TEST_NAME_SHORT="www.alice.short.gnu"
31
32# export GNUNET_FORCE_LOG="namestore;;;;DEBUG/gns;;;;DEBUG/;;;;WARNING"
33
34# Start gnunet
35echo "Starting arm with configuration $TEST_CONFIG"
36gnunet-arm -s -c $TEST_CONFIG
37
38# Create initial identities: short-zone, delegated-zone, testego
39echo "Creating identities"
40gnunet-identity -d -c $TEST_CONFIG
41gnunet-identity -C short-zone -c $TEST_CONFIG
42gnunet-identity -C delegatedego -c $TEST_CONFIG
43gnunet-identity -e short-zone -s gns-short -c $TEST_CONFIG
44gnunet-identity -C testego -c $TEST_CONFIG
45
46echo "Adding nick names for identities"
47gnunet-namestore -z testego -i $TEST_NICK_EGO -c $TEST_CONFIG
48gnunet-namestore -z delegatedego -i $TEST_NICK_DELEGATED -c $TEST_CONFIG
49
50# Adding label www in Alice's delegatedego zone
51echo "Adding www record with IP $TEST_IP"
52gnunet-namestore -p -z delegatedego -a -n www -t A -V $TEST_IP -e never -c test_gns_nick_shorten.conf
53
54# Retrieve PKEYs for delegation
55DELEGATED_PKEY=$(gnunet-identity -d -c $TEST_CONFIG| grep delegatedego | awk '{print $3}')
56echo "Alice's PKEY is $DELEGATED_PKEY"
57
58SHORTEN_PKEY=$(gnunet-identity -c test_gns_nick_shorten.conf -d | grep short-zone | awk '{print $3}')
59echo "Shorten PKEY is $SHORTEN_PKEY"
60
61# Delegate the name "short" to shortenzone
62gnunet-namestore -p -z testego -a -n short -t PKEY -V $SHORTEN_PKEY -e never -c test_gns_nick_shorten.conf
63
64# Delegate the name "mybestfriendalice" to alice
65gnunet-namestore -p -z testego -a -n mybestfriendalice -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_nick_shorten.conf
66
67# Perform lookup to shorten
68echo "Start gns..."
69gnunet-arm -c test_gns_nick_shorten.conf -i gns
70
71
72RES_IP=`$DO_TIMEOUT gnunet-gns --raw -z testego -u $TEST_NAME -t A -c test_gns_nick_shorten.conf`
73
74sleep 1
75
76echo "Lookup shortened names"
77PKEY_SHORT_RES=$($DO_TIMEOUT gnunet-gns --raw -c test_gns_nick_shorten.conf -z short-zone -u alice.gnu -t PKEY)
78echo "Resolving alice's PKEY in shorten zone: $PKEY_SHORT_RES"
79PKEY_RES=$($DO_TIMEOUT gnunet-gns --raw -c test_gns_nick_shorten.conf -z testego -u alice.short.gnu -t PKEY)
80echo "Resolving alice's PKEY in master zone: $PKEY_RES"
81
82RES=0
83if [ "$DELEGATED_PKEY" == "$PKEY_SHORT_RES" ]
84then
85 echo "PASS: Resolved delegation for shorten name in shortened zone"
86else
87 echo "FAIL: Expected PKEY in $DELEGATED_PKEY, received PKEY '$PKEY_SHORT_RES' in shorten zone."
88 RES=1
89fi
90
91if [ "$DELEGATED_PKEY" == "$PKEY_RES" ]
92then
93 echo "PASS: Resolved delegation for shorten name in master zone"
94else
95 echo "FAIL: Expected PKEY in $DELEGATED_PKEY, received PKEY $PKEY_SHORT_RES in master zone."
96 RES=1
97fi
98
99if [ $RES -eq 0 ]
100then
101 RES_IP=`$DO_TIMEOUT gnunet-gns --raw -z testego -u $TEST_NAME_SHORT -t A -c test_gns_nick_shorten.conf`
102 if [ "$RES_IP" == "$TEST_IP" ]
103 then
104 echo "PASS: Received $TEST_IP for $TEST_NAME_SHORT"
105 else
106 echo "FAIL: Expected IP in $TEST_IP, received IP '$RES_IP' for $TEST_SHORT_NAME."
107 RES=1
108 fi
109fi
110
111
112# Clean up
113echo "Clean up..."
114gnunet-namestore -z testego -d -n mybestfriendalice -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_nick_shorten.conf
115gnunet-namestore -z delegatedego -d -n www -t A -V $TEST_IP -e never -c test_gns_nick_shorten.conf
116gnunet-identity -D -z testego -c $TEST_CONFIG
117gnunet-identity -D -z delegatedego -c $TEST_CONFIG
118gnunet-identity -D -z short-zone -c $TEST_CONFIG
119
120gnunet-arm -e -c test_gns_nick_shorten.conf
121rm -rf /tmp/test-gnunet-gns-peer-1/
122
123exit $RES
124
diff --git a/src/gns/test_gns_reverse_lookup.sh b/src/gns/test_gns_reverse_lookup.sh
deleted file mode 100755
index 189adef11..000000000
--- a/src/gns/test_gns_reverse_lookup.sh
+++ /dev/null
@@ -1,50 +0,0 @@
1#!/bin/bash
2trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
3which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
4
5LOCATION=$(which gnunet-config)
6if [ -z $LOCATION ]
7then
8 LOCATION="gnunet-config"
9fi
10$LOCATION --version 1> /dev/null
11if test $? != 0
12then
13 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
14 exit 77
15fi
16
17TEST_NAME="dave.bob.alice.gnu"
18gnunet-arm -s -c test_gns_lookup.conf
19gnunet-identity -C bob -c test_gns_lookup.conf
20BOB_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep bob | awk '{print $3}')
21gnunet-identity -C daveego -c test_gns_lookup.conf
22DAVE_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep dave | awk '{print $3}')
23gnunet-identity -C aliceego -c test_gns_lookup.conf
24ALICE_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep alice | awk '{print $3}')
25gnunet-identity -C testego -c test_gns_lookup.conf
26ROOT_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep testego | awk '{print $3}')
27
28gnunet-identity -s gns-reverse -e bob -c test_gns_lookup.conf
29
30gnunet-namestore -p -z testego -a -n alice -t PKEY -V $ALICE_PKEY -e never -c test_gns_lookup.conf
31gnunet-namestore -p -z aliceego -a -n bob -t PKEY -V $BOB_PKEY -e never -c test_gns_lookup.conf
32gnunet-namestore -p -z aliceego -a -n + -t REVERSE -V "alice $ROOT_PKEY 0" -e never -c test_gns_lookup.conf
33gnunet-namestore -p -z bob -a -n dave -t PKEY -V $DAVE_PKEY -e never -c test_gns_lookup.conf
34gnunet-namestore -p -z bob -a -n alice -t PKEY -V $ALICE_PKEY -e never -c test_gns_lookup.conf
35#gnunet-namestore -p -z bob -a -n + -t REVERSE -V "bob $ALICE_PKEY 0" -e never -c test_gns_lookup.conf
36gnunet-namestore -p -z daveego -a -n + -t REVERSE -V "dave $BOB_PKEY 0" -e never -c test_gns_lookup.conf
37gnunet-namestore -p -z daveego -a -n bob -t PKEY -V $BOB_PKEY -e never -c test_gns_lookup.conf
38gnunet-arm -i gns -c test_gns_lookup.conf
39sleep 10
40RES_NAME=`$DO_TIMEOUT gnunet-gns --raw -z testego -R $DAVE_PKEY -c test_gns_lookup.conf`
41gnunet-arm -e -c test_gns_lookup.conf
42rm -rf /tmp/test-gnunet-gns-peer-1/
43
44if [ "$RES_NAME" == "$TEST_NAME" ]
45then
46 exit 0
47else
48 echo "Failed to resolve to proper IP, got $RES_IP."
49 exit 1
50fi
diff --git a/src/gns/w32nsp-resolve.c b/src/gns/w32nsp-resolve.c
index 1de1a3657..82f15c6cc 100644
--- a/src/gns/w32nsp-resolve.c
+++ b/src/gns/w32nsp-resolve.c
@@ -22,6 +22,9 @@
22 * @brief W32 integration for GNS 22 * @brief W32 integration for GNS
23 * @author LRN 23 * @author LRN
24 */ 24 */
25/* Instead of including gnunet_common.h */
26#define GNUNET_memcpy(dst,src,n) do { if (0 != n) { (void) memcpy (dst,src,n); } } while (0)
27
25#include <ws2tcpip.h> 28#include <ws2tcpip.h>
26#include <windows.h> 29#include <windows.h>
27#include <nspapi.h> 30#include <nspapi.h>