aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/.gitignore3
-rw-r--r--src/include/Makefile.am37
-rw-r--r--src/include/block_dns.h6
-rw-r--r--src/include/block_fs.h6
-rw-r--r--src/include/block_regex.h1
-rw-r--r--src/include/gauger.h1
-rw-r--r--src/include/gettext.h11
-rw-r--r--src/include/gnu_name_system_protocols.h96
-rw-r--r--src/include/gnu_name_system_record_types.h68
-rw-r--r--src/include/gnu_name_system_service_ports.h104
-rw-r--r--src/include/gnunet_abd_service.h38
-rw-r--r--src/include/gnunet_abe_lib.h193
-rw-r--r--src/include/gnunet_applications.h5
-rw-r--r--src/include/gnunet_arm_service.h83
-rw-r--r--src/include/gnunet_ats_application_service.h103
-rw-r--r--src/include/gnunet_ats_plugin.h486
-rw-r--r--src/include/gnunet_ats_service.h624
-rw-r--r--src/include/gnunet_ats_transport_service.h240
-rw-r--r--src/include/gnunet_bandwidth_lib.h12
-rw-r--r--src/include/gnunet_bio_lib.h106
-rw-r--r--src/include/gnunet_block_group_lib.h7
-rw-r--r--src/include/gnunet_block_lib.h261
-rw-r--r--src/include/gnunet_block_plugin.h135
-rw-r--r--src/include/gnunet_buffer_lib.h10
-rw-r--r--src/include/gnunet_cadet_service.h9
-rw-r--r--src/include/gnunet_child_management_lib.h13
-rw-r--r--src/include/gnunet_client_lib.h19
-rw-r--r--src/include/gnunet_common.h558
-rw-r--r--src/include/gnunet_config.h.in58
-rw-r--r--src/include/gnunet_configuration_lib.h319
-rw-r--r--src/include/gnunet_consensus_service.h10
-rw-r--r--src/include/gnunet_container_lib.h525
-rw-r--r--src/include/gnunet_conversation_service.h8
-rw-r--r--src/include/gnunet_core_service.h7
-rw-r--r--src/include/gnunet_crypto_lib.h2239
-rw-r--r--src/include/gnunet_curl_lib.h23
-rw-r--r--src/include/gnunet_datacache_lib.h118
-rw-r--r--src/include/gnunet_datacache_plugin.h81
-rw-r--r--src/include/gnunet_datastore_plugin.h28
-rw-r--r--src/include/gnunet_datastore_service.h6
-rw-r--r--src/include/gnunet_db_lib.h1
-rw-r--r--src/include/gnunet_dht_block_types.h156
-rw-r--r--src/include/gnunet_dht_service.h236
-rw-r--r--src/include/gnunet_dhtu_plugin.h90
-rw-r--r--src/include/gnunet_disk_lib.h14
-rw-r--r--src/include/gnunet_dns_service.h6
-rw-r--r--src/include/gnunet_dnsparser_lib.h98
-rw-r--r--src/include/gnunet_dnsstub_lib.h12
-rw-r--r--src/include/gnunet_error_codes.h242
-rw-r--r--src/include/gnunet_fragmentation_lib.h230
-rw-r--r--src/include/gnunet_friends_lib.h118
-rw-r--r--src/include/gnunet_fs_service.h517
-rw-r--r--src/include/gnunet_getopt_lib.h57
-rw-r--r--src/include/gnunet_gns_service.h27
-rw-r--r--src/include/gnunet_gnsrecord_json_lib.h14
-rw-r--r--src/include/gnunet_gnsrecord_lib.h441
-rw-r--r--src/include/gnunet_gnsrecord_plugin.h22
-rw-r--r--src/include/gnunet_hello_lib.h539
-rw-r--r--src/include/gnunet_hello_uri_lib.h304
-rw-r--r--src/include/gnunet_helper_lib.h27
-rw-r--r--src/include/gnunet_identity_service.h458
-rw-r--r--src/include/gnunet_json_lib.h274
-rw-r--r--src/include/gnunet_load_lib.h6
-rw-r--r--src/include/gnunet_messenger_service.h336
-rw-r--r--src/include/gnunet_mhd_compat.h3
-rw-r--r--src/include/gnunet_microphone_lib.h6
-rw-r--r--src/include/gnunet_mq_lib.h113
-rw-r--r--src/include/gnunet_mst_lib.h23
-rw-r--r--src/include/gnunet_my_lib.h500
-rw-r--r--src/include/gnunet_mysql_lib.h157
-rw-r--r--src/include/gnunet_namecache_plugin.h6
-rw-r--r--src/include/gnunet_namecache_service.h6
-rw-r--r--src/include/gnunet_namestore_plugin.h125
-rw-r--r--src/include/gnunet_namestore_service.h344
-rw-r--r--src/include/gnunet_nat_auto_service.h3
-rw-r--r--src/include/gnunet_nat_service.h20
-rw-r--r--src/include/gnunet_nc_lib.h14
-rw-r--r--src/include/gnunet_network_lib.h25
-rw-r--r--src/include/gnunet_nse_service.h6
-rw-r--r--src/include/gnunet_nt_lib.h12
-rw-r--r--src/include/gnunet_op_lib.h11
-rw-r--r--src/include/gnunet_os_lib.h106
-rw-r--r--src/include/gnunet_peer_lib.h11
-rw-r--r--src/include/gnunet_peerinfo_service.h210
-rw-r--r--src/include/gnunet_peerstore_plugin.h24
-rw-r--r--src/include/gnunet_peerstore_service.h200
-rw-r--r--src/include/gnunet_plugin_lib.h15
-rw-r--r--src/include/gnunet_pq_lib.h786
-rw-r--r--src/include/gnunet_program_lib.h50
-rw-r--r--src/include/gnunet_protocols.h143
-rw-r--r--src/include/gnunet_reclaim_lib.h22
-rw-r--r--src/include/gnunet_reclaim_plugin.h6
-rw-r--r--src/include/gnunet_reclaim_service.h80
-rw-r--r--src/include/gnunet_regex_service.h6
-rw-r--r--src/include/gnunet_resolver_service.h6
-rw-r--r--src/include/gnunet_rest_lib.h6
-rw-r--r--src/include/gnunet_rest_plugin.h27
-rw-r--r--src/include/gnunet_revocation_service.h140
-rw-r--r--src/include/gnunet_rps_service.h5
-rw-r--r--src/include/gnunet_scalarproduct_service.h3
-rw-r--r--src/include/gnunet_scheduler_lib.h7
-rw-r--r--src/include/gnunet_secretsharing_service.h1
-rw-r--r--src/include/gnunet_service_lib.h132
-rw-r--r--src/include/gnunet_set_service.h16
-rw-r--r--src/include/gnunet_seti_service.h6
-rw-r--r--src/include/gnunet_setu_service.h12
-rw-r--r--src/include/gnunet_signal_lib.h10
-rw-r--r--src/include/gnunet_signatures.h194
-rw-r--r--src/include/gnunet_socks.h6
-rw-r--r--src/include/gnunet_speaker_lib.h6
-rw-r--r--src/include/gnunet_sq_lib.h21
-rw-r--r--src/include/gnunet_statistics_service.h6
-rw-r--r--src/include/gnunet_strings_lib.h99
-rw-r--r--src/include/gnunet_testbed_lib.h130
-rw-r--r--src/include/gnunet_testbed_logger_service.h133
-rw-r--r--src/include/gnunet_testbed_service.h1729
-rw-r--r--src/include/gnunet_testing_arm_lib.h47
-rw-r--r--src/include/gnunet_testing_core_lib.h159
-rw-r--r--src/include/gnunet_testing_lib.h1123
-rw-r--r--src/include/gnunet_testing_netjail_lib.h492
-rw-r--r--src/include/gnunet_testing_ng_lib.h769
-rw-r--r--src/include/gnunet_testing_plugin.h83
-rw-r--r--src/include/gnunet_testing_testbed_lib.h42
-rw-r--r--src/include/gnunet_testing_transport_lib.h205
-rw-r--r--src/include/gnunet_time_lib.h278
-rw-r--r--src/include/gnunet_transport_application_service.h13
-rw-r--r--src/include/gnunet_transport_communication_service.h16
-rw-r--r--src/include/gnunet_transport_core_service.h8
-rw-r--r--src/include/gnunet_transport_hello_service.h201
-rw-r--r--src/include/gnunet_transport_manipulation_service.h117
-rw-r--r--src/include/gnunet_transport_monitor_service.h9
-rw-r--r--src/include/gnunet_transport_plugin.h727
-rw-r--r--src/include/gnunet_transport_service.h708
-rw-r--r--src/include/gnunet_tun_lib.h35
-rw-r--r--src/include/gnunet_util_lib.h24
-rw-r--r--src/include/gnunet_vpn_service.h6
-rw-r--r--src/include/meson.build122
-rw-r--r--src/include/platform.h7
138 files changed, 10274 insertions, 11527 deletions
diff --git a/src/include/.gitignore b/src/include/.gitignore
new file mode 100644
index 000000000..76ca45ab4
--- /dev/null
+++ b/src/include/.gitignore
@@ -0,0 +1,3 @@
1!gnunet_config.h.in
2gnunet_config.h
3gnunet_mysql_compat.h
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index e4b02b8ee..ea8bae62f 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -4,23 +4,22 @@ SUBDIRS = .
4gnunetincludedir = $(includedir)/gnunet 4gnunetincludedir = $(includedir)/gnunet
5 5
6EXTRA_DIST = \ 6EXTRA_DIST = \
7 platform.h \
7 gauger.h \ 8 gauger.h \
8 block_fs.h \ 9 block_fs.h \
9 block_dns.h \ 10 block_dns.h \
10 block_regex.h 11 block_regex.h
11 12
12gnunetinclude_HEADERS = \ 13gnunetinclude_HEADERS = \
13 platform.h gettext.h \ 14 gnunet_config.h \
15 gettext.h \
14 compat.h \ 16 compat.h \
15 gnunet_abd_service.h \ 17 gnunet_abd_service.h \
16 gnunet_applications.h \ 18 gnunet_applications.h \
17 gnunet_arm_service.h \ 19 gnunet_arm_service.h \
18 gnunet_ats_service.h \
19 gnunet_ats_application_service.h \
20 gnunet_ats_transport_service.h \
21 gnunet_ats_plugin.h \
22 gnunet_bandwidth_lib.h \ 20 gnunet_bandwidth_lib.h \
23 gnunet_bio_lib.h \ 21 gnunet_bio_lib.h \
22 gnunet_dht_block_types.h \
24 gnunet_block_lib.h \ 23 gnunet_block_lib.h \
25 gnunet_block_group_lib.h \ 24 gnunet_block_group_lib.h \
26 gnunet_block_plugin.h \ 25 gnunet_block_plugin.h \
@@ -47,8 +46,7 @@ gnunetinclude_HEADERS = \
47 gnunet_dnsparser_lib.h \ 46 gnunet_dnsparser_lib.h \
48 gnunet_dnsstub_lib.h \ 47 gnunet_dnsstub_lib.h \
49 gnunet_dns_service.h \ 48 gnunet_dns_service.h \
50 gnunet_fragmentation_lib.h \ 49 gnunet_error_codes.h \
51 gnunet_friends_lib.h \
52 gnunet_fs_service.h \ 50 gnunet_fs_service.h \
53 gnunet_getopt_lib.h \ 51 gnunet_getopt_lib.h \
54 gnunet_gns_service.h \ 52 gnunet_gns_service.h \
@@ -56,10 +54,11 @@ gnunetinclude_HEADERS = \
56 gnunet_gnsrecord_json_lib.h \ 54 gnunet_gnsrecord_json_lib.h \
57 gnunet_gnsrecord_plugin.h \ 55 gnunet_gnsrecord_plugin.h \
58 gnu_name_system_record_types.h \ 56 gnu_name_system_record_types.h \
59 gnunet_hello_lib.h \ 57 gnu_name_system_protocols.h \
58 gnu_name_system_service_ports.h \
59 gnunet_hello_uri_lib.h \
60 gnunet_helper_lib.h \ 60 gnunet_helper_lib.h \
61 gnunet_identity_service.h \ 61 gnunet_identity_service.h \
62 gnunet_abe_lib.h \
63 gnunet_reclaim_lib.h \ 62 gnunet_reclaim_lib.h \
64 gnunet_reclaim_plugin.h \ 63 gnunet_reclaim_plugin.h \
65 gnunet_reclaim_service.h \ 64 gnunet_reclaim_service.h \
@@ -71,8 +70,6 @@ gnunetinclude_HEADERS = \
71 gnunet_microphone_lib.h \ 70 gnunet_microphone_lib.h \
72 gnunet_mst_lib.h \ 71 gnunet_mst_lib.h \
73 gnunet_mq_lib.h \ 72 gnunet_mq_lib.h \
74 gnunet_my_lib.h \
75 gnunet_mysql_lib.h \
76 gnunet_namecache_plugin.h \ 73 gnunet_namecache_plugin.h \
77 gnunet_namecache_service.h \ 74 gnunet_namecache_service.h \
78 gnunet_namestore_plugin.h \ 75 gnunet_namestore_plugin.h \
@@ -83,10 +80,8 @@ gnunetinclude_HEADERS = \
83 gnunet_network_lib.h \ 80 gnunet_network_lib.h \
84 gnunet_nse_service.h \ 81 gnunet_nse_service.h \
85 gnunet_nt_lib.h \ 82 gnunet_nt_lib.h \
86 gnunet_op_lib.h \
87 gnunet_os_lib.h \ 83 gnunet_os_lib.h \
88 gnunet_peer_lib.h \ 84 gnunet_peer_lib.h \
89 gnunet_peerinfo_service.h \
90 gnunet_peerstore_plugin.h \ 85 gnunet_peerstore_plugin.h \
91 gnunet_peerstore_service.h \ 86 gnunet_peerstore_service.h \
92 gnunet_plugin_lib.h \ 87 gnunet_plugin_lib.h \
@@ -113,21 +108,17 @@ gnunetinclude_HEADERS = \
113 gnunet_sq_lib.h \ 108 gnunet_sq_lib.h \
114 gnunet_statistics_service.h \ 109 gnunet_statistics_service.h \
115 gnunet_strings_lib.h \ 110 gnunet_strings_lib.h \
116 gnunet_testbed_service.h \
117 gnunet_testbed_logger_service.h \
118 gnunet_testing_lib.h \ 111 gnunet_testing_lib.h \
119 gnunet_testing_plugin.h \ 112 gnunet_testing_arm_lib.h \
120 gnunet_testing_ng_lib.h \ 113 gnunet_testing_core_lib.h \
121 gnunet_testing_netjail_lib.h \ 114 gnunet_testing_testbed_lib.h \
115 gnunet_testing_transport_lib.h \
116 gnunet_testbed_lib.h \
122 gnunet_time_lib.h \ 117 gnunet_time_lib.h \
123 gnunet_transport_service.h \
124 gnunet_transport_application_service.h \ 118 gnunet_transport_application_service.h \
125 gnunet_transport_communication_service.h \ 119 gnunet_transport_communication_service.h \
126 gnunet_transport_core_service.h \
127 gnunet_transport_hello_service.h \
128 gnunet_transport_manipulation_service.h \
129 gnunet_transport_monitor_service.h \ 120 gnunet_transport_monitor_service.h \
130 gnunet_transport_plugin.h \ 121 gnunet_transport_core_service.h \
131 gnunet_tun_lib.h \ 122 gnunet_tun_lib.h \
132 gnunet_uri_lib.h \ 123 gnunet_uri_lib.h \
133 gnunet_util_lib.h \ 124 gnunet_util_lib.h \
diff --git a/src/include/block_dns.h b/src/include/block_dns.h
index 2186cb1a1..4ac6d0250 100644
--- a/src/include/block_dns.h
+++ b/src/include/block_dns.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup vpn_suite
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -30,6 +33,7 @@
30#ifndef BLOCK_DNS_H 33#ifndef BLOCK_DNS_H
31#define BLOCK_DNS_H 34#define BLOCK_DNS_H
32 35
36
33#include "gnunet_util_lib.h" 37#include "gnunet_util_lib.h"
34 38
35GNUNET_NETWORK_STRUCT_BEGIN 39GNUNET_NETWORK_STRUCT_BEGIN
@@ -65,3 +69,5 @@ GNUNET_NETWORK_STRUCT_END
65#endif 69#endif
66 70
67/** @} */ /* end of group */ 71/** @} */ /* end of group */
72
73/** @} */ /* end of group addition to vpn_suite */
diff --git a/src/include/block_fs.h b/src/include/block_fs.h
index e4caf6e50..b64a83f39 100644
--- a/src/include/block_fs.h
+++ b/src/include/block_fs.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup fs_l2
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -31,6 +34,7 @@
31#ifndef BLOCK_FS_H 34#ifndef BLOCK_FS_H
32#define BLOCK_FS_H 35#define BLOCK_FS_H
33 36
37
34#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
35#include "gnunet_fs_service.h" 39#include "gnunet_fs_service.h"
36 40
@@ -98,3 +102,5 @@ GNUNET_NETWORK_STRUCT_END
98#endif 102#endif
99 103
100/** @} */ /* end of group */ 104/** @} */ /* end of group */
105
106/** @} */ /* end of group addition to fs_l2 */
diff --git a/src/include/block_regex.h b/src/include/block_regex.h
index cc78f2c32..fea19e335 100644
--- a/src/include/block_regex.h
+++ b/src/include/block_regex.h
@@ -36,6 +36,7 @@ extern "C"
36#endif 36#endif
37#endif 37#endif
38 38
39
39#include "gnunet_util_lib.h" 40#include "gnunet_util_lib.h"
40#include <stdint.h> 41#include <stdint.h>
41 42
diff --git a/src/include/gauger.h b/src/include/gauger.h
index 716ce9cb1..f811b335c 100644
--- a/src/include/gauger.h
+++ b/src/include/gauger.h
@@ -11,6 +11,7 @@
11#ifndef __GAUGER_H__ 11#ifndef __GAUGER_H__
12#define __GAUGER_H__ 12#define __GAUGER_H__
13 13
14
14#include <unistd.h> 15#include <unistd.h>
15#include <stdio.h> 16#include <stdio.h>
16#include <sys/wait.h> 17#include <sys/wait.h>
diff --git a/src/include/gettext.h b/src/include/gettext.h
index 458512657..d62a3db7d 100644
--- a/src/include/gettext.h
+++ b/src/include/gettext.h
@@ -20,9 +20,14 @@
20#define _LIBGETTEXT_H 1 20#define _LIBGETTEXT_H 1
21 21
22/* NLS can be disabled through the configure --disable-nls option. */ 22/* NLS can be disabled through the configure --disable-nls option. */
23#ifndef ENABLE_NLS
24#define ENABLE_NLS 0
25#endif
26
23#if ENABLE_NLS 27#if ENABLE_NLS
24 28
25/* Get declarations of GNU message catalog functions. */ 29/* Get declarations of GNU message catalog functions. */
30
26#include <libintl.h> 31#include <libintl.h>
27 32
28#else 33#else
@@ -46,11 +51,11 @@
46#define dgettext(Domainname, Msgid) ((const char *) (Msgid)) 51#define dgettext(Domainname, Msgid) ((const char *) (Msgid))
47#define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid)) 52#define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
48#define ngettext(Msgid1, Msgid2, N) \ 53#define ngettext(Msgid1, Msgid2, N) \
49 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) 54 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
50#define dngettext(Domainname, Msgid1, Msgid2, N) \ 55#define dngettext(Domainname, Msgid1, Msgid2, N) \
51 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) 56 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
52#define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ 57#define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
53 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) 58 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
54/* slight modification here to avoid warnings: generate GNUNET_NO code, 59/* slight modification here to avoid warnings: generate GNUNET_NO code,
55 not even the cast... */ 60 not even the cast... */
56#define textdomain(Domainname) 61#define textdomain(Domainname)
diff --git a/src/include/gnu_name_system_protocols.h b/src/include/gnu_name_system_protocols.h
new file mode 100644
index 000000000..c10eef468
--- /dev/null
+++ b/src/include/gnu_name_system_protocols.h
@@ -0,0 +1,96 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012-2023 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20#ifndef GNUNET_GNS_PROTOCOLS_H
21#define GNUNET_GNS_PROTOCOLS_H
22
23/**
24 * WARNING:
25 * This header is generated!
26 * In order to add GNS service ports, you must register
27 * them in GANA, and then use the header generation script
28 * to create an update of this file. You may then replace this
29 * file with the update.
30 */
31
32#ifdef __cplusplus
33extern "C" {
34#if 0 /* keep Emacsens' auto-indent happy */
35}
36#endif
37#endif
38
39struct GNUNET_GNS_Protocol
40{
41 const char *name;
42
43 uint16_t number;
44};
45
46struct GNUNET_GNS_Protocol GNUNET_GNS_Protocols[] = {
47 /**
48 * LIGHTest trust policy scheme
49 */
50 {
51 .name = "trust",
52 .number = 49152
53 },
54
55 {
56 .name = NULL,
57 .number = 0
58 }
59};
60
61uint16_t
62GNUNET_GNS_protocol_name_to_number (const char *name)
63{
64 int i = 0;
65 while (NULL != GNUNET_GNS_Protocols[i].name)
66 {
67 if (0 == strcmp (name, GNUNET_GNS_Protocols[i].name))
68 return GNUNET_GNS_Protocols[i].number;
69 i++;
70 }
71 return 0;
72}
73
74
75const char*
76GNUNET_GNS_protocol_number_to_name (uint16_t number)
77{
78 int i = 0;
79 while (NULL != GNUNET_GNS_Protocols[i].name)
80 {
81 if (number == GNUNET_GNS_Protocols[i].number)
82 return GNUNET_GNS_Protocols[i].name;
83 i++;
84 }
85 return NULL;
86}
87
88
89#if 0 /* keep Emacsens' auto-indent happy */
90{
91#endif
92#ifdef __cplusplus
93}
94#endif
95
96#endif
diff --git a/src/include/gnu_name_system_record_types.h b/src/include/gnu_name_system_record_types.h
index 22b2c472e..8a62cac11 100644
--- a/src/include/gnu_name_system_record_types.h
+++ b/src/include/gnu_name_system_record_types.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2012-2021 GNUnet e.V. 3 Copyright (C) 2012-2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -38,106 +38,162 @@ extern "C" {
38 38
39 39
40/** 40/**
41 * GNS zone transfer 41 * GNS zone delegation (PKEY)
42 */ 42 */
43#define GNUNET_GNSRECORD_TYPE_PKEY 65536 43#define GNUNET_GNSRECORD_TYPE_PKEY 65536
44 44
45
45/** 46/**
46 * GNS nick names 47 * GNS zone nickname
47 */ 48 */
48#define GNUNET_GNSRECORD_TYPE_NICK 65537 49#define GNUNET_GNSRECORD_TYPE_NICK 65537
49 50
51
50/** 52/**
51 * legacy hostnames 53 * GNS legacy hostname
52 */ 54 */
53#define GNUNET_GNSRECORD_TYPE_LEHO 65538 55#define GNUNET_GNSRECORD_TYPE_LEHO 65538
54 56
57
55/** 58/**
56 * VPN resolution 59 * VPN resolution
57 */ 60 */
58#define GNUNET_GNSRECORD_TYPE_VPN 65539 61#define GNUNET_GNSRECORD_TYPE_VPN 65539
59 62
63
60/** 64/**
61 * Delegation to DNS 65 * Delegation to DNS
62 */ 66 */
63#define GNUNET_GNSRECORD_TYPE_GNS2DNS 65540 67#define GNUNET_GNSRECORD_TYPE_GNS2DNS 65540
64 68
69
65/** 70/**
66 * Boxed records (see TLSA/SRV handling in GNS) 71 * Box record
67 */ 72 */
68#define GNUNET_GNSRECORD_TYPE_BOX 65541 73#define GNUNET_GNSRECORD_TYPE_BOX 65541
69 74
75
70/** 76/**
71 * social place for SecuShare 77 * social place for SecuShare
72 */ 78 */
73#define GNUNET_GNSRECORD_TYPE_PLACE 65542 79#define GNUNET_GNSRECORD_TYPE_PLACE 65542
74 80
81
75/** 82/**
76 * Endpoint for conversation 83 * Endpoint for conversation
77 */ 84 */
78#define GNUNET_GNSRECORD_TYPE_PHONE 65543 85#define GNUNET_GNSRECORD_TYPE_PHONE 65543
79 86
87
80/** 88/**
81 * identity attribute 89 * identity attribute
82 */ 90 */
83#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE 65544 91#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE 65544
84 92
93
85/** 94/**
86 * local ticket reference 95 * local ticket reference
87 */ 96 */
88#define GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET 65545 97#define GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET 65545
89 98
99
100/**
101 * SBox record
102 */
103#define GNUNET_GNSRECORD_TYPE_SBOX 65547
104
105
90/** 106/**
91 * For ABD policies 107 * For ABD policies
92 */ 108 */
93#define GNUNET_GNSRECORD_TYPE_DELEGATE 65548 109#define GNUNET_GNSRECORD_TYPE_DELEGATE 65548
94 110
111
95/** 112/**
96 * For ABD reverse lookups 113 * For ABD reverse lookups
97 */ 114 */
98#define GNUNET_GNSRECORD_TYPE_ATTRIBUTE 65549 115#define GNUNET_GNSRECORD_TYPE_ATTRIBUTE 65549
99 116
117
100/** 118/**
101 * for reclaim records 119 * for reclaim records
102 */ 120 */
103#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF 65550 121#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF 65550
104 122
123
124/**
125 * Redirection record
126 */
127#define GNUNET_GNSRECORD_TYPE_REDIRECT 65551
128
129
105/** 130/**
106 * For reclaim OIDC client names. 131 * For reclaim OIDC client names.
107 */ 132 */
108#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT 65552 133#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT 65552
109 134
135
110/** 136/**
111 * Used reclaimID OIDC client redirect URIs. 137 * Used reclaimID OIDC client redirect URIs.
112 */ 138 */
113#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT 65553 139#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT 65553
114 140
141
115/** 142/**
116 * Record type for an attribute attestation (e.g. JWT). 143 * Record type for an attribute attestation (e.g. JWT).
117 */ 144 */
118#define GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL 65554 145#define GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL 65554
119 146
147
120/** 148/**
121 * Record type for a presentation of a credential. 149 * Record type for a presentation of a credential.
122 */ 150 */
123#define GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION 65555 151#define GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION 65555
124 152
153
125/** 154/**
126 * Record type for EDKEY zone delegations. 155 * GNS zone delegation (EDKEY)
127 */ 156 */
128#define GNUNET_GNSRECORD_TYPE_EDKEY 65556 157#define GNUNET_GNSRECORD_TYPE_EDKEY 65556
129 158
159
130/** 160/**
131 * Encoding for Robust Immutable Storage (ERIS) binary read capability 161 * Encoding for Robust Immutable Storage (ERIS) binary read capability
132 */ 162 */
133#define GNUNET_GNSRECORD_TYPE_ERIS_READ_CAPABILITY 65557 163#define GNUNET_GNSRECORD_TYPE_ERIS_READ_CAPABILITY 65557
134 164
165
135/** 166/**
136 * Record type to share an entry of a messenger room 167 * Record type to share an entry of a messenger room
137 */ 168 */
138#define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY 65558 169#define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY 65558
139 170
140 171
172/**
173 * Record type to indicate a previously delete record (PRIVATE only)
174 */
175#define GNUNET_GNSRECORD_TYPE_TOMBSTONE 65559
176
177
178/**
179 * Record type to store details about a messenger room
180 */
181#define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS 65560
182
183
184/**
185 * Record type to store DID Documents
186 */
187#define GNUNET_GNSRECORD_TYPE_DID_DOCUMENT 65561
188
189
190/**
191 * Private metadata for a delegation registration
192 */
193#define GNUNET_GNSRECORD_TYPE_GNS_REGISTRAR_METADATA 4294901760
194
195
196
141#if 0 /* keep Emacsens' auto-indent happy */ 197#if 0 /* keep Emacsens' auto-indent happy */
142{ 198{
143#endif 199#endif
diff --git a/src/include/gnu_name_system_service_ports.h b/src/include/gnu_name_system_service_ports.h
new file mode 100644
index 000000000..040e598b6
--- /dev/null
+++ b/src/include/gnu_name_system_service_ports.h
@@ -0,0 +1,104 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012-2023 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20#ifndef GNUNET_GNS_SERVICE_PORTS_H
21#define GNUNET_GNS_SERVICE_PORTS_H
22
23/**
24 * WARNING:
25 * This header is generated!
26 * In order to add GNS service ports, you must register
27 * them in GANA, and then use the header generation script
28 * to create an update of this file. You may then replace this
29 * file with the update.
30 */
31
32#ifdef __cplusplus
33extern "C" {
34#if 0 /* keep Emacsens' auto-indent happy */
35}
36#endif
37#endif
38
39struct GNUNET_GNS_ServicePort
40{
41 const char *name;
42
43 uint16_t port;
44};
45
46struct GNUNET_GNS_ServicePort GNUNET_GNS_ServicePorts[] = {
47 /**
48 * Used by Trust Scheme Authorities to publish information about Trust Schemes (LIGHTest)
49 */
50 {
51 .name = "scheme",
52 .port = 49152
53 },
54
55 /**
56 * Used Trust Translation Authorities to publish information about Trust Translations (LIGHTest)
57 */
58 {
59 .name = "translation",
60 .port = 49153
61 },
62
63 {
64 .name = NULL,
65 .port = 0
66 }
67};
68
69uint16_t
70GNUNET_GNS_service_port_name_to_number (const char *name)
71{
72 int i = 0;
73 while (NULL != GNUNET_GNS_ServicePorts[i].name)
74 {
75 if (0 == strcmp (name, GNUNET_GNS_ServicePorts[i].name))
76 return GNUNET_GNS_ServicePorts[i].port;
77 i++;
78 }
79 return 0;
80}
81
82
83const char*
84GNUNET_GNS_service_port_number_to_name (uint16_t port)
85{
86 int i = 0;
87 while (NULL != GNUNET_GNS_ServicePorts[i].name)
88 {
89 if (port == GNUNET_GNS_ServicePorts[i].port)
90 return GNUNET_GNS_ServicePorts[i].name;
91 i++;
92 }
93 return NULL;
94}
95
96
97#if 0 /* keep Emacsens' auto-indent happy */
98{
99#endif
100#ifdef __cplusplus
101}
102#endif
103
104#endif
diff --git a/src/include/gnunet_abd_service.h b/src/include/gnunet_abd_service.h
index afec880f1..cb6e77256 100644
--- a/src/include/gnunet_abd_service.h
+++ b/src/include/gnunet_abd_service.h
@@ -19,19 +19,23 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup reclaim_suite
23 * @{
24 *
22 * @author Martin Schanzenbach 25 * @author Martin Schanzenbach
23 * 26 *
24 * @file 27 * @file
25 * API to the Credential service 28 * API to the Credential service
26 * 29 *
27 * @defgroup abd Credential service 30 * @defgroup abd Credential service
28 * Credentials 31 * Credential service for Attribute-Based Decryption
29 * 32 *
30 * @{ 33 * @{
31 */ 34 */
32#ifndef GNUNET_ABD_SERVICE_H 35#ifndef GNUNET_ABD_SERVICE_H
33#define GNUNET_ABD_SERVICE_H 36#define GNUNET_ABD_SERVICE_H
34 37
38
35#include "gnunet_util_lib.h" 39#include "gnunet_util_lib.h"
36#include "gnunet_gns_service.h" 40#include "gnunet_gns_service.h"
37#include "gnunet_identity_service.h" 41#include "gnunet_identity_service.h"
@@ -103,7 +107,7 @@ struct GNUNET_ABD_DelegationRecordSet
103 /** 107 /**
104 * Public key of the subject this attribute was delegated to 108 * Public key of the subject this attribute was delegated to
105 */ 109 */
106 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key; 110 struct GNUNET_CRYPTO_PublicKey subject_key;
107 111
108 /** 112 /**
109 * Length of attribute, may be 0 113 * Length of attribute, may be 0
@@ -123,7 +127,7 @@ struct GNUNET_ABD_DelegationSet
123 /** 127 /**
124 * Public key of the subject this attribute was delegated to 128 * Public key of the subject this attribute was delegated to
125 */ 129 */
126 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key; 130 struct GNUNET_CRYPTO_PublicKey subject_key;
127 131
128 uint32_t subject_attribute_len; 132 uint32_t subject_attribute_len;
129 133
@@ -143,12 +147,12 @@ struct GNUNET_ABD_Delegation
143 /** 147 /**
144 * The issuer of the delegation 148 * The issuer of the delegation
145 */ 149 */
146 struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key; 150 struct GNUNET_CRYPTO_PublicKey issuer_key;
147 151
148 /** 152 /**
149 * Public key of the subject this attribute was delegated to 153 * Public key of the subject this attribute was delegated to
150 */ 154 */
151 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key; 155 struct GNUNET_CRYPTO_PublicKey subject_key;
152 156
153 /** 157 /**
154 * Length of the attribute 158 * Length of the attribute
@@ -181,17 +185,17 @@ struct GNUNET_ABD_Delegate
181 /** 185 /**
182 * The issuer of the credential 186 * The issuer of the credential
183 */ 187 */
184 struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key; 188 struct GNUNET_CRYPTO_PublicKey issuer_key;
185 189
186 /** 190 /**
187 * Public key of the subject this credential was issued to 191 * Public key of the subject this credential was issued to
188 */ 192 */
189 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key; 193 struct GNUNET_CRYPTO_PublicKey subject_key;
190 194
191 /** 195 /**
192 * Signature of this credential 196 * Signature of this credential
193 */ 197 */
194 struct GNUNET_CRYPTO_EcdsaSignature signature; 198 struct GNUNET_CRYPTO_Signature signature;
195 199
196 /** 200 /**
197 * Expiration of this credential 201 * Expiration of this credential
@@ -318,9 +322,9 @@ typedef void (*GNUNET_ABD_RemoveDelegateResultProcessor) (void *cls,
318 */ 322 */
319struct GNUNET_ABD_Request* 323struct GNUNET_ABD_Request*
320 GNUNET_ABD_verify (struct GNUNET_ABD_Handle *handle, 324 GNUNET_ABD_verify (struct GNUNET_ABD_Handle *handle,
321 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key, 325 const struct GNUNET_CRYPTO_PublicKey *issuer_key,
322 const char *issuer_attribute, 326 const char *issuer_attribute,
323 const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key, 327 const struct GNUNET_CRYPTO_PublicKey *subject_key,
324 uint32_t delegate_count, 328 uint32_t delegate_count,
325 const struct GNUNET_ABD_Delegate *delegates, 329 const struct GNUNET_ABD_Delegate *delegates,
326 enum GNUNET_ABD_AlgoDirectionFlags direction, 330 enum GNUNET_ABD_AlgoDirectionFlags direction,
@@ -331,9 +335,9 @@ struct GNUNET_ABD_Request*
331 335
332struct GNUNET_ABD_Request* 336struct GNUNET_ABD_Request*
333 GNUNET_ABD_collect (struct GNUNET_ABD_Handle *handle, 337 GNUNET_ABD_collect (struct GNUNET_ABD_Handle *handle,
334 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key, 338 const struct GNUNET_CRYPTO_PublicKey *issuer_key,
335 const char *issuer_attribute, 339 const char *issuer_attribute,
336 const struct GNUNET_CRYPTO_EcdsaPrivateKey *subject_key, 340 const struct GNUNET_CRYPTO_PrivateKey *subject_key,
337 enum GNUNET_ABD_AlgoDirectionFlags direction, 341 enum GNUNET_ABD_AlgoDirectionFlags direction,
338 GNUNET_ABD_CredentialResultProcessor proc, 342 GNUNET_ABD_CredentialResultProcessor proc,
339 void *proc_cls, 343 void *proc_cls,
@@ -356,7 +360,7 @@ struct GNUNET_ABD_Request *
356GNUNET_ABD_add_delegation (struct GNUNET_ABD_Handle *handle, 360GNUNET_ABD_add_delegation (struct GNUNET_ABD_Handle *handle,
357 struct GNUNET_IDENTITY_Ego *issuer, 361 struct GNUNET_IDENTITY_Ego *issuer,
358 const char *attribute, 362 const char *attribute,
359 struct GNUNET_CRYPTO_EcdsaPublicKey *subject, 363 struct GNUNET_CRYPTO_PublicKey *subject,
360 const char *delegated_attribute, 364 const char *delegated_attribute,
361 GNUNET_ABD_DelegateResultProcessor proc, 365 GNUNET_ABD_DelegateResultProcessor proc,
362 void *proc_cls); 366 void *proc_cls);
@@ -384,13 +388,13 @@ GNUNET_ABD_remove_delegation (struct GNUNET_ABD_Handle *handle,
384 * 388 *
385 * @param issuer the ego that should be used to issue the attribute 389 * @param issuer the ego that should be used to issue the attribute
386 * @param subject the subject of the attribute 390 * @param subject the subject of the attribute
387 * @param attribute the name of the attribute 391 * @param iss_attr the name of the attribute
388 * @param expiration the TTL of the credential 392 * @param expiration the TTL of the credential
389 * @return handle to the queued request 393 * @return handle to the queued request
390 */ 394 */
391struct GNUNET_ABD_Delegate* 395struct GNUNET_ABD_Delegate*
392GNUNET_ABD_delegate_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, 396GNUNET_ABD_delegate_issue (const struct GNUNET_CRYPTO_PrivateKey *issuer,
393 struct GNUNET_CRYPTO_EcdsaPublicKey *subject, 397 struct GNUNET_CRYPTO_PublicKey *subject,
394 const char *iss_attr, 398 const char *iss_attr,
395 const char *sub_attr, 399 const char *sub_attr,
396 struct GNUNET_TIME_Absolute *expiration); 400 struct GNUNET_TIME_Absolute *expiration);
@@ -415,3 +419,5 @@ GNUNET_ABD_request_cancel (struct GNUNET_ABD_Request *lr);
415#endif 419#endif
416 420
417/** @} */ /* end of group */ 421/** @} */ /* end of group */
422
423/** @} */ /* end of group addition to reclaim_suite */
diff --git a/src/include/gnunet_abe_lib.h b/src/include/gnunet_abe_lib.h
deleted file mode 100644
index 7aeb3520d..000000000
--- a/src/include/gnunet_abe_lib.h
+++ /dev/null
@@ -1,193 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001-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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file include/gnunet_abe_lib.h
23 * @brief Attribute-Based Encryption primitives for GNUnet
24 *
25 * @author Martin Schanzenbach
26 *
27 * @defgroup abe ABE Crypto library: Attribute-Based Encryption operations
28 *
29 */
30#ifndef GNUNET_ABE_LIB_H
31#define GNUNET_ABE_LIB_H
32
33#ifdef __cplusplus
34extern "C"
35{
36#if 0 /* keep Emacsens' auto-indent happy */
37}
38#endif
39#endif
40
41#include "gnunet_common.h"
42#include <gcrypt.h>
43
44/**
45 * @brief type for ABE master keys
46 */
47struct GNUNET_CRYPTO_AbeMasterKey;
48
49/**
50 * @brief type for ABE keys
51 */
52struct GNUNET_CRYPTO_AbeKey;
53
54
55/**
56 * @ingroup abe
57 * Create a new CP-ABE master key. Caller must free return value.
58 *
59 * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_master_key
60 */
61struct GNUNET_ABE_AbeMasterKey *
62GNUNET_ABE_cpabe_create_master_key (void);
63
64/**
65 * @ingroup abe
66 * Delete a CP-ABE master key.
67 *
68 * @param key the master key
69 * @return fresh private key; free using #GNUNET_free
70 */
71void
72GNUNET_ABE_cpabe_delete_master_key (struct GNUNET_ABE_AbeMasterKey *key);
73
74/**
75 * @ingroup abe
76 * Create a new CP-ABE key. Caller must free return value.
77 *
78 * @param key the master key
79 * @param attrs the attributes to append to the key
80 * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_key
81 */
82struct GNUNET_ABE_AbeKey *
83GNUNET_ABE_cpabe_create_key (struct GNUNET_ABE_AbeMasterKey *key,
84 char **attrs);
85
86/**
87 * @ingroup abe
88 * Delete a CP-ABE key.
89 *
90 * @param key the key to delete
91 * @param delete_pub GNUNET_YES if the public key should also be freed (bug in gabe)
92 * @return fresh private key; free using #GNUNET_free
93 */
94void
95GNUNET_ABE_cpabe_delete_key (struct GNUNET_ABE_AbeKey *key,
96 int delete_pub);
97
98
99/**
100 * @ingroup abe
101 * Encrypt a block using sessionkey.
102 *
103 * @param block the block to encrypt
104 * @param size the size of the @a block
105 * @param policy the ABE policy
106 * @param key the key used to encrypt
107 * @param result the result buffer. Will be allocated. Free using #GNUNET_free
108 * @return the size of the encrypted block, -1 for errors
109 */
110ssize_t
111GNUNET_ABE_cpabe_encrypt (const void *block,
112 size_t size,
113 const char *policy,
114 const struct GNUNET_ABE_AbeMasterKey *key,
115 void **result);
116
117/**
118 * @ingroup abe
119 * Decrypt a block using the ABE key.
120 *
121 * @param block the block to encrypt
122 * @param size the size of the @a block
123 * @param key the key used to decrypt
124 * @param result the result buffer. Will be allocated. Free using #GNUNET_free
125 * @return the size of the encrypted block, -1 for errors
126 */
127ssize_t
128GNUNET_ABE_cpabe_decrypt (const void *block,
129 size_t size,
130 const struct GNUNET_ABE_AbeKey *key,
131 void **result);
132
133/**
134 * @ingroup abe
135 * Serialize an ABE key.
136 *
137 * @param key the key to serialize
138 * @param result the result buffer. Will be allocated. Free using #GNUNET_free
139 * @return the size of the encrypted block, -1 for errors
140 */
141ssize_t
142GNUNET_ABE_cpabe_serialize_key (const struct GNUNET_ABE_AbeKey *key,
143 void **result);
144
145/**
146 * @ingroup abe
147 * Deserialize a serialized ABE key.
148 *
149 * @param data the data to deserialize
150 * @param len the length of the data.
151 * @return the ABE key. NULL of unsuccessful
152 */
153struct GNUNET_ABE_AbeKey*
154GNUNET_ABE_cpabe_deserialize_key (const void *data,
155 size_t len);
156
157/**
158 * @ingroup abe
159 * Serialize an ABE master key.
160 *
161 * @param key the key to serialize
162 * @param result the result buffer. Will be allocated. Free using #GNUNET_free
163 * @return the size of the encrypted block, -1 for errors
164 */
165ssize_t
166GNUNET_ABE_cpabe_serialize_master_key (const struct
167 GNUNET_ABE_AbeMasterKey *key,
168 void **result);
169
170/**
171 * @ingroup abe
172 * Deserialize an ABE master key.
173 *
174 * @param data the data to deserialize
175 * @param len the length of the data.
176 * @return the ABE key. NULL of unsuccessful
177 */
178struct GNUNET_ABE_AbeMasterKey*
179GNUNET_ABE_cpabe_deserialize_master_key (const void *data,
180 size_t len);
181
182
183#if 0 /* keep Emacsens' auto-indent happy */
184{
185#endif
186#ifdef __cplusplus
187}
188#endif
189
190
191/* ifndef GNUNET_ABE_LIB_H */
192#endif
193/* end of gnunet_abe_lib.h */
diff --git a/src/include/gnunet_applications.h b/src/include/gnunet_applications.h
index 1e2ac59f7..489dc7050 100644
--- a/src/include/gnunet_applications.h
+++ b/src/include/gnunet_applications.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Backbone
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -133,4 +136,6 @@ extern "C"
133 136
134/** @} */ /* end of group */ 137/** @} */ /* end of group */
135 138
139/** @} */ /* end of group addition to Backbone */
140
136/* end of gnunet_applications.h */ 141/* end of gnunet_applications.h */
diff --git a/src/include/gnunet_arm_service.h b/src/include/gnunet_arm_service.h
index 9615f8c9d..ef860bff4 100644
--- a/src/include/gnunet_arm_service.h
+++ b/src/include/gnunet_arm_service.h
@@ -43,6 +43,7 @@ extern "C"
43#endif 43#endif
44#endif 44#endif
45 45
46
46#include "gnunet_util_lib.h" 47#include "gnunet_util_lib.h"
47 48
48/** 49/**
@@ -243,8 +244,9 @@ struct GNUNET_ARM_Operation;
243 * #GNUNET_SYSERR if there was an error. 244 * #GNUNET_SYSERR if there was an error.
244 */ 245 */
245typedef void 246typedef void
246(*GNUNET_ARM_ConnectionStatusCallback) (void *cls, 247(*GNUNET_ARM_ConnectionStatusCallback) (
247 int connected); 248 void *cls,
249 enum GNUNET_GenericReturnValue connected);
248 250
249 251
250/** 252/**
@@ -258,9 +260,10 @@ typedef void
258 * @param result result of the operation 260 * @param result result of the operation
259 */ 261 */
260typedef void 262typedef void
261(*GNUNET_ARM_ResultCallback) (void *cls, 263(*GNUNET_ARM_ResultCallback) (
262 enum GNUNET_ARM_RequestStatus rs, 264 void *cls,
263 enum GNUNET_ARM_Result result); 265 enum GNUNET_ARM_RequestStatus rs,
266 enum GNUNET_ARM_Result result);
264 267
265 268
266/** 269/**
@@ -275,10 +278,11 @@ typedef void
275 * @param list list of services managed by arm 278 * @param list list of services managed by arm
276 */ 279 */
277typedef void 280typedef void
278(*GNUNET_ARM_ServiceListCallback) (void *cls, 281(*GNUNET_ARM_ServiceListCallback) (
279 enum GNUNET_ARM_RequestStatus rs, 282 void *cls,
280 unsigned int count, 283 enum GNUNET_ARM_RequestStatus rs,
281 const struct GNUNET_ARM_ServiceInfo *list); 284 unsigned int count,
285 const struct GNUNET_ARM_ServiceInfo *list);
282 286
283 287
284/** 288/**
@@ -293,18 +297,20 @@ typedef void
293 * @return context to use for further ARM operations, NULL on error. 297 * @return context to use for further ARM operations, NULL on error.
294 */ 298 */
295struct GNUNET_ARM_Handle * 299struct GNUNET_ARM_Handle *
296GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 300GNUNET_ARM_connect (
297 GNUNET_ARM_ConnectionStatusCallback conn_status, 301 const struct GNUNET_CONFIGURATION_Handle *cfg,
298 void *conn_status_cls); 302 GNUNET_ARM_ConnectionStatusCallback conn_status,
303 void *conn_status_cls);
299 304
300 305
301/** 306/**
302 * Disconnect from the ARM service and destroy the handle. 307 * Disconnect from the ARM service and destroy the handle.
303 * 308 *
304 * @param h the handle that was being used 309 * @param[in] h the handle that was being used
305 */ 310 */
306void 311void
307GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h); 312GNUNET_ARM_disconnect (
313 struct GNUNET_ARM_Handle *h);
308 314
309 315
310/** 316/**
@@ -314,7 +320,8 @@ GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h);
314 * @param op operation to cancel 320 * @param op operation to cancel
315 */ 321 */
316void 322void
317GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op); 323GNUNET_ARM_operation_cancel (
324 struct GNUNET_ARM_Operation *op);
318 325
319 326
320/** 327/**
@@ -326,9 +333,10 @@ GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op);
326 * @return handle for the operation, NULL on error 333 * @return handle for the operation, NULL on error
327 */ 334 */
328struct GNUNET_ARM_Operation * 335struct GNUNET_ARM_Operation *
329GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h, 336GNUNET_ARM_request_service_list (
330 GNUNET_ARM_ServiceListCallback cont, 337 struct GNUNET_ARM_Handle *h,
331 void *cont_cls); 338 GNUNET_ARM_ServiceListCallback cont,
339 void *cont_cls);
332 340
333 341
334/** 342/**
@@ -346,10 +354,11 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
346 * @return handle for the operation, NULL on error 354 * @return handle for the operation, NULL on error
347 */ 355 */
348struct GNUNET_ARM_Operation * 356struct GNUNET_ARM_Operation *
349GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, 357GNUNET_ARM_request_service_stop (
350 const char *service_name, 358 struct GNUNET_ARM_Handle *h,
351 GNUNET_ARM_ResultCallback cont, 359 const char *service_name,
352 void *cont_cls); 360 GNUNET_ARM_ResultCallback cont,
361 void *cont_cls);
353 362
354 363
355/** 364/**
@@ -363,12 +372,12 @@ GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
363 * @return handle for the operation, NULL on error 372 * @return handle for the operation, NULL on error
364 */ 373 */
365struct GNUNET_ARM_Operation * 374struct GNUNET_ARM_Operation *
366GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, 375GNUNET_ARM_request_service_start (
367 const char *service_name, 376 struct GNUNET_ARM_Handle *h,
368 enum GNUNET_OS_InheritStdioFlags 377 const char *service_name,
369 std_inheritance, 378 enum GNUNET_OS_InheritStdioFlags std_inheritance,
370 GNUNET_ARM_ResultCallback cont, 379 GNUNET_ARM_ResultCallback cont,
371 void *cont_cls); 380 void *cont_cls);
372 381
373 382
374/** 383/**
@@ -385,10 +394,10 @@ struct GNUNET_ARM_MonitorHandle;
385 * @param status status of the service 394 * @param status status of the service
386 */ 395 */
387typedef void 396typedef void
388(*GNUNET_ARM_ServiceMonitorCallback) (void *cls, 397(*GNUNET_ARM_ServiceMonitorCallback) (
389 const char *service, 398 void *cls,
390 enum GNUNET_ARM_ServiceMonitorStatus 399 const char *service,
391 status); 400 enum GNUNET_ARM_ServiceMonitorStatus status);
392 401
393 402
394/** 403/**
@@ -403,9 +412,10 @@ typedef void
403 * @return context to use for further ARM monitor operations, NULL on error. 412 * @return context to use for further ARM monitor operations, NULL on error.
404 */ 413 */
405struct GNUNET_ARM_MonitorHandle * 414struct GNUNET_ARM_MonitorHandle *
406GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 415GNUNET_ARM_monitor_start (
407 GNUNET_ARM_ServiceMonitorCallback cont, 416 const struct GNUNET_CONFIGURATION_Handle *cfg,
408 void *cont_cls); 417 GNUNET_ARM_ServiceMonitorCallback cont,
418 void *cont_cls);
409 419
410 420
411/** 421/**
@@ -414,7 +424,8 @@ GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
414 * @param h the handle that was being used 424 * @param h the handle that was being used
415 */ 425 */
416void 426void
417GNUNET_ARM_monitor_stop (struct GNUNET_ARM_MonitorHandle *h); 427GNUNET_ARM_monitor_stop (
428 struct GNUNET_ARM_MonitorHandle *h);
418 429
419#if 0 /* keep Emacsens' auto-indent happy */ 430#if 0 /* keep Emacsens' auto-indent happy */
420{ 431{
diff --git a/src/include/gnunet_ats_application_service.h b/src/include/gnunet_ats_application_service.h
deleted file mode 100644
index a48dba825..000000000
--- a/src/include/gnunet_ats_application_service.h
+++ /dev/null
@@ -1,103 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010-2015, 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file
22 * Bandwidth allocation API for applications to interact with
23 *
24 * @author Christian Grothoff
25 * @author Matthias Wachs
26 *
27 * @defgroup ats ATS service
28 * Bandwidth allocation
29 *
30 * @see [Documentation](https://gnunet.org/ats-subsystem)
31 *
32 * @{
33 */
34#ifndef GNUNET_ATS_APPLICATION_SERVICE_H
35#define GNUNET_ATS_APPLICATION_SERVICE_H
36
37#include "gnunet_constants.h"
38#include "gnunet_util_lib.h"
39
40/**
41 * Handle to the ATS subsystem for making suggestions about
42 * connections the peer would like to have.
43 */
44struct GNUNET_ATS_ApplicationHandle;
45
46
47/**
48 * Initialize the ATS application client handle.
49 *
50 * @param cfg configuration to use
51 * @return ats application handle, NULL on error
52 */
53struct GNUNET_ATS_ApplicationHandle *
54GNUNET_ATS_application_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
55
56
57/**
58 * Shutdown ATS application client.
59 *
60 * @param ch handle to destroy
61 */
62void
63GNUNET_ATS_application_done (struct GNUNET_ATS_ApplicationHandle *ch);
64
65
66/**
67 * Handle for suggestion requests.
68 */
69struct GNUNET_ATS_ApplicationSuggestHandle;
70
71
72/**
73 * An application would like to communicate with a peer. ATS should
74 * allocate bandwidth using a suitable address for requiremetns @a pk
75 * to transport.
76 *
77 * @param ch handle
78 * @param peer identity of the peer we need an address for
79 * @param pk what kind of application will the application require (can be
80 * #GNUNET_MQ_PREFERENCE_NONE, we will still try to connect)
81 * @param bw desired bandwidth, can be zero (we will still try to connect)
82 * @return suggestion handle, NULL if request is already pending
83 */
84struct GNUNET_ATS_ApplicationSuggestHandle *
85GNUNET_ATS_application_suggest (struct GNUNET_ATS_ApplicationHandle *ch,
86 const struct GNUNET_PeerIdentity *peer,
87 enum GNUNET_MQ_PreferenceKind pk,
88 struct GNUNET_BANDWIDTH_Value32NBO bw);
89
90
91/**
92 * We no longer care about communicating with a peer.
93 *
94 * @param sh handle
95 */
96void
97GNUNET_ATS_application_suggest_cancel (struct
98 GNUNET_ATS_ApplicationSuggestHandle *sh);
99
100/** @} */ /* end of group */
101
102#endif
103/* end of file gnunet_ats_application_service.h */
diff --git a/src/include/gnunet_ats_plugin.h b/src/include/gnunet_ats_plugin.h
deleted file mode 100644
index c0662673c..000000000
--- a/src/include/gnunet_ats_plugin.h
+++ /dev/null
@@ -1,486 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2009-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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 *
24 * @file
25 * API for the ATS solvers.
26 *
27 * @defgroup ats-plugin ATS service plugin API
28 * Plugin API for the ATS service.
29 *
30 * Specifies the struct that is given to the plugin's entry method and the other
31 * struct that must be returned. Note that the destructors of ATS plugins will
32 * be given the value returned by the constructor and is expected to return a
33 * NULL pointer.
34 *
35 * @{
36 */
37#ifndef PLUGIN_ATS_H
38#define PLUGIN_ATS_H
39
40#include "gnunet_ats_service.h"
41#include "gnunet_statistics_service.h"
42
43/**
44 * Representation of an address the plugin can choose from.
45 */
46struct ATS_Address;
47
48/**
49 * Change the preference for a peer
50 *
51 * @param handle the solver handle
52 * @param client the client sending this request
53 * @param peer the peer id
54 * @param kind the preference kind to change
55 * @param score the new preference score
56 * @param pref_rel the normalized preference value for this kind over all clients
57 */
58typedef void
59(*GAS_solver_address_change_preference) (void *solver,
60 const struct GNUNET_PeerIdentity *peer,
61 enum GNUNET_ATS_PreferenceKind kind,
62 double pref_rel);
63
64
65/**
66 * Give feedback about the current assignment
67 *
68 * @param handle the solver handle
69 * @param application the application sending this request
70 * @param peer the peer id
71 * @param scope the time interval for this feedback: [now - scope .. now]
72 * @param kind the preference kind for this feedback
73 * @param score the feedback score
74 */
75typedef void
76(*GAS_solver_address_feedback_preference) (void *solver,
77 struct GNUNET_SERVICE_Client *
78 application,
79 const struct
80 GNUNET_PeerIdentity *peer,
81 const struct GNUNET_TIME_Relative
82 scope,
83 enum GNUNET_ATS_PreferenceKind kind,
84 double score);
85
86/**
87 * Notify the solver about a bulk operation changing possibly a lot of values
88 * Solver will not resolve until all bulk operations are marked as done
89 *
90 * @param solver the solver
91 */
92typedef void
93(*GAS_solver_bulk_start) (void *solver);
94
95
96/**
97 * Mark a bulk operation as done
98 * Solver will resolve if values have changed
99 *
100 * @param solver the solver
101 */
102typedef void
103(*GAS_solver_bulk_stop) (void *solver);
104
105
106/**
107 * Add a single address within a network to the solver
108 *
109 * @param solver the solver Handle
110 * @param address the address to add
111 * @param network network type of this address
112 */
113typedef void
114(*GAS_solver_address_add) (void *solver,
115 struct ATS_Address *address,
116 uint32_t network);
117
118
119/**
120 * Delete an address or just the session from the solver
121 *
122 * @param solver the solver Handle
123 * @param address the address to delete
124 */
125typedef void
126(*GAS_solver_address_delete) (void *solver,
127 struct ATS_Address *address);
128
129
130/**
131 * Transport properties for this address have changed
132 *
133 * @param solver solver handle
134 * @param address the address
135 */
136typedef void
137(*GAS_solver_address_property_changed) (void *solver,
138 struct ATS_Address *address);
139
140
141/**
142 * Get the preferred address for a peer from solver
143 *
144 * @param solver the solver to use
145 * @param peer the peer
146 */
147typedef void
148(*GAS_solver_get_preferred_address) (void *solver,
149 const struct GNUNET_PeerIdentity *peer);
150
151
152/**
153 * Stop getting the preferred address for a peer from solver
154 *
155 * @param solver the solver to use
156 * @param peer the peer
157 */
158typedef void
159(*GAS_solver_stop_get_preferred_address) (void *solver,
160 const struct
161 GNUNET_PeerIdentity *peer);
162
163
164/**
165 * Solver functions.
166 *
167 * Each solver is required to set up and return an instance
168 * of this struct during initialization.
169 */
170struct GNUNET_ATS_SolverFunctions
171{
172 /**
173 * Closure to pass to all solver functions in this struct.
174 */
175 void *cls;
176
177 /**
178 * Add a new address for a peer to the solver
179 *
180 * The address is already contained in the addresses hashmap!
181 */
182 GAS_solver_address_add s_add;
183
184 /**
185 * Update the properties of an address in the solver
186 */
187 GAS_solver_address_property_changed s_address_update_property;
188
189 /**
190 * Tell solver to notify ATS if the address to use changes for a specific
191 * peer using the bandwidth changed callback
192 *
193 * The solver must only notify about changes for peers with pending address
194 * requests!
195 */
196 GAS_solver_get_preferred_address s_get;
197
198 /**
199 * Tell solver stop notifying ATS about changes for this peers
200 *
201 * The solver must only notify about changes for peers with pending address
202 * requests!
203 */
204 GAS_solver_stop_get_preferred_address s_get_stop;
205
206 /**
207 * Delete an address in the solver
208 *
209 * The address is not contained in the address hashmap anymore!
210 */
211 GAS_solver_address_delete s_del;
212
213 /**
214 * Change relative preference for quality in solver
215 */
216 GAS_solver_address_change_preference s_pref;
217
218 /**
219 * Give feedback about the current assignment
220 */
221 GAS_solver_address_feedback_preference s_feedback;
222
223 /**
224 * Start a bulk operation
225 *
226 * Used if many values have to be updated at the same time.
227 * When a bulk operation is pending the solver does not have to resolve
228 * the problem since more updates will follow anyway
229 *
230 * For each call to bulk_start, a call to bulk_stop is required!
231 */
232 GAS_solver_bulk_start s_bulk_start;
233
234 /**
235 * Bulk operation done
236 *
237 * If no more bulk operations are pending, the solver can solve the problem
238 * with the updated values
239 */
240 GAS_solver_bulk_stop s_bulk_stop;
241};
242
243
244/**
245 * Operation codes for solver information callback
246 *
247 * Order of calls is expected to be:
248 * #GAS_OP_SOLVE_START
249 * #GAS_OP_SOLVE_STOP
250 * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_START
251 * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
252 *
253 */
254enum GAS_Solver_Operation
255{
256 /**
257 * A solution iteration has been started
258 */
259 GAS_OP_SOLVE_START,
260
261 /**
262 * A solution iteration has been finished
263 */
264 GAS_OP_SOLVE_STOP,
265
266 /**
267 * The setup of the problem as a preparation to solve it was started
268 */
269 GAS_OP_SOLVE_SETUP_START,
270
271 /**
272 * The setup of the problem as a preparation to solve is finished
273 */
274 GAS_OP_SOLVE_SETUP_STOP,
275
276 /**
277 * Solving of the LP problem was started
278 * MLP solver only
279 */
280 GAS_OP_SOLVE_MLP_LP_START,
281
282 /**
283 * Solving of the LP problem is done
284 * MLP solver only
285 */
286 GAS_OP_SOLVE_MLP_LP_STOP,
287
288 /**
289 * Solving of the MLP problem was started
290 * MLP solver only
291 */
292 GAS_OP_SOLVE_MLP_MLP_START,
293
294 /**
295 * Solving of the MLP problem is done
296 * MLP solver only
297 */
298 GAS_OP_SOLVE_MLP_MLP_STOP,
299
300 /**
301 * After the problem was finished, start notifications about changes
302 * to addresses
303 */
304 GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
305
306 /**
307 * After the problem was finished, notifications about changes to addresses
308 * are done
309 */
310 GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
311};
312
313
314/**
315 * Status of a GAS_Solver_Operation operation
316 */
317enum GAS_Solver_Status
318{
319 /**
320 * Success
321 */
322 GAS_STAT_SUCCESS,
323
324 /**
325 * Failure
326 */
327 GAS_STAT_FAIL
328};
329
330
331/**
332 * Status of the operation
333 */
334enum GAS_Solver_Additional_Information
335{
336 /**
337 * No more specific information
338 */
339 GAS_INFO_NONE,
340
341 /**
342 * A full solution process is performed
343 * Quite specific to the MLP solver
344 */
345 GAS_INFO_FULL,
346
347 /**
348 * An existing solution was reused
349 * Quite specific to the MLP solver
350 */
351 GAS_INFO_UPDATED,
352
353 /**
354 * The proportional solver had to recalculate for a single network
355 */
356 GAS_INFO_PROP_SINGLE,
357
358 /**
359 * The proportional solver had to recalculate for all networks
360 */
361 GAS_INFO_PROP_ALL
362};
363
364
365/**
366 * Callback to call with additional information
367 * Used for measurement
368 *
369 * @param cls the closure
370 * @param op the operation
371 */
372typedef void
373(*GAS_solver_information_callback) (void *cls,
374 enum GAS_Solver_Operation op,
375 enum GAS_Solver_Status stat,
376 enum GAS_Solver_Additional_Information);
377
378
379/**
380 * Callback to call from solver when bandwidth for address has changed
381 *
382 * @param address the with changed bandwidth assigned
383 */
384typedef void
385(*GAS_bandwidth_changed_cb) (void *cls,
386 struct ATS_Address *address);
387
388
389/**
390 * Callback to call from solver to obtain application preference
391 * values for a peer.
392 *
393 * @param cls the cls
394 * @param id the peer id
395 * @return carry of double values containing the preferences with
396 * GNUNET_ATS_PreferenceCount elements
397 */
398typedef const double *
399(*GAS_get_preferences) (void *cls,
400 const struct GNUNET_PeerIdentity *id);
401
402
403/**
404 * Callback to call from solver to obtain application connectivity
405 * preferences for a peer.
406 *
407 * @param cls the cls
408 * @param id the peer id
409 * @return 0 if connectivity is not desired, non-null if address
410 * suggestions are requested
411 */
412typedef unsigned int
413(*GAS_get_connectivity) (void *cls,
414 const struct GNUNET_PeerIdentity *id);
415
416
417/**
418 * The ATS plugin will pass a pointer to a struct
419 * of this type as to the initialization function
420 * of the ATS plugins.
421 */
422struct GNUNET_ATS_PluginEnvironment
423{
424 /**
425 * Configuration handle to be used by the solver
426 */
427 const struct GNUNET_CONFIGURATION_Handle *cfg;
428
429 /**
430 * Statistics handle to be used by the solver
431 */
432 struct GNUNET_STATISTICS_Handle *stats;
433
434 /**
435 * Closure to pass to all callbacks in this struct.
436 */
437 void *cls;
438
439 /**
440 * Hashmap containing all addresses available
441 */
442 struct GNUNET_CONTAINER_MultiPeerMap *addresses;
443
444 /**
445 * ATS addresses callback to be notified about bandwidth assignment changes
446 */
447 GAS_bandwidth_changed_cb bandwidth_changed_cb;
448
449 /**
450 * ATS addresses function to obtain preference values
451 */
452 GAS_get_preferences get_preferences;
453
454 /**
455 * ATS addresses function to obtain preference values
456 */
457 GAS_get_connectivity get_connectivity;
458
459 /**
460 * Callback for solver to call with status information,
461 * can be NULL
462 */
463 GAS_solver_information_callback info_cb;
464
465 /**
466 * Number of networks available, size of the @e out_quota
467 * and @e in_quota arrays.
468 */
469 unsigned int network_count;
470
471 /**
472 * Array of configured outbound quotas
473 * Order according to networks in network array
474 */
475 unsigned long long out_quota[GNUNET_NT_COUNT];
476
477 /**
478 * Array of configured inbound quotas
479 * Order according to networks in network array
480 */
481 unsigned long long in_quota[GNUNET_NT_COUNT];
482};
483
484#endif
485
486/** @} */ /* end of group */
diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h
deleted file mode 100644
index 68ba8e6b2..000000000
--- a/src/include/gnunet_ats_service.h
+++ /dev/null
@@ -1,624 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010-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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file
22 * Automatic transport selection and outbound bandwidth determination
23 *
24 * @author Christian Grothoff
25 * @author Matthias Wachs
26 *
27 * @defgroup ats ATS service
28 * Automatic Transport Selection and outbound bandwidth determination
29 *
30 * @see [Documentation](https://gnunet.org/ats-subsystem)
31 *
32 * @{
33 */
34#ifndef GNUNET_ATS_SERVICE_H
35#define GNUNET_ATS_SERVICE_H
36
37#include "gnunet_constants.h"
38#include "gnunet_util_lib.h"
39#include "gnunet_hello_lib.h"
40
41
42/**
43 * Default bandwidth assigned to a network : 64 KB/s
44 */
45#define GNUNET_ATS_DefaultBandwidth 65536
46
47/**
48 * Undefined value for an `enum GNUNET_ATS_Property`
49 */
50#define GNUNET_ATS_VALUE_UNDEFINED UINT32_MAX
51
52/**
53 * String representation for GNUNET_ATS_VALUE_UNDEFINED
54 */
55#define GNUNET_ATS_VALUE_UNDEFINED_STR "undefined"
56
57/**
58 * Maximum bandwidth assigned to a network : 4095 MB/s
59 */
60#define GNUNET_ATS_MaxBandwidth UINT32_MAX
61
62/**
63 * Textual equivalent for GNUNET_ATS_MaxBandwidth
64 */
65#define GNUNET_ATS_MaxBandwidthString "unlimited"
66
67
68/**
69 * ATS performance characteristics for an address.
70 */
71struct GNUNET_ATS_Properties
72{
73 /**
74 * Delay. Time between when the time packet is sent and the packet
75 * arrives. FOREVER if we did not measure yet.
76 */
77 struct GNUNET_TIME_Relative delay;
78
79 /**
80 * Actual traffic on this connection from this peer to the other peer.
81 * Includes transport overhead.
82 *
83 * Unit: [bytes/second]
84 */
85 uint32_t utilization_out;
86
87 /**
88 * Actual traffic on this connection from the other peer to this peer.
89 * Includes transport overhead.
90 *
91 * Unit: [bytes/second]
92 */
93 uint32_t utilization_in;
94
95 /**
96 * Distance on network layer (required for distance-vector routing)
97 * in hops. Zero for direct connections (e.g. plain TCP/UDP).
98 */
99 unsigned int distance;
100
101 /**
102 * Which network scope does the respective address belong to?
103 * This property does not change.
104 */
105 enum GNUNET_NetworkType scope;
106};
107
108
109/**
110 * ATS performance characteristics for an address in
111 * network byte order (for IPC).
112 */
113struct GNUNET_ATS_PropertiesNBO
114{
115 /**
116 * Actual traffic on this connection from this peer to the other peer.
117 * Includes transport overhead.
118 *
119 * Unit: [bytes/second]
120 */
121 uint32_t utilization_out GNUNET_PACKED;
122
123 /**
124 * Actual traffic on this connection from the other peer to this peer.
125 * Includes transport overhead.
126 *
127 * Unit: [bytes/second]
128 */
129 uint32_t utilization_in GNUNET_PACKED;
130
131 /**
132 * Which network scope does the respective address belong to?
133 * This property does not change.
134 */
135 uint32_t scope GNUNET_PACKED;
136
137 /**
138 * Distance on network layer (required for distance-vector routing)
139 * in hops. Zero for direct connections (e.g. plain TCP/UDP).
140 */
141 uint32_t distance GNUNET_PACKED;
142
143 /**
144 * Delay. Time between when the time packet is sent and the packet
145 * arrives. FOREVER if we did not measure yet.
146 */
147 struct GNUNET_TIME_RelativeNBO delay;
148};
149
150
151/* ********************* LAN Characterization library ************************ */
152/* Note: these functions do not really communicate with the ATS service */
153
154
155/**
156 * Convert ATS properties from host to network byte order.
157 *
158 * @param nbo[OUT] value written
159 * @param hbo value read
160 */
161void
162GNUNET_ATS_properties_hton (struct GNUNET_ATS_PropertiesNBO *nbo,
163 const struct GNUNET_ATS_Properties *hbo);
164
165
166/**
167 * Convert ATS properties from network to host byte order.
168 *
169 * @param hbo[OUT] value written
170 * @param nbo value read
171 */
172void
173GNUNET_ATS_properties_ntoh (struct GNUNET_ATS_Properties *hbo,
174 const struct GNUNET_ATS_PropertiesNBO *nbo);
175
176
177/* ********************Connection Suggestion API ***************************** */
178
179/**
180 * Handle to the ATS subsystem for making suggestions about
181 * connections the peer would like to have.
182 */
183struct GNUNET_ATS_ConnectivityHandle;
184
185/**
186 * Handle for address suggestion requests.
187 */
188struct GNUNET_ATS_ConnectivitySuggestHandle;
189
190
191/**
192 * Initialize the ATS connectivity suggestion client handle.
193 *
194 * @param cfg configuration to use
195 * @return ats connectivity handle, NULL on error
196 */
197struct GNUNET_ATS_ConnectivityHandle *
198GNUNET_ATS_connectivity_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
199
200
201/**
202 * Shutdown ATS connectivity suggestion client.
203 *
204 * @param ch handle to destroy
205 */
206void
207GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch);
208
209
210/**
211 * We would like to establish a new connection with a peer. ATS
212 * should suggest a good address to begin with.
213 *
214 * @param ch handle
215 * @param peer identity of the peer we need an address for
216 * @param strength how urgent is the need for such a suggestion
217 * @return suggestion handle, NULL if request is already pending
218 */
219struct GNUNET_ATS_ConnectivitySuggestHandle *
220GNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch,
221 const struct GNUNET_PeerIdentity *peer,
222 uint32_t strength);
223
224
225/**
226 * We no longer care about being connected to a peer.
227 *
228 * @param sh handle
229 */
230void
231GNUNET_ATS_connectivity_suggest_cancel (struct
232 GNUNET_ATS_ConnectivitySuggestHandle *sh);
233
234
235/* ******************************** Scheduling API ***************************** */
236
237/**
238 * Handle to the ATS subsystem for bandwidth/transport scheduling information.
239 */
240struct GNUNET_ATS_SchedulingHandle;
241
242/**
243 * Opaque session handle, defined by plugins. Contents not known to ATS.
244 */
245struct GNUNET_ATS_Session;
246
247
248/**
249 * Signature of a function called by ATS with the current bandwidth
250 * and address preferences as determined by ATS. If our connection
251 * to ATS dies and thus all suggestions become invalid, this function
252 * is called ONCE with all arguments (except @a cls) being NULL/0.
253 *
254 * @param cls closure
255 * @param peer for which we suggest an address, NULL if ATS connection died
256 * @param address suggested address (including peer identity of the peer),
257 * may be NULL to signal disconnect from peer
258 * @param session session to use, NULL to establish a new outgoing session
259 * @param bandwidth_out assigned outbound bandwidth for the connection,
260 * 0 to signal disconnect
261 * @param bandwidth_in assigned inbound bandwidth for the connection,
262 * 0 to signal disconnect
263 */
264typedef void
265(*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
266 const struct GNUNET_PeerIdentity *peer,
267 const struct
268 GNUNET_HELLO_Address *address,
269 struct GNUNET_ATS_Session *session,
270 struct GNUNET_BANDWIDTH_Value32NBO
271 bandwidth_out,
272 struct GNUNET_BANDWIDTH_Value32NBO
273 bandwidth_in);
274
275
276/**
277 * Initialize the ATS scheduling subsystem.
278 *
279 * @param cfg configuration to use
280 * @param suggest_cb notification to call whenever the suggestation changed
281 * @param suggest_cb_cls closure for @a suggest_cb
282 * @return ats context
283 */
284struct GNUNET_ATS_SchedulingHandle *
285GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
286 GNUNET_ATS_AddressSuggestionCallback suggest_cb,
287 void *suggest_cb_cls);
288
289
290/**
291 * Client is done with ATS scheduling, release resources.
292 *
293 * @param sh handle to release
294 */
295void
296GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh);
297
298
299/**
300 * Handle used within ATS to track an address.
301 */
302struct GNUNET_ATS_AddressRecord;
303
304
305/**
306 * We have a new address ATS should know. Addresses have to be added with this
307 * function before they can be: updated, set in use and destroyed
308 *
309 * @param sh handle
310 * @param address the address
311 * @param session session handle (if available, e.g for incoming connections)
312 * @param prop performance data for the address
313 * @return handle to the address representation inside ATS, NULL
314 * on error (i.e. ATS knows this exact address already, or
315 * address is invalid)
316 */
317struct GNUNET_ATS_AddressRecord *
318GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
319 const struct GNUNET_HELLO_Address *address,
320 struct GNUNET_ATS_Session *session,
321 const struct GNUNET_ATS_Properties *prop);
322
323
324/**
325 * An address was used to initiate a session.
326 *
327 * @param ar address record to update information for
328 * @param session session handle
329 */
330void
331GNUNET_ATS_address_add_session (struct GNUNET_ATS_AddressRecord *ar,
332 struct GNUNET_ATS_Session *session);
333
334
335/**
336 * A @a session was destroyed, disassociate it from the given address
337 * record. If this was an incoming address, destroys the address as
338 * well.
339 *
340 * @param ar address record to update information for
341 * @param session session handle
342 * @return #GNUNET_YES if the @a ar was destroyed because
343 * it was an incoming address,
344 * #GNUNET_NO if the @ar was kept because we can
345 * use it still to establish a new session
346 */
347int
348GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar,
349 struct GNUNET_ATS_Session *session);
350
351
352/**
353 * We have updated performance statistics for a given address. Note
354 * that this function can be called for addresses that are currently
355 * in use as well as addresses that are valid but not actively in use.
356 * Furthermore, the peer may not even be connected to us right now (@a
357 * session value of NULL used to signal disconnect, or somehow we
358 * otherwise got updated on @a ats information). Based on the
359 * information provided, ATS may update bandwidth assignments and
360 * suggest to switch addresses.
361 *
362 * @param ar address record to update information for
363 * @param prop performance data for the address
364 */
365void
366GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar,
367 const struct GNUNET_ATS_Properties *prop);
368
369
370/**
371 * An address got destroyed, stop using it as a valid address.
372 *
373 * @param ar address record to destroy, it's validation has
374 * expired and ATS may no longer use it
375 */
376void
377GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar);
378
379
380/* ******************************** Performance API ***************************** */
381
382/**
383 * ATS Handle to obtain and/or modify performance information.
384 */
385struct GNUNET_ATS_PerformanceHandle;
386
387/**
388 * Signature of a function that is called with QoS information about an address.
389 *
390 * @param cls closure
391 * @param address the address, NULL if ATS service was disconnected or
392 * when the iteration is completed in the case of
393 * #GNUNET_ATS_performance_list_addresses()
394 * @param address_active #GNUNET_YES if this address is actively used
395 * to maintain a connection to a peer;
396 * #GNUNET_NO if the address is not actively used;
397 * #GNUNET_SYSERR if this address is no longer available for ATS
398 * @param bandwidth_out assigned outbound bandwidth for the connection
399 * @param bandwidth_in assigned inbound bandwidth for the connection
400 * @param prop performance data for the address
401 */
402typedef void
403(*GNUNET_ATS_AddressInformationCallback) (void *cls,
404 const struct
405 GNUNET_HELLO_Address *address,
406 int address_active,
407 struct GNUNET_BANDWIDTH_Value32NBO
408 bandwidth_out,
409 struct GNUNET_BANDWIDTH_Value32NBO
410 bandwidth_in,
411 const struct
412 GNUNET_ATS_Properties *prop);
413
414
415/**
416 * Handle for an address listing operation
417 */
418struct GNUNET_ATS_AddressListHandle;
419
420
421/**
422 * Get handle to access performance API of the ATS subsystem.
423 *
424 * @param cfg configuration to use
425 * @param addr_info_cb callback called when performance characteristics for
426 * an address change
427 * @param addr_info_cb_cls closure for @a addr_info_cb
428 * @return ats performance context
429 */
430struct GNUNET_ATS_PerformanceHandle *
431GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
432 GNUNET_ATS_AddressInformationCallback addr_info_cb,
433 void *addr_info_cb_cls);
434
435
436/**
437 * Get information about addresses known to the ATS subsystem.
438 *
439 * @param ph the performance handle to use
440 * @param peer peer idm can be NULL for all peers
441 * @param all #GNUNET_YES to get information about all addresses or #GNUNET_NO to
442 * get only address currently used
443 * @param infocb callback to call with the addresses,
444 * will callback with address == NULL when done
445 * @param infocb_cls closure for @a infocb
446 * @return handle to abort the operation
447 */
448struct GNUNET_ATS_AddressListHandle *
449GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *ph,
450 const struct GNUNET_PeerIdentity *peer,
451 int all,
452 GNUNET_ATS_AddressInformationCallback
453 infocb,
454 void *infocb_cls);
455
456
457/**
458 * Cancel a pending address listing operation
459 *
460 * @param alh the `struct GNUNET_ATS_AddressListHandle` handle to cancel
461 */
462void
463GNUNET_ATS_performance_list_addresses_cancel (struct
464 GNUNET_ATS_AddressListHandle *alh);
465
466
467/**
468 * Client is done using the ATS performance subsystem, release resources.
469 *
470 * @param ph handle
471 */
472void
473GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph);
474
475
476/**
477 * Function called with reservation result.
478 *
479 * @param cls closure
480 * @param peer identifies the peer
481 * @param amount set to the amount that was actually reserved or unreserved;
482 * either the full requested amount or zero (no partial reservations)
483 * @param res_delay if the reservation could not be satisfied (amount was 0), how
484 * long should the client wait until re-trying?
485 */
486typedef void
487(*GNUNET_ATS_ReservationCallback) (void *cls,
488 const struct GNUNET_PeerIdentity *peer,
489 int32_t amount,
490 struct GNUNET_TIME_Relative res_delay);
491
492
493/**
494 * Context that can be used to cancel a peer information request.
495 */
496struct GNUNET_ATS_ReservationContext;
497
498
499/**
500 * Reserve inbound bandwidth from the given peer. ATS will look at
501 * the current amount of traffic we receive from the peer and ensure
502 * that the peer could add 'amount' of data to its stream.
503 *
504 * @param ph performance handle
505 * @param peer identifies the peer
506 * @param amount reserve N bytes for receiving, negative
507 * amounts can be used to undo a (recent) reservation;
508 * @param rcb function to call with the resulting reservation information
509 * @param rcb_cls closure for @a rcb
510 * @return NULL on error
511 * @deprecated will be replaced soon
512 */
513struct GNUNET_ATS_ReservationContext *
514GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
515 const struct GNUNET_PeerIdentity *peer,
516 int32_t amount,
517 GNUNET_ATS_ReservationCallback rcb,
518 void *rcb_cls);
519
520
521/**
522 * Cancel request for reserving bandwidth.
523 *
524 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
525 */
526void
527GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc);
528
529
530/**
531 * ATS preference types as array initializer
532 */
533#define GNUNET_ATS_PreferenceType { GNUNET_ATS_PREFERENCE_BANDWIDTH, \
534 GNUNET_ATS_PREFERENCE_LATENCY, \
535 GNUNET_ATS_PREFERENCE_END }
536
537/**
538 * ATS preference types as string array initializer
539 */
540#define GNUNET_ATS_PreferenceTypeString { "BANDWIDTH", "LATENCY", "END" }
541
542/**
543 * Enum defining all known preference categories.
544 */
545enum GNUNET_ATS_PreferenceKind
546{
547 /**
548 * Change the peer's bandwidth value (value per byte of bandwidth in
549 * the goal function) to the given amount. The argument is followed
550 * by a double value giving the desired value (can be negative).
551 * Preference changes are forgotten if peers disconnect.
552 */
553 GNUNET_ATS_PREFERENCE_BANDWIDTH = 0,
554
555 /**
556 * Change the peer's latency value to the given amount. The
557 * argument is followed by a double value giving the desired value
558 * (can be negative). The absolute score in the goal function is
559 * the inverse of the latency in microseconds (minimum: 1
560 * microsecond) multiplied by the latency preferences.
561 */
562 GNUNET_ATS_PREFERENCE_LATENCY = 1,
563
564 /**
565 * End of preference list.
566 */
567 GNUNET_ATS_PREFERENCE_END = 2
568};
569
570
571/**
572 * Convert a GNUNET_ATS_PreferenceType to a string
573 *
574 * @param type the preference type
575 * @return a string or NULL if invalid
576 */
577const char *
578GNUNET_ATS_print_preference_type (enum GNUNET_ATS_PreferenceKind type);
579
580
581/**
582 * Change preferences for the given peer. Preference changes are forgotten if peers
583 * disconnect.
584 *
585 * @param ph performance handle @param peer identifies the peer
586 * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the
587 * desired changes
588 */
589void
590GNUNET_ATS_performance_change_preference (struct
591 GNUNET_ATS_PerformanceHandle *ph,
592 const struct
593 GNUNET_PeerIdentity *peer,
594 ...);
595
596
597/**
598 * Application feedback on how good preference requirements are fulfilled
599 * for the preferences included in the given time scope [now - scope .. now]
600 *
601 * An application notifies ATS if (and only if) it has feedback information
602 * for specific properties. This values are valid until the feedback scores are
603 * updated by the application.
604 *
605 * If the application has no feedback for this preference kind the application
606 * will not explicitly call for this property and will not include it in this
607 * function call.
608 *
609 * @param ph performance handle
610 * @param scope the time interval this valid for: [now - scope .. now]
611 * @param peer identifies the peer
612 * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes
613 */
614void
615GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph,
616 const struct GNUNET_PeerIdentity *peer,
617 const struct GNUNET_TIME_Relative scope,
618 ...);
619
620#endif
621
622/** @} */ /* end of group */
623
624/* end of file gnunet-service-transport_ats.h */
diff --git a/src/include/gnunet_ats_transport_service.h b/src/include/gnunet_ats_transport_service.h
deleted file mode 100644
index fd821baef..000000000
--- a/src/include/gnunet_ats_transport_service.h
+++ /dev/null
@@ -1,240 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010-2015, 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file
22 * Bandwidth allocation API for the transport service
23 *
24 * @author Christian Grothoff
25 * @author Matthias Wachs
26 *
27 * @defgroup ats ATS service
28 * Bandwidth allocation for transport service
29 *
30 * @see [Documentation](https://gnunet.org/ats-subsystem)
31 *
32 * @{
33 */
34#ifndef GNUNET_ATS_TRANSPORT_SERVICE_H
35#define GNUNET_ATS_TRANSPORT_SERVICE_H
36
37#include "gnunet_constants.h"
38#include "gnunet_util_lib.h"
39#include "gnunet_nt_lib.h"
40#include "gnunet_transport_communication_service.h"
41
42
43/**
44 * ATS performance characteristics for a session.
45 */
46struct GNUNET_ATS_Properties
47{
48 /**
49 * Delay. Time between when the time packet is sent and the packet
50 * arrives. FOREVER if we did not (successfully) measure yet.
51 */
52 struct GNUNET_TIME_Relative delay;
53
54 /**
55 * Confirmed successful payload on this connection from this peer to
56 * the other peer.
57 *
58 * Unit: [bytes/second]
59 */
60 uint32_t goodput_out;
61
62 /**
63 * Confirmed useful payload on this connection to this peer from
64 * the other peer.
65 *
66 * Unit: [bytes/second]
67 */
68 uint32_t goodput_in;
69
70 /**
71 * Actual traffic on this connection from this peer to the other peer.
72 * Includes transport overhead.
73 *
74 * Unit: [bytes/second]
75 */
76 uint32_t utilization_out;
77
78 /**
79 * Actual traffic on this connection from the other peer to this peer.
80 * Includes transport overhead.
81 *
82 * Unit: [bytes/second]
83 */
84 uint32_t utilization_in;
85
86 /**
87 * Distance on network layer (required for distance-vector routing)
88 * in hops. Zero for direct connections (e.g. plain TCP/UDP).
89 */
90 uint32_t distance;
91
92 /**
93 * MTU of the network layer, UINT32_MAX for no MTU (stream).
94 *
95 * Unit: [bytes]
96 */
97 uint32_t mtu;
98
99 /**
100 * Which network scope does the respective address belong to?
101 */
102 enum GNUNET_NetworkType nt;
103
104 /**
105 * What characteristics does this communicator have?
106 */
107 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
108};
109
110
111/* ******************************** Transport API ***************************** */
112
113/**
114 * Handle to the ATS subsystem for bandwidth/transport transport information.
115 */
116struct GNUNET_ATS_TransportHandle;
117
118/**
119 * Opaque session handle, to be defined by transport. Contents not known to ATS.
120 */
121struct GNUNET_ATS_Session;
122
123
124/**
125 * Signature of a function called by ATS with the current bandwidth
126 * allocation to be used as determined by ATS.
127 *
128 * @param cls closure
129 * @param session session this is about
130 * @param bandwidth_out assigned outbound bandwidth for the connection,
131 * 0 to signal disconnect
132 * @param bandwidth_in assigned inbound bandwidth for the connection,
133 * 0 to signal disconnect
134 */
135typedef void
136(*GNUNET_ATS_AllocationCallback) (void *cls,
137 struct GNUNET_ATS_Session *session,
138 struct GNUNET_BANDWIDTH_Value32NBO
139 bandwidth_out,
140 struct GNUNET_BANDWIDTH_Value32NBO
141 bandwidth_in);
142
143
144/**
145 * Signature of a function called by ATS suggesting transport to
146 * try connecting with a particular address.
147 *
148 * @param cls closure
149 * @param pid target peer
150 * @param address the address to try
151 */
152typedef void
153(*GNUNET_ATS_SuggestionCallback) (void *cls,
154 const struct GNUNET_PeerIdentity *pid,
155 const char *address);
156
157
158/**
159 * Initialize the ATS transport subsystem.
160 *
161 * @param cfg configuration to use
162 * @param alloc_cb notification to call whenever the allocation changed
163 * @param alloc_cb_cls closure for @a alloc_cb
164 * @param suggest_cb notification to call whenever the suggestation is made
165 * @param suggest_cb_cls closure for @a suggest_cb
166 * @return ats context
167 */
168struct GNUNET_ATS_TransportHandle *
169GNUNET_ATS_transport_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
170 GNUNET_ATS_AllocationCallback alloc_cb,
171 void *alloc_cb_cls,
172 GNUNET_ATS_SuggestionCallback suggest_cb,
173 void *suggest_cb_cls);
174
175
176/**
177 * Client is done with ATS transport, release resources.
178 *
179 * @param ath handle to release
180 */
181void
182GNUNET_ATS_transport_done (struct GNUNET_ATS_TransportHandle *ath);
183
184
185/**
186 * Handle used within ATS to track an session.
187 */
188struct GNUNET_ATS_SessionRecord;
189
190
191/**
192 * We have a new session ATS should know. Sessiones have to be added with this
193 * function before they can be: updated, set in use and destroyed
194 *
195 * @param ath handle
196 * @param pid peer we connected to
197 * @param address the address (human readable version),
198 * @param session transport-internal handle for the session/queue, NULL if
199 * the session is inbound-only
200 * @param prop performance data for the session
201 * @return handle to the session representation inside ATS, NULL
202 * on error (i.e. ATS knows this exact session already, or
203 * session is invalid)
204 */
205struct GNUNET_ATS_SessionRecord *
206GNUNET_ATS_session_add (struct GNUNET_ATS_TransportHandle *ath,
207 const struct GNUNET_PeerIdentity *pid,
208 const char *address,
209 struct GNUNET_ATS_Session *session,
210 const struct GNUNET_ATS_Properties *prop);
211
212
213/**
214 * We have updated performance statistics for a given session. Based
215 * on the information provided, ATS may update bandwidth assignments.
216 *
217 * @param ar session record to update information for
218 * @param prop performance data for the session
219 */
220void
221GNUNET_ATS_session_update (struct GNUNET_ATS_SessionRecord *ar,
222 const struct GNUNET_ATS_Properties *prop);
223
224
225/**
226 * A session was destroyed, ATS should now schedule and
227 * allocate under the assumption that this @a ar is no
228 * longer in use.
229 *
230 * @param ar session record to drop
231 */
232void
233GNUNET_ATS_session_del (struct GNUNET_ATS_SessionRecord *ar);
234
235
236#endif
237
238/** @} */ /* end of group */
239
240/* end of file gnunet-service-transport_ats.h */
diff --git a/src/include/gnunet_bandwidth_lib.h b/src/include/gnunet_bandwidth_lib.h
index 9130ff57e..00a7d6c5d 100644
--- a/src/include/gnunet_bandwidth_lib.h
+++ b/src/include/gnunet_bandwidth_lib.h
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * 27 *
24 * @file 28 * @file
@@ -29,6 +33,10 @@
29 * @{ 33 * @{
30 */ 34 */
31 35
36#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
37#error "Only <gnunet_util_lib.h> can be included directly."
38#endif
39
32#ifndef GNUNET_BANDWIDTH_LIB_H 40#ifndef GNUNET_BANDWIDTH_LIB_H
33#define GNUNET_BANDWIDTH_LIB_H 41#define GNUNET_BANDWIDTH_LIB_H
34 42
@@ -39,7 +47,7 @@ extern "C" {
39#endif 47#endif
40#endif 48#endif
41 49
42#include "gnunet_common.h" 50
43#include "gnunet_time_lib.h" 51#include "gnunet_time_lib.h"
44 52
45GNUNET_NETWORK_STRUCT_BEGIN 53GNUNET_NETWORK_STRUCT_BEGIN
@@ -351,4 +359,6 @@ GNUNET_BANDWIDTH_tracker_update_quota (
351 359
352/** @} */ /* end of group */ 360/** @} */ /* end of group */
353 361
362/** @} */ /* end of group addition */
363
354/* end of gnunet_bandwidth_lib.h */ 364/* end of gnunet_bandwidth_lib.h */
diff --git a/src/include/gnunet_bio_lib.h b/src/include/gnunet_bio_lib.h
index 142f1b088..73550db7e 100644
--- a/src/include/gnunet_bio_lib.h
+++ b/src/include/gnunet_bio_lib.h
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * 27 *
24 * @file 28 * @file
@@ -29,9 +33,15 @@
29 * @{ 33 * @{
30 */ 34 */
31 35
36#include "gnunet_common.h"
37#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
38#error "Only <gnunet_util_lib.h> can be included directly."
39#endif
40
32#ifndef GNUNET_BIO_LIB_H 41#ifndef GNUNET_BIO_LIB_H
33#define GNUNET_BIO_LIB_H 42#define GNUNET_BIO_LIB_H
34 43
44
35#include "gnunet_container_lib.h" 45#include "gnunet_container_lib.h"
36 46
37#ifdef __cplusplus 47#ifdef __cplusplus
@@ -79,9 +89,18 @@ GNUNET_BIO_read_open_buffer (void *buffer, size_t size);
79 * @param emsg set to the error message 89 * @param emsg set to the error message
80 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 90 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
81 */ 91 */
82int 92enum GNUNET_GenericReturnValue
83GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg); 93GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg);
84 94
95/**
96 * Set read error to handle
97 *
98 * @param h the handle
99 * @param emsg the message
100 */
101void
102GNUNET_BIO_read_set_error (struct GNUNET_BIO_ReadHandle *h, const char* emsg);
103
85 104
86/** 105/**
87 * Read some contents into a buffer. 106 * Read some contents into a buffer.
@@ -92,7 +111,7 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg);
92 * @param len the number of bytes to read 111 * @param len the number of bytes to read
93 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 112 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
94 */ 113 */
95int 114enum GNUNET_GenericReturnValue
96GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, 115GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
97 const char *what, 116 const char *what,
98 void *result, 117 void *result,
@@ -109,26 +128,13 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
109 * @param max_length maximum allowed length for the string 128 * @param max_length maximum allowed length for the string
110 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 129 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
111 */ 130 */
112int 131enum GNUNET_GenericReturnValue
113GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, 132GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
114 const char *what, 133 const char *what,
115 char **result, 134 char **result,
116 size_t max_length); 135 size_t max_length);
117 136
118 137
119/**
120 * Read a metadata container.
121 *
122 * @param h handle to an open file
123 * @param what describes what is being read (for error message creation)
124 * @param result the buffer to store a pointer to the (allocated) metadata
125 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
126 */
127int
128GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
129 const char *what,
130 struct GNUNET_CONTAINER_MetaData **result);
131
132 138
133/** 139/**
134 * Read a float. 140 * Read a float.
@@ -137,7 +143,7 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
137 * @param what describes what is being read (for error message creation) 143 * @param what describes what is being read (for error message creation)
138 * @param f address of float to read 144 * @param f address of float to read
139 */ 145 */
140int 146enum GNUNET_GenericReturnValue
141GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h, 147GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h,
142 const char *what, 148 const char *what,
143 float *f); 149 float *f);
@@ -150,7 +156,7 @@ GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h,
150 * @param what describes what is being read (for error message creation) 156 * @param what describes what is being read (for error message creation)
151 * @param f address of double to read 157 * @param f address of double to read
152 */ 158 */
153int 159enum GNUNET_GenericReturnValue
154GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h, 160GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h,
155 const char *what, 161 const char *what,
156 double *f); 162 double *f);
@@ -164,7 +170,7 @@ GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h,
164 * @param i where to store the data 170 * @param i where to store the data
165 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 171 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
166 */ 172 */
167int 173enum GNUNET_GenericReturnValue
168GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h, 174GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h,
169 const char *what, 175 const char *what,
170 int32_t *i); 176 int32_t *i);
@@ -178,7 +184,7 @@ GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h,
178 * @param i where to store the data 184 * @param i where to store the data
179 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 185 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
180 */ 186 */
181int 187enum GNUNET_GenericReturnValue
182GNUNET_BIO_read_int64 (struct GNUNET_BIO_ReadHandle *h, 188GNUNET_BIO_read_int64 (struct GNUNET_BIO_ReadHandle *h,
183 const char *what, 189 const char *what,
184 int64_t *i); 190 int64_t *i);
@@ -219,7 +225,7 @@ GNUNET_BIO_write_open_buffer (void);
219 * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned 225 * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned
220 * and the file is closed 226 * and the file is closed
221 */ 227 */
222int 228enum GNUNET_GenericReturnValue
223GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h); 229GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h);
224 230
225 231
@@ -235,7 +241,7 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h);
235 * @param size where to store the size of @e contents 241 * @param size where to store the size of @e contents
236 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 242 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
237 */ 243 */
238int 244enum GNUNET_GenericReturnValue
239GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h, 245GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
240 char **emsg, 246 char **emsg,
241 void **contents, 247 void **contents,
@@ -251,7 +257,7 @@ GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
251 * if the handle has an error message, the return value is #GNUNET_SYSERR 257 * if the handle has an error message, the return value is #GNUNET_SYSERR
252 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 258 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
253 */ 259 */
254int 260enum GNUNET_GenericReturnValue
255GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg); 261GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg);
256 262
257 263
@@ -264,7 +270,7 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg);
264 * @param n number of bytes to write 270 * @param n number of bytes to write
265 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 271 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
266 */ 272 */
267int 273enum GNUNET_GenericReturnValue
268GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, 274GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
269 const char *what, 275 const char *what,
270 const void *buffer, 276 const void *buffer,
@@ -279,25 +285,12 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
279 * @param s string to write (can be NULL) 285 * @param s string to write (can be NULL)
280 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 286 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
281 */ 287 */
282int 288enum GNUNET_GenericReturnValue
283GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, 289GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h,
284 const char *what, 290 const char *what,
285 const char *s); 291 const char *s);
286 292
287 293
288/**
289 * Write a metadata container.
290 *
291 * @param h the IO handle to write to
292 * @param what what is being written (for error message creation)
293 * @param m metadata to write
294 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
295 */
296int
297GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
298 const char *what,
299 const struct GNUNET_CONTAINER_MetaData *m);
300
301 294
302/** 295/**
303 * Write a float. 296 * Write a float.
@@ -306,7 +299,7 @@ GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
306 * @param what what is being written (for error message creation) 299 * @param what what is being written (for error message creation)
307 * @param f float to write (must be a variable) 300 * @param f float to write (must be a variable)
308 */ 301 */
309int 302enum GNUNET_GenericReturnValue
310GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h, 303GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h,
311 const char *what, 304 const char *what,
312 float f); 305 float f);
@@ -318,7 +311,7 @@ GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h,
318 * @param what what is being written (for error message creation) 311 * @param what what is being written (for error message creation)
319 * @param f double to write (must be a variable) 312 * @param f double to write (must be a variable)
320 */ 313 */
321int 314enum GNUNET_GenericReturnValue
322GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h, 315GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h,
323 const char *what, 316 const char *what,
324 double f); 317 double f);
@@ -332,7 +325,7 @@ GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h,
332 * @param i 32-bit integer to write 325 * @param i 32-bit integer to write
333 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 326 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
334 */ 327 */
335int 328enum GNUNET_GenericReturnValue
336GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, 329GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
337 const char *what, 330 const char *what,
338 int32_t i); 331 int32_t i);
@@ -346,7 +339,7 @@ GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
346 * @param i 64-bit integer to write 339 * @param i 64-bit integer to write
347 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 340 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
348 */ 341 */
349int 342enum GNUNET_GenericReturnValue
350GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, 343GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h,
351 const char *what, 344 const char *what,
352 int64_t i); 345 int64_t i);
@@ -444,17 +437,6 @@ GNUNET_BIO_read_spec_string (const char *what,
444 size_t max_length); 437 size_t max_length);
445 438
446 439
447/**
448 * Create the specification to read a metadata container.
449 *
450 * @param what describes what is being read (for error message creation)
451 * @param result the buffer to store a pointer to the (allocated) metadata
452 * @return the read spec
453 */
454struct GNUNET_BIO_ReadSpec
455GNUNET_BIO_read_spec_meta_data (const char *what,
456 struct GNUNET_CONTAINER_MetaData **result);
457
458 440
459/** 441/**
460 * Create the specification to read an (u)int32_t. 442 * Create the specification to read an (u)int32_t.
@@ -508,7 +490,7 @@ GNUNET_BIO_read_spec_double (const char *what, double *f);
508 * the last element must be #GNUNET_BIO_read_spec_end 490 * the last element must be #GNUNET_BIO_read_spec_end
509 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 491 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
510 */ 492 */
511int 493enum GNUNET_GenericReturnValue
512GNUNET_BIO_read_spec_commit (struct GNUNET_BIO_ReadHandle *h, 494GNUNET_BIO_read_spec_commit (struct GNUNET_BIO_ReadHandle *h,
513 struct GNUNET_BIO_ReadSpec *rs); 495 struct GNUNET_BIO_ReadSpec *rs);
514 496
@@ -601,18 +583,6 @@ GNUNET_BIO_write_spec_string (const char *what,
601 583
602 584
603/** 585/**
604 * Create the specification to write a metadata container.
605 *
606 * @param what what is being written (for error message creation)
607 * @param m metadata to write
608 * @return the write spec
609 */
610struct GNUNET_BIO_WriteSpec
611GNUNET_BIO_write_spec_meta_data (const char *what,
612 const struct GNUNET_CONTAINER_MetaData *m);
613
614
615/**
616 * Create the specification to write an (u)int32_t. 586 * Create the specification to write an (u)int32_t.
617 * 587 *
618 * @param what describes what is being written (for error message creation) 588 * @param what describes what is being written (for error message creation)
@@ -666,7 +636,7 @@ GNUNET_BIO_write_spec_double (const char *what, double *f);
666 * the last element must be #GNUNET_BIO_write_spec_end 636 * the last element must be #GNUNET_BIO_write_spec_end
667 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 637 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
668 */ 638 */
669int 639enum GNUNET_GenericReturnValue
670GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h, 640GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h,
671 struct GNUNET_BIO_WriteSpec *ws); 641 struct GNUNET_BIO_WriteSpec *ws);
672 642
@@ -683,4 +653,6 @@ GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h,
683 653
684/** @} */ /* end of group bio */ 654/** @} */ /* end of group bio */
685 655
656/** @} */ /* end of group addition */
657
686/* end of gnunet_bio_lib.h */ 658/* end of gnunet_bio_lib.h */
diff --git a/src/include/gnunet_block_group_lib.h b/src/include/gnunet_block_group_lib.h
index 6cb601757..b1f59899e 100644
--- a/src/include/gnunet_block_group_lib.h
+++ b/src/include/gnunet_block_group_lib.h
@@ -31,6 +31,7 @@
31#ifndef GNUNET_BLOCK_GROUP_LIB_H 31#ifndef GNUNET_BLOCK_GROUP_LIB_H
32#define GNUNET_BLOCK_GROUP_LIB_H 32#define GNUNET_BLOCK_GROUP_LIB_H
33 33
34
34#include "gnunet_util_lib.h" 35#include "gnunet_util_lib.h"
35#include "gnunet_block_lib.h" 36#include "gnunet_block_lib.h"
36 37
@@ -68,7 +69,6 @@ GNUNET_BLOCK_GROUP_compute_bloomfilter_size (unsigned int entry_count,
68 * @param bf_size size of the Bloom filter 69 * @param bf_size size of the Bloom filter
69 * @param bf_k K-value for the Bloom filter 70 * @param bf_k K-value for the Bloom filter
70 * @param type block type 71 * @param type block type
71 * @param nonce random value used to seed the group creation
72 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh 72 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh
73 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh 73 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
74 * @return block group handle, NULL if block groups are not supported 74 * @return block group handle, NULL if block groups are not supported
@@ -79,7 +79,6 @@ GNUNET_BLOCK_GROUP_bf_create (void *cls,
79 size_t bf_size, 79 size_t bf_size,
80 unsigned int bf_k, 80 unsigned int bf_k,
81 enum GNUNET_BLOCK_Type type, 81 enum GNUNET_BLOCK_Type type,
82 uint32_t nonce,
83 const void *raw_data, 82 const void *raw_data,
84 size_t raw_data_size); 83 size_t raw_data_size);
85 84
@@ -92,9 +91,9 @@ GNUNET_BLOCK_GROUP_bf_create (void *cls,
92 * @param bg block group to use for testing 91 * @param bg block group to use for testing
93 * @param hc hash of element to evaluate 92 * @param hc hash of element to evaluate
94 * @return #GNUNET_YES if @a hc is (likely) a duplicate 93 * @return #GNUNET_YES if @a hc is (likely) a duplicate
95 * #GNUNET_NO if @a hc was definitively not in @bg (but now is) 94 * #GNUNET_NO if @a hc was definitively not in @a bg (but now is)
96 */ 95 */
97int 96enum GNUNET_GenericReturnValue
98GNUNET_BLOCK_GROUP_bf_test_and_set (struct GNUNET_BLOCK_Group *bg, 97GNUNET_BLOCK_GROUP_bf_test_and_set (struct GNUNET_BLOCK_Group *bg,
99 const struct GNUNET_HashCode *hc); 98 const struct GNUNET_HashCode *hc);
100 99
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h
index 73b51252e..fdccbab78 100644
--- a/src/include/gnunet_block_lib.h
+++ b/src/include/gnunet_block_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
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, 2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup dht_libs DHT and support libraries
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -31,7 +34,10 @@
31#ifndef GNUNET_BLOCK_LIB_H 34#ifndef GNUNET_BLOCK_LIB_H
32#define GNUNET_BLOCK_LIB_H 35#define GNUNET_BLOCK_LIB_H
33 36
37
34#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
39#include "gnunet_dht_block_types.h"
40
35#ifdef __cplusplus 41#ifdef __cplusplus
36extern "C" 42extern "C"
37{ 43{
@@ -42,181 +48,36 @@ extern "C"
42 48
43 49
44/** 50/**
45 * Blocks in the datastore and the datacache must have a unique type.
46 */
47enum GNUNET_BLOCK_Type
48{
49 /**
50 * Any type of block, used as a wildcard when searching. Should
51 * never be attached to a specific block.
52 */
53 GNUNET_BLOCK_TYPE_ANY = 0,
54
55 /**
56 * Data block (leaf) in the CHK tree.
57 */
58 GNUNET_BLOCK_TYPE_FS_DBLOCK = 1,
59
60 /**
61 * Inner block in the CHK tree.
62 */
63 GNUNET_BLOCK_TYPE_FS_IBLOCK = 2,
64
65 /**
66 * Legacy type, no longer in use.
67 */
68 GNUNET_BLOCK_TYPE_FS_KBLOCK = 3,
69
70 /**
71 * Legacy type, no longer in use.
72 */
73 GNUNET_BLOCK_TYPE_FS_SBLOCK = 4,
74
75 /**
76 * Legacy type, no longer in use.
77 */
78 GNUNET_BLOCK_TYPE_FS_NBLOCK = 5,
79
80 /**
81 * Type of a block representing a block to be encoded on demand from disk.
82 * Should never appear on the network directly.
83 */
84 GNUNET_BLOCK_TYPE_FS_ONDEMAND = 6,
85
86 /**
87 * Type of a block that contains a HELLO for a peer (for
88 * DHT and CADET find-peer operations).
89 */
90 GNUNET_BLOCK_TYPE_DHT_HELLO = 7,
91
92 /**
93 * Block for testing.
94 */
95 GNUNET_BLOCK_TYPE_TEST = 8,
96
97 /**
98 * Type of a block representing any type of search result
99 * (universal). Implemented in the context of #2564, replaces
100 * SBLOCKS, KBLOCKS and NBLOCKS.
101 */
102 GNUNET_BLOCK_TYPE_FS_UBLOCK = 9,
103
104 /**
105 * Block for storing DNS exit service advertisements.
106 */
107 GNUNET_BLOCK_TYPE_DNS = 10,
108
109 /**
110 * Block for storing record data
111 */
112 GNUNET_BLOCK_TYPE_GNS_NAMERECORD = 11,
113
114 /**
115 * Block type for a revocation message by which a key is revoked.
116 */
117 GNUNET_BLOCK_TYPE_REVOCATION = 12,
118
119 /**
120 * Block to store a cadet regex state
121 */
122 GNUNET_BLOCK_TYPE_REGEX = 22,
123
124 /**
125 * Block to store a cadet regex accepting state
126 */
127 GNUNET_BLOCK_TYPE_REGEX_ACCEPT = 23,
128
129 /**
130 * Block for testing set/consensus. If first byte of the block
131 * is non-zero, the block is considered invalid.
132 */
133 GNUNET_BLOCK_TYPE_SET_TEST = 24,
134
135 /**
136 * Block type for consensus elements.
137 * Contains either special marker elements or a nested block.
138 */
139 GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT = 25,
140
141 /**
142 * Block for testing set intersection. If first byte of the block
143 * is non-zero, the block is considered invalid.
144 */
145 GNUNET_BLOCK_TYPE_SETI_TEST = 24,
146
147 /**
148 * Block for testing set union. If first byte of the block
149 * is non-zero, the block is considered invalid.
150 */
151 GNUNET_BLOCK_TYPE_SETU_TEST = 24,
152
153};
154
155
156/**
157 * Flags that can be set to control the evaluation.
158 */
159enum GNUNET_BLOCK_EvaluationOptions
160{
161 /**
162 * Default behavior.
163 */
164 GNUNET_BLOCK_EO_NONE = 0,
165
166 /**
167 * The block is obtained from the local database, skip cryptographic
168 * checks.
169 */
170 GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO = 1
171};
172
173
174/**
175 * Possible ways for how a block may relate to a query. 51 * Possible ways for how a block may relate to a query.
176 */ 52 */
177enum GNUNET_BLOCK_EvaluationResult 53enum GNUNET_BLOCK_ReplyEvaluationResult
178{ 54{
179 /**
180 * Valid result, and there may be more.
181 */
182 GNUNET_BLOCK_EVALUATION_OK_MORE = 0,
183 55
184 /** 56 /**
185 * Last possible valid result. 57 * Specified block type not supported by any plugin.
186 */ 58 */
187 GNUNET_BLOCK_EVALUATION_OK_LAST = 1, 59 GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED = -1,
188 60
189 /** 61 /**
190 * Valid result, but suppressed because it is a duplicate. 62 * Valid result, but suppressed because it is a duplicate.
191 */ 63 */
192 GNUNET_BLOCK_EVALUATION_OK_DUPLICATE = 2, 64 GNUNET_BLOCK_REPLY_OK_DUPLICATE = 0,
193
194 /**
195 * Block does not match query (invalid result)
196 */
197 GNUNET_BLOCK_EVALUATION_RESULT_INVALID = 3,
198 65
199 /** 66 /**
200 * Block does not match xquery (valid result, not relevant for the request) 67 * Block does not match xquery (valid result, not relevant for the request)
201 */ 68 */
202 GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT = 4, 69 GNUNET_BLOCK_REPLY_IRRELEVANT = 1,
203 70
204 /** 71 /**
205 * Query is valid, no reply given. 72 * Valid result, and there may be more.
206 */ 73 */
207 GNUNET_BLOCK_EVALUATION_REQUEST_VALID = 10, 74 GNUNET_BLOCK_REPLY_OK_MORE = 2,
208 75
209 /** 76 /**
210 * Query format does not match block type (invalid query). For 77 * Last possible valid result.
211 * example, xquery not given or xquery_size not appropriate for
212 * type.
213 */ 78 */
214 GNUNET_BLOCK_EVALUATION_REQUEST_INVALID = 11, 79 GNUNET_BLOCK_REPLY_OK_LAST = 3
215 80
216 /**
217 * Specified block type not supported by this plugin.
218 */
219 GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED = 20
220}; 81};
221 82
222 83
@@ -271,7 +132,6 @@ struct GNUNET_BLOCK_Group;
271 * 132 *
272 * @param ctx block context in which the block group is created 133 * @param ctx block context in which the block group is created
273 * @param type type of the block for which we are creating the group 134 * @param type type of the block for which we are creating the group
274 * @param nonce random value used to seed the group creation
275 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh 135 * @param raw_data optional serialized prior state of the group, NULL if unavailable/fresh
276 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh 136 * @param raw_data_size number of bytes in @a raw_data, 0 if unavailable/fresh
277 * @param ... type-specific additional data, can be empty 137 * @param ... type-specific additional data, can be empty
@@ -281,7 +141,6 @@ struct GNUNET_BLOCK_Group;
281struct GNUNET_BLOCK_Group * 141struct GNUNET_BLOCK_Group *
282GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx, 142GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx,
283 enum GNUNET_BLOCK_Type type, 143 enum GNUNET_BLOCK_Type type,
284 uint32_t nonce,
285 const void *raw_data, 144 const void *raw_data,
286 size_t raw_data_size, 145 size_t raw_data_size,
287 ...); 146 ...);
@@ -291,15 +150,13 @@ GNUNET_BLOCK_group_create (struct GNUNET_BLOCK_Context *ctx,
291 * Serialize state of a block group. 150 * Serialize state of a block group.
292 * 151 *
293 * @param bg group to serialize 152 * @param bg group to serialize
294 * @param[out] nonce set to the nonce of the @a bg
295 * @param[out] raw_data set to the serialized state 153 * @param[out] raw_data set to the serialized state
296 * @param[out] raw_data_size set to the number of bytes in @a raw_data 154 * @param[out] raw_data_size set to the number of bytes in @a raw_data
297 * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not 155 * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not
298 * supported, #GNUNET_SYSERR on error 156 * supported, #GNUNET_SYSERR on error
299 */ 157 */
300int 158enum GNUNET_GenericReturnValue
301GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg, 159GNUNET_BLOCK_group_serialize (struct GNUNET_BLOCK_Group *bg,
302 uint32_t *nonce,
303 void **raw_data, 160 void **raw_data,
304 size_t *raw_data_size); 161 size_t *raw_data_size);
305 162
@@ -314,16 +171,12 @@ GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg);
314 171
315 172
316/** 173/**
317 * Function called to validate a reply or a request. For 174 * Function called to validate if a reply is good for a
318 * request evaluation, simply pass "NULL" for the @a reply_block. 175 * particular query.
319 * Note that it is assumed that the reply has already been
320 * matched to the key (and signatures checked) as it would
321 * be done with the #GNUNET_BLOCK_get_key() function.
322 * 176 *
323 * @param ctx block contxt 177 * @param ctx block contxt
324 * @param type block type 178 * @param type block type
325 * @param group block group to use for evaluation 179 * @param[in,out] group block group to use for evaluation
326 * @param eo evaluation options to control evaluation
327 * @param query original query (hash) 180 * @param query original query (hash)
328 * @param xquery extrended query data (can be NULL, depending on type) 181 * @param xquery extrended query data (can be NULL, depending on type)
329 * @param xquery_size number of bytes in @a xquery 182 * @param xquery_size number of bytes in @a xquery
@@ -331,20 +184,57 @@ GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg);
331 * @param reply_block_size number of bytes in @a reply_block 184 * @param reply_block_size number of bytes in @a reply_block
332 * @return characterization of result 185 * @return characterization of result
333 */ 186 */
334enum GNUNET_BLOCK_EvaluationResult 187enum GNUNET_BLOCK_ReplyEvaluationResult
335GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, 188GNUNET_BLOCK_check_reply (struct GNUNET_BLOCK_Context *ctx,
336 enum GNUNET_BLOCK_Type type, 189 enum GNUNET_BLOCK_Type type,
337 struct GNUNET_BLOCK_Group *group, 190 struct GNUNET_BLOCK_Group *group,
338 enum GNUNET_BLOCK_EvaluationOptions eo, 191 const struct GNUNET_HashCode *query,
339 const struct GNUNET_HashCode *query, 192 const void *xquery,
340 const void *xquery, 193 size_t xquery_size,
341 size_t xquery_size, 194 const void *reply_block,
342 const void *reply_block, 195 size_t reply_block_size);
343 size_t reply_block_size);
344 196
345 197
346/** 198/**
347 * Function called to obtain the key for a block. 199 * Function called to validate a request.
200 *
201 * @param ctx block contxt
202 * @param type block type
203 * @param query original query (hash)
204 * @param xquery extrended query data (can be NULL, depending on type)
205 * @param xquery_size number of bytes in @a xquery
206 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not,
207 * #GNUNET_SYSERR if @a type is not supported
208 */
209enum GNUNET_GenericReturnValue
210GNUNET_BLOCK_check_query (struct GNUNET_BLOCK_Context *ctx,
211 enum GNUNET_BLOCK_Type type,
212 const struct GNUNET_HashCode *query,
213 const void *xquery,
214 size_t xquery_size);
215
216
217/**
218 * Function called to validate a block.
219 *
220 * @param ctx block contxt
221 * @param type block type
222 * @param block payload to put
223 * @param block_size number of bytes in @a block
224 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not,
225 * #GNUNET_SYSERR if @a type is not supported
226 */
227enum GNUNET_GenericReturnValue
228GNUNET_BLOCK_check_block (struct GNUNET_BLOCK_Context *ctx,
229 enum GNUNET_BLOCK_Type type,
230 const void *block,
231 size_t block_size);
232
233
234/**
235 * Function called to obtain the @a key for a @a block.
236 * If the @a block is malformed, the function should
237 * zero-out @a key and return #GNUNET_OK.
348 * 238 *
349 * @param ctx block context 239 * @param ctx block context
350 * @param type block type 240 * @param type block type
@@ -352,11 +242,10 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
352 * @param block_size number of bytes in @a block 242 * @param block_size number of bytes in @a block
353 * @param key set to the key (query) for the given block 243 * @param key set to the key (query) for the given block
354 * @return #GNUNET_YES on success, 244 * @return #GNUNET_YES on success,
355 * #GNUNET_NO if the block is malformed 245 * #GNUNET_NO if extracting a key from a block of this @a type does not work
356 * #GNUNET_SYSERR if type not supported 246 * #GNUNET_SYSERR if @a type not supported
357 * (or if extracting a key from a block of this type does not work)
358 */ 247 */
359int 248enum GNUNET_GenericReturnValue
360GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, 249GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
361 enum GNUNET_BLOCK_Type type, 250 enum GNUNET_BLOCK_Type type,
362 const void *block, 251 const void *block,
@@ -375,7 +264,7 @@ GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
375 * @param seen_results_count number of entries in @a seen_results 264 * @param seen_results_count number of entries in @a seen_results
376 * @return #GNUNET_SYSERR if not supported, #GNUNET_OK on success 265 * @return #GNUNET_SYSERR if not supported, #GNUNET_OK on success
377 */ 266 */
378int 267enum GNUNET_GenericReturnValue
379GNUNET_BLOCK_group_set_seen (struct GNUNET_BLOCK_Group *bg, 268GNUNET_BLOCK_group_set_seen (struct GNUNET_BLOCK_Group *bg,
380 const struct GNUNET_HashCode *seen_results, 269 const struct GNUNET_HashCode *seen_results,
381 unsigned int seen_results_count); 270 unsigned int seen_results_count);
@@ -383,7 +272,7 @@ GNUNET_BLOCK_group_set_seen (struct GNUNET_BLOCK_Group *bg,
383 272
384/** 273/**
385 * Try merging two block groups. Afterwards, @a bg1 should remain 274 * Try merging two block groups. Afterwards, @a bg1 should remain
386 * valid and contain the rules from both @a bg1 and @bg2, and 275 * valid and contain the rules from both @a bg1 and @a bg2, and
387 * @a bg2 should be destroyed (as part of this call). The latter 276 * @a bg2 should be destroyed (as part of this call). The latter
388 * should happen even if merging is not supported. 277 * should happen even if merging is not supported.
389 * 278 *
@@ -393,7 +282,7 @@ GNUNET_BLOCK_group_set_seen (struct GNUNET_BLOCK_Group *bg,
393 * #GNUNET_NO if merge failed due to different nonce 282 * #GNUNET_NO if merge failed due to different nonce
394 * #GNUNET_SYSERR if merging is not supported 283 * #GNUNET_SYSERR if merging is not supported
395 */ 284 */
396int 285enum GNUNET_GenericReturnValue
397GNUNET_BLOCK_group_merge (struct GNUNET_BLOCK_Group *bg1, 286GNUNET_BLOCK_group_merge (struct GNUNET_BLOCK_Group *bg1,
398 struct GNUNET_BLOCK_Group *bg2); 287 struct GNUNET_BLOCK_Group *bg2);
399 288
@@ -410,4 +299,6 @@ GNUNET_BLOCK_group_merge (struct GNUNET_BLOCK_Group *bg1,
410 299
411/** @} */ /* end of group */ 300/** @} */ /* end of group */
412 301
302/** @} */ /* end of group addition */
303
413/* end of gnunet_block_lib.h */ 304/* end of gnunet_block_lib.h */
diff --git a/src/include/gnunet_block_plugin.h b/src/include/gnunet_block_plugin.h
index ee237ac03..16e93c780 100644
--- a/src/include/gnunet_block_plugin.h
+++ b/src/include/gnunet_block_plugin.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2010,2013,2017 GNUnet e.V. 3 Copyright (C) 2010, 2013, 2017, 2021, 2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup dht_libs DHT and support libraries
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -35,6 +38,7 @@
35#ifndef PLUGIN_BLOCK_H 38#ifndef PLUGIN_BLOCK_H
36#define PLUGIN_BLOCK_H 39#define PLUGIN_BLOCK_H
37 40
41
38#include "gnunet_util_lib.h" 42#include "gnunet_util_lib.h"
39#include "gnunet_block_lib.h" 43#include "gnunet_block_lib.h"
40 44
@@ -48,10 +52,10 @@
48 * @param seen_results_count number of entries in @a seen_results 52 * @param seen_results_count number of entries in @a seen_results
49 */ 53 */
50typedef void 54typedef void
51(*GNUNET_BLOCK_GroupMarkSeenFunction)(struct GNUNET_BLOCK_Group *bg, 55(*GNUNET_BLOCK_GroupMarkSeenFunction)(
52 const struct 56 struct GNUNET_BLOCK_Group *bg,
53 GNUNET_HashCode *seen_results, 57 const struct GNUNET_HashCode *seen_results,
54 unsigned int seen_results_count); 58 unsigned int seen_results_count);
55 59
56 60
57/** 61/**
@@ -63,7 +67,7 @@ typedef void
63 * @return #GNUNET_OK on success, #GNUNET_NO if the nonces were different and thus 67 * @return #GNUNET_OK on success, #GNUNET_NO if the nonces were different and thus
64 * we failed. 68 * we failed.
65 */ 69 */
66typedef int 70typedef enum GNUNET_GenericReturnValue
67(*GNUNET_BLOCK_GroupMergeFunction)(struct GNUNET_BLOCK_Group *bg1, 71(*GNUNET_BLOCK_GroupMergeFunction)(struct GNUNET_BLOCK_Group *bg1,
68 const struct GNUNET_BLOCK_Group *bg2); 72 const struct GNUNET_BLOCK_Group *bg2);
69 73
@@ -72,15 +76,13 @@ typedef int
72 * Serialize state of a block group. 76 * Serialize state of a block group.
73 * 77 *
74 * @param bg group to serialize 78 * @param bg group to serialize
75 * @param[out] nonce set to the nonce of the @a bg
76 * @param[out] raw_data set to the serialized state 79 * @param[out] raw_data set to the serialized state
77 * @param[out] raw_data_size set to the number of bytes in @a raw_data 80 * @param[out] raw_data_size set to the number of bytes in @a raw_data
78 * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not 81 * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not
79 * supported, #GNUNET_SYSERR on error 82 * supported, #GNUNET_SYSERR on error
80 */ 83 */
81typedef int 84typedef enum GNUNET_GenericReturnValue
82(*GNUNET_BLOCK_GroupSerializeFunction)(struct GNUNET_BLOCK_Group *bg, 85(*GNUNET_BLOCK_GroupSerializeFunction)(struct GNUNET_BLOCK_Group *bg,
83 uint32_t *nonce,
84 void **raw_data, 86 void **raw_data,
85 size_t *raw_data_size); 87 size_t *raw_data_size);
86 88
@@ -156,24 +158,54 @@ struct GNUNET_BLOCK_Group
156typedef struct GNUNET_BLOCK_Group * 158typedef struct GNUNET_BLOCK_Group *
157(*GNUNET_BLOCK_GroupCreateFunction)(void *cls, 159(*GNUNET_BLOCK_GroupCreateFunction)(void *cls,
158 enum GNUNET_BLOCK_Type type, 160 enum GNUNET_BLOCK_Type type,
159 uint32_t nonce,
160 const void *raw_data, 161 const void *raw_data,
161 size_t raw_data_size, 162 size_t raw_data_size,
162 va_list va); 163 va_list va);
163 164
164 165
165/** 166/**
166 * Function called to validate a reply or a request. For 167 * Function called to validate a query.
167 * request evaluation, simply pass "NULL" for the @a reply_block. 168 *
168 * Note that it is assumed that the reply has already been 169 * @param cls closure
169 * matched to the key (and signatures checked) as it would 170 * @param type block type
170 * be done with the "get_key" function. 171 * @param query original query (hash)
172 * @param xquery extrended query data (can be NULL, depending on type)
173 * @param xquery_size number of bytes in @a xquery
174 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not
175 */
176typedef enum GNUNET_GenericReturnValue
177(*GNUNET_BLOCK_QueryEvaluationFunction)(void *cls,
178 enum GNUNET_BLOCK_Type type,
179 const struct GNUNET_HashCode *query,
180 const void *xquery,
181 size_t xquery_size);
182
183
184/**
185 * Function called to validate a @a block for storage.
186 *
187 * @param cls closure
188 * @param type block type
189 * @param block block data to validate
190 * @param block_size number of bytes in @a block
191 * @return #GNUNET_OK if the @a block is fine, #GNUNET_NO if not, #GNUNET_SYSERR if the @a type is not supported
192 */
193typedef enum GNUNET_GenericReturnValue
194(*GNUNET_BLOCK_BlockEvaluationFunction)(void *cls,
195 enum GNUNET_BLOCK_Type type,
196 const void *block,
197 size_t block_size);
198
199
200/**
201 * Function called to validate a reply to a request. Note that it is assumed
202 * that the reply has already been matched to the key (and signatures checked)
203 * as it would be done with the GetKeyFunction and the
204 * BlockEvaluationFunction.
171 * 205 *
172 * @param cls closure 206 * @param cls closure
173 * @param ctx block context
174 * @param type block type 207 * @param type block type
175 * @param group which block group to use for evaluation 208 * @param group which block group to use for evaluation
176 * @param eo evaluation options to control evaluation
177 * @param query original query (hash) 209 * @param query original query (hash)
178 * @param xquery extrended query data (can be NULL, depending on type) 210 * @param xquery extrended query data (can be NULL, depending on type)
179 * @param xquery_size number of bytes in @a xquery 211 * @param xquery_size number of bytes in @a xquery
@@ -181,38 +213,37 @@ typedef struct GNUNET_BLOCK_Group *
181 * @param reply_block_size number of bytes in @a reply_block 213 * @param reply_block_size number of bytes in @a reply_block
182 * @return characterization of result 214 * @return characterization of result
183 */ 215 */
184typedef enum GNUNET_BLOCK_EvaluationResult 216typedef enum GNUNET_BLOCK_ReplyEvaluationResult
185(*GNUNET_BLOCK_EvaluationFunction)(void *cls, 217(*GNUNET_BLOCK_ReplyEvaluationFunction)(void *cls,
186 struct GNUNET_BLOCK_Context *ctx, 218 enum GNUNET_BLOCK_Type type,
187 enum GNUNET_BLOCK_Type type, 219 struct GNUNET_BLOCK_Group *group,
188 struct GNUNET_BLOCK_Group *group, 220 const struct GNUNET_HashCode *query,
189 enum GNUNET_BLOCK_EvaluationOptions eo, 221 const void *xquery,
190 const struct GNUNET_HashCode *query, 222 size_t xquery_size,
191 const void *xquery, 223 const void *reply_block,
192 size_t xquery_size, 224 size_t reply_block_size);
193 const void *reply_block,
194 size_t reply_block_size);
195 225
196 226
197/** 227/**
198 * Function called to obtain the key for a block. 228 * Function called to obtain the @a key for a block.
229 * If the @a block is malformed, the function should
230 * zero-out @a key and return #GNUNET_OK.
199 * 231 *
200 * @param cls closure 232 * @param cls closure
201 * @param type block type 233 * @param type block type
202 * @param block block to get the key for 234 * @param block block to get the @a key for
203 * @param block_size number of bytes in @a block 235 * @param block_size number of bytes in @a block
204 * @param key set to the key (query) for the given block 236 * @param[out] key set to the key (query) for the given block
205 * @return #GNUNET_YES on success, 237 * @return #GNUNET_YES on success,
206 * #GNUNET_NO if the block is malformed 238 * #GNUNET_NO if extracting a key for this @a type does not work
207 * #GNUNET_SYSERR if type not supported 239 * #GNUNET_SYSERR if @a type not supported
208 * (or if extracting a key from a block of this type does not work)
209 */ 240 */
210typedef int 241typedef enum GNUNET_GenericReturnValue
211(*GNUNET_BLOCK_GetKeyFunction) (void *cls, 242(*GNUNET_BLOCK_GetKeyFunction)(void *cls,
212 enum GNUNET_BLOCK_Type type, 243 enum GNUNET_BLOCK_Type type,
213 const void *block, 244 const void *block,
214 size_t block_size, 245 size_t block_size,
215 struct GNUNET_HashCode *key); 246 struct GNUNET_HashCode *key);
216 247
217 248
218/** 249/**
@@ -232,12 +263,6 @@ struct GNUNET_BLOCK_PluginFunctions
232 const enum GNUNET_BLOCK_Type *types; 263 const enum GNUNET_BLOCK_Type *types;
233 264
234 /** 265 /**
235 * Main function of a block plugin. Allows us to check if a
236 * block matches a query.
237 */
238 GNUNET_BLOCK_EvaluationFunction evaluate;
239
240 /**
241 * Obtain the key for a given block (if possible). 266 * Obtain the key for a given block (if possible).
242 */ 267 */
243 GNUNET_BLOCK_GetKeyFunction get_key; 268 GNUNET_BLOCK_GetKeyFunction get_key;
@@ -247,8 +272,26 @@ struct GNUNET_BLOCK_PluginFunctions
247 * context (i.e. to detect duplicates). 272 * context (i.e. to detect duplicates).
248 */ 273 */
249 GNUNET_BLOCK_GroupCreateFunction create_group; 274 GNUNET_BLOCK_GroupCreateFunction create_group;
275
276 /**
277 * Check that a query is well-formed.
278 */
279 GNUNET_BLOCK_QueryEvaluationFunction check_query;
280
281 /**
282 * Check that a block is well-formed.
283 */
284 GNUNET_BLOCK_BlockEvaluationFunction check_block;
285
286 /**
287 * Check that a reply block matches a query.
288 */
289 GNUNET_BLOCK_ReplyEvaluationFunction check_reply;
290
250}; 291};
251 292
252#endif 293#endif
253 294
254/** @} */ /* end of group */ 295/** @} */ /* end of group */
296
297/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_buffer_lib.h b/src/include/gnunet_buffer_lib.h
index 7239eccfb..e65981206 100644
--- a/src/include/gnunet_buffer_lib.h
+++ b/src/include/gnunet_buffer_lib.h
@@ -19,11 +19,19 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * Common buffer management functions. 26 * Common buffer management functions.
23 * 27 *
24 * @author Florian Dold 28 * @author Florian Dold
25 */ 29 */
26 30
31#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
32#error "Only <gnunet_util_lib.h> can be included directly."
33#endif
34
27#ifndef GNUNET_BUFFER_LIB_H 35#ifndef GNUNET_BUFFER_LIB_H
28#define GNUNET_BUFFER_LIB_H 36#define GNUNET_BUFFER_LIB_H
29 37
@@ -203,3 +211,5 @@ GNUNET_buffer_clear (struct GNUNET_Buffer *buf);
203 211
204 212
205#endif 213#endif
214
215/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_cadet_service.h b/src/include/gnunet_cadet_service.h
index f08c1572a..ab53d2bd8 100644
--- a/src/include/gnunet_cadet_service.h
+++ b/src/include/gnunet_cadet_service.h
@@ -18,6 +18,9 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup Backbone
22 * @{
23 *
21 * @author Christian Grothoff 24 * @author Christian Grothoff
22 * @author Bart Polot 25 * @author Bart Polot
23 * 26 *
@@ -42,8 +45,8 @@ extern "C" {
42#endif 45#endif
43#endif 46#endif
44 47
48
45#include "gnunet_util_lib.h" 49#include "gnunet_util_lib.h"
46#include "gnunet_transport_service.h"
47 50
48/** 51/**
49 * Version number of GNUnet-cadet API. 52 * Version number of GNUnet-cadet API.
@@ -309,7 +312,9 @@ union GNUNET_CADET_ChannelInfo
309 * Get information about a channel. 312 * Get information about a channel.
310 * 313 *
311 * @param channel Channel handle. 314 * @param channel Channel handle.
315 * @param option Query (GNUNET_CADET_OPTION_*)
312 * @param ... dependent on option, currently not used 316 * @param ... dependent on option, currently not used
317 *
313 * @return Union with an answer to the query. 318 * @return Union with an answer to the query.
314 */ 319 */
315const union GNUNET_CADET_ChannelInfo * 320const union GNUNET_CADET_ChannelInfo *
@@ -627,4 +632,6 @@ GNUNET_CADET_list_tunnels_cancel (struct GNUNET_CADET_ListTunnels *lt);
627 632
628/** @} */ /* end of group */ 633/** @} */ /* end of group */
629 634
635/** @} */ /* end of group addition */
636
630/* end of gnunet_cadet_service.h */ 637/* end of gnunet_cadet_service.h */
diff --git a/src/include/gnunet_child_management_lib.h b/src/include/gnunet_child_management_lib.h
index a35b37865..ab0ab93eb 100644
--- a/src/include/gnunet_child_management_lib.h
+++ b/src/include/gnunet_child_management_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs
28 * @{
29 *
22 * @file include/gnunet_child_management_lib.h 30 * @file include/gnunet_child_management_lib.h
23 * @brief GNUnet child management api 31 * @brief GNUnet child management api
24 * @author Christian Grothoff 32 * @author Christian Grothoff
@@ -41,8 +49,7 @@ struct GNUNET_ChildWaitHandle;
41 * @param cls handle for the callback 49 * @param cls handle for the callback
42 * @param type type of the process 50 * @param type type of the process
43 * @param exit_code status code of the process 51 * @param exit_code status code of the process
44 * 52 */
45*/
46typedef void 53typedef void
47(*GNUNET_ChildCompletedCallback)(void *cls, 54(*GNUNET_ChildCompletedCallback)(void *cls,
48 enum GNUNET_OS_ProcessStatusType type, 55 enum GNUNET_OS_ProcessStatusType type,
@@ -70,3 +77,5 @@ void
70GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh); 77GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh);
71 78
72#endif 79#endif
80
81/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_client_lib.h b/src/include/gnunet_client_lib.h
index 2ecd38b04..ab4c7d088 100644
--- a/src/include/gnunet_client_lib.h
+++ b/src/include/gnunet_client_lib.h
@@ -19,6 +19,13 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
26 * @addtogroup networking
27 * @{
28 *
22 * @author Christian Grothoff 29 * @author Christian Grothoff
23 * 30 *
24 * @file 31 * @file
@@ -32,6 +39,10 @@
32 * @{ 39 * @{
33 */ 40 */
34 41
42#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
43#error "Only <gnunet_util_lib.h> can be included directly."
44#endif
45
35#ifndef GNUNET_CLIENT_LIB_H 46#ifndef GNUNET_CLIENT_LIB_H
36#define GNUNET_CLIENT_LIB_H 47#define GNUNET_CLIENT_LIB_H
37 48
@@ -43,6 +54,7 @@ extern "C"
43#endif 54#endif
44#endif 55#endif
45 56
57
46#include "gnunet_mq_lib.h" 58#include "gnunet_mq_lib.h"
47 59
48 60
@@ -67,7 +79,8 @@ GNUNET_CLIENT_test (const struct GNUNET_CONFIGURATION_Handle *cfg,
67 * Create a message queue to connect to a GNUnet service. 79 * Create a message queue to connect to a GNUnet service.
68 * If handlers are specified, receive messages from the connection. 80 * If handlers are specified, receive messages from the connection.
69 * 81 *
70 * @param connection the client connection 82 * @param cfg our configuration
83 * @param service_name name of the service to connect to
71 * @param handlers handlers for receiving messages, can be NULL 84 * @param handlers handlers for receiving messages, can be NULL
72 * @param error_handler error handler 85 * @param error_handler error handler
73 * @param error_handler_cls closure for the @a error_handler 86 * @param error_handler_cls closure for the @a error_handler
@@ -93,4 +106,8 @@ GNUNET_CLIENT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
93 106
94/** @} */ /* end of group client */ 107/** @} */ /* end of group client */
95 108
109/** @} */ /* end of group addition */
110
111/** @} */ /* end of group addition */
112
96/* end of gnunet_client_lib.h */ 113/* end of gnunet_client_lib.h */
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 4472d3ee8..c5885e7c4 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2006-2021 GNUnet e.V. 3 Copyright (C) 2006-2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @file include/gnunet_common.h 26 * @file include/gnunet_common.h
23 * @brief commonly used definitions; globals in this file 27 * @brief commonly used definitions; globals in this file
24 * are exempt from the rule that the module name ("common") 28 * are exempt from the rule that the module name ("common")
@@ -36,28 +40,38 @@
36#ifndef GNUNET_COMMON_H 40#ifndef GNUNET_COMMON_H
37#define GNUNET_COMMON_H 41#define GNUNET_COMMON_H
38 42
43#include "gnunet_config.h"
44
45#include <stdbool.h>
39#include <stdlib.h> 46#include <stdlib.h>
40#if HAVE_SYS_SOCKET_H
41#include <sys/socket.h> 47#include <sys/socket.h>
42#endif 48#include <sys/un.h>
43#if HAVE_NETINET_IN_H
44#include <netinet/in.h> 49#include <netinet/in.h>
45#endif 50#include <arpa/inet.h>
46#ifdef HAVE_STDINT_H
47#include <stdint.h> 51#include <stdint.h>
48#endif
49#ifdef HAVE_STDARG_H
50#include <stdarg.h> 52#include <stdarg.h>
51#endif
52#ifdef HAVE_SYS_TYPES_H
53#include <sys/types.h> 53#include <sys/types.h>
54#endif
55#ifdef HAVE_SYS_SOCKET_H
56#include <sys/socket.h>
57#endif
58 54
55#if defined(__FreeBSD__)
56
57#include <sys/endian.h>
58#define bswap_32(x) bswap32 (x)
59#define bswap_64(x) bswap64 (x)
60
61#elif defined(__OpenBSD__)
62
63#define bswap_32(x) swap32 (x)
64#define bswap_64(x) swap64 (x)
59 65
60#ifdef HAVE_BYTESWAP_H 66#elif defined(__NetBSD__)
67
68#include <machine/bswap.h>
69#if defined(__BSWAP_RENAME) && ! defined(__bswap_32)
70#define bswap_32(x) bswap32 (x)
71#define bswap_64(x) bswap64 (x)
72#endif
73
74#elif defined(__linux__) || defined(GNU)
61#include <byteswap.h> 75#include <byteswap.h>
62#endif 76#endif
63 77
@@ -132,12 +146,6 @@ enum GNUNET_GenericReturnValue
132#endif 146#endif
133 147
134/** 148/**
135 * wrap va_arg for enums
136 */
137#define GNUNET_VA_ARG_ENUM(va, X) ((enum X) va_arg (va, int))
138
139
140/**
141 * @ingroup logging 149 * @ingroup logging
142 * define #GNUNET_EXTRA_LOGGING if using this header outside the GNUnet source 150 * define #GNUNET_EXTRA_LOGGING if using this header outside the GNUnet source
143 * tree where gnunet_config.h is unavailable 151 * tree where gnunet_config.h is unavailable
@@ -150,8 +158,7 @@ enum GNUNET_GenericReturnValue
150 * Endian operations 158 * Endian operations
151 */ 159 */
152 160
153#if __BYTE_ORDER == __LITTLE_ENDIAN 161#if defined(bswap_16) || defined(bswap_32) || defined(bswap_64)
154#ifdef HAVE_BYTESWAP_H
155#define BYTE_SWAP_16(x) bswap_16 (x) 162#define BYTE_SWAP_16(x) bswap_16 (x)
156#define BYTE_SWAP_32(x) bswap_32 (x) 163#define BYTE_SWAP_32(x) bswap_32 (x)
157#define BYTE_SWAP_64(x) bswap_64 (x) 164#define BYTE_SWAP_64(x) bswap_64 (x)
@@ -159,17 +166,22 @@ enum GNUNET_GenericReturnValue
159#define BYTE_SWAP_16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8)) 166#define BYTE_SWAP_16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))
160 167
161#define BYTE_SWAP_32(x) \ 168#define BYTE_SWAP_32(x) \
162 ((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \ 169 ((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \
163 | (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24)) 170 | (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24))
164 171
165#define BYTE_SWAP_64(x) \ 172#define BYTE_SWAP_64(x) \
166 ((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << 40) \ 173 ((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << \
167 | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) << 8) \ 174 40) \
168 | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) >> 24) \ 175 | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) \
169 | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) >> \ 176 << 8) \
170 56)) 177 | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) \
178 >> 24) \
179 | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) \
180 >> \
181 56))
171#endif 182#endif
172 183
184#if __BYTE_ORDER == __LITTLE_ENDIAN
173#define GNUNET_htobe16(x) BYTE_SWAP_16 (x) 185#define GNUNET_htobe16(x) BYTE_SWAP_16 (x)
174#define GNUNET_htole16(x) (x) 186#define GNUNET_htole16(x) (x)
175#define GNUNET_be16toh(x) BYTE_SWAP_16 (x) 187#define GNUNET_be16toh(x) BYTE_SWAP_16 (x)
@@ -471,7 +483,7 @@ GNUNET_get_log_call_status (int caller_level,
471 483
472#endif 484#endif
473 485
474 486/* *INDENT-OFF* */
475/** 487/**
476 * @ingroup logging 488 * @ingroup logging
477 * Main log function. 489 * Main log function.
@@ -481,13 +493,15 @@ GNUNET_get_log_call_status (int caller_level,
481 * @param ... arguments for format string 493 * @param ... arguments for format string
482 */ 494 */
483void 495void
484GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...) 496GNUNET_log_nocheck (enum GNUNET_ErrorType kind,
497 const char *message,
498 ...)
485__attribute__ ((format (printf, 2, 3))); 499__attribute__ ((format (printf, 2, 3)));
486 500
487/* from glib */ 501/* from glib */
488#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) 502#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
489#define _GNUNET_BOOLEAN_EXPR(expr) \ 503#define _GNUNET_BOOLEAN_EXPR(expr) \
490 __extension__ ({ \ 504 __extension__ ({ \
491 int _gnunet_boolean_var_; \ 505 int _gnunet_boolean_var_; \
492 if (expr) \ 506 if (expr) \
493 _gnunet_boolean_var_ = 1; \ 507 _gnunet_boolean_var_ = 1; \
@@ -505,6 +519,7 @@ __attribute__ ((format (printf, 2, 3)));
505#if ! defined(GNUNET_LOG_CALL_STATUS) 519#if ! defined(GNUNET_LOG_CALL_STATUS)
506#define GNUNET_LOG_CALL_STATUS -1 520#define GNUNET_LOG_CALL_STATUS -1
507#endif 521#endif
522/* *INDENT-ON* */
508 523
509 524
510/** 525/**
@@ -526,56 +541,56 @@ __attribute__ ((format (printf, 3, 4)));
526 541
527#if ! defined(GNUNET_CULL_LOGGING) 542#if ! defined(GNUNET_CULL_LOGGING)
528#define GNUNET_log_from(kind, comp, ...) \ 543#define GNUNET_log_from(kind, comp, ...) \
529 do \ 544 do \
530 { \ 545 { \
531 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \ 546 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
532 if ((GNUNET_EXTRA_LOGGING > 0) || \ 547 if ((GNUNET_EXTRA_LOGGING > 0) || \
533 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ 548 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
534 { \ 549 { \
535 if (GN_UNLIKELY (log_call_enabled == -1)) \ 550 if (GN_UNLIKELY (log_call_enabled == -1)) \
536 log_call_enabled = \ 551 log_call_enabled = \
537 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \ 552 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
538 (comp), \ 553 (comp), \
539 __FILE__, \ 554 __FILE__, \
540 __FUNCTION__, \ 555 __FUNCTION__, \
541 __LINE__); \ 556 __LINE__); \
542 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ 557 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
543 { \ 558 { \
544 GNUNET_log_skip (-1, GNUNET_NO); \ 559 GNUNET_log_skip (-1, GNUNET_NO); \
545 } \ 560 } \
546 else \ 561 else \
547 { \ 562 { \
548 if (GN_UNLIKELY (log_call_enabled)) \ 563 if (GN_UNLIKELY (log_call_enabled)) \
549 GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \ 564 GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
550 } \ 565 } \
551 } \ 566 } \
552 } while (0) 567 } while (0)
553 568
554#define GNUNET_log(kind, ...) \ 569#define GNUNET_log(kind, ...) \
555 do \ 570 do \
556 { \ 571 { \
557 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \ 572 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
558 if ((GNUNET_EXTRA_LOGGING > 0) || \ 573 if ((GNUNET_EXTRA_LOGGING > 0) || \
559 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ 574 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
560 { \ 575 { \
561 if (GN_UNLIKELY (log_call_enabled == -1)) \ 576 if (GN_UNLIKELY (log_call_enabled == -1)) \
562 log_call_enabled = \ 577 log_call_enabled = \
563 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \ 578 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
564 NULL, \ 579 NULL, \
565 __FILE__, \ 580 __FILE__, \
566 __FUNCTION__, \ 581 __FUNCTION__, \
567 __LINE__); \ 582 __LINE__); \
568 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ 583 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
569 { \ 584 { \
570 GNUNET_log_skip (-1, GNUNET_NO); \ 585 GNUNET_log_skip (-1, GNUNET_NO); \
571 } \ 586 } \
572 else \ 587 else \
573 { \ 588 { \
574 if (GN_UNLIKELY (log_call_enabled)) \ 589 if (GN_UNLIKELY (log_call_enabled)) \
575 GNUNET_log_nocheck ((kind), __VA_ARGS__); \ 590 GNUNET_log_nocheck ((kind), __VA_ARGS__); \
576 } \ 591 } \
577 } \ 592 } \
578 } while (0) 593 } while (0)
579#else 594#else
580#define GNUNET_log(...) 595#define GNUNET_log(...)
581#define GNUNET_log_from(...) 596#define GNUNET_log_from(...)
@@ -623,6 +638,31 @@ GNUNET_abort_ (void) GNUNET_NORETURN;
623 638
624 639
625/** 640/**
641 * Convert a buffer to an 8-character string
642 * representative of the contents. This is used
643 * for logging binary data when debugging.
644 *
645 * @param buf buffer to log
646 * @param buf_size number of bytes in @a buf
647 * @return text representation of buf, valid until next
648 * call to this function
649 */
650const char *
651GNUNET_b2s (const void *buf,
652 size_t buf_size);
653
654
655/**
656 * Convert a fixed-sized object to a string using
657 * #GNUNET_b2s().
658 *
659 * @param obj address of object to convert
660 * @return string representing the binary obj buffer
661 */
662#define GNUNET_B2S(obj) GNUNET_b2s ((obj), sizeof (*(obj)))
663
664
665/**
626 * @ingroup logging 666 * @ingroup logging
627 * Ignore the next @a n calls to the log function. 667 * Ignore the next @a n calls to the log function.
628 * 668 *
@@ -642,8 +682,10 @@ GNUNET_log_skip (int n, int check_reset);
642 * @param logfile change logging to logfile (use NULL to keep stderr) 682 * @param logfile change logging to logfile (use NULL to keep stderr)
643 * @return #GNUNET_OK on success, #GNUNET_SYSERR if logfile could not be opened 683 * @return #GNUNET_OK on success, #GNUNET_SYSERR if logfile could not be opened
644 */ 684 */
645int 685enum GNUNET_GenericReturnValue
646GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile); 686GNUNET_log_setup (const char *comp,
687 const char *loglevel,
688 const char *logfile);
647 689
648 690
649/** 691/**
@@ -657,7 +699,8 @@ GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile);
657 * @param logger_cls closure for @a logger 699 * @param logger_cls closure for @a logger
658 */ 700 */
659void 701void
660GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls); 702GNUNET_logger_add (GNUNET_Logger logger,
703 void *logger_cls);
661 704
662 705
663/** 706/**
@@ -668,7 +711,8 @@ GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls);
668 * @param logger_cls closure for @a logger 711 * @param logger_cls closure for @a logger
669 */ 712 */
670void 713void
671GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls); 714GNUNET_logger_remove (GNUNET_Logger logger,
715 void *logger_cls);
672 716
673 717
674/** 718/**
@@ -883,36 +927,37 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
883 * @ingroup logging 927 * @ingroup logging
884 * Use this for fatal errors that cannot be handled 928 * Use this for fatal errors that cannot be handled
885 */ 929 */
886#if __GNUC__ >= 6 || __clang_major__ >= 6 930#if __GNUC__ >= 6 || __clang_major__ >= 6
887#define GNUNET_assert(cond) \ 931#define GNUNET_assert(cond) \
888 do \ 932 do \
889 { \ 933 { \
890 _Pragma("GCC diagnostic push") \ 934 _Pragma("GCC diagnostic push") \
891 _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \ 935 _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \
892 if (! (cond)) \ 936 if (! (cond)) \
893 { \ 937 { \
894 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ 938 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
895 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ 939 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
896 __FILE__, \ 940 __FILE__, \
897 __LINE__); \ 941 __LINE__); \
898 GNUNET_abort_ (); \ 942 GNUNET_abort_ (); \
899 } \ 943 } \
900 _Pragma("GCC diagnostic pop") \ 944 _Pragma("GCC diagnostic pop") \
901 } while (0) 945 } while (0)
902#else 946#else
903/* older GCC/clangs do not support -Wtautological-compare */ 947/* older GCC/clangs do not support -Wtautological-compare */
904#define GNUNET_assert(cond) \ 948#define GNUNET_assert(cond) \
905 do \ 949 do \
906 { \ 950 { \
907 if (! (cond)) \ 951 if (! (cond)) \
908 { \ 952 { \
909 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ 953 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
910 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ 954 dgettext ("gnunet", \
911 __FILE__, \ 955 "Assertion failed at %s:%d. Aborting.\n"), \
912 __LINE__); \ 956 __FILE__, \
913 GNUNET_abort_ (); \ 957 __LINE__); \
914 } \ 958 GNUNET_abort_ (); \
915 } while (0) 959 } \
960 } while (0)
916#endif 961#endif
917 962
918/** 963/**
@@ -920,17 +965,18 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
920 * Use this for fatal errors that cannot be handled 965 * Use this for fatal errors that cannot be handled
921 */ 966 */
922#define GNUNET_assert_at(cond, f, l) \ 967#define GNUNET_assert_at(cond, f, l) \
923 do \ 968 do \
924 { \ 969 { \
925 if (! (cond)) \ 970 if (! (cond)) \
926 { \ 971 { \
927 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ 972 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
928 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ 973 dgettext ("gnunet", \
929 f, \ 974 "Assertion failed at %s:%d. Aborting.\n"), \
930 l); \ 975 f, \
931 GNUNET_abort_ (); \ 976 l); \
932 } \ 977 GNUNET_abort_ (); \
933 } while (0) 978 } \
979 } while (0)
934 980
935 981
936/** 982/**
@@ -941,21 +987,23 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
941 * @param comp Component string to use for logging 987 * @param comp Component string to use for logging
942 */ 988 */
943#define GNUNET_assert_from(cond, comp) \ 989#define GNUNET_assert_from(cond, comp) \
944 do \ 990 do \
945 { \ 991 { \
946 if (! (cond)) \ 992 if (! (cond)) \
947 { \ 993 { \
948 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \ 994 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \
949 comp, \ 995 comp, \
950 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \ 996 dgettext ("gnunet", \
951 __FILE__, \ 997 "Assertion failed at %s:%d. Aborting.\n") \
952 __LINE__); \ 998 , \
953 GNUNET_abort_ (); \ 999 __FILE__, \
954 } \ 1000 __LINE__); \
955 } while (0) 1001 GNUNET_abort_ (); \
956 1002 } \
957 1003 } while (0)
958#if HAVE_STATIC_ASSERT 1004
1005
1006#ifdef _Static_assert
959/** 1007/**
960 * Assertion to be checked (if supported by C compiler) at 1008 * Assertion to be checked (if supported by C compiler) at
961 * compile time, otherwise checked at runtime and resulting 1009 * compile time, otherwise checked at runtime and resulting
@@ -983,16 +1031,16 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
983 * not fatal (can be handled) but should not occur. 1031 * not fatal (can be handled) but should not occur.
984 */ 1032 */
985#define GNUNET_break(cond) \ 1033#define GNUNET_break(cond) \
986 do \ 1034 do \
987 { \ 1035 { \
988 if (! (cond)) \ 1036 if (! (cond)) \
989 { \ 1037 { \
990 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ 1038 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
991 dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \ 1039 dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \
992 __FILE__, \ 1040 __FILE__, \
993 __LINE__); \ 1041 __LINE__); \
994 } \ 1042 } \
995 } while (0) 1043 } while (0)
996 1044
997 1045
998/** 1046/**
@@ -1005,16 +1053,17 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
1005 * development and testing. "OP == other peer". 1053 * development and testing. "OP == other peer".
1006 */ 1054 */
1007#define GNUNET_break_op(cond) \ 1055#define GNUNET_break_op(cond) \
1008 do \ 1056 do \
1009 { \ 1057 { \
1010 if (! (cond)) \ 1058 if (! (cond)) \
1011 { \ 1059 { \
1012 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \ 1060 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \
1013 dgettext ("gnunet", "External protocol violation detected at %s:%d.\n"), \ 1061 dgettext ("gnunet", \
1014 __FILE__, \ 1062 "External protocol violation detected at %s:%d.\n"), \
1015 __LINE__); \ 1063 __FILE__, \
1016 } \ 1064 __LINE__); \
1017 } while (0) 1065 } \
1066 } while (0)
1018 1067
1019 1068
1020/** 1069/**
@@ -1024,15 +1073,16 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
1024 * by strerror(errno). 1073 * by strerror(errno).
1025 */ 1074 */
1026#define GNUNET_log_strerror(level, cmd) \ 1075#define GNUNET_log_strerror(level, cmd) \
1027 do \ 1076 do \
1028 { \ 1077 { \
1029 GNUNET_log (level, \ 1078 GNUNET_log (level, \
1030 dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \ 1079 dgettext ("gnunet", \
1031 cmd, \ 1080 "`%s' failed at %s:%d with error: %s\n"), \
1032 __FILE__, \ 1081 cmd, \
1033 __LINE__, \ 1082 __FILE__, \
1034 strerror (errno)); \ 1083 __LINE__, \
1035 } while (0) 1084 strerror (errno)); \
1085 } while (0)
1036 1086
1037 1087
1038/** 1088/**
@@ -1042,16 +1092,17 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
1042 * by strerror(errno). 1092 * by strerror(errno).
1043 */ 1093 */
1044#define GNUNET_log_from_strerror(level, component, cmd) \ 1094#define GNUNET_log_from_strerror(level, component, cmd) \
1045 do \ 1095 do \
1046 { \ 1096 { \
1047 GNUNET_log_from (level, \ 1097 GNUNET_log_from (level, \
1048 component, \ 1098 component, \
1049 dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \ 1099 dgettext ("gnunet", \
1050 cmd, \ 1100 "`%s' failed at %s:%d with error: %s\n"), \
1051 __FILE__, \ 1101 cmd, \
1052 __LINE__, \ 1102 __FILE__, \
1053 strerror (errno)); \ 1103 __LINE__, \
1054 } while (0) 1104 strerror (errno)); \
1105 } while (0)
1055 1106
1056 1107
1057/** 1108/**
@@ -1061,16 +1112,17 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
1061 * by strerror(errno). 1112 * by strerror(errno).
1062 */ 1113 */
1063#define GNUNET_log_strerror_file(level, cmd, filename) \ 1114#define GNUNET_log_strerror_file(level, cmd, filename) \
1064 do \ 1115 do \
1065 { \ 1116 { \
1066 GNUNET_log (level, \ 1117 GNUNET_log (level, \
1067 dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \ 1118 dgettext ("gnunet", \
1068 cmd, \ 1119 "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1069 filename, \ 1120 cmd, \
1070 __FILE__, \ 1121 filename, \
1071 __LINE__, \ 1122 __FILE__, \
1072 strerror (errno)); \ 1123 __LINE__, \
1073 } while (0) 1124 strerror (errno)); \
1125 } while (0)
1074 1126
1075 1127
1076/** 1128/**
@@ -1080,17 +1132,18 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
1080 * by strerror(errno). 1132 * by strerror(errno).
1081 */ 1133 */
1082#define GNUNET_log_from_strerror_file(level, component, cmd, filename) \ 1134#define GNUNET_log_from_strerror_file(level, component, cmd, filename) \
1083 do \ 1135 do \
1084 { \ 1136 { \
1085 GNUNET_log_from (level, \ 1137 GNUNET_log_from (level, \
1086 component, \ 1138 component, \
1087 dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \ 1139 dgettext ("gnunet", \
1088 cmd, \ 1140 "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1089 filename, \ 1141 cmd, \
1090 __FILE__, \ 1142 filename, \
1091 __LINE__, \ 1143 __FILE__, \
1092 strerror (errno)); \ 1144 __LINE__, \
1093 } while (0) 1145 strerror (errno)); \
1146 } while (0)
1094 1147
1095/* ************************* endianness conversion ****************** */ 1148/* ************************* endianness conversion ****************** */
1096 1149
@@ -1183,7 +1236,7 @@ GNUNET_ntoh_double (double d);
1183 * the first element! 1236 * the first element!
1184 */ 1237 */
1185#define GNUNET_memcmp(a, b) \ 1238#define GNUNET_memcmp(a, b) \
1186 ({ \ 1239 ({ \
1187 const typeof (*b) * _a = (a); \ 1240 const typeof (*b) * _a = (a); \
1188 const typeof (*a) * _b = (b); \ 1241 const typeof (*a) * _b = (b); \
1189 memcmp (_a, _b, sizeof(*a)); \ 1242 memcmp (_a, _b, sizeof(*a)); \
@@ -1212,7 +1265,7 @@ GNUNET_memcmp_ct_ (const void *b1,
1212 * the first element! 1265 * the first element!
1213 */ 1266 */
1214#define GNUNET_memcmp_priv(a, b) \ 1267#define GNUNET_memcmp_priv(a, b) \
1215 ({ \ 1268 ({ \
1216 const typeof (*b) * _a = (a); \ 1269 const typeof (*b) * _a = (a); \
1217 const typeof (*a) * _b = (b); \ 1270 const typeof (*a) * _b = (b); \
1218 GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \ 1271 GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \
@@ -1225,9 +1278,9 @@ GNUNET_memcmp_ct_ (const void *b1,
1225 * @param a pointer to @a n bytes which should be tested for the 1278 * @param a pointer to @a n bytes which should be tested for the
1226 * entire memory being zero'ed out. 1279 * entire memory being zero'ed out.
1227 * @param n number of bytes in @a to be tested 1280 * @param n number of bytes in @a to be tested
1228 * @return GNUNET_YES if a is zero, GNUNET_NO otherwise 1281 * @return true if @a a is zero, false_NO otherwise
1229 */ 1282 */
1230enum GNUNET_GenericReturnValue 1283bool
1231GNUNET_is_zero_ (const void *a, 1284GNUNET_is_zero_ (const void *a,
1232 size_t n); 1285 size_t n);
1233 1286
@@ -1240,7 +1293,7 @@ GNUNET_is_zero_ (const void *a,
1240 * @return GNUNET_YES if a is zero, GNUNET_NO otherwise 1293 * @return GNUNET_YES if a is zero, GNUNET_NO otherwise
1241 */ 1294 */
1242#define GNUNET_is_zero(a) \ 1295#define GNUNET_is_zero(a) \
1243 GNUNET_is_zero_ (a, sizeof (*a)) 1296 GNUNET_is_zero_ ((a), sizeof (*(a)))
1244 1297
1245 1298
1246/** 1299/**
@@ -1253,15 +1306,16 @@ GNUNET_is_zero_ (const void *a,
1253 * @param n number of bytes to copy 1306 * @param n number of bytes to copy
1254 */ 1307 */
1255#define GNUNET_memcpy(dst, src, n) \ 1308#define GNUNET_memcpy(dst, src, n) \
1256 do \ 1309 do \
1257 { \ 1310 { \
1258 if (0 != n) \ 1311 if (0 != n) \
1259 { \ 1312 { \
1260 (void) memcpy (dst, src, n); \ 1313 (void) memcpy (dst, src, n); \
1261 } \ 1314 } \
1262 } while (0) 1315 } while (0)
1263 1316
1264 1317
1318/* *INDENT-OFF* */
1265/** 1319/**
1266 * @ingroup memory 1320 * @ingroup memory
1267 * Allocate a size @a n array with structs or unions of the given @a type. 1321 * Allocate a size @a n array with structs or unions of the given @a type.
@@ -1275,6 +1329,7 @@ GNUNET_is_zero_ (const void *a,
1275 GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \ 1329 GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \
1276 (type *) GNUNET_malloc ((n) * sizeof(type)); \ 1330 (type *) GNUNET_malloc ((n) * sizeof(type)); \
1277 }) 1331 })
1332/* *INDENT-ON* */
1278 1333
1279/** 1334/**
1280 * @ingroup memory 1335 * @ingroup memory
@@ -1286,7 +1341,7 @@ GNUNET_is_zero_ (const void *a,
1286 * @param type name of the struct or union, i.e. pass 'struct Foo'. 1341 * @param type name of the struct or union, i.e. pass 'struct Foo'.
1287 */ 1342 */
1288#define GNUNET_new_array_2d(n, m, type) \ 1343#define GNUNET_new_array_2d(n, m, type) \
1289 (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__) 1344 (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__)
1290 1345
1291/** 1346/**
1292 * @ingroup memory 1347 * @ingroup memory
@@ -1299,7 +1354,8 @@ GNUNET_is_zero_ (const void *a,
1299 * @param type name of the struct or union, i.e. pass 'struct Foo'. 1354 * @param type name of the struct or union, i.e. pass 'struct Foo'.
1300 */ 1355 */
1301#define GNUNET_new_array_3d(n, m, o, type) \ 1356#define GNUNET_new_array_3d(n, m, o, type) \
1302 (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, __LINE__) 1357 (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, \
1358 __LINE__)
1303 1359
1304/** 1360/**
1305 * @ingroup memory 1361 * @ingroup memory
@@ -1331,7 +1387,7 @@ GNUNET_is_zero_ (const void *a,
1331 * @return pointer to size bytes of memory, NULL if we do not have enough memory 1387 * @return pointer to size bytes of memory, NULL if we do not have enough memory
1332 */ 1388 */
1333#define GNUNET_malloc_large(size) \ 1389#define GNUNET_malloc_large(size) \
1334 GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__) 1390 GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__)
1335 1391
1336 1392
1337/** 1393/**
@@ -1344,7 +1400,7 @@ GNUNET_is_zero_ (const void *a,
1344 * @return pointer to size bytes of memory 1400 * @return pointer to size bytes of memory
1345 */ 1401 */
1346#define GNUNET_realloc(ptr, size) \ 1402#define GNUNET_realloc(ptr, size) \
1347 GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__) 1403 GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__)
1348 1404
1349 1405
1350/** 1406/**
@@ -1371,8 +1427,8 @@ GNUNET_is_zero_ (const void *a,
1371 * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. NULL is allowed. 1427 * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. NULL is allowed.
1372 */ 1428 */
1373#define GNUNET_free(ptr) do { \ 1429#define GNUNET_free(ptr) do { \
1374 GNUNET_xfree_ (ptr, __FILE__, __LINE__); \ 1430 GNUNET_xfree_ (ptr, __FILE__, __LINE__); \
1375 ptr = NULL; \ 1431 ptr = NULL; \
1376} while (0) 1432} while (0)
1377 1433
1378 1434
@@ -1386,6 +1442,7 @@ GNUNET_is_zero_ (const void *a,
1386 */ 1442 */
1387#define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__) 1443#define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__)
1388 1444
1445
1389/** 1446/**
1390 * @ingroup memory 1447 * @ingroup memory
1391 * Wrapper around #GNUNET_xstrndup_. Makes a partial copy of the string 1448 * Wrapper around #GNUNET_xstrndup_. Makes a partial copy of the string
@@ -1396,7 +1453,7 @@ GNUNET_is_zero_ (const void *a,
1396 * @return a partial copy of the string including zero-termination 1453 * @return a partial copy of the string including zero-termination
1397 */ 1454 */
1398#define GNUNET_strndup(a, length) \ 1455#define GNUNET_strndup(a, length) \
1399 GNUNET_xstrndup_ (a, length, __FILE__, __LINE__) 1456 GNUNET_xstrndup_ (a, length, __FILE__, __LINE__)
1400 1457
1401/** 1458/**
1402 * @ingroup memory 1459 * @ingroup memory
@@ -1434,12 +1491,12 @@ GNUNET_is_zero_ (const void *a,
1434 * free the vector (then, arr will be NULL afterwards). 1491 * free the vector (then, arr will be NULL afterwards).
1435 */ 1492 */
1436#define GNUNET_array_grow(arr, size, tsize) \ 1493#define GNUNET_array_grow(arr, size, tsize) \
1437 GNUNET_xgrow_ ((void **) &(arr), \ 1494 GNUNET_xgrow_ ((void **) &(arr), \
1438 sizeof((arr)[0]), \ 1495 sizeof((arr)[0]), \
1439 &size, \ 1496 &size, \
1440 tsize, \ 1497 tsize, \
1441 __FILE__, \ 1498 __FILE__, \
1442 __LINE__) 1499 __LINE__)
1443 1500
1444/** 1501/**
1445 * @ingroup memory 1502 * @ingroup memory
@@ -1455,12 +1512,12 @@ GNUNET_is_zero_ (const void *a,
1455 * @param element the element that will be appended to the array 1512 * @param element the element that will be appended to the array
1456 */ 1513 */
1457#define GNUNET_array_append(arr, len, element) \ 1514#define GNUNET_array_append(arr, len, element) \
1458 do \ 1515 do \
1459 { \ 1516 { \
1460 GNUNET_assert ((len) + 1 > (len)); \ 1517 GNUNET_assert ((len) + 1 > (len)); \
1461 GNUNET_array_grow (arr, len, len + 1); \ 1518 GNUNET_array_grow (arr, len, len + 1); \
1462 (arr) [len - 1] = element; \ 1519 (arr) [len - 1] = element; \
1463 } while (0) 1520 } while (0)
1464 1521
1465 1522
1466/** 1523/**
@@ -1481,21 +1538,21 @@ GNUNET_is_zero_ (const void *a,
1481 * will be updated to reflect the new address. The TYPE of 1538 * will be updated to reflect the new address. The TYPE of
1482 * arr is important since size is the number of elements and 1539 * arr is important since size is the number of elements and
1483 * not the size in bytes 1540 * not the size in bytes
1484 * @param len the number of elements in the existing vector (number 1541 * @param len2 the number of elements in the existing vector (number
1485 * of elements to copy over), will be updated with the new 1542 * of elements to copy over), will be updated with the new
1486 * array size 1543 * array size
1487 1544
1488 */ 1545 */
1489#define GNUNET_array_concatenate(arr1, len1, arr2, len2) \ 1546#define GNUNET_array_concatenate(arr1, len1, arr2, len2) \
1490 do \ 1547 do \
1491 { \ 1548 { \
1492 const typeof (*arr2) * _a1 = (arr1); \ 1549 const typeof (*arr2) * _a1 = (arr1); \
1493 const typeof (*arr1) * _a2 = (arr2); \ 1550 const typeof (*arr1) * _a2 = (arr2); \
1494 GNUNET_assert ((len1) + (len2) >= (len1)); \ 1551 GNUNET_assert ((len1) + (len2) >= (len1)); \
1495 GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \ 1552 GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \
1496 GNUNET_array_grow (arr1, len1, (len1) + (len2)); \ 1553 GNUNET_array_grow (arr1, len1, (len1) + (len2)); \
1497 memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \ 1554 memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \
1498 } while (0) 1555 } while (0)
1499 1556
1500 1557
1501/** 1558/**
@@ -1546,7 +1603,9 @@ __attribute__ ((format (printf, 2, 3)));
1546 * @return allocated memory, never NULL 1603 * @return allocated memory, never NULL
1547 */ 1604 */
1548void * 1605void *
1549GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber); 1606GNUNET_xmalloc_ (size_t size,
1607 const char *filename,
1608 int linenumber);
1550 1609
1551 1610
1552/** 1611/**
@@ -1626,7 +1685,9 @@ GNUNET_xmemdup_ (const void *buf,
1626 * @return pointer to size bytes of memory, NULL if we do not have enough memory 1685 * @return pointer to size bytes of memory, NULL if we do not have enough memory
1627 */ 1686 */
1628void * 1687void *
1629GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber); 1688GNUNET_xmalloc_unchecked_ (size_t size,
1689 const char *filename,
1690 int linenumber);
1630 1691
1631 1692
1632/** 1693/**
@@ -1634,7 +1695,10 @@ GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber);
1634 * memory is available. 1695 * memory is available.
1635 */ 1696 */
1636void * 1697void *
1637GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber); 1698GNUNET_xrealloc_ (void *ptr,
1699 size_t n,
1700 const char *filename,
1701 int linenumber);
1638 1702
1639 1703
1640/** 1704/**
@@ -1647,7 +1711,9 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber);
1647 * @param linenumber line where this call is being made (for debugging) 1711 * @param linenumber line where this call is being made (for debugging)
1648 */ 1712 */
1649void 1713void
1650GNUNET_xfree_ (void *ptr, const char *filename, int linenumber); 1714GNUNET_xfree_ (void *ptr,
1715 const char *filename,
1716 int linenumber);
1651 1717
1652 1718
1653/** 1719/**
@@ -1658,7 +1724,9 @@ GNUNET_xfree_ (void *ptr, const char *filename, int linenumber);
1658 * @return the duplicated string 1724 * @return the duplicated string
1659 */ 1725 */
1660char * 1726char *
1661GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber); 1727GNUNET_xstrdup_ (const char *str,
1728 const char *filename,
1729 int linenumber);
1662 1730
1663/** 1731/**
1664 * Dup partially a string. Don't call GNUNET_xstrndup_ directly. Use the #GNUNET_strndup macro. 1732 * Dup partially a string. Don't call GNUNET_xstrndup_ directly. Use the #GNUNET_strndup macro.
@@ -1714,7 +1782,7 @@ GNUNET_copy_message (const struct GNUNET_MessageHeader *msg);
1714 * Set the async scope for the current thread. 1782 * Set the async scope for the current thread.
1715 * 1783 *
1716 * @param aid the async scope identifier 1784 * @param aid the async scope identifier
1717 * @param old_scope[out] location to save the old scope 1785 * @param[out] old_scope location to save the old scope
1718 */ 1786 */
1719void 1787void
1720GNUNET_async_scope_enter (const struct GNUNET_AsyncScopeId *aid, 1788GNUNET_async_scope_enter (const struct GNUNET_AsyncScopeId *aid,
@@ -1828,6 +1896,8 @@ enum GNUNET_SCHEDULER_Priority
1828}; 1896};
1829 1897
1830 1898
1899/* *INDENT-OFF* */
1900
1831#if 0 /* keep Emacsens' auto-indent happy */ 1901#if 0 /* keep Emacsens' auto-indent happy */
1832{ 1902{
1833#endif 1903#endif
diff --git a/src/include/gnunet_config.h.in b/src/include/gnunet_config.h.in
new file mode 100644
index 000000000..5dff759ae
--- /dev/null
+++ b/src/include/gnunet_config.h.in
@@ -0,0 +1,58 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2022 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21#ifndef GNUNET_CONFIG_H
22#define GNUNET_CONFIG_H
23
24/**
25 * @author Martin Schanzenbach
26 *
27 * @file
28 * Convenience header including public (!) information on the
29 * installed GNUnet configuration.
30 *
31 */
32
33/* The version of GNUnet */
34#define GNUNET_VERSION "@gnunet_version@"
35
36/* Major version */
37#define GNUNET_MAJOR_VERSION @gnunet_major_version@
38
39/* Micro version */
40#define GNUNET_MINOR_VERSION @gnunet_minor_version@
41
42/* Mico version */
43#define GNUNET_MICRO_VERSION @gnunet_micro_version@
44
45/* Set to 1 is this is an experimental build */
46#define GNUNET_EXPERIMENTAL @enable_experimental@
47
48/* Set to 1 if GnuTLS has DANE support */
49#define GNUNET_CURL_GNUTLS @curl_gnutls@
50
51/**
52 * Set to 1 if file-sharing meta data parsing is built with
53 * libextractor, which means that callers to the API must use also use
54 * libextractor.
55 */
56#define GNUNET_FS_EXTRACTOR_ENABLED @extractor@
57
58#endif
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h
index 570546b68..132172516 100644
--- a/src/include/gnunet_configuration_lib.h
+++ b/src/include/gnunet_configuration_lib.h
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * 27 *
24 * @file 28 * @file
@@ -31,6 +35,7 @@
31#ifndef GNUNET_CONFIGURATION_LIB_H 35#ifndef GNUNET_CONFIGURATION_LIB_H
32#define GNUNET_CONFIGURATION_LIB_H 36#define GNUNET_CONFIGURATION_LIB_H
33 37
38
34#include "gnunet_time_lib.h" 39#include "gnunet_time_lib.h"
35 40
36#ifdef __cplusplus 41#ifdef __cplusplus
@@ -61,7 +66,8 @@ GNUNET_CONFIGURATION_create (void);
61 * @return duplicate configuration 66 * @return duplicate configuration
62 */ 67 */
63struct GNUNET_CONFIGURATION_Handle * 68struct GNUNET_CONFIGURATION_Handle *
64GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg); 69GNUNET_CONFIGURATION_dup (
70 const struct GNUNET_CONFIGURATION_Handle *cfg);
65 71
66 72
67/** 73/**
@@ -70,7 +76,8 @@ GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg);
70 * @param cfg configuration to destroy 76 * @param cfg configuration to destroy
71 */ 77 */
72void 78void
73GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg); 79GNUNET_CONFIGURATION_destroy (
80 struct GNUNET_CONFIGURATION_Handle *cfg);
74 81
75 82
76/** 83/**
@@ -83,8 +90,9 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg);
83 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 90 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
84 */ 91 */
85enum GNUNET_GenericReturnValue 92enum GNUNET_GenericReturnValue
86GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, 93GNUNET_CONFIGURATION_load (
87 const char *filename); 94 struct GNUNET_CONFIGURATION_Handle *cfg,
95 const char *filename);
88 96
89 97
90/** 98/**
@@ -96,8 +104,9 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
96 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 104 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
97 */ 105 */
98enum GNUNET_GenericReturnValue 106enum GNUNET_GenericReturnValue
99GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, 107GNUNET_CONFIGURATION_load_from (
100 const char *defaults_d); 108 struct GNUNET_CONFIGURATION_Handle *cfg,
109 const char *defaults_d);
101 110
102 111
103/** 112/**
@@ -133,8 +142,9 @@ GNUNET_CONFIGURATION_default_filename (void);
133 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 142 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
134 */ 143 */
135enum GNUNET_GenericReturnValue 144enum GNUNET_GenericReturnValue
136GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, 145GNUNET_CONFIGURATION_parse (
137 const char *filename); 146 struct GNUNET_CONFIGURATION_Handle *cfg,
147 const char *filename);
138 148
139 149
140/** 150/**
@@ -146,8 +156,9 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
146 * present. This memory should be freed by the caller 156 * present. This memory should be freed by the caller
147 */ 157 */
148char * 158char *
149GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, 159GNUNET_CONFIGURATION_serialize (
150 size_t *size); 160 const struct GNUNET_CONFIGURATION_Handle *cfg,
161 size_t *size);
151 162
152 163
153/** 164/**
@@ -160,8 +171,9 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
160 * present. This memory should be freed by the caller 171 * present. This memory should be freed by the caller
161 */ 172 */
162char * 173char *
163GNUNET_CONFIGURATION_serialize_diagnostics (const struct 174GNUNET_CONFIGURATION_serialize_diagnostics (
164 GNUNET_CONFIGURATION_Handle *cfg); 175 const struct GNUNET_CONFIGURATION_Handle *cfg);
176
165 177
166/** 178/**
167 * De-serializes configuration 179 * De-serializes configuration
@@ -170,14 +182,15 @@ GNUNET_CONFIGURATION_serialize_diagnostics (const struct
170 * @param mem the memory block of serialized configuration 182 * @param mem the memory block of serialized configuration
171 * @param size the size of the memory block 183 * @param size the size of the memory block
172 * @param source_filename source filename, will be used 184 * @param source_filename source filename, will be used
173 * to resolve relative @INLINE@ statements 185 * to resolve relative \@INLINE\@ statements
174 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 186 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
175 */ 187 */
176enum GNUNET_GenericReturnValue 188enum GNUNET_GenericReturnValue
177GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, 189GNUNET_CONFIGURATION_deserialize (
178 const char *mem, 190 struct GNUNET_CONFIGURATION_Handle *cfg,
179 size_t size, 191 const char *mem,
180 const char *source_filename); 192 size_t size,
193 const char *source_filename);
181 194
182 195
183/** 196/**
@@ -188,8 +201,9 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
188 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 201 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
189 */ 202 */
190enum GNUNET_GenericReturnValue 203enum GNUNET_GenericReturnValue
191GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, 204GNUNET_CONFIGURATION_write (
192 const char *filename); 205 struct GNUNET_CONFIGURATION_Handle *cfg,
206 const char *filename);
193 207
194 208
195/** 209/**
@@ -228,7 +242,8 @@ GNUNET_CONFIGURATION_get_diff (
228 * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed) 242 * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed)
229 */ 243 */
230enum GNUNET_GenericReturnValue 244enum GNUNET_GenericReturnValue
231GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg); 245GNUNET_CONFIGURATION_is_dirty (
246 const struct GNUNET_CONFIGURATION_Handle *cfg);
232 247
233 248
234/** 249/**
@@ -239,8 +254,9 @@ GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
239 * @return status code 254 * @return status code
240 */ 255 */
241typedef enum GNUNET_GenericReturnValue 256typedef enum GNUNET_GenericReturnValue
242(*GNUNET_CONFIGURATION_Callback)(void *cls, 257(*GNUNET_CONFIGURATION_Callback)(
243 const struct GNUNET_CONFIGURATION_Handle *cfg); 258 void *cls,
259 const struct GNUNET_CONFIGURATION_Handle *cfg);
244 260
245 261
246/** 262/**
@@ -255,9 +271,10 @@ typedef enum GNUNET_GenericReturnValue
255 * otherwise return value from @a cb. 271 * otherwise return value from @a cb.
256 */ 272 */
257enum GNUNET_GenericReturnValue 273enum GNUNET_GenericReturnValue
258GNUNET_CONFIGURATION_parse_and_run (const char *filename, 274GNUNET_CONFIGURATION_parse_and_run (
259 GNUNET_CONFIGURATION_Callback cb, 275 const char *filename,
260 void *cb_cls); 276 GNUNET_CONFIGURATION_Callback cb,
277 void *cb_cls);
261 278
262/** 279/**
263 * Enable extra diagnostics. Will produce more log output 280 * Enable extra diagnostics. Will produce more log output
@@ -266,8 +283,8 @@ GNUNET_CONFIGURATION_parse_and_run (const char *filename,
266 * @param cfg configuration handle 283 * @param cfg configuration handle
267 */ 284 */
268void 285void
269GNUNET_CONFIGURATION_enable_diagnostics (struct 286GNUNET_CONFIGURATION_enable_diagnostics (
270 GNUNET_CONFIGURATION_Handle *cfg); 287 struct GNUNET_CONFIGURATION_Handle *cfg);
271 288
272 289
273/** 290/**
@@ -292,8 +309,8 @@ typedef void
292 * @param section name of the section 309 * @param section name of the section
293 */ 310 */
294typedef void 311typedef void
295(*GNUNET_CONFIGURATION_Section_Iterator) (void *cls, 312(*GNUNET_CONFIGURATION_SectionIterator) (void *cls,
296 const char *section); 313 const char *section);
297 314
298 315
299/** 316/**
@@ -304,9 +321,10 @@ typedef void
304 * @param iter_cls closure for @a iter 321 * @param iter_cls closure for @a iter
305 */ 322 */
306void 323void
307GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, 324GNUNET_CONFIGURATION_iterate (
308 GNUNET_CONFIGURATION_Iterator iter, 325 const struct GNUNET_CONFIGURATION_Handle *cfg,
309 void *iter_cls); 326 GNUNET_CONFIGURATION_Iterator iter,
327 void *iter_cls);
310 328
311 329
312/** 330/**
@@ -317,11 +335,10 @@ GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
317 * @param iter_cls closure for @a iter 335 * @param iter_cls closure for @a iter
318 */ 336 */
319void 337void
320GNUNET_CONFIGURATION_iterate_sections (const struct 338GNUNET_CONFIGURATION_iterate_sections (
321 GNUNET_CONFIGURATION_Handle *cfg, 339 const struct GNUNET_CONFIGURATION_Handle *cfg,
322 GNUNET_CONFIGURATION_Section_Iterator 340 GNUNET_CONFIGURATION_SectionIterator iter,
323 iter, 341 void *iter_cls);
324 void *iter_cls);
325 342
326 343
327/** 344/**
@@ -331,8 +348,9 @@ GNUNET_CONFIGURATION_iterate_sections (const struct
331 * @param section name of the section to remove 348 * @param section name of the section to remove
332 */ 349 */
333void 350void
334GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, 351GNUNET_CONFIGURATION_remove_section (
335 const char *section); 352 struct GNUNET_CONFIGURATION_Handle *cfg,
353 const char *section);
336 354
337 355
338/** 356/**
@@ -345,11 +363,11 @@ GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
345 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 363 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
346 */ 364 */
347enum GNUNET_GenericReturnValue 365enum GNUNET_GenericReturnValue
348GNUNET_CONFIGURATION_get_value_number (const struct 366GNUNET_CONFIGURATION_get_value_number (
349 GNUNET_CONFIGURATION_Handle *cfg, 367 const struct GNUNET_CONFIGURATION_Handle *cfg,
350 const char *section, 368 const char *section,
351 const char *option, 369 const char *option,
352 unsigned long long *number); 370 unsigned long long *number);
353 371
354 372
355/** 373/**
@@ -362,11 +380,11 @@ GNUNET_CONFIGURATION_get_value_number (const struct
362 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 380 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
363 */ 381 */
364enum GNUNET_GenericReturnValue 382enum GNUNET_GenericReturnValue
365GNUNET_CONFIGURATION_get_value_float (const struct 383GNUNET_CONFIGURATION_get_value_float (
366 GNUNET_CONFIGURATION_Handle *cfg, 384 const struct GNUNET_CONFIGURATION_Handle *cfg,
367 const char *section, 385 const char *section,
368 const char *option, 386 const char *option,
369 float *number); 387 float *number);
370 388
371 389
372/** 390/**
@@ -379,11 +397,11 @@ GNUNET_CONFIGURATION_get_value_float (const struct
379 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 397 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
380 */ 398 */
381enum GNUNET_GenericReturnValue 399enum GNUNET_GenericReturnValue
382GNUNET_CONFIGURATION_get_value_time (const struct 400GNUNET_CONFIGURATION_get_value_time (
383 GNUNET_CONFIGURATION_Handle *cfg, 401 const struct GNUNET_CONFIGURATION_Handle *cfg,
384 const char *section, 402 const char *section,
385 const char *option, 403 const char *option,
386 struct GNUNET_TIME_Relative *time); 404 struct GNUNET_TIME_Relative *time);
387 405
388 406
389/** 407/**
@@ -396,11 +414,11 @@ GNUNET_CONFIGURATION_get_value_time (const struct
396 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 414 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
397 */ 415 */
398enum GNUNET_GenericReturnValue 416enum GNUNET_GenericReturnValue
399GNUNET_CONFIGURATION_get_value_size (const struct 417GNUNET_CONFIGURATION_get_value_size (
400 GNUNET_CONFIGURATION_Handle *cfg, 418 const struct GNUNET_CONFIGURATION_Handle *cfg,
401 const char *section, 419 const char *section,
402 const char *option, 420 const char *option,
403 unsigned long long *size); 421 unsigned long long *size);
404 422
405 423
406/** 424/**
@@ -447,11 +465,11 @@ GNUNET_CONFIGURATION_get_value_string (
447 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 465 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
448 */ 466 */
449enum GNUNET_GenericReturnValue 467enum GNUNET_GenericReturnValue
450GNUNET_CONFIGURATION_get_value_filename (const struct 468GNUNET_CONFIGURATION_get_value_filename (
451 GNUNET_CONFIGURATION_Handle *cfg, 469 const struct GNUNET_CONFIGURATION_Handle *cfg,
452 const char *section, 470 const char *section,
453 const char *option, 471 const char *option,
454 char **value); 472 char **value);
455 473
456 474
457/** 475/**
@@ -465,12 +483,13 @@ GNUNET_CONFIGURATION_get_value_filename (const struct
465 * @return number of filenames iterated over, -1 on error 483 * @return number of filenames iterated over, -1 on error
466 */ 484 */
467int 485int
468GNUNET_CONFIGURATION_iterate_value_filenames (const struct 486GNUNET_CONFIGURATION_iterate_value_filenames (
469 GNUNET_CONFIGURATION_Handle *cfg, 487 const struct GNUNET_CONFIGURATION_Handle *cfg,
470 const char *section, 488 const char *section,
471 const char *option, 489 const char *option,
472 GNUNET_FileNameCallback cb, 490 GNUNET_FileNameCallback cb,
473 void *cb_cls); 491 void *cb_cls);
492
474 493
475/** 494/**
476 * Iterate over values of a section in the configuration. 495 * Iterate over values of a section in the configuration.
@@ -481,11 +500,12 @@ GNUNET_CONFIGURATION_iterate_value_filenames (const struct
481 * @param iter_cls closure for @a iter 500 * @param iter_cls closure for @a iter
482 */ 501 */
483void 502void
484GNUNET_CONFIGURATION_iterate_section_values (const struct 503GNUNET_CONFIGURATION_iterate_section_values (
485 GNUNET_CONFIGURATION_Handle *cfg, 504 const struct GNUNET_CONFIGURATION_Handle *cfg,
486 const char *section, 505 const char *section,
487 GNUNET_CONFIGURATION_Iterator iter, 506 GNUNET_CONFIGURATION_Iterator iter,
488 void *iter_cls); 507 void *iter_cls);
508
489 509
490/** 510/**
491 * Get a configuration value that should be in a set of 511 * Get a configuration value that should be in a set of
@@ -500,12 +520,13 @@ GNUNET_CONFIGURATION_iterate_section_values (const struct
500 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 520 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
501 */ 521 */
502enum GNUNET_GenericReturnValue 522enum GNUNET_GenericReturnValue
503GNUNET_CONFIGURATION_get_value_choice (const struct 523GNUNET_CONFIGURATION_get_value_choice (
504 GNUNET_CONFIGURATION_Handle *cfg, 524 const struct GNUNET_CONFIGURATION_Handle *cfg,
505 const char *section, 525 const char *section,
506 const char *option, 526 const char *option,
507 const char *const *choices, 527 const char *const *choices,
508 const char **value); 528 const char **value);
529
509 530
510/** 531/**
511 * Get a configuration value that should be in a set of 532 * Get a configuration value that should be in a set of
@@ -517,10 +538,10 @@ GNUNET_CONFIGURATION_get_value_choice (const struct
517 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR 538 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR
518 */ 539 */
519enum GNUNET_GenericReturnValue 540enum GNUNET_GenericReturnValue
520GNUNET_CONFIGURATION_get_value_yesno (const struct 541GNUNET_CONFIGURATION_get_value_yesno (
521 GNUNET_CONFIGURATION_Handle *cfg, 542 const struct GNUNET_CONFIGURATION_Handle *cfg,
522 const char *section, 543 const char *section,
523 const char *option); 544 const char *option);
524 545
525 546
526/** 547/**
@@ -589,10 +610,11 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
589 * @param value value to set 610 * @param value value to set
590 */ 611 */
591void 612void
592GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, 613GNUNET_CONFIGURATION_set_value_string (
593 const char *section, 614 struct GNUNET_CONFIGURATION_Handle *cfg,
594 const char *option, 615 const char *section,
595 const char *value); 616 const char *option,
617 const char *value);
596 618
597 619
598/** 620/**
@@ -607,11 +629,11 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
607 * #GNUNET_SYSERR if the filename is not in the list 629 * #GNUNET_SYSERR if the filename is not in the list
608 */ 630 */
609enum GNUNET_GenericReturnValue 631enum GNUNET_GenericReturnValue
610GNUNET_CONFIGURATION_remove_value_filename (struct 632GNUNET_CONFIGURATION_remove_value_filename (
611 GNUNET_CONFIGURATION_Handle *cfg, 633 struct GNUNET_CONFIGURATION_Handle *cfg,
612 const char *section, 634 const char *section,
613 const char *option, 635 const char *option,
614 const char *value); 636 const char *value);
615 637
616 638
617/** 639/**
@@ -626,11 +648,11 @@ GNUNET_CONFIGURATION_remove_value_filename (struct
626 * #GNUNET_SYSERR if the filename already in the list 648 * #GNUNET_SYSERR if the filename already in the list
627 */ 649 */
628enum GNUNET_GenericReturnValue 650enum GNUNET_GenericReturnValue
629GNUNET_CONFIGURATION_append_value_filename (struct 651GNUNET_CONFIGURATION_append_value_filename (
630 GNUNET_CONFIGURATION_Handle *cfg, 652 struct GNUNET_CONFIGURATION_Handle *cfg,
631 const char *section, 653 const char *section,
632 const char *option, 654 const char *option,
633 const char *value); 655 const char *value);
634 656
635 657
636/** 658/**
@@ -642,10 +664,8 @@ struct GNUNET_CONFIGURATION_ConfigSettings
642{ 664{
643 665
644 /** 666 /**
645 * Must be set to the API version, i.e. 667 * Must be set to the API version, i.e. #GNUNET_UTIL_VERSION. Used to
646 * #GNUNET_UTIL_VERSION. Used to detect 668 * detect which version of the struct the client is using.
647 * which version of the struct the client
648 * is using.
649 */ 669 */
650 unsigned int api_version; 670 unsigned int api_version;
651 671
@@ -689,7 +709,6 @@ struct GNUNET_CONFIGURATION_ConfigSettings
689 */ 709 */
690 int full; 710 int full;
691 711
692
693 /** 712 /**
694 * Return value from the operation, to be returned 713 * Return value from the operation, to be returned
695 * from 'main'. 714 * from 'main'.
@@ -707,50 +726,52 @@ struct GNUNET_CONFIGURATION_ConfigSettings
707 * @param cs configuration settings to initialize 726 * @param cs configuration settings to initialize
708 */ 727 */
709#define GNUNET_CONFIGURATION_CONFIG_OPTIONS(cs) \ 728#define GNUNET_CONFIGURATION_CONFIG_OPTIONS(cs) \
710 GNUNET_GETOPT_option_flag ( \ 729 GNUNET_GETOPT_option_flag ( \
711 'F', \ 730 'F', \
712 "full", \ 731 "full", \
713 gettext_noop ( \ 732 gettext_noop ( \
714 "write the full configuration file, including default values"), \ 733 "write the full configuration file, including default values"), \
715 &(cs)->full), \ 734 &(cs)->full), \
716 GNUNET_GETOPT_option_flag ( \ 735 GNUNET_GETOPT_option_flag ( \
717 'f', \ 736 'f', \
718 "filename", \ 737 "filename", \
719 gettext_noop ("interpret option value as a filename (with $-expansion)"), \ 738 gettext_noop ( \
720 &(cs)->is_filename), \ 739 "interpret option value as a filename (with $-expansion)"), \
721 GNUNET_GETOPT_option_string ('o', \ 740 &(cs)->is_filename), \
722 "option", \ 741 GNUNET_GETOPT_option_string ('o', \
723 "OPTION", \ 742 "option", \
724 gettext_noop ("name of the option to access"), \ 743 "OPTION", \
725 &(cs)->option), \ 744 gettext_noop ( \
726 GNUNET_GETOPT_option_flag ( \ 745 "name of the option to access"), \
727 'r', \ 746 &(cs)->option), \
728 "rewrite", \ 747 GNUNET_GETOPT_option_flag ( \
729 gettext_noop ( \ 748 'r', \
730 "rewrite the configuration file, even if nothing changed"), \ 749 "rewrite", \
731 &(cs)->rewrite), \ 750 gettext_noop ( \
732 GNUNET_GETOPT_option_flag ( \ 751 "rewrite the configuration file, even if nothing changed"), \
733 'd', \ 752 &(cs)->rewrite), \
734 "diagnostics", \ 753 GNUNET_GETOPT_option_flag ( \
735 gettext_noop ( \ 754 'd', \
736 "output extra diagnostics"), \ 755 "diagnostics", \
737 &(cs)->diagnostics), \ 756 gettext_noop ( \
738 GNUNET_GETOPT_option_flag ('S', \ 757 "output extra diagnostics"), \
739 "list-sections", \ 758 &(cs)->diagnostics), \
740 gettext_noop ( \ 759 GNUNET_GETOPT_option_flag ('S', \
741 "print available configuration sections"), \ 760 "list-sections", \
742 &(cs)->list_sections), \ 761 gettext_noop ( \
743 GNUNET_GETOPT_option_string ('s', \ 762 "print available configuration sections"), \
744 "section", \ 763 &(cs)->list_sections), \
745 "SECTION", \ 764 GNUNET_GETOPT_option_string ('s', \
746 gettext_noop ( \ 765 "section", \
747 "name of the section to access"), \ 766 "SECTION", \
748 &(cs)->section), \ 767 gettext_noop ( \
749 GNUNET_GETOPT_option_string ('V', \ 768 "name of the section to access"), \
750 "value", \ 769 &(cs)->section), \
751 "VALUE", \ 770 GNUNET_GETOPT_option_string ('V', \
752 gettext_noop ("value to set"), \ 771 "value", \
753 &(cs)->value) 772 "VALUE", \
773 gettext_noop ("value to set"), \
774 &(cs)->value)
754 775
755 776
756/** 777/**
@@ -793,3 +814,5 @@ GNUNET_CONFIGURATION_config_tool_run (
793#endif 814#endif
794 815
795/** @} */ /* end of group configuration */ 816/** @} */ /* end of group configuration */
817
818/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_consensus_service.h b/src/include/gnunet_consensus_service.h
index 9387aa095..47a928d9c 100644
--- a/src/include/gnunet_consensus_service.h
+++ b/src/include/gnunet_consensus_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Sets
23 * @{
24 *
22 * @author Florian Dold 25 * @author Florian Dold
23 * 26 *
24 * @file 27 * @file
@@ -40,6 +43,7 @@ extern "C"
40#endif 43#endif
41#endif 44#endif
42 45
46
43#include "gnunet_common.h" 47#include "gnunet_common.h"
44#include "gnunet_time_lib.h" 48#include "gnunet_time_lib.h"
45#include "gnunet_configuration_lib.h" 49#include "gnunet_configuration_lib.h"
@@ -78,8 +82,8 @@ struct GNUNET_CONSENSUS_Handle;
78 * Create a consensus session. The set being reconciled is initially 82 * Create a consensus session. The set being reconciled is initially
79 * empty. 83 * empty.
80 * 84 *
81 * @param cfg 85 * @param cfg configuration to use for connecting to the consensus service
82 * @param num_peers 86 * @param num_peers number of peers in the peers array
83 * @param peers array of peers participating in this consensus session 87 * @param peers array of peers participating in this consensus session
84 * Inclusion of the local peer is optional. 88 * Inclusion of the local peer is optional.
85 * @param session_id session identifier 89 * @param session_id session identifier
@@ -180,3 +184,5 @@ GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus);
180#endif 184#endif
181 185
182/** @} */ /* end of group */ 186/** @} */ /* end of group */
187
188/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h
index 3eb80595c..8f36f1c61 100644
--- a/src/include/gnunet_container_lib.h
+++ b/src/include/gnunet_container_lib.h
@@ -19,35 +19,57 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * @author Nils Durner 27 * @author Nils Durner
24 * 28 *
25 * @file 29 * @file
26 * Container classes for GNUnet 30 * Container classes for GNUnet
27 * 31 *
28 * @defgroup hashmap Container library: MultiHashMap 32 * @addtogroup container
33 * Common data structures in GNUnet programs
34 * @{
35 *
36 * @defgroup hashmap MultiHashMap
29 * Hash map with multiple values per key. 37 * Hash map with multiple values per key.
30 * 38 *
31 * @see [Documentation](https://gnunet.org/util_multihashmap) 39 * @see [Documentation](https://gnunet.org/util_multihashmap)
32 * 40 *
33 * @defgroup heap Container library: Heap 41 * @defgroup heap Heap
34 * Min- or max-heap with arbitrary element removal 42 * Min- or max-heap with arbitrary element removal
35 * 43 *
36 * @defgroup bloomfilter Container library: Bloom filter 44 * @defgroup bloomfilter Bloom filter
37 * Probabilistic set tests 45 * Probabilistic set tests
38 * 46 *
39 * @defgroup dll Container library: Doubly-linked list 47 * @defgroup dll Doubly-linked list
40 * 48 *
41 * @see [Documentation](https://gnunet.org/mdll-api) 49 * @see [Documentation](https://gnunet.org/mdll-api)
42 * 50 *
43 * @defgroup metadata Container library: Metadata 51 *
44 * GNU libextractor key-value pairs 52 * @}
45 */ 53 */
46 54
55#include "gnunet_common.h"
56#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
57#error "Only <gnunet_util_lib.h> can be included directly."
58#endif
59
47#ifndef GNUNET_CONTAINER_LIB_H 60#ifndef GNUNET_CONTAINER_LIB_H
48#define GNUNET_CONTAINER_LIB_H 61#define GNUNET_CONTAINER_LIB_H
49 62
63#ifdef __cplusplus
64extern "C" {
65#if 0 /* keep Emacsens' auto-indent happy */
66}
67#endif
68#endif
69
70
50/* add error and config prototypes */ 71/* add error and config prototypes */
72
51#include "gnunet_crypto_lib.h" 73#include "gnunet_crypto_lib.h"
52 74
53 75
@@ -87,114 +109,6 @@ char *
87GNUNET_decompress (const char *input, size_t input_size, size_t output_size); 109GNUNET_decompress (const char *input, size_t input_size, size_t output_size);
88 110
89 111
90#if HAVE_EXTRACTOR_H
91
92#include <extractor.h>
93
94#else
95
96/* definitions from extractor.h we need for the build */
97
98/**
99 * Enumeration defining various sources of keywords. See also
100 * http://dublincore.org/documents/1998/09/dces/
101 */
102enum EXTRACTOR_MetaType
103{
104 EXTRACTOR_METATYPE_RESERVED = 0,
105 EXTRACTOR_METATYPE_MIMETYPE = 1,
106 EXTRACTOR_METATYPE_FILENAME = 2,
107 EXTRACTOR_METATYPE_COMMENT = 3,
108 EXTRACTOR_METATYPE_TITLE = 4,
109 EXTRACTOR_METATYPE_BOOK_TITLE = 5,
110 EXTRACTOR_METATYPE_JOURNAL_NAME = 8,
111 EXTRACTOR_METATYPE_AUTHOR_NAME = 13,
112 EXTRACTOR_METATYPE_PUBLICATION_DATE = 24,
113 EXTRACTOR_METATYPE_URL = 29,
114 EXTRACTOR_METATYPE_URI = 30,
115 EXTRACTOR_METATYPE_ISRC = 31,
116 EXTRACTOR_METATYPE_UNKNOWN = 45,
117 EXTRACTOR_METATYPE_DESCRIPTION = 46,
118 EXTRACTOR_METATYPE_KEYWORDS = 49,
119 EXTRACTOR_METATYPE_SUBJECT = 52,
120 EXTRACTOR_METATYPE_PACKAGE_NAME = 69,
121 EXTRACTOR_METATYPE_THUMBNAIL = 114,
122 EXTRACTOR_METATYPE_ALBUM = 129,
123 EXTRACTOR_METATYPE_ARTIST = 130,
124 EXTRACTOR_METATYPE_ORIGINAL_TITLE = 162,
125 EXTRACTOR_METATYPE_GNUNET_FULL_DATA = 174,
126 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME = 180,
127};
128
129/**
130 * Format in which the extracted meta data is presented.
131 */
132enum EXTRACTOR_MetaFormat
133{
134 /**
135 * Format is unknown.
136 */
137 EXTRACTOR_METAFORMAT_UNKNOWN = 0,
138
139 /**
140 * 0-terminated, UTF-8 encoded string. "data_len"
141 * is strlen(data)+1.
142 */
143 EXTRACTOR_METAFORMAT_UTF8 = 1,
144
145 /**
146 * Some kind of binary format, see given Mime type.
147 */
148 EXTRACTOR_METAFORMAT_BINARY = 2,
149
150 /**
151 * 0-terminated string. The specific encoding is unknown.
152 * "data_len" is strlen (data)+1.
153 */
154 EXTRACTOR_METAFORMAT_C_STRING = 3
155};
156
157
158/**
159 * Type of a function that libextractor calls for each
160 * meta data item found.
161 *
162 * @param cls closure (user-defined)
163 * @param plugin_name name of the plugin that produced this value;
164 * special values can be used (e.g. '&lt;zlib&gt;' for zlib being
165 * used in the main libextractor library and yielding
166 * meta data).
167 * @param type libextractor-type describing the meta data
168 * @param format basic format information about @a data
169 * @param data_mime_type mime-type of @a data (not of the original file);
170 * can be NULL (if mime-type is not known)
171 * @param data actual meta-data found
172 * @param data_len number of bytes in @a data
173 * @return 0 to continue extracting, 1 to abort
174 */
175typedef int (*EXTRACTOR_MetaDataProcessor) (void *cls,
176 const char *plugin_name,
177 enum EXTRACTOR_MetaType type,
178 enum EXTRACTOR_MetaFormat format,
179 const char *data_mime_type,
180 const char *data,
181 size_t data_len);
182
183#endif
184
185#ifndef EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME
186/* hack for LE < 0.6.3 */
187#define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME 180
188#endif
189
190#ifdef __cplusplus
191extern "C" {
192#if 0 /* keep Emacsens' auto-indent happy */
193}
194#endif
195#endif
196
197
198/* ******************* bloomfilter ***************** */ 112/* ******************* bloomfilter ***************** */
199 113
200/** 114/**
@@ -264,7 +178,7 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data,
264 * @param size the size of the given @a data array 178 * @param size the size of the given @a data array
265 * @return #GNUNET_SYSERR if the data array of the wrong size 179 * @return #GNUNET_SYSERR if the data array of the wrong size
266 */ 180 */
267int 181enum GNUNET_GenericReturnValue
268GNUNET_CONTAINER_bloomfilter_get_raw_data ( 182GNUNET_CONTAINER_bloomfilter_get_raw_data (
269 const struct GNUNET_CONTAINER_BloomFilter *bf, 183 const struct GNUNET_CONTAINER_BloomFilter *bf,
270 char *data, 184 char *data,
@@ -277,9 +191,9 @@ GNUNET_CONTAINER_bloomfilter_get_raw_data (
277 * 191 *
278 * @param e the element 192 * @param e the element
279 * @param bf the filter 193 * @param bf the filter
280 * @return #GNUNET_YES if the element is in the filter, #GNUNET_NO if not 194 * @return true if the element is in the filter, false if not
281 */ 195 */
282int 196bool
283GNUNET_CONTAINER_bloomfilter_test ( 197GNUNET_CONTAINER_bloomfilter_test (
284 const struct GNUNET_CONTAINER_BloomFilter *bf, 198 const struct GNUNET_CONTAINER_BloomFilter *bf,
285 const struct GNUNET_HashCode *e); 199 const struct GNUNET_HashCode *e);
@@ -378,7 +292,7 @@ GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf);
378 * @param size size of @a data 292 * @param size size of @a data
379 * @return #GNUNET_OK on success 293 * @return #GNUNET_OK on success
380 */ 294 */
381int 295enum GNUNET_GenericReturnValue
382GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, 296GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
383 const char *data, 297 const char *data,
384 size_t size); 298 size_t size);
@@ -394,7 +308,7 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
394 * @param to_or the bloomfilter to or-in 308 * @param to_or the bloomfilter to or-in
395 * @return #GNUNET_OK on success 309 * @return #GNUNET_OK on success
396 */ 310 */
397int 311enum GNUNET_GenericReturnValue
398GNUNET_CONTAINER_bloomfilter_or2 ( 312GNUNET_CONTAINER_bloomfilter_or2 (
399 struct GNUNET_CONTAINER_BloomFilter *bf, 313 struct GNUNET_CONTAINER_BloomFilter *bf,
400 const struct GNUNET_CONTAINER_BloomFilter *to_or); 314 const struct GNUNET_CONTAINER_BloomFilter *to_or);
@@ -420,285 +334,6 @@ GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
420 unsigned int k); 334 unsigned int k);
421 335
422 336
423/* ****************** metadata ******************* */
424
425/**
426 * @ingroup metadata
427 * Meta data to associate with a file, directory or namespace.
428 */
429struct GNUNET_CONTAINER_MetaData;
430
431
432/**
433 * @ingroup metadata
434 * Create a fresh meta data container.
435 *
436 * @return empty meta-data container
437 */
438struct GNUNET_CONTAINER_MetaData *
439GNUNET_CONTAINER_meta_data_create (void);
440
441
442/**
443 * @ingroup metadata
444 * Duplicate a MetaData token.
445 *
446 * @param md what to duplicate
447 * @return duplicate meta-data container
448 */
449struct GNUNET_CONTAINER_MetaData *
450GNUNET_CONTAINER_meta_data_duplicate (
451 const struct GNUNET_CONTAINER_MetaData *md);
452
453
454/**
455 * @ingroup metadata
456 * Free meta data.
457 *
458 * @param md what to free
459 */
460void
461GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md);
462
463
464/**
465 * @ingroup metadata
466 * Test if two MDs are equal. We consider them equal if
467 * the meta types, formats and content match (we do not
468 * include the mime types and plugins names in this
469 * consideration).
470 *
471 * @param md1 first value to check
472 * @param md2 other value to check
473 * @return #GNUNET_YES if they are equal
474 */
475int
476GNUNET_CONTAINER_meta_data_test_equal (
477 const struct GNUNET_CONTAINER_MetaData *md1,
478 const struct GNUNET_CONTAINER_MetaData *md2);
479
480
481/**
482 * @ingroup metadata
483 * Extend metadata.
484 *
485 * @param md metadata to extend
486 * @param plugin_name name of the plugin that produced this value;
487 * special values can be used (e.g. '&lt;zlib&gt;' for zlib being
488 * used in the main libextractor library and yielding
489 * meta data).
490 * @param type libextractor-type describing the meta data
491 * @param format basic format information about data
492 * @param data_mime_type mime-type of data (not of the original file);
493 * can be NULL (if mime-type is not known)
494 * @param data actual meta-data found
495 * @param data_size number of bytes in data
496 * @return #GNUNET_OK on success, #GNUNET_SYSERR if this entry already exists
497 * data_mime_type and plugin_name are not considered for "exists" checks
498 */
499int
500GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
501 const char *plugin_name,
502 enum EXTRACTOR_MetaType type,
503 enum EXTRACTOR_MetaFormat format,
504 const char *data_mime_type,
505 const char *data,
506 size_t data_size);
507
508
509/**
510 * @ingroup metadata
511 * Extend metadata. Merges the meta data from the second argument
512 * into the first, discarding duplicate key-value pairs.
513 *
514 * @param md metadata to extend
515 * @param in metadata to merge
516 */
517void
518GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md,
519 const struct GNUNET_CONTAINER_MetaData *in);
520
521
522/**
523 * @ingroup metadata
524 * Remove an item.
525 *
526 * @param md metadata to manipulate
527 * @param type type of the item to remove
528 * @param data specific value to remove, NULL to remove all
529 * entries of the given type
530 * @param data_size number of bytes in data
531 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the item does not exist in md
532 */
533int
534GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
535 enum EXTRACTOR_MetaType type,
536 const char *data,
537 size_t data_size);
538
539
540/**
541 * @ingroup metadata
542 * Remove all items in the container.
543 *
544 * @param md metadata to manipulate
545 */
546void
547GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md);
548
549
550/**
551 * @ingroup metadata
552 * Add the current time as the publication date
553 * to the meta-data.
554 *
555 * @param md metadata to modify
556 */
557void
558GNUNET_CONTAINER_meta_data_add_publication_date (
559 struct GNUNET_CONTAINER_MetaData *md);
560
561
562/**
563 * @ingroup metadata
564 * Iterate over MD entries.
565 *
566 * @param md metadata to inspect
567 * @param iter function to call on each entry, return 0 to continue to iterate
568 * and 1 to abort iteration in this function (GNU libextractor API!)
569 * @param iter_cls closure for @a iter
570 * @return number of entries
571 */
572int
573GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData *md,
574 EXTRACTOR_MetaDataProcessor iter,
575 void *iter_cls);
576
577
578/**
579 * @ingroup metadata
580 * Get the first MD entry of the given type. Caller
581 * is responsible for freeing the return value.
582 * Also, only meta data items that are strings (0-terminated)
583 * are returned by this function.
584 *
585 * @param md metadata to inspect
586 * @param type type to look for
587 * @return NULL if no entry was found
588 */
589char *
590GNUNET_CONTAINER_meta_data_get_by_type (
591 const struct GNUNET_CONTAINER_MetaData *md,
592 enum EXTRACTOR_MetaType type);
593
594
595/**
596 * @ingroup metadata
597 * Get the first matching MD entry of the given types. Caller is
598 * responsible for freeing the return value. Also, only meta data
599 * items that are strings (0-terminated) are returned by this
600 * function.
601 *
602 * @param md metadata to inspect
603 * @param ... -1-terminated list of types
604 * @return NULL if we do not have any such entry,
605 * otherwise client is responsible for freeing the value!
606 */
607char *
608GNUNET_CONTAINER_meta_data_get_first_by_types (
609 const struct GNUNET_CONTAINER_MetaData *md,
610 ...);
611
612/**
613 * @ingroup metadata
614 * Get a thumbnail from the meta-data (if present). Only matches meta
615 * data with mime type "image" and binary format.
616 *
617 * @param md metadata to inspect
618 * @param thumb will be set to the thumbnail data. Must be
619 * freed by the caller!
620 * @return number of bytes in thumbnail, 0 if not available
621 */
622size_t
623GNUNET_CONTAINER_meta_data_get_thumbnail (
624 const struct GNUNET_CONTAINER_MetaData *md,
625 unsigned char **thumb);
626
627
628/**
629 * @ingroup metadata
630 * Options for metadata serialization.
631 */
632enum GNUNET_CONTAINER_MetaDataSerializationOptions
633{
634 /**
635 * @ingroup metadata
636 * Serialize all of the data.
637 */
638 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL = 0,
639
640 /**
641 * @ingroup metadata
642 * If not enough space is available, it is acceptable
643 * to only serialize some of the metadata.
644 */
645 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART = 1,
646
647 /**
648 * @ingroup metadata
649 * Speed is of the essence, do not allow compression.
650 */
651 GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS = 2
652};
653
654
655/**
656 * @ingroup metadata
657 * Serialize meta-data to target.
658 *
659 * @param md metadata to serialize
660 * @param target where to write the serialized metadata;
661 * *target can be NULL, in which case memory is allocated
662 * @param max maximum number of bytes available
663 * @param opt is it ok to just write SOME of the
664 * meta-data to match the size constraint,
665 * possibly discarding some data?
666 * @return number of bytes written on success,
667 * -1 on error (typically: not enough
668 * space)
669 */
670ssize_t
671GNUNET_CONTAINER_meta_data_serialize (
672 const struct GNUNET_CONTAINER_MetaData *md,
673 char **target,
674 size_t max,
675 enum GNUNET_CONTAINER_MetaDataSerializationOptions opt);
676
677
678/**
679 * @ingroup metadata
680 * Get the size of the full meta-data in serialized form.
681 *
682 * @param md metadata to inspect
683 * @return number of bytes needed for serialization, -1 on error
684 */
685ssize_t
686GNUNET_CONTAINER_meta_data_get_serialized_size (
687 const struct GNUNET_CONTAINER_MetaData *md);
688
689
690/**
691 * @ingroup metadata
692 * Deserialize meta-data. Initializes md.
693 *
694 * @param input serialized meta-data.
695 * @param size number of bytes available
696 * @return MD on success, NULL on error (e.g.
697 * bad format)
698 */
699struct GNUNET_CONTAINER_MetaData *
700GNUNET_CONTAINER_meta_data_deserialize (const char *input, size_t size);
701
702 337
703/* ******************************* HashMap **************************** */ 338/* ******************************* HashMap **************************** */
704 339
@@ -766,7 +401,8 @@ enum GNUNET_CONTAINER_MultiHashMapOption
766 * iterate, 401 * iterate,
767 * #GNUNET_NO if not. 402 * #GNUNET_NO if not.
768 */ 403 */
769typedef int (*GNUNET_CONTAINER_MulitHashMapIteratorCallback) ( 404typedef enum GNUNET_GenericReturnValue
405(*GNUNET_CONTAINER_MultiHashMapIteratorCallback)(
770 void *cls, 406 void *cls,
771 const struct GNUNET_HashCode *key, 407 const struct GNUNET_HashCode *key,
772 void *value); 408 void *value);
@@ -834,7 +470,7 @@ GNUNET_CONTAINER_multihashmap_get (
834 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair 470 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
835 * is not in the map 471 * is not in the map
836 */ 472 */
837int 473enum GNUNET_GenericReturnValue
838GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, 474GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map,
839 const struct GNUNET_HashCode *key, 475 const struct GNUNET_HashCode *key,
840 const void *value); 476 const void *value);
@@ -876,7 +512,7 @@ GNUNET_CONTAINER_multihashmap_clear (struct GNUNET_CONTAINER_MultiHashMap *map);
876 * @return #GNUNET_YES if such a value exists, 512 * @return #GNUNET_YES if such a value exists,
877 * #GNUNET_NO if not 513 * #GNUNET_NO if not
878 */ 514 */
879int 515enum GNUNET_GenericReturnValue
880GNUNET_CONTAINER_multihashmap_contains ( 516GNUNET_CONTAINER_multihashmap_contains (
881 const struct GNUNET_CONTAINER_MultiHashMap *map, 517 const struct GNUNET_CONTAINER_MultiHashMap *map,
882 const struct GNUNET_HashCode *key); 518 const struct GNUNET_HashCode *key);
@@ -893,7 +529,7 @@ GNUNET_CONTAINER_multihashmap_contains (
893 * @return #GNUNET_YES if such a value exists, 529 * @return #GNUNET_YES if such a value exists,
894 * #GNUNET_NO if not 530 * #GNUNET_NO if not
895 */ 531 */
896int 532enum GNUNET_GenericReturnValue
897GNUNET_CONTAINER_multihashmap_contains_value ( 533GNUNET_CONTAINER_multihashmap_contains_value (
898 const struct GNUNET_CONTAINER_MultiHashMap *map, 534 const struct GNUNET_CONTAINER_MultiHashMap *map,
899 const struct GNUNET_HashCode *key, 535 const struct GNUNET_HashCode *key,
@@ -913,7 +549,7 @@ GNUNET_CONTAINER_multihashmap_contains_value (
913 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the 549 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
914 * value already exists 550 * value already exists
915 */ 551 */
916int 552enum GNUNET_GenericReturnValue
917GNUNET_CONTAINER_multihashmap_put ( 553GNUNET_CONTAINER_multihashmap_put (
918 struct GNUNET_CONTAINER_MultiHashMap *map, 554 struct GNUNET_CONTAINER_MultiHashMap *map,
919 const struct GNUNET_HashCode *key, 555 const struct GNUNET_HashCode *key,
@@ -945,7 +581,7 @@ GNUNET_CONTAINER_multihashmap_size (
945int 581int
946GNUNET_CONTAINER_multihashmap_iterate ( 582GNUNET_CONTAINER_multihashmap_iterate (
947 struct GNUNET_CONTAINER_MultiHashMap *map, 583 struct GNUNET_CONTAINER_MultiHashMap *map,
948 GNUNET_CONTAINER_MulitHashMapIteratorCallback it, 584 GNUNET_CONTAINER_MultiHashMapIteratorCallback it,
949 void *it_cls); 585 void *it_cls);
950 586
951 587
@@ -982,7 +618,7 @@ GNUNET_CONTAINER_multihashmap_iterator_create (
982 * @return #GNUNET_YES we returned an element, 618 * @return #GNUNET_YES we returned an element,
983 * #GNUNET_NO if we are out of elements 619 * #GNUNET_NO if we are out of elements
984 */ 620 */
985int 621enum GNUNET_GenericReturnValue
986GNUNET_CONTAINER_multihashmap_iterator_next ( 622GNUNET_CONTAINER_multihashmap_iterator_next (
987 struct GNUNET_CONTAINER_MultiHashMapIterator *iter, 623 struct GNUNET_CONTAINER_MultiHashMapIterator *iter,
988 struct GNUNET_HashCode *key, 624 struct GNUNET_HashCode *key,
@@ -1011,11 +647,11 @@ GNUNET_CONTAINER_multihashmap_iterator_destroy (
1011 * @return the number of key value pairs processed, 647 * @return the number of key value pairs processed,
1012 * #GNUNET_SYSERR if it aborted iteration 648 * #GNUNET_SYSERR if it aborted iteration
1013 */ 649 */
1014int 650enum GNUNET_GenericReturnValue
1015GNUNET_CONTAINER_multihashmap_get_multiple ( 651GNUNET_CONTAINER_multihashmap_get_multiple (
1016 struct GNUNET_CONTAINER_MultiHashMap *map, 652 struct GNUNET_CONTAINER_MultiHashMap *map,
1017 const struct GNUNET_HashCode *key, 653 const struct GNUNET_HashCode *key,
1018 GNUNET_CONTAINER_MulitHashMapIteratorCallback it, 654 GNUNET_CONTAINER_MultiHashMapIteratorCallback it,
1019 void *it_cls); 655 void *it_cls);
1020 656
1021 657
@@ -1033,7 +669,7 @@ GNUNET_CONTAINER_multihashmap_get_multiple (
1033unsigned int 669unsigned int
1034GNUNET_CONTAINER_multihashmap_get_random ( 670GNUNET_CONTAINER_multihashmap_get_random (
1035 const struct GNUNET_CONTAINER_MultiHashMap *map, 671 const struct GNUNET_CONTAINER_MultiHashMap *map,
1036 GNUNET_CONTAINER_MulitHashMapIteratorCallback it, 672 GNUNET_CONTAINER_MultiHashMapIteratorCallback it,
1037 void *it_cls); 673 void *it_cls);
1038 674
1039 675
@@ -1050,7 +686,8 @@ GNUNET_CONTAINER_multihashmap_get_random (
1050 * iterate, 686 * iterate,
1051 * #GNUNET_NO if not. 687 * #GNUNET_NO if not.
1052 */ 688 */
1053typedef int (*GNUNET_CONTAINER_PeerMapIterator) ( 689typedef enum GNUNET_GenericReturnValue
690(*GNUNET_CONTAINER_PeerMapIterator)(
1054 void *cls, 691 void *cls,
1055 const struct GNUNET_PeerIdentity *key, 692 const struct GNUNET_PeerIdentity *key,
1056 void *value); 693 void *value);
@@ -1123,7 +760,7 @@ GNUNET_CONTAINER_multipeermap_get (
1123 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair 760 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
1124 * is not in the map 761 * is not in the map
1125 */ 762 */
1126int 763enum GNUNET_GenericReturnValue
1127GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map, 764GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map,
1128 const struct GNUNET_PeerIdentity *key, 765 const struct GNUNET_PeerIdentity *key,
1129 const void *value); 766 const void *value);
@@ -1153,7 +790,7 @@ GNUNET_CONTAINER_multipeermap_remove_all (
1153 * @return #GNUNET_YES if such a value exists, 790 * @return #GNUNET_YES if such a value exists,
1154 * #GNUNET_NO if not 791 * #GNUNET_NO if not
1155 */ 792 */
1156int 793enum GNUNET_GenericReturnValue
1157GNUNET_CONTAINER_multipeermap_contains ( 794GNUNET_CONTAINER_multipeermap_contains (
1158 const struct GNUNET_CONTAINER_MultiPeerMap *map, 795 const struct GNUNET_CONTAINER_MultiPeerMap *map,
1159 const struct GNUNET_PeerIdentity *key); 796 const struct GNUNET_PeerIdentity *key);
@@ -1170,7 +807,7 @@ GNUNET_CONTAINER_multipeermap_contains (
1170 * @return #GNUNET_YES if such a value exists, 807 * @return #GNUNET_YES if such a value exists,
1171 * #GNUNET_NO if not 808 * #GNUNET_NO if not
1172 */ 809 */
1173int 810enum GNUNET_GenericReturnValue
1174GNUNET_CONTAINER_multipeermap_contains_value ( 811GNUNET_CONTAINER_multipeermap_contains_value (
1175 const struct GNUNET_CONTAINER_MultiPeerMap *map, 812 const struct GNUNET_CONTAINER_MultiPeerMap *map,
1176 const struct GNUNET_PeerIdentity *key, 813 const struct GNUNET_PeerIdentity *key,
@@ -1250,9 +887,12 @@ GNUNET_CONTAINER_multipeermap_iterator_create (
1250 * @ingroup hashmap 887 * @ingroup hashmap
1251 * Retrieve the next element from the hash map at the iterator's 888 * Retrieve the next element from the hash map at the iterator's
1252 * position. If there are no elements left, #GNUNET_NO is returned, 889 * position. If there are no elements left, #GNUNET_NO is returned,
1253 * and @a key and @a value are not modified. This operation is only 890 * and @a key and @a value are not modified.
1254 * allowed if no elements have been removed from the multihashmap 891 *
1255 * since the creation of @a iter, and the map has not been destroyed. 892 * This operation is only allowed if no elements have been removed
893 * from the multihashmap since the creation of @a iter, and the map
894 * has not been destroyed.
895 *
1256 * Adding elements may result in repeating or skipping elements. 896 * Adding elements may result in repeating or skipping elements.
1257 * 897 *
1258 * @param iter the iterator to get the next element from 898 * @param iter the iterator to get the next element from
@@ -1261,7 +901,7 @@ GNUNET_CONTAINER_multipeermap_iterator_create (
1261 * @return #GNUNET_YES we returned an element, 901 * @return #GNUNET_YES we returned an element,
1262 * #GNUNET_NO if we are out of elements 902 * #GNUNET_NO if we are out of elements
1263 */ 903 */
1264int 904enum GNUNET_GenericReturnValue
1265GNUNET_CONTAINER_multipeermap_iterator_next ( 905GNUNET_CONTAINER_multipeermap_iterator_next (
1266 struct GNUNET_CONTAINER_MultiPeerMapIterator *iter, 906 struct GNUNET_CONTAINER_MultiPeerMapIterator *iter,
1267 struct GNUNET_PeerIdentity *key, 907 struct GNUNET_PeerIdentity *key,
@@ -1329,7 +969,8 @@ GNUNET_CONTAINER_multipeermap_get_random (
1329 * iterate, 969 * iterate,
1330 * #GNUNET_NO if not. 970 * #GNUNET_NO if not.
1331 */ 971 */
1332typedef int (*GNUNET_CONTAINER_ShortmapIterator) ( 972typedef enum GNUNET_GenericReturnValue
973(*GNUNET_CONTAINER_ShortmapIterator)(
1333 void *cls, 974 void *cls,
1334 const struct GNUNET_ShortHashCode *key, 975 const struct GNUNET_ShortHashCode *key,
1335 void *value); 976 void *value);
@@ -1470,7 +1111,7 @@ GNUNET_CONTAINER_multishortmap_contains_value (
1470 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the 1111 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
1471 * value already exists 1112 * value already exists
1472 */ 1113 */
1473int 1114enum GNUNET_GenericReturnValue
1474GNUNET_CONTAINER_multishortmap_put ( 1115GNUNET_CONTAINER_multishortmap_put (
1475 struct GNUNET_CONTAINER_MultiShortmap *map, 1116 struct GNUNET_CONTAINER_MultiShortmap *map,
1476 const struct GNUNET_ShortHashCode *key, 1117 const struct GNUNET_ShortHashCode *key,
@@ -1543,7 +1184,7 @@ GNUNET_CONTAINER_multishortmap_iterator_create (
1543 * @return #GNUNET_YES we returned an element, 1184 * @return #GNUNET_YES we returned an element,
1544 * #GNUNET_NO if we are out of elements 1185 * #GNUNET_NO if we are out of elements
1545 */ 1186 */
1546int 1187enum GNUNET_GenericReturnValue
1547GNUNET_CONTAINER_multishortmap_iterator_next ( 1188GNUNET_CONTAINER_multishortmap_iterator_next (
1548 struct GNUNET_CONTAINER_MultiShortmapIterator *iter, 1189 struct GNUNET_CONTAINER_MultiShortmapIterator *iter,
1549 struct GNUNET_ShortHashCode *key, 1190 struct GNUNET_ShortHashCode *key,
@@ -1612,7 +1253,8 @@ GNUNET_CONTAINER_multishortmap_get_random (
1612 * iterate, 1253 * iterate,
1613 * #GNUNET_NO if not. 1254 * #GNUNET_NO if not.
1614 */ 1255 */
1615typedef int (*GNUNET_CONTAINER_MultiUuidmapIteratorCallback) ( 1256typedef enum GNUNET_GenericReturnValue
1257(*GNUNET_CONTAINER_MultiUuidmapIteratorCallback)(
1616 void *cls, 1258 void *cls,
1617 const struct GNUNET_Uuid *key, 1259 const struct GNUNET_Uuid *key,
1618 void *value); 1260 void *value);
@@ -1685,7 +1327,7 @@ GNUNET_CONTAINER_multiuuidmap_get (
1685 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair 1327 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
1686 * is not in the map 1328 * is not in the map
1687 */ 1329 */
1688int 1330enum GNUNET_GenericReturnValue
1689GNUNET_CONTAINER_multiuuidmap_remove (struct GNUNET_CONTAINER_MultiUuidmap *map, 1331GNUNET_CONTAINER_multiuuidmap_remove (struct GNUNET_CONTAINER_MultiUuidmap *map,
1690 const struct GNUNET_Uuid *key, 1332 const struct GNUNET_Uuid *key,
1691 const void *value); 1333 const void *value);
@@ -1715,7 +1357,7 @@ GNUNET_CONTAINER_multiuuidmap_remove_all (
1715 * @return #GNUNET_YES if such a value exists, 1357 * @return #GNUNET_YES if such a value exists,
1716 * #GNUNET_NO if not 1358 * #GNUNET_NO if not
1717 */ 1359 */
1718int 1360enum GNUNET_GenericReturnValue
1719GNUNET_CONTAINER_multiuuidmap_contains ( 1361GNUNET_CONTAINER_multiuuidmap_contains (
1720 const struct GNUNET_CONTAINER_MultiUuidmap *map, 1362 const struct GNUNET_CONTAINER_MultiUuidmap *map,
1721 const struct GNUNET_Uuid *key); 1363 const struct GNUNET_Uuid *key);
@@ -1732,7 +1374,7 @@ GNUNET_CONTAINER_multiuuidmap_contains (
1732 * @return #GNUNET_YES if such a value exists, 1374 * @return #GNUNET_YES if such a value exists,
1733 * #GNUNET_NO if not 1375 * #GNUNET_NO if not
1734 */ 1376 */
1735int 1377enum GNUNET_GenericReturnValue
1736GNUNET_CONTAINER_multiuuidmap_contains_value ( 1378GNUNET_CONTAINER_multiuuidmap_contains_value (
1737 const struct GNUNET_CONTAINER_MultiUuidmap *map, 1379 const struct GNUNET_CONTAINER_MultiUuidmap *map,
1738 const struct GNUNET_Uuid *key, 1380 const struct GNUNET_Uuid *key,
@@ -1752,7 +1394,7 @@ GNUNET_CONTAINER_multiuuidmap_contains_value (
1752 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the 1394 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
1753 * value already exists 1395 * value already exists
1754 */ 1396 */
1755int 1397enum GNUNET_GenericReturnValue
1756GNUNET_CONTAINER_multiuuidmap_put ( 1398GNUNET_CONTAINER_multiuuidmap_put (
1757 struct GNUNET_CONTAINER_MultiUuidmap *map, 1399 struct GNUNET_CONTAINER_MultiUuidmap *map,
1758 const struct GNUNET_Uuid *key, 1400 const struct GNUNET_Uuid *key,
@@ -1782,7 +1424,7 @@ GNUNET_CONTAINER_multiuuidmap_size (
1782 * @return the number of key value pairs processed, 1424 * @return the number of key value pairs processed,
1783 * #GNUNET_SYSERR if it aborted iteration 1425 * #GNUNET_SYSERR if it aborted iteration
1784 */ 1426 */
1785int 1427enum GNUNET_GenericReturnValue
1786GNUNET_CONTAINER_multiuuidmap_iterate ( 1428GNUNET_CONTAINER_multiuuidmap_iterate (
1787 struct GNUNET_CONTAINER_MultiUuidmap *map, 1429 struct GNUNET_CONTAINER_MultiUuidmap *map,
1788 GNUNET_CONTAINER_MultiUuidmapIteratorCallback it, 1430 GNUNET_CONTAINER_MultiUuidmapIteratorCallback it,
@@ -1825,7 +1467,7 @@ GNUNET_CONTAINER_multiuuidmap_iterator_create (
1825 * @return #GNUNET_YES we returned an element, 1467 * @return #GNUNET_YES we returned an element,
1826 * #GNUNET_NO if we are out of elements 1468 * #GNUNET_NO if we are out of elements
1827 */ 1469 */
1828int 1470enum GNUNET_GenericReturnValue
1829GNUNET_CONTAINER_multiuuidmap_iterator_next ( 1471GNUNET_CONTAINER_multiuuidmap_iterator_next (
1830 struct GNUNET_CONTAINER_MultiUuidmapIterator *iter, 1472 struct GNUNET_CONTAINER_MultiUuidmapIterator *iter,
1831 struct GNUNET_Uuid *key, 1473 struct GNUNET_Uuid *key,
@@ -1908,9 +1550,11 @@ struct GNUNET_CONTAINER_MultiHashMap32Iterator;
1908 * iterate, 1550 * iterate,
1909 * #GNUNET_NO if not. 1551 * #GNUNET_NO if not.
1910 */ 1552 */
1911typedef int (*GNUNET_CONTAINER_MulitHashMapIterator32Callback) (void *cls, 1553typedef enum GNUNET_GenericReturnValue
1912 uint32_t key, 1554(*GNUNET_CONTAINER_MultiHashMapIterator32Callback)(
1913 void *value); 1555 void *cls,
1556 uint32_t key,
1557 void *value);
1914 1558
1915 1559
1916/** 1560/**
@@ -1978,7 +1622,7 @@ GNUNET_CONTAINER_multihashmap32_get (
1978int 1622int
1979GNUNET_CONTAINER_multihashmap32_iterate ( 1623GNUNET_CONTAINER_multihashmap32_iterate (
1980 struct GNUNET_CONTAINER_MultiHashMap32 *map, 1624 struct GNUNET_CONTAINER_MultiHashMap32 *map,
1981 GNUNET_CONTAINER_MulitHashMapIterator32Callback it, 1625 GNUNET_CONTAINER_MultiHashMapIterator32Callback it,
1982 void *it_cls); 1626 void *it_cls);
1983 1627
1984 1628
@@ -1994,7 +1638,7 @@ GNUNET_CONTAINER_multihashmap32_iterate (
1994 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair 1638 * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
1995 * is not in the map 1639 * is not in the map
1996 */ 1640 */
1997int 1641enum GNUNET_GenericReturnValue
1998GNUNET_CONTAINER_multihashmap32_remove ( 1642GNUNET_CONTAINER_multihashmap32_remove (
1999 struct GNUNET_CONTAINER_MultiHashMap32 *map, 1643 struct GNUNET_CONTAINER_MultiHashMap32 *map,
2000 uint32_t key, 1644 uint32_t key,
@@ -2026,7 +1670,7 @@ GNUNET_CONTAINER_multihashmap32_remove_all (
2026 * @return #GNUNET_YES if such a value exists, 1670 * @return #GNUNET_YES if such a value exists,
2027 * #GNUNET_NO if not 1671 * #GNUNET_NO if not
2028 */ 1672 */
2029int 1673enum GNUNET_GenericReturnValue
2030GNUNET_CONTAINER_multihashmap32_contains ( 1674GNUNET_CONTAINER_multihashmap32_contains (
2031 const struct GNUNET_CONTAINER_MultiHashMap32 *map, 1675 const struct GNUNET_CONTAINER_MultiHashMap32 *map,
2032 uint32_t key); 1676 uint32_t key);
@@ -2043,7 +1687,7 @@ GNUNET_CONTAINER_multihashmap32_contains (
2043 * @return #GNUNET_YES if such a value exists, 1687 * @return #GNUNET_YES if such a value exists,
2044 * #GNUNET_NO if not 1688 * #GNUNET_NO if not
2045 */ 1689 */
2046int 1690enum GNUNET_GenericReturnValue
2047GNUNET_CONTAINER_multihashmap32_contains_value ( 1691GNUNET_CONTAINER_multihashmap32_contains_value (
2048 const struct GNUNET_CONTAINER_MultiHashMap32 *map, 1692 const struct GNUNET_CONTAINER_MultiHashMap32 *map,
2049 uint32_t key, 1693 uint32_t key,
@@ -2063,7 +1707,7 @@ GNUNET_CONTAINER_multihashmap32_contains_value (
2063 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the 1707 * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
2064 * value already exists 1708 * value already exists
2065 */ 1709 */
2066int 1710enum GNUNET_GenericReturnValue
2067GNUNET_CONTAINER_multihashmap32_put ( 1711GNUNET_CONTAINER_multihashmap32_put (
2068 struct GNUNET_CONTAINER_MultiHashMap32 *map, 1712 struct GNUNET_CONTAINER_MultiHashMap32 *map,
2069 uint32_t key, 1713 uint32_t key,
@@ -2086,7 +1730,7 @@ int
2086GNUNET_CONTAINER_multihashmap32_get_multiple ( 1730GNUNET_CONTAINER_multihashmap32_get_multiple (
2087 struct GNUNET_CONTAINER_MultiHashMap32 *map, 1731 struct GNUNET_CONTAINER_MultiHashMap32 *map,
2088 uint32_t key, 1732 uint32_t key,
2089 GNUNET_CONTAINER_MulitHashMapIterator32Callback it, 1733 GNUNET_CONTAINER_MultiHashMapIterator32Callback it,
2090 void *it_cls); 1734 void *it_cls);
2091 1735
2092 1736
@@ -2121,7 +1765,7 @@ GNUNET_CONTAINER_multihashmap32_iterator_create (
2121 * @return #GNUNET_YES we returned an element, 1765 * @return #GNUNET_YES we returned an element,
2122 * #GNUNET_NO if we are out of elements 1766 * #GNUNET_NO if we are out of elements
2123 */ 1767 */
2124int 1768enum GNUNET_GenericReturnValue
2125GNUNET_CONTAINER_multihashmap32_iterator_next ( 1769GNUNET_CONTAINER_multihashmap32_iterator_next (
2126 struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter, 1770 struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter,
2127 uint32_t *key, 1771 uint32_t *key,
@@ -2568,7 +2212,7 @@ GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap);
2568 * @return #GNUNET_YES if an element is returned, 2212 * @return #GNUNET_YES if an element is returned,
2569 * #GNUNET_NO if the heap is empty. 2213 * #GNUNET_NO if the heap is empty.
2570 */ 2214 */
2571int 2215enum GNUNET_GenericReturnValue
2572GNUNET_CONTAINER_heap_peek2 (const struct GNUNET_CONTAINER_Heap *heap, 2216GNUNET_CONTAINER_heap_peek2 (const struct GNUNET_CONTAINER_Heap *heap,
2573 void **element, 2217 void **element,
2574 GNUNET_CONTAINER_HeapCostType *cost); 2218 GNUNET_CONTAINER_HeapCostType *cost);
@@ -2608,8 +2252,8 @@ GNUNET_CONTAINER_heap_node_get_cost (
2608 * @return #GNUNET_YES if we should continue to iterate, 2252 * @return #GNUNET_YES if we should continue to iterate,
2609 * #GNUNET_NO if not. 2253 * #GNUNET_NO if not.
2610 */ 2254 */
2611typedef int 2255typedef enum GNUNET_GenericReturnValue
2612(*GNUNET_CONTAINER_HeapIterator) ( 2256(*GNUNET_CONTAINER_HeapIterator)(
2613 void *cls, 2257 void *cls,
2614 struct GNUNET_CONTAINER_HeapNode *node, 2258 struct GNUNET_CONTAINER_HeapNode *node,
2615 void *element, 2259 void *element,
@@ -2704,4 +2348,7 @@ GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_HeapNode *node,
2704 2348
2705/* ifndef GNUNET_CONTAINER_LIB_H */ 2349/* ifndef GNUNET_CONTAINER_LIB_H */
2706#endif 2350#endif
2351
2352/** @} */ /* end of group addition */
2353
2707/* end of gnunet_container_lib.h */ 2354/* end of gnunet_container_lib.h */
diff --git a/src/include/gnunet_conversation_service.h b/src/include/gnunet_conversation_service.h
index be5a81cfb..7857a49cf 100644
--- a/src/include/gnunet_conversation_service.h
+++ b/src/include/gnunet_conversation_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup conversation_l2 Conversation service and libraries
23 * @{
24 *
22 * @author Simon Dieterle 25 * @author Simon Dieterle
23 * @author Andreas Fuchs 26 * @author Andreas Fuchs
24 * @author Christian Grothoff 27 * @author Christian Grothoff
@@ -58,6 +61,7 @@ extern "C"
58#endif 61#endif
59#endif 62#endif
60 63
64
61#include "gnunet_util_lib.h" 65#include "gnunet_util_lib.h"
62#include "gnunet_identity_service.h" 66#include "gnunet_identity_service.h"
63#include "gnunet_namestore_service.h" 67#include "gnunet_namestore_service.h"
@@ -147,7 +151,7 @@ typedef void
147 struct GNUNET_CONVERSATION_Caller * 151 struct GNUNET_CONVERSATION_Caller *
148 caller, 152 caller,
149 const struct 153 const struct
150 GNUNET_IDENTITY_PublicKey *caller_id); 154 GNUNET_CRYPTO_PublicKey *caller_id);
151 155
152 156
153/** 157/**
@@ -438,3 +442,5 @@ GNUNET_CONVERSATION_call_stop (struct GNUNET_CONVERSATION_Call *call);
438#endif 442#endif
439 443
440/** @} */ /* end of group */ 444/** @} */ /* end of group */
445
446/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h
index 59d9613f8..c3069be81 100644
--- a/src/include/gnunet_core_service.h
+++ b/src/include/gnunet_core_service.h
@@ -20,6 +20,9 @@
20/** 20/**
21 * @author Christian Grothoff 21 * @author Christian Grothoff
22 * 22 *
23 * @addtogroup Backbone
24 * @{
25 *
23 * @file include/gnunet_core_service.h 26 * @file include/gnunet_core_service.h
24 * Core service; the main API for encrypted P2P communications 27 * Core service; the main API for encrypted P2P communications
25 * 28 *
@@ -40,8 +43,8 @@ extern "C" {
40#endif 43#endif
41#endif 44#endif
42 45
46
43#include "gnunet_util_lib.h" 47#include "gnunet_util_lib.h"
44#include "gnunet_transport_service.h"
45 48
46/** 49/**
47 * Version number of GNUnet-core API. 50 * Version number of GNUnet-core API.
@@ -441,4 +444,6 @@ GNUNET_CORE_mq_create (struct GNUNET_CORE_Handle *h,
441 444
442/** @} */ /* end of group core */ 445/** @} */ /* end of group core */
443 446
447/** @} */ /* end of backbone addition */
448
444/* end of gnunet_core_service.h */ 449/* end of gnunet_core_service.h */
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index edb4bb230..b74bbcd1e 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
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-2023 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @file include/gnunet_crypto_lib.h 26 * @file include/gnunet_crypto_lib.h
23 * @brief cryptographic primitives for GNUnet 27 * @brief cryptographic primitives for GNUnet
24 * 28 *
@@ -40,6 +44,10 @@
40 * @see [Documentation](https://gnunet.org/crypto-api) 44 * @see [Documentation](https://gnunet.org/crypto-api)
41 */ 45 */
42 46
47#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
48#error "Only <gnunet_util_lib.h> can be included directly."
49#endif
50
43#ifndef GNUNET_CRYPTO_LIB_H 51#ifndef GNUNET_CRYPTO_LIB_H
44#define GNUNET_CRYPTO_LIB_H 52#define GNUNET_CRYPTO_LIB_H
45 53
@@ -50,6 +58,8 @@ extern "C" {
50#endif 58#endif
51#endif 59#endif
52 60
61
62#include <stdbool.h>
53#include <sodium.h> 63#include <sodium.h>
54 64
55/** 65/**
@@ -57,7 +67,6 @@ extern "C" {
57 */ 67 */
58struct GNUNET_PeerIdentity; 68struct GNUNET_PeerIdentity;
59 69
60#include "gnunet_common.h"
61#include <gcrypt.h> 70#include <gcrypt.h>
62 71
63 72
@@ -286,6 +295,170 @@ struct GNUNET_CRYPTO_EddsaPrivateScalar
286 unsigned char s[512 / 8]; 295 unsigned char s[512 / 8];
287}; 296};
288 297
298/**
299 * Private ECC key material encoded for transmission. To be used only for
300 * Edx25519 signatures. An initial key corresponds to data from the key
301 * expansion and clamping in the EdDSA key generation.
302 */
303struct GNUNET_CRYPTO_Edx25519PrivateKey
304{
305 /**
306 * a is a value mod n, where n has at most 256 bits. It is the first half of
307 * the seed-expansion of EdDSA and will be clamped.
308 */
309 unsigned char a[256 / 8];
310
311 /**
312 * b consists of 32 bytes which where originally the lower 32bytes of the key
313 * expansion. Subsequent calls to derive_private will change this value, too.
314 */
315 unsigned char b[256 / 8];
316};
317
318
319/**
320 * Public ECC key (always for curve Ed25519) encoded in a format suitable for
321 * network transmission and Edx25519 (same as EdDSA) signatures. Refer to
322 * section 5.1.3 of rfc8032, for a thorough explanation of how this value maps
323 * to the x- and y-coordinates.
324 */
325struct GNUNET_CRYPTO_Edx25519PublicKey
326{
327 /**
328 * Point Q consists of a y-value mod p (256 bits); the x-value is
329 * always positive. The point is stored in Ed25519 standard
330 * compact format.
331 */
332 unsigned char q_y[256 / 8];
333};
334
335/**
336 * @brief an ECC signature using Edx25519 (same as in EdDSA).
337 */
338struct GNUNET_CRYPTO_Edx25519Signature
339{
340 /**
341 * R value.
342 */
343 unsigned char r[256 / 8];
344
345 /**
346 * S value.
347 */
348 unsigned char s[256 / 8];
349};
350
351/**
352 * Elligator representative (always for Curve25519)
353 */
354struct GNUNET_CRYPTO_ElligatorRepresentative
355{
356 /**
357 * Represents an element of Curve25519 finite field.
358 * Always smaller than 2 ^ 254 - 10 -> Needs to be serialized into a random-looking byte stream before transmission.
359 */
360 unsigned char r[256 / 8];
361};
362
363/**
364 * Key type for the generic public key union
365 */
366enum GNUNET_CRYPTO_KeyType
367{
368 /**
369 * The identity type. The value is the same as the
370 * PKEY record type.
371 */
372 GNUNET_PUBLIC_KEY_TYPE_ECDSA = 65536,
373
374 /**
375 * EDDSA identity. The value is the same as the EDKEY
376 * record type.
377 */
378 GNUNET_PUBLIC_KEY_TYPE_EDDSA = 65556
379};
380
381/**
382 * A private key for an identity as per LSD0001.
383 * Note that these types are NOT packed and MUST NOT be used in RPC
384 * messages. Use the respective serialization functions.
385 */
386struct GNUNET_CRYPTO_PrivateKey
387{
388 /**
389 * Type of public key.
390 * Defined by the GNS zone type value.
391 * In NBO.
392 */
393 uint32_t type;
394
395 union
396 {
397 /**
398 * An ECDSA identity key.
399 */
400 struct GNUNET_CRYPTO_EcdsaPrivateKey ecdsa_key;
401
402 /**
403 * AN EdDSA identtiy key
404 */
405 struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_key;
406 };
407};
408
409
410/**
411 * An identity key as per LSD0001.
412 */
413struct GNUNET_CRYPTO_PublicKey
414{
415 /**
416 * Type of public key.
417 * Defined by the GNS zone type value.
418 * In NBO.
419 */
420 uint32_t type;
421
422 union
423 {
424 /**
425 * An ECDSA identity key.
426 */
427 struct GNUNET_CRYPTO_EcdsaPublicKey ecdsa_key;
428
429 /**
430 * AN EdDSA identtiy key
431 */
432 struct GNUNET_CRYPTO_EddsaPublicKey eddsa_key;
433 };
434};
435
436
437/**
438 * An identity signature as per LSD0001.
439 */
440struct GNUNET_CRYPTO_Signature
441{
442 /**
443 * Type of signature.
444 * Defined by the GNS zone type value.
445 * In NBO.
446 */
447 uint32_t type;
448
449 union
450 {
451 /**
452 * An ECDSA signature
453 */
454 struct GNUNET_CRYPTO_EcdsaSignature ecdsa_signature;
455
456 /**
457 * AN EdDSA signature
458 */
459 struct GNUNET_CRYPTO_EddsaSignature eddsa_signature;
460 };
461};
289 462
290/** 463/**
291 * @brief type for session keys 464 * @brief type for session keys
@@ -306,7 +479,7 @@ struct GNUNET_CRYPTO_SymmetricSessionKey
306/** 479/**
307 * Type of a nonce used for challenges. 480 * Type of a nonce used for challenges.
308 */ 481 */
309struct ChallengeNonceP 482struct GNUNET_CRYPTO_ChallengeNonceP
310{ 483{
311 /** 484 /**
312 * The value of the nonce. Note that this is NOT a hash. 485 * The value of the nonce. Note that this is NOT a hash.
@@ -392,6 +565,143 @@ struct GNUNET_CRYPTO_PaillierCiphertext
392}; 565};
393 566
394 567
568/**
569 * Curve25519 Scalar
570 */
571struct GNUNET_CRYPTO_Cs25519Scalar
572{
573 /**
574 * 32 byte scalar
575 */
576 unsigned char d[crypto_core_ed25519_SCALARBYTES];
577};
578
579
580/**
581 * Curve25519 point
582 */
583struct GNUNET_CRYPTO_Cs25519Point
584{
585 /**
586 * This is a point on the Curve25519.
587 * The x coordinate can be restored using the y coordinate
588 */
589 unsigned char y[crypto_core_ed25519_BYTES];
590};
591
592
593/**
594 * The private information of an Schnorr key pair.
595 */
596struct GNUNET_CRYPTO_CsPrivateKey
597{
598 struct GNUNET_CRYPTO_Cs25519Scalar scalar;
599};
600
601
602/**
603 * The public information of an Schnorr key pair.
604 */
605struct GNUNET_CRYPTO_CsPublicKey
606{
607 struct GNUNET_CRYPTO_Cs25519Point point;
608};
609
610
611/**
612 * Secret used for blinding (alpha and beta).
613 */
614struct GNUNET_CRYPTO_CsBlindingSecret
615{
616 struct GNUNET_CRYPTO_Cs25519Scalar alpha;
617 struct GNUNET_CRYPTO_Cs25519Scalar beta;
618};
619
620
621/**
622 * the private r used in the signature
623 */
624struct GNUNET_CRYPTO_CsRSecret
625{
626 struct GNUNET_CRYPTO_Cs25519Scalar scalar;
627};
628
629
630/**
631 * the public R (derived from r) used in c
632 */
633struct GNUNET_CRYPTO_CsRPublic
634{
635 struct GNUNET_CRYPTO_Cs25519Point point;
636};
637
638
639/**
640 * Schnorr c to be signed
641 */
642struct GNUNET_CRYPTO_CsC
643{
644 struct GNUNET_CRYPTO_Cs25519Scalar scalar;
645};
646
647
648/**
649 * s in the signature
650 */
651struct GNUNET_CRYPTO_CsS
652{
653 struct GNUNET_CRYPTO_Cs25519Scalar scalar;
654};
655
656
657/**
658 * blinded s in the signature
659 */
660struct GNUNET_CRYPTO_CsBlindS
661{
662 struct GNUNET_CRYPTO_Cs25519Scalar scalar;
663};
664
665
666/**
667 * CS Signtature containing scalar s and point R
668 */
669struct GNUNET_CRYPTO_CsSignature
670{
671 /**
672 * Schnorr signatures are composed of a scalar s and a curve point
673 */
674 struct GNUNET_CRYPTO_CsS s_scalar;
675
676 /**
677 * Curve point of the Schnorr signature.
678 */
679 struct GNUNET_CRYPTO_CsRPublic r_point;
680};
681
682
683/**
684 * Nonce for the session, picked by client,
685 * shared with the signer.
686 */
687struct GNUNET_CRYPTO_CsSessionNonce
688{
689 /*a nonce*/
690 unsigned char snonce[256 / 8];
691};
692
693
694/**
695 * Nonce for computing blinding factors. Not
696 * shared with the signer.
697 */
698struct GNUNET_CRYPTO_CsBlindingNonce
699{
700 /*a nonce*/
701 unsigned char bnonce[256 / 8];
702};
703
704
395/* **************** Functions and Macros ************* */ 705/* **************** Functions and Macros ************* */
396 706
397/** 707/**
@@ -480,7 +790,7 @@ GNUNET_CRYPTO_zero_keys (void *buffer, size_t length);
480 * Fill block with a random values. 790 * Fill block with a random values.
481 * 791 *
482 * @param mode desired quality of the random number 792 * @param mode desired quality of the random number
483 * @param buffer the buffer to fill 793 * @param[out] buffer the buffer to fill
484 * @param length buffer length 794 * @param length buffer length
485 */ 795 */
486void 796void
@@ -497,7 +807,7 @@ GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode,
497 * here is not a completely random number. 807 * here is not a completely random number.
498 * 808 *
499 * @param mode desired quality of the random number 809 * @param mode desired quality of the random number
500 * @param uuid the value to fill 810 * @param[out] uuid the value to fill
501 */ 811 */
502void 812void
503GNUNET_CRYPTO_random_timeflake (enum GNUNET_CRYPTO_Quality mode, 813GNUNET_CRYPTO_random_timeflake (enum GNUNET_CRYPTO_Quality mode,
@@ -518,7 +828,7 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i);
518 828
519/** 829/**
520 * @ingroup crypto 830 * @ingroup crypto
521 * Random on unsigned 64-bit values. 831 * Generate a random unsigned 64-bit value.
522 * 832 *
523 * @param mode desired quality of the random number 833 * @param mode desired quality of the random number
524 * @param max value returned will be in range [0,@a max) (exclusive) 834 * @param max value returned will be in range [0,@a max) (exclusive)
@@ -781,7 +1091,7 @@ GNUNET_CRYPTO_hash_context_abort (struct GNUNET_HashContext *hc);
781 1091
782/** 1092/**
783 * Calculate HMAC of a message (RFC 2104) 1093 * Calculate HMAC of a message (RFC 2104)
784 * TODO: Shouldn' this be the standard hmac function and 1094 * TODO: Shouldn't this be the standard hmac function and
785 * the above be renamed? 1095 * the above be renamed?
786 * 1096 *
787 * @param key secret key 1097 * @param key secret key
@@ -916,61 +1226,38 @@ GNUNET_CRYPTO_hash_xor (const struct GNUNET_HashCode *a,
916 1226
917 1227
918/** 1228/**
919 * @ingroup hash 1229 * Count the number of leading 0 bits in @a h.
920 * Convert a hashcode into a key.
921 * 1230 *
922 * @param hc hash code that serves to generate the key 1231 * @param h a hash
923 * @param skey set to a valid session key 1232 * @return number of leading 0 bits in @a h
924 * @param iv set to a valid initialization vector
925 */ 1233 */
926void 1234unsigned int
927GNUNET_CRYPTO_hash_to_aes_key ( 1235GNUNET_CRYPTO_hash_count_leading_zeros (const struct GNUNET_HashCode *h);
928 const struct GNUNET_HashCode *hc,
929 struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
930 struct GNUNET_CRYPTO_SymmetricInitializationVector *iv);
931 1236
932 1237
933/** 1238/**
934 * @ingroup hash 1239 * Count the number of tailing 0 bits in @a h.
935 * Obtain a bit from a hashcode.
936 * 1240 *
937 * @param code the `struct GNUNET_HashCode` to index bit-wise 1241 * @param h a hash
938 * @param bit index into the hashcode, [0...159] where 0 is the leftmost bit 1242 * @return number of tailing 0 bits in @a h
939 * (bytes in code interpreted big endian)
940 * @return Bit \a bit from hashcode \a code, -1 for invalid index
941 */
942int
943GNUNET_CRYPTO_hash_get_bit_ltr (const struct GNUNET_HashCode *code,
944 unsigned int bit);
945
946
947/**
948 * Obtain a bit from a hashcode.
949 * @param code the GNUNET_CRYPTO_hash to index bit-wise
950 * @param bit index into the hashcode, [0...511] where 0 is the rightmost bit
951 * (bytes in code interpreted little endian)
952 * @return Bit \a bit from hashcode \a code, -1 for invalid index
953 */ 1243 */
954int 1244unsigned int
955GNUNET_CRYPTO_hash_get_bit_rtl (const struct GNUNET_HashCode *code, 1245GNUNET_CRYPTO_hash_count_tailing_zeros (const struct GNUNET_HashCode *h);
956 unsigned int bit);
957 1246
958 1247
959/** 1248/**
960 * @ingroup hash 1249 * @ingroup hash
961 * Determine how many low order bits match in two 1250 * Convert a hashcode into a key.
962 * `struct GNUNET_HashCodes`. e.g. - 010011 and 011111 share
963 * the first two lowest order bits, and therefore the
964 * return value is two (NOT XOR distance, nor how many
965 * bits match absolutely!).
966 * 1251 *
967 * @param first the first hashcode 1252 * @param hc hash code that serves to generate the key
968 * @param second the hashcode to compare first to 1253 * @param skey set to a valid session key
969 * @return the number of bits that match 1254 * @param iv set to a valid initialization vector
970 */ 1255 */
971unsigned int 1256void
972GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode *first, 1257GNUNET_CRYPTO_hash_to_aes_key (
973 const struct GNUNET_HashCode *second); 1258 const struct GNUNET_HashCode *hc,
1259 struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
1260 struct GNUNET_CRYPTO_SymmetricInitializationVector *iv);
974 1261
975 1262
976/** 1263/**
@@ -1180,6 +1467,17 @@ GNUNET_CRYPTO_eddsa_key_get_public (
1180 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, 1467 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1181 struct GNUNET_CRYPTO_EddsaPublicKey *pub); 1468 struct GNUNET_CRYPTO_EddsaPublicKey *pub);
1182 1469
1470/**
1471 * @ingroup crypto
1472 * Extract the public key for the given private key.
1473 *
1474 * @param priv the private key
1475 * @param pub where to write the public key
1476 */
1477void
1478GNUNET_CRYPTO_edx25519_key_get_public (
1479 const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv,
1480 struct GNUNET_CRYPTO_Edx25519PublicKey *pub);
1183 1481
1184/** 1482/**
1185 * @ingroup crypto 1483 * @ingroup crypto
@@ -1264,7 +1562,7 @@ enum GNUNET_GenericReturnValue
1264GNUNET_CRYPTO_eddsa_private_key_from_string ( 1562GNUNET_CRYPTO_eddsa_private_key_from_string (
1265 const char *enc, 1563 const char *enc,
1266 size_t enclen, 1564 size_t enclen,
1267 struct GNUNET_CRYPTO_EddsaPrivateKey *pub); 1565 struct GNUNET_CRYPTO_EddsaPrivateKey *priv);
1268 1566
1269 1567
1270/** 1568/**
@@ -1366,7 +1664,34 @@ GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk);
1366 1664
1367/** 1665/**
1368 * @ingroup crypto 1666 * @ingroup crypto
1667 * Create a new private key.
1668 *
1669 * @param[out] pk private key to initialize
1670 */
1671void
1672GNUNET_CRYPTO_edx25519_key_create (struct GNUNET_CRYPTO_Edx25519PrivateKey *pk);
1673
1674/**
1675 * @ingroup crypto
1676 * Create a new private key for Edx25519 from a given seed. After expanding
1677 * the seed, the first half of the key will be clamped according to EdDSA.
1678 *
1679 * @param seed seed input
1680 * @param seedsize size of the seed in bytes
1681 * @param[out] pk private key to initialize
1682 */
1683void
1684GNUNET_CRYPTO_edx25519_key_create_from_seed (
1685 const void *seed,
1686 size_t seedsize,
1687 struct GNUNET_CRYPTO_Edx25519PrivateKey *pk);
1688
1689/**
1690 * @ingroup crypto
1369 * Create a new private key. Clear with #GNUNET_CRYPTO_ecdhe_key_clear(). 1691 * Create a new private key. Clear with #GNUNET_CRYPTO_ecdhe_key_clear().
1692 * This is X25519 DH (RFC 7748 Section 5) and corresponds to
1693 * X25519(a,9).
1694 * See #GNUNET_CRYPTO_ecc_ecdh for the DH function.
1370 * 1695 *
1371 * @param[out] pk set to fresh private key; 1696 * @param[out] pk set to fresh private key;
1372 */ 1697 */
@@ -1393,6 +1718,14 @@ GNUNET_CRYPTO_eddsa_key_clear (struct GNUNET_CRYPTO_EddsaPrivateKey *pk);
1393void 1718void
1394GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk); 1719GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk);
1395 1720
1721/**
1722 * @ingroup crypto
1723 * Clear memory that was used to store a private key.
1724 *
1725 * @param pk location of the key
1726 */
1727void
1728GNUNET_CRYPTO_edx25519_key_clear (struct GNUNET_CRYPTO_Edx25519PrivateKey *pk);
1396 1729
1397/** 1730/**
1398 * @ingroup crypto 1731 * @ingroup crypto
@@ -1403,6 +1736,15 @@ GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk);
1403void 1736void
1404GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk); 1737GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk);
1405 1738
1739/**
1740 * @ingroup crypto
1741 * Clear memory that was used to store a private key.
1742 *
1743 * @param pk location of the key
1744 */
1745void
1746GNUNET_CRYPTO_private_key_clear (struct GNUNET_CRYPTO_PrivateKey *pk);
1747
1406 1748
1407/** 1749/**
1408 * @ingroup crypto 1750 * @ingroup crypto
@@ -1436,12 +1778,49 @@ GNUNET_CRYPTO_eddsa_setup_hostkey (const char *cfg_name);
1436 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the identity 1778 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the identity
1437 * could not be retrieved 1779 * could not be retrieved
1438 */ 1780 */
1439int 1781enum GNUNET_GenericReturnValue
1440GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, 1782GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg,
1441 struct GNUNET_PeerIdentity *dst); 1783 struct GNUNET_PeerIdentity *dst);
1442 1784
1443 1785
1444/** 1786/**
1787 * @ingroup crypto
1788 * Sign a given block with a specific purpose using the host's peer identity.
1789 *
1790 * @param cfg configuration to use
1791 * @param purpose what to sign (size, purpose)
1792 * @param sig where to write the signature
1793 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the identity
1794 * could not be retrieved
1795 */
1796enum GNUNET_GenericReturnValue
1797GNUNET_CRYPTO_sign_by_peer_identity (const struct
1798 GNUNET_CONFIGURATION_Handle *cfg,
1799 const struct
1800 GNUNET_CRYPTO_EccSignaturePurpose *purpose,
1801 struct GNUNET_CRYPTO_EddsaSignature *sig);
1802
1803
1804/**
1805 * @ingroup crypto
1806 * Verify a given signature with a peer's identity.
1807 *
1808 * @param purpose what is the purpose that the signature should have?
1809 * @param validate block to validate (size, purpose, data)
1810 * @param sig signature that is being validated
1811 * @param identity the peer's identity to verify
1812 * @return #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
1813 */
1814enum GNUNET_GenericReturnValue
1815GNUNET_CRYPTO_verify_peer_identity (uint32_t purpose,
1816 const struct
1817 GNUNET_CRYPTO_EccSignaturePurpose *validate,
1818 const struct
1819 GNUNET_CRYPTO_EddsaSignature *sig,
1820 const struct GNUNET_PeerIdentity *identity);
1821
1822
1823/**
1445 * Internal structure used to cache pre-calculated values for DLOG calculation. 1824 * Internal structure used to cache pre-calculated values for DLOG calculation.
1446 */ 1825 */
1447struct GNUNET_CRYPTO_EccDlogContext; 1826struct GNUNET_CRYPTO_EccDlogContext;
@@ -1484,7 +1863,7 @@ GNUNET_CRYPTO_ecc_dlog_prepare (unsigned int max,
1484 * Calculate ECC discrete logarithm for small factors. 1863 * Calculate ECC discrete logarithm for small factors.
1485 * Opposite of #GNUNET_CRYPTO_ecc_dexp(). 1864 * Opposite of #GNUNET_CRYPTO_ecc_dexp().
1486 * 1865 *
1487 * @param dlc precalculated values, determine range of factors 1866 * @param edc precalculated values, determine range of factors
1488 * @param input point on the curve to factor 1867 * @param input point on the curve to factor
1489 * @return INT_MAX if dlog failed, otherwise the factor 1868 * @return INT_MAX if dlog failed, otherwise the factor
1490 */ 1869 */
@@ -1607,6 +1986,9 @@ GNUNET_CRYPTO_ecc_scalar_from_int (int64_t val,
1607/** 1986/**
1608 * @ingroup crypto 1987 * @ingroup crypto
1609 * Derive key material from a public and a private ECC key. 1988 * Derive key material from a public and a private ECC key.
1989 * This is X25519 DH (RFC 7748 Section 5) and corresponds to
1990 * H(X25519(b,X25519(a,9))) where b := priv, pub := X25519(a,9),
1991 * and a := #GNUNET_CRYPTO_ecdhe_key_create().
1610 * 1992 *
1611 * @param priv private key to use for the ECDH (x) 1993 * @param priv private key to use for the ECDH (x)
1612 * @param pub public key to use for the ECDH (yG) 1994 * @param pub public key to use for the ECDH (yG)
@@ -1623,6 +2005,10 @@ GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1623 * @ingroup crypto 2005 * @ingroup crypto
1624 * Derive key material from a ECDH public key and a private EdDSA key. 2006 * Derive key material from a ECDH public key and a private EdDSA key.
1625 * Dual to #GNUNET_CRRYPTO_ecdh_eddsa. 2007 * Dual to #GNUNET_CRRYPTO_ecdh_eddsa.
2008 * This uses the Ed25519 private seed as X25519 seed.
2009 * As such, this also is a X25519 DH (see #GNUNET_CRYPTO_ecc_ecdh).
2010 * NOTE: Whenever you can get away with it, use separate key pairs
2011 * for signing and encryption (DH)!
1626 * 2012 *
1627 * @param priv private key from EdDSA to use for the ECDH (x) 2013 * @param priv private key from EdDSA to use for the ECDH (x)
1628 * @param pub public key to use for the ECDH (yG) 2014 * @param pub public key to use for the ECDH (yG)
@@ -1634,6 +2020,122 @@ GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1634 const struct GNUNET_CRYPTO_EcdhePublicKey *pub, 2020 const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
1635 struct GNUNET_HashCode *key_material); 2021 struct GNUNET_HashCode *key_material);
1636 2022
2023/**
2024 * @ingroup crypto
2025 * Decapsulate a key for a private EdDSA key.
2026 * Dual to #GNUNET_CRRYPTO_eddsa_kem_encaps.
2027 *
2028 * @param priv private key from EdDSA to use for the ECDH (x)
2029 * @param c the encapsulated key
2030 * @param key_material where to write the key material H(h(x)yG)
2031 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2032 */
2033enum GNUNET_GenericReturnValue
2034GNUNET_CRYPTO_eddsa_kem_decaps (const struct
2035 GNUNET_CRYPTO_EddsaPrivateKey *priv,
2036 const struct GNUNET_CRYPTO_EcdhePublicKey *c,
2037 struct GNUNET_HashCode *key_material);
2038
2039/**
2040 * @ingroup crypto
2041 * Encapsulate key material for a EdDSA public key.
2042 * Dual to #GNUNET_CRRYPTO_eddsa_kem_decaps.
2043 *
2044 * @param priv private key to use for the ECDH (y)
2045 * @param c public key from EdDSA to use for the ECDH (X=h(x)G)
2046 * @param key_material where to write the key material H(yX)=H(h(x)yG)
2047 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2048 */
2049enum GNUNET_GenericReturnValue
2050GNUNET_CRYPTO_eddsa_kem_encaps (const struct GNUNET_CRYPTO_EddsaPublicKey *pub,
2051 struct GNUNET_CRYPTO_EcdhePublicKey *c,
2052 struct GNUNET_HashCode *key_material);
2053
2054/**
2055 * This is the encapsulated key of our FO-KEM.
2056 */
2057struct GNUNET_CRYPTO_FoKemC
2058{
2059 /* The output of the FO-OWTF F(x) */
2060 struct GNUNET_HashCode y;
2061
2062 /* The ephemeral public key from the DH in the KEM */
2063 struct GNUNET_CRYPTO_EcdhePublicKey pub;
2064};
2065
2066/**
2067 * @ingroup crypto
2068 * Encapsulate key material using a CCA-secure KEM.
2069 * The KEM is using a OWTF with image oracle constructed from
2070 * a Fujusaki-Okamoto transformation using ElGamal (DH plus XOR OTP).
2071 * Dual to #GNUNET_CRRYPTO_eddsa_fo_kem_decaps.
2072 *
2073 * @param pub public key to encapsulated for
2074 * @param[out] c the encapsulation
2075 * @param[out] key_material the encapsulated key
2076 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2077 */
2078enum GNUNET_GenericReturnValue
2079GNUNET_CRYPTO_eddsa_fo_kem_encaps (
2080 const struct GNUNET_CRYPTO_EddsaPublicKey *pub,
2081 struct GNUNET_CRYPTO_FoKemC *c,
2082 struct GNUNET_HashCode *key_material);
2083
2084
2085/**
2086 * @ingroup crypto
2087 * Decapsulate key material using a CCA-secure KEM.
2088 * The KEM is using a OWTF with image oracle constructed from
2089 * a Fujusaki-Okamoto transformation using ElGamal (DH plus XOR OTP).
2090 * Dual to #GNUNET_CRRYPTO_eddsa_fo_kem_encaps.
2091 *
2092 * @param priv private key this encapsulation is for
2093 * @param c the encapsulation
2094 * @param[out] key_material the encapsulated key
2095 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2096 */
2097enum GNUNET_GenericReturnValue
2098GNUNET_CRYPTO_eddsa_fo_kem_decaps (const struct
2099 GNUNET_CRYPTO_EddsaPrivateKey *priv,
2100 const struct GNUNET_CRYPTO_FoKemC *c,
2101 struct GNUNET_HashCode *key_material);
2102
2103/**
2104 * @ingroup crypto
2105 * Encapsulate key material using a CCA-secure KEM.
2106 * The KEM is using a OWTF with image oracle constructed from
2107 * a Fujusaki-Okamoto transformation using ElGamal (DH plus XOR OTP).
2108 * Dual to #GNUNET_CRRYPTO_eddsa_fo_kem_decaps.
2109 *
2110 * @param pub public key to encapsulated for
2111 * @param[out] c the encapsulation
2112 * @param[out] key_material the encapsulated key
2113 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2114 */
2115enum GNUNET_GenericReturnValue
2116GNUNET_CRYPTO_ecdsa_fo_kem_encaps (const struct
2117 GNUNET_CRYPTO_EcdsaPublicKey *pub,
2118 struct GNUNET_CRYPTO_FoKemC *c,
2119 struct GNUNET_HashCode *key_material);
2120
2121
2122/**
2123 * @ingroup crypto
2124 * Decapsulate key material using a CCA-secure KEM.
2125 * The KEM is using a OWTF with image oracle constructed from
2126 * a Fujusaki-Okamoto transformation using ElGamal (DH plus XOR OTP).
2127 * Dual to #GNUNET_CRRYPTO_eddsa_fo_kem_encaps.
2128 *
2129 * @param priv private key this encapsulation is for
2130 * @param c the encapsulation
2131 * @param[out] key_material the encapsulated key
2132 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2133 */
2134enum GNUNET_GenericReturnValue
2135GNUNET_CRYPTO_ecdsa_fo_kem_decaps (const struct
2136 GNUNET_CRYPTO_EcdsaPrivateKey *priv,
2137 struct GNUNET_CRYPTO_FoKemC *c,
2138 struct GNUNET_HashCode *key_material);
1637 2139
1638/** 2140/**
1639 * @ingroup crypto 2141 * @ingroup crypto
@@ -1655,6 +2157,10 @@ GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
1655 * @ingroup crypto 2157 * @ingroup crypto
1656 * Derive key material from a EdDSA public key and a private ECDH key. 2158 * Derive key material from a EdDSA public key and a private ECDH key.
1657 * Dual to #GNUNET_CRRYPTO_eddsa_ecdh. 2159 * Dual to #GNUNET_CRRYPTO_eddsa_ecdh.
2160 * This converts the Edwards25519 public key @a pub to a Curve25519
2161 * public key before computing a X25519 DH (see #GNUNET_CRYPTO_ecc_ecdh).
2162 * NOTE: Whenever you can get away with it, use separate key pairs
2163 * for signing and encryption (DH)!
1658 * 2164 *
1659 * @param priv private key to use for the ECDH (y) 2165 * @param priv private key to use for the ECDH (y)
1660 * @param pub public key from EdDSA to use for the ECDH (X=h(x)G) 2166 * @param pub public key from EdDSA to use for the ECDH (X=h(x)G)
@@ -1666,6 +2172,7 @@ GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1666 const struct GNUNET_CRYPTO_EddsaPublicKey *pub, 2172 const struct GNUNET_CRYPTO_EddsaPublicKey *pub,
1667 struct GNUNET_HashCode *key_material); 2173 struct GNUNET_HashCode *key_material);
1668 2174
2175
1669/** 2176/**
1670 * @ingroup crypto 2177 * @ingroup crypto
1671 * Derive key material from a EcDSA public key and a private ECDH key. 2178 * Derive key material from a EcDSA public key and a private ECDH key.
@@ -1750,6 +2257,21 @@ GNUNET_CRYPTO_ecdsa_sign_ (
1750 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, 2257 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
1751 struct GNUNET_CRYPTO_EcdsaSignature *sig); 2258 struct GNUNET_CRYPTO_EcdsaSignature *sig);
1752 2259
2260/**
2261 * @brief
2262 *
2263 * @param priv
2264 * @param data
2265 * @param size
2266 * @param sig
2267 * @return enum GNUNET_GenericReturnValue
2268 */
2269enum GNUNET_GenericReturnValue
2270GNUNET_CRYPTO_eddsa_sign_raw (
2271 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
2272 void *data,
2273 size_t size,
2274 struct GNUNET_CRYPTO_EddsaSignature *sig);
1753 2275
1754/** 2276/**
1755 * @ingroup crypto 2277 * @ingroup crypto
@@ -1775,6 +2297,53 @@ GNUNET_CRYPTO_ecdsa_sign_ (
1775 sig)); \ 2297 sig)); \
1776} while (0) 2298} while (0)
1777 2299
2300/**
2301 * @ingroup crypto
2302 * @brief Edx25519 sign a given block.
2303 *
2304 * The @a purpose data is the beginning of the data of which the signature is
2305 * to be created. The `size` field in @a purpose must correctly indicate the
2306 * number of bytes of the data structure, including its header. If possible,
2307 * use #GNUNET_CRYPTO_edx25519_sign() instead of this function (only if @a
2308 * validate is not fixed-size, you must use this function directly).
2309 *
2310 * @param priv private key to use for the signing
2311 * @param purpose what to sign (size, purpose)
2312 * @param[out] sig where to write the signature
2313 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2314 */
2315enum GNUNET_GenericReturnValue
2316GNUNET_CRYPTO_edx25519_sign_ (
2317 const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv,
2318 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
2319 struct GNUNET_CRYPTO_Edx25519Signature *sig);
2320
2321
2322/**
2323 * @ingroup crypto
2324 * @brief Edx25519 sign a given block. The resulting signature is compatible
2325 * with EdDSA.
2326 *
2327 * The @a ps data must be a fixed-size struct for which the signature is to be
2328 * created. The `size` field in @a ps->purpose must correctly indicate the
2329 * number of bytes of the data structure, including its header.
2330 *
2331 * @param priv private key to use for the signing
2332 * @param ps packed struct with what to sign, MUST begin with a purpose
2333 * @param[out] sig where to write the signature
2334 */
2335#define GNUNET_CRYPTO_edx25519_sign(priv,ps,sig) do { \
2336 /* check size is set correctly */ \
2337 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
2338 /* check 'ps' begins with the purpose */ \
2339 GNUNET_static_assert (((void*) (ps)) == \
2340 ((void*) &(ps)->purpose)); \
2341 GNUNET_assert (GNUNET_OK == \
2342 GNUNET_CRYPTO_edx25519_sign_ (priv, \
2343 &(ps)->purpose, \
2344 sig)); \
2345} while (0)
2346
1778 2347
1779/** 2348/**
1780 * @ingroup crypto 2349 * @ingroup crypto
@@ -1818,7 +2387,7 @@ GNUNET_CRYPTO_eddsa_verify_ (
1818 */ 2387 */
1819#define GNUNET_CRYPTO_eddsa_verify(purp,ps,sig,pub) ({ \ 2388#define GNUNET_CRYPTO_eddsa_verify(purp,ps,sig,pub) ({ \
1820 /* check size is set correctly */ \ 2389 /* check size is set correctly */ \
1821 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ 2390 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
1822 /* check 'ps' begins with the purpose */ \ 2391 /* check 'ps' begins with the purpose */ \
1823 GNUNET_static_assert (((void*) (ps)) == \ 2392 GNUNET_static_assert (((void*) (ps)) == \
1824 ((void*) &(ps)->purpose)); \ 2393 ((void*) &(ps)->purpose)); \
@@ -1828,7 +2397,6 @@ GNUNET_CRYPTO_eddsa_verify_ (
1828 pub); \ 2397 pub); \
1829 }) 2398 })
1830 2399
1831
1832/** 2400/**
1833 * @ingroup crypto 2401 * @ingroup crypto
1834 * @brief Verify ECDSA signature. 2402 * @brief Verify ECDSA signature.
@@ -1883,6 +2451,58 @@ GNUNET_CRYPTO_ecdsa_verify_ (
1883 2451
1884/** 2452/**
1885 * @ingroup crypto 2453 * @ingroup crypto
2454 * @brief Verify Edx25519 signature.
2455 *
2456 * The @a validate data is the beginning of the data of which the signature
2457 * is to be verified. The `size` field in @a validate must correctly indicate
2458 * the number of bytes of the data structure, including its header. If @a
2459 * purpose does not match the purpose given in @a validate (the latter must be
2460 * in big endian), signature verification fails. If possible, use
2461 * #GNUNET_CRYPTO_edx25519_verify() instead of this function (only if @a
2462 * validate is not fixed-size, you must use this function directly).
2463 *
2464 * @param purpose what is the purpose that the signature should have?
2465 * @param validate block to validate (size, purpose, data)
2466 * @param sig signature that is being validated
2467 * @param pub public key of the signer
2468 * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
2469 */
2470enum GNUNET_GenericReturnValue
2471GNUNET_CRYPTO_edx25519_verify_ (
2472 uint32_t purpose,
2473 const struct GNUNET_CRYPTO_EccSignaturePurpose *validate,
2474 const struct GNUNET_CRYPTO_Edx25519Signature *sig,
2475 const struct GNUNET_CRYPTO_Edx25519PublicKey *pub);
2476
2477
2478/**
2479 * @ingroup crypto
2480 * @brief Verify Edx25519 signature.
2481 *
2482 * The @a ps data must be a fixed-size struct for which the signature is to be
2483 * created. The `size` field in @a ps->purpose must correctly indicate the
2484 * number of bytes of the data structure, including its header.
2485 *
2486 * @param purp purpose of the signature, must match 'ps->purpose.purpose'
2487 * (except in host byte order)
2488 * @param priv private key to use for the signing
2489 * @param ps packed struct with what to sign, MUST begin with a purpose
2490 * @param sig where to write the signature
2491 */
2492#define GNUNET_CRYPTO_edx25519_verify(purp,ps,sig,pub) ({ \
2493 /* check size is set correctly */ \
2494 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
2495 /* check 'ps' begins with the purpose */ \
2496 GNUNET_static_assert (((void*) (ps)) == \
2497 ((void*) &(ps)->purpose)); \
2498 GNUNET_CRYPTO_edx25519_verify_ (purp, \
2499 &(ps)->purpose, \
2500 sig, \
2501 pub); \
2502 })
2503
2504/**
2505 * @ingroup crypto
1886 * Derive a private key from a given private key and a label. 2506 * Derive a private key from a given private key and a label.
1887 * Essentially calculates a private key 'h = H(l,P) * d mod n' 2507 * Essentially calculates a private key 'h = H(l,P) * d mod n'
1888 * where n is the size of the ECC group and P is the public 2508 * where n is the size of the ECC group and P is the public
@@ -1919,6 +2539,26 @@ GNUNET_CRYPTO_ecdsa_public_key_derive (
1919 const char *context, 2539 const char *context,
1920 struct GNUNET_CRYPTO_EcdsaPublicKey *result); 2540 struct GNUNET_CRYPTO_EcdsaPublicKey *result);
1921 2541
2542/**
2543 * This is a signature function for ECDSA which takes a
2544 * private key, derives/blinds it and signs the message.
2545 *
2546 * @param pkey original private key
2547 * @param label label to use for key deriviation
2548 * @param context additional context to use for HKDF of 'h';
2549 * typically the name of the subsystem/application
2550 * @param purpose the signature purpose
2551 * @param sig the resulting signature
2552 * @return GNUNET_OK on success
2553 */
2554enum GNUNET_GenericReturnValue
2555GNUNET_CRYPTO_ecdsa_sign_derived (
2556 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
2557 const char *label,
2558 const char *context,
2559 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
2560 struct GNUNET_CRYPTO_EcdsaSignature *sig);
2561
1922 2562
1923/** 2563/**
1924 * @ingroup crypto 2564 * @ingroup crypto
@@ -1964,23 +2604,23 @@ GNUNET_CRYPTO_eddsa_public_key_derive (
1964 2604
1965 2605
1966/** 2606/**
1967 * This is a signature function for EdDSA which takes the 2607 * This is a signature function for EdDSA which takes a
1968 * secret scalar sk instead of the private seed which is 2608 * private key and derives it using the label and context
1969 * usually the case for crypto APIs. We require this functionality 2609 * before signing.
1970 * in order to use derived private keys for signatures we
1971 * cannot calculate the inverse of a sk to find the seed
1972 * efficiently.
1973 * 2610 *
1974 * The resulting signature is a standard EdDSA signature 2611 * @param pkey original private key
1975 * which can be verified using the usual APIs. 2612 * @param label label to use for key deriviation
1976 * 2613 * @param context additional context to use for HKDF of 'h';
1977 * @param sk the secret scalar 2614 * typically the name of the subsystem/application
1978 * @param purp the signature purpose 2615 * @param purpose the signature purpose
1979 * @param sig the resulting signature 2616 * @param sig the resulting signature
2617 * @return GNUNET_OK on success
1980 */ 2618 */
1981void 2619enum GNUNET_GenericReturnValue
1982GNUNET_CRYPTO_eddsa_sign_with_scalar ( 2620GNUNET_CRYPTO_eddsa_sign_derived (
1983 const struct GNUNET_CRYPTO_EddsaPrivateScalar *priv, 2621 const struct GNUNET_CRYPTO_EddsaPrivateKey *pkey,
2622 const char *label,
2623 const char *context,
1984 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, 2624 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
1985 struct GNUNET_CRYPTO_EddsaSignature *sig); 2625 struct GNUNET_CRYPTO_EddsaSignature *sig);
1986 2626
@@ -1996,6 +2636,134 @@ GNUNET_CRYPTO_eddsa_key_get_public_from_scalar (
1996 const struct GNUNET_CRYPTO_EddsaPrivateScalar *s, 2636 const struct GNUNET_CRYPTO_EddsaPrivateScalar *s,
1997 struct GNUNET_CRYPTO_EddsaPublicKey *pkey); 2637 struct GNUNET_CRYPTO_EddsaPublicKey *pkey);
1998 2638
2639/**
2640 * @ingroup crypto
2641 * Derive a private scalar from a given private key and a label.
2642 * Essentially calculates a private key 'h = H(l,P) * d mod n'
2643 * where n is the size of the ECC group and P is the public
2644 * key associated with the private key 'd'.
2645 *
2646 * @param priv original private key
2647 * @param seed input seed
2648 * @param seedsize size of the seed
2649 * @param result derived private key
2650 */
2651void
2652GNUNET_CRYPTO_edx25519_private_key_derive (
2653 const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv,
2654 const void *seed,
2655 size_t seedsize,
2656 struct GNUNET_CRYPTO_Edx25519PrivateKey *result);
2657
2658
2659/**
2660 * @ingroup crypto
2661 * Derive a public key from a given public key and a label.
2662 * Essentially calculates a public key 'V = H(l,P) * P'.
2663 *
2664 * @param pub original public key
2665 * @param seed input seed
2666 * @param seedsize size of the seed
2667 * @param result where to write the derived public key
2668 */
2669void
2670GNUNET_CRYPTO_edx25519_public_key_derive (
2671 const struct GNUNET_CRYPTO_Edx25519PublicKey *pub,
2672 const void *seed,
2673 size_t seedsize,
2674 struct GNUNET_CRYPTO_Edx25519PublicKey *result);
2675
2676
2677/**
2678 * @ingroup crypto
2679 * Clears the most significant bit and second most significant bit of the serialized representaive before applying elligator direct map.
2680 *
2681 * @param representative serialized elligator representative of an element of Curves25519's finite field
2682 * @param point destination for the calculated point on the curve
2683 * @param high_y bool pointed to will be set to 'true' if corresponding y-coordinate is > 2 ^ 254 - 10, otherwise 0. Can be set to NULL if not needed.
2684 */
2685void
2686GNUNET_CRYPTO_ecdhe_elligator_decoding (
2687 struct GNUNET_CRYPTO_EcdhePublicKey *point,
2688 bool *high_y,
2689 const struct GNUNET_CRYPTO_ElligatorRepresentative *representative);
2690
2691/**
2692 * @ingroup crypto
2693 * Encodes a point on Curve25519 to a an element of the underlying finite field.
2694 * This transformation is deterministic.
2695 *
2696 * @param r storage for the calculated representative
2697 * @param pub a point on the curve
2698 * @param high_y encodes if y-coordinate is > 2 ^254 - 10, which determines the representative value out of two
2699 * @return 'true' if the given point can be encoded into a representative. Otherwise 'false' is returned and the content of the representative storage is undefined
2700 */
2701bool
2702GNUNET_CRYPTO_ecdhe_elligator_encoding (
2703 struct GNUNET_CRYPTO_ElligatorRepresentative *r,
2704 const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
2705 bool high_y);
2706
2707
2708/**
2709 * @ingroup crypto
2710 * Generates a valid public key for elligator's inverse map by adding a lower order point to a prime order point.
2711 * Following Method 1 in description https://elligator.org/key-exchange section Step 2: Generate a “special” public key.
2712 *
2713 * @param pub valid public key for elligator inverse map
2714 * @param pk private key for generating valid public key
2715 * @return GNUNET_OK on success
2716 */
2717enum GNUNET_GenericReturnValue
2718GNUNET_CRYPTO_ecdhe_elligator_generate_public_key (
2719 struct GNUNET_CRYPTO_EcdhePublicKey *pub,
2720 struct GNUNET_CRYPTO_EcdhePrivateKey *pk);
2721
2722
2723/**
2724 * @ingroup crypto
2725 * Generates a private key for Curve25519 and the elligator representative of the corresponding public key.
2726 *
2727 * @param repr representative of the public key
2728 * @param pk Curve25519 private key
2729 */
2730void
2731GNUNET_CRYPTO_ecdhe_elligator_key_create (
2732 struct GNUNET_CRYPTO_ElligatorRepresentative *repr,
2733 struct GNUNET_CRYPTO_EcdhePrivateKey *pk);
2734
2735/**
2736 * @ingroup crypto
2737 * Carries out ecdh encapsulation with given public key and the private key from a freshly created ephemeral key pair.
2738 * Following the terminology in https://eprint.iacr.org/2021/509.pdf.
2739 *
2740 * @param pub given edwards curve public key (X)
2741 * @param r representative of ephemeral public key A to use for the ECDH (direct_map(r)=A=aG)
2742 * @param key_material where to write the key material H(aX)=H(x(aG))
2743 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2744 */
2745enum GNUNET_GenericReturnValue
2746GNUNET_CRYPTO_eddsa_elligator_kem_encaps (
2747 const struct GNUNET_CRYPTO_EddsaPublicKey *pub,
2748 struct GNUNET_CRYPTO_ElligatorRepresentative *r,
2749 struct GNUNET_HashCode *key_material);
2750
2751/**
2752 * @ingroup crypto
2753 * Carries out ecdh decapsulation with own private key and the representative of the received public key.
2754 * Following the terminology in https://eprint.iacr.org/2021/509.pdf.
2755 *
2756 * @param priv own private key (x)
2757 * @param r received representative r, from which we can obtain the public key A (direct_map(r)=A=aG)
2758 * @param key_material where to write the key material H(xA)=H(a(xG))
2759 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
2760 */
2761enum GNUNET_GenericReturnValue
2762GNUNET_CRYPTO_eddsa_elligator_kem_decaps (
2763 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
2764 const struct GNUNET_CRYPTO_ElligatorRepresentative *r,
2765 struct GNUNET_HashCode *key_material);
2766
1999 2767
2000/** 2768/**
2001 * Output the given MPI value to the given buffer in network 2769 * Output the given MPI value to the given buffer in network
@@ -2063,7 +2831,7 @@ GNUNET_CRYPTO_paillier_encrypt (
2063 * @param private_key Private key to use for decryption. 2831 * @param private_key Private key to use for decryption.
2064 * @param public_key Public key to use for decryption. 2832 * @param public_key Public key to use for decryption.
2065 * @param ciphertext Ciphertext to decrypt. 2833 * @param ciphertext Ciphertext to decrypt.
2066 * @param[out] m Decryption of @a ciphertext with @private_key. 2834 * @param[out] m Decryption of @a ciphertext with @a private_key.
2067 */ 2835 */
2068void 2836void
2069GNUNET_CRYPTO_paillier_decrypt ( 2837GNUNET_CRYPTO_paillier_decrypt (
@@ -2074,7 +2842,8 @@ GNUNET_CRYPTO_paillier_decrypt (
2074 2842
2075 2843
2076/** 2844/**
2077 * Compute a ciphertext that represents the sum of the plaintext in @a x1 and @a x2 2845 * Compute a ciphertext that represents the sum of the plaintext in @a c1
2846 * and @a c2
2078 * 2847 *
2079 * Note that this operation can only be done a finite number of times 2848 * Note that this operation can only be done a finite number of times
2080 * before an overflow occurs. 2849 * before an overflow occurs.
@@ -2211,8 +2980,9 @@ GNUNET_CRYPTO_rsa_private_key_get_public (
2211 * @param hc where to store the hash code 2980 * @param hc where to store the hash code
2212 */ 2981 */
2213void 2982void
2214GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key, 2983GNUNET_CRYPTO_rsa_public_key_hash (
2215 struct GNUNET_HashCode *hc); 2984 const struct GNUNET_CRYPTO_RsaPublicKey *key,
2985 struct GNUNET_HashCode *hc);
2216 2986
2217 2987
2218/** 2988/**
@@ -2317,53 +3087,83 @@ GNUNET_CRYPTO_rsa_public_key_cmp (const struct GNUNET_CRYPTO_RsaPublicKey *p1,
2317 3087
2318 3088
2319/** 3089/**
3090 * @brief RSA Parameters to create blinded signature
3091 */
3092struct GNUNET_CRYPTO_RsaBlindedMessage
3093{
3094 /**
3095 * Blinded message to be signed
3096 * Note: is malloc()'ed!
3097 */
3098 void *blinded_msg;
3099
3100 /**
3101 * Size of the @e blinded_msg to be signed.
3102 */
3103 size_t blinded_msg_size;
3104};
3105
3106
3107/**
2320 * Blinds the given message with the given blinding key 3108 * Blinds the given message with the given blinding key
2321 * 3109 *
2322 * @param hash hash of the message to sign 3110 * @param message the message to sign
2323 * @param bkey the blinding key 3111 * @param message_size number of bytes in @a message
3112 * @param bks the blinding key
2324 * @param pkey the public key of the signer 3113 * @param pkey the public key of the signer
2325 * @param[out] buf set to a buffer with the blinded message to be signed 3114 * @param[out] bm set to the blinded message
2326 * @param[out] buf_size number of bytes stored in @a buf
2327 * @return #GNUNET_YES if successful, #GNUNET_NO if RSA key is malicious 3115 * @return #GNUNET_YES if successful, #GNUNET_NO if RSA key is malicious
2328 */ 3116 */
2329int 3117enum GNUNET_GenericReturnValue
2330GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, 3118GNUNET_CRYPTO_rsa_blind (const void *message,
3119 size_t message_size,
2331 const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, 3120 const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks,
2332 struct GNUNET_CRYPTO_RsaPublicKey *pkey, 3121 struct GNUNET_CRYPTO_RsaPublicKey *pkey,
2333 void **buf, 3122 struct GNUNET_CRYPTO_RsaBlindedMessage *bm);
2334 size_t *buf_size);
2335 3123
2336 3124
2337/** 3125/**
2338 * Sign a blinded value, which must be a full domain hash of a message. 3126 * Sign a blinded value, which must be a full domain hash of a message.
2339 * 3127 *
2340 * @param key private key to use for the signing 3128 * @param key private key to use for the signing
2341 * @param msg the (blinded) message to sign 3129 * @param bm the (blinded) message to sign
2342 * @param msg_len number of bytes in @a msg to sign
2343 * @return NULL on error, signature on success 3130 * @return NULL on error, signature on success
2344 */ 3131 */
2345struct GNUNET_CRYPTO_RsaSignature * 3132struct GNUNET_CRYPTO_RsaSignature *
2346GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key, 3133GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
2347 const void *msg, 3134 const struct
2348 size_t msg_len); 3135 GNUNET_CRYPTO_RsaBlindedMessage *bm);
2349 3136
2350 3137
2351/** 3138/**
2352 * Create and sign a full domain hash of a message. 3139 * Create and sign a full domain hash of a message.
2353 * 3140 *
2354 * @param key private key to use for the signing 3141 * @param key private key to use for the signing
2355 * @param hash the hash of the message to sign 3142 * @param message the message to sign
3143 * @param message_size number of bytes in @a message
2356 * @return NULL on error, including a malicious RSA key, signature on success 3144 * @return NULL on error, including a malicious RSA key, signature on success
2357 */ 3145 */
2358struct GNUNET_CRYPTO_RsaSignature * 3146struct GNUNET_CRYPTO_RsaSignature *
2359GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key, 3147GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
2360 const struct GNUNET_HashCode *hash); 3148 const void *message,
3149 size_t message_size);
3150
3151
3152/**
3153 * Free memory occupied by blinded message. Only frees contents, not
3154 * @a bm itself.
3155 *
3156 * @param[in] bm memory to free
3157 */
3158void
3159GNUNET_CRYPTO_rsa_blinded_message_free (
3160 struct GNUNET_CRYPTO_RsaBlindedMessage *bm);
2361 3161
2362 3162
2363/** 3163/**
2364 * Free memory occupied by signature. 3164 * Free memory occupied by signature.
2365 * 3165 *
2366 * @param sig memory to free 3166 * @param[in] sig memory to free
2367 */ 3167 */
2368void 3168void
2369GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig); 3169GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig);
@@ -2391,8 +3191,9 @@ GNUNET_CRYPTO_rsa_signature_encode (
2391 * @return NULL on error 3191 * @return NULL on error
2392 */ 3192 */
2393struct GNUNET_CRYPTO_RsaSignature * 3193struct GNUNET_CRYPTO_RsaSignature *
2394GNUNET_CRYPTO_rsa_signature_decode (const void *buf, 3194GNUNET_CRYPTO_rsa_signature_decode (
2395 size_t buf_size); 3195 const void *buf,
3196 size_t buf_size);
2396 3197
2397 3198
2398/** 3199/**
@@ -2402,7 +3203,8 @@ GNUNET_CRYPTO_rsa_signature_decode (const void *buf,
2402 * @return the duplicate key; NULL upon error 3203 * @return the duplicate key; NULL upon error
2403 */ 3204 */
2404struct GNUNET_CRYPTO_RsaSignature * 3205struct GNUNET_CRYPTO_RsaSignature *
2405GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_RsaSignature *sig); 3206GNUNET_CRYPTO_rsa_signature_dup (
3207 const struct GNUNET_CRYPTO_RsaSignature *sig);
2406 3208
2407 3209
2408/** 3210/**
@@ -2425,17 +3227,1267 @@ GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig,
2425 * Verify whether the given hash corresponds to the given signature and the 3227 * Verify whether the given hash corresponds to the given signature and the
2426 * signature is valid with respect to the given public key. 3228 * signature is valid with respect to the given public key.
2427 * 3229 *
2428 * @param hash the message to verify to match the @a sig 3230 * @param message the message to sign
3231 * @param message_size number of bytes in @a message
2429 * @param sig signature that is being validated 3232 * @param sig signature that is being validated
2430 * @param public_key public key of the signer 3233 * @param public_key public key of the signer
2431 * @returns #GNUNET_YES if ok, #GNUNET_NO if RSA key is malicious, #GNUNET_SYSERR if signature 3234 * @returns #GNUNET_YES if ok, #GNUNET_NO if RSA key is malicious, #GNUNET_SYSERR if signature
2432 */ 3235 */
2433enum GNUNET_GenericReturnValue 3236enum GNUNET_GenericReturnValue
2434GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, 3237GNUNET_CRYPTO_rsa_verify (const void *message,
3238 size_t message_size,
2435 const struct GNUNET_CRYPTO_RsaSignature *sig, 3239 const struct GNUNET_CRYPTO_RsaSignature *sig,
2436 const struct GNUNET_CRYPTO_RsaPublicKey *public_key); 3240 const struct GNUNET_CRYPTO_RsaPublicKey *public_key);
2437 3241
2438 3242
3243/**
3244 * Create a new random private key.
3245 *
3246 * @param[out] priv where to write the fresh private key
3247 */
3248void
3249GNUNET_CRYPTO_cs_private_key_generate (struct GNUNET_CRYPTO_CsPrivateKey *priv);
3250
3251
3252/**
3253 * Extract the public key of the given private key.
3254 *
3255 * @param priv the private key
3256 * @param[out] pub where to write the public key
3257 */
3258void
3259GNUNET_CRYPTO_cs_private_key_get_public (
3260 const struct GNUNET_CRYPTO_CsPrivateKey *priv,
3261 struct GNUNET_CRYPTO_CsPublicKey *pub);
3262
3263
3264/**
3265 * Derive a new secret r pair r0 and r1.
3266 * In original papers r is generated randomly
3267 * To provide abort-idempotency, r needs to be derived but still needs to be UNPREDICTABLE
3268 * To ensure unpredictability a new nonce should be used when a new r needs to be derived.
3269 * Uses HKDF internally.
3270 * Comment: Can be done in one HKDF shot and split output.
3271 *
3272 * @param nonce is a random nonce
3273 * @param seed seed to use in derivation
3274 * @param lts is a long-term-secret in form of a private key
3275 * @param[out] r array containing derived secrets r0 and r1
3276 */
3277void
3278GNUNET_CRYPTO_cs_r_derive (
3279 const struct GNUNET_CRYPTO_CsSessionNonce *nonce,
3280 const char *seed,
3281 const struct GNUNET_CRYPTO_CsPrivateKey *lts,
3282 struct GNUNET_CRYPTO_CsRSecret r[2]);
3283
3284
3285/**
3286 * Extract the public R of the given secret r.
3287 *
3288 * @param r_priv the private key
3289 * @param[out] r_pub where to write the public key
3290 */
3291void
3292GNUNET_CRYPTO_cs_r_get_public (
3293 const struct GNUNET_CRYPTO_CsRSecret *r_priv,
3294 struct GNUNET_CRYPTO_CsRPublic *r_pub);
3295
3296
3297/**
3298 * Derives new random blinding factors.
3299 * In original papers blinding factors are generated randomly
3300 * To provide abort-idempotency, blinding factors need to be derived but still need to be UNPREDICTABLE.
3301 * To ensure unpredictability a new nonce has to be used.
3302 * Uses HKDF internally.
3303 *
3304 * @param blind_seed is the blinding seed to derive blinding factors
3305 * @param[out] bs array containing the two derived blinding secrets
3306 */
3307void
3308GNUNET_CRYPTO_cs_blinding_secrets_derive (
3309 const struct GNUNET_CRYPTO_CsBlindingNonce *blind_seed,
3310 struct GNUNET_CRYPTO_CsBlindingSecret bs[2]);
3311
3312
3313/**
3314 * @brief CS Parameters derived from the message
3315 * during blinding to create blinded signature
3316 */
3317struct GNUNET_CRYPTO_CsBlindedMessage
3318{
3319 /**
3320 * The Clause Schnorr c_0 and c_1 containing the blinded message
3321 */
3322 struct GNUNET_CRYPTO_CsC c[2];
3323
3324 /**
3325 * Nonce used in initial request.
3326 */
3327 struct GNUNET_CRYPTO_CsSessionNonce nonce;
3328
3329};
3330
3331
3332/**
3333 * Pair of Public R values for Cs denominations
3334 */
3335struct GNUNET_CRYPTO_CSPublicRPairP
3336{
3337 struct GNUNET_CRYPTO_CsRPublic r_pub[2];
3338};
3339
3340
3341/**
3342 * Calculate two blinded c's.
3343 * Comment: One would be insecure due to Wagner's algorithm solving ROS
3344 *
3345 * @param bs array of the two blinding factor structs each containing alpha and beta
3346 * @param r_pub array of the two signer's nonce R
3347 * @param pub the public key of the signer
3348 * @param msg the message to blind in preparation for signing
3349 * @param msg_len length of message msg
3350 * @param[out] blinded_c array of the two blinded c's
3351 * @param[out] r_pub_blind array of the two blinded R
3352 */
3353void
3354GNUNET_CRYPTO_cs_calc_blinded_c (
3355 const struct GNUNET_CRYPTO_CsBlindingSecret bs[2],
3356 const struct GNUNET_CRYPTO_CsRPublic r_pub[2],
3357 const struct GNUNET_CRYPTO_CsPublicKey *pub,
3358 const void *msg,
3359 size_t msg_len,
3360 struct GNUNET_CRYPTO_CsC blinded_c[2],
3361 struct GNUNET_CRYPTO_CSPublicRPairP *r_pub_blind);
3362
3363
3364/**
3365 * The Sign Answer for Clause Blind Schnorr signature.
3366 * The sign operation returns a parameter @param b and the signature
3367 * scalar @param s_scalar.
3368 */
3369struct GNUNET_CRYPTO_CsBlindSignature
3370{
3371 /**
3372 * To make ROS problem harder, the signer chooses an unpredictable b and
3373 * only calculates signature of c_b
3374 */
3375 unsigned int b;
3376
3377 /**
3378 * The blinded s scalar calculated from c_b
3379 */
3380 struct GNUNET_CRYPTO_CsBlindS s_scalar;
3381};
3382
3383
3384/**
3385 * Sign a blinded @a c.
3386 * This function derives b from a nonce and a longterm secret.
3387 * In the original papers b is generated randomly.
3388 * To provide abort-idempotency, b needs to be derived but still need to be UNPREDICTABLE.
3389 * To ensure unpredictability a new nonce has to be used for every signature.
3390 * HKDF is used internally for derivation.
3391 * r0 and r1 can be derived prior by using GNUNET_CRYPTO_cs_r_derive.
3392 *
3393 * @param priv private key to use for the signing and as LTS in HKDF
3394 * @param r array of the two secret inputs from the signer
3395 * @param bm blinded message, including array of the two blinded c to sign c_b and the random nonce
3396 * @param[out] cs_blind_sig where to write the blind signature
3397 */
3398void
3399GNUNET_CRYPTO_cs_sign_derive (
3400 const struct GNUNET_CRYPTO_CsPrivateKey *priv,
3401 const struct GNUNET_CRYPTO_CsRSecret r[2],
3402 const struct GNUNET_CRYPTO_CsBlindedMessage *bm,
3403 struct GNUNET_CRYPTO_CsBlindSignature *cs_blind_sig);
3404
3405
3406/**
3407 * Unblind a blind-signed signature using a c that was blinded
3408 *
3409 * @param blinded_signature_scalar the signature made on the blinded c
3410 * @param bs the blinding factors used in the blinding
3411 * @param[out] signature_scalar where to write the unblinded signature
3412 */
3413void
3414GNUNET_CRYPTO_cs_unblind (
3415 const struct GNUNET_CRYPTO_CsBlindS *blinded_signature_scalar,
3416 const struct GNUNET_CRYPTO_CsBlindingSecret *bs,
3417 struct GNUNET_CRYPTO_CsS *signature_scalar);
3418
3419
3420/**
3421 * Verify whether the given message corresponds to the given signature and the
3422 * signature is valid with respect to the given public key.
3423 *
3424 * @param sig signature that is being validated
3425 * @param pub public key of the signer
3426 * @param msg is the message that should be signed by @a sig (message is used to calculate c)
3427 * @param msg_len is the message length
3428 * @returns #GNUNET_YES on success, #GNUNET_SYSERR if signature invalid
3429 */
3430enum GNUNET_GenericReturnValue
3431GNUNET_CRYPTO_cs_verify (
3432 const struct GNUNET_CRYPTO_CsSignature *sig,
3433 const struct GNUNET_CRYPTO_CsPublicKey *pub,
3434 const void *msg,
3435 size_t msg_len);
3436
3437
3438/**
3439 * Types of public keys used for blind signatures.
3440 */
3441enum GNUNET_CRYPTO_BlindSignatureAlgorithm
3442{
3443
3444 /**
3445 * Invalid type of signature.
3446 */
3447 GNUNET_CRYPTO_BSA_INVALID = 0,
3448
3449 /**
3450 * RSA blind signature.
3451 */
3452 GNUNET_CRYPTO_BSA_RSA = 1,
3453
3454 /**
3455 * Clause Blind Schnorr signature.
3456 */
3457 GNUNET_CRYPTO_BSA_CS = 2
3458};
3459
3460
3461/**
3462 * @brief Type of (unblinded) signatures.
3463 */
3464struct GNUNET_CRYPTO_UnblindedSignature
3465{
3466
3467 /**
3468 * Type of the signature.
3469 */
3470 enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher;
3471
3472 /**
3473 * Reference counter.
3474 */
3475 unsigned int rc;
3476
3477 /**
3478 * Details, depending on @e cipher.
3479 */
3480 union
3481 {
3482 /**
3483 * If we use #GNUNET_CRYPTO_BSA_CS in @a cipher.
3484 */
3485 struct GNUNET_CRYPTO_CsSignature cs_signature;
3486
3487 /**
3488 * If we use #GNUNET_CRYPTO_BSA_RSA in @a cipher.
3489 */
3490 struct GNUNET_CRYPTO_RsaSignature *rsa_signature;
3491
3492 } details;
3493
3494};
3495
3496
3497/**
3498 * @brief Type for *blinded* signatures.
3499 * Must be unblinded before it becomes valid.
3500 */
3501struct GNUNET_CRYPTO_BlindedSignature
3502{
3503
3504 /**
3505 * Type of the signature.
3506 */
3507 enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher;
3508
3509 /**
3510 * Reference counter.
3511 */
3512 unsigned int rc;
3513
3514 /**
3515 * Details, depending on @e cipher.
3516 */
3517 union
3518 {
3519 /**
3520 * If we use #GNUNET_CRYPTO_BSA_CS in @a cipher.
3521 * At this point only the blinded s scalar is used.
3522 * The final signature consisting of r,s is built after unblinding.
3523 */
3524 struct GNUNET_CRYPTO_CsBlindSignature blinded_cs_answer;
3525
3526 /**
3527 * If we use #GNUNET_CRYPTO_BSA_RSA in @a cipher.
3528 */
3529 struct GNUNET_CRYPTO_RsaSignature *blinded_rsa_signature;
3530
3531 } details;
3532
3533};
3534
3535
3536/**
3537 * @brief Type of public signing keys for blind signatures.
3538 */
3539struct GNUNET_CRYPTO_BlindSignPublicKey
3540{
3541
3542 /**
3543 * Type of the public key.
3544 */
3545 enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher;
3546
3547 /**
3548 * Reference counter.
3549 */
3550 unsigned int rc;
3551
3552 /**
3553 * Hash of the public key.
3554 */
3555 struct GNUNET_HashCode pub_key_hash;
3556
3557 /**
3558 * Details, depending on @e cipher.
3559 */
3560 union
3561 {
3562 /**
3563 * If we use #GNUNET_CRYPTO_BSA_CS in @a cipher.
3564 */
3565 struct GNUNET_CRYPTO_CsPublicKey cs_public_key;
3566
3567 /**
3568 * If we use #GNUNET_CRYPTO_BSA_RSA in @a cipher.
3569 */
3570 struct GNUNET_CRYPTO_RsaPublicKey *rsa_public_key;
3571
3572 } details;
3573};
3574
3575
3576/**
3577 * @brief Type of private signing keys for blind signing.
3578 */
3579struct GNUNET_CRYPTO_BlindSignPrivateKey
3580{
3581
3582 /**
3583 * Type of the public key.
3584 */
3585 enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher;
3586
3587 /**
3588 * Reference counter.
3589 */
3590 unsigned int rc;
3591
3592 /**
3593 * Details, depending on @e cipher.
3594 */
3595 union
3596 {
3597 /**
3598 * If we use #GNUNET_CRYPTO_BSA_CS in @a cipher.
3599 */
3600 struct GNUNET_CRYPTO_CsPrivateKey cs_private_key;
3601
3602 /**
3603 * If we use #GNUNET_CRYPTO_BSA_RSA in @a cipher.
3604 */
3605 struct GNUNET_CRYPTO_RsaPrivateKey *rsa_private_key;
3606
3607 } details;
3608};
3609
3610
3611/**
3612 * @brief Blinded message ready for blind signing.
3613 */
3614struct GNUNET_CRYPTO_BlindedMessage
3615{
3616 /**
3617 * Type of the sign blinded message
3618 */
3619 enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher;
3620
3621 /**
3622 * Reference counter.
3623 */
3624 unsigned int rc;
3625
3626 /**
3627 * Details, depending on @e cipher.
3628 */
3629 union
3630 {
3631 /**
3632 * If we use #GNUNET_CRYPTO_BSA_CS in @a cipher.
3633 */
3634 struct GNUNET_CRYPTO_CsBlindedMessage cs_blinded_message;
3635
3636 /**
3637 * If we use #GNUNET_CRYPTO_BSA_RSA in @a cipher.
3638 */
3639 struct GNUNET_CRYPTO_RsaBlindedMessage rsa_blinded_message;
3640
3641 } details;
3642};
3643
3644
3645/**
3646 * Secret r for Cs denominations
3647 */
3648struct GNUNET_CRYPTO_CSPrivateRPairP
3649{
3650 struct GNUNET_CRYPTO_CsRSecret r[2];
3651};
3652
3653
3654/**
3655 * @brief Input needed for blinding a message.
3656 */
3657struct GNUNET_CRYPTO_BlindingInputValues
3658{
3659
3660 /**
3661 * Type of the signature.
3662 */
3663 enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher;
3664
3665 /**
3666 * Reference counter.
3667 */
3668 unsigned int rc;
3669
3670 /**
3671 * Details, depending on @e cipher.
3672 */
3673 union
3674 {
3675 /**
3676 * If we use #GNUNET_CRYPTO_BSA_CS in @a cipher.
3677 */
3678 struct GNUNET_CRYPTO_CSPublicRPairP cs_values;
3679
3680 } details;
3681
3682};
3683
3684
3685/**
3686 * Nonce used to deterministiacally derive input values
3687 * used in multi-round blind signature protocols.
3688 */
3689union GNUNET_CRYPTO_BlindSessionNonce
3690{
3691 /**
3692 * Nonce used when signing with CS.
3693 */
3694 struct GNUNET_CRYPTO_CsSessionNonce cs_nonce;
3695};
3696
3697
3698/**
3699 * Compute blinding input values for a given @a nonce and
3700 * @a salt.
3701 *
3702 * @param bsign_priv private key to compute input values for
3703 * @param nonce session nonce to derive input values from
3704 * @param salt salt to include in derivation logic
3705 * @return blinding input values
3706 */
3707struct GNUNET_CRYPTO_BlindingInputValues *
3708GNUNET_CRYPTO_get_blinding_input_values (
3709 const struct GNUNET_CRYPTO_BlindSignPrivateKey *bsign_priv,
3710 const union GNUNET_CRYPTO_BlindSessionNonce *nonce,
3711 const char *salt);
3712
3713
3714/**
3715 * Decrement reference counter of a @a bsign_pub, and free it if it reaches zero.
3716 *
3717 * @param[in] bsign_pub key to free
3718 */
3719void
3720GNUNET_CRYPTO_blind_sign_pub_decref (
3721 struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub);
3722
3723
3724/**
3725 * Decrement reference counter of a @a bsign_priv, and free it if it reaches zero.
3726 *
3727 * @param[in] bsign_priv key to free
3728 */
3729void
3730GNUNET_CRYPTO_blind_sign_priv_decref (
3731 struct GNUNET_CRYPTO_BlindSignPrivateKey *bsign_priv);
3732
3733
3734/**
3735 * Decrement reference counter of a @a ub_sig, and free it if it reaches zero.
3736 *
3737 * @param[in] ub_sig signature to free
3738 */
3739void
3740GNUNET_CRYPTO_unblinded_sig_decref (
3741 struct GNUNET_CRYPTO_UnblindedSignature *ub_sig);
3742
3743
3744/**
3745 * Decrement reference counter of a @a blind_sig, and free it if it reaches zero.
3746 *
3747 * @param[in] blind_sig signature to free
3748 */
3749void
3750GNUNET_CRYPTO_blinded_sig_decref (
3751 struct GNUNET_CRYPTO_BlindedSignature *blind_sig);
3752
3753
3754/**
3755 * Decrement reference counter of a @a bm, and free it if it reaches zero.
3756 *
3757 * @param[in] bm blinded message to free
3758 */
3759void
3760GNUNET_CRYPTO_blinded_message_decref (
3761 struct GNUNET_CRYPTO_BlindedMessage *bm);
3762
3763
3764/**
3765 * Increment reference counter of the given @a bm.
3766 *
3767 * @param[in,out] bm blinded message to increment reference counter for
3768 * @return alias of @a bm with RC incremented
3769 */
3770struct GNUNET_CRYPTO_BlindedMessage *
3771GNUNET_CRYPTO_blinded_message_incref (
3772 struct GNUNET_CRYPTO_BlindedMessage *bm);
3773
3774
3775/**
3776 * Increment reference counter of the given @a bi.
3777 *
3778 * @param[in,out] bi blinding input values to increment reference counter for
3779 * @return alias of @a bi with RC incremented
3780 */
3781struct GNUNET_CRYPTO_BlindingInputValues *
3782GNUNET_CRYPTO_blinding_input_values_incref (
3783 struct GNUNET_CRYPTO_BlindingInputValues *bm);
3784
3785
3786/**
3787 * Decrement reference counter of the given @a bi, and free it if it reaches
3788 * zero.
3789 *
3790 * @param[in,out] bi blinding input values to decrement reference counter for
3791 */
3792void
3793GNUNET_CRYPTO_blinding_input_values_decref (
3794 struct GNUNET_CRYPTO_BlindingInputValues *bm);
3795
3796
3797/**
3798 * Increment reference counter of the given @a bsign_pub.
3799 *
3800 * @param[in,out] bsign_pub public key to increment reference counter for
3801 * @return alias of @a bsign_pub with RC incremented
3802 */
3803struct GNUNET_CRYPTO_BlindSignPublicKey *
3804GNUNET_CRYPTO_bsign_pub_incref (
3805 struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub);
3806
3807
3808/**
3809 * Increment reference counter of the given @a bsign_priv.
3810 *
3811 * @param[in,out] bsign_priv private key to increment reference counter for
3812 * @return alias of @a bsign_priv with RC incremented
3813 */
3814struct GNUNET_CRYPTO_BlindSignPrivateKey *
3815GNUNET_CRYPTO_bsign_priv_incref (
3816 struct GNUNET_CRYPTO_BlindSignPrivateKey *bsign_priv);
3817
3818
3819/**
3820 * Increment reference counter of the given @a ub_sig.
3821 *
3822 * @param[in,out] ub_sig signature to increment reference counter for
3823 * @return alias of @a ub_sig with RC incremented
3824 */
3825struct GNUNET_CRYPTO_UnblindedSignature *
3826GNUNET_CRYPTO_ub_sig_incref (struct GNUNET_CRYPTO_UnblindedSignature *ub_sig);
3827
3828
3829/**
3830 * Increment reference counter of the given @a blind_sig.
3831 *
3832 * @param[in,out] blind_sig signature to increment reference counter for
3833 * @return alias of @a blind_sig with RC incremented
3834 */
3835struct GNUNET_CRYPTO_BlindedSignature *
3836GNUNET_CRYPTO_blind_sig_incref (
3837 struct GNUNET_CRYPTO_BlindedSignature *blind_sig);
3838
3839
3840/**
3841 * Compare two denomination public keys.
3842 *
3843 * @param bp1 first key
3844 * @param bp2 second key
3845 * @return 0 if the keys are equal, otherwise -1 or 1
3846 */
3847int
3848GNUNET_CRYPTO_bsign_pub_cmp (
3849 const struct GNUNET_CRYPTO_BlindSignPublicKey *bp1,
3850 const struct GNUNET_CRYPTO_BlindSignPublicKey *bp2);
3851
3852
3853/**
3854 * Compare two denomination signatures.
3855 *
3856 * @param sig1 first signature
3857 * @param sig2 second signature
3858 * @return 0 if the keys are equal, otherwise -1 or 1
3859 */
3860int
3861GNUNET_CRYPTO_ub_sig_cmp (const struct GNUNET_CRYPTO_UnblindedSignature *sig1,
3862 const struct GNUNET_CRYPTO_UnblindedSignature *sig2);
3863
3864
3865/**
3866 * Compare two blinded denomination signatures.
3867 *
3868 * @param sig1 first signature
3869 * @param sig2 second signature
3870 * @return 0 if the keys are equal, otherwise -1 or 1
3871 */
3872int
3873GNUNET_CRYPTO_blind_sig_cmp (
3874 const struct GNUNET_CRYPTO_BlindedSignature *sig1,
3875 const struct GNUNET_CRYPTO_BlindedSignature *sig2);
3876
3877
3878/**
3879 * Compare two blinded messages.
3880 *
3881 * @param bp1 first blinded message
3882 * @param bp2 second blinded message
3883 * @return 0 if the keys are equal, otherwise -1 or 1
3884 */
3885int
3886GNUNET_CRYPTO_blinded_message_cmp (
3887 const struct GNUNET_CRYPTO_BlindedMessage *bp1,
3888 const struct GNUNET_CRYPTO_BlindedMessage *bp2);
3889
3890
3891/**
3892 * Initialize public-private key pair for blind signatures.
3893 *
3894 * For #GNUNET_CRYPTO_BSA_RSA, an additional "unsigned int"
3895 * argument with the number of bits for 'n' (e.g. 2048) must
3896 * be passed.
3897 *
3898 * @param[out] bsign_priv where to write the private key with RC 1
3899 * @param[out] bsign_pub where to write the public key with RC 1
3900 * @param cipher which type of cipher to use
3901 * @param ... RSA key size (eg. 2048/3072/4096)
3902 * @return #GNUNET_OK on success, #GNUNET_NO if parameterst were invalid
3903 */
3904enum GNUNET_GenericReturnValue
3905GNUNET_CRYPTO_blind_sign_keys_create (
3906 struct GNUNET_CRYPTO_BlindSignPrivateKey **bsign_priv,
3907 struct GNUNET_CRYPTO_BlindSignPublicKey **bsign_pub,
3908 enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher,
3909 ...);
3910
3911
3912/**
3913 * Initialize public-private key pair for blind signatures.
3914 *
3915 * For #GNUNET_CRYPTO_BSA_RSA, an additional "unsigned int"
3916 * argument with the number of bits for 'n' (e.g. 2048) must
3917 * be passed.
3918 *
3919 * @param[out] bsign_priv where to write the private key with RC 1
3920 * @param[out] bsign_pub where to write the public key with RC 1
3921 * @param cipher which type of cipher to use
3922 * @param ap RSA key size (eg. 2048/3072/4096)
3923 * @return #GNUNET_OK on success, #GNUNET_NO if parameterst were invalid
3924 */
3925enum GNUNET_GenericReturnValue
3926GNUNET_CRYPTO_blind_sign_keys_create_va (
3927 struct GNUNET_CRYPTO_BlindSignPrivateKey **bsign_priv,
3928 struct GNUNET_CRYPTO_BlindSignPublicKey **bsign_pub,
3929 enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher,
3930 va_list ap);
3931
3932
3933/**
3934 * @brief Type of blinding secrets. Must be exactly 32 bytes (DB).
3935 */
3936union GNUNET_CRYPTO_BlindingSecretP
3937{
3938 /**
3939 * Clause Schnorr nonce.
3940 */
3941 struct GNUNET_CRYPTO_CsBlindingNonce nonce;
3942
3943 /**
3944 * Variant for RSA for blind signatures.
3945 */
3946 struct GNUNET_CRYPTO_RsaBlindingKeySecret rsa_bks;
3947};
3948
3949
3950/**
3951 * Blind message for blind signing with @a dk using blinding secret @a coin_bks.
3952 *
3953 * @param bsign_pub public key to blind for
3954 * @param bks blinding secret to use
3955 * @param nonce nonce used to obtain @a alg_values
3956 * can be NULL if input values are not used for the cipher
3957 * @param message message to sign
3958 * @param message_size number of bytes in @a message
3959 * @param alg_values algorithm specific values to blind the @a message
3960 * @return blinded message to give to signer, NULL on error
3961 */
3962struct GNUNET_CRYPTO_BlindedMessage *
3963GNUNET_CRYPTO_message_blind_to_sign (
3964 const struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub,
3965 const union GNUNET_CRYPTO_BlindingSecretP *bks,
3966 const union GNUNET_CRYPTO_BlindSessionNonce *nonce,
3967 const void *message,
3968 size_t message_size,
3969 const struct GNUNET_CRYPTO_BlindingInputValues *alg_values);
3970
3971
3972/**
3973 * Create blind signature.
3974 *
3975 * @param bsign_priv private key to use for signing
3976 * @param salt salt value to use for the HKDF,
3977 * can be NULL if input values are not used for the cipher
3978 * @param blinded_message the already blinded message to sign
3979 * @return blind signature with RC=1, NULL on failure
3980 */
3981struct GNUNET_CRYPTO_BlindedSignature *
3982GNUNET_CRYPTO_blind_sign (
3983 const struct GNUNET_CRYPTO_BlindSignPrivateKey *bsign_priv,
3984 const char *salt,
3985 const struct GNUNET_CRYPTO_BlindedMessage *blinded_message);
3986
3987
3988/**
3989 * Unblind blind signature.
3990 *
3991 * @param blinded_sig the blind signature
3992 * @param bks blinding secret to use
3993 * @param message message that was supposedly signed
3994 * @param message_size number of bytes in @a message
3995 * @param alg_values algorithm specific values
3996 * @param bsign_pub public key used for signing
3997 * @return unblinded signature with RC=1, NULL on error
3998 */
3999struct GNUNET_CRYPTO_UnblindedSignature *
4000GNUNET_CRYPTO_blind_sig_unblind (
4001 const struct GNUNET_CRYPTO_BlindedSignature *blinded_sig,
4002 const union GNUNET_CRYPTO_BlindingSecretP *bks,
4003 const void *message,
4004 size_t message_size,
4005 const struct GNUNET_CRYPTO_BlindingInputValues *alg_values,
4006 const struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub);
4007
4008
4009/**
4010 * Verify signature made blindly.
4011 *
4012 * @param bsign_pub public key
4013 * @param ub_sig signature made blindly with the private key
4014 * @param message message that was supposedly signed
4015 * @param message_size number of bytes in @a message
4016 * @return #GNUNET_OK if the signature is valid
4017 */
4018enum GNUNET_GenericReturnValue
4019GNUNET_CRYPTO_blind_sig_verify (
4020 const struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub,
4021 const struct GNUNET_CRYPTO_UnblindedSignature *ub_sig,
4022 const void *message,
4023 size_t message_size);
4024
4025
4026/**
4027 * Get the compacted length of a #GNUNET_CRYPTO_PublicKey.
4028 * Compacted means that it returns the minimum number of bytes this
4029 * key is long, as opposed to the union structure inside
4030 * #GNUNET_CRYPTO_PublicKey.
4031 * Useful for compact serializations.
4032 *
4033 * @param key the key.
4034 * @return -1 on error, else the compacted length of the key.
4035 */
4036ssize_t
4037GNUNET_CRYPTO_public_key_get_length (const struct
4038 GNUNET_CRYPTO_PublicKey *key);
4039
4040/**
4041 * Reads a #GNUNET_CRYPTO_PublicKey from a compact buffer.
4042 * The buffer has to contain at least the compacted length of
4043 * a #GNUNET_CRYPTO_PublicKey in bytes.
4044 * If the buffer is too small, the function returns -1 as error.
4045 * If the buffer does not contain a valid key, it returns -2 as error.
4046 *
4047 * @param buffer the buffer
4048 * @param len the length of buffer
4049 * @param key the key
4050 * @param the amount of bytes read from the buffer
4051 * @return #GNUNET_SYSERR on error
4052 */
4053enum GNUNET_GenericReturnValue
4054GNUNET_CRYPTO_read_public_key_from_buffer (
4055 const void *buffer,
4056 size_t len,
4057 struct GNUNET_CRYPTO_PublicKey *key,
4058 size_t *read);
4059
4060/**
4061 * Get the compacted length of a #GNUNET_CRYPTO_PrivateKey.
4062 * Compacted means that it returns the minimum number of bytes this
4063 * key is long, as opposed to the union structure inside
4064 * #GNUNET_CRYPTO_PrivateKey.
4065 * Useful for compact serializations.
4066 *
4067 * @param key the key.
4068 * @return -1 on error, else the compacted length of the key.
4069 */
4070ssize_t
4071GNUNET_CRYPTO_private_key_get_length (
4072 const struct GNUNET_CRYPTO_PrivateKey *key);
4073
4074
4075/**
4076 * Writes a #GNUNET_CRYPTO_PublicKey to a compact buffer.
4077 * The buffer requires space for at least the compacted length of
4078 * a #GNUNET_CRYPTO_PublicKey in bytes.
4079 * If the buffer is too small, the function returns -1 as error.
4080 * If the key is not valid, it returns -2 as error.
4081 *
4082 * @param key the key
4083 * @param buffer the buffer
4084 * @param len the length of buffer
4085 * @return -1 or -2 on error, else the amount of bytes written to the buffer
4086 */
4087ssize_t
4088GNUNET_CRYPTO_write_public_key_to_buffer (const struct
4089 GNUNET_CRYPTO_PublicKey *key,
4090 void*buffer,
4091 size_t len);
4092
4093
4094/**
4095 * Reads a #GNUNET_CRYPTO_PrivateKey from a compact buffer.
4096 * The buffer has to contain at least the compacted length of
4097 * a #GNUNET_CRYPTO_PrivateKey in bytes.
4098 * If the buffer is too small, the function returns GNUNET_SYSERR as error.
4099 *
4100 * @param buffer the buffer
4101 * @param len the length of buffer
4102 * @param key the key
4103 * @param the amount of bytes read from the buffer
4104 * @return #GNUNET_SYSERR on error
4105 */
4106enum GNUNET_GenericReturnValue
4107GNUNET_CRYPTO_read_private_key_from_buffer (
4108 const void*buffer,
4109 size_t len,
4110 struct GNUNET_CRYPTO_PrivateKey *key,
4111 size_t *read);
4112
4113
4114/**
4115 * Writes a #GNUNET_CRYPTO_PrivateKey to a compact buffer.
4116 * The buffer requires space for at least the compacted length of
4117 * a #GNUNET_CRYPTO_PrivateKey in bytes.
4118 * If the buffer is too small, the function returns -1 as error.
4119 * If the key is not valid, it returns -2 as error.
4120 *
4121 * @param key the key
4122 * @param buffer the buffer
4123 * @param len the length of buffer
4124 * @return -1 or -2 on error, else the amount of bytes written to the buffer
4125 */
4126ssize_t
4127GNUNET_CRYPTO_write_private_key_to_buffer (
4128 const struct GNUNET_CRYPTO_PrivateKey *key,
4129 void*buffer,
4130 size_t len);
4131
4132
4133/**
4134 * Get the compacted length of a #GNUNET_CRYPTO_Signature.
4135 * Compacted means that it returns the minimum number of bytes this
4136 * signature is long, as opposed to the union structure inside
4137 * #GNUNET_CRYPTO_Signature.
4138 * Useful for compact serializations.
4139 *
4140 * @param sig the signature.
4141 * @return -1 on error, else the compacted length of the signature.
4142 */
4143ssize_t
4144GNUNET_CRYPTO_signature_get_length (
4145 const struct GNUNET_CRYPTO_Signature *sig);
4146
4147
4148/**
4149 * Get the compacted length of a signature by type.
4150 * Compacted means that it returns the minimum number of bytes this
4151 * signature is long, as opposed to the union structure inside
4152 * #GNUNET_CRYPTO_Signature.
4153 * Useful for compact serializations.
4154 *
4155 * @param sig the signature.
4156 * @return -1 on error, else the compacted length of the signature.
4157 */
4158ssize_t
4159GNUNET_CRYPTO_signature_get_raw_length_by_type (uint32_t type);
4160
4161
4162/**
4163 * Reads a #GNUNET_CRYPTO_Signature from a compact buffer.
4164 * The buffer has to contain at least the compacted length of
4165 * a #GNUNET_CRYPTO_Signature in bytes.
4166 * If the buffer is too small, the function returns -1 as error.
4167 * If the buffer does not contain a valid key, it returns -2 as error.
4168 *
4169 * @param sig the signature
4170 * @param buffer the buffer
4171 * @param len the length of buffer
4172 * @return -1 or -2 on error, else the amount of bytes read from the buffer
4173 */
4174ssize_t
4175GNUNET_CRYPTO_read_signature_from_buffer (
4176 struct GNUNET_CRYPTO_Signature *sig,
4177 const void*buffer,
4178 size_t len);
4179
4180
4181/**
4182 * Writes a #GNUNET_CRYPTO_Signature to a compact buffer.
4183 * The buffer requires space for at least the compacted length of
4184 * a #GNUNET_CRYPTO_Signature in bytes.
4185 * If the buffer is too small, the function returns -1 as error.
4186 * If the key is not valid, it returns -2 as error.
4187 *
4188 * @param sig the signature
4189 * @param buffer the buffer
4190 * @param len the length of buffer
4191 * @return -1 or -2 on error, else the amount of bytes written to the buffer
4192 */
4193ssize_t
4194GNUNET_CRYPTO_write_signature_to_buffer (
4195 const struct GNUNET_CRYPTO_Signature *sig,
4196 void*buffer,
4197 size_t len);
4198
4199
4200/**
4201 * @brief Sign a given block.
4202 *
4203 * The @a purpose data is the beginning of the data of which the signature is
4204 * to be created. The `size` field in @a purpose must correctly indicate the
4205 * number of bytes of the data structure, including its header. If possible,
4206 * use #GNUNET_CRYPTO_sign() instead of this function.
4207 *
4208 * @param priv private key to use for the signing
4209 * @param purpose what to sign (size, purpose)
4210 * @param[out] sig where to write the signature
4211 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
4212 */
4213enum GNUNET_GenericReturnValue
4214GNUNET_CRYPTO_sign_ (
4215 const struct GNUNET_CRYPTO_PrivateKey *priv,
4216 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
4217 struct GNUNET_CRYPTO_Signature *sig);
4218
4219/**
4220 * @brief Sign a given block.
4221 *
4222 * The @a purpose data is the beginning of the data of which the signature is
4223 * to be created. The `size` field in @a purpose must correctly indicate the
4224 * number of bytes of the data structure, including its header.
4225 * The signature payload and length depends on the key type.
4226 *
4227 * @param priv private key to use for the signing
4228 * @param purpose what to sign (size, purpose)
4229 * @param[out] sig where to write the signature
4230 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
4231 */
4232enum GNUNET_GenericReturnValue
4233GNUNET_CRYPTO_sign_raw_ (
4234 const struct GNUNET_CRYPTO_PrivateKey *priv,
4235 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
4236 unsigned char *sig);
4237
4238
4239/**
4240 * @brief Sign a given block with #GNUNET_CRYPTO_PrivateKey.
4241 *
4242 * The @a ps data must be a fixed-size struct for which the signature is to be
4243 * created. The `size` field in @a ps->purpose must correctly indicate the
4244 * number of bytes of the data structure, including its header.
4245 *
4246 * @param priv private key to use for the signing
4247 * @param ps packed struct with what to sign, MUST begin with a purpose
4248 * @param[out] sig where to write the signature
4249 */
4250#define GNUNET_CRYPTO_sign(priv,ps,sig) do { \
4251 /* check size is set correctly */ \
4252 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
4253 /* check 'ps' begins with the purpose */ \
4254 GNUNET_static_assert (((void*) (ps)) == \
4255 ((void*) &(ps)->purpose)); \
4256 GNUNET_assert (GNUNET_OK == \
4257 GNUNET_CRYPTO_sign_ (priv, \
4258 &(ps)->purpose, \
4259 sig)); \
4260} while (0)
4261
4262
4263/**
4264 * @brief Verify a given signature.
4265 *
4266 * The @a validate data is the beginning of the data of which the signature
4267 * is to be verified. The `size` field in @a validate must correctly indicate
4268 * the number of bytes of the data structure, including its header. If @a
4269 * purpose does not match the purpose given in @a validate (the latter must be
4270 * in big endian), signature verification fails. If possible,
4271 * use #GNUNET_CRYPTO_signature_verify() instead of this function (only if @a validate
4272 * is not fixed-size, you must use this function directly).
4273 *
4274 * @param purpose what is the purpose that the signature should have?
4275 * @param validate block to validate (size, purpose, data)
4276 * @param sig signature that is being validated
4277 * @param pub public key of the signer
4278 * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
4279 */
4280enum GNUNET_GenericReturnValue
4281GNUNET_CRYPTO_signature_verify_ (
4282 uint32_t purpose,
4283 const struct GNUNET_CRYPTO_EccSignaturePurpose *validate,
4284 const struct GNUNET_CRYPTO_Signature *sig,
4285 const struct GNUNET_CRYPTO_PublicKey *pub);
4286
4287/**
4288 * @brief Verify a given signature.
4289 *
4290 * The @a validate data is the beginning of the data of which the signature
4291 * is to be verified. The `size` field in @a validate must correctly indicate
4292 * the number of bytes of the data structure, including its header. If @a
4293 * purpose does not match the purpose given in @a validate (the latter must be
4294 * in big endian), signature verification fails.
4295 *
4296 * @param purpose what is the purpose that the signature should have?
4297 * @param validate block to validate (size, purpose, data)
4298 * @param sig signature that is being validated
4299 * @param pub public key of the signer
4300 * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
4301 */
4302enum GNUNET_GenericReturnValue
4303GNUNET_CRYPTO_signature_verify_raw_ (
4304 uint32_t purpose,
4305 const struct GNUNET_CRYPTO_EccSignaturePurpose *validate,
4306 const unsigned char *sig,
4307 const struct GNUNET_CRYPTO_PublicKey *pub);
4308
4309
4310/**
4311 * @brief Verify a given signature with #GNUNET_CRYPTO_PublicKey.
4312 *
4313 * The @a ps data must be a fixed-size struct for which the signature is to be
4314 * created. The `size` field in @a ps->purpose must correctly indicate the
4315 * number of bytes of the data structure, including its header.
4316 *
4317 * @param purp purpose of the signature, must match 'ps->purpose.purpose'
4318 * (except in host byte order)
4319 * @param ps packed struct with what to sign, MUST begin with a purpose
4320 * @param sig where to read the signature from
4321 * @param pub public key to use for the verifying
4322 */
4323#define GNUNET_CRYPTO_signature_verify(purp,ps,sig,pub) ({ \
4324 /* check size is set correctly */ \
4325 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
4326 /* check 'ps' begins with the purpose */ \
4327 GNUNET_static_assert (((void*) (ps)) == \
4328 ((void*) &(ps)->purpose)); \
4329 GNUNET_CRYPTO_signature_verify_ (purp, \
4330 &(ps)->purpose, \
4331 sig, \
4332 pub); \
4333 })
4334
4335
4336/**
4337 * Encrypt a block with #GNUNET_CRYPTO_PublicKey and derives a
4338 * #GNUNET_CRYPTO_EcdhePublicKey which is required for decryption
4339 * using ecdh to derive a symmetric key.
4340 *
4341 * @param block the block to encrypt
4342 * @param size the size of the @a block
4343 * @param pub public key to use for ecdh
4344 * @param ecc where to write the ecc public key
4345 * @param result the output parameter in which to store the encrypted result
4346 * can be the same or overlap with @c block
4347 * @returns the size of the encrypted block, -1 for errors.
4348 * Due to the use of CFB and therefore an effective stream cipher,
4349 * this size should be the same as @c len.
4350 */
4351ssize_t
4352GNUNET_CRYPTO_encrypt_old (const void *block,
4353 size_t size,
4354 const struct GNUNET_CRYPTO_PublicKey *pub,
4355 struct GNUNET_CRYPTO_EcdhePublicKey *ecc,
4356 void *result);
4357
4358
4359/**
4360 * Decrypt a given block with #GNUNET_CRYPTO_PrivateKey and a given
4361 * #GNUNET_CRYPTO_EcdhePublicKey using ecdh to derive a symmetric key.
4362 *
4363 * @param block the data to decrypt, encoded as returned by encrypt
4364 * @param size the size of the @a block to decrypt
4365 * @param priv private key to use for ecdh
4366 * @param ecc the ecc public key
4367 * @param result address to store the result at
4368 * can be the same or overlap with @c block
4369 * @return -1 on failure, size of decrypted block on success.
4370 * Due to the use of CFB and therefore an effective stream cipher,
4371 * this size should be the same as @c size.
4372 */
4373ssize_t
4374GNUNET_CRYPTO_decrypt_old (
4375 const void *block,
4376 size_t size,
4377 const struct GNUNET_CRYPTO_PrivateKey *priv,
4378 const struct GNUNET_CRYPTO_EcdhePublicKey *ecc,
4379 void *result);
4380
4381#define GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES (crypto_secretbox_MACBYTES \
4382 + sizeof (struct \
4383 GNUNET_CRYPTO_FoKemC))
4384
4385/**
4386 * Encrypt a block with #GNUNET_CRYPTO_PublicKey and derives a
4387 * #GNUNET_CRYPTO_EcdhePublicKey which is required for decryption
4388 * using ecdh to derive a symmetric key.
4389 *
4390 * Note that the result buffer for the ciphertext must be the length of
4391 * the message to encrypt plus #GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES.
4392 *
4393 * @param block the block to encrypt
4394 * @param size the size of the @a block
4395 * @param pub public key to encrypt for
4396 * @param result the output parameter in which to store the encrypted result
4397 * can be the same or overlap with @c block
4398 * @returns GNUNET_OK on success.
4399 */
4400enum GNUNET_GenericReturnValue
4401GNUNET_CRYPTO_encrypt (const void *block,
4402 size_t size,
4403 const struct GNUNET_CRYPTO_PublicKey *pub,
4404 void *result,
4405 size_t result_size);
4406
4407
4408/**
4409 * Decrypt a given block with #GNUNET_CRYPTO_PrivateKey and a given
4410 * #GNUNET_CRYPTO_EcdhePublicKey using ecdh to derive a symmetric key.
4411 *
4412 * @param block the data to decrypt, encoded as returned by encrypt
4413 * @param size the size of the @a block to decrypt
4414 * @param priv private key to use for ecdh
4415 * @param result address to store the result at
4416 * can be the same or overlap with @c block
4417 * @returns GNUNET_OK on success.
4418 */
4419enum GNUNET_GenericReturnValue
4420GNUNET_CRYPTO_decrypt (const void *block,
4421 size_t size,
4422 const struct GNUNET_CRYPTO_PrivateKey *priv,
4423 void *result,
4424 size_t result_size);
4425
4426
4427/**
4428 * Creates a (Base32) string representation of the public key.
4429 * The resulting string encodes a compacted representation of the key.
4430 * See also #GNUNET_CRYPTO_key_get_length.
4431 *
4432 * @param key the key.
4433 * @return the string representation of the key, or NULL on error.
4434 */
4435char *
4436GNUNET_CRYPTO_public_key_to_string (
4437 const struct GNUNET_CRYPTO_PublicKey *key);
4438
4439
4440/**
4441 * Creates a (Base32) string representation of the private key.
4442 * The resulting string encodes a compacted representation of the key.
4443 * See also #GNUNET_CRYPTO_key_get_length.
4444 *
4445 * @param key the key.
4446 * @return the string representation of the key, or NULL on error.
4447 */
4448char *
4449GNUNET_CRYPTO_private_key_to_string (
4450 const struct GNUNET_CRYPTO_PrivateKey *key);
4451
4452
4453/**
4454 * Parses a (Base32) string representation of the public key.
4455 * See also #GNUNET_CRYPTO_public_key_to_string.
4456 *
4457 * @param str the encoded key.
4458 * @param key where to write the key.
4459 * @return GNUNET_SYSERR on error.
4460 */
4461enum GNUNET_GenericReturnValue
4462GNUNET_CRYPTO_public_key_from_string (const char*str,
4463 struct GNUNET_CRYPTO_PublicKey *key);
4464
4465
4466/**
4467 * Parses a (Base32) string representation of the private key.
4468 * See also #GNUNET_CRYPTO_private_key_to_string.
4469 *
4470 * @param str the encoded key.
4471 * @param key where to write the key.
4472 * @return GNUNET_SYSERR on error.
4473 */
4474enum GNUNET_GenericReturnValue
4475GNUNET_CRYPTO_private_key_from_string (const char*str,
4476 struct GNUNET_CRYPTO_PrivateKey *key);
4477
4478
4479/**
4480 * Retrieves the public key representation of a private key.
4481 *
4482 * @param privkey the private key.
4483 * @param key the public key result.
4484 * @return GNUNET_SYSERR on error.
4485 */
4486enum GNUNET_GenericReturnValue
4487GNUNET_CRYPTO_key_get_public (const struct
4488 GNUNET_CRYPTO_PrivateKey *privkey,
4489 struct GNUNET_CRYPTO_PublicKey *key);
4490
2439#if 0 /* keep Emacsens' auto-indent happy */ 4491#if 0 /* keep Emacsens' auto-indent happy */
2440{ 4492{
2441#endif 4493#endif
@@ -2446,4 +4498,7 @@ GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash,
2446 4498
2447/* ifndef GNUNET_CRYPTO_LIB_H */ 4499/* ifndef GNUNET_CRYPTO_LIB_H */
2448#endif 4500#endif
4501
4502/** @} */ /* end of group addition */
4503
2449/* end of gnunet_crypto_lib.h */ 4504/* end of gnunet_crypto_lib.h */
diff --git a/src/include/gnunet_curl_lib.h b/src/include/gnunet_curl_lib.h
index 38acecc48..967170085 100644
--- a/src/include/gnunet_curl_lib.h
+++ b/src/include/gnunet_curl_lib.h
@@ -18,6 +18,9 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup lib_extra Additional libraries
22 * @{
23 *
21 * @file src/include/gnunet_curl_lib.h 24 * @file src/include/gnunet_curl_lib.h
22 * @brief library to make it easy to download JSON replies over HTTP 25 * @brief library to make it easy to download JSON replies over HTTP
23 * @author Sree Harsha Totakura <sreeharsha@totakura.in> 26 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
@@ -29,13 +32,8 @@
29 */ 32 */
30#ifndef GNUNET_CURL_LIB_H 33#ifndef GNUNET_CURL_LIB_H
31#define GNUNET_CURL_LIB_H 34#define GNUNET_CURL_LIB_H
32#if HAVE_LIBCURL 35
33#include <curl/curl.h> 36#include <curl/curl.h>
34#elif HAVE_LIBGNURL
35#include <gnurl/curl.h>
36#else
37#error "needs curl or gnurl"
38#endif
39#include "gnunet_util_lib.h" 37#include "gnunet_util_lib.h"
40 38
41 39
@@ -230,7 +228,7 @@ typedef void
230 * be executed AND cleaned up 228 * be executed AND cleaned up
231 * @param jcc callback to invoke upon completion 229 * @param jcc callback to invoke upon completion
232 * @param jcc_cls closure for @a jcc 230 * @param jcc_cls closure for @a jcc
233 * @return NULL on error (in this case, @eh is still released!) 231 * @return NULL on error (in this case, @a eh is still released!)
234 */ 232 */
235struct GNUNET_CURL_Job * 233struct GNUNET_CURL_Job *
236GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx, 234GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx,
@@ -252,7 +250,7 @@ GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx,
252 * be executed AND cleaned up 250 * be executed AND cleaned up
253 * @param jcc callback to invoke upon completion 251 * @param jcc callback to invoke upon completion
254 * @param jcc_cls closure for @a jcc 252 * @param jcc_cls closure for @a jcc
255 * @return NULL on error (in this case, @eh is still released!) 253 * @return NULL on error (in this case, @a eh is still released!)
256 */ 254 */
257struct GNUNET_CURL_Job * 255struct GNUNET_CURL_Job *
258GNUNET_CURL_job_add_with_ct_json (struct GNUNET_CURL_Context *ctx, 256GNUNET_CURL_job_add_with_ct_json (struct GNUNET_CURL_Context *ctx,
@@ -310,7 +308,7 @@ GNUNET_CURL_set_tlscert (struct GNUNET_CURL_Context *ctx,
310 * @param job_headers extra headers to add for this request 308 * @param job_headers extra headers to add for this request
311 * @param jcc callback to invoke upon completion 309 * @param jcc callback to invoke upon completion
312 * @param jcc_cls closure for @a jcc 310 * @param jcc_cls closure for @a jcc
313 * @return NULL on error (in this case, @eh is still released!) 311 * @return NULL on error (in this case, @a eh is still released!)
314 */ 312 */
315struct GNUNET_CURL_Job * 313struct GNUNET_CURL_Job *
316GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx, 314GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx,
@@ -330,10 +328,9 @@ GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx,
330 * @param eh curl easy handle for the request, will 328 * @param eh curl easy handle for the request, will
331 * be executed AND cleaned up 329 * be executed AND cleaned up
332 * @param job_headers extra headers to add for this request 330 * @param job_headers extra headers to add for this request
333 * @param max_reply_size largest acceptable response body
334 * @param jcc callback to invoke upon completion 331 * @param jcc callback to invoke upon completion
335 * @param jcc_cls closure for @a jcc 332 * @param jcc_cls closure for @a jcc
336 * @return NULL on error (in this case, @eh is still released!) 333 * @return NULL on error (in this case, @a eh is still released!)
337 */ 334 */
338struct GNUNET_CURL_Job * 335struct GNUNET_CURL_Job *
339GNUNET_CURL_job_add_raw (struct GNUNET_CURL_Context *ctx, 336GNUNET_CURL_job_add_raw (struct GNUNET_CURL_Context *ctx,
@@ -436,11 +433,13 @@ GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx,
436 * 433 *
437 * @returns #GNUNET_YES iff given a valid scope ID 434 * @returns #GNUNET_YES iff given a valid scope ID
438 */ 435 */
439int 436enum GNUNET_GenericReturnValue
440GNUNET_CURL_is_valid_scope_id (const char *scope_id); 437GNUNET_CURL_is_valid_scope_id (const char *scope_id);
441 438
442 439
443#endif 440#endif
444/** @} */ /* end of group */ 441/** @} */ /* end of group */
445 442
443/** @} */ /* end of group addition to lib_extra */
444
446/* end of gnunet_curl_lib.h */ 445/* end of gnunet_curl_lib.h */
diff --git a/src/include/gnunet_datacache_lib.h b/src/include/gnunet_datacache_lib.h
index 40885803b..2c7bf1e8f 100644
--- a/src/include/gnunet_datacache_lib.h
+++ b/src/include/gnunet_datacache_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2006, 2009, 2015 GNUnet e.V. 3 Copyright (C) 2006, 2009, 2015, 2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup dht_libs DHT and support libraries
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -37,8 +40,10 @@
37#ifndef GNUNET_DATACACHE_LIB_H 40#ifndef GNUNET_DATACACHE_LIB_H
38#define GNUNET_DATACACHE_LIB_H 41#define GNUNET_DATACACHE_LIB_H
39 42
43
40#include "gnunet_util_lib.h" 44#include "gnunet_util_lib.h"
41#include "gnunet_block_lib.h" 45#include "gnunet_block_lib.h"
46#include "gnunet_dht_service.h"
42 47
43#ifdef __cplusplus 48#ifdef __cplusplus
44extern "C" 49extern "C"
@@ -50,6 +55,59 @@ extern "C"
50 55
51 56
52/** 57/**
58 * Information about a block stored in the datacache.
59 */
60struct GNUNET_DATACACHE_Block
61{
62 /**
63 * Key of the block.
64 */
65 struct GNUNET_HashCode key;
66
67 /**
68 * When does the block expire?
69 */
70 struct GNUNET_TIME_Absolute expiration_time;
71
72 /**
73 * If the path was truncated, this is the peer
74 * ID at which the path was truncated.
75 */
76 struct GNUNET_PeerIdentity trunc_peer;
77
78 /**
79 * PUT path taken by the block, array of peer identities.
80 */
81 const struct GNUNET_DHT_PathElement *put_path;
82
83 /**
84 * Actual block data.
85 */
86 const void *data;
87
88 /**
89 * Number of bytes in @a data.
90 */
91 size_t data_size;
92
93 /**
94 * Length of the @e put_path array.
95 */
96 unsigned int put_path_length;
97
98 /**
99 * Type of the block.
100 */
101 enum GNUNET_BLOCK_Type type;
102
103 /**
104 * Options for routing for the block.
105 */
106 enum GNUNET_DHT_RouteOption ro;
107};
108
109
110/**
53 * Handle to the cache. 111 * Handle to the cache.
54 */ 112 */
55struct GNUNET_DATACACHE_Handle; 113struct GNUNET_DATACACHE_Handle;
@@ -80,50 +138,26 @@ GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h);
80 * An iterator over a set of items stored in the datacache. 138 * An iterator over a set of items stored in the datacache.
81 * 139 *
82 * @param cls closure 140 * @param cls closure
83 * @param key key for the content 141 * @param block a block from the datacache
84 * @param data_size number of bytes in @a data
85 * @param data content stored
86 * @param type type of the content
87 * @param exp when will the content expire?
88 * @param path_info_len number of entries in @a path_info
89 * @param path_info a path through the network
90 * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort 142 * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort
91 */ 143 */
92typedef int 144typedef enum GNUNET_GenericReturnValue
93(*GNUNET_DATACACHE_Iterator) (void *cls, 145(*GNUNET_DATACACHE_Iterator)(void *cls,
94 const struct GNUNET_HashCode *key, 146 const struct GNUNET_DATACACHE_Block *block);
95 size_t data_size,
96 const char *data,
97 enum GNUNET_BLOCK_Type type,
98 struct GNUNET_TIME_Absolute exp,
99 unsigned int path_info_len,
100 const struct GNUNET_PeerIdentity *path_info);
101 147
102 148
103/** 149/**
104 * Store an item in the datacache. 150 * Store an item in the datacache.
105 * 151 *
106 * @param h handle to the datacache 152 * @param h handle to the datacache
107 * @param key key to store data under 153 * @param xor_distance how close is the block's key to our pid?
108 * @param how close is @a key to our pid? 154 * @param block actual block data to store
109 * @param data_size number of bytes in @a data
110 * @param data data to store
111 * @param type type of the value
112 * @param discard_time when to discard the value in any case
113 * @param path_info_len number of entries in @a path_info
114 * @param path_info a path through the network
115 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error, #GNUNET_NO if duplicate 155 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error, #GNUNET_NO if duplicate
116 */ 156 */
117int 157enum GNUNET_GenericReturnValue
118GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, 158GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
119 const struct GNUNET_HashCode *key,
120 uint32_t xor_distance, 159 uint32_t xor_distance,
121 size_t data_size, 160 const struct GNUNET_DATACACHE_Block *block);
122 const char *data,
123 enum GNUNET_BLOCK_Type type,
124 struct GNUNET_TIME_Absolute discard_time,
125 unsigned int path_info_len,
126 const struct GNUNET_PeerIdentity *path_info);
127 161
128 162
129/** 163/**
@@ -146,20 +180,6 @@ GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
146 180
147 181
148/** 182/**
149 * Obtain a random element from the datacache.
150 *
151 * @param h handle to the datacache
152 * @param iter maybe NULL (to just count)
153 * @param iter_cls closure for @a iter
154 * @return the number of results found (zero or 1)
155 */
156unsigned int
157GNUNET_DATACACHE_get_random (struct GNUNET_DATACACHE_Handle *h,
158 GNUNET_DATACACHE_Iterator iter,
159 void *iter_cls);
160
161
162/**
163 * Iterate over the results that are "close" to a particular key in 183 * Iterate over the results that are "close" to a particular key in
164 * the datacache. "close" is defined as numerically larger than @a 184 * the datacache. "close" is defined as numerically larger than @a
165 * key (when interpreted as a circular address space), with small 185 * key (when interpreted as a circular address space), with small
@@ -167,6 +187,7 @@ GNUNET_DATACACHE_get_random (struct GNUNET_DATACACHE_Handle *h,
167 * 187 *
168 * @param h handle to the datacache 188 * @param h handle to the datacache
169 * @param key area of the keyspace to look into 189 * @param key area of the keyspace to look into
190 * @param type entries of which type are relevant?
170 * @param num_results number of results that should be returned to @a iter 191 * @param num_results number of results that should be returned to @a iter
171 * @param iter maybe NULL (to just count) 192 * @param iter maybe NULL (to just count)
172 * @param iter_cls closure for @a iter 193 * @param iter_cls closure for @a iter
@@ -175,6 +196,7 @@ GNUNET_DATACACHE_get_random (struct GNUNET_DATACACHE_Handle *h,
175unsigned int 196unsigned int
176GNUNET_DATACACHE_get_closest (struct GNUNET_DATACACHE_Handle *h, 197GNUNET_DATACACHE_get_closest (struct GNUNET_DATACACHE_Handle *h,
177 const struct GNUNET_HashCode *key, 198 const struct GNUNET_HashCode *key,
199 enum GNUNET_BLOCK_Type type,
178 unsigned int num_results, 200 unsigned int num_results,
179 GNUNET_DATACACHE_Iterator iter, 201 GNUNET_DATACACHE_Iterator iter,
180 void *iter_cls); 202 void *iter_cls);
@@ -190,3 +212,5 @@ GNUNET_DATACACHE_get_closest (struct GNUNET_DATACACHE_Handle *h,
190#endif 212#endif
191 213
192/** @} */ /* end of group */ 214/** @} */ /* end of group */
215
216/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_datacache_plugin.h b/src/include/gnunet_datacache_plugin.h
index d7fa8fde0..e144e155e 100644
--- a/src/include/gnunet_datacache_plugin.h
+++ b/src/include/gnunet_datacache_plugin.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2006, 2009, 2015 GNUnet e.V. 3 Copyright (C) 2006, 2009, 2015, 2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup dht_libs DHT and support libraries
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -31,6 +34,7 @@
31#ifndef PLUGIN_DATACACHE_H 34#ifndef PLUGIN_DATACACHE_H
32#define PLUGIN_DATACACHE_H 35#define PLUGIN_DATACACHE_H
33 36
37
34#include "gnunet_datacache_lib.h" 38#include "gnunet_datacache_lib.h"
35 39
36#ifdef __cplusplus 40#ifdef __cplusplus
@@ -105,25 +109,15 @@ struct GNUNET_DATACACHE_PluginFunctions
105 * Store an item in the datastore. 109 * Store an item in the datastore.
106 * 110 *
107 * @param cls closure (internal context for the plugin) 111 * @param cls closure (internal context for the plugin)
108 * @param key key to store the value under
109 * @param xor_distance how close is @a key to our PID? 112 * @param xor_distance how close is @a key to our PID?
110 * @param size number of bytes in @a data 113 * @param block data to store
111 * @param data data to store
112 * @param type type of the value
113 * @param discard_time when to discard the value in any case
114 * @param path_info_len number of entries in @a path_info
115 * @param path_info a path through the network
116 * @return 0 if duplicate, -1 on error, number of bytes used otherwise 114 * @return 0 if duplicate, -1 on error, number of bytes used otherwise
117 */ 115 */
118 ssize_t (*put) (void *cls, 116 ssize_t
119 const struct GNUNET_HashCode *key, 117 (*put) (void *cls,
120 uint32_t xor_distance, 118 uint32_t xor_distance,
121 size_t size, 119 const struct GNUNET_DATACACHE_Block *block);
122 const char *data, 120
123 enum GNUNET_BLOCK_Type type,
124 struct GNUNET_TIME_Absolute discard_time,
125 unsigned int path_info_len,
126 const struct GNUNET_PeerIdentity *path_info);
127 121
128 /** 122 /**
129 * Iterate over the results for a particular key 123 * Iterate over the results for a particular key
@@ -136,11 +130,13 @@ struct GNUNET_DATACACHE_PluginFunctions
136 * @param iter_cls closure for @a iter 130 * @param iter_cls closure for @a iter
137 * @return the number of results found 131 * @return the number of results found
138 */ 132 */
139 unsigned int (*get) (void *cls, 133 unsigned int
140 const struct GNUNET_HashCode *key, 134 (*get) (void *cls,
141 enum GNUNET_BLOCK_Type type, 135 const struct GNUNET_HashCode *key,
142 GNUNET_DATACACHE_Iterator iter, 136 enum GNUNET_BLOCK_Type type,
143 void *iter_cls); 137 GNUNET_DATACACHE_Iterator iter,
138 void *iter_cls);
139
144 140
145 /** 141 /**
146 * Delete the entry with the lowest expiration value 142 * Delete the entry with the lowest expiration value
@@ -149,39 +145,32 @@ struct GNUNET_DATACACHE_PluginFunctions
149 * @param cls closure (internal context for the plugin) 145 * @param cls closure (internal context for the plugin)
150 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 146 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
151 */ 147 */
152 int (*del) (void *cls); 148 enum GNUNET_GenericReturnValue
153 149 (*del)(void *cls);
154 /**
155 * Return a random value from the datastore.
156 *
157 * @param cls closure (internal context for the plugin)
158 * @param iter maybe NULL (to just count)
159 * @param iter_cls closure for @a iter
160 * @return the number of results found (zero or one)
161 */
162 unsigned int (*get_random) (void *cls,
163 GNUNET_DATACACHE_Iterator iter,
164 void *iter_cls);
165 150
166 151
167 /** 152 /**
168 * Iterate over the results that are "close" to a particular key in 153 * Iterate over the results that are "close" to a particular key in the
169 * the datacache. "close" is defined as numerically larger than @a 154 * datacache. "close" is defined as returning the @a num_results that are
170 * key (when interpreted as a circular address space), with small 155 * numerically closest and larger than @a key and also @a num_results that
171 * distance. 156 * are numerically lower than @a key. Thus, the maximum number of results
157 * returned is actually twice @a num_results.
172 * 158 *
173 * @param cls closure (internal context for the plugin) 159 * @param cls closure (internal context for the plugin)
174 * @param key area of the keyspace to look into 160 * @param key area of the keyspace to look into
175 * @param num_results number of results that should be returned to @a iter 161 * @param type desired block type for the replies
162 * @param num_results half the number of results that should be returned to @a iter
176 * @param iter maybe NULL (to just count) 163 * @param iter maybe NULL (to just count)
177 * @param iter_cls closure for @a iter 164 * @param iter_cls closure for @a iter
178 * @return the number of results found 165 * @return the number of results found
179 */ 166 */
180 unsigned int (*get_closest) (void *cls, 167 unsigned int
181 const struct GNUNET_HashCode *key, 168 (*get_closest) (void *cls,
182 unsigned int num_results, 169 const struct GNUNET_HashCode *key,
183 GNUNET_DATACACHE_Iterator iter, 170 enum GNUNET_BLOCK_Type type,
184 void *iter_cls); 171 unsigned int num_results,
172 GNUNET_DATACACHE_Iterator iter,
173 void *iter_cls);
185}; 174};
186 175
187 176
@@ -195,3 +184,5 @@ struct GNUNET_DATACACHE_PluginFunctions
195#endif 184#endif
196 185
197/** @} */ /* end of group */ 186/** @} */ /* end of group */
187
188/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_datastore_plugin.h b/src/include/gnunet_datastore_plugin.h
index 113f6b2f2..c4f31c7ce 100644
--- a/src/include/gnunet_datastore_plugin.h
+++ b/src/include/gnunet_datastore_plugin.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup fs_l2 File sharing and support services/libraries
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -31,6 +34,7 @@
31#ifndef PLUGIN_DATASTORE_H 34#ifndef PLUGIN_DATASTORE_H
32#define PLUGIN_DATASTORE_H 35#define PLUGIN_DATASTORE_H
33 36
37
34#include "gnunet_block_lib.h" 38#include "gnunet_block_lib.h"
35#include "gnunet_configuration_lib.h" 39#include "gnunet_configuration_lib.h"
36#include "gnunet_datastore_service.h" 40#include "gnunet_datastore_service.h"
@@ -98,17 +102,17 @@ struct GNUNET_DATASTORE_PluginEnvironment
98 * @return #GNUNET_OK to keep the item 102 * @return #GNUNET_OK to keep the item
99 * #GNUNET_NO to delete the item 103 * #GNUNET_NO to delete the item
100 */ 104 */
101typedef int 105typedef enum GNUNET_GenericReturnValue
102(*PluginDatumProcessor) (void *cls, 106(*PluginDatumProcessor)(void *cls,
103 const struct GNUNET_HashCode *key, 107 const struct GNUNET_HashCode *key,
104 uint32_t size, 108 uint32_t size,
105 const void *data, 109 const void *data,
106 enum GNUNET_BLOCK_Type type, 110 enum GNUNET_BLOCK_Type type,
107 uint32_t priority, 111 uint32_t priority,
108 uint32_t anonymity, 112 uint32_t anonymity,
109 uint32_t replication, 113 uint32_t replication,
110 struct GNUNET_TIME_Absolute expiration, 114 struct GNUNET_TIME_Absolute expiration,
111 uint64_t uid); 115 uint64_t uid);
112 116
113 117
114/** 118/**
@@ -377,3 +381,5 @@ struct GNUNET_DATASTORE_PluginFunctions
377#endif 381#endif
378 382
379/** @} */ /* end of group */ 383/** @} */ /* end of group */
384
385/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_datastore_service.h b/src/include/gnunet_datastore_service.h
index c99db67bc..153387238 100644
--- a/src/include/gnunet_datastore_service.h
+++ b/src/include/gnunet_datastore_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup fs_l2 File sharing and support services/libraries
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -39,6 +42,7 @@
39#ifndef GNUNET_DATASTORE_SERVICE_H 42#ifndef GNUNET_DATASTORE_SERVICE_H
40#define GNUNET_DATASTORE_SERVICE_H 43#define GNUNET_DATASTORE_SERVICE_H
41 44
45
42#include "gnunet_util_lib.h" 46#include "gnunet_util_lib.h"
43#include "gnunet_block_lib.h" 47#include "gnunet_block_lib.h"
44 48
@@ -361,3 +365,5 @@ GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe);
361#endif 365#endif
362 366
363/** @} */ /* end of group */ 367/** @} */ /* end of group */
368
369/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_db_lib.h b/src/include/gnunet_db_lib.h
index e88e836f6..1ff665c2b 100644
--- a/src/include/gnunet_db_lib.h
+++ b/src/include/gnunet_db_lib.h
@@ -25,6 +25,7 @@
25#ifndef GNUNET_DB_LIB_H 25#ifndef GNUNET_DB_LIB_H
26#define GNUNET_DB_LIB_H 26#define GNUNET_DB_LIB_H
27 27
28
28#include "gnunet_common.h" 29#include "gnunet_common.h"
29 30
30/** 31/**
diff --git a/src/include/gnunet_dht_block_types.h b/src/include/gnunet_dht_block_types.h
new file mode 100644
index 000000000..ab46af410
--- /dev/null
+++ b/src/include/gnunet_dht_block_types.h
@@ -0,0 +1,156 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012-2022 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20#ifndef GNUNET_DHT_BLOCK_TYPES_H
21#define GNUNET_DHT_BLOCK_TYPES_H
22
23/**
24 * WARNING:
25 * This header is generated!
26 * In order to add DHT block types, you must register
27 * them in GANA, and then use the header generation script
28 * to create an update of this file. You may then replace this
29 * file with the update.
30 */
31
32#ifdef __cplusplus
33extern "C" {
34#if 0 /* keep Emacsens' auto-indent happy */
35}
36#endif
37#endif
38
39/**
40 * Blocks in the datastore and the datacache must have a unique type.
41 */
42enum GNUNET_BLOCK_Type
43{
44
45
46 /**
47 * Identifier for any block.
48 */
49 GNUNET_BLOCK_TYPE_ANY = 0,
50
51
52 /**
53 * Data block (leaf) in the CHK tree.
54 */
55 GNUNET_BLOCK_TYPE_FS_DBLOCK = 1,
56
57
58 /**
59 * Inner block in the CHK tree.
60 */
61 GNUNET_BLOCK_TYPE_FS_IBLOCK = 2,
62
63
64 /**
65 * Type of a block representing a block to be encoded on demand from disk. Should never appear on the network directly.
66 */
67 GNUNET_BLOCK_TYPE_FS_ONDEMAND = 6,
68
69
70 /**
71 * Legacy type of a block that contains a HELLO for a peer.
72 */
73 GNUNET_BLOCK_TYPE_LEGACY_HELLO = 7,
74
75
76 /**
77 * Block for testing.
78 */
79 GNUNET_BLOCK_TYPE_TEST = 8,
80
81
82 /**
83 * Type of a block representing any type of search result (universal).
84 */
85 GNUNET_BLOCK_TYPE_FS_UBLOCK = 9,
86
87
88 /**
89 * Block for storing DNS exit service advertisements.
90 */
91 GNUNET_BLOCK_TYPE_DNS = 10,
92
93
94 /**
95 * Block for storing GNS record data.
96 */
97 GNUNET_BLOCK_TYPE_GNS_NAMERECORD = 11,
98
99
100 /**
101 * Block type for a revocation message by which a key is revoked.
102 */
103 GNUNET_BLOCK_TYPE_REVOCATION = 12,
104
105
106 /**
107 * Type of a block that contains a DHT-NG HELLO for a peer.
108 */
109 GNUNET_BLOCK_TYPE_DHT_HELLO = 13,
110
111
112 /**
113 * Block to store a cadet regex state
114 */
115 GNUNET_BLOCK_TYPE_REGEX = 22,
116
117
118 /**
119 * Block to store a cadet regex accepting state
120 */
121 GNUNET_BLOCK_TYPE_REGEX_ACCEPT = 23,
122
123
124 /**
125 * Block for testing set/consensus. If first byte of the block is non-zero, the block is considered invalid.
126 */
127 GNUNET_BLOCK_TYPE_SET_TEST = 24,
128
129
130 /**
131 * Block type for consensus elements. Contains either special marker elements or a nested block.
132 */
133 GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT = 25,
134
135
136 /**
137 * Block for testing set intersection. If first byte of the block is non-zero, the block is considered invalid.
138 */
139 GNUNET_BLOCK_TYPE_SETI_TEST = 26,
140
141
142 /**
143 * Block for testing set union. If first byte of the block is non-zero, the block is considered invalid.
144 */
145 GNUNET_BLOCK_TYPE_SETU_TEST = 27,
146};
147
148
149#if 0 /* keep Emacsens' auto-indent happy */
150{
151#endif
152#ifdef __cplusplus
153}
154#endif
155
156#endif
diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h
index d4a4ed7d2..a1ea31c25 100644
--- a/src/include/gnunet_dht_service.h
+++ b/src/include/gnunet_dht_service.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2004-2013, 2016 GNUnet e.V. 3 Copyright (C) 2004-2013, 2016, 2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,11 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Backbone
23 * @{
24 * @addtogroup dht_libs DHT and support libraries
25 * @{
26 *
22 * @author Christian Grothoff 27 * @author Christian Grothoff
23 * 28 *
24 * @file 29 * @file
@@ -35,9 +40,9 @@
35#ifndef GNUNET_DHT_SERVICE_H 40#ifndef GNUNET_DHT_SERVICE_H
36#define GNUNET_DHT_SERVICE_H 41#define GNUNET_DHT_SERVICE_H
37 42
43
38#include "gnunet_util_lib.h" 44#include "gnunet_util_lib.h"
39#include "gnunet_block_lib.h" 45#include "gnunet_block_lib.h"
40#include "gnunet_hello_lib.h"
41 46
42#ifdef __cplusplus 47#ifdef __cplusplus
43extern "C" 48extern "C"
@@ -56,6 +61,12 @@ extern "C"
56 61
57 62
58/** 63/**
64 * Maximum allowed replication level for all requests.
65 */
66#define GNUNET_DHT_MAXIMUM_REPLICATION_LEVEL 16
67
68
69/**
59 * Connection to the DHT service. 70 * Connection to the DHT service.
60 */ 71 */
61struct GNUNET_DHT_Handle; 72struct GNUNET_DHT_Handle;
@@ -95,18 +106,88 @@ enum GNUNET_DHT_RouteOption
95 GNUNET_DHT_RO_RECORD_ROUTE = 2, 106 GNUNET_DHT_RO_RECORD_ROUTE = 2,
96 107
97 /** 108 /**
98 * This is a 'FIND-PEER' request, so approximate results are fine. 109 * Approximate results are fine.
110 */
111 GNUNET_DHT_RO_FIND_APPROXIMATE = 4,
112
113 /**
114 * Flag set if the path was truncated.
115 */
116 GNUNET_DHT_RO_TRUNCATED = 8,
117
118 /**
119 * Flag given to monitors if this was the last hop for a GET/PUT.
120 * This is only used for internal processing.
121 */
122 GNUNET_DHT_RO_LAST_HOP = 32768
123};
124
125
126GNUNET_NETWORK_STRUCT_BEGIN
127
128/**
129 * Message signed by a peer when doing path tracking.
130 */
131struct GNUNET_DHT_HopSignature
132{
133 /**
134 * Must be #GNUNET_SIGNATURE_PURPOSE_DHT_HOP.
99 */ 135 */
100 GNUNET_DHT_RO_FIND_PEER = 4, 136 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
101 137
102 /** 138 /**
103 * Flag given to monitors if this was the last hop for a GET/PUT. 139 * Expiration time of the block.
104 * This is only used for internal processing. 140 */
105 */ 141 struct GNUNET_TIME_AbsoluteNBO expiration_time;
106 GNUNET_DHT_RO_LAST_HOP = 65535 142
143 /**
144 * Hash over the payload of the block.
145 */
146 struct GNUNET_HashCode h_data GNUNET_PACKED;
147
148 /**
149 * Previous hop the message was received from. All zeros
150 * if this peer was the initiator.
151 */
152 struct GNUNET_PeerIdentity pred;
153
154 /**
155 * Next hop the message was forwarded to.
156 */
157 struct GNUNET_PeerIdentity succ;
158};
159
160
161/**
162 * A (signed) path tracking a block's flow through the DHT is represented by
163 * an array of path elements, each consisting of a peer on the path and a
164 * signature by which the peer affirms its routing decision.
165 */
166struct GNUNET_DHT_PathElement
167{
168 /**
169 * Signature affirming the hop of type
170 * #GNUNET_SIGNATURE_PURPOSE_DHT_HOP.
171 */
172 struct GNUNET_CRYPTO_EddsaSignature sig;
173
174 /**
175 * Previous peer on the path (matches "pred" in the signed field).
176 *
177 * The public key used to create the @e sig is in the *next* path element,
178 * or is the sender of the message if this was the last path element.
179 *
180 * The "succ" field can be found in 'pred' if there are two more path
181 * elements in the path, is the sender if there is only one more path
182 * element, or the recipient if this was the last element on the path.
183 */
184 struct GNUNET_PeerIdentity pred;
185
107}; 186};
108 187
109 188
189GNUNET_NETWORK_STRUCT_END
190
110/** 191/**
111 * Initialize the connection with the DHT service. 192 * Initialize the connection with the DHT service.
112 * 193 *
@@ -190,13 +271,16 @@ GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph);
190 * 271 *
191 * @param cls closure 272 * @param cls closure
192 * @param exp when will this value expire 273 * @param exp when will this value expire
193 * @param key key of the result 274 * @param query_hash key of the query
275 * @param trunc_peer peer where the path was truncated, or NULL if the path is complete
194 * @param get_path peers on reply path (or NULL if not recorded) 276 * @param get_path peers on reply path (or NULL if not recorded)
195 * [0] = datastore's first neighbor, [length - 1] = local peer 277 * [0] = datastore's first neighbor, [length - 1] = local peer
196 * @param get_path_length number of entries in @a get_path 278 * @param get_path_length number of entries in @a get_path
197 * @param put_path peers on the PUT path (or NULL if not recorded) 279 * @param put_path peers on the PUT path (or NULL if not recorded)
198 * [0] = origin, [length - 1] = datastore 280 * [0] = origin, [length - 1] = datastore
199 * @param put_path_length number of entries in @a put_path 281 * @param put_path_length number of entries in @a put_path,
282 * note that the last signature will be all zeros as
283 * we did not forward and thus did not sign!
200 * @param type type of the result 284 * @param type type of the result
201 * @param size number of bytes in @a data 285 * @param size number of bytes in @a data
202 * @param data pointer to the result data 286 * @param data pointer to the result data
@@ -204,10 +288,11 @@ GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph);
204typedef void 288typedef void
205(*GNUNET_DHT_GetIterator) (void *cls, 289(*GNUNET_DHT_GetIterator) (void *cls,
206 struct GNUNET_TIME_Absolute exp, 290 struct GNUNET_TIME_Absolute exp,
207 const struct GNUNET_HashCode *key, 291 const struct GNUNET_HashCode *query_hash,
208 const struct GNUNET_PeerIdentity *get_path, 292 const struct GNUNET_PeerIdentity *trunc_peer,
293 const struct GNUNET_DHT_PathElement *get_path,
209 unsigned int get_path_length, 294 unsigned int get_path_length,
210 const struct GNUNET_PeerIdentity *put_path, 295 const struct GNUNET_DHT_PathElement *put_path,
211 unsigned int put_path_length, 296 unsigned int put_path_length,
212 enum GNUNET_BLOCK_Type type, 297 enum GNUNET_BLOCK_Type type,
213 size_t size, 298 size_t size,
@@ -280,8 +365,6 @@ struct GNUNET_DHT_MonitorHandle;
280 * @param options Options, for instance RecordRoute, DemultiplexEverywhere. 365 * @param options Options, for instance RecordRoute, DemultiplexEverywhere.
281 * @param type The type of data in the request. 366 * @param type The type of data in the request.
282 * @param hop_count Hop count so far. 367 * @param hop_count Hop count so far.
283 * @param path_length number of entries in @a path (or 0 if not recorded).
284 * @param path peers on the GET path (or NULL if not recorded).
285 * @param desired_replication_level Desired replication level. 368 * @param desired_replication_level Desired replication level.
286 * @param key Key of the requested data. 369 * @param key Key of the requested data.
287 */ 370 */
@@ -291,8 +374,6 @@ typedef void
291 enum GNUNET_BLOCK_Type type, 374 enum GNUNET_BLOCK_Type type,
292 uint32_t hop_count, 375 uint32_t hop_count,
293 uint32_t desired_replication_level, 376 uint32_t desired_replication_level,
294 unsigned int path_length,
295 const struct GNUNET_PeerIdentity *path,
296 const struct GNUNET_HashCode *key); 377 const struct GNUNET_HashCode *key);
297 378
298 379
@@ -301,7 +382,10 @@ typedef void
301 * 382 *
302 * @param cls Closure. 383 * @param cls Closure.
303 * @param type The type of data in the result. 384 * @param type The type of data in the result.
385 * @param trunc_peer peer where the path was truncated, or NULL if the path is complete
304 * @param get_path Peers on GET path (or NULL if not recorded). 386 * @param get_path Peers on GET path (or NULL if not recorded).
387 * note that the last signature will be all zeros as
388 * we did not forward and thus did not sign!
305 * @param get_path_length number of entries in @a get_path. 389 * @param get_path_length number of entries in @a get_path.
306 * @param put_path peers on the PUT path (or NULL if not recorded). 390 * @param put_path peers on the PUT path (or NULL if not recorded).
307 * @param put_path_length number of entries in @a get_path. 391 * @param put_path_length number of entries in @a get_path.
@@ -313,9 +397,10 @@ typedef void
313typedef void 397typedef void
314(*GNUNET_DHT_MonitorGetRespCB) (void *cls, 398(*GNUNET_DHT_MonitorGetRespCB) (void *cls,
315 enum GNUNET_BLOCK_Type type, 399 enum GNUNET_BLOCK_Type type,
316 const struct GNUNET_PeerIdentity *get_path, 400 const struct GNUNET_PeerIdentity *trunc_peer,
401 const struct GNUNET_DHT_PathElement *get_path,
317 unsigned int get_path_length, 402 unsigned int get_path_length,
318 const struct GNUNET_PeerIdentity *put_path, 403 const struct GNUNET_DHT_PathElement *put_path,
319 unsigned int put_path_length, 404 unsigned int put_path_length,
320 struct GNUNET_TIME_Absolute exp, 405 struct GNUNET_TIME_Absolute exp,
321 const struct GNUNET_HashCode *key, 406 const struct GNUNET_HashCode *key,
@@ -330,9 +415,12 @@ typedef void
330 * @param options Options, for instance RecordRoute, DemultiplexEverywhere. 415 * @param options Options, for instance RecordRoute, DemultiplexEverywhere.
331 * @param type The type of data in the request. 416 * @param type The type of data in the request.
332 * @param hop_count Hop count so far. 417 * @param hop_count Hop count so far.
418 * @param desired_replication_level Desired replication level.
419 * @param trunc_peer peer where the path was truncated, or NULL if the path is complete
333 * @param path_length number of entries in @a path (or 0 if not recorded). 420 * @param path_length number of entries in @a path (or 0 if not recorded).
334 * @param path peers on the PUT path (or NULL if not recorded). 421 * @param path peers on the PUT path (or NULL if not recorded).
335 * @param desired_replication_level Desired replication level. 422 * note that the last signature will be all zeros as
423 * we did not forward and thus did not sign!
336 * @param exp Expiration time of the data. 424 * @param exp Expiration time of the data.
337 * @param key Key under which data is to be stored. 425 * @param key Key under which data is to be stored.
338 * @param data Pointer to the data carried. 426 * @param data Pointer to the data carried.
@@ -344,8 +432,9 @@ typedef void
344 enum GNUNET_BLOCK_Type type, 432 enum GNUNET_BLOCK_Type type,
345 uint32_t hop_count, 433 uint32_t hop_count,
346 uint32_t desired_replication_level, 434 uint32_t desired_replication_level,
435 const struct GNUNET_PeerIdentity *trunc_peer,
347 unsigned int path_length, 436 unsigned int path_length,
348 const struct GNUNET_PeerIdentity *path, 437 const struct GNUNET_DHT_PathElement *path,
349 struct GNUNET_TIME_Absolute exp, 438 struct GNUNET_TIME_Absolute exp,
350 const struct GNUNET_HashCode *key, 439 const struct GNUNET_HashCode *key,
351 const void *data, 440 const void *data,
@@ -385,6 +474,107 @@ void
385GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle); 474GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle);
386 475
387 476
477/**
478 * Convert a peer path to a human-readable string.
479 *
480 * @param path array of path elements to convert to a string
481 * @param path_len length of the @a path array
482 * @return string representing the array of @a pids
483 */
484char *
485GNUNET_DHT_pp2s (const struct GNUNET_DHT_PathElement *path,
486 unsigned int path_len);
487
488
489/**
490 * Verify signatures on a path consisting of @a put_path and @a get_path in
491 * reverse order (starting at the last element of the @a get_path). Note that
492 * the last signature on the path is never verified as that is the slot where
493 * our peer (@a me) would need to sign.
494 *
495 * @param data payload (the block)
496 * @param data_size number of bytes in @a data
497 * @param exp_time expiration time of @a data
498 * @param trunc_peer peer which signature was broken or where the path was truncated,
499 * NULL if path is not truncated
500 * @param get_path array of path elements to verify
501 * @param get_path_len length of the @a get_path array
502 * @param put_path array of path elements to verify
503 * @param put_path_len length of the @a put_path array
504 * @param me our own peer identity (needed to verify the last element)
505 * @return 0 on success, otherwise the index of
506 * the last path element that succeeded with verification;
507 * @a get_path_len + @a put_path_len if no signature was valid
508 */
509unsigned int
510GNUNET_DHT_verify_path (const void *data,
511 size_t data_size,
512 struct GNUNET_TIME_Absolute exp_time,
513 const struct GNUNET_PeerIdentity *trunc_peer,
514 const struct GNUNET_DHT_PathElement *put_path,
515 unsigned int put_path_len,
516 const struct GNUNET_DHT_PathElement *get_path,
517 unsigned int get_path_len,
518 const struct GNUNET_PeerIdentity *me);
519
520
521/**
522 * Handle to get a HELLO URL from the DHT for manual bootstrapping.
523 */
524struct GNUNET_DHT_HelloGetHandle;
525
526
527/**
528 * Signature called with the result of a HELLO GET operation.
529 *
530 * @param cls closure
531 * @param hello_url the resulting HELLO URL, NULL on error
532 */
533typedef void
534(*GNUNET_DHT_HelloGetCallback)(void *cls,
535 const char *hello_url);
536
537
538/**
539 * Obtain HELLO URL of the DHT identified by @a dht_handle.
540 *
541 * @param dht_handle DHT to query
542 * @param cb function to call with the result
543 * @param cb_cls closure for @a cb
544 * @return NULL on failure
545 */
546struct GNUNET_DHT_HelloGetHandle *
547GNUNET_DHT_hello_get (struct GNUNET_DHT_Handle *dht_handle,
548 GNUNET_DHT_HelloGetCallback cb,
549 void *cb_cls);
550
551
552/**
553 * Cancel hello get operation.
554 *
555 * @param[in] hgh operation to cancel.
556 */
557void
558GNUNET_DHT_hello_get_cancel (struct GNUNET_DHT_HelloGetHandle *hgh);
559
560
561/**
562 * Offer HELLO URL of the DHT identified by @a dht_handle.
563 * Callback may be invoked once, only way to cancel is to
564 * disconnect @a dht_handle.
565 *
566 * @param dht_handle DHT to query
567 * @param url URL with a HELLO to offer to the DHT
568 * @param cb function called when done
569 * @param cb_cls closure for @a cb
570 */
571void
572GNUNET_DHT_hello_offer (struct GNUNET_DHT_Handle *dht_handle,
573 const char *url,
574 GNUNET_SCHEDULER_TaskCallback cb,
575 void *cb_cls);
576
577
388#if 0 /* keep Emacsens' auto-indent happy */ 578#if 0 /* keep Emacsens' auto-indent happy */
389{ 579{
390#endif 580#endif
@@ -395,3 +585,7 @@ GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle);
395#endif 585#endif
396 586
397/** @} */ /* end of group dht */ 587/** @} */ /* end of group dht */
588
589/** @} */ /* end of group addition */
590
591/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_dhtu_plugin.h b/src/include/gnunet_dhtu_plugin.h
index e65318fb5..0503dda1c 100644
--- a/src/include/gnunet_dhtu_plugin.h
+++ b/src/include/gnunet_dhtu_plugin.h
@@ -27,6 +27,7 @@
27#ifndef PLUGIN_DHTU_H 27#ifndef PLUGIN_DHTU_H
28#define PLUGIN_DHTU_H 28#define PLUGIN_DHTU_H
29 29
30
30#include "gnunet_util_lib.h" 31#include "gnunet_util_lib.h"
31 32
32 33
@@ -57,38 +58,6 @@ struct GNUNET_DHTU_Target;
57 */ 58 */
58struct GNUNET_DHTU_PreferenceHandle; 59struct GNUNET_DHTU_PreferenceHandle;
59 60
60/**
61 * Opaque handle for a private key used by this underlay.
62 */
63struct GNUNET_DHTU_PrivateKey;
64
65/**
66 * Handle for a public key used by another peer. Note that
67 * the underlay used must be communicated separately.
68 */
69struct GNUNET_DHTU_PublicKey
70{
71 /**
72 * How long is the public key, in network byte order.
73 */
74 uint16_t size;
75
76 /* followed by size-2 bytes of the actual public key */
77};
78
79
80/**
81 * Hash used by the DHT for keys and peers.
82 */
83struct GNUNET_DHTU_Hash
84{
85
86 /**
87 * For now, use a 512 bit hash. (To be discussed).
88 */
89 struct GNUNET_HashCode hc;
90};
91
92 61
93/** 62/**
94 * The datastore service will pass a pointer to a struct 63 * The datastore service will pass a pointer to a struct
@@ -111,9 +80,6 @@ struct GNUNET_DHTU_PluginEnvironment
111 * Function to call with new addresses of this peer. 80 * Function to call with new addresses of this peer.
112 * 81 *
113 * @param cls the closure 82 * @param cls the closure
114 * @param my_id hash position of this address in the DHT
115 * @param pk private key of this peer used at @a address,
116 * pointer will remain valid until @e address_del_cb is called
117 * @param address address under which we are likely reachable, 83 * @param address address under which we are likely reachable,
118 * pointer will remain valid until @e address_del_cb is called; to be used for HELLOs. Example: "ip+udp://1.1.1.1:2086/" 84 * pointer will remain valid until @e address_del_cb is called; to be used for HELLOs. Example: "ip+udp://1.1.1.1:2086/"
119 * @param source handle for sending from this address, NULL if we can only receive 85 * @param source handle for sending from this address, NULL if we can only receive
@@ -121,8 +87,6 @@ struct GNUNET_DHTU_PluginEnvironment
121 */ 87 */
122 void 88 void
123 (*address_add_cb)(void *cls, 89 (*address_add_cb)(void *cls,
124 const struct GNUNET_DHTU_Hash *my_id,
125 const struct GNUNET_DHTU_PrivateKey *pk,
126 const char *address, 90 const char *address,
127 struct GNUNET_DHTU_Source *source, 91 struct GNUNET_DHTU_Source *source,
128 void **ctx); 92 void **ctx);
@@ -154,21 +118,19 @@ struct GNUNET_DHTU_PluginEnvironment
154 * that peer. 118 * that peer.
155 * 119 *
156 * @param cls the closure 120 * @param cls the closure
157 * @param pk public key of the target,
158 * pointer will remain valid until @e disconnect_cb is called
159 * @para peer_id hash position of the peer,
160 * pointer will remain valid until @e disconnect_cb is called
161 * @param target handle to the target, 121 * @param target handle to the target,
162 * pointer will remain valid until @e disconnect_cb is called 122 * pointer will remain valid until @e disconnect_cb is called
123 * @param pid peer identity,
124 * pointer will remain valid until @e disconnect_cb is called
163 * @param[out] ctx storage space for DHT to use in association with this target 125 * @param[out] ctx storage space for DHT to use in association with this target
164 */ 126 */
165 void 127 void
166 (*connect_cb)(void *cls, 128 (*connect_cb)(void *cls,
167 const struct GNUNET_DHTU_PublicKey *pk,
168 const struct GNUNET_DHTU_Hash *peer_id,
169 struct GNUNET_DHTU_Target *target, 129 struct GNUNET_DHTU_Target *target,
130 const struct GNUNET_PeerIdentity *pid,
170 void **ctx); 131 void **ctx);
171 132
133
172 /** 134 /**
173 * Function to call when we disconnected from a peer and can henceforth 135 * Function to call when we disconnected from a peer and can henceforth
174 * cannot transmit to that peer anymore. 136 * cannot transmit to that peer anymore.
@@ -209,50 +171,18 @@ struct GNUNET_DHTU_PluginFunctions
209 void *cls; 171 void *cls;
210 172
211 /** 173 /**
212 * Use our private key to sign a message.
213 *
214 * @param cls closure
215 * @param pk our private key to sign with
216 * @param purpose what to sign
217 * @param[out] signature, allocated on heap and returned
218 * @return -1 on error, otherwise number of bytes in @a sig
219 */
220 ssize_t
221 (*sign)(void *cls,
222 const struct GNUNET_DHTU_PrivateKey *pk,
223 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
224 void **sig);
225
226 /**
227 * Verify signature in @a sig over @a purpose.
228 *
229 * @param cls closure
230 * @param pk public key to verify signature of
231 * @param purpose what was being signed
232 * @param sig signature data
233 * @param sig_size number of bytes in @a sig
234 * @return #GNUNET_OK if signature is valid
235 * #GNUNET_NO if signatures are not supported
236 * #GNUNET_SYSERR if signature is invalid
237 */
238 enum GNUNET_GenericReturnValue
239 (*verify)(void *cls,
240 const struct GNUNET_DHTU_PublicKey *pk,
241 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
242 const void *sig,
243 size_t sig_size);
244
245
246 /**
247 * Request creation of a session with a peer at the given @a address. 174 * Request creation of a session with a peer at the given @a address.
248 * 175 *
249 * @param cls closure (internal context for the plugin) 176 * @param cls closure (internal context for the plugin)
250 * @param address target address to connect to 177 * @param pid target identity of the peer to connect to
178 * @param address target address URI to connect to
251 */ 179 */
252 void 180 void
253 (*try_connect) (void *cls, 181 (*try_connect) (void *cls,
182 const struct GNUNET_PeerIdentity *pid,
254 const char *address); 183 const char *address);
255 184
185
256 /** 186 /**
257 * Request underlay to keep the connection to @a target alive if possible. 187 * Request underlay to keep the connection to @a target alive if possible.
258 * Hold may be called multiple times to express a strong preference to 188 * Hold may be called multiple times to express a strong preference to
@@ -266,7 +196,7 @@ struct GNUNET_DHTU_PluginFunctions
266 struct GNUNET_DHTU_Target *target); 196 struct GNUNET_DHTU_Target *target);
267 197
268 /** 198 /**
269 * Do no long request underlay to keep the connection alive. 199 * Do no longer request underlay to keep the connection alive.
270 * 200 *
271 * @param cls closure 201 * @param cls closure
272 * @param target connection to keep alive 202 * @param target connection to keep alive
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h
index 7dfd9ccf1..2aec55851 100644
--- a/src/include/gnunet_disk_lib.h
+++ b/src/include/gnunet_disk_lib.h
@@ -18,6 +18,10 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup libgnunetutil
22 * Multi-function utilities library for GNUnet programs
23 * @{
24 *
21 * @author Christian Grothoff 25 * @author Christian Grothoff
22 * 26 *
23 * @file 27 * @file
@@ -27,6 +31,11 @@
27 * Disk IO APIs 31 * Disk IO APIs
28 * @{ 32 * @{
29 */ 33 */
34
35#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
36#error "Only <gnunet_util_lib.h> can be included directly."
37#endif
38
30#ifndef GNUNET_DISK_LIB_H 39#ifndef GNUNET_DISK_LIB_H
31#define GNUNET_DISK_LIB_H 40#define GNUNET_DISK_LIB_H
32 41
@@ -72,6 +81,7 @@ struct GNUNET_DISK_FileHandle
72 or unsigned long long, this IS platform dependent; 81 or unsigned long long, this IS platform dependent;
73 but "stdlib.h" should be portable 'enough' to be 82 but "stdlib.h" should be portable 'enough' to be
74 unconditionally available... */ 83 unconditionally available... */
84
75#include <stdlib.h> 85#include <stdlib.h>
76#include "gnunet_configuration_lib.h" 86#include "gnunet_configuration_lib.h"
77#include "gnunet_scheduler_lib.h" 87#include "gnunet_scheduler_lib.h"
@@ -670,7 +680,7 @@ GNUNET_DISK_directory_scan (const char *dir_name,
670 * Currently, the glob_pattern only supports asterisks in the last 680 * Currently, the glob_pattern only supports asterisks in the last
671 * path component. 681 * path component.
672 * 682 *
673 * @param glob_patterb the glob pattern to search for 683 * @param glob_pattern the glob pattern to search for
674 * @param callback the method to call for each file 684 * @param callback the method to call for each file
675 * @param callback_cls closure for @a callback 685 * @param callback_cls closure for @a callback
676 * @return the number of files found, -1 on error 686 * @return the number of files found, -1 on error
@@ -815,4 +825,6 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h);
815 825
816/** @} */ /* end of group */ 826/** @} */ /* end of group */
817 827
828/** @} */ /* end of group addition */
829
818/* end of gnunet_disk_lib.h */ 830/* end of gnunet_disk_lib.h */
diff --git a/src/include/gnunet_dns_service.h b/src/include/gnunet_dns_service.h
index 20f0f13ee..b5741a7e2 100644
--- a/src/include/gnunet_dns_service.h
+++ b/src/include/gnunet_dns_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup vpn_suite VPN services and libraries
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -33,6 +36,7 @@
33#ifndef GNUNET_DNS_SERVICE_H 36#ifndef GNUNET_DNS_SERVICE_H
34#define GNUNET_DNS_SERVICE_H 37#define GNUNET_DNS_SERVICE_H
35 38
39
36#include "gnunet_util_lib.h" 40#include "gnunet_util_lib.h"
37 41
38 42
@@ -191,3 +195,5 @@ GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *dh);
191#endif 195#endif
192 196
193/** @} */ /* end of group */ 197/** @} */ /* end of group */
198
199/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_dnsparser_lib.h b/src/include/gnunet_dnsparser_lib.h
index f77073264..9a84f346f 100644
--- a/src/include/gnunet_dnsparser_lib.h
+++ b/src/include/gnunet_dnsparser_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
25
21/** 26/**
27 * @addtogroup libgnunetutil
28 * @{
29 *
22 * @author Philipp Toelke 30 * @author Philipp Toelke
23 * @author Christian Grothoff 31 * @author Christian Grothoff
24 * 32 *
@@ -32,8 +40,6 @@
32#ifndef GNUNET_DNSPARSER_LIB_H 40#ifndef GNUNET_DNSPARSER_LIB_H
33#define GNUNET_DNSPARSER_LIB_H 41#define GNUNET_DNSPARSER_LIB_H
34 42
35#include "gnunet_util_lib.h"
36
37/** 43/**
38 * Maximum length of a label in DNS. 44 * Maximum length of a label in DNS.
39 */ 45 */
@@ -78,6 +84,7 @@
78#define GNUNET_DNSPARSER_TYPE_NSEC3 50 84#define GNUNET_DNSPARSER_TYPE_NSEC3 50
79#define GNUNET_DNSPARSER_TYPE_NSEC3PARAM 51 85#define GNUNET_DNSPARSER_TYPE_NSEC3PARAM 51
80#define GNUNET_DNSPARSER_TYPE_TLSA 52 86#define GNUNET_DNSPARSER_TYPE_TLSA 52
87#define GNUNET_DNSPARSER_TYPE_SMIMEA 53
81#define GNUNET_DNSPARSER_TYPE_HIP 55 88#define GNUNET_DNSPARSER_TYPE_HIP 55
82#define GNUNET_DNSPARSER_TYPE_CDS 59 89#define GNUNET_DNSPARSER_TYPE_CDS 59
83#define GNUNET_DNSPARSER_TYPE_CDNSKEY 60 90#define GNUNET_DNSPARSER_TYPE_CDNSKEY 60
@@ -172,6 +179,33 @@ struct GNUNET_DNSPARSER_SrvRecord
172 179
173 180
174/** 181/**
182 * Information from URI records (RFC 7553).
183 */
184struct GNUNET_DNSPARSER_UriRecord
185{
186 /**
187 * URI of the target,
188 * where the URI is as specified in RFC 3986.
189 */
190 char *target;
191
192 /**
193 * Preference for this entry (lower value is higher preference). Clients
194 * will contact hosts from the lowest-priority group first and fall back
195 * to higher priorities if the low-priority entries are unavailable.
196 */
197 uint16_t priority;
198
199 /**
200 * Relative weight for records with the same priority. Clients will use
201 * the hosts of the same (lowest) priority with a probability proportional
202 * to the weight given.
203 */
204 uint16_t weight;
205};
206
207
208/**
175 * DNS CERT types as defined in RFC 4398. 209 * DNS CERT types as defined in RFC 4398.
176 */ 210 */
177enum GNUNET_DNSPARSER_CertType 211enum GNUNET_DNSPARSER_CertType
@@ -473,6 +507,11 @@ struct GNUNET_DNSPARSER_Record
473 struct GNUNET_DNSPARSER_SrvRecord *srv; 507 struct GNUNET_DNSPARSER_SrvRecord *srv;
474 508
475 /** 509 /**
510 * URI data for URI records.
511 */
512 struct GNUNET_DNSPARSER_UriRecord *uri;
513
514 /**
476 * Raw data for all other types. 515 * Raw data for all other types.
477 */ 516 */
478 struct GNUNET_DNSPARSER_RawRecord raw; 517 struct GNUNET_DNSPARSER_RawRecord raw;
@@ -737,6 +776,25 @@ GNUNET_DNSPARSER_builder_add_srv (char *dst,
737 size_t *off, 776 size_t *off,
738 const struct GNUNET_DNSPARSER_SrvRecord *srv); 777 const struct GNUNET_DNSPARSER_SrvRecord *srv);
739 778
779
780/**
781 * Add an URI record to the UDP packet at the given location.
782 *
783 * @param dst where to write the URI record
784 * @param dst_len number of bytes in @a dst
785 * @param off pointer to offset where to write the URI information (increment by bytes used)
786 * can also change if there was an error
787 * @param uri URI information to write
788 * @return #GNUNET_SYSERR if @a uri is invalid
789 * #GNUNET_NO if @a uri did not fit
790 * #GNUNET_OK if @a uri was added to @a dst
791 */
792int
793GNUNET_DNSPARSER_builder_add_uri (char *dst,
794 size_t dst_len,
795 size_t *off,
796 const struct GNUNET_DNSPARSER_UriRecord *uri);
797
740/* ***************** low-level parsing API ******************** */ 798/* ***************** low-level parsing API ******************** */
741 799
742/** 800/**
@@ -847,6 +905,21 @@ GNUNET_DNSPARSER_parse_srv (const char *udp_payload,
847 size_t udp_payload_length, 905 size_t udp_payload_length,
848 size_t *off); 906 size_t *off);
849 907
908
909/**
910 * Parse a DNS URI record.
911 *
912 * @param udp_payload reference to UDP packet
913 * @param udp_payload_length length of @a udp_payload
914 * @param off pointer to the offset of the query to parse in the URI record (to be
915 * incremented by the size of the record), unchanged on error
916 * @return the parsed URI record, NULL on error
917 */
918struct GNUNET_DNSPARSER_UriRecord *
919GNUNET_DNSPARSER_parse_uri (const char *udp_payload,
920 size_t udp_payload_length,
921 size_t *off);
922
850/* ***************** low-level duplication API ******************** */ 923/* ***************** low-level duplication API ******************** */
851 924
852/** 925/**
@@ -903,6 +976,16 @@ GNUNET_DNSPARSER_duplicate_srv_record (const struct
903 GNUNET_DNSPARSER_SrvRecord *r); 976 GNUNET_DNSPARSER_SrvRecord *r);
904 977
905 978
979/**
980 * Duplicate (deep-copy) the given DNS record
981 *
982 * @param r the record
983 * @return the newly allocated record
984 */
985struct GNUNET_DNSPARSER_UriRecord *
986GNUNET_DNSPARSER_duplicate_uri_record (const struct
987 GNUNET_DNSPARSER_UriRecord *r);
988
906/* ***************** low-level deallocation API ******************** */ 989/* ***************** low-level deallocation API ******************** */
907 990
908/** 991/**
@@ -933,6 +1016,15 @@ GNUNET_DNSPARSER_free_srv (struct GNUNET_DNSPARSER_SrvRecord *srv);
933 1016
934 1017
935/** 1018/**
1019 * Free URI information record.
1020 *
1021 * @param uri record to free
1022 */
1023void
1024GNUNET_DNSPARSER_free_uri (struct GNUNET_DNSPARSER_UriRecord *uri);
1025
1026
1027/**
936 * Free SOA information record. 1028 * Free SOA information record.
937 * 1029 *
938 * @param soa record to free 1030 * @param soa record to free
@@ -978,3 +1070,5 @@ GNUNET_DNSPARSER_hex_to_bin (const char *hex,
978#endif 1070#endif
979 1071
980/** @} */ /* end of group */ 1072/** @} */ /* end of group */
1073
1074/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_dnsstub_lib.h b/src/include/gnunet_dnsstub_lib.h
index 4e93105bb..fa5151a8c 100644
--- a/src/include/gnunet_dnsstub_lib.h
+++ b/src/include/gnunet_dnsstub_lib.h
@@ -18,7 +18,14 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * @{
28 *
22 * @author Christian Grothoff 29 * @author Christian Grothoff
23 * 30 *
24 * @file 31 * @file
@@ -31,6 +38,7 @@
31#ifndef GNUNET_DNSSTUB_LIB_H 38#ifndef GNUNET_DNSSTUB_LIB_H
32#define GNUNET_DNSSTUB_LIB_H 39#define GNUNET_DNSSTUB_LIB_H
33 40
41
34#include "gnunet_util_lib.h" 42#include "gnunet_util_lib.h"
35 43
36/** 44/**
@@ -86,7 +94,7 @@ GNUNET_DNSSTUB_add_dns_sa (struct GNUNET_DNSSTUB_Context *ctx,
86 * Only effective for requests issued after this call. 94 * Only effective for requests issued after this call.
87 * 95 *
88 * @param ctx resolver context to modify 96 * @param ctx resolver context to modify
89 * @param retry_frequ how long to wait between retries 97 * @param retry_freq how long to wait between retries
90 */ 98 */
91void 99void
92GNUNET_DNSSTUB_set_retry (struct GNUNET_DNSSTUB_Context *ctx, 100GNUNET_DNSSTUB_set_retry (struct GNUNET_DNSSTUB_Context *ctx,
@@ -147,3 +155,5 @@ GNUNET_DNSSTUB_resolve_cancel (struct GNUNET_DNSSTUB_RequestSocket *rs);
147#endif 155#endif
148 156
149/** @} */ /* end of group */ 157/** @} */ /* end of group */
158
159/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_error_codes.h b/src/include/gnunet_error_codes.h
new file mode 100644
index 000000000..aa897afe0
--- /dev/null
+++ b/src/include/gnunet_error_codes.h
@@ -0,0 +1,242 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012-2022 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20 /**
21 * @file include/taler_error_codes.h
22 * @brief GNUnet error codes, generated via https://gana.gnunet.org/
23 *
24 * Do NOT edit this file, it is generated!
25 */
26#ifndef GNUNET_ERROR_CODES_H
27#define GNUNET_ERROR_CODES_H
28
29#ifdef __cplusplus
30extern "C" {
31#if 0 /* keep Emacsens' auto-indent happy */
32}
33#endif
34#endif
35
36#include <limits.h>
37
38
39/**
40 * Taler error codes.
41 */
42enum GNUNET_ErrorCode
43{
44
45
46 /**
47 * No error (success).
48 * Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0).
49 */
50 GNUNET_EC_NONE = 0,
51
52
53 /**
54 * Unknown and unspecified error.
55 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
56 */
57 GNUNET_EC_UNKNOWN = 1,
58
59
60 /**
61 * Communication with service failed.
62 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
63 */
64 GNUNET_EC_SERVICE_COMMUNICATION_FAILED = 101,
65
66
67 /**
68 * Ego not found.
69 * Returned with an HTTP status code of #MHD_HTTP_NOT_FOUND (404).
70 */
71 GNUNET_EC_IDENTITY_NOT_FOUND = 200,
72
73
74 /**
75 * Identifier already in use for another ego.
76 * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409).
77 */
78 GNUNET_EC_IDENTITY_NAME_CONFLICT = 201,
79
80
81 /**
82 * The given ego is invalid or malformed.
83 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
84 */
85 GNUNET_EC_IDENTITY_INVALID = 202,
86
87
88 /**
89 * Unknown namestore error.
90 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
91 */
92 GNUNET_EC_NAMESTORE_UNKNOWN = 5000,
93
94
95 /**
96 * Zone iteration failed.
97 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
98 */
99 GNUNET_EC_NAMESTORE_ITERATION_FAILED = 5001,
100
101
102 /**
103 * Zone not found.
104 * Returned with an HTTP status code of #MHD_HTTP_NOT_FOUND (404).
105 */
106 GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND = 5002,
107
108
109 /**
110 * Record not found.
111 * Returned with an HTTP status code of #MHD_HTTP_NOT_FOUND (404).
112 */
113 GNUNET_EC_NAMESTORE_RECORD_NOT_FOUND = 5003,
114
115
116 /**
117 * Zone iteration failed.
118 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
119 */
120 GNUNET_EC_NAMESTORE_RECORD_DELETE_FAILED = 5004,
121
122
123 /**
124 * Zone does not contain any records.
125 * Returned with an HTTP status code of #MHD_HTTP_NOT_FOUND (404).
126 */
127 GNUNET_EC_NAMESTORE_ZONE_EMPTY = 5005,
128
129
130 /**
131 * Failed to lookup record.
132 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
133 */
134 GNUNET_EC_NAMESTORE_LOOKUP_ERROR = 5006,
135
136
137 /**
138 * No records given.
139 * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400).
140 */
141 GNUNET_EC_NAMESTORE_NO_RECORDS_GIVEN = 5007,
142
143
144 /**
145 * Record data invalid.
146 * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400).
147 */
148 GNUNET_EC_NAMESTORE_RECORD_DATA_INVALID = 5008,
149
150
151 /**
152 * No label given.
153 * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400).
154 */
155 GNUNET_EC_NAMESTORE_NO_LABEL_GIVEN = 5009,
156
157
158 /**
159 * No results given.
160 * Returned with an HTTP status code of #MHD_HTTP_NOT_FOUND (404).
161 */
162 GNUNET_EC_NAMESTORE_NO_RESULTS = 5010,
163
164
165 /**
166 * Record already exists.
167 * Returned with an HTTP status code of #MHD_HTTP_CONFLICT (409).
168 */
169 GNUNET_EC_NAMESTORE_RECORD_EXISTS = 5011,
170
171
172 /**
173 * Record size exceeds maximum limit.
174 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
175 */
176 GNUNET_EC_NAMESTORE_RECORD_TOO_BIG = 5012,
177
178
179 /**
180 * There was an error in the database backend.
181 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
182 */
183 GNUNET_EC_NAMESTORE_BACKEND_FAILED = 5013,
184
185
186 /**
187 * Failed to store the given records.
188 * Returned with an HTTP status code of #MHD_HTTP_INTERNAL_SERVER_ERROR (500).
189 */
190 GNUNET_EC_NAMESTORE_STORE_FAILED = 5014,
191
192
193 /**
194 * Label invalid or malformed.
195 * Returned with an HTTP status code of #MHD_HTTP_BAD_REQUEST (400).
196 */
197 GNUNET_EC_NAMESTORE_LABEL_INVALID = 5015,
198
199
200};
201
202
203/**
204 * Returns a hint for a given error code.
205 *
206 * @param ec the error code.
207 * @return the hint if it could be found, otherwise "<no hint found>"
208 */
209const char *
210GNUNET_ErrorCode_get_hint (enum GNUNET_ErrorCode ec);
211
212
213/**
214 * Return HTTP status for a given error code.
215 *
216 * @param ec the error code.
217 * @return the HTTP status code for the given @a ec, UINT_MAX if not found
218 */
219unsigned int
220GNUNET_ErrorCode_get_http_status (enum GNUNET_ErrorCode ec);
221
222
223/**
224 * Return HTTP status for a given error code that is guaranteed
225 * to work (no corner cases).
226 *
227 * @param ec the error code.
228 * @return the HTTP status code for the given @a ec, 500 if
229 * the @a ec is not found or is a client-side code
230 */
231unsigned int
232GNUNET_ErrorCode_get_http_status_safe (enum GNUNET_ErrorCode ec);
233
234
235#if 0 /* keep Emacsens' auto-indent happy */
236{
237#endif
238#ifdef __cplusplus
239}
240#endif
241
242#endif
diff --git a/src/include/gnunet_fragmentation_lib.h b/src/include/gnunet_fragmentation_lib.h
deleted file mode 100644
index c964b5434..000000000
--- a/src/include/gnunet_fragmentation_lib.h
+++ /dev/null
@@ -1,230 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2009, 2011, 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @author Christian Grothoff
22 *
23 * @file
24 * Library to help fragment messages
25 *
26 * @defgroup fragmentation Fragmentation library
27 * Library to help fragment messages
28 * @{
29 *
30 * @todo Consider additional flow-control for sending from
31 * fragmentation based on continuations.
32 */
33
34#ifndef GNUNET_FRAGMENTATION_LIB_H
35#define GNUNET_FRAGMENTATION_LIB_H
36
37#include "gnunet_util_lib.h"
38#include "gnunet_bandwidth_lib.h"
39#include "gnunet_statistics_service.h"
40
41#ifdef __cplusplus
42extern "C"
43{
44#if 0 /* keep Emacsens' auto-indent happy */
45}
46#endif
47#endif
48
49
50/**
51 * Fragmentation context.
52 */
53struct GNUNET_FRAGMENT_Context;
54
55
56/**
57 * Function that is called with messages created by the fragmentation
58 * module. In the case of the 'proc' callback of the
59 * #GNUNET_FRAGMENT_context_create() function, this function must
60 * eventually call #GNUNET_FRAGMENT_context_transmission_done().
61 *
62 * @param cls closure
63 * @param msg the message that was created
64 */
65typedef void
66(*GNUNET_FRAGMENT_MessageProcessor) (void *cls,
67 const struct GNUNET_MessageHeader *msg);
68
69
70/**
71 * Create a fragmentation context for the given message.
72 * Fragments the message into fragments of size @a mtu or
73 * less. Calls @a proc on each un-acknowledged fragment,
74 * using both the expected @a msg_delay between messages and
75 * acknowledgements and the given @a tracker to guide the
76 * frequency of calls to @a proc.
77 *
78 * @param stats statistics context
79 * @param mtu the maximum message size for each fragment
80 * @param tracker bandwidth tracker to use for flow control (can be NULL)
81 * @param msg_delay initial delay to insert between fragment transmissions
82 * based on previous messages
83 * @param ack_delay expected delay between fragment transmission
84 * and ACK based on previous messages
85 * @param msg the message to fragment
86 * @param proc function to call for each fragment to transmit
87 * @param proc_cls closure for proc
88 * @return the fragmentation context
89 */
90struct GNUNET_FRAGMENT_Context *
91GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
92 uint16_t mtu,
93 struct GNUNET_BANDWIDTH_Tracker *tracker,
94 struct GNUNET_TIME_Relative msg_delay,
95 struct GNUNET_TIME_Relative ack_delay,
96 const struct GNUNET_MessageHeader *msg,
97 GNUNET_FRAGMENT_MessageProcessor proc,
98 void *proc_cls);
99
100
101/**
102 * Continuation to call from the 'proc' function after the fragment
103 * has been transmitted (and hence the next fragment can now be
104 * given to proc).
105 *
106 * @param fc fragmentation context
107 */
108void
109GNUNET_FRAGMENT_context_transmission_done (struct GNUNET_FRAGMENT_Context *fc);
110
111
112/**
113 * Process an acknowledgement message we got from the other
114 * side (to control re-transmits).
115 *
116 * @param fc fragmentation context
117 * @param msg acknowledgement message we received
118 * @return #GNUNET_OK if this ack completes the work of the 'fc'
119 * (all fragments have been received);
120 * #GNUNET_NO if more messages are pending
121 * #GNUNET_SYSERR if this ack is not valid for this fc
122 */
123int
124GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
125 const struct GNUNET_MessageHeader *msg);
126
127
128/**
129 * Destroy the given fragmentation context (stop calling 'proc', free
130 * resources).
131 *
132 * @param fc fragmentation context
133 * @param msg_delay where to store average delay between individual message transmissions the
134 * last message (OUT only)
135 * @param ack_delay where to store average delay between transmission and ACK for the
136 * last message, set to FOREVER if the message was not fully transmitted (OUT only)
137 */
138void
139GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc,
140 struct GNUNET_TIME_Relative *msg_delay,
141 struct GNUNET_TIME_Relative *ack_delay);
142
143
144/**
145 * Convert an ACK message to a printable format suitable for logging.
146 *
147 * @param ack message to print
148 * @return ack in human-readable format
149 */
150const char *
151GNUNET_FRAGMENT_print_ack (const struct GNUNET_MessageHeader *ack);
152
153
154/**
155 * Defragmentation context (one per connection).
156 */
157struct GNUNET_DEFRAGMENT_Context;
158
159
160/**
161 * Function that is called with acknowledgement messages created by
162 * the fragmentation module. Acknowledgements are cumulative,
163 * so it is OK to only transmit the 'latest' ack message for the same
164 * message ID.
165 *
166 * @param cls closure
167 * @param id unique message ID (modulo collisions)
168 * @param msg the message that was created
169 */
170typedef void
171(*GNUNET_DEFRAGMENT_AckProcessor) (void *cls,
172 uint32_t id,
173 const struct GNUNET_MessageHeader *msg);
174
175
176/**
177 * Create a defragmentation context.
178 *
179 * @param stats statistics context
180 * @param mtu the maximum message size for each fragment
181 * @param num_msgs how many fragmented messages
182 * to we defragment at most at the same time?
183 * @param cls closure for @a proc and @a ackp
184 * @param proc function to call with defragmented messages
185 * @param ackp function to call with acknowledgements (to send
186 * back to the other side)
187 * @return the defragmentation context
188 */
189struct GNUNET_DEFRAGMENT_Context *
190GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
191 uint16_t mtu,
192 unsigned int num_msgs,
193 void *cls,
194 GNUNET_FRAGMENT_MessageProcessor proc,
195 GNUNET_DEFRAGMENT_AckProcessor ackp);
196
197
198/**
199 * Destroy the given defragmentation context.
200 *
201 * @param dc defragmentation context
202 */
203void
204GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc);
205
206
207/**
208 * We have received a fragment. Process it.
209 *
210 * @param dc the context
211 * @param msg the message that was received
212 * @return #GNUNET_OK on success,
213 * #GNUNET_NO if this was a duplicate,
214 * #GNUNET_SYSERR on error
215 */
216int
217GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
218 const struct GNUNET_MessageHeader *msg);
219
220
221#if 0 /* keep Emacsens' auto-indent happy */
222{
223#endif
224#ifdef __cplusplus
225}
226#endif
227
228#endif
229
230/** @} */ /* end of group */
diff --git a/src/include/gnunet_friends_lib.h b/src/include/gnunet_friends_lib.h
deleted file mode 100644
index d591ea082..000000000
--- a/src/include/gnunet_friends_lib.h
+++ /dev/null
@@ -1,118 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2013 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 *
24 * @file
25 * Library to read and write the FRIENDS file
26 *
27 * @defgroup friends Friends library
28 * Library to read and write the FRIENDS file
29 * @{
30 */
31#ifndef GNUNET_FRIENDS_LIB_H
32#define GNUNET_FRIENDS_LIB_H
33
34#ifdef __cplusplus
35extern "C"
36{
37#if 0 /* keep Emacsens' auto-indent happy */
38}
39#endif
40#endif
41
42#include "gnunet_util_lib.h"
43
44
45/**
46 * Signature of a function called on each friend found.
47 *
48 * @param cls closure
49 * @param friend_id peer identity of the friend
50 */
51typedef void (*GNUNET_FRIENDS_Callback)(void *cls,
52 const struct
53 GNUNET_PeerIdentity *friend_id);
54
55
56/**
57 * Parse the FRIENDS file.
58 *
59 * @param cfg our configuration
60 * @param cb function to call on each friend found
61 * @param cb_cls closure for @a cb
62 * @return #GNUNET_OK on success, #GNUNET_SYSERR on parsing errors
63 */
64int
65GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg,
66 GNUNET_FRIENDS_Callback cb,
67 void *cb_cls);
68
69
70/**
71 * Handle for writing a friends file.
72 */
73struct GNUNET_FRIENDS_Writer;
74
75
76/**
77 * Start writing a fresh FRIENDS file. Will make a backup of the
78 * old one.
79 *
80 * @param cfg configuration to use.
81 * @return NULL on error
82 */
83struct GNUNET_FRIENDS_Writer *
84GNUNET_FRIENDS_write_start (const struct GNUNET_CONFIGURATION_Handle *cfg);
85
86
87/**
88 * Finish writing out the friends file.
89 *
90 * @param w write handle
91 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
92 */
93int
94GNUNET_FRIENDS_write_stop (struct GNUNET_FRIENDS_Writer *w);
95
96
97/**
98 * Add a friend to the friends file.
99 *
100 * @param w write handle
101 * @param friend_id friend to add
102 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
103 */
104int
105GNUNET_FRIENDS_write (struct GNUNET_FRIENDS_Writer *w,
106 const struct GNUNET_PeerIdentity *friend_id);
107
108
109#if 0 /* keep Emacsens' auto-indent happy */
110{
111#endif
112#ifdef __cplusplus
113}
114#endif
115
116#endif
117
118/** @} */ /* end of group */
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h
index 686035e2c..a05e07ac5 100644
--- a/src/include/gnunet_fs_service.h
+++ b/src/include/gnunet_fs_service.h
@@ -18,6 +18,9 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup fs_l2 File sharing and support services/libraries
22 * @{
23 *
21 * @author Christian Grothoff 24 * @author Christian Grothoff
22 * 25 *
23 * @file 26 * @file
@@ -33,6 +36,8 @@
33#ifndef GNUNET_FS_LIB_H 36#ifndef GNUNET_FS_LIB_H
34#define GNUNET_FS_LIB_H 37#define GNUNET_FS_LIB_H
35 38
39
40#include "gnunet_common.h"
36#include "gnunet_util_lib.h" 41#include "gnunet_util_lib.h"
37 42
38#ifdef __cplusplus 43#ifdef __cplusplus
@@ -66,6 +71,106 @@ extern "C"
66 */ 71 */
67#define GNUNET_FS_VERSION 0x00090300 72#define GNUNET_FS_VERSION 0x00090300
68 73
74#if GNUNET_FS_EXTRACTOR_ENABLED
75
76#include <extractor.h>
77
78#else
79
80/* definitions from extractor.h we need for the build */
81
82/**
83 * Enumeration defining various sources of keywords. See also
84 * http://dublincore.org/documents/1998/09/dces/
85 */
86enum EXTRACTOR_MetaType
87{
88 EXTRACTOR_METATYPE_RESERVED = 0,
89 EXTRACTOR_METATYPE_MIMETYPE = 1,
90 EXTRACTOR_METATYPE_FILENAME = 2,
91 EXTRACTOR_METATYPE_COMMENT = 3,
92 EXTRACTOR_METATYPE_TITLE = 4,
93 EXTRACTOR_METATYPE_BOOK_TITLE = 5,
94 EXTRACTOR_METATYPE_JOURNAL_NAME = 8,
95 EXTRACTOR_METATYPE_AUTHOR_NAME = 13,
96 EXTRACTOR_METATYPE_PUBLICATION_DATE = 24,
97 EXTRACTOR_METATYPE_URL = 29,
98 EXTRACTOR_METATYPE_URI = 30,
99 EXTRACTOR_METATYPE_ISRC = 31,
100 EXTRACTOR_METATYPE_UNKNOWN = 45,
101 EXTRACTOR_METATYPE_DESCRIPTION = 46,
102 EXTRACTOR_METATYPE_KEYWORDS = 49,
103 EXTRACTOR_METATYPE_SUBJECT = 52,
104 EXTRACTOR_METATYPE_PACKAGE_NAME = 69,
105 EXTRACTOR_METATYPE_THUMBNAIL = 114,
106 EXTRACTOR_METATYPE_ALBUM = 129,
107 EXTRACTOR_METATYPE_ARTIST = 130,
108 EXTRACTOR_METATYPE_ORIGINAL_TITLE = 162,
109 EXTRACTOR_METATYPE_GNUNET_FULL_DATA = 174,
110 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME = 180,
111};
112
113/**
114 * Format in which the extracted meta data is presented.
115 */
116enum EXTRACTOR_MetaFormat
117{
118 /**
119 * Format is unknown.
120 */
121 EXTRACTOR_METAFORMAT_UNKNOWN = 0,
122
123 /**
124 * 0-terminated, UTF-8 encoded string. "data_len"
125 * is strlen(data)+1.
126 */
127 EXTRACTOR_METAFORMAT_UTF8 = 1,
128
129 /**
130 * Some kind of binary format, see given Mime type.
131 */
132 EXTRACTOR_METAFORMAT_BINARY = 2,
133
134 /**
135 * 0-terminated string. The specific encoding is unknown.
136 * "data_len" is strlen (data)+1.
137 */
138 EXTRACTOR_METAFORMAT_C_STRING = 3
139};
140
141
142/**
143 * Type of a function that libextractor calls for each
144 * meta data item found.
145 *
146 * @param cls closure (user-defined)
147 * @param plugin_name name of the plugin that produced this value;
148 * special values can be used (e.g. '&lt;zlib&gt;' for zlib being
149 * used in the main libextractor library and yielding
150 * meta data).
151 * @param type libextractor-type describing the meta data
152 * @param format basic format information about @a data
153 * @param data_mime_type mime-type of @a data (not of the original file);
154 * can be NULL (if mime-type is not known)
155 * @param data actual meta-data found
156 * @param data_len number of bytes in @a data
157 * @return 0 to continue extracting, 1 to abort
158 */
159typedef int (*EXTRACTOR_MetaDataProcessor) (void *cls,
160 const char *plugin_name,
161 enum EXTRACTOR_MetaType type,
162 enum EXTRACTOR_MetaFormat format,
163 const char *data_mime_type,
164 const char *data,
165 size_t data_len);
166
167#endif
168
169#ifndef EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME
170/* hack for LE < 0.6.3 */
171#define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME 180
172#endif
173
69 174
70/* ******************** URI API *********************** */ 175/* ******************** URI API *********************** */
71 176
@@ -88,6 +193,12 @@ extern "C"
88 */ 193 */
89struct GNUNET_FS_Uri; 194struct GNUNET_FS_Uri;
90 195
196/**
197 * @ingroup metadata
198 * Meta data to associate with a file, directory or namespace.
199 */
200struct GNUNET_FS_MetaData;
201
91 202
92/** 203/**
93 * Iterator over keywords 204 * Iterator over keywords
@@ -108,7 +219,7 @@ typedef int
108 * into HashMaps. The key may change between FS implementations. 219 * into HashMaps. The key may change between FS implementations.
109 * 220 *
110 * @param uri uri to convert to a unique key 221 * @param uri uri to convert to a unique key
111 * @param key wherer to store the unique key 222 * @param key where to store the unique key
112 * @return #GNUNET_OK on success 223 * @return #GNUNET_OK on success
113 */ 224 */
114int 225int
@@ -414,6 +525,17 @@ GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
414 525
415 526
416/** 527/**
528 * What is the hash of the original file's content
529 * that this URI refers to?
530 *
531 * @param uri the CHK URI to inspect
532 * @return hash of the file as specified in the CHK URI
533 */
534const struct GNUNET_HashCode*
535GNUNET_FS_uri_chk_get_file_hash (const struct GNUNET_FS_Uri *uri);
536
537
538/**
417 * Is this a location URI? 539 * Is this a location URI?
418 * 540 *
419 * @param uri the uri to check 541 * @param uri the uri to check
@@ -432,7 +554,7 @@ GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
432 * @return NULL on error, otherwise a KSK URI 554 * @return NULL on error, otherwise a KSK URI
433 */ 555 */
434struct GNUNET_FS_Uri * 556struct GNUNET_FS_Uri *
435GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData 557GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_FS_MetaData
436 *md); 558 *md);
437 559
438 560
@@ -461,14 +583,14 @@ GNUNET_FS_GETOPT_KEYWORDS (char shortName,
461 * @param name long name of the option 583 * @param name long name of the option
462 * @param argumentHelp help text for the option argument 584 * @param argumentHelp help text for the option argument
463 * @param description long help text for the option 585 * @param description long help text for the option
464 * @param[out] metadata set to the desired value 586 * @param[out] meta metadata set to the desired value
465 */ 587 */
466struct GNUNET_GETOPT_CommandLineOption 588struct GNUNET_GETOPT_CommandLineOption
467GNUNET_FS_GETOPT_METADATA (char shortName, 589GNUNET_FS_GETOPT_METADATA (char shortName,
468 const char *name, 590 const char *name,
469 const char *argumentHelp, 591 const char *argumentHelp,
470 const char *description, 592 const char *description,
471 struct GNUNET_CONTAINER_MetaData **meta); 593 struct GNUNET_FS_MetaData **meta);
472 594
473/** 595/**
474 * Command-line option parser function that allows the user to specify 596 * Command-line option parser function that allows the user to specify
@@ -477,7 +599,7 @@ GNUNET_FS_GETOPT_METADATA (char shortName,
477 * the metadata must be passed as the "scls" argument. 599 * the metadata must be passed as the "scls" argument.
478 * 600 *
479 * @param ctx command line processor context 601 * @param ctx command line processor context
480 * @param scls must be of type `struct GNUNET_CONTAINER_MetaData **` 602 * @param scls must be of type `struct GNUNET_FS_MetaData **`
481 * @param option name of the option (typically 'k') 603 * @param option name of the option (typically 'k')
482 * @param value command line argument given 604 * @param value command line argument given
483 * @return #GNUNET_OK on success 605 * @return #GNUNET_OK on success
@@ -1095,7 +1217,7 @@ struct GNUNET_FS_ProgressInfo
1095 /** 1217 /**
1096 * Known metadata for the download. 1218 * Known metadata for the download.
1097 */ 1219 */
1098 const struct GNUNET_CONTAINER_MetaData *meta; 1220 const struct GNUNET_FS_MetaData *meta;
1099 } start; 1221 } start;
1100 1222
1101 /** 1223 /**
@@ -1107,7 +1229,7 @@ struct GNUNET_FS_ProgressInfo
1107 /** 1229 /**
1108 * Known metadata for the download. 1230 * Known metadata for the download.
1109 */ 1231 */
1110 const struct GNUNET_CONTAINER_MetaData *meta; 1232 const struct GNUNET_FS_MetaData *meta;
1111 1233
1112 /** 1234 /**
1113 * Error message, NULL if we have not encountered any error yet. 1235 * Error message, NULL if we have not encountered any error yet.
@@ -1192,7 +1314,7 @@ struct GNUNET_FS_ProgressInfo
1192 /** 1314 /**
1193 * Metadata for the search result. 1315 * Metadata for the search result.
1194 */ 1316 */
1195 const struct GNUNET_CONTAINER_MetaData *meta; 1317 const struct GNUNET_FS_MetaData *meta;
1196 1318
1197 /** 1319 /**
1198 * URI for the search result. 1320 * URI for the search result.
@@ -1220,7 +1342,7 @@ struct GNUNET_FS_ProgressInfo
1220 /** 1342 /**
1221 * Metadata for the search result. 1343 * Metadata for the search result.
1222 */ 1344 */
1223 const struct GNUNET_CONTAINER_MetaData *meta; 1345 const struct GNUNET_FS_MetaData *meta;
1224 1346
1225 /** 1347 /**
1226 * URI for the search result. 1348 * URI for the search result.
@@ -1267,7 +1389,7 @@ struct GNUNET_FS_ProgressInfo
1267 /** 1389 /**
1268 * Metadata for the search result. 1390 * Metadata for the search result.
1269 */ 1391 */
1270 const struct GNUNET_CONTAINER_MetaData *meta; 1392 const struct GNUNET_FS_MetaData *meta;
1271 1393
1272 /** 1394 /**
1273 * URI for the search result. 1395 * URI for the search result.
@@ -1319,7 +1441,7 @@ struct GNUNET_FS_ProgressInfo
1319 /** 1441 /**
1320 * Metadata for the search result. 1442 * Metadata for the search result.
1321 */ 1443 */
1322 const struct GNUNET_CONTAINER_MetaData *meta; 1444 const struct GNUNET_FS_MetaData *meta;
1323 1445
1324 /** 1446 /**
1325 * URI for the search result. 1447 * URI for the search result.
@@ -1347,7 +1469,7 @@ struct GNUNET_FS_ProgressInfo
1347 /** 1469 /**
1348 * Metadata for the search result. 1470 * Metadata for the search result.
1349 */ 1471 */
1350 const struct GNUNET_CONTAINER_MetaData *meta; 1472 const struct GNUNET_FS_MetaData *meta;
1351 1473
1352 /** 1474 /**
1353 * URI for the search result. 1475 * URI for the search result.
@@ -1402,7 +1524,7 @@ struct GNUNET_FS_ProgressInfo
1402 /** 1524 /**
1403 * Metadata for the namespace. 1525 * Metadata for the namespace.
1404 */ 1526 */
1405 const struct GNUNET_CONTAINER_MetaData *meta; 1527 const struct GNUNET_FS_MetaData *meta;
1406 1528
1407 /** 1529 /**
1408 * Public key of the namespace. 1530 * Public key of the namespace.
@@ -1702,7 +1824,7 @@ typedef int
1702(*GNUNET_FS_FileInformationProcessor) (void *cls, 1824(*GNUNET_FS_FileInformationProcessor) (void *cls,
1703 struct GNUNET_FS_FileInformation *fi, 1825 struct GNUNET_FS_FileInformation *fi,
1704 uint64_t length, 1826 uint64_t length,
1705 struct GNUNET_CONTAINER_MetaData *meta, 1827 struct GNUNET_FS_MetaData *meta,
1706 struct GNUNET_FS_Uri **uri, 1828 struct GNUNET_FS_Uri **uri,
1707 struct GNUNET_FS_BlockOptions *bo, 1829 struct GNUNET_FS_BlockOptions *bo,
1708 int *do_index, 1830 int *do_index,
@@ -1729,7 +1851,8 @@ GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1729 * @return "filename" field of the structure (can be NULL) 1851 * @return "filename" field of the structure (can be NULL)
1730 */ 1852 */
1731const char * 1853const char *
1732GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s); 1854GNUNET_FS_file_information_get_filename (const struct
1855 GNUNET_FS_FileInformation *s);
1733 1856
1734 1857
1735/** 1858/**
@@ -1766,7 +1889,7 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
1766 const struct 1889 const struct
1767 GNUNET_FS_Uri *keywords, 1890 GNUNET_FS_Uri *keywords,
1768 const struct 1891 const struct
1769 GNUNET_CONTAINER_MetaData *meta, 1892 GNUNET_FS_MetaData *meta,
1770 int do_index, 1893 int do_index,
1771 const struct 1894 const struct
1772 GNUNET_FS_BlockOptions *bo); 1895 GNUNET_FS_BlockOptions *bo);
@@ -1796,7 +1919,7 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
1796 const struct 1919 const struct
1797 GNUNET_FS_Uri *keywords, 1920 GNUNET_FS_Uri *keywords,
1798 const struct 1921 const struct
1799 GNUNET_CONTAINER_MetaData *meta, 1922 GNUNET_FS_MetaData *meta,
1800 int do_index, 1923 int do_index,
1801 const struct 1924 const struct
1802 GNUNET_FS_BlockOptions *bo); 1925 GNUNET_FS_BlockOptions *bo);
@@ -1855,7 +1978,7 @@ GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
1855 const struct GNUNET_FS_Uri 1978 const struct GNUNET_FS_Uri
1856 *keywords, 1979 *keywords,
1857 const struct 1980 const struct
1858 GNUNET_CONTAINER_MetaData *meta, 1981 GNUNET_FS_MetaData *meta,
1859 int do_index, 1982 int do_index,
1860 const struct 1983 const struct
1861 GNUNET_FS_BlockOptions *bo); 1984 GNUNET_FS_BlockOptions *bo);
@@ -1879,7 +2002,7 @@ GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
1879 const struct GNUNET_FS_Uri 2002 const struct GNUNET_FS_Uri
1880 *keywords, 2003 *keywords,
1881 const struct 2004 const struct
1882 GNUNET_CONTAINER_MetaData 2005 GNUNET_FS_MetaData
1883 *meta, 2006 *meta,
1884 const struct 2007 const struct
1885 GNUNET_FS_BlockOptions *bo, 2008 GNUNET_FS_BlockOptions *bo,
@@ -2038,7 +2161,7 @@ struct GNUNET_FS_PublishKskContext;
2038struct GNUNET_FS_PublishKskContext * 2161struct GNUNET_FS_PublishKskContext *
2039GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, 2162GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2040 const struct GNUNET_FS_Uri *ksk_uri, 2163 const struct GNUNET_FS_Uri *ksk_uri,
2041 const struct GNUNET_CONTAINER_MetaData *meta, 2164 const struct GNUNET_FS_MetaData *meta,
2042 const struct GNUNET_FS_Uri *uri, 2165 const struct GNUNET_FS_Uri *uri,
2043 const struct GNUNET_FS_BlockOptions *bo, 2166 const struct GNUNET_FS_BlockOptions *bo,
2044 enum GNUNET_FS_PublishOptions options, 2167 enum GNUNET_FS_PublishOptions options,
@@ -2080,7 +2203,7 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2080 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, 2203 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
2081 const char *identifier, 2204 const char *identifier,
2082 const char *update, 2205 const char *update,
2083 const struct GNUNET_CONTAINER_MetaData *meta, 2206 const struct GNUNET_FS_MetaData *meta,
2084 const struct GNUNET_FS_Uri *uri, 2207 const struct GNUNET_FS_Uri *uri,
2085 const struct GNUNET_FS_BlockOptions *bo, 2208 const struct GNUNET_FS_BlockOptions *bo,
2086 enum GNUNET_FS_PublishOptions options, 2209 enum GNUNET_FS_PublishOptions options,
@@ -2176,7 +2299,7 @@ typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls,
2176 const struct 2299 const struct
2177 GNUNET_FS_Uri *last_uri, 2300 GNUNET_FS_Uri *last_uri,
2178 const struct 2301 const struct
2179 GNUNET_CONTAINER_MetaData * 2302 GNUNET_FS_MetaData *
2180 last_meta, 2303 last_meta,
2181 const char *next_id); 2304 const char *next_id);
2182 2305
@@ -2286,7 +2409,7 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2286struct GNUNET_FS_SearchResult * 2409struct GNUNET_FS_SearchResult *
2287GNUNET_FS_probe (struct GNUNET_FS_Handle *h, 2410GNUNET_FS_probe (struct GNUNET_FS_Handle *h,
2288 const struct GNUNET_FS_Uri *uri, 2411 const struct GNUNET_FS_Uri *uri,
2289 const struct GNUNET_CONTAINER_MetaData *meta, 2412 const struct GNUNET_FS_MetaData *meta,
2290 void *client_info, 2413 void *client_info,
2291 uint32_t anonymity); 2414 uint32_t anonymity);
2292 2415
@@ -2374,7 +2497,7 @@ enum GNUNET_FS_DownloadOptions
2374struct GNUNET_FS_DownloadContext * 2497struct GNUNET_FS_DownloadContext *
2375GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, 2498GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2376 const struct GNUNET_FS_Uri *uri, 2499 const struct GNUNET_FS_Uri *uri,
2377 const struct GNUNET_CONTAINER_MetaData *meta, 2500 const struct GNUNET_FS_MetaData *meta,
2378 const char *filename, const char *tempname, 2501 const char *filename, const char *tempname,
2379 uint64_t offset, uint64_t length, uint32_t anonymity, 2502 uint64_t offset, uint64_t length, uint32_t anonymity,
2380 enum GNUNET_FS_DownloadOptions options, void *cctx, 2503 enum GNUNET_FS_DownloadOptions options, void *cctx,
@@ -2468,7 +2591,7 @@ GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc);
2468 * we have no mime-type information (treat as #GNUNET_NO) 2591 * we have no mime-type information (treat as #GNUNET_NO)
2469 */ 2592 */
2470int 2593int
2471GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData 2594GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_FS_MetaData
2472 *md); 2595 *md);
2473 2596
2474 2597
@@ -2479,7 +2602,7 @@ GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
2479 * @param md metadata to add mimetype to 2602 * @param md metadata to add mimetype to
2480 */ 2603 */
2481void 2604void
2482GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md); 2605GNUNET_FS_meta_data_make_directory (struct GNUNET_FS_MetaData *md);
2483 2606
2484 2607
2485/** 2608/**
@@ -2490,7 +2613,7 @@ GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2490 */ 2613 */
2491char * 2614char *
2492GNUNET_FS_meta_data_suggest_filename (const struct 2615GNUNET_FS_meta_data_suggest_filename (const struct
2493 GNUNET_CONTAINER_MetaData *md); 2616 GNUNET_FS_MetaData *md);
2494 2617
2495 2618
2496/** 2619/**
@@ -2513,7 +2636,7 @@ typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
2513 const struct GNUNET_FS_Uri * 2636 const struct GNUNET_FS_Uri *
2514 uri, 2637 uri,
2515 const struct 2638 const struct
2516 GNUNET_CONTAINER_MetaData * 2639 GNUNET_FS_MetaData *
2517 meta, size_t length, 2640 meta, size_t length,
2518 const void *data); 2641 const void *data);
2519 2642
@@ -2556,7 +2679,7 @@ struct GNUNET_FS_DirectoryBuilder;
2556 * @param mdir metadata for the directory 2679 * @param mdir metadata for the directory
2557 */ 2680 */
2558struct GNUNET_FS_DirectoryBuilder * 2681struct GNUNET_FS_DirectoryBuilder *
2559GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData 2682GNUNET_FS_directory_builder_create (const struct GNUNET_FS_MetaData
2560 *mdir); 2683 *mdir);
2561 2684
2562 2685
@@ -2573,7 +2696,7 @@ GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
2573void 2696void
2574GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, 2697GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2575 const struct GNUNET_FS_Uri *uri, 2698 const struct GNUNET_FS_Uri *uri,
2576 const struct GNUNET_CONTAINER_MetaData *md, 2699 const struct GNUNET_FS_MetaData *md,
2577 const void *data); 2700 const void *data);
2578 2701
2579 2702
@@ -2688,7 +2811,7 @@ struct GNUNET_FS_ShareTreeItem
2688 /** 2811 /**
2689 * Metadata for this file or directory 2812 * Metadata for this file or directory
2690 */ 2813 */
2691 struct GNUNET_CONTAINER_MetaData *meta; 2814 struct GNUNET_FS_MetaData *meta;
2692 2815
2693 /** 2816 /**
2694 * Keywords for this file or directory (derived from metadata). 2817 * Keywords for this file or directory (derived from metadata).
@@ -2777,6 +2900,336 @@ GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel);
2777void 2900void
2778GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel); 2901GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
2779 2902
2903/**
2904 * Meta data processing
2905 * @defgroup metadata Metadata
2906 * GNU libextractor key-value pairs
2907 */
2908
2909
2910/* ****************** metadata ******************* */
2911
2912
2913/**
2914 * @ingroup metadata
2915 * Create a fresh meta data container.
2916 *
2917 * @return empty meta-data container
2918 */
2919struct GNUNET_FS_MetaData *
2920GNUNET_FS_meta_data_create (void);
2921
2922
2923/**
2924 * @ingroup metadata
2925 * Duplicate a MetaData token.
2926 *
2927 * @param md what to duplicate
2928 * @return duplicate meta-data container
2929 */
2930struct GNUNET_FS_MetaData *
2931GNUNET_FS_meta_data_duplicate (
2932 const struct GNUNET_FS_MetaData *md);
2933
2934
2935/**
2936 * @ingroup metadata
2937 * Free meta data.
2938 *
2939 * @param md what to free
2940 */
2941void
2942GNUNET_FS_meta_data_destroy (struct GNUNET_FS_MetaData *md);
2943
2944
2945/**
2946 * @ingroup metadata
2947 * Test if two MDs are equal. We consider them equal if
2948 * the meta types, formats and content match (we do not
2949 * include the mime types and plugins names in this
2950 * consideration).
2951 *
2952 * @param md1 first value to check
2953 * @param md2 other value to check
2954 * @return #GNUNET_YES if they are equal
2955 */
2956int
2957GNUNET_FS_meta_data_test_equal (
2958 const struct GNUNET_FS_MetaData *md1,
2959 const struct GNUNET_FS_MetaData *md2);
2960
2961
2962/**
2963 * @ingroup metadata
2964 * Extend metadata.
2965 *
2966 * @param md metadata to extend
2967 * @param plugin_name name of the plugin that produced this value;
2968 * special values can be used (e.g. '&lt;zlib&gt;' for zlib being
2969 * used in the main libextractor library and yielding
2970 * meta data).
2971 * @param type libextractor-type describing the meta data
2972 * @param format basic format information about data
2973 * @param data_mime_type mime-type of data (not of the original file);
2974 * can be NULL (if mime-type is not known)
2975 * @param data actual meta-data found
2976 * @param data_size number of bytes in data
2977 * @return #GNUNET_OK on success, #GNUNET_SYSERR if this entry already exists
2978 * data_mime_type and plugin_name are not considered for "exists" checks
2979 */
2980int
2981GNUNET_FS_meta_data_insert (struct GNUNET_FS_MetaData *md,
2982 const char *plugin_name,
2983 enum EXTRACTOR_MetaType type,
2984 enum EXTRACTOR_MetaFormat format,
2985 const char *data_mime_type,
2986 const char *data,
2987 size_t data_size);
2988
2989
2990/**
2991 * @ingroup metadata
2992 * Extend metadata. Merges the meta data from the second argument
2993 * into the first, discarding duplicate key-value pairs.
2994 *
2995 * @param md metadata to extend
2996 * @param in metadata to merge
2997 */
2998void
2999GNUNET_FS_meta_data_merge (struct GNUNET_FS_MetaData *md,
3000 const struct GNUNET_FS_MetaData *in);
3001
3002
3003/**
3004 * @ingroup metadata
3005 * Remove an item.
3006 *
3007 * @param md metadata to manipulate
3008 * @param type type of the item to remove
3009 * @param data specific value to remove, NULL to remove all
3010 * entries of the given type
3011 * @param data_size number of bytes in data
3012 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the item does not exist in md
3013 */
3014int
3015GNUNET_FS_meta_data_delete (struct GNUNET_FS_MetaData *md,
3016 enum EXTRACTOR_MetaType type,
3017 const char *data,
3018 size_t data_size);
3019
3020
3021/**
3022 * @ingroup metadata
3023 * Remove all items in the container.
3024 *
3025 * @param md metadata to manipulate
3026 */
3027void
3028GNUNET_FS_meta_data_clear (struct GNUNET_FS_MetaData *md);
3029
3030
3031/**
3032 * @ingroup metadata
3033 * Add the current time as the publication date
3034 * to the meta-data.
3035 *
3036 * @param md metadata to modify
3037 */
3038void
3039GNUNET_FS_meta_data_add_publication_date (
3040 struct GNUNET_FS_MetaData *md);
3041
3042
3043/**
3044 * @ingroup metadata
3045 * Iterate over MD entries.
3046 *
3047 * @param md metadata to inspect
3048 * @param iter function to call on each entry, return 0 to continue to iterate
3049 * and 1 to abort iteration in this function (GNU libextractor API!)
3050 * @param iter_cls closure for @a iter
3051 * @return number of entries
3052 */
3053int
3054GNUNET_FS_meta_data_iterate (const struct GNUNET_FS_MetaData *md,
3055 EXTRACTOR_MetaDataProcessor iter,
3056 void *iter_cls);
3057
3058
3059/**
3060 * @ingroup metadata
3061 * Get the first MD entry of the given type. Caller
3062 * is responsible for freeing the return value.
3063 * Also, only meta data items that are strings (0-terminated)
3064 * are returned by this function.
3065 *
3066 * @param md metadata to inspect
3067 * @param type type to look for
3068 * @return NULL if no entry was found
3069 */
3070char *
3071GNUNET_FS_meta_data_get_by_type (
3072 const struct GNUNET_FS_MetaData *md,
3073 enum EXTRACTOR_MetaType type);
3074
3075
3076/**
3077 * @ingroup metadata
3078 * Get the first matching MD entry of the given types. Caller is
3079 * responsible for freeing the return value. Also, only meta data
3080 * items that are strings (0-terminated) are returned by this
3081 * function.
3082 *
3083 * @param md metadata to inspect
3084 * @param ... -1-terminated list of types
3085 * @return NULL if we do not have any such entry,
3086 * otherwise client is responsible for freeing the value!
3087 */
3088char *
3089GNUNET_FS_meta_data_get_first_by_types (
3090 const struct GNUNET_FS_MetaData *md,
3091 ...);
3092
3093/**
3094 * @ingroup metadata
3095 * Get a thumbnail from the meta-data (if present). Only matches meta
3096 * data with mime type "image" and binary format.
3097 *
3098 * @param md metadata to inspect
3099 * @param thumb will be set to the thumbnail data. Must be
3100 * freed by the caller!
3101 * @return number of bytes in thumbnail, 0 if not available
3102 */
3103size_t
3104GNUNET_FS_meta_data_get_thumbnail (
3105 const struct GNUNET_FS_MetaData *md,
3106 unsigned char **thumb);
3107
3108
3109/**
3110 * @ingroup metadata
3111 * Options for metadata serialization.
3112 */
3113enum GNUNET_FS_MetaDataSerializationOptions
3114{
3115 /**
3116 * @ingroup metadata
3117 * Serialize all of the data.
3118 */
3119 GNUNET_FS_META_DATA_SERIALIZE_FULL = 0,
3120
3121 /**
3122 * @ingroup metadata
3123 * If not enough space is available, it is acceptable
3124 * to only serialize some of the metadata.
3125 */
3126 GNUNET_FS_META_DATA_SERIALIZE_PART = 1,
3127
3128 /**
3129 * @ingroup metadata
3130 * Speed is of the essence, do not allow compression.
3131 */
3132 GNUNET_FS_META_DATA_SERIALIZE_NO_COMPRESS = 2
3133};
3134
3135
3136/**
3137 * @ingroup metadata
3138 * Serialize meta-data to target.
3139 *
3140 * @param md metadata to serialize
3141 * @param target where to write the serialized metadata;
3142 * *target can be NULL, in which case memory is allocated
3143 * @param max maximum number of bytes available
3144 * @param opt is it ok to just write SOME of the
3145 * meta-data to match the size constraint,
3146 * possibly discarding some data?
3147 * @return number of bytes written on success,
3148 * -1 on error (typically: not enough
3149 * space)
3150 */
3151ssize_t
3152GNUNET_FS_meta_data_serialize (
3153 const struct GNUNET_FS_MetaData *md,
3154 char **target,
3155 size_t max,
3156 enum GNUNET_FS_MetaDataSerializationOptions opt);
3157
3158
3159/**
3160 * @ingroup metadata
3161 * Get the size of the full meta-data in serialized form.
3162 *
3163 * @param md metadata to inspect
3164 * @return number of bytes needed for serialization, -1 on error
3165 */
3166ssize_t
3167GNUNET_FS_meta_data_get_serialized_size (
3168 const struct GNUNET_FS_MetaData *md);
3169
3170
3171/**
3172 * @ingroup metadata
3173 * Deserialize meta-data. Initializes md.
3174 *
3175 * @param input serialized meta-data.
3176 * @param size number of bytes available
3177 * @return MD on success, NULL on error (e.g.
3178 * bad format)
3179 */
3180struct GNUNET_FS_MetaData *
3181GNUNET_FS_meta_data_deserialize (const char *input, size_t size);
3182
3183/**
3184 * Write a metadata container.
3185 *
3186 * @param h the IO handle to write to
3187 * @param what what is being written (for error message creation)
3188 * @param m metadata to write
3189 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
3190 */
3191enum GNUNET_GenericReturnValue
3192GNUNET_FS_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
3193 const char *what,
3194 const struct GNUNET_FS_MetaData *m);
3195
3196/**
3197 * Create the specification to read a metadata container.
3198 *
3199 * @param what describes what is being read (for error message creation)
3200 * @param result the buffer to store a pointer to the (allocated) metadata
3201 * @return the read spec
3202 */
3203struct GNUNET_BIO_ReadSpec
3204GNUNET_FS_read_spec_meta_data (const char *what,
3205 struct GNUNET_FS_MetaData **result);
3206
3207
3208
3209/**
3210 * Create the specification to write a metadata container.
3211 *
3212 * @param what what is being written (for error message creation)
3213 * @param m metadata to write
3214 * @return the write spec
3215 */
3216struct GNUNET_BIO_WriteSpec
3217GNUNET_FS_write_spec_meta_data (const char *what,
3218 const struct GNUNET_FS_MetaData *m);
3219
3220/**
3221 * Read a metadata container.
3222 *
3223 * @param h handle to an open file
3224 * @param what describes what is being read (for error message creation)
3225 * @param result the buffer to store a pointer to the (allocated) metadata
3226 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
3227 */
3228enum GNUNET_GenericReturnValue
3229GNUNET_FS_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
3230 const char *what,
3231 struct GNUNET_FS_MetaData **result);
3232
2780 3233
2781#if 0 /* keep Emacsens' auto-indent happy */ 3234#if 0 /* keep Emacsens' auto-indent happy */
2782{ 3235{
@@ -2788,3 +3241,5 @@ GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
2788#endif 3241#endif
2789 3242
2790/** @} */ /* end of group */ 3243/** @} */ /* end of group */
3244
3245/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_getopt_lib.h b/src/include/gnunet_getopt_lib.h
index 731be4159..451ddf12b 100644
--- a/src/include/gnunet_getopt_lib.h
+++ b/src/include/gnunet_getopt_lib.h
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * 27 *
24 * @file 28 * @file
@@ -29,6 +33,10 @@
29 * @{ 33 * @{
30 */ 34 */
31 35
36#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
37#error "Only <gnunet_util_lib.h> can be included directly."
38#endif
39
32#ifndef GNUNET_GETOPT_LIB_H 40#ifndef GNUNET_GETOPT_LIB_H
33#define GNUNET_GETOPT_LIB_H 41#define GNUNET_GETOPT_LIB_H
34 42
@@ -39,6 +47,7 @@ extern "C" {
39#endif 47#endif
40#endif 48#endif
41 49
50
42#include "gnunet_configuration_lib.h" 51#include "gnunet_configuration_lib.h"
43 52
44/** 53/**
@@ -266,12 +275,12 @@ GNUNET_GETOPT_option_base32_fixed_size (char shortName,
266 argumentHelp, \ 275 argumentHelp, \
267 description, \ 276 description, \
268 val) \ 277 val) \
269 GNUNET_GETOPT_option_base32_fixed_size (shortName, \ 278 GNUNET_GETOPT_option_base32_fixed_size (shortName, \
270 name, \ 279 name, \
271 argumentHelp, \ 280 argumentHelp, \
272 description, \ 281 description, \
273 val, \ 282 val, \
274 sizeof(*val)) 283 sizeof(*val))
275 284
276 285
277/** 286/**
@@ -378,12 +387,29 @@ GNUNET_GETOPT_option_absolute_time (char shortName,
378 387
379 388
380/** 389/**
381 * Increment @a val each time the option flag is given by one. 390 * Allow user to specify a `struct GNUNET_TIME_Timestamp`
391 * (using human-readable "fancy" time).
382 * 392 *
383 * @param shortName short name of the option 393 * @param shortName short name of the option
384 * @param name long name of the option 394 * @param name long name of the option
385 * @param argumentHelp help text for the option argument 395 * @param argumentHelp help text for the option argument
386 * @param description long help text for the option 396 * @param description long help text for the option
397 * @param[out] val set to the time specified at the command line
398 */
399struct GNUNET_GETOPT_CommandLineOption
400GNUNET_GETOPT_option_timestamp (char shortName,
401 const char *name,
402 const char *argumentHelp,
403 const char *description,
404 struct GNUNET_TIME_Timestamp *val);
405
406
407/**
408 * Increment @a val each time the option flag is given by one.
409 *
410 * @param shortName short name of the option
411 * @param name long name of the option
412 * @param description long help text for the option
387 * @param[out] val set to 1 if the option is present 413 * @param[out] val set to 1 if the option is present
388 */ 414 */
389struct GNUNET_GETOPT_CommandLineOption 415struct GNUNET_GETOPT_CommandLineOption
@@ -414,15 +440,6 @@ GNUNET_GETOPT_option_verbose (unsigned int *level);
414 440
415 441
416/** 442/**
417 * Allow user to specify log file name (-l option)
418 *
419 * @param[out] logfn set to the name of the logfile
420 */
421struct GNUNET_GETOPT_CommandLineOption
422GNUNET_GETOPT_option_logfile (char **logfn);
423
424
425/**
426 * Allow user to specify configuration file name (-c option) 443 * Allow user to specify configuration file name (-c option)
427 * 444 *
428 * @param[out] fn set to the name of the configuration file 445 * @param[out] fn set to the name of the configuration file
@@ -455,9 +472,9 @@ GNUNET_GETOPT_option_exclusive (struct GNUNET_GETOPT_CommandLineOption opt);
455 * Marker for the end of the list of options. 472 * Marker for the end of the list of options.
456 */ 473 */
457#define GNUNET_GETOPT_OPTION_END \ 474#define GNUNET_GETOPT_OPTION_END \
458 { \ 475 { \
459 '\0', NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL \ 476 '\0', NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL \
460 } 477 }
461 478
462 479
463/** 480/**
@@ -489,4 +506,6 @@ GNUNET_GETOPT_run (const char *binaryOptions,
489 506
490/** @} */ /* end of group getopt */ 507/** @} */ /* end of group getopt */
491 508
509/** @} */ /* end of group addition */
510
492/* end of gnunet_getopt_lib.h */ 511/* end of gnunet_getopt_lib.h */
diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h
index 3f6c9b9aa..e7ed2d3c2 100644
--- a/src/include/gnunet_gns_service.h
+++ b/src/include/gnunet_gns_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Martin Schanzenbach 25 * @author Martin Schanzenbach
23 * 26 *
24 * @file 27 * @file
@@ -34,8 +37,8 @@
34#ifndef GNUNET_GNS_SERVICE_H 37#ifndef GNUNET_GNS_SERVICE_H
35#define GNUNET_GNS_SERVICE_H 38#define GNUNET_GNS_SERVICE_H
36 39
40
37#include "gnunet_util_lib.h" 41#include "gnunet_util_lib.h"
38#include "gnunet_dnsparser_lib.h"
39#include "gnunet_identity_service.h" 42#include "gnunet_identity_service.h"
40#include "gnunet_namestore_service.h" 43#include "gnunet_namestore_service.h"
41 44
@@ -48,12 +51,6 @@ extern "C" {
48 51
49 52
50/** 53/**
51 * String we use to indicate an empty label (top-level
52 * entry in the zone). DNS uses "@", so do we.
53 */
54#define GNUNET_GNS_EMPTY_LABEL_AT "@"
55
56/**
57 * Connection to the GNS service. 54 * Connection to the GNS service.
58 */ 55 */
59struct GNUNET_GNS_Handle; 56struct GNUNET_GNS_Handle;
@@ -140,7 +137,7 @@ enum GNUNET_GNS_LocalOptions
140struct GNUNET_GNS_LookupRequest * 137struct GNUNET_GNS_LookupRequest *
141GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, 138GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
142 const char *name, 139 const char *name,
143 const struct GNUNET_IDENTITY_PublicKey *zone, 140 const struct GNUNET_CRYPTO_PublicKey *zone,
144 uint32_t type, 141 uint32_t type,
145 enum GNUNET_GNS_LocalOptions options, 142 enum GNUNET_GNS_LocalOptions options,
146 GNUNET_GNS_LookupResultProcessor proc, 143 GNUNET_GNS_LookupResultProcessor proc,
@@ -164,7 +161,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
164struct GNUNET_GNS_LookupRequest * 161struct GNUNET_GNS_LookupRequest *
165GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle *handle, 162GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle *handle,
166 const char *name, 163 const char *name,
167 const struct GNUNET_IDENTITY_PublicKey *zone, 164 const struct GNUNET_CRYPTO_PublicKey *zone,
168 uint32_t type, 165 uint32_t type,
169 enum GNUNET_GNS_LocalOptions options, 166 enum GNUNET_GNS_LocalOptions options,
170 uint16_t recursion_depth_limit, 167 uint16_t recursion_depth_limit,
@@ -230,6 +227,16 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle,
230void * 227void *
231GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr); 228GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr);
232 229
230/**
231 * Try to parse the zTLD into a public key.
232 *
233 * @param[in] name the name to parse
234 * @param[out] ztld_key the identity key (must be allocated by caller). Only set of #GNUNET_OK is returned.
235 * @return GNUNET_OK on success.
236 */
237enum GNUNET_GenericReturnValue
238GNUNET_GNS_parse_ztld (const char *name,
239 struct GNUNET_CRYPTO_PublicKey *ztld_key);
233 240
234#if 0 /* keep Emacsens' auto-indent happy */ 241#if 0 /* keep Emacsens' auto-indent happy */
235{ 242{
@@ -241,3 +248,5 @@ GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr);
241#endif 248#endif
242 249
243/** @} */ /* end of group */ 250/** @} */ /* end of group */
251
252/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_gnsrecord_json_lib.h b/src/include/gnunet_gnsrecord_json_lib.h
index 966461705..5bc48034b 100644
--- a/src/include/gnunet_gnsrecord_json_lib.h
+++ b/src/include/gnunet_gnsrecord_json_lib.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Martin Schanzenbach 25 * @author Martin Schanzenbach
23 * 26 *
24 * @file 27 * @file
@@ -34,6 +37,7 @@
34#ifndef GNUNET_GNSRECORD_JSON_LIB_H 37#ifndef GNUNET_GNSRECORD_JSON_LIB_H
35#define GNUNET_GNSRECORD_JSON_LIB_H 38#define GNUNET_GNSRECORD_JSON_LIB_H
36 39
40
37#include "gnunet_gnsrecord_lib.h" 41#include "gnunet_gnsrecord_lib.h"
38#include "gnunet_json_lib.h" 42#include "gnunet_json_lib.h"
39 43
@@ -69,5 +73,15 @@ GNUNET_GNSRECORD_JSON_from_gnsrecord (const char*rname,
69 const struct GNUNET_GNSRECORD_Data *rd, 73 const struct GNUNET_GNSRECORD_Data *rd,
70 unsigned int rd_count); 74 unsigned int rd_count);
71 75
76#if 0 /* keep Emacsens' auto-indent happy */
77{
78#endif
79#ifdef __cplusplus
80}
81#endif
72 82
73#endif 83#endif
84
85/** @} */ /* end of group */
86
87/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h
index f00a5d0f8..b4e45727b 100644
--- a/src/include/gnunet_gnsrecord_lib.h
+++ b/src/include/gnunet_gnsrecord_lib.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -34,6 +37,8 @@
34#ifndef GNUNET_GNSRECORD_LIB_H 37#ifndef GNUNET_GNSRECORD_LIB_H
35#define GNUNET_GNSRECORD_LIB_H 38#define GNUNET_GNSRECORD_LIB_H
36 39
40
41#include "gnunet_common.h"
37#include "gnunet_identity_service.h" 42#include "gnunet_identity_service.h"
38 43
39#ifdef __cplusplus 44#ifdef __cplusplus
@@ -44,6 +49,12 @@ extern "C" {
44#endif 49#endif
45 50
46/** 51/**
52 * String we use to indicate an empty label (top-level
53 * entry in the zone). DNS uses "@", so do we.
54 */
55#define GNUNET_GNS_EMPTY_LABEL_AT "@"
56
57/**
47 * Maximum size of a value that can be stored in a GNS block. 58 * Maximum size of a value that can be stored in a GNS block.
48 */ 59 */
49#define GNUNET_GNSRECORD_MAX_BLOCK_SIZE (63 * 1024) 60#define GNUNET_GNSRECORD_MAX_BLOCK_SIZE (63 * 1024)
@@ -60,50 +71,102 @@ extern "C" {
60#include "gnu_name_system_record_types.h" 71#include "gnu_name_system_record_types.h"
61 72
62/** 73/**
74 * When comparing flags for record equality for removal,
75 * which flags should must match (in addition to the type,
76 * name, expiration value and data of the record)? All flags
77 * that are not listed here will be ignored for this purpose.
78 * (for example, we don't expect that users will remember to
79 * pass the '--private' option when removing a record from
80 * the namestore, hence we don't require this particular option
81 * to match upon removal). See also
82 * #GNUNET_GNSRECORD_records_cmp.
83 */
84#define GNUNET_GNSRECORD_RF_RCMP_FLAGS (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)
85
86
87/**
63 * Flags that can be set for a record. 88 * Flags that can be set for a record.
89 * The numbers in the registry correspond to the bit index as specified in
90 * LSD0001 Chapter "Resource Records".
91 * Each enum member represents the 16-bit integer value of the flags field if
92 * only that particular flag was set.
93 * The value can be used to efficiently compare the bitmask setting for the
94 * record flag in C.
95 * WARNING: The values are in host byte order! In order to correctly check
96 * against the flags field a record, the respective fields must
97 * also be converted to HBO (or the enum value to NBO).
64 */ 98 */
65enum GNUNET_GNSRECORD_Flags 99enum GNUNET_GNSRECORD_Flags
66{ 100{
67 /** 101 /**
68 * No special options. 102 * Entry for no flags / cleared flags.
69 */ 103 */
70 GNUNET_GNSRECORD_RF_NONE = 0, 104 GNUNET_GNSRECORD_RF_NONE = 0,
71 105
106
107 /**
108 * This record is critical. If it cannot be processed (for example because the record type is unknown) resolution MUST fail
109 */
110 GNUNET_GNSRECORD_RF_CRITICAL = 1 << (15 - 15),
111
112
72 /** 113 /**
73 * This is a private record of this peer and it should 114 * This record should not be used unless all (other) records in the set with an absolute expiration time have expired.
74 * thus not be handed out to other peers.
75 */ 115 */
76 GNUNET_GNSRECORD_RF_PRIVATE = 2, 116 GNUNET_GNSRECORD_RF_SHADOW = 1 << (15 - 14),
117
77 118
78 /** 119 /**
79 * This is a supplemental record. 120 * This is a supplemental record.
80 */ 121 */
81 GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 4, 122 GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 1 << (15 - 13),
82 123
83 /** 124 /**
84 * This expiration time of the record is a relative 125 * Maintenance records. E.g. TOMBSTONEs
85 * time (not an absolute time).
86 */ 126 */
87 GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION = 8, 127 GNUNET_GNSRECORD_RF_MAINTENANCE = 1 << (15 - 2),
88 128
89 /** 129 /**
90 * This record should not be used unless all (other) records with an absolute 130 * This expiration time of the record is a relative time (not an absolute time). Used in GNUnet implementation.
91 * expiration time have expired.
92 */ 131 */
93 GNUNET_GNSRECORD_RF_SHADOW_RECORD = 16 132 GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION = 1 << (15 - 1),
133
134
135 /**
136 * This is a private record of this peer and it should thus not be published.
137 */
138 GNUNET_GNSRECORD_RF_PRIVATE = 1 << (15 - 0),
139
140};
141
94 142
95/** 143/**
96 * When comparing flags for record equality for removal, 144 * Filter for GNUNET_GNSRECORD_normalize_record_set().
97 * which flags should must match (in addition to the type,
98 * name, expiration value and data of the record)? All flags
99 * that are not listed here will be ignored for this purpose.
100 * (for example, we don't expect that users will remember to
101 * pass the '--private' option when removing a record from
102 * the namestore, hence we don't require this particular option
103 * to match upon removal). See also
104 * #GNUNET_GNSRECORD_records_cmp.
105 */ 145 */
106#define GNUNET_GNSRECORD_RF_RCMP_FLAGS (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION) 146enum GNUNET_GNSRECORD_Filter
147{
148 /**
149 * No filter flags set.
150 * Private and public records are returned,
151 * maintenance records (TOMBSTONE etc) are not.
152 */
153 GNUNET_GNSRECORD_FILTER_NONE = 0,
154
155 /**
156 * Include maintenance records (TOMBSTONE etc).
157 */
158 GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE = 1,
159
160 /**
161 * Filter private records
162 */
163 GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE = 2,
164
165 /**
166 * Filter public records.
167 * FIXME: Not implemented
168 */
169 // GNUNET_NAMESTORE_FILTER_OMIT_PUBLIC = 4,
107}; 170};
108 171
109 172
@@ -184,12 +247,6 @@ struct GNUNET_GNSRECORD_EcdsaBlock
184 struct GNUNET_CRYPTO_EcdsaSignature signature; 247 struct GNUNET_CRYPTO_EcdsaSignature signature;
185 248
186 /** 249 /**
187 * Number of bytes signed; also specifies the number of bytes
188 * of encrypted data that follow.
189 */
190 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
191
192 /**
193 * Expiration time of the block. 250 * Expiration time of the block.
194 */ 251 */
195 struct GNUNET_TIME_AbsoluteNBO expiration_time; 252 struct GNUNET_TIME_AbsoluteNBO expiration_time;
@@ -214,22 +271,25 @@ struct GNUNET_GNSRECORD_EddsaBlock
214 struct GNUNET_CRYPTO_EddsaSignature signature; 271 struct GNUNET_CRYPTO_EddsaSignature signature;
215 272
216 /** 273 /**
217 * Number of bytes signed; also specifies the number of bytes
218 * of encrypted data that follow.
219 */
220 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
221
222 /**
223 * Expiration time of the block. 274 * Expiration time of the block.
224 */ 275 */
225 struct GNUNET_TIME_AbsoluteNBO expiration_time; 276 struct GNUNET_TIME_AbsoluteNBO expiration_time;
226 277
278
227 /* followed by encrypted data */ 279 /* followed by encrypted data */
228}; 280};
229 281
230 282
231struct GNUNET_GNSRECORD_Block 283struct GNUNET_GNSRECORD_Block
232{ 284{
285 /**
286 * Size of the block.
287 */
288 uint32_t size;
289
290 /**
291 * The zone type (GNUNET_GNSRECORD_TYPE_PKEY)
292 */
233 uint32_t type; 293 uint32_t type;
234 294
235 union 295 union
@@ -271,6 +331,31 @@ struct GNUNET_GNSRECORD_BoxRecord
271 /* followed by the 'original' record */ 331 /* followed by the 'original' record */
272}; 332};
273 333
334
335/**
336 * Record type used to box up SMIMEA records. For example, a
337 * SMIMEA record for "c93f1e400f26708f98cb19d936620da35eec8f72e57
338 * f9eec01c1afd6._smimecert.foo.gnu" will be stored under
339 * "foo.gnu" as a SBOX record with the local-path of the associated
340 * e-mails hash turnicated to 28 octets encoded as hex and protocol _smimecert
341 * and record_type "SMIMEA". When a BOX record is received, GNS
342 * unboxes it if the name contained "hash._PROTO", otherwise GNS
343 * leaves it untouched. This is done to ensure that SMIMEA
344 * records do not require a separate network request, thus making SMIMEA
345 * records inseparable from the "main" A/AAAA/VPN/etc. records.
346 */
347struct GNUNET_GNSRECORD_SBoxRecord
348{
349 /**
350 * GNS record type of the boxed record. In NBO.
351 */
352 uint32_t record_type GNUNET_PACKED;
353
354 /* followed by the zero terminated hostname prefix */
355 /* followed by the 'original' record */
356};
357
358
274/** 359/**
275 * Record type used internally to keep track of reverse mappings into a 360 * Record type used internally to keep track of reverse mappings into a
276 * namespace. 361 * namespace.
@@ -283,7 +368,7 @@ struct GNUNET_GNSRECORD_ReverseRecord
283 /** 368 /**
284 * The public key of the namespace the is delegating to our namespace 369 * The public key of the namespace the is delegating to our namespace
285 */ 370 */
286 struct GNUNET_IDENTITY_PublicKey pkey; 371 struct GNUNET_CRYPTO_PublicKey pkey;
287 372
288 /** 373 /**
289 * The expiration time of the delegation 374 * The expiration time of the delegation
@@ -293,8 +378,6 @@ struct GNUNET_GNSRECORD_ReverseRecord
293 /* followed by the name the delegator uses to refer to our namespace */ 378 /* followed by the name the delegator uses to refer to our namespace */
294}; 379};
295 380
296GNUNET_NETWORK_STRUCT_END
297
298 381
299/** 382/**
300 * Process a records that were decrypted from a block. 383 * Process a records that were decrypted from a block.
@@ -387,6 +470,9 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count,
387 const struct GNUNET_GNSRECORD_Data *rd, 470 const struct GNUNET_GNSRECORD_Data *rd,
388 size_t dest_size, char *dest); 471 size_t dest_size, char *dest);
389 472
473unsigned int
474GNUNET_GNSRECORD_records_deserialize_get_size (size_t len,
475 const char *src);
390 476
391/** 477/**
392 * Deserialize the given records to the given destination. 478 * Deserialize the given records to the given destination.
@@ -418,12 +504,13 @@ GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd);
418 504
419 505
420/** 506/**
421 * Convert a UTF-8 string to UTF-8 lowercase 507 * Normalize a UTF-8 string to a GNS name
508 *
422 * @param src source string 509 * @param src source string
423 * @return converted result 510 * @return converted result
424 */ 511 */
425char * 512char *
426GNUNET_GNSRECORD_string_to_lowercase (const char *src); 513GNUNET_GNSRECORD_string_normalize (const char *src);
427 514
428 515
429/** 516/**
@@ -436,7 +523,7 @@ GNUNET_GNSRECORD_string_to_lowercase (const char *src);
436 * #GNUNET_GNSRECORD_z2s. 523 * #GNUNET_GNSRECORD_z2s.
437 */ 524 */
438const char * 525const char *
439GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z); 526GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_PublicKey *z);
440 527
441 528
442/** 529/**
@@ -450,7 +537,7 @@ GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z);
450 * key in an encoding suitable for DNS labels. 537 * key in an encoding suitable for DNS labels.
451 */ 538 */
452const char * 539const char *
453GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey); 540GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_PublicKey *pkey);
454 541
455 542
456/** 543/**
@@ -464,7 +551,7 @@ GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey);
464 */ 551 */
465int 552int
466GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, 553GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey,
467 struct GNUNET_IDENTITY_PublicKey *pkey); 554 struct GNUNET_CRYPTO_PublicKey *pkey);
468 555
469 556
470/** 557/**
@@ -476,12 +563,13 @@ GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey,
476 */ 563 */
477void 564void
478GNUNET_GNSRECORD_query_from_private_key ( 565GNUNET_GNSRECORD_query_from_private_key (
479 const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, 566 const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label,
480 struct GNUNET_HashCode *query); 567 struct GNUNET_HashCode *query);
481 568
482 569
483/** 570/**
484 * Calculate the DHT query for a given @a label in a given @a zone. 571 * Calculate the DHT query for a given @a label in a given @a zone.
572 * FIXME: We may want to plugin-ize this at some point.
485 * 573 *
486 * @param pub public key of the zone 574 * @param pub public key of the zone
487 * @param label label of the record 575 * @param label label of the record
@@ -489,11 +577,39 @@ GNUNET_GNSRECORD_query_from_private_key (
489 */ 577 */
490void 578void
491GNUNET_GNSRECORD_query_from_public_key ( 579GNUNET_GNSRECORD_query_from_public_key (
492 const struct GNUNET_IDENTITY_PublicKey *pub, const char *label, 580 const struct GNUNET_CRYPTO_PublicKey *pub, const char *label,
493 struct GNUNET_HashCode *query); 581 struct GNUNET_HashCode *query);
494 582
495 583
496/** 584/**
585 * Get size of buffer for block creation.
586 *
587 * @param key the zone key
588 * @param rd record data
589 * @param rd_count number of records
590 * @return -1 on error (otherwise the length of the block)
591 */
592ssize_t
593GNUNET_GNSRECORD_block_calculate_size (const struct
594 GNUNET_CRYPTO_PrivateKey *key,
595 const struct GNUNET_GNSRECORD_Data *rd,
596 unsigned int rd_count);
597
598/**
599 * Sign a block create with #GNUNET_GNSRECORD_block_create_unsigned
600 *
601 * @param key the private key
602 * @param label the label of the block
603 * @param block the unsigned block
604 * @return GNUNET_OK on success
605 */
606enum GNUNET_GenericReturnValue
607GNUNET_GNSRECORD_block_sign (const struct
608 GNUNET_CRYPTO_PrivateKey *key,
609 const char *label,
610 struct GNUNET_GNSRECORD_Block *block);
611
612/**
497 * Sign name and records 613 * Sign name and records
498 * 614 *
499 * @param key the private key 615 * @param key the private key
@@ -501,13 +617,41 @@ GNUNET_GNSRECORD_query_from_public_key (
501 * @param label the name for the records 617 * @param label the name for the records
502 * @param rd record data 618 * @param rd record data
503 * @param rd_count number of records in @a rd 619 * @param rd_count number of records in @a rd
620 * @param result the block buffer. Will be allocated.
621 * @return GNUNET_OK on success
504 */ 622 */
505struct GNUNET_GNSRECORD_Block * 623enum GNUNET_GenericReturnValue
506GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key, 624GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_PrivateKey *key,
507 struct GNUNET_TIME_Absolute expire, 625 struct GNUNET_TIME_Absolute expire,
508 const char *label, 626 const char *label,
509 const struct GNUNET_GNSRECORD_Data *rd, 627 const struct GNUNET_GNSRECORD_Data *rd,
510 unsigned int rd_count); 628 unsigned int rd_count,
629 struct GNUNET_GNSRECORD_Block **block);
630
631
632/**
633 * Create name and records but do not sign!
634 * Sign later with #GNUNET_GNSRECORD_block_sign().
635 * Cache derived public key (also keeps the
636 * private key in static memory, so do not use this function if
637 * keeping the private key in the process'es RAM is a major issue).
638 *
639 * @param key the private key
640 * @param expire block expiration
641 * @param label the name for the records
642 * @param rd record data
643 * @param rd_count number of records in @a rd
644 * @param result the block buffer. Will be allocated.
645 * @return GNUNET_OK on success.
646 */
647enum GNUNET_GenericReturnValue
648GNUNET_GNSRECORD_block_create_unsigned (const struct
649 GNUNET_CRYPTO_PrivateKey *key,
650 struct GNUNET_TIME_Absolute expire,
651 const char *label,
652 const struct GNUNET_GNSRECORD_Data *rd,
653 unsigned int rd_count,
654 struct GNUNET_GNSRECORD_Block **result);
511 655
512 656
513/** 657/**
@@ -520,13 +664,16 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key,
520 * @param label the name for the records 664 * @param label the name for the records
521 * @param rd record data 665 * @param rd record data
522 * @param rd_count number of records in @a rd 666 * @param rd_count number of records in @a rd
667 * @param result the block buffer. Will be allocated.
668 * @return GNUNET_OK on success.
523 */ 669 */
524struct GNUNET_GNSRECORD_Block * 670enum GNUNET_GenericReturnValue
525GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *key, 671GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_PrivateKey *key,
526 struct GNUNET_TIME_Absolute expire, 672 struct GNUNET_TIME_Absolute expire,
527 const char *label, 673 const char *label,
528 const struct GNUNET_GNSRECORD_Data *rd, 674 const struct GNUNET_GNSRECORD_Data *rd,
529 unsigned int rd_count); 675 unsigned int rd_count,
676 struct GNUNET_GNSRECORD_Block **result);
530 677
531 678
532/** 679/**
@@ -536,7 +683,7 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *key,
536 * @param block block to verify 683 * @param block block to verify
537 * @return #GNUNET_OK if the signature is valid 684 * @return #GNUNET_OK if the signature is valid
538 */ 685 */
539int 686enum GNUNET_GenericReturnValue
540GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); 687GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block);
541 688
542 689
@@ -551,10 +698,10 @@ GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block);
551 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was 698 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was
552 * not well-formed 699 * not well-formed
553 */ 700 */
554int 701enum GNUNET_GenericReturnValue
555GNUNET_GNSRECORD_block_decrypt ( 702GNUNET_GNSRECORD_block_decrypt (
556 const struct GNUNET_GNSRECORD_Block *block, 703 const struct GNUNET_GNSRECORD_Block *block,
557 const struct GNUNET_IDENTITY_PublicKey *zone_key, const char *label, 704 const struct GNUNET_CRYPTO_PublicKey *zone_key, const char *label,
558 GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls); 705 GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls);
559 706
560 707
@@ -565,7 +712,7 @@ GNUNET_GNSRECORD_block_decrypt (
565 * @param b another record 712 * @param b another record
566 * @return #GNUNET_YES if the records are equal, or #GNUNET_NO if not. 713 * @return #GNUNET_YES if the records are equal, or #GNUNET_NO if not.
567 */ 714 */
568int 715enum GNUNET_GenericReturnValue
569GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, 716GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a,
570 const struct GNUNET_GNSRECORD_Data *b); 717 const struct GNUNET_GNSRECORD_Data *b);
571 718
@@ -577,11 +724,14 @@ GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a,
577 * 724 *
578 * @param rd_count number of records given in @a rd 725 * @param rd_count number of records given in @a rd
579 * @param rd array of records 726 * @param rd array of records
727 * @param min minimum expiration time
580 * @return absolute expiration time 728 * @return absolute expiration time
581 */ 729 */
582struct GNUNET_TIME_Absolute 730struct GNUNET_TIME_Absolute
583GNUNET_GNSRECORD_record_get_expiration_time ( 731GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count,
584 unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd); 732 const struct
733 GNUNET_GNSRECORD_Data *rd,
734 struct GNUNET_TIME_Absolute min);
585 735
586 736
587/** 737/**
@@ -631,7 +781,7 @@ enum GNUNET_GenericReturnValue
631GNUNET_GNSRECORD_identity_from_data (const char *data, 781GNUNET_GNSRECORD_identity_from_data (const char *data,
632 size_t data_size, 782 size_t data_size,
633 uint32_t type, 783 uint32_t type,
634 struct GNUNET_IDENTITY_PublicKey *key); 784 struct GNUNET_CRYPTO_PublicKey *key);
635 785
636 786
637/** 787/**
@@ -645,7 +795,7 @@ GNUNET_GNSRECORD_identity_from_data (const char *data,
645 */ 795 */
646enum GNUNET_GenericReturnValue 796enum GNUNET_GenericReturnValue
647GNUNET_GNSRECORD_data_from_identity (const struct 797GNUNET_GNSRECORD_data_from_identity (const struct
648 GNUNET_IDENTITY_PublicKey *key, 798 GNUNET_CRYPTO_PublicKey *key,
649 char **data, 799 char **data,
650 size_t *data_size, 800 size_t *data_size,
651 uint32_t *type); 801 uint32_t *type);
@@ -661,6 +811,181 @@ GNUNET_GNSRECORD_data_from_identity (const struct
661enum GNUNET_GenericReturnValue 811enum GNUNET_GenericReturnValue
662GNUNET_GNSRECORD_is_zonekey_type (uint32_t type); 812GNUNET_GNSRECORD_is_zonekey_type (uint32_t type);
663 813
814/**
815 * Check if this type is a critical record.
816 *
817 * @param type the type to check
818 * @return GNUNET_YES if it is critical.
819 */
820enum GNUNET_GenericReturnValue
821GNUNET_GNSRECORD_is_critical (uint32_t type);
822
823/**
824 * Normalize namestore records: Check for consistency and
825 * expirations. Purge expired records. Returns a "clean" record set.
826 * Also returns the minimum expiration time this block should be
827 * published under.
828 * Also checks rules with respect to labels (e.g. no delegations under
829 * the empty label)
830 *
831 * @param label the label under which this set (supposed to be) stored.
832 * @param rd input records
833 * @param rd_count size of the @a rd and @a rd_public arrays
834 * @param rd_public where to write the converted records
835 * @param rd_count_public number of records written to @a rd_public
836 * @param min_expiry the minimum expiration of this set
837 * @param filter the record set filter, see GNUNET_GNSRECORD_Filter.
838 * @param emsg the error message if something went wrong
839 * @return GNUNET_OK if set could be normalized and is consistent
840 */
841enum GNUNET_GenericReturnValue
842GNUNET_GNSRECORD_normalize_record_set (const char *label,
843 const struct GNUNET_GNSRECORD_Data *rd,
844 unsigned int rd_count,
845 struct GNUNET_GNSRECORD_Data *rd_public,
846 unsigned int *rd_count_public,
847 struct GNUNET_TIME_Absolute *min_expiry,
848 enum GNUNET_GNSRECORD_Filter filter,
849 char **emsg);
850
851/**
852 * Check label for invalid characters.
853 *
854 * @param label the label to check
855 * @param emsg an error message (NULL if label is valid). Will be allocated.
856 * @return GNUNET_OK if label is valid.
857 */
858enum GNUNET_GenericReturnValue
859GNUNET_GNSRECORD_label_check (const char*label, char **emsg);
860
861/**
862 * Maximum length of a revocation
863 */
864#define GNUNET_MAX_POW_SIZE sizeof(struct GNUNET_GNSRECORD_PowP) \
865 + sizeof(struct GNUNET_CRYPTO_PublicKey) \
866 + 1024 // FIXME max sig_len
867
868/**
869 * The proof-of-work narrowing factor.
870 * The number of PoWs that are calculates as part of revocation.
871 */
872#define POW_COUNT 32
873
874
875GNUNET_NETWORK_STRUCT_BEGIN
876
877/**
878 * Struct for a proof of work as part of the revocation.
879 */
880struct GNUNET_GNSRECORD_PowP
881{
882 /**
883 * The timestamp of the revocation
884 */
885 struct GNUNET_TIME_AbsoluteNBO timestamp;
886
887 /**
888 * The TTL of this revocation (purely informational)
889 */
890 struct GNUNET_TIME_RelativeNBO ttl;
891
892 /**
893 * The PoWs
894 */
895 uint64_t pow[POW_COUNT] GNUNET_PACKED;
896
897 /** followed by the public key type, the key and a signature **/
898};
899
900
901/**
902 * The signature object we use for the PoW
903 */
904struct GNUNET_GNSRECORD_SignaturePurposePS
905{
906 /**
907 * The signature purpose
908 */
909 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
910
911 /**
912 * The timestamp of the revocation
913 */
914 struct GNUNET_TIME_AbsoluteNBO timestamp;
915
916 /** Followed by the zone public key type and key **/
917};
918
919GNUNET_NETWORK_STRUCT_END
920
921
922/**
923 * Handle to a running proof-of-work calculation.
924 */
925struct GNUNET_GNSRECORD_PowCalculationHandle;
926
927
928/**
929 * Check if the given proof-of-work is valid.
930 *
931 * @param pow proof of work
932 * @param matching_bits how many bits must match (configuration)
933 * @param epoch_duration length of single epoch in configuration
934 * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
935 */
936enum GNUNET_GenericReturnValue
937GNUNET_GNSRECORD_check_pow (const struct GNUNET_GNSRECORD_PowP *pow,
938 unsigned int matching_bits,
939 struct GNUNET_TIME_Relative epoch_duration);
940
941
942/**
943 * Initializes a fresh PoW computation.
944 *
945 * @param key the key to calculate the PoW for.
946 * @param pow the pow object to work with in the calculation.
947 */
948void
949GNUNET_GNSRECORD_pow_init (const struct GNUNET_CRYPTO_PrivateKey *key,
950 struct GNUNET_GNSRECORD_PowP *pow);
951
952
953/**
954 * Starts a proof-of-work calculation given the pow object as well as
955 * target epochs and difficulty.
956 *
957 * @param pow the PoW to based calculations on.
958 * @param epochs the number of epochs for which the PoW must be valid.
959 * @param difficulty the base difficulty of the PoW.
960 * @return a handle for use in PoW rounds
961 */
962struct GNUNET_GNSRECORD_PowCalculationHandle*
963GNUNET_GNSRECORD_pow_start (struct GNUNET_GNSRECORD_PowP *pow,
964 int epochs,
965 unsigned int difficulty);
966
967
968/**
969 * Calculate a single round in the key revocation PoW.
970 *
971 * @param pc handle to the PoW, initially called with NULL.
972 * @return GNUNET_YES if the @a pow is acceptable, GNUNET_NO if not
973 */
974enum GNUNET_GenericReturnValue
975GNUNET_GNSRECORD_pow_round (struct GNUNET_GNSRECORD_PowCalculationHandle *pc);
976
977size_t
978GNUNET_GNSRECORD_proof_get_size (const struct GNUNET_GNSRECORD_PowP *pow);
979
980/**
981 * Stop a PoW calculation
982 *
983 * @param pc the calculation to clean up
984 * @return #GNUNET_YES if pow valid, #GNUNET_NO if pow was set but is not
985 * valid
986 */
987void
988GNUNET_GNSRECORD_pow_stop (struct GNUNET_GNSRECORD_PowCalculationHandle *pc);
664 989
665#if 0 /* keep Emacsens' auto-indent happy */ 990#if 0 /* keep Emacsens' auto-indent happy */
666{ 991{
@@ -672,3 +997,5 @@ GNUNET_GNSRECORD_is_zonekey_type (uint32_t type);
672#endif 997#endif
673 998
674/** @} */ /* end of group */ 999/** @} */ /* end of group */
1000
1001/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_gnsrecord_plugin.h b/src/include/gnunet_gnsrecord_plugin.h
index aec22c3af..f55934b60 100644
--- a/src/include/gnunet_gnsrecord_plugin.h
+++ b/src/include/gnunet_gnsrecord_plugin.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -105,6 +108,18 @@ typedef const char *
105(*GNUNET_GNSRECORD_NumberToTypenameFunction) (void *cls, 108(*GNUNET_GNSRECORD_NumberToTypenameFunction) (void *cls,
106 uint32_t type); 109 uint32_t type);
107 110
111/**
112 * Function called to check for critical records.
113 *
114 * @param cls closure
115 * @param type number of a type to check
116 * @return GNUNET_YES if critical, otherwise GNUNET_NO
117 */
118typedef enum GNUNET_GenericReturnValue
119(*GNUNET_GNSRECORD_IsCriticalFunction) (void *cls,
120 uint32_t type);
121
122
108 123
109/** 124/**
110 * Each plugin is required to return a pointer to a struct of this 125 * Each plugin is required to return a pointer to a struct of this
@@ -136,10 +151,17 @@ struct GNUNET_GNSRECORD_PluginFunctions
136 * Number to typename. 151 * Number to typename.
137 */ 152 */
138 GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename; 153 GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename;
154
155 /**
156 * Is critical.
157 */
158 GNUNET_GNSRECORD_IsCriticalFunction is_critical;
139}; 159};
140 160
141/** @} */ /* end of group */ 161/** @} */ /* end of group */
142 162
163/** @} */ /* end of group addition */
164
143#if 0 /* keep Emacsens' auto-indent happy */ 165#if 0 /* keep Emacsens' auto-indent happy */
144{ 166{
145#endif 167#endif
diff --git a/src/include/gnunet_hello_lib.h b/src/include/gnunet_hello_lib.h
deleted file mode 100644
index 74eca999d..000000000
--- a/src/include/gnunet_hello_lib.h
+++ /dev/null
@@ -1,539 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2010, 2011 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 * @file
24 * Helper library for handling HELLOs
25 *
26 * @defgroup hello Hello library
27 * Helper library for handling HELLOs
28 *
29 * @see [Documentation](https://gnunet.org/gnunets-hostlist-subsystem)
30 *
31 * @{
32 */
33
34#ifndef GNUNET_HELLO_LIB_H
35#define GNUNET_HELLO_LIB_H
36
37#ifdef __cplusplus
38extern "C" {
39#if 0 /* keep Emacsens' auto-indent happy */
40}
41#endif
42#endif
43
44#include "gnunet_util_lib.h"
45
46/**
47 * Prefix that every HELLO URI must start with.
48 */
49#define GNUNET_HELLO_URI_PREFIX "gnunet://hello/"
50
51/**
52 * Prefix that every FRIEND HELLO URI must start with.
53 */
54#define GNUNET_FRIEND_HELLO_URI_PREFIX "gnunet://friend-hello/"
55
56/**
57 * Separator used in HELLO URI
58 */
59#define GNUNET_HELLO_URI_SEP '+'
60
61
62/**
63 * Additional local information about an address
64 *
65 * These information are only valid for the local peer and are not serialized
66 * when a #GNUNET_HELLO_Message is created
67 */
68enum GNUNET_HELLO_AddressInfo
69{
70 /**
71 * No additional information
72 */
73 GNUNET_HELLO_ADDRESS_INFO_NONE = 0,
74
75 /**
76 * This is an inbound address and cannot be used to initiate an outbound
77 * connection to another peer
78 */
79 GNUNET_HELLO_ADDRESS_INFO_INBOUND = 1
80};
81
82
83/**
84 * An address for communicating with a peer. We frequently
85 * need this tuple and the components cannot really be
86 * separated. This is NOT the format that would be used
87 * on the wire.
88 */
89struct GNUNET_HELLO_Address
90{
91 /**
92 * For which peer is this an address?
93 */
94 struct GNUNET_PeerIdentity peer;
95
96 /**
97 * Name of the transport plugin enabling the communication using
98 * this address.
99 */
100 const char *transport_name;
101
102 /**
103 * Binary representation of the address (plugin-specific).
104 */
105 const void *address;
106
107 /**
108 * Number of bytes in @e address.
109 */
110 size_t address_length;
111
112 /**
113 * Extended information about address
114 *
115 * This field contains additional #GNUNET_HELLO_AddressInfo flags e.g.
116 * to indicate an address is inbound and cannot be used to initiate an
117 * outbound connection.
118 *
119 * These information are only valid for the local peer and are not serialized
120 * when a #GNUNET_HELLO_Message is created
121 */
122 enum GNUNET_HELLO_AddressInfo local_info;
123};
124
125
126/**
127 * Allocate an address struct.
128 *
129 * @param peer the peer
130 * @param transport_name plugin name
131 * @param address binary address
132 * @param address_length number of bytes in @a address
133 * @param local_info additional local information for the address
134 * @return the address struct
135 */
136struct GNUNET_HELLO_Address *
137GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer,
138 const char *transport_name,
139 const void *address,
140 size_t address_length,
141 enum GNUNET_HELLO_AddressInfo local_info);
142
143
144/**
145 * Copy an address struct.
146 *
147 * @param address address to copy
148 * @return a copy of the address struct
149 */
150struct GNUNET_HELLO_Address *
151GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address);
152
153
154/**
155 * Compare two addresses. Does NOT compare the peer identity,
156 * that is assumed already to match!
157 *
158 * @param a1 first address
159 * @param a2 second address
160 * @return 0 if the addresses are equal, -1 if @a a1< @a a2, 1 if @a a1> @a a2.
161 */
162int
163GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1,
164 const struct GNUNET_HELLO_Address *a2);
165
166
167/**
168 * Get the size of an address struct.
169 *
170 * @param address address
171 * @return the size
172 */
173size_t
174GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address);
175
176
177/**
178 * Check if an address has a local option set
179 *
180 * @param address the address to check
181 * @param option the respective option to check for
182 * @return #GNUNET_YES or #GNUNET_NO
183 */
184int
185GNUNET_HELLO_address_check_option (const struct GNUNET_HELLO_Address *address,
186 enum GNUNET_HELLO_AddressInfo option);
187
188
189/**
190 * Free an address.
191 *
192 * @param addr address to free
193 */
194#define GNUNET_HELLO_address_free(addr) GNUNET_free (addr)
195
196
197GNUNET_NETWORK_STRUCT_BEGIN
198
199/**
200 * A HELLO message is used to exchange information about
201 * transports with other peers. This struct is always
202 * followed by the actual network addresses which have
203 * the format:
204 *
205 * 1) transport-name (0-terminated)
206 * 2) address-length (uint16_t, network byte order; possibly
207 * unaligned!)
208 * 3) address expiration (`struct GNUNET_TIME_AbsoluteNBO`); possibly
209 * unaligned!)
210 * 4) address (address-length bytes; possibly unaligned!)
211 */
212struct GNUNET_HELLO_Message
213{
214 /**
215 * Type will be #GNUNET_MESSAGE_TYPE_HELLO.
216 */
217 struct GNUNET_MessageHeader header;
218
219 /**
220 * Use in F2F mode: Do not gossip this HELLO message
221 */
222 uint32_t friend_only GNUNET_PACKED;
223
224 /**
225 * The public key of the peer.
226 */
227 struct GNUNET_CRYPTO_EddsaPublicKey publicKey;
228};
229GNUNET_NETWORK_STRUCT_END
230
231
232/**
233 * Return HELLO type
234 *
235 * @param h HELLO Message to test
236 * @return #GNUNET_YES for friend-only or #GNUNET_NO otherwise
237 */
238int
239GNUNET_HELLO_is_friend_only (const struct GNUNET_HELLO_Message *h);
240
241
242/**
243 * Copy the given address information into
244 * the given buffer using the format of HELLOs.
245 *
246 * @param address address to add
247 * @param expiration expiration for the address
248 * @param target where to copy the address
249 * @param max maximum number of bytes to copy to @a target
250 * @return number of bytes copied, 0 if
251 * the target buffer was not big enough.
252 */
253size_t
254GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address,
255 struct GNUNET_TIME_Absolute expiration,
256 char *target,
257 size_t max);
258
259
260/**
261 * Callback function used to fill a buffer of max bytes with a list of
262 * addresses in the format used by HELLOs. Should use
263 * #GNUNET_HELLO_add_address() as a helper function.
264 *
265 * @param cls closure
266 * @param max maximum number of bytes that can be written to @a buf
267 * @param buf where to write the address information
268 * @return number of bytes written or 0, #GNUNET_SYSERR to signal the
269 * end of the iteration.
270 */
271typedef ssize_t
272(*GNUNET_HELLO_GenerateAddressListCallback) (void *cls,
273 size_t max,
274 void *buf);
275
276
277/**
278 * Construct a HELLO message given the public key,
279 * expiration time and an iterator that spews the
280 * transport addresses.
281 *
282 * If friend only is set to #GNUNET_YES we create a FRIEND_HELLO which
283 * will not be gossiped to other peers.
284 *
285 * @param public_key public key to include in the HELLO
286 * @param addrgen callback to invoke to get addresses
287 * @param addrgen_cls closure for @a addrgen
288 * @param friend_only should the returned HELLO be only visible to friends?
289 * @return the hello message
290 */
291struct GNUNET_HELLO_Message *
292GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EddsaPublicKey *public_key,
293 GNUNET_HELLO_GenerateAddressListCallback addrgen,
294 void *addrgen_cls,
295 int friend_only);
296
297
298/**
299 * Return the size of the given HELLO message.
300 *
301 * @param hello to inspect
302 * @return the size, 0 if HELLO is invalid
303 */
304uint16_t
305GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello);
306
307
308/**
309 * Construct a HELLO message by merging the
310 * addresses in two existing HELLOs (which
311 * must be for the same peer).
312 *
313 * @param h1 first HELLO message
314 * @param h2 the second HELLO message
315 * @return the combined hello message
316 */
317struct GNUNET_HELLO_Message *
318GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1,
319 const struct GNUNET_HELLO_Message *h2);
320
321
322/**
323 * Test if two HELLO messages contain the same addresses.
324 * If they only differ in expiration time, the lowest
325 * expiration time larger than 'now' where they differ
326 * is returned.
327 *
328 * @param h1 first HELLO message
329 * @param h2 the second HELLO message
330 * @param now time to use for deciding which addresses have
331 * expired and should not be considered at all
332 * @return absolute time forever if the two HELLOs are
333 * totally identical; smallest timestamp >= now if
334 * they only differ in timestamps;
335 * zero if the some addresses with expirations >= now
336 * do not match at all
337 */
338struct GNUNET_TIME_Absolute
339GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1,
340 const struct GNUNET_HELLO_Message *h2,
341 struct GNUNET_TIME_Absolute now);
342
343
344/**
345 * Iterator callback to go over all addresses.
346 *
347 * @param cls closure
348 * @param address the address
349 * @param expiration expiration time
350 * @return #GNUNET_OK to keep the address,
351 * #GNUNET_NO to delete it from the HELLO
352 * #GNUNET_SYSERR to stop iterating (but keep current address)
353 */
354typedef int (*GNUNET_HELLO_AddressIterator) (
355 void *cls,
356 const struct GNUNET_HELLO_Address *address,
357 struct GNUNET_TIME_Absolute expiration);
358
359
360/**
361 * When does the last address in the given HELLO expire?
362 *
363 * @param msg HELLO to inspect
364 * @return time the last address expires, 0 if there are no addresses in the HELLO
365 */
366struct GNUNET_TIME_Absolute
367GNUNET_HELLO_get_last_expiration (const struct GNUNET_HELLO_Message *msg);
368
369
370/**
371 * Iterate over all of the addresses in the HELLO.
372 *
373 * @param msg HELLO to iterate over; client does not need to
374 * have verified that msg is well-formed (beyond starting
375 * with a GNUNET_MessageHeader of the right type).
376 * @param return_modified if a modified copy should be returned,
377 * otherwise NULL will be returned
378 * @param it iterator to call on each address
379 * @param it_cls closure for @a it
380 * @return the modified HELLO or NULL
381 */
382struct GNUNET_HELLO_Message *
383GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg,
384 int return_modified,
385 GNUNET_HELLO_AddressIterator it,
386 void *it_cls);
387
388
389/**
390 * Iterate over addresses in @a new_hello that are NOT already present
391 * in @a old_hello. Note that if the address is present in @a old_hello
392 * but the expiration time in @a new_hello is more recent, the
393 * iterator is also called.
394 *
395 * @param new_hello a HELLO message
396 * @param old_hello a HELLO message
397 * @param expiration_limit ignore addresses in old_hello
398 * that expired before the given time stamp
399 * @param it iterator to call on each address
400 * @param it_cls closure for @a it
401 */
402void
403GNUNET_HELLO_iterate_new_addresses (
404 const struct GNUNET_HELLO_Message *new_hello,
405 const struct GNUNET_HELLO_Message *old_hello,
406 struct GNUNET_TIME_Absolute expiration_limit,
407 GNUNET_HELLO_AddressIterator it,
408 void *it_cls);
409
410
411/**
412 * Get the peer identity from a HELLO message.
413 *
414 * @param hello the hello message
415 * @param peer where to store the peer's identity
416 * @return #GNUNET_SYSERR if the HELLO was malformed
417 */
418int
419GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello,
420 struct GNUNET_PeerIdentity *peer);
421
422
423/**
424 * Get the header from a HELLO message, used so other code
425 * can correctly send HELLO messages.
426 *
427 * @param hello the hello message
428 *
429 * @return header or NULL if the HELLO was malformed
430 */
431struct GNUNET_MessageHeader *
432GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello);
433
434
435/**
436 * Helper function to load/access transport plugins.
437 * FIXME: pass closure!
438 *
439 * @param name name of the transport plugin to load
440 * @return NULL if a plugin with name @a name is not known/loadable
441 */
442typedef struct GNUNET_TRANSPORT_PluginFunctions *(
443*GNUNET_HELLO_TransportPluginsFind) (const char *name);
444
445
446/**
447 * Compose a hello URI string from a hello message.
448 *
449 * @param hello Hello message
450 * @param plugins_find Function to find transport plugins by name
451 * @return Hello URI string
452 */
453char *
454GNUNET_HELLO_compose_uri (const struct GNUNET_HELLO_Message *hello,
455 GNUNET_HELLO_TransportPluginsFind plugins_find);
456
457
458/**
459 * Parse a hello URI string to a hello message.
460 *
461 * @param uri URI string to parse
462 * @param pubkey Pointer to struct where public key is parsed
463 * @param hello Pointer to struct where hello message is parsed
464 * @param plugins_find Function to find transport plugins by name
465 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the URI was invalid, #GNUNET_NO on other errors
466 */
467int
468GNUNET_HELLO_parse_uri (const char *uri,
469 struct GNUNET_CRYPTO_EddsaPublicKey *pubkey,
470 struct GNUNET_HELLO_Message **hello,
471 GNUNET_HELLO_TransportPluginsFind plugins_find);
472
473
474/* NG API */
475#include "gnunet_nt_lib.h"
476
477
478/**
479 * Build address record by signing raw information with private key.
480 *
481 * @param address text address to sign
482 * @param nt network type of @a address
483 * @param mono_time when was @a address valid
484 * @param private_key signing key to use
485 * @param result[out] where to write address record (allocated)
486 * @param result_size[out] set to size of @a result
487 */
488void
489GNUNET_HELLO_sign_address (
490 const char *address,
491 enum GNUNET_NetworkType nt,
492 struct GNUNET_TIME_Absolute mono_time,
493 const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key,
494 void **result,
495 size_t *result_size);
496
497
498/**
499 * Check signature and extract address record.
500 *
501 * @param raw raw signed address
502 * @param raw_size size of @a raw
503 * @param pid public key to use for signature verification
504 * @param nt[out] set to network type
505 * @param mono_time[out] when was the address generated
506 * @return NULL on error, otherwise the address
507 */
508char *
509GNUNET_HELLO_extract_address (const void *raw,
510 size_t raw_size,
511 const struct GNUNET_PeerIdentity *pid,
512 enum GNUNET_NetworkType *nt,
513 struct GNUNET_TIME_Absolute *mono_time);
514
515
516/**
517 * Given an address as a string, extract the prefix that identifies
518 * the communicator offering transmissions to that address.
519 *
520 * @param address a peer's address
521 * @return NULL if the address is mal-formed, otherwise the prefix
522 */
523char *
524GNUNET_HELLO_address_to_prefix (const char *address);
525
526
527#if 0 /* keep Emacsens' auto-indent happy */
528{
529#endif
530#ifdef __cplusplus
531}
532#endif
533
534/* ifndef GNUNET_HELLO_LIB_H */
535#endif
536
537/** @} */ /* end of group */
538
539/* end of gnunet_hello_lib.h */
diff --git a/src/include/gnunet_hello_uri_lib.h b/src/include/gnunet_hello_uri_lib.h
new file mode 100644
index 000000000..aecda0885
--- /dev/null
+++ b/src/include/gnunet_hello_uri_lib.h
@@ -0,0 +1,304 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2022 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @addtogroup Backbone
23 * @{
24 *
25 * @author Christian Grothoff
26 * @file
27 * Helper library for handling HELLO URIs
28 *
29 * @defgroup hello_uri Hello_Uri library
30 * Helper library for handling HELLO URIs
31 *
32 * @{
33 */
34
35#ifndef GNUNET_HELLO_URI_LIB_H
36#define GNUNET_HELLO_URI_LIB_H
37
38#ifdef __cplusplus
39extern "C" {
40#if 0 /* keep Emacsens' auto-indent happy */
41}
42#endif
43#endif
44
45
46#include "gnunet_util_lib.h"
47
48
49/**
50 * Context for building (or parsing) HELLO URIs.
51 */
52struct GNUNET_HELLO_Builder;
53
54
55/**
56 * For how long are HELLO signatures valid?
57 */
58#define GNUNET_HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply ( \
59 GNUNET_TIME_UNIT_DAYS, 2)
60
61
62/**
63 * Allocate builder.
64 *
65 * @param pid peer the builder is for
66 * @return new builder
67 */
68struct GNUNET_HELLO_Builder *
69GNUNET_HELLO_builder_new (const struct GNUNET_PeerIdentity *pid);
70
71
72/**
73 * Get the PeerIdentity for this builder.
74 */
75const struct GNUNET_PeerIdentity *
76GNUNET_HELLO_builder_get_id (const struct GNUNET_HELLO_Builder *builder);
77
78
79/**
80 * Release resources of a @a builder.
81 *
82 * @param[in] builder to free
83 */
84void
85GNUNET_HELLO_builder_free (struct GNUNET_HELLO_Builder *builder);
86
87
88/**
89 * Parse @a msg into builder.
90 *
91 * @param msg message to parse
92 * @return builder, NULL on failure
93 */
94struct GNUNET_HELLO_Builder *
95GNUNET_HELLO_builder_from_msg (const struct GNUNET_MessageHeader *msg);
96
97
98/**
99 * Parse @a block into builder.
100 *
101 * @param block DHT block to parse
102 * @param block_size number of bytes in @a block
103 * @return builder, NULL on failure
104 */
105struct GNUNET_HELLO_Builder *
106GNUNET_HELLO_builder_from_block (const void *block,
107 size_t block_size);
108
109
110/**
111 * Parse GNUnet HELLO @a url into builder.
112 *
113 * @param url URL to parse
114 * @return builder, NULL on failure
115 */
116struct GNUNET_HELLO_Builder *
117GNUNET_HELLO_builder_from_url (const char *url);
118
119
120/**
121 * Get the expiration time for this HELLO.
122 *
123 * @param msg The hello msg.
124 * @return The expiration time.
125 */
126struct GNUNET_TIME_Absolute
127GNUNET_HELLO_builder_get_expiration_time (const struct
128 GNUNET_MessageHeader *msg);
129
130
131/**
132 * Generate envelope with GNUnet HELLO message (including
133 * peer ID) from a @a builder
134 *
135 * @param builder builder to serialize
136 * @param priv private key to use to sign the result
137 * @return HELLO message matching @a builder
138 */
139struct GNUNET_MQ_Envelope *
140GNUNET_HELLO_builder_to_env (const struct GNUNET_HELLO_Builder *builder,
141 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
142 struct GNUNET_TIME_Relative expiration_time);
143
144
145/**
146 * Generate DHT HELLO message (without peer ID) from a @a builder
147 *
148 * @param builder builder to serialize
149 * @param priv private key to use to sign the result
150 * @return HELLO message matching @a builder
151 */
152struct GNUNET_MessageHeader *
153GNUNET_HELLO_builder_to_dht_hello_msg (
154 const struct GNUNET_HELLO_Builder *builder,
155 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
156 struct GNUNET_TIME_Relative expiration_time);
157
158
159/**
160 * Generate GNUnet HELLO URI from a @a builder
161 *
162 * @param builder builder to serialize
163 * @param priv private key to use to sign the result
164 * @return hello URI
165 */
166char *
167GNUNET_HELLO_builder_to_url (const struct GNUNET_HELLO_Builder *builder,
168 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv);
169
170/**
171 * Generate DHT block from a @a builder
172 *
173 * @param builder the builder to serialize
174 * @param priv private key to use to sign the result
175 * @param[out] block where to write the block, NULL to only calculate @a block_size
176 * @param[in,out] block_size input is number of bytes available in @a block,
177 * output is number of bytes needed in @a block
178 * @return #GNUNET_OK on success, #GNUNET_NO if @a block_size was too small
179 * or if @a block was NULL
180 */
181enum GNUNET_GenericReturnValue
182GNUNET_HELLO_builder_to_block (const struct GNUNET_HELLO_Builder *builder,
183 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
184 void *block,
185 size_t *block_size,
186 struct GNUNET_TIME_Relative expiration_time);
187
188
189/**
190 * Add individual @a address to the @a builder
191 *
192 * @param[in,out] builder to update
193 * @param address address URI to add
194 * @return #GNUNET_OK on success, #GNUNET_NO if @a address was already
195 * in @a builder
196 */
197enum GNUNET_GenericReturnValue
198GNUNET_HELLO_builder_add_address (struct GNUNET_HELLO_Builder *builder,
199 const char *address);
200
201
202/**
203 * Remove individual @a address from the @a builder
204 *
205 * @param[in,out] builder to update
206 * @param address address URI to remove
207 * @return #GNUNET_OK on success, #GNUNET_NO if @a address was not
208 * in @a builder
209 */
210enum GNUNET_GenericReturnValue
211GNUNET_HELLO_builder_del_address (struct GNUNET_HELLO_Builder *builder,
212 const char *address);
213
214
215/**
216 * Callback function used to extract URIs from a builder.
217 *
218 * @param cls closure
219 * @param uri one of the URIs
220 */
221typedef void
222(*GNUNET_HELLO_UriCallback) (void *cls,
223 const struct GNUNET_PeerIdentity* pid,
224 const char *uri);
225
226
227/**
228 * Iterate over URIs in a builder.
229 *
230 * @param builder builder to iterate over
231 * @param uc callback invoked for each URI, can be NULL
232 * @param uc_cls closure for @a addrgen
233 * @return pid of the peer the @a builder is for, can be NULL
234 */
235const struct GNUNET_PeerIdentity *
236GNUNET_HELLO_builder_iterate (const struct GNUNET_HELLO_Builder *builder,
237 GNUNET_HELLO_UriCallback uc,
238 void *uc_cls);
239
240
241/**
242 * Convert a DHT @a hello message to a HELLO @a block.
243 *
244 * @param hello the HELLO message
245 * @param pid peer that created the @a hello
246 * @param[out] block set to the HELLO block
247 * @param[out] block_size set to number of bytes in @a block
248 * @param[out] block_expiration set to expiration time of @a block
249 * @return #GNUNET_OK on success,
250 * #GNUNET_NO if the @a hello is expired (@a block is set!)
251 * #GNUNET_SYSERR if @a hello is invalid (@a block will be set to NULL)
252 */
253enum GNUNET_GenericReturnValue
254GNUNET_HELLO_dht_msg_to_block (const struct GNUNET_MessageHeader *hello,
255 const struct GNUNET_PeerIdentity *pid,
256 void **block,
257 size_t *block_size,
258 struct GNUNET_TIME_Absolute *block_expiration);
259
260
261/**
262 * Given an address as a string, extract the prefix that identifies
263 * the communicator offering transmissions to that address.
264 *
265 * @param address a peer's address
266 * @return NULL if the address is mal-formed, otherwise the prefix
267 */
268char *
269GNUNET_HELLO_address_to_prefix (const char *address);
270
271/**
272 * Build address record by signing raw information with private key.
273 *
274 * @param address text address to sign
275 * @param nt network type of @a address
276 * @param mono_time when was @a address valid
277 * @param private_key signing key to use
278 * @param[out] result where to write address record (allocated)
279 * @param[out] result_size set to size of @a result
280 */
281void
282GNUNET_HELLO_sign_address (
283 const char *address,
284 enum GNUNET_NetworkType nt,
285 struct GNUNET_TIME_Absolute mono_time,
286 const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key,
287 void **result,
288 size_t *result_size);
289
290#if 0 /* keep Emacsens' auto-indent happy */
291{
292#endif
293#ifdef __cplusplus
294}
295#endif
296
297/* ifndef GNUNET_HELLO_URI_LIB_H */
298#endif
299
300/** @} */ /* end of group */
301
302/** @} */ /* end of group addition */
303
304/* end of gnunet_hello_uri_lib.h */
diff --git a/src/include/gnunet_helper_lib.h b/src/include/gnunet_helper_lib.h
index b54120204..57630c45c 100644
--- a/src/include/gnunet_helper_lib.h
+++ b/src/include/gnunet_helper_lib.h
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Philipp Toelke 26 * @author Philipp Toelke
23 * @author Christian Grothoff 27 * @author Christian Grothoff
24 * 28 *
@@ -34,10 +38,14 @@
34 * @{ 38 * @{
35 */ 39 */
36 40
41#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
42#error "Only <gnunet_util_lib.h> can be included directly."
43#endif
44
37#ifndef GNUNET_HELPER_LIB_H 45#ifndef GNUNET_HELPER_LIB_H
38#define GNUNET_HELPER_LIB_H 46#define GNUNET_HELPER_LIB_H
39 47
40#include "gnunet_scheduler_lib.h" 48
41#include "gnunet_mst_lib.h" 49#include "gnunet_mst_lib.h"
42 50
43 51
@@ -91,8 +99,9 @@ GNUNET_HELPER_start (int with_control_pipe,
91 * stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper 99 * stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper
92 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error 100 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error
93 */ 101 */
94int 102enum GNUNET_GenericReturnValue
95GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, int soft_kill); 103GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h,
104 int soft_kill);
96 105
97 106
98/** 107/**
@@ -103,7 +112,7 @@ GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, int soft_kill);
103 * @param h the helper handle 112 * @param h the helper handle
104 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error 113 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error
105 */ 114 */
106int 115enum GNUNET_GenericReturnValue
107GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h); 116GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h);
108 117
109 118
@@ -136,8 +145,10 @@ GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h, int soft_kill);
136 * #GNUNET_NO if helper process died 145 * #GNUNET_NO if helper process died
137 * #GNUNET_SYSERR during GNUNET_HELPER_destroy 146 * #GNUNET_SYSERR during GNUNET_HELPER_destroy
138 */ 147 */
139typedef void (*GNUNET_HELPER_Continuation)(void *cls, 148typedef void
140 int result); 149(*GNUNET_HELPER_Continuation)(
150 void *cls,
151 enum GNUNET_GenericReturnValue result);
141 152
142 153
143/** 154/**
@@ -162,7 +173,7 @@ struct GNUNET_HELPER_SendHandle;
162struct GNUNET_HELPER_SendHandle * 173struct GNUNET_HELPER_SendHandle *
163GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h, 174GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h,
164 const struct GNUNET_MessageHeader *msg, 175 const struct GNUNET_MessageHeader *msg,
165 int can_drop, 176 bool can_drop,
166 GNUNET_HELPER_Continuation cont, 177 GNUNET_HELPER_Continuation cont,
167 void *cont_cls); 178 void *cont_cls);
168 179
@@ -181,3 +192,5 @@ GNUNET_HELPER_send_cancel (struct GNUNET_HELPER_SendHandle *sh);
181/* end of include guard: GNUNET_HELPER_LIB_H */ 192/* end of include guard: GNUNET_HELPER_LIB_H */
182 193
183/** @} */ /* end of group */ 194/** @} */ /* end of group */
195
196/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_identity_service.h b/src/include/gnunet_identity_service.h
index c123983e2..270f4d26f 100644
--- a/src/include/gnunet_identity_service.h
+++ b/src/include/gnunet_identity_service.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V. 3 Copyright (C) 2013--2023 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup egos Ego management
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -42,6 +45,7 @@
42#ifndef GNUNET_IDENTITY_SERVICE_H 45#ifndef GNUNET_IDENTITY_SERVICE_H
43#define GNUNET_IDENTITY_SERVICE_H 46#define GNUNET_IDENTITY_SERVICE_H
44 47
48#include "gnunet_common.h"
45#ifdef __cplusplus 49#ifdef __cplusplus
46extern "C" { 50extern "C" {
47#if 0 /* keep Emacsens' auto-indent happy */ 51#if 0 /* keep Emacsens' auto-indent happy */
@@ -49,6 +53,7 @@ extern "C" {
49#endif 53#endif
50#endif 54#endif
51 55
56
52#include "gnunet_util_lib.h" 57#include "gnunet_util_lib.h"
53 58
54 59
@@ -57,20 +62,6 @@ extern "C" {
57 */ 62 */
58#define GNUNET_IDENTITY_VERSION 0x00000100 63#define GNUNET_IDENTITY_VERSION 0x00000100
59 64
60enum GNUNET_IDENTITY_KeyType
61{
62 /**
63 * The identity type. The value is the same as the
64 * PKEY record type.
65 */
66 GNUNET_IDENTITY_TYPE_ECDSA = 65536,
67
68 /**
69 * EDDSA identity. The value is the same as the EDKEY
70 * record type.
71 */
72 GNUNET_IDENTITY_TYPE_EDDSA = 65556
73};
74 65
75/** 66/**
76 * Handle to access the identity service. 67 * Handle to access the identity service.
@@ -82,88 +73,6 @@ struct GNUNET_IDENTITY_Handle;
82 */ 73 */
83struct GNUNET_IDENTITY_Ego; 74struct GNUNET_IDENTITY_Ego;
84 75
85
86/**
87 * A private key for an identity as per LSD0001.
88 */
89struct GNUNET_IDENTITY_PrivateKey
90{
91 /**
92 * Type of public key.
93 * Defined by the GNS zone type value.
94 * In NBO.
95 */
96 uint32_t type;
97
98 union
99 {
100 /**
101 * An ECDSA identity key.
102 */
103 struct GNUNET_CRYPTO_EcdsaPrivateKey ecdsa_key;
104
105 /**
106 * AN EdDSA identtiy key
107 */
108 struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_key;
109 };
110};
111
112
113/**
114 * An identity key as per LSD0001.
115 */
116struct GNUNET_IDENTITY_PublicKey
117{
118 /**
119 * Type of public key.
120 * Defined by the GNS zone type value.
121 * In NBO.
122 */
123 uint32_t type;
124
125 union
126 {
127 /**
128 * An ECDSA identity key.
129 */
130 struct GNUNET_CRYPTO_EcdsaPublicKey ecdsa_key;
131
132 /**
133 * AN EdDSA identtiy key
134 */
135 struct GNUNET_CRYPTO_EddsaPublicKey eddsa_key;
136 };
137};
138
139
140/**
141 * An identity signature as per LSD0001.
142 */
143struct GNUNET_IDENTITY_Signature
144{
145 /**
146 * Type of signature.
147 * Defined by the GNS zone type value.
148 * In NBO.
149 */
150 uint32_t type;
151
152 union
153 {
154 /**
155 * An ECDSA signature
156 */
157 struct GNUNET_CRYPTO_EcdsaSignature ecdsa_signature;
158
159 /**
160 * AN EdDSA signature
161 */
162 struct GNUNET_CRYPTO_EddsaSignature eddsa_signature;
163 };
164};
165
166
167/** 76/**
168 * Handle for an operation with the identity service. 77 * Handle for an operation with the identity service.
169 */ 78 */
@@ -176,7 +85,7 @@ struct GNUNET_IDENTITY_Operation;
176 * @param ego the ego 85 * @param ego the ego
177 * @return associated ECC key, valid as long as the ego is valid 86 * @return associated ECC key, valid as long as the ego is valid
178 */ 87 */
179const struct GNUNET_IDENTITY_PrivateKey * 88const struct GNUNET_CRYPTO_PrivateKey *
180GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego); 89GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego);
181 90
182 91
@@ -197,7 +106,17 @@ GNUNET_IDENTITY_ego_get_anonymous (void);
197 */ 106 */
198void 107void
199GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, 108GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego,
200 struct GNUNET_IDENTITY_PublicKey *pk); 109 struct GNUNET_CRYPTO_PublicKey *pk);
110
111
112/**
113 * Obtain the name associated with an ego.
114 *
115 * @param ego the ego
116 * @return associated name, valid as long as the ego is valid
117 */
118const char*
119GNUNET_IDENTITY_ego_get_name (const struct GNUNET_IDENTITY_Ego *ego);
201 120
202 121
203/** 122/**
@@ -275,11 +194,11 @@ GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *id,
275 * been completed. 194 * been completed.
276 * 195 *
277 * @param cls closure 196 * @param cls closure
278 * @param emsg NULL on success, otherwise an error message 197 * @param ec the #GNUNET_ErrorCode
279 */ 198 */
280typedef void 199typedef void
281(*GNUNET_IDENTITY_Continuation) (void *cls, 200(*GNUNET_IDENTITY_Continuation) (void *cls,
282 const char *emsg); 201 enum GNUNET_ErrorCode ec);
283 202
284 203
285/** 204/**
@@ -315,13 +234,13 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h);
315 * 234 *
316 * @param cls closure 235 * @param cls closure
317 * @param pk private key, NULL on error 236 * @param pk private key, NULL on error
318 * @param emsg error message, NULL on success 237 * @param ec the #GNUNET_ErrorCode
319 */ 238 */
320typedef void 239typedef void
321(*GNUNET_IDENTITY_CreateContinuation) ( 240(*GNUNET_IDENTITY_CreateContinuation) (
322 void *cls, 241 void *cls,
323 const struct GNUNET_IDENTITY_PrivateKey *pk, 242 const struct GNUNET_CRYPTO_PrivateKey *pk,
324 const char *emsg); 243 enum GNUNET_ErrorCode ec);
325 244
326 245
327/** 246/**
@@ -338,8 +257,8 @@ typedef void
338struct GNUNET_IDENTITY_Operation * 257struct GNUNET_IDENTITY_Operation *
339GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id, 258GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
340 const char *name, 259 const char *name,
341 const struct GNUNET_IDENTITY_PrivateKey *privkey, 260 const struct GNUNET_CRYPTO_PrivateKey *privkey,
342 enum GNUNET_IDENTITY_KeyType ktype, 261 enum GNUNET_CRYPTO_KeyType ktype,
343 GNUNET_IDENTITY_CreateContinuation cont, 262 GNUNET_IDENTITY_CreateContinuation cont,
344 void *cont_cls); 263 void *cont_cls);
345 264
@@ -390,319 +309,6 @@ void
390GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op); 309GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op);
391 310
392 311
393/**
394 * Get the compacted length of a #GNUNET_IDENTITY_PublicKey.
395 * Compacted means that it returns the minimum number of bytes this
396 * key is long, as opposed to the union structure inside
397 * #GNUNET_IDENTITY_PublicKey.
398 * Useful for compact serializations.
399 *
400 * @param key the key.
401 * @return -1 on error, else the compacted length of the key.
402 */
403ssize_t
404GNUNET_IDENTITY_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key);
405
406
407/**
408 * Reads a #GNUNET_IDENTITY_PublicKey from a compact buffer.
409 * The buffer has to contain at least the compacted length of
410 * a #GNUNET_IDENTITY_PublicKey in bytes.
411 * If the buffer is too small, the function returns -1 as error.
412 * If the buffer does not contain a valid key, it returns -2 as error.
413 *
414 * @param key the key
415 * @param buffer the buffer
416 * @param len the length of buffer
417 * @return -1 or -2 on error, else the amount of bytes read from the buffer
418 */
419ssize_t
420GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key,
421 const void*buffer,
422 size_t len);
423
424
425/**
426 * Writes a #GNUNET_IDENTITY_PublicKey to a compact buffer.
427 * The buffer requires space for at least the compacted length of
428 * a #GNUNET_IDENTITY_PublicKey in bytes.
429 * If the buffer is too small, the function returns -1 as error.
430 * If the key is not valid, it returns -2 as error.
431 *
432 * @param key the key
433 * @param buffer the buffer
434 * @param len the length of buffer
435 * @return -1 or -2 on error, else the amount of bytes written to the buffer
436 */
437ssize_t
438GNUNET_IDENTITY_write_key_to_buffer (const struct
439 GNUNET_IDENTITY_PublicKey *key,
440 void*buffer,
441 size_t len);
442
443
444/**
445 * Get the compacted length of a #GNUNET_IDENTITY_Signature.
446 * Compacted means that it returns the minimum number of bytes this
447 * signature is long, as opposed to the union structure inside
448 * #GNUNET_IDENTITY_Signature.
449 * Useful for compact serializations.
450 *
451 * @param sig the signature.
452 * @return -1 on error, else the compacted length of the signature.
453 */
454ssize_t
455GNUNET_IDENTITY_signature_get_length (const struct
456 GNUNET_IDENTITY_Signature *sig);
457
458
459/**
460 * Reads a #GNUNET_IDENTITY_Signature from a compact buffer.
461 * The buffer has to contain at least the compacted length of
462 * a #GNUNET_IDENTITY_Signature in bytes.
463 * If the buffer is too small, the function returns -1 as error.
464 * If the buffer does not contain a valid key, it returns -2 as error.
465 *
466 * @param sig the signature
467 * @param buffer the buffer
468 * @param len the length of buffer
469 * @return -1 or -2 on error, else the amount of bytes read from the buffer
470 */
471ssize_t
472GNUNET_IDENTITY_read_signature_from_buffer (struct
473 GNUNET_IDENTITY_Signature *sig,
474 const void*buffer,
475 size_t len);
476
477
478/**
479 * Writes a #GNUNET_IDENTITY_Signature to a compact buffer.
480 * The buffer requires space for at least the compacted length of
481 * a #GNUNET_IDENTITY_Signature in bytes.
482 * If the buffer is too small, the function returns -1 as error.
483 * If the key is not valid, it returns -2 as error.
484 *
485 * @param sig the signature
486 * @param buffer the buffer
487 * @param len the length of buffer
488 * @return -1 or -2 on error, else the amount of bytes written to the buffer
489 */
490ssize_t
491GNUNET_IDENTITY_write_signature_to_buffer (const struct
492 GNUNET_IDENTITY_Signature *sig,
493 void*buffer,
494 size_t len);
495
496
497/**
498 * @brief Sign a given block.
499 *
500 * The @a purpose data is the beginning of the data of which the signature is
501 * to be created. The `size` field in @a purpose must correctly indicate the
502 * number of bytes of the data structure, including its header. If possible,
503 * use #GNUNET_IDENTITY_sign() instead of this function.
504 *
505 * @param priv private key to use for the signing
506 * @param purpose what to sign (size, purpose)
507 * @param[out] sig where to write the signature
508 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
509 */
510int
511GNUNET_IDENTITY_sign_ (const struct
512 GNUNET_IDENTITY_PrivateKey *priv,
513 const struct
514 GNUNET_CRYPTO_EccSignaturePurpose *purpose,
515 struct GNUNET_IDENTITY_Signature *sig);
516
517
518/**
519 * @brief Sign a given block with #GNUNET_IDENTITY_PrivateKey.
520 *
521 * The @a ps data must be a fixed-size struct for which the signature is to be
522 * created. The `size` field in @a ps->purpose must correctly indicate the
523 * number of bytes of the data structure, including its header.
524 *
525 * @param priv private key to use for the signing
526 * @param ps packed struct with what to sign, MUST begin with a purpose
527 * @param[out] sig where to write the signature
528 */
529#define GNUNET_IDENTITY_sign(priv,ps,sig) do { \
530 /* check size is set correctly */ \
531 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
532 /* check 'ps' begins with the purpose */ \
533 GNUNET_static_assert (((void*) (ps)) == \
534 ((void*) &(ps)->purpose)); \
535 GNUNET_assert (GNUNET_OK == \
536 GNUNET_IDENTITY_sign_ (priv, \
537 &(ps)->purpose, \
538 sig)); \
539} while (0)
540
541
542/**
543 * @brief Verify a given signature.
544 *
545 * The @a validate data is the beginning of the data of which the signature
546 * is to be verified. The `size` field in @a validate must correctly indicate
547 * the number of bytes of the data structure, including its header. If @a
548 * purpose does not match the purpose given in @a validate (the latter must be
549 * in big endian), signature verification fails. If possible,
550 * use #GNUNET_IDENTITY_signature_verify() instead of this function (only if @a validate
551 * is not fixed-size, you must use this function directly).
552 *
553 * @param purpose what is the purpose that the signature should have?
554 * @param validate block to validate (size, purpose, data)
555 * @param sig signature that is being validated
556 * @param pub public key of the signer
557 * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
558 */
559int
560GNUNET_IDENTITY_signature_verify_ (uint32_t purpose,
561 const struct
562 GNUNET_CRYPTO_EccSignaturePurpose *validate,
563 const struct GNUNET_IDENTITY_Signature *sig,
564 const struct
565 GNUNET_IDENTITY_PublicKey *pub);
566
567
568/**
569 * @brief Verify a given signature with #GNUNET_IDENTITY_PublicKey.
570 *
571 * The @a ps data must be a fixed-size struct for which the signature is to be
572 * created. The `size` field in @a ps->purpose must correctly indicate the
573 * number of bytes of the data structure, including its header.
574 *
575 * @param purp purpose of the signature, must match 'ps->purpose.purpose'
576 * (except in host byte order)
577 * @param ps packed struct with what to sign, MUST begin with a purpose
578 * @param sig where to read the signature from
579 * @param pub public key to use for the verifying
580 */
581#define GNUNET_IDENTITY_signature_verify(purp,ps,sig,pub) ({ \
582 /* check size is set correctly */ \
583 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
584 /* check 'ps' begins with the purpose */ \
585 GNUNET_static_assert (((void*) (ps)) == \
586 ((void*) &(ps)->purpose)); \
587 GNUNET_IDENTITY_signature_verify_ (purp, \
588 &(ps)->purpose, \
589 sig, \
590 pub); \
591 })
592
593
594/**
595 * Encrypt a block with #GNUNET_IDENTITY_PublicKey and derives a
596 * #GNUNET_CRYPTO_EcdhePublicKey which is required for decryption
597 * using ecdh to derive a symmetric key.
598 *
599 * @param block the block to encrypt
600 * @param size the size of the @a block
601 * @param pub public key to use for ecdh
602 * @param ecc where to write the ecc public key
603 * @param result the output parameter in which to store the encrypted result
604 * can be the same or overlap with @c block
605 * @returns the size of the encrypted block, -1 for errors.
606 * Due to the use of CFB and therefore an effective stream cipher,
607 * this size should be the same as @c len.
608 */
609ssize_t
610GNUNET_IDENTITY_encrypt (const void *block,
611 size_t size,
612 const struct GNUNET_IDENTITY_PublicKey *pub,
613 struct GNUNET_CRYPTO_EcdhePublicKey *ecc,
614 void *result);
615
616
617/**
618 * Decrypt a given block with #GNUNET_IDENTITY_PrivateKey and a given
619 * #GNUNET_CRYPTO_EcdhePublicKey using ecdh to derive a symmetric key.
620 *
621 * @param block the data to decrypt, encoded as returned by encrypt
622 * @param size the size of the @a block to decrypt
623 * @param priv private key to use for ecdh
624 * @param ecc the ecc public key
625 * @param result address to store the result at
626 * can be the same or overlap with @c block
627 * @return -1 on failure, size of decrypted block on success.
628 * Due to the use of CFB and therefore an effective stream cipher,
629 * this size should be the same as @c size.
630 */
631ssize_t
632GNUNET_IDENTITY_decrypt (const void *block,
633 size_t size,
634 const struct
635 GNUNET_IDENTITY_PrivateKey *priv,
636 const struct
637 GNUNET_CRYPTO_EcdhePublicKey *ecc,
638 void *result);
639
640
641/**
642 * Creates a (Base32) string representation of the public key.
643 * The resulting string encodes a compacted representation of the key.
644 * See also #GNUNET_IDENTITY_key_get_length.
645 *
646 * @param key the key.
647 * @return the string representation of the key, or NULL on error.
648 */
649char *
650GNUNET_IDENTITY_public_key_to_string (const struct
651 GNUNET_IDENTITY_PublicKey *key);
652
653
654/**
655 * Creates a (Base32) string representation of the private key.
656 * The resulting string encodes a compacted representation of the key.
657 * See also #GNUNET_IDENTITY_key_get_length.
658 *
659 * @param key the key.
660 * @return the string representation of the key, or NULL on error.
661 */
662char *
663GNUNET_IDENTITY_private_key_to_string (const struct
664 GNUNET_IDENTITY_PrivateKey *key);
665
666
667/**
668 * Parses a (Base32) string representation of the public key.
669 * See also #GNUNET_IDENTITY_public_key_to_string.
670 *
671 * @param str the encoded key.
672 * @param key where to write the key.
673 * @return GNUNET_SYSERR on error.
674 */
675enum GNUNET_GenericReturnValue
676GNUNET_IDENTITY_public_key_from_string (const char*str,
677 struct GNUNET_IDENTITY_PublicKey *key);
678
679
680/**
681 * Parses a (Base32) string representation of the private key.
682 * See also #GNUNET_IDENTITY_private_key_to_string.
683 *
684 * @param str the encoded key.
685 * @param key where to write the key.
686 * @return GNUNET_SYSERR on error.
687 */
688enum GNUNET_GenericReturnValue
689GNUNET_IDENTITY_private_key_from_string (const char*str,
690 struct GNUNET_IDENTITY_PrivateKey *key);
691
692
693/**
694 * Retrieves the public key representation of a private key.
695 *
696 * @param privkey the private key.
697 * @param key the public key result.
698 * @return GNUNET_SYSERR on error.
699 */
700enum GNUNET_GenericReturnValue
701GNUNET_IDENTITY_key_get_public (const struct
702 GNUNET_IDENTITY_PrivateKey *privkey,
703 struct GNUNET_IDENTITY_PublicKey *key);
704
705
706/* ************* convenience API to lookup an ego ***************** */ 312/* ************* convenience API to lookup an ego ***************** */
707 313
708/** 314/**
@@ -755,7 +361,7 @@ GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el);
755typedef void 361typedef void
756(*GNUNET_IDENTITY_EgoSuffixCallback) ( 362(*GNUNET_IDENTITY_EgoSuffixCallback) (
757 void *cls, 363 void *cls,
758 const struct GNUNET_IDENTITY_PrivateKey *priv, 364 const struct GNUNET_CRYPTO_PrivateKey *priv,
759 const char *ego_name); 365 const char *ego_name);
760 366
761 367
@@ -778,11 +384,11 @@ struct GNUNET_IDENTITY_EgoSuffixLookup;
778 * @return handle to abort the operation 384 * @return handle to abort the operation
779 */ 385 */
780struct GNUNET_IDENTITY_EgoSuffixLookup * 386struct GNUNET_IDENTITY_EgoSuffixLookup *
781GNUNET_IDENTITY_ego_lookup_by_suffix (const struct 387GNUNET_IDENTITY_ego_lookup_by_suffix (
782 GNUNET_CONFIGURATION_Handle *cfg, 388 const struct GNUNET_CONFIGURATION_Handle *cfg,
783 const char *suffix, 389 const char *suffix,
784 GNUNET_IDENTITY_EgoSuffixCallback cb, 390 GNUNET_IDENTITY_EgoSuffixCallback cb,
785 void *cb_cls); 391 void *cb_cls);
786 392
787 393
788/** 394/**
@@ -807,4 +413,6 @@ GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (
807 413
808/** @} */ /* end of group identity */ 414/** @} */ /* end of group identity */
809 415
416/** @} */ /* end of group addition */
417
810/* end of gnunet_identity_service.h */ 418/* end of gnunet_identity_service.h */
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h
index 5ef4592e5..5f4d5134d 100644
--- a/src/include/gnunet_json_lib.h
+++ b/src/include/gnunet_json_lib.h
@@ -27,6 +27,7 @@
27#ifndef GNUNET_JSON_LIB_H 27#ifndef GNUNET_JSON_LIB_H
28#define GNUNET_JSON_LIB_H 28#define GNUNET_JSON_LIB_H
29 29
30
30#include "gnunet_util_lib.h" 31#include "gnunet_util_lib.h"
31#include <jansson.h> 32#include <jansson.h>
32#include <microhttpd.h> 33#include <microhttpd.h>
@@ -48,10 +49,10 @@ struct GNUNET_JSON_Specification;
48 * @return #GNUNET_SYSERR on error, 49 * @return #GNUNET_SYSERR on error,
49 * #GNUNET_OK on success 50 * #GNUNET_OK on success
50 */ 51 */
51typedef int 52typedef enum GNUNET_GenericReturnValue
52(*GNUNET_JSON_Parser) (void *cls, 53(*GNUNET_JSON_Parser)(void *cls,
53 json_t *root, 54 json_t *root,
54 struct GNUNET_JSON_Specification *spec); 55 struct GNUNET_JSON_Specification *spec);
55 56
56 57
57/** 58/**
@@ -97,9 +98,10 @@ struct GNUNET_JSON_Specification
97 void *ptr; 98 void *ptr;
98 99
99 /** 100 /**
100 * Number of bytes available in @e ptr. 101 * Pointer to set to true if this argument is
102 * indeed missing. Can be NULL.
101 */ 103 */
102 size_t ptr_size; 104 bool *missing;
103 105
104 /** 106 /**
105 * Where should we store the final size of @e ptr. 107 * Where should we store the final size of @e ptr.
@@ -107,6 +109,11 @@ struct GNUNET_JSON_Specification
107 size_t *size_ptr; 109 size_t *size_ptr;
108 110
109 /** 111 /**
112 * Number of bytes available in @e ptr.
113 */
114 size_t ptr_size;
115
116 /**
110 * Set to true if this component is optional. 117 * Set to true if this component is optional.
111 */ 118 */
112 bool is_optional; 119 bool is_optional;
@@ -123,7 +130,7 @@ struct GNUNET_JSON_Specification
123 * @param root the JSON node to start the navigation at. 130 * @param root the JSON node to start the navigation at.
124 * @param spec parse specification array 131 * @param spec parse specification array
125 * @param[out] error_json_name which JSON field was problematic 132 * @param[out] error_json_name which JSON field was problematic
126 * @param[out] which index into @a spec did we encounter an error 133 * @param[out] error_line which index into @a spec did we encounter an error
127 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 134 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
128 */ 135 */
129enum GNUNET_GenericReturnValue 136enum GNUNET_GenericReturnValue
@@ -135,7 +142,13 @@ GNUNET_JSON_parse (const json_t *root,
135 142
136/** 143/**
137 * Frees all elements allocated during a #GNUNET_JSON_parse() 144 * Frees all elements allocated during a #GNUNET_JSON_parse()
138 * operation. 145 * operation. Convenience function to be called if cleaning
146 * up all heap-allocated data from a #GNUNET_JSON_parse() is
147 * desired. The function does not have to be called if no data
148 * was heap-allocated (e.g. only integers, strings and fixed-sized
149 * data was used), or if the application calls the respective
150 * code to free the heap (not always #GNUNET_free(), depends
151 * on the data type!) on the returned heap-allocated data itself.
139 * 152 *
140 * @param spec specification of the parse operation 153 * @param spec specification of the parse operation
141 */ 154 */
@@ -157,10 +170,12 @@ GNUNET_JSON_spec_end (void);
157 * Set the "optional" flag for a parser specification entry. 170 * Set the "optional" flag for a parser specification entry.
158 * 171 *
159 * @param spec specification to modify 172 * @param spec specification to modify
173 * @param[out] missing set to true if the argument is missing, NULL is allowed.
160 * @return spec copy of @a spec with optional bit set 174 * @return spec copy of @a spec with optional bit set
161 */ 175 */
162struct GNUNET_JSON_Specification 176struct GNUNET_JSON_Specification
163GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec); 177GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec,
178 bool *missing);
164 179
165 180
166/** 181/**
@@ -189,6 +204,29 @@ GNUNET_JSON_spec_fixed (const char *name,
189 204
190 205
191/** 206/**
207 * Variable size object (in network byte order, encoded using base64 encoding).
208 *
209 * @param name name of the JSON field
210 * @param[out] obj pointer where to write the data, must have @a size bytes
211 * @param size number of bytes expected in @a obj
212 */
213struct GNUNET_JSON_Specification
214GNUNET_JSON_spec_fixed64 (const char *name,
215 void *obj,
216 size_t size);
217
218
219/**
220 * Fixed size object (in network byte order, encoded using base64 encoding).
221 *
222 * @param name name of the JSON field
223 * @param obj pointer where to write the data (type of `*obj` will determine size)
224 */
225#define GNUNET_JSON_spec_fixed64_auto(name, obj) \
226 GNUNET_JSON_spec_fixed (name, obj, sizeof(*obj))
227
228
229/**
192 * Variable size object (in network byte order, encoded using 230 * Variable size object (in network byte order, encoded using
193 * Crockford Base32hex encoding). 231 * Crockford Base32hex encoding).
194 * 232 *
@@ -214,7 +252,8 @@ GNUNET_JSON_spec_string (const char *name,
214 252
215 253
216/** 254/**
217 * JSON object. 255 * JSON object or array. Reference counter is
256 * incremented.
218 * 257 *
219 * @param name name of the JSON field 258 * @param name name of the JSON field
220 * @param[out] jsonp where to store the JSON found under @a name 259 * @param[out] jsonp where to store the JSON found under @a name
@@ -225,6 +264,28 @@ GNUNET_JSON_spec_json (const char *name,
225 264
226 265
227/** 266/**
267 * JSON object, reference counter not incremented.
268 *
269 * @param name name of the JSON field
270 * @param[out] jsonp where to store the JSON found under @a name
271 */
272struct GNUNET_JSON_Specification
273GNUNET_JSON_spec_object_const (const char *name,
274 const json_t **jsonp);
275
276
277/**
278 * JSON array, reference counter not incremented.
279 *
280 * @param name name of the JSON field
281 * @param[out] jsonp where to store the JSON found under @a name
282 */
283struct GNUNET_JSON_Specification
284GNUNET_JSON_spec_array_const (const char *name,
285 const json_t **jsonp);
286
287
288/**
228 * boolean. 289 * boolean.
229 * 290 *
230 * @param name name of the JSON field 291 * @param name name of the JSON field
@@ -236,6 +297,17 @@ GNUNET_JSON_spec_bool (const char *name,
236 297
237 298
238/** 299/**
300 * double.
301 *
302 * @param name name of the JSON field
303 * @param[out] f where to store the double found under @a name
304 */
305struct GNUNET_JSON_Specification
306GNUNET_JSON_spec_double (const char *name,
307 double *f);
308
309
310/**
239 * 8-bit integer. 311 * 8-bit integer.
240 * 312 *
241 * @param name name of the JSON field 313 * @param name name of the JSON field
@@ -304,25 +376,25 @@ GNUNET_JSON_spec_boolean (const char *name,
304/* ************ GNUnet-specific parser specifications ******************* */ 376/* ************ GNUnet-specific parser specifications ******************* */
305 377
306/** 378/**
307 * Absolute time. 379 * Timestamp.
308 * 380 *
309 * @param name name of the JSON field 381 * @param name name of the JSON field
310 * @param[out] at where to store the absolute time found under @a name 382 * @param[out] t at where to store the absolute time found under @a name
311 */ 383 */
312struct GNUNET_JSON_Specification 384struct GNUNET_JSON_Specification
313GNUNET_JSON_spec_absolute_time (const char *name, 385GNUNET_JSON_spec_timestamp (const char *name,
314 struct GNUNET_TIME_Absolute *at); 386 struct GNUNET_TIME_Timestamp *t);
315 387
316 388
317/** 389/**
318 * Absolute time in network byte order. 390 * Timestamp in network byte order.
319 * 391 *
320 * @param name name of the JSON field 392 * @param name name of the JSON field
321 * @param[out] at where to store the absolute time found under @a name 393 * @param[out] tn where to store the absolute time found under @a name
322 */ 394 */
323struct GNUNET_JSON_Specification 395struct GNUNET_JSON_Specification
324GNUNET_JSON_spec_absolute_time_nbo (const char *name, 396GNUNET_JSON_spec_timestamp_nbo (const char *name,
325 struct GNUNET_TIME_AbsoluteNBO *at); 397 struct GNUNET_TIME_TimestampNBO *tn);
326 398
327 399
328/** 400/**
@@ -358,6 +430,39 @@ GNUNET_JSON_spec_rsa_signature (const char *name,
358 struct GNUNET_CRYPTO_RsaSignature **sig); 430 struct GNUNET_CRYPTO_RsaSignature **sig);
359 431
360 432
433/**
434 * Specification for parsing a blinded message.
435 *
436 * @param name name of the JSON field
437 * @param sig where to store the blinded message found under @a name
438 */
439struct GNUNET_JSON_Specification
440GNUNET_JSON_spec_blinded_message (const char *name,
441 struct GNUNET_CRYPTO_BlindedMessage **msg);
442
443
444/**
445 * Specification for parsing a blinded signature.
446 *
447 * @param name name of the JSON field
448 * @param sig where to store the blinded signature found under @a name
449 */
450struct GNUNET_JSON_Specification
451GNUNET_JSON_spec_blinded_signature (const char *field,
452 struct GNUNET_CRYPTO_BlindedSignature **b_sig);
453
454
455/**
456 * Specification for parsing an unblinded signature.
457 *
458 * @param name name of the JSON field
459 * @param sig where to store the unblinded signature found under @a name
460 */
461struct GNUNET_JSON_Specification
462GNUNET_JSON_spec_unblinded_signature (const char *field,
463 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig);
464
465
361/* ****************** Generic generator interface ******************* */ 466/* ****************** Generic generator interface ******************* */
362 467
363 468
@@ -370,7 +475,21 @@ GNUNET_JSON_spec_rsa_signature (const char *name,
370 * @return json string that encodes @a data 475 * @return json string that encodes @a data
371 */ 476 */
372json_t * 477json_t *
373GNUNET_JSON_from_data (const void *data, size_t size); 478GNUNET_JSON_from_data (const void *data,
479 size_t size);
480
481
482/**
483 * Convert binary data to a JSON string with base64
484 * encoding.
485 *
486 * @param data binary data
487 * @param size size of @a data in bytes
488 * @return json string that encodes @a data
489 */
490json_t *
491GNUNET_JSON_from_data64 (const void *data,
492 size_t size);
374 493
375 494
376/** 495/**
@@ -385,23 +504,34 @@ GNUNET_JSON_from_data (const void *data, size_t size);
385 504
386 505
387/** 506/**
388 * Convert absolute timestamp to a json string. 507 * Convert binary data to a JSON string with base64
508 * encoding.
509 *
510 * @param ptr binary data, sizeof (*ptr) must yield correct size
511 * @return json string that encodes @a data
512 */
513#define GNUNET_JSON_from_data64_auto(ptr) \
514 GNUNET_JSON_from_data64 (ptr, sizeof(*ptr))
515
516
517/**
518 * Convert timestamp to a json string.
389 * 519 *
390 * @param stamp the time stamp 520 * @param stamp the time stamp
391 * @return a json string with the timestamp in @a stamp 521 * @return a json string with the timestamp in @a stamp
392 */ 522 */
393json_t * 523json_t *
394GNUNET_JSON_from_time_abs (struct GNUNET_TIME_Absolute stamp); 524GNUNET_JSON_from_timestamp (struct GNUNET_TIME_Timestamp stamp);
395 525
396 526
397/** 527/**
398 * Convert absolute timestamp to a json string. 528 * Convert timestamp to a json string.
399 * 529 *
400 * @param stamp the time stamp 530 * @param stamp the time stamp
401 * @return a json string with the timestamp in @a stamp 531 * @return a json string with the timestamp in @a stamp
402 */ 532 */
403json_t * 533json_t *
404GNUNET_JSON_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO stamp); 534GNUNET_JSON_from_timestamp_nbo (struct GNUNET_TIME_TimestampNBO stamp);
405 535
406 536
407/** 537/**
@@ -624,6 +754,19 @@ GNUNET_JSON_pack_bool (const char *name,
624 754
625/** 755/**
626 * Generate packer instruction for a JSON field of type 756 * Generate packer instruction for a JSON field of type
757 * double.
758 *
759 * @param name name of the field to add to the object
760 * @param f double value
761 * @return json pack specification
762 */
763struct GNUNET_JSON_PackSpec
764GNUNET_JSON_pack_double (const char *name,
765 double f);
766
767
768/**
769 * Generate packer instruction for a JSON field of type
627 * string. 770 * string.
628 * 771 *
629 * @param name name of the field to add to the object 772 * @param name name of the field to add to the object
@@ -747,30 +890,61 @@ GNUNET_JSON_pack_data_varsize (const char *name,
747 890
748/** 891/**
749 * Generate packer instruction for a JSON field of type 892 * Generate packer instruction for a JSON field of type
750 * absolute time. 893 * variable size binary blob.
894 * Use base64-encoding, instead of the more common
895 * Crockford base32-encoding.
896 *
897 * @param name name of the field to add to the object
898 * @param blob binary data to pack
899 * @param blob_size number of bytes in @a blob
900 * @return json pack specification
901 */
902struct GNUNET_JSON_PackSpec
903GNUNET_JSON_pack_data64_varsize (const char *name,
904 const void *blob,
905 size_t blob_size);
906
907
908/**
909 * Generate packer instruction for a JSON field where the
910 * size is automatically determined from the argument.
911 * Use base64-encoding, instead of the more common
912 * Crockford base32-encoding.
913 *
914 * @param name name of the field to add to the object
915 * @param blob data to pack, must not be an array
916 * @return json pack specification
917 */
918#define GNUNET_JSON_pack_data64_auto(name,blob) \
919 GNUNET_JSON_pack_data64_varsize (name, blob, sizeof (*blob))
920
921
922/**
923 * Generate packer instruction for a JSON field of type
924 * timestamp.
751 * 925 *
752 * @param name name of the field to add to the object 926 * @param name name of the field to add to the object
753 * @param at absolute time to pack, a value of 0 is only 927 * @param at timestamp pack, a value of 0 is only
754 * allowed with #GNUNET_JSON_pack_allow_null()! 928 * allowed with #GNUNET_JSON_pack_allow_null()!
755 * @return json pack specification 929 * @return json pack specification
756 */ 930 */
757struct GNUNET_JSON_PackSpec 931struct GNUNET_JSON_PackSpec
758GNUNET_JSON_pack_time_abs (const char *name, 932GNUNET_JSON_pack_timestamp (const char *name,
759 struct GNUNET_TIME_Absolute at); 933 struct GNUNET_TIME_Timestamp at);
760 934
761 935
762/** 936/**
763 * Generate packer instruction for a JSON field of type 937 * Generate packer instruction for a JSON field of type
764 * absolute time in network byte order. 938 * timestamp in network byte order.
765 * 939 *
766 * @param name name of the field to add to the object 940 * @param name name of the field to add to the object
767 * @param at absolute time to pack, a value of 0 is only 941 * @param at timestamp to pack, a value of 0 is only
768 * allowed with #GNUNET_JSON_pack_allow_null()! 942 * allowed with #GNUNET_JSON_pack_allow_null()!
769 * @return json pack specification 943 * @return json pack specification
770 */ 944 */
771struct GNUNET_JSON_PackSpec 945struct GNUNET_JSON_PackSpec
772GNUNET_JSON_pack_time_abs_nbo (const char *name, 946GNUNET_JSON_pack_timestamp_nbo (const char *name,
773 struct GNUNET_TIME_AbsoluteNBO at); 947 struct GNUNET_TIME_TimestampNBO at);
774 948
775 949
776/** 950/**
@@ -825,6 +999,44 @@ GNUNET_JSON_pack_rsa_signature (const char *name,
825 const struct GNUNET_CRYPTO_RsaSignature *sig); 999 const struct GNUNET_CRYPTO_RsaSignature *sig);
826 1000
827 1001
1002/**
1003 * Generate packer instruction for a JSON field of type
1004 * unblinded signature.
1005 *
1006 * @param name name of the field to add to the object
1007 * @param sig unblinded signature
1008 * @return json pack specification
1009 */
1010struct GNUNET_JSON_PackSpec
1011GNUNET_JSON_pack_unblinded_signature (const char *name,
1012 const struct GNUNET_CRYPTO_UnblindedSignature *sig);
1013
1014
1015/**
1016 * Generate packer instruction for a JSON field of type
1017 * blinded message.
1018 *
1019 * @param name name of the field to add to the object
1020 * @param msg blinded message
1021 * @return json pack specification
1022 */
1023struct GNUNET_JSON_PackSpec
1024GNUNET_JSON_pack_blinded_message (const char *name,
1025 const struct GNUNET_CRYPTO_BlindedMessage *msg);
1026
1027
1028/**
1029 * Generate packer instruction for a JSON field of type
1030 * blinded signature.
1031 *
1032 * @param name name of the field to add to the object
1033 * @param sig blinded signature
1034 * @return json pack specification
1035 */
1036struct GNUNET_JSON_PackSpec
1037GNUNET_JSON_pack_blinded_sig (const char *name,
1038 const struct GNUNET_CRYPTO_BlindedSignature *sig);
1039
828#endif 1040#endif
829 1041
830/* end of gnunet_json_lib.h */ 1042/* end of gnunet_json_lib.h */
diff --git a/src/include/gnunet_load_lib.h b/src/include/gnunet_load_lib.h
index ef596807a..56cacfbbb 100644
--- a/src/include/gnunet_load_lib.h
+++ b/src/include/gnunet_load_lib.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -40,6 +43,7 @@ extern "C"
40#endif 43#endif
41#endif 44#endif
42 45
46
43#include "gnunet_common.h" 47#include "gnunet_common.h"
44#include "gnunet_time_lib.h" 48#include "gnunet_time_lib.h"
45 49
@@ -124,4 +128,6 @@ GNUNET_LOAD_update (struct GNUNET_LOAD_Value *load, uint64_t data);
124 128
125/** @} */ /* end of group */ 129/** @} */ /* end of group */
126 130
131/** @} */ /* end of group addition to libgnunetutil */
132
127/* end of gnunet_load_lib.h */ 133/* end of gnunet_load_lib.h */
diff --git a/src/include/gnunet_messenger_service.h b/src/include/gnunet_messenger_service.h
index 96d48b411..3f039f944 100644
--- a/src/include/gnunet_messenger_service.h
+++ b/src/include/gnunet_messenger_service.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2020--2021 GNUnet e.V. 3 Copyright (C) 2020--2024 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -39,21 +39,14 @@ extern "C" {
39#endif 39#endif
40#endif 40#endif
41 41
42#include "platform.h" 42#include "gnunet_util_lib.h"
43#include "gnunet_configuration_lib.h"
44#include "gnunet_crypto_lib.h"
45#include "gnunet_identity_service.h"
46#include "gnunet_mq_lib.h"
47#include "gnunet_protocols.h"
48#include "gnunet_scheduler_lib.h"
49#include "gnunet_time_lib.h"
50 43
51/** 44/**
52 * Version number of GNUnet Messenger API. 45 * Version number of GNUnet Messenger API.
53 * 46 *
54 * Current version of the Messenger: 0.1 47 * Current version of the Messenger: 0.4
55 */ 48 */
56#define GNUNET_MESSENGER_VERSION 0x00000001 49#define GNUNET_MESSENGER_VERSION 0x00000004
57 50
58/** 51/**
59 * Identifier of GNUnet MESSENGER Service. 52 * Identifier of GNUnet MESSENGER Service.
@@ -91,7 +84,28 @@ struct GNUNET_MESSENGER_RoomEntryRecord
91 /** 84 /**
92 * The hash identifying the port of the room. 85 * The hash identifying the port of the room.
93 */ 86 */
94 struct GNUNET_HashCode key; 87 struct GNUNET_HashCode key GNUNET_PACKED;
88};
89
90GNUNET_NETWORK_STRUCT_END
91
92 GNUNET_NETWORK_STRUCT_BEGIN
93
94/**
95 * A room details record specifies a custom name for a given room and
96 * some additional space for flags.
97 */
98struct GNUNET_MESSENGER_RoomDetailsRecord
99{
100 /**
101 * The custom name for the room.
102 */
103 char name[256];
104
105 /**
106 * The flags of the room.
107 */
108 uint32_t flags;
95}; 109};
96 110
97GNUNET_NETWORK_STRUCT_END 111GNUNET_NETWORK_STRUCT_END
@@ -177,6 +191,26 @@ enum GNUNET_MESSENGER_MessageKind
177 GNUNET_MESSENGER_KIND_DELETE = 15, 191 GNUNET_MESSENGER_KIND_DELETE = 15,
178 192
179 /** 193 /**
194 * The connection kind. The message contains a #GNUNET_MESSENGER_MessageConnection body.
195 */
196 GNUNET_MESSENGER_KIND_CONNECTION = 16,
197
198 /**
199 * The ticket kind. The message contains a #GNUNET_MESSENGER_MessageTicket body.
200 */
201 GNUNET_MESSENGER_KIND_TICKET = 17,
202
203 /**
204 * The transcript kind. The message contains a #GNUNET_MESSENGER_MessageTranscript body.
205 */
206 GNUNET_MESSENGER_KIND_TRANSCRIPT = 18,
207
208 /**
209 * The tag kind. The message contains a #GNUNET_MESSENGER_MessageTag body.
210 */
211 GNUNET_MESSENGER_KIND_TAG = 19,
212
213 /**
180 * The unknown kind. The message contains an unknown body. 214 * The unknown kind. The message contains an unknown body.
181 */ 215 */
182 GNUNET_MESSENGER_KIND_UNKNOWN = 0 216 GNUNET_MESSENGER_KIND_UNKNOWN = 0
@@ -204,7 +238,7 @@ struct GNUNET_MESSENGER_MessageHeader
204 /** 238 /**
205 * The signature of the senders private key. 239 * The signature of the senders private key.
206 */ 240 */
207 struct GNUNET_IDENTITY_Signature signature; 241 struct GNUNET_CRYPTO_Signature signature;
208 242
209 /** 243 /**
210 * The timestamp of the message. 244 * The timestamp of the message.
@@ -236,11 +270,6 @@ struct GNUNET_MESSENGER_MessageHeader
236struct GNUNET_MESSENGER_MessageInfo 270struct GNUNET_MESSENGER_MessageInfo
237{ 271{
238 /** 272 /**
239 * The senders key to verify its signatures.
240 */
241 struct GNUNET_IDENTITY_PublicKey host_key;
242
243 /**
244 * The version of GNUnet Messenger API. 273 * The version of GNUnet Messenger API.
245 * 274 *
246 * The sixteen lower bits represent the lower version number while the sixteen higher bits 275 * The sixteen lower bits represent the lower version number while the sixteen higher bits
@@ -261,7 +290,7 @@ struct GNUNET_MESSENGER_MessageJoin
261 /** 290 /**
262 * The senders public key to verify its signatures. 291 * The senders public key to verify its signatures.
263 */ 292 */
264 struct GNUNET_IDENTITY_PublicKey key; 293 struct GNUNET_CRYPTO_PublicKey key;
265}; 294};
266 295
267/** 296/**
@@ -299,7 +328,7 @@ struct GNUNET_MESSENGER_MessageKey
299 /** 328 /**
300 * The new public key which replaces the current senders public key. 329 * The new public key which replaces the current senders public key.
301 */ 330 */
302 struct GNUNET_IDENTITY_PublicKey key; 331 struct GNUNET_CRYPTO_PublicKey key;
303}; 332};
304 333
305/** 334/**
@@ -478,6 +507,87 @@ struct GNUNET_MESSENGER_MessageDelete
478}; 507};
479 508
480/** 509/**
510 * A connection message body
511 * This allows to tell others about connection information about a peer.
512 *
513 * Message-body-size: 8 bytes
514 */
515struct GNUNET_MESSENGER_MessageConnection
516{
517 /**
518 * The amount of connections of a peer.
519 */
520 uint32_t amount;
521
522 /**
523 * The flags about the connections of a peer.
524 */
525 uint32_t flags;
526};
527
528/**
529 * A ticket message body
530 * This allows to exchange ticket identifiers with an audience.
531 *
532 * Message-body-size: 0+ bytes
533 */
534struct GNUNET_MESSENGER_MessageTicket
535{
536 /**
537 * The identifier of a ticket.
538 */
539 char *identifier;
540};
541
542/**
543 * A transcript message body
544 * This allows reading the content of a sent private message.
545 *
546 * Message-body-size: 68+
547 */
548struct GNUNET_MESSENGER_MessageTranscript
549{
550 /**
551 * The hash of the original message.
552 */
553 struct GNUNET_HashCode hash;
554
555 /**
556 * The key from the recipient of the original message.
557 */
558 struct GNUNET_CRYPTO_PublicKey key;
559
560 /**
561 * The length of the transcribed message.
562 */
563 uint16_t length;
564
565 /**
566 * The data of the transcribed message.
567 */
568 char *data;
569};
570
571/**
572 * A tag message body
573 * This allows tagging a message with a custom tag.
574 *
575 * Message-body-size: 32+
576 */
577struct GNUNET_MESSENGER_MessageTag
578{
579 /**
580 * The hash of the message to tag.
581 */
582 struct GNUNET_HashCode hash;
583
584 /**
585 * The custom tag.
586 */
587 char *tag;
588};
589
590/**
481 * The unified body of a #GNUNET_MESSENGER_Message. 591 * The unified body of a #GNUNET_MESSENGER_Message.
482 */ 592 */
483struct GNUNET_MESSENGER_MessageBody 593struct GNUNET_MESSENGER_MessageBody
@@ -499,6 +609,10 @@ struct GNUNET_MESSENGER_MessageBody
499 struct GNUNET_MESSENGER_MessageFile file; 609 struct GNUNET_MESSENGER_MessageFile file;
500 struct GNUNET_MESSENGER_MessagePrivate privacy; 610 struct GNUNET_MESSENGER_MessagePrivate privacy;
501 struct GNUNET_MESSENGER_MessageDelete deletion; 611 struct GNUNET_MESSENGER_MessageDelete deletion;
612 struct GNUNET_MESSENGER_MessageConnection connection;
613 struct GNUNET_MESSENGER_MessageTicket ticket;
614 struct GNUNET_MESSENGER_MessageTranscript transcript;
615 struct GNUNET_MESSENGER_MessageTag tag;
502 }; 616 };
503}; 617};
504 618
@@ -519,7 +633,7 @@ struct GNUNET_MESSENGER_Message
519}; 633};
520 634
521/** 635/**
522 * Enum for the different supported flags used by message handling 636 * Enum for the different supported flags used by message handling.
523 * Compatible flags can be OR'ed together. 637 * Compatible flags can be OR'ed together.
524 */ 638 */
525enum GNUNET_MESSENGER_MessageFlags 639enum GNUNET_MESSENGER_MessageFlags
@@ -538,18 +652,44 @@ enum GNUNET_MESSENGER_MessageFlags
538 * The private flag. The flag indicates that the message was privately encrypted. 652 * The private flag. The flag indicates that the message was privately encrypted.
539 */ 653 */
540 GNUNET_MESSENGER_FLAG_PRIVATE = 2, 654 GNUNET_MESSENGER_FLAG_PRIVATE = 2,
655
656 /**
657 * The peer flag. The flag indicates that the message was sent by a peer and not a member.
658 */
659 GNUNET_MESSENGER_FLAG_PEER = 4,
660
661 /**
662 * The recent flag. The flag indicates that the message was recently handled by the service.
663 */
664 GNUNET_MESSENGER_FLAG_RECENT = 8,
665
666 /**
667 * The update flag. The flag indicates that the message was updated by the client.
668 */
669 GNUNET_MESSENGER_FLAG_UPDATE = 16,
670
671 /**
672 * The delete flag. The flag indicates that the message was deleted by the service.
673 */
674 GNUNET_MESSENGER_FLAG_DELETE = 32,
541}; 675};
542 676
543/** 677/**
544 * Method called whenever the EGO of a <i>handle</i> changes or if the first connection fails 678 * Enum for the different supported flags used to specify connection handling.
545 * to load a valid EGO and the anonymous key pair will be used instead. 679 * Compatible flags can be OR'ed together.
546 *
547 * @param[in/out] cls Closure from #GNUNET_MESSENGER_connect
548 * @param[in/out] handle Messenger handle
549 */ 680 */
550typedef void 681enum GNUNET_MESSENGER_ConnectionFlags
551(*GNUNET_MESSENGER_IdentityCallback) (void *cls, 682{
552 struct GNUNET_MESSENGER_Handle *handle); 683 /**
684 * The none flag. The flag indicates that the connection is not affected by any modifications.
685 */
686 GNUNET_MESSENGER_FLAG_CONNECTION_NONE = 0,/**< GNUNET_MESSENGER_FLAG_CONNECTION_NONE */
687
688 /**
689 * The auto flag. The flag indicates that a peer will automatically handle routing.
690 */
691 GNUNET_MESSENGER_FLAG_CONNECTION_AUTO = 1,/**< GNUNET_MESSENGER_FLAG_CONNECTION_AUTO */
692};
553 693
554/** 694/**
555 * Method called whenever a message is sent or received from a <i>room</i>. 695 * Method called whenever a message is sent or received from a <i>room</i>.
@@ -560,6 +700,7 @@ typedef void
560 * @param[in/out] cls Closure from #GNUNET_MESSENGER_connect 700 * @param[in/out] cls Closure from #GNUNET_MESSENGER_connect
561 * @param[in] room Room handle 701 * @param[in] room Room handle
562 * @param[in] sender Sender of message 702 * @param[in] sender Sender of message
703 * @param[in] recipient Recipient of message
563 * @param[in] message Newly received or sent message 704 * @param[in] message Newly received or sent message
564 * @param[in] hash Hash identifying the message 705 * @param[in] hash Hash identifying the message
565 * @param[in] flags Flags of the message 706 * @param[in] flags Flags of the message
@@ -567,8 +708,12 @@ typedef void
567typedef void 708typedef void
568(*GNUNET_MESSENGER_MessageCallback) (void *cls, 709(*GNUNET_MESSENGER_MessageCallback) (void *cls,
569 struct GNUNET_MESSENGER_Room *room, 710 struct GNUNET_MESSENGER_Room *room,
570 const struct GNUNET_MESSENGER_Contact *sender, 711 const struct
571 const struct GNUNET_MESSENGER_Message *message, 712 GNUNET_MESSENGER_Contact *sender,
713 const struct
714 GNUNET_MESSENGER_Contact *recipient,
715 const struct
716 GNUNET_MESSENGER_Message *message,
572 const struct GNUNET_HashCode *hash, 717 const struct GNUNET_HashCode *hash,
573 enum GNUNET_MESSENGER_MessageFlags flags); 718 enum GNUNET_MESSENGER_MessageFlags flags);
574 719
@@ -580,49 +725,34 @@ typedef void
580 * @param[in] room Room handle 725 * @param[in] room Room handle
581 * @param[in] contact Contact handle 726 * @param[in] contact Contact handle
582 */ 727 */
583typedef int 728typedef enum GNUNET_GenericReturnValue
584(*GNUNET_MESSENGER_MemberCallback) (void* cls, 729(*GNUNET_MESSENGER_MemberCallback) (void *cls,
585 struct GNUNET_MESSENGER_Room *room, 730 struct GNUNET_MESSENGER_Room *room,
586 const struct GNUNET_MESSENGER_Contact *contact); 731 const struct
732 GNUNET_MESSENGER_Contact *contact);
587 733
588/** 734/**
589 * Set up a handle for the messenger related functions and connects to all necessary services. It will look up the ego 735 * Set up a handle for the messenger related functions and connects to all necessary services. It will use the
590 * key identified by its <i>name</i> and use it for signing all messages from the handle. 736 * a custom name in combination of a private key provided for signing all messages from the handle.
591 * 737 *
592 * @param[in] cfg Configuration to use 738 * @param[in] cfg Configuration to use
593 * @param[in] name Name to look up an ego or NULL to stay anonymous 739 * @param[in] name Name or NULL
594 * @param[in] identity_callback Function called when the EGO of the handle changes 740 * @param[in] key Private key or NULL to stay anonymous
595 * @param[in/out] identity_cls Closure for the <i>identity_callback</i> handler
596 * @param[in] msg_callback Function called when a new message is sent or received 741 * @param[in] msg_callback Function called when a new message is sent or received
597 * @param[in/out] msg_cls Closure for the <i>msg_callback</i> handler 742 * @param[in,out] msg_cls Closure for the <i>msg_callback</i> handler
598 * @return Messenger handle to use, NULL on error 743 * @return Messenger handle to use, NULL on error
599 */ 744 */
600struct GNUNET_MESSENGER_Handle* 745struct GNUNET_MESSENGER_Handle*
601GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 746GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
602 const char *name, 747 const char *name,
603 GNUNET_MESSENGER_IdentityCallback identity_callback, 748 const struct GNUNET_CRYPTO_PrivateKey *key,
604 void *identity_cls,
605 GNUNET_MESSENGER_MessageCallback msg_callback, 749 GNUNET_MESSENGER_MessageCallback msg_callback,
606 void *msg_cls); 750 void *msg_cls);
607 751
608/** 752/**
609 * Update a handle of the messenger to use a different ego key and replace the old one with a newly generated one. All
610 * participated rooms get informed about the key renewal. The handle requires a set name for this function to work and
611 * it needs to be unused by other egos.
612 *
613 * Keep in mind that this will fully delete the old ego key (if any is used) even if any other service wants to use it
614 * as default.
615 *
616 * @param[in/out] handle Messenger handle to use
617 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
618 */
619int
620GNUNET_MESSENGER_update (struct GNUNET_MESSENGER_Handle *handle);
621
622/**
623 * Disconnect all of the messengers used services and clears up its used memory. 753 * Disconnect all of the messengers used services and clears up its used memory.
624 * 754 *
625 * @param[in/out] handle Messenger handle to use 755 * @param[in,out] handle Messenger handle to use
626 */ 756 */
627void 757void
628GNUNET_MESSENGER_disconnect (struct GNUNET_MESSENGER_Handle *handle); 758GNUNET_MESSENGER_disconnect (struct GNUNET_MESSENGER_Handle *handle);
@@ -637,15 +767,14 @@ const char*
637GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle); 767GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle);
638 768
639/** 769/**
640 * Set the name for the messenger. This will rename the currently used ego and move all stored files related to the current 770 * Set the name for the messenger handle and sends messages renaming your contact in currently
641 * name to its new directory. If anything fails during this process the function returns #GNUNET_NO and the name for 771 * open rooms.
642 * the messenger won't change as specified.
643 * 772 *
644 * @param[in/out] handle Messenger handle to use 773 * @param[in,out] handle Messenger handle to use
645 * @param[in] name Name for the messenger to change to 774 * @param[in] name Name for the messenger to change to
646 * @return #GNUNET_YES on success, #GNUNET_NO on failure and #GNUNET_SYSERR if <i>handle</i> is NULL 775 * @return #GNUNET_YES on success, #GNUNET_NO on failure and #GNUNET_SYSERR if <i>handle</i> is NULL
647 */ 776 */
648int 777enum GNUNET_GenericReturnValue
649GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle, 778GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle,
650 const char *name); 779 const char *name);
651 780
@@ -653,12 +782,25 @@ GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle,
653 * Get the public key used by the messenger or NULL if the anonymous key was used. 782 * Get the public key used by the messenger or NULL if the anonymous key was used.
654 * 783 *
655 * @param[in] handle Messenger handle to use 784 * @param[in] handle Messenger handle to use
656 * @return Used ego's public key or NULL 785 * @return Used public key or NULL
657 */ 786 */
658const struct GNUNET_IDENTITY_PublicKey* 787const struct GNUNET_CRYPTO_PublicKey*
659GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle); 788GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle);
660 789
661/** 790/**
791 * Set the private key used by the messenger or NULL if the anonymous key should be
792 * used instead. The currently used key will be replaced and the change will get signed
793 * accordingly to be verified by all contacts.
794 *
795 * @param[in,out] handle Messenger handle to use
796 * @param[in] key Private key to change to or NULL
797 * @return #GNUNET_YES on success, #GNUNET_NO on failure and #GNUNET_SYSERR if <i>handle</i> is NULL
798 */
799enum GNUNET_GenericReturnValue
800GNUNET_MESSENGER_set_key (struct GNUNET_MESSENGER_Handle *handle,
801 const struct GNUNET_CRYPTO_PrivateKey *key);
802
803/**
662 * Open a room to send and receive messages. The room will use the specified <i>key</i> as port for the underlying cadet 804 * Open a room to send and receive messages. The room will use the specified <i>key</i> as port for the underlying cadet
663 * service. Opening a room results in opening the port for incoming connections as possible <b>door</b>. 805 * service. Opening a room results in opening the port for incoming connections as possible <b>door</b>.
664 * 806 *
@@ -670,7 +812,7 @@ GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle);
670 * 812 *
671 * ( All <b>doors</b> form a ring structured network to shorten the latency sending and receiving messages. ) 813 * ( All <b>doors</b> form a ring structured network to shorten the latency sending and receiving messages. )
672 * 814 *
673 * @param[in/out] handle Messenger handle to use 815 * @param[in,out] handle Messenger handle to use
674 * @param[in] key Hash identifying the port 816 * @param[in] key Hash identifying the port
675 * @return Room handle, NULL on error 817 * @return Room handle, NULL on error
676 */ 818 */
@@ -691,7 +833,7 @@ GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle,
691 * 833 *
692 * ( All <b>doors</b> form a ring structured network to shorten the latency sending and receiving messages. ) 834 * ( All <b>doors</b> form a ring structured network to shorten the latency sending and receiving messages. )
693 * 835 *
694 * @param[in/out] handle Messenger handle to use 836 * @param[in,out] handle Messenger handle to use
695 * @param[in] door Peer identity of an open <b>door</b> 837 * @param[in] door Peer identity of an open <b>door</b>
696 * @param[in] key Hash identifying the port 838 * @param[in] key Hash identifying the port
697 * @return Room handle, NULL on error 839 * @return Room handle, NULL on error
@@ -708,7 +850,7 @@ GNUNET_MESSENGER_enter_room (struct GNUNET_MESSENGER_Handle *handle,
708 * ( After a member closes a <b>door</b>, all members entered through that specific <b>door</b> have to use another one 850 * ( After a member closes a <b>door</b>, all members entered through that specific <b>door</b> have to use another one
709 * or open the room on their own. ) 851 * or open the room on their own. )
710 * 852 *
711 * @param[in/out] room Room handle 853 * @param[in,out] room Room handle
712 */ 854 */
713void 855void
714GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room); 856GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room);
@@ -753,25 +895,51 @@ GNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room,
753 const struct GNUNET_HashCode *hash); 895 const struct GNUNET_HashCode *hash);
754 896
755/** 897/**
898 * Get the contact of a member in a <i>room</i> which has been targeted as recipient of a specific message identified
899 * with a given <i>hash</i>.
900 *
901 * Notice that contacts are independent of rooms but will be removed if all rooms containing these contacts get closed.
902 *
903 * @param[in] room Room handle
904 * @param[in] hash Hash identifying a message
905 * @return Contact handle, NULL otherwise
906 */
907const struct GNUNET_MESSENGER_Contact*
908GNUNET_MESSENGER_get_recipient (const struct GNUNET_MESSENGER_Room *room,
909 const struct GNUNET_HashCode *hash);
910
911/**
756 * Get the name used by the <i>contact</i>. 912 * Get the name used by the <i>contact</i>.
757 * 913 *
758 * @param[in] contact Contact handle 914 * @param[in] contact Contact handle
759 * @return Name of <i>contact</i> or NULL 915 * @return Name of <i>contact</i> or NULL
760 */ 916 */
761const char* 917const char*
762GNUNET_MESSENGER_contact_get_name (const struct GNUNET_MESSENGER_Contact *contact); 918GNUNET_MESSENGER_contact_get_name (const struct
919 GNUNET_MESSENGER_Contact *contact);
763 920
764/** 921/**
765 * Get the public key used by the <i>contact</i> or NULL if the anonymous key was used. 922 * Get the public key used by the <i>contact</i> or NULL if the anonymous key was used.
766 * 923 *
767 * @param[in] contact Contact handle 924 * @param[in] contact Contact handle
768 * @return Public key of the ego used by <i>contact</i> or NULL 925 * @return Public key used by <i>contact</i> or NULL
769 */ 926 */
770const struct GNUNET_IDENTITY_PublicKey* 927const struct GNUNET_CRYPTO_PublicKey*
771GNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact); 928GNUNET_MESSENGER_contact_get_key (const struct
929 GNUNET_MESSENGER_Contact *contact);
772 930
773/** 931/**
774 * Send a <i>message</i> into a </i>room</i>. If you opened the <i>room</i> all entered members will receive the 932 * Get the locally unique id of the <i>contact</i>.
933 *
934 * @param[in] contact Contact handle
935 * @return Locally unique contact id or zero
936 */
937size_t
938GNUNET_MESSENGER_contact_get_id (const struct
939 GNUNET_MESSENGER_Contact *contact);
940
941/**
942 * Send a <i>message</i> into a <i>room</i>. If you opened the <i>room</i> all entered members will receive the
775 * <i>message</i>. If you entered the <i>room</i> through a <b>door</b> all so entered <b>doors</b> will receive the 943 * <i>message</i>. If you entered the <i>room</i> through a <b>door</b> all so entered <b>doors</b> will receive the
776 * <i>message</i> as well. All members receiving the <i>message</i> will also propagate this <i>message</i> recursively 944 * <i>message</i> as well. All members receiving the <i>message</i> will also propagate this <i>message</i> recursively
777 * as long as the <i>message</i> is unknown to them. 945 * as long as the <i>message</i> is unknown to them.
@@ -784,14 +952,30 @@ GNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact
784 * 952 *
785 * Sending a message to all members in a given room can be done by providing NULL as contact. 953 * Sending a message to all members in a given room can be done by providing NULL as contact.
786 * 954 *
787 * @param[in/out] room Room handle 955 * @param[in,out] room Room handle
788 * @param[in] message New message to send 956 * @param[in,out] message New message to send
789 * @param[in] contact Contact or NULL 957 * @param[in] contact Contact or NULL
790 */ 958 */
791void 959void
792GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, 960GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room,
793 const struct GNUNET_MESSENGER_Message *message, 961 const struct GNUNET_MESSENGER_Message *message,
794 const struct GNUNET_MESSENGER_Contact* contact); 962 const struct GNUNET_MESSENGER_Contact *contact);
963
964/**
965 * Delete a message identified by its <i>hash</i> from a <i>room</i>. A deletion will be propagated to all members
966 * of the room as with any other sent message. Notice that a deletion will only request other members of the room
967 * to delete the selected message. If you are not permitted to delete the message, the deletion will be ignored.
968 *
969 * Depending on the implementation other clients may also ignore your deletion request in other circumstances.
970 *
971 * @param[in,out] room Room handle
972 * @param[in] message Message to delete
973 * @param[in] delay Delay to delete the message
974 */
975void
976GNUNET_MESSENGER_delete_message (struct GNUNET_MESSENGER_Room *room,
977 const struct GNUNET_HashCode *hash,
978 const struct GNUNET_TIME_Relative delay);
795 979
796/** 980/**
797 * Get the message in a <i>room</i> identified by its <i>hash</i>. 981 * Get the message in a <i>room</i> identified by its <i>hash</i>.
@@ -817,7 +1001,7 @@ GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room,
817int 1001int
818GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room, 1002GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room,
819 GNUNET_MESSENGER_MemberCallback callback, 1003 GNUNET_MESSENGER_MemberCallback callback,
820 void* cls); 1004 void *cls);
821 1005
822#if 0 /* keep Emacsens' auto-indent happy */ 1006#if 0 /* keep Emacsens' auto-indent happy */
823{ 1007{
diff --git a/src/include/gnunet_mhd_compat.h b/src/include/gnunet_mhd_compat.h
index 0cfcc6445..7ef297c2f 100644
--- a/src/include/gnunet_mhd_compat.h
+++ b/src/include/gnunet_mhd_compat.h
@@ -25,6 +25,7 @@
25 * MHD compatibility definitions for warning-less compile of 25 * MHD compatibility definitions for warning-less compile of
26 * our code against MHD before and after #MHD_VERSION 0x00097002. 26 * our code against MHD before and after #MHD_VERSION 0x00097002.
27 */ 27 */
28
28#include <microhttpd.h> 29#include <microhttpd.h>
29 30
30#if MHD_VERSION >= 0x00097002 31#if MHD_VERSION >= 0x00097002
@@ -35,7 +36,7 @@
35 36
36#else 37#else
37 38
38/** 39**
39 * Data type to use for functions return an "MHD result". 40 * Data type to use for functions return an "MHD result".
40 */ 41 */
41#define MHD_RESULT int 42#define MHD_RESULT int
diff --git a/src/include/gnunet_microphone_lib.h b/src/include/gnunet_microphone_lib.h
index 2b08bcd71..394caed68 100644
--- a/src/include/gnunet_microphone_lib.h
+++ b/src/include/gnunet_microphone_lib.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup conversation_l2 Conversation service and libraries
23 * @{
24 *
22 * @author Simon Dieterle 25 * @author Simon Dieterle
23 * @author Andreas Fuchs 26 * @author Andreas Fuchs
24 * @author Christian Grothoff 27 * @author Christian Grothoff
@@ -41,6 +44,7 @@ extern "C"
41#endif 44#endif
42#endif 45#endif
43 46
47
44#include "gnunet_util_lib.h" 48#include "gnunet_util_lib.h"
45 49
46/** 50/**
@@ -141,4 +145,6 @@ GNUNET_MICROPHONE_destroy (struct GNUNET_MICROPHONE_Handle *microphone);
141 145
142/** @} */ /* end of group */ 146/** @} */ /* end of group */
143 147
148/** @} */ /* end of group addition */
149
144/* end of gnunet_microphone_lib.h */ 150/* end of gnunet_microphone_lib.h */
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h
index a1c5c4957..b40693cdb 100644
--- a/src/include/gnunet_mq_lib.h
+++ b/src/include/gnunet_mq_lib.h
@@ -18,7 +18,17 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#include "gnunet_common.h"
22#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
23#error "Only <gnunet_util_lib.h> can be included directly."
24#endif
25
26
21/** 27/**
28 * @addtogroup libgnunetutil
29 * Multi-function utilities library for GNUnet programs
30 * @{
31 *
22 * @author Florian Dold 32 * @author Florian Dold
23 * @author Christian Grothoff 33 * @author Christian Grothoff
24 * 34 *
@@ -35,6 +45,7 @@
35#ifndef GNUNET_MQ_LIB_H 45#ifndef GNUNET_MQ_LIB_H
36#define GNUNET_MQ_LIB_H 46#define GNUNET_MQ_LIB_H
37 47
48
38#include "gnunet_scheduler_lib.h" 49#include "gnunet_scheduler_lib.h"
39 50
40/** 51/**
@@ -50,9 +61,9 @@
50 * @return the MQ message 61 * @return the MQ message
51 */ 62 */
52#define GNUNET_MQ_msg_extra(mvar, esize, type) \ 63#define GNUNET_MQ_msg_extra(mvar, esize, type) \
53 GNUNET_MQ_msg_ (((struct GNUNET_MessageHeader **) &(mvar)), \ 64 GNUNET_MQ_msg_ (((struct GNUNET_MessageHeader **) &(mvar)), \
54 (esize) + sizeof *(mvar), \ 65 (esize) + sizeof *(mvar), \
55 (type)) 66 (type))
56 67
57/** 68/**
58 * Allocate a GNUNET_MQ_Envelope. 69 * Allocate a GNUNET_MQ_Envelope.
@@ -74,7 +85,7 @@
74 * @param type type of the message 85 * @param type type of the message
75 */ 86 */
76#define GNUNET_MQ_msg_header(type) \ 87#define GNUNET_MQ_msg_header(type) \
77 GNUNET_MQ_msg_ (NULL, sizeof(struct GNUNET_MessageHeader), type) 88 GNUNET_MQ_msg_ (NULL, sizeof(struct GNUNET_MessageHeader), type)
78 89
79 90
80/** 91/**
@@ -86,7 +97,8 @@
86 * @param type type of the message 97 * @param type type of the message
87 */ 98 */
88#define GNUNET_MQ_msg_header_extra(mh, esize, type) \ 99#define GNUNET_MQ_msg_header_extra(mh, esize, type) \
89 GNUNET_MQ_msg_ (&mh, (esize) + sizeof(struct GNUNET_MessageHeader), type) 100 GNUNET_MQ_msg_ (&mh, (esize) + sizeof(struct GNUNET_MessageHeader), type \
101 )
90 102
91 103
92/** 104/**
@@ -100,7 +112,7 @@
100 * @return a newly allocated 'struct GNUNET_MQ_Envelope *' 112 * @return a newly allocated 'struct GNUNET_MQ_Envelope *'
101 */ 113 */
102#define GNUNET_MQ_msg_nested_mh(mvar, type, mh) \ 114#define GNUNET_MQ_msg_nested_mh(mvar, type, mh) \
103 ({ \ 115 ({ \
104 struct GNUNET_MQ_Envelope *_ev; \ 116 struct GNUNET_MQ_Envelope *_ev; \
105 _ev = GNUNET_MQ_msg_nested_mh_ ((struct GNUNET_MessageHeader **) &(mvar), \ 117 _ev = GNUNET_MQ_msg_nested_mh_ ((struct GNUNET_MessageHeader **) &(mvar), \
106 sizeof(*(mvar)), \ 118 sizeof(*(mvar)), \
@@ -120,8 +132,8 @@
120 * or NULL if the given message in @a var does not have any space after the message struct 132 * or NULL if the given message in @a var does not have any space after the message struct
121 */ 133 */
122#define GNUNET_MQ_extract_nested_mh(var) \ 134#define GNUNET_MQ_extract_nested_mh(var) \
123 GNUNET_MQ_extract_nested_mh_ ((struct GNUNET_MessageHeader *) (var), \ 135 GNUNET_MQ_extract_nested_mh_ ((struct GNUNET_MessageHeader *) (var), \
124 sizeof(*(var))) 136 sizeof(*(var)))
125 137
126 138
127/** 139/**
@@ -319,7 +331,7 @@ typedef void
319 * @return #GNUNET_OK if the message is well-formed, 331 * @return #GNUNET_OK if the message is well-formed,
320 * #GNUNET_SYSERR if not 332 * #GNUNET_SYSERR if not
321 */ 333 */
322typedef int 334typedef enum GNUNET_GenericReturnValue
323(*GNUNET_MQ_MessageValidationCallback) ( 335(*GNUNET_MQ_MessageValidationCallback) (
324 void *cls, 336 void *cls,
325 const struct GNUNET_MessageHeader *msg); 337 const struct GNUNET_MessageHeader *msg);
@@ -386,9 +398,9 @@ typedef void
386 * FIFO of envelopes independent of MQ itself and wants to 398 * FIFO of envelopes independent of MQ itself and wants to
387 * re-use the pointers internal to @a env. Use with caution. 399 * re-use the pointers internal to @a env. Use with caution.
388 * 400 *
389 * @param[in|out] env_head of envelope DLL 401 * @param[in,out] env_head of envelope DLL
390 * @param[in|out] env_tail tail of envelope DLL 402 * @param[in,out] env_tail tail of envelope DLL
391 * @param[in|out] env element to insert at the tail 403 * @param[in,out] env element to insert at the tail
392 */ 404 */
393void 405void
394GNUNET_MQ_dll_insert_head (struct GNUNET_MQ_Envelope **env_head, 406GNUNET_MQ_dll_insert_head (struct GNUNET_MQ_Envelope **env_head,
@@ -404,9 +416,9 @@ GNUNET_MQ_dll_insert_head (struct GNUNET_MQ_Envelope **env_head,
404 * FIFO of envelopes independent of MQ itself and wants to 416 * FIFO of envelopes independent of MQ itself and wants to
405 * re-use the pointers internal to @a env. Use with caution. 417 * re-use the pointers internal to @a env. Use with caution.
406 * 418 *
407 * @param[in|out] env_head of envelope DLL 419 * @param[in,out] env_head of envelope DLL
408 * @param[in|out] env_tail tail of envelope DLL 420 * @param[in,out] env_tail tail of envelope DLL
409 * @param[in|out] env element to insert at the tail 421 * @param[in,out] env element to insert at the tail
410 */ 422 */
411void 423void
412GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head, 424GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head,
@@ -422,9 +434,9 @@ GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head,
422 * FIFO of envelopes independent of MQ itself and wants to 434 * FIFO of envelopes independent of MQ itself and wants to
423 * re-use the pointers internal to @a env. Use with caution. 435 * re-use the pointers internal to @a env. Use with caution.
424 * 436 *
425 * @param[in|out] env_head of envelope DLL 437 * @param[in,out] env_head of envelope DLL
426 * @param[in|out] env_tail tail of envelope DLL 438 * @param[in,out] env_tail tail of envelope DLL
427 * @param[in|out] env element to remove from the DLL 439 * @param[in,out] env element to remove from the DLL
428 */ 440 */
429void 441void
430GNUNET_MQ_dll_remove (struct GNUNET_MQ_Envelope **env_head, 442GNUNET_MQ_dll_remove (struct GNUNET_MQ_Envelope **env_head,
@@ -519,9 +531,9 @@ struct GNUNET_MQ_MessageHandler
519 * End-marker for the handlers array 531 * End-marker for the handlers array
520 */ 532 */
521#define GNUNET_MQ_handler_end() \ 533#define GNUNET_MQ_handler_end() \
522 { \ 534 { \
523 NULL, NULL, NULL, 0, 0 \ 535 NULL, NULL, NULL, 0, 0 \
524 } 536 }
525 537
526 538
527/** 539/**
@@ -553,7 +565,7 @@ struct GNUNET_MQ_MessageHandler
553 * @param ctx context for the callbacks 565 * @param ctx context for the callbacks
554 */ 566 */
555#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx) \ 567#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx) \
556 ({ \ 568 ({ \
557 void (*_cb)(void *cls, const str *msg) = &handle_ ## name; \ 569 void (*_cb)(void *cls, const str *msg) = &handle_ ## name; \
558 ((struct GNUNET_MQ_MessageHandler){ NULL, \ 570 ((struct GNUNET_MQ_MessageHandler){ NULL, \
559 (GNUNET_MQ_MessageCallback) _cb, \ 571 (GNUNET_MQ_MessageCallback) _cb, \
@@ -597,6 +609,7 @@ struct GNUNET_MQ_MessageHandler
597 * "context"), 609 * "context"),
598 * GNUNET_MQ_handler_end() 610 * GNUNET_MQ_handler_end()
599 * }; 611 * };
612 * </code>
600 * 613 *
601 * @param name unique basename for the functions 614 * @param name unique basename for the functions
602 * @param code message type constant 615 * @param code message type constant
@@ -604,7 +617,7 @@ struct GNUNET_MQ_MessageHandler
604 * @param ctx context for the callbacks 617 * @param ctx context for the callbacks
605 */ 618 */
606#define GNUNET_MQ_hd_var_size(name, code, str, ctx) \ 619#define GNUNET_MQ_hd_var_size(name, code, str, ctx) \
607 __extension__ ({ \ 620 __extension__ ({ \
608 int (*_mv)(void *cls, const str *msg) = &check_ ## name; \ 621 int (*_mv)(void *cls, const str *msg) = &check_ ## name; \
609 void (*_cb)(void *cls, const str *msg) = &handle_ ## name; \ 622 void (*_cb)(void *cls, const str *msg) = &handle_ ## name; \
610 ((struct GNUNET_MQ_MessageHandler){ (GNUNET_MQ_MessageValidationCallback) \ 623 ((struct GNUNET_MQ_MessageHandler){ (GNUNET_MQ_MessageValidationCallback) \
@@ -627,17 +640,17 @@ struct GNUNET_MQ_MessageHandler
627 * the size, starting with a `struct GNUNET_MessageHeader` 640 * the size, starting with a `struct GNUNET_MessageHeader`
628 */ 641 */
629#define GNUNET_MQ_check_zero_termination(m) \ 642#define GNUNET_MQ_check_zero_termination(m) \
630 { \ 643 { \
631 const char *str = (const char *) &m[1]; \ 644 const char *str = (const char *) &m[1]; \
632 const struct GNUNET_MessageHeader *hdr = \ 645 const struct GNUNET_MessageHeader *hdr = \
633 (const struct GNUNET_MessageHeader *) m; \ 646 (const struct GNUNET_MessageHeader *) m; \
634 uint16_t slen = ntohs (hdr->size) - sizeof(*m); \ 647 uint16_t slen = ntohs (hdr->size) - sizeof(*m); \
635 if ((0 == slen) || (memchr (str, 0, slen) != &str[slen - 1])) \ 648 if ((0 == slen) || (memchr (str, 0, slen) != &str[slen - 1])) \
636 { \ 649 { \
637 GNUNET_break (0); \ 650 GNUNET_break (0); \
638 return GNUNET_NO; \ 651 return GNUNET_NO; \
639 } \ 652 } \
640 } 653 }
641 654
642 655
643/** 656/**
@@ -653,19 +666,19 @@ struct GNUNET_MQ_MessageHandler
653 * the size, starting with a `struct GNUNET_MessageHeader` 666 * the size, starting with a `struct GNUNET_MessageHeader`
654 */ 667 */
655#define GNUNET_MQ_check_boxed_message(m) \ 668#define GNUNET_MQ_check_boxed_message(m) \
656 { \ 669 { \
657 const struct GNUNET_MessageHeader *inbox = \ 670 const struct GNUNET_MessageHeader *inbox = \
658 (const struct GNUNET_MessageHeader *) &m[1]; \ 671 (const struct GNUNET_MessageHeader *) &m[1]; \
659 const struct GNUNET_MessageHeader *hdr = \ 672 const struct GNUNET_MessageHeader *hdr = \
660 (const struct GNUNET_MessageHeader *) m; \ 673 (const struct GNUNET_MessageHeader *) m; \
661 uint16_t slen = ntohs (hdr->size) - sizeof(*m); \ 674 uint16_t slen = ntohs (hdr->size) - sizeof(*m); \
662 if ((slen < sizeof(struct GNUNET_MessageHeader)) || \ 675 if ((slen < sizeof(struct GNUNET_MessageHeader)) || \
663 (slen != ntohs (inbox->size))) \ 676 (slen != ntohs (inbox->size))) \
664 { \ 677 { \
665 GNUNET_break (0); \ 678 GNUNET_break (0); \
666 return GNUNET_NO; \ 679 return GNUNET_NO; \
667 } \ 680 } \
668 } 681 }
669 682
670 683
671/** 684/**
@@ -680,7 +693,7 @@ struct GNUNET_MQ_MessageHandler
680 * @return #GNUNET_OK on success, #GNUNET_NO if no handler matched, 693 * @return #GNUNET_OK on success, #GNUNET_NO if no handler matched,
681 * #GNUNET_SYSERR if message was rejected by check function 694 * #GNUNET_SYSERR if message was rejected by check function
682 */ 695 */
683int 696enum GNUNET_GenericReturnValue
684GNUNET_MQ_handle_message (const struct GNUNET_MQ_MessageHandler *handlers, 697GNUNET_MQ_handle_message (const struct GNUNET_MQ_MessageHandler *handlers,
685 const struct GNUNET_MessageHeader *mh); 698 const struct GNUNET_MessageHeader *mh);
686 699
@@ -983,7 +996,7 @@ GNUNET_MQ_destroy_notify_cancel (
983 * Call the message message handler that was registered 996 * Call the message message handler that was registered
984 * for the type of the given message in the given message queue. 997 * for the type of the given message in the given message queue.
985 * 998 *
986 * This function is indented to be used for the implementation 999 * This function is intended to be used for the implementation
987 * of message queues. 1000 * of message queues.
988 * 1001 *
989 * @param mq message queue with the handlers 1002 * @param mq message queue with the handlers
@@ -1120,3 +1133,5 @@ GNUNET_MQ_preference_to_string (enum GNUNET_MQ_PreferenceKind type);
1120#endif 1133#endif
1121 1134
1122/** @} */ /* end of group mq */ 1135/** @} */ /* end of group mq */
1136
1137/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_mst_lib.h b/src/include/gnunet_mst_lib.h
index 9f3431b98..5b848bbd6 100644
--- a/src/include/gnunet_mst_lib.h
+++ b/src/include/gnunet_mst_lib.h
@@ -19,6 +19,13 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
26 * @addtogroup networking
27 * @{
28 *
22 * @author Christian Grothoff 29 * @author Christian Grothoff
23 * 30 *
24 * @file 31 * @file
@@ -32,6 +39,10 @@
32 * @{ 39 * @{
33 */ 40 */
34 41
42#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
43#error "Only <gnunet_util_lib.h> can be included directly."
44#endif
45
35#ifndef GNUNET_MST_LIB_H 46#ifndef GNUNET_MST_LIB_H
36#define GNUNET_MST_LIB_H 47#define GNUNET_MST_LIB_H
37 48
@@ -43,8 +54,6 @@ extern "C"
43#endif 54#endif
44#endif 55#endif
45 56
46#include "gnunet_common.h"
47
48 57
49/** 58/**
50 * Handle to a message stream tokenizer. 59 * Handle to a message stream tokenizer.
@@ -96,7 +105,7 @@ GNUNET_MST_create (GNUNET_MessageTokenizerCallback cb,
96 * #GNUNET_NO if one_shot was set and we have another message ready 105 * #GNUNET_NO if one_shot was set and we have another message ready
97 * #GNUNET_SYSERR if the data stream is corrupt 106 * #GNUNET_SYSERR if the data stream is corrupt
98 */ 107 */
99int 108enum GNUNET_GenericReturnValue
100GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst, 109GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst,
101 const char *buf, 110 const char *buf,
102 size_t size, 111 size_t size,
@@ -118,7 +127,7 @@ GNUNET_MST_from_buffer (struct GNUNET_MessageStreamTokenizer *mst,
118 * #GNUNET_NO if one_shot was set and we have another message ready 127 * #GNUNET_NO if one_shot was set and we have another message ready
119 * #GNUNET_SYSERR if the data stream is corrupt 128 * #GNUNET_SYSERR if the data stream is corrupt
120 */ 129 */
121int 130enum GNUNET_GenericReturnValue
122GNUNET_MST_read (struct GNUNET_MessageStreamTokenizer *mst, 131GNUNET_MST_read (struct GNUNET_MessageStreamTokenizer *mst,
123 struct GNUNET_NETWORK_Handle *sock, 132 struct GNUNET_NETWORK_Handle *sock,
124 int purge, 133 int purge,
@@ -136,7 +145,7 @@ GNUNET_MST_read (struct GNUNET_MessageStreamTokenizer *mst,
136 * #GNUNET_NO if one_shot was set and we have another message ready 145 * #GNUNET_NO if one_shot was set and we have another message ready
137 * #GNUNET_SYSERR if the data stream is corrupt 146 * #GNUNET_SYSERR if the data stream is corrupt
138 */ 147 */
139int 148enum GNUNET_GenericReturnValue
140GNUNET_MST_next (struct GNUNET_MessageStreamTokenizer *mst, 149GNUNET_MST_next (struct GNUNET_MessageStreamTokenizer *mst,
141 int one_shot); 150 int one_shot);
142 151
@@ -161,4 +170,8 @@ GNUNET_MST_destroy (struct GNUNET_MessageStreamTokenizer *mst);
161 170
162/** @} */ /* end of group server */ 171/** @} */ /* end of group server */
163 172
173/** @} */ /* end of group addition to networking */
174
175/** @} */ /* end of group addition to libgnunetutil*/
176
164/* end of gnunet_mst_lib.h */ 177/* end of gnunet_mst_lib.h */
diff --git a/src/include/gnunet_my_lib.h b/src/include/gnunet_my_lib.h
deleted file mode 100644
index 0c95d50d0..000000000
--- a/src/include/gnunet_my_lib.h
+++ /dev/null
@@ -1,500 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2016 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @author Christian Grothoff
22 * @author Christophe Genevey
23 *
24 * @file
25 * Helper library to access a MySQL database
26 *
27 * @defgroup mysql MySQL library
28 * Helper library to access a MySQL database.
29 * @{
30 */
31#ifndef GNUNET_MY_LIB_H
32#define GNUNET_MY_LIB_H
33
34#include "gnunet_util_lib.h"
35#include "gnunet_mysql_lib.h"
36#include <mysql/mysql.h>
37
38#ifdef __cplusplus
39extern "C"
40{
41#if 0 /* keep Emacsens' auto-indent happy */
42}
43#endif
44#endif
45
46
47/**
48 * Information we pass to #GNUNET_MY_exec_prepared() to
49 * initialize the arguments of the prepared statement.
50 */
51struct GNUNET_MY_QueryParam;
52
53
54/**
55 * Function called to convert input argument into SQL parameters.
56 *
57 * @param cls closure
58 * @param pq data about the query
59 * @param qbind array of parameters to initialize
60 * @return -1 on error
61 */
62typedef int
63(*GNUNET_MY_QueryConverter)(void *cls,
64 const struct GNUNET_MY_QueryParam *qp,
65 MYSQL_BIND *qbind);
66
67
68/**
69 * Function called to cleanup result data.
70 *
71 * @param cls closure
72 * @param rs spec to clean up
73 */
74typedef void
75(*GNUNET_MY_QueryCleanup)(void *cls,
76 MYSQL_BIND *qbind);
77/**
78 * Information we pass to #GNUNET_MY_exec_prepared() to
79 * initialize the arguments of the prepared statement.
80 */
81
82
83struct GNUNET_MY_QueryParam
84{
85 /**
86 * Function to call for the type conversion.
87 */
88 GNUNET_MY_QueryConverter conv;
89
90 /**
91 * Function to call for cleaning up the query. Can be NULL.
92 */
93 GNUNET_MY_QueryCleanup cleaner;
94
95 /**
96 * Closure for @e conv.
97 */
98 void *conv_cls;
99
100 /**
101 * Number of arguments the @a conv converter expects to initialize.
102 */
103 unsigned int num_params;
104
105 /**
106 * Information to pass to @e conv.
107 */
108 const void *data;
109
110 /**
111 * Information to pass to @e conv. Size of @a data.
112 */
113 unsigned long data_len;
114};
115
116/**
117 * End of query parameter specification.
118 *
119 * @return array last entry for the result specification to use
120 */
121#define GNUNET_MY_query_param_end { NULL, NULL, NULL, 0, NULL, 0 }
122
123
124/**
125 * Generate query parameter for a buffer @a ptr of
126 * @a ptr_size bytes.FG
127 *
128 * @param ptr pointer to the query parameter to pass
129 * @oaran ptr_size number of bytes in @a ptr
130 */
131struct GNUNET_MY_QueryParam
132GNUNET_MY_query_param_fixed_size (const void *ptr,
133 size_t ptr_size);
134
135
136/**
137 * Run a prepared SELECT statement.
138 *
139 * @param mc mysql context
140 * @param sh handle to SELECT statement
141 * @param params parameters to the statement
142 * @return TBD
143 */
144int
145GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc,
146 struct GNUNET_MYSQL_StatementHandle *sh,
147 struct GNUNET_MY_QueryParam *params);
148
149
150/**
151 * Information we pass to #GNUNET_MY_extract_result() to
152 * initialize the arguments of the prepared statement.
153 */
154struct GNUNET_MY_ResultParam;
155
156/**
157 * Information we pass to #GNUNET_MY_extract_result() to
158 * initialize the arguments of the prepared statement.
159 */
160struct GNUNET_MY_ResultSpec;
161
162/**
163 * Function called to convert input argument into SQL parameters.
164 *
165 * @param cls closure
166 * @param[in,out] rs
167 * @param stmt the mysql statement that is being run
168 * @param column the column that is being processed
169 * @param[out] results
170 * @return -1 on error
171 */
172typedef int
173(*GNUNET_MY_ResultConverter)(void *cls,
174 struct GNUNET_MY_ResultSpec *rs,
175 MYSQL_STMT *stmt,
176 unsigned int column,
177 MYSQL_BIND *results);
178
179/**
180 * Function called to cleanup result data.
181 *
182 * @param cls closure
183 * @param rs spec to clean up
184 */
185typedef void
186(*GNUNET_MY_ResultCleanup)(void *cls,
187 struct GNUNET_MY_ResultSpec *rs);
188
189
190/**
191 * Information we pass to #GNUNET_MY_extract_result() to
192 * initialize the arguments of the prepared statement.
193 */
194struct GNUNET_MY_ResultSpec
195{
196 /**
197 * Function to call to initialize the MYSQL_BIND array.
198 */
199 GNUNET_MY_ResultConverter pre_conv;
200
201 /**
202 * Function to call for converting the result. Can be NULL.
203 */
204 GNUNET_MY_ResultConverter post_conv;
205
206 /**
207 * Function to call for cleaning up the result. Can be NULL.
208 */
209 GNUNET_MY_ResultCleanup cleaner;
210
211 /**
212 * Closure for @e conv.
213 */
214 void *conv_cls;
215
216 /**
217 * Destination for the data.
218 */
219 void *dst;
220
221 /**
222 * Allowed size for the data, 0 for variable-size
223 * (in this case, the type of @e dst is a `void **`
224 * and we need to allocate a buffer of the right size).
225 */
226 size_t dst_size;
227
228 /**
229 * Where to store actual size of the result.
230 */
231 size_t *result_size;
232
233 /**
234 * How many fields does this result specification occupy
235 * in the result returned by MySQL.
236 */
237 unsigned int num_fields;
238
239 /**
240 * Location where we temporarily store the output buffer
241 * length from MySQL. Internal to libgnunetmy.
242 */
243 unsigned long mysql_bind_output_length;
244
245 /**
246 * Memory for MySQL to notify us about NULL values.
247 */
248 MYSQL_BOOL is_null;
249};
250
251
252/**
253 * End of result speceter specification.
254 *
255 * @return array last entry for the result specification to use
256 */
257#define GNUNET_MY_result_spec_end { NULL, NULL, NULL, 0, NULL, 0, 0 }
258
259
260/**
261 * Obtain fixed size result of @a ptr_size bytes from
262 * MySQL, store in already allocated buffer at @a ptr.
263 *
264 * @spec ptr where to write the result
265 * @oaran ptr_size number of bytes available at @a ptr
266 */
267struct GNUNET_MY_ResultSpec
268GNUNET_MY_result_spec_fixed_size (void *ptr,
269 size_t ptr_size);
270
271/**
272 * Generate query parameter for a string
273 *
274 *@param ptr pointer to the string query parameter to pass
275 */
276struct GNUNET_MY_QueryParam
277GNUNET_MY_query_param_string (const char *ptr);
278
279/**
280 * Generate fixed-size query parameter with size determined
281 * by variable type.
282 *
283 * @param x pointer to the query parameter to pass
284 */
285#define GNUNET_MY_query_param_auto_from_type( \
286 x) GNUNET_MY_query_param_fixed_size ((x), sizeof(*(x)))
287
288/**
289 * Generate query parameter for an RSA public key. The
290 * database must contain a BLOB type in the respective position.
291 *
292 * @param x the query parameter to pass
293 * @return array entry for the query parameters to use
294 */
295struct GNUNET_MY_QueryParam
296GNUNET_MY_query_param_rsa_public_key (const struct
297 GNUNET_CRYPTO_RsaPublicKey *x);
298
299/**
300 * Generate query parameter for an RSA signature. The
301 * database must contain a BLOB type in the respective position
302 *
303 *@param x the query parameter to pass
304 *@return array entry for the query parameters to use
305 */
306struct GNUNET_MY_QueryParam
307GNUNET_MY_query_param_rsa_signature (const struct
308 GNUNET_CRYPTO_RsaSignature *x);
309
310/**
311 * Generate query parameter for an absolute time value.
312 * The database must store a 64-bit integer.
313 *
314 *@param x pointer to the query parameter to pass
315 *@return array entry for the query parameters to use
316 */
317struct GNUNET_MY_QueryParam
318GNUNET_MY_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x);
319
320
321/**
322 * Generate query parameter for an absolute time value.
323 * The database must store a 64-bit integer.
324 *
325 *@param x pointer to the query parameter to pass
326 */
327struct GNUNET_MY_QueryParam
328GNUNET_MY_query_param_absolute_time_nbo (const struct
329 GNUNET_TIME_AbsoluteNBO *x);
330
331/**
332 * Generate query parameter for an uint16_t in host byte order.
333 *
334 * @param x pointer to the query parameter to pass
335 */
336struct GNUNET_MY_QueryParam
337GNUNET_MY_query_param_uint16 (const uint16_t *x);
338
339/**
340 * Generate query parameter for an uint32_t in host byte order
341 *
342 *@param x pointer to the query parameter to pass
343 */
344struct GNUNET_MY_QueryParam
345GNUNET_MY_query_param_uint32 (const uint32_t *x);
346
347/**
348 * Generate query parameter for an uint64_t in host byte order
349 *
350 *@param x pointer to the query parameter to pass
351 */
352struct GNUNET_MY_QueryParam
353GNUNET_MY_query_param_uint64 (const uint64_t *x);
354
355/**
356 * We expect a fixed-size result, with size determined by the type of `* dst`
357 *
358 * @spec name name of the field in the table
359 * @spec dst point to where to store the result, type fits expected result size
360 * @return array entry for the result specification to use
361 */
362#define GNUNET_MY_result_spec_auto_from_type( \
363 dst) GNUNET_MY_result_spec_fixed_size ((dst), sizeof(*(dst)))
364
365
366/**
367 * Variable-size result expected
368 *
369 * @param[out] dst where to store the result, allocated
370 * @param[out] sptr where to store the size of @a dst
371 * @return array entru for the result specification to use
372 */
373struct GNUNET_MY_ResultSpec
374GNUNET_MY_result_spec_variable_size (void **dst,
375 size_t *ptr_size);
376
377/**
378 * RSA public key expected
379 *
380 * @param name name of the field in the table
381 * @param[out] rsa where to store the result
382 * @return array entry for the result specification to use
383 */
384struct GNUNET_MY_ResultSpec
385GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa);
386
387
388/**
389 * RSA signature expected.
390 *
391 * @param[out] sig where to store the result;
392 * @return array entry for the result specification to use
393 */
394struct GNUNET_MY_ResultSpec
395GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig);
396
397/**
398 * 0- terminated string exprected.
399 *
400 * @param[out] dst where to store the result, allocated
401 * @return array entry for the result specification to use
402 */
403struct GNUNET_MY_ResultSpec
404GNUNET_MY_result_spec_string (char **dst);
405
406/**
407 * Absolute time expected
408 *
409 * @param name name of the field in the table
410 * @param[out] at where to store the result
411 * @return array entry for the result specification to use
412 */
413struct GNUNET_MY_ResultSpec
414GNUNET_MY_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at);
415
416/**
417 * Absolute time in network byte order expected
418 *
419 * @param[out] at where to store the result
420 * @return array entry for the result specification to use
421 */
422struct GNUNET_MY_ResultSpec
423GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at);
424
425/**
426 * uint16_t expected
427 *
428 * @param[out] u16 where to store the result
429 * @return array entry for the result specification to use
430 */
431struct GNUNET_MY_ResultSpec
432GNUNET_MY_result_spec_uint16 (uint16_t *u16);
433
434/**
435 * uint32_t expected
436 *
437 * @param[out] u32 where to store the result
438 * @return array entry for the result specification to use
439 */
440struct GNUNET_MY_ResultSpec
441GNUNET_MY_result_spec_uint32 (uint32_t *u32);
442
443/**
444 * uint64_t expected.
445 *
446 * @param[out] u64 where to store the result
447 * @return array entry for the result specification to use
448 */
449struct GNUNET_MY_ResultSpec
450GNUNET_MY_result_spec_uint64 (uint64_t *u64);
451
452
453/**
454 * Extract results from a query result according to the given
455 * specification. Always fetches the next row.
456 *
457 * @param sh statement that returned results
458 * @param rs specification to extract for
459 * @return
460 * #GNUNET_YES if all results could be extracted
461 * #GNUNET_NO if there is no more data in the result set
462 * #GNUNET_SYSERR if a result was invalid
463 */
464int
465GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
466 struct GNUNET_MY_ResultSpec *specs);
467
468
469/**
470 * Free all memory that was allocated in @a qp during
471 * #GNUNET_MY_exect_prepared().
472 *
473 * @param qp query specification to clean up
474 * @param qbind mysql query
475 */
476void
477GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp,
478 MYSQL_BIND *qbind);
479
480
481/**
482 * Free all memory that was allocated in @a rs during
483 * #GNUNET_MY_extract_result().
484 *
485 * @param rs reult specification to clean up
486 */
487void
488GNUNET_MY_cleanup_result (struct GNUNET_MY_ResultSpec *rs);
489
490
491#if 0 /* keep Emacsens' auto-indent happy */
492{
493#endif
494#ifdef __cplusplus
495}
496#endif
497
498#endif
499
500/** @} */ /* end of group */
diff --git a/src/include/gnunet_mysql_lib.h b/src/include/gnunet_mysql_lib.h
deleted file mode 100644
index 843d3ccb3..000000000
--- a/src/include/gnunet_mysql_lib.h
+++ /dev/null
@@ -1,157 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @author Christian Grothoff
22 *
23 * @file
24 * Helper library to access a MySQL database
25 *
26 * @defgroup mysql MySQL library
27 * Helper library to access a MySQL database.
28 * @{
29 */
30#ifndef GNUNET_MYSQL_LIB_H
31#define GNUNET_MYSQL_LIB_H
32
33#include "gnunet_util_lib.h"
34#include <mysql/mysql.h>
35
36#ifdef __cplusplus
37extern "C"
38{
39#if 0 /* keep Emacsens' auto-indent happy */
40}
41#endif
42#endif
43
44#ifdef HAVE_MYSQL8
45 typedef bool MYSQL_BOOL;
46#else
47 typedef my_bool MYSQL_BOOL; //MySQL < 8 wants this
48#endif
49
50
51/**
52 * Mysql context.
53 */
54struct GNUNET_MYSQL_Context;
55
56
57/**
58 * Handle for a prepared statement.
59 */
60struct GNUNET_MYSQL_StatementHandle;
61
62
63/**
64 * Type of a callback that will be called for each
65 * data set returned from MySQL.
66 *
67 * @param cls user-defined argument
68 * @param num_values number of elements in values
69 * @param values values returned by MySQL
70 * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort
71 */
72typedef int
73(*GNUNET_MYSQL_DataProcessor) (void *cls,
74 unsigned int num_values,
75 MYSQL_BIND *values);
76
77
78/**
79 * Create a mysql context.
80 *
81 * @param cfg configuration
82 * @param section configuration section to use to get MySQL configuration options
83 * @return the mysql context
84 */
85struct GNUNET_MYSQL_Context *
86GNUNET_MYSQL_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
87 const char *section);
88
89
90/**
91 * Destroy a mysql context. Also frees all associated prepared statements.
92 *
93 * @param mc context to destroy
94 */
95void
96GNUNET_MYSQL_context_destroy (struct GNUNET_MYSQL_Context *mc);
97
98
99/**
100 * Close database connection and all prepared statements (we got a DB
101 * error). The connection will automatically be re-opened and
102 * statements will be re-prepared if they are needed again later.
103 *
104 * @param mc mysql context
105 */
106void
107GNUNET_MYSQL_statements_invalidate (struct GNUNET_MYSQL_Context *mc);
108
109
110/**
111 * Get internal handle for a prepared statement. This function should rarely
112 * be used, and if, with caution! On failures during the interaction with
113 * the handle, you must call #GNUNET_MYSQL_statements_invalidate()!
114 *
115 * @param sh prepared statement to introspect
116 * @return MySQL statement handle, NULL on error
117 */
118MYSQL_STMT *
119GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_StatementHandle *sh);
120
121
122/**
123 * Prepare a statement. Prepared statements are automatically discarded
124 * when the MySQL context is destroyed.
125 *
126 * @param mc mysql context
127 * @param query query text
128 * @return prepared statement, NULL on error
129 */
130struct GNUNET_MYSQL_StatementHandle *
131GNUNET_MYSQL_statement_prepare (struct GNUNET_MYSQL_Context *mc,
132 const char *query);
133
134
135/**
136 * Run a SQL statement.
137 *
138 * @param mc mysql context
139 * @param sql SQL statement to run
140 * @return #GNUNET_OK on success
141 * #GNUNET_SYSERR if there was a problem
142 */
143int
144GNUNET_MYSQL_statement_run (struct GNUNET_MYSQL_Context *mc,
145 const char *sql);
146
147
148#if 0 /* keep Emacsens' auto-indent happy */
149{
150#endif
151#ifdef __cplusplus
152}
153#endif
154
155#endif
156
157/** @} */ /* end of group */
diff --git a/src/include/gnunet_namecache_plugin.h b/src/include/gnunet_namecache_plugin.h
index 7c218fbeb..a3848bf4e 100644
--- a/src/include/gnunet_namecache_plugin.h
+++ b/src/include/gnunet_namecache_plugin.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -34,6 +37,7 @@
34#ifndef GNUNET_NAMECACHE_PLUGIN_H 37#ifndef GNUNET_NAMECACHE_PLUGIN_H
35#define GNUNET_NAMECACHE_PLUGIN_H 38#define GNUNET_NAMECACHE_PLUGIN_H
36 39
40
37#include "gnunet_util_lib.h" 41#include "gnunet_util_lib.h"
38#include "gnunet_namecache_service.h" 42#include "gnunet_namecache_service.h"
39#include "gnunet_namestore_service.h" 43#include "gnunet_namestore_service.h"
@@ -106,3 +110,5 @@ struct GNUNET_NAMECACHE_PluginFunctions
106#endif 110#endif
107 111
108/** @} */ /* end of group */ 112/** @} */ /* end of group */
113
114/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_namecache_service.h b/src/include/gnunet_namecache_service.h
index 07b26aec3..669386c37 100644
--- a/src/include/gnunet_namecache_service.h
+++ b/src/include/gnunet_namecache_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -38,6 +41,7 @@
38#ifndef GNUNET_NAMECACHE_SERVICE_H 41#ifndef GNUNET_NAMECACHE_SERVICE_H
39#define GNUNET_NAMECACHE_SERVICE_H 42#define GNUNET_NAMECACHE_SERVICE_H
40 43
44
41#include "gnunet_util_lib.h" 45#include "gnunet_util_lib.h"
42#include "gnunet_block_lib.h" 46#include "gnunet_block_lib.h"
43#include "gnunet_namestore_service.h" 47#include "gnunet_namestore_service.h"
@@ -173,3 +177,5 @@ GNUNET_NAMECACHE_cancel (struct GNUNET_NAMECACHE_QueueEntry *qe);
173#endif 177#endif
174 178
175/** @} */ /* end of group */ 179/** @} */ /* end of group */
180
181/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_namestore_plugin.h b/src/include/gnunet_namestore_plugin.h
index 9cc8abc6e..b7bcc4eb6 100644
--- a/src/include/gnunet_namestore_plugin.h
+++ b/src/include/gnunet_namestore_plugin.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -31,6 +34,7 @@
31#ifndef GNUNET_NAMESTORE_PLUGIN_H 34#ifndef GNUNET_NAMESTORE_PLUGIN_H
32#define GNUNET_NAMESTORE_PLUGIN_H 35#define GNUNET_NAMESTORE_PLUGIN_H
33 36
37
34#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
35#include "gnunet_namestore_service.h" 39#include "gnunet_namestore_service.h"
36 40
@@ -49,6 +53,7 @@ extern "C"
49 * @param cls closure 53 * @param cls closure
50 * @param serial unique serial number of the record, MUST NOT BE ZERO, 54 * @param serial unique serial number of the record, MUST NOT BE ZERO,
51 * and must be monotonically increasing while iterating 55 * and must be monotonically increasing while iterating
56 * @param editor_hint content of the editor field when record was read (may be NULL)
52 * @param zone_key private key of the zone 57 * @param zone_key private key of the zone
53 * @param label name that is being mapped (at most 255 characters long) 58 * @param label name that is being mapped (at most 255 characters long)
54 * @param rd_count number of entries in @a rd array 59 * @param rd_count number of entries in @a rd array
@@ -57,8 +62,9 @@ extern "C"
57typedef void 62typedef void
58(*GNUNET_NAMESTORE_RecordIterator) (void *cls, 63(*GNUNET_NAMESTORE_RecordIterator) (void *cls,
59 uint64_t serial, 64 uint64_t serial,
65 const char *editor_hint,
60 const struct 66 const struct
61 GNUNET_IDENTITY_PrivateKey *private_key, 67 GNUNET_CRYPTO_PrivateKey *private_key,
62 const char *label, 68 const char *label,
63 unsigned int rd_count, 69 unsigned int rd_count,
64 const struct GNUNET_GNSRECORD_Data *rd); 70 const struct GNUNET_GNSRECORD_Data *rd);
@@ -85,12 +91,12 @@ struct GNUNET_NAMESTORE_PluginFunctions
85 * @param rd array of records with data to store 91 * @param rd array of records with data to store
86 * @return #GNUNET_OK on success, else #GNUNET_SYSERR 92 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
87 */ 93 */
88 int 94 enum GNUNET_GenericReturnValue
89 (*store_records) (void *cls, 95 (*store_records)(void *cls,
90 const struct GNUNET_IDENTITY_PrivateKey *zone, 96 const struct GNUNET_CRYPTO_PrivateKey *zone,
91 const char *label, 97 const char *label,
92 unsigned int rd_count, 98 unsigned int rd_count,
93 const struct GNUNET_GNSRECORD_Data *rd); 99 const struct GNUNET_GNSRECORD_Data *rd);
94 100
95 /** 101 /**
96 * Lookup records in the datastore for which we are the authority. 102 * Lookup records in the datastore for which we are the authority.
@@ -102,12 +108,12 @@ struct GNUNET_NAMESTORE_PluginFunctions
102 * @param iter_cls closure for @a iter 108 * @param iter_cls closure for @a iter
103 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR 109 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR
104 */ 110 */
105 int 111 enum GNUNET_GenericReturnValue
106 (*lookup_records) (void *cls, 112 (*lookup_records)(void *cls,
107 const struct GNUNET_IDENTITY_PrivateKey *zone, 113 const struct GNUNET_CRYPTO_PrivateKey *zone,
108 const char *label, 114 const char *label,
109 GNUNET_NAMESTORE_RecordIterator iter, 115 GNUNET_NAMESTORE_RecordIterator iter,
110 void *iter_cls); 116 void *iter_cls);
111 117
112 118
113 /** 119 /**
@@ -124,13 +130,13 @@ struct GNUNET_NAMESTORE_PluginFunctions
124 * @param iter_cls closure for @a iter 130 * @param iter_cls closure for @a iter
125 * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error 131 * @return #GNUNET_OK on success, #GNUNET_NO if there were no more results, #GNUNET_SYSERR on error
126 */ 132 */
127 int 133 enum GNUNET_GenericReturnValue
128 (*iterate_records) (void *cls, 134 (*iterate_records)(void *cls,
129 const struct GNUNET_IDENTITY_PrivateKey *zone, 135 const struct GNUNET_CRYPTO_PrivateKey *zone,
130 uint64_t serial, 136 uint64_t serial,
131 uint64_t limit, 137 uint64_t limit,
132 GNUNET_NAMESTORE_RecordIterator iter, 138 GNUNET_NAMESTORE_RecordIterator iter,
133 void *iter_cls); 139 void *iter_cls);
134 140
135 141
136 /** 142 /**
@@ -144,12 +150,77 @@ struct GNUNET_NAMESTORE_PluginFunctions
144 * @param iter_cls closure for @a iter 150 * @param iter_cls closure for @a iter
145 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error 151 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
146 */ 152 */
147 int 153 enum GNUNET_GenericReturnValue
148 (*zone_to_name) (void *cls, 154 (*zone_to_name)(void *cls,
149 const struct GNUNET_IDENTITY_PrivateKey *zone, 155 const struct GNUNET_CRYPTO_PrivateKey *zone,
150 const struct GNUNET_IDENTITY_PublicKey *value_zone, 156 const struct GNUNET_CRYPTO_PublicKey *value_zone,
151 GNUNET_NAMESTORE_RecordIterator iter, 157 GNUNET_NAMESTORE_RecordIterator iter,
152 void *iter_cls); 158 void *iter_cls);
159
160 /** Transaction-based API draft **/
161
162 /**
163 * Edit records in the namestore.
164 * This modifies the editor hint, an advisory lock entry.
165 * The record iterator will be called with the old editor hint (if any).
166 *
167 * @param cls closure (internal context for the plugin)
168 * @param zone private key of the zone
169 * @param editor_hint the new value for the advisory lock field
170 * @param label name of the record in the zone
171 * @param iter function to call with the result
172 * @param iter_cls closure for @a iter
173 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR
174 */
175 enum GNUNET_GenericReturnValue
176 (*edit_records)(void *cls,
177 const char *editor_hint,
178 const struct GNUNET_CRYPTO_PrivateKey *zone,
179 const char *label,
180 GNUNET_NAMESTORE_RecordIterator iter,
181 void *iter_cls);
182
183 /**
184 * This clears the editor hint, unless it does not match the
185 * given editor hint, in which case this is a NOP.
186 * If a replacement hint is given, it hint is not cleared, but
187 * set to the replacement.
188 *
189 * @param cls closure (internal context for the plugin)
190 * @param zone private key of the zone
191 * @param editor_hint the new value for the advisory lock field
192 * @param editor_hint_replacement an optional value to use instead of a clear
193 * @param label name of the record in the zone
194 * @param iter function to call with the result
195 * @param iter_cls closure for @a iter
196 * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR
197 */
198 enum GNUNET_GenericReturnValue
199 (*clear_editor_hint)(void *cls,
200 const char *editor_hint,
201 const char *editor_hint_replacement,
202 const struct GNUNET_CRYPTO_PrivateKey *zone,
203 const char *label);
204
205 /**
206 * Setup the database.
207 *
208 * @param cls closure (internal context for the plugin)
209 * @return #GNUNET_OK on success, else fails with #GNUNET_SYSERR
210 */
211 enum GNUNET_GenericReturnValue
212 (*create_tables)(void *cls);
213
214
215 /**
216 * Drop existing tables.
217 * DANGEROUS: All existing data in the dabase will be lost!
218 *
219 * @param cls closure (internal context for the plugin)
220 * @return #GNUNET_OK on success, else fails with #GNUNET_SYSERR
221 */
222 enum GNUNET_GenericReturnValue
223 (*drop_tables)(void *cls);
153}; 224};
154 225
155 226
@@ -163,3 +234,5 @@ struct GNUNET_NAMESTORE_PluginFunctions
163#endif 234#endif
164 235
165/** @} */ /* end of group */ 236/** @} */ /* end of group */
237
238/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h
index 2482b97a5..0f9be8b10 100644
--- a/src/include/gnunet_namestore_service.h
+++ b/src/include/gnunet_namestore_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup GNS
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -38,10 +41,10 @@
38#ifndef GNUNET_NAMESTORE_SERVICE_H 41#ifndef GNUNET_NAMESTORE_SERVICE_H
39#define GNUNET_NAMESTORE_SERVICE_H 42#define GNUNET_NAMESTORE_SERVICE_H
40 43
44
45#include "gnunet_error_codes.h"
41#include "gnunet_util_lib.h" 46#include "gnunet_util_lib.h"
42#include "gnunet_block_lib.h"
43#include "gnunet_gnsrecord_lib.h" 47#include "gnunet_gnsrecord_lib.h"
44#include "gnunet_identity_service.h"
45 48
46#ifdef __cplusplus 49#ifdef __cplusplus
47extern "C" 50extern "C"
@@ -67,6 +70,28 @@ struct GNUNET_NAMESTORE_Handle;
67 */ 70 */
68struct GNUNET_NAMESTORE_ZoneIterator; 71struct GNUNET_NAMESTORE_ZoneIterator;
69 72
73/**
74 * Transaction control types.
75 * They roughly correspond to DB transaction controls
76 */
77enum GNUNET_NAMESTORE_TxControl
78{
79 GNUNET_NAMESTORE_TX_BEGIN = 0,
80 GNUNET_NAMESTORE_TX_COMMIT = 1,
81 GNUNET_NAMESTORE_TX_ROLLBACK = 2,
82};
83
84/**
85 * A struct for record bulk import.
86 * The fields are arrays pointing to individual GNS records and names.
87 */
88struct GNUNET_NAMESTORE_RecordInfo
89{
90 const char *a_label;
91 unsigned int a_rd_count;
92 struct GNUNET_GNSRECORD_Data *a_rd;
93};
94
70 95
71/** 96/**
72 * Connect to the namestore service. 97 * Connect to the namestore service.
@@ -97,12 +122,11 @@ GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h);
97 * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) 122 * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
98 * #GNUNET_NO if content was already there or not found 123 * #GNUNET_NO if content was already there or not found
99 * #GNUNET_YES (or other positive value) on success 124 * #GNUNET_YES (or other positive value) on success
100 * @param emsg NULL on success, otherwise an error message 125 * @param ec the #GNUNET_ErrorCode, #GNUNET_EC_NONE on success.
101 */ 126 */
102typedef void 127typedef void
103(*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls, 128(*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls,
104 int32_t success, 129 enum GNUNET_ErrorCode ec);
105 const char *emsg);
106 130
107 131
108/** 132/**
@@ -116,6 +140,9 @@ typedef void
116 * keep up with the changes, calling @a cont will be delayed until the 140 * keep up with the changes, calling @a cont will be delayed until the
117 * monitors do keep up. 141 * monitors do keep up.
118 * 142 *
143 * This always overwrites the record set and unsets any advisory
144 * lock inrrespective of the currently set editor hint/advisory lock value.
145 *
119 * @param h handle to the namestore 146 * @param h handle to the namestore
120 * @param pkey private key of the zone 147 * @param pkey private key of the zone
121 * @param label name that is being mapped 148 * @param label name that is being mapped
@@ -126,13 +153,81 @@ typedef void
126 * @return handle to abort the request 153 * @return handle to abort the request
127 */ 154 */
128struct GNUNET_NAMESTORE_QueueEntry * 155struct GNUNET_NAMESTORE_QueueEntry *
129GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, 156GNUNET_NAMESTORE_record_set_store (struct GNUNET_NAMESTORE_Handle *h,
130 const struct GNUNET_IDENTITY_PrivateKey *pkey, 157 const struct GNUNET_CRYPTO_PrivateKey *pkey,
131 const char *label, 158 const char *label,
132 unsigned int rd_count, 159 unsigned int rd_count,
133 const struct GNUNET_GNSRECORD_Data *rd, 160 const struct GNUNET_GNSRECORD_Data *rd,
134 GNUNET_NAMESTORE_ContinuationWithStatus cont, 161 GNUNET_NAMESTORE_ContinuationWithStatus cont,
135 void *cont_cls); 162 void *cont_cls);
163
164/**
165 * Store one or more record sets in the namestore. If any item is already present,
166 * it is replaced with the new record. Use an empty array to
167 * remove all records under the given name.
168 *
169 * The continuation is called after the records have been stored in the
170 * database. They may not yet have been commited. Monitors may be notified
171 * asynchronously (basically with a buffer when commited).
172 * However, if any monitor is consistently too slow to
173 * keep up with the changes, calling @a cont will be delayed until the
174 * monitors do keep up.
175 * Uncommited store requests within a transaction (GNUNET_NAMESTORE_transaction_begin)
176 * cause @a cont to be called immediately before the commit and before
177 * notification of monitors.
178 *
179 * This always overwrites the record set and unsets any advisory
180 * lock inrrespective of the currently set editor hint/advisory lock value.
181 *
182 * @param h handle to the namestore
183 * @param pkey private key of the zone
184 * @param rd_set_count the number of record sets
185 * @param record_info the records to add containing @a rd_set_count records
186 * @param cont continuation to call when done
187 * @param rds_sent set to how many record sets could actually be sent
188 * @param cont_cls closure for @a cont
189 * @return handle to abort the request
190 */
191struct GNUNET_NAMESTORE_QueueEntry *
192GNUNET_NAMESTORE_records_store (
193 struct GNUNET_NAMESTORE_Handle *h,
194 const struct GNUNET_CRYPTO_PrivateKey *pkey,
195 unsigned int rd_set_count,
196 const struct GNUNET_NAMESTORE_RecordInfo *record_info,
197 unsigned int *rds_sent,
198 GNUNET_NAMESTORE_ContinuationWithStatus cont,
199 void *cont_cls);
200
201/**
202 * Store an item in the namestore. If the item is already present,
203 * it is replaced with the new record. Use an empty array to
204 * remove all records under the given name.
205 *
206 * The continuation is called after the value has been stored in the
207 * database. Monitors may be notified asynchronously (basically with
208 * a buffer). However, if any monitor is consistently too slow to
209 * keep up with the changes, calling @a cont will be delayed until the
210 * monitors do keep up.
211 *
212 * @param h handle to the namestore
213 * @param pkey private key of the zone
214 * @param label name that is being mapped
215 * @param rd_count number of records in the 'rd' array
216 * @param rd array of records with data to store
217 * @param is_zonemaster update tombstones, do not process monitors
218 * @param cont continuation to call when done
219 * @param cont_cls closure for @a cont
220 * @return handle to abort the request
221 */
222struct GNUNET_NAMESTORE_QueueEntry *
223GNUNET_NAMESTORE_record_set_store_ (struct GNUNET_NAMESTORE_Handle *h,
224 const struct GNUNET_CRYPTO_PrivateKey *pkey,
225 const char *label,
226 unsigned int rd_count,
227 const struct GNUNET_GNSRECORD_Data *rd,
228 int is_zonemaster,
229 GNUNET_NAMESTORE_ContinuationWithStatus cont,
230 void *cont_cls);
136 231
137 232
138/** 233/**
@@ -147,10 +242,48 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
147typedef void 242typedef void
148(*GNUNET_NAMESTORE_RecordMonitor) (void *cls, 243(*GNUNET_NAMESTORE_RecordMonitor) (void *cls,
149 const struct 244 const struct
150 GNUNET_IDENTITY_PrivateKey *zone, 245 GNUNET_CRYPTO_PrivateKey *zone,
151 const char *label, 246 const char *label,
152 unsigned int rd_count, 247 unsigned int rd_count,
153 const struct GNUNET_GNSRECORD_Data *rd); 248 const struct GNUNET_GNSRECORD_Data *rd);
249/**
250 * Process a record that was stored in the namestore.
251 *
252 * @param cls closure
253 * @param ec the error code. #GNUNET_EC_NONE on success.
254 * @param rd_count number of entries in @a rd array, 0 if label was deleted
255 * @param rd array of records with data to store
256 * @param editor_hint the advisory lock value that was replaced. NULL of not advisory lock
257 was set or if lock was equal to provided editor hint.
258 */
259typedef void
260(*GNUNET_NAMESTORE_EditRecordSetBeginCallback) (void *cls,
261 enum GNUNET_ErrorCode ec,
262 unsigned int rd_count,
263 const struct
264 GNUNET_GNSRECORD_Data *rd,
265 const char *editor_hint);
266
267/**
268 * Process a record set that was stored in the namestore.
269 * The record set expiration value takes existing TOMBSTONE records
270 * into account even if those are not returned.
271 *
272 * @param cls closure
273 * @param zone private key of the zone
274 * @param label label of the records
275 * @param rd_count number of entries in @a rd array, 0 if label was deleted
276 * @param rd array of records with data to store
277 * @param expiry the expiration of this record set.
278 */
279typedef void
280(*GNUNET_NAMESTORE_RecordSetMonitor) (void *cls,
281 const struct
282 GNUNET_CRYPTO_PrivateKey *zone,
283 const char *label,
284 unsigned int rd_count,
285 const struct GNUNET_GNSRECORD_Data *rd,
286 struct GNUNET_TIME_Absolute expiry);
154 287
155 288
156/** 289/**
@@ -170,13 +303,39 @@ typedef void
170struct GNUNET_NAMESTORE_QueueEntry * 303struct GNUNET_NAMESTORE_QueueEntry *
171GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, 304GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
172 const struct 305 const struct
173 GNUNET_IDENTITY_PrivateKey *pkey, 306 GNUNET_CRYPTO_PrivateKey *pkey,
174 const char *label, 307 const char *label,
175 GNUNET_SCHEDULER_TaskCallback error_cb, 308 GNUNET_SCHEDULER_TaskCallback error_cb,
176 void *error_cb_cls, 309 void *error_cb_cls,
177 GNUNET_NAMESTORE_RecordMonitor rm, 310 GNUNET_NAMESTORE_RecordMonitor rm,
178 void *rm_cls); 311 void *rm_cls);
179 312
313/**
314 * Lookup an item in the namestore with GNSRECORD filter.
315 *
316 * @param h handle to the namestore
317 * @param pkey private key of the zone
318 * @param label name that is being mapped
319 * @param error_cb function to call on error (i.e. disconnect)
320 * the handle is afterwards invalid
321 * @param error_cb_cls closure for @a error_cb
322 * @param rm function to call with the result (with 0 records if we don't have that label);
323 * the handle is afterwards invalid
324 * @param rm_cls closure for @a rm
325 * @param filter the record set filter to use
326 * @return handle to abort the request
327 */
328struct GNUNET_NAMESTORE_QueueEntry *
329GNUNET_NAMESTORE_records_lookup2 (struct GNUNET_NAMESTORE_Handle *h,
330 const struct
331 GNUNET_CRYPTO_PrivateKey *pkey,
332 const char *label,
333 GNUNET_SCHEDULER_TaskCallback error_cb,
334 void *error_cb_cls,
335 GNUNET_NAMESTORE_RecordMonitor rm,
336 void *rm_cls,
337 enum GNUNET_GNSRECORD_Filter filter);
338
180 339
181/** 340/**
182 * Look for an existing PKEY delegation record for a given public key. 341 * Look for an existing PKEY delegation record for a given public key.
@@ -197,9 +356,9 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
197 */ 356 */
198struct GNUNET_NAMESTORE_QueueEntry * 357struct GNUNET_NAMESTORE_QueueEntry *
199GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, 358GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
200 const struct GNUNET_IDENTITY_PrivateKey *zone, 359 const struct GNUNET_CRYPTO_PrivateKey *zone,
201 const struct 360 const struct
202 GNUNET_IDENTITY_PublicKey *value_zone, 361 GNUNET_CRYPTO_PublicKey *value_zone,
203 GNUNET_SCHEDULER_TaskCallback error_cb, 362 GNUNET_SCHEDULER_TaskCallback error_cb,
204 void *error_cb_cls, 363 void *error_cb_cls,
205 GNUNET_NAMESTORE_RecordMonitor proc, 364 GNUNET_NAMESTORE_RecordMonitor proc,
@@ -219,6 +378,9 @@ GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
219 378
220 379
221/** 380/**
381 * @deprecated since 0.16.7 will be replaced in 0.18
382 * @see GNUNET_NAMESTORE_zone_iteration_start2()
383 *
222 * Starts a new zone iteration (used to periodically PUT all of our 384 * Starts a new zone iteration (used to periodically PUT all of our
223 * records into our DHT). This MUST lock the `struct GNUNET_NAMESTORE_Handle` 385 * records into our DHT). This MUST lock the `struct GNUNET_NAMESTORE_Handle`
224 * for any other calls than #GNUNET_NAMESTORE_zone_iterator_next() and 386 * for any other calls than #GNUNET_NAMESTORE_zone_iterator_next() and
@@ -246,7 +408,7 @@ GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
246struct GNUNET_NAMESTORE_ZoneIterator * 408struct GNUNET_NAMESTORE_ZoneIterator *
247GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h, 409GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
248 const struct 410 const struct
249 GNUNET_IDENTITY_PrivateKey *zone, 411 GNUNET_CRYPTO_PrivateKey *zone,
250 GNUNET_SCHEDULER_TaskCallback error_cb, 412 GNUNET_SCHEDULER_TaskCallback error_cb,
251 void *error_cb_cls, 413 void *error_cb_cls,
252 GNUNET_NAMESTORE_RecordMonitor proc, 414 GNUNET_NAMESTORE_RecordMonitor proc,
@@ -254,6 +416,44 @@ GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
254 GNUNET_SCHEDULER_TaskCallback finish_cb, 416 GNUNET_SCHEDULER_TaskCallback finish_cb,
255 void *finish_cb_cls); 417 void *finish_cb_cls);
256 418
419/**
420 * Starts a new zone iteration (used to periodically PUT all of our
421 * records into our DHT). This MUST lock the `struct GNUNET_NAMESTORE_Handle`
422 * for any other calls than #GNUNET_NAMESTORE_zone_iterator_next() and
423 * #GNUNET_NAMESTORE_zone_iteration_stop. @a proc will be called once
424 * immediately, and then again after
425 * #GNUNET_NAMESTORE_zone_iterator_next() is invoked.
426 *
427 * On error (disconnect), @a error_cb will be invoked.
428 * On normal completion, @a finish_cb proc will be
429 * invoked.
430 *
431 * @param h handle to the namestore
432 * @param zone zone to access, NULL for all zones
433 * @param error_cb function to call on error (i.e. disconnect),
434 * the handle is afterwards invalid
435 * @param error_cb_cls closure for @a error_cb
436 * @param proc function to call on each name from the zone; it
437 * will be called repeatedly with a value (if available)
438 * @param proc_cls closure for @a proc
439 * @param finish_cb function to call on completion
440 * the handle is afterwards invalid
441 * @param finish_cb_cls closure for @a finish_cb
442 * @param filter the record set filter to use
443 * @return an iterator handle to use for iteration
444 */
445struct GNUNET_NAMESTORE_ZoneIterator *
446GNUNET_NAMESTORE_zone_iteration_start2 (struct GNUNET_NAMESTORE_Handle *h,
447 const struct
448 GNUNET_CRYPTO_PrivateKey *zone,
449 GNUNET_SCHEDULER_TaskCallback error_cb,
450 void *error_cb_cls,
451 GNUNET_NAMESTORE_RecordSetMonitor proc,
452 void *proc_cls,
453 GNUNET_SCHEDULER_TaskCallback finish_cb,
454 void *finish_cb_cls,
455 enum GNUNET_GNSRECORD_Filter filter);
456
257 457
258/** 458/**
259 * Calls the record processor specified in #GNUNET_NAMESTORE_zone_iteration_start 459 * Calls the record processor specified in #GNUNET_NAMESTORE_zone_iteration_start
@@ -286,6 +486,9 @@ struct GNUNET_NAMESTORE_ZoneMonitor;
286 486
287 487
288/** 488/**
489 * @deprecated since 0.16.7 will be replaced in 0.18
490 * @see GNUNET_NAMESTORE_zone_monitor_start2()
491 *
289 * Begin monitoring a zone for changes. Will first call the @a 492 * Begin monitoring a zone for changes. Will first call the @a
290 * monitor function on all existing records in the selected zone(s) if 493 * monitor function on all existing records in the selected zone(s) if
291 * @a iterate_first is #GNUNET_YES. In any case, we will then call @a 494 * @a iterate_first is #GNUNET_YES. In any case, we will then call @a
@@ -315,7 +518,7 @@ struct GNUNET_NAMESTORE_ZoneMonitor;
315struct GNUNET_NAMESTORE_ZoneMonitor * 518struct GNUNET_NAMESTORE_ZoneMonitor *
316GNUNET_NAMESTORE_zone_monitor_start ( 519GNUNET_NAMESTORE_zone_monitor_start (
317 const struct GNUNET_CONFIGURATION_Handle *cfg, 520 const struct GNUNET_CONFIGURATION_Handle *cfg,
318 const struct GNUNET_IDENTITY_PrivateKey *zone, 521 const struct GNUNET_CRYPTO_PrivateKey *zone,
319 int iterate_first, 522 int iterate_first,
320 GNUNET_SCHEDULER_TaskCallback error_cb, 523 GNUNET_SCHEDULER_TaskCallback error_cb,
321 void *error_cb_cls, 524 void *error_cb_cls,
@@ -324,6 +527,47 @@ GNUNET_NAMESTORE_zone_monitor_start (
324 GNUNET_SCHEDULER_TaskCallback sync_cb, 527 GNUNET_SCHEDULER_TaskCallback sync_cb,
325 void *sync_cb_cls); 528 void *sync_cb_cls);
326 529
530/**
531 * Begin monitoring a zone for changes. Will first call the @a
532 * monitor function on all existing records in the selected zone(s) if
533 * @a iterate_first is #GNUNET_YES. In any case, we will then call @a
534 * sync_cb, and then afterwards call the @a monitor whenever a record
535 * changes. If the namestore disconnects, the @a error_cb function is
536 * called with a disconnect event. Once the connection is
537 * re-established, the process begins from the start (depending on @a
538 * iterate_first, we will again first do all existing records, then @a
539 * sync, then updates).
540 *
541 * @param cfg configuration to use to connect to namestore
542 * @param zone zone to monitor, NULL for all zones
543 * @param iterate_first #GNUNET_YES to first iterate over all existing records,
544 * #GNUNET_NO to only return changes that happen from now on
545 * @param error_cb function to call on error (i.e. disconnect); note that
546 * unlike the other error callbacks in this API, a call to this
547 * function does NOT destroy the monitor handle, it merely signals
548 * that monitoring is down. You need to still explicitly call
549 * #GNUNET_NAMESTORE_zone_monitor_stop().
550 * @param error_cb_cls closure for @a error_cb
551 * @param monitor function to call on zone changes, with an initial limit of 1
552 * @param monitor_cls closure for @a monitor
553 * @param sync_cb function called when we're in sync with the namestore
554 * @param sync_cb_cls closure for @a sync_cb
555 * @param filter the record set filter to use
556 * @return handle to stop monitoring
557 */
558struct GNUNET_NAMESTORE_ZoneMonitor *
559GNUNET_NAMESTORE_zone_monitor_start2 (
560 const struct GNUNET_CONFIGURATION_Handle *cfg,
561 const struct GNUNET_CRYPTO_PrivateKey *zone,
562 int iterate_first,
563 GNUNET_SCHEDULER_TaskCallback error_cb,
564 void *error_cb_cls,
565 GNUNET_NAMESTORE_RecordSetMonitor monitor,
566 void *monitor_cls,
567 GNUNET_SCHEDULER_TaskCallback sync_cb,
568 void *sync_cb_cls,
569 enum GNUNET_GNSRECORD_Filter filter);
570
327 571
328/** 572/**
329 * Calls the monitor processor specified in #GNUNET_NAMESTORE_zone_monitor_start 573 * Calls the monitor processor specified in #GNUNET_NAMESTORE_zone_monitor_start
@@ -360,6 +604,68 @@ void
360GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm); 604GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm);
361 605
362 606
607/**
608 * New API draft. Experimental
609 */
610
611/**
612 * This function is used to initiate the editing
613 * of a record set under #label.
614 * It will set the editor hint of the record set to #editor_hint.
615 * The editor hint serves as an advisory lock that is used in
616 * #GNUNET_NAMESTORE_EdtirRecordSetBeginCallback if #editor_hint
617 * differs from the currently set advisory lock in the database.
618 *
619 * @param h handle to the namestore
620 * @param pkey the private key of the zone to edit
621 * @param label the label of the record set to edit
622 * @param editor_hint the editor hint to set as advisory lock
623 * @param error_cb the error callback
624 * @param error_cb_cls closure to #error_cb
625 * @param edit_cb the #GNUNET_NAMESTORE_EditRecordSetBeginCallback
626 * @param edit_cb_cls closure to #edit_cb
627 * @return handle to the operation
628 */
629struct GNUNET_NAMESTORE_QueueEntry *
630GNUNET_NAMESTORE_record_set_edit_begin (struct GNUNET_NAMESTORE_Handle *h,
631 const struct
632 GNUNET_CRYPTO_PrivateKey *pkey,
633 const char *label,
634 const char *editor_hint,
635 GNUNET_NAMESTORE_EditRecordSetBeginCallback
636 edit_cb,
637 void *edit_cb_cls);
638
639/**
640 * If the current advisory lock is set to the provided editor hint,
641 * this API cancels the editing of a record set and unsets the advisory lock in database.
642 * Optionally, a new editor hint can be provided: For example,
643 * the value that was returned in in the callback to
644 * #GNUNET_NAMESTORE_record_set_edit_begin.
645 *
646 * If provided editor hint does not match the current advisory lock,
647 * this function is not doing anything (NOP).
648 *
649 * @param h handle to the namestore
650 * @param pkey the private key of the zone to edit
651 * @param label the label of the record set to edit
652 * @param editor_hint the editor hint to set as advisory lock
653 * @param editor_hint_replacement the editor hint to set as advisory lock instead of clearing it
654 * @param finished_cb the callback called when cancelled
655 * @param finished_cb_cls closure to #finished_cb
656 * @return handle to the operation
657 */
658struct GNUNET_NAMESTORE_QueueEntry *
659GNUNET_NAMESTORE_record_set_edit_cancel (struct GNUNET_NAMESTORE_Handle *h,
660 const struct
661 GNUNET_CRYPTO_PrivateKey *pkey,
662 const char *label,
663 const char *editor_hint,
664 const char *editor_hint_replacement,
665 GNUNET_NAMESTORE_ContinuationWithStatus
666 finished_cb,
667 void *finished_cls);
668
363#if 0 /* keep Emacsens' auto-indent happy */ 669#if 0 /* keep Emacsens' auto-indent happy */
364{ 670{
365#endif 671#endif
@@ -370,3 +676,5 @@ GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm);
370#endif 676#endif
371 677
372/** @} */ /* end of group */ 678/** @} */ /* end of group */
679
680/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_nat_auto_service.h b/src/include/gnunet_nat_auto_service.h
index 78284dc01..1c511cac3 100644
--- a/src/include/gnunet_nat_auto_service.h
+++ b/src/include/gnunet_nat_auto_service.h
@@ -26,7 +26,7 @@
26 * Service for testing and autoconfiguration of 26 * Service for testing and autoconfiguration of
27 * NAT traversal functionality 27 * NAT traversal functionality
28 * 28 *
29 * @defgroup nat NAT testing library 29 * @defgroup nat NAT library
30 * 30 *
31 * @{ 31 * @{
32 */ 32 */
@@ -34,6 +34,7 @@
34#ifndef GNUNET_NAT_AUTO_SERVICE_H 34#ifndef GNUNET_NAT_AUTO_SERVICE_H
35#define GNUNET_NAT_AUTO_SERVICE_H 35#define GNUNET_NAT_AUTO_SERVICE_H
36 36
37
37#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
38#include "gnunet_nat_service.h" 39#include "gnunet_nat_service.h"
39 40
diff --git a/src/include/gnunet_nat_service.h b/src/include/gnunet_nat_service.h
index e39e2c016..ba9f252a0 100644
--- a/src/include/gnunet_nat_service.h
+++ b/src/include/gnunet_nat_service.h
@@ -36,6 +36,7 @@
36#ifndef GNUNET_NAT_SERVICE_H 36#ifndef GNUNET_NAT_SERVICE_H
37#define GNUNET_NAT_SERVICE_H 37#define GNUNET_NAT_SERVICE_H
38 38
39
39#include "gnunet_util_lib.h" 40#include "gnunet_util_lib.h"
40 41
41 42
@@ -344,6 +345,19 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
344 345
345 346
346/** 347/**
348 * Add global address to the list of addresses and notify clients.
349 *
350 * @param nh the handle returned by register
351 * @param addr IP address to add.
352 * @param address_length number of bytes in @a addr
353 */
354void
355GNUNET_NAT_add_global_address (struct GNUNET_NAT_Handle *nh,
356 char *addr,
357 unsigned int address_length);
358
359
360/**
347 * Test if the given address is (currently) a plausible IP address for 361 * Test if the given address is (currently) a plausible IP address for
348 * this peer. Mostly a convenience function so that clients do not 362 * this peer. Mostly a convenience function so that clients do not
349 * have to explicitly track all IPs that the #GNUNET_NAT_AddressCallback 363 * have to explicitly track all IPs that the #GNUNET_NAT_AddressCallback
@@ -385,6 +399,12 @@ GNUNET_NAT_request_reversal (struct GNUNET_NAT_Handle *nh,
385 * handle. This frees the handle, after having sent the needed 399 * handle. This frees the handle, after having sent the needed
386 * commands to close open ports. 400 * commands to close open ports.
387 * 401 *
402 * FIXME: No, the implementation of this API does not do anything beyond
403 * cleaning up the handle.
404 * This is a problem for applications that use #GNUNET_NAT_AddressCallback
405 * and use the app_ctx to store objects, because the callback will never be
406 * called for cleanup on unregister.
407 *
388 * @param nh the handle to unregister 408 * @param nh the handle to unregister
389 */ 409 */
390void 410void
diff --git a/src/include/gnunet_nc_lib.h b/src/include/gnunet_nc_lib.h
index bd22fd6e2..8f4d9a16f 100644
--- a/src/include/gnunet_nc_lib.h
+++ b/src/include/gnunet_nc_lib.h
@@ -17,7 +17,17 @@
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20
21
22#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
23#error "Only <gnunet_util_lib.h> can be included directly."
24#endif
25
20/** 26/**
27 * @addtogroup libgnunetutil
28 * Multi-function utilities library for GNUnet programs
29 * @{
30 *
21 * @author Christian Grothoff 31 * @author Christian Grothoff
22 * 32 *
23 * @file 33 * @file
@@ -99,3 +109,7 @@ unsigned int
99GNUNET_notification_context_get_size (struct GNUNET_NotificationContext *nc); 109GNUNET_notification_context_get_size (struct GNUNET_NotificationContext *nc);
100 110
101#endif 111#endif
112
113/** @} */ /* end of group mq */
114
115/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h
index ff1e853f5..764b7b29d 100644
--- a/src/include/gnunet_network_lib.h
+++ b/src/include/gnunet_network_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
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, 2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -19,7 +19,15 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
26 * @addtogroup networking
27 * @{
28 *
22 * @author Nils Durner 29 * @author Nils Durner
30 * @author Tobias Frisch
23 * 31 *
24 * @file 32 * @file
25 * Basic low-level networking interface 33 * Basic low-level networking interface
@@ -31,6 +39,7 @@
31#ifndef GNUNET_NETWORK_LIB_H 39#ifndef GNUNET_NETWORK_LIB_H
32#define GNUNET_NETWORK_LIB_H 40#define GNUNET_NETWORK_LIB_H
33 41
42#include "gnunet_common.h"
34#ifdef __cplusplus 43#ifdef __cplusplus
35extern "C" 44extern "C"
36{ 45{
@@ -39,6 +48,14 @@ extern "C"
39#endif 48#endif
40#endif 49#endif
41 50
51//#ifdef HAVE_SYS_SELECT_H
52/*
53 * Include "sys/select.h" because it is required to use
54 * "fd_set" in "struct GNUNET_NETWORK_FDSet"!
55 */
56
57#include <sys/select.h>
58//#endif
42#ifdef HAVE_SYS_SOCKET_H 59#ifdef HAVE_SYS_SOCKET_H
43#include <sys/socket.h> 60#include <sys/socket.h>
44#endif 61#endif
@@ -141,7 +158,7 @@ GNUNET_NETWORK_socket_box_native (int fd);
141 * @param doBlock blocking mode 158 * @param doBlock blocking mode
142 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 159 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
143 */ 160 */
144int 161enum GNUNET_GenericReturnValue
145GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, 162GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd,
146 int doBlock); 163 int doBlock);
147 164
@@ -580,3 +597,7 @@ GNUNET_NETWORK_test_port_free (int ipproto,
580#endif /* GNUNET_NETWORK_LIB_H */ 597#endif /* GNUNET_NETWORK_LIB_H */
581 598
582/** @} */ /* end of group */ 599/** @} */ /* end of group */
600
601/** @} */ /* end of group addition */
602
603/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_nse_service.h b/src/include/gnunet_nse_service.h
index 0401e0cbc..fe9e1f853 100644
--- a/src/include/gnunet_nse_service.h
+++ b/src/include/gnunet_nse_service.h
@@ -22,6 +22,9 @@
22#define GNUNET_NSE_SERVICE_H_ 22#define GNUNET_NSE_SERVICE_H_
23 23
24/** 24/**
25 * @addtogroup Backbone
26 * @{
27 *
25 * @author Nathan Evans 28 * @author Nathan Evans
26 * 29 *
27 * @file 30 * @file
@@ -47,6 +50,7 @@ extern "C"
47#endif 50#endif
48#endif 51#endif
49 52
53
50#include "gnunet_util_lib.h" 54#include "gnunet_util_lib.h"
51 55
52/** 56/**
@@ -116,4 +120,6 @@ GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h);
116 120
117/** @} */ /* end of group nse */ 121/** @} */ /* end of group nse */
118 122
123/** @} */ /* end of group addition */
124
119#endif /* GNUNET_NSE_SERVICE_H_ */ 125#endif /* GNUNET_NSE_SERVICE_H_ */
diff --git a/src/include/gnunet_nt_lib.h b/src/include/gnunet_nt_lib.h
index 18419a7b8..014b4fbe0 100644
--- a/src/include/gnunet_nt_lib.h
+++ b/src/include/gnunet_nt_lib.h
@@ -17,12 +17,20 @@
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20
21#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
20/** 25/**
26 * @addtogroup Backbone
27 * @{
28 *
21 * @file network type characterization 29 * @file network type characterization
22 * @author Christian Grothoff 30 * @author Christian Grothoff
23 * @author Matthias Wachs 31 * @author Matthias Wachs
24 * 32 *
25 * @defgroup nt network type characterization 33 * @defgroup nt Network type characterization
26 * 34 *
27 * @{ 35 * @{
28 */ 36 */
@@ -122,3 +130,5 @@ GNUNET_NT_scanner_done (struct GNUNET_NT_InterfaceScanner *is);
122#endif 130#endif
123 131
124/** @} */ /* end of group */ 132/** @} */ /* end of group */
133
134/** @} */ /* end of group addition to backbone */
diff --git a/src/include/gnunet_op_lib.h b/src/include/gnunet_op_lib.h
index 77fa7f955..e028fb7fb 100644
--- a/src/include/gnunet_op_lib.h
+++ b/src/include/gnunet_op_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs
28 * @{
29 *
22 * @file 30 * @file
23 * Asynchronous operations; register callbacks for operations and call them when a response arrives. 31 * Asynchronous operations; register callbacks for operations and call them when a response arrives.
24 * 32 *
@@ -28,6 +36,7 @@
28#ifndef GNUNET_OP_H 36#ifndef GNUNET_OP_H
29#define GNUNET_OP_H 37#define GNUNET_OP_H
30 38
39
31#include "gnunet_util_lib.h" 40#include "gnunet_util_lib.h"
32 41
33/** 42/**
@@ -153,3 +162,5 @@ GNUNET_OP_remove (struct GNUNET_OP_Handle *h,
153 162
154 163
155#endif // GNUNET_OP_H 164#endif // GNUNET_OP_H
165
166/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h
index eddf97dab..93296c96b 100644
--- a/src/include/gnunet_os_lib.h
+++ b/src/include/gnunet_os_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs
28 * @{
29 *
22 * @author Christian Grothoff 30 * @author Christian Grothoff
23 * @author Krista Bennett 31 * @author Krista Bennett
24 * @author Gerd Knorr <kraxel@bytesex.org> 32 * @author Gerd Knorr <kraxel@bytesex.org>
@@ -56,10 +64,6 @@ extern "C"
56#endif 64#endif
57#endif 65#endif
58 66
59#include "gnunet_common.h"
60#include "gnunet_configuration_lib.h"
61#include "gnunet_scheduler_lib.h"
62
63 67
64/** 68/**
65 * Flags that determine which of the standard streams 69 * Flags that determine which of the standard streams
@@ -379,14 +383,14 @@ GNUNET_OS_get_suid_binary_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
379 * @param addrlen length of the address 383 * @param addrlen length of the address
380 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort 384 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
381 */ 385 */
382typedef int 386typedef enum GNUNET_GenericReturnValue
383(*GNUNET_OS_NetworkInterfaceProcessor) (void *cls, 387(*GNUNET_OS_NetworkInterfaceProcessor)(void *cls,
384 const char *name, 388 const char *name,
385 int isDefault, 389 int isDefault,
386 const struct sockaddr *addr, 390 const struct sockaddr *addr,
387 const struct sockaddr *broadcast_addr, 391 const struct sockaddr *broadcast_addr,
388 const struct sockaddr *netmask, 392 const struct sockaddr *netmask,
389 socklen_t addrlen); 393 socklen_t addrlen);
390 394
391 395
392/** 396/**
@@ -399,6 +403,10 @@ void
399GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, 403GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc,
400 void *proc_cls); 404 void *proc_cls);
401 405
406#ifndef HAVE_SYSCONF
407#define HAVE_SYSCONF 0
408#endif
409
402/** 410/**
403 * @brief Get maximum string length returned by gethostname() 411 * @brief Get maximum string length returned by gethostname()
404 */ 412 */
@@ -469,12 +477,13 @@ GNUNET_OS_process_get_pid (struct GNUNET_OS_Process *proc);
469 * @return pointer to process structure of the new process, NULL on error 477 * @return pointer to process structure of the new process, NULL on error
470 */ 478 */
471struct GNUNET_OS_Process * 479struct GNUNET_OS_Process *
472GNUNET_OS_start_process_vap (enum GNUNET_OS_InheritStdioFlags std_inheritance, 480GNUNET_OS_start_process_vap (
473 struct GNUNET_DISK_PipeHandle *pipe_stdin, 481 enum GNUNET_OS_InheritStdioFlags std_inheritance,
474 struct GNUNET_DISK_PipeHandle *pipe_stdout, 482 struct GNUNET_DISK_PipeHandle *pipe_stdin,
475 struct GNUNET_DISK_PipeHandle *pipe_stderr, 483 struct GNUNET_DISK_PipeHandle *pipe_stdout,
476 const char *filename, 484 struct GNUNET_DISK_PipeHandle *pipe_stderr,
477 char *const argv[]); 485 const char *filename,
486 char *const argv[]);
478 487
479 488
480/** 489/**
@@ -489,11 +498,13 @@ GNUNET_OS_start_process_vap (enum GNUNET_OS_InheritStdioFlags std_inheritance,
489 * @return pointer to process structure of the new process, NULL on error 498 * @return pointer to process structure of the new process, NULL on error
490 */ 499 */
491struct GNUNET_OS_Process * 500struct GNUNET_OS_Process *
492GNUNET_OS_start_process (enum GNUNET_OS_InheritStdioFlags std_inheritance, 501GNUNET_OS_start_process (
493 struct GNUNET_DISK_PipeHandle *pipe_stdin, 502 enum GNUNET_OS_InheritStdioFlags std_inheritance,
494 struct GNUNET_DISK_PipeHandle *pipe_stdout, 503 struct GNUNET_DISK_PipeHandle *pipe_stdin,
495 struct GNUNET_DISK_PipeHandle *pipe_stderr, 504 struct GNUNET_DISK_PipeHandle *pipe_stdout,
496 const char *filename, ...); 505 struct GNUNET_DISK_PipeHandle *pipe_stderr,
506 const char *filename,
507 ...);
497 508
498 509
499/** 510/**
@@ -508,11 +519,14 @@ GNUNET_OS_start_process (enum GNUNET_OS_InheritStdioFlags std_inheritance,
508 * @return pointer to process structure of the new process, NULL on error 519 * @return pointer to process structure of the new process, NULL on error
509 */ 520 */
510struct GNUNET_OS_Process * 521struct GNUNET_OS_Process *
511GNUNET_OS_start_process_va (enum GNUNET_OS_InheritStdioFlags std_inheritance, 522GNUNET_OS_start_process_va (
512 struct GNUNET_DISK_PipeHandle *pipe_stdin, 523 enum GNUNET_OS_InheritStdioFlags std_inheritance,
513 struct GNUNET_DISK_PipeHandle *pipe_stdout, 524 struct GNUNET_DISK_PipeHandle *pipe_stdin,
514 struct GNUNET_DISK_PipeHandle *pipe_stderr, 525 struct GNUNET_DISK_PipeHandle *pipe_stdout,
515 const char *filename, va_list va); 526 struct GNUNET_DISK_PipeHandle *pipe_stderr,
527 const char *filename,
528 va_list va);
529
516 530
517/** 531/**
518 * Start a process. 532 * Start a process.
@@ -526,10 +540,11 @@ GNUNET_OS_start_process_va (enum GNUNET_OS_InheritStdioFlags std_inheritance,
526 * @return pointer to process structure of the new process, NULL on error 540 * @return pointer to process structure of the new process, NULL on error
527 */ 541 */
528struct GNUNET_OS_Process * 542struct GNUNET_OS_Process *
529GNUNET_OS_start_process_v (enum GNUNET_OS_InheritStdioFlags std_inheritance, 543GNUNET_OS_start_process_v (
530 const int *lsocks, 544 enum GNUNET_OS_InheritStdioFlags std_inheritance,
531 const char *filename, 545 const int *lsocks,
532 char *const argv[]); 546 const char *filename,
547 char *const argv[]);
533 548
534 549
535/** 550/**
@@ -550,9 +565,11 @@ GNUNET_OS_start_process_v (enum GNUNET_OS_InheritStdioFlags std_inheritance,
550 * @return pointer to process structure of the new process, NULL on error 565 * @return pointer to process structure of the new process, NULL on error
551 */ 566 */
552struct GNUNET_OS_Process * 567struct GNUNET_OS_Process *
553GNUNET_OS_start_process_s (enum GNUNET_OS_InheritStdioFlags std_inheritance, 568GNUNET_OS_start_process_s (
554 const int *lsocks, 569 enum GNUNET_OS_InheritStdioFlags std_inheritance,
555 const char *filename, ...); 570 const int *lsocks,
571 const char *filename,
572 ...);
556 573
557 574
558/** 575/**
@@ -592,11 +609,12 @@ GNUNET_OS_command_stop (struct GNUNET_OS_CommandHandle *cmd);
592 * @return NULL on error 609 * @return NULL on error
593 */ 610 */
594struct GNUNET_OS_CommandHandle * 611struct GNUNET_OS_CommandHandle *
595GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, 612GNUNET_OS_command_run (
596 void *proc_cls, 613 GNUNET_OS_LineProcessor proc,
597 struct GNUNET_TIME_Relative timeout, 614 void *proc_cls,
598 const char *binary, 615 struct GNUNET_TIME_Relative timeout,
599 ...); 616 const char *binary,
617 ...);
600 618
601 619
602/** 620/**
@@ -608,7 +626,7 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc,
608 * @param code return code/signal number 626 * @param code return code/signal number
609 * @return #GNUNET_OK on success, #GNUNET_NO if the process is still running, #GNUNET_SYSERR otherwise 627 * @return #GNUNET_OK on success, #GNUNET_NO if the process is still running, #GNUNET_SYSERR otherwise
610 */ 628 */
611int 629enum GNUNET_GenericReturnValue
612GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, 630GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
613 enum GNUNET_OS_ProcessStatusType *type, 631 enum GNUNET_OS_ProcessStatusType *type,
614 unsigned long *code); 632 unsigned long *code);
@@ -624,7 +642,7 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
624 * @param proc pointer to process structure of the process to wait for 642 * @param proc pointer to process structure of the process to wait for
625 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 643 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
626 */ 644 */
627int 645enum GNUNET_GenericReturnValue
628GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc); 646GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc);
629 647
630 648
@@ -637,7 +655,7 @@ GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc);
637 * @param code return code/signal number 655 * @param code return code/signal number
638 * @return #GNUNET_OK on success, #GNUNET_NO if the process is still running, #GNUNET_SYSERR otherwise 656 * @return #GNUNET_OK on success, #GNUNET_NO if the process is still running, #GNUNET_SYSERR otherwise
639 */ 657 */
640int 658enum GNUNET_GenericReturnValue
641GNUNET_OS_process_wait_status (struct GNUNET_OS_Process *proc, 659GNUNET_OS_process_wait_status (struct GNUNET_OS_Process *proc,
642 enum GNUNET_OS_ProcessStatusType *type, 660 enum GNUNET_OS_ProcessStatusType *type,
643 unsigned long *code); 661 unsigned long *code);
@@ -690,4 +708,6 @@ GNUNET_OS_check_helper_binary (const char *binary,
690 708
691/** @} */ /* end of group */ 709/** @} */ /* end of group */
692 710
711/** @} */ /* end of group addition */
712
693/* end of gnunet_os_lib.h */ 713/* end of gnunet_os_lib.h */
diff --git a/src/include/gnunet_peer_lib.h b/src/include/gnunet_peer_lib.h
index f94b883f8..4a67878b9 100644
--- a/src/include/gnunet_peer_lib.h
+++ b/src/include/gnunet_peer_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs
28 * @{
29 *
22 * @author Christian Grothoff 30 * @author Christian Grothoff
23 * 31 *
24 * @file 32 * @file
@@ -32,6 +40,7 @@
32#ifndef GNUNET_PEER_LIB_H 40#ifndef GNUNET_PEER_LIB_H
33#define GNUNET_PEER_LIB_H 41#define GNUNET_PEER_LIB_H
34 42
43
35#include "gnunet_util_lib.h" 44#include "gnunet_util_lib.h"
36 45
37#ifdef __cplusplus 46#ifdef __cplusplus
@@ -126,4 +135,6 @@ GNUNET_PEER_resolve2 (GNUNET_PEER_Id id);
126 135
127/** @} */ /* end of group */ 136/** @} */ /* end of group */
128 137
138/** @} */ /* end of group addition */
139
129/* end of gnunet_peer_lib.h */ 140/* end of gnunet_peer_lib.h */
diff --git a/src/include/gnunet_peerinfo_service.h b/src/include/gnunet_peerinfo_service.h
deleted file mode 100644
index cdea1a95f..000000000
--- a/src/include/gnunet_peerinfo_service.h
+++ /dev/null
@@ -1,210 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2009, 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,
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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @author Christian Grothoff
22 *
23 * @file
24 * Maintain the list of currently known hosts
25 *
26 * @defgroup peerinfo Peer Info service
27 * Maintain the list of currently known hosts.
28 *
29 * Holds an in-memory structure of data/hosts.
30 *
31 * @see [Documentation](https://gnunet.org/gnunets-peerinfo-subsystem)
32 *
33 * @{
34 */
35
36#ifndef GNUNET_PEERINFO_SERVICE_H
37#define GNUNET_PEERINFO_SERVICE_H
38
39#include "gnunet_common.h"
40#include "gnunet_configuration_lib.h"
41#include "gnunet_crypto_lib.h"
42#include "gnunet_hello_lib.h"
43
44#ifdef __cplusplus
45extern "C"
46{
47#if 0 /* keep Emacsens' auto-indent happy */
48}
49#endif
50#endif
51
52
53/**
54 * Handle to the peerinfo service.
55 */
56struct GNUNET_PEERINFO_Handle;
57
58
59/**
60 * Connect to the peerinfo service.
61 *
62 * @param cfg configuration to use
63 * @return NULL on error (configuration related, actual connection
64 * etablishment may happen asynchronously).
65 */
66struct GNUNET_PEERINFO_Handle *
67GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
68
69
70/**
71 * Disconnect from the peerinfo service. Note that all iterators must
72 * have completed or have been cancelled by the time this function is
73 * called (otherwise, calling this function is a serious error).
74 * Furthermore, if #GNUNET_PEERINFO_add_peer() operations are still
75 * pending, they will be cancelled silently on disconnect.
76 *
77 * @param h handle to disconnect
78 */
79void
80GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h);
81
82
83/**
84 * Add a host to the persistent list. This method operates in
85 * semi-reliable mode: if the transmission is not completed by
86 * the time #GNUNET_PEERINFO_disconnect() is called, it will be
87 * aborted. Furthermore, if a second HELLO is added for the
88 * same peer before the first one was transmitted, PEERINFO may
89 * merge the two HELLOs prior to transmission to the service.
90 *
91 * @param h handle to the peerinfo service
92 * @param hello the verified (!) HELLO message
93 * @param cont continuation to call when done, NULL is allowed
94 * @param cont_cls closure for @a cont
95 * @return handle to cancel add operation; all pending
96 * 'add' operations will be cancelled automatically
97 * on disconnect, so it is not necessary to keep this
98 * handle (unless @a cont is non-NULL and at some point
99 * calling @a cont must be prevented)
100 */
101struct GNUNET_MQ_Envelope *
102GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
103 const struct GNUNET_HELLO_Message *hello,
104 GNUNET_SCHEDULER_TaskCallback cont,
105 void *cont_cls);
106
107
108/**
109 * Type of an iterator over the hosts. Note that each
110 * host will be called with each available protocol.
111 *
112 * @param cls closure
113 * @param peer id of the peer, NULL for last call
114 * @param hello hello message for the peer (can be NULL)
115 * @param error message
116 */
117typedef void
118(*GNUNET_PEERINFO_Processor) (void *cls,
119 const struct GNUNET_PeerIdentity *peer,
120 const struct GNUNET_HELLO_Message *hello,
121 const char *err_msg);
122
123
124/**
125 * Handle for cancellation of iteration over peers.
126 */
127struct GNUNET_PEERINFO_IteratorContext;
128
129
130/**
131 * Call a method for each known matching host. The callback method
132 * will be invoked once for each matching host and then finally once
133 * with a NULL pointer. After that final invocation, the iterator
134 * context must no longer be used.
135 *
136 * Instead of calling this function with `peer == NULL` it is often
137 * better to use #GNUNET_PEERINFO_notify().
138 *
139 * @param h handle to the peerinfo service
140 * @param include_friend_only include HELLO messages for friends only
141 * @param peer restrict iteration to this peer only (can be NULL)
142 * @param timeout how long to wait until timing out
143 * @param callback the method to call for each peer
144 * @param callback_cls closure for @a callback
145 * @return iterator context
146 */
147struct GNUNET_PEERINFO_IteratorContext *
148GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
149 int include_friend_only,
150 const struct GNUNET_PeerIdentity *peer,
151 GNUNET_PEERINFO_Processor callback,
152 void *callback_cls);
153
154
155/**
156 * Cancel an iteration over peer information.
157 *
158 * @param ic context of the iterator to cancel
159 */
160void
161GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic);
162
163
164/**
165 * Handle for notifications about changes to the set of known peers.
166 */
167struct GNUNET_PEERINFO_NotifyContext;
168
169
170/**
171 * Call a method whenever our known information about peers
172 * changes. Initially calls the given function for all known
173 * peers and then only signals changes.
174 *
175 * If @a include_friend_only is set to #GNUNET_YES peerinfo will include HELLO
176 * messages which are intended for friend to friend mode and which do not
177 * have to be gossiped. Otherwise these messages are skipped.
178 *
179 * @param cfg configuration to use
180 * @param include_friend_only include HELLO messages for friends only
181 * @param callback the method to call for each peer
182 * @param callback_cls closure for @a callback
183 * @return NULL on error
184 */
185struct GNUNET_PEERINFO_NotifyContext *
186GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
187 int include_friend_only,
188 GNUNET_PEERINFO_Processor callback,
189 void *callback_cls);
190
191
192/**
193 * Stop notifying about changes.
194 *
195 * @param nc context to stop notifying
196 */
197void
198GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc);
199
200
201#if 0 /* keep Emacsens' auto-indent happy */
202{
203#endif
204#ifdef __cplusplus
205}
206#endif
207
208#endif
209
210/** @} */ /* end of group */
diff --git a/src/include/gnunet_peerstore_plugin.h b/src/include/gnunet_peerstore_plugin.h
index 90190e5b5..6ecb9135a 100644
--- a/src/include/gnunet_peerstore_plugin.h
+++ b/src/include/gnunet_peerstore_plugin.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Backbone
23 * @{
24 *
22 * @author Omar Tarabai 25 * @author Omar Tarabai
23 * 26 *
24 * @file 27 * @file
@@ -31,6 +34,7 @@
31#ifndef GNUNET_PEERSTORE_PLUGIN_H 34#ifndef GNUNET_PEERSTORE_PLUGIN_H
32#define GNUNET_PEERSTORE_PLUGIN_H 35#define GNUNET_PEERSTORE_PLUGIN_H
33 36
37
34#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
35#include "gnunet_peerstore_service.h" 39#include "gnunet_peerstore_service.h"
36 40
@@ -42,6 +46,19 @@ extern "C"
42#endif 46#endif
43#endif 47#endif
44 48
49/**
50 * Function called by PEERSTORE for each matching record.
51 *
52 * @param cls closure
53 * @param seq sequence in interation
54 * @param record peerstore record information
55 * @param emsg error message, or NULL if no errors
56 */
57typedef void (*GNUNET_PEERSTORE_PluginProcessor) (
58 void *cls,
59 uint64_t seq,
60 const struct GNUNET_PEERSTORE_Record *record,
61 const char *emsg);
45 62
46/** 63/**
47 * @brief struct returned by the initialization function of the plugin 64 * @brief struct returned by the initialization function of the plugin
@@ -89,6 +106,7 @@ struct GNUNET_PEERSTORE_PluginFunctions
89 * @param sub_system name of sub system 106 * @param sub_system name of sub system
90 * @param peer Peer identity (can be NULL) 107 * @param peer Peer identity (can be NULL)
91 * @param key entry key string (can be NULL) 108 * @param key entry key string (can be NULL)
109 * @param limit max number of results to give
92 * @param iter function to call asynchronously with the results, terminated 110 * @param iter function to call asynchronously with the results, terminated
93 * by a NULL result 111 * by a NULL result
94 * @param iter_cls closure for @a iter 112 * @param iter_cls closure for @a iter
@@ -100,7 +118,9 @@ struct GNUNET_PEERSTORE_PluginFunctions
100 const char *sub_system, 118 const char *sub_system,
101 const struct GNUNET_PeerIdentity *peer, 119 const struct GNUNET_PeerIdentity *peer,
102 const char *key, 120 const char *key,
103 GNUNET_PEERSTORE_Processor iter, 121 uint64_t serial,
122 uint64_t limit,
123 GNUNET_PEERSTORE_PluginProcessor iter,
104 void *iter_cls); 124 void *iter_cls);
105 125
106 /** 126 /**
@@ -131,3 +151,5 @@ struct GNUNET_PEERSTORE_PluginFunctions
131#endif 151#endif
132 152
133/** @} */ /* end of group */ 153/** @} */ /* end of group */
154
155/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_peerstore_service.h b/src/include/gnunet_peerstore_service.h
index 91a8f2e66..3fb9df82a 100644
--- a/src/include/gnunet_peerstore_service.h
+++ b/src/include/gnunet_peerstore_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Backbone
23 * @{
24 *
22 * @author Omar Tarabai 25 * @author Omar Tarabai
23 * 26 *
24 * @file 27 * @file
@@ -33,6 +36,7 @@
33#ifndef GNUNET_PEERSTORE_SERVICE_H 36#ifndef GNUNET_PEERSTORE_SERVICE_H
34#define GNUNET_PEERSTORE_SERVICE_H 37#define GNUNET_PEERSTORE_SERVICE_H
35 38
39
36#include "gnunet_util_lib.h" 40#include "gnunet_util_lib.h"
37 41
38#ifdef __cplusplus 42#ifdef __cplusplus
@@ -42,6 +46,10 @@ extern "C" {
42#endif 46#endif
43#endif 47#endif
44 48
49/**
50 * Key used for storing HELLO in the peerstore
51 */
52#define GNUNET_PEERSTORE_HELLO_KEY "peerstore-peer-hello-uri"
45 53
46/** 54/**
47 * Key used for storing addresses in URL format in the peerstore 55 * Key used for storing addresses in URL format in the peerstore
@@ -58,32 +66,32 @@ extern "C" {
58 * messages. 66 * messages.
59 */ 67 */
60#define GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME \ 68#define GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME \
61 "transport-backchannel-monotonic-time" 69 "transport-backchannel-monotonic-time"
62 70
63/** 71/**
64 * Key used to store sender's monotonic time from DV learn 72 * Key used to store sender's monotonic time from DV learn
65 * messages. 73 * messages.
66 */ 74 */
67#define GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME \ 75#define GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME \
68 "transport-dv-learn-monotonic-time" 76 "transport-dv-learn-monotonic-time"
69 77
70/** 78/**
71 * Key used to store sender's monotonic time from handshake message. 79 * Key used to store sender's monotonic time from handshake message.
72 */ 80 */
73#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE \ 81#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE \
74 "transport-tcp-communicator-handshake" 82 "transport-tcp-communicator-handshake"
75 83
76/** 84/**
77 * Key used to store sender's monotonic time from handshake ack message. 85 * Key used to store sender's monotonic time from handshake ack message.
78 */ 86 */
79#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK \ 87#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK \
80 "transport-tcp-communicator-handshake-ack" 88 "transport-tcp-communicator-handshake-ack"
81 89
82/** 90/**
83 * Key used to store sender's monotonic time from rekey message. 91 * Key used to store sender's monotonic time from rekey message.
84 */ 92 */
85#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY \ 93#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY \
86 "transport-tcp-communicator-rekey" 94 "transport-tcp-communicator-rekey"
87 95
88 96
89/** 97/**
@@ -100,7 +108,8 @@ enum GNUNET_PEERSTORE_StoreOption
100 * Delete any previous values for the given key before 108 * Delete any previous values for the given key before
101 * storing the given value. 109 * storing the given value.
102 */ 110 */
103 GNUNET_PEERSTORE_STOREOPTION_REPLACE = 1 111 GNUNET_PEERSTORE_STOREOPTION_REPLACE = 1,
112
104}; 113};
105 114
106/** 115/**
@@ -114,6 +123,11 @@ struct GNUNET_PEERSTORE_Handle;
114struct GNUNET_PEERSTORE_StoreContext; 123struct GNUNET_PEERSTORE_StoreContext;
115 124
116/** 125/**
126 * Context for the info handler.
127 */
128struct GNUNET_PEERSTORE_NotifyContext;
129
130/**
117 * Single PEERSTORE record 131 * Single PEERSTORE record
118 */ 132 */
119struct GNUNET_PEERSTORE_Record 133struct GNUNET_PEERSTORE_Record
@@ -148,11 +162,6 @@ struct GNUNET_PEERSTORE_Record
148 */ 162 */
149 struct GNUNET_TIME_Absolute expiry; 163 struct GNUNET_TIME_Absolute expiry;
150 164
151 /**
152 * Client from which this record originated.
153 * NOTE: This is internal to the service.
154 */
155 struct GNUNET_SERVICE_Client *client;
156}; 165};
157 166
158 167
@@ -166,9 +175,16 @@ typedef void (*GNUNET_PEERSTORE_Continuation) (void *cls, int success);
166 175
167 176
168/** 177/**
178 * Context for a add hello uri request.
179 */
180struct GNUNET_PEERSTORE_StoreHelloContext;
181
182
183/**
169 * Function called by PEERSTORE for each matching record. 184 * Function called by PEERSTORE for each matching record.
170 * 185 *
171 * @param cls closure 186 * @param cls closure
187 * @param seq sequence in interation
172 * @param record peerstore record information 188 * @param record peerstore record information
173 * @param emsg error message, or NULL if no errors 189 * @param emsg error message, or NULL if no errors
174 */ 190 */
@@ -177,6 +193,43 @@ typedef void (*GNUNET_PEERSTORE_Processor) (
177 const struct GNUNET_PEERSTORE_Record *record, 193 const struct GNUNET_PEERSTORE_Record *record,
178 const char *emsg); 194 const char *emsg);
179 195
196/**
197 * Function called by PEERSTORE when notifying a client about a changed hello.
198 *
199 * @param cls closure
200 * @param hello_uri Hello uri.
201 */
202typedef void (*GNUNET_PEERSTORE_hello_notify_cb) (
203 void *cls,
204 const struct GNUNET_PeerIdentity *peer,
205 const struct GNUNET_MessageHeader *hello,
206 const char *err_msg);
207
208/**
209 * Add hello to peerstore.
210 *
211 * @param h handle for peerstore.
212 * @param msg The hello to add.
213 * @param cont The continuation function to execute after storing.
214 * @param cont_cls The continuation function closure.
215 * @return The context for storing.
216 */
217struct GNUNET_PEERSTORE_StoreHelloContext *
218GNUNET_PEERSTORE_hello_add (struct GNUNET_PEERSTORE_Handle *h,
219 const struct GNUNET_MessageHeader *msg,
220 GNUNET_PEERSTORE_Continuation cont,
221 void *cont_cls);
222
223
224/**
225 * Cancel the request to add a hello.
226 *
227 * @param huc The context for storing a hello.
228 */
229void
230GNUNET_PEERSTORE_hello_add_cancel (struct
231 GNUNET_PEERSTORE_StoreHelloContext *huc);
232
180 233
181/** 234/**
182 * Connect to the PEERSTORE service. 235 * Connect to the PEERSTORE service.
@@ -188,15 +241,13 @@ GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
188 241
189 242
190/** 243/**
191 * Disconnect from the PEERSTORE service. Any pending ITERATE and WATCH requests 244 * Disconnect from the PEERSTORE service. Any pending ITERATE and WATCH and
192 * will be canceled. 245 * STORE requests will be canceled.
193 * Any pending STORE requests will depend on @e snyc_first flag.
194 * 246 *
195 * @param h handle to disconnect 247 * @param h handle to disconnect
196 * @param sync_first send any pending STORE requests before disconnecting
197 */ 248 */
198void 249void
199GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first); 250GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h);
200 251
201 252
202/** 253/**
@@ -238,63 +289,130 @@ GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc);
238 289
239 290
240/** 291/**
241 * Iterate over records matching supplied key information 292 * Iterate over peerstore entries.
293 * The iteration can be filtered to contain only records
294 * matching @a peer and/or @a key.
295 * The @a sub_system to match must be provided.
296 * @a callback will be called with (each) matching record.
297 * #GNUNET_PEERSTORE_iteration_next() must be invoked
298 * to continue processing until the end of the iteration is
299 * reached.
242 * 300 *
243 * @param h handle to the PEERSTORE service 301 * @param h handle to the PEERSTORE service
244 * @param sub_system name of sub system 302 * @param sub_system name of sub system
245 * @param peer Peer identity (can be NULL) 303 * @param peer Peer identity (can be NULL)
246 * @param key entry key string (can be NULL) 304 * @param key entry key string (can be NULL)
247 * @param callback function called with each matching record, all NULL's on end 305 * @param callback function called with each matching record. The record will be NULL to indicate end.
248 * @param callback_cls closure for @a callback 306 * @param callback_cls closure for @a callback
307 * @return Handle to iteration request
249 */ 308 */
250struct GNUNET_PEERSTORE_IterateContext * 309struct GNUNET_PEERSTORE_IterateContext *
251GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, 310GNUNET_PEERSTORE_iteration_start (struct GNUNET_PEERSTORE_Handle *h,
252 const char *sub_system, 311 const char *sub_system,
253 const struct GNUNET_PeerIdentity *peer, 312 const struct GNUNET_PeerIdentity *peer,
254 const char *key, 313 const char *key,
255 GNUNET_PEERSTORE_Processor callback, 314 GNUNET_PEERSTORE_Processor callback,
256 void *callback_cls); 315 void *callback_cls);
257 316
258 317
259/** 318/**
260 * Cancel an iterate request 319 * Continue an iteration.
261 * Please do not call after the iterate request is done 320 * Do NOT call after the iterate request is done.
262 * 321 *
263 * @param ic Iterate request context as returned by GNUNET_PEERSTORE_iterate() 322 * @param ic Iterate request context as returned by #GNUNET_PEERSTORE_iteration_start()
323 * @param limit how many records to return max until #GNUNET_PEERSTORE_iterate_next() needs to be called again.
264 */ 324 */
265void 325void
266GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic); 326GNUNET_PEERSTORE_iteration_next (struct GNUNET_PEERSTORE_IterateContext *ic,
327 uint64_t limit);
267 328
268 329
269/** 330/**
331 * Cancel an iteration.
332 * Do NOT call after the iterate request is done
333 *
334 * @param ic Iterate request context as returned by #GNUNET_PEERSTORE_iteration_start()
335 */
336void
337GNUNET_PEERSTORE_iteration_stop (struct GNUNET_PEERSTORE_IterateContext *ic);
338
339/**
270 * Request watching a given key 340 * Request watching a given key
271 * User will be notified with any new values added to key. 341 * The monitoring can be filtered to contain only records
342 * matching @a peer and/or @a key.
343 * The @a sub_system to match must be provided.
344 * @a callback will be called with (each) matching new record.
345 * #GNUNET_PEERSTORE_monitor_next() must be invoked
346 * to continue processing until @a sync_cb is
347 * called, indicating that the caller should be up-to-date.
348 * The caller will be notified with any new values added to key
349 * through @a callback.
350 * If @a iterate_first is set to GNUNET_YES, the monitor will first
351 * iterate over all existing, matching records. In any case,
352 * after @a sync_cb is called the first time monitoring starts.
272 * 353 *
273 * @param h handle to the PEERSTORE service 354 * @param h handle to the PEERSTORE service
355 * @param iterate_first first iterated of all results if GNUNET_YES
274 * @param sub_system name of sub system 356 * @param sub_system name of sub system
275 * @param peer Peer identity 357 * @param peer Peer identity
276 * @param key entry key string 358 * @param key entry key string
359 * @param error_cb function to call on error (i.e. disconnect); note that
360 * unlike the other error callbacks in this API, a call to this
361 * function does NOT destroy the monitor handle, it merely signals
362 * that monitoring is down. You need to still explicitly call
363 * #GNUNET_PEERSTORE_monitor_stop().
364 * @param error_cb_cls closure for @a error_cb
365 * @param sync_cb function called when we're in sync with the peerstore
366 * @param sync_cb_cls closure for @a sync_cb
277 * @param callback function called with each new value 367 * @param callback function called with each new value
278 * @param callback_cls closure for @a callback 368 * @param callback_cls closure for @a callback
279 * @return Handle to watch request 369 * @return Handle to watch request
280 */ 370 */
281struct GNUNET_PEERSTORE_WatchContext * 371struct GNUNET_PEERSTORE_Monitor *
282GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h, 372GNUNET_PEERSTORE_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
283 const char *sub_system, 373 int iterate_first,
284 const struct GNUNET_PeerIdentity *peer, 374 const char *sub_system,
285 const char *key, 375 const struct GNUNET_PeerIdentity *peer,
286 GNUNET_PEERSTORE_Processor callback, 376 const char *key,
287 void *callback_cls); 377 GNUNET_SCHEDULER_TaskCallback error_cb,
288 378 void *error_cb_cls,
379 GNUNET_SCHEDULER_TaskCallback sync_cb,
380 void *sync_cb_cls,
381 GNUNET_PEERSTORE_Processor callback,
382 void *callback_cls);
289 383
290/** 384/**
291 * Cancel a watch request 385 * Calls the monitor processor specified in #GNUNET_PEERSTORE_monitor_start
386 * for the next record(s). This function is used to allow clients that merely
387 * monitor the NAMESTORE to still throttle namestore operations, so we can be
388 * sure that the monitors can keep up.
389 *
390 * Note that #GNUNET_PEERSTORE_store() only waits for this
391 * call if the previous limit set by the client was already reached.
392 * Thus, by using a @a limit greater than 1, monitors basically enable
393 * a queue of notifications to be processed asynchronously with some
394 * delay. Note that even with a limit of 1 the
395 * #GNUNET_PEERSTORE_store() function will run asynchronously
396 * and the continuation may be invoked before the monitors completed
397 * (or even started) processing the notification. Thus, monitors will
398 * only closely track the current state of the peerstore, but not
399 * be involved in the transactions.
292 * 400 *
293 * @param wc handle to the watch request 401 * @param zm the monitor
402 * @param limit number of records to return to the iterator in one shot
403 * (before #GNUNET_PEERSTORE_monitor_next is to be called again)
294 */ 404 */
295void 405void
296GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc); 406GNUNET_PEERSTORE_monitor_next (struct GNUNET_PEERSTORE_Monitor *zm,
407 uint64_t limit);
297 408
409/**
410 * Stop monitoring.
411 *
412 * @param zm handle to the monitor activity to stop
413 */
414void
415GNUNET_PEERSTORE_monitor_stop (struct GNUNET_PEERSTORE_Monitor *zm);
298 416
299#if 0 /* keep Emacsens' auto-indent happy */ 417#if 0 /* keep Emacsens' auto-indent happy */
300{ 418{
@@ -306,3 +424,5 @@ GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc);
306#endif 424#endif
307 425
308/** @} */ /* end of group */ 426/** @} */ /* end of group */
427
428/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_plugin_lib.h b/src/include/gnunet_plugin_lib.h
index d265eb343..2a9cde47f 100644
--- a/src/include/gnunet_plugin_lib.h
+++ b/src/include/gnunet_plugin_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs
28 * @{
29 *
22 * @author Christian Grothoff 30 * @author Christian Grothoff
23 * 31 *
24 * @file 32 * @file
@@ -40,9 +48,6 @@ extern "C"
40#endif 48#endif
41#endif 49#endif
42 50
43#include "gnunet_common.h"
44#include "gnunet_configuration_lib.h"
45
46 51
47/** 52/**
48 * Signature of any function exported by a plugin. 53 * Signature of any function exported by a plugin.
@@ -65,7 +70,7 @@ typedef void *
65 * @param library_name name of the plugin to test if it is installed 70 * @param library_name name of the plugin to test if it is installed
66 * @return #GNUNET_YES if the plugin exists, #GNUNET_NO if not 71 * @return #GNUNET_YES if the plugin exists, #GNUNET_NO if not
67 */ 72 */
68int 73enum GNUNET_GenericReturnValue
69GNUNET_PLUGIN_test (const char *library_name); 74GNUNET_PLUGIN_test (const char *library_name);
70 75
71 76
@@ -169,4 +174,6 @@ GNUNET_PLUGIN_unload (const char *library_name,
169 174
170/** @} */ /* end of group */ 175/** @} */ /* end of group */
171 176
177/** @} */ /* end of group addition */
178
172/* end of gnunet_plugin_lib.h */ 179/* end of gnunet_plugin_lib.h */
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h
index 6a374f7e2..5f698058a 100644
--- a/src/include/gnunet_pq_lib.h
+++ b/src/include/gnunet_pq_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2016, 2017, 2020, 2021 GNUnet e.V. 3 Copyright (C) 2016, 2017, 2020-2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -25,9 +25,19 @@
25#ifndef GNUNET_PQ_LIB_H 25#ifndef GNUNET_PQ_LIB_H
26#define GNUNET_PQ_LIB_H 26#define GNUNET_PQ_LIB_H
27 27
28
28#include <libpq-fe.h> 29#include <libpq-fe.h>
30#include <stdint.h>
31#include "gnunet_common.h"
32#include "gnunet_time_lib.h"
29#include "gnunet_util_lib.h" 33#include "gnunet_util_lib.h"
30#include "gnunet_db_lib.h" 34#include "gnunet_db_lib.h"
35#include "postgres_ext.h"
36
37/**
38 * Postgres context.
39 */
40struct GNUNET_PQ_Context;
31 41
32/* ************************* pq_query_helper.c functions ************************ */ 42/* ************************* pq_query_helper.c functions ************************ */
33 43
@@ -57,6 +67,14 @@ typedef int
57 void *scratch[], 67 void *scratch[],
58 unsigned int scratch_length); 68 unsigned int scratch_length);
59 69
70/**
71 * Function called to cleanup the closure of SQL parameters converter. Will be
72 * called with GNUNET_PQ_query_params_cleanup
73 *
74 * @param cls closure
75 */
76typedef void
77(*GNUNET_PQ_QueryConverter_Cleanup)(void *cls);
60 78
61/** 79/**
62 * @brief Description of a DB query parameter. 80 * @brief Description of a DB query parameter.
@@ -70,10 +88,20 @@ struct GNUNET_PQ_QueryParam
70 88
71 /** 89 /**
72 * Closure for @e conv. 90 * Closure for @e conv.
91 * The function @conv_cls_cleanup can be set to cleanup the closure.
92 * The cleanup of the closure MUST be triggered manually by a call to
93 * GNUNET_PQ_query_params_cleanup.
73 */ 94 */
74 void *conv_cls; 95 void *conv_cls;
75 96
76 /** 97 /**
98 * Function to cleanup the closure @a conv_cls, may be NULL.
99 * The cleanup of the closure MUST be triggered manually by a call to
100 * GNUNET_PQ_query_params_cleanup.
101 */
102 GNUNET_PQ_QueryConverter_Cleanup conv_cls_cleanup;
103
104 /**
77 * Data or NULL. 105 * Data or NULL.
78 */ 106 */
79 const void *data; 107 const void *data;
@@ -90,13 +118,26 @@ struct GNUNET_PQ_QueryParam
90 118
91}; 119};
92 120
121/**
122 * Must be called to cleanup memory from closures after the query parameters
123 * have been used as much as needed.
124 *
125 * @param params Array of GNUNET_PQ_QueryParam which must terminate with a GNUNET_PQ_query_param_end
126 */
127void
128GNUNET_PQ_cleanup_query_params_closures (
129 const struct GNUNET_PQ_QueryParam *params);
93 130
94/** 131/**
95 * End of query parameter specification. 132 * End of query parameter specification.
96 */ 133 */
97#define GNUNET_PQ_query_param_end \ 134#define GNUNET_PQ_query_param_end \
98 { \ 135 { \
99 NULL, NULL, NULL, 0, 0 \ 136 .conv = NULL, \
137 .conv_cls = NULL, \
138 .data = NULL, \
139 .size = 0, \
140 .num_params = 0 \
100 } 141 }
101 142
102 143
@@ -114,7 +155,7 @@ GNUNET_PQ_query_param_null (void);
114 * @a ptr_size bytes. 155 * @a ptr_size bytes.
115 * 156 *
116 * @param ptr pointer to the query parameter to pass 157 * @param ptr pointer to the query parameter to pass
117 * @oaran ptr_size number of bytes in @a ptr 158 * @param ptr_size number of bytes in @a ptr
118 * @return query parameter to use 159 * @return query parameter to use
119 */ 160 */
120struct GNUNET_PQ_QueryParam 161struct GNUNET_PQ_QueryParam
@@ -133,6 +174,220 @@ GNUNET_PQ_query_param_string (const char *ptr);
133 174
134 175
135/** 176/**
177 * Pass a boolean into a query.
178 *
179 * @param b boolean bit to pass
180 * @return query parameter to use
181 */
182struct GNUNET_PQ_QueryParam
183GNUNET_PQ_query_param_bool (bool b);
184
185/**
186 * Returns the oid for a given datatype by name.
187 *
188 * @param db The db-connection
189 * @param name The name of the datatype
190 * @param[out] oid The OID of the datatype.
191 * @return GNUNET_OK when the datatype was found, GNUNET_SYSERR otherwise
192 */
193enum GNUNET_GenericReturnValue
194GNUNET_PQ_get_oid_by_name (
195 struct GNUNET_PQ_Context *db,
196 const char *name,
197 Oid *oid);
198
199
200/**
201 * The header for a postgresql array in binary format. note that this a
202 * simplified special case of the general structure (which contains pointers),
203 * as we only support one-dimensional arrays.
204 *
205 * Note that all values must be in network-byte-order.
206 */
207struct GNUNET_PQ_ArrayHeader_P
208{
209 uint32_t ndim; /* number of dimensions. we only support ndim = 1 */
210 uint32_t has_null;
211 uint32_t oid; /* oid of the elements */
212 uint32_t dim; /* size of the array */
213 uint32_t lbound; /* index value of first element in the db (default: 1). */
214} __attribute__((packed));
215
216
217/**
218 * Generate query parameter for an array of bool in host byte order.
219 *
220 * @param num Number of elements in @a elements
221 * @param elements Continuous array of @a num boolean elements
222 * @param db Database context, needed for database-depending encoding of @a elements
223 * @return query parameter to use
224 */
225struct GNUNET_PQ_QueryParam
226GNUNET_PQ_query_param_array_bool (
227 unsigned int num,
228 const bool *elements,
229 struct GNUNET_PQ_Context *db);
230
231/**
232 * Generate query parameter for an array of uint16_t in host byte order.
233 * Note that the (unsigend) elements are not checked to wrap over INT2_MAX
234 *
235 * @param num Number of elements in @a elements
236 * @param elements Continuous array of @a num uint16 elements
237 * @param db Database context, needed for database-depending encoding of @a elements
238 * @return query parameter to use
239 */
240struct GNUNET_PQ_QueryParam
241GNUNET_PQ_query_param_array_uint16 (
242 unsigned int num,
243 const uint16_t *elements,
244 struct GNUNET_PQ_Context *db);
245
246/**
247 * Generate query parameter for an array of uint32_t in host byte order.
248 * Note that the (unsigend) elements are not checked to wrap over INT4_MAX
249 *
250 * @param num Number of elements in @a elements
251 * @param elements Continuous Array of @a num uint32_t elements
252 * @param db Database context, needed for database-depending encoding of @a elements
253 * @return query parameter to use
254 */
255struct GNUNET_PQ_QueryParam
256GNUNET_PQ_query_param_array_uint32 (
257 unsigned int num,
258 const uint32_t *elements,
259 struct GNUNET_PQ_Context *db);
260
261/**
262 * Generate query parameter for an array of uint64 in host byte order.
263 * Note that the (unsigend) elements are not checked to wrap over INT8_MAX
264 *
265 * @param num Number of elements in @a elements
266 * @param elements Continuous array of @a num uint64_t elements
267 * @param db Database context, needed for database-depending encoding of @a elements
268 * @return query parameter to use
269 */
270struct GNUNET_PQ_QueryParam
271GNUNET_PQ_query_param_array_uint64 (
272 unsigned int num,
273 const uint64_t *elements,
274 struct GNUNET_PQ_Context *db);
275
276/**
277 * Generate query parameter for an array of buffers @a elements, each of
278 * corresponding size given in @a sizes.
279 *
280 * @param num Number of elements in @a elements
281 * @param elements Continous array of @a num buffers, each of corresponding size given in @a sizes.
282 * @param sizes Pointer to sizes in bytes of each element in @a elements
283 * @param db Database context, needed for database-depending encoding of @a elements
284 * @return query parameter to use
285 */
286struct GNUNET_PQ_QueryParam
287GNUNET_PQ_query_param_array_bytes (
288 unsigned int num,
289 const void *elements,
290 const size_t *sizes,
291 struct GNUNET_PQ_Context *db);
292
293/**
294 * Generate query parameter for an array of buffers @a elements,
295 * each of the same size @a size.
296 *
297 * @param num Number of elements in @a elements
298 * @param elements Continous array of @a num buffers, each with the same size @a same_size
299 * @param same_size Size in bytes of each element in @a elements
300 * @param db Database context, needed for database-depending encoding of @a elements
301 * @return query parameter to use
302 */
303struct GNUNET_PQ_QueryParam
304GNUNET_PQ_query_param_array_bytes_same_size (
305 unsigned int num,
306 const void *elements,
307 size_t same_size,
308 struct GNUNET_PQ_Context *db);
309
310/**
311 * Generate array of equal-sized query parameter with size determined
312 * by variable type from a pointer to an continuous array.
313 *
314 * @param num Number of elements in @a elements
315 * @param elements Continuous array of the query parameter to pass.
316 * @param db Database context, needed for database-depending encoding of @a elements
317 * @return query parameter to use
318 */
319#define GNUNET_PQ_query_param_array_auto_from_type(num, elements, db) \
320 GNUNET_PQ_query_param_array_bytes_same_size ((num), \
321 (elements), \
322 sizeof(*(elements)), \
323 (db))
324
325/**
326 * Generate query parameter for an array of pointers to buffers @a elements,
327 * each of the same size @a size.
328 *
329 * @param num Number of elements in @a elements
330 * @param elements Array of @a num pointers to buffers, each with the same size @a same_size
331 * @param same_size Size in bytes of each element in @a elements
332 * @param db Database context, needed for database-depending encoding of @a elements
333 * @return query parameter to use
334 */
335struct GNUNET_PQ_QueryParam
336GNUNET_PQ_query_param_array_ptrs_bytes_same_size (
337 unsigned int num,
338 const void *elements[static num],
339 size_t same_size,
340 struct GNUNET_PQ_Context *db);
341
342
343/**
344 * Generate array of equal-sized query parameter with size determined by
345 * variable type from a pointer to an array of pointers to objects of the same
346 * type.
347 *
348 * @param num Number of elements in @a elements
349 * @param elements Continuous array of the query parameter to pass.
350 * @param db Database context, needed for database-depending encoding of @a elements
351 * @return query parameter to use
352 */
353#define GNUNET_PQ_query_param_array_ptrs_auto_from_type(num, elements, db) \
354 GNUNET_PQ_query_param_array_ptrs_bytes_same_size ((num), \
355 (const void **) (elements), \
356 sizeof(*(elements[0])), \
357 (db))
358
359
360/**
361 * Generate query parameter for an array of strings (continuous)
362 *
363 * @param num Number of elements in @a elements
364 * @param elements Array of @a num continuous strings (zero-terminated each)
365 * @param db Database context, needed for database-depending encoding of @a elements
366 * @return query parameter to use
367 */
368struct GNUNET_PQ_QueryParam
369GNUNET_PQ_query_param_array_string (
370 unsigned int num,
371 const char *elements,
372 struct GNUNET_PQ_Context *db);
373
374
375/**
376 * Generate query parameter for an array of strings (pointers)
377 *
378 * @param num Number of elements in @a elements
379 * @param elements Array of @a num pointer to strings
380 * @param db Database context, needed for database-depending encoding of @a elements
381 * @return query parameter to use
382 */
383struct GNUNET_PQ_QueryParam
384GNUNET_PQ_query_param_array_ptrs_string (
385 unsigned int num,
386 const char *elements[static num],
387 struct GNUNET_PQ_Context *db);
388
389
390/**
136 * Generate fixed-size query parameter with size determined 391 * Generate fixed-size query parameter with size determined
137 * by variable type. 392 * by variable type.
138 * 393 *
@@ -142,6 +397,83 @@ GNUNET_PQ_query_param_string (const char *ptr);
142#define GNUNET_PQ_query_param_auto_from_type(x) \ 397#define GNUNET_PQ_query_param_auto_from_type(x) \
143 GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x))) 398 GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x)))
144 399
400/**
401 * Generate query parameter for an array of absolute time stamps (continuous)
402 *
403 * @param num Number of elements in @a elements
404 * @param elements Array of @a num absolute timestamps
405 * @return query parameter to use
406 */
407struct GNUNET_PQ_QueryParam
408GNUNET_PQ_query_param_array_abs_time (
409 unsigned int num,
410 const struct GNUNET_TIME_Absolute *elements,
411 struct GNUNET_PQ_Context *db);
412
413/**
414 * Generate query parameter for an array of absolute time stamps (pointers)
415 *
416 * @param num Number of elements in @a elements
417 * @param elements Array of @a num pointers to absolute timestamps
418 * @return query parameter to use
419 */
420struct GNUNET_PQ_QueryParam
421GNUNET_PQ_query_param_array_ptrs_abs_time (
422 unsigned int num,
423 const struct GNUNET_TIME_Absolute *elements[],
424 struct GNUNET_PQ_Context *db);
425
426/**
427 * Generate query parameter for an array of relative time stamps (continuous)
428 *
429 * @param num Number of elements in @a elements
430 * @param elements Array of @a num relative timestamps
431 * @return query parameter to use
432 */
433struct GNUNET_PQ_QueryParam
434GNUNET_PQ_query_param_array_rel_time (
435 unsigned int num,
436 const struct GNUNET_TIME_Relative *elements,
437 struct GNUNET_PQ_Context *db);
438
439/**
440 * Generate query parameter for an array of relative time stamps (pointers)
441 *
442 * @param num Number of elements in @a elements
443 * @param elements Array of @a num pointers to relative timestamps
444 * @return query parameter to use
445 */
446struct GNUNET_PQ_QueryParam
447GNUNET_PQ_query_param_array_ptrs_rel_time (
448 unsigned int num,
449 const struct GNUNET_TIME_Relative *elements[],
450 struct GNUNET_PQ_Context *db);
451
452/**
453 * Generate query parameter for an array of time stamps (continuous)
454 *
455 * @param num Number of elements in @a elements
456 * @param elements Array of @a num timestamps
457 * @return query parameter to use
458 */
459struct GNUNET_PQ_QueryParam
460GNUNET_PQ_query_param_array_timestamp (
461 unsigned int num,
462 const struct GNUNET_TIME_Timestamp *elements,
463 struct GNUNET_PQ_Context *db);
464
465/**
466 * Generate query parameter for an array of time stamps (pointers)
467 *
468 * @param num Number of elements in @a elements
469 * @param elements Array of @a num pointers to relative timestamps
470 * @return query parameter to use
471 */
472struct GNUNET_PQ_QueryParam
473GNUNET_PQ_query_param_array_ptrs_timestamp (
474 unsigned int num,
475 const struct GNUNET_TIME_Timestamp *elements[],
476 struct GNUNET_PQ_Context *db);
145 477
146/** 478/**
147 * Generate query parameter for an RSA public key. The 479 * Generate query parameter for an RSA public key. The
@@ -190,6 +522,17 @@ GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x);
190 522
191 523
192/** 524/**
525 * Generate query parameter for a timestamp.
526 * The database must store a 64-bit integer.
527 *
528 * @param x pointer to the query parameter to pass
529 * @return query parameter to use
530 */
531struct GNUNET_PQ_QueryParam
532GNUNET_PQ_query_param_timestamp (const struct GNUNET_TIME_Timestamp *x);
533
534
535/**
193 * Generate query parameter for an absolute time value. 536 * Generate query parameter for an absolute time value.
194 * The database must store a 64-bit integer. 537 * The database must store a 64-bit integer.
195 * 538 *
@@ -202,6 +545,18 @@ GNUNET_PQ_query_param_absolute_time_nbo (
202 545
203 546
204/** 547/**
548 * Generate query parameter for a timestamp in NBO.
549 * The database must store a 64-bit integer.
550 *
551 * @param x pointer to the query parameter to pass
552 * @return query parameter to use
553 */
554struct GNUNET_PQ_QueryParam
555GNUNET_PQ_query_param_timestamp_nbo (
556 const struct GNUNET_TIME_TimestampNBO *x);
557
558
559/**
205 * Generate query parameter for an uint16_t in host byte order. 560 * Generate query parameter for an uint16_t in host byte order.
206 * 561 *
207 * @param x pointer to the query parameter to pass 562 * @param x pointer to the query parameter to pass
@@ -222,7 +577,7 @@ GNUNET_PQ_query_param_uint32 (const uint32_t *x);
222 577
223 578
224/** 579/**
225 * Generate query parameter for an uint16_t in host byte order. 580 * Generate query parameter for an uint64_t in host byte order.
226 * 581 *
227 * @param x pointer to the query parameter to pass 582 * @param x pointer to the query parameter to pass
228 * @return query parameter to use 583 * @return query parameter to use
@@ -231,6 +586,57 @@ struct GNUNET_PQ_QueryParam
231GNUNET_PQ_query_param_uint64 (const uint64_t *x); 586GNUNET_PQ_query_param_uint64 (const uint64_t *x);
232 587
233 588
589/**
590 * Generate query parameter for an int64_t in host byte order.
591 *
592 * @param x pointer to the query parameter to pass
593 * @return query parameter to use
594 */
595struct GNUNET_PQ_QueryParam
596GNUNET_PQ_query_param_int64 (const int64_t *x);
597
598/**
599 * Generate query parameter for a blind sign public key.
600 * Internally, the various attributes of the public key
601 * will be serialized into on variable-size BLOB.
602 *
603 * @param pub pointer to the query parameter to pass
604 *
605 */
606struct GNUNET_PQ_QueryParam
607GNUNET_PQ_query_param_blind_sign_pub (
608 const struct GNUNET_CRYPTO_BlindSignPublicKey *pub);
609
610/**
611 * Generate query parameter for a blind sign private key of variable size.
612 *
613 * @param priv pointer to the query parameter to pass
614 *
615 */
616struct GNUNET_PQ_QueryParam
617GNUNET_PQ_query_param_blind_sign_priv (
618 const struct GNUNET_CRYPTO_BlindSignPrivateKey *priv);
619
620/**
621 * Generate query parameter for an unblinded signature of variable size.
622 *
623 * @param sig pointer to the query parameter to pass
624 *
625 */
626struct GNUNET_PQ_QueryParam
627GNUNET_PQ_query_param_unblinded_sig (
628 const struct GNUNET_CRYPTO_UnblindedSignature *sig);
629
630/**
631 * Generate query parameter for a blinded signature of variable size.
632 *
633 * @param b_sig pointer to the query parameter to pass
634 *
635 */
636struct GNUNET_PQ_QueryParam
637GNUNET_PQ_query_param_blinded_sig (
638 const struct GNUNET_CRYPTO_BlindedSignature *b_sig);
639
234/* ************************* pq_result_helper.c functions ************************ */ 640/* ************************* pq_result_helper.c functions ************************ */
235 641
236 642
@@ -280,8 +686,7 @@ struct GNUNET_PQ_ResultSpec
280 GNUNET_PQ_ResultConverter conv; 686 GNUNET_PQ_ResultConverter conv;
281 687
282 /** 688 /**
283 * Function to clean up result data, NULL if cleanup is 689 * Function to clean up result data, NULL if cleanup is not necessary.
284 * not necessary.
285 */ 690 */
286 GNUNET_PQ_ResultCleanup cleaner; 691 GNUNET_PQ_ResultCleanup cleaner;
287 692
@@ -296,9 +701,9 @@ struct GNUNET_PQ_ResultSpec
296 void *dst; 701 void *dst;
297 702
298 /** 703 /**
299 * Allowed size for the data, 0 for variable-size 704 * Allowed size for the data, 0 for variable-size (in this case, the type of
300 * (in this case, the type of @e dst is a `void **` 705 * @e dst is a `void **` and we need to allocate a buffer of the right
301 * and we need to allocate a buffer of the right size). 706 * size).
302 */ 707 */
303 size_t dst_size; 708 size_t dst_size;
304 709
@@ -318,10 +723,8 @@ struct GNUNET_PQ_ResultSpec
318 bool is_nullable; 723 bool is_nullable;
319 724
320 /** 725 /**
321 * Points to a location where we should store 726 * Points to a location where we should store "true" if the result found is
322 * "true" if the result found is NULL, and 727 * NULL, and otherwise "false". Only used if @e is_nullable is true.
323 * otherwise "false". Only used if @e is_nullable
324 * is true.
325 */ 728 */
326 bool *is_null; 729 bool *is_null;
327 730
@@ -348,8 +751,7 @@ struct GNUNET_PQ_ResultSpec
348 751
349 752
350/** 753/**
351 * Allow NULL value to be found in the database 754 * Allow NULL value to be found in the database for the given value.
352 * for the given value.
353 * 755 *
354 * @param rs result spec entry to modify 756 * @param rs result spec entry to modify
355 * @param[out] is_null location set to 'true' if the 757 * @param[out] is_null location set to 'true' if the
@@ -414,6 +816,18 @@ GNUNET_PQ_result_spec_string (const char *name,
414 816
415 817
416/** 818/**
819 * boolean expected.
820 *
821 * @param name name of the field in the table
822 * @param[out] dst where to store the result
823 * @return array entry for the result specification to use
824 */
825struct GNUNET_PQ_ResultSpec
826GNUNET_PQ_result_spec_bool (const char *name,
827 bool *dst);
828
829
830/**
417 * RSA public key expected. 831 * RSA public key expected.
418 * 832 *
419 * @param name name of the field in the table 833 * @param name name of the field in the table
@@ -450,6 +864,18 @@ GNUNET_PQ_result_spec_absolute_time (const char *name,
450 864
451 865
452/** 866/**
867 * Timestamp expected.
868 *
869 * @param name name of the field in the table
870 * @param[out] t where to store the result
871 * @return array entry for the result specification to use
872 */
873struct GNUNET_PQ_ResultSpec
874GNUNET_PQ_result_spec_timestamp (const char *name,
875 struct GNUNET_TIME_Timestamp *t);
876
877
878/**
453 * Relative time expected. 879 * Relative time expected.
454 * 880 *
455 * @param name name of the field in the table 881 * @param name name of the field in the table
@@ -474,6 +900,18 @@ GNUNET_PQ_result_spec_absolute_time_nbo (const char *name,
474 900
475 901
476/** 902/**
903 * Timestamp expected.
904 *
905 * @param name name of the field in the table
906 * @param[out] tn where to store the result
907 * @return array entry for the result specification to use
908 */
909struct GNUNET_PQ_ResultSpec
910GNUNET_PQ_result_spec_timestamp_nbo (const char *name,
911 struct GNUNET_TIME_TimestampNBO *tn);
912
913
914/**
477 * uint16_t expected. 915 * uint16_t expected.
478 * 916 *
479 * @param name name of the field in the table 917 * @param name name of the field in the table
@@ -509,15 +947,233 @@ GNUNET_PQ_result_spec_uint64 (const char *name,
509 uint64_t *u64); 947 uint64_t *u64);
510 948
511 949
512/* ************************* pq.c functions ************************ */ 950/**
951 * int64_t expected.
952 *
953 * @param name name of the field in the table
954 * @param[out] i64 where to store the result
955 * @return array entry for the result specification to use
956 */
957struct GNUNET_PQ_ResultSpec
958GNUNET_PQ_result_spec_int64 (const char *name,
959 int64_t *i64);
960
513 961
514/** 962/**
515 * Postgres context. 963 * array of bool expected.
964 *
965 * @param db Database context, needed for OID lookup for the correct type
966 * @param name name of the field in the table
967 * @param[out] num where to store the number of elements in the array @a bools.
968 * @param[out] bools pointer to where to store the result, an array of @a num bool's. Allocated by the function, MUST be freed with GNUNET_free.
969 * @return array entry for the result specification to use
516 */ 970 */
517struct GNUNET_PQ_Context; 971struct GNUNET_PQ_ResultSpec
972GNUNET_PQ_result_spec_array_bool (
973 struct GNUNET_PQ_Context *db,
974 const char *name,
975 size_t *num,
976 bool **bools);
977
978/**
979 * array of uint16_t expected.
980 *
981 * @param db Database context, needed for OID lookup for the correct type
982 * @param name name of the field in the table
983 * @param[out] num where to store the number of elements in the array @a u16s.
984 * @param[out] dst pointer to where to store the an array of @a num uint16_t's. Allocated by the function, MUST be freed with GNUNET_free.
985 * @return array entry for the result specification to use
986 */
987struct GNUNET_PQ_ResultSpec
988GNUNET_PQ_result_spec_array_uint16 (
989 struct GNUNET_PQ_Context *db,
990 const char *name,
991 size_t *num,
992 uint16_t **dst);
993
994/**
995 * array of uint32_t expected.
996 *
997 * @param db Database context, needed for OID lookup for the correct type
998 * @param name name of the field in the table
999 * @param[out] num where to store the number of elements in the array @a u32s.
1000 * @param[out] dst pointer to where to store the array of @a num uint32_t's. Allocated by the function, MUST be freed with GNUNET_free.
1001 * @return array entry for the result specification to use
1002 */
1003struct GNUNET_PQ_ResultSpec
1004GNUNET_PQ_result_spec_array_uint32 (
1005 struct GNUNET_PQ_Context *db,
1006 const char *name,
1007 size_t *num,
1008 uint32_t **dst);
1009
1010/**
1011 * array of uint64_t expected.
1012 *
1013 * @param db Database context, needed for OID lookup for the correct type
1014 * @param name name of the field in the table
1015 * @param[out] num where to store the number of elements in the array @a u64s.
1016 * @param[out] dst pointer to where to store the array of @a num uint64_t's. Allocated by the function, MUST be freed with GNUNET_free.
1017 * @return array entry for the result specification to use
1018 */
1019struct GNUNET_PQ_ResultSpec
1020GNUNET_PQ_result_spec_array_uint64 (
1021 struct GNUNET_PQ_Context *db,
1022 const char *name,
1023 size_t *num,
1024 uint64_t **dst);
1025
1026
1027/**
1028 * array of absolute time expected.
1029 *
1030 * @param db Database context, needed for OID lookup for the correct type
1031 * @param name name of the field in the table
1032 * @param[out] num where to store the number of elements in the array @a u64s.
1033 * @param[out] dst pointer to where to store the array of @a num absolute time. Allocated by the function, MUST be freed with GNUNET_free.
1034 * @return array entry for the result specification to use
1035 */
1036struct GNUNET_PQ_ResultSpec
1037GNUNET_PQ_result_spec_array_abs_time (
1038 struct GNUNET_PQ_Context *db,
1039 const char *name,
1040 size_t *num,
1041 struct GNUNET_TIME_Absolute **dst);
1042
1043/**
1044 * array of relative time expected.
1045 *
1046 * @param db Database context, needed for OID lookup for the correct type
1047 * @param name name of the field in the table
1048 * @param[out] num where to store the number of elements in the array @a u64s.
1049 * @param[out] dst pointer to where to store the array of @a num relate time. Allocated by the function, MUST be freed with GNUNET_free.
1050 * @return array entry for the result specification to use
1051 */
1052struct GNUNET_PQ_ResultSpec
1053GNUNET_PQ_result_spec_array_rel_time (
1054 struct GNUNET_PQ_Context *db,
1055 const char *name,
1056 size_t *num,
1057 struct GNUNET_TIME_Relative **dst);
1058
1059/**
1060 * array of relative time expected.
1061 *
1062 * @param db Database context, needed for OID lookup for the correct type
1063 * @param name name of the field in the table
1064 * @param[out] num where to store the number of elements in the array @a u64s.
1065 * @param[out] dst pointer to where to store the array of @a num timestamps. Allocated by the function, MUST be freed with GNUNET_free.
1066 * @return array entry for the result specification to use
1067 */
1068
1069struct GNUNET_PQ_ResultSpec
1070GNUNET_PQ_result_spec_array_timestamp (
1071 struct GNUNET_PQ_Context *db,
1072 const char *name,
1073 size_t *num,
1074 struct GNUNET_TIME_Timestamp **dst);
1075
1076/**
1077 * Array of variable-size result expected.
1078 *
1079 * @param db Database context, needed for OID lookup for the correct type
1080 * @param name name of the field in the table
1081 * @param[out] num where to store the number of elements
1082 * @param[out] sizes where to store the @a num size's of byte-buffers in @a dst
1083 * @param[out] dst where to store the continuous array of @a num byte-buffers , allocated
1084 * @return array entry for the result specification to use
1085 */
1086struct GNUNET_PQ_ResultSpec
1087GNUNET_PQ_result_spec_array_variable_size (
1088 struct GNUNET_PQ_Context *db,
1089 const char *name,
1090 size_t *num,
1091 size_t **sizes,
1092 void **dst);
1093
1094
1095/**
1096 * Array of fixed-size result expected.
1097 *
1098 * @param db Database context, needed for OID lookup for the correct type
1099 * @param name name of the field in the table
1100 * @param size number of bytes expected in each element of @a dst
1101 * @param[out] num where to store the number of elements
1102 * @param[out] dst where to store the results, an continuous array of fixed-size elements
1103 * @return array entry for the result specification to use
1104 */
1105struct GNUNET_PQ_ResultSpec
1106GNUNET_PQ_result_spec_array_fixed_size (
1107 struct GNUNET_PQ_Context *db,
1108 const char *name,
1109 size_t size,
1110 size_t *num,
1111 void **dst);
518 1112
519 1113
520/** 1114/**
1115 * We expect a fixed-size result, with size determined by the type of `* dst`
1116 *
1117 * @param db Database context, needed for OID lookup for the correct type
1118 * @param name name of the field in the table
1119 * @param num pointer to where to store the number of elements
1120 * @param dst pointer to where to store the results, type fits expected result size
1121 * @return array entry for the result specification to use
1122 */
1123#define GNUNET_PQ_result_spec_auto_array_from_type(db, name, num, dst) \
1124 GNUNET_PQ_result_spec_array_fixed_size ( \
1125 (db), \
1126 (name), \
1127 sizeof(*(dst)), \
1128 (num), \
1129 (void *) &(dst))
1130
1131
1132/**
1133 * Array of 0-terminated strings expected.
1134 *
1135 * @param db Database context, needed for OID lookup for the correct type
1136 * @param name name of the field in the table
1137 * @param[out] num where to store the number of elements
1138 * @param[out] dst where to store the allocated continous array of @a num 0-terminated strings
1139 * @return array entry for the result specification to use
1140 */
1141struct GNUNET_PQ_ResultSpec
1142GNUNET_PQ_result_spec_array_string (
1143 struct GNUNET_PQ_Context *db,
1144 const char *name,
1145 size_t *num,
1146 char **dst);
1147
1148
1149/**
1150 * Blind sign public key expected.
1151 *
1152 * @param name name of the field in the table
1153 * @param[out] public_key where to store the denomination signature
1154 * @return array entry for the result specification to use
1155 */
1156struct GNUNET_PQ_ResultSpec
1157GNUNET_PQ_result_spec_blind_sign_pub (
1158 const char *name,
1159 struct GNUNET_CRYPTO_BlindSignPublicKey **public_key);
1160
1161
1162/**
1163 * Blind sign private key expected.
1164 *
1165 * @param name name of the field in the table
1166 * @param[out] private_key where to store the denomination signature
1167 * @return array entry for the result specification to use
1168 */
1169struct GNUNET_PQ_ResultSpec
1170GNUNET_PQ_result_spec_blind_sign_priv (
1171 const char *name,
1172 struct GNUNET_CRYPTO_BlindSignPrivateKey **private_key);
1173
1174/* ************************* pq.c functions ************************ */
1175
1176/**
521 * Execute a prepared statement. 1177 * Execute a prepared statement.
522 * 1178 *
523 * @param db database context 1179 * @param db database context
@@ -681,11 +1337,6 @@ struct GNUNET_PQ_PreparedStatement
681 */ 1337 */
682 const char *sql; 1338 const char *sql;
683 1339
684 /**
685 * Number of arguments included in @e sql.
686 */
687 unsigned int num_arguments;
688
689}; 1340};
690 1341
691 1342
@@ -694,7 +1345,7 @@ struct GNUNET_PQ_PreparedStatement
694 */ 1345 */
695#define GNUNET_PQ_PREPARED_STATEMENT_END \ 1346#define GNUNET_PQ_PREPARED_STATEMENT_END \
696 { \ 1347 { \
697 NULL, NULL, 0 \ 1348 NULL, NULL \
698 } 1349 }
699 1350
700 1351
@@ -703,13 +1354,11 @@ struct GNUNET_PQ_PreparedStatement
703 * 1354 *
704 * @param name name of the statement 1355 * @param name name of the statement
705 * @param sql actual SQL statement 1356 * @param sql actual SQL statement
706 * @param num_args number of arguments in the statement
707 * @return initialized struct 1357 * @return initialized struct
708 */ 1358 */
709struct GNUNET_PQ_PreparedStatement 1359struct GNUNET_PQ_PreparedStatement
710GNUNET_PQ_make_prepare (const char *name, 1360GNUNET_PQ_make_prepare (const char *name,
711 const char *sql, 1361 const char *sql);
712 unsigned int num_args);
713 1362
714 1363
715/** 1364/**
@@ -726,6 +1375,22 @@ GNUNET_PQ_prepare_statements (struct GNUNET_PQ_Context *db,
726 const struct GNUNET_PQ_PreparedStatement *ps); 1375 const struct GNUNET_PQ_PreparedStatement *ps);
727 1376
728 1377
1378/**
1379 * Request creation of prepared statements @a ps from Postgres, but do not
1380 * automatically re-prepare the statement if we are disconnected from the
1381 * database.
1382 *
1383 * @param db database to prepare the statements for
1384 * @param ps #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
1385 * statements.
1386 * @return #GNUNET_OK on success,
1387 * #GNUNET_SYSERR on error
1388 */
1389enum GNUNET_GenericReturnValue
1390GNUNET_PQ_prepare_once (struct GNUNET_PQ_Context *db,
1391 const struct GNUNET_PQ_PreparedStatement *ps);
1392
1393
729/* ******************** pq_exec.c functions ************** */ 1394/* ******************** pq_exec.c functions ************** */
730 1395
731 1396
@@ -780,7 +1445,7 @@ GNUNET_PQ_make_try_execute (const char *sql);
780/** 1445/**
781 * Request execution of an array of statements @a es from Postgres. 1446 * Request execution of an array of statements @a es from Postgres.
782 * 1447 *
783 * @param pq database to execute the statements in 1448 * @param db database to execute the statements in
784 * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared 1449 * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
785 * statements. 1450 * statements.
786 * @return #GNUNET_OK on success (modulo statements where errors can be ignored) 1451 * @return #GNUNET_OK on success (modulo statements where errors can be ignored)
@@ -822,14 +1487,14 @@ enum GNUNET_PQ_Options
822 * configuration. Initialize logging via GNUnet's log routines and disable 1487 * configuration. Initialize logging via GNUnet's log routines and disable
823 * Postgres's logger. Also ensures that the statements in @a load_path and @a 1488 * Postgres's logger. Also ensures that the statements in @a load_path and @a
824 * es are executed whenever we (re)connect to the database, and that the 1489 * es are executed whenever we (re)connect to the database, and that the
825 * prepared statements in @a ps are "ready". If statements in @es fail that 1490 * prepared statements in @a ps are "ready". If statements in @a es fail that
826 * were created with #GNUNET_PQ_make_execute(), then the entire operation 1491 * were created with #GNUNET_PQ_make_execute(), then the entire operation
827 * fails. 1492 * fails.
828 * 1493 *
829 * In @a load_path, a list of "$XXXX.sql" files is expected where $XXXX 1494 * In @a load_path, a list of "$XXXX.sql" files is expected where $XXXX
830 * must be a sequence of contiguous integer values starting at 0000. 1495 * must be a sequence of contiguous integer values starting at 0000.
831 * These files are then loaded in sequence using "psql $config_str" before 1496 * These files are then loaded in sequence using "psql $config_str" before
832 * running statements from @e es. The directory is inspected again on 1497 * running statements from @a es. The directory is inspected again on
833 * reconnect. 1498 * reconnect.
834 * 1499 *
835 * @param config_str configuration to use 1500 * @param config_str configuration to use
@@ -847,11 +1512,26 @@ GNUNET_PQ_connect (const char *config_str,
847 1512
848 1513
849/** 1514/**
1515 * Execute SQL statements from @a buf against @a db.
1516 * The given filename infix in @a buf is prefixed with
1517 * the "load_path" and ".sql" is appended to construct
1518 * the full filename.
1519 *
1520 * @param db database context to use
1521 * @param buf filename infix (!) with the SQL code to run
1522 * @return #GNUNET_OK on success, #GNUNET_NO if patch @a buf does not exist, #GNUNET_SYSERR on error
1523 */
1524enum GNUNET_GenericReturnValue
1525GNUNET_PQ_exec_sql (struct GNUNET_PQ_Context *db,
1526 const char *buf);
1527
1528
1529/**
850 * Create a connection to the Postgres database using @a config_str for the 1530 * Create a connection to the Postgres database using @a config_str for the
851 * configuration. Initialize logging via GNUnet's log routines and disable 1531 * configuration. Initialize logging via GNUnet's log routines and disable
852 * Postgres's logger. Also ensures that the statements in @a load_path and @a 1532 * Postgres's logger. Also ensures that the statements in @a load_path and @a
853 * es are executed whenever we (re)connect to the database, and that the 1533 * es are executed whenever we (re)connect to the database, and that the
854 * prepared statements in @a ps are "ready". If statements in @es fail that 1534 * prepared statements in @a ps are "ready". If statements in @a es fail that
855 * were created with #GNUNET_PQ_make_execute(), then the entire operation 1535 * were created with #GNUNET_PQ_make_execute(), then the entire operation
856 * fails. 1536 * fails.
857 * 1537 *
@@ -863,6 +1543,7 @@ GNUNET_PQ_connect (const char *config_str,
863 * 1543 *
864 * @param config_str configuration to use 1544 * @param config_str configuration to use
865 * @param load_path path to directory with SQL transactions to run, can be NULL 1545 * @param load_path path to directory with SQL transactions to run, can be NULL
1546 * @param auto_suffix infix of SQL series to run on every reconnect; runs multiple (!) files, of the form auto_suffix-XXXX where XXXX is from 0 to 9999 (consequtive).
866 * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated 1547 * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated
867 * array of statements to execute upon EACH connection, can be NULL 1548 * array of statements to execute upon EACH connection, can be NULL
868 * @param ps array of prepared statements to prepare, can be NULL 1549 * @param ps array of prepared statements to prepare, can be NULL
@@ -872,16 +1553,17 @@ GNUNET_PQ_connect (const char *config_str,
872struct GNUNET_PQ_Context * 1553struct GNUNET_PQ_Context *
873GNUNET_PQ_connect2 (const char *config_str, 1554GNUNET_PQ_connect2 (const char *config_str,
874 const char *load_path, 1555 const char *load_path,
1556 const char *auto_suffix,
875 const struct GNUNET_PQ_ExecuteStatement *es, 1557 const struct GNUNET_PQ_ExecuteStatement *es,
876 const struct GNUNET_PQ_PreparedStatement *ps, 1558 const struct GNUNET_PQ_PreparedStatement *ps,
877 enum GNUNET_PQ_Options flags); 1559 enum GNUNET_PQ_Options flags);
878 1560
879 1561
880/** 1562/**
881 * Connect to a postgres database using the configuration 1563 * Connect to a postgres database using the configuration option "CONFIG" in
882 * option "CONFIG" in @a section. Also ensures that the 1564 * @a section. Also ensures that the statements in @a es are executed
883 * statements in @a es are executed whenever we (re)connect to the 1565 * whenever we (re)connect to the database, and that the prepared statements
884 * database, and that the prepared statements in @a ps are "ready". 1566 * in @a ps are "ready".
885 * 1567 *
886 * The caller does not have to ensure that @a es and @a ps remain allocated 1568 * The caller does not have to ensure that @a es and @a ps remain allocated
887 * and initialized in memory until #GNUNET_PQ_disconnect() is called, as a copy will be made. 1569 * and initialized in memory until #GNUNET_PQ_disconnect() is called, as a copy will be made.
@@ -909,7 +1591,8 @@ GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
909 * database, and that the prepared statements in @a ps are "ready". 1591 * database, and that the prepared statements in @a ps are "ready".
910 * 1592 *
911 * The caller does not have to ensure that @a es and @a ps remain allocated 1593 * The caller does not have to ensure that @a es and @a ps remain allocated
912 * and initialized in memory until #GNUNET_PQ_disconnect() is called, as a copy will be made. 1594 * and initialized in memory until #GNUNET_PQ_disconnect() is called, as a
1595 * copy will be made.
913 * 1596 *
914 * @param cfg configuration 1597 * @param cfg configuration
915 * @param section configuration section to use to get Postgres configuration options 1598 * @param section configuration section to use to get Postgres configuration options
@@ -988,12 +1671,24 @@ GNUNET_PQ_event_listen_cancel (struct GNUNET_DB_EventHandler *eh);
988 1671
989 1672
990/** 1673/**
1674 * Poll for events right now. Useful if we may have
1675 * triggered an event for ourselves. Not needed when
1676 * using GNUNET_PQ_event_notify(), but useful when
1677 * stored procedures may have triggered events.
1678 * Does nothing if there are no events.
1679 *
1680 * @param[in,out] db database to check for events
1681 */
1682void
1683GNUNET_PQ_event_do_poll (struct GNUNET_PQ_Context *db);
1684
1685
1686/**
991 * Notify all that listen on @a es of an event. 1687 * Notify all that listen on @a es of an event.
992 * 1688 *
993 * Unlike many other calls, this function is thread-safe 1689 * Unlike many other calls, this function is thread-safe and may be called
994 * and may be called from threads that are different 1690 * from threads that are different from the one that setup @a db. However, the
995 * from the one that setup @a db. However, the @a cb 1691 * @a cb will always be called from the thread that runs
996 * will always be called from the thread that runs
997 * #GNUNET_PQ_event_do_poll() or the GNUnet scheduler. 1692 * #GNUNET_PQ_event_do_poll() or the GNUnet scheduler.
998 * 1693 *
999 * @param db database context to use 1694 * @param db database context to use
@@ -1009,6 +1704,17 @@ GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db,
1009 1704
1010 1705
1011/** 1706/**
1707 * Compute the channel that one should notify upon for the given event
1708 * specification.
1709 *
1710 * @param es event specification
1711 * @return channel to notify upon
1712 */
1713char *
1714GNUNET_PQ_get_event_notify_channel (const struct GNUNET_DB_EventHeaderP *es);
1715
1716
1717/**
1012 * Within the @a db context, run all the SQL files 1718 * Within the @a db context, run all the SQL files
1013 * from the @a load_path from 0000-9999.sql (as long 1719 * from the @a load_path from 0000-9999.sql (as long
1014 * as the files exist contiguously). 1720 * as the files exist contiguously).
diff --git a/src/include/gnunet_program_lib.h b/src/include/gnunet_program_lib.h
index 4167060c0..f06d95422 100644
--- a/src/include/gnunet_program_lib.h
+++ b/src/include/gnunet_program_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs
28 * @{
29 *
22 * @author Christian Grothoff 30 * @author Christian Grothoff
23 * 31 *
24 * @file 32 * @file
@@ -40,6 +48,7 @@ extern "C"
40#endif 48#endif
41#endif 49#endif
42 50
51
43#include "gnunet_configuration_lib.h" 52#include "gnunet_configuration_lib.h"
44#include "gnunet_getopt_lib.h" 53#include "gnunet_getopt_lib.h"
45#include "gnunet_scheduler_lib.h" 54#include "gnunet_scheduler_lib.h"
@@ -113,6 +122,45 @@ GNUNET_PROGRAM_run (int argc,
113 GNUNET_PROGRAM_Main task, 122 GNUNET_PROGRAM_Main task,
114 void *task_cls); 123 void *task_cls);
115 124
125enum GNUNET_GenericReturnValue
126GNUNET_DAEMON_register (const char *daemon_name,
127 const char *daemon_desc,
128 GNUNET_PROGRAM_Main task);
129
130#ifndef HAVE_GNUNET_MONOLITH
131#define GNUNET_DAEMON_MAIN(daemon_name, daemon_help, init_cb) \
132 int \
133 main (int argc, \
134 char *const *argv) \
135 { \
136 int ret; \
137 struct GNUNET_GETOPT_CommandLineOption options[] = { \
138 GNUNET_GETOPT_OPTION_END \
139 }; \
140 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, \
141 &argv)) \
142 return 2; \
143 ret = GNUNET_PROGRAM_run (argc, \
144 argv, \
145 daemon_name, \
146 daemon_help, \
147 options, \
148 init_cb, \
149 NULL); \
150 GNUNET_free_nz ((void*) argv); \
151 return ret; \
152 }
153#else
154#define GNUNET_DAEMON_MAIN(daemon_name, daemon_help, init_cb) \
155 static int __attribute__ ((constructor)) \
156 init (void) \
157 { \
158 return GNUNET_DAEMON_register (daemon_name, \
159 daemon_help, \
160 init_cb); \
161 }
162#endif
163
116 164
117#if 0 /* keep Emacsens' auto-indent happy */ 165#if 0 /* keep Emacsens' auto-indent happy */
118{ 166{
@@ -126,4 +174,6 @@ GNUNET_PROGRAM_run (int argc,
126 174
127/** @} */ /* end of group program */ 175/** @} */ /* end of group program */
128 176
177/** @} */ /* end of group addition */
178
129/* end of gnunet_program_lib.h */ 179/* end of gnunet_program_lib.h */
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 9e278eb92..9fce48386 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001--2020 GNUnet e.V. 3 Copyright (C) 2001--2024 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * @author Tobias Frisch 27 * @author Tobias Frisch
24 * 28 *
@@ -153,10 +157,10 @@ extern "C" {
153 ******************************************************************************/ 157 ******************************************************************************/
154 158
155/** 159/**
156 * Previously used for HELLO messages used for communicating peer addresses. 160 * Latest HELLO messages used for communicating peer addresses.
157 * Managed by libgnunethello. 161 * Managed by libgnunethello.
158 */ 162 */
159#define GNUNET_MESSAGE_TYPE_HELLO_LEGACY 16 163#define GNUNET_MESSAGE_TYPE_HELLO_URI 16
160 164
161/** 165/**
162 * HELLO message with friend only flag used for communicating peer addresses. 166 * HELLO message with friend only flag used for communicating peer addresses.
@@ -660,13 +664,26 @@ extern "C" {
660#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN 156 664#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN 156
661 665
662/** 666/**
663 * DHT wants to use CORE to transmit data. 667 * HELLO advertising a neighbours addresses.
668 */
669#define GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO 157
670
671/**
672 * Encapsulation of DHT messages in CORE service.
673 */
674#define GNUNET_MESSAGE_TYPE_DHT_CORE 158
675
676/**
677 * HELLO URL send between client and service (in
678 * either direction).
664 */ 679 */
665#define GNUNET_MESSAGE_TYPE_DHT_CORE 143 680#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_HELLO_URL 159
666 681
667/** 682/**
668 * Further X-VINE DHT messages continued from 880 683 * Client requests DHT service's HELLO URL.
669 */ 684 */
685#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_HELLO_GET 161
686
670 687
671/******************************************************************************* 688/*******************************************************************************
672 * HOSTLIST message types 689 * HOSTLIST message types
@@ -1310,7 +1327,7 @@ extern "C" {
1310/** 1327/**
1311 * Service to client: result of store operation. 1328 * Service to client: result of store operation.
1312 */ 1329 */
1313#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE 436 1330#define GNUNET_MESSAGE_TYPE_NAMESTORE_GENERIC_RESPONSE 436
1314 1331
1315/** 1332/**
1316 * Client to service: lookup label 1333 * Client to service: lookup label
@@ -1796,7 +1813,6 @@ extern "C" {
1796#define GNUNET_MESSAGE_TYPE_SETU_P2P_SEND_FULL 710 1813#define GNUNET_MESSAGE_TYPE_SETU_P2P_SEND_FULL 710
1797 1814
1798 1815
1799
1800/******************************************************************************* 1816/*******************************************************************************
1801 * SETI message types 1817 * SETI message types
1802 ******************************************************************************/ 1818 ******************************************************************************/
@@ -2336,7 +2352,7 @@ extern "C" {
2336/** M<->S<->C: PSYC message which contains a header and one or more message 2352/** M<->S<->C: PSYC message which contains a header and one or more message
2337 * parts. */ 2353 * parts. */
2338#define GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_HEADER \ 2354#define GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_HEADER \
2339 692 // FIXME: start using this where appropriate 2355 692 // FIXME: start using this where appropriate
2340 2356
2341/** Message part: method */ 2357/** Message part: method */
2342#define GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD 693 2358#define GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD 693
@@ -2583,14 +2599,14 @@ extern "C" {
2583#define GNUNET_MESSAGE_TYPE_PEERSTORE_STORE 820 2599#define GNUNET_MESSAGE_TYPE_PEERSTORE_STORE 820
2584 2600
2585/** 2601/**
2586 * Iteration request 2602 * Iteration request (see also 828, 829)
2587 */ 2603 */
2588#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE 821 2604#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_START 821
2589 2605
2590/** 2606/**
2591 * Iteration record message 2607 * Record result message
2592 */ 2608 */
2593#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD 822 2609#define GNUNET_MESSAGE_TYPE_PEERSTORE_RECORD 822
2594 2610
2595/** 2611/**
2596 * Iteration end message 2612 * Iteration end message
@@ -2598,19 +2614,34 @@ extern "C" {
2598#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END 823 2614#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END 823
2599 2615
2600/** 2616/**
2601 * Watch request 2617 * Monitor request
2618 */
2619#define GNUNET_MESSAGE_TYPE_PEERSTORE_MONITOR_START 824
2620
2621/**
2622 * Monitor sync
2623 */
2624#define GNUNET_MESSAGE_TYPE_PEERSTORE_MONITOR_SYNC 825
2625
2626/**
2627 * Monitor next request
2628 */
2629#define GNUNET_MESSAGE_TYPE_PEERSTORE_MONITOR_NEXT 826
2630
2631/**
2632 * Store result message
2602 */ 2633 */
2603#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH 824 2634#define GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT 827
2604 2635
2605/** 2636/**
2606 * Watch response 2637 * Iteration request (see also 821, 829)
2607 */ 2638 */
2608#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD 825 2639#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_NEXT 828
2609 2640
2610/** 2641/**
2611 * Watch cancel request 2642 * Iteration request (see also 821, 828)
2612 */ 2643 */
2613#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL 826 2644#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_STOP 829
2614 2645
2615/******************************************************************************* 2646/*******************************************************************************
2616 * SOCIAL message types 2647 * SOCIAL message types
@@ -2747,19 +2778,6 @@ extern "C" {
2747 */ 2778 */
2748#define GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_SUCCESSOR_CONFIRMATION 892 2779#define GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_SUCCESSOR_CONFIRMATION 892
2749 2780
2750#if ENABLE_MALICIOUS
2751/**
2752 * Turn X-VINE DHT service malicious
2753 */
2754#define GNUNET_MESSAGE_TYPE_DHT_ACT_MALICIOUS 893
2755
2756/**
2757 * Acknowledge receiving ACT MALICIOUS request
2758 */
2759#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_ACT_MALICIOUS_OK 894
2760
2761#endif
2762
2763 2781
2764/******************************************************************************* 2782/*******************************************************************************
2765 * Whanau DHT messages 2783 * Whanau DHT messages
@@ -2844,6 +2862,10 @@ extern "C" {
2844 */ 2862 */
2845#define GNUNET_MESSAGE_TYPE_RPS_CS_SEED 954 2863#define GNUNET_MESSAGE_TYPE_RPS_CS_SEED 954
2846 2864
2865#ifndef ENABLE_MALICIOUS
2866#define ENABLE_MALICIOUS 0
2867#endif
2868
2847#if ENABLE_MALICIOUS 2869#if ENABLE_MALICIOUS
2848/** 2870/**
2849 * Turn RPS service malicious 2871 * Turn RPS service malicious
@@ -3185,6 +3207,11 @@ extern "C" {
3185#define GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE 1064 3207#define GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE 1064
3186 3208
3187/** 3209/**
3210 * Message to ask NAT service to notify all clients about a new global address.
3211 */
3212#define GNUNET_MESSAGE_TYPE_NAT_ADD_GLOBAL_ADDRESS 1065
3213
3214/**
3188 * Message to ask NAT service to request autoconfiguration. 3215 * Message to ask NAT service to request autoconfiguration.
3189 */ 3216 */
3190#define GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG 1067 3217#define GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG 1067
@@ -3514,6 +3541,11 @@ extern "C" {
3514#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD 1461 3541#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD 1461
3515 3542
3516/** 3543/**
3544 * UDP Rekey.
3545 */
3546#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_REKEY 1462
3547
3548/**
3517 * Next available: 1500 3549 * Next available: 1500
3518 */ 3550 */
3519#define GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_DELETE 1500 3551#define GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_DELETE 1500
@@ -3533,17 +3565,9 @@ extern "C" {
3533 3565
3534#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE 1600 3566#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE 1600
3535 3567
3536#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_UPDATE 1601 3568#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY 1601
3537
3538#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY 1602
3539
3540#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_NAME 1603
3541 3569
3542#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME 1604 3570#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID 1602
3543
3544#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_KEY 1605
3545
3546#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID 1606
3547 3571
3548/************************************ Room *************************************/ 3572/************************************ Room *************************************/
3549 3573
@@ -3559,6 +3583,10 @@ extern "C" {
3559 3583
3560#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE 1616 3584#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE 1616
3561 3585
3586#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SYNC 1617
3587
3588#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_LINK 1618
3589
3562/*********************************************************************************/ 3590/*********************************************************************************/
3563 3591
3564/*********************************************************************************/ 3592/*********************************************************************************/
@@ -3585,7 +3613,36 @@ extern "C" {
3585 3613
3586#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED 1706 3614#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED 1706
3587 3615
3616#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED 1707
3617
3618#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACH 1708
3619
3620#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE 1709
3621
3622#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACHED 1710
3623
3624/*********************************************************************************/
3625
3626/*********************************************************************************/
3627/********************************** NAMESTORE (cont.) **************************/
3588/*********************************************************************************/ 3628/*********************************************************************************/
3629/* NAMESTORE: message types 1750-1800
3630 */
3631
3632/**
3633 * Message type for start of record edit with advisory lock
3634 */
3635#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT 1750
3636
3637/**
3638 * Return record set to edit with previous editor hint/advisory lock
3639 */
3640#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT_RESPONSE 1751
3641
3642/**
3643 * Message type for cancellation/reset of editor hint/advisory lock
3644 */
3645#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT_CANCEL 1752
3589 3646
3590/** 3647/**
3591 * Type used to match 'all' message types. 3648 * Type used to match 'all' message types.
@@ -3605,4 +3662,6 @@ extern "C" {
3605 3662
3606/** @} */ /* end of group protocols */ 3663/** @} */ /* end of group protocols */
3607 3664
3665/** @} */ /* end of group addition */
3666
3608/* end of gnunet_protocols.h */ 3667/* end of gnunet_protocols.h */
diff --git a/src/include/gnunet_reclaim_lib.h b/src/include/gnunet_reclaim_lib.h
index bbf1c3ad3..e4dec14fa 100644
--- a/src/include/gnunet_reclaim_lib.h
+++ b/src/include/gnunet_reclaim_lib.h
@@ -19,12 +19,15 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup reclaim_suite RECLAIM services and libraries
23 * @{
24 *
22 * @author Martin Schanzenbach 25 * @author Martin Schanzenbach
23 * 26 *
24 * @file 27 * @file
25 * Identity attribute definitions 28 * Identity attribute definitions
26 * 29 *
27 * @defgroup reclaim-attribute reclaim attributes 30 * @defgroup reclaim-attribute Reclaim attributes
28 * @{ 31 * @{
29 */ 32 */
30#ifndef GNUNET_RECLAIM_ATTRIBUTE_LIB_H 33#ifndef GNUNET_RECLAIM_ATTRIBUTE_LIB_H
@@ -37,6 +40,7 @@ extern "C" {
37#endif 40#endif
38#endif 41#endif
39 42
43
40#include "gnunet_util_lib.h" 44#include "gnunet_util_lib.h"
41 45
42enum GNUNET_RECLAIM_AttributeType { 46enum GNUNET_RECLAIM_AttributeType {
@@ -512,7 +516,7 @@ GNUNET_RECLAIM_attribute_number_to_typename (uint32_t type);
512/** 516/**
513 * Get required size for serialization buffer 517 * Get required size for serialization buffer
514 * 518 *
515 * @param attrs the attribute list to serialize 519 * @param credentials the attribute list to serialize
516 * @return the required buffer size 520 * @return the required buffer size
517 */ 521 */
518size_t 522size_t
@@ -521,9 +525,9 @@ GNUNET_RECLAIM_credential_list_serialize_get_size (
521 525
522 526
523/** 527/**
524 * Destroy claim list 528 * Destroy credential list
525 * 529 *
526 * @param attrs list to destroy 530 * @param credentials list to destroy
527 */ 531 */
528void 532void
529GNUNET_RECLAIM_credential_list_destroy ( 533GNUNET_RECLAIM_credential_list_destroy (
@@ -548,15 +552,15 @@ GNUNET_RECLAIM_credential_list_add (
548 552
549 553
550/** 554/**
551 * Serialize an attribute list 555 * Serialize a credential list
552 * 556 *
553 * @param attrs the attribute list to serialize 557 * @param credentials the credential list to serialize
554 * @param result the serialized attribute 558 * @param result the serialized credential
555 * @return length of serialized data 559 * @return length of serialized data
556 */ 560 */
557size_t 561size_t
558GNUNET_RECLAIM_credential_list_serialize ( 562GNUNET_RECLAIM_credential_list_serialize (
559 const struct GNUNET_RECLAIM_CredentialList *attrs, 563 const struct GNUNET_RECLAIM_CredentialList *credentials,
560 char *result); 564 char *result);
561 565
562 566
@@ -858,4 +862,6 @@ GNUNET_RECLAIM_credential_get_presentation (
858 862
859/** @} */ /* end of group reclaim-attribute */ 863/** @} */ /* end of group reclaim-attribute */
860 864
865/** @} */ /* end of group addition */
866
861/* end of gnunet_reclaim_attribute_lib.h */ 867/* end of gnunet_reclaim_attribute_lib.h */
diff --git a/src/include/gnunet_reclaim_plugin.h b/src/include/gnunet_reclaim_plugin.h
index 11d5d76f7..f8b2084d2 100644
--- a/src/include/gnunet_reclaim_plugin.h
+++ b/src/include/gnunet_reclaim_plugin.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup reclaim_suite RECLAIM services and libraries
23 * @{
24 *
22 * @author Martin Schanzenbach 25 * @author Martin Schanzenbach
23 * 26 *
24 * @file 27 * @file
@@ -30,6 +33,7 @@
30#ifndef GNUNET_RECLAIM_PLUGIN_H 33#ifndef GNUNET_RECLAIM_PLUGIN_H
31#define GNUNET_RECLAIM_PLUGIN_H 34#define GNUNET_RECLAIM_PLUGIN_H
32 35
36
33#include "gnunet_util_lib.h" 37#include "gnunet_util_lib.h"
34#include "gnunet_reclaim_lib.h" 38#include "gnunet_reclaim_lib.h"
35 39
@@ -439,3 +443,5 @@ struct GNUNET_RECLAIM_CredentialPluginFunctions
439#endif 443#endif
440 444
441/** @} */ /* end of group */ 445/** @} */ /* end of group */
446
447/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_reclaim_service.h b/src/include/gnunet_reclaim_service.h
index 38e1c8735..086c3f021 100644
--- a/src/include/gnunet_reclaim_service.h
+++ b/src/include/gnunet_reclaim_service.h
@@ -19,13 +19,16 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup reclaim_suite RECLAIM services and libraries
23 * @{
24 *
22 * @author Martin Schanzenbach 25 * @author Martin Schanzenbach
23 * 26 *
24 * @file 27 * @file
25 * reclaim service; implements identity and personal data sharing 28 * reclaim service; implements identity and personal data sharing
26 * for GNUnet 29 * for GNUnet
27 * 30 *
28 * @defgroup reclaim service 31 * @defgroup reclaim Reclaim service
29 * @{ 32 * @{
30 */ 33 */
31#ifndef GNUNET_RECLAIM_SERVICE_H 34#ifndef GNUNET_RECLAIM_SERVICE_H
@@ -38,6 +41,7 @@ extern "C" {
38#endif 41#endif
39#endif 42#endif
40 43
44
41#include "gnunet_identity_service.h" 45#include "gnunet_identity_service.h"
42#include "gnunet_reclaim_lib.h" 46#include "gnunet_reclaim_lib.h"
43#include "gnunet_util_lib.h" 47#include "gnunet_util_lib.h"
@@ -45,7 +49,7 @@ extern "C" {
45/** 49/**
46 * Version number of the re:claimID API. 50 * Version number of the re:claimID API.
47 */ 51 */
48#define GNUNET_RECLAIM_VERSION 0x00000001 52#define GNUNET_RECLAIM_VERSION 0x00000002
49 53
50/** 54/**
51 * Opaque handle to access the service. 55 * Opaque handle to access the service.
@@ -58,6 +62,9 @@ struct GNUNET_RECLAIM_Handle;
58 */ 62 */
59struct GNUNET_RECLAIM_Operation; 63struct GNUNET_RECLAIM_Operation;
60 64
65#define GNUNET_RECLAIM_TICKET_RP_URI_MAX_LEN 256
66
67#define GNUNET_RECLAIM_TICKET_RP_URI_URN_PREFIX "urn:gns:"
61 68
62/** 69/**
63 * The authorization ticket. This ticket is meant to be transferred 70 * The authorization ticket. This ticket is meant to be transferred
@@ -68,19 +75,30 @@ struct GNUNET_RECLAIM_Operation;
68struct GNUNET_RECLAIM_Ticket 75struct GNUNET_RECLAIM_Ticket
69{ 76{
70 /** 77 /**
71 * The ticket issuer (= the user) 78 * The ticket. A GNS name ending in the
79 * zTLD for identity.
80 * Base32(rnd).zTLD(identity)
81 * 0-terminated string.
72 */ 82 */
73 struct GNUNET_IDENTITY_PublicKey identity; 83 char gns_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH * 2 + 2];
74 84
75 /** 85 /**
76 * The ticket audience (= relying party) 86 * The ticket issuer (= the user)
77 */ 87 */
78 struct GNUNET_IDENTITY_PublicKey audience; 88 //struct GNUNET_CRYPTO_PublicKey identity;
79 89
80 /** 90 /**
81 * The ticket random identifier 91 * The ticket random identifier
82 */ 92 */
83 struct GNUNET_RECLAIM_Identifier rnd; 93 //struct GNUNET_RECLAIM_Identifier rnd;
94
95
96 /**
97 * Followed by the ticket audience (= relying party) URI.
98 * 0-terminated string.
99 * Example: "urn:gns:000G002B4RF1XPBXDPGZA0PT16BHQCS427YQK4NC84KZMK7TK8C2Z5GMK8"
100 */
101 //char rp_uri[GNUNET_RECLAIM_TICKET_RP_URI_MAX_LEN];
84}; 102};
85 103
86 104
@@ -91,10 +109,12 @@ struct GNUNET_RECLAIM_Ticket
91 * 109 *
92 * @param cls closure 110 * @param cls closure
93 * @param ticket the ticket 111 * @param ticket the ticket
112 * @param rp_uri the RP URI of the ticket
94 */ 113 */
95typedef void (*GNUNET_RECLAIM_TicketCallback) ( 114typedef void (*GNUNET_RECLAIM_TicketCallback) (
96 void *cls, 115 void *cls,
97 const struct GNUNET_RECLAIM_Ticket *ticket); 116 const struct GNUNET_RECLAIM_Ticket *ticket,
117 const char* rp_uri);
98 118
99/** 119/**
100 * Method called when a token has been issued. 120 * Method called when a token has been issued.
@@ -130,7 +150,7 @@ typedef void (*GNUNET_RECLAIM_ContinuationWithStatus) (void *cls,
130 * @param attr The attribute 150 * @param attr The attribute
131 */ 151 */
132typedef void (*GNUNET_RECLAIM_AttributeResult) ( 152typedef void (*GNUNET_RECLAIM_AttributeResult) (
133 void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, 153 void *cls, const struct GNUNET_CRYPTO_PublicKey *identity,
134 const struct GNUNET_RECLAIM_Attribute *attr); 154 const struct GNUNET_RECLAIM_Attribute *attr);
135 155
136/** 156/**
@@ -142,7 +162,7 @@ typedef void (*GNUNET_RECLAIM_AttributeResult) (
142 * @param presentation The presentation for the credential (may be NULL) 162 * @param presentation The presentation for the credential (may be NULL)
143 */ 163 */
144typedef void (*GNUNET_RECLAIM_AttributeTicketResult) ( 164typedef void (*GNUNET_RECLAIM_AttributeTicketResult) (
145 void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, 165 void *cls, const struct GNUNET_CRYPTO_PublicKey *identity,
146 const struct GNUNET_RECLAIM_Attribute *attr, 166 const struct GNUNET_RECLAIM_Attribute *attr,
147 const struct GNUNET_RECLAIM_Presentation *presentation); 167 const struct GNUNET_RECLAIM_Presentation *presentation);
148 168
@@ -156,7 +176,7 @@ typedef void (*GNUNET_RECLAIM_AttributeTicketResult) (
156 * @param attributes the parsed attributes 176 * @param attributes the parsed attributes
157 */ 177 */
158typedef void (*GNUNET_RECLAIM_CredentialResult) ( 178typedef void (*GNUNET_RECLAIM_CredentialResult) (
159 void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, 179 void *cls, const struct GNUNET_CRYPTO_PublicKey *identity,
160 const struct GNUNET_RECLAIM_Credential *credential); 180 const struct GNUNET_RECLAIM_Credential *credential);
161 181
162 182
@@ -185,7 +205,7 @@ GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
185struct GNUNET_RECLAIM_Operation * 205struct GNUNET_RECLAIM_Operation *
186GNUNET_RECLAIM_attribute_store ( 206GNUNET_RECLAIM_attribute_store (
187 struct GNUNET_RECLAIM_Handle *h, 207 struct GNUNET_RECLAIM_Handle *h,
188 const struct GNUNET_IDENTITY_PrivateKey *pkey, 208 const struct GNUNET_CRYPTO_PrivateKey *pkey,
189 const struct GNUNET_RECLAIM_Attribute *attr, 209 const struct GNUNET_RECLAIM_Attribute *attr,
190 const struct GNUNET_TIME_Relative *exp_interval, 210 const struct GNUNET_TIME_Relative *exp_interval,
191 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls); 211 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls);
@@ -197,7 +217,7 @@ GNUNET_RECLAIM_attribute_store (
197 * 217 *
198 * @param h handle to the re:claimID service 218 * @param h handle to the re:claimID service
199 * @param pkey private key of the identity 219 * @param pkey private key of the identity
200 * @param attr the credential value 220 * @param credential the credential value
201 * @param exp_interval the relative expiration interval for the credential 221 * @param exp_interval the relative expiration interval for the credential
202 * @param cont continuation to call when done 222 * @param cont continuation to call when done
203 * @param cont_cls closure for @a cont 223 * @param cont_cls closure for @a cont
@@ -206,7 +226,7 @@ GNUNET_RECLAIM_attribute_store (
206struct GNUNET_RECLAIM_Operation * 226struct GNUNET_RECLAIM_Operation *
207GNUNET_RECLAIM_credential_store ( 227GNUNET_RECLAIM_credential_store (
208 struct GNUNET_RECLAIM_Handle *h, 228 struct GNUNET_RECLAIM_Handle *h,
209 const struct GNUNET_IDENTITY_PrivateKey *pkey, 229 const struct GNUNET_CRYPTO_PrivateKey *pkey,
210 const struct GNUNET_RECLAIM_Credential *credential, 230 const struct GNUNET_RECLAIM_Credential *credential,
211 const struct GNUNET_TIME_Relative *exp_interval, 231 const struct GNUNET_TIME_Relative *exp_interval,
212 GNUNET_RECLAIM_ContinuationWithStatus cont, 232 GNUNET_RECLAIM_ContinuationWithStatus cont,
@@ -227,12 +247,12 @@ GNUNET_RECLAIM_credential_store (
227struct GNUNET_RECLAIM_Operation * 247struct GNUNET_RECLAIM_Operation *
228GNUNET_RECLAIM_attribute_delete ( 248GNUNET_RECLAIM_attribute_delete (
229 struct GNUNET_RECLAIM_Handle *h, 249 struct GNUNET_RECLAIM_Handle *h,
230 const struct GNUNET_IDENTITY_PrivateKey *pkey, 250 const struct GNUNET_CRYPTO_PrivateKey *pkey,
231 const struct GNUNET_RECLAIM_Attribute *attr, 251 const struct GNUNET_RECLAIM_Attribute *attr,
232 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls); 252 GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls);
233 253
234/** 254/**
235 * Delete a credential. Tickets used to share use a presentation of this 255 * Delete a credential. Tickets used to share a presentation of this
236 * credential are updated accordingly. 256 * credential are updated accordingly.
237 * 257 *
238 * @param h handle to the re:claimID service 258 * @param h handle to the re:claimID service
@@ -245,7 +265,7 @@ GNUNET_RECLAIM_attribute_delete (
245struct GNUNET_RECLAIM_Operation * 265struct GNUNET_RECLAIM_Operation *
246GNUNET_RECLAIM_credential_delete ( 266GNUNET_RECLAIM_credential_delete (
247 struct GNUNET_RECLAIM_Handle *h, 267 struct GNUNET_RECLAIM_Handle *h,
248 const struct GNUNET_IDENTITY_PrivateKey *pkey, 268 const struct GNUNET_CRYPTO_PrivateKey *pkey,
249 const struct GNUNET_RECLAIM_Credential *cred, 269 const struct GNUNET_RECLAIM_Credential *cred,
250 GNUNET_RECLAIM_ContinuationWithStatus cont, 270 GNUNET_RECLAIM_ContinuationWithStatus cont,
251 void *cont_cls); 271 void *cont_cls);
@@ -277,7 +297,7 @@ GNUNET_RECLAIM_credential_delete (
277struct GNUNET_RECLAIM_AttributeIterator * 297struct GNUNET_RECLAIM_AttributeIterator *
278GNUNET_RECLAIM_get_attributes_start ( 298GNUNET_RECLAIM_get_attributes_start (
279 struct GNUNET_RECLAIM_Handle *h, 299 struct GNUNET_RECLAIM_Handle *h,
280 const struct GNUNET_IDENTITY_PrivateKey *identity, 300 const struct GNUNET_CRYPTO_PrivateKey *identity,
281 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, 301 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
282 GNUNET_RECLAIM_AttributeResult proc, void *proc_cls, 302 GNUNET_RECLAIM_AttributeResult proc, void *proc_cls,
283 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls); 303 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls);
@@ -333,7 +353,7 @@ GNUNET_RECLAIM_get_attributes_stop (
333struct GNUNET_RECLAIM_CredentialIterator * 353struct GNUNET_RECLAIM_CredentialIterator *
334GNUNET_RECLAIM_get_credentials_start ( 354GNUNET_RECLAIM_get_credentials_start (
335 struct GNUNET_RECLAIM_Handle *h, 355 struct GNUNET_RECLAIM_Handle *h,
336 const struct GNUNET_IDENTITY_PrivateKey *identity, 356 const struct GNUNET_CRYPTO_PrivateKey *identity,
337 GNUNET_SCHEDULER_TaskCallback error_cb, 357 GNUNET_SCHEDULER_TaskCallback error_cb,
338 void *error_cb_cls, 358 void *error_cb_cls,
339 GNUNET_RECLAIM_CredentialResult proc, 359 GNUNET_RECLAIM_CredentialResult proc,
@@ -346,7 +366,7 @@ GNUNET_RECLAIM_get_credentials_start (
346 * Calls the record processor specified in #GNUNET_RECLAIM_get_credentials_start 366 * Calls the record processor specified in #GNUNET_RECLAIM_get_credentials_start
347 * for the next record. 367 * for the next record.
348 * 368 *
349 * @param it the iterator 369 * @param ait the iterator
350 */ 370 */
351void 371void
352GNUNET_RECLAIM_get_credentials_next ( 372GNUNET_RECLAIM_get_credentials_next (
@@ -358,7 +378,7 @@ GNUNET_RECLAIM_get_credentials_next (
358 * be called on any iteration that has not yet completed prior to calling 378 * be called on any iteration that has not yet completed prior to calling
359 * #GNUNET_RECLAIM_disconnect. 379 * #GNUNET_RECLAIM_disconnect.
360 * 380 *
361 * @param it the iterator 381 * @param ait the iterator
362 */ 382 */
363void 383void
364GNUNET_RECLAIM_get_credentials_stop ( 384GNUNET_RECLAIM_get_credentials_stop (
@@ -372,7 +392,7 @@ GNUNET_RECLAIM_get_credentials_stop (
372 * 392 *
373 * @param h the identity provider to use 393 * @param h the identity provider to use
374 * @param iss the issuing identity (= the user) 394 * @param iss the issuing identity (= the user)
375 * @param rp the subject of the ticket (= the relying party) 395 * @param rp_uri the subject of the ticket (= the relying party) see #GNUNET_RECLAIM_Ticket
376 * @param attrs the attributes that the relying party is given access to 396 * @param attrs the attributes that the relying party is given access to
377 * @param cb the callback 397 * @param cb the callback
378 * @param cb_cls the callback closure 398 * @param cb_cls the callback closure
@@ -381,8 +401,8 @@ GNUNET_RECLAIM_get_credentials_stop (
381struct GNUNET_RECLAIM_Operation * 401struct GNUNET_RECLAIM_Operation *
382GNUNET_RECLAIM_ticket_issue ( 402GNUNET_RECLAIM_ticket_issue (
383 struct GNUNET_RECLAIM_Handle *h, 403 struct GNUNET_RECLAIM_Handle *h,
384 const struct GNUNET_IDENTITY_PrivateKey *iss, 404 const struct GNUNET_CRYPTO_PrivateKey *iss,
385 const struct GNUNET_IDENTITY_PublicKey *rp, 405 const char *rp_uri,
386 const struct GNUNET_RECLAIM_AttributeList *attrs, 406 const struct GNUNET_RECLAIM_AttributeList *attrs,
387 GNUNET_RECLAIM_IssueTicketCallback cb, void *cb_cls); 407 GNUNET_RECLAIM_IssueTicketCallback cb, void *cb_cls);
388 408
@@ -403,7 +423,7 @@ GNUNET_RECLAIM_ticket_issue (
403struct GNUNET_RECLAIM_Operation * 423struct GNUNET_RECLAIM_Operation *
404GNUNET_RECLAIM_ticket_revoke ( 424GNUNET_RECLAIM_ticket_revoke (
405 struct GNUNET_RECLAIM_Handle *h, 425 struct GNUNET_RECLAIM_Handle *h,
406 const struct GNUNET_IDENTITY_PrivateKey *identity, 426 const struct GNUNET_CRYPTO_PrivateKey *identity,
407 const struct GNUNET_RECLAIM_Ticket *ticket, 427 const struct GNUNET_RECLAIM_Ticket *ticket,
408 GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls); 428 GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls);
409 429
@@ -413,9 +433,8 @@ GNUNET_RECLAIM_ticket_revoke (
413 * information from the issuer 433 * information from the issuer
414 * 434 *
415 * @param h the identity provider to use 435 * @param h the identity provider to use
416 * @param identity the identity that is the subject of the issued ticket (the
417 * relying party)
418 * @param ticket the issued ticket to consume 436 * @param ticket the issued ticket to consume
437 * @param rp_uri the RP URI
419 * @param cb the callback to call 438 * @param cb the callback to call
420 * @param cb_cls the callback closure 439 * @param cb_cls the callback closure
421 * @return handle to abort the operation 440 * @return handle to abort the operation
@@ -423,8 +442,8 @@ GNUNET_RECLAIM_ticket_revoke (
423struct GNUNET_RECLAIM_Operation * 442struct GNUNET_RECLAIM_Operation *
424GNUNET_RECLAIM_ticket_consume ( 443GNUNET_RECLAIM_ticket_consume (
425 struct GNUNET_RECLAIM_Handle *h, 444 struct GNUNET_RECLAIM_Handle *h,
426 const struct GNUNET_IDENTITY_PrivateKey *identity,
427 const struct GNUNET_RECLAIM_Ticket *ticket, 445 const struct GNUNET_RECLAIM_Ticket *ticket,
446 const char *rp_uri,
428 GNUNET_RECLAIM_AttributeTicketResult cb, void *cb_cls); 447 GNUNET_RECLAIM_AttributeTicketResult cb, void *cb_cls);
429 448
430 449
@@ -448,7 +467,7 @@ GNUNET_RECLAIM_ticket_consume (
448struct GNUNET_RECLAIM_TicketIterator * 467struct GNUNET_RECLAIM_TicketIterator *
449GNUNET_RECLAIM_ticket_iteration_start ( 468GNUNET_RECLAIM_ticket_iteration_start (
450 struct GNUNET_RECLAIM_Handle *h, 469 struct GNUNET_RECLAIM_Handle *h,
451 const struct GNUNET_IDENTITY_PrivateKey *identity, 470 const struct GNUNET_CRYPTO_PrivateKey *identity,
452 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, 471 GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
453 GNUNET_RECLAIM_TicketCallback proc, void *proc_cls, 472 GNUNET_RECLAIM_TicketCallback proc, void *proc_cls,
454 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls); 473 GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls);
@@ -495,7 +514,6 @@ GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h);
495void 514void
496GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op); 515GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op);
497 516
498
499#if 0 /* keep Emacsens' auto-indent happy */ 517#if 0 /* keep Emacsens' auto-indent happy */
500{ 518{
501#endif 519#endif
@@ -509,4 +527,6 @@ GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op);
509 527
510/** @} */ /* end of group reclaim */ 528/** @} */ /* end of group reclaim */
511 529
530/** @} */ /* end of group addition */
531
512/* end of gnunet_reclaim_service.h */ 532/* end of gnunet_reclaim_service.h */
diff --git a/src/include/gnunet_regex_service.h b/src/include/gnunet_regex_service.h
index a875eab90..093bf2d6a 100644
--- a/src/include/gnunet_regex_service.h
+++ b/src/include/gnunet_regex_service.h
@@ -18,6 +18,9 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup Backbone
22 * @{
23 *
21 * @author Maximilian Szengel 24 * @author Maximilian Szengel
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
@@ -36,6 +39,7 @@
36#ifndef GNUNET_REGEX_SERVICE_H 39#ifndef GNUNET_REGEX_SERVICE_H
37#define GNUNET_REGEX_SERVICE_H 40#define GNUNET_REGEX_SERVICE_H
38 41
42
39#include "gnunet_util_lib.h" 43#include "gnunet_util_lib.h"
40 44
41#ifdef __cplusplus 45#ifdef __cplusplus
@@ -149,3 +153,5 @@ GNUNET_REGEX_search_cancel (struct GNUNET_REGEX_Search *s);
149#endif 153#endif
150 154
151/** @} */ /* end of group */ 155/** @} */ /* end of group */
156
157/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_resolver_service.h b/src/include/gnunet_resolver_service.h
index 956e4d67e..89fec24f5 100644
--- a/src/include/gnunet_resolver_service.h
+++ b/src/include/gnunet_resolver_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup vpn_suite
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -40,6 +43,7 @@ extern "C"
40#endif 43#endif
41#endif 44#endif
42 45
46
43#include "gnunet_configuration_lib.h" 47#include "gnunet_configuration_lib.h"
44#include "gnunet_scheduler_lib.h" 48#include "gnunet_scheduler_lib.h"
45#include "gnunet_time_lib.h" 49#include "gnunet_time_lib.h"
@@ -178,4 +182,6 @@ GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh);
178 182
179/** @} */ /* end of group resolver */ 183/** @} */ /* end of group resolver */
180 184
185/** @} */ /* end of group addition to vpn_suite */
186
181/* end of gnunet_resolver_service.h */ 187/* end of gnunet_resolver_service.h */
diff --git a/src/include/gnunet_rest_lib.h b/src/include/gnunet_rest_lib.h
index 7e74bee76..f70500de5 100644
--- a/src/include/gnunet_rest_lib.h
+++ b/src/include/gnunet_rest_lib.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup rest_l2 REST service and libraries
23 * @{
24 *
22 * @author Martin Schanzenbach 25 * @author Martin Schanzenbach
23 * 26 *
24 * @file 27 * @file
@@ -31,6 +34,7 @@
31#ifndef GNUNET_REST_LIB_H 34#ifndef GNUNET_REST_LIB_H
32#define GNUNET_REST_LIB_H 35#define GNUNET_REST_LIB_H
33 36
37
34#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
35#include <microhttpd.h> 39#include <microhttpd.h>
36 40
@@ -137,3 +141,5 @@ GNUNET_REST_handle_request (struct GNUNET_REST_RequestHandle *conn,
137#endif 141#endif
138 142
139/** @} */ /* end of group */ 143/** @} */ /* end of group */
144
145/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_rest_plugin.h b/src/include/gnunet_rest_plugin.h
index 96454f66b..3a8af5389 100644
--- a/src/include/gnunet_rest_plugin.h
+++ b/src/include/gnunet_rest_plugin.h
@@ -18,6 +18,9 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup rest_l2 REST service and libraries
22 * @{
23 *
21 * @author Martin Schanzenbach 24 * @author Martin Schanzenbach
22 * 25 *
23 * @file 26 * @file
@@ -29,6 +32,7 @@
29#ifndef GNUNET_REST_PLUGIN_H 32#ifndef GNUNET_REST_PLUGIN_H
30#define GNUNET_REST_PLUGIN_H 33#define GNUNET_REST_PLUGIN_H
31 34
35
32#include "gnunet_util_lib.h" 36#include "gnunet_util_lib.h"
33#include "gnunet_rest_lib.h" 37#include "gnunet_rest_lib.h"
34#include "microhttpd.h" 38#include "microhttpd.h"
@@ -59,24 +63,13 @@ struct GNUNET_REST_Plugin
59 * e.g. http://hostname:port/name 63 * e.g. http://hostname:port/name
60 */ 64 */
61 char *name; 65 char *name;
62
63 /**
64 * Function to process a REST call
65 *
66 * @param method the HTTP method called
67 * @param url the relative url accessed
68 * @param data the REST data (can be NULL)
69 * @param data_size the length of the data
70 * @param proc the callback for result
71 * @param proc_cls closure for callback
72 * @return GNUNET_YES if the request was processed
73 */
74 enum GNUNET_GenericReturnValue (*process_request)(
75 struct GNUNET_REST_RequestHandle *handle,
76 GNUNET_REST_ResultProcessor proc,
77 void *proc_cls);
78}; 66};
79 67
68typedef enum GNUNET_GenericReturnValue (*GNUNET_REST_ProcessingFunction)(
69 void *plugin,
70 struct GNUNET_REST_RequestHandle *handle,
71 GNUNET_REST_ResultProcessor proc,
72 void *proc_cls);
80 73
81#if 0 /* keep Emacsens' auto-indent happy */ 74#if 0 /* keep Emacsens' auto-indent happy */
82{ 75{
@@ -88,3 +81,5 @@ struct GNUNET_REST_Plugin
88#endif 81#endif
89 82
90/** @} */ /* end of group */ 83/** @} */ /* end of group */
84
85/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_revocation_service.h b/src/include/gnunet_revocation_service.h
index 8cff948e2..427be62ac 100644
--- a/src/include/gnunet_revocation_service.h
+++ b/src/include/gnunet_revocation_service.h
@@ -21,9 +21,14 @@
21#ifndef GNUNET_REVOCATION_SERVICE_H_ 21#ifndef GNUNET_REVOCATION_SERVICE_H_
22#define GNUNET_REVOCATION_SERVICE_H_ 22#define GNUNET_REVOCATION_SERVICE_H_
23 23
24
25#include "gnunet_gnsrecord_lib.h"
24#include "gnunet_identity_service.h" 26#include "gnunet_identity_service.h"
25 27
26/** 28/**
29 * @addtogroup egos Ego management
30 * @{
31 *
27 * @author Christian Grothoff 32 * @author Christian Grothoff
28 * 33 *
29 * @file 34 * @file
@@ -52,71 +57,6 @@ extern "C"
52 */ 57 */
53#define GNUNET_REVOCATION_VERSION 0x00000001 58#define GNUNET_REVOCATION_VERSION 0x00000001
54 59
55/**
56 * Maximum length of a revocation
57 */
58#define GNUNET_REVOCATION_MAX_PROOF_SIZE sizeof(struct GNUNET_REVOCATION_PowP) +\
59 sizeof(struct GNUNET_IDENTITY_PublicKey) +\
60 1024 //FIXME max sig_len
61
62/**
63 * The proof-of-work narrowing factor.
64 * The number of PoWs that are calculates as part of revocation.
65 */
66#define POW_COUNT 32
67
68
69GNUNET_NETWORK_STRUCT_BEGIN
70
71/**
72 * Struct for a proof of work as part of the revocation.
73 */
74struct GNUNET_REVOCATION_PowP
75{
76 /**
77 * The timestamp of the revocation
78 */
79 struct GNUNET_TIME_AbsoluteNBO timestamp;
80
81 /**
82 * The TTL of this revocation (purely informational)
83 */
84 struct GNUNET_TIME_RelativeNBO ttl;
85
86 /**
87 * The PoWs
88 */
89 uint64_t pow[POW_COUNT] GNUNET_PACKED;
90
91 /** followed by the public key type, the key and a signature **/
92};
93
94
95/**
96 * The signature object we use for the PoW
97 */
98struct GNUNET_REVOCATION_SignaturePurposePS
99{
100 /**
101 * The signature purpose
102 */
103 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
104
105 /**
106 * The timestamp of the revocation
107 */
108 struct GNUNET_TIME_AbsoluteNBO timestamp;
109
110 /** Followed by the zone public key type and key **/
111};
112
113GNUNET_NETWORK_STRUCT_END
114
115
116/**
117 * Handle to a running proof-of-work calculation.
118 */
119struct GNUNET_REVOCATION_PowCalculationHandle;
120 60
121/** 61/**
122 * Handle for the key revocation query. 62 * Handle for the key revocation query.
@@ -148,7 +88,7 @@ typedef void (*GNUNET_REVOCATION_Callback) (void *cls,
148 */ 88 */
149struct GNUNET_REVOCATION_Query * 89struct GNUNET_REVOCATION_Query *
150GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg, 90GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg,
151 const struct GNUNET_IDENTITY_PublicKey *key, 91 const struct GNUNET_CRYPTO_PublicKey *key,
152 GNUNET_REVOCATION_Callback func, void *func_cls); 92 GNUNET_REVOCATION_Callback func, void *func_cls);
153 93
154 94
@@ -172,7 +112,7 @@ struct GNUNET_REVOCATION_Handle;
172 * 112 *
173 * @param cfg the configuration to use 113 * @param cfg the configuration to use
174 * @param pow proof of work to use (should have been created by 114 * @param pow proof of work to use (should have been created by
175 * iteratively calling #GNUNET_REVOCATION_pow_round) 115 * iteratively calling #GNUNET_CRYPTO_pow_round)
176 * @param func function to call with the result of the check 116 * @param func function to call with the result of the check
177 * (called with `is_valid` being #GNUNET_NO if 117 * (called with `is_valid` being #GNUNET_NO if
178 * the revocation worked). 118 * the revocation worked).
@@ -181,7 +121,7 @@ struct GNUNET_REVOCATION_Handle;
181 */ 121 */
182struct GNUNET_REVOCATION_Handle * 122struct GNUNET_REVOCATION_Handle *
183GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, 123GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg,
184 const struct GNUNET_REVOCATION_PowP *pow, 124 const struct GNUNET_GNSRECORD_PowP *pow,
185 GNUNET_REVOCATION_Callback func, void *func_cls); 125 GNUNET_REVOCATION_Callback func, void *func_cls);
186 126
187 127
@@ -194,68 +134,6 @@ void
194GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h); 134GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h);
195 135
196 136
197/**
198 * Check if the given proof-of-work is valid.
199 *
200 * @param pow proof of work
201 * @param matching_bits how many bits must match (configuration)
202 * @param epoch_duration length of single epoch in configuration
203 * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
204 */
205enum GNUNET_GenericReturnValue
206GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow,
207 unsigned int matching_bits,
208 struct GNUNET_TIME_Relative epoch_duration);
209
210
211/**
212 * Initializes a fresh PoW computation.
213 *
214 * @param key the key to calculate the PoW for.
215 * @param pow the pow object to work with in the calculation.
216 */
217void
218GNUNET_REVOCATION_pow_init (const struct GNUNET_IDENTITY_PrivateKey *key,
219 struct GNUNET_REVOCATION_PowP *pow);
220
221
222/**
223 * Starts a proof-of-work calculation given the pow object as well as
224 * target epochs and difficulty.
225 *
226 * @param pow the PoW to based calculations on.
227 * @param epochs the number of epochs for which the PoW must be valid.
228 * @param difficulty the base difficulty of the PoW.
229 * @return a handle for use in PoW rounds
230 */
231struct GNUNET_REVOCATION_PowCalculationHandle*
232GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_PowP *pow,
233 int epochs,
234 unsigned int difficulty);
235
236
237/**
238 * Calculate a single round in the key revocation PoW.
239 *
240 * @param pc handle to the PoW, initially called with NULL.
241 * @return GNUNET_YES if the @a pow is acceptable, GNUNET_NO if not
242 */
243enum GNUNET_GenericReturnValue
244GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc);
245
246
247/**
248 * Stop a PoW calculation
249 *
250 * @param pc the calculation to clean up
251 * @return #GNUNET_YES if pow valid, #GNUNET_NO if pow was set but is not
252 * valid
253 */
254void
255GNUNET_REVOCATION_pow_stop (struct GNUNET_REVOCATION_PowCalculationHandle *pc);
256
257size_t
258GNUNET_REVOCATION_proof_get_size (const struct GNUNET_REVOCATION_PowP *pow);
259 137
260 138
261#if 0 /* keep Emacsens' auto-indent happy */ 139#if 0 /* keep Emacsens' auto-indent happy */
@@ -268,3 +146,5 @@ GNUNET_REVOCATION_proof_get_size (const struct GNUNET_REVOCATION_PowP *pow);
268#endif /* GNUNET_REVOCATION_SERVICE_H_ */ 146#endif /* GNUNET_REVOCATION_SERVICE_H_ */
269 147
270/** @} */ /* end of group revocation */ 148/** @} */ /* end of group revocation */
149
150/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_rps_service.h b/src/include/gnunet_rps_service.h
index a0ed675f7..85c085111 100644
--- a/src/include/gnunet_rps_service.h
+++ b/src/include/gnunet_rps_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Backbone
23 * @{
24 *
22 * @author Julius Bünger 25 * @author Julius Bünger
23 * 26 *
24 * @file 27 * @file
@@ -262,3 +265,5 @@ GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h);
262#endif 265#endif
263 266
264/** @} */ /* end of group */ 267/** @} */ /* end of group */
268
269/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_scalarproduct_service.h b/src/include/gnunet_scalarproduct_service.h
index 1d775f659..96d12db3f 100644
--- a/src/include/gnunet_scalarproduct_service.h
+++ b/src/include/gnunet_scalarproduct_service.h
@@ -31,6 +31,7 @@
31#ifndef GNUNET_SCALARPRODUCT_SERVICE_H 31#ifndef GNUNET_SCALARPRODUCT_SERVICE_H
32#define GNUNET_SCALARPRODUCT_SERVICE_H 32#define GNUNET_SCALARPRODUCT_SERVICE_H
33#define GCRYPT_NO_DEPRECATED 33#define GCRYPT_NO_DEPRECATED
34
34#include <gcrypt.h> 35#include <gcrypt.h>
35 36
36#ifdef __cplusplus 37#ifdef __cplusplus
@@ -179,7 +180,7 @@ GNUNET_SCALARPRODUCT_start_computation (
179struct GNUNET_SCALARPRODUCT_ComputationHandle * 180struct GNUNET_SCALARPRODUCT_ComputationHandle *
180GNUNET_SCALARPRODUCT_accept_computation ( 181GNUNET_SCALARPRODUCT_accept_computation (
181 const struct GNUNET_CONFIGURATION_Handle *cfg, 182 const struct GNUNET_CONFIGURATION_Handle *cfg,
182 const struct GNUNET_HashCode *key, 183 const struct GNUNET_HashCode *session_key,
183 const struct GNUNET_SCALARPRODUCT_Element *elements, 184 const struct GNUNET_SCALARPRODUCT_Element *elements,
184 uint32_t element_count, 185 uint32_t element_count,
185 GNUNET_SCALARPRODUCT_ContinuationWithStatus cont, 186 GNUNET_SCALARPRODUCT_ContinuationWithStatus cont,
diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h
index 158f1d83b..0118a1535 100644
--- a/src/include/gnunet_scheduler_lib.h
+++ b/src/include/gnunet_scheduler_lib.h
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * 27 *
24 * @file 28 * @file
@@ -92,6 +96,7 @@ enum GNUNET_SCHEDULER_Reason
92}; 96};
93 97
94 98
99
95#include "gnunet_time_lib.h" 100#include "gnunet_time_lib.h"
96#include "gnunet_network_lib.h" 101#include "gnunet_network_lib.h"
97 102
@@ -929,3 +934,5 @@ GNUNET_SCHEDULER_begin_async_scope (struct GNUNET_AsyncScopeId *aid);
929#endif 934#endif
930 935
931/** @} */ /* end of group scheduler */ 936/** @} */ /* end of group scheduler */
937
938/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_secretsharing_service.h b/src/include/gnunet_secretsharing_service.h
index c13cf482a..de629b308 100644
--- a/src/include/gnunet_secretsharing_service.h
+++ b/src/include/gnunet_secretsharing_service.h
@@ -40,6 +40,7 @@ extern "C"
40#endif 40#endif
41#endif 41#endif
42 42
43
43#include "gnunet_common.h" 44#include "gnunet_common.h"
44#include "gnunet_time_lib.h" 45#include "gnunet_time_lib.h"
45#include "gnunet_configuration_lib.h" 46#include "gnunet_configuration_lib.h"
diff --git a/src/include/gnunet_service_lib.h b/src/include/gnunet_service_lib.h
index ad238a0fa..0ad4fcc3c 100644
--- a/src/include/gnunet_service_lib.h
+++ b/src/include/gnunet_service_lib.h
@@ -18,7 +18,19 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21
22#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
23#error "Only <gnunet_util_lib.h> can be included directly."
24#endif
25
21/** 26/**
27 * @addtogroup libgnunetutil
28 * Multi-function utilities library for GNUnet programs
29 * @{
30 *
31 * @addtogroup networking
32 * @{
33 *
22 * @author Christian Grothoff 34 * @author Christian Grothoff
23 * 35 *
24 * @file 36 * @file
@@ -43,8 +55,8 @@ extern "C"
43#endif 55#endif
44#endif 56#endif
45 57
58#include "gnunet_util_lib.h"
46#include "gnunet_configuration_lib.h" 59#include "gnunet_configuration_lib.h"
47#include "gnunet_mq_lib.h"
48 60
49 61
50/** 62/**
@@ -191,7 +203,6 @@ GNUNET_SERVICE_start (const char *service_name,
191void 203void
192GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Handle *srv); 204GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Handle *srv);
193 205
194
195/** 206/**
196 * Creates the "main" function for a GNUnet service. You 207 * Creates the "main" function for a GNUnet service. You
197 * should almost always use the #GNUNET_SERVICE_MAIN macro 208 * should almost always use the #GNUNET_SERVICE_MAIN macro
@@ -246,6 +257,56 @@ GNUNET_SERVICE_run_ (int argc,
246 257
247 258
248/** 259/**
260 * Registers the GNUnet service to be scheduled as part of a monilithic
261 * libgnunet.
262 * You should almost always use the #GNUNET_SERVICE_MAIN macro
263 * instead of calling this function directly.
264 *
265 * The function will launch the service with the name @a service_name
266 * using the @a service_options to configure its shutdown
267 * behavior. Once the service is ready, the @a init_cb will be called
268 * for service-specific initialization. @a init_cb will be given the
269 * service handler which can be used to control the service's
270 * availability. When clients connect or disconnect, the respective
271 * @a connect_cb or @a disconnect_cb functions will be called. For
272 * messages received from the clients, the respective @a handlers will
273 * be invoked; for the closure of the handlers we use the return value
274 * from the @a connect_cb invocation of the respective client.
275 *
276 * Each handler MUST call #GNUNET_SERVICE_client_continue() after each
277 * message to receive further messages from this client. If
278 * #GNUNET_SERVICE_client_continue() is not called within a short
279 * time, a warning will be logged. If delays are expected, services
280 * should call #GNUNET_SERVICE_client_disable_continue_warning() to
281 * disable the warning.
282 *
283 * Clients sending invalid messages (based on @a handlers) will be
284 * dropped. Additionally, clients can be dropped at any time using
285 * #GNUNET_SERVICE_client_drop().
286 *
287 * @param service_name name of the service to run
288 * @param options options controlling shutdown of the service
289 * @param service_init_cb function to call once the service is ready
290 * @param connect_cb function to call whenever a client connects
291 * @param disconnect_cb function to call whenever a client disconnects
292 * @param cls closure argument for @a service_init_cb, @a connect_cb and @a disconnect_cb
293 * @param handlers NULL-terminated array of message handlers for the service,
294 * the closure will be set to the value returned by
295 * the @a connect_cb for the respective connection
296 * @return 0 on success, non-zero on error
297 */
298int
299GNUNET_SERVICE_register_ (
300 const char *service_name,
301 enum GNUNET_SERVICE_Options options,
302 GNUNET_SERVICE_InitCallback service_init_cb,
303 GNUNET_SERVICE_ConnectHandler connect_cb,
304 GNUNET_SERVICE_DisconnectHandler disconnect_cb,
305 void *cls,
306 const struct GNUNET_MQ_MessageHandler *handlers);
307
308
309/**
249 * Creates the "main" function for a GNUnet service. You 310 * Creates the "main" function for a GNUnet service. You
250 * MUST use this macro to define GNUnet services (except 311 * MUST use this macro to define GNUnet services (except
251 * for ARM, which MUST NOT use the macro). The reason is 312 * for ARM, which MUST NOT use the macro). The reason is
@@ -275,8 +336,8 @@ GNUNET_SERVICE_run_ (int argc,
275 * #GNUNET_SERVICE_client_drop(). 336 * #GNUNET_SERVICE_client_drop().
276 * 337 *
277 * @param service_name name of the service to run 338 * @param service_name name of the service to run
278 * @param options options controlling shutdown of the service 339 * @param service_options options controlling shutdown of the service
279 * @param service_init_cb function to call once the service is ready 340 * @param init_cb function to call once the service is ready
280 * @param connect_cb function to call whenever a client connects 341 * @param connect_cb function to call whenever a client connects
281 * @param disconnect_cb function to call whenever a client disconnects 342 * @param disconnect_cb function to call whenever a client disconnects
282 * @param cls closure argument for @a service_init_cb, @a connect_cb and @a disconnect_cb 343 * @param cls closure argument for @a service_init_cb, @a connect_cb and @a disconnect_cb
@@ -302,26 +363,51 @@ GNUNET_SERVICE_run_ (int argc,
302 * GNUNET_MQ_handler_end ()); 363 * GNUNET_MQ_handler_end ());
303 * </code> 364 * </code>
304 */ 365 */
366#ifndef HAVE_GNUNET_MONOLITH
367#define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb, connect_cb, \
368 disconnect_cb, cls, ...) \
369 int \
370 main (int argc, \
371 char *const *argv) \
372 { \
373 struct GNUNET_MQ_MessageHandler mh[] = { \
374 __VA_ARGS__ \
375 }; \
376 return GNUNET_SERVICE_run_ (argc, \
377 argv, \
378 service_name, \
379 service_options, \
380 init_cb, \
381 connect_cb, \
382 disconnect_cb, \
383 cls, \
384 mh); \
385 }
386#else
305#define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb, connect_cb, \ 387#define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb, connect_cb, \
306 disconnect_cb, cls, ...) \ 388 disconnect_cb, cls, ...) \
307 int \ 389 static int __attribute__ ((constructor)) \
308 main (int argc, \ 390 init (void) \
309 char *const *argv) \ 391 { \
310 { \ 392 struct GNUNET_MQ_MessageHandler mh[] = { \
311 struct GNUNET_MQ_MessageHandler mh[] = { \ 393 __VA_ARGS__ \
312 __VA_ARGS__ \ 394 }; \
313 }; \ 395 return GNUNET_SERVICE_register_ (service_name, \
314 return GNUNET_SERVICE_run_ (argc, \ 396 service_options, \
315 argv, \ 397 init_cb, \
316 service_name, \ 398 connect_cb, \
317 service_options, \ 399 disconnect_cb, \
318 init_cb, \ 400 cls, \
319 connect_cb, \ 401 mh); \
320 disconnect_cb, \ 402 }
321 cls, \ 403#endif
322 mh); \
323 }
324 404
405/**
406 * Run the mainloop in a monolithic libgnunet.
407 * Must be called such that services are actually launched.
408 */
409void
410GNUNET_SERVICE_main (int argc, char *const *argv);
325 411
326/** 412/**
327 * Suspend accepting connections from the listen socket temporarily. 413 * Suspend accepting connections from the listen socket temporarily.
@@ -442,4 +528,8 @@ GNUNET_SERVICE_client_persist (struct GNUNET_SERVICE_Client *c);
442 528
443/** @} */ /* end of group service */ 529/** @} */ /* end of group service */
444 530
531/** @} */ /* end of group addition to networking*/
532
533/** @} */ /* end of group addition to libgnunetutil */
534
445/* end of gnunet_service_lib.h */ 535/* end of gnunet_service_lib.h */
diff --git a/src/include/gnunet_set_service.h b/src/include/gnunet_set_service.h
index 802a979cd..6874c9ec4 100644
--- a/src/include/gnunet_set_service.h
+++ b/src/include/gnunet_set_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Sets
23 * @{
24 *
22 * @author Florian Dold 25 * @author Florian Dold
23 * @author Christian Grothoff 26 * @author Christian Grothoff
24 * 27 *
@@ -44,6 +47,7 @@ extern "C"
44#endif 47#endif
45#endif 48#endif
46 49
50
47#include "gnunet_common.h" 51#include "gnunet_common.h"
48#include "gnunet_time_lib.h" 52#include "gnunet_time_lib.h"
49#include "gnunet_configuration_lib.h" 53#include "gnunet_configuration_lib.h"
@@ -365,10 +369,10 @@ GNUNET_SET_add_element (struct GNUNET_SET_Handle *set,
365 369
366 370
367/** 371/**
368 * Remove an element to the given set. 372 * Remove an element to the given set.
369 * After the element has been removed (in the sense of the 373 * After the element has been removed (in the sense of the request
370 * request being transmitted to the set service), cont will be called. 374 * being transmitted to the set service), @a cont will be called.
371 * Calls to remove_element can be queued 375 * Multiple calls to GNUNET_SET_remove_element() can be queued
372 * 376 *
373 * @param set set to remove element from 377 * @param set set to remove element from
374 * @param element element to remove from the set 378 * @param element element to remove from the set
@@ -556,7 +560,7 @@ GNUNET_SET_element_dup (const struct GNUNET_SET_Element *element);
556 * Hash a set element. 560 * Hash a set element.
557 * 561 *
558 * @param element the element that should be hashed 562 * @param element the element that should be hashed
559 * @param ret_hash a pointer to where the hash of @a element 563 * @param[out] ret_hash a pointer to where the hash of @a element
560 * should be stored 564 * should be stored
561 */ 565 */
562void 566void
@@ -574,3 +578,5 @@ GNUNET_SET_element_hash (const struct GNUNET_SET_Element *element,
574#endif 578#endif
575 579
576/** @} */ /* end of group */ 580/** @} */ /* end of group */
581
582/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_seti_service.h b/src/include/gnunet_seti_service.h
index 5cf35e0cd..9125ae825 100644
--- a/src/include/gnunet_seti_service.h
+++ b/src/include/gnunet_seti_service.h
@@ -18,6 +18,9 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup Sets
22 * @{
23 *
21 * @author Florian Dold 24 * @author Florian Dold
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
@@ -41,6 +44,7 @@ extern "C"
41#endif 44#endif
42#endif 45#endif
43 46
47
44#include "gnunet_common.h" 48#include "gnunet_common.h"
45#include "gnunet_time_lib.h" 49#include "gnunet_time_lib.h"
46#include "gnunet_configuration_lib.h" 50#include "gnunet_configuration_lib.h"
@@ -367,3 +371,5 @@ GNUNET_SETI_element_hash (const struct GNUNET_SETI_Element *element,
367#endif 371#endif
368 372
369/** @} */ /* end of group */ 373/** @} */ /* end of group */
374
375/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_setu_service.h b/src/include/gnunet_setu_service.h
index 1d7e48402..89a50f138 100644
--- a/src/include/gnunet_setu_service.h
+++ b/src/include/gnunet_setu_service.h
@@ -18,6 +18,9 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup Sets
22 * @{
23 *
21 * @author Florian Dold 24 * @author Florian Dold
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
@@ -41,6 +44,7 @@ extern "C"
41#endif 44#endif
42#endif 45#endif
43 46
47
44#include "gnunet_common.h" 48#include "gnunet_common.h"
45#include "gnunet_time_lib.h" 49#include "gnunet_time_lib.h"
46#include "gnunet_configuration_lib.h" 50#include "gnunet_configuration_lib.h"
@@ -288,9 +292,9 @@ GNUNET_SETU_destroy (struct GNUNET_SETU_Handle *set);
288 292
289 293
290/** 294/**
291 * Prepare a set operation to be evaluated with another peer. The evaluation 295 * Prepare a set operation to be evaluated with another peer.
292 * will not start until the client provides a local set with 296 * The evaluation will not start until the client provides a
293 * GNUNET_SETU_commit(). 297 * local set with GNUNET_SETU_commit().
294 * 298 *
295 * @param other_peer peer with the other set 299 * @param other_peer peer with the other set
296 * @param app_id hash for the application using the set 300 * @param app_id hash for the application using the set
@@ -412,3 +416,5 @@ GNUNET_SETU_element_hash (const struct GNUNET_SETU_Element *element,
412#endif 416#endif
413 417
414/** @} */ /* end of group */ 418/** @} */ /* end of group */
419
420/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_signal_lib.h b/src/include/gnunet_signal_lib.h
index 5a14a2d9e..02fbbf005 100644
--- a/src/include/gnunet_signal_lib.h
+++ b/src/include/gnunet_signal_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs
28 * @{
29 *
22 * @author Christian Grothoff 30 * @author Christian Grothoff
23 * 31 *
24 * @file 32 * @file
@@ -105,4 +113,6 @@ GNUNET_SIGNAL_raise (const int sig);
105 113
106/** @} */ /* end of group */ 114/** @} */ /* end of group */
107 115
116/** @} */ /* end of group addition */
117
108/* end of gnunet_signal_lib.h */ 118/* end of gnunet_signal_lib.h */
diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h
index 7c0c1d104..6ec30bf71 100644
--- a/src/include/gnunet_signatures.h
+++ b/src/include/gnunet_signatures.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2012-2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -17,250 +17,238 @@
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20#ifndef GNUNET_SIGNATURES_H
21#define GNUNET_SIGNATURES_H
20 22
21/** 23/**
22 * @author Christian Grothoff 24 * WARNING:
23 * 25 * This header is generated!
24 * @file 26 * In order to add a signature purpose, you must register
25 * Constants for network signatures 27 * them in GANA, and then use the header generation script
26 * 28 * to create an update of this file. You may then replace this
27 * @defgroup signatures Network signature definitions 29 * file with the update.
28 * @{
29 */ 30 */
30 31
31#ifndef GNUNET_SIGNATURES_H 32
32#define GNUNET_SIGNATURES_H
33 33
34#ifdef __cplusplus 34#ifdef __cplusplus
35extern "C" 35extern "C" {
36{ 36#if 0 /* keep Emacsens' auto-indent happy */
37#if 0 /* keep Emacsens' auto-indent happy */
38} 37}
39#endif 38#endif
40#endif 39#endif
41 40
41
42/** 42/**
43 * Test signature, not valid for anything other than writing 43 * Network signature purpose definitions. Note that all values
44 * a test. (Note that the signature verification code will 44 * must be uint32_t and encoded in network byte order in the structs.
45 * accept this value). 45 */
46
47
48
49/**
50 * Test signature, not valid for anything other than writing a test. (Note that the signature verification code will accept this value). (GNUnet)
46 */ 51 */
47#define GNUNET_SIGNATURE_PURPOSE_TEST 0 52#define GNUNET_SIGNATURE_PURPOSE_TEST 0
48 53
54
49/** 55/**
50 * Signature for confirming that this peer uses a particular address. 56 * Signature for confirming that this peer uses a particular address. (GNUnet-TRANSPORT)
51 */ 57 */
52#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN 1 58#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN 1
53 59
60
54/** 61/**
55 * Signature for confirming that this peer intends to disconnect. 62 * Signature for confirming that this peer intends to disconnect. (GNUnet-TRANSPORT)
56 */ 63 */
57#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DISCONNECT 2 64#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DISCONNECT 2
58 65
66
59/** 67/**
60 * Signature for confirming a key revocation. 68 * GNS zone key revocation (GNS)
61 */ 69 */
62#define GNUNET_SIGNATURE_PURPOSE_REVOCATION 3 70#define GNUNET_SIGNATURE_PURPOSE_GNS_REVOCATION 3
71
63 72
64/** 73/**
65 * Signature for a namespace/pseudonym advertisement (by 74 * Signature for a namespace/pseudonym advertisement (by the namespace owner). (GNUnet-FS)
66 * the namespace owner).
67 */ 75 */
68#define GNUNET_SIGNATURE_PURPOSE_NAMESPACE_ADVERTISEMENT 4 76#define GNUNET_SIGNATURE_PURPOSE_NAMESPACE_ADVERTISEMENT 4
69 77
78
70/** 79/**
71 * Signature by which a peer affirms that it is 80 * Signature by which a peer affirms that it is providing a certain bit of content for use in LOCation URIs. (GNUnet-FS)
72 * providing a certain bit of content (used
73 * in LOCation URIs).
74 */ 81 */
75#define GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT 5 82#define GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT 5
76 83
77/**
78 * Obsolete, legacy value.
79 */
80#define GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK 6
81 84
82/** 85/**
83 * Obsolete, legacy value. 86 * Signature by which a peer affirms that it forwarded a message in the DHT. (GNUnet-DHT)
84 */ 87 */
85#define GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK 7 88#define GNUNET_SIGNATURE_PURPOSE_DHT_HOP 6
86 89
87/**
88 * Obsolete, legacy value.
89 */
90#define GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK 8
91 90
92/** 91/**
93 * Obsolete, legacy value. 92 * Signature by which a peer affirms its address. (GNUnet-HELLO)
94 */ 93 */
95#define GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG 9 94#define GNUNET_SIGNATURE_PURPOSE_HELLO 7
96 95
97/**
98 *
99 */
100#define GNUNET_SIGNATURE_PURPOSE_RESOLVER_RESPONSE 10
101 96
102/** 97/**
103 * Signature of an GNUNET_DNS_Advertisement 98 * Signature on a GNUNET_DNS_Advertisement. (GNUnet-DNS+Exit)
104 */ 99 */
105#define GNUNET_SIGNATURE_PURPOSE_DNS_RECORD 11 100#define GNUNET_SIGNATURE_PURPOSE_DNS_RECORD 11
106 101
102
107/** 103/**
108 * Signature of a chat message. 104 * Signature of a chat message. (GNUnet-MESSENGER)
109 */ 105 */
110#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE 12 106#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE 12
111 107
108
112/** 109/**
113 * Signature of confirmation receipt for a chat message. 110 * Signature of confirmation receipt for a chat message. (GNUnet-MESSENGER)
114 */ 111 */
115#define GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT 13 112#define GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT 13
116 113
114
117/** 115/**
118 * Signature of a network size estimate message. 116 * Signature of a network size estimate message. (GNUnet-NSE)
119 */ 117 */
120#define GNUNET_SIGNATURE_PURPOSE_NSE_SEND 14 118#define GNUNET_SIGNATURE_PURPOSE_NSE_SEND 14
121 119
120
122/** 121/**
123 * Signature of a gnunet naming system record block 122 * GNS record set signature (GNS)
124 */ 123 */
125#define GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN 15 124#define GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN 15
126 125
126
127/** 127/**
128 * Purpose is to set a session key. 128 * Purpose is to set a session key. (GNUnet-CORE)
129 */ 129 */
130#define GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY 16 130#define GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY 16
131 131
132
132/** 133/**
133 * UBlock Signature, done using DSS, not ECC 134 * UBlock Signature, done using DSS, not ECC (GNUnet-FS)
134 */ 135 */
135#define GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK 17 136#define GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK 17
136 137
138
137/** 139/**
138 * Accept state in regex DFA. Peer affirms that 140 * Accept state in regex DFA. Peer affirms that it offers the matching service. (GNUnet-REGEX)
139 * it offers the matching service.
140 */ 141 */
141#define GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT 18 142#define GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT 18
142 143
143/**
144 * Signature of a multicast message sent by the origin.
145 */
146#define GNUNET_SIGNATURE_PURPOSE_MULTICAST_MESSAGE 19
147 144
148/** 145/**
149 * Signature of a conversation ring. 146 * Signature of a conversation ring. (GNUnet-CONVERSATION)
150 */ 147 */
151#define GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING 20 148#define GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING 20
152 149
150
153/** 151/**
154 * Signature for the first round of distributed key generation. 152 * Signature for the first round of distributed key generation. (GNUnet-SECRETSHARING)
155 */ 153 */
156#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG1 21 154#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG1 21
157 155
158/**
159 * Signature for the second round of distributed key generation.
160 */
161#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG2 22
162 156
163/** 157/**
164 * Signature for cooperatice decryption. 158 * Signature for the second round of distributed key generation. (GNUnet-SECRETSHARING)
165 */ 159 */
166#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DECRYPTION 23 160#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG2 22
167 161
168/**
169 * Signature of a multicast request sent by a member.
170 */
171#define GNUNET_SIGNATURE_PURPOSE_MULTICAST_REQUEST 24
172 162
173/** 163/**
174 * Signature for a sensor anomaly report message. 164 * Signature for the cooperative decryption. (GNUnet-SECRETSHARING)
175 */ 165 */
176#define GNUNET_SIGNATURE_PURPOSE_SENSOR_ANOMALY_REPORT 25 166#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DECRYPTION 23
177 167
178/**
179 * Signature for a GNUid Token
180 */
181#define GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN 26
182 168
183/** 169/**
184 * Signature for a GNUid Ticket 170 * Signature for a GNUid Ticket (Reclaim)
185 */ 171 */
186#define GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN 27 172#define GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN 27
187 173
174
188/** 175/**
189 * Signature for a GNUnet credential 176 * Signature for a GNUnet credential (Reclaim)
190 */ 177 */
191#define GNUNET_SIGNATURE_PURPOSE_DELEGATE 28 178#define GNUNET_SIGNATURE_PURPOSE_DELEGATE 28
192 179
180
193/** 181/**
194 * Signature by a peer affirming that this is one of its 182 * Signature by a peer affirming that this is one of its addresses for the given time period. (GNUnet-TRANSPORT)
195 * addresses (for the given time period).
196 */ 183 */
197#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS 29 184#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS 29
198 185
186
199/** 187/**
200 * Signature by a peer affirming that the given ephemeral 188 * Signature by a peer affirming that the given ephemeral key is currently in use by that peer's transport service. (GNUnet-TRANSPORT)
201 * key is currently in use by that peer's transport service.
202 */ 189 */
203#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL 30 190#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL 30
204 191
192
205/** 193/**
206 * Signature used by TCP communicator handshake, 194 * Signature used by TCP communicator handshake. (GNUnet-TRANSPORT-TCP)
207 */ 195 */
208#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE 31 196#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE 31
197
209 198
210/** 199/**
211 * Signature used by TCP communicator rekey. 200 * Signature used by TCP communicator rekey. (GNUnet-TRANSPORT-TCP)
212 */ 201 */
213#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY 32 202#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_REKEY 32
203
214 204
215/** 205/**
216 * Signature used by UDP communicator handshake 206 * Signature used by UDP communicator handshake. (GNUnet-TRANSPORT-UDP)
217 */ 207 */
218#define GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE 33 208#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_UDP_HANDSHAKE 33
209
219 210
220/** 211/**
221 * Signature used by UDP broadcasts. 212 * Signature used by UDP broadcasts. (GNUnet-TRANSPORT-UDP)
222 */ 213 */
223#define GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST 34 214#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_UDP_BROADCAST 34
215
224 216
225/** 217/**
226 * Signature by a peer affirming that it received a 218 * Signature by a peer affirming that it received a challenge (and stating how long it expects the address on which the challenge was received to remain valid). (GNUnet-TRANSPORT)
227 * challenge (and stating how long it expects the
228 * address on which the challenge was received to
229 * remain valid).
230 */ 219 */
231#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE 35 220#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE 35
232 221
222
233/** 223/**
234 * Signature by a peer affirming that it is on a DV path. 224 * Signature by a peer affirming that it is on a DV path. (GNUnet-TRANSPORT)
235 */ 225 */
236#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP 36 226#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP 36
237 227
228
238/** 229/**
239 * Signature by a peer affirming that it originated the 230 * Signature by a peer affirming that it originated the DV path. (GNUnet-TRANSPORT)
240 * DV path.
241 */ 231 */
242#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR 37 232#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR 37
243 233
234
244/** 235/**
245 * Signature by a peer that like to create a connection. 236 * Signature by a peer that like to create a connection. (GNUnet-CADET)
246 */ 237 */
247#define GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR 38 238#define GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR 38
248 239
240
249/** 241/**
250 * Signature by a peer sending back the nonce received at initial handshake. 242 * Signature by a peer sending back the nonce received at initial handshake. (GNUnet-TRANSPORT-TCP)
251 */ 243 */
252#define GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE_ACK 39 244#define GNUNET_SIGNATURE_PURPOSE_COMMUNICATOR_TCP_HANDSHAKE_ACK 39
253 245
254#if 0 /* keep Emacsens' auto-indent happy */ 246
247#if 0 /* keep Emacsens' auto-indent happy */
255{ 248{
256#endif 249#endif
257#ifdef __cplusplus 250#ifdef __cplusplus
258} 251}
259#endif 252#endif
260 253
261/* ifndef GNUNET_SIGNATURES_H */
262#endif 254#endif
263
264/** @} */ /* end of group */
265
266/* end of gnunet_signatures.h */
diff --git a/src/include/gnunet_socks.h b/src/include/gnunet_socks.h
index 1a6ae1119..98a27cd1a 100644
--- a/src/include/gnunet_socks.h
+++ b/src/include/gnunet_socks.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * @{
24 *
22 * @author Jeffrey Burdges 25 * @author Jeffrey Burdges
23 * 26 *
24 * @file 27 * @file
@@ -40,6 +43,7 @@ extern "C"
40#endif 43#endif
41#endif 44#endif
42 45
46
43#include "gnunet_common.h" 47#include "gnunet_common.h"
44 48
45 49
@@ -81,4 +85,6 @@ GNUNET_SOCKS_do_connect (const char *service_name,
81 85
82/** @} */ /* end of group */ 86/** @} */ /* end of group */
83 87
88/** @} */ /* end of group addition to libgnunetutil */
89
84/* end of gnunet_socks.h */ 90/* end of gnunet_socks.h */
diff --git a/src/include/gnunet_speaker_lib.h b/src/include/gnunet_speaker_lib.h
index 71a7c2166..c6bb128dd 100644
--- a/src/include/gnunet_speaker_lib.h
+++ b/src/include/gnunet_speaker_lib.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup conversation_l2 Conversation service and libraries
23 * @{
24 *
22 * @author Simon Dieterle 25 * @author Simon Dieterle
23 * @author Andreas Fuchs 26 * @author Andreas Fuchs
24 * @author Christian Grothoff 27 * @author Christian Grothoff
@@ -41,6 +44,7 @@ extern "C"
41#endif 44#endif
42#endif 45#endif
43 46
47
44#include "gnunet_util_lib.h" 48#include "gnunet_util_lib.h"
45 49
46/** 50/**
@@ -142,4 +146,6 @@ GNUNET_SPEAKER_destroy (struct GNUNET_SPEAKER_Handle *speaker);
142 146
143/** @} */ /* end of group */ 147/** @} */ /* end of group */
144 148
149/** @} */ /* end of group addition */
150
145/* end of gnunet_speaker_lib.h */ 151/* end of gnunet_speaker_lib.h */
diff --git a/src/include/gnunet_sq_lib.h b/src/include/gnunet_sq_lib.h
index 21ce5b393..b84e6759a 100644
--- a/src/include/gnunet_sq_lib.h
+++ b/src/include/gnunet_sq_lib.h
@@ -25,6 +25,7 @@
25#ifndef GNUNET_SQ_LIB_H 25#ifndef GNUNET_SQ_LIB_H
26#define GNUNET_SQ_LIB_H 26#define GNUNET_SQ_LIB_H
27 27
28
28#include <sqlite3.h> 29#include <sqlite3.h>
29#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
30 31
@@ -40,7 +41,7 @@
40 * so immediately suitable for passing to `sqlite3_bind`-functions. 41 * so immediately suitable for passing to `sqlite3_bind`-functions.
41 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 42 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
42 */ 43 */
43typedef int 44typedef enum GNUNET_GenericReturnValue
44(*GNUNET_SQ_QueryConverter)(void *cls, 45(*GNUNET_SQ_QueryConverter)(void *cls,
45 const void *data, 46 const void *data,
46 size_t data_len, 47 size_t data_len,
@@ -91,7 +92,7 @@ struct GNUNET_SQ_QueryParam
91 * @a ptr_size bytes. 92 * @a ptr_size bytes.
92 * 93 *
93 * @param ptr pointer to the query parameter to pass 94 * @param ptr pointer to the query parameter to pass
94 * @oaran ptr_size number of bytes in @a ptr 95 * @param ptr_size number of bytes in @a ptr
95 */ 96 */
96struct GNUNET_SQ_QueryParam 97struct GNUNET_SQ_QueryParam
97GNUNET_SQ_query_param_fixed_size (const void *ptr, 98GNUNET_SQ_query_param_fixed_size (const void *ptr,
@@ -156,8 +157,8 @@ GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x);
156 * @param x pointer to the query parameter to pass 157 * @param x pointer to the query parameter to pass
157 */ 158 */
158struct GNUNET_SQ_QueryParam 159struct GNUNET_SQ_QueryParam
159GNUNET_SQ_query_param_absolute_time_nbo (const struct 160GNUNET_SQ_query_param_absolute_time_nbo (
160 GNUNET_TIME_AbsoluteNBO *x); 161 const struct GNUNET_TIME_AbsoluteNBO *x);
161 162
162 163
163/** 164/**
@@ -194,7 +195,7 @@ GNUNET_SQ_query_param_uint64 (const uint64_t *x);
194 * @param params parameters to the statement 195 * @param params parameters to the statement
195 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 196 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
196 */ 197 */
197int 198enum GNUNET_GenericReturnValue
198GNUNET_SQ_bind (sqlite3_stmt *stmt, 199GNUNET_SQ_bind (sqlite3_stmt *stmt,
199 const struct GNUNET_SQ_QueryParam *params); 200 const struct GNUNET_SQ_QueryParam *params);
200 201
@@ -222,7 +223,7 @@ GNUNET_SQ_reset (sqlite3 *dbh,
222 * #GNUNET_YES if all results could be extracted 223 * #GNUNET_YES if all results could be extracted
223 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 224 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
224 */ 225 */
225typedef int 226typedef enum GNUNET_GenericReturnValue
226(*GNUNET_SQ_ResultConverter)(void *cls, 227(*GNUNET_SQ_ResultConverter)(void *cls,
227 sqlite3_stmt *result, 228 sqlite3_stmt *result,
228 unsigned int column, 229 unsigned int column,
@@ -436,7 +437,7 @@ GNUNET_SQ_result_spec_uint64 (uint64_t *u64);
436 * #GNUNET_OK if all results could be extracted 437 * #GNUNET_OK if all results could be extracted
437 * #GNUNET_SYSERR if a result was invalid (non-existing field) 438 * #GNUNET_SYSERR if a result was invalid (non-existing field)
438 */ 439 */
439int 440enum GNUNET_GenericReturnValue
440GNUNET_SQ_extract_result (sqlite3_stmt *result, 441GNUNET_SQ_extract_result (sqlite3_stmt *result,
441 struct GNUNET_SQ_ResultSpec *rs); 442 struct GNUNET_SQ_ResultSpec *rs);
442 443
@@ -498,7 +499,7 @@ GNUNET_SQ_make_prepare (const char *sql,
498 * @param ps array of statements to prepare 499 * @param ps array of statements to prepare
499 * @return #GNUNET_OK on success 500 * @return #GNUNET_OK on success
500 */ 501 */
501int 502enum GNUNET_GenericReturnValue
502GNUNET_SQ_prepare (sqlite3 *dbh, 503GNUNET_SQ_prepare (sqlite3 *dbh,
503 const struct GNUNET_SQ_PrepareStatement *ps); 504 const struct GNUNET_SQ_PrepareStatement *ps);
504 505
@@ -520,7 +521,7 @@ struct GNUNET_SQ_ExecuteStatement
520 /** 521 /**
521 * Should we ignore errors? 522 * Should we ignore errors?
522 */ 523 */
523 int ignore_errors; 524 bool ignore_errors;
524}; 525};
525 526
526 527
@@ -560,7 +561,7 @@ GNUNET_SQ_make_try_execute (const char *sql);
560 * @return #GNUNET_OK on success (modulo statements where errors can be ignored) 561 * @return #GNUNET_OK on success (modulo statements where errors can be ignored)
561 * #GNUNET_SYSERR on error 562 * #GNUNET_SYSERR on error
562 */ 563 */
563int 564enum GNUNET_GenericReturnValue
564GNUNET_SQ_exec_statements (sqlite3 *dbh, 565GNUNET_SQ_exec_statements (sqlite3 *dbh,
565 const struct GNUNET_SQ_ExecuteStatement *es); 566 const struct GNUNET_SQ_ExecuteStatement *es);
566 567
diff --git a/src/include/gnunet_statistics_service.h b/src/include/gnunet_statistics_service.h
index 20e958865..0fe09e69a 100644
--- a/src/include/gnunet_statistics_service.h
+++ b/src/include/gnunet_statistics_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Backbone
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -47,6 +50,7 @@ extern "C"
47#endif 50#endif
48#endif 51#endif
49 52
53
50#include "gnunet_util_lib.h" 54#include "gnunet_util_lib.h"
51 55
52/** 56/**
@@ -227,4 +231,6 @@ GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
227 231
228/** @} */ /* end of group statistics */ 232/** @} */ /* end of group statistics */
229 233
234/** @} */ /* end of group addition */
235
230#endif 236#endif
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h
index 977c2ead7..df70c5e8f 100644
--- a/src/include/gnunet_strings_lib.h
+++ b/src/include/gnunet_strings_lib.h
@@ -18,7 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup libgnunetutil
27 * Multi-function utilities library for GNUnet programs
28 * @{
29 *
22 * @author Christian Grothoff 30 * @author Christian Grothoff
23 * @author Krista Bennett 31 * @author Krista Bennett
24 * @author Gerd Knorr <kraxel@bytesex.org> 32 * @author Gerd Knorr <kraxel@bytesex.org>
@@ -33,6 +41,10 @@
33 * @{ 41 * @{
34 */ 42 */
35 43
44#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
45#error "Only <gnunet_util_lib.h> can be included directly."
46#endif
47
36#ifndef GNUNET_STRINGS_LIB_H 48#ifndef GNUNET_STRINGS_LIB_H
37#define GNUNET_STRINGS_LIB_H 49#define GNUNET_STRINGS_LIB_H
38 50
@@ -40,6 +52,7 @@
40 or unsigned long long, this IS platform dependent; 52 or unsigned long long, this IS platform dependent;
41 but "stdlib.h" should be portable 'enough' to be 53 but "stdlib.h" should be portable 'enough' to be
42 unconditionally available... */ 54 unconditionally available... */
55
43#include <stdlib.h> 56#include <stdlib.h>
44#include <sys/socket.h> 57#include <sys/socket.h>
45#include <netinet/in.h> 58#include <netinet/in.h>
@@ -63,7 +76,7 @@ extern "C"
63 * @param size set to the size in bytes 76 * @param size set to the size in bytes
64 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 77 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
65 */ 78 */
66int 79enum GNUNET_GenericReturnValue
67GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, 80GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
68 unsigned long long *size); 81 unsigned long long *size);
69 82
@@ -76,7 +89,7 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
76 * @param rtime set to the relative time 89 * @param rtime set to the relative time
77 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 90 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
78 */ 91 */
79int 92enum GNUNET_GenericReturnValue
80GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time, 93GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
81 struct GNUNET_TIME_Relative *rtime); 94 struct GNUNET_TIME_Relative *rtime);
82 95
@@ -91,12 +104,27 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
91 * @param atime set to the absolute time 104 * @param atime set to the absolute time
92 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 105 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
93 */ 106 */
94int 107enum GNUNET_GenericReturnValue
95GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time, 108GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
96 struct GNUNET_TIME_Absolute *atime); 109 struct GNUNET_TIME_Absolute *atime);
97 110
98 111
99/** 112/**
113 * @ingroup time
114 * Convert a given fancy human-readable time to our internal
115 * representation. The human-readable time is expected to be
116 * in local time, whereas the returned value will be in UTC.
117 *
118 * @param fancy_time human readable string (e.g. %Y-%m-%d %H:%M:%S)
119 * @param atime set to the absolute time
120 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
121 */
122enum GNUNET_GenericReturnValue
123GNUNET_STRINGS_fancy_time_to_timestamp (const char *fancy_time,
124 struct GNUNET_TIME_Timestamp *atime);
125
126
127/**
100 * Convert a given filesize into a fancy human-readable format. 128 * Convert a given filesize into a fancy human-readable format.
101 * 129 *
102 * @param size number of bytes 130 * @param size number of bytes
@@ -143,6 +171,16 @@ GNUNET_STRINGS_to_utf8 (const char *input,
143 171
144 172
145/** 173/**
174 * Normalize the utf-8 input string to NFC.
175 *
176 * @param input input string
177 * @return result (freshly allocated) or NULL on error.
178 */
179char*
180GNUNET_STRINGS_utf8_normalize (const char *input);
181
182
183/**
146 * Convert the len bytes-long UTF-8 string 184 * Convert the len bytes-long UTF-8 string
147 * given in input to the given charset. 185 * given in input to the given charset.
148 * 186 *
@@ -165,8 +203,9 @@ GNUNET_STRINGS_from_utf8 (const char *input,
165 * 203 *
166 * @param input input string 204 * @param input input string
167 * @param output output buffer 205 * @param output output buffer
206 * @return GNUNET_OK on success
168 */ 207 */
169void 208enum GNUNET_GenericReturnValue
170GNUNET_STRINGS_utf8_tolower (const char *input, 209GNUNET_STRINGS_utf8_tolower (const char *input,
171 char *output); 210 char *output);
172 211
@@ -177,8 +216,9 @@ GNUNET_STRINGS_utf8_tolower (const char *input,
177 * 216 *
178 * @param input input string 217 * @param input input string
179 * @param output output buffer 218 * @param output output buffer
219 * @return #GNUNET_OK on success
180 */ 220 */
181void 221enum GNUNET_GenericReturnValue
182GNUNET_STRINGS_utf8_toupper (const char *input, 222GNUNET_STRINGS_utf8_toupper (const char *input,
183 char *output); 223 char *output);
184 224
@@ -370,15 +410,19 @@ GNUNET_STRINGS_base64_encode (const void *in,
370/** 410/**
371 * url/percent encode (RFC3986). 411 * url/percent encode (RFC3986).
372 * 412 *
413 * FIXME: awkward API, @a len is not actually used
414 * @a out is 0-terminated, should probably be changed
415 * to only input @a data and directly return @out or NULL.
416 *
373 * @param data the data to decode 417 * @param data the data to decode
374 * @param len the length of the input 418 * @param len the length of the input
375 * @param output where to write the output (*output should be NULL, 419 * @param out where to write the output (*out should be NULL,
376 * is allocated) 420 * is allocated)
377 * @return the size of the output 421 * @return the size of the output
378 */ 422 */
379size_t 423size_t
380GNUNET_STRINGS_urlencode (const char *data, 424GNUNET_STRINGS_urlencode (size_t len,
381 size_t len, 425 const char data[static len],
382 char **out); 426 char **out);
383 427
384 428
@@ -417,7 +461,7 @@ GNUNET_STRINGS_base64_decode (const char *data,
417 * 461 *
418 * @param data the data to decode 462 * @param data the data to decode
419 * @param len the length of the input 463 * @param len the length of the input
420 * @param output where to write the output (*output should be NULL, 464 * @param out where to write the output (*out should be NULL,
421 * is allocated) 465 * is allocated)
422 * @return the size of the output 466 * @return the size of the output
423 */ 467 */
@@ -431,7 +475,7 @@ GNUNET_STRINGS_base64url_decode (const char *data,
431 * 475 *
432 * @param data the data to encode 476 * @param data the data to encode
433 * @param len the length of the input 477 * @param len the length of the input
434 * @param output where to write the output (*output should be NULL, 478 * @param[out] out where to write the output (*output should be NULL,
435 * is allocated) 479 * is allocated)
436 * @return the size of the output 480 * @return the size of the output
437 */ 481 */
@@ -442,18 +486,6 @@ GNUNET_STRINGS_urldecode (const char *data,
442 486
443 487
444/** 488/**
445 * Convert a peer path to a human-readable string.
446 *
447 * @param pids array of PIDs to convert to a string
448 * @param num_pids length of the @a pids array
449 * @return string representing the array of @a pids
450 */
451char *
452GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids,
453 unsigned int num_pids);
454
455
456/**
457 * Parse a path that might be an URI. 489 * Parse a path that might be an URI.
458 * 490 *
459 * @param path path to parse. Must be NULL-terminated. 491 * @param path path to parse. Must be NULL-terminated.
@@ -550,7 +582,7 @@ GNUNET_STRINGS_check_filename (const char *filename,
550 */ 582 */
551enum GNUNET_GenericReturnValue 583enum GNUNET_GenericReturnValue
552GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, 584GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
553 uint16_t addrlen, 585 size_t addrlen,
554 struct sockaddr_in6 *r_buf); 586 struct sockaddr_in6 *r_buf);
555 587
556 588
@@ -566,7 +598,7 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
566 */ 598 */
567enum GNUNET_GenericReturnValue 599enum GNUNET_GenericReturnValue
568GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, 600GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
569 uint16_t addrlen, 601 size_t addrlen,
570 struct sockaddr_in *r_buf); 602 struct sockaddr_in *r_buf);
571 603
572 604
@@ -642,6 +674,23 @@ GNUNET_strlcpy (char *dst,
642 size_t n); 674 size_t n);
643 675
644 676
677/**
678 * Sometimes we use the binary name to determine which specific
679 * test to run. In those cases, the string after the last "_"
680 * in 'argv[0]' specifies a string that determines the configuration
681 * file or plugin to use.
682 *
683 * This function returns the respective substring, taking care
684 * of issues such as binaries ending in '.exe' on W32.
685 *
686 * @param argv0 the name of the binary
687 * @return string between the last '_' and the '.exe' (or the end of the string),
688 * NULL if argv0 has no '_'
689 */
690char *
691GNUNET_STRINGS_get_suffix_from_binary_name (const char *argv0);
692
693
645/* ***************** IPv4/IPv6 parsing ****************** */ 694/* ***************** IPv4/IPv6 parsing ****************** */
646 695
647struct GNUNET_STRINGS_PortPolicy 696struct GNUNET_STRINGS_PortPolicy
@@ -750,4 +799,6 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX);
750 799
751/** @} */ /* end of group */ 800/** @} */ /* end of group */
752 801
802/** @} */ /* end of group addition */
803
753/* end of gnunet_util_string.h */ 804/* end of gnunet_util_string.h */
diff --git a/src/include/gnunet_testbed_lib.h b/src/include/gnunet_testbed_lib.h
new file mode 100644
index 000000000..e33f31ee1
--- /dev/null
+++ b/src/include/gnunet_testbed_lib.h
@@ -0,0 +1,130 @@
1#ifndef GNUNET_TESTBED_LIB_H
2#define GNUNET_TESTBED_LIB_H
3
4/**
5 * FIXME.
6 */
7struct GNUNET_TESTBED_System;
8
9#define GNUNET_TESTBED_PREFIX "GNUNET_TESTBED_PREFIX"
10
11/**
12 * Create a system handle. There must only be one system
13 * handle per operating system.
14 *
15 * @param testdir only the directory name without any path. This is used for
16 * all service homes; the directory will be created in a temporary
17 * location depending on the underlying OS. This variable will be
18 * overridden with the value of the environmental variable
19 * GNUNET_TESTBED_PREFIX, if it exists.
20 * @param trusted_ip the ip address which will be set as TRUSTED HOST in all
21 * service configurations generated to allow control connections from
22 * this ip. This can either be a single ip address or a network address
23 * in CIDR notation.
24 * @param hostname the hostname of the system we are using for testing; NULL for
25 * localhost
26 * @param lowport lowest port number this system is allowed to allocate (inclusive)
27 * @param highport highest port number this system is allowed to allocate (exclusive)
28 * @return handle to this system, NULL on error
29 */
30struct GNUNET_TESTBED_System *
31GNUNET_TESTBED_system_create_with_portrange (
32 const char *testdir,
33 const char *trusted_ip,
34 const char *hostname,
35 uint16_t lowport,
36 uint16_t highport);
37
38
39/**
40 * Create a system handle. There must only be one system handle per operating
41 * system. Uses a default range for allowed ports. Ports are still tested for
42 * availability.
43 *
44 * @param testdir only the directory name without any path. This is used for all
45 * service homes; the directory will be created in a temporary location
46 * depending on the underlying OS. This variable will be
47 * overridden with the value of the environmental variable
48 * GNUNET_TESTBED_PREFIX, if it exists.
49 * @param trusted_ip the ip address which will be set as TRUSTED HOST in all
50 * service configurations generated to allow control connections from
51 * this ip. This can either be a single ip address or a network address
52 * in CIDR notation.
53 * @param hostname the hostname of the system we are using for testing; NULL for
54 * localhost
55 * @param shared_services NULL terminated array describing services that are to
56 * be shared among peers
57 * @return handle to this system, NULL on error
58 */
59struct GNUNET_TESTBED_System *
60GNUNET_TESTBED_system_create (
61 const char *testdir,
62 const char *trusted_ip,
63 const char *hostname);
64
65
66/**
67 * Free system resources.
68 *
69 * @param system system to be freed
70 * @param remove_paths should the 'testdir' and all subdirectories
71 * be removed (clean up on shutdown)?
72 */
73void
74GNUNET_TESTBED_system_destroy (
75 struct GNUNET_TESTBED_System *system,
76 bool remove_paths);
77
78
79/**
80 * Reserve a TCP or UDP port for a peer.
81 *
82 * @param system system to use for reservation tracking
83 * @return 0 if no free port was available
84 */
85uint16_t
86GNUNET_TESTBED_reserve_port (
87 struct GNUNET_TESTBED_System *system);
88
89
90/**
91 * Release reservation of a TCP or UDP port for a peer
92 * (used during #GNUNET_TESTBED_peer_destroy()).
93 *
94 * @param system system to use for reservation tracking
95 * @param port reserved port to release
96 */
97void
98GNUNET_TESTBED_release_port (
99 struct GNUNET_TESTBED_System *system,
100 uint16_t port);
101
102
103/**
104 * Create a new configuration using the given configuration as a template;
105 * ports and paths will be modified to select available ports on the local
106 * system. The default configuration will be available in PATHS section under
107 * the option DEFAULTCONFIG after the call. GNUNET_HOME is also set in PATHS
108 * section to the temporary directory specific to this configuration. If we run
109 * out of "*port" numbers, return #GNUNET_SYSERR.
110 *
111 * This is primarily a helper function used internally
112 * by 'GNUNET_TESTBED_peer_configure'.
113 *
114 * @param system system to use to coordinate resource usage
115 * @param cfg template configuration to update
116 * @param ports array with port numbers used in the created configuration.
117 * Will be updated upon successful return. Can be NULL
118 * @param nports the size of the `ports' array. Will be updated.
119 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - the configuration will
120 * be incomplete and should not be used there upon
121 */
122enum GNUNET_GenericReturnValue
123GNUNET_TESTBED_configuration_create (
124 struct GNUNET_TESTBED_System *system,
125 struct GNUNET_CONFIGURATION_Handle *cfg,
126 uint16_t **ports,
127 unsigned int *nports);
128
129
130#endif
diff --git a/src/include/gnunet_testbed_logger_service.h b/src/include/gnunet_testbed_logger_service.h
deleted file mode 100644
index 72b5ab364..000000000
--- a/src/include/gnunet_testbed_logger_service.h
+++ /dev/null
@@ -1,133 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2008--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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
23 *
24 * @file
25 * API for submitting data to the testbed logger service
26 *
27 * @defgroup testbed-logger Testbed Logger service
28 * Submit data to the testbed logger service.
29 * @{
30 */
31
32#ifndef GNUNET_TESTBED_LOGGER_SERVICE_H
33#define GNUNET_TESTBED_LOGGER_SERVICE_H
34
35#ifdef __cplusplus
36extern "C"
37{
38#if 0 /* keep Emacsens' auto-indent happy */
39}
40#endif
41#endif
42
43#include "gnunet_util_lib.h"
44
45/**
46 * Opaque handle for the logging service
47 */
48struct GNUNET_TESTBED_LOGGER_Handle;
49
50
51/**
52 * Connect to the testbed logger service
53 *
54 * @param cfg configuration to use
55 * @return the handle which can be used for sending data to the service; NULL
56 * upon any error
57 */
58struct GNUNET_TESTBED_LOGGER_Handle *
59GNUNET_TESTBED_LOGGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
60
61
62/**
63 * Disconnect from the logger service. Also cancels any pending send handles.
64 *
65 * @param h the logger handle
66 */
67void
68GNUNET_TESTBED_LOGGER_disconnect (struct GNUNET_TESTBED_LOGGER_Handle *h);
69
70
71/**
72 * Functions of this type are called to notify a successful transmission of the
73 * message to the logger service.
74 *
75 * @param cls the closure given to GNUNET_TESTBED_LOGGER_send()
76 * @param size the amount of data sent
77 */
78typedef void
79(*GNUNET_TESTBED_LOGGER_FlushCompletion) (void *cls,
80 size_t size);
81
82
83/**
84 * Send data to be logged to the logger service. The data will be buffered and
85 * will be sent upon an explicit call to GNUNET_TESTBED_LOGGER_flush() or upon
86 * exceeding a threshold size.
87 *
88 * @param h the logger handle
89 * @param data the data to send;
90 * @param size how many bytes of @a data to send
91 */
92void
93GNUNET_TESTBED_LOGGER_write (struct GNUNET_TESTBED_LOGGER_Handle *h,
94 const void *data,
95 size_t size);
96
97
98/**
99 * Flush the buffered data to the logger service
100 *
101 * @param h the logger handle
102 * @param cb the callback to call after the data is flushed
103 * @param cb_cls the closure for @a cb
104 */
105void
106GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h,
107 GNUNET_TESTBED_LOGGER_FlushCompletion cb,
108 void *cb_cls);
109
110
111/**
112 * Cancel notification upon flush. Should only be used when the flush
113 * completion callback given to GNUNET_TESTBED_LOGGER_flush() is not already
114 * called.
115 *
116 * @param h the logger handle
117 */
118void
119GNUNET_TESTBED_LOGGER_flush_cancel (struct GNUNET_TESTBED_LOGGER_Handle *h);
120
121
122#if 0 /* keep Emacsens' auto-indent happy */
123{
124#endif
125#ifdef __cplusplus
126}
127#endif
128
129#endif /* GNUNET_TESTBED_LOGGER_SERVICE_H */
130
131/** @} */ /* end of group */
132
133/* End of gnunet_testbed_logger_service.h */
diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h
deleted file mode 100644
index 888c6e391..000000000
--- a/src/include/gnunet_testbed_service.h
+++ /dev/null
@@ -1,1729 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2008--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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 *
24 * @file
25 * API for writing tests and creating large-scale emulation testbeds for GNUnet.
26 *
27 * @defgroup testbed Testbed service
28 * Writing tests and creating large-scale emulation testbeds for GNUnet.
29 *
30 * @see [Documentation](https://docs.gnunet.org/handbook/gnunet.html#TESTBED-Subsystem)
31 *
32 * @{
33 */
34
35#ifndef GNUNET_TESTBED_SERVICE_H
36#define GNUNET_TESTBED_SERVICE_H
37
38#include "gnunet_util_lib.h"
39#include "gnunet_testing_lib.h"
40
41#ifdef __cplusplus
42extern "C"
43{
44#if 0 /* keep Emacsens' auto-indent happy */
45}
46#endif
47#endif
48
49
50/**
51 * Opaque handle to a host running experiments managed by the testbed framework.
52 * The master process must be able to SSH to this host without password (via
53 * ssh-agent).
54 */
55struct GNUNET_TESTBED_Host;
56
57/**
58 * Opaque handle to a peer controlled by the testbed framework. A peer runs
59 * at a particular host.
60 */
61struct GNUNET_TESTBED_Peer;
62
63/**
64 * Opaque handle to an abstract operation to be executed by the testbed framework.
65 */
66struct GNUNET_TESTBED_Operation;
67
68/**
69 * Handle to interact with a GNUnet testbed controller. Each
70 * controller has at least one master handle which is created when the
71 * controller is created; this master handle interacts with the
72 * controller process, destroying it destroys the controller (by
73 * closing stdin of the controller process). Additionally,
74 * controllers can interact with each other (in a P2P fashion); those
75 * links are established via TCP/IP on the controller's service port.
76 */
77struct GNUNET_TESTBED_Controller;
78
79
80/**
81 * Create a host to run peers and controllers on.
82 *
83 * @param hostname name of the host, use "NULL" for localhost
84 * @param username username to use for the login; may be NULL
85 * @param cfg the configuration to use as a template while starting a controller
86 * on this host. Operation queue sizes specific to a host are also
87 * read from this configuration handle
88 * @param port port number to use for ssh; use 0 to let ssh decide
89 * @return handle to the host, NULL on error
90 */
91struct GNUNET_TESTBED_Host *
92GNUNET_TESTBED_host_create (const char *hostname,
93 const char *username,
94 const struct GNUNET_CONFIGURATION_Handle *cfg,
95 uint16_t port);
96
97
98/**
99 * Create a host to run peers and controllers on. This function is used
100 * if a peer learns about a host via IPC between controllers (and thus
101 * some higher-level controller has already determined the unique IDs).
102 *
103 * @param id global host ID assigned to the host; 0 is
104 * reserved to always mean 'localhost'
105 * @param hostname name of the host, use "NULL" for localhost
106 * @param username username to use for the login; may be NULL
107 * @param cfg the configuration to use as a template while starting a controller
108 * on this host. Operation queue sizes specific to a host are also
109 * read from this configuration handle
110 * @param port port number to use for ssh; use 0 to let ssh decide
111 * @return handle to the host, NULL on error
112 */
113struct GNUNET_TESTBED_Host *
114GNUNET_TESTBED_host_create_with_id (uint32_t id,
115 const char *hostname,
116 const char *username,
117 const struct GNUNET_CONFIGURATION_Handle
118 *cfg,
119 uint16_t port);
120
121
122/**
123 * Load a set of hosts from a configuration file. The hostfile format is
124 * specified at https://gnunet.org/content/hosts-file-format
125 *
126 * @param filename file with the host specification
127 * @param cfg the configuration to use as a template while starting a controller
128 * on any of the loaded hosts. Operation queue sizes specific to a host
129 * are also read from this configuration handle
130 * @param hosts set to the hosts found in the file; caller must free this if
131 * number of hosts returned is greater than 0
132 * @return number of hosts returned in 'hosts', 0 on error
133 */
134unsigned int
135GNUNET_TESTBED_hosts_load_from_file (const char *filename,
136 const struct GNUNET_CONFIGURATION_Handle
137 *cfg,
138 struct GNUNET_TESTBED_Host ***hosts);
139
140
141/**
142 * Destroy a host handle. Must only be called once everything
143 * running on that host has been stopped.
144 *
145 * @param host handle to destroy
146 */
147void
148GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host);
149
150
151/**
152 * The handle for whether a host is habitable or not
153 */
154struct GNUNET_TESTBED_HostHabitableCheckHandle;
155
156
157/**
158 * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to
159 * inform whether the given host is habitable or not. The Handle returned by
160 * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called
161 *
162 * @param cls the closure given to GNUNET_TESTBED_is_host_habitable()
163 * @param host the host whose status is being reported; will be NULL if the host
164 * given to GNUNET_TESTBED_is_host_habitable() is NULL
165 * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
166 */
167typedef void
168(*GNUNET_TESTBED_HostHabitableCallback) (void *cls,
169 const struct GNUNET_TESTBED_Host *host,
170 int status);
171
172
173/**
174 * Checks whether a host can be used to start testbed service
175 *
176 * @param host the host to check
177 * @param config the configuration handle to lookup the path of the testbed
178 * helper
179 * @param cb the callback to call to inform about habitability of the given host
180 * @param cb_cls the closure for the callback
181 * @return NULL upon any error or a handle which can be passed to
182 * GNUNET_TESTBED_is_host_habitable_cancel()
183 */
184struct GNUNET_TESTBED_HostHabitableCheckHandle *
185GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
186 const struct GNUNET_CONFIGURATION_Handle
187 *config,
188 GNUNET_TESTBED_HostHabitableCallback cb,
189 void *cb_cls);
190
191
192/**
193 * Function to cancel a request started using GNUNET_TESTBED_is_host_habitable()
194 *
195 * @param handle the habitability check handle
196 */
197void
198GNUNET_TESTBED_is_host_habitable_cancel (struct
199 GNUNET_TESTBED_HostHabitableCheckHandle
200 *handle);
201
202/**
203 * Obtain the host's hostname.
204 *
205 * @param host handle to the host, NULL means 'localhost'
206 * @return hostname of the host
207 */
208const char *
209GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host);
210
211
212/**
213 * Enumeration with (at most 64) possible event types that
214 * can be monitored using the testbed framework.
215 */
216enum GNUNET_TESTBED_EventType
217{
218 /**
219 * A peer has been started.
220 */
221 GNUNET_TESTBED_ET_PEER_START = 0,
222
223 /**
224 * A peer has been stopped.
225 */
226 GNUNET_TESTBED_ET_PEER_STOP = 1,
227
228 /**
229 * A connection between two peers was established.
230 */
231 GNUNET_TESTBED_ET_CONNECT = 2,
232
233 /**
234 * A connection between two peers was torn down.
235 */
236 GNUNET_TESTBED_ET_DISCONNECT = 3,
237
238 /**
239 * A requested testbed operation has been completed.
240 */
241 GNUNET_TESTBED_ET_OPERATION_FINISHED = 4,
242};
243
244
245/**
246 * Types of information that can be requested about a peer.
247 */
248enum GNUNET_TESTBED_PeerInformationType
249{
250 /**
251 * Special value (not valid for requesting information)
252 * that is used in the event struct if a 'generic' pointer
253 * is returned (for other operations not related to this
254 * enumeration).
255 */
256 GNUNET_TESTBED_PIT_GENERIC = 0,
257
258 /**
259 * What configuration is the peer using? Returns a 'const struct
260 * GNUNET_CONFIGURATION_Handle *'. Valid until
261 * 'GNUNET_TESTNIG_operation_done' is called. However, the
262 * values may be inaccurate if the peer is reconfigured in
263 * the meantime.
264 */
265 GNUNET_TESTBED_PIT_CONFIGURATION,
266
267 /**
268 * What is the identity of the peer? Returns a
269 * 'const struct GNUNET_PeerIdentity *'. Valid until
270 * 'GNUNET_TESTNIG_operation_done' is called.
271 */
272 GNUNET_TESTBED_PIT_IDENTITY
273};
274
275
276/**
277 * Argument to GNUNET_TESTBED_ControllerCallback with details about
278 * the event.
279 */
280struct GNUNET_TESTBED_EventInformation
281{
282 /**
283 * Type of the event.
284 */
285 enum GNUNET_TESTBED_EventType type;
286
287 /**
288 * Handle for the corresponding operation that generated this event
289 */
290 struct GNUNET_TESTBED_Operation *op;
291
292 /**
293 * Closure given while creating the above operation
294 */
295 void *op_cls;
296
297 /**
298 * Details about the event.
299 */
300 union
301 {
302 /**
303 * Details about peer start event.
304 */
305 struct
306 {
307 /**
308 * Handle for the host where the peer
309 * was started.
310 */
311 struct GNUNET_TESTBED_Host *host;
312
313 /**
314 * Handle for the peer that was started.
315 */
316 struct GNUNET_TESTBED_Peer *peer;
317 } peer_start;
318
319 /**
320 * Details about peer stop event.
321 */
322 struct
323 {
324 /**
325 * Handle for the peer that was started.
326 */
327 struct GNUNET_TESTBED_Peer *peer;
328 } peer_stop;
329
330 /**
331 * Details about connect event.
332 */
333 struct
334 {
335 /**
336 * Handle for one of the connected peers.
337 */
338 struct GNUNET_TESTBED_Peer *peer1;
339
340 /**
341 * Handle for one of the connected peers.
342 */
343 struct GNUNET_TESTBED_Peer *peer2;
344 } peer_connect;
345
346 /**
347 * Details about disconnect event.
348 */
349 struct
350 {
351 /**
352 * Handle for one of the disconnected peers.
353 */
354 struct GNUNET_TESTBED_Peer *peer1;
355
356 /**
357 * Handle for one of the disconnected peers.
358 */
359 struct GNUNET_TESTBED_Peer *peer2;
360 } peer_disconnect;
361
362 /**
363 * Details about an operation finished event.
364 */
365 struct
366 {
367 /**
368 * Error message for the operation, NULL on success.
369 */
370 const char *emsg;
371
372 /**
373 * No result (NULL pointer) or generic result
374 * (whatever the GNUNET_TESTBED_ConnectAdapter returned).
375 */
376 void *generic;
377 } operation_finished;
378 } details;
379};
380
381
382/**
383 * Signature of the event handler function called by the
384 * respective event controller.
385 *
386 * @param cls closure
387 * @param event information about the event
388 */
389typedef void
390(*GNUNET_TESTBED_ControllerCallback)(void *cls,
391 const struct
392 GNUNET_TESTBED_EventInformation *event);
393
394
395/**
396 * Opaque Handle for Controller process
397 */
398struct GNUNET_TESTBED_ControllerProc;
399
400
401/**
402 * Callback to signal successful startup of the controller process
403 *
404 * @param cls the closure from GNUNET_TESTBED_controller_start()
405 * @param cfg the configuration with which the controller has been started;
406 * NULL if status is not #GNUNET_OK
407 * @param status #GNUNET_OK if the startup is successful; #GNUNET_SYSERR if not,
408 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
409 */
410typedef void
411(*GNUNET_TESTBED_ControllerStatusCallback) (void *cls,
412 const struct
413 GNUNET_CONFIGURATION_Handle *cfg,
414 int status);
415
416
417/**
418 * Starts a controller process at the given host. The given host's configuration
419 * is used as a Template configuration to use for the remote controller; the
420 * remote controller will be started with a slightly modified configuration
421 * (port numbers, unix domain sockets and service home values are changed as per
422 * TESTING library on the remote host). The modified configuration replaces the
423 * host's existing configuration before signalling success through the
424 * GNUNET_TESTBED_ControllerStatusCallback()
425 *
426 * @param trusted_ip the ip address of the controller which will be set as TRUSTED
427 * HOST(all connections form this ip are permitted by the testbed) when
428 * starting testbed controller at host. This can either be a single ip
429 * address or a network address in CIDR notation.
430 * @param host the host where the controller has to be started. CANNOT be NULL.
431 * @param cb function called when the controller is successfully started or
432 * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
433 * called if cb is called with GNUNET_SYSERR as status. Will never be
434 * called in the same task as 'GNUNET_TESTBED_controller_start'
435 * (synchronous errors will be signalled by returning NULL). This
436 * parameter cannot be NULL.
437 * @param cls closure for above callbacks
438 * @return the controller process handle, NULL on errors
439 */
440struct GNUNET_TESTBED_ControllerProc *
441GNUNET_TESTBED_controller_start (const char *trusted_ip,
442 struct GNUNET_TESTBED_Host *host,
443 GNUNET_TESTBED_ControllerStatusCallback cb,
444 void *cls);
445
446
447/**
448 * Stop the controller process (also will terminate all peers and controllers
449 * dependent on this controller). This function blocks until the testbed has
450 * been fully terminated (!). The controller status cb from
451 * GNUNET_TESTBED_controller_start() will not be called.
452 *
453 * @param cproc the controller process handle
454 */
455void
456GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc);
457
458
459/**
460 * Connect to a controller process. The configuration to use for the connection
461 * is retrieved from the given host where a controller is started using
462 * GNUNET_TESTBED_controller_start().
463 *
464 * @param host host to run the controller on; This should be the same host if
465 * the controller was previously started with
466 * GNUNET_TESTBED_controller_start()
467 * @param event_mask bit mask with set of events to call 'cc' for;
468 * or-ed values of "1LL" shifted by the
469 * respective 'enum GNUNET_TESTBED_EventType'
470 * (e.g. "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...")
471 * @param cc controller callback to invoke on events
472 * @param cc_cls closure for cc
473 * @return handle to the controller
474 */
475struct GNUNET_TESTBED_Controller *
476GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
477 uint64_t event_mask,
478 GNUNET_TESTBED_ControllerCallback cc,
479 void *cc_cls);
480
481
482/**
483 * Stop the given controller (also will terminate all peers and
484 * controllers dependent on this controller). This function
485 * blocks until the testbed has been fully terminated (!).
486 *
487 * @param c handle to controller to stop
488 */
489void
490GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c);
491
492
493/**
494 * Opaque handle for host registration
495 */
496struct GNUNET_TESTBED_HostRegistrationHandle;
497
498
499/**
500 * Callback which will be called to after a host registration succeeded or failed
501 *
502 * @param cls the closure
503 * @param emsg the error message; NULL if host registration is successful
504 */
505typedef void
506(*GNUNET_TESTBED_HostRegistrationCompletion) (void *cls,
507 const char *emsg);
508
509
510/**
511 * Register a host with the controller. This makes the controller aware of the
512 * host. A host should be registered at the controller before starting a
513 * sub-controller on that host using GNUNET_TESTBED_controller_link().
514 *
515 * @param controller the controller handle
516 * @param host the host to register
517 * @param cc the completion callback to call to inform the status of
518 * registration. After calling this callback the registration handle
519 * will be invalid. Cannot be NULL
520 * @param cc_cls the closure for the cc
521 * @return handle to the host registration which can be used to cancel the
522 * registration; NULL if another registration handle is present and
523 * is not cancelled
524 */
525struct GNUNET_TESTBED_HostRegistrationHandle *
526GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
527 struct GNUNET_TESTBED_Host *host,
528 GNUNET_TESTBED_HostRegistrationCompletion cc,
529 void *cc_cls);
530
531
532/**
533 * Cancel the pending registration. Note that the registration message will
534 * already be queued to be sent to the service, cancellation has only the
535 * effect that the registration completion callback for the registration is
536 * never called and from our perspective the host is not registered until the
537 * completion callback is called.
538 *
539 * @param handle the registration handle to cancel
540 */
541void
542GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
543 *handle);
544
545
546/**
547 * Callback to be called when an operation is completed
548 *
549 * @param cls the callback closure from functions generating an operation
550 * @param op the operation that has been finished
551 * @param emsg error message in case the operation has failed; will be NULL if
552 * operation has executed successfully.
553 */
554typedef void
555(*GNUNET_TESTBED_OperationCompletionCallback) (void *cls,
556 struct GNUNET_TESTBED_Operation *
557 op,
558 const char *emsg);
559
560
561/**
562 * Create a link from slave controller to delegated controller. Whenever the
563 * master controller is asked to start a peer at the delegated controller the
564 * request will be routed towards slave controller (if a route exists). The
565 * slave controller will then route it to the delegated controller. The
566 * configuration of the delegated controller is given and is used to either
567 * create the delegated controller or to connect to an existing controller. Note
568 * that while starting the delegated controller the configuration will be
569 * modified to accommodate available free ports. the 'is_subordinate' specifies
570 * if the given delegated controller should be started and managed by the slave
571 * controller, or if the delegated controller already has a master and the slave
572 * controller connects to it as a non master controller. The success or failure
573 * of this operation will be signalled through the
574 * GNUNET_TESTBED_ControllerCallback() with an event of type
575 * #GNUNET_TESTBED_ET_OPERATION_FINISHED
576 *
577 * @param op_cls the operation closure for the event which is generated to
578 * signal success or failure of this operation
579 * @param master handle to the master controller who creates the association
580 * @param delegated_host requests to which host should be delegated; cannot be NULL
581 * @param slave_host which host is used to run the slave controller; use NULL to
582 * make the master controller connect to the delegated host
583 * @param is_subordinate #GNUNET_YES if the controller at delegated_host should
584 * be started by the slave controller; #GNUNET_NO if the slave
585 * controller has to connect to the already started delegated
586 * controller via TCP/IP
587 * @return the operation handle
588 */
589struct GNUNET_TESTBED_Operation *
590GNUNET_TESTBED_controller_link (void *op_cls,
591 struct GNUNET_TESTBED_Controller *master,
592 struct GNUNET_TESTBED_Host *delegated_host,
593 struct GNUNET_TESTBED_Host *slave_host,
594 int is_subordinate);
595
596
597/**
598 * Function to acquire the configuration of a running slave controller. The
599 * completion of the operation is signalled through the controller_cb from
600 * GNUNET_TESTBED_controller_connect(). If the operation is successful the
601 * handle to the configuration is available in the generic pointer of
602 * operation_finished field of `struct GNUNET_TESTBED_EventInformation`.
603 *
604 * @param op_cls the closure for the operation
605 * @param master the handle to master controller
606 * @param slave_host the host where the slave controller is running; the handle
607 * to the slave_host should remain valid until this operation is
608 * cancelled or marked as finished
609 * @return the operation handle; NULL if the slave_host is not registered at
610 * master
611 */
612struct GNUNET_TESTBED_Operation *
613GNUNET_TESTBED_get_slave_config (void *op_cls,
614 struct GNUNET_TESTBED_Controller *master,
615 struct GNUNET_TESTBED_Host *slave_host);
616
617
618/**
619 * Functions of this signature are called when a peer has been successfully
620 * created
621 *
622 * @param cls the closure from GNUNET_TESTBED_peer_create()
623 * @param peer the handle for the created peer; NULL on any error during
624 * creation
625 * @param emsg NULL if peer is not NULL; else MAY contain the error description
626 */
627typedef void
628(*GNUNET_TESTBED_PeerCreateCallback) (void *cls,
629 struct GNUNET_TESTBED_Peer *peer,
630 const char *emsg);
631
632
633/**
634 * Create the given peer at the specified host using the given
635 * controller. If the given controller is not running on the target
636 * host, it should find or create a controller at the target host and
637 * delegate creating the peer. Explicit delegation paths can be setup
638 * using 'GNUNET_TESTBED_controller_link'. If no explicit delegation
639 * path exists, a direct link with a subordinate controller is setup
640 * for the first delegated peer to a particular host; the subordinate
641 * controller is then destroyed once the last peer that was delegated
642 * to the remote host is stopped.
643 *
644 * Creating the peer only creates the handle to manipulate and further
645 * configure the peer; use #GNUNET_TESTBED_peer_start and
646 * #GNUNET_TESTBED_peer_stop to actually start/stop the peer's
647 * processes.
648 *
649 * Note that the given configuration will be adjusted by the
650 * controller to avoid port/path conflicts with other peers.
651 * The "final" configuration can be obtained using
652 * #GNUNET_TESTBED_peer_get_information.
653 *
654 * @param controller controller process to use
655 * @param host host to run the peer on; cannot be NULL
656 * @param cfg Template configuration to use for the peer. Should exist until
657 * operation is cancelled or GNUNET_TESTBED_operation_done() is called
658 * @param cb the callback to call when the peer has been created
659 * @param cls the closure to the above callback
660 * @return the operation handle
661 */
662struct GNUNET_TESTBED_Operation *
663GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
664 struct GNUNET_TESTBED_Host *host,
665 const struct GNUNET_CONFIGURATION_Handle *cfg,
666 GNUNET_TESTBED_PeerCreateCallback cb,
667 void *cls);
668
669
670/**
671 * Functions of this signature are called when a peer has been successfully
672 * started or stopped.
673 *
674 * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
675 * @param emsg NULL on success; otherwise an error description
676 */
677typedef void
678(*GNUNET_TESTBED_PeerChurnCallback) (void *cls,
679 const char *emsg);
680
681
682/**
683 * Start the given peer.
684 *
685 * @param op_cls the closure for this operation; will be set in the event
686 * information
687 * @param peer peer to start
688 * @param pcc function to call upon completion
689 * @param pcc_cls closure for 'pcc'
690 * @return handle to the operation
691 */
692struct GNUNET_TESTBED_Operation *
693GNUNET_TESTBED_peer_start (void *op_cls,
694 struct GNUNET_TESTBED_Peer *peer,
695 GNUNET_TESTBED_PeerChurnCallback pcc,
696 void *pcc_cls);
697
698
699/**
700 * Stop the given peer. The handle remains valid (use
701 * #GNUNET_TESTBED_peer_destroy to fully clean up the
702 * state of the peer).
703 *
704 * @param op_cls the closure for this operation; will be set in the event
705 * information
706 * @param peer peer to stop
707 * @param pcc function to call upon completion
708 * @param pcc_cls closure for 'pcc'
709 * @return handle to the operation
710 */
711struct GNUNET_TESTBED_Operation *
712GNUNET_TESTBED_peer_stop (void *op_cls,
713 struct GNUNET_TESTBED_Peer *peer,
714 GNUNET_TESTBED_PeerChurnCallback pcc,
715 void *pcc_cls);
716
717
718/**
719 * Data returned from GNUNET_TESTBED_peer_get_information
720 */
721struct GNUNET_TESTBED_PeerInformation
722{
723 /**
724 * Peer information type; captures which of the types
725 * in the 'op_result' is actually in use.
726 */
727 enum GNUNET_TESTBED_PeerInformationType pit;
728
729 /**
730 * The result of the get information operation; Choose according to the pit
731 */
732 union
733 {
734 /**
735 * The configuration of the peer
736 */
737 struct GNUNET_CONFIGURATION_Handle *cfg;
738
739 /**
740 * The identity of the peer
741 */
742 struct GNUNET_PeerIdentity *id;
743 } result;
744};
745
746
747/**
748 * Callback to be called when the requested peer information is available
749 * The peer information in the callback is valid until the operation 'op' is canceled.
750 *
751 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
752 * @param op the operation this callback corresponds to
753 * @param pinfo the result; will be NULL if the operation has failed
754 * @param emsg error message if the operation has failed; will be NULL if the
755 * operation is successful
756 */
757typedef void
758(*GNUNET_TESTBED_PeerInfoCallback) (void *cb_cls,
759 struct GNUNET_TESTBED_Operation *op,
760 const struct
761 GNUNET_TESTBED_PeerInformation *pinfo,
762 const char *emsg);
763
764
765/**
766 * Request information about a peer. The controller callback will not be called
767 * with event type #GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this
768 * operation is available. Instead, the GNUNET_TESTBED_PeerInfoCallback() will
769 * be called.
770 * The peer information in the callback is valid until the operation is canceled.
771 *
772 * @param peer peer to request information about
773 * @param pit desired information
774 * @param cb the convenience callback to be called when results for this
775 * operation are available
776 * @param cb_cls the closure for @a cb
777 * @return handle to the operation
778 */
779struct GNUNET_TESTBED_Operation *
780GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
781 enum GNUNET_TESTBED_PeerInformationType
782 pit,
783 GNUNET_TESTBED_PeerInfoCallback cb,
784 void *cb_cls);
785
786
787/**
788 * Change @a peer configuration. Ports and paths cannot be changed this
789 * way.
790 *
791 * @param peer peer to change configuration for
792 * @param cfg new configuration
793 * @return handle to the operation
794 */
795struct GNUNET_TESTBED_Operation *
796GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
797 const struct
798 GNUNET_CONFIGURATION_Handle *cfg);
799
800
801/**
802 * Destroy the given peer; the peer should have been
803 * stopped first (if it was started).
804 *
805 * @param peer peer to stop
806 * @return handle to the operation
807 */
808struct GNUNET_TESTBED_Operation *
809GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer);
810
811
812/**
813 * Start or stop given service at a peer. This should not be called to
814 * start/stop the peer's ARM service. Use GNUNET_TESTBED_peer_start(),
815 * GNUNET_TESTBED_peer_stop() for starting/stopping peer's ARM service. Success
816 * or failure of the generated operation is signalled through the controller
817 * event callback and/or operation completion callback.
818 *
819 * @param op_cls the closure for the operation
820 * @param peer the peer whose service is to be started/stopped
821 * @param service_name the name of the service
822 * @param cb the operation completion callback
823 * @param cb_cls the closure for @a cb
824 * @param start 1 to start the service; 0 to stop the service
825 * @return an operation handle; NULL upon error (peer not running)
826 */
827struct GNUNET_TESTBED_Operation *
828GNUNET_TESTBED_peer_manage_service (void *op_cls,
829 struct GNUNET_TESTBED_Peer *peer,
830 const char *service_name,
831 GNUNET_TESTBED_OperationCompletionCallback
832 cb,
833 void *cb_cls,
834 unsigned int start);
835
836
837/**
838 * Stops and destroys all peers. Is equivalent of calling
839 * GNUNET_TESTBED_peer_stop() and GNUNET_TESTBED_peer_destroy() on all peers,
840 * except that the peer stop event and operation finished event corresponding to
841 * the respective functions are not generated. This function should be called
842 * when there are no other pending operations. If there are pending operations,
843 * it will return NULL
844 *
845 * @param c the controller to send this message to
846 * @param op_cls closure for the operation
847 * @param cb the callback to call when all peers are stopped and destroyed
848 * @param cb_cls the closure for the callback
849 * @return operation handle on success; NULL if any pending operations are
850 * present
851 */
852struct GNUNET_TESTBED_Operation *
853GNUNET_TESTBED_shutdown_peers (struct GNUNET_TESTBED_Controller *c,
854 void *op_cls,
855 GNUNET_TESTBED_OperationCompletionCallback cb,
856 void *cb_cls);
857
858
859/**
860 * Options for peer connections.
861 */
862enum GNUNET_TESTBED_ConnectOption
863{
864 /**
865 * No option (not valid as an argument).
866 */
867 GNUNET_TESTBED_CO_NONE = 0,
868
869 /**
870 * Allow or disallow a connection between the specified peers.
871 * Followed by #GNUNET_NO (int) if a connection is disallowed
872 * or #GNUNET_YES if a connection is allowed. Note that the
873 * default (all connections allowed or disallowed) is
874 * specified in the configuration of the controller.
875 */
876 GNUNET_TESTBED_CO_ALLOW = 1,
877
878 /**
879 * FIXME: add (and implement) options to limit connection to
880 * particular transports, force simulation of particular latencies
881 * or message loss rates, or set bandwidth limitations.
882 */
883};
884
885
886/**
887 * Manipulate the P2P underlay topology by configuring a link
888 * between two peers.
889 *
890 * @param op_cls closure argument to give with the operation event
891 * @param p1 first peer
892 * @param p2 second peer
893 * @param co option to change
894 * @param ap option-specific values
895 * @return handle to the operation, NULL if configuring the link at this
896 * time is not allowed
897 */
898struct GNUNET_TESTBED_Operation *
899GNUNET_TESTBED_underlay_configure_link_va (void *op_cls,
900 struct GNUNET_TESTBED_Peer *p1,
901 struct GNUNET_TESTBED_Peer *p2,
902 enum GNUNET_TESTBED_ConnectOption co,
903 va_list ap);
904
905
906/**
907 * Manipulate the P2P underlay topology by configuring a link
908 * between two peers.
909 *
910 * @param op_cls closure argument to give with the operation event
911 * @param p1 first peer
912 * @param p2 second peer
913 * @param co option to change
914 * @param ... option-specific values
915 * @return handle to the operation, NULL if configuring the link at this
916 * time is not allowed
917 */
918struct GNUNET_TESTBED_Operation *
919GNUNET_TESTBED_underlay_configure_link (void *op_cls,
920 struct GNUNET_TESTBED_Peer *p1,
921 struct GNUNET_TESTBED_Peer *p2,
922 enum GNUNET_TESTBED_ConnectOption co,
923 ...);
924
925
926/**
927 * Topologies and topology options supported for testbeds. Options should always
928 * end with #GNUNET_TESTBED_TOPOLOGY_OPTION_END
929 */
930enum GNUNET_TESTBED_TopologyOption
931{
932 /**
933 * A clique (everyone connected to everyone else). No options. If there are N
934 * peers this topology results in (N * (N -1)) connections.
935 */
936 GNUNET_TESTBED_TOPOLOGY_CLIQUE,
937
938 /**
939 * Small-world network (2d torus plus random links). Followed
940 * by the number of random links to add (unsigned int).
941 */
942 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD,
943
944 /**
945 * Small-world network (ring plus random links). Followed
946 * by the number of random links to add (unsigned int).
947 */
948 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING,
949
950 /**
951 * Ring topology. No options.
952 */
953 GNUNET_TESTBED_TOPOLOGY_RING,
954
955 /**
956 * Star topology. No options.
957 */
958 GNUNET_TESTBED_TOPOLOGY_STAR,
959
960 /**
961 * 2-d torus. No options.
962 */
963 GNUNET_TESTBED_TOPOLOGY_2D_TORUS,
964
965 /**
966 * Random graph. Followed by the number of random links to be established
967 * (unsigned int)
968 */
969 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
970
971 /**
972 * Certain percentage of peers are unable to communicate directly
973 * replicating NAT conditions. Followed by the fraction of
974 * NAT'ed peers (float).
975 */
976 GNUNET_TESTBED_TOPOLOGY_INTERNAT,
977
978 /**
979 * Scale free topology. It is generated according to the method described in
980 * "Emergence of Scaling in Random Networks." Science 286, 509-512, 1999.
981 *
982 * This options takes two arguments in the following order: an uint16_t to
983 * determine the maximum number of edges a peer is permitted to have while
984 * generating scale free topology, a good value for this argument is 70; and
985 * an uint8_t to determine the number of edges to be established when adding a
986 * new node to the scale free network, a good value for this argument is 4.
987 */
988 GNUNET_TESTBED_TOPOLOGY_SCALE_FREE,
989
990 /**
991 * Straight line topology. No options.
992 */
993 GNUNET_TESTBED_TOPOLOGY_LINE,
994
995 /**
996 * Read a topology from a given file. Followed by the name of the file (const char *).
997 */
998 GNUNET_TESTBED_TOPOLOGY_FROM_FILE,
999
1000 /**
1001 * All peers are disconnected. No options.
1002 */
1003 GNUNET_TESTBED_TOPOLOGY_NONE,
1004
1005 /**
1006 * The options should always end with this
1007 */
1008 GNUNET_TESTBED_TOPOLOGY_OPTION_END,
1009
1010 /* The following are not topologies but influence how the topology has to be
1011 setup. These options should follow the topology specific options (if
1012 required by the chosen topology). Note that these should be given before
1013 GNUNET_TESTBED_TOPOLOGY_OPTION_END */
1014
1015 /**
1016 * How many times should the failed overlay connect operations be retried
1017 * before giving up. The default if this option is not specified is to retry
1018 * 3 times. This option takes and unsigned integer as a parameter. Use this
1019 * option with parameter 0 to disable retrying of failed overlay connect
1020 * operations.
1021 */
1022 GNUNET_TESTBED_TOPOLOGY_RETRY_CNT
1023};
1024
1025
1026/**
1027 * Configure overall network topology to have a particular shape.
1028 *
1029 * @param op_cls closure argument to give with the operation event
1030 * @param num_peers number of peers in 'peers'
1031 * @param peers array of 'num_peers' with the peers to configure
1032 * @param topo desired underlay topology to use
1033 * @param ap topology-specific options
1034 * @return handle to the operation, NULL if configuring the topology
1035 * is not allowed at this time
1036 */
1037struct GNUNET_TESTBED_Operation *
1038GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
1039 unsigned int num_peers,
1040 struct GNUNET_TESTBED_Peer **
1041 peers,
1042 enum
1043 GNUNET_TESTBED_TopologyOption
1044 topo,
1045 va_list ap);
1046
1047
1048/**
1049 * Configure overall network topology to have a particular shape.
1050 *
1051 * @param op_cls closure argument to give with the operation event
1052 * @param num_peers number of peers in 'peers'
1053 * @param peers array of 'num_peers' with the peers to configure
1054 * @param topo desired underlay topology to use
1055 * @param ... topology-specific options
1056 * @return handle to the operation, NULL if configuring the topology
1057 * is not allowed at this time
1058 */
1059struct GNUNET_TESTBED_Operation *
1060GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
1061 unsigned int num_peers,
1062 struct GNUNET_TESTBED_Peer **peers,
1063 enum GNUNET_TESTBED_TopologyOption
1064 topo,
1065 ...);
1066
1067
1068/**
1069 * Both peers must have been started before calling this function.
1070 * This function then obtains a HELLO from @a p1, gives it to @a p2
1071 * and asks @a p2 to connect to @a p1.
1072 *
1073 * @param op_cls closure argument to give with the operation event
1074 * @param cb the callback to call when this operation has finished
1075 * @param cb_cls the closure for @a cb
1076 * @param p1 first peer
1077 * @param p2 second peer
1078 * @return handle to the operation, NULL if connecting these two
1079 * peers is fundamentally not possible at this time (peers
1080 * not running or underlay disallows)
1081 */
1082struct GNUNET_TESTBED_Operation *
1083GNUNET_TESTBED_overlay_connect (void *op_cls,
1084 GNUNET_TESTBED_OperationCompletionCallback cb,
1085 void *cb_cls,
1086 struct GNUNET_TESTBED_Peer *p1,
1087 struct GNUNET_TESTBED_Peer *p2);
1088
1089
1090/**
1091 * Callbacks of this type are called when topology configuration is completed
1092 *
1093 * @param cls the operation closure given to
1094 * GNUNET_TESTBED_overlay_configure_topology_va() and
1095 * GNUNET_TESTBED_overlay_configure() calls
1096 * @param nsuccess the number of successful overlay connects
1097 * @param nfailures the number of overlay connects which failed
1098 */
1099typedef void (*GNUNET_TESTBED_TopologyCompletionCallback) (void *cls,
1100 unsigned int
1101 nsuccess,
1102 unsigned int
1103 nfailures);
1104
1105
1106/**
1107 * All peers must have been started before calling this function.
1108 * This function then connects the given peers in the P2P overlay
1109 * using the given topology.
1110 *
1111 * @param op_cls closure argument to give with the peer connect operation events
1112 * generated through this function
1113 * @param num_peers number of peers in 'peers'
1114 * @param peers array of 'num_peers' with the peers to configure
1115 * @param max_connections the maximums number of overlay connections that will
1116 * be made to achieve the given topology
1117 * @param comp_cb the completion callback to call when the topology generation
1118 * is completed
1119 * @param comp_cb_cls closure for the @a comp_cb
1120 * @param topo desired underlay topology to use
1121 * @param va topology-specific options
1122 * @return handle to the operation, NULL if connecting these
1123 * peers is fundamentally not possible at this time (peers
1124 * not running or underlay disallows) or if num_peers is less than 2
1125 */
1126struct GNUNET_TESTBED_Operation *
1127GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
1128 unsigned int num_peers,
1129 struct GNUNET_TESTBED_Peer **peers,
1130 unsigned int *max_connections,
1131 GNUNET_TESTBED_TopologyCompletionCallback
1132 comp_cb,
1133 void *comp_cb_cls,
1134 enum GNUNET_TESTBED_TopologyOption
1135 topo,
1136 va_list va);
1137
1138
1139/**
1140 * All peers must have been started before calling this function.
1141 * This function then connects the given peers in the P2P overlay
1142 * using the given topology.
1143 *
1144 * @param op_cls closure argument to give with the peer connect operation events
1145 * generated through this function
1146 * @param num_peers number of peers in 'peers'
1147 * @param peers array of 'num_peers' with the peers to configure
1148 * @param max_connections the maximums number of overlay connections that will
1149 * be made to achieve the given topology
1150 * @param comp_cb the completion callback to call when the topology generation
1151 * is completed
1152 * @param comp_cb_cls closure for the above completion callback
1153 * @param topo desired underlay topology to use
1154 * @param ... topology-specific options
1155 * @return handle to the operation, NULL if connecting these
1156 * peers is fundamentally not possible at this time (peers
1157 * not running or underlay disallows) or if num_peers is less than 2
1158 */
1159struct GNUNET_TESTBED_Operation *
1160GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
1161 unsigned int num_peers,
1162 struct GNUNET_TESTBED_Peer **peers,
1163 unsigned int *max_connections,
1164 GNUNET_TESTBED_TopologyCompletionCallback
1165 comp_cb,
1166 void *comp_cb_cls,
1167 enum GNUNET_TESTBED_TopologyOption
1168 topo,
1169 ...);
1170
1171
1172/**
1173 * Ask the testbed controller to write the current overlay topology to
1174 * a file. Naturally, the file will only contain a snapshot as the
1175 * topology may evolve all the time.
1176 * FIXME: needs continuation!?
1177 *
1178 * @param controller overlay controller to inspect
1179 * @param filename name of the file the topology should
1180 * be written to.
1181 */
1182void
1183GNUNET_TESTBED_overlay_write_topology_to_file (struct
1184 GNUNET_TESTBED_Controller *
1185 controller,
1186 const char *filename);
1187
1188
1189/**
1190 * Adapter function called to establish a connection to
1191 * a service.
1192 *
1193 * @param cls closure
1194 * @param cfg configuration of the peer to connect to; will be available until
1195 * GNUNET_TESTBED_operation_done() is called on the operation returned
1196 * from GNUNET_TESTBED_service_connect()
1197 * @return service handle to return in 'op_result', NULL on error
1198 */
1199typedef void *
1200(*GNUNET_TESTBED_ConnectAdapter)(void *cls,
1201 const struct GNUNET_CONFIGURATION_Handle *cfg);
1202
1203
1204/**
1205 * Adapter function called to destroy a connection to
1206 * a service.
1207 *
1208 * @param cls closure
1209 * @param op_result service handle returned from the connect adapter
1210 */
1211typedef void
1212(*GNUNET_TESTBED_DisconnectAdapter)(void *cls,
1213 void *op_result);
1214
1215
1216/**
1217 * Callback to be called when a service connect operation is completed
1218 *
1219 * @param cls the callback closure from functions generating an operation
1220 * @param op the operation that has been finished
1221 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
1222 * @param emsg error message in case the operation has failed; will be NULL if
1223 * operation has executed successfully.
1224 */
1225typedef void
1226(*GNUNET_TESTBED_ServiceConnectCompletionCallback) (void *cls,
1227 struct
1228 GNUNET_TESTBED_Operation *op,
1229 void *ca_result,
1230 const char *emsg);
1231
1232
1233/**
1234 * Connect to a service offered by the given peer. Will ensure that
1235 * the request is queued to not overwhelm our ability to create and
1236 * maintain connections with other systems. The actual service
1237 * handle is then returned via the 'op_result' member in the event
1238 * callback. The @a ca callback is used to create the connection
1239 * when the time is right; the @a da callback will be used to
1240 * destroy the connection (upon #GNUNET_TESTBED_operation_done).
1241 * #GNUNET_TESTBED_operation_done can be used to abort this
1242 * operation until the event callback has been called.
1243 *
1244 * @param op_cls closure to pass in operation event // FIXME: didn't we say we'd no longer use the global callback for these? -CG
1245 * @param peer peer that runs the service
1246 * @param service_name name of the service to connect to
1247 * @param cb the callback to call when this operation is ready (that is,
1248 * right after the connect adapter returns)
1249 * @param cb_cls closure for @a cb
1250 * @param ca helper function to establish the connection
1251 * @param da helper function to close the connection
1252 * @param cada_cls closure for @a ca and @a da
1253 * @return handle for the operation
1254 */
1255struct GNUNET_TESTBED_Operation *
1256GNUNET_TESTBED_service_connect (void *op_cls,
1257 struct GNUNET_TESTBED_Peer *peer,
1258 const char *service_name,
1259 GNUNET_TESTBED_ServiceConnectCompletionCallback
1260 cb,
1261 void *cb_cls,
1262 GNUNET_TESTBED_ConnectAdapter ca,
1263 GNUNET_TESTBED_DisconnectAdapter da,
1264 void *cada_cls);
1265
1266
1267/**
1268 * This function is used to signal that the event information (struct
1269 * GNUNET_TESTBED_EventInformation) from an operation has been fully processed
1270 * i.e. if the event callback is ever called for this operation. If the event
1271 * callback for this operation has not yet been called, calling this function
1272 * cancels the operation, frees its resources and ensures the no event is
1273 * generated with respect to this operation. Note that however cancelling an
1274 * operation does NOT guarantee that the operation will be fully undone (or that
1275 * nothing ever happened).
1276 *
1277 * This function MUST be called for every operation to fully remove the
1278 * operation from the operation queue. After calling this function, if
1279 * operation is completed and its event information is of type
1280 * GNUNET_TESTBED_ET_OPERATION_FINISHED, the 'op_result' becomes invalid (!).
1281
1282 * If the operation is generated from GNUNET_TESTBED_service_connect() then
1283 * calling this function on such as operation calls the disconnect adapter if
1284 * the connect adapter was ever called.
1285 *
1286 * @param operation operation to signal completion or cancellation
1287 */
1288void
1289GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation);
1290
1291
1292/**
1293 * Callback function to process statistic values from all peers.
1294 *
1295 * @param cls closure
1296 * @param peer the peer the statistic belong to
1297 * @param subsystem name of subsystem that created the statistic
1298 * @param name the name of the datum
1299 * @param value the current value
1300 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
1301 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
1302 */
1303typedef int
1304(*GNUNET_TESTBED_StatisticsIterator) (void *cls,
1305 const struct GNUNET_TESTBED_Peer *peer,
1306 const char *subsystem,
1307 const char *name,
1308 uint64_t value,
1309 int is_persistent);
1310
1311
1312/**
1313 * Convenience method that iterates over all (running) peers
1314 * and retrieves all statistics from each peer.
1315 *
1316 * @param num_peers number of peers to iterate over
1317 * @param peers array of peers to iterate over
1318 * @param subsystem limit to the specified subsystem, NULL for all subsystems
1319 * @param name name of the statistic value, NULL for all values
1320 * @param proc processing function for each statistic retrieved
1321 * @param cont continuation to call once call is completed. The completion of this
1322 * operation is *ONLY* signalled through this callback -- no
1323 * GNUNET_TESTBED_ET_OPERATION_FINISHED is generated
1324 * @param cls closure to pass to proc and cont
1325 * @return operation handle to cancel the operation
1326 */
1327struct GNUNET_TESTBED_Operation *
1328GNUNET_TESTBED_get_statistics (unsigned int num_peers,
1329 struct GNUNET_TESTBED_Peer **peers,
1330 const char *subsystem, const char *name,
1331 GNUNET_TESTBED_StatisticsIterator proc,
1332 GNUNET_TESTBED_OperationCompletionCallback cont,
1333 void *cls);
1334
1335
1336/**
1337 * Return the index of the peer inside of the total peer array,
1338 * aka. the peer's "unique ID".
1339 *
1340 * @param peer Peer handle.
1341 *
1342 * @return The peer's unique ID.
1343 */
1344uint32_t
1345GNUNET_TESTBED_get_index (const struct GNUNET_TESTBED_Peer *peer);
1346
1347
1348/**
1349 * Handle for testbed run helper functions
1350 */
1351struct GNUNET_TESTBED_RunHandle;
1352
1353
1354/**
1355 * Signature of a main function for a testcase.
1356 *
1357 * @param cls closure
1358 * @param h the run handle
1359 * @param num_peers number of peers in 'peers'
1360 * @param peers handle to peers run in the testbed. NULL upon timeout (see
1361 * GNUNET_TESTBED_test_run()).
1362 * @param links_succeeded the number of overlay link connection attempts that
1363 * succeeded
1364 * @param links_failed the number of overlay link connection attempts that
1365 * failed
1366 * @see GNUNET_TESTBED_test_run()
1367 */
1368typedef void
1369(*GNUNET_TESTBED_TestMaster)(void *cls,
1370 struct GNUNET_TESTBED_RunHandle *h,
1371 unsigned int num_peers,
1372 struct GNUNET_TESTBED_Peer **peers,
1373 unsigned int links_succeeded,
1374 unsigned int links_failed);
1375
1376
1377/**
1378 * Convenience method for running a testbed with
1379 * a single call. Underlay and overlay topology
1380 * are configured using the "UNDERLAY" and "OVERLAY"
1381 * options in the "[testbed]" section of the configuration\
1382 * (with possible options given in "UNDERLAY_XXX" and/or
1383 * "OVERLAY_XXX").
1384 *
1385 * The test_master callback will be called once the testbed setup is finished or
1386 * upon a timeout. This timeout is given through the configuration file by
1387 * setting the option "SETUP_TIMEOUT" in "[TESTBED]" section.
1388 *
1389 * The testbed is to be terminated using a call to
1390 * "GNUNET_SCHEDULER_shutdown".
1391 *
1392 * @param host_filename name of the file with the 'hosts', NULL
1393 * to run everything on 'localhost'
1394 * @param cfg configuration to use (for testbed, controller and peers)
1395 * @param num_peers number of peers to start; FIXME: maybe put that ALSO into
1396 * cfg?; should be greater than 0
1397 * @param event_mask bit mask with set of events to call 'cc' for;
1398 * or-ed values of "1LL" shifted by the
1399 * respective 'enum GNUNET_TESTBED_EventType'
1400 * (e.g. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1401 * @param cc controller callback to invoke on events; This callback is called
1402 * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1403 * set in the event_mask as this is the only way get access to the
1404 * handle of each peer
1405 * @param cc_cls closure for cc
1406 * @param test_master this callback will be called once the test is ready or
1407 * upon timeout
1408 * @param test_master_cls closure for 'test_master'.
1409 */
1410void
1411GNUNET_TESTBED_run (const char *host_filename,
1412 const struct GNUNET_CONFIGURATION_Handle *cfg,
1413 unsigned int num_peers,
1414 uint64_t event_mask,
1415 GNUNET_TESTBED_ControllerCallback cc,
1416 void *cc_cls,
1417 GNUNET_TESTBED_TestMaster test_master,
1418 void *test_master_cls);
1419
1420
1421/**
1422 * Convenience method for running a "simple" test on the local system
1423 * with a single call from 'main'. Underlay and overlay topology are
1424 * configured using the "UNDERLAY" and "OVERLAY" options in the
1425 * "[TESTBED]" section of the configuration (with possible options
1426 * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX").
1427 *
1428 * The test_master callback will be called once the testbed setup is finished or
1429 * upon a timeout. This timeout is given through the configuration file by
1430 * setting the option "SETUP_TIMEOUT" in "[TESTBED]" section.
1431 *
1432 * The test is to be terminated using a call to
1433 * "GNUNET_SCHEDULER_shutdown". If starting the test fails,
1434 * the program is stopped without 'master' ever being run.
1435 *
1436 * NOTE: this function should be called from 'main', NOT from
1437 * within a GNUNET_SCHEDULER-loop. This function will initialize
1438 * the scheduler loop, the testbed and then pass control to
1439 * 'master'.
1440 *
1441 * @param testname name of the testcase (to configure logging, etc.)
1442 * @param cfg_filename configuration filename to use
1443 * (for testbed, controller and peers)
1444 * @param num_peers number of peers to start; should be greter than 0
1445 * @param event_mask bit mask with set of events to call 'cc' for;
1446 * or-ed values of "1LL" shifted by the
1447 * respective 'enum GNUNET_TESTBED_EventType'
1448 * (e.g. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1449 * @param cc controller callback to invoke on events; This callback is called
1450 * for all peer start events even if #GNUNET_TESTBED_ET_PEER_START isn't
1451 * set in the event_mask as this is the only way get access to the
1452 * handle of each peer
1453 * @param cc_cls closure for @a cc
1454 * @param test_master this callback will be called once the test is ready or
1455 * upon timeout
1456 * @param test_master_cls closure for @a test_master.
1457 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1458 */
1459int
1460GNUNET_TESTBED_test_run (const char *testname,
1461 const char *cfg_filename,
1462 unsigned int num_peers,
1463 uint64_t event_mask,
1464 GNUNET_TESTBED_ControllerCallback cc,
1465 void *cc_cls,
1466 GNUNET_TESTBED_TestMaster test_master,
1467 void *test_master_cls);
1468
1469
1470/**
1471 * Obtain handle to the master controller from a testbed run. The handle
1472 * returned should not be disconnected.
1473 *
1474 * @param h the testbed run handle
1475 * @return handle to the master controller
1476 */
1477struct GNUNET_TESTBED_Controller *
1478GNUNET_TESTBED_run_get_controller_handle (struct GNUNET_TESTBED_RunHandle *h);
1479
1480
1481/**
1482 * Opaque handle for barrier
1483 */
1484struct GNUNET_TESTBED_Barrier;
1485
1486
1487/**
1488 * Status of a barrier
1489 */
1490enum GNUNET_TESTBED_BarrierStatus
1491{
1492 /**
1493 * Barrier initialised successfully
1494 */
1495 GNUNET_TESTBED_BARRIERSTATUS_INITIALISED = 1,
1496
1497 /**
1498 * Barrier is crossed
1499 */
1500 GNUNET_TESTBED_BARRIERSTATUS_CROSSED,
1501
1502 /**
1503 * Error status
1504 */
1505 GNUNET_TESTBED_BARRIERSTATUS_ERROR,
1506};
1507
1508
1509/**
1510 * Functions of this type are to be given as callback argument to
1511 * GNUNET_TESTBED_barrier_init(). The callback will be called when status
1512 * information is available for the barrier.
1513 *
1514 * @param cls the closure given to GNUNET_TESTBED_barrier_init()
1515 * @param name the name of the barrier
1516 * @param barrier the barrier handle
1517 * @param status status of the barrier. The barrier is removed once it has been
1518 * crossed or an error occurs while processing it. Therefore it is
1519 * invalid to call GNUNET_TESTBED_barrier_cancel() on a crossed or
1520 * errored barrier.
1521 * @param emsg if the status were to be #GNUNET_SYSERR, this parameter has the
1522 * error message
1523 */
1524typedef void
1525(*GNUNET_TESTBED_barrier_status_cb) (void *cls,
1526 const char *name,
1527 struct GNUNET_TESTBED_Barrier *barrier,
1528 enum GNUNET_TESTBED_BarrierStatus status,
1529 const char *emsg);
1530
1531
1532/**
1533 * Initialise a barrier and call the given callback when the required percentage
1534 * of peers (quorum) reach the barrier.
1535 *
1536 * @param controller the handle to the controller
1537 * @param name identification name of the barrier
1538 * @param quorum the percentage of peers that is required to reach the barrier.
1539 * Peers signal reaching a barrier by calling
1540 * GNUNET_TESTBED_barrier_reached().
1541 * @param cb the callback to call when the barrier is reached or upon error.
1542 * Cannot be NULL.
1543 * @param cb_cls closure for @a cb
1544 * @return barrier handle
1545 */
1546struct GNUNET_TESTBED_Barrier *
1547GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller,
1548 const char *name,
1549 unsigned int quorum,
1550 GNUNET_TESTBED_barrier_status_cb cb,
1551 void *cb_cls);
1552
1553
1554/**
1555 * Cancel a barrier.
1556 *
1557 * @param barrier the barrier handle
1558 */
1559void
1560GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier);
1561
1562
1563/**
1564 * Opaque handle for barrier wait
1565 */
1566struct GNUNET_TESTBED_BarrierWaitHandle;
1567
1568
1569/**
1570 * Functions of this type are to be given as acallback argument to
1571 * GNUNET_TESTBED_barrier_wait(). The callback will be called when the barrier
1572 * corresponding given in GNUNET_TESTBED_barrier_wait() is crossed or cancelled.
1573 *
1574 * @param cls closure pointer given to GNUNET_TESTBED_barrier_wait()
1575 * @param name the barrier name
1576 * @param status #GNUNET_SYSERR in case of error while waiting for the barrier;
1577 * #GNUNET_OK if the barrier is crossed
1578 */
1579typedef void
1580(*GNUNET_TESTBED_barrier_wait_cb) (void *cls,
1581 const char *name,
1582 int status);
1583
1584
1585/**
1586 * Wait for a barrier to be crossed. This function should be called by the
1587 * peers which have been started by the testbed. If the peer is not started by
1588 * testbed this function may return error
1589 *
1590 * @param name the name of the barrier
1591 * @param cb the barrier wait callback
1592 * @param cls the closure for the above callback
1593 * @return barrier wait handle which can be used to cancel the waiting at
1594 * anytime before the callback is called. NULL upon error.
1595 */
1596struct GNUNET_TESTBED_BarrierWaitHandle *
1597GNUNET_TESTBED_barrier_wait (const char *name,
1598 GNUNET_TESTBED_barrier_wait_cb cb,
1599 void *cls);
1600
1601
1602/**
1603 * Cancel a barrier wait handle. Should not be called in or after the callback
1604 * given to GNUNET_TESTBED_barrier_wait() has been called.
1605 *
1606 * @param h the barrier wait handle
1607 */
1608void
1609GNUNET_TESTBED_barrier_wait_cancel (struct GNUNET_TESTBED_BarrierWaitHandle *h);
1610
1611
1612/**
1613 * Model for configuring underlay links of a peer
1614 * @ingroup underlay
1615 */
1616struct GNUNET_TESTBED_UnderlayLinkModel;
1617
1618
1619/**
1620 * The type of GNUNET_TESTBED_UnderlayLinkModel
1621 * @ingroup underlay
1622 */
1623enum GNUNET_TESTBED_UnderlayLinkModelType
1624{
1625 /**
1626 * The model is based on white listing of peers to which underlay connections
1627 * are permitted. Underlay connections to all other peers will not be
1628 * permitted.
1629 */
1630 GNUNET_TESTBED_UNDERLAYLINKMODELTYPE_BLACKLIST,
1631
1632 /**
1633 * The model is based on black listing of peers to which underlay connections
1634 * are not permitted. Underlay connections to all other peers will be
1635 * permitted
1636 */
1637 GNUNET_TESTBED_UNDERLAYLINKMODELTYPE_WHITELIST
1638};
1639
1640
1641/**
1642 * Create a GNUNET_TESTBED_UnderlayLinkModel for the given peer. A peer can
1643 * have ONLY ONE model and it can be either a blacklist or whitelist based one.
1644 *
1645 * @ingroup underlay
1646 * @param peer the peer for which the model has to be created
1647 * @param type the type of the model
1648 * @return the model
1649 */
1650struct GNUNET_TESTBED_UnderlayLinkModel *
1651GNUNET_TESTBED_underlaylinkmodel_create (struct GNUNET_TESTBED_Peer *peer,
1652 enum
1653 GNUNET_TESTBED_UnderlayLinkModelType
1654 type);
1655
1656
1657/**
1658 * Add a peer to the given model. Underlay connections to the given peer will
1659 * be permitted if the model is whitelist based; otherwise they will not be
1660 * permitted.
1661 *
1662 * @ingroup underlay
1663 * @param model the model
1664 * @param peer the peer to add
1665 */
1666void
1667GNUNET_TESTBED_underlaylinkmodel_add_peer (struct
1668 GNUNET_TESTBED_UnderlayLinkModel *
1669 model,
1670 struct GNUNET_TESTBED_Peer *peer);
1671
1672
1673/**
1674 * Set the metrics for a link to the given peer in the underlay model. The link
1675 * SHOULD be permittable according to the given model.
1676 *
1677 * @ingroup underlay
1678 * @param model the model
1679 * @param peer the other end peer of the link
1680 * @param latency latency of the link in microseconds
1681 * @param loss data loss of the link expressed as a percentage
1682 * @param bandwidth bandwidth of the link in kilobytes per second [kB/s]
1683 */
1684void
1685GNUNET_TESTBED_underlaylinkmodel_set_link (struct
1686 GNUNET_TESTBED_UnderlayLinkModel *
1687 model,
1688 struct GNUNET_TESTBED_Peer *peer,
1689 uint32_t latency,
1690 uint32_t loss,
1691 uint32_t bandwidth);
1692
1693
1694/**
1695 * Commit the model. The model is freed in this function(!).
1696 *
1697 * @ingroup underlay
1698 * @param model the model to commit
1699 */
1700void
1701GNUNET_TESTBED_underlaylinkmodel_commit (struct
1702 GNUNET_TESTBED_UnderlayLinkModel *model);
1703
1704
1705/**
1706 * Free the resources of the model. Use this function only if the model has not
1707 * be committed and has to be unallocated. The peer can then have another model
1708 * created.
1709 *
1710 * @ingroup underlay
1711 * @param model the model to unallocate
1712 */
1713void
1714GNUNET_TESTBED_underlaylinkmodel_free (struct
1715 GNUNET_TESTBED_UnderlayLinkModel *model);
1716
1717
1718#if 0 /* keep Emacsens' auto-indent happy */
1719{
1720#endif
1721
1722
1723#ifdef __cplusplus
1724}
1725#endif
1726
1727#endif
1728
1729/** @} */ /* end of group */
diff --git a/src/include/gnunet_testing_arm_lib.h b/src/include/gnunet_testing_arm_lib.h
new file mode 100644
index 000000000..66852b506
--- /dev/null
+++ b/src/include/gnunet_testing_arm_lib.h
@@ -0,0 +1,47 @@
1#ifndef GNUNET_TESTING_ARM_LIB_H
2#define GNUNET_TESTING_ARM_LIB_H
3
4#include "gnunet_arm_service.h"
5
6/**
7 * Create command.
8 *
9 * @param label name for command.
10 * @param system_label Label of the cmd to setup a test environment.
11 * @param cfgname Configuration file name for this peer.
12 * @return command.
13 */
14struct GNUNET_TESTING_Command
15GNUNET_TESTING_ARM_cmd_start_peer (
16 const char *label,
17 const char *system_label,
18 const char *cfgname);
19
20
21/**
22 * Create command.
23 *
24 * @param label name for command.
25 * @param start_label Label of the cmd to start the peer.
26 * @return command.
27 */
28struct GNUNET_TESTING_Command
29GNUNET_TESTING_cmd_stop_peer (
30 const char *label,
31 const char *start_label);
32
33
34/**
35 * Call #op on all simple traits.
36 */
37#define GNUNET_TESTING_ARM_SIMPLE_TRAITS(op, prefix) \
38 op (prefix, \
39 arm_handle, \
40 struct GNUNET_ARM_Handle)
41
42
43GNUNET_TESTING_ARM_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT,
44 GNUNET_TESTING_ARM)
45
46
47#endif
diff --git a/src/include/gnunet_testing_core_lib.h b/src/include/gnunet_testing_core_lib.h
new file mode 100644
index 000000000..cf96b395d
--- /dev/null
+++ b/src/include/gnunet_testing_core_lib.h
@@ -0,0 +1,159 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021-2023 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @brief API for cmds working with core sub system provided by libgnunetcoretesting
23 * @author t3sserakt
24 */
25#ifndef GNUNET_TESTING_CORE_LIB_H
26#define GNUNET_TESTING_CORE_LIB_H
27
28
29#include "gnunet_util_lib.h"
30#include "gnunet_testing_lib.h"
31
32
33/**
34 * Struct to store information needed in callbacks.
35 */
36// FIXME: breaks naming conventions
37struct GNUNET_TESTING_ConnectPeersState
38{
39 /**
40 * Receive callback
41 */
42 struct GNUNET_MQ_MessageHandler *handlers;
43
44 /**
45 * A map with struct GNUNET_MQ_Handle values for each peer this peer
46 * is connected to.
47 */
48 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
49
50 /**
51 * Handle for transport.
52 */
53 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
54
55 /**
56 * Core handle.
57 */
58 struct GNUNET_TRANSPORT_CoreHandle *th;
59
60 /**
61 * Context for our asynchronous completion.
62 */
63 struct GNUNET_TESTING_AsyncContext ac;
64
65 /**
66 * The testing system of this node.
67 */
68 const struct GNUNET_TESTING_System *tl_system;
69
70 // Label of the cmd which started the test system.
71 const char *create_label;
72
73 /**
74 * Number globally identifying the node.
75 *
76 */
77 uint32_t num;
78
79 /**
80 * Label of the cmd to start a peer.
81 *
82 */
83 const char *start_peer_label;
84
85 /**
86 * The topology of the test setup.
87 */
88 struct GNUNET_TESTING_NetjailTopology *topology;
89
90 /**
91 * Connections to other peers.
92 */
93 struct GNUNET_TESTING_NodeConnection *node_connections_head;
94
95 struct GNUNET_TESTING_Interpreter *is;
96
97 /**
98 * Number of connections.
99 */
100 unsigned int con_num;
101
102 /**
103 * Number of additional connects this cmd will wait for not triggered by this cmd.
104 */
105 unsigned int additional_connects;
106
107 /**
108 * Number of connections we already have a notification for.
109 */
110 unsigned int con_num_notified;
111
112 /**
113 * Number of additional connects this cmd will wait for not triggered by this cmd we already have a notification for.
114 */
115 unsigned int additional_connects_notified;
116
117 /**
118 * Flag indicating, whether the command is waiting for peers to connect that are configured to connect.
119 */
120 unsigned int wait_for_connect;
121};
122
123
124/**
125 * FIXME: document properly!
126 * Create command
127 *
128 * @param label name for command
129 * @param start_peer_label Label of the cmd to start a peer.
130 * @param create_label Label of the cmd which started the test system.
131 * @param num Number globally identifying the node.
132 * @param topology The topology for the test setup.
133 * @param additional_connects Number of additional connects this cmd will wait for not triggered by this cmd.
134 * @return command.
135 */
136struct GNUNET_TESTING_Command
137GNUNET_CORE_cmd_connect_peers (
138 const char *label,
139 const char *start_peer_label,
140 const char *create_label,
141 uint32_t num,
142 struct GNUNET_TESTING_NetjailTopology *topology,
143 unsigned int additional_connects,
144 unsigned int wait_for_connect,
145 struct GNUNET_MQ_MessageHandler *handlers);
146
147
148/**
149 * Call #op on all simple traits.
150 */
151#define GNUNET_CORE_TESTING_SIMPLE_TRAITS(op, prefix) \
152 op (prefix, connect_peer_state, const struct \
153 GNUNET_TESTING_ConnectPeersState)
154
155GNUNET_CORE_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT,
156 GNUNET_CORE_TESTING)
157
158
159#endif
diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h
index 664e20ac3..95961b640 100644
--- a/src/include/gnunet_testing_lib.h
+++ b/src/include/gnunet_testing_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2008, 2009, 2012 GNUnet e.V. 3 Copyright (C) 2021, 2023, 2024 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -19,456 +19,959 @@
19 */ 19 */
20 20
21/** 21/**
22 * @author Christian Grothoff 22 * @brief Central interpreter and command loop for writing an interpreter to test asynchronous systems
23 * 23 * @author Christian Grothoff <christian@grothoff.org>
24 * @file 24 * @author Marcello Stanisci
25 * Convenience API for writing testcases for GNUnet 25 * @author t3sserakt
26 */
27#ifndef GNUNET_TESTING_LIB_H
28#define GNUNET_TESTING_LIB_H
29
30#include "gnunet_util_lib.h"
31
32/**
33 * Maximum length of label in command
34 */
35#define GNUNET_TESTING_CMD_MAX_LABEL_LENGTH 127
36
37/* ********************* Helper functions ********************* */
38
39/**
40 * Print failing line number and trigger shutdown. Useful
41 * quite any time after the command "run" method has been called.
42 * Returns from the current function.
43 */
44#define GNUNET_TESTING_FAIL(is) \
45 do { \
46 GNUNET_break (0); \
47 GNUNET_TESTING_interpreter_fail (is); \
48 return; \
49 } while (0)
50
51
52/**
53 * Log an error message about a command not having run to completion.
26 * 54 *
27 * @defgroup testing Testing library 55 * @param is interpreter
28 * Library for writing testcases for GNUnet. 56 * @param label command label of the incomplete command
57 */
58#define GNUNET_TESTING_command_incomplete(is,label) \
59 do { \
60 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
61 "Command %s (%s:%u) did not complete (at %s)\n", \
62 label, \
63 __FILE__, \
64 __LINE__, \
65 GNUNET_TESTING_interpreter_current_cmd_get_label (is)); \
66 } while (0)
67
68
69/* ******************* Generic interpreter logic ************ */
70
71/**
72 * Global state of the interpreter, used by a command
73 * to access information about other commands.
74 */
75struct GNUNET_TESTING_Interpreter;
76
77/**
78 * State each asynchronous command must have in its closure.
79 */
80struct GNUNET_TESTING_AsyncContext
81{
82
83 /**
84 * Interpreter we are part of. Initialized when
85 * the global interpreter starts.
86 */
87 struct GNUNET_TESTING_Interpreter *is;
88
89 /**
90 * Function to call when async operation is done.
91 */
92 GNUNET_SCHEDULER_TaskCallback notify_finished;
93
94 /**
95 * Closure for @e notify_finished.
96 */
97 void *notify_finished_cls;
98
99 /**
100 * Indication if the command finished (#GNUNET_OK).
101 * #GNUNET_NO if it did not finish,
102 * #GNUNET_SYSERR if it failed.
103 */
104 enum GNUNET_GenericReturnValue finished;
105
106 /**
107 * Set to true if interpreter_next() has already been
108 * called for this command.
109 */
110 bool next_called;
111};
112
113
114/**
115 * The asynchronous command of @a ac has failed.
29 * 116 *
30 * It can start/stop one or more peers on a system; testing is responsible for 117 * @param ac command-specific context
31 * managing private keys, ports and paths; it is a low-level library that does 118 */
32 * not support higher-level functions such as P2P connection, topology 119void
33 * management or distributed testbed maintenance (those are provided by the 120GNUNET_TESTING_async_fail (
34 * [Testbed service](@ref testbed)) 121 struct GNUNET_TESTING_AsyncContext *ac);
122
123
124/**
125 * The asynchronous command of @a ac has finished.
35 * 126 *
36 * @see [Documentation](https://gnunet.org/writing_testcases) 127 * @param ac command-specific context
128 */
129void
130GNUNET_TESTING_async_finish (
131 struct GNUNET_TESTING_AsyncContext *ac);
132
133
134/**
135 * Signature of a function used to start executing a command of a test. Runs
136 * the command. Note that upon return, the interpreter will not automatically
137 * run the next command if this is an asynchronous command unless the command
138 * was wrapped in #GNUNET_TESTING_cmd_make_unblocking(), as the command may
139 * then continue asynchronously in other scheduler tasks. In this case,
140 * #GNUNET_TESTING_async_finish() must be called to run the next task.
37 * 141 *
38 * @{ 142 * @param cls closure
143 * @param is interpreter running the command
39 */ 144 */
145typedef void
146(*GNUNET_TESTING_CommandRunRoutine)(
147 void *cls,
148 struct GNUNET_TESTING_Interpreter *is);
40 149
41#ifndef GNUNET_TESTING_LIB_H
42#define GNUNET_TESTING_LIB_H
43 150
44#include "gnunet_util_lib.h" 151/**
45#include "gnunet_statistics_service.h" 152 * Signature of a function used to clean up resources allocated
46#include "gnunet_arm_service.h" 153 * by a command.
154 *
155 * @param cls closure
156 */
157typedef void
158(*GNUNET_TESTING_CommandCleanupRoutine)(void *cls);
47 159
48#ifdef __cplusplus
49extern "C"
50{
51#if 0 /* keep Emacsens' auto-indent happy */
52}
53#endif
54#endif
55 160
56/** 161/**
57 * Size of each hostkey in the hostkey file (in BYTES). 162 * Signature of a function used to extract traits exposed by a
163 * command.
164 *
165 * @param cls closure
166 * @param[out] ret where to return the trait data
167 * @param trait name of the trait to return
168 * @param index index of the trait (for traits that are indexed)
169 * @return #GNUNET_OK on success
58 */ 170 */
59#define GNUNET_TESTING_HOSTKEYFILESIZE sizeof(struct \ 171typedef enum GNUNET_GenericReturnValue
60 GNUNET_CRYPTO_EddsaPrivateKey) 172(*GNUNET_TESTING_CommandGetTraits) (void *cls,
173 const void **ret,
174 const char *trait,
175 unsigned int index);
61 176
62/** 177/**
63 * The environmental variable, if set, that dictates where testing should place 178 * Create a new command that may be asynchronous.
64 * generated peer configurations 179 *
180 * @param cls the closure
181 * @param label the Label. Maximum length is #GNUNET_TESTING_CMD_MAX_LABEL_LENGTH
182 * @param run the run routing
183 * @param cleanup the cleanup function
184 * @param traits the traits function (optional)
185 * @param ac the async context, NULL if command is always
186 * synchronous
187 * @return the command the function cannot fail
65 */ 188 */
66#define GNUNET_TESTING_PREFIX "GNUNET_TESTING_PREFIX" 189struct GNUNET_TESTING_Command
190GNUNET_TESTING_command_new_ac (
191 void *cls,
192 const char *label,
193 GNUNET_TESTING_CommandRunRoutine run,
194 GNUNET_TESTING_CommandCleanupRoutine cleanup,
195 GNUNET_TESTING_CommandGetTraits traits,
196 struct GNUNET_TESTING_AsyncContext *ac);
67 197
68 198
69/** 199/**
70 * Handle for a system on which GNUnet peers are executed; 200 * Create a new command
71 * a system is used for reserving unique paths and ports. 201 *
202 * @param cls the closure
203 * @param label the Label. Maximum length is #GNUNET_TESTING_CMD_MAX_LABEL_LENGTH
204 * @param run the run routing
205 * @param cleanup the cleanup function
206 * @param traits the traits function (optional)
207 * @return the command the function cannot fail
72 */ 208 */
73struct GNUNET_TESTING_System; 209#define GNUNET_TESTING_command_new(cls,label,run,cleanup,traits) \
210 GNUNET_TESTING_command_new_ac (cls,label,run,cleanup,traits,NULL)
74 211
75 212
76/** 213/**
77 * Handle for a GNUnet peer controlled by testing. 214 * Structure with storage space for a label.
78 */ 215 */
79struct GNUNET_TESTING_Peer; 216struct GNUNET_TESTING_CommandLabel
217{
218 char value[GNUNET_TESTING_CMD_MAX_LABEL_LENGTH + 1];
219};
80 220
81 221
82/** 222/**
83 * Specification of a service that is to be shared among peers 223 * Set @a label to @a value. Asserts that @a value is
224 * not longer than #GNUNET_TESTING_CMD_MAX_LABEL_LENGTH.
225 *
226 * @param[out] label label to initialize
227 * @param value value to store into @a label
84 */ 228 */
85struct GNUNET_TESTING_SharedService 229void
230GNUNET_TESTING_set_label (
231 struct GNUNET_TESTING_CommandLabel *label,
232 const char *value);
233
234
235/**
236 * A command to be run by the interpreter.
237 */
238struct GNUNET_TESTING_Command
86{ 239{
240
241 /**
242 * Label for the command.
243 */
244 struct GNUNET_TESTING_CommandLabel label;
245
246 /**
247 * Closure for all commands with command-specific context information.
248 */
249 void *cls;
250
251 /**
252 * Variable name for the command, NULL for none.
253 */
254 const char *name;
255
256 /**
257 * Runs the command. Note that upon return, the interpreter
258 * will not automatically run the next command, as the command
259 * may continue asynchronously in other scheduler tasks. Thus,
260 * the command must ensure to eventually call
261 * #GNUNET_TESTING_interpreter_next() or
262 * #GNUNET_TESTING_interpreter_fail().
263 *
264 * If this function creates some asynchronous activity, it should
265 * initialize @e finish to a function that can be used to wait for
266 * the asynchronous activity to terminate.
267 *
268 * @param cls closure
269 * @param is interpreter state
270 */
271 GNUNET_TESTING_CommandRunRoutine run;
272
273 /**
274 * Pointer to the asynchronous context in the command's
275 * closure. Used by the
276 * #GNUNET_TESTING_async_finish() and
277 * #GNUNET_TESTING_async_fail() functions.
278 *
279 * Must be NULL if a command is synchronous.
280 */
281 struct GNUNET_TESTING_AsyncContext *ac;
282
283 /**
284 * Clean up after the command. Run during forced termination
285 * (CTRL-C) or test failure or test success.
286 *
287 * @param cls closure
288 */
289 GNUNET_TESTING_CommandCleanupRoutine cleanup;
290
291 /**
292 * Extract information from a command that is useful for other
293 * commands. Can be NULL if a command has no traits.
294 *
295 * @param cls closure
296 * @param[out] ret result (could be anything)
297 * @param trait name of the trait
298 * @param index index number of the object to extract.
299 * @return #GNUNET_OK on success,
300 * #GNUNET_NO if no trait was found
301 */
302 GNUNET_TESTING_CommandGetTraits traits;
303
87 /** 304 /**
88 * The name of the service. 305 * When did the execution of this command start?
89 */ 306 */
90 const char *service; 307 struct GNUNET_TIME_Absolute start_time;
91 308
92 /** 309 /**
93 * The configuration template for the service. Cannot be NULL 310 * When did the execution of this command finish?
94 */ 311 */
95 const struct GNUNET_CONFIGURATION_Handle *cfg; 312 struct GNUNET_TIME_Absolute finish_time;
96 313
97 /** 314 /**
98 * The number of peers which share an instance of the service. 0 for sharing 315 * When did we start the last run of this command? Delta to @e finish_time
99 * among all peers 316 * gives the latency for the last successful run. Useful in case @e
317 * num_tries was positive and the command was run multiple times. In that
318 * case, the @e start_time gives the time when we first tried to run the
319 * command, so the difference between @e start_time and @e finish_time would
320 * be the time all of the @e num_tries took, while the delta to @e
321 * last_req_time is the time the last (successful) execution took.
100 */ 322 */
101 unsigned int share; 323 struct GNUNET_TIME_Absolute last_req_time;
324
325 /**
326 * How often did we try to execute this command? (In case it is a request
327 * that is repated.) Note that a command must have some built-in retry
328 * mechanism for this value to be useful.
329 */
330 unsigned int num_tries;
331
332 /**
333 * If "true", the interpreter should not immediately run the next command,
334 * even if this command did not complete via #GNUNET_TESTING_async_finish().
335 * Otherwise, #GNUNET_TESTING_cmd_finish() must be used to ensure that a
336 * command actually completed.
337 */
338 bool asynchronous_finish;
339
102}; 340};
103 341
104 342
105/** 343/**
106 * Create a system handle. There must only be one system handle per operating 344 * Lookup command by label.
107 * system. Uses a default range for allowed ports. Ports are still tested for 345 *
108 * availability. 346 * @param is interpreter to lookup command in
109 * 347 * @param label label of the command to lookup.
110 * @param testdir only the directory name without any path. This is used for all 348 * @return the command, if it is found, or NULL.
111 * service homes; the directory will be created in a temporary location 349 */
112 * depending on the underlying OS. This variable will be 350const struct GNUNET_TESTING_Command *
113 * overridden with the value of the environmental variable 351GNUNET_TESTING_interpreter_lookup_command (
114 * GNUNET_TESTING_PREFIX, if it exists. 352 struct GNUNET_TESTING_Interpreter *is,
115 * @param trusted_ip the ip address which will be set as TRUSTED HOST in all 353 const char *label);
116 * service configurations generated to allow control connections from 354
117 * this ip. This can either be a single ip address or a network address 355
118 * in CIDR notation. 356/**
119 * @param hostname the hostname of the system we are using for testing; NULL for 357 * Get command from hash map by variable name.
120 * localhost 358 *
121 * @param shared_services NULL terminated array describing services that are to 359 * @param is interpreter state.
122 * be shared among peers 360 * @param name name of the variable to get command by
123 * @return handle to this system, NULL on error 361 * @return the command, if it is found, or NULL.
124 */ 362 */
125struct GNUNET_TESTING_System * 363const struct GNUNET_TESTING_Command *
126GNUNET_TESTING_system_create (const char *testdir, 364GNUNET_TESTING_interpreter_get_command (
127 const char *trusted_ip, 365 struct GNUNET_TESTING_Interpreter *is,
128 const char *hostname, 366 const char *name);
129 const struct GNUNET_TESTING_SharedService * 367
130 shared_services); 368
131 369/**
132 370 * Update the last request time of the current command
133/** 371 * to the current time.
134 * Create a system handle. There must only be one system 372 *
135 * handle per operating system. Use this function directly 373 * @param[in,out] is interpreter state where to show
136 * if multiple system objects are created for the same host 374 * that we are doing something
137 * (only really useful when testing --- or to make the port 375 */
138 * range configurable). 376void
139 * 377GNUNET_TESTING_interpreter_current_cmd_touch (
140 * @param testdir only the directory name without any path. This is used for 378 struct GNUNET_TESTING_Interpreter *is);
141 * all service homes; the directory will be created in a temporary 379
142 * location depending on the underlying OS. This variable will be 380
143 * overridden with the value of the environmental variable 381/**
144 * GNUNET_TESTING_PREFIX, if it exists. 382 * Increment the 'num_tries' counter for the current command.
145 * @param trusted_ip the ip address which will be set as TRUSTED HOST in all 383 *
146 * service configurations generated to allow control connections from 384 * @param[in,out] is interpreter state where to
147 * this ip. This can either be a single ip address or a network address 385 * increment the counter
148 * in CIDR notation.
149 * @param hostname the hostname of the system we are using for testing; NULL for
150 * localhost
151 * @param shared_services NULL terminated array describing services that are to
152 * be shared among peers
153 * @param lowport lowest port number this system is allowed to allocate (inclusive)
154 * @param highport highest port number this system is allowed to allocate (exclusive)
155 * @return handle to this system, NULL on error
156 */
157struct GNUNET_TESTING_System *
158GNUNET_TESTING_system_create_with_portrange (const char *testdir,
159 const char *trusted_ip,
160 const char *hostname,
161 const struct
162 GNUNET_TESTING_SharedService *
163 shared_services,
164 uint16_t lowport,
165 uint16_t highport);
166
167
168/**
169 * Free system resources.
170 *
171 * @param system system to be freed
172 * @param remove_paths should the 'testdir' and all subdirectories
173 * be removed (clean up on shutdown)?
174 */ 386 */
175void 387void
176GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, 388GNUNET_TESTING_interpreter_current_cmd_inc_tries (
177 int remove_paths); 389 struct GNUNET_TESTING_Interpreter *is);
390
391
392/**
393 * Obtain label of the command being now run.
394 *
395 * @param is interpreter state.
396 * @return the label.
397 */
398const char *
399GNUNET_TESTING_interpreter_current_cmd_get_label (
400 struct GNUNET_TESTING_Interpreter *is);
178 401
179 402
180/** 403/**
181 * Testing includes a number of pre-created hostkeys for 404 * Current command failed, clean up and fail the test case.
182 * faster peer startup. This function can be used to
183 * access the n-th key of those pre-created hostkeys; note
184 * that these keys are ONLY useful for testing and not
185 * secure as the private keys are part of the public
186 * GNUnet source code.
187 * 405 *
188 * This is primarily a helper function used internally 406 * @param is interpreter state.
189 * by #GNUNET_TESTING_peer_configure(). 407 */
408void
409GNUNET_TESTING_interpreter_fail (
410 struct GNUNET_TESTING_Interpreter *is);
411
412
413/**
414 * Skips the current test, the environment is
415 * not prepared correctly.
190 * 416 *
191 * @param system the testing system handle 417 * @param is interpreter state.
192 * @param key_number desired pre-created hostkey to obtain
193 * @param id set to the peer's identity (hash of the public
194 * key; if NULL, #GNUNET_SYSERR is returned immediately
195 * @return NULL on error (not enough keys)
196 */ 418 */
197struct GNUNET_CRYPTO_EddsaPrivateKey * 419void
198GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, 420GNUNET_TESTING_interpreter_skip (
199 uint32_t key_number, 421 struct GNUNET_TESTING_Interpreter *is);
200 struct GNUNET_PeerIdentity *id);
201 422
202 423
203/** 424/**
204 * Reserve a port for a peer. 425 * Callback over commands of an interpreter.
205 * 426 *
206 * @param system system to use for reservation tracking 427 * @param cls closure
207 * @return 0 if no free port was available 428 * @param cmd a command to process
208 */ 429 */
209uint16_t 430typedef void
210GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system); 431(*GNUNET_TESTING_CommandIterator)(
432 void *cls,
433 const struct GNUNET_TESTING_Command *cmd);
211 434
212 435
213/** 436/**
214 * Release reservation of a TCP or UDP port for a peer 437 * Iterates over all of the top-level commands of an
215 * (used during GNUNET_TESTING_peer_destroy). 438 * interpreter.
216 * 439 *
217 * @param system system to use for reservation tracking 440 * @param[in] is interpreter to iterate over
218 * @param port reserved port to release 441 * @param asc true in execution order, false for reverse execution order
442 * @param cb function to call on each command
443 * @param cb_cls closure for cb
219 */ 444 */
220void 445void
221GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, 446GNUNET_TESTING_interpreter_commands_iterate (
222 uint16_t port); 447 struct GNUNET_TESTING_Interpreter *is,
448 bool asc,
449 GNUNET_TESTING_CommandIterator cb,
450 void *cb_cls);
451
452
453/* ************** Fundamental interpreter commands ************ */
223 454
224 455
225/** 456/**
226 * Create a new configuration using the given configuration as a template; 457 * Create command array terminator.
227 * ports and paths will be modified to select available ports on the local
228 * system. The default configuration will be available in PATHS section under
229 * the option DEFAULTCONFIG after the call. SERVICE_HOME is also set in PATHS
230 * section to the temporary directory specific to this configuration. If we run
231 * out of "*port" numbers, return #GNUNET_SYSERR.
232 * 458 *
233 * This is primarily a helper function used internally 459 * @return a end-command.
234 * by #GNUNET_TESTING_peer_configure(). 460 */
461struct GNUNET_TESTING_Command
462GNUNET_TESTING_cmd_end (void);
463
464
465/**
466 * Create a "batch" command. Such command takes a end_CMD-terminated array of
467 * CMDs and executed them. Once it hits the end CMD, it passes the control to
468 * the next top-level CMD, regardless of it being another batch or ordinary
469 * CMD.
235 * 470 *
236 * @param system system to use to coordinate resource usage 471 * @param label the command label.
237 * @param cfg template configuration to update 472 * @param batch array of CMDs to execute.
238 * @return #GNUNET_OK on success, 473 * @return the command.
239 * #GNUNET_SYSERR on error - the configuration will
240 * be incomplete and should not be used there upon
241 */ 474 */
242int 475struct GNUNET_TESTING_Command
243GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, 476GNUNET_TESTING_cmd_batch (
244 struct GNUNET_CONFIGURATION_Handle *cfg); 477 const char *label,
478 struct GNUNET_TESTING_Command *batch);
479
480
481/**
482 * Performance counter.
483 */
484struct GNUNET_TESTING_Timer
485{
486 /**
487 * For which type of commands.
488 */
489 const char *prefix;
245 490
246// FIXME: add dual to 'release' ports again... 491 /**
492 * Total time spend in all commands of this type.
493 */
494 struct GNUNET_TIME_Relative total_duration;
247 495
496 /**
497 * Total time spend waiting for the *successful* exeuction
498 * in all commands of this type.
499 */
500 struct GNUNET_TIME_Relative success_latency;
501
502 /**
503 * Number of commands summed up.
504 */
505 unsigned int num_commands;
506
507 /**
508 * Number of retries summed up.
509 */
510 unsigned int num_retries;
511};
248 512
249/** 513/**
250 * Configure a GNUnet peer. GNUnet must be installed on the local 514 * Obtain performance data from the interpreter.
251 * system and available in the PATH.
252 * 515 *
253 * @param system system to use to coordinate resource usage 516 * @param label command label.
254 * @param cfg configuration to use; will be UPDATED (to reflect needed 517 * @param[in,out] timers NULL-prefix terminated array that specifies what commands (by label) to obtain runtimes for
255 * changes in port numbers and paths) 518 * @return the command
256 * @param key_number number of the hostkey to use for the peer
257 * @param id identifier for the daemon, will be set, can be NULL
258 * @param emsg set to freshly allocated error message (set to NULL on success),
259 * can be NULL
260 * @return handle to the peer, NULL on error
261 */ 519 */
262struct GNUNET_TESTING_Peer * 520struct GNUNET_TESTING_Command
263GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, 521GNUNET_TESTING_cmd_stat (
264 struct GNUNET_CONFIGURATION_Handle *cfg, 522 const char *label,
265 uint32_t key_number, 523 struct GNUNET_TESTING_Timer *timers);
266 struct GNUNET_PeerIdentity *id,
267 char **emsg);
268 524
269 525
270/** 526/**
271 * Obtain the peer identity from a peer handle. 527 * Set variable to command as side-effect of
528 * running a command.
272 * 529 *
273 * @param peer peer handle for which we want the peer's identity 530 * @param name name of the variable to set
274 * @param id identifier for the daemon, will be set 531 * @param cmd command to set to variable when run
532 * @return modified command
275 */ 533 */
276void 534struct GNUNET_TESTING_Command
277GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer, 535GNUNET_TESTING_cmd_set_var (
278 struct GNUNET_PeerIdentity *id); 536 const char *name,
537 struct GNUNET_TESTING_Command cmd);
279 538
280 539
281/** 540/**
282 * Start the peer. 541 * Command to create a barrier.
283 * 542 *
284 * @param peer peer to start 543 * @param label The label of this command.
285 * @return #GNUNET_OK on success, 544 * @param number_to_be_reached If this number of processes reached
286 * #GNUNET_SYSERR on error (i.e. peer already running) 545 * this barrier, all processes waiting at
546 * this barrier can pass it.
287 */ 547 */
288int 548struct GNUNET_TESTING_Command
289GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer); 549GNUNET_TESTING_cmd_barrier_create (
550 const char *label,
551 unsigned int number_to_be_reached);
290 552
291 553
292/** 554/**
293 * Stop the peer. This call is blocking as it kills the peer's main ARM process 555 * If this command is executed the the process is signaling the master process
294 * by sending a SIGTERM and waits on it. For asynchronous shutdown of peer, see 556 * that it reached a barrier. If this command is synchronous it will block.
295 * GNUNET_TESTING_peer_stop_async().
296 * 557 *
297 * @param peer peer to stop 558 * @param label name for command.
298 * @return #GNUNET_OK on success, 559 * @param barrier_label The name of the barrier we waited for and which was reached.
299 * #GNUNET_SYSERR on error (i.e. peer not running) 560 * @return command.
300 */ 561 */
301int 562struct GNUNET_TESTING_Command
302GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer); 563GNUNET_TESTING_cmd_barrier_reached (
564 const char *label,
565 const char *barrier_label);
566
567
568#define GNUNET_TESTING_NETJAIL_START_SCRIPT "netjail_start_new.sh"
303 569
570#define GNUNET_TESTING_NETJAIL_STOP_SCRIPT "netjail_stop.sh"
304 571
305/** 572/**
306 * Destroy the peer. Releases resources locked during peer configuration. 573 * Create command.
307 * If the peer is still running, it will be stopped AND a warning will be
308 * printed (users of the API should stop the peer explicitly first).
309 * 574 *
310 * @param peer peer to destroy 575 * @param label Name for the command.
576 * @param topology_data topology data
577 * @param timeout Before this timeout is reached this cmd MUST finish.
578 * @return command.
311 */ 579 */
312void 580struct GNUNET_TESTING_Command
313GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer); 581GNUNET_TESTING_cmd_netjail_start_helpers (
582 const char *label,
583 const char *topology_cmd_label,
584 struct GNUNET_TIME_Relative timeout);
314 585
315 586
316/** 587/**
317 * Sends SIGTERM to the peer's main process 588 * This command executes a shell script to setup the netjail environment.
318 * 589 *
319 * @param peer the handle to the peer 590 * @param label name for command.
320 * @return #GNUNET_OK if successful; #GNUNET_SYSERR if the main process is NULL 591 * @param script which script to run, e.g. #GNUNET_TESTING_NETJAIL_START_SCRIPT
321 * or upon any error while sending SIGTERM 592 * @param topology_config Configuration file for the test topology.
593 * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data.
594 * @return command.
322 */ 595 */
323int 596struct GNUNET_TESTING_Command
324GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer); 597GNUNET_TESTING_cmd_netjail_setup (
598 const char *label,
599 const char *script,
600 const char *topology_cmd_label);
601
602
603struct GNUNET_TESTING_Command
604GNUNET_TESTING_cmd_load_topology_from_file (
605 const char *label,
606 const char *filename);
607
608
609struct GNUNET_TESTING_Command
610GNUNET_TESTING_cmd_load_topology_from_string (
611 const char *label,
612 const char *topology_data);
325 613
326 614
327/** 615/**
328 * Waits for a peer to terminate. The peer's main process will also be destroyed. 616 * Turn asynchronous command into non-blocking command by setting
617 * asynchronous_finish to true. Modifies (and then returns) @a cmd simply
618 * setting the bit. By default, most commands are blocking, and by wrapping
619 * the command construction in this function a blocking command can be turned
620 * into an asynchronous command where the interpreter continues after
621 * initiating the asynchronous action. Does nothing if the command is
622 * fundamentally synchronous.
329 * 623 *
330 * @param peer the handle to the peer 624 * @param[in,out] cmd command to make non-blocking
331 * @return #GNUNET_OK if successful; #GNUNET_SYSERR if the main process is NULL 625 * @return a finish-command.
332 * or upon any error while waiting
333 */ 626 */
334int 627struct GNUNET_TESTING_Command
335GNUNET_TESTING_peer_wait (struct GNUNET_TESTING_Peer *peer); 628GNUNET_TESTING_cmd_make_unblocking (
629 struct GNUNET_TESTING_Command cmd);
336 630
337 631
338/** 632/**
339 * Callback to inform whether the peer is running or stopped. 633 * Create (synchronous) command that waits for another command to finish.
634 * If @a cmd_ref did not finish after @a timeout, this command will fail
635 * the test case.
340 * 636 *
341 * @param cls the closure given to GNUNET_TESTING_peer_stop_async() 637 * @param finish_label label for this command
342 * @param peer the respective peer whose status is being reported 638 * @param cmd_ref reference to a previous command which we should
343 * @param success #GNUNET_YES if the peer is stopped; #GNUNET_SYSERR upon any 639 * wait for (call `finish()` on)
344 * error 640 * @param timeout how long to wait at most for @a cmd_ref to finish
641 * @return a finish-command.
345 */ 642 */
346typedef void 643const struct GNUNET_TESTING_Command
347(*GNUNET_TESTING_PeerStopCallback) (void *cls, 644GNUNET_TESTING_cmd_finish (
348 struct GNUNET_TESTING_Peer *peer, 645 const char *finish_label,
349 int success); 646 const char *cmd_ref,
647 struct GNUNET_TIME_Relative timeout);
350 648
351 649
352/** 650/**
353 * Stop a peer asynchronously using ARM API. Peer's shutdown is signaled 651 * Create a "signal" CMD.
354 * through the GNUNET_TESTING_PeerStopCallback().
355 * 652 *
356 * @param peer the peer to stop 653 * @param label command label.
357 * @param cb the callback to signal peer shutdown 654 * @param process_label label of a command that has a process trait
358 * @param cb_cls closure for the @a cb 655 * @param signal signal to send to @a process.
359 * @return #GNUNET_OK upon successfully giving the request to the ARM API (this 656 * @return the command.
360 * does not mean that the peer is successfully stopped); #GNUNET_SYSERR
361 * upon any error.
362 */ 657 */
363int 658struct GNUNET_TESTING_Command
364GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer, 659GNUNET_TESTING_cmd_signal (
365 GNUNET_TESTING_PeerStopCallback cb, 660 const char *label,
366 void *cb_cls); 661 const char *process_label,
662 int signal);
367 663
368 664
369/** 665/**
370 * Cancel a previous asynchronous peer stop request. 666 * Sleep for @a duration.
371 * GNUNET_TESTING_peer_stop_async() should have been called before on the given
372 * peer. It is an error to call this function if the peer stop callback was
373 * already called
374 * 667 *
375 * @param peer the peer on which GNUNET_TESTING_peer_stop_async() was called 668 * @param label command label.
376 * before. 669 * @param duration time to sleep
670 * @return the command.
377 */ 671 */
378void 672struct GNUNET_TESTING_Command
379GNUNET_TESTING_peer_stop_async_cancel (struct GNUNET_TESTING_Peer *peer); 673GNUNET_TESTING_cmd_sleep (
674 const char *label,
675 struct GNUNET_TIME_Relative duration);
380 676
381 677
382/** 678/**
383 * Signature of the 'main' function for a (single-peer) testcase that 679 * Command to execute a command.
384 * is run using #GNUNET_TESTING_peer_run(). 680 *
681 * @param label Label of the command.
682*/
683const struct GNUNET_TESTING_Command
684GNUNET_TESTING_cmd_exec (
685 const char *label,
686 enum GNUNET_OS_ProcessStatusType expected_type,
687 unsigned long int expected_exit_code,
688 char *const script_argv[]);
689
690
691/**
692 * Command to execute a command.
693 *
694 * @param label Label of the command.
695*/
696const struct GNUNET_TESTING_Command
697GNUNET_TESTING_cmd_exec_va (
698 const char *label,
699 enum GNUNET_OS_ProcessStatusType expected_type,
700 unsigned long int expected_exit_code,
701 ...);
702
703
704/**
705 * Make the instruction pointer point to @a target_label
706 * only if @a counter is greater than zero. Note that
707 * the command that will be executed next in this case
708 * is the one AFTER @a target_label, as the command we
709 * jump to is skipped by the advancing IP after the
710 * rewind.
711 *
712 * @param label command label
713 * @param target_label label of the new instruction pointer's destination after the jump;
714 * must be before the current instruction (and the command at the @a target_label itself will not be run, but the one afterwards)
715 * @param counter counts how many times the rewinding is to happen.
716 */
717struct GNUNET_TESTING_Command
718GNUNET_TESTING_cmd_rewind_ip (
719 const char *label,
720 const char *target_label,
721 unsigned int counter);
722
723
724/* ***************** main loop logic ************* */
725
726/**
727 * Function called with the final result of the test.
385 * 728 *
386 * @param cls closure 729 * @param cls closure
387 * @param cfg configuration of the peer that was started 730 * @param rv #GNUNET_OK if the test passed
388 * @param peer identity of the peer that was created
389 */ 731 */
390typedef void 732typedef void
391(*GNUNET_TESTING_TestMain) (void *cls, 733(*GNUNET_TESTING_ResultCallback)(
392 const struct GNUNET_CONFIGURATION_Handle *cfg, 734 void *cls,
393 struct GNUNET_TESTING_Peer *peer); 735 enum GNUNET_GenericReturnValue rv);
736
737
738/**
739 * Run the testsuite. Note, CMDs are copied into the interpreter state
740 * because they are _usually_ defined into the "run" method that returns after
741 * having scheduled the test interpreter.
742 *
743 * @param commands the array of command to execute
744 * @param timeout how long to wait for each command to execute
745 * @param rc function to call with the final result
746 * @param rc_cls closure for @a rc
747 * @return The interpreter.
748 */
749struct GNUNET_TESTING_Interpreter *
750GNUNET_TESTING_run (
751 const struct GNUNET_TESTING_Command *commands,
752 struct GNUNET_TIME_Relative timeout,
753 GNUNET_TESTING_ResultCallback rc,
754 void *rc_cls);
394 755
395 756
396/** 757/**
397 * Start a single peer and run a test using the testing library. 758 * Start a GNUnet scheduler event loop and run the testsuite. Return 0 upon
398 * Starts a peer using the given configuration and then invokes the 759 * success. Expected to be called directly from main().
399 * given callback. This function ALSO initializes the scheduler loop
400 * and should thus be called directly from "main". The testcase
401 * should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'.
402 * 760 *
403 * @param testdir only the directory name without any path. This is used for 761 * @param commands the list of command to execute
404 * all service homes; the directory will be created in a temporary 762 * @param timeout how long to wait for each command to execute
405 * location depending on the underlying OS 763 * @return EXIT_SUCCESS on success, EXIT_FAILURE on failure
406 * @param cfgfilename name of the configuration file to use;
407 * use NULL to only run with defaults
408 * @param tm main function of the testcase
409 * @param tm_cls closure for 'tm'
410 * @return 0 on success, 1 on error
411 */ 764 */
412int 765int
413GNUNET_TESTING_peer_run (const char *testdir, 766GNUNET_TESTING_main (
414 const char *cfgfilename, 767 const struct GNUNET_TESTING_Command *commands,
415 GNUNET_TESTING_TestMain tm, 768 struct GNUNET_TIME_Relative timeout);
416 void *tm_cls); 769
770
771/* ***************** plugin logic ************* */
772
773
774/**
775 * The plugin API every test case plugin has to implement.
776 */
777struct GNUNET_TESTING_PluginFunctions;
778
779
780struct GNUNET_TESTING_PluginFunctions *
781GNUNET_TESTING_make_plugin (
782 const struct GNUNET_TESTING_Command *commands);
783
784#define GNUNET_TESTING_MAKE_PLUGIN(prefix,name,...) \
785 void * \
786 prefix ## _plugin_ ## name ## _init (void *cls) { \
787 const char *my_node_id = cls; (void) my_node_id; \
788 struct GNUNET_TESTING_Command commands[] = { \
789 __VA_ARGS__, \
790 GNUNET_TESTING_cmd_end () \
791 }; \
792 return GNUNET_TESTING_make_plugin (commands); \
793 } \
794 void * \
795 prefix ## _plugin_ ## name ## _done (void *cls) { \
796 struct GNUNET_TESTING_PluginFunctions *api = cls; \
797 GNUNET_free (api); \
798 return NULL; \
799 }
800
801
802/* *** Generic trait logic for implementing traits ********* */
803
804/**
805 * A `struct GNUNET_TESTING_Trait` can be used to exchange data between cmds.
806 *
807 * Therefor the cmd which like to provide data to other cmds has to implement
808 * the trait function, where an array of traits is defined with the help of
809 * the #GNUNET_TESTING_make_trait_ macro. The data can be retrieved with the
810 * help of the #GNUNET_TESTING_get_trait_ macro. Traits name and type must be
811 * defined to make use of the macros.
812 */
813struct GNUNET_TESTING_Trait
814{
815 /**
816 * Index number associated with the trait. This gives the
817 * possibility to have _multiple_ traits on offer under the
818 * same name.
819 */
820 unsigned int index;
821
822 /**
823 * Trait type, for example "reserve-pub" or "coin-priv".
824 */
825 const char *trait_name;
826
827 /**
828 * Pointer to the piece of data to offer.
829 */
830 const void *ptr;
831};
832
833
834/**
835 * "end" of traits array. Because traits are offered into arrays, this type
836 * of trait is used to mark the end of such arrays; useful when iterating over
837 * those.
838 */
839struct GNUNET_TESTING_Trait
840GNUNET_TESTING_trait_end (void);
417 841
418 842
419/** 843/**
420 * Start a single service (no ARM, except of course if the given 844 * Obtain value of a trait from a command.
421 * service name is 'arm') and run a test using the testing library.
422 * Starts a service using the given configuration and then invokes the
423 * given callback. This function ALSO initializes the scheduler loop
424 * and should thus be called directly from "main". The testcase
425 * should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'.
426 * 845 *
427 * This function is useful if the testcase is for a single service 846 * @param traits the array of all the traits.
428 * and if that service doesn't itself depend on other services. 847 * @param[out] ret where to store the result.
848 * @param trait type of the trait to extract.
849 * @param index index number of the trait to extract.
850 * @return #GNUNET_OK when the trait is found.
851 */
852enum GNUNET_GenericReturnValue
853GNUNET_TESTING_get_trait (
854 const struct GNUNET_TESTING_Trait *traits,
855 const void **ret,
856 const char *trait,
857 unsigned int index);
858
859
860/**
861 * Create headers for a trait with name @a name for
862 * statically allocated data of type @a type.
429 * 863 *
430 * @param testdir only the directory name without any path. This is used for 864 * @param prefix symbol prefix to use
431 * all service homes; the directory will be created in a temporary 865 * @param name name of the trait
432 * location depending on the underlying OS 866 * @param type data type for the trait
433 * @param service_name name of the service to run
434 * @param cfgfilename name of the configuration file to use;
435 * use NULL to only run with defaults
436 * @param tm main function of the testcase
437 * @param tm_cls closure for @a tm
438 * @return 0 on success, 1 on error
439 */ 867 */
440int 868#define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(prefix,name,type) \
441GNUNET_TESTING_service_run (const char *testdir, 869 enum GNUNET_GenericReturnValue \
442 const char *service_name, 870 prefix ## _get_trait_ ## name ( \
443 const char *cfgfilename, 871 const struct GNUNET_TESTING_Command *cmd, \
444 GNUNET_TESTING_TestMain tm, 872 type * *ret); \
445 void *tm_cls); 873 struct GNUNET_TESTING_Trait \
874 prefix ## _make_trait_ ## name ( \
875 type * value);
446 876
447 877
448/** 878/**
449 * Sometimes we use the binary name to determine which specific 879 * Create C implementation for a trait with name @a name for statically
450 * test to run. In those cases, the string after the last "_" 880 * allocated data of type @a type.
451 * in 'argv[0]' specifies a string that determines the configuration
452 * file or plugin to use.
453 * 881 *
454 * This function returns the respective substring, taking care 882 * @param prefix symbol prefix to use
455 * of issues such as binaries ending in '.exe' on W32. 883 * @param name name of the trait
884 * @param type data type for the trait
885 */
886#define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(prefix,name,type) \
887 enum GNUNET_GenericReturnValue \
888 prefix ## _get_trait_ ## name ( \
889 const struct GNUNET_TESTING_Command *cmd, \
890 type * *ret) \
891 { \
892 if (NULL == cmd->traits) return GNUNET_SYSERR; \
893 return cmd->traits (cmd->cls, \
894 (const void **) ret, \
895 GNUNET_S (name), \
896 0); \
897 } \
898 struct GNUNET_TESTING_Trait \
899 prefix ## _make_trait_ ## name ( \
900 type * value) \
901 { \
902 struct GNUNET_TESTING_Trait ret = { \
903 .trait_name = GNUNET_S (name), \
904 .ptr = (const void *) value \
905 }; \
906 return ret; \
907 }
908
909
910/**
911 * Create headers for a trait with name @a name for
912 * statically allocated data of type @a type.
456 * 913 *
457 * @param argv0 the name of the binary 914 * @param prefix symbol prefix to use
458 * @return string between the last '_' and the '.exe' (or the end of the string), 915 * @param name name of the trait
459 * NULL if argv0 has no '_' 916 * @param type data type for the trait
460 */ 917 */
461char * 918#define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(prefix,name,type) \
462GNUNET_TESTING_get_testname_from_underscore (const char *argv0); 919 enum GNUNET_GenericReturnValue \
920 prefix ## _get_trait_ ## name ( \
921 const struct GNUNET_TESTING_Command *cmd, \
922 unsigned int index, \
923 type * *ret); \
924 struct GNUNET_TESTING_Trait \
925 prefix ## _make_trait_ ## name ( \
926 unsigned int index, \
927 type * value);
463 928
464 929
465#if 0 /* keep Emacsens' auto-indent happy */ 930/**
466{ 931 * Create C implementation for a trait with name @a name for statically
467#endif 932 * allocated data of type @a type.
468#ifdef __cplusplus 933 */
469} 934#define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(prefix,name,type) \
470#endif 935 enum GNUNET_GenericReturnValue \
936 prefix ## _get_trait_ ## name ( \
937 const struct GNUNET_TESTING_Command *cmd, \
938 unsigned int index, \
939 type * *ret) \
940 { \
941 if (NULL == cmd->traits) return GNUNET_SYSERR; \
942 return cmd->traits (cmd->cls, \
943 (const void **) ret, \
944 GNUNET_S (name), \
945 index); \
946 } \
947 struct GNUNET_TESTING_Trait \
948 prefix ## _make_trait_ ## name ( \
949 unsigned int index, \
950 type * value) \
951 { \
952 struct GNUNET_TESTING_Trait ret = { \
953 .index = index, \
954 .trait_name = GNUNET_S (name), \
955 .ptr = (const void *) value \
956 }; \
957 return ret; \
958 }
471 959
472#endif
473 960
474/** @} */ /* end of group */ 961/**
962 * Call #op on all simple traits needed by testing core logic.
963 *
964 * @param op operation to perform
965 * @param prefix prefix to pass to @e op
966 */
967#define GNUNET_TESTING_SIMPLE_TRAITS(op,prefix) \
968 op (prefix, process, struct GNUNET_OS_Process *) \
969 op (prefix, cmd, const struct GNUNET_TESTING_Command) \
970 op (prefix, batch_cmds, struct GNUNET_TESTING_Command *)
971
972
973GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT,
974 GNUNET_TESTING)
975
976
977#endif
diff --git a/src/include/gnunet_testing_netjail_lib.h b/src/include/gnunet_testing_netjail_lib.h
deleted file mode 100644
index 011db00f8..000000000
--- a/src/include/gnunet_testing_netjail_lib.h
+++ /dev/null
@@ -1,492 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @brief API for writing an interpreter to test GNUnet components
23 * @author Christian Grothoff <christian@grothoff.org>
24 * @author Marcello Stanisci
25 * @author t3sserakt
26 */
27#ifndef GNUNET_TESTING_NETJAIL_LIB_H
28#define GNUNET_TESTING_NETJAIL_LIB_H
29
30#include "gnunet_util_lib.h"
31#include "gnunet_testing_plugin.h"
32#include "gnunet_testing_ng_lib.h"
33
34
35/**
36 * Router of a netjail subnet.
37 */
38struct GNUNET_TESTING_NetjailRouter
39{
40 /**
41 * Will tcp be forwarded?
42 */
43 unsigned int tcp_port;
44
45 /**
46 * Will udp be forwarded?
47 */
48 unsigned int udp_port;
49};
50
51
52/**
53 * Enum for the different types of nodes.
54 */
55enum GNUNET_TESTING_NODE_TYPE
56{
57 /**
58 * Node in a subnet.
59 */
60 GNUNET_TESTING_SUBNET_NODE,
61
62 /**
63 * Global known node.
64 */
65 GNUNET_TESTING_GLOBAL_NODE
66};
67
68/**
69 * Protocol address prefix für a connection between nodes.
70 */
71struct GNUNET_TESTING_AddressPrefix
72{
73 /**
74 * Pointer to the previous prefix in the DLL.
75 */
76 struct GNUNET_TESTING_AddressPrefix *prev;
77
78 /**
79 * Pointer to the next prefix in the DLL.
80 */
81 struct GNUNET_TESTING_AddressPrefix *next;
82
83 /**
84 * The address prefix.
85 */
86 char *address_prefix;
87};
88
89
90/**
91 * Node in a netjail topology.
92 */
93struct GNUNET_TESTING_NetjailNode;
94
95/**
96 * Connection to another node.
97 */
98struct GNUNET_TESTING_NodeConnection
99{
100 /**
101 * Pointer to the previous connection in the DLL.
102 */
103 struct GNUNET_TESTING_NodeConnection *prev;
104
105 /**
106 * Pointer to the next connection in the DLL.
107 */
108 struct GNUNET_TESTING_NodeConnection *next;
109
110 /**
111 * The number of the subnet of the node this connection points to. This is 0,
112 * if the node is a global known node.
113 */
114 unsigned int namespace_n;
115
116 /**
117 * The number of the node this connection points to.
118 */
119 unsigned int node_n;
120
121 /**
122 * The type of the node this connection points to.
123 */
124 enum GNUNET_TESTING_NODE_TYPE node_type;
125
126 /**
127 * The node which establish the connection
128 */
129 struct GNUNET_TESTING_NetjailNode *node;
130
131 /**
132 * Head of the DLL with the address prefixes for the protocolls this node is reachable.
133 */
134 struct GNUNET_TESTING_AddressPrefix *address_prefixes_head;
135
136 /**
137 * Tail of the DLL with the address prefixes for the protocolls this node is reachable.
138 */
139 struct GNUNET_TESTING_AddressPrefix *address_prefixes_tail;
140};
141
142/**
143 * Node in the netjail topology.
144 */
145struct GNUNET_TESTING_NetjailNode
146{
147 /**
148 * Plugin for the test case to be run on this node.
149 */
150 char *plugin;
151
152 /**
153 * Flag indicating if this node is a global known node.
154 */
155 unsigned int is_global;
156
157 /**
158 * The number of the subnet this node is running in.
159 */
160 unsigned int namespace_n;
161
162 /**
163 * The number of this node in the subnet.
164 */
165 unsigned int node_n;
166
167 /**
168 * Head of the DLL with the connections which shall be established to other nodes.
169 */
170 struct GNUNET_TESTING_NodeConnection *node_connections_head;
171
172 /**
173 * Tail of the DLL with the connections which shall be established to other nodes.
174 */
175 struct GNUNET_TESTING_NodeConnection *node_connections_tail;
176};
177
178
179/**
180 * Subnet in a topology.
181 */
182struct GNUNET_TESTING_NetjailNamespace
183{
184 /**
185 * The number of the subnet.
186 */
187 unsigned int namespace_n;
188
189 /**
190 * Router of the subnet.
191 */
192 struct GNUNET_TESTING_NetjailRouter *router;
193
194 /**
195 * Hash map containing the nodes in this subnet.
196 */
197 struct GNUNET_CONTAINER_MultiShortmap *nodes;
198};
199
200/**
201 * Toplogy of our netjail setup.
202 */
203struct GNUNET_TESTING_NetjailTopology
204{
205
206 /**
207 * Default plugin for the test case to be run on nodes.
208 */
209 char *plugin;
210
211 /**
212 * Number of subnets.
213 */
214 unsigned int namespaces_n;
215
216 /**
217 * Number of nodes per subnet.
218 */
219 unsigned int nodes_m;
220
221 /**
222 * Number of global known nodes.
223 */
224 unsigned int nodes_x;
225
226 /**
227 * Hash map containing the subnets (for natted nodes) of the topology.
228 */
229 struct GNUNET_CONTAINER_MultiShortmap *map_namespaces;
230
231 /**
232 * Hash map containing the global known nodes which are not natted.
233 */
234 struct GNUNET_CONTAINER_MultiShortmap *map_globals;
235};
236
237/**
238 * Getting the topology from file.
239 *
240 * @param filename The name of the topology file.
241 * @return The GNUNET_TESTING_NetjailTopology
242 */
243struct GNUNET_TESTING_NetjailTopology *
244GNUNET_TESTING_get_topo_from_file (const char *filename);
245
246
247/**
248 * Parse the topology data.
249 *
250 * @param data The topology data.
251 * @return The GNUNET_TESTING_NetjailTopology
252 */
253struct GNUNET_TESTING_NetjailTopology *
254GNUNET_TESTING_get_topo_from_string (char *data);
255
256
257/**
258 * Get the connections to other nodes for a specific node.
259 *
260 * @param num The specific node we want the connections for.
261 * @param topology The topology we get the connections from.
262 * @return The connections of the node.
263 */
264struct GNUNET_TESTING_NodeConnection *
265GNUNET_TESTING_get_connections (unsigned int num, struct
266 GNUNET_TESTING_NetjailTopology *topology);
267
268
269/**
270 * Get the address for a specific communicator from a connection.
271 *
272 * @param connection The connection we like to have the address from.
273 * @param prefix The communicator protocol prefix.
274 * @return The address of the communicator.
275 */
276char *
277GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection,
278 char *prefix);
279
280
281/**
282 * Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.
283 *
284 * @param topology The GNUNET_TESTING_NetjailTopology to be deallocated.
285 */
286void
287GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology);
288
289
290/**
291 * Calculate the unique id identifying a node from a given connction.
292 *
293 * @param node_connection The connection we calculate the id from.
294 * @param topology The topology we get all needed information from.
295 * @return The unique id of the node from the connection.
296 */
297unsigned int
298GNUNET_TESTING_calculate_num (struct
299 GNUNET_TESTING_NodeConnection *node_connection,
300 struct GNUNET_TESTING_NetjailTopology *topology);
301
302
303/**
304 * Struct with information for callbacks.
305 *
306 */
307struct BlockState
308{
309 /**
310 * Context for our asynchronous completion.
311 */
312 struct GNUNET_TESTING_AsyncContext ac;
313
314 /**
315 * The label of this command.
316 */
317 const char *label;
318
319 /**
320 * If this command will block.
321 */
322 unsigned int asynchronous_finish;
323};
324
325/**
326 * Struct to hold information for callbacks.
327 *
328 */
329struct LocalPreparedState
330{
331 /**
332 * Context for our asynchronous completion.
333 */
334 struct GNUNET_TESTING_AsyncContext ac;
335
336 /**
337 * Callback to write messages to the master loop.
338 *
339 */
340 TESTING_CMD_HELPER_write_cb write_message;
341};
342
343
344struct GNUNET_TESTING_Command
345GNUNET_TESTING_cmd_system_destroy (const char *label,
346 const char *create_label);
347
348
349struct GNUNET_TESTING_Command
350GNUNET_TESTING_cmd_system_create (const char *label,
351 const char *testdir);
352
353
354/**
355 * Create command.
356 *
357 * @param label name for command.
358 * @param topology_config Configuration file for the test topology.
359 * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data.
360 * @return command.
361 */
362struct GNUNET_TESTING_Command
363GNUNET_TESTING_cmd_netjail_start (const char *label,
364 char *topology_config,
365 unsigned int *read_file);
366
367
368/**
369 * Create command.
370 *
371 * @param label name for command.
372 * @param topology_config Configuration file for the test topology.
373 * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data.
374 * @return command.
375 */
376struct GNUNET_TESTING_Command
377GNUNET_TESTING_cmd_netjail_stop (const char *label,
378 char *topology_config,
379 unsigned int *read_file);
380
381
382/**
383 * Create command.
384 *
385 * @param label Name for the command.
386 * @param topology The complete topology information.
387 * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data.
388 * @param topology_data If read_file is GNUNET_NO, topology_data holds the string with the topology.
389 * @return command.
390 */
391struct GNUNET_TESTING_Command
392GNUNET_TESTING_cmd_netjail_start_testing_system (
393 const char *label,
394 struct GNUNET_TESTING_NetjailTopology *topology,
395 unsigned int *read_file,
396 char *topology_data);
397
398
399/**
400 * Create command.
401 *
402 * @param label name for command.
403 * @param helper_start_label label of the cmd to start the test system.
404 * @param topology The complete topology information.
405 * @return command.
406 */
407struct GNUNET_TESTING_Command
408GNUNET_TESTING_cmd_stop_testing_system (
409 const char *label,
410 const char *helper_start_label,
411 struct GNUNET_TESTING_NetjailTopology *topology);
412
413
414/**
415 * Create a GNUNET_CMDS_LOCAL_FINISHED message.
416 *
417 * @param rv The result of the local test as GNUNET_GenericReturnValue.
418 * @return The GNUNET_CMDS_LOCAL_FINISHED message.
419*/
420struct GNUNET_MessageHeader *
421GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv);
422
423
424
425
426
427struct GNUNET_TESTING_Command
428GNUNET_TESTING_cmd_block_until_all_peers_started (
429 const char *label,
430 unsigned int *all_peers_started);
431
432
433/**
434 * Create command.
435 *
436 * @param label name for command.
437 * @param all_peers_started Flag which will be set from outside.
438 * @param asynchronous_finish If GNUNET_YES this command will not block.
439 * @return command.
440 */
441struct GNUNET_TESTING_Command
442GNUNET_TESTING_cmd_block_until_external_trigger (
443 const char *label);
444
445
446struct GNUNET_TESTING_Command
447GNUNET_TESTING_cmd_send_peer_ready (const char *label,
448 TESTING_CMD_HELPER_write_cb write_message);
449
450
451/**
452 * Create command.
453 *
454 * @param label name for command.
455 * @param write_message Callback to write messages to the master loop.
456 * @return command.
457 */
458struct GNUNET_TESTING_Command
459GNUNET_TESTING_cmd_local_test_finished (
460 const char *label,
461 TESTING_CMD_HELPER_write_cb write_message);
462
463/**
464 * Create command.
465 *
466 * @param label name for command.
467 * @param write_message Callback to write messages to the master loop.
468 * @param all_local_tests_prepared Flag which will be set from outside.
469 * @return command.
470 */
471struct GNUNET_TESTING_Command
472GNUNET_TESTING_cmd_local_test_prepared (const char *label,
473 TESTING_CMD_HELPER_write_cb
474 write_message);
475
476
477/* ***** Netjail trait support ***** */
478
479
480/**
481 * Call #op on all simple traits.
482 */
483#define GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS(op) \
484 op (test_system, const struct GNUNET_TESTING_System) \
485 op (async_context, const struct GNUNET_TESTING_AsyncContext) \
486 op (helper_handles, const struct GNUNET_HELPER_Handle *) \
487 op (local_prepared_state, const struct LocalPreparedState) \
488 op (block_state, const struct BlockState)
489
490GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT)
491
492#endif
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
deleted file mode 100644
index c0e534594..000000000
--- a/src/include/gnunet_testing_ng_lib.h
+++ /dev/null
@@ -1,769 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @brief API for writing an interpreter to test GNUnet components
23 * @author Christian Grothoff <christian@grothoff.org>
24 * @author Marcello Stanisci
25 * @author t3sserakt
26 */
27#ifndef GNUNET_TESTING_NG_LIB_H
28#define GNUNET_TESTING_NG_LIB_H
29
30#include "gnunet_util_lib.h"
31#include "gnunet_testing_plugin.h"
32#include "gnunet_testing_lib.h"
33
34/**
35 * Stringify operator.
36 *
37 * @param a some expression to stringify. Must NOT be a macro.
38 * @return same expression as a constant string.
39 */
40#define GNUNET_S(a) #a
41
42
43/* ********************* Helper functions ********************* */
44
45/**
46 * Print failing line number and trigger shutdown. Useful
47 * quite any time after the command "run" method has been called.
48 */
49#define GNUNET_TESTING_FAIL(is) \
50 do \
51 { \
52 GNUNET_break (0); \
53 GNUNET_TESTING_interpreter_fail (is); \
54 return; \
55 } while (0)
56
57
58/* ******************* Generic interpreter logic ************ */
59
60/**
61 * Global state of the interpreter, used by a command
62 * to access information about other commands.
63 */
64struct GNUNET_TESTING_Interpreter;
65
66/**
67 * State each asynchronous command must have in its closure.
68 */
69struct GNUNET_TESTING_AsyncContext
70{
71
72 /**
73 * Interpreter we are part of.
74 */
75 struct GNUNET_TESTING_Interpreter *is;
76
77 /**
78 * Function to call when done.
79 */
80 GNUNET_SCHEDULER_TaskCallback cont;
81
82 /**
83 * Closure for @e cont.
84 */
85 void *cont_cls;
86
87 /**
88 * Indication if the command finished (#GNUNET_OK).
89 * #GNUNET_NO if it did not finish,
90 * #GNUNET_SYSERR if it failed.
91 */
92 enum GNUNET_GenericReturnValue finished;
93};
94
95
96/**
97 * A command to be run by the interpreter.
98 */
99struct GNUNET_TESTING_Command
100{
101
102 /**
103 * Closure for all commands with command-specific context information.
104 */
105 void *cls;
106
107 /**
108 * Label for the command.
109 */
110 const char *label;
111
112 /**
113 * Runs the command. Note that upon return, the interpreter
114 * will not automatically run the next command, as the command
115 * may continue asynchronously in other scheduler tasks. Thus,
116 * the command must ensure to eventually call
117 * #GNUNET_TESTING_interpreter_next() or
118 * #GNUNET_TESTING_interpreter_fail().
119 *
120 * If this function creates some asynchronous activity, it should
121 * initialize @e finish to a function that can be used to wait for
122 * the asynchronous activity to terminate.
123 *
124 * @param cls closure
125 * @param is interpreter state
126 */
127 void
128 (*run)(void *cls,
129 struct GNUNET_TESTING_Interpreter *is);
130
131 /**
132 * Pointer to the asynchronous context in the command's
133 * closure. Used by the
134 * #GNUNET_TESTING_async_finish() and
135 * #GNUNET_TESTING_async_fail() functions.
136 *
137 * Must be NULL if a command is synchronous.
138 */
139 struct GNUNET_TESTING_AsyncContext *ac;
140
141 /**
142 * Clean up after the command. Run during forced termination
143 * (CTRL-C) or test failure or test success.
144 *
145 * @param cls closure
146 */
147 void
148 (*cleanup)(void *cls);
149
150 /**
151 * Extract information from a command that is useful for other
152 * commands. Can be NULL if a command has no traits.
153 *
154 * @param cls closure
155 * @param[out] ret result (could be anything)
156 * @param trait name of the trait
157 * @param index index number of the object to extract.
158 * @return #GNUNET_OK on success,
159 * #GNUNET_NO if no trait was found
160 */
161 enum GNUNET_GenericReturnValue
162 (*traits)(void *cls,
163 const void **ret,
164 const char *trait,
165 unsigned int index);
166
167 /**
168 * When did the execution of this command start?
169 */
170 struct GNUNET_TIME_Absolute start_time;
171
172 /**
173 * When did the execution of this command finish?
174 */
175 struct GNUNET_TIME_Absolute finish_time;
176
177 /**
178 * When did we start the last run of this command? Delta to @e finish_time
179 * gives the latency for the last successful run. Useful in case @e
180 * num_tries was positive and the command was run multiple times. In that
181 * case, the @e start_time gives the time when we first tried to run the
182 * command, so the difference between @e start_time and @e finish_time would
183 * be the time all of the @e num_tries took, while the delta to @e
184 * last_req_time is the time the last (successful) execution took.
185 */
186 struct GNUNET_TIME_Absolute last_req_time;
187
188 /**
189 * In case @e asynchronous_finish is true, how long should we wait for this
190 * command to complete? If @e finish did not complete after this amount of
191 * time, the interpreter will fail. Should be set generously to ensure
192 * tests do not fail on slow systems.
193 */
194 struct GNUNET_TIME_Relative default_timeout;
195
196 /**
197 * How often did we try to execute this command? (In case it is a request
198 * that is repated.) Note that a command must have some built-in retry
199 * mechanism for this value to be useful.
200 */
201 unsigned int num_tries;
202
203 /**
204 * If "true", the interpreter should not immediately call
205 * @e finish, even if @e finish is non-NULL. Otherwise,
206 * #GNUNET_TESTING_cmd_finish() must be used
207 * to ensure that a command actually completed.
208 */
209 bool asynchronous_finish;
210
211};
212
213
214/**
215 * Lookup command by label.
216 * Only future commands are looked up.
217 *
218 * @param is interpreter to lookup command in
219 * @param label label of the command to lookup.
220 * @return the command, if it is found, or NULL.
221 */
222const struct GNUNET_TESTING_Command *
223GNUNET_TESTING_interpreter_lookup_future_command (
224 struct GNUNET_TESTING_Interpreter *is,
225 const char *label);
226
227
228/**
229 * Lookup command by label.
230 *
231 * @param is interpreter to lookup command in
232 * @param label label of the command to lookup.
233 * @return the command, if it is found, or NULL.
234 */
235const struct GNUNET_TESTING_Command *
236GNUNET_TESTING_interpreter_lookup_command (
237 struct GNUNET_TESTING_Interpreter *is,
238 const char *label);
239
240
241/**
242 * Lookup command by label.
243 * All commands, first into the past, then into the furture are looked up.
244 *
245 * @param is interpreter to lookup command in
246 * @param label label of the command to lookup.
247 * @return the command, if it is found, or NULL.
248 */
249const struct GNUNET_TESTING_Command *
250GNUNET_TESTING_interpreter_lookup_command_all (
251 struct GNUNET_TESTING_Interpreter *is,
252 const char *label);
253
254
255/**
256 * Obtain label of the command being now run.
257 *
258 * @param is interpreter state.
259 * @return the label.
260 */
261const char *
262GNUNET_TESTING_interpreter_get_current_label (
263 struct GNUNET_TESTING_Interpreter *is);
264
265
266/**
267 * Current command failed, clean up and fail the test case.
268 *
269 * @param is interpreter state.
270 */
271void
272GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is);
273
274
275/**
276 * The asynchronous command of @a ac has failed.
277 *
278 * @param ac command-specific context
279 */
280void
281GNUNET_TESTING_async_fail (struct GNUNET_TESTING_AsyncContext *ac);
282
283
284/**
285 * The asynchronous command of @a ac has finished.
286 *
287 * @param ac command-specific context
288 */
289void
290GNUNET_TESTING_async_finish (struct GNUNET_TESTING_AsyncContext *ac);
291
292
293/**
294 * Create command array terminator.
295 *
296 * @return a end-command.
297 */
298struct GNUNET_TESTING_Command
299GNUNET_TESTING_cmd_end (void);
300
301
302/**
303 * Turn asynchronous command into non blocking command by setting asynchronous_finish to true.
304 *
305 * @param cmd command to make synchronous.
306 * @return a finish-command.
307 */
308struct GNUNET_TESTING_Command
309GNUNET_TESTING_cmd_make_unblocking (struct GNUNET_TESTING_Command cmd);
310
311
312/**
313 * Create (synchronous) command that waits for another command to finish.
314 * If @a cmd_ref did not finish after @a timeout, this command will fail
315 * the test case.
316 *
317 * @param finish_label label for this command
318 * @param cmd_ref reference to a previous command which we should
319 * wait for (call `finish()` on)
320 * @param timeout how long to wait at most for @a cmd_ref to finish
321 * @return a finish-command.
322 */
323const struct GNUNET_TESTING_Command
324GNUNET_TESTING_cmd_finish (const char *finish_label,
325 const char *cmd_ref,
326 struct GNUNET_TIME_Relative timeout);
327
328
329/**
330 * Make the instruction pointer point to @a target_label
331 * only if @a counter is greater than zero.
332 *
333 * @param label command label
334 * @param target_label label of the new instruction pointer's destination after the jump;
335 * must be before the current instruction
336 * @param counter counts how many times the rewinding is to happen.
337 */
338struct GNUNET_TESTING_Command
339GNUNET_TESTING_cmd_rewind_ip (const char *label,
340 const char *target_label,
341 unsigned int counter);
342
343
344/**
345 * Function called with the final result of the test.
346 *
347 * @param cls closure
348 * @param rv #GNUNET_OK if the test passed
349 */
350typedef void
351(*GNUNET_TESTING_ResultCallback)(void *cls,
352 enum GNUNET_GenericReturnValue rv);
353
354
355/**
356 * Run the testsuite. Note, CMDs are copied into
357 * the interpreter state because they are _usually_
358 * defined into the "run" method that returns after
359 * having scheduled the test interpreter.
360 *
361 * @param commands the list of command to execute
362 * @param timeout how long to wait for each command to execute
363 * @param rc function to call with the final result
364 * @param rc_cls closure for @a rc
365 */
366void
367GNUNET_TESTING_run (struct GNUNET_TESTING_Command *commands,
368 struct GNUNET_TIME_Relative timeout,
369 GNUNET_TESTING_ResultCallback rc,
370 void *rc_cls);
371
372
373/**
374 * Start a GNUnet scheduler event loop and
375 * run the testsuite. Return 0 upon success.
376 * Expected to be called directly from main().
377 *
378 * @param commands the list of command to execute
379 * @param timeout how long to wait for each command to execute
380 * @return EXIT_SUCCESS on success, EXIT_FAILURE on failure
381 */
382int
383GNUNET_TESTING_main (struct GNUNET_TESTING_Command *commands,
384 struct GNUNET_TIME_Relative timeout);
385
386
387/**
388 * Look for substring in a programs' name.
389 *
390 * @param prog program's name to look into
391 * @param marker chunk to find in @a prog
392 * // FIXME: this does not belong here! => libgnunetutil, maybe?
393 * // FIXME: return bool? document return value!
394 */
395int
396GNUNET_TESTING_has_in_name (const char *prog,
397 const char *marker);
398
399
400/* ************** Specific interpreter commands ************ */
401
402
403/**
404 * Returns the actual running command.
405 *
406 * @param is Global state of the interpreter, used by a command
407 * to access information about other commands.
408 * @return The actual running command.
409 */
410struct GNUNET_TESTING_Command *
411GNUNET_TESTING_interpreter_get_current_command (
412 struct GNUNET_TESTING_Interpreter *is);
413
414
415/**
416 * Check if the command is running.
417 *
418 * @param cmd The command to check.
419 * @return GNUNET_NO if the command is not running, GNUNET_YES if it is running.
420 */
421enum GNUNET_GenericReturnValue
422GNUNET_TESTING_running (const struct GNUNET_TESTING_Command *command);
423
424
425/**
426 * Check if a command is finished.
427 *
428 * @param cmd The command to check.
429 * @return GNUNET_NO if the command is not finished, GNUNET_YES if it is finished.
430 */
431enum GNUNET_GenericReturnValue
432GNUNET_TESTING_finished (struct GNUNET_TESTING_Command *command);
433
434
435/**
436 * Create a "signal" CMD.
437 *
438 * @param label command label.
439 * @param process_label label of a command that has a process trait
440 * @param process_index index of the process trait at @a process_label // FIXME: enum? needed?
441 * @param signal signal to send to @a process.
442 * @return the command.
443 */
444struct GNUNET_TESTING_Command
445GNUNET_TESTING_cmd_signal (const char *label,
446 const char *process_label,
447 unsigned int process_index,
448 int signal);
449
450
451/**
452 * Sleep for @a duration.
453 *
454 * @param label command label.
455 * @param duration time to sleep
456 * @return the command.
457 */
458struct GNUNET_TESTING_Command
459GNUNET_TESTING_cmd_sleep (const char *label,
460 struct GNUNET_TIME_Relative duration);
461
462
463/**
464 * Create a "batch" command. Such command takes a end_CMD-terminated array of
465 * CMDs and executed them. Once it hits the end CMD, it passes the control to
466 * the next top-level CMD, regardless of it being another batch or ordinary
467 * CMD.
468 *
469 * @param label the command label.
470 * @param batch array of CMDs to execute.
471 * @return the command.
472 */
473struct GNUNET_TESTING_Command
474GNUNET_TESTING_cmd_batch (const char *label,
475 struct GNUNET_TESTING_Command *batch);
476
477
478/**
479 * Performance counter.
480 * // FIXME: this might not belong here!
481 */
482struct GNUNET_TESTING_Timer
483{
484 /**
485 * For which type of commands.
486 */
487 const char *prefix;
488
489 /**
490 * Total time spend in all commands of this type.
491 */
492 struct GNUNET_TIME_Relative total_duration;
493
494 /**
495 * Total time spend waiting for the *successful* exeuction
496 * in all commands of this type.
497 */
498 struct GNUNET_TIME_Relative success_latency;
499
500 /**
501 * Number of commands summed up.
502 */
503 unsigned int num_commands;
504
505 /**
506 * Number of retries summed up.
507 */
508 unsigned int num_retries;
509};
510
511
512/**
513 * Getting the topology from file.
514 *
515 * @param filename The name of the topology file.
516 * @return The GNUNET_TESTING_NetjailTopology
517 */
518struct GNUNET_TESTING_NetjailTopology *
519GNUNET_TESTING_get_topo_from_file (const char *filename);
520
521
522/**
523 * Parse the topology data.
524 *
525 * @param data The topology data.
526 * @return The GNUNET_TESTING_NetjailTopology
527 */
528struct GNUNET_TESTING_NetjailTopology *
529GNUNET_TESTING_get_topo_from_string (char *data);
530
531
532/**
533 * Get the connections to other nodes for a specific node.
534 *
535 * @param num The specific node we want the connections for.
536 * @param topology The topology we get the connections from.
537 * @return The connections of the node.
538 */
539struct GNUNET_TESTING_NodeConnection *
540GNUNET_TESTING_get_connections (unsigned int num, struct
541 GNUNET_TESTING_NetjailTopology *topology);
542
543
544/**
545 * Get the address for a specific communicator from a connection.
546 *
547 * @param connection The connection we like to have the address from.
548 * @param prefix The communicator protocol prefix.
549 * @return The address of the communicator.
550 */
551char *
552GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection,
553 char *prefix);
554
555
556/**
557 * Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.
558 *
559 * @param topology The GNUNET_TESTING_NetjailTopology to be deallocated.
560 */
561void
562GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology);
563
564
565/**
566 * Calculate the unique id identifying a node from a given connction.
567 *
568 * @param node_connection The connection we calculate the id from.
569 * @param topology The topology we get all needed information from.
570 * @return The unique id of the node from the connection.
571 */
572unsigned int
573GNUNET_TESTING_calculate_num (struct
574 GNUNET_TESTING_NodeConnection *node_connection,
575 struct GNUNET_TESTING_NetjailTopology *topology);
576
577
578/**
579 * Retrieve the public key from the test system with the unique node id.
580 *
581 * @param num The unique node id.
582 * @param tl_system The test system.
583 * @return The peer identity wrapping the public key.
584 */
585struct GNUNET_PeerIdentity *
586GNUNET_TESTING_get_pub_key (unsigned int num,
587 const struct GNUNET_TESTING_System *tl_system);
588
589
590/**
591 * Obtain performance data from the interpreter.
592 *
593 * @param timers what commands (by label) to obtain runtimes for
594 * @return the command
595 */
596struct GNUNET_TESTING_Command
597GNUNET_TESTING_cmd_stat (struct GNUNET_TESTING_Timer *timers);
598
599
600/* *** Generic trait logic for implementing traits ********* */
601
602/**
603 * A trait.
604 */
605struct GNUNET_TESTING_Trait
606{
607 /**
608 * Index number associated with the trait. This gives the
609 * possibility to have _multiple_ traits on offer under the
610 * same name.
611 */
612 unsigned int index;
613
614 /**
615 * Trait type, for example "reserve-pub" or "coin-priv".
616 */
617 const char *trait_name;
618
619 /**
620 * Pointer to the piece of data to offer.
621 */
622 const void *ptr;
623};
624
625
626/**
627 * "end" trait. Because traits are offered into arrays,
628 * this type of trait is used to mark the end of such arrays;
629 * useful when iterating over those.
630 */
631struct GNUNET_TESTING_Trait
632GNUNET_TESTING_trait_end (void);
633
634
635/**
636 * Extract a trait.
637 *
638 * @param traits the array of all the traits.
639 * @param[out] ret where to store the result.
640 * @param trait type of the trait to extract.
641 * @param index index number of the trait to extract.
642 * @return #GNUNET_OK when the trait is found.
643 */
644enum GNUNET_GenericReturnValue
645GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits,
646 const void **ret,
647 const char *trait,
648 unsigned int index);
649
650
651/* ****** Specific traits supported by this component ******* */
652
653
654/**
655 * Create headers for a trait with name @a name for
656 * statically allocated data of type @a type.
657 */
658#define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(name,type) \
659 enum GNUNET_GenericReturnValue \
660 GNUNET_TESTING_get_trait_ ## name ( \
661 const struct GNUNET_TESTING_Command *cmd, \
662 type **ret); \
663 struct GNUNET_TESTING_Trait \
664 GNUNET_TESTING_make_trait_ ## name ( \
665 type * value);
666
667
668/**
669 * Create C implementation for a trait with name @a name for statically
670 * allocated data of type @a type.
671 */
672#define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(name,type) \
673 enum GNUNET_GenericReturnValue \
674 GNUNET_TESTING_get_trait_ ## name ( \
675 const struct GNUNET_TESTING_Command *cmd, \
676 type **ret) \
677 { \
678 if (NULL == cmd->traits) return GNUNET_SYSERR; \
679 return cmd->traits (cmd->cls, \
680 (const void **) ret, \
681 GNUNET_S (name), \
682 0); \
683 } \
684 struct GNUNET_TESTING_Trait \
685 GNUNET_TESTING_make_trait_ ## name ( \
686 type * value) \
687 { \
688 struct GNUNET_TESTING_Trait ret = { \
689 .trait_name = GNUNET_S (name), \
690 .ptr = (const void *) value \
691 }; \
692 return ret; \
693 }
694
695
696/**
697 * Create headers for a trait with name @a name for
698 * statically allocated data of type @a type.
699 */
700#define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(name,type) \
701 enum GNUNET_GenericReturnValue \
702 GNUNET_TESTING_get_trait_ ## name ( \
703 const struct GNUNET_TESTING_Command *cmd, \
704 unsigned int index, \
705 type **ret); \
706 struct GNUNET_TESTING_Trait \
707 GNUNET_TESTING_make_trait_ ## name ( \
708 unsigned int index, \
709 type * value);
710
711
712/**
713 * Create C implementation for a trait with name @a name for statically
714 * allocated data of type @a type.
715 */
716#define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(name,type) \
717 enum GNUNET_GenericReturnValue \
718 GNUNET_TESTING_get_trait_ ## name ( \
719 const struct GNUNET_TESTING_Command *cmd, \
720 unsigned int index, \
721 type **ret) \
722 { \
723 if (NULL == cmd->traits) return GNUNET_SYSERR; \
724 return cmd->traits (cmd->cls, \
725 (const void **) ret, \
726 GNUNET_S (name), \
727 index); \
728 } \
729 struct GNUNET_TESTING_Trait \
730 GNUNET_TESTING_make_trait_ ## name ( \
731 unsigned int index, \
732 type * value) \
733 { \
734 struct GNUNET_TESTING_Trait ret = { \
735 .index = index, \
736 .trait_name = GNUNET_S (name), \
737 .ptr = (const void *) value \
738 }; \
739 return ret; \
740 }
741
742
743/**
744 * Call #op on all simple traits.
745 */
746#define GNUNET_TESTING_SIMPLE_TRAITS(op) \
747 op (process, struct GNUNET_OS_Process *)
748
749
750/**
751 * Call #op on all indexed traits.
752 */
753#define GNUNET_TESTING_INDEXED_TRAITS(op) \
754 op (uint32, const uint32_t) \
755 op (uint64, const uint64_t) \
756 op (int64, const int64_t) \
757 op (uint, const unsigned int) \
758 op (string, const char) \
759 op (cmd, const struct GNUNET_TESTING_Command) \
760 op (uuid, const struct GNUNET_Uuid) \
761 op (time, const struct GNUNET_TIME_Absolute) \
762 op (absolute_time, const struct GNUNET_TIME_Absolute) \
763 op (relative_time, const struct GNUNET_TIME_Relative)
764
765GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT)
766
767GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT)
768
769#endif
diff --git a/src/include/gnunet_testing_plugin.h b/src/include/gnunet_testing_plugin.h
deleted file mode 100644
index b59d2cea1..000000000
--- a/src/include/gnunet_testing_plugin.h
+++ /dev/null
@@ -1,83 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 *
23 * @author t3sserakt
24 *
25 * Plugin API to start test cases.
26 *
27 */
28#ifndef GNUNET_TESTING_PLUGIN_H
29#define GNUNET_TESTING_PLUGIN_H
30
31#ifdef __cplusplus
32extern "C"
33{
34#if 0 /* keep Emacsens' auto-indent happy */
35}
36#endif
37#endif
38
39typedef void
40(*TESTING_CMD_HELPER_write_cb) (struct GNUNET_MessageHeader *message, size_t
41 msg_length);
42
43typedef void
44(*GNUNET_TESTING_PLUGIN_StartTestCase) (TESTING_CMD_HELPER_write_cb
45 write_message, char *router_ip,
46 char *node_ip,
47 char *n,
48 char *m,
49 char *local_m,
50 char *topology_data,
51 unsigned int *read_file);
52
53
54typedef void
55(*GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED) ();
56
57
58typedef void
59(*GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED) ();
60
61
62struct GNUNET_TESTING_PluginFunctions
63{
64 /**
65 * Closure for all of the callbacks.
66 */
67 void *cls;
68
69 GNUNET_TESTING_PLUGIN_StartTestCase start_testcase;
70
71 GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED all_peers_started;
72
73 GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED all_local_tests_prepared;
74};
75
76#if 0 /* keep Emacsens' auto-indent happy */
77{
78#endif
79#ifdef __cplusplus
80}
81#endif
82
83#endif
diff --git a/src/include/gnunet_testing_testbed_lib.h b/src/include/gnunet_testing_testbed_lib.h
new file mode 100644
index 000000000..872382706
--- /dev/null
+++ b/src/include/gnunet_testing_testbed_lib.h
@@ -0,0 +1,42 @@
1#ifndef GNUNET_TESTING_TESTBED_LIB_H
2#define GNUNET_TESTING_TESTBED_LIB_H
3
4#include "gnunet_testing_lib.h"
5#include "gnunet_testbed_lib.h"
6
7/**
8 * This command destroys the ressources allocated for the test system setup.
9 *
10 * @param label Name for command.
11 * @param create_label Label of the cmd which started the test system.
12 * @param write_message Callback to write messages to the master loop.
13 * @return command.
14 */
15struct GNUNET_TESTING_Command
16GNUNET_TESTBED_cmd_system_destroy (const char *label,
17 const char *create_label);
18
19/**
20 * This command is setting up a test environment for a peer to start.
21 *
22 * @param label Name for command.
23 * @param testdir Only the directory name without any path. Temporary
24 * directory used for all service homes.
25 */
26struct GNUNET_TESTING_Command
27GNUNET_TESTBED_cmd_system_create (const char *label,
28 const char *testdir);
29
30
31/**
32 * Call #op on all simple traits.
33 */
34#define GNUNET_TESTING_TESTBED_SIMPLE_TRAITS(op, prefix) \
35 op (prefix, test_system, struct GNUNET_TESTBED_System)
36
37
38GNUNET_TESTING_TESTBED_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT,
39 GNUNET_TESTING_TESTBED)
40
41
42#endif
diff --git a/src/include/gnunet_testing_transport_lib.h b/src/include/gnunet_testing_transport_lib.h
new file mode 100644
index 000000000..db2749661
--- /dev/null
+++ b/src/include/gnunet_testing_transport_lib.h
@@ -0,0 +1,205 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021-2023 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @brief API for cmds working with transport sub system.
23 * @author t3sserakt
24 */
25#ifndef GNUNET_TRANSPORT_TESTING_NG_LIB_H
26#define GNUNET_TRANSPORT_TESTING_NG_LIB_H
27
28
29#include "gnunet_util_lib.h"
30#include "gnunet_testing_lib.h"
31
32/**
33 * Application handle; FIXME: what exactly is this?
34 */
35struct GNUNET_TRANSPORT_ApplicationHandle;
36
37
38// FIXME: breaks naming conventions
39typedef void *
40(*GNUNET_TESTING_notify_connect_cb) (struct GNUNET_TESTING_Interpreter *is,
41 const struct GNUNET_PeerIdentity *peer);
42
43
44// FIXME: breaks naming conventions! Needed public?
45struct GNUNET_TESTING_StartPeerState
46{
47 /**
48 * Context for our asynchronous completion.
49 */
50 struct GNUNET_TESTING_AsyncContext ac;
51
52 /**
53 * The ip of a node.
54 */
55 char *node_ip;
56
57 /**
58 * Receive callback
59 */
60 struct GNUNET_MQ_MessageHandler *handlers;
61
62 /**
63 * GNUnet configuration file used to start a peer.
64 */
65 char *cfgname;
66
67 /**
68 * Peer's configuration
69 */
70 struct GNUNET_CONFIGURATION_Handle *cfg;
71
72 /**
73 * struct GNUNET_TESTING_Peer returned by GNUNET_TESTING_peer_configure.
74 */
75 struct GNUNET_TESTING_Peer *peer;
76
77 /**
78 * Peer identity
79 */
80 struct GNUNET_PeerIdentity id;
81
82 /**
83 * Peer's transport service handle
84 */
85 struct GNUNET_TRANSPORT_CoreHandle *th;
86
87 /**
88 * Application handle
89 */
90 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
91
92 /**
93 * Peer's PEERSTORE Handle
94 */
95 struct GNUNET_PEERSTORE_Handle *ph;
96
97 /**
98 * Hello get task
99 */
100 struct GNUNET_SCHEDULER_Task *rh_task;
101
102 /**
103 * Peer's transport get hello handle to retrieve peer's HELLO message
104 */
105 struct GNUNET_PEERSTORE_IterateContext *pic;
106
107 /**
108 * Hello
109 */
110 char *hello;
111
112 /**
113 * Hello size
114 */
115 size_t hello_size;
116
117 /**
118 * The label of the command which was started by calling GNUNET_TESTING_cmd_system_create.
119 */
120 char *system_label;
121
122 /**
123 * An unique number to identify the peer
124 */
125 unsigned int no;
126
127 /**
128 * A map with struct GNUNET_MQ_Handle values for each peer this peer
129 * is connected to.
130 */
131 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
132
133 /**
134 * Test setup for this peer.
135 */
136 const struct GNUNET_TESTING_System *tl_system;
137
138 /**
139 * Callback which is called on neighbour connect events.
140 */
141 GNUNET_TESTING_notify_connect_cb notify_connect;
142
143 /**
144 * Flag indicating, if udp broadcast should be switched on.
145 */
146 enum GNUNET_GenericReturnValue broadcast;
147};
148
149
150/**
151 * Create command.
152 *
153 * @param label name for command.
154 * @param system_label Label of the cmd to setup a test environment.
155 * @param no Decimal number representing the last byte of the IP address of this peer.
156 * @param node_ip The IP address of this node.
157 * @param cfgname Configuration file name for this peer.
158 * @param broadcast Flag indicating, if broadcast should be switched on.
159 * @return command.
160 */
161struct GNUNET_TESTING_Command
162GNUNET_TESTING_cmd_start_peer (const char *label,
163 const char *system_label,
164 uint32_t no,
165 const char *node_ip,
166 const char *cfgname,
167 unsigned int broadcast);
168
169
170struct GNUNET_TESTING_Command
171GNUNET_TESTING_cmd_stop_peer (const char *label,
172 const char *start_label);
173
174
175/**
176 * Retrieve peer identity from the test system with the unique node id.
177 *
178 * @param num The unique node id.
179 * @param tl_system The test system.
180 * @return The peer identity wrapping the public key.
181 */
182struct GNUNET_PeerIdentity *
183GNUNET_TESTING_get_peer (unsigned int num,
184 const struct GNUNET_TESTING_System *tl_system);
185
186
187/**
188 * Call #op on all simple traits.
189 */
190#define GNUNET_TRANSPORT_TESTING_SIMPLE_TRAITS(op, prefix) \
191 op (prefix, connected_peers_map, const struct \
192 GNUNET_CONTAINER_MultiShortmap) \
193 op (prefix, peer_id, const struct GNUNET_PeerIdentity) \
194 op (prefix, hello_size, const size_t) \
195 op (prefix, hello, const char) \
196 op (prefix, application_handle, const struct \
197 GNUNET_TRANSPORT_ApplicationHandle) \
198 op (prefix, state, const struct GNUNET_TESTING_StartPeerState) \
199 op (prefix, broadcast, const enum GNUNET_GenericReturnValue)
200
201
202GNUNET_TRANSPORT_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT,
203 GNUNET_TRANSPORT_TESTING)
204
205#endif
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h
index 26b442066..88dafc62c 100644
--- a/src/include/gnunet_time_lib.h
+++ b/src/include/gnunet_time_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
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-2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * 27 *
24 * @file 28 * @file
@@ -40,6 +44,7 @@ extern "C"
40#endif 44#endif
41#endif 45#endif
42 46
47
43#include "gnunet_common.h" 48#include "gnunet_common.h"
44 49
45/** 50/**
@@ -54,6 +59,17 @@ struct GNUNET_TIME_Absolute
54}; 59};
55 60
56/** 61/**
62 * Rounded time for timestamps used by GNUnet, in seconds.
63 */
64struct GNUNET_TIME_Timestamp
65{
66 /**
67 * The actual value. Must be round number in seconds.
68 */
69 struct GNUNET_TIME_Absolute abs_time;
70};
71
72/**
57 * Time for relative time used by GNUnet, in microseconds. 73 * Time for relative time used by GNUnet, in microseconds.
58 * Always positive, so we can only refer to future time. 74 * Always positive, so we can only refer to future time.
59 */ 75 */
@@ -89,17 +105,34 @@ struct GNUNET_TIME_AbsoluteNBO
89 */ 105 */
90 uint64_t abs_value_us__ GNUNET_PACKED; 106 uint64_t abs_value_us__ GNUNET_PACKED;
91}; 107};
108
109/**
110 * Time for timestamps used by GNUnet, in seconds and in network byte order.
111 */
112struct GNUNET_TIME_TimestampNBO
113{
114 /**
115 * The actual value. Must be round number in seconds.
116 */
117 struct GNUNET_TIME_AbsoluteNBO abs_time_nbo;
118};
119
92GNUNET_NETWORK_STRUCT_END 120GNUNET_NETWORK_STRUCT_END
93 121
94/** 122/**
95 * Relative time zero. 123 * Relative time zero.
96 */ 124 */
97#define GNUNET_TIME_UNIT_ZERO GNUNET_TIME_relative_get_zero_ () 125#define GNUNET_TIME_UNIT_ZERO ((struct GNUNET_TIME_Relative){0})
98 126
99/** 127/**
100 * Absolute time zero. 128 * Absolute time zero.
101 */ 129 */
102#define GNUNET_TIME_UNIT_ZERO_ABS GNUNET_TIME_absolute_get_zero_ () 130#define GNUNET_TIME_UNIT_ZERO_ABS ((struct GNUNET_TIME_Absolute){0})
131
132/**
133 * Timestamp of zero.
134 */
135#define GNUNET_TIME_UNIT_ZERO_TS ((struct GNUNET_TIME_Timestamp){{0}})
103 136
104/** 137/**
105 * One microsecond, our basic time unit. 138 * One microsecond, our basic time unit.
@@ -154,13 +187,22 @@ GNUNET_NETWORK_STRUCT_END
154 * Constant used to specify "forever". This constant 187 * Constant used to specify "forever". This constant
155 * will be treated specially in all time operations. 188 * will be treated specially in all time operations.
156 */ 189 */
157#define GNUNET_TIME_UNIT_FOREVER_REL GNUNET_TIME_relative_get_forever_ () 190#define GNUNET_TIME_UNIT_FOREVER_REL \
191 ((struct GNUNET_TIME_Relative){UINT64_MAX})
192
193/**
194 * Constant used to specify "forever". This constant
195 * will be treated specially in all time operations.
196 */
197#define GNUNET_TIME_UNIT_FOREVER_ABS \
198 ((struct GNUNET_TIME_Absolute){UINT64_MAX})
158 199
159/** 200/**
160 * Constant used to specify "forever". This constant 201 * Constant used to specify "forever". This constant
161 * will be treated specially in all time operations. 202 * will be treated specially in all time operations.
162 */ 203 */
163#define GNUNET_TIME_UNIT_FOREVER_ABS GNUNET_TIME_absolute_get_forever_ () 204#define GNUNET_TIME_UNIT_FOREVER_TS \
205 ((struct GNUNET_TIME_Timestamp){{UINT64_MAX}})
164 206
165 207
166/** 208/**
@@ -183,6 +225,47 @@ GNUNET_NETWORK_STRUCT_END
183 225
184 226
185/** 227/**
228 * Convert @a ts to human-readable timestamp.
229 * Note that the returned value will be overwritten if this function
230 * is called again.
231 *
232 * @param ts the timestamp to convert
233 * @return statically allocated string, will change on the next call
234 */
235const char *
236GNUNET_TIME_timestamp2s (struct GNUNET_TIME_Timestamp ts);
237
238
239/**
240 * @ingroup time
241 * Like `asctime`, except for GNUnet time. Converts a GNUnet internal
242 * absolute time (which is in UTC) to a string in local time.
243 * Note that the returned value will be overwritten if this function
244 * is called again.
245 *
246 * @param ts the absolute time to convert
247 * @return timestamp in human-readable form in local time
248 */
249const char *
250GNUNET_TIME_absolute2s (struct GNUNET_TIME_Absolute ts);
251
252
253/**
254 * @ingroup time
255 * Give relative time in human-readable fancy format.
256 * This is one of the very few calls in the entire API that is
257 * NOT reentrant!
258 *
259 * @param delta time in milli seconds
260 * @param do_round are we allowed to round a bit?
261 * @return string in human-readable form
262 */
263const char *
264GNUNET_TIME_relative2s (struct GNUNET_TIME_Relative delta,
265 bool do_round);
266
267
268/**
186 * Randomized exponential back-off, starting at 1 ms 269 * Randomized exponential back-off, starting at 1 ms
187 * and going up by a factor of 2+r, where 0 <= r <= 0.5, up 270 * and going up by a factor of 2+r, where 0 <= r <= 0.5, up
188 * to a maximum of the given threshold. 271 * to a maximum of the given threshold.
@@ -192,8 +275,8 @@ GNUNET_NETWORK_STRUCT_END
192 * @return the next backoff time 275 * @return the next backoff time
193 */ 276 */
194struct GNUNET_TIME_Relative 277struct GNUNET_TIME_Relative
195GNUNET_TIME_randomized_backoff (struct GNUNET_TIME_Relative rt, struct 278GNUNET_TIME_randomized_backoff (struct GNUNET_TIME_Relative rt,
196 GNUNET_TIME_Relative threshold); 279 struct GNUNET_TIME_Relative threshold);
197 280
198 281
199/** 282/**
@@ -290,27 +373,69 @@ GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel);
290 373
291 374
292/** 375/**
293 * Round a time value so that it is suitable for transmission 376 * Convert relative time to a timestamp in the
294 * via JSON encodings. 377 * future.
378 *
379 * @param rel relative time to convert
380 * @return timestamp that is "rel" in the future, or FOREVER if rel==FOREVER (or if we would overflow)
381 */
382struct GNUNET_TIME_Timestamp
383GNUNET_TIME_relative_to_timestamp (struct GNUNET_TIME_Relative rel);
384
385
386/**
387 * Round an absolute time to a timestamp.
295 * 388 *
296 * @param at time to round 389 * @param at time to round
297 * @return #GNUNET_OK if time was already rounded, #GNUNET_NO if 390 * @return the result
298 * it was just now rounded
299 */ 391 */
300int 392struct GNUNET_TIME_Timestamp
301GNUNET_TIME_round_abs (struct GNUNET_TIME_Absolute *at); 393GNUNET_TIME_absolute_to_timestamp (struct GNUNET_TIME_Absolute at);
302 394
303 395
304/** 396/**
305 * Round a time value so that it is suitable for transmission 397 * Get timestamp representing the current time.
306 * via JSON encodings.
307 * 398 *
308 * @param rt time to round 399 * @return current time, rounded down to seconds
309 * @return #GNUNET_OK if time was already rounded, #GNUNET_NO if
310 * it was just now rounded
311 */ 400 */
312int 401struct GNUNET_TIME_Timestamp
313GNUNET_TIME_round_rel (struct GNUNET_TIME_Relative *rt); 402GNUNET_TIME_timestamp_get (void);
403
404
405/**
406 * Compare two absolute times.
407 *
408 * @param t1 first time
409 * @param op compare operator
410 * @param t2 second time
411 * @return true if @a t1 @a op @a t2
412 */
413#define GNUNET_TIME_absolute_cmp(t1,op,t2) \
414 ((void) (1 op 2), (t1).abs_value_us op (t2).abs_value_us)
415
416
417/**
418 * Compare two timestamps
419 *
420 * @param t1 first timestamp
421 * @param op compare operator
422 * @param t2 second timestamp
423 * @return true if @a t1 @a op @a t2
424 */
425#define GNUNET_TIME_timestamp_cmp(t1,op,t2) \
426 GNUNET_TIME_absolute_cmp ((t1).abs_time,op,(t2).abs_time)
427
428
429/**
430 * Compare two relative times.
431 *
432 * @param t1 first time
433 * @param op compare operator
434 * @param t2 second time
435 * @return true if @a t1 @a op @a t2
436 */
437#define GNUNET_TIME_relative_cmp(t1,op,t2) \
438 ((void) (1 op 2), (t1).rel_value_us op (t2).rel_value_us)
314 439
315 440
316/** 441/**
@@ -362,6 +487,42 @@ GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1,
362 487
363 488
364/** 489/**
490 * Round down absolute time @a at to multiple of @a rt.
491 *
492 * @param at absolute time to round
493 * @param rt multiple to round to (non-zero)
494 * @return rounded time
495 */
496struct GNUNET_TIME_Absolute
497GNUNET_TIME_absolute_round_down (struct GNUNET_TIME_Absolute at,
498 struct GNUNET_TIME_Relative rt);
499
500
501/**
502 * Return the maximum of two timestamps.
503 *
504 * @param t1 first timestamp
505 * @param t2 other timestamp
506 * @return timestamp that is smaller
507 */
508struct GNUNET_TIME_Timestamp
509GNUNET_TIME_timestamp_max (struct GNUNET_TIME_Timestamp t1,
510 struct GNUNET_TIME_Timestamp t2);
511
512
513/**
514 * Return the minimum of two timestamps.
515 *
516 * @param t1 first timestamp
517 * @param t2 other timestamp
518 * @return timestamp that is smaller
519 */
520struct GNUNET_TIME_Timestamp
521GNUNET_TIME_timestamp_min (struct GNUNET_TIME_Timestamp t1,
522 struct GNUNET_TIME_Timestamp t2);
523
524
525/**
365 * Given a timestamp in the future, how much time 526 * Given a timestamp in the future, how much time
366 * remains until then? 527 * remains until then?
367 * 528 *
@@ -373,6 +534,21 @@ GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future);
373 534
374 535
375/** 536/**
537 * Test if @a a1 and @a a2 are equal within a margin of
538 * error of @a t.
539 *
540 * @param a1 time to compare
541 * @param a2 time to compare
542 * @param t tolerance to apply
543 * @return true if "|a1-a2|<=t" holds.
544 */
545bool
546GNUNET_TIME_absolute_approx_eq (struct GNUNET_TIME_Absolute a1,
547 struct GNUNET_TIME_Absolute a2,
548 struct GNUNET_TIME_Relative t);
549
550
551/**
376 * Calculate the estimate time of arrival/completion 552 * Calculate the estimate time of arrival/completion
377 * for an operation. 553 * for an operation.
378 * 554 *
@@ -443,6 +619,17 @@ GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start,
443 * Multiply relative time by a given factor. 619 * Multiply relative time by a given factor.
444 * 620 *
445 * @param rel some duration 621 * @param rel some duration
622 * @param factor double to multiply with
623 * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
624 */
625struct GNUNET_TIME_Relative
626GNUNET_TIME_relative_multiply_double (struct GNUNET_TIME_Relative rel,
627 double factor);
628
629/**
630 * Multiply relative time by a given factor.
631 *
632 * @param rel some duration
446 * @param factor integer to multiply with 633 * @param factor integer to multiply with
447 * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor 634 * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
448 */ 635 */
@@ -530,6 +717,16 @@ GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a);
530 717
531 718
532/** 719/**
720 * Convert timestamp to network byte order.
721 *
722 * @param t time to convert
723 * @return converted time value
724 */
725struct GNUNET_TIME_TimestampNBO
726GNUNET_TIME_timestamp_hton (struct GNUNET_TIME_Timestamp t);
727
728
729/**
533 * Convert milliseconds after the UNIX epoch to absolute time. 730 * Convert milliseconds after the UNIX epoch to absolute time.
534 * 731 *
535 * @param ms_after_epoch millisecond timestamp to convert 732 * @param ms_after_epoch millisecond timestamp to convert
@@ -558,6 +755,15 @@ GNUNET_TIME_absolute_is_past (struct GNUNET_TIME_Absolute abs);
558 755
559 756
560/** 757/**
758 * Test if @a abs is truly zero.
759 *
760 * @return true if it is.
761 */
762bool
763GNUNET_TIME_absolute_is_zero (struct GNUNET_TIME_Absolute abs);
764
765
766/**
561 * Test if @a abs is truly in the future (excluding now). 767 * Test if @a abs is truly in the future (excluding now).
562 * 768 *
563 * @return true if it is. 769 * @return true if it is.
@@ -595,6 +801,26 @@ GNUNET_TIME_absolute_from_s (uint64_t s_after_epoch);
595 801
596 802
597/** 803/**
804 * Convert seconds after the UNIX epoch to timestamp.
805 *
806 * @param s_after_epoch seconds after epoch to convert
807 * @return converted time value
808 */
809struct GNUNET_TIME_Timestamp
810GNUNET_TIME_timestamp_from_s (uint64_t s_after_epoch);
811
812
813/**
814 * Convert timestamp to number of seconds after the UNIX epoch.
815 *
816 * @param ts timestamp to convert
817 * @return converted time value
818 */
819uint64_t
820GNUNET_TIME_timestamp_to_s (struct GNUNET_TIME_Timestamp ts);
821
822
823/**
598 * Convert absolute time from network byte order. 824 * Convert absolute time from network byte order.
599 * 825 *
600 * @param a time to convert 826 * @param a time to convert
@@ -605,6 +831,16 @@ GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a);
605 831
606 832
607/** 833/**
834 * Convert timestamp from network byte order.
835 *
836 * @param tn time to convert
837 * @return converted time value
838 */
839struct GNUNET_TIME_Timestamp
840GNUNET_TIME_timestamp_ntoh (struct GNUNET_TIME_TimestampNBO tn);
841
842
843/**
608 * Set the timestamp offset for this instance. 844 * Set the timestamp offset for this instance.
609 * 845 *
610 * @param offset the offset to skew the locale time by 846 * @param offset the offset to skew the locale time by
@@ -690,4 +926,6 @@ GNUNET_TIME_absolute_get_monotonic (
690 926
691/** @} */ /* end of group time */ 927/** @} */ /* end of group time */
692 928
929/** @} */ /* end of group addition */
930
693/* end of gnunet_time_lib.h */ 931/* end of gnunet_time_lib.h */
diff --git a/src/include/gnunet_transport_application_service.h b/src/include/gnunet_transport_application_service.h
index f5d4c4ee0..c093ad96a 100644
--- a/src/include/gnunet_transport_application_service.h
+++ b/src/include/gnunet_transport_application_service.h
@@ -18,25 +18,24 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup Backbone
22 * @{
23 *
21 * @file 24 * @file
22 * Bandwidth allocation API for applications to interact with 25 * Bandwidth allocation API for applications to interact with
23 * 26 *
24 * @author Christian Grothoff 27 * @author Christian Grothoff
25 * @author Matthias Wachs 28 * @author Matthias Wachs
26 * 29 *
27 * @defgroup TRANSPORT service 30 * @defgroup TNG Transport Next Generation service
28 * Bandwidth allocation
29 *
30 * @{ 31 * @{
31 */ 32 */
32#ifndef GNUNET_TRANSPORT_APPLICATION_SERVICE_H 33#ifndef GNUNET_TRANSPORT_APPLICATION_SERVICE_H
33#define GNUNET_TRANSPORT_APPLICATION_SERVICE_H 34#define GNUNET_TRANSPORT_APPLICATION_SERVICE_H
34 35
36
35#include "gnunet_constants.h" 37#include "gnunet_constants.h"
36#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
37#include "gnunet_nt_lib.h"
38#include "gnunet_testing_lib.h"
39#include "gnunet_testing_ng_lib.h"
40 39
41/** 40/**
42 * Handle to the TRANSPORT subsystem for making suggestions about 41 * Handle to the TRANSPORT subsystem for making suggestions about
@@ -118,5 +117,7 @@ GNUNET_TRANSPORT_application_validate (
118 117
119/** @} */ /* end of group */ 118/** @} */ /* end of group */
120 119
120/** @} */ /* end of group addition */
121
121#endif 122#endif
122/* end of file gnunet_ats_application_service.h */ 123/* end of file gnunet_ats_application_service.h */
diff --git a/src/include/gnunet_transport_communication_service.h b/src/include/gnunet_transport_communication_service.h
index 81a382fb2..ea947911f 100644
--- a/src/include/gnunet_transport_communication_service.h
+++ b/src/include/gnunet_transport_communication_service.h
@@ -19,12 +19,15 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Backbone
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
25 * API of the transport service towards the communicator processes. 28 * API of the transport service towards the communicator processes.
26 * 29 *
27 * @defgroup transport TRANSPORT service 30 * @defgroup TNG Transport Next Generation service
28 * Low-level communication with other peers 31 * Low-level communication with other peers
29 * 32 *
30 * @see [Documentation](https://gnunet.org/transport-service) 33 * @see [Documentation](https://gnunet.org/transport-service)
@@ -42,8 +45,8 @@ extern "C" {
42#endif 45#endif
43#endif 46#endif
44 47
48
45#include "gnunet_util_lib.h" 49#include "gnunet_util_lib.h"
46#include "gnunet_nt_lib.h"
47 50
48/** 51/**
49 * Version number of the transport communication API. 52 * Version number of the transport communication API.
@@ -71,7 +74,7 @@ extern "C" {
71 * @param address where to send the message, human-readable 74 * @param address where to send the message, human-readable
72 * communicator-specific format, 0-terminated, UTF-8 75 * communicator-specific format, 0-terminated, UTF-8
73 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is 76 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is
74 * invalid 77 * invalid, #GNUNET_NO if this address is already (beging) connected to.
75 */ 78 */
76typedef int (*GNUNET_TRANSPORT_CommunicatorMqInit) ( 79typedef int (*GNUNET_TRANSPORT_CommunicatorMqInit) (
77 void *cls, 80 void *cls,
@@ -135,7 +138,8 @@ typedef void (*GNUNET_TRANSPORT_CommunicatorNotify) (
135 * Connect to the transport service. 138 * Connect to the transport service.
136 * 139 *
137 * @param cfg configuration to use 140 * @param cfg configuration to use
138 * @param config_section section of the configuration to use for options 141 * @param config_section_name section of the configuration to use for
142 * options
139 * @param addr_prefix address prefix for addresses supported by this 143 * @param addr_prefix address prefix for addresses supported by this
140 * communicator, could be NULL for incoming-only communicators 144 * communicator, could be NULL for incoming-only communicators
141 * @param cc what characteristics does the communicator have? 145 * @param cc what characteristics does the communicator have?
@@ -280,7 +284,7 @@ GNUNET_TRANSPORT_communicator_mq_add (
280 * Notify transport service that an MQ was updated 284 * Notify transport service that an MQ was updated
281 * 285 *
282 * @param ch connection to transport service 286 * @param ch connection to transport service
283 * @param qh the queue to update 287 * @param u_qh the queue to update
284 * @param q_len number of messages that can be send through this queue 288 * @param q_len number of messages that can be send through this queue
285 * @param priority queue priority. Queues with highest priority should be 289 * @param priority queue priority. Queues with highest priority should be
286 * used 290 * used
@@ -383,4 +387,6 @@ GNUNET_TRANSPORT_communicator_notify (
383 387
384/** @} */ /* end of group */ 388/** @} */ /* end of group */
385 389
390/** @} */ /* end of group addition */
391
386/* end of gnunet_transport_communicator_service.h */ 392/* end of gnunet_transport_communicator_service.h */
diff --git a/src/include/gnunet_transport_core_service.h b/src/include/gnunet_transport_core_service.h
index 314eb342f..f7907a12d 100644
--- a/src/include/gnunet_transport_core_service.h
+++ b/src/include/gnunet_transport_core_service.h
@@ -18,12 +18,15 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup Backbone
22 * @{
23 *
21 * @author Christian Grothoff 24 * @author Christian Grothoff
22 * 25 *
23 * @file 26 * @file
24 * API of the transport service towards the CORE service (TNG version) 27 * API of the transport service towards the CORE service (TNG version)
25 * 28 *
26 * @defgroup transport TRANSPORT service 29 * @defgroup TNG Transport Next Generation service
27 * Communication with other peers 30 * Communication with other peers
28 * 31 *
29 * @see [Documentation](https://gnunet.org/transport-service) 32 * @see [Documentation](https://gnunet.org/transport-service)
@@ -40,6 +43,7 @@ extern "C" {
40#endif 43#endif
41#endif 44#endif
42 45
46
43#include "gnunet_util_lib.h" 47#include "gnunet_util_lib.h"
44 48
45/** 49/**
@@ -174,4 +178,6 @@ GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
174 178
175/** @} */ /* end of group */ 179/** @} */ /* end of group */
176 180
181/** @} */ /* end of group addition */
182
177/* end of gnunet_transport_core_service.h */ 183/* end of gnunet_transport_core_service.h */
diff --git a/src/include/gnunet_transport_hello_service.h b/src/include/gnunet_transport_hello_service.h
deleted file mode 100644
index fecffd527..000000000
--- a/src/include/gnunet_transport_hello_service.h
+++ /dev/null
@@ -1,201 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2016 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 *
24 * @file
25 * obtain information about our current address
26 *
27 * @deprecated, in TNG applications should query PEERSTORE directly!
28 *
29 * @defgroup transport Transport service
30 * address information
31 *
32 * @see [Documentation](https://gnunet.org/transport-service)
33 *
34 * @{
35 */
36#ifndef GNUNET_TRANSPORT_HELLO_SERVICE_H
37#define GNUNET_TRANSPORT_HELLO_SERVICE_H
38
39#ifdef __cplusplus
40extern "C" {
41#if 0 /* keep Emacsens' auto-indent happy */
42}
43#endif
44#endif
45
46#include "gnunet_util_lib.h"
47#include "gnunet_ats_service.h"
48
49/**
50 * Version number of the transport API.
51 */
52#define GNUNET_TRANSPORT_HELLO_VERSION 0x00000000
53
54
55/**
56 * Some addresses contain sensitive information or are
57 * not suitable for global distribution. We use address
58 * classes to filter addresses by which domain they make
59 * sense to be used in. These are used in a bitmask.
60 */
61enum GNUNET_TRANSPORT_AddressClass
62{
63 /**
64 * No address.
65 */
66 GNUNET_TRANSPORT_AC_NONE = 0,
67
68 /**
69 * Addresses that fall into no other category
70 * (i.e. incoming which we cannot use elsewhere).
71 */
72 GNUNET_TRANSPORT_AC_OTHER = 1,
73
74 /**
75 * Addresses that are global and are insensitive
76 * (i.e. IPv4).
77 */
78 GNUNET_TRANSPORT_AC_GLOBAL = 2,
79
80 /**
81 * Addresses that are global and are sensitive
82 * (i.e. IPv6 with our MAC).
83 */
84 GNUNET_TRANSPORT_AC_GLOBAL_PRIVATE = 4,
85
86 /**
87 * Addresses useful in the local wired network,
88 * i.e. a MAC. Sensitive, but obvious to people nearby.
89 * Useful for broadcasts.
90 */
91 GNUNET_TRANSPORT_AC_LAN = 8,
92
93 /**
94 * Addresses useful in the local wireless network,
95 * i.e. a MAC. Sensitive, but obvious to people nearby.
96 * Useful for broadcasts.
97 */
98 GNUNET_TRANSPORT_AC_WLAN = 16,
99
100 /**
101 * Addresses useful in the local bluetooth network. Sensitive, but
102 * obvious to people nearby. Useful for broadcasts.
103 */
104 GNUNET_TRANSPORT_AC_BT = 32,
105
106 /**
107 * Bitmask for "any" address.
108 */
109 GNUNET_TRANSPORT_AC_ANY = 65535
110};
111
112
113/**
114 * Function called whenever there is an update to the
115 * HELLO of this peer.
116 *
117 * @param cls closure
118 * @param hello our updated HELLO
119 */
120typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback) (
121 void *cls,
122 const struct GNUNET_MessageHeader *hello);
123
124
125/**
126 * Handle to cancel a #GNUNET_TRANSPORT_hello_get() operation.
127 */
128struct GNUNET_TRANSPORT_HelloGetHandle;
129
130
131/**
132 * Obtain updates on changes to the HELLO message for this peer. The callback
133 * given in this function is never called synchronously.
134 *
135 * @param cfg configuration to use
136 * @param ac which network type should the addresses from the HELLO belong to?
137 * @param rec function to call with the HELLO
138 * @param rec_cls closure for @a rec
139 * @return handle to cancel the operation
140 */
141struct GNUNET_TRANSPORT_HelloGetHandle *
142GNUNET_TRANSPORT_hello_get (const struct GNUNET_CONFIGURATION_Handle *cfg,
143 enum GNUNET_TRANSPORT_AddressClass ac,
144 GNUNET_TRANSPORT_HelloUpdateCallback rec,
145 void *rec_cls);
146
147
148/**
149 * Stop receiving updates about changes to our HELLO message.
150 *
151 * @param ghh handle to cancel
152 */
153void
154GNUNET_TRANSPORT_hello_get_cancel (struct GNUNET_TRANSPORT_HelloGetHandle *ghh);
155
156
157/**
158 * Function with addresses found in a HELLO.
159 *
160 * @param cls closure
161 * @param peer identity of the peer
162 * @param address the address (UTF-8, 0-terminated)
163 * @param nt network type of the address
164 * @param expiration when does this address expire?
165 */
166typedef void (*GNUNET_TRANSPORT_AddressCallback) (
167 void *cls,
168 const struct GNUNET_PeerIdentity *peer,
169 const char *address,
170 enum GNUNET_NetworkType nt,
171 struct GNUNET_TIME_Absolute expiration);
172
173
174/**
175 * Parse a HELLO message that we have received into its
176 * constituent addresses.
177 *
178 * @param hello message to parse
179 * @param cb function to call on each address found
180 * @param cb_cls closure for @a cb
181 * @return #GNUNET_OK if hello was well-formed, #GNUNET_SYSERR if not
182 */
183int
184GNUNET_TRANSPORT_hello_parse (const struct GNUNET_MessageHeader *hello,
185 GNUNET_TRANSPORT_AddressCallback cb,
186 void *cb_cls);
187
188
189#if 0 /* keep Emacsens' auto-indent happy */
190{
191#endif
192#ifdef __cplusplus
193}
194#endif
195
196/* ifndef GNUNET_TRANSPORT_HELLO_SERVICE_H */
197#endif
198
199/** @} */ /* end of group */
200
201/* end of gnunet_transport_hello_service.h */
diff --git a/src/include/gnunet_transport_manipulation_service.h b/src/include/gnunet_transport_manipulation_service.h
deleted file mode 100644
index 09fb138f8..000000000
--- a/src/include/gnunet_transport_manipulation_service.h
+++ /dev/null
@@ -1,117 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2014, 2016 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 *
24 * @file
25 * Low-level P2P IO
26 *
27 * @defgroup transport Transport service
28 * Low-level P2P IO
29 *
30 * @see [Documentation](https://gnunet.org/transport-service)
31 *
32 * @{
33 */
34
35#ifndef GNUNET_TRANSPORT_MANIPULATION_SERVICE_H
36#define GNUNET_TRANSPORT_MANIPULATION_SERVICE_H
37
38
39#ifdef __cplusplus
40extern "C"
41{
42#if 0 /* keep Emacsens' auto-indent happy */
43}
44#endif
45#endif
46
47#include "gnunet_util_lib.h"
48#include "gnunet_ats_service.h"
49
50/**
51 * Version number of the transport API.
52 */
53#define GNUNET_TRANSPORT_MANIPULATION_VERSION 0x00000003
54
55/**
56 * Handle for transport manipulation.
57 */
58struct GNUNET_TRANSPORT_ManipulationHandle;
59
60
61/**
62 * Connect to the transport service. Note that the connection may
63 * complete (or fail) asynchronously.
64 *
65 * @param cfg configuration to use
66 * @return NULL on error
67 */
68struct GNUNET_TRANSPORT_ManipulationHandle *
69GNUNET_TRANSPORT_manipulation_connect (const struct
70 GNUNET_CONFIGURATION_Handle *cfg);
71
72
73/**
74 * Disconnect from the transport service.
75 *
76 * @param handle handle returned from connect
77 */
78void
79GNUNET_TRANSPORT_manipulation_disconnect (struct
80 GNUNET_TRANSPORT_ManipulationHandle *
81 handle);
82
83
84/**
85 * Set transport metrics for a peer and a direction
86 *
87 * @param handle transport handle
88 * @param peer the peer to set the metric for
89 * @param prop the performance metrics to set
90 * @param delay_in inbound delay to introduce
91 * @param delay_out outbound delay to introduce
92 *
93 * Note: Delay restrictions in receiving direction will be enforced
94 * with one message delay.
95 */
96void
97GNUNET_TRANSPORT_manipulation_set (struct
98 GNUNET_TRANSPORT_ManipulationHandle *handle,
99 const struct GNUNET_PeerIdentity *peer,
100 const struct GNUNET_ATS_Properties *prop,
101 struct GNUNET_TIME_Relative delay_in,
102 struct GNUNET_TIME_Relative delay_out);
103
104
105#if 0 /* keep Emacsens' auto-indent happy */
106{
107#endif
108#ifdef __cplusplus
109}
110#endif
111
112/* ifndef GNUNET_TRANSPORT_MANIPULATION_SERVICE_H */
113#endif
114
115/** @} */ /* end of group */
116
117/* end of gnunet_transport_manipulation_service.h */
diff --git a/src/include/gnunet_transport_monitor_service.h b/src/include/gnunet_transport_monitor_service.h
index f39be16d7..7c586b51e 100644
--- a/src/include/gnunet_transport_monitor_service.h
+++ b/src/include/gnunet_transport_monitor_service.h
@@ -19,12 +19,15 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup Backbone
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
25 * Monitoring / diagnostics API for the transport service 28 * Monitoring / diagnostics API for the transport service
26 * 29 *
27 * @defgroup transport TRANSPORT service 30 * @defgroup TNG Transport Next Generation service
28 * Communication with other peers 31 * Communication with other peers
29 * 32 *
30 * @see [Documentation](https://gnunet.org/transport-service) 33 * @see [Documentation](https://gnunet.org/transport-service)
@@ -42,8 +45,8 @@ extern "C"
42#endif 45#endif
43#endif 46#endif
44 47
48
45#include "gnunet_util_lib.h" 49#include "gnunet_util_lib.h"
46#include "gnunet_ats_transport_service.h"
47#include "gnunet_transport_communication_service.h" 50#include "gnunet_transport_communication_service.h"
48 51
49 52
@@ -189,4 +192,6 @@ GNUNET_TRANSPORT_monitor_cancel (struct GNUNET_TRANSPORT_MonitorContext *mc);
189 192
190/** @} */ /* end of group */ 193/** @} */ /* end of group */
191 194
195/** @} */ /* end of group addition */
196
192/* end of gnunet_transport_monitor_service.h */ 197/* end of gnunet_transport_monitor_service.h */
diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h
deleted file mode 100644
index 74b27923a..000000000
--- a/src/include/gnunet_transport_plugin.h
+++ /dev/null
@@ -1,727 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2009-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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 *
24 * @file
25 * Transport service plugin API
26 *
27 * @defgroup transport-plugin Transport Service plugin API
28 *
29 * Specifies the struct that is given to the plugin's entry method and the other
30 * struct that must be returned. Note that the destructors of transport plugins
31 * will be given the value returned by the constructor and is expected to return
32 * a NULL pointer.
33 *
34 * @{
35 */
36#ifndef PLUGIN_TRANSPORT_H
37#define PLUGIN_TRANSPORT_H
38
39#include "gnunet_configuration_lib.h"
40#include "gnunet_scheduler_lib.h"
41#include "gnunet_statistics_service.h"
42#include "gnunet_transport_service.h"
43#include "gnunet_ats_service.h"
44
45#define TRANSPORT_SESSION_INBOUND_STRING "<inbound>"
46
47/**
48 * Opaque pointer that plugins can use to distinguish specific
49 * connections to a given peer. Typically used by stateful plugins to
50 * allow the service to refer to specific streams instead of a more
51 * general notion of "some connection" to the given peer. This is
52 * useful since sometimes (e.g. for inbound TCP connections) a
53 * connection may not have an address that can be used for meaningful
54 * distinction between sessions to the same peer.
55 *
56 * Each 'struct GNUNET_ATS_Session' MUST start with the 'struct GNUNET_PeerIdentity'
57 * of the peer the session is for (which will be used for some error
58 * checking by the ATS code).
59 */
60struct GNUNET_ATS_Session;
61
62
63/**
64 * Function that will be called whenever the plugin internally
65 * cleans up a session pointer and hence the service needs to
66 * discard all of those sessions as well. Plugins that do not
67 * use sessions can simply omit calling this function and always
68 * use NULL wherever a session pointer is needed. This function
69 * should be called BEFORE a potential "TransmitContinuation"
70 * from the "TransmitFunction".
71 *
72 * @param cls closure
73 * @param peer which peer was the session for
74 * @param session which session is being destroyed
75 */
76typedef void
77(*GNUNET_TRANSPORT_SessionEnd) (void *cls,
78 const struct GNUNET_HELLO_Address *address,
79 struct GNUNET_ATS_Session *session);
80
81
82/**
83 * Plugin tells transport service about a new inbound session
84 *
85 * @param cls unused
86 * @param address the address
87 * @param session the new session
88 * @param net network information
89 */
90typedef void
91(*GNUNET_TRANSPORT_SessionStart) (void *cls,
92 const struct GNUNET_HELLO_Address *address,
93 struct GNUNET_ATS_Session *session,
94 enum GNUNET_NetworkType net);
95
96
97/**
98 * Function called by the transport for each received message.
99 * This function should also be called with "NULL" for the
100 * message to signal that the other peer disconnected.
101 *
102 * @param cls closure
103 * @param peer (claimed) identity of the other peer
104 * @param message the message, NULL if we only care about
105 * learning about the delay until we should receive again
106 * @param session identifier used for this session (NULL for plugins
107 * that do not offer bi-directional communication to the sender
108 * using the same "connection")
109 * @param sender_address binary address of the sender (if we established the
110 * connection or are otherwise sure of it; should be NULL
111 * for inbound TCP/UDP connections since it it not clear
112 * that we could establish ourselves a connection to that
113 * IP address and get the same system)
114 * @param sender_address_len number of bytes in @a sender_address
115 * @return how long the plugin should wait until receiving more data;
116 * returning #GNUNET_TIME_UNIT_FOREVER_REL means that the
117 * connection should be closed
118 */
119typedef struct GNUNET_TIME_Relative
120(*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls,
121 const struct
122 GNUNET_HELLO_Address *address,
123 struct GNUNET_ATS_Session *session,
124 const struct
125 GNUNET_MessageHeader *message);
126
127
128/**
129 * Function that can be called by plugins to figure if an address is
130 * an loopback, LAN or WAN address. Ultimately invokes
131 * #GNUNET_ATS_address_get_type().
132 *
133 * @param cls closure
134 * @param addr binary address
135 * @param addrlen length of the @a addr
136 * @return type of the network the address belongs to
137 */
138typedef enum GNUNET_NetworkType
139(*GNUNET_TRANSPORT_AddressToType)(void *cls,
140 const struct sockaddr *addr,
141 size_t addrlen);
142
143
144/**
145 * Function called when distance of an address changes.
146 *
147 * @param cls closure
148 * @param peer peer
149 * @param distance new distance
150 */
151typedef void
152(*GNUNET_TRANSPORT_UpdateAddressDistance) (void *cls,
153 const struct
154 GNUNET_HELLO_Address *address,
155 uint32_t distance);
156
157
158/**
159 * Function that will be called for each address the transport
160 * is aware that it might be reachable under.
161 *
162 * @param cls closure
163 * @param add_remove should the address added (#GNUNET_YES) or removed (#GNUNET_NO) from the
164 * set of valid addresses?
165 * @param address the address to add or remove
166 */
167typedef void
168(*GNUNET_TRANSPORT_AddressNotification) (void *cls,
169 int add_remove,
170 const struct
171 GNUNET_HELLO_Address *address);
172
173
174/**
175 * Function that will be called whenever the plugin receives data over
176 * the network and wants to determine how long it should wait until
177 * the next time it reads from the given peer. Note that some plugins
178 * (such as UDP) may not be able to wait (for a particular peer), so
179 * the waiting part is optional. Plugins that can wait should call
180 * this function, sleep the given amount of time, and call it again
181 * (with zero bytes read) UNTIL it returns zero and only then read.
182 *
183 * @param cls closure
184 * @param peer which peer did we read data from
185 * @param amount_recved number of bytes read (can be zero)
186 * @return how long to wait until reading more from this peer
187 * (to enforce inbound quotas); returning #GNUNET_TIME_UNIT_FOREVER_REL
188 * means that the connection should be closed
189 */
190typedef struct GNUNET_TIME_Relative
191(*GNUNET_TRANSPORT_TrafficReport) (void *cls,
192 const struct GNUNET_PeerIdentity *peer,
193 size_t amount_recved);
194
195
196/**
197 * Function that returns a HELLO message.
198 *
199 * @return HELLO message (FIXME with what?)
200 */
201typedef const struct GNUNET_MessageHeader *
202(*GNUNET_TRANSPORT_GetHelloCallback) (void);
203
204
205/**
206 * The transport service will pass a pointer to a struct
207 * of this type as the first and only argument to the
208 * entry point of each transport plugin.
209 */
210struct GNUNET_TRANSPORT_PluginEnvironment
211{
212 /**
213 * Configuration to use.
214 */
215 const struct GNUNET_CONFIGURATION_Handle *cfg;
216
217 /**
218 * Identity of this peer.
219 */
220 const struct GNUNET_PeerIdentity *my_identity;
221
222 /**
223 * Closure for the various callbacks.
224 */
225 void *cls;
226
227 /**
228 * Handle for reporting statistics.
229 */
230 struct GNUNET_STATISTICS_Handle *stats;
231
232 /**
233 * Function that should be called by the transport plugin
234 * whenever a message is received. If this field is "NULL",
235 * the plugin should load in 'stub' mode and NOT fully
236 * initialize and instead only return an API with the
237 * @e address_pretty_printer, @e address_to_string and
238 * @e string_to_address functions.
239 */
240 GNUNET_TRANSPORT_PluginReceiveCallback receive;
241
242 /**
243 * Function that returns our HELLO.
244 */
245 GNUNET_TRANSPORT_GetHelloCallback get_our_hello;
246
247 /**
248 * Function that must be called by each plugin to notify the
249 * transport service about the addresses under which the transport
250 * provided by the plugin can be reached.
251 */
252 GNUNET_TRANSPORT_AddressNotification notify_address;
253
254 /**
255 * Function that must be called by the plugin when a non-NULL
256 * session handle stops being valid (is destroyed).
257 */
258 GNUNET_TRANSPORT_SessionEnd session_end;
259
260 /**
261 * Function called by the plugin when a new (incoming) session was created
262 * not explicitly created using the the get_session function
263 */
264 GNUNET_TRANSPORT_SessionStart session_start;
265
266 /**
267 * Function that will be called to figure if an address is an loopback,
268 * LAN, WAN etc. address
269 */
270 GNUNET_TRANSPORT_AddressToType get_address_type;
271
272 /**
273 * Function that will be called by DV to update distance for
274 * an address.
275 */
276 GNUNET_TRANSPORT_UpdateAddressDistance update_address_distance;
277
278 /**
279 * What is the maximum number of connections that this transport
280 * should allow? Transports that do not have sessions (such as
281 * UDP) can ignore this value.
282 */
283 uint32_t max_connections;
284};
285
286
287/**
288 * Function called by the #GNUNET_TRANSPORT_TransmitFunction
289 * upon "completion". In the case that a peer disconnects,
290 * this function must be called for each pending request
291 * (with a 'failure' indication) AFTER notifying the service
292 * about the disconnect event (so that the service won't try
293 * to transmit more messages, believing the connection still
294 * exists...).
295 *
296 * @param cls closure
297 * @param target who was the recipient of the message?
298 * @param result #GNUNET_OK on success
299 * #GNUNET_SYSERR if the target disconnected;
300 * disconnect will ALSO be signalled using
301 * the ReceiveCallback.
302 * @param size_payload bytes of payload from transport service in message
303 * @param size_on_wire bytes required on wire for transmission,
304 * 0 if result == #GNUNET_SYSERR
305 */
306typedef void
307(*GNUNET_TRANSPORT_TransmitContinuation) (void *cls,
308 const struct
309 GNUNET_PeerIdentity *target,
310 int result,
311 size_t size_payload,
312 size_t size_on_wire);
313
314
315/**
316 * The new send function with just the session and no address
317 *
318 * Function that can be used by the transport service to transmit
319 * a message using the plugin. Note that in the case of a
320 * peer disconnecting, the continuation MUST be called
321 * prior to the disconnect notification itself. This function
322 * will be called with this peer's HELLO message to initiate
323 * a fresh connection to another peer.
324 *
325 * @param cls closure
326 * @param session which session must be used
327 * @param msgbuf the message to transmit
328 * @param msgbuf_size number of bytes in @a msgbuf
329 * @param priority how important is the message (most plugins will
330 * ignore message priority and just FIFO)
331 * @param to how long to wait at most for the transmission (does not
332 * require plugins to discard the message after the timeout,
333 * just advisory for the desired delay; most plugins will ignore
334 * this as well)
335 * @param cont continuation to call once the message has
336 * been transmitted (or if the transport is ready
337 * for the next transmission call; or if the
338 * peer disconnected...); can be NULL
339 * @param cont_cls closure for @a cont
340 * @return number of bytes used (on the physical network, with overheads);
341 * -1 on hard errors (i.e. address invalid); 0 is a legal value
342 * and does NOT mean that the message was not transmitted (DV)
343 */
344typedef ssize_t
345(*GNUNET_TRANSPORT_TransmitFunction) (void *cls,
346 struct GNUNET_ATS_Session *session,
347 const char *msgbuf,
348 size_t msgbuf_size,
349 unsigned int priority,
350 struct GNUNET_TIME_Relative to,
351 GNUNET_TRANSPORT_TransmitContinuation cont,
352 void *cont_cls);
353
354
355/**
356 * Function that can be called to force a disconnect from the
357 * specified neighbour for the given session only. . This should
358 * also cancel all previously scheduled transmissions for this
359 * session. Obviously the transmission may have been partially
360 * completed already, which is OK. The plugin is supposed to close
361 * the connection (if applicable).
362 *
363 * @param cls closure with the `struct Plugin`
364 * @param session session to destroy
365 * @return #GNUNET_OK on success
366 */
367typedef int
368(*GNUNET_TRANSPORT_DisconnectSessionFunction) (void *cls,
369 struct GNUNET_ATS_Session *
370 session);
371
372
373/**
374 * Function that is called to get the keepalive factor.
375 * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
376 * calculate the interval between keepalive packets.
377 *
378 * @param cls closure with the `struct Plugin`
379 * @return keepalive factor
380 */
381typedef unsigned int
382(*GNUNET_TRANSPORT_QueryKeepaliveFactorFunction) (void *cls);
383
384
385/**
386 * Function that can be called to force a disconnect from the
387 * specified neighbour. This should also cancel all previously
388 * scheduled transmissions. Obviously the transmission may have been
389 * partially completed already, which is OK. The plugin is supposed
390 * to close the connection (if applicable) and no longer call the
391 * transmit continuation(s).
392 *
393 * @param cls closure
394 * @param target peer for which the last transmission is
395 * to be cancelled
396 */
397typedef void
398(*GNUNET_TRANSPORT_DisconnectPeerFunction) (void *cls,
399 const struct
400 GNUNET_PeerIdentity *target);
401
402
403/**
404 * Function called by the pretty printer for the resolved address for
405 * each human-readable address obtained. The callback can be called
406 * several times. The last invocation must be with a @a address of
407 * NULL and a @a res of #GNUNET_OK. Thus, to indicate conversion
408 * errors, the callback might be called first with @a address NULL and
409 * @a res being #GNUNET_SYSERR. In that case, there must still be a
410 * subsequent call later with @a address NULL and @a res #GNUNET_OK.
411 *
412 * @param cls closure
413 * @param address one of the names for the host, NULL on last callback
414 * @param res #GNUNET_OK if conversion was successful, #GNUNET_SYSERR on failure,
415 * #GNUNET_OK on last callback
416 */
417typedef void
418(*GNUNET_TRANSPORT_AddressStringCallback) (void *cls,
419 const char *address,
420 int res);
421
422
423/**
424 * Convert the transports address to a nice, human-readable
425 * format.
426 *
427 * @param cls closure
428 * @param type name of the transport that generated the address
429 * @param addr one of the addresses of the host, NULL for the last address
430 * the specific address format depends on the transport
431 * @param addrlen length of the @a addr
432 * @param numeric should (IP) addresses be displayed in numeric form?
433 * @param timeout after how long should we give up?
434 * @param asc function to call on each string
435 * @param asc_cls closure for @a asc
436 */
437typedef void
438(*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls,
439 const char *type,
440 const void *addr,
441 size_t addrlen,
442 int numeric,
443 struct GNUNET_TIME_Relative timeout,
444 GNUNET_TRANSPORT_AddressStringCallback
445 asc,
446 void *asc_cls);
447
448
449/**
450 * Another peer has suggested an address for this peer and transport
451 * plugin. Check that this could be a valid address. This function
452 * is not expected to 'validate' the address in the sense of trying to
453 * connect to it but simply to see if the binary format is technically
454 * legal for establishing a connection to this peer (and make sure that
455 * the address really corresponds to our network connection/settings
456 * and not some potential man-in-the-middle).
457 *
458 * @param addr pointer to the address
459 * @param addrlen length of @a addr
460 * @return #GNUNET_OK if this is a plausible address for this peer
461 * and transport, #GNUNET_SYSERR if not
462 */
463typedef int
464(*GNUNET_TRANSPORT_CheckAddress) (void *cls,
465 const void *addr,
466 size_t addrlen);
467
468
469/**
470 * Create a new session to transmit data to the target
471 * This session will used to send data to this peer and the plugin will
472 * notify us by calling the env->session_end function
473 *
474 * @param cls the plugin
475 * @param address the hello address
476 * @return the session if the address is valid, NULL otherwise
477 */
478typedef struct GNUNET_ATS_Session *
479(*GNUNET_TRANSPORT_CreateSession) (void *cls,
480 const struct GNUNET_HELLO_Address *address);
481
482
483/**
484 * Function that will be called whenever the transport service wants to
485 * notify the plugin that a session is still active and in use and
486 * therefore the session timeout for this session has to be updated
487 *
488 * @param cls closure
489 * @param peer which peer was the session for
490 * @param session which session is being updated
491 */
492typedef void
493(*GNUNET_TRANSPORT_UpdateSessionTimeout) (void *cls,
494 const struct
495 GNUNET_PeerIdentity *peer,
496 struct GNUNET_ATS_Session *session);
497
498
499/**
500 * Function that will be called whenever the transport service wants to
501 * notify the plugin that the inbound quota changed and that the plugin
502 * should update it's delay for the next receive value
503 *
504 * @param cls closure
505 * @param peer which peer was the session for
506 * @param session which session is being updated
507 * @param delay new delay to use for receiving
508 */
509typedef void
510(*GNUNET_TRANSPORT_UpdateInboundDelay) (void *cls,
511 const struct GNUNET_PeerIdentity *peer,
512 struct GNUNET_ATS_Session *session,
513 struct GNUNET_TIME_Relative delay);
514
515
516/**
517 * Function called for a quick conversion of the binary address to
518 * a numeric address. Note that the caller must not free the
519 * address and that the next call to this function is allowed
520 * to override the address again.
521 *
522 * @param cls closure
523 * @param addr binary address
524 * @param addr_len length of the @a addr
525 * @return string representing the same address
526 */
527typedef const char *
528(*GNUNET_TRANSPORT_AddressToString) (void *cls,
529 const void *addr,
530 size_t addrlen);
531
532
533/**
534 * Function called to convert a string address to
535 * a binary address.
536 *
537 * @param cls closure (`struct Plugin*`)
538 * @param addr string address
539 * @param addrlen length of the @a addr including \0 termination
540 * @param buf location to store the buffer
541 * If the function returns #GNUNET_SYSERR, its contents are undefined.
542 * @param added length of created address
543 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
544 */
545typedef int
546(*GNUNET_TRANSPORT_StringToAddress) (void *cls,
547 const char *addr,
548 uint16_t addrlen,
549 void **buf,
550 size_t *added);
551
552
553/**
554 * Function to obtain the network type for a session
555 *
556 * @param cls closure (`struct Plugin *`)
557 * @param session the session
558 * @return the network type
559 */
560typedef enum GNUNET_NetworkType
561(*GNUNET_TRANSPORT_GetNetworkType)(void *cls,
562 struct GNUNET_ATS_Session *session);
563
564
565/**
566 * Function to obtain the network type for an address.
567 *
568 * @param cls closure (`struct Plugin *`)
569 * @param address the address
570 * @return the network type
571 */
572typedef enum GNUNET_NetworkType
573(*GNUNET_TRANSPORT_GetNetworkTypeForAddress)(void *cls,
574 const struct
575 GNUNET_HELLO_Address *address);
576
577
578/**
579 * Function called by the plugin with information about the
580 * current sessions managed by the plugin (for monitoring).
581 *
582 * @param cls closure
583 * @param session session handle this information is about,
584 * NULL to indicate that we are "in sync" (initial
585 * iteration complete)
586 * @param info information about the state of the session,
587 * NULL if @a session is also NULL and we are
588 * merely signalling that the initial iteration is over
589 */
590typedef void
591(*GNUNET_TRANSPORT_SessionInfoCallback) (void *cls,
592 struct GNUNET_ATS_Session *session,
593 const struct
594 GNUNET_TRANSPORT_SessionInfo *info);
595
596
597/**
598 * Begin monitoring sessions of a plugin. There can only
599 * be one active monitor per plugin (i.e. if there are
600 * multiple monitors, the transport service needs to
601 * multiplex the generated events over all of them).
602 *
603 * @param cls closure of the plugin
604 * @param sic callback to invoke, NULL to disable monitor;
605 * plugin will being by iterating over all active
606 * sessions immediately and then enter monitor mode
607 * @param sic_cls closure for @a sic
608 */
609typedef void
610(*GNUNET_TRANSPORT_SessionMonitorSetup) (void *cls,
611 GNUNET_TRANSPORT_SessionInfoCallback
612 sic,
613 void *sic_cls);
614
615
616/**
617 * Each plugin is required to return a pointer to a struct of this
618 * type as the return value from its entry point.
619 */
620struct GNUNET_TRANSPORT_PluginFunctions
621{
622 /**
623 * Closure for all of the callbacks.
624 */
625 void *cls;
626
627 /**
628 * Function that the transport service will use to transmit data to
629 * another peer. May be NULL for plugins that only support
630 * receiving data. After this call, the plugin call the specified
631 * continuation with success or error before notifying us about the
632 * target having disconnected.
633 */
634 GNUNET_TRANSPORT_TransmitFunction send;
635
636 /**
637 * Function that can be used to force the plugin to disconnect from
638 * the given peer and cancel all previous transmissions (and their
639 * continuations).
640 */
641 GNUNET_TRANSPORT_DisconnectPeerFunction disconnect_peer;
642
643 /**
644 * Function that can be used to force the plugin to disconnect from
645 * the given peer and cancel all previous transmissions (and their
646 * continuations).
647 */
648 GNUNET_TRANSPORT_DisconnectSessionFunction disconnect_session;
649
650 /**
651 * Function that will be called whenever the transport service wants to
652 * notify the plugin that a session is still active and in use and
653 * therefore the session timeout for this session has to be updated
654 */
655 GNUNET_TRANSPORT_UpdateSessionTimeout update_session_timeout;
656
657 /**
658 * Function that will be called whenever the transport service wants to
659 * notify the plugin that the inbound quota changed and that the plugin
660 * should update it's delay for the next receive value
661 */
662 GNUNET_TRANSPORT_UpdateInboundDelay update_inbound_delay;
663
664 /**
665 * Function that is used to query keepalive factor.
666 * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
667 * calculate the interval between keepalive packets.
668 */
669 GNUNET_TRANSPORT_QueryKeepaliveFactorFunction query_keepalive_factor;
670
671 /**
672 * Function to pretty-print addresses.
673 */
674 GNUNET_TRANSPORT_AddressPrettyPrinter address_pretty_printer;
675
676 /**
677 * Function that will be called to check if a binary address
678 * for this plugin is well-formed and corresponds to an
679 * address for THIS peer (as per our configuration). Naturally,
680 * if absolutely necessary, plugins can be a bit conservative in
681 * their answer, but in general plugins should make sure that the
682 * address does not redirect traffic to a 3rd party that might
683 * try to man-in-the-middle our traffic.
684 */
685 GNUNET_TRANSPORT_CheckAddress check_address;
686
687 /**
688 * Function that will be called to convert a binary address
689 * to a string (numeric conversion only).
690 */
691 GNUNET_TRANSPORT_AddressToString address_to_string;
692
693 /**
694 * Function that will be called to convert a string address
695 * to binary (numeric conversion only).
696 */
697 GNUNET_TRANSPORT_StringToAddress string_to_address;
698
699 /**
700 * Function that will be called tell the plugin to create a session
701 * object.
702 */
703 GNUNET_TRANSPORT_CreateSession get_session;
704
705 /**
706 * Function to obtain the network type for a session
707 */
708 GNUNET_TRANSPORT_GetNetworkType get_network;
709
710 /**
711 * Function to obtain the network type for an address
712 */
713 GNUNET_TRANSPORT_GetNetworkTypeForAddress get_network_for_address;
714
715 /**
716 * Function to monitor the sessions managed by the plugin.
717 */
718 GNUNET_TRANSPORT_SessionMonitorSetup setup_monitor;
719};
720
721
722/*#ifndef PLUGIN_TRANSPORT_H*/
723#endif
724
725/** @} */ /* end of group */
726
727/* end of gnunet_transport_plugin.h */
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h
deleted file mode 100644
index 459efc506..000000000
--- a/src/include/gnunet_transport_service.h
+++ /dev/null
@@ -1,708 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2016 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 *
24 * @file
25 * Low-level P2P IO
26 *
27 * @defgroup transport Transport service
28 * Low-level P2P IO
29 *
30 * @see [Documentation](https://gnunet.org/transport-service)
31 *
32 * @{
33 */
34
35#ifndef GNUNET_TRANSPORT_SERVICE_H
36#define GNUNET_TRANSPORT_SERVICE_H
37
38#ifdef __cplusplus
39extern "C" {
40#if 0 /* keep Emacsens' auto-indent happy */
41}
42#endif
43#endif
44
45#include "gnunet_util_lib.h"
46#include "gnunet_ats_service.h"
47
48/**
49 * Version number of the transport API.
50 */
51#define GNUNET_TRANSPORT_VERSION 0x00000003
52
53
54/* *************************** HELLO *************************** */
55
56/**
57 * Handle for a #GNUNET_TRANSPORT_offer_hello operation
58 */
59struct GNUNET_TRANSPORT_OfferHelloHandle;
60
61
62/**
63 * Offer the transport service the HELLO of another peer. Note that
64 * the transport service may just ignore this message if the HELLO is
65 * malformed or useless due to our local configuration.
66 *
67 * @param cfg configuration
68 * @param hello the hello message
69 * @param cont continuation to call when HELLO has been sent,
70 * tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail
71 * tc reasong #GNUNET_SCHEDULER_REASON_READ_READY for success
72 * @param cont_cls closure for @a cont
73 * @return a `struct GNUNET_TRANSPORT_OfferHelloHandle` handle or NULL on
74 * failure, in case of failure @a cont will not be called
75 *
76 */
77struct GNUNET_TRANSPORT_OfferHelloHandle *
78GNUNET_TRANSPORT_offer_hello (const struct GNUNET_CONFIGURATION_Handle *cfg,
79 const struct GNUNET_MessageHeader *hello,
80 GNUNET_SCHEDULER_TaskCallback cont,
81 void *cont_cls);
82
83
84/**
85 * Cancel the request to transport to offer the HELLO message
86 *
87 * @param ohh the `struct GNUNET_TRANSPORT_OfferHelloHandle` to cancel
88 */
89void
90GNUNET_TRANSPORT_offer_hello_cancel (
91 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh);
92
93
94/* *********************** Address to String ******************* */
95
96/**
97 * Handle to cancel a pending address lookup.
98 */
99struct GNUNET_TRANSPORT_AddressToStringContext;
100
101
102/**
103 * Function to call with a textual representation of an address. This
104 * function will be called several times with different possible
105 * textual representations, and a last time with @a address being NULL
106 * to signal the end of the iteration. Note that @a address NULL
107 * always is the last call, regardless of the value in @a res.
108 *
109 * @param cls closure
110 * @param address NULL on end of iteration,
111 * otherwise 0-terminated printable UTF-8 string,
112 * in particular an empty string if @a res is #GNUNET_NO
113 * @param res result of the address to string conversion:
114 * if #GNUNET_OK: conversion successful
115 * if #GNUNET_NO: address was invalid (or not supported)
116 * if #GNUNET_SYSERR: communication error (IPC error)
117 */
118typedef void
119(*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
120 const char *address,
121 int res);
122
123
124/**
125 * Convert a binary address into a human readable address.
126 *
127 * @param cfg configuration to use
128 * @param address address to convert (binary format)
129 * @param numeric should (IP) addresses be displayed in numeric form
130 * (otherwise do reverse DNS lookup)
131 * @param timeout how long is the lookup allowed to take at most
132 * @param aluc function to call with the results
133 * @param aluc_cls closure for @a aluc
134 * @return handle to cancel the operation, NULL on error
135 */
136struct GNUNET_TRANSPORT_AddressToStringContext *
137GNUNET_TRANSPORT_address_to_string (
138 const struct GNUNET_CONFIGURATION_Handle *cfg,
139 const struct GNUNET_HELLO_Address *address,
140 int numeric,
141 struct GNUNET_TIME_Relative timeout,
142 GNUNET_TRANSPORT_AddressToStringCallback aluc,
143 void *aluc_cls);
144
145
146/**
147 * Cancel request for address conversion.
148 *
149 * @param alc the context handle
150 */
151void
152GNUNET_TRANSPORT_address_to_string_cancel (
153 struct GNUNET_TRANSPORT_AddressToStringContext *alc);
154
155
156/* *********************** Monitoring ************************** */
157
158
159/**
160 * Possible state of a neighbour. Initially, we are
161 * #GNUNET_TRANSPORT_PS_NOT_CONNECTED.
162 *
163 * Then, there are two main paths. If we receive a SYN message, we give
164 * the inbound address to ATS. After the check we ask ATS for a suggestion
165 * (#GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS). If ATS makes a suggestion, we
166 * send our SYN_ACK and go to #GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK.
167 * If we receive a ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
168 * (and notify everyone about the new connection). If the operation times out,
169 * we go to #GNUNET_TRANSPORT_PS_DISCONNECT.
170 *
171 * The other case is where we transmit a SYN message first. We
172 * start with #GNUNET_TRANSPORT_PS_INIT_ATS. If we get an address, we send
173 * the SYN message and go to state #GNUNET_TRANSPORT_PS_CONNECT_SENT.
174 * Once we receive a SYN_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
175 * (and notify everyone about the new connection and send
176 * back a ACK). If the operation times out, we go to
177 * #GNUNET_TRANSPORT_PS_DISCONNECT.
178 *
179 * If the session is in trouble (i.e. transport-level disconnect or
180 * timeout), we go to #GNUNET_TRANSPORT_PS_RECONNECT_ATS where we ask ATS for a
181 * new address (we don't notify anyone about the disconnect yet). Once we have
182 * a new address, we enter #GNUNET_TRANSPORT_PS_RECONNECT_SENT and send a SYN
183 * message. If we receive a SYN_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
184 * and nobody noticed that we had trouble; we also send a ACK at this time just
185 * in case. If the operation times out, we go to
186 * #GNUNET_TRANSPORT_PS_DISCONNECT (and notify everyone about the lost
187 * connection).
188 *
189 * If ATS decides to switch addresses while we have a normal
190 * connection, we go to #GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_SYN_SENT
191 * and send a SESSION_CONNECT. If we get a ACK back, we switch the
192 * primary connection to the suggested alternative from ATS, go back
193 * to #GNUNET_TRANSPORT_PS_CONNECTED and send a ACK to the other peer just to be
194 * sure. If the operation times out
195 * we go to #GNUNET_TRANSPORT_PS_CONNECTED (and notify ATS that the given
196 * alternative address is "invalid").
197 *
198 * Once a session is in #GNUNET_TRANSPORT_PS_DISCONNECT, it is cleaned up and
199 * then goes to (#GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED). If we receive an
200 * explicit disconnect request, we can go from any state to
201 * #GNUNET_TRANSPORT_PS_DISCONNECT, possibly after generating disconnect
202 * notifications.
203 *
204 * Note that it is quite possible that while we are in any of these
205 * states, we could receive a 'SYN' request from the other peer.
206 * We then enter a 'weird' state where we pursue our own primary state
207 * machine (as described above), but with the 'send_connect_ack' flag
208 * set to 1. If our state machine allows us to send a 'SYN_ACK'
209 * (because we have an acceptable address), we send the 'SYN_ACK'
210 * and set the 'send_connect_ack' to 2. If we then receive a
211 * 'ACK', we go to #GNUNET_TRANSPORT_PS_CONNECTED (and reset 'send_connect_ack'
212 * to 0).
213 *
214 */
215enum GNUNET_TRANSPORT_PeerState
216{
217 /**
218 * Fresh peer or completely disconnected
219 */
220 GNUNET_TRANSPORT_PS_NOT_CONNECTED = 0,
221
222 /**
223 * Asked to initiate connection, trying to get address from ATS
224 */
225 GNUNET_TRANSPORT_PS_INIT_ATS,
226
227 /**
228 * Sent SYN message to other peer, waiting for SYN_ACK
229 */
230 GNUNET_TRANSPORT_PS_SYN_SENT,
231
232 /**
233 * Received a SYN, asking ATS about address suggestions.
234 */
235 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
236
237 /**
238 * SYN request from other peer was SYN_ACK'ed, waiting for ACK.
239 */
240 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
241
242 /**
243 * Got our SYN_ACK/ACK, connection is up.
244 */
245 GNUNET_TRANSPORT_PS_CONNECTED,
246
247 /**
248 * Connection got into trouble, rest of the system still believes
249 * it to be up, but we're getting a new address from ATS.
250 */
251 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
252
253 /**
254 * Sent SYN over new address (either by ATS telling us to switch
255 * addresses or from RECONNECT_ATS); if this fails, we need to tell
256 * the rest of the system about a disconnect.
257 */
258 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
259
260 /**
261 * We have some primary connection, but ATS suggested we switch
262 * to some alternative; we now sent a SYN message for the
263 * alternative session to the other peer and waiting for a
264 * SYN_ACK to make this our primary connection.
265 */
266 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
267
268 /**
269 * Disconnect in progress (we're sending the DISCONNECT message to the
270 * other peer; after that is finished, the state will be cleaned up).
271 */
272 GNUNET_TRANSPORT_PS_DISCONNECT,
273
274 /**
275 * We're finished with the disconnect; and are cleaning up the state
276 * now! We put the struct into this state when we are really in the
277 * task that calls 'free' on it and are about to remove the record
278 * from the map. We should never find a 'struct NeighbourMapEntry'
279 * in this state in the map. Accessing a 'struct NeighbourMapEntry'
280 * in this state virtually always means using memory that has been
281 * freed (the exception being the cleanup code in #free_neighbour()).
282 */
283 GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED
284};
285
286
287/**
288 * Convert a transport state to a human readable string.
289 *
290 * @param state the state
291 */
292const char *
293GNUNET_TRANSPORT_ps2s (enum GNUNET_TRANSPORT_PeerState state);
294
295
296/**
297 * Check if a state is defined as connected
298 *
299 * @param state the state value
300 * @return #GNUNET_YES or #GNUNET_NO
301 */
302int
303GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state);
304
305
306/**
307 * Handle for a #GNUNET_TRANSPORT_monitor_peers operation.
308 */
309struct GNUNET_TRANSPORT_PeerMonitoringContext;
310
311
312/**
313 * Function to call with information about a peer
314 *
315 * If one_shot was set to #GNUNET_YES to iterate over all peers once,
316 * a final call with NULL for peer and address will follow when done.
317 * In this case state and timeout do not contain valid values.
318 *
319 * The #GNUNET_TRANSPORT_monitor_peers_cancel() call MUST not be called from
320 * within this function!
321 *
322 *
323 * @param cls closure
324 * @param peer peer this update is about,
325 * NULL if this is the final last callback for a iteration operation
326 * @param address address, NULL if this is the final callback for iteration op
327 * @param state current state this peer is in
328 * @param state_timeout timeout for the current state of the peer
329 */
330typedef void
331(*GNUNET_TRANSPORT_PeerIterateCallback) (
332 void *cls,
333 const struct GNUNET_PeerIdentity *peer,
334 const struct GNUNET_HELLO_Address *address,
335 enum GNUNET_TRANSPORT_PeerState state,
336 struct GNUNET_TIME_Absolute state_timeout);
337
338
339/**
340 * Return information about a specific peer or all peers currently known to
341 * transport service once or in monitoring mode. To obtain information about
342 * a specific peer, a peer identity can be passed. To obtain information about
343 * all peers currently known to transport service, NULL can be passed as peer
344 * identity.
345 *
346 * For each peer, the callback is called with information about the address used
347 * to communicate with this peer, the state this peer is currently in and the
348 * the current timeout for this state.
349 *
350 * Upon completion, the #GNUNET_TRANSPORT_PeerIterateCallback is called one
351 * more time with `NULL`. After this, the operation must no longer be
352 * explicitly canceled.
353 *
354 * The #GNUNET_TRANSPORT_monitor_peers_cancel call MUST not be called in the
355 * the peer_callback!
356 *
357 * @param cfg configuration to use
358 * @param peer a specific peer identity to obtain information for,
359 * NULL for all peers
360 * @param one_shot #GNUNET_YES to return the current state and then end (with
361 * NULL+NULL), #GNUNET_NO to monitor peers continuously
362 * @param peer_callback function to call with the results
363 * @param peer_callback_cls closure for @a peer_callback
364 */
365struct GNUNET_TRANSPORT_PeerMonitoringContext *
366GNUNET_TRANSPORT_monitor_peers (
367 const struct GNUNET_CONFIGURATION_Handle *cfg,
368 const struct GNUNET_PeerIdentity *peer,
369 int one_shot,
370 GNUNET_TRANSPORT_PeerIterateCallback peer_callback,
371 void *peer_callback_cls);
372
373
374/**
375 * Cancel request to monitor peers
376 *
377 * @param pic handle for the request to cancel
378 */
379void
380GNUNET_TRANSPORT_monitor_peers_cancel (
381 struct GNUNET_TRANSPORT_PeerMonitoringContext *pic);
382
383
384/* *********************** Blacklisting ************************ */
385
386/**
387 * Handle for blacklisting peers.
388 */
389struct GNUNET_TRANSPORT_Blacklist;
390
391
392/**
393 * Function that decides if a connection is acceptable or not.
394 *
395 * @param cls closure
396 * @param pid peer to approve or disapproave
397 * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not
398 */
399typedef int
400(*GNUNET_TRANSPORT_BlacklistCallback) (
401 void *cls,
402 const struct GNUNET_PeerIdentity *pid);
403
404
405/**
406 * Install a blacklist callback. The service will be queried for all
407 * existing connections as well as any fresh connections to check if
408 * they are permitted. If the blacklisting callback is unregistered,
409 * all hosts that were denied in the past will automatically be
410 * whitelisted again. Cancelling the blacklist handle is also the
411 * only way to re-enable connections from peers that were previously
412 * blacklisted.
413 *
414 * @param cfg configuration to use
415 * @param cb callback to invoke to check if connections are allowed
416 * @param cb_cls closure for @a cb
417 * @return NULL on error, otherwise handle for cancellation
418 */
419struct GNUNET_TRANSPORT_Blacklist *
420GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
421 GNUNET_TRANSPORT_BlacklistCallback cb,
422 void *cb_cls);
423
424
425/**
426 * Abort the blacklist. Note that this function is the only way for
427 * removing a peer from the blacklist.
428 *
429 * @param br handle of the request that is to be cancelled
430 */
431void
432GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
433
434
435/**
436 * Handle for a plugin session state monitor.
437 */
438struct GNUNET_TRANSPORT_PluginMonitor;
439
440/**
441 * Abstract representation of a plugin's session.
442 * Corresponds to the `struct GNUNET_ATS_Session` within the TRANSPORT service.
443 */
444struct GNUNET_TRANSPORT_PluginSession;
445
446
447/**
448 * Possible states of a session in a plugin.
449 */
450enum GNUNET_TRANSPORT_SessionState
451{
452 /**
453 * The session was created (first call for each session object).
454 */
455 GNUNET_TRANSPORT_SS_INIT,
456
457 /**
458 * Initial session handshake is in progress.
459 */
460 GNUNET_TRANSPORT_SS_HANDSHAKE,
461
462 /**
463 * Session is fully UP.
464 */
465 GNUNET_TRANSPORT_SS_UP,
466
467 /**
468 * This is just an update about the session,
469 * the state did not change.
470 */
471 GNUNET_TRANSPORT_SS_UPDATE,
472
473 /**
474 * Session is being torn down and about to disappear.
475 * Last call for each session object.
476 */
477 GNUNET_TRANSPORT_SS_DONE
478};
479
480
481/**
482 * Information about a plugin's session.
483 */
484struct GNUNET_TRANSPORT_SessionInfo
485{
486 /**
487 * New state of the session.
488 */
489 enum GNUNET_TRANSPORT_SessionState state;
490
491 /**
492 * #GNUNET_YES if this is an inbound connection,
493 * #GNUNET_NO if this is an outbound connection,
494 * #GNUNET_SYSERR if connections of this plugin
495 * are so fundamentally bidirectional
496 * that they have no 'initiator'
497 */
498 int is_inbound;
499
500 /**
501 * Number of messages pending transmission for this session.
502 */
503 uint32_t num_msg_pending;
504
505 /**
506 * Number of bytes pending transmission for this session.
507 */
508 uint32_t num_bytes_pending;
509
510 /**
511 * Until when does this plugin refuse to receive to manage
512 * staying within the inbound quota? ZERO if receive is
513 * active.
514 */
515 struct GNUNET_TIME_Absolute receive_delay;
516
517 /**
518 * At what time will this session timeout (unless activity
519 * happens)?
520 */
521 struct GNUNET_TIME_Absolute session_timeout;
522
523 /**
524 * Address used by the session. Can be NULL if none is available.
525 */
526 const struct GNUNET_HELLO_Address *address;
527};
528
529
530/**
531 * Function called by the plugin with information about the
532 * current sessions managed by the plugin (for monitoring).
533 *
534 * @param cls closure
535 * @param session session handle this information is about,
536 * NULL to indicate that we are "in sync" (initial
537 * iteration complete)
538 * @param session_ctx storage location where the application
539 * can store data; will point to NULL on #GNUNET_TRANSPORT_SS_INIT,
540 * and must be reset to NULL on #GNUNET_TRANSPORT_SS_DONE
541 * @param info information about the state of the session,
542 * NULL if @a session is also NULL and we are
543 * merely signalling that the initial iteration is over;
544 * NULL with @a session being non-NULL if the monitor
545 * was being cancelled while sessions were active
546 */
547typedef void
548(*GNUNET_TRANSPORT_SessionMonitorCallback) (
549 void *cls,
550 struct GNUNET_TRANSPORT_PluginSession *session,
551 void **session_ctx,
552 const struct GNUNET_TRANSPORT_SessionInfo *info);
553
554
555/**
556 * Install a plugin session state monitor callback. The callback
557 * will be notified whenever the session changes.
558 *
559 * @param cfg configuration to use
560 * @param cb callback to invoke on events
561 * @param cb_cls closure for @a cb
562 * @return NULL on error, otherwise handle for cancellation
563 */
564struct GNUNET_TRANSPORT_PluginMonitor *
565GNUNET_TRANSPORT_monitor_plugins (const struct GNUNET_CONFIGURATION_Handle *cfg,
566 GNUNET_TRANSPORT_SessionMonitorCallback cb,
567 void *cb_cls);
568
569
570/**
571 * Cancel monitoring the plugin session state. The callback will be
572 * called once for each session that is up with the "info" argument
573 * being NULL (this is just to enable client-side cleanup).
574 *
575 * @param pm handle of the request that is to be cancelled
576 */
577void
578GNUNET_TRANSPORT_monitor_plugins_cancel (
579 struct GNUNET_TRANSPORT_PluginMonitor *pm);
580
581
582/**
583 * Opaque handle to the service.
584 */
585struct GNUNET_TRANSPORT_CoreHandle;
586
587
588/**
589 * Function called to notify transport users that another
590 * peer connected to us.
591 *
592 * @param cls closure
593 * @param peer the identity of the peer that connected; this
594 * pointer will remain valid until the disconnect, hence
595 * applications do not necessarily have to make a copy
596 * of the value if they only need it until disconnect
597 * @param mq message queue to use to transmit to @a peer
598 * @return closure to use in MQ handlers
599 */
600typedef void *
601(*GNUNET_TRANSPORT_NotifyConnect) (
602 void *cls,
603 const struct GNUNET_PeerIdentity *peer,
604 struct GNUNET_MQ_Handle *mq);
605
606
607/**
608 * Function called to notify transport users that another peer
609 * disconnected from us. The message queue that was given to the
610 * connect notification will be destroyed and must not be used
611 * henceforth.
612 *
613 * @param cls closure from #GNUNET_TRANSPORT_core_connect
614 * @param peer the peer that disconnected
615 * @param handlers_cls closure of the handlers, was returned from the
616 * connect notification callback
617 */
618typedef void
619(*GNUNET_TRANSPORT_NotifyDisconnect) (
620 void *cls,
621 const struct GNUNET_PeerIdentity *peer,
622 void *handler_cls);
623
624
625/**
626 * Function called if we have "excess" bandwidth to a peer.
627 * The notification will happen the first time we have excess
628 * bandwidth, and then only again after the client has performed
629 * some transmission to the peer.
630 *
631 * Excess bandwidth is defined as being allowed (by ATS) to send
632 * more data, and us reaching the limit of the capacity build-up
633 * (which, if we go past it, means we don't use available bandwidth).
634 * See also the "max carry" in `struct GNUNET_BANDWIDTH_Tracker`.
635 *
636 * @param cls the closure
637 * @param neighbour peer that we have excess bandwidth to
638 * @param handlers_cls closure of the handlers, was returned from the
639 * connect notification callback
640 */
641typedef void
642(*GNUNET_TRANSPORT_NotifyExcessBandwidth) (
643 void *cls,
644 const struct GNUNET_PeerIdentity *neighbour,
645 void *handlers_cls);
646
647
648/**
649 * Connect to the transport service. Note that the connection may
650 * complete (or fail) asynchronously.
651 *
652 * @param cfg configuration to use
653 * @param self our own identity (API should check that it matches
654 * the identity found by transport), or NULL (no check)
655 * @param handlers array of message handlers; note that the
656 * closures provided will be ignored and replaced
657 * with the respective return value from @a nc
658 * @param handlers array with handlers to call when we receive messages, or NULL
659 * @param cls closure for the @a nc, @a nd and @a neb callbacks
660 * @param nc function to call on connect events, or NULL
661 * @param nd function to call on disconnect events, or NULL
662 * @param neb function to call if we have excess bandwidth to a peer, or NULL
663 * @return NULL on error
664 */
665struct GNUNET_TRANSPORT_CoreHandle *
666GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
667 const struct GNUNET_PeerIdentity *self,
668 const struct GNUNET_MQ_MessageHandler *handlers,
669 void *cls,
670 GNUNET_TRANSPORT_NotifyConnect nc,
671 GNUNET_TRANSPORT_NotifyDisconnect nd,
672 GNUNET_TRANSPORT_NotifyExcessBandwidth neb);
673
674
675/**
676 * Disconnect from the transport service.
677 *
678 * @param handle handle returned from connect
679 */
680void
681GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle);
682
683
684/**
685 * Checks if a given peer is connected to us and get the message queue.
686 *
687 * @param handle connection to transport service
688 * @param peer the peer to check
689 * @return NULL if disconnected, otherwise message queue for @a peer
690 */
691struct GNUNET_MQ_Handle *
692GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
693 const struct GNUNET_PeerIdentity *peer);
694
695
696#if 0 /* keep Emacsens' auto-indent happy */
697{
698#endif
699#ifdef __cplusplus
700}
701#endif
702
703/* ifndef GNUNET_TRANSPORT_SERVICE_H */
704#endif
705
706/** @} */ /* end of group */
707
708/* end of gnunet_transport_service.h */
diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h
index 61880cea1..6c7d2cd42 100644
--- a/src/include/gnunet_tun_lib.h
+++ b/src/include/gnunet_tun_lib.h
@@ -18,7 +18,14 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20 20
21#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
21/** 25/**
26 * @addtogroup vpn_suite VPN services and libraries
27 * @{
28 *
22 * @author Philipp Toelke 29 * @author Philipp Toelke
23 * @author Christian Grothoff 30 * @author Christian Grothoff
24 * 31 *
@@ -34,9 +41,6 @@
34#ifndef GNUNET_TUN_LIB_H 41#ifndef GNUNET_TUN_LIB_H
35#define GNUNET_TUN_LIB_H 42#define GNUNET_TUN_LIB_H
36 43
37#include "gnunet_common.h"
38#include "gnunet_crypto_lib.h"
39
40 44
41/* see http://www.iana.org/assignments/ethernet-numbers */ 45/* see http://www.iana.org/assignments/ethernet-numbers */
42#ifndef ETH_P_IPV4 46#ifndef ETH_P_IPV4
@@ -546,6 +550,29 @@ struct GNUNET_TUN_DnsSrvRecord
546 550
547 551
548/** 552/**
553 * Payload of DNS URI record (header).
554 */
555struct GNUNET_TUN_DnsUriRecord
556{
557 /**
558 * Preference for this entry (lower value is higher preference). Clients
559 * will contact hosts from the lowest-priority group first and fall back
560 * to higher priorities if the low-priority entries are unavailable. (NBO)
561 */
562 uint16_t prio GNUNET_PACKED;
563
564 /**
565 * Relative weight for records with the same priority. Clients will use
566 * the hosts of the same (lowest) priority with a probability proportional
567 * to the weight given. (NBO)
568 */
569 uint16_t weight GNUNET_PACKED;
570
571 /* followed by 'target' name */
572};
573
574
575/**
549 * Payload of DNS CERT record. 576 * Payload of DNS CERT record.
550 */ 577 */
551struct GNUNET_TUN_DnsCertRecord 578struct GNUNET_TUN_DnsCertRecord
@@ -946,3 +973,5 @@ GNUNET_TUN_compute_service_cadet_port (const struct GNUNET_HashCode *desc,
946#endif 973#endif
947 974
948/** @} */ /* end of group */ 975/** @} */ /* end of group */
976
977/** @} */ /* end of group addition */
diff --git a/src/include/gnunet_util_lib.h b/src/include/gnunet_util_lib.h
index cc4f3a01e..86a1204bb 100644
--- a/src/include/gnunet_util_lib.h
+++ b/src/include/gnunet_util_lib.h
@@ -30,6 +30,10 @@
30#ifndef GNUNET_UTIL_LIB_H 30#ifndef GNUNET_UTIL_LIB_H
31#define GNUNET_UTIL_LIB_H 31#define GNUNET_UTIL_LIB_H
32 32
33#define __GNUNET_UTIL_LIB_H_INSIDE__
34
35#include <sys/socket.h>
36
33#ifdef __cplusplus 37#ifdef __cplusplus
34extern "C" 38extern "C"
35{ 39{
@@ -59,9 +63,10 @@ extern "C"
59 * this service available to anyone but yourself. 63 * this service available to anyone but yourself.
60 */ 64 */
61#define GNUNET_AGPL_URL "https://git.gnunet.org/gnunet.git/tag/?h=v" \ 65#define GNUNET_AGPL_URL "https://git.gnunet.org/gnunet.git/tag/?h=v" \
62 PACKAGE_VERSION 66 GNUNET_VERSION
63
64 67
68#include "gnunet_config.h"
69#include "gnunet_common.h"
65#include "gnunet_crypto_lib.h" 70#include "gnunet_crypto_lib.h"
66#include "gnunet_bandwidth_lib.h" 71#include "gnunet_bandwidth_lib.h"
67#include "gnunet_bio_lib.h" 72#include "gnunet_bio_lib.h"
@@ -72,8 +77,8 @@ extern "C"
72#include "gnunet_helper_lib.h" 77#include "gnunet_helper_lib.h"
73#include "gnunet_mst_lib.h" 78#include "gnunet_mst_lib.h"
74#include "gnunet_mq_lib.h" 79#include "gnunet_mq_lib.h"
80#include "gnunet_nt_lib.h"
75#include "gnunet_nc_lib.h" 81#include "gnunet_nc_lib.h"
76#include "gnunet_op_lib.h"
77#include "gnunet_os_lib.h" 82#include "gnunet_os_lib.h"
78#include "gnunet_peer_lib.h" 83#include "gnunet_peer_lib.h"
79#include "gnunet_plugin_lib.h" 84#include "gnunet_plugin_lib.h"
@@ -86,6 +91,17 @@ extern "C"
86#include "gnunet_dnsstub_lib.h" 91#include "gnunet_dnsstub_lib.h"
87#include "gnunet_dnsparser_lib.h" 92#include "gnunet_dnsparser_lib.h"
88#include "gnunet_child_management_lib.h" 93#include "gnunet_child_management_lib.h"
94#include "gnunet_error_codes.h"
95
96
97/**
98 * Stringify operator.
99 *
100 * @param a some expression to stringify. Must NOT be a macro.
101 * @return same expression as a constant string.
102 */
103#define GNUNET_S(a) #a
104
89 105
90#if 0 /* keep Emacsens' auto-indent happy */ 106#if 0 /* keep Emacsens' auto-indent happy */
91{ 107{
@@ -94,4 +110,6 @@ extern "C"
94} 110}
95#endif 111#endif
96 112
113#undef __GNUNET_UTIL_LIB_H_INSIDE__
114
97#endif 115#endif
diff --git a/src/include/gnunet_vpn_service.h b/src/include/gnunet_vpn_service.h
index 31476e140..f0a04ae1b 100644
--- a/src/include/gnunet_vpn_service.h
+++ b/src/include/gnunet_vpn_service.h
@@ -19,6 +19,9 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup vpn_suite VPN services and libraries
23 * @{
24 *
22 * @author Christian Grothoff 25 * @author Christian Grothoff
23 * 26 *
24 * @file 27 * @file
@@ -31,6 +34,7 @@
31#ifndef GNUNET_VPN_SERVICE_H 34#ifndef GNUNET_VPN_SERVICE_H
32#define GNUNET_VPN_SERVICE_H 35#define GNUNET_VPN_SERVICE_H
33 36
37
34#include "gnunet_util_lib.h" 38#include "gnunet_util_lib.h"
35 39
36 40
@@ -159,3 +163,5 @@ GNUNET_VPN_disconnect (struct GNUNET_VPN_Handle *vh);
159#endif 163#endif
160 164
161/** @} */ /* end of group */ 165/** @} */ /* end of group */
166
167/** @} */ /* end of group addition */
diff --git a/src/include/meson.build b/src/include/meson.build
new file mode 100644
index 000000000..51a8009af
--- /dev/null
+++ b/src/include/meson.build
@@ -0,0 +1,122 @@
1configure_file(
2 input : 'gnunet_config.h.in',
3 output : 'gnunet_config.h',
4 configuration : cdata,
5 install: true,
6 install_dir: get_option('includedir')/'gnunet'
7)
8
9install_headers(
10 'gettext.h',
11 'compat.h',
12 'gnunet_abd_service.h',
13 'gnunet_applications.h',
14 'gnunet_arm_service.h',
15 'gnunet_bandwidth_lib.h',
16 'gnunet_bio_lib.h',
17 'gnunet_dht_block_types.h',
18 'gnunet_block_lib.h',
19 'gnunet_block_group_lib.h',
20 'gnunet_block_plugin.h',
21 'gnunet_buffer_lib.h',
22 'gnunet_child_management_lib.h',
23 'gnunet_client_lib.h',
24 'gnunet_common.h',
25 'gnunet_constants.h',
26 'gnunet_configuration_lib.h',
27 'gnunet_consensus_service.h',
28 'gnunet_container_lib.h',
29 'gnunet_conversation_service.h',
30 'gnunet_core_service.h',
31 'gnunet_crypto_lib.h',
32 'gnunet_curl_lib.h',
33 'gnunet_datacache_lib.h',
34 'gnunet_datacache_plugin.h',
35 'gnunet_datastore_service.h',
36 'gnunet_datastore_plugin.h',
37 'gnunet_db_lib.h',
38 'gnunet_dht_service.h',
39 'gnunet_dhtu_plugin.h',
40 'gnunet_disk_lib.h',
41 'gnunet_dnsparser_lib.h',
42 'gnunet_dnsstub_lib.h',
43 'gnunet_dns_service.h',
44 'gnunet_error_codes.h',
45 'gnunet_fs_service.h',
46 'gnunet_getopt_lib.h',
47 'gnunet_gns_service.h',
48 'gnunet_gnsrecord_lib.h',
49 'gnunet_gnsrecord_json_lib.h',
50 'gnunet_gnsrecord_plugin.h',
51 'gnu_name_system_protocols.h',
52 'gnu_name_system_service_ports.h',
53 'gnu_name_system_record_types.h',
54 'gnunet_hello_uri_lib.h',
55 'gnunet_helper_lib.h',
56 'gnunet_identity_service.h',
57 'gnunet_reclaim_lib.h',
58 'gnunet_reclaim_plugin.h',
59 'gnunet_reclaim_service.h',
60 'gnunet_json_lib.h',
61 'gnunet_load_lib.h',
62 'gnunet_cadet_service.h',
63 'gnunet_messenger_service.h',
64 'gnunet_mhd_compat.h',
65 'gnunet_microphone_lib.h',
66 'gnunet_mst_lib.h',
67 'gnunet_mq_lib.h',
68 'gnunet_namecache_plugin.h',
69 'gnunet_namecache_service.h',
70 'gnunet_namestore_plugin.h',
71 'gnunet_namestore_service.h',
72 'gnunet_nat_auto_service.h',
73 'gnunet_nat_service.h',
74 'gnunet_nc_lib.h',
75 'gnunet_network_lib.h',
76 'gnunet_nse_service.h',
77 'gnunet_nt_lib.h',
78 'gnunet_op_lib.h',
79 'gnunet_os_lib.h',
80 'gnunet_peer_lib.h',
81 'gnunet_peerstore_plugin.h',
82 'gnunet_peerstore_service.h',
83 'gnunet_plugin_lib.h',
84 'gnunet_pq_lib.h',
85 'gnunet_program_lib.h',
86 'gnunet_protocols.h',
87 'gnunet_resolver_service.h',
88 'gnunet_regex_service.h',
89 'gnunet_rest_lib.h',
90 'gnunet_rest_plugin.h',
91 'gnunet_rps_service.h',
92 'gnunet_revocation_service.h',
93 'gnunet_scalarproduct_service.h',
94 'gnunet_scheduler_lib.h',
95 'gnunet_secretsharing_service.h',
96 'gnunet_service_lib.h',
97 'gnunet_set_service.h',
98 'gnunet_seti_service.h',
99 'gnunet_setu_service.h',
100 'gnunet_signal_lib.h',
101 'gnunet_signatures.h',
102 'gnunet_socks.h',
103 'gnunet_speaker_lib.h',
104 'gnunet_sq_lib.h',
105 'gnunet_statistics_service.h',
106 'gnunet_strings_lib.h',
107 'gnunet_testing_lib.h',
108 'gnunet_testing_arm_lib.h',
109 'gnunet_testing_core_lib.h',
110 'gnunet_testing_testbed_lib.h',
111 'gnunet_testing_transport_lib.h',
112 'gnunet_time_lib.h',
113 'gnunet_transport_application_service.h',
114 'gnunet_transport_communication_service.h',
115 'gnunet_transport_core_service.h',
116 'gnunet_transport_monitor_service.h',
117 'gnunet_tun_lib.h',
118 'gnunet_uri_lib.h',
119 'gnunet_util_lib.h',
120 'gnunet_vpn_service.h',
121 install_dir: get_option('includedir')/'gnunet'
122 )
diff --git a/src/include/platform.h b/src/include/platform.h
index e44f9f51a..c04d8d487 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -34,7 +34,7 @@
34#ifndef HAVE_USED_CONFIG_H 34#ifndef HAVE_USED_CONFIG_H
35#define HAVE_USED_CONFIG_H 35#define HAVE_USED_CONFIG_H
36#if HAVE_CONFIG_H 36#if HAVE_CONFIG_H
37#include "gnunet_config.h" 37#include "gnunet_private_config.h"
38#endif 38#endif
39#endif 39#endif
40 40
@@ -44,6 +44,7 @@
44#ifdef HAVE_SYS_TYPES_H 44#ifdef HAVE_SYS_TYPES_H
45#include <sys/types.h> 45#include <sys/types.h>
46#endif 46#endif
47#include <inttypes.h>
47 48
48#ifdef __clang__ 49#ifdef __clang__
49#undef HAVE_STATIC_ASSERT 50#undef HAVE_STATIC_ASSERT
@@ -272,6 +273,10 @@ atoll (const char *nptr);
272#define EXIT_NOTRUNNING 7 273#define EXIT_NOTRUNNING 7
273#endif 274#endif
274 275
276#ifndef EXIT_NO_RESTART
277#define EXIT_NO_RESTART 9
278#endif
279
275/** 280/**
276 * clang et al do not have such an attribute 281 * clang et al do not have such an attribute
277 */ 282 */