aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/.gitignore5
-rw-r--r--src/util/Makefile.am38
-rw-r--r--src/util/bandwidth.c18
-rw-r--r--src/util/bio.c18
-rw-r--r--src/util/client.c27
-rw-r--r--src/util/common_allocation.c18
-rw-r--r--src/util/common_endian.c18
-rw-r--r--src/util/common_logging.c183
-rw-r--r--src/util/configuration.c18
-rw-r--r--src/util/configuration_loader.c18
-rw-r--r--src/util/container_bloomfilter.c18
-rw-r--r--src/util/container_heap.c18
-rw-r--r--src/util/container_meta_data.c18
-rw-r--r--src/util/container_multihashmap.c18
-rw-r--r--src/util/container_multihashmap32.c18
-rw-r--r--src/util/container_multipeermap.c18
-rw-r--r--src/util/container_multishortmap.c18
-rw-r--r--src/util/crypto_abe.c46
-rw-r--r--src/util/crypto_crc.c18
-rw-r--r--src/util/crypto_ecc.c187
-rw-r--r--src/util/crypto_ecc_dlog.c18
-rw-r--r--src/util/crypto_ecc_setup.c29
-rw-r--r--src/util/crypto_hash.c44
-rw-r--r--src/util/crypto_hash_file.c18
-rw-r--r--src/util/crypto_kdf.c18
-rw-r--r--src/util/crypto_mpi.c18
-rw-r--r--src/util/crypto_paillier.c18
-rw-r--r--src/util/crypto_random.c45
-rw-r--r--src/util/crypto_rsa.c29
-rw-r--r--src/util/crypto_symmetric.c18
-rw-r--r--src/util/disk.c116
-rw-r--r--src/util/disk.h18
-rw-r--r--src/util/dnsparser.c1458
-rw-r--r--src/util/dnsstub.c747
-rw-r--r--src/util/getopt_helpers.c101
-rw-r--r--src/util/gnunet-config.c57
-rw-r--r--src/util/gnunet-ecc.c18
-rw-r--r--src/util/gnunet-helper-w32-console.c18
-rw-r--r--src/util/gnunet-helper-w32-console.h18
-rwxr-xr-xsrc/util/gnunet-qr.py.in173
-rw-r--r--src/util/gnunet-resolver.c18
-rw-r--r--src/util/gnunet-scrypt.c18
-rw-r--r--src/util/gnunet-service-resolver.c1030
-rw-r--r--src/util/gnunet-timeout-w32.c191
-rw-r--r--src/util/gnunet-timeout.c128
-rw-r--r--src/util/gnunet-uri.c18
-rw-r--r--src/util/helper.c18
-rw-r--r--src/util/load.c18
-rw-r--r--src/util/mq.c81
-rw-r--r--src/util/mst.c18
-rw-r--r--src/util/nc.c18
-rw-r--r--src/util/network.c18
-rw-r--r--src/util/op.c18
-rw-r--r--src/util/os_installation.c18
-rw-r--r--src/util/os_network.c18
-rw-r--r--src/util/os_priority.c24
-rw-r--r--src/util/peer.c18
-rw-r--r--src/util/perf_crypto_asymmetric.c18
-rw-r--r--src/util/perf_crypto_ecc_dlog.c18
-rw-r--r--src/util/perf_crypto_hash.c18
-rw-r--r--src/util/perf_crypto_paillier.c18
-rw-r--r--src/util/perf_crypto_rsa.c18
-rw-r--r--src/util/perf_crypto_symmetric.c18
-rw-r--r--src/util/perf_malloc.c18
-rw-r--r--src/util/plugin.c18
-rw-r--r--src/util/program.c18
-rw-r--r--src/util/regex.c834
-rw-r--r--src/util/resolver.conf.in2
-rw-r--r--src/util/resolver.h45
-rw-r--r--src/util/resolver_api.c74
-rw-r--r--src/util/scheduler.c207
-rw-r--r--src/util/service.c58
-rw-r--r--src/util/signal.c18
-rw-r--r--src/util/socks.c18
-rw-r--r--src/util/speedup.c18
-rw-r--r--src/util/speedup.h18
-rw-r--r--src/util/strings.c53
-rw-r--r--src/util/test_bio.c18
-rw-r--r--src/util/test_client.c18
-rw-r--r--src/util/test_common_allocation.c18
-rw-r--r--src/util/test_common_endian.c18
-rw-r--r--src/util/test_common_logging.c18
-rw-r--r--src/util/test_common_logging_dummy.c18
-rw-r--r--src/util/test_common_logging_runtime_loglevels.c18
-rw-r--r--src/util/test_configuration.c18
-rw-r--r--src/util/test_configuration_data.conf2
-rw-r--r--src/util/test_container_bloomfilter.c18
-rw-r--r--src/util/test_container_dll.c16
-rw-r--r--src/util/test_container_heap.c16
-rw-r--r--src/util/test_container_meta_data.c18
-rw-r--r--src/util/test_container_multihashmap.c18
-rw-r--r--src/util/test_container_multihashmap32.c18
-rw-r--r--src/util/test_container_multipeermap.c18
-rw-r--r--src/util/test_crypto_crc.c18
-rw-r--r--src/util/test_crypto_ecc_dlog.c18
-rw-r--r--src/util/test_crypto_ecdh_eddsa.c70
-rw-r--r--src/util/test_crypto_ecdhe.c43
-rw-r--r--src/util/test_crypto_ecdsa.c18
-rw-r--r--src/util/test_crypto_eddsa.c18
-rw-r--r--src/util/test_crypto_hash.c18
-rw-r--r--src/util/test_crypto_hash_context.c22
-rw-r--r--src/util/test_crypto_paillier.c18
-rw-r--r--src/util/test_crypto_random.c18
-rw-r--r--src/util/test_crypto_rsa.c20
-rw-r--r--src/util/test_crypto_symmetric.c18
-rw-r--r--src/util/test_disk.c18
-rw-r--r--src/util/test_getopt.c18
-rw-r--r--src/util/test_hexcoder.c54
-rw-r--r--src/util/test_mq.c294
-rw-r--r--src/util/test_os_network.c18
-rw-r--r--src/util/test_os_start_process.c18
-rw-r--r--src/util/test_peer.c18
-rw-r--r--src/util/test_plugin.c18
-rw-r--r--src/util/test_plugin_plug.c18
-rw-r--r--src/util/test_program.c18
-rw-r--r--src/util/test_regex.c179
-rw-r--r--src/util/test_resolver_api.c18
-rw-r--r--src/util/test_resolver_api_data.conf2
-rw-r--r--src/util/test_scheduler.c18
-rw-r--r--src/util/test_scheduler_delay.c18
-rw-r--r--src/util/test_service.c18
-rw-r--r--src/util/test_service_data.conf4
-rw-r--r--src/util/test_socks.c18
-rw-r--r--src/util/test_speedup.c18
-rw-r--r--src/util/test_strings.c18
-rw-r--r--src/util/test_strings_to_data.c18
-rw-r--r--src/util/test_time.c18
-rw-r--r--src/util/test_tun.c72
-rw-r--r--src/util/time.c18
-rw-r--r--src/util/tun.c309
-rw-r--r--src/util/util.conf5
-rw-r--r--src/util/win.c18
-rw-r--r--src/util/winproc.c18
133 files changed, 6708 insertions, 2032 deletions
diff --git a/src/util/.gitignore b/src/util/.gitignore
index d32a66833..7b190ca76 100644
--- a/src/util/.gitignore
+++ b/src/util/.gitignore
@@ -68,3 +68,8 @@ perf_crypto_asymmetric
68perf_crypto_hash 68perf_crypto_hash
69perf_crypto_symmetric 69perf_crypto_symmetric
70perf_crypto_rsa 70perf_crypto_rsa
71perf_crypto_ecc_dlog
72test_hexcoder
73test_regex
74test_tun
75gnunet-timeout
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index eb655157d..4ae073c2c 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -89,6 +89,8 @@ libgnunetutil_la_SOURCES = \
89 crypto_rsa.c \ 89 crypto_rsa.c \
90 disk.c \ 90 disk.c \
91 disk.h \ 91 disk.h \
92 dnsparser.c \
93 dnsstub.c \
92 getopt.c \ 94 getopt.c \
93 getopt_helpers.c \ 95 getopt_helpers.c \
94 helper.c \ 96 helper.c \
@@ -104,12 +106,14 @@ libgnunetutil_la_SOURCES = \
104 peer.c \ 106 peer.c \
105 plugin.c \ 107 plugin.c \
106 program.c \ 108 program.c \
109 regex.c \
107 resolver_api.c resolver.h \ 110 resolver_api.c resolver.h \
108 scheduler.c \ 111 scheduler.c \
109 service.c \ 112 service.c \
110 signal.c \ 113 signal.c \
111 strings.c \ 114 strings.c \
112 time.c \ 115 time.c \
116 tun.c \
113 speedup.c speedup.h 117 speedup.c speedup.h
114 118
115libgnunetutil_la_LIBADD = \ 119libgnunetutil_la_LIBADD = \
@@ -117,7 +121,7 @@ libgnunetutil_la_LIBADD = \
117 $(LIBGCRYPT_LIBS) \ 121 $(LIBGCRYPT_LIBS) \
118 $(LTLIBICONV) \ 122 $(LTLIBICONV) \
119 $(LTLIBINTL) \ 123 $(LTLIBINTL) \
120 -lltdl $(Z_LIBS) -lunistring $(XLIB) 124 -lltdl -lidn $(Z_LIBS) -lunistring $(XLIB)
121 125
122libgnunetutil_la_LDFLAGS = \ 126libgnunetutil_la_LDFLAGS = \
123 $(GN_LIB_LDFLAGS) \ 127 $(GN_LIB_LDFLAGS) \
@@ -162,6 +166,7 @@ lib_LTLIBRARIES = libgnunetutil.la
162 166
163libexec_PROGRAMS = \ 167libexec_PROGRAMS = \
164 gnunet-service-resolver \ 168 gnunet-service-resolver \
169 gnunet-timeout \
165 $(W32CONSOLEHELPER) 170 $(W32CONSOLEHELPER)
166 171
167bin_SCRIPTS =\ 172bin_SCRIPTS =\
@@ -188,6 +193,15 @@ endif
188endif 193endif
189 194
190 195
196if !MINGW
197gnunet_timeout_SOURCES = \
198 gnunet-timeout.c
199else
200gnunet_timeout_SOURCES = \
201 gnunet-timeout-w32.c
202endif
203
204
191do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' 205do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g'
192 206
193gnunet-qr: gnunet-qr.py.in Makefile 207gnunet-qr: gnunet-qr.py.in Makefile
@@ -199,6 +213,9 @@ gnunet_service_resolver_SOURCES = \
199gnunet_service_resolver_LDADD = \ 213gnunet_service_resolver_LDADD = \
200 libgnunetutil.la \ 214 libgnunetutil.la \
201 $(GN_LIBINTL) 215 $(GN_LIBINTL)
216if HAVE_GETADDRINFO_A
217gnunet_service_resolver_LDADD += -lanl
218endif
202 219
203 220
204gnunet_resolver_SOURCES = \ 221gnunet_resolver_SOURCES = \
@@ -288,19 +305,22 @@ check_PROGRAMS = \
288 test_crypto_rsa \ 305 test_crypto_rsa \
289 test_disk \ 306 test_disk \
290 test_getopt \ 307 test_getopt \
308 test_hexcoder \
291 test_mq \ 309 test_mq \
292 test_os_network \ 310 test_os_network \
293 test_peer \ 311 test_peer \
294 test_plugin \ 312 test_plugin \
295 test_program \ 313 test_program \
314 test_regex \
296 test_resolver_api.nc \ 315 test_resolver_api.nc \
297 test_scheduler \ 316 test_scheduler \
298 test_scheduler_delay \ 317 test_scheduler_delay \
299 test_service \ 318 test_service \
300 test_strings \ 319 test_strings \
301 test_strings_to_data \ 320 test_strings_to_data \
302 test_time \
303 test_speedup \ 321 test_speedup \
322 test_time \
323 test_tun \
304 $(BENCHMARKS) \ 324 $(BENCHMARKS) \
305 test_os_start_process \ 325 test_os_start_process \
306 test_common_logging_runtime_loglevels 326 test_common_logging_runtime_loglevels
@@ -316,6 +336,20 @@ test_bio_SOURCES = \
316test_bio_LDADD = \ 336test_bio_LDADD = \
317 libgnunetutil.la 337 libgnunetutil.la
318 338
339test_hexcoder_SOURCES = \
340 test_hexcoder.c
341test_hexcoder_LDADD = \
342 libgnunetutil.la
343
344test_tun_SOURCES = \
345 test_tun.c
346test_tun_LDADD = \
347 libgnunetutil.la
348
349test_regex_SOURCES = \
350 test_regex.c
351test_regex_LDADD = \
352 libgnunetutil.la
319 353
320test_os_start_process_SOURCES = \ 354test_os_start_process_SOURCES = \
321 test_os_start_process.c 355 test_os_start_process.c
diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c
index f551bbb82..5e0bae539 100644
--- a/src/util/bandwidth.c
+++ b/src/util/bandwidth.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/util/bio.c b/src/util/bio.c
index 816917a22..a31e5448f 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2006, 2009, 2013 GNUnet e.V. 3 Copyright (C) 2006, 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 util/bio.c 19 * @file util/bio.c
diff --git a/src/util/client.c b/src/util/client.c
index 3479fa971..1f569255a 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001-2016 GNUnet e.V. 3 Copyright (C) 2001-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/**
@@ -723,6 +721,17 @@ test_service_configuration (const char *service_name,
723 &unixpath)) && 721 &unixpath)) &&
724 (0 < strlen (unixpath))) 722 (0 < strlen (unixpath)))
725 ret = GNUNET_OK; 723 ret = GNUNET_OK;
724 else if ((GNUNET_OK ==
725 GNUNET_CONFIGURATION_have_value (cfg,
726 service_name,
727 "UNIXPATH")))
728 {
729 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
730 service_name,
731 "UNIXPATH",
732 _("not a valid filename"));
733 return GNUNET_SYSERR; /* UNIXPATH specified but invalid! */
734 }
726 GNUNET_free_non_null (unixpath); 735 GNUNET_free_non_null (unixpath);
727#endif 736#endif
728 737
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index 1c55d72b5..53e1a6707 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2005, 2006 GNUnet e.V. 3 Copyright (C) 2001, 2002, 2003, 2005, 2006 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/util/common_endian.c b/src/util/common_endian.c
index f29e42c98..502e1e3a3 100644
--- a/src/util/common_endian.c
+++ b/src/util/common_endian.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2004, 2006, 2012 GNUnet e.V. 3 Copyright (C) 2001, 2002, 2003, 2004, 2006, 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/**
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index ea5430191..be2e084b5 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2006-2013 GNUnet e.V. 3 Copyright (C) 2006-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/**
@@ -628,6 +626,9 @@ parse_definitions (const char *constname, int force)
628 to_line = INT_MAX; 626 to_line = INT_MAX;
629 } 627 }
630 break; 628 break;
629 default:
630 fprintf(stderr, "ERROR: Unable to parse log defintion: Syntax error.\n");
631 break;
631 } 632 }
632 start = p + 1; 633 start = p + 1;
633 state++; 634 state++;
@@ -654,6 +655,7 @@ parse_definitions (const char *constname, int force)
654 start = p + 1; 655 start = p + 1;
655 break; 656 break;
656 default: 657 default:
658 fprintf(stderr, "ERROR: Unable to parse log defintion: Syntax error.\n");
657 break; 659 break;
658 } 660 }
659 default: 661 default:
@@ -815,32 +817,39 @@ output_message (enum GNUNET_ErrorType kind,
815 if ( (NULL != GNUNET_stderr) && 817 if ( (NULL != GNUNET_stderr) &&
816 (NULL == loggers) ) 818 (NULL == loggers) )
817 { 819 {
818 if (kind == GNUNET_ERROR_TYPE_MESSAGE) { 820 if (kind == GNUNET_ERROR_TYPE_MESSAGE)
819 /* The idea here is to produce "normal" output messages 821 {
820 * for end users while still having the power of the 822 /* The idea here is to produce "normal" output messages
821 * logging engine for developer needs. So ideally this 823 * for end users while still having the power of the
822 * is what it should look like when CLI tools are used 824 * logging engine for developer needs. So ideally this
823 * interactively, yet the same message shouldn't look 825 * is what it should look like when CLI tools are used
824 * this way if the output is going to logfiles or robots 826 * interactively, yet the same message shouldn't look
825 * instead. Is this the right place to do this? --lynX 827 * this way if the output is going to logfiles or robots
826 */ 828 * instead.
827 FPRINTF (GNUNET_stderr, 829 */
828 "* %s", 830 FPRINTF (GNUNET_stderr,
829 msg); 831 "* %s",
830 } else { 832 msg);
831 FPRINTF (GNUNET_stderr, 833 }
832 "%s %s %s %s", 834 else
833 datestr, 835 {
834 comp, 836 FPRINTF (GNUNET_stderr,
835 GNUNET_error_type_to_string (kind), 837 "%s %s %s %s",
836 msg); 838 datestr,
839 comp,
840 GNUNET_error_type_to_string (kind),
841 msg);
837 } 842 }
838 fflush (GNUNET_stderr); 843 fflush (GNUNET_stderr);
839 } 844 }
840 pos = loggers; 845 pos = loggers;
841 while (pos != NULL) 846 while (NULL != pos)
842 { 847 {
843 pos->logger (pos->logger_cls, kind, comp, datestr, msg); 848 pos->logger (pos->logger_cls,
849 kind,
850 comp,
851 datestr,
852 msg);
844 pos = pos->next; 853 pos = pos->next;
845 } 854 }
846#if WINDOWS 855#if WINDOWS
@@ -1192,6 +1201,106 @@ GNUNET_h2s2 (const struct GNUNET_HashCode * hc)
1192 1201
1193/** 1202/**
1194 * @ingroup logging 1203 * @ingroup logging
1204 * Convert a public key value to a string (for printing debug messages).
1205 * This is one of the very few calls in the entire API that is
1206 * NOT reentrant!
1207 *
1208 * @param hc the hash code
1209 * @return string
1210 */
1211const char *
1212GNUNET_p2s (const struct GNUNET_CRYPTO_EddsaPublicKey *p)
1213{
1214 static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
1215 struct GNUNET_HashCode hc;
1216
1217 GNUNET_CRYPTO_hash (p,
1218 sizeof (*p),
1219 &hc);
1220 GNUNET_CRYPTO_hash_to_enc (&hc,
1221 &ret);
1222 ret.encoding[6] = '\0';
1223 return (const char *) ret.encoding;
1224}
1225
1226
1227/**
1228 * @ingroup logging
1229 * Convert a public key value to a string (for printing debug messages).
1230 * This is one of the very few calls in the entire API that is
1231 * NOT reentrant!
1232 *
1233 * @param hc the hash code
1234 * @return string
1235 */
1236const char *
1237GNUNET_p2s2 (const struct GNUNET_CRYPTO_EddsaPublicKey *p)
1238{
1239 static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
1240 struct GNUNET_HashCode hc;
1241
1242 GNUNET_CRYPTO_hash (p,
1243 sizeof (*p),
1244 &hc);
1245 GNUNET_CRYPTO_hash_to_enc (&hc,
1246 &ret);
1247 ret.encoding[6] = '\0';
1248 return (const char *) ret.encoding;
1249}
1250
1251
1252/**
1253 * @ingroup logging
1254 * Convert a public key value to a string (for printing debug messages).
1255 * This is one of the very few calls in the entire API that is
1256 * NOT reentrant!
1257 *
1258 * @param hc the hash code
1259 * @return string
1260 */
1261const char *
1262GNUNET_e2s (const struct GNUNET_CRYPTO_EcdhePublicKey *p)
1263{
1264 static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
1265 struct GNUNET_HashCode hc;
1266
1267 GNUNET_CRYPTO_hash (p,
1268 sizeof (*p),
1269 &hc);
1270 GNUNET_CRYPTO_hash_to_enc (&hc,
1271 &ret);
1272 ret.encoding[6] = '\0';
1273 return (const char *) ret.encoding;
1274}
1275
1276
1277/**
1278 * @ingroup logging
1279 * Convert a public key value to a string (for printing debug messages).
1280 * This is one of the very few calls in the entire API that is
1281 * NOT reentrant!
1282 *
1283 * @param hc the hash code
1284 * @return string
1285 */
1286const char *
1287GNUNET_e2s2 (const struct GNUNET_CRYPTO_EcdhePublicKey *p)
1288{
1289 static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
1290 struct GNUNET_HashCode hc;
1291
1292 GNUNET_CRYPTO_hash (p,
1293 sizeof (*p),
1294 &hc);
1295 GNUNET_CRYPTO_hash_to_enc (&hc,
1296 &ret);
1297 ret.encoding[6] = '\0';
1298 return (const char *) ret.encoding;
1299}
1300
1301
1302/**
1303 * @ingroup logging
1195 * Convert a short hash value to a string (for printing debug messages). 1304 * Convert a short hash value to a string (for printing debug messages).
1196 * This is one of the very few calls in the entire API that is 1305 * This is one of the very few calls in the entire API that is
1197 * NOT reentrant! 1306 * NOT reentrant!
@@ -1244,14 +1353,15 @@ GNUNET_h2s_full (const struct GNUNET_HashCode * hc)
1244const char * 1353const char *
1245GNUNET_i2s (const struct GNUNET_PeerIdentity *pid) 1354GNUNET_i2s (const struct GNUNET_PeerIdentity *pid)
1246{ 1355{
1247 static char buf[256]; 1356 static char buf[5];
1248 char *ret; 1357 char *ret;
1249 1358
1250 if (NULL == pid) 1359 if (NULL == pid)
1251 return "NULL"; 1360 return "NULL";
1252 ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); 1361 ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key);
1253 strcpy (buf, 1362 strncpy (buf,
1254 ret); 1363 ret,
1364 sizeof (buf) - 1);
1255 GNUNET_free (ret); 1365 GNUNET_free (ret);
1256 buf[4] = '\0'; 1366 buf[4] = '\0';
1257 return buf; 1367 return buf;
@@ -1272,14 +1382,15 @@ GNUNET_i2s (const struct GNUNET_PeerIdentity *pid)
1272const char * 1382const char *
1273GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid) 1383GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid)
1274{ 1384{
1275 static char buf[256]; 1385 static char buf[5];
1276 char *ret; 1386 char *ret;
1277 1387
1278 if (NULL == pid) 1388 if (NULL == pid)
1279 return "NULL"; 1389 return "NULL";
1280 ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); 1390 ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key);
1281 strcpy (buf, 1391 strncpy (buf,
1282 ret); 1392 ret,
1393 sizeof (buf) - 1);
1283 GNUNET_free (ret); 1394 GNUNET_free (ret);
1284 buf[4] = '\0'; 1395 buf[4] = '\0';
1285 return buf; 1396 return buf;
diff --git a/src/util/configuration.c b/src/util/configuration.c
index 25eeaf80f..9a583dfdb 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2006, 2007, 2008, 2009, 2013 GNUnet e.V. 3 Copyright (C) 2006, 2007, 2008, 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/** 19/**
diff --git a/src/util/configuration_loader.c b/src/util/configuration_loader.c
index ceaf2a6ea..45711e0fd 100644
--- a/src/util/configuration_loader.c
+++ b/src/util/configuration_loader.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2006, 2007, 2008, 2009, 2013 GNUnet e.V. 3 Copyright (C) 2006, 2007, 2008, 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/** 19/**
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c
index db61c5221..5f2fdd3ad 100644
--- a/src/util/container_bloomfilter.c
+++ b/src/util/container_bloomfilter.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008, 2011, 2012, 2018 GNUnet e.V. 3 Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008, 2011, 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 * @file util/container_bloomfilter.c 19 * @file util/container_bloomfilter.c
diff --git a/src/util/container_heap.c b/src/util/container_heap.c
index 21bdee834..5a0ae0002 100644
--- a/src/util/container_heap.c
+++ b/src/util/container_heap.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2008, 2009 GNUnet e.V. 3 Copyright (C) 2008, 2009 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/util/container_meta_data.c b/src/util/container_meta_data.c
index ec527005a..3859d8e64 100644
--- a/src/util/container_meta_data.c
+++ b/src/util/container_meta_data.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010 GNUnet e.V. 3 Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010 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/util/container_multihashmap.c b/src/util/container_multihashmap.c
index 6001fc1df..1811f861f 100644
--- a/src/util/container_multihashmap.c
+++ b/src/util/container_multihashmap.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2008, 2012 GNUnet e.V. 3 Copyright (C) 2008, 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 util/container_multihashmap.c 19 * @file util/container_multihashmap.c
diff --git a/src/util/container_multihashmap32.c b/src/util/container_multihashmap32.c
index d33c3c2d9..daf5059b6 100644
--- a/src/util/container_multihashmap32.c
+++ b/src/util/container_multihashmap32.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2008 GNUnet e.V. 3 Copyright (C) 2008 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 util/container_multihashmap32.c 19 * @file util/container_multihashmap32.c
diff --git a/src/util/container_multipeermap.c b/src/util/container_multipeermap.c
index 7830771d8..ede2fd8b7 100644
--- a/src/util/container_multipeermap.c
+++ b/src/util/container_multipeermap.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2008, 2012 GNUnet e.V. 3 Copyright (C) 2008, 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 util/container_multipeermap.c 19 * @file util/container_multipeermap.c
diff --git a/src/util/container_multishortmap.c b/src/util/container_multishortmap.c
index cfa82ca20..f815b6238 100644
--- a/src/util/container_multishortmap.c
+++ b/src/util/container_multishortmap.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2008, 2012 GNUnet e.V. 3 Copyright (C) 2008, 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 util/container_multishortmap.c 19 * @file util/container_multishortmap.c
diff --git a/src/util/crypto_abe.c b/src/util/crypto_abe.c
index fcaa826ed..581e63764 100644
--- a/src/util/crypto_abe.c
+++ b/src/util/crypto_abe.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. Copyright (C) 2001-2014 Christian Grothoff 2 This file is part of GNUnet. Copyright (C) 2001-2014 Christian Grothoff
3 (and other contributing authors) 3 (and other contributing authors)
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
@@ -53,12 +51,14 @@ init_aes( element_t k, int enc,
53 int rc; 51 int rc;
54 int key_len; 52 int key_len;
55 unsigned char* key_buf; 53 unsigned char* key_buf;
56 54
57 key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k); 55 key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k);
58 key_buf = (unsigned char*) malloc(key_len); 56 key_buf = (unsigned char*) malloc(key_len);
59 element_to_bytes(key_buf, k); 57 element_to_bytes(key_buf, k);
60 58
61 memcpy (key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH); 59 GNUNET_memcpy (key->aes_key,
60 key_buf,
61 GNUNET_CRYPTO_AES_KEY_LENGTH);
62 GNUNET_assert (0 == 62 GNUNET_assert (0 ==
63 gcry_cipher_open (handle, GCRY_CIPHER_AES256, 63 gcry_cipher_open (handle, GCRY_CIPHER_AES256,
64 GCRY_CIPHER_MODE_CFB, 0)); 64 GCRY_CIPHER_MODE_CFB, 0));
@@ -123,16 +123,16 @@ aes_128_cbc_decrypt( char* ct,
123 unsigned char iv[16]; 123 unsigned char iv[16];
124 char* tmp; 124 char* tmp;
125 uint32_t len; 125 uint32_t len;
126 126
127 init_aes(k, 1, &handle, &skey, iv); 127 init_aes(k, 1, &handle, &skey, iv);
128 128
129 tmp = GNUNET_malloc (size); 129 tmp = GNUNET_malloc (size);
130 130
131 //AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT); 131 //AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT);
132 GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size)); 132 GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size));
133 gcry_cipher_close (handle); 133 gcry_cipher_close (handle);
134 /* TODO make less crufty */ 134 /* TODO make less crufty */
135 135
136 /* get real length */ 136 /* get real length */
137 len = 0; 137 len = 0;
138 len = len 138 len = len
@@ -173,7 +173,7 @@ GNUNET_CRYPTO_cpabe_create_key (struct GNUNET_CRYPTO_AbeMasterKey *key,
173 struct GNUNET_CRYPTO_AbeKey *prv_key; 173 struct GNUNET_CRYPTO_AbeKey *prv_key;
174 int size; 174 int size;
175 char *tmp; 175 char *tmp;
176 176
177 prv_key = GNUNET_new (struct GNUNET_CRYPTO_AbeKey); 177 prv_key = GNUNET_new (struct GNUNET_CRYPTO_AbeKey);
178 prv_key->prv = gabe_keygen(key->pub, key->msk, attrs); 178 prv_key->prv = gabe_keygen(key->pub, key->msk, attrs);
179 size = gabe_pub_serialize(key->pub, &tmp); 179 size = gabe_pub_serialize(key->pub, &tmp);
@@ -204,7 +204,7 @@ write_cpabe (void **result,
204{ 204{
205 char *ptr; 205 char *ptr;
206 uint32_t *len; 206 uint32_t *len;
207 207
208 *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len); 208 *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len);
209 ptr = *result; 209 ptr = *result;
210 len = (uint32_t*) ptr; 210 len = (uint32_t*) ptr;
@@ -213,12 +213,12 @@ write_cpabe (void **result,
213 len = (uint32_t*) ptr; 213 len = (uint32_t*) ptr;
214 *len = htonl (aes_buf_len); 214 *len = htonl (aes_buf_len);
215 ptr += 4; 215 ptr += 4;
216 memcpy (ptr, aes_buf, aes_buf_len); 216 GNUNET_memcpy (ptr, aes_buf, aes_buf_len);
217 ptr += aes_buf_len; 217 ptr += aes_buf_len;
218 len = (uint32_t*) ptr; 218 len = (uint32_t*) ptr;
219 *len = htonl (cph_buf_len); 219 *len = htonl (cph_buf_len);
220 ptr += 4; 220 ptr += 4;
221 memcpy (ptr, cph_buf, cph_buf_len); 221 GNUNET_memcpy (ptr, cph_buf, cph_buf_len);
222 return 12 + cph_buf_len + aes_buf_len; 222 return 12 + cph_buf_len + aes_buf_len;
223} 223}
224 224
@@ -241,13 +241,13 @@ read_cpabe (const void *data,
241 *aes_buf_len = ntohl (*len); 241 *aes_buf_len = ntohl (*len);
242 ptr += 4; 242 ptr += 4;
243 *aes_buf = GNUNET_malloc (*aes_buf_len); 243 *aes_buf = GNUNET_malloc (*aes_buf_len);
244 memcpy(*aes_buf, ptr, *aes_buf_len); 244 GNUNET_memcpy (*aes_buf, ptr, *aes_buf_len);
245 ptr += *aes_buf_len; 245 ptr += *aes_buf_len;
246 len = (uint32_t*)ptr; 246 len = (uint32_t*)ptr;
247 *cph_buf_len = ntohl (*len); 247 *cph_buf_len = ntohl (*len);
248 ptr += 4; 248 ptr += 4;
249 *cph_buf = GNUNET_malloc (*cph_buf_len); 249 *cph_buf = GNUNET_malloc (*cph_buf_len);
250 memcpy(*cph_buf, ptr, *cph_buf_len); 250 GNUNET_memcpy (*cph_buf, ptr, *cph_buf_len);
251 251
252 return buf_len; 252 return buf_len;
253} 253}
@@ -362,7 +362,7 @@ GNUNET_CRYPTO_cpabe_deserialize_key (const void *data,
362 &prv_len); 362 &prv_len);
363 key->pub = gabe_pub_unserialize (pub, pub_len); 363 key->pub = gabe_pub_unserialize (pub, pub_len);
364 key->prv = gabe_prv_unserialize (key->pub, prv, prv_len); 364 key->prv = gabe_prv_unserialize (key->pub, prv, prv_len);
365 365
366 GNUNET_free (pub); 366 GNUNET_free (pub);
367 GNUNET_free (prv); 367 GNUNET_free (prv);
368 return key; 368 return key;
@@ -408,7 +408,7 @@ GNUNET_CRYPTO_cpabe_deserialize_master_key (const void *data,
408 &msk_len); 408 &msk_len);
409 key->pub = gabe_pub_unserialize (pub, pub_len); 409 key->pub = gabe_pub_unserialize (pub, pub_len);
410 key->msk = gabe_msk_unserialize (key->pub, msk, msk_len); 410 key->msk = gabe_msk_unserialize (key->pub, msk, msk_len);
411 411
412 GNUNET_free (pub); 412 GNUNET_free (pub);
413 GNUNET_free (msk); 413 GNUNET_free (msk);
414 414
diff --git a/src/util/crypto_crc.c b/src/util/crypto_crc.c
index 03b24d9f7..b8fd8059d 100644
--- a/src/util/crypto_crc.c
+++ b/src/util/crypto_crc.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2004, 2006 GNUnet e.V. 3 Copyright (C) 2001, 2002, 2003, 2004, 2006 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 For the actual CRC-32 code: 18 For the actual CRC-32 code:
21 Copyright abandoned; this code is in the public domain. 19 Copyright abandoned; this code is in the public domain.
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c
index 5d5e8a9ce..07782b181 100644
--- a/src/util/crypto_ecc.c
+++ b/src/util/crypto_ecc.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013, 2015 GNUnet e.V. 3 Copyright (C) 2012, 2013, 2015 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/**
@@ -455,7 +453,7 @@ GNUNET_CRYPTO_eddsa_public_key_from_string (const char *enc,
455int 453int
456GNUNET_CRYPTO_eddsa_private_key_from_string (const char *enc, 454GNUNET_CRYPTO_eddsa_private_key_from_string (const char *enc,
457 size_t enclen, 455 size_t enclen,
458 struct GNUNET_CRYPTO_EddsaPrivateKey *pub) 456 struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
459{ 457{
460 size_t keylen = (sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8; 458 size_t keylen = (sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8;
461 459
@@ -465,10 +463,19 @@ GNUNET_CRYPTO_eddsa_private_key_from_string (const char *enc,
465 if (enclen != keylen) 463 if (enclen != keylen)
466 return GNUNET_SYSERR; 464 return GNUNET_SYSERR;
467 465
468 if (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, enclen, 466 if (GNUNET_OK !=
469 pub, 467 GNUNET_STRINGS_string_to_data (enc, enclen,
470 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))) 468 priv,
469 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)))
471 return GNUNET_SYSERR; 470 return GNUNET_SYSERR;
471#if CRYPTO_BUG
472 if (GNUNET_OK !=
473 check_eddsa_key (priv))
474 {
475 GNUNET_break (0);
476 return GNUNET_OK;
477 }
478#endif
472 return GNUNET_OK; 479 return GNUNET_OK;
473} 480}
474 481
@@ -651,6 +658,9 @@ GNUNET_CRYPTO_eddsa_key_create ()
651 gcry_mpi_t d; 658 gcry_mpi_t d;
652 int rc; 659 int rc;
653 660
661#if CRYPTO_BUG
662 again:
663#endif
654 if (0 != (rc = gcry_sexp_build (&s_keyparam, NULL, 664 if (0 != (rc = gcry_sexp_build (&s_keyparam, NULL,
655 "(genkey(ecc(curve \"" CURVE "\")" 665 "(genkey(ecc(curve \"" CURVE "\")"
656 "(flags eddsa)))"))) 666 "(flags eddsa)))")))
@@ -683,6 +693,17 @@ GNUNET_CRYPTO_eddsa_key_create ()
683 priv = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey); 693 priv = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey);
684 GNUNET_CRYPTO_mpi_print_unsigned (priv->d, sizeof (priv->d), d); 694 GNUNET_CRYPTO_mpi_print_unsigned (priv->d, sizeof (priv->d), d);
685 gcry_mpi_release (d); 695 gcry_mpi_release (d);
696
697#if CRYPTO_BUG
698 if (GNUNET_OK !=
699 check_eddsa_key (priv))
700 {
701 GNUNET_break (0);
702 GNUNET_free (priv);
703 goto again;
704 }
705#endif
706
686 return priv; 707 return priv;
687} 708}
688 709
@@ -1249,6 +1270,7 @@ eddsa_d_to_a (gcry_mpi_t d)
1249 1270
1250 /* Note that we clear DIGEST so we can use it as input to left pad 1271 /* Note that we clear DIGEST so we can use it as input to left pad
1251 the key with zeroes for hashing. */ 1272 the key with zeroes for hashing. */
1273 memset (digest, 0, sizeof digest);
1252 memset (hvec, 0, sizeof hvec); 1274 memset (hvec, 0, sizeof hvec);
1253 rawmpilen = sizeof (rawmpi); 1275 rawmpilen = sizeof (rawmpi);
1254 GNUNET_assert (0 == 1276 GNUNET_assert (0 ==
@@ -1279,6 +1301,48 @@ eddsa_d_to_a (gcry_mpi_t d)
1279 1301
1280 1302
1281/** 1303/**
1304 * Take point from ECDH and convert it to key material.
1305 *
1306 * @param result point from ECDH
1307 * @param ctx ECC context
1308 * @param key_material[out] set to derived key material
1309 * @return #GNUNET_OK on success
1310 */
1311static int
1312point_to_hash (gcry_mpi_point_t result,
1313 gcry_ctx_t ctx,
1314 struct GNUNET_HashCode *key_material)
1315{
1316 gcry_mpi_t result_x;
1317 unsigned char xbuf[256 / 8];
1318 size_t rsize;
1319
1320 /* finally, convert point to string for hashing */
1321 result_x = gcry_mpi_new (256);
1322 if (gcry_mpi_ec_get_affine (result_x, NULL, result, ctx))
1323 {
1324 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "get_affine failed", 0);
1325 return GNUNET_SYSERR;
1326 }
1327
1328 rsize = sizeof (xbuf);
1329 GNUNET_assert (! gcry_mpi_get_flag (result_x, GCRYMPI_FLAG_OPAQUE));
1330 /* result_x can be negative here, so we do not use 'GNUNET_CRYPTO_mpi_print_unsigned'
1331 as that does not include the sign bit; x should be a 255-bit
1332 value, so with the sign it should fit snugly into the 256-bit
1333 xbuf */
1334 GNUNET_assert (0 ==
1335 gcry_mpi_print (GCRYMPI_FMT_STD, xbuf, rsize, &rsize,
1336 result_x));
1337 GNUNET_CRYPTO_hash (xbuf,
1338 rsize,
1339 key_material);
1340 gcry_mpi_release (result_x);
1341 return GNUNET_OK;
1342}
1343
1344
1345/**
1282 * @ingroup crypto 1346 * @ingroup crypto
1283 * Derive key material from a ECDH public key and a private EdDSA key. 1347 * Derive key material from a ECDH public key and a private EdDSA key.
1284 * Dual to #GNUNET_CRRYPTO_ecdh_eddsa. 1348 * Dual to #GNUNET_CRRYPTO_ecdh_eddsa.
@@ -1299,9 +1363,7 @@ GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1299 gcry_mpi_t a; 1363 gcry_mpi_t a;
1300 gcry_ctx_t ctx; 1364 gcry_ctx_t ctx;
1301 gcry_sexp_t pub_sexpr; 1365 gcry_sexp_t pub_sexpr;
1302 gcry_mpi_t result_x; 1366 int ret;
1303 unsigned char xbuf[256 / 8];
1304 size_t rsize;
1305 1367
1306 /* first, extract the q = dP value from the public key */ 1368 /* first, extract the q = dP value from the public key */
1307 if (0 != gcry_sexp_build (&pub_sexpr, NULL, 1369 if (0 != gcry_sexp_build (&pub_sexpr, NULL,
@@ -1325,34 +1387,15 @@ GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1325 gcry_mpi_point_release (q); 1387 gcry_mpi_point_release (q);
1326 gcry_mpi_release (a); 1388 gcry_mpi_release (a);
1327 1389
1328 /* finally, convert point to string for hashing */ 1390 ret = point_to_hash (result,
1329 result_x = gcry_mpi_new (256); 1391 ctx,
1330 if (gcry_mpi_ec_get_affine (result_x, NULL, result, ctx)) 1392 key_material);
1331 {
1332 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "get_affine failed", 0);
1333 gcry_mpi_point_release (result);
1334 gcry_ctx_release (ctx);
1335 return GNUNET_SYSERR;
1336 }
1337 gcry_mpi_point_release (result); 1393 gcry_mpi_point_release (result);
1338 gcry_ctx_release (ctx); 1394 gcry_ctx_release (ctx);
1339 1395 return ret;
1340 rsize = sizeof (xbuf);
1341 GNUNET_assert (! gcry_mpi_get_flag (result_x, GCRYMPI_FLAG_OPAQUE));
1342 /* result_x can be negative here, so we do not use 'GNUNET_CRYPTO_mpi_print_unsigned'
1343 as that does not include the sign bit; x should be a 255-bit
1344 value, so with the sign it should fit snugly into the 256-bit
1345 xbuf */
1346 GNUNET_assert (0 ==
1347 gcry_mpi_print (GCRYMPI_FMT_STD, xbuf, rsize, &rsize,
1348 result_x));
1349 GNUNET_CRYPTO_hash (xbuf,
1350 rsize,
1351 key_material);
1352 gcry_mpi_release (result_x);
1353 return GNUNET_OK;
1354} 1396}
1355 1397
1398
1356/** 1399/**
1357 * @ingroup crypto 1400 * @ingroup crypto
1358 * Derive key material from a ECDH public key and a private ECDSA key. 1401 * Derive key material from a ECDH public key and a private ECDSA key.
@@ -1373,9 +1416,7 @@ GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
1373 gcry_mpi_t d; 1416 gcry_mpi_t d;
1374 gcry_ctx_t ctx; 1417 gcry_ctx_t ctx;
1375 gcry_sexp_t pub_sexpr; 1418 gcry_sexp_t pub_sexpr;
1376 gcry_mpi_t result_x; 1419 int ret;
1377 unsigned char xbuf[256 / 8];
1378 size_t rsize;
1379 1420
1380 /* first, extract the q = dP value from the public key */ 1421 /* first, extract the q = dP value from the public key */
1381 if (0 != gcry_sexp_build (&pub_sexpr, NULL, 1422 if (0 != gcry_sexp_build (&pub_sexpr, NULL,
@@ -1396,31 +1437,12 @@ GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
1396 gcry_mpi_release (d); 1437 gcry_mpi_release (d);
1397 1438
1398 /* finally, convert point to string for hashing */ 1439 /* finally, convert point to string for hashing */
1399 result_x = gcry_mpi_new (256); 1440 ret = point_to_hash (result,
1400 if (gcry_mpi_ec_get_affine (result_x, NULL, result, ctx)) 1441 ctx,
1401 { 1442 key_material);
1402 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "get_affine failed", 0);
1403 gcry_mpi_point_release (result);
1404 gcry_ctx_release (ctx);
1405 return GNUNET_SYSERR;
1406 }
1407 gcry_mpi_point_release (result); 1443 gcry_mpi_point_release (result);
1408 gcry_ctx_release (ctx); 1444 gcry_ctx_release (ctx);
1409 1445 return ret;
1410 rsize = sizeof (xbuf);
1411 GNUNET_assert (! gcry_mpi_get_flag (result_x, GCRYMPI_FLAG_OPAQUE));
1412 /* result_x can be negative here, so we do not use 'GNUNET_CRYPTO_mpi_print_unsigned'
1413 as that does not include the sign bit; x should be a 255-bit
1414 value, so with the sign it should fit snugly into the 256-bit
1415 xbuf */
1416 GNUNET_assert (0 ==
1417 gcry_mpi_print (GCRYMPI_FMT_STD, xbuf, rsize, &rsize,
1418 result_x));
1419 GNUNET_CRYPTO_hash (xbuf,
1420 rsize,
1421 key_material);
1422 gcry_mpi_release (result_x);
1423 return GNUNET_OK;
1424} 1446}
1425 1447
1426 1448
@@ -1445,9 +1467,7 @@ GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1445 gcry_mpi_t d; 1467 gcry_mpi_t d;
1446 gcry_ctx_t ctx; 1468 gcry_ctx_t ctx;
1447 gcry_sexp_t pub_sexpr; 1469 gcry_sexp_t pub_sexpr;
1448 gcry_mpi_t result_x; 1470 int ret;
1449 unsigned char xbuf[256 / 8];
1450 size_t rsize;
1451 1471
1452 /* first, extract the q = dP value from the public key */ 1472 /* first, extract the q = dP value from the public key */
1453 if (0 != gcry_sexp_build (&pub_sexpr, NULL, 1473 if (0 != gcry_sexp_build (&pub_sexpr, NULL,
@@ -1468,31 +1488,12 @@ GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1468 gcry_mpi_release (d); 1488 gcry_mpi_release (d);
1469 1489
1470 /* finally, convert point to string for hashing */ 1490 /* finally, convert point to string for hashing */
1471 result_x = gcry_mpi_new (256); 1491 ret = point_to_hash (result,
1472 if (gcry_mpi_ec_get_affine (result_x, NULL, result, ctx)) 1492 ctx,
1473 { 1493 key_material);
1474 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "get_affine failed", 0);
1475 gcry_mpi_point_release (result);
1476 gcry_ctx_release (ctx);
1477 return GNUNET_SYSERR;
1478 }
1479 gcry_mpi_point_release (result); 1494 gcry_mpi_point_release (result);
1480 gcry_ctx_release (ctx); 1495 gcry_ctx_release (ctx);
1481 1496 return ret;
1482 rsize = sizeof (xbuf);
1483 GNUNET_assert (! gcry_mpi_get_flag (result_x, GCRYMPI_FLAG_OPAQUE));
1484 /* result_x can be negative here, so we do not use 'GNUNET_CRYPTO_mpi_print_unsigned'
1485 as that does not include the sign bit; x should be a 255-bit
1486 value, so with the sign it should fit snugly into the 256-bit
1487 xbuf */
1488 GNUNET_assert (0 ==
1489 gcry_mpi_print (GCRYMPI_FMT_STD, xbuf, rsize, &rsize,
1490 result_x));
1491 GNUNET_CRYPTO_hash (xbuf,
1492 rsize,
1493 key_material);
1494 gcry_mpi_release (result_x);
1495 return GNUNET_OK;
1496} 1497}
1497 1498
1498/** 1499/**
diff --git a/src/util/crypto_ecc_dlog.c b/src/util/crypto_ecc_dlog.c
index 91411368f..9d3674319 100644
--- a/src/util/crypto_ecc_dlog.c
+++ b/src/util/crypto_ecc_dlog.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013, 2015 GNUnet e.V. 3 Copyright (C) 2012, 2013, 2015 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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/ 17*/
20 18
21/** 19/**
diff --git a/src/util/crypto_ecc_setup.c b/src/util/crypto_ecc_setup.c
index e7caf9ded..507cbba11 100644
--- a/src/util/crypto_ecc_setup.c
+++ b/src/util/crypto_ecc_setup.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013, 2015 GNUnet e.V. 3 Copyright (C) 2012, 2013, 2015 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/**
@@ -221,6 +219,15 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
221 filename); 219 filename);
222 GNUNET_assert (GNUNET_YES == 220 GNUNET_assert (GNUNET_YES ==
223 GNUNET_DISK_file_close (fd)); 221 GNUNET_DISK_file_close (fd));
222#if CRYPTO_BUG
223 if (GNUNET_OK !=
224 check_eddsa_key (priv))
225 {
226 GNUNET_break (0);
227 GNUNET_free (priv);
228 return NULL;
229 }
230#endif
224 return priv; 231 return priv;
225} 232}
226 233
@@ -248,7 +255,7 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
248 int ec; 255 int ec;
249 uint64_t fs; 256 uint64_t fs;
250 ssize_t sret; 257 ssize_t sret;
251 258
252 if (GNUNET_SYSERR == 259 if (GNUNET_SYSERR ==
253 GNUNET_DISK_directory_create_for_file (filename)) 260 GNUNET_DISK_directory_create_for_file (filename))
254 return NULL; 261 return NULL;
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index cce9cf82a..fe1f58df7 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001-2013 GNUnet e.V. 3 Copyright (C) 2001-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/**
@@ -367,14 +365,17 @@ GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
367 365
368/** 366/**
369 * Calculate HMAC of a message (RFC 2104) 367 * Calculate HMAC of a message (RFC 2104)
368 * TODO: Shouldn' this be the standard hmac function and
369 * the above be renamed?
370 * 370 *
371 * @param key secret key 371 * @param key secret key
372 * @param key_len secret key length
372 * @param plaintext input plaintext 373 * @param plaintext input plaintext
373 * @param plaintext_len length of @a plaintext 374 * @param plaintext_len length of @a plaintext
374 * @param hmac where to store the hmac 375 * @param hmac where to store the hmac
375 */ 376 */
376void 377void
377GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, 378GNUNET_CRYPTO_hmac_raw (const void *key, size_t key_len,
378 const void *plaintext, size_t plaintext_len, 379 const void *plaintext, size_t plaintext_len,
379 struct GNUNET_HashCode *hmac) 380 struct GNUNET_HashCode *hmac)
380{ 381{
@@ -392,7 +393,7 @@ GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
392 { 393 {
393 gcry_md_reset (md); 394 gcry_md_reset (md);
394 } 395 }
395 gcry_md_setkey (md, key->key, sizeof (key->key)); 396 gcry_md_setkey (md, key, key_len);
396 gcry_md_write (md, plaintext, plaintext_len); 397 gcry_md_write (md, plaintext, plaintext_len);
397 mc = gcry_md_read (md, GCRY_MD_SHA512); 398 mc = gcry_md_read (md, GCRY_MD_SHA512);
398 GNUNET_assert (NULL != mc); 399 GNUNET_assert (NULL != mc);
@@ -401,6 +402,25 @@ GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
401 402
402 403
403/** 404/**
405 * Calculate HMAC of a message (RFC 2104)
406 *
407 * @param key secret key
408 * @param plaintext input plaintext
409 * @param plaintext_len length of @a plaintext
410 * @param hmac where to store the hmac
411 */
412void
413GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
414 const void *plaintext, size_t plaintext_len,
415 struct GNUNET_HashCode *hmac)
416{
417 GNUNET_CRYPTO_hmac_raw ((void*) key->key, sizeof (key->key),
418 plaintext, plaintext_len,
419 hmac);
420}
421
422
423/**
404 * Context for cummulative hashing. 424 * Context for cummulative hashing.
405 */ 425 */
406struct GNUNET_HashContext 426struct GNUNET_HashContext
diff --git a/src/util/crypto_hash_file.c b/src/util/crypto_hash_file.c
index cb632d02c..4d9824d22 100644
--- a/src/util/crypto_hash_file.c
+++ b/src/util/crypto_hash_file.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001-2013 GNUnet e.V. 3 Copyright (C) 2001-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/util/crypto_kdf.c b/src/util/crypto_kdf.c
index 6d7c5a096..0fc6996eb 100644
--- a/src/util/crypto_kdf.c
+++ b/src/util/crypto_kdf.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010 GNUnet e.V. 3 Copyright (C) 2010 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/util/crypto_mpi.c b/src/util/crypto_mpi.c
index ff3e9a8a7..0cb49d62f 100644
--- a/src/util/crypto_mpi.c
+++ b/src/util/crypto_mpi.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/** 19/**
diff --git a/src/util/crypto_paillier.c b/src/util/crypto_paillier.c
index 530a2957f..416240ea4 100644
--- a/src/util/crypto_paillier.c
+++ b/src/util/crypto_paillier.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2014 GNUnet e.V. 3 Copyright (C) 2014 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/util/crypto_random.c b/src/util/crypto_random.c
index d5b5eb9ec..df6d3fb9b 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. Copyright (C) 2001-2014 Christian Grothoff 2 This file is part of GNUnet. Copyright (C) 2001-2014 Christian Grothoff
3 (and other contributing authors) 3 (and other contributing authors)
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
@@ -271,6 +269,28 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max)
271 269
272 270
273/** 271/**
272 * Allocation wrapper for libgcrypt, used to avoid bad locking
273 * strategy of libgcrypt implementation.
274 */
275static void *
276w_malloc (size_t n)
277{
278 return calloc (n, 1);
279}
280
281
282/**
283 * Allocation wrapper for libgcrypt, used to avoid bad locking
284 * strategy of libgcrypt implementation.
285 */
286static int
287w_check (const void *p)
288{
289 return 0; /* not secure memory */
290}
291
292
293/**
274 * Initialize libgcrypt. 294 * Initialize libgcrypt.
275 */ 295 */
276void __attribute__ ((constructor)) 296void __attribute__ ((constructor))
@@ -285,6 +305,13 @@ GNUNET_CRYPTO_random_init ()
285 NEED_LIBGCRYPT_VERSION); 305 NEED_LIBGCRYPT_VERSION);
286 GNUNET_assert (0); 306 GNUNET_assert (0);
287 } 307 }
308 /* set custom allocators */
309 gcry_set_allocation_handler (&w_malloc,
310 &w_malloc,
311 &w_check,
312 &realloc,
313 &free);
314 /* Disable use of secure memory */
288 if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0))) 315 if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0)))
289 FPRINTF (stderr, 316 FPRINTF (stderr,
290 "Failed to set libgcrypt option %s: %s\n", 317 "Failed to set libgcrypt option %s: %s\n",
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c
index a985d8e59..1225aba73 100644
--- a/src/util/crypto_rsa.c
+++ b/src/util/crypto_rsa.c
@@ -2,16 +2,18 @@
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2014,2016 GNUnet e.V. 3 Copyright (C) 2014,2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify it under the 5 GNUnet is free software: you can redistribute it and/or modify it
6 terms of the GNU General Public License as published by the Free Software 6 under the terms of the GNU Affero General Public License as published
7 Foundation; either version 3, or (at your option) any later version. 7 by the Free Software Foundation, either version 3 of the License,
8 8 or (at your option) any later version.
9 GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY 9
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 10 GNUnet is distributed in the hope that it will be useful, but
11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 You should have received a copy of the GNU General Public License along with 13 Affero General Public License for more details.
14 GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> 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/>.
15*/ 17*/
16 18
17/** 19/**
@@ -94,7 +96,6 @@ key_from_sexp (gcry_mpi_t *array,
94 gcry_sexp_t list; 96 gcry_sexp_t list;
95 gcry_sexp_t l2; 97 gcry_sexp_t l2;
96 const char *s; 98 const char *s;
97 unsigned int i;
98 unsigned int idx; 99 unsigned int idx;
99 100
100 if (! (list = gcry_sexp_find_token (sexp, topname, 0))) 101 if (! (list = gcry_sexp_find_token (sexp, topname, 0)))
@@ -109,7 +110,7 @@ key_from_sexp (gcry_mpi_t *array,
109 { 110 {
110 if (! (l2 = gcry_sexp_find_token (list, s, 1))) 111 if (! (l2 = gcry_sexp_find_token (list, s, 1)))
111 { 112 {
112 for (i = 0; i < idx; i++) 113 for (unsigned int i = 0; i < idx; i++)
113 { 114 {
114 gcry_free (array[i]); 115 gcry_free (array[i]);
115 array[i] = NULL; 116 array[i] = NULL;
@@ -121,7 +122,7 @@ key_from_sexp (gcry_mpi_t *array,
121 gcry_sexp_release (l2); 122 gcry_sexp_release (l2);
122 if (! array[idx]) 123 if (! array[idx])
123 { 124 {
124 for (i = 0; i < idx; i++) 125 for (unsigned int i = 0; i < idx; i++)
125 { 126 {
126 gcry_free (array[i]); 127 gcry_free (array[i]);
127 array[i] = NULL; 128 array[i] = NULL;
@@ -720,7 +721,7 @@ rsa_full_domain_hash (const struct GNUNET_CRYPTO_RsaPublicKey *pkey,
720 * @param pkey the public key of the signer 721 * @param pkey the public key of the signer
721 * @param[out] buf set to a buffer with the blinded message to be signed 722 * @param[out] buf set to a buffer with the blinded message to be signed
722 * @param[out] buf_size number of bytes stored in @a buf 723 * @param[out] buf_size number of bytes stored in @a buf
723 * @return GNUNET_YES if successful, GNUNET_NO if RSA key is malicious 724 * @return #GNUNET_YES if successful, #GNUNET_NO if RSA key is malicious
724 */ 725 */
725int 726int
726GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, 727GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash,
diff --git a/src/util/crypto_symmetric.c b/src/util/crypto_symmetric.c
index e25e2f1dd..f7d7b4a7a 100644
--- a/src/util/crypto_symmetric.c
+++ b/src/util/crypto_symmetric.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2013 GNUnet e.V. 3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 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/util/disk.c b/src/util/disk.c
index 8fd689070..e0227be70 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -1,21 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001--2013, 2016 GNUnet e.V. 3 Copyright (C) 2001--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 util/disk.c 19 * @file util/disk.c
@@ -832,6 +830,12 @@ GNUNET_DISK_directory_create_for_file (const char *filename)
832 errno = EINVAL; 830 errno = EINVAL;
833 return GNUNET_SYSERR; 831 return GNUNET_SYSERR;
834 } 832 }
833 if (0 == ACCESS (rdir, W_OK))
834 {
835 GNUNET_free (rdir);
836 return GNUNET_OK;
837 }
838
835 len = strlen (rdir); 839 len = strlen (rdir);
836 while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) 840 while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
837 len--; 841 len--;
@@ -1401,13 +1405,28 @@ GNUNET_DISK_file_copy (const char *src,
1401 struct GNUNET_DISK_FileHandle *in; 1405 struct GNUNET_DISK_FileHandle *in;
1402 struct GNUNET_DISK_FileHandle *out; 1406 struct GNUNET_DISK_FileHandle *out;
1403 1407
1404 if (GNUNET_OK != GNUNET_DISK_file_size (src, &size, GNUNET_YES, GNUNET_YES)) 1408 if (GNUNET_OK !=
1409 GNUNET_DISK_file_size (src,
1410 &size,
1411 GNUNET_YES,
1412 GNUNET_YES))
1413 {
1414 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1415 "stat",
1416 src);
1405 return GNUNET_SYSERR; 1417 return GNUNET_SYSERR;
1418 }
1406 pos = 0; 1419 pos = 0;
1407 in = GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ, 1420 in = GNUNET_DISK_file_open (src,
1421 GNUNET_DISK_OPEN_READ,
1408 GNUNET_DISK_PERM_NONE); 1422 GNUNET_DISK_PERM_NONE);
1409 if (!in) 1423 if (! in)
1424 {
1425 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1426 "open",
1427 src);
1410 return GNUNET_SYSERR; 1428 return GNUNET_SYSERR;
1429 }
1411 out = 1430 out =
1412 GNUNET_DISK_file_open (dst, 1431 GNUNET_DISK_file_open (dst,
1413 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | 1432 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
@@ -1418,6 +1437,9 @@ GNUNET_DISK_file_copy (const char *src,
1418 GNUNET_DISK_PERM_GROUP_WRITE); 1437 GNUNET_DISK_PERM_GROUP_WRITE);
1419 if (!out) 1438 if (!out)
1420 { 1439 {
1440 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1441 "open",
1442 dst);
1421 GNUNET_DISK_file_close (in); 1443 GNUNET_DISK_file_close (in);
1422 return GNUNET_SYSERR; 1444 return GNUNET_SYSERR;
1423 } 1445 }
@@ -1670,16 +1692,19 @@ GNUNET_DISK_file_open (const char *fn,
1670 return NULL; 1692 return NULL;
1671 } 1693 }
1672 if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS) 1694 if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)
1673 oflags |= (O_CREAT | O_EXCL); 1695 oflags |= (O_CREAT | O_EXCL);
1674 if (flags & GNUNET_DISK_OPEN_TRUNCATE) 1696 if (flags & GNUNET_DISK_OPEN_TRUNCATE)
1675 oflags |= O_TRUNC; 1697 oflags |= O_TRUNC;
1676 if (flags & GNUNET_DISK_OPEN_APPEND) 1698 if (flags & GNUNET_DISK_OPEN_APPEND)
1677 oflags |= O_APPEND; 1699 oflags |= O_APPEND;
1678 if (flags & GNUNET_DISK_OPEN_CREATE) 1700 if(GNUNET_NO == GNUNET_DISK_file_test(fn))
1679 { 1701 {
1680 (void) GNUNET_DISK_directory_create_for_file (expfn); 1702 if (flags & GNUNET_DISK_OPEN_CREATE )
1681 oflags |= O_CREAT; 1703 {
1682 mode = translate_unix_perms (perm); 1704 (void) GNUNET_DISK_directory_create_for_file (expfn);
1705 oflags |= O_CREAT;
1706 mode = translate_unix_perms (perm);
1707 }
1683 } 1708 }
1684 1709
1685 fd = open (expfn, oflags 1710 fd = open (expfn, oflags
@@ -2641,4 +2666,55 @@ GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
2641 return GNUNET_OK; 2666 return GNUNET_OK;
2642} 2667}
2643 2668
2669
2670/**
2671 * Remove the directory given under @a option in
2672 * section [PATHS] in configuration under @a cfg_filename
2673 *
2674 * @param cfg_filename configuration file to parse
2675 * @param option option with the dir name to purge
2676 */
2677void
2678GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
2679 const char *option)
2680{
2681 struct GNUNET_CONFIGURATION_Handle *cfg;
2682 char *tmpname;
2683
2684 cfg = GNUNET_CONFIGURATION_create ();
2685 if (GNUNET_OK !=
2686 GNUNET_CONFIGURATION_load (cfg,
2687 cfg_filename))
2688 {
2689 GNUNET_break (0);
2690 GNUNET_CONFIGURATION_destroy (cfg);
2691 return;
2692 }
2693 if (GNUNET_OK !=
2694 GNUNET_CONFIGURATION_get_value_filename (cfg,
2695 "PATHS",
2696 option,
2697 &tmpname))
2698 {
2699 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
2700 "PATHS",
2701 option);
2702 GNUNET_CONFIGURATION_destroy (cfg);
2703 return;
2704 }
2705 GNUNET_CONFIGURATION_destroy (cfg);
2706 if (GNUNET_SYSERR ==
2707 GNUNET_DISK_directory_remove (tmpname))
2708 {
2709 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
2710 "remove",
2711 tmpname);
2712 GNUNET_free (tmpname);
2713 return;
2714 }
2715 GNUNET_free (tmpname);
2716}
2717
2718
2719
2644/* end of disk.c */ 2720/* end of disk.c */
diff --git a/src/util/disk.h b/src/util/disk.h
index 149890390..629971d81 100644
--- a/src/util/disk.h
+++ b/src/util/disk.h
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009 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/util/dnsparser.c b/src/util/dnsparser.c
new file mode 100644
index 000000000..24f1b18cf
--- /dev/null
+++ b/src/util/dnsparser.c
@@ -0,0 +1,1458 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010-2014 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/**
20 * @file dns/dnsparser.c
21 * @brief helper library to parse DNS packets.
22 * @author Philipp Toelke
23 * @author Christian Grothoff
24 */
25#include "platform.h"
26#include <idna.h>
27#if WINDOWS
28#include <idn-free.h>
29#endif
30#include "gnunet_util_lib.h"
31
32
33/**
34 * Check if a label in UTF-8 format can be coded into valid IDNA.
35 * This can fail if the ASCII-conversion becomes longer than 63 characters.
36 *
37 * @param label label to check (UTF-8 string)
38 * @return #GNUNET_OK if the label can be converted to IDNA,
39 * #GNUNET_SYSERR if the label is not valid for DNS names
40 */
41int
42GNUNET_DNSPARSER_check_label (const char *label)
43{
44 char *output;
45 size_t slen;
46
47 if (NULL != strchr (label, '.'))
48 return GNUNET_SYSERR; /* not a label! Did you mean GNUNET_DNSPARSER_check_name? */
49 if (IDNA_SUCCESS !=
50 idna_to_ascii_8z (label, &output, IDNA_ALLOW_UNASSIGNED))
51 return GNUNET_SYSERR;
52 slen = strlen (output);
53#if WINDOWS
54 idn_free (output);
55#else
56 free (output);
57#endif
58 return (slen > 63) ? GNUNET_SYSERR : GNUNET_OK;
59}
60
61
62/**
63 * Check if a label in UTF-8 format can be coded into valid IDNA.
64 * This can fail if the ASCII-conversion becomes longer than 253 characters.
65 *
66 * @param name name to check (UTF-8 string)
67 * @return #GNUNET_OK if the label can be converted to IDNA,
68 * #GNUNET_SYSERR if the label is not valid for DNS names
69 */
70int
71GNUNET_DNSPARSER_check_name (const char *name)
72{
73 char *ldup;
74 char *output;
75 size_t slen;
76 char *tok;
77
78 ldup = GNUNET_strdup (name);
79 for (tok = strtok (ldup, "."); NULL != tok; tok = strtok (NULL, "."))
80 if (GNUNET_OK !=
81 GNUNET_DNSPARSER_check_label (tok))
82 {
83 GNUNET_free (ldup);
84 return GNUNET_SYSERR;
85 }
86 GNUNET_free (ldup);
87 if (IDNA_SUCCESS !=
88 idna_to_ascii_8z (name, &output, IDNA_ALLOW_UNASSIGNED))
89 return GNUNET_SYSERR;
90 slen = strlen (output);
91#if WINDOWS
92 idn_free (output);
93#else
94 free (output);
95#endif
96 return (slen > 253) ? GNUNET_SYSERR : GNUNET_OK;
97}
98
99
100/**
101 * Free SOA information record.
102 *
103 * @param soa record to free
104 */
105void
106GNUNET_DNSPARSER_free_soa (struct GNUNET_DNSPARSER_SoaRecord *soa)
107{
108 if (NULL == soa)
109 return;
110 GNUNET_free_non_null (soa->mname);
111 GNUNET_free_non_null (soa->rname);
112 GNUNET_free (soa);
113}
114
115
116/**
117 * Free CERT information record.
118 *
119 * @param cert record to free
120 */
121void
122GNUNET_DNSPARSER_free_cert (struct GNUNET_DNSPARSER_CertRecord *cert)
123{
124 if (NULL == cert)
125 return;
126 GNUNET_free_non_null (cert->certificate_data);
127 GNUNET_free (cert);
128}
129
130
131/**
132 * Free SRV information record.
133 *
134 * @param srv record to free
135 */
136void
137GNUNET_DNSPARSER_free_srv (struct GNUNET_DNSPARSER_SrvRecord *srv)
138{
139 if (NULL == srv)
140 return;
141 GNUNET_free_non_null (srv->target);
142 GNUNET_free (srv);
143}
144
145
146/**
147 * Free MX information record.
148 *
149 * @param mx record to free
150 */
151void
152GNUNET_DNSPARSER_free_mx (struct GNUNET_DNSPARSER_MxRecord *mx)
153{
154 if (NULL == mx)
155 return;
156 GNUNET_free_non_null (mx->mxhost);
157 GNUNET_free (mx);
158}
159
160
161/**
162 * Free the given DNS record.
163 *
164 * @param r record to free
165 */
166void
167GNUNET_DNSPARSER_free_record (struct GNUNET_DNSPARSER_Record *r)
168{
169 GNUNET_free_non_null (r->name);
170 switch (r->type)
171 {
172 case GNUNET_DNSPARSER_TYPE_MX:
173 GNUNET_DNSPARSER_free_mx (r->data.mx);
174 break;
175 case GNUNET_DNSPARSER_TYPE_SOA:
176 GNUNET_DNSPARSER_free_soa (r->data.soa);
177 break;
178 case GNUNET_DNSPARSER_TYPE_SRV:
179 GNUNET_DNSPARSER_free_srv (r->data.srv);
180 break;
181 case GNUNET_DNSPARSER_TYPE_CERT:
182 GNUNET_DNSPARSER_free_cert (r->data.cert);
183 break;
184 case GNUNET_DNSPARSER_TYPE_NS:
185 case GNUNET_DNSPARSER_TYPE_CNAME:
186 case GNUNET_DNSPARSER_TYPE_PTR:
187 GNUNET_free_non_null (r->data.hostname);
188 break;
189 default:
190 GNUNET_free_non_null (r->data.raw.data);
191 break;
192 }
193}
194
195
196/**
197 * Parse name inside of a DNS query or record.
198 *
199 * @param udp_payload entire UDP payload
200 * @param udp_payload_length length of @a udp_payload
201 * @param off pointer to the offset of the name to parse in the udp_payload (to be
202 * incremented by the size of the name)
203 * @param depth current depth of our recursion (to prevent stack overflow)
204 * @return name as 0-terminated C string on success, NULL if the payload is malformed
205 */
206static char *
207parse_name (const char *udp_payload,
208 size_t udp_payload_length,
209 size_t *off,
210 unsigned int depth)
211{
212 const uint8_t *input = (const uint8_t *) udp_payload;
213 char *ret;
214 char *tmp;
215 char *xstr;
216 uint8_t len;
217 size_t xoff;
218 char *utf8;
219 Idna_rc rc;
220
221 ret = GNUNET_strdup ("");
222 while (1)
223 {
224 if (*off >= udp_payload_length)
225 {
226 GNUNET_break_op (0);
227 goto error;
228 }
229 len = input[*off];
230 if (0 == len)
231 {
232 (*off)++;
233 break;
234 }
235 if (len < 64)
236 {
237 if (*off + 1 + len > udp_payload_length)
238 {
239 GNUNET_break_op (0);
240 goto error;
241 }
242 GNUNET_asprintf (&tmp,
243 "%.*s",
244 (int) len,
245 &udp_payload[*off + 1]);
246 if (IDNA_SUCCESS !=
247 (rc = idna_to_unicode_8z8z (tmp, &utf8, IDNA_ALLOW_UNASSIGNED)))
248 {
249 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
250 _("Failed to convert DNS IDNA name `%s' to UTF-8: %s\n"),
251 tmp,
252 idna_strerror (rc));
253 GNUNET_free (tmp);
254 GNUNET_asprintf (&tmp,
255 "%s%.*s.",
256 ret,
257 (int) len,
258 &udp_payload[*off + 1]);
259 }
260 else
261 {
262 GNUNET_free (tmp);
263 GNUNET_asprintf (&tmp,
264 "%s%s.",
265 ret,
266 utf8);
267#if WINDOWS
268 idn_free (utf8);
269#else
270 free (utf8);
271#endif
272 }
273 GNUNET_free (ret);
274 ret = tmp;
275 *off += 1 + len;
276 }
277 else if ((64 | 128) == (len & (64 | 128)) )
278 {
279 if (depth > 32)
280 {
281 GNUNET_break_op (0);
282 goto error; /* hard bound on stack to prevent "infinite" recursion, disallow! */
283 }
284 /* pointer to string */
285 if (*off + 1 > udp_payload_length)
286 {
287 GNUNET_break_op (0);
288 goto error;
289 }
290 xoff = ((len - (64 | 128)) << 8) + input[*off+1];
291 xstr = parse_name (udp_payload,
292 udp_payload_length,
293 &xoff,
294 depth + 1);
295 if (NULL == xstr)
296 {
297 GNUNET_break_op (0);
298 goto error;
299 }
300 GNUNET_asprintf (&tmp,
301 "%s%s.",
302 ret,
303 xstr);
304 GNUNET_free (ret);
305 GNUNET_free (xstr);
306 ret = tmp;
307 if (strlen (ret) > udp_payload_length)
308 {
309 GNUNET_break_op (0);
310 goto error; /* we are looping (building an infinite string) */
311 }
312 *off += 2;
313 /* pointers always terminate names */
314 break;
315 }
316 else
317 {
318 /* neither pointer nor inline string, not supported... */
319 GNUNET_break_op (0);
320 goto error;
321 }
322 }
323 if (0 < strlen(ret))
324 ret[strlen(ret)-1] = '\0'; /* eat tailing '.' */
325 return ret;
326 error:
327 GNUNET_break_op (0);
328 GNUNET_free (ret);
329 return NULL;
330}
331
332
333/**
334 * Parse name inside of a DNS query or record.
335 *
336 * @param udp_payload entire UDP payload
337 * @param udp_payload_length length of @a udp_payload
338 * @param off pointer to the offset of the name to parse in the udp_payload (to be
339 * incremented by the size of the name)
340 * @return name as 0-terminated C string on success, NULL if the payload is malformed
341 */
342char *
343GNUNET_DNSPARSER_parse_name (const char *udp_payload,
344 size_t udp_payload_length,
345 size_t *off)
346{
347 return parse_name (udp_payload, udp_payload_length, off, 0);
348}
349
350
351/**
352 * Parse a DNS query entry.
353 *
354 * @param udp_payload entire UDP payload
355 * @param udp_payload_length length of @a udp_payload
356 * @param off pointer to the offset of the query to parse in the udp_payload (to be
357 * incremented by the size of the query)
358 * @param q where to write the query information
359 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the query is malformed
360 */
361int
362GNUNET_DNSPARSER_parse_query (const char *udp_payload,
363 size_t udp_payload_length,
364 size_t *off,
365 struct GNUNET_DNSPARSER_Query *q)
366{
367 char *name;
368 struct GNUNET_TUN_DnsQueryLine ql;
369
370 name = GNUNET_DNSPARSER_parse_name (udp_payload,
371 udp_payload_length,
372 off);
373 if (NULL == name)
374 {
375 GNUNET_break_op (0);
376 return GNUNET_SYSERR;
377 }
378 q->name = name;
379 if (*off + sizeof (struct GNUNET_TUN_DnsQueryLine) > udp_payload_length)
380 {
381 GNUNET_break_op (0);
382 return GNUNET_SYSERR;
383 }
384 GNUNET_memcpy (&ql, &udp_payload[*off], sizeof (ql));
385 *off += sizeof (ql);
386 q->type = ntohs (ql.type);
387 q->dns_traffic_class = ntohs (ql.dns_traffic_class);
388 return GNUNET_OK;
389}
390
391
392/**
393 * Parse a DNS SOA record.
394 *
395 * @param udp_payload reference to UDP packet
396 * @param udp_payload_length length of @a udp_payload
397 * @param off pointer to the offset of the query to parse in the SOA record (to be
398 * incremented by the size of the record), unchanged on error
399 * @return the parsed SOA record, NULL on error
400 */
401struct GNUNET_DNSPARSER_SoaRecord *
402GNUNET_DNSPARSER_parse_soa (const char *udp_payload,
403 size_t udp_payload_length,
404 size_t *off)
405{
406 struct GNUNET_DNSPARSER_SoaRecord *soa;
407 struct GNUNET_TUN_DnsSoaRecord soa_bin;
408 size_t old_off;
409
410 old_off = *off;
411 soa = GNUNET_new (struct GNUNET_DNSPARSER_SoaRecord);
412 soa->mname = GNUNET_DNSPARSER_parse_name (udp_payload,
413 udp_payload_length,
414 off);
415 soa->rname = GNUNET_DNSPARSER_parse_name (udp_payload,
416 udp_payload_length,
417 off);
418 if ( (NULL == soa->mname) ||
419 (NULL == soa->rname) ||
420 (*off + sizeof (struct GNUNET_TUN_DnsSoaRecord) > udp_payload_length) )
421 {
422 GNUNET_break_op (0);
423 GNUNET_DNSPARSER_free_soa (soa);
424 *off = old_off;
425 return NULL;
426 }
427 GNUNET_memcpy (&soa_bin,
428 &udp_payload[*off],
429 sizeof (struct GNUNET_TUN_DnsSoaRecord));
430 soa->serial = ntohl (soa_bin.serial);
431 soa->refresh = ntohl (soa_bin.refresh);
432 soa->retry = ntohl (soa_bin.retry);
433 soa->expire = ntohl (soa_bin.expire);
434 soa->minimum_ttl = ntohl (soa_bin.minimum);
435 (*off) += sizeof (struct GNUNET_TUN_DnsSoaRecord);
436 return soa;
437}
438
439
440/**
441 * Parse a DNS MX record.
442 *
443 * @param udp_payload reference to UDP packet
444 * @param udp_payload_length length of @a udp_payload
445 * @param off pointer to the offset of the query to parse in the MX record (to be
446 * incremented by the size of the record), unchanged on error
447 * @return the parsed MX record, NULL on error
448 */
449struct GNUNET_DNSPARSER_MxRecord *
450GNUNET_DNSPARSER_parse_mx (const char *udp_payload,
451 size_t udp_payload_length,
452 size_t *off)
453{
454 struct GNUNET_DNSPARSER_MxRecord *mx;
455 uint16_t mxpref;
456 size_t old_off;
457
458 old_off = *off;
459 if (*off + sizeof (uint16_t) > udp_payload_length)
460 {
461 GNUNET_break_op (0);
462 return NULL;
463 }
464 GNUNET_memcpy (&mxpref, &udp_payload[*off], sizeof (uint16_t));
465 (*off) += sizeof (uint16_t);
466 mx = GNUNET_new (struct GNUNET_DNSPARSER_MxRecord);
467 mx->preference = ntohs (mxpref);
468 mx->mxhost = GNUNET_DNSPARSER_parse_name (udp_payload,
469 udp_payload_length,
470 off);
471 if (NULL == mx->mxhost)
472 {
473 GNUNET_break_op (0);
474 GNUNET_DNSPARSER_free_mx (mx);
475 *off = old_off;
476 return NULL;
477 }
478 return mx;
479}
480
481
482/**
483 * Parse a DNS SRV record.
484 *
485 * @param udp_payload reference to UDP packet
486 * @param udp_payload_length length of @a udp_payload
487 * @param off pointer to the offset of the query to parse in the SRV record (to be
488 * incremented by the size of the record), unchanged on error
489 * @return the parsed SRV record, NULL on error
490 */
491struct GNUNET_DNSPARSER_SrvRecord *
492GNUNET_DNSPARSER_parse_srv (const char *udp_payload,
493 size_t udp_payload_length,
494 size_t *off)
495{
496 struct GNUNET_DNSPARSER_SrvRecord *srv;
497 struct GNUNET_TUN_DnsSrvRecord srv_bin;
498 size_t old_off;
499
500 old_off = *off;
501 if (*off + sizeof (struct GNUNET_TUN_DnsSrvRecord) > udp_payload_length)
502 return NULL;
503 GNUNET_memcpy (&srv_bin,
504 &udp_payload[*off],
505 sizeof (struct GNUNET_TUN_DnsSrvRecord));
506 (*off) += sizeof (struct GNUNET_TUN_DnsSrvRecord);
507 srv = GNUNET_new (struct GNUNET_DNSPARSER_SrvRecord);
508 srv->priority = ntohs (srv_bin.prio);
509 srv->weight = ntohs (srv_bin.weight);
510 srv->port = ntohs (srv_bin.port);
511 srv->target = GNUNET_DNSPARSER_parse_name (udp_payload,
512 udp_payload_length,
513 off);
514 if (NULL == srv->target)
515 {
516 GNUNET_DNSPARSER_free_srv (srv);
517 *off = old_off;
518 return NULL;
519 }
520 return srv;
521}
522
523
524/**
525 * Parse a DNS CERT record.
526 *
527 * @param udp_payload reference to UDP packet
528 * @param udp_payload_length length of @a udp_payload
529 * @param off pointer to the offset of the query to parse in the CERT record (to be
530 * incremented by the size of the record), unchanged on error
531 * @return the parsed CERT record, NULL on error
532 */
533struct GNUNET_DNSPARSER_CertRecord *
534GNUNET_DNSPARSER_parse_cert (const char *udp_payload,
535 size_t udp_payload_length,
536 size_t *off)
537{
538 struct GNUNET_DNSPARSER_CertRecord *cert;
539 struct GNUNET_TUN_DnsCertRecord dcert;
540
541 if (*off + sizeof (struct GNUNET_TUN_DnsCertRecord) >= udp_payload_length)
542 {
543 GNUNET_break_op (0);
544 return NULL;
545 }
546 GNUNET_memcpy (&dcert,
547 &udp_payload[*off],
548 sizeof (struct GNUNET_TUN_DnsCertRecord));
549 (*off) += sizeof (struct GNUNET_TUN_DnsCertRecord);
550 cert = GNUNET_new (struct GNUNET_DNSPARSER_CertRecord);
551 cert->cert_type = ntohs (dcert.cert_type);
552 cert->cert_tag = ntohs (dcert.cert_tag);
553 cert->algorithm = dcert.algorithm;
554 cert->certificate_size = udp_payload_length - (*off);
555 cert->certificate_data = GNUNET_malloc (cert->certificate_size);
556 GNUNET_memcpy (cert->certificate_data,
557 &udp_payload[*off],
558 cert->certificate_size);
559 (*off) += cert->certificate_size;
560 return cert;
561}
562
563
564/**
565 * Parse a DNS record entry.
566 *
567 * @param udp_payload entire UDP payload
568 * @param udp_payload_length length of @a udp_payload
569 * @param off pointer to the offset of the record to parse in the udp_payload (to be
570 * incremented by the size of the record)
571 * @param r where to write the record information
572 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the record is malformed
573 */
574int
575GNUNET_DNSPARSER_parse_record (const char *udp_payload,
576 size_t udp_payload_length,
577 size_t *off,
578 struct GNUNET_DNSPARSER_Record *r)
579{
580 char *name;
581 struct GNUNET_TUN_DnsRecordLine rl;
582 size_t old_off;
583 uint16_t data_len;
584
585 name = GNUNET_DNSPARSER_parse_name (udp_payload,
586 udp_payload_length,
587 off);
588 if (NULL == name)
589 {
590 GNUNET_break_op (0);
591 return GNUNET_SYSERR;
592 }
593 r->name = name;
594 if (*off + sizeof (struct GNUNET_TUN_DnsRecordLine) > udp_payload_length)
595 {
596 GNUNET_break_op (0);
597 return GNUNET_SYSERR;
598 }
599 GNUNET_memcpy (&rl, &udp_payload[*off], sizeof (rl));
600 (*off) += sizeof (rl);
601 r->type = ntohs (rl.type);
602 r->dns_traffic_class = ntohs (rl.dns_traffic_class);
603 r->expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
604 ntohl (rl.ttl)));
605 data_len = ntohs (rl.data_len);
606 if (*off + data_len > udp_payload_length)
607 {
608 GNUNET_break_op (0);
609 return GNUNET_SYSERR;
610 }
611 old_off = *off;
612 switch (r->type)
613 {
614 case GNUNET_DNSPARSER_TYPE_NS:
615 case GNUNET_DNSPARSER_TYPE_CNAME:
616 case GNUNET_DNSPARSER_TYPE_DNAME:
617 case GNUNET_DNSPARSER_TYPE_PTR:
618 r->data.hostname = GNUNET_DNSPARSER_parse_name (udp_payload,
619 udp_payload_length,
620 off);
621 if ( (NULL == r->data.hostname) ||
622 (old_off + data_len != *off) )
623 return GNUNET_SYSERR;
624 return GNUNET_OK;
625 case GNUNET_DNSPARSER_TYPE_SOA:
626 r->data.soa = GNUNET_DNSPARSER_parse_soa (udp_payload,
627 udp_payload_length,
628 off);
629 if ( (NULL == r->data.soa) ||
630 (old_off + data_len != *off) )
631 {
632 GNUNET_break_op (0);
633 return GNUNET_SYSERR;
634 }
635 return GNUNET_OK;
636 case GNUNET_DNSPARSER_TYPE_MX:
637 r->data.mx = GNUNET_DNSPARSER_parse_mx (udp_payload,
638 udp_payload_length,
639 off);
640 if ( (NULL == r->data.mx) ||
641 (old_off + data_len != *off) )
642 {
643 GNUNET_break_op (0);
644 return GNUNET_SYSERR;
645 }
646 return GNUNET_OK;
647 case GNUNET_DNSPARSER_TYPE_SRV:
648 r->data.srv = GNUNET_DNSPARSER_parse_srv (udp_payload,
649 udp_payload_length,
650 off);
651 if ( (NULL == r->data.srv) ||
652 (old_off + data_len != *off) )
653 {
654 GNUNET_break_op (0);
655 return GNUNET_SYSERR;
656 }
657 return GNUNET_OK;
658 default:
659 r->data.raw.data = GNUNET_malloc (data_len);
660 r->data.raw.data_len = data_len;
661 GNUNET_memcpy (r->data.raw.data,
662 &udp_payload[*off],
663 data_len);
664 break;
665 }
666 (*off) += data_len;
667 return GNUNET_OK;
668}
669
670
671/**
672 * Parse a UDP payload of a DNS packet in to a nice struct for further
673 * processing and manipulation.
674 *
675 * @param udp_payload wire-format of the DNS packet
676 * @param udp_payload_length number of bytes in @a udp_payload
677 * @return NULL on error, otherwise the parsed packet
678 */
679struct GNUNET_DNSPARSER_Packet *
680GNUNET_DNSPARSER_parse (const char *udp_payload,
681 size_t udp_payload_length)
682{
683 struct GNUNET_DNSPARSER_Packet *p;
684 const struct GNUNET_TUN_DnsHeader *dns;
685 size_t off;
686 unsigned int n;
687
688 if (udp_payload_length < sizeof (struct GNUNET_TUN_DnsHeader))
689 return NULL;
690 dns = (const struct GNUNET_TUN_DnsHeader *) udp_payload;
691 off = sizeof (struct GNUNET_TUN_DnsHeader);
692 p = GNUNET_new (struct GNUNET_DNSPARSER_Packet);
693 p->flags = dns->flags;
694 p->id = dns->id;
695 n = ntohs (dns->query_count);
696 if (n > 0)
697 {
698 p->queries = GNUNET_new_array (n,
699 struct GNUNET_DNSPARSER_Query);
700 p->num_queries = n;
701 for (unsigned int i=0;i<n;i++)
702 if (GNUNET_OK !=
703 GNUNET_DNSPARSER_parse_query (udp_payload,
704 udp_payload_length,
705 &off,
706 &p->queries[i]))
707 goto error;
708 }
709 n = ntohs (dns->answer_rcount);
710 if (n > 0)
711 {
712 p->answers = GNUNET_new_array (n,
713 struct GNUNET_DNSPARSER_Record);
714 p->num_answers = n;
715 for (unsigned int i=0;i<n;i++)
716 if (GNUNET_OK !=
717 GNUNET_DNSPARSER_parse_record (udp_payload,
718 udp_payload_length,
719 &off,
720 &p->answers[i]))
721 goto error;
722 }
723 n = ntohs (dns->authority_rcount);
724 if (n > 0)
725 {
726 p->authority_records = GNUNET_new_array (n,
727 struct GNUNET_DNSPARSER_Record);
728 p->num_authority_records = n;
729 for (unsigned int i=0;i<n;i++)
730 if (GNUNET_OK !=
731 GNUNET_DNSPARSER_parse_record (udp_payload,
732 udp_payload_length,
733 &off,
734 &p->authority_records[i]))
735 goto error;
736 }
737 n = ntohs (dns->additional_rcount);
738 if (n > 0)
739 {
740 p->additional_records = GNUNET_new_array (n,
741 struct GNUNET_DNSPARSER_Record);
742 p->num_additional_records = n;
743 for (unsigned int i=0;i<n;i++)
744 {
745 if (GNUNET_OK !=
746 GNUNET_DNSPARSER_parse_record (udp_payload,
747 udp_payload_length,
748 &off,
749 &p->additional_records[i]))
750 goto error;
751 }
752 }
753 return p;
754 error:
755 GNUNET_break_op (0);
756 GNUNET_DNSPARSER_free_packet (p);
757 return NULL;
758}
759
760
761/**
762 * Duplicate (deep-copy) the given DNS record
763 *
764 * @param r the record
765 * @return the newly allocated record
766 */
767struct GNUNET_DNSPARSER_Record *
768GNUNET_DNSPARSER_duplicate_record (const struct GNUNET_DNSPARSER_Record *r)
769{
770 struct GNUNET_DNSPARSER_Record *dup = GNUNET_memdup (r, sizeof (*r));
771
772 dup->name = GNUNET_strdup (r->name);
773 switch (r->type)
774 {
775 case GNUNET_DNSPARSER_TYPE_NS:
776 case GNUNET_DNSPARSER_TYPE_CNAME:
777 case GNUNET_DNSPARSER_TYPE_PTR:
778 {
779 dup->data.hostname = GNUNET_strdup (r->data.hostname);
780 break;
781 }
782 case GNUNET_DNSPARSER_TYPE_SOA:
783 {
784 dup->data.soa = GNUNET_DNSPARSER_duplicate_soa_record (r->data.soa);
785 break;
786 }
787 case GNUNET_DNSPARSER_TYPE_CERT:
788 {
789 dup->data.cert = GNUNET_DNSPARSER_duplicate_cert_record (r->data.cert);
790 break;
791 }
792 case GNUNET_DNSPARSER_TYPE_MX:
793 {
794 dup->data.mx = GNUNET_DNSPARSER_duplicate_mx_record (r->data.mx);
795 break;
796 }
797 case GNUNET_DNSPARSER_TYPE_SRV:
798 {
799 dup->data.srv = GNUNET_DNSPARSER_duplicate_srv_record (r->data.srv);
800 break;
801 }
802 default:
803 {
804 dup->data.raw.data = GNUNET_memdup (r->data.raw.data,
805 r->data.raw.data_len);
806 }
807 }
808 return dup;
809}
810
811
812/**
813 * Duplicate (deep-copy) the given DNS record
814 *
815 * @param r the record
816 * @return the newly allocated record
817 */
818struct GNUNET_DNSPARSER_SoaRecord *
819GNUNET_DNSPARSER_duplicate_soa_record (const struct GNUNET_DNSPARSER_SoaRecord *r)
820{
821 struct GNUNET_DNSPARSER_SoaRecord *dup = GNUNET_memdup (r, sizeof (*r));
822
823 dup->mname = GNUNET_strdup (r->mname);
824 dup->rname = GNUNET_strdup (r->rname);
825 return dup;
826}
827
828
829/**
830 * Duplicate (deep-copy) the given DNS record
831 *
832 * @param r the record
833 * @return the newly allocated record
834 */
835struct GNUNET_DNSPARSER_CertRecord *
836GNUNET_DNSPARSER_duplicate_cert_record (const struct GNUNET_DNSPARSER_CertRecord *r)
837{
838 struct GNUNET_DNSPARSER_CertRecord *dup = GNUNET_memdup (r, sizeof (*r));
839
840 dup->certificate_data = GNUNET_strdup (r->certificate_data);
841 return dup;
842}
843
844
845/**
846 * Duplicate (deep-copy) the given DNS record
847 *
848 * @param r the record
849 * @return the newly allocated record
850 */
851struct GNUNET_DNSPARSER_MxRecord *
852GNUNET_DNSPARSER_duplicate_mx_record (const struct GNUNET_DNSPARSER_MxRecord *r)
853{
854 struct GNUNET_DNSPARSER_MxRecord *dup = GNUNET_memdup (r, sizeof (*r));
855
856 dup->mxhost = GNUNET_strdup (r->mxhost);
857 return dup;
858}
859
860
861/**
862 * Duplicate (deep-copy) the given DNS record
863 *
864 * @param r the record
865 * @return the newly allocated record
866 */
867struct GNUNET_DNSPARSER_SrvRecord *
868GNUNET_DNSPARSER_duplicate_srv_record (const struct GNUNET_DNSPARSER_SrvRecord *r)
869{
870 struct GNUNET_DNSPARSER_SrvRecord *dup = GNUNET_memdup (r, sizeof (*r));
871
872 dup->target = GNUNET_strdup (r->target);
873 return dup;
874}
875
876
877/**
878 * Free memory taken by a packet.
879 *
880 * @param p packet to free
881 */
882void
883GNUNET_DNSPARSER_free_packet (struct GNUNET_DNSPARSER_Packet *p)
884{
885 for (unsigned int i=0;i<p->num_queries;i++)
886 GNUNET_free_non_null (p->queries[i].name);
887 GNUNET_free_non_null (p->queries);
888 for (unsigned int i=0;i<p->num_answers;i++)
889 GNUNET_DNSPARSER_free_record (&p->answers[i]);
890 GNUNET_free_non_null (p->answers);
891 for (unsigned int i=0;i<p->num_authority_records;i++)
892 GNUNET_DNSPARSER_free_record (&p->authority_records[i]);
893 GNUNET_free_non_null (p->authority_records);
894 for (unsigned int i=0;i<p->num_additional_records;i++)
895 GNUNET_DNSPARSER_free_record (&p->additional_records[i]);
896 GNUNET_free_non_null (p->additional_records);
897 GNUNET_free (p);
898}
899
900
901/* ********************** DNS packet assembly code **************** */
902
903
904/**
905 * Add a DNS name to the UDP packet at the given location, converting
906 * the name to IDNA notation as necessary.
907 *
908 * @param dst where to write the name (UDP packet)
909 * @param dst_len number of bytes in @a dst
910 * @param off pointer to offset where to write the name (increment by bytes used)
911 * must not be changed if there is an error
912 * @param name name to write
913 * @return #GNUNET_SYSERR if @a name is invalid
914 * #GNUNET_NO if @a name did not fit
915 * #GNUNET_OK if @a name was added to @a dst
916 */
917int
918GNUNET_DNSPARSER_builder_add_name (char *dst,
919 size_t dst_len,
920 size_t *off,
921 const char *name)
922{
923 const char *dot;
924 const char *idna_name;
925 char *idna_start;
926 size_t start;
927 size_t pos;
928 size_t len;
929 Idna_rc rc;
930
931 if (NULL == name)
932 return GNUNET_SYSERR;
933
934 if (IDNA_SUCCESS !=
935 (rc = idna_to_ascii_8z (name,
936 &idna_start,
937 IDNA_ALLOW_UNASSIGNED)))
938 {
939 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
940 _("Failed to convert UTF-8 name `%s' to DNS IDNA format: %s\n"),
941 name,
942 idna_strerror (rc));
943 return GNUNET_NO;
944 }
945 idna_name = idna_start;
946 start = *off;
947 if (start + strlen (idna_name) + 2 > dst_len)
948 goto fail;
949 pos = start;
950 do
951 {
952 dot = strchr (idna_name, '.');
953 if (NULL == dot)
954 len = strlen (idna_name);
955 else
956 len = dot - idna_name;
957 if ( (len >= 64) || (0 == len) )
958 {
959 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
960 "Invalid DNS name `%s': label with %u characters encountered\n",
961 name,
962 (unsigned int) len);
963 goto fail; /* label too long or empty */
964 }
965 dst[pos++] = (char) (uint8_t) len;
966 GNUNET_memcpy (&dst[pos],
967 idna_name,
968 len);
969 pos += len;
970 idna_name += len + 1; /* also skip dot */
971 }
972 while (NULL != dot);
973 dst[pos++] = '\0'; /* terminator */
974 *off = pos;
975#if WINDOWS
976 idn_free (idna_start);
977#else
978 free (idna_start);
979#endif
980 return GNUNET_OK;
981 fail:
982#if WINDOWS
983 idn_free (idna_start);
984#else
985 free (idna_start);
986#endif
987 return GNUNET_NO;
988}
989
990
991/**
992 * Add a DNS query to the UDP packet at the given location.
993 *
994 * @param dst where to write the query
995 * @param dst_len number of bytes in @a dst
996 * @param off pointer to offset where to write the query (increment by bytes used)
997 * must not be changed if there is an error
998 * @param query query to write
999 * @return #GNUNET_SYSERR if @a query is invalid
1000 * #GNUNET_NO if @a query did not fit
1001 * #GNUNET_OK if @a query was added to @a dst
1002 */
1003int
1004GNUNET_DNSPARSER_builder_add_query (char *dst,
1005 size_t dst_len,
1006 size_t *off,
1007 const struct GNUNET_DNSPARSER_Query *query)
1008{
1009 int ret;
1010 struct GNUNET_TUN_DnsQueryLine ql;
1011
1012 ret = GNUNET_DNSPARSER_builder_add_name (dst, dst_len - sizeof (struct GNUNET_TUN_DnsQueryLine), off, query->name);
1013 if (ret != GNUNET_OK)
1014 return ret;
1015 ql.type = htons (query->type);
1016 ql.dns_traffic_class = htons (query->dns_traffic_class);
1017 GNUNET_memcpy (&dst[*off], &ql, sizeof (ql));
1018 (*off) += sizeof (ql);
1019 return GNUNET_OK;
1020}
1021
1022
1023/**
1024 * Add an MX record to the UDP packet at the given location.
1025 *
1026 * @param dst where to write the mx record
1027 * @param dst_len number of bytes in @a dst
1028 * @param off pointer to offset where to write the mx information (increment by bytes used);
1029 * can also change if there was an error
1030 * @param mx mx information to write
1031 * @return #GNUNET_SYSERR if @a mx is invalid
1032 * #GNUNET_NO if @a mx did not fit
1033 * #GNUNET_OK if @a mx was added to @a dst
1034 */
1035int
1036GNUNET_DNSPARSER_builder_add_mx (char *dst,
1037 size_t dst_len,
1038 size_t *off,
1039 const struct GNUNET_DNSPARSER_MxRecord *mx)
1040{
1041 uint16_t mxpref;
1042
1043 if (*off + sizeof (uint16_t) > dst_len)
1044 return GNUNET_NO;
1045 mxpref = htons (mx->preference);
1046 GNUNET_memcpy (&dst[*off],
1047 &mxpref,
1048 sizeof (mxpref));
1049 (*off) += sizeof (mxpref);
1050 return GNUNET_DNSPARSER_builder_add_name (dst,
1051 dst_len,
1052 off,
1053 mx->mxhost);
1054}
1055
1056
1057/**
1058 * Add a CERT record to the UDP packet at the given location.
1059 *
1060 * @param dst where to write the CERT record
1061 * @param dst_len number of bytes in @a dst
1062 * @param off pointer to offset where to write the CERT information (increment by bytes used);
1063 * can also change if there was an error
1064 * @param cert CERT information to write
1065 * @return #GNUNET_SYSERR if @a cert is invalid
1066 * #GNUNET_NO if @a cert did not fit
1067 * #GNUNET_OK if @a cert was added to @a dst
1068 */
1069int
1070GNUNET_DNSPARSER_builder_add_cert (char *dst,
1071 size_t dst_len,
1072 size_t *off,
1073 const struct GNUNET_DNSPARSER_CertRecord *cert)
1074{
1075 struct GNUNET_TUN_DnsCertRecord dcert;
1076
1077 if ( (cert->cert_type > UINT16_MAX) ||
1078 (cert->algorithm > UINT8_MAX) )
1079 {
1080 GNUNET_break (0);
1081 return GNUNET_SYSERR;
1082 }
1083 if (*off + sizeof (struct GNUNET_TUN_DnsCertRecord) + cert->certificate_size > dst_len)
1084 return GNUNET_NO;
1085 dcert.cert_type = htons ((uint16_t) cert->cert_type);
1086 dcert.cert_tag = htons ((uint16_t) cert->cert_tag);
1087 dcert.algorithm = (uint8_t) cert->algorithm;
1088 GNUNET_memcpy (&dst[*off], &dcert, sizeof (dcert));
1089 (*off) += sizeof (dcert);
1090 GNUNET_memcpy (&dst[*off], cert->certificate_data, cert->certificate_size);
1091 (*off) += cert->certificate_size;
1092 return GNUNET_OK;
1093}
1094
1095
1096/**
1097 * Add an SOA record to the UDP packet at the given location.
1098 *
1099 * @param dst where to write the SOA record
1100 * @param dst_len number of bytes in @a dst
1101 * @param off pointer to offset where to write the SOA information (increment by bytes used)
1102 * can also change if there was an error
1103 * @param soa SOA information to write
1104 * @return #GNUNET_SYSERR if @a soa is invalid
1105 * #GNUNET_NO if @a soa did not fit
1106 * #GNUNET_OK if @a soa was added to @a dst
1107 */
1108int
1109GNUNET_DNSPARSER_builder_add_soa (char *dst,
1110 size_t dst_len,
1111 size_t *off,
1112 const struct GNUNET_DNSPARSER_SoaRecord *soa)
1113{
1114 struct GNUNET_TUN_DnsSoaRecord sd;
1115 int ret;
1116
1117 if ( (GNUNET_OK != (ret = GNUNET_DNSPARSER_builder_add_name (dst,
1118 dst_len,
1119 off,
1120 soa->mname))) ||
1121 (GNUNET_OK != (ret = GNUNET_DNSPARSER_builder_add_name (dst,
1122 dst_len,
1123 off,
1124 soa->rname)) ) )
1125 return ret;
1126 if (*off + sizeof (struct GNUNET_TUN_DnsSoaRecord) > dst_len)
1127 return GNUNET_NO;
1128 sd.serial = htonl (soa->serial);
1129 sd.refresh = htonl (soa->refresh);
1130 sd.retry = htonl (soa->retry);
1131 sd.expire = htonl (soa->expire);
1132 sd.minimum = htonl (soa->minimum_ttl);
1133 GNUNET_memcpy (&dst[*off], &sd, sizeof (sd));
1134 (*off) += sizeof (sd);
1135 return GNUNET_OK;
1136}
1137
1138
1139/**
1140 * Add an SRV record to the UDP packet at the given location.
1141 *
1142 * @param dst where to write the SRV record
1143 * @param dst_len number of bytes in @a dst
1144 * @param off pointer to offset where to write the SRV information (increment by bytes used)
1145 * can also change if there was an error
1146 * @param srv SRV information to write
1147 * @return #GNUNET_SYSERR if @a srv is invalid
1148 * #GNUNET_NO if @a srv did not fit
1149 * #GNUNET_OK if @a srv was added to @a dst
1150 */
1151int
1152GNUNET_DNSPARSER_builder_add_srv (char *dst,
1153 size_t dst_len,
1154 size_t *off,
1155 const struct GNUNET_DNSPARSER_SrvRecord *srv)
1156{
1157 struct GNUNET_TUN_DnsSrvRecord sd;
1158 int ret;
1159
1160 if (*off + sizeof (struct GNUNET_TUN_DnsSrvRecord) > dst_len)
1161 return GNUNET_NO;
1162 sd.prio = htons (srv->priority);
1163 sd.weight = htons (srv->weight);
1164 sd.port = htons (srv->port);
1165 GNUNET_memcpy (&dst[*off],
1166 &sd,
1167 sizeof (sd));
1168 (*off) += sizeof (sd);
1169 if (GNUNET_OK != (ret = GNUNET_DNSPARSER_builder_add_name (dst,
1170 dst_len,
1171 off,
1172 srv->target)))
1173 return ret;
1174 return GNUNET_OK;
1175}
1176
1177
1178/**
1179 * Add a DNS record to the UDP packet at the given location.
1180 *
1181 * @param dst where to write the query
1182 * @param dst_len number of bytes in @a dst
1183 * @param off pointer to offset where to write the query (increment by bytes used)
1184 * must not be changed if there is an error
1185 * @param record record to write
1186 * @return #GNUNET_SYSERR if @a record is invalid
1187 * #GNUNET_NO if @a record did not fit
1188 * #GNUNET_OK if @a record was added to @a dst
1189 */
1190static int
1191add_record (char *dst,
1192 size_t dst_len,
1193 size_t *off,
1194 const struct GNUNET_DNSPARSER_Record *record)
1195{
1196 int ret;
1197 size_t start;
1198 size_t pos;
1199 struct GNUNET_TUN_DnsRecordLine rl;
1200
1201 start = *off;
1202 ret = GNUNET_DNSPARSER_builder_add_name (dst,
1203 dst_len - sizeof (struct GNUNET_TUN_DnsRecordLine),
1204 off,
1205 record->name);
1206 if (GNUNET_OK != ret)
1207 return ret;
1208 /* '*off' is now the position where we will need to write the record line */
1209
1210 pos = *off + sizeof (struct GNUNET_TUN_DnsRecordLine);
1211 switch (record->type)
1212 {
1213 case GNUNET_DNSPARSER_TYPE_MX:
1214 ret = GNUNET_DNSPARSER_builder_add_mx (dst,
1215 dst_len,
1216 &pos,
1217 record->data.mx);
1218 break;
1219 case GNUNET_DNSPARSER_TYPE_CERT:
1220 ret = GNUNET_DNSPARSER_builder_add_cert (dst,
1221 dst_len,
1222 &pos,
1223 record->data.cert);
1224 break;
1225 case GNUNET_DNSPARSER_TYPE_SOA:
1226 ret = GNUNET_DNSPARSER_builder_add_soa (dst,
1227 dst_len,
1228 &pos,
1229 record->data.soa);
1230 break;
1231 case GNUNET_DNSPARSER_TYPE_NS:
1232 case GNUNET_DNSPARSER_TYPE_CNAME:
1233 case GNUNET_DNSPARSER_TYPE_PTR:
1234 ret = GNUNET_DNSPARSER_builder_add_name (dst,
1235 dst_len,
1236 &pos,
1237 record->data.hostname);
1238 break;
1239 case GNUNET_DNSPARSER_TYPE_SRV:
1240 ret = GNUNET_DNSPARSER_builder_add_srv (dst,
1241 dst_len,
1242 &pos,
1243 record->data.srv);
1244 break;
1245 default:
1246 if (pos + record->data.raw.data_len > dst_len)
1247 {
1248 ret = GNUNET_NO;
1249 break;
1250 }
1251 GNUNET_memcpy (&dst[pos],
1252 record->data.raw.data,
1253 record->data.raw.data_len);
1254 pos += record->data.raw.data_len;
1255 ret = GNUNET_OK;
1256 break;
1257 }
1258 if (GNUNET_OK != ret)
1259 {
1260 *off = start;
1261 return GNUNET_NO;
1262 }
1263
1264 if (pos - (*off + sizeof (struct GNUNET_TUN_DnsRecordLine)) > UINT16_MAX)
1265 {
1266 /* record data too long */
1267 *off = start;
1268 return GNUNET_NO;
1269 }
1270 rl.type = htons (record->type);
1271 rl.dns_traffic_class = htons (record->dns_traffic_class);
1272 rl.ttl = htonl (GNUNET_TIME_absolute_get_remaining (record->expiration_time).rel_value_us / 1000LL / 1000LL); /* in seconds */
1273 rl.data_len = htons ((uint16_t) (pos - (*off + sizeof (struct GNUNET_TUN_DnsRecordLine))));
1274 GNUNET_memcpy (&dst[*off],
1275 &rl,
1276 sizeof (struct GNUNET_TUN_DnsRecordLine));
1277 *off = pos;
1278 return GNUNET_OK;
1279}
1280
1281
1282/**
1283 * Given a DNS packet @a p, generate the corresponding UDP payload.
1284 * Note that we do not attempt to pack the strings with pointers
1285 * as this would complicate the code and this is about being
1286 * simple and secure, not fast, fancy and broken like bind.
1287 *
1288 * @param p packet to pack
1289 * @param max maximum allowed size for the resulting UDP payload
1290 * @param buf set to a buffer with the packed message
1291 * @param buf_length set to the length of @a buf
1292 * @return #GNUNET_SYSERR if @a p is invalid
1293 * #GNUNET_NO if @a p was truncated (but there is still a result in @a buf)
1294 * #GNUNET_OK if @a p was packed completely into @a buf
1295 */
1296int
1297GNUNET_DNSPARSER_pack (const struct GNUNET_DNSPARSER_Packet *p,
1298 uint16_t max,
1299 char **buf,
1300 size_t *buf_length)
1301{
1302 struct GNUNET_TUN_DnsHeader dns;
1303 size_t off;
1304 char tmp[max];
1305 int ret;
1306 int trc;
1307
1308 if ( (p->num_queries > UINT16_MAX) ||
1309 (p->num_answers > UINT16_MAX) ||
1310 (p->num_authority_records > UINT16_MAX) ||
1311 (p->num_additional_records > UINT16_MAX) )
1312 return GNUNET_SYSERR;
1313 dns.id = p->id;
1314 dns.flags = p->flags;
1315 dns.query_count = htons (p->num_queries);
1316 dns.answer_rcount = htons (p->num_answers);
1317 dns.authority_rcount = htons (p->num_authority_records);
1318 dns.additional_rcount = htons (p->num_additional_records);
1319
1320 off = sizeof (struct GNUNET_TUN_DnsHeader);
1321 trc = GNUNET_NO;
1322 for (unsigned int i=0;i<p->num_queries;i++)
1323 {
1324 ret = GNUNET_DNSPARSER_builder_add_query (tmp,
1325 sizeof (tmp),
1326 &off,
1327 &p->queries[i]);
1328 if (GNUNET_SYSERR == ret)
1329 return GNUNET_SYSERR;
1330 if (GNUNET_NO == ret)
1331 {
1332 dns.query_count = htons ((uint16_t) (i-1));
1333 trc = GNUNET_YES;
1334 break;
1335 }
1336 }
1337 for (unsigned int i=0;i<p->num_answers;i++)
1338 {
1339 ret = add_record (tmp,
1340 sizeof (tmp),
1341 &off,
1342 &p->answers[i]);
1343 if (GNUNET_SYSERR == ret)
1344 return GNUNET_SYSERR;
1345 if (GNUNET_NO == ret)
1346 {
1347 dns.answer_rcount = htons ((uint16_t) (i-1));
1348 trc = GNUNET_YES;
1349 break;
1350 }
1351 }
1352 for (unsigned int i=0;i<p->num_authority_records;i++)
1353 {
1354 ret = add_record (tmp,
1355 sizeof (tmp),
1356 &off,
1357 &p->authority_records[i]);
1358 if (GNUNET_SYSERR == ret)
1359 return GNUNET_SYSERR;
1360 if (GNUNET_NO == ret)
1361 {
1362 dns.authority_rcount = htons ((uint16_t) (i-1));
1363 trc = GNUNET_YES;
1364 break;
1365 }
1366 }
1367 for (unsigned int i=0;i<p->num_additional_records;i++)
1368 {
1369 ret = add_record (tmp,
1370 sizeof (tmp),
1371 &off,
1372 &p->additional_records[i]);
1373 if (GNUNET_SYSERR == ret)
1374 return GNUNET_SYSERR;
1375 if (GNUNET_NO == ret)
1376 {
1377 dns.additional_rcount = htons (i-1);
1378 trc = GNUNET_YES;
1379 break;
1380 }
1381 }
1382
1383 if (GNUNET_YES == trc)
1384 dns.flags.message_truncated = 1;
1385 GNUNET_memcpy (tmp,
1386 &dns,
1387 sizeof (struct GNUNET_TUN_DnsHeader));
1388
1389 *buf = GNUNET_malloc (off);
1390 *buf_length = off;
1391 GNUNET_memcpy (*buf,
1392 tmp,
1393 off);
1394 if (GNUNET_YES == trc)
1395 return GNUNET_NO;
1396 return GNUNET_OK;
1397}
1398
1399
1400/**
1401 * Convert a block of binary data to HEX.
1402 *
1403 * @param data binary data to convert
1404 * @param data_size number of bytes in @a data
1405 * @return HEX string (lower case)
1406 */
1407char *
1408GNUNET_DNSPARSER_bin_to_hex (const void *data,
1409 size_t data_size)
1410{
1411 char *ret;
1412 size_t off;
1413 const uint8_t *idata;
1414
1415 idata = data;
1416 ret = GNUNET_malloc (data_size * 2 + 1);
1417 for (off = 0; off < data_size; off++)
1418 sprintf (&ret[off * 2],
1419 "%02x",
1420 idata[off]);
1421 return ret;
1422}
1423
1424
1425/**
1426 * Convert a HEX string to block of binary data.
1427 *
1428 * @param hex HEX string to convert (may contain mixed case)
1429 * @param data where to write result, must be
1430 * at least `strlen(hex)/2` bytes long
1431 * @return number of bytes written to data
1432 */
1433size_t
1434GNUNET_DNSPARSER_hex_to_bin (const char *hex,
1435 void *data)
1436{
1437 size_t data_size;
1438 size_t off;
1439 uint8_t *idata;
1440 unsigned int h;
1441 char in[3];
1442
1443 data_size = strlen (hex) / 2;
1444 idata = data;
1445 in[2] = '\0';
1446 for (off = 0; off < data_size; off++)
1447 {
1448 in[0] = tolower ((unsigned char) hex[off * 2]);
1449 in[1] = tolower ((unsigned char) hex[off * 2 + 1]);
1450 if (1 != sscanf (in, "%x", &h))
1451 return off;
1452 idata[off] = (uint8_t) h;
1453 }
1454 return off;
1455}
1456
1457
1458/* end of dnsparser.c */
diff --git a/src/util/dnsstub.c b/src/util/dnsstub.c
new file mode 100644
index 000000000..5b84e6e63
--- /dev/null
+++ b/src/util/dnsstub.c
@@ -0,0 +1,747 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012, 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 dns/dnsstub.c
20 * @brief DNS stub resolver which sends DNS requests to an actual resolver
21 * @author Christian Grothoff
22 */
23#include "platform.h"
24#include "gnunet_util_lib.h"
25
26/**
27 * Timeout for retrying DNS queries.
28 */
29#define DNS_RETRANSMIT_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
30
31
32/**
33 * DNS Server used for resolution.
34 */
35struct DnsServer;
36
37
38/**
39 * UDP socket we are using for sending DNS requests to the Internet.
40 */
41struct GNUNET_DNSSTUB_RequestSocket
42{
43
44 /**
45 * UDP socket we use for this request for IPv4
46 */
47 struct GNUNET_NETWORK_Handle *dnsout4;
48
49 /**
50 * UDP socket we use for this request for IPv6
51 */
52 struct GNUNET_NETWORK_Handle *dnsout6;
53
54 /**
55 * Function to call with result.
56 */
57 GNUNET_DNSSTUB_ResultCallback rc;
58
59 /**
60 * Closure for @e rc.
61 */
62 void *rc_cls;
63
64 /**
65 * Task for reading from dnsout4 and dnsout6.
66 */
67 struct GNUNET_SCHEDULER_Task *read_task;
68
69 /**
70 * Task for retrying transmission of the query.
71 */
72 struct GNUNET_SCHEDULER_Task *retry_task;
73
74 /**
75 * Next address we sent the DNS request to.
76 */
77 struct DnsServer *ds_pos;
78
79 /**
80 * Context this request executes in.
81 */
82 struct GNUNET_DNSSTUB_Context *ctx;
83
84 /**
85 * Query we sent to @e addr.
86 */
87 void *request;
88
89 /**
90 * Number of bytes in @a request.
91 */
92 size_t request_len;
93
94};
95
96
97/**
98 * DNS Server used for resolution.
99 */
100struct DnsServer
101{
102
103 /**
104 * Kept in a DLL.
105 */
106 struct DnsServer *next;
107
108 /**
109 * Kept in a DLL.
110 */
111 struct DnsServer *prev;
112
113 /**
114 * IP address of the DNS resolver.
115 */
116 struct sockaddr_storage ss;
117};
118
119
120/**
121 * Handle to the stub resolver.
122 */
123struct GNUNET_DNSSTUB_Context
124{
125
126 /**
127 * Array of all open sockets for DNS requests.
128 */
129 struct GNUNET_DNSSTUB_RequestSocket *sockets;
130
131 /**
132 * DLL of DNS resolvers we use.
133 */
134 struct DnsServer *dns_head;
135
136 /**
137 * DLL of DNS resolvers we use.
138 */
139 struct DnsServer *dns_tail;
140
141 /**
142 * How frequently do we retry requests?
143 */
144 struct GNUNET_TIME_Relative retry_freq;
145
146 /**
147 * Length of @e sockets array.
148 */
149 unsigned int num_sockets;
150
151};
152
153
154/**
155 * We're done with a `struct GNUNET_DNSSTUB_RequestSocket`, close it for now.
156 *
157 * @param rs request socket to clean up
158 */
159static void
160cleanup_rs (struct GNUNET_DNSSTUB_RequestSocket *rs)
161{
162 if (NULL != rs->dnsout4)
163 {
164 GNUNET_NETWORK_socket_close (rs->dnsout4);
165 rs->dnsout4 = NULL;
166 }
167 if (NULL != rs->dnsout6)
168 {
169 GNUNET_NETWORK_socket_close (rs->dnsout6);
170 rs->dnsout6 = NULL;
171 }
172 if (NULL != rs->read_task)
173 {
174 GNUNET_SCHEDULER_cancel (rs->read_task);
175 rs->read_task = NULL;
176 }
177 if (NULL != rs->retry_task)
178 {
179 GNUNET_SCHEDULER_cancel (rs->retry_task);
180 rs->retry_task = NULL;
181 }
182 if (NULL != rs->request)
183 {
184 GNUNET_free (rs->request);
185 rs->request = NULL;
186 }
187}
188
189
190/**
191 * Open source port for sending DNS requests
192 *
193 * @param af AF_INET or AF_INET6
194 * @return #GNUNET_OK on success
195 */
196static struct GNUNET_NETWORK_Handle *
197open_socket (int af)
198{
199 struct sockaddr_in a4;
200 struct sockaddr_in6 a6;
201 struct sockaddr *sa;
202 socklen_t alen;
203 struct GNUNET_NETWORK_Handle *ret;
204
205 ret = GNUNET_NETWORK_socket_create (af, SOCK_DGRAM, 0);
206 if (NULL == ret)
207 return NULL;
208 switch (af)
209 {
210 case AF_INET:
211 memset (&a4, 0, alen = sizeof (struct sockaddr_in));
212 sa = (struct sockaddr *) &a4;
213 break;
214 case AF_INET6:
215 memset (&a6, 0, alen = sizeof (struct sockaddr_in6));
216 sa = (struct sockaddr *) &a6;
217 break;
218 default:
219 GNUNET_break (0);
220 GNUNET_NETWORK_socket_close (ret);
221 return NULL;
222 }
223 sa->sa_family = af;
224 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret,
225 sa,
226 alen))
227 {
228 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
229 _("Could not bind to any port: %s\n"),
230 STRERROR (errno));
231 GNUNET_NETWORK_socket_close (ret);
232 return NULL;
233 }
234 return ret;
235}
236
237
238/**
239 * Get a socket of the specified address family to send out a
240 * UDP DNS request to the Internet.
241 *
242 * @param ctx the DNSSTUB context
243 * @return NULL on error
244 */
245static struct GNUNET_DNSSTUB_RequestSocket *
246get_request_socket (struct GNUNET_DNSSTUB_Context *ctx)
247{
248 struct GNUNET_DNSSTUB_RequestSocket *rs;
249
250 for (unsigned int i=0;i<256;i++)
251 {
252 rs = &ctx->sockets[GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
253 ctx->num_sockets)];
254 if (NULL == rs->rc)
255 break;
256 }
257 if (NULL != rs->rc)
258 {
259 /* signal "failure" */
260 rs->rc (rs->rc_cls,
261 NULL,
262 0);
263 rs->rc = NULL;
264 }
265 if (NULL != rs->read_task)
266 {
267 GNUNET_SCHEDULER_cancel (rs->read_task);
268 rs->read_task = NULL;
269 }
270 if (NULL != rs->retry_task)
271 {
272 GNUNET_SCHEDULER_cancel (rs->retry_task);
273 rs->retry_task = NULL;
274 }
275 if (NULL != rs->request)
276 {
277 GNUNET_free (rs->request);
278 rs->request = NULL;
279 }
280 rs->ctx = ctx;
281 return rs;
282}
283
284
285/**
286 * Actually do the reading of a DNS packet from our UDP socket and see
287 * if we have a valid, matching, pending request.
288 *
289 * @param rs request socket with callback details
290 * @param dnsout socket to read from
291 * @return #GNUNET_OK on success, #GNUNET_NO on drop, #GNUNET_SYSERR on IO-errors (closed socket)
292 */
293static int
294do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
295 struct GNUNET_NETWORK_Handle *dnsout)
296{
297 struct GNUNET_DNSSTUB_Context *ctx = rs->ctx;
298 ssize_t r;
299 int len;
300
301#ifndef MINGW
302 if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout),
303 FIONREAD,
304 &len))
305 {
306 /* conservative choice: */
307 len = UINT16_MAX;
308 }
309#else
310 /* port the code above? */
311 len = UINT16_MAX;
312#endif
313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
314 "Receiving %d byte DNS reply\n",
315 len);
316 {
317 unsigned char buf[len] GNUNET_ALIGN;
318 int found;
319 struct sockaddr_storage addr;
320 socklen_t addrlen;
321 struct GNUNET_TUN_DnsHeader *dns;
322
323 addrlen = sizeof (addr);
324 memset (&addr,
325 0,
326 sizeof (addr));
327 r = GNUNET_NETWORK_socket_recvfrom (dnsout,
328 buf,
329 sizeof (buf),
330 (struct sockaddr*) &addr,
331 &addrlen);
332 if (-1 == r)
333 {
334 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
335 "recvfrom");
336 GNUNET_NETWORK_socket_close (dnsout);
337 return GNUNET_SYSERR;
338 }
339 found = GNUNET_NO;
340 for (struct DnsServer *ds = ctx->dns_head; NULL != ds; ds = ds->next)
341 {
342 if (0 == memcmp (&addr,
343 &ds->ss,
344 GNUNET_MIN (sizeof (struct sockaddr_storage),
345 addrlen)))
346 {
347 found = GNUNET_YES;
348 break;
349 }
350 }
351 if (GNUNET_NO == found)
352 {
353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
354 "Received DNS response from server we never asked (ignored)");
355 return GNUNET_NO;
356 }
357 if (sizeof (struct GNUNET_TUN_DnsHeader) > (size_t) r)
358 {
359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
360 _("Received DNS response that is too small (%u bytes)"),
361 (unsigned int) r);
362 return GNUNET_NO;
363 }
364 dns = (struct GNUNET_TUN_DnsHeader *) buf;
365 if (NULL == rs->rc)
366 {
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
368 "Request timeout or cancelled; ignoring reply\n");
369 return GNUNET_NO;
370 }
371 rs->rc (rs->rc_cls,
372 dns,
373 r);
374 }
375 return GNUNET_OK;
376}
377
378
379/**
380 * Read a DNS response from the (unhindered) UDP-Socket
381 *
382 * @param cls socket to read from
383 */
384static void
385read_response (void *cls);
386
387
388/**
389 * Schedule #read_response() task for @a rs.
390 *
391 * @param rs request to schedule read operation for
392 */
393static void
394schedule_read (struct GNUNET_DNSSTUB_RequestSocket *rs)
395{
396 struct GNUNET_NETWORK_FDSet *rset;
397
398 if (NULL != rs->read_task)
399 GNUNET_SCHEDULER_cancel (rs->read_task);
400 rset = GNUNET_NETWORK_fdset_create ();
401 if (NULL != rs->dnsout4)
402 GNUNET_NETWORK_fdset_set (rset,
403 rs->dnsout4);
404 if (NULL != rs->dnsout6)
405 GNUNET_NETWORK_fdset_set (rset,
406 rs->dnsout6);
407 rs->read_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
408 GNUNET_TIME_UNIT_FOREVER_REL,
409 rset,
410 NULL,
411 &read_response,
412 rs);
413 GNUNET_NETWORK_fdset_destroy (rset);
414}
415
416
417/**
418 * Read a DNS response from the (unhindered) UDP-Socket
419 *
420 * @param cls `struct GNUNET_DNSSTUB_RequestSocket` to read from
421 */
422static void
423read_response (void *cls)
424{
425 struct GNUNET_DNSSTUB_RequestSocket *rs = cls;
426 const struct GNUNET_SCHEDULER_TaskContext *tc;
427
428 rs->read_task = NULL;
429 tc = GNUNET_SCHEDULER_get_task_context ();
430 /* read and process ready sockets */
431 if ( (NULL != rs->dnsout4) &&
432 (GNUNET_NETWORK_fdset_isset (tc->read_ready,
433 rs->dnsout4)) &&
434 (GNUNET_SYSERR ==
435 do_dns_read (rs,
436 rs->dnsout4)) )
437 rs->dnsout4 = NULL;
438 if ( (NULL != rs->dnsout6) &&
439 (GNUNET_NETWORK_fdset_isset (tc->read_ready,
440 rs->dnsout6)) &&
441 (GNUNET_SYSERR ==
442 do_dns_read (rs,
443 rs->dnsout6)) )
444 rs->dnsout6 = NULL;
445 /* re-schedule read task */
446 schedule_read (rs);
447}
448
449
450/**
451 * Task to (re)transmit the DNS query, possibly repeatedly until
452 * we succeed.
453 *
454 * @param cls our `struct GNUNET_DNSSTUB_RequestSocket *`
455 */
456static void
457transmit_query (void *cls)
458{
459 struct GNUNET_DNSSTUB_RequestSocket *rs = cls;
460 struct GNUNET_DNSSTUB_Context *ctx = rs->ctx;
461 const struct sockaddr *sa;
462 socklen_t salen;
463 struct DnsServer *ds;
464 struct GNUNET_NETWORK_Handle *dnsout;
465
466 rs->retry_task = GNUNET_SCHEDULER_add_delayed (ctx->retry_freq,
467 &transmit_query,
468 rs);
469 ds = rs->ds_pos;
470 rs->ds_pos = ds->next;
471 if (NULL == rs->ds_pos)
472 rs->ds_pos = ctx->dns_head;
473 GNUNET_assert (NULL != ds);
474 dnsout = NULL;
475 switch (ds->ss.ss_family)
476 {
477 case AF_INET:
478 if (NULL == rs->dnsout4)
479 rs->dnsout4 = open_socket (AF_INET);
480 dnsout = rs->dnsout4;
481 sa = (const struct sockaddr *) &ds->ss;
482 salen = sizeof (struct sockaddr_in);
483 break;
484 case AF_INET6:
485 if (NULL == rs->dnsout6)
486 rs->dnsout6 = open_socket (AF_INET6);
487 dnsout = rs->dnsout6;
488 sa = (const struct sockaddr *) &ds->ss;
489 salen = sizeof (struct sockaddr_in6);
490 break;
491 default:
492 return;
493 }
494 if (NULL == dnsout)
495 {
496 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
497 "Unable to use configure DNS server, skipping\n");
498 return;
499 }
500 if (GNUNET_SYSERR ==
501 GNUNET_NETWORK_socket_sendto (dnsout,
502 rs->request,
503 rs->request_len,
504 sa,
505 salen))
506 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
507 _("Failed to send DNS request to %s: %s\n"),
508 GNUNET_a2s (sa,
509 salen),
510 STRERROR (errno));
511 else
512 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
513 _("Sent DNS request to %s\n"),
514 GNUNET_a2s (sa,
515 salen));
516 schedule_read (rs);
517}
518
519
520/**
521 * Perform DNS resolution using our default IP from init.
522 *
523 * @param ctx stub resolver to use
524 * @param request DNS request to transmit
525 * @param request_len number of bytes in msg
526 * @param rc function to call with result
527 * @param rc_cls closure for 'rc'
528 * @return socket used for the request, NULL on error
529 */
530struct GNUNET_DNSSTUB_RequestSocket *
531GNUNET_DNSSTUB_resolve (struct GNUNET_DNSSTUB_Context *ctx,
532 const void *request,
533 size_t request_len,
534 GNUNET_DNSSTUB_ResultCallback rc,
535 void *rc_cls)
536{
537 struct GNUNET_DNSSTUB_RequestSocket *rs;
538
539 if (NULL == ctx->dns_head)
540 {
541 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
542 "No DNS server configured for resolution\n");
543 return NULL;
544 }
545 if (NULL == (rs = get_request_socket (ctx)))
546 {
547 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
548 "No request socket available for DNS resolution\n");
549 return NULL;
550 }
551 rs->ds_pos = ctx->dns_head;
552 rs->rc = rc;
553 rs->rc_cls = rc_cls;
554 rs->request = GNUNET_memdup (request,
555 request_len);
556 rs->request_len = request_len;
557 rs->retry_task = GNUNET_SCHEDULER_add_now (&transmit_query,
558 rs);
559 return rs;
560}
561
562
563/**
564 * Cancel DNS resolution.
565 *
566 * @param rs resolution to cancel
567 */
568void
569GNUNET_DNSSTUB_resolve_cancel (struct GNUNET_DNSSTUB_RequestSocket *rs)
570{
571 rs->rc = NULL;
572 if (NULL != rs->retry_task)
573 {
574 GNUNET_SCHEDULER_cancel (rs->retry_task);
575 rs->retry_task = NULL;
576 }
577 if (NULL != rs->read_task)
578 {
579 GNUNET_SCHEDULER_cancel (rs->read_task);
580 rs->read_task = NULL;
581 }
582}
583
584
585/**
586 * Start a DNS stub resolver.
587 *
588 * @param num_sockets how many sockets should we open
589 * in parallel for DNS queries for this stub?
590 * @return NULL on error
591 */
592struct GNUNET_DNSSTUB_Context *
593GNUNET_DNSSTUB_start (unsigned int num_sockets)
594{
595 struct GNUNET_DNSSTUB_Context *ctx;
596
597 if (0 == num_sockets)
598 {
599 GNUNET_break (0);
600 return NULL;
601 }
602 ctx = GNUNET_new (struct GNUNET_DNSSTUB_Context);
603 ctx->num_sockets = num_sockets;
604 ctx->sockets = GNUNET_new_array (num_sockets,
605 struct GNUNET_DNSSTUB_RequestSocket);
606 ctx->retry_freq = DNS_RETRANSMIT_DELAY;
607 return ctx;
608}
609
610
611/**
612 * Add nameserver for use by the DNSSTUB. We will use
613 * all provided nameservers for resolution (round-robin).
614 *
615 * @param ctx resolver context to modify
616 * @param dns_ip target IP address to use (as string)
617 * @return #GNUNET_OK on success
618 */
619int
620GNUNET_DNSSTUB_add_dns_ip (struct GNUNET_DNSSTUB_Context *ctx,
621 const char *dns_ip)
622{
623 struct DnsServer *ds;
624 struct in_addr i4;
625 struct in6_addr i6;
626
627 ds = GNUNET_new (struct DnsServer);
628 if (1 == inet_pton (AF_INET,
629 dns_ip,
630 &i4))
631 {
632 struct sockaddr_in *s4 = (struct sockaddr_in *) &ds->ss;
633
634 s4->sin_family = AF_INET;
635 s4->sin_port = htons (53);
636 s4->sin_addr = i4;
637#if HAVE_SOCKADDR_IN_SIN_LEN
638 s4->sin_len = (u_char) sizeof (struct sockaddr_in);
639#endif
640 }
641 else if (1 == inet_pton (AF_INET6,
642 dns_ip,
643 &i6))
644 {
645 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) &ds->ss;
646
647 s6->sin6_family = AF_INET6;
648 s6->sin6_port = htons (53);
649 s6->sin6_addr = i6;
650#if HAVE_SOCKADDR_IN_SIN_LEN
651 s6->sin6_len = (u_char) sizeof (struct sockaddr_in6);
652#endif
653 }
654 else
655 {
656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
657 "Malformed IP address `%s' for DNS server\n",
658 dns_ip);
659 GNUNET_free (ds);
660 return GNUNET_SYSERR;
661 }
662 GNUNET_CONTAINER_DLL_insert (ctx->dns_head,
663 ctx->dns_tail,
664 ds);
665 return GNUNET_OK;
666}
667
668
669/**
670 * Add nameserver for use by the DNSSTUB. We will use
671 * all provided nameservers for resolution (round-robin).
672 *
673 * @param ctx resolver context to modify
674 * @param sa socket address of DNS resolver to use
675 * @return #GNUNET_OK on success
676 */
677int
678GNUNET_DNSSTUB_add_dns_sa (struct GNUNET_DNSSTUB_Context *ctx,
679 const struct sockaddr *sa)
680{
681 struct DnsServer *ds;
682
683 ds = GNUNET_new (struct DnsServer);
684 switch (sa->sa_family)
685 {
686 case AF_INET:
687 GNUNET_memcpy (&ds->ss,
688 sa,
689 sizeof (struct sockaddr_in));
690 break;
691 case AF_INET6:
692 GNUNET_memcpy (&ds->ss,
693 sa,
694 sizeof (struct sockaddr_in6));
695 break;
696 default:
697 GNUNET_break (0);
698 GNUNET_free (ds);
699 return GNUNET_SYSERR;
700 }
701 GNUNET_CONTAINER_DLL_insert (ctx->dns_head,
702 ctx->dns_tail,
703 ds);
704 return GNUNET_OK;
705}
706
707
708/**
709 * How long should we try requests before timing out?
710 * Only effective for requests issued after this call.
711 *
712 * @param ctx resolver context to modify
713 * @param retry_freq how long to wait between retries
714 */
715void
716GNUNET_DNSSTUB_set_retry (struct GNUNET_DNSSTUB_Context *ctx,
717 struct GNUNET_TIME_Relative retry_freq)
718{
719 ctx->retry_freq = retry_freq;
720}
721
722
723/**
724 * Cleanup DNSSTUB resolver.
725 *
726 * @param ctx stub resolver to clean up
727 */
728void
729GNUNET_DNSSTUB_stop (struct GNUNET_DNSSTUB_Context *ctx)
730{
731 struct DnsServer *ds;
732
733 while (NULL != (ds = ctx->dns_head))
734 {
735 GNUNET_CONTAINER_DLL_remove (ctx->dns_head,
736 ctx->dns_tail,
737 ds);
738 GNUNET_free (ds);
739 }
740 for (unsigned int i=0;i<ctx->num_sockets;i++)
741 cleanup_rs (&ctx->sockets[i]);
742 GNUNET_free (ctx->sockets);
743 GNUNET_free (ctx);
744}
745
746
747/* end of dnsstub.c */
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c
index c836c9055..32cce65dd 100644
--- a/src/util/getopt_helpers.c
+++ b/src/util/getopt_helpers.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2006, 2011 GNUnet e.V. 3 Copyright (C) 2006, 2011 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/**
@@ -750,6 +748,13 @@ set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
750 unsigned int *val = scls; 748 unsigned int *val = scls;
751 749
752 (void) ctx; 750 (void) ctx;
751 if('-' == *value)
752 {
753 FPRINTF (stderr,
754 _("Your input for the '%s' option has to be a non negative number \n"),
755 option);
756 return GNUNET_SYSERR;
757 }
753 if (1 != SSCANF (value, 758 if (1 != SSCANF (value,
754 "%u", 759 "%u",
755 val)) 760 val))
@@ -793,6 +798,82 @@ GNUNET_GETOPT_option_uint (char shortName,
793} 798}
794 799
795 800
801
802/**
803 * Set an option of type 'uint16_t' from the command line.
804 * A pointer to this function should be passed as part of the
805 * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options
806 * of this type. It should be followed by a pointer to a value of
807 * type 'uint16_t'.
808 *
809 * @param ctx command line processing context
810 * @param scls additional closure (will point to the 'unsigned int')
811 * @param option name of the option
812 * @param value actual value of the option as a string.
813 * @return #GNUNET_OK if parsing the value worked
814 */
815static int
816set_uint16 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
817 void *scls,
818 const char *option,
819 const char *value)
820{
821 uint16_t *val = scls;
822 unsigned int v;
823
824 (void) ctx;
825 if (1 != SSCANF (value,
826 "%u",
827 &v))
828 {
829 FPRINTF (stderr,
830 _("You must pass a number to the `%s' option.\n"),
831 option);
832 return GNUNET_SYSERR;
833 }
834 if (v > UINT16_MAX)
835 {
836 FPRINTF (stderr,
837 _("You must pass a number below %u to the `%s' option.\n"),
838 (unsigned int) UINT16_MAX,
839 option);
840 return GNUNET_SYSERR;
841 }
842 *val = (uint16_t) v;
843 return GNUNET_OK;
844}
845
846
847/**
848 * Allow user to specify an uint16_t.
849 *
850 * @param shortName short name of the option
851 * @param name long name of the option
852 * @param argumentHelp help text for the option argument
853 * @param description long help text for the option
854 * @param[out] val set to the value specified at the command line
855 */
856struct GNUNET_GETOPT_CommandLineOption
857GNUNET_GETOPT_option_uint16 (char shortName,
858 const char *name,
859 const char *argumentHelp,
860 const char *description,
861 uint16_t *val)
862{
863 struct GNUNET_GETOPT_CommandLineOption clo = {
864 .shortName = shortName,
865 .name = name,
866 .argumentHelp = argumentHelp,
867 .description = description,
868 .require_argument = 1,
869 .processor = &set_uint16,
870 .scls = (void *) val
871 };
872
873 return clo;
874}
875
876
796/** 877/**
797 * Closure for #set_base32(). 878 * Closure for #set_base32().
798 */ 879 */
diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c
index 5f7d9fc0d..4528bbe24 100644
--- a/src/util/gnunet-config.c
+++ b/src/util/gnunet-config.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/** 19/**
@@ -77,12 +75,37 @@ print_option (void *cls,
77 const char *option, 75 const char *option,
78 const char *value) 76 const char *value)
79{ 77{
80 (void) cls; 78 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
79
81 (void) section; 80 (void) section;
82 fprintf (stdout, 81 if (is_filename)
83 "%s = %s\n", 82 {
84 option, 83 char *value_fn;
85 value); 84 char *fn;
85
86 GNUNET_assert (GNUNET_OK ==
87 GNUNET_CONFIGURATION_get_value_filename (cfg,
88 section,
89 option,
90 &value_fn));
91 fn = GNUNET_STRINGS_filename_expand (value_fn);
92 if (NULL == fn)
93 fn = value_fn;
94 else
95 GNUNET_free (value_fn);
96 fprintf (stdout,
97 "%s = %s\n",
98 option,
99 fn);
100 GNUNET_free (fn);
101 }
102 else
103 {
104 fprintf (stdout,
105 "%s = %s\n",
106 option,
107 value);
108 }
86} 109}
87 110
88 111
@@ -161,8 +184,8 @@ run (void *cls,
161 { 184 {
162 GNUNET_CONFIGURATION_iterate_section_values (cfg, 185 GNUNET_CONFIGURATION_iterate_section_values (cfg,
163 section, 186 section,
164 &print_option, 187 &print_option,
165 NULL); 188 (void *) cfg);
166 } 189 }
167 else 190 else
168 { 191 {
diff --git a/src/util/gnunet-ecc.c b/src/util/gnunet-ecc.c
index 59a100a8c..438999402 100644
--- a/src/util/gnunet-ecc.c
+++ b/src/util/gnunet-ecc.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/** 19/**
diff --git a/src/util/gnunet-helper-w32-console.c b/src/util/gnunet-helper-w32-console.c
index cde730fcd..3540cae8a 100644
--- a/src/util/gnunet-helper-w32-console.c
+++ b/src/util/gnunet-helper-w32-console.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2014 GNUnet e.V. 3 Copyright (C) 2014 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/util/gnunet-helper-w32-console.h b/src/util/gnunet-helper-w32-console.h
index 452c83248..d70b0e32a 100644
--- a/src/util/gnunet-helper-w32-console.h
+++ b/src/util/gnunet-helper-w32-console.h
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2014 GNUnet e.V. 3 Copyright (C) 2014 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/util/gnunet-qr.py.in b/src/util/gnunet-qr.py.in
index 549ce5af1..a5918fdf8 100755
--- a/src/util/gnunet-qr.py.in
+++ b/src/util/gnunet-qr.py.in
@@ -4,105 +4,106 @@ import getopt
4import subprocess 4import subprocess
5from sys import argv 5from sys import argv
6try: 6try:
7 import zbar 7 import zbar
8except ImportError as e: 8except ImportError as e:
9 print('Cannot run gnunet-qr, please install zbar-python') 9 print('Cannot run gnunet-qr, please install zbar-python')
10 sys.exit (1) 10 sys.exit(1)
11 11
12def help (): 12
13 print('gnunet-qr\n\ 13def help():
14 print('gnunet-qr\n\
14Scan a QR code using a video device and import\n\ 15Scan a QR code using a video device and import\n\
15Arguments mandatory for long options are also mandatory for short options.\n\ 16Arguments mandatory for long options are also mandatory for short options.\n\
16 -c, --config=FILENAME use configuration file FILENAME\n\ 17 -c, --config=FILENAME use configuration file FILENAME\n\
17 -d, --device=DEVICE use device DEVICE\n\ 18 -d, --device=DEVICE use device DEVICE\n\
18 -s, --silent do not show preview windows\n\ 19 -s, --silent do not show preview windows\n\
19 -h, --help print this help\n\ 20 -h, --help print this help\n\
20 -v, --verbose be verbose\n\ 21 -v, --verbose be verbose\n\
21Report bugs to gnunet-developers@gnu.org.\n\ 22Report bugs to gnunet-developers@gnu.org.\n\
22GNUnet home page: http://www.gnu.org/software/gnunet/\n\ 23GNUnet home page: http://www.gnu.org/software/gnunet/\n\
23General help using GNU software: http://www.gnu.org/gethelp/') 24General help using GNU software: http://www.gnu.org/gethelp/')
24 25
25 26
26if __name__ == '__main__': 27if __name__ == '__main__':
27 configuration = '' 28 configuration = ''
28 device = '/dev/video0' 29 device = '/dev/video0'
29 url = '' 30 url = ''
30 verbose = False 31 verbose = False
31 silent = False 32 silent = False
32 # Parse arguments 33 # Parse arguments
33 try: 34 try:
34 opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config","help", "device","silent","verbose"]) 35 opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config", "help", "device", "silent", "verbose"])
35 except getopt.GetoptError as e: 36 except getopt.GetoptError as e:
36 help () 37 help()
37 print(str (e)) 38 print(str(e))
38 exit (1) 39 exit(1)
39 for o,a in opts: 40 for o, a in opts:
40 if o in ("-h", "--help"): 41 if o in ("-h", "--help"):
41 help () 42 help()
42 sys.exit (0) 43 sys.exit(0)
43 elif o in ("-c", "--config"): 44 elif o in ("-c", "--config"):
44 configuration = a 45 configuration = a
45 elif o in ("-d", "--device"): 46 elif o in ("-d", "--device"):
46 device = a 47 device = a
47 elif o in ("-s", "--silent"): 48 elif o in ("-s", "--silent"):
48 silent = True 49 silent = True
49 elif o in ("-v", "--verbose"): 50 elif o in ("-v", "--verbose"):
50 verbose = True 51 verbose = True
51 if (True == verbose): 52 if (True == verbose):
52 print('Initializing') 53 print('Initializing')
53 # create a Processor 54 # create a Processor
54 proc = zbar.Processor() 55 proc = zbar.Processor()
56
57 # configure the Processor
58 proc.parse_config('enable')
59
60 # initialize the Processor
61 try:
62 if (True == verbose):
63 print('Opening video device ' + device)
64 proc.init(device)
65 except Exception as e:
66 print('Failed to open device ' + device)
67 exit(1)
68
69 # enable the preview window
70 # if (True == silent):
71 # proc.visible = True
72 # else:
73 # proc.visible = False
74
75 proc.visible = True
76 # read at least one barcode (or until window closed)
77 try:
78 if (True == verbose):
79 print('Capturing')
80 proc.process_one()
81 except Exception as e:
82 # Window was closed without finding code
83 exit(1)
55 84
56 # configure the Processor 85 # hide the preview window
57 proc.parse_config('enable') 86 proc.visible = False
58 87
59 # initialize the Processor 88 # extract results
60 try: 89 for symbol in proc.results:
61 if (True == verbose): 90 # do something useful with results
62 print('Opening video device ' + device) 91 if (True == verbose):
63 proc.init(device) 92 print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data)
64 except Exception as e: 93 args = list()
65 print('Failed to open device ' + device) 94 args.append("gnunet-uri")
66 exit (1) 95 if (configuration != ''):
67 96 args.append(str("-c " + str(configuration)))
68 # enable the preview window 97 args.append(str(symbol.data))
69 #if (True == silent): 98 cmd = ''
70 # proc.visible = True 99 for a in args:
71 #else: 100 cmd += " " + str(a)
72 # proc.visible = False 101 if (verbose):
73 102 print('Running `' + cmd +'`')
74 proc.visible = True 103 res=subprocess.call(args)
75 # read at least one barcode (or until window closed) 104 if (0 != res):
76 try: 105 print('Failed to add URI ' + str(symbol.data))
77 if (True == verbose): 106 else:
78 print('Capturing') 107 print('Added URI ' + str(symbol.data))
79 proc.process_one() 108 exit(res)
80 except Exception as e: 109 exit(1)
81 # Window was closed without finding code
82 exit (1)
83
84 # hide the preview window
85 proc.visible = False
86
87 # extract results
88 for symbol in proc.results:
89 # do something useful with results
90 if (True == verbose):
91 print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data)
92 args = list()
93 args.append("gnunet-uri")
94 if (configuration != ''):
95 args.append (str("-c " + str(configuration)))
96 args.append (str(symbol.data))
97 cmd = ''
98 for a in args:
99 cmd += " " + str(a)
100 if (verbose):
101 print('Running `' + cmd +'`')
102 res=subprocess.call(args)
103 if (0 != res):
104 print('Failed to add URI ' + str(symbol.data))
105 else:
106 print('Added URI ' + str(symbol.data))
107 exit (res)
108 exit (1)
diff --git a/src/util/gnunet-resolver.c b/src/util/gnunet-resolver.c
index 4954e0398..e841afca9 100644
--- a/src/util/gnunet-resolver.c
+++ b/src/util/gnunet-resolver.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010 GNUnet e.V. 3 Copyright (C) 2010 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/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c
index 3b3b7d695..fb66a757d 100644
--- a/src/util/gnunet-scrypt.c
+++ b/src/util/gnunet-scrypt.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2014 GNUnet e.V. 3 Copyright (C) 2014 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 util/gnunet-scrypt.c 19 * @file util/gnunet-scrypt.c
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c
index ccb592349..5b890261b 100644
--- a/src/util/gnunet-service-resolver.c
+++ b/src/util/gnunet-service-resolver.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2007-2016 GNUnet e.V. 3 Copyright (C) 2007-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/**
@@ -29,553 +27,559 @@
29#include "gnunet_statistics_service.h" 27#include "gnunet_statistics_service.h"
30#include "resolver.h" 28#include "resolver.h"
31 29
30
31struct Record
32{
33 struct Record *next;
34
35 struct Record *prev;
36
37 struct GNUNET_DNSPARSER_Record *record;
38};
39
32/** 40/**
33 * A cached DNS lookup result (for reverse lookup). 41 * A cached DNS lookup result.
34 */ 42 */
35struct IPCache 43struct ResolveCache
36{ 44{
37 /** 45 /**
38 * This is a doubly linked list. 46 * This is a doubly linked list.
39 */ 47 */
40 struct IPCache *next; 48 struct ResolveCache *next;
41 49
42 /** 50 /**
43 * This is a doubly linked list. 51 * This is a doubly linked list.
44 */ 52 */
45 struct IPCache *prev; 53 struct ResolveCache *prev;
46 54
47 /** 55 /**
48 * Hostname in human-readable form. 56 * type of queried DNS record
49 */ 57 */
50 char *addr; 58 uint16_t record_type;
51 59
52 /** 60 /**
53 * Binary IP address, allocated at the end of this struct. 61 * a pointer to the request_id if a query for this hostname/record_type
62 * is currently pending, NULL otherwise.
54 */ 63 */
55 const void *ip; 64 int16_t *request_id;
56 65
57 /** 66 /**
58 * Last time this entry was updated. 67 * The client that queried the records contained in this cache entry.
59 */ 68 */
60 struct GNUNET_TIME_Absolute last_refresh; 69 struct GNUNET_SERVICE_Client *client;
61 70
62 /** 71 /**
63 * Last time this entry was requested. 72 * head of a double linked list containing the lookup results
64 */ 73 */
65 struct GNUNET_TIME_Absolute last_request; 74 struct Record *records_head;
66 75
67 /** 76 /**
68 * Number of bytes in ip. 77 * tail of a double linked list containing the lookup results
69 */ 78 */
70 size_t ip_len; 79 struct Record *records_tail;
71 80
72 /** 81 /**
73 * Address family of the IP. 82 * handle for cancelling a request
74 */ 83 */
75 int af; 84 struct GNUNET_DNSSTUB_RequestSocket *resolve_handle;
85
86 /**
87 * handle for the resolution timeout task
88 */
89 struct GNUNET_SCHEDULER_Task *timeout_task;
90
76}; 91};
77 92
78 93
79/** 94/**
80 * Start of the linked list of cached DNS lookup results. 95 * Start of the linked list of cached DNS lookup results.
81 */ 96 */
82static struct IPCache *cache_head; 97static struct ResolveCache *cache_head;
83 98
84/** 99/**
85 * Tail of the linked list of cached DNS lookup results. 100 * Tail of the linked list of cached DNS lookup results.
86 */ 101 */
87static struct IPCache *cache_tail; 102static struct ResolveCache *cache_tail;
88
89 103
90#if HAVE_GETNAMEINFO
91/** 104/**
92 * Resolve the given request using getnameinfo 105 * context of dnsstub library
93 *
94 * @param cache the request to resolve (and where to store the result)
95 */ 106 */
96static void 107static struct GNUNET_DNSSTUB_Context *dnsstub_ctx;
97getnameinfo_resolve (struct IPCache *cache) 108
109
110void free_cache_entry (struct ResolveCache *entry)
98{ 111{
99 char hostname[256]; 112 struct Record *pos;
100 const struct sockaddr *sa; 113 struct Record *next;
101 struct sockaddr_in v4; 114
102 struct sockaddr_in6 v6; 115 next = entry->records_head;
103 size_t salen; 116 while (NULL != (pos = next))
104 int ret;
105
106 switch (cache->af)
107 { 117 {
108 case AF_INET: 118 next = pos->next;
109 GNUNET_assert (cache->ip_len == sizeof (struct in_addr)); 119 GNUNET_CONTAINER_DLL_remove (entry->records_head,
110 sa = (const struct sockaddr*) &v4; 120 entry->records_tail,
111 memset (&v4, 0, sizeof (v4)); 121 pos);
112 v4.sin_addr = * (const struct in_addr*) cache->ip; 122 if (NULL != pos->record)
113 v4.sin_family = AF_INET; 123 {
114#if HAVE_SOCKADDR_IN_SIN_LEN 124 GNUNET_DNSPARSER_free_record (pos->record);
115 v4.sin_len = sizeof (v4); 125 GNUNET_free (pos->record);
116#endif 126 }
117 salen = sizeof (v4); 127 GNUNET_free (pos);
118 break;
119 case AF_INET6:
120 GNUNET_assert (cache->ip_len == sizeof (struct in6_addr));
121 sa = (const struct sockaddr*) &v6;
122 memset (&v6, 0, sizeof (v6));
123 v6.sin6_addr = * (const struct in6_addr*) cache->ip;
124 v6.sin6_family = AF_INET6;
125#if HAVE_SOCKADDR_IN_SIN_LEN
126 v6.sin6_len = sizeof (v6);
127#endif
128 salen = sizeof (v6);
129 break;
130 default:
131 GNUNET_assert (0);
132 } 128 }
133 129 if (NULL != entry->resolve_handle)
134 if (0 ==
135 (ret = getnameinfo (sa, salen,
136 hostname, sizeof (hostname),
137 NULL,
138 0, 0)))
139 { 130 {
140 cache->addr = GNUNET_strdup (hostname); 131 GNUNET_DNSSTUB_resolve_cancel (entry->resolve_handle);
132 entry->resolve_handle = NULL;
141 } 133 }
142 else 134 if (NULL != entry->timeout_task)
143 { 135 {
144 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 136 GNUNET_SCHEDULER_cancel (entry->timeout_task);
145 "getnameinfo failed: %s\n", 137 entry->timeout_task = NULL;
146 gai_strerror (ret));
147 } 138 }
139 GNUNET_free_non_null (entry->request_id);
140 GNUNET_free (entry);
148} 141}
149#endif
150 142
151 143
152#if HAVE_GETHOSTBYADDR 144static char*
145extract_dns_server (const char* line, size_t line_len)
146{
147 if (0 == strncmp (line, "nameserver ", 11))
148 return GNUNET_strndup (line + 11, line_len - 11);
149 return NULL;
150}
151
152
153/** 153/**
154 * Resolve the given request using gethostbyaddr 154 * reads the list of nameservers from /etc/resolve.conf
155 * 155 *
156 * @param cache the request to resolve (and where to store the result) 156 * @param server_addrs[out] a list of null-terminated server address strings
157 * @return the number of server addresses in @server_addrs, -1 on error
157 */ 158 */
158static void 159static ssize_t
159gethostbyaddr_resolve (struct IPCache *cache) 160lookup_dns_servers (char ***server_addrs)
160{ 161{
161 struct hostent *ent; 162 struct GNUNET_DISK_FileHandle *fh;
162 163 char buf[2048];
163 ent = gethostbyaddr (cache->ip, 164 ssize_t bytes_read;
164 cache->ip_len, 165 size_t read_offset = 0;
165 cache->af); 166 unsigned int num_dns_servers = 0;
166 if (NULL != ent) 167
168 fh = GNUNET_DISK_file_open ("/etc/resolv.conf",
169 GNUNET_DISK_OPEN_READ,
170 GNUNET_DISK_PERM_NONE);
171 if (NULL == fh)
167 { 172 {
168 cache->addr = GNUNET_strdup (ent->h_name); 173 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
174 "Could not open /etc/resolv.conf. "
175 "DNS resolution will not be possible.\n");
176 return -1;
169 } 177 }
170 else 178 bytes_read = GNUNET_DISK_file_read (fh,
179 buf,
180 sizeof (buf));
181 *server_addrs = NULL;
182 while (read_offset < bytes_read)
171 { 183 {
172 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 184 char *newline;
173 "gethostbyaddr failed: %s\n", 185 size_t line_len;
174 hstrerror (h_errno)); 186 char *dns_server;
187
188 newline = strchr (buf + read_offset, '\n');
189 if (NULL == newline)
190 {
191 break;
192 }
193 line_len = newline - buf - read_offset;
194 dns_server = extract_dns_server (buf + read_offset, line_len);
195 if (NULL != dns_server)
196 {
197 GNUNET_array_append (*server_addrs,
198 num_dns_servers,
199 dns_server);
200 }
201 read_offset += line_len + 1;
175 } 202 }
203 GNUNET_DISK_file_close (fh);
204 return num_dns_servers;
176} 205}
177#endif
178 206
179 207
180/** 208static char *
181 * Resolve the given request using the available methods. 209make_reverse_hostname (const void *ip, int af)
182 *
183 * @param cache the request to resolve (and where to store the result)
184 */
185static void
186cache_resolve (struct IPCache *cache)
187{ 210{
188#if HAVE_GETNAMEINFO 211 char *buf = GNUNET_new_array (80, char);
189 if (NULL == cache->addr) 212 int pos = 0;
190 getnameinfo_resolve (cache); 213 if (AF_INET == af)
191#endif 214 {
192#if HAVE_GETHOSTBYADDR 215 struct in_addr *addr = (struct in_addr *)ip;
193 if (NULL == cache->addr) 216 uint32_t ip_int = addr->s_addr;
194 gethostbyaddr_resolve (cache); 217 for (int i = 3; i >= 0; i--)
195#endif 218 {
219 int n = GNUNET_snprintf (buf + pos,
220 80 - pos,
221 "%u.",
222 ((uint8_t *)&ip_int)[i]);
223 if (n < 0)
224 {
225 GNUNET_free (buf);
226 return NULL;
227 }
228 pos += n;
229 }
230 pos += GNUNET_snprintf (buf + pos, 80 - pos, "in-addr.arpa");
231 }
232 else if (AF_INET6 == af)
233 {
234 struct in6_addr *addr = (struct in6_addr *)ip;
235 for (int i = 15; i >= 0; i--)
236 {
237 int n = GNUNET_snprintf (buf + pos, 80 - pos, "%x.", addr->s6_addr[i] & 0xf);
238 if (n < 0)
239 {
240 GNUNET_free (buf);
241 return NULL;
242 }
243 pos += n;
244 n = GNUNET_snprintf (buf + pos, 80 - pos, "%x.", addr->s6_addr[i] >> 4);
245 if (n < 0)
246 {
247 GNUNET_free (buf);
248 return NULL;
249 }
250 pos += n;
251 }
252 pos += GNUNET_snprintf (buf + pos, 80 - pos, "ip6.arpa");
253 }
254 buf[pos] = '\0';
255 return buf;
196} 256}
197 257
198 258
199/**
200 * Function called after the replies for the request have all
201 * been transmitted to the client, and we can now read the next
202 * request from the client.
203 *
204 * @param cls the `struct GNUNET_SERVICE_Client` to continue with
205 */
206static void 259static void
207notify_service_client_done (void *cls) 260send_reply (struct GNUNET_DNSPARSER_Record *record,
261 uint16_t request_id,
262 struct GNUNET_SERVICE_Client *client)
208{ 263{
209 struct GNUNET_SERVICE_Client *client = cls; 264 struct GNUNET_RESOLVER_ResponseMessage *msg;
265 struct GNUNET_MQ_Envelope *env;
266 void *payload;
267 size_t payload_len;
210 268
211 GNUNET_SERVICE_client_continue (client); 269 switch (record->type)
270 {
271 case GNUNET_DNSPARSER_TYPE_PTR:
272 {
273 char *hostname = record->data.hostname;
274 payload = hostname;
275 payload_len = strlen (hostname) + 1;
276 break;
277 }
278 case GNUNET_DNSPARSER_TYPE_A:
279 case GNUNET_DNSPARSER_TYPE_AAAA:
280 {
281 payload = record->data.raw.data;
282 payload_len = record->data.raw.data_len;
283 break;
284 }
285 default:
286 {
287 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
288 "Cannot handle DNS response type: unimplemented\n");
289 return;
290 }
291 }
292 env = GNUNET_MQ_msg_extra (msg,
293 payload_len,
294 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
295 msg->id = request_id;
296 GNUNET_memcpy (&msg[1],
297 payload,
298 payload_len);
299 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
300 env);
212} 301}
213 302
214 303
215/**
216 * Get an IP address as a string (works for both IPv4 and IPv6). Note
217 * that the resolution happens asynchronously and that the first call
218 * may not immediately result in the FQN (but instead in a
219 * human-readable IP address).
220 *
221 * @param client handle to the client making the request (for sending the reply)
222 * @param af AF_INET or AF_INET6
223 * @param ip `struct in_addr` or `struct in6_addr`
224 */
225static void 304static void
226get_ip_as_string (struct GNUNET_SERVICE_Client *client, 305send_end_msg (uint16_t request_id,
227 int af, 306 struct GNUNET_SERVICE_Client *client)
228 const void *ip)
229{ 307{
230 struct IPCache *pos; 308 struct GNUNET_RESOLVER_ResponseMessage *msg;
231 struct IPCache *next;
232 struct GNUNET_TIME_Absolute now;
233 struct GNUNET_MQ_Envelope *env; 309 struct GNUNET_MQ_Envelope *env;
234 struct GNUNET_MQ_Handle *mq;
235 struct GNUNET_MessageHeader *msg;
236 size_t ip_len;
237 struct in6_addr ix;
238 size_t alen;
239 310
240 switch (af) 311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
312 "Sending end message\n");
313 env = GNUNET_MQ_msg (msg,
314 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
315 msg->id = request_id;
316 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
317 env);
318}
319
320
321static void
322handle_resolve_result (void *cls,
323 const struct GNUNET_TUN_DnsHeader *dns,
324 size_t dns_len)
325{
326 struct ResolveCache *cache = cls;
327 struct GNUNET_DNSPARSER_Packet *parsed;
328 uint16_t request_id = *cache->request_id;
329 struct GNUNET_SERVICE_Client *client = cache->client;
330
331 parsed = GNUNET_DNSPARSER_parse ((const char *)dns,
332 dns_len);
333 if (NULL == parsed)
241 { 334 {
242 case AF_INET: 335 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
243 ip_len = sizeof (struct in_addr); 336 "Failed to parse DNS reply (request ID %u\n",
244 break; 337 request_id);
245 case AF_INET6: 338 return;
246 ip_len = sizeof (struct in6_addr);
247 break;
248 default:
249 GNUNET_assert (0);
250 } 339 }
251 now = GNUNET_TIME_absolute_get (); 340 if (request_id != ntohs (parsed->id))
252 next = cache_head;
253 while ( (NULL != (pos = next)) &&
254 ( (pos->af != af) ||
255 (pos->ip_len != ip_len) ||
256 (0 != memcmp (pos->ip, ip, ip_len))) )
257 { 341 {
258 next = pos->next; 342 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
259 if (GNUNET_TIME_absolute_get_duration (pos->last_request).rel_value_us < 343 "Request ID in DNS reply does not match\n");
260 60 * 60 * 1000 * 1000LL) 344 return;
261 {
262 GNUNET_CONTAINER_DLL_remove (cache_head,
263 cache_tail,
264 pos);
265 GNUNET_free_non_null (pos->addr);
266 GNUNET_free (pos);
267 continue;
268 }
269 } 345 }
270 if (NULL != pos) 346 else if (0 == parsed->num_answers)
271 { 347 {
272 if ( (1 == inet_pton (af, 348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
273 pos->ip, 349 "DNS reply (request ID %u) contains no answers\n",
274 &ix)) && 350 request_id);
275 (GNUNET_TIME_absolute_get_duration (pos->last_request).rel_value_us > 351 GNUNET_CONTAINER_DLL_remove (cache_head,
276 120 * 1000 * 1000LL) ) 352 cache_tail,
353 cache);
354 free_cache_entry (cache);
355 cache = NULL;
356 }
357 else
358 {
359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
360 "Got reply for request ID %u\n",
361 request_id);
362 for (unsigned int i = 0; i != parsed->num_answers; i++)
277 { 363 {
278 /* try again if still numeric AND 2 minutes have expired */ 364 struct Record *cache_entry = GNUNET_new (struct Record);
279 GNUNET_free_non_null (pos->addr); 365 struct GNUNET_DNSPARSER_Record *record = &parsed->answers[i];
280 pos->addr = NULL; 366 cache_entry->record = GNUNET_DNSPARSER_duplicate_record (record);
281 cache_resolve (pos); 367 GNUNET_CONTAINER_DLL_insert (cache->records_head,
282 pos->last_request = now; 368 cache->records_tail,
369 cache_entry);
370 send_reply (cache_entry->record,
371 request_id,
372 cache->client);
283 } 373 }
374 GNUNET_free_non_null (cache->request_id);
375 cache->request_id = NULL;
284 } 376 }
285 else 377 send_end_msg (request_id,
378 client);
379 if (NULL != cache)
380 cache->client = NULL;
381 if (NULL != cache)
286 { 382 {
287 pos = GNUNET_malloc (sizeof (struct IPCache) + ip_len); 383 if (NULL != cache->timeout_task)
288 pos->ip = &pos[1]; 384 {
289 GNUNET_memcpy (&pos[1], 385 GNUNET_SCHEDULER_cancel (cache->timeout_task);
290 ip, 386 cache->timeout_task = NULL;
291 ip_len); 387 }
292 pos->last_request = now; 388 if (NULL != cache->resolve_handle)
293 pos->last_refresh = now; 389 {
294 pos->ip_len = ip_len; 390 GNUNET_DNSSTUB_resolve_cancel (cache->resolve_handle);
295 pos->af = af; 391 cache->resolve_handle = NULL;
296 GNUNET_CONTAINER_DLL_insert (cache_head, 392 }
297 cache_tail,
298 pos);
299 cache_resolve (pos);
300 } 393 }
301 if (NULL != pos->addr) 394 GNUNET_DNSPARSER_free_packet (parsed);
302 alen = strlen (pos->addr) + 1;
303 else
304 alen = 0;
305 mq = GNUNET_SERVICE_client_get_mq (client);
306 env = GNUNET_MQ_msg_extra (msg,
307 alen,
308 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
309 GNUNET_memcpy (&msg[1],
310 pos->addr,
311 alen);
312 GNUNET_MQ_send (mq,
313 env);
314 env = GNUNET_MQ_msg (msg,
315 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
316 GNUNET_MQ_notify_sent (env,
317 &notify_service_client_done,
318 client);
319 GNUNET_MQ_send (mq,
320 env);
321} 395}
322 396
323 397
324#if HAVE_GETADDRINFO 398static void
325static int 399handle_resolve_timeout (void *cls)
326getaddrinfo_resolve (struct GNUNET_MQ_Handle *mq,
327 const char *hostname,
328 int af)
329{ 400{
330 int s; 401 struct ResolveCache *cache = cls;
331 struct addrinfo hints;
332 struct addrinfo *result;
333 struct addrinfo *pos;
334 struct GNUNET_MessageHeader *msg;
335 struct GNUNET_MQ_Envelope *env;
336 402
337#ifdef WINDOWS 403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
338 /* Due to a bug, getaddrinfo will not return a mix of different families */ 404 "timeout!\n");
339 if (AF_UNSPEC == af) 405 if (NULL != cache->resolve_handle)
340 { 406 {
341 int ret1; 407 GNUNET_DNSSTUB_resolve_cancel (cache->resolve_handle);
342 int ret2; 408 cache->resolve_handle = NULL;
343 ret1 = getaddrinfo_resolve (mq,
344 hostname,
345 AF_INET);
346 ret2 = getaddrinfo_resolve (mq,
347 hostname,
348 AF_INET6);
349 if ( (ret1 == GNUNET_OK) ||
350 (ret2 == GNUNET_OK) )
351 return GNUNET_OK;
352 if ( (ret1 == GNUNET_SYSERR) ||
353 (ret2 == GNUNET_SYSERR) )
354 return GNUNET_SYSERR;
355 return GNUNET_NO;
356 } 409 }
357#endif 410 GNUNET_CONTAINER_DLL_remove (cache_head,
411 cache_tail,
412 cache);
413 free_cache_entry (cache);
414}
415
358 416
359 memset (&hints, 417static int
418resolve_and_cache (const char* hostname,
419 uint16_t record_type,
420 uint16_t request_id,
421 struct GNUNET_SERVICE_Client *client)
422{
423 char *packet_buf;
424 size_t packet_size;
425 struct GNUNET_DNSPARSER_Query query;
426 struct GNUNET_DNSPARSER_Packet packet;
427 struct ResolveCache *cache;
428 struct GNUNET_TIME_Relative timeout =
429 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5);
430
431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
432 "resolve_and_cache\n");
433 query.name = (char *)hostname;
434 query.type = record_type;
435 query.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
436 memset (&packet,
360 0, 437 0,
361 sizeof (struct addrinfo)); 438 sizeof (packet));
362 hints.ai_family = af; 439 packet.num_queries = 1;
363 hints.ai_socktype = SOCK_STREAM; /* go for TCP */ 440 packet.queries = &query;
364 441 packet.id = htons (request_id);
365 if (0 != (s = getaddrinfo (hostname, 442 packet.flags.recursion_desired = 1;
366 NULL, 443 if (GNUNET_OK !=
367 &hints, 444 GNUNET_DNSPARSER_pack (&packet,
368 &result))) 445 UINT16_MAX,
446 &packet_buf,
447 &packet_size))
369 { 448 {
370 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 449 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
371 _("Could not resolve `%s' (%s): %s\n"), 450 "Failed to pack query for hostname `%s'\n",
372 hostname, 451 hostname);
373 (af ==
374 AF_INET) ? "IPv4" : ((af == AF_INET6) ? "IPv6" : "any"),
375 gai_strerror (s));
376 if ( (s == EAI_BADFLAGS) ||
377#ifndef WINDOWS
378 (s == EAI_SYSTEM) ||
379#endif
380 (s == EAI_MEMORY) )
381 return GNUNET_NO; /* other function may still succeed */
382 return GNUNET_SYSERR;
383 }
384 if (NULL == result)
385 return GNUNET_SYSERR; 452 return GNUNET_SYSERR;
386 for (pos = result; pos != NULL; pos = pos->ai_next) 453
387 {
388 switch (pos->ai_family)
389 {
390 case AF_INET:
391 env = GNUNET_MQ_msg_extra (msg,
392 sizeof (struct in_addr),
393 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
394 GNUNET_memcpy (&msg[1],
395 &((struct sockaddr_in*) pos->ai_addr)->sin_addr,
396 sizeof (struct in_addr));
397 GNUNET_MQ_send (mq,
398 env);
399 break;
400 case AF_INET6:
401 env = GNUNET_MQ_msg_extra (msg,
402 sizeof (struct in6_addr),
403 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
404 GNUNET_memcpy (&msg[1],
405 &((struct sockaddr_in6*) pos->ai_addr)->sin6_addr,
406 sizeof (struct in6_addr));
407 GNUNET_MQ_send (mq,
408 env);
409 break;
410 default:
411 /* unsupported, skip */
412 break;
413 }
414 } 454 }
415 freeaddrinfo (result); 455 cache = GNUNET_malloc (sizeof (struct ResolveCache));
456 cache->record_type = record_type;
457 cache->request_id = GNUNET_memdup (&request_id, sizeof (request_id));
458 cache->client = client;
459 cache->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
460 &handle_resolve_timeout,
461 cache);
462 cache->resolve_handle =
463 GNUNET_DNSSTUB_resolve (dnsstub_ctx,
464 packet_buf,
465 packet_size,
466 &handle_resolve_result,
467 cache);
468 GNUNET_CONTAINER_DLL_insert (cache_head,
469 cache_tail,
470 cache);
471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
472 "resolve %s, request_id = %u\n",
473 hostname,
474 request_id);
475 GNUNET_free (packet_buf);
416 return GNUNET_OK; 476 return GNUNET_OK;
417} 477}
418 478
419 479
420#elif HAVE_GETHOSTBYNAME2 480static const char *
481get_hostname (struct ResolveCache *cache_entry)
482{
483 if (NULL != cache_entry->records_head)
484 {
485 GNUNET_assert (NULL != cache_entry->records_head);
486 GNUNET_assert (NULL != cache_entry->records_head->record);
487 GNUNET_assert (NULL != cache_entry->records_head->record->name);
488 return cache_entry->records_head->record->name;
489 }
490 return NULL;
491}
421 492
422 493
423static int 494static const uint16_t *
424gethostbyname2_resolve (struct GNUNET_MQ_Handle *mq, 495get_record_type (struct ResolveCache *cache_entry)
425 const char *hostname,
426 int af)
427{ 496{
428 struct hostent *hp; 497 if (NULL != cache_entry->records_head)
429 int ret1; 498 return &cache_entry->record_type;
430 int ret2; 499 return NULL;
431 struct GNUNET_MQ_Envelope *env; 500}
432 struct GNUNET_MessageHeader *msg;
433 501
434#ifdef WINDOWS
435 /* gethostbyname2() in plibc is a compat dummy that calls gethostbyname(). */
436 return GNUNET_NO;
437#endif
438 502
439 if (af == AF_UNSPEC) 503static const struct GNUNET_TIME_Absolute *
440 { 504get_expiration_time (struct ResolveCache *cache_entry)
441 ret1 = gethostbyname2_resolve (mq, 505{
442 hostname, 506 if (NULL != cache_entry->records_head)
443 AF_INET); 507 return &cache_entry->records_head->record->expiration_time;
444 ret2 = gethostbyname2_resolve (mq, 508 return NULL;
445 hostname,
446 AF_INET6);
447 if ( (ret1 == GNUNET_OK) ||
448 (ret2 == GNUNET_OK) )
449 return GNUNET_OK;
450 if ( (ret1 == GNUNET_SYSERR) ||
451 (ret2 == GNUNET_SYSERR) )
452 return GNUNET_SYSERR;
453 return GNUNET_NO;
454 }
455 hp = gethostbyname2 (hostname,
456 af);
457 if (hp == NULL)
458 {
459 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
460 _("Could not find IP of host `%s': %s\n"),
461 hostname,
462 hstrerror (h_errno));
463 return GNUNET_SYSERR;
464 }
465 GNUNET_assert (hp->h_addrtype == af);
466 switch (af)
467 {
468 case AF_INET:
469 GNUNET_assert (hp->h_length == sizeof (struct in_addr));
470 env = GNUNET_MQ_msg_extra (msg,
471 hp->h_length,
472 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
473 GNUNET_memcpy (&msg[1],
474 hp->h_addr_list[0],
475 hp->h_length);
476 GNUNET_MQ_send (mq,
477 env);
478 break;
479 case AF_INET6:
480 GNUNET_assert (hp->h_length == sizeof (struct in6_addr));
481 env = GNUNET_MQ_msg_extra (msg,
482 hp->h_length,
483 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
484 GNUNET_memcpy (&msg[1],
485 hp->h_addr_list[0],
486 hp->h_length);
487 GNUNET_MQ_send (mq,
488 env);
489 break;
490 default:
491 GNUNET_break (0);
492 return GNUNET_SYSERR;
493 }
494 return GNUNET_OK;
495} 509}
496 510
497#elif HAVE_GETHOSTBYNAME
498
499 511
500static int 512static int
501gethostbyname_resolve (struct GNUNET_MQ_Handle *mq, 513remove_if_expired (struct ResolveCache *cache_entry)
502 const char *hostname)
503{ 514{
504 struct hostent *hp; 515 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
505 struct GNUNET_MessageHeader *msg;
506 struct GNUNET_MQ_Envelope *env;
507 516
508 hp = GETHOSTBYNAME (hostname); 517 if ( (NULL != cache_entry->records_head) &&
509 if (NULL == hp) 518 (now.abs_value_us > get_expiration_time (cache_entry)->abs_value_us) )
510 { 519 {
511 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 520 GNUNET_CONTAINER_DLL_remove (cache_head,
512 _("Could not find IP of host `%s': %s\n"), 521 cache_tail,
513 hostname, 522 cache_entry);
514 hstrerror (h_errno)); 523 free_cache_entry (cache_entry);
515 return GNUNET_SYSERR; 524 return GNUNET_YES;
516 }
517 if (hp->h_addrtype != AF_INET)
518 {
519 GNUNET_break (0);
520 return GNUNET_SYSERR;
521 } 525 }
522 GNUNET_assert (hp->h_length == sizeof (struct in_addr)); 526 return GNUNET_NO;
523 env = GNUNET_MQ_msg_extra (msg,
524 hp->h_length,
525 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
526 GNUNET_memcpy (&msg[1],
527 hp->h_addr_list[0],
528 hp->h_length);
529 GNUNET_MQ_send (mq,
530 env);
531 return GNUNET_OK;
532} 527}
533#endif
534 528
535 529
536/** 530/**
537 * Convert a string to an IP address. 531 * Get an IP address as a string (works for both IPv4 and IPv6). Note
532 * that the resolution happens asynchronously and that the first call
533 * may not immediately result in the FQN (but instead in a
534 * human-readable IP address).
538 * 535 *
539 * @param client where to send the IP address 536 * @param client handle to the client making the request (for sending the reply)
540 * @param hostname the hostname to resolve 537 * @param af AF_INET or AF_INET6
541 * @param af AF_INET or AF_INET6; use AF_UNSPEC for "any" 538 * @param ip `struct in_addr` or `struct in6_addr`
542 */ 539 */
543static void 540static int
544get_ip_from_hostname (struct GNUNET_SERVICE_Client *client, 541try_cache (const char *hostname,
545 const char *hostname, 542 uint16_t record_type,
546 int af) 543 uint16_t request_id,
544 struct GNUNET_SERVICE_Client *client)
547{ 545{
548 int ret; 546 struct ResolveCache *pos;
549 struct GNUNET_MQ_Handle *mq; 547 struct ResolveCache *next;
550 struct GNUNET_MQ_Envelope *env; 548
551 struct GNUNET_MessageHeader *msg; 549 next = cache_head;
552 550 while ( (NULL != (pos = next)) &&
553 mq = GNUNET_SERVICE_client_get_mq (client); 551 ( (NULL == pos->records_head) ||
554 ret = GNUNET_NO; 552 (0 != strcmp (get_hostname (pos), hostname)) ||
555#if HAVE_GETADDRINFO 553 (*get_record_type (pos) != record_type) ) )
556 if (ret == GNUNET_NO) 554 {
557 ret = getaddrinfo_resolve (mq, 555 next = pos->next;
558 hostname, 556 remove_if_expired (pos);
559 af); 557 }
560#elif HAVE_GETHOSTBYNAME2 558 if (NULL != pos)
561 if (ret == GNUNET_NO) 559 {
562 ret = gethostbyname2_resolve (mq, 560 if (GNUNET_NO == remove_if_expired (pos))
563 hostname, 561 {
564 af); 562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
565#elif HAVE_GETHOSTBYNAME 563 "found cache entry for '%s', record type '%u'\n",
566 if ( (ret == GNUNET_NO) && 564 hostname,
567 ( (af == AF_UNSPEC) || 565 record_type);
568 (af == PF_INET) ) ) 566 struct Record *cache_pos = pos->records_head;
569 gethostbyname_resolve (mq, 567 while (NULL != cache_pos)
570 hostname); 568 {
571#endif 569 send_reply (cache_pos->record,
572 env = GNUNET_MQ_msg (msg, 570 request_id,
573 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 571 client);
574 GNUNET_MQ_notify_sent (env, 572 cache_pos = cache_pos->next;
575 &notify_service_client_done, 573 }
576 client); 574 send_end_msg (request_id,
577 GNUNET_MQ_send (mq, 575 client);
578 env); 576 return GNUNET_YES;
577 }
578 }
579 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
580 "no cache entry for '%s'\n",
581 hostname);
582 return GNUNET_NO;
579} 583}
580 584
581 585
@@ -633,7 +637,24 @@ check_get (void *cls,
633 } 637 }
634 return GNUNET_OK; 638 return GNUNET_OK;
635} 639}
636 640
641
642static void
643process_get (const char *hostname,
644 uint16_t record_type,
645 uint16_t request_id,
646 struct GNUNET_SERVICE_Client *client)
647{
648 if (GNUNET_NO == try_cache (hostname, record_type, request_id, client))
649 {
650 int result = resolve_and_cache (hostname,
651 record_type,
652 request_id,
653 client);
654 GNUNET_assert (GNUNET_OK == result);
655 }
656}
657
637 658
638/** 659/**
639 * Handle GET-message. 660 * Handle GET-message.
@@ -646,43 +667,100 @@ handle_get (void *cls,
646 const struct GNUNET_RESOLVER_GetMessage *msg) 667 const struct GNUNET_RESOLVER_GetMessage *msg)
647{ 668{
648 struct GNUNET_SERVICE_Client *client = cls; 669 struct GNUNET_SERVICE_Client *client = cls;
649 const void *ip;
650 int direction; 670 int direction;
651 int af; 671 int af;
672 uint16_t request_id;
673 const char *hostname;
652 674
653 direction = ntohl (msg->direction); 675 direction = ntohl (msg->direction);
654 af = ntohl (msg->af); 676 af = ntohl (msg->af);
677 request_id = ntohs (msg->id);
655 if (GNUNET_NO == direction) 678 if (GNUNET_NO == direction)
656 { 679 {
657 /* IP from hostname */ 680 /* IP from hostname */
658 const char *hostname; 681 hostname = GNUNET_strdup ((const char *) &msg[1]);
659 682 switch (af)
660 hostname = (const char *) &msg[1]; 683 {
661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 684 case AF_UNSPEC:
662 "Resolver asked to look up `%s'.\n", 685 {
663 hostname); 686 process_get (hostname, GNUNET_DNSPARSER_TYPE_ALL, request_id, client);
664 get_ip_from_hostname (client, 687 break;
665 hostname, 688 }
666 af); 689 case AF_INET:
667 return; 690 {
691 process_get (hostname, GNUNET_DNSPARSER_TYPE_A, request_id, client);
692 break;
693 }
694 case AF_INET6:
695 {
696 process_get (hostname, GNUNET_DNSPARSER_TYPE_AAAA, request_id, client);
697 break;
698 }
699 default:
700 {
701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
702 "got invalid af: %d\n",
703 af);
704 GNUNET_assert (0);
705 }
706 }
707 }
708 else
709 {
710 /* hostname from IP */
711 hostname = make_reverse_hostname (&msg[1], af);
712 process_get (hostname, GNUNET_DNSPARSER_TYPE_PTR, request_id, client);
668 } 713 }
669 ip = &msg[1]; 714 GNUNET_free_non_null ((char *)hostname);
670 715 GNUNET_SERVICE_client_continue (client);
671#if !defined(GNUNET_CULL_LOGGING) 716}
717
718
719static void
720shutdown_task (void *cls)
721{
722 (void) cls;
723 struct ResolveCache *pos;
724
725 while (NULL != (pos = cache_head))
672 { 726 {
673 char buf[INET6_ADDRSTRLEN]; 727 GNUNET_CONTAINER_DLL_remove (cache_head,
728 cache_tail,
729 pos);
730 free_cache_entry (pos);
731 }
732 GNUNET_DNSSTUB_stop (dnsstub_ctx);
733}
734
674 735
736static void
737init_cb (void *cls,
738 const struct GNUNET_CONFIGURATION_Handle *cfg,
739 struct GNUNET_SERVICE_Handle *sh)
740{
741 (void) cfg;
742 (void) sh;
743
744 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
745 cls);
746 dnsstub_ctx = GNUNET_DNSSTUB_start (128);
747 char **dns_servers;
748 ssize_t num_dns_servers = lookup_dns_servers (&dns_servers);
749 if (0 == num_dns_servers)
750 {
751 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
752 "no DNS server available. DNS resolution will not be possible.\n");
753 }
754 for (int i = 0; i != num_dns_servers; i++)
755 {
756 int result = GNUNET_DNSSTUB_add_dns_ip (dnsstub_ctx, dns_servers[i]);
675 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
676 "Resolver asked to look up IP address `%s'.\n", 758 "Adding DNS server '%s': %s\n",
677 inet_ntop (af, 759 dns_servers[i],
678 ip, 760 GNUNET_OK == result ? "success" : "failure");
679 buf, 761 GNUNET_free (dns_servers[i]);
680 sizeof (buf)));
681 } 762 }
682#endif 763 GNUNET_free_non_null (dns_servers);
683 get_ip_as_string (client,
684 af,
685 ip);
686} 764}
687 765
688 766
@@ -719,7 +797,16 @@ disconnect_cb (void *cls,
719 void *internal_cls) 797 void *internal_cls)
720{ 798{
721 (void) cls; 799 (void) cls;
722 800 struct ResolveCache *pos = cache_head;
801
802 while (NULL != pos)
803 {
804 if (pos->client == c)
805 {
806 pos->client = NULL;
807 }
808 pos = pos->next;
809 }
723 GNUNET_assert (c == internal_cls); 810 GNUNET_assert (c == internal_cls);
724} 811}
725 812
@@ -730,7 +817,7 @@ disconnect_cb (void *cls,
730GNUNET_SERVICE_MAIN 817GNUNET_SERVICE_MAIN
731("resolver", 818("resolver",
732 GNUNET_SERVICE_OPTION_NONE, 819 GNUNET_SERVICE_OPTION_NONE,
733 NULL, 820 &init_cb,
734 &connect_cb, 821 &connect_cb,
735 &disconnect_cb, 822 &disconnect_cb,
736 NULL, 823 NULL,
@@ -757,23 +844,4 @@ GNUNET_RESOLVER_memory_init ()
757#endif 844#endif
758 845
759 846
760/**
761 * Free globals on exit.
762 */
763void __attribute__ ((destructor))
764GNUNET_RESOLVER_memory_done ()
765{
766 struct IPCache *pos;
767
768 while (NULL != (pos = cache_head))
769 {
770 GNUNET_CONTAINER_DLL_remove (cache_head,
771 cache_tail,
772 pos);
773 GNUNET_free_non_null (pos->addr);
774 GNUNET_free (pos);
775 }
776}
777
778
779/* end of gnunet-service-resolver.c */ 847/* end of gnunet-service-resolver.c */
diff --git a/src/util/gnunet-timeout-w32.c b/src/util/gnunet-timeout-w32.c
new file mode 100644
index 000000000..78b268fe2
--- /dev/null
+++ b/src/util/gnunet-timeout-w32.c
@@ -0,0 +1,191 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010 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, or
8 (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/**
20 * @file src/util/gnunet-timeout-w32.c
21 * @brief small tool starting a child process, waiting that it terminates or killing it after a given timeout period
22 * @author LRN
23 */
24
25#include <windows.h>
26#include <sys/types.h>
27#include <stdio.h>
28
29int
30main (int argc, char *argv[])
31{
32 int i;
33 DWORD wait_result;
34 wchar_t *commandline;
35 wchar_t **wargv;
36 wchar_t *arg;
37 unsigned int cmdlen;
38 STARTUPINFOW start;
39 PROCESS_INFORMATION proc;
40
41 wchar_t wpath[MAX_PATH + 1];
42
43 wchar_t *pathbuf;
44 DWORD pathbuf_len, alloc_len;
45 wchar_t *ptr;
46 wchar_t *non_const_filename;
47 wchar_t *wcmd;
48 int wargc;
49 int timeout = 0;
50 ssize_t wrote;
51
52 HANDLE job;
53
54 if (argc < 3)
55 {
56 printf
57 ("arg 1: timeout in sec., arg 2: executable, arg<n> arguments\n");
58 exit (1);
59 }
60
61 timeout = atoi (argv[1]);
62
63 if (timeout == 0)
64 timeout = 600;
65
66 commandline = GetCommandLineW ();
67 if (commandline == NULL)
68 {
69 printf ("Failed to get commandline: %lu\n", GetLastError ());
70 exit (2);
71 }
72
73 wargv = CommandLineToArgvW (commandline, &wargc);
74 if (wargv == NULL || wargc <= 1)
75 {
76 printf ("Failed to get parse commandline: %lu\n", GetLastError ());
77 exit (3);
78 }
79
80 job = CreateJobObject (NULL, NULL);
81 if (job == NULL)
82 {
83 printf ("Failed to create a job: %lu\n", GetLastError ());
84 exit (4);
85 }
86
87 pathbuf_len = GetEnvironmentVariableW (L"PATH", (wchar_t *) &pathbuf, 0);
88
89 alloc_len = pathbuf_len + 1;
90
91 pathbuf = malloc (alloc_len * sizeof (wchar_t));
92
93 ptr = pathbuf;
94
95 alloc_len = GetEnvironmentVariableW (L"PATH", ptr, pathbuf_len);
96
97 cmdlen = wcslen (wargv[2]);
98 if (cmdlen < 5 || wcscmp (&wargv[2][cmdlen - 4], L".exe") != 0)
99 {
100 non_const_filename = malloc (sizeof (wchar_t) * (cmdlen + 5));
101 swprintf (non_const_filename, cmdlen + 5, L"%S.exe", wargv[2]);
102 }
103 else
104 {
105 non_const_filename = wcsdup (wargv[2]);
106 }
107
108 /* Check that this is the full path. If it isn't, search. */
109 if (non_const_filename[1] == L':')
110 swprintf (wpath, sizeof (wpath) / sizeof (wchar_t), L"%S", non_const_filename);
111 else if (!SearchPathW
112 (pathbuf, non_const_filename, NULL, sizeof (wpath) / sizeof (wchar_t),
113 wpath, NULL))
114 {
115 printf ("Failed to get find executable: %lu\n", GetLastError ());
116 exit (5);
117 }
118 free (pathbuf);
119 free (non_const_filename);
120
121 cmdlen = wcslen (wpath) + 4;
122 i = 3;
123 while (NULL != (arg = wargv[i++]))
124 cmdlen += wcslen (arg) + 4;
125
126 wcmd = malloc (sizeof (wchar_t) * (cmdlen + 1));
127 wrote = 0;
128 i = 2;
129 while (NULL != (arg = wargv[i++]))
130 {
131 /* This is to escape trailing slash */
132 wchar_t arg_lastchar = arg[wcslen (arg) - 1];
133 if (wrote == 0)
134 {
135 wrote += swprintf (&wcmd[wrote], cmdlen + 1 - wrote, L"\"%S%S\" ", wpath,
136 arg_lastchar == L'\\' ? L"\\" : L"");
137 }
138 else
139 {
140 if (wcschr (arg, L' ') != NULL)
141 wrote += swprintf (&wcmd[wrote], cmdlen + 1 - wrote, L"\"%S%S\"%S", arg,
142 arg_lastchar == L'\\' ? L"\\" : L"", i == wargc ? L"" : L" ");
143 else
144 wrote += swprintf (&wcmd[wrote], cmdlen + 1 - wrote, L"%S%S%S", arg,
145 arg_lastchar == L'\\' ? L"\\" : L"", i == wargc ? L"" : L" ");
146 }
147 }
148
149 LocalFree (wargv);
150
151 memset (&start, 0, sizeof (start));
152 start.cb = sizeof (start);
153
154 if (!CreateProcessW (wpath, wcmd, NULL, NULL, TRUE, CREATE_SUSPENDED,
155 NULL, NULL, &start, &proc))
156 {
157 wprintf (L"Failed to get spawn process `%S' with arguments `%S': %lu\n", wpath, wcmd, GetLastError ());
158 exit (6);
159 }
160
161 AssignProcessToJobObject (job, proc.hProcess);
162
163 ResumeThread (proc.hThread);
164 CloseHandle (proc.hThread);
165
166 free (wcmd);
167
168 wait_result = WaitForSingleObject (proc.hProcess, timeout * 1000);
169 if (wait_result == WAIT_OBJECT_0)
170 {
171 DWORD status;
172 wait_result = GetExitCodeProcess (proc.hProcess, &status);
173 CloseHandle (proc.hProcess);
174 if (wait_result != 0)
175 {
176 printf ("Test process exited with result %lu\n", status);
177 TerminateJobObject (job, status);
178 exit (status);
179 }
180 printf ("Test process exited (failed to obtain exit status)\n");
181 TerminateJobObject (job, 0);
182 exit (0);
183 }
184 printf ("Child processes were killed after timeout of %u seconds\n",
185 timeout);
186 TerminateJobObject (job, 1);
187 CloseHandle (proc.hProcess);
188 exit (1);
189}
190
191/* end of timeout_watchdog_w32.c */
diff --git a/src/util/gnunet-timeout.c b/src/util/gnunet-timeout.c
new file mode 100644
index 000000000..8dfb6ad17
--- /dev/null
+++ b/src/util/gnunet-timeout.c
@@ -0,0 +1,128 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010 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, or
8 (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/**
20 * @file src/util/gnunet-timeout.c
21 * @brief small tool starting a child process, waiting that it terminates or killing it after a given timeout period
22 * @author Matthias Wachs
23 */
24
25#include <sys/types.h>
26#include <sys/wait.h>
27#include <signal.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include <unistd.h>
31
32static pid_t child;
33
34
35static void
36sigchld_handler (int val)
37{
38 int status = 0;
39 int ret = 0;
40
41 (void) val;
42 waitpid (child,
43 &status,
44 0);
45 if (WIFEXITED (status) != 0)
46 {
47 ret = WEXITSTATUS (status);
48 fprintf (stderr,
49 "Process exited with result %u\n",
50 ret);
51 exit (ret); /* return same status code */
52 }
53 if (WIFSIGNALED (status) != 0)
54 {
55 ret = WTERMSIG (status);
56 fprintf (stderr,
57 "Process received signal %u\n",
58 ret);
59 kill (getpid (),
60 ret); /* kill self with the same signal */
61 }
62 exit (-1);
63}
64
65
66static void
67sigint_handler (int val)
68{
69 kill (0,
70 val);
71 exit (val);
72}
73
74
75int
76main (int argc,
77 char *argv[])
78{
79 int timeout = 0;
80 pid_t gpid = 0;
81
82 if (argc < 3)
83 {
84 fprintf (stderr,
85 "arg 1: timeout in sec., arg 2: executable, arg<n> arguments\n");
86 exit (-1);
87 }
88
89 timeout = atoi (argv[1]);
90
91 if (timeout == 0)
92 timeout = 600;
93
94 /* with getpgid() it does not compile, but getpgrp is the BSD version and working */
95 gpid = getpgrp ();
96
97 signal (SIGCHLD, sigchld_handler);
98 signal (SIGABRT, sigint_handler);
99 signal (SIGFPE, sigint_handler);
100 signal (SIGILL, sigint_handler);
101 signal (SIGINT, sigint_handler);
102 signal (SIGSEGV, sigint_handler);
103 signal (SIGTERM, sigint_handler);
104
105 child = fork ();
106 if (child == 0)
107 {
108 /* int setpgrp(pid_t pid, pid_t pgid); is not working on this machine */
109 //setpgrp (0, pid_t gpid);
110 if (-1 != gpid)
111 setpgid (0, gpid);
112 execvp (argv[2],
113 &argv[2]);
114 exit (-1);
115 }
116 if (child > 0)
117 {
118 sleep (timeout);
119 printf ("Child processes were killed after timeout of %u seconds\n",
120 timeout);
121 kill (0,
122 SIGTERM);
123 exit (3);
124 }
125 exit (-1);
126}
127
128/* end of timeout_watchdog.c */
diff --git a/src/util/gnunet-uri.c b/src/util/gnunet-uri.c
index f69508f67..33cd3543d 100644
--- a/src/util/gnunet-uri.c
+++ b/src/util/gnunet-uri.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/** 19/**
diff --git a/src/util/helper.c b/src/util/helper.c
index a84b06e66..5cdfb904a 100644
--- a/src/util/helper.c
+++ b/src/util/helper.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011, 2012 Christian Grothoff 3 Copyright (C) 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/util/load.c b/src/util/load.c
index d1de6aa36..41ee7a91a 100644
--- a/src/util/load.c
+++ b/src/util/load.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/util/mq.c b/src/util/mq.c
index dbcce704d..eaac85575 100644
--- a/src/util/mq.c
+++ b/src/util/mq.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/** 19/**
@@ -1071,6 +1069,32 @@ GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq,
1071 1069
1072 1070
1073/** 1071/**
1072 * Obtain message contained in envelope.
1073 *
1074 * @param env the envelope
1075 * @return message contained in the envelope
1076 */
1077const struct GNUNET_MessageHeader *
1078GNUNET_MQ_env_get_msg (const struct GNUNET_MQ_Envelope *env)
1079{
1080 return env->mh;
1081}
1082
1083
1084/**
1085 * Return next envelope in queue.
1086 *
1087 * @param env a queued envelope
1088 * @return next one, or NULL
1089 */
1090const struct GNUNET_MQ_Envelope *
1091GNUNET_MQ_env_next (const struct GNUNET_MQ_Envelope *env)
1092{
1093 return env->next;
1094}
1095
1096
1097/**
1074 * Register function to be called whenever @a mq is being 1098 * Register function to be called whenever @a mq is being
1075 * destroyed. 1099 * destroyed.
1076 * 1100 *
@@ -1190,6 +1214,43 @@ GNUNET_MQ_copy_handlers (const struct GNUNET_MQ_MessageHandler *handlers)
1190 1214
1191 1215
1192/** 1216/**
1217 * Copy an array of handlers, appending AGPL handler.
1218 *
1219 * Useful if the array has been delared in local memory and needs to be
1220 * persisted for future use.
1221 *
1222 * @param handlers Array of handlers to be copied. Can be NULL (nothing done).
1223 * @param agpl_handler function to call for AGPL handling
1224 * @param agpl_cls closure for @a agpl_handler
1225 * @return A newly allocated array of handlers.
1226 * Needs to be freed with #GNUNET_free.
1227 */
1228struct GNUNET_MQ_MessageHandler *
1229GNUNET_MQ_copy_handlers2 (const struct GNUNET_MQ_MessageHandler *handlers,
1230 GNUNET_MQ_MessageCallback agpl_handler,
1231 void *agpl_cls)
1232{
1233 struct GNUNET_MQ_MessageHandler *copy;
1234 unsigned int count;
1235
1236 if (NULL == handlers)
1237 return NULL;
1238 count = GNUNET_MQ_count_handlers (handlers);
1239 copy = GNUNET_new_array (count + 2,
1240 struct GNUNET_MQ_MessageHandler);
1241 GNUNET_memcpy (copy,
1242 handlers,
1243 count * sizeof (struct GNUNET_MQ_MessageHandler));
1244 copy[count].mv = NULL;
1245 copy[count].cb = agpl_handler;
1246 copy[count].cls = agpl_cls;
1247 copy[count].type = GNUNET_MESSAGE_TYPE_REQUEST_AGPL;
1248 copy[count].expected_size = sizeof (struct GNUNET_MessageHeader);
1249 return copy;
1250}
1251
1252
1253/**
1193 * Count the handlers in a handler array. 1254 * Count the handlers in a handler array.
1194 * 1255 *
1195 * @param handlers Array of handlers to be counted. 1256 * @param handlers Array of handlers to be counted.
diff --git a/src/util/mst.c b/src/util/mst.c
index 5e472965f..a5c6f3c3e 100644
--- a/src/util/mst.c
+++ b/src/util/mst.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010, 2016, 2017 GNUnet e.V. 3 Copyright (C) 2010, 2016, 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/** 19/**
diff --git a/src/util/nc.c b/src/util/nc.c
index d9ebde323..42a0114a7 100644
--- a/src/util/nc.c
+++ b/src/util/nc.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010, 2016 GNUnet e.V. 3 Copyright (C) 2010, 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/**
diff --git a/src/util/network.c b/src/util/network.c
index 0cb1529a6..fe9827083 100644
--- a/src/util/network.c
+++ b/src/util/network.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/** 19/**
diff --git a/src/util/op.c b/src/util/op.c
index 41be763e5..19f6ce4f0 100644
--- a/src/util/op.c
+++ b/src/util/op.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2016 GNUnet e.V. 3 Copyright (C) 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/**
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index 2e35de681..2977a833b 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2006-2018 GNUnet e.V. 3 Copyright (C) 2006-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/** 19/**
diff --git a/src/util/os_network.c b/src/util/os_network.c
index 5cb2b6864..3e9ea47b4 100644
--- a/src/util/os_network.c
+++ b/src/util/os_network.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2004, 2005, 2006, 2015 GNUnet e.V. 3 Copyright (C) 2004, 2005, 2006, 2015 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/util/os_priority.c b/src/util/os_priority.c
index 98998b520..a758f24f1 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2011 GNUnet e.V. 3 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2011 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/**
@@ -1590,7 +1588,7 @@ GNUNET_OS_start_process_s (int pipe_control,
1590 1588
1591 1589
1592/** 1590/**
1593 * Retrieve the status of a process, waiting on him if dead. 1591 * Retrieve the status of a process, waiting on it if dead.
1594 * Nonblocking version. 1592 * Nonblocking version.
1595 * 1593 *
1596 * @param proc process ID 1594 * @param proc process ID
@@ -1707,7 +1705,7 @@ process_status (struct GNUNET_OS_Process *proc,
1707 1705
1708 1706
1709/** 1707/**
1710 * Retrieve the status of a process, waiting on him if dead. 1708 * Retrieve the status of a process, waiting on it if dead.
1711 * Nonblocking version. 1709 * Nonblocking version.
1712 * 1710 *
1713 * @param proc process ID 1711 * @param proc process ID
@@ -1728,7 +1726,7 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
1728 1726
1729 1727
1730/** 1728/**
1731 * Retrieve the status of a process, waiting on him if dead. 1729 * Retrieve the status of a process, waiting on it if dead.
1732 * Blocking version. 1730 * Blocking version.
1733 * 1731 *
1734 * @param proc pointer to process structure 1732 * @param proc pointer to process structure
diff --git a/src/util/peer.c b/src/util/peer.c
index b1c65fbcf..f9e1b4cbe 100644
--- a/src/util/peer.c
+++ b/src/util/peer.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2006, 2008, 2009 GNUnet e.V. 3 Copyright (C) 2006, 2008, 2009 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/util/perf_crypto_asymmetric.c b/src/util/perf_crypto_asymmetric.c
index 418d6dab3..acfdba541 100644
--- a/src/util/perf_crypto_asymmetric.c
+++ b/src/util/perf_crypto_asymmetric.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2015 GNUnet e.V. 3 Copyright (C) 2015 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/util/perf_crypto_ecc_dlog.c b/src/util/perf_crypto_ecc_dlog.c
index 01369649f..4be928d42 100644
--- a/src/util/perf_crypto_ecc_dlog.c
+++ b/src/util/perf_crypto_ecc_dlog.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2015 GNUnet e.V. 3 Copyright (C) 2015 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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 17
20*/ 18*/
21/** 19/**
diff --git a/src/util/perf_crypto_hash.c b/src/util/perf_crypto_hash.c
index 8bea26e4b..f1c69e96a 100644
--- a/src/util/perf_crypto_hash.c
+++ b/src/util/perf_crypto_hash.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2002, 2003, 2004, 2006 GNUnet e.V. 3 Copyright (C) 2002, 2003, 2004, 2006 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/util/perf_crypto_paillier.c b/src/util/perf_crypto_paillier.c
index 0ebd431b9..b1430d713 100644
--- a/src/util/perf_crypto_paillier.c
+++ b/src/util/perf_crypto_paillier.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2014 GNUnet e.V. 3 Copyright (C) 2014 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/util/perf_crypto_rsa.c b/src/util/perf_crypto_rsa.c
index f64b8335d..4ad348d5b 100644
--- a/src/util/perf_crypto_rsa.c
+++ b/src/util/perf_crypto_rsa.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2014 GNUnet e.V. 3 Copyright (C) 2014 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/util/perf_crypto_symmetric.c b/src/util/perf_crypto_symmetric.c
index fa420e20d..2382010e1 100644
--- a/src/util/perf_crypto_symmetric.c
+++ b/src/util/perf_crypto_symmetric.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2002, 2003, 2004, 2006 GNUnet e.V. 3 Copyright (C) 2002, 2003, 2004, 2006 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/util/perf_malloc.c b/src/util/perf_malloc.c
index 09756c6e8..01694d766 100644
--- a/src/util/perf_malloc.c
+++ b/src/util/perf_malloc.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/** 19/**
diff --git a/src/util/plugin.c b/src/util/plugin.c
index fb296f80d..b88dc4012 100644
--- a/src/util/plugin.c
+++ b/src/util/plugin.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2002-2013 GNUnet e.V. 3 Copyright (C) 2002-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/util/program.c b/src/util/program.c
index a02bff77c..2a9b4fac9 100644
--- a/src/util/program.c
+++ b/src/util/program.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 PURPROSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPROSE. 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/util/regex.c b/src/util/regex.c
new file mode 100644
index 000000000..7565a9eac
--- /dev/null
+++ b/src/util/regex.c
@@ -0,0 +1,834 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012, 2013, 2015 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/tun/regex.c
20 * @brief functions to convert IP networks to regexes
21 * @author Maximilian Szengel
22 * @author Christian Grothoff
23 */
24#include "platform.h"
25#include "gnunet_util_lib.h"
26#include "gnunet_tun_lib.h"
27
28/**
29 * 'wildcard', matches all possible values (for HEX encoding).
30 */
31#define DOT "(0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F)"
32
33
34/**
35 * Create a regex in @a rxstr from the given @a ip and @a netmask.
36 *
37 * @param ip IPv4 representation.
38 * @param port destination port
39 * @param rxstr generated regex, must be at least #GNUNET_TUN_IPV4_REGEXLEN
40 * bytes long.
41 */
42void
43GNUNET_TUN_ipv4toregexsearch (const struct in_addr *ip,
44 uint16_t port,
45 char *rxstr)
46{
47 GNUNET_snprintf (rxstr,
48 GNUNET_TUN_IPV4_REGEXLEN,
49 "4-%04X-%08X",
50 (unsigned int) port,
51 ntohl (ip->s_addr));
52}
53
54
55/**
56 * Create a regex in @a rxstr from the given @a ipv6 and @a prefixlen.
57 *
58 * @param ipv6 IPv6 representation.
59 * @param port destination port
60 * @param rxstr generated regex, must be at least #GNUNET_TUN_IPV6_REGEXLEN
61 * bytes long.
62 */
63void
64GNUNET_TUN_ipv6toregexsearch (const struct in6_addr *ipv6,
65 uint16_t port,
66 char *rxstr)
67{
68 const uint32_t *addr;
69
70 addr = (const uint32_t *) ipv6;
71 GNUNET_snprintf (rxstr,
72 GNUNET_TUN_IPV6_REGEXLEN,
73 "6-%04X-%08X%08X%08X%08X",
74 (unsigned int) port,
75 ntohl (addr[0]),
76 ntohl (addr[1]),
77 ntohl (addr[2]),
78 ntohl (addr[3]));
79}
80
81
82/**
83 * Convert the given 4-bit (!) number to a regex.
84 *
85 * @param value the value, only the lowest 4 bits will be looked at
86 * @param mask which bits in value are wildcards (any value)?
87 */
88static char *
89nibble_to_regex (uint8_t value,
90 uint8_t mask)
91{
92 char *ret;
93
94 value &= mask;
95 switch (mask)
96 {
97 case 0:
98 return GNUNET_strdup (DOT);
99 case 8:
100 GNUNET_asprintf (&ret,
101 "(%X|%X|%X|%X|%X|%X|%X|%X)",
102 value,
103 value + 1,
104 value + 2,
105 value + 3,
106 value + 4,
107 value + 5,
108 value + 6,
109 value + 7);
110 return ret;
111 case 12:
112 GNUNET_asprintf (&ret,
113 "(%X|%X|%X|%X)",
114 value,
115 value + 1,
116 value + 2,
117 value + 3);
118 return ret;
119 case 14:
120 GNUNET_asprintf (&ret,
121 "(%X|%X)",
122 value,
123 value + 1);
124 return ret;
125 case 15:
126 GNUNET_asprintf (&ret,
127 "%X",
128 value);
129 return ret;
130 default:
131 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
132 _("Bad mask: %d\n"),
133 mask);
134 GNUNET_break (0);
135 return NULL;
136 }
137}
138
139
140/**
141 * Convert the given 16-bit number to a regex.
142 *
143 * @param value the value
144 * @param mask which bits in value are wildcards (any value)?
145 */
146static char *
147num_to_regex (uint16_t value,
148 uint16_t mask)
149{
150 const uint8_t *v = (const uint8_t *) &value;
151 const uint8_t *m = (const uint8_t *) &mask;
152 char *a;
153 char *b;
154 char *c;
155 char *d;
156 char *ret;
157
158 a = nibble_to_regex (v[0] >> 4, m[0] >> 4);
159 b = nibble_to_regex (v[0] & 15, m[0] & 15);
160 c = nibble_to_regex (v[1] >> 4, m[1] >> 4);
161 d = nibble_to_regex (v[1] & 15, m[1] & 15);
162 ret = NULL;
163 if ( (NULL != a) &&
164 (NULL != b) &&
165 (NULL != c) &&
166 (NULL != d) )
167 GNUNET_asprintf (&ret,
168 "%s%s%s%s",
169 a, b, c, d);
170 GNUNET_free_non_null (a);
171 GNUNET_free_non_null (b);
172 GNUNET_free_non_null (c);
173 GNUNET_free_non_null (d);
174 return ret;
175}
176
177
178/**
179 * Do we need to put parents around the given argument?
180 *
181 * @param arg part of a regular expression
182 * @return #GNUNET_YES if we should parens,
183 * #GNUNET_NO if not
184 */
185static int
186needs_parens (const char *arg)
187{
188 size_t off;
189 size_t len;
190 unsigned int op;
191
192 op = 0;
193 len = strlen (arg);
194 for (off=0;off<len;off++)
195 {
196 switch (arg[off])
197 {
198 case '(':
199 op++;
200 break;
201 case ')':
202 GNUNET_assert (op > 0);
203 op--;
204 break;
205 case '|':
206 if (0 == op)
207 return GNUNET_YES;
208 break;
209 default:
210 break;
211 }
212 }
213 return GNUNET_NO;
214}
215
216
217/**
218 * Compute port policy for the given range of
219 * port numbers.
220 *
221 * @param start starting offset
222 * @param end end offset
223 * @param step increment level (power of 16)
224 * @param pp port policy to convert
225 * @return corresponding regex
226 */
227static char *
228compute_policy (unsigned int start,
229 unsigned int end,
230 unsigned int step,
231 const struct GNUNET_STRINGS_PortPolicy *pp)
232{
233 unsigned int i;
234 char before[36]; /* 16 * 2 + 3 dots + 0-terminator */
235 char middlel[33]; /* 16 * 2 + 0-terminator */
236 char middleh[33]; /* 16 * 2 + 0-terminator */
237 char after[36]; /* 16 * 2 + 3 dots + 0-terminator */
238 char beforep[36+2]; /* 16 * 2 + 3 dots + 0-terminator + ()*/
239 char middlehp[33+2]; /* 16 * 2 + 0-terminator + () */
240 char middlelp[33+2]; /* 16 * 2 + 0-terminator + () */
241 char afterp[36+2]; /* 16 * 2 + 3 dots + 0-terminator + () */
242 char dots[5 * strlen (DOT)];
243 char buf[3];
244 char *middle;
245 char *ret;
246 unsigned int xstep;
247 char *recl;
248 char *rech;
249 char *reclp;
250 char *rechp;
251 unsigned int start_port;
252 unsigned int end_port;
253
254 GNUNET_assert (GNUNET_YES == pp->negate_portrange);
255 start_port = pp->start_port;
256 if (1 == start_port)
257 start_port = 0;
258 end_port = pp->end_port;
259 GNUNET_assert ((end - start) / step <= 0xF);
260 before[0] = '\0';
261 middlel[0] = '\0';
262 middleh[0] = '\0';
263 after[0] = '\0';
264 for (i=start;i<=end;i+=step)
265 {
266 GNUNET_snprintf (buf,
267 sizeof (buf),
268 "%X|",
269 (i - start) / step);
270 if (i / step < start_port / step)
271 strcat (before, buf);
272 else if (i / step > end_port / step)
273 strcat (after, buf);
274 else if (i / step == start_port / step)
275 strcat (middlel, buf);
276 else if (i / step == end_port / step)
277 strcat (middleh, buf);
278 }
279 if (strlen (before) > 0)
280 before[strlen (before)-1] = '\0';
281 if (strlen (middlel) > 0)
282 middlel[strlen (middlel)-1] = '\0';
283 if (strlen (middleh) > 0)
284 middleh[strlen (middleh)-1] = '\0';
285 if (strlen (after) > 0)
286 after[strlen (after)-1] = '\0';
287 if (needs_parens (before))
288 GNUNET_snprintf (beforep,
289 sizeof (beforep),
290 "(%s)",
291 before);
292 else
293 strcpy (beforep, before);
294 if (needs_parens (middlel))
295 GNUNET_snprintf (middlelp,
296 sizeof (middlelp),
297 "(%s)",
298 middlel);
299 else
300 strcpy (middlelp, middlel);
301 if (needs_parens (middleh))
302 GNUNET_snprintf (middlehp,
303 sizeof (middlehp),
304 "(%s)",
305 middleh);
306 else
307 strcpy (middlehp, middleh);
308 if (needs_parens (after))
309 GNUNET_snprintf (afterp,
310 sizeof (afterp),
311 "(%s)",
312 after);
313 else
314 strcpy (afterp, after);
315 dots[0] = '\0';
316 for (xstep=step/16;xstep>0;xstep/=16)
317 strcat (dots, DOT);
318 if (step >= 16)
319 {
320 if (strlen (middlel) > 0)
321 recl = compute_policy ((start_port / step) * step,
322 (start_port / step) * step + step - 1,
323 step / 16,
324 pp);
325 else
326 recl = GNUNET_strdup ("");
327 if (strlen (middleh) > 0)
328 rech = compute_policy ((end_port / step) * step,
329 (end_port / step) * step + step - 1,
330 step / 16,
331 pp);
332 else
333 rech = GNUNET_strdup ("");
334 }
335 else
336 {
337 recl = GNUNET_strdup ("");
338 rech = GNUNET_strdup ("");
339 middlel[0] = '\0';
340 middlelp[0] = '\0';
341 middleh[0] = '\0';
342 middlehp[0] = '\0';
343 }
344 if (needs_parens (recl))
345 GNUNET_asprintf (&reclp,
346 "(%s)",
347 recl);
348 else
349 reclp = GNUNET_strdup (recl);
350 if (needs_parens (rech))
351 GNUNET_asprintf (&rechp,
352 "(%s)",
353 rech);
354 else
355 rechp = GNUNET_strdup (rech);
356
357 if ( (strlen (middleh) > 0) &&
358 (strlen (rech) > 0) &&
359 (strlen (middlel) > 0) &&
360 (strlen (recl) > 0) )
361 {
362 GNUNET_asprintf (&middle,
363 "%s%s|%s%s",
364 middlel,
365 reclp,
366 middleh,
367 rechp);
368 }
369 else if ( (strlen (middleh) > 0) &&
370 (strlen (rech) > 0) )
371 {
372 GNUNET_asprintf (&middle,
373 "%s%s",
374 middleh,
375 rechp);
376 }
377 else if ( (strlen (middlel) > 0) &&
378 (strlen (recl) > 0) )
379 {
380 GNUNET_asprintf (&middle,
381 "%s%s",
382 middlel,
383 reclp);
384 }
385 else
386 {
387 middle = GNUNET_strdup ("");
388 }
389 if ( (strlen(before) > 0) &&
390 (strlen(after) > 0) )
391 {
392 if (strlen (dots) > 0)
393 {
394 if (strlen (middle) > 0)
395 GNUNET_asprintf (&ret,
396 "(%s%s|%s|%s%s)",
397 beforep, dots,
398 middle,
399 afterp, dots);
400 else
401 GNUNET_asprintf (&ret,
402 "(%s|%s)%s",
403 beforep,
404 afterp,
405 dots);
406 }
407 else
408 {
409 if (strlen (middle) > 0)
410 GNUNET_asprintf (&ret,
411 "(%s|%s|%s)",
412 before,
413 middle,
414 after);
415 else if (1 == step)
416 GNUNET_asprintf (&ret,
417 "%s|%s",
418 before,
419 after);
420 else
421 GNUNET_asprintf (&ret,
422 "(%s|%s)",
423 before,
424 after);
425 }
426 }
427 else if (strlen (before) > 0)
428 {
429 if (strlen (dots) > 0)
430 {
431 if (strlen (middle) > 0)
432 GNUNET_asprintf (&ret,
433 "(%s%s|%s)",
434 beforep, dots,
435 middle);
436 else
437 GNUNET_asprintf (&ret,
438 "%s%s",
439 beforep, dots);
440 }
441 else
442 {
443 if (strlen (middle) > 0)
444 GNUNET_asprintf (&ret,
445 "(%s|%s)",
446 before,
447 middle);
448 else
449 GNUNET_asprintf (&ret,
450 "%s",
451 before);
452 }
453 }
454 else if (strlen (after) > 0)
455 {
456 if (strlen (dots) > 0)
457 {
458 if (strlen (middle) > 0)
459 GNUNET_asprintf (&ret,
460 "(%s|%s%s)",
461 middle,
462 afterp, dots);
463 else
464 GNUNET_asprintf (&ret,
465 "%s%s",
466 afterp, dots);
467 }
468 else
469 {
470 if (strlen (middle) > 0)
471 GNUNET_asprintf (&ret,
472 "%s|%s",
473 middle,
474 after);
475 else
476 GNUNET_asprintf (&ret,
477 "%s",
478 after);
479 }
480 }
481 else if (strlen (middle) > 0)
482 {
483 GNUNET_asprintf (&ret,
484 "%s",
485 middle);
486 }
487 else
488 {
489 ret = GNUNET_strdup ("");
490 }
491 GNUNET_free (middle);
492 GNUNET_free (reclp);
493 GNUNET_free (rechp);
494 GNUNET_free (recl);
495 GNUNET_free (rech);
496 return ret;
497}
498
499
500/**
501 * Convert a port policy to a regular expression. Note: this is a
502 * very simplistic implementation, we might want to consider doing
503 * something more sophisiticated (resulting in smaller regular
504 * expressions) at a later time.
505 *
506 * @param pp port policy to convert
507 * @return NULL on error
508 */
509static char *
510port_to_regex (const struct GNUNET_STRINGS_PortPolicy *pp)
511{
512 char *reg;
513 char *ret;
514 char *pos;
515 unsigned int i;
516 unsigned int cnt;
517
518 if ( (0 == pp->start_port) ||
519 ( (1 == pp->start_port) &&
520 (0xFFFF == pp->end_port) &&
521 (GNUNET_NO == pp->negate_portrange)) )
522 return GNUNET_strdup (DOT DOT DOT DOT);
523 if ( (pp->start_port == pp->end_port) &&
524 (GNUNET_NO == pp->negate_portrange))
525 {
526 GNUNET_asprintf (&ret,
527 "%04X",
528 pp->start_port);
529 return ret;
530 }
531 if (pp->end_port < pp->start_port)
532 return NULL;
533
534 if (GNUNET_YES == pp->negate_portrange)
535 {
536 ret = compute_policy (0, 0xFFFF, 0x1000, pp);
537 }
538 else
539 {
540 cnt = pp->end_port - pp->start_port + 1;
541 reg = GNUNET_malloc (cnt * 5 + 1);
542 pos = reg;
543 for (i=1;i<=0xFFFF;i++)
544 {
545 if ( (i >= pp->start_port) && (i <= pp->end_port) )
546 {
547 if (pos == reg)
548 {
549 GNUNET_snprintf (pos,
550 5,
551 "%04X",
552 i);
553 }
554 else
555 {
556 GNUNET_snprintf (pos,
557 6,
558 "|%04X",
559 i);
560 }
561 pos += strlen (pos);
562 }
563 }
564 GNUNET_asprintf (&ret,
565 "(%s)",
566 reg);
567 GNUNET_free (reg);
568 }
569 return ret;
570}
571
572
573/**
574 * Convert an address (IPv4 or IPv6) to a regex.
575 *
576 * @param addr address
577 * @param mask network mask
578 * @param len number of bytes in @a addr and @a mask
579 * @return NULL on error, otherwise regex for the address
580 */
581static char *
582address_to_regex (const void *addr,
583 const void *mask,
584 size_t len)
585{
586 const uint16_t *a = addr;
587 const uint16_t *m = mask;
588 char *ret;
589 char *tmp;
590 char *reg;
591 unsigned int i;
592
593 ret = NULL;
594 GNUNET_assert (1 != (len % 2));
595 for (i=0;i<len / 2;i++)
596 {
597 reg = num_to_regex (a[i], m[i]);
598 if (NULL == reg)
599 {
600 GNUNET_free_non_null (ret);
601 return NULL;
602 }
603 if (NULL == ret)
604 {
605 ret = reg;
606 }
607 else
608 {
609 GNUNET_asprintf (&tmp,
610 "%s%s",
611 ret, reg);
612 GNUNET_free (ret);
613 GNUNET_free (reg);
614 ret = tmp;
615 }
616 }
617 return ret;
618}
619
620
621/**
622 * Convert a single line of an IPv4 policy to a regular expression.
623 *
624 * @param v4 line to convert
625 * @return NULL on error
626 */
627static char *
628ipv4_to_regex (const struct GNUNET_STRINGS_IPv4NetworkPolicy *v4)
629{
630 char *reg;
631 char *pp;
632 char *ret;
633
634 reg = address_to_regex (&v4->network,
635 &v4->netmask,
636 sizeof (struct in_addr));
637 if (NULL == reg)
638 return NULL;
639 pp = port_to_regex (&v4->pp);
640 if (NULL == pp)
641 {
642 GNUNET_free (reg);
643 return NULL;
644 }
645 GNUNET_asprintf (&ret,
646 "4-%s-%s",
647 pp, reg);
648 GNUNET_free (pp);
649 GNUNET_free (reg);
650 return ret;
651}
652
653
654/**
655 * Convert a single line of an IPv4 policy to a regular expression.
656 *
657 * @param v6 line to convert
658 * @return NULL on error
659 */
660static char *
661ipv6_to_regex (const struct GNUNET_STRINGS_IPv6NetworkPolicy *v6)
662{
663 char *reg;
664 char *pp;
665 char *ret;
666
667 reg = address_to_regex (&v6->network,
668 &v6->netmask,
669 sizeof (struct in6_addr));
670 if (NULL == reg)
671 return NULL;
672 pp = port_to_regex (&v6->pp);
673 if (NULL == pp)
674 {
675 GNUNET_free (reg);
676 return NULL;
677 }
678 GNUNET_asprintf (&ret,
679 "6-%s-%s",
680 pp, reg);
681 GNUNET_free (pp);
682 GNUNET_free (reg);
683 return ret;
684}
685
686
687/**
688 * Convert an exit policy to a regular expression. The exit policy
689 * specifies a set of subnets this peer is willing to serve as an
690 * exit for; the resulting regular expression will match the
691 * IPv4 address strings as returned by #GNUNET_TUN_ipv4toregexsearch().
692 *
693 * @param policy exit policy specification
694 * @return regular expression, NULL on error
695 */
696char *
697GNUNET_TUN_ipv4policy2regex (const char *policy)
698{
699 struct GNUNET_STRINGS_IPv4NetworkPolicy *np;
700 char *reg;
701 char *tmp;
702 char *line;
703 unsigned int i;
704
705 np = GNUNET_STRINGS_parse_ipv4_policy (policy);
706 if (NULL == np)
707 return NULL;
708 reg = NULL;
709 for (i=0; (0 == i) || (0 != np[i].network.s_addr); i++)
710 {
711 line = ipv4_to_regex (&np[i]);
712 if (NULL == line)
713 {
714 GNUNET_free_non_null (reg);
715 GNUNET_free (np);
716 return NULL;
717 }
718 if (NULL == reg)
719 {
720 reg = line;
721 }
722 else
723 {
724 GNUNET_asprintf (&tmp,
725 "%s|(%s)",
726 reg, line);
727 GNUNET_free (reg);
728 GNUNET_free (line);
729 reg = tmp;
730 }
731 if (0 == np[i].network.s_addr)
732 break;
733 }
734 GNUNET_free (np);
735 return reg;
736}
737
738
739/**
740 * Convert an exit policy to a regular expression. The exit policy
741 * specifies a set of subnets this peer is willing to serve as an
742 * exit for; the resulting regular expression will match the
743 * IPv6 address strings as returned by #GNUNET_TUN_ipv6toregexsearch().
744 *
745 * @param policy exit policy specification
746 * @return regular expression, NULL on error
747 */
748char *
749GNUNET_TUN_ipv6policy2regex (const char *policy)
750{
751 struct in6_addr zero;
752 struct GNUNET_STRINGS_IPv6NetworkPolicy *np;
753 char *reg;
754 char *tmp;
755 char *line;
756 unsigned int i;
757
758 np = GNUNET_STRINGS_parse_ipv6_policy (policy);
759 if (NULL == np)
760 return NULL;
761 reg = NULL;
762 memset (&zero, 0, sizeof (struct in6_addr));
763 for (i=0; (0 == i) || (0 != memcmp (&zero, &np[i].network, sizeof (struct in6_addr))); i++)
764 {
765 line = ipv6_to_regex (&np[i]);
766 if (NULL == line)
767 {
768 GNUNET_free_non_null (reg);
769 GNUNET_free (np);
770 return NULL;
771 }
772 if (NULL == reg)
773 {
774 reg = line;
775 }
776 else
777 {
778 GNUNET_asprintf (&tmp,
779 "%s|(%s)",
780 reg, line);
781 GNUNET_free (reg);
782 GNUNET_free (line);
783 reg = tmp;
784 }
785 if (0 == memcmp (&zero, &np[i].network, sizeof (struct in6_addr)))
786 break;
787 }
788 GNUNET_free (np);
789 return reg;
790}
791
792
793/**
794 * Hash the service name of a hosted service to the
795 * hash code that is used to identify the service on
796 * the network.
797 *
798 * @param service_name a string
799 * @param hc corresponding hash
800 */
801void
802GNUNET_TUN_service_name_to_hash (const char *service_name,
803 struct GNUNET_HashCode *hc)
804{
805 GNUNET_CRYPTO_hash (service_name,
806 strlen (service_name),
807 hc);
808}
809
810
811/**
812 * Compute the CADET port given a service descriptor
813 * (returned from #GNUNET_TUN_service_name_to_hash) and
814 * a TCP/UDP port @a ip_port.
815 *
816 * @param desc service shared secret
817 * @param ip_port TCP/UDP port, use 0 for ICMP
818 * @param[out] cadet_port CADET port to use
819 */
820void
821GNUNET_TUN_compute_service_cadet_port (const struct GNUNET_HashCode *desc,
822 uint16_t ip_port,
823 struct GNUNET_HashCode *cadet_port)
824{
825 uint16_t be_port = htons (ip_port);
826
827 *cadet_port = *desc;
828 GNUNET_memcpy (cadet_port,
829 &be_port,
830 sizeof (uint16_t));
831}
832
833
834/* end of regex.c */
diff --git a/src/util/resolver.conf.in b/src/util/resolver.conf.in
index 9c5df32bc..6e2b9a869 100644
--- a/src/util/resolver.conf.in
+++ b/src/util/resolver.conf.in
@@ -1,5 +1,5 @@
1[resolver] 1[resolver]
2AUTOSTART = @AUTOSTART@ 2START_ON_DEMAND = @START_ON_DEMAND@
3@JAVAPORT@PORT = 2089 3@JAVAPORT@PORT = 2089
4HOSTNAME = localhost 4HOSTNAME = localhost
5BINARY = gnunet-service-resolver 5BINARY = gnunet-service-resolver
diff --git a/src/util/resolver.h b/src/util/resolver.h
index 78f3fd0ed..07851d052 100644
--- a/src/util/resolver.h
+++ b/src/util/resolver.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/**
@@ -58,10 +56,37 @@ struct GNUNET_RESOLVER_GetMessage
58 */ 56 */
59 int32_t af GNUNET_PACKED; 57 int32_t af GNUNET_PACKED;
60 58
59 /**
60 * identifies the request and is contained in the response message. The
61 * client has to match response to request by this identifier.
62 */
63 uint16_t id GNUNET_PACKED;
64
61 /* followed by 0-terminated string for A/AAAA-lookup or 65 /* followed by 0-terminated string for A/AAAA-lookup or
62 by 'struct in_addr' / 'struct in6_addr' for reverse lookup */ 66 by 'struct in_addr' / 'struct in6_addr' for reverse lookup */
63 67
64}; 68};
69
70
71struct GNUNET_RESOLVER_ResponseMessage
72{
73 /**
74 * Type: GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE
75 */
76 struct GNUNET_MessageHeader header;
77
78 /**
79 * identifies the request this message responds to. The client
80 * has to match response to request by this identifier.
81 */
82 uint16_t id GNUNET_PACKED;
83
84 /* followed by 0-terminated string for response to a reverse lookup
85 * or by 'struct in_addr' / 'struct in6_addr' for response to
86 * A/AAAA-lookup
87 */
88};
89
65GNUNET_NETWORK_STRUCT_END 90GNUNET_NETWORK_STRUCT_END
66 91
67#endif 92#endif
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index 68f02587a..8a054327b 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009-2018 GNUnet e.V. 3 Copyright (C) 2009-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/** 19/**
@@ -70,6 +68,11 @@ static struct GNUNET_RESOLVER_RequestHandle *req_head;
70 */ 68 */
71static struct GNUNET_RESOLVER_RequestHandle *req_tail; 69static struct GNUNET_RESOLVER_RequestHandle *req_tail;
72 70
71///**
72// * ID of the last request we sent to the service
73// */
74//static uint16_t last_request_id;
75
73/** 76/**
74 * How long should we wait to reconnect? 77 * How long should we wait to reconnect?
75 */ 78 */
@@ -139,6 +142,11 @@ struct GNUNET_RESOLVER_RequestHandle
139 int af; 142 int af;
140 143
141 /** 144 /**
145 * Identifies the request. The response will contain this id.
146 */
147 uint32_t id;
148
149 /**
142 * Has this request been transmitted to the service? 150 * Has this request been transmitted to the service?
143 * #GNUNET_YES if transmitted 151 * #GNUNET_YES if transmitted
144 * #GNUNET_YES if not transmitted 152 * #GNUNET_YES if not transmitted
@@ -182,6 +190,11 @@ check_config ()
182 struct sockaddr_in v4; 190 struct sockaddr_in v4;
183 struct sockaddr_in6 v6; 191 struct sockaddr_in6 v6;
184 192
193 if (GNUNET_OK ==
194 GNUNET_CONFIGURATION_have_value (resolver_cfg,
195 "resolver",
196 "UNIXPATH"))
197 return GNUNET_OK;
185 memset (&v4, 0, sizeof (v4)); 198 memset (&v4, 0, sizeof (v4));
186 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); 199 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
187 v4.sin_family = AF_INET; 200 v4.sin_family = AF_INET;
@@ -432,11 +445,13 @@ process_requests ()
432 GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); 445 GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST);
433 msg->direction = htonl (rh->direction); 446 msg->direction = htonl (rh->direction);
434 msg->af = htonl (rh->af); 447 msg->af = htonl (rh->af);
448 msg->id = htons (rh->id);
435 GNUNET_memcpy (&msg[1], 449 GNUNET_memcpy (&msg[1],
436 &rh[1], 450 &rh[1],
437 rh->data_len); 451 rh->data_len);
438 LOG (GNUNET_ERROR_TYPE_DEBUG, 452 LOG (GNUNET_ERROR_TYPE_DEBUG,
439 "Transmitting DNS resolution request to DNS service\n"); 453 "Transmitting DNS resolution request (ID %u) to DNS service\n",
454 rh->id);
440 GNUNET_MQ_send (mq, 455 GNUNET_MQ_send (mq,
441 env); 456 env);
442 rh->was_transmitted = GNUNET_YES; 457 rh->was_transmitted = GNUNET_YES;
@@ -451,7 +466,7 @@ process_requests ()
451 */ 466 */
452static int 467static int
453check_response (void *cls, 468check_response (void *cls,
454 const struct GNUNET_MessageHeader *msg) 469 const struct GNUNET_RESOLVER_ResponseMessage *msg)
455{ 470{
456 (void) cls; 471 (void) cls;
457 (void) msg; 472 (void) msg;
@@ -471,11 +486,18 @@ check_response (void *cls,
471 */ 486 */
472static void 487static void
473handle_response (void *cls, 488handle_response (void *cls,
474 const struct GNUNET_MessageHeader *msg) 489 const struct GNUNET_RESOLVER_ResponseMessage *msg)
475{ 490{
476 struct GNUNET_RESOLVER_RequestHandle *rh = req_head; 491 struct GNUNET_RESOLVER_RequestHandle *rh = req_head;
477 uint16_t size; 492 uint16_t size;
478 char *nret; 493 char *nret;
494 uint16_t request_id = msg->id;
495
496 for (; rh != NULL; rh = rh->next)
497 {
498 if (rh->id == request_id)
499 break;
500 }
479 501
480 (void) cls; 502 (void) cls;
481 if (NULL == rh) 503 if (NULL == rh)
@@ -487,8 +509,8 @@ handle_response (void *cls,
487 reconnect (); 509 reconnect ();
488 return; 510 return;
489 } 511 }
490 size = ntohs (msg->size); 512 size = ntohs (msg->header.size);
491 if (size == sizeof (struct GNUNET_MessageHeader)) 513 if (size == sizeof (struct GNUNET_RESOLVER_ResponseMessage))
492 { 514 {
493 LOG (GNUNET_ERROR_TYPE_DEBUG, 515 LOG (GNUNET_ERROR_TYPE_DEBUG,
494 "Received empty response from DNS service\n"); 516 "Received empty response from DNS service\n");
@@ -515,8 +537,8 @@ handle_response (void *cls,
515 if ( (NULL != rh->addr_callback) && 537 if ( (NULL != rh->addr_callback) &&
516 (GNUNET_SYSERR != rh->was_transmitted) ) 538 (GNUNET_SYSERR != rh->was_transmitted) )
517 rh->addr_callback (rh->cls, 539 rh->addr_callback (rh->cls,
518 NULL, 540 NULL,
519 0); 541 0);
520 } 542 }
521 rh->was_transmitted = GNUNET_NO; 543 rh->was_transmitted = GNUNET_NO;
522 GNUNET_RESOLVER_request_cancel (rh); 544 GNUNET_RESOLVER_request_cancel (rh);
@@ -529,7 +551,7 @@ handle_response (void *cls,
529 const char *hostname; 551 const char *hostname;
530 552
531 hostname = (const char *) &msg[1]; 553 hostname = (const char *) &msg[1];
532 if (hostname[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') 554 if (hostname[size - sizeof (struct GNUNET_RESOLVER_ResponseMessage) - 1] != '\0')
533 { 555 {
534 GNUNET_break (0); 556 GNUNET_break (0);
535 if (GNUNET_SYSERR != rh->was_transmitted) 557 if (GNUNET_SYSERR != rh->was_transmitted)
@@ -563,7 +585,7 @@ handle_response (void *cls,
563 size_t ip_len; 585 size_t ip_len;
564 586
565 ip = &msg[1]; 587 ip = &msg[1];
566 ip_len = size - sizeof (struct GNUNET_MessageHeader); 588 ip_len = size - sizeof (struct GNUNET_RESOLVER_ResponseMessage);
567 if (ip_len == sizeof (struct in_addr)) 589 if (ip_len == sizeof (struct in_addr))
568 { 590 {
569 memset (&v4, 0, sizeof (v4)); 591 memset (&v4, 0, sizeof (v4));
@@ -760,7 +782,7 @@ reconnect_task (void *cls)
760 struct GNUNET_MQ_MessageHandler handlers[] = { 782 struct GNUNET_MQ_MessageHandler handlers[] = {
761 GNUNET_MQ_hd_var_size (response, 783 GNUNET_MQ_hd_var_size (response,
762 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE, 784 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE,
763 struct GNUNET_MessageHeader, 785 struct GNUNET_RESOLVER_ResponseMessage,
764 NULL), 786 NULL),
765 GNUNET_MQ_handler_end () 787 GNUNET_MQ_handler_end ()
766 }; 788 };
@@ -889,6 +911,14 @@ handle_lookup_timeout (void *cls)
889} 911}
890 912
891 913
914static uint16_t
915get_request_id ()
916{
917 return (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
918 UINT16_MAX);
919}
920
921
892/** 922/**
893 * Convert a string to one or more IP addresses. 923 * Convert a string to one or more IP addresses.
894 * 924 *
@@ -923,6 +953,8 @@ GNUNET_RESOLVER_ip_get (const char *hostname,
923 hostname); 953 hostname);
924 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen); 954 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen);
925 rh->af = af; 955 rh->af = af;
956 //rh->id = ++last_request_id;
957 rh->id = get_request_id ();
926 rh->addr_callback = callback; 958 rh->addr_callback = callback;
927 rh->cls = callback_cls; 959 rh->cls = callback_cls;
928 GNUNET_memcpy (&rh[1], 960 GNUNET_memcpy (&rh[1],
@@ -1069,6 +1101,8 @@ GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa,
1069 rh->name_callback = callback; 1101 rh->name_callback = callback;
1070 rh->cls = cls; 1102 rh->cls = cls;
1071 rh->af = sa->sa_family; 1103 rh->af = sa->sa_family;
1104 //rh->id = ++last_request_id;
1105 rh->id = get_request_id ();
1072 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); 1106 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1073 GNUNET_memcpy (&rh[1], 1107 GNUNET_memcpy (&rh[1],
1074 ip, 1108 ip,
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index cc0ba3eb0..5d3836639 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2009-2017 GNUnet e.V. 3 Copyright (C) 2009-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 util/scheduler.c 19 * @file util/scheduler.c
@@ -967,8 +965,6 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task)
967 965
968 /* scheduler must be running */ 966 /* scheduler must be running */
969 GNUNET_assert (NULL != scheduler_driver); 967 GNUNET_assert (NULL != scheduler_driver);
970 GNUNET_assert ( (NULL != active_task) ||
971 (GNUNET_NO == task->lifeness) );
972 is_fd_task = (NULL != task->fds); 968 is_fd_task = (NULL != task->fds);
973 if (is_fd_task) 969 if (is_fd_task)
974 { 970 {
@@ -1058,9 +1054,9 @@ GNUNET_SCHEDULER_add_with_reason_and_priority (GNUNET_SCHEDULER_TaskCallback tas
1058{ 1054{
1059 struct GNUNET_SCHEDULER_Task *t; 1055 struct GNUNET_SCHEDULER_Task *t;
1060 1056
1057 /* scheduler must be running */
1058 GNUNET_assert (NULL != scheduler_driver);
1061 GNUNET_assert (NULL != task); 1059 GNUNET_assert (NULL != task);
1062 GNUNET_assert ((NULL != active_task) ||
1063 (GNUNET_SCHEDULER_REASON_STARTUP == reason));
1064 t = GNUNET_new (struct GNUNET_SCHEDULER_Task); 1060 t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1065 t->read_fd = -1; 1061 t->read_fd = -1;
1066 t->write_fd = -1; 1062 t->write_fd = -1;
@@ -1101,7 +1097,8 @@ GNUNET_SCHEDULER_add_at_with_priority (struct GNUNET_TIME_Absolute at,
1101 struct GNUNET_SCHEDULER_Task *pos; 1097 struct GNUNET_SCHEDULER_Task *pos;
1102 struct GNUNET_SCHEDULER_Task *prev; 1098 struct GNUNET_SCHEDULER_Task *prev;
1103 1099
1104 GNUNET_assert (NULL != active_task); 1100 /* scheduler must be running */
1101 GNUNET_assert (NULL != scheduler_driver);
1105 GNUNET_assert (NULL != task); 1102 GNUNET_assert (NULL != task);
1106 t = GNUNET_new (struct GNUNET_SCHEDULER_Task); 1103 t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1107 t->callback = task; 1104 t->callback = task;
@@ -1288,7 +1285,8 @@ GNUNET_SCHEDULER_add_shutdown (GNUNET_SCHEDULER_TaskCallback task,
1288{ 1285{
1289 struct GNUNET_SCHEDULER_Task *t; 1286 struct GNUNET_SCHEDULER_Task *t;
1290 1287
1291 GNUNET_assert (NULL != active_task); 1288 /* scheduler must be running */
1289 GNUNET_assert (NULL != scheduler_driver);
1292 GNUNET_assert (NULL != task); 1290 GNUNET_assert (NULL != task);
1293 t = GNUNET_new (struct GNUNET_SCHEDULER_Task); 1291 t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1294 t->callback = task; 1292 t->callback = task;
@@ -1405,7 +1403,8 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
1405{ 1403{
1406 struct GNUNET_SCHEDULER_Task *t; 1404 struct GNUNET_SCHEDULER_Task *t;
1407 1405
1408 GNUNET_assert (NULL != active_task); 1406 /* scheduler must be running */
1407 GNUNET_assert (NULL != scheduler_driver);
1409 GNUNET_assert (NULL != task); 1408 GNUNET_assert (NULL != task);
1410 t = GNUNET_new (struct GNUNET_SCHEDULER_Task); 1409 t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1411 init_fd_info (t, 1410 init_fd_info (t,
@@ -1834,7 +1833,6 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
1834 1833
1835 /* scheduler must be running */ 1834 /* scheduler must be running */
1836 GNUNET_assert (NULL != scheduler_driver); 1835 GNUNET_assert (NULL != scheduler_driver);
1837 GNUNET_assert (NULL != active_task);
1838 GNUNET_assert (NULL != task); 1836 GNUNET_assert (NULL != task);
1839 int no_rs = (NULL == rs); 1837 int no_rs = (NULL == rs);
1840 int no_ws = (NULL == ws); 1838 int no_ws = (NULL == ws);
@@ -2024,99 +2022,109 @@ GNUNET_SCHEDULER_do_work (struct GNUNET_SCHEDULER_Handle *sh)
2024 if (timeout.abs_value_us > now.abs_value_us) 2022 if (timeout.abs_value_us > now.abs_value_us)
2025 { 2023 {
2026 /** 2024 /**
2027 * The driver called this function before the current timeout was 2025 * The event loop called this function before the current timeout was
2028 * reached (and no FD tasks are ready). This can happen in the 2026 * reached (and no FD tasks are ready). This is acceptable if
2029 * rare case when the system time is changed while the driver is 2027 *
2030 * waiting for the timeout, so we handle this gracefully. It might 2028 * - the system time was changed while the driver was waiting for
2031 * also be a programming error in the driver though. 2029 * the timeout
2030 * - an external event loop called GNUnet API functions outside of
2031 * the callbacks called in GNUNET_SCHEDULER_do_work and thus
2032 * wasn't notified about the new timeout
2033 *
2034 * It might also mean we are busy-waiting because of a programming
2035 * error in the external event loop.
2032 */ 2036 */
2033 LOG (GNUNET_ERROR_TYPE_DEBUG, 2037 LOG (GNUNET_ERROR_TYPE_DEBUG,
2034 "GNUNET_SCHEDULER_do_work did not find any ready " 2038 "GNUNET_SCHEDULER_do_work did not find any ready "
2035 "tasks and timeout has not been reached yet.\n"); 2039 "tasks and timeout has not been reached yet.\n");
2036 return GNUNET_NO;
2037 } 2040 }
2038 /** 2041 else
2039 * the current timeout was reached but no ready tasks were found, 2042 {
2040 * internal scheduler error! 2043 /**
2041 */ 2044 * the current timeout was reached but no ready tasks were found,
2042 GNUNET_assert (0); 2045 * internal scheduler error!
2043 } 2046 */
2044 2047 GNUNET_assert (0);
2045 /* find out which task priority level we are going to 2048 }
2046 process this time */
2047 max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP;
2048 GNUNET_assert (NULL == ready_head[GNUNET_SCHEDULER_PRIORITY_KEEP]);
2049 /* yes, p>0 is correct, 0 is "KEEP" which should
2050 * always be an empty queue (see assertion)! */
2051 for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--)
2052 {
2053 pos = ready_head[p];
2054 if (NULL != pos)
2055 break;
2056 } 2049 }
2057 GNUNET_assert (NULL != pos); /* ready_count wrong? */ 2050 else
2058
2059 /* process all tasks at this priority level, then yield */
2060 while (NULL != (pos = ready_head[p]))
2061 { 2051 {
2062 GNUNET_CONTAINER_DLL_remove (ready_head[p], 2052 /* find out which task priority level we are going to
2063 ready_tail[p], 2053 process this time */
2064 pos); 2054 max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP;
2065 ready_count--; 2055 GNUNET_assert (NULL == ready_head[GNUNET_SCHEDULER_PRIORITY_KEEP]);
2066 current_priority = pos->priority; 2056 /* yes, p>0 is correct, 0 is "KEEP" which should
2067 current_lifeness = pos->lifeness; 2057 * always be an empty queue (see assertion)! */
2068 active_task = pos; 2058 for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--)
2069#if PROFILE_DELAYS
2070 if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value_us >
2071 DELAY_THRESHOLD.rel_value_us)
2072 { 2059 {
2073 LOG (GNUNET_ERROR_TYPE_DEBUG, 2060 pos = ready_head[p];
2074 "Task %p took %s to be scheduled\n", 2061 if (NULL != pos)
2075 pos, 2062 break;
2076 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pos->start_time),
2077 GNUNET_YES));
2078 } 2063 }
2079#endif 2064 GNUNET_assert (NULL != pos); /* ready_count wrong? */
2080 tc.reason = pos->reason; 2065
2081 GNUNET_NETWORK_fdset_zero (sh->rs); 2066 /* process all tasks at this priority level, then yield */
2082 GNUNET_NETWORK_fdset_zero (sh->ws); 2067 while (NULL != (pos = ready_head[p]))
2083 // FIXME: do we have to remove FdInfos from fds if they are not ready?
2084 tc.fds_len = pos->fds_len;
2085 tc.fds = pos->fds;
2086 for (unsigned int i = 0; i != pos->fds_len; ++i)
2087 { 2068 {
2088 struct GNUNET_SCHEDULER_FdInfo *fdi = &pos->fds[i]; 2069 GNUNET_CONTAINER_DLL_remove (ready_head[p],
2089 if (0 != (GNUNET_SCHEDULER_ET_IN & fdi->et)) 2070 ready_tail[p],
2071 pos);
2072 ready_count--;
2073 current_priority = pos->priority;
2074 current_lifeness = pos->lifeness;
2075 active_task = pos;
2076#if PROFILE_DELAYS
2077 if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value_us >
2078 DELAY_THRESHOLD.rel_value_us)
2090 { 2079 {
2091 GNUNET_NETWORK_fdset_set_native (sh->rs, 2080 LOG (GNUNET_ERROR_TYPE_DEBUG,
2092 fdi->sock); 2081 "Task %p took %s to be scheduled\n",
2082 pos,
2083 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pos->start_time),
2084 GNUNET_YES));
2093 } 2085 }
2094 if (0 != (GNUNET_SCHEDULER_ET_OUT & fdi->et)) 2086#endif
2087 tc.reason = pos->reason;
2088 GNUNET_NETWORK_fdset_zero (sh->rs);
2089 GNUNET_NETWORK_fdset_zero (sh->ws);
2090 // FIXME: do we have to remove FdInfos from fds if they are not ready?
2091 tc.fds_len = pos->fds_len;
2092 tc.fds = pos->fds;
2093 for (unsigned int i = 0; i != pos->fds_len; ++i)
2095 { 2094 {
2096 GNUNET_NETWORK_fdset_set_native (sh->ws, 2095 struct GNUNET_SCHEDULER_FdInfo *fdi = &pos->fds[i];
2097 fdi->sock); 2096 if (0 != (GNUNET_SCHEDULER_ET_IN & fdi->et))
2097 {
2098 GNUNET_NETWORK_fdset_set_native (sh->rs,
2099 fdi->sock);
2100 }
2101 if (0 != (GNUNET_SCHEDULER_ET_OUT & fdi->et))
2102 {
2103 GNUNET_NETWORK_fdset_set_native (sh->ws,
2104 fdi->sock);
2105 }
2098 } 2106 }
2099 } 2107 tc.read_ready = sh->rs;
2100 tc.read_ready = sh->rs; 2108 tc.write_ready = sh->ws;
2101 tc.write_ready = sh->ws; 2109 LOG (GNUNET_ERROR_TYPE_DEBUG,
2102 LOG (GNUNET_ERROR_TYPE_DEBUG, 2110 "Running task %p\n",
2103 "Running task %p\n", 2111 pos);
2104 pos); 2112 GNUNET_assert (NULL != pos->callback);
2105 GNUNET_assert (NULL != pos->callback); 2113 pos->callback (pos->callback_cls);
2106 pos->callback (pos->callback_cls); 2114 if (NULL != pos->fds)
2107 if (NULL != pos->fds)
2108 {
2109 int del_result = scheduler_driver->del (scheduler_driver->cls, pos);
2110 if (GNUNET_OK != del_result)
2111 { 2115 {
2112 LOG (GNUNET_ERROR_TYPE_ERROR, 2116 int del_result = scheduler_driver->del (scheduler_driver->cls, pos);
2113 "driver could not delete task %p\n", pos); 2117 if (GNUNET_OK != del_result)
2114 GNUNET_assert (0); 2118 {
2119 LOG (GNUNET_ERROR_TYPE_ERROR,
2120 "driver could not delete task %p\n", pos);
2121 GNUNET_assert (0);
2122 }
2115 } 2123 }
2124 active_task = NULL;
2125 dump_backtrace (pos);
2126 destroy_task (pos);
2116 } 2127 }
2117 active_task = NULL;
2118 dump_backtrace (pos);
2119 destroy_task (pos);
2120 } 2128 }
2121 shutdown_if_no_lifeness (); 2129 shutdown_if_no_lifeness ();
2122 if (0 == ready_count) 2130 if (0 == ready_count)
@@ -2166,12 +2174,12 @@ struct GNUNET_SCHEDULER_Handle *
2166GNUNET_SCHEDULER_driver_init (const struct GNUNET_SCHEDULER_Driver *driver) 2174GNUNET_SCHEDULER_driver_init (const struct GNUNET_SCHEDULER_Driver *driver)
2167{ 2175{
2168 struct GNUNET_SCHEDULER_Handle *sh; 2176 struct GNUNET_SCHEDULER_Handle *sh;
2169 struct GNUNET_SCHEDULER_Task tsk;
2170 const struct GNUNET_DISK_FileHandle *pr; 2177 const struct GNUNET_DISK_FileHandle *pr;
2171 2178
2172 /* general set-up */ 2179 /* scheduler must not be running */
2173 GNUNET_assert (NULL == active_task); 2180 GNUNET_assert (NULL == scheduler_driver);
2174 GNUNET_assert (NULL == shutdown_pipe_handle); 2181 GNUNET_assert (NULL == shutdown_pipe_handle);
2182 /* general set-up */
2175 sh = GNUNET_new (struct GNUNET_SCHEDULER_Handle); 2183 sh = GNUNET_new (struct GNUNET_SCHEDULER_Handle);
2176 shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, 2184 shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO,
2177 GNUNET_NO, 2185 GNUNET_NO,
@@ -2206,10 +2214,6 @@ GNUNET_SCHEDULER_driver_init (const struct GNUNET_SCHEDULER_Driver *driver)
2206 /* Setup initial tasks */ 2214 /* Setup initial tasks */
2207 current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; 2215 current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
2208 current_lifeness = GNUNET_NO; 2216 current_lifeness = GNUNET_NO;
2209 memset (&tsk,
2210 0,
2211 sizeof (tsk));
2212 active_task = &tsk;
2213 install_parent_control_task = 2217 install_parent_control_task =
2214 GNUNET_SCHEDULER_add_now (&install_parent_control_handler, 2218 GNUNET_SCHEDULER_add_now (&install_parent_control_handler,
2215 NULL); 2219 NULL);
@@ -2219,7 +2223,6 @@ GNUNET_SCHEDULER_driver_init (const struct GNUNET_SCHEDULER_Driver *driver)
2219 &shutdown_pipe_cb, 2223 &shutdown_pipe_cb,
2220 NULL); 2224 NULL);
2221 current_lifeness = GNUNET_YES; 2225 current_lifeness = GNUNET_YES;
2222 active_task = NULL;
2223 scheduler_driver->set_wakeup (scheduler_driver->cls, 2226 scheduler_driver->set_wakeup (scheduler_driver->cls,
2224 get_timeout ()); 2227 get_timeout ());
2225 /* begin main event loop */ 2228 /* begin main event loop */
diff --git a/src/util/service.c b/src/util/service.c
index 1156093f4..20cc1036d 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2016 GNUnet e.V. 3 Copyright (C) 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/**
@@ -1572,6 +1570,36 @@ teardown_service (struct GNUNET_SERVICE_Handle *sh)
1572 1570
1573 1571
1574/** 1572/**
1573 * Function to return link to AGPL source upon request.
1574 *
1575 * @param cls closure with the identification of the client
1576 * @param msg AGPL request
1577 */
1578static void
1579return_agpl (void *cls,
1580 const struct GNUNET_MessageHeader *msg)
1581{
1582 struct GNUNET_SERVICE_Client *client = cls;
1583 struct GNUNET_MQ_Handle *mq;
1584 struct GNUNET_MQ_Envelope *env;
1585 struct GNUNET_MessageHeader *res;
1586 size_t slen;
1587
1588 slen = strlen (GNUNET_AGPL_URL) + 1;
1589 env = GNUNET_MQ_msg_extra (res,
1590 GNUNET_MESSAGE_TYPE_RESPONSE_AGPL,
1591 slen);
1592 memcpy (&res[1],
1593 GNUNET_AGPL_URL,
1594 slen);
1595 mq = GNUNET_SERVICE_client_get_mq (client);
1596 GNUNET_MQ_send (mq,
1597 env);
1598 GNUNET_SERVICE_client_continue (client);
1599}
1600
1601
1602/**
1575 * Low-level function to start a service if the scheduler 1603 * Low-level function to start a service if the scheduler
1576 * is already running. Should only be used directly in 1604 * is already running. Should only be used directly in
1577 * special cases. 1605 * special cases.
@@ -1623,7 +1651,9 @@ GNUNET_SERVICE_start (const char *service_name,
1623 sh->connect_cb = connect_cb; 1651 sh->connect_cb = connect_cb;
1624 sh->disconnect_cb = disconnect_cb; 1652 sh->disconnect_cb = disconnect_cb;
1625 sh->cb_cls = cls; 1653 sh->cb_cls = cls;
1626 sh->handlers = GNUNET_MQ_copy_handlers (handlers); 1654 sh->handlers = GNUNET_MQ_copy_handlers2 (handlers,
1655 &return_agpl,
1656 NULL);
1627 if (GNUNET_OK != setup_service (sh)) 1657 if (GNUNET_OK != setup_service (sh))
1628 { 1658 {
1629 GNUNET_free_non_null (sh->handlers); 1659 GNUNET_free_non_null (sh->handlers);
@@ -1723,9 +1753,9 @@ GNUNET_SERVICE_run_ (int argc,
1723 struct GNUNET_GETOPT_CommandLineOption service_options[] = { 1753 struct GNUNET_GETOPT_CommandLineOption service_options[] = {
1724 GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename), 1754 GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
1725 GNUNET_GETOPT_option_flag ('d', 1755 GNUNET_GETOPT_option_flag ('d',
1726 "daemonize", 1756 "daemonize",
1727 gettext_noop ("do daemonize (detach from terminal)"), 1757 gettext_noop ("do daemonize (detach from terminal)"),
1728 &do_daemonize), 1758 &do_daemonize),
1729 GNUNET_GETOPT_option_help (NULL), 1759 GNUNET_GETOPT_option_help (NULL),
1730 GNUNET_GETOPT_option_loglevel (&loglev), 1760 GNUNET_GETOPT_option_loglevel (&loglev),
1731 GNUNET_GETOPT_option_logfile (&logfile), 1761 GNUNET_GETOPT_option_logfile (&logfile),
diff --git a/src/util/signal.c b/src/util/signal.c
index cb917e36a..ecb792106 100644
--- a/src/util/signal.c
+++ b/src/util/signal.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2006 GNUnet e.V. 3 Copyright (C) 2001, 2002, 2006 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/util/socks.c b/src/util/socks.c
index 85548fd79..1459fd2f0 100644
--- a/src/util/socks.c
+++ b/src/util/socks.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/** 19/**
diff --git a/src/util/speedup.c b/src/util/speedup.c
index f5e81f16b..d32364480 100644
--- a/src/util/speedup.c
+++ b/src/util/speedup.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/**
diff --git a/src/util/speedup.h b/src/util/speedup.h
index 36b77aaf0..a9ea1cbae 100644
--- a/src/util/speedup.h
+++ b/src/util/speedup.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/** 19/**
diff --git a/src/util/strings.c b/src/util/strings.c
index 4cfcd63b3..ea3c8cfb9 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2005-2017 GNUnet e.V. 3 Copyright (C) 2005-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 util/strings.c 19 * @file util/strings.c
@@ -1949,27 +1947,27 @@ static char *cvt =
1949/** 1947/**
1950 * Encode into Base64. 1948 * Encode into Base64.
1951 * 1949 *
1952 * @param data the data to encode 1950 * @param in the data to encode
1953 * @param len the length of the input 1951 * @param len the length of the input
1954 * @param output where to write the output (*output should be NULL, 1952 * @param output where to write the output (*output should be NULL,
1955 * is allocated) 1953 * is allocated)
1956 * @return the size of the output 1954 * @return the size of the output
1957 */ 1955 */
1958size_t 1956size_t
1959GNUNET_STRINGS_base64_encode (const char *data, 1957GNUNET_STRINGS_base64_encode (const void *in,
1960 size_t len, 1958 size_t len,
1961 char **output) 1959 char **output)
1962{ 1960{
1963 size_t i; 1961 const char *data = in;
1964 char c;
1965 size_t ret; 1962 size_t ret;
1966 char *opt; 1963 char *opt;
1967 1964
1968 ret = 0; 1965 ret = 0;
1969 opt = GNUNET_malloc (2 + (len * 4 / 3) + 8); 1966 opt = GNUNET_malloc (2 + (len * 4 / 3) + 8);
1970 *output = opt; 1967 for (size_t i = 0; i < len; ++i)
1971 for (i = 0; i < len; ++i)
1972 { 1968 {
1969 char c;
1970
1973 c = (data[i] >> 2) & 0x3f; 1971 c = (data[i] >> 2) & 0x3f;
1974 opt[ret++] = cvt[(int) c]; 1972 opt[ret++] = cvt[(int) c];
1975 c = (data[i] << 4) & 0x3f; 1973 c = (data[i] << 4) & 0x3f;
@@ -1999,6 +1997,7 @@ GNUNET_STRINGS_base64_encode (const char *data,
1999 } 1997 }
2000 } 1998 }
2001 opt[ret++] = FILLCHAR; 1999 opt[ret++] = FILLCHAR;
2000 *output = opt;
2002 return ret; 2001 return ret;
2003} 2002}
2004 2003
@@ -2020,11 +2019,10 @@ GNUNET_STRINGS_base64_encode (const char *data,
2020 */ 2019 */
2021size_t 2020size_t
2022GNUNET_STRINGS_base64_decode (const char *data, 2021GNUNET_STRINGS_base64_decode (const char *data,
2023 size_t len, char **output) 2022 size_t len,
2023 void **out)
2024{ 2024{
2025 size_t i; 2025 char *output;
2026 char c;
2027 char c1;
2028 size_t ret = 0; 2026 size_t ret = 0;
2029 2027
2030#define CHECK_CRLF while (data[i] == '\r' || data[i] == '\n') {\ 2028#define CHECK_CRLF while (data[i] == '\r' || data[i] == '\n') {\
@@ -2033,12 +2031,15 @@ GNUNET_STRINGS_base64_decode (const char *data,
2033 if (i >= len) goto END; \ 2031 if (i >= len) goto END; \
2034 } 2032 }
2035 2033
2036 *output = GNUNET_malloc ((len * 3 / 4) + 8); 2034 output = GNUNET_malloc ((len * 3 / 4) + 8);
2037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2038 "base64_decode decoding len=%d\n", 2036 "base64_decode decoding len=%d\n",
2039 (int) len); 2037 (int) len);
2040 for (i = 0; i < len; ++i) 2038 for (size_t i = 0; i < len; ++i)
2041 { 2039 {
2040 char c;
2041 char c1;
2042
2042 CHECK_CRLF; 2043 CHECK_CRLF;
2043 if (FILLCHAR == data[i]) 2044 if (FILLCHAR == data[i])
2044 break; 2045 break;
@@ -2047,7 +2048,7 @@ GNUNET_STRINGS_base64_decode (const char *data,
2047 CHECK_CRLF; 2048 CHECK_CRLF;
2048 c1 = (char) cvtfind (data[i]); 2049 c1 = (char) cvtfind (data[i]);
2049 c = (c << 2) | ((c1 >> 4) & 0x3); 2050 c = (c << 2) | ((c1 >> 4) & 0x3);
2050 (*output)[ret++] = c; 2051 output[ret++] = c;
2051 if (++i < len) 2052 if (++i < len)
2052 { 2053 {
2053 CHECK_CRLF; 2054 CHECK_CRLF;
@@ -2056,7 +2057,7 @@ GNUNET_STRINGS_base64_decode (const char *data,
2056 break; 2057 break;
2057 c = (char) cvtfind (c); 2058 c = (char) cvtfind (c);
2058 c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf); 2059 c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf);
2059 (*output)[ret++] = c1; 2060 output[ret++] = c1;
2060 } 2061 }
2061 if (++i < len) 2062 if (++i < len)
2062 { 2063 {
@@ -2067,15 +2068,13 @@ GNUNET_STRINGS_base64_decode (const char *data,
2067 2068
2068 c1 = (char) cvtfind (c1); 2069 c1 = (char) cvtfind (c1);
2069 c = ((c << 6) & 0xc0) | c1; 2070 c = ((c << 6) & 0xc0) | c1;
2070 (*output)[ret++] = c; 2071 output[ret++] = c;
2071 } 2072 }
2072 } 2073 }
2073END: 2074END:
2075 *out = output;
2074 return ret; 2076 return ret;
2075} 2077}
2076 2078
2077 2079
2078
2079
2080
2081/* end of strings.c */ 2080/* end of strings.c */
diff --git a/src/util/test_bio.c b/src/util/test_bio.c
index c88b78426..acdd0bc06 100644
--- a/src/util/test_bio.c
+++ b/src/util/test_bio.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009 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/util/test_client.c b/src/util/test_client.c
index 527b400b0..a425f7ec4 100644
--- a/src/util/test_client.c
+++ b/src/util/test_client.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009, 2016 GNUnet e.V. 3 Copyright (C) 2009, 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 * @file util/test_client.c 19 * @file util/test_client.c
diff --git a/src/util/test_common_allocation.c b/src/util/test_common_allocation.c
index 4d1b6fe7d..dd2bb23c3 100644
--- a/src/util/test_common_allocation.c
+++ b/src/util/test_common_allocation.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2005, 2006, 2017 GNUnet e.V. 3 Copyright (C) 2001, 2002, 2003, 2005, 2006, 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/** 19/**
diff --git a/src/util/test_common_endian.c b/src/util/test_common_endian.c
index edcbe4d31..f7bf00b40 100644
--- a/src/util/test_common_endian.c
+++ b/src/util/test_common_endian.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009 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 util/test_common_endian.c 19 * @file util/test_common_endian.c
diff --git a/src/util/test_common_logging.c b/src/util/test_common_logging.c
index 62acbfd1c..5832e75f4 100644
--- a/src/util/test_common_logging.c
+++ b/src/util/test_common_logging.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2008 GNUnet e.V. 3 Copyright (C) 2008 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/util/test_common_logging_dummy.c b/src/util/test_common_logging_dummy.c
index cb191ddab..afa78aad0 100644
--- a/src/util/test_common_logging_dummy.c
+++ b/src/util/test_common_logging_dummy.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2008-2013 GNUnet e.V. 3 Copyright (C) 2008-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/util/test_common_logging_runtime_loglevels.c b/src/util/test_common_logging_runtime_loglevels.c
index c633d7de8..863cb2a55 100644
--- a/src/util/test_common_logging_runtime_loglevels.c
+++ b/src/util/test_common_logging_runtime_loglevels.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011 GNUnet e.V. 3 Copyright (C) 2011 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/util/test_configuration.c b/src/util/test_configuration.c
index 80ae01c68..067c15bf2 100644
--- a/src/util/test_configuration.c
+++ b/src/util/test_configuration.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2003, 2004, 2005, 2006, 2007 GNUnet e.V. 3 Copyright (C) 2003, 2004, 2005, 2006, 2007 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 util/test_configuration.c 19 * @file util/test_configuration.c
diff --git a/src/util/test_configuration_data.conf b/src/util/test_configuration_data.conf
index 517cbf0b0..93dfd128a 100644
--- a/src/util/test_configuration_data.conf
+++ b/src/util/test_configuration_data.conf
@@ -3,7 +3,7 @@ SUBST=/hello
3 3
4[GNUNET] 4[GNUNET]
5SUBST=hello 5SUBST=hello
6GNUNET_HOME=/tmp 6GNUNET_HOME=$GNUNET_TMP/test-hello-configuration-data/
7 7
8[test] 8[test]
9a=a 9a=a
diff --git a/src/util/test_container_bloomfilter.c b/src/util/test_container_bloomfilter.c
index 53fc1c3bc..c144f48a1 100644
--- a/src/util/test_container_bloomfilter.c
+++ b/src/util/test_container_bloomfilter.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2004, 2009 GNUnet e.V. 3 Copyright (C) 2004, 2009 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 util/test_container_bloomfilter.c 19 * @file util/test_container_bloomfilter.c
diff --git a/src/util/test_container_dll.c b/src/util/test_container_dll.c
index 4d2830807..47d4c3d61 100644
--- a/src/util/test_container_dll.c
+++ b/src/util/test_container_dll.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2017 GNUnet e.V. 3 Copyright (C) 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/** 19/**
diff --git a/src/util/test_container_heap.c b/src/util/test_container_heap.c
index 82b0e9523..4be235573 100644
--- a/src/util/test_container_heap.c
+++ b/src/util/test_container_heap.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2008 GNUnet e.V. 3 Copyright (C) 2008 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/util/test_container_meta_data.c b/src/util/test_container_meta_data.c
index cd23674a3..5a658cc75 100644
--- a/src/util/test_container_meta_data.c
+++ b/src/util/test_container_meta_data.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2003, 2004, 2006, 2009, 2010 GNUnet e.V. 3 Copyright (C) 2003, 2004, 2006, 2009, 2010 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/util/test_container_multihashmap.c b/src/util/test_container_multihashmap.c
index a0ef8aa36..188eb2968 100644
--- a/src/util/test_container_multihashmap.c
+++ b/src/util/test_container_multihashmap.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2008 GNUnet e.V. 3 Copyright (C) 2008 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/util/test_container_multihashmap32.c b/src/util/test_container_multihashmap32.c
index c50a751d4..15a74d4ac 100644
--- a/src/util/test_container_multihashmap32.c
+++ b/src/util/test_container_multihashmap32.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2008 GNUnet e.V. 3 Copyright (C) 2008 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/util/test_container_multipeermap.c b/src/util/test_container_multipeermap.c
index 65bed6606..3f7b44da5 100644
--- a/src/util/test_container_multipeermap.c
+++ b/src/util/test_container_multipeermap.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2008, 2013 GNUnet e.V. 3 Copyright (C) 2008, 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/util/test_crypto_crc.c b/src/util/test_crypto_crc.c
index 0f67dde54..3695603cd 100644
--- a/src/util/test_crypto_crc.c
+++ b/src/util/test_crypto_crc.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2004, 2006 GNUnet e.V. 3 Copyright (C) 2001, 2002, 2003, 2004, 2006 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 For the actual CRC code: 18 For the actual CRC code:
21 Copyright abandoned; this code is in the public domain. 19 Copyright abandoned; this code is in the public domain.
diff --git a/src/util/test_crypto_ecc_dlog.c b/src/util/test_crypto_ecc_dlog.c
index 3bddf8efa..eabe3ed08 100644
--- a/src/util/test_crypto_ecc_dlog.c
+++ b/src/util/test_crypto_ecc_dlog.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2015 GNUnet e.V. 3 Copyright (C) 2015 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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 17
20*/ 18*/
21/** 19/**
diff --git a/src/util/test_crypto_ecdh_eddsa.c b/src/util/test_crypto_ecdh_eddsa.c
index ec7819c3b..b7b1634e4 100644
--- a/src/util/test_crypto_ecdh_eddsa.c
+++ b/src/util/test_crypto_ecdh_eddsa.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2002-2015 GNUnet e.V. 3 Copyright (C) 2002-2015 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/**
@@ -36,30 +34,35 @@ test_ecdh()
36 struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ecdh; 34 struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ecdh;
37 struct GNUNET_CRYPTO_EddsaPublicKey id1; 35 struct GNUNET_CRYPTO_EddsaPublicKey id1;
38 struct GNUNET_CRYPTO_EcdhePublicKey id2; 36 struct GNUNET_CRYPTO_EcdhePublicKey id2;
39 struct GNUNET_HashCode dh[3]; 37 struct GNUNET_HashCode dh[2];
40 38
41 /* Generate keys */ 39 /* Generate keys */
42 priv_dsa = GNUNET_CRYPTO_eddsa_key_create (); 40 priv_dsa = GNUNET_CRYPTO_eddsa_key_create ();
43 priv_ecdh = GNUNET_CRYPTO_ecdhe_key_create ();
44 /* Extract public keys */
45 GNUNET_CRYPTO_eddsa_key_get_public (priv_dsa, 41 GNUNET_CRYPTO_eddsa_key_get_public (priv_dsa,
46 &id1); 42 &id1);
47 GNUNET_CRYPTO_ecdhe_key_get_public (priv_ecdh, 43 for (unsigned int j=0;j<4;j++)
48 &id2); 44 {
49 /* Do ECDH */ 45 fprintf (stderr, ",");
50 GNUNET_assert (GNUNET_OK == 46 priv_ecdh = GNUNET_CRYPTO_ecdhe_key_create ();
51 GNUNET_CRYPTO_eddsa_ecdh (priv_dsa, 47 /* Extract public keys */
52 &id2, 48 GNUNET_CRYPTO_ecdhe_key_get_public (priv_ecdh,
53 &dh[0])); 49 &id2);
54 GNUNET_assert (GNUNET_OK == 50 /* Do ECDH */
55 GNUNET_CRYPTO_ecdh_eddsa (priv_ecdh, 51 GNUNET_assert (GNUNET_OK ==
56 &id1, 52 GNUNET_CRYPTO_eddsa_ecdh (priv_dsa,
57 &dh[1])); 53 &id2,
58 /* Check that both DH results are equal. */ 54 &dh[0]));
59 GNUNET_assert (0 == memcmp (&dh[0], &dh[1], 55 GNUNET_assert (GNUNET_OK ==
60 sizeof (struct GNUNET_HashCode))); 56 GNUNET_CRYPTO_ecdh_eddsa (priv_ecdh,
57 &id1,
58 &dh[1]));
59 /* Check that both DH results are equal. */
60 GNUNET_assert (0 == memcmp (&dh[0],
61 &dh[1],
62 sizeof (struct GNUNET_HashCode)));
63 GNUNET_free (priv_ecdh);
64 }
61 GNUNET_free (priv_dsa); 65 GNUNET_free (priv_dsa);
62 GNUNET_free (priv_ecdh);
63 return 0; 66 return 0;
64} 67}
65 68
@@ -75,10 +78,15 @@ main (int argc, char *argv[])
75 return 0; 78 return 0;
76 } 79 }
77 if (getenv ("GNUNET_GCRYPT_DEBUG")) 80 if (getenv ("GNUNET_GCRYPT_DEBUG"))
78 gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0); 81 gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
79 GNUNET_log_setup ("test-crypto-ecdh-eddsa", "WARNING", NULL); 82 GNUNET_log_setup ("test-crypto-ecdh-eddsa", "WARNING", NULL);
80 if (0 != test_ecdh()) 83 for (unsigned int i=0;i<4;i++)
81 return 1; 84 {
85 fprintf (stderr,
86 ".");
87 if (0 != test_ecdh())
88 return 1;
89 }
82 return 0; 90 return 0;
83} 91}
84 92
diff --git a/src/util/test_crypto_ecdhe.c b/src/util/test_crypto_ecdhe.c
index 0cfb7f2c3..6f887e9f3 100644
--- a/src/util/test_crypto_ecdhe.c
+++ b/src/util/test_crypto_ecdhe.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2002-2013 GNUnet e.V. 3 Copyright (C) 2002-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/**
@@ -50,16 +48,21 @@ main (int argc, char *argv[])
50 gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0); 48 gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0);
51 GNUNET_log_setup ("test-crypto-ecdhe", "WARNING", NULL); 49 GNUNET_log_setup ("test-crypto-ecdhe", "WARNING", NULL);
52 50
53 priv1 = GNUNET_CRYPTO_ecdhe_key_create (); 51 for (unsigned int i=0;i<100;i++)
54 priv2 = GNUNET_CRYPTO_ecdhe_key_create (); 52 {
55 GNUNET_CRYPTO_ecdhe_key_get_public (priv1, &pub1); 53 fprintf (stderr,
56 GNUNET_CRYPTO_ecdhe_key_get_public (priv2, &pub2); 54 ".");
57 GNUNET_CRYPTO_ecc_ecdh (priv1, &pub2, &ecdh1); 55 priv1 = GNUNET_CRYPTO_ecdhe_key_create ();
58 GNUNET_CRYPTO_ecc_ecdh (priv2, &pub1, &ecdh2); 56 priv2 = GNUNET_CRYPTO_ecdhe_key_create ();
59 GNUNET_assert (0 == memcmp (&ecdh1, &ecdh2, 57 GNUNET_CRYPTO_ecdhe_key_get_public (priv1, &pub1);
60 sizeof (struct GNUNET_HashCode))); 58 GNUNET_CRYPTO_ecdhe_key_get_public (priv2, &pub2);
61 GNUNET_free (priv1); 59 GNUNET_CRYPTO_ecc_ecdh (priv1, &pub2, &ecdh1);
62 GNUNET_free (priv2); 60 GNUNET_CRYPTO_ecc_ecdh (priv2, &pub1, &ecdh2);
61 GNUNET_assert (0 == memcmp (&ecdh1, &ecdh2,
62 sizeof (struct GNUNET_HashCode)));
63 GNUNET_free (priv1);
64 GNUNET_free (priv2);
65 }
63 return 0; 66 return 0;
64} 67}
65 68
diff --git a/src/util/test_crypto_ecdsa.c b/src/util/test_crypto_ecdsa.c
index 4e0baf09f..b3df27513 100644
--- a/src/util/test_crypto_ecdsa.c
+++ b/src/util/test_crypto_ecdsa.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2002-2013 GNUnet e.V. 3 Copyright (C) 2002-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/util/test_crypto_eddsa.c b/src/util/test_crypto_eddsa.c
index 4b12eb983..8539be277 100644
--- a/src/util/test_crypto_eddsa.c
+++ b/src/util/test_crypto_eddsa.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2002-2013 GNUnet e.V. 3 Copyright (C) 2002-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/util/test_crypto_hash.c b/src/util/test_crypto_hash.c
index 731205841..609be8a72 100644
--- a/src/util/test_crypto_hash.c
+++ b/src/util/test_crypto_hash.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2002, 2003, 2004, 2006, 2009 GNUnet e.V. 3 Copyright (C) 2002, 2003, 2004, 2006, 2009 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/util/test_crypto_hash_context.c b/src/util/test_crypto_hash_context.c
index 5ef73fe3c..26487fd39 100644
--- a/src/util/test_crypto_hash_context.c
+++ b/src/util/test_crypto_hash_context.c
@@ -2,16 +2,18 @@
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2014 GNUnet e.V. 3 Copyright (C) 2014 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify it under the 5 GNUnet is free software: you can redistribute it and/or modify it
6 terms of the GNU General Public License as published by the Free Software 6 under the terms of the GNU Affero General Public License as published
7 Foundation; either version 3, or (at your option) any later version. 7 by the Free Software Foundation, either version 3 of the License,
8 8 or (at your option) any later version.
9 GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY 9
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 10 GNUnet is distributed in the hope that it will be useful, but
11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 You should have received a copy of the GNU General Public License along with 13 Affero General Public License for more details.
14 GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> 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/>.
15*/ 17*/
16/** 18/**
17 * @file util/test_crypto_hash_context.c 19 * @file util/test_crypto_hash_context.c
diff --git a/src/util/test_crypto_paillier.c b/src/util/test_crypto_paillier.c
index 1e7e0b301..d600a2806 100644
--- a/src/util/test_crypto_paillier.c
+++ b/src/util/test_crypto_paillier.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2014 GNUnet e.V. 3 Copyright (C) 2014 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/util/test_crypto_random.c b/src/util/test_crypto_random.c
index e908e4626..f5e0a2731 100644
--- a/src/util/test_crypto_random.c
+++ b/src/util/test_crypto_random.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009 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/util/test_crypto_rsa.c b/src/util/test_crypto_rsa.c
index c64c0acf9..320dfce54 100644
--- a/src/util/test_crypto_rsa.c
+++ b/src/util/test_crypto_rsa.c
@@ -2,16 +2,18 @@
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2014,2015 GNUnet e.V. 3 Copyright (C) 2014,2015 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify it under the 5 GNUnet is free software: you can redistribute it and/or modify it
6 terms of the GNU General Public License as published by the Free Software 6 under the terms of the GNU Affero General Public License as published
7 Foundation; either version 3, or (at your option) any later version. 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
8 9
9 GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY 10 GNUnet is distributed in the hope that it will be useful, but
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 WITHOUT ANY WARRANTY; without even the implied warranty of
11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 13 Affero General Public License for more details.
13 You should have received a copy of the GNU General Public License along with 14
14 GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> 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/>.
15*/ 17*/
16 18
17/** 19/**
diff --git a/src/util/test_crypto_symmetric.c b/src/util/test_crypto_symmetric.c
index b2fdd07c3..d6d177ed0 100644
--- a/src/util/test_crypto_symmetric.c
+++ b/src/util/test_crypto_symmetric.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2002, 2003, 2004, 2006 GNUnet e.V. 3 Copyright (C) 2002, 2003, 2004, 2006 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/util/test_disk.c b/src/util/test_disk.c
index 7b9a6d45c..352e3ee3e 100644
--- a/src/util/test_disk.c
+++ b/src/util/test_disk.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2005, 2006, 2009 GNUnet e.V. 3 Copyright (C) 2001, 2002, 2003, 2005, 2006, 2009 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/util/test_getopt.c b/src/util/test_getopt.c
index 16f2df8d1..e5b854658 100644
--- a/src/util/test_getopt.c
+++ b/src/util/test_getopt.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2003, 2004, 2005, 2006, 2009 GNUnet e.V. 3 Copyright (C) 2003, 2004, 2005, 2006, 2009 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 util/test_getopt.c 19 * @file util/test_getopt.c
diff --git a/src/util/test_hexcoder.c b/src/util/test_hexcoder.c
new file mode 100644
index 000000000..441d7e200
--- /dev/null
+++ b/src/util/test_hexcoder.c
@@ -0,0 +1,54 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2014 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/**
20 * @author Christian Grothoff
21 * @file dns/test_hexcoder.c
22 * @brief test for #GNUNET_DNSPARSER_hex_to_bin() and
23 * #GNUNET_DNSPARSER_bin_to_hex()
24 */
25#include "platform.h"
26#include "gnunet_util_lib.h"
27#include "gnunet_dnsparser_lib.h"
28
29#define TESTSTRING "Hello World!"
30
31
32int
33main (int argc,
34 char *argv[])
35{
36 char buf[strlen (TESTSTRING) + 1];
37 char *ret;
38
39 GNUNET_log_setup ("test-hexcoder", "WARNING", NULL);
40 ret = GNUNET_DNSPARSER_bin_to_hex (TESTSTRING,
41 strlen (TESTSTRING) + 1);
42 GNUNET_assert (NULL != ret);
43 GNUNET_assert (sizeof (buf) ==
44 GNUNET_DNSPARSER_hex_to_bin (ret,
45 buf));
46 GNUNET_assert (0 == memcmp (TESTSTRING,
47 buf,
48 sizeof (buf)));
49 GNUNET_free (ret);
50 return 0;
51}
52
53
54/* end of test_hexcoder.c */
diff --git a/src/util/test_mq.c b/src/util/test_mq.c
index 9e8fc844e..c02ee677e 100644
--- a/src/util/test_mq.c
+++ b/src/util/test_mq.c
@@ -1,30 +1,39 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V. 3 Copyright (C) 2012, 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/** 19/**
22 * @file util/test_mq.c 20 * @file util/test_mq.c
23 * @brief simple tests for mq 21 * @brief tests for mq
22 * @author Florian Dold
23 * @author Christian Grothoff
24 */ 24 */
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
27 27
28#define NUM_TRANSMISSIONS 500
29
30/**
31 * How long does the receiver take per message?
32 */
33#define RECEIVER_THROTTLE GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 1)
34
35static unsigned int received_cnt;
36
28 37
29GNUNET_NETWORK_STRUCT_BEGIN 38GNUNET_NETWORK_STRUCT_BEGIN
30 39
@@ -36,6 +45,216 @@ struct MyMessage
36 45
37GNUNET_NETWORK_STRUCT_END 46GNUNET_NETWORK_STRUCT_END
38 47
48static int global_ret;
49
50static struct GNUNET_SCHEDULER_Task *tt;
51
52static struct GNUNET_SCHEDULER_Task *dt;
53
54static struct GNUNET_MQ_Handle *cmq;
55
56
57static void
58do_shutdown (void *cls)
59{
60 (void) cls;
61 if (NULL != tt)
62 {
63 GNUNET_SCHEDULER_cancel (tt);
64 tt = NULL;
65 }
66 if (NULL != cmq)
67 {
68 GNUNET_MQ_destroy (cmq);
69 cmq = NULL;
70 }
71}
72
73
74static void
75do_timeout (void *cls)
76{
77 (void) cls;
78 tt = NULL;
79 GNUNET_SCHEDULER_shutdown ();
80 global_ret = 1;
81}
82
83
84/**
85 * Generic error handler, called with the appropriate
86 * error code and the same closure specified at the creation of
87 * the message queue.
88 * Not every message queue implementation supports an error handler.
89 *
90 * @param cls closure
91 * @param error error code
92 */
93static void
94error_cb (void *cls,
95 enum GNUNET_MQ_Error error)
96{
97 GNUNET_break (0);
98 global_ret = 3;
99 GNUNET_SCHEDULER_shutdown ();
100}
101
102
103static void
104client_continue (void *cls)
105{
106 struct GNUNET_SERVICE_Client *c = cls;
107
108 dt = NULL;
109 GNUNET_SERVICE_client_continue (c);
110}
111
112
113static void
114handle_dummy (void *cls,
115 const struct MyMessage *msg)
116{
117 struct GNUNET_SERVICE_Client *c = cls;
118
119 GNUNET_assert (NULL == dt);
120 /* artificially make receiver slower than sender */
121 dt = GNUNET_SCHEDULER_add_delayed (RECEIVER_THROTTLE,
122 &client_continue,
123 c);
124 if (received_cnt != ntohl (msg->x))
125 {
126 GNUNET_break (0);
127 global_ret = 4;
128 GNUNET_SCHEDULER_shutdown ();
129 }
130 received_cnt++;
131}
132
133
134static void
135handle_dummy2 (void *cls,
136 const struct MyMessage *msg)
137{
138 struct GNUNET_SERVICE_Client *c = cls;
139
140 GNUNET_SERVICE_client_continue (c);
141 if (NUM_TRANSMISSIONS != received_cnt)
142 {
143 GNUNET_break (0);
144 global_ret = 5;
145 }
146 GNUNET_SCHEDULER_shutdown ();
147}
148
149
150/**
151 * Function called whenever MQ has sent a message.
152 */
153static void
154notify_sent_cb (void *cls)
155{
156 static unsigned int seen;
157 unsigned int *cnt = cls;
158
159 if (seen != *cnt)
160 {
161 GNUNET_break (0);
162 global_ret = 6;
163 GNUNET_SCHEDULER_shutdown ();
164 }
165 seen++;
166 GNUNET_free (cnt);
167}
168
169
170/**
171 * Start running the actual test.
172 *
173 * @param cls closure passed to #GNUNET_SERVICE_MAIN
174 * @param cfg configuration to use for this service
175 * @param sh handle to the newly create service
176 */
177static void
178run (void *cls,
179 const struct GNUNET_CONFIGURATION_Handle *cfg,
180 struct GNUNET_SERVICE_Handle *sh)
181{
182 struct GNUNET_MQ_MessageHandler ch[] = {
183 GNUNET_MQ_handler_end ()
184 };
185 struct GNUNET_MQ_Envelope *env;
186 struct MyMessage *m;
187
188 (void) cls;
189 (void) sh;
190 cmq = GNUNET_CLIENT_connect (cfg,
191 "test_client",
192 ch,
193 &error_cb,
194 NULL);
195 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
196 NULL);
197 tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
198 &do_timeout,
199 NULL);
200 for (unsigned int i=0;i<NUM_TRANSMISSIONS;i++)
201 {
202 unsigned int *cnt;
203
204 cnt = GNUNET_new (unsigned int);
205 *cnt = i;
206 env = GNUNET_MQ_msg (m,
207 GNUNET_MESSAGE_TYPE_DUMMY);
208 GNUNET_MQ_notify_sent (env,
209 &notify_sent_cb,
210 cnt);
211 m->x = htonl (i);
212 GNUNET_MQ_send (cmq,
213 env);
214 }
215 env = GNUNET_MQ_msg (m,
216 GNUNET_MESSAGE_TYPE_DUMMY2);
217 GNUNET_MQ_send (cmq,
218 env);
219}
220
221
222/**
223 * Callback to be called when a client connects to the service.
224 *
225 * @param cls closure for the service
226 * @param c the new client that connected to the service
227 * @param mq the message queue used to send messages to the client
228 * @return the client-specific (`internal') closure
229 */
230static void *
231connect_cb (void *cls,
232 struct GNUNET_SERVICE_Client *c,
233 struct GNUNET_MQ_Handle *mq)
234{
235 (void) cls;
236 (void) mq;
237 return c;
238}
239
240
241/**
242 * Callback to be called when a client disconnected from the service
243 *
244 * @param cls closure for the service
245 * @param c the client that disconnected
246 * @param internal_cls the client-specific (`internal') closure
247 */
248static void
249disconnect_cb (void *cls,
250 struct GNUNET_SERVICE_Client *c,
251 void *internal_cls)
252{
253 (void) cls;
254 (void) c;
255 (void) internal_cls;
256}
257
39 258
40static void 259static void
41test1 () 260test1 ()
@@ -46,10 +265,11 @@ test1 ()
46 mm = NULL; 265 mm = NULL;
47 mqm = NULL; 266 mqm = NULL;
48 267
49 mqm = GNUNET_MQ_msg (mm, 42); 268 mqm = GNUNET_MQ_msg (mm,
269 GNUNET_MESSAGE_TYPE_DUMMY);
50 GNUNET_assert (NULL != mqm); 270 GNUNET_assert (NULL != mqm);
51 GNUNET_assert (NULL != mm); 271 GNUNET_assert (NULL != mm);
52 GNUNET_assert (42 == ntohs (mm->header.type)); 272 GNUNET_assert (GNUNET_MESSAGE_TYPE_DUMMY == ntohs (mm->header.type));
53 GNUNET_assert (sizeof (struct MyMessage) == ntohs (mm->header.size)); 273 GNUNET_assert (sizeof (struct MyMessage) == ntohs (mm->header.size));
54 GNUNET_MQ_discard (mqm); 274 GNUNET_MQ_discard (mqm);
55} 275}
@@ -61,13 +281,15 @@ test2 ()
61 struct GNUNET_MQ_Envelope *mqm; 281 struct GNUNET_MQ_Envelope *mqm;
62 struct GNUNET_MessageHeader *mh; 282 struct GNUNET_MessageHeader *mh;
63 283
64 mqm = GNUNET_MQ_msg_header (42); 284 mqm = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_DUMMY);
65 /* how could the above be checked? */ 285 /* how could the above be checked? */
66 286
67 GNUNET_MQ_discard (mqm); 287 GNUNET_MQ_discard (mqm);
68 288
69 mqm = GNUNET_MQ_msg_header_extra (mh, 20, 42); 289 mqm = GNUNET_MQ_msg_header_extra (mh,
70 GNUNET_assert (42 == ntohs (mh->type)); 290 20,
291 GNUNET_MESSAGE_TYPE_DUMMY);
292 GNUNET_assert (GNUNET_MESSAGE_TYPE_DUMMY == ntohs (mh->type));
71 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) + 20 == ntohs (mh->size)); 293 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) + 20 == ntohs (mh->size));
72 GNUNET_MQ_discard (mqm); 294 GNUNET_MQ_discard (mqm);
73} 295}
@@ -76,9 +298,41 @@ test2 ()
76int 298int
77main (int argc, char **argv) 299main (int argc, char **argv)
78{ 300{
79 GNUNET_log_setup ("test-mq", "INFO", NULL); 301 char * test_argv[] = {
302 (char *) "test_client",
303 "-c",
304 "test_client_data.conf",
305 NULL
306 };
307 struct GNUNET_MQ_MessageHandler mh[] = {
308 GNUNET_MQ_hd_fixed_size (dummy,
309 GNUNET_MESSAGE_TYPE_DUMMY,
310 struct MyMessage,
311 NULL),
312 GNUNET_MQ_hd_fixed_size (dummy2,
313 GNUNET_MESSAGE_TYPE_DUMMY2,
314 struct MyMessage,
315 NULL),
316 GNUNET_MQ_handler_end ()
317 };
318
319 (void) argc;
320 (void) argv;
321 GNUNET_log_setup ("test-mq",
322 "INFO",
323 NULL);
80 test1 (); 324 test1 ();
81 test2 (); 325 test2 ();
82 return 0; 326 if (0 !=
327 GNUNET_SERVICE_run_ (3,
328 test_argv,
329 "test_client",
330 GNUNET_SERVICE_OPTION_NONE,
331 &run,
332 &connect_cb,
333 &disconnect_cb,
334 NULL,
335 mh))
336 return 1;
337 return global_ret;
83} 338}
84
diff --git a/src/util/test_os_network.c b/src/util/test_os_network.c
index 85f98201f..1809a8eb6 100644
--- a/src/util/test_os_network.c
+++ b/src/util/test_os_network.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2003, 2004, 2005, 2006, 2009 GNUnet e.V. 3 Copyright (C) 2003, 2004, 2005, 2006, 2009 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 util/test_os_network.c 19 * @file util/test_os_network.c
diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c
index 929b24232..cfc39e1e0 100644
--- a/src/util/test_os_start_process.c
+++ b/src/util/test_os_start_process.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009 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 util/test_os_start_process.c 19 * @file util/test_os_start_process.c
diff --git a/src/util/test_peer.c b/src/util/test_peer.c
index d16c66a27..ddb242738 100644
--- a/src/util/test_peer.c
+++ b/src/util/test_peer.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009 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 util/test_peer.c 19 * @file util/test_peer.c
diff --git a/src/util/test_plugin.c b/src/util/test_plugin.c
index 3630886dc..a736a077a 100644
--- a/src/util/test_plugin.c
+++ b/src/util/test_plugin.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009 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 util/test_plugin.c 19 * @file util/test_plugin.c
diff --git a/src/util/test_plugin_plug.c b/src/util/test_plugin_plug.c
index 7c4f581de..683b45d3c 100644
--- a/src/util/test_plugin_plug.c
+++ b/src/util/test_plugin_plug.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009 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 util/test_plugin_plug.c 19 * @file util/test_plugin_plug.c
diff --git a/src/util/test_program.c b/src/util/test_program.c
index 6d51b1872..001f3aea1 100644
--- a/src/util/test_program.c
+++ b/src/util/test_program.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009 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 util/test_program.c 19 * @file util/test_program.c
diff --git a/src/util/test_regex.c b/src/util/test_regex.c
new file mode 100644
index 000000000..2e7d52828
--- /dev/null
+++ b/src/util/test_regex.c
@@ -0,0 +1,179 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012, 2013 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 tun/test_regex.c
20 * @brief simple test for regex.c iptoregex functions
21 * @author Maximilian Szengel
22 */
23#include "platform.h"
24#include "gnunet_tun_lib.h"
25
26/**
27 * 'wildcard', matches all possible values (for HEX encoding).
28 */
29#define DOT "(0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F)"
30
31
32static int
33test_iptoregex (const char *ipv4,
34 uint16_t port,
35 const char *expectedv4,
36 const char *ipv6,
37 uint16_t port6,
38 const char *expectedv6)
39{
40 int error = 0;
41
42 struct in_addr a;
43 struct in6_addr b;
44 char rxv4[GNUNET_TUN_IPV4_REGEXLEN];
45 char rxv6[GNUNET_TUN_IPV6_REGEXLEN];
46
47 GNUNET_assert (1 == inet_pton (AF_INET, ipv4, &a));
48 GNUNET_TUN_ipv4toregexsearch (&a, port, rxv4);
49
50 if (0 != strcmp (rxv4, expectedv4))
51 {
52 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
53 "Expected: %s but got: %s\n",
54 expectedv4,
55 rxv4);
56 error++;
57 }
58
59 GNUNET_assert (1 == inet_pton (AF_INET6, ipv6, &b));
60 GNUNET_TUN_ipv6toregexsearch (&b, port6, rxv6);
61 if (0 != strcmp (rxv6, expectedv6))
62 {
63 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
64 "Expected: %s but got: %s\n",
65 expectedv6, rxv6);
66 error++;
67 }
68 return error;
69}
70
71
72static int
73test_policy4toregex (const char *policy,
74 const char *regex)
75{
76 char *r;
77 int ret;
78
79 ret = 0;
80 r = GNUNET_TUN_ipv4policy2regex (policy);
81 if (NULL == r)
82 {
83 GNUNET_break (0);
84 return 1;
85 }
86 if (0 != strcmp (regex, r))
87 {
88 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
89 "Expected: `%s' but got: `%s'\n",
90 regex, r);
91 ret = 2;
92 }
93 GNUNET_free (r);
94 return ret;
95}
96
97
98static int
99test_policy6toregex (const char *policy,
100 const char *regex)
101{
102 char *r;
103 int ret;
104
105 ret = 0;
106 r = GNUNET_TUN_ipv6policy2regex (policy);
107 if (NULL == r)
108 {
109 GNUNET_break (0);
110 return 1;
111 }
112 if (0 != strcmp (regex, r))
113 {
114 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
115 "Expected: `%s' but got: `%s'\n",
116 regex, r);
117 ret = 2;
118 }
119 GNUNET_free (r);
120 return ret;
121}
122
123
124int
125main (int argc, char *argv[])
126{
127 int error;
128 char *r;
129
130 GNUNET_log_setup ("test-regex", "WARNING", NULL);
131 error = 0;
132
133 /* this is just a performance test ... */
134 r = GNUNET_TUN_ipv4policy2regex ("1.2.3.4/16:!25;");
135 GNUNET_break (NULL != r);
136 GNUNET_free (r);
137
138 error +=
139 test_iptoregex ("192.1.2.3", 2086,
140 "4-0826-C0010203",
141 "FFFF::1", 8080,
142 "6-1F90-FFFF0000000000000000000000000001");
143 error +=
144 test_iptoregex ("187.238.255.0", 80,
145 "4-0050-BBEEFF00",
146 "E1E1:73F9:51BE::0", 49,
147 "6-0031-E1E173F951BE00000000000000000000");
148 error +=
149 test_policy4toregex ("192.1.2.0/24:80;",
150 "4-0050-C00102" DOT DOT);
151 error +=
152 test_policy4toregex ("192.1.0.0/16;",
153 "4-" DOT DOT DOT DOT "-C001" DOT DOT DOT DOT);
154 error +=
155 test_policy4toregex ("192.1.0.0/16:80-81;",
156 "4-(0050|0051)-C001" DOT DOT DOT DOT);
157 error +=
158 test_policy4toregex ("192.1.0.0/8:!3-65535;",
159 "4-000(0|1|2)-C0" DOT DOT DOT DOT DOT DOT);
160 error +=
161 test_policy4toregex ("192.1.0.0/8:!25-56;",
162 "4-(0(0(0"DOT"|1(0|1|2|3|4|5|6|7|8)|3(9|A|B|C|D|E|F)|(4|5|6|7|8|9|A|B|C|D|E|F)"DOT")|(1|2|3|4|5|6|7|8|9|A|B|C|D|E|F)"DOT DOT")|(1|2|3|4|5|6|7|8|9|A|B|C|D|E|F)"DOT DOT DOT")-C0"DOT DOT DOT DOT DOT DOT);
163 error +=
164 test_policy6toregex ("E1E1::1;",
165 "6-"DOT DOT DOT DOT"-E1E10000000000000000000000000001");
166 error +=
167 test_policy6toregex ("E1E1:ABCD::1/120;",
168 "6-"DOT DOT DOT DOT"-E1E1ABCD0000000000000000000000" DOT DOT);
169 error +=
170 test_policy6toregex ("E1E1:ABCD::ABCD/126;",
171 "6-"DOT DOT DOT DOT"-E1E1ABCD00000000000000000000ABC(C|D|E|F)");
172 error +=
173 test_policy6toregex ("E1E1:ABCD::ABCD/127;",
174 "6-"DOT DOT DOT DOT"-E1E1ABCD00000000000000000000ABC(C|D)");
175 error +=
176 test_policy6toregex ("E1E1:ABCD::ABCD/128:80;",
177 "6-0050-E1E1ABCD00000000000000000000ABCD");
178 return error;
179}
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c
index 8acceea3a..5a8f95093 100644
--- a/src/util/test_resolver_api.c
+++ b/src/util/test_resolver_api.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009 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 resolver/test_resolver_api.c 19 * @file resolver/test_resolver_api.c
@@ -260,6 +258,8 @@ run (void *cls, char *const *args, const char *cfgfile,
260 /* Resolve the same using GNUNET */ 258 /* Resolve the same using GNUNET */
261 GNUNET_RESOLVER_ip_get (ROOTSERVER_NAME, AF_INET, timeout, 259 GNUNET_RESOLVER_ip_get (ROOTSERVER_NAME, AF_INET, timeout,
262 &check_rootserver_ip, cls); 260 &check_rootserver_ip, cls);
261 GNUNET_RESOLVER_ip_get (ROOTSERVER_NAME, AF_INET, timeout,
262 &check_rootserver_ip, cls);
263 263
264 /* 264 /*
265 * Success: forward lookups work as expected 265 * Success: forward lookups work as expected
diff --git a/src/util/test_resolver_api_data.conf b/src/util/test_resolver_api_data.conf
index 42b36d66a..dd4384b80 100644
--- a/src/util/test_resolver_api_data.conf
+++ b/src/util/test_resolver_api_data.conf
@@ -1,5 +1,5 @@
1[PATHS] 1[PATHS]
2GNUNET_TEST_HOME = /tmp/test-gnunetd-statistics/ 2GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunetd-statistics/
3 3
4[resolver] 4[resolver]
5PORT = 22354 5PORT = 22354
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c
index 83319d2aa..904461465 100644
--- a/src/util/test_scheduler.c
+++ b/src/util/test_scheduler.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009 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 util/test_scheduler.c 19 * @file util/test_scheduler.c
diff --git a/src/util/test_scheduler_delay.c b/src/util/test_scheduler_delay.c
index 93568cd81..f8c4ef8da 100644
--- a/src/util/test_scheduler_delay.c
+++ b/src/util/test_scheduler_delay.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001-2013 GNUnet e.V. 3 Copyright (C) 2001-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 util/test_scheduler_delay.c 19 * @file util/test_scheduler_delay.c
diff --git a/src/util/test_service.c b/src/util/test_service.c
index 424a445bb..6858f956e 100644
--- a/src/util/test_service.c
+++ b/src/util/test_service.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 GNUnet e.V. 3 Copyright (C) 2009, 2013, 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 * @file util/test_service.c 19 * @file util/test_service.c
diff --git a/src/util/test_service_data.conf b/src/util/test_service_data.conf
index c04626b5b..975d5a1e3 100644
--- a/src/util/test_service_data.conf
+++ b/src/util/test_service_data.conf
@@ -1,7 +1,7 @@
1[test_service] 1[test_service]
2PORT=12435 2PORT=12435
3BINDTO=localhost 3BINDTO=localhost
4PIDFILE=/tmp/test-service.pid 4PIDFILE=$GNUNET_TMP/test-service.pid
5MAXBUF=1024 5MAXBUF=1024
6DISABLEV6=NO 6DISABLEV6=NO
7ACCEPT_FROM=127.0.0.1; 7ACCEPT_FROM=127.0.0.1;
@@ -12,7 +12,7 @@ HOSTNAME=localhost
12 12
13[test_service6] 13[test_service6]
14PORT=12435 14PORT=12435
15PIDFILE=/tmp/test-service.pid 15PIDFILE=$GNUNET_TMP/test-service.pid
16TIMEOUT=30 s 16TIMEOUT=30 s
17MAXBUF=1024 17MAXBUF=1024
18DISABLEV6=NO 18DISABLEV6=NO
diff --git a/src/util/test_socks.c b/src/util/test_socks.c
index cb70f916f..9df7b66bc 100644
--- a/src/util/test_socks.c
+++ b/src/util/test_socks.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2015, 2016 GNUnet e.V. 3 Copyright (C) 2015, 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 * @file util/test_socks.c 19 * @file util/test_socks.c
diff --git a/src/util/test_speedup.c b/src/util/test_speedup.c
index b9f2cfb4d..8a385ae47 100644
--- a/src/util/test_speedup.c
+++ b/src/util/test_speedup.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 * @file util/test_speedup.c 19 * @file util/test_speedup.c
diff --git a/src/util/test_strings.c b/src/util/test_strings.c
index b66474934..3750986e6 100644
--- a/src/util/test_strings.c
+++ b/src/util/test_strings.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009 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 util/test_strings.c 19 * @file util/test_strings.c
diff --git a/src/util/test_strings_to_data.c b/src/util/test_strings_to_data.c
index bd594aac0..1c58d91ec 100644
--- a/src/util/test_strings_to_data.c
+++ b/src/util/test_strings_to_data.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009 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 util/test_strings_to_data.c 19 * @file util/test_strings_to_data.c
diff --git a/src/util/test_time.c b/src/util/test_time.c
index d0aca2166..2ac93e01d 100644
--- a/src/util/test_time.c
+++ b/src/util/test_time.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001-2013 GNUnet e.V. 3 Copyright (C) 2001-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 util/test_time.c 19 * @file util/test_time.c
diff --git a/src/util/test_tun.c b/src/util/test_tun.c
new file mode 100644
index 000000000..edbd4c05d
--- /dev/null
+++ b/src/util/test_tun.c
@@ -0,0 +1,72 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010, 2011, 2012 Christian Grothoff
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/**
20 * @file tun/test_tun.c
21 * @brief test for tun.c
22 * @author Christian Grothoff
23 */
24#include "platform.h"
25#include "gnunet_tun_lib.h"
26
27static int ret;
28
29static void
30test_udp (size_t pll,
31 int pl_fill,
32 uint16_t crc)
33{
34 struct GNUNET_TUN_IPv4Header ip;
35 struct GNUNET_TUN_UdpHeader udp;
36 char payload[pll];
37 struct in_addr src;
38 struct in_addr dst;
39
40 GNUNET_assert (1 == inet_pton (AF_INET, "1.2.3.4", &src));
41 GNUNET_assert (1 == inet_pton (AF_INET, "122.2.3.5", &dst));
42 memset (payload, pl_fill, sizeof (payload));
43 GNUNET_TUN_initialize_ipv4_header (&ip,
44 IPPROTO_UDP,
45 pll + sizeof (udp),
46 &src,
47 &dst);
48 udp.source_port = htons (4242);
49 udp.destination_port = htons (4242);
50 udp.len = htons (pll);
51 GNUNET_TUN_calculate_udp4_checksum (&ip,
52 &udp,
53 payload,
54 pll);
55 if (crc != ntohs (udp.crc))
56 {
57 fprintf (stderr, "Got CRC: %u, wanted: %u\n",
58 ntohs (udp.crc),
59 crc);
60 ret = 1;
61 }
62}
63
64int main (int argc,
65 char **argv)
66{
67 test_udp (4, 3, 22439);
68 test_udp (4, 1, 23467);
69 test_udp (7, 17, 6516);
70 test_udp (12451, 251, 42771);
71 return ret;
72}
diff --git a/src/util/time.c b/src/util/time.c
index 5ffb19ec1..ee90eb8ae 100644
--- a/src/util/time.c
+++ b/src/util/time.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001-2013 GNUnet e.V. 3 Copyright (C) 2001-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/util/tun.c b/src/util/tun.c
new file mode 100644
index 000000000..25e729e58
--- /dev/null
+++ b/src/util/tun.c
@@ -0,0 +1,309 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010, 2011, 2012 Christian Grothoff
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/**
20 * @file tun/tun.c
21 * @brief standard IP calculations for TUN interaction
22 * @author Philipp Toelke
23 * @author Christian Grothoff
24 */
25#include "platform.h"
26#include "gnunet_util_lib.h"
27
28/**
29 * IP TTL we use for packets that we assemble (8 bit unsigned integer)
30 */
31#define FRESH_TTL 64
32
33
34/**
35 * Initialize an IPv4 header.
36 *
37 * @param ip header to initialize
38 * @param protocol protocol to use (i.e. IPPROTO_UDP)
39 * @param payload_length number of bytes of payload that follow (excluding IPv4 header)
40 * @param src source IP address to use
41 * @param dst destination IP address to use
42 */
43void
44GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
45 uint8_t protocol,
46 uint16_t payload_length,
47 const struct in_addr *src,
48 const struct in_addr *dst)
49{
50 GNUNET_assert (20 == sizeof (struct GNUNET_TUN_IPv4Header));
51 GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv4Header));
52 memset (ip, 0, sizeof (struct GNUNET_TUN_IPv4Header));
53 ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
54 ip->version = 4;
55 ip->total_length = htons (sizeof (struct GNUNET_TUN_IPv4Header) + payload_length);
56 ip->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
57 65536);
58 ip->ttl = FRESH_TTL;
59 ip->protocol = protocol;
60 ip->source_address = *src;
61 ip->destination_address = *dst;
62 ip->checksum = GNUNET_CRYPTO_crc16_n (ip, sizeof (struct GNUNET_TUN_IPv4Header));
63}
64
65
66/**
67 * Initialize an IPv6 header.
68 *
69 * @param ip header to initialize
70 * @param protocol protocol to use (i.e. IPPROTO_UDP), technically "next_header" for IPv6
71 * @param payload_length number of bytes of payload that follow (excluding IPv6 header)
72 * @param src source IP address to use
73 * @param dst destination IP address to use
74 */
75void
76GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
77 uint8_t protocol,
78 uint16_t payload_length,
79 const struct in6_addr *src,
80 const struct in6_addr *dst)
81{
82 GNUNET_assert (40 == sizeof (struct GNUNET_TUN_IPv6Header));
83 GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv6Header));
84 memset (ip, 0, sizeof (struct GNUNET_TUN_IPv6Header));
85 ip->version = 6;
86 ip->next_header = protocol;
87 ip->payload_length = htons ((uint16_t) payload_length);
88 ip->hop_limit = FRESH_TTL;
89 ip->destination_address = *dst;
90 ip->source_address = *src;
91}
92
93
94/**
95 * Calculate IPv4 TCP checksum.
96 *
97 * @param ip ipv4 header fully initialized
98 * @param tcp TCP header (initialized except for CRC)
99 * @param payload the TCP payload
100 * @param payload_length number of bytes of TCP payload
101 */
102void
103GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
104 struct GNUNET_TUN_TcpHeader *tcp,
105 const void *payload,
106 uint16_t payload_length)
107{
108 uint32_t sum;
109 uint16_t tmp;
110
111 GNUNET_assert (20 == sizeof (struct GNUNET_TUN_TcpHeader));
112 GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + sizeof (struct GNUNET_TUN_TcpHeader) ==
113 ntohs (ip->total_length));
114 GNUNET_assert (IPPROTO_TCP == ip->protocol);
115
116 tcp->crc = 0;
117 sum = GNUNET_CRYPTO_crc16_step (0,
118 &ip->source_address,
119 sizeof (struct in_addr) * 2);
120 tmp = htons (IPPROTO_TCP);
121 sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t));
122 tmp = htons (payload_length + sizeof (struct GNUNET_TUN_TcpHeader));
123 sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t));
124 sum = GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof (struct GNUNET_TUN_TcpHeader));
125 sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
126 tcp->crc = GNUNET_CRYPTO_crc16_finish (sum);
127}
128
129
130/**
131 * Calculate IPv6 TCP checksum.
132 *
133 * @param ip ipv6 header fully initialized
134 * @param tcp header (initialized except for CRC)
135 * @param payload the TCP payload
136 * @param payload_length number of bytes of TCP payload
137 */
138void
139GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
140 struct GNUNET_TUN_TcpHeader *tcp,
141 const void *payload,
142 uint16_t payload_length)
143{
144 uint32_t sum;
145 uint32_t tmp;
146
147 GNUNET_assert (20 == sizeof (struct GNUNET_TUN_TcpHeader));
148 GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_TcpHeader) ==
149 ntohs (ip->payload_length));
150 GNUNET_assert (IPPROTO_TCP == ip->next_header);
151 tcp->crc = 0;
152 sum = GNUNET_CRYPTO_crc16_step (0, &ip->source_address, 2 * sizeof (struct in6_addr));
153 tmp = htonl (sizeof (struct GNUNET_TUN_TcpHeader) + payload_length);
154 sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
155 tmp = htonl (IPPROTO_TCP);
156 sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
157 sum = GNUNET_CRYPTO_crc16_step (sum, tcp,
158 sizeof (struct GNUNET_TUN_TcpHeader));
159 sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
160 tcp->crc = GNUNET_CRYPTO_crc16_finish (sum);
161}
162
163
164/**
165 * Calculate IPv4 UDP checksum.
166 *
167 * @param ip ipv4 header fully initialized
168 * @param udp UDP header (initialized except for CRC)
169 * @param payload the UDP payload
170 * @param payload_length number of bytes of UDP payload
171 */
172void
173GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
174 struct GNUNET_TUN_UdpHeader *udp,
175 const void *payload,
176 uint16_t payload_length)
177{
178 uint32_t sum;
179 uint16_t tmp;
180
181 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
182 GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + sizeof (struct GNUNET_TUN_UdpHeader) ==
183 ntohs (ip->total_length));
184 GNUNET_assert (IPPROTO_UDP == ip->protocol);
185
186 udp->crc = 0; /* technically optional, but we calculate it anyway, just to be sure */
187 sum = GNUNET_CRYPTO_crc16_step (0,
188 &ip->source_address,
189 sizeof (struct in_addr) * 2);
190 tmp = htons (IPPROTO_UDP);
191 sum = GNUNET_CRYPTO_crc16_step (sum,
192 &tmp,
193 sizeof (uint16_t));
194 tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + payload_length);
195 sum = GNUNET_CRYPTO_crc16_step (sum,
196 &tmp,
197 sizeof (uint16_t));
198 sum = GNUNET_CRYPTO_crc16_step (sum,
199 udp,
200 sizeof (struct GNUNET_TUN_UdpHeader));
201 sum = GNUNET_CRYPTO_crc16_step (sum,
202 payload,
203 payload_length);
204 udp->crc = GNUNET_CRYPTO_crc16_finish (sum);
205}
206
207
208/**
209 * Calculate IPv6 UDP checksum.
210 *
211 * @param ip ipv6 header fully initialized
212 * @param udp UDP header (initialized except for CRC)
213 * @param payload the UDP payload
214 * @param payload_length number of bytes of UDP payload
215 */
216void
217GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
218 struct GNUNET_TUN_UdpHeader *udp,
219 const void *payload,
220 uint16_t payload_length)
221{
222 uint32_t sum;
223 uint32_t tmp;
224
225 GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_UdpHeader) ==
226 ntohs (ip->payload_length));
227 GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_UdpHeader) ==
228 ntohs (udp->len));
229 GNUNET_assert (IPPROTO_UDP == ip->next_header);
230
231 udp->crc = 0;
232 sum = GNUNET_CRYPTO_crc16_step (0,
233 &ip->source_address,
234 sizeof (struct in6_addr) * 2);
235 tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + payload_length); /* aka udp->len */
236 sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
237 tmp = htons (ip->next_header);
238 sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
239 sum = GNUNET_CRYPTO_crc16_step (sum, udp, sizeof (struct GNUNET_TUN_UdpHeader));
240 sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
241 udp->crc = GNUNET_CRYPTO_crc16_finish (sum);
242}
243
244
245/**
246 * Calculate ICMP checksum.
247 *
248 * @param icmp IMCP header (initialized except for CRC)
249 * @param payload the ICMP payload
250 * @param payload_length number of bytes of ICMP payload
251 */
252void
253GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp,
254 const void *payload,
255 uint16_t payload_length)
256{
257 uint32_t sum;
258
259 GNUNET_assert (8 == sizeof (struct GNUNET_TUN_IcmpHeader));
260 icmp->crc = 0;
261 sum = GNUNET_CRYPTO_crc16_step (0,
262 icmp,
263 sizeof (struct GNUNET_TUN_IcmpHeader));
264 sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
265 icmp->crc = GNUNET_CRYPTO_crc16_finish (sum);
266}
267
268
269/**
270 * Check if two sockaddrs are equal.
271 *
272 * @param sa one address
273 * @param sb another address
274 * @param include_port also check ports
275 * @return #GNUNET_YES if they are equal
276 */
277int
278GNUNET_TUN_sockaddr_cmp (const struct sockaddr *sa,
279 const struct sockaddr *sb,
280 int include_port)
281{
282 if (sa->sa_family != sb->sa_family)
283 return GNUNET_NO;
284
285 switch (sa->sa_family)
286 {
287 case AF_INET:
288 {
289 const struct sockaddr_in *sa4 = (const struct sockaddr_in *) sa;
290 const struct sockaddr_in *sb4 = (const struct sockaddr_in *) sb;
291 return (sa4->sin_addr.s_addr == sb4->sin_addr.s_addr);
292 }
293 case AF_INET6:
294 {
295 const struct sockaddr_in6 *sa6 = (const struct sockaddr_in6 *) sa;
296 const struct sockaddr_in6 *sb6 = (const struct sockaddr_in6 *) sb;
297
298 return (0 == memcmp(&sa6->sin6_addr,
299 &sb6->sin6_addr,
300 sizeof (struct in6_addr)));
301 }
302 default:
303 GNUNET_break (0);
304 return GNUNET_SYSERR;
305 }
306}
307
308
309/* end of tun.c */
diff --git a/src/util/util.conf b/src/util/util.conf
index ceb5fdcbb..dbc2b2e0d 100644
--- a/src/util/util.conf
+++ b/src/util/util.conf
@@ -25,7 +25,7 @@ GNUNET_CACHE_HOME = ${XDG_CACHE_HOME:-$GNUNET_HOME/.cache}/gnunet/
25 25
26# Runtime data (i.e UNIX domain sockets, locks, always lost on system boot) 26# Runtime data (i.e UNIX domain sockets, locks, always lost on system boot)
27# This is the variable for system-wide services; use GNUNET_USER_RUNTIME_DIR 27# This is the variable for system-wide services; use GNUNET_USER_RUNTIME_DIR
28# for per-user services (where USER_SERVICE=YES is set) 28# for per-user services (where RUN_PER_USER=YES is set)
29# Note that the 'gnunet'/system user must have $TMPDIR/$TMP set to 29# Note that the 'gnunet'/system user must have $TMPDIR/$TMP set to
30# exactly the same values as 'normal' users, otherwise this will fail. 30# exactly the same values as 'normal' users, otherwise this will fail.
31# If $TMPDIR or $TMP are set to different directories for different 31# If $TMPDIR or $TMP are set to different directories for different
@@ -36,6 +36,9 @@ GNUNET_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/gnunet-system-runtime/
36# Runtime data for per-user services 36# Runtime data for per-user services
37GNUNET_USER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/gnunet-${USERHOME:-${USER:-user}}-runtime/ 37GNUNET_USER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/gnunet-${USERHOME:-${USER:-user}}-runtime/
38 38
39# Directory to use for temporary files.
40GNUNET_TMP = ${TMPDIR:-${TMP:-/tmp}}/gnunet/
41
39 42
40# Override for GNUNET_HOME used by test cases. 43# Override for GNUNET_HOME used by test cases.
41# GNUNET_TEST_HOME = /tmp/foo/bar 44# GNUNET_TEST_HOME = /tmp/foo/bar
diff --git a/src/util/win.c b/src/util/win.c
index 97877b0ca..511e5d515 100644
--- a/src/util/win.c
+++ b/src/util/win.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 GNUnet e.V. 3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 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/util/winproc.c b/src/util/winproc.c
index 318b68a88..887df2412 100644
--- a/src/util/winproc.c
+++ b/src/util/winproc.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 GNUnet e.V. 3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 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/**