aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/.gitignore1
-rw-r--r--src/gns/Makefile.am39
-rw-r--r--src/gns/gns-helper-service-w32.conf2
-rw-r--r--src/gns/gns.conf.in16
-rw-r--r--src/gns/gns.h18
-rw-r--r--src/gns/gns_api.c31
-rw-r--r--src/gns/gns_api.h18
-rw-r--r--src/gns/gns_tld_api.c24
-rw-r--r--src/gns/gnunet-bcd.c43
-rw-r--r--src/gns/gnunet-dns2gns.c19
-rw-r--r--src/gns/gnunet-gns-benchmark.c613
-rw-r--r--src/gns/gnunet-gns-helper-service-w32.c18
-rw-r--r--src/gns/gnunet-gns-import.c18
-rw-r--r--src/gns/gnunet-gns-proxy-setup-ca10
-rw-r--r--src/gns/gnunet-gns-proxy.c558
-rw-r--r--src/gns/gnunet-gns.c24
-rw-r--r--src/gns/gnunet-service-gns.c54
-rw-r--r--src/gns/gnunet-service-gns.h18
-rw-r--r--src/gns/gnunet-service-gns_interceptor.c20
-rw-r--r--src/gns/gnunet-service-gns_interceptor.h18
-rw-r--r--src/gns/gnunet-service-gns_resolver.c266
-rw-r--r--src/gns/gnunet-service-gns_resolver.h18
-rw-r--r--src/gns/nss/nss_gns.c269
-rw-r--r--src/gns/nss/nss_gns_query.c39
-rw-r--r--src/gns/nss/nss_gns_query.h44
-rw-r--r--src/gns/plugin_block_gns.c18
-rw-r--r--src/gns/plugin_gnsrecord_gns.c30
-rw-r--r--src/gns/plugin_rest_gns.c693
-rwxr-xr-xsrc/gns/test_gns_at_lookup.sh (renamed from src/gns/test_gns_plus_lookup.sh)8
-rwxr-xr-xsrc/gns/test_gns_cname_lookup.sh4
-rw-r--r--src/gns/test_gns_defaults.conf4
-rwxr-xr-xsrc/gns/test_gns_delegated_lookup.sh4
-rwxr-xr-xsrc/gns/test_gns_dht_lookup.sh4
-rwxr-xr-xsrc/gns/test_gns_gns2dns_cname_lookup.sh89
-rwxr-xr-xsrc/gns/test_gns_gns2dns_lookup.sh4
-rwxr-xr-xsrc/gns/test_gns_ipv6_lookup.sh2
-rw-r--r--src/gns/test_gns_lookup.conf6
-rwxr-xr-xsrc/gns/test_gns_mx_lookup.sh4
-rw-r--r--src/gns/test_gns_nick_shorten.conf6
-rw-r--r--src/gns/test_gns_proxy.c18
-rw-r--r--src/gns/test_gns_proxy.conf6
-rwxr-xr-xsrc/gns/test_gns_quickupdate.sh4
-rwxr-xr-xsrc/gns/test_gns_rel_expiration.sh4
-rwxr-xr-xsrc/gns/test_gns_revocation.sh4
-rw-r--r--src/gns/test_gns_simple_lookup.conf18
-rwxr-xr-xsrc/gns/test_gns_soa_lookup.sh4
-rwxr-xr-xsrc/gns/test_gns_txt_lookup.sh4
-rwxr-xr-xsrc/gns/test_gns_zkey_lookup.sh4
-rw-r--r--src/gns/w32nsp-install.c18
-rw-r--r--src/gns/w32nsp-resolve.c18
-rw-r--r--src/gns/w32nsp.c18
-rw-r--r--src/gns/w32resolver.h18
52 files changed, 1799 insertions, 1413 deletions
diff --git a/src/gns/.gitignore b/src/gns/.gitignore
index 5aecfd51d..2b9a18f21 100644
--- a/src/gns/.gitignore
+++ b/src/gns/.gitignore
@@ -3,3 +3,4 @@ gnunet-bcd
3gnunet-dns2gns 3gnunet-dns2gns
4gnunet-gns 4gnunet-gns
5gnunet-gns-proxy 5gnunet-gns-proxy
6gnunet-gns-benchmark
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 57b096b96..2659f7e6a 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -76,6 +76,9 @@ bin_PROGRAMS = \
76 $(DO_NONPOSIX_GNSIMPORT) \ 76 $(DO_NONPOSIX_GNSIMPORT) \
77 gnunet-gns 77 gnunet-gns
78 78
79noinst_PROGRAMS = \
80 gnunet-gns-benchmark
81
79if HAVE_MHD 82if HAVE_MHD
80if LINUX 83if LINUX
81bin_PROGRAMS += gnunet-bcd 84bin_PROGRAMS += gnunet-bcd
@@ -89,17 +92,10 @@ plugin_LTLIBRARIES = \
89 libgnunet_plugin_gnsrecord_gns.la 92 libgnunet_plugin_gnsrecord_gns.la
90 93
91 94
92if HAVE_MHD
93if HAVE_JSON
94plugin_LTLIBRARIES += libgnunet_plugin_rest_gns.la
95endif
96endif
97
98libgnunet_plugin_gnsrecord_gns_la_SOURCES = \ 95libgnunet_plugin_gnsrecord_gns_la_SOURCES = \
99 plugin_gnsrecord_gns.c 96 plugin_gnsrecord_gns.c
100libgnunet_plugin_gnsrecord_gns_la_LIBADD = \ 97libgnunet_plugin_gnsrecord_gns_la_LIBADD = \
101 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 98 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
102 $(top_builddir)/src/dns/libgnunetdnsparser.la \
103 $(top_builddir)/src/util/libgnunetutil.la \ 99 $(top_builddir)/src/util/libgnunetutil.la \
104 $(LTLIBINTL) 100 $(LTLIBINTL)
105libgnunet_plugin_gnsrecord_gns_la_LDFLAGS = \ 101libgnunet_plugin_gnsrecord_gns_la_LDFLAGS = \
@@ -114,6 +110,14 @@ gnunet_gns_LDADD = \
114 $(top_builddir)/src/util/libgnunetutil.la \ 110 $(top_builddir)/src/util/libgnunetutil.la \
115 $(GN_LIBINTL) 111 $(GN_LIBINTL)
116 112
113gnunet_gns_benchmark_SOURCES = \
114 gnunet-gns-benchmark.c
115gnunet_gns_benchmark_LDADD = \
116 libgnunetgns.la \
117 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
118 $(top_builddir)/src/util/libgnunetutil.la \
119 $(GN_LIBINTL)
120
117 121
118gnunet_bcd_SOURCES = \ 122gnunet_bcd_SOURCES = \
119 gnunet-bcd.c 123 gnunet-bcd.c
@@ -129,8 +133,6 @@ gnunet_dns2gns_LDADD = \
129 libgnunetgns.la \ 133 libgnunetgns.la \
130 $(top_builddir)/src/util/libgnunetutil.la \ 134 $(top_builddir)/src/util/libgnunetutil.la \
131 $(top_builddir)/src/identity/libgnunetidentity.la \ 135 $(top_builddir)/src/identity/libgnunetidentity.la \
132 $(top_builddir)/src/dns/libgnunetdnsparser.la \
133 $(top_builddir)/src/dns/libgnunetdnsstub.la \
134 $(GN_LIBINTL) 136 $(GN_LIBINTL)
135 137
136if LINUX 138if LINUX
@@ -195,10 +197,7 @@ gnunet_service_gns_LDADD = \
195 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 197 $(top_builddir)/src/statistics/libgnunetstatistics.la \
196 $(top_builddir)/src/util/libgnunetutil.la \ 198 $(top_builddir)/src/util/libgnunetutil.la \
197 $(top_builddir)/src/dns/libgnunetdns.la \ 199 $(top_builddir)/src/dns/libgnunetdns.la \
198 $(top_builddir)/src/dns/libgnunetdnsparser.la \
199 $(top_builddir)/src/dns/libgnunetdnsstub.la \
200 $(top_builddir)/src/dht/libgnunetdht.la \ 200 $(top_builddir)/src/dht/libgnunetdht.la \
201 $(top_builddir)/src/tun/libgnunettun.la \
202 $(top_builddir)/src/namecache/libgnunetnamecache.la \ 201 $(top_builddir)/src/namecache/libgnunetnamecache.la \
203 $(USE_VPN) \ 202 $(USE_VPN) \
204 $(GN_LIBINTL) 203 $(GN_LIBINTL)
@@ -233,19 +232,6 @@ libgnunet_plugin_block_gns_la_LIBADD = \
233libgnunet_plugin_block_gns_la_LDFLAGS = \ 232libgnunet_plugin_block_gns_la_LDFLAGS = \
234 $(GN_PLUGIN_LDFLAGS) 233 $(GN_PLUGIN_LDFLAGS)
235 234
236libgnunet_plugin_rest_gns_la_SOURCES = \
237 plugin_rest_gns.c
238libgnunet_plugin_rest_gns_la_LIBADD = \
239 libgnunetgns.la \
240 $(top_builddir)/src/rest/libgnunetrest.la \
241 $(top_builddir)/src/identity/libgnunetidentity.la \
242 $(top_builddir)/src/jsonapi/libgnunetjsonapi.la \
243 $(top_builddir)/src/jsonapi/libgnunetjsonapiutils.la \
244 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
245 $(LTLIBINTL) -ljansson -lmicrohttpd
246libgnunet_plugin_rest_gns_la_LDFLAGS = \
247 $(GN_PLUGIN_LDFLAGS)
248
249 235
250check_SCRIPTS = \ 236check_SCRIPTS = \
251 test_gns_lookup.sh \ 237 test_gns_lookup.sh \
@@ -253,9 +239,10 @@ check_SCRIPTS = \
253 test_gns_txt_lookup.sh\ 239 test_gns_txt_lookup.sh\
254 test_gns_mx_lookup.sh \ 240 test_gns_mx_lookup.sh \
255 test_gns_gns2dns_lookup.sh \ 241 test_gns_gns2dns_lookup.sh \
242 test_gns_gns2dns_cname_lookup.sh \
256 test_gns_dht_lookup.sh\ 243 test_gns_dht_lookup.sh\
257 test_gns_delegated_lookup.sh \ 244 test_gns_delegated_lookup.sh \
258 test_gns_plus_lookup.sh\ 245 test_gns_at_lookup.sh\
259 test_gns_zkey_lookup.sh\ 246 test_gns_zkey_lookup.sh\
260 test_gns_rel_expiration.sh\ 247 test_gns_rel_expiration.sh\
261 test_gns_soa_lookup.sh\ 248 test_gns_soa_lookup.sh\
diff --git a/src/gns/gns-helper-service-w32.conf b/src/gns/gns-helper-service-w32.conf
index 48652173a..a7b9fdd70 100644
--- a/src/gns/gns-helper-service-w32.conf
+++ b/src/gns/gns-helper-service-w32.conf
@@ -1,4 +1,4 @@
1[gns-helper-service-w32] 1[gns-helper-service-w32]
2AUTOSTART = YES 2START_ON_DEMAND = YES
3BINARY = gnunet-gns-helper-service-w32 3BINARY = gnunet-gns-helper-service-w32
4PORT = 5353 4PORT = 5353
diff --git a/src/gns/gns.conf.in b/src/gns/gns.conf.in
index 2e49a4c60..2e6a02b07 100644
--- a/src/gns/gns.conf.in
+++ b/src/gns/gns.conf.in
@@ -1,6 +1,6 @@
1[gns] 1[gns]
2AUTOSTART = @AUTOSTART@ 2START_ON_DEMAND = @START_ON_DEMAND@
3FORCESTART = YES 3IMMEDIATE_START = YES
4HOSTNAME = localhost 4HOSTNAME = localhost
5BINARY = gnunet-service-gns 5BINARY = gnunet-service-gns
6UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-gns.sock 6UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-gns.sock
@@ -20,18 +20,18 @@ MAX_PARALLEL_BACKGROUND_QUERIES = 1000
20# we will ask gnunet-service-dns to pass DNS queries to us. Otherwise, 20# we will ask gnunet-service-dns to pass DNS queries to us. Otherwise,
21# we only answer GNS queries via the API (which itself may be 21# we only answer GNS queries via the API (which itself may be
22# called via NSS or other mechanisms). 22# called via NSS or other mechanisms).
23INTERCEPT_DNS = YES 23INTERCEPT_DNS = NO
24 24
25# PREFIX = valgrind --leak-check=full --track-origins=yes 25# PREFIX = valgrind --leak-check=full --track-origins=yes
26 26
27# Zones 27# Zones
28.pin = DWJASSPE33MRN8T6Q0PENRNBTQY0E6ZYGTRCDP5DGPBF2CRJMJEG 28.pin = DWJASSPE33MRN8T6Q0PENRNBTQY0E6ZYGTRCDP5DGPBF2CRJMJEG
29 29.fr = TFDAXBXMAN40MCG4E8Y9Y1C6D16JCMDPH2VMD30KMB92SECEMYGG
30 30
31[gns-proxy] 31[gns-proxy]
32BINARY = gnunet-gns-proxy 32BINARY = gnunet-gns-proxy
33AUTOSTART = NO 33START_ON_DEMAND = NO
34USER_SERVICE = YES 34RUN_PER_USER = YES
35 35
36# Where is the certificate for the GNS proxy stored? 36# Where is the certificate for the GNS proxy stored?
37PROXY_CACERT = $GNUNET_DATA_HOME/gns/gns_ca_cert.pem 37PROXY_CACERT = $GNUNET_DATA_HOME/gns/gns_ca_cert.pem
@@ -40,8 +40,8 @@ PROXY_UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-gns-proxy.sock
40 40
41[dns2gns] 41[dns2gns]
42BINARY = gnunet-dns2gns 42BINARY = gnunet-dns2gns
43AUTOSTART = NO 43START_ON_DEMAND = NO
44USER_SERVICE = YES 44RUN_PER_USER = YES
45 45
46# -d: DNS resolver to use, -s: suffix to use, -f: fcfs suffix to use 46# -d: DNS resolver to use, -s: suffix to use, -f: fcfs suffix to use
47OPTIONS = -d 8.8.8.8 47OPTIONS = -d 8.8.8.8
diff --git a/src/gns/gns.h b/src/gns/gns.h
index d77bf53c6..8a615f43e 100644
--- a/src/gns/gns.h
+++ b/src/gns/gns.h
@@ -2,20 +2,18 @@
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 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19 */ 17 */
20/** 18/**
21 * @file gns/gns.h 19 * @file gns/gns.h
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index ff67f0205..3b658da92 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009-2013, 2016, 2018 GNUnet e.V. 3 Copyright (C) 2009-2013, 2016, 2018 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gns/gns_api.c 19 * @file gns/gns_api.c
@@ -157,7 +155,7 @@ check_result (void *cls,
157 size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg); 155 size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg);
158 uint32_t rd_count = ntohl (lookup_msg->rd_count); 156 uint32_t rd_count = ntohl (lookup_msg->rd_count);
159 struct GNUNET_GNSRECORD_Data rd[rd_count]; 157 struct GNUNET_GNSRECORD_Data rd[rd_count];
160 158
161 (void) cls; 159 (void) cls;
162 if (GNUNET_SYSERR == 160 if (GNUNET_SYSERR ==
163 GNUNET_GNSRECORD_records_deserialize (mlen, 161 GNUNET_GNSRECORD_records_deserialize (mlen,
@@ -201,7 +199,7 @@ handle_result (void *cls,
201 return; 199 return;
202 proc = lr->lookup_proc; 200 proc = lr->lookup_proc;
203 proc_cls = lr->proc_cls; 201 proc_cls = lr->proc_cls;
204 202
205 GNUNET_assert (GNUNET_OK == 203 GNUNET_assert (GNUNET_OK ==
206 GNUNET_GNSRECORD_records_deserialize (mlen, 204 GNUNET_GNSRECORD_records_deserialize (mlen,
207 (const char*) &lookup_msg[1], 205 (const char*) &lookup_msg[1],
@@ -234,7 +232,6 @@ reconnect (struct GNUNET_GNS_Handle *handle)
234 handle), 232 handle),
235 GNUNET_MQ_handler_end () 233 GNUNET_MQ_handler_end ()
236 }; 234 };
237 struct GNUNET_GNS_LookupRequest *lh;
238 235
239 GNUNET_assert (NULL == handle->mq); 236 GNUNET_assert (NULL == handle->mq);
240 LOG (GNUNET_ERROR_TYPE_DEBUG, 237 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -246,7 +243,9 @@ reconnect (struct GNUNET_GNS_Handle *handle)
246 handle); 243 handle);
247 if (NULL == handle->mq) 244 if (NULL == handle->mq)
248 return; 245 return;
249 for (lh = handle->lookup_head; NULL != lh; lh = lh->next) 246 for (struct GNUNET_GNS_LookupRequest *lh = handle->lookup_head;
247 NULL != lh;
248 lh = lh->next)
250 GNUNET_MQ_send_copy (handle->mq, 249 GNUNET_MQ_send_copy (handle->mq,
251 lh->env); 250 lh->env);
252} 251}
@@ -302,17 +301,21 @@ GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle)
302 * Cancel pending lookup request 301 * Cancel pending lookup request
303 * 302 *
304 * @param lr the lookup request to cancel 303 * @param lr the lookup request to cancel
304 * @return closure from the lookup result processor
305 */ 305 */
306void 306void *
307GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr) 307GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr)
308{ 308{
309 struct GNUNET_GNS_Handle *handle = lr->gns_handle; 309 struct GNUNET_GNS_Handle *handle = lr->gns_handle;
310 void *ret;
310 311
311 GNUNET_CONTAINER_DLL_remove (handle->lookup_head, 312 GNUNET_CONTAINER_DLL_remove (handle->lookup_head,
312 handle->lookup_tail, 313 handle->lookup_tail,
313 lr); 314 lr);
314 GNUNET_MQ_discard (lr->env); 315 GNUNET_MQ_discard (lr->env);
316 ret = lr->proc_cls;
315 GNUNET_free (lr); 317 GNUNET_free (lr);
318 return ret;
316} 319}
317 320
318 321
diff --git a/src/gns/gns_api.h b/src/gns/gns_api.h
index e4912338f..622e4339c 100644
--- a/src/gns/gns_api.h
+++ b/src/gns/gns_api.h
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009-2013, 2016, 2018 GNUnet e.V. 3 Copyright (C) 2009-2013, 2016, 2018 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gns/gns_api.h 19 * @file gns/gns_api.h
diff --git a/src/gns/gns_tld_api.c b/src/gns/gns_tld_api.c
index 8a4d03b11..825b51d06 100644
--- a/src/gns/gns_tld_api.c
+++ b/src/gns/gns_tld_api.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009-2013, 2016, 2018 GNUnet e.V. 3 Copyright (C) 2009-2013, 2016, 2018 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gns/gns_tld_api.c 19 * @file gns/gns_tld_api.c
@@ -319,10 +317,13 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle,
319 * Cancel pending lookup request 317 * Cancel pending lookup request
320 * 318 *
321 * @param ltr the lookup request to cancel 319 * @param ltr the lookup request to cancel
320 * @return closure from the lookup result processor
322 */ 321 */
323void 322void *
324GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr) 323GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr)
325{ 324{
325 void *ret = ltr->lookup_proc_cls;
326
326 if (NULL != ltr->id_op) 327 if (NULL != ltr->id_op)
327 { 328 {
328 GNUNET_IDENTITY_ego_lookup_cancel (ltr->id_op); 329 GNUNET_IDENTITY_ego_lookup_cancel (ltr->id_op);
@@ -335,6 +336,7 @@ GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr)
335 } 336 }
336 GNUNET_free (ltr->name); 337 GNUNET_free (ltr->name);
337 GNUNET_free (ltr); 338 GNUNET_free (ltr);
339 return ret;
338} 340}
339 341
340/* end of gns_tld_api.c */ 342/* end of gns_tld_api.c */
diff --git a/src/gns/gnunet-bcd.c b/src/gns/gnunet-bcd.c
index 0746d5c57..9737e1a49 100644
--- a/src/gns/gnunet-bcd.c
+++ b/src/gns/gnunet-bcd.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V. 3 Copyright (C) 2013 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20 18
21/** 19/**
@@ -76,7 +74,7 @@ static char *resfile;
76/** 74/**
77 * Port number. 75 * Port number.
78 */ 76 */
79static unsigned int port = 8888; 77static uint16_t port = 8888;
80 78
81 79
82struct Entry 80struct Entry
@@ -351,7 +349,7 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
351static int 349static int
352server_start () 350server_start ()
353{ 351{
354 if ((0 == port) || (port > UINT16_MAX)) 352 if (0 == port)
355 { 353 {
356 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 354 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
357 _("Invalid port number %u. Exiting.\n"), 355 _("Invalid port number %u. Exiting.\n"),
@@ -362,7 +360,7 @@ server_start ()
362 _("Businesscard HTTP server starts on %u\n"), 360 _("Businesscard HTTP server starts on %u\n"),
363 port); 361 port);
364 daemon_handle = MHD_start_daemon (MHD_USE_DUAL_STACK | MHD_USE_DEBUG, 362 daemon_handle = MHD_start_daemon (MHD_USE_DUAL_STACK | MHD_USE_DEBUG,
365 (uint16_t) port, 363 port,
366 NULL /* accept_policy_callback */, NULL, 364 NULL /* accept_policy_callback */, NULL,
367 &access_handler_callback, NULL, 365 &access_handler_callback, NULL,
368 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 512, 366 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 512,
@@ -374,7 +372,7 @@ server_start ()
374 { 372 {
375 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 373 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
376 _("Could not start businesscard HTTP server on port %u\n"), 374 _("Could not start businesscard HTTP server on port %u\n"),
377 (unsigned short) port); 375 (unsigned int) port);
378 return GNUNET_SYSERR; 376 return GNUNET_SYSERR;
379 } 377 }
380 http_task = prepare_daemon (daemon_handle); 378 http_task = prepare_daemon (daemon_handle);
@@ -471,7 +469,7 @@ run (void *cls,
471 "open", 469 "open",
472 fn); 470 fn);
473 GNUNET_free (fn); 471 GNUNET_free (fn);
474 CLOSE (fd); 472 GNUNET_break (0 == CLOSE (fd));
475 return; 473 return;
476 } 474 }
477 GNUNET_free (fn); 475 GNUNET_free (fn);
@@ -501,6 +499,7 @@ run (void *cls,
501 return; 499 return;
502 GNUNET_SCHEDULER_add_shutdown (&server_stop, 500 GNUNET_SCHEDULER_add_shutdown (&server_stop,
503 NULL); 501 NULL);
502 GNUNET_break (0 == CLOSE(fd));
504} 503}
505 504
506 505
@@ -516,17 +515,17 @@ main (int argc, char *const *argv)
516{ 515{
517 struct GNUNET_GETOPT_CommandLineOption options[] = { 516 struct GNUNET_GETOPT_CommandLineOption options[] = {
518 517
519 GNUNET_GETOPT_option_uint ('p', 518 GNUNET_GETOPT_option_uint16 ('p',
520 "port", 519 "port",
521 "PORT", 520 "PORT",
522 gettext_noop ("Run HTTP serve on port PORT (default is 8888)"), 521 gettext_noop ("Run HTTP serve on port PORT (default is 8888)"),
523 &port), 522 &port),
524
525 GNUNET_GETOPT_OPTION_END 523 GNUNET_GETOPT_OPTION_END
526 }; 524 };
527 int ret; 525 int ret;
528 526
529 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 527 if (GNUNET_OK !=
528 GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
530 return 2; 529 return 2;
531 GNUNET_log_setup ("gnunet-bcd", "WARNING", NULL); 530 GNUNET_log_setup ("gnunet-bcd", "WARNING", NULL);
532 ret = 531 ret =
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c
index bc66f1325..8d39e8c53 100644
--- a/src/gns/gnunet-dns2gns.c
+++ b/src/gns/gnunet-dns2gns.c
@@ -2,20 +2,18 @@
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 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gnunet-dns2gns.c 19 * @file gnunet-dns2gns.c
@@ -271,6 +269,7 @@ dns_result_processor (void *cls,
271 } 269 }
272 request->packet = GNUNET_DNSPARSER_parse ((char*)dns, 270 request->packet = GNUNET_DNSPARSER_parse ((char*)dns,
273 r); 271 r);
272 GNUNET_DNSSTUB_resolve_cancel (request->dns_lookup);
274 send_response (request); 273 send_response (request);
275} 274}
276 275
diff --git a/src/gns/gnunet-gns-benchmark.c b/src/gns/gnunet-gns-benchmark.c
new file mode 100644
index 000000000..6ed4dfe6c
--- /dev/null
+++ b/src/gns/gnunet-gns-benchmark.c
@@ -0,0 +1,613 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2018 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18/**
19 * @file src/gns/gnunet-gns-benchmark.c
20 * @brief issue many queries to GNS and compute performance statistics
21 * @author Christian Grothoff
22 */
23#include "platform.h"
24#include <gnunet_util_lib.h>
25#include <gnunet_gnsrecord_lib.h>
26#include <gnunet_gns_service.h>
27
28
29/**
30 * How long do we wait at least between requests by default?
31 */
32#define DEF_REQUEST_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 1)
33
34/**
35 * How long do we wait until we consider a request failed by default?
36 */
37#define DEF_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
38
39
40/**
41 * We distinguish between different categories of
42 * requests, for which we track statistics separately.
43 * However, this process does not change how it acts
44 * based on the category.
45 */
46enum RequestCategory
47{
48 RC_SHARED = 0,
49 RC_PRIVATE = 1,
50 /**
51 * Must be last and match number of categories.
52 */
53 RC_MAX = 2
54};
55
56
57/**
58 * Request we should make. We keep this struct in memory per request,
59 * thus optimizing it is crucial for the overall memory consumption of
60 * the zone importer.
61 */
62struct Request
63{
64
65 /**
66 * Active requests are kept in a DLL.
67 */
68 struct Request *next;
69
70 /**
71 * Active requests are kept in a DLL.
72 */
73 struct Request *prev;
74
75 /**
76 * Socket used to make the request, NULL if not active.
77 */
78 struct GNUNET_GNS_LookupWithTldRequest *lr;
79
80 /**
81 * Hostname we are resolving, allocated at the end of
82 * this struct (optimizing memory consumption by reducing
83 * total number of allocations).
84 */
85 const char *hostname;
86
87 /**
88 * While we are fetching the record, the value is set to the
89 * starting time of the GNS operation.
90 */
91 struct GNUNET_TIME_Absolute op_start_time;
92
93 /**
94 * Observed latency, set once we got a reply.
95 */
96 struct GNUNET_TIME_Relative latency;
97
98 /**
99 * Category of the request.
100 */
101 enum RequestCategory cat;
102
103};
104
105
106/**
107 * GNS handle.
108 */
109static struct GNUNET_GNS_Handle *gns;
110
111/**
112 * Number of lookups we performed overall per category.
113 */
114static unsigned int lookups[RC_MAX];
115
116/**
117 * Number of replies we got per category.
118 */
119static unsigned int replies[RC_MAX];
120
121/**
122 * Number of replies we got per category.
123 */
124static unsigned int failures[RC_MAX];
125
126/**
127 * Sum of the observed latencies of successful queries,
128 * per category.
129 */
130static struct GNUNET_TIME_Relative latency_sum[RC_MAX];
131
132/**
133 * Active requests are kept in a DLL.
134 */
135static struct Request *act_head;
136
137/**
138 * Active requests are kept in a DLL.
139 */
140static struct Request *act_tail;
141
142/**
143 * Completed successful requests are kept in a DLL.
144 */
145static struct Request *succ_head;
146
147/**
148 * Completed successful requests are kept in a DLL.
149 */
150static struct Request *succ_tail;
151
152/**
153 * Yet to be started requests are kept in a DLL.
154 */
155static struct Request *todo_head;
156
157/**
158 * Yet to be started requests are kept in a DLL.
159 */
160static struct Request *todo_tail;
161
162/**
163 * Main task.
164 */
165static struct GNUNET_SCHEDULER_Task *t;
166
167/**
168 * Delay between requests.
169 */
170static struct GNUNET_TIME_Relative request_delay;
171
172/**
173 * Timeout for requests.
174 */
175static struct GNUNET_TIME_Relative timeout;
176
177/**
178 * Number of requests we have concurrently active.
179 */
180static unsigned int active_cnt;
181
182/**
183 * Look for GNS2DNS records specifically?
184 */
185static int g2d;
186
187/**
188 * Free @a req and data structures reachable from it.
189 *
190 * @param req request to free
191 */
192static void
193free_request (struct Request *req)
194{
195 if (NULL != req->lr)
196 GNUNET_GNS_lookup_with_tld_cancel (req->lr);
197 GNUNET_free (req);
198}
199
200
201/**
202 * Function called with the result of a GNS resolution.
203 *
204 * @param cls closure with the `struct Request`
205 * @param gns_tld #GNUNET_YES if GNS lookup was attempted
206 * @param rd_count number of records in @a rd
207 * @param rd the records in reply
208 */
209static void
210process_result (void *cls,
211 int gns_tld,
212 uint32_t rd_count,
213 const struct GNUNET_GNSRECORD_Data *rd)
214{
215 struct Request *req = cls;
216
217 (void) gns_tld;
218 (void) rd_count;
219 (void) rd;
220 active_cnt--;
221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
222 "Got response for request `%s'\n",
223 req->hostname);
224 req->lr = NULL;
225 req->latency = GNUNET_TIME_absolute_get_duration (req->op_start_time);
226 GNUNET_CONTAINER_DLL_remove (act_head,
227 act_tail,
228 req);
229 GNUNET_CONTAINER_DLL_insert (succ_head,
230 succ_tail,
231 req);
232 replies[req->cat]++;
233 latency_sum[req->cat]
234 = GNUNET_TIME_relative_add (latency_sum[req->cat],
235 req->latency);
236}
237
238
239/**
240 * Process request from the queue.
241 *
242 * @param cls NULL
243 */
244static void
245process_queue (void *cls)
246{
247 struct Request *req;
248 struct GNUNET_TIME_Relative duration;
249
250 (void) cls;
251 t = NULL;
252 /* check for expired requests */
253 while (NULL != (req = act_head))
254 {
255 duration = GNUNET_TIME_absolute_get_duration (req->op_start_time);
256 if (duration.rel_value_us < timeout.rel_value_us)
257 break;
258 GNUNET_CONTAINER_DLL_remove (act_head,
259 act_tail,
260 req);
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
262 "Failing request `%s' due to timeout\n",
263 req->hostname);
264 failures[req->cat]++;
265 active_cnt--;
266 free_request (req);
267 }
268 if (NULL == (req = todo_head))
269 {
270 struct GNUNET_TIME_Absolute at;
271
272 if (NULL == (req = act_head))
273 {
274 GNUNET_SCHEDULER_shutdown ();
275 return;
276 }
277 at = GNUNET_TIME_absolute_add (req->op_start_time,
278 timeout);
279 t = GNUNET_SCHEDULER_add_at (at,
280 &process_queue,
281 NULL);
282 return;
283 }
284 GNUNET_CONTAINER_DLL_remove (todo_head,
285 todo_tail,
286 req);
287 GNUNET_CONTAINER_DLL_insert_tail (act_head,
288 act_tail,
289 req);
290 lookups[req->cat]++;
291 active_cnt++;
292 req->op_start_time = GNUNET_TIME_absolute_get ();
293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
294 "Starting request `%s' (%u in parallel)\n",
295 req->hostname,
296 active_cnt);
297 req->lr = GNUNET_GNS_lookup_with_tld (gns,
298 req->hostname,
299 g2d
300 ? GNUNET_GNSRECORD_TYPE_GNS2DNS
301 : GNUNET_GNSRECORD_TYPE_ANY,
302 GNUNET_GNS_LO_DEFAULT,
303 &process_result,
304 req);
305 t = GNUNET_SCHEDULER_add_delayed (request_delay,
306 &process_queue,
307 NULL);
308}
309
310
311/**
312 * Compare two requests by latency for qsort().
313 *
314 * @param c1 pointer to `struct Request *`
315 * @param c2 pointer to `struct Request *`
316 * @return -1 if c1<c2, 1 if c1>c2, 0 if c1==c2.
317 */
318static int
319compare_req (const void *c1,
320 const void *c2)
321{
322 const struct Request *r1 = *(void **) c1;
323 const struct Request *r2 = *(void **) c2;
324
325 if (r1->latency.rel_value_us < r2->latency.rel_value_us)
326 return -1;
327 if (r1->latency.rel_value_us > r2->latency.rel_value_us)
328 return 1;
329 return 0;
330}
331
332
333/**
334 * Output statistics, then clean up and terminate the process.
335 *
336 * @param cls NULL
337 */
338static void
339do_shutdown (void *cls)
340{
341 struct Request *req;
342 struct Request **ra[RC_MAX];
343 unsigned int rp[RC_MAX];
344
345 (void) cls;
346 for (enum RequestCategory rc = 0;rc < RC_MAX;rc++)
347 {
348 ra[rc] = GNUNET_new_array (replies[rc],
349 struct Request *);
350 rp[rc] = 0;
351 }
352 for (req = succ_head;NULL != req; req = req->next)
353 {
354 GNUNET_assert (rp[req->cat] < replies[req->cat]);
355 ra[req->cat][rp[req->cat]++] = req;
356 }
357 for (enum RequestCategory rc = 0;rc < RC_MAX;rc++)
358 {
359 unsigned int off;
360
361 fprintf (stdout,
362 "Category %u\n",
363 rc);
364 fprintf (stdout,
365 "\tlookups: %u replies: %u failures: %u\n",
366 lookups[rc],
367 replies[rc],
368 failures[rc]);
369 if (0 == rp[rc])
370 continue;
371 qsort (ra[rc],
372 rp[rc],
373 sizeof (struct Request *),
374 &compare_req);
375 latency_sum[rc] = GNUNET_TIME_relative_divide (latency_sum[rc],
376 replies[rc]);
377 fprintf (stdout,
378 "\taverage: %s\n",
379 GNUNET_STRINGS_relative_time_to_string (latency_sum[rc],
380 GNUNET_YES));
381 off = rp[rc] * 50 / 100;
382 fprintf (stdout,
383 "\tmedian(50): %s\n",
384 GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
385 GNUNET_YES));
386 off = rp[rc] * 75 / 100;
387 fprintf (stdout,
388 "\tquantile(75): %s\n",
389 GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
390 GNUNET_YES));
391 off = rp[rc] * 90 / 100;
392 fprintf (stdout,
393 "\tquantile(90): %s\n",
394 GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
395 GNUNET_YES));
396 off = rp[rc] * 99 / 100;
397 fprintf (stdout,
398 "\tquantile(99): %s\n",
399 GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
400 GNUNET_YES));
401 GNUNET_free (ra[rc]);
402 }
403 if (NULL != t)
404 {
405 GNUNET_SCHEDULER_cancel (t);
406 t = NULL;
407 }
408 while (NULL != (req = act_head))
409 {
410 GNUNET_CONTAINER_DLL_remove (act_head,
411 act_tail,
412 req);
413 free_request (req);
414 }
415 while (NULL != (req = succ_head))
416 {
417 GNUNET_CONTAINER_DLL_remove (succ_head,
418 succ_tail,
419 req);
420 free_request (req);
421 }
422 while (NULL != (req = todo_head))
423 {
424 GNUNET_CONTAINER_DLL_remove (todo_head,
425 todo_tail,
426 req);
427 free_request (req);
428 }
429 if (NULL != gns)
430 {
431 GNUNET_GNS_disconnect (gns);
432 gns = NULL;
433 }
434}
435
436
437/**
438 * Add @a hostname to the list of requests to be made.
439 *
440 * @param hostname name to resolve
441 * @param cat category of the @a hostname
442 */
443static void
444queue (const char *hostname,
445 enum RequestCategory cat)
446{
447 struct Request *req;
448 const char *dot;
449 size_t hlen;
450
451 dot = strchr (hostname,
452 (unsigned char) '.');
453 if (NULL == dot)
454 {
455 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
456 "Refusing invalid hostname `%s' (lacks '.')\n",
457 hostname);
458 return;
459 }
460 hlen = strlen (hostname) + 1;
461 req = GNUNET_malloc (sizeof (struct Request) + hlen);
462 req->cat = cat;
463 req->hostname = (char *) &req[1];
464 GNUNET_memcpy (&req[1],
465 hostname,
466 hlen);
467 GNUNET_CONTAINER_DLL_insert (todo_head,
468 todo_tail,
469 req);
470}
471
472
473/**
474 * Begin processing hostnames from stdin.
475 *
476 * @param cls NULL
477 */
478static void
479process_stdin (void *cls)
480{
481 static struct GNUNET_TIME_Absolute last;
482 static uint64_t idot;
483 unsigned int cat;
484 char hn[256];
485 char in[270];
486
487 (void) cls;
488 t = NULL;
489 while (NULL !=
490 fgets (in,
491 sizeof (in),
492 stdin))
493 {
494 if (strlen(in) > 0)
495 hn[strlen(in)-1] = '\0'; /* eat newline */
496 if ( (2 != sscanf (in,
497 "%u %255s",
498 &cat,
499 hn)) ||
500 (cat >= RC_MAX) )
501 {
502 fprintf (stderr,
503 "Malformed input line `%s', skipping\n",
504 in);
505 continue;
506 }
507 if (0 == idot)
508 last = GNUNET_TIME_absolute_get ();
509 idot++;
510 if (0 == idot % 100000)
511 {
512 struct GNUNET_TIME_Relative delta;
513
514 delta = GNUNET_TIME_absolute_get_duration (last);
515 last = GNUNET_TIME_absolute_get ();
516 fprintf (stderr,
517 "Read 100000 domain names in %s\n",
518 GNUNET_STRINGS_relative_time_to_string (delta,
519 GNUNET_YES));
520 }
521 queue (hn,
522 (enum RequestCategory) cat);
523 }
524 fprintf (stderr,
525 "Done reading %llu domain names\n",
526 (unsigned long long) idot);
527 t = GNUNET_SCHEDULER_add_now (&process_queue,
528 NULL);
529}
530
531
532/**
533 * Process requests from the queue, then if the queue is
534 * not empty, try again.
535 *
536 * @param cls NULL
537 * @param args remaining command-line arguments
538 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
539 * @param cfg configuration
540 */
541static void
542run (void *cls,
543 char *const *args,
544 const char *cfgfile,
545 const struct GNUNET_CONFIGURATION_Handle *cfg)
546{
547 (void) cls;
548 (void) args;
549 (void) cfgfile;
550 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
551 NULL);
552 gns = GNUNET_GNS_connect (cfg);
553 if (NULL == gns)
554 {
555 GNUNET_break (0);
556 GNUNET_SCHEDULER_shutdown ();
557 return;
558 }
559 t = GNUNET_SCHEDULER_add_now (&process_stdin,
560 NULL);
561}
562
563
564/**
565 * Call with list of names with numeric category to query.
566 *
567 * @param argc unused
568 * @param argv unused
569 * @return 0 on success
570 */
571int
572main (int argc,
573 char *const*argv)
574{
575 int ret = 0;
576 struct GNUNET_GETOPT_CommandLineOption options[] = {
577 GNUNET_GETOPT_option_relative_time ('d',
578 "delay",
579 "RELATIVETIME",
580 gettext_noop ("how long to wait between queries"),
581 &request_delay),
582 GNUNET_GETOPT_option_relative_time ('t',
583 "timeout",
584 "RELATIVETIME",
585 gettext_noop ("how long to wait for an answer"),
586 &timeout),
587 GNUNET_GETOPT_option_flag ('2',
588 "g2d",
589 gettext_noop ("look for GNS2DNS records instead of ANY"),
590 &g2d),
591 GNUNET_GETOPT_OPTION_END
592 };
593
594 if (GNUNET_OK !=
595 GNUNET_STRINGS_get_utf8_args (argc, argv,
596 &argc, &argv))
597 return 2;
598 timeout = DEF_TIMEOUT;
599 request_delay = DEF_REQUEST_DELAY;
600 if (GNUNET_OK !=
601 GNUNET_PROGRAM_run (argc,
602 argv,
603 "gnunet-gns-benchmark",
604 "resolve GNS names and measure performance",
605 options,
606 &run,
607 NULL))
608 ret = 1;
609 GNUNET_free ((void*) argv);
610 return ret;
611}
612
613/* end of gnunet-gns-benchmark.c */
diff --git a/src/gns/gnunet-gns-helper-service-w32.c b/src/gns/gnunet-gns-helper-service-w32.c
index a59cc5981..0e3b3f0e6 100644
--- a/src/gns/gnunet-gns-helper-service-w32.c
+++ b/src/gns/gnunet-gns-helper-service-w32.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012, 2017 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gnunet-gns-helper-service-w32.c 19 * @file gnunet-gns-helper-service-w32.c
diff --git a/src/gns/gnunet-gns-import.c b/src/gns/gnunet-gns-import.c
index 3b9b0a081..2b2c0ddee 100644
--- a/src/gns/gnunet-gns-import.c
+++ b/src/gns/gnunet-gns-import.c
@@ -2,20 +2,18 @@
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 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gnunet-gns.c 19 * @file gnunet-gns.c
diff --git a/src/gns/gnunet-gns-proxy-setup-ca b/src/gns/gnunet-gns-proxy-setup-ca
index 72d478a50..52f4b012b 100644
--- a/src/gns/gnunet-gns-proxy-setup-ca
+++ b/src/gns/gnunet-gns-proxy-setup-ca
@@ -2,12 +2,22 @@
2# This shell script will generate an X509 certificate for your gnunet-gns-proxy 2# This shell script will generate an X509 certificate for your gnunet-gns-proxy
3# and install it (for both GNUnet and your browser). 3# and install it (for both GNUnet and your browser).
4# 4#
5
6# TODO: We should sed the real paths to the binaries involved here.
7
5if ! which certutil > /dev/null 8if ! which certutil > /dev/null
6then 9then
7 echo "'certutil' command not found. Please install it." 10 echo "'certutil' command not found. Please install it."
8 exit 1 11 exit 1
9fi 12fi
10 13
14if ! which openssl > /dev/null
15then
16 echo "'openssl' command not found. Please install it."
17 exit 1
18fi
19
20
11echo "Generating CA" 21echo "Generating CA"
12options='' 22options=''
13while getopts "c:" opt; do 23while getopts "c:" opt; do
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 08663a57e..d66f5c658 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -1,21 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012-2014 GNUnet e.V. 3 Copyright (C) 2012-2018 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @author Martin Schanzenbach 19 * @author Martin Schanzenbach
@@ -48,6 +46,7 @@
48#include "gns.h" 46#include "gns.h"
49 47
50 48
49
51/** 50/**
52 * Default Socks5 listen port. 51 * Default Socks5 listen port.
53 */ 52 */
@@ -106,7 +105,13 @@
106 * @param fun name of curl_easy-function that gave the error 105 * @param fun name of curl_easy-function that gave the error
107 * @param rc return code from curl 106 * @param rc return code from curl
108 */ 107 */
109#define LOG_CURL_EASY(level,fun,rc) GNUNET_log(level, _("%s failed at %s:%d: `%s'\n"), fun, __FILE__, __LINE__, curl_easy_strerror (rc)) 108#define LOG_CURL_EASY(level,fun,rc) \
109 GNUNET_log (level, \
110 _("%s failed at %s:%d: `%s'\n"), \
111 fun, \
112 __FILE__, \
113 __LINE__, \
114 curl_easy_strerror (rc))
110 115
111 116
112/* *************** Socks protocol definitions (move to TUN?) ****************** */ 117/* *************** Socks protocol definitions (move to TUN?) ****************** */
@@ -626,6 +631,11 @@ struct Socks5Request
626 * Did we suspend MHD processing? 631 * Did we suspend MHD processing?
627 */ 632 */
628 int suspended; 633 int suspended;
634
635 /**
636 * Did we pause CURL processing?
637 */
638 int curl_paused;
629}; 639};
630 640
631 641
@@ -636,7 +646,7 @@ struct Socks5Request
636/** 646/**
637 * The port the proxy is running on (default 7777) 647 * The port the proxy is running on (default 7777)
638 */ 648 */
639static unsigned long long port = GNUNET_GNS_PROXY_PORT; 649static uint16_t port = GNUNET_GNS_PROXY_PORT;
640 650
641/** 651/**
642 * The CA file (pem) to use for the proxy CA 652 * The CA file (pem) to use for the proxy CA
@@ -679,6 +689,11 @@ static CURLM *curl_multi;
679static struct GNUNET_GNS_Handle *gns_handle; 689static struct GNUNET_GNS_Handle *gns_handle;
680 690
681/** 691/**
692 * Disable IPv6.
693 */
694static int disable_v6;
695
696/**
682 * DLL for http/https daemons 697 * DLL for http/https daemons
683 */ 698 */
684static struct MhdHttpList *mhd_httpd_head; 699static struct MhdHttpList *mhd_httpd_head;
@@ -763,21 +778,37 @@ cleanup_s5r (struct Socks5Request *s5r)
763 } 778 }
764 if ( (NULL != s5r->response) && 779 if ( (NULL != s5r->response) &&
765 (curl_failure_response != s5r->response) ) 780 (curl_failure_response != s5r->response) )
781 {
766 MHD_destroy_response (s5r->response); 782 MHD_destroy_response (s5r->response);
783 s5r->response = NULL;
784 }
767 if (NULL != s5r->rtask) 785 if (NULL != s5r->rtask)
786 {
768 GNUNET_SCHEDULER_cancel (s5r->rtask); 787 GNUNET_SCHEDULER_cancel (s5r->rtask);
788 s5r->rtask = NULL;
789 }
769 if (NULL != s5r->timeout_task) 790 if (NULL != s5r->timeout_task)
791 {
770 GNUNET_SCHEDULER_cancel (s5r->timeout_task); 792 GNUNET_SCHEDULER_cancel (s5r->timeout_task);
793 s5r->timeout_task = NULL;
794 }
771 if (NULL != s5r->wtask) 795 if (NULL != s5r->wtask)
796 {
772 GNUNET_SCHEDULER_cancel (s5r->wtask); 797 GNUNET_SCHEDULER_cancel (s5r->wtask);
798 s5r->wtask = NULL;
799 }
773 if (NULL != s5r->gns_lookup) 800 if (NULL != s5r->gns_lookup)
801 {
774 GNUNET_GNS_lookup_with_tld_cancel (s5r->gns_lookup); 802 GNUNET_GNS_lookup_with_tld_cancel (s5r->gns_lookup);
803 s5r->gns_lookup = NULL;
804 }
775 if (NULL != s5r->sock) 805 if (NULL != s5r->sock)
776 { 806 {
777 if (SOCKS5_SOCKET_WITH_MHD <= s5r->state) 807 if (SOCKS5_SOCKET_WITH_MHD <= s5r->state)
778 GNUNET_NETWORK_socket_free_memory_only_ (s5r->sock); 808 GNUNET_NETWORK_socket_free_memory_only_ (s5r->sock);
779 else 809 else
780 GNUNET_NETWORK_socket_close (s5r->sock); 810 GNUNET_NETWORK_socket_close (s5r->sock);
811 s5r->sock = NULL;
781 } 812 }
782 GNUNET_CONTAINER_DLL_remove (s5r_head, 813 GNUNET_CONTAINER_DLL_remove (s5r_head,
783 s5r_tail, 814 s5r_tail,
@@ -823,7 +854,9 @@ mhd_content_cb (void *cls,
823 start the download, the IO buffer is still full 854 start the download, the IO buffer is still full
824 with upload data. */ 855 with upload data. */
825 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 856 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
826 "Pausing MHD download, not yet ready for download\n"); 857 "Pausing MHD download %s%s, not yet ready for download\n",
858 s5r->domain,
859 s5r->url);
827 return 0; /* not yet ready for data download */ 860 return 0; /* not yet ready for data download */
828 } 861 }
829 bytes_to_copy = GNUNET_MIN (max, 862 bytes_to_copy = GNUNET_MIN (max,
@@ -832,12 +865,21 @@ mhd_content_cb (void *cls,
832 (SOCKS5_SOCKET_DOWNLOAD_DONE != s5r->state) ) 865 (SOCKS5_SOCKET_DOWNLOAD_DONE != s5r->state) )
833 { 866 {
834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 867 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
835 "Pausing MHD download, no data available\n"); 868 "Pausing MHD download %s%s, no data available\n",
869 s5r->domain,
870 s5r->url);
836 if (NULL != s5r->curl) 871 if (NULL != s5r->curl)
837 { 872 {
838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 873 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
839 "Continuing CURL interaction\n"); 874 "Continuing CURL interaction for %s%s\n",
840 curl_easy_pause (s5r->curl, CURLPAUSE_CONT); 875 s5r->domain,
876 s5r->url);
877 if (GNUNET_YES == s5r->curl_paused)
878 {
879 s5r->curl_paused = GNUNET_NO;
880 curl_easy_pause (s5r->curl,
881 CURLPAUSE_CONT);
882 }
841 curl_download_prepare (); 883 curl_download_prepare ();
842 } 884 }
843 if (GNUNET_NO == s5r->suspended) 885 if (GNUNET_NO == s5r->suspended)
@@ -851,13 +893,17 @@ mhd_content_cb (void *cls,
851 (SOCKS5_SOCKET_DOWNLOAD_DONE == s5r->state) ) 893 (SOCKS5_SOCKET_DOWNLOAD_DONE == s5r->state) )
852 { 894 {
853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 895 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
854 "Completed MHD download\n"); 896 "Completed MHD download %s%s\n",
897 s5r->domain,
898 s5r->url);
855 return MHD_CONTENT_READER_END_OF_STREAM; 899 return MHD_CONTENT_READER_END_OF_STREAM;
856 } 900 }
857 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 901 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
858 "Writing %llu/%llu bytes\n", 902 "Writing %llu/%llu bytes to %s%s\n",
859 (unsigned long long) bytes_to_copy, 903 (unsigned long long) bytes_to_copy,
860 (unsigned long long) s5r->io_len); 904 (unsigned long long) s5r->io_len,
905 s5r->domain,
906 s5r->url);
861 GNUNET_memcpy (buf, 907 GNUNET_memcpy (buf,
862 s5r->io_buf, 908 s5r->io_buf,
863 bytes_to_copy); 909 bytes_to_copy);
@@ -865,10 +911,14 @@ mhd_content_cb (void *cls,
865 &s5r->io_buf[bytes_to_copy], 911 &s5r->io_buf[bytes_to_copy],
866 s5r->io_len - bytes_to_copy); 912 s5r->io_len - bytes_to_copy);
867 s5r->io_len -= bytes_to_copy; 913 s5r->io_len -= bytes_to_copy;
868 if (NULL != s5r->curl) 914 if ( (NULL != s5r->curl) &&
915 (GNUNET_YES == s5r->curl_paused) )
869 { 916 {
870 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 917 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
871 "Continuing CURL interaction\n"); 918 "Continuing CURL interaction for %s%s\n",
919 s5r->domain,
920 s5r->url);
921 s5r->curl_paused = GNUNET_NO;
872 curl_easy_pause (s5r->curl, 922 curl_easy_pause (s5r->curl,
873 CURLPAUSE_CONT); 923 CURLPAUSE_CONT);
874 } 924 }
@@ -911,8 +961,10 @@ check_ssl_certificate (struct Socks5Request *s5r)
911 tlsinfo->backend); 961 tlsinfo->backend);
912 return GNUNET_SYSERR; 962 return GNUNET_SYSERR;
913 } 963 }
914 chainp = gnutls_certificate_get_peers (tlsinfo->internals, &cert_list_size); 964 chainp = gnutls_certificate_get_peers (tlsinfo->internals,
915 if ( (! chainp) || (0 == cert_list_size) ) 965 &cert_list_size);
966 if ( (! chainp) ||
967 (0 == cert_list_size) )
916 return GNUNET_SYSERR; 968 return GNUNET_SYSERR;
917 969
918 size = sizeof (certdn); 970 size = sizeof (certdn);
@@ -1015,9 +1067,10 @@ check_ssl_certificate (struct Socks5Request *s5r)
1015 name))) 1067 name)))
1016 { 1068 {
1017 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1069 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1018 _("TLS certificate subject name (%s) does not match `%s'\n"), 1070 _("TLS certificate subject name (%s) does not match `%s': %d\n"),
1019 certdn, 1071 certdn,
1020 name); 1072 name,
1073 rc);
1021 gnutls_x509_crt_deinit (x509_cert); 1074 gnutls_x509_crt_deinit (x509_cert);
1022 return GNUNET_SYSERR; 1075 return GNUNET_SYSERR;
1023 } 1076 }
@@ -1075,15 +1128,17 @@ curl_check_hdr (void *buffer,
1075 if (GNUNET_OK != check_ssl_certificate (s5r)) 1128 if (GNUNET_OK != check_ssl_certificate (s5r))
1076 return 0; 1129 return 0;
1077 } 1130 }
1078 1131 ndup = GNUNET_strndup (buffer,
1079 ndup = GNUNET_strndup (buffer, bytes); 1132 bytes);
1080 hdr_type = strtok (ndup, ":"); 1133 hdr_type = strtok (ndup,
1134 ":");
1081 if (NULL == hdr_type) 1135 if (NULL == hdr_type)
1082 { 1136 {
1083 GNUNET_free (ndup); 1137 GNUNET_free (ndup);
1084 return bytes; 1138 return bytes;
1085 } 1139 }
1086 hdr_val = strtok (NULL, ""); 1140 hdr_val = strtok (NULL,
1141 "");
1087 if (NULL == hdr_val) 1142 if (NULL == hdr_val)
1088 { 1143 {
1089 GNUNET_free (ndup); 1144 GNUNET_free (ndup);
@@ -1105,7 +1160,9 @@ curl_check_hdr (void *buffer,
1105 domain_matched = GNUNET_NO; /* make sure we match domain at most once */ 1160 domain_matched = GNUNET_NO; /* make sure we match domain at most once */
1106 for (tok = strtok (hdr_val, ";"); NULL != tok; tok = strtok (NULL, ";")) 1161 for (tok = strtok (hdr_val, ";"); NULL != tok; tok = strtok (NULL, ";"))
1107 { 1162 {
1108 if ( (0 == strncasecmp (tok, " domain", strlen (" domain"))) && 1163 if ( (0 == strncasecmp (tok,
1164 " domain",
1165 strlen (" domain"))) &&
1109 (GNUNET_NO == domain_matched) ) 1166 (GNUNET_NO == domain_matched) )
1110 { 1167 {
1111 domain_matched = GNUNET_YES; 1168 domain_matched = GNUNET_YES;
@@ -1113,7 +1170,8 @@ curl_check_hdr (void *buffer,
1113 if (strlen (cookie_domain) < strlen (s5r->leho)) 1170 if (strlen (cookie_domain) < strlen (s5r->leho))
1114 { 1171 {
1115 delta_cdomain = strlen (s5r->leho) - strlen (cookie_domain); 1172 delta_cdomain = strlen (s5r->leho) - strlen (cookie_domain);
1116 if (0 == strcasecmp (cookie_domain, s5r->leho + delta_cdomain)) 1173 if (0 == strcasecmp (cookie_domain,
1174 s5r->leho + delta_cdomain))
1117 { 1175 {
1118 offset += sprintf (new_cookie_hdr + offset, 1176 offset += sprintf (new_cookie_hdr + offset,
1119 " domain=%s;", 1177 " domain=%s;",
@@ -1121,18 +1179,30 @@ curl_check_hdr (void *buffer,
1121 continue; 1179 continue;
1122 } 1180 }
1123 } 1181 }
1124 else if (0 == strcmp (cookie_domain, s5r->leho)) 1182 else if (0 == strcmp (cookie_domain,
1183 s5r->leho))
1125 { 1184 {
1126 offset += sprintf (new_cookie_hdr + offset, 1185 offset += sprintf (new_cookie_hdr + offset,
1127 " domain=%s;", 1186 " domain=%s;",
1128 s5r->domain); 1187 s5r->domain);
1129 continue; 1188 continue;
1130 } 1189 }
1190 else if ( ('.' == cookie_domain[0]) &&
1191 (0 == strcmp (&cookie_domain[1],
1192 s5r->leho)) )
1193 {
1194 offset += sprintf (new_cookie_hdr + offset,
1195 " domain=.%s;",
1196 s5r->domain);
1197 continue;
1198 }
1131 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1199 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1132 _("Cookie domain `%s' supplied by server is invalid\n"), 1200 _("Cookie domain `%s' supplied by server is invalid\n"),
1133 tok); 1201 tok);
1134 } 1202 }
1135 GNUNET_memcpy (new_cookie_hdr + offset, tok, strlen (tok)); 1203 GNUNET_memcpy (new_cookie_hdr + offset,
1204 tok,
1205 strlen (tok));
1136 offset += strlen (tok); 1206 offset += strlen (tok);
1137 new_cookie_hdr[offset++] = ';'; 1207 new_cookie_hdr[offset++] = ';';
1138 } 1208 }
@@ -1140,7 +1210,14 @@ curl_check_hdr (void *buffer,
1140 } 1210 }
1141 1211
1142 new_location = NULL; 1212 new_location = NULL;
1143 if (0 == strcasecmp (MHD_HTTP_HEADER_LOCATION, hdr_type)) 1213 if (0 == strcasecmp (MHD_HTTP_HEADER_TRANSFER_ENCODING,
1214 hdr_type))
1215 {
1216 /* Ignore transfer encoding, set automatically by MHD if required */
1217 goto cleanup;
1218 }
1219 if (0 == strcasecmp (MHD_HTTP_HEADER_LOCATION,
1220 hdr_type))
1144 { 1221 {
1145 char *leho_host; 1222 char *leho_host;
1146 1223
@@ -1184,6 +1261,7 @@ curl_check_hdr (void *buffer,
1184 s5r->header_tail, 1261 s5r->header_tail,
1185 header); 1262 header);
1186 } 1263 }
1264 cleanup:
1187 GNUNET_free (ndup); 1265 GNUNET_free (ndup);
1188 GNUNET_free_non_null (new_cookie_hdr); 1266 GNUNET_free_non_null (new_cookie_hdr);
1189 GNUNET_free_non_null (new_location); 1267 GNUNET_free_non_null (new_location);
@@ -1227,7 +1305,9 @@ create_mhd_response_from_s5r (struct Socks5Request *s5r)
1227 s5r->domain, 1305 s5r->domain,
1228 s5r->url); 1306 s5r->url);
1229 s5r->response_code = resp_code; 1307 s5r->response_code = resp_code;
1230 s5r->response = MHD_create_response_from_callback ((-1 == content_length) ? MHD_SIZE_UNKNOWN : content_length, 1308 s5r->response = MHD_create_response_from_callback ((-1 == content_length)
1309 ? MHD_SIZE_UNKNOWN
1310 : content_length,
1231 IO_BUFFERSIZE, 1311 IO_BUFFERSIZE,
1232 &mhd_content_cb, 1312 &mhd_content_cb,
1233 s5r, 1313 s5r,
@@ -1269,6 +1349,7 @@ create_mhd_response_from_s5r (struct Socks5Request *s5r)
1269 return GNUNET_OK; 1349 return GNUNET_OK;
1270} 1350}
1271 1351
1352
1272/** 1353/**
1273 * Handle response payload data from cURL. Copies it into our `io_buf` to make 1354 * Handle response payload data from cURL. Copies it into our `io_buf` to make
1274 * it available to MHD. 1355 * it available to MHD.
@@ -1288,6 +1369,12 @@ curl_download_cb (void *ptr,
1288 struct Socks5Request *s5r = ctx; 1369 struct Socks5Request *s5r = ctx;
1289 size_t total = size * nmemb; 1370 size_t total = size * nmemb;
1290 1371
1372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1373 "Receiving %ux%u bytes for `%s%s' from cURL\n",
1374 (unsigned int) size,
1375 (unsigned int) nmemb,
1376 s5r->domain,
1377 s5r->url);
1291 if (NULL == s5r->response) 1378 if (NULL == s5r->response)
1292 GNUNET_assert (GNUNET_OK == 1379 GNUNET_assert (GNUNET_OK ==
1293 create_mhd_response_from_s5r (s5r)); 1380 create_mhd_response_from_s5r (s5r));
@@ -1302,6 +1389,7 @@ curl_download_cb (void *ptr,
1302 "Pausing CURL download `%s%s', waiting for UPLOAD to finish\n", 1389 "Pausing CURL download `%s%s', waiting for UPLOAD to finish\n",
1303 s5r->domain, 1390 s5r->domain,
1304 s5r->url); 1391 s5r->url);
1392 s5r->curl_paused = GNUNET_YES;
1305 return CURL_WRITEFUNC_PAUSE; /* not yet ready for data download */ 1393 return CURL_WRITEFUNC_PAUSE; /* not yet ready for data download */
1306 } 1394 }
1307 if (sizeof (s5r->io_buf) - s5r->io_len < total) 1395 if (sizeof (s5r->io_buf) - s5r->io_len < total)
@@ -1313,6 +1401,7 @@ curl_download_cb (void *ptr,
1313 (unsigned long long) sizeof (s5r->io_buf), 1401 (unsigned long long) sizeof (s5r->io_buf),
1314 (unsigned long long) s5r->io_len, 1402 (unsigned long long) s5r->io_len,
1315 (unsigned long long) total); 1403 (unsigned long long) total);
1404 s5r->curl_paused = GNUNET_YES;
1316 return CURL_WRITEFUNC_PAUSE; /* not enough space */ 1405 return CURL_WRITEFUNC_PAUSE; /* not enough space */
1317 } 1406 }
1318 GNUNET_memcpy (&s5r->io_buf[s5r->io_len], 1407 GNUNET_memcpy (&s5r->io_buf[s5r->io_len],
@@ -1367,6 +1456,12 @@ curl_upload_cb (void *buf,
1367 (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) ) 1456 (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) )
1368 { 1457 {
1369 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; 1458 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
1459 if (GNUNET_YES == s5r->curl_paused)
1460 {
1461 s5r->curl_paused = GNUNET_NO;
1462 curl_easy_pause (s5r->curl,
1463 CURLPAUSE_CONT);
1464 }
1370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1371 "Completed CURL UPLOAD %s%s\n", 1466 "Completed CURL UPLOAD %s%s\n",
1372 s5r->domain, 1467 s5r->domain,
@@ -1381,7 +1476,9 @@ curl_upload_cb (void *buf,
1381 } 1476 }
1382 to_copy = GNUNET_MIN (s5r->io_len, 1477 to_copy = GNUNET_MIN (s5r->io_len,
1383 len); 1478 len);
1384 GNUNET_memcpy (buf, s5r->io_buf, to_copy); 1479 GNUNET_memcpy (buf,
1480 s5r->io_buf,
1481 to_copy);
1385 memmove (s5r->io_buf, 1482 memmove (s5r->io_buf,
1386 &s5r->io_buf[to_copy], 1483 &s5r->io_buf[to_copy],
1387 s5r->io_len - to_copy); 1484 s5r->io_len - to_copy);
@@ -1445,20 +1542,28 @@ curl_download_prepare ()
1445 return; 1542 return;
1446 } 1543 }
1447 to = -1; 1544 to = -1;
1448 GNUNET_break (CURLM_OK == curl_multi_timeout (curl_multi, &to)); 1545 GNUNET_break (CURLM_OK ==
1546 curl_multi_timeout (curl_multi,
1547 &to));
1449 if (-1 == to) 1548 if (-1 == to)
1450 rtime = GNUNET_TIME_UNIT_FOREVER_REL; 1549 rtime = GNUNET_TIME_UNIT_FOREVER_REL;
1451 else 1550 else
1452 rtime = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, to); 1551 rtime = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1552 to);
1453 if (-1 != max) 1553 if (-1 != max)
1454 { 1554 {
1455 grs = GNUNET_NETWORK_fdset_create (); 1555 grs = GNUNET_NETWORK_fdset_create ();
1456 gws = GNUNET_NETWORK_fdset_create (); 1556 gws = GNUNET_NETWORK_fdset_create ();
1457 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); 1557 GNUNET_NETWORK_fdset_copy_native (grs,
1458 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); 1558 &rs,
1559 max + 1);
1560 GNUNET_NETWORK_fdset_copy_native (gws,
1561 &ws,
1562 max + 1);
1459 curl_download_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1563 curl_download_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1460 rtime, 1564 rtime,
1461 grs, gws, 1565 grs,
1566 gws,
1462 &curl_task_download, 1567 &curl_task_download,
1463 curl_multi); 1568 curl_multi);
1464 GNUNET_NETWORK_fdset_destroy (gws); 1569 GNUNET_NETWORK_fdset_destroy (gws);
@@ -1495,6 +1600,9 @@ curl_task_download (void *cls)
1495 running = 0; 1600 running = 0;
1496 mret = curl_multi_perform (curl_multi, 1601 mret = curl_multi_perform (curl_multi,
1497 &running); 1602 &running);
1603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1604 "Checking CURL multi status: %d\n",
1605 mret);
1498 while (NULL != (msg = curl_multi_info_read (curl_multi, 1606 while (NULL != (msg = curl_multi_info_read (curl_multi,
1499 &msgnum))) 1607 &msgnum)))
1500 { 1608 {
@@ -1527,7 +1635,12 @@ curl_task_download (void *cls)
1527 GNUNET_assert (GNUNET_OK == 1635 GNUNET_assert (GNUNET_OK ==
1528 create_mhd_response_from_s5r (s5r)); 1636 create_mhd_response_from_s5r (s5r));
1529 } 1637 }
1530 s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE; 1638 s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE;
1639 if (GNUNET_YES == s5r->suspended)
1640 {
1641 MHD_resume_connection (s5r->con);
1642 s5r->suspended = GNUNET_NO;
1643 }
1531 run_mhd_now (s5r->hd); 1644 run_mhd_now (s5r->hd);
1532 break; 1645 break;
1533 default: 1646 default:
@@ -1538,6 +1651,11 @@ curl_task_download (void *cls)
1538 curl_easy_strerror (msg->data.result)); 1651 curl_easy_strerror (msg->data.result));
1539 /* FIXME: indicate error somehow? close MHD connection badly as well? */ 1652 /* FIXME: indicate error somehow? close MHD connection badly as well? */
1540 s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE; 1653 s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE;
1654 if (GNUNET_YES == s5r->suspended)
1655 {
1656 MHD_resume_connection (s5r->con);
1657 s5r->suspended = GNUNET_NO;
1658 }
1541 run_mhd_now (s5r->hd); 1659 run_mhd_now (s5r->hd);
1542 break; 1660 break;
1543 } 1661 }
@@ -1600,13 +1718,10 @@ con_val_iter (void *cls,
1600 struct Socks5Request *s5r = cls; 1718 struct Socks5Request *s5r = cls;
1601 char *hdr; 1719 char *hdr;
1602 1720
1603 if ( (0 == strcasecmp (MHD_HTTP_HEADER_HOST, key)) && 1721 if ( (0 == strcasecmp (MHD_HTTP_HEADER_HOST,
1722 key)) &&
1604 (NULL != s5r->leho) ) 1723 (NULL != s5r->leho) )
1605 value = s5r->leho; 1724 value = s5r->leho;
1606 if (0 == strcasecmp (MHD_HTTP_HEADER_CONTENT_LENGTH, key))
1607 return MHD_YES;
1608 if (0 == strcasecmp (MHD_HTTP_HEADER_ACCEPT_ENCODING, key))
1609 return MHD_YES;
1610 GNUNET_asprintf (&hdr, 1725 GNUNET_asprintf (&hdr,
1611 "%s: %s", 1726 "%s: %s",
1612 key, 1727 key,
@@ -1670,7 +1785,7 @@ create_response (void *cls,
1670 return MHD_NO; 1785 return MHD_NO;
1671 } 1786 }
1672 s5r->con = con; 1787 s5r->con = con;
1673 //Fresh connection. 1788 /* Fresh connection. */
1674 if (SOCKS5_SOCKET_WITH_MHD == s5r->state) 1789 if (SOCKS5_SOCKET_WITH_MHD == s5r->state)
1675 { 1790 {
1676 /* first time here, initialize curl handle */ 1791 /* first time here, initialize curl handle */
@@ -1726,21 +1841,40 @@ create_response (void *cls,
1726 return MHD_queue_response (con, 1841 return MHD_queue_response (con,
1727 MHD_HTTP_INTERNAL_SERVER_ERROR, 1842 MHD_HTTP_INTERNAL_SERVER_ERROR,
1728 curl_failure_response); 1843 curl_failure_response);
1729 curl_easy_setopt (s5r->curl, CURLOPT_HEADERFUNCTION, &curl_check_hdr); 1844 curl_easy_setopt (s5r->curl,
1730 curl_easy_setopt (s5r->curl, CURLOPT_HEADERDATA, s5r); 1845 CURLOPT_HEADERFUNCTION,
1731 curl_easy_setopt (s5r->curl, CURLOPT_FOLLOWLOCATION, 0); 1846 &curl_check_hdr);
1847 curl_easy_setopt (s5r->curl,
1848 CURLOPT_HEADERDATA,
1849 s5r);
1850 curl_easy_setopt (s5r->curl,
1851 CURLOPT_FOLLOWLOCATION,
1852 0);
1732 if (s5r->is_gns) 1853 if (s5r->is_gns)
1733 curl_easy_setopt (s5r->curl, 1854 curl_easy_setopt (s5r->curl,
1734 CURLOPT_IPRESOLVE, 1855 CURLOPT_IPRESOLVE,
1735 CURL_IPRESOLVE_V4); 1856 CURL_IPRESOLVE_V4);
1736 curl_easy_setopt (s5r->curl, CURLOPT_CONNECTTIMEOUT, 600L); 1857 curl_easy_setopt (s5r->curl,
1737 curl_easy_setopt (s5r->curl, CURLOPT_TIMEOUT, 600L); 1858 CURLOPT_CONNECTTIMEOUT,
1738 curl_easy_setopt (s5r->curl, CURLOPT_NOSIGNAL, 1L); 1859 600L);
1739 curl_easy_setopt (s5r->curl, CURLOPT_HTTP_CONTENT_DECODING, 0); 1860 curl_easy_setopt (s5r->curl,
1740 curl_easy_setopt (s5r->curl, CURLOPT_HTTP_TRANSFER_DECODING, 0); 1861 CURLOPT_TIMEOUT,
1741 curl_easy_setopt (s5r->curl, CURLOPT_NOSIGNAL, 1L); 1862 600L);
1742 curl_easy_setopt (s5r->curl, CURLOPT_PRIVATE, s5r); 1863 curl_easy_setopt (s5r->curl,
1743 curl_easy_setopt (s5r->curl, CURLOPT_VERBOSE, 0L); 1864 CURLOPT_NOSIGNAL,
1865 1L);
1866 curl_easy_setopt (s5r->curl,
1867 CURLOPT_HTTP_CONTENT_DECODING,
1868 0);
1869 curl_easy_setopt (s5r->curl,
1870 CURLOPT_NOSIGNAL,
1871 1L);
1872 curl_easy_setopt (s5r->curl,
1873 CURLOPT_PRIVATE,
1874 s5r);
1875 curl_easy_setopt (s5r->curl,
1876 CURLOPT_VERBOSE,
1877 0L);
1744 /** 1878 /**
1745 * Pre-populate cache to resolve Hostname. 1879 * Pre-populate cache to resolve Hostname.
1746 * This is necessary as the DNS name in the CURLOPT_URL is used 1880 * This is necessary as the DNS name in the CURLOPT_URL is used
@@ -1796,37 +1930,131 @@ create_response (void *cls,
1796 MHD_HTTP_METHOD_PUT)) 1930 MHD_HTTP_METHOD_PUT))
1797 { 1931 {
1798 s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED; 1932 s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED;
1799 curl_easy_setopt (s5r->curl, CURLOPT_UPLOAD, 1L); 1933 curl_easy_setopt (s5r->curl,
1800 curl_easy_setopt (s5r->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb); 1934 CURLOPT_UPLOAD,
1801 curl_easy_setopt (s5r->curl, CURLOPT_WRITEDATA, s5r); 1935 1L);
1802 curl_easy_setopt (s5r->curl, CURLOPT_READFUNCTION, &curl_upload_cb); 1936 curl_easy_setopt (s5r->curl,
1803 curl_easy_setopt (s5r->curl, CURLOPT_READDATA, s5r); 1937 CURLOPT_WRITEFUNCTION,
1938 &curl_download_cb);
1939 curl_easy_setopt (s5r->curl,
1940 CURLOPT_WRITEDATA,
1941 s5r);
1942 GNUNET_assert (CURLE_OK ==
1943 curl_easy_setopt (s5r->curl,
1944 CURLOPT_READFUNCTION,
1945 &curl_upload_cb));
1946 curl_easy_setopt (s5r->curl,
1947 CURLOPT_READDATA,
1948 s5r);
1949 {
1950 const char *us;
1951 long upload_size = 0;
1952
1953 us = MHD_lookup_connection_value (con,
1954 MHD_HEADER_KIND,
1955 MHD_HTTP_HEADER_CONTENT_LENGTH);
1956 if ( (1 == sscanf (us,
1957 "%ld",
1958 &upload_size)) &&
1959 (upload_size >= 0) )
1960 {
1961 curl_easy_setopt (s5r->curl,
1962 CURLOPT_INFILESIZE,
1963 upload_size);
1964 }
1965 }
1804 } 1966 }
1805 else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_POST)) 1967 else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_POST))
1806 { 1968 {
1807 s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED; 1969 s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED;
1808 curl_easy_setopt (s5r->curl, CURLOPT_POST, 1L); 1970 curl_easy_setopt (s5r->curl,
1809 curl_easy_setopt (s5r->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb); 1971 CURLOPT_POST,
1810 curl_easy_setopt (s5r->curl, CURLOPT_WRITEDATA, s5r); 1972 1L);
1811 curl_easy_setopt (s5r->curl, CURLOPT_READFUNCTION, &curl_upload_cb); 1973 curl_easy_setopt (s5r->curl,
1812 curl_easy_setopt (s5r->curl, CURLOPT_READDATA, s5r); 1974 CURLOPT_WRITEFUNCTION,
1975 &curl_download_cb);
1976 curl_easy_setopt (s5r->curl,
1977 CURLOPT_WRITEDATA,
1978 s5r);
1979 curl_easy_setopt (s5r->curl,
1980 CURLOPT_READFUNCTION,
1981 &curl_upload_cb);
1982 curl_easy_setopt (s5r->curl,
1983 CURLOPT_READDATA,
1984 s5r);
1985 {
1986 const char *us;
1987 long upload_size;
1988
1989 us = MHD_lookup_connection_value (con,
1990 MHD_HEADER_KIND,
1991 MHD_HTTP_HEADER_CONTENT_LENGTH);
1992 if ( (NULL != us) &&
1993 (1 == sscanf (us,
1994 "%ld",
1995 &upload_size)) &&
1996 (upload_size >= 0) )
1997 {
1998 curl_easy_setopt (s5r->curl,
1999 CURLOPT_INFILESIZE,
2000 upload_size);
2001 } else {
2002 curl_easy_setopt (s5r->curl,
2003 CURLOPT_INFILESIZE,
2004 upload_size);
2005 }
2006 }
1813 } 2007 }
1814 else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_HEAD)) 2008 else if (0 == strcasecmp (meth,
2009 MHD_HTTP_METHOD_HEAD))
1815 { 2010 {
1816 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; 2011 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
1817 curl_easy_setopt (s5r->curl, CURLOPT_NOBODY, 1L); 2012 curl_easy_setopt (s5r->curl,
2013 CURLOPT_NOBODY,
2014 1L);
1818 } 2015 }
1819 else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_OPTIONS)) 2016 else if (0 == strcasecmp (meth,
2017 MHD_HTTP_METHOD_OPTIONS))
1820 { 2018 {
1821 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; 2019 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
1822 curl_easy_setopt (s5r->curl, CURLOPT_CUSTOMREQUEST, "OPTIONS"); 2020 curl_easy_setopt (s5r->curl,
2021 CURLOPT_CUSTOMREQUEST,
2022 "OPTIONS");
2023 curl_easy_setopt (s5r->curl,
2024 CURLOPT_WRITEFUNCTION,
2025 &curl_download_cb);
2026 curl_easy_setopt (s5r->curl,
2027 CURLOPT_WRITEDATA,
2028 s5r);
2029
1823 } 2030 }
1824 else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_GET)) 2031 else if (0 == strcasecmp (meth,
2032 MHD_HTTP_METHOD_GET))
1825 { 2033 {
1826 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; 2034 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
1827 curl_easy_setopt (s5r->curl, CURLOPT_HTTPGET, 1L); 2035 curl_easy_setopt (s5r->curl,
1828 curl_easy_setopt (s5r->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb); 2036 CURLOPT_HTTPGET,
1829 curl_easy_setopt (s5r->curl, CURLOPT_WRITEDATA, s5r); 2037 1L);
2038 curl_easy_setopt (s5r->curl,
2039 CURLOPT_WRITEFUNCTION,
2040 &curl_download_cb);
2041 curl_easy_setopt (s5r->curl,
2042 CURLOPT_WRITEDATA,
2043 s5r);
2044 }
2045 else if (0 == strcasecmp (meth,
2046 MHD_HTTP_METHOD_DELETE))
2047 {
2048 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
2049 curl_easy_setopt (s5r->curl,
2050 CURLOPT_CUSTOMREQUEST,
2051 "DELETE");
2052 curl_easy_setopt (s5r->curl,
2053 CURLOPT_WRITEFUNCTION,
2054 &curl_download_cb);
2055 curl_easy_setopt (s5r->curl,
2056 CURLOPT_WRITEDATA,
2057 s5r);
1830 } 2058 }
1831 else 2059 else
1832 { 2060 {
@@ -1840,31 +2068,47 @@ create_response (void *cls,
1840 2068
1841 if (0 == strcasecmp (ver, MHD_HTTP_VERSION_1_0)) 2069 if (0 == strcasecmp (ver, MHD_HTTP_VERSION_1_0))
1842 { 2070 {
1843 curl_easy_setopt (s5r->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 2071 curl_easy_setopt (s5r->curl,
2072 CURLOPT_HTTP_VERSION,
2073 CURL_HTTP_VERSION_1_0);
1844 } 2074 }
1845 else if (0 == strcasecmp (ver, MHD_HTTP_VERSION_1_1)) 2075 else if (0 == strcasecmp (ver, MHD_HTTP_VERSION_1_1))
1846 { 2076 {
1847 curl_easy_setopt (s5r->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 2077 curl_easy_setopt (s5r->curl,
2078 CURLOPT_HTTP_VERSION,
2079 CURL_HTTP_VERSION_1_1);
1848 } 2080 }
1849 else 2081 else
1850 { 2082 {
1851 curl_easy_setopt (s5r->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_NONE); 2083 curl_easy_setopt (s5r->curl,
2084 CURLOPT_HTTP_VERSION,
2085 CURL_HTTP_VERSION_NONE);
1852 } 2086 }
1853 2087
1854 if (HTTPS_PORT == s5r->port) 2088 if (HTTPS_PORT == s5r->port)
1855 { 2089 {
1856 curl_easy_setopt (s5r->curl, CURLOPT_USE_SSL, CURLUSESSL_ALL); 2090 curl_easy_setopt (s5r->curl,
2091 CURLOPT_USE_SSL,
2092 CURLUSESSL_ALL);
1857 if (NULL != s5r->dane_data) 2093 if (NULL != s5r->dane_data)
1858 curl_easy_setopt (s5r->curl, CURLOPT_SSL_VERIFYPEER, 0L); 2094 curl_easy_setopt (s5r->curl,
2095 CURLOPT_SSL_VERIFYPEER,
2096 0L);
1859 else 2097 else
1860 curl_easy_setopt (s5r->curl, CURLOPT_SSL_VERIFYPEER, 1L); 2098 curl_easy_setopt (s5r->curl,
2099 CURLOPT_SSL_VERIFYPEER,
2100 1L);
1861 /* Disable cURL checking the hostname, as we will check ourselves 2101 /* Disable cURL checking the hostname, as we will check ourselves
1862 as only we have the domain name or the LEHO or the DANE record */ 2102 as only we have the domain name or the LEHO or the DANE record */
1863 curl_easy_setopt (s5r->curl, CURLOPT_SSL_VERIFYHOST, 0L); 2103 curl_easy_setopt (s5r->curl,
2104 CURLOPT_SSL_VERIFYHOST,
2105 0L);
1864 } 2106 }
1865 else 2107 else
1866 { 2108 {
1867 curl_easy_setopt (s5r->curl, CURLOPT_USE_SSL, CURLUSESSL_NONE); 2109 curl_easy_setopt (s5r->curl,
2110 CURLOPT_USE_SSL,
2111 CURLUSESSL_NONE);
1868 } 2112 }
1869 2113
1870 if (CURLM_OK != 2114 if (CURLM_OK !=
@@ -1892,12 +2136,14 @@ create_response (void *cls,
1892 { 2136 {
1893 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1894 "Processing %u bytes UPLOAD\n", 2138 "Processing %u bytes UPLOAD\n",
1895 (unsigned int) *upload_data_size); 2139 (unsigned int) *upload_data_size);
1896 2140
1897 /* FIXME: This must be set or a header with Transfer-Encoding: chunked. Else 2141 /* FIXME: This must be set or a header with Transfer-Encoding: chunked. Else
1898 * upload callback is not called! 2142 * upload callback is not called!
1899 */ 2143 */
1900 curl_easy_setopt (s5r->curl, CURLOPT_POSTFIELDSIZE, *upload_data_size); 2144 curl_easy_setopt (s5r->curl,
2145 CURLOPT_POSTFIELDSIZE,
2146 *upload_data_size);
1901 2147
1902 left = GNUNET_MIN (*upload_data_size, 2148 left = GNUNET_MIN (*upload_data_size,
1903 sizeof (s5r->io_buf) - s5r->io_len); 2149 sizeof (s5r->io_buf) - s5r->io_len);
@@ -1907,8 +2153,12 @@ create_response (void *cls,
1907 s5r->io_len += left; 2153 s5r->io_len += left;
1908 *upload_data_size -= left; 2154 *upload_data_size -= left;
1909 GNUNET_assert (NULL != s5r->curl); 2155 GNUNET_assert (NULL != s5r->curl);
1910 curl_easy_pause (s5r->curl, 2156 if (GNUNET_YES == s5r->curl_paused)
1911 CURLPAUSE_CONT); 2157 {
2158 s5r->curl_paused = GNUNET_NO;
2159 curl_easy_pause (s5r->curl,
2160 CURLPAUSE_CONT);
2161 }
1912 return MHD_YES; 2162 return MHD_YES;
1913 } 2163 }
1914 if (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) 2164 if (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state)
@@ -2286,8 +2536,10 @@ load_file (const char* filename,
2286 uint64_t fsize; 2536 uint64_t fsize;
2287 2537
2288 if (GNUNET_OK != 2538 if (GNUNET_OK !=
2289 GNUNET_DISK_file_size (filename, &fsize, 2539 GNUNET_DISK_file_size (filename,
2290 GNUNET_YES, GNUNET_YES)) 2540 &fsize,
2541 GNUNET_YES,
2542 GNUNET_YES))
2291 return NULL; 2543 return NULL;
2292 if (fsize > MAX_PEM_SIZE) 2544 if (fsize > MAX_PEM_SIZE)
2293 return NULL; 2545 return NULL;
@@ -2319,7 +2571,8 @@ load_key_from_file (gnutls_x509_privkey_t key,
2319 gnutls_datum_t key_data; 2571 gnutls_datum_t key_data;
2320 int ret; 2572 int ret;
2321 2573
2322 key_data.data = load_file (keyfile, &key_data.size); 2574 key_data.data = load_file (keyfile,
2575 &key_data.size);
2323 if (NULL == key_data.data) 2576 if (NULL == key_data.data)
2324 return GNUNET_SYSERR; 2577 return GNUNET_SYSERR;
2325 ret = gnutls_x509_privkey_import (key, &key_data, 2578 ret = gnutls_x509_privkey_import (key, &key_data,
@@ -2349,15 +2602,18 @@ load_cert_from_file (gnutls_x509_crt_t crt,
2349 gnutls_datum_t cert_data; 2602 gnutls_datum_t cert_data;
2350 int ret; 2603 int ret;
2351 2604
2352 cert_data.data = load_file (certfile, &cert_data.size); 2605 cert_data.data = load_file (certfile,
2606 &cert_data.size);
2353 if (NULL == cert_data.data) 2607 if (NULL == cert_data.data)
2354 return GNUNET_SYSERR; 2608 return GNUNET_SYSERR;
2355 ret = gnutls_x509_crt_import (crt, &cert_data, 2609 ret = gnutls_x509_crt_import (crt,
2610 &cert_data,
2356 GNUTLS_X509_FMT_PEM); 2611 GNUTLS_X509_FMT_PEM);
2357 if (GNUTLS_E_SUCCESS != ret) 2612 if (GNUTLS_E_SUCCESS != ret)
2358 { 2613 {
2359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2614 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2360 _("Unable to import certificate %s\n"), certfile); 2615 _("Unable to import certificate from `%s'\n"),
2616 certfile);
2361 } 2617 }
2362 GNUNET_free_non_null (cert_data.data); 2618 GNUNET_free_non_null (cert_data.data);
2363 return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK; 2619 return (GNUTLS_E_SUCCESS != ret) ? GNUNET_SYSERR : GNUNET_OK;
@@ -2387,14 +2643,27 @@ generate_gns_certificate (const char *name)
2387 GNUNET_break (GNUTLS_E_SUCCESS == gnutls_x509_crt_init (&request)); 2643 GNUNET_break (GNUTLS_E_SUCCESS == gnutls_x509_crt_init (&request));
2388 GNUNET_break (GNUTLS_E_SUCCESS == gnutls_x509_crt_set_key (request, proxy_ca.key)); 2644 GNUNET_break (GNUTLS_E_SUCCESS == gnutls_x509_crt_set_key (request, proxy_ca.key));
2389 pgc = GNUNET_new (struct ProxyGNSCertificate); 2645 pgc = GNUNET_new (struct ProxyGNSCertificate);
2390 gnutls_x509_crt_set_dn_by_oid (request, GNUTLS_OID_X520_COUNTRY_NAME, 2646 gnutls_x509_crt_set_dn_by_oid (request,
2391 0, "ZZ", 2); 2647 GNUTLS_OID_X520_COUNTRY_NAME,
2392 gnutls_x509_crt_set_dn_by_oid (request, GNUTLS_OID_X520_ORGANIZATION_NAME, 2648 0,
2393 0, "GNU Name System", 4); 2649 "ZZ",
2394 gnutls_x509_crt_set_dn_by_oid (request, GNUTLS_OID_X520_COMMON_NAME, 2650 strlen ("ZZ"));
2395 0, name, strlen (name)); 2651 gnutls_x509_crt_set_dn_by_oid (request,
2396 GNUNET_break (GNUTLS_E_SUCCESS == gnutls_x509_crt_set_version (request, 3)); 2652 GNUTLS_OID_X520_ORGANIZATION_NAME,
2397 gnutls_rnd (GNUTLS_RND_NONCE, &serial, sizeof (serial)); 2653 0,
2654 "GNU Name System",
2655 strlen ("GNU Name System"));
2656 gnutls_x509_crt_set_dn_by_oid (request,
2657 GNUTLS_OID_X520_COMMON_NAME,
2658 0,
2659 name,
2660 strlen (name));
2661 GNUNET_break (GNUTLS_E_SUCCESS ==
2662 gnutls_x509_crt_set_version (request,
2663 3));
2664 gnutls_rnd (GNUTLS_RND_NONCE,
2665 &serial,
2666 sizeof (serial));
2398 gnutls_x509_crt_set_serial (request, 2667 gnutls_x509_crt_set_serial (request,
2399 &serial, 2668 &serial,
2400 sizeof (serial)); 2669 sizeof (serial));
@@ -2408,15 +2677,21 @@ generate_gns_certificate (const char *name)
2408 etime = mktime (tm_data); 2677 etime = mktime (tm_data);
2409 gnutls_x509_crt_set_expiration_time (request, 2678 gnutls_x509_crt_set_expiration_time (request,
2410 etime); 2679 etime);
2411 gnutls_x509_crt_sign (request, 2680 gnutls_x509_crt_sign2 (request,
2412 proxy_ca.cert, 2681 proxy_ca.cert,
2413 proxy_ca.key); 2682 proxy_ca.key,
2683 GNUTLS_DIG_SHA512,
2684 0);
2414 key_buf_size = sizeof (pgc->key); 2685 key_buf_size = sizeof (pgc->key);
2415 cert_buf_size = sizeof (pgc->cert); 2686 cert_buf_size = sizeof (pgc->cert);
2416 gnutls_x509_crt_export (request, GNUTLS_X509_FMT_PEM, 2687 gnutls_x509_crt_export (request,
2417 pgc->cert, &cert_buf_size); 2688 GNUTLS_X509_FMT_PEM,
2418 gnutls_x509_privkey_export (proxy_ca.key, GNUTLS_X509_FMT_PEM, 2689 pgc->cert,
2419 pgc->key, &key_buf_size); 2690 &cert_buf_size);
2691 gnutls_x509_privkey_export (proxy_ca.key,
2692 GNUTLS_X509_FMT_PEM,
2693 pgc->key,
2694 &key_buf_size);
2420 gnutls_x509_crt_deinit (request); 2695 gnutls_x509_crt_deinit (request);
2421 return pgc; 2696 return pgc;
2422} 2697}
@@ -2755,8 +3030,10 @@ handle_gns_result (void *cls,
2755 } 3030 }
2756 if (GNUNET_YES == got_ip) 3031 if (GNUNET_YES == got_ip)
2757 break; 3032 break;
3033 if (GNUNET_YES == disable_v6)
3034 break;
2758 if (GNUNET_OK != 3035 if (GNUNET_OK !=
2759 GNUNET_NETWORK_test_pf (PF_INET)) 3036 GNUNET_NETWORK_test_pf (PF_INET6))
2760 break; 3037 break;
2761 /* FIXME: allow user to disable IPv6 per configuration option... */ 3038 /* FIXME: allow user to disable IPv6 per configuration option... */
2762 got_ip = GNUNET_YES; 3039 got_ip = GNUNET_YES;
@@ -2857,7 +3134,8 @@ do_s5r_read (void *cls)
2857 s5r->rtask = NULL; 3134 s5r->rtask = NULL;
2858 tc = GNUNET_SCHEDULER_get_task_context (); 3135 tc = GNUNET_SCHEDULER_get_task_context ();
2859 if ( (NULL != tc->read_ready) && 3136 if ( (NULL != tc->read_ready) &&
2860 (GNUNET_NETWORK_fdset_isset (tc->read_ready, s5r->sock)) ) 3137 (GNUNET_NETWORK_fdset_isset (tc->read_ready,
3138 s5r->sock)) )
2861 { 3139 {
2862 rlen = GNUNET_NETWORK_socket_recv (s5r->sock, 3140 rlen = GNUNET_NETWORK_socket_recv (s5r->sock,
2863 &s5r->rbuf[s5r->rbuf_len], 3141 &s5r->rbuf[s5r->rbuf_len],
@@ -2983,7 +3261,8 @@ do_s5r_read (void *cls)
2983 s5r->domain = GNUNET_strndup (dom_name, 3261 s5r->domain = GNUNET_strndup (dom_name,
2984 *dom_len); 3262 *dom_len);
2985 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2986 "Requested connection is to %s:%d\n", 3264 "Requested connection is to http%s://%s:%d\n",
3265 (HTTPS_PORT == s5r->port) ? "s" : "",
2987 s5r->domain, 3266 s5r->domain,
2988 ntohs (*port)); 3267 ntohs (*port));
2989 s5r->state = SOCKS5_RESOLVING; 3268 s5r->state = SOCKS5_RESOLVING;
@@ -3054,17 +3333,22 @@ do_accept (void *cls)
3054 if (lsock == lsock4) 3333 if (lsock == lsock4)
3055 ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 3334 ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
3056 lsock, 3335 lsock,
3057 &do_accept, lsock); 3336 &do_accept,
3337 lsock);
3058 else if (lsock == lsock6) 3338 else if (lsock == lsock6)
3059 ltask6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 3339 ltask6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
3060 lsock, 3340 lsock,
3061 &do_accept, lsock); 3341 &do_accept,
3342 lsock);
3062 else 3343 else
3063 GNUNET_assert (0); 3344 GNUNET_assert (0);
3064 s = GNUNET_NETWORK_socket_accept (lsock, NULL, NULL); 3345 s = GNUNET_NETWORK_socket_accept (lsock,
3346 NULL,
3347 NULL);
3065 if (NULL == s) 3348 if (NULL == s)
3066 { 3349 {
3067 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "accept"); 3350 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
3351 "accept");
3068 return; 3352 return;
3069 } 3353 }
3070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -3077,7 +3361,8 @@ do_accept (void *cls)
3077 s5r->state = SOCKS5_INIT; 3361 s5r->state = SOCKS5_INIT;
3078 s5r->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 3362 s5r->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
3079 s5r->sock, 3363 s5r->sock,
3080 &do_s5r_read, s5r); 3364 &do_s5r_read,
3365 s5r);
3081} 3366}
3082 3367
3083 3368
@@ -3174,7 +3459,8 @@ bind_v4 ()
3174 if (NULL == ls) 3459 if (NULL == ls)
3175 return NULL; 3460 return NULL;
3176 if (GNUNET_OK != 3461 if (GNUNET_OK !=
3177 GNUNET_NETWORK_socket_bind (ls, (const struct sockaddr *) &sa4, 3462 GNUNET_NETWORK_socket_bind (ls,
3463 (const struct sockaddr *) &sa4,
3178 sizeof (sa4))) 3464 sizeof (sa4)))
3179 { 3465 {
3180 eno = errno; 3466 eno = errno;
@@ -3210,7 +3496,8 @@ bind_v6 ()
3210 if (NULL == ls) 3496 if (NULL == ls)
3211 return NULL; 3497 return NULL;
3212 if (GNUNET_OK != 3498 if (GNUNET_OK !=
3213 GNUNET_NETWORK_socket_bind (ls, (const struct sockaddr *) &sa6, 3499 GNUNET_NETWORK_socket_bind (ls,
3500 (const struct sockaddr *) &sa6,
3214 sizeof (sa6))) 3501 sizeof (sa6)))
3215 { 3502 {
3216 eno = errno; 3503 eno = errno;
@@ -3265,7 +3552,8 @@ run (void *cls,
3265 cafile = cafile_cfg; 3552 cafile = cafile_cfg;
3266 } 3553 }
3267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3268 "Using %s as CA\n", cafile); 3555 "Using `%s' as CA\n",
3556 cafile);
3269 3557
3270 gnutls_global_init (); 3558 gnutls_global_init ();
3271 gnutls_x509_crt_init (&proxy_ca.cert); 3559 gnutls_x509_crt_init (&proxy_ca.cert);
@@ -3365,8 +3653,8 @@ run (void *cls,
3365 return; 3653 return;
3366 } 3654 }
3367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3368 "Proxy listens on port %llu\n", 3656 "Proxy listens on port %u\n",
3369 port); 3657 (unsigned int) port);
3370 3658
3371 /* start MHD daemon for HTTP */ 3659 /* start MHD daemon for HTTP */
3372 hd = GNUNET_new (struct MhdHttpList); 3660 hd = GNUNET_new (struct MhdHttpList);
@@ -3400,19 +3688,24 @@ run (void *cls,
3400 * @return 0 ok, 1 on error 3688 * @return 0 ok, 1 on error
3401 */ 3689 */
3402int 3690int
3403main (int argc, char *const *argv) 3691main (int argc,
3692 char *const *argv)
3404{ 3693{
3405 struct GNUNET_GETOPT_CommandLineOption options[] = { 3694 struct GNUNET_GETOPT_CommandLineOption options[] = {
3406 GNUNET_GETOPT_option_ulong ('p', 3695 GNUNET_GETOPT_option_uint16 ('p',
3407 "port", 3696 "port",
3408 NULL, 3697 NULL,
3409 gettext_noop ("listen on specified port (default: 7777)"), 3698 gettext_noop ("listen on specified port (default: 7777)"),
3410 &port), 3699 &port),
3411 GNUNET_GETOPT_option_string ('a', 3700 GNUNET_GETOPT_option_string ('a',
3412 "authority", 3701 "authority",
3413 NULL, 3702 NULL,
3414 gettext_noop ("pem file to use as CA"), 3703 gettext_noop ("pem file to use as CA"),
3415 &cafile_opt), 3704 &cafile_opt),
3705 GNUNET_GETOPT_option_flag ('6',
3706 "disable-ivp6",
3707 gettext_noop ("disable use of IPv6"),
3708 &disable_v6),
3416 3709
3417 GNUNET_GETOPT_OPTION_END 3710 GNUNET_GETOPT_OPTION_END
3418 }; 3711 };
@@ -3421,8 +3714,9 @@ main (int argc, char *const *argv)
3421 "</head><body>cURL fail</body></html>"; 3714 "</head><body>cURL fail</body></html>";
3422 int ret; 3715 int ret;
3423 3716
3424 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, 3717 if (GNUNET_OK !=
3425 &argc, &argv)) 3718 GNUNET_STRINGS_get_utf8_args (argc, argv,
3719 &argc, &argv))
3426 return 2; 3720 return 2;
3427 GNUNET_log_setup ("gnunet-gns-proxy", 3721 GNUNET_log_setup ("gnunet-gns-proxy",
3428 "WARNING", 3722 "WARNING",
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
index 34f6e2c82..463348ed3 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012-2013, 2017-2018 GNUnet e.V. 3 Copyright (C) 2012-2013, 2017-2018 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gnunet-gns.c 19 * @file gnunet-gns.c
@@ -67,8 +65,9 @@ static struct GNUNET_GNS_LookupWithTldRequest *lr;
67/** 65/**
68 * Global return value. 66 * Global return value.
69 * 0 on success (default), 67 * 0 on success (default),
70 * 1 on internal failures, 2 on launch failure, 68 * 1 on internal failures
71 * 3 if the name is not a GNS-supported TLD, 69 * 2 on launch failure,
70 * 4 if the name is not a GNS-supported TLD,
72 */ 71 */
73static int global_ret; 72static int global_ret;
74 73
@@ -116,7 +115,7 @@ process_lookup_result (void *cls,
116 lr = NULL; 115 lr = NULL;
117 if (GNUNET_NO == was_gns) 116 if (GNUNET_NO == was_gns)
118 { 117 {
119 global_ret = 3; 118 global_ret = 4; /* not for GNS */
120 GNUNET_SCHEDULER_shutdown (); 119 GNUNET_SCHEDULER_shutdown ();
121 return; 120 return;
122 } 121 }
@@ -185,7 +184,6 @@ run (void *cls,
185 global_ret = 2; 184 global_ret = 2;
186 return; 185 return;
187 } 186 }
188
189 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 187 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
190 NULL); 188 NULL);
191 189
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index c376ddfcc..71e744733 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011-2018 GNUnet e.V. 3 Copyright (C) 2011-2018 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gns/gnunet-service-gns.c 19 * @file gns/gnunet-service-gns.c
@@ -296,7 +294,6 @@ client_disconnect_cb (void *cls,
296 clh); 294 clh);
297 GNUNET_free (clh); 295 GNUNET_free (clh);
298 } 296 }
299
300 GNUNET_free (gc); 297 GNUNET_free (gc);
301} 298}
302 299
@@ -335,31 +332,47 @@ client_connect_cb (void *cls,
335 * @param rd the record data 332 * @param rd the record data
336 */ 333 */
337static void 334static void
338send_lookup_response (void* cls, 335send_lookup_response (void *cls,
339 uint32_t rd_count, 336 uint32_t rd_count,
340 const struct GNUNET_GNSRECORD_Data *rd) 337 const struct GNUNET_GNSRECORD_Data *rd)
341{ 338{
342 struct ClientLookupHandle *clh = cls; 339 struct ClientLookupHandle *clh = cls;
340 struct GnsClient *gc = clh->gc;
343 struct GNUNET_MQ_Envelope *env; 341 struct GNUNET_MQ_Envelope *env;
344 struct LookupResultMessage *rmsg; 342 struct LookupResultMessage *rmsg;
345 size_t len; 343 ssize_t len;
346 344
347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
348 "Sending LOOKUP_RESULT message with %u results\n", 346 "Sending LOOKUP_RESULT message with %u results\n",
349 (unsigned int) rd_count); 347 (unsigned int) rd_count);
350 348 len = GNUNET_GNSRECORD_records_get_size (rd_count,
351 len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); 349 rd);
350 if (len < 0)
351 {
352 GNUNET_break (0);
353 GNUNET_SERVICE_client_drop (gc->client);
354 return;
355 }
356 if (len > UINT16_MAX - sizeof (*rmsg))
357 {
358 GNUNET_break (0);
359 GNUNET_SERVICE_client_drop (gc->client);
360 return;
361 }
352 env = GNUNET_MQ_msg_extra (rmsg, 362 env = GNUNET_MQ_msg_extra (rmsg,
353 len, 363 len,
354 GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT); 364 GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT);
355 rmsg->id = clh->request_id; 365 rmsg->id = clh->request_id;
356 rmsg->rd_count = htonl (rd_count); 366 rmsg->rd_count = htonl (rd_count);
357 GNUNET_GNSRECORD_records_serialize (rd_count, rd, len, 367 GNUNET_assert (len ==
358 (char*) &rmsg[1]); 368 GNUNET_GNSRECORD_records_serialize (rd_count,
359 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(clh->gc->client), 369 rd,
370 len,
371 (char*) &rmsg[1]));
372 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (gc->client),
360 env); 373 env);
361 GNUNET_CONTAINER_DLL_remove (clh->gc->clh_head, 374 GNUNET_CONTAINER_DLL_remove (gc->clh_head,
362 clh->gc->clh_tail, 375 gc->clh_tail,
363 clh); 376 clh);
364 GNUNET_free (clh); 377 GNUNET_free (clh);
365 GNUNET_STATISTICS_update (statistics, 378 GNUNET_STATISTICS_update (statistics,
@@ -428,7 +441,6 @@ handle_lookup (void *cls,
428 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
429 "Received LOOKUP `%s' message\n", 442 "Received LOOKUP `%s' message\n",
430 name); 443 name);
431
432 clh = GNUNET_new (struct ClientLookupHandle); 444 clh = GNUNET_new (struct ClientLookupHandle);
433 GNUNET_CONTAINER_DLL_insert (gc->clh_head, 445 GNUNET_CONTAINER_DLL_insert (gc->clh_head,
434 gc->clh_tail, 446 gc->clh_tail,
diff --git a/src/gns/gnunet-service-gns.h b/src/gns/gnunet-service-gns.h
index 439bad881..952c7178f 100644
--- a/src/gns/gnunet-service-gns.h
+++ b/src/gns/gnunet-service-gns.h
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2018 GNUnet e.V. 3 Copyright (C) 2018 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gns/gnunet-service-gns.h 19 * @file gns/gnunet-service-gns.h
diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c
index 0425e9500..42f3e1514 100644
--- a/src/gns/gnunet-service-gns_interceptor.c
+++ b/src/gns/gnunet-service-gns_interceptor.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009-2013 GNUnet e.V. 3 Copyright (C) 2009-2013 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gns/gnunet-service-gns_interceptor.c 19 * @file gns/gnunet-service-gns_interceptor.c
@@ -105,7 +103,7 @@ reply_to_dns (void *cls, uint32_t rd_count,
105 unsigned int num_answers; 103 unsigned int num_answers;
106 unsigned int skip_answers; 104 unsigned int skip_answers;
107 unsigned int skip_additional; 105 unsigned int skip_additional;
108 size_t off; 106 size_t off = 0;
109 107
110 /* Put records in the DNS packet */ 108 /* Put records in the DNS packet */
111 num_answers = 0; 109 num_answers = 0;
diff --git a/src/gns/gnunet-service-gns_interceptor.h b/src/gns/gnunet-service-gns_interceptor.h
index ff54b7b6e..460665cf0 100644
--- a/src/gns/gnunet-service-gns_interceptor.h
+++ b/src/gns/gnunet-service-gns_interceptor.h
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010, 2011, 2012 GNUnet e.V. 3 Copyright (C) 2009, 2010, 2011, 2012 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gns/gnunet-service-gns_interceptor.h 19 * @file gns/gnunet-service-gns_interceptor.h
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 92e03bc69..67960ef97 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011-2013 GNUnet e.V. 3 Copyright (C) 2011-2013 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20 18
21/** 19/**
@@ -60,7 +58,7 @@
60/** 58/**
61 * DHT replication level 59 * DHT replication level
62 */ 60 */
63#define DHT_GNS_REPLICATION_LEVEL 5 61#define DHT_GNS_REPLICATION_LEVEL 10
64 62
65/** 63/**
66 * How deep do we allow recursions to go before we abort? 64 * How deep do we allow recursions to go before we abort?
@@ -109,6 +107,11 @@ struct Gns2DnsPending
109 * Handle for DNS resolution of the DNS nameserver. 107 * Handle for DNS resolution of the DNS nameserver.
110 */ 108 */
111 struct GNUNET_RESOLVER_RequestHandle *dns_rh; 109 struct GNUNET_RESOLVER_RequestHandle *dns_rh;
110
111 /**
112 * How many results did we get?
113 */
114 unsigned int num_results;
112}; 115};
113 116
114 117
@@ -146,16 +149,6 @@ struct AuthorityChain
146 char *label; 149 char *label;
147 150
148 /** 151 /**
149 * label/name suggested for shortening to the authority
150 */
151 char *suggested_shortening_label;
152
153 /**
154 * Do we already try to shorten this authority?
155 */
156 int shortening_started;
157
158 /**
159 * #GNUNET_YES if the authority was a GNS authority, 152 * #GNUNET_YES if the authority was a GNS authority,
160 * #GNUNET_NO if the authority was a DNS authority. 153 * #GNUNET_NO if the authority was a DNS authority.
161 */ 154 */
@@ -285,7 +278,7 @@ struct VpnContext
285 /** 278 /**
286 * Number of bytes in @e rd_data. 279 * Number of bytes in @e rd_data.
287 */ 280 */
288 size_t rd_data_size; 281 ssize_t rd_data_size;
289}; 282};
290 283
291 284
@@ -378,6 +371,12 @@ struct GNS_ResolverHandle
378 char *name; 371 char *name;
379 372
380 /** 373 /**
374 * Legacy Hostname to use if we encountered GNS2DNS record
375 * and thus can deduct the LEHO from that transition.
376 */
377 char *leho;
378
379 /**
381 * DLL of results we got from DNS. 380 * DLL of results we got from DNS.
382 */ 381 */
383 struct DnsResult *dns_result_head; 382 struct DnsResult *dns_result_head;
@@ -813,7 +812,9 @@ add_dns_result (struct GNS_ResolverHandle *rh,
813 res->data_size = data_size; 812 res->data_size = data_size;
814 res->record_type = record_type; 813 res->record_type = record_type;
815 res->data = &res[1]; 814 res->data = &res[1];
816 GNUNET_memcpy (&res[1], data, data_size); 815 GNUNET_memcpy (&res[1],
816 data,
817 data_size);
817 GNUNET_CONTAINER_DLL_insert (rh->dns_result_head, 818 GNUNET_CONTAINER_DLL_insert (rh->dns_result_head,
818 rh->dns_result_tail, 819 rh->dns_result_tail,
819 res); 820 res);
@@ -939,41 +940,57 @@ dns_result_parser (void *cls,
939 if ( (p->num_answers > 0) && 940 if ( (p->num_answers > 0) &&
940 (GNUNET_DNSPARSER_TYPE_CNAME == p->answers[0].type) && 941 (GNUNET_DNSPARSER_TYPE_CNAME == p->answers[0].type) &&
941 (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type) ) 942 (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type) )
942 { 943 {
943 int af; 944 int af;
944 945
945 GNUNET_free (rh->name); 946 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
946 rh->name = GNUNET_strdup (p->answers[0].data.hostname); 947 "Got CNAME `%s' from DNS for `%s'\n",
947 rh->name_resolution_pos = strlen (rh->name); 948 p->answers[0].data.hostname,
948 switch (rh->record_type) 949 rh->name);
949 { 950 if (NULL != rh->std_resolve)
950 case GNUNET_DNSPARSER_TYPE_A: 951 {
951 af = AF_INET; 952 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
952 break; 953 "Multiple CNAME results from DNS resolving `%s'! Not really allowed...\n",
953 case GNUNET_DNSPARSER_TYPE_AAAA:
954 af = AF_INET6;
955 break;
956 default:
957 af = AF_UNSPEC;
958 break;
959 }
960 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
961 "Doing standard DNS lookup for `%s'\n",
962 rh->name); 954 rh->name);
963 rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name, 955 GNUNET_RESOLVER_request_cancel (rh->std_resolve);
964 af,
965 DNS_LOOKUP_TIMEOUT,
966 &handle_dns_result,
967 rh);
968 GNUNET_DNSPARSER_free_packet (p);
969 return;
970 } 956 }
957 GNUNET_free (rh->name);
958 rh->name = GNUNET_strdup (p->answers[0].data.hostname);
959 rh->name_resolution_pos = strlen (rh->name);
960 switch (rh->record_type)
961 {
962 case GNUNET_DNSPARSER_TYPE_A:
963 af = AF_INET;
964 break;
965 case GNUNET_DNSPARSER_TYPE_AAAA:
966 af = AF_INET6;
967 break;
968 default:
969 af = AF_UNSPEC;
970 break;
971 }
972 if (NULL != rh->leho)
973 add_dns_result (rh,
974 GNUNET_TIME_UNIT_HOURS.rel_value_us,
975 GNUNET_GNSRECORD_TYPE_LEHO,
976 strlen (rh->leho),
977 rh->leho);
978 rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name,
979 af,
980 DNS_LOOKUP_TIMEOUT,
981 &handle_dns_result,
982 rh);
983 GNUNET_DNSPARSER_free_packet (p);
984 GNUNET_DNSSTUB_resolve_cancel (rh->dns_request);
985 rh->dns_request = NULL;
986 return;
987 }
971 988
972 /* convert from (parsed) DNS to (binary) GNS format! */ 989 /* convert from (parsed) DNS to (binary) GNS format! */
973 rd_count = p->num_answers + p->num_authority_records + p->num_additional_records; 990 rd_count = p->num_answers + p->num_authority_records + p->num_additional_records;
974 { 991 {
975 struct GNUNET_GNSRECORD_Data rd[rd_count]; 992 struct GNUNET_GNSRECORD_Data rd[rd_count + 1]; /* +1 for LEHO */
976 unsigned int skip; 993 int skip;
977 char buf[UINT16_MAX]; 994 char buf[UINT16_MAX];
978 size_t buf_off; 995 size_t buf_off;
979 size_t buf_start; 996 size_t buf_start;
@@ -1097,14 +1114,28 @@ dns_result_parser (void *cls,
1097 skip++; 1114 skip++;
1098 continue; 1115 continue;
1099 } 1116 }
1117 } /* end of for all records in answer */
1118 if (NULL != rh->leho)
1119 {
1120 rd[rd_count - skip].record_type = GNUNET_GNSRECORD_TYPE_LEHO;
1121 rd[rd_count - skip].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1122 rd[rd_count - skip].expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us;
1123 rd[rd_count - skip].data = rh->leho;
1124 rd[rd_count - skip].data_size = strlen (rh->leho);
1125 skip--; /* skip one LESS */
1126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1127 "Adding LEHO %s\n",
1128 rh->leho);
1100 } 1129 }
1101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1102 "Returning DNS response for `%s' with %u answers\n", 1131 "Returning DNS response for `%s' with %u answers\n",
1103 rh->ac_tail->label, 1132 rh->ac_tail->label,
1104 (unsigned int) p->num_answers); 1133 (unsigned int) (rd_count - skip));
1105 rh->proc (rh->proc_cls, 1134 rh->proc (rh->proc_cls,
1106 rd_count - skip, 1135 rd_count - skip,
1107 rd); 1136 rd);
1137 GNUNET_DNSSTUB_resolve_cancel (rh->dns_request);
1138 rh->dns_request = NULL;
1108 } 1139 }
1109 GNUNET_DNSPARSER_free_packet (p); 1140 GNUNET_DNSPARSER_free_packet (p);
1110 if (NULL != rh->task_id) 1141 if (NULL != rh->task_id)
@@ -1168,6 +1199,7 @@ recursive_dns_resolution (struct GNS_ResolverHandle *rh)
1168 rh->original_dns_id = p->id; 1199 rh->original_dns_id = p->id;
1169 GNUNET_assert (NULL != ac->authority_info.dns_authority.dns_handle); 1200 GNUNET_assert (NULL != ac->authority_info.dns_authority.dns_handle);
1170 GNUNET_assert (NULL == rh->dns_request); 1201 GNUNET_assert (NULL == rh->dns_request);
1202 rh->leho = GNUNET_strdup (ac->label);
1171 rh->dns_request = GNUNET_DNSSTUB_resolve (ac->authority_info.dns_authority.dns_handle, 1203 rh->dns_request = GNUNET_DNSSTUB_resolve (ac->authority_info.dns_authority.dns_handle,
1172 dns_request, 1204 dns_request,
1173 dns_request_length, 1205 dns_request_length,
@@ -1228,8 +1260,6 @@ handle_gns_cname_result (struct GNS_ResolverHandle *rh,
1228 ac->gns_authority = GNUNET_YES; 1260 ac->gns_authority = GNUNET_YES;
1229 ac->authority_info.gns_authority = rh->ac_tail->authority_info.gns_authority; 1261 ac->authority_info.gns_authority = rh->ac_tail->authority_info.gns_authority;
1230 ac->label = resolver_lookup_get_next_label (rh); 1262 ac->label = resolver_lookup_get_next_label (rh);
1231 ac->suggested_shortening_label = NULL;
1232 ac->shortening_started = GNUNET_NO;
1233 /* add AC to tail */ 1263 /* add AC to tail */
1234 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, 1264 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
1235 rh->ac_tail, 1265 rh->ac_tail,
@@ -1238,6 +1268,17 @@ handle_gns_cname_result (struct GNS_ResolverHandle *rh,
1238 rh); 1268 rh);
1239 return; 1269 return;
1240 } 1270 }
1271 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1272 "Got CNAME `%s' from GNS for `%s'\n",
1273 cname,
1274 rh->name);
1275 if (NULL != rh->std_resolve)
1276 {
1277 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1278 "Multiple CNAME results from GNS resolving `%s'! Not really allowed...\n",
1279 rh->name);
1280 GNUNET_RESOLVER_request_cancel (rh->std_resolve);
1281 }
1241 /* name is absolute, go to DNS */ 1282 /* name is absolute, go to DNS */
1242 GNUNET_free (rh->name); 1283 GNUNET_free (rh->name);
1243 rh->name = GNUNET_strdup (cname); 1284 rh->name = GNUNET_strdup (cname);
@@ -1305,7 +1346,7 @@ vpn_allocation_cb (void *cls,
1305 vpn_ctx->vpn_request = NULL; 1346 vpn_ctx->vpn_request = NULL;
1306 rh->vpn_ctx = NULL; 1347 rh->vpn_ctx = NULL;
1307 GNUNET_assert (GNUNET_OK == 1348 GNUNET_assert (GNUNET_OK ==
1308 GNUNET_GNSRECORD_records_deserialize (vpn_ctx->rd_data_size, 1349 GNUNET_GNSRECORD_records_deserialize ((size_t) vpn_ctx->rd_data_size,
1309 vpn_ctx->rd_data, 1350 vpn_ctx->rd_data,
1310 vpn_ctx->rd_count, 1351 vpn_ctx->rd_count,
1311 rd)); 1352 rd));
@@ -1336,6 +1377,10 @@ vpn_allocation_cb (void *cls,
1336 } 1377 }
1337 } 1378 }
1338 GNUNET_assert (i < vpn_ctx->rd_count); 1379 GNUNET_assert (i < vpn_ctx->rd_count);
1380 if (0 == vpn_ctx->rd_count)
1381 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1382 _("VPN returned empty result for `%s'\n"),
1383 rh->name);
1339 handle_gns_resolution_result (rh, 1384 handle_gns_resolution_result (rh,
1340 vpn_ctx->rd_count, 1385 vpn_ctx->rd_count,
1341 rd); 1386 rd);
@@ -1494,26 +1539,48 @@ handle_gns2dns_ip (void *cls,
1494{ 1539{
1495 struct Gns2DnsPending *gp = cls; 1540 struct Gns2DnsPending *gp = cls;
1496 struct AuthorityChain *ac = gp->ac; 1541 struct AuthorityChain *ac = gp->ac;
1542 struct sockaddr_storage ss;
1543 struct sockaddr_in *v4;
1544 struct sockaddr_in6 *v6;
1497 1545
1498 GNUNET_RESOLVER_request_cancel (gp->dns_rh);
1499 GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head,
1500 ac->authority_info.dns_authority.gp_tail,
1501 gp);
1502 GNUNET_free (gp);
1503 if (NULL == addr) 1546 if (NULL == addr)
1504 { 1547 {
1505 /* DNS resolution failed */ 1548 /* DNS resolution finished */
1506 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1549 if (0 == gp->num_results)
1507 "Failed to use DNS to resolve name of DNS resolver\n"); 1550 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1551 "Failed to use DNS to resolve name of DNS resolver\n");
1552 GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head,
1553 ac->authority_info.dns_authority.gp_tail,
1554 gp);
1555 GNUNET_free (gp);
1556 continue_with_gns2dns (ac);
1557 return;
1508 } 1558 }
1509 else 1559 GNUNET_memcpy (&ss,
1560 addr,
1561 addrlen);
1562 switch (ss.ss_family)
1510 { 1563 {
1511 if (GNUNET_OK == 1564 case AF_INET:
1512 GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle, 1565 v4 = (struct sockaddr_in *) &ss;
1513 addr)) 1566 v4->sin_port = htons (53);
1514 ac->authority_info.dns_authority.found = GNUNET_YES; 1567 gp->num_results++;
1568 break;
1569 case AF_INET6:
1570 v6 = (struct sockaddr_in6 *) &ss;
1571 v6->sin6_port = htons (53);
1572 gp->num_results++;
1573 break;
1574 default:
1575 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1576 "Unsupported AF %d\n",
1577 ss.ss_family);
1578 return;
1515 } 1579 }
1516 continue_with_gns2dns (ac); 1580 if (GNUNET_OK ==
1581 GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle,
1582 (struct sockaddr *) &ss))
1583 ac->authority_info.dns_authority.found = GNUNET_YES;
1517} 1584}
1518 1585
1519 1586
@@ -1572,8 +1639,6 @@ recursive_pkey_resolution (struct GNS_ResolverHandle *rh,
1572 ac = GNUNET_new (struct AuthorityChain); 1639 ac = GNUNET_new (struct AuthorityChain);
1573 ac->rh = rh; 1640 ac->rh = rh;
1574 ac->gns_authority = GNUNET_YES; 1641 ac->gns_authority = GNUNET_YES;
1575 ac->suggested_shortening_label = NULL;
1576 ac->shortening_started = GNUNET_NO;
1577 GNUNET_memcpy (&ac->authority_info.gns_authority, 1642 GNUNET_memcpy (&ac->authority_info.gns_authority,
1578 rd->data, 1643 rd->data,
1579 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); 1644 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
@@ -1620,6 +1685,8 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh,
1620 size_t off; 1685 size_t off;
1621 struct Gns2DnsPending *gp; 1686 struct Gns2DnsPending *gp;
1622 struct GNUNET_CRYPTO_EcdsaPublicKey zone; 1687 struct GNUNET_CRYPTO_EcdsaPublicKey zone;
1688 struct sockaddr_in v4;
1689 struct sockaddr_in6 v6;
1623 1690
1624 if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type) 1691 if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type)
1625 continue; 1692 continue;
@@ -1661,10 +1728,16 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh,
1661 } 1728 }
1662 1729
1663 /* check if 'ip' is already an IPv4/IPv6 address */ 1730 /* check if 'ip' is already an IPv4/IPv6 address */
1664 if (GNUNET_OK == 1731 if ( (1 == inet_pton (AF_INET,
1665 GNUNET_DNSSTUB_add_dns_ip (ac->authority_info.dns_authority.dns_handle, 1732 ip,
1666 ip)) 1733 &v4)) ||
1734 (1 == inet_pton (AF_INET6,
1735 ip,
1736 &v6)) )
1667 { 1737 {
1738 GNUNET_break (GNUNET_OK ==
1739 GNUNET_DNSSTUB_add_dns_ip (ac->authority_info.dns_authority.dns_handle,
1740 ip));
1668 ac->authority_info.dns_authority.found = GNUNET_YES; 1741 ac->authority_info.dns_authority.found = GNUNET_YES;
1669 GNUNET_free (ip); 1742 GNUNET_free (ip);
1670 continue; 1743 continue;
@@ -1769,7 +1842,6 @@ handle_gns_resolution_result (void *cls,
1769 const struct GNUNET_GNSRECORD_Data *rd) 1842 const struct GNUNET_GNSRECORD_Data *rd)
1770{ 1843{
1771 struct GNS_ResolverHandle *rh = cls; 1844 struct GNS_ResolverHandle *rh = cls;
1772 struct AuthorityChain *shorten_ac;
1773 char *cname; 1845 char *cname;
1774 struct VpnContext *vpn_ctx; 1846 struct VpnContext *vpn_ctx;
1775 const struct GNUNET_TUN_GnsVpnRecord *vpn; 1847 const struct GNUNET_TUN_GnsVpnRecord *vpn;
@@ -1791,7 +1863,8 @@ handle_gns_resolution_result (void *cls,
1791 if (0 == rd_count) 1863 if (0 == rd_count)
1792 { 1864 {
1793 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1865 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1794 _("GNS lookup failed (zero records found)\n")); 1866 _("GNS lookup failed (zero records found for `%s')\n"),
1867 rh->name);
1795 fail_resolution (rh); 1868 fail_resolution (rh);
1796 return; 1869 return;
1797 } 1870 }
@@ -1860,13 +1933,20 @@ handle_gns_resolution_result (void *cls,
1860 vpn_ctx->rh = rh; 1933 vpn_ctx->rh = rh;
1861 vpn_ctx->rd_data_size = GNUNET_GNSRECORD_records_get_size (rd_count, 1934 vpn_ctx->rd_data_size = GNUNET_GNSRECORD_records_get_size (rd_count,
1862 rd); 1935 rd);
1863 vpn_ctx->rd_data = GNUNET_malloc (vpn_ctx->rd_data_size); 1936 if (vpn_ctx->rd_data_size < 0)
1937 {
1938 GNUNET_break_op (0);
1939 GNUNET_free (vpn_ctx);
1940 fail_resolution (rh);
1941 return;
1942 }
1943 vpn_ctx->rd_data = GNUNET_malloc ((size_t) vpn_ctx->rd_data_size);
1864 vpn_ctx->rd_count = rd_count; 1944 vpn_ctx->rd_count = rd_count;
1865 GNUNET_assert (vpn_ctx->rd_data_size == 1945 GNUNET_assert (vpn_ctx->rd_data_size ==
1866 (size_t) GNUNET_GNSRECORD_records_serialize (rd_count, 1946 GNUNET_GNSRECORD_records_serialize (rd_count,
1867 rd, 1947 rd,
1868 vpn_ctx->rd_data_size, 1948 (size_t) vpn_ctx->rd_data_size,
1869 vpn_ctx->rd_data)); 1949 vpn_ctx->rd_data));
1870 vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer (vpn_handle, 1950 vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer (vpn_handle,
1871 af, 1951 af,
1872 ntohs (vpn->proto), 1952 ntohs (vpn->proto),
@@ -1899,7 +1979,6 @@ handle_gns_resolution_result (void *cls,
1899 using 'scratch' array for memory allocations */ 1979 using 'scratch' array for memory allocations */
1900 scratch_off = 0; 1980 scratch_off = 0;
1901 rd_off = 0; 1981 rd_off = 0;
1902 shorten_ac = rh->ac_tail;
1903 for (unsigned int i=0;i<rd_count;i++) 1982 for (unsigned int i=0;i<rd_count;i++)
1904 { 1983 {
1905 GNUNET_assert (rd_off <= i); 1984 GNUNET_assert (rd_off <= i);
@@ -2077,8 +2156,6 @@ handle_gns_resolution_result (void *cls,
2077 GNUNET_break_op (0); 2156 GNUNET_break_op (0);
2078 break; 2157 break;
2079 } 2158 }
2080 if (NULL == shorten_ac->suggested_shortening_label)
2081 shorten_ac->suggested_shortening_label = GNUNET_strdup (nick);
2082 break; 2159 break;
2083 } 2160 }
2084 case GNUNET_GNSRECORD_TYPE_PKEY: 2161 case GNUNET_GNSRECORD_TYPE_PKEY:
@@ -2104,8 +2181,6 @@ handle_gns_resolution_result (void *cls,
2104 ac->gns_authority = GNUNET_YES; 2181 ac->gns_authority = GNUNET_YES;
2105 ac->authority_info.gns_authority = pub; 2182 ac->authority_info.gns_authority = pub;
2106 ac->label = GNUNET_strdup (GNUNET_GNS_EMPTY_LABEL_AT); 2183 ac->label = GNUNET_strdup (GNUNET_GNS_EMPTY_LABEL_AT);
2107 ac->suggested_shortening_label = NULL;
2108 ac->shortening_started = GNUNET_NO;
2109 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, 2184 GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
2110 rh->ac_tail, 2185 rh->ac_tail,
2111 ac); 2186 ac);
@@ -2300,6 +2375,11 @@ handle_dht_response (void *cls,
2300 fail_resolution (rh); 2375 fail_resolution (rh);
2301 return; 2376 return;
2302 } 2377 }
2378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2379 "Decrypting DHT block of size %u for `%s', expires %s\n",
2380 ntohl (block->purpose.size),
2381 rh->name,
2382 GNUNET_STRINGS_absolute_time_to_string (exp));
2303 if (GNUNET_OK != 2383 if (GNUNET_OK !=
2304 GNUNET_GNSRECORD_block_decrypt (block, 2384 GNUNET_GNSRECORD_block_decrypt (block,
2305 &ac->authority_info.gns_authority, 2385 &ac->authority_info.gns_authority,
@@ -2317,6 +2397,8 @@ handle_dht_response (void *cls,
2317 "Received expired block from the DHT, will not cache it.\n"); 2397 "Received expired block from the DHT, will not cache it.\n");
2318 return; 2398 return;
2319 } 2399 }
2400 if (GNUNET_YES == disable_cache)
2401 return;
2320 /* Cache well-formed blocks */ 2402 /* Cache well-formed blocks */
2321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2322 "Caching response from the DHT in namecache\n"); 2404 "Caching response from the DHT in namecache\n");
@@ -2327,7 +2409,7 @@ handle_dht_response (void *cls,
2327 co); 2409 co);
2328 GNUNET_CONTAINER_DLL_insert (co_head, 2410 GNUNET_CONTAINER_DLL_insert (co_head,
2329 co_tail, 2411 co_tail,
2330 co); 2412 co);
2331} 2413}
2332 2414
2333 2415
@@ -2357,7 +2439,8 @@ start_dht_request (struct GNS_ResolverHandle *rh,
2357 if (GNUNET_CONTAINER_heap_get_size (dht_lookup_heap) > max_allowed_background_queries) 2439 if (GNUNET_CONTAINER_heap_get_size (dht_lookup_heap) > max_allowed_background_queries)
2358 { 2440 {
2359 /* fail longest-standing DHT request */ 2441 /* fail longest-standing DHT request */
2360 rx = GNUNET_CONTAINER_heap_peek (dht_lookup_heap); 2442 rx = GNUNET_CONTAINER_heap_remove_root (dht_lookup_heap);
2443 rx->dht_heap_node = NULL;
2361 GNUNET_assert (NULL != rx); 2444 GNUNET_assert (NULL != rx);
2362 fail_resolution (rx); 2445 fail_resolution (rx);
2363 } 2446 }
@@ -2379,6 +2462,10 @@ handle_gns_namecache_resolution_result (void *cls,
2379{ 2462{
2380 struct GNS_ResolverHandle *rh = cls; 2463 struct GNS_ResolverHandle *rh = cls;
2381 2464
2465 if (0 == rd_count)
2466 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2467 _("GNS namecache returned empty result for `%s'\n"),
2468 rh->name);
2382 handle_gns_resolution_result (rh, 2469 handle_gns_resolution_result (rh,
2383 rd_count, 2470 rd_count,
2384 rd); 2471 rd);
@@ -2627,7 +2714,6 @@ start_resolver_lookup (void *cls)
2627 ac = GNUNET_new (struct AuthorityChain); 2714 ac = GNUNET_new (struct AuthorityChain);
2628 ac->rh = rh; 2715 ac->rh = rh;
2629 ac->label = resolver_lookup_get_next_label (rh); 2716 ac->label = resolver_lookup_get_next_label (rh);
2630 ac->suggested_shortening_label = NULL;
2631 if (NULL == ac->label) 2717 if (NULL == ac->label)
2632 /* name was just the "TLD", so we default to label 2718 /* name was just the "TLD", so we default to label
2633 #GNUNET_GNS_EMPTY_LABEL_AT */ 2719 #GNUNET_GNS_EMPTY_LABEL_AT */
@@ -2741,7 +2827,6 @@ GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh)
2741 GNUNET_DNSSTUB_stop (ac->authority_info.dns_authority.dns_handle); 2827 GNUNET_DNSSTUB_stop (ac->authority_info.dns_authority.dns_handle);
2742 } 2828 }
2743 GNUNET_free (ac->label); 2829 GNUNET_free (ac->label);
2744 GNUNET_free_non_null (ac->suggested_shortening_label);
2745 GNUNET_free (ac); 2830 GNUNET_free (ac);
2746 } 2831 }
2747 if (NULL != rh->task_id) 2832 if (NULL != rh->task_id)
@@ -2789,6 +2874,7 @@ GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh)
2789 dr); 2874 dr);
2790 GNUNET_free (dr); 2875 GNUNET_free (dr);
2791 } 2876 }
2877 GNUNET_free_non_null (rh->leho);
2792 GNUNET_free (rh->name); 2878 GNUNET_free (rh->name);
2793 GNUNET_free (rh); 2879 GNUNET_free (rh);
2794} 2880}
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h
index 06ecc51ce..d4cbd08f8 100644
--- a/src/gns/gnunet-service-gns_resolver.h
+++ b/src/gns/gnunet-service-gns_resolver.h
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009-2013 GNUnet e.V. 3 Copyright (C) 2009-2013 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gns/gnunet-service-gns_resolver.h 19 * @file gns/gnunet-service-gns_resolver.h
diff --git a/src/gns/nss/nss_gns.c b/src/gns/nss/nss_gns.c
index 03ac6e09c..58aab47fd 100644
--- a/src/gns/nss/nss_gns.c
+++ b/src/gns/nss/nss_gns.c
@@ -54,121 +54,126 @@
54 * @return a nss_status code 54 * @return a nss_status code
55 */ 55 */
56enum nss_status 56enum nss_status
57_nss_gns_gethostbyname2_r( 57_nss_gns_gethostbyname2_r(const char *name,
58 const char *name, 58 int af,
59 int af, 59 struct hostent *result,
60 struct hostent * result, 60 char *buffer,
61 char *buffer, 61 size_t buflen,
62 size_t buflen, 62 int *errnop,
63 int *errnop, 63 int *h_errnop)
64 int *h_errnop) { 64{
65 65 struct userdata u;
66 struct userdata u; 66 enum nss_status status = NSS_STATUS_UNAVAIL;
67 enum nss_status status = NSS_STATUS_UNAVAIL; 67 int i;
68 int i; 68 size_t address_length;
69 size_t address_length, l, idx, astart; 69 size_t l;
70 70 size_t idx;
71 if (af == AF_UNSPEC) 71 size_t astart;
72
73 if (af == AF_UNSPEC)
72#ifdef NSS_IPV6_ONLY 74#ifdef NSS_IPV6_ONLY
73 af = AF_INET6; 75 af = AF_INET6;
74#else 76#else
75 af = AF_INET; 77 af = AF_INET;
76#endif 78#endif
77 79
78#ifdef NSS_IPV4_ONLY 80#ifdef NSS_IPV4_ONLY
79 if (af != AF_INET) 81 if (af != AF_INET)
80#elif NSS_IPV6_ONLY 82#elif NSS_IPV6_ONLY
81 if (af != AF_INET6) 83 if (af != AF_INET6)
82#else 84#else
83 if (af != AF_INET && af != AF_INET6) 85 if ( (af != AF_INET) &&
86 (af != AF_INET6) )
84#endif 87#endif
85 { 88 {
86 *errnop = EINVAL; 89 *errnop = EINVAL;
87 *h_errnop = NO_RECOVERY; 90 *h_errnop = NO_RECOVERY;
88 91
89 goto finish; 92 goto finish;
90 } 93 }
91
92 address_length = af == AF_INET ? sizeof(ipv4_address_t) : sizeof(ipv6_address_t);
93 if (buflen <
94 sizeof(char*)+ /* alias names */
95 strlen(name)+1) { /* official name */
96
97 *errnop = ERANGE;
98 *h_errnop = NO_RECOVERY;
99 status = NSS_STATUS_TRYAGAIN;
100
101 goto finish;
102 }
103
104 u.count = 0;
105 u.data_len = 0;
106
107 i = gns_resolve_name(af, name, &u);
108 if (-3 == i)
109 {
110 status = NSS_STATUS_NOTFOUND;
111 goto finish;
112 }
113 if (-2 == i)
114 {
115 status = NSS_STATUS_UNAVAIL;
116 goto finish;
117 }
118 if ( (-1 == i) ||
119 (u.count == 0) )
120 {
121 *errnop = ETIMEDOUT;
122 *h_errnop = HOST_NOT_FOUND;
123 status = NSS_STATUS_NOTFOUND;
124 goto finish;
125 }
126
127
128 /* Alias names */
129 *((char**) buffer) = NULL;
130 result->h_aliases = (char**) buffer;
131 idx = sizeof(char*);
132
133 /* Official name */
134 strcpy(buffer+idx, name);
135 result->h_name = buffer+idx;
136 idx += strlen(name)+1;
137
138 ALIGN(idx);
139
140 result->h_addrtype = af;
141 result->h_length = address_length;
142
143 /* Check if there's enough space for the addresses */
144 if (buflen < idx+u.data_len+sizeof(char*)*(u.count+1)) {
145 *errnop = ERANGE;
146 *h_errnop = NO_RECOVERY;
147 status = NSS_STATUS_TRYAGAIN;
148 goto finish;
149 }
150 94
95 address_length = (af == AF_INET) ? sizeof(ipv4_address_t) : sizeof(ipv6_address_t);
96 if (buflen <
97 sizeof(char*)+ /* alias names */
98 strlen(name)+1)
99 { /* official name */
100 *errnop = ERANGE;
101 *h_errnop = NO_RECOVERY;
102 status = NSS_STATUS_TRYAGAIN;
103
104 goto finish;
105 }
106 u.count = 0;
107 u.data_len = 0;
108 i = gns_resolve_name (af,
109 name,
110 &u);
111 if (-3 == i)
112 {
113 status = NSS_STATUS_NOTFOUND;
114 goto finish;
115 }
116 if (-2 == i)
117 {
118 status = NSS_STATUS_UNAVAIL;
119 goto finish;
120 }
121 if ( (-1 == i) ||
122 (u.count == 0) )
123 {
124 *errnop = ETIMEDOUT;
125 *h_errnop = HOST_NOT_FOUND;
126 status = NSS_STATUS_NOTFOUND;
127 goto finish;
128 }
129 /* Alias names */
130 *((char**) buffer) = NULL;
131 result->h_aliases = (char**) buffer;
132 idx = sizeof(char*);
133
134 /* Official name */
135 strcpy (buffer+idx,
136 name);
137 result->h_name = buffer+idx;
138 idx += strlen (name)+1;
139
140 ALIGN(idx);
141
142 result->h_addrtype = af;
143 result->h_length = address_length;
144
145 /* Check if there's enough space for the addresses */
146 if (buflen < idx+u.data_len+sizeof(char*)*(u.count+1))
147 {
148 *errnop = ERANGE;
149 *h_errnop = NO_RECOVERY;
150 status = NSS_STATUS_TRYAGAIN;
151 goto finish;
152 }
151 /* Addresses */ 153 /* Addresses */
152 astart = idx; 154 astart = idx;
153 l = u.count*address_length; 155 l = u.count*address_length;
154 if (0 != l) 156 if (0 != l)
155 memcpy(buffer+astart, &u.data, l); 157 memcpy (buffer+astart,
156 /* address_length is a multiple of 32bits, so idx is still aligned 158 &u.data,
157 * correctly */ 159 l);
158 idx += l; 160 /* address_length is a multiple of 32bits, so idx is still aligned
159 161 * correctly */
160 /* Address array address_lenght is always a multiple of 32bits */ 162 idx += l;
161 for (i = 0; i < u.count; i++) 163
162 ((char**) (buffer+idx))[i] = buffer+astart+address_length*i; 164 /* Address array address_length is always a multiple of 32bits */
163 ((char**) (buffer+idx))[i] = NULL; 165 for (i = 0; i < u.count; i++)
164 result->h_addr_list = (char**) (buffer+idx); 166 ((char**) (buffer+idx))[i] = buffer+astart+address_length*i;
165 167 ((char**) (buffer+idx))[i] = NULL;
166 status = NSS_STATUS_SUCCESS; 168 result->h_addr_list = (char**) (buffer+idx);
169
170 status = NSS_STATUS_SUCCESS;
167 171
168finish: 172finish:
169 return status; 173 return status;
170} 174}
171 175
176
172/** 177/**
173 * The gethostbyname hook executed by nsswitch 178 * The gethostbyname hook executed by nsswitch
174 * 179 *
@@ -176,29 +181,28 @@ finish:
176 * @param result the result hostent 181 * @param result the result hostent
177 * @param buffer the result buffer 182 * @param buffer the result buffer
178 * @param buflen length of the buffer 183 * @param buflen length of the buffer
179 * @param errnop idk 184 * @param errnop[out] the low-level error code to return to the application
180 * @param h_errnop idk 185 * @param h_errnop idk
181 * @return a nss_status code 186 * @return a nss_status code
182 */ 187 */
183enum nss_status 188enum nss_status
184_nss_gns_gethostbyname_r ( 189_nss_gns_gethostbyname_r (const char *name,
185 const char *name, 190 struct hostent *result,
186 struct hostent *result, 191 char *buffer,
187 char *buffer, 192 size_t buflen,
188 size_t buflen, 193 int *errnop,
189 int *errnop, 194 int *h_errnop)
190 int *h_errnop) { 195{
191 196 return _nss_gns_gethostbyname2_r (name,
192 return _nss_gns_gethostbyname2_r( 197 AF_UNSPEC,
193 name, 198 result,
194 AF_UNSPEC, 199 buffer,
195 result, 200 buflen,
196 buffer, 201 errnop,
197 buflen, 202 h_errnop);
198 errnop,
199 h_errnop);
200} 203}
201 204
205
202/** 206/**
203 * The gethostbyaddr hook executed by nsswitch 207 * The gethostbyaddr hook executed by nsswitch
204 * We can't do this so we always return NSS_STATUS_UNAVAIL 208 * We can't do this so we always return NSS_STATUS_UNAVAIL
@@ -209,23 +213,22 @@ _nss_gns_gethostbyname_r (
209 * @param result the result hostent 213 * @param result the result hostent
210 * @param buffer the result buffer 214 * @param buffer the result buffer
211 * @param buflen length of the buffer 215 * @param buflen length of the buffer
212 * @param errnop idk 216 * @param errnop[out] the low-level error code to return to the application
213 * @param h_errnop idk 217 * @param h_errnop idk
214 * @return NSS_STATUS_UNAVAIL 218 * @return NSS_STATUS_UNAVAIL
215 */ 219 */
216enum nss_status 220enum nss_status
217_nss_gns_gethostbyaddr_r( 221_nss_gns_gethostbyaddr_r (const void* addr,
218 const void* addr, 222 int len,
219 int len, 223 int af,
220 int af, 224 struct hostent *result,
221 struct hostent *result, 225 char *buffer,
222 char *buffer, 226 size_t buflen,
223 size_t buflen, 227 int *errnop,
224 int *errnop, 228 int *h_errnop)
225 int *h_errnop) { 229{
226 230 *errnop = EINVAL;
227 *errnop = EINVAL; 231 *h_errnop = NO_RECOVERY;
228 *h_errnop = NO_RECOVERY; 232 //NOTE we allow to leak this into DNS so no NOTFOUND
229 //NOTE we allow to leak this into DNS so no NOTFOUND 233 return NSS_STATUS_UNAVAIL;
230 return NSS_STATUS_UNAVAIL;
231} 234}
diff --git a/src/gns/nss/nss_gns_query.c b/src/gns/nss/nss_gns_query.c
index 4700100b5..867ead624 100644
--- a/src/gns/nss/nss_gns_query.c
+++ b/src/gns/nss/nss_gns_query.c
@@ -2,20 +2,18 @@
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 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20#include <string.h> 18#include <string.h>
21#include <stdio.h> 19#include <stdio.h>
@@ -50,14 +48,16 @@ gns_resolve_name (int af,
50 { 48 {
51 if (-1 == asprintf (&cmd, 49 if (-1 == asprintf (&cmd,
52 "%s -t AAAA -u %s\n", 50 "%s -t AAAA -u %s\n",
53 "gnunet-gns -r", name)) 51 "gnunet-gns -r",
52 name))
54 return -1; 53 return -1;
55 } 54 }
56 else 55 else
57 { 56 {
58 if (-1 == asprintf (&cmd, 57 if (-1 == asprintf (&cmd,
59 "%s %s\n", 58 "%s %s\n",
60 "gnunet-gns -r -u", name)) 59 "gnunet-gns -r -u",
60 name))
61 return -1; 61 return -1;
62 } 62 }
63 if (NULL == (p = popen (cmd, "r"))) 63 if (NULL == (p = popen (cmd, "r")))
@@ -65,7 +65,9 @@ gns_resolve_name (int af,
65 free (cmd); 65 free (cmd);
66 return -1; 66 return -1;
67 } 67 }
68 while (NULL != fgets (line, sizeof(line), p)) 68 while (NULL != fgets (line,
69 sizeof(line),
70 p))
69 { 71 {
70 if (u->count >= MAX_ENTRIES) 72 if (u->count >= MAX_ENTRIES)
71 break; 73 break;
@@ -74,7 +76,9 @@ gns_resolve_name (int af,
74 line[strlen(line)-1] = '\0'; 76 line[strlen(line)-1] = '\0';
75 if (AF_INET == af) 77 if (AF_INET == af)
76 { 78 {
77 if (inet_pton(af, line, &(u->data.ipv4[u->count]))) 79 if (inet_pton(af,
80 line,
81 &u->data.ipv4[u->count]))
78 { 82 {
79 u->count++; 83 u->count++;
80 u->data_len += sizeof(ipv4_address_t); 84 u->data_len += sizeof(ipv4_address_t);
@@ -88,7 +92,9 @@ gns_resolve_name (int af,
88 } 92 }
89 else if (AF_INET6 == af) 93 else if (AF_INET6 == af)
90 { 94 {
91 if (inet_pton(af, line, &(u->data.ipv6[u->count]))) 95 if (inet_pton(af,
96 line,
97 &u->data.ipv6[u->count]))
92 { 98 {
93 u->count++; 99 u->count++;
94 u->data_len += sizeof(ipv6_address_t); 100 u->data_len += sizeof(ipv6_address_t);
@@ -107,7 +113,10 @@ gns_resolve_name (int af,
107 if (4 == ret) 113 if (4 == ret)
108 return -2; /* not for GNS */ 114 return -2; /* not for GNS */
109 if (3 == ret) 115 if (3 == ret)
110 return -3; /* timeout */ 116 return -3; /* timeout -> not found */
117 if ( (2 == ret) || (1 == ret) )
118 return -2; /* launch failure -> service unavailable */
111 return 0; 119 return 0;
112} 120}
121
113/* end of nss_gns_query.c */ 122/* end of nss_gns_query.c */
diff --git a/src/gns/nss/nss_gns_query.h b/src/gns/nss/nss_gns_query.h
index 024f11e2e..48cab4b22 100644
--- a/src/gns/nss/nss_gns_query.h
+++ b/src/gns/nss/nss_gns_query.h
@@ -2,20 +2,18 @@
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 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20#ifndef NSS_GNS_QUERY_H 18#ifndef NSS_GNS_QUERY_H
21#define NSS_GNS_QUERY_H 19#define NSS_GNS_QUERY_H
@@ -28,25 +26,30 @@
28/* Maximum number of entries to return */ 26/* Maximum number of entries to return */
29#define MAX_ENTRIES 16 27#define MAX_ENTRIES 16
30 28
31typedef struct { 29typedef struct
32 uint32_t address; 30{
31 uint32_t address;
33} ipv4_address_t; 32} ipv4_address_t;
34 33
35typedef struct { 34
36 uint8_t address[16]; 35typedef struct
36{
37 uint8_t address[16];
37} ipv6_address_t; 38} ipv6_address_t;
38 39
39 40
40struct userdata { 41struct userdata
42{
41 int count; 43 int count;
42 int data_len; /* only valid when doing reverse lookup */ 44 int data_len; /* only valid when doing reverse lookup */
43 union { 45 union {
44 ipv4_address_t ipv4[MAX_ENTRIES]; 46 ipv4_address_t ipv4[MAX_ENTRIES];
45 ipv6_address_t ipv6[MAX_ENTRIES]; 47 ipv6_address_t ipv6[MAX_ENTRIES];
46 char *name[MAX_ENTRIES]; 48 char *name[MAX_ENTRIES];
47 } data; 49 } data;
48}; 50};
49 51
52
50/** 53/**
51 * Wrapper function that uses gnunet-gns cli tool to resolve 54 * Wrapper function that uses gnunet-gns cli tool to resolve
52 * an IPv4/6 address. 55 * an IPv4/6 address.
@@ -56,8 +59,9 @@ struct userdata {
56 * @param u the userdata (result struct) 59 * @param u the userdata (result struct)
57 * @return -1 on error else 0 60 * @return -1 on error else 0
58 */ 61 */
59int gns_resolve_name(int af, 62int
60 const char *name, 63gns_resolve_name(int af,
61 struct userdata *userdata); 64 const char *name,
65 struct userdata *userdata);
62 66
63#endif 67#endif
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c
index a42fef953..677bb7721 100644
--- a/src/gns/plugin_block_gns.c
+++ b/src/gns/plugin_block_gns.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2010-2013 GNUnet e.V. 3 Copyright (C) 2010-2013 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20 18
21/** 19/**
diff --git a/src/gns/plugin_gnsrecord_gns.c b/src/gns/plugin_gnsrecord_gns.c
index 07d1a9c04..c99f39616 100644
--- a/src/gns/plugin_gnsrecord_gns.c
+++ b/src/gns/plugin_gnsrecord_gns.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2013, 2014, 2016 GNUnet e.V. 3 Copyright (C) 2013, 2014, 2016 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20 18
21/** 19/**
@@ -102,9 +100,9 @@ gns_value_to_string (void *cls,
102 ('\0' != cdata[data_size - 1]) ) 100 ('\0' != cdata[data_size - 1]) )
103 return NULL; /* malformed */ 101 return NULL; /* malformed */
104 /* need to memcpy for alignment */ 102 /* need to memcpy for alignment */
105 memcpy (&vpn, 103 GNUNET_memcpy (&vpn,
106 data, 104 data,
107 sizeof (vpn)); 105 sizeof (vpn));
108 GNUNET_asprintf (&vpn_str, 106 GNUNET_asprintf (&vpn_str,
109 "%u %s %s", 107 "%u %s %s",
110 (unsigned int) ntohs (vpn.proto), 108 (unsigned int) ntohs (vpn.proto),
@@ -122,9 +120,9 @@ gns_value_to_string (void *cls,
122 cdata = data; 120 cdata = data;
123 if (data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord)) 121 if (data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord))
124 return NULL; /* malformed */ 122 return NULL; /* malformed */
125 memcpy (&box, 123 GNUNET_memcpy (&box,
126 data, 124 data,
127 sizeof (box)); 125 sizeof (box));
128 rt = ntohl (box.record_type); 126 rt = ntohl (box.record_type);
129 ival = GNUNET_GNSRECORD_value_to_string (rt, 127 ival = GNUNET_GNSRECORD_value_to_string (rt,
130 &cdata[sizeof (box)], 128 &cdata[sizeof (box)],
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c
deleted file mode 100644
index 1d215b6a4..000000000
--- a/src/gns/plugin_rest_gns.c
+++ /dev/null
@@ -1,693 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 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 * @author Martin Schanzenbach
22 * @file gns/plugin_rest_gns.c
23 * @brief GNUnet GNS REST plugin
24 *
25 */
26
27#include "platform.h"
28#include "gnunet_rest_plugin.h"
29#include <gnunet_dnsparser_lib.h>
30#include <gnunet_identity_service.h>
31#include <gnunet_gnsrecord_lib.h>
32#include <gnunet_namestore_service.h>
33#include <gnunet_gns_service.h>
34#include <gnunet_rest_lib.h>
35#include <gnunet_jsonapi_lib.h>
36#include <gnunet_jsonapi_util.h>
37#include <jansson.h>
38
39#define GNUNET_REST_API_NS_GNS "/gns"
40
41#define GNUNET_REST_JSONAPI_GNS_RECORD_TYPE "record_type"
42
43#define GNUNET_REST_JSONAPI_GNS_TYPEINFO "gns_name"
44
45#define GNUNET_REST_JSONAPI_GNS_RECORD "records"
46
47#define GNUNET_REST_JSONAPI_GNS_EGO "ego"
48
49#define GNUNET_REST_JSONAPI_GNS_PKEY "pkey"
50
51#define GNUNET_REST_JSONAPI_GNS_OPTIONS "options"
52
53/**
54 * @brief struct returned by the initialization function of the plugin
55 */
56struct Plugin
57{
58 const struct GNUNET_CONFIGURATION_Handle *cfg;
59};
60
61const struct GNUNET_CONFIGURATION_Handle *cfg;
62
63struct LookupHandle
64{
65 /**
66 * Handle to GNS service.
67 */
68 struct GNUNET_GNS_Handle *gns;
69
70 /**
71 * Desired timeout for the lookup (default is no timeout).
72 */
73 struct GNUNET_TIME_Relative timeout;
74
75 /**
76 * Handle to lookup request
77 */
78 struct GNUNET_GNS_LookupRequest *lookup_request;
79
80 /**
81 * Handle to rest request
82 */
83 struct GNUNET_REST_RequestHandle *rest_handle;
84
85 /**
86 * Lookup an ego with the identity service.
87 */
88 struct GNUNET_IDENTITY_EgoLookup *el;
89
90 /**
91 * Handle for identity service.
92 */
93 struct GNUNET_IDENTITY_Handle *identity;
94
95 /**
96 * Active operation on identity service.
97 */
98 struct GNUNET_IDENTITY_Operation *id_op;
99
100 /**
101 * ID of a task associated with the resolution process.
102 */
103 struct GNUNET_SCHEDULER_Task * timeout_task;
104
105 /**
106 * The root of the received JSON or NULL
107 */
108 json_t *json_root;
109
110 /**
111 * The plugin result processor
112 */
113 GNUNET_REST_ResultProcessor proc;
114
115 /**
116 * The closure of the result processor
117 */
118 void *proc_cls;
119
120 /**
121 * The name to look up
122 */
123 char *name;
124
125 /**
126 * The ego to use
127 * In string representation from JSON
128 */
129 const char *ego_str;
130
131 /**
132 * The Pkey to use
133 * In string representation from JSON
134 */
135 const char *pkey_str;
136
137 /**
138 * The record type
139 */
140 int type;
141
142 /**
143 * The public key of to use for lookup
144 */
145 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
146
147 /**
148 * The public key to use for lookup
149 */
150 struct GNUNET_CRYPTO_EcdsaPublicKey pkeym;
151
152 /**
153 * The resolver options
154 */
155 enum GNUNET_GNS_LocalOptions options;
156
157 /**
158 * the shorten key
159 */
160 struct GNUNET_CRYPTO_EcdsaPrivateKey shorten_key;
161
162 /**
163 * HTTP response code
164 */
165 int response_code;
166
167};
168
169
170/**
171 * Cleanup lookup handle.
172 *
173 * @param handle Handle to clean up
174 */
175static void
176cleanup_handle (struct LookupHandle *handle)
177{
178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
179 "Cleaning up\n");
180 if (NULL != handle->json_root)
181 json_decref (handle->json_root);
182
183 if (NULL != handle->name)
184 GNUNET_free (handle->name);
185 if (NULL != handle->el)
186 {
187 GNUNET_IDENTITY_ego_lookup_cancel (handle->el);
188 handle->el = NULL;
189 }
190 if (NULL != handle->id_op)
191 {
192 GNUNET_IDENTITY_cancel (handle->id_op);
193 handle->id_op = NULL;
194 }
195 if (NULL != handle->lookup_request)
196 {
197 GNUNET_GNS_lookup_cancel (handle->lookup_request);
198 handle->lookup_request = NULL;
199 }
200 if (NULL != handle->identity)
201 {
202 GNUNET_IDENTITY_disconnect (handle->identity);
203 handle->identity = NULL;
204 }
205 if (NULL != handle->gns)
206 {
207 GNUNET_GNS_disconnect (handle->gns);
208 handle->gns = NULL;
209 }
210
211 if (NULL != handle->timeout_task)
212 {
213 GNUNET_SCHEDULER_cancel (handle->timeout_task);
214 }
215 GNUNET_free (handle);
216}
217
218
219/**
220 * Task run on shutdown. Cleans up everything.
221 *
222 * @param cls unused
223 * @param tc scheduler context
224 */
225static void
226do_error (void *cls)
227{
228 struct LookupHandle *handle = cls;
229 struct MHD_Response *resp;
230
231 resp = GNUNET_REST_create_response (NULL);
232 handle->proc (handle->proc_cls, resp, handle->response_code);
233 cleanup_handle (handle);
234}
235
236
237/**
238 * Create json representation of a GNSRECORD
239 *
240 * @param rd the GNSRECORD_Data
241 */
242static json_t *
243gnsrecord_to_json (const struct GNUNET_GNSRECORD_Data *rd)
244{
245 const char *typename;
246 char *string_val;
247 const char *exp_str;
248 json_t *record_obj;
249
250 typename = GNUNET_GNSRECORD_number_to_typename (rd->record_type);
251 string_val = GNUNET_GNSRECORD_value_to_string (rd->record_type,
252 rd->data,
253 rd->data_size);
254
255 if (NULL == string_val)
256 {
257 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
258 "Record of type %d malformed, skipping\n",
259 (int) rd->record_type);
260 return NULL;
261 }
262 record_obj = json_object ();
263 json_object_set_new (record_obj, "type", json_string (typename));
264 json_object_set_new (record_obj, "value", json_string (string_val));
265 GNUNET_free (string_val);
266
267 if (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION & rd->flags)
268 {
269 struct GNUNET_TIME_Relative time_rel;
270 time_rel.rel_value_us = rd->expiration_time;
271 exp_str = GNUNET_STRINGS_relative_time_to_string (time_rel, 1);
272 }
273 else
274 {
275 struct GNUNET_TIME_Absolute time_abs;
276 time_abs.abs_value_us = rd->expiration_time;
277 exp_str = GNUNET_STRINGS_absolute_time_to_string (time_abs);
278 }
279 json_object_set_new (record_obj, "expiration_time", json_string (exp_str));
280
281 json_object_set_new (record_obj, "expired",
282 json_boolean (GNUNET_YES == GNUNET_GNSRECORD_is_expired (rd)));
283 return record_obj;
284}
285
286/**
287 * Function called with the result of a GNS lookup.
288 *
289 * @param cls the 'const char *' name that was resolved
290 * @param rd_count number of records returned
291 * @param rd array of @a rd_count records with the results
292 */
293static void
294process_lookup_result (void *cls, uint32_t rd_count,
295 const struct GNUNET_GNSRECORD_Data *rd)
296{
297 struct LookupHandle *handle = cls;
298 struct MHD_Response *resp;
299 struct GNUNET_JSONAPI_Document *json_document;
300 struct GNUNET_JSONAPI_Resource *json_resource;
301 uint32_t i;
302 char *result;
303 json_t *result_array;
304 json_t *record_obj;
305
306 result_array = json_array();
307 json_document = GNUNET_JSONAPI_document_new ();
308 json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_GNS_TYPEINFO, handle->name);
309 handle->lookup_request = NULL;
310 for (i=0; i<rd_count; i++)
311 {
312 if ( (rd[i].record_type != handle->type) &&
313 (GNUNET_GNSRECORD_TYPE_ANY != handle->type) )
314 continue;
315 record_obj = gnsrecord_to_json (&(rd[i]));
316 json_array_append (result_array, record_obj);
317 json_decref (record_obj);
318 }
319 GNUNET_JSONAPI_resource_add_attr (json_resource,
320 GNUNET_REST_JSONAPI_GNS_RECORD,
321 result_array);
322 GNUNET_JSONAPI_document_resource_add (json_document, json_resource);
323 GNUNET_JSONAPI_document_serialize (json_document, &result);
324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result);
325 json_decref (result_array);
326 GNUNET_JSONAPI_document_delete (json_document);
327 resp = GNUNET_REST_create_response (result);
328 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
329 GNUNET_free (result);
330 cleanup_handle (handle);
331}
332
333
334/**
335 * Perform the actual resolution, starting with the zone
336 * identified by the given public key and the shorten zone.
337 *
338 * @param pkey public key to use for the zone, can be NULL
339 */
340static void
341lookup_with_public_key (struct LookupHandle *handle)
342{
343 if (UINT32_MAX == handle->type)
344 {
345 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
346 _("Invalid typename specified, assuming `ANY'\n"));
347 handle->type = GNUNET_GNSRECORD_TYPE_ANY;
348 }
349 if (NULL != handle->name)
350 {
351 handle->lookup_request = GNUNET_GNS_lookup (handle->gns,
352 handle->name,
353 &handle->pkey,
354 handle->type,
355 handle->options,
356 &process_lookup_result,
357 handle);
358 }
359 else
360 {
361 GNUNET_SCHEDULER_add_now (&do_error, handle);
362 return;
363 }
364}
365
366
367/**
368 * Method called to with the ego we are to use for the lookup,
369 * when the ego is determined by a name.
370 *
371 * @param cls closure (NULL, unused)
372 * @param ego ego handle, NULL if not found
373 */
374static void
375identity_zone_cb (void *cls,
376 const struct GNUNET_IDENTITY_Ego *ego)
377{
378 struct LookupHandle *handle = cls;
379
380 handle->el = NULL;
381 if (NULL == ego)
382 {
383 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
384 _("Ego for not found, cannot perform lookup.\n"));
385 GNUNET_SCHEDULER_add_now (&do_error, handle);
386 return;
387 }
388 else
389 {
390 GNUNET_IDENTITY_ego_get_public_key (ego, &handle->pkey);
391 lookup_with_public_key (handle);
392 }
393 json_decref(handle->json_root);
394}
395
396
397/**
398 * Method called to with the ego we are to use for the lookup,
399 * when the ego is the one for the default master zone.
400 *
401 * @param cls closure (NULL, unused)
402 * @param ego ego handle, NULL if not found
403 * @param ctx context for application to store data for this ego
404 * (during the lifetime of this process, initially NULL)
405 * @param name name assigned by the user for this ego,
406 * NULL if the user just deleted the ego and it
407 * must thus no longer be used
408 */
409static void
410identity_master_cb (void *cls,
411 struct GNUNET_IDENTITY_Ego *ego,
412 void **ctx,
413 const char *name)
414{
415 const char *dot;
416 struct LookupHandle *handle = cls;
417
418 handle->id_op = NULL;
419 if (NULL == ego)
420 {
421 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
422 _("Ego for `gns-master' not found, cannot perform lookup. Did you run gnunet-gns-import.sh?\n"));
423 GNUNET_SCHEDULER_add_now (&do_error, handle);
424 return;
425 }
426 GNUNET_IDENTITY_ego_get_public_key (ego,
427 &handle->pkey);
428 /* main name is our own master zone, do no look for that in the DHT */
429 handle->options = GNUNET_GNS_LO_LOCAL_MASTER;
430 /* if the name is of the form 'label.gnu', never go to the DHT */
431 dot = NULL;
432 if (NULL != handle->name)
433 dot = strchr (handle->name, '.');
434 if ( (NULL != dot) &&
435 (0 == strcasecmp (dot, ".gnu")) )
436 handle->options = GNUNET_GNS_LO_NO_DHT;
437 lookup_with_public_key (handle);
438}
439
440/**
441 * Parse REST uri for name and record type
442 *
443 * @param url Url to parse
444 * @param handle lookup handle to populate
445 * @return GNUNET_SYSERR on error
446 */
447static int
448parse_url (const char *url, struct LookupHandle *handle)
449{
450 char *name;
451 char tmp_url[strlen(url)+1];
452 char *tok;
453
454 strcpy (tmp_url, url);
455 tok = strtok ((char*)tmp_url, "/");
456 if (NULL == tok)
457 return GNUNET_SYSERR;
458 name = strtok (NULL, "/");
459 if (NULL == name)
460 return GNUNET_SYSERR;
461 GNUNET_asprintf (&handle->name,
462 "%s",
463 name);
464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
465 "Got name: %s\n", handle->name);
466 return GNUNET_OK;
467}
468
469
470static void
471get_gns_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
472 const char* url,
473 void *cls)
474{
475 struct LookupHandle *handle = cls;
476 struct GNUNET_HashCode key;
477
478 //parse name and type from url
479 if (GNUNET_OK != parse_url (url, handle))
480 {
481 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing url...\n");
482 GNUNET_SCHEDULER_add_now (&do_error, handle);
483 return;
484 }
485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
486 "Connecting...\n");
487 handle->gns = GNUNET_GNS_connect (cfg);
488 handle->identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
489 handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout,
490 &do_error, handle);
491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
492 "Connected\n");
493 if (NULL == handle->gns)
494 {
495 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
496 "Connecting to GNS failed\n");
497 GNUNET_SCHEDULER_add_now (&do_error, handle);
498 return;
499 }
500 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_GNS_OPTIONS,
501 strlen (GNUNET_REST_JSONAPI_GNS_OPTIONS),
502 &key);
503 handle->options = GNUNET_GNS_LO_DEFAULT;
504 if ( GNUNET_YES ==
505 GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map,
506 &key) )
507 {
508 handle->options = GNUNET_GNS_LO_DEFAULT;//TODO(char*) GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
509 //&key);
510 }
511 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_GNS_RECORD_TYPE,
512 strlen (GNUNET_REST_JSONAPI_GNS_RECORD_TYPE),
513 &key);
514 if ( GNUNET_YES ==
515 GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map,
516 &key) )
517 {
518 handle->type = GNUNET_GNSRECORD_typename_to_number
519 (GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
520 &key));
521 }
522 else
523 handle->type = GNUNET_GNSRECORD_TYPE_ANY;
524
525 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_GNS_PKEY,
526 strlen (GNUNET_REST_JSONAPI_GNS_PKEY),
527 &key);
528 if ( GNUNET_YES ==
529 GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map,
530 &key) )
531 {
532 handle->pkey_str = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
533 &key);
534 GNUNET_assert (NULL != handle->pkey_str);
535 if (GNUNET_OK !=
536 GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->pkey_str,
537 strlen(handle->pkey_str),
538 &(handle->pkey)))
539 {
540 GNUNET_SCHEDULER_add_now (&do_error, handle);
541 return;
542 }
543 lookup_with_public_key (handle);
544 return;
545 }
546 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_GNS_EGO,
547 strlen (GNUNET_REST_JSONAPI_GNS_EGO),
548 &key);
549 if ( GNUNET_YES ==
550 GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map,
551 &key) )
552 {
553 handle->ego_str = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
554 &key);
555 handle->el = GNUNET_IDENTITY_ego_lookup (cfg,
556 handle->ego_str,
557 &identity_zone_cb,
558 handle);
559 return;
560 }
561 if ( (NULL != handle->name) &&
562 (strlen (handle->name) > 4) &&
563 (0 == strcmp (".zkey",
564 &handle->name[strlen (handle->name) - 4])) )
565 {
566 GNUNET_CRYPTO_ecdsa_key_get_public
567 (GNUNET_CRYPTO_ecdsa_key_get_anonymous (),
568 &(handle->pkey));
569 lookup_with_public_key (handle);
570 }
571 else
572 {
573 GNUNET_break (NULL == handle->id_op);
574 handle->id_op = GNUNET_IDENTITY_get (handle->identity,
575 "gns-master",
576 &identity_master_cb,
577 handle);
578 GNUNET_assert (NULL != handle->id_op);
579 }
580}
581
582/**
583 * Handle rest request
584 *
585 * @param handle the lookup handle
586 */
587static void
588options_cont (struct GNUNET_REST_RequestHandle *con_handle,
589 const char* url,
590 void *cls)
591{
592 struct MHD_Response *resp;
593 struct LookupHandle *handle = cls;
594
595 //For GNS, independent of path return all options
596 resp = GNUNET_REST_create_response (NULL);
597 MHD_add_response_header (resp,
598 "Access-Control-Allow-Methods",
599 MHD_HTTP_METHOD_GET);
600 handle->proc (handle->proc_cls,
601 resp,
602 MHD_HTTP_OK);
603 cleanup_handle (handle);
604}
605
606
607/**
608 * Function processing the REST call
609 *
610 * @param method HTTP method
611 * @param url URL of the HTTP request
612 * @param data body of the HTTP request (optional)
613 * @param data_size length of the body
614 * @param proc callback function for the result
615 * @param proc_cls closure for @a proc
616 * @return #GNUNET_OK if request accepted
617 */
618static void
619rest_gns_process_request (struct GNUNET_REST_RequestHandle *conndata_handle,
620 GNUNET_REST_ResultProcessor proc,
621 void *proc_cls)
622{
623 static const struct GNUNET_REST_RequestHandler handlers[] = {
624 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_GNS, &get_gns_cont},
625 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_GNS, &options_cont},
626 GNUNET_REST_HANDLER_END
627 };
628 struct LookupHandle *handle = GNUNET_new (struct LookupHandle);
629 struct GNUNET_REST_RequestHandlerError err;
630
631 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
632 handle->proc_cls = proc_cls;
633 handle->proc = proc;
634 handle->rest_handle = conndata_handle;
635
636 if (GNUNET_NO == GNUNET_JSONAPI_handle_request (conndata_handle,
637 handlers,
638 &err,
639 handle))
640 {
641 handle->response_code = err.error_code;
642 GNUNET_SCHEDULER_add_now (&do_error, handle);
643 }
644}
645
646
647/**
648 * Entry point for the plugin.
649 *
650 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
651 * @return NULL on error, otherwise the plugin context
652 */
653void *
654libgnunet_plugin_rest_gns_init (void *cls)
655{
656 static struct Plugin plugin;
657 cfg = cls;
658 struct GNUNET_REST_Plugin *api;
659
660 if (NULL != plugin.cfg)
661 return NULL; /* can only initialize once! */
662 memset (&plugin, 0, sizeof (struct Plugin));
663 plugin.cfg = cfg;
664 api = GNUNET_new (struct GNUNET_REST_Plugin);
665 api->cls = &plugin;
666 api->name = GNUNET_REST_API_NS_GNS;
667 api->process_request = &rest_gns_process_request;
668 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
669 _("GNS REST API initialized\n"));
670 return api;
671}
672
673
674/**
675 * Exit point from the plugin.
676 *
677 * @param cls the plugin context (as returned by "init")
678 * @return always NULL
679 */
680void *
681libgnunet_plugin_rest_gns_done (void *cls)
682{
683 struct GNUNET_REST_Plugin *api = cls;
684 struct Plugin *plugin = api->cls;
685
686 plugin->cfg = NULL;
687 GNUNET_free (api);
688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
689 "GNS REST plugin is finished\n");
690 return NULL;
691}
692
693/* end of plugin_rest_gns.c */
diff --git a/src/gns/test_gns_plus_lookup.sh b/src/gns/test_gns_at_lookup.sh
index 4cf7a8855..8c1d2a088 100755
--- a/src/gns/test_gns_plus_lookup.sh
+++ b/src/gns/test_gns_at_lookup.sh
@@ -14,7 +14,7 @@ then
14fi 14fi
15 15
16which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 16which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
17rm -rf /tmp/test-gnunet-gns-peer-1/ 17rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
18 18
19TEST_IP="127.0.0.1" 19TEST_IP="127.0.0.1"
20MY_EGO="myego" 20MY_EGO="myego"
@@ -23,12 +23,12 @@ gnunet-identity -C delegatedego -c test_gns_lookup.conf
23DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep delegatedego | awk '{print $3}') 23DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep delegatedego | awk '{print $3}')
24gnunet-identity -C $MY_EGO -c test_gns_lookup.conf 24gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
25gnunet-namestore -p -z $MY_EGO -a -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf 25gnunet-namestore -p -z $MY_EGO -a -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
26gnunet-namestore -p -z delegatedego -a -n '+' -t A -V $TEST_IP -e never -c test_gns_lookup.conf 26gnunet-namestore -p -z delegatedego -a -n '@' -t A -V $TEST_IP -e never -c test_gns_lookup.conf
27RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u b.$MY_EGO -t A -c test_gns_lookup.conf` 27RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u b.$MY_EGO -t A -c test_gns_lookup.conf`
28gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf 28gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
29gnunet-namestore -z delegatedego -d -n '+' -t A -V $TEST_IP -e never -c test_gns_lookup.conf 29gnunet-namestore -z delegatedego -d -n '@' -t A -V $TEST_IP -e never -c test_gns_lookup.conf
30gnunet-arm -e -c test_gns_lookup.conf 30gnunet-arm -e -c test_gns_lookup.conf
31rm -rf /tmp/test-gnunet-gns-peer-1/ 31rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
32 32
33if [ "$RES_IP" == "$TEST_IP" ] 33if [ "$RES_IP" == "$TEST_IP" ]
34then 34then
diff --git a/src/gns/test_gns_cname_lookup.sh b/src/gns/test_gns_cname_lookup.sh
index d9627850f..00ccd265b 100755
--- a/src/gns/test_gns_cname_lookup.sh
+++ b/src/gns/test_gns_cname_lookup.sh
@@ -22,7 +22,7 @@ then
22fi 22fi
23 23
24 24
25rm -rf /tmp/test-gnunet-gns-peer-1/ 25rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
26 26
27TEST_IP_PLUS="127.0.0.1" 27TEST_IP_PLUS="127.0.0.1"
28TEST_IP_DNS="131.159.74.67" 28TEST_IP_DNS="131.159.74.67"
@@ -51,7 +51,7 @@ gnunet-namestore -p -z $MY_EGO -d -n $TEST_RECORD_NAME_PLUS -t CNAME -V $TEST_RE
51gnunet-namestore -p -z $MY_EGO -d -n $TEST_RECORD_CNAME_SERVER -t A -V $TEST_IP_PLUS -e never -c test_gns_lookup.conf 51gnunet-namestore -p -z $MY_EGO -d -n $TEST_RECORD_CNAME_SERVER -t A -V $TEST_IP_PLUS -e never -c test_gns_lookup.conf
52gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 52gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
53gnunet-arm -e -c test_gns_lookup.conf 53gnunet-arm -e -c test_gns_lookup.conf
54rm -rf /tmp/test-gnunet-gns-peer-1/ 54rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
55 55
56if [ "$RES_CNAME_RAW" == "server.$TESTEGOZONE" ] 56if [ "$RES_CNAME_RAW" == "server.$TESTEGOZONE" ]
57then 57then
diff --git a/src/gns/test_gns_defaults.conf b/src/gns/test_gns_defaults.conf
index 27e9c2c31..01825fafe 100644
--- a/src/gns/test_gns_defaults.conf
+++ b/src/gns/test_gns_defaults.conf
@@ -1,7 +1,7 @@
1@INLINE@ ../../contrib/no_forcestart.conf 1@INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf
2 2
3[PATHS] 3[PATHS]
4GNUNET_TEST_HOME = /tmp/test-gnunet-gns-testing/ 4GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-gns-testing/
5 5
6[namestore-sqlite] 6[namestore-sqlite]
7FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db 7FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db
diff --git a/src/gns/test_gns_delegated_lookup.sh b/src/gns/test_gns_delegated_lookup.sh
index edda688ff..3374f1b3b 100755
--- a/src/gns/test_gns_delegated_lookup.sh
+++ b/src/gns/test_gns_delegated_lookup.sh
@@ -14,7 +14,7 @@ then
14 exit 77 14 exit 77
15fi 15fi
16 16
17rm -rf /tmp/test-gnunet-gns-peer-1/ 17rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
18MY_EGO="myego" 18MY_EGO="myego"
19OTHER_EGO="delegatedego" 19OTHER_EGO="delegatedego"
20FINAL_LABEL="www" 20FINAL_LABEL="www"
@@ -32,7 +32,7 @@ gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test
32gnunet-namestore -z $OTHER_EGO -d -n $FINAL_LABEL -t A -V $TEST_IP -e never -c test_gns_lookup.conf 32gnunet-namestore -z $OTHER_EGO -d -n $FINAL_LABEL -t A -V $TEST_IP -e never -c test_gns_lookup.conf
33gnunet-arm -e -c test_gns_lookup.conf 33gnunet-arm -e -c test_gns_lookup.conf
34 34
35rm -rf /tmp/test-gnunet-gns-peer-1/ 35rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
36 36
37if [ "$RES_IP" == "$TEST_IP" ] 37if [ "$RES_IP" == "$TEST_IP" ]
38then 38then
diff --git a/src/gns/test_gns_dht_lookup.sh b/src/gns/test_gns_dht_lookup.sh
index 365c77339..6c977bb0d 100755
--- a/src/gns/test_gns_dht_lookup.sh
+++ b/src/gns/test_gns_dht_lookup.sh
@@ -18,7 +18,7 @@ TEST_IP="127.0.0.1"
18MY_EGO="myego" 18MY_EGO="myego"
19OTHER_EGO="delegatedego" 19OTHER_EGO="delegatedego"
20 20
21 21rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
22gnunet-arm -s -c test_gns_lookup.conf 22gnunet-arm -s -c test_gns_lookup.conf
23gnunet-identity -C $OTHER_EGO -c test_gns_lookup.conf 23gnunet-identity -C $OTHER_EGO -c test_gns_lookup.conf
24DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep $OTHER_EGO | awk '{print $3}') 24DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep $OTHER_EGO | awk '{print $3}')
@@ -31,7 +31,7 @@ gnunet-namestore -z $OTHER_EGO -d -n www -t A -V $TEST_IP -e never -c test_gns_
31RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u www.b.$MY_EGO -t A -c test_gns_lookup.conf` 31RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u www.b.$MY_EGO -t A -c test_gns_lookup.conf`
32gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf 32gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
33gnunet-arm -e -c test_gns_lookup.conf 33gnunet-arm -e -c test_gns_lookup.conf
34rm -rf /tmp/test-gnunet-gns-peer-1/ 34rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
35 35
36if [ "$RES_IP" == "$TEST_IP" ] 36if [ "$RES_IP" == "$TEST_IP" ]
37then 37then
diff --git a/src/gns/test_gns_gns2dns_cname_lookup.sh b/src/gns/test_gns_gns2dns_cname_lookup.sh
new file mode 100755
index 000000000..32e730d4c
--- /dev/null
+++ b/src/gns/test_gns_gns2dns_cname_lookup.sh
@@ -0,0 +1,89 @@
1#!/bin/bash
2trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
17# IP address of 'www.gnunet.org'
18TEST_IP="131.159.74.67"
19# IPv6 address of 'gnunet.org'
20TEST_IP6="2001:4ca0:2001:42:225:90ff:fe6b:d60"
21
22# main label used during resolution
23TEST_RECORD_NAME="homepage"
24
25XNS=ns.joker.com
26
27if ! nslookup gnunet.org a.$XNS &> /dev/null
28then
29 echo "Cannot reach DNS, skipping test"
30 exit 77
31fi
32
33# helper record for pointing to the DNS resolver
34TEST_RESOLVER_LABEL="resolver"
35# GNS2DNS record value: delegate to DNS domain 'gnunet.org'
36# using the TEST_RESOLVER_LABEL DNS server for resolution
37TEST_RECORD_GNS2DNS1="gnunet.org@a.$XNS"
38TEST_RECORD_GNS2DNS2="gnunet.org@b.$XNS"
39TEST_RECORD_GNS2DNS3="gnunet.org@c.$XNS"
40
41MY_EGO="myego"
42# various names we will use for resolution
43TEST_DOMAIN="www.${TEST_RECORD_NAME}.$MY_EGO"
44
45gnunet-arm -s -c test_gns_lookup.conf
46gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
47
48# set IP address for DNS resolver for resolving in gnunet.org domain
49# map '$TEST_RECORD_NAME.$MY_EGO' to 'gnunet.org' in DNS
50gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS1 -e never -c test_gns_lookup.conf
51gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS2 -e never -c test_gns_lookup.conf
52gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS3 -e never -c test_gns_lookup.conf
53
54which timeout &> /dev/null && DO_TIMEOUT="timeout 15"
55
56echo "EGOs:"
57gnunet-identity -d
58
59# lookup 'www.gnunet.org', IPv4
60RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN -t A -c test_gns_lookup.conf`
61# lookup 'www.gnunet.org', IPv6
62RES_IP6=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN -t AAAA -c test_gns_lookup.conf`
63
64# clean up
65gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS1 -e never -c test_gns_lookup.conf
66gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS2 -e never -c test_gns_lookup.conf
67gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS3 -e never -c test_gns_lookup.conf
68gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
69gnunet-arm -e -c test_gns_lookup.conf
70rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
71
72ret=0
73if [ "$RES_IP" == "$TEST_IP" ]
74then
75 echo "PASS: Resolved $TEST_DOMAIN to $RES_IP."
76else
77 echo "Failed to resolve to proper IP for $TEST_DOMAIN, got $RES_IP, wanted $TEST_IP."
78 ret=1
79fi
80
81if [ "$RES_IP6" == "$TEST_IP6" ]
82then
83 echo "PASS: Resolved $TEST_DOMAIN to $RES_IP6."
84else
85 echo "Failed to resolve to proper IP for $TEST_DOMAIN, got $RES_IP6, wanted $TEST_IP6."
86 ret=1
87fi
88
89exit $ret
diff --git a/src/gns/test_gns_gns2dns_lookup.sh b/src/gns/test_gns_gns2dns_lookup.sh
index 921d9594d..ad5d762eb 100755
--- a/src/gns/test_gns_gns2dns_lookup.sh
+++ b/src/gns/test_gns_gns2dns_lookup.sh
@@ -13,7 +13,7 @@ then
13 exit 77 13 exit 77
14fi 14fi
15 15
16rm -r rm -rf /tmp/test-gnunet-gns-peer-1/ 16rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
17# IP address of 'uk.gnunet.org' 17# IP address of 'uk.gnunet.org'
18TEST_IP_ALT2="81.187.252.184" 18TEST_IP_ALT2="81.187.252.184"
19# IP address of 'www.gnunet.org' 19# IP address of 'www.gnunet.org'
@@ -72,7 +72,7 @@ gnunet-namestore -z $MY_EGO -d -n $TEST_RESOLVER_LABEL -t A -V $TEST_IP_GNS2DNS
72gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS -e never -c test_gns_lookup.conf 72gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS -e never -c test_gns_lookup.conf
73gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 73gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
74gnunet-arm -e -c test_gns_lookup.conf 74gnunet-arm -e -c test_gns_lookup.conf
75rm -rf /tmp/test-gnunet-gns-peer-1/ 75rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
76 76
77ret=0 77ret=0
78if [ "$RES_IP" == "$TEST_IP" ] 78if [ "$RES_IP" == "$TEST_IP" ]
diff --git a/src/gns/test_gns_ipv6_lookup.sh b/src/gns/test_gns_ipv6_lookup.sh
index 118c23060..301e6ae0c 100755
--- a/src/gns/test_gns_ipv6_lookup.sh
+++ b/src/gns/test_gns_ipv6_lookup.sh
@@ -24,7 +24,7 @@ RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u www.$MY_EGO -t AAAA -c test_gns_lookup.c
24gnunet-namestore -z $MY_EGO -d -n www -t AAAA -V $TEST_IP -e never -c test_gns_lookup.conf 24gnunet-namestore -z $MY_EGO -d -n www -t AAAA -V $TEST_IP -e never -c test_gns_lookup.conf
25gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 25gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
26gnunet-arm -e -c test_gns_lookup.conf 26gnunet-arm -e -c test_gns_lookup.conf
27rm -rf /tmp/test-gnunet-gns-peer-1/ 27rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
28 28
29if [ "$RES_IP" == "$TEST_IP" ] 29if [ "$RES_IP" == "$TEST_IP" ]
30then 30then
diff --git a/src/gns/test_gns_lookup.conf b/src/gns/test_gns_lookup.conf
index a9a2345c7..0d9d2b49a 100644
--- a/src/gns/test_gns_lookup.conf
+++ b/src/gns/test_gns_lookup.conf
@@ -1,17 +1,17 @@
1@INLINE@ test_gns_defaults.conf 1@INLINE@ test_gns_defaults.conf
2 2
3[PATHS] 3[PATHS]
4GNUNET_TEST_HOME = /tmp/test-gnunet-gns-peer-1/ 4GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-gns-peer-1/
5 5
6[dht] 6[dht]
7AUTOSTART = YES 7START_ON_DEMAND = YES
8 8
9[transport] 9[transport]
10PLUGINS = 10PLUGINS =
11 11
12[gns] 12[gns]
13# PREFIX = valgrind --leak-check=full --track-origins=yes 13# PREFIX = valgrind --leak-check=full --track-origins=yes
14AUTOSTART = YES 14START_ON_DEMAND = YES
15AUTO_IMPORT_PKEY = YES 15AUTO_IMPORT_PKEY = YES
16MAX_PARALLEL_BACKGROUND_QUERIES = 10 16MAX_PARALLEL_BACKGROUND_QUERIES = 10
17DEFAULT_LOOKUP_TIMEOUT = 15 s 17DEFAULT_LOOKUP_TIMEOUT = 15 s
diff --git a/src/gns/test_gns_mx_lookup.sh b/src/gns/test_gns_mx_lookup.sh
index 8abc9f509..5a7ef21c3 100755
--- a/src/gns/test_gns_mx_lookup.sh
+++ b/src/gns/test_gns_mx_lookup.sh
@@ -13,7 +13,7 @@ then
13 exit 77 13 exit 77
14fi 14fi
15 15
16rm -rf /tmp/test-gnunet-gns-peer-1/ 16rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
17which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 17which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
18 18
19MY_EGO="myego" 19MY_EGO="myego"
@@ -28,7 +28,7 @@ RES_MX=`$DO_TIMEOUT gnunet-gns --raw -u www.$MY_EGO -t MX -c test_gns_lookup.con
28gnunet-namestore -z $MY_EGO -d -n www -t MX -V "$TEST_MX" -e never -c test_gns_lookup.conf 28gnunet-namestore -z $MY_EGO -d -n www -t MX -V "$TEST_MX" -e never -c test_gns_lookup.conf
29gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 29gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
30gnunet-arm -e -c test_gns_lookup.conf 30gnunet-arm -e -c test_gns_lookup.conf
31rm -rf /tmp/test-gnunet-gns-peer-1/ 31rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
32 32
33if [ "$RES_MX" == "$WANT_MX" ] 33if [ "$RES_MX" == "$WANT_MX" ]
34then 34then
diff --git a/src/gns/test_gns_nick_shorten.conf b/src/gns/test_gns_nick_shorten.conf
index eac9fee43..317477c80 100644
--- a/src/gns/test_gns_nick_shorten.conf
+++ b/src/gns/test_gns_nick_shorten.conf
@@ -1,17 +1,17 @@
1@INLINE@ test_gns_defaults.conf 1@INLINE@ test_gns_defaults.conf
2 2
3[PATHS] 3[PATHS]
4GNUNET_TEST_HOME = /tmp/test-gnunet-gns-peer-1/ 4GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-gns-peer-1/
5 5
6[dht] 6[dht]
7AUTOSTART = YES 7START_ON_DEMAND = YES
8 8
9[transport] 9[transport]
10PLUGINS = 10PLUGINS =
11 11
12[gns] 12[gns]
13#PREFIX = valgrind --leak-check=full --track-origins=yes 13#PREFIX = valgrind --leak-check=full --track-origins=yes
14AUTOSTART = YES 14START_ON_DEMAND = YES
15AUTO_IMPORT_PKEY = YES 15AUTO_IMPORT_PKEY = YES
16MAX_PARALLEL_BACKGROUND_QUERIES = 10 16MAX_PARALLEL_BACKGROUND_QUERIES = 10
17DEFAULT_LOOKUP_TIMEOUT = 15 s 17DEFAULT_LOOKUP_TIMEOUT = 15 s
diff --git a/src/gns/test_gns_proxy.c b/src/gns/test_gns_proxy.c
index b381f5b4f..4c915cabe 100644
--- a/src/gns/test_gns_proxy.c
+++ b/src/gns/test_gns_proxy.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2007, 2009, 2011, 2012 Christian Grothoff 3 Copyright (C) 2007, 2009, 2011, 2012 Christian Grothoff
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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20 18
21/** 19/**
diff --git a/src/gns/test_gns_proxy.conf b/src/gns/test_gns_proxy.conf
index fb1b0c7c8..51edd5a0c 100644
--- a/src/gns/test_gns_proxy.conf
+++ b/src/gns/test_gns_proxy.conf
@@ -1,5 +1,5 @@
1[PATHS] 1[PATHS]
2GNUNET_TEST_HOME = /tmp/gnunet-test-gns-proxy/ 2GNUNET_TEST_HOME = $GNUNET_TMP/gnunet-test-gns-proxy/
3 3
4[transport] 4[transport]
5PLUGINS = tcp 5PLUGINS = tcp
@@ -13,7 +13,7 @@ WEAKRANDOM = YES
13HOSTKEYSFILE = ${DATADIR}/testing_hostkeys.dat 13HOSTKEYSFILE = ${DATADIR}/testing_hostkeys.dat
14 14
15[gns] 15[gns]
16AUTOSTART = YES 16START_ON_DEMAND = YES
17ZONEKEY = $GNUNET_TEST_HOME/.zonekey 17ZONEKEY = $GNUNET_TEST_HOME/.zonekey
18HIJACK_DNS = YES 18HIJACK_DNS = YES
19 19
@@ -22,7 +22,7 @@ PROXY_CACERT = proxy/test_cert.pem
22PROXY_UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-gns-proxy.sock 22PROXY_UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-gns-proxy.sock
23 23
24[namestore] 24[namestore]
25AUTOSTART = YES 25START_ON_DEMAND = YES
26 26
27[dns] 27[dns]
28PROVIDE_EXIT = NO 28PROVIDE_EXIT = NO
diff --git a/src/gns/test_gns_quickupdate.sh b/src/gns/test_gns_quickupdate.sh
index 5606491e4..e0eb33f2e 100755
--- a/src/gns/test_gns_quickupdate.sh
+++ b/src/gns/test_gns_quickupdate.sh
@@ -17,7 +17,7 @@ MY_EGO="myego"
17OTHER_EGO="delegatedego" 17OTHER_EGO="delegatedego"
18 18
19 19
20rm -rf /tmp/test-gnunet-gns-peer-1/ 20rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
21which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 21which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
22TEST_IP="127.0.0.1" 22TEST_IP="127.0.0.1"
23gnunet-arm -s -c test_gns_lookup.conf 23gnunet-arm -s -c test_gns_lookup.conf
@@ -53,7 +53,7 @@ gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test
53gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 53gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
54gnunet-identity -D $OTHER_EGO -c test_gns_lookup.conf 54gnunet-identity -D $OTHER_EGO -c test_gns_lookup.conf
55gnunet-arm -e -c test_gns_lookup.conf 55gnunet-arm -e -c test_gns_lookup.conf
56rm -rf /tmp/test-gnunet-gns-peer-1/ 56rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
57 57
58if [ "$RES_IP" == "$TEST_IP" ] 58if [ "$RES_IP" == "$TEST_IP" ]
59then 59then
diff --git a/src/gns/test_gns_rel_expiration.sh b/src/gns/test_gns_rel_expiration.sh
index 992098db3..a266a7484 100755
--- a/src/gns/test_gns_rel_expiration.sh
+++ b/src/gns/test_gns_rel_expiration.sh
@@ -16,7 +16,7 @@ fi
16MY_EGO="myego" 16MY_EGO="myego"
17OTHER_EGO="delegatedego" 17OTHER_EGO="delegatedego"
18 18
19rm -rf /tmp/test-gnunet-gns-peer-1/ 19rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
20which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 20which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
21TEST_IP="127.0.0.1" 21TEST_IP="127.0.0.1"
22gnunet-arm -s -c test_gns_lookup.conf 22gnunet-arm -s -c test_gns_lookup.conf
@@ -38,7 +38,7 @@ gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test
38gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 38gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
39gnunet-identity -D $OTHER_EGO -c test_gns_lookup.conf 39gnunet-identity -D $OTHER_EGO -c test_gns_lookup.conf
40gnunet-arm -e -c test_gns_lookup.conf 40gnunet-arm -e -c test_gns_lookup.conf
41rm -rf /tmp/test-gnunet-gns-peer-1/ 41rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
42 42
43if [ "$RES_IP_EXP" == "$TEST_IP" ] 43if [ "$RES_IP_EXP" == "$TEST_IP" ]
44then 44then
diff --git a/src/gns/test_gns_revocation.sh b/src/gns/test_gns_revocation.sh
index 269b940d9..12f0c0881 100755
--- a/src/gns/test_gns_revocation.sh
+++ b/src/gns/test_gns_revocation.sh
@@ -14,7 +14,7 @@ then
14 exit 77 14 exit 77
15fi 15fi
16 16
17rm -rf /tmp/test-gnunet-gns-peer-1/ 17rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
18MY_EGO="myego" 18MY_EGO="myego"
19OTHER_EGO="delegatedego" 19OTHER_EGO="delegatedego"
20TEST_IP="127.0.0.1" 20TEST_IP="127.0.0.1"
@@ -31,7 +31,7 @@ RES_IP_REV=`$DO_TIMEOUT gnunet-gns --raw -u www.b.$MY_EGO -t A -c test_gns_looku
31gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf 31gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
32gnunet-namestore -z $OTHER_EGO -d -n www -t A -V $TEST_IP -e never -c test_gns_lookup.conf 32gnunet-namestore -z $OTHER_EGO -d -n www -t A -V $TEST_IP -e never -c test_gns_lookup.conf
33gnunet-arm -e -c test_gns_lookup.conf 33gnunet-arm -e -c test_gns_lookup.conf
34rm -rf /tmp/test-gnunet-gns-peer-1/ 34rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
35 35
36if [ "$RES_IP" != "$TEST_IP" ] 36if [ "$RES_IP" != "$TEST_IP" ]
37then 37then
diff --git a/src/gns/test_gns_simple_lookup.conf b/src/gns/test_gns_simple_lookup.conf
index 77ee8fc18..374731377 100644
--- a/src/gns/test_gns_simple_lookup.conf
+++ b/src/gns/test_gns_simple_lookup.conf
@@ -1,13 +1,13 @@
1@INLINE@ test_gns_defaults.conf 1@INLINE@ test_gns_defaults.conf
2[fs] 2[fs]
3AUTOSTART = NO 3START_ON_DEMAND = NO
4 4
5[resolver] 5[resolver]
6AUTOSTART = YES 6START_ON_DEMAND = YES
7HOSTNAME = localhost 7HOSTNAME = localhost
8 8
9[dht] 9[dht]
10AUTOSTART = YES 10START_ON_DEMAND = YES
11ACCEPT_FROM6 = ::1; 11ACCEPT_FROM6 = ::1;
12ACCEPT_FROM = 127.0.0.1; 12ACCEPT_FROM = 127.0.0.1;
13HOSTNAME = localhost 13HOSTNAME = localhost
@@ -41,7 +41,7 @@ PORT = 12368
41BINDTO = 127.0.0.1 41BINDTO = 127.0.0.1
42 42
43[PATHS] 43[PATHS]
44GNUNET_TEST_HOME = /tmp/test-gnunetd-gns-peer-1/ 44GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunetd-gns-peer-1/
45 45
46 46
47[nat] 47[nat]
@@ -54,12 +54,12 @@ EXTERNAL_ADDRESS = 127.0.0.1
54USE_LOCALADDR = NO 54USE_LOCALADDR = NO
55 55
56[dns] 56[dns]
57AUTOSTART = YES 57START_ON_DEMAND = YES
58DNS_EXIT = 8.8.8.8 58DNS_EXIT = 8.8.8.8
59 59
60[gns] 60[gns]
61#PREFIX = valgrind --leak-check=full --track-origins=yes 61#PREFIX = valgrind --leak-check=full --track-origins=yes
62AUTOSTART = YES 62START_ON_DEMAND = YES
63BINARY = gnunet-service-gns 63BINARY = gnunet-service-gns
64ZONEKEY = zonefiles/test_zonekey 64ZONEKEY = zonefiles/test_zonekey
65PRIVATE_ZONE = private 65PRIVATE_ZONE = private
@@ -75,14 +75,14 @@ DEFAULT_LOOKUP_TIMEOUT = 15 s
75RECORD_PUT_INTERVAL = 1 h 75RECORD_PUT_INTERVAL = 1 h
76 76
77[nse] 77[nse]
78AUTOSTART = NO 78START_ON_DEMAND = NO
79 79
80[statistics] 80[statistics]
81AUTOSTART = NO 81START_ON_DEMAND = NO
82 82
83[namestore] 83[namestore]
84PORT = 22371 84PORT = 22371
85AUTOSTART = YES 85START_ON_DEMAND = YES
86UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-namestore-default.sock 86UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-namestore-default.sock
87UNIX_MATCH_UID = YES 87UNIX_MATCH_UID = YES
88UNIX_MATCH_GID = YES 88UNIX_MATCH_GID = YES
diff --git a/src/gns/test_gns_soa_lookup.sh b/src/gns/test_gns_soa_lookup.sh
index 2f9cc58de..82a5885c3 100755
--- a/src/gns/test_gns_soa_lookup.sh
+++ b/src/gns/test_gns_soa_lookup.sh
@@ -15,7 +15,7 @@ fi
15 15
16which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 16which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
17 17
18rm -rf /tmp/test-gnunet-gns-peer-1/ 18rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
19MY_EGO="myego" 19MY_EGO="myego"
20TEST_DOMAIN="homepage.$MY_EGO" 20TEST_DOMAIN="homepage.$MY_EGO"
21# some public DNS resolver we can use 21# some public DNS resolver we can use
@@ -36,7 +36,7 @@ RES_SOA=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN -t SOA -c test_gns_lookup.
36gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V ${TEST_RECORD_GNS2DNS}@${TEST_IP_GNS2DNS} -e never -c test_gns_lookup.conf &> /dev/null 36gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V ${TEST_RECORD_GNS2DNS}@${TEST_IP_GNS2DNS} -e never -c test_gns_lookup.conf &> /dev/null
37gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 37gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
38gnunet-arm -e -c test_gns_lookup.conf 38gnunet-arm -e -c test_gns_lookup.conf
39rm -rf /tmp/test-gnunet-gns-peer-1/ 39rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
40 40
41if [ "x$RES_SOA" != "x" ] 41if [ "x$RES_SOA" != "x" ]
42then 42then
diff --git a/src/gns/test_gns_txt_lookup.sh b/src/gns/test_gns_txt_lookup.sh
index 68a60c8b6..ce9b9e806 100755
--- a/src/gns/test_gns_txt_lookup.sh
+++ b/src/gns/test_gns_txt_lookup.sh
@@ -13,7 +13,7 @@ then
13 exit 77 13 exit 77
14fi 14fi
15 15
16rm -rf /tmp/test-gnunet-gns-peer-1/ 16rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
17which timeout &> /dev/null && DO_TIMEOUT="timeout 30" 17which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
18TEST_TXT="GNS powered txt record data" 18TEST_TXT="GNS powered txt record data"
19MY_EGO="myego" 19MY_EGO="myego"
@@ -25,7 +25,7 @@ RES_TXT=`$DO_TIMEOUT gnunet-gns --raw -u $LABEL.$MY_EGO -t TXT -c test_gns_looku
25gnunet-namestore -z $MY_EGO -d -n $LABEL -t TXT -V "$TEST_TXT" -e never -c test_gns_lookup.conf 25gnunet-namestore -z $MY_EGO -d -n $LABEL -t TXT -V "$TEST_TXT" -e never -c test_gns_lookup.conf
26gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 26gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
27gnunet-arm -e -c test_gns_lookup.conf 27gnunet-arm -e -c test_gns_lookup.conf
28rm -rf /tmp/test-gnunet-gns-peer-1/ 28rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
29 29
30if [ "$RES_TXT" == "$TEST_TXT" ] 30if [ "$RES_TXT" == "$TEST_TXT" ]
31then 31then
diff --git a/src/gns/test_gns_zkey_lookup.sh b/src/gns/test_gns_zkey_lookup.sh
index 312198780..5e67e0ce2 100755
--- a/src/gns/test_gns_zkey_lookup.sh
+++ b/src/gns/test_gns_zkey_lookup.sh
@@ -14,7 +14,7 @@ then
14 exit 77 14 exit 77
15fi 15fi
16 16
17rm -rf /tmp/test-gnunet-gns-peer-1/ 17rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
18 18
19TEST_IP="127.0.0.1" 19TEST_IP="127.0.0.1"
20gnunet-arm -s -c test_gns_lookup.conf 20gnunet-arm -s -c test_gns_lookup.conf
@@ -27,7 +27,7 @@ RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u www.${DELEGATED_PKEY} -t A -c test_gns_l
27gnunet-namestore -z testego -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf 27gnunet-namestore -z testego -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
28gnunet-namestore -z delegatedego -d -n www -t A -V $TEST_IP -e never -c test_gns_lookup.conf 28gnunet-namestore -z delegatedego -d -n www -t A -V $TEST_IP -e never -c test_gns_lookup.conf
29gnunet-arm -e -c test_gns_lookup.conf 29gnunet-arm -e -c test_gns_lookup.conf
30rm -rf /tmp/test-gnunet-gns-peer-1/ 30rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
31 31
32if [ "$RES_IP" == "$TEST_IP" ] 32if [ "$RES_IP" == "$TEST_IP" ]
33then 33then
diff --git a/src/gns/w32nsp-install.c b/src/gns/w32nsp-install.c
index a4da577ba..7a8beb703 100644
--- a/src/gns/w32nsp-install.c
+++ b/src/gns/w32nsp-install.c
@@ -2,20 +2,18 @@
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 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gns/w32nsp-install.c 19 * @file gns/w32nsp-install.c
diff --git a/src/gns/w32nsp-resolve.c b/src/gns/w32nsp-resolve.c
index 82f15c6cc..c1178cb23 100644
--- a/src/gns/w32nsp-resolve.c
+++ b/src/gns/w32nsp-resolve.c
@@ -2,20 +2,18 @@
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 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gns/w32nsp-resolve.c 19 * @file gns/w32nsp-resolve.c
diff --git a/src/gns/w32nsp.c b/src/gns/w32nsp.c
index 3e926fcc4..082319ffe 100644
--- a/src/gns/w32nsp.c
+++ b/src/gns/w32nsp.c
@@ -2,20 +2,18 @@
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 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file gns/w32nsp.c 19 * @file gns/w32nsp.c
diff --git a/src/gns/w32resolver.h b/src/gns/w32resolver.h
index cac082b42..8649d82d4 100644
--- a/src/gns/w32resolver.h
+++ b/src/gns/w32resolver.h
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009, 2012 GNUnet e.V. 3 Copyright (C) 2009, 2012 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 it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20 18
21/** 19/**